mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-08 20:01:12 +01:00
8a7d013dfd
It includes all the backports from this Gutenberg PR https://github.com/WordPress/gutenberg/pull/59756/ Props get_dave, swissspidy, bernhard-reiter, youknowriad. See #60315. Built from https://develop.svn.wordpress.org/trunk@57814 git-svn-id: http://core.svn.wordpress.org/trunk@57315 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2 lines
30 KiB
JavaScript
2 lines
30 KiB
JavaScript
/*! This file is auto-generated */
|
||
(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{RichTextData:()=>I,__experimentalRichText:()=>Ge,__unstableCreateElement:()=>b,__unstableToDom:()=>we,__unstableUseRichText:()=>Ye,applyFormat:()=>E,concat:()=>J,create:()=>B,getActiveFormat:()=>Q,getActiveFormats:()=>N,getActiveObject:()=>ee,getTextContent:()=>V,insert:()=>ie,insertObject:()=>ue,isCollapsed:()=>te,isEmpty:()=>ne,join:()=>re,registerFormatType:()=>oe,remove:()=>ce,removeFormat:()=>ae,replace:()=>le,slice:()=>fe,split:()=>de,store:()=>g,toHTMLString:()=>O,toggleFormat:()=>Fe,unregisterFormatType:()=>Re,useAnchor:()=>$e,useAnchorRef:()=>De});var n={};e.r(n),e.d(n,{getFormatType:()=>u,getFormatTypeForBareElement:()=>f,getFormatTypeForClassName:()=>d,getFormatTypes:()=>l});var r={};e.r(r),e.d(r,{addFormatTypes:()=>m,removeFormatTypes:()=>p});const o=window.wp.data;const a=(0,o.combineReducers)({formatTypes:function(e={},t){switch(t.type){case"ADD_FORMAT_TYPES":return{...e,...t.formatTypes.reduce(((e,t)=>({...e,[t.name]:t})),{})};case"REMOVE_FORMAT_TYPES":return Object.fromEntries(Object.entries(e).filter((([e])=>!t.names.includes(e))))}return e}});var s={};function i(e){return[e]}function c(e,t,n){var r;if(e.length!==t.length)return!1;for(r=n;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}const l=function(e,t){var n,r=t||i;function o(){n=new WeakMap}function a(){var t,o,a,i,l,u=arguments.length;for(i=new Array(u),a=0;a<u;a++)i[a]=arguments[a];for(t=function(e){var t,r,o,a,i,c=n,l=!0;for(t=0;t<e.length;t++){if(!(i=r=e[t])||"object"!=typeof i){l=!1;break}c.has(r)?c=c.get(r):(o=new WeakMap,c.set(r,o),c=o)}return c.has(s)||((a=function(){var e={clear:function(){e.head=null}};return e}()).isUniqueByDependants=l,c.set(s,a)),c.get(s)}(l=r.apply(null,i)),t.isUniqueByDependants||(t.lastDependants&&!c(l,t.lastDependants,0)&&t.clear(),t.lastDependants=l),o=t.head;o;){if(c(o.args,i,1))return o!==t.head&&(o.prev.next=o.next,o.next&&(o.next.prev=o.prev),o.next=t.head,o.prev=null,t.head.prev=o,t.head=o),o.val;o=o.next}return o={val:e.apply(null,i)},i[0]=null,o.args=i,t.head&&(t.head.prev=o,o.next=t.head),t.head=o,o.val}return a.getDependants=r,a.clear=o,o(),a}((e=>Object.values(e.formatTypes)),(e=>[e.formatTypes]));function u(e,t){return e.formatTypes[t]}function f(e,t){const n=l(e);return n.find((({className:e,tagName:n})=>null===e&&t===n))||n.find((({className:e,tagName:t})=>null===e&&"*"===t))}function d(e,t){return l(e).find((({className:e})=>null!==e&&` ${t} `.indexOf(` ${e} `)>=0))}function m(e){return{type:"ADD_FORMAT_TYPES",formatTypes:Array.isArray(e)?e:[e]}}function p(e){return{type:"REMOVE_FORMAT_TYPES",names:Array.isArray(e)?e:[e]}}const g=(0,o.createReduxStore)("core/rich-text",{reducer:a,selectors:n,actions:r});function h(e,t){if(e===t)return!0;if(!e||!t)return!1;if(e.type!==t.type)return!1;const n=e.attributes,r=t.attributes;if(n===r)return!0;if(!n||!r)return!1;const o=Object.keys(n),a=Object.keys(r);if(o.length!==a.length)return!1;const s=o.length;for(let e=0;e<s;e++){const t=o[e];if(n[t]!==r[t])return!1}return!0}function v(e){const t=e.formats.slice();return t.forEach(((e,n)=>{const r=t[n-1];if(r){const o=e.slice();o.forEach(((e,t)=>{const n=r[t];h(e,n)&&(o[t]=n)})),t[n]=o}})),{...e,formats:t}}function y(e,t,n){return(e=e.slice())[t]=n,e}function E(e,t,n=e.start,r=e.end){const{formats:o,activeFormats:a}=e,s=o.slice();if(n===r){const e=s[n]?.find((({type:e})=>e===t.type));if(e){const o=s[n].indexOf(e);for(;s[n]&&s[n][o]===e;)s[n]=y(s[n],o,t),n--;for(r++;s[r]&&s[r][o]===e;)s[r]=y(s[r],o,t),r++}}else{let e=1/0;for(let o=n;o<r;o++)if(s[o]){s[o]=s[o].filter((({type:e})=>e!==t.type));const n=s[o].length;n<e&&(e=n)}else s[o]=[],e=0;for(let o=n;o<r;o++)s[o].splice(e,0,t)}return v({...e,formats:s,activeFormats:[...a?.filter((({type:e})=>e!==t.type))||[],t]})}function b({implementation:e},t){return b.body||(b.body=e.createHTMLDocument("").body),b.body.innerHTML=t,b.body}(0,o.register)(g);const T="",x="\ufeff",w=window.wp.escapeHtml;function N(e,t=[]){const{formats:n,start:r,end:o,activeFormats:a}=e;if(void 0===r)return t;if(r===o){if(a)return a;const e=n[r-1]||t,o=n[r]||t;return e.length<o.length?e:o}if(!n[r])return t;const s=n.slice(r,o),i=[...s[0]];let c=s.length;for(;c--;){const e=s[c];if(!e)return t;let n=i.length;for(;n--;){const t=i[n];e.find((e=>h(t,e)))||i.splice(n,1)}if(0===i.length)return t}return i||t}function L(e){return(0,o.select)(g).getFormatType(e)}function C(e,t){if(t)return e;const n={};for(const t in e){let r=t;t.startsWith("data-disable-rich-text-")&&(r=t.slice(23)),n[r]=e[t]}return n}function _({type:e,tagName:t,attributes:n,unregisteredAttributes:r,object:o,boundaryClass:a,isEditableTree:s}){const i=L(e);let c={};if(a&&s&&(c["data-rich-text-format-boundary"]="true"),!i)return n&&(c={...n,...c}),{type:e,attributes:C(c,s),object:o};c={...r,...c};for(const e in n){const t=!!i.attributes&&i.attributes[e];t?c[t]=n[e]:c[e]=n[e]}return i.className&&(c.class?c.class=`${i.className} ${c.class}`:c.class=i.className),s&&!1===i.contentEditable&&(c.contenteditable="false"),{type:t||i.tagName,object:i.object,attributes:C(c,s)}}function F(e,t,n){do{if(e[n]!==t[n])return!1}while(n--);return!0}function R({value:e,preserveWhiteSpace:t,createEmpty:n,append:r,getLastChild:o,getParent:a,isText:s,getText:i,remove:c,appendText:l,onStartIndex:u,onEndIndex:f,isEditableTree:d,placeholder:m}){const{formats:p,replacements:g,text:h,start:v,end:y}=e,E=p.length+1,b=n(),w=N(e),C=w[w.length-1];let R,O;r(b,"");for(let e=0;e<E;e++){const n=h.charAt(e),E=d&&(!O||"\n"===O),w=p[e];let N=o(b);if(w&&w.forEach(((e,t)=>{if(N&&R&&F(w,R,t))return void(N=o(N));const{type:n,tagName:l,attributes:u,unregisteredAttributes:f}=e,m=d&&e===C,p=a(N),g=r(p,_({type:n,tagName:l,attributes:u,unregisteredAttributes:f,boundaryClass:m,isEditableTree:d}));s(N)&&0===i(N).length&&c(N),N=r(g,"")})),0===e&&(u&&0===v&&u(b,N),f&&0===y&&f(b,N)),n===T){const t=g[e];if(!t)continue;const{type:n,attributes:o,innerHTML:s}=t,i=L(n);d||"script"!==n?!1===i?.contentEditable?(N=r(a(N),_({...t,isEditableTree:d,boundaryClass:v===e&&y===e+1})),s&&r(N,{html:s})):N=r(a(N),_({...t,object:!0,isEditableTree:d})):(N=r(a(N),_({type:"script",isEditableTree:d})),r(N,{html:decodeURIComponent(o["data-rich-text-script"])})),N=r(a(N),"")}else t||"\n"!==n?s(N)?l(N,n):N=r(a(N),n):(N=r(a(N),{type:"br",attributes:d?{"data-rich-text-line-break":"true"}:void 0,object:!0}),N=r(a(N),""));u&&v===e+1&&u(b,N),f&&y===e+1&&f(b,N),E&&e===h.length&&(r(a(N),x),m&&0===h.length&&r(a(N),{type:"span",attributes:{"data-rich-text-placeholder":m,style:"pointer-events:none;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;"}})),R=w,O=n}return b}function O({value:e,preserveWhiteSpace:t}){return j(R({value:e,preserveWhiteSpace:t,createEmpty:A,append:D,getLastChild:S,getParent:k,isText:$,getText:H,remove:P,appendText:M}).children)}function A(){return{}}function S({children:e}){return e&&e[e.length-1]}function D(e,t){return"string"==typeof t&&(t={text:t}),t.parent=e,e.children=e.children||[],e.children.push(t),t}function M(e,t){e.text+=t}function k({parent:e}){return e}function $({text:e}){return"string"==typeof e}function H({text:e}){return e}function P(e){const t=e.parent.children.indexOf(e);return-1!==t&&e.parent.children.splice(t,1),e}function j(e=[]){return e.map((e=>void 0!==e.html?e.html:void 0===e.text?function({type:e,attributes:t,object:n,children:r}){let o="";for(const e in t)(0,w.isValidAttributeName)(e)&&(o+=` ${e}="${(0,w.escapeAttribute)(t[e])}"`);return n?`<${e}${o}>`:`<${e}${o}>${j(r)}</${e}>`}(e):(0,w.escapeEditableHTML)(e.text))).join("")}function V({text:e}){return e.replace(T,"")}function W({tagName:e,attributes:t}){let n;if(t&&t.class&&(n=(0,o.select)(g).getFormatTypeForClassName(t.class),n&&(t.class=` ${t.class} `.replace(` ${n.className} `," ").trim(),t.class||delete t.class)),n||(n=(0,o.select)(g).getFormatTypeForBareElement(e)),!n)return t?{type:e,attributes:t}:{type:e};if(n.__experimentalCreatePrepareEditableTree&&!n.__experimentalCreateOnChangeEditableValue)return null;if(!t)return{formatType:n,type:n.name,tagName:e};const r={},a={},s={...t};for(const e in n.attributes){const t=n.attributes[e];r[e]=s[t],delete s[t],void 0===r[e]&&delete r[e]}for(const e in s)a[e]=t[e];return!1===n.contentEditable&&delete a.contenteditable,{formatType:n,type:n.name,tagName:e,attributes:r,unregisteredAttributes:a}}class I{#e;static empty(){return new I}static fromPlainText(e){return new I(B({text:e}))}static fromHTMLString(e){return new I(B({html:e}))}static fromHTMLElement(e,t={}){const{preserveWhiteSpace:n=!1}=t,r=n?e:U(e),o=new I(B({element:r}));return Object.defineProperty(o,"originalHTML",{value:e.innerHTML}),o}constructor(e={formats:[],replacements:[],text:""}){this.#e=e}toPlainText(){return V(this.#e)}toHTMLString({preserveWhiteSpace:e}={}){return this.originalHTML||O({value:this.#e,preserveWhiteSpace:e})}valueOf(){return this.toHTMLString()}toString(){return this.toHTMLString()}toJSON(){return this.toHTMLString()}get length(){return this.text.length}get formats(){return this.#e.formats}get replacements(){return this.#e.replacements}get text(){return this.#e.text}}for(const e of Object.getOwnPropertyNames(String.prototype))I.prototype.hasOwnProperty(e)||Object.defineProperty(I.prototype,e,{value(...t){return this.toHTMLString()[e](...t)}});function B({element:e,text:t,html:n,range:r,__unstableIsEditableTree:o}={}){return n instanceof I?{text:n.text,formats:n.formats,replacements:n.replacements}:"string"==typeof t&&t.length>0?{formats:Array(t.length),replacements:Array(t.length),text:t}:("string"==typeof n&&n.length>0&&(e=b(document,n)),"object"!=typeof e?{formats:[],replacements:[],text:""}:Y({element:e,range:r,isEditableTree:o}))}function z(e,t,n,r){if(!n)return;const{parentNode:o}=t,{startContainer:a,startOffset:s,endContainer:i,endOffset:c}=n,l=e.text.length;void 0!==r.start?e.start=l+r.start:t===a&&t.nodeType===t.TEXT_NODE?e.start=l+s:o===a&&t===a.childNodes[s]?e.start=l:o===a&&t===a.childNodes[s-1]?e.start=l+r.text.length:t===a&&(e.start=l),void 0!==r.end?e.end=l+r.end:t===i&&t.nodeType===t.TEXT_NODE?e.end=l+c:o===i&&t===i.childNodes[c-1]?e.end=l+r.text.length:o===i&&t===i.childNodes[c]?e.end=l:t===i&&(e.end=l+c)}function X(e,t,n){if(!t)return;const{startContainer:r,endContainer:o}=t;let{startOffset:a,endOffset:s}=t;return e===r&&(a=n(e.nodeValue.slice(0,a)).length),e===o&&(s=n(e.nodeValue.slice(0,s)).length),{startContainer:r,startOffset:a,endContainer:o,endOffset:s}}function U(e,t=!0){const n=e.cloneNode(!0);return n.normalize(),Array.from(n.childNodes).forEach(((e,n,r)=>{if(e.nodeType===e.TEXT_NODE){let o=e.nodeValue;/[\n\t\r\f]/.test(o)&&(o=o.replace(/[\n\t\r\f]+/g," ")),-1!==o.indexOf(" ")&&(o=o.replace(/ {2,}/g," ")),0===n&&o.startsWith(" ")?o=o.slice(1):t&&n===r.length-1&&o.endsWith(" ")&&(o=o.slice(0,-1)),e.nodeValue=o}else e.nodeType===e.ELEMENT_NODE&&U(e,!1)})),n}const q="\r";function K(e){return e.replace(new RegExp(`[${x}${T}${q}]`,"gu"),"")}function Y({element:e,range:t,isEditableTree:n}){const r={formats:[],replacements:[],text:""};if(!e)return r;if(!e.hasChildNodes())return z(r,e,t,{formats:[],replacements:[],text:""}),r;const o=e.childNodes.length;for(let a=0;a<o;a++){const s=e.childNodes[a],i=s.nodeName.toLowerCase();if(s.nodeType===s.TEXT_NODE){const u=K(s.nodeValue);z(r,s,t=X(s,t,K),{text:u}),r.formats.length+=u.length,r.replacements.length+=u.length,r.text+=u;continue}if(s.nodeType!==s.ELEMENT_NODE)continue;if(n&&"br"===i&&!s.getAttribute("data-rich-text-line-break")){z(r,s,t,{formats:[],replacements:[],text:""});continue}if("script"===i){const f={formats:[,],replacements:[{type:i,attributes:{"data-rich-text-script":s.getAttribute("data-rich-text-script")||encodeURIComponent(s.innerHTML)}}],text:T};z(r,s,t,f),Z(r,f);continue}if("br"===i){z(r,s,t,{formats:[],replacements:[],text:""}),Z(r,B({text:"\n"}));continue}const c=W({tagName:i,attributes:G({element:s})});if(!1===c?.formatType?.contentEditable){delete c.formatType,z(r,s,t,{formats:[],replacements:[],text:""}),Z(r,{formats:[,],replacements:[{...c,innerHTML:s.innerHTML}],text:T});continue}c&&delete c.formatType;const l=Y({element:s,range:t,isEditableTree:n});if(z(r,s,t,l),!c||s.getAttribute("data-rich-text-placeholder"))Z(r,l);else if(0===l.text.length)c.attributes&&Z(r,{formats:[,],replacements:[c],text:T});else{function d(e){if(d.formats===e)return d.newFormats;const t=e?[c,...e]:[c];return d.formats=e,d.newFormats=t,t}d.newFormats=[c],Z(r,{...l,formats:Array.from(l.formats,d)})}}return r}function G({element:e}){if(!e.hasAttributes())return;const t=e.attributes.length;let n;for(let r=0;r<t;r++){const{name:t,value:o}=e.attributes[r];if(0===t.indexOf("data-rich-text-"))continue;n=n||{},n[/^on/i.test(t)?"data-disable-rich-text-"+t:t]=o}return n}function Z(e,t){return e.formats=e.formats.concat(t.formats),e.replacements=e.replacements.concat(t.replacements),e.text+=t.text,e}function J(...e){return v(e.reduce(Z,B()))}function Q(e,t){return N(e).find((({type:e})=>e===t))}function ee({start:e,end:t,replacements:n,text:r}){if(e+1===t&&r[e]===T)return n[e]}function te({start:e,end:t}){if(void 0!==e&&void 0!==t)return e===t}function ne({text:e}){return 0===e.length}function re(e,t=""){return"string"==typeof t&&(t=B({text:t})),v(e.reduce(((e,{formats:n,replacements:r,text:o})=>({formats:e.formats.concat(t.formats,n),replacements:e.replacements.concat(t.replacements,r),text:e.text+t.text+o}))))}function oe(e,t){if("string"==typeof(t={name:e,...t}).name)if(/^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/.test(t.name))if((0,o.select)(g).getFormatType(t.name))window.console.error('Format "'+t.name+'" is already registered.');else if("string"==typeof t.tagName&&""!==t.tagName)if("string"==typeof t.className&&""!==t.className||null===t.className)if(/^[_a-zA-Z]+[a-zA-Z0-9_-]*$/.test(t.className)){if(null===t.className){const e=(0,o.select)(g).getFormatTypeForBareElement(t.tagName);if(e&&"core/unknown"!==e.name)return void window.console.error(`Format "${e.name}" is already registered to handle bare tag name "${t.tagName}".`)}else{const e=(0,o.select)(g).getFormatTypeForClassName(t.className);if(e)return void window.console.error(`Format "${e.name}" is already registered to handle class name "${t.className}".`)}if("title"in t&&""!==t.title)if("keywords"in t&&t.keywords.length>3)window.console.error('The format "'+t.name+'" can have a maximum of 3 keywords.');else{if("string"==typeof t.title)return(0,o.dispatch)(g).addFormatTypes(t),t;window.console.error("Format titles must be strings.")}else window.console.error('The format "'+t.name+'" must have a title.')}else window.console.error("A class name must begin with a letter, followed by any number of hyphens, underscores, letters, or numbers.");else window.console.error("Format class names must be a string, or null to handle bare elements.");else window.console.error("Format tag names must be a string.");else window.console.error("Format names must contain a namespace prefix, include only lowercase alphanumeric characters or dashes, and start with a letter. Example: my-plugin/my-custom-format");else window.console.error("Format names must be strings.")}function ae(e,t,n=e.start,r=e.end){const{formats:o,activeFormats:a}=e,s=o.slice();if(n===r){const e=s[n]?.find((({type:e})=>e===t));if(e){for(;s[n]?.find((t=>t===e));)se(s,n,t),n--;for(r++;s[r]?.find((t=>t===e));)se(s,r,t),r++}}else for(let e=n;e<r;e++)s[e]&&se(s,e,t);return v({...e,formats:s,activeFormats:a?.filter((({type:e})=>e!==t))||[]})}function se(e,t,n){const r=e[t].filter((({type:e})=>e!==n));r.length?e[t]=r:delete e[t]}function ie(e,t,n=e.start,r=e.end){const{formats:o,replacements:a,text:s}=e;"string"==typeof t&&(t=B({text:t}));const i=n+t.text.length;return v({formats:o.slice(0,n).concat(t.formats,o.slice(r)),replacements:a.slice(0,n).concat(t.replacements,a.slice(r)),text:s.slice(0,n)+t.text+s.slice(r),start:i,end:i})}function ce(e,t,n){return ie(e,B(),t,n)}function le({formats:e,replacements:t,text:n,start:r,end:o},a,s){return n=n.replace(a,((n,...a)=>{const i=a[a.length-2];let c,l,u=s;return"function"==typeof u&&(u=s(n,...a)),"object"==typeof u?(c=u.formats,l=u.replacements,u=u.text):(c=Array(u.length),l=Array(u.length),e[i]&&(c=c.fill(e[i]))),e=e.slice(0,i).concat(c,e.slice(i+n.length)),t=t.slice(0,i).concat(l,t.slice(i+n.length)),r&&(r=o=i+u.length),u})),v({formats:e,replacements:t,text:n,start:r,end:o})}function ue(e,t,n,r){return ie(e,{formats:[,],replacements:[t],text:T},n,r)}function fe(e,t=e.start,n=e.end){const{formats:r,replacements:o,text:a}=e;return void 0===t||void 0===n?{...e}:{formats:r.slice(t,n),replacements:o.slice(t,n),text:a.slice(t,n)}}function de({formats:e,replacements:t,text:n,start:r,end:o},a){if("string"!=typeof a)return function({formats:e,replacements:t,text:n,start:r,end:o},a=r,s=o){if(void 0===r||void 0===o)return;const i={formats:e.slice(0,a),replacements:t.slice(0,a),text:n.slice(0,a)},c={formats:e.slice(s),replacements:t.slice(s),text:n.slice(s),start:0,end:0};return[i,c]}(...arguments);let s=0;return n.split(a).map((n=>{const i=s,c={formats:e.slice(i,i+n.length),replacements:t.slice(i,i+n.length),text:n};return s+=a.length+n.length,void 0!==r&&void 0!==o&&(r>=i&&r<s?c.start=r-i:r<i&&o>i&&(c.start=0),o>=i&&o<s?c.end=o-i:r<s&&o>s&&(c.end=n.length)),c}))}function me(e,t){return e===t||e&&t&&e.startContainer===t.startContainer&&e.startOffset===t.startOffset&&e.endContainer===t.endContainer&&e.endOffset===t.endOffset}function pe(e,t,n){const r=e.parentNode;let o=0;for(;e=e.previousSibling;)o++;return n=[o,...n],r!==t&&(n=pe(r,t,n)),n}function ge(e,t){for(t=[...t];e&&t.length>1;)e=e.childNodes[t.shift()];return{node:e,offset:t[0]}}function he(e,t){if(void 0!==t.html)return e.innerHTML+=t.html;"string"==typeof t&&(t=e.ownerDocument.createTextNode(t));const{type:n,attributes:r}=t;if(n){t=e.ownerDocument.createElement(n);for(const e in r)t.setAttribute(e,r[e])}return e.appendChild(t)}function ve(e,t){e.appendData(t)}function ye({lastChild:e}){return e}function Ee({parentNode:e}){return e}function be(e){return e.nodeType===e.TEXT_NODE}function Te({nodeValue:e}){return e}function xe(e){return e.parentNode.removeChild(e)}function we({value:e,prepareEditableTree:t,isEditableTree:n=!0,placeholder:r,doc:o=document}){let a=[],s=[];t&&(e={...e,formats:t(e)});return{body:R({value:e,createEmpty:()=>b(o,""),append:he,getLastChild:ye,getParent:Ee,isText:be,getText:Te,remove:xe,appendText:ve,onStartIndex(e,t){a=pe(t,e,[t.nodeValue.length])},onEndIndex(e,t){s=pe(t,e,[t.nodeValue.length])},isEditableTree:n,placeholder:r}),selection:{startPath:a,endPath:s}}}function Ne({value:e,current:t,prepareEditableTree:n,__unstableDomOnly:r,placeholder:o}){const{body:a,selection:s}=we({value:e,prepareEditableTree:n,placeholder:o,doc:t.ownerDocument});Le(a,t),void 0===e.start||r||function({startPath:e,endPath:t},n){const{node:r,offset:o}=ge(n,e),{node:a,offset:s}=ge(n,t),{ownerDocument:i}=n,{defaultView:c}=i,l=c.getSelection(),u=i.createRange();u.setStart(r,o),u.setEnd(a,s);const{activeElement:f}=i;if(l.rangeCount>0){if(me(u,l.getRangeAt(0)))return;l.removeAllRanges()}l.addRange(u),f!==i.activeElement&&f instanceof c.HTMLElement&&f.focus()}(s,t)}function Le(e,t){let n,r=0;for(;n=e.firstChild;){const o=t.childNodes[r];if(o)if(o.isEqualNode(n))e.removeChild(n);else if(o.nodeName!==n.nodeName||o.nodeType===o.TEXT_NODE&&o.data!==n.data)t.replaceChild(n,o);else{const t=o.attributes,r=n.attributes;if(t){let e=t.length;for(;e--;){const{name:r}=t[e];n.getAttribute(r)||o.removeAttribute(r)}}if(r)for(let e=0;e<r.length;e++){const{name:t,value:n}=r[e];o.getAttribute(t)!==n&&o.setAttribute(t,n)}Le(n,o),e.removeChild(n)}else t.appendChild(n);r++}for(;t.childNodes[r];)t.removeChild(t.childNodes[r])}const Ce=window.wp.a11y,_e=window.wp.i18n;function Fe(e,t){return Q(e,t.type)?(t.title&&(0,Ce.speak)((0,_e.sprintf)((0,_e.__)("%s removed."),t.title),"assertive"),ae(e,t.type)):(t.title&&(0,Ce.speak)((0,_e.sprintf)((0,_e.__)("%s applied."),t.title),"assertive"),E(e,t))}function Re(e){const t=(0,o.select)(g).getFormatType(e);if(t)return(0,o.dispatch)(g).removeFormatTypes(e),t;window.console.error(`Format ${e} is not registered.`)}const Oe=window.wp.element,Ae=window.wp.deprecated;var Se=e.n(Ae);function De({ref:e,value:t,settings:n={}}){Se()("`useAnchorRef` hook",{since:"6.1",alternative:"`useAnchor` hook"});const{tagName:r,className:o,name:a}=n,s=a?Q(t,a):void 0;return(0,Oe.useMemo)((()=>{if(!e.current)return;const{ownerDocument:{defaultView:t}}=e.current,n=t.getSelection();if(!n.rangeCount)return;const a=n.getRangeAt(0);if(!s)return a;let i=a.startContainer;for(i=i.nextElementSibling||i;i.nodeType!==i.ELEMENT_NODE;)i=i.parentNode;return i.closest(r+(o?"."+o:""))}),[s,t.start,t.end,r,o])}const Me=window.wp.compose;function ke(e,t,n){if(!e)return;const{ownerDocument:r}=e,{defaultView:o}=r,a=o.getSelection();if(!a)return;if(!a.rangeCount)return;const s=a.getRangeAt(0);if(!s||!s.startContainer)return;const i=function(e,t,n,r){let o=e.startContainer;if(o.nodeType===o.TEXT_NODE&&e.startOffset===o.length&&o.nextSibling)for(o=o.nextSibling;o.firstChild;)o=o.firstChild;if(o.nodeType!==o.ELEMENT_NODE&&(o=o.parentElement),!o)return;if(o===t)return;if(!t.contains(o))return;const a=n+(r?"."+r:"");for(;o!==t;){if(o.matches(a))return o;o=o.parentElement}}(s,e,t,n);return i||function(e,t){return{contextElement:t,getBoundingClientRect:()=>t.contains(e.startContainer)?e.getBoundingClientRect():t.getBoundingClientRect()}}(s,e)}function $e({editableContentElement:e,settings:t={}}){const{tagName:n,className:r,isActive:o}=t,[a,s]=(0,Oe.useState)((()=>ke(e,n,r))),i=(0,Me.usePrevious)(o);return(0,Oe.useLayoutEffect)((()=>{if(!e)return;function t(){s(ke(e,n,r))}function a(){l.addEventListener("selectionchange",t)}function c(){l.removeEventListener("selectionchange",t)}const{ownerDocument:l}=e;return(e===l.activeElement||!i&&o||i&&!o)&&(s(ke(e,n,r)),a()),e.addEventListener("focusin",a),e.addEventListener("focusout",c),()=>{c(),e.removeEventListener("focusin",a),e.removeEventListener("focusout",c)}}),[e,n,r,o,i]),a}const He="pre-wrap",Pe="1px";function je({record:e}){const t=(0,Oe.useRef)(),{activeFormats:n=[],replacements:r,start:o}=e.current,a=r[o];return(0,Oe.useEffect)((()=>{if(!(n&&n.length||a))return;const e="*[data-rich-text-format-boundary]",r=t.current.querySelector(e);if(!r)return;const{ownerDocument:o}=r,{defaultView:s}=o,i=`${`.rich-text:focus ${e}`} {${`background-color: ${s.getComputedStyle(r).color.replace(")",", 0.2)").replace("rgb","rgba")}`}}`,c="rich-text-boundary-style";let l=o.getElementById(c);l||(l=o.createElement("style"),l.id=c,o.head.appendChild(l)),l.innerHTML!==i&&(l.innerHTML=i)}),[n,a]),t}function Ve(e){const t=(0,Oe.useRef)(e);return t.current=e,(0,Me.useRefEffect)((e=>{function n(n){const{record:r}=t.current,{ownerDocument:o}=e;if(te(r.current)||!e.contains(o.activeElement))return;const a=fe(r.current),s=V(a),i=O({value:a});n.clipboardData.setData("text/plain",s),n.clipboardData.setData("text/html",i),n.clipboardData.setData("rich-text","true"),n.preventDefault(),"cut"===n.type&&o.execCommand("delete")}return e.addEventListener("copy",n),e.addEventListener("cut",n),()=>{e.removeEventListener("copy",n),e.removeEventListener("cut",n)}}),[])}const We=window.wp.keycodes,Ie=[];function Be(e){const[,t]=(0,Oe.useReducer)((()=>({}))),n=(0,Oe.useRef)(e);return n.current=e,(0,Me.useRefEffect)((e=>{function r(r){const{keyCode:o,shiftKey:a,altKey:s,metaKey:i,ctrlKey:c}=r;if(a||s||i||c||o!==We.LEFT&&o!==We.RIGHT)return;const{record:l,applyRecord:u}=n.current,{text:f,formats:d,start:m,end:p,activeFormats:g=[]}=l.current,h=te(l.current),{ownerDocument:v}=e,{defaultView:y}=v,{direction:E}=y.getComputedStyle(e),b="rtl"===E?We.RIGHT:We.LEFT,T=r.keyCode===b;if(h&&0===g.length){if(0===m&&T)return;if(p===f.length&&!T)return}if(!h)return;const x=d[m-1]||Ie,w=d[m]||Ie,N=T?x:w,L=g.every(((e,t)=>e===N[t]));let C=g.length;if(L?C<N.length&&C++:C--,C===g.length)return void(l.current._newActiveFormats=N);r.preventDefault();const _=(L?N:T?w:x).slice(0,C),F={...l.current,activeFormats:_};l.current=F,u(F),t()}return e.addEventListener("keydown",r),()=>{e.removeEventListener("keydown",r)}}),[])}const ze=new Set(["insertParagraph","insertOrderedList","insertUnorderedList","insertHorizontalRule","insertLink"]),Xe=[],Ue="data-rich-text-placeholder";function qe(e){const t=(0,Oe.useRef)(e);return t.current=e,(0,Me.useRefEffect)((e=>{const{ownerDocument:n}=e,{defaultView:r}=n;let o=!1;function a(e){if(o)return;let n;e&&(n=e.inputType);const{record:r,applyRecord:a,createRecord:s,handleChange:i}=t.current;if(n&&(0===n.indexOf("format")||ze.has(n)))return void a(r.current);const c=s(),{start:l,activeFormats:u=[]}=r.current,f=function({value:e,start:t,end:n,formats:r}){const o=Math.min(t,n),a=Math.max(t,n),s=e.formats[o-1]||[],i=e.formats[a]||[];for(e.activeFormats=r.map(((e,t)=>{if(s[t]){if(h(e,s[t]))return s[t]}else if(i[t]&&h(e,i[t]))return i[t];return e}));--n>=t;)e.activeFormats.length>0?e.formats[n]=e.activeFormats:delete e.formats[n];return e}({value:c,start:l,end:c.start,formats:u});i(f)}function s(){const{record:i,applyRecord:c,createRecord:l,onSelectionChange:u}=t.current;if("true"!==e.contentEditable)return;if(n.activeElement!==e)return void n.removeEventListener("selectionchange",s);if(o)return;const{start:f,end:d,text:m}=l(),p=i.current;if(m!==p.text)return void a();if(f===p.start&&d===p.end)return void(0===p.text.length&&0===f&&function(e){const t=e.getSelection(),{anchorNode:n,anchorOffset:r}=t;if(n.nodeType!==n.ELEMENT_NODE)return;const o=n.childNodes[r];o&&o.nodeType===o.ELEMENT_NODE&&o.hasAttribute(Ue)&&t.collapseToStart()}(r));const g={...p,start:f,end:d,activeFormats:p._newActiveFormats,_newActiveFormats:void 0},h=N(g,Xe);g.activeFormats=h,i.current=g,c(g,{domOnly:!0}),u(f,d)}function i(){o=!0,n.removeEventListener("selectionchange",s),e.querySelector(`[${Ue}]`)?.remove()}function c(){o=!1,a({inputType:"insertText"}),n.addEventListener("selectionchange",s)}function l(){const{record:r,isSelected:o,onSelectionChange:a,applyRecord:i}=t.current;if(!e.parentElement.closest('[contenteditable="true"]')){if(o)i(r.current,{domOnly:!0});else{const e=void 0;r.current={...r.current,start:e,end:e,activeFormats:Xe}}a(r.current.start,r.current.end),n.addEventListener("selectionchange",s)}}return e.addEventListener("input",a),e.addEventListener("compositionstart",i),e.addEventListener("compositionend",c),e.addEventListener("focus",l),()=>{e.removeEventListener("input",a),e.removeEventListener("compositionstart",i),e.removeEventListener("compositionend",c),e.removeEventListener("focus",l)}}),[])}function Ke(e){const t=(0,Oe.useRef)(e);return t.current=e,(0,Me.useRefEffect)((e=>{function n(e){const{keyCode:n}=e,{createRecord:r,handleChange:o}=t.current;if(e.defaultPrevented)return;if(n!==We.DELETE&&n!==We.BACKSPACE)return;const a=r(),{start:s,end:i,text:c}=a;0===s&&0!==i&&i===c.length&&(o(ce(a)),e.preventDefault())}return e.addEventListener("keydown",n),()=>{e.removeEventListener("keydown",n)}}),[])}function Ye({value:e="",selectionStart:t,selectionEnd:n,placeholder:r,onSelectionChange:a,preserveWhiteSpace:s,onChange:i,__unstableDisableFormats:c,__unstableIsSelected:l,__unstableDependencies:u=[],__unstableAfterParse:f,__unstableBeforeSerialize:d,__unstableAddInvisibleFormats:m}){const p=(0,o.useRegistry)(),[,g]=(0,Oe.useReducer)((()=>({}))),h=(0,Oe.useRef)();function v(){const{ownerDocument:{defaultView:e}}=h.current,t=e.getSelection(),n=t.rangeCount>0?t.getRangeAt(0):null;return B({element:h.current,range:n,__unstableIsEditableTree:!0})}function y(e,{domOnly:t}={}){Ne({value:e,current:h.current,prepareEditableTree:m,__unstableDomOnly:t,placeholder:r})}const E=(0,Oe.useRef)(e),b=(0,Oe.useRef)();function T(){E.current=e,b.current=e,e instanceof I||(b.current=e?I.fromHTMLString(e,{preserveWhiteSpace:s}):I.empty()),b.current={text:b.current.text,formats:b.current.formats,replacements:b.current.replacements},c&&(b.current.formats=Array(e.length),b.current.replacements=Array(e.length)),f&&(b.current.formats=f(b.current)),b.current.start=t,b.current.end=n}const x=(0,Oe.useRef)(!1);function w(t){if(b.current=t,y(t),c)E.current=t.text;else{const n=d?d(t):t.formats;t={...t,formats:n},E.current="string"==typeof e?O({value:t,preserveWhiteSpace:s}):new I(t)}const{start:n,end:r,formats:o,text:l}=b.current;p.batch((()=>{a(n,r),i(E.current,{__unstableFormats:o,__unstableText:l})})),g()}function N(){T(),y(b.current)}b.current?t===b.current.start&&n===b.current.end||(x.current=l,b.current={...b.current,start:t,end:n,activeFormats:void 0}):(x.current=l,T());const L=(0,Oe.useRef)(!1);(0,Oe.useLayoutEffect)((()=>{L.current&&e!==E.current&&(N(),g())}),[e]),(0,Oe.useLayoutEffect)((()=>{x.current&&(h.current.ownerDocument.activeElement!==h.current&&h.current.focus(),y(b.current),x.current=!1)}),[x.current]);const C=(0,Me.useMergeRefs)([h,(0,Oe.useCallback)((e=>{e&&(e.style.whiteSpace=He,e.style.minWidth=Pe)}),[]),je({record:b}),Ve({record:b}),(0,Me.useRefEffect)((e=>{function t(t){const{target:n}=t;if(n===e||n.textContent&&n.isContentEditable)return;const{ownerDocument:r}=n,{defaultView:o}=r,a=o.getSelection();if(a.containsNode(n))return;const s=r.createRange(),i=n.isContentEditable?n:n.closest("[contenteditable]");s.selectNode(i),a.removeAllRanges(),a.addRange(s),t.preventDefault()}function n(n){n.relatedTarget&&!e.contains(n.relatedTarget)&&"A"===n.relatedTarget.tagName&&t(n)}return e.addEventListener("click",t),e.addEventListener("focusin",n),()=>{e.removeEventListener("click",t),e.removeEventListener("focusin",n)}}),[]),Be({record:b,applyRecord:y}),Ke({createRecord:v,handleChange:w}),qe({record:b,applyRecord:y,createRecord:v,handleChange:w,isSelected:l,onSelectionChange:a}),(0,Me.useRefEffect)((e=>{const{ownerDocument:t}=e,{defaultView:n}=t,r=n?.getSelection();let o;function a(){return r.rangeCount?r.getRangeAt(0):null}function s(e){const n="keydown"===e.type?"keyup":"pointerup";function r(){t.removeEventListener(n,s),t.removeEventListener("selectionchange",r),t.removeEventListener("input",r)}function s(){r(),me(o,a())||t.dispatchEvent(new Event("selectionchange"))}t.addEventListener(n,s),t.addEventListener("selectionchange",r),t.addEventListener("input",r),o=a()}return e.addEventListener("pointerdown",s),e.addEventListener("keydown",s),()=>{e.removeEventListener("pointerdown",s),e.removeEventListener("keydown",s)}}),[]),(0,Me.useRefEffect)((()=>{N(),L.current=!0}),[r,...u])]);return{value:b.current,getValue:()=>b.current,onChange:w,ref:C}}function Ge(){}(window.wp=window.wp||{}).richText=t})(); |