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