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

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;
@@ -60495,17 +60444,6 @@ $$${mathData.mathjaxText}$$
60495
60444
  return true;
60496
60445
  }
60497
60446
  }
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
60447
  function getCommentAbstractFromSelectedBlocks(editor, blocks) {
60510
60448
  return blocks.map((selectedBlock) => {
60511
60449
  var _a, _b;
@@ -60560,7 +60498,9 @@ $$${mathData.mathjaxText}$$
60560
60498
  editor.updateBlockData(block, newData);
60561
60499
  }
60562
60500
  function addCommentToBlock$1(editor, block, provider) {
60563
- const abstract = getCommentAbstract(editor, [block]);
60501
+ const { start, end } = createBlockSimpleRange(editor, block, 0, getBlockTextLength$6(editor, block));
60502
+ const selectedBlock = { block, start, end };
60503
+ const abstract = getCommentAbstractFromSelectedBlocks(editor, [selectedBlock]);
60564
60504
  const comment = createComment({
60565
60505
  editor,
60566
60506
  abstract
@@ -64351,6 +64291,7 @@ ${codeText}
64351
64291
  return block;
64352
64292
  }
64353
64293
  const logger$1i = getLogger("block-menu-drag-handler");
64294
+ const MIN_DISTANCE_THRESHOLD$1 = 3;
64354
64295
  function createDragEventFromMouseEvent$2(event, type) {
64355
64296
  const dragEvent = new DragEvent(type, {
64356
64297
  bubbles: true,
@@ -64368,7 +64309,7 @@ ${codeText}
64368
64309
  constructor(editor, button2) {
64369
64310
  __publicField(this, "dragPreview");
64370
64311
  __publicField(this, "autoScroll");
64371
- __publicField(this, "oldPos", { x: 0, y: 0 });
64312
+ __publicField(this, "startPos", { x: 0, y: 0 });
64372
64313
  __publicField(this, "handleMouseDown", (event) => {
64373
64314
  const block = this.button.blockMenu.currentBlock;
64374
64315
  assert(logger$1i, block, "no dragged block");
@@ -64381,7 +64322,7 @@ ${codeText}
64381
64322
  return;
64382
64323
  }
64383
64324
  const { x, y } = event;
64384
- this.oldPos = { x, y };
64325
+ this.startPos = { x, y };
64385
64326
  document.addEventListener("mouseup", this.handleDragEnd);
64386
64327
  this.editor.contentElement.addEventListener("mousemove", this.handleDrag);
64387
64328
  });
@@ -64412,13 +64353,14 @@ ${codeText}
64412
64353
  });
64413
64354
  __publicField(this, "handleDrag", (event) => {
64414
64355
  const { target, x, y } = event;
64415
- if (this.oldPos.x === x && this.oldPos.y === y) {
64356
+ const deltaX = x - this.startPos.x;
64357
+ const deltaY = y - this.startPos.y;
64358
+ if (Math.abs(deltaX) < MIN_DISTANCE_THRESHOLD$1 && Math.abs(deltaY) < MIN_DISTANCE_THRESHOLD$1) {
64416
64359
  return;
64417
64360
  }
64418
64361
  if (!window.isDragging) {
64419
64362
  this.handleDragStart(event);
64420
64363
  }
64421
- this.oldPos = { x, y };
64422
64364
  assert(logger$1i, target instanceof Element, "target is invalid");
64423
64365
  this.dragPreview.handleDrag(event);
64424
64366
  const dragEvent = createDragEventFromMouseEvent$2(event, "dragover");
@@ -65457,6 +65399,7 @@ ${codeText}
65457
65399
  }
65458
65400
  return true;
65459
65401
  }
65402
+ const MIN_DISTANCE_THRESHOLD = 3;
65460
65403
  async function elementToDataUrl$1(element) {
65461
65404
  const orgDataUrl = await domToImage__default.default.toSvg(element);
65462
65405
  return orgDataUrl;
@@ -65565,25 +65508,27 @@ ${codeText}
65565
65508
  }
65566
65509
  });
65567
65510
  __publicField(this, "handleDrag", (event) => {
65568
- var _a;
65569
65511
  const { x, y } = event;
65570
- if (((_a = this.startPosition) == null ? void 0 : _a.x) === x && this.startPosition.y === y) {
65512
+ if (!this.startPosition) {
65513
+ return;
65514
+ }
65515
+ const { x: startX, y: startY } = this.startPosition;
65516
+ const deltaX = x - startX;
65517
+ const deltaY = y - startY;
65518
+ if (Math.abs(deltaX) < MIN_DISTANCE_THRESHOLD && Math.abs(deltaY) < MIN_DISTANCE_THRESHOLD) {
65571
65519
  return;
65572
65520
  }
65573
65521
  if (!window.isDragging) {
65574
65522
  window.isDragging = true;
65575
65523
  this.handleDragStart(event);
65576
65524
  }
65577
- if (this.startPosition && this.dragContainer) {
65525
+ if (this.dragContainer) {
65578
65526
  const { x: x2, y: y2 } = event;
65579
65527
  if (x2 === 0 && y2 === 0) {
65580
65528
  this.dragContainer.style.transform = "";
65581
65529
  this.dragContainer.style.opacity = "0";
65582
65530
  return;
65583
65531
  }
65584
- const { x: startX, y: startY } = this.startPosition;
65585
- const deltaX = x2 - startX;
65586
- const deltaY = y2 - startY;
65587
65532
  this.dragContainer.style.transform = `translate(${deltaX}px, ${deltaY}px)`;
65588
65533
  this.dragContainer.style.opacity = "0.5";
65589
65534
  }
@@ -68987,8 +68932,7 @@ ${codeText}
68987
68932
  return;
68988
68933
  }
68989
68934
  const selectedBlocks = getAllSelectedBlocks(editor, { simpleBlockOnly: true });
68990
- const blocks = selectedBlocks.map((s) => s.block);
68991
- const abstract = getCommentAbstract(editor, blocks);
68935
+ const abstract = getCommentAbstractFromSelectedBlocks(editor, selectedBlocks);
68992
68936
  const comment = createComment({
68993
68937
  editor,
68994
68938
  abstract
@@ -74044,14 +73988,11 @@ ${content}
74044
73988
  }
74045
73989
  const list2 = elem;
74046
73990
  const blocks = [];
74047
- let firstLevel;
73991
+ let firstLevel = 1;
74048
73992
  Array.from(list2.children).forEach((child) => {
74049
73993
  if (child instanceof HTMLLIElement) {
74050
- const listData = getListData(child);
73994
+ getListData(child);
74051
73995
  const textBlocks = options.textElementToBlocks(child, options);
74052
- if (!firstLevel) {
74053
- firstLevel = listData.level;
74054
- }
74055
73996
  const firstBlock = textBlocks[0];
74056
73997
  blocks.push({
74057
73998
  ...firstBlock,
@@ -76154,7 +76095,7 @@ ${content}
76154
76095
  rangeInSelected = containers.some((selectContainer) => selectContainer.contains(nextBlock));
76155
76096
  }
76156
76097
  if (!rangeInSelected) {
76157
- this.editor.selectionHandler.handleMouseDown(event, { autoScroll: false });
76098
+ this.editor.selectionHandler.handleMouseDown(event);
76158
76099
  }
76159
76100
  });
76160
76101
  __publicField(this, "handleContextMenu", (event) => {
@@ -86438,16 +86379,18 @@ ${data2.flowchartText}
86438
86379
  StatusBox
86439
86380
  ];
86440
86381
  function createHistoryEditor(root2, doc2, options) {
86441
- var _a, _b, _c, _d;
86382
+ var _a, _b, _c, _d, _e;
86442
86383
  Logger$2.level = (_a = options.logLevel) != null ? _a : LogLevel.DEBUG;
86384
+ const tableOptions = { ...(_b = options.componentsOptions) == null ? void 0 : _b.table, locatingContainer: void 0 };
86385
+ const componentsOptions = { ...options.componentsOptions, table: tableOptions };
86443
86386
  const editor = createEditor(root2, doc2, {
86444
86387
  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) || []],
86388
+ blocks: [...StandardBlocks, ...((_c = options == null ? void 0 : options.components) == null ? void 0 : _c.blocks) || []],
86389
+ embeds: [...StandardEmbeds, ...((_d = options.components) == null ? void 0 : _d.embeds) || []],
86390
+ boxes: [...StandardBoxes, ...((_e = options.components) == null ? void 0 : _e.boxes) || []],
86448
86391
  textRenders: [new BlockPaddingRender()],
86449
86392
  decorators: [new CodeTextDecorator()],
86450
- options: { ...options.componentsOptions }
86393
+ options: componentsOptions
86451
86394
  }
86452
86395
  });
86453
86396
  editor.readonly = true;
@@ -88344,7 +88287,7 @@ ${data2.flowchartText}
88344
88287
  }
88345
88288
  }
88346
88289
  });
88347
- editor.version = "2.2.11";
88290
+ editor.version = "2.2.12-beta.1";
88348
88291
  return editor;
88349
88292
  }
88350
88293
  function isDoc(doc2) {
@@ -88439,7 +88382,7 @@ ${data2.flowchartText}
88439
88382
  });
88440
88383
  editor.addCustom(DOC_RE_AUTH_KEYS, (editor2) => new DocReAuthCallbacks(editor2));
88441
88384
  OnesEditorToolbar.register(editor);
88442
- editor.version = "2.2.11";
88385
+ editor.version = "2.2.12-beta.1";
88443
88386
  return editor;
88444
88387
  }
88445
88388
  async function showDocVersions(editor, options, serverUrl) {
@@ -134239,7 +134182,7 @@ ${data2.flowchartText}
134239
134182
  exports2.LocalDoc = LocalDoc;
134240
134183
  exports2.LogLevel = LogLevel;
134241
134184
  exports2.Logger = Logger$2;
134242
- exports2.MIN_DISTANCE_THRESHOLD = MIN_DISTANCE_THRESHOLD$1;
134185
+ exports2.MIN_DISTANCE_THRESHOLD = MIN_DISTANCE_THRESHOLD$3;
134243
134186
  exports2.ManualCloseDialog = ManualCloseDialog;
134244
134187
  exports2.ManualMenu = ManualMenu;
134245
134188
  exports2.ManualToolbar = ManualToolbar;
@@ -134529,7 +134472,7 @@ ${data2.flowchartText}
134529
134472
  exports2.getBlockNearestRangeFromPoint = getBlockNearestRangeFromPoint;
134530
134473
  exports2.getBlockOptions = getBlockOptions;
134531
134474
  exports2.getBlockPath = getBlockPath;
134532
- exports2.getBlockProperties = getBlockProperties$e;
134475
+ exports2.getBlockProperties = getBlockProperties$d;
134533
134476
  exports2.getBlockRangeFromPoint = getBlockRangeFromPoint;
134534
134477
  exports2.getBlockStyles = getBlockStyles;
134535
134478
  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.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",