@hufe921/canvas-editor 0.9.48 → 0.9.49

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/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## [0.9.49](https://github.com/Hufe921/canvas-editor/compare/v0.9.48...v0.9.49) (2023-09-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * control minimum width when scaling ([05ddc2d](https://github.com/Hufe921/canvas-editor/commit/05ddc2db290e58a4ec0fb1b00ad5d64ce7f4cf3a))
7
+ * draw text element letter space error #282 ([c35f8ab](https://github.com/Hufe921/canvas-editor/commit/c35f8ab82c57849269a09fbad9d54d5085065d22)), closes [#282](https://github.com/Hufe921/canvas-editor/issues/282)
8
+ * omitObject function missing reference ([c45317e](https://github.com/Hufe921/canvas-editor/commit/c45317eced93e3d79129aea24776a8629d058050))
9
+
10
+
11
+ ### Features
12
+
13
+ * add set and get control value api #278 ([f754741](https://github.com/Hufe921/canvas-editor/commit/f754741f32de6c5d5c27d15dfc9fc31e284d29dc)), closes [#278](https://github.com/Hufe921/canvas-editor/issues/278)
14
+ * text element width #277 ([bb64626](https://github.com/Hufe921/canvas-editor/commit/bb646266b10897c3097ada5932f9b7cef317aebe)), closes [#277](https://github.com/Hufe921/canvas-editor/issues/277)
15
+
16
+
17
+ ### Performance Improvements
18
+
19
+ * adjusted the tab draw in the list style #283 ([fc0fdb2](https://github.com/Hufe921/canvas-editor/commit/fc0fdb2fe36966e3b8a51107d9929ca137e5681c)), closes [#283](https://github.com/Hufe921/canvas-editor/issues/283)
20
+
21
+
22
+
1
23
  ## [0.9.48](https://github.com/Hufe921/canvas-editor/compare/v0.9.47...v0.9.48) (2023-09-09)
2
24
 
3
25
 
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
  var index = "";
26
- const version = "0.9.48";
26
+ const version = "0.9.49";
27
27
  var MaxHeightRatio;
28
28
  (function(MaxHeightRatio2) {
29
29
  MaxHeightRatio2["HALF"] = "half";
@@ -257,14 +257,14 @@ function cloneProperty(properties, sourceElement, targetElement) {
257
257
  }
258
258
  }
259
259
  }
260
- function omitObject(object, keys) {
261
- const cloneObject = deepClone(object);
260
+ function omitObject(object, omitKeys) {
261
+ const newObject = {};
262
262
  for (const key in object) {
263
- if (keys.includes(key)) {
264
- delete cloneObject[key];
263
+ if (!omitKeys.includes(key)) {
264
+ newObject[key] = object[key];
265
265
  }
266
266
  }
267
- return cloneObject;
267
+ return newObject;
268
268
  }
269
269
  function convertStringToBase64(input2) {
270
270
  const encoder = new TextEncoder();
@@ -4919,10 +4919,10 @@ class CheckboxControl {
4919
4919
  setValue() {
4920
4920
  return -1;
4921
4921
  }
4922
- setSelect() {
4922
+ setSelect(context = {}) {
4923
4923
  const { control } = this.element;
4924
- const elementList = this.control.getElementList();
4925
- const { startIndex } = this.control.getRange();
4924
+ const elementList = context.elementList || this.control.getElementList();
4925
+ const { startIndex } = context.range || this.control.getRange();
4926
4926
  const startElement = elementList[startIndex];
4927
4927
  const data2 = [];
4928
4928
  let preIndex = startIndex;
@@ -7497,6 +7497,18 @@ class TextParticle {
7497
7497
  return this.measureText(ctx, element).width;
7498
7498
  }
7499
7499
  measureText(ctx, element) {
7500
+ if (element.width) {
7501
+ const textMetrics2 = ctx.measureText(element.value);
7502
+ return {
7503
+ width: element.width,
7504
+ actualBoundingBoxAscent: textMetrics2.actualBoundingBoxAscent,
7505
+ actualBoundingBoxDescent: textMetrics2.actualBoundingBoxDescent,
7506
+ actualBoundingBoxLeft: textMetrics2.actualBoundingBoxLeft,
7507
+ actualBoundingBoxRight: textMetrics2.actualBoundingBoxRight,
7508
+ fontBoundingBoxAscent: textMetrics2.fontBoundingBoxAscent,
7509
+ fontBoundingBoxDescent: textMetrics2.fontBoundingBoxDescent
7510
+ };
7511
+ }
7500
7512
  const id = `${element.value}${ctx.font}`;
7501
7513
  const cacheTextMetrics = this.cacheMeasureText.get(id);
7502
7514
  if (cacheTextMetrics) {
@@ -8662,9 +8674,9 @@ class SelectControl {
8662
8674
  }
8663
8675
  return this.clearSelect();
8664
8676
  }
8665
- clearSelect() {
8666
- const elementList = this.control.getElementList();
8667
- const { startIndex } = this.control.getRange();
8677
+ clearSelect(context = {}) {
8678
+ const elementList = context.elementList || this.control.getElementList();
8679
+ const { startIndex } = context.range || this.control.getRange();
8668
8680
  const startElement = elementList[startIndex];
8669
8681
  let leftIndex = -1;
8670
8682
  let rightIndex = -1;
@@ -8694,7 +8706,7 @@ class SelectControl {
8694
8706
  this.element.control.code = null;
8695
8707
  return preIndex;
8696
8708
  }
8697
- setSelect(code) {
8709
+ setSelect(code, context = {}) {
8698
8710
  const control = this.element.control;
8699
8711
  const valueSets = control.valueSets;
8700
8712
  if (!Array.isArray(valueSets) || !valueSets.length)
@@ -8702,9 +8714,9 @@ class SelectControl {
8702
8714
  const valueSet = valueSets.find((v) => v.code === code);
8703
8715
  if (!valueSet)
8704
8716
  return;
8705
- const startIndex = this.clearSelect();
8717
+ const startIndex = this.clearSelect(context);
8706
8718
  this.control.removePlaceholder(startIndex);
8707
- const elementList = this.control.getElementList();
8719
+ const elementList = context.elementList || this.control.getElementList();
8708
8720
  const startElement = elementList[startIndex];
8709
8721
  const anchorElement = startElement.controlComponent === ControlComponent.PREFIX ? omitObject(startElement, EDITOR_ELEMENT_STYLE_ATTR) : startElement;
8710
8722
  const start = startIndex + 1;
@@ -8718,10 +8730,12 @@ class SelectControl {
8718
8730
  formatElementContext(elementList, [newElement], startIndex);
8719
8731
  draw.spliceElementList(elementList, start + i, 0, newElement);
8720
8732
  }
8721
- const newIndex = start + data2.length - 1;
8722
- this.control.repaintControl(newIndex);
8723
8733
  this.element.control.code = code;
8724
- this.destroy();
8734
+ if (!context.range) {
8735
+ const newIndex = start + data2.length - 1;
8736
+ this.control.repaintControl(newIndex);
8737
+ this.destroy();
8738
+ }
8725
8739
  }
8726
8740
  _createSelectPopupDom() {
8727
8741
  const control = this.element.control;
@@ -8816,9 +8830,9 @@ class TextControl {
8816
8830
  }
8817
8831
  return data2;
8818
8832
  }
8819
- setValue(data2) {
8820
- const elementList = this.control.getElementList();
8821
- const range = this.control.getRange();
8833
+ setValue(data2, context = {}) {
8834
+ const elementList = context.elementList || this.control.getElementList();
8835
+ const range = context.range || this.control.getRange();
8822
8836
  this.control.shrinkBoundary();
8823
8837
  const { startIndex, endIndex } = range;
8824
8838
  const draw = this.control.getDraw();
@@ -8839,6 +8853,17 @@ class TextControl {
8839
8853
  }
8840
8854
  return start + data2.length - 1;
8841
8855
  }
8856
+ clearValue(context = {}) {
8857
+ const elementList = context.elementList || this.control.getElementList();
8858
+ const range = context.range || this.control.getRange();
8859
+ const { startIndex, endIndex } = range;
8860
+ this.control.getDraw().spliceElementList(elementList, startIndex + 1, endIndex - startIndex);
8861
+ const value = this.getValue();
8862
+ if (!value.length) {
8863
+ this.control.addPlaceholder(startIndex);
8864
+ }
8865
+ return startIndex;
8866
+ }
8842
8867
  keydown(evt) {
8843
8868
  const elementList = this.control.getElementList();
8844
8869
  const range = this.control.getRange();
@@ -9217,6 +9242,135 @@ class Control {
9217
9242
  }
9218
9243
  return this.activeControl.cut();
9219
9244
  }
9245
+ getValueByConceptId(payload) {
9246
+ var _a;
9247
+ const { conceptId } = payload;
9248
+ const elementList = [
9249
+ ...this.draw.getHeaderElementList(),
9250
+ ...this.draw.getOriginalMainElementList(),
9251
+ ...this.draw.getFooterElementList()
9252
+ ];
9253
+ const result = [];
9254
+ let i = 0;
9255
+ while (i < elementList.length) {
9256
+ const element = elementList[i];
9257
+ i++;
9258
+ if (((_a = element == null ? void 0 : element.control) == null ? void 0 : _a.conceptId) !== conceptId)
9259
+ continue;
9260
+ const { type, code, valueSets } = element.control;
9261
+ let j = i;
9262
+ let textControlValue = "";
9263
+ while (j < elementList.length) {
9264
+ const nextElement = elementList[j];
9265
+ if (nextElement.controlId !== element.controlId)
9266
+ break;
9267
+ if (type === ControlType.TEXT && nextElement.controlComponent === ControlComponent.VALUE) {
9268
+ textControlValue += nextElement.value;
9269
+ }
9270
+ j++;
9271
+ }
9272
+ if (type === ControlType.TEXT) {
9273
+ result.push({
9274
+ value: textControlValue || null,
9275
+ innerText: textControlValue || null
9276
+ });
9277
+ } else if (type === ControlType.SELECT || type === ControlType.CHECKBOX) {
9278
+ const innerText = code == null ? void 0 : code.split(",").map((selectCode) => {
9279
+ var _a2;
9280
+ return (_a2 = valueSets == null ? void 0 : valueSets.find((valueSet) => valueSet.code === selectCode)) == null ? void 0 : _a2.value;
9281
+ }).filter(Boolean).join("");
9282
+ result.push({
9283
+ value: code || null,
9284
+ innerText: innerText || null
9285
+ });
9286
+ }
9287
+ i = j;
9288
+ }
9289
+ return result;
9290
+ }
9291
+ setValueByConceptId(payload) {
9292
+ var _a;
9293
+ const isReadonly = this.draw.isReadonly();
9294
+ if (isReadonly)
9295
+ return;
9296
+ let isExistSet = false;
9297
+ const { conceptId, value } = payload;
9298
+ const data2 = [
9299
+ this.draw.getHeaderElementList(),
9300
+ this.draw.getOriginalMainElementList(),
9301
+ this.draw.getFooterElementList()
9302
+ ];
9303
+ for (const elementList of data2) {
9304
+ let i = 0;
9305
+ while (i < elementList.length) {
9306
+ const element = elementList[i];
9307
+ i++;
9308
+ if (((_a = element == null ? void 0 : element.control) == null ? void 0 : _a.conceptId) !== conceptId)
9309
+ continue;
9310
+ isExistSet = true;
9311
+ const { type } = element.control;
9312
+ let currentEndIndex = i;
9313
+ while (currentEndIndex < elementList.length) {
9314
+ const nextElement = elementList[currentEndIndex];
9315
+ if (nextElement.controlId !== element.controlId)
9316
+ break;
9317
+ currentEndIndex++;
9318
+ }
9319
+ const fakeRange = {
9320
+ startIndex: i - 1,
9321
+ endIndex: currentEndIndex - 2
9322
+ };
9323
+ const controlContext = {
9324
+ range: fakeRange,
9325
+ elementList
9326
+ };
9327
+ if (type === ControlType.TEXT) {
9328
+ const formatValue = [{ value }];
9329
+ formatElementList(formatValue, {
9330
+ isHandleFirstElement: false,
9331
+ editorOptions: this.draw.getOptions()
9332
+ });
9333
+ const text = new TextControl(element, this);
9334
+ if (value) {
9335
+ text.setValue(formatValue, controlContext);
9336
+ } else {
9337
+ text.clearValue(controlContext);
9338
+ }
9339
+ } else if (type === ControlType.SELECT) {
9340
+ const select = new SelectControl(element, this);
9341
+ if (value) {
9342
+ select.setSelect(value, controlContext);
9343
+ } else {
9344
+ select.clearSelect(controlContext);
9345
+ }
9346
+ } else if (type === ControlType.CHECKBOX) {
9347
+ const checkbox = new CheckboxControl(element, this);
9348
+ const checkboxElementList = elementList.slice(fakeRange.startIndex + 1, fakeRange.endIndex + 1);
9349
+ const codes = (value == null ? void 0 : value.split(",")) || [];
9350
+ for (const checkElement of checkboxElementList) {
9351
+ if (checkElement.controlComponent === ControlComponent.CHECKBOX) {
9352
+ const checkboxItem = checkElement.checkbox;
9353
+ checkboxItem.value = codes.includes(checkboxItem.code);
9354
+ }
9355
+ }
9356
+ checkbox.setSelect(controlContext);
9357
+ }
9358
+ let newEndIndex = i;
9359
+ while (newEndIndex < elementList.length) {
9360
+ const nextElement = elementList[newEndIndex];
9361
+ if (nextElement.controlId !== element.controlId)
9362
+ break;
9363
+ newEndIndex++;
9364
+ }
9365
+ i = newEndIndex;
9366
+ }
9367
+ }
9368
+ if (isExistSet) {
9369
+ this.draw.render({
9370
+ isSetCursor: false
9371
+ });
9372
+ }
9373
+ }
9220
9374
  }
9221
9375
  class CheckboxParticle {
9222
9376
  constructor(draw) {
@@ -10840,6 +10994,14 @@ class ListParticle {
10840
10994
  const startElement = elementList[0];
10841
10995
  if (startElement.value !== ZERO || startElement.listWrap)
10842
10996
  return;
10997
+ let tabWidth = 0;
10998
+ const { defaultTabWidth, scale, defaultFont, defaultSize } = this.options;
10999
+ for (let i = 1; i < elementList.length; i++) {
11000
+ const element = elementList[i];
11001
+ if ((element == null ? void 0 : element.type) !== ElementType.TAB)
11002
+ break;
11003
+ tabWidth += defaultTabWidth * scale;
11004
+ }
10843
11005
  let text = "";
10844
11006
  if (startElement.listType === ListType.UL) {
10845
11007
  text = ulStyleMapping[startElement.listStyle] || ulStyleMapping[UlStyle.DISC];
@@ -10849,9 +11011,8 @@ class ListParticle {
10849
11011
  if (!text)
10850
11012
  return;
10851
11013
  const { coordinate: { leftTop: [startX, startY] } } = position;
10852
- const x = startX - offsetX;
11014
+ const x = startX - offsetX + tabWidth;
10853
11015
  const y = startY + ascent;
10854
- const { defaultFont, defaultSize, scale } = this.options;
10855
11016
  ctx.save();
10856
11017
  ctx.font = `${defaultSize * scale}px ${defaultFont}`;
10857
11018
  ctx.fillText(text, x, y);
@@ -12103,7 +12264,7 @@ class Draw {
12103
12264
  const extraWidth = rowElement.control.minWidth - controlRealWidth;
12104
12265
  if (extraWidth > 0) {
12105
12266
  const rowRemainingWidth = availableWidth - curRow.width - metrics.width;
12106
- const left = Math.min(rowRemainingWidth, extraWidth);
12267
+ const left = Math.min(rowRemainingWidth, extraWidth) * scale;
12107
12268
  rowElement.left = left;
12108
12269
  curRow.width += left;
12109
12270
  } else {
@@ -12289,6 +12450,9 @@ class Draw {
12289
12450
  this.blockParticle.render(pageNo, element, x, y);
12290
12451
  } else {
12291
12452
  this.textParticle.record(ctx, element, x, y + offsetY);
12453
+ if (element.width || element.letterSpacing) {
12454
+ this.textParticle.complete();
12455
+ }
12292
12456
  }
12293
12457
  if (element.underline || ((_a = element.control) == null ? void 0 : _a.underline)) {
12294
12458
  const rowMargin = defaultBasicRowMarginHeight * (element.rowMargin || defaultRowMargin) * scale;
@@ -12647,6 +12811,7 @@ class Command {
12647
12811
  __publicField(this, "executeSetGroup");
12648
12812
  __publicField(this, "executeDeleteGroup");
12649
12813
  __publicField(this, "executeLocationGroup");
12814
+ __publicField(this, "executeSetControlValue");
12650
12815
  __publicField(this, "getCatalog");
12651
12816
  __publicField(this, "getImage");
12652
12817
  __publicField(this, "getOptions");
@@ -12662,6 +12827,7 @@ class Command {
12662
12827
  __publicField(this, "getSearchNavigateInfo");
12663
12828
  __publicField(this, "getLocale");
12664
12829
  __publicField(this, "getGroupIds");
12830
+ __publicField(this, "getControlValue");
12665
12831
  this.executeMode = adapt.mode.bind(adapt);
12666
12832
  this.executeCut = adapt.cut.bind(adapt);
12667
12833
  this.executeCopy = adapt.copy.bind(adapt);
@@ -12756,6 +12922,8 @@ class Command {
12756
12922
  this.getSearchNavigateInfo = adapt.getSearchNavigateInfo.bind(adapt);
12757
12923
  this.getLocale = adapt.getLocale.bind(adapt);
12758
12924
  this.getGroupIds = adapt.getGroupIds.bind(adapt);
12925
+ this.executeSetControlValue = adapt.setControlValue.bind(adapt);
12926
+ this.getControlValue = adapt.getControlValue.bind(adapt);
12759
12927
  }
12760
12928
  }
12761
12929
  const defaultWatermarkOption = {
@@ -14590,6 +14758,15 @@ class CommandAdapt {
14590
14758
  isSubmitHistory: false
14591
14759
  });
14592
14760
  }
14761
+ getControlValue(payload) {
14762
+ return this.draw.getControl().getValueByConceptId(payload);
14763
+ }
14764
+ setControlValue(payload) {
14765
+ const isReadonly = this.draw.isReadonly();
14766
+ if (isReadonly)
14767
+ return;
14768
+ this.draw.getControl().setValueByConceptId(payload);
14769
+ }
14593
14770
  }
14594
14771
  class Listener {
14595
14772
  constructor() {