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