@leafer-in/text-editor 1.0.0-rc.25 → 1.0.0-rc.26
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
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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"},o={top:"flex-start",middle:"center",bottom:"flex-end"},i=e.inviteCode;function s(t,i,s){const{style:r}=t,{fill:a,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=i;r.fontFamily=i.fontFamily,r.fontSize=i.fontSize*s+"px",function(t,n){let o="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":o=e.ColorConvert.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const t=n.stops[0];o=e.ColorConvert.string("string"==typeof t?t:t.color);break;default:void 0!==n.r&&(o=e.ColorConvert.string(n))}else o=n;t.color=o}(r,a),r.fontStyle=i.italic?"italic":"normal",r.fontWeight=i.fontWeight,r.textDecoration="delete"===p?"line-through":p,r.textTransform=n[i.textCase],r.textAlign=i.textAlign,r.display="flex",r.flexDirection="column",r.justifyContent=o[i.verticalAlign],r.lineHeight=(i.__.__lineHeight||0)*s+"px",r.letterSpacing=(i.__.__letterSpacing||0)*s+"px","none"===c?r.whiteSpace="nowrap":"break"===c&&(r.wordBreak="break-all"),r.textIndent=(i.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}function r(e){return e.length>6&&"e"===e[6]}let a=s;setTimeout((function(){Object.values(i).some(r)||(a=()=>s)})),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;this._keyEvent=n.keyEvent,n.keyEvent=!1;const o=this.editTarget;o.visible=!1;const i=this.editDom=document.createElement("div"),{style:s}=i;i.contentEditable="true",i.innerText=o.text,s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box";const{scaleX:r,scaleY:a}=o.worldTransform;this.textScale=Math.max(Math.abs(r),Math.abs(a));const l=o.fontSize*this.textScale;l<12&&(this.textScale*=12/l),t.app.view.appendChild(i),this.eventIds=[t.app.on_(e.PointerEvent.DOWN,(e=>{e.origin.target!==i&&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),i.addEventListener("focus",this.onFocus),i.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const c=window.getSelection(),d=document.createRange();if(this.config.selectAll)d.selectNodeContents(i);else{const e=i.childNodes[0];d.setStartAfter(e),d.setEndAfter(e),d.collapse(!0)}c.removeAllRanges(),c.addRange(d)}onInput(){this.editTarget.text=this.editDom.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:t,textScale:n}=this,{style:o}=this.editDom,{x:i,y:s}=t.app.tree.clientBounds,{a:r,b:l,c:c,d:d,e:p,f:h}=new e.Matrix(t.worldTransform).scale(1/n);o.transform=`matrix(${r},${l},${c},${d},${p},${h})`,o.left=i-window.scrollX+"px",o.top=s-window.scrollY+"px",o.width=t.width*n+(t.__.__autoWidth?20:0)+"px",o.height=t.height*n+(t.__.__autoHeight?20:0)+"px",a(this.editDom,t,this.textScale)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,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,o){var i,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}([t.registerInnerEditor()],exports.TextEditor);
|
package/dist/text-editor.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{inviteCode as t,PointerEvent as
|
|
1
|
+
import{inviteCode as e,ColorConvert as t,PointerEvent as n,Matrix as o}from"@leafer-ui/core";import{registerInnerEditor as i,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"},l=e;function c(e,n,o){const{style:i}=e,{fill:s,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=n;i.fontFamily=n.fontFamily,i.fontSize=n.fontSize*o+"px",function(e,n){let o="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":o=t.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const e=n.stops[0];o=t.string("string"==typeof e?e:e.color);break;default:void 0!==n.r&&(o=t.string(n))}else o=n;e.color=o}(i,s),i.fontStyle=n.italic?"italic":"normal",i.fontWeight=n.fontWeight,i.textDecoration="delete"===p?"line-through":p,i.textTransform=r[n.textCase],i.textAlign=n.textAlign,i.display="flex",i.flexDirection="column",i.justifyContent=a[n.verticalAlign],i.lineHeight=(n.__.__lineHeight||0)*o+"px",i.letterSpacing=(n.__.__letterSpacing||0)*o+"px","none"===c?i.whiteSpace="nowrap":"break"===c&&(i.wordBreak="break-all"),i.textIndent=(n.paraIndent||0)*o+"px",i.padding=l instanceof Array?l.map((e=>e*o+"px")).join(" "):(l||0)*o+"px",i.textOverflow="show"===d?"":"hide"===d?"clip":d}function d(e){return e.length>6&&"e"===e[6]}let p=c;setTimeout((function(){Object.values(l).some(d)||(p=()=>c)}));let h=class extends s{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:e}=this,{config:t}=e.app;this._keyEvent=t.keyEvent,t.keyEvent=!1;const o=this.editTarget;o.visible=!1;const i=this.editDom=document.createElement("div"),{style:s}=i;i.contentEditable="true",i.innerText=o.text,s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box";const{scaleX:r,scaleY:a}=o.worldTransform;this.textScale=Math.max(Math.abs(r),Math.abs(a));const l=o.fontSize*this.textScale;l<12&&(this.textScale*=12/l),e.app.view.appendChild(i),this.eventIds=[e.app.on_(n.DOWN,(t=>{t.origin.target!==i&&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),i.addEventListener("focus",this.onFocus),i.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const c=window.getSelection(),d=document.createRange();if(this.config.selectAll)d.selectNodeContents(i);else{const e=i.childNodes[0];d.setStartAfter(e),d.setEndAfter(e),d.collapse(!0)}c.removeAllRanges(),c.addRange(d)}onInput(){this.editTarget.text=this.editDom.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:e,textScale:t}=this,{style:n}=this.editDom,{x:i,y:s}=e.app.tree.clientBounds,{a:r,b:a,c:l,d:c,e:d,f:h}=new o(e.worldTransform).scale(1/t);n.transform=`matrix(${r},${a},${l},${c},${d},${h})`,n.left=i-window.scrollX+"px",n.top=s-window.scrollY+"px",n.width=e.width*t+(e.__.__autoWidth?20:0)+"px",n.height=e.height*t+(e.__.__autoHeight?20:0)+"px",p(this.editDom,e,this.textScale)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,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)}};h=function(e,t,n,o){var i,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}([i()],h);export{h as TextEditor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{inviteCode as t,PointerEvent as
|
|
1
|
+
import{inviteCode as e,ColorConvert as t,PointerEvent as n,Matrix as o}from"@leafer-ui/core";import{registerInnerEditor as i,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"},l=e;function c(e,n,o){const{style:i}=e,{fill:s,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=n;i.fontFamily=n.fontFamily,i.fontSize=n.fontSize*o+"px",function(e,n){let o="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":o=t.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const e=n.stops[0];o=t.string("string"==typeof e?e:e.color);break;default:void 0!==n.r&&(o=t.string(n))}else o=n;e.color=o}(i,s),i.fontStyle=n.italic?"italic":"normal",i.fontWeight=n.fontWeight,i.textDecoration="delete"===p?"line-through":p,i.textTransform=r[n.textCase],i.textAlign=n.textAlign,i.display="flex",i.flexDirection="column",i.justifyContent=a[n.verticalAlign],i.lineHeight=(n.__.__lineHeight||0)*o+"px",i.letterSpacing=(n.__.__letterSpacing||0)*o+"px","none"===c?i.whiteSpace="nowrap":"break"===c&&(i.wordBreak="break-all"),i.textIndent=(n.paraIndent||0)*o+"px",i.padding=l instanceof Array?l.map((e=>e*o+"px")).join(" "):(l||0)*o+"px",i.textOverflow="show"===d?"":"hide"===d?"clip":d}function d(e){return e.length>6&&"e"===e[6]}let p=c;setTimeout((function(){Object.values(l).some(d)||(p=()=>c)}));let h=class extends s{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:e}=this,{config:t}=e.app;this._keyEvent=t.keyEvent,t.keyEvent=!1;const o=this.editTarget;o.visible=!1;const i=this.editDom=document.createElement("div"),{style:s}=i;i.contentEditable="true",i.innerText=o.text,s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box";const{scaleX:r,scaleY:a}=o.worldTransform;this.textScale=Math.max(Math.abs(r),Math.abs(a));const l=o.fontSize*this.textScale;l<12&&(this.textScale*=12/l),e.app.view.appendChild(i),this.eventIds=[e.app.on_(n.DOWN,(t=>{t.origin.target!==i&&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),i.addEventListener("focus",this.onFocus),i.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const c=window.getSelection(),d=document.createRange();if(this.config.selectAll)d.selectNodeContents(i);else{const e=i.childNodes[0];d.setStartAfter(e),d.setEndAfter(e),d.collapse(!0)}c.removeAllRanges(),c.addRange(d)}onInput(){this.editTarget.text=this.editDom.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:e,textScale:t}=this,{style:n}=this.editDom,{x:i,y:s}=e.app.tree.clientBounds,{a:r,b:a,c:l,d:c,e:d,f:h}=new o(e.worldTransform).scale(1/t);n.transform=`matrix(${r},${a},${l},${c},${d},${h})`,n.left=i-window.scrollX+"px",n.top=s-window.scrollY+"px",n.width=e.width*t+(e.__.__autoWidth?20:0)+"px",n.height=e.height*t+(e.__.__autoHeight?20:0)+"px",p(this.editDom,e,this.textScale)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,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)}};h=function(e,t,n,o){var i,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}([i()],h);export{h as TextEditor};
|
package/dist/text-editor.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.textEditor=function(t,
|
|
1
|
+
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.textEditor=function(e,t,n){"use strict";"function"==typeof SuppressedError&&SuppressedError;const o={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},i={top:"flex-start",middle:"center",bottom:"flex-end"},s=t.inviteCode;function r(e,n,s){const{style:r}=e,{fill:a,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=n;r.fontFamily=n.fontFamily,r.fontSize=n.fontSize*s+"px",function(e,n){let o="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":o=t.ColorConvert.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const e=n.stops[0];o=t.ColorConvert.string("string"==typeof e?e:e.color);break;default:void 0!==n.r&&(o=t.ColorConvert.string(n))}else o=n;e.color=o}(r,a),r.fontStyle=n.italic?"italic":"normal",r.fontWeight=n.fontWeight,r.textDecoration="delete"===p?"line-through":p,r.textTransform=o[n.textCase],r.textAlign=n.textAlign,r.display="flex",r.flexDirection="column",r.justifyContent=i[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((e=>e*s+"px")).join(" "):(l||0)*s+"px",r.textOverflow="show"===d?"":"hide"===d?"clip":d}function a(e){return e.length>6&&"e"===e[6]}let l=r;return setTimeout((function(){Object.values(s).some(a)||(l=()=>r)})),e.TextEditor=class extends n.InnerEditor{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:e}=this,{config:n}=e.app;this._keyEvent=n.keyEvent,n.keyEvent=!1;const o=this.editTarget;o.visible=!1;const i=this.editDom=document.createElement("div"),{style:s}=i;i.contentEditable="true",i.innerText=o.text,s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box";const{scaleX:r,scaleY:a}=o.worldTransform;this.textScale=Math.max(Math.abs(r),Math.abs(a));const l=o.fontSize*this.textScale;l<12&&(this.textScale*=12/l),e.app.view.appendChild(i),this.eventIds=[e.app.on_(t.PointerEvent.DOWN,(t=>{t.origin.target!==i&&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),i.addEventListener("focus",this.onFocus),i.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const c=window.getSelection(),d=document.createRange();if(this.config.selectAll)d.selectNodeContents(i);else{const e=i.childNodes[0];d.setStartAfter(e),d.setEndAfter(e),d.collapse(!0)}c.removeAllRanges(),c.addRange(d)}onInput(){this.editTarget.text=this.editDom.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:e,textScale:n}=this,{style:o}=this.editDom,{x:i,y:s}=e.app.tree.clientBounds,{a:r,b:a,c:c,d:d,e:p,f:h}=new t.Matrix(e.worldTransform).scale(1/n);o.transform=`matrix(${r},${a},${c},${d},${p},${h})`,o.left=i-window.scrollX+"px",o.top=s-window.scrollY+"px",o.width=e.width*n+(e.__.__autoWidth?20:0)+"px",o.height=e.height*n+(e.__.__autoHeight?20:0)+"px",l(this.editDom,e,this.textScale)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,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)}},e.TextEditor=function(e,t,n,o){var i,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}([n.registerInnerEditor()],e.TextEditor),e}({},LeaferUI,LeaferIN.editor);
|
package/dist/text-editor.min.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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"},o={top:"flex-start",middle:"center",bottom:"flex-end"},i=e.inviteCode;function s(t,i,s){const{style:r}=t,{fill:a,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=i;r.fontFamily=i.fontFamily,r.fontSize=i.fontSize*s+"px",function(t,n){let o="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":o=e.ColorConvert.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const t=n.stops[0];o=e.ColorConvert.string("string"==typeof t?t:t.color);break;default:void 0!==n.r&&(o=e.ColorConvert.string(n))}else o=n;t.color=o}(r,a),r.fontStyle=i.italic?"italic":"normal",r.fontWeight=i.fontWeight,r.textDecoration="delete"===p?"line-through":p,r.textTransform=n[i.textCase],r.textAlign=i.textAlign,r.display="flex",r.flexDirection="column",r.justifyContent=o[i.verticalAlign],r.lineHeight=(i.__.__lineHeight||0)*s+"px",r.letterSpacing=(i.__.__letterSpacing||0)*s+"px","none"===c?r.whiteSpace="nowrap":"break"===c&&(r.wordBreak="break-all"),r.textIndent=(i.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}function r(e){return e.length>6&&"e"===e[6]}let a=s;setTimeout((function(){Object.values(i).some(r)||(a=()=>s)})),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;this._keyEvent=n.keyEvent,n.keyEvent=!1;const o=this.editTarget;o.visible=!1;const i=this.editDom=document.createElement("div"),{style:s}=i;i.contentEditable="true",i.innerText=o.text,s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box";const{scaleX:r,scaleY:a}=o.worldTransform;this.textScale=Math.max(Math.abs(r),Math.abs(a));const l=o.fontSize*this.textScale;l<12&&(this.textScale*=12/l),t.app.view.appendChild(i),this.eventIds=[t.app.on_(e.PointerEvent.DOWN,(e=>{e.origin.target!==i&&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),i.addEventListener("focus",this.onFocus),i.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const c=window.getSelection(),d=document.createRange();if(this.config.selectAll)d.selectNodeContents(i);else{const e=i.childNodes[0];d.setStartAfter(e),d.setEndAfter(e),d.collapse(!0)}c.removeAllRanges(),c.addRange(d)}onInput(){this.editTarget.text=this.editDom.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:t,textScale:n}=this,{style:o}=this.editDom,{x:i,y:s}=t.app.tree.clientBounds,{a:r,b:l,c:c,d:d,e:p,f:h}=new e.Matrix(t.worldTransform).scale(1/n);o.transform=`matrix(${r},${l},${c},${d},${p},${h})`,o.left=i-window.scrollX+"px",o.top=s-window.scrollY+"px",o.width=t.width*n+(t.__.__autoWidth?20:0)+"px",o.height=t.height*n+(t.__.__autoHeight?20:0)+"px",a(this.editDom,t,this.textScale)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,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,o){var i,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(r=(s<3?i(r):s>3?i(t,n,r):i(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,
|
|
1
|
+
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.textEditor=function(e,t,n){"use strict";"function"==typeof SuppressedError&&SuppressedError;const o={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},i={top:"flex-start",middle:"center",bottom:"flex-end"},s=t.inviteCode;function r(e,n,s){const{style:r}=e,{fill:a,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=n;r.fontFamily=n.fontFamily,r.fontSize=n.fontSize*s+"px",function(e,n){let o="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":o=t.ColorConvert.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const e=n.stops[0];o=t.ColorConvert.string("string"==typeof e?e:e.color);break;default:void 0!==n.r&&(o=t.ColorConvert.string(n))}else o=n;e.color=o}(r,a),r.fontStyle=n.italic?"italic":"normal",r.fontWeight=n.fontWeight,r.textDecoration="delete"===p?"line-through":p,r.textTransform=o[n.textCase],r.textAlign=n.textAlign,r.display="flex",r.flexDirection="column",r.justifyContent=i[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((e=>e*s+"px")).join(" "):(l||0)*s+"px",r.textOverflow="show"===d?"":"hide"===d?"clip":d}function a(e){return e.length>6&&"e"===e[6]}let l=r;return setTimeout((function(){Object.values(s).some(a)||(l=()=>r)})),e.TextEditor=class extends n.InnerEditor{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:e}=this,{config:n}=e.app;this._keyEvent=n.keyEvent,n.keyEvent=!1;const o=this.editTarget;o.visible=!1;const i=this.editDom=document.createElement("div"),{style:s}=i;i.contentEditable="true",i.innerText=o.text,s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box";const{scaleX:r,scaleY:a}=o.worldTransform;this.textScale=Math.max(Math.abs(r),Math.abs(a));const l=o.fontSize*this.textScale;l<12&&(this.textScale*=12/l),e.app.view.appendChild(i),this.eventIds=[e.app.on_(t.PointerEvent.DOWN,(t=>{t.origin.target!==i&&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),i.addEventListener("focus",this.onFocus),i.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const c=window.getSelection(),d=document.createRange();if(this.config.selectAll)d.selectNodeContents(i);else{const e=i.childNodes[0];d.setStartAfter(e),d.setEndAfter(e),d.collapse(!0)}c.removeAllRanges(),c.addRange(d)}onInput(){this.editTarget.text=this.editDom.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:e,textScale:n}=this,{style:o}=this.editDom,{x:i,y:s}=e.app.tree.clientBounds,{a:r,b:a,c:c,d:d,e:p,f:h}=new t.Matrix(e.worldTransform).scale(1/n);o.transform=`matrix(${r},${a},${c},${d},${p},${h})`,o.left=i-window.scrollX+"px",o.top=s-window.scrollY+"px",o.width=e.width*n+(e.__.__autoWidth?20:0)+"px",o.height=e.height*n+(e.__.__autoHeight?20:0)+"px",l(this.editDom,e,this.textScale)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,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)}},e.TextEditor=function(e,t,n,o){var i,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}([n.registerInnerEditor()],e.TextEditor),e}({},LeaferUI,LeaferIN.editor);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/text-editor",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.26",
|
|
4
4
|
"description": "@leafer-in/text-editor",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"leaferjs"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@leafer-ui/core": "1.0.0-rc.
|
|
28
|
-
"@leafer-in/editor": "1.0.0-rc.
|
|
29
|
-
"@leafer-ui/interface": "1.0.0-rc.
|
|
30
|
-
"@leafer-in/interface": "1.0.0-rc.
|
|
27
|
+
"@leafer-ui/core": "1.0.0-rc.26",
|
|
28
|
+
"@leafer-in/editor": "1.0.0-rc.26",
|
|
29
|
+
"@leafer-ui/interface": "1.0.0-rc.26",
|
|
30
|
+
"@leafer-in/interface": "1.0.0-rc.26"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -3,13 +3,18 @@ import { InnerEditor } from '@leafer-in/editor';
|
|
|
3
3
|
|
|
4
4
|
declare class TextEditor extends InnerEditor {
|
|
5
5
|
get tag(): string;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
editTarget: IText;
|
|
7
|
+
editDom: HTMLDivElement;
|
|
8
8
|
textScale: number;
|
|
9
|
+
config: {
|
|
10
|
+
selectAll: boolean;
|
|
11
|
+
};
|
|
9
12
|
eventIds: IEventListenerId[];
|
|
13
|
+
protected _keyEvent: boolean;
|
|
10
14
|
onLoad(): void;
|
|
11
15
|
protected onInput(): void;
|
|
12
16
|
protected onFocus(): void;
|
|
17
|
+
protected onEscape(e: KeyboardEvent): void;
|
|
13
18
|
onUpdate(): void;
|
|
14
19
|
onUnload(): void;
|
|
15
20
|
}
|