@b10cks/vue 0.10.2 → 0.10.4

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.
@@ -1,3 +1,4 @@
1
1
  import { Plugin } from 'vue';
2
2
  export { previewBridge } from './preview-bridge';
3
+ export { B10cksComponentResolverKey, type BlockComponentResolver } from './types';
3
4
  export declare const B10cksVue: Plugin;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("vue"),b={key:1},h=o.defineComponent({__name:"B10cksComponent",props:{block:{}},setup(e,{expose:t}){const s=e,n=o.useTemplateRef("blockRef");t({value:n});const r=o.shallowRef(null),u=o.computed(()=>s.block?.block||null);return o.watch(()=>u.value,async l=>{if(!l){r.value=null;return}const p=l.replace(/^([a-z])/,i=>i.toUpperCase()).replace(/([a-z])([A-Z])/g,"$1$2");try{r.value=o.defineAsyncComponent({loader:()=>import(`~/b10cks/${p}.vue`),timeout:3e3,onError:(i,d,v)=>{console.warn(`Failed to load block component for type "${l}":`,i),v()}})}catch(i){console.error(`Error resolving component for block type "${l}":`,i)}},{immediate:!0}),(l,p)=>r.value?(o.openBlock(),o.createBlock(o.resolveDynamicComponent(r.value),o.mergeProps({key:0,ref_key:"blockRef",ref:n},{...l.$props,...l.$attrs}),null,16)):(o.openBlock(),o.createElementBlock("div",b,'Component for block type "'+o.toDisplayString(u.value)+'" not found.',1))}});class c{static instance;eventListeners={};isEnabled=!1;constructor(){this.isEnabled=this.isIframe()}init(){this.isEnabled&&window&&window.addEventListener("message",this.handleMessage)}static getInstance(){return c.instance||(c.instance=new c),c.instance}isInPreviewMode(){return this.isEnabled}isIframe(){return window&&window.self!==window.top}handleMessage=t=>{if(!t.data||typeof t.data!="object")return;const{type:s,payload:n}=t.data;this.notifyListeners(s,n)};notifyListeners(t,s){const n=this.eventListeners[t];n&&n.forEach(r=>{r(s)})}on(t,s){return this.isEnabled?(this.eventListeners[t]||(this.eventListeners[t]=[]),this.eventListeners[t].push(s),()=>{this.eventListeners[t]=this.eventListeners[t].filter(n=>n!==s)}):()=>{}}selectItem(t){this.isEnabled&&window.parent.postMessage({type:"SELECT_UPDATE",payload:{selectedItem:t}},"*")}updateField(t,s,n){this.isEnabled&&window.parent.postMessage({type:"FIELD_UPDATE",payload:{itemId:t,field:s,value:n}},"*")}destroy(){this.isEnabled&&(window.removeEventListener("message",this.handleMessage),this.isEnabled=!1),this.eventListeners={}}}const a=c.getInstance(),f={mounted(e,t,s){if(!a.isInPreviewMode())return;const{id:n}=t.value;if(!n){console.warn("v-editable directive requires a block with an id");return}e.classList.add("b10cks-preview");const r=i=>{i.preventDefault(),i.stopPropagation(),a.selectItem(n)},u=({selectedItem:i})=>{s.el&&(i===n?(s.el.classList.add("b10cks-selected"),m(e)):s.el.classList.remove("b10cks-selected"))},l=({selectedItem:i})=>{s.el&&(i===n?s.el.classList.add("b10cks-hover"):s.el.classList.remove("b10cks-hover"))},p=({content:i})=>{if(i&&i.id===n){const d=s.ctx;d.parent.attrs.block=i,d.update(),d.props.block=i,d.update()}};e.addEventListener("click",r),a.on("SELECT_UPDATE",u),a.on("HOVER_UPDATE",l),a.on("CONTENT_UPDATE",p),e._editableCleanup=()=>{e.removeEventListener("click",r)}},updated(e,t,s){a.isInPreviewMode()&&t.value!==t.oldValue&&(e._editableCleanup&&e._editableCleanup(),f.mounted(e,t,s))},unmounted(e){a.isInPreviewMode()&&(e._editableCleanup&&(e._editableCleanup(),delete e._editableCleanup),e.classList.remove("b10cks-preview","b10cks-selected"))}};function m(e){e.scrollIntoView&&e.scrollIntoView({behavior:"smooth"})}if(a.isInPreviewMode()){const e=document.createElement("style");e.innerHTML=`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("vue"),f=Symbol("b10cks:resolveBlockComponent"),b={key:1},h=r.defineComponent({__name:"B10cksComponent",props:{block:{}},setup(e,{expose:t}){const s=e,n=r.useTemplateRef("blockRef");t({value:n});const o=r.shallowRef(null),d=r.computed(()=>s.block?.block||null),u=r.inject(f,null);return r.watch(()=>d.value,async a=>{if(!a){o.value=null;return}if(!u){console.error("B10cks: No component resolver found. Make sure you are using @b10cks/nuxt module or have provided a custom resolver."),o.value=null;return}try{o.value=await u(a)}catch(i){console.warn(`Failed to load block component for type "${a}":`,i),o.value=null}},{immediate:!0}),(a,i)=>o.value?(r.openBlock(),r.createBlock(r.resolveDynamicComponent(o.value),r.mergeProps({key:0,ref_key:"blockRef",ref:n},{...a.$props,...a.$attrs}),null,16)):(r.openBlock(),r.createElementBlock("div",b,'Component for block type "'+r.toDisplayString(d.value)+'" not found.',1))}});class c{static instance;eventListeners={};isEnabled=!1;constructor(){this.isEnabled=this.isIframe()}init(){this.isEnabled&&window&&window.addEventListener("message",this.handleMessage)}static getInstance(){return c.instance||(c.instance=new c),c.instance}isInPreviewMode(){return this.isEnabled}isIframe(){return typeof window<"u"&&window.self!==window.top}handleMessage=t=>{if(!t.data||typeof t.data!="object")return;const{type:s,payload:n}=t.data;this.notifyListeners(s,n)};notifyListeners(t,s){const n=this.eventListeners[t];n&&n.forEach(o=>{o(s)})}on(t,s){return this.isEnabled?(this.eventListeners[t]||(this.eventListeners[t]=[]),this.eventListeners[t].push(s),()=>{this.eventListeners[t]=this.eventListeners[t].filter(n=>n!==s)}):()=>{}}selectItem(t){this.isEnabled&&window.parent.postMessage({type:"SELECT_UPDATE",payload:{selectedItem:t}},"*")}updateField(t,s,n){this.isEnabled&&window.parent.postMessage({type:"FIELD_UPDATE",payload:{itemId:t,field:s,value:n}},"*")}destroy(){this.isEnabled&&(window.removeEventListener("message",this.handleMessage),this.isEnabled=!1),this.eventListeners={}}}const l=c.getInstance(),v={mounted(e,t,s){if(!l.isInPreviewMode())return;const{id:n}=t.value;if(!n){console.warn("v-editable directive requires a block with an id");return}e.classList.add("b10cks-preview");const o=i=>{i.preventDefault(),i.stopPropagation(),l.selectItem(n)},d=({selectedItem:i})=>{s.el&&(i===n?(s.el.classList.add("b10cks-selected"),m(e)):s.el.classList.remove("b10cks-selected"))},u=({selectedItem:i})=>{s.el&&(i===n?s.el.classList.add("b10cks-hover"):s.el.classList.remove("b10cks-hover"))},a=({content:i})=>{if(i&&i.id===n){const p=s.ctx;p.parent.attrs.block=i,p.update(),p.props.block=i,p.update()}};e.addEventListener("click",o),l.on("SELECT_UPDATE",d),l.on("HOVER_UPDATE",u),l.on("CONTENT_UPDATE",a),e._editableCleanup=()=>{e.removeEventListener("click",o)}},updated(e,t,s){l.isInPreviewMode()&&t.value!==t.oldValue&&(e._editableCleanup&&e._editableCleanup(),v.mounted(e,t,s))},unmounted(e){l.isInPreviewMode()&&(e._editableCleanup&&(e._editableCleanup(),delete e._editableCleanup),e.classList.remove("b10cks-preview","b10cks-selected"))}};function m(e){e.scrollIntoView&&e.scrollIntoView({behavior:"smooth"})}if(l.isInPreviewMode()){const e=document.createElement("style");e.innerHTML=`
2
2
  .b10cks-hover,
3
3
  .b10cks-preview:hover {
4
4
  outline: 2px dashed rgba(59, 130, 246, 0.5);
@@ -8,5 +8,5 @@
8
8
  outline: 2px solid rgb(59, 130, 246) !important;
9
9
  outline-offset: 2px;
10
10
  }
11
- `,document.head.appendChild(e)}const k={mounted(e,t){const{id:s,field:n}=t.value;a.isInPreviewMode()&&(e.setAttribute("contenteditable","true"),e.addEventListener("input",r=>{a.updateField(s,n,r.target.innerText)}))}},E={install(e,t){e.provide("b10cksVueOptions",t),e.directive("editable",f),e.directive("editable-field",k),e.component("B10cksComponent",h)}};exports.B10cksVue=E;exports.previewBridge=a;
11
+ `,document.head.appendChild(e)}const k={mounted(e,t){const{id:s,field:n}=t.value;l.isInPreviewMode()&&(e.setAttribute("contenteditable","true"),e.addEventListener("input",o=>{l.updateField(s,n,o.target.innerText)}))}},w={install(e,t){e.provide("b10cksVueOptions",t),e.directive("editable",v),e.directive("editable-field",k),e.component("B10cksComponent",h)}};exports.B10cksComponentResolverKey=f;exports.B10cksVue=w;exports.previewBridge=l;
12
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/components/B10cksComponent.vue","../src/preview-bridge.ts","../src/directives/v-editable.ts","../src/directives/v-editable-content.ts","../src/index.ts"],"sourcesContent":["<script setup lang=\"ts\">\nimport type { IBContent } from '@b10cks/client'\nimport {\n type Component,\n computed,\n defineAsyncComponent,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\n\nconst props = defineProps<{\n block: IBContent<string> & Record<string, never>\n}>()\n\nconst blockRef = useTemplateRef('blockRef')\ndefineExpose({ value: blockRef })\n\nconst resolvedComponent = shallowRef<Component | null>(null)\nconst componentName = computed(() => props.block?.block || null)\n\nwatch(\n () => componentName.value,\n async (newComponentName: string | null) => {\n if (!newComponentName) {\n resolvedComponent.value = null\n return\n }\n\n const pascalCaseBlockType = newComponentName\n .replace(/^([a-z])/, (match: string) => match.toUpperCase())\n .replace(/([a-z])([A-Z])/g, '$1$2')\n\n try {\n resolvedComponent.value = defineAsyncComponent({\n loader: () => import(`~/b10cks/${pascalCaseBlockType}.vue`),\n timeout: 3000,\n onError: (error, _, fail) => {\n // biome-ignore lint/suspicious/noConsole: give developers feedback\n console.warn(`Failed to load block component for type \"${newComponentName}\":`, error)\n fail()\n },\n })\n } catch (error) {\n // biome-ignore lint/suspicious/noConsole: give developers feedback\n console.error(`Error resolving component for block type \"${newComponentName}\":`, error)\n }\n },\n { immediate: true }\n)\n</script>\n<template>\n <component\n :is=\"resolvedComponent\"\n v-if=\"resolvedComponent\"\n ref=\"blockRef\"\n v-bind=\"{ ...$props, ...$attrs }\"\n />\n <div v-else>Component for block type \"{{ componentName }}\" not found.</div>\n</template>\n","export type ContentUpdateEvent = {\n content: Record<string, unknown>\n}\n\nexport type SelectUpdateEvent = {\n selectedItem: string\n}\n\nexport type EventType = 'CONTENT_UPDATE' | 'SELECT_UPDATE' | 'HOVER_UPDATE'\n\nexport type EventPayloadMap = {\n CONTENT_UPDATE: ContentUpdateEvent\n SELECT_UPDATE: SelectUpdateEvent\n HOVER_UPDATE: SelectUpdateEvent\n}\n\nexport type BridgeEvent = {\n type: EventType\n payload: ContentUpdateEvent | SelectUpdateEvent\n b10cksId?: string\n}\n\ntype EventCallback<T> = (payload: T) => void\n\nclass PreviewBridge {\n private static instance: PreviewBridge\n private eventListeners: {\n [key in EventType]?: Array<EventCallback<EventPayloadMap[key]>>\n } = {}\n\n private isEnabled = false\n\n private constructor() {\n this.isEnabled = this.isIframe()\n }\n\n public init(): void {\n if (this.isEnabled && window) {\n window.addEventListener('message', this.handleMessage)\n }\n }\n\n public static getInstance(): PreviewBridge {\n if (!PreviewBridge.instance) {\n PreviewBridge.instance = new PreviewBridge()\n }\n return PreviewBridge.instance\n }\n\n public isInPreviewMode(): boolean {\n return this.isEnabled\n }\n\n private isIframe(): boolean {\n return window && window.self !== window.top\n }\n\n private handleMessage = (event: MessageEvent): void => {\n if (!event.data || typeof event.data !== 'object') return\n const { type, payload } = event.data as BridgeEvent\n\n this.notifyListeners(type as EventType, payload)\n }\n\n private notifyListeners<T extends EventType>(type: T, payload: EventPayloadMap[T]): void {\n const listeners = this.eventListeners[type] as\n | Array<EventCallback<EventPayloadMap[T]>>\n | undefined\n\n if (listeners) {\n listeners.forEach((listener) => {\n listener(payload)\n })\n }\n }\n\n public on<T extends EventType>(\n eventType: T,\n callback: EventCallback<EventPayloadMap[T]>\n ): () => void {\n if (!this.isEnabled) return () => {}\n\n if (!this.eventListeners[eventType]) {\n this.eventListeners[eventType] = []\n }\n\n ;(this.eventListeners[eventType] as Array<EventCallback<EventPayloadMap[T]>>).push(callback)\n\n return () => {\n this.eventListeners[eventType] = (\n this.eventListeners[eventType] as Array<EventCallback<EventPayloadMap[T]>>\n ).filter((listener) => listener !== callback) as never\n }\n }\n\n public selectItem(selectedItem: string): void {\n if (!this.isEnabled) return\n\n window.parent.postMessage(\n {\n type: 'SELECT_UPDATE',\n payload: { selectedItem },\n },\n '*'\n )\n }\n\n public updateField(itemId: string, field: string, value: string): void {\n if (!this.isEnabled) return\n\n window.parent.postMessage(\n {\n type: 'FIELD_UPDATE',\n payload: { itemId, field, value },\n },\n '*'\n )\n }\n\n public destroy(): void {\n if (this.isEnabled) {\n window.removeEventListener('message', this.handleMessage)\n this.isEnabled = false\n }\n this.eventListeners = {}\n }\n}\n\nexport const previewBridge = PreviewBridge.getInstance()\n","import type { DirectiveBinding, VNode } from 'vue'\n\nimport type { SelectUpdateEvent } from '../preview-bridge'\n\nimport { previewBridge } from '../preview-bridge'\n\ninterface EditableElement extends HTMLElement {\n _editableCleanup?: () => void\n}\n\nexport const EditableDirective = {\n mounted(el: EditableElement, binding: DirectiveBinding, node: VNode) {\n if (!previewBridge.isInPreviewMode()) return\n const { id: itemId } = binding.value\n\n if (!itemId) {\n // biome-ignore lint/suspicious/noConsole: give developers feedback\n console.warn('v-editable directive requires a block with an id')\n return\n }\n\n el.classList.add('b10cks-preview')\n\n const handleClick = (e: MouseEvent) => {\n e.preventDefault()\n e.stopPropagation()\n previewBridge.selectItem(itemId)\n }\n\n const handleSelectionChange = ({ selectedItem }: SelectUpdateEvent) => {\n if (!node.el) return\n\n if (selectedItem === itemId) {\n node.el.classList.add('b10cks-selected')\n scrollIntoViewIfNeeded(el)\n } else {\n node.el.classList.remove('b10cks-selected')\n }\n }\n\n const handleHoverChange = ({ selectedItem }: SelectUpdateEvent) => {\n if (!node.el) return\n\n if (selectedItem === itemId) {\n node.el.classList.add('b10cks-hover')\n } else {\n node.el.classList.remove('b10cks-hover')\n }\n }\n\n const handleUpdate = ({ content }: { content: any }) => {\n if (content && content.id === itemId) {\n // biome-ignore lint/suspicious/noExplicitAny: use of any to access internal properties\n const ctx = (node as any).ctx\n ctx.parent.attrs.block = content\n ctx.update()\n ctx.props.block = content\n ctx.update()\n }\n }\n\n el.addEventListener('click', handleClick)\n previewBridge.on('SELECT_UPDATE', handleSelectionChange)\n previewBridge.on('HOVER_UPDATE', handleHoverChange)\n previewBridge.on('CONTENT_UPDATE', handleUpdate)\n\n el._editableCleanup = () => {\n el.removeEventListener('click', handleClick)\n }\n },\n\n updated(el: EditableElement, binding: DirectiveBinding, vnode: VNode) {\n if (!previewBridge.isInPreviewMode()) return\n\n if (binding.value !== binding.oldValue) {\n if (el._editableCleanup) {\n el._editableCleanup()\n }\n\n EditableDirective.mounted(el, binding, vnode)\n }\n },\n\n unmounted(el: EditableElement) {\n if (!previewBridge.isInPreviewMode()) return\n\n if (el._editableCleanup) {\n el._editableCleanup()\n delete el._editableCleanup\n }\n\n el.classList.remove('b10cks-preview', 'b10cks-selected')\n },\n}\n\nfunction scrollIntoViewIfNeeded(el: HTMLElement) {\n if (el.scrollIntoView) {\n el.scrollIntoView({ behavior: 'smooth' })\n }\n}\n\nif (previewBridge.isInPreviewMode()) {\n const style = document.createElement('style')\n style.innerHTML = `\n .b10cks-hover,\n .b10cks-preview:hover {\n outline: 2px dashed rgba(59, 130, 246, 0.5);\n outline-offset: 2px;\n }\n .b10cks-selected {\n outline: 2px solid rgb(59, 130, 246) !important;\n outline-offset: 2px;\n }\n `\n document.head.appendChild(style)\n}\n","import type { Directive, DirectiveBinding } from 'vue'\n\nimport { previewBridge } from '../preview-bridge'\n\nexport const EditableContentDirective: Directive<HTMLElement> = {\n mounted(el: HTMLElement, binding: DirectiveBinding) {\n const { id: itemId, field } = binding.value\n if (!previewBridge.isInPreviewMode()) return\n el.setAttribute('contenteditable', 'true')\n\n el.addEventListener('input', (event: Event) => {\n previewBridge.updateField(itemId, field, (event.target as HTMLInputElement).innerText)\n })\n },\n}\n","import type { Plugin } from 'vue'\n\nimport type { B10cksVuePluginOptions } from './types'\n\nimport B10cksComponent from './components/B10cksComponent.vue'\nimport { EditableDirective } from './directives/v-editable'\nimport { EditableContentDirective } from './directives/v-editable-content'\n\nexport { previewBridge } from './preview-bridge'\n\nexport const B10cksVue: Plugin = {\n install(app, pluginOptions: B10cksVuePluginOptions) {\n app.provide('b10cksVueOptions', pluginOptions)\n\n app.directive('editable', EditableDirective)\n app.directive('editable-field', EditableContentDirective)\n app.component('B10cksComponent', B10cksComponent)\n },\n}\n"],"names":["props","__props","blockRef","useTemplateRef","__expose","resolvedComponent","shallowRef","componentName","computed","watch","newComponentName","pascalCaseBlockType","match","defineAsyncComponent","error","_","fail","_createBlock","_resolveDynamicComponent","_mergeProps","$props","$attrs","_openBlock","_createElementBlock","_hoisted_1","_toDisplayString","PreviewBridge","event","type","payload","listeners","listener","eventType","callback","selectedItem","itemId","field","value","previewBridge","EditableDirective","el","binding","node","handleClick","e","handleSelectionChange","scrollIntoViewIfNeeded","handleHoverChange","handleUpdate","content","ctx","vnode","style","EditableContentDirective","B10cksVue","app","pluginOptions","B10cksComponent"],"mappings":"oMAWA,MAAMA,EAAQC,EAIRC,EAAWC,EAAAA,eAAe,UAAU,EAC1CC,EAAa,CAAE,MAAOF,EAAU,EAEhC,MAAMG,EAAoBC,EAAAA,WAA6B,IAAI,EACrDC,EAAgBC,EAAAA,SAAS,IAAMR,EAAM,OAAO,OAAS,IAAI,EAE/DS,OAAAA,EAAAA,MACE,IAAMF,EAAc,MACpB,MAAOG,GAAoC,CACzC,GAAI,CAACA,EAAkB,CACrBL,EAAkB,MAAQ,KAC1B,MACF,CAEA,MAAMM,EAAsBD,EACzB,QAAQ,WAAaE,GAAkBA,EAAM,YAAA,CAAa,EAC1D,QAAQ,kBAAmB,MAAM,EAEpC,GAAI,CACFP,EAAkB,MAAQQ,uBAAqB,CAC7C,OAAQ,IAAM,OAAO,YAAYF,CAAmB,QACpD,QAAS,IACT,QAAS,CAACG,EAAOC,EAAGC,IAAS,CAE3B,QAAQ,KAAK,4CAA4CN,CAAgB,KAAMI,CAAK,EACpFE,EAAA,CACF,CAAA,CACD,CACH,OAASF,EAAO,CAEd,QAAQ,MAAM,6CAA6CJ,CAAgB,KAAMI,CAAK,CACxF,CACF,EACA,CAAE,UAAW,EAAA,CAAK,SAMVT,EAAA,qBAFRY,EAAAA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BC,CAAa,EAE7CD,EAAI,UAAU,WAAYhB,CAAiB,EAC3CgB,EAAI,UAAU,iBAAkBF,CAAwB,EACxDE,EAAI,UAAU,kBAAmBE,CAAe,CAClD,CACF"}
1
+ {"version":3,"file":"index.js","sources":["../src/types.ts","../src/components/B10cksComponent.vue","../src/preview-bridge.ts","../src/directives/v-editable.ts","../src/directives/v-editable-content.ts","../src/index.ts"],"sourcesContent":["import type { B10cksApiClientOptions } from '@b10cks/client'\nimport type { Component, InjectionKey } from 'vue'\n\nexport interface B10cksVuePluginOptions extends B10cksApiClientOptions {}\n\nexport type BlockComponentResolver = (componentName: string) => Promise<Component>\n\nexport const B10cksComponentResolverKey: InjectionKey<BlockComponentResolver> = Symbol(\n 'b10cks:resolveBlockComponent'\n)\n","<script setup lang=\"ts\">\nimport type { IBContent } from '@b10cks/client'\nimport { computed, defineAsyncComponent, inject, shallowRef, useTemplateRef, watch } from 'vue'\n\nimport { B10cksComponentResolverKey } from '../types'\n\nconst props = defineProps<{\n block: IBContent<string> & Record<string, never>\n}>()\n\nconst blockRef = useTemplateRef('blockRef')\ndefineExpose({ value: blockRef })\n\nconst resolvedComponent = shallowRef<ReturnType<typeof defineAsyncComponent> | null>(null)\nconst componentName = computed(() => props.block?.block || null)\n\nconst resolveBlockComponent = inject(B10cksComponentResolverKey, null)\n\nwatch(\n () => componentName.value,\n async (newComponentName: string | null) => {\n if (!newComponentName) {\n resolvedComponent.value = null\n return\n }\n\n if (!resolveBlockComponent) {\n // biome-ignore lint/suspicious/noConsole: give developers feedback\n console.error(\n 'B10cks: No component resolver found. Make sure you are using @b10cks/nuxt module or have provided a custom resolver.'\n )\n resolvedComponent.value = null\n return\n }\n\n try {\n resolvedComponent.value = await resolveBlockComponent(newComponentName)\n } catch (error) {\n // biome-ignore lint/suspicious/noConsole: give developers feedback\n console.warn(`Failed to load block component for type \"${newComponentName}\":`, error)\n resolvedComponent.value = null\n }\n },\n { immediate: true }\n)\n</script>\n<template>\n <component\n :is=\"resolvedComponent\"\n v-if=\"resolvedComponent\"\n ref=\"blockRef\"\n v-bind=\"{ ...$props, ...$attrs }\"\n />\n <div v-else>Component for block type \"{{ componentName }}\" not found.</div>\n</template>\n","export type ContentUpdateEvent = {\n content: Record<string, unknown>\n}\n\nexport type SelectUpdateEvent = {\n selectedItem: string\n}\n\nexport type EventType = 'CONTENT_UPDATE' | 'SELECT_UPDATE' | 'HOVER_UPDATE'\n\nexport type EventPayloadMap = {\n CONTENT_UPDATE: ContentUpdateEvent\n SELECT_UPDATE: SelectUpdateEvent\n HOVER_UPDATE: SelectUpdateEvent\n}\n\nexport type BridgeEvent = {\n type: EventType\n payload: ContentUpdateEvent | SelectUpdateEvent\n b10cksId?: string\n}\n\ntype EventCallback<T> = (payload: T) => void\n\nclass PreviewBridge {\n private static instance: PreviewBridge\n private eventListeners: {\n [key in EventType]?: Array<EventCallback<EventPayloadMap[key]>>\n } = {}\n\n private isEnabled = false\n\n private constructor() {\n this.isEnabled = this.isIframe()\n }\n\n public init(): void {\n if (this.isEnabled && window) {\n window.addEventListener('message', this.handleMessage)\n }\n }\n\n public static getInstance(): PreviewBridge {\n if (!PreviewBridge.instance) {\n PreviewBridge.instance = new PreviewBridge()\n }\n return PreviewBridge.instance\n }\n\n public isInPreviewMode(): boolean {\n return this.isEnabled\n }\n\n private isIframe(): boolean {\n return typeof window !== 'undefined' && window.self !== window.top\n }\n\n private handleMessage = (event: MessageEvent): void => {\n if (!event.data || typeof event.data !== 'object') return\n const { type, payload } = event.data as BridgeEvent\n\n this.notifyListeners(type as EventType, payload)\n }\n\n private notifyListeners<T extends EventType>(type: T, payload: EventPayloadMap[T]): void {\n const listeners = this.eventListeners[type] as\n | Array<EventCallback<EventPayloadMap[T]>>\n | undefined\n\n if (listeners) {\n listeners.forEach((listener) => {\n listener(payload)\n })\n }\n }\n\n public on<T extends EventType>(\n eventType: T,\n callback: EventCallback<EventPayloadMap[T]>\n ): () => void {\n if (!this.isEnabled) return () => {}\n\n if (!this.eventListeners[eventType]) {\n this.eventListeners[eventType] = []\n }\n\n ;(this.eventListeners[eventType] as Array<EventCallback<EventPayloadMap[T]>>).push(callback)\n\n return () => {\n this.eventListeners[eventType] = (\n this.eventListeners[eventType] as Array<EventCallback<EventPayloadMap[T]>>\n ).filter((listener) => listener !== callback) as never\n }\n }\n\n public selectItem(selectedItem: string): void {\n if (!this.isEnabled) return\n\n window.parent.postMessage(\n {\n type: 'SELECT_UPDATE',\n payload: { selectedItem },\n },\n '*'\n )\n }\n\n public updateField(itemId: string, field: string, value: string): void {\n if (!this.isEnabled) return\n\n window.parent.postMessage(\n {\n type: 'FIELD_UPDATE',\n payload: { itemId, field, value },\n },\n '*'\n )\n }\n\n public destroy(): void {\n if (this.isEnabled) {\n window.removeEventListener('message', this.handleMessage)\n this.isEnabled = false\n }\n this.eventListeners = {}\n }\n}\n\nexport const previewBridge = PreviewBridge.getInstance()\n","import type { DirectiveBinding, VNode } from 'vue'\n\nimport type { SelectUpdateEvent } from '../preview-bridge'\n\nimport { previewBridge } from '../preview-bridge'\n\ninterface EditableElement extends HTMLElement {\n _editableCleanup?: () => void\n}\n\nexport const EditableDirective = {\n mounted(el: EditableElement, binding: DirectiveBinding, node: VNode) {\n if (!previewBridge.isInPreviewMode()) return\n const { id: itemId } = binding.value\n\n if (!itemId) {\n // biome-ignore lint/suspicious/noConsole: give developers feedback\n console.warn('v-editable directive requires a block with an id')\n return\n }\n\n el.classList.add('b10cks-preview')\n\n const handleClick = (e: MouseEvent) => {\n e.preventDefault()\n e.stopPropagation()\n previewBridge.selectItem(itemId)\n }\n\n const handleSelectionChange = ({ selectedItem }: SelectUpdateEvent) => {\n if (!node.el) return\n\n if (selectedItem === itemId) {\n node.el.classList.add('b10cks-selected')\n scrollIntoViewIfNeeded(el)\n } else {\n node.el.classList.remove('b10cks-selected')\n }\n }\n\n const handleHoverChange = ({ selectedItem }: SelectUpdateEvent) => {\n if (!node.el) return\n\n if (selectedItem === itemId) {\n node.el.classList.add('b10cks-hover')\n } else {\n node.el.classList.remove('b10cks-hover')\n }\n }\n\n const handleUpdate = ({ content }: { content: any }) => {\n if (content && content.id === itemId) {\n // biome-ignore lint/suspicious/noExplicitAny: use of any to access internal properties\n const ctx = (node as any).ctx\n ctx.parent.attrs.block = content\n ctx.update()\n ctx.props.block = content\n ctx.update()\n }\n }\n\n el.addEventListener('click', handleClick)\n previewBridge.on('SELECT_UPDATE', handleSelectionChange)\n previewBridge.on('HOVER_UPDATE', handleHoverChange)\n previewBridge.on('CONTENT_UPDATE', handleUpdate)\n\n el._editableCleanup = () => {\n el.removeEventListener('click', handleClick)\n }\n },\n\n updated(el: EditableElement, binding: DirectiveBinding, vnode: VNode) {\n if (!previewBridge.isInPreviewMode()) return\n\n if (binding.value !== binding.oldValue) {\n if (el._editableCleanup) {\n el._editableCleanup()\n }\n\n EditableDirective.mounted(el, binding, vnode)\n }\n },\n\n unmounted(el: EditableElement) {\n if (!previewBridge.isInPreviewMode()) return\n\n if (el._editableCleanup) {\n el._editableCleanup()\n delete el._editableCleanup\n }\n\n el.classList.remove('b10cks-preview', 'b10cks-selected')\n },\n}\n\nfunction scrollIntoViewIfNeeded(el: HTMLElement) {\n if (el.scrollIntoView) {\n el.scrollIntoView({ behavior: 'smooth' })\n }\n}\n\nif (previewBridge.isInPreviewMode()) {\n const style = document.createElement('style')\n style.innerHTML = `\n .b10cks-hover,\n .b10cks-preview:hover {\n outline: 2px dashed rgba(59, 130, 246, 0.5);\n outline-offset: 2px;\n }\n .b10cks-selected {\n outline: 2px solid rgb(59, 130, 246) !important;\n outline-offset: 2px;\n }\n `\n document.head.appendChild(style)\n}\n","import type { Directive, DirectiveBinding } from 'vue'\n\nimport { previewBridge } from '../preview-bridge'\n\nexport const EditableContentDirective: Directive<HTMLElement> = {\n mounted(el: HTMLElement, binding: DirectiveBinding) {\n const { id: itemId, field } = binding.value\n if (!previewBridge.isInPreviewMode()) return\n el.setAttribute('contenteditable', 'true')\n\n el.addEventListener('input', (event: Event) => {\n previewBridge.updateField(itemId, field, (event.target as HTMLInputElement).innerText)\n })\n },\n}\n","import type { Plugin } from 'vue'\n\nimport type { B10cksVuePluginOptions } from './types'\n\nimport B10cksComponent from './components/B10cksComponent.vue'\nimport { EditableDirective } from './directives/v-editable'\nimport { EditableContentDirective } from './directives/v-editable-content'\n\nexport { previewBridge } from './preview-bridge'\nexport { B10cksComponentResolverKey, type BlockComponentResolver } from './types'\n\nexport const B10cksVue: Plugin = {\n install(app, pluginOptions: B10cksVuePluginOptions) {\n app.provide('b10cksVueOptions', pluginOptions)\n\n app.directive('editable', EditableDirective)\n app.directive('editable-field', EditableContentDirective)\n app.component('B10cksComponent', B10cksComponent)\n },\n}\n"],"names":["B10cksComponentResolverKey","props","__props","blockRef","useTemplateRef","__expose","resolvedComponent","shallowRef","componentName","computed","resolveBlockComponent","inject","watch","newComponentName","error","_createBlock","_resolveDynamicComponent","_mergeProps","$props","$attrs","_openBlock","_createElementBlock","_hoisted_1","_toDisplayString","PreviewBridge","event","type","payload","listeners","listener","eventType","callback","selectedItem","itemId","field","value","previewBridge","EditableDirective","el","binding","node","handleClick","e","handleSelectionChange","scrollIntoViewIfNeeded","handleHoverChange","handleUpdate","content","ctx","vnode","style","EditableContentDirective","B10cksVue","app","pluginOptions","B10cksComponent"],"mappings":"uGAOaA,EAAmE,OAC9E,8BACF,+FCHA,MAAMC,EAAQC,EAIRC,EAAWC,EAAAA,eAAe,UAAU,EAC1CC,EAAa,CAAE,MAAOF,EAAU,EAEhC,MAAMG,EAAoBC,EAAAA,WAA2D,IAAI,EACnFC,EAAgBC,EAAAA,SAAS,IAAMR,EAAM,OAAO,OAAS,IAAI,EAEzDS,EAAwBC,EAAAA,OAAOX,EAA4B,IAAI,EAErEY,OAAAA,EAAAA,MACE,IAAMJ,EAAc,MACpB,MAAOK,GAAoC,CACzC,GAAI,CAACA,EAAkB,CACrBP,EAAkB,MAAQ,KAC1B,MACF,CAEA,GAAI,CAACI,EAAuB,CAE1B,QAAQ,MAC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Q,MAAAC,CAAA,EAAUK,EAAQ,MACjCH,EAAc,oBACnBE,EAAG,aAAa,kBAAmB,MAAM,EAEzCA,EAAG,iBAAiB,QAAUb,GAAiB,CAC7CW,EAAc,YAAYH,EAAQC,EAAQT,EAAM,OAA4B,SAAS,CACvF,CAAC,EACH,CACF,ECHa2B,EAAoB,CAC/B,QAAQC,EAAKC,EAAuC,CAClDD,EAAI,QAAQ,mBAAoBC,CAAa,EAE7CD,EAAI,UAAU,WAAYhB,CAAiB,EAC3CgB,EAAI,UAAU,iBAAkBF,CAAwB,EACxDE,EAAI,UAAU,kBAAmBE,CAAe,CAClD,CACF"}
package/dist/index.mjs CHANGED
@@ -1,42 +1,43 @@
1
- import { defineComponent as b, useTemplateRef as h, shallowRef as m, computed as k, watch as E, defineAsyncComponent as w, createBlock as L, createElementBlock as y, openBlock as p, resolveDynamicComponent as C, mergeProps as I, toDisplayString as g } from "vue";
2
- const _ = { key: 1 }, M = /* @__PURE__ */ b({
1
+ import { defineComponent as v, useTemplateRef as b, shallowRef as h, computed as m, inject as k, watch as w, createBlock as E, createElementBlock as L, openBlock as p, resolveDynamicComponent as y, mergeProps as C, toDisplayString as I } from "vue";
2
+ const g = Symbol(
3
+ "b10cks:resolveBlockComponent"
4
+ ), _ = { key: 1 }, M = /* @__PURE__ */ v({
3
5
  __name: "B10cksComponent",
4
6
  props: {
5
7
  block: {}
6
8
  },
7
9
  setup(e, { expose: t }) {
8
- const s = e, n = h("blockRef");
10
+ const s = e, n = b("blockRef");
9
11
  t({ value: n });
10
- const o = m(null), d = k(() => s.block?.block || null);
11
- return E(
12
- () => d.value,
13
- async (a) => {
14
- if (!a) {
12
+ const o = h(null), c = m(() => s.block?.block || null), d = k(g, null);
13
+ return w(
14
+ () => c.value,
15
+ async (l) => {
16
+ if (!l) {
15
17
  o.value = null;
16
18
  return;
17
19
  }
18
- const u = a.replace(/^([a-z])/, (i) => i.toUpperCase()).replace(/([a-z])([A-Z])/g, "$1$2");
20
+ if (!d) {
21
+ console.error(
22
+ "B10cks: No component resolver found. Make sure you are using @b10cks/nuxt module or have provided a custom resolver."
23
+ ), o.value = null;
24
+ return;
25
+ }
19
26
  try {
20
- o.value = w({
21
- loader: () => import(`~/b10cks/${u}.vue`),
22
- timeout: 3e3,
23
- onError: (i, c, v) => {
24
- console.warn(`Failed to load block component for type "${a}":`, i), v();
25
- }
26
- });
27
+ o.value = await d(l);
27
28
  } catch (i) {
28
- console.error(`Error resolving component for block type "${a}":`, i);
29
+ console.warn(`Failed to load block component for type "${l}":`, i), o.value = null;
29
30
  }
30
31
  },
31
32
  { immediate: !0 }
32
- ), (a, u) => o.value ? (p(), L(C(o.value), I({
33
+ ), (l, i) => o.value ? (p(), E(y(o.value), C({
33
34
  key: 0,
34
35
  ref_key: "blockRef",
35
36
  ref: n
36
- }, { ...a.$props, ...a.$attrs }), null, 16)) : (p(), y("div", _, 'Component for block type "' + g(d.value) + '" not found.', 1));
37
+ }, { ...l.$props, ...l.$attrs }), null, 16)) : (p(), L("div", _, 'Component for block type "' + I(c.value) + '" not found.', 1));
37
38
  }
38
39
  });
39
- class l {
40
+ class a {
40
41
  static instance;
41
42
  eventListeners = {};
42
43
  isEnabled = !1;
@@ -47,13 +48,13 @@ class l {
47
48
  this.isEnabled && window && window.addEventListener("message", this.handleMessage);
48
49
  }
49
50
  static getInstance() {
50
- return l.instance || (l.instance = new l()), l.instance;
51
+ return a.instance || (a.instance = new a()), a.instance;
51
52
  }
52
53
  isInPreviewMode() {
53
54
  return this.isEnabled;
54
55
  }
55
56
  isIframe() {
56
- return window && window.self !== window.top;
57
+ return typeof window < "u" && window.self !== window.top;
57
58
  }
58
59
  handleMessage = (t) => {
59
60
  if (!t.data || typeof t.data != "object") return;
@@ -94,7 +95,7 @@ class l {
94
95
  this.isEnabled && (window.removeEventListener("message", this.handleMessage), this.isEnabled = !1), this.eventListeners = {};
95
96
  }
96
97
  }
97
- const r = l.getInstance(), f = {
98
+ const r = a.getInstance(), f = {
98
99
  mounted(e, t, s) {
99
100
  if (!r.isInPreviewMode()) return;
100
101
  const { id: n } = t.value;
@@ -105,17 +106,17 @@ const r = l.getInstance(), f = {
105
106
  e.classList.add("b10cks-preview");
106
107
  const o = (i) => {
107
108
  i.preventDefault(), i.stopPropagation(), r.selectItem(n);
108
- }, d = ({ selectedItem: i }) => {
109
+ }, c = ({ selectedItem: i }) => {
109
110
  s.el && (i === n ? (s.el.classList.add("b10cks-selected"), D(e)) : s.el.classList.remove("b10cks-selected"));
110
- }, a = ({ selectedItem: i }) => {
111
+ }, d = ({ selectedItem: i }) => {
111
112
  s.el && (i === n ? s.el.classList.add("b10cks-hover") : s.el.classList.remove("b10cks-hover"));
112
- }, u = ({ content: i }) => {
113
+ }, l = ({ content: i }) => {
113
114
  if (i && i.id === n) {
114
- const c = s.ctx;
115
- c.parent.attrs.block = i, c.update(), c.props.block = i, c.update();
115
+ const u = s.ctx;
116
+ u.parent.attrs.block = i, u.update(), u.props.block = i, u.update();
116
117
  }
117
118
  };
118
- e.addEventListener("click", o), r.on("SELECT_UPDATE", d), r.on("HOVER_UPDATE", a), r.on("CONTENT_UPDATE", u), e._editableCleanup = () => {
119
+ e.addEventListener("click", o), r.on("SELECT_UPDATE", c), r.on("HOVER_UPDATE", d), r.on("CONTENT_UPDATE", l), e._editableCleanup = () => {
119
120
  e.removeEventListener("click", o);
120
121
  };
121
122
  },
@@ -150,13 +151,14 @@ const P = {
150
151
  r.updateField(s, n, o.target.innerText);
151
152
  }));
152
153
  }
153
- }, x = {
154
+ }, B = {
154
155
  install(e, t) {
155
156
  e.provide("b10cksVueOptions", t), e.directive("editable", f), e.directive("editable-field", P), e.component("B10cksComponent", M);
156
157
  }
157
158
  };
158
159
  export {
159
- x as B10cksVue,
160
+ g as B10cksComponentResolverKey,
161
+ B as B10cksVue,
160
162
  r as previewBridge
161
163
  };
162
164
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/components/B10cksComponent.vue","../src/preview-bridge.ts","../src/directives/v-editable.ts","../src/directives/v-editable-content.ts","../src/index.ts"],"sourcesContent":["<script setup lang=\"ts\">\nimport type { IBContent } from '@b10cks/client'\nimport {\n type Component,\n computed,\n defineAsyncComponent,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\n\nconst props = defineProps<{\n block: IBContent<string> & Record<string, never>\n}>()\n\nconst blockRef = useTemplateRef('blockRef')\ndefineExpose({ value: blockRef })\n\nconst resolvedComponent = shallowRef<Component | null>(null)\nconst componentName = computed(() => props.block?.block || null)\n\nwatch(\n () => componentName.value,\n async (newComponentName: string | null) => {\n if (!newComponentName) {\n resolvedComponent.value = null\n return\n }\n\n const pascalCaseBlockType = newComponentName\n .replace(/^([a-z])/, (match: string) => match.toUpperCase())\n .replace(/([a-z])([A-Z])/g, '$1$2')\n\n try {\n resolvedComponent.value = defineAsyncComponent({\n loader: () => import(`~/b10cks/${pascalCaseBlockType}.vue`),\n timeout: 3000,\n onError: (error, _, fail) => {\n // biome-ignore lint/suspicious/noConsole: give developers feedback\n console.warn(`Failed to load block component for type \"${newComponentName}\":`, error)\n fail()\n },\n })\n } catch (error) {\n // biome-ignore lint/suspicious/noConsole: give developers feedback\n console.error(`Error resolving component for block type \"${newComponentName}\":`, error)\n }\n },\n { immediate: true }\n)\n</script>\n<template>\n <component\n :is=\"resolvedComponent\"\n v-if=\"resolvedComponent\"\n ref=\"blockRef\"\n v-bind=\"{ ...$props, ...$attrs }\"\n />\n <div v-else>Component for block type \"{{ componentName }}\" not found.</div>\n</template>\n","export type ContentUpdateEvent = {\n content: Record<string, unknown>\n}\n\nexport type SelectUpdateEvent = {\n selectedItem: string\n}\n\nexport type EventType = 'CONTENT_UPDATE' | 'SELECT_UPDATE' | 'HOVER_UPDATE'\n\nexport type EventPayloadMap = {\n CONTENT_UPDATE: ContentUpdateEvent\n SELECT_UPDATE: SelectUpdateEvent\n HOVER_UPDATE: SelectUpdateEvent\n}\n\nexport type BridgeEvent = {\n type: EventType\n payload: ContentUpdateEvent | SelectUpdateEvent\n b10cksId?: string\n}\n\ntype EventCallback<T> = (payload: T) => void\n\nclass PreviewBridge {\n private static instance: PreviewBridge\n private eventListeners: {\n [key in EventType]?: Array<EventCallback<EventPayloadMap[key]>>\n } = {}\n\n private isEnabled = false\n\n private constructor() {\n this.isEnabled = this.isIframe()\n }\n\n public init(): void {\n if (this.isEnabled && window) {\n window.addEventListener('message', this.handleMessage)\n }\n }\n\n public static getInstance(): PreviewBridge {\n if (!PreviewBridge.instance) {\n PreviewBridge.instance = new PreviewBridge()\n }\n return PreviewBridge.instance\n }\n\n public isInPreviewMode(): boolean {\n return this.isEnabled\n }\n\n private isIframe(): boolean {\n return window && window.self !== window.top\n }\n\n private handleMessage = (event: MessageEvent): void => {\n if (!event.data || typeof event.data !== 'object') return\n const { type, payload } = event.data as BridgeEvent\n\n this.notifyListeners(type as EventType, payload)\n }\n\n private notifyListeners<T extends EventType>(type: T, payload: EventPayloadMap[T]): void {\n const listeners = this.eventListeners[type] as\n | Array<EventCallback<EventPayloadMap[T]>>\n | undefined\n\n if (listeners) {\n listeners.forEach((listener) => {\n listener(payload)\n })\n }\n }\n\n public on<T extends EventType>(\n eventType: T,\n callback: EventCallback<EventPayloadMap[T]>\n ): () => void {\n if (!this.isEnabled) return () => {}\n\n if (!this.eventListeners[eventType]) {\n this.eventListeners[eventType] = []\n }\n\n ;(this.eventListeners[eventType] as Array<EventCallback<EventPayloadMap[T]>>).push(callback)\n\n return () => {\n this.eventListeners[eventType] = (\n this.eventListeners[eventType] as Array<EventCallback<EventPayloadMap[T]>>\n ).filter((listener) => listener !== callback) as never\n }\n }\n\n public selectItem(selectedItem: string): void {\n if (!this.isEnabled) return\n\n window.parent.postMessage(\n {\n type: 'SELECT_UPDATE',\n payload: { selectedItem },\n },\n '*'\n )\n }\n\n public updateField(itemId: string, field: string, value: string): void {\n if (!this.isEnabled) return\n\n window.parent.postMessage(\n {\n type: 'FIELD_UPDATE',\n payload: { itemId, field, value },\n },\n '*'\n )\n }\n\n public destroy(): void {\n if (this.isEnabled) {\n window.removeEventListener('message', this.handleMessage)\n this.isEnabled = false\n }\n this.eventListeners = {}\n }\n}\n\nexport const previewBridge = PreviewBridge.getInstance()\n","import type { DirectiveBinding, VNode } from 'vue'\n\nimport type { SelectUpdateEvent } from '../preview-bridge'\n\nimport { previewBridge } from '../preview-bridge'\n\ninterface EditableElement extends HTMLElement {\n _editableCleanup?: () => void\n}\n\nexport const EditableDirective = {\n mounted(el: EditableElement, binding: DirectiveBinding, node: VNode) {\n if (!previewBridge.isInPreviewMode()) return\n const { id: itemId } = binding.value\n\n if (!itemId) {\n // biome-ignore lint/suspicious/noConsole: give developers feedback\n console.warn('v-editable directive requires a block with an id')\n return\n }\n\n el.classList.add('b10cks-preview')\n\n const handleClick = (e: MouseEvent) => {\n e.preventDefault()\n e.stopPropagation()\n previewBridge.selectItem(itemId)\n }\n\n const handleSelectionChange = ({ selectedItem }: SelectUpdateEvent) => {\n if (!node.el) return\n\n if (selectedItem === itemId) {\n node.el.classList.add('b10cks-selected')\n scrollIntoViewIfNeeded(el)\n } else {\n node.el.classList.remove('b10cks-selected')\n }\n }\n\n const handleHoverChange = ({ selectedItem }: SelectUpdateEvent) => {\n if (!node.el) return\n\n if (selectedItem === itemId) {\n node.el.classList.add('b10cks-hover')\n } else {\n node.el.classList.remove('b10cks-hover')\n }\n }\n\n const handleUpdate = ({ content }: { content: any }) => {\n if (content && content.id === itemId) {\n // biome-ignore lint/suspicious/noExplicitAny: use of any to access internal properties\n const ctx = (node as any).ctx\n ctx.parent.attrs.block = content\n ctx.update()\n ctx.props.block = content\n ctx.update()\n }\n }\n\n el.addEventListener('click', handleClick)\n previewBridge.on('SELECT_UPDATE', handleSelectionChange)\n previewBridge.on('HOVER_UPDATE', handleHoverChange)\n previewBridge.on('CONTENT_UPDATE', handleUpdate)\n\n el._editableCleanup = () => {\n el.removeEventListener('click', handleClick)\n }\n },\n\n updated(el: EditableElement, binding: DirectiveBinding, vnode: VNode) {\n if (!previewBridge.isInPreviewMode()) return\n\n if (binding.value !== binding.oldValue) {\n if (el._editableCleanup) {\n el._editableCleanup()\n }\n\n EditableDirective.mounted(el, binding, vnode)\n }\n },\n\n unmounted(el: EditableElement) {\n if (!previewBridge.isInPreviewMode()) return\n\n if (el._editableCleanup) {\n el._editableCleanup()\n delete el._editableCleanup\n }\n\n el.classList.remove('b10cks-preview', 'b10cks-selected')\n },\n}\n\nfunction scrollIntoViewIfNeeded(el: HTMLElement) {\n if (el.scrollIntoView) {\n el.scrollIntoView({ behavior: 'smooth' })\n }\n}\n\nif (previewBridge.isInPreviewMode()) {\n const style = document.createElement('style')\n style.innerHTML = `\n .b10cks-hover,\n .b10cks-preview:hover {\n outline: 2px dashed rgba(59, 130, 246, 0.5);\n outline-offset: 2px;\n }\n .b10cks-selected {\n outline: 2px solid rgb(59, 130, 246) !important;\n outline-offset: 2px;\n }\n `\n document.head.appendChild(style)\n}\n","import type { Directive, DirectiveBinding } from 'vue'\n\nimport { previewBridge } from '../preview-bridge'\n\nexport const EditableContentDirective: Directive<HTMLElement> = {\n mounted(el: HTMLElement, binding: DirectiveBinding) {\n const { id: itemId, field } = binding.value\n if (!previewBridge.isInPreviewMode()) return\n el.setAttribute('contenteditable', 'true')\n\n el.addEventListener('input', (event: Event) => {\n previewBridge.updateField(itemId, field, (event.target as HTMLInputElement).innerText)\n })\n },\n}\n","import type { Plugin } from 'vue'\n\nimport type { B10cksVuePluginOptions } from './types'\n\nimport B10cksComponent from './components/B10cksComponent.vue'\nimport { EditableDirective } from './directives/v-editable'\nimport { EditableContentDirective } from './directives/v-editable-content'\n\nexport { previewBridge } from './preview-bridge'\n\nexport const B10cksVue: Plugin = {\n install(app, pluginOptions: B10cksVuePluginOptions) {\n app.provide('b10cksVueOptions', pluginOptions)\n\n app.directive('editable', EditableDirective)\n app.directive('editable-field', EditableContentDirective)\n app.component('B10cksComponent', B10cksComponent)\n },\n}\n"],"names":["props","__props","blockRef","useTemplateRef","__expose","resolvedComponent","shallowRef","componentName","computed","watch","newComponentName","pascalCaseBlockType","match","defineAsyncComponent","error","_","fail","_createBlock","_resolveDynamicComponent","_mergeProps","$props","$attrs","_openBlock","_createElementBlock","_hoisted_1","_toDisplayString","PreviewBridge","event","type","payload","listeners","listener","eventType","callback","selectedItem","itemId","field","value","previewBridge","EditableDirective","el","binding","node","handleClick","e","handleSelectionChange","scrollIntoViewIfNeeded","handleHoverChange","handleUpdate","content","ctx","vnode","style","EditableContentDirective","B10cksVue","app","pluginOptions","B10cksComponent"],"mappings":";;;;;;;AAWA,UAAMA,IAAQC,GAIRC,IAAWC,EAAe,UAAU;AAC1C,IAAAC,EAAa,EAAE,OAAOF,GAAU;AAEhC,UAAMG,IAAoBC,EAA6B,IAAI,GACrDC,IAAgBC,EAAS,MAAMR,EAAM,OAAO,SAAS,IAAI;AAE/D,WAAAS;AAAA,MACE,MAAMF,EAAc;AAAA,MACpB,OAAOG,MAAoC;AACzC,YAAI,CAACA,GAAkB;AACrB,UAAAL,EAAkB,QAAQ;AAC1B;AAAA,QACF;AAEA,cAAMM,IAAsBD,EACzB,QAAQ,YAAY,CAACE,MAAkBA,EAAM,YAAA,CAAa,EAC1D,QAAQ,mBAAmB,MAAM;AAEpC,YAAI;AACF,UAAAP,EAAkB,QAAQQ,EAAqB;AAAA,YAC7C,QAAQ,MAAM,OAAO,YAAYF,CAAmB;AAAA,YACpD,SAAS;AAAA,YACT,SAAS,CAACG,GAAOC,GAAGC,MAAS;AAE3B,sBAAQ,KAAK,4CAA4CN,CAAgB,MAAMI,CAAK,GACpFE,EAAA;AAAA,YACF;AAAA,UAAA,CACD;AAAA,QACH,SAASF,GAAO;AAEd,kBAAQ,MAAM,6CAA6CJ,CAAgB,MAAMI,CAAK;AAAA,QACxF;AAAA,MACF;AAAA,MACA,EAAE,WAAW,GAAA;AAAA,IAAK,aAMVT,EAAA,cAFRY,EAKEC,EAJKb,EAAA,KAAiB,GADxBc,EAKE;AAA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A;AAAA;AAAA;AAAA;AAAA,KAWlB,SAAS,KAAK,YAAYA,CAAK;AACjC;AC/GO,MAAMC,IAAmD;AAAA,EAC9D,QAAQb,GAAiBC,GAA2B;AAClD,UAAM,EAAE,IAAIN,GAAQ,OAAAC,EAAA,IAAUK,EAAQ;AACtC,IAAKH,EAAc,sBACnBE,EAAG,aAAa,mBAAmB,MAAM,GAEzCA,EAAG,iBAAiB,SAAS,CAACb,MAAiB;AAC7C,MAAAW,EAAc,YAAYH,GAAQC,GAAQT,EAAM,OAA4B,SAAS;AAAA,IACvF,CAAC;AAAA,EACH;AACF,GCJa2B,IAAoB;AAAA,EAC/B,QAAQC,GAAKC,GAAuC;AAClD,IAAAD,EAAI,QAAQ,oBAAoBC,CAAa,GAE7CD,EAAI,UAAU,YAAYhB,CAAiB,GAC3CgB,EAAI,UAAU,kBAAkBF,CAAwB,GACxDE,EAAI,UAAU,mBAAmBE,CAAe;AAAA,EAClD;AACF;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/types.ts","../src/components/B10cksComponent.vue","../src/preview-bridge.ts","../src/directives/v-editable.ts","../src/directives/v-editable-content.ts","../src/index.ts"],"sourcesContent":["import type { B10cksApiClientOptions } from '@b10cks/client'\nimport type { Component, InjectionKey } from 'vue'\n\nexport interface B10cksVuePluginOptions extends B10cksApiClientOptions {}\n\nexport type BlockComponentResolver = (componentName: string) => Promise<Component>\n\nexport const B10cksComponentResolverKey: InjectionKey<BlockComponentResolver> = Symbol(\n 'b10cks:resolveBlockComponent'\n)\n","<script setup lang=\"ts\">\nimport type { IBContent } from '@b10cks/client'\nimport { computed, defineAsyncComponent, inject, shallowRef, useTemplateRef, watch } from 'vue'\n\nimport { B10cksComponentResolverKey } from '../types'\n\nconst props = defineProps<{\n block: IBContent<string> & Record<string, never>\n}>()\n\nconst blockRef = useTemplateRef('blockRef')\ndefineExpose({ value: blockRef })\n\nconst resolvedComponent = shallowRef<ReturnType<typeof defineAsyncComponent> | null>(null)\nconst componentName = computed(() => props.block?.block || null)\n\nconst resolveBlockComponent = inject(B10cksComponentResolverKey, null)\n\nwatch(\n () => componentName.value,\n async (newComponentName: string | null) => {\n if (!newComponentName) {\n resolvedComponent.value = null\n return\n }\n\n if (!resolveBlockComponent) {\n // biome-ignore lint/suspicious/noConsole: give developers feedback\n console.error(\n 'B10cks: No component resolver found. Make sure you are using @b10cks/nuxt module or have provided a custom resolver.'\n )\n resolvedComponent.value = null\n return\n }\n\n try {\n resolvedComponent.value = await resolveBlockComponent(newComponentName)\n } catch (error) {\n // biome-ignore lint/suspicious/noConsole: give developers feedback\n console.warn(`Failed to load block component for type \"${newComponentName}\":`, error)\n resolvedComponent.value = null\n }\n },\n { immediate: true }\n)\n</script>\n<template>\n <component\n :is=\"resolvedComponent\"\n v-if=\"resolvedComponent\"\n ref=\"blockRef\"\n v-bind=\"{ ...$props, ...$attrs }\"\n />\n <div v-else>Component for block type \"{{ componentName }}\" not found.</div>\n</template>\n","export type ContentUpdateEvent = {\n content: Record<string, unknown>\n}\n\nexport type SelectUpdateEvent = {\n selectedItem: string\n}\n\nexport type EventType = 'CONTENT_UPDATE' | 'SELECT_UPDATE' | 'HOVER_UPDATE'\n\nexport type EventPayloadMap = {\n CONTENT_UPDATE: ContentUpdateEvent\n SELECT_UPDATE: SelectUpdateEvent\n HOVER_UPDATE: SelectUpdateEvent\n}\n\nexport type BridgeEvent = {\n type: EventType\n payload: ContentUpdateEvent | SelectUpdateEvent\n b10cksId?: string\n}\n\ntype EventCallback<T> = (payload: T) => void\n\nclass PreviewBridge {\n private static instance: PreviewBridge\n private eventListeners: {\n [key in EventType]?: Array<EventCallback<EventPayloadMap[key]>>\n } = {}\n\n private isEnabled = false\n\n private constructor() {\n this.isEnabled = this.isIframe()\n }\n\n public init(): void {\n if (this.isEnabled && window) {\n window.addEventListener('message', this.handleMessage)\n }\n }\n\n public static getInstance(): PreviewBridge {\n if (!PreviewBridge.instance) {\n PreviewBridge.instance = new PreviewBridge()\n }\n return PreviewBridge.instance\n }\n\n public isInPreviewMode(): boolean {\n return this.isEnabled\n }\n\n private isIframe(): boolean {\n return typeof window !== 'undefined' && window.self !== window.top\n }\n\n private handleMessage = (event: MessageEvent): void => {\n if (!event.data || typeof event.data !== 'object') return\n const { type, payload } = event.data as BridgeEvent\n\n this.notifyListeners(type as EventType, payload)\n }\n\n private notifyListeners<T extends EventType>(type: T, payload: EventPayloadMap[T]): void {\n const listeners = this.eventListeners[type] as\n | Array<EventCallback<EventPayloadMap[T]>>\n | undefined\n\n if (listeners) {\n listeners.forEach((listener) => {\n listener(payload)\n })\n }\n }\n\n public on<T extends EventType>(\n eventType: T,\n callback: EventCallback<EventPayloadMap[T]>\n ): () => void {\n if (!this.isEnabled) return () => {}\n\n if (!this.eventListeners[eventType]) {\n this.eventListeners[eventType] = []\n }\n\n ;(this.eventListeners[eventType] as Array<EventCallback<EventPayloadMap[T]>>).push(callback)\n\n return () => {\n this.eventListeners[eventType] = (\n this.eventListeners[eventType] as Array<EventCallback<EventPayloadMap[T]>>\n ).filter((listener) => listener !== callback) as never\n }\n }\n\n public selectItem(selectedItem: string): void {\n if (!this.isEnabled) return\n\n window.parent.postMessage(\n {\n type: 'SELECT_UPDATE',\n payload: { selectedItem },\n },\n '*'\n )\n }\n\n public updateField(itemId: string, field: string, value: string): void {\n if (!this.isEnabled) return\n\n window.parent.postMessage(\n {\n type: 'FIELD_UPDATE',\n payload: { itemId, field, value },\n },\n '*'\n )\n }\n\n public destroy(): void {\n if (this.isEnabled) {\n window.removeEventListener('message', this.handleMessage)\n this.isEnabled = false\n }\n this.eventListeners = {}\n }\n}\n\nexport const previewBridge = PreviewBridge.getInstance()\n","import type { DirectiveBinding, VNode } from 'vue'\n\nimport type { SelectUpdateEvent } from '../preview-bridge'\n\nimport { previewBridge } from '../preview-bridge'\n\ninterface EditableElement extends HTMLElement {\n _editableCleanup?: () => void\n}\n\nexport const EditableDirective = {\n mounted(el: EditableElement, binding: DirectiveBinding, node: VNode) {\n if (!previewBridge.isInPreviewMode()) return\n const { id: itemId } = binding.value\n\n if (!itemId) {\n // biome-ignore lint/suspicious/noConsole: give developers feedback\n console.warn('v-editable directive requires a block with an id')\n return\n }\n\n el.classList.add('b10cks-preview')\n\n const handleClick = (e: MouseEvent) => {\n e.preventDefault()\n e.stopPropagation()\n previewBridge.selectItem(itemId)\n }\n\n const handleSelectionChange = ({ selectedItem }: SelectUpdateEvent) => {\n if (!node.el) return\n\n if (selectedItem === itemId) {\n node.el.classList.add('b10cks-selected')\n scrollIntoViewIfNeeded(el)\n } else {\n node.el.classList.remove('b10cks-selected')\n }\n }\n\n const handleHoverChange = ({ selectedItem }: SelectUpdateEvent) => {\n if (!node.el) return\n\n if (selectedItem === itemId) {\n node.el.classList.add('b10cks-hover')\n } else {\n node.el.classList.remove('b10cks-hover')\n }\n }\n\n const handleUpdate = ({ content }: { content: any }) => {\n if (content && content.id === itemId) {\n // biome-ignore lint/suspicious/noExplicitAny: use of any to access internal properties\n const ctx = (node as any).ctx\n ctx.parent.attrs.block = content\n ctx.update()\n ctx.props.block = content\n ctx.update()\n }\n }\n\n el.addEventListener('click', handleClick)\n previewBridge.on('SELECT_UPDATE', handleSelectionChange)\n previewBridge.on('HOVER_UPDATE', handleHoverChange)\n previewBridge.on('CONTENT_UPDATE', handleUpdate)\n\n el._editableCleanup = () => {\n el.removeEventListener('click', handleClick)\n }\n },\n\n updated(el: EditableElement, binding: DirectiveBinding, vnode: VNode) {\n if (!previewBridge.isInPreviewMode()) return\n\n if (binding.value !== binding.oldValue) {\n if (el._editableCleanup) {\n el._editableCleanup()\n }\n\n EditableDirective.mounted(el, binding, vnode)\n }\n },\n\n unmounted(el: EditableElement) {\n if (!previewBridge.isInPreviewMode()) return\n\n if (el._editableCleanup) {\n el._editableCleanup()\n delete el._editableCleanup\n }\n\n el.classList.remove('b10cks-preview', 'b10cks-selected')\n },\n}\n\nfunction scrollIntoViewIfNeeded(el: HTMLElement) {\n if (el.scrollIntoView) {\n el.scrollIntoView({ behavior: 'smooth' })\n }\n}\n\nif (previewBridge.isInPreviewMode()) {\n const style = document.createElement('style')\n style.innerHTML = `\n .b10cks-hover,\n .b10cks-preview:hover {\n outline: 2px dashed rgba(59, 130, 246, 0.5);\n outline-offset: 2px;\n }\n .b10cks-selected {\n outline: 2px solid rgb(59, 130, 246) !important;\n outline-offset: 2px;\n }\n `\n document.head.appendChild(style)\n}\n","import type { Directive, DirectiveBinding } from 'vue'\n\nimport { previewBridge } from '../preview-bridge'\n\nexport const EditableContentDirective: Directive<HTMLElement> = {\n mounted(el: HTMLElement, binding: DirectiveBinding) {\n const { id: itemId, field } = binding.value\n if (!previewBridge.isInPreviewMode()) return\n el.setAttribute('contenteditable', 'true')\n\n el.addEventListener('input', (event: Event) => {\n previewBridge.updateField(itemId, field, (event.target as HTMLInputElement).innerText)\n })\n },\n}\n","import type { Plugin } from 'vue'\n\nimport type { B10cksVuePluginOptions } from './types'\n\nimport B10cksComponent from './components/B10cksComponent.vue'\nimport { EditableDirective } from './directives/v-editable'\nimport { EditableContentDirective } from './directives/v-editable-content'\n\nexport { previewBridge } from './preview-bridge'\nexport { B10cksComponentResolverKey, type BlockComponentResolver } from './types'\n\nexport const B10cksVue: Plugin = {\n install(app, pluginOptions: B10cksVuePluginOptions) {\n app.provide('b10cksVueOptions', pluginOptions)\n\n app.directive('editable', EditableDirective)\n app.directive('editable-field', EditableContentDirective)\n app.component('B10cksComponent', B10cksComponent)\n },\n}\n"],"names":["B10cksComponentResolverKey","props","__props","blockRef","useTemplateRef","__expose","resolvedComponent","shallowRef","componentName","computed","resolveBlockComponent","inject","watch","newComponentName","error","_createBlock","_resolveDynamicComponent","_mergeProps","$props","$attrs","_openBlock","_createElementBlock","_hoisted_1","_toDisplayString","PreviewBridge","event","type","payload","listeners","listener","eventType","callback","selectedItem","itemId","field","value","previewBridge","EditableDirective","el","binding","node","handleClick","e","handleSelectionChange","scrollIntoViewIfNeeded","handleHoverChange","handleUpdate","content","ctx","vnode","style","EditableContentDirective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B,QAAQC,GAAKC,GAAuC;AAClD,IAAAD,EAAI,QAAQ,oBAAoBC,CAAa,GAE7CD,EAAI,UAAU,YAAYhB,CAAiB,GAC3CgB,EAAI,UAAU,kBAAkBF,CAAwB,GACxDE,EAAI,UAAU,mBAAmBE,CAAe;AAAA,EAClD;AACF;"}
@@ -0,0 +1,6 @@
1
+ import { B10cksApiClientOptions } from '../../client/src';
2
+ import { Component, InjectionKey } from 'vue';
3
+ export interface B10cksVuePluginOptions extends B10cksApiClientOptions {
4
+ }
5
+ export type BlockComponentResolver = (componentName: string) => Promise<Component>;
6
+ export declare const B10cksComponentResolverKey: InjectionKey<BlockComponentResolver>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b10cks/vue",
3
- "version": "0.10.2",
3
+ "version": "0.10.4",
4
4
  "description": "SDK to integrate b10cks into your vue applications",
5
5
  "license": "MIT",
6
6
  "author": "Michael Wallner @ Coder's Cantina",
@@ -28,7 +28,7 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@b10cks/client": "^0.10.1"
31
+ "@b10cks/client": "^0.10.2"
32
32
  },
33
33
  "devDependencies": {
34
34
  "typescript": "^5.9.3",
@@ -1,3 +0,0 @@
1
- import { B10cksApiClientOptions } from '../../client/src';
2
- export interface B10cksVuePluginOptions extends B10cksApiClientOptions {
3
- }