WordPress/wp-includes/js/dist/rich-text.min.js

2 lines
33 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*! This file is auto-generated */
this.wp=this.wp||{},this.wp.richText=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s="yyEc")}({"1ZqX":function(e,t){e.exports=window.wp.data},GRId:function(e,t){e.exports=window.wp.element},K9lf:function(e,t){e.exports=window.wp.compose},RxS6:function(e,t){e.exports=window.wp.keycodes},Vx3V:function(e,t){e.exports=window.wp.escapeHtml},YLtl:function(e,t){e.exports=window.lodash},pPDe:function(e,t,n){"use strict";var r,o;function a(e){return[e]}function c(){var e={clear:function(){e.head=null}};return e}function s(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}r={},o="undefined"!=typeof WeakMap,t.a=function(e,t){var n,i;function u(){n=o?new WeakMap:c()}function l(){var n,r,o,a,c,u=arguments.length;for(a=new Array(u),o=0;o<u;o++)a[o]=arguments[o];for(c=t.apply(null,a),(n=i(c)).isUniqueByDependants||(n.lastDependants&&!s(c,n.lastDependants,0)&&n.clear(),n.lastDependants=c),r=n.head;r;){if(s(r.args,a,1))return r!==n.head&&(r.prev.next=r.next,r.next&&(r.next.prev=r.prev),r.next=n.head,r.prev=null,n.head.prev=r,n.head=r),r.val;r=r.next}return r={val:e.apply(null,a)},a[0]=null,r.args=a,n.head&&(n.head.prev=r,r.next=n.head),n.head=r,r.val}return t||(t=a),i=o?function(e){var t,o,a,s,i,u=n,l=!0;for(t=0;t<e.length;t++){if(o=e[t],!(i=o)||"object"!=typeof i){l=!1;break}u.has(o)?u=u.get(o):(a=new WeakMap,u.set(o,a),u=a)}return u.has(r)||((s=c()).isUniqueByDependants=l,u.set(r,s)),u.get(r)}:function(){return n},l.getDependants=t,l.clear=u,u(),l}},yyEc:function(e,t,n){"use strict";n.r(t),n.d(t,"store",(function(){return g})),n.d(t,"applyFormat",(function(){return y})),n.d(t,"concat",(function(){return D})),n.d(t,"create",(function(){return w})),n.d(t,"getActiveFormat",(function(){return k})),n.d(t,"getActiveObject",(function(){return M})),n.d(t,"getTextContent",(function(){return P})),n.d(t,"__unstableIsListRootSelected",(function(){return $})),n.d(t,"__unstableIsActiveListType",(function(){return V})),n.d(t,"isCollapsed",(function(){return K})),n.d(t,"isEmpty",(function(){return B})),n.d(t,"__unstableIsEmptyLine",(function(){return H})),n.d(t,"join",(function(){return z})),n.d(t,"registerFormatType",(function(){return q})),n.d(t,"removeFormat",(function(){return X})),n.d(t,"remove",(function(){return G})),n.d(t,"replace",(function(){return Z})),n.d(t,"insert",(function(){return U})),n.d(t,"__unstableInsertLineSeparator",(function(){return J})),n.d(t,"__unstableRemoveLineSeparator",(function(){return Q})),n.d(t,"insertObject",(function(){return ee})),n.d(t,"slice",(function(){return te})),n.d(t,"split",(function(){return ne})),n.d(t,"__unstableToDom",(function(){return he})),n.d(t,"toHTMLString",(function(){return ye})),n.d(t,"toggleFormat",(function(){return Le})),n.d(t,"__UNSTABLE_LINE_SEPARATOR",(function(){return x})),n.d(t,"unregisterFormatType",(function(){return Re})),n.d(t,"__unstableCanIndentListItems",(function(){return Ne})),n.d(t,"__unstableCanOutdentListItems",(function(){return Se})),n.d(t,"__unstableIndentListItems",(function(){return Ae})),n.d(t,"__unstableOutdentListItems",(function(){return We})),n.d(t,"__unstableChangeListType",(function(){return ke})),n.d(t,"__unstableCreateElement",(function(){return T})),n.d(t,"useAnchorRef",(function(){return Pe})),n.d(t,"__experimentalRichText",(function(){return Je})),n.d(t,"__unstableUseRichText",(function(){return Ze})),n.d(t,"__unstableFormatEdit",(function(){return Qe}));var r={};n.r(r),n.d(r,"getFormatTypes",(function(){return u})),n.d(r,"getFormatType",(function(){return l})),n.d(r,"getFormatTypeForBareElement",(function(){return f})),n.d(r,"getFormatTypeForClassName",(function(){return d}));var o={};n.r(o),n.d(o,"addFormatTypes",(function(){return m})),n.d(o,"removeFormatTypes",(function(){return p}));var a=n("1ZqX"),c=n("YLtl");var s=Object(a.combineReducers)({formatTypes:function(e={},t){switch(t.type){case"ADD_FORMAT_TYPES":return{...e,...Object(c.keyBy)(t.formatTypes,"name")};case"REMOVE_FORMAT_TYPES":return Object(c.omit)(e,t.names)}return e}}),i=n("pPDe");const u=Object(i.a)(e=>Object.values(e.formatTypes),e=>[e.formatTypes]);function l(e,t){return e.formatTypes[t]}function f(e,t){return Object(c.find)(u(e),({className:e,tagName:n})=>null===e&&t===n)}function d(e,t){return Object(c.find)(u(e),({className:e})=>null!==e&&` ${t} `.indexOf(` ${e} `)>=0)}function m(e){return{type:"ADD_FORMAT_TYPES",formatTypes:Object(c.castArray)(e)}}function p(e){return{type:"REMOVE_FORMAT_TYPES",names:Object(c.castArray)(e)}}const g=Object(a.createReduxStore)("core/rich-text",{reducer:s,selectors:r,actions:o});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 c=o.length;for(let e=0;e<c;e++){const t=o[e];if(n[t]!==r[t])return!1}return!0}function b(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 v(e,t,n){return(e=e.slice())[t]=n,e}function y(e,t,n=e.start,r=e.end){const{formats:o,activeFormats:a}=e,s=o.slice();if(n===r){const e=Object(c.find)(s[n],{type:t.type});if(e){const o=s[n].indexOf(e);for(;s[n]&&s[n][o]===e;)s[n]=v(s[n],o,t),n--;for(r++;s[r]&&s[r][o]===e;)s[r]=v(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 b({...e,formats:s,activeFormats:[...Object(c.reject)(a,{type:t.type}),t]})}function T({implementation:e},t){return T.body||(T.body=e.createHTMLDocument("").body),T.body.innerHTML=t,T.body}Object(a.register)(g);const x="\u2028";function E(e,t){for(const n in e)if(e[n]===t)return n}function O({type:e,attributes:t}){let n;if(t&&t.class&&(n=Object(a.select)("core/rich-text").getFormatTypeForClassName(t.class),n&&(t.class=` ${t.class} `.replace(` ${n.className} `," ").trim(),t.class||delete t.class)),n||(n=Object(a.select)("core/rich-text").getFormatTypeForBareElement(e)),!n)return t?{type:e,attributes:t}:{type:e};if(n.__experimentalCreatePrepareEditableTree&&!n.__experimentalCreateOnChangeEditableValue)return null;if(!t)return{type:n.name};const r={},o={};for(const e in t){const a=E(n.attributes,e);a?r[a]=t[e]:o[e]=t[e]}return{type:n.name,attributes:r,unregisteredAttributes:o}}function w({element:e,text:t,html:n,range:r,multilineTag:o,multilineWrapperTags:a,__unstableIsEditableTree:c,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=T(document,n)),"object"!=typeof e?{formats:[],replacements:[],text:""}:o?N({element:e,range:r,multilineTag:o,multilineWrapperTags:a,isEditableTree:c,preserveWhiteSpace:s}):R({element:e,range:r,isEditableTree:c,preserveWhiteSpace:s}))}function _(e,t,n,r){if(!n)return;const{parentNode:o}=t,{startContainer:a,startOffset:c,endContainer:s,endOffset:i}=n,u=e.text.length;void 0!==r.start?e.start=u+r.start:t===a&&t.nodeType===t.TEXT_NODE?e.start=u+c:o===a&&t===a.childNodes[c]?e.start=u:o===a&&t===a.childNodes[c-1]?e.start=u+r.text.length:t===a&&(e.start=u),void 0!==r.end?e.end=u+r.end:t===s&&t.nodeType===t.TEXT_NODE?e.end=u+i:o===s&&t===s.childNodes[i-1]?e.end=u+r.text.length:o===s&&t===s.childNodes[i]?e.end=u:t===s&&(e.end=u+i)}function j(e,t,n){if(!t)return;const{startContainer:r,endContainer:o}=t;let{startOffset:a,endOffset:c}=t;return e===r&&(a=n(e.nodeValue.slice(0,a)).length),e===o&&(c=n(e.nodeValue.slice(0,c)).length),{startContainer:r,startOffset:a,endContainer:o,endOffset:c}}function C(e){return e.replace(/[\n\r\t]+/g," ")}const F=new RegExp("\ufeff","g");function L(e){return e.replace(F,"")}function R({element:e,range:t,multilineTag:n,multilineWrapperTags:r,currentWrapperTags:o=[],isEditableTree:a,preserveWhiteSpace:c}){const s={formats:[],replacements:[],text:""};if(!e)return s;if(!e.hasChildNodes())return _(s,e,t,{formats:[],replacements:[],text:""}),s;const i=e.childNodes.length;for(let l=0;l<i;l++){const i=e.childNodes[l],f=i.nodeName.toLowerCase();if(i.nodeType===i.TEXT_NODE){let e=L;c||(e=e=>L(C(e)));const n=e(i.nodeValue);_(s,i,t=j(i,t,e),{text:n}),s.formats.length+=n.length,s.replacements.length+=n.length,s.text+=n;continue}if(i.nodeType!==i.ELEMENT_NODE)continue;if(a&&(i.getAttribute("data-rich-text-placeholder")||"br"===f&&!i.getAttribute("data-rich-text-line-break"))){_(s,i,t,{formats:[],replacements:[],text:""});continue}if("br"===f){_(s,i,t,{formats:[],replacements:[],text:""}),A(s,w({text:"\n"}));continue}const d=s.formats[s.formats.length-1],m=d&&d[d.length-1],p=O({type:f,attributes:S({element:i})}),g=h(p,m)?m:p;if(r&&-1!==r.indexOf(f)){const e=N({element:i,range:t,multilineTag:n,multilineWrapperTags:r,currentWrapperTags:[...o,g],isEditableTree:a,preserveWhiteSpace:c});_(s,i,t,e),A(s,e);continue}const b=R({element:i,range:t,multilineTag:n,multilineWrapperTags:r,isEditableTree:a,preserveWhiteSpace:c});if(_(s,i,t,b),g)if(0===b.text.length)g.attributes&&A(s,{formats:[,],replacements:[g],text:""});else{function u(e){if(u.formats===e)return u.newFormats;const t=e?[g,...e]:[g];return u.formats=e,u.newFormats=t,t}u.newFormats=[g],A(s,{...b,formats:Array.from(b.formats,u)})}else A(s,b)}return s}function N({element:e,range:t,multilineTag:n,multilineWrapperTags:r,currentWrapperTags:o=[],isEditableTree:a,preserveWhiteSpace:c}){const s={formats:[],replacements:[],text:""};if(!e||!e.hasChildNodes())return s;const i=e.children.length;for(let u=0;u<i;u++){const i=e.children[u];if(i.nodeName.toLowerCase()!==n)continue;const l=R({element:i,range:t,multilineTag:n,multilineWrapperTags:r,currentWrapperTags:o,isEditableTree:a,preserveWhiteSpace:c});(0!==u||o.length>0)&&A(s,{formats:[,],replacements:o.length>0?[o]:[,],text:x}),_(s,i,t,l),A(s,l)}return s}function S({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];0!==t.indexOf("data-rich-text-")&&(n=n||{},n[t]=o)}return n}function A(e,t){return e.formats=e.formats.concat(t.formats),e.replacements=e.replacements.concat(t.replacements),e.text+=t.text,e}function D(...e){return b(e.reduce(A,w()))}function W({formats:e,start:t,end:n,activeFormats:r},o=[]){if(void 0===t)return o;if(t===n){if(r)return r;const n=e[t-1]||o,a=e[t]||o;return n.length<a.length?n:a}return e[t]||o}function k(e,t){return Object(c.find)(W(e),{type:t})}function M({start:e,end:t,replacements:n,text:r}){if(e+1===t&&""===r[e])return n[e]}function P({text:e}){return e.replace(new RegExp("","g"),"").replace(new RegExp(x,"g"),"\n")}function I({start:e,text:t},n=e){let r=n;for(;r--;)if(t[r]===x)return r}function $(e){const{replacements:t,start:n}=e,r=t[I(e,n)];return!r||r.length<1}function V(e,t,n){const{replacements:r,start:o}=e,a=r[I(e,o)];if(!a||0===a.length)return t===n;return a[a.length-1].type===t}function K({start:e,end:t}){if(void 0!==e&&void 0!==t)return e===t}function B({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)===x||(t===e.length&&e.slice(-1)===x||e.slice(t-1,n+1)===`${x}${x}`)))}function z(e,t=""){return"string"==typeof t&&(t=w({text:t})),b(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 q(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(Object(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=Object(a.select)(g).getFormatTypeForBareElement(t.tagName);if(e)return void window.console.error(`Format "${e.name}" is already registered to handle bare tag name "${t.tagName}".`)}else{const e=Object(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 Object(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 X(e,t,n=e.start,r=e.end){const{formats:o,activeFormats:a}=e,s=o.slice();if(n===r){const e=Object(c.find)(s[n],{type:t});if(e){for(;Object(c.find)(s[n],e);)Y(s,n,t),n--;for(r++;Object(c.find)(s[r],e);)Y(s,r,t),r++}}else for(let e=n;e<r;e++)s[e]&&Y(s,e,t);return b({...e,formats:s,activeFormats:Object(c.reject)(a,{type:t})})}function Y(e,t,n){const r=e[t].filter(({type:e})=>e!==n);r.length?e[t]=r:delete e[t]}function U(e,t,n=e.start,r=e.end){const{formats:o,replacements:a,text:c}=e;"string"==typeof t&&(t=w({text:t}));const s=n+t.text.length;return b({formats:o.slice(0,n).concat(t.formats,o.slice(r)),replacements:a.slice(0,n).concat(t.replacements,a.slice(r)),text:c.slice(0,n)+t.text+c.slice(r),start:s,end:s})}function G(e,t,n){return U(e,w(),t,n)}function Z({formats:e,replacements:t,text:n,start:r,end:o},a,c){return n=n.replace(a,(n,...a)=>{const s=a[a.length-2];let i,u,l=c;return"function"==typeof l&&(l=c(n,...a)),"object"==typeof l?(i=l.formats,u=l.replacements,l=l.text):(i=Array(l.length),u=Array(l.length),e[s]&&(i=i.fill(e[s]))),e=e.slice(0,s).concat(i,e.slice(s+n.length)),t=t.slice(0,s).concat(u,t.slice(s+n.length)),r&&(r=o=s+l.length),l}),b({formats:e,replacements:t,text:n,start:r,end:o})}function J(e,t=e.start,n=e.end){const r=e.text.slice(0,t).lastIndexOf(x),o=e.replacements[r];let a=[,];o&&(a=[o]);return U(e,{formats:[,],replacements:a,text:x},t,n)}function Q(e,t=!0){const{replacements:n,text:r,start:o,end:a}=e,c=K(e);let s,i=o-1,u=c?o-1:o,l=a;if(t||(i=a,u=o,l=c?a+1:a),r[i]===x){if(c&&n[i]&&n[i].length){const t=n.slice();t[i]=n[i].slice(0,-1),s={...e,replacements:t}}else s=G(e,u,l);return s}}function ee(e,t,n,r){return U(e,{formats:[,],replacements:[t],text:""},n,r)}function te(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 ne({formats:e,replacements:t,text:n,start:r,end:o},a){if("string"!=typeof a)return re(...arguments);let c=0;return n.split(a).map(n=>{const s=c,i={formats:e.slice(s,s+n.length),replacements:t.slice(s,s+n.length),text:n};return c+=a.length+n.length,void 0!==r&&void 0!==o&&(r>=s&&r<c?i.start=r-s:r<s&&o>s&&(i.start=0),o>=s&&o<c?i.end=o-s:r<c&&o>c&&(i.end=n.length)),i})}function re({formats:e,replacements:t,text:n,start:r,end:o},a=r,c=o){if(void 0===r||void 0===o)return;const s={formats:e.slice(0,a),replacements:t.slice(0,a),text:n.slice(0,a)},i={formats:e.slice(c),replacements:t.slice(c),text:n.slice(c),start:0,end:0};return[Z(s,/\u2028+$/,""),Z(i,/^\u2028+/,"")]}function oe({type:e,attributes:t,unregisteredAttributes:n,object:r,boundaryClass:o}){const c=(s=e,Object(a.select)(g).getFormatType(s));var s;let i={};if(o&&(i["data-rich-text-format-boundary"]="true"),!c)return t&&(i={...t,...i}),{type:e,attributes:i,object:r};i={...n,...i};for(const e in t){const n=!!c.attributes&&c.attributes[e];n?i[n]=t[e]:i[e]=t[e]}return c.className&&(i.class?i.class=`${c.className} ${i.class}`:i.class=c.className),{type:c.tagName,object:c.object,attributes:i}}function ae(e,t,n){do{if(e[n]!==t[n])return!1}while(n--);return!0}function ce({value:e,multilineTag:t,preserveWhiteSpace:n,createEmpty:r,append:o,getLastChild:a,getParent:c,isText:s,getText:i,remove:u,appendText:l,onStartIndex:f,onEndIndex:d,isEditableTree:m,placeholder:p}){const{formats:g,replacements:h,text:b,start:v,end:y}=e,T=g.length+1,E=r(),O={type:t},w=W(e),_=w[w.length-1];let j,C,F;t?(o(o(E,{type:t}),""),C=j=[O]):o(E,"");for(let e=0;e<T;e++){const r=b.charAt(e),T=m&&(!F||F===x||"\n"===F);let w=g[e];t&&(w=r===x?j=(h[e]||[]).reduce((e,t)=>(e.push(t,O),e),[O]):[...j,...w||[]]);let L=a(E);if(T&&r===x){let e=L;for(;!s(e);)e=a(e);o(c(e),"\ufeff")}if(F===x){let t=L;for(;!s(t);)t=a(t);f&&v===e&&f(E,t),d&&y===e&&d(E,t)}w&&w.forEach((e,t)=>{if(L&&C&&ae(w,C,t)&&(r!==x||w.length-1!==t))return void(L=a(L));const{type:n,attributes:l,unregisteredAttributes:f}=e,d=m&&r!==x&&e===_,p=c(L),g=o(p,oe({type:n,attributes:l,unregisteredAttributes:f,boundaryClass:d}));s(L)&&0===i(L).length&&u(L),L=o(g,"")}),r!==x?(0===e&&(f&&0===v&&f(E,L),d&&0===y&&d(E,L)),""===r?(L=o(c(L),oe({...h[e],object:!0})),L=o(c(L),"")):n||"\n"!==r?s(L)?l(L,r):L=o(c(L),r):(L=o(c(L),{type:"br",attributes:m?{"data-rich-text-line-break":"true"}:void 0,object:!0}),L=o(c(L),"")),f&&v===e+1&&f(E,L),d&&y===e+1&&d(E,L),T&&e===b.length&&(o(c(L),"\ufeff"),p&&0===b.length&&o(c(L),{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;"}})),C=w,F=r):(C=w,F=r)}return E}function se(e,t,n){const r=e.parentNode;let o=0;for(;e=e.previousSibling;)o++;return n=[o,...n],r!==t&&(n=se(r,t,n)),n}function ie(e,t){for(t=[...t];e&&t.length>1;)e=e.childNodes[t.shift()];return{node:e,offset:t[0]}}function ue(e,t){"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 le(e,t){e.appendData(t)}function fe({lastChild:e}){return e}function de({parentNode:e}){return e}function me(e){return e.nodeType===e.TEXT_NODE}function pe({nodeValue:e}){return e}function ge(e){return e.parentNode.removeChild(e)}function he({value:e,multilineTag:t,prepareEditableTree:n,isEditableTree:r=!0,placeholder:o,doc:a=document}){let c=[],s=[];n&&(e={...e,formats:n(e)});return{body:ce({value:e,multilineTag:t,createEmpty:()=>T(a,""),append:ue,getLastChild:fe,getParent:de,isText:me,getText:pe,remove:ge,appendText:le,onStartIndex(e,t){c=se(t,e,[t.nodeValue.length])},onEndIndex(e,t){s=se(t,e,[t.nodeValue.length])},isEditableTree:r,placeholder:o}),selection:{startPath:c,endPath:s}}}function be({value:e,current:t,multilineTag:n,prepareEditableTree:r,__unstableDomOnly:o,placeholder:a}){const{body:c,selection:s}=he({value:e,multilineTag:n,prepareEditableTree:r,placeholder:a,doc:t.ownerDocument});!function e(t,n){let r,o=0;for(;r=t.firstChild;){const a=n.childNodes[o];if(a)if(a.isEqualNode(r))t.removeChild(r);else if(a.nodeName!==r.nodeName||a.nodeType===a.TEXT_NODE&&a.data!==r.data)n.replaceChild(r,a);else{const n=a.attributes,o=r.attributes;if(n){let e=n.length;for(;e--;){const{name:t}=n[e];r.getAttribute(t)||a.removeAttribute(t)}}if(o)for(let e=0;e<o.length;e++){const{name:t,value:n}=o[e];a.getAttribute(t)!==n&&a.setAttribute(t,n)}e(r,a),t.removeChild(r)}else n.appendChild(r);o++}for(;n.childNodes[o];)n.removeChild(n.childNodes[o])}(c,t),void 0===e.start||o||function({startPath:e,endPath:t},n){const{node:r,offset:o}=ie(n,e),{node:a,offset:c}=ie(n,t),{ownerDocument:s}=n,{defaultView:i}=s,u=i.getSelection(),l=s.createRange();l.setStart(r,o),l.setEnd(a,c);const{activeElement:f}=s;if(u.rangeCount>0){if(d=l,m=u.getRangeAt(0),d.startContainer===m.startContainer&&d.startOffset===m.startOffset&&d.endContainer===m.endContainer&&d.endOffset===m.endOffset)return;u.removeAllRanges()}var d,m;u.addRange(l),f!==s.activeElement&&f instanceof i.HTMLElement&&f.focus()}(s,t)}var ve=n("Vx3V");function ye({value:e,multilineTag:t,preserveWhiteSpace:n}){return Fe(ce({value:e,multilineTag:t,preserveWhiteSpace:n,createEmpty:Te,append:Ee,getLastChild:xe,getParent:we,isText:_e,getText:je,remove:Ce,appendText:Oe}).children)}function Te(){return{}}function xe({children:e}){return e&&e[e.length-1]}function Ee(e,t){return"string"==typeof t&&(t={text:t}),t.parent=e,e.children=e.children||[],e.children.push(t),t}function Oe(e,t){e.text+=t}function we({parent:e}){return e}function _e({text:e}){return"string"==typeof e}function je({text:e}){return e}function Ce(e){const t=e.parent.children.indexOf(e);return-1!==t&&e.parent.children.splice(t,1),e}function Fe(e=[]){return e.map(e=>void 0===e.text?function({type:e,attributes:t,object:n,children:r}){let o="";for(const e in t)Object(ve.isValidAttributeName)(e)&&(o+=` ${e}="${Object(ve.escapeAttribute)(t[e])}"`);return n?`<${e}${o}>`:`<${e}${o}>${Fe(r)}</${e}>`}(e):Object(ve.escapeEditableHTML)(e.text)).join("")}function Le(e,t){return k(e,t.type)?X(e,t.type):y(e,t)}function Re(e){const t=Object(a.select)(g).getFormatType(e);if(t)return Object(a.dispatch)(g).removeFormatTypes(e),t;window.console.error(`Format ${e} is not registered.`)}function Ne(e){const t=I(e);if(void 0===t)return!1;const{replacements:n}=e,r=I(e,t),o=n[t]||[],a=n[r]||[];return o.length<=a.length}function Se(e){const{replacements:t,start:n}=e;return void 0!==t[I(e,n)]}function Ae(e,t){if(!Ne(e))return e;const n=I(e),r=I(e,n),{text:o,replacements:a,end:c}=e,s=a.slice(),i=function({text:e,replacements:t},n){const r=t[n]||[];let o=n;for(;o-- >=0;){if(e[o]!==x)continue;const n=t[o]||[];if(n.length===r.length+1)return o;if(n.length<=r.length)return}}(e,n);for(let e=n;e<c;e++)if(o[e]===x)if(i){const t=a[i]||[];s[e]=t.concat((s[e]||[]).slice(t.length-1))}else{const n=a[r]||[],o=n[n.length-1]||t;s[e]=n.concat([o],(s[e]||[]).slice(n.length))}return{...e,replacements:s}}function De({text:e,replacements:t},n){const r=t[n]||[];let o=n;for(;o-- >=0;){if(e[o]!==x)continue;if((t[o]||[]).length===r.length-1)return o}}function We(e){if(!Se(e))return e;const{text:t,replacements:n,start:r,end:o}=e,a=I(e,r),c=n.slice(0),s=n[De(e,a)]||[],i=function({text:e,replacements:t},n){const r=t[n]||[];let o=n;for(let a=n||0;a<e.length;a++){if(e[a]!==x)continue;if(!((t[a]||[]).length>=r.length))return o;o=a}return o}(e,I(e,o));for(let e=a;e<=i;e++){if(t[e]!==x)continue;const n=c[e]||[];c[e]=s.concat(n.slice(s.length+1)),0===c[e].length&&delete c[e]}return{...e,replacements:c}}function ke(e,t){const{text:n,replacements:r,start:o,end:a}=e,c=I(e,o),s=r[c]||[],i=r[I(e,a)]||[],u=De(e,c),l=r.slice(),f=s.length-1,d=i.length-1;let m;for(let e=u+1||0;e<n.length;e++)if(n[e]===x){if((l[e]||[]).length<=f)break;l[e]&&(m=!0,l[e]=l[e].map((e,n)=>n<f||n>d?e:t))}return m?{...e,replacements:l}:e}var Me=n("GRId");function Pe({ref:e,value:t,settings:n={}}){const{tagName:r,className:o,name:a}=n,c=a?k(t,a):void 0;return Object(Me.useMemo)(()=>{if(!e.current)return;const{ownerDocument:{defaultView:t}}=e.current,n=t.getSelection();if(!n.rangeCount)return;const a=n.getRangeAt(0);if(!c)return a;let s=a.startContainer;for(s=s.nextElementSibling||s;s.nodeType!==s.ELEMENT_NODE;)s=s.parentNode;return s.closest(r+(o?"."+o:""))},[c,t.start,t.end,r,o])}var Ie=n("K9lf");function $e({record:e}){const t=Object(Me.useRef)(),{activeFormats:n=[]}=e.current;return Object(Me.useEffect)(()=>{if(!n||!n.length)return;const e=t.current.querySelector("*[data-rich-text-format-boundary]");if(!e)return;const{ownerDocument:r}=e,{defaultView:o}=r,a=`.rich-text:focus *[data-rich-text-format-boundary] {${"background-color: "+o.getComputedStyle(e).color.replace(")",", 0.2)").replace("rgb","rgba")}}`;let c=r.getElementById("rich-text-boundary-style");c||(c=r.createElement("style"),c.id="rich-text-boundary-style",r.head.appendChild(c)),c.innerHTML!==a&&(c.innerHTML=a)},[n]),t}function Ve(){const e=Object(Me.useRef)();return Object(Me.useEffect)(()=>{0},[]),e}function Ke(e){const t=Object(Me.useRef)(e);return t.current=e,Object(Ie.useRefEffect)(e=>{function n(n){const{record:r,multilineTag:o,preserveWhiteSpace:a}=t.current;if(K(r.current)||!e.contains(e.ownerDocument.activeElement))return;const c=te(r.current),s=P(c),i=ye({value:c,multilineTag:o,preserveWhiteSpace:a});n.clipboardData.setData("text/plain",s),n.clipboardData.setData("text/html",i),n.clipboardData.setData("rich-text","true"),n.preventDefault()}return e.addEventListener("copy",n),()=>{e.removeEventListener("copy",n)}},[])}var Be=n("RxS6");const He=[];function ze(e){const[,t]=Object(Me.useReducer)(()=>({})),n=Object(Me.useRef)(e);return n.current=e,Object(Ie.useRefEffect)(e=>{function r(r){const{keyCode:o,shiftKey:a,altKey:c,metaKey:s,ctrlKey:i}=r;if(a||c||s||i||o!==Be.LEFT&&o!==Be.RIGHT)return;const{record:u,applyRecord:l}=n.current,{text:f,formats:d,start:m,end:p,activeFormats:g=[]}=u.current,h=K(u.current),{ownerDocument:b}=e,{defaultView:v}=b,{direction:y}=v.getComputedStyle(e),T="rtl"===y?Be.RIGHT:Be.LEFT,x=r.keyCode===T;if(h&&0===g.length){if(0===m&&x)return;if(p===f.length&&!x)return}if(!h)return;const E=d[m-1]||He,O=d[m]||He;let w=g.length,_=O;if(E.length>O.length&&(_=E),E.length<O.length?(!x&&g.length<O.length&&w++,x&&g.length>E.length&&w--):E.length>O.length&&(!x&&g.length>O.length&&w--,x&&g.length<E.length&&w++),w===g.length)return void(u.current._newActiveFormats=x?E:O);r.preventDefault();const j=_.slice(0,w),C={...u.current,activeFormats:j};u.current=C,l(C),t()}return e.addEventListener("keydown",r),()=>{e.removeEventListener("keydown",r)}},[])}function qe(e){const t=Object(Me.useRef)(e);return t.current=e,Object(Ie.useRefEffect)(e=>{function n(n){const{keyCode:r,shiftKey:o,altKey:a,metaKey:c,ctrlKey:s}=n,{multilineTag:i,createRecord:u,handleChange:l}=t.current;if(o||a||c||s||r!==Be.SPACE||"li"!==i)return;const f=u();if(!K(f))return;const{text:d,start:m}=f,p=d[m-1];p&&p!==x||(l(Ae(f,{type:e.tagName.toLowerCase()})),n.preventDefault())}return e.addEventListener("keydown",n),()=>{e.removeEventListener("keydown",n)}},[])}const Xe=new Set(["insertParagraph","insertOrderedList","insertUnorderedList","insertHorizontalRule","insertLink"]),Ye=[];function Ue(e){const t=Object(Me.useRef)(e);return t.current=e,Object(Ie.useRefEffect)(e=>{const{ownerDocument:n}=e,{defaultView:r}=n;let o,a=!1;function c(e){if(a)return;let n;e&&(n=e.inputType);const{record:r,applyRecord:o,createRecord:c,handleChange:s}=t.current;if(n&&(0===n.indexOf("format")||Xe.has(n)))return void o(r.current);const i=c(),{start:u,activeFormats:l=[]}=r.current;s(function({value:e,start:t,end:n,formats:r}){const o=e.formats[t-1]||[],a=e.formats[n]||[];for(e.activeFormats=r.map((e,t)=>{if(o[t]){if(h(e,o[t]))return o[t]}else if(a[t]&&h(e,a[t]))return a[t];return e});--n>=t;)e.activeFormats.length>0?e.formats[n]=e.activeFormats:delete e.formats[n];return e}({value:i,start:u,end:i.start,formats:l}))}function s(o){if(n.activeElement!==e)return;const{record:s,applyRecord:i,createRecord:u,isSelected:l,onSelectionChange:f}=t.current;if("selectionchange"!==o.type&&!l)return;if("true"!==e.contentEditable)return;if(a)return;const{start:d,end:m,text:p}=u(),g=s.current;if(p!==g.text)return void c();if(d===g.start&&m===g.end)return void(0===g.text.length&&0===d&&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.getAttribute("data-rich-text-placeholder")&&t.collapseToStart()}(r));const h={...g,start:d,end:m,activeFormats:g._newActiveFormats,_newActiveFormats:void 0},b=W(h,Ye);h.activeFormats=b,s.current=h,i(h,{domOnly:!0}),f(d,m)}function i(){a=!0,n.removeEventListener("selectionchange",s)}function u(){a=!1,c({inputType:"insertText"}),n.addEventListener("selectionchange",s)}function l(){const{record:e,isSelected:a,onSelectionChange:c}=t.current;if(a)c(e.current.start,e.current.end);else{const t=void 0;e.current={...e.current,start:t,end:t,activeFormats:Ye},c(t,t)}o=r.requestAnimationFrame(s),n.addEventListener("selectionchange",s)}function f(){n.removeEventListener("selectionchange",s)}return e.addEventListener("input",c),e.addEventListener("compositionstart",i),e.addEventListener("compositionend",u),e.addEventListener("focus",l),e.addEventListener("blur",f),e.addEventListener("keyup",s),e.addEventListener("mouseup",s),e.addEventListener("touchend",s),()=>{e.removeEventListener("input",c),e.removeEventListener("compositionstart",i),e.removeEventListener("compositionend",u),e.removeEventListener("focus",l),e.removeEventListener("blur",f),e.removeEventListener("keyup",s),e.removeEventListener("mouseup",s),e.removeEventListener("touchend",s),n.removeEventListener("selectionchange",s),r.cancelAnimationFrame(o)}},[])}function Ge(e){const t=Object(Me.useRef)(e);return t.current=e,Object(Ie.useRefEffect)(e=>{function n(e){const{keyCode:n}=e,{createRecord:r,handleChange:o,multilineTag:a}=t.current;if(e.defaultPrevented)return;if(n!==Be.DELETE&&n!==Be.BACKSPACE)return;const c=r(),{start:s,end:i,text:u}=c,l=n===Be.BACKSPACE;if(0===s&&0!==i&&i===u.length)return o(G(c)),void e.preventDefault();if(a){let t;t=l&&0===c.start&&0===c.end&&H(c)?Q(c,!l):Q(c,l),t&&(o(t),e.preventDefault())}}return e.addEventListener("keydown",n),()=>{e.removeEventListener("keydown",n)}},[])}function Ze({value:e="",selectionStart:t,selectionEnd:n,placeholder:r,preserveWhiteSpace:o,onSelectionChange:a,onChange:c,__unstableMultilineTag:s,__unstableDisableFormats:i,__unstableIsSelected:u,__unstableDependencies:l,__unstableAfterParse:f,__unstableBeforeSerialize:d,__unstableAddInvisibleFormats:m}){const[,p]=Object(Me.useReducer)(()=>({})),g=Object(Me.useRef)();function h(){const{ownerDocument:{defaultView:e}}=g.current,t=e.getSelection(),n=t.rangeCount>0?t.getRangeAt(0):null;return w({element:g.current,range:n,multilineTag:s,multilineWrapperTags:"li"===s?["ul","ol"]:void 0,__unstableIsEditableTree:!0,preserveWhiteSpace:o})}function b(e,{domOnly:t}={}){be({value:e,current:g.current,multilineTag:s,multilineWrapperTags:"li"===s?["ul","ol"]:void 0,prepareEditableTree:m,__unstableDomOnly:t,placeholder:r})}const v=Object(Me.useRef)(e),y=Object(Me.useRef)();function T(){v.current=e,y.current=w({html:e,multilineTag:s,multilineWrapperTags:"li"===s?["ul","ol"]:void 0,preserveWhiteSpace:o}),i&&(y.current.formats=Array(e.length),y.current.replacements=Array(e.length)),y.current.formats=f(y.current),y.current.start=t,y.current.end=n}const x=Object(Me.useRef)(!1);function E(e){b(e),v.current=i?e.text:ye({value:{...e,formats:d(e)},multilineTag:s,preserveWhiteSpace:o}),y.current=e;const{start:t,end:n,formats:r,text:u}=e;a(t,n),c(v.current,{__unstableFormats:r,__unstableText:u}),p()}function O(){T(),b(y.current)}y.current?t===y.current.start&&n===y.current.end||(x.current=u,y.current={...y.current,start:t,end:n}):T();const _=Object(Me.useRef)(!1);Object(Me.useLayoutEffect)(()=>{_.current&&e!==v.current&&O()},[e]),Object(Me.useLayoutEffect)(()=>{x.current&&(O(),x.current=!1)},[x.current]);const j=Object(Ie.useMergeRefs)([g,Object(Me.useCallback)(e=>{e&&(e.style.whiteSpace="pre-wrap",e.style.minWidth="1px")},[]),$e({record:y}),Ve(),Ke({record:y,multilineTag:s,preserveWhiteSpace:o}),Object(Ie.useRefEffect)(e=>{function t(t){const{target:n}=t;if(n===e||n.textContent)return;const{ownerDocument:r}=n,{defaultView:o}=r,a=r.createRange(),c=o.getSelection();a.selectNode(n),c.removeAllRanges(),c.addRange(a)}return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}},[]),ze({record:y,applyRecord:b}),Ge({createRecord:h,handleChange:E,multilineTag:s}),qe({multilineTag:s,createRecord:h,handleChange:E}),Ue({record:y,applyRecord:b,createRecord:h,handleChange:E,isSelected:u,onSelectionChange:a}),Object(Ie.useRefEffect)(()=>{O(),_.current=!0},[r,...l])]);return{value:y.current,onChange:E,onFocus:function(){g.current.focus(),b(y.current)},ref:j}}function Je(){}function Qe({formatTypes:e,onChange:t,onFocus:n,value:r,forwardedRef:o}){return e.map(e=>{const{name:a,edit:c}=e;if(!c)return null;const s=k(r,a),i=void 0!==s,u=M(r),l=void 0!==u&&u.type===a;return Object(Me.createElement)(c,{key:a,isActive:i,activeAttributes:i&&s.attributes||{},isObjectActive:l,activeObjectAttributes:l&&u.attributes||{},value:r,onChange:t,onFocus:n,contentRef:o})})}}});