@visactor/vrender-core 0.22.0-vstory.1 → 0.22.0-vstory.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.
- package/cjs/core/global.d.ts +0 -3
- package/cjs/core/global.js +1 -7
- package/cjs/core/global.js.map +1 -1
- package/cjs/graphic/config.js +1 -0
- package/cjs/graphic/config.js.map +1 -1
- package/cjs/graphic/graphic.d.ts +1 -1
- package/cjs/graphic/graphic.js +5 -5
- package/cjs/graphic/graphic.js.map +1 -1
- package/cjs/graphic/richtext/line.js +1 -1
- package/cjs/graphic/richtext/line.js.map +1 -1
- package/cjs/graphic/richtext/paragraph.d.ts +1 -1
- package/cjs/graphic/richtext/paragraph.js +32 -7
- package/cjs/graphic/richtext/paragraph.js.map +1 -1
- package/cjs/graphic/richtext.js +4 -1
- package/cjs/graphic/richtext.js.map +1 -1
- package/cjs/interface/global.d.ts +0 -1
- package/cjs/interface/global.js.map +1 -1
- package/cjs/interface/graphic/richText.d.ts +10 -0
- package/cjs/interface/graphic/richText.js.map +1 -1
- package/cjs/interface/graphic.d.ts +1 -1
- package/cjs/interface/graphic.js.map +1 -1
- package/cjs/plugins/builtin-plugin/edit-module.d.ts +2 -1
- package/cjs/plugins/builtin-plugin/edit-module.js +18 -13
- package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +30 -6
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +248 -74
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
- package/cjs/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
- package/cjs/render/contributions/render/contributions/image-contribution-render.js +2 -2
- package/cjs/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/draw-contribution.js +2 -1
- package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
- package/cjs/render/contributions/render/image-render.js.map +1 -1
- package/cjs/resource-loader/loader.js +1 -1
- package/cjs/resource-loader/loader.js.map +1 -1
- package/dist/index.es.js +376 -82
- package/es/core/global.d.ts +0 -3
- package/es/core/global.js +1 -8
- package/es/core/global.js.map +1 -1
- package/es/graphic/config.js +1 -0
- package/es/graphic/config.js.map +1 -1
- package/es/graphic/graphic.d.ts +1 -1
- package/es/graphic/graphic.js +5 -5
- package/es/graphic/graphic.js.map +1 -1
- package/es/graphic/richtext/line.js +1 -1
- package/es/graphic/richtext/line.js.map +1 -1
- package/es/graphic/richtext/paragraph.d.ts +1 -1
- package/es/graphic/richtext/paragraph.js +32 -7
- package/es/graphic/richtext/paragraph.js.map +1 -1
- package/es/graphic/richtext.js +4 -1
- package/es/graphic/richtext.js.map +1 -1
- package/es/interface/global.d.ts +0 -1
- package/es/interface/global.js.map +1 -1
- package/es/interface/graphic/richText.d.ts +10 -0
- package/es/interface/graphic/richText.js.map +1 -1
- package/es/interface/graphic.d.ts +1 -1
- package/es/interface/graphic.js.map +1 -1
- package/es/plugins/builtin-plugin/edit-module.d.ts +2 -1
- package/es/plugins/builtin-plugin/edit-module.js +15 -11
- package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +30 -6
- package/es/plugins/builtin-plugin/richtext-edit-plugin.js +248 -73
- package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
- package/es/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
- package/es/render/contributions/render/contributions/image-contribution-render.js +2 -2
- package/es/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
- package/es/render/contributions/render/draw-contribution.js +1 -1
- package/es/render/contributions/render/draw-contribution.js.map +1 -1
- package/es/render/contributions/render/image-render.js.map +1 -1
- package/es/resource-loader/loader.js +1 -1
- package/es/resource-loader/loader.js.map +1 -1
- package/package.json +3 -3
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: !0
|
|
5
|
-
}), exports.RichTextEditPlugin = exports.FORMAT_ELEMENT_COMMAND = exports.FORMAT_TEXT_COMMAND = void 0;
|
|
5
|
+
}), exports.RichTextEditPlugin = exports.FORMAT_ELEMENT_COMMAND = exports.FORMAT_ALL_TEXT_COMMAND = exports.FORMAT_TEXT_COMMAND = void 0;
|
|
6
6
|
|
|
7
7
|
const vutils_1 = require("@visactor/vutils"), generator_1 = require("../../common/generator"), graphic_1 = require("../../graphic"), animate_1 = require("../../animate"), edit_module_1 = require("./edit-module"), application_1 = require("../../application"), utils_1 = require("../../graphic/richtext/utils");
|
|
8
8
|
|
|
@@ -31,6 +31,7 @@ class Selection {
|
|
|
31
31
|
if (!this.rt) return null;
|
|
32
32
|
let idx = Math.round(cursorIdx);
|
|
33
33
|
const config = this.rt.attribute.textConfig;
|
|
34
|
+
if (!config.length) return null;
|
|
34
35
|
for (let i = 0; i < config.length; i++) if ("\n" !== config[i].text && (idx--, idx < 0)) return config[i][key];
|
|
35
36
|
return null !== (_a = config[Math.min(idx, config.length - 1)][key]) && void 0 !== _a ? _a : this.rt.attribute[key];
|
|
36
37
|
}
|
|
@@ -48,7 +49,8 @@ class Selection {
|
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
exports.FORMAT_TEXT_COMMAND = "FORMAT_TEXT_COMMAND", exports.
|
|
52
|
+
exports.FORMAT_TEXT_COMMAND = "FORMAT_TEXT_COMMAND", exports.FORMAT_ALL_TEXT_COMMAND = "FORMAT_ALL_TEXT_COMMAND",
|
|
53
|
+
exports.FORMAT_ELEMENT_COMMAND = "FORMAT_ELEMENT_COMMAND";
|
|
52
54
|
|
|
53
55
|
class RichTextEditPlugin {
|
|
54
56
|
static tryUpdateRichtext(richtext) {
|
|
@@ -67,17 +69,36 @@ class RichTextEditPlugin {
|
|
|
67
69
|
}
|
|
68
70
|
constructor() {
|
|
69
71
|
this.name = "RichTextEditPlugin", this.activeEvent = "onRegister", this._uid = generator_1.Generator.GenAutoIncrementId(),
|
|
70
|
-
this.key = this.name + this._uid, this.editing = !1, this.
|
|
72
|
+
this.key = this.name + this._uid, this.editing = !1, this.focusing = !1, this.pointerDown = !1,
|
|
73
|
+
this.formatTextCommandCb = (payload, p) => {
|
|
74
|
+
const rt = p.currRt;
|
|
75
|
+
if (!rt) return;
|
|
76
|
+
const selectionData = p.getSelection();
|
|
77
|
+
if (!selectionData) return;
|
|
78
|
+
const {selectionStartCursorIdx: selectionStartCursorIdx, curCursorIdx: curCursorIdx} = selectionData, minCursorIdx = Math.min(selectionStartCursorIdx, curCursorIdx), maxCursorIdx = Math.max(selectionStartCursorIdx, curCursorIdx), minConfigIdx = (0,
|
|
79
|
+
edit_module_1.findConfigIndexByCursorIdx)(rt.attribute.textConfig, minCursorIdx), maxConfigIdx = (0,
|
|
80
|
+
edit_module_1.findConfigIndexByCursorIdx)(rt.attribute.textConfig, maxCursorIdx), config = rt.attribute.textConfig.slice(minConfigIdx, maxConfigIdx);
|
|
81
|
+
this._formatTextCommand(payload, config, rt);
|
|
82
|
+
}, this.formatAllTextCommandCb = (payload, p) => {
|
|
83
|
+
const rt = p.currRt;
|
|
84
|
+
if (!rt) return;
|
|
85
|
+
const config = rt.attribute.textConfig;
|
|
86
|
+
this._formatTextCommand(payload, config, rt);
|
|
87
|
+
}, this.handleKeyDown = e => {
|
|
71
88
|
this.currRt && this.editing && (this.copyToClipboard(e) || this.fullSelection(e) || this.directKey(e));
|
|
72
89
|
}, this.handleInput = (text, isComposing, cursorIdx, rt) => {
|
|
73
|
-
this.
|
|
90
|
+
this.currRt && (this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.hideSelection(),
|
|
91
|
+
this.updateCbs.forEach((cb => cb("input", this))));
|
|
74
92
|
}, this.handleChange = (text, isComposing, cursorIdx, rt) => {
|
|
75
|
-
|
|
93
|
+
if (!this.currRt) return;
|
|
94
|
+
this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.curCursorIdx = cursorIdx,
|
|
95
|
+
this.selectionStartCursorIdx = cursorIdx;
|
|
76
96
|
const p = this.computedCursorPosByCursorIdx(cursorIdx, rt);
|
|
77
97
|
this.setCursorAndTextArea(p.x, p.y1, p.y2, rt), this.hideSelection(), this.updateCbs.forEach((cb => cb("change", this)));
|
|
78
|
-
}, this.handleFocusIn = () => {
|
|
79
|
-
|
|
80
|
-
|
|
98
|
+
}, this.handleFocusIn = () => {
|
|
99
|
+
throw new Error("不会走到这里 handleFocusIn");
|
|
100
|
+
}, this.handleFocusOut = () => {
|
|
101
|
+
throw new Error("不会走到这里 handleFocusOut");
|
|
81
102
|
}, this.handleMove = e => {
|
|
82
103
|
this.isRichtext(e) && (this.currRt = e.target, this.handleEnter(e), e.target.once("pointerleave", this.handleLeave),
|
|
83
104
|
this.tryShowSelection(e, !1));
|
|
@@ -86,27 +107,24 @@ class RichTextEditPlugin {
|
|
|
86
107
|
}, this.handleLeave = e => {
|
|
87
108
|
this.editing = !1, this.pluginService.stage.setCursor("default");
|
|
88
109
|
}, this.handlePointerDown = e => {
|
|
89
|
-
this.editing ? this.onFocus(e) : this.deFocus(), this.triggerRender(), this.pointerDown = !0,
|
|
110
|
+
this.editing ? this.onFocus(e) : this.deFocus(!0), this.triggerRender(), this.pointerDown = !0,
|
|
90
111
|
this.updateCbs.forEach((cb => cb(this.editing ? "onfocus" : "defocus", this)));
|
|
91
112
|
}, this.handlePointerUp = e => {
|
|
92
113
|
this.pointerDown = !1;
|
|
93
114
|
}, this.handleDBLClick = e => {
|
|
94
115
|
this.editing && this.tryShowSelection(e, !0);
|
|
95
116
|
}, this.commandCbs = new Map, this.commandCbs.set(exports.FORMAT_TEXT_COMMAND, [ this.formatTextCommandCb ]),
|
|
117
|
+
this.commandCbs.set(exports.FORMAT_ALL_TEXT_COMMAND, [ this.formatAllTextCommandCb ]),
|
|
96
118
|
this.updateCbs = [], this.timeline = new animate_1.DefaultTimeline, this.ticker = new animate_1.DefaultTicker([ this.timeline ]),
|
|
97
119
|
this.deltaX = 0, this.deltaY = 0;
|
|
98
120
|
}
|
|
99
|
-
|
|
100
|
-
const rt = p.currRt;
|
|
101
|
-
if (!rt) return;
|
|
102
|
-
const selectionData = p.getSelection();
|
|
103
|
-
if (!selectionData) return;
|
|
104
|
-
const {selectionStartCursorIdx: selectionStartCursorIdx, curCursorIdx: curCursorIdx} = selectionData, minCursorIdx = Math.min(selectionStartCursorIdx, curCursorIdx), maxCursorIdx = Math.max(selectionStartCursorIdx, curCursorIdx), minConfigIdx = (0,
|
|
105
|
-
edit_module_1.findConfigIndexByCursorIdx)(rt.attribute.textConfig, minCursorIdx), maxConfigIdx = (0,
|
|
106
|
-
edit_module_1.findConfigIndexByCursorIdx)(rt.attribute.textConfig, maxCursorIdx), config = rt.attribute.textConfig.slice(minConfigIdx, maxConfigIdx);
|
|
121
|
+
_formatTextCommand(payload, config, rt) {
|
|
107
122
|
"bold" === payload ? config.forEach((item => item.fontWeight = "bold")) : "italic" === payload ? config.forEach((item => item.fontStyle = "italic")) : "underline" === payload ? config.forEach((item => item.underline = !0)) : "lineThrough" === payload ? config.forEach((item => item.lineThrough = !0)) : (0,
|
|
108
123
|
vutils_1.isObject)(payload) && config.forEach((item => (0, vutils_1.merge)(item, payload))),
|
|
109
124
|
rt.setAttributes(rt.attribute);
|
|
125
|
+
const cache = rt.getFrameCache();
|
|
126
|
+
cache && (this.selectionRangeByCursorIdx(this.selectionStartCursorIdx, this.curCursorIdx, cache),
|
|
127
|
+
this.tryShowInputBounds());
|
|
110
128
|
}
|
|
111
129
|
dispatchCommand(command, payload) {
|
|
112
130
|
const cbs = this.commandCbs.get(command);
|
|
@@ -115,9 +133,17 @@ class RichTextEditPlugin {
|
|
|
115
133
|
registerCommand(command, cb) {
|
|
116
134
|
(this.commandCbs.get(command) || []).push(cb);
|
|
117
135
|
}
|
|
136
|
+
removeCommand(command, cb) {
|
|
137
|
+
const cbs = this.commandCbs.get(command) || [], idx = cbs.indexOf(cb);
|
|
138
|
+
idx > -1 && cbs.splice(idx, 1);
|
|
139
|
+
}
|
|
118
140
|
registerUpdateListener(cb) {
|
|
119
141
|
(this.updateCbs || []).push(cb);
|
|
120
142
|
}
|
|
143
|
+
removeUpdateListener(cb) {
|
|
144
|
+
const cbs = this.updateCbs || [], idx = cbs.indexOf(cb);
|
|
145
|
+
idx > -1 && cbs.splice(idx, 1);
|
|
146
|
+
}
|
|
121
147
|
activate(context) {
|
|
122
148
|
this.pluginService = context, this.editModule = new edit_module_1.EditModule, context.stage.on("pointermove", this.handleMove),
|
|
123
149
|
context.stage.on("pointerdown", this.handlePointerDown), context.stage.on("pointerup", this.handlePointerUp),
|
|
@@ -141,8 +167,10 @@ class RichTextEditPlugin {
|
|
|
141
167
|
if (!cache) return;
|
|
142
168
|
const {lines: lines} = cache, totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
|
|
143
169
|
startIdx > endIdx && ([startIdx, endIdx] = [ endIdx, startIdx ]), startIdx = Math.min(Math.max(startIdx, -.1), totalCursorCount + .1),
|
|
144
|
-
endIdx = Math.min(Math.max(endIdx, -.1), totalCursorCount + .1), this.
|
|
145
|
-
|
|
170
|
+
endIdx = Math.min(Math.max(endIdx, -.1), totalCursorCount + .1), this.selectionRangeByCursorIdx(startIdx, endIdx, cache);
|
|
171
|
+
}
|
|
172
|
+
selectionRangeByCursorIdx(startCursorIdx, endCursorIdx, cache) {
|
|
173
|
+
this.curCursorIdx = endCursorIdx, this.selectionStartCursorIdx = startCursorIdx;
|
|
146
174
|
const {x: x, y1: y1, y2: y2} = this.computedCursorPosByCursorIdx(this.selectionStartCursorIdx, this.currRt);
|
|
147
175
|
this.startCursorPos = {
|
|
148
176
|
x: x,
|
|
@@ -195,60 +223,162 @@ class RichTextEditPlugin {
|
|
|
195
223
|
}
|
|
196
224
|
return !0;
|
|
197
225
|
}
|
|
226
|
+
tryShowShadowPlaceholder() {
|
|
227
|
+
if (!this.currRt) return;
|
|
228
|
+
const shadowRoot = this.currRt.shadowRoot;
|
|
229
|
+
if (shadowRoot) {
|
|
230
|
+
const placeholder = shadowRoot.getElementsByType("richtext")[0];
|
|
231
|
+
placeholder && shadowRoot.removeChild(placeholder);
|
|
232
|
+
}
|
|
233
|
+
const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
|
|
234
|
+
if (textConfig && textConfig.length) return;
|
|
235
|
+
if (!editOptions || !editOptions.placeholder) return;
|
|
236
|
+
const {placeholder: placeholder, placeholderColor: placeholderColor = "rgba(0, 0, 0, 0.6)", placeholderFontFamily: placeholderFontFamily, placeholderFontSize: placeholderFontSize} = editOptions, shadow = this.currRt.shadowRoot || this.currRt.attachShadow();
|
|
237
|
+
this.shadowPlaceHolder = (0, graphic_1.createRichText)(Object.assign(Object.assign({}, this.currRt.attribute), {
|
|
238
|
+
x: 0,
|
|
239
|
+
y: 0,
|
|
240
|
+
angle: 0,
|
|
241
|
+
_debug_bounds: !1,
|
|
242
|
+
textConfig: [ {
|
|
243
|
+
text: placeholder,
|
|
244
|
+
fill: placeholderColor,
|
|
245
|
+
fontFamily: placeholderFontFamily,
|
|
246
|
+
fontSize: placeholderFontSize
|
|
247
|
+
} ]
|
|
248
|
+
})), shadow.add(this.shadowPlaceHolder);
|
|
249
|
+
}
|
|
250
|
+
tryShowInputBounds() {
|
|
251
|
+
if (!this.currRt || !this.focusing) return;
|
|
252
|
+
const {editOptions: editOptions = {}} = this.currRt.attribute, {boundsStrokeWhenInput: boundsStrokeWhenInput} = editOptions;
|
|
253
|
+
if (!editOptions || !boundsStrokeWhenInput) return;
|
|
254
|
+
const {attribute: attribute} = this.currRt, b = this.currRt.AABBBounds;
|
|
255
|
+
let h = b.height();
|
|
256
|
+
if (!attribute.textConfig.length && this.editLine) {
|
|
257
|
+
const {points: points} = this.editLine.attribute;
|
|
258
|
+
h = points[1].y - points[0].y;
|
|
259
|
+
}
|
|
260
|
+
this.shadowBounds = this.shadowBounds || (0, graphic_1.createRect)({}), this.shadowBounds.setAttributes({
|
|
261
|
+
x: 0,
|
|
262
|
+
y: 0,
|
|
263
|
+
width: b.width(),
|
|
264
|
+
height: h,
|
|
265
|
+
fill: !1,
|
|
266
|
+
stroke: boundsStrokeWhenInput,
|
|
267
|
+
lineWidth: 1,
|
|
268
|
+
boundsMode: "empty",
|
|
269
|
+
zIndex: -1
|
|
270
|
+
});
|
|
271
|
+
(this.currRt.shadowRoot || this.currRt.attachShadow()).add(this.shadowBounds), this.offsetLineBgAndShadowBounds();
|
|
272
|
+
}
|
|
273
|
+
trySyncPlaceholderToTextConfig() {
|
|
274
|
+
if (!this.currRt) return;
|
|
275
|
+
const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
|
|
276
|
+
if (textConfig && textConfig.length) return;
|
|
277
|
+
if (!editOptions || !editOptions.placeholder) return;
|
|
278
|
+
const {placeholder: placeholder} = editOptions;
|
|
279
|
+
this.currRt.setAttributes({
|
|
280
|
+
textConfig: [ Object.assign({
|
|
281
|
+
text: placeholder
|
|
282
|
+
}, (0, edit_module_1.getDefaultCharacterConfig)(this.currRt.attribute)) ]
|
|
283
|
+
});
|
|
284
|
+
}
|
|
198
285
|
deactivate(context) {
|
|
199
286
|
context.stage.off("pointermove", this.handleMove), context.stage.off("pointerdown", this.handlePointerDown),
|
|
200
287
|
context.stage.off("pointerup", this.handlePointerUp), context.stage.off("pointerleave", this.handlePointerUp),
|
|
201
288
|
context.stage.off("dblclick", this.handleDBLClick), application_1.application.global.addEventListener("keydown", this.handleKeyDown);
|
|
202
289
|
}
|
|
203
|
-
onFocus(e) {
|
|
204
|
-
this.deFocus(), this.
|
|
290
|
+
onFocus(e, data) {
|
|
291
|
+
this.deFocus(!1), this.focusing = !0;
|
|
205
292
|
const target = e.target;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
this.
|
|
234
|
-
x: x,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
293
|
+
if (!target || "richtext" !== target.type) return;
|
|
294
|
+
this.currRt = target, RichTextEditPlugin.tryUpdateRichtext(target);
|
|
295
|
+
const shadowRoot = target.shadowRoot || target.attachShadow(), cache = target.getFrameCache();
|
|
296
|
+
if (cache) {
|
|
297
|
+
if (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
|
|
298
|
+
shadowRootIdx: 1,
|
|
299
|
+
pickable: !1,
|
|
300
|
+
x: this.deltaX,
|
|
301
|
+
y: this.deltaY
|
|
302
|
+
}), !this.editLine) {
|
|
303
|
+
const line = (0, graphic_1.createLine)({
|
|
304
|
+
x: 0,
|
|
305
|
+
y: 0,
|
|
306
|
+
lineWidth: 1,
|
|
307
|
+
stroke: "black",
|
|
308
|
+
boundsMode: "empty"
|
|
309
|
+
});
|
|
310
|
+
this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
|
|
311
|
+
const g = (0, graphic_1.createGroup)({
|
|
312
|
+
x: 0,
|
|
313
|
+
y: 0,
|
|
314
|
+
width: 0,
|
|
315
|
+
height: 0,
|
|
316
|
+
boundsMode: "empty"
|
|
317
|
+
});
|
|
318
|
+
this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
|
|
319
|
+
}
|
|
320
|
+
if (data = data || this.computedCursorPosByEvent(e, cache)) {
|
|
321
|
+
const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
|
|
322
|
+
this.startCursorPos = {
|
|
323
|
+
x: x,
|
|
324
|
+
y: (y1 + y2) / 2
|
|
325
|
+
}, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
|
|
326
|
+
this.setCursorAndTextArea(x, y1, y2, target);
|
|
327
|
+
} else {
|
|
328
|
+
const x = 0, y1 = 0, y2 = (0, graphic_1.getRichTextBounds)(Object.assign(Object.assign({}, target.attribute), {
|
|
329
|
+
textConfig: [ {
|
|
330
|
+
text: "a"
|
|
331
|
+
} ]
|
|
332
|
+
})).height();
|
|
333
|
+
this.startCursorPos = {
|
|
334
|
+
x: x,
|
|
335
|
+
y: (y1 + y2) / 2
|
|
336
|
+
}, this.curCursorIdx = -.1, this.selectionStartCursorIdx = -.1, this.setCursorAndTextArea(x, y1, y2, target);
|
|
337
|
+
}
|
|
338
|
+
this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.currRt.addUpdateBoundTag();
|
|
238
339
|
}
|
|
239
340
|
}
|
|
240
|
-
|
|
341
|
+
offsetLineBgAndShadowBounds() {
|
|
342
|
+
const rt = this.currRt, {textBaseline: textBaseline} = rt.attribute;
|
|
343
|
+
let b, dy = 0, attr = rt.attribute;
|
|
344
|
+
"middle" !== textBaseline && "bottom" !== textBaseline || (attr.textConfig.length || (attr = Object.assign(Object.assign({}, attr), {
|
|
345
|
+
textConfig: [ {
|
|
346
|
+
text: "a"
|
|
347
|
+
} ]
|
|
348
|
+
})), b = (0, graphic_1.getRichTextBounds)(attr)), "middle" === textBaseline ? dy = -b.height() / 2 : "bottom" === textBaseline && (dy = -b.height()),
|
|
349
|
+
this.editLine && this.editLine.setAttributes({
|
|
350
|
+
dy: dy
|
|
351
|
+
}), this.editBg && this.editBg.setAttributes({
|
|
352
|
+
dy: dy
|
|
353
|
+
}), this.shadowBounds && this.shadowBounds.setAttributes({
|
|
354
|
+
dy: dy
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
deFocus(trulyDeFocus = !1) {
|
|
241
358
|
const target = this.currRt;
|
|
242
|
-
|
|
243
|
-
this.
|
|
244
|
-
|
|
359
|
+
if (!target) return;
|
|
360
|
+
trulyDeFocus && (this.trySyncPlaceholderToTextConfig(), target.detachShadow());
|
|
361
|
+
const currRt = this.currRt;
|
|
362
|
+
this.currRt = null, this.editLine && (this.editLine.parent && this.editLine.parent.removeChild(this.editLine),
|
|
363
|
+
this.editLine.release(), this.editLine = null, this.editBg.parent && this.editBg.parent.removeChild(this.editBg),
|
|
364
|
+
this.editBg.release(), this.editBg = null), trulyDeFocus && (this.shadowBounds && (this.shadowBounds.parent && this.shadowBounds.parent.removeChild(this.shadowBounds),
|
|
365
|
+
this.shadowBounds.release(), this.shadowBounds = null), this.shadowPlaceHolder && (this.shadowPlaceHolder.parent && this.shadowPlaceHolder.parent.removeChild(this.shadowPlaceHolder),
|
|
366
|
+
this.shadowPlaceHolder.release(), this.shadowPlaceHolder = null)), this.focusing = !1;
|
|
367
|
+
const textConfig = currRt.attribute.textConfig;
|
|
368
|
+
let lastConfig = textConfig[textConfig.length - 1], cleared = !1;
|
|
369
|
+
for (;lastConfig && "\n" === lastConfig.text; ) textConfig.pop(), lastConfig = textConfig[textConfig.length - 1],
|
|
370
|
+
cleared = !0;
|
|
371
|
+
cleared && currRt.setAttributes({
|
|
372
|
+
textConfig: textConfig
|
|
373
|
+
});
|
|
245
374
|
}
|
|
246
375
|
addAnimateToLine(line) {
|
|
247
376
|
line.animates && line.animates.forEach((animate => {
|
|
248
377
|
animate.stop(), animate.release();
|
|
249
378
|
}));
|
|
250
|
-
|
|
251
|
-
|
|
379
|
+
line.animate({
|
|
380
|
+
timeline: this.timeline
|
|
381
|
+
}).to({
|
|
252
382
|
opacity: 1
|
|
253
383
|
}, 10, "linear").wait(700).to({
|
|
254
384
|
opacity: 0
|
|
@@ -334,7 +464,7 @@ class RichTextEditPlugin {
|
|
|
334
464
|
y += line.height;
|
|
335
465
|
}
|
|
336
466
|
}
|
|
337
|
-
this.setCursorAndTextArea(currCursorData.x, currCursorData.y1
|
|
467
|
+
this.setCursorAndTextArea(currCursorData.x, currCursorData.y1, currCursorData.y2, this.currRt),
|
|
338
468
|
this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
|
|
339
469
|
}
|
|
340
470
|
hideSelection() {
|
|
@@ -389,8 +519,15 @@ class RichTextEditPlugin {
|
|
|
389
519
|
x: 0,
|
|
390
520
|
y: 0
|
|
391
521
|
};
|
|
392
|
-
|
|
393
|
-
|
|
522
|
+
e.target.globalTransMatrix.transformPoint(p, p1), p1.x -= this.deltaX, p1.y -= this.deltaY;
|
|
523
|
+
const rt = this.currRt, {textBaseline: textBaseline} = rt.attribute;
|
|
524
|
+
let dy = 0;
|
|
525
|
+
if ("middle" === textBaseline) {
|
|
526
|
+
dy = (0, graphic_1.getRichTextBounds)(rt.attribute).height() / 2;
|
|
527
|
+
} else if ("bottom" === textBaseline) {
|
|
528
|
+
dy = (0, graphic_1.getRichTextBounds)(rt.attribute).height();
|
|
529
|
+
}
|
|
530
|
+
return p1.y += dy, p1;
|
|
394
531
|
}
|
|
395
532
|
setCursorAndTextArea(x, y1, y2, rt) {
|
|
396
533
|
this.editLine.setAttributes({
|
|
@@ -411,15 +548,14 @@ class RichTextEditPlugin {
|
|
|
411
548
|
y: y1
|
|
412
549
|
}, out);
|
|
413
550
|
const {left: left, top: top} = this.pluginService.stage.window.getBoundingClientRect();
|
|
414
|
-
out.x += left, out.y += top, this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
|
|
551
|
+
out.x += left, out.y += top, this.offsetLineBgAndShadowBounds(), this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
|
|
415
552
|
}
|
|
416
553
|
computedCursorPosByEvent(e, cache) {
|
|
417
554
|
const p1 = this.getEventPosition(e), lineInfo = this.getLineByPoint(cache, p1);
|
|
418
555
|
if (!lineInfo) return;
|
|
419
556
|
const {columnInfo: columnInfo, delta: delta} = this.getColumnAndIndexByLinePoint(lineInfo, p1);
|
|
420
557
|
if (!columnInfo) return;
|
|
421
|
-
|
|
422
|
-
y1 += 2, y2 -= 2;
|
|
558
|
+
const y1 = lineInfo.top, y2 = lineInfo.top + lineInfo.height;
|
|
423
559
|
let cursorIndex = this.getColumnIndex(cache, columnInfo);
|
|
424
560
|
cursorIndex += delta;
|
|
425
561
|
return {
|
|
@@ -434,17 +570,31 @@ class RichTextEditPlugin {
|
|
|
434
570
|
computedCursorPosByCursorIdx(cursorIdx, rt) {
|
|
435
571
|
var _a, _b, _c;
|
|
436
572
|
const idx = Math.round(cursorIdx), leftRight = cursorIdx - idx, cache = rt.getFrameCache(), column = this.getColumnByIndex(cache, idx), height = null !== (_a = rt.attribute.fontSize) && void 0 !== _a ? _a : null === (_c = null === (_b = rt.attribute.textConfig) || void 0 === _b ? void 0 : _b[0]) || void 0 === _c ? void 0 : _c.fontSize;
|
|
437
|
-
if (!column)
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
573
|
+
if (!column) {
|
|
574
|
+
if (!cache.lines.length) {
|
|
575
|
+
return {
|
|
576
|
+
x: 0,
|
|
577
|
+
y1: 0,
|
|
578
|
+
y2: (0, graphic_1.getRichTextBounds)(Object.assign(Object.assign({}, rt.attribute), {
|
|
579
|
+
textConfig: [ {
|
|
580
|
+
text: "a"
|
|
581
|
+
} ]
|
|
582
|
+
})).height()
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
return {
|
|
586
|
+
x: 0,
|
|
587
|
+
y1: 0,
|
|
588
|
+
y2: height
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
const {lineInfo: lineInfo, columnInfo: columnInfo} = column, y1 = lineInfo.top, y2 = lineInfo.top + lineInfo.height;
|
|
592
|
+
return {
|
|
445
593
|
x: columnInfo.left + (leftRight < 0 ? 0 : columnInfo.width),
|
|
446
594
|
y1: y1,
|
|
447
|
-
y2: y2
|
|
595
|
+
y2: y2,
|
|
596
|
+
lineInfo: lineInfo,
|
|
597
|
+
columnInfo: columnInfo
|
|
448
598
|
};
|
|
449
599
|
}
|
|
450
600
|
getColumnByIndex(cache, index) {
|
|
@@ -467,6 +617,30 @@ class RichTextEditPlugin {
|
|
|
467
617
|
getSelection(defaultAll = !1) {
|
|
468
618
|
return this.currRt ? null != this.selectionStartCursorIdx && null != this.curCursorIdx ? new Selection(this.selectionStartCursorIdx, this.curCursorIdx, this.currRt) : defaultAll ? RichTextEditPlugin.CreateSelection(this.currRt) : null : null;
|
|
469
619
|
}
|
|
620
|
+
forceFocus(params) {
|
|
621
|
+
const {target: target, e: e, cursorIndex: cursorIndex} = params;
|
|
622
|
+
target && (this.currRt = target, e ? this._forceFocusByEvent(e) : this._forceFocusByCursorIndex(null != cursorIndex ? cursorIndex : -.1));
|
|
623
|
+
}
|
|
624
|
+
_forceFocusByEvent(e) {
|
|
625
|
+
this.handleEnter(e), this.handlePointerDown(e), this.handlePointerUp(e);
|
|
626
|
+
}
|
|
627
|
+
_forceFocusByCursorIndex(cursorIndex) {
|
|
628
|
+
const richtext = this.currRt;
|
|
629
|
+
if (!richtext) return;
|
|
630
|
+
let x = 0, y1 = 0, y2 = 2, lineInfo = null, columnInfo = null;
|
|
631
|
+
const data = this.computedCursorPosByCursorIdx(cursorIndex, richtext);
|
|
632
|
+
x = data.x, y1 = data.y1, y2 = data.y2, lineInfo = data.lineInfo, columnInfo = data.columnInfo,
|
|
633
|
+
this.onFocus({
|
|
634
|
+
target: this.currRt
|
|
635
|
+
}, {
|
|
636
|
+
x: x,
|
|
637
|
+
y1: y1,
|
|
638
|
+
y2: y2,
|
|
639
|
+
cursorIndex: cursorIndex,
|
|
640
|
+
lineInfo: lineInfo,
|
|
641
|
+
columnInfo: columnInfo
|
|
642
|
+
});
|
|
643
|
+
}
|
|
470
644
|
}
|
|
471
645
|
|
|
472
646
|
exports.RichTextEditPlugin = RichTextEditPlugin;
|