@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.
@@ -1,10 +1,10 @@
1
- import { EditTool } from '@leafer-in/editor';
1
+ import { EditTool } from "@leafer-in/editor";
2
2
  export declare class TextEditTool extends EditTool {
3
3
  get tag(): string;
4
4
  quill: any;
5
- private _dragRAF;
6
5
  private updateBoxDebounced;
7
6
  constructor(editor: any);
7
+ private debounce;
8
8
  addEvent(): void;
9
9
  onLoad(): void;
10
10
  private isUpdatingPoints;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/TextEditTool/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAA+D,MAAM,mBAAmB,CAAC;AAa1G,qBACa,YAAa,SAAQ,QAAQ;IACxC,IAAW,GAAG,WAEb;IAEM,KAAK,EAAE,GAAG,CAAQ;IACzB,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,kBAAkB,CAAsB;gBAEpC,MAAM,EAAE,GAAG;IAQhB,QAAQ,IAAI,IAAI;IAqChB,MAAM,IAAI,IAAI;IAqCrB,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,WAAW,CAAK;IAEjB,oBAAoB,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IASrC,QAAQ,IAAI,IAAI;IAchB,QAAQ,IAAI,IAAI;IAIhB,SAAS,IAAI,IAAI;CACzB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/TextEditTool/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAGT,MAAM,mBAAmB,CAAC;AAI3B,qBAEa,YAAa,SAAQ,QAAQ;IAExC,IAAW,GAAG,WAEb;IACM,KAAK,EAAE,GAAG,CAAQ;IACzB,OAAO,CAAC,kBAAkB,CAAsB;gBAEpC,MAAM,EAAE,GAAG;IAQvB,OAAO,CAAC,QAAQ;IAgBT,QAAQ,IAAI,IAAI;IA2BhB,MAAM,IAAI,IAAI;IA2BrB,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,WAAW,CAAK;IACjB,oBAAoB,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAQrC,QAAQ,IAAI,IAAI;IAgBhB,QAAQ,IAAI,IAAI;IAMhB,SAAS,IAAI,IAAI;CACzB"}
@@ -10,124 +10,98 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.TextEditTool = void 0;
13
- const leafer_ui_1 = require("leafer-ui");
14
13
  const editor_1 = require("@leafer-in/editor");
14
+ const leafer_ui_1 = require("leafer-ui");
15
+ const __1 = require("../");
15
16
  const utils_1 = require("../utils");
16
- const TextEditor_1 = require("../TextEditor");
17
- function debounce(func, wait) {
18
- let timeout = null;
19
- return function (...args) {
20
- if (timeout)
21
- clearTimeout(timeout);
22
- timeout = setTimeout(() => func.apply(this, args), wait);
23
- };
24
- }
25
17
  let TextEditTool = class TextEditTool extends editor_1.EditTool {
26
18
  get tag() {
27
- return 'TextEditTool';
19
+ return "TextEditTool";
28
20
  }
29
21
  constructor(editor) {
30
22
  super(editor);
31
23
  this.quill = null;
32
- this._dragRAF = null;
33
24
  this.isUpdatingPoints = false;
34
25
  this.curveAmount = 0;
35
26
  this.eventIds = [];
36
- this.updateBoxDebounced = debounce((text) => {
27
+ this.updateBoxDebounced = this.debounce((text) => {
37
28
  (0, utils_1.updataHtmlText)(text);
38
29
  }, 300);
39
30
  }
31
+ debounce(func, wait) {
32
+ let timeout = null;
33
+ return ((...args) => {
34
+ if (timeout !== null) {
35
+ window.clearTimeout(timeout);
36
+ }
37
+ timeout = window.setTimeout(() => func.apply(this, args), wait);
38
+ });
39
+ }
40
40
  addEvent() {
41
- if (!this.editor?.element)
42
- return;
43
- const text = this.editor.element.findOne('HTMLText');
44
- if (!text)
45
- return;
41
+ const { editor } = __1.quillManager.getCanvas();
42
+ const text = editor._target.findOne("HTMLText");
46
43
  const { scaleX, scaleY } = text.worldTransform;
47
44
  const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
48
- const div = document.querySelector('#textInnerEditor');
49
- if (!div)
50
- return;
45
+ const div = document.querySelector("#textInnerEditor");
51
46
  const { style } = div;
52
47
  this.eventIds = [
53
- this.editor.on_(editor_1.EditorScaleEvent.SCALE, (e) => {
54
- if (!text.data)
55
- text.data = {};
48
+ editor.on_(editor_1.EditorScaleEvent.SCALE, (e) => {
56
49
  if (!text.data.canChangeBox) {
57
50
  text.data.canChangeBox = true;
58
51
  }
59
- if (text.data.canChangeBox && text.parent) {
60
- const parentWidth = text.parent.width;
61
- if (parentWidth !== undefined) {
62
- style.width = parentWidth * zoomScale + 'px';
63
- style.height = 'auto';
64
- }
52
+ if (text.data.canChangeBox) {
53
+ style.width = text.parent.width * zoomScale + "px";
54
+ style.height = "auto";
65
55
  }
66
56
  this.updateBoxDebounced(text);
67
57
  }),
68
- this.editor.on_(leafer_ui_1.PointerEvent.DOUBLE_TAP, () => {
69
- if (!text.parent?.locked) {
70
- this.editor.openInnerEditor(text, true);
58
+ editor.on_(leafer_ui_1.PointerEvent.DOUBLE_TAP, () => {
59
+ if (!text.parent.locked) {
60
+ editor.openInnerEditor(text, true);
71
61
  }
72
- })
62
+ }),
73
63
  ];
74
64
  }
75
65
  onLoad() {
76
- if (!this.editor?.element)
77
- return;
78
- const text = this.editor.element.findOne('HTMLText');
79
- if (!text)
80
- return;
66
+ console.log(22222222);
67
+ const { editor } = __1.quillManager.getCanvas();
68
+ const text = editor._target.findOne("HTMLText");
81
69
  const { scaleX, scaleY } = text.worldTransform;
82
70
  const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
83
71
  this.addEvent();
84
- this.editBox.add(this.view);
85
- this.quill = TextEditor_1.TextEditor.quill;
86
- if (this.quill && text.text) {
87
- this.quill.clipboard.dangerouslyPasteHTML(text.text);
88
- }
89
- const div = document.querySelector('#textInnerEditor');
90
- if (!div)
91
- return;
72
+ this.quill = __1.quillManager.getQuill();
73
+ this.quill.clipboard.dangerouslyPasteHTML(text.text);
74
+ const div = document.querySelector("#textInnerEditor");
92
75
  const { style } = div;
93
- if (text.data?.canChangeBox && text.parent) {
94
- const parentWidth = text.parent.width;
95
- const parentHeight = text.parent.height;
96
- if (parentWidth !== undefined) {
97
- style.width = parentWidth * zoomScale + 'px';
98
- }
99
- if (parentHeight !== undefined) {
100
- style.height = parentHeight * zoomScale + 'px';
101
- }
76
+ if (text.data.canChangeBox) {
77
+ style.width = text.parent.width * zoomScale + "px";
78
+ style.height = text.parent.height * zoomScale + "px";
102
79
  }
103
80
  else {
104
- style.width = 'auto';
105
- style.height = 'auto';
81
+ style.width = "auto";
82
+ style.height = "auto";
106
83
  }
107
84
  }
108
85
  updateChangeBoxBound(text) {
109
- if (text && text.__layout?.boxBounds) {
86
+ text &&
110
87
  text.set({
111
88
  width: text.__layout.boxBounds.width,
112
- height: text.__layout.boxBounds.height
89
+ height: text.__layout.boxBounds.height,
113
90
  });
114
- }
115
91
  }
116
92
  onUpdate() {
117
- if (!this.editor?.element)
118
- return;
119
- const text = this.editor.element.findOne('HTMLText');
120
- if (!text)
121
- return;
122
- const el = this.editor.element;
123
- console.log('文本bound更新');
124
- if (this.curveAmount === text.curveAmount)
93
+ const { editor } = __1.quillManager.getCanvas();
94
+ const text = editor._target.findOne("HTMLText");
95
+ const el = editor._target;
96
+ console.log("文本bound更新");
97
+ if (this.curveAmount == text.curveAmount)
125
98
  return;
126
99
  if (this.isUpdatingPoints)
127
100
  return;
128
101
  }
129
102
  onUnload() {
130
- this.editor.off_(this.eventIds);
103
+ const { editor } = __1.quillManager.getCanvas();
104
+ editor.off_(this.eventIds);
131
105
  }
132
106
  onDestroy() { }
133
107
  };
@@ -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"}
@@ -5,8 +5,8 @@ exports.getArcRadius = getArcRadius;
5
5
  exports.toSuperscript = toSuperscript;
6
6
  exports.toSubscript = toSubscript;
7
7
  exports.toNormal = toNormal;
8
- const leafer_ui_1 = require("leafer-ui");
9
8
  const html_1 = require("@leafer-in/html");
9
+ const leafer_ui_1 = require("leafer-ui");
10
10
  function getArcRadius(fontSize, curveAmount) {
11
11
  if (curveAmount === 0)
12
12
  return Infinity;
@@ -83,20 +83,103 @@ const handleShowCurve = (element, op) => {
83
83
  };
84
84
  exports.handleShowCurve = handleShowCurve;
85
85
  const baseSuperscript = {
86
- '0': '⁰', '1': '¹', '2': '²', '3': '³', '4': '⁴', '5': '⁵', '6': '⁶', '7': '⁷', '8': '⁸', '9': '⁹',
87
- a: '', b: '', c: 'ᶜ', d: 'ᵈ', e: 'ᵉ', f: 'ᶠ', g: 'ᵍ', h: 'ʰ', i: 'ⁱ', j: 'ʲ', k: 'ᵏ',
88
- l: 'ˡ', m: '', n: 'ⁿ', o: 'ᵒ', p: 'ᵖ', r: 'ʳ', s: 'ˢ', t: 'ᵗ', u: 'ᵘ', v: 'ᵛ', w: 'ʷ',
89
- x: 'ˣ', y: 'ʸ', z: 'ᶻ',
90
- A: '', B: '', D: 'ᴰ', E: 'ᴱ', G: 'ᴳ', H: 'ᴴ', I: 'ᴵ', J: 'ᴶ', K: 'ᴷ', L: 'ᴸ', M: 'ᴹ',
91
- N: '', O: '', P: 'ᴾ', R: 'ᴿ', T: 'ᵀ', U: 'ᵁ', W: 'ᵂ',
92
- '+': '', '-': '⁻', '=': '⁼', '(': '⁽', ')': '⁾'
86
+ '0': '⁰',
87
+ '1': '¹',
88
+ '2': '²',
89
+ '3': '³',
90
+ '4': '',
91
+ '5': '',
92
+ '6': '',
93
+ '7': '⁷',
94
+ '8': '⁸',
95
+ '9': '⁹',
96
+ a: 'ᵃ',
97
+ b: 'ᵇ',
98
+ c: 'ᶜ',
99
+ d: 'ᵈ',
100
+ e: 'ᵉ',
101
+ f: 'ᶠ',
102
+ g: 'ᵍ',
103
+ h: 'ʰ',
104
+ i: 'ⁱ',
105
+ j: 'ʲ',
106
+ k: 'ᵏ',
107
+ l: 'ˡ',
108
+ m: 'ᵐ',
109
+ n: 'ⁿ',
110
+ o: 'ᵒ',
111
+ p: 'ᵖ',
112
+ r: 'ʳ',
113
+ s: 'ˢ',
114
+ t: 'ᵗ',
115
+ u: 'ᵘ',
116
+ v: 'ᵛ',
117
+ w: 'ʷ',
118
+ x: 'ˣ',
119
+ y: 'ʸ',
120
+ z: 'ᶻ',
121
+ A: 'ᴬ',
122
+ B: 'ᴮ',
123
+ D: 'ᴰ',
124
+ E: 'ᴱ',
125
+ G: 'ᴳ',
126
+ H: 'ᴴ',
127
+ I: 'ᴵ',
128
+ J: 'ᴶ',
129
+ K: 'ᴷ',
130
+ L: 'ᴸ',
131
+ M: 'ᴹ',
132
+ N: 'ᴺ',
133
+ O: 'ᴼ',
134
+ P: 'ᴾ',
135
+ R: 'ᴿ',
136
+ T: 'ᵀ',
137
+ U: 'ᵁ',
138
+ W: 'ᵂ',
139
+ '+': '⁺',
140
+ '-': '⁻',
141
+ '=': '⁼',
142
+ '(': '⁽',
143
+ ')': '⁾'
93
144
  };
94
145
  const baseSubscript = {
95
- '0': '₀', '1': '₁', '2': '₂', '3': '₃', '4': '₄', '5': '₅', '6': '₆', '7': '₇', '8': '₈', '9': '₉',
96
- a: '', e: '', h: 'ₕ', i: 'ᵢ', j: 'ⱼ', k: 'ₖ', l: 'ₗ', m: 'ₘ', n: 'ₙ', o: 'ₒ', p: 'ₚ',
97
- r: '', s: '', t: 'ₜ', u: 'ᵤ', v: 'ᵥ', x: 'ₓ',
98
- '+': '', '-': '₋', '=': '₌', '(': '₍', ')': '₎',
99
- 'β': '', 'γ': 'ᵧ', 'ρ': 'ᵨ', 'φ': 'ᵩ', 'χ': 'ᵪ'
146
+ '0': '₀',
147
+ '1': '',
148
+ '2': '',
149
+ '3': '',
150
+ '4': '',
151
+ '5': '₅',
152
+ '6': '₆',
153
+ '7': '₇',
154
+ '8': '₈',
155
+ '9': '₉',
156
+ a: 'ₐ',
157
+ e: 'ₑ',
158
+ h: 'ₕ',
159
+ i: 'ᵢ',
160
+ j: 'ⱼ',
161
+ k: 'ₖ',
162
+ l: 'ₗ',
163
+ m: 'ₘ',
164
+ n: 'ₙ',
165
+ o: 'ₒ',
166
+ p: 'ₚ',
167
+ r: 'ᵣ',
168
+ s: 'ₛ',
169
+ t: 'ₜ',
170
+ u: 'ᵤ',
171
+ v: 'ᵥ',
172
+ x: 'ₓ',
173
+ '+': '₊',
174
+ '-': '₋',
175
+ '=': '₌',
176
+ '(': '₍',
177
+ ')': '₎',
178
+ β: 'ᵦ',
179
+ γ: 'ᵧ',
180
+ ρ: 'ᵨ',
181
+ φ: 'ᵩ',
182
+ χ: 'ᵪ'
100
183
  };
101
184
  function invertMap(map) {
102
185
  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"}
@@ -5,23 +5,34 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  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;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
- var TextEditor_1;
9
8
  Object.defineProperty(exports, "__esModule", { value: true });
10
9
  exports.TextEditor = void 0;
11
- const core_1 = require("@leafer-ui/core");
12
10
  const editor_1 = require("@leafer-in/editor");
11
+ const core_1 = require("@leafer-ui/core");
12
+ const _1 = require(".");
13
13
  const utils_1 = require("./utils");
14
- let TextEditor = TextEditor_1 = class TextEditor extends editor_1.InnerEditor {
14
+ console.log(1111, 'registerInnerEditor');
15
+ let TextEditor = class TextEditor extends editor_1.InnerEditor {
15
16
  constructor() {
16
17
  super(...arguments);
17
18
  this.config = {
18
19
  selectAll: false,
19
20
  };
20
21
  this.eventIds = [];
22
+ this.selectText = undefined;
23
+ this.inBody = undefined;
24
+ this.isHTMLText = undefined;
25
+ this._keyEvent = undefined;
26
+ this.quill = null;
27
+ this.isComposing = false;
28
+ this.misspelledWords = [];
29
+ this.overlay = null;
21
30
  this.onSelectionChange = async (e) => {
22
31
  e && localStorage.setItem("selection-change", JSON.stringify(e));
23
32
  };
24
33
  this.onInput = async () => {
34
+ const { editDom } = this;
35
+ console.log("onInput");
25
36
  (0, utils_1.updataHtmlText)(this.editTarget);
26
37
  };
27
38
  this.isUpdatingPoints = false;
@@ -29,26 +40,22 @@ let TextEditor = TextEditor_1 = class TextEditor extends editor_1.InnerEditor {
29
40
  get tag() {
30
41
  return "TextEditor";
31
42
  }
43
+ get isOASystem() {
44
+ return window.location.host.includes("oa");
45
+ }
32
46
  onLoad() {
33
47
  const { editor } = this;
34
48
  const { config } = editor.app;
35
49
  const text = this.editTarget;
36
50
  const { scaleX, scaleY } = text.worldTransform;
37
51
  const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
38
- this.quill = TextEditor_1.quill;
39
52
  this.isHTMLText = !(text instanceof Text);
53
+ this._keyEvent = config.keyEvent;
40
54
  config.keyEvent = false;
41
- const element = document.querySelector("#textInnerEditor");
42
- if (!element || !(element instanceof HTMLDivElement)) {
43
- console.error("Cannot find #textInnerEditor element or it's not a div");
44
- return;
45
- }
46
- const div = (this.editDom = element);
55
+ const div = (this.editDom = document.querySelector("#textInnerEditor"));
47
56
  const { style } = div;
48
57
  style.visibility = "visible";
49
- if (text.data?.canChangeBox &&
50
- text.parent?.width !== undefined &&
51
- text.parent?.height !== undefined) {
58
+ if (text.data.canChangeBox) {
52
59
  style.width = text.parent.width * zoomScale + "px";
53
60
  style.height = text.parent.height * zoomScale + "px";
54
61
  }
@@ -57,51 +64,44 @@ let TextEditor = TextEditor_1 = class TextEditor extends editor_1.InnerEditor {
57
64
  style.height = "auto";
58
65
  }
59
66
  style.outline = "solid #8499EF";
60
- if (text.data?.textData?.fontSize) {
67
+ if (text.data.textData.fontSize) {
61
68
  div.style.fontSize = `${text.data.textData.fontSize * zoomScale}px`;
62
69
  }
63
- if (text.data?.textData?.fontFamily) {
70
+ if (text.data.textData.fontFamily) {
64
71
  div.style.fontFamily = `${text.data.textData.fontFamily}`;
65
72
  }
66
- if (text.data?.textData?.lineHeight) {
73
+ if (text.data.textData.lineHeight) {
67
74
  div.style.lineHeight = text.data.textData.lineHeight;
68
75
  }
69
- if (text.data?.textData?.letterSpacing) {
76
+ if (text.data.textData.letterSpacing) {
70
77
  div.style.letterSpacing = `${text.data.textData.letterSpacing}px`;
71
78
  }
72
- if (text.data?.textData?.textShadow) {
79
+ if (text.data.textData.textShadow) {
73
80
  div.style.textShadow = `${text.data.textData.textShadow}`;
74
81
  }
75
82
  else {
76
83
  div.style.textShadow = "none";
77
84
  }
78
- if (text.data?.textData?.alignContent) {
85
+ if (text.data.textData.alignContent) {
79
86
  const qlEditor = div.querySelector(".ql-editor");
80
- if (qlEditor) {
81
- qlEditor.style.alignContent = `${text.data.textData.alignContent}`;
82
- }
87
+ qlEditor.style.alignContent = `${text.data.textData.alignContent}`;
83
88
  }
84
- if (this.quill) {
85
- this.quill.clipboard.dangerouslyPasteHTML(text.text);
86
- if (text.parent?.children?.[0]?.tag?.includes("Shape")) {
87
- const parentWidth = text.parent.width;
88
- if (parentWidth !== undefined) {
89
- style.width = parentWidth * zoomScale + "px";
90
- style.left = "0px";
91
- }
92
- this.quill.formatLine(0, this.quill.getLength(), "align", "center");
93
- }
94
- else {
95
- this.quill.setSelection(0, this.quill.getLength() - 1);
96
- }
97
- this.quill.on("text-change", this.onInput);
98
- this.quill.on("selection-change", this.onSelectionChange);
89
+ this.quill = _1.quillManager.getQuill();
90
+ this.quill.clipboard.dangerouslyPasteHTML(text.text);
91
+ if (text.parent.children[0].tag.includes("Shape")) {
92
+ style.width = text.parent.width * zoomScale + "px";
93
+ style.left = "0px";
94
+ this.quill.formatLine(0, this.quill.getLength(), "align", "center");
95
+ }
96
+ else {
97
+ this.quill.setSelection(0, this.quill.getLength() - 1);
99
98
  }
99
+ this.quill.on("text-change", this.onInput);
100
+ this.quill.on("selection-change", this.onSelectionChange);
100
101
  localStorage.removeItem("selection-change");
101
102
  this.eventIds = [
102
103
  editor.app.on_(core_1.PointerEvent.DOWN, (e) => {
103
- let { target } = e.origin;
104
- let find = false;
104
+ let { target } = e.origin, find = false;
105
105
  while (target) {
106
106
  if (target === div)
107
107
  find = true;
@@ -116,27 +116,20 @@ let TextEditor = TextEditor_1 = class TextEditor extends editor_1.InnerEditor {
116
116
  }
117
117
  onUpdate() {
118
118
  const { editTarget: text } = this;
119
- if (!text.parent?.__local)
120
- return;
121
119
  const { scaleX, scaleY } = text.worldTransform;
122
120
  const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
123
- const local = text.parent.__local;
124
- let width = local.width || 0;
125
- let height = local.height || 0;
126
- width *= zoomScale;
127
- height *= zoomScale;
121
+ let { width, height } = text.parent.__local;
122
+ ((width *= zoomScale), (height *= zoomScale));
128
123
  const { x, y } = this.inBody
129
124
  ? text.app.clientBounds
130
- : (text.app.tree?.clientBounds || { x: 0, y: 0 });
125
+ : text.app.tree.clientBounds;
131
126
  const { a, b, c, d, e, f } = new core_1.Matrix(text.worldTransform)
132
127
  .scale(1 / zoomScale)
133
128
  .translateInner(0, 0);
134
- if (this.editDom) {
135
- const { style } = this.editDom;
136
- style.transform = `matrix(${a},${b},${c},${d},${e},${f})`;
137
- style.left = x + "px";
138
- style.top = y + "px";
139
- }
129
+ const { style } = this.editDom;
130
+ style.transform = `matrix(${a},${b},${c},${d},${e},${f})`;
131
+ style.left = x + "px";
132
+ style.top = y + "px";
140
133
  text.set({
141
134
  visible: false,
142
135
  });
@@ -145,22 +138,32 @@ let TextEditor = TextEditor_1 = class TextEditor extends editor_1.InnerEditor {
145
138
  const { editTarget: text, editor, editDom: dom } = this;
146
139
  if (text) {
147
140
  this.onInput();
141
+ if (editor.app)
142
+ editor.app.config.keyEvent = this._keyEvent;
148
143
  editor.off_(this.eventIds);
149
- if (this.editDom) {
150
- this.editDom.style.visibility = "hidden";
151
- }
144
+ this.editDom.style.visibility = "hidden";
152
145
  this.eventIds = [];
153
146
  }
154
- text.set({
155
- visible: true,
156
- });
157
- if (this.quill) {
158
- this.quill.off("text-change", this.onInput);
159
- this.quill.off("selection-change", this.onSelectionChange);
147
+ if (text.parent &&
148
+ text.parent.name == "Text" &&
149
+ text.parent.children.some((e) => e.tag === "Box")) {
150
+ text.parent.findOne("Box").opacity = 1;
151
+ text.visible = false;
152
+ }
153
+ else {
154
+ text.set({
155
+ visible: true,
156
+ });
157
+ }
158
+ if (this.quill.getLength() === 1 && text.parent.name === "Text") {
159
+ text.parent.remove();
160
160
  }
161
+ console.log("onUnload");
162
+ this.quill.off("text-change", this.onInput);
163
+ this.quill.off("selection-change", this.onSelectionChange);
161
164
  }
162
165
  };
163
166
  exports.TextEditor = TextEditor;
164
- exports.TextEditor = TextEditor = TextEditor_1 = __decorate([
167
+ exports.TextEditor = TextEditor = __decorate([
165
168
  (0, editor_1.registerInnerEditor)()
166
169
  ], TextEditor);
@@ -1,10 +1,10 @@
1
- import { EditTool } from '@leafer-in/editor';
1
+ import { EditTool } from "@leafer-in/editor";
2
2
  export declare class TextEditTool extends EditTool {
3
3
  get tag(): string;
4
4
  quill: any;
5
- private _dragRAF;
6
5
  private updateBoxDebounced;
7
6
  constructor(editor: any);
7
+ private debounce;
8
8
  addEvent(): void;
9
9
  onLoad(): void;
10
10
  private isUpdatingPoints;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/TextEditTool/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAA+D,MAAM,mBAAmB,CAAC;AAa1G,qBACa,YAAa,SAAQ,QAAQ;IACxC,IAAW,GAAG,WAEb;IAEM,KAAK,EAAE,GAAG,CAAQ;IACzB,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,kBAAkB,CAAsB;gBAEpC,MAAM,EAAE,GAAG;IAQhB,QAAQ,IAAI,IAAI;IAqChB,MAAM,IAAI,IAAI;IAqCrB,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,WAAW,CAAK;IAEjB,oBAAoB,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IASrC,QAAQ,IAAI,IAAI;IAchB,QAAQ,IAAI,IAAI;IAIhB,SAAS,IAAI,IAAI;CACzB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/TextEditTool/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAGT,MAAM,mBAAmB,CAAC;AAI3B,qBAEa,YAAa,SAAQ,QAAQ;IAExC,IAAW,GAAG,WAEb;IACM,KAAK,EAAE,GAAG,CAAQ;IACzB,OAAO,CAAC,kBAAkB,CAAsB;gBAEpC,MAAM,EAAE,GAAG;IAQvB,OAAO,CAAC,QAAQ;IAgBT,QAAQ,IAAI,IAAI;IA2BhB,MAAM,IAAI,IAAI;IA2BrB,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,WAAW,CAAK;IACjB,oBAAoB,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAQrC,QAAQ,IAAI,IAAI;IAgBhB,QAAQ,IAAI,IAAI;IAMhB,SAAS,IAAI,IAAI;CACzB"}