@aeriz/wysiwyg 1.0.5 → 2.0.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/LICENSE +201 -201
- package/README.md +82 -573
- package/angular/README.md +10 -4
- package/angular/aeriz-editor.directive.ts +40 -18
- package/dist/adapters/jquery.cjs +1 -1
- package/dist/adapters/jquery.js +14 -14
- package/dist/adapters/shared.cjs +1 -1
- package/dist/adapters/shared.js +59 -56
- package/dist/adapters/vue.cjs +1 -1
- package/dist/adapters/vue.js +64 -56
- package/dist/adapters/vue2.cjs +1 -1
- package/dist/adapters/vue2.js +24 -17
- package/dist/adapters/wc.cjs +1 -1
- package/dist/adapters/wc.js +108 -72
- package/dist/aeriz-wysiwyg-adapter.js +24 -32
- package/dist/aeriz-wysiwyg-adapter.min.js +1 -1
- package/dist/aeriz-wysiwyg-highlight.js +964 -0
- package/dist/aeriz-wysiwyg-highlight.min.js +5 -0
- package/dist/aeriz-wysiwyg-jquery.js +25 -32
- package/dist/aeriz-wysiwyg-jquery.min.js +1 -1
- package/dist/aeriz-wysiwyg-wc.js +80 -43
- package/dist/aeriz-wysiwyg-wc.min.js +1 -1
- package/dist/aeriz-wysiwyg.cjs +3525 -1744
- package/dist/aeriz-wysiwyg.css +2104 -1904
- package/dist/aeriz-wysiwyg.esm.js +3525 -1744
- package/dist/aeriz-wysiwyg.esm.min.js +4840 -3581
- package/dist/aeriz-wysiwyg.js +3525 -1744
- package/dist/aeriz-wysiwyg.min.cjs +51 -46
- package/dist/aeriz-wysiwyg.min.css +1 -1
- package/dist/aeriz-wysiwyg.min.js +51 -46
- package/dist/highlight.cjs +5 -0
- package/dist/highlight.js +895 -0
- package/dist/server.cjs +24 -19
- package/dist/server.js +612 -251
- package/dist-types/adapters/shared.d.ts +0 -8
- package/dist-types/adapters/shared.d.ts.map +1 -1
- package/dist-types/adapters/vue.d.ts +62 -21
- package/dist-types/adapters/vue.d.ts.map +1 -1
- package/dist-types/adapters/vue2.d.ts +33 -14
- package/dist-types/adapters/vue2.d.ts.map +1 -1
- package/dist-types/adapters/wc.d.ts +15 -6
- package/dist-types/adapters/wc.d.ts.map +1 -1
- package/dist-types/cjs/adapters/shared.d.cts +0 -8
- package/dist-types/cjs/adapters/vue.d.cts +62 -21
- package/dist-types/cjs/adapters/vue2.d.cts +33 -14
- package/dist-types/cjs/adapters/wc.d.cts +15 -6
- package/dist-types/cjs/core/AerizEditor.d.cts +204 -48
- package/dist-types/cjs/core/AerizViewer.d.cts +7 -0
- package/dist-types/cjs/core/block-meta.d.cts +40 -0
- package/dist-types/cjs/core/block-tracker.d.cts +64 -0
- package/dist-types/cjs/core/blocks.d.cts +39 -4
- package/dist-types/cjs/core/fonts.d.cts +33 -46
- package/dist-types/cjs/core/history.d.cts +28 -10
- package/dist-types/cjs/core/html-to-blocks.d.cts +10 -0
- package/dist-types/cjs/core/i18n.d.cts +44 -0
- package/dist-types/cjs/core/import-html.d.cts +0 -13
- package/dist-types/cjs/core/insert-fragment.d.cts +21 -0
- package/dist-types/cjs/core/paste-clean.d.cts +36 -0
- package/dist-types/cjs/core/sanitize-dom.d.cts +21 -0
- package/dist-types/cjs/core/sanitize-html.d.cts +8 -0
- package/dist-types/cjs/core/sanitize-policy.d.cts +22 -0
- package/dist-types/cjs/core/selection.d.cts +5 -0
- package/dist-types/cjs/core/table-grid.d.cts +87 -0
- package/dist-types/cjs/core/table-ops.d.cts +2 -22
- package/dist-types/cjs/highlight/index.d.cts +5 -0
- package/dist-types/cjs/index.d.cts +19 -11
- package/dist-types/cjs/server/index.d.cts +4 -5
- package/dist-types/cjs/types/index.d.cts +63 -15
- package/dist-types/cjs/ui/Toolbar.d.cts +10 -0
- package/dist-types/cjs/ui/doc-tools.d.cts +58 -0
- package/dist-types/cjs/ui/popovers.d.cts +14 -25
- package/dist-types/core/AerizEditor.d.ts +204 -48
- package/dist-types/core/AerizEditor.d.ts.map +1 -1
- package/dist-types/core/AerizViewer.d.ts +7 -0
- package/dist-types/core/AerizViewer.d.ts.map +1 -1
- package/dist-types/core/block-meta.d.ts +40 -0
- package/dist-types/core/block-meta.d.ts.map +1 -1
- package/dist-types/core/block-policy.d.ts.map +1 -1
- package/dist-types/core/block-tracker.d.ts +64 -0
- package/dist-types/core/block-tracker.d.ts.map +1 -0
- package/dist-types/core/blocks.d.ts +39 -4
- package/dist-types/core/blocks.d.ts.map +1 -1
- package/dist-types/core/fonts.d.ts +33 -46
- package/dist-types/core/fonts.d.ts.map +1 -1
- package/dist-types/core/history.d.ts +28 -10
- package/dist-types/core/history.d.ts.map +1 -1
- package/dist-types/core/html-mini.d.ts.map +1 -1
- package/dist-types/core/html-to-blocks.d.ts +10 -0
- package/dist-types/core/html-to-blocks.d.ts.map +1 -0
- package/dist-types/core/i18n.d.ts +44 -0
- package/dist-types/core/i18n.d.ts.map +1 -1
- package/dist-types/core/import-html.d.ts +0 -13
- package/dist-types/core/import-html.d.ts.map +1 -1
- package/dist-types/core/import-markdown.d.ts.map +1 -1
- package/dist-types/core/insert-fragment.d.ts +21 -0
- package/dist-types/core/insert-fragment.d.ts.map +1 -0
- package/dist-types/core/markdown-export.d.ts.map +1 -1
- package/dist-types/core/paste-clean.d.ts +36 -0
- package/dist-types/core/paste-clean.d.ts.map +1 -0
- package/dist-types/core/render-string.d.ts.map +1 -1
- package/dist-types/core/sanitize-dom.d.ts +21 -0
- package/dist-types/core/sanitize-dom.d.ts.map +1 -0
- package/dist-types/core/sanitize-html.d.ts +8 -0
- package/dist-types/core/sanitize-html.d.ts.map +1 -0
- package/dist-types/core/sanitize-policy.d.ts +22 -0
- package/dist-types/core/sanitize-policy.d.ts.map +1 -0
- package/dist-types/core/selection.d.ts +5 -0
- package/dist-types/core/selection.d.ts.map +1 -1
- package/dist-types/core/snapshot.d.ts.map +1 -1
- package/dist-types/core/table-grid.d.ts +87 -0
- package/dist-types/core/table-grid.d.ts.map +1 -0
- package/dist-types/core/table-ops.d.ts +2 -22
- package/dist-types/core/table-ops.d.ts.map +1 -1
- package/dist-types/highlight/index.d.ts +5 -0
- package/dist-types/highlight/index.d.ts.map +1 -0
- package/dist-types/index.d.ts +19 -11
- package/dist-types/index.d.ts.map +1 -1
- package/dist-types/server/index.d.ts +4 -5
- package/dist-types/server/index.d.ts.map +1 -1
- package/dist-types/types/index.d.ts +63 -15
- package/dist-types/types/index.d.ts.map +1 -1
- package/dist-types/ui/Toolbar.d.ts +10 -0
- package/dist-types/ui/Toolbar.d.ts.map +1 -1
- package/dist-types/ui/doc-tools.d.ts +58 -0
- package/dist-types/ui/doc-tools.d.ts.map +1 -0
- package/dist-types/ui/icons.d.ts.map +1 -1
- package/dist-types/ui/popovers.d.ts +14 -25
- package/dist-types/ui/popovers.d.ts.map +1 -1
- package/package.json +70 -5
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var AerizWysiwygHighlight=function(m){"use strict";const h={lineComment:"//",blockComment:{start:"/*",end:"*/"},stringDelims:['"',"'"]},g=new Set(["abstract","arguments","async","await","break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","export","extends","finally","for","from","function","get","if","implements","import","in","instanceof","interface","let","new","null","of","package","private","protected","public","return","set","static","super","switch","this","throw","true","false","try","typeof","undefined","var","void","while","with","yield"]),S=new Set([...g,"any","as","asserts","boolean","declare","infer","is","keyof","module","namespace","never","number","object","override","readonly","require","satisfies","string","symbol","type","unique","unknown"]),v=new Set(["False","None","True","and","as","assert","async","await","break","class","continue","def","del","elif","else","except","finally","for","from","global","if","import","in","is","lambda","nonlocal","not","or","pass","raise","return","try","while","with","yield"]),x=new Set(["abs","all","any","bool","dict","enumerate","filter","float","int","isinstance","len","list","map","max","min","open","print","range","set","sorted","str","sum","tuple","type","zip","self","cls"]),y=new Set(["auto","break","case","char","const","continue","default","do","double","else","enum","extern","float","for","goto","if","int","long","register","return","short","signed","sizeof","static","struct","switch","typedef","union","unsigned","void","volatile","while","inline","restrict","_Bool","NULL"]),_=new Set([...y,"class","new","delete","try","catch","throw","template","typename","namespace","using","public","private","protected","virtual","override","this","nullptr","true","false","bool","explicit","friend","mutable","operator","reinterpret_cast","static_cast","dynamic_cast","const_cast","constexpr","decltype","noexcept","final","auto"]),$=new Set(["abstract","async","await","base","bool","break","byte","case","catch","char","checked","class","const","continue","decimal","default","delegate","do","double","else","enum","event","explicit","extern","false","finally","fixed","float","for","foreach","goto","if","implicit","in","int","interface","internal","is","lock","long","namespace","new","null","object","operator","out","override","params","private","protected","public","readonly","ref","return","sbyte","sealed","short","sizeof","stackalloc","static","string","struct","switch","this","throw","true","try","typeof","uint","ulong","unchecked","unsafe","ushort","using","var","virtual","void","volatile","while","yield","record","init","nameof","when"]),O=new Set(["abstract","assert","boolean","break","byte","case","catch","char","class","const","continue","default","do","double","else","enum","extends","final","finally","float","for","goto","if","implements","import","instanceof","int","interface","long","native","new","null","package","private","protected","public","return","short","static","strictfp","super","switch","synchronized","this","throw","throws","transient","true","false","try","void","volatile","while","var","yield","record","sealed","permits","non-sealed"]),A=new Set(["abstract","actual","annotation","as","break","by","catch","class","companion","const","constructor","continue","crossinline","data","do","dynamic","else","enum","expect","external","false","final","finally","for","fun","get","if","import","in","init","inline","inner","interface","internal","is","it","lateinit","null","object","open","operator","out","override","package","private","protected","public","reified","return","sealed","set","super","suspend","tailrec","this","throw","true","try","typealias","typeof","val","var","vararg","when","where","while"]),C=new Set(["break","case","chan","const","continue","default","defer","else","fallthrough","for","func","go","goto","if","import","interface","map","package","range","return","select","struct","switch","type","var","true","false","nil","iota"]),D=new Set(["as","async","await","break","const","continue","crate","dyn","else","enum","extern","false","fn","for","if","impl","in","let","loop","match","mod","move","mut","pub","ref","return","self","Self","static","struct","super","trait","true","type","unsafe","use","where","while","box","do","final","macro","override","priv","typeof","unsized","virtual","yield"]),W=new Set(["if","then","else","elif","fi","case","esac","for","while","until","do","done","function","return","select","break","continue","in","echo","export","local","readonly","declare","typeset","unset","eval","exec","source","true","false"]),E=new Set(["select","from","where","insert","update","delete","into","values","set","create","table","drop","alter","index","view","join","inner","left","right","outer","full","cross","on","group","by","order","having","limit","offset","union","all","distinct","as","and","or","not","null","true","false","is","in","between","like","exists","primary","key","foreign","references","unique","default","check","constraint","database","schema","with","case","when","then","else","end","cast","count","sum","avg","min","max","asc","desc"]),R=new Set(["true","false","null"]),b=[{id:"plaintext",label:"Plain Text",keywords:new Set},{id:"javascript",label:"JavaScript",keywords:g,...h,stringDelims:['"',"'","`"]},{id:"typescript",label:"TypeScript",keywords:S,...h,stringDelims:['"',"'","`"]},{id:"python",label:"Python",keywords:v,builtins:x,lineComment:"#",stringDelims:['"',"'"]},{id:"json",label:"JSON",keywords:R,stringDelims:['"']},{id:"html",label:"HTML",keywords:new Set,custom:e=>L(e)},{id:"css",label:"CSS",keywords:new Set,custom:e=>N(e)},{id:"bash",label:"Bash",keywords:W,lineComment:"#",stringDelims:['"',"'"]},{id:"sql",label:"SQL",keywords:E,caseInsensitiveKeywords:!0,lineComment:"--",blockComment:{start:"/*",end:"*/"},stringDelims:['"',"'"]},{id:"markdown",label:"Markdown",keywords:new Set,custom:e=>P(e)},{id:"c",label:"C",keywords:y,...h},{id:"cpp",label:"C++",keywords:_,...h},{id:"csharp",label:"C#",keywords:$,...h},{id:"java",label:"Java",keywords:O,...h},{id:"kotlin",label:"Kotlin",keywords:A,...h},{id:"go",label:"Go",keywords:C,...h},{id:"rust",label:"Rust",keywords:D,...h}],z=(()=>{const e=new Map;for(const t of b)e.set(t.id,t);return e})(),K="plaintext";function Y(e,t){if(!t||t===K)return s(e);const n=z.get(t);return n?n.custom?n.custom(e):T(e,n):s(e)}function T(e,t){var c,a;const n=!!t.caseInsensitiveKeywords;let o="",i=0;const l=e.length;for(;i<l;){if(t.lineComment&&e.startsWith(t.lineComment,i)){const r=e.indexOf(`
|
|
2
|
+
`,i),p=r===-1?l:r;o+=`<span class="hl-comment">${s(e.slice(i,p))}</span>`,i=p;continue}if(t.blockComment&&e.startsWith(t.blockComment.start,i)){const r=e.indexOf(t.blockComment.end,i+t.blockComment.start.length),p=r===-1?l:r+t.blockComment.end.length;o+=`<span class="hl-comment">${s(e.slice(i,p))}</span>`,i=p;continue}const u=(c=t.stringDelims)==null?void 0:c.find(r=>e.startsWith(r,i));if(u){let r=i+u.length;for(;r<l;){const p=e[r]??"";if(p==="\\"){r+=2;continue}if(e.startsWith(u,r)){r+=u.length;break}if(p===`
|
|
3
|
+
`&&u!=="`")break;r++}o+=`<span class="hl-string">${s(e.slice(i,r))}</span>`,i=r;continue}const f=e[i]??"";if(/[0-9]/.test(f)){const r=j.exec(e.slice(i));if(r){o+=`<span class="hl-number">${s(r[0])}</span>`,i+=r[0].length;continue}}if(/[a-zA-Z_$]/.test(f)){let r=i+1;for(;r<l&&/[a-zA-Z0-9_$]/.test(e[r]??"");)r++;const p=e.slice(i,r),k=n?p.toLowerCase():p;if(t.keywords.has(k))o+=`<span class="hl-keyword">${s(p)}</span>`;else if((a=t.builtins)!=null&&a.has(k))o+=`<span class="hl-builtin">${s(p)}</span>`;else{let d=r;for(;d<l&&(e[d]===" "||e[d]===" ");)d++;e[d]==="("?o+=`<span class="hl-fn">${s(p)}</span>`:o+=s(p)}i=r;continue}o+=s(f),i++}return o}const j=/^(0[xX][0-9a-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|[0-9][0-9_]*(?:\.[0-9_]+)?(?:[eE][-+]?[0-9_]+)?)[a-zA-Z]*/;function L(e){let t="",n=0;const o=e.length;for(;n<o;){if(e.startsWith("<!--",n)){const i=e.indexOf("-->",n+4),l=i===-1?o:i+3;t+=`<span class="hl-comment">${s(e.slice(n,l))}</span>`,n=l;continue}if(e[n]==="<"){const i=e.indexOf(">",n);if(i===-1){t+=s(e.slice(n));break}const l=e.slice(n,i+1);t+=M(l),n=i+1;continue}t+=s(e[n]??""),n++}return t}function M(e){const t=e.slice(1,-1);let n='<span class="hl-punct"><</span>';const o=/^\/?[a-zA-Z][a-zA-Z0-9-]*/.exec(t);if(o){n+=`<span class="hl-tag">${s(o[0])}</span>`;let i=t.slice(o[0].length);const l=/\s+([a-zA-Z_:][a-zA-Z0-9_:.-]*)(\s*=\s*("([^"]*)"|'([^']*)'|([^\s>]+)))?/g;let c=0,a;for(;a=l.exec(i);){n+=s(i.slice(c,a.index)),n+=s(i.slice(a.index,a.index+a[0].indexOf(a[1]??""))),n+=`<span class="hl-attr">${s(a[1]??"")}</span>`;const u=i.slice(a.index+(a[0].indexOf(a[1]??"")+(a[1]??"").length),a.index+a[0].length);if(u.includes("=")){const f=u.indexOf("=");n+=s(u.slice(0,f+1));const r=u.slice(f+1);n+=`<span class="hl-string">${s(r)}</span>`}c=a.index+a[0].length}n+=s(i.slice(c))}else n+=s(t);return n+='<span class="hl-punct">></span>',n}function N(e){let t="",n=0;const o=e.length;let i=!1;for(;n<o;){if(e.startsWith("/*",n)){const c=e.indexOf("*/",n+2),a=c===-1?o:c+2;t+=`<span class="hl-comment">${s(e.slice(n,a))}</span>`,n=a;continue}const l=e[n]??"";if(l==="{"){i=!0,t+=s(l),n++;continue}if(l==="}"){i=!1,t+=s(l),n++;continue}if(l==='"'||l==="'"){const c=l;let a=n+1;for(;a<o&&e[a]!==c;)e[a]==="\\"?a+=2:a++;a=Math.min(a+1,o),t+=`<span class="hl-string">${s(e.slice(n,a))}</span>`,n=a;continue}if(/[a-zA-Z_-]/.test(l)||l==="@"||l==="#"||l==="."||l===":"){let c=n+1;for(;c<o&&/[a-zA-Z0-9_-]/.test(e[c]??"");)c++;const a=e.slice(n,c);if(l==="@")t+=`<span class="hl-keyword">${s(a)}</span>`;else if(i&&/^[a-zA-Z-]+$/.test(a)){let u=c;for(;u<o&&(e[u]===" "||e[u]===" ");)u++;e[u]===":"?t+=`<span class="hl-prop">${s(a)}</span>`:t+=s(a)}else t+=`<span class="hl-tag">${s(a)}</span>`;n=c;continue}if(/[0-9]/.test(l)){const c=/^[0-9.]+(px|em|rem|%|vh|vw|s|ms|deg|fr)?/.exec(e.slice(n));if(c){t+=`<span class="hl-number">${s(c[0])}</span>`,n+=c[0].length;continue}}t+=s(l),n++}return t}function P(e){return e.split(`
|
|
4
|
+
`).map(Z).join(`
|
|
5
|
+
`)}function Z(e){const t=/^(#{1,6})\s+(.*)$/.exec(e);if(t)return`<span class="hl-keyword">${s(t[1]??"")}</span> <span class="hl-tag">${w(t[2]??"")}</span>`;if(e.startsWith(">"))return`<span class="hl-comment">${s(e)}</span>`;if(e.startsWith("```"))return`<span class="hl-keyword">${s(e)}</span>`;const n=/^(\s*)([-*+]|\d+\.)\s+(.*)$/.exec(e);return n?`${n[1]??""}<span class="hl-keyword">${s(n[2]??"")}</span> ${w(n[3]??"")}`:w(e)}function w(e){let t=s(e);return t=t.replace(/\*\*([^*]+)\*\*/g,'<span class="hl-keyword">**$1**</span>'),t=t.replace(new RegExp("(?<!\\*)\\*([^*]+)\\*(?!\\*)","g"),'<span class="hl-string">*$1*</span>'),t=t.replace(/`([^`]+)`/g,'<span class="hl-builtin">`$1`</span>'),t=t.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<span class="hl-tag">[$1]</span><span class="hl-string">($2)</span>'),t}function s(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}const B={languages:b.map(({id:e,label:t})=>({id:e,label:t})),highlight:Y};return m.highlighter=B,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"}),m}({});
|
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
var AerizWysiwygJQuery = function(exports, wysiwyg) {
|
|
2
2
|
"use strict";
|
|
3
|
-
|
|
4
|
-
const scratch = document.createElement("div");
|
|
5
|
-
scratch.innerHTML = html;
|
|
6
|
-
wysiwyg.normalizeContent(scratch, { writableTail: false });
|
|
7
|
-
const ids = new wysiwyg.BlockIdRegistry();
|
|
8
|
-
wysiwyg.assignMissingIds(scratch, ids);
|
|
9
|
-
return wysiwyg.serializeBlocks(wysiwyg.listBlocks(scratch, (el) => ids.ensure(el)));
|
|
10
|
-
}
|
|
3
|
+
const CONTROLLER_PROPS = /* @__PURE__ */ new Set(["value", "onChange", "onStateChange", "onReady", "onDestroy"]);
|
|
11
4
|
function toEditorOptions(element, props, onChange) {
|
|
12
5
|
const options = { element, onChange };
|
|
6
|
+
for (const [key, value] of Object.entries(props)) {
|
|
7
|
+
if (value === void 0 || CONTROLLER_PROPS.has(key)) continue;
|
|
8
|
+
options[key] = value;
|
|
9
|
+
}
|
|
13
10
|
const initial = props.value ?? props.initialHTML;
|
|
14
11
|
if (initial !== void 0) options.initialHTML = initial;
|
|
15
|
-
if (props.placeholder !== void 0) options.placeholder = props.placeholder;
|
|
16
|
-
if (props.toolbar !== void 0) options.toolbar = props.toolbar;
|
|
17
|
-
if (props.theme !== void 0) options.theme = props.theme;
|
|
18
|
-
if (props.locale !== void 0) options.locale = props.locale;
|
|
19
|
-
if (props.htmlStyles !== void 0) options.htmlStyles = props.htmlStyles;
|
|
20
|
-
if (props.onImageUpload !== void 0) options.onImageUpload = props.onImageUpload;
|
|
21
|
-
if (props.imageUploadUrl !== void 0) options.imageUploadUrl = props.imageUploadUrl;
|
|
22
|
-
if (props.onFileUpload !== void 0) options.onFileUpload = props.onFileUpload;
|
|
23
|
-
if (props.fileUploadUrl !== void 0) options.fileUploadUrl = props.fileUploadUrl;
|
|
24
12
|
return options;
|
|
25
13
|
}
|
|
14
|
+
const LIVE_OPTIONS = ["upload", "htmlStyles", "onError"];
|
|
15
|
+
const REBUILD_OPTIONS = ["locale", "statusBar", "height", "ariaLabel", "fonts", "fontSizes", "highlighter"];
|
|
16
|
+
function sameValue(a, b) {
|
|
17
|
+
if (a === b) return true;
|
|
18
|
+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) return false;
|
|
19
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
20
|
+
}
|
|
26
21
|
function sameToolbar(a, b) {
|
|
27
22
|
if (a === b) return true;
|
|
28
23
|
if (a === false || b === false || a === void 0 || b === void 0) {
|
|
@@ -47,16 +42,11 @@ var AerizWysiwygJQuery = function(exports, wysiwyg) {
|
|
|
47
42
|
let unsubscribe = null;
|
|
48
43
|
let liveOptions;
|
|
49
44
|
const syncLazyOptions = (next) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
else liveOptions.onFileUpload = next.onFileUpload;
|
|
56
|
-
if (next.fileUploadUrl === void 0) delete liveOptions.fileUploadUrl;
|
|
57
|
-
else liveOptions.fileUploadUrl = next.fileUploadUrl;
|
|
58
|
-
if (next.htmlStyles === void 0) delete liveOptions.htmlStyles;
|
|
59
|
-
else liveOptions.htmlStyles = next.htmlStyles;
|
|
45
|
+
const live = liveOptions;
|
|
46
|
+
for (const key of LIVE_OPTIONS) {
|
|
47
|
+
if (next[key] === void 0) delete live[key];
|
|
48
|
+
else live[key] = next[key];
|
|
49
|
+
}
|
|
60
50
|
};
|
|
61
51
|
const create = (from, html) => {
|
|
62
52
|
var _a;
|
|
@@ -86,7 +76,7 @@ var AerizWysiwygJQuery = function(exports, wysiwyg) {
|
|
|
86
76
|
if (disposed) return;
|
|
87
77
|
const prev = props;
|
|
88
78
|
props = next;
|
|
89
|
-
if (next.
|
|
79
|
+
if (!sameToolbar(next.toolbar, prev.toolbar) || REBUILD_OPTIONS.some((key) => !sameValue(next[key], prev[key]))) {
|
|
90
80
|
const carried = next.value ?? editor.getHTML();
|
|
91
81
|
teardown();
|
|
92
82
|
create(next, carried);
|
|
@@ -96,6 +86,9 @@ var AerizWysiwygJQuery = function(exports, wysiwyg) {
|
|
|
96
86
|
if (next.theme !== prev.theme && next.theme !== void 0) {
|
|
97
87
|
editor.setTheme(next.theme);
|
|
98
88
|
}
|
|
89
|
+
if (Boolean(next.readOnly) !== Boolean(prev.readOnly)) {
|
|
90
|
+
editor.setReadOnly(Boolean(next.readOnly));
|
|
91
|
+
}
|
|
99
92
|
if (next.placeholder !== prev.placeholder) {
|
|
100
93
|
if (next.placeholder === void 0) {
|
|
101
94
|
delete editor.content.dataset.placeholder;
|
|
@@ -122,8 +115,8 @@ var AerizWysiwygJQuery = function(exports, wysiwyg) {
|
|
|
122
115
|
}
|
|
123
116
|
function toViewerOptions(element, props) {
|
|
124
117
|
const options = { element };
|
|
125
|
-
|
|
126
|
-
if (
|
|
118
|
+
if (props.blocks !== void 0) options.initialBlocks = props.blocks;
|
|
119
|
+
else if (props.html !== void 0) options.initialHTML = props.html;
|
|
127
120
|
if (props.theme !== void 0) options.theme = props.theme;
|
|
128
121
|
if (props.htmlStyles !== void 0) options.htmlStyles = props.htmlStyles;
|
|
129
122
|
return options;
|
|
@@ -149,7 +142,7 @@ var AerizWysiwygJQuery = function(exports, wysiwyg) {
|
|
|
149
142
|
if (next.blocks !== void 0) {
|
|
150
143
|
if (next.blocks !== prev.blocks) viewer.setBlocks(next.blocks);
|
|
151
144
|
} else if (next.html !== void 0 && next.html !== prev.html) {
|
|
152
|
-
if (next.html !== viewer.getHTML()) viewer.
|
|
145
|
+
if (next.html !== viewer.getHTML()) viewer.setHTML(next.html);
|
|
153
146
|
}
|
|
154
147
|
},
|
|
155
148
|
destroy() {
|
|
@@ -170,7 +163,7 @@ var AerizWysiwygJQuery = function(exports, wysiwyg) {
|
|
|
170
163
|
case "getHTML":
|
|
171
164
|
return (controller == null ? void 0 : controller.editor.getHTML()) ?? "";
|
|
172
165
|
case "getBlocks":
|
|
173
|
-
return (controller == null ? void 0 : controller.editor.
|
|
166
|
+
return (controller == null ? void 0 : controller.editor.getBlocks()) ?? [];
|
|
174
167
|
case "setHTML":
|
|
175
168
|
collection.each((_i, el) => {
|
|
176
169
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var AerizWysiwygJQuery=function(
|
|
1
|
+
var AerizWysiwygJQuery=function(y,v){"use strict";const k=new Set(["value","onChange","onStateChange","onReady","onDestroy"]);function H(e,s,i){const a={element:e,onChange:i};for(const[o,u]of Object.entries(s))u===void 0||k.has(o)||(a[o]=u);const r=s.value??s.initialHTML;return r!==void 0&&(a.initialHTML=r),a}const O=["upload","htmlStyles","onError"],z=["locale","statusBar","height","ariaLabel","fonts","fontSizes","highlighter"];function E(e,s){return e===s?!0:typeof e!="object"||typeof s!="object"||!e||!s?!1:JSON.stringify(e)===JSON.stringify(s)}function B(e,s){return e===s?!0:e===!1||s===!1||e===void 0||s===void 0||e.sticky!==s.sticky||e.items.length!==s.items.length?!1:e.items.every((i,a)=>i===s.items[a])}function _(e,s){let i=s,a="",r=!1,o=!1;const u=n=>{var f;a=n,!r&&((f=i.onChange)==null||f.call(i,n))};let t,d=null,g;const J=n=>{const f=g;for(const l of O)n[l]===void 0?delete f[l]:f[l]=n[l]},T=(n,f)=>{var S;const l=f!==void 0?{...n,value:f}:n;g=H(e,l,u),t=new v.AerizEditor(g),a=t.getHTML(),d=t.onStateChange(Q=>{var M;return(M=i.onStateChange)==null?void 0:M.call(i,Q)}),(S=i.onReady)==null||S.call(i,t)},L=()=>{var n;(n=i.onDestroy)==null||n.call(i,t),d==null||d(),d=null,t.destroy()};return T(i),{get editor(){return t},update(n){if(o)return;const f=i;if(i=n,!B(n.toolbar,f.toolbar)||z.some(l=>!E(n[l],f[l]))){const l=n.value??t.getHTML();L(),T(n,l);return}if(J(n),n.theme!==f.theme&&n.theme!==void 0&&t.setTheme(n.theme),!!n.readOnly!=!!f.readOnly&&t.setReadOnly(!!n.readOnly),n.placeholder!==f.placeholder&&(n.placeholder===void 0?delete t.content.dataset.placeholder:t.content.dataset.placeholder=n.placeholder),n.value!==void 0&&n.value!==a&&n.value!==t.getHTML()){r=!0;try{t.setHTML(n.value)}finally{r=!1}a=n.value}},destroy(){o||(o=!0,L())}}}function b(e,s){const i={element:e};return s.blocks!==void 0?i.initialBlocks=s.blocks:s.html!==void 0&&(i.initialHTML=s.html),s.theme!==void 0&&(i.theme=s.theme),s.htmlStyles!==void 0&&(i.htmlStyles=s.htmlStyles),i}function R(e,s){var u;let i=s,a=!1;const r=b(e,s),o=new v.AerizViewer(r);return(u=i.onReady)==null||u.call(i,o),{viewer:o,update(t){if(a)return;const d=i;i=t,t.theme!==d.theme&&t.theme!==void 0&&o.setTheme(t.theme),t.htmlStyles===void 0?delete r.htmlStyles:r.htmlStyles=t.htmlStyles,t.blocks!==void 0?t.blocks!==d.blocks&&o.setBlocks(t.blocks):t.html!==void 0&&t.html!==d.html&&t.html!==o.getHTML()&&o.setHTML(t.html)},destroy(){var t;a||(a=!0,(t=i.onDestroy)==null||t.call(i,o),o.destroy())}}}const c=new WeakMap,h=new WeakMap;function V(e,s,i){const a=e[0],r=a?c.get(a):void 0;switch(s){case"getHTML":return(r==null?void 0:r.editor.getHTML())??"";case"getBlocks":return(r==null?void 0:r.editor.getBlocks())??[];case"setHTML":return e.each((o,u)=>{var t;(t=c.get(u))==null||t.editor.setHTML(String(i[0]??""))}),e;case"update":return e.each((o,u)=>{var t;(t=c.get(u))==null||t.update(i[0]??{})}),e;case"focus":return r==null||r.editor.focus(),e;case"instance":return(r==null?void 0:r.editor)??null;case"destroy":return e.each((o,u)=>{const t=c.get(u);t&&(t.destroy(),c.delete(u))}),e;default:throw new Error(`aerizEditor: 알 수 없는 명령 "${s}"`)}}function j(e,s,i){const a=e[0],r=a?h.get(a):void 0;switch(s){case"getHTML":return(r==null?void 0:r.viewer.getHTML())??"";case"getBlocks":return(r==null?void 0:r.viewer.getBlocks())??[];case"update":return e.each((o,u)=>{var t;(t=h.get(u))==null||t.update(i[0]??{})}),e;case"instance":return(r==null?void 0:r.viewer)??null;case"destroy":return e.each((o,u)=>{const t=h.get(u);t&&(t.destroy(),h.delete(u))}),e;default:throw new Error(`aerizViewer: 알 수 없는 명령 "${s}"`)}}function A(e,...s){if(typeof e=="string")return V(this,e,s);const i=e??{};return this.each((a,r)=>{const o=c.get(r);if(o){o.update(i);return}c.set(r,_(r,i))}),this}function C(e,...s){if(typeof e=="string")return j(this,e,s);const i=e??{};return this.each((a,r)=>{const o=h.get(r);if(o){o.update(i);return}h.set(r,R(r,i))}),this}function w(e){if(!e||typeof e.fn!="object")throw new TypeError("registerAerizJQuery: jQuery 객체가 필요합니다.");e.fn.aerizEditor||(e.fn.aerizEditor=A),e.fn.aerizViewer||(e.fn.aerizViewer=C)}const m=globalThis.jQuery;return m&&w(m),y.registerAerizJQuery=w,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"}),y}({},AerizWysiwyg);
|
package/dist/aeriz-wysiwyg-wc.js
CHANGED
|
@@ -3,29 +3,24 @@ var AerizWysiwygWC = function(exports, wysiwyg) {
|
|
|
3
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
const scratch = document.createElement("div");
|
|
8
|
-
scratch.innerHTML = html;
|
|
9
|
-
wysiwyg.normalizeContent(scratch, { writableTail: false });
|
|
10
|
-
const ids = new wysiwyg.BlockIdRegistry();
|
|
11
|
-
wysiwyg.assignMissingIds(scratch, ids);
|
|
12
|
-
return wysiwyg.serializeBlocks(wysiwyg.listBlocks(scratch, (el) => ids.ensure(el)));
|
|
13
|
-
}
|
|
6
|
+
const CONTROLLER_PROPS = /* @__PURE__ */ new Set(["value", "onChange", "onStateChange", "onReady", "onDestroy"]);
|
|
14
7
|
function toEditorOptions(element, props, onChange) {
|
|
15
8
|
const options = { element, onChange };
|
|
9
|
+
for (const [key, value] of Object.entries(props)) {
|
|
10
|
+
if (value === void 0 || CONTROLLER_PROPS.has(key)) continue;
|
|
11
|
+
options[key] = value;
|
|
12
|
+
}
|
|
16
13
|
const initial = props.value ?? props.initialHTML;
|
|
17
14
|
if (initial !== void 0) options.initialHTML = initial;
|
|
18
|
-
if (props.placeholder !== void 0) options.placeholder = props.placeholder;
|
|
19
|
-
if (props.toolbar !== void 0) options.toolbar = props.toolbar;
|
|
20
|
-
if (props.theme !== void 0) options.theme = props.theme;
|
|
21
|
-
if (props.locale !== void 0) options.locale = props.locale;
|
|
22
|
-
if (props.htmlStyles !== void 0) options.htmlStyles = props.htmlStyles;
|
|
23
|
-
if (props.onImageUpload !== void 0) options.onImageUpload = props.onImageUpload;
|
|
24
|
-
if (props.imageUploadUrl !== void 0) options.imageUploadUrl = props.imageUploadUrl;
|
|
25
|
-
if (props.onFileUpload !== void 0) options.onFileUpload = props.onFileUpload;
|
|
26
|
-
if (props.fileUploadUrl !== void 0) options.fileUploadUrl = props.fileUploadUrl;
|
|
27
15
|
return options;
|
|
28
16
|
}
|
|
17
|
+
const LIVE_OPTIONS = ["upload", "htmlStyles", "onError"];
|
|
18
|
+
const REBUILD_OPTIONS = ["locale", "statusBar", "height", "ariaLabel", "fonts", "fontSizes", "highlighter"];
|
|
19
|
+
function sameValue(a, b) {
|
|
20
|
+
if (a === b) return true;
|
|
21
|
+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) return false;
|
|
22
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
23
|
+
}
|
|
29
24
|
function sameToolbar(a, b) {
|
|
30
25
|
if (a === b) return true;
|
|
31
26
|
if (a === false || b === false || a === void 0 || b === void 0) {
|
|
@@ -50,16 +45,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
50
45
|
let unsubscribe = null;
|
|
51
46
|
let liveOptions;
|
|
52
47
|
const syncLazyOptions = (next) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
else liveOptions.onFileUpload = next.onFileUpload;
|
|
59
|
-
if (next.fileUploadUrl === void 0) delete liveOptions.fileUploadUrl;
|
|
60
|
-
else liveOptions.fileUploadUrl = next.fileUploadUrl;
|
|
61
|
-
if (next.htmlStyles === void 0) delete liveOptions.htmlStyles;
|
|
62
|
-
else liveOptions.htmlStyles = next.htmlStyles;
|
|
48
|
+
const live = liveOptions;
|
|
49
|
+
for (const key of LIVE_OPTIONS) {
|
|
50
|
+
if (next[key] === void 0) delete live[key];
|
|
51
|
+
else live[key] = next[key];
|
|
52
|
+
}
|
|
63
53
|
};
|
|
64
54
|
const create = (from, html) => {
|
|
65
55
|
var _a;
|
|
@@ -89,7 +79,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
89
79
|
if (disposed) return;
|
|
90
80
|
const prev = props;
|
|
91
81
|
props = next;
|
|
92
|
-
if (next.
|
|
82
|
+
if (!sameToolbar(next.toolbar, prev.toolbar) || REBUILD_OPTIONS.some((key) => !sameValue(next[key], prev[key]))) {
|
|
93
83
|
const carried = next.value ?? editor.getHTML();
|
|
94
84
|
teardown();
|
|
95
85
|
create(next, carried);
|
|
@@ -99,6 +89,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
99
89
|
if (next.theme !== prev.theme && next.theme !== void 0) {
|
|
100
90
|
editor.setTheme(next.theme);
|
|
101
91
|
}
|
|
92
|
+
if (Boolean(next.readOnly) !== Boolean(prev.readOnly)) {
|
|
93
|
+
editor.setReadOnly(Boolean(next.readOnly));
|
|
94
|
+
}
|
|
102
95
|
if (next.placeholder !== prev.placeholder) {
|
|
103
96
|
if (next.placeholder === void 0) {
|
|
104
97
|
delete editor.content.dataset.placeholder;
|
|
@@ -125,8 +118,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
125
118
|
}
|
|
126
119
|
function toViewerOptions(element, props) {
|
|
127
120
|
const options = { element };
|
|
128
|
-
|
|
129
|
-
if (
|
|
121
|
+
if (props.blocks !== void 0) options.initialBlocks = props.blocks;
|
|
122
|
+
else if (props.html !== void 0) options.initialHTML = props.html;
|
|
130
123
|
if (props.theme !== void 0) options.theme = props.theme;
|
|
131
124
|
if (props.htmlStyles !== void 0) options.htmlStyles = props.htmlStyles;
|
|
132
125
|
return options;
|
|
@@ -152,7 +145,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
152
145
|
if (next.blocks !== void 0) {
|
|
153
146
|
if (next.blocks !== prev.blocks) viewer.setBlocks(next.blocks);
|
|
154
147
|
} else if (next.html !== void 0 && next.html !== prev.html) {
|
|
155
|
-
if (next.html !== viewer.getHTML()) viewer.
|
|
148
|
+
if (next.html !== viewer.getHTML()) viewer.setHTML(next.html);
|
|
156
149
|
}
|
|
157
150
|
},
|
|
158
151
|
destroy() {
|
|
@@ -204,9 +197,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
204
197
|
class AerizEditorElement extends HTMLElement {
|
|
205
198
|
constructor() {
|
|
206
199
|
super();
|
|
207
|
-
|
|
208
|
-
__publicField(this, "
|
|
209
|
-
__publicField(this, "
|
|
200
|
+
// 속성(문자열) 으로 나타낼 수 없는 옵션은 프로퍼티로 준다. 바꾸면 바로 반영된다.
|
|
201
|
+
__publicField(this, "uploadValue");
|
|
202
|
+
__publicField(this, "fontsValue");
|
|
203
|
+
__publicField(this, "highlighterValue");
|
|
204
|
+
__publicField(this, "fontSizesValue");
|
|
210
205
|
__publicField(this, "controller", null);
|
|
211
206
|
__publicField(this, "internals", null);
|
|
212
207
|
/**
|
|
@@ -229,10 +224,43 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
229
224
|
"locale",
|
|
230
225
|
"toolbar",
|
|
231
226
|
"html-styles",
|
|
232
|
-
"
|
|
233
|
-
"
|
|
227
|
+
"read-only",
|
|
228
|
+
"height",
|
|
229
|
+
"status-bar",
|
|
230
|
+
"upload-url",
|
|
231
|
+
"aria-label"
|
|
234
232
|
];
|
|
235
233
|
}
|
|
234
|
+
/** 올리기 설정. `upload-url` 속성보다 우선한다 (헤더 · 직접 올리기가 필요할 때). */
|
|
235
|
+
get upload() {
|
|
236
|
+
return this.uploadValue;
|
|
237
|
+
}
|
|
238
|
+
set upload(value) {
|
|
239
|
+
this.uploadValue = value;
|
|
240
|
+
this.applyProps();
|
|
241
|
+
}
|
|
242
|
+
/** 코드 블록 색칠기 (`@aeriz/wysiwyg/highlight` 의 `highlighter`). */
|
|
243
|
+
get highlighter() {
|
|
244
|
+
return this.highlighterValue;
|
|
245
|
+
}
|
|
246
|
+
set highlighter(value) {
|
|
247
|
+
this.highlighterValue = value;
|
|
248
|
+
this.applyProps();
|
|
249
|
+
}
|
|
250
|
+
get fonts() {
|
|
251
|
+
return this.fontsValue;
|
|
252
|
+
}
|
|
253
|
+
set fonts(value) {
|
|
254
|
+
this.fontsValue = value;
|
|
255
|
+
this.applyProps();
|
|
256
|
+
}
|
|
257
|
+
get fontSizes() {
|
|
258
|
+
return this.fontSizesValue;
|
|
259
|
+
}
|
|
260
|
+
set fontSizes(value) {
|
|
261
|
+
this.fontSizesValue = value;
|
|
262
|
+
this.applyProps();
|
|
263
|
+
}
|
|
236
264
|
/** 현재 본문 HTML. 설정하면 본문을 교체한다. */
|
|
237
265
|
get value() {
|
|
238
266
|
if (this.controller) return this.controller.editor.getHTML();
|
|
@@ -250,7 +278,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
250
278
|
/** 블록 상태 스냅샷. */
|
|
251
279
|
getBlocks() {
|
|
252
280
|
var _a;
|
|
253
|
-
return ((_a = this.controller) == null ? void 0 : _a.editor.
|
|
281
|
+
return ((_a = this.controller) == null ? void 0 : _a.editor.getBlocks()) ?? [];
|
|
254
282
|
}
|
|
255
283
|
/** 본문에 캐럿을 둔다. `HTMLElement.focus()` 를 본문 쪽으로 위임한다. */
|
|
256
284
|
focus() {
|
|
@@ -298,6 +326,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
298
326
|
this.syncFormValue(html);
|
|
299
327
|
this.dispatchEvent(new CustomEvent("input", { detail: { html }, bubbles: true }));
|
|
300
328
|
this.dispatchEvent(new CustomEvent("change", { detail: { html }, bubbles: true }));
|
|
329
|
+
},
|
|
330
|
+
onError: (error, context) => {
|
|
331
|
+
this.dispatchEvent(new CustomEvent("error", { detail: { error, code: context.code }, bubbles: true }));
|
|
301
332
|
}
|
|
302
333
|
};
|
|
303
334
|
if (this.pendingValue !== void 0) props.value = this.pendingValue;
|
|
@@ -313,12 +344,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
313
344
|
if (htmlStyles === "class" || htmlStyles === "inline") {
|
|
314
345
|
props.htmlStyles = htmlStyles;
|
|
315
346
|
}
|
|
316
|
-
|
|
317
|
-
if (
|
|
318
|
-
const
|
|
319
|
-
if (
|
|
320
|
-
|
|
321
|
-
if (
|
|
347
|
+
if (this.hasAttribute("read-only")) props.readOnly = true;
|
|
348
|
+
if (this.getAttribute("status-bar") === "false") props.statusBar = false;
|
|
349
|
+
const height = this.getAttribute("height");
|
|
350
|
+
if (height) props.height = /^\d+$/.test(height) ? Number(height) : height;
|
|
351
|
+
const label = this.getAttribute("aria-label");
|
|
352
|
+
if (label) props.ariaLabel = label;
|
|
353
|
+
const uploadUrl = this.getAttribute("upload-url");
|
|
354
|
+
if (this.uploadValue) props.upload = this.uploadValue;
|
|
355
|
+
else if (uploadUrl) props.upload = { url: uploadUrl };
|
|
356
|
+
if (this.fontsValue) props.fonts = this.fontsValue;
|
|
357
|
+
if (this.highlighterValue) props.highlighter = this.highlighterValue;
|
|
358
|
+
if (this.fontSizesValue) props.fontSizes = this.fontSizesValue;
|
|
322
359
|
return props;
|
|
323
360
|
}
|
|
324
361
|
syncFormValue(html) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var AerizWysiwygWC=function(
|
|
1
|
+
var AerizWysiwygWC=function(c,f){"use strict";var D=Object.defineProperty;var W=(c,f,v)=>f in c?D(c,f,{enumerable:!0,configurable:!0,writable:!0,value:v}):c[f]=v;var h=(c,f,v)=>W(c,typeof f!="symbol"?f+"":f,v);const v=new Set(["value","onChange","onStateChange","onReady","onDestroy"]);function L(i,t,e){const l={element:i,onChange:e};for(const[n,g]of Object.entries(t))g===void 0||v.has(n)||(l[n]=g);const r=t.value??t.initialHTML;return r!==void 0&&(l.initialHTML=r),l}const C=["upload","htmlStyles","onError"],z=["locale","statusBar","height","ariaLabel","fonts","fontSizes","highlighter"];function O(i,t){return i===t?!0:typeof i!="object"||typeof t!="object"||!i||!t?!1:JSON.stringify(i)===JSON.stringify(t)}function M(i,t){return i===t?!0:i===!1||t===!1||i===void 0||t===void 0||i.sticky!==t.sticky||i.items.length!==t.items.length?!1:i.items.every((e,l)=>e===t.items[l])}function H(i,t){let e=t,l="",r=!1,n=!1;const g=o=>{var u;l=o,!r&&((u=e.onChange)==null||u.call(e,o))};let s,a=null,b;const y=o=>{const u=b;for(const d of C)o[d]===void 0?delete u[d]:u[d]=o[d]},m=(o,u)=>{var T;const d=u!==void 0?{...o,value:u}:o;b=L(i,d,g),s=new f.AerizEditor(b),l=s.getHTML(),a=s.onStateChange(I=>{var A;return(A=e.onStateChange)==null?void 0:A.call(e,I)}),(T=e.onReady)==null||T.call(e,s)},p=()=>{var o;(o=e.onDestroy)==null||o.call(e,s),a==null||a(),a=null,s.destroy()};return m(e),{get editor(){return s},update(o){if(n)return;const u=e;if(e=o,!M(o.toolbar,u.toolbar)||z.some(d=>!O(o[d],u[d]))){const d=o.value??s.getHTML();p(),m(o,d);return}if(y(o),o.theme!==u.theme&&o.theme!==void 0&&s.setTheme(o.theme),!!o.readOnly!=!!u.readOnly&&s.setReadOnly(!!o.readOnly),o.placeholder!==u.placeholder&&(o.placeholder===void 0?delete s.content.dataset.placeholder:s.content.dataset.placeholder=o.placeholder),o.value!==void 0&&o.value!==l&&o.value!==s.getHTML()){r=!0;try{s.setHTML(o.value)}finally{r=!1}l=o.value}},destroy(){n||(n=!0,p())}}}function P(i,t){const e={element:i};return t.blocks!==void 0?e.initialBlocks=t.blocks:t.html!==void 0&&(e.initialHTML=t.html),t.theme!==void 0&&(e.theme=t.theme),t.htmlStyles!==void 0&&(e.htmlStyles=t.htmlStyles),e}function w(i,t){var g;let e=t,l=!1;const r=P(i,t),n=new f.AerizViewer(r);return(g=e.onReady)==null||g.call(e,n),{viewer:n,update(s){if(l)return;const a=e;e=s,s.theme!==a.theme&&s.theme!==void 0&&n.setTheme(s.theme),s.htmlStyles===void 0?delete r.htmlStyles:r.htmlStyles=s.htmlStyles,s.blocks!==void 0?s.blocks!==a.blocks&&n.setBlocks(s.blocks):s.html!==void 0&&s.html!==a.html&&s.html!==n.getHTML()&&n.setHTML(s.html)},destroy(){var s;l||(l=!0,(s=e.onDestroy)==null||s.call(e,n),n.destroy())}}}const B=["light","dark"],R=["en","ko","ja","zh"];function E(i){return i!==null&&B.includes(i)?i:void 0}function j(i){return i!==null&&R.includes(i)?i:void 0}function N(i){if(i===null)return;const t=i.trim();if(t==="")return;if(t==="false"||t==="none")return!1;if(t.startsWith("{")){try{const l=JSON.parse(t);if(l&&typeof l=="object"&&Array.isArray(l.items))return l}catch{}return}const e=t.split(/[\s,]+/).filter(l=>l.length>0);return e.length>0?{items:e}:void 0}function F(i){const t=i.attachInternals;if(typeof t!="function")return null;try{const e=t.call(i);return typeof e=="object"&&e!==null&&typeof e.setFormValue=="function"?e:null}catch{return null}}class V extends HTMLElement{constructor(){super();h(this,"uploadValue");h(this,"fontsValue");h(this,"highlighterValue");h(this,"fontSizesValue");h(this,"controller",null);h(this,"internals",null);h(this,"pendingValue");h(this,"currentHTML","");this.internals=F(this)}static get observedAttributes(){return["value","placeholder","theme","locale","toolbar","html-styles","read-only","height","status-bar","upload-url","aria-label"]}get upload(){return this.uploadValue}set upload(e){this.uploadValue=e,this.applyProps()}get highlighter(){return this.highlighterValue}set highlighter(e){this.highlighterValue=e,this.applyProps()}get fonts(){return this.fontsValue}set fonts(e){this.fontsValue=e,this.applyProps()}get fontSizes(){return this.fontSizesValue}set fontSizes(e){this.fontSizesValue=e,this.applyProps()}get value(){return this.controller?this.controller.editor.getHTML():this.pendingValue??this.currentHTML}set value(e){this.pendingValue=e,this.applyProps()}get editor(){var e;return((e=this.controller)==null?void 0:e.editor)??null}getBlocks(){var e;return((e=this.controller)==null?void 0:e.editor.getBlocks())??[]}focus(){var e;(e=this.controller)==null||e.editor.focus()}connectedCallback(){if(!this.controller){if(this.pendingValue===void 0){const e=this.getAttribute("value");e!==null&&(this.pendingValue=e)}this.controller=H(this,this.buildProps()),this.pendingValue=void 0,this.syncFormValue(this.controller.editor.getHTML()),this.dispatchEvent(new CustomEvent("aeriz-ready",{detail:{editor:this.controller.editor},bubbles:!1}))}}disconnectedCallback(){var e;(e=this.controller)==null||e.destroy(),this.controller=null}attributeChangedCallback(e,l,r){e==="value"&&(this.pendingValue=r??""),this.applyProps()}applyProps(){this.controller&&(this.controller.update(this.buildProps()),this.pendingValue=void 0)}buildProps(){const e={onChange:m=>{this.pendingValue=void 0,this.syncFormValue(m),this.dispatchEvent(new CustomEvent("input",{detail:{html:m},bubbles:!0})),this.dispatchEvent(new CustomEvent("change",{detail:{html:m},bubbles:!0}))},onError:(m,p)=>{this.dispatchEvent(new CustomEvent("error",{detail:{error:m,code:p.code},bubbles:!0}))}};this.pendingValue!==void 0&&(e.value=this.pendingValue);const l=this.getAttribute("placeholder");l!==null&&(e.placeholder=l);const r=E(this.getAttribute("theme"));r!==void 0&&(e.theme=r);const n=j(this.getAttribute("locale"));n!==void 0&&(e.locale=n);const g=N(this.getAttribute("toolbar"));g!==void 0&&(e.toolbar=g);const s=this.getAttribute("html-styles");(s==="class"||s==="inline")&&(e.htmlStyles=s),this.hasAttribute("read-only")&&(e.readOnly=!0),this.getAttribute("status-bar")==="false"&&(e.statusBar=!1);const a=this.getAttribute("height");a&&(e.height=/^\d+$/.test(a)?Number(a):a);const b=this.getAttribute("aria-label");b&&(e.ariaLabel=b);const y=this.getAttribute("upload-url");return this.uploadValue?e.upload=this.uploadValue:y&&(e.upload={url:y}),this.fontsValue&&(e.fonts=this.fontsValue),this.highlighterValue&&(e.highlighter=this.highlighterValue),this.fontSizesValue&&(e.fontSizes=this.fontSizesValue),e}syncFormValue(e){var l;this.currentHTML=e,(l=this.internals)==null||l.setFormValue(e)}}h(V,"formAssociated",!0);class S extends HTMLElement{constructor(){super(...arguments);h(this,"controller",null);h(this,"pendingBlocks")}static get observedAttributes(){return["html","theme"]}get blocks(){var e;return((e=this.controller)==null?void 0:e.viewer.getBlocks())??this.pendingBlocks??[]}set blocks(e){var l;this.pendingBlocks=e,(l=this.controller)==null||l.update(this.buildProps())}get viewer(){var e;return((e=this.controller)==null?void 0:e.viewer)??null}connectedCallback(){this.controller||(this.controller=w(this,this.buildProps()),this.dispatchEvent(new CustomEvent("aeriz-ready",{detail:{viewer:this.controller.viewer},bubbles:!1})))}disconnectedCallback(){var e;(e=this.controller)==null||e.destroy(),this.controller=null}attributeChangedCallback(){var e;(e=this.controller)==null||e.update(this.buildProps())}buildProps(){const e={};this.pendingBlocks!==void 0&&(e.blocks=this.pendingBlocks);const l=this.getAttribute("html");l!==null&&(e.html=l);const r=E(this.getAttribute("theme"));return r!==void 0&&(e.theme=r),e}}function k(i="aeriz"){if(typeof customElements>"u")return;const t=`${i}-editor`,e=`${i}-viewer`;customElements.get(t)||customElements.define(t,V),customElements.get(e)||customElements.define(e,S)}return k(),c.AerizEditorElement=V,c.AerizViewerElement=S,c.defineAerizElements=k,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}),c}({},AerizWysiwyg);
|