@bloklabs/vue 1.8.0 → 1.10.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 CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("vue"),t=require("@bloklabs/core"),n=require("@bloklabs/core/adapters");var r=new WeakMap;function i(e,t){r.set(e,t)}function a(e){return r.get(e)}function o(e){r.delete(e)}var s=new WeakMap;function c(e,t){s.set(e,t)}function l(e){return s.get(e)}function u(e){s.delete(e)}function d(e){"@babel/helpers - typeof";return d=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},d(e)}function f(e,t){if(d(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(d(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function p(e){var t=f(e,`string`);return d(t)==`symbol`?t:t+``}function m(e,t,n){return(t=p(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(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 g(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?h(Object(n),!0).forEach(function(t){m(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):h(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var _=Symbol(`BLOK_DEFAULT_CONFIG`);function v(t){(0,e.provide)(_,t)}function y(){return(0,e.inject)(_,{})}function b(e,t){if(Object.keys(e).length===0)return t;let n=g({},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=g(g({},e.tools),t.tools)),n}var x=`__blokPortalRegistry`,S=()=>{let t=(0,e.reactive)(new Map);return{entries:t,register(n,r){t.set(n,(0,e.markRaw)(r))},unregister(e,n){var r;n!==void 0&&((r=t.get(e))==null?void 0:r.hostEl)!==n||t.delete(e)},setProps(e,n){let r=t.get(e);r!==void 0&&Object.assign(r.props,n)}}},C=new WeakMap;function w(e,t){C.set(e,t)}function T(e){return C.get(e)}function E(e){C.delete(e)}var D=e=>({onChange:e.onChange!==void 0,onSave:e.onSave!==void 0,onEnter:e.onEnter!==void 0,onSubmit:e.onSubmit!==void 0,onBeforeRender:e.onBeforeRender!==void 0,onAfterRender:e.onAfterRender!==void 0}),O=(e,t)=>{if(typeof e!=`object`||!e)return e;let n={};for(let[i,a]of Object.entries(e)){var r;let e=typeof a==`function`?a:a==null?void 0:a.class;if(!(typeof e==`function`&&e.__isBlokVueBlock===!0)){n[i]=a;continue}let o=typeof a==`function`?{class:a}:g({},a);o.config=g(g({},(r=o.config)==null?{}:r),{},{[x]:t}),n[i]=o}return n};function k(r,a){let s=(0,e.shallowRef)(null),l=(0,e.inject)(_,{}),d=()=>b(l,(0,e.toValue)(r)),f={current:null,holder:null,lastRenderedData:d().data,seededEditor:null,renderChain:Promise.resolve(),appliedHandlerPresence:{onChange:!1,onSave:!1,onEnter:!1,onSubmit:!1,onBeforeRender:!1,onAfterRender:!1}},p={onChange:(...e)=>{var t,n;(t=(n=d()).onChange)==null||t.call(n,...e)},onSave:(...e)=>{var t,n;f.lastRenderedData=e[0],(t=(n=d()).onSave)==null||t.call(n,...e)},onEnter:(...e)=>{var t,n;return(t=(n=d()).onEnter)==null?void 0:t.call(n,...e)},onSubmit:(...e)=>{var t,n;(t=(n=d()).onSubmit)==null||t.call(n,...e)},onBeforeRender:(...e)=>{var t,n,r;return(t=(n=(r=d()).onBeforeRender)==null?void 0:n.call(r,...e))==null?e[0]:t},onAfterRender:(...e)=>{var t,n;(t=(n=d()).onAfterRender)==null||t.call(n,...e)}},m=()=>{let t=g({},b((0,e.toRaw)(l),(0,e.toRaw)((0,e.toValue)(r))));return delete t.holder,t.data!==void 0&&(t.data=(0,e.toRaw)(t.data)),t},h=()=>{if(f.current!==null){u(f.current),E(f.current),o(f.current);try{f.current.destroy()}catch(e){}}f.current=null,f.holder=null,s.value=null},v=()=>{let e=document.createElement(`div`);f.holder=e;let n=m(),r=S();n.tools!==void 0&&(n.tools=O(n.tools,r));let a=D(d());n.onChange=a.onChange?p.onChange:void 0,n.onSave=a.onSave?p.onSave:void 0,n.onEnter=a.onEnter?p.onEnter:void 0,n.onSubmit=a.onSubmit?p.onSubmit:void 0,n.onBeforeRender=a.onBeforeRender?p.onBeforeRender:void 0,n.onAfterRender=a.onAfterRender?p.onAfterRender:void 0,f.appliedHandlerPresence=a;let o=new t.Blok(g(g({},n),{},{holder:e}));f.current=o,c(o,e),w(o,r),i(o,{markRendered:e=>{f.lastRenderedData=e}}),o.isReady.then(()=>{f.current===o&&(s.value=o)}).catch(()=>{f.current===o&&h()})};(0,e.watch)([s,()=>(0,n.normalizeReadOnlyConfig)(d().readOnly).enabled,()=>(0,n.normalizeReadOnlyConfig)(d().readOnly).hideControls,()=>typeof d().readOnly==`object`],([e,t,n,r])=>{e&&(r?e.readOnly.set(t,{hideControls:n}):e.readOnly.set(t))},{immediate:!0}),(0,e.watch)([s,()=>d().hideToolbar],([e,t])=>{e&&e.toolbar.setHidden(!!t)},{immediate:!0}),(0,e.watch)([s,()=>d().theme],([e,t])=>{e&&t!==void 0&&e.theme.set(t)},{immediate:!0}),(0,e.watch)([s,()=>d().width],([e,t])=>{e&&t!==void 0&&e.width.set(t)},{immediate:!0}),(0,e.watch)([s,()=>d().placeholder],([e,t])=>{e&&t!==void 0&&e.placeholder.set(t)},{immediate:!0});let y={value:void 0};(0,e.watch)([s,()=>{var e;return(e=d().style)==null?void 0:e.tokens}],([e,t])=>{!e||t===void 0||(0,n.deepEqual)(t,y.value)||(y.value=g({},t),e.tokens.set(t))},{immediate:!0,deep:!0});let x={value:d().i18n};(0,e.watch)([s,()=>d().i18n],([e,t])=>{if(!e||t===void 0||(0,n.deepEqual)(t,x.value))return;x.value=g({},t);let{locale:r,messages:i,direction:a}=t;e.i18n.update(g(g(g({},r===void 0?{}:{locale:r}),i===void 0?{}:{messages:i}),a===void 0?{}:{direction:a}))},{immediate:!0,deep:!0});let C={editor:null,value:void 0};return(0,e.watch)([s,()=>d().inlineToolbar],([e,t])=>{if(!e||t===void 0||C.editor===e&&(0,n.deepEqual)(t,C.value))return;let r=Array.isArray(t)?[...t]:t;C.editor=e,C.value=r,e.tools.setInlineToolbar(r)},{immediate:!0,deep:!0}),(0,e.watch)([s,()=>d().autofocus],([e,t])=>{e&&t&&e.focus()},{immediate:!0}),(0,e.watch)([s,()=>JSON.stringify(D(d()))],([e])=>{if(!e)return;let t=D(d()),n=f.appliedHandlerPresence,r={},i={value:!1},a=(e,r)=>{t[e]!==n[e]&&(n[e]=t[e],i.value=!0,r(t[e]?p[e]:void 0))};a(`onChange`,e=>{r.onChange=e}),a(`onSave`,e=>{r.onSave=e}),a(`onEnter`,e=>{r.onEnter=e}),a(`onSubmit`,e=>{r.onSubmit=e}),a(`onBeforeRender`,e=>{r.onBeforeRender=e}),a(`onAfterRender`,e=>{r.onAfterRender=e}),i.value&&e.handlers.set(r)},{immediate:!0}),(0,e.watch)([s,()=>d().data],([t,r])=>{if(!t||r===void 0)return;if(f.seededEditor!==t){f.seededEditor=t,f.lastRenderedData=r;return}let i=f.lastRenderedData;i!==void 0&&(0,n.equalsOutputData)(r,i)||(f.lastRenderedData=r,f.renderChain=f.renderChain.catch(()=>void 0).then(()=>t.render((0,n.toRenderableData)((0,e.toRaw)(r)))))},{immediate:!0}),a!==void 0&&(0,e.watch)(()=>(0,e.toValue)(a),()=>{h(),v()}),(0,e.onMounted)(v),(0,e.onBeforeUnmount)(h),s}var A=`block changed`;function j(t){let r=(0,e.shallowRef)(0),i=()=>{let n=(0,e.toValue)(t);return n===null?null:(0,e.toRaw)(n)},a=()=>{r.value},o=(0,e.shallowRef)(n.EMPTY_API),s={editor:null,handler:null},c=()=>{s.editor!==null&&s.handler!==null&&s.editor.off(A,s.handler),s.editor=null,s.handler=null};return(0,e.watch)(()=>i(),e=>{if(c(),r.value+=1,e===null){o.value=n.EMPTY_API;return}let t=()=>{r.value+=1};e.on(A,t),s.editor=e,s.handler=t,o.value=(0,n.createBlocksApiForEditor)(e,a)},{immediate:!0}),(0,e.onScopeDispose)(c),{getById:e=>o.value.getById(e),getChildren:e=>o.value.getChildren(e),insert:e=>o.value.insert(e),insertMany:e=>o.value.insertMany(e),insertTree:e=>o.value.insertTree(e),insertMarkdown:(e,t)=>o.value.insertMarkdown(e,t),exportMarkdown:()=>o.value.exportMarkdown(),move:(e,t)=>o.value.move(e,t),nest:(e,t)=>o.value.nest(e,t),unnest:e=>o.value.unnest(e),remove:e=>o.value.remove(e),update:(e,t,n)=>o.value.update(e,t,n),convert:(e,t,n,r)=>o.value.convert(e,t,n,r),transact:e=>o.value.transact(e),transactWithoutCapture:e=>o.value.transactWithoutCapture(e),getBlocksCount:()=>o.value.getBlocksCount(),getCurrentBlockIndex:()=>o.value.getCurrentBlockIndex(),getBlockByIndex:e=>o.value.getBlockByIndex(e),getBlockByElement:e=>o.value.getBlockByElement(e),getBlockData:e=>o.value.getBlockData(e),getBlockIndex:e=>o.value.getBlockIndex(e),composeBlockData:e=>o.value.composeBlockData(e),renderFromHTML:e=>o.value.renderFromHTML(e),insertOutputData:(e,t)=>o.value.insertOutputData(e,t),splitBlock:(e,t,n,r,i)=>o.value.splitBlock(e,t,n,r,i),insertInsideParent:(e,t,n)=>o.value.insertInsideParent(e,t,n),render:e=>o.value.render(e),clear:()=>o.value.clear(),isSyncingFromYjs:()=>o.value.isSyncingFromYjs()}}function M(n={}){let{within:r,settleOn:i}=n,a=(0,e.shallowRef)(!1),o=()=>{var n;let o=r===void 0||(n=(0,e.toValue)(r))==null?null:n;a.value=r!==void 0&&o===null?!1:t.Blok.readyState({within:o,settleOn:i}).ready};return(0,e.onScopeDispose)(t.Blok.subscribeReady(o)),(0,e.onMounted)(o),a}var N=(0,e.defineComponent)({name:`BlockErrorBoundary`,setup(t,{slots:n}){return(0,e.onErrorCaptured)(()=>!1),()=>{var e;return(e=n.default)==null?void 0:e.call(n)}}}),P=(0,e.defineComponent)({name:`BlockPortalHost`,props:{registry:{type:Object,required:!0}},setup(t){return()=>(0,e.h)(e.Fragment,Array.from(t.registry.entries.entries()).map(([t,n])=>(0,e.h)(e.Teleport,{key:t,to:n.hostEl},[(0,e.h)(N,null,{default:()=>(0,e.h)(n.component,n.props)})])))}}),F=Symbol(`BLOK_EDITOR_INSTANCE`),I=(0,e.shallowRef)(null);function L(){return(0,e.inject)(F,I)}var R=(0,e.defineComponent)({name:`BlokContent`,props:{editor:{type:Object,default:null}},setup(t){let n=(0,e.ref)(null);(0,e.provide)(F,(0,e.computed)(()=>t.editor===null?null:(0,e.toRaw)(t.editor)));let r=t=>{if(n.value===null||t===null)return;let r=l((0,e.toRaw)(t));r!==void 0&&n.value.appendChild(r)},i=t=>{var n;t!==null&&((n=l((0,e.toRaw)(t)))==null||n.remove())};return(0,e.onMounted)(()=>{r(t.editor)}),(0,e.watch)(()=>t.editor,(e,t)=>{i(t==null?null:t),r(e)}),(0,e.onBeforeUnmount)(()=>{i(t.editor)}),()=>{let r=t.editor,i=r===null?void 0:T((0,e.toRaw)(r));return(0,e.h)(`div`,{ref:n},i===void 0?[]:[(0,e.h)(P,{registry:i})])}}}),z=`autofocus.defaultBlock.dataModel.placeholder.sanitizer.hideToolbar.maxHistoryLength.historyDebounceTime.newGroupDelay.globalUndoRedo.tools.data.minHeight.logLevel.readOnly.i18n.link.linkPaste.inlineToolbar.tunes.style.theme.scrollToBlock.user.resolveUser.notifierPosition.notifier.width.onBeforeRender.onBeforePaste.onEnter.onSubmit.onError.migrations.uploader.captureClicksBelowEditor`.split(`.`),B=(0,e.defineComponent)({name:`BlokEditor`,inheritAttrs:!1,props:{autofocus:{type:Boolean,default:void 0},defaultBlock:{type:String,default:void 0},dataModel:{type:String,default:void 0},placeholder:{type:[String,Boolean],default:void 0},sanitizer:{type:Object,default:void 0},hideToolbar:{type:Boolean,default:void 0},maxHistoryLength:{type:Number,default:void 0},historyDebounceTime:{type:Number,default:void 0},newGroupDelay:{type:Number,default:void 0},globalUndoRedo:{type:Boolean,default:void 0},tools:{type:Object,default:void 0},data:{type:Object,default:void 0},minHeight:{type:Number,default:void 0},logLevel:{type:String,default:void 0},readOnly:{type:[Boolean,Object],default:void 0},i18n:{type:Object,default:void 0},link:{type:Object,default:void 0},linkPaste:{type:Object,default:void 0},inlineToolbar:{type:[Array,Boolean],default:void 0},tunes:{type:Array,default:void 0},style:{type:Object,default:void 0},theme:{type:String,default:void 0},scrollToBlock:{type:Object,default:void 0},user:{type:Object,default:void 0},resolveUser:{type:Function,default:void 0},notifierPosition:{type:String,default:void 0},notifier:{type:Function,default:void 0},width:{type:String,default:void 0},onBeforeRender:{type:Function,default:void 0},onBeforePaste:{type:Function,default:void 0},onEnter:{type:Function,default:void 0},onSubmit:{type:Function,default:void 0},onError:{type:Function,default:void 0},migrations:{type:Object,default:void 0},uploader:{type:Object,default:void 0},captureClicksBelowEditor:{type:Boolean,default:void 0},recreateKey:{type:null}},emits:{ready:e=>!0,change:e=>!0,save:e=>!0,"update:data":e=>!0,"after-render":e=>!0,"theme-change":e=>!0,"blocks-rendered":e=>!0,"block-rendered":e=>!0},setup(t,{emit:n,expose:r,attrs:i}){let o=(0,e.getCurrentInstance)(),s=()=>{let e=o==null?void 0:o.vnode.props;return e==null?``:Object.keys(e).filter(e=>e.startsWith(`on`)).sort().join(`|`)},c=(0,e.ref)(s());(0,e.onUpdated)(()=>{c.value=s()});let l=e=>c.value.split(`|`).includes(e),u=()=>{let e={};for(let n of z){let r=t[n];r!==void 0&&(e[n]=r)}return l(`onChange`)&&(e.onChange=(e,t)=>{n(`change`,{api:e,event:t})}),(l(`onSave`)||l(`onUpdate:data`))&&(e.onSave=e=>{n(`update:data`,e),n(`save`,e)}),l(`onAfterRender`)&&(e.onAfterRender=e=>{n(`after-render`,e)}),l(`onThemeChange`)&&(e.onThemeChange=e=>{n(`theme-change`,e)}),e},d=k(()=>u(),()=>t.recreateKey);(0,e.watch)([d,c],([e],t,r)=>{if(e===null)return;let i=[];if(l(`onBlocksRendered`)){let t=e=>n(`blocks-rendered`,e);e.on(`blocks:rendered`,t),i.push([`blocks:rendered`,t])}if(l(`onBlockRendered`)){let t=e=>n(`block-rendered`,e);e.on(`block:rendered`,t),i.push([`block:rendered`,t])}r(()=>{for(let[t,n]of i)e.off(t,n)})});let f={last:null};return(0,e.watch)(d,e=>{e!==null&&e!==f.last&&(f.last=e,n(`ready`,e))}),r({instance:(0,e.computed)(()=>d.value),save:()=>{var e;return(e=d.value)==null?void 0:e.save()},focus:e=>{var t;(t=d.value)==null||t.focus(e)},render:e=>{let t=d.value;if(t!==null)return t.render(e).then(()=>{var n;(n=a(t))==null||n.markRendered(e)})}}),()=>(0,e.h)(R,g({editor:d.value},i))}}),V=[`toolbox`,`isReadOnlySupported`,`__isBlokVueBlock`],H=new Set([void 0,`user`,`api`,`convert`]),U=(e,t,n)=>{let r=new Map;t.forEach((e,t)=>{var i;let a=[];for(let[r,o]of Object.entries((i=n==null?void 0:n(e,t))==null?{}:i)){if(o==null){e.holder.removeAttribute(r);continue}e.holder.setAttribute(r,String(o)),a.push(r)}r.set(e.id,{holder:e.holder,names:a})});for(let[t,n]of e){let e=r.get(t);n.names.filter(t=>e===void 0||!e.names.includes(t)).forEach(e=>n.holder.removeAttribute(e))}e.clear(),r.forEach((t,n)=>e.set(n,t))},W=(e,t,r)=>{var i;e==null||(i=e.events)==null||i.emit(n.BlockChildrenMounted,{blockId:t,childIds:r.map(e=>e.id)})};function G(t){var r,i;let a=()=>(0,e.defineComponent)({name:`VueBlock(${t.type})`,props:{ctx:{type:Object,required:!0},notifyMounted:{type:Function,default:void 0}},setup(n){return(0,e.onMounted)(()=>{var e;return(e=n.notifyMounted)==null?void 0:e.call(n)}),t.setup(n.ctx)}}),o=(r=class{static get toolbox(){return t.toolbox}static get isReadOnlySupported(){return!0}constructor(r){var i,o,s;this.wrappedComponent=a(),this.mountSignalled=!1,this.hostEl=null,this.pendingDispatch=!1,this.notifyMounted=()=>{var e;if(this.mountSignalled)return;this.mountSignalled=!0;let n={origin:this.origin,api:this.api};if((e=t.onMounted)==null||e.call(t,this.blockApi,n),H.has(this.origin)){var r;(r=t.onCreated)==null||r.call(t,this.blockApi,n)}},this.commit=e=>{let r=(0,n.fillDefaults)(t.propSchema,g(g({},this.mirror),e));(0,n.deepEqual)(r,this.mirror)||(this.mirror=r,this.lastRendered=r,this.dataRef.value=r,this.flushDispatch())},this.blockApi=r.block;let c=(i=r.config)==null?{}:i;this.registry=c[x],this.api=r.api;let l=r.api;this.pointerDrag=()=>{var e;return(l==null||(e=l.blocks)==null?void 0:e.isPointerDragActive)===!0},this.mirror=(0,n.fillDefaults)(t.propSchema,(0,e.toRaw)((o=r.data)==null?{}:o)),this.lastRendered=this.mirror,this.dataRef=(0,e.shallowRef)(this.mirror),this.readOnlyRef=(0,e.shallowRef)(r.readOnly),this.origin=(s=r.origin)==null?`api`:s;let u=this.blockApi,d=this.api;this.childrenComponent=(0,e.defineComponent)({name:`VueBlockChildren(${t.type})`,props:{childAttributes:{type:Function,default:void 0}},setup(t){let r=(0,e.ref)(null),i=new Map,a=()=>{if(r.value===null)return;let e=u.getChildren();(0,n.mountChildBlocks)(r.value,e),U(i,e,t.childAttributes),W(d,u.id,e)};return(0,e.onMounted)(a),(0,e.onUpdated)(a),()=>(0,e.h)(`div`,{ref:r,[n.DATA_ATTR.nestedBlocks]:``})}})}render(){var e;let t=document.createElement(`div`);t.setAttribute(`data-blok-mutation-free`,`true`),this.hostEl=t;let n={data:this.dataRef,commit:this.commit,block:this.blockApi,api:this.api,readOnly:this.readOnlyRef,BlockChildren:this.childrenComponent};return(e=this.registry)==null||e.register(this.blockApi.id,{hostEl:t,component:this.wrappedComponent,props:{ctx:n,notifyMounted:this.notifyMounted}}),t}rendered(){var e;(e=t.onRendered)==null||e.call(t,this.blockApi)}save(){return this.mirror}async setData(r){var i=this;let a=(0,n.fillDefaults)(t.propSchema,(0,e.toRaw)(r==null?{}:r));return(0,n.deepEqual)(a,i.lastRendered)?!0:(i.mirror=a,i.lastRendered=a,i.dataRef.value=a,await(0,e.nextTick)(),!0)}setReadOnly(e){this.readOnlyRef.value=e}getToolbarAnchorElement(){var e;let n=this.hostEl;if(!(n===null||t.getToolbarAnchorElement===void 0))return(e=t.getToolbarAnchorElement(n,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)}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)}},r.__isBlokVueBlock=!0,r);for(let[e,n]of Object.entries((i=t.statics)==null?{}:i))V.includes(e)||Object.defineProperty(o,e,{value:n,writable:!0,enumerable:!0,configurable:!0});return o}exports.BLOK_DEFAULT_CONFIG=_,exports.BLOK_EDITOR_INSTANCE=F,exports.BlokContent=R,exports.BlokEditor=B,exports.createVueBlock=G,exports.provideBlok=v,exports.useBlocks=j,exports.useBlok=k,exports.useBlokDefaults=y,exports.useBlokInstance=L,exports.useBlokReady=M;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("vue"),t=require("@bloklabs/core"),n=require("@bloklabs/core/adapters");var r=new WeakMap;function i(e,t){r.set(e,t)}function a(e){return r.get(e)}function o(e){r.delete(e)}var s=new WeakMap;function c(e,t){s.set(e,t)}function l(e){return s.get(e)}function u(e){s.delete(e)}function d(e){"@babel/helpers - typeof";return d=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},d(e)}function f(e,t){if(d(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(d(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function p(e){var t=f(e,`string`);return d(t)==`symbol`?t:t+``}function m(e,t,n){return(t=p(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(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 g(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?h(Object(n),!0).forEach(function(t){m(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):h(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var _=Symbol(`BLOK_DEFAULT_CONFIG`);function v(t){(0,e.provide)(_,t)}function y(){return(0,e.inject)(_,{})}function b(e,t){if(Object.keys(e).length===0)return t;let n=g({},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=g(g({},e.tools),t.tools)),n}var x=`__blokPortalRegistry`,S=()=>{let t=(0,e.reactive)(new Map);return{entries:t,register(n,r){t.set(n,(0,e.markRaw)(r))},unregister(e,n){var r;n!==void 0&&((r=t.get(e))==null?void 0:r.hostEl)!==n||t.delete(e)},setProps(e,n){let r=t.get(e);r!==void 0&&Object.assign(r.props,n)}}},C=new WeakMap;function w(e,t){C.set(e,t)}function T(e){return C.get(e)}function E(e){C.delete(e)}var D=e=>({onChange:e.onChange!==void 0,onSave:e.onSave!==void 0,onEnter:e.onEnter!==void 0,onSubmit:e.onSubmit!==void 0,onBeforeRender:e.onBeforeRender!==void 0,onAfterRender:e.onAfterRender!==void 0}),O=(e,t)=>{if(typeof e!=`object`||!e)return e;let n={};for(let[i,a]of Object.entries(e)){var r;let e=typeof a==`function`?a:a==null?void 0:a.class;if(!(typeof e==`function`&&e.__isBlokVueBlock===!0)){n[i]=a;continue}let o=typeof a==`function`?{class:a}:g({},a);o.config=g(g({},(r=o.config)==null?{}:r),{},{[x]:t}),n[i]=o}return n};function k(r,a){let s=(0,e.shallowRef)(null),l=(0,e.inject)(_,{}),d=()=>b(l,(0,e.toValue)(r)),f={current:null,holder:null,lastRenderedData:d().data,seededEditor:null,renderChain:Promise.resolve(),appliedHandlerPresence:{onChange:!1,onSave:!1,onEnter:!1,onSubmit:!1,onBeforeRender:!1,onAfterRender:!1}},p={onChange:(...e)=>{var t,n;(t=(n=d()).onChange)==null||t.call(n,...e)},onSave:(...e)=>{var t,n;f.lastRenderedData=e[0],(t=(n=d()).onSave)==null||t.call(n,...e)},onEnter:(...e)=>{var t,n;return(t=(n=d()).onEnter)==null?void 0:t.call(n,...e)},onSubmit:(...e)=>{var t,n;(t=(n=d()).onSubmit)==null||t.call(n,...e)},onBeforeRender:(...e)=>{var t,n,r;return(t=(n=(r=d()).onBeforeRender)==null?void 0:n.call(r,...e))==null?e[0]:t},onAfterRender:(...e)=>{var t,n;(t=(n=d()).onAfterRender)==null||t.call(n,...e)}},m=()=>{let t=g({},b((0,e.toRaw)(l),(0,e.toRaw)((0,e.toValue)(r))));return delete t.holder,t.data!==void 0&&(t.data=(0,e.toRaw)(t.data)),t},h=()=>{if(f.current!==null){u(f.current),E(f.current),o(f.current);try{f.current.destroy()}catch(e){}}f.current=null,f.holder=null,s.value=null},v=()=>{let e=document.createElement(`div`);f.holder=e;let n=m(),r=S();n.tools!==void 0&&(n.tools=O(n.tools,r));let a=D(d());n.onChange=a.onChange?p.onChange:void 0,n.onSave=a.onSave?p.onSave:void 0,n.onEnter=a.onEnter?p.onEnter:void 0,n.onSubmit=a.onSubmit?p.onSubmit:void 0,n.onBeforeRender=a.onBeforeRender?p.onBeforeRender:void 0,n.onAfterRender=a.onAfterRender?p.onAfterRender:void 0,f.appliedHandlerPresence=a;let o=new t.Blok(g(g({},n),{},{holder:e}));f.current=o,c(o,e),w(o,r),i(o,{markRendered:e=>{f.lastRenderedData=e}}),o.isReady.then(()=>{f.current===o&&(s.value=o)}).catch(()=>{f.current===o&&h()})};(0,e.watch)([s,()=>(0,n.normalizeReadOnlyConfig)(d().readOnly).enabled,()=>(0,n.normalizeReadOnlyConfig)(d().readOnly).hideControls,()=>typeof d().readOnly==`object`],([e,t,n,r])=>{e&&(r?e.readOnly.set(t,{hideControls:n}):e.readOnly.set(t))},{immediate:!0}),(0,e.watch)([s,()=>d().hideToolbar],([e,t])=>{e&&e.toolbar.setHidden(!!t)},{immediate:!0}),(0,e.watch)([s,()=>d().theme],([e,t])=>{e&&t!==void 0&&e.theme.set(t)},{immediate:!0}),(0,e.watch)([s,()=>d().width],([e,t])=>{e&&t!==void 0&&e.width.set(t)},{immediate:!0}),(0,e.watch)([s,()=>d().placeholder],([e,t])=>{e&&t!==void 0&&e.placeholder.set(t)},{immediate:!0});let y={value:void 0};(0,e.watch)([s,()=>{var e;return(e=d().style)==null?void 0:e.tokens}],([e,t])=>{!e||t===void 0||(0,n.deepEqual)(t,y.value)||(y.value=g({},t),e.tokens.set(t))},{immediate:!0,deep:!0});let x={value:d().i18n};(0,e.watch)([s,()=>d().i18n],([e,t])=>{if(!e||t===void 0||(0,n.deepEqual)(t,x.value))return;x.value=g({},t);let{locale:r,messages:i,direction:a}=t;e.i18n.update(g(g(g({},r===void 0?{}:{locale:r}),i===void 0?{}:{messages:i}),a===void 0?{}:{direction:a}))},{immediate:!0,deep:!0});let C={editor:null,value:void 0};return(0,e.watch)([s,()=>d().inlineToolbar],([e,t])=>{if(!e||t===void 0||C.editor===e&&(0,n.deepEqual)(t,C.value))return;let r=Array.isArray(t)?[...t]:t;C.editor=e,C.value=r,e.tools.setInlineToolbar(r)},{immediate:!0,deep:!0}),(0,e.watch)([s,()=>d().autofocus],([e,t])=>{e&&t&&e.focus()},{immediate:!0}),(0,e.watch)([s,()=>JSON.stringify(D(d()))],([e])=>{if(!e)return;let t=D(d()),n=f.appliedHandlerPresence,r={},i={value:!1},a=(e,r)=>{t[e]!==n[e]&&(n[e]=t[e],i.value=!0,r(t[e]?p[e]:void 0))};a(`onChange`,e=>{r.onChange=e}),a(`onSave`,e=>{r.onSave=e}),a(`onEnter`,e=>{r.onEnter=e}),a(`onSubmit`,e=>{r.onSubmit=e}),a(`onBeforeRender`,e=>{r.onBeforeRender=e}),a(`onAfterRender`,e=>{r.onAfterRender=e}),i.value&&e.handlers.set(r)},{immediate:!0}),(0,e.watch)([s,()=>d().data],([t,r])=>{if(!t||r===void 0)return;if(f.seededEditor!==t){f.seededEditor=t,f.lastRenderedData=r;return}let i=f.lastRenderedData;i!==void 0&&(0,n.equalsOutputData)(r,i)||(f.lastRenderedData=r,f.renderChain=f.renderChain.catch(()=>void 0).then(()=>t.render((0,n.toRenderableData)((0,e.toRaw)(r)))))},{immediate:!0}),a!==void 0&&(0,e.watch)(()=>(0,e.toValue)(a),()=>{h(),v()}),(0,e.onMounted)(v),(0,e.onBeforeUnmount)(h),s}var A=`block changed`;function j(t,r={}){let i=(0,e.shallowRef)(0),a=()=>{let n=(0,e.toValue)(t);return n===null?null:(0,e.toRaw)(n)},o=()=>{i.value},s=(0,e.shallowRef)(n.EMPTY_API),c={editor:null,handler:null},l=()=>{c.editor!==null&&c.handler!==null&&c.editor.off(A,c.handler),c.editor=null,c.handler=null};return(0,e.watch)(()=>a(),t=>{if(l(),i.value+=1,t===null){s.value=n.EMPTY_API;return}let a=a=>{var o;let s=(o=(0,e.toValue)(r.within))==null?null:o;s!==null&&!(0,n.changeTouchesSubtree)(t,a,s)||(i.value+=1)};t.on(A,a),c.editor=t,c.handler=a,s.value=(0,n.createBlocksApiForEditor)(t,o)},{immediate:!0}),(0,e.onScopeDispose)(l),{getById:e=>s.value.getById(e),getChildren:e=>s.value.getChildren(e),insert:e=>s.value.insert(e),insertMany:e=>s.value.insertMany(e),insertTree:e=>s.value.insertTree(e),insertMarkdown:(e,t)=>s.value.insertMarkdown(e,t),exportMarkdown:()=>s.value.exportMarkdown(),move:(e,t)=>s.value.move(e,t),nest:(e,t)=>s.value.nest(e,t),unnest:e=>s.value.unnest(e),remove:e=>s.value.remove(e),update:(e,t,n)=>s.value.update(e,t,n),convert:(e,t,n,r)=>s.value.convert(e,t,n,r),transact:e=>s.value.transact(e),transactWithoutCapture:e=>s.value.transactWithoutCapture(e),getBlocksCount:()=>s.value.getBlocksCount(),getCurrentBlockIndex:()=>s.value.getCurrentBlockIndex(),getBlockByIndex:e=>s.value.getBlockByIndex(e),getBlockByElement:e=>s.value.getBlockByElement(e),getBlockData:e=>s.value.getBlockData(e),getBlockIndex:e=>s.value.getBlockIndex(e),composeBlockData:e=>s.value.composeBlockData(e),renderFromHTML:e=>s.value.renderFromHTML(e),insertOutputData:(e,t)=>s.value.insertOutputData(e,t),splitBlock:(e,t,n,r,i)=>s.value.splitBlock(e,t,n,r,i),insertInsideParent:(e,t,n)=>s.value.insertInsideParent(e,t,n),render:e=>s.value.render(e),clear:()=>s.value.clear(),isSyncingFromYjs:()=>s.value.isSyncingFromYjs()}}function M(n={}){let{within:r,settleOn:i}=n,a=(0,e.shallowRef)(!1),o=()=>{var n;let o=r===void 0||(n=(0,e.toValue)(r))==null?null:n;a.value=r!==void 0&&o===null?!1:t.Blok.readyState({within:o,settleOn:i}).ready};return(0,e.onScopeDispose)(t.Blok.subscribeReady(o)),(0,e.onMounted)(o),a}var N=(0,e.defineComponent)({name:`BlockErrorBoundary`,setup(t,{slots:n}){return(0,e.onErrorCaptured)(()=>!1),()=>{var e;return(e=n.default)==null?void 0:e.call(n)}}}),P=(0,e.defineComponent)({name:`BlockPortalHost`,props:{registry:{type:Object,required:!0}},setup(t){return()=>(0,e.h)(e.Fragment,Array.from(t.registry.entries.entries()).map(([t,n])=>(0,e.h)(e.Teleport,{key:t,to:n.hostEl},[(0,e.h)(N,null,{default:()=>(0,e.h)(n.component,n.props)})])))}}),F=Symbol(`BLOK_EDITOR_INSTANCE`),I=(0,e.shallowRef)(null);function L(){return(0,e.inject)(F,I)}var R=(0,e.defineComponent)({name:`BlokContent`,props:{editor:{type:Object,default:null}},setup(t){let n=(0,e.ref)(null);(0,e.provide)(F,(0,e.computed)(()=>t.editor===null?null:(0,e.toRaw)(t.editor)));let r=t=>{if(n.value===null||t===null)return;let r=l((0,e.toRaw)(t));r!==void 0&&n.value.appendChild(r)},i=t=>{var n;t!==null&&((n=l((0,e.toRaw)(t)))==null||n.remove())};return(0,e.onMounted)(()=>{r(t.editor)}),(0,e.watch)(()=>t.editor,(e,t)=>{i(t==null?null:t),r(e)}),(0,e.onBeforeUnmount)(()=>{i(t.editor)}),()=>{let r=t.editor,i=r===null?void 0:T((0,e.toRaw)(r));return(0,e.h)(`div`,{ref:n},i===void 0?[]:[(0,e.h)(P,{registry:i})])}}}),z=`autofocus.defaultBlock.dataModel.placeholder.sanitizer.hideToolbar.maxHistoryLength.historyDebounceTime.newGroupDelay.globalUndoRedo.tools.data.minHeight.logLevel.readOnly.i18n.link.linkPaste.inlineToolbar.tunes.style.theme.scrollToBlock.user.resolveUser.notifierPosition.notifier.width.onBeforeRender.onBeforePaste.onEnter.onSubmit.onError.migrations.uploader.captureClicksBelowEditor`.split(`.`),B=(0,e.defineComponent)({name:`BlokEditor`,inheritAttrs:!1,props:{autofocus:{type:Boolean,default:void 0},defaultBlock:{type:String,default:void 0},dataModel:{type:String,default:void 0},placeholder:{type:[String,Boolean],default:void 0},sanitizer:{type:Object,default:void 0},hideToolbar:{type:Boolean,default:void 0},maxHistoryLength:{type:Number,default:void 0},historyDebounceTime:{type:Number,default:void 0},newGroupDelay:{type:Number,default:void 0},globalUndoRedo:{type:Boolean,default:void 0},tools:{type:Object,default:void 0},data:{type:Object,default:void 0},minHeight:{type:Number,default:void 0},logLevel:{type:String,default:void 0},readOnly:{type:[Boolean,Object],default:void 0},i18n:{type:Object,default:void 0},link:{type:Object,default:void 0},linkPaste:{type:Object,default:void 0},inlineToolbar:{type:[Array,Boolean],default:void 0},tunes:{type:Array,default:void 0},style:{type:Object,default:void 0},theme:{type:String,default:void 0},scrollToBlock:{type:Object,default:void 0},user:{type:Object,default:void 0},resolveUser:{type:Function,default:void 0},notifierPosition:{type:String,default:void 0},notifier:{type:Function,default:void 0},width:{type:String,default:void 0},onBeforeRender:{type:Function,default:void 0},onBeforePaste:{type:Function,default:void 0},onEnter:{type:Function,default:void 0},onSubmit:{type:Function,default:void 0},onError:{type:Function,default:void 0},migrations:{type:Object,default:void 0},uploader:{type:Object,default:void 0},captureClicksBelowEditor:{type:Boolean,default:void 0},recreateKey:{type:null}},emits:{ready:e=>!0,change:e=>!0,save:e=>!0,"update:data":e=>!0,"after-render":e=>!0,"theme-change":e=>!0,"blocks-rendered":e=>!0,"block-rendered":e=>!0},setup(t,{emit:n,expose:r,attrs:i}){let o=(0,e.getCurrentInstance)(),s=()=>{let e=o==null?void 0:o.vnode.props;return e==null?``:Object.keys(e).filter(e=>e.startsWith(`on`)).sort().join(`|`)},c=(0,e.ref)(s());(0,e.onUpdated)(()=>{c.value=s()});let l=e=>c.value.split(`|`).includes(e),u=()=>{let e={};for(let n of z){let r=t[n];r!==void 0&&(e[n]=r)}return l(`onChange`)&&(e.onChange=(e,t)=>{n(`change`,{api:e,event:t})}),(l(`onSave`)||l(`onUpdate:data`))&&(e.onSave=e=>{n(`update:data`,e),n(`save`,e)}),l(`onAfterRender`)&&(e.onAfterRender=e=>{n(`after-render`,e)}),l(`onThemeChange`)&&(e.onThemeChange=e=>{n(`theme-change`,e)}),e},d=k(()=>u(),()=>t.recreateKey);(0,e.watch)([d,c],([e],t,r)=>{if(e===null)return;let i=[];if(l(`onBlocksRendered`)){let t=e=>n(`blocks-rendered`,e);e.on(`blocks:rendered`,t),i.push([`blocks:rendered`,t])}if(l(`onBlockRendered`)){let t=e=>n(`block-rendered`,e);e.on(`block:rendered`,t),i.push([`block:rendered`,t])}r(()=>{for(let[t,n]of i)e.off(t,n)})});let f={last:null};return(0,e.watch)(d,e=>{e!==null&&e!==f.last&&(f.last=e,n(`ready`,e))}),r({instance:(0,e.computed)(()=>d.value),save:()=>{var e;return(e=d.value)==null?void 0:e.save()},focus:e=>{var t;(t=d.value)==null||t.focus(e)},render:e=>{let t=d.value;if(t!==null)return t.render(e).then(()=>{var n;(n=a(t))==null||n.markRendered(e)})}}),()=>(0,e.h)(R,g({editor:d.value},i))}}),V=[`toolbox`,`isReadOnlySupported`,`__isBlokVueBlock`],H=new Set([void 0,`user`,`api`,`convert`]),U=(e,t,r)=>{var i;e==null||(i=e.events)==null||i.emit(n.BlockChildrenMounted,{blockId:t,childIds:r.map(e=>e.id)})};function W(t){var r,i;let a=()=>(0,e.defineComponent)({name:`VueBlock(${t.type})`,props:{ctx:{type:Object,required:!0},notifyMounted:{type:Function,default:void 0}},setup(n){return(0,e.onMounted)(()=>{var e;return(e=n.notifyMounted)==null?void 0:e.call(n)}),t.setup(n.ctx)}}),o=(r=class{static get toolbox(){return t.toolbox}static get isReadOnlySupported(){return!0}constructor(r){var i,o,s;this.wrappedComponent=a(),this.mountSignalled=!1,this.hostEl=null,this.pendingDispatch=!1,this.anchorEl=null,this.toolbarAnchorRef=e=>{let t=e===null||e instanceof Element?e:e.$el;this.anchorEl=t instanceof HTMLElement?t:null},this.notifyMounted=()=>{var e;if(this.mountSignalled)return;this.mountSignalled=!0;let n={origin:this.origin,api:this.api};if((e=t.onMounted)==null||e.call(t,this.blockApi,n),H.has(this.origin)){var r;(r=t.onCreated)==null||r.call(t,this.blockApi,n)}},this.commit=e=>{let r=(0,n.fillDefaults)(t.propSchema,g(g({},this.mirror),e));(0,n.deepEqual)(r,this.mirror)||(this.mirror=r,this.lastRendered=r,this.dataRef.value=r,this.flushDispatch())},this.blockApi=r.block;let c=(i=r.config)==null?{}:i;this.registry=c[x],this.api=r.api;let l=r.api;this.pointerDrag=()=>{var e;return(l==null||(e=l.blocks)==null?void 0:e.isPointerDragActive)===!0},this.mirror=(0,n.fillDefaults)(t.propSchema,(0,e.toRaw)((o=r.data)==null?{}:o)),this.lastRendered=this.mirror,this.dataRef=(0,e.shallowRef)(this.mirror),this.readOnlyRef=(0,e.shallowRef)(r.readOnly),this.origin=(s=r.origin)==null?`api`:s;let u=this.blockApi,d=this.api;this.childrenComponent=(0,e.defineComponent)({name:`VueBlockChildren(${t.type})`,props:{childAttributes:{type:Function,default:void 0},childContentAttributes:{type:Function,default:void 0}},setup(t){let r=(0,e.ref)(null),i=(0,n.createChildDecorationLedger)(),a=()=>{if(r.value===null)return;let e=u.getChildren();(0,n.mountChildBlocks)(r.value,e),(0,n.applyChildDecoration)(i,e,{childAttributes:t.childAttributes,childContentAttributes:t.childContentAttributes}),U(d,u.id,e)};return(0,e.onMounted)(a),(0,e.onUpdated)(a),()=>(0,e.h)(`div`,{ref:r,[n.DATA_ATTR.nestedBlocks]:``})}})}render(){var e;let t=document.createElement(`div`);t.setAttribute(`data-blok-mutation-free`,`true`),this.hostEl=t;let n={data:this.dataRef,commit:this.commit,block:this.blockApi,api:this.api,readOnly:this.readOnlyRef,BlockChildren:this.childrenComponent,toolbarAnchorRef:this.toolbarAnchorRef};return(e=this.registry)==null||e.register(this.blockApi.id,{hostEl:t,component:this.wrappedComponent,props:{ctx:n,notifyMounted:this.notifyMounted}}),t}rendered(){var e;(e=t.onRendered)==null||e.call(t,this.blockApi)}save(){return this.mirror}async setData(r){var i=this;let a=(0,n.fillDefaults)(t.propSchema,(0,e.toRaw)(r==null?{}:r));return(0,n.deepEqual)(a,i.lastRendered)?!0:(i.mirror=a,i.lastRendered=a,i.dataRef.value=a,await(0,e.nextTick)(),!0)}setReadOnly(e){this.readOnlyRef.value=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)}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)}},r.__isBlokVueBlock=!0,r);for(let[e,n]of Object.entries((i=t.statics)==null?{}:i))V.includes(e)||Object.defineProperty(o,e,{value:n,writable:!0,enumerable:!0,configurable:!0});return o}exports.BLOK_DEFAULT_CONFIG=_,exports.BLOK_EDITOR_INSTANCE=F,exports.BlokContent=R,exports.BlokEditor=B,exports.createVueBlock=W,exports.provideBlok=v,exports.useBlocks=j,exports.useBlok=k,exports.useBlokDefaults=y,exports.useBlokInstance=L,exports.useBlokReady=M;
package/dist/index.mjs CHANGED
@@ -1,61 +1,61 @@
1
1
  import { Fragment as e, Teleport as t, computed as n, defineComponent as r, getCurrentInstance as i, h as a, inject as o, markRaw as s, nextTick as c, onBeforeUnmount as l, onErrorCaptured as u, onMounted as d, onScopeDispose as f, onUpdated as p, provide as m, reactive as h, ref as g, shallowRef as _, toRaw as v, toValue as y, watch as b } from "vue";
2
2
  import { Blok as x } from "@bloklabs/core";
3
- import { BlockChildrenMounted as ee, DATA_ATTR as S, EMPTY_API as C, createBlocksApiForEditor as w, deepEqual as T, equalsOutputData as te, fillDefaults as E, mountChildBlocks as D, normalizeReadOnlyConfig as O, toRenderableData as ne } from "@bloklabs/core/adapters";
3
+ import { BlockChildrenMounted as ee, DATA_ATTR as te, EMPTY_API as S, applyChildDecoration as C, changeTouchesSubtree as w, createBlocksApiForEditor as T, createChildDecorationLedger as E, deepEqual as D, equalsOutputData as ne, fillDefaults as O, mountChildBlocks as re, normalizeReadOnlyConfig as k, toRenderableData as ie } from "@bloklabs/core/adapters";
4
4
  //#region src/content-baseline-map.ts
5
- var k = /* @__PURE__ */ new WeakMap();
6
- function A(e, t) {
7
- k.set(e, t);
8
- }
9
- function re(e) {
10
- return k.get(e);
5
+ var A = /* @__PURE__ */ new WeakMap();
6
+ function ae(e, t) {
7
+ A.set(e, t);
11
8
  }
12
9
  function j(e) {
13
- k.delete(e);
10
+ return A.get(e);
11
+ }
12
+ function M(e) {
13
+ A.delete(e);
14
14
  }
15
15
  //#endregion
16
16
  //#region src/holder-map.ts
17
- var M = /* @__PURE__ */ new WeakMap();
18
- function N(e, t) {
19
- M.set(e, t);
17
+ var N = /* @__PURE__ */ new WeakMap();
18
+ function oe(e, t) {
19
+ N.set(e, t);
20
20
  }
21
21
  function P(e) {
22
- return M.get(e);
22
+ return N.get(e);
23
23
  }
24
- function F(e) {
25
- M.delete(e);
24
+ function se(e) {
25
+ N.delete(e);
26
26
  }
27
27
  //#endregion
28
28
  //#region \0@oxc-project+runtime@0.139.0/helpers/esm/typeof.js
29
- function I(e) {
29
+ function F(e) {
30
30
  "@babel/helpers - typeof";
31
- return I = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
31
+ return F = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
32
32
  return typeof e;
33
33
  } : function(e) {
34
34
  return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
35
- }, I(e);
35
+ }, F(e);
36
36
  }
37
37
  //#endregion
38
38
  //#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPrimitive.js
39
- function ie(e, t) {
40
- if (I(e) != "object" || !e) return e;
39
+ function I(e, t) {
40
+ if (F(e) != "object" || !e) return e;
41
41
  var n = e[Symbol.toPrimitive];
42
42
  if (n !== void 0) {
43
43
  var r = n.call(e, t || "default");
44
- if (I(r) != "object") return r;
44
+ if (F(r) != "object") return r;
45
45
  throw TypeError("@@toPrimitive must return a primitive value.");
46
46
  }
47
47
  return (t === "string" ? String : Number)(e);
48
48
  }
49
49
  //#endregion
50
50
  //#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPropertyKey.js
51
- function ae(e) {
52
- var t = ie(e, "string");
53
- return I(t) == "symbol" ? t : t + "";
51
+ function L(e) {
52
+ var t = I(e, "string");
53
+ return F(t) == "symbol" ? t : t + "";
54
54
  }
55
55
  //#endregion
56
56
  //#region \0@oxc-project+runtime@0.139.0/helpers/esm/defineProperty.js
57
- function L(e, t, n) {
58
- return (t = ae(t)) in e ? Object.defineProperty(e, t, {
57
+ function R(e, t, n) {
58
+ return (t = L(t)) in e ? Object.defineProperty(e, t, {
59
59
  value: n,
60
60
  enumerable: !0,
61
61
  configurable: !0,
@@ -64,7 +64,7 @@ function L(e, t, n) {
64
64
  }
65
65
  //#endregion
66
66
  //#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectSpread2.js
67
- function R(e, t) {
67
+ function z(e, t) {
68
68
  var n = Object.keys(e);
69
69
  if (Object.getOwnPropertySymbols) {
70
70
  var r = Object.getOwnPropertySymbols(e);
@@ -74,12 +74,12 @@ function R(e, t) {
74
74
  }
75
75
  return n;
76
76
  }
77
- function z(e) {
77
+ function B(e) {
78
78
  for (var t = 1; t < arguments.length; t++) {
79
79
  var n = arguments[t] == null ? {} : arguments[t];
80
- t % 2 ? R(Object(n), !0).forEach(function(t) {
81
- L(e, t, n[t]);
82
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : R(Object(n)).forEach(function(t) {
80
+ t % 2 ? z(Object(n), !0).forEach(function(t) {
81
+ R(e, t, n[t]);
82
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : z(Object(n)).forEach(function(t) {
83
83
  Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t));
84
84
  });
85
85
  }
@@ -87,25 +87,25 @@ function z(e) {
87
87
  }
88
88
  //#endregion
89
89
  //#region src/provide-blok.ts
90
- var B = Symbol("BLOK_DEFAULT_CONFIG");
91
- function V(e) {
92
- m(B, e);
90
+ var V = Symbol("BLOK_DEFAULT_CONFIG");
91
+ function H(e) {
92
+ m(V, e);
93
93
  }
94
- function H() {
95
- return o(B, {});
94
+ function U() {
95
+ return o(V, {});
96
96
  }
97
- function U(e, t) {
97
+ function W(e, t) {
98
98
  if (Object.keys(e).length === 0) return t;
99
- let n = z({}, e);
99
+ let n = B({}, e);
100
100
  for (let e of Object.keys(t)) {
101
101
  let r = t[e];
102
102
  r !== void 0 && (n[e] = r);
103
103
  }
104
- return (e.tools !== void 0 || t.tools !== void 0) && (n.tools = z(z({}, e.tools), t.tools)), n;
104
+ return (e.tools !== void 0 || t.tools !== void 0) && (n.tools = B(B({}, e.tools), t.tools)), n;
105
105
  }
106
106
  //#endregion
107
107
  //#region src/block-portal-registry.ts
108
- var W = "__blokPortalRegistry", G = () => {
108
+ var G = "__blokPortalRegistry", K = () => {
109
109
  let e = h(/* @__PURE__ */ new Map());
110
110
  return {
111
111
  entries: e,
@@ -121,15 +121,15 @@ var W = "__blokPortalRegistry", G = () => {
121
121
  r !== void 0 && Object.assign(r.props, n);
122
122
  }
123
123
  };
124
- }, K = /* @__PURE__ */ new WeakMap();
125
- function q(e, t) {
126
- K.set(e, t);
124
+ }, q = /* @__PURE__ */ new WeakMap();
125
+ function ce(e, t) {
126
+ q.set(e, t);
127
127
  }
128
128
  function J(e) {
129
- return K.get(e);
129
+ return q.get(e);
130
130
  }
131
- function oe(e) {
132
- K.delete(e);
131
+ function le(e) {
132
+ q.delete(e);
133
133
  }
134
134
  //#endregion
135
135
  //#region src/useBlok.ts
@@ -140,7 +140,7 @@ var Y = (e) => ({
140
140
  onSubmit: e.onSubmit !== void 0,
141
141
  onBeforeRender: e.onBeforeRender !== void 0,
142
142
  onAfterRender: e.onAfterRender !== void 0
143
- }), se = (e, t) => {
143
+ }), ue = (e, t) => {
144
144
  if (typeof e != "object" || !e) return e;
145
145
  let n = {};
146
146
  for (let [i, a] of Object.entries(e)) {
@@ -150,13 +150,13 @@ var Y = (e) => ({
150
150
  n[i] = a;
151
151
  continue;
152
152
  }
153
- let o = typeof a == "function" ? { class: a } : z({}, a);
154
- o.config = z(z({}, (r = o.config) == null ? {} : r), {}, { [W]: t }), n[i] = o;
153
+ let o = typeof a == "function" ? { class: a } : B({}, a);
154
+ o.config = B(B({}, (r = o.config) == null ? {} : r), {}, { [G]: t }), n[i] = o;
155
155
  }
156
156
  return n;
157
157
  };
158
158
  function X(e, t) {
159
- let n = _(null), r = o(B, {}), i = () => U(r, y(e)), a = {
159
+ let n = _(null), r = o(V, {}), i = () => W(r, y(e)), a = {
160
160
  current: null,
161
161
  holder: null,
162
162
  lastRenderedData: i().data,
@@ -196,11 +196,11 @@ function X(e, t) {
196
196
  (t = (n = i()).onAfterRender) == null || t.call(n, ...e);
197
197
  }
198
198
  }, c = () => {
199
- let t = z({}, U(v(r), v(y(e))));
199
+ let t = B({}, W(v(r), v(y(e))));
200
200
  return delete t.holder, t.data !== void 0 && (t.data = v(t.data)), t;
201
201
  }, u = () => {
202
202
  if (a.current !== null) {
203
- F(a.current), oe(a.current), j(a.current);
203
+ se(a.current), le(a.current), M(a.current);
204
204
  try {
205
205
  a.current.destroy();
206
206
  } catch (e) {}
@@ -209,12 +209,12 @@ function X(e, t) {
209
209
  }, f = () => {
210
210
  let e = document.createElement("div");
211
211
  a.holder = e;
212
- let t = c(), r = G();
213
- t.tools !== void 0 && (t.tools = se(t.tools, r));
212
+ let t = c(), r = K();
213
+ t.tools !== void 0 && (t.tools = ue(t.tools, r));
214
214
  let o = Y(i());
215
215
  t.onChange = o.onChange ? s.onChange : void 0, t.onSave = o.onSave ? s.onSave : void 0, t.onEnter = o.onEnter ? s.onEnter : void 0, t.onSubmit = o.onSubmit ? s.onSubmit : void 0, t.onBeforeRender = o.onBeforeRender ? s.onBeforeRender : void 0, t.onAfterRender = o.onAfterRender ? s.onAfterRender : void 0, a.appliedHandlerPresence = o;
216
- let l = new x(z(z({}, t), {}, { holder: e }));
217
- a.current = l, N(l, e), q(l, r), A(l, { markRendered: (e) => {
216
+ let l = new x(B(B({}, t), {}, { holder: e }));
217
+ a.current = l, oe(l, e), ce(l, r), ae(l, { markRendered: (e) => {
218
218
  a.lastRenderedData = e;
219
219
  } }), l.isReady.then(() => {
220
220
  a.current === l && (n.value = l);
@@ -224,8 +224,8 @@ function X(e, t) {
224
224
  };
225
225
  b([
226
226
  n,
227
- () => O(i().readOnly).enabled,
228
- () => O(i().readOnly).hideControls,
227
+ () => k(i().readOnly).enabled,
228
+ () => k(i().readOnly).hideControls,
229
229
  () => typeof i().readOnly == "object"
230
230
  ], ([e, t, n, r]) => {
231
231
  e && (r ? e.readOnly.set(t, { hideControls: n }) : e.readOnly.set(t));
@@ -243,17 +243,17 @@ function X(e, t) {
243
243
  var e;
244
244
  return (e = i().style) == null ? void 0 : e.tokens;
245
245
  }], ([e, t]) => {
246
- !e || t === void 0 || T(t, p.value) || (p.value = z({}, t), e.tokens.set(t));
246
+ !e || t === void 0 || D(t, p.value) || (p.value = B({}, t), e.tokens.set(t));
247
247
  }, {
248
248
  immediate: !0,
249
249
  deep: !0
250
250
  });
251
251
  let m = { value: i().i18n };
252
252
  b([n, () => i().i18n], ([e, t]) => {
253
- if (!e || t === void 0 || T(t, m.value)) return;
254
- m.value = z({}, t);
253
+ if (!e || t === void 0 || D(t, m.value)) return;
254
+ m.value = B({}, t);
255
255
  let { locale: n, messages: r, direction: i } = t;
256
- e.i18n.update(z(z(z({}, n === void 0 ? {} : { locale: n }), r === void 0 ? {} : { messages: r }), i === void 0 ? {} : { direction: i }));
256
+ e.i18n.update(B(B(B({}, n === void 0 ? {} : { locale: n }), r === void 0 ? {} : { messages: r }), i === void 0 ? {} : { direction: i }));
257
257
  }, {
258
258
  immediate: !0,
259
259
  deep: !0
@@ -263,7 +263,7 @@ function X(e, t) {
263
263
  value: void 0
264
264
  };
265
265
  return b([n, () => i().inlineToolbar], ([e, t]) => {
266
- if (!e || t === void 0 || h.editor === e && T(t, h.value)) return;
266
+ if (!e || t === void 0 || h.editor === e && D(t, h.value)) return;
267
267
  let n = Array.isArray(t) ? [...t] : t;
268
268
  h.editor = e, h.value = n, e.tools.setInlineToolbar(n);
269
269
  }, {
@@ -296,7 +296,7 @@ function X(e, t) {
296
296
  return;
297
297
  }
298
298
  let n = a.lastRenderedData;
299
- n !== void 0 && te(t, n) || (a.lastRenderedData = t, a.renderChain = a.renderChain.catch(() => void 0).then(() => e.render(ne(v(t)))));
299
+ n !== void 0 && ne(t, n) || (a.lastRenderedData = t, a.renderChain = a.renderChain.catch(() => void 0).then(() => e.render(ie(v(t)))));
300
300
  }, { immediate: !0 }), t !== void 0 && b(() => y(t), () => {
301
301
  u(), f();
302
302
  }), d(f), l(u), n;
@@ -304,62 +304,64 @@ function X(e, t) {
304
304
  //#endregion
305
305
  //#region src/useBlocks.ts
306
306
  var Z = "block changed";
307
- function ce(e) {
308
- let t = _(0), n = () => {
307
+ function de(e, t = {}) {
308
+ let n = _(0), r = () => {
309
309
  let t = y(e);
310
310
  return t === null ? null : v(t);
311
- }, r = () => {
312
- t.value;
313
- }, i = _(C), a = {
311
+ }, i = () => {
312
+ n.value;
313
+ }, a = _(S), o = {
314
314
  editor: null,
315
315
  handler: null
316
- }, o = () => {
317
- a.editor !== null && a.handler !== null && a.editor.off(Z, a.handler), a.editor = null, a.handler = null;
316
+ }, s = () => {
317
+ o.editor !== null && o.handler !== null && o.editor.off(Z, o.handler), o.editor = null, o.handler = null;
318
318
  };
319
- return b(() => n(), (e) => {
320
- if (o(), t.value += 1, e === null) {
321
- i.value = C;
319
+ return b(() => r(), (e) => {
320
+ if (s(), n.value += 1, e === null) {
321
+ a.value = S;
322
322
  return;
323
323
  }
324
- let n = () => {
325
- t.value += 1;
324
+ let r = (r) => {
325
+ var i;
326
+ let a = (i = y(t.within)) == null ? null : i;
327
+ a !== null && !w(e, r, a) || (n.value += 1);
326
328
  };
327
- e.on(Z, n), a.editor = e, a.handler = n, i.value = w(e, r);
328
- }, { immediate: !0 }), f(o), {
329
- getById: (e) => i.value.getById(e),
330
- getChildren: (e) => i.value.getChildren(e),
331
- insert: (e) => i.value.insert(e),
332
- insertMany: (e) => i.value.insertMany(e),
333
- insertTree: (e) => i.value.insertTree(e),
334
- insertMarkdown: (e, t) => i.value.insertMarkdown(e, t),
335
- exportMarkdown: () => i.value.exportMarkdown(),
336
- move: (e, t) => i.value.move(e, t),
337
- nest: (e, t) => i.value.nest(e, t),
338
- unnest: (e) => i.value.unnest(e),
339
- remove: (e) => i.value.remove(e),
340
- update: (e, t, n) => i.value.update(e, t, n),
341
- convert: (e, t, n, r) => i.value.convert(e, t, n, r),
342
- transact: (e) => i.value.transact(e),
343
- transactWithoutCapture: (e) => i.value.transactWithoutCapture(e),
344
- getBlocksCount: () => i.value.getBlocksCount(),
345
- getCurrentBlockIndex: () => i.value.getCurrentBlockIndex(),
346
- getBlockByIndex: (e) => i.value.getBlockByIndex(e),
347
- getBlockByElement: (e) => i.value.getBlockByElement(e),
348
- getBlockData: (e) => i.value.getBlockData(e),
349
- getBlockIndex: (e) => i.value.getBlockIndex(e),
350
- composeBlockData: (e) => i.value.composeBlockData(e),
351
- renderFromHTML: (e) => i.value.renderFromHTML(e),
352
- insertOutputData: (e, t) => i.value.insertOutputData(e, t),
353
- splitBlock: (e, t, n, r, a) => i.value.splitBlock(e, t, n, r, a),
354
- insertInsideParent: (e, t, n) => i.value.insertInsideParent(e, t, n),
355
- render: (e) => i.value.render(e),
356
- clear: () => i.value.clear(),
357
- isSyncingFromYjs: () => i.value.isSyncingFromYjs()
329
+ e.on(Z, r), o.editor = e, o.handler = r, a.value = T(e, i);
330
+ }, { immediate: !0 }), f(s), {
331
+ getById: (e) => a.value.getById(e),
332
+ getChildren: (e) => a.value.getChildren(e),
333
+ insert: (e) => a.value.insert(e),
334
+ insertMany: (e) => a.value.insertMany(e),
335
+ insertTree: (e) => a.value.insertTree(e),
336
+ insertMarkdown: (e, t) => a.value.insertMarkdown(e, t),
337
+ exportMarkdown: () => a.value.exportMarkdown(),
338
+ move: (e, t) => a.value.move(e, t),
339
+ nest: (e, t) => a.value.nest(e, t),
340
+ unnest: (e) => a.value.unnest(e),
341
+ remove: (e) => a.value.remove(e),
342
+ update: (e, t, n) => a.value.update(e, t, n),
343
+ convert: (e, t, n, r) => a.value.convert(e, t, n, r),
344
+ transact: (e) => a.value.transact(e),
345
+ transactWithoutCapture: (e) => a.value.transactWithoutCapture(e),
346
+ getBlocksCount: () => a.value.getBlocksCount(),
347
+ getCurrentBlockIndex: () => a.value.getCurrentBlockIndex(),
348
+ getBlockByIndex: (e) => a.value.getBlockByIndex(e),
349
+ getBlockByElement: (e) => a.value.getBlockByElement(e),
350
+ getBlockData: (e) => a.value.getBlockData(e),
351
+ getBlockIndex: (e) => a.value.getBlockIndex(e),
352
+ composeBlockData: (e) => a.value.composeBlockData(e),
353
+ renderFromHTML: (e) => a.value.renderFromHTML(e),
354
+ insertOutputData: (e, t) => a.value.insertOutputData(e, t),
355
+ splitBlock: (e, t, n, r, i) => a.value.splitBlock(e, t, n, r, i),
356
+ insertInsideParent: (e, t, n) => a.value.insertInsideParent(e, t, n),
357
+ render: (e) => a.value.render(e),
358
+ clear: () => a.value.clear(),
359
+ isSyncingFromYjs: () => a.value.isSyncingFromYjs()
358
360
  };
359
361
  }
360
362
  //#endregion
361
363
  //#region src/useBlokReady.ts
362
- function le(e = {}) {
364
+ function fe(e = {}) {
363
365
  let { within: t, settleOn: n } = e, r = _(!1), i = () => {
364
366
  var e;
365
367
  let i = t === void 0 || (e = y(t)) == null ? null : e;
@@ -372,7 +374,7 @@ function le(e = {}) {
372
374
  }
373
375
  //#endregion
374
376
  //#region src/BlockPortalHost.ts
375
- var ue = r({
377
+ var pe = r({
376
378
  name: "BlockErrorBoundary",
377
379
  setup(e, { slots: t }) {
378
380
  return u(() => !1), () => {
@@ -380,7 +382,7 @@ var ue = r({
380
382
  return (e = t.default) == null ? void 0 : e.call(t);
381
383
  };
382
384
  }
383
- }), de = r({
385
+ }), me = r({
384
386
  name: "BlockPortalHost",
385
387
  props: { registry: {
386
388
  type: Object,
@@ -390,11 +392,11 @@ var ue = r({
390
392
  return () => a(e, Array.from(n.registry.entries.entries()).map(([e, n]) => a(t, {
391
393
  key: e,
392
394
  to: n.hostEl
393
- }, [a(ue, null, { default: () => a(n.component, n.props) })])));
395
+ }, [a(pe, null, { default: () => a(n.component, n.props) })])));
394
396
  }
395
- }), Q = Symbol("BLOK_EDITOR_INSTANCE"), fe = _(null);
396
- function pe() {
397
- return o(Q, fe);
397
+ }), Q = Symbol("BLOK_EDITOR_INSTANCE"), he = _(null);
398
+ function ge() {
399
+ return o(Q, he);
398
400
  }
399
401
  //#endregion
400
402
  //#region src/BlokContent.ts
@@ -423,10 +425,10 @@ var $ = r({
423
425
  i(e.editor);
424
426
  }), () => {
425
427
  let n = e.editor, r = n === null ? void 0 : J(v(n));
426
- return a("div", { ref: t }, r === void 0 ? [] : [a(de, { registry: r })]);
428
+ return a("div", { ref: t }, r === void 0 ? [] : [a(me, { registry: r })]);
427
429
  };
428
430
  }
429
- }), me = /* @__PURE__ */ "autofocus.defaultBlock.dataModel.placeholder.sanitizer.hideToolbar.maxHistoryLength.historyDebounceTime.newGroupDelay.globalUndoRedo.tools.data.minHeight.logLevel.readOnly.i18n.link.linkPaste.inlineToolbar.tunes.style.theme.scrollToBlock.user.resolveUser.notifierPosition.notifier.width.onBeforeRender.onBeforePaste.onEnter.onSubmit.onError.migrations.uploader.captureClicksBelowEditor".split("."), he = r({
431
+ }), _e = /* @__PURE__ */ "autofocus.defaultBlock.dataModel.placeholder.sanitizer.hideToolbar.maxHistoryLength.historyDebounceTime.newGroupDelay.globalUndoRedo.tools.data.minHeight.logLevel.readOnly.i18n.link.linkPaste.inlineToolbar.tunes.style.theme.scrollToBlock.user.resolveUser.notifierPosition.notifier.width.onBeforeRender.onBeforePaste.onEnter.onSubmit.onError.migrations.uploader.captureClicksBelowEditor".split("."), ve = r({
430
432
  name: "BlokEditor",
431
433
  inheritAttrs: !1,
432
434
  props: {
@@ -596,7 +598,7 @@ var $ = r({
596
598
  });
597
599
  let u = (e) => l.value.split("|").includes(e), d = () => {
598
600
  let n = {};
599
- for (let t of me) {
601
+ for (let t of _e) {
600
602
  let r = e[t];
601
603
  r !== void 0 && (n[t] = r);
602
604
  }
@@ -645,50 +647,28 @@ var $ = r({
645
647
  let t = f.value;
646
648
  if (t !== null) return t.render(e).then(() => {
647
649
  var n;
648
- (n = re(t)) == null || n.markRendered(e);
650
+ (n = j(t)) == null || n.markRendered(e);
649
651
  });
650
652
  }
651
- }), () => a($, z({ editor: f.value }, o));
653
+ }), () => a($, B({ editor: f.value }, o));
652
654
  }
653
- }), ge = [
655
+ }), ye = [
654
656
  "toolbox",
655
657
  "isReadOnlySupported",
656
658
  "__isBlokVueBlock"
657
- ], _e = /* @__PURE__ */ new Set([
659
+ ], be = /* @__PURE__ */ new Set([
658
660
  void 0,
659
661
  "user",
660
662
  "api",
661
663
  "convert"
662
- ]), ve = (e, t, n) => {
663
- let r = /* @__PURE__ */ new Map();
664
- t.forEach((e, t) => {
665
- var i;
666
- let a = [];
667
- for (let [r, o] of Object.entries((i = n == null ? void 0 : n(e, t)) == null ? {} : i)) {
668
- if (o == null) {
669
- e.holder.removeAttribute(r);
670
- continue;
671
- }
672
- e.holder.setAttribute(r, String(o)), a.push(r);
673
- }
674
- r.set(e.id, {
675
- holder: e.holder,
676
- names: a
677
- });
678
- });
679
- for (let [t, n] of e) {
680
- let e = r.get(t);
681
- n.names.filter((t) => e === void 0 || !e.names.includes(t)).forEach((e) => n.holder.removeAttribute(e));
682
- }
683
- e.clear(), r.forEach((t, n) => e.set(n, t));
684
- }, ye = (e, t, n) => {
664
+ ]), xe = (e, t, n) => {
685
665
  var r;
686
666
  e == null || (r = e.events) == null || r.emit(ee, {
687
667
  blockId: t,
688
668
  childIds: n.map((e) => e.id)
689
669
  });
690
670
  };
691
- function be(e) {
671
+ function Se(e) {
692
672
  var t, n;
693
673
  let i = () => r({
694
674
  name: `VueBlock(${e.type})`,
@@ -717,7 +697,10 @@ function be(e) {
717
697
  }
718
698
  constructor(t) {
719
699
  var n, o, s;
720
- this.wrappedComponent = i(), this.mountSignalled = !1, this.hostEl = null, this.pendingDispatch = !1, this.notifyMounted = () => {
700
+ this.wrappedComponent = i(), this.mountSignalled = !1, this.hostEl = null, this.pendingDispatch = !1, this.anchorEl = null, this.toolbarAnchorRef = (e) => {
701
+ let t = e === null || e instanceof Element ? e : e.$el;
702
+ this.anchorEl = t instanceof HTMLElement ? t : null;
703
+ }, this.notifyMounted = () => {
721
704
  var t;
722
705
  if (this.mountSignalled) return;
723
706
  this.mountSignalled = !0;
@@ -725,37 +708,46 @@ function be(e) {
725
708
  origin: this.origin,
726
709
  api: this.api
727
710
  };
728
- if ((t = e.onMounted) == null || t.call(e, this.blockApi, n), _e.has(this.origin)) {
711
+ if ((t = e.onMounted) == null || t.call(e, this.blockApi, n), be.has(this.origin)) {
729
712
  var r;
730
713
  (r = e.onCreated) == null || r.call(e, this.blockApi, n);
731
714
  }
732
715
  }, this.commit = (t) => {
733
- let n = E(e.propSchema, z(z({}, this.mirror), t));
734
- T(n, this.mirror) || (this.mirror = n, this.lastRendered = n, this.dataRef.value = n, this.flushDispatch());
716
+ let n = O(e.propSchema, B(B({}, this.mirror), t));
717
+ D(n, this.mirror) || (this.mirror = n, this.lastRendered = n, this.dataRef.value = n, this.flushDispatch());
735
718
  }, this.blockApi = t.block;
736
719
  let c = (n = t.config) == null ? {} : n;
737
- this.registry = c[W], this.api = t.api;
720
+ this.registry = c[G], this.api = t.api;
738
721
  let l = t.api;
739
722
  this.pointerDrag = () => {
740
723
  var e;
741
724
  return (l == null || (e = l.blocks) == null ? void 0 : e.isPointerDragActive) === !0;
742
- }, this.mirror = E(e.propSchema, v((o = t.data) == null ? {} : o)), this.lastRendered = this.mirror, this.dataRef = _(this.mirror), this.readOnlyRef = _(t.readOnly), this.origin = (s = t.origin) == null ? "api" : s;
725
+ }, this.mirror = O(e.propSchema, v((o = t.data) == null ? {} : o)), this.lastRendered = this.mirror, this.dataRef = _(this.mirror), this.readOnlyRef = _(t.readOnly), this.origin = (s = t.origin) == null ? "api" : s;
743
726
  let u = this.blockApi, f = this.api;
744
727
  this.childrenComponent = r({
745
728
  name: `VueBlockChildren(${e.type})`,
746
- props: { childAttributes: {
747
- type: Function,
748
- default: void 0
749
- } },
729
+ props: {
730
+ childAttributes: {
731
+ type: Function,
732
+ default: void 0
733
+ },
734
+ childContentAttributes: {
735
+ type: Function,
736
+ default: void 0
737
+ }
738
+ },
750
739
  setup(e) {
751
- let t = g(null), n = /* @__PURE__ */ new Map(), r = () => {
740
+ let t = g(null), n = E(), r = () => {
752
741
  if (t.value === null) return;
753
742
  let r = u.getChildren();
754
- D(t.value, r), ve(n, r, e.childAttributes), ye(f, u.id, r);
743
+ re(t.value, r), C(n, r, {
744
+ childAttributes: e.childAttributes,
745
+ childContentAttributes: e.childContentAttributes
746
+ }), xe(f, u.id, r);
755
747
  };
756
748
  return d(r), p(r), () => a("div", {
757
749
  ref: t,
758
- [S.nestedBlocks]: ""
750
+ [te.nestedBlocks]: ""
759
751
  });
760
752
  }
761
753
  });
@@ -770,7 +762,8 @@ function be(e) {
770
762
  block: this.blockApi,
771
763
  api: this.api,
772
764
  readOnly: this.readOnlyRef,
773
- BlockChildren: this.childrenComponent
765
+ BlockChildren: this.childrenComponent,
766
+ toolbarAnchorRef: this.toolbarAnchorRef
774
767
  };
775
768
  return (e = this.registry) == null || e.register(this.blockApi.id, {
776
769
  hostEl: t,
@@ -790,16 +783,18 @@ function be(e) {
790
783
  }
791
784
  async setData(t) {
792
785
  var n = this;
793
- let r = E(e.propSchema, v(t == null ? {} : t));
794
- return T(r, n.lastRendered) ? !0 : (n.mirror = r, n.lastRendered = r, n.dataRef.value = r, await c(), !0);
786
+ let r = O(e.propSchema, v(t == null ? {} : t));
787
+ return D(r, n.lastRendered) ? !0 : (n.mirror = r, n.lastRendered = r, n.dataRef.value = r, await c(), !0);
795
788
  }
796
789
  setReadOnly(e) {
797
790
  this.readOnlyRef.value = e;
798
791
  }
799
792
  getToolbarAnchorElement() {
800
793
  var t;
801
- let n = this.hostEl;
802
- if (!(n === null || e.getToolbarAnchorElement === void 0)) return (t = e.getToolbarAnchorElement(n, this.blockApi)) == null ? void 0 : t;
794
+ let n = this.anchorEl;
795
+ if (n !== null && n.isConnected) return n;
796
+ let r = this.hostEl;
797
+ if (!(r === null || e.getToolbarAnchorElement === void 0)) return (t = e.getToolbarAnchorElement(r, this.blockApi)) == null ? void 0 : t;
803
798
  }
804
799
  moved() {
805
800
  var t;
@@ -830,7 +825,7 @@ function be(e) {
830
825
  requestAnimationFrame(e);
831
826
  }
832
827
  }, t.__isBlokVueBlock = !0, t);
833
- for (let [t, r] of Object.entries((n = e.statics) == null ? {} : n)) ge.includes(t) || Object.defineProperty(o, t, {
828
+ for (let [t, r] of Object.entries((n = e.statics) == null ? {} : n)) ye.includes(t) || Object.defineProperty(o, t, {
834
829
  value: r,
835
830
  writable: !0,
836
831
  enumerable: !0,
@@ -839,4 +834,4 @@ function be(e) {
839
834
  return o;
840
835
  }
841
836
  //#endregion
842
- export { B as BLOK_DEFAULT_CONFIG, Q as BLOK_EDITOR_INSTANCE, $ as BlokContent, he as BlokEditor, be as createVueBlock, V as provideBlok, ce as useBlocks, X as useBlok, H as useBlokDefaults, pe as useBlokInstance, le as useBlokReady };
837
+ export { V as BLOK_DEFAULT_CONFIG, Q as BLOK_EDITOR_INSTANCE, $ as BlokContent, ve as BlokEditor, Se as createVueBlock, H as provideBlok, de as useBlocks, X as useBlok, U as useBlokDefaults, ge as useBlokInstance, fe as useBlokReady };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bloklabs/vue",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "description": "Vue block editor — official Vue 3 bindings for Blok, the headless Notion-like rich text editor. Composables 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
  "build": "yarn run -T vite build --mode production"
55
55
  },
56
56
  "peerDependencies": {
57
- "@bloklabs/core": "^1.8.0",
57
+ "@bloklabs/core": "^1.10.0",
58
58
  "vue": "^3.5.0"
59
59
  }
60
60
  }
@@ -9,6 +9,7 @@ import {
9
9
  shallowRef,
10
10
  toRaw,
11
11
  type Component,
12
+ type ComponentPublicInstance,
12
13
  type PropType,
13
14
  type ShallowRef,
14
15
  type VNodeChild,
@@ -23,7 +24,14 @@ import type {
23
24
  BlockToolData,
24
25
  ToolboxConfig,
25
26
  } from '@/types/tools';
26
- import { BlockChildrenMounted, DATA_ATTR , deepEqual , mountChildBlocks } from '@bloklabs/core/adapters';
27
+ import {
28
+ applyChildDecoration,
29
+ BlockChildrenMounted,
30
+ createChildDecorationLedger,
31
+ DATA_ATTR,
32
+ deepEqual,
33
+ mountChildBlocks,
34
+ } from '@bloklabs/core/adapters';
27
35
  import { fillDefaults, type PropSchema } from '@bloklabs/core/adapters';
28
36
 
29
37
  import {
@@ -80,55 +88,6 @@ export type ChildAttributes = Record<string, string | number | boolean | null |
80
88
  /** The `BlockChildren` per-child decorator (see {@link VueBlockRenderProps.BlockChildren}). */
81
89
  export type ChildAttributesFn = (child: BlockAPI, index: number) => ChildAttributes;
82
90
 
83
- /** What the previous decoration pass wrote for one child, so it can be undone. */
84
- interface StampedChild {
85
- holder: HTMLElement;
86
- names: string[];
87
- }
88
-
89
- /**
90
- * Apply one pass of per-child holder attributes and clear the previous pass's
91
- * leftovers — including on a child that has since left the container, which
92
- * would otherwise keep a dead index forever.
93
- * @param stamped - the slot's ledger of what the last pass wrote (mutated)
94
- * @param children - the container's model children, in model order
95
- * @param decorate - the authored per-child decorator, if any
96
- */
97
- const applyChildAttributes = (
98
- stamped: Map<string, StampedChild>,
99
- children: BlockAPI[],
100
- decorate: ChildAttributesFn | undefined
101
- ): void => {
102
- const next = new Map<string, StampedChild>();
103
-
104
- children.forEach((child, index) => {
105
- const names: string[] = [];
106
-
107
- for (const [name, value] of Object.entries(decorate?.(child, index) ?? {})) {
108
- if (value === null || value === undefined) {
109
- child.holder.removeAttribute(name);
110
- continue;
111
- }
112
-
113
- child.holder.setAttribute(name, String(value));
114
- names.push(name);
115
- }
116
-
117
- next.set(child.id, { holder: child.holder, names });
118
- });
119
-
120
- for (const [id, previous] of stamped) {
121
- const current = next.get(id);
122
-
123
- previous.names
124
- .filter(name => current === undefined || !current.names.includes(name))
125
- .forEach(name => previous.holder.removeAttribute(name));
126
- }
127
-
128
- stamped.clear();
129
- next.forEach((entry, id) => stamped.set(id, entry));
130
- };
131
-
132
91
  /**
133
92
  * Announce that a container's child holders have settled in its slot — the
134
93
  * signal a host waits on before putting the caret into a freshly inserted
@@ -187,6 +146,17 @@ export interface VueBlockRenderProps<Data> {
187
146
  * by identity), so decoration is attributes, never wrapper elements. Attributes
188
147
  * the callback stops producing are removed on the next pass.
189
148
  *
149
+ * A second prop, `childContentAttributes`, is the same decoration applied one
150
+ * level IN — on each child's `[data-blok-element-content]` wrapper instead of
151
+ * its holder. Core's decoration law blesses both, and a container needs both:
152
+ * the holder is the child's outer box (rails, indices, hover states), the
153
+ * content wrapper is where the child's own text box begins, which is what a
154
+ * numbered rail or a connector line has to align to. Reach for it instead of
155
+ * walking core's wrapper chain from a holder hook (`[data-step] >
156
+ * [data-blok-element-content] > …`) — those selectors encode engine DOM in host
157
+ * CSS and break when that structure changes. A child whose DOM has not
158
+ * committed yet has no wrapper to write to and is stamped on the next pass.
159
+ *
190
160
  * Writing on a child's holder is inert by design: core's mutation filter drops
191
161
  * a holder-targeted attribute record for the child block and suppresses it for
192
162
  * the container. The guarantee stops at the holder and its
@@ -194,6 +164,27 @@ export interface VueBlockRenderProps<Data> {
194
164
  * root DOES score as that child's edit.
195
165
  */
196
166
  BlockChildren: Component;
167
+ /**
168
+ * Attach this to the element the +/drag toolbar should vertically center on:
169
+ * `h('div', { ref: ctx.toolbarAnchorRef })`, or `:ref="ctx.toolbarAnchorRef"`
170
+ * in a template. The Vue-native way to answer core's
171
+ * `getToolbarAnchorElement`, which is otherwise a `(host, block) => Element`
172
+ * hook resolved OUTSIDE the render tree — so pointing at an element you render
173
+ * meant inventing a data attribute and `querySelector`-ing for it from
174
+ * {@link CreateVueBlockSpec.getToolbarAnchorElement}.
175
+ *
176
+ * A container block whose own chrome is not editable needs an anchor: with
177
+ * none, core centers the toolbar on the first `[contenteditable]` under the
178
+ * host, which for a container is its FIRST CHILD BLOCK — parking the +/drag
179
+ * handles halfway down, beside content that has a toolbar of its own.
180
+ *
181
+ * The ref is stable across renders and outranks
182
+ * {@link CreateVueBlockSpec.getToolbarAnchorElement} while it holds a MOUNTED
183
+ * element; when the element unmounts (Vue calls the ref with null, or it is
184
+ * detached) the declared hook takes over again, so the toolbar is never
185
+ * positioned against a stale node. Leave it unattached to keep core's default.
186
+ */
187
+ toolbarAnchorRef: (element: Element | ComponentPublicInstance | null) => void;
197
188
  }
198
189
 
199
190
  /**
@@ -421,6 +412,25 @@ export function createVueBlock<Data = BlockToolData>(
421
412
  private hostEl: HTMLElement | null = null;
422
413
  /** Latest patch queued while a pointer drag suppresses dispatchChange. */
423
414
  private pendingDispatch = false;
415
+ /** Element the block pointed `toolbarAnchorRef` at, if any. */
416
+ private anchorEl: HTMLElement | null = null;
417
+ /**
418
+ * The `toolbarAnchorRef` context member. A bound field so its identity is
419
+ * STABLE across renders — a fresh function ref each render would make Vue
420
+ * detach (null) and re-attach it on every patch.
421
+ * @param element - what Vue attached: an element, a component instance, or
422
+ * null on detach
423
+ */
424
+ private readonly toolbarAnchorRef = (
425
+ element: Element | ComponentPublicInstance | null
426
+ ): void => {
427
+ // A ref placed on a child COMPONENT hands over its instance, not its DOM.
428
+ const resolved = element === null || element instanceof Element
429
+ ? element
430
+ : (element.$el as unknown);
431
+
432
+ this.anchorEl = resolved instanceof HTMLElement ? resolved : null;
433
+ };
424
434
 
425
435
  public constructor(options: BlockToolConstructorOptions) {
426
436
  this.blockApi = options.block;
@@ -457,11 +467,15 @@ export function createVueBlock<Data = BlockToolData>(
457
467
  type: Function as PropType<ChildAttributesFn>,
458
468
  default: undefined,
459
469
  },
470
+ childContentAttributes: {
471
+ type: Function as PropType<ChildAttributesFn>,
472
+ default: undefined,
473
+ },
460
474
  },
461
475
  setup(props) {
462
476
  const slot = ref<HTMLElement | null>(null);
463
477
  // What the last decoration pass wrote, so a dropped key is cleaned up.
464
- const stamped = new Map<string, StampedChild>();
478
+ const ledger = createChildDecorationLedger();
465
479
  const mountKids = (): void => {
466
480
  if (slot.value === null) {
467
481
  return;
@@ -470,7 +484,10 @@ export function createVueBlock<Data = BlockToolData>(
470
484
  const children = blockApi.getChildren();
471
485
 
472
486
  mountChildBlocks(slot.value, children);
473
- applyChildAttributes(stamped, children, props.childAttributes);
487
+ applyChildDecoration(ledger, children, {
488
+ childAttributes: props.childAttributes,
489
+ childContentAttributes: props.childContentAttributes,
490
+ });
474
491
  emitChildrenMounted(api, blockApi.id, children);
475
492
  };
476
493
 
@@ -498,6 +515,7 @@ export function createVueBlock<Data = BlockToolData>(
498
515
  api: this.api,
499
516
  readOnly: this.readOnlyRef,
500
517
  BlockChildren: this.childrenComponent,
518
+ toolbarAnchorRef: this.toolbarAnchorRef,
501
519
  };
502
520
 
503
521
  this.registry?.register(this.blockApi.id, {
@@ -584,6 +602,19 @@ export function createVueBlock<Data = BlockToolData>(
584
602
  * default positioning already assumes.
585
603
  */
586
604
  public getToolbarAnchorElement(): HTMLElement | undefined {
605
+ /**
606
+ * A ref the block attached wins — it names the exact element, chosen from
607
+ * inside the render tree. `isConnected` is the guard that matters: Vue
608
+ * nulls the ref on unmount, but a block that re-parents its anchor can
609
+ * leave a detached node here, and positioning the toolbar against one
610
+ * silently parks it at 0,0.
611
+ */
612
+ const fromRef = this.anchorEl;
613
+
614
+ if (fromRef !== null && fromRef.isConnected) {
615
+ return fromRef;
616
+ }
617
+
587
618
  const host = this.hostEl;
588
619
 
589
620
  if (host === null || spec.getToolbarAnchorElement === undefined) {
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { useBlok } from './useBlok';
2
2
  export { useBlocks } from './useBlocks';
3
+ export type { UseBlocksOptions } from './useBlocks';
3
4
  export { useBlokReady } from './useBlokReady';
4
5
  export { BlokContent } from './BlokContent';
5
6
  export { BlokEditor } from './BlokEditor';
package/src/useBlocks.ts CHANGED
@@ -9,12 +9,35 @@ import {
9
9
  } from 'vue';
10
10
 
11
11
  import type { Blok } from '@/types';
12
- import { createBlocksApiForEditor, EMPTY_API } from '@bloklabs/core/adapters';
12
+ import { changeTouchesSubtree, createBlocksApiForEditor, EMPTY_API } from '@bloklabs/core/adapters';
13
13
 
14
14
  import type { UseBlocksApi } from './blocks-snapshot';
15
15
 
16
16
  const BLOCK_CHANGED_EVENT = 'block changed';
17
17
 
18
+ /** Options for {@link useBlocks}. */
19
+ export interface UseBlocksOptions {
20
+ /**
21
+ * Re-render only for changes inside the subtree rooted at this block id (the
22
+ * block itself or any descendant). Omit — or pass `null` — for the
23
+ * document-wide default.
24
+ *
25
+ * This bounds REACTIVITY, not reads: the returned API still sees the whole
26
+ * tree, so a scoped consumer can still `getById` anything. Reach for it in a
27
+ * container block that renders only its own children — unscoped, such a block
28
+ * invalidates on every keystroke anywhere in the document, and a page of N
29
+ * containers turns one keystroke into N re-renders.
30
+ *
31
+ * Accepted as a value, ref or getter (like `editor`) and read at EMIT time, so
32
+ * changing it takes effect immediately with no re-subscription.
33
+ *
34
+ * A change whose block cannot be placed in the tree (a removal that emits
35
+ * after the block is gone) counts as in-scope: skipping it would leave a
36
+ * container rendering a child that no longer exists.
37
+ */
38
+ within?: MaybeRefOrGetter<string | null>;
39
+ }
40
+
18
41
  /**
19
42
  * Vue composable exposing an id/parentId-relative, reactive view of the block
20
43
  * tree. Reads refresh whenever the editor emits `block changed`; mutators route
@@ -43,8 +66,13 @@ const BLOCK_CHANGED_EVENT = 'block changed';
43
66
  * `transact`/`transactWithoutCapture`, which still run their callback.
44
67
  *
45
68
  * @param editor - the Blok instance (or ref/getter of it), or null pre-ready
69
+ * @param options - reactivity options; see {@link UseBlocksOptions.within} to
70
+ * scope invalidation to one block's subtree
46
71
  */
47
- export function useBlocks(editor: MaybeRefOrGetter<Blok | null>): UseBlocksApi {
72
+ export function useBlocks(
73
+ editor: MaybeRefOrGetter<Blok | null>,
74
+ options: UseBlocksOptions = {}
75
+ ): UseBlocksApi {
48
76
  // Bumped on every `block changed`; the shared API's read methods touch it
49
77
  // (via the onRead seam below) so template/computed reads stay reactive.
50
78
  const version = shallowRef(0);
@@ -68,7 +96,7 @@ export function useBlocks(editor: MaybeRefOrGetter<Blok | null>): UseBlocksApi {
68
96
 
69
97
  // Manage the `block changed` subscription, re-binding when the editor changes.
70
98
  // Held in one object (no `let` reassignment) — the same pattern useBlok uses.
71
- const sub: { editor: Blok | null; handler: (() => void) | null } = { editor: null, handler: null };
99
+ const sub: { editor: Blok | null; handler: ((payload?: unknown) => void) | null } = { editor: null, handler: null };
72
100
 
73
101
  const unsubscribe = (): void => {
74
102
  if (sub.editor !== null && sub.handler !== null) {
@@ -91,7 +119,14 @@ export function useBlocks(editor: MaybeRefOrGetter<Blok | null>): UseBlocksApi {
91
119
  return;
92
120
  }
93
121
 
94
- const handler = (): void => {
122
+ const handler = (payload?: unknown): void => {
123
+ // Resolved per emission, so a reactive `within` needs no re-subscription.
124
+ const within = toValue(options.within) ?? null;
125
+
126
+ if (within !== null && !changeTouchesSubtree(ed, payload, within)) {
127
+ return;
128
+ }
129
+
95
130
  version.value += 1;
96
131
  };
97
132
 
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Component, DefineComponent, InjectionKey, MaybeRefOrGetter, Ref, ShallowRef } from 'vue';
1
+ import type { Component, ComponentPublicInstance, DefineComponent, InjectionKey, MaybeRefOrGetter, Ref, ShallowRef } from 'vue';
2
2
  import type {
3
3
  API,
4
4
  Blok,
@@ -467,6 +467,7 @@ export interface UseBlocksApi {
467
467
  * block" tree, manipulated without flat-index math. Mirrors React's `useBlocks`.
468
468
  *
469
469
  * @param editor - the Blok instance (value/ref/getter), or null before ready
470
+ * @param options - reactivity options; see {@link UseBlocksOptions.within}
470
471
  *
471
472
  * @example
472
473
  * ```ts
@@ -478,7 +479,39 @@ export interface UseBlocksApi {
478
479
  * });
479
480
  * ```
480
481
  */
481
- export declare function useBlocks(editor: MaybeRefOrGetter<Blok | null>): UseBlocksApi;
482
+ export declare function useBlocks(
483
+ editor: MaybeRefOrGetter<Blok | null>,
484
+ options?: UseBlocksOptions
485
+ ): UseBlocksApi;
486
+
487
+ /** Options for {@link useBlocks}. */
488
+ export interface UseBlocksOptions {
489
+ /**
490
+ * Invalidate reads only for changes inside the subtree rooted at this block id
491
+ * (the block itself or any descendant). Omit — or pass `null` — for the
492
+ * document-wide default.
493
+ *
494
+ * This bounds REACTIVITY, not reads: the returned API still sees the whole
495
+ * tree, so a scoped consumer can still `getById` anything. Reach for it in a
496
+ * container block that renders only its own children — unscoped, such a block
497
+ * invalidates on every keystroke anywhere in the document, and a page of N
498
+ * containers turns one keystroke into N re-renders.
499
+ *
500
+ * Accepted as a value, ref or getter (like `editor`) and read at EMIT time, so
501
+ * changing it takes effect immediately with no re-subscription.
502
+ *
503
+ * A change whose block cannot be placed in the tree (a removal that emits
504
+ * after the block is gone) counts as in-scope: skipping it would leave a
505
+ * container rendering a child that no longer exists.
506
+ *
507
+ * @example
508
+ * ```ts
509
+ * // A container block invalidating only for its own subtree.
510
+ * const blocks = useBlocks(useBlokInstance(), { within: () => block.id });
511
+ * ```
512
+ */
513
+ within?: MaybeRefOrGetter<string | null>;
514
+ }
482
515
 
483
516
  /** Options accepted by {@link useBlokReady}. */
484
517
  export interface UseBlokReadyOptions {
@@ -578,8 +611,40 @@ export interface VueBlockRenderProps<Data> {
578
611
  * each child's HOLDER after mounting (named hooks instead of positional
579
612
  * `:nth-child()` CSS). Holders stay DIRECT children of the slot; attributes
580
613
  * the callback stops producing are removed on the next pass.
614
+ *
615
+ * A second prop, `childContentAttributes: ChildAttributesFn`, is the same
616
+ * decoration applied one level IN — on each child's
617
+ * `[data-blok-element-content]` wrapper instead of its holder. Blok's
618
+ * decoration law blesses both, and a container needs both: the holder is the
619
+ * child's outer box (rails, indices, hover states), the content wrapper is
620
+ * where the child's own text box begins, which is what a numbered rail or a
621
+ * connector line has to align to. Reach for it instead of walking Blok's
622
+ * wrapper chain from a holder hook (`[data-step] >
623
+ * [data-blok-element-content] > …`) — those selectors encode engine DOM in host
624
+ * CSS and break when that structure changes. A child whose DOM has not
625
+ * committed yet is stamped on the next pass.
581
626
  */
582
627
  BlockChildren: Component;
628
+ /**
629
+ * Attach this to the element the +/drag toolbar should vertically center on:
630
+ * `h('div', { ref: ctx.toolbarAnchorRef })`. The Vue-native way to answer
631
+ * core's `getToolbarAnchorElement`, which is otherwise a
632
+ * `(host, block) => Element` hook resolved OUTSIDE the render tree — so
633
+ * pointing at an element you render meant inventing a data attribute and
634
+ * `querySelector`-ing for it.
635
+ *
636
+ * A container block whose own chrome is not editable needs an anchor: with
637
+ * none, core centers the toolbar on the first `[contenteditable]` under the
638
+ * host, which for a container is its FIRST CHILD BLOCK — parking the +/drag
639
+ * handles halfway down, beside content that has a toolbar of its own.
640
+ *
641
+ * The ref is stable across renders and outranks the spec's
642
+ * `getToolbarAnchorElement` while it holds a MOUNTED element; once the element
643
+ * unmounts or detaches, the declared hook takes over again, so the toolbar is
644
+ * never positioned against a stale node. A ref placed on a child COMPONENT is
645
+ * resolved through its `$el`. Leave it unattached to keep core's default.
646
+ */
647
+ toolbarAnchorRef: (element: Element | ComponentPublicInstance | null) => void;
583
648
  }
584
649
 
585
650
  /** Spec for {@link createVueBlock}. Authored as a `.ts` render function (no SFC). */