@hufe921/canvas-editor 0.9.94 → 0.9.95

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,32 @@
1
+ ## [0.9.95](https://github.com/Hufe921/canvas-editor/compare/v0.9.94...v0.9.95) (2024-10-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * date element update data boundary error #835 ([7f69fd9](https://github.com/Hufe921/canvas-editor/commit/7f69fd9ca2ea474167b10b0e122b745cffed2ab8)), closes [#835](https://github.com/Hufe921/canvas-editor/issues/835)
7
+ * previewer wheel event stop propagation ([ddf0806](https://github.com/Hufe921/canvas-editor/commit/ddf0806e3751c12c56523b987dc1031a85b17b69))
8
+ * set table context error when using directional keys ([b210ce3](https://github.com/Hufe921/canvas-editor/commit/b210ce39b1a440d8fecf7d222c5398b2025d3d68))
9
+
10
+
11
+ ### Chores
12
+
13
+ * update watermark option ([d14e720](https://github.com/Hufe921/canvas-editor/commit/d14e72001784202db5eeb7d9bb5ca76cce3cea3c))
14
+
15
+
16
+ ### Documentation
17
+
18
+ * update api markdown ([8c0f660](https://github.com/Hufe921/canvas-editor/commit/8c0f660bce8b2a579041af073e04de89913aa1a2))
19
+
20
+
21
+ ### Features
22
+
23
+ * add getKeywordContext api #846 ([abbb62d](https://github.com/Hufe921/canvas-editor/commit/abbb62df3bf45e64c67a7da3f7bbe666f4eb1328)), closes [#846](https://github.com/Hufe921/canvas-editor/issues/846)
24
+ * control element support set row flex #839 ([3f265c8](https://github.com/Hufe921/canvas-editor/commit/3f265c835b8f63bcc07b41596ab4dce886e99629)), closes [#839](https://github.com/Hufe921/canvas-editor/issues/839)
25
+ * export getElementListByHTML and getTextFromElementList api ([590c97d](https://github.com/Hufe921/canvas-editor/commit/590c97db225931d6bb4e117736a71be83cbb117e))
26
+ * remove row spacing from continuous tables #842 ([a4d8633](https://github.com/Hufe921/canvas-editor/commit/a4d863320bc8f9b2efa0390c09d58566faa62be9)), closes [#842](https://github.com/Hufe921/canvas-editor/issues/842)
27
+
28
+
29
+
1
30
  ## [0.9.94](https://github.com/Hufe921/canvas-editor/compare/v0.9.93...v0.9.94) (2024-10-07)
2
31
 
3
32
 
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
  var index = "";
26
- const version = "0.9.94";
26
+ const version = "0.9.95";
27
27
  var MaxHeightRatio;
28
28
  (function(MaxHeightRatio2) {
29
29
  MaxHeightRatio2["HALF"] = "half";
@@ -6701,7 +6701,7 @@ function left(evt, host) {
6701
6701
  tdIndex: preTdIndex,
6702
6702
  tdId: preTd.id,
6703
6703
  trId: preTr.id,
6704
- tableId: element.id
6704
+ tableId: element.tableId
6705
6705
  });
6706
6706
  anchorStartIndex = preTd.value.length - 1;
6707
6707
  anchorEndIndex = anchorStartIndex;
@@ -6840,7 +6840,7 @@ function right(evt, host) {
6840
6840
  tdIndex: nextTdIndex,
6841
6841
  tdId: preTd.id,
6842
6842
  trId: preTr.id,
6843
- tableId: element.id
6843
+ tableId: element.tableId
6844
6844
  });
6845
6845
  anchorStartIndex = 0;
6846
6846
  anchorEndIndex = anchorStartIndex;
@@ -6988,8 +6988,8 @@ function updown(evt, host) {
6988
6988
  index: index2,
6989
6989
  trIndex: preTrIndex,
6990
6990
  tdIndex: preTdIndex,
6991
- tdId: preTr.id,
6992
- trId: preTd.id,
6991
+ tdId: preTd.id,
6992
+ trId: preTr.id,
6993
6993
  tableId
6994
6994
  });
6995
6995
  anchorStartIndex = preTd.value.length - 1;
@@ -7032,8 +7032,8 @@ function updown(evt, host) {
7032
7032
  index: index2,
7033
7033
  trIndex: nexTrIndex,
7034
7034
  tdIndex: nextTdIndex,
7035
- tdId: nextTr.id,
7036
- trId: nextTd.id,
7035
+ tdId: nextTd.id,
7036
+ trId: nextTr.id,
7037
7037
  tableId
7038
7038
  });
7039
7039
  anchorStartIndex = nextTd.value.length - 1;
@@ -8822,7 +8822,7 @@ class RangeManager {
8822
8822
  } else {
8823
8823
  const { type, groupId, tableId, index: index2, tdIndex, trIndex } = searchMatch;
8824
8824
  const range = {
8825
- startIndex: index2 - 1,
8825
+ startIndex: index2,
8826
8826
  endIndex: index2
8827
8827
  };
8828
8828
  if (type === EditorContext.TABLE) {
@@ -13233,6 +13233,45 @@ class Control {
13233
13233
  direction
13234
13234
  });
13235
13235
  }
13236
+ setMinWidthControlInfo(option) {
13237
+ var _a, _b, _c, _d, _e;
13238
+ const { row, rowElement, controlRealWidth, availableWidth } = option;
13239
+ if (!((_a = rowElement.control) == null ? void 0 : _a.minWidth))
13240
+ return;
13241
+ const { scale } = this.options;
13242
+ const controlMinWidth = rowElement.control.minWidth * scale;
13243
+ let controlFirstElement = null;
13244
+ if (((_b = rowElement.control) == null ? void 0 : _b.minWidth) && (((_c = rowElement.control) == null ? void 0 : _c.rowFlex) === RowFlex.CENTER || ((_d = rowElement.control) == null ? void 0 : _d.rowFlex) === RowFlex.RIGHT)) {
13245
+ let controlContentWidth = rowElement.metrics.width;
13246
+ let controlElementIndex = row.elementList.length - 1;
13247
+ while (controlElementIndex >= 0) {
13248
+ const controlRowElement = row.elementList[controlElementIndex];
13249
+ controlContentWidth += controlRowElement.metrics.width;
13250
+ if (((_e = row.elementList[controlElementIndex - 1]) == null ? void 0 : _e.controlComponent) === ControlComponent.PREFIX) {
13251
+ controlFirstElement = controlRowElement;
13252
+ break;
13253
+ }
13254
+ controlElementIndex--;
13255
+ }
13256
+ if (controlFirstElement) {
13257
+ if (controlContentWidth < controlMinWidth) {
13258
+ if (rowElement.control.rowFlex === RowFlex.CENTER) {
13259
+ controlFirstElement.left = (controlMinWidth - controlContentWidth) / 2;
13260
+ } else if (rowElement.control.rowFlex === RowFlex.RIGHT) {
13261
+ controlFirstElement.left = controlMinWidth - controlContentWidth - rowElement.metrics.width;
13262
+ }
13263
+ }
13264
+ }
13265
+ }
13266
+ const extraWidth = controlMinWidth - controlRealWidth;
13267
+ if (extraWidth > 0) {
13268
+ const controlFirstElementLeft = (controlFirstElement == null ? void 0 : controlFirstElement.left) || 0;
13269
+ const rowRemainingWidth = availableWidth - row.width - rowElement.metrics.width;
13270
+ const left2 = Math.min(rowRemainingWidth, extraWidth);
13271
+ rowElement.left = left2 - controlFirstElementLeft;
13272
+ row.width += left2 - controlFirstElementLeft;
13273
+ }
13274
+ }
13236
13275
  }
13237
13276
  class CheckboxParticle {
13238
13277
  constructor(draw) {
@@ -13765,6 +13804,7 @@ class Previewer {
13765
13804
  };
13766
13805
  previewerContainer.onwheel = (evt) => {
13767
13806
  evt.preventDefault();
13807
+ evt.stopPropagation();
13768
13808
  if (evt.deltaY < 0) {
13769
13809
  scaleSize += 0.1;
13770
13810
  } else {
@@ -13884,7 +13924,7 @@ class DateParticle {
13884
13924
  if (startElement.type !== ElementType.DATE)
13885
13925
  return null;
13886
13926
  let preIndex = startIndex;
13887
- while (preIndex > 0) {
13927
+ while (preIndex >= 0) {
13888
13928
  const preElement = elementList[preIndex];
13889
13929
  if (preElement.dateId !== startElement.dateId) {
13890
13930
  leftIndex = preIndex;
@@ -16835,7 +16875,7 @@ class Draw {
16835
16875
  return defaultBasicRowMarginHeight * ((_a = el.rowMargin) != null ? _a : defaultRowMargin) * scale;
16836
16876
  }
16837
16877
  computeRowList(payload) {
16838
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
16878
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
16839
16879
  const { innerWidth, elementList, isPagingMode = false, isFromTable = false, startX = 0, startY = 0, pageHeight = 0, mainOuterHeight = 0, surroundElementList = [] } = payload;
16840
16880
  const { defaultSize, defaultRowMargin, scale, table: { tdPadding }, defaultTabWidth } = this.options;
16841
16881
  const defaultBasicRowMarginHeight = this.getDefaultBasicRowMarginHeight();
@@ -16988,13 +17028,16 @@ class Draw {
16988
17028
  metrics.height = elementHeight;
16989
17029
  metrics.boundingBoxDescent = elementHeight;
16990
17030
  metrics.boundingBoxAscent = -rowMargin;
17031
+ if (((_e = elementList[i + 1]) == null ? void 0 : _e.type) === ElementType.TABLE) {
17032
+ metrics.boundingBoxAscent -= rowMargin;
17033
+ }
16991
17034
  if (isPagingMode) {
16992
17035
  const height2 = this.getHeight();
16993
17036
  const marginHeight = this.getMainOuterHeight();
16994
17037
  let curPagePreHeight = marginHeight;
16995
17038
  for (let r = 0; r < rowList.length; r++) {
16996
17039
  const row = rowList[r];
16997
- if (row.height + curPagePreHeight > height2 || ((_e = rowList[r - 1]) == null ? void 0 : _e.isPageBreak)) {
17040
+ if (row.height + curPagePreHeight > height2 || ((_f = rowList[r - 1]) == null ? void 0 : _f.isPageBreak)) {
16998
17041
  curPagePreHeight = marginHeight + row.height;
16999
17042
  } else {
17000
17043
  curPagePreHeight += row.height;
@@ -17015,7 +17058,7 @@ class Draw {
17015
17058
  const trHeight = tr.height * scale;
17016
17059
  if (curPagePreHeight + rowMarginHeight + preTrHeight + trHeight > height2) {
17017
17060
  const rowColCount = tr.tdList.reduce((pre, cur) => pre + cur.colspan, 0);
17018
- if (((_f = element.colgroup) == null ? void 0 : _f.length) !== rowColCount) {
17061
+ if (((_g = element.colgroup) == null ? void 0 : _g.length) !== rowColCount) {
17019
17062
  deleteCount = 0;
17020
17063
  }
17021
17064
  break;
@@ -17139,18 +17182,17 @@ class Draw {
17139
17182
  left: 0,
17140
17183
  style: this.getElementFont(element, scale)
17141
17184
  });
17142
- if ((_g = rowElement.control) == null ? void 0 : _g.minWidth) {
17185
+ if ((_h = rowElement.control) == null ? void 0 : _h.minWidth) {
17143
17186
  if (rowElement.controlComponent) {
17144
17187
  controlRealWidth += metrics.width;
17145
17188
  }
17146
17189
  if (rowElement.controlComponent === ControlComponent.POSTFIX) {
17147
- const extraWidth = rowElement.control.minWidth - controlRealWidth;
17148
- if (extraWidth > 0) {
17149
- const rowRemainingWidth = availableWidth - curRow.width - metrics.width;
17150
- const left2 = Math.min(rowRemainingWidth, extraWidth) * scale;
17151
- rowElement.left = left2;
17152
- curRow.width += left2;
17153
- }
17190
+ this.control.setMinWidthControlInfo({
17191
+ row: curRow,
17192
+ rowElement,
17193
+ availableWidth,
17194
+ controlRealWidth
17195
+ });
17154
17196
  controlRealWidth = 0;
17155
17197
  }
17156
17198
  }
@@ -17207,10 +17249,10 @@ class Draw {
17207
17249
  elementList: [rowElement],
17208
17250
  ascent,
17209
17251
  rowIndex: curRow.rowIndex + 1,
17210
- rowFlex: ((_h = elementList[i]) == null ? void 0 : _h.rowFlex) || ((_i = elementList[i + 1]) == null ? void 0 : _i.rowFlex),
17252
+ rowFlex: ((_i = elementList[i]) == null ? void 0 : _i.rowFlex) || ((_j = elementList[i + 1]) == null ? void 0 : _j.rowFlex),
17211
17253
  isPageBreak: element.type === ElementType.PAGE_BREAK
17212
17254
  };
17213
- if (rowElement.controlComponent !== ControlComponent.PREFIX && ((_j = rowElement.control) == null ? void 0 : _j.indentation) === ControlIndentation.VALUE_START) {
17255
+ if (rowElement.controlComponent !== ControlComponent.PREFIX && ((_k = rowElement.control) == null ? void 0 : _k.indentation) === ControlIndentation.VALUE_START) {
17214
17256
  const preStartIndex = curRow.elementList.findIndex((el) => el.controlId === rowElement.controlId && el.controlComponent !== ControlComponent.PREFIX);
17215
17257
  if (~preStartIndex) {
17216
17258
  const preRowPositionList = this.position.computeRowPosition({
@@ -17243,7 +17285,7 @@ class Draw {
17243
17285
  if (isWrap || i === elementList.length - 1) {
17244
17286
  curRow.isWidthNotEnough = isWidthNotEnough && !isForceBreak;
17245
17287
  if (!curRow.isSurround && ((preElement == null ? void 0 : preElement.rowFlex) === RowFlex.JUSTIFY || (preElement == null ? void 0 : preElement.rowFlex) === RowFlex.ALIGNMENT && isWidthNotEnough)) {
17246
- const rowElementList = ((_k = curRow.elementList[0]) == null ? void 0 : _k.value) === ZERO ? curRow.elementList.slice(1) : curRow.elementList;
17288
+ const rowElementList = ((_l = curRow.elementList[0]) == null ? void 0 : _l.value) === ZERO ? curRow.elementList.slice(1) : curRow.elementList;
17247
17289
  const gap = (availableWidth - curRow.width) / (rowElementList.length - 1);
17248
17290
  for (let e = 0; e < rowElementList.length - 1; e++) {
17249
17291
  const el = rowElementList[e];
@@ -17348,7 +17390,7 @@ class Draw {
17348
17390
  }
17349
17391
  }
17350
17392
  drawRow(ctx, payload) {
17351
- var _a, _b, _c, _d, _e, _f;
17393
+ var _a, _b, _c, _d, _e, _f, _g;
17352
17394
  this._drawHighlight(ctx, payload);
17353
17395
  const { scale, table: { tdPadding }, group: group2, lineBreak } = this.options;
17354
17396
  const { rowList, pageNo, elementList, positionList, startIndex, zone: zone2, isDrawLineBreak = !lineBreak.disabled } = payload;
@@ -17466,9 +17508,9 @@ class Draw {
17466
17508
  if (element.type === ElementType.SUBSCRIPT) {
17467
17509
  offsetY2 = this.subscriptParticle.getOffsetY(element);
17468
17510
  }
17469
- const color = element.controlComponent === ControlComponent.PLACEHOLDER ? void 0 : element.color;
17470
- this.underline.recordFillInfo(ctx, x - offsetX, y + curRow.height - rowMargin + offsetY2, metrics.width + offsetX, 0, color, (_e = element.textDecoration) == null ? void 0 : _e.style);
17471
- } else if ((preElement == null ? void 0 : preElement.underline) || ((_f = preElement == null ? void 0 : preElement.control) == null ? void 0 : _f.underline)) {
17511
+ const color = ((_e = element.control) == null ? void 0 : _e.underline) ? this.options.underlineColor : element.color;
17512
+ this.underline.recordFillInfo(ctx, x - offsetX, y + curRow.height - rowMargin + offsetY2, metrics.width + offsetX, 0, color, (_f = element.textDecoration) == null ? void 0 : _f.style);
17513
+ } else if ((preElement == null ? void 0 : preElement.underline) || ((_g = preElement == null ? void 0 : preElement.control) == null ? void 0 : _g.underline)) {
17472
17514
  this.underline.render(ctx);
17473
17515
  }
17474
17516
  if (element.strikeout) {
@@ -17945,6 +17987,7 @@ class Command {
17945
17987
  __publicField(this, "getRangeRow");
17946
17988
  __publicField(this, "getRangeParagraph");
17947
17989
  __publicField(this, "getKeywordRangeList");
17990
+ __publicField(this, "getKeywordContext");
17948
17991
  __publicField(this, "getPaperMargin");
17949
17992
  __publicField(this, "getSearchNavigateInfo");
17950
17993
  __publicField(this, "getLocale");
@@ -18055,6 +18098,7 @@ class Command {
18055
18098
  this.getRangeRow = adapt.getRangeRow.bind(adapt);
18056
18099
  this.getRangeParagraph = adapt.getRangeParagraph.bind(adapt);
18057
18100
  this.getKeywordRangeList = adapt.getKeywordRangeList.bind(adapt);
18101
+ this.getKeywordContext = adapt.getKeywordContext.bind(adapt);
18058
18102
  this.getCatalog = adapt.getCatalog.bind(adapt);
18059
18103
  this.getPaperMargin = adapt.getPaperMargin.bind(adapt);
18060
18104
  this.getSearchNavigateInfo = adapt.getSearchNavigateInfo.bind(adapt);
@@ -19024,12 +19068,14 @@ class CommandAdapt {
19024
19068
  if (isReadonly)
19025
19069
  return;
19026
19070
  const options = this.draw.getOptions();
19027
- const { color, size, opacity, font } = defaultWatermarkOption;
19071
+ const { color, size, opacity, font, gap } = defaultWatermarkOption;
19028
19072
  options.watermark.data = payload.data;
19029
19073
  options.watermark.color = payload.color || color;
19030
19074
  options.watermark.size = payload.size || size;
19031
19075
  options.watermark.opacity = payload.opacity || opacity;
19032
19076
  options.watermark.font = payload.font || font;
19077
+ options.watermark.repeat = !!payload.repeat;
19078
+ options.watermark.gap = payload.gap || gap;
19033
19079
  this.draw.render({
19034
19080
  isSetCursor: false,
19035
19081
  isSubmitHistory: false,
@@ -19410,6 +19456,34 @@ class CommandAdapt {
19410
19456
  getKeywordRangeList(payload) {
19411
19457
  return this.range.getKeywordRangeList(payload);
19412
19458
  }
19459
+ getKeywordContext(payload) {
19460
+ var _a, _b, _c, _d;
19461
+ const rangeList = this.getKeywordRangeList(payload);
19462
+ if (!rangeList.length)
19463
+ return null;
19464
+ const searchResultContextList = [];
19465
+ const positionList = this.position.getOriginalMainPositionList();
19466
+ const elementList = this.draw.getOriginalMainElementList();
19467
+ for (let r = 0; r < rangeList.length; r++) {
19468
+ const range = rangeList[r];
19469
+ const { startIndex, endIndex, tableId, startTrIndex, startTdIndex } = range;
19470
+ let keywordPositionList = positionList;
19471
+ if (range.tableId) {
19472
+ const tableElement = elementList.find((el) => el.id === tableId);
19473
+ if (tableElement) {
19474
+ keywordPositionList = ((_d = (_c = (_b = (_a = tableElement.trList) == null ? void 0 : _a[startTrIndex]) == null ? void 0 : _b.tdList) == null ? void 0 : _c[startTdIndex]) == null ? void 0 : _d.positionList) || [];
19475
+ }
19476
+ }
19477
+ const startPosition = deepClone(keywordPositionList[startIndex]);
19478
+ const endPosition = deepClone(keywordPositionList[endIndex]);
19479
+ searchResultContextList.push({
19480
+ range,
19481
+ startPosition,
19482
+ endPosition
19483
+ });
19484
+ }
19485
+ return searchResultContextList;
19486
+ }
19413
19487
  pageMode(payload) {
19414
19488
  this.draw.setPageMode(payload);
19415
19489
  }
@@ -21039,5 +21113,5 @@ class Editor {
21039
21113
  this.use = plugin.use.bind(plugin);
21040
21114
  }
21041
21115
  }
21042
- export { BackgroundRepeat, BackgroundSize, BlockType, Command, ControlIndentation, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, INTERNAL_CONTEXT_MENU_KEY, ImageDisplay, KeyMap, LETTER_CLASS, LineNumberType, ListStyle, ListType, LocationPosition, MaxHeightRatio, NumberType, PageMode, PaperDirection, RenderMode, RowFlex, TableBorder, TdBorder, TdSlash, TextDecorationStyle, TitleLevel, VerticalAlign, WordBreak, createDomFromElementList, Editor as default, splitText };
21116
+ export { BackgroundRepeat, BackgroundSize, BlockType, Command, ControlIndentation, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, INTERNAL_CONTEXT_MENU_KEY, ImageDisplay, KeyMap, LETTER_CLASS, LineNumberType, ListStyle, ListType, LocationPosition, MaxHeightRatio, NumberType, PageMode, PaperDirection, RenderMode, RowFlex, TableBorder, TdBorder, TdSlash, TextDecorationStyle, TitleLevel, VerticalAlign, WordBreak, createDomFromElementList, Editor as default, getElementListByHTML, getTextFromElementList, splitText };
21043
21117
  //# sourceMappingURL=canvas-editor.es.js.map