@visactor/vrender-core 0.21.4 → 0.21.5-vstory.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.
- package/cjs/animate/Ticker/default-ticker.d.ts +2 -0
- package/cjs/animate/Ticker/default-ticker.js +7 -1
- package/cjs/animate/Ticker/default-ticker.js.map +1 -1
- package/cjs/animate/animate.js +1 -1
- package/cjs/animate/animate.js.map +1 -1
- package/cjs/animate/easing-func.d.ts +1 -0
- package/cjs/animate/easing-func.js +16 -0
- package/cjs/animate/easing-func.js.map +1 -0
- package/cjs/animate/easing.d.ts +4 -0
- package/cjs/animate/easing.js +12 -1
- package/cjs/animate/easing.js.map +1 -1
- package/cjs/animate/index.d.ts +1 -0
- package/cjs/animate/index.js +1 -1
- package/cjs/animate/index.js.map +1 -1
- package/cjs/color-string/store.js +1 -2
- package/cjs/common/3d-interceptor.js +2 -1
- package/cjs/common/bezier-utils.d.ts +3 -0
- package/cjs/common/bezier-utils.js +17 -2
- package/cjs/common/bezier-utils.js.map +1 -1
- package/cjs/common/custom-path2d.d.ts +4 -0
- package/cjs/common/custom-path2d.js +43 -11
- package/cjs/common/custom-path2d.js.map +1 -1
- package/cjs/common/render-area.js +0 -1
- package/cjs/common/render-command-list.js +2 -1
- package/cjs/common/segment/curve/arc.d.ts +4 -1
- package/cjs/common/segment/curve/arc.js +10 -1
- package/cjs/common/segment/curve/arc.js.map +1 -1
- package/cjs/common/segment/curve/base.d.ts +4 -1
- package/cjs/common/segment/curve/base.js.map +1 -1
- package/cjs/common/segment/curve/cubic-bezier.d.ts +5 -1
- package/cjs/common/segment/curve/cubic-bezier.js +24 -3
- package/cjs/common/segment/curve/cubic-bezier.js.map +1 -1
- package/cjs/common/segment/curve/curve-context.js +5 -4
- package/cjs/common/segment/curve/curve-context.js.map +1 -1
- package/cjs/common/segment/curve/ellipse.d.ts +4 -1
- package/cjs/common/segment/curve/ellipse.js +9 -0
- package/cjs/common/segment/curve/ellipse.js.map +1 -1
- package/cjs/common/segment/curve/line.d.ts +4 -1
- package/cjs/common/segment/curve/line.js +18 -0
- package/cjs/common/segment/curve/line.js.map +1 -1
- package/cjs/common/segment/curve/move.d.ts +4 -1
- package/cjs/common/segment/curve/move.js +9 -0
- package/cjs/common/segment/curve/move.js.map +1 -1
- package/cjs/common/segment/curve/path.d.ts +2 -1
- package/cjs/common/segment/curve/path.js +5 -2
- package/cjs/common/segment/curve/path.js.map +1 -1
- package/cjs/common/segment/curve/quadratic-bezier.d.ts +6 -2
- package/cjs/common/segment/curve/quadratic-bezier.js +23 -5
- package/cjs/common/segment/curve/quadratic-bezier.js.map +1 -1
- package/cjs/common/store.js +1 -1
- package/cjs/graphic/builtin-symbol/rect.d.ts +2 -1
- package/cjs/graphic/builtin-symbol/rect.js +28 -0
- package/cjs/graphic/builtin-symbol/rect.js.map +1 -1
- package/cjs/graphic/builtin-symbol/utils.d.ts +2 -1
- package/cjs/graphic/builtin-symbol/utils.js +5 -0
- package/cjs/graphic/builtin-symbol/utils.js.map +1 -1
- package/cjs/graphic/config.js +6 -1
- package/cjs/graphic/config.js.map +1 -1
- package/cjs/graphic/graphic.js +2 -1
- package/cjs/graphic/graphic.js.map +1 -1
- package/cjs/graphic/richtext/wrapper.d.ts +1 -0
- package/cjs/graphic/richtext/wrapper.js +1 -1
- package/cjs/graphic/richtext/wrapper.js.map +1 -1
- package/cjs/graphic/richtext.js +2 -1
- package/cjs/graphic/richtext.js.map +1 -1
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/interface/animate.d.ts +5 -39
- package/cjs/interface/animate.js.map +1 -1
- package/cjs/interface/graphic/path.d.ts +1 -0
- package/cjs/interface/graphic/path.js.map +1 -1
- package/cjs/interface/graphic/symbol.d.ts +2 -0
- package/cjs/interface/graphic/symbol.js.map +1 -1
- package/cjs/interface/graphic.d.ts +6 -2
- package/cjs/interface/graphic.js.map +1 -1
- package/cjs/interface/path.d.ts +5 -0
- package/cjs/interface/path.js.map +1 -1
- package/cjs/interface/picker.d.ts +13 -0
- package/cjs/interface/picker.js.map +1 -1
- package/cjs/picker/constants.d.ts +2 -0
- package/cjs/picker/constants.js +3 -2
- package/cjs/picker/constants.js.map +1 -1
- package/cjs/picker/pick-interceptor.d.ts +7 -2
- package/cjs/picker/pick-interceptor.js +19 -2
- package/cjs/picker/pick-interceptor.js.map +1 -1
- package/cjs/picker/pick-modules.js +7 -4
- package/cjs/picker/pick-modules.js.map +1 -1
- package/cjs/picker/picker-service.d.ts +4 -2
- package/cjs/picker/picker-service.js +13 -12
- package/cjs/picker/picker-service.js.map +1 -1
- package/cjs/plugins/builtin-plugin/edit-module.d.ts +6 -5
- package/cjs/plugins/builtin-plugin/edit-module.js +84 -28
- package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.d.ts +1 -0
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.js +3 -0
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.js.map +1 -0
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +49 -30
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +280 -217
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
- package/cjs/render/contributions/render/arc3d-render.js.map +1 -1
- package/cjs/render/contributions/render/base-render.d.ts +1 -0
- package/cjs/render/contributions/render/base-render.js +20 -2
- package/cjs/render/contributions/render/base-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js +29 -2
- package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/symbol-contribution-render.d.ts +8 -1
- package/cjs/render/contributions/render/contributions/symbol-contribution-render.js +30 -2
- package/cjs/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/path-render.js.map +1 -1
- package/cjs/render/contributions/render/polygon-render.js.map +1 -1
- package/cjs/render/contributions/render/symbol-render.js +15 -12
- package/cjs/render/contributions/render/symbol-render.js.map +1 -1
- package/cjs/render/contributions/render/utils.d.ts +1 -2
- package/cjs/render/contributions/render/utils.js +4 -20
- package/cjs/render/contributions/render/utils.js.map +1 -1
- package/dist/index.es.js +8351 -7751
- package/es/animate/Ticker/default-ticker.d.ts +2 -0
- package/es/animate/Ticker/default-ticker.js +7 -1
- package/es/animate/Ticker/default-ticker.js.map +1 -1
- package/es/animate/animate.js +1 -1
- package/es/animate/animate.js.map +1 -1
- package/es/animate/easing-func.d.ts +1 -0
- package/es/animate/easing-func.js +10 -0
- package/es/animate/easing-func.js.map +1 -0
- package/es/animate/easing.d.ts +4 -0
- package/es/animate/easing.js +12 -1
- package/es/animate/easing.js.map +1 -1
- package/es/animate/index.d.ts +1 -0
- package/es/animate/index.js +2 -0
- package/es/animate/index.js.map +1 -1
- package/es/color-string/store.js +1 -2
- package/es/common/3d-interceptor.js +2 -1
- package/es/common/bezier-utils.d.ts +3 -0
- package/es/common/bezier-utils.js +14 -0
- package/es/common/bezier-utils.js.map +1 -1
- package/es/common/custom-path2d.d.ts +4 -0
- package/es/common/custom-path2d.js +44 -12
- package/es/common/custom-path2d.js.map +1 -1
- package/es/common/render-area.js +1 -2
- package/es/common/render-command-list.js +2 -1
- package/es/common/segment/curve/arc.d.ts +4 -1
- package/es/common/segment/curve/arc.js +10 -1
- package/es/common/segment/curve/arc.js.map +1 -1
- package/es/common/segment/curve/base.d.ts +4 -1
- package/es/common/segment/curve/base.js.map +1 -1
- package/es/common/segment/curve/cubic-bezier.d.ts +5 -1
- package/es/common/segment/curve/cubic-bezier.js +22 -1
- package/es/common/segment/curve/cubic-bezier.js.map +1 -1
- package/es/common/segment/curve/curve-context.js +6 -3
- package/es/common/segment/curve/curve-context.js.map +1 -1
- package/es/common/segment/curve/ellipse.d.ts +4 -1
- package/es/common/segment/curve/ellipse.js +9 -0
- package/es/common/segment/curve/ellipse.js.map +1 -1
- package/es/common/segment/curve/line.d.ts +4 -1
- package/es/common/segment/curve/line.js +18 -0
- package/es/common/segment/curve/line.js.map +1 -1
- package/es/common/segment/curve/move.d.ts +4 -1
- package/es/common/segment/curve/move.js +9 -0
- package/es/common/segment/curve/move.js.map +1 -1
- package/es/common/segment/curve/path.d.ts +2 -1
- package/es/common/segment/curve/path.js +5 -2
- package/es/common/segment/curve/path.js.map +1 -1
- package/es/common/segment/curve/quadratic-bezier.d.ts +6 -2
- package/es/common/segment/curve/quadratic-bezier.js +28 -5
- package/es/common/segment/curve/quadratic-bezier.js.map +1 -1
- package/es/common/store.js +1 -1
- package/es/graphic/builtin-symbol/rect.d.ts +2 -1
- package/es/graphic/builtin-symbol/rect.js +28 -0
- package/es/graphic/builtin-symbol/rect.js.map +1 -1
- package/es/graphic/builtin-symbol/utils.d.ts +2 -1
- package/es/graphic/builtin-symbol/utils.js +5 -0
- package/es/graphic/builtin-symbol/utils.js.map +1 -1
- package/es/graphic/config.js +6 -1
- package/es/graphic/config.js.map +1 -1
- package/es/graphic/graphic.js +2 -1
- package/es/graphic/graphic.js.map +1 -1
- package/es/graphic/richtext/wrapper.d.ts +1 -0
- package/es/graphic/richtext/wrapper.js +1 -1
- package/es/graphic/richtext/wrapper.js.map +1 -1
- package/es/graphic/richtext.js +2 -1
- package/es/graphic/richtext.js.map +1 -1
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -0
- package/es/index.js.map +1 -1
- package/es/interface/animate.d.ts +5 -39
- package/es/interface/animate.js.map +1 -1
- package/es/interface/graphic/path.d.ts +1 -0
- package/es/interface/graphic/path.js.map +1 -1
- package/es/interface/graphic/symbol.d.ts +2 -0
- package/es/interface/graphic/symbol.js.map +1 -1
- package/es/interface/graphic.d.ts +6 -2
- package/es/interface/graphic.js.map +1 -1
- package/es/interface/path.d.ts +5 -0
- package/es/interface/path.js.map +1 -1
- package/es/interface/picker.d.ts +13 -0
- package/es/interface/picker.js.map +1 -1
- package/es/picker/constants.d.ts +2 -0
- package/es/picker/constants.js +4 -0
- package/es/picker/constants.js.map +1 -1
- package/es/picker/pick-interceptor.d.ts +7 -2
- package/es/picker/pick-interceptor.js +19 -1
- package/es/picker/pick-interceptor.js.map +1 -1
- package/es/picker/pick-modules.js +5 -3
- package/es/picker/pick-modules.js.map +1 -1
- package/es/picker/picker-service.d.ts +4 -2
- package/es/picker/picker-service.js +13 -13
- package/es/picker/picker-service.js.map +1 -1
- package/es/plugins/builtin-plugin/edit-module.d.ts +6 -5
- package/es/plugins/builtin-plugin/edit-module.js +79 -25
- package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/es/plugins/builtin-plugin/richtext-edit-plugin-old.d.ts +1 -0
- package/es/plugins/builtin-plugin/richtext-edit-plugin-old.js +3 -0
- package/es/plugins/builtin-plugin/richtext-edit-plugin-old.js.map +1 -0
- package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +49 -30
- package/es/plugins/builtin-plugin/richtext-edit-plugin.js +283 -214
- package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
- package/es/render/contributions/render/arc3d-render.js.map +1 -1
- package/es/render/contributions/render/base-render.d.ts +1 -0
- package/es/render/contributions/render/base-render.js +21 -2
- package/es/render/contributions/render/base-render.js.map +1 -1
- package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
- package/es/render/contributions/render/contributions/base-texture-contribution-render.js +29 -2
- package/es/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
- package/es/render/contributions/render/contributions/symbol-contribution-render.d.ts +8 -1
- package/es/render/contributions/render/contributions/symbol-contribution-render.js +26 -0
- package/es/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
- package/es/render/contributions/render/path-render.js.map +1 -1
- package/es/render/contributions/render/polygon-render.js.map +1 -1
- package/es/render/contributions/render/symbol-render.js +16 -13
- package/es/render/contributions/render/symbol-render.js.map +1 -1
- package/es/render/contributions/render/utils.d.ts +1 -2
- package/es/render/contributions/render/utils.js +0 -18
- package/es/render/contributions/render/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,17 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function
|
|
3
|
+
var __rest = this && this.__rest || function(s, e) {
|
|
4
|
+
var t = {};
|
|
5
|
+
for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
|
|
6
|
+
if (null != s && "function" == typeof Object.getOwnPropertySymbols) {
|
|
7
|
+
var i = 0;
|
|
8
|
+
for (p = Object.getOwnPropertySymbols(s); i < p.length; i++) e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
Object.defineProperty(exports, "__esModule", {
|
|
14
|
+
value: !0
|
|
15
|
+
}), exports.EditModule = exports.textConfigIgnoreLinebreakIdxToCursorIdx = exports.findConfigIndex = void 0;
|
|
16
|
+
|
|
17
|
+
const application_1 = require("../../application");
|
|
18
|
+
|
|
19
|
+
function getMaxConfigIndexIgnoreLinebreak(textConfig) {
|
|
20
|
+
let idx = 0;
|
|
21
|
+
for (let i = 0; i < textConfig.length; i++) {
|
|
22
|
+
"\n" !== textConfig[i].text && idx++;
|
|
23
|
+
}
|
|
24
|
+
return Math.max(idx - 1, 0);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function findConfigIndex(textConfig, cursorIndex) {
|
|
4
28
|
let index = 0;
|
|
29
|
+
if (cursorIndex < 0) return -1;
|
|
30
|
+
let idx = Math.round(cursorIndex);
|
|
5
31
|
for (index = 0; index < textConfig.length; index++) {
|
|
6
|
-
|
|
7
|
-
if (c.text && "\n" === c.text || cursorIndex--, cursorIndex < 0) break;
|
|
32
|
+
if ("\n" !== textConfig[index].text && idx--, idx < 0) break;
|
|
8
33
|
}
|
|
9
|
-
return index
|
|
34
|
+
return cursorIndex - Math.round(cursorIndex) < 0 && index--, index = Math.max(index, 0),
|
|
35
|
+
Math.min(index, textConfig.length - 1);
|
|
10
36
|
}
|
|
11
37
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
38
|
+
function textConfigIgnoreLinebreakIdxToCursorIdx(textConfig, cursorIndex) {
|
|
39
|
+
var _a;
|
|
40
|
+
let index = 0;
|
|
41
|
+
for (let i = 0; i < cursorIndex; i++) {
|
|
42
|
+
"\n" !== textConfig[i].text && index++;
|
|
43
|
+
}
|
|
44
|
+
return "\n" === (null === (_a = textConfig[cursorIndex]) || void 0 === _a ? void 0 : _a.text) ? index -= .1 : index += .1,
|
|
45
|
+
index;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.findConfigIndex = findConfigIndex, exports.textConfigIgnoreLinebreakIdxToCursorIdx = textConfigIgnoreLinebreakIdxToCursorIdx;
|
|
15
49
|
|
|
16
50
|
class EditModule {
|
|
17
51
|
constructor(container) {
|
|
@@ -21,45 +55,67 @@ class EditModule {
|
|
|
21
55
|
type: "Backspace"
|
|
22
56
|
});
|
|
23
57
|
}, this.handleCompositionStart = () => {
|
|
24
|
-
const {textConfig: textConfig = []} = this.currRt.attribute
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
58
|
+
const {textConfig: textConfig = []} = this.currRt.attribute;
|
|
59
|
+
if (this.cursorIndex < 0) {
|
|
60
|
+
const config = textConfig[0];
|
|
61
|
+
textConfig.unshift(Object.assign(Object.assign({
|
|
62
|
+
fill: "black"
|
|
63
|
+
}, config), {
|
|
64
|
+
text: ""
|
|
65
|
+
}));
|
|
66
|
+
} else {
|
|
67
|
+
const cursorIndex = findConfigIndex(textConfig, this.cursorIndex), lastConfig = textConfig[cursorIndex];
|
|
68
|
+
textConfig.splice(cursorIndex + 1, 0, Object.assign(Object.assign({}, lastConfig), {
|
|
69
|
+
text: ""
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
this.isComposing = !0;
|
|
28
73
|
}, this.handleCompositionEnd = () => {
|
|
29
74
|
this.isComposing = !1;
|
|
30
|
-
const {textConfig: textConfig = []} = this.currRt.attribute,
|
|
31
|
-
textConfig.splice(
|
|
32
|
-
const text = lastConfig.text, textList = Array.from(text.toString());
|
|
33
|
-
for (let i = 0; i < textList.length; i++) textConfig.splice(i +
|
|
75
|
+
const {textConfig: textConfig = []} = this.currRt.attribute, configIdx = findConfigIndex(textConfig, this.cursorIndex + 1), lastConfig = textConfig[configIdx];
|
|
76
|
+
textConfig.splice(configIdx, 1);
|
|
77
|
+
const text = lastConfig.text, textList = text ? Array.from(text.toString()) : [];
|
|
78
|
+
for (let i = 0; i < textList.length; i++) textConfig.splice(i + configIdx, 0, Object.assign(Object.assign({}, lastConfig), {
|
|
34
79
|
text: textList[i]
|
|
35
80
|
}));
|
|
36
81
|
this.currRt.setAttributes({
|
|
37
82
|
textConfig: textConfig
|
|
38
83
|
}), this.onChangeCbList.forEach((cb => {
|
|
39
|
-
cb(text, this.isComposing, this.cursorIndex + textList.length, this.currRt
|
|
84
|
+
cb(text, this.isComposing, Math.min(this.cursorIndex + textList.length, getMaxConfigIndexIgnoreLinebreak(textConfig) + .1), this.currRt);
|
|
40
85
|
}));
|
|
41
86
|
}, this.handleInput = ev => {
|
|
87
|
+
var _a, _b, _c, _d;
|
|
42
88
|
if (!this.currRt) return;
|
|
89
|
+
const _e = this.currRt.attribute, {textConfig: textConfig = []} = _e, rest = __rest(_e, [ "textConfig" ]);
|
|
90
|
+
if ("Backspace" === ev.type && !textConfig.length) return;
|
|
43
91
|
let str = ev.data;
|
|
44
|
-
"Backspace" === ev.type || str || (str = "\n");
|
|
45
|
-
const {textConfig: textConfig = []} = this.currRt.attribute;
|
|
92
|
+
this.isComposing || "Backspace" === ev.type || str || (str = "\n");
|
|
46
93
|
let startIdx = this.selectionStartCursorIdx, endIdx = this.cursorIndex;
|
|
47
94
|
startIdx > endIdx && ([startIdx, endIdx] = [ endIdx, startIdx ]), this.selectionStartCursorIdx = startIdx,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const
|
|
95
|
+
startIdx = findConfigIndex(textConfig, startIdx), endIdx = findConfigIndex(textConfig, endIdx);
|
|
96
|
+
let idxDelta = 0;
|
|
97
|
+
"\n" === str && (idxDelta = -.2);
|
|
98
|
+
const lastConfigIdx = startIdx + (this.isComposing ? 1 : 0);
|
|
99
|
+
let lastConfig = textConfig[lastConfigIdx];
|
|
100
|
+
lastConfig || (lastConfig = 0 === textConfig.length ? {
|
|
101
|
+
fill: null !== (_a = rest.fill) && void 0 !== _a ? _a : "black",
|
|
102
|
+
stroke: null !== (_b = rest.stroke) && void 0 !== _b && _b,
|
|
103
|
+
fontSize: null !== (_c = rest.fontSize) && void 0 !== _c ? _c : 12,
|
|
104
|
+
fontWeight: null !== (_d = rest.fontWeight) && void 0 !== _d ? _d : "normal"
|
|
105
|
+
} : textConfig[lastConfigIdx - 1] || textConfig[lastConfigIdx + 1]);
|
|
52
106
|
let currConfig = lastConfig;
|
|
53
107
|
"Backspace" !== ev.type || this.isComposing ? (startIdx !== endIdx && textConfig.splice(startIdx + 1, endIdx - startIdx),
|
|
54
108
|
this.isComposing || (currConfig = Object.assign(Object.assign({}, lastConfig), {
|
|
55
109
|
text: ""
|
|
56
|
-
}), startIdx += 1, textConfig.splice(startIdx, 0, currConfig)), currConfig.text = str
|
|
110
|
+
}), startIdx += 1, textConfig.splice(startIdx, 0, currConfig)), currConfig.text = str,
|
|
111
|
+
textConfig.length || textConfig.push(currConfig)) : startIdx !== endIdx ? textConfig.splice(startIdx + 1, endIdx - startIdx) : (textConfig.splice(startIdx, 1),
|
|
57
112
|
startIdx -= 1), this.currRt.setAttributes({
|
|
58
113
|
textConfig: textConfig
|
|
59
|
-
}), this.
|
|
60
|
-
|
|
114
|
+
}), this.cursorIndex = textConfigIgnoreLinebreakIdxToCursorIdx(textConfig, startIdx),
|
|
115
|
+
this.cursorIndex += idxDelta, this.isComposing ? this.onInputCbList.forEach((cb => {
|
|
116
|
+
cb(str, this.isComposing, this.cursorIndex, this.currRt);
|
|
61
117
|
})) : this.onChangeCbList.forEach((cb => {
|
|
62
|
-
cb(str, this.isComposing,
|
|
118
|
+
cb(str, this.isComposing, this.cursorIndex, this.currRt);
|
|
63
119
|
}));
|
|
64
120
|
}, this.container = null != container ? container : document.body;
|
|
65
121
|
const textAreaDom = document.createElement("textarea");
|
|
@@ -76,7 +132,7 @@ class EditModule {
|
|
|
76
132
|
applyStyle(textAreaDom) {
|
|
77
133
|
textAreaDom.setAttribute("style", "width: 100px; height: 30px; left: 0; top: 0; position: absolute; z-index: -1; outline: none; resize: none; border: none; overflow: hidden; color: transparent; user-select: none; caret-color: transparent;background-color: transparent;"),
|
|
78
134
|
textAreaDom.addEventListener("input", this.handleInput), textAreaDom.addEventListener("compositionstart", this.handleCompositionStart),
|
|
79
|
-
textAreaDom.addEventListener("compositionend", this.handleCompositionEnd),
|
|
135
|
+
textAreaDom.addEventListener("compositionend", this.handleCompositionEnd), application_1.application.global.addEventListener("keydown", this.handleKeyDown);
|
|
80
136
|
}
|
|
81
137
|
moveTo(x, y, rt, cursorIndex, selectionStartCursorIdx) {
|
|
82
138
|
this.textAreaDom.style.left = `${x}px`, this.textAreaDom.style.top = `${y}px`, setTimeout((() => {
|
|
@@ -86,7 +142,7 @@ class EditModule {
|
|
|
86
142
|
release() {
|
|
87
143
|
this.textAreaDom.removeEventListener("input", this.handleInput), this.textAreaDom.removeEventListener("compositionstart", this.handleCompositionStart),
|
|
88
144
|
this.textAreaDom.removeEventListener("compositionend", this.handleCompositionEnd),
|
|
89
|
-
|
|
145
|
+
application_1.application.global.removeEventListener("keydown", this.handleKeyDown);
|
|
90
146
|
}
|
|
91
147
|
}
|
|
92
148
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugins/builtin-plugin/edit-module.ts"],"names":[],"mappings":";;;AAGA,SAAgB,8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B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QAEjB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;IACzD,CAAC;IAED,OAAO;QACL,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAChE,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACtF,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAClF,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC5D,CAAC;CACF;AAjKD,gCAiKC","file":"edit-module.js","sourcesContent":["import type { IRichText, IRichTextCharacter, IRichTextParagraphCharacter } from '../../interface';\nimport { IRichTextIcon, IRichTextParagraph } from '../../interface';\n\nexport function findCursorIndexIgnoreLinebreak(textConfig: IRichTextCharacter[], cursorIndex: number): number {\n let index = 0;\n for (index = 0; index < textConfig.length; index++) {\n const c = textConfig[index] as IRichTextParagraphCharacter;\n if (!(c.text && c.text === '\\n')) {\n cursorIndex--;\n }\n if (cursorIndex < 0) {\n break;\n }\n }\n return index;\n}\n\nexport class EditModule {\n container: HTMLElement;\n textAreaDom: HTMLTextAreaElement;\n currRt: IRichText;\n isComposing: boolean;\n cursorIndex: number;\n selectionStartCursorIdx: number;\n // 输入的回调(composing的时候每次也会触发)\n onInputCbList: Array<\n (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void\n >;\n // change的回调(composing确认才会触发)\n onChangeCbList: Array<\n (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void\n >;\n\n constructor(container?: HTMLElement) {\n this.container = container ?? document.body;\n\n const textAreaDom = document.createElement('textarea');\n textAreaDom.autocomplete = 'off';\n textAreaDom.innerText = '';\n this.applyStyle(textAreaDom);\n this.container.append(textAreaDom);\n this.textAreaDom = textAreaDom;\n this.isComposing = false;\n this.onInputCbList = [];\n this.onChangeCbList = [];\n }\n\n onInput(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void) {\n this.onInputCbList.push(cb);\n }\n\n onChange(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void) {\n this.onChangeCbList.push(cb);\n }\n\n applyStyle(textAreaDom: HTMLTextAreaElement) {\n textAreaDom.setAttribute(\n 'style',\n `width: 100px; height: 30px; left: 0; top: 0; position: absolute; z-index: -1; outline: none; resize: none; border: none; overflow: hidden; color: transparent; user-select: none; caret-color: transparent;background-color: transparent;`\n );\n\n textAreaDom.addEventListener('input', this.handleInput);\n textAreaDom.addEventListener('compositionstart', this.handleCompositionStart);\n textAreaDom.addEventListener('compositionend', this.handleCompositionEnd);\n window.addEventListener('keydown', this.handleKeyDown);\n }\n\n handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Delete' || e.key === 'Backspace') {\n this.handleInput({ data: null, type: 'Backspace' });\n }\n };\n\n handleCompositionStart = () => {\n const { textConfig = [] } = this.currRt.attribute;\n const cursorIndex = findCursorIndexIgnoreLinebreak(textConfig, this.cursorIndex);\n const lastConfig = textConfig[cursorIndex];\n textConfig.splice(cursorIndex + 1, 0, { ...lastConfig, text: '' });\n this.isComposing = true;\n };\n handleCompositionEnd = () => {\n this.isComposing = false;\n // 拆分上一次的内容\n const { textConfig = [] } = this.currRt.attribute;\n const curIdx = findCursorIndexIgnoreLinebreak(textConfig, this.cursorIndex + 1);\n\n const lastConfig = textConfig[curIdx];\n textConfig.splice(curIdx, 1);\n const text = (lastConfig as any).text;\n const textList: string[] = Array.from(text.toString());\n for (let i = 0; i < textList.length; i++) {\n textConfig.splice(i + curIdx, 0, { ...lastConfig, text: textList[i] });\n }\n this.currRt.setAttributes({ textConfig });\n this.onChangeCbList.forEach(cb => {\n cb(text, this.isComposing, this.cursorIndex + textList.length, this.currRt, 'right');\n });\n };\n\n handleInput = (ev: any) => {\n if (!this.currRt) {\n return;\n }\n let str = (ev as any).data;\n if (ev.type !== 'Backspace' && !str) {\n str = '\\n';\n }\n // 如果是回车,那就不往后+1\n const { textConfig = [] } = this.currRt.attribute;\n\n // 如果有选中多个文字,那就先删除\n let startIdx = this.selectionStartCursorIdx;\n let endIdx = this.cursorIndex;\n if (startIdx > endIdx) {\n [startIdx, endIdx] = [endIdx, startIdx];\n }\n // 无论是否composition都立刻恢复到没有选中的idx状态\n this.selectionStartCursorIdx = startIdx;\n this.cursorIndex = startIdx;\n\n // 转换成基于textConfig的\n startIdx = findCursorIndexIgnoreLinebreak(textConfig, startIdx);\n const delta = this.selectionStartCursorIdx - startIdx;\n endIdx = findCursorIndexIgnoreLinebreak(textConfig, endIdx);\n\n const lastConfig = textConfig[startIdx + (this.isComposing ? 1 : 0)];\n let currConfig = lastConfig;\n if (ev.type === 'Backspace' && !this.isComposing) {\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx + 1, endIdx - startIdx);\n } else {\n textConfig.splice(startIdx, 1);\n startIdx -= 1;\n }\n } else {\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx + 1, endIdx - startIdx);\n }\n\n if (!this.isComposing) {\n currConfig = { ...lastConfig, text: '' };\n startIdx += 1;\n textConfig.splice(startIdx, 0, currConfig);\n }\n (currConfig as any).text = str;\n }\n\n this.currRt.setAttributes({ textConfig });\n if (!this.isComposing) {\n this.onChangeCbList.forEach(cb => {\n cb(str, this.isComposing, startIdx + delta, this.currRt, str === '\\n' ? 'left' : 'right');\n });\n } else {\n this.onInputCbList.forEach(cb => {\n cb(str, this.isComposing, startIdx + delta, this.currRt, str === '\\n' ? 'left' : 'right');\n });\n }\n };\n\n moveTo(x: number, y: number, rt: IRichText, cursorIndex: number, selectionStartCursorIdx: number) {\n this.textAreaDom.style.left = `${x}px`;\n this.textAreaDom.style.top = `${y}px`;\n setTimeout(() => {\n this.textAreaDom.focus();\n this.textAreaDom.setSelectionRange(0, 0);\n });\n this.currRt = rt;\n\n this.cursorIndex = cursorIndex;\n this.selectionStartCursorIdx = selectionStartCursorIdx;\n }\n\n release() {\n this.textAreaDom.removeEventListener('input', this.handleInput);\n this.textAreaDom.removeEventListener('compositionstart', this.handleCompositionStart);\n this.textAreaDom.removeEventListener('compositionend', this.handleCompositionEnd);\n window.removeEventListener('keydown', this.handleKeyDown);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/plugins/builtin-plugin/edit-module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,mDAAgD;AAIhD,SAAS,gCAAgC,CAAC,UAAgC;IACxE,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAgC,CAAC;QACvD,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,EAAE;YACnB,GAAG,EAAE,CAAC;SACP;KACF;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9B,CAAC;AAQD,SAAgB,eAAe,CAAC,UAAgC,EAAE,WAAmB;IACnF,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,IAAI,WAAW,GAAG,CAAC,EAAE;QACnB,OAAO,CAAC,CAAC,CAAC;KACX;IACD,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAClC,KAAK,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAClD,MAAM,CAAC,GAAG,UAA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AAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACrE,CAAC;IA0ID,MAAM,CAAC,CAAS,EAAE,CAAS,EAAE,EAAa,EAAE,WAAmB,EAAE,uBAA+B;QAC9F,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACvC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC;QACtC,UAAU,CAAC,GAAG,EAAE;YACd,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QAEjB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;IACzD,CAAC;IAED,OAAO;QACL,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAChE,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACtF,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAClF,yBAAW,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACxE,CAAC;CACF;AAzMD,gCAyMC","file":"edit-module.js","sourcesContent":["import { application } from '../../application';\nimport type { IRichText, IRichTextCharacter, IRichTextParagraphCharacter } from '../../interface';\nimport { IRichTextIcon, IRichTextParagraph } from '../../interface';\n\nfunction getMaxConfigIndexIgnoreLinebreak(textConfig: IRichTextCharacter[]) {\n let idx = 0;\n for (let i = 0; i < textConfig.length; i++) {\n const c = textConfig[i] as IRichTextParagraphCharacter;\n if (c.text !== '\\n') {\n idx++;\n }\n }\n return Math.max(idx - 1, 0);\n}\n\n/**\n * 找到cursorIndex所在的textConfig的位置,忽略换行符\n * @param textConfig\n * @param cursorIndex\n * @returns\n */\nexport function findConfigIndex(textConfig: IRichTextCharacter[], cursorIndex: number): number {\n let index = 0;\n // 小于0是在最前面了\n if (cursorIndex < 0) {\n return -1;\n }\n let idx = Math.round(cursorIndex);\n for (index = 0; index < textConfig.length; index++) {\n const c = textConfig[index] as IRichTextParagraphCharacter;\n if (c.text !== '\\n') {\n idx--;\n }\n if (idx < 0) {\n break;\n }\n }\n if (cursorIndex - Math.round(cursorIndex) < 0) {\n index--;\n }\n index = Math.max(index, 0);\n // 避免超过限度,最后一个字符可能是换行符,算一个字符\n return Math.min(index, textConfig.length - 1);\n}\n\nexport function textConfigIgnoreLinebreakIdxToCursorIdx(textConfig: IRichTextCharacter[], cursorIndex: number): number {\n let index = 0;\n for (let i = 0; i < cursorIndex; i++) {\n const c = textConfig[i] as IRichTextParagraphCharacter;\n if (c.text !== '\\n') {\n index++;\n }\n }\n // 正常Cursor是放在右边的,但如果回退到换行符了,那就放在左侧\n if ((textConfig[cursorIndex] as any)?.text === '\\n') {\n index -= 0.1;\n } else {\n index += 0.1;\n }\n return index;\n}\n\nexport class EditModule {\n container: HTMLElement;\n textAreaDom: HTMLTextAreaElement;\n currRt: IRichText;\n isComposing: boolean;\n cursorIndex: number;\n selectionStartCursorIdx: number;\n // 输入的回调(composing的时候每次也会触发)\n onInputCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void>;\n // change的回调(composing确认才会触发)\n onChangeCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void>;\n\n constructor(container?: HTMLElement) {\n this.container = container ?? document.body;\n\n const textAreaDom = document.createElement('textarea');\n textAreaDom.autocomplete = 'off';\n textAreaDom.innerText = '';\n this.applyStyle(textAreaDom);\n this.container.append(textAreaDom);\n this.textAreaDom = textAreaDom;\n this.isComposing = false;\n this.onInputCbList = [];\n this.onChangeCbList = [];\n }\n\n onInput(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void) {\n this.onInputCbList.push(cb);\n }\n\n onChange(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void) {\n this.onChangeCbList.push(cb);\n }\n\n applyStyle(textAreaDom: HTMLTextAreaElement) {\n textAreaDom.setAttribute(\n 'style',\n `width: 100px; height: 30px; left: 0; top: 0; position: absolute; z-index: -1; outline: none; resize: none; border: none; overflow: hidden; color: transparent; user-select: none; caret-color: transparent;background-color: transparent;`\n );\n\n textAreaDom.addEventListener('input', this.handleInput);\n textAreaDom.addEventListener('compositionstart', this.handleCompositionStart);\n textAreaDom.addEventListener('compositionend', this.handleCompositionEnd);\n application.global.addEventListener('keydown', this.handleKeyDown);\n }\n\n handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Delete' || e.key === 'Backspace') {\n this.handleInput({ data: null, type: 'Backspace' });\n }\n };\n\n handleCompositionStart = () => {\n const { textConfig = [] } = this.currRt.attribute;\n if (this.cursorIndex < 0) {\n const config = textConfig[0];\n textConfig.unshift({ fill: 'black', ...config, text: '' });\n } else {\n const cursorIndex = findConfigIndex(textConfig, this.cursorIndex);\n const lastConfig = textConfig[cursorIndex];\n textConfig.splice(cursorIndex + 1, 0, { ...lastConfig, text: '' });\n }\n\n this.isComposing = true;\n };\n handleCompositionEnd = () => {\n this.isComposing = false;\n // 拆分上一次的内容\n const { textConfig = [] } = this.currRt.attribute;\n const configIdx = findConfigIndex(textConfig, this.cursorIndex + 1);\n\n const lastConfig = textConfig[configIdx];\n textConfig.splice(configIdx, 1);\n const text = (lastConfig as any).text;\n const textList: string[] = text ? Array.from(text.toString()) : [];\n for (let i = 0; i < textList.length; i++) {\n textConfig.splice(i + configIdx, 0, { ...lastConfig, text: textList[i] });\n }\n this.currRt.setAttributes({ textConfig });\n this.onChangeCbList.forEach(cb => {\n cb(\n text,\n this.isComposing,\n // TODO 当换行后刚开始输入会有问题,后续看这里具体Cursor变换逻辑\n Math.min(this.cursorIndex + textList.length, getMaxConfigIndexIgnoreLinebreak(textConfig) + 0.1),\n this.currRt\n );\n });\n };\n\n handleInput = (ev: any) => {\n if (!this.currRt) {\n return;\n }\n\n // 如果是回车,那就不往后+1\n const { textConfig = [], ...rest } = this.currRt.attribute;\n // 删完了,直接返回\n if (ev.type === 'Backspace' && !textConfig.length) {\n return;\n }\n\n let str = (ev as any).data;\n if (!this.isComposing && ev.type !== 'Backspace' && !str) {\n str = '\\n';\n }\n\n // 如果有选中多个文字,那就先删除\n let startIdx = this.selectionStartCursorIdx;\n let endIdx = this.cursorIndex;\n if (startIdx > endIdx) {\n [startIdx, endIdx] = [endIdx, startIdx];\n }\n // 无论是否composition都立刻恢复到没有选中的idx状态\n this.selectionStartCursorIdx = startIdx;\n\n // 转换成基于textConfig的\n // let delta = 0;\n startIdx = findConfigIndex(textConfig, startIdx);\n // delta = this.selectionStartCursorIdx - startIdx;\n endIdx = findConfigIndex(textConfig, endIdx);\n // console.log(startIdx, delta, endIdx);\n\n let idxDelta = 0;\n // 如果是换行,得往回一格\n if (str === '\\n') {\n idxDelta = -0.2;\n }\n\n const lastConfigIdx = startIdx + (this.isComposing ? 1 : 0);\n let lastConfig: any = textConfig[lastConfigIdx];\n if (!lastConfig) {\n if (textConfig.length === 0) {\n lastConfig = {\n fill: rest.fill ?? 'black',\n stroke: rest.stroke ?? false,\n fontSize: rest.fontSize ?? 12,\n fontWeight: rest.fontWeight ?? 'normal'\n };\n } else {\n lastConfig = textConfig[lastConfigIdx - 1] || textConfig[lastConfigIdx + 1];\n }\n }\n let currConfig = lastConfig;\n if (ev.type === 'Backspace' && !this.isComposing) {\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx + 1, endIdx - startIdx);\n } else {\n textConfig.splice(startIdx, 1);\n startIdx -= 1;\n }\n } else {\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx + 1, endIdx - startIdx);\n }\n\n if (!this.isComposing) {\n currConfig = { ...lastConfig, text: '' };\n startIdx += 1;\n textConfig.splice(startIdx, 0, currConfig);\n }\n (currConfig as any).text = str;\n if (!textConfig.length) {\n textConfig.push(currConfig);\n }\n }\n\n this.currRt.setAttributes({ textConfig });\n this.cursorIndex = textConfigIgnoreLinebreakIdxToCursorIdx(textConfig, startIdx);\n\n this.cursorIndex += idxDelta;\n if (!this.isComposing) {\n this.onChangeCbList.forEach(cb => {\n cb(str, this.isComposing, this.cursorIndex, this.currRt);\n });\n } else {\n this.onInputCbList.forEach(cb => {\n cb(str, this.isComposing, this.cursorIndex, this.currRt);\n });\n }\n };\n\n moveTo(x: number, y: number, rt: IRichText, cursorIndex: number, selectionStartCursorIdx: number) {\n this.textAreaDom.style.left = `${x}px`;\n this.textAreaDom.style.top = `${y}px`;\n setTimeout(() => {\n this.textAreaDom.focus();\n this.textAreaDom.setSelectionRange(0, 0);\n });\n this.currRt = rt;\n\n this.cursorIndex = cursorIndex;\n this.selectionStartCursorIdx = selectionStartCursorIdx;\n }\n\n release() {\n this.textAreaDom.removeEventListener('input', this.handleInput);\n this.textAreaDom.removeEventListener('compositionstart', this.handleCompositionStart);\n this.textAreaDom.removeEventListener('compositionend', this.handleCompositionEnd);\n application.global.removeEventListener('keydown', this.handleKeyDown);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugins/builtin-plugin/richtext-edit-plugin-old.ts"],"names":[],"mappings":"","file":"richtext-edit-plugin-old.js","sourcesContent":["// import type { IPointLike } from '@visactor/vutils';\n// import { isObject, isString, max, merge } from '@visactor/vutils';\n// import { Generator } from '../../common/generator';\n// import { createGroup, createLine, createRect } from '../../graphic';\n// import type {\n// IGroup,\n// ILine,\n// IPlugin,\n// IPluginService,\n// IRect,\n// IRichText,\n// IRichTextCharacter,\n// IRichTextFrame,\n// IRichTextIcon,\n// IRichTextLine,\n// IRichTextParagraph,\n// IRichTextParagraphCharacter,\n// ITicker,\n// ITimeline\n// } from '../../interface';\n// import { EditModule, findCursorIndexIgnoreLinebreak } from './edit-module';\n// import { Animate, DefaultTicker, DefaultTimeline } from '../../animate';\n\n// type UpdateType = 'input' | 'change' | 'onfocus' | 'defocus' | 'selection' | 'dispatch';\n\n// class Selection {\n// cacheSelectionStartCursorIdx: number;\n// cacheCurCursorIdx: number;\n// selectionStartCursorIdx: number;\n// curCursorIdx: number;\n// rt: IRichText;\n\n// constructor(\n// cacheSelectionStartCursorIdx: number,\n// cacheCurCursorIdx: number,\n// selectionStartCursorIdx: number,\n// curCursorIdx: number,\n// rt: IRichText\n// ) {\n// this.curCursorIdx = curCursorIdx;\n// this.selectionStartCursorIdx = selectionStartCursorIdx;\n// this.cacheCurCursorIdx = cacheCurCursorIdx;\n// this.cacheSelectionStartCursorIdx = cacheSelectionStartCursorIdx;\n// this.rt = rt;\n// }\n\n// isEmpty(): boolean {\n// return this.selectionStartCursorIdx === this.curCursorIdx;\n// }\n\n// hasFormat(key: string): boolean {\n// return this.getFormat(key) != null;\n// }\n\n// /**\n// * 获取第idx中key的值\n// * @param key\n// * @param idx cursor左侧字符的值,如果idx为-1则认为是特殊情况,为右侧字符的值\n// */\n// _getFormat(key: string, idx: number) {\n// if (!this.rt) {\n// return null;\n// }\n// const config = this.rt.attribute.textConfig as any;\n// if (idx < 0) {\n// idx = 0;\n// }\n// if (idx >= config.length) {\n// return null;\n// }\n// return config[idx][key] ?? (this.rt.attribute as any)[key];\n// }\n// getFormat(key: string): any {\n// return this.getAllFormat(key)[0];\n// }\n\n// getAllFormat(key: string): any {\n// const valSet = new Set();\n// let minCursorIdx = Math.min(this.selectionStartCursorIdx, this.curCursorIdx);\n// let maxCursorIdx = Math.max(this.selectionStartCursorIdx, this.curCursorIdx);\n// if (minCursorIdx === maxCursorIdx) {\n// return [this._getFormat(key, minCursorIdx)];\n// }\n// minCursorIdx++;\n// maxCursorIdx++;\n// const maxConfigIdx = this.rt.attribute.textConfig.length - 1;\n// if (minCursorIdx > maxConfigIdx) {\n// minCursorIdx = maxConfigIdx;\n// }\n// if (maxCursorIdx > maxConfigIdx) {\n// maxCursorIdx = maxConfigIdx;\n// }\n// for (let i = minCursorIdx; i < maxCursorIdx; i++) {\n// const val = this._getFormat(key, i);\n// val && valSet.add(val);\n// }\n// return Array.from(valSet.values());\n// }\n// }\n\n// export const FORMAT_TEXT_COMMAND = 'FORMAT_TEXT_COMMAND';\n// export const FORMAT_ELEMENT_COMMAND = 'FORMAT_ELEMENT_COMMAND';\n// export class RichTextEditPlugin implements IPlugin {\n// name: 'RichTextEditPlugin' = 'RichTextEditPlugin';\n// activeEvent: 'onRegister' = 'onRegister';\n// pluginService: IPluginService;\n// _uid: number = Generator.GenAutoIncrementId();\n// key: string = this.name + this._uid;\n// editing: boolean = false;\n// editLine: ILine;\n// editBg: IGroup;\n// pointerDown: boolean = false;\n// // 用于selection中保存上一次click时候的位置\n// lastPoint?: IPointLike;\n// editModule: EditModule;\n// currRt: IRichText;\n\n// // 当前的cursor信息\n// // 0.1为第一个字符右侧, -0.1为第一个字符左侧\n// // 1.1为第二个字符右侧,0.9为第二个字符左侧\n// curCursorIdx: number;\n// selectionStartCursorIdx: number;\n\n// commandCbs: Map<string, Array<(payload: any, p: RichTextEditPlugin) => void>>;\n// updateCbs: Array<(type: UpdateType, p: RichTextEditPlugin) => void>;\n\n// ticker: ITicker;\n// timeline: ITimeline;\n\n// // 富文本有align或者baseline的时候,需要对光标做偏移\n// protected declare deltaX: number;\n// protected declare deltaY: number;\n\n// constructor() {\n// this.commandCbs = new Map();\n// this.commandCbs.set(FORMAT_TEXT_COMMAND, [this.formatTextCommandCb]);\n// this.updateCbs = [];\n// this.timeline = new DefaultTimeline();\n// this.ticker = new DefaultTicker([this.timeline]);\n// this.deltaX = 0;\n// this.deltaY = 0;\n// }\n\n// static CreateSelection(rt: IRichText) {\n// if (!rt) {\n// return null;\n// }\n// const { textConfig = [] } = rt.attribute;\n// return new Selection(\n// -1,\n// textConfig.length - 1,\n// findCursorIndexIgnoreLinebreak(textConfig, -1),\n// findCursorIndexIgnoreLinebreak(textConfig, textConfig.length - 1),\n// rt\n// );\n// }\n\n// /**\n// * 获取当前选择的区间范围\n// * @param defaultAll 如果force为true,又没有选择,则认为选择了所有然后进行匹配,如果为false,则认为什么都没有选择,返回null\n// * @returns\n// */\n// getSelection(defaultAll: boolean = false) {\n// if (!this.currRt) {\n// return null;\n// }\n// if (\n// this.selectionStartCursorIdx != null &&\n// this.curCursorIdx != null\n// // this.selectionStartCursorIdx !== this.curCursorIdx &&\n// ) {\n// return new Selection(\n// this.selectionStartCursorIdx,\n// this.curCursorIdx,\n// findCursorIndexIgnoreLinebreak(this.currRt.attribute.textConfig, this.selectionStartCursorIdx),\n// findCursorIndexIgnoreLinebreak(this.currRt.attribute.textConfig, this.curCursorIdx),\n// this.currRt\n// );\n// } else if (defaultAll) {\n// return RichTextEditPlugin.CreateSelection(this.currRt);\n// }\n// return null;\n// }\n\n// /* command */\n// formatTextCommandCb(payload: string, p: RichTextEditPlugin) {\n// const rt = p.currRt;\n// if (!rt) {\n// return;\n// }\n// const selectionData = p.getSelection();\n// if (!selectionData) {\n// return;\n// }\n// const { selectionStartCursorIdx, curCursorIdx } = selectionData;\n// const minCursorIdx = Math.min(selectionStartCursorIdx, curCursorIdx);\n// const maxCursorIdx = Math.max(selectionStartCursorIdx, curCursorIdx);\n// const config = rt.attribute.textConfig.slice(minCursorIdx + 1, maxCursorIdx + 1);\n// if (payload === 'bold') {\n// config.forEach((item: IRichTextParagraphCharacter) => (item.fontWeight = 'bold'));\n// } else if (payload === 'italic') {\n// config.forEach((item: IRichTextParagraphCharacter) => (item.fontStyle = 'italic'));\n// } else if (payload === 'underline') {\n// config.forEach((item: IRichTextParagraphCharacter) => (item.underline = true));\n// } else if (payload === 'lineThrough') {\n// config.forEach((item: IRichTextParagraphCharacter) => (item.lineThrough = true));\n// } else if (isObject(payload)) {\n// config.forEach((item: IRichTextParagraphCharacter) => merge(item, payload));\n// }\n// rt.setAttributes(rt.attribute);\n// }\n\n// dispatchCommand(command: string, payload: any) {\n// const cbs = this.commandCbs.get(command);\n// cbs && cbs.forEach(cb => cb(payload, this));\n// this.updateCbs.forEach(cb => cb('dispatch', this));\n// }\n\n// registerCommand(command: string, cb: (payload: any, p: RichTextEditPlugin) => void) {\n// const cbs: Array<(payload: any, p: RichTextEditPlugin) => void> = this.commandCbs.get(command) || [];\n// cbs.push(cb);\n// }\n\n// registerUpdateListener(cb: (type: UpdateType, p: RichTextEditPlugin) => void) {\n// const cbs = this.updateCbs || [];\n// cbs.push(cb);\n// }\n\n// activate(context: IPluginService): void {\n// this.pluginService = context;\n// this.editModule = new EditModule();\n// // context.stage.on('click', this.handleClick);\n// context.stage.on('pointermove', this.handleMove);\n// context.stage.on('pointerdown', this.handlePointerDown);\n// context.stage.on('pointerup', this.handlePointerUp);\n// context.stage.on('pointerleave', this.handlePointerUp);\n\n// this.editModule.onInput(this.handleInput);\n// this.editModule.onChange(this.handleChange);\n// }\n\n// handleInput = (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, orient: 'left' | 'right') => {\n// // 修改cursor的位置,但并不同步,因为这可能是临时的\n// const p = this.getPointByColumnIdx(cursorIdx, rt, orient);\n// this.hideSelection();\n// this.setCursor(p.x, p.y1, p.y2);\n// this.updateCbs.forEach(cb => cb('input', this));\n// };\n// handleChange = (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, orient: 'left' | 'right') => {\n// // 修改cursor的位置,并同步到editModule\n// const p = this.getPointByColumnIdx(cursorIdx, rt, orient);\n// this.curCursorIdx = cursorIdx;\n// this.selectionStartCursorIdx = cursorIdx;\n// this.setCursorAndTextArea(p.x, p.y1, p.y2, rt);\n// this.hideSelection();\n// this.updateCbs.forEach(cb => cb('change', this));\n// };\n\n// handleMove = (e: PointerEvent) => {\n// if (!this.isRichtext(e)) {\n// return;\n// }\n// this.currRt = e.target as IRichText;\n// this.handleEnter(e);\n// (e.target as any).once('pointerleave', this.handleLeave);\n\n// this.showSelection(e);\n// };\n\n// showSelection(e: PointerEvent) {\n// const cache = (e.target as IRichText).getFrameCache();\n// if (!(cache && this.editBg)) {\n// return;\n// }\n// if (this.pointerDown) {\n// let p0 = this.lastPoint;\n// // 计算p1在字符中的位置\n// let p1 = this.getEventPosition(e);\n// let line1Info = this.getLineByPoint(cache, p1);\n// if (!line1Info) {\n// return;\n// }\n// const column1 = this.getColumnByLinePoint(line1Info, p1);\n// const y1 = line1Info.top;\n// const y2 = line1Info.top + line1Info.height;\n// let x = column1.left + column1.width;\n// let cursorIndex = this.getColumnIndex(cache, column1);\n// if (p1.x < column1.left + column1.width / 2) {\n// x = column1.left;\n// cursorIndex -= 1;\n// }\n// p1.x = x;\n// p1.y = (y1 + y2) / 2;\n// let line0Info = this.getLineByPoint(cache, p0);\n// if (p0.y > p1.y || (p0.y === p1.y && p0.x > p1.x)) {\n// [p0, p1] = [p1, p0];\n// [line1Info, line0Info] = [line0Info, line1Info];\n// }\n\n// this.editBg.removeAllChild();\n// if (line0Info === line1Info) {\n// // const column0 = this.getColumnByLinePoint(line0Info, p0);\n// this.editBg.setAttributes({\n// x: p0.x,\n// y: line0Info.top,\n// width: p1.x - p0.x,\n// height: line0Info.height,\n// fill: '#336df4',\n// fillOpacity: 0.2\n// });\n// } else {\n// this.editBg.setAttributes({ x: 0, y: line0Info.top, width: 0, height: 0 });\n// const startIdx = cache.lines.findIndex(item => item === line0Info);\n// const endIdx = cache.lines.findIndex(item => item === line1Info);\n// let y = 0;\n// for (let i = startIdx; i <= endIdx; i++) {\n// const line = cache.lines[i];\n// if (i === startIdx) {\n// const p = line.paragraphs[line.paragraphs.length - 1];\n// this.editBg.add(\n// createRect({\n// x: p0.x,\n// y,\n// width: p.left + p.width - p0.x,\n// height: line.height,\n// fill: '#336df4',\n// fillOpacity: 0.2\n// })\n// );\n// } else if (i === endIdx) {\n// const p = line.paragraphs[0];\n// this.editBg.add(\n// createRect({\n// x: p.left,\n// y,\n// width: p1.x - p.left,\n// height: line.height,\n// fill: '#336df4',\n// fillOpacity: 0.2\n// })\n// );\n// } else {\n// const p0 = line.paragraphs[0];\n// const p1 = line.paragraphs[line.paragraphs.length - 1];\n// this.editBg.add(\n// createRect({\n// x: p0.left,\n// y,\n// width: p1.left + p1.width - p0.left,\n// height: line.height,\n// fill: '#336df4',\n// fillOpacity: 0.2\n// })\n// );\n// }\n// y += line.height;\n// }\n// }\n\n// this.curCursorIdx = cursorIndex;\n// this.setCursorAndTextArea(x, y1 + 2, y2 - 2, e.target as IRichText);\n\n// this.applyUpdate();\n// this.updateCbs.forEach(cb => cb('selection', this));\n// }\n// }\n\n// hideSelection() {\n// if (this.editBg) {\n// this.editBg.removeAllChild();\n// this.editBg.setAttributes({ fill: 'transparent' });\n// }\n// }\n\n// handlePointerDown = (e: PointerEvent) => {\n// if (this.editing) {\n// this.onFocus(e);\n// } else {\n// this.deFocus(e);\n// }\n// this.applyUpdate();\n// this.pointerDown = true;\n// this.updateCbs.forEach(cb => cb(this.editing ? 'onfocus' : 'defocus', this));\n// console.log(this.selectionStartCursorIdx);\n// };\n// handlePointerUp = (e: PointerEvent) => {\n// this.pointerDown = false;\n// };\n\n// forceFocus(e: PointerEvent) {\n// this.handleEnter(e);\n// this.handlePointerDown(e);\n// this.handlePointerUp(e);\n// }\n\n// // 鼠标进入\n// handleEnter = (e: PointerEvent) => {\n// this.editing = true;\n// this.pluginService.stage.setCursor('text');\n// };\n\n// // 鼠标离开\n// handleLeave = (e: PointerEvent) => {\n// this.editing = false;\n// this.pluginService.stage.setCursor('default');\n// };\n\n// isRichtext(e: PointerEvent) {\n// return !!(e.target && (e.target as any).type === 'richtext' && (e.target as any).attribute.editable);\n// }\n\n// protected getEventPosition(e: PointerEvent): IPointLike {\n// const p = this.pluginService.stage.eventPointTransform(e);\n\n// const p1 = { x: 0, y: 0 };\n// (e.target as IRichText).globalTransMatrix.transformPoint(p, p1);\n// p1.x -= this.deltaX;\n// p1.y -= this.deltaY;\n// return p1;\n// }\n\n// protected getLineByPoint(cache: IRichTextFrame, p1: IPointLike): IRichTextLine {\n// let lineInfo = cache.lines[0];\n// for (let i = 0; i < cache.lines.length; i++) {\n// if (lineInfo.top <= p1.y && lineInfo.top + lineInfo.height >= p1.y) {\n// break;\n// }\n// lineInfo = cache.lines[i + 1];\n// }\n\n// return lineInfo;\n// }\n// protected getColumnByLinePoint(lineInfo: IRichTextLine, p1: IPointLike): IRichTextParagraph | IRichTextIcon {\n// let columnInfo = lineInfo.paragraphs[0];\n// for (let i = 0; i < lineInfo.paragraphs.length; i++) {\n// if (columnInfo.left <= p1.x && columnInfo.left + columnInfo.width >= p1.x) {\n// break;\n// }\n// columnInfo = lineInfo.paragraphs[i];\n// }\n\n// return columnInfo;\n// }\n\n// onFocus(e: PointerEvent) {\n// this.deFocus(e);\n// this.currRt = e.target as IRichText;\n\n// // 添加shadowGraphic\n// const target = e.target as IRichText;\n// RichTextEditPlugin.tryUpdateRichtext(target);\n// const shadowRoot = target.attachShadow();\n// const cache = target.getFrameCache();\n// if (!cache) {\n// return;\n// }\n\n// this.deltaX = 0;\n// this.deltaY = 0;\n// const height = cache.actualHeight;\n// const width = cache.lines.reduce((w, item) => Math.max(w, item.actualWidth), 0);\n// if (cache.globalAlign === 'center') {\n// this.deltaX = -width / 2;\n// } else if (cache.globalAlign === 'right') {\n// this.deltaX = -width;\n// }\n// if (cache.globalBaseline === 'middle') {\n// this.deltaY = -height / 2;\n// } else if (cache.globalBaseline === 'bottom') {\n// this.deltaY = -height;\n// }\n\n// shadowRoot.setAttributes({ shadowRootIdx: -1, x: this.deltaX, y: this.deltaY });\n// if (!this.editLine) {\n// const line = createLine({ x: 0, y: 0, lineWidth: 1, stroke: 'black' });\n// // 不使用stage的Ticker,避免影响其他的动画以及受到其他动画影响\n// const animate = line.animate();\n// animate.setTimeline(this.timeline);\n// animate.to({ opacity: 1 }, 10, 'linear').wait(700).to({ opacity: 0 }, 10, 'linear').wait(700).loop(Infinity);\n// this.editLine = line;\n// this.ticker.start(true);\n\n// const g = createGroup({ x: 0, y: 0, width: 0, height: 0 });\n// this.editBg = g;\n// shadowRoot.add(this.editLine);\n// shadowRoot.add(this.editBg);\n// }\n\n// const p1 = this.getEventPosition(e);\n\n// const lineInfo = this.getLineByPoint(cache, p1);\n\n// if (lineInfo) {\n// const columnInfo = this.getColumnByLinePoint(lineInfo, p1);\n// if (!columnInfo) {\n// return;\n// }\n\n// let y1 = lineInfo.top;\n// let y2 = lineInfo.top + lineInfo.height;\n// let x = columnInfo.left + columnInfo.width;\n// y1 += 2;\n// y2 -= 2;\n// let cursorIndex = this.getColumnIndex(cache, columnInfo);\n// if (p1.x < columnInfo.left + columnInfo.width / 2) {\n// x = columnInfo.left;\n// cursorIndex -= 1;\n// }\n\n// this.lastPoint = { x, y: (y1 + y2) / 2 };\n\n// this.curCursorIdx = cursorIndex;\n// this.selectionStartCursorIdx = cursorIndex;\n// this.setCursorAndTextArea(x, y1, y2, target);\n// }\n// }\n\n// protected getPointByColumnIdx(idx: number, rt: IRichText, orient: 'left' | 'right') {\n// const cache = rt.getFrameCache();\n// const column = this.getColumnByIndex(cache, idx);\n// const height = rt.attribute.fontSize ?? (rt.attribute.textConfig?.[0] as any)?.fontSize;\n// if (!column) {\n// return {\n// x: 0,\n// y1: 0,\n// y2: height\n// };\n// }\n// const { lineInfo, columnInfo } = column;\n// let y1 = lineInfo.top;\n// let y2 = lineInfo.top + lineInfo.height;\n// const x = columnInfo.left + (orient === 'left' ? 0 : columnInfo.width);\n// y1 += 2;\n// y2 -= 2;\n\n// return { x, y1, y2 };\n// }\n\n// protected getColumnIndex(cache: IRichTextFrame, cInfo: IRichTextParagraph | IRichTextIcon) {\n// // TODO 认为都是单个字符拆分的\n// let inputIndex = -1;\n// for (let i = 0; i < cache.lines.length; i++) {\n// const line = cache.lines[i];\n// for (let j = 0; j < line.paragraphs.length; j++) {\n// inputIndex++;\n// if (cInfo === line.paragraphs[j]) {\n// return inputIndex;\n// }\n// }\n// }\n// return -1;\n// }\n// protected getColumnByIndex(\n// cache: IRichTextFrame,\n// index: number\n// ): {\n// lineInfo: IRichTextLine;\n// columnInfo: IRichTextParagraph | IRichTextIcon;\n// } | null {\n// // TODO 认为都是单个字符拆分的\n// let inputIndex = -1;\n// for (let i = 0; i < cache.lines.length; i++) {\n// const lineInfo = cache.lines[i];\n// for (let j = 0; j < lineInfo.paragraphs.length; j++) {\n// const columnInfo = lineInfo.paragraphs[j];\n// inputIndex++;\n// if (inputIndex === index) {\n// return {\n// lineInfo,\n// columnInfo\n// };\n// }\n// }\n// }\n// return null;\n// }\n\n// protected setCursorAndTextArea(x: number, y1: number, y2: number, rt: IRichText) {\n// this.editLine.setAttributes({\n// points: [\n// { x, y: y1 },\n// { x, y: y2 }\n// ]\n// });\n// const out = { x: 0, y: 0 };\n// rt.globalTransMatrix.getInverse().transformPoint({ x, y: y1 }, out);\n// // TODO 考虑stage变换\n// const { left, top } = this.pluginService.stage.window.getBoundingClientRect();\n// out.x += left;\n// out.y += top;\n\n// this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);\n// }\n// protected setCursor(x: number, y1: number, y2: number) {\n// this.editLine.setAttributes({\n// points: [\n// { x, y: y1 },\n// { x, y: y2 }\n// ]\n// });\n// }\n\n// applyUpdate() {\n// this.pluginService.stage.renderNextFrame();\n// }\n// deFocus(e: PointerEvent) {\n// const target = this.currRt as IRichText;\n// if (!target) {\n// return;\n// }\n// target.detachShadow();\n// this.currRt = null;\n// if (this.editLine) {\n// this.editLine.parent.removeChild(this.editLine);\n// this.editLine.release();\n// this.editLine = null;\n\n// this.editBg.parent.removeChild(this.editBg);\n// this.editBg.release();\n// this.editBg = null;\n// }\n// }\n\n// static splitText(text: string) {\n// // 😁这种emoji长度算两个,所以得处理一下\n// return Array.from(text);\n// }\n\n// static tryUpdateRichtext(richtext: IRichText) {\n// const cache = richtext.getFrameCache();\n// if (\n// !cache.lines.every(line =>\n// line.paragraphs.every(\n// item => !(item.text && isString(item.text) && RichTextEditPlugin.splitText(item.text).length > 1)\n// )\n// )\n// ) {\n// const tc: IRichTextCharacter[] = [];\n// richtext.attribute.textConfig.forEach((item: IRichTextParagraphCharacter) => {\n// const textList = RichTextEditPlugin.splitText(item.text.toString());\n// if (isString(item.text) && textList.length > 1) {\n// // 拆分\n// for (let i = 0; i < textList.length; i++) {\n// const t = textList[i];\n// tc.push({ ...item, text: t });\n// }\n// } else {\n// tc.push(item);\n// }\n// });\n// richtext.setAttributes({ textConfig: tc });\n// richtext.doUpdateFrameCache(tc);\n// }\n// }\n\n// onSelect() {\n// return;\n// }\n\n// deactivate(context: IPluginService): void {\n// // context.stage.off('pointerdown', this.handleClick);\n// context.stage.off('pointermove', this.handleMove);\n// context.stage.off('pointerdown', this.handlePointerDown);\n// context.stage.off('pointerup', this.handlePointerUp);\n// context.stage.off('pointerleave', this.handlePointerUp);\n// }\n\n// release() {\n// this.editModule.release();\n// }\n// }\n"]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { IPointLike } from '@visactor/vutils';
|
|
2
|
-
import type { IGroup, ILine, IPlugin, IPluginService, IRichText, IRichTextFrame, IRichTextIcon, IRichTextLine, IRichTextParagraph } from '../../interface';
|
|
2
|
+
import type { IGroup, ILine, IPlugin, IPluginService, IRichText, IRichTextFrame, IRichTextIcon, IRichTextLine, IRichTextParagraph, ITicker, ITimeline } from '../../interface';
|
|
3
3
|
import { EditModule } from './edit-module';
|
|
4
4
|
type UpdateType = 'input' | 'change' | 'onfocus' | 'defocus' | 'selection' | 'dispatch';
|
|
5
5
|
declare class Selection {
|
|
6
|
-
cacheSelectionStartCursorIdx: number;
|
|
7
|
-
cacheCurCursorIdx: number;
|
|
8
6
|
selectionStartCursorIdx: number;
|
|
9
7
|
curCursorIdx: number;
|
|
10
8
|
rt: IRichText;
|
|
11
|
-
constructor(
|
|
9
|
+
constructor(selectionStartCursorIdx: number, curCursorIdx: number, rt: IRichText);
|
|
10
|
+
isEmpty(): boolean;
|
|
12
11
|
hasFormat(key: string): boolean;
|
|
12
|
+
_getFormat(key: string, cursorIdx: number): any;
|
|
13
13
|
getFormat(key: string): any;
|
|
14
14
|
getAllFormat(key: string): any;
|
|
15
15
|
}
|
|
@@ -22,55 +22,74 @@ export declare class RichTextEditPlugin implements IPlugin {
|
|
|
22
22
|
_uid: number;
|
|
23
23
|
key: string;
|
|
24
24
|
editing: boolean;
|
|
25
|
+
pointerDown: boolean;
|
|
25
26
|
editLine: ILine;
|
|
26
27
|
editBg: IGroup;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
editModule: EditModule;
|
|
28
|
+
ticker: ITicker;
|
|
29
|
+
timeline: ITimeline;
|
|
30
30
|
currRt: IRichText;
|
|
31
31
|
curCursorIdx: number;
|
|
32
32
|
selectionStartCursorIdx: number;
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
startCursorPos?: IPointLike;
|
|
34
|
+
editModule: EditModule;
|
|
35
|
+
protected commandCbs: Map<string, Array<(payload: any, p: RichTextEditPlugin) => void>>;
|
|
36
|
+
protected updateCbs: Array<(type: UpdateType, p: RichTextEditPlugin) => void>;
|
|
37
|
+
protected deltaX: number;
|
|
38
|
+
protected deltaY: number;
|
|
39
|
+
static splitText(text: string): string[];
|
|
40
|
+
static tryUpdateRichtext(richtext: IRichText): void;
|
|
41
|
+
static CreateSelection(rt: IRichText): Selection;
|
|
35
42
|
constructor();
|
|
36
|
-
getSelection(): Selection;
|
|
37
43
|
formatTextCommandCb(payload: string, p: RichTextEditPlugin): void;
|
|
38
44
|
dispatchCommand(command: string, payload: any): void;
|
|
39
45
|
registerCommand(command: string, cb: (payload: any, p: RichTextEditPlugin) => void): void;
|
|
40
46
|
registerUpdateListener(cb: (type: UpdateType, p: RichTextEditPlugin) => void): void;
|
|
41
47
|
activate(context: IPluginService): void;
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
handleKeyDown: (e: KeyboardEvent) => void;
|
|
49
|
+
handleInput: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void;
|
|
50
|
+
handleChange: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void;
|
|
51
|
+
deactivate(context: IPluginService): void;
|
|
44
52
|
handleMove: (e: PointerEvent) => void;
|
|
45
|
-
showSelection(e: PointerEvent): void;
|
|
46
|
-
hideSelection(): void;
|
|
47
|
-
handlePointerDown: (e: PointerEvent) => void;
|
|
48
|
-
handlePointerUp: (e: PointerEvent) => void;
|
|
49
53
|
handleEnter: (e: PointerEvent) => void;
|
|
50
54
|
handleLeave: (e: PointerEvent) => void;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
protected getLineByPoint(cache: IRichTextFrame, p1: IPointLike): IRichTextLine;
|
|
54
|
-
protected getColumnByLinePoint(lineInfo: IRichTextLine, p1: IPointLike): IRichTextParagraph | IRichTextIcon;
|
|
55
|
+
handlePointerDown: (e: PointerEvent) => void;
|
|
56
|
+
handlePointerUp: (e: PointerEvent) => void;
|
|
55
57
|
onFocus(e: PointerEvent): void;
|
|
56
|
-
protected
|
|
58
|
+
protected deFocus(e: PointerEvent): void;
|
|
59
|
+
protected addAnimateToLine(line: ILine): void;
|
|
60
|
+
tryShowSelection(e: PointerEvent): void;
|
|
61
|
+
hideSelection(): void;
|
|
62
|
+
protected getLineByPoint(cache: IRichTextFrame, p1: IPointLike): IRichTextLine;
|
|
63
|
+
protected getColumnAndIndexByLinePoint(lineInfo: IRichTextLine, p1: IPointLike): {
|
|
64
|
+
columnInfo: IRichTextParagraph | IRichTextIcon;
|
|
65
|
+
delta: number;
|
|
66
|
+
};
|
|
67
|
+
protected getColumnIndex(cache: IRichTextFrame, cInfo: IRichTextParagraph | IRichTextIcon): number;
|
|
68
|
+
protected isRichtext(e: PointerEvent): boolean;
|
|
69
|
+
protected triggerRender(): void;
|
|
70
|
+
protected computeGlobalDelta(cache: IRichTextFrame): void;
|
|
71
|
+
protected getEventPosition(e: PointerEvent): IPointLike;
|
|
72
|
+
protected setCursorAndTextArea(x: number, y1: number, y2: number, rt: IRichText): void;
|
|
73
|
+
protected computedCursorPosByEvent(e: PointerEvent, cache: IRichTextFrame): {
|
|
74
|
+
x: any;
|
|
75
|
+
y1: number;
|
|
76
|
+
y2: number;
|
|
77
|
+
cursorIndex: number;
|
|
78
|
+
};
|
|
79
|
+
protected computedCursorPosByCursorIdx(cursorIdx: number, rt: IRichText): {
|
|
80
|
+
x: number;
|
|
81
|
+
y1: number;
|
|
82
|
+
y2: any;
|
|
83
|
+
} | {
|
|
57
84
|
x: any;
|
|
58
85
|
y1: number;
|
|
59
86
|
y2: number;
|
|
60
87
|
};
|
|
61
|
-
protected getColumnIndex(cache: IRichTextFrame, cInfo: IRichTextParagraph | IRichTextIcon): number;
|
|
62
88
|
protected getColumnByIndex(cache: IRichTextFrame, index: number): {
|
|
63
89
|
lineInfo: IRichTextLine;
|
|
64
90
|
columnInfo: IRichTextParagraph | IRichTextIcon;
|
|
65
91
|
} | null;
|
|
66
|
-
protected setCursorAndTextArea(x: number, y1: number, y2: number, rt: IRichText): void;
|
|
67
|
-
protected setCursor(x: number, y1: number, y2: number): void;
|
|
68
|
-
applyUpdate(): void;
|
|
69
|
-
deFocus(e: PointerEvent): void;
|
|
70
|
-
splitText(text: string): string[];
|
|
71
|
-
tryUpdateRichtext(richtext: IRichText): void;
|
|
72
|
-
onSelect(): void;
|
|
73
|
-
deactivate(context: IPluginService): void;
|
|
74
92
|
release(): void;
|
|
93
|
+
getSelection(defaultAll?: boolean): Selection;
|
|
75
94
|
}
|
|
76
95
|
export {};
|