svelte-editorjs
Version:
An EditorJS wrapper for Svelte
3 lines (2 loc) • 1.47 kB
JavaScript
function e(){}const t=[];function n(n,s=e){let c;const i=[];function r(e){if(r=e,((s=n)!=s?r==r:s!==r||s&&"object"==typeof s||"function"==typeof s)&&(n=e,c)){const e=!t.length;for(let e=0;e<i.length;e+=1){const s=i[e];s[1](),t.push(s,n)}if(e){for(let e=0;e<t.length;e+=2)t[e][0](t[e+1]);t.length=0}}var s,r}return{set:r,update:function(e){r(e(n))},subscribe:function(t,a=e){const o=[t,a];return i.push(o),1===i.length&&(c=s(r)||e),t(n),()=>{const e=i.indexOf(o);-1!==e&&i.splice(e,1),0===i.length&&(c(),c=null)}}}}function s(e={}){var t;const s=null!==(t=e.data)&&void 0!==t?t:{time:(new Date).getTime(),blocks:[]};let c;const{subscribe:i,set:r}=n({}),{subscribe:a,set:o}=n(!1),{subscribe:u,set:b,update:l}=n(s);function d(t,n={}){return async function(){if("undefined"==typeof window)return;const s=new((await import("./editor-be7b0f7a.js").then((function(e){return e.e}))).default)(Object.assign(Object.assign(Object.assign({},e),n),{holder:t}));s.isReady.then((()=>{c=s,n.data&&b(n.data);r({instance:s,save:async()=>{const e=await s.save();b(e)},render:async e=>{s.render(e)},clear:async()=>{s.clear(),l((e=>Object.assign(Object.assign({},e),{time:(new Date).getTime(),blocks:[]})))}}),o(!0)})).catch(console.error)}(),{destroy(){null==c||c.destroy()}}}return d.subscribe=i,{editor:d,isReady:{subscribe:a},data:{subscribe:u,set:e=>{l((t=>Object.assign(Object.assign({},t),e))),null==c||c.render(e)},update:l}}}export{s as createEditor};
//# sourceMappingURL=index.js.map