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 i(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,s;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=s(c)).isUniqueByDependants||(n.lastDependants&&!i(c,n.lastDependants,0)&&n.clear(),n.lastDependants=c),r=n.head;r;){if(i(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),s=o?function(e){var t,o,a,i,s,u=n,l=!0;for(t=0;t<e.length;t++){if(o=e[t],!(s=o)||"object"!=typeof s){l=!1;break}u.has(o)?u=u.get(o):(a=new WeakMap,u.set(o,a),u=a)}return u.has(r)||((i=c()).isUniqueByDependants=l,u.set(r,i)),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 I})),n.d(t,"__unstableIsListRootSelected",(function(){return $})),n.d(t,"__unstableIsActiveListType",(function(){return V})),n.d(t,"isCollapsed",(function(){return H})),n.d(t,"isEmpty",(function(){return K})),n.d(t,"__unstableIsEmptyLine",(function(){return B})),n.d(t,"join",(function(){return z})),n.d(t,"registerFormatType",(function(){return q})),n.d(t,"removeFormat",(function(){return U})),n.d(t,"remove",(function(){return G})),n.d(t,"replace",(function(){return Z})),n.d(t,"insert",(function(){return Y})),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 be})),n.d(t,"toHTMLString",(function(){return Te})),n.d(t,"toggleFormat",(function(){return Le})),n.d(t,"__UNSTABLE_LINE_SEPARATOR",(function(){return x})),n.d(t,"unregisterFormatType",(function(){return Ne})),n.d(t,"__unstableCanIndentListItems",(function(){return Se})),n.d(t,"__unstableCanOutdentListItems",(function(){return Ae})),n.d(t,"__unstableIndentListItems",(function(){return De})),n.d(t,"__unstableOutdentListItems",(function(){return ke})),n.d(t,"__unstableChangeListType",(function(){return Me})),n.d(t,"__unstableCreateElement",(function(){return T})),n.d(t,"useAnchorRef",(function(){return Pe})),n.d(t,"__experimentalRichText",(function(){return Qe})),n.d(t,"__unstableUseRichText",(function(){return Je})),n.d(t,"__unstableFormatEdit",(function(){return et}));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 i=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}}),s=n("pPDe");const u=Object(s.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:i,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,i=o.slice();if(n===r){const e=Object(c.find)(i[n],{type:t.type});if(e){const o=i[n].indexOf(e);for(;i[n]&&i[n][o]===e;)i[n]=v(i[n],o,t),n--;for(r++;i[r]&&i[r][o]===e;)i[r]=v(i[r],o,t),r++}}else{let e=1/0;for(let o=n;o<r;o++)if(i[o]){i[o]=i[o].filter(({type:e})=>e!==t.type);const n=i[o].length;n<e&&(e=n)}else i[o]=[],e=0;for(let o=n;o<r;o++)i[o].splice(e,0,t)}return b({...e,formats:i,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:i}={}){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:i}):L({element:e,range:r,isEditableTree:c,preserveWhiteSpace:i}))}function _(e,t,n,r){if(!n)return;const{parentNode:o}=t,{startContainer:a,startOffset:c,endContainer:i,endOffset:s}=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===i&&t.nodeType===t.TEXT_NODE?e.end=u+s:o===i&&t===i.childNodes[s-1]?e.end=u+r.text.length:o===i&&t===i.childNodes[s]?e.end=u:t===i&&(e.end=u+s)}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 R(e){return e.replace(F,"")}function L({element:e,range:t,multilineTag:n,multilineWrapperTags:r,currentWrapperTags:o=[],isEditableTree:a,preserveWhiteSpace:c}){const i={formats:[],replacements:[],text:""};if(!e)return i;if(!e.hasChildNodes())return _(i,e,t,{formats:[],replacements:[],text:""}),i;const s=e.childNodes.length;for(let l=0;l<s;l++){const s=e.childNodes[l],f=s.nodeName.toLowerCase();if(s.nodeType===s.TEXT_NODE){let e=R;c||(e=e=>R(C(e)));const n=e(s.nodeValue);_(i,s,t=j(s,t,e),{text:n}),i.formats.length+=n.length,i.replacements.length+=n.length,i.text+=n;continue}if(s.nodeType!==s.ELEMENT_NODE)continue;if(a&&(s.getAttribute("data-rich-text-placeholder")||"br"===f&&!s.getAttribute("data-rich-text-line-break"))){_(i,s,t,{formats:[],replacements:[],text:""});continue}if("script"===f){const e={formats:[,],replacements:[{type:f,attributes:{"data-rich-text-script":s.getAttribute("data-rich-text-script")||encodeURIComponent(s.innerHTML)}}],text:""};_(i,s,t,e),A(i,e);continue}if("br"===f){_(i,s,t,{formats:[],replacements:[],text:""}),A(i,w({text:"\n"}));continue}const d=i.formats[i.formats.length-1],m=d&&d[d.length-1],p=O({type:f,attributes:S({element:s})}),g=h(p,m)?m:p;if(r&&-1!==r.indexOf(f)){const e=N({element:s,range:t,multilineTag:n,multilineWrapperTags:r,currentWrapperTags:[...o,g],isEditableTree:a,preserveWhiteSpace:c});_(i,s,t,e),A(i,e);continue}const b=L({element:s,range:t,multilineTag:n,multilineWrapperTags:r,isEditableTree:a,preserveWhiteSpace:c});if(_(i,s,t,b),g)if(0===b.text.length)g.attributes&&A(i,{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(i,{...b,formats:Array.from(b.formats,u)})}else A(i,b)}return i}function N({element:e,range:t,multilineTag:n,multilineWrapperTags:r,currentWrapperTags:o=[],isEditableTree:a,preserveWhiteSpace:c}){const i={formats:[],replacements:[],text:""};if(!e||!e.hasChildNodes())return i;const s=e.children.length;for(let u=0;u<s;u++){const s=e.children[u];if(s.nodeName.toLowerCase()!==n)continue;const l=L({element:s,range:t,multilineTag:n,multilineWrapperTags:r,currentWrapperTags:o,isEditableTree:a,preserveWhiteSpace:c});(0!==u||o.length>0)&&A(i,{formats:[,],replacements:o.length>0?[o]:[,],text:x}),_(i,s,t,l),A(i,l)}return i}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];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 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 I({text:e}){return e.replace(new RegExp("","g"),"").replace(new RegExp(x,"g"),"\n")}function P({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[P(e,n)];return!r||r.length<1}function V(e,t,n){const{replacements:r,start:o}=e,a=r[P(e,o)];if(!a||0===a.length)return t===n;return a[a.length-1].type===t}function H({start:e,end:t}){if(void 0!==e&&void 0!==t)return e===t}function K({text:e}){return 0===e.length}function B({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 U(e,t,n=e.start,r=e.end){const{formats:o,activeFormats:a}=e,i=o.slice();if(n===r){const e=Object(c.find)(i[n],{type:t});if(e){for(;Object(c.find)(i[n],e);)X(i,n,t),n--;for(r++;Object(c.find)(i[r],e);)X(i,r,t),r++}}else for(let e=n;e<r;e++)i[e]&&X(i,e,t);return b({...e,formats:i,activeFormats:Object(c.reject)(a,{type:t})})}function X(e,t,n){const r=e[t].filter(({type:e})=>e!==n);r.length?e[t]=r:delete e[t]}function Y(e,t,n=e.start,r=e.end){const{formats:o,replacements:a,text:c}=e;"string"==typeof t&&(t=w({text:t}));const i=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:i,end:i})}function G(e,t,n){return Y(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 i=a[a.length-2];let s,u,l=c;return"function"==typeof l&&(l=c(n,...a)),"object"==typeof l?(s=l.formats,u=l.replacements,l=l.text):(s=Array(l.length),u=Array(l.length),e[i]&&(s=s.fill(e[i]))),e=e.slice(0,i).concat(s,e.slice(i+n.length)),t=t.slice(0,i).concat(u,t.slice(i+n.length)),r&&(r=o=i+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 Y(e,{formats:[,],replacements:a,text:x},t,n)}function Q(e,t=!0){const{replacements:n,text:r,start:o,end:a}=e,c=H(e);let i,s=o-1,u=c?o-1:o,l=a;if(t||(s=a,u=o,l=c?a+1:a),r[s]===x){if(c&&n[s]&&n[s].length){const t=n.slice();t[s]=n[s].slice(0,-1),i={...e,replacements:t}}else i=G(e,u,l);return i}}function ee(e,t,n,r){return Y(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 i=c,s={formats:e.slice(i,i+n.length),replacements:t.slice(i,i+n.length),text:n};return c+=a.length+n.length,void 0!==r&&void 0!==o&&(r>=i&&r<c?s.start=r-i:r<i&&o>i&&(s.start=0),o>=i&&o<c?s.end=o-i:r<c&&o>c&&(s.end=n.length)),s})}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 i={formats:e.slice(0,a),replacements:t.slice(0,a),text:n.slice(0,a)},s={formats:e.slice(c),replacements:t.slice(c),text:n.slice(c),start:0,end:0};return[Z(i,/\u2028+$/,""),Z(s,/^\u2028+/,"")]}function oe(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("data-disable-rich-text-".length)),n[r]=e[t]}return n}function ae({type:e,attributes:t,unregisteredAttributes:n,object:r,boundaryClass:o,isEditableTree:c}){const i=(s=e,Object(a.select)(g).getFormatType(s));var s;let u={};if(o&&(u["data-rich-text-format-boundary"]="true"),!i)return t&&(u={...t,...u}),{type:e,attributes:oe(u,c),object:r};u={...n,...u};for(const e in t){const n=!!i.attributes&&i.attributes[e];n?u[n]=t[e]:u[e]=t[e]}return i.className&&(u.class?u.class=`${i.className} ${u.class}`:u.class=i.className),{type:i.tagName,object:i.object,attributes:oe(u,c)}}function ce(e,t,n){do{if(e[n]!==t[n])return!1}while(n--);return!0}function ie({value:e,multilineTag:t,preserveWhiteSpace:n,createEmpty:r,append:o,getLastChild:a,getParent:c,isText:i,getText:s,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 R=a(E);if(T&&r===x){let e=R;for(;!i(e);)e=a(e);o(c(e),"\ufeff")}if(F===x){let t=R;for(;!i(t);)t=a(t);f&&v===e&&f(E,t),d&&y===e&&d(E,t)}w&&w.forEach((e,t)=>{if(R&&C&&ce(w,C,t)&&(r!==x||w.length-1!==t))return void(R=a(R));const{type:n,attributes:l,unregisteredAttributes:f}=e,d=m&&r!==x&&e===_,p=c(R),g=o(p,ae({type:n,attributes:l,unregisteredAttributes:f,boundaryClass:d,isEditableTree:m}));i(R)&&0===s(R).length&&u(R),R=o(g,"")}),r!==x?(0===e&&(f&&0===v&&f(E,R),d&&0===y&&d(E,R)),""===r?(m||"script"!==h[e].type?R=o(c(R),ae({...h[e],object:!0,isEditableTree:m})):(R=o(c(R),ae({type:"script",isEditableTree:m})),o(R,{html:decodeURIComponent(h[e].attributes["data-rich-text-script"])})),R=o(c(R),"")):n||"\n"!==r?i(R)?l(R,r):R=o(c(R),r):(R=o(c(R),{type:"br",attributes:m?{"data-rich-text-line-break":"true"}:void 0,object:!0}),R=o(c(R),"")),f&&v===e+1&&f(E,R),d&&y===e+1&&d(E,R),T&&e===b.length&&(o(c(R),"\ufeff"),p&&0===b.length&&o(c(R),{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 ue(e,t){for(t=[...t];e&&t.length>1;)e=e.childNodes[t.shift()];return{node:e,offset:t[0]}}function le(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 fe(e,t){e.appendData(t)}function de({lastChild:e}){return e}function me({parentNode:e}){return e}function pe(e){return e.nodeType===e.TEXT_NODE}function ge({nodeValue:e}){return e}function he(e){return e.parentNode.removeChild(e)}function be({value:e,multilineTag:t,prepareEditableTree:n,isEditableTree:r=!0,placeholder:o,doc:a=document}){let c=[],i=[];n&&(e={...e,formats:n(e)});return{body:ie({value:e,multilineTag:t,createEmpty:()=>T(a,""),append:le,getLastChild:de,getParent:me,isText:pe,getText:ge,remove:he,appendText:fe,onStartIndex(e,t){c=se(t,e,[t.nodeValue.length])},onEndIndex(e,t){i=se(t,e,[t.nodeValue.length])},isEditableTree:r,placeholder:o}),selection:{startPath:c,endPath:i}}}function ve({value:e,current:t,multilineTag:n,prepareEditableTree:r,__unstableDomOnly:o,placeholder:a}){const{body:c,selection:i}=be({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}=ue(n,e),{node:a,offset:c}=ue(n,t),{ownerDocument:i}=n,{defaultView:s}=i,u=s.getSelection(),l=i.createRange();l.setStart(r,o),l.setEnd(a,c);const{activeElement:f}=i;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!==i.activeElement&&f instanceof s.HTMLElement&&f.focus()}(i,t)}var ye=n("Vx3V");function Te({value:e,multilineTag:t,preserveWhiteSpace:n}){return Re(ie({value:e,multilineTag:t,preserveWhiteSpace:n,createEmpty:xe,append:Oe,getLastChild:Ee,getParent:_e,isText:je,getText:Ce,remove:Fe,appendText:we}).children)}function xe(){return{}}function Ee({children:e}){return e&&e[e.length-1]}function Oe(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 je({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 Re(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)Object(ye.isValidAttributeName)(e)&&(o+=` ${e}="${Object(ye.escapeAttribute)(t[e])}"`);return n?`<${e}${o}>`:`<${e}${o}>${Re(r)}</${e}>`}(e):Object(ye.escapeEditableHTML)(e.text)).join("")}function Le(e,t){return k(e,t.type)?U(e,t.type):y(e,t)}function Ne(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 Se(e){const t=P(e);if(void 0===t)return!1;const{replacements:n}=e,r=P(e,t),o=n[t]||[],a=n[r]||[];return o.length<=a.length}function Ae(e){const{replacements:t,start:n}=e;return void 0!==t[P(e,n)]}function De(e,t){if(!Se(e))return e;const n=P(e),r=P(e,n),{text:o,replacements:a,end:c}=e,i=a.slice(),s=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(s){const t=a[s]||[];i[e]=t.concat((i[e]||[]).slice(t.length-1))}else{const n=a[r]||[],o=n[n.length-1]||t;i[e]=n.concat([o],(i[e]||[]).slice(n.length))}return{...e,replacements:i}}function We({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 ke(e){if(!Ae(e))return e;const{text:t,replacements:n,start:r,end:o}=e,a=P(e,r),c=n.slice(0),i=n[We(e,a)]||[],s=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,P(e,o));for(let e=a;e<=s;e++){if(t[e]!==x)continue;const n=c[e]||[];c[e]=i.concat(n.slice(i.length+1)),0===c[e].length&&delete c[e]}return{...e,replacements:c}}function Me(e,t){const{text:n,replacements:r,start:o,end:a}=e,c=P(e,o),i=r[c]||[],s=r[P(e,a)]||[],u=We(e,c),l=r.slice(),f=i.length-1,d=s.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 Ie=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(Ie.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 i=a.startContainer;for(i=i.nextElementSibling||i;i.nodeType!==i.ELEMENT_NODE;)i=i.parentNode;return i.closest(r+(o?"."+o:""))},[c,t.start,t.end,r,o])}var $e=n("K9lf");function Ve({record:e}){const t=Object(Ie.useRef)(),{activeFormats:n=[]}=e.current;return Object(Ie.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 He(){const e=Object(Ie.useRef)();return Object(Ie.useEffect)(()=>{0},[]),e}function Ke(e){const t=Object(Ie.useRef)(e);return t.current=e,Object($e.useRefEffect)(e=>{function n(n){const{record:r,multilineTag:o,preserveWhiteSpace:a}=t.current;if(H(r.current)||!e.contains(e.ownerDocument.activeElement))return;const c=te(r.current),i=I(c),s=Te({value:c,multilineTag:o,preserveWhiteSpace:a});n.clipboardData.setData("text/plain",i),n.clipboardData.setData("text/html",s),n.clipboardData.setData("rich-text","true"),n.preventDefault()}return e.addEventListener("copy",n),()=>{e.removeEventListener("copy",n)}},[])}var Be=n("RxS6");const ze=[];function qe(e){const[,t]=Object(Ie.useReducer)(()=>({})),n=Object(Ie.useRef)(e);return n.current=e,Object($e.useRefEffect)(e=>{function r(r){const{keyCode:o,shiftKey:a,altKey:c,metaKey:i,ctrlKey:s}=r;if(a||c||i||s||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=H(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]||ze,O=d[m]||ze;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 Ue(e){const t=Object(Ie.useRef)(e);return t.current=e,Object($e.useRefEffect)(e=>{function n(n){const{keyCode:r,shiftKey:o,altKey:a,metaKey:c,ctrlKey:i}=n,{multilineTag:s,createRecord:u,handleChange:l}=t.current;if(o||a||c||i||r!==Be.SPACE||"li"!==s)return;const f=u();if(!H(f))return;const{text:d,start:m}=f,p=d[m-1];p&&p!==x||(l(De(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 Ge(e){const t=Object(Ie.useRef)(e);return t.current=e,Object($e.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:i}=t.current;if(n&&(0===n.indexOf("format")||Xe.has(n)))return void o(r.current);const s=c(),{start:u,activeFormats:l=[]}=r.current;i(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:s,start:u,end:s.start,formats:l}))}function i(o){if(n.activeElement!==e)return;const{record:i,applyRecord:s,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=i.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,i.current=h,s(h,{domOnly:!0}),f(d,m)}function s(){a=!0,n.removeEventListener("selectionchange",i)}function u(){a=!1,c({inputType:"insertText"}),n.addEventListener("selectionchange",i)}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(i),n.addEventListener("selectionchange",i)}function f(){n.removeEventListener("selectionchange",i)}return e.addEventListener("input",c),e.addEventListener("compositionstart",s),e.addEventListener("compositionend",u),e.addEventListener("focus",l),e.addEventListener("blur",f),e.addEventListener("keyup",i),e.addEventListener("mouseup",i),e.addEventListener("touchend",i),()=>{e.removeEventListener("input",c),e.removeEventListener("compositionstart",s),e.removeEventListener("compositionend",u),e.removeEventListener("focus",l),e.removeEventListener("blur",f),e.removeEventListener("keyup",i),e.removeEventListener("mouseup",i),e.removeEventListener("touchend",i),n.removeEventListener("selectionchange",i),r.cancelAnimationFrame(o)}},[])}function Ze(e){const t=Object(Ie.useRef)(e);return t.current=e,Object($e.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:i,end:s,text:u}=c,l=n===Be.BACKSPACE;if(0===i&&0!==s&&s===u.length)return o(G(c)),void e.preventDefault();if(a){let t;t=l&&0===c.start&&0===c.end&&B(c)?Q(c,!l):Q(c,l),t&&(o(t),e.preventDefault())}}return e.addEventListener("keydown",n),()=>{e.removeEventListener("keydown",n)}},[])}function Je({value:e="",selectionStart:t,selectionEnd:n,placeholder:r,preserveWhiteSpace:o,onSelectionChange:a,onChange:c,__unstableMultilineTag:i,__unstableDisableFormats:s,__unstableIsSelected:u,__unstableDependencies:l,__unstableAfterParse:f,__unstableBeforeSerialize:d,__unstableAddInvisibleFormats:m}){const[,p]=Object(Ie.useReducer)(()=>({})),g=Object(Ie.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:i,multilineWrapperTags:"li"===i?["ul","ol"]:void 0,__unstableIsEditableTree:!0,preserveWhiteSpace:o})}function b(e,{domOnly:t}={}){ve({value:e,current:g.current,multilineTag:i,multilineWrapperTags:"li"===i?["ul","ol"]:void 0,prepareEditableTree:m,__unstableDomOnly:t,placeholder:r})}const v=Object(Ie.useRef)(e),y=Object(Ie.useRef)();function T(){v.current=e,y.current=w({html:e,multilineTag:i,multilineWrapperTags:"li"===i?["ul","ol"]:void 0,preserveWhiteSpace:o}),s&&(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(Ie.useRef)(!1);function E(e){b(e),v.current=s?e.text:Te({value:{...e,formats:d(e)},multilineTag:i,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(Ie.useRef)(!1);Object(Ie.useLayoutEffect)(()=>{_.current&&e!==v.current&&O()},[e]),Object(Ie.useLayoutEffect)(()=>{x.current&&(O(),x.current=!1)},[x.current]);const j=Object($e.useMergeRefs)([g,Object(Ie.useCallback)(e=>{e&&(e.style.whiteSpace="pre-wrap",e.style.minWidth="1px")},[]),Ve({record:y}),He(),Ke({record:y,multilineTag:i,preserveWhiteSpace:o}),Object($e.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)}},[]),qe({record:y,applyRecord:b}),Ze({createRecord:h,handleChange:E,multilineTag:i}),Ue({multilineTag:i,createRecord:h,handleChange:E}),Ge({record:y,applyRecord:b,createRecord:h,handleChange:E,isSelected:u,onSelectionChange:a}),Object($e.useRefEffect)(()=>{O(),_.current=!0},[r,...l])]);return{value:y.current,onChange:E,onFocus:function(){g.current.focus(),b(y.current)},ref:j}}function Qe(){}function et({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 i=k(r,a),s=void 0!==i,u=M(r),l=void 0!==u&&u.type===a;return Object(Ie.createElement)(c,{key:a,isActive:s,activeAttributes:s&&i.attributes||{},isObjectActive:l,activeObjectAttributes:l&&u.attributes||{},value:r,onChange:t,onFocus:n,contentRef:o})})}}});