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