| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 var wp; 2 (wp ||= {}).formatLibrary = (() => { 3 var __create = Object.create; 4 var __defProp = Object.defineProperty; 5 var __getOwnPropDesc = Object.getOwnPropertyDescriptor; 6 var __getOwnPropNames = Object.getOwnPropertyNames; 7 var __getProtoOf = Object.getPrototypeOf; 8 var __hasOwnProp = Object.prototype.hasOwnProperty; 9 var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { 10 get: (a, b) => (typeof require !== "undefined" ? require : a)[b] 11 }) : x)(function(x) { 12 if (typeof require !== "undefined") return require.apply(this, arguments); 13 throw Error('Dynamic require of "' + x + '" is not supported'); 14 }); 15 var __commonJS = (cb, mod) => function __require2() { 16 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; 17 }; 18 var __copyProps = (to, from, except, desc) => { 19 if (from && typeof from === "object" || typeof from === "function") { 20 for (let key of __getOwnPropNames(from)) 21 if (!__hasOwnProp.call(to, key) && key !== except) 22 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); 23 } 24 return to; 25 }; 26 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( 27 // If the importer is in node compatibility mode or this is not an ESM 28 // file that has been converted to a CommonJS file using a Babel- 29 // compatible transform (i.e. "__esModule" has not been set), then set 30 // "default" to the CommonJS "module.exports" for node compatibility. 31 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, 32 mod 33 )); 34 35 // package-external:@wordpress/rich-text 36 var require_rich_text = __commonJS({ 37 "package-external:@wordpress/rich-text"(exports, module) { 38 module.exports = window.wp.richText; 39 } 40 }); 41 42 // package-external:@wordpress/i18n 43 var require_i18n = __commonJS({ 44 "package-external:@wordpress/i18n"(exports, module) { 45 module.exports = window.wp.i18n; 46 } 47 }); 48 49 // package-external:@wordpress/block-editor 50 var require_block_editor = __commonJS({ 51 "package-external:@wordpress/block-editor"(exports, module) { 52 module.exports = window.wp.blockEditor; 53 } 54 }); 55 56 // package-external:@wordpress/element 57 var require_element = __commonJS({ 58 "package-external:@wordpress/element"(exports, module) { 59 module.exports = window.wp.element; 60 } 61 }); 62 63 // package-external:@wordpress/primitives 64 var require_primitives = __commonJS({ 65 "package-external:@wordpress/primitives"(exports, module) { 66 module.exports = window.wp.primitives; 67 } 68 }); 69 70 // vendor-external:react/jsx-runtime 71 var require_jsx_runtime = __commonJS({ 72 "vendor-external:react/jsx-runtime"(exports, module) { 73 module.exports = window.ReactJSXRuntime; 74 } 75 }); 76 77 // package-external:@wordpress/private-apis 78 var require_private_apis = __commonJS({ 79 "package-external:@wordpress/private-apis"(exports, module) { 80 module.exports = window.wp.privateApis; 81 } 82 }); 83 84 // package-external:@wordpress/components 85 var require_components = __commonJS({ 86 "package-external:@wordpress/components"(exports, module) { 87 module.exports = window.wp.components; 88 } 89 }); 90 91 // package-external:@wordpress/url 92 var require_url = __commonJS({ 93 "package-external:@wordpress/url"(exports, module) { 94 module.exports = window.wp.url; 95 } 96 }); 97 98 // package-external:@wordpress/html-entities 99 var require_html_entities = __commonJS({ 100 "package-external:@wordpress/html-entities"(exports, module) { 101 module.exports = window.wp.htmlEntities; 102 } 103 }); 104 105 // package-external:@wordpress/a11y 106 var require_a11y = __commonJS({ 107 "package-external:@wordpress/a11y"(exports, module) { 108 module.exports = window.wp.a11y; 109 } 110 }); 111 112 // package-external:@wordpress/data 113 var require_data = __commonJS({ 114 "package-external:@wordpress/data"(exports, module) { 115 module.exports = window.wp.data; 116 } 117 }); 118 119 // package-external:@wordpress/compose 120 var require_compose = __commonJS({ 121 "package-external:@wordpress/compose"(exports, module) { 122 module.exports = window.wp.compose; 123 } 124 }); 125 126 // packages/format-library/build-module/index.js 127 var import_rich_text18 = __toESM(require_rich_text()); 128 129 // packages/format-library/build-module/bold/index.js 130 var import_i18n = __toESM(require_i18n()); 131 var import_rich_text = __toESM(require_rich_text()); 132 var import_block_editor = __toESM(require_block_editor()); 133 134 // packages/icons/build-module/icon/index.js 135 var import_element = __toESM(require_element()); 136 var icon_default = (0, import_element.forwardRef)( 137 ({ icon, size = 24, ...props }, ref) => { 138 return (0, import_element.cloneElement)(icon, { 139 width: size, 140 height: size, 141 ...props, 142 ref 143 }); 144 } 145 ); 146 147 // packages/icons/build-module/library/button.js 148 var import_primitives = __toESM(require_primitives()); 149 var import_jsx_runtime = __toESM(require_jsx_runtime()); 150 var button_default = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.Path, { d: "M8 12.5h8V11H8v1.5Z M19 6.5H5a2 2 0 0 0-2 2V15a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8.5a2 2 0 0 0-2-2ZM5 8h14a.5.5 0 0 1 .5.5V15a.5.5 0 0 1-.5.5H5a.5.5 0 0 1-.5-.5V8.5A.5.5 0 0 1 5 8Z" }) }); 151 152 // packages/icons/build-module/library/code.js 153 var import_primitives2 = __toESM(require_primitives()); 154 var import_jsx_runtime2 = __toESM(require_jsx_runtime()); 155 var code_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.Path, { d: "M20.8 10.7l-4.3-4.3-1.1 1.1 4.3 4.3c.1.1.1.3 0 .4l-4.3 4.3 1.1 1.1 4.3-4.3c.7-.8.7-1.9 0-2.6zM4.2 11.8l4.3-4.3-1-1-4.3 4.3c-.7.7-.7 1.8 0 2.5l4.3 4.3 1.1-1.1-4.3-4.3c-.2-.1-.2-.3-.1-.4z" }) }); 156 157 // packages/icons/build-module/library/color.js 158 var import_primitives3 = __toESM(require_primitives()); 159 var import_jsx_runtime3 = __toESM(require_jsx_runtime()); 160 var color_default = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.Path, { d: "M17.2 10.9c-.5-1-1.2-2.1-2.1-3.2-.6-.9-1.3-1.7-2.1-2.6L12 4l-1 1.1c-.6.9-1.3 1.7-2 2.6-.8 1.2-1.5 2.3-2 3.2-.6 1.2-1 2.2-1 3 0 3.4 2.7 6.1 6.1 6.1s6.1-2.7 6.1-6.1c0-.8-.3-1.8-1-3zm-5.1 7.6c-2.5 0-4.6-2.1-4.6-4.6 0-.3.1-1 .8-2.3.5-.9 1.1-1.9 2-3.1.7-.9 1.3-1.7 1.8-2.3.7.8 1.3 1.6 1.8 2.3.8 1.1 1.5 2.2 2 3.1.7 1.3.8 2 .8 2.3 0 2.5-2.1 4.6-4.6 4.6z" }) }); 161 162 // packages/icons/build-module/library/format-bold.js 163 var import_primitives4 = __toESM(require_primitives()); 164 var import_jsx_runtime4 = __toESM(require_jsx_runtime()); 165 var format_bold_default = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.Path, { d: "M14.7 11.3c1-.6 1.5-1.6 1.5-3 0-2.3-1.3-3.4-4-3.4H7v14h5.8c1.4 0 2.5-.3 3.3-1 .8-.7 1.2-1.7 1.2-2.9.1-1.9-.8-3.1-2.6-3.7zm-5.1-4h2.3c.6 0 1.1.1 1.4.4.3.3.5.7.5 1.2s-.2 1-.5 1.2c-.3.3-.8.4-1.4.4H9.6V7.3zm4.6 9c-.4.3-1 .4-1.7.4H9.6v-3.9h2.9c.7 0 1.3.2 1.7.5.4.3.6.8.6 1.5s-.2 1.2-.6 1.5z" }) }); 166 167 // packages/icons/build-module/library/format-italic.js 168 var import_primitives5 = __toESM(require_primitives()); 169 var import_jsx_runtime5 = __toESM(require_jsx_runtime()); 170 var format_italic_default = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.Path, { d: "M12.5 5L10 19h1.9l2.5-14z" }) }); 171 172 // packages/icons/build-module/library/format-strikethrough.js 173 var import_primitives6 = __toESM(require_primitives()); 174 var import_jsx_runtime6 = __toESM(require_jsx_runtime()); 175 var format_strikethrough_default = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives6.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives6.Path, { d: "M9.1 9v-.5c0-.6.2-1.1.7-1.4.5-.3 1.2-.5 2-.5.7 0 1.4.1 2.1.3.7.2 1.4.5 2.1.9l.2-1.9c-.6-.3-1.2-.5-1.9-.7-.8-.1-1.6-.2-2.4-.2-1.5 0-2.7.3-3.6 1-.8.7-1.2 1.5-1.2 2.6V9h2zM20 12H4v1h8.3c.3.1.6.2.8.3.5.2.9.5 1.1.8.3.3.4.7.4 1.2 0 .7-.2 1.1-.8 1.5-.5.3-1.2.5-2.1.5-.8 0-1.6-.1-2.4-.3-.8-.2-1.5-.5-2.2-.8L7 18.1c.5.2 1.2.4 2 .6.8.2 1.6.3 2.4.3 1.7 0 3-.3 3.9-1 .9-.7 1.3-1.6 1.3-2.8 0-.9-.2-1.7-.7-2.2H20v-1z" }) }); 176 177 // packages/icons/build-module/library/help.js 178 var import_primitives7 = __toESM(require_primitives()); 179 var import_jsx_runtime7 = __toESM(require_jsx_runtime()); 180 var help_default = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives7.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives7.Path, { d: "M12 4a8 8 0 1 1 .001 16.001A8 8 0 0 1 12 4Zm0 1.5a6.5 6.5 0 1 0-.001 13.001A6.5 6.5 0 0 0 12 5.5Zm.75 11h-1.5V15h1.5v1.5Zm-.445-9.234a3 3 0 0 1 .445 5.89V14h-1.5v-1.25c0-.57.452-.958.917-1.01A1.5 1.5 0 0 0 12 8.75a1.5 1.5 0 0 0-1.5 1.5H9a3 3 0 0 1 3.305-2.984Z" }) }); 181 182 // packages/icons/build-module/library/language.js 183 var import_primitives8 = __toESM(require_primitives()); 184 var import_jsx_runtime8 = __toESM(require_jsx_runtime()); 185 var language_default = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_primitives8.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_primitives8.Path, { d: "M17.5 10h-1.7l-3.7 10.5h1.7l.9-2.6h3.9l.9 2.6h1.7L17.5 10zm-2.2 6.3 1.4-4 1.4 4h-2.8zm-4.8-3.8c1.6-1.8 2.9-3.6 3.7-5.7H16V5.2h-5.8V3H8.8v2.2H3v1.5h9.6c-.7 1.6-1.8 3.1-3.1 4.6C8.6 10.2 7.8 9 7.2 8H5.6c.6 1.4 1.7 2.9 2.9 4.4l-2.4 2.4c-.3.4-.7.8-1.1 1.2l1 1 1.2-1.2c.8-.8 1.6-1.5 2.3-2.3.8.9 1.7 1.7 2.5 2.5l.6-1.5c-.7-.6-1.4-1.3-2.1-2z" }) }); 186 187 // packages/icons/build-module/library/link.js 188 var import_primitives9 = __toESM(require_primitives()); 189 var import_jsx_runtime9 = __toESM(require_jsx_runtime()); 190 var link_default = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_primitives9.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_primitives9.Path, { d: "M10 17.389H8.444A5.194 5.194 0 1 1 8.444 7H10v1.5H8.444a3.694 3.694 0 0 0 0 7.389H10v1.5ZM14 7h1.556a5.194 5.194 0 0 1 0 10.39H14v-1.5h1.556a3.694 3.694 0 0 0 0-7.39H14V7Zm-4.5 6h5v-1.5h-5V13Z" }) }); 191 192 // packages/icons/build-module/library/math.js 193 var import_primitives10 = __toESM(require_primitives()); 194 var import_jsx_runtime10 = __toESM(require_jsx_runtime()); 195 var math_default = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_primitives10.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_primitives10.Path, { d: "M11.2 6.8c-.7 0-1.4.5-1.6 1.1l-2.8 7.5-1.2-1.8c-.1-.2-.4-.3-.6-.3H3v1.5h1.6l1.2 1.8c.6.9 1.9.7 2.2-.3l2.9-7.9s.1-.2.2-.2h7.8V6.7h-7.8Zm5.3 3.4-1.9 1.9-1.9-1.9-1.1 1.1 1.9 1.9-1.9 1.9 1.1 1.1 1.9-1.9 1.9 1.9 1.1-1.1-1.9-1.9 1.9-1.9-1.1-1.1Z" }) }); 196 197 // packages/icons/build-module/library/subscript.js 198 var import_primitives11 = __toESM(require_primitives()); 199 var import_jsx_runtime11 = __toESM(require_jsx_runtime()); 200 var subscript_default = /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_primitives11.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_primitives11.Path, { d: "M16.9 18.3l.8-1.2c.4-.6.7-1.2.9-1.6.2-.4.3-.8.3-1.2 0-.3-.1-.7-.2-1-.1-.3-.4-.5-.6-.7-.3-.2-.6-.3-1-.3s-.8.1-1.1.2c-.3.1-.7.3-1 .6l.2 1.3c.3-.3.5-.5.8-.6s.6-.2.9-.2c.3 0 .5.1.7.2.2.2.2.4.2.7 0 .3-.1.5-.2.8-.1.3-.4.7-.8 1.3L15 19.4h4.3v-1.2h-2.4zM14.1 7.2h-2L9.5 11 6.9 7.2h-2l3.6 5.3L4.7 18h2l2.7-4 2.7 4h2l-3.8-5.5 3.8-5.3z" }) }); 201 202 // packages/icons/build-module/library/superscript.js 203 var import_primitives12 = __toESM(require_primitives()); 204 var import_jsx_runtime12 = __toESM(require_jsx_runtime()); 205 var superscript_default = /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_primitives12.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_primitives12.Path, { d: "M16.9 10.3l.8-1.3c.4-.6.7-1.2.9-1.6.2-.4.3-.8.3-1.2 0-.3-.1-.7-.2-1-.2-.2-.4-.4-.7-.6-.3-.2-.6-.3-1-.3s-.8.1-1.1.2c-.3.1-.7.3-1 .6l.1 1.3c.3-.3.5-.5.8-.6s.6-.2.9-.2c.3 0 .5.1.7.2.2.2.2.4.2.7 0 .3-.1.5-.2.8-.1.3-.4.7-.8 1.3l-1.8 2.8h4.3v-1.2h-2.2zm-2.8-3.1h-2L9.5 11 6.9 7.2h-2l3.6 5.3L4.7 18h2l2.7-4 2.7 4h2l-3.8-5.5 3.8-5.3z" }) }); 206 207 // packages/icons/build-module/library/text-color.js 208 var import_primitives13 = __toESM(require_primitives()); 209 var import_jsx_runtime13 = __toESM(require_jsx_runtime()); 210 var text_color_default = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_primitives13.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_primitives13.Path, { d: "M12.9 6h-2l-4 11h1.9l1.1-3h4.2l1.1 3h1.9L12.9 6zm-2.5 6.5l1.5-4.9 1.7 4.9h-3.2z" }) }); 211 212 // packages/format-library/build-module/lock-unlock.js 213 var import_private_apis = __toESM(require_private_apis()); 214 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)( 215 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.", 216 "@wordpress/format-library" 217 ); 218 219 // packages/format-library/build-module/bold/index.js 220 var import_jsx_runtime14 = __toESM(require_jsx_runtime()); 221 var { essentialFormatKey } = unlock(import_block_editor.privateApis); 222 var name = "core/bold"; 223 var title = (0, import_i18n.__)("Bold"); 224 var bold = { 225 name, 226 title, 227 tagName: "strong", 228 className: null, 229 [essentialFormatKey]: true, 230 edit({ isActive, value, onChange, onFocus, isVisible = true }) { 231 function onToggle() { 232 onChange((0, import_rich_text.toggleFormat)(value, { type: name, title })); 233 } 234 function onClick() { 235 onChange((0, import_rich_text.toggleFormat)(value, { type: name })); 236 onFocus(); 237 } 238 return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [ 239 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)( 240 import_block_editor.RichTextShortcut, 241 { 242 type: "primary", 243 character: "b", 244 onUse: onToggle 245 } 246 ), 247 isVisible && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)( 248 import_block_editor.RichTextToolbarButton, 249 { 250 name: "bold", 251 icon: format_bold_default, 252 title, 253 onClick, 254 isActive, 255 shortcutType: "primary", 256 shortcutCharacter: "b" 257 } 258 ), 259 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)( 260 import_block_editor.__unstableRichTextInputEvent, 261 { 262 inputType: "formatBold", 263 onInput: onToggle 264 } 265 ) 266 ] }); 267 } 268 }; 269 270 // packages/format-library/build-module/code/index.js 271 var import_i18n2 = __toESM(require_i18n()); 272 var import_rich_text2 = __toESM(require_rich_text()); 273 var import_block_editor2 = __toESM(require_block_editor()); 274 var import_jsx_runtime15 = __toESM(require_jsx_runtime()); 275 var name2 = "core/code"; 276 var title2 = (0, import_i18n2.__)("Inline code"); 277 var code = { 278 name: name2, 279 title: title2, 280 tagName: "code", 281 className: null, 282 __unstableInputRule(value) { 283 const BACKTICK = "`"; 284 const { start, text } = value; 285 const characterBefore = text[start - 1]; 286 if (characterBefore !== BACKTICK) { 287 return value; 288 } 289 if (start - 2 < 0) { 290 return value; 291 } 292 const indexBefore = text.lastIndexOf(BACKTICK, start - 2); 293 if (indexBefore === -1) { 294 return value; 295 } 296 const startIndex = indexBefore; 297 const endIndex = start - 2; 298 if (startIndex === endIndex) { 299 return value; 300 } 301 value = (0, import_rich_text2.remove)(value, startIndex, startIndex + 1); 302 value = (0, import_rich_text2.remove)(value, endIndex, endIndex + 1); 303 value = (0, import_rich_text2.applyFormat)(value, { type: name2 }, startIndex, endIndex); 304 return value; 305 }, 306 edit({ value, onChange, onFocus, isActive }) { 307 function onClick() { 308 onChange((0, import_rich_text2.toggleFormat)(value, { type: name2, title: title2 })); 309 onFocus(); 310 } 311 return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [ 312 /* @__PURE__ */ (0, import_jsx_runtime15.jsx)( 313 import_block_editor2.RichTextShortcut, 314 { 315 type: "access", 316 character: "x", 317 onUse: onClick 318 } 319 ), 320 /* @__PURE__ */ (0, import_jsx_runtime15.jsx)( 321 import_block_editor2.RichTextToolbarButton, 322 { 323 icon: code_default, 324 title: title2, 325 onClick, 326 isActive, 327 role: "menuitemcheckbox" 328 } 329 ) 330 ] }); 331 } 332 }; 333 334 // packages/format-library/build-module/image/index.js 335 var import_components = __toESM(require_components()); 336 var import_i18n3 = __toESM(require_i18n()); 337 var import_element2 = __toESM(require_element()); 338 var import_rich_text3 = __toESM(require_rich_text()); 339 var import_block_editor3 = __toESM(require_block_editor()); 340 var import_jsx_runtime16 = __toESM(require_jsx_runtime()); 341 var ALLOWED_MEDIA_TYPES = ["image"]; 342 var name3 = "core/image"; 343 var title3 = (0, import_i18n3.__)("Inline image"); 344 function getCurrentImageId(activeObjectAttributes) { 345 if (!activeObjectAttributes?.className) { 346 return void 0; 347 } 348 const [, id] = activeObjectAttributes.className.match(/wp-image-(\d+)/) ?? []; 349 return id ? parseInt(id, 10) : void 0; 350 } 351 var image = { 352 name: name3, 353 title: title3, 354 keywords: [(0, import_i18n3.__)("photo"), (0, import_i18n3.__)("media")], 355 object: true, 356 tagName: "img", 357 className: null, 358 attributes: { 359 className: "class", 360 style: "style", 361 url: "src", 362 alt: "alt" 363 }, 364 edit: Edit 365 }; 366 function InlineUI({ value, onChange, activeObjectAttributes, contentRef }) { 367 const { style, alt } = activeObjectAttributes; 368 const width = style?.replace(/\D/g, ""); 369 const [editedWidth, setEditedWidth] = (0, import_element2.useState)(width); 370 const [editedAlt, setEditedAlt] = (0, import_element2.useState)(alt); 371 const hasChanged = editedWidth !== width || editedAlt !== alt; 372 const popoverAnchor = (0, import_rich_text3.useAnchor)({ 373 editableContentElement: contentRef.current, 374 settings: image 375 }); 376 return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( 377 import_components.Popover, 378 { 379 focusOnMount: false, 380 anchor: popoverAnchor, 381 className: "block-editor-format-toolbar__image-popover", 382 children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( 383 "form", 384 { 385 className: "block-editor-format-toolbar__image-container-content", 386 onSubmit: (event) => { 387 const newReplacements = value.replacements.slice(); 388 newReplacements[value.start] = { 389 type: name3, 390 attributes: { 391 ...activeObjectAttributes, 392 style: editedWidth ? `width: $editedWidth}px;` : "", 393 alt: editedAlt 394 } 395 }; 396 onChange({ 397 ...value, 398 replacements: newReplacements 399 }); 400 event.preventDefault(); 401 }, 402 children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_components.__experimentalVStack, { spacing: 4, children: [ 403 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( 404 import_components.__experimentalNumberControl, 405 { 406 __next40pxDefaultSize: true, 407 label: (0, import_i18n3.__)("Width"), 408 value: editedWidth, 409 min: 1, 410 onChange: (newWidth) => { 411 setEditedWidth(newWidth); 412 } 413 } 414 ), 415 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( 416 import_components.TextareaControl, 417 { 418 label: (0, import_i18n3.__)("Alternative text"), 419 value: editedAlt, 420 onChange: (newAlt) => { 421 setEditedAlt(newAlt); 422 }, 423 help: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_jsx_runtime16.Fragment, { children: [ 424 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( 425 import_components.ExternalLink, 426 { 427 href: ( 428 // translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations. 429 (0, import_i18n3.__)( 430 "https://www.w3.org/WAI/tutorials/images/decision-tree/" 431 ) 432 ), 433 children: (0, import_i18n3.__)( 434 "Describe the purpose of the image." 435 ) 436 } 437 ), 438 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("br", {}), 439 (0, import_i18n3.__)("Leave empty if decorative.") 440 ] }) 441 } 442 ), 443 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_components.__experimentalHStack, { justify: "right", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( 444 import_components.Button, 445 { 446 disabled: !hasChanged, 447 accessibleWhenDisabled: true, 448 variant: "primary", 449 type: "submit", 450 size: "compact", 451 children: (0, import_i18n3.__)("Apply") 452 } 453 ) }) 454 ] }) 455 } 456 ) 457 } 458 ); 459 } 460 function Edit({ 461 value, 462 onChange, 463 onFocus, 464 isObjectActive, 465 activeObjectAttributes, 466 contentRef 467 }) { 468 return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_block_editor3.MediaUploadCheck, { children: [ 469 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( 470 import_block_editor3.MediaUpload, 471 { 472 allowedTypes: ALLOWED_MEDIA_TYPES, 473 value: getCurrentImageId(activeObjectAttributes), 474 onSelect: ({ id, url, alt, width: imgWidth }) => { 475 onChange( 476 (0, import_rich_text3.insertObject)(value, { 477 type: name3, 478 attributes: { 479 className: `wp-image-$id}`, 480 style: `width: $Math.min( 481 imgWidth, 482 150 483 )}px;`, 484 url, 485 alt 486 } 487 }) 488 ); 489 onFocus(); 490 }, 491 render: ({ open }) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( 492 import_block_editor3.RichTextToolbarButton, 493 { 494 icon: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( 495 import_components.SVG, 496 { 497 xmlns: "http://www.w3.org/2000/svg", 498 viewBox: "0 0 24 24", 499 children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_components.Path, { d: "M4 18.5h16V17H4v1.5zM16 13v1.5h4V13h-4zM5.1 15h7.8c.6 0 1.1-.5 1.1-1.1V6.1c0-.6-.5-1.1-1.1-1.1H5.1C4.5 5 4 5.5 4 6.1v7.8c0 .6.5 1.1 1.1 1.1zm.4-8.5h7V10l-1-1c-.3-.3-.8-.3-1 0l-1.6 1.5-1.2-.7c-.3-.2-.6-.2-.9 0l-1.3 1V6.5zm0 6.1l1.8-1.3 1.3.8c.3.2.7.2.9-.1l1.5-1.4 1.5 1.4v1.5h-7v-.9z" }) 500 } 501 ), 502 title: isObjectActive ? (0, import_i18n3.__)("Replace image") : title3, 503 onClick: open, 504 isActive: isObjectActive 505 } 506 ) 507 } 508 ), 509 isObjectActive && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( 510 InlineUI, 511 { 512 value, 513 onChange, 514 activeObjectAttributes, 515 contentRef 516 } 517 ) 518 ] }); 519 } 520 521 // packages/format-library/build-module/italic/index.js 522 var import_i18n4 = __toESM(require_i18n()); 523 var import_rich_text4 = __toESM(require_rich_text()); 524 var import_block_editor4 = __toESM(require_block_editor()); 525 var import_jsx_runtime17 = __toESM(require_jsx_runtime()); 526 var { essentialFormatKey: essentialFormatKey2 } = unlock(import_block_editor4.privateApis); 527 var name4 = "core/italic"; 528 var title4 = (0, import_i18n4.__)("Italic"); 529 var italic = { 530 name: name4, 531 title: title4, 532 tagName: "em", 533 className: null, 534 [essentialFormatKey2]: true, 535 edit({ isActive, value, onChange, onFocus, isVisible = true }) { 536 function onToggle() { 537 onChange((0, import_rich_text4.toggleFormat)(value, { type: name4, title: title4 })); 538 } 539 function onClick() { 540 onChange((0, import_rich_text4.toggleFormat)(value, { type: name4 })); 541 onFocus(); 542 } 543 return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [ 544 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)( 545 import_block_editor4.RichTextShortcut, 546 { 547 type: "primary", 548 character: "i", 549 onUse: onToggle 550 } 551 ), 552 isVisible && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)( 553 import_block_editor4.RichTextToolbarButton, 554 { 555 name: "italic", 556 icon: format_italic_default, 557 title: title4, 558 onClick, 559 isActive, 560 shortcutType: "primary", 561 shortcutCharacter: "i" 562 } 563 ), 564 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)( 565 import_block_editor4.__unstableRichTextInputEvent, 566 { 567 inputType: "formatItalic", 568 onInput: onToggle 569 } 570 ) 571 ] }); 572 } 573 }; 574 575 // packages/format-library/build-module/link/index.js 576 var import_i18n7 = __toESM(require_i18n()); 577 var import_element5 = __toESM(require_element()); 578 var import_rich_text6 = __toESM(require_rich_text()); 579 var import_url3 = __toESM(require_url()); 580 var import_block_editor6 = __toESM(require_block_editor()); 581 var import_html_entities = __toESM(require_html_entities()); 582 var import_a11y2 = __toESM(require_a11y()); 583 584 // packages/format-library/build-module/link/inline.js 585 var import_element4 = __toESM(require_element()); 586 var import_i18n6 = __toESM(require_i18n()); 587 var import_a11y = __toESM(require_a11y()); 588 var import_components3 = __toESM(require_components()); 589 var import_url2 = __toESM(require_url()); 590 var import_rich_text5 = __toESM(require_rich_text()); 591 var import_block_editor5 = __toESM(require_block_editor()); 592 var import_data = __toESM(require_data()); 593 594 // packages/format-library/build-module/link/utils.js 595 var import_url = __toESM(require_url()); 596 function isValidHref(href) { 597 if (!href) { 598 return false; 599 } 600 const trimmedHref = href.trim(); 601 if (!trimmedHref) { 602 return false; 603 } 604 if (/^\S+:/.test(trimmedHref)) { 605 const protocol = (0, import_url.getProtocol)(trimmedHref); 606 if (!(0, import_url.isValidProtocol)(protocol)) { 607 return false; 608 } 609 if (protocol.startsWith("http") && !/^https?:\/\/[^\/\s]/i.test(trimmedHref)) { 610 return false; 611 } 612 const authority = (0, import_url.getAuthority)(trimmedHref); 613 if (!(0, import_url.isValidAuthority)(authority)) { 614 return false; 615 } 616 const path = (0, import_url.getPath)(trimmedHref); 617 if (path && !(0, import_url.isValidPath)(path)) { 618 return false; 619 } 620 const queryString = (0, import_url.getQueryString)(trimmedHref); 621 if (queryString && !(0, import_url.isValidQueryString)(queryString)) { 622 return false; 623 } 624 const fragment = (0, import_url.getFragment)(trimmedHref); 625 if (fragment && !(0, import_url.isValidFragment)(fragment)) { 626 return false; 627 } 628 } 629 if (trimmedHref.startsWith("#") && !(0, import_url.isValidFragment)(trimmedHref)) { 630 return false; 631 } 632 return true; 633 } 634 function createLinkFormat({ 635 url, 636 type, 637 id, 638 opensInNewWindow, 639 nofollow, 640 cssClasses 641 }) { 642 const format = { 643 type: "core/link", 644 attributes: { 645 url 646 } 647 }; 648 if (type) { 649 format.attributes.type = type; 650 } 651 if (id) { 652 format.attributes.id = id; 653 } 654 if (opensInNewWindow) { 655 format.attributes.target = "_blank"; 656 format.attributes.rel = format.attributes.rel ? format.attributes.rel + " noreferrer noopener" : "noreferrer noopener"; 657 } 658 if (nofollow) { 659 format.attributes.rel = format.attributes.rel ? format.attributes.rel + " nofollow" : "nofollow"; 660 } 661 const trimmedCssClasses = cssClasses?.trim(); 662 if (trimmedCssClasses?.length) { 663 format.attributes.class = trimmedCssClasses; 664 } 665 return format; 666 } 667 function getFormatBoundary(value, format, startIndex = value.start, endIndex = value.end) { 668 const EMPTY_BOUNDARIES = { 669 start: null, 670 end: null 671 }; 672 const { formats } = value; 673 let targetFormat; 674 let initialIndex; 675 if (!formats?.length) { 676 return EMPTY_BOUNDARIES; 677 } 678 const newFormats = formats.slice(); 679 const formatAtStart = newFormats[startIndex]?.find( 680 ({ type }) => type === format.type 681 ); 682 const formatAtEnd = newFormats[endIndex]?.find( 683 ({ type }) => type === format.type 684 ); 685 const formatAtEndMinusOne = newFormats[endIndex - 1]?.find( 686 ({ type }) => type === format.type 687 ); 688 if (!!formatAtStart) { 689 targetFormat = formatAtStart; 690 initialIndex = startIndex; 691 } else if (!!formatAtEnd) { 692 targetFormat = formatAtEnd; 693 initialIndex = endIndex; 694 } else if (!!formatAtEndMinusOne) { 695 targetFormat = formatAtEndMinusOne; 696 initialIndex = endIndex - 1; 697 } else { 698 return EMPTY_BOUNDARIES; 699 } 700 const index = newFormats[initialIndex].indexOf(targetFormat); 701 const walkingArgs = [newFormats, initialIndex, targetFormat, index]; 702 startIndex = walkToStart(...walkingArgs); 703 endIndex = walkToEnd(...walkingArgs); 704 startIndex = startIndex < 0 ? 0 : startIndex; 705 return { 706 start: startIndex, 707 end: endIndex 708 }; 709 } 710 function walkToBoundary(formats, initialIndex, targetFormatRef, formatIndex, direction) { 711 let index = initialIndex; 712 const directions = { 713 forwards: 1, 714 backwards: -1 715 }; 716 const directionIncrement = directions[direction] || 1; 717 const inverseDirectionIncrement = directionIncrement * -1; 718 while (formats[index] && formats[index][formatIndex] === targetFormatRef) { 719 index = index + directionIncrement; 720 } 721 index = index + inverseDirectionIncrement; 722 return index; 723 } 724 var partialRight = (fn, ...partialArgs) => (...args) => fn(...args, ...partialArgs); 725 var walkToStart = partialRight(walkToBoundary, "backwards"); 726 var walkToEnd = partialRight(walkToBoundary, "forwards"); 727 728 // packages/format-library/build-module/link/css-classes-setting.js 729 var import_element3 = __toESM(require_element()); 730 var import_compose = __toESM(require_compose()); 731 var import_i18n5 = __toESM(require_i18n()); 732 var import_components2 = __toESM(require_components()); 733 var import_jsx_runtime18 = __toESM(require_jsx_runtime()); 734 var CSSClassesSettingComponent = ({ setting, value, onChange }) => { 735 const hasValue = value ? value?.cssClasses?.length > 0 : false; 736 const [isSettingActive, setIsSettingActive] = (0, import_element3.useState)(hasValue); 737 const instanceId = (0, import_compose.useInstanceId)(CSSClassesSettingComponent); 738 const controlledRegionId = `css-classes-setting-$instanceId}`; 739 const handleSettingChange = (newValue) => { 740 const sanitizedValue = typeof newValue === "string" ? newValue.replace(/,/g, " ").replace(/\s+/g, " ").trim() : newValue; 741 onChange({ 742 ...value, 743 [setting.id]: sanitizedValue 744 }); 745 }; 746 const handleCheckboxChange = () => { 747 if (isSettingActive) { 748 if (hasValue) { 749 handleSettingChange(""); 750 } 751 setIsSettingActive(false); 752 } else { 753 setIsSettingActive(true); 754 } 755 }; 756 return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("fieldset", { children: [ 757 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_components2.VisuallyHidden, { as: "legend", children: setting.title }), 758 /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_components2.__experimentalVStack, { spacing: 3, children: [ 759 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)( 760 import_components2.CheckboxControl, 761 { 762 label: setting.title, 763 onChange: handleCheckboxChange, 764 checked: isSettingActive || hasValue, 765 "aria-expanded": isSettingActive, 766 "aria-controls": isSettingActive ? controlledRegionId : void 0 767 } 768 ), 769 isSettingActive && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { id: controlledRegionId, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)( 770 import_components2.__experimentalInputControl, 771 { 772 label: (0, import_i18n5.__)("CSS classes"), 773 value: value?.cssClasses, 774 onChange: handleSettingChange, 775 help: (0, import_i18n5.__)( 776 "Separate multiple classes with spaces." 777 ), 778 __unstableInputWidth: "100%", 779 __next40pxDefaultSize: true 780 } 781 ) }) 782 ] }) 783 ] }); 784 }; 785 var css_classes_setting_default = CSSClassesSettingComponent; 786 787 // packages/format-library/build-module/link/inline.js 788 var import_jsx_runtime19 = __toESM(require_jsx_runtime()); 789 var LINK_SETTINGS = [ 790 ...import_block_editor5.LinkControl.DEFAULT_LINK_SETTINGS, 791 { 792 id: "nofollow", 793 title: (0, import_i18n6.__)("Mark as nofollow") 794 }, 795 { 796 id: "cssClasses", 797 title: (0, import_i18n6.__)("Additional CSS class(es)"), 798 render: (setting, value, onChange) => { 799 return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)( 800 css_classes_setting_default, 801 { 802 setting, 803 value, 804 onChange 805 } 806 ); 807 } 808 } 809 ]; 810 function InlineLinkUI({ 811 isActive, 812 activeAttributes, 813 value, 814 onChange, 815 onFocusOutside, 816 stopAddingLink, 817 contentRef, 818 focusOnMount 819 }) { 820 const richLinkTextValue = getRichTextValueFromSelection(value, isActive); 821 const richTextText = richLinkTextValue.text; 822 const { selectionChange } = (0, import_data.useDispatch)(import_block_editor5.store); 823 const { createPageEntity, userCanCreatePages, selectionStart } = (0, import_data.useSelect)( 824 (select) => { 825 const { getSettings, getSelectionStart } = select(import_block_editor5.store); 826 const _settings = getSettings(); 827 return { 828 createPageEntity: _settings.__experimentalCreatePageEntity, 829 userCanCreatePages: _settings.__experimentalUserCanCreatePages, 830 selectionStart: getSelectionStart() 831 }; 832 }, 833 [] 834 ); 835 const linkValue = (0, import_element4.useMemo)( 836 () => ({ 837 url: activeAttributes.url, 838 type: activeAttributes.type, 839 id: activeAttributes.id, 840 opensInNewTab: activeAttributes.target === "_blank", 841 nofollow: activeAttributes.rel?.includes("nofollow"), 842 title: richTextText, 843 cssClasses: activeAttributes.class 844 }), 845 [ 846 activeAttributes.class, 847 activeAttributes.id, 848 activeAttributes.rel, 849 activeAttributes.target, 850 activeAttributes.type, 851 activeAttributes.url, 852 richTextText 853 ] 854 ); 855 function removeLink() { 856 const newValue = (0, import_rich_text5.removeFormat)(value, "core/link"); 857 onChange(newValue); 858 stopAddingLink(); 859 (0, import_a11y.speak)((0, import_i18n6.__)("Link removed."), "assertive"); 860 } 861 function onChangeLink(nextValue) { 862 const hasLink = linkValue?.url; 863 const isNewLink = !hasLink; 864 nextValue = { 865 ...linkValue, 866 ...nextValue 867 }; 868 const newUrl = (0, import_url2.prependHTTP)(nextValue.url); 869 const linkFormat = createLinkFormat({ 870 url: newUrl, 871 type: nextValue.type, 872 id: nextValue.id !== void 0 && nextValue.id !== null ? String(nextValue.id) : void 0, 873 opensInNewWindow: nextValue.opensInNewTab, 874 nofollow: nextValue.nofollow, 875 cssClasses: nextValue.cssClasses 876 }); 877 const newText = nextValue.title || newUrl; 878 let newValue; 879 if ((0, import_rich_text5.isCollapsed)(value) && !isActive) { 880 const inserted = (0, import_rich_text5.insert)(value, newText); 881 newValue = (0, import_rich_text5.applyFormat)( 882 inserted, 883 linkFormat, 884 value.start, 885 value.start + newText.length 886 ); 887 onChange(newValue); 888 stopAddingLink(); 889 selectionChange({ 890 clientId: selectionStart.clientId, 891 identifier: selectionStart.attributeKey, 892 start: value.start + newText.length + 1 893 }); 894 return; 895 } else if (newText === richTextText) { 896 newValue = (0, import_rich_text5.applyFormat)(value, linkFormat); 897 } else { 898 newValue = (0, import_rich_text5.create)({ text: newText }); 899 newValue = (0, import_rich_text5.applyFormat)(newValue, linkFormat, 0, newText.length); 900 const boundary = getFormatBoundary(value, { 901 type: "core/link" 902 }); 903 const [valBefore, valAfter] = (0, import_rich_text5.split)( 904 value, 905 boundary.start, 906 boundary.start 907 ); 908 const newValAfter = (0, import_rich_text5.replace)(valAfter, richTextText, newValue); 909 newValue = (0, import_rich_text5.concat)(valBefore, newValAfter); 910 } 911 onChange(newValue); 912 if (!isNewLink) { 913 stopAddingLink(); 914 } 915 if (!isValidHref(newUrl)) { 916 (0, import_a11y.speak)( 917 (0, import_i18n6.__)( 918 "Warning: the link has been inserted but may have errors. Please test it." 919 ), 920 "assertive" 921 ); 922 } else if (isActive) { 923 (0, import_a11y.speak)((0, import_i18n6.__)("Link edited."), "assertive"); 924 } else { 925 (0, import_a11y.speak)((0, import_i18n6.__)("Link inserted."), "assertive"); 926 } 927 } 928 const popoverAnchor = (0, import_rich_text5.useAnchor)({ 929 editableContentElement: contentRef.current, 930 settings: { 931 ...link, 932 isActive 933 } 934 }); 935 async function handleCreate(pageTitle) { 936 const page = await createPageEntity({ 937 title: pageTitle, 938 status: "draft" 939 }); 940 return { 941 id: page.id, 942 type: page.type, 943 title: page.title.rendered, 944 url: page.link, 945 kind: "post-type" 946 }; 947 } 948 function createButtonText(searchTerm) { 949 return (0, import_element4.createInterpolateElement)( 950 (0, import_i18n6.sprintf)( 951 /* translators: %s: search term. */ 952 (0, import_i18n6.__)("Create page: <mark>%s</mark>"), 953 searchTerm 954 ), 955 { mark: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("mark", {}) } 956 ); 957 } 958 return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)( 959 import_components3.Popover, 960 { 961 anchor: popoverAnchor, 962 animate: false, 963 onClose: stopAddingLink, 964 onFocusOutside, 965 placement: "bottom", 966 offset: 8, 967 shift: true, 968 focusOnMount, 969 constrainTabbing: true, 970 children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)( 971 import_block_editor5.LinkControl, 972 { 973 value: linkValue, 974 onChange: onChangeLink, 975 onRemove: removeLink, 976 hasRichPreviews: true, 977 createSuggestion: createPageEntity && handleCreate, 978 withCreateSuggestion: userCanCreatePages, 979 createSuggestionButtonText: createButtonText, 980 hasTextControl: true, 981 settings: LINK_SETTINGS, 982 showInitialSuggestions: true, 983 suggestionsQuery: { 984 // always show Pages as initial suggestions 985 initialSuggestionsSearchOptions: { 986 type: "post", 987 subtype: "page", 988 perPage: 20 989 } 990 } 991 } 992 ) 993 } 994 ); 995 } 996 function getRichTextValueFromSelection(value, isActive) { 997 let textStart = value.start; 998 let textEnd = value.end; 999 if (isActive) { 1000 const boundary = getFormatBoundary(value, { 1001 type: "core/link" 1002 }); 1003 textStart = boundary.start; 1004 textEnd = boundary.end + 1; 1005 } 1006 return (0, import_rich_text5.slice)(value, textStart, textEnd); 1007 } 1008 var inline_default = InlineLinkUI; 1009 1010 // packages/format-library/build-module/link/index.js 1011 var import_jsx_runtime20 = __toESM(require_jsx_runtime()); 1012 var { essentialFormatKey: essentialFormatKey3 } = unlock(import_block_editor6.privateApis); 1013 var name5 = "core/link"; 1014 var title5 = (0, import_i18n7.__)("Link"); 1015 function Edit2({ 1016 isActive, 1017 activeAttributes, 1018 value, 1019 onChange, 1020 onFocus, 1021 contentRef, 1022 isVisible = true 1023 }) { 1024 const [addingLink, setAddingLink] = (0, import_element5.useState)(false); 1025 const [openedBy, setOpenedBy] = (0, import_element5.useState)(null); 1026 (0, import_element5.useEffect)(() => { 1027 if (!isActive) { 1028 setAddingLink(false); 1029 } 1030 }, [isActive]); 1031 (0, import_element5.useLayoutEffect)(() => { 1032 const editableContentElement = contentRef.current; 1033 if (!editableContentElement) { 1034 return; 1035 } 1036 function handleClick(event) { 1037 const link2 = event.target.closest("[contenteditable] a"); 1038 if (!link2 || // other formats (e.g. bold) may be nested within the link. 1039 !isActive) { 1040 return; 1041 } 1042 setAddingLink(true); 1043 setOpenedBy({ 1044 el: link2, 1045 action: "click" 1046 }); 1047 } 1048 editableContentElement.addEventListener("click", handleClick); 1049 return () => { 1050 editableContentElement.removeEventListener("click", handleClick); 1051 }; 1052 }, [contentRef, isActive]); 1053 function addLink(target) { 1054 const text = (0, import_rich_text6.getTextContent)((0, import_rich_text6.slice)(value)); 1055 if (!isActive && text && (0, import_url3.isURL)(text) && isValidHref(text)) { 1056 onChange( 1057 (0, import_rich_text6.applyFormat)(value, { 1058 type: name5, 1059 attributes: { url: text } 1060 }) 1061 ); 1062 } else if (!isActive && text && (0, import_url3.isEmail)(text)) { 1063 onChange( 1064 (0, import_rich_text6.applyFormat)(value, { 1065 type: name5, 1066 attributes: { url: `mailto:$text}` } 1067 }) 1068 ); 1069 } else if (!isActive && text && (0, import_url3.isPhoneNumber)(text)) { 1070 onChange( 1071 (0, import_rich_text6.applyFormat)(value, { 1072 type: name5, 1073 attributes: { url: `tel:$text.replace(/\D/g, "")}` } 1074 }) 1075 ); 1076 } else { 1077 if (target) { 1078 setOpenedBy({ 1079 el: target, 1080 action: null 1081 // We don't need to distinguish between click or keyboard here 1082 }); 1083 } 1084 setAddingLink(true); 1085 } 1086 } 1087 function stopAddingLink() { 1088 setAddingLink(false); 1089 if (openedBy?.el?.tagName === "BUTTON") { 1090 openedBy.el.focus(); 1091 } else { 1092 onFocus(); 1093 } 1094 setOpenedBy(null); 1095 } 1096 function onFocusOutside() { 1097 setAddingLink(false); 1098 setOpenedBy(null); 1099 } 1100 function onRemoveFormat() { 1101 onChange((0, import_rich_text6.removeFormat)(value, name5)); 1102 (0, import_a11y2.speak)((0, import_i18n7.__)("Link removed."), "assertive"); 1103 } 1104 const shouldAutoFocus = !(openedBy?.el?.tagName === "A" && openedBy?.action === "click"); 1105 const hasSelection = !(0, import_rich_text6.isCollapsed)(value); 1106 return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [ 1107 hasSelection && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)( 1108 import_block_editor6.RichTextShortcut, 1109 { 1110 type: "primary", 1111 character: "k", 1112 onUse: addLink 1113 } 1114 ), 1115 /* @__PURE__ */ (0, import_jsx_runtime20.jsx)( 1116 import_block_editor6.RichTextShortcut, 1117 { 1118 type: "primaryShift", 1119 character: "k", 1120 onUse: onRemoveFormat 1121 } 1122 ), 1123 isVisible && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)( 1124 import_block_editor6.RichTextToolbarButton, 1125 { 1126 name: "link", 1127 icon: link_default, 1128 title: isActive ? (0, import_i18n7.__)("Link") : title5, 1129 onClick: (event) => { 1130 addLink(event.currentTarget); 1131 }, 1132 isActive: isActive || addingLink, 1133 shortcutType: "primary", 1134 shortcutCharacter: "k", 1135 "aria-haspopup": "true", 1136 "aria-expanded": addingLink 1137 } 1138 ), 1139 isVisible && addingLink && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)( 1140 inline_default, 1141 { 1142 stopAddingLink, 1143 onFocusOutside, 1144 isActive, 1145 activeAttributes, 1146 value, 1147 onChange, 1148 contentRef, 1149 focusOnMount: shouldAutoFocus ? "firstElement" : false 1150 } 1151 ) 1152 ] }); 1153 } 1154 var link = { 1155 name: name5, 1156 title: title5, 1157 tagName: "a", 1158 className: null, 1159 attributes: { 1160 url: "href", 1161 type: "data-type", 1162 id: "data-id", 1163 _id: "id", 1164 target: "target", 1165 rel: "rel", 1166 class: "class" 1167 }, 1168 [essentialFormatKey3]: true, 1169 __unstablePasteRule(value, { html, plainText }) { 1170 const pastedText = (html || plainText).replace(/<[^>]+>/g, "").trim(); 1171 if (!(0, import_url3.isURL)(pastedText) || !/^https?:/.test(pastedText)) { 1172 return value; 1173 } 1174 window.console.log("Created link:\n\n", pastedText); 1175 const format = { 1176 type: name5, 1177 attributes: { 1178 url: (0, import_html_entities.decodeEntities)(pastedText) 1179 } 1180 }; 1181 if ((0, import_rich_text6.isCollapsed)(value)) { 1182 return (0, import_rich_text6.insert)( 1183 value, 1184 (0, import_rich_text6.applyFormat)( 1185 (0, import_rich_text6.create)({ text: plainText }), 1186 format, 1187 0, 1188 plainText.length 1189 ) 1190 ); 1191 } 1192 return (0, import_rich_text6.applyFormat)(value, format); 1193 }, 1194 edit: Edit2 1195 }; 1196 1197 // packages/format-library/build-module/strikethrough/index.js 1198 var import_i18n8 = __toESM(require_i18n()); 1199 var import_rich_text7 = __toESM(require_rich_text()); 1200 var import_block_editor7 = __toESM(require_block_editor()); 1201 var import_jsx_runtime21 = __toESM(require_jsx_runtime()); 1202 var name6 = "core/strikethrough"; 1203 var title6 = (0, import_i18n8.__)("Strikethrough"); 1204 var strikethrough = { 1205 name: name6, 1206 title: title6, 1207 tagName: "s", 1208 className: null, 1209 edit({ isActive, value, onChange, onFocus }) { 1210 function onClick() { 1211 onChange((0, import_rich_text7.toggleFormat)(value, { type: name6, title: title6 })); 1212 onFocus(); 1213 } 1214 return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [ 1215 /* @__PURE__ */ (0, import_jsx_runtime21.jsx)( 1216 import_block_editor7.RichTextShortcut, 1217 { 1218 type: "access", 1219 character: "d", 1220 onUse: onClick 1221 } 1222 ), 1223 /* @__PURE__ */ (0, import_jsx_runtime21.jsx)( 1224 import_block_editor7.RichTextToolbarButton, 1225 { 1226 icon: format_strikethrough_default, 1227 title: title6, 1228 onClick, 1229 isActive, 1230 role: "menuitemcheckbox" 1231 } 1232 ) 1233 ] }); 1234 } 1235 }; 1236 1237 // packages/format-library/build-module/underline/index.js 1238 var import_i18n9 = __toESM(require_i18n()); 1239 var import_rich_text8 = __toESM(require_rich_text()); 1240 var import_block_editor8 = __toESM(require_block_editor()); 1241 var import_jsx_runtime22 = __toESM(require_jsx_runtime()); 1242 var name7 = "core/underline"; 1243 var title7 = (0, import_i18n9.__)("Underline"); 1244 var underline = { 1245 name: name7, 1246 title: title7, 1247 tagName: "span", 1248 className: null, 1249 attributes: { 1250 style: "style" 1251 }, 1252 edit({ value, onChange }) { 1253 const onToggle = () => { 1254 onChange( 1255 (0, import_rich_text8.toggleFormat)(value, { 1256 type: name7, 1257 attributes: { 1258 style: "text-decoration: underline;" 1259 }, 1260 title: title7 1261 }) 1262 ); 1263 }; 1264 return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [ 1265 /* @__PURE__ */ (0, import_jsx_runtime22.jsx)( 1266 import_block_editor8.RichTextShortcut, 1267 { 1268 type: "primary", 1269 character: "u", 1270 onUse: onToggle 1271 } 1272 ), 1273 /* @__PURE__ */ (0, import_jsx_runtime22.jsx)( 1274 import_block_editor8.__unstableRichTextInputEvent, 1275 { 1276 inputType: "formatUnderline", 1277 onInput: onToggle 1278 } 1279 ) 1280 ] }); 1281 } 1282 }; 1283 1284 // packages/format-library/build-module/text-color/index.js 1285 var import_i18n11 = __toESM(require_i18n()); 1286 var import_element7 = __toESM(require_element()); 1287 var import_block_editor10 = __toESM(require_block_editor()); 1288 var import_rich_text10 = __toESM(require_rich_text()); 1289 1290 // packages/format-library/build-module/text-color/inline.js 1291 var import_element6 = __toESM(require_element()); 1292 var import_data2 = __toESM(require_data()); 1293 var import_rich_text9 = __toESM(require_rich_text()); 1294 var import_block_editor9 = __toESM(require_block_editor()); 1295 var import_components4 = __toESM(require_components()); 1296 var import_i18n10 = __toESM(require_i18n()); 1297 var import_jsx_runtime23 = __toESM(require_jsx_runtime()); 1298 var { Tabs } = unlock(import_components4.privateApis); 1299 var TABS = [ 1300 { name: "color", title: (0, import_i18n10.__)("Text") }, 1301 { name: "backgroundColor", title: (0, import_i18n10.__)("Background") } 1302 ]; 1303 function parseCSS(css = "") { 1304 return css.split(";").reduce((accumulator, rule) => { 1305 if (rule) { 1306 const [property, value] = rule.split(":"); 1307 if (property === "color") { 1308 accumulator.color = value; 1309 } 1310 if (property === "background-color" && value !== transparentValue) { 1311 accumulator.backgroundColor = value; 1312 } 1313 } 1314 return accumulator; 1315 }, {}); 1316 } 1317 function parseClassName(className = "", colorSettings) { 1318 return className.split(" ").reduce((accumulator, name16) => { 1319 if (name16.startsWith("has-") && name16.endsWith("-color")) { 1320 const colorSlug = name16.replace(/^has-/, "").replace(/-color$/, ""); 1321 const colorObject = (0, import_block_editor9.getColorObjectByAttributeValues)( 1322 colorSettings, 1323 colorSlug 1324 ); 1325 accumulator.color = colorObject.color; 1326 } 1327 return accumulator; 1328 }, {}); 1329 } 1330 function getActiveColors(value, name16, colorSettings) { 1331 const activeColorFormat = (0, import_rich_text9.getActiveFormat)(value, name16); 1332 if (!activeColorFormat) { 1333 return {}; 1334 } 1335 return { 1336 ...parseCSS(activeColorFormat.attributes.style), 1337 ...parseClassName(activeColorFormat.attributes.class, colorSettings) 1338 }; 1339 } 1340 function setColors(value, name16, colorSettings, colors) { 1341 const { color, backgroundColor } = { 1342 ...getActiveColors(value, name16, colorSettings), 1343 ...colors 1344 }; 1345 if (!color && !backgroundColor) { 1346 return (0, import_rich_text9.removeFormat)(value, name16); 1347 } 1348 const styles = []; 1349 const classNames = []; 1350 const attributes = {}; 1351 if (backgroundColor) { 1352 styles.push(["background-color", backgroundColor].join(":")); 1353 } else { 1354 styles.push(["background-color", transparentValue].join(":")); 1355 } 1356 if (color) { 1357 const colorObject = (0, import_block_editor9.getColorObjectByColorValue)(colorSettings, color); 1358 if (colorObject) { 1359 classNames.push((0, import_block_editor9.getColorClassName)("color", colorObject.slug)); 1360 } else { 1361 styles.push(["color", color].join(":")); 1362 } 1363 } 1364 if (styles.length) { 1365 attributes.style = styles.join(";"); 1366 } 1367 if (classNames.length) { 1368 attributes.class = classNames.join(" "); 1369 } 1370 return (0, import_rich_text9.applyFormat)(value, { type: name16, attributes }); 1371 } 1372 function ColorPicker({ name: name16, property, value, onChange }) { 1373 const colors = (0, import_data2.useSelect)((select) => { 1374 const { getSettings } = select(import_block_editor9.store); 1375 return getSettings().colors ?? []; 1376 }, []); 1377 const activeColors = (0, import_element6.useMemo)( 1378 () => getActiveColors(value, name16, colors), 1379 [name16, value, colors] 1380 ); 1381 return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)( 1382 import_block_editor9.ColorPalette, 1383 { 1384 value: activeColors[property], 1385 onChange: (color) => { 1386 onChange( 1387 setColors(value, name16, colors, { [property]: color }) 1388 ); 1389 }, 1390 enableAlpha: true, 1391 __experimentalIsRenderedInSidebar: true 1392 } 1393 ); 1394 } 1395 function InlineColorUI({ 1396 name: name16, 1397 value, 1398 onChange, 1399 onClose, 1400 contentRef, 1401 isActive 1402 }) { 1403 const popoverAnchor = (0, import_rich_text9.useAnchor)({ 1404 editableContentElement: contentRef.current, 1405 settings: { ...textColor, isActive } 1406 }); 1407 return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)( 1408 import_components4.Popover, 1409 { 1410 onClose, 1411 className: "format-library__inline-color-popover", 1412 anchor: popoverAnchor, 1413 children: /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(Tabs, { children: [ 1414 /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Tabs.TabList, { children: TABS.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Tabs.Tab, { tabId: tab.name, children: tab.title }, tab.name)) }), 1415 TABS.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)( 1416 Tabs.TabPanel, 1417 { 1418 tabId: tab.name, 1419 focusable: false, 1420 children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)( 1421 ColorPicker, 1422 { 1423 name: name16, 1424 property: tab.name, 1425 value, 1426 onChange 1427 } 1428 ) 1429 }, 1430 tab.name 1431 )) 1432 ] }) 1433 } 1434 ); 1435 } 1436 1437 // packages/format-library/build-module/text-color/index.js 1438 var import_jsx_runtime24 = __toESM(require_jsx_runtime()); 1439 var transparentValue = "rgba(0, 0, 0, 0)"; 1440 var name8 = "core/text-color"; 1441 var title8 = (0, import_i18n11.__)("Highlight"); 1442 var EMPTY_ARRAY = []; 1443 function getComputedStyleProperty(element, property) { 1444 const { ownerDocument } = element; 1445 const { defaultView } = ownerDocument; 1446 const style = defaultView.getComputedStyle(element); 1447 const value = style.getPropertyValue(property); 1448 if (property === "background-color" && value === transparentValue && element.parentElement) { 1449 return getComputedStyleProperty(element.parentElement, property); 1450 } 1451 return value; 1452 } 1453 function fillComputedColors(element, { color, backgroundColor }) { 1454 if (!color && !backgroundColor) { 1455 return; 1456 } 1457 return { 1458 color: color || getComputedStyleProperty(element, "color"), 1459 backgroundColor: backgroundColor === transparentValue ? getComputedStyleProperty(element, "background-color") : backgroundColor 1460 }; 1461 } 1462 function TextColorEdit({ 1463 value, 1464 onChange, 1465 isActive, 1466 activeAttributes, 1467 contentRef 1468 }) { 1469 const [allowCustomControl, colors = EMPTY_ARRAY] = (0, import_block_editor10.useSettings)( 1470 "color.custom", 1471 "color.palette" 1472 ); 1473 const [isAddingColor, setIsAddingColor] = (0, import_element7.useState)(false); 1474 const colorIndicatorStyle = (0, import_element7.useMemo)( 1475 () => fillComputedColors( 1476 contentRef.current, 1477 getActiveColors(value, name8, colors) 1478 ), 1479 [contentRef, value, colors] 1480 ); 1481 const hasColorsToChoose = !!colors.length || allowCustomControl; 1482 if (!hasColorsToChoose && !isActive) { 1483 return null; 1484 } 1485 return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [ 1486 /* @__PURE__ */ (0, import_jsx_runtime24.jsx)( 1487 import_block_editor10.RichTextToolbarButton, 1488 { 1489 className: "format-library-text-color-button", 1490 isActive, 1491 icon: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)( 1492 icon_default, 1493 { 1494 icon: Object.keys(activeAttributes).length ? text_color_default : color_default, 1495 style: colorIndicatorStyle 1496 } 1497 ), 1498 title: title8, 1499 onClick: hasColorsToChoose ? () => setIsAddingColor(true) : () => onChange((0, import_rich_text10.removeFormat)(value, name8)), 1500 role: "menuitemcheckbox" 1501 } 1502 ), 1503 isAddingColor && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)( 1504 InlineColorUI, 1505 { 1506 name: name8, 1507 onClose: () => setIsAddingColor(false), 1508 activeAttributes, 1509 value, 1510 onChange, 1511 contentRef, 1512 isActive 1513 } 1514 ) 1515 ] }); 1516 } 1517 var textColor = { 1518 name: name8, 1519 title: title8, 1520 tagName: "mark", 1521 className: "has-inline-color", 1522 attributes: { 1523 style: "style", 1524 class: "class" 1525 }, 1526 edit: TextColorEdit 1527 }; 1528 1529 // packages/format-library/build-module/subscript/index.js 1530 var import_i18n12 = __toESM(require_i18n()); 1531 var import_rich_text11 = __toESM(require_rich_text()); 1532 var import_block_editor11 = __toESM(require_block_editor()); 1533 var import_jsx_runtime25 = __toESM(require_jsx_runtime()); 1534 var name9 = "core/subscript"; 1535 var title9 = (0, import_i18n12.__)("Subscript"); 1536 var subscript = { 1537 name: name9, 1538 title: title9, 1539 tagName: "sub", 1540 className: null, 1541 edit({ isActive, value, onChange, onFocus }) { 1542 function onToggle() { 1543 onChange((0, import_rich_text11.toggleFormat)(value, { type: name9, title: title9 })); 1544 } 1545 function onClick() { 1546 onToggle(); 1547 onFocus(); 1548 } 1549 return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)( 1550 import_block_editor11.RichTextToolbarButton, 1551 { 1552 icon: subscript_default, 1553 title: title9, 1554 onClick, 1555 isActive, 1556 role: "menuitemcheckbox" 1557 } 1558 ); 1559 } 1560 }; 1561 1562 // packages/format-library/build-module/superscript/index.js 1563 var import_i18n13 = __toESM(require_i18n()); 1564 var import_rich_text12 = __toESM(require_rich_text()); 1565 var import_block_editor12 = __toESM(require_block_editor()); 1566 var import_jsx_runtime26 = __toESM(require_jsx_runtime()); 1567 var name10 = "core/superscript"; 1568 var title10 = (0, import_i18n13.__)("Superscript"); 1569 var superscript = { 1570 name: name10, 1571 title: title10, 1572 tagName: "sup", 1573 className: null, 1574 edit({ isActive, value, onChange, onFocus }) { 1575 function onToggle() { 1576 onChange((0, import_rich_text12.toggleFormat)(value, { type: name10, title: title10 })); 1577 } 1578 function onClick() { 1579 onToggle(); 1580 onFocus(); 1581 } 1582 return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)( 1583 import_block_editor12.RichTextToolbarButton, 1584 { 1585 icon: superscript_default, 1586 title: title10, 1587 onClick, 1588 isActive, 1589 role: "menuitemcheckbox" 1590 } 1591 ); 1592 } 1593 }; 1594 1595 // packages/format-library/build-module/keyboard/index.js 1596 var import_i18n14 = __toESM(require_i18n()); 1597 var import_rich_text13 = __toESM(require_rich_text()); 1598 var import_block_editor13 = __toESM(require_block_editor()); 1599 var import_jsx_runtime27 = __toESM(require_jsx_runtime()); 1600 var name11 = "core/keyboard"; 1601 var title11 = (0, import_i18n14.__)("Keyboard input"); 1602 var keyboard = { 1603 name: name11, 1604 title: title11, 1605 tagName: "kbd", 1606 className: null, 1607 edit({ isActive, value, onChange, onFocus }) { 1608 function onToggle() { 1609 onChange((0, import_rich_text13.toggleFormat)(value, { type: name11, title: title11 })); 1610 } 1611 function onClick() { 1612 onToggle(); 1613 onFocus(); 1614 } 1615 return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)( 1616 import_block_editor13.RichTextToolbarButton, 1617 { 1618 icon: button_default, 1619 title: title11, 1620 onClick, 1621 isActive, 1622 role: "menuitemcheckbox" 1623 } 1624 ); 1625 } 1626 }; 1627 1628 // packages/format-library/build-module/unknown/index.js 1629 var import_i18n15 = __toESM(require_i18n()); 1630 var import_rich_text14 = __toESM(require_rich_text()); 1631 var import_block_editor14 = __toESM(require_block_editor()); 1632 var import_jsx_runtime28 = __toESM(require_jsx_runtime()); 1633 var name12 = "core/unknown"; 1634 var title12 = (0, import_i18n15.__)("Clear Unknown Formatting"); 1635 function selectionContainsUnknownFormats(value) { 1636 if ((0, import_rich_text14.isCollapsed)(value)) { 1637 return false; 1638 } 1639 const selectedValue = (0, import_rich_text14.slice)(value); 1640 return selectedValue.formats.some((formats) => { 1641 return formats.some((format) => format.type === name12); 1642 }); 1643 } 1644 var unknown = { 1645 name: name12, 1646 title: title12, 1647 tagName: "*", 1648 className: null, 1649 edit({ isActive, value, onChange, onFocus }) { 1650 if (!isActive && !selectionContainsUnknownFormats(value)) { 1651 return null; 1652 } 1653 function onClick() { 1654 onChange((0, import_rich_text14.removeFormat)(value, name12)); 1655 onFocus(); 1656 } 1657 return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)( 1658 import_block_editor14.RichTextToolbarButton, 1659 { 1660 name: "unknown", 1661 icon: help_default, 1662 title: title12, 1663 onClick, 1664 isActive: true 1665 } 1666 ); 1667 } 1668 }; 1669 1670 // packages/format-library/build-module/language/index.js 1671 var import_i18n16 = __toESM(require_i18n()); 1672 var import_block_editor15 = __toESM(require_block_editor()); 1673 var import_components5 = __toESM(require_components()); 1674 var import_element8 = __toESM(require_element()); 1675 var import_rich_text15 = __toESM(require_rich_text()); 1676 var import_jsx_runtime29 = __toESM(require_jsx_runtime()); 1677 var name13 = "core/language"; 1678 var title13 = (0, import_i18n16.__)("Language"); 1679 var language = { 1680 name: name13, 1681 tagName: "bdo", 1682 className: null, 1683 edit: Edit3, 1684 title: title13 1685 }; 1686 function Edit3({ isActive, value, onChange, contentRef }) { 1687 const [isPopoverVisible, setIsPopoverVisible] = (0, import_element8.useState)(false); 1688 const togglePopover = () => { 1689 setIsPopoverVisible((state) => !state); 1690 }; 1691 return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(import_jsx_runtime29.Fragment, { children: [ 1692 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)( 1693 import_block_editor15.RichTextToolbarButton, 1694 { 1695 icon: language_default, 1696 label: title13, 1697 title: title13, 1698 onClick: () => { 1699 if (isActive) { 1700 onChange((0, import_rich_text15.removeFormat)(value, name13)); 1701 } else { 1702 togglePopover(); 1703 } 1704 }, 1705 isActive, 1706 role: "menuitemcheckbox" 1707 } 1708 ), 1709 isPopoverVisible && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)( 1710 InlineLanguageUI, 1711 { 1712 value, 1713 onChange, 1714 onClose: togglePopover, 1715 contentRef 1716 } 1717 ) 1718 ] }); 1719 } 1720 function InlineLanguageUI({ value, contentRef, onChange, onClose }) { 1721 const popoverAnchor = (0, import_rich_text15.useAnchor)({ 1722 editableContentElement: contentRef.current, 1723 settings: language 1724 }); 1725 const [lang, setLang] = (0, import_element8.useState)(""); 1726 const [dir, setDir] = (0, import_element8.useState)("ltr"); 1727 return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)( 1728 import_components5.Popover, 1729 { 1730 className: "block-editor-format-toolbar__language-popover", 1731 anchor: popoverAnchor, 1732 onClose, 1733 children: /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)( 1734 import_components5.__experimentalVStack, 1735 { 1736 as: "form", 1737 spacing: 4, 1738 className: "block-editor-format-toolbar__language-container-content", 1739 onSubmit: (event) => { 1740 event.preventDefault(); 1741 onChange( 1742 (0, import_rich_text15.applyFormat)(value, { 1743 type: name13, 1744 attributes: { 1745 lang, 1746 dir 1747 } 1748 }) 1749 ); 1750 onClose(); 1751 }, 1752 children: [ 1753 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)( 1754 import_components5.TextControl, 1755 { 1756 __next40pxDefaultSize: true, 1757 label: title13, 1758 value: lang, 1759 onChange: (val) => setLang(val), 1760 help: (0, import_i18n16.__)( 1761 'A valid language attribute, like "en" or "fr".' 1762 ) 1763 } 1764 ), 1765 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)( 1766 import_components5.SelectControl, 1767 { 1768 __next40pxDefaultSize: true, 1769 label: (0, import_i18n16.__)("Text direction"), 1770 value: dir, 1771 options: [ 1772 { 1773 label: (0, import_i18n16.__)("Left to right"), 1774 value: "ltr" 1775 }, 1776 { 1777 label: (0, import_i18n16.__)("Right to left"), 1778 value: "rtl" 1779 } 1780 ], 1781 onChange: (val) => setDir(val) 1782 } 1783 ), 1784 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_components5.__experimentalHStack, { alignment: "right", children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)( 1785 import_components5.Button, 1786 { 1787 __next40pxDefaultSize: true, 1788 variant: "primary", 1789 type: "submit", 1790 text: (0, import_i18n16.__)("Apply") 1791 } 1792 ) }) 1793 ] 1794 } 1795 ) 1796 } 1797 ); 1798 } 1799 1800 // packages/format-library/build-module/math/index.js 1801 var import_i18n17 = __toESM(require_i18n()); 1802 var import_element9 = __toESM(require_element()); 1803 var import_rich_text16 = __toESM(require_rich_text()); 1804 var import_block_editor16 = __toESM(require_block_editor()); 1805 var import_components6 = __toESM(require_components()); 1806 var import_a11y3 = __toESM(require_a11y()); 1807 var import_jsx_runtime30 = __toESM(require_jsx_runtime()); 1808 var { Badge } = unlock(import_components6.privateApis); 1809 var name14 = "core/math"; 1810 var title14 = (0, import_i18n17.__)("Math"); 1811 function InlineUI2({ 1812 value, 1813 onChange, 1814 activeAttributes, 1815 contentRef, 1816 latexToMathML 1817 }) { 1818 const [latex, setLatex] = (0, import_element9.useState)( 1819 activeAttributes?.["data-latex"] || "" 1820 ); 1821 const [error, setError] = (0, import_element9.useState)(null); 1822 const popoverAnchor = (0, import_rich_text16.useAnchor)({ 1823 editableContentElement: contentRef.current, 1824 settings: math 1825 }); 1826 const handleLatexChange = (newLatex) => { 1827 let mathML = ""; 1828 setLatex(newLatex); 1829 if (newLatex) { 1830 try { 1831 mathML = latexToMathML(newLatex, { displayMode: false }); 1832 setError(null); 1833 } catch (err) { 1834 setError(err.message); 1835 (0, import_a11y3.speak)( 1836 (0, import_i18n17.sprintf)( 1837 /* translators: %s: error message returned when parsing LaTeX. */ 1838 (0, import_i18n17.__)("Error parsing mathematical expression: %s"), 1839 err.message 1840 ) 1841 ); 1842 return; 1843 } 1844 } 1845 const newReplacements = value.replacements.slice(); 1846 newReplacements[value.start] = { 1847 type: name14, 1848 attributes: { 1849 "data-latex": newLatex 1850 }, 1851 innerHTML: mathML 1852 }; 1853 onChange({ 1854 ...value, 1855 replacements: newReplacements 1856 }); 1857 }; 1858 return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)( 1859 import_components6.Popover, 1860 { 1861 placement: "bottom-start", 1862 offset: 8, 1863 focusOnMount: false, 1864 anchor: popoverAnchor, 1865 className: "block-editor-format-toolbar__math-popover", 1866 children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { style: { minWidth: "300px", padding: "4px" }, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_components6.__experimentalVStack, { spacing: 1, children: [ 1867 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)( 1868 import_components6.TextControl, 1869 { 1870 __next40pxDefaultSize: true, 1871 hideLabelFromVision: true, 1872 label: (0, import_i18n17.__)("LaTeX math syntax"), 1873 value: latex, 1874 onChange: handleLatexChange, 1875 placeholder: (0, import_i18n17.__)("e.g., x^2, \\frac{a}{b}"), 1876 autoComplete: "off", 1877 className: "block-editor-format-toolbar__math-input" 1878 } 1879 ), 1880 error && /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_jsx_runtime30.Fragment, { children: [ 1881 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)( 1882 Badge, 1883 { 1884 intent: "error", 1885 className: "wp-block-math__error", 1886 children: (0, import_i18n17.sprintf)( 1887 /* translators: %s: error message returned when parsing LaTeX. */ 1888 (0, import_i18n17.__)("Error: %s"), 1889 error 1890 ) 1891 } 1892 ), 1893 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("style", { children: ".wp-block-math__error .components-badge__content{white-space:normal}" }) 1894 ] }) 1895 ] }) }) 1896 } 1897 ); 1898 } 1899 function Edit4({ 1900 value, 1901 onChange, 1902 onFocus, 1903 isObjectActive, 1904 activeObjectAttributes, 1905 contentRef 1906 }) { 1907 const [latexToMathML, setLatexToMathML] = (0, import_element9.useState)(); 1908 (0, import_element9.useEffect)(() => { 1909 import("@wordpress/latex-to-mathml").then((module) => { 1910 setLatexToMathML(() => module.default); 1911 }); 1912 }, []); 1913 return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_jsx_runtime30.Fragment, { children: [ 1914 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)( 1915 import_block_editor16.RichTextToolbarButton, 1916 { 1917 icon: math_default, 1918 title: title14, 1919 onClick: () => { 1920 const newValue = (0, import_rich_text16.insertObject)(value, { 1921 type: name14, 1922 attributes: { 1923 "data-latex": "" 1924 }, 1925 innerHTML: "" 1926 }); 1927 newValue.start = newValue.end - 1; 1928 onChange(newValue); 1929 onFocus(); 1930 }, 1931 isActive: isObjectActive 1932 } 1933 ), 1934 isObjectActive && /* @__PURE__ */ (0, import_jsx_runtime30.jsx)( 1935 InlineUI2, 1936 { 1937 value, 1938 onChange, 1939 activeAttributes: activeObjectAttributes, 1940 contentRef, 1941 latexToMathML 1942 } 1943 ) 1944 ] }); 1945 } 1946 var math = { 1947 name: name14, 1948 title: title14, 1949 tagName: "math", 1950 className: null, 1951 attributes: { 1952 "data-latex": "data-latex" 1953 }, 1954 contentEditable: false, 1955 edit: Edit4 1956 }; 1957 1958 // packages/format-library/build-module/non-breaking-space/index.js 1959 var import_i18n18 = __toESM(require_i18n()); 1960 var import_rich_text17 = __toESM(require_rich_text()); 1961 var import_block_editor17 = __toESM(require_block_editor()); 1962 var import_jsx_runtime31 = __toESM(require_jsx_runtime()); 1963 var name15 = "core/non-breaking-space"; 1964 var title15 = (0, import_i18n18.__)("Non breaking space"); 1965 var nonBreakingSpace = { 1966 name: name15, 1967 title: title15, 1968 tagName: "nbsp", 1969 className: null, 1970 edit({ value, onChange }) { 1971 function addNonBreakingSpace() { 1972 onChange((0, import_rich_text17.insert)(value, "\xA0")); 1973 } 1974 return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)( 1975 import_block_editor17.RichTextShortcut, 1976 { 1977 type: "primaryShift", 1978 character: " ", 1979 onUse: addNonBreakingSpace 1980 } 1981 ); 1982 } 1983 }; 1984 1985 // packages/format-library/build-module/default-formats.js 1986 var default_formats_default = [ 1987 bold, 1988 code, 1989 image, 1990 italic, 1991 link, 1992 strikethrough, 1993 underline, 1994 textColor, 1995 subscript, 1996 superscript, 1997 keyboard, 1998 unknown, 1999 language, 2000 math, 2001 nonBreakingSpace 2002 ]; 2003 2004 // packages/format-library/build-module/index.js 2005 default_formats_default.forEach( 2006 ({ name: name16, ...settings }) => (0, import_rich_text18.registerFormatType)(name16, settings) 2007 ); 2008 })();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Wed Apr 15 08:20:10 2026 | Cross-referenced by PHPXref |