@hufe921/canvas-editor 0.9.80 → 0.9.81

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.81](https://github.com/Hufe921/canvas-editor/compare/v0.9.80...v0.9.81) (2024-06-07)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * disable zone tip in continuous page mode #638 ([bf322df](https://github.com/Hufe921/canvas-editor/commit/bf322dfea334ee242a452c44fdb613a1937d963b)), closes [#638](https://github.com/Hufe921/canvas-editor/issues/638)
7
+ * some shortcut keys with shift are invalid #629 ([aca9d34](https://github.com/Hufe921/canvas-editor/commit/aca9d34a46004f2da207f7127f69430e4e59ab25)), closes [#629](https://github.com/Hufe921/canvas-editor/issues/629)
8
+
9
+
10
+ ### Documentation
11
+
12
+ * update start.md ([55bbe22](https://github.com/Hufe921/canvas-editor/commit/55bbe22578320319d9ab38b26ebbe8687b21f1c1))
13
+
14
+
15
+ ### Features
16
+
17
+ * add executeLocationControl api #592 ([53701fc](https://github.com/Hufe921/canvas-editor/commit/53701fc46c347595722801e8bca40647cda74bcb)), closes [#592](https://github.com/Hufe921/canvas-editor/issues/592)
18
+ * add maximum page number option #617 ([afce688](https://github.com/Hufe921/canvas-editor/commit/afce6882493c198595a0575640dd313c8cbdb14f)), closes [#617](https://github.com/Hufe921/canvas-editor/issues/617)
19
+ * add options to the getValue api ([65acd58](https://github.com/Hufe921/canvas-editor/commit/65acd580d6813bd15b8ee079b16ae8d5f9e77767))
20
+ * add selection info to rangeContext ([2df03ed](https://github.com/Hufe921/canvas-editor/commit/2df03ed3867cf8edf5fb656c017986af6725780c))
21
+ * set title style through executeSetHtml api #626 ([ac795b0](https://github.com/Hufe921/canvas-editor/commit/ac795b0bc45f99e92a5292a676414e1d7347cb7e)), closes [#626](https://github.com/Hufe921/canvas-editor/issues/626)
22
+
23
+
24
+ ### Tests
25
+
26
+ * update watermark test case ([c75482a](https://github.com/Hufe921/canvas-editor/commit/c75482a4f6f18da010963500e790780a63c061c4))
27
+
28
+
29
+
1
30
  ## [0.9.80](https://github.com/Hufe921/canvas-editor/compare/v0.9.79...v0.9.80) (2024-05-31)
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.80";
26
+ const version = "0.9.81";
27
27
  var MaxHeightRatio;
28
28
  (function(MaxHeightRatio2) {
29
29
  MaxHeightRatio2["HALF"] = "half";
@@ -4081,12 +4081,17 @@ function isSameElementExceptValue(source, target) {
4081
4081
  }
4082
4082
  return true;
4083
4083
  }
4084
- function pickElementAttr(payload) {
4084
+ function pickElementAttr(payload, option = {}) {
4085
+ const { extraPickAttrs } = option;
4086
+ const zipAttrs = EDITOR_ELEMENT_ZIP_ATTR;
4087
+ if (extraPickAttrs) {
4088
+ zipAttrs.push(...extraPickAttrs);
4089
+ }
4085
4090
  const element = {
4086
4091
  value: payload.value === ZERO ? `
4087
4092
  ` : payload.value
4088
4093
  };
4089
- EDITOR_ELEMENT_ZIP_ATTR.forEach((attr) => {
4094
+ zipAttrs.forEach((attr) => {
4090
4095
  const value = payload[attr];
4091
4096
  if (value !== void 0) {
4092
4097
  element[attr] = value;
@@ -4094,7 +4099,8 @@ function pickElementAttr(payload) {
4094
4099
  });
4095
4100
  return element;
4096
4101
  }
4097
- function zipElementList(payload) {
4102
+ function zipElementList(payload, options = {}) {
4103
+ const { extraPickAttrs } = options;
4098
4104
  const elementList = deepClone(payload);
4099
4105
  const zipElementListData = [];
4100
4106
  let e = 0;
@@ -4126,7 +4132,7 @@ function zipElementList(payload) {
4126
4132
  valueList.push(titleE);
4127
4133
  e++;
4128
4134
  }
4129
- titleElement.valueList = zipElementList(valueList);
4135
+ titleElement.valueList = zipElementList(valueList, options);
4130
4136
  element = titleElement;
4131
4137
  }
4132
4138
  } else if (element.listId && element.listType) {
@@ -4153,7 +4159,7 @@ function zipElementList(payload) {
4153
4159
  valueList.push(listE);
4154
4160
  e++;
4155
4161
  }
4156
- listElement.valueList = zipElementList(valueList);
4162
+ listElement.valueList = zipElementList(valueList, options);
4157
4163
  element = listElement;
4158
4164
  }
4159
4165
  } else if (element.type === ElementType.TABLE) {
@@ -4182,7 +4188,7 @@ function zipElementList(payload) {
4182
4188
  const zipTd = {
4183
4189
  colspan: td.colspan,
4184
4190
  rowspan: td.rowspan,
4185
- value: zipElementList(td.value)
4191
+ value: zipElementList(td.value, options)
4186
4192
  };
4187
4193
  TABLE_TD_ZIP_ATTR.forEach((attr) => {
4188
4194
  const value = td[attr];
@@ -4214,7 +4220,7 @@ function zipElementList(payload) {
4214
4220
  valueList.push(hyperlinkE);
4215
4221
  e++;
4216
4222
  }
4217
- hyperlinkElement.valueList = zipElementList(valueList);
4223
+ hyperlinkElement.valueList = zipElementList(valueList, options);
4218
4224
  element = hyperlinkElement;
4219
4225
  }
4220
4226
  } else if (element.type === ElementType.DATE) {
@@ -4237,7 +4243,7 @@ function zipElementList(payload) {
4237
4243
  valueList.push(dateE);
4238
4244
  e++;
4239
4245
  }
4240
- dateElement.valueList = zipElementList(valueList);
4246
+ dateElement.valueList = zipElementList(valueList, options);
4241
4247
  element = dateElement;
4242
4248
  }
4243
4249
  } else if (element.controlId) {
@@ -4248,7 +4254,8 @@ function zipElementList(payload) {
4248
4254
  const controlElement = __spreadProps(__spreadValues({}, pickObject(element, EDITOR_ROW_ATTR)), {
4249
4255
  type: ElementType.CONTROL,
4250
4256
  value: "",
4251
- control
4257
+ control,
4258
+ controlId
4252
4259
  });
4253
4260
  const valueList = [];
4254
4261
  while (e < elementList.length) {
@@ -4264,16 +4271,16 @@ function zipElementList(payload) {
4264
4271
  }
4265
4272
  e++;
4266
4273
  }
4267
- controlElement.control.value = zipElementList(valueList);
4268
- element = controlElement;
4274
+ controlElement.control.value = zipElementList(valueList, options);
4275
+ element = pickElementAttr(controlElement, { extraPickAttrs });
4269
4276
  }
4270
4277
  }
4271
- const pickElement = pickElementAttr(element);
4278
+ const pickElement = pickElementAttr(element, { extraPickAttrs });
4272
4279
  if (!element.type || element.type === ElementType.TEXT || element.type === ElementType.SUBSCRIPT || element.type === ElementType.SUPERSCRIPT) {
4273
4280
  while (e < elementList.length) {
4274
4281
  const nextElement = elementList[e + 1];
4275
4282
  e++;
4276
- if (nextElement && isSameElementExceptValue(pickElement, pickElementAttr(nextElement))) {
4283
+ if (nextElement && isSameElementExceptValue(pickElement, pickElementAttr(nextElement, { extraPickAttrs }))) {
4277
4284
  const nextValue = nextElement.value === ZERO ? "\n" : nextElement.value;
4278
4285
  pickElement.value += nextValue;
4279
4286
  } else {
@@ -4692,7 +4699,7 @@ function getElementListByHTML(htmlText, options) {
4692
4699
  }
4693
4700
  } else if (/H[1-6]/.test(node.nodeName)) {
4694
4701
  const hElement = node;
4695
- const valueList = getElementListByHTML(hElement.innerHTML, options);
4702
+ const valueList = getElementListByHTML(replaceHTMLElementTag(hElement, "div").outerHTML, options);
4696
4703
  elementList.push({
4697
4704
  value: "",
4698
4705
  type: ElementType.TITLE,
@@ -4900,6 +4907,15 @@ function getSlimCloneElementList(elementList) {
4900
4907
  function getIsBlockElement(element) {
4901
4908
  return !!(element == null ? void 0 : element.type) && (BLOCK_ELEMENT_TYPE.includes(element.type) || element.imgDisplay === ImageDisplay.INLINE);
4902
4909
  }
4910
+ function replaceHTMLElementTag(oldDom, tagName) {
4911
+ const newDom = document.createElement(tagName);
4912
+ for (let i = 0; i < oldDom.attributes.length; i++) {
4913
+ const attr = oldDom.attributes[i];
4914
+ newDom.setAttribute(attr.name, attr.value);
4915
+ }
4916
+ newDom.innerHTML = oldDom.innerHTML;
4917
+ return newDom;
4918
+ }
4903
4919
  function setClipboardData(data2) {
4904
4920
  localStorage.setItem(EDITOR_CLIPBOARD, JSON.stringify({
4905
4921
  text: data2.text,
@@ -9200,7 +9216,8 @@ const defaultPageNumberOption = {
9200
9216
  numberType: NumberType.ARABIC,
9201
9217
  disabled: false,
9202
9218
  startPageNo: 1,
9203
- fromPageNo: 0
9219
+ fromPageNo: 0,
9220
+ maxPageNo: null
9204
9221
  };
9205
9222
  class PageNumber {
9206
9223
  constructor(draw) {
@@ -12277,7 +12294,9 @@ class Control {
12277
12294
  for (const elementList of data2) {
12278
12295
  getControlElementList(elementList);
12279
12296
  }
12280
- return zipElementList(controlElementList);
12297
+ return zipElementList(controlElementList, {
12298
+ extraPickAttrs: ["controlId"]
12299
+ });
12281
12300
  }
12282
12301
  recordBorderInfo(x, y, width, height) {
12283
12302
  this.controlBorder.recordBorderInfo(x, y, width, height);
@@ -13548,6 +13567,7 @@ class ImageObserver {
13548
13567
  }
13549
13568
  class ZoneTip {
13550
13569
  constructor(draw, zone2) {
13570
+ __publicField(this, "draw");
13551
13571
  __publicField(this, "zone");
13552
13572
  __publicField(this, "i18n");
13553
13573
  __publicField(this, "container");
@@ -13556,6 +13576,7 @@ class ZoneTip {
13556
13576
  __publicField(this, "tipContainer");
13557
13577
  __publicField(this, "tipContent");
13558
13578
  __publicField(this, "currentMoveZone");
13579
+ this.draw = draw;
13559
13580
  this.zone = zone2;
13560
13581
  this.i18n = draw.getI18n();
13561
13582
  this.container = draw.getContainer();
@@ -13579,7 +13600,7 @@ class ZoneTip {
13579
13600
  }
13580
13601
  _watchMouseMoveZoneChange(watchZones) {
13581
13602
  this.pageContainer.addEventListener("mousemove", throttle((evt) => {
13582
- if (this.isDisableMouseMove)
13603
+ if (this.isDisableMouseMove || !this.draw.getIsPagingMode())
13583
13604
  return;
13584
13605
  if (!evt.offsetY)
13585
13606
  return;
@@ -15048,7 +15069,6 @@ class Draw {
15048
15069
  });
15049
15070
  }
15050
15071
  getValue(options = {}) {
15051
- const { width, height, margins, watermark } = this.options;
15052
15072
  const { pageNo } = options;
15053
15073
  let mainElementList = this.elementList;
15054
15074
  if (Number.isInteger(pageNo) && pageNo >= 0 && pageNo < this.pageRowList.length) {
@@ -15061,11 +15081,8 @@ class Draw {
15061
15081
  };
15062
15082
  return {
15063
15083
  version,
15064
- width,
15065
- height,
15066
- margins,
15067
- watermark: watermark.data ? watermark : void 0,
15068
- data: data2
15084
+ data: data2,
15085
+ options: deepClone(this.options)
15069
15086
  };
15070
15087
  }
15071
15088
  setValue(payload) {
@@ -15558,7 +15575,7 @@ class Draw {
15558
15575
  _computePageList() {
15559
15576
  var _a;
15560
15577
  const pageRowList = [[]];
15561
- const { pageMode } = this.options;
15578
+ const { pageMode, pageNumber: { maxPageNo } } = this.options;
15562
15579
  const height = this.getHeight();
15563
15580
  const marginHeight = this.getMainOuterHeight();
15564
15581
  let pageHeight = marginHeight;
@@ -15582,6 +15599,10 @@ class Draw {
15582
15599
  for (let i = 0; i < this.rowList.length; i++) {
15583
15600
  const row = this.rowList[i];
15584
15601
  if (row.height + pageHeight > height || ((_a = this.rowList[i - 1]) == null ? void 0 : _a.isPageBreak)) {
15602
+ if (Number.isInteger(maxPageNo) && pageNo >= maxPageNo) {
15603
+ this.elementList = this.elementList.slice(0, row.startIndex);
15604
+ break;
15605
+ }
15585
15606
  pageHeight = marginHeight + row.height;
15586
15607
  pageRowList.push([row]);
15587
15608
  pageNo++;
@@ -16157,6 +16178,7 @@ class Command {
16157
16178
  __publicField(this, "executeSetControlExtension");
16158
16179
  __publicField(this, "executeSetControlProperties");
16159
16180
  __publicField(this, "executeSetControlHighlight");
16181
+ __publicField(this, "executeLocationControl");
16160
16182
  __publicField(this, "executeUpdateOptions");
16161
16183
  __publicField(this, "executeInsertTitle");
16162
16184
  __publicField(this, "getCatalog");
@@ -16291,6 +16313,7 @@ class Command {
16291
16313
  this.executeSetControlHighlight = adapt.setControlHighlight.bind(adapt);
16292
16314
  this.getControlValue = adapt.getControlValue.bind(adapt);
16293
16315
  this.getControlList = adapt.getControlList.bind(adapt);
16316
+ this.executeLocationControl = adapt.locationControl.bind(adapt);
16294
16317
  }
16295
16318
  }
16296
16319
  const defaultWatermarkOption = {
@@ -18308,6 +18331,8 @@ class CommandAdapt {
18308
18331
  if (!~startIndex && !~endIndex)
18309
18332
  return null;
18310
18333
  const isCollapsed = startIndex === endIndex;
18334
+ const selectionText = this.range.toString();
18335
+ const selectionElementList = zipElementList(this.range.getSelectionElementList() || []);
18311
18336
  const elementList = this.draw.getElementList();
18312
18337
  const startElement = pickElementAttr(elementList[isCollapsed ? startIndex : startIndex + 1]);
18313
18338
  const endElement = pickElementAttr(elementList[endIndex]);
@@ -18375,7 +18400,9 @@ class CommandAdapt {
18375
18400
  isTable,
18376
18401
  trIndex: trIndex != null ? trIndex : null,
18377
18402
  tdIndex: tdIndex != null ? tdIndex : null,
18378
- tableElement
18403
+ tableElement,
18404
+ selectionText,
18405
+ selectionElementList
18379
18406
  });
18380
18407
  }
18381
18408
  getRangeRow() {
@@ -18605,6 +18632,80 @@ class CommandAdapt {
18605
18632
  getControlList() {
18606
18633
  return this.draw.getControl().getList();
18607
18634
  }
18635
+ locationControl(controlId) {
18636
+ function location(elementList, zone2) {
18637
+ let i = 0;
18638
+ while (i < elementList.length) {
18639
+ const element = elementList[i];
18640
+ i++;
18641
+ if (element.type === ElementType.TABLE) {
18642
+ const trList = element.trList;
18643
+ for (let r = 0; r < trList.length; r++) {
18644
+ const tr = trList[r];
18645
+ for (let d = 0; d < tr.tdList.length; d++) {
18646
+ const td = tr.tdList[d];
18647
+ const locationContext = location(td.value, zone2);
18648
+ if (locationContext) {
18649
+ return __spreadProps(__spreadValues({}, locationContext), {
18650
+ positionContext: {
18651
+ isTable: true,
18652
+ index: i - 1,
18653
+ trIndex: r,
18654
+ tdIndex: d,
18655
+ tdId: element.tdId,
18656
+ trId: element.trId,
18657
+ tableId: element.tableId
18658
+ }
18659
+ });
18660
+ }
18661
+ }
18662
+ }
18663
+ }
18664
+ if ((element == null ? void 0 : element.controlId) !== controlId)
18665
+ continue;
18666
+ const curIndex = i - 1;
18667
+ return {
18668
+ zone: zone2,
18669
+ range: {
18670
+ startIndex: curIndex,
18671
+ endIndex: curIndex
18672
+ },
18673
+ positionContext: {
18674
+ isTable: false
18675
+ }
18676
+ };
18677
+ }
18678
+ return null;
18679
+ }
18680
+ const data2 = [
18681
+ {
18682
+ zone: EditorZone.HEADER,
18683
+ elementList: this.draw.getHeaderElementList()
18684
+ },
18685
+ {
18686
+ zone: EditorZone.MAIN,
18687
+ elementList: this.draw.getOriginalMainElementList()
18688
+ },
18689
+ {
18690
+ zone: EditorZone.FOOTER,
18691
+ elementList: this.draw.getFooterElementList()
18692
+ }
18693
+ ];
18694
+ for (const context of data2) {
18695
+ const locationContext = location(context.elementList, context.zone);
18696
+ if (locationContext) {
18697
+ this.setZone(locationContext.zone);
18698
+ this.position.setPositionContext(locationContext.positionContext);
18699
+ this.range.replaceRange(locationContext.range);
18700
+ this.draw.render({
18701
+ curIndex: locationContext.range.startIndex,
18702
+ isCompute: false,
18703
+ isSubmitHistory: false
18704
+ });
18705
+ break;
18706
+ }
18707
+ }
18708
+ }
18608
18709
  getContainer() {
18609
18710
  return this.draw.getContainer();
18610
18711
  }
@@ -19483,7 +19584,7 @@ class ContextMenu {
19483
19584
  }
19484
19585
  const richtextKeys = [
19485
19586
  {
19486
- key: KeyMap.X_UPPERCASE,
19587
+ key: KeyMap.X,
19487
19588
  ctrl: true,
19488
19589
  shift: true,
19489
19590
  callback: (command) => {
@@ -19700,7 +19801,7 @@ class Shortcut {
19700
19801
  var _a;
19701
19802
  for (let s = 0; s < shortCutList.length; s++) {
19702
19803
  const shortCut = shortCutList[s];
19703
- if ((shortCut.mod ? isMod(evt) === !!shortCut.mod : evt.ctrlKey === !!shortCut.ctrl && evt.metaKey === !!shortCut.meta) && evt.shiftKey === !!shortCut.shift && evt.altKey === !!shortCut.alt && evt.key === shortCut.key) {
19804
+ if ((shortCut.mod ? isMod(evt) === !!shortCut.mod : evt.ctrlKey === !!shortCut.ctrl && evt.metaKey === !!shortCut.meta) && evt.shiftKey === !!shortCut.shift && evt.altKey === !!shortCut.alt && evt.key.toLowerCase() === shortCut.key.toLowerCase()) {
19704
19805
  if (!shortCut.disable) {
19705
19806
  (_a = shortCut == null ? void 0 : shortCut.callback) == null ? void 0 : _a.call(shortCut, this.command);
19706
19807
  evt.preventDefault();