@chenyomi/leafer-htmltext-editor 1.0.0 → 1.0.2

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,124 +7,98 @@ 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 "../";
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);
28
20
  this.quill = null;
29
- this._dragRAF = null;
30
21
  this.isUpdatingPoints = false;
31
22
  this.curveAmount = 0;
32
23
  this.eventIds = [];
33
- this.updateBoxDebounced = debounce((text) => {
24
+ this.updateBoxDebounced = this.debounce((text) => {
34
25
  updataHtmlText(text);
35
26
  }, 300);
36
27
  }
28
+ debounce(func, wait) {
29
+ let timeout = null;
30
+ return ((...args) => {
31
+ if (timeout !== null) {
32
+ window.clearTimeout(timeout);
33
+ }
34
+ timeout = window.setTimeout(() => func.apply(this, args), wait);
35
+ });
36
+ }
37
37
  addEvent() {
38
- if (!this.editor?.element)
39
- return;
40
- const text = this.editor.element.findOne('HTMLText');
41
- if (!text)
42
- return;
38
+ const { editor } = quillManager.getCanvas();
39
+ const text = editor._target.findOne("HTMLText");
43
40
  const { scaleX, scaleY } = text.worldTransform;
44
41
  const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
45
- const div = document.querySelector('#textInnerEditor');
46
- if (!div)
47
- return;
42
+ const div = document.querySelector("#textInnerEditor");
48
43
  const { style } = div;
49
44
  this.eventIds = [
50
- this.editor.on_(EditorScaleEvent.SCALE, (e) => {
51
- if (!text.data)
52
- text.data = {};
45
+ editor.on_(EditorScaleEvent.SCALE, (e) => {
53
46
  if (!text.data.canChangeBox) {
54
47
  text.data.canChangeBox = true;
55
48
  }
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
- }
49
+ if (text.data.canChangeBox) {
50
+ style.width = text.parent.width * zoomScale + "px";
51
+ style.height = "auto";
62
52
  }
63
53
  this.updateBoxDebounced(text);
64
54
  }),
65
- this.editor.on_(PointerEvent.DOUBLE_TAP, () => {
66
- if (!text.parent?.locked) {
67
- this.editor.openInnerEditor(text, true);
55
+ editor.on_(PointerEvent.DOUBLE_TAP, () => {
56
+ if (!text.parent.locked) {
57
+ editor.openInnerEditor(text, true);
68
58
  }
69
- })
59
+ }),
70
60
  ];
71
61
  }
72
62
  onLoad() {
73
- if (!this.editor?.element)
74
- return;
75
- const text = this.editor.element.findOne('HTMLText');
76
- if (!text)
77
- return;
63
+ console.log(22222222);
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;AAMrE,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,32 @@ 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
+ console.log(1111, 'registerInnerEditor');
12
+ let TextEditor = class TextEditor extends InnerEditor {
12
13
  constructor() {
13
14
  super(...arguments);
14
15
  this.config = {
15
16
  selectAll: false,
16
17
  };
17
18
  this.eventIds = [];
19
+ this.selectText = undefined;
20
+ this.inBody = undefined;
21
+ this.isHTMLText = undefined;
22
+ this._keyEvent = undefined;
23
+ this.quill = null;
24
+ this.isComposing = false;
25
+ this.misspelledWords = [];
26
+ this.overlay = null;
18
27
  this.onSelectionChange = async (e) => {
19
28
  e && localStorage.setItem("selection-change", JSON.stringify(e));
20
29
  };
21
30
  this.onInput = async () => {
31
+ const { editDom } = this;
32
+ console.log("onInput");
22
33
  updataHtmlText(this.editTarget);
23
34
  };
24
35
  this.isUpdatingPoints = false;
@@ -26,26 +37,22 @@ let TextEditor = TextEditor_1 = class TextEditor extends InnerEditor {
26
37
  get tag() {
27
38
  return "TextEditor";
28
39
  }
40
+ get isOASystem() {
41
+ return window.location.host.includes("oa");
42
+ }
29
43
  onLoad() {
30
44
  const { editor } = this;
31
45
  const { config } = editor.app;
32
46
  const text = this.editTarget;
33
47
  const { scaleX, scaleY } = text.worldTransform;
34
48
  const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
35
- this.quill = TextEditor_1.quill;
36
49
  this.isHTMLText = !(text instanceof Text);
50
+ this._keyEvent = config.keyEvent;
37
51
  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);
52
+ const div = (this.editDom = document.querySelector("#textInnerEditor"));
44
53
  const { style } = div;
45
54
  style.visibility = "visible";
46
- if (text.data?.canChangeBox &&
47
- text.parent?.width !== undefined &&
48
- text.parent?.height !== undefined) {
55
+ if (text.data.canChangeBox) {
49
56
  style.width = text.parent.width * zoomScale + "px";
50
57
  style.height = text.parent.height * zoomScale + "px";
51
58
  }
@@ -54,51 +61,44 @@ let TextEditor = TextEditor_1 = class TextEditor extends InnerEditor {
54
61
  style.height = "auto";
55
62
  }
56
63
  style.outline = "solid #8499EF";
57
- if (text.data?.textData?.fontSize) {
64
+ if (text.data.textData.fontSize) {
58
65
  div.style.fontSize = `${text.data.textData.fontSize * zoomScale}px`;
59
66
  }
60
- if (text.data?.textData?.fontFamily) {
67
+ if (text.data.textData.fontFamily) {
61
68
  div.style.fontFamily = `${text.data.textData.fontFamily}`;
62
69
  }
63
- if (text.data?.textData?.lineHeight) {
70
+ if (text.data.textData.lineHeight) {
64
71
  div.style.lineHeight = text.data.textData.lineHeight;
65
72
  }
66
- if (text.data?.textData?.letterSpacing) {
73
+ if (text.data.textData.letterSpacing) {
67
74
  div.style.letterSpacing = `${text.data.textData.letterSpacing}px`;
68
75
  }
69
- if (text.data?.textData?.textShadow) {
76
+ if (text.data.textData.textShadow) {
70
77
  div.style.textShadow = `${text.data.textData.textShadow}`;
71
78
  }
72
79
  else {
73
80
  div.style.textShadow = "none";
74
81
  }
75
- if (text.data?.textData?.alignContent) {
82
+ if (text.data.textData.alignContent) {
76
83
  const qlEditor = div.querySelector(".ql-editor");
77
- if (qlEditor) {
78
- qlEditor.style.alignContent = `${text.data.textData.alignContent}`;
79
- }
84
+ qlEditor.style.alignContent = `${text.data.textData.alignContent}`;
80
85
  }
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);
86
+ this.quill = quillManager.getQuill();
87
+ this.quill.clipboard.dangerouslyPasteHTML(text.text);
88
+ if (text.parent.children[0].tag.includes("Shape")) {
89
+ style.width = text.parent.width * zoomScale + "px";
90
+ style.left = "0px";
91
+ this.quill.formatLine(0, this.quill.getLength(), "align", "center");
92
+ }
93
+ else {
94
+ this.quill.setSelection(0, this.quill.getLength() - 1);
96
95
  }
96
+ this.quill.on("text-change", this.onInput);
97
+ this.quill.on("selection-change", this.onSelectionChange);
97
98
  localStorage.removeItem("selection-change");
98
99
  this.eventIds = [
99
100
  editor.app.on_(PointerEvent.DOWN, (e) => {
100
- let { target } = e.origin;
101
- let find = false;
101
+ let { target } = e.origin, find = false;
102
102
  while (target) {
103
103
  if (target === div)
104
104
  find = true;
@@ -113,27 +113,20 @@ let TextEditor = TextEditor_1 = class TextEditor extends InnerEditor {
113
113
  }
114
114
  onUpdate() {
115
115
  const { editTarget: text } = this;
116
- if (!text.parent?.__local)
117
- return;
118
116
  const { scaleX, scaleY } = text.worldTransform;
119
117
  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;
118
+ let { width, height } = text.parent.__local;
119
+ ((width *= zoomScale), (height *= zoomScale));
125
120
  const { x, y } = this.inBody
126
121
  ? text.app.clientBounds
127
- : (text.app.tree?.clientBounds || { x: 0, y: 0 });
122
+ : text.app.tree.clientBounds;
128
123
  const { a, b, c, d, e, f } = new Matrix(text.worldTransform)
129
124
  .scale(1 / zoomScale)
130
125
  .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
- }
126
+ const { style } = this.editDom;
127
+ style.transform = `matrix(${a},${b},${c},${d},${e},${f})`;
128
+ style.left = x + "px";
129
+ style.top = y + "px";
137
130
  text.set({
138
131
  visible: false,
139
132
  });
@@ -142,22 +135,32 @@ let TextEditor = TextEditor_1 = class TextEditor extends InnerEditor {
142
135
  const { editTarget: text, editor, editDom: dom } = this;
143
136
  if (text) {
144
137
  this.onInput();
138
+ if (editor.app)
139
+ editor.app.config.keyEvent = this._keyEvent;
145
140
  editor.off_(this.eventIds);
146
- if (this.editDom) {
147
- this.editDom.style.visibility = "hidden";
148
- }
141
+ this.editDom.style.visibility = "hidden";
149
142
  this.eventIds = [];
150
143
  }
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);
144
+ if (text.parent &&
145
+ text.parent.name == "Text" &&
146
+ text.parent.children.some((e) => e.tag === "Box")) {
147
+ text.parent.findOne("Box").opacity = 1;
148
+ text.visible = false;
149
+ }
150
+ else {
151
+ text.set({
152
+ visible: true,
153
+ });
154
+ }
155
+ if (this.quill.getLength() === 1 && text.parent.name === "Text") {
156
+ text.parent.remove();
157
157
  }
158
+ console.log("onUnload");
159
+ this.quill.off("text-change", this.onInput);
160
+ this.quill.off("selection-change", this.onSelectionChange);
158
161
  }
159
162
  };
160
- TextEditor = TextEditor_1 = __decorate([
163
+ TextEditor = __decorate([
161
164
  registerInnerEditor()
162
165
  ], TextEditor);
163
166
  export { TextEditor };
@@ -1,7 +1,19 @@
1
- export { TextEditor } from "./TextEditor";
1
+ import Quill from "quill";
2
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;
3
+ import './TextEditor';
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): Promise<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;
18
+ export {};
7
19
  //# 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,KAAgB,MAAM,OAAO,CAAC;AACrC,OAAO,gBAAgB,CAAC;AACxB,OAAO,cAAc,CAAA;AACrB,cAAM,YAAY;IAChB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAe;IACtC,OAAO,CAAC,KAAK,CAAsB;IAC5B,IAAI,EAAE,GAAG,GAAG,IAAI,CAAQ;IAE/B,OAAO;IAEP,MAAM,CAAC,WAAW;IAOZ,IAAI,CAAC,GAAG,EAAE,GAAG;IAiDnB,QAAQ;IAOR,SAAS;IAOT,OAAO,CAAC,aAAa;IA+Bd,aAAa,IAAI,OAAO;IAQxB,QAAQ,CACb,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,EAC7B,KAAK,SAAI,EACT,OAAO,CAAC,EAAE,GAAG,GACZ,IAAI;CA4BR;AAED,eAAO,MAAM,YAAY,cAA6B,CAAC"}
@@ -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"}