@visactor/vrender-core 0.22.0-vstory.6 → 0.22.0-vstory.8
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/graphic/group.js +1 -1
- package/cjs/graphic/group.js.map +1 -1
- package/cjs/graphic/richtext/line.js +11 -1
- package/cjs/graphic/richtext/line.js.map +1 -1
- package/cjs/graphic/richtext/paragraph.d.ts +8 -1
- package/cjs/graphic/richtext/paragraph.js +8 -20
- package/cjs/graphic/richtext/paragraph.js.map +1 -1
- package/cjs/graphic/richtext.d.ts +2 -1
- package/cjs/graphic/richtext.js +6 -0
- package/cjs/graphic/richtext.js.map +1 -1
- package/cjs/interface/graphic/richText.d.ts +1 -0
- package/cjs/interface/graphic/richText.js.map +1 -1
- package/cjs/plugins/builtin-plugin/edit-module.js +2 -2
- package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +3 -2
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +87 -73
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
- package/cjs/render/contributions/render/draw-contribution.js +1 -1
- package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
- package/dist/index.es.js +81 -47
- package/es/graphic/group.js +1 -1
- package/es/graphic/group.js.map +1 -1
- package/es/graphic/richtext/line.js +11 -1
- package/es/graphic/richtext/line.js.map +1 -1
- package/es/graphic/richtext/paragraph.d.ts +8 -1
- package/es/graphic/richtext/paragraph.js +8 -20
- package/es/graphic/richtext/paragraph.js.map +1 -1
- package/es/graphic/richtext.d.ts +2 -1
- package/es/graphic/richtext.js +6 -0
- package/es/graphic/richtext.js.map +1 -1
- package/es/interface/graphic/richText.d.ts +1 -0
- package/es/interface/graphic/richText.js.map +1 -1
- package/es/plugins/builtin-plugin/edit-module.js +2 -2
- package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +3 -2
- package/es/plugins/builtin-plugin/richtext-edit-plugin.js +85 -73
- package/es/plugins/builtin-plugin/richtext-edit-plugin.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/package.json +3 -3
|
@@ -185,7 +185,10 @@ class RichTextEditPlugin {
|
|
|
185
185
|
if (!currRt) return;
|
|
186
186
|
const cache = currRt.getFrameCache();
|
|
187
187
|
if (!cache) return;
|
|
188
|
-
const {lines: lines} = cache
|
|
188
|
+
const {lines: lines} = cache;
|
|
189
|
+
if (0 === lines.length) return;
|
|
190
|
+
if (!lines[0].paragraphs || 0 === lines[0].paragraphs.length) return;
|
|
191
|
+
const totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
|
|
189
192
|
return this.selectionRange(-.1, totalCursorCount + .1), e.preventDefault(), !0;
|
|
190
193
|
}
|
|
191
194
|
return !1;
|
|
@@ -233,29 +236,32 @@ class RichTextEditPlugin {
|
|
|
233
236
|
const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
|
|
234
237
|
if (textConfig && textConfig.length) return;
|
|
235
238
|
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
|
|
237
|
-
|
|
239
|
+
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({}, (0,
|
|
240
|
+
edit_module_1.getDefaultCharacterConfig)(this.currRt.attribute)), {
|
|
241
|
+
text: placeholder
|
|
242
|
+
});
|
|
243
|
+
placeholderColor && (textConfigItem.fill = placeholderColor), placeholderFontFamily && (textConfigItem.fontFamily = placeholderFontFamily),
|
|
244
|
+
placeholderFontSize && (textConfigItem.fontSize = placeholderFontSize), this.shadowPlaceHolder = (0,
|
|
245
|
+
graphic_1.createRichText)(Object.assign(Object.assign({}, this.currRt.attribute), {
|
|
238
246
|
x: 0,
|
|
239
247
|
y: 0,
|
|
248
|
+
pickable: !1,
|
|
249
|
+
editable: !1,
|
|
250
|
+
editOptions: null,
|
|
240
251
|
angle: 0,
|
|
241
252
|
_debug_bounds: !1,
|
|
242
|
-
textConfig: [
|
|
243
|
-
text: placeholder,
|
|
244
|
-
fill: placeholderColor,
|
|
245
|
-
fontFamily: placeholderFontFamily,
|
|
246
|
-
fontSize: placeholderFontSize
|
|
247
|
-
} ]
|
|
253
|
+
textConfig: [ textConfigItem ]
|
|
248
254
|
})), shadow.add(this.shadowPlaceHolder);
|
|
249
255
|
}
|
|
250
256
|
tryShowInputBounds() {
|
|
251
257
|
if (!this.currRt || !this.focusing) return;
|
|
252
258
|
const {editOptions: editOptions = {}} = this.currRt.attribute, {boundsStrokeWhenInput: boundsStrokeWhenInput} = editOptions;
|
|
253
259
|
if (!editOptions || !boundsStrokeWhenInput) return;
|
|
254
|
-
const {attribute: attribute} = this.currRt
|
|
255
|
-
let h = b.height();
|
|
260
|
+
const {attribute: attribute} = this.currRt;
|
|
261
|
+
let b = this.currRt.AABBBounds, h = b.height();
|
|
256
262
|
if (!attribute.textConfig.length && this.editLine) {
|
|
257
263
|
const {points: points} = this.editLine.attribute;
|
|
258
|
-
h = points[1].y - points[0].y;
|
|
264
|
+
h = points[1].y - points[0].y, b = (0, graphic_1.getRichTextBounds)(Object.assign({}, this.shadowPlaceHolder.attribute));
|
|
259
265
|
}
|
|
260
266
|
this.shadowBounds = this.shadowBounds || (0, graphic_1.createRect)({}), this.shadowBounds.setAttributes({
|
|
261
267
|
x: 0,
|
|
@@ -265,16 +271,15 @@ class RichTextEditPlugin {
|
|
|
265
271
|
fill: !1,
|
|
266
272
|
stroke: boundsStrokeWhenInput,
|
|
267
273
|
lineWidth: 1,
|
|
268
|
-
boundsMode: "empty",
|
|
269
274
|
zIndex: -1
|
|
270
275
|
});
|
|
271
|
-
|
|
276
|
+
this.getShadow(this.currRt).add(this.shadowBounds), this.offsetLineBgAndShadowBounds();
|
|
272
277
|
}
|
|
273
278
|
trySyncPlaceholderToTextConfig() {
|
|
274
279
|
if (!this.currRt) return;
|
|
275
280
|
const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
|
|
276
281
|
if (textConfig && textConfig.length) return;
|
|
277
|
-
if (!editOptions
|
|
282
|
+
if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceHolderToTextConfig)) return;
|
|
278
283
|
const {placeholder: placeholder} = editOptions;
|
|
279
284
|
this.currRt.setAttributes({
|
|
280
285
|
textConfig: [ Object.assign({
|
|
@@ -288,11 +293,12 @@ class RichTextEditPlugin {
|
|
|
288
293
|
context.stage.off("dblclick", this.handleDBLClick), application_1.application.global.addEventListener("keydown", this.handleKeyDown);
|
|
289
294
|
}
|
|
290
295
|
onFocus(e, data) {
|
|
291
|
-
this.deFocus(!1),
|
|
296
|
+
this.updateCbs && this.updateCbs.forEach((cb => cb("beforeOnfocus", this))), this.deFocus(!1),
|
|
297
|
+
this.focusing = !0;
|
|
292
298
|
const target = e.target;
|
|
293
299
|
if (!target || "richtext" !== target.type) return;
|
|
294
300
|
this.currRt = target, RichTextEditPlugin.tryUpdateRichtext(target);
|
|
295
|
-
const shadowRoot =
|
|
301
|
+
const shadowRoot = this.getShadow(target), cache = target.getFrameCache();
|
|
296
302
|
if (cache) {
|
|
297
303
|
if (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
|
|
298
304
|
shadowRootIdx: 1,
|
|
@@ -304,16 +310,14 @@ class RichTextEditPlugin {
|
|
|
304
310
|
x: 0,
|
|
305
311
|
y: 0,
|
|
306
312
|
lineWidth: 1,
|
|
307
|
-
stroke: "black"
|
|
308
|
-
boundsMode: "empty"
|
|
313
|
+
stroke: "black"
|
|
309
314
|
});
|
|
310
315
|
this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
|
|
311
316
|
const g = (0, graphic_1.createGroup)({
|
|
312
317
|
x: 0,
|
|
313
318
|
y: 0,
|
|
314
319
|
width: 0,
|
|
315
|
-
height: 0
|
|
316
|
-
boundsMode: "empty"
|
|
320
|
+
height: 0
|
|
317
321
|
});
|
|
318
322
|
this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
|
|
319
323
|
}
|
|
@@ -357,7 +361,9 @@ class RichTextEditPlugin {
|
|
|
357
361
|
deFocus(trulyDeFocus = !1) {
|
|
358
362
|
const target = this.currRt;
|
|
359
363
|
if (!target) return;
|
|
360
|
-
|
|
364
|
+
this.updateCbs && this.updateCbs.forEach((cb => cb("beforeDefocus", this, {
|
|
365
|
+
trulyDeFocus: trulyDeFocus
|
|
366
|
+
}))), trulyDeFocus && (this.trySyncPlaceholderToTextConfig(), target.detachShadow());
|
|
361
367
|
const currRt = this.currRt;
|
|
362
368
|
this.currRt = null, this.editLine && (this.editLine.parent && this.editLine.parent.removeChild(this.editLine),
|
|
363
369
|
this.editLine.release(), this.editLine = null, this.editBg.parent && this.editBg.parent.removeChild(this.editBg),
|
|
@@ -411,67 +417,75 @@ class RichTextEditPlugin {
|
|
|
411
417
|
x: currCursorData.x,
|
|
412
418
|
y: (currCursorData.y1 + currCursorData.y2) / 2
|
|
413
419
|
}, line0Info = this.getLineByPoint(cache, startCursorPos), line1Info = this.getLineByPoint(cache, endCursorPos);
|
|
414
|
-
if (
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
width: endCursorPos.x - startCursorPos.x,
|
|
419
|
-
height: line0Info.height,
|
|
420
|
-
fill: "#336df4",
|
|
421
|
-
fillOpacity: .2
|
|
422
|
-
}); else {
|
|
423
|
-
this.editBg.setAttributes({
|
|
424
|
-
x: 0,
|
|
420
|
+
if (line0Info && line1Info) {
|
|
421
|
+
if ((startCursorPos.y > endCursorPos.y || startCursorPos.y === endCursorPos.y && startCursorPos.x > endCursorPos.x) && ([startCursorPos, endCursorPos] = [ endCursorPos, startCursorPos ],
|
|
422
|
+
[line1Info, line0Info] = [ line0Info, line1Info ]), this.hideSelection(), line0Info === line1Info) this.editBg.setAttributes({
|
|
423
|
+
x: startCursorPos.x,
|
|
425
424
|
y: line0Info.top,
|
|
426
|
-
width:
|
|
427
|
-
height:
|
|
428
|
-
|
|
429
|
-
|
|
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
|
-
|
|
425
|
+
width: endCursorPos.x - startCursorPos.x,
|
|
426
|
+
height: line0Info.height,
|
|
427
|
+
fill: "#336df4",
|
|
428
|
+
fillOpacity: .2
|
|
429
|
+
}); else {
|
|
430
|
+
this.editBg.setAttributes({
|
|
431
|
+
x: 0,
|
|
432
|
+
y: line0Info.top,
|
|
433
|
+
width: 0,
|
|
434
|
+
height: 0
|
|
435
|
+
});
|
|
436
|
+
const startIdx = cache.lines.findIndex((item => item === line0Info)), endIdx = cache.lines.findIndex((item => item === line1Info));
|
|
437
|
+
let y = 0;
|
|
438
|
+
for (let i = startIdx; i <= endIdx; i++) {
|
|
439
|
+
const line = cache.lines[i];
|
|
440
|
+
if (i === startIdx) {
|
|
441
|
+
const p = line.paragraphs[line.paragraphs.length - 1];
|
|
442
|
+
this.editBg.add((0, graphic_1.createRect)({
|
|
443
|
+
x: startCursorPos.x,
|
|
444
|
+
y: y,
|
|
445
|
+
width: p.left + p.width - startCursorPos.x,
|
|
446
|
+
height: line.height,
|
|
447
|
+
fill: "#336df4",
|
|
448
|
+
fillOpacity: .2
|
|
449
|
+
}));
|
|
450
|
+
} else if (i === endIdx) {
|
|
451
|
+
const p = line.paragraphs[0];
|
|
452
|
+
this.editBg.add((0, graphic_1.createRect)({
|
|
453
|
+
x: p.left,
|
|
454
|
+
y: y,
|
|
455
|
+
width: endCursorPos.x - p.left,
|
|
456
|
+
height: line.height,
|
|
457
|
+
fill: "#336df4",
|
|
458
|
+
fillOpacity: .2
|
|
459
|
+
}));
|
|
460
|
+
} else {
|
|
461
|
+
const p0 = line.paragraphs[0], p1 = line.paragraphs[line.paragraphs.length - 1];
|
|
462
|
+
this.editBg.add((0, graphic_1.createRect)({
|
|
463
|
+
x: p0.left,
|
|
464
|
+
y: y,
|
|
465
|
+
width: p1.left + p1.width - p0.left,
|
|
466
|
+
height: line.height,
|
|
467
|
+
fill: "#336df4",
|
|
468
|
+
fillOpacity: .2
|
|
469
|
+
}));
|
|
470
|
+
}
|
|
471
|
+
y += line.height;
|
|
463
472
|
}
|
|
464
|
-
y += line.height;
|
|
465
473
|
}
|
|
474
|
+
this.setCursorAndTextArea(currCursorData.x, currCursorData.y1, currCursorData.y2, this.currRt),
|
|
475
|
+
this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
|
|
466
476
|
}
|
|
467
|
-
this.setCursorAndTextArea(currCursorData.x, currCursorData.y1, currCursorData.y2, this.currRt),
|
|
468
|
-
this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
|
|
469
477
|
}
|
|
470
478
|
hideSelection() {
|
|
471
479
|
this.editBg && (this.editBg.removeAllChild(), this.editBg.setAttributes({
|
|
472
480
|
fill: "transparent"
|
|
473
481
|
}));
|
|
474
482
|
}
|
|
483
|
+
getShadow(rt) {
|
|
484
|
+
const sr = rt.shadowRoot || rt.attachShadow();
|
|
485
|
+
return sr.setAttributes({
|
|
486
|
+
boundsMode: "empty"
|
|
487
|
+
}), sr;
|
|
488
|
+
}
|
|
475
489
|
getLineByPoint(cache, p1) {
|
|
476
490
|
let lineInfo = cache.lines[0];
|
|
477
491
|
for (let i = 0; i < cache.lines.length && !(lineInfo.top <= p1.y && lineInfo.top + lineInfo.height >= p1.y); i++) lineInfo = cache.lines[i + 1];
|