2 lines
33 KiB
JavaScript
2 lines
33 KiB
JavaScript
/*! This file is auto-generated */
|
||
!function(){"use strict";var e={n:function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},d:function(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:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(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,{__UNSTABLE_LINE_SEPARATOR:function(){return T},__experimentalRichText:function(){return et},__unstableCreateElement:function(){return E},__unstableFormatEdit:function(){return tt},__unstableInsertLineSeparator:function(){return G},__unstableIsEmptyLine:function(){return H},__unstableToDom:function(){return ge},__unstableUseRichText:function(){return Qe},applyFormat:function(){return b},concat:function(){return W},create:function(){return N},getActiveFormat:function(){return M},getActiveFormats:function(){return k},getActiveObject:function(){return $},getTextContent:function(){return P},insert:function(){return q},insertObject:function(){return Z},isCollapsed:function(){return V},isEmpty:function(){return I},join:function(){return B},registerFormatType:function(){return z},remove:function(){return X},removeFormat:function(){return U},replace:function(){return Y},slice:function(){return J},split:function(){return Q},store:function(){return g},toHTMLString:function(){return be},toggleFormat:function(){return Se},unregisterFormatType:function(){return De},useAnchor:function(){return je},useAnchorRef:function(){return Me}});var n={};e.r(n),e.d(n,{getFormatType:function(){return l},getFormatTypeForBareElement:function(){return f},getFormatTypeForClassName:function(){return d},getFormatTypes:function(){return u}});var r={};e.r(r),e.d(r,{addFormatTypes:function(){return m},removeFormatTypes:function(){return p}});var a=window.wp.data;var o=(0,a.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}}),i={};function s(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 u=function(e,t){var n,r=t||s;function a(){n=new WeakMap}function o(){var t,a,o,s,u,l=arguments.length;for(s=new Array(l),o=0;o<l;o++)s[o]=arguments[o];for(t=function(e){var t,r,a,o,s,c=n,u=!0;for(t=0;t<e.length;t++){if(!(s=r=e[t])||"object"!=typeof s){u=!1;break}c.has(r)?c=c.get(r):(a=new WeakMap,c.set(r,a),c=a)}return c.has(i)||((o=function(){var e={clear:function(){e.head=null}};return e}()).isUniqueByDependants=u,c.set(i,o)),c.get(i)}(u=r.apply(null,s)),t.isUniqueByDependants||(t.lastDependants&&!c(u,t.lastDependants,0)&&t.clear(),t.lastDependants=u),a=t.head;a;){if(c(a.args,s,1))return a!==t.head&&(a.prev.next=a.next,a.next&&(a.next.prev=a.prev),a.next=t.head,a.prev=null,t.head.prev=a,t.head=a),a.val;a=a.next}return a={val:e.apply(null,s)},s[0]=null,a.args=s,t.head&&(t.head.prev=a,a.next=t.head),t.head=a,a.val}return o.getDependants=r,o.clear=a,a(),o}((e=>Object.values(e.formatTypes)),(e=>[e.formatTypes]));function l(e,t){return e.formatTypes[t]}function f(e,t){const n=u(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 u(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,a.createReduxStore)("core/rich-text",{reducer:o,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 a=Object.keys(n),o=Object.keys(r);if(a.length!==o.length)return!1;const i=a.length;for(let e=0;e<i;e++){const t=a[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 a=e.slice();a.forEach(((e,t)=>{const n=r[t];h(e,n)&&(a[t]=n)})),t[n]=a}})),{...e,formats:t}}function y(e,t,n){return(e=e.slice())[t]=n,e}function b(e,t,n=e.start,r=e.end){const{formats:a,activeFormats:o}=e,i=a.slice();if(n===r){const e=i[n]?.find((({type:e})=>e===t.type));if(e){const a=i[n].indexOf(e);for(;i[n]&&i[n][a]===e;)i[n]=y(i[n],a,t),n--;for(r++;i[r]&&i[r][a]===e;)i[r]=y(i[r],a,t),r++}}else{let e=1/0;for(let a=n;a<r;a++)if(i[a]){i[a]=i[a].filter((({type:e})=>e!==t.type));const n=i[a].length;n<e&&(e=n)}else i[a]=[],e=0;for(let a=n;a<r;a++)i[a].splice(e,0,t)}return v({...e,formats:i,activeFormats:[...o?.filter((({type:e})=>e!==t.type))||[],t]})}function E({implementation:e},t){return E.body||(E.body=e.createHTMLDocument("").body),E.body.innerHTML=t,E.body}(0,a.register)(g);const T="\u2028",x="",w="\ufeff";function _({tagName:e,attributes:t}){let n;if(t&&t.class&&(n=(0,a.select)(g).getFormatTypeForClassName(t.class),n&&(t.class=` ${t.class} `.replace(` ${n.className} `," ").trim(),t.class||delete t.class)),n||(n=(0,a.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={},o={},i={...t};for(const e in n.attributes){const t=n.attributes[e];r[e]=i[t],n.__unstableFilterAttributeValue&&(r[e]=n.__unstableFilterAttributeValue(e,r[e])),delete i[t],void 0===r[e]&&delete r[e]}for(const e in i)o[e]=t[e];return!1===n.contentEditable&&delete o.contenteditable,{formatType:n,type:n.name,tagName:e,attributes:r,unregisteredAttributes:o}}function N({element:e,text:t,html:n,range:r,multilineTag:a,multilineWrapperTags:o,__unstableIsEditableTree:i,preserveWhiteSpace:s}={}){return"string"==typeof t&&t.length>0?{formats:Array(t.length),replacements:Array(t.length),text:t}:("string"==typeof n&&n.length>0&&(e=E(document,n)),"object"!=typeof e?{formats:[],replacements:[],text:""}:a?S({element:e,range:r,multilineTag:a,multilineWrapperTags:o,isEditableTree:i,preserveWhiteSpace:s}):R({element:e,range:r,isEditableTree:i,preserveWhiteSpace:s}))}function C(e,t,n,r){if(!n)return;const{parentNode:a}=t,{startContainer:o,startOffset:i,endContainer:s,endOffset:c}=n,u=e.text.length;void 0!==r.start?e.start=u+r.start:t===o&&t.nodeType===t.TEXT_NODE?e.start=u+i:a===o&&t===o.childNodes[i]?e.start=u:a===o&&t===o.childNodes[i-1]?e.start=u+r.text.length:t===o&&(e.start=u),void 0!==r.end?e.end=u+r.end:t===s&&t.nodeType===t.TEXT_NODE?e.end=u+c:a===s&&t===s.childNodes[c-1]?e.end=u+r.text.length:a===s&&t===s.childNodes[c]?e.end=u:t===s&&(e.end=u+c)}function F(e,t,n){if(!t)return;const{startContainer:r,endContainer:a}=t;let{startOffset:o,endOffset:i}=t;return e===r&&(o=n(e.nodeValue.slice(0,o)).length),e===a&&(i=n(e.nodeValue.slice(0,i)).length),{startContainer:r,startOffset:o,endContainer:a,endOffset:i}}function L(e){return e.replace(/[\n\r\t]+/g," ")}function A(e){return e.replace(new RegExp(`[${w}${x}]`,"gu"),"")}function R({element:e,range:t,multilineTag:n,multilineWrapperTags:r,currentWrapperTags:a=[],isEditableTree:o,preserveWhiteSpace:i}){const s={formats:[],replacements:[],text:""};if(!e)return s;if(!e.hasChildNodes())return C(s,e,t,{formats:[],replacements:[],text:""}),s;const c=e.childNodes.length;for(let u=0;u<c;u++){const l=e.childNodes[u],f=l.nodeName.toLowerCase();if(l.nodeType===l.TEXT_NODE){let p=A;i||(p=e=>A(L(e)));const g=p(l.nodeValue);C(s,l,t=F(l,t,p),{text:g}),s.formats.length+=g.length,s.replacements.length+=g.length,s.text+=g;continue}if(l.nodeType!==l.ELEMENT_NODE)continue;if(o&&(l.getAttribute("data-rich-text-placeholder")||"br"===f&&!l.getAttribute("data-rich-text-line-break"))){C(s,l,t,{formats:[],replacements:[],text:""});continue}if("script"===f){const h={formats:[,],replacements:[{type:f,attributes:{"data-rich-text-script":l.getAttribute("data-rich-text-script")||encodeURIComponent(l.innerHTML)}}],text:x};C(s,l,t,h),O(s,h);continue}if("br"===f){C(s,l,t,{formats:[],replacements:[],text:""}),O(s,N({text:"\n"}));continue}const d=_({tagName:f,attributes:D({element:l})});if(!1===d?.formatType?.contentEditable){delete d.formatType,C(s,l,t,{formats:[],replacements:[],text:""}),O(s,{formats:[,],replacements:[{...d,innerHTML:l.innerHTML}],text:x});continue}if(d&&delete d.formatType,r&&-1!==r.indexOf(f)){const v=S({element:l,range:t,multilineTag:n,multilineWrapperTags:r,currentWrapperTags:[...a,d],isEditableTree:o,preserveWhiteSpace:i});C(s,l,t,v),O(s,v);continue}const m=R({element:l,range:t,multilineTag:n,multilineWrapperTags:r,isEditableTree:o,preserveWhiteSpace:i});if(C(s,l,t,m),d)if(0===m.text.length)d.attributes&&O(s,{formats:[,],replacements:[d],text:x});else{function y(e){if(y.formats===e)return y.newFormats;const t=e?[d,...e]:[d];return y.formats=e,y.newFormats=t,t}y.newFormats=[d],O(s,{...m,formats:Array.from(m.formats,y)})}else O(s,m)}return s}function S({element:e,range:t,multilineTag:n,multilineWrapperTags:r,currentWrapperTags:a=[],isEditableTree:o,preserveWhiteSpace:i}){const s={formats:[],replacements:[],text:""};if(!e||!e.hasChildNodes())return s;const c=e.children.length;for(let u=0;u<c;u++){const c=e.children[u];if(c.nodeName.toLowerCase()!==n)continue;const l=R({element:c,range:t,multilineTag:n,multilineWrapperTags:r,currentWrapperTags:a,isEditableTree:o,preserveWhiteSpace:i});(0!==u||a.length>0)&&O(s,{formats:[,],replacements:a.length>0?[a]:[,],text:T}),C(s,c,t,l),O(s,l)}return s}function D({element:e}){if(!e.hasAttributes())return;const t=e.attributes.length;let n;for(let r=0;r<t;r++){const{name:t,value:a}=e.attributes[r];if(0===t.indexOf("data-rich-text-"))continue;n=n||{},n[/^on/i.test(t)?"data-disable-rich-text-"+t:t]=a}return n}function O(e,t){return e.formats=e.formats.concat(t.formats),e.replacements=e.replacements.concat(t.replacements),e.text+=t.text,e}function W(...e){return v(e.reduce(O,N()))}function k(e,t=[]){const{formats:n,start:r,end:a,activeFormats:o}=e;if(void 0===r)return t;if(r===a){if(o)return o;const e=n[r-1]||t,a=n[r]||t;return e.length<a.length?e:a}if(!n[r])return t;const i=n.slice(r,a),s=[...i[0]];let c=i.length;for(;c--;){const e=i[c];if(!e)return t;let n=s.length;for(;n--;){const t=s[n];e.find((e=>h(t,e)))||s.splice(n,1)}if(0===s.length)return t}return s||t}function M(e,t){return k(e).find((({type:e})=>e===t))}function $({start:e,end:t,replacements:n,text:r}){if(e+1===t&&r[e]===x)return n[e]}const j=new RegExp(`[${x}${T}]`,"g");function P({text:e}){return e.replace(j,(e=>e===x?"":"\n"))}function V({start:e,end:t}){if(void 0!==e&&void 0!==t)return e===t}function I({text:e}){return 0===e.length}function H({text:e,start:t,end:n}){return t===n&&(0===e.length||(0===t&&e.slice(0,1)===T||(t===e.length&&e.slice(-1)===T||e.slice(t-1,n+1)===`${T}${T}`)))}function B(e,t=""){return"string"==typeof t&&(t=N({text:t})),v(e.reduce(((e,{formats:n,replacements:r,text:a})=>({formats:e.formats.concat(t.formats,n),replacements:e.replacements.concat(t.replacements,r),text:e.text+t.text+a}))))}function z(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,a.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,a.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,a.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,a.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, 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 U(e,t,n=e.start,r=e.end){const{formats:a,activeFormats:o}=e,i=a.slice();if(n===r){const e=i[n]?.find((({type:e})=>e===t));if(e){for(;i[n]?.find((t=>t===e));)K(i,n,t),n--;for(r++;i[r]?.find((t=>t===e));)K(i,r,t),r++}}else for(let e=n;e<r;e++)i[e]&&K(i,e,t);return v({...e,formats:i,activeFormats:o?.filter((({type:e})=>e!==t))||[]})}function K(e,t,n){const r=e[t].filter((({type:e})=>e!==n));r.length?e[t]=r:delete e[t]}function q(e,t,n=e.start,r=e.end){const{formats:a,replacements:o,text:i}=e;"string"==typeof t&&(t=N({text:t}));const s=n+t.text.length;return v({formats:a.slice(0,n).concat(t.formats,a.slice(r)),replacements:o.slice(0,n).concat(t.replacements,o.slice(r)),text:i.slice(0,n)+t.text+i.slice(r),start:s,end:s})}function X(e,t,n){return q(e,N(),t,n)}function Y({formats:e,replacements:t,text:n,start:r,end:a},o,i){return n=n.replace(o,((n,...o)=>{const s=o[o.length-2];let c,u,l=i;return"function"==typeof l&&(l=i(n,...o)),"object"==typeof l?(c=l.formats,u=l.replacements,l=l.text):(c=Array(l.length),u=Array(l.length),e[s]&&(c=c.fill(e[s]))),e=e.slice(0,s).concat(c,e.slice(s+n.length)),t=t.slice(0,s).concat(u,t.slice(s+n.length)),r&&(r=a=s+l.length),l})),v({formats:e,replacements:t,text:n,start:r,end:a})}function G(e,t=e.start,n=e.end){const r=e.text.slice(0,t).lastIndexOf(T),a=e.replacements[r];let o=[,];a&&(o=[a]);return q(e,{formats:[,],replacements:o,text:T},t,n)}function Z(e,t,n,r){return q(e,{formats:[,],replacements:[t],text:x},n,r)}function J(e,t=e.start,n=e.end){const{formats:r,replacements:a,text:o}=e;return void 0===t||void 0===n?{...e}:{formats:r.slice(t,n),replacements:a.slice(t,n),text:o.slice(t,n)}}function Q({formats:e,replacements:t,text:n,start:r,end:a},o){if("string"!=typeof o)return function({formats:e,replacements:t,text:n,start:r,end:a},o=r,i=a){if(void 0===r||void 0===a)return;const s={formats:e.slice(0,o),replacements:t.slice(0,o),text:n.slice(0,o)},c={formats:e.slice(i),replacements:t.slice(i),text:n.slice(i),start:0,end:0};return[Y(s,/\u2028+$/,""),Y(c,/^\u2028+/,"")]}(...arguments);let i=0;return n.split(o).map((n=>{const s=i,c={formats:e.slice(s,s+n.length),replacements:t.slice(s,s+n.length),text:n};return i+=o.length+n.length,void 0!==r&&void 0!==a&&(r>=s&&r<i?c.start=r-s:r<s&&a>s&&(c.start=0),a>=s&&a<i?c.end=a-s:r<i&&a>i&&(c.end=n.length)),c}))}function ee(e){return(0,a.select)(g).getFormatType(e)}function te(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 ne({type:e,tagName:t,attributes:n,unregisteredAttributes:r,object:a,boundaryClass:o,isEditableTree:i}){const s=ee(e);let c={};if(o&&i&&(c["data-rich-text-format-boundary"]="true"),!s)return n&&(c={...n,...c}),{type:e,attributes:te(c,i),object:a};c={...r,...c};for(const e in n){const t=!!s.attributes&&s.attributes[e];t?c[t]=n[e]:c[e]=n[e]}return s.className&&(c.class?c.class=`${s.className} ${c.class}`:c.class=s.className),i&&!1===s.contentEditable&&(c.contenteditable="false"),{type:t||s.tagName,object:s.object,attributes:te(c,i)}}function re(e,t,n){do{if(e[n]!==t[n])return!1}while(n--);return!0}function ae({value:e,multilineTag:t,preserveWhiteSpace:n,createEmpty:r,append:a,getLastChild:o,getParent:i,isText:s,getText:c,remove:u,appendText:l,onStartIndex:f,onEndIndex:d,isEditableTree:m,placeholder:p}){const{formats:g,replacements:h,text:v,start:y,end:b}=e,E=g.length+1,_=r(),N={type:t},C=k(e),F=C[C.length-1];let L,A,R;t?(a(a(_,{type:t}),""),A=L=[N]):a(_,"");for(let e=0;e<E;e++){const r=v.charAt(e),E=m&&(!R||R===T||"\n"===R);let C=g[e];t&&(C=r===T?L=(h[e]||[]).reduce(((e,t)=>(e.push(t,N),e)),[N]):[...L,...C||[]]);let S=o(_);if(E&&r===T){let e=S;for(;!s(e);)e=o(e);a(i(e),w)}if(R===T){let t=S;for(;!s(t);)t=o(t);f&&y===e&&f(_,t),d&&b===e&&d(_,t)}if(C&&C.forEach(((e,t)=>{if(S&&A&&re(C,A,t)&&(r!==T||C.length-1!==t))return void(S=o(S));const{type:n,tagName:l,attributes:f,unregisteredAttributes:d}=e,p=m&&r!==T&&e===F,g=i(S),h=a(g,ne({type:n,tagName:l,attributes:f,unregisteredAttributes:d,boundaryClass:p,isEditableTree:m}));s(S)&&0===c(S).length&&u(S),S=a(h,"")})),r!==T){if(0===e&&(f&&0===y&&f(_,S),d&&0===b&&d(_,S)),r===x){const t=h[e];if(!t)continue;const{type:n,attributes:r,innerHTML:o}=t,s=ee(n);m||"script"!==n?!1===s?.contentEditable?(S=a(i(S),ne({...t,isEditableTree:m,boundaryClass:y===e&&b===e+1})),o&&a(S,{html:o})):S=a(i(S),ne({...t,object:!0,isEditableTree:m})):(S=a(i(S),ne({type:"script",isEditableTree:m})),a(S,{html:decodeURIComponent(r["data-rich-text-script"])})),S=a(i(S),"")}else n||"\n"!==r?s(S)?l(S,r):S=a(i(S),r):(S=a(i(S),{type:"br",attributes:m?{"data-rich-text-line-break":"true"}:void 0,object:!0}),S=a(i(S),""));f&&y===e+1&&f(_,S),d&&b===e+1&&d(_,S),E&&e===v.length&&(a(i(S),w),p&&0===v.length&&a(i(S),{type:"span",attributes:{"data-rich-text-placeholder":p,contenteditable:"false",style:"pointer-events:none;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;"}})),A=C,R=r}else A=C,R=r}return _}function oe(e,t){return e===t||e&&t&&e.startContainer===t.startContainer&&e.startOffset===t.startOffset&&e.endContainer===t.endContainer&&e.endOffset===t.endOffset}function ie(e,t,n){const r=e.parentNode;let a=0;for(;e=e.previousSibling;)a++;return n=[a,...n],r!==t&&(n=ie(r,t,n)),n}function se(e,t){for(t=[...t];e&&t.length>1;)e=e.childNodes[t.shift()];return{node:e,offset:t[0]}}function ce(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 ue(e,t){e.appendData(t)}function le({lastChild:e}){return e}function fe({parentNode:e}){return e}function de(e){return e.nodeType===e.TEXT_NODE}function me({nodeValue:e}){return e}function pe(e){return e.parentNode.removeChild(e)}function ge({value:e,multilineTag:t,prepareEditableTree:n,isEditableTree:r=!0,placeholder:a,doc:o=document}){let i=[],s=[];n&&(e={...e,formats:n(e)});return{body:ae({value:e,multilineTag:t,createEmpty:()=>E(o,""),append:ce,getLastChild:le,getParent:fe,isText:de,getText:me,remove:pe,appendText:ue,onStartIndex(e,t){i=ie(t,e,[t.nodeValue.length])},onEndIndex(e,t){s=ie(t,e,[t.nodeValue.length])},isEditableTree:r,placeholder:a}),selection:{startPath:i,endPath:s}}}function he({value:e,current:t,multilineTag:n,prepareEditableTree:r,__unstableDomOnly:a,placeholder:o}){const{body:i,selection:s}=ge({value:e,multilineTag:n,prepareEditableTree:r,placeholder:o,doc:t.ownerDocument});ve(i,t),void 0===e.start||a||function({startPath:e,endPath:t},n){const{node:r,offset:a}=se(n,e),{node:o,offset:i}=se(n,t),{ownerDocument:s}=n,{defaultView:c}=s,u=c.getSelection(),l=s.createRange();l.setStart(r,a),l.setEnd(o,i);const{activeElement:f}=s;if(u.rangeCount>0){if(oe(l,u.getRangeAt(0)))return;u.removeAllRanges()}u.addRange(l),f!==s.activeElement&&f instanceof c.HTMLElement&&f.focus()}(s,t)}function ve(e,t){let n,r=0;for(;n=e.firstChild;){const a=t.childNodes[r];if(a)if(a.isEqualNode(n))e.removeChild(n);else if(a.nodeName!==n.nodeName||a.nodeType===a.TEXT_NODE&&a.data!==n.data)t.replaceChild(n,a);else{const t=a.attributes,r=n.attributes;if(t){let e=t.length;for(;e--;){const{name:r}=t[e];n.getAttribute(r)||a.removeAttribute(r)}}if(r)for(let e=0;e<r.length;e++){const{name:t,value:n}=r[e];a.getAttribute(t)!==n&&a.setAttribute(t,n)}ve(n,a),e.removeChild(n)}else t.appendChild(n);r++}for(;t.childNodes[r];)t.removeChild(t.childNodes[r])}var ye=window.wp.escapeHtml;function be({value:e,multilineTag:t,preserveWhiteSpace:n}){return Le(ae({value:e,multilineTag:t,preserveWhiteSpace:n,createEmpty:Ee,append:xe,getLastChild:Te,getParent:_e,isText:Ne,getText:Ce,remove:Fe,appendText:we}).children)}function Ee(){return{}}function Te({children:e}){return e&&e[e.length-1]}function xe(e,t){return"string"==typeof t&&(t={text:t}),t.parent=e,e.children=e.children||[],e.children.push(t),t}function we(e,t){e.text+=t}function _e({parent:e}){return e}function Ne({text:e}){return"string"==typeof e}function Ce({text:e}){return e}function Fe(e){const t=e.parent.children.indexOf(e);return-1!==t&&e.parent.children.splice(t,1),e}function Le(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 a="";for(const e in t)(0,ye.isValidAttributeName)(e)&&(a+=` ${e}="${(0,ye.escapeAttribute)(t[e])}"`);return n?`<${e}${a}>`:`<${e}${a}>${Le(r)}</${e}>`}(e):(0,ye.escapeEditableHTML)(e.text))).join("")}var Ae=window.wp.a11y,Re=window.wp.i18n;function Se(e,t){return M(e,t.type)?(t.title&&(0,Ae.speak)((0,Re.sprintf)((0,Re.__)("%s removed."),t.title),"assertive"),U(e,t.type)):(t.title&&(0,Ae.speak)((0,Re.sprintf)((0,Re.__)("%s applied."),t.title),"assertive"),b(e,t))}function De(e){const t=(0,a.select)(g).getFormatType(e);if(t)return(0,a.dispatch)(g).removeFormatTypes(e),t;window.console.error(`Format ${e} is not registered.`)}var Oe=window.wp.element,We=window.wp.deprecated,ke=e.n(We);function Me({ref:e,value:t,settings:n={}}){ke()("`useAnchorRef` hook",{since:"6.1",alternative:"`useAnchor` hook"});const{tagName:r,className:a,name:o}=n,i=o?M(t,o):void 0;return(0,Oe.useMemo)((()=>{if(!e.current)return;const{ownerDocument:{defaultView:t}}=e.current,n=t.getSelection();if(!n.rangeCount)return;const o=n.getRangeAt(0);if(!i)return o;let s=o.startContainer;for(s=s.nextElementSibling||s;s.nodeType!==s.ELEMENT_NODE;)s=s.parentNode;return s.closest(r+(a?"."+a:""))}),[i,t.start,t.end,r,a])}function $e(e,t,n){if(!e)return;const{ownerDocument:r}=e,{defaultView:a}=r,o=a.getSelection();if(!o)return;if(!o.rangeCount)return;const i=o.getRangeAt(0);if(!i||!i.startContainer)return;const s=function(e,t,n,r){let a=e.startContainer;if(a=a.nextElementSibling||a,a.nodeType!==a.ELEMENT_NODE&&(a=a.parentElement),!a)return;if(a===t)return;if(!t.contains(a))return;const o=n+(r?"."+r:"");for(;a!==t;){if(a.matches(o))return a;a=a.parentElement}}(i,e,t,n);return s||function(e,t){return{ownerDocument:e.startContainer.ownerDocument,getBoundingClientRect(){return t.contains(e.startContainer)?e.getBoundingClientRect():t.getBoundingClientRect()}}}(i,e)}function je({editableContentElement:e,settings:t={}}){const{tagName:n,className:r}=t,[a,o]=(0,Oe.useState)((()=>$e(e,n,r)));return(0,Oe.useLayoutEffect)((()=>{if(!e)return;const{ownerDocument:t}=e;function a(){o($e(e,n,r))}function i(){t.addEventListener("selectionchange",a)}function s(){t.removeEventListener("selectionchange",a)}return e===t.activeElement&&i(),e.addEventListener("focusin",i),e.addEventListener("focusout",s),s}),[e,n,r]),a}var Pe=window.wp.compose;const Ve="pre-wrap",Ie="1px";function He({record:e}){const t=(0,Oe.useRef)(),{activeFormats:n=[],replacements:r,start:a}=e.current,o=r[a];return(0,Oe.useEffect)((()=>{if(!(n&&n.length||o))return;const e="*[data-rich-text-format-boundary]",r=t.current.querySelector(e);if(!r)return;const{ownerDocument:a}=r,{defaultView:i}=a,s=`${`.rich-text:focus ${e}`} {${`background-color: ${i.getComputedStyle(r).color.replace(")",", 0.2)").replace("rgb","rgba")}`}}`,c="rich-text-boundary-style";let u=a.getElementById(c);u||(u=a.createElement("style"),u.id=c,a.head.appendChild(u)),u.innerHTML!==s&&(u.innerHTML=s)}),[n,o]),t}function Be(e){const t=(0,Oe.useRef)(e);return t.current=e,(0,Pe.useRefEffect)((e=>{function n(n){const{record:r,multilineTag:a,preserveWhiteSpace:o}=t.current,{ownerDocument:i}=e;if(V(r.current)||!e.contains(i.activeElement))return;const s=J(r.current),c=P(s),u=be({value:s,multilineTag:a,preserveWhiteSpace:o});n.clipboardData.setData("text/plain",c),n.clipboardData.setData("text/html",u),n.clipboardData.setData("rich-text","true"),n.clipboardData.setData("rich-text-multi-line-tag",a||""),n.preventDefault(),"cut"===n.type&&i.execCommand("delete")}return e.addEventListener("copy",n),e.addEventListener("cut",n),()=>{e.removeEventListener("copy",n),e.removeEventListener("cut",n)}}),[])}var ze=window.wp.keycodes;const Ue=[];function Ke(e){const[,t]=(0,Oe.useReducer)((()=>({}))),n=(0,Oe.useRef)(e);return n.current=e,(0,Pe.useRefEffect)((e=>{function r(r){const{keyCode:a,shiftKey:o,altKey:i,metaKey:s,ctrlKey:c}=r;if(o||i||s||c||a!==ze.LEFT&&a!==ze.RIGHT)return;const{record:u,applyRecord:l}=n.current,{text:f,formats:d,start:m,end:p,activeFormats:g=[]}=u.current,h=V(u.current),{ownerDocument:v}=e,{defaultView:y}=v,{direction:b}=y.getComputedStyle(e),E="rtl"===b?ze.RIGHT:ze.LEFT,T=r.keyCode===E;if(h&&0===g.length){if(0===m&&T)return;if(p===f.length&&!T)return}if(!h)return;const x=d[m-1]||Ue,w=d[m]||Ue,_=T?x:w,N=g.every(((e,t)=>e===_[t]));let C=g.length;if(N?C<_.length&&C++:C--,C===g.length)return void(u.current._newActiveFormats=_);r.preventDefault();const F=(N?_:T?w:x).slice(0,C),L={...u.current,activeFormats:F};u.current=L,l(L),t()}return e.addEventListener("keydown",r),()=>{e.removeEventListener("keydown",r)}}),[])}const qe=new Set(["insertParagraph","insertOrderedList","insertUnorderedList","insertHorizontalRule","insertLink"]),Xe=[],Ye="data-rich-text-placeholder";function Ge(e){const t=(0,Oe.useRef)(e);return t.current=e,(0,Pe.useRefEffect)((e=>{const{ownerDocument:n}=e,{defaultView:r}=n;let a=!1;function o(e){if(a)return;let n;e&&(n=e.inputType);const{record:r,applyRecord:o,createRecord:i,handleChange:s}=t.current;if(n&&(0===n.indexOf("format")||qe.has(n)))return void o(r.current);const c=i(),{start:u,activeFormats:l=[]}=r.current,f=function({value:e,start:t,end:n,formats:r}){const a=Math.min(t,n),o=Math.max(t,n),i=e.formats[a-1]||[],s=e.formats[o]||[];for(e.activeFormats=r.map(((e,t)=>{if(i[t]){if(h(e,i[t]))return i[t]}else if(s[t]&&h(e,s[t]))return s[t];return e}));--n>=t;)e.activeFormats.length>0?e.formats[n]=e.activeFormats:delete e.formats[n];return e}({value:c,start:u,end:c.start,formats:l});s(f)}function i(){const{record:i,applyRecord:s,createRecord:c,onSelectionChange:u}=t.current;if("true"!==e.contentEditable)return;if(n.activeElement!==e){if("true"!==n.activeElement.contentEditable)return;if(!n.activeElement.contains(e))return;const t=r.getSelection(),{anchorNode:a,focusNode:o}=t;if(e.contains(a)&&e!==a&&e.contains(o)&&e!==o){const{start:e,end:t}=c();i.current.activeFormats=Xe,u(e,t)}else if(e.contains(a)&&e!==a){const{start:e,end:t=e}=c();i.current.activeFormats=Xe,u(t)}else if(e.contains(o)){const{start:e,end:t=e}=c();i.current.activeFormats=Xe,u(void 0,t)}return}if(a)return;const{start:l,end:f,text:d}=c(),m=i.current;if(d!==m.text)return void o();if(l===m.start&&f===m.end)return void(0===m.text.length&&0===l&&function(e){const t=e.getSelection(),{anchorNode:n,anchorOffset:r}=t;if(n.nodeType!==n.ELEMENT_NODE)return;const a=n.childNodes[r];a&&a.nodeType===a.ELEMENT_NODE&&a.hasAttribute(Ye)&&t.collapseToStart()}(r));const p={...m,start:l,end:f,activeFormats:m._newActiveFormats,_newActiveFormats:void 0},g=k(p,Xe);p.activeFormats=g,i.current=p,s(p,{domOnly:!0}),u(l,f)}function s(){a=!0,n.removeEventListener("selectionchange",i),e.querySelector(`[${Ye}]`)?.remove()}function c(){a=!1,o({inputType:"insertText"}),n.addEventListener("selectionchange",i)}function u(){const{record:n,isSelected:r,onSelectionChange:a,applyRecord:o}=t.current;if(!e.parentElement.closest('[contenteditable="true"]'))if(r)o(n.current),a(n.current.start,n.current.end);else{const e=void 0;n.current={...n.current,start:e,end:e,activeFormats:Xe}}}return e.addEventListener("input",o),e.addEventListener("compositionstart",s),e.addEventListener("compositionend",c),e.addEventListener("focus",u),n.addEventListener("selectionchange",i),()=>{e.removeEventListener("input",o),e.removeEventListener("compositionstart",s),e.removeEventListener("compositionend",c),e.removeEventListener("focus",u),n.removeEventListener("selectionchange",i)}}),[])}function Ze(e,t=!0){const{replacements:n,text:r,start:a,end:o}=e,i=V(e);let s,c=a-1,u=i?a-1:a,l=o;if(t||(c=o,u=a,l=i?o+1:o),r[c]===T){if(i&&n[c]&&n[c].length){const t=n.slice();t[c]=n[c].slice(0,-1),s={...e,replacements:t}}else s=X(e,u,l);return s}}function Je(e){const t=(0,Oe.useRef)(e);return t.current=e,(0,Pe.useRefEffect)((e=>{function n(e){const{keyCode:n}=e,{createRecord:r,handleChange:a,multilineTag:o}=t.current;if(e.defaultPrevented)return;if(n!==ze.DELETE&&n!==ze.BACKSPACE)return;const i=r(),{start:s,end:c,text:u}=i,l=n===ze.BACKSPACE;if(0===s&&0!==c&&c===u.length)return a(X(i)),void e.preventDefault();if(o){let t;t=l&&0===i.start&&0===i.end&&H(i)?Ze(i,!l):Ze(i,l),t&&(a(t),e.preventDefault())}}return e.addEventListener("keydown",n),()=>{e.removeEventListener("keydown",n)}}),[])}function Qe({value:e="",selectionStart:t,selectionEnd:n,placeholder:r,preserveWhiteSpace:o,onSelectionChange:i,onChange:s,__unstableMultilineTag:c,__unstableDisableFormats:u,__unstableIsSelected:l,__unstableDependencies:f=[],__unstableAfterParse:d,__unstableBeforeSerialize:m,__unstableAddInvisibleFormats:p}){const g=(0,a.useRegistry)(),[,h]=(0,Oe.useReducer)((()=>({}))),v=(0,Oe.useRef)();function y(){const{ownerDocument:{defaultView:e}}=v.current,t=e.getSelection(),n=t.rangeCount>0?t.getRangeAt(0):null;return N({element:v.current,range:n,multilineTag:c,multilineWrapperTags:"li"===c?["ul","ol"]:void 0,__unstableIsEditableTree:!0,preserveWhiteSpace:o})}function b(e,{domOnly:t}={}){he({value:e,current:v.current,multilineTag:c,multilineWrapperTags:"li"===c?["ul","ol"]:void 0,prepareEditableTree:p,__unstableDomOnly:t,placeholder:r})}const E=(0,Oe.useRef)(e),T=(0,Oe.useRef)();function x(){E.current=e,T.current=N({html:e,multilineTag:c,multilineWrapperTags:"li"===c?["ul","ol"]:void 0,preserveWhiteSpace:o}),u&&(T.current.formats=Array(e.length),T.current.replacements=Array(e.length)),d&&(T.current.formats=d(T.current)),T.current.start=t,T.current.end=n}const w=(0,Oe.useRef)(!1);if(T.current)t===T.current.start&&n===T.current.end||(w.current=l,T.current={...T.current,start:t,end:n});else{w.current=l,x();"core/text-color"===T.current?.formats[0]?.[0]?.type&&function(e){T.current=e,E.current=be({value:m?{...e,formats:m(e)}:e,multilineTag:c,preserveWhiteSpace:o});const{formats:t,text:n}=e;g.batch((()=>{s(E.current,{__unstableFormats:t,__unstableText:n})})),h()}(T.current)}function _(e){T.current=e,b(e),E.current=u?e.text:be({value:m?{...e,formats:m(e)}:e,multilineTag:c,preserveWhiteSpace:o});const{start:t,end:n,formats:r,text:a}=e;g.batch((()=>{i(t,n),s(E.current,{__unstableFormats:r,__unstableText:a})})),h()}function C(){x(),b(T.current)}const F=(0,Oe.useRef)(!1);(0,Oe.useLayoutEffect)((()=>{F.current&&e!==E.current&&(C(),h())}),[e]),(0,Oe.useLayoutEffect)((()=>{w.current&&(v.current.ownerDocument.activeElement!==v.current&&v.current.focus(),C(),w.current=!1)}),[w.current]);const L=(0,Pe.useMergeRefs)([v,(0,Oe.useCallback)((e=>{e&&(e.style.whiteSpace=Ve,e.style.minWidth=Ie)}),[]),He({record:T}),Be({record:T,multilineTag:c,preserveWhiteSpace:o}),(0,Pe.useRefEffect)((e=>{function t(t){const{target:n}=t;if(n===e||n.textContent&&n.isContentEditable)return;const{ownerDocument:r}=n,{defaultView:a}=r,o=a.getSelection();if(o.containsNode(n))return;const i=r.createRange(),s=n.isContentEditable?n:n.closest("[contenteditable]");i.selectNode(s),o.removeAllRanges(),o.addRange(i),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)}}),[]),Ke({record:T,applyRecord:b}),Je({createRecord:y,handleChange:_,multilineTag:c}),Ge({record:T,applyRecord:b,createRecord:y,handleChange:_,isSelected:l,onSelectionChange:i}),(0,Pe.useRefEffect)((e=>{const{ownerDocument:t}=e,{defaultView:n}=t,r=n?.getSelection();let a;function o(){return r.rangeCount?r.getRangeAt(0):null}function i(e){const n="keydown"===e.type?"keyup":"pointerup";function r(){t.removeEventListener(n,i),t.removeEventListener("selectionchange",r),t.removeEventListener("input",r)}function i(){r(),oe(a,o())||t.dispatchEvent(new Event("selectionchange"))}t.addEventListener(n,i),t.addEventListener("selectionchange",r),t.addEventListener("input",r),a=o()}return e.addEventListener("pointerdown",i),e.addEventListener("keydown",i),()=>{e.removeEventListener("pointerdown",i),e.removeEventListener("keydown",i)}}),[]),(0,Pe.useRefEffect)((()=>{C(),F.current=!0}),[r,...f])]);return{value:T.current,getValue:()=>T.current,onChange:_,ref:L}}function et(){}function tt({formatTypes:e,onChange:t,onFocus:n,value:r,forwardedRef:a}){return e.map((e=>{const{name:o,edit:i}=e;if(!i)return null;const s=M(r,o),c=void 0!==s,u=$(r),l=void 0!==u&&u.type===o;return(0,Oe.createElement)(i,{key:o,isActive:c,activeAttributes:c&&s.attributes||{},isObjectActive:l,activeObjectAttributes:l&&u.attributes||{},value:r,onChange:t,onFocus:n,contentRef:a})}))}(window.wp=window.wp||{}).richText=t}(); |