@leafer-in/text-editor 1.0.10 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/text-editor.cjs
CHANGED
|
@@ -121,7 +121,7 @@ exports.TextEditor = class TextEditor extends editor.InnerEditor {
|
|
|
121
121
|
style.position = 'fixed';
|
|
122
122
|
style.transformOrigin = 'left top';
|
|
123
123
|
style.boxSizing = 'border-box';
|
|
124
|
-
this.isHTMLText ? div.innerHTML = text.text : div.innerText = text.text;
|
|
124
|
+
this.isHTMLText ? div.innerHTML = String(text.text) : div.innerText = String(text.text);
|
|
125
125
|
const { view } = editor.app;
|
|
126
126
|
(this.inBody = view instanceof HTMLCanvasElement) ? document.body.appendChild(div) : view.appendChild(div);
|
|
127
127
|
this.eventIds = [
|
package/dist/text-editor.esm.js
CHANGED
|
@@ -119,7 +119,7 @@ let TextEditor = class TextEditor extends InnerEditor {
|
|
|
119
119
|
style.position = 'fixed';
|
|
120
120
|
style.transformOrigin = 'left top';
|
|
121
121
|
style.boxSizing = 'border-box';
|
|
122
|
-
this.isHTMLText ? div.innerHTML = text.text : div.innerText = text.text;
|
|
122
|
+
this.isHTMLText ? div.innerHTML = String(text.text) : div.innerText = String(text.text);
|
|
123
123
|
const { view } = editor.app;
|
|
124
124
|
(this.inBody = view instanceof HTMLCanvasElement) ? document.body.appendChild(div) : view.appendChild(div);
|
|
125
125
|
this.eventIds = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ColorConvert as e,Text as t,PointerEvent as n,Matrix as i}from"@leafer-ui/core";import{registerInnerEditor as o,InnerEditor as s}from"@leafer-in/editor";"function"==typeof SuppressedError&&SuppressedError;const r={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},a={top:"flex-start",middle:"center",bottom:"flex-end"};function l(t,n,i){const{style:o}=t,{fill:s,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=n;o.fontFamily=n.fontFamily,o.fontSize=n.fontSize*i+"px",function(t,n){let i="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":i=e.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const t=n.stops[0];i=e.string("string"==typeof t?t:t.color);break;default:void 0!==n.r&&(i=e.string(n))}else i=n;t.color=i}(o,s),o.fontStyle=n.italic?"italic":"normal",o.fontWeight=n.fontWeight,o.textDecoration="delete"===p?"line-through":p,o.textTransform=r[n.textCase],o.textAlign=n.textAlign,o.display="flex",o.flexDirection="column",o.justifyContent=a[n.verticalAlign],o.lineHeight=(n.__.__lineHeight||0)*i+"px",o.letterSpacing=(n.__.__letterSpacing||0)*i+"px","none"===c?o.whiteSpace="nowrap":"break"===c&&(o.wordBreak="break-all"),o.textIndent=(n.paraIndent||0)*i+"px",o.padding=l instanceof Array?l.map((e=>e*i+"px")).join(" "):(l||0)*i+"px",o.textOverflow="show"===d?"":"hide"===d?"clip":d}let c=class extends s{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:e}=this,{config:i}=e.app,o=this.editTarget;o.visible=!1,this.isHTMLText=!(o instanceof t),this._keyEvent=i.keyEvent,i.keyEvent=!1;const s=this.editDom=document.createElement("div"),{style:r}=s;s.contentEditable="true",r.position="fixed",r.transformOrigin="left top",r.boxSizing="border-box",this.isHTMLText?s.innerHTML=o.text:s.innerText=o.text;const{view:a}=e.app;(this.inBody=a instanceof HTMLCanvasElement)?document.body.appendChild(s):a.appendChild(s),this.eventIds=[e.app.on_(n.DOWN,(t=>{let n,{target:i}=t.origin;for(;i;)i===s&&(n=!0),i=i.parentElement;n||e.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),this.onEscape=this.onEscape.bind(this),s.addEventListener("focus",this.onFocus),s.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const l=window.getSelection(),c=document.createRange();if(this.config.selectAll)c.selectNodeContents(s);else{const e=s.childNodes[0];c.setStartAfter(e),c.setEndAfter(e),c.collapse(!0)}l.removeAllRanges(),l.addRange(c)}onInput(){const{editDom:e}=this;this.editTarget.text=this.isHTMLText?e.innerHTML:e.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:e}=this;let t=1;if(!this.isHTMLText){const{scaleX:n,scaleY:i}=e.worldTransform;t=Math.max(Math.abs(n),Math.abs(i));e.fontSize*t<12&&(t*=12/e.fontSize)}this.textScale=t;const{a:n,b:o,c:s,d:r,e:a,f:c}=new i(e.worldTransform).scale(1/t);let{x:d,y:p}=this.inBody?e.app.clientBounds:e.app.tree.clientBounds;this.inBody||(d-=window.scrollX,p-=window.scrollY);let{width:h,height:f}=e;h*=t,f*=t;const g=e.__;if(g.__autoWidth&&g.autoSizeAlign)switch(h+=20,g.textAlign){case"center":d-=h/2;break;case"right":d-=h}if(g.__autoHeight&&g.autoSizeAlign)switch(f+=20,g.verticalAlign){case"middle":p-=f/2;break;case"bottom":p-=f}const{style:u}=this.editDom;u.transform=`matrix(${n},${o},${s},${r},${a},${c})`,u.left=d+"px",u.top=p+"px",u.width=h+"px",u.height=f+"px",this.isHTMLText||l(this.editDom,e,t)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,t.app&&(t.app.config.keyEvent=this._keyEvent),t.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("keydown",this.onEscape),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.editDom=this.eventIds=void 0)}};c=function(e,t,n,i){var o,s=arguments.length,r=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(r=(s<3?o(r):s>3?o(t,n,r):o(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}([o()],c);export{c as TextEditor};
|
|
1
|
+
import{ColorConvert as e,Text as t,PointerEvent as n,Matrix as i}from"@leafer-ui/core";import{registerInnerEditor as o,InnerEditor as s}from"@leafer-in/editor";"function"==typeof SuppressedError&&SuppressedError;const r={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},a={top:"flex-start",middle:"center",bottom:"flex-end"};function l(t,n,i){const{style:o}=t,{fill:s,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=n;o.fontFamily=n.fontFamily,o.fontSize=n.fontSize*i+"px",function(t,n){let i="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":i=e.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const t=n.stops[0];i=e.string("string"==typeof t?t:t.color);break;default:void 0!==n.r&&(i=e.string(n))}else i=n;t.color=i}(o,s),o.fontStyle=n.italic?"italic":"normal",o.fontWeight=n.fontWeight,o.textDecoration="delete"===p?"line-through":p,o.textTransform=r[n.textCase],o.textAlign=n.textAlign,o.display="flex",o.flexDirection="column",o.justifyContent=a[n.verticalAlign],o.lineHeight=(n.__.__lineHeight||0)*i+"px",o.letterSpacing=(n.__.__letterSpacing||0)*i+"px","none"===c?o.whiteSpace="nowrap":"break"===c&&(o.wordBreak="break-all"),o.textIndent=(n.paraIndent||0)*i+"px",o.padding=l instanceof Array?l.map((e=>e*i+"px")).join(" "):(l||0)*i+"px",o.textOverflow="show"===d?"":"hide"===d?"clip":d}let c=class extends s{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:e}=this,{config:i}=e.app,o=this.editTarget;o.visible=!1,this.isHTMLText=!(o instanceof t),this._keyEvent=i.keyEvent,i.keyEvent=!1;const s=this.editDom=document.createElement("div"),{style:r}=s;s.contentEditable="true",r.position="fixed",r.transformOrigin="left top",r.boxSizing="border-box",this.isHTMLText?s.innerHTML=String(o.text):s.innerText=String(o.text);const{view:a}=e.app;(this.inBody=a instanceof HTMLCanvasElement)?document.body.appendChild(s):a.appendChild(s),this.eventIds=[e.app.on_(n.DOWN,(t=>{let n,{target:i}=t.origin;for(;i;)i===s&&(n=!0),i=i.parentElement;n||e.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),this.onEscape=this.onEscape.bind(this),s.addEventListener("focus",this.onFocus),s.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const l=window.getSelection(),c=document.createRange();if(this.config.selectAll)c.selectNodeContents(s);else{const e=s.childNodes[0];c.setStartAfter(e),c.setEndAfter(e),c.collapse(!0)}l.removeAllRanges(),l.addRange(c)}onInput(){const{editDom:e}=this;this.editTarget.text=this.isHTMLText?e.innerHTML:e.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:e}=this;let t=1;if(!this.isHTMLText){const{scaleX:n,scaleY:i}=e.worldTransform;t=Math.max(Math.abs(n),Math.abs(i));e.fontSize*t<12&&(t*=12/e.fontSize)}this.textScale=t;const{a:n,b:o,c:s,d:r,e:a,f:c}=new i(e.worldTransform).scale(1/t);let{x:d,y:p}=this.inBody?e.app.clientBounds:e.app.tree.clientBounds;this.inBody||(d-=window.scrollX,p-=window.scrollY);let{width:h,height:f}=e;h*=t,f*=t;const g=e.__;if(g.__autoWidth&&g.autoSizeAlign)switch(h+=20,g.textAlign){case"center":d-=h/2;break;case"right":d-=h}if(g.__autoHeight&&g.autoSizeAlign)switch(f+=20,g.verticalAlign){case"middle":p-=f/2;break;case"bottom":p-=f}const{style:u}=this.editDom;u.transform=`matrix(${n},${o},${s},${r},${a},${c})`,u.left=d+"px",u.top=p+"px",u.width=h+"px",u.height=f+"px",this.isHTMLText||l(this.editDom,e,t)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,t.app&&(t.app.config.keyEvent=this._keyEvent),t.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("keydown",this.onEscape),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.editDom=this.eventIds=void 0)}};c=function(e,t,n,i){var o,s=arguments.length,r=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(r=(s<3?o(r):s>3?o(t,n,r):o(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}([o()],c);export{c as TextEditor};
|
package/dist/text-editor.js
CHANGED
|
@@ -120,7 +120,7 @@ this.LeaferIN.textEditor = (function (exports, core, editor) {
|
|
|
120
120
|
style.position = 'fixed';
|
|
121
121
|
style.transformOrigin = 'left top';
|
|
122
122
|
style.boxSizing = 'border-box';
|
|
123
|
-
this.isHTMLText ? div.innerHTML = text.text : div.innerText = text.text;
|
|
123
|
+
this.isHTMLText ? div.innerHTML = String(text.text) : div.innerText = String(text.text);
|
|
124
124
|
const { view } = editor.app;
|
|
125
125
|
(this.inBody = view instanceof HTMLCanvasElement) ? document.body.appendChild(div) : view.appendChild(div);
|
|
126
126
|
this.eventIds = [
|
package/dist/text-editor.min.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@leafer-ui/core"),t=require("@leafer-in/editor");"function"==typeof SuppressedError&&SuppressedError;const n={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},i={top:"flex-start",middle:"center",bottom:"flex-end"};function o(t,o,s){const{style:r}=t,{fill:a,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=o;r.fontFamily=o.fontFamily,r.fontSize=o.fontSize*s+"px",function(t,n){let i="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":i=e.ColorConvert.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const t=n.stops[0];i=e.ColorConvert.string("string"==typeof t?t:t.color);break;default:void 0!==n.r&&(i=e.ColorConvert.string(n))}else i=n;t.color=i}(r,a),r.fontStyle=o.italic?"italic":"normal",r.fontWeight=o.fontWeight,r.textDecoration="delete"===p?"line-through":p,r.textTransform=n[o.textCase],r.textAlign=o.textAlign,r.display="flex",r.flexDirection="column",r.justifyContent=i[o.verticalAlign],r.lineHeight=(o.__.__lineHeight||0)*s+"px",r.letterSpacing=(o.__.__letterSpacing||0)*s+"px","none"===c?r.whiteSpace="nowrap":"break"===c&&(r.wordBreak="break-all"),r.textIndent=(o.paraIndent||0)*s+"px",r.padding=l instanceof Array?l.map((e=>e*s+"px")).join(" "):(l||0)*s+"px",r.textOverflow="show"===d?"":"hide"===d?"clip":d}exports.TextEditor=class extends t.InnerEditor{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:t}=this,{config:n}=t.app,i=this.editTarget;i.visible=!1,this.isHTMLText=!(i instanceof e.Text),this._keyEvent=n.keyEvent,n.keyEvent=!1;const o=this.editDom=document.createElement("div"),{style:s}=o;o.contentEditable="true",s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box",this.isHTMLText?o.innerHTML=i.text:o.innerText=i.text;const{view:r}=t.app;(this.inBody=r instanceof HTMLCanvasElement)?document.body.appendChild(o):r.appendChild(o),this.eventIds=[t.app.on_(e.PointerEvent.DOWN,(e=>{let n,{target:i}=e.origin;for(;i;)i===o&&(n=!0),i=i.parentElement;n||t.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),this.onEscape=this.onEscape.bind(this),o.addEventListener("focus",this.onFocus),o.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const a=window.getSelection(),l=document.createRange();if(this.config.selectAll)l.selectNodeContents(o);else{const e=o.childNodes[0];l.setStartAfter(e),l.setEndAfter(e),l.collapse(!0)}a.removeAllRanges(),a.addRange(l)}onInput(){const{editDom:e}=this;this.editTarget.text=this.isHTMLText?e.innerHTML:e.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:t}=this;let n=1;if(!this.isHTMLText){const{scaleX:e,scaleY:i}=t.worldTransform;n=Math.max(Math.abs(e),Math.abs(i));t.fontSize*n<12&&(n*=12/t.fontSize)}this.textScale=n;const{a:i,b:s,c:r,d:a,e:l,f:c}=new e.Matrix(t.worldTransform).scale(1/n);let{x:d,y:p}=this.inBody?t.app.clientBounds:t.app.tree.clientBounds;this.inBody||(d-=window.scrollX,p-=window.scrollY);let{width:h,height:f}=t;h*=n,f*=n;const x=t.__;if(x.__autoWidth&&x.autoSizeAlign)switch(h+=20,x.textAlign){case"center":d-=h/2;break;case"right":d-=h}if(x.__autoHeight&&x.autoSizeAlign)switch(f+=20,x.verticalAlign){case"middle":p-=f/2;break;case"bottom":p-=f}const{style:
|
|
1
|
+
"use strict";var e=require("@leafer-ui/core"),t=require("@leafer-in/editor");"function"==typeof SuppressedError&&SuppressedError;const n={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},i={top:"flex-start",middle:"center",bottom:"flex-end"};function o(t,o,s){const{style:r}=t,{fill:a,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=o;r.fontFamily=o.fontFamily,r.fontSize=o.fontSize*s+"px",function(t,n){let i="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":i=e.ColorConvert.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const t=n.stops[0];i=e.ColorConvert.string("string"==typeof t?t:t.color);break;default:void 0!==n.r&&(i=e.ColorConvert.string(n))}else i=n;t.color=i}(r,a),r.fontStyle=o.italic?"italic":"normal",r.fontWeight=o.fontWeight,r.textDecoration="delete"===p?"line-through":p,r.textTransform=n[o.textCase],r.textAlign=o.textAlign,r.display="flex",r.flexDirection="column",r.justifyContent=i[o.verticalAlign],r.lineHeight=(o.__.__lineHeight||0)*s+"px",r.letterSpacing=(o.__.__letterSpacing||0)*s+"px","none"===c?r.whiteSpace="nowrap":"break"===c&&(r.wordBreak="break-all"),r.textIndent=(o.paraIndent||0)*s+"px",r.padding=l instanceof Array?l.map((e=>e*s+"px")).join(" "):(l||0)*s+"px",r.textOverflow="show"===d?"":"hide"===d?"clip":d}exports.TextEditor=class extends t.InnerEditor{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:t}=this,{config:n}=t.app,i=this.editTarget;i.visible=!1,this.isHTMLText=!(i instanceof e.Text),this._keyEvent=n.keyEvent,n.keyEvent=!1;const o=this.editDom=document.createElement("div"),{style:s}=o;o.contentEditable="true",s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box",this.isHTMLText?o.innerHTML=String(i.text):o.innerText=String(i.text);const{view:r}=t.app;(this.inBody=r instanceof HTMLCanvasElement)?document.body.appendChild(o):r.appendChild(o),this.eventIds=[t.app.on_(e.PointerEvent.DOWN,(e=>{let n,{target:i}=e.origin;for(;i;)i===o&&(n=!0),i=i.parentElement;n||t.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),this.onEscape=this.onEscape.bind(this),o.addEventListener("focus",this.onFocus),o.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const a=window.getSelection(),l=document.createRange();if(this.config.selectAll)l.selectNodeContents(o);else{const e=o.childNodes[0];l.setStartAfter(e),l.setEndAfter(e),l.collapse(!0)}a.removeAllRanges(),a.addRange(l)}onInput(){const{editDom:e}=this;this.editTarget.text=this.isHTMLText?e.innerHTML:e.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:t}=this;let n=1;if(!this.isHTMLText){const{scaleX:e,scaleY:i}=t.worldTransform;n=Math.max(Math.abs(e),Math.abs(i));t.fontSize*n<12&&(n*=12/t.fontSize)}this.textScale=n;const{a:i,b:s,c:r,d:a,e:l,f:c}=new e.Matrix(t.worldTransform).scale(1/n);let{x:d,y:p}=this.inBody?t.app.clientBounds:t.app.tree.clientBounds;this.inBody||(d-=window.scrollX,p-=window.scrollY);let{width:h,height:f}=t;h*=n,f*=n;const x=t.__;if(x.__autoWidth&&x.autoSizeAlign)switch(h+=20,x.textAlign){case"center":d-=h/2;break;case"right":d-=h}if(x.__autoHeight&&x.autoSizeAlign)switch(f+=20,x.verticalAlign){case"middle":p-=f/2;break;case"bottom":p-=f}const{style:g}=this.editDom;g.transform=`matrix(${i},${s},${r},${a},${l},${c})`,g.left=d+"px",g.top=p+"px",g.width=h+"px",g.height=f+"px",this.isHTMLText||o(this.editDom,t,n)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,t.app&&(t.app.config.keyEvent=this._keyEvent),t.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("keydown",this.onEscape),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.editDom=this.eventIds=void 0)}},exports.TextEditor=function(e,t,n,i){var o,s=arguments.length,r=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(r=(s<3?o(r):s>3?o(t,n,r):o(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}([t.registerInnerEditor()],exports.TextEditor);
|
package/dist/text-editor.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.textEditor=function(t,e,n){"use strict";"function"==typeof SuppressedError&&SuppressedError;const i={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},o={top:"flex-start",middle:"center",bottom:"flex-end"};function s(t,n,s){const{style:r}=t,{fill:a,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=n;r.fontFamily=n.fontFamily,r.fontSize=n.fontSize*s+"px",function(t,n){let i="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":i=e.ColorConvert.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const t=n.stops[0];i=e.ColorConvert.string("string"==typeof t?t:t.color);break;default:void 0!==n.r&&(i=e.ColorConvert.string(n))}else i=n;t.color=i}(r,a),r.fontStyle=n.italic?"italic":"normal",r.fontWeight=n.fontWeight,r.textDecoration="delete"===p?"line-through":p,r.textTransform=i[n.textCase],r.textAlign=n.textAlign,r.display="flex",r.flexDirection="column",r.justifyContent=o[n.verticalAlign],r.lineHeight=(n.__.__lineHeight||0)*s+"px",r.letterSpacing=(n.__.__letterSpacing||0)*s+"px","none"===c?r.whiteSpace="nowrap":"break"===c&&(r.wordBreak="break-all"),r.textIndent=(n.paraIndent||0)*s+"px",r.padding=l instanceof Array?l.map((t=>t*s+"px")).join(" "):(l||0)*s+"px",r.textOverflow="show"===d?"":"hide"===d?"clip":d}return t.TextEditor=class extends n.InnerEditor{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:t}=this,{config:n}=t.app,i=this.editTarget;i.visible=!1,this.isHTMLText=!(i instanceof e.Text),this._keyEvent=n.keyEvent,n.keyEvent=!1;const o=this.editDom=document.createElement("div"),{style:s}=o;o.contentEditable="true",s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box",this.isHTMLText?o.innerHTML=i.text:o.innerText=i.text;const{view:r}=t.app;(this.inBody=r instanceof HTMLCanvasElement)?document.body.appendChild(o):r.appendChild(o),this.eventIds=[t.app.on_(e.PointerEvent.DOWN,(e=>{let n,{target:i}=e.origin;for(;i;)i===o&&(n=!0),i=i.parentElement;n||t.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),this.onEscape=this.onEscape.bind(this),o.addEventListener("focus",this.onFocus),o.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const a=window.getSelection(),l=document.createRange();if(this.config.selectAll)l.selectNodeContents(o);else{const t=o.childNodes[0];l.setStartAfter(t),l.setEndAfter(t),l.collapse(!0)}a.removeAllRanges(),a.addRange(l)}onInput(){const{editDom:t}=this;this.editTarget.text=this.isHTMLText?t.innerHTML:t.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(t){"Escape"===t.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:t}=this;let n=1;if(!this.isHTMLText){const{scaleX:e,scaleY:i}=t.worldTransform;n=Math.max(Math.abs(e),Math.abs(i));t.fontSize*n<12&&(n*=12/t.fontSize)}this.textScale=n;const{a:i,b:o,c:r,d:a,e:l,f:c}=new e.Matrix(t.worldTransform).scale(1/n);let{x:d,y:p}=this.inBody?t.app.clientBounds:t.app.tree.clientBounds;this.inBody||(d-=window.scrollX,p-=window.scrollY);let{width:h,height:f}=t;h*=n,f*=n;const
|
|
1
|
+
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.textEditor=function(t,e,n){"use strict";"function"==typeof SuppressedError&&SuppressedError;const i={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},o={top:"flex-start",middle:"center",bottom:"flex-end"};function s(t,n,s){const{style:r}=t,{fill:a,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=n;r.fontFamily=n.fontFamily,r.fontSize=n.fontSize*s+"px",function(t,n){let i="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":i=e.ColorConvert.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const t=n.stops[0];i=e.ColorConvert.string("string"==typeof t?t:t.color);break;default:void 0!==n.r&&(i=e.ColorConvert.string(n))}else i=n;t.color=i}(r,a),r.fontStyle=n.italic?"italic":"normal",r.fontWeight=n.fontWeight,r.textDecoration="delete"===p?"line-through":p,r.textTransform=i[n.textCase],r.textAlign=n.textAlign,r.display="flex",r.flexDirection="column",r.justifyContent=o[n.verticalAlign],r.lineHeight=(n.__.__lineHeight||0)*s+"px",r.letterSpacing=(n.__.__letterSpacing||0)*s+"px","none"===c?r.whiteSpace="nowrap":"break"===c&&(r.wordBreak="break-all"),r.textIndent=(n.paraIndent||0)*s+"px",r.padding=l instanceof Array?l.map((t=>t*s+"px")).join(" "):(l||0)*s+"px",r.textOverflow="show"===d?"":"hide"===d?"clip":d}return t.TextEditor=class extends n.InnerEditor{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:t}=this,{config:n}=t.app,i=this.editTarget;i.visible=!1,this.isHTMLText=!(i instanceof e.Text),this._keyEvent=n.keyEvent,n.keyEvent=!1;const o=this.editDom=document.createElement("div"),{style:s}=o;o.contentEditable="true",s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box",this.isHTMLText?o.innerHTML=String(i.text):o.innerText=String(i.text);const{view:r}=t.app;(this.inBody=r instanceof HTMLCanvasElement)?document.body.appendChild(o):r.appendChild(o),this.eventIds=[t.app.on_(e.PointerEvent.DOWN,(e=>{let n,{target:i}=e.origin;for(;i;)i===o&&(n=!0),i=i.parentElement;n||t.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),this.onEscape=this.onEscape.bind(this),o.addEventListener("focus",this.onFocus),o.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const a=window.getSelection(),l=document.createRange();if(this.config.selectAll)l.selectNodeContents(o);else{const t=o.childNodes[0];l.setStartAfter(t),l.setEndAfter(t),l.collapse(!0)}a.removeAllRanges(),a.addRange(l)}onInput(){const{editDom:t}=this;this.editTarget.text=this.isHTMLText?t.innerHTML:t.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(t){"Escape"===t.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:t}=this;let n=1;if(!this.isHTMLText){const{scaleX:e,scaleY:i}=t.worldTransform;n=Math.max(Math.abs(e),Math.abs(i));t.fontSize*n<12&&(n*=12/t.fontSize)}this.textScale=n;const{a:i,b:o,c:r,d:a,e:l,f:c}=new e.Matrix(t.worldTransform).scale(1/n);let{x:d,y:p}=this.inBody?t.app.clientBounds:t.app.tree.clientBounds;this.inBody||(d-=window.scrollX,p-=window.scrollY);let{width:h,height:f}=t;h*=n,f*=n;const g=t.__;if(g.__autoWidth&&g.autoSizeAlign)switch(h+=20,g.textAlign){case"center":d-=h/2;break;case"right":d-=h}if(g.__autoHeight&&g.autoSizeAlign)switch(f+=20,g.verticalAlign){case"middle":p-=f/2;break;case"bottom":p-=f}const{style:x}=this.editDom;x.transform=`matrix(${i},${o},${r},${a},${l},${c})`,x.left=d+"px",x.top=p+"px",x.width=h+"px",x.height=f+"px",this.isHTMLText||s(this.editDom,t,n)}onUnload(){const{editTarget:t,editor:e,editDom:n}=this;t&&(this.onInput(),t.visible=!0,e.app&&(e.app.config.keyEvent=this._keyEvent),e.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("keydown",this.onEscape),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.editDom=this.eventIds=void 0)}},t.TextEditor=function(t,e,n,i){var o,s=arguments.length,r=s<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(s<3?o(r):s>3?o(e,n,r):o(e,n))||r);return s>3&&r&&Object.defineProperty(e,n,r),r}([n.registerInnerEditor()],t.TextEditor),t}({},LeaferUI,LeaferIN.editor);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/text-editor",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "@leafer-in/text-editor",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"leaferjs"
|
|
35
35
|
],
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@leafer-in/editor": "^1.0
|
|
38
|
-
"@leafer-ui/core": "^1.0
|
|
39
|
-
"@leafer-ui/interface": "^1.0
|
|
40
|
-
"@leafer-in/interface": "^1.0
|
|
37
|
+
"@leafer-in/editor": "^1.1.0",
|
|
38
|
+
"@leafer-ui/core": "^1.1.0",
|
|
39
|
+
"@leafer-ui/interface": "^1.1.0",
|
|
40
|
+
"@leafer-in/interface": "^1.1.0"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/TextEditor.ts
CHANGED
|
@@ -41,7 +41,7 @@ export class TextEditor extends InnerEditor {
|
|
|
41
41
|
style.transformOrigin = 'left top'
|
|
42
42
|
style.boxSizing = 'border-box'
|
|
43
43
|
|
|
44
|
-
this.isHTMLText ? div.innerHTML = text.text : div.innerText = text.text
|
|
44
|
+
this.isHTMLText ? div.innerHTML = String(text.text) : div.innerText = String(text.text)
|
|
45
45
|
|
|
46
46
|
const { view } = editor.app;
|
|
47
47
|
(this.inBody = view instanceof HTMLCanvasElement) ? document.body.appendChild(div) : (view as HTMLDivElement).appendChild(div)
|