@chenyomi/leafer-htmltext-editor 1.0.0 → 1.0.1

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.
@@ -7,21 +7,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { PointerEvent } from 'leafer-ui';
11
- import { EditTool, registerEditTool, EditorScaleEvent } from '@leafer-in/editor';
12
- import { updataHtmlText } from '../utils';
13
- import { TextEditor } from '../TextEditor';
14
- function debounce(func, wait) {
15
- let timeout = null;
16
- return function (...args) {
17
- if (timeout)
18
- clearTimeout(timeout);
19
- timeout = setTimeout(() => func.apply(this, args), wait);
20
- };
21
- }
10
+ import { EditTool, EditorScaleEvent, registerEditTool, } from "@leafer-in/editor";
11
+ import { PointerEvent } from "leafer-ui";
12
+ import { quillManager } from "../index";
13
+ import { updataHtmlText } from "../utils";
22
14
  let TextEditTool = class TextEditTool extends EditTool {
23
15
  get tag() {
24
- return 'TextEditTool';
16
+ return "TextEditTool";
25
17
  }
26
18
  constructor(editor) {
27
19
  super(editor);
@@ -30,101 +22,83 @@ let TextEditTool = class TextEditTool extends EditTool {
30
22
  this.isUpdatingPoints = false;
31
23
  this.curveAmount = 0;
32
24
  this.eventIds = [];
33
- this.updateBoxDebounced = debounce((text) => {
25
+ this.updateBoxDebounced = this.debounce((text) => {
34
26
  updataHtmlText(text);
35
27
  }, 300);
36
28
  }
29
+ debounce(func, wait) {
30
+ let timeout = null;
31
+ return ((...args) => {
32
+ if (timeout !== null) {
33
+ window.clearTimeout(timeout);
34
+ }
35
+ timeout = window.setTimeout(() => func.apply(this, args), wait);
36
+ });
37
+ }
37
38
  addEvent() {
38
- if (!this.editor?.element)
39
- return;
40
- const text = this.editor.element.findOne('HTMLText');
41
- if (!text)
42
- return;
39
+ const { editor } = quillManager.getCanvas();
40
+ const text = editor._target.findOne("HTMLText");
43
41
  const { scaleX, scaleY } = text.worldTransform;
44
42
  const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
45
- const div = document.querySelector('#textInnerEditor');
46
- if (!div)
47
- return;
43
+ const div = document.querySelector("#textInnerEditor");
48
44
  const { style } = div;
49
45
  this.eventIds = [
50
- this.editor.on_(EditorScaleEvent.SCALE, (e) => {
51
- if (!text.data)
52
- text.data = {};
46
+ editor.on_(EditorScaleEvent.SCALE, (e) => {
53
47
  if (!text.data.canChangeBox) {
54
48
  text.data.canChangeBox = true;
55
49
  }
56
- if (text.data.canChangeBox && text.parent) {
57
- const parentWidth = text.parent.width;
58
- if (parentWidth !== undefined) {
59
- style.width = parentWidth * zoomScale + 'px';
60
- style.height = 'auto';
61
- }
50
+ if (text.data.canChangeBox) {
51
+ style.width = text.parent.width * zoomScale + "px";
52
+ style.height = "auto";
62
53
  }
63
54
  this.updateBoxDebounced(text);
64
55
  }),
65
- this.editor.on_(PointerEvent.DOUBLE_TAP, () => {
66
- if (!text.parent?.locked) {
67
- this.editor.openInnerEditor(text, true);
56
+ editor.on_(PointerEvent.DOUBLE_TAP, () => {
57
+ if (!text.parent.locked) {
58
+ editor.openInnerEditor(text, true);
68
59
  }
69
- })
60
+ }),
70
61
  ];
71
62
  }
72
63
  onLoad() {
73
- if (!this.editor?.element)
74
- return;
75
- const text = this.editor.element.findOne('HTMLText');
76
- if (!text)
77
- return;
64
+ const { editor } = quillManager.getCanvas();
65
+ const text = editor._target.findOne("HTMLText");
78
66
  const { scaleX, scaleY } = text.worldTransform;
79
67
  const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
80
68
  this.addEvent();
81
- this.editBox.add(this.view);
82
- this.quill = TextEditor.quill;
83
- if (this.quill && text.text) {
84
- this.quill.clipboard.dangerouslyPasteHTML(text.text);
85
- }
86
- const div = document.querySelector('#textInnerEditor');
87
- if (!div)
88
- return;
69
+ this.quill = quillManager.getQuill();
70
+ this.quill.clipboard.dangerouslyPasteHTML(text.text);
71
+ const div = document.querySelector("#textInnerEditor");
89
72
  const { style } = div;
90
- if (text.data?.canChangeBox && text.parent) {
91
- const parentWidth = text.parent.width;
92
- const parentHeight = text.parent.height;
93
- if (parentWidth !== undefined) {
94
- style.width = parentWidth * zoomScale + 'px';
95
- }
96
- if (parentHeight !== undefined) {
97
- style.height = parentHeight * zoomScale + 'px';
98
- }
73
+ if (text.data.canChangeBox) {
74
+ style.width = text.parent.width * zoomScale + "px";
75
+ style.height = text.parent.height * zoomScale + "px";
99
76
  }
100
77
  else {
101
- style.width = 'auto';
102
- style.height = 'auto';
78
+ style.width = "auto";
79
+ style.height = "auto";
103
80
  }
104
81
  }
105
82
  updateChangeBoxBound(text) {
106
- if (text && text.__layout?.boxBounds) {
83
+ text &&
107
84
  text.set({
108
85
  width: text.__layout.boxBounds.width,
109
- height: text.__layout.boxBounds.height
86
+ height: text.__layout.boxBounds.height,
110
87
  });
111
- }
112
88
  }
113
89
  onUpdate() {
114
- if (!this.editor?.element)
115
- return;
116
- const text = this.editor.element.findOne('HTMLText');
117
- if (!text)
118
- return;
119
- const el = this.editor.element;
120
- console.log('文本bound更新');
121
- if (this.curveAmount === text.curveAmount)
90
+ const { editor } = quillManager.getCanvas();
91
+ const text = editor._target.findOne("HTMLText");
92
+ const el = editor._target;
93
+ console.log("文本bound更新");
94
+ if (this.curveAmount == text.curveAmount)
122
95
  return;
123
96
  if (this.isUpdatingPoints)
124
97
  return;
125
98
  }
126
99
  onUnload() {
127
- this.editor.off_(this.eventIds);
100
+ const { editor } = quillManager.getCanvas();
101
+ editor.off_(this.eventIds);
128
102
  }
129
103
  onDestroy() { }
130
104
  };
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/TextEditTool/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAM1E;AAED,eAAO,MAAM,eAAe,GAAI,SAAS,GAAG,EAAE,IAAI,OAAO,SAsExD,CAAA;AAmFD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMnD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMjD;AAGD,eAAO,MAAM,iBAAiB,UAAgC,CAAA;AAE9D,eAAO,MAAM,eAAe,UAA8B,CAAA;AA0B1D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM9C"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/TextEditTool/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAM1E;AAED,eAAO,MAAM,eAAe,GAAI,SAAS,GAAG,EAAE,IAAI,OAAO,SAsExD,CAAA;AAgKD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMnD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMjD;AAED,eAAO,MAAM,iBAAiB,UAAgC,CAAA;AAE9D,eAAO,MAAM,eAAe,UAA8B,CAAA;AAuB1D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM9C"}
@@ -1,5 +1,5 @@
1
- import { Box, Path } from 'leafer-ui';
2
1
  import { HTMLText } from '@leafer-in/html';
2
+ import { Box, Path } from 'leafer-ui';
3
3
  export function getArcRadius(fontSize, curveAmount) {
4
4
  if (curveAmount === 0)
5
5
  return Infinity;
@@ -75,20 +75,103 @@ export const handleShowCurve = (element, op) => {
75
75
  element.add(group);
76
76
  };
77
77
  const baseSuperscript = {
78
- '0': '⁰', '1': '¹', '2': '²', '3': '³', '4': '⁴', '5': '⁵', '6': '⁶', '7': '⁷', '8': '⁸', '9': '⁹',
79
- a: '', b: '', c: 'ᶜ', d: 'ᵈ', e: 'ᵉ', f: 'ᶠ', g: 'ᵍ', h: 'ʰ', i: 'ⁱ', j: 'ʲ', k: 'ᵏ',
80
- l: 'ˡ', m: '', n: 'ⁿ', o: 'ᵒ', p: 'ᵖ', r: 'ʳ', s: 'ˢ', t: 'ᵗ', u: 'ᵘ', v: 'ᵛ', w: 'ʷ',
81
- x: 'ˣ', y: 'ʸ', z: 'ᶻ',
82
- A: '', B: '', D: 'ᴰ', E: 'ᴱ', G: 'ᴳ', H: 'ᴴ', I: 'ᴵ', J: 'ᴶ', K: 'ᴷ', L: 'ᴸ', M: 'ᴹ',
83
- N: '', O: '', P: 'ᴾ', R: 'ᴿ', T: 'ᵀ', U: 'ᵁ', W: 'ᵂ',
84
- '+': '', '-': '⁻', '=': '⁼', '(': '⁽', ')': '⁾'
78
+ '0': '⁰',
79
+ '1': '¹',
80
+ '2': '²',
81
+ '3': '³',
82
+ '4': '',
83
+ '5': '',
84
+ '6': '',
85
+ '7': '⁷',
86
+ '8': '⁸',
87
+ '9': '⁹',
88
+ a: 'ᵃ',
89
+ b: 'ᵇ',
90
+ c: 'ᶜ',
91
+ d: 'ᵈ',
92
+ e: 'ᵉ',
93
+ f: 'ᶠ',
94
+ g: 'ᵍ',
95
+ h: 'ʰ',
96
+ i: 'ⁱ',
97
+ j: 'ʲ',
98
+ k: 'ᵏ',
99
+ l: 'ˡ',
100
+ m: 'ᵐ',
101
+ n: 'ⁿ',
102
+ o: 'ᵒ',
103
+ p: 'ᵖ',
104
+ r: 'ʳ',
105
+ s: 'ˢ',
106
+ t: 'ᵗ',
107
+ u: 'ᵘ',
108
+ v: 'ᵛ',
109
+ w: 'ʷ',
110
+ x: 'ˣ',
111
+ y: 'ʸ',
112
+ z: 'ᶻ',
113
+ A: 'ᴬ',
114
+ B: 'ᴮ',
115
+ D: 'ᴰ',
116
+ E: 'ᴱ',
117
+ G: 'ᴳ',
118
+ H: 'ᴴ',
119
+ I: 'ᴵ',
120
+ J: 'ᴶ',
121
+ K: 'ᴷ',
122
+ L: 'ᴸ',
123
+ M: 'ᴹ',
124
+ N: 'ᴺ',
125
+ O: 'ᴼ',
126
+ P: 'ᴾ',
127
+ R: 'ᴿ',
128
+ T: 'ᵀ',
129
+ U: 'ᵁ',
130
+ W: 'ᵂ',
131
+ '+': '⁺',
132
+ '-': '⁻',
133
+ '=': '⁼',
134
+ '(': '⁽',
135
+ ')': '⁾'
85
136
  };
86
137
  const baseSubscript = {
87
- '0': '₀', '1': '₁', '2': '₂', '3': '₃', '4': '₄', '5': '₅', '6': '₆', '7': '₇', '8': '₈', '9': '₉',
88
- a: '', e: '', h: 'ₕ', i: 'ᵢ', j: 'ⱼ', k: 'ₖ', l: 'ₗ', m: 'ₘ', n: 'ₙ', o: 'ₒ', p: 'ₚ',
89
- r: '', s: '', t: 'ₜ', u: 'ᵤ', v: 'ᵥ', x: 'ₓ',
90
- '+': '', '-': '₋', '=': '₌', '(': '₍', ')': '₎',
91
- 'β': '', 'γ': 'ᵧ', 'ρ': 'ᵨ', 'φ': 'ᵩ', 'χ': 'ᵪ'
138
+ '0': '₀',
139
+ '1': '',
140
+ '2': '',
141
+ '3': '',
142
+ '4': '',
143
+ '5': '₅',
144
+ '6': '₆',
145
+ '7': '₇',
146
+ '8': '₈',
147
+ '9': '₉',
148
+ a: 'ₐ',
149
+ e: 'ₑ',
150
+ h: 'ₕ',
151
+ i: 'ᵢ',
152
+ j: 'ⱼ',
153
+ k: 'ₖ',
154
+ l: 'ₗ',
155
+ m: 'ₘ',
156
+ n: 'ₙ',
157
+ o: 'ₒ',
158
+ p: 'ₚ',
159
+ r: 'ᵣ',
160
+ s: 'ₛ',
161
+ t: 'ₜ',
162
+ u: 'ᵤ',
163
+ v: 'ᵥ',
164
+ x: 'ₓ',
165
+ '+': '₊',
166
+ '-': '₋',
167
+ '=': '₌',
168
+ '(': '₍',
169
+ ')': '₎',
170
+ β: 'ᵦ',
171
+ γ: 'ᵧ',
172
+ ρ: 'ᵨ',
173
+ φ: 'ᵩ',
174
+ χ: 'ᵪ'
92
175
  };
93
176
  function invertMap(map) {
94
177
  const inv = {};
@@ -1,15 +1,12 @@
1
- import { IText, IEventListenerId } from "@leafer-in/interface";
2
1
  import { InnerEditor } from "@leafer-in/editor";
3
2
  export declare class TextEditor extends InnerEditor {
4
- static quill: any;
5
3
  get tag(): string;
6
- quill: any;
7
- editTarget: IText;
8
- editDom: HTMLDivElement | undefined;
4
+ editTarget: any;
5
+ editDom: any;
9
6
  config: {
10
7
  selectAll: boolean;
11
8
  };
12
- eventIds: IEventListenerId[];
9
+ eventIds: any[];
13
10
  protected selectText: {
14
11
  start: number;
15
12
  end: number;
@@ -17,6 +14,12 @@ export declare class TextEditor extends InnerEditor {
17
14
  } | undefined;
18
15
  protected inBody: boolean | undefined;
19
16
  protected isHTMLText: boolean | undefined;
17
+ protected _keyEvent: boolean | undefined;
18
+ quill: any;
19
+ isComposing: boolean;
20
+ private misspelledWords;
21
+ private overlay;
22
+ private get isOASystem();
20
23
  onLoad(): void;
21
24
  private onSelectionChange;
22
25
  private onInput;
@@ -1 +1 @@
1
- {"version":3,"file":"TextEditor.d.ts","sourceRoot":"","sources":["../../src/TextEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAuB,MAAM,mBAAmB,CAAC;AAMrE,qBACa,UAAW,SAAQ,WAAW;IACzC,OAAc,KAAK,EAAE,GAAG,CAAC;IAEzB,IAAW,GAAG,WAEb;IAEM,KAAK,EAAE,GAAG,CAAC;IACH,UAAU,EAAE,KAAK,CAAC;IAE1B,OAAO,EAAE,cAAc,GAAG,SAAS,CAAC;IACpC,MAAM;;MAEX;IAEK,QAAQ,EAAE,gBAAgB,EAAE,CAAM;IAEzC,SAAS,CAAC,UAAU,EAChB;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC5C,SAAS,CAAC;IACd,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,SAAS,CAAC,UAAU,EAAE,OAAO,GAAG,SAAS,CAAC;IAEnC,MAAM,IAAI,IAAI;IAoGrB,OAAO,CAAC,iBAAiB,CAEvB;IAEF,OAAO,CAAC,OAAO,CAGb;IAEK,QAAQ;IAkCf,OAAO,CAAC,gBAAgB,CAAS;IAE1B,QAAQ,IAAI,IAAI;CAsBxB"}
1
+ {"version":3,"file":"TextEditor.d.ts","sourceRoot":"","sources":["../../src/TextEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAuB,MAAM,mBAAmB,CAAC;AAKrE,qBACa,UAAW,SAAQ,WAAW;IACzC,IAAW,GAAG,WAEb;IACc,UAAU,EAAE,GAAG,CAAC;IAExB,OAAO,EAAE,GAAG,CAAC;IACb,MAAM;;MAEX;IAEK,QAAQ,EAAE,GAAG,EAAE,CAAM;IAE5B,SAAS,CAAC,UAAU,EAChB;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC5C,SAAS,CAAa;IAC1B,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAa;IAClD,SAAS,CAAC,UAAU,EAAE,OAAO,GAAG,SAAS,CAAa;IACtD,SAAS,CAAC,SAAS,EAAE,OAAO,GAAG,SAAS,CAAa;IAC9C,KAAK,EAAE,GAAG,CAAQ;IAClB,WAAW,EAAE,OAAO,CAAS;IAGpC,OAAO,CAAC,eAAe,CAIf;IACR,OAAO,CAAC,OAAO,CAA+B;IAG9C,OAAO,KAAK,UAAU,GAErB;IACM,MAAM,IAAI,IAAI;IA2FrB,OAAO,CAAC,iBAAiB,CAEvB;IAEF,OAAO,CAAC,OAAO,CAUb;IAEK,QAAQ;IA0Bf,OAAO,CAAC,gBAAgB,CAAS;IAC1B,QAAQ,IAAI,IAAI;CAsCxB"}
@@ -4,21 +4,31 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- var TextEditor_1;
8
- import { Matrix, PointerEvent } from "@leafer-ui/core";
9
7
  import { InnerEditor, registerInnerEditor } from "@leafer-in/editor";
8
+ import { Matrix, PointerEvent } from "@leafer-ui/core";
9
+ import { quillManager } from ".";
10
10
  import { updataHtmlText } from "./utils";
11
- let TextEditor = TextEditor_1 = class TextEditor extends InnerEditor {
11
+ let TextEditor = class TextEditor extends InnerEditor {
12
12
  constructor() {
13
13
  super(...arguments);
14
14
  this.config = {
15
15
  selectAll: false,
16
16
  };
17
17
  this.eventIds = [];
18
+ this.selectText = undefined;
19
+ this.inBody = undefined;
20
+ this.isHTMLText = undefined;
21
+ this._keyEvent = undefined;
22
+ this.quill = null;
23
+ this.isComposing = false;
24
+ this.misspelledWords = [];
25
+ this.overlay = null;
18
26
  this.onSelectionChange = async (e) => {
19
27
  e && localStorage.setItem("selection-change", JSON.stringify(e));
20
28
  };
21
29
  this.onInput = async () => {
30
+ const { editDom } = this;
31
+ console.log("onInput");
22
32
  updataHtmlText(this.editTarget);
23
33
  };
24
34
  this.isUpdatingPoints = false;
@@ -26,26 +36,22 @@ let TextEditor = TextEditor_1 = class TextEditor extends InnerEditor {
26
36
  get tag() {
27
37
  return "TextEditor";
28
38
  }
39
+ get isOASystem() {
40
+ return window.location.host.includes("oa");
41
+ }
29
42
  onLoad() {
30
43
  const { editor } = this;
31
44
  const { config } = editor.app;
32
45
  const text = this.editTarget;
33
46
  const { scaleX, scaleY } = text.worldTransform;
34
47
  const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
35
- this.quill = TextEditor_1.quill;
36
48
  this.isHTMLText = !(text instanceof Text);
49
+ this._keyEvent = config.keyEvent;
37
50
  config.keyEvent = false;
38
- const element = document.querySelector("#textInnerEditor");
39
- if (!element || !(element instanceof HTMLDivElement)) {
40
- console.error("Cannot find #textInnerEditor element or it's not a div");
41
- return;
42
- }
43
- const div = (this.editDom = element);
51
+ const div = (this.editDom = document.querySelector("#textInnerEditor"));
44
52
  const { style } = div;
45
53
  style.visibility = "visible";
46
- if (text.data?.canChangeBox &&
47
- text.parent?.width !== undefined &&
48
- text.parent?.height !== undefined) {
54
+ if (text.data.canChangeBox) {
49
55
  style.width = text.parent.width * zoomScale + "px";
50
56
  style.height = text.parent.height * zoomScale + "px";
51
57
  }
@@ -54,51 +60,44 @@ let TextEditor = TextEditor_1 = class TextEditor extends InnerEditor {
54
60
  style.height = "auto";
55
61
  }
56
62
  style.outline = "solid #8499EF";
57
- if (text.data?.textData?.fontSize) {
63
+ if (text.data.textData.fontSize) {
58
64
  div.style.fontSize = `${text.data.textData.fontSize * zoomScale}px`;
59
65
  }
60
- if (text.data?.textData?.fontFamily) {
66
+ if (text.data.textData.fontFamily) {
61
67
  div.style.fontFamily = `${text.data.textData.fontFamily}`;
62
68
  }
63
- if (text.data?.textData?.lineHeight) {
69
+ if (text.data.textData.lineHeight) {
64
70
  div.style.lineHeight = text.data.textData.lineHeight;
65
71
  }
66
- if (text.data?.textData?.letterSpacing) {
72
+ if (text.data.textData.letterSpacing) {
67
73
  div.style.letterSpacing = `${text.data.textData.letterSpacing}px`;
68
74
  }
69
- if (text.data?.textData?.textShadow) {
75
+ if (text.data.textData.textShadow) {
70
76
  div.style.textShadow = `${text.data.textData.textShadow}`;
71
77
  }
72
78
  else {
73
79
  div.style.textShadow = "none";
74
80
  }
75
- if (text.data?.textData?.alignContent) {
81
+ if (text.data.textData.alignContent) {
76
82
  const qlEditor = div.querySelector(".ql-editor");
77
- if (qlEditor) {
78
- qlEditor.style.alignContent = `${text.data.textData.alignContent}`;
79
- }
83
+ qlEditor.style.alignContent = `${text.data.textData.alignContent}`;
80
84
  }
81
- if (this.quill) {
82
- this.quill.clipboard.dangerouslyPasteHTML(text.text);
83
- if (text.parent?.children?.[0]?.tag?.includes("Shape")) {
84
- const parentWidth = text.parent.width;
85
- if (parentWidth !== undefined) {
86
- style.width = parentWidth * zoomScale + "px";
87
- style.left = "0px";
88
- }
89
- this.quill.formatLine(0, this.quill.getLength(), "align", "center");
90
- }
91
- else {
92
- this.quill.setSelection(0, this.quill.getLength() - 1);
93
- }
94
- this.quill.on("text-change", this.onInput);
95
- this.quill.on("selection-change", this.onSelectionChange);
85
+ this.quill = quillManager.getQuill();
86
+ this.quill.clipboard.dangerouslyPasteHTML(text.text);
87
+ if (text.parent.children[0].tag.includes("Shape")) {
88
+ style.width = text.parent.width * zoomScale + "px";
89
+ style.left = "0px";
90
+ this.quill.formatLine(0, this.quill.getLength(), "align", "center");
91
+ }
92
+ else {
93
+ this.quill.setSelection(0, this.quill.getLength() - 1);
96
94
  }
95
+ this.quill.on("text-change", this.onInput);
96
+ this.quill.on("selection-change", this.onSelectionChange);
97
97
  localStorage.removeItem("selection-change");
98
98
  this.eventIds = [
99
99
  editor.app.on_(PointerEvent.DOWN, (e) => {
100
- let { target } = e.origin;
101
- let find = false;
100
+ let { target } = e.origin, find = false;
102
101
  while (target) {
103
102
  if (target === div)
104
103
  find = true;
@@ -113,27 +112,20 @@ let TextEditor = TextEditor_1 = class TextEditor extends InnerEditor {
113
112
  }
114
113
  onUpdate() {
115
114
  const { editTarget: text } = this;
116
- if (!text.parent?.__local)
117
- return;
118
115
  const { scaleX, scaleY } = text.worldTransform;
119
116
  const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
120
- const local = text.parent.__local;
121
- let width = local.width || 0;
122
- let height = local.height || 0;
123
- width *= zoomScale;
124
- height *= zoomScale;
117
+ let { width, height } = text.parent.__local;
118
+ ((width *= zoomScale), (height *= zoomScale));
125
119
  const { x, y } = this.inBody
126
120
  ? text.app.clientBounds
127
- : (text.app.tree?.clientBounds || { x: 0, y: 0 });
121
+ : text.app.tree.clientBounds;
128
122
  const { a, b, c, d, e, f } = new Matrix(text.worldTransform)
129
123
  .scale(1 / zoomScale)
130
124
  .translateInner(0, 0);
131
- if (this.editDom) {
132
- const { style } = this.editDom;
133
- style.transform = `matrix(${a},${b},${c},${d},${e},${f})`;
134
- style.left = x + "px";
135
- style.top = y + "px";
136
- }
125
+ const { style } = this.editDom;
126
+ style.transform = `matrix(${a},${b},${c},${d},${e},${f})`;
127
+ style.left = x + "px";
128
+ style.top = y + "px";
137
129
  text.set({
138
130
  visible: false,
139
131
  });
@@ -142,22 +134,32 @@ let TextEditor = TextEditor_1 = class TextEditor extends InnerEditor {
142
134
  const { editTarget: text, editor, editDom: dom } = this;
143
135
  if (text) {
144
136
  this.onInput();
137
+ if (editor.app)
138
+ editor.app.config.keyEvent = this._keyEvent;
145
139
  editor.off_(this.eventIds);
146
- if (this.editDom) {
147
- this.editDom.style.visibility = "hidden";
148
- }
140
+ this.editDom.style.visibility = "hidden";
149
141
  this.eventIds = [];
150
142
  }
151
- text.set({
152
- visible: true,
153
- });
154
- if (this.quill) {
155
- this.quill.off("text-change", this.onInput);
156
- this.quill.off("selection-change", this.onSelectionChange);
143
+ if (text.parent &&
144
+ text.parent.name == "Text" &&
145
+ text.parent.children.some((e) => e.tag === "Box")) {
146
+ text.parent.findOne("Box").opacity = 1;
147
+ text.visible = false;
148
+ }
149
+ else {
150
+ text.set({
151
+ visible: true,
152
+ });
153
+ }
154
+ if (this.quill.getLength() === 1 && text.parent.name === "Text") {
155
+ text.parent.remove();
157
156
  }
157
+ console.log("onUnload");
158
+ this.quill.off("text-change", this.onInput);
159
+ this.quill.off("selection-change", this.onSelectionChange);
158
160
  }
159
161
  };
160
- TextEditor = TextEditor_1 = __decorate([
162
+ TextEditor = __decorate([
161
163
  registerInnerEditor()
162
164
  ], TextEditor);
163
165
  export { TextEditor };
@@ -1,7 +1,18 @@
1
- export { TextEditor } from "./TextEditor";
2
- import "./TextEditTool";
3
- import "quill/dist/quill.core.css";
4
- export { updataHtmlText, setHTMLText } from "./utils";
5
- export { fontManager, defaultFonts, FontManager } from "./fonts/font";
6
- export declare function initTextEditorQuill(container?: HTMLElement): any;
1
+ export { TextEditor } from './TextEditor';
2
+ import './TextEditTool';
3
+ import Quill from 'quill';
4
+ declare class QuillManager {
5
+ private static instance;
6
+ private quill;
7
+ app_: any | null;
8
+ private constructor();
9
+ static getInstance(): QuillManager;
10
+ init(app: any): Quill;
11
+ getQuill(): Quill;
12
+ getCanvas(): any;
13
+ private registerFonts;
14
+ isMultiSelect(): boolean;
15
+ dateEdit(callback: (leaf: any) => void, level?: number, listNew?: any): void;
16
+ }
17
+ export declare const quillManager: QuillManager;
7
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,gBAAgB,CAAC;AAIxB,OAAO,2BAA2B,CAAC;AAGnC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAItE,wBAAgB,mBAAmB,CAAC,SAAS,CAAC,EAAE,WAAW,OA6E1D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,gBAAgB,CAAA;AAGvB,OAAO,KAAgB,MAAM,OAAO,CAAA;AAEpC,cAAM,YAAY;IAChB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAc;IACrC,OAAO,CAAC,KAAK,CAAqB;IAC3B,IAAI,EAAE,GAAG,GAAG,IAAI,CAAO;IAE9B,OAAO;IAEP,MAAM,CAAC,WAAW;IAQlB,IAAI,CAAC,GAAG,EAAE,GAAG;IAgDb,QAAQ;IAOR,SAAS;IAOT,OAAO,CAAC,aAAa;IA+Bd,aAAa,IAAI,OAAO;IAQxB,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,EAAE,KAAK,SAAI,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI;CA4B/E;AAED,eAAO,MAAM,YAAY,cAA6B,CAAA"}
@@ -1,3 +1,3 @@
1
1
  export declare const updataHtmlText: (e?: any, base64font?: any, fontObj?: any) => Promise<void>;
2
- export declare const setHTMLText: (key: string, value?: any, base64font?: any, editor?: any, isInnerEditor?: boolean) => void;
2
+ export declare const setHTMLText: (key: string, value?: any, base64font?: any) => void;
3
3
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,cAAc,GAAU,IAAI,GAAG,EAAE,aAAa,GAAG,EAAE,UAAU,GAAG,kBAuG5E,CAAC;AAqFF,eAAO,MAAM,WAAW,GACtB,KAAK,MAAM,EACX,QAAQ,GAAG,EACX,aAAa,GAAG,EAChB,SAAS,GAAG,EACZ,gBAAgB,OAAO,SAgIxB,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,GAAU,IAAI,GAAG,EAAE,aAAa,GAAG,EAAE,UAAU,GAAG,kBAgG5E,CAAA;AAmED,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,EAAE,QAAQ,GAAG,EAAE,aAAa,GAAG,SA+HrE,CAAA"}