@ones-editor/editor 5.0.4 → 5.0.5-beta.ONES22302330.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
@@ -5276,6 +5276,14 @@ div[data-command-bar-id=table-row-column-toolbar] .tippy-box .tippy-content butt
5276
5276
  div[data-command-bar-id=table-cell-menu] .tippy-box .tippy-content .editor-command-bar.menu .command-item.selected[data-id=delete-select-row], div[data-command-bar-id=table-cell-menu] .tippy-box .tippy-content .editor-command-bar.menu .command-item.selected[data-id=delete-select-col] {
5277
5277
  color: #eb3723;
5278
5278
  background-color: #fff6f5;
5279
+ }
5280
+ @media screen {
5281
+ @supports (content-visibility: auto) and (contain-intrinsic-size: auto 400px) {
5282
+ .editor-root.readonly:not(.find-dialog-open) [data-type=table-content].deferred-table-content {
5283
+ content-visibility: auto;
5284
+ contain-intrinsic-size: auto 1000px auto 400px;
5285
+ }
5286
+ }
5279
5287
  }.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-anchor[data-id=paste-special-button-anchor] {
5280
5288
  z-index: unset;
5281
5289
  }
@@ -26786,9 +26794,25 @@ var __publicField = (obj, key, value) => {
26786
26794
  }
26787
26795
  }
26788
26796
  }
26797
+ function allSelected(editor, range) {
26798
+ if (range.isCollapsed()) {
26799
+ return false;
26800
+ }
26801
+ const firstChildBlock = getFirstChildBlock(editor.rootContainer);
26802
+ const lastChildBlock = getLastChildBlock(editor.rootContainer);
26803
+ const { start, end } = range;
26804
+ return start.blockId === getBlockId(firstChildBlock) && start.offset === 0 && end.blockId === getBlockId(lastChildBlock) && end.offset === getBlockTextLength$6(editor, lastChildBlock);
26805
+ }
26789
26806
  function updateSelectionBackground(editor) {
26790
26807
  clearAllSelection(editor);
26791
- editor.selection.range.getSelectedBlocks().forEach((s) => updateBlockSelection(editor, s.block, s.start, s.end));
26808
+ const { range } = editor.selection;
26809
+ const cssSelection = hasClass(editor.rootContainer, "select-all") && range.isSimple() && allSelected(editor, range);
26810
+ range.getSelectedBlocks().forEach((s) => {
26811
+ if (cssSelection && isTextKindBlock(editor, s.block) && !s.block.hasAttribute("data-document-title")) {
26812
+ return;
26813
+ }
26814
+ updateBlockSelection(editor, s.block, s.start, s.end);
26815
+ });
26792
26816
  }
26793
26817
  const logger$3U = getLogger("editor-dom");
26794
26818
  function editorGetClientHeight(editor) {
@@ -26937,15 +26961,6 @@ var __publicField = (obj, key, value) => {
26937
26961
  anchorElem.remove();
26938
26962
  }, 200);
26939
26963
  }
26940
- function allSelected(editor, range) {
26941
- if (range.isCollapsed()) {
26942
- return false;
26943
- }
26944
- const firstChildBlock = getFirstChildBlock(editor.rootContainer);
26945
- const lastChildBlock = getLastChildBlock(editor.rootContainer);
26946
- const { start, end } = range;
26947
- return start.blockId === getBlockId(firstChildBlock) && start.offset === 0 && end.blockId === getBlockId(lastChildBlock) && end.offset === getBlockTextLength$6(editor, lastChildBlock);
26948
- }
26949
26964
  const logger$3T = getLogger("range-in-block");
26950
26965
  function rangeInBlock(block, range) {
26951
26966
  const editor = range.getEditor();
@@ -27712,14 +27727,14 @@ var __publicField = (obj, key, value) => {
27712
27727
  }
27713
27728
  function mergeDocs(docs) {
27714
27729
  const rootBlocks = [];
27715
- let childContainers = {};
27730
+ const childContainers = /* @__PURE__ */ Object.create(null);
27716
27731
  docs.forEach((doc2) => {
27717
27732
  rootBlocks.push(...doc2.blocks.root);
27718
- const { root: root2, ...subContainers } = doc2.blocks;
27719
- childContainers = {
27720
- ...childContainers,
27721
- ...subContainers
27722
- };
27733
+ Object.entries(doc2.blocks).forEach(([containerId, blocks]) => {
27734
+ if (containerId !== "root") {
27735
+ childContainers[containerId] = blocks;
27736
+ }
27737
+ });
27723
27738
  });
27724
27739
  return {
27725
27740
  blocks: {
@@ -29029,10 +29044,10 @@ var __publicField = (obj, key, value) => {
29029
29044
  doc2.blocks[childContainerId] = cloneDeep__default.default(childBlocks);
29030
29045
  });
29031
29046
  }
29032
- function selectedBlockToDoc(editor, selectedBlock) {
29047
+ function selectedBlockToDoc(editor, selectedBlock, getSourceDoc) {
29033
29048
  const blockClass = getBlockClass(editor, selectedBlock.block);
29034
29049
  if (blockClass.selectionToDoc) {
29035
- return blockClass.selectionToDoc(editor, selectedBlock);
29050
+ return blockClass.selectionToDoc(editor, selectedBlock, getSourceDoc);
29036
29051
  }
29037
29052
  const data2 = cloneDeep__default.default(editorGetBlockData(editor, selectedBlock.block));
29038
29053
  if (isTextKindBlock(editor, selectedBlock.block)) {
@@ -29099,7 +29114,12 @@ var __publicField = (obj, key, value) => {
29099
29114
  }
29100
29115
  function selectionToDoc$2(editor) {
29101
29116
  const selectedBlocks = editor.selection.range.getSelectedBlocks();
29102
- const docs = selectedBlocks.map((s) => selectedBlockToDoc(editor, s));
29117
+ let sourceDoc;
29118
+ const getSourceDoc = () => {
29119
+ sourceDoc != null ? sourceDoc : sourceDoc = editor.doc.toJSON();
29120
+ return sourceDoc;
29121
+ };
29122
+ const docs = selectedBlocks.map((s) => selectedBlockToDoc(editor, s, getSourceDoc));
29103
29123
  return mergeDocs(docs);
29104
29124
  }
29105
29125
  function containerToDoc(editor, containerId) {
@@ -41171,9 +41191,31 @@ ${codeText}
41171
41191
  class ChildBlockEventTracker extends tinyTypedEmitter.TypedEmitter {
41172
41192
  constructor(editor) {
41173
41193
  super();
41194
+ __publicField(this, "trackedListeners", /* @__PURE__ */ new Map());
41174
41195
  this.editor = editor;
41175
41196
  this.editor.doc.registerCallback(this);
41176
41197
  }
41198
+ track(callback) {
41199
+ var _a;
41200
+ const count = (_a = this.trackedListeners.get(callback)) != null ? _a : 0;
41201
+ this.trackedListeners.set(callback, count + 1);
41202
+ if (count === 0) {
41203
+ this.addListener("change", callback);
41204
+ this.addListener("insert", callback);
41205
+ }
41206
+ }
41207
+ untrack(callback) {
41208
+ const count = this.trackedListeners.get(callback);
41209
+ if (!count)
41210
+ return;
41211
+ if (count > 1) {
41212
+ this.trackedListeners.set(callback, count - 1);
41213
+ } else {
41214
+ this.trackedListeners.delete(callback);
41215
+ this.removeListener("change", callback);
41216
+ this.removeListener("insert", callback);
41217
+ }
41218
+ }
41177
41219
  handleChild(containerId, blockIndex, action) {
41178
41220
  if (isRootContainer(getContainerById(this.editor, containerId))) {
41179
41221
  return;
@@ -41201,6 +41243,8 @@ ${codeText}
41201
41243
  }
41202
41244
  destroy() {
41203
41245
  this.editor.doc.unregisterCallback(this);
41246
+ this.trackedListeners.clear();
41247
+ this.removeAllListeners();
41204
41248
  }
41205
41249
  }
41206
41250
  function trackChildBlockEvent(editor, callback) {
@@ -41208,16 +41252,14 @@ ${codeText}
41208
41252
  "child-block-tracker",
41209
41253
  () => new ChildBlockEventTracker(editor)
41210
41254
  );
41211
- handler.addListener("change", callback);
41212
- handler.addListener("insert", callback);
41255
+ handler.track(callback);
41213
41256
  }
41214
41257
  function untrackChildBlockEvent(editor, callback) {
41215
41258
  const handler = editor.addCustom(
41216
41259
  "child-block-tracker",
41217
41260
  () => new ChildBlockEventTracker(editor)
41218
41261
  );
41219
- handler.removeListener("change", callback);
41220
- handler.removeListener("insert", callback);
41262
+ handler.untrack(callback);
41221
41263
  }
41222
41264
  const style$e = "";
41223
41265
  const zhCN$x = {
@@ -48688,13 +48730,22 @@ ${codeText}
48688
48730
  class ContainerIntersectionObserver {
48689
48731
  constructor(scrollCore, callback) {
48690
48732
  __publicField(this, "intersectionObserver");
48733
+ __publicField(this, "intersecting", /* @__PURE__ */ new WeakSet());
48691
48734
  __publicField(this, "handleIntersection", (entries) => {
48692
48735
  entries.forEach((entry) => {
48693
48736
  const container = this.containers.get(getContainer(entry.target));
48694
48737
  if (container) {
48695
- this.handleIntersectionEntry(entry);
48738
+ if (entry.isIntersecting || this.intersecting.has(entry.target)) {
48739
+ this.handleIntersectionEntry(entry);
48740
+ }
48741
+ if (entry.isIntersecting) {
48742
+ this.intersecting.add(entry.target);
48743
+ } else {
48744
+ this.intersecting.delete(entry.target);
48745
+ }
48696
48746
  this.callback(entry);
48697
48747
  } else {
48748
+ this.intersecting.delete(entry.target);
48698
48749
  this.intersectionObserver.unobserve(entry.target);
48699
48750
  }
48700
48751
  });
@@ -48723,9 +48774,11 @@ ${codeText}
48723
48774
  this.intersectionObserver.observe(scrollContainer);
48724
48775
  }
48725
48776
  unbind(scrollContainer) {
48777
+ this.intersecting.delete(scrollContainer);
48726
48778
  this.intersectionObserver.unobserve(scrollContainer);
48727
48779
  }
48728
48780
  destroy() {
48781
+ this.intersecting = /* @__PURE__ */ new WeakSet();
48729
48782
  this.intersectionObserver.disconnect();
48730
48783
  }
48731
48784
  }
@@ -49064,11 +49117,17 @@ ${codeText}
49064
49117
  __publicField(this, "scrollWrapResizeObserve", null);
49065
49118
  __publicField(this, "locatingContainerResizeObserver", null);
49066
49119
  __publicField(this, "isWindowEventBind", false);
49120
+ __publicField(this, "boundContainers", /* @__PURE__ */ new WeakSet());
49067
49121
  __publicField(this, "containers", /* @__PURE__ */ new Map());
49122
+ __publicField(this, "containerCallbacks", /* @__PURE__ */ new Map());
49068
49123
  __publicField(this, "handleScrollContainerScroll", (scrollContainerElement) => {
49124
+ var _a;
49125
+ (_a = this.containerCallbacks.get(getContainer(scrollContainerElement))) == null ? void 0 : _a.scroll(this, scrollContainerElement);
49069
49126
  this.emit("scroll", this, scrollContainerElement);
49070
49127
  });
49071
49128
  __publicField(this, "handleResize", (scrollContainerElement) => {
49129
+ var _a;
49130
+ (_a = this.containerCallbacks.get(getContainer(scrollContainerElement))) == null ? void 0 : _a.resize(this, scrollContainerElement);
49072
49131
  this.emit("resize", this, scrollContainerElement);
49073
49132
  });
49074
49133
  __publicField(this, "handleIntersection", (entry) => {
@@ -49121,6 +49180,8 @@ ${codeText}
49121
49180
  }
49122
49181
  unbindCore(scrollContainer, scrollWrap) {
49123
49182
  var _a, _b, _c, _d, _e, _f;
49183
+ if (!this.boundContainers.delete(scrollContainer))
49184
+ return;
49124
49185
  const scrollbarContainer = getScrollbarContainer(scrollContainer);
49125
49186
  (_a = this.containerScrollObserver) == null ? void 0 : _a.unbindContentScroll(scrollContainer);
49126
49187
  (_b = this.containerScrollObserver) == null ? void 0 : _b.unbind(scrollbarContainer);
@@ -49145,8 +49206,11 @@ ${codeText}
49145
49206
  (_e = this.parentContainerScrollObserver) == null ? void 0 : _e.bindScrollContainer(scrollContainer);
49146
49207
  }
49147
49208
  (_f = this.locatingContainerResizeObserver) == null ? void 0 : _f.bind(scrollContainer);
49209
+ this.boundContainers.add(scrollContainer);
49148
49210
  }
49149
- bind(container, option) {
49211
+ bind(container, option, callbacks) {
49212
+ if (callbacks)
49213
+ this.containerCallbacks.set(container, callbacks);
49150
49214
  this.containers.set(container, option);
49151
49215
  const scrollContainer = container.firstElementChild;
49152
49216
  if (!this.containerIntersectionObserver) {
@@ -49160,6 +49224,7 @@ ${codeText}
49160
49224
  const scrollWrap = getContainerScrollArea(scrollContainer);
49161
49225
  this.unbindCore(scrollContainer, scrollWrap);
49162
49226
  this.containers.delete(container);
49227
+ this.containerCallbacks.delete(container);
49163
49228
  (_a = this.containerIntersectionObserver) == null ? void 0 : _a.unbind(scrollContainer);
49164
49229
  if (!this.containers.size) {
49165
49230
  this.destroy();
@@ -49208,9 +49273,10 @@ ${codeText}
49208
49273
  rootScrollMap.set(parentContainer, this.scrollListener);
49209
49274
  }
49210
49275
  this.scrollListener.unbind(container);
49211
- this.scrollListener.bind(container, options);
49212
- this.scrollListener.on("scroll", this.handleContainerScroll);
49213
- this.scrollListener.on("resize", this.handleResize);
49276
+ this.scrollListener.bind(container, options, {
49277
+ scroll: this.handleContainerScroll,
49278
+ resize: this.handleResize
49279
+ });
49214
49280
  this.scrollContainerElement = scrollContainerElement;
49215
49281
  });
49216
49282
  __publicField(this, "handleContainerScroll", (scrollListener, scrollContainerElement) => {
@@ -49239,8 +49305,6 @@ ${codeText}
49239
49305
  baseListener.destroy();
49240
49306
  }
49241
49307
  destroy() {
49242
- var _a;
49243
- (_a = this.scrollListener) == null ? void 0 : _a.off("scroll", this.handleContainerScroll);
49244
49308
  const container = getContainer(this.contentElement);
49245
49309
  if (container) {
49246
49310
  rootScrollMap.forEach((baseListener, parentContainer) => {
@@ -74926,6 +74990,9 @@ ${codeText}
74926
74990
  try {
74927
74991
  const tableContent = createElement("div", [], null);
74928
74992
  tableContent.setAttribute("data-type", "table-content");
74993
+ if (isRootContainer(container)) {
74994
+ addClass(tableContent, "deferred-table-content");
74995
+ }
74929
74996
  const table = createTable(editor, path, tableData);
74930
74997
  table.classList.add("drag-preview-element");
74931
74998
  tableContent.appendChild(table);
@@ -74941,15 +75008,16 @@ ${codeText}
74941
75008
  }
74942
75009
  trackChildBlockEvent(editor, handleChartDebounceUpdate);
74943
75010
  const scrollContainer = editor.addCustom(getTableScrollKey(blockElement), () => createScrollContainer());
74944
- const overflowY = window.getComputedStyle(container).overflowY;
75011
+ const rootContainer = isRootContainer(container);
75012
+ const overflowY = rootContainer ? "" : window.getComputedStyle(container).overflowY;
74945
75013
  const containerScrollable = overflowY === "auto" || overflowY === "scroll";
74946
75014
  scrollContainer.init({
74947
75015
  parentElement: content,
74948
75016
  childElement: tableContent,
74949
75017
  safeRightSpace: clientType.isMobile ? 20 : 50,
74950
75018
  safeLeftSpace: 40,
74951
- parentContainer: isRootContainer(container) || !containerScrollable ? editor.scrollContainer : container,
74952
- locatingContainer: isRootContainer(container) ? (options == null ? void 0 : options.locatingContainer) || editor.parent : container,
75019
+ parentContainer: rootContainer || !containerScrollable ? editor.scrollContainer : container,
75020
+ locatingContainer: rootContainer ? (options == null ? void 0 : options.locatingContainer) || editor.parent : container,
74953
75021
  paddingLeft: TABLE_BAR_WIDTH + INSERT_BUTTON_SIZE,
74954
75022
  paddingTop: TABLE_BAR_WIDTH + INSERT_BUTTON_SIZE,
74955
75023
  paddingBottom: INSERT_BUTTON_SIZE / 2,
@@ -74961,9 +75029,11 @@ ${codeText}
74961
75029
  const tableScrollEvents = handleTableScrollEvents(editor);
74962
75030
  scrollContainer.on("scroll", tableScrollEvents.handleReset);
74963
75031
  scrollContainer.on("resize", tableScrollEvents.handleReset);
74964
- setTimeout(() => {
74965
- handleChartUpdate(editor, blockElement);
74966
- });
75032
+ if (tableData.chart) {
75033
+ setTimeout(() => {
75034
+ handleChartUpdate(editor, blockElement);
75035
+ });
75036
+ }
74967
75037
  } catch (err) {
74968
75038
  const message = `invalid table data: ${JSON.stringify(tableData)}`;
74969
75039
  logger$_.error(message);
@@ -75118,13 +75188,14 @@ ${codeText}
75118
75188
  return acc;
75119
75189
  }, {});
75120
75190
  }
75121
- function selectionToDoc(editor, selectedBlock) {
75191
+ function selectionToDoc(editor, selectedBlock, getSourceDoc) {
75122
75192
  const { start, end, block } = selectedBlock;
75123
75193
  const blockType = getBlockType(block);
75124
75194
  assert(logger$Y, blockType === "table", `invalid block type: ${blockType}`);
75125
75195
  const blockData = editor.getBlockData(block);
75196
+ const oldDoc = getSourceDoc ? getSourceDoc() : editor.doc.toJSON();
75126
75197
  if (start.isSimple() && end.isSimple()) {
75127
- const doc2 = cloneBlock(editor.editorBlocks, editor.doc.toJSON(), blockData);
75198
+ const doc2 = cloneBlock(editor.editorBlocks, oldDoc, blockData);
75128
75199
  return doc2;
75129
75200
  }
75130
75201
  assert(logger$Y, !start.isSimple() && !end.isSimple(), "invalid block pos type");
@@ -75132,7 +75203,6 @@ ${codeText}
75132
75203
  const { fromCol, toCol, fromRow, toRow } = getTableSelectionRange(block, start, end);
75133
75204
  const spanData = {};
75134
75205
  const children = [];
75135
- const oldDoc = editor.doc.toJSON();
75136
75206
  let childContainers = {};
75137
75207
  const subGrid = grid.sub({ row: fromRow, col: fromCol }, { row: toRow, col: toCol });
75138
75208
  subGrid.forEach((row, rowIndex) => {
@@ -75792,7 +75862,7 @@ ${codeText}
75792
75862
  const tableScrollEvents = handleTableScrollEvents(editor);
75793
75863
  scrollContent.off("scroll", tableScrollEvents.handleReset);
75794
75864
  scrollContent.off("resize", tableScrollEvents.handleReset);
75795
- scrollContent.destroy();
75865
+ editor.destroyCustom(getTableScrollKey(block));
75796
75866
  }
75797
75867
  }
75798
75868
  function getBlockProperties$9() {
@@ -79929,7 +79999,11 @@ ${docStr}
79929
79999
  const eleRect = firstChild.getBoundingClientRect();
79930
80000
  offsetTop = eleRect.y;
79931
80001
  }
79932
- scrollIntoView(editor, firstChild, { animation: true });
80002
+ if (editor.readonly) {
80003
+ firstChild.scrollIntoView({ block: "center", inline: "nearest" });
80004
+ } else {
80005
+ scrollIntoView(editor, firstChild, { animation: true });
80006
+ }
79933
80007
  }
79934
80008
  function getCurrentHighligh(editor) {
79935
80009
  const elem = editor.rootContainer.querySelector(".editor-highlight.active");
@@ -80524,6 +80598,7 @@ ${docStr}
80524
80598
  this.components.statusContainer.style.display = "flex";
80525
80599
  }
80526
80600
  show(options) {
80601
+ this.editor.rootElement.classList.add("find-dialog-open");
80527
80602
  document.addEventListener("keydown", this.handleDocumentKeyDown);
80528
80603
  const text2 = this.editor.getSelectedText();
80529
80604
  if (text2.length > 0 && text2.length < 50) {
@@ -80576,6 +80651,7 @@ ${docStr}
80576
80651
  }
80577
80652
  hide() {
80578
80653
  var _a;
80654
+ this.editor.rootElement.classList.remove("find-dialog-open");
80579
80655
  (_a = this.dialog) == null ? void 0 : _a.close("cancelBar");
80580
80656
  clearAllHighlights(this.editor);
80581
80657
  document.removeEventListener("keydown", this.handleDocumentKeyDown);
@@ -80590,6 +80666,7 @@ ${docStr}
80590
80666
  }
80591
80667
  destroy() {
80592
80668
  var _a;
80669
+ this.editor.rootElement.classList.remove("find-dialog-open");
80593
80670
  (_a = this.dialog) == null ? void 0 : _a.destroy();
80594
80671
  }
80595
80672
  }
@@ -97661,7 +97738,7 @@ ${JSON.stringify(error2, null, 2)}`);
97661
97738
  }
97662
97739
  }
97663
97740
  });
97664
- editor.version = "5.0.4";
97741
+ editor.version = "5.0.5-beta.ONES22302330.1";
97665
97742
  return editor;
97666
97743
  }
97667
97744
  function isDoc(doc2) {
@@ -97797,7 +97874,7 @@ ${JSON.stringify(error2, null, 2)}`);
97797
97874
  OnesEditorDropTarget.register(editor);
97798
97875
  OnesEditorTocProvider.register(editor);
97799
97876
  OnesEditorExclusiveBlock.register(editor);
97800
- editor.version = "5.0.4";
97877
+ editor.version = "5.0.5-beta.ONES22302330.1";
97801
97878
  return editor;
97802
97879
  } catch (error2) {
97803
97880
  try {
@@ -97940,7 +98017,7 @@ ${JSON.stringify(error2, null, 2)}`);
97940
98017
  }
97941
98018
  }
97942
98019
  });
97943
- editor.version = "5.0.4";
98020
+ editor.version = "5.0.5-beta.ONES22302330.1";
97944
98021
  return editor;
97945
98022
  }
97946
98023
  const emojis$1 = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "5.0.4",
3
+ "version": "5.0.5-beta.ONES22302330.1",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {