@dslate/core
Version:
一个Ant Design风格的富文本编辑器 - An Ant Design style rich editor based on Slate
34 lines (30 loc) • 22 kB
JavaScript
(function(f,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react"),require("slate"),require("slate-react")):typeof define=="function"&&define.amd?define(["exports","react","slate","slate-react"],b):(f=typeof globalThis<"u"?globalThis:f||self,b(f.DSlateCore={},f.React,f.Slate,f.SlateReact))})(this,function(f,b,d,ve){"use strict";function er(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var re={exports:{}},W={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var pe;function rr(){if(pe)return W;pe=1;var t=b,o=Symbol.for("react.element"),n=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,u=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function l(v,h,j){var g,C={},k=null,x=null;j!==void 0&&(k=""+j),h.key!==void 0&&(k=""+h.key),h.ref!==void 0&&(x=h.ref);for(g in h)a.call(h,g)&&!s.hasOwnProperty(g)&&(C[g]=h[g]);if(v&&v.defaultProps)for(g in h=v.defaultProps,h)C[g]===void 0&&(C[g]=h[g]);return{$$typeof:o,type:v,key:k,ref:x,props:C,_owner:u.current}}return W.Fragment=n,W.jsx=l,W.jsxs=l,W}var V={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var ye;function tr(){return ye||(ye=1,process.env.NODE_ENV!=="production"&&function(){var t=b,o=Symbol.for("react.element"),n=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),u=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),v=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),j=Symbol.for("react.suspense"),g=Symbol.for("react.suspense_list"),C=Symbol.for("react.memo"),k=Symbol.for("react.lazy"),x=Symbol.for("react.offscreen"),J=Symbol.iterator,ae="@@iterator";function z(e){if(e===null||typeof e!="object")return null;var r=J&&e[J]||e[ae];return typeof r=="function"?r:null}var F=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(e){{for(var r=arguments.length,i=new Array(r>1?r-1:0),c=1;c<r;c++)i[c-1]=arguments[c];_("error",e,i)}}function _(e,r,i){{var c=F.ReactDebugCurrentFrame,m=c.getStackAddendum();m!==""&&(r+="%s",i=i.concat([m]));var E=i.map(function(y){return String(y)});E.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,E)}}var D=!1,$=!1,P=!1,S=!1,Rr=!1,je;je=Symbol.for("react.module.reference");function Sr(e){return!!(typeof e=="string"||typeof e=="function"||e===a||e===s||Rr||e===u||e===j||e===g||S||e===x||D||$||P||typeof e=="object"&&e!==null&&(e.$$typeof===k||e.$$typeof===C||e.$$typeof===l||e.$$typeof===v||e.$$typeof===h||e.$$typeof===je||e.getModuleId!==void 0))}function wr(e,r,i){var c=e.displayName;if(c)return c;var m=r.displayName||r.name||"";return m!==""?i+"("+m+")":i}function xe(e){return e.displayName||"Context"}function I(e){if(e==null)return null;if(typeof e.tag=="number"&&w("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case a:return"Fragment";case n:return"Portal";case s:return"Profiler";case u:return"StrictMode";case j:return"Suspense";case g:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case v:var r=e;return xe(r)+".Consumer";case l:var i=e;return xe(i._context)+".Provider";case h:return wr(e,e.render,"ForwardRef");case C:var c=e.displayName||null;return c!==null?c:I(e.type)||"Memo";case k:{var m=e,E=m._payload,y=m._init;try{return I(y(E))}catch{return null}}}return null}var U=Object.assign,G=0,Ae,De,Fe,Ie,Le,$e,Ue;function Ne(){}Ne.__reactDisabledLog=!0;function Pr(){{if(G===0){Ae=console.log,De=console.info,Fe=console.warn,Ie=console.error,Le=console.group,$e=console.groupCollapsed,Ue=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Ne,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}G++}}function kr(){{if(G--,G===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:U({},e,{value:Ae}),info:U({},e,{value:De}),warn:U({},e,{value:Fe}),error:U({},e,{value:Ie}),group:U({},e,{value:Le}),groupCollapsed:U({},e,{value:$e}),groupEnd:U({},e,{value:Ue})})}G<0&&w("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var oe=F.ReactCurrentDispatcher,ie;function K(e,r,i){{if(ie===void 0)try{throw Error()}catch(m){var c=m.stack.trim().match(/\n( *(at )?)/);ie=c&&c[1]||""}return`
`+ie+e}}var se=!1,X;{var Or=typeof WeakMap=="function"?WeakMap:Map;X=new Or}function Be(e,r){if(!e||se)return"";{var i=X.get(e);if(i!==void 0)return i}var c;se=!0;var m=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var E;E=oe.current,oe.current=null,Pr();try{if(r){var y=function(){throw Error()};if(Object.defineProperty(y.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(y,[])}catch(L){c=L}Reflect.construct(e,[],y)}else{try{y.call()}catch(L){c=L}e.call(y.prototype)}}else{try{throw Error()}catch(L){c=L}e()}}catch(L){if(L&&c&&typeof L.stack=="string"){for(var p=L.stack.split(`
`),O=c.stack.split(`
`),T=p.length-1,R=O.length-1;T>=1&&R>=0&&p[T]!==O[R];)R--;for(;T>=1&&R>=0;T--,R--)if(p[T]!==O[R]){if(T!==1||R!==1)do if(T--,R--,R<0||p[T]!==O[R]){var A=`
`+p[T].replace(" at new "," at ");return e.displayName&&A.includes("<anonymous>")&&(A=A.replace("<anonymous>",e.displayName)),typeof e=="function"&&X.set(e,A),A}while(T>=1&&R>=0);break}}}finally{se=!1,oe.current=E,kr(),Error.prepareStackTrace=m}var B=e?e.displayName||e.name:"",Qe=B?K(B):"";return typeof e=="function"&&X.set(e,Qe),Qe}function jr(e,r,i){return Be(e,!1)}function xr(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function Z(e,r,i){if(e==null)return"";if(typeof e=="function")return Be(e,xr(e));if(typeof e=="string")return K(e);switch(e){case j:return K("Suspense");case g:return K("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case h:return jr(e.render);case C:return Z(e.type,r,i);case k:{var c=e,m=c._payload,E=c._init;try{return Z(E(m),r,i)}catch{}}}return""}var Q=Object.prototype.hasOwnProperty,We={},Ve=F.ReactDebugCurrentFrame;function ee(e){if(e){var r=e._owner,i=Z(e.type,e._source,r?r.type:null);Ve.setExtraStackFrame(i)}else Ve.setExtraStackFrame(null)}function Ar(e,r,i,c,m){{var E=Function.call.bind(Q);for(var y in e)if(E(e,y)){var p=void 0;try{if(typeof e[y]!="function"){var O=Error((c||"React class")+": "+i+" type `"+y+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[y]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw O.name="Invariant Violation",O}p=e[y](r,y,c,i,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(T){p=T}p&&!(p instanceof Error)&&(ee(m),w("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",c||"React class",i,y,typeof p),ee(null)),p instanceof Error&&!(p.message in We)&&(We[p.message]=!0,ee(m),w("Failed %s type: %s",i,p.message),ee(null))}}}var Dr=Array.isArray;function ue(e){return Dr(e)}function Fr(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,i=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return i}}function Ir(e){try{return Me(e),!1}catch{return!0}}function Me(e){return""+e}function Ye(e){if(Ir(e))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Fr(e)),Me(e)}var H=F.ReactCurrentOwner,Lr={key:!0,ref:!0,__self:!0,__source:!0},ze,Ge,le;le={};function $r(e){if(Q.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function Ur(e){if(Q.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function Nr(e,r){if(typeof e.ref=="string"&&H.current&&r&&H.current.stateNode!==r){var i=I(H.current.type);le[i]||(w('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',I(H.current.type),e.ref),le[i]=!0)}}function Br(e,r){{var i=function(){ze||(ze=!0,w("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};i.isReactWarning=!0,Object.defineProperty(e,"key",{get:i,configurable:!0})}}function Wr(e,r){{var i=function(){Ge||(Ge=!0,w("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};i.isReactWarning=!0,Object.defineProperty(e,"ref",{get:i,configurable:!0})}}var Vr=function(e,r,i,c,m,E,y){var p={$$typeof:o,type:e,key:r,ref:i,props:y,_owner:E};return p._store={},Object.defineProperty(p._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(p,"_self",{configurable:!1,enumerable:!1,writable:!1,value:c}),Object.defineProperty(p,"_source",{configurable:!1,enumerable:!1,writable:!1,value:m}),Object.freeze&&(Object.freeze(p.props),Object.freeze(p)),p};function Mr(e,r,i,c,m){{var E,y={},p=null,O=null;i!==void 0&&(Ye(i),p=""+i),Ur(r)&&(Ye(r.key),p=""+r.key),$r(r)&&(O=r.ref,Nr(r,m));for(E in r)Q.call(r,E)&&!Lr.hasOwnProperty(E)&&(y[E]=r[E]);if(e&&e.defaultProps){var T=e.defaultProps;for(E in T)y[E]===void 0&&(y[E]=T[E])}if(p||O){var R=typeof e=="function"?e.displayName||e.name||"Unknown":e;p&&Br(y,R),O&&Wr(y,R)}return Vr(e,p,O,m,c,H.current,y)}}var ce=F.ReactCurrentOwner,He=F.ReactDebugCurrentFrame;function N(e){if(e){var r=e._owner,i=Z(e.type,e._source,r?r.type:null);He.setExtraStackFrame(i)}else He.setExtraStackFrame(null)}var fe;fe=!1;function de(e){return typeof e=="object"&&e!==null&&e.$$typeof===o}function qe(){{if(ce.current){var e=I(ce.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function Yr(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),i=e.lineNumber;return`
Check your code at `+r+":"+i+"."}return""}}var Je={};function zr(e){{var r=qe();if(!r){var i=typeof e=="string"?e:e.displayName||e.name;i&&(r=`
Check the top-level render call using <`+i+">.")}return r}}function Ke(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var i=zr(r);if(Je[i])return;Je[i]=!0;var c="";e&&e._owner&&e._owner!==ce.current&&(c=" It was passed a child from "+I(e._owner.type)+"."),N(e),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',i,c),N(null)}}function Xe(e,r){{if(typeof e!="object")return;if(ue(e))for(var i=0;i<e.length;i++){var c=e[i];de(c)&&Ke(c,r)}else if(de(e))e._store&&(e._store.validated=!0);else if(e){var m=z(e);if(typeof m=="function"&&m!==e.entries)for(var E=m.call(e),y;!(y=E.next()).done;)de(y.value)&&Ke(y.value,r)}}}function Gr(e){{var r=e.type;if(r==null||typeof r=="string")return;var i;if(typeof r=="function")i=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===h||r.$$typeof===C))i=r.propTypes;else return;if(i){var c=I(r);Ar(i,e.props,"prop",c,e)}else if(r.PropTypes!==void 0&&!fe){fe=!0;var m=I(r);w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",m||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Hr(e){{for(var r=Object.keys(e.props),i=0;i<r.length;i++){var c=r[i];if(c!=="children"&&c!=="key"){N(e),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",c),N(null);break}}e.ref!==null&&(N(e),w("Invalid attribute `ref` supplied to `React.Fragment`."),N(null))}}function Ze(e,r,i,c,m,E){{var y=Sr(e);if(!y){var p="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(p+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var O=Yr(m);O?p+=O:p+=qe();var T;e===null?T="null":ue(e)?T="array":e!==void 0&&e.$$typeof===o?(T="<"+(I(e.type)||"Unknown")+" />",p=" Did you accidentally export a JSX literal instead of a component?"):T=typeof e,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",T,p)}var R=Mr(e,r,i,m,E);if(R==null)return R;if(y){var A=r.children;if(A!==void 0)if(c)if(ue(A)){for(var B=0;B<A.length;B++)Xe(A[B],e);Object.freeze&&Object.freeze(A)}else w("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Xe(A,e)}return e===a?Hr(R):Gr(R),R}}function qr(e,r,i){return Ze(e,r,i,!0)}function Jr(e,r,i){return Ze(e,r,i,!1)}var Kr=Jr,Xr=qr;V.Fragment=a,V.jsx=Kr,V.jsxs=Xr}()),V}process.env.NODE_ENV==="production"?re.exports=rr():re.exports=tr();var nr=re.exports;const me=nr.jsx;/*!
* escape-html
* Copyright(c) 2012-2013 TJ Holowaychuk
* Copyright(c) 2015 Andreas Lubbe
* Copyright(c) 2015 Tiancheng "Timothy" Gu
* MIT Licensed
*/var ar=/["'&<>]/,or=ir;function ir(t){var o=""+t,n=ar.exec(o);if(!n)return o;var a,u="",s=0,l=0;for(s=n.index;s<o.length;s++){switch(o.charCodeAt(s)){case 34:a=""";break;case 38:a="&";break;case 39:a="'";break;case 60:a="<";break;case 62:a=">";break;default:continue}l!==s&&(u+=o.substring(l,s)),l=s+1,u+=a}return l!==s?u+o.substring(l,s):u}const be=er(or),ge={plugins:[],locales:[{locale:"default"}],locale:"default"},Ee=(t,o)=>{const{selection:n}=t;if(!n)return!1;const[a]=Array.from(d.Editor.nodes(t,{match:u=>!d.Editor.isEditor(u)&&d.Element.isElement(u)&&d.Editor.isBlock(t,u)&&u.type===o}));return!!a},sr=(t,o)=>{const n=Ee(t,o);d.Transforms.setNodes(t,{type:n?t.defaultElement:o},{hanging:!0,match:a=>!d.Editor.isEditor(a)&&d.Element.isElement(a)&&d.Editor.isBlock(t,a)&&a.type===(n?o:t.defaultElement)})},ur=(t,o,n)=>{const{selection:a}=t;if(!a)return n;const[u]=d.Editor.nodes(t,{at:d.Editor.unhangRange(t,a),match:l=>!d.Editor.isEditor(l)&&d.Element.isElement(l)&&d.Editor.isBlock(t,l)&&o in l});if(!u)return n;const[s]=u;return s[o]??n},lr=(t,o,n)=>{const{selection:a}=t;a&&d.Transforms.setNodes(t,{[o]:n},{match:u=>!d.Editor.isEditor(u)&&d.Element.isElement(u)&&d.Editor.isBlock(t,u)})},cr=(t,o)=>{const{selection:n}=t;n&&d.Transforms.unsetNodes(t,o,{match:a=>!d.Editor.isEditor(a)&&d.Element.isElement(a)&&d.Editor.isBlock(t,a)})},he=t=>{const o=new FileReader;o.addEventListener("load",()=>{var n;(n=t.onSuccess)==null||n.call(t,{url:o.result})},!1),o.readAsDataURL(t.file)},_e=t=>{const o=new FileReader;o.addEventListener("load",n=>{var u,s;let a=new Blob([(u=n==null?void 0:n.target)==null?void 0:u.result],{type:t.file.type});window.URL=window.URL||window.webkitURL,(s=t.onSuccess)==null||s.call(t,{url:window.URL.createObjectURL(a)})},!1),o.readAsDataURL(t.file)},Ce=(t,o,n)=>{const a=o.replace(/\[(\d+)\]/g,".$1").split(".");let u=t,s=n;for(const l of a)if(s=Object(u)[l],u=Object(u)[l],s===void 0)return n;return s},fr=t=>{var n;if(!t.selection)return!1;const o=(n=d.Editor.above(t))==null?void 0:n[0];return o?d.Node.string(o)===""&&!o.children.some(a=>d.Element.isElement(a)&&d.Editor.isInline(t,a)):!1},dr=(t,o)=>{const n=t.selection;if(n&&d.Range.isCollapsed(n)){const[a]=d.Editor.nodes(t,{match:u=>!d.Editor.isEditor(u)&&d.Element.isElement(u)&&u.type===o});if(a){const[,u]=a,s=d.Editor.start(t,u);if(d.Point.equals(n.anchor,s))return!0}}return!1},vr=(t,o)=>{const n=[...t];for(const a of o)if(a.locale)for(const{locale:u,...s}of a.locale){const l=n.find(v=>v.locale===u);if(l){const v={...l[a.type]||{}};l[a.type]={...s,...v}}else n.push({locale:u,[a.type]:{...s}})}return n},M=(t,o,n,a)=>o.filter(s=>s.nodeType===n).reduce((s,l)=>{const v={...s};if(!l.renderStyle)return{...v};let h={};return typeof l.renderStyle=="function"?h=l.renderStyle(t,a,l.props):t[l.type]&&(h=l.renderStyle),{...v,...h}},{});function pr(t){return t.replace(/([A-Z])/g,function(o){return"-"+o.toLowerCase()}).trim()}const Y=t=>typeof t!="object"?"":Object.keys(t).map(o=>{let n=t[o];return typeof n=="number"&&(n=n+"px"),`${pr(o)}:${n};`}).join(""),yr=(t,o,n,a="dataurl")=>{const{onProgress:u,onError:s,onSuccess:l}=t;return new Promise((v,h)=>{n==null||n(1);const j={...t,onProgress:g=>{u==null||u(g),n==null||n((g==null?void 0:g.percent)??0)},onError:(g,C)=>{h(g),s==null||s(g,C),n==null||n(-1)},onSuccess:g=>{l==null||l(g),n==null||n(0),v(g)}};if(o)o(j);else{if(console.log("defaultType",a),a==="dataurl"){he(j);return}if(a==="bloburl"){_e(j);return}alert("not support upload function"),h("not support upload function"),s==null||s(new Error("not support upload function")),n==null||n(-1)}})},Te=(t,o,n=!1)=>{const a=d.Editor.marks(t);return(a==null?void 0:a[o])??n},mr=(t,o,n)=>{d.Editor.addMark(t,o,n)},br=(t,o)=>{Te(t,o)?d.Editor.removeMark(t,o):d.Editor.addMark(t,o,!0)};let gr=(t=21)=>crypto.getRandomValues(new Uint8Array(t)).reduce((o,n)=>(n&=63,n<36?o+=n.toString(36):n<62?o+=(n-26).toString(36).toUpperCase():n>62?o+="-":o+="_",o),"");const Re=(t,o)=>o.reduce((n,a)=>{a.uuid||(a.uuid=`${a.type}_${gr()}`);const{isVoid:u,isInline:s,normalizeNode:l}=n;return a.isDefaultElement&&(n.defaultElement=a.type),"isVoid"in a&&(n.isVoid=v=>v.type===a.type?a.isVoid?typeof a.isVoid=="function"?a.isVoid(v):a.isVoid:!1:u(v)),"isInline"in a&&(n.isInline=v=>v.type===a.type?a.isInline?typeof a.isInline=="function"?a.isInline(v):a.isInline:!1:s(v)),"normalizeNode"in a&&(n.normalizeNode=v=>{if(a.normalizeNode){a.normalizeNode(v,t,l);return}l(v)}),typeof(a==null?void 0:a.withPlugin)=="function"?a==null?void 0:a.withPlugin(n):n},t),Se=b.createContext({uuid:void 0,type:void 0}),we=()=>b.useContext(Se),te=b.createContext({}),{Consumer:Er,Provider:Pe}=te,ke=()=>b.useContext(te),Oe=()=>{const{uuid:t,type:o}=we(),{plugins:n,pluginProps:a}=q(),u=ke(),{setVisibleKey:s,disabled:l}=u,[v,h]=b.useState(!1),[j,g]=b.useState(!1);b.useEffect(()=>{h(u.visibleKey===t)},[u.visibleKey,t]),b.useEffect(()=>{var x;g(l||(((x=u.disabledTypes)==null?void 0:x.includes(o))??!1))},[u.disabledTypes,o,l]);const C=n==null?void 0:n.find(x=>x.uuid===t),k=b.useCallback(x=>{x?s==null||s(C==null?void 0:C.uuid):s==null||s(void 0)},[t]);return{visible:v,setVisible:k,props:{...(C==null?void 0:C.props)??{},...(a==null?void 0:a[o??""])??{}},uuid:t,type:C==null?void 0:C.type,disabled:j}},ne=b.createContext(ge),{Provider:hr}=ne,q=()=>b.useContext(ne),_r=()=>{const{type:t}=Oe(),{locales:o,locale:n}=q();return(a,u)=>{const s=o.find(l=>l.locale===n)??{locale:"default"};return Ce(s,`${t?`${t}.${a}`:a}`,u)||u}},Cr=b.forwardRef(({value:t,onChange:o,children:n,disabled:a=!1},u)=>{const{plugins:s=[],pluginProps:l}=q(),v=b.useMemo(()=>Re(ve.withReact(d.createEditor()),s),[]),[h,j]=b.useState(void 0),[g,C]=b.useState(0),[k,x]=b.useState([]),J=b.useCallback(_=>{const D=Array.isArray(_)?_:[_];x(k.filter($=>!D.includes($)))},[k]),ae=b.useCallback(_=>{const D=Array.isArray(_)?_:[_];x(Array.from(new Set([...k,...D])))},[k]),z=b.useCallback(_=>{if(d.Text.isText(_)){const S=M(_,s,"text",v);return`<span style="${Y(S)}">${be(_.text)}</span>`}const D=_.children.map(S=>z(S)),$=M(_,s,"element",v),P=Object.values(s).find(S=>S.type===_.type&&S.nodeType==="element");if(P&&P.serialize){const S={...(P==null?void 0:P.props)??{},...(l==null?void 0:l[P.type??""])??{},style:Y($)};return P.serialize(_,S,D)}return D.join("").replace(/style=""/gi,"")},[s,l]),F=b.useCallback(_=>{if(d.Text.isText(_)){const S=M(_,s,"text",v);return{type:"node",name:"span",attrs:{style:Y(S)},children:[{type:"text",text:be(_.text)}]}}const D=_.children.map(S=>F(S)),$=M(_,s,"element",v),P=Object.values(s).find(S=>S.type===_.type&&S.nodeType==="element");if(P&&P.serializeWeapp){const S={...(P==null?void 0:P.props)??{},...(l==null?void 0:l[P.type??""])??{},style:Y($)};return P.serializeWeapp(_,S,D)}return D},[s,l]),w=b.useCallback(()=>v,[v]);return b.useImperativeHandle(u,()=>({serialize:z,getEditor:w,serializeWeapp:F}),[z,w]),me(Pe,{value:{visibleKey:h,setVisibleKey:j,disabledTypes:k,enablePluginByType:J,disablePluginByType:ae,setPercent:C,percent:g,disabled:a},children:me(ve.Slate,{editor:v,initialValue:t,value:t,onChange:o,children:n})})}),Tr={zhCN:"zh-cn",enUS:"en"};f.ConfigContext=ne,f.ConfigProvider=hr,f.DSlateCore=Cr,f.GlobalPluginConsumer=Er,f.GlobalPluginContext=te,f.GlobalPluginProvider=Pe,f.Locales=Tr,f.PluginUuidContext=Se,f.base64file=he,f.blobfile=_e,f.clearBlockProps=cr,f.defaultConfig=ge,f.get=Ce,f.getBlockProps=ur,f.getTextProps=Te,f.isBlockActive=Ee,f.isEmpty=fr,f.isStart=dr,f.mergeLocalteFromPlugins=vr,f.mergeStyle=M,f.promiseUploadFunc=yr,f.setBlockProps=lr,f.setTextProps=mr,f.style2string=Y,f.toggleBlock=sr,f.toggleTextProps=br,f.useConfig=q,f.useMessage=_r,f.usePlugin=Oe,f.usePluginHelper=ke,f.usePluginUuid=we,f.withPlugins=Re,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});