@bloklabs/react 1.10.1 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +69 -65
- package/package.json +2 -2
- package/src/config-keys.ts +1 -0
- package/src/types.ts +1 -0
- package/src/useBlok.ts +14 -0
- package/types/index.d.ts +1 -0
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("@bloklabs/core"),n=require("@bloklabs/core/adapters"),r=require("react/jsx-runtime"),i=require("@bloklabs/core/locales"),a=require("react-dom"),o=require("@bloklabs/core/view"),s=require("react-dom/client");var c=new WeakMap;function l(e,t){c.set(e,t)}function u(e){return c.get(e)}function d(e){c.delete(e)}function f(e){"@babel/helpers - typeof";return f=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},f(e)}function p(e,t){if(f(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(f(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function m(e){var t=p(e,`string`);return f(t)==`symbol`?t:t+``}function h(e,t,n){return(t=m(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function g(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function _(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?g(Object(n),!0).forEach(function(t){h(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var v=(0,e.createContext)({});function y({defaults:e,children:t}){return(0,r.jsx)(v.Provider,{value:e,children:t})}function b(){return(0,e.useContext)(v)}function ee(e,t){if(Object.keys(e).length===0)return t;let n=_({},e);for(let e of Object.keys(t)){let r=t[e];r!==void 0&&(n[e]=r)}return(e.tools!==void 0||t.tools!==void 0)&&(n.tools=_(_({},e.tools),t.tools)),n}var x=`__blokPortalRegistry`,S=`__blokToolName`,C=()=>{let e={snapshot:new Map},t=new Set,n=new Map,r=n=>{e.snapshot=n,t.forEach(e=>e())};return{register(t,i){let a=new Map(e.snapshot),o=i.toolName===void 0?void 0:n.get(i.toolName);a.set(t,o===void 0?i:_(_({},i),{},{props:_(_({},i.props),{},{config:o})})),r(a)},unregister(t,n){let i=e.snapshot.get(t);if(i===void 0||n!==void 0&&i.hostEl!==n)return;let a=new Map(e.snapshot);a.delete(t),r(a)},setProps(t,n){let i=e.snapshot.get(t);if(i===void 0)return;let a=new Map(e.snapshot);a.set(t,_(_({},i),{},{props:_(_({},i.props),n)})),r(a)},setToolConfig(t,i){n.set(t,i);let a=[...e.snapshot].filter(([,e])=>e.toolName===t);if(a.length===0)return;let o=new Map(e.snapshot);for(let[e,t]of a)o.set(e,_(_({},t),{},{props:_(_({},t.props),{},{config:i})}));r(o)},subscribe(e){return t.add(e),()=>{t.delete(e)}},getSnapshot(){return e.snapshot}}},w=new WeakMap;function te(e,t){w.set(e,t)}function T(e){return w.get(e)}function E(e){w.delete(e)}var D=new WeakMap;function ne(e,t){D.set(e,t)}function O(e){return D.get(e)}function k(e){D.delete(e)}var A=e=>{if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},j=(e,t)=>t.reduce((e,t)=>{if(Array.isArray(e))return typeof t==`number`?e[t]:void 0;if(A(e))return e[t]},e),re=(e,t)=>{let n=(e,t)=>{if(typeof e==`function`)return typeof t==`function`?t:e;if(Array.isArray(e)){let r=Array.isArray(t)?t:[];return e.map((e,t)=>n(e,r[t]))}if(A(e)){let r=A(t)?t:{},i={};for(let[t,a]of Object.entries(e))i[t]=n(a,r[t]);return i}return e},r=n(t,e);return A(r)?r:{}},ie=(e,t)=>{if(!A(e))return e;let n={};for(let[r,i]of Object.entries(e)){if(!A(i)||!A(i.config)){n[r]=i;continue}let e=new WeakSet,a=(n,i)=>{if(typeof n==`function`){let e=n;return function(...n){let a=t(),o=A(a)?a[r]:void 0,s=j(A(o)?o.config:void 0,i);return Reflect.apply(typeof s==`function`?s:e,this,n)}}if(Array.isArray(n))return e.has(n)?n:(e.add(n),n.map((e,t)=>a(e,[...i,t])));if(A(n)){if(e.has(n))return n;e.add(n);let t={};for(let[e,r]of Object.entries(n))t[e]=a(r,[...i,e]);return t}return n};n[r]=_(_({},i),{},{config:a(i.config,[])})}return n},M=e=>{let t=typeof e==`function`?e:e==null?void 0:e.class;return typeof t==`function`&&t.__isBlokReactBlock===!0},N=e=>{let t=typeof e==`function`?e:e==null?void 0:e.class;return typeof t==`function`&&t.__isBlokReactInlineTool===!0},ae=(e,t)=>{if(typeof e!=`object`||!e)return e;let n={};for(let[i,a]of Object.entries(e)){var r;if(!M(a)&&!N(a)){n[i]=a;continue}let e=typeof a==`function`?{class:a}:_({},a);e.config=_(_({},(r=e.config)==null?{}:r),{},{[x]:t,[S]:i});let o=e.class.__buildPortalToolbox,s=typeof o==`function`&&e.toolbox===void 0?o(t,i):void 0;s!==void 0&&(e.toolbox=s),n[i]=e}return n};function P(r,i){var a,o;let s=ee((0,e.useContext)(v),r),[c,u]=(0,e.useState)(null),f=(0,e.useRef)(s);f.current=s;let p=(0,e.useRef)({editor:null,holder:null,destroyTimeout:null,isDestroyed:!1,isEditorReady:!1,depsToken:null}),m=(0,e.useMemo)(()=>({}),i==null?[]:i),h=(0,e.useRef)(s.data),g=(0,e.useRef)((0,n.createEmittedEchoWindow)()),y=(0,e.useRef)(null),b=(0,e.useRef)(s.data),x=(0,e.useRef)(Promise.resolve()),S=(0,e.useRef)(void 0),w=(0,e.useRef)(null),T=(0,e.useRef)(void 0),D=(0,e.useRef)(new Map),O=(0,e.useRef)(new Map),A=(0,e.useRef)(null),j=(0,e.useRef)({onChange:!1,onSave:!1,onEnter:!1,onSubmit:!1,onBeforeRender:!1,onAfterRender:!1});(0,e.useEffect)(()=>{var e;if(typeof window>`u`)return;let n=p.current;if(n.destroyTimeout!==null&&(clearTimeout(n.destroyTimeout),n.destroyTimeout=null),n.editor!==null&&!n.isDestroyed&&n.depsToken===m)return n.isEditorReady&&u(n.editor),()=>{F(n,u)};if(n.editor!==null&&!n.isDestroyed){d(n.editor),E(n.editor),k(n.editor);try{n.editor.destroy()}catch(e){}n.editor=null,n.holder=null,n.isDestroyed=!0,n.isEditorReady=!1,u(null)}let r=document.createElement(`div`);n.holder=r,n.isDestroyed=!1,n.isEditorReady=!1,n.depsToken=m;let i=f.current,a=C(),o=i.tools===void 0?void 0:ie(i.tools,()=>f.current.tools),s=o===void 0?void 0:ae(o,a);w.current=a,T.current=o,D.current=new Map,O.current=new Map(Object.entries((e=i.tools)==null?{}:e).map(([e,t])=>[e,typeof t==`object`&&t?t.toolbox:void 0]));let c={onChange:(...e)=>{var t,n;(t=(n=f.current).onChange)==null||t.call(n,...e)},onSave:(...e)=>{var t,n;h.current=e[0],g.current.record(e[0]),(t=(n=f.current).onSave)==null||t.call(n,...e)},onEnter:(...e)=>{var t,n;return(t=(n=f.current).onEnter)==null?void 0:t.call(n,...e)},onSubmit:(...e)=>{var t,n;(t=(n=f.current).onSubmit)==null||t.call(n,...e)},onBeforeRender:(...e)=>{var t,n,r;return(t=(n=(r=f.current).onBeforeRender)==null?void 0:n.call(r,...e))==null?e[0]:t},onAfterRender:(...e)=>{var t,n;(t=(n=f.current).onAfterRender)==null||t.call(n,...e)}};A.current=c;let v={onChange:i.onChange!==void 0,onSave:i.onSave!==void 0,onEnter:i.onEnter!==void 0,onSubmit:i.onSubmit!==void 0,onBeforeRender:i.onBeforeRender!==void 0,onAfterRender:i.onAfterRender!==void 0};j.current=v;let y=new t.Blok(_(_(_(_(_(_(_(_({},i),s===void 0?{}:{tools:s}),{},{holder:r,onReady:(...e)=>{var t,n;(t=(n=f.current).onReady)==null||t.call(n,...e)}},v.onChange?{onChange:c.onChange}:{}),v.onSave?{onSave:c.onSave}:{}),v.onEnter?{onEnter:c.onEnter}:{}),v.onSubmit?{onSubmit:c.onSubmit}:{}),v.onBeforeRender?{onBeforeRender:c.onBeforeRender}:{}),v.onAfterRender?{onAfterRender:c.onAfterRender}:{}));return n.editor=y,b.current=i.data,l(y,r),te(y,a),ne(y,{markRendered:e=>{g.current.clear(),h.current=e,S.current=void 0}}),y.isReady.then(()=>{n.editor===y&&!n.isDestroyed&&(n.isEditorReady=!0,u(y))}).catch(()=>{if(n.editor===y&&!n.isDestroyed){d(y),E(y),k(y);try{y.destroy()}catch(e){}n.editor=null,n.holder=null,n.isDestroyed=!0,n.isEditorReady=!1,u(null)}}),()=>{F(n,u)}},[m]),(0,e.useEffect)(()=>{let e=w.current,t=p.current;if(e===null||t.editor===null||t.isDestroyed)return;let r=f.current.tools;if(typeof r!=`object`||!r)return;let i=T.current;for(let[t,o]of Object.entries(r)){var a;if(!M(o))continue;let r=typeof o==`function`||(a=o.config)==null?{}:a,s=i==null?void 0:i[t],c=re(typeof s==`object`&&s?s.config:void 0,r),l=D.current.get(t);if(l!==void 0&&(0,n.deepEqual)(c,l))continue;let u=Object.freeze(c);D.current.set(t,u),e.setToolConfig(t,u)}}),(0,e.useEffect)(()=>{let e=p.current;if(e.editor===null||e.isDestroyed||!e.isEditorReady)return;let t=f.current.tools;if(!(typeof t!=`object`||!t))for(let[i,a]of Object.entries(t)){var r;if(!O.current.has(i))continue;let t=typeof a==`object`&&a?a.toolbox:void 0;(0,n.deepEqual)(t,O.current.get(i))||(O.current.set(i,t),(r=e.editor.tools)==null||r.update(i,{toolbox:t}))}}),(0,e.useEffect)(()=>{let e=p.current,t=A.current;if(e.editor===null||e.isDestroyed||!e.isEditorReady||t===null)return;let n=f.current,r=j.current,i={},a={value:!1},o=(e,i)=>{let o=n[e]!==void 0;o!==r[e]&&(r[e]=o,a.value=!0,i(o?t[e]:void 0))};o(`onChange`,e=>{i.onChange=e}),o(`onSave`,e=>{i.onSave=e}),o(`onEnter`,e=>{i.onEnter=e}),o(`onSubmit`,e=>{i.onSubmit=e}),o(`onBeforeRender`,e=>{i.onBeforeRender=e}),o(`onAfterRender`,e=>{i.onAfterRender=e}),a.value&&e.editor.handlers.set(i)});let N=typeof s.readOnly==`object`&&s.readOnly!==null,{enabled:P,hideControls:I}=(0,n.normalizeReadOnlyConfig)(s.readOnly);(0,e.useEffect)(()=>{c!==null&&(N?c.readOnly.set(P,{hideControls:I}):c.readOnly.set(P))},[c,P,I,N]);let{hideToolbar:L}=s;(0,e.useEffect)(()=>{c===null||L===void 0||c.toolbar.setHidden(L)},[c,L]);let{inlineToolbar:R}=s;(0,e.useEffect)(()=>{c===null||R===void 0||c.tools.setInlineToolbar(R)},[c,R===void 0?void 0:JSON.stringify(R)]);let{autofocus:z}=s;(0,e.useEffect)(()=>{c===null||!z||c.focus()},[c,z]);let{theme:B}=s;(0,e.useEffect)(()=>{c===null||B===void 0||c.theme.set(B)},[c,B]);let{width:V}=s;(0,e.useEffect)(()=>{c===null||V===void 0||c.width.set(V)},[c,V]);let H=(a=s.style)==null?void 0:a.tokens,U=(0,e.useRef)((o=s.style)==null?void 0:o.tokens);(0,e.useEffect)(()=>{c===null||H===void 0||(0,n.deepEqual)(H,U.current)||(U.current=H,c.tokens.set(H))},[c,H]);let{i18n:W}=s,G=(0,e.useRef)(s.i18n);(0,e.useEffect)(()=>{if(c===null||W===void 0||(0,n.deepEqual)(W,G.current))return;G.current=W;let{locale:e,messages:t,direction:r}=W;c.i18n.update(_(_(_({},e===void 0?{}:{locale:e}),t===void 0?{}:{messages:t}),r===void 0?{}:{direction:r}))},[c,W]);let{placeholder:K}=s;(0,e.useEffect)(()=>{c===null||K===void 0||c.placeholder.set(K)},[c,K]);let{data:q}=s;return(0,e.useEffect)(()=>{if(c===null||q===void 0)return;let e=p.current;if(e.editor!==c||e.isDestroyed)return;if(y.current!==c&&(y.current=c,S.current=void 0,g.current.clear(),(0,n.deepEqual)(q,b.current))){h.current=q;return}let t=h.current,r=S.current;t!==void 0&&(0,n.equalsOutputData)(q,t)||r!==void 0&&(0,n.equalsOutputData)(q,r)||g.current.matches(q)||(g.current.clear(),S.current=q,x.current=x.current.catch(()=>void 0).then(()=>c.render((0,n.toRenderableData)(q))).then(()=>{h.current=q},()=>{}).then(()=>{S.current===q&&(S.current=void 0)}))},[c,q]),c}function F(e,t){e.destroyTimeout=setTimeout(()=>{if(e.editor!==null){d(e.editor),E(e.editor),k(e.editor);try{e.editor.destroy()}catch(e){}e.editor=null,e.holder=null,e.isDestroyed=!0,e.isEditorReady=!1,e.destroyTimeout=null,t(null)}},0)}var I=class extends e.Component{constructor(...e){super(...e),this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(){}render(){return this.state.failed?null:this.props.children}};function L({registry:t}){let n=(0,e.useSyncExternalStore)(t.subscribe,t.getSnapshot,t.getSnapshot);return(0,r.jsx)(r.Fragment,{children:Array.from(n.entries()).map(([e,t])=>{let n=t.component;return(0,a.createPortal)((0,r.jsx)(I,{children:(0,r.jsx)(n,_({},t.props))}),t.hostEl,e)})})}var R=(0,e.createContext)(null);function z(){return(0,e.useContext)(R)}function B(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.includes(r))continue;n[r]=e[r]}return n}function V(e,t){if(e==null)return{};var n,r,i=B(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.includes(n)||{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var H=[`editor`];function U(e){var t,n;if(typeof window>`u`)return;let r=window.location.hash.slice(1);r!==``&&((t=(n=e.blocks).scrollToBlock)==null||t.call(n,W(r)))}function W(e){try{return decodeURIComponent(e)}catch(t){return e}}var G=(0,e.forwardRef)(function(t,n){let{editor:i}=t,a=V(t,H),o=(0,e.useRef)(null),s=e=>{if(o.current=e,typeof n==`function`)n(e);else if(n!=null){let t=n;t.current=e}};(0,e.useEffect)(()=>{if(i===null||o.current===null)return;let e=u(i);if(e!==void 0)return o.current.appendChild(e),U(i),()=>{e.remove()}},[i]);let c=i===null?void 0:T(i);return(0,r.jsx)(`div`,_(_({ref:s},a),{},{children:c===void 0?null:(0,r.jsx)(R.Provider,{value:i,children:(0,r.jsx)(L,{registry:c})})}))}),K=`autofocus.defaultBlock.dataModel.placeholder.sanitizer.hideToolbar.maxHistoryLength.historyDebounceTime.newGroupDelay.globalUndoRedo.tools.data.minHeight.logLevel.readOnly.i18n.link.linkPaste.onBeforePaste.onReady.onChange.onSave.onError.onEnter.onSubmit.onBeforeRender.onAfterRender.inlineToolbar.tunes.style.theme.onThemeChange.scrollToBlock.user.resolveUser.notifierPosition.notifier.width.migrations.uploader.captureClicksBelowEditor`.split(`.`),q=[`deps`,`onReady`,`locale`,`onBlocksRendered`,`onBlockRendered`],oe=new Set(K),se=(0,e.forwardRef)(function(t,n){let{deps:i,onReady:a,locale:o,onBlocksRendered:s,onBlockRendered:c}=t,l=V(t,q),u={},d={};for(let e of Object.keys(l)){let t=l[e];oe.has(e)?u[e]=t:d[e]=t}if(o!==void 0){let e=u.i18n;u.i18n=_(_({},e),{},{locale:o})}let f=P(u,i);(0,e.useImperativeHandle)(n,()=>f,[f]);let p=(0,e.useRef)(a);p.current=a;let m=(0,e.useRef)(null);(0,e.useEffect)(()=>{if(f!==null&&m.current!==f){var e;m.current=f,(e=p.current)==null||e.call(p,f)}},[f]);let h=(0,e.useRef)(s);h.current=s;let g=(0,e.useRef)(c);g.current=c;let v=!!s,y=!!c;return(0,e.useEffect)(()=>{if(f===null)return;let e=[];if(v){let t=e=>{var t;return(t=h.current)==null?void 0:t.call(h,e)};f.on(`blocks:rendered`,t),e.push([`blocks:rendered`,t])}if(y){let t=e=>{var t;return(t=g.current)==null?void 0:t.call(g,e)};f.on(`block:rendered`,t),e.push([`block:rendered`,t])}return()=>{for(let[t,n]of e)f.off(t,n)}},[f,v,y]),(0,r.jsx)(G,_({editor:f},d))});function ce(){let t=(0,e.useRef)(null);return(0,e.useMemo)(()=>({ref:e=>{t.current=e},get current(){return t.current},get isReady(){return t.current!==null},focus:e=>{var n,r;return(n=(r=t.current)==null?void 0:r.focus(e))!=null&&n},clear:()=>{let e=t.current;return e===null?Promise.resolve():e.clear().then(()=>{var t;(t=O(e))==null||t.markRendered(n.EMPTY_OUTPUT_DATA)})},save:()=>t.current===null?Promise.resolve(null):t.current.save(),render:e=>{let n=t.current;return n===null?Promise.resolve():n.render(e).then(()=>{var t;(t=O(n))==null||t.markRendered(e)})},setReadOnly:e=>{let n=t.current;return n===null?Promise.resolve(!1):n.readOnly.set(e==null?!n.readOnly.isEnabled:e)}}),[])}var J=`block changed`;function le(t,r={}){var i;let a=(i=r.within)==null?null:i,o=(0,e.useRef)(0),s=(0,e.useRef)(t);s.current!==t&&(s.current=t,o.current=0);let c=(0,e.useCallback)(e=>{if(t===null)return()=>void 0;let r=r=>{a!==null&&!(0,n.changeTouchesSubtree)(t,r,a)||(o.current+=1,e())};return t.on(J,r),()=>t.off(J,r)},[t,a]),l=(0,e.useCallback)(()=>o.current,[]);return(0,e.useSyncExternalStore)(c,l,l),(0,e.useMemo)(()=>t===null?n.EMPTY_API:(0,n.createBlocksApiForEditor)(t),[t])}function ue(n={}){let{within:r,settleOn:i}=n,[a,o]=(0,e.useState)(!1);return(0,e.useEffect)(()=>{let e=()=>{var e;let n=r instanceof Element?r:(e=r==null?void 0:r.current)==null?null:e;o(r!==void 0&&n===null?!1:t.Blok.readyState({within:n,settleOn:i}).ready)};return e(),t.Blok.subscribeReady(e)},[r,i]),a}var de=new Set([`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`link`,`meta`,`param`,`source`,`track`,`wbr`]),fe=new Set([`disabled`,`open`,`controls`,`autoplay`,`loop`,`muted`,`required`,`multiple`,`playsinline`,`reversed`,`hidden`,`default`,`novalidate`,`allowfullscreen`,`itemscope`]),Y={class:`className`,for:`htmlFor`,colspan:`colSpan`,rowspan:`rowSpan`,tabindex:`tabIndex`,readonly:`readOnly`,srcset:`srcSet`,srclang:`srcLang`,datetime:`dateTime`,autoplay:`autoPlay`,playsinline:`playsInline`,novalidate:`noValidate`,allowfullscreen:`allowFullScreen`,crossorigin:`crossOrigin`,referrerpolicy:`referrerPolicy`,contenteditable:`contentEditable`,spellcheck:`spellCheck`,maxlength:`maxLength`,minlength:`minLength`,usemap:`useMap`,itemscope:`itemScope`},pe=e=>{let t={};for(let n of e.split(`;`)){let e=n.indexOf(`:`);if(e===-1)continue;let r=n.slice(0,e).trim(),i=n.slice(e+1).trim();if(r===``||i===``)continue;let a=r.startsWith(`--`)?r:r.toLowerCase().replace(/-([a-z])/g,(e,t)=>t.toUpperCase());t[a]=i}return t},me=(e,t)=>{let n={key:t};for(let[t,a]of Object.entries(e)){var r;if(t===`style`){n.style=pe(a);continue}if(t===`checked`){n.defaultChecked=!0;continue}if(t===`value`){n.defaultValue=a;continue}if(fe.has(t)){var i;n[(i=Y[t])==null?t:i]=!0;continue}n[(r=Y[t])==null?t:r]=a}return n},X=t=>t.map((t,n)=>{if(`text`in t)return t.text;let r=me(t.attrs,n);return de.has(t.tag)||t.children.length===0?(0,e.createElement)(t.tag,r):(0,e.createElement)(t.tag,r,...X(t.children))}),Z=(t,n)=>{let r=n==null?void 0:n.schema,i=n==null?void 0:n.renderers,a=n==null?void 0:n.onUnknownBlock,s=n==null?void 0:n.toolAttributes,c=n==null?void 0:n.blockIds,l=n==null?void 0:n.transformUrl,u=n==null?void 0:n.inlineRenderers,d=n==null?void 0:n.classes;return(0,e.useMemo)(()=>(0,e.createElement)(e.Fragment,null,...X((0,o.blocksToViewNodes)(t,{schema:r,renderers:i,onUnknownBlock:a,toolAttributes:s,blockIds:c,transformUrl:l,inlineRenderers:u,classes:d}))),[t,r,i,a,s,c,l,u,d])},he=[`data`,`schema`,`renderers`,`onUnknownBlock`,`toolAttributes`,`blockIds`,`transformUrl`,`inlineRenderers`,`classes`],Q=e=>{let{data:t,schema:n,renderers:i,onUnknownBlock:a,toolAttributes:o,blockIds:s,transformUrl:c,inlineRenderers:l,classes:u}=e,d=V(e,he),f=Z(t,{schema:n,renderers:i,onUnknownBlock:a,toolAttributes:o,blockIds:s,transformUrl:c,inlineRenderers:l,classes:u==null||u});return(0,r.jsx)(`div`,_(_({"data-blok-interface":`view`},d),{},{children:f}))},ge=[`icon`,`title`],_e=[`commit`,`readOnly`],ve=[x,S],ye=(e,t,r)=>{var i;e==null||(i=e.events)==null||i.emit(n.BlockChildrenMounted,{blockId:t,childIds:r.map(e=>e.id)})},be=new Set([void 0,`user`,`api`,`convert`]),xe=[`toolbox`,`isReadOnlySupported`,`__isBlokReactBlock`,`__buildPortalToolbox`];function Se(t){var i,o;let c=e=>{if(typeof document>`u`)return null;let t=document.createElement(`div`),n=(0,s.createRoot)(t);(0,a.flushSync)(()=>{n.render(e)});let r=t.innerHTML;return n.unmount(),r===``?null:r},l=t=>{let{icon:n,title:r}=t,i=_({},V(t,ge));if(typeof r==`string`&&(i.title=r),!(0,e.isValidElement)(n))return n!==void 0&&(i.icon=n),{entry:i,deferred:!1};let a=c(n);return a===null?(i.icon=n,{entry:i,deferred:!0}):(i.icon=a,{entry:i,deferred:!1})},u=()=>{if(t.toolbox===void 0)return{value:void 0,complete:!0};let e=(Array.isArray(t.toolbox)?t.toolbox:[t.toolbox]).map(e=>l(e)),n=e.every(e=>!e.deferred),r=e.map(e=>e.entry);return{value:Array.isArray(t.toolbox)?r:r[0],complete:n}},d=(n,i)=>{if(t.toolbox===void 0)return;let a=Array.isArray(t.toolbox)?t.toolbox:[t.toolbox];if(!a.some(t=>(0,e.isValidElement)(t.title)))return;let o=a.map((t,a)=>{let{entry:o,deferred:s}=l(t);if(s&&delete o.icon,!(0,e.isValidElement)(t.title))return o;let c=document.createElement(`span`);c.setAttribute(`data-blok-mutation-free`,`true`);let u=t.title,d=()=>(0,r.jsx)(r.Fragment,{children:u});return d.displayName=`BlokToolboxTitle(${i})`,n.register(`__blok-toolbox-title__:${i}:${a}`,{hostEl:c,component:d,props:{},toolName:i}),_(_({},o),{},{titleEl:c})});return Array.isArray(t.toolbox)?o:o[0]},f={resolved:!1,value:void 0},p=()=>{if(f.resolved)return f.value;let{value:e,complete:t}=u();return t&&(f.value=e,f.resolved=!0),e},m=t.viewComponent===void 0?t.component:e=>{let n=t.viewComponent;if(e.readOnly&&n!==void 0){let{commit:t,readOnly:i}=e;return(0,r.jsx)(n,_({},V(e,_e)))}let i=t.component;return(0,r.jsx)(i,_({},e))},h=(i=class{static get toolbox(){return p()}static __buildPortalToolbox(e,t){return d(e,t)}static get isReadOnlySupported(){return!0}constructor(i){var a,o,s;this.mountSignalled=!1,this.hostEl=null,this.pendingDispatch=!1,this.anchorEl=null,this.toolbarAnchorRef=e=>{this.anchorEl=e},this.commit=e=>{var r;let i=(0,n.fillDefaults)(t.propSchema,_(_({},this.mirror),e));(0,n.deepEqual)(i,this.mirror)||(this.mirror=i,this.lastRendered=i,(r=this.registry)==null||r.setProps(this.blockApi.id,{data:i}),this.flushDispatch())},this.blockApi=i.block;let c=(a=i.config)==null?{}:a;this.registry=c[x];let l=c[S];this.toolName=typeof l==`string`?l:void 0;let u={};for(let[e,t]of Object.entries(c))ve.includes(e)||(u[e]=t);this.toolConfig=Object.freeze(u),this.api=i.api;let d=i.api;this.pointerDrag=()=>{var e;return(d==null||(e=d.blocks)==null?void 0:e.isPointerDragActive)===!0},this.mirror=(0,n.fillDefaults)(t.propSchema,(o=i.data)==null?{}:o),this.lastRendered=this.mirror,this.readOnly=i.readOnly,this.origin=(s=i.origin)==null?`api`:s;let f=this.blockApi,p=this.api;this.childrenComponent=function({childAttributes:t,childContentAttributes:i}){let a=(0,e.useRef)(null),o=(0,e.useRef)((0,n.createChildDecorationLedger)());return(0,e.useEffect)(()=>{if(a.current===null)return;let e=f.getChildren();(0,n.mountChildBlocks)(a.current,e),(0,n.applyChildDecoration)(o.current,e,{childAttributes:t,childContentAttributes:i}),ye(p,f.id,e)}),(0,r.jsx)(`div`,{ref:a,[n.DATA_ATTR.nestedBlocks]:``})},this.entryComponent=this.buildEntryComponent()}buildEntryComponent(){let n=t.onMounted,i=t.onCreated;if(n===void 0&&i===void 0)return m;let a=m,o=()=>{if(this.mountSignalled)return;this.mountSignalled=!0;let e={origin:this.origin,api:this.api};n==null||n(this.blockApi,e),be.has(this.origin)&&(i==null||i(this.blockApi,e))},s=t=>((0,e.useEffect)(o,[]),(0,r.jsx)(a,_({},t)));return s.displayName=`BlokBlockMount(${t.type})`,s}render(){var e;let t=document.createElement(`div`);return t.setAttribute(`data-blok-mutation-free`,`true`),this.hostEl=t,(e=this.registry)==null||e.register(this.blockApi.id,{hostEl:t,component:this.entryComponent,props:this.buildProps(),toolName:this.toolName}),t}rendered(){var e;(e=t.onRendered)==null||e.call(t,this.blockApi)}save(){return this.mirror}async setData(e){var r=this;let i=(0,n.fillDefaults)(t.propSchema,e==null?{}:e);return(0,n.deepEqual)(i,r.lastRendered)?!0:(r.mirror=i,r.lastRendered=i,r.pushProps({data:i}),!0)}setReadOnly(e){this.readOnly=e,this.pushProps({readOnly:e})}getToolbarAnchorElement(){var e;let n=this.anchorEl;if(n!==null&&n.isConnected)return n;let r=this.hostEl;if(!(r===null||t.getToolbarAnchorElement===void 0))return(e=t.getToolbarAnchorElement(r,this.blockApi))==null?void 0:e}moved(){var e;(e=t.onMoved)==null||e.call(t,this.blockApi)}removed(){var e,n,r;(e=this.registry)==null||e.unregister(this.blockApi.id,(n=this.hostEl)==null?void 0:n),(r=t.onRemoved)==null||r.call(t,this.blockApi)}destroy(){var e,t;(e=this.registry)==null||e.unregister(this.blockApi.id,(t=this.hostEl)==null?void 0:t)}buildProps(){return{data:this.mirror,commit:this.commit,block:this.blockApi,api:this.api,readOnly:this.readOnly,config:this.toolConfig,BlockChildren:this.childrenComponent,toolbarAnchorRef:this.toolbarAnchorRef}}pushProps(e){let t=this.registry;t!==void 0&&(0,a.flushSync)(()=>{t.setProps(this.blockApi.id,e)})}flushDispatch(){if(!this.pointerDrag()){this.pendingDispatch=!1,this.blockApi.dispatchChange();return}if(this.pendingDispatch)return;this.pendingDispatch=!0;let e=()=>{if(this.pointerDrag()){requestAnimationFrame(e);return}this.pendingDispatch=!1,this.blockApi.dispatchChange()};requestAnimationFrame(e)}},i.__isBlokReactBlock=!0,i);for(let[e,n]of Object.entries((o=t.statics)==null?{}:o))xe.includes(e)||Object.defineProperty(h,e,{value:n,writable:!0,enumerable:!0,configurable:!0});return h}var Ce=[x,S],we=e=>`__blok-inline-tool__:${e}:${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,$=(0,e.createContext)(null);function Te(){let t=(0,e.useContext)($);if(t===null)throw Error(`useInlineTool() must be called from a component rendered by createReactInlineTool`);return t}function Ee(t){var i;return i=class{static get type(){return t.type}static get title(){return t.title}static get titleKey(){var e;return(e=t.titleKey)==null?t.type:e}static get shortcut(){return t.shortcut}static get mark(){return t.mark}static get sanitize(){return t.sanitize===void 0?t.mark===void 0?void 0:(0,n.markSanitizerConfig)(t.mark):t.sanitize}static get isReadOnlySupported(){var e;return(e=t.isReadOnlySupported)!=null&&e}constructor(e){var n;this.active=!1,this.registered=!1;let r=(n=e==null?void 0:e.config)==null?{}:n;this.api=e==null?void 0:e.api,this.registry=r[x];let i=r[S];this.toolName=typeof i==`string`?i:t.type,this.portalKey=we(this.toolName);let a={};for(let[e,t]of Object.entries(r))Ce.includes(e)||(a[e]=t);this.toolConfig=Object.freeze(a),this.portalComponent=this.createPortalComponent()}render(){let e=document.createElement(`div`);return e.setAttribute(`data-blok-mutation-free`,`true`),this.registry!==void 0&&(this.registry.register(this.portalKey,{hostEl:e,component:this.portalComponent,props:{active:this.active,config:this.toolConfig},toolName:this.toolName}),this.registered=!0),{name:this.toolName,title:t.title,icon:e,onActivate:()=>{this.activate()},isActive:()=>this.refreshActiveState()}}destroy(){var e;this.registered&&(this.registered=!1,(e=this.registry)==null||e.unregister(this.portalKey))}activate(){var e;if(typeof t.surround==`function`){let e=window.getSelection();if(!e||e.rangeCount===0)return;t.surround(e.getRangeAt(0),this.api);return}t.mark!==void 0&&((e=this.api)==null?void 0:e.marks)!==void 0&&this.api.marks.toggle(t.mark)}refreshActiveState(){let e=this.computeActiveState();if(e!==this.active&&(this.active=e,this.registered)){var t;(t=this.registry)==null||t.setProps(this.portalKey,{active:e})}return e}computeActiveState(){var e;return typeof t.checkState==`function`?!!t.checkState(window.getSelection(),this.api):t.mark!==void 0&&((e=this.api)==null?void 0:e.marks)!==void 0&&this.api.marks.has(t.mark)}createPortalComponent(){let n=this.api,i=t.mark,a=t.component,o=i!==void 0&&(n==null?void 0:n.marks)!==void 0?{has:()=>n.marks.has(i),toggle:e=>n.marks.toggle(i,e),apply:e=>n.marks.apply(i,e),remove:()=>n.marks.remove(i),read:()=>n.marks.read(i)}:null,s=t=>{let i=(0,e.useMemo)(()=>({active:t.active,config:t.config,api:n,mark:o}),[t.active,t.config]);return(0,r.jsx)($.Provider,{value:i,children:(0,r.jsx)(a,{active:t.active,config:t.config})})};return s.displayName=`BlokInlineTool(${this.toolName})`,s}},i.__isBlokReactInlineTool=!0,i.isInline=!0,i}exports.BLOK_PORTAL_REGISTRY_CONFIG_KEY=x,exports.BLOK_TOOL_NAME_CONFIG_KEY=S,exports.BlockPortalHost=L,exports.BlokContent=G,exports.BlokEditor=se,exports.BlokProvider=y,exports.BlokView=Q,exports.createBlockPortalRegistry=C,exports.createReactBlock=Se,exports.createReactInlineTool=Ee,Object.defineProperty(exports,"getDirection",{enumerable:!0,get:function(){return i.getDirection}}),Object.defineProperty(exports,"normalizeLocale",{enumerable:!0,get:function(){return i.normalizeLocale}}),exports.useBlocks=le,exports.useBlok=P,exports.useBlokDefaults=b,exports.useBlokHandle=ce,exports.useBlokInstance=z,exports.useBlokReady=ue,exports.useBlokView=Z,exports.useInlineTool=Te;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("@bloklabs/core"),n=require("@bloklabs/core/adapters"),r=require("react/jsx-runtime"),i=require("@bloklabs/core/locales"),a=require("react-dom"),o=require("@bloklabs/core/view"),s=require("react-dom/client");var c=new WeakMap;function l(e,t){c.set(e,t)}function u(e){return c.get(e)}function d(e){c.delete(e)}function f(e){"@babel/helpers - typeof";return f=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},f(e)}function p(e,t){if(f(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(f(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function m(e){var t=p(e,`string`);return f(t)==`symbol`?t:t+``}function h(e,t,n){return(t=m(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function g(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function _(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?g(Object(n),!0).forEach(function(t){h(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var v=(0,e.createContext)({});function y({defaults:e,children:t}){return(0,r.jsx)(v.Provider,{value:e,children:t})}function b(){return(0,e.useContext)(v)}function ee(e,t){if(Object.keys(e).length===0)return t;let n=_({},e);for(let e of Object.keys(t)){let r=t[e];r!==void 0&&(n[e]=r)}return(e.tools!==void 0||t.tools!==void 0)&&(n.tools=_(_({},e.tools),t.tools)),n}var x=`__blokPortalRegistry`,S=`__blokToolName`,C=()=>{let e={snapshot:new Map},t=new Set,n=new Map,r=n=>{e.snapshot=n,t.forEach(e=>e())};return{register(t,i){let a=new Map(e.snapshot),o=i.toolName===void 0?void 0:n.get(i.toolName);a.set(t,o===void 0?i:_(_({},i),{},{props:_(_({},i.props),{},{config:o})})),r(a)},unregister(t,n){let i=e.snapshot.get(t);if(i===void 0||n!==void 0&&i.hostEl!==n)return;let a=new Map(e.snapshot);a.delete(t),r(a)},setProps(t,n){let i=e.snapshot.get(t);if(i===void 0)return;let a=new Map(e.snapshot);a.set(t,_(_({},i),{},{props:_(_({},i.props),n)})),r(a)},setToolConfig(t,i){n.set(t,i);let a=[...e.snapshot].filter(([,e])=>e.toolName===t);if(a.length===0)return;let o=new Map(e.snapshot);for(let[e,t]of a)o.set(e,_(_({},t),{},{props:_(_({},t.props),{},{config:i})}));r(o)},subscribe(e){return t.add(e),()=>{t.delete(e)}},getSnapshot(){return e.snapshot}}},w=new WeakMap;function te(e,t){w.set(e,t)}function T(e){return w.get(e)}function E(e){w.delete(e)}var D=new WeakMap;function ne(e,t){D.set(e,t)}function O(e){return D.get(e)}function k(e){D.delete(e)}var A=e=>{if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},j=(e,t)=>t.reduce((e,t)=>{if(Array.isArray(e))return typeof t==`number`?e[t]:void 0;if(A(e))return e[t]},e),re=(e,t)=>{let n=(e,t)=>{if(typeof e==`function`)return typeof t==`function`?t:e;if(Array.isArray(e)){let r=Array.isArray(t)?t:[];return e.map((e,t)=>n(e,r[t]))}if(A(e)){let r=A(t)?t:{},i={};for(let[t,a]of Object.entries(e))i[t]=n(a,r[t]);return i}return e},r=n(t,e);return A(r)?r:{}},ie=(e,t)=>{if(!A(e))return e;let n={};for(let[r,i]of Object.entries(e)){if(!A(i)||!A(i.config)){n[r]=i;continue}let e=new WeakSet,a=(n,i)=>{if(typeof n==`function`){let e=n;return function(...n){let a=t(),o=A(a)?a[r]:void 0,s=j(A(o)?o.config:void 0,i);return Reflect.apply(typeof s==`function`?s:e,this,n)}}if(Array.isArray(n))return e.has(n)?n:(e.add(n),n.map((e,t)=>a(e,[...i,t])));if(A(n)){if(e.has(n))return n;e.add(n);let t={};for(let[e,r]of Object.entries(n))t[e]=a(r,[...i,e]);return t}return n};n[r]=_(_({},i),{},{config:a(i.config,[])})}return n},M=e=>{let t=typeof e==`function`?e:e==null?void 0:e.class;return typeof t==`function`&&t.__isBlokReactBlock===!0},N=e=>{let t=typeof e==`function`?e:e==null?void 0:e.class;return typeof t==`function`&&t.__isBlokReactInlineTool===!0},ae=(e,t)=>{if(typeof e!=`object`||!e)return e;let n={};for(let[i,a]of Object.entries(e)){var r;if(!M(a)&&!N(a)){n[i]=a;continue}let e=typeof a==`function`?{class:a}:_({},a);e.config=_(_({},(r=e.config)==null?{}:r),{},{[x]:t,[S]:i});let o=e.class.__buildPortalToolbox,s=typeof o==`function`&&e.toolbox===void 0?o(t,i):void 0;s!==void 0&&(e.toolbox=s),n[i]=e}return n};function P(r,i){var a,o;let s=ee((0,e.useContext)(v),r),[c,u]=(0,e.useState)(null),f=(0,e.useRef)(s);f.current=s;let p=(0,e.useRef)({editor:null,holder:null,destroyTimeout:null,isDestroyed:!1,isEditorReady:!1,depsToken:null}),m=(0,e.useMemo)(()=>({}),i==null?[]:i),h=(0,e.useRef)(s.data),g=(0,e.useRef)((0,n.createEmittedEchoWindow)()),y=(0,e.useRef)(null),b=(0,e.useRef)(s.data),x=(0,e.useRef)(Promise.resolve()),S=(0,e.useRef)(void 0),w=(0,e.useRef)(null),T=(0,e.useRef)(void 0),D=(0,e.useRef)(new Map),O=(0,e.useRef)(new Map),A=(0,e.useRef)(null),j=(0,e.useRef)({onChange:!1,onSave:!1,onEnter:!1,onSubmit:!1,onBeforeRender:!1,onAfterRender:!1});(0,e.useEffect)(()=>{var e;if(typeof window>`u`)return;let n=p.current;if(n.destroyTimeout!==null&&(clearTimeout(n.destroyTimeout),n.destroyTimeout=null),n.editor!==null&&!n.isDestroyed&&n.depsToken===m)return n.isEditorReady&&u(n.editor),()=>{F(n,u)};if(n.editor!==null&&!n.isDestroyed){d(n.editor),E(n.editor),k(n.editor);try{n.editor.destroy()}catch(e){}n.editor=null,n.holder=null,n.isDestroyed=!0,n.isEditorReady=!1,u(null)}let r=document.createElement(`div`);n.holder=r,n.isDestroyed=!1,n.isEditorReady=!1,n.depsToken=m;let i=f.current,a=C(),o=i.tools===void 0?void 0:ie(i.tools,()=>f.current.tools),s=o===void 0?void 0:ae(o,a);w.current=a,T.current=o,D.current=new Map,O.current=new Map(Object.entries((e=i.tools)==null?{}:e).map(([e,t])=>[e,typeof t==`object`&&t?t.toolbox:void 0]));let c={onChange:(...e)=>{var t,n;(t=(n=f.current).onChange)==null||t.call(n,...e)},onSave:(...e)=>{var t,n;h.current=e[0],g.current.record(e[0]),(t=(n=f.current).onSave)==null||t.call(n,...e)},onEnter:(...e)=>{var t,n;return(t=(n=f.current).onEnter)==null?void 0:t.call(n,...e)},onSubmit:(...e)=>{var t,n;(t=(n=f.current).onSubmit)==null||t.call(n,...e)},onBeforeRender:(...e)=>{var t,n,r;return(t=(n=(r=f.current).onBeforeRender)==null?void 0:n.call(r,...e))==null?e[0]:t},onAfterRender:(...e)=>{var t,n;(t=(n=f.current).onAfterRender)==null||t.call(n,...e)}};A.current=c;let v={onChange:i.onChange!==void 0,onSave:i.onSave!==void 0,onEnter:i.onEnter!==void 0,onSubmit:i.onSubmit!==void 0,onBeforeRender:i.onBeforeRender!==void 0,onAfterRender:i.onAfterRender!==void 0};j.current=v;let y=new t.Blok(_(_(_(_(_(_(_(_({},i),s===void 0?{}:{tools:s}),{},{holder:r,onReady:(...e)=>{var t,n;(t=(n=f.current).onReady)==null||t.call(n,...e)}},v.onChange?{onChange:c.onChange}:{}),v.onSave?{onSave:c.onSave}:{}),v.onEnter?{onEnter:c.onEnter}:{}),v.onSubmit?{onSubmit:c.onSubmit}:{}),v.onBeforeRender?{onBeforeRender:c.onBeforeRender}:{}),v.onAfterRender?{onAfterRender:c.onAfterRender}:{}));return n.editor=y,b.current=i.data,l(y,r),te(y,a),ne(y,{markRendered:e=>{g.current.clear(),h.current=e,S.current=void 0}}),y.isReady.then(()=>{n.editor===y&&!n.isDestroyed&&(n.isEditorReady=!0,u(y))}).catch(()=>{if(n.editor===y&&!n.isDestroyed){d(y),E(y),k(y);try{y.destroy()}catch(e){}n.editor=null,n.holder=null,n.isDestroyed=!0,n.isEditorReady=!1,u(null)}}),()=>{F(n,u)}},[m]),(0,e.useEffect)(()=>{let e=w.current,t=p.current;if(e===null||t.editor===null||t.isDestroyed)return;let r=f.current.tools;if(typeof r!=`object`||!r)return;let i=T.current;for(let[t,o]of Object.entries(r)){var a;if(!M(o))continue;let r=typeof o==`function`||(a=o.config)==null?{}:a,s=i==null?void 0:i[t],c=re(typeof s==`object`&&s?s.config:void 0,r),l=D.current.get(t);if(l!==void 0&&(0,n.deepEqual)(c,l))continue;let u=Object.freeze(c);D.current.set(t,u),e.setToolConfig(t,u)}}),(0,e.useEffect)(()=>{let e=p.current;if(e.editor===null||e.isDestroyed||!e.isEditorReady)return;let t=f.current.tools;if(!(typeof t!=`object`||!t))for(let[i,a]of Object.entries(t)){var r;if(!O.current.has(i))continue;let t=typeof a==`object`&&a?a.toolbox:void 0;(0,n.deepEqual)(t,O.current.get(i))||(O.current.set(i,t),(r=e.editor.tools)==null||r.update(i,{toolbox:t}))}}),(0,e.useEffect)(()=>{let e=p.current,t=A.current;if(e.editor===null||e.isDestroyed||!e.isEditorReady||t===null)return;let n=f.current,r=j.current,i={},a={value:!1},o=(e,i)=>{let o=n[e]!==void 0;o!==r[e]&&(r[e]=o,a.value=!0,i(o?t[e]:void 0))};o(`onChange`,e=>{i.onChange=e}),o(`onSave`,e=>{i.onSave=e}),o(`onEnter`,e=>{i.onEnter=e}),o(`onSubmit`,e=>{i.onSubmit=e}),o(`onBeforeRender`,e=>{i.onBeforeRender=e}),o(`onAfterRender`,e=>{i.onAfterRender=e}),a.value&&e.editor.handlers.set(i)});let N=typeof s.readOnly==`object`&&s.readOnly!==null,{enabled:P,hideControls:I}=(0,n.normalizeReadOnlyConfig)(s.readOnly);(0,e.useEffect)(()=>{c!==null&&(N?c.readOnly.set(P,{hideControls:I}):c.readOnly.set(P))},[c,P,I,N]);let{hideToolbar:L}=s;(0,e.useEffect)(()=>{c===null||L===void 0||c.toolbar.setHidden(L)},[c,L]);let{toolbarPosition:R}=s;(0,e.useEffect)(()=>{c===null||R===void 0||c.toolbar.setPosition(R)},[c,R]);let{inlineToolbar:z}=s;(0,e.useEffect)(()=>{c===null||z===void 0||c.tools.setInlineToolbar(z)},[c,z===void 0?void 0:JSON.stringify(z)]);let{autofocus:B}=s;(0,e.useEffect)(()=>{c===null||!B||c.focus()},[c,B]);let{theme:V}=s;(0,e.useEffect)(()=>{c===null||V===void 0||c.theme.set(V)},[c,V]);let{width:H}=s;(0,e.useEffect)(()=>{c===null||H===void 0||c.width.set(H)},[c,H]);let U=(a=s.style)==null?void 0:a.tokens,W=(0,e.useRef)((o=s.style)==null?void 0:o.tokens);(0,e.useEffect)(()=>{c===null||U===void 0||(0,n.deepEqual)(U,W.current)||(W.current=U,c.tokens.set(U))},[c,U]);let{i18n:G}=s,K=(0,e.useRef)(s.i18n);(0,e.useEffect)(()=>{if(c===null||G===void 0||(0,n.deepEqual)(G,K.current))return;K.current=G;let{locale:e,messages:t,direction:r}=G;c.i18n.update(_(_(_({},e===void 0?{}:{locale:e}),t===void 0?{}:{messages:t}),r===void 0?{}:{direction:r}))},[c,G]);let{placeholder:q}=s;(0,e.useEffect)(()=>{c===null||q===void 0||c.placeholder.set(q)},[c,q]);let{data:J}=s;return(0,e.useEffect)(()=>{if(c===null||J===void 0)return;let e=p.current;if(e.editor!==c||e.isDestroyed)return;if(y.current!==c&&(y.current=c,S.current=void 0,g.current.clear(),(0,n.deepEqual)(J,b.current))){h.current=J;return}let t=h.current,r=S.current;t!==void 0&&(0,n.equalsOutputData)(J,t)||r!==void 0&&(0,n.equalsOutputData)(J,r)||g.current.matches(J)||(g.current.clear(),S.current=J,x.current=x.current.catch(()=>void 0).then(()=>c.render((0,n.toRenderableData)(J))).then(()=>{h.current=J},()=>{}).then(()=>{S.current===J&&(S.current=void 0)}))},[c,J]),c}function F(e,t){e.destroyTimeout=setTimeout(()=>{if(e.editor!==null){d(e.editor),E(e.editor),k(e.editor);try{e.editor.destroy()}catch(e){}e.editor=null,e.holder=null,e.isDestroyed=!0,e.isEditorReady=!1,e.destroyTimeout=null,t(null)}},0)}var I=class extends e.Component{constructor(...e){super(...e),this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(){}render(){return this.state.failed?null:this.props.children}};function L({registry:t}){let n=(0,e.useSyncExternalStore)(t.subscribe,t.getSnapshot,t.getSnapshot);return(0,r.jsx)(r.Fragment,{children:Array.from(n.entries()).map(([e,t])=>{let n=t.component;return(0,a.createPortal)((0,r.jsx)(I,{children:(0,r.jsx)(n,_({},t.props))}),t.hostEl,e)})})}var R=(0,e.createContext)(null);function z(){return(0,e.useContext)(R)}function B(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.includes(r))continue;n[r]=e[r]}return n}function V(e,t){if(e==null)return{};var n,r,i=B(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.includes(n)||{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var H=[`editor`];function U(e){var t,n;if(typeof window>`u`)return;let r=window.location.hash.slice(1);r!==``&&((t=(n=e.blocks).scrollToBlock)==null||t.call(n,W(r)))}function W(e){try{return decodeURIComponent(e)}catch(t){return e}}var G=(0,e.forwardRef)(function(t,n){let{editor:i}=t,a=V(t,H),o=(0,e.useRef)(null),s=e=>{if(o.current=e,typeof n==`function`)n(e);else if(n!=null){let t=n;t.current=e}};(0,e.useEffect)(()=>{if(i===null||o.current===null)return;let e=u(i);if(e!==void 0)return o.current.appendChild(e),U(i),()=>{e.remove()}},[i]);let c=i===null?void 0:T(i);return(0,r.jsx)(`div`,_(_({ref:s},a),{},{children:c===void 0?null:(0,r.jsx)(R.Provider,{value:i,children:(0,r.jsx)(L,{registry:c})})}))}),K=`autofocus.defaultBlock.dataModel.placeholder.sanitizer.hideToolbar.toolbarPosition.maxHistoryLength.historyDebounceTime.newGroupDelay.globalUndoRedo.tools.data.minHeight.logLevel.readOnly.i18n.link.linkPaste.onBeforePaste.onReady.onChange.onSave.onError.onEnter.onSubmit.onBeforeRender.onAfterRender.inlineToolbar.tunes.style.theme.onThemeChange.scrollToBlock.user.resolveUser.notifierPosition.notifier.width.migrations.uploader.captureClicksBelowEditor`.split(`.`),q=[`deps`,`onReady`,`locale`,`onBlocksRendered`,`onBlockRendered`],J=new Set(K),oe=(0,e.forwardRef)(function(t,n){let{deps:i,onReady:a,locale:o,onBlocksRendered:s,onBlockRendered:c}=t,l=V(t,q),u={},d={};for(let e of Object.keys(l)){let t=l[e];J.has(e)?u[e]=t:d[e]=t}if(o!==void 0){let e=u.i18n;u.i18n=_(_({},e),{},{locale:o})}let f=P(u,i);(0,e.useImperativeHandle)(n,()=>f,[f]);let p=(0,e.useRef)(a);p.current=a;let m=(0,e.useRef)(null);(0,e.useEffect)(()=>{if(f!==null&&m.current!==f){var e;m.current=f,(e=p.current)==null||e.call(p,f)}},[f]);let h=(0,e.useRef)(s);h.current=s;let g=(0,e.useRef)(c);g.current=c;let v=!!s,y=!!c;return(0,e.useEffect)(()=>{if(f===null)return;let e=[];if(v){let t=e=>{var t;return(t=h.current)==null?void 0:t.call(h,e)};f.on(`blocks:rendered`,t),e.push([`blocks:rendered`,t])}if(y){let t=e=>{var t;return(t=g.current)==null?void 0:t.call(g,e)};f.on(`block:rendered`,t),e.push([`block:rendered`,t])}return()=>{for(let[t,n]of e)f.off(t,n)}},[f,v,y]),(0,r.jsx)(G,_({editor:f},d))});function se(){let t=(0,e.useRef)(null);return(0,e.useMemo)(()=>({ref:e=>{t.current=e},get current(){return t.current},get isReady(){return t.current!==null},focus:e=>{var n,r;return(n=(r=t.current)==null?void 0:r.focus(e))!=null&&n},clear:()=>{let e=t.current;return e===null?Promise.resolve():e.clear().then(()=>{var t;(t=O(e))==null||t.markRendered(n.EMPTY_OUTPUT_DATA)})},save:()=>t.current===null?Promise.resolve(null):t.current.save(),render:e=>{let n=t.current;return n===null?Promise.resolve():n.render(e).then(()=>{var t;(t=O(n))==null||t.markRendered(e)})},setReadOnly:e=>{let n=t.current;return n===null?Promise.resolve(!1):n.readOnly.set(e==null?!n.readOnly.isEnabled:e)}}),[])}var Y=`block changed`;function ce(t,r={}){var i;let a=(i=r.within)==null?null:i,o=(0,e.useRef)(0),s=(0,e.useRef)(t);s.current!==t&&(s.current=t,o.current=0);let c=(0,e.useCallback)(e=>{if(t===null)return()=>void 0;let r=r=>{a!==null&&!(0,n.changeTouchesSubtree)(t,r,a)||(o.current+=1,e())};return t.on(Y,r),()=>t.off(Y,r)},[t,a]),l=(0,e.useCallback)(()=>o.current,[]);return(0,e.useSyncExternalStore)(c,l,l),(0,e.useMemo)(()=>t===null?n.EMPTY_API:(0,n.createBlocksApiForEditor)(t),[t])}function le(n={}){let{within:r,settleOn:i}=n,[a,o]=(0,e.useState)(!1);return(0,e.useEffect)(()=>{let e=()=>{var e;let n=r instanceof Element?r:(e=r==null?void 0:r.current)==null?null:e;o(r!==void 0&&n===null?!1:t.Blok.readyState({within:n,settleOn:i}).ready)};return e(),t.Blok.subscribeReady(e)},[r,i]),a}var ue=new Set([`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`link`,`meta`,`param`,`source`,`track`,`wbr`]),de=new Set([`disabled`,`open`,`controls`,`autoplay`,`loop`,`muted`,`required`,`multiple`,`playsinline`,`reversed`,`hidden`,`default`,`novalidate`,`allowfullscreen`,`itemscope`]),X={class:`className`,for:`htmlFor`,colspan:`colSpan`,rowspan:`rowSpan`,tabindex:`tabIndex`,readonly:`readOnly`,srcset:`srcSet`,srclang:`srcLang`,datetime:`dateTime`,autoplay:`autoPlay`,playsinline:`playsInline`,novalidate:`noValidate`,allowfullscreen:`allowFullScreen`,crossorigin:`crossOrigin`,referrerpolicy:`referrerPolicy`,contenteditable:`contentEditable`,spellcheck:`spellCheck`,maxlength:`maxLength`,minlength:`minLength`,usemap:`useMap`,itemscope:`itemScope`},fe=e=>{let t={};for(let n of e.split(`;`)){let e=n.indexOf(`:`);if(e===-1)continue;let r=n.slice(0,e).trim(),i=n.slice(e+1).trim();if(r===``||i===``)continue;let a=r.startsWith(`--`)?r:r.toLowerCase().replace(/-([a-z])/g,(e,t)=>t.toUpperCase());t[a]=i}return t},pe=(e,t)=>{let n={key:t};for(let[t,a]of Object.entries(e)){var r;if(t===`style`){n.style=fe(a);continue}if(t===`checked`){n.defaultChecked=!0;continue}if(t===`value`){n.defaultValue=a;continue}if(de.has(t)){var i;n[(i=X[t])==null?t:i]=!0;continue}n[(r=X[t])==null?t:r]=a}return n},Z=t=>t.map((t,n)=>{if(`text`in t)return t.text;let r=pe(t.attrs,n);return ue.has(t.tag)||t.children.length===0?(0,e.createElement)(t.tag,r):(0,e.createElement)(t.tag,r,...Z(t.children))}),Q=(t,n)=>{let r=n==null?void 0:n.schema,i=n==null?void 0:n.renderers,a=n==null?void 0:n.onUnknownBlock,s=n==null?void 0:n.toolAttributes,c=n==null?void 0:n.blockIds,l=n==null?void 0:n.transformUrl,u=n==null?void 0:n.inlineRenderers,d=n==null?void 0:n.classes;return(0,e.useMemo)(()=>(0,e.createElement)(e.Fragment,null,...Z((0,o.blocksToViewNodes)(t,{schema:r,renderers:i,onUnknownBlock:a,toolAttributes:s,blockIds:c,transformUrl:l,inlineRenderers:u,classes:d}))),[t,r,i,a,s,c,l,u,d])},me=[`data`,`schema`,`renderers`,`onUnknownBlock`,`toolAttributes`,`blockIds`,`transformUrl`,`inlineRenderers`,`classes`],he=e=>{let{data:t,schema:n,renderers:i,onUnknownBlock:a,toolAttributes:o,blockIds:s,transformUrl:c,inlineRenderers:l,classes:u}=e,d=V(e,me),f=Q(t,{schema:n,renderers:i,onUnknownBlock:a,toolAttributes:o,blockIds:s,transformUrl:c,inlineRenderers:l,classes:u==null||u});return(0,r.jsx)(`div`,_(_({"data-blok-interface":`view`},d),{},{children:f}))},ge=[`icon`,`title`],_e=[`commit`,`readOnly`],ve=[x,S],ye=(e,t,r)=>{var i;e==null||(i=e.events)==null||i.emit(n.BlockChildrenMounted,{blockId:t,childIds:r.map(e=>e.id)})},be=new Set([void 0,`user`,`api`,`convert`]),xe=[`toolbox`,`isReadOnlySupported`,`__isBlokReactBlock`,`__buildPortalToolbox`];function Se(t){var i,o;let c=e=>{if(typeof document>`u`)return null;let t=document.createElement(`div`),n=(0,s.createRoot)(t);(0,a.flushSync)(()=>{n.render(e)});let r=t.innerHTML;return n.unmount(),r===``?null:r},l=t=>{let{icon:n,title:r}=t,i=_({},V(t,ge));if(typeof r==`string`&&(i.title=r),!(0,e.isValidElement)(n))return n!==void 0&&(i.icon=n),{entry:i,deferred:!1};let a=c(n);return a===null?(i.icon=n,{entry:i,deferred:!0}):(i.icon=a,{entry:i,deferred:!1})},u=()=>{if(t.toolbox===void 0)return{value:void 0,complete:!0};let e=(Array.isArray(t.toolbox)?t.toolbox:[t.toolbox]).map(e=>l(e)),n=e.every(e=>!e.deferred),r=e.map(e=>e.entry);return{value:Array.isArray(t.toolbox)?r:r[0],complete:n}},d=(n,i)=>{if(t.toolbox===void 0)return;let a=Array.isArray(t.toolbox)?t.toolbox:[t.toolbox];if(!a.some(t=>(0,e.isValidElement)(t.title)))return;let o=a.map((t,a)=>{let{entry:o,deferred:s}=l(t);if(s&&delete o.icon,!(0,e.isValidElement)(t.title))return o;let c=document.createElement(`span`);c.setAttribute(`data-blok-mutation-free`,`true`);let u=t.title,d=()=>(0,r.jsx)(r.Fragment,{children:u});return d.displayName=`BlokToolboxTitle(${i})`,n.register(`__blok-toolbox-title__:${i}:${a}`,{hostEl:c,component:d,props:{},toolName:i}),_(_({},o),{},{titleEl:c})});return Array.isArray(t.toolbox)?o:o[0]},f={resolved:!1,value:void 0},p=()=>{if(f.resolved)return f.value;let{value:e,complete:t}=u();return t&&(f.value=e,f.resolved=!0),e},m=t.viewComponent===void 0?t.component:e=>{let n=t.viewComponent;if(e.readOnly&&n!==void 0){let{commit:t,readOnly:i}=e;return(0,r.jsx)(n,_({},V(e,_e)))}let i=t.component;return(0,r.jsx)(i,_({},e))},h=(i=class{static get toolbox(){return p()}static __buildPortalToolbox(e,t){return d(e,t)}static get isReadOnlySupported(){return!0}constructor(i){var a,o,s;this.mountSignalled=!1,this.hostEl=null,this.pendingDispatch=!1,this.anchorEl=null,this.toolbarAnchorRef=e=>{this.anchorEl=e},this.commit=e=>{var r;let i=(0,n.fillDefaults)(t.propSchema,_(_({},this.mirror),e));(0,n.deepEqual)(i,this.mirror)||(this.mirror=i,this.lastRendered=i,(r=this.registry)==null||r.setProps(this.blockApi.id,{data:i}),this.flushDispatch())},this.blockApi=i.block;let c=(a=i.config)==null?{}:a;this.registry=c[x];let l=c[S];this.toolName=typeof l==`string`?l:void 0;let u={};for(let[e,t]of Object.entries(c))ve.includes(e)||(u[e]=t);this.toolConfig=Object.freeze(u),this.api=i.api;let d=i.api;this.pointerDrag=()=>{var e;return(d==null||(e=d.blocks)==null?void 0:e.isPointerDragActive)===!0},this.mirror=(0,n.fillDefaults)(t.propSchema,(o=i.data)==null?{}:o),this.lastRendered=this.mirror,this.readOnly=i.readOnly,this.origin=(s=i.origin)==null?`api`:s;let f=this.blockApi,p=this.api;this.childrenComponent=function({childAttributes:t,childContentAttributes:i}){let a=(0,e.useRef)(null),o=(0,e.useRef)((0,n.createChildDecorationLedger)());return(0,e.useEffect)(()=>{if(a.current===null)return;let e=f.getChildren();(0,n.mountChildBlocks)(a.current,e),(0,n.applyChildDecoration)(o.current,e,{childAttributes:t,childContentAttributes:i}),ye(p,f.id,e)}),(0,r.jsx)(`div`,{ref:a,[n.DATA_ATTR.nestedBlocks]:``})},this.entryComponent=this.buildEntryComponent()}buildEntryComponent(){let n=t.onMounted,i=t.onCreated;if(n===void 0&&i===void 0)return m;let a=m,o=()=>{if(this.mountSignalled)return;this.mountSignalled=!0;let e={origin:this.origin,api:this.api};n==null||n(this.blockApi,e),be.has(this.origin)&&(i==null||i(this.blockApi,e))},s=t=>((0,e.useEffect)(o,[]),(0,r.jsx)(a,_({},t)));return s.displayName=`BlokBlockMount(${t.type})`,s}render(){var e;let t=document.createElement(`div`);return t.setAttribute(`data-blok-mutation-free`,`true`),this.hostEl=t,(e=this.registry)==null||e.register(this.blockApi.id,{hostEl:t,component:this.entryComponent,props:this.buildProps(),toolName:this.toolName}),t}rendered(){var e;(e=t.onRendered)==null||e.call(t,this.blockApi)}save(){return this.mirror}async setData(e){var r=this;let i=(0,n.fillDefaults)(t.propSchema,e==null?{}:e);return(0,n.deepEqual)(i,r.lastRendered)?!0:(r.mirror=i,r.lastRendered=i,r.pushProps({data:i}),!0)}setReadOnly(e){this.readOnly=e,this.pushProps({readOnly:e})}getToolbarAnchorElement(){var e;let n=this.anchorEl;if(n!==null&&n.isConnected)return n;let r=this.hostEl;if(!(r===null||t.getToolbarAnchorElement===void 0))return(e=t.getToolbarAnchorElement(r,this.blockApi))==null?void 0:e}moved(){var e;(e=t.onMoved)==null||e.call(t,this.blockApi)}removed(){var e,n,r;(e=this.registry)==null||e.unregister(this.blockApi.id,(n=this.hostEl)==null?void 0:n),(r=t.onRemoved)==null||r.call(t,this.blockApi)}destroy(){var e,t;(e=this.registry)==null||e.unregister(this.blockApi.id,(t=this.hostEl)==null?void 0:t)}buildProps(){return{data:this.mirror,commit:this.commit,block:this.blockApi,api:this.api,readOnly:this.readOnly,config:this.toolConfig,BlockChildren:this.childrenComponent,toolbarAnchorRef:this.toolbarAnchorRef}}pushProps(e){let t=this.registry;t!==void 0&&(0,a.flushSync)(()=>{t.setProps(this.blockApi.id,e)})}flushDispatch(){if(!this.pointerDrag()){this.pendingDispatch=!1,this.blockApi.dispatchChange();return}if(this.pendingDispatch)return;this.pendingDispatch=!0;let e=()=>{if(this.pointerDrag()){requestAnimationFrame(e);return}this.pendingDispatch=!1,this.blockApi.dispatchChange()};requestAnimationFrame(e)}},i.__isBlokReactBlock=!0,i);for(let[e,n]of Object.entries((o=t.statics)==null?{}:o))xe.includes(e)||Object.defineProperty(h,e,{value:n,writable:!0,enumerable:!0,configurable:!0});return h}var Ce=[x,S],we=e=>`__blok-inline-tool__:${e}:${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,$=(0,e.createContext)(null);function Te(){let t=(0,e.useContext)($);if(t===null)throw Error(`useInlineTool() must be called from a component rendered by createReactInlineTool`);return t}function Ee(t){var i;return i=class{static get type(){return t.type}static get title(){return t.title}static get titleKey(){var e;return(e=t.titleKey)==null?t.type:e}static get shortcut(){return t.shortcut}static get mark(){return t.mark}static get sanitize(){return t.sanitize===void 0?t.mark===void 0?void 0:(0,n.markSanitizerConfig)(t.mark):t.sanitize}static get isReadOnlySupported(){var e;return(e=t.isReadOnlySupported)!=null&&e}constructor(e){var n;this.active=!1,this.registered=!1;let r=(n=e==null?void 0:e.config)==null?{}:n;this.api=e==null?void 0:e.api,this.registry=r[x];let i=r[S];this.toolName=typeof i==`string`?i:t.type,this.portalKey=we(this.toolName);let a={};for(let[e,t]of Object.entries(r))Ce.includes(e)||(a[e]=t);this.toolConfig=Object.freeze(a),this.portalComponent=this.createPortalComponent()}render(){let e=document.createElement(`div`);return e.setAttribute(`data-blok-mutation-free`,`true`),this.registry!==void 0&&(this.registry.register(this.portalKey,{hostEl:e,component:this.portalComponent,props:{active:this.active,config:this.toolConfig},toolName:this.toolName}),this.registered=!0),{name:this.toolName,title:t.title,icon:e,onActivate:()=>{this.activate()},isActive:()=>this.refreshActiveState()}}destroy(){var e;this.registered&&(this.registered=!1,(e=this.registry)==null||e.unregister(this.portalKey))}activate(){var e;if(typeof t.surround==`function`){let e=window.getSelection();if(!e||e.rangeCount===0)return;t.surround(e.getRangeAt(0),this.api);return}t.mark!==void 0&&((e=this.api)==null?void 0:e.marks)!==void 0&&this.api.marks.toggle(t.mark)}refreshActiveState(){let e=this.computeActiveState();if(e!==this.active&&(this.active=e,this.registered)){var t;(t=this.registry)==null||t.setProps(this.portalKey,{active:e})}return e}computeActiveState(){var e;return typeof t.checkState==`function`?!!t.checkState(window.getSelection(),this.api):t.mark!==void 0&&((e=this.api)==null?void 0:e.marks)!==void 0&&this.api.marks.has(t.mark)}createPortalComponent(){let n=this.api,i=t.mark,a=t.component,o=i!==void 0&&(n==null?void 0:n.marks)!==void 0?{has:()=>n.marks.has(i),toggle:e=>n.marks.toggle(i,e),apply:e=>n.marks.apply(i,e),remove:()=>n.marks.remove(i),read:()=>n.marks.read(i)}:null,s=t=>{let i=(0,e.useMemo)(()=>({active:t.active,config:t.config,api:n,mark:o}),[t.active,t.config]);return(0,r.jsx)($.Provider,{value:i,children:(0,r.jsx)(a,{active:t.active,config:t.config})})};return s.displayName=`BlokInlineTool(${this.toolName})`,s}},i.__isBlokReactInlineTool=!0,i.isInline=!0,i}exports.BLOK_PORTAL_REGISTRY_CONFIG_KEY=x,exports.BLOK_TOOL_NAME_CONFIG_KEY=S,exports.BlockPortalHost=L,exports.BlokContent=G,exports.BlokEditor=oe,exports.BlokProvider=y,exports.BlokView=he,exports.createBlockPortalRegistry=C,exports.createReactBlock=Se,exports.createReactInlineTool=Ee,Object.defineProperty(exports,"getDirection",{enumerable:!0,get:function(){return i.getDirection}}),Object.defineProperty(exports,"normalizeLocale",{enumerable:!0,get:function(){return i.normalizeLocale}}),exports.useBlocks=ce,exports.useBlok=P,exports.useBlokDefaults=b,exports.useBlokHandle=se,exports.useBlokInstance=z,exports.useBlokReady=le,exports.useBlokView=Q,exports.useInlineTool=Te;
|
package/dist/index.mjs
CHANGED
|
@@ -81,16 +81,16 @@ function W(e) {
|
|
|
81
81
|
//#endregion
|
|
82
82
|
//#region src/provide-blok.tsx
|
|
83
83
|
var G = n({});
|
|
84
|
-
function
|
|
84
|
+
function K({ defaults: e, children: t }) {
|
|
85
85
|
return /* @__PURE__ */ k(G.Provider, {
|
|
86
86
|
value: e,
|
|
87
87
|
children: t
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function ae() {
|
|
91
91
|
return s(G);
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function oe(e, t) {
|
|
94
94
|
if (Object.keys(e).length === 0) return t;
|
|
95
95
|
let n = W({}, e);
|
|
96
96
|
for (let e of Object.keys(t)) {
|
|
@@ -101,7 +101,7 @@ function se(e, t) {
|
|
|
101
101
|
}
|
|
102
102
|
//#endregion
|
|
103
103
|
//#region src/block-portal-registry.ts
|
|
104
|
-
var
|
|
104
|
+
var q = "__blokPortalRegistry", J = "__blokToolName", se = () => {
|
|
105
105
|
let e = { snapshot: /* @__PURE__ */ new Map() }, t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map(), r = (n) => {
|
|
106
106
|
e.snapshot = n, t.forEach((e) => e());
|
|
107
107
|
};
|
|
@@ -139,27 +139,27 @@ var K = "__blokPortalRegistry", q = "__blokToolName", ce = () => {
|
|
|
139
139
|
return e.snapshot;
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
|
-
},
|
|
143
|
-
function
|
|
144
|
-
|
|
142
|
+
}, Y = /* @__PURE__ */ new WeakMap();
|
|
143
|
+
function ce(e, t) {
|
|
144
|
+
Y.set(e, t);
|
|
145
145
|
}
|
|
146
|
-
function
|
|
147
|
-
return
|
|
146
|
+
function le(e) {
|
|
147
|
+
return Y.get(e);
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
|
|
149
|
+
function X(e) {
|
|
150
|
+
Y.delete(e);
|
|
151
151
|
}
|
|
152
152
|
//#endregion
|
|
153
153
|
//#region src/content-baseline-map.ts
|
|
154
|
-
var
|
|
155
|
-
function
|
|
156
|
-
|
|
154
|
+
var Z = /* @__PURE__ */ new WeakMap();
|
|
155
|
+
function ue(e, t) {
|
|
156
|
+
Z.set(e, t);
|
|
157
157
|
}
|
|
158
|
-
function
|
|
159
|
-
return
|
|
158
|
+
function de(e) {
|
|
159
|
+
return Z.get(e);
|
|
160
160
|
}
|
|
161
|
-
function
|
|
162
|
-
|
|
161
|
+
function fe(e) {
|
|
162
|
+
Z.delete(e);
|
|
163
163
|
}
|
|
164
164
|
//#endregion
|
|
165
165
|
//#region src/live-tool-config.ts
|
|
@@ -231,8 +231,8 @@ var Q = (e) => {
|
|
|
231
231
|
}
|
|
232
232
|
let e = typeof a == "function" ? { class: a } : W({}, a);
|
|
233
233
|
e.config = W(W({}, (r = e.config) == null ? {} : r), {}, {
|
|
234
|
-
[
|
|
235
|
-
[
|
|
234
|
+
[q]: t,
|
|
235
|
+
[J]: i
|
|
236
236
|
});
|
|
237
237
|
let o = e.class.__buildPortalToolbox, s = typeof o == "function" && e.toolbox === void 0 ? o(t, i) : void 0;
|
|
238
238
|
s !== void 0 && (e.toolbox = s), n[i] = e;
|
|
@@ -241,7 +241,7 @@ var Q = (e) => {
|
|
|
241
241
|
};
|
|
242
242
|
function ye(e, t) {
|
|
243
243
|
var n, r;
|
|
244
|
-
let i =
|
|
244
|
+
let i = oe(s(G), e), [a, o] = f(null), l = d(i);
|
|
245
245
|
l.current = i;
|
|
246
246
|
let p = d({
|
|
247
247
|
editor: null,
|
|
@@ -266,7 +266,7 @@ function ye(e, t) {
|
|
|
266
266
|
be(t, o);
|
|
267
267
|
};
|
|
268
268
|
if (t.editor !== null && !t.isDestroyed) {
|
|
269
|
-
R(t.editor),
|
|
269
|
+
R(t.editor), X(t.editor), fe(t.editor);
|
|
270
270
|
try {
|
|
271
271
|
t.editor.destroy();
|
|
272
272
|
} catch (e) {}
|
|
@@ -274,7 +274,7 @@ function ye(e, t) {
|
|
|
274
274
|
}
|
|
275
275
|
let n = document.createElement("div");
|
|
276
276
|
t.holder = n, t.isDestroyed = !1, t.isEditorReady = !1, t.depsToken = h;
|
|
277
|
-
let r = l.current, i =
|
|
277
|
+
let r = l.current, i = se(), a = r.tools === void 0 ? void 0 : he(r.tools, () => l.current.tools), s = a === void 0 ? void 0 : ve(a, i);
|
|
278
278
|
S.current = i, C.current = a, T.current = /* @__PURE__ */ new Map(), E.current = new Map(Object.entries((e = r.tools) == null ? {} : e).map(([e, t]) => [e, typeof t == "object" && t ? t.toolbox : void 0]));
|
|
279
279
|
let c = {
|
|
280
280
|
onChange: (...e) => {
|
|
@@ -319,13 +319,13 @@ function ye(e, t) {
|
|
|
319
319
|
(t = (n = l.current).onReady) == null || t.call(n, ...e);
|
|
320
320
|
}
|
|
321
321
|
}, u.onChange ? { onChange: c.onChange } : {}), u.onSave ? { onSave: c.onSave } : {}), u.onEnter ? { onEnter: c.onEnter } : {}), u.onSubmit ? { onSubmit: c.onSubmit } : {}), u.onBeforeRender ? { onBeforeRender: c.onBeforeRender } : {}), u.onAfterRender ? { onAfterRender: c.onAfterRender } : {}));
|
|
322
|
-
return t.editor = d, y.current = r.data, ie(d, n),
|
|
322
|
+
return t.editor = d, y.current = r.data, ie(d, n), ce(d, i), ue(d, { markRendered: (e) => {
|
|
323
323
|
_.current.clear(), g.current = e, x.current = void 0;
|
|
324
324
|
} }), d.isReady.then(() => {
|
|
325
325
|
t.editor === d && !t.isDestroyed && (t.isEditorReady = !0, o(d));
|
|
326
326
|
}).catch(() => {
|
|
327
327
|
if (t.editor === d && !t.isDestroyed) {
|
|
328
|
-
R(d),
|
|
328
|
+
R(d), X(d), fe(d);
|
|
329
329
|
try {
|
|
330
330
|
d.destroy();
|
|
331
331
|
} catch (e) {}
|
|
@@ -392,58 +392,62 @@ function ye(e, t) {
|
|
|
392
392
|
c(() => {
|
|
393
393
|
a === null || M === void 0 || a.toolbar.setHidden(M);
|
|
394
394
|
}, [a, M]);
|
|
395
|
-
let {
|
|
395
|
+
let { toolbarPosition: N } = i;
|
|
396
396
|
c(() => {
|
|
397
|
-
a === null || N === void 0 || a.
|
|
398
|
-
}, [a, N
|
|
399
|
-
let {
|
|
397
|
+
a === null || N === void 0 || a.toolbar.setPosition(N);
|
|
398
|
+
}, [a, N]);
|
|
399
|
+
let { inlineToolbar: P } = i;
|
|
400
400
|
c(() => {
|
|
401
|
-
a === null ||
|
|
402
|
-
}, [a, P]);
|
|
403
|
-
let {
|
|
401
|
+
a === null || P === void 0 || a.tools.setInlineToolbar(P);
|
|
402
|
+
}, [a, P === void 0 ? void 0 : JSON.stringify(P)]);
|
|
403
|
+
let { autofocus: F } = i;
|
|
404
404
|
c(() => {
|
|
405
|
-
a === null || F
|
|
405
|
+
a === null || !F || a.focus();
|
|
406
406
|
}, [a, F]);
|
|
407
|
-
let {
|
|
407
|
+
let { theme: I } = i;
|
|
408
408
|
c(() => {
|
|
409
|
-
a === null || I === void 0 || a.
|
|
409
|
+
a === null || I === void 0 || a.theme.set(I);
|
|
410
410
|
}, [a, I]);
|
|
411
|
-
let
|
|
411
|
+
let { width: L } = i;
|
|
412
412
|
c(() => {
|
|
413
|
-
a === null || L === void 0 ||
|
|
413
|
+
a === null || L === void 0 || a.width.set(L);
|
|
414
414
|
}, [a, L]);
|
|
415
|
-
let
|
|
415
|
+
let z = (n = i.style) == null ? void 0 : n.tokens, B = d((r = i.style) == null ? void 0 : r.tokens);
|
|
416
|
+
c(() => {
|
|
417
|
+
a === null || z === void 0 || w(z, B.current) || (B.current = z, a.tokens.set(z));
|
|
418
|
+
}, [a, z]);
|
|
419
|
+
let { i18n: V } = i, H = d(i.i18n);
|
|
416
420
|
c(() => {
|
|
417
|
-
if (a === null ||
|
|
418
|
-
|
|
419
|
-
let { locale: e, messages: t, direction: n } =
|
|
421
|
+
if (a === null || V === void 0 || w(V, H.current)) return;
|
|
422
|
+
H.current = V;
|
|
423
|
+
let { locale: e, messages: t, direction: n } = V;
|
|
420
424
|
a.i18n.update(W(W(W({}, e === void 0 ? {} : { locale: e }), t === void 0 ? {} : { messages: t }), n === void 0 ? {} : { direction: n }));
|
|
421
|
-
}, [a,
|
|
422
|
-
let { placeholder:
|
|
425
|
+
}, [a, V]);
|
|
426
|
+
let { placeholder: U } = i;
|
|
423
427
|
c(() => {
|
|
424
|
-
a === null ||
|
|
425
|
-
}, [a,
|
|
426
|
-
let { data:
|
|
428
|
+
a === null || U === void 0 || a.placeholder.set(U);
|
|
429
|
+
}, [a, U]);
|
|
430
|
+
let { data: K } = i;
|
|
427
431
|
return c(() => {
|
|
428
|
-
if (a === null ||
|
|
432
|
+
if (a === null || K === void 0) return;
|
|
429
433
|
let e = p.current;
|
|
430
434
|
if (e.editor !== a || e.isDestroyed) return;
|
|
431
|
-
if (v.current !== a && (v.current = a, x.current = void 0, _.current.clear(), w(
|
|
432
|
-
g.current =
|
|
435
|
+
if (v.current !== a && (v.current = a, x.current = void 0, _.current.clear(), w(K, y.current))) {
|
|
436
|
+
g.current = K;
|
|
433
437
|
return;
|
|
434
438
|
}
|
|
435
439
|
let t = g.current, n = x.current;
|
|
436
|
-
t !== void 0 && te(
|
|
437
|
-
g.current =
|
|
440
|
+
t !== void 0 && te(K, t) || n !== void 0 && te(K, n) || _.current.matches(K) || (_.current.clear(), x.current = K, b.current = b.current.catch(() => void 0).then(() => a.render(re(K))).then(() => {
|
|
441
|
+
g.current = K;
|
|
438
442
|
}, () => {}).then(() => {
|
|
439
|
-
x.current ===
|
|
443
|
+
x.current === K && (x.current = void 0);
|
|
440
444
|
}));
|
|
441
|
-
}, [a,
|
|
445
|
+
}, [a, K]), a;
|
|
442
446
|
}
|
|
443
447
|
function be(e, t) {
|
|
444
448
|
e.destroyTimeout = setTimeout(() => {
|
|
445
449
|
if (e.editor !== null) {
|
|
446
|
-
R(e.editor),
|
|
450
|
+
R(e.editor), X(e.editor), fe(e.editor);
|
|
447
451
|
try {
|
|
448
452
|
e.editor.destroy();
|
|
449
453
|
} catch (e) {}
|
|
@@ -531,12 +535,12 @@ var ke = i(function(e, t) {
|
|
|
531
535
|
e.remove();
|
|
532
536
|
};
|
|
533
537
|
}, [n]);
|
|
534
|
-
let o = n === null ? void 0 :
|
|
538
|
+
let o = n === null ? void 0 : le(n);
|
|
535
539
|
return /* @__PURE__ */ k("div", W(W({ ref: a }, r), {}, { children: o === void 0 ? null : /* @__PURE__ */ k(Ce.Provider, {
|
|
536
540
|
value: n,
|
|
537
541
|
children: /* @__PURE__ */ k(Se, { registry: o })
|
|
538
542
|
}) }));
|
|
539
|
-
}), Ae = /* @__PURE__ */ "autofocus.defaultBlock.dataModel.placeholder.sanitizer.hideToolbar.maxHistoryLength.historyDebounceTime.newGroupDelay.globalUndoRedo.tools.data.minHeight.logLevel.readOnly.i18n.link.linkPaste.onBeforePaste.onReady.onChange.onSave.onError.onEnter.onSubmit.onBeforeRender.onAfterRender.inlineToolbar.tunes.style.theme.onThemeChange.scrollToBlock.user.resolveUser.notifierPosition.notifier.width.migrations.uploader.captureClicksBelowEditor".split("."), je = [
|
|
543
|
+
}), Ae = /* @__PURE__ */ "autofocus.defaultBlock.dataModel.placeholder.sanitizer.hideToolbar.toolbarPosition.maxHistoryLength.historyDebounceTime.newGroupDelay.globalUndoRedo.tools.data.minHeight.logLevel.readOnly.i18n.link.linkPaste.onBeforePaste.onReady.onChange.onSave.onError.onEnter.onSubmit.onBeforeRender.onAfterRender.inlineToolbar.tunes.style.theme.onThemeChange.scrollToBlock.user.resolveUser.notifierPosition.notifier.width.migrations.uploader.captureClicksBelowEditor".split("."), je = [
|
|
540
544
|
"deps",
|
|
541
545
|
"onReady",
|
|
542
546
|
"locale",
|
|
@@ -616,7 +620,7 @@ function Pe() {
|
|
|
616
620
|
let t = e.current;
|
|
617
621
|
return t === null ? Promise.resolve() : t.clear().then(() => {
|
|
618
622
|
var e;
|
|
619
|
-
(e =
|
|
623
|
+
(e = de(t)) == null || e.markRendered(v);
|
|
620
624
|
});
|
|
621
625
|
},
|
|
622
626
|
save: () => e.current === null ? Promise.resolve(null) : e.current.save(),
|
|
@@ -624,7 +628,7 @@ function Pe() {
|
|
|
624
628
|
let n = e.current;
|
|
625
629
|
return n === null ? Promise.resolve() : n.render(t).then(() => {
|
|
626
630
|
var e;
|
|
627
|
-
(e =
|
|
631
|
+
(e = de(n)) == null || e.markRendered(t);
|
|
628
632
|
});
|
|
629
633
|
},
|
|
630
634
|
setReadOnly: (t) => {
|
|
@@ -803,7 +807,7 @@ var Re = /* @__PURE__ */ new Set([
|
|
|
803
807
|
classes: l == null || l
|
|
804
808
|
});
|
|
805
809
|
return /* @__PURE__ */ k("div", W(W({ "data-blok-interface": "view" }, u), {}, { children: d }));
|
|
806
|
-
}, qe = ["icon", "title"], Je = ["commit", "readOnly"], Ye = [
|
|
810
|
+
}, qe = ["icon", "title"], Je = ["commit", "readOnly"], Ye = [q, J], Xe = (e, t, n) => {
|
|
807
811
|
var r;
|
|
808
812
|
e == null || (r = e.events) == null || r.emit(h, {
|
|
809
813
|
blockId: t,
|
|
@@ -907,8 +911,8 @@ function $e(e) {
|
|
|
907
911
|
C(r, this.mirror) || (this.mirror = r, this.lastRendered = r, (n = this.registry) == null || n.setProps(this.blockApi.id, { data: r }), this.flushDispatch());
|
|
908
912
|
}, this.blockApi = t.block;
|
|
909
913
|
let a = (n = t.config) == null ? {} : n;
|
|
910
|
-
this.registry = a[
|
|
911
|
-
let o = a[
|
|
914
|
+
this.registry = a[q];
|
|
915
|
+
let o = a[J];
|
|
912
916
|
this.toolName = typeof o == "string" ? o : void 0;
|
|
913
917
|
let s = {};
|
|
914
918
|
for (let [e, t] of Object.entries(a)) Ye.includes(e) || (s[e] = t);
|
|
@@ -1037,7 +1041,7 @@ function $e(e) {
|
|
|
1037
1041
|
}
|
|
1038
1042
|
//#endregion
|
|
1039
1043
|
//#region src/createReactInlineTool.tsx
|
|
1040
|
-
var et = [
|
|
1044
|
+
var et = [q, J], tt = (e) => `__blok-inline-tool__:${e}:${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`, nt = n(null);
|
|
1041
1045
|
function rt() {
|
|
1042
1046
|
let e = s(nt);
|
|
1043
1047
|
if (e === null) throw Error("useInlineTool() must be called from a component rendered by createReactInlineTool");
|
|
@@ -1073,8 +1077,8 @@ function it(e) {
|
|
|
1073
1077
|
var n;
|
|
1074
1078
|
this.active = !1, this.registered = !1;
|
|
1075
1079
|
let r = (n = t == null ? void 0 : t.config) == null ? {} : n;
|
|
1076
|
-
this.api = t == null ? void 0 : t.api, this.registry = r[
|
|
1077
|
-
let i = r[
|
|
1080
|
+
this.api = t == null ? void 0 : t.api, this.registry = r[q];
|
|
1081
|
+
let i = r[J];
|
|
1078
1082
|
this.toolName = typeof i == "string" ? i : e.type, this.portalKey = tt(this.toolName);
|
|
1079
1083
|
let a = {};
|
|
1080
1084
|
for (let [e, t] of Object.entries(r)) et.includes(e) || (a[e] = t);
|
|
@@ -1153,4 +1157,4 @@ function it(e) {
|
|
|
1153
1157
|
}, t.__isBlokReactInlineTool = !0, t.isInline = !0, t;
|
|
1154
1158
|
}
|
|
1155
1159
|
//#endregion
|
|
1156
|
-
export {
|
|
1160
|
+
export { q as BLOK_PORTAL_REGISTRY_CONFIG_KEY, J as BLOK_TOOL_NAME_CONFIG_KEY, Se as BlockPortalHost, ke as BlokContent, Ne as BlokEditor, K as BlokProvider, Ke as BlokView, se as createBlockPortalRegistry, $e as createReactBlock, it as createReactInlineTool, A as getDirection, j as normalizeLocale, Ie as useBlocks, ye as useBlok, ae as useBlokDefaults, Pe as useBlokHandle, we as useBlokInstance, Le as useBlokReady, We as useBlokView, rt as useInlineTool };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloklabs/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "React block editor — official React bindings for Blok, the headless Notion-like rich text editor. Hooks and components that render blocks and save to JSON.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "JackUait",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"test": "yarn run -T vitest run"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@bloklabs/core": "^1.
|
|
57
|
+
"@bloklabs/core": "^1.11.0",
|
|
58
58
|
"react": "^18.0.0 || ^19.0.0",
|
|
59
59
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
60
60
|
}
|
package/src/config-keys.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { BlokConfig, Blok, EditorWidth } from '@/types';
|
|
|
9
9
|
* - `readOnly` — calls `editor.readOnly.set(value)`; the object form also
|
|
10
10
|
* syncs `hideControls` via `editor.readOnly.set(enabled, { hideControls })`
|
|
11
11
|
* - `hideToolbar` — calls `editor.toolbar.setHidden(value)`
|
|
12
|
+
* - `toolbarPosition` — calls `editor.toolbar.setPosition(value)`
|
|
12
13
|
* - `inlineToolbar` — calls `editor.tools.setInlineToolbar(value)` (arrays
|
|
13
14
|
* are compared by content, so a re-created literal is a no-op)
|
|
14
15
|
* - `autofocus` — calls `editor.focus()` when changed to true
|
package/src/useBlok.ts
CHANGED
|
@@ -590,6 +590,20 @@ export function useBlok(configInput: UseBlokConfig, deps?: DependencyList): Blok
|
|
|
590
590
|
editor.toolbar.setHidden(hideToolbar);
|
|
591
591
|
}, [editor, hideToolbar]);
|
|
592
592
|
|
|
593
|
+
// Reactive: toolbarPosition — `toolbar.setPosition` writes
|
|
594
|
+
// `config.toolbarPosition` (read live by the layout paths CSS cannot mirror)
|
|
595
|
+
// AND re-stamps the wrapper's toolbar-position attribute (the CSS hook that
|
|
596
|
+
// swaps the gutter and the actions bar), so a prop flip moves the controls in
|
|
597
|
+
// place. Guarded on `undefined` so a consumer who never sets the prop gets no
|
|
598
|
+
// call at all (mirrors hideToolbar).
|
|
599
|
+
const { toolbarPosition } = config;
|
|
600
|
+
useEffect(() => {
|
|
601
|
+
if (editor === null || toolbarPosition === undefined) {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
editor.toolbar.setPosition(toolbarPosition);
|
|
605
|
+
}, [editor, toolbarPosition]);
|
|
606
|
+
|
|
593
607
|
// Reactive: inlineToolbar — `tools.setInlineToolbar` re-assigns every block
|
|
594
608
|
// tool's inline set and invalidates sanitize caches, so the change lands on
|
|
595
609
|
// the next selection without a re-render. The dep is a content serialization
|
package/types/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { getDirection, normalizeLocale } from '@bloklabs/core/locales';
|
|
|
21
21
|
* - `readOnly` — calls `editor.readOnly.set(value)`; the object form also
|
|
22
22
|
* syncs `hideControls` via `editor.readOnly.set(enabled, { hideControls })`
|
|
23
23
|
* - `hideToolbar` — calls `editor.toolbar.setHidden(value)`
|
|
24
|
+
* - `toolbarPosition` — calls `editor.toolbar.setPosition(value)`
|
|
24
25
|
* - `inlineToolbar` — calls `editor.tools.setInlineToolbar(value)` (arrays
|
|
25
26
|
* are compared by content, so a re-created literal is a no-op)
|
|
26
27
|
* - `autofocus` — calls `editor.focus()` when changed to true
|