@ones-editor/editor 2.2.11 → 2.2.12-beta.2

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/dist/index.js CHANGED
@@ -5836,6 +5836,7 @@ div.editor-root:not(.mobile) div.editor-content div[data-type=editor-container]
5836
5836
  flex: 1;
5837
5837
  align-items: center;
5838
5838
  justify-content: center;
5839
+ overflow: hidden;
5839
5840
  }
5840
5841
  .version-dialog .version-loading svg {
5841
5842
  width: 28px;
@@ -9885,7 +9886,7 @@ var __publicField = (obj, key, value) => {
9885
9886
  removeStyle(CURSOR_TYPE_ID);
9886
9887
  }
9887
9888
  }
9888
- const MIN_DISTANCE_THRESHOLD$1 = 3;
9889
+ const MIN_DISTANCE_THRESHOLD$3 = 3;
9889
9890
  const logger$4C = getLogger("drag-drop");
9890
9891
  class DragDrop {
9891
9892
  constructor(options) {
@@ -9916,7 +9917,7 @@ var __publicField = (obj, key, value) => {
9916
9917
  this.onDragging(event, deltaX, deltaY);
9917
9918
  return;
9918
9919
  }
9919
- const threshold = (_a = this.options.minThreshold) != null ? _a : MIN_DISTANCE_THRESHOLD$1;
9920
+ const threshold = (_a = this.options.minThreshold) != null ? _a : MIN_DISTANCE_THRESHOLD$3;
9920
9921
  if (Math.abs(deltaX) >= threshold || Math.abs(deltaY) >= threshold) {
9921
9922
  this.onDragStart(this.mouseDownEvent);
9922
9923
  }
@@ -11448,7 +11449,7 @@ var __publicField = (obj, key, value) => {
11448
11449
  return block;
11449
11450
  }
11450
11451
  const logger$4p = getLogger("root-container");
11451
- const MIN_DISTANCE_THRESHOLD = 3;
11452
+ const MIN_DISTANCE_THRESHOLD$2 = 3;
11452
11453
  class RootContainer {
11453
11454
  constructor(editor, rootContainer) {
11454
11455
  __publicField(this, "resizeObserver");
@@ -11546,7 +11547,7 @@ var __publicField = (obj, key, value) => {
11546
11547
  return;
11547
11548
  }
11548
11549
  if (target instanceof HTMLElement && target.draggable) {
11549
- this.editor.selectionHandler.handleMouseDown(event, { autoScroll: false });
11550
+ this.editor.selectionHandler.handleMouseDown(event);
11550
11551
  this.editor.selectionHandler.stopSelection();
11551
11552
  this.editor.input.focus();
11552
11553
  return;
@@ -11558,7 +11559,7 @@ var __publicField = (obj, key, value) => {
11558
11559
  } else {
11559
11560
  document.addEventListener("touchend", this.handleMouseUp);
11560
11561
  }
11561
- this.editor.selectionHandler.handleMouseDown(event, { autoScroll: true });
11562
+ this.editor.selectionHandler.handleMouseDown(event);
11562
11563
  }
11563
11564
  this.editor.input.focus({ preventScroll: true });
11564
11565
  });
@@ -11568,7 +11569,7 @@ var __publicField = (obj, key, value) => {
11568
11569
  return;
11569
11570
  const deltaX = event.x - this.mouseDownEvent.x;
11570
11571
  const deltaY = event.y - this.mouseDownEvent.y;
11571
- if (Math.abs(deltaX) >= MIN_DISTANCE_THRESHOLD || Math.abs(deltaY) >= MIN_DISTANCE_THRESHOLD) {
11572
+ if (Math.abs(deltaX) >= MIN_DISTANCE_THRESHOLD$2 || Math.abs(deltaY) >= MIN_DISTANCE_THRESHOLD$2) {
11572
11573
  this.editor.selectionHandler.handleMouseMove(event);
11573
11574
  this.isMoved = true;
11574
11575
  }
@@ -11807,7 +11808,7 @@ var __publicField = (obj, key, value) => {
11807
11808
  function isRootBlock(block) {
11808
11809
  return isRootContainer(getParentContainer(block));
11809
11810
  }
11810
- function getBlockProperties$e(editor, block) {
11811
+ function getBlockProperties$d(editor, block) {
11811
11812
  var _a;
11812
11813
  const blockClass = getBlockClass(editor, block);
11813
11814
  const properties = (_a = blockClass.getBlockProperties) == null ? void 0 : _a.call(blockClass, editor, block);
@@ -12422,7 +12423,7 @@ var __publicField = (obj, key, value) => {
12422
12423
  }
12423
12424
  return embed.convertTo(editor, blockData, doc2, type);
12424
12425
  }
12425
- function getBlockProperties$d(editor, block) {
12426
+ function getBlockProperties$c(editor, block) {
12426
12427
  const embedClass = getEmbedClassFromBlock(editor, block);
12427
12428
  if (embedClass.getBlockProperties) {
12428
12429
  return embedClass.getBlockProperties(editor, block);
@@ -12521,7 +12522,7 @@ var __publicField = (obj, key, value) => {
12521
12522
  clearSelection: clearSelection$5,
12522
12523
  convertFrom: convertFrom$9,
12523
12524
  convertTo: convertTo$l,
12524
- getBlockProperties: getBlockProperties$d,
12525
+ getBlockProperties: getBlockProperties$c,
12525
12526
  getOptions: getOptions$9,
12526
12527
  handleDeleteBlock: handleDeleteBlock$5,
12527
12528
  handleUpdateBlock: handleUpdateBlock$6,
@@ -24409,49 +24410,6 @@ var __publicField = (obj, key, value) => {
24409
24410
  function getClientRects$1(editor, block, range) {
24410
24411
  return getRangeClientRects(editor, block, range);
24411
24412
  }
24412
- function getAbstractByBlockText(editor, blockText) {
24413
- let res = "";
24414
- blockText.forEach((op) => {
24415
- var _a, _b, _c;
24416
- if (!op.insert) {
24417
- return;
24418
- }
24419
- if (op.attributes && op.attributes.box === true) {
24420
- const box = editor.getBoxById(op.attributes.id);
24421
- const properties = (_b = (_a = editor.editorBoxes.getBoxClass(op.attributes.type)).getBoxProperties) == null ? void 0 : _b.call(_a, editor, box);
24422
- res += (_c = properties == null ? void 0 : properties.abstract) != null ? _c : " ";
24423
- return;
24424
- }
24425
- res += op.insert;
24426
- });
24427
- return res.trim();
24428
- }
24429
- function getBlockProperties$c(editor, block) {
24430
- assert(logger$3L, isTextKindBlock(editor, block), "block in not textBlock");
24431
- const range = editor.selection.range;
24432
- let abstract = "";
24433
- if (range.isCollapsed()) {
24434
- const blockText = editor.getBlockText(block);
24435
- abstract = getAbstractByBlockText(editor, blockText);
24436
- } else {
24437
- const blockId = getBlockId(block);
24438
- const selectedBlock = getAllSelectedBlocks(editor, { simpleBlockOnly: true }).find((b) => getBlockId(b.block) === blockId);
24439
- if (selectedBlock && !isEmptyTextBlock(editor, selectedBlock.block)) {
24440
- assert(logger$3L, selectedBlock.block === block, "block not match");
24441
- const blockOps = editor.getBlockText(block);
24442
- const { start, end } = selectedBlock;
24443
- const offset = start.offset;
24444
- const length = end.offset - offset;
24445
- if (length > 0) {
24446
- const { middle } = splitToThree(blockOps, offset, length);
24447
- abstract = getAbstractByBlockText(editor, middle);
24448
- }
24449
- }
24450
- }
24451
- return {
24452
- abstract: abstract.trim()
24453
- };
24454
- }
24455
24413
  function convertTo$k(editor, blockData, doc2, type) {
24456
24414
  assert(logger$3L, blockData.text, "no text for text block");
24457
24415
  if (type === "text") {
@@ -24495,7 +24453,6 @@ var __publicField = (obj, key, value) => {
24495
24453
  getCaretRect: getTextCaretRect,
24496
24454
  getClientRects: getClientRects$1,
24497
24455
  setBlockText: updateBlockText$1,
24498
- getBlockProperties: getBlockProperties$c,
24499
24456
  convertTo: convertTo$k,
24500
24457
  blockToDoc: blockToDoc$1
24501
24458
  };
@@ -28090,9 +28047,8 @@ var __publicField = (obj, key, value) => {
28090
28047
  __publicField(this, "startPos", null);
28091
28048
  __publicField(this, "lastCaretRect");
28092
28049
  __publicField(this, "mouseDownEvent", null);
28093
- __publicField(this, "autoScroll", null);
28094
- __publicField(this, "handleMouseDown", (event, options) => {
28095
- var _a;
28050
+ __publicField(this, "autoScroll");
28051
+ __publicField(this, "handleMouseDown", (event) => {
28096
28052
  this.mouseDownEvent = event;
28097
28053
  const x = ensureIsMobileEvent(event) ? event.changedTouches[0].clientX : event.x;
28098
28054
  const y = ensureIsMobileEvent(event) ? event.changedTouches[0].clientY : event.y;
@@ -28101,30 +28057,16 @@ var __publicField = (obj, key, value) => {
28101
28057
  if (range instanceof EditorComplexSelectionRange) {
28102
28058
  return;
28103
28059
  }
28104
- if (!this.autoScroll && options.autoScroll) {
28105
- const selectedBlocks = range.getSelectedBlocks();
28106
- const scrollElement = getScrollContainer$1(selectedBlocks[0].block);
28107
- this.autoScroll = new AutoScroll({
28108
- scrollElement,
28109
- edge: {
28110
- top: 50,
28111
- bottom: 50
28112
- }
28113
- });
28114
- }
28115
28060
  const oldRange = this.editor.selection.range;
28116
28061
  if (event.shiftKey && oldRange.isSimple()) {
28117
28062
  const oldAnchor = oldRange.anchor;
28118
- this.editor.selection.setSelection(oldAnchor, range.focus);
28063
+ this.editor.selection.setSelection(oldAnchor, range.focus, { noScroll: true });
28119
28064
  this.startPos = range.start;
28120
28065
  } else {
28121
- this.editor.selection.setSelection(range.anchor, range.focus);
28066
+ this.editor.selection.setSelection(range.anchor, range.focus, { noScroll: true });
28122
28067
  this.startPos = range.start;
28123
28068
  }
28124
28069
  this.editor.selection.updateLastCaretRect();
28125
- if (options.autoScroll) {
28126
- (_a = this.autoScroll) == null ? void 0 : _a.active();
28127
- }
28128
28070
  }
28129
28071
  });
28130
28072
  __publicField(this, "handleMouseMove", (event) => {
@@ -28141,21 +28083,28 @@ var __publicField = (obj, key, value) => {
28141
28083
  if (!range) {
28142
28084
  return;
28143
28085
  }
28086
+ this.autoScroll.active();
28144
28087
  const adjusted = adjustSelectionPos$1(this.editor, this.startPos, range.end);
28145
28088
  if (!adjusted) {
28146
28089
  return;
28147
28090
  }
28148
28091
  const { anchor: anchor2, focus } = adjusted;
28149
- this.editor.selection.setSelection(anchor2, focus);
28092
+ this.editor.selection.setSelection(anchor2, focus, { noScroll: true });
28150
28093
  });
28151
28094
  __publicField(this, "handleMouseUp", (event) => {
28152
- var _a;
28153
- (_a = this.autoScroll) == null ? void 0 : _a.inactive();
28095
+ this.autoScroll.inactive();
28154
28096
  this.startPos = null;
28155
28097
  });
28156
28098
  this.editor = editor;
28157
28099
  this.startPos = null;
28158
28100
  this.lastCaretRect = new DOMRect();
28101
+ this.autoScroll = new AutoScroll({
28102
+ scrollElement: editor.scrollContainer,
28103
+ edge: {
28104
+ top: 50,
28105
+ bottom: 50
28106
+ }
28107
+ });
28159
28108
  }
28160
28109
  isSelecting() {
28161
28110
  return this.startPos !== null;
@@ -51759,10 +51708,6 @@ ${codeText}
51759
51708
  return;
51760
51709
  }
51761
51710
  }
51762
- if (isTitleBlock$2(firstBlock.block)) {
51763
- this.toolbar.close("selectionChange");
51764
- return;
51765
- }
51766
51711
  this.toolbar.updateItems(commands);
51767
51712
  const lastBlock2 = selectedBlocks[selectedBlocks.length - 1];
51768
51713
  const reverseToolbar = !this.editor.selection.range.isReverse() && lastBlock2 !== firstBlock;
@@ -60495,17 +60440,6 @@ $$${mathData.mathjaxText}$$
60495
60440
  return true;
60496
60441
  }
60497
60442
  }
60498
- function getCommentAbstract(editor, blocks) {
60499
- return blocks.map((block) => {
60500
- var _a, _b;
60501
- const blockClass = getBlockClass(editor, block);
60502
- const blockProperties = (_a = blockClass.getBlockProperties) == null ? void 0 : _a.call(blockClass, editor, block);
60503
- if (isEmbedBlock(block) || isComplexKindBlock(editor, block)) {
60504
- return (blockProperties == null ? void 0 : blockProperties.abstract) ? `[${blockProperties.abstract}]` : "";
60505
- }
60506
- return (_b = blockProperties == null ? void 0 : blockProperties.abstract) != null ? _b : "";
60507
- }).join(" ");
60508
- }
60509
60443
  function getCommentAbstractFromSelectedBlocks(editor, blocks) {
60510
60444
  return blocks.map((selectedBlock) => {
60511
60445
  var _a, _b;
@@ -60560,7 +60494,9 @@ $$${mathData.mathjaxText}$$
60560
60494
  editor.updateBlockData(block, newData);
60561
60495
  }
60562
60496
  function addCommentToBlock$1(editor, block, provider) {
60563
- const abstract = getCommentAbstract(editor, [block]);
60497
+ const { start, end } = createBlockSimpleRange(editor, block, 0, getBlockTextLength$6(editor, block));
60498
+ const selectedBlock = { block, start, end };
60499
+ const abstract = getCommentAbstractFromSelectedBlocks(editor, [selectedBlock]);
60564
60500
  const comment = createComment({
60565
60501
  editor,
60566
60502
  abstract
@@ -64351,6 +64287,7 @@ ${codeText}
64351
64287
  return block;
64352
64288
  }
64353
64289
  const logger$1i = getLogger("block-menu-drag-handler");
64290
+ const MIN_DISTANCE_THRESHOLD$1 = 3;
64354
64291
  function createDragEventFromMouseEvent$2(event, type) {
64355
64292
  const dragEvent = new DragEvent(type, {
64356
64293
  bubbles: true,
@@ -64368,7 +64305,7 @@ ${codeText}
64368
64305
  constructor(editor, button2) {
64369
64306
  __publicField(this, "dragPreview");
64370
64307
  __publicField(this, "autoScroll");
64371
- __publicField(this, "oldPos", { x: 0, y: 0 });
64308
+ __publicField(this, "startPos", { x: 0, y: 0 });
64372
64309
  __publicField(this, "handleMouseDown", (event) => {
64373
64310
  const block = this.button.blockMenu.currentBlock;
64374
64311
  assert(logger$1i, block, "no dragged block");
@@ -64381,7 +64318,7 @@ ${codeText}
64381
64318
  return;
64382
64319
  }
64383
64320
  const { x, y } = event;
64384
- this.oldPos = { x, y };
64321
+ this.startPos = { x, y };
64385
64322
  document.addEventListener("mouseup", this.handleDragEnd);
64386
64323
  this.editor.contentElement.addEventListener("mousemove", this.handleDrag);
64387
64324
  });
@@ -64412,13 +64349,14 @@ ${codeText}
64412
64349
  });
64413
64350
  __publicField(this, "handleDrag", (event) => {
64414
64351
  const { target, x, y } = event;
64415
- if (this.oldPos.x === x && this.oldPos.y === y) {
64352
+ const deltaX = x - this.startPos.x;
64353
+ const deltaY = y - this.startPos.y;
64354
+ if (Math.abs(deltaX) < MIN_DISTANCE_THRESHOLD$1 && Math.abs(deltaY) < MIN_DISTANCE_THRESHOLD$1) {
64416
64355
  return;
64417
64356
  }
64418
64357
  if (!window.isDragging) {
64419
64358
  this.handleDragStart(event);
64420
64359
  }
64421
- this.oldPos = { x, y };
64422
64360
  assert(logger$1i, target instanceof Element, "target is invalid");
64423
64361
  this.dragPreview.handleDrag(event);
64424
64362
  const dragEvent = createDragEventFromMouseEvent$2(event, "dragover");
@@ -65457,6 +65395,7 @@ ${codeText}
65457
65395
  }
65458
65396
  return true;
65459
65397
  }
65398
+ const MIN_DISTANCE_THRESHOLD = 3;
65460
65399
  async function elementToDataUrl$1(element) {
65461
65400
  const orgDataUrl = await domToImage__default.default.toSvg(element);
65462
65401
  return orgDataUrl;
@@ -65565,25 +65504,27 @@ ${codeText}
65565
65504
  }
65566
65505
  });
65567
65506
  __publicField(this, "handleDrag", (event) => {
65568
- var _a;
65569
65507
  const { x, y } = event;
65570
- if (((_a = this.startPosition) == null ? void 0 : _a.x) === x && this.startPosition.y === y) {
65508
+ if (!this.startPosition) {
65509
+ return;
65510
+ }
65511
+ const { x: startX, y: startY } = this.startPosition;
65512
+ const deltaX = x - startX;
65513
+ const deltaY = y - startY;
65514
+ if (Math.abs(deltaX) < MIN_DISTANCE_THRESHOLD && Math.abs(deltaY) < MIN_DISTANCE_THRESHOLD) {
65571
65515
  return;
65572
65516
  }
65573
65517
  if (!window.isDragging) {
65574
65518
  window.isDragging = true;
65575
65519
  this.handleDragStart(event);
65576
65520
  }
65577
- if (this.startPosition && this.dragContainer) {
65521
+ if (this.dragContainer) {
65578
65522
  const { x: x2, y: y2 } = event;
65579
65523
  if (x2 === 0 && y2 === 0) {
65580
65524
  this.dragContainer.style.transform = "";
65581
65525
  this.dragContainer.style.opacity = "0";
65582
65526
  return;
65583
65527
  }
65584
- const { x: startX, y: startY } = this.startPosition;
65585
- const deltaX = x2 - startX;
65586
- const deltaY = y2 - startY;
65587
65528
  this.dragContainer.style.transform = `translate(${deltaX}px, ${deltaY}px)`;
65588
65529
  this.dragContainer.style.opacity = "0.5";
65589
65530
  }
@@ -68987,8 +68928,7 @@ ${codeText}
68987
68928
  return;
68988
68929
  }
68989
68930
  const selectedBlocks = getAllSelectedBlocks(editor, { simpleBlockOnly: true });
68990
- const blocks = selectedBlocks.map((s) => s.block);
68991
- const abstract = getCommentAbstract(editor, blocks);
68931
+ const abstract = getCommentAbstractFromSelectedBlocks(editor, selectedBlocks);
68992
68932
  const comment = createComment({
68993
68933
  editor,
68994
68934
  abstract
@@ -74044,14 +73984,11 @@ ${content}
74044
73984
  }
74045
73985
  const list2 = elem;
74046
73986
  const blocks = [];
74047
- let firstLevel;
73987
+ let firstLevel = 1;
74048
73988
  Array.from(list2.children).forEach((child) => {
74049
73989
  if (child instanceof HTMLLIElement) {
74050
- const listData = getListData(child);
73990
+ getListData(child);
74051
73991
  const textBlocks = options.textElementToBlocks(child, options);
74052
- if (!firstLevel) {
74053
- firstLevel = listData.level;
74054
- }
74055
73992
  const firstBlock = textBlocks[0];
74056
73993
  blocks.push({
74057
73994
  ...firstBlock,
@@ -76154,7 +76091,7 @@ ${content}
76154
76091
  rangeInSelected = containers.some((selectContainer) => selectContainer.contains(nextBlock));
76155
76092
  }
76156
76093
  if (!rangeInSelected) {
76157
- this.editor.selectionHandler.handleMouseDown(event, { autoScroll: false });
76094
+ this.editor.selectionHandler.handleMouseDown(event);
76158
76095
  }
76159
76096
  });
76160
76097
  __publicField(this, "handleContextMenu", (event) => {
@@ -86438,16 +86375,18 @@ ${data2.flowchartText}
86438
86375
  StatusBox
86439
86376
  ];
86440
86377
  function createHistoryEditor(root2, doc2, options) {
86441
- var _a, _b, _c, _d;
86378
+ var _a, _b, _c, _d, _e;
86442
86379
  Logger$2.level = (_a = options.logLevel) != null ? _a : LogLevel.DEBUG;
86380
+ const tableOptions = { ...(_b = options.componentsOptions) == null ? void 0 : _b.table, locatingContainer: void 0 };
86381
+ const componentsOptions = { ...options.componentsOptions, table: tableOptions };
86443
86382
  const editor = createEditor(root2, doc2, {
86444
86383
  components: {
86445
- blocks: [...StandardBlocks, ...((_b = options == null ? void 0 : options.components) == null ? void 0 : _b.blocks) || []],
86446
- embeds: [...StandardEmbeds, ...((_c = options.components) == null ? void 0 : _c.embeds) || []],
86447
- boxes: [...StandardBoxes, ...((_d = options.components) == null ? void 0 : _d.boxes) || []],
86384
+ blocks: [...StandardBlocks, ...((_c = options == null ? void 0 : options.components) == null ? void 0 : _c.blocks) || []],
86385
+ embeds: [...StandardEmbeds, ...((_d = options.components) == null ? void 0 : _d.embeds) || []],
86386
+ boxes: [...StandardBoxes, ...((_e = options.components) == null ? void 0 : _e.boxes) || []],
86448
86387
  textRenders: [new BlockPaddingRender()],
86449
86388
  decorators: [new CodeTextDecorator()],
86450
- options: { ...options.componentsOptions }
86389
+ options: componentsOptions
86451
86390
  }
86452
86391
  });
86453
86392
  editor.readonly = true;
@@ -88344,7 +88283,7 @@ ${data2.flowchartText}
88344
88283
  }
88345
88284
  }
88346
88285
  });
88347
- editor.version = "2.2.11";
88286
+ editor.version = "2.2.12-beta.2";
88348
88287
  return editor;
88349
88288
  }
88350
88289
  function isDoc(doc2) {
@@ -88439,7 +88378,7 @@ ${data2.flowchartText}
88439
88378
  });
88440
88379
  editor.addCustom(DOC_RE_AUTH_KEYS, (editor2) => new DocReAuthCallbacks(editor2));
88441
88380
  OnesEditorToolbar.register(editor);
88442
- editor.version = "2.2.11";
88381
+ editor.version = "2.2.12-beta.2";
88443
88382
  return editor;
88444
88383
  }
88445
88384
  async function showDocVersions(editor, options, serverUrl) {
@@ -134239,7 +134178,7 @@ ${data2.flowchartText}
134239
134178
  exports2.LocalDoc = LocalDoc;
134240
134179
  exports2.LogLevel = LogLevel;
134241
134180
  exports2.Logger = Logger$2;
134242
- exports2.MIN_DISTANCE_THRESHOLD = MIN_DISTANCE_THRESHOLD$1;
134181
+ exports2.MIN_DISTANCE_THRESHOLD = MIN_DISTANCE_THRESHOLD$3;
134243
134182
  exports2.ManualCloseDialog = ManualCloseDialog;
134244
134183
  exports2.ManualMenu = ManualMenu;
134245
134184
  exports2.ManualToolbar = ManualToolbar;
@@ -134529,7 +134468,7 @@ ${data2.flowchartText}
134529
134468
  exports2.getBlockNearestRangeFromPoint = getBlockNearestRangeFromPoint;
134530
134469
  exports2.getBlockOptions = getBlockOptions;
134531
134470
  exports2.getBlockPath = getBlockPath;
134532
- exports2.getBlockProperties = getBlockProperties$e;
134471
+ exports2.getBlockProperties = getBlockProperties$d;
134533
134472
  exports2.getBlockRangeFromPoint = getBlockRangeFromPoint;
134534
134473
  exports2.getBlockStyles = getBlockStyles;
134535
134474
  exports2.getBlockTextLength = getBlockTextLength$6;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "2.2.11",
3
+ "version": "2.2.12-beta.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",