@visactor/vrender-core 0.22.0-vstory.11 → 0.22.0-vstory.14
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/animate.js +1 -1
- package/cjs/animate/animate.js.map +1 -1
- package/cjs/animate/custom-animate.js +2 -1
- package/cjs/animate/custom-animate.js.map +1 -1
- package/cjs/common/inversify/annotation/optional.d.ts +2 -0
- package/cjs/common/inversify/annotation/optional.js +14 -0
- package/cjs/common/inversify/annotation/optional.js.map +1 -0
- package/cjs/common/inversify/container.js +9 -6
- package/cjs/common/inversify/container.js.map +1 -1
- package/cjs/common/render-area.d.ts +0 -4
- package/cjs/common/render-area.js +16 -76
- package/cjs/common/render-area.js.map +1 -1
- package/cjs/common/render-curve.d.ts +1 -1
- package/cjs/common/render-curve.js.map +1 -1
- package/cjs/common/segment/step.js +1 -1
- package/cjs/common/segment/step.js.map +1 -1
- package/cjs/core/contributions/textMeasure/AtextMeasure.js +10 -0
- package/cjs/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
- package/cjs/core/global.d.ts +3 -0
- package/cjs/core/global.js +7 -1
- package/cjs/core/global.js.map +1 -1
- package/cjs/graphic/bounds.d.ts +2 -2
- package/cjs/graphic/bounds.js.map +1 -1
- package/cjs/graphic/config.js +2 -0
- package/cjs/graphic/config.js.map +1 -1
- package/cjs/graphic/graphic.js +4 -4
- package/cjs/graphic/graphic.js.map +1 -1
- package/cjs/graphic/group.d.ts +0 -1
- package/cjs/graphic/group.js +0 -5
- package/cjs/graphic/group.js.map +1 -1
- package/cjs/graphic/line.js +2 -2
- package/cjs/graphic/line.js.map +1 -1
- package/cjs/graphic/richtext/line.js +3 -13
- package/cjs/graphic/richtext/line.js.map +1 -1
- package/cjs/graphic/richtext/paragraph.d.ts +3 -9
- package/cjs/graphic/richtext/paragraph.js +33 -20
- package/cjs/graphic/richtext/paragraph.js.map +1 -1
- package/cjs/graphic/richtext/utils.d.ts +1 -1
- package/cjs/graphic/richtext/utils.js +6 -7
- package/cjs/graphic/richtext/utils.js.map +1 -1
- package/cjs/graphic/richtext.d.ts +0 -1
- package/cjs/graphic/richtext.js +25 -14
- package/cjs/graphic/richtext.js.map +1 -1
- package/cjs/interface/color.js.map +1 -1
- package/cjs/interface/global.d.ts +1 -0
- package/cjs/interface/global.js.map +1 -1
- package/cjs/interface/graphic/richText.d.ts +2 -1
- package/cjs/interface/graphic/richText.js.map +1 -1
- package/cjs/interface/graphic.d.ts +3 -2
- package/cjs/interface/graphic.js.map +1 -1
- package/cjs/plugins/builtin-plugin/edit-module.js +10 -5
- package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +10 -7
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +190 -159
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
- package/cjs/render/contributions/render/area-render.d.ts +1 -1
- package/cjs/render/contributions/render/area-render.js +16 -36
- package/cjs/render/contributions/render/area-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/base-contribution-render.d.ts +1 -0
- package/cjs/render/contributions/render/contributions/base-contribution-render.js +7 -3
- package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/group-contribution-render.js +2 -1
- package/cjs/render/contributions/render/contributions/group-contribution-render.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/contributions/text-contribution-render.js +3 -2
- package/cjs/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/draw-contribution.js +1 -0
- package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
- package/cjs/render/contributions/render/image-render.js.map +1 -1
- package/cjs/render/contributions/render/line-render.js +9 -31
- package/cjs/render/contributions/render/line-render.js.map +1 -1
- package/cjs/resource-loader/loader.d.ts +2 -2
- package/cjs/resource-loader/loader.js +1 -1
- package/cjs/resource-loader/loader.js.map +1 -1
- package/dist/index.es.js +328 -501
- package/es/animate/animate.js +4 -3
- package/es/animate/animate.js.map +1 -1
- package/es/animate/custom-animate.js +2 -1
- package/es/animate/custom-animate.js.map +1 -1
- package/es/common/inversify/annotation/optional.d.ts +2 -0
- package/es/common/inversify/annotation/optional.js +12 -0
- package/es/common/inversify/annotation/optional.js.map +1 -0
- package/es/common/inversify/container.js +9 -6
- package/es/common/inversify/container.js.map +1 -1
- package/es/common/render-area.d.ts +0 -4
- package/es/common/render-area.js +16 -76
- package/es/common/render-area.js.map +1 -1
- package/es/common/render-curve.d.ts +1 -1
- package/es/common/render-curve.js.map +1 -1
- package/es/common/segment/step.js +1 -1
- package/es/common/segment/step.js.map +1 -1
- package/es/core/contributions/textMeasure/AtextMeasure.js +10 -0
- package/es/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
- package/es/core/global.d.ts +3 -0
- package/es/core/global.js +8 -1
- package/es/core/global.js.map +1 -1
- package/es/graphic/bounds.d.ts +2 -2
- package/es/graphic/bounds.js.map +1 -1
- package/es/graphic/config.js +2 -0
- package/es/graphic/config.js.map +1 -1
- package/es/graphic/graphic.js +5 -5
- package/es/graphic/graphic.js.map +1 -1
- package/es/graphic/group.d.ts +0 -1
- package/es/graphic/group.js +0 -5
- package/es/graphic/group.js.map +1 -1
- package/es/graphic/line.js +2 -2
- package/es/graphic/line.js.map +1 -1
- package/es/graphic/richtext/line.js +3 -13
- package/es/graphic/richtext/line.js.map +1 -1
- package/es/graphic/richtext/paragraph.d.ts +3 -9
- package/es/graphic/richtext/paragraph.js +33 -20
- package/es/graphic/richtext/paragraph.js.map +1 -1
- package/es/graphic/richtext/utils.d.ts +1 -1
- package/es/graphic/richtext/utils.js +6 -7
- package/es/graphic/richtext/utils.js.map +1 -1
- package/es/graphic/richtext.d.ts +0 -1
- package/es/graphic/richtext.js +22 -13
- package/es/graphic/richtext.js.map +1 -1
- package/es/interface/color.js.map +1 -1
- package/es/interface/global.d.ts +1 -0
- package/es/interface/global.js.map +1 -1
- package/es/interface/graphic/richText.d.ts +2 -1
- package/es/interface/graphic/richText.js.map +1 -1
- package/es/interface/graphic.d.ts +3 -2
- package/es/interface/graphic.js.map +1 -1
- package/es/plugins/builtin-plugin/edit-module.js +10 -5
- package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +10 -7
- package/es/plugins/builtin-plugin/richtext-edit-plugin.js +190 -159
- package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
- package/es/render/contributions/render/area-render.d.ts +1 -1
- package/es/render/contributions/render/area-render.js +16 -36
- package/es/render/contributions/render/area-render.js.map +1 -1
- package/es/render/contributions/render/contributions/base-contribution-render.d.ts +1 -0
- package/es/render/contributions/render/contributions/base-contribution-render.js +7 -3
- package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
- package/es/render/contributions/render/contributions/group-contribution-render.js +2 -1
- package/es/render/contributions/render/contributions/group-contribution-render.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/contributions/text-contribution-render.js +3 -2
- package/es/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
- package/es/render/contributions/render/draw-contribution.js +3 -2
- package/es/render/contributions/render/draw-contribution.js.map +1 -1
- package/es/render/contributions/render/image-render.js.map +1 -1
- package/es/render/contributions/render/line-render.js +9 -31
- package/es/render/contributions/render/line-render.js.map +1 -1
- package/es/resource-loader/loader.d.ts +2 -2
- package/es/resource-loader/loader.js +1 -1
- package/es/resource-loader/loader.js.map +1 -1
- package/package.json +1 -1
|
@@ -40,15 +40,16 @@ class Selection {
|
|
|
40
40
|
for (let i = 0; i < config.length; i++) if ("\n" !== config[i].text && (idx--, idx < 0)) return config[i][key];
|
|
41
41
|
return null !== (_a = config[Math.min(idx, config.length - 1)][key]) && void 0 !== _a ? _a : this.rt.attribute[key];
|
|
42
42
|
}
|
|
43
|
-
getFormat(key) {
|
|
44
|
-
return this.getAllFormat(key)[0];
|
|
43
|
+
getFormat(key, supportOutAttr = !1) {
|
|
44
|
+
return this.getAllFormat(key, supportOutAttr)[0];
|
|
45
45
|
}
|
|
46
|
-
getAllFormat(key,
|
|
46
|
+
getAllFormat(key, supportOutAttr = !1) {
|
|
47
|
+
var _a, _b, _c, _d;
|
|
47
48
|
const valSet = new Set, minCursorIdx = Math.min(this.selectionStartCursorIdx, this.curCursorIdx), maxCursorIdx = Math.max(this.selectionStartCursorIdx, this.curCursorIdx);
|
|
48
|
-
if (minCursorIdx === maxCursorIdx) return [ this._getFormat(key, minCursorIdx) ];
|
|
49
|
+
if (minCursorIdx === maxCursorIdx) return supportOutAttr ? [ null !== (_a = this._getFormat(key, minCursorIdx)) && void 0 !== _a ? _a : (null === (_b = this.rt) || void 0 === _b ? void 0 : _b.attribute)[key] ] : [ this._getFormat(key, minCursorIdx) ];
|
|
49
50
|
for (let i = Math.ceil(minCursorIdx); i <= Math.floor(maxCursorIdx); i++) {
|
|
50
|
-
const val = this._getFormat(key, i);
|
|
51
|
-
|
|
51
|
+
const val = supportOutAttr ? null !== (_c = this._getFormat(key, i)) && void 0 !== _c ? _c : (null === (_d = this.rt) || void 0 === _d ? void 0 : _d.attribute)[key] : this._getFormat(key, i);
|
|
52
|
+
val && valSet.add(val);
|
|
52
53
|
}
|
|
53
54
|
return Array.from(valSet.values());
|
|
54
55
|
}
|
|
@@ -91,7 +92,7 @@ export class RichTextEditPlugin {
|
|
|
91
92
|
const config = rt.attribute.textConfig;
|
|
92
93
|
this._formatTextCommand(payload, config, rt);
|
|
93
94
|
}, this.handleKeyDown = e => {
|
|
94
|
-
this.currRt && this.editing && (this.copyToClipboard(e) || this.
|
|
95
|
+
this.currRt && this.editing && (this.copyToClipboard(e) || this.fullSelectionKeyHandler(e) || this.directKeyHandler(e));
|
|
95
96
|
}, this.handleInput = (text, isComposing, cursorIdx, rt) => {
|
|
96
97
|
this.currRt && (this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.hideSelection(),
|
|
97
98
|
this.updateCbs.forEach((cb => cb("input", this))));
|
|
@@ -106,15 +107,16 @@ export class RichTextEditPlugin {
|
|
|
106
107
|
}, this.handleFocusOut = () => {
|
|
107
108
|
throw new Error("不会走到这里 handleFocusOut");
|
|
108
109
|
}, this.handleMove = e => {
|
|
109
|
-
this.
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
this.isRichtext(e) && (this.currRt = e.target, this.handleEnter(e), e.target.once("pointerleave", this.handleLeave, {
|
|
111
|
+
capture: !0
|
|
112
|
+
}), this.tryShowSelection(e, !1));
|
|
113
|
+
}, this.handleEnter = e => {
|
|
112
114
|
this.editing = !0, this.pluginService.stage.setCursor("text");
|
|
113
|
-
}, this.handleLeave =
|
|
115
|
+
}, this.handleLeave = e => {
|
|
114
116
|
this.editing = !1, this.pluginService.stage.setCursor("default");
|
|
115
117
|
}, this.handlePointerDown = e => {
|
|
116
|
-
this.editing
|
|
117
|
-
this.
|
|
118
|
+
this.editing ? this.onFocus(e) : this.deFocus(!0), this.triggerRender(), this.pointerDown = !0,
|
|
119
|
+
this.updateCbs.forEach((cb => cb(this.editing ? "onfocus" : "defocus", this)));
|
|
118
120
|
}, this.handlePointerUp = e => {
|
|
119
121
|
this.pointerDown = !1;
|
|
120
122
|
}, this.handleDBLClick = e => {
|
|
@@ -150,10 +152,17 @@ export class RichTextEditPlugin {
|
|
|
150
152
|
idx > -1 && cbs.splice(idx, 1);
|
|
151
153
|
}
|
|
152
154
|
activate(context) {
|
|
153
|
-
this.pluginService = context, this.editModule = new EditModule, context.stage.on("pointermove", this.handleMove
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
this.pluginService = context, this.editModule = new EditModule, context.stage.on("pointermove", this.handleMove, {
|
|
156
|
+
capture: !0
|
|
157
|
+
}), context.stage.on("pointerdown", this.handlePointerDown, {
|
|
158
|
+
capture: !0
|
|
159
|
+
}), context.stage.on("pointerup", this.handlePointerUp, {
|
|
160
|
+
capture: !0
|
|
161
|
+
}), context.stage.on("pointerleave", this.handlePointerUp, {
|
|
162
|
+
capture: !0
|
|
163
|
+
}), context.stage.on("dblclick", this.handleDBLClick, {
|
|
164
|
+
capture: !0
|
|
165
|
+
}), application.global.addEventListener("keydown", this.handleKeyDown), this.editModule.onInput(this.handleInput),
|
|
157
166
|
this.editModule.onChange(this.handleChange), this.editModule.onFocusOut(this.handleFocusOut);
|
|
158
167
|
}
|
|
159
168
|
copyToClipboard(e) {
|
|
@@ -182,21 +191,21 @@ export class RichTextEditPlugin {
|
|
|
182
191
|
const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt);
|
|
183
192
|
this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt), this._tryShowSelection(pos, cache);
|
|
184
193
|
}
|
|
185
|
-
fullSelection(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
fullSelection() {
|
|
195
|
+
const currRt = this.currRt;
|
|
196
|
+
if (!currRt) return;
|
|
197
|
+
const cache = currRt.getFrameCache();
|
|
198
|
+
if (!cache) return;
|
|
199
|
+
const {lines: lines} = cache;
|
|
200
|
+
if (!lines.length || !lines[0].paragraphs.length) return;
|
|
201
|
+
const totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
|
|
202
|
+
this.selectionRange(-.1, totalCursorCount + .1);
|
|
203
|
+
}
|
|
204
|
+
fullSelectionKeyHandler(e) {
|
|
205
|
+
return !!(application.global.isMacOS() && e.metaKey && "a" === e.key || !application.global.isMacOS() && e.ctrlKey && "a" === e.key) && (this.fullSelection(),
|
|
206
|
+
e.preventDefault(), !0);
|
|
198
207
|
}
|
|
199
|
-
|
|
208
|
+
directKeyHandler(e) {
|
|
200
209
|
if ("ArrowUp" !== e.key && "ArrowDown" !== e.key && "ArrowLeft" !== e.key && "ArrowRight" !== e.key) return !1;
|
|
201
210
|
const cache = this.currRt.getFrameCache();
|
|
202
211
|
if (!cache) return !1;
|
|
@@ -205,8 +214,7 @@ export class RichTextEditPlugin {
|
|
|
205
214
|
const {lineInfo: lineInfo, columnInfo: columnInfo} = this.getColumnByIndex(cache, Math.round(this.curCursorIdx)), {lines: lines} = cache, totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
|
|
206
215
|
if (x) {
|
|
207
216
|
x > 0 && columnInfo === lineInfo.paragraphs[lineInfo.paragraphs.length - 2] && this.curCursorIdx < Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx + .2 : x > 0 && columnInfo === lineInfo.paragraphs[lineInfo.paragraphs.length - 1] && this.curCursorIdx > Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx + 1 - .2 : x < 0 && columnInfo === lineInfo.paragraphs[0] && this.curCursorIdx > Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx - .2 : x < 0 && columnInfo === lineInfo.paragraphs[0] && this.curCursorIdx < Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx - 1 + .2 : this.curCursorIdx += x,
|
|
208
|
-
this.curCursorIdx < -.1 ? this.curCursorIdx = -.1 : this.curCursorIdx > totalCursorCount + .1 && (this.curCursorIdx = totalCursorCount + .1)
|
|
209
|
-
this.selectionStartCursorIdx = this.curCursorIdx;
|
|
217
|
+
this.curCursorIdx < -.1 ? this.curCursorIdx = -.1 : this.curCursorIdx > totalCursorCount + .1 && (this.curCursorIdx = totalCursorCount + .1);
|
|
210
218
|
const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt);
|
|
211
219
|
this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt), this.hideSelection();
|
|
212
220
|
}
|
|
@@ -237,7 +245,7 @@ export class RichTextEditPlugin {
|
|
|
237
245
|
const placeholder = shadowRoot.getElementsByType("richtext")[0];
|
|
238
246
|
placeholder && shadowRoot.removeChild(placeholder);
|
|
239
247
|
}
|
|
240
|
-
const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
|
|
248
|
+
const {textConfig: textConfig, editOptions: editOptions = {}} = this.currRt.attribute;
|
|
241
249
|
if (textConfig && textConfig.length) return;
|
|
242
250
|
if (!editOptions || !editOptions.placeholder) return;
|
|
243
251
|
const {placeholder: placeholder, placeholderColor: placeholderColor = "rgba(0, 0, 0, 0.6)", placeholderFontFamily: placeholderFontFamily, placeholderFontSize: placeholderFontSize} = editOptions, shadow = this.getShadow(this.currRt), textConfigItem = Object.assign(Object.assign({}, getDefaultCharacterConfig(this.currRt.attribute)), {
|
|
@@ -247,41 +255,44 @@ export class RichTextEditPlugin {
|
|
|
247
255
|
placeholderFontSize && (textConfigItem.fontSize = placeholderFontSize), this.shadowPlaceHolder = createRichText(Object.assign(Object.assign({}, this.currRt.attribute), {
|
|
248
256
|
x: 0,
|
|
249
257
|
y: 0,
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
editOptions: null,
|
|
258
|
+
dx: -this.deltaX,
|
|
259
|
+
dy: -this.deltaY,
|
|
253
260
|
angle: 0,
|
|
254
|
-
_debug_bounds: !1,
|
|
255
261
|
textConfig: [ textConfigItem ]
|
|
256
262
|
})), shadow.add(this.shadowPlaceHolder);
|
|
257
263
|
}
|
|
264
|
+
getRichTextAABBBounds(rt) {
|
|
265
|
+
const {attribute: attribute} = rt;
|
|
266
|
+
return attribute.textConfig.length ? rt.AABBBounds : getRichTextBounds(Object.assign(Object.assign({}, this.shadowPlaceHolder.attribute), {
|
|
267
|
+
x: attribute.x,
|
|
268
|
+
y: attribute.y,
|
|
269
|
+
textAlign: attribute.textAlign,
|
|
270
|
+
boundsMode: "accurate"
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
258
273
|
tryShowInputBounds() {
|
|
259
274
|
if (!this.currRt || !this.focusing) return;
|
|
260
275
|
const {editOptions: editOptions = {}} = this.currRt.attribute, {boundsStrokeWhenInput: boundsStrokeWhenInput} = editOptions;
|
|
261
276
|
if (!editOptions || !boundsStrokeWhenInput) return;
|
|
262
|
-
const
|
|
263
|
-
let b = this.currRt.AABBBounds, h = b.height();
|
|
264
|
-
if (!attribute.textConfig.length && this.editLine) {
|
|
265
|
-
const {points: points} = this.editLine.attribute;
|
|
266
|
-
h = points[1].y - points[0].y, b = getRichTextBounds(Object.assign({}, this.shadowPlaceHolder.attribute));
|
|
267
|
-
}
|
|
277
|
+
const b = this.getRichTextAABBBounds(this.currRt), height = b.height(), width = b.width();
|
|
268
278
|
this.shadowBounds = this.shadowBounds || createRect({}), this.shadowBounds.setAttributes({
|
|
269
279
|
x: 0,
|
|
270
280
|
y: 0,
|
|
271
|
-
width:
|
|
272
|
-
height:
|
|
281
|
+
width: width,
|
|
282
|
+
height: height,
|
|
273
283
|
fill: !1,
|
|
274
284
|
stroke: boundsStrokeWhenInput,
|
|
275
285
|
lineWidth: 1,
|
|
276
286
|
zIndex: -1
|
|
277
287
|
});
|
|
278
|
-
this.getShadow(this.currRt).add(this.shadowBounds), this.offsetLineBgAndShadowBounds()
|
|
288
|
+
this.getShadow(this.currRt).add(this.shadowBounds), this.offsetLineBgAndShadowBounds(),
|
|
289
|
+
this.offsetShadowRoot();
|
|
279
290
|
}
|
|
280
291
|
trySyncPlaceholderToTextConfig() {
|
|
281
292
|
if (!this.currRt) return;
|
|
282
293
|
const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
|
|
283
294
|
if (textConfig && textConfig.length) return;
|
|
284
|
-
if (!(editOptions && editOptions.placeholder && editOptions.
|
|
295
|
+
if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceholderToTextConfig)) return;
|
|
285
296
|
const {placeholder: placeholder} = editOptions;
|
|
286
297
|
this.currRt.setAttributes({
|
|
287
298
|
textConfig: [ Object.assign({
|
|
@@ -290,9 +301,20 @@ export class RichTextEditPlugin {
|
|
|
290
301
|
});
|
|
291
302
|
}
|
|
292
303
|
deactivate(context) {
|
|
293
|
-
context.stage.off("pointermove", this.handleMove
|
|
294
|
-
|
|
295
|
-
context.stage.off("
|
|
304
|
+
context.stage.off("pointermove", this.handleMove, {
|
|
305
|
+
capture: !0
|
|
306
|
+
}), context.stage.off("pointerdown", this.handlePointerDown, {
|
|
307
|
+
capture: !0
|
|
308
|
+
}), context.stage.off("pointerup", this.handlePointerUp, {
|
|
309
|
+
capture: !0
|
|
310
|
+
}), context.stage.off("pointerleave", this.handlePointerUp, {
|
|
311
|
+
capture: !0
|
|
312
|
+
}), context.stage.off("dblclick", this.handleDBLClick, {
|
|
313
|
+
capture: !0
|
|
314
|
+
}), application.global.addEventListener("keydown", this.handleKeyDown);
|
|
315
|
+
}
|
|
316
|
+
stopPropagation(e) {
|
|
317
|
+
e.stopPropagation();
|
|
296
318
|
}
|
|
297
319
|
onFocus(e, data) {
|
|
298
320
|
this.updateCbs && this.updateCbs.forEach((cb => cb("beforeOnfocus", this))), this.deFocus(!1),
|
|
@@ -301,48 +323,59 @@ export class RichTextEditPlugin {
|
|
|
301
323
|
if (!target || "richtext" !== target.type) return;
|
|
302
324
|
this.currRt = target, RichTextEditPlugin.tryUpdateRichtext(target);
|
|
303
325
|
const shadowRoot = this.getShadow(target), cache = target.getFrameCache();
|
|
304
|
-
if (cache)
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
height: 0
|
|
323
|
-
});
|
|
324
|
-
this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
|
|
325
|
-
}
|
|
326
|
-
if (data = data || this.computedCursorPosByEvent(e, cache)) {
|
|
327
|
-
const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
|
|
328
|
-
this.startCursorPos = {
|
|
329
|
-
x: x,
|
|
330
|
-
y: (y1 + y2) / 2
|
|
331
|
-
}, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
|
|
332
|
-
this.setCursorAndTextArea(x, y1, y2, target);
|
|
333
|
-
} else {
|
|
334
|
-
const x = 0, y1 = 0, y2 = getRichTextBounds(Object.assign(Object.assign({}, target.attribute), {
|
|
335
|
-
textConfig: [ {
|
|
336
|
-
text: "a"
|
|
337
|
-
} ]
|
|
338
|
-
})).height();
|
|
339
|
-
this.startCursorPos = {
|
|
340
|
-
x: x,
|
|
341
|
-
y: (y1 + y2) / 2
|
|
342
|
-
}, this.curCursorIdx = -.1, this.selectionStartCursorIdx = -.1, this.setCursorAndTextArea(x, y1, y2, target);
|
|
343
|
-
}
|
|
344
|
-
this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.currRt.addUpdateBoundTag();
|
|
326
|
+
if (!cache) return;
|
|
327
|
+
const {editOptions: editOptions = {}} = this.currRt.attribute;
|
|
328
|
+
if (editOptions.stopPropagation && target.addEventListener("*", this.stopPropagation),
|
|
329
|
+
this.offsetShadowRoot(target), !this.editLine) {
|
|
330
|
+
const line = createLine({
|
|
331
|
+
x: 0,
|
|
332
|
+
y: 0,
|
|
333
|
+
lineWidth: 1,
|
|
334
|
+
stroke: "black"
|
|
335
|
+
});
|
|
336
|
+
this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
|
|
337
|
+
const g = createGroup({
|
|
338
|
+
x: 0,
|
|
339
|
+
y: 0,
|
|
340
|
+
width: 0,
|
|
341
|
+
height: 0
|
|
342
|
+
});
|
|
343
|
+
this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
|
|
345
344
|
}
|
|
345
|
+
if (data = data || this.computedCursorPosByEvent(e, cache)) {
|
|
346
|
+
const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
|
|
347
|
+
this.startCursorPos = {
|
|
348
|
+
x: x,
|
|
349
|
+
y: (y1 + y2) / 2
|
|
350
|
+
}, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
|
|
351
|
+
this.setCursorAndTextArea(x, y1, y2, target);
|
|
352
|
+
} else {
|
|
353
|
+
const x = 0, y1 = 0, y2 = getRichTextBounds(Object.assign(Object.assign({}, target.attribute), {
|
|
354
|
+
textConfig: [ {
|
|
355
|
+
text: "a"
|
|
356
|
+
} ]
|
|
357
|
+
})).height();
|
|
358
|
+
this.startCursorPos = {
|
|
359
|
+
x: x,
|
|
360
|
+
y: (y1 + y2) / 2
|
|
361
|
+
}, this.curCursorIdx = -.1, this.selectionStartCursorIdx = -.1, this.setCursorAndTextArea(x, y1, y2, target);
|
|
362
|
+
}
|
|
363
|
+
this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.currRt.addUpdateBoundTag();
|
|
364
|
+
}
|
|
365
|
+
offsetShadowRoot(rt) {
|
|
366
|
+
if (!(rt = rt || this.currRt)) return;
|
|
367
|
+
const shadowRoot = this.getShadow(rt);
|
|
368
|
+
if (!shadowRoot) return;
|
|
369
|
+
const cache = rt.getFrameCache();
|
|
370
|
+
cache && (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
|
|
371
|
+
shadowRootIdx: 1,
|
|
372
|
+
pickable: !1,
|
|
373
|
+
x: this.deltaX,
|
|
374
|
+
y: this.deltaY
|
|
375
|
+
}), this.shadowPlaceHolder && this.shadowPlaceHolder.setAttributes({
|
|
376
|
+
dx: -this.deltaX,
|
|
377
|
+
dy: -this.deltaY
|
|
378
|
+
}));
|
|
346
379
|
}
|
|
347
380
|
offsetLineBgAndShadowBounds() {
|
|
348
381
|
const rt = this.currRt, {textBaseline: textBaseline} = rt.attribute;
|
|
@@ -361,11 +394,15 @@ export class RichTextEditPlugin {
|
|
|
361
394
|
});
|
|
362
395
|
}
|
|
363
396
|
deFocus(trulyDeFocus = !1) {
|
|
364
|
-
const currRt = this.currRt;
|
|
365
|
-
if (!currRt) return;
|
|
366
397
|
this.updateCbs && this.updateCbs.forEach((cb => cb("beforeDefocus", this, {
|
|
367
398
|
trulyDeFocus: trulyDeFocus
|
|
368
|
-
})))
|
|
399
|
+
})));
|
|
400
|
+
const target = this.currRt;
|
|
401
|
+
if (!target) return;
|
|
402
|
+
const {editOptions: editOptions = {}} = target.attribute;
|
|
403
|
+
editOptions.stopPropagation && target.removeEventListener("*", this.stopPropagation),
|
|
404
|
+
trulyDeFocus && (this.trySyncPlaceholderToTextConfig(), target.detachShadow());
|
|
405
|
+
const currRt = this.currRt;
|
|
369
406
|
this.currRt = null, this.editLine && (this.editLine.parent && this.editLine.parent.removeChild(this.editLine),
|
|
370
407
|
this.editLine.release(), this.editLine = null, this.editBg.parent && this.editBg.parent.removeChild(this.editBg),
|
|
371
408
|
this.editBg.release(), this.editBg = null), trulyDeFocus && (this.shadowBounds && (this.shadowBounds.parent && this.shadowBounds.parent.removeChild(this.shadowBounds),
|
|
@@ -377,12 +414,10 @@ export class RichTextEditPlugin {
|
|
|
377
414
|
cleared = !0;
|
|
378
415
|
cleared && currRt.setAttributes({
|
|
379
416
|
textConfig: textConfig
|
|
380
|
-
})
|
|
417
|
+
});
|
|
381
418
|
}
|
|
382
419
|
addAnimateToLine(line) {
|
|
383
|
-
line.
|
|
384
|
-
opacity: 1
|
|
385
|
-
}), line.animates && line.animates.forEach((animate => {
|
|
420
|
+
line.animates && line.animates.forEach((animate => {
|
|
386
421
|
animate.stop(), animate.release();
|
|
387
422
|
}));
|
|
388
423
|
line.animate({
|
|
@@ -420,63 +455,61 @@ export class RichTextEditPlugin {
|
|
|
420
455
|
x: currCursorData.x,
|
|
421
456
|
y: (currCursorData.y1 + currCursorData.y2) / 2
|
|
422
457
|
}, line0Info = this.getLineByPoint(cache, startCursorPos), line1Info = this.getLineByPoint(cache, endCursorPos);
|
|
423
|
-
if (
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
458
|
+
if ((startCursorPos.y > endCursorPos.y || startCursorPos.y === endCursorPos.y && startCursorPos.x > endCursorPos.x) && ([startCursorPos, endCursorPos] = [ endCursorPos, startCursorPos ],
|
|
459
|
+
[line1Info, line0Info] = [ line0Info, line1Info ]), this.hideSelection(), line0Info === line1Info) this.editBg.setAttributes({
|
|
460
|
+
x: startCursorPos.x,
|
|
461
|
+
y: line0Info.top,
|
|
462
|
+
width: endCursorPos.x - startCursorPos.x,
|
|
463
|
+
height: line0Info.height,
|
|
464
|
+
fill: "#336df4",
|
|
465
|
+
fillOpacity: .2
|
|
466
|
+
}); else {
|
|
467
|
+
this.editBg.setAttributes({
|
|
468
|
+
x: 0,
|
|
427
469
|
y: line0Info.top,
|
|
428
|
-
width:
|
|
429
|
-
height:
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
this.editBg.add(createRect({
|
|
466
|
-
x: p0.left,
|
|
467
|
-
y: y,
|
|
468
|
-
width: p1.left + p1.width - p0.left,
|
|
469
|
-
height: line.height,
|
|
470
|
-
fill: "#336df4",
|
|
471
|
-
fillOpacity: .2
|
|
472
|
-
}));
|
|
473
|
-
}
|
|
474
|
-
y += line.height;
|
|
470
|
+
width: 0,
|
|
471
|
+
height: 0
|
|
472
|
+
});
|
|
473
|
+
const startIdx = cache.lines.findIndex((item => item === line0Info)), endIdx = cache.lines.findIndex((item => item === line1Info));
|
|
474
|
+
let y = 0;
|
|
475
|
+
for (let i = startIdx; i <= endIdx; i++) {
|
|
476
|
+
const line = cache.lines[i];
|
|
477
|
+
if (i === startIdx) {
|
|
478
|
+
const p = line.paragraphs[line.paragraphs.length - 1];
|
|
479
|
+
this.editBg.add(createRect({
|
|
480
|
+
x: startCursorPos.x,
|
|
481
|
+
y: y,
|
|
482
|
+
width: p.left + p.width - startCursorPos.x,
|
|
483
|
+
height: line.height,
|
|
484
|
+
fill: "#336df4",
|
|
485
|
+
fillOpacity: .2
|
|
486
|
+
}));
|
|
487
|
+
} else if (i === endIdx) {
|
|
488
|
+
const p = line.paragraphs[0];
|
|
489
|
+
this.editBg.add(createRect({
|
|
490
|
+
x: p.left,
|
|
491
|
+
y: y,
|
|
492
|
+
width: endCursorPos.x - p.left,
|
|
493
|
+
height: line.height,
|
|
494
|
+
fill: "#336df4",
|
|
495
|
+
fillOpacity: .2
|
|
496
|
+
}));
|
|
497
|
+
} else {
|
|
498
|
+
const p0 = line.paragraphs[0], p1 = line.paragraphs[line.paragraphs.length - 1];
|
|
499
|
+
this.editBg.add(createRect({
|
|
500
|
+
x: p0.left,
|
|
501
|
+
y: y,
|
|
502
|
+
width: p1.left + p1.width - p0.left,
|
|
503
|
+
height: line.height,
|
|
504
|
+
fill: "#336df4",
|
|
505
|
+
fillOpacity: .2
|
|
506
|
+
}));
|
|
475
507
|
}
|
|
508
|
+
y += line.height;
|
|
476
509
|
}
|
|
477
|
-
this.setCursorAndTextArea(currCursorData.x, currCursorData.y1, currCursorData.y2, this.currRt),
|
|
478
|
-
this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
|
|
479
510
|
}
|
|
511
|
+
this.setCursorAndTextArea(currCursorData.x, currCursorData.y1, currCursorData.y2, this.currRt),
|
|
512
|
+
this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
|
|
480
513
|
}
|
|
481
514
|
hideSelection() {
|
|
482
515
|
this.editBg && (this.editBg.removeAllChild(), this.editBg.setAttributes({
|
|
@@ -520,16 +553,13 @@ export class RichTextEditPlugin {
|
|
|
520
553
|
return -1;
|
|
521
554
|
}
|
|
522
555
|
isRichtext(e) {
|
|
523
|
-
return !(!e.target || "richtext" !== e.target.type);
|
|
524
|
-
}
|
|
525
|
-
isEditableRichtext(e) {
|
|
526
|
-
return this.isRichtext(e) && !!e.target.attribute.editable;
|
|
556
|
+
return !(!e.target || "richtext" !== e.target.type || !e.target.attribute.editable);
|
|
527
557
|
}
|
|
528
558
|
triggerRender() {
|
|
529
559
|
this.pluginService.stage.renderNextFrame();
|
|
530
560
|
}
|
|
531
561
|
computeGlobalDelta(cache) {
|
|
532
|
-
this.deltaX = 0, this.deltaY = 0;
|
|
562
|
+
this.deltaX = 0, this.deltaY = 0, 0 === cache.lines.length && this.shadowPlaceHolder && (cache = this.shadowPlaceHolder.getFrameCache());
|
|
533
563
|
const height = cache.height, actualHeight = cache.actualHeight, width = cache.lines.reduce(((w, item) => Math.max(w, item.actualWidth)), 0);
|
|
534
564
|
"center" === cache.globalAlign ? this.deltaX = -width / 2 : "right" === cache.globalAlign && (this.deltaX = -width),
|
|
535
565
|
"middle" === cache.verticalDirection ? this.deltaY = height / 2 - actualHeight / 2 : "bottom" === cache.verticalDirection && (this.deltaY = height - actualHeight);
|
|
@@ -568,7 +598,8 @@ export class RichTextEditPlugin {
|
|
|
568
598
|
y: y1
|
|
569
599
|
}, out);
|
|
570
600
|
const {left: left, top: top} = this.pluginService.stage.window.getBoundingClientRect();
|
|
571
|
-
out.x += left, out.y += top, this.offsetLineBgAndShadowBounds(), this.
|
|
601
|
+
out.x += left, out.y += top, this.offsetLineBgAndShadowBounds(), this.offsetShadowRoot(),
|
|
602
|
+
this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
|
|
572
603
|
}
|
|
573
604
|
computedCursorPosByEvent(e, cache) {
|
|
574
605
|
const p1 = this.getEventPosition(e), lineInfo = this.getLineByPoint(cache, p1);
|
|
@@ -642,7 +673,7 @@ export class RichTextEditPlugin {
|
|
|
642
673
|
target && (this.currRt = target, e ? this._forceFocusByEvent(e) : this._forceFocusByCursorIndex(null != cursorIndex ? cursorIndex : -.1));
|
|
643
674
|
}
|
|
644
675
|
_forceFocusByEvent(e) {
|
|
645
|
-
this.handleEnter(), this.handlePointerDown(e), this.handlePointerUp(e);
|
|
676
|
+
this.handleEnter(e), this.handlePointerDown(e), this.handlePointerUp(e);
|
|
646
677
|
}
|
|
647
678
|
_forceFocusByCursorIndex(cursorIndex) {
|
|
648
679
|
const richtext = this.currRt;
|