@blocknote/core 0.35.0 → 0.36.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.
Files changed (72) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +7 -25
  3. package/dist/blocknote.cjs +8 -8
  4. package/dist/blocknote.cjs.map +1 -1
  5. package/dist/blocknote.js +1592 -1458
  6. package/dist/blocknote.js.map +1 -1
  7. package/dist/{en-Dx9fwHD4.js → en-CvDoFvhc.js} +4 -1
  8. package/dist/en-CvDoFvhc.js.map +1 -0
  9. package/dist/{en-CsgPjHa4.cjs → en-ub2yVBX0.cjs} +2 -2
  10. package/dist/en-ub2yVBX0.cjs.map +1 -0
  11. package/dist/locales.cjs +1 -1
  12. package/dist/locales.cjs.map +1 -1
  13. package/dist/locales.js +62 -2
  14. package/dist/locales.js.map +1 -1
  15. package/dist/style.css +1 -1
  16. package/dist/tsconfig.tsbuildinfo +1 -1
  17. package/dist/webpack-stats.json +1 -1
  18. package/package.json +17 -16
  19. package/src/api/__snapshots__/blocks-moved-down-twice-in-same-parent.json +44 -0
  20. package/src/api/__snapshots__/blocks-moved-insert-changes-sibling-order.json +26 -0
  21. package/src/api/__snapshots__/blocks-moved-nested-sibling-reorder.json +180 -0
  22. package/src/api/__snapshots__/blocks-moved-up-down-in-same-parent.json +44 -0
  23. package/src/api/__snapshots__/blocks-moved-up-down-in-same-transaction.json +44 -0
  24. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +132 -4
  25. package/src/api/clipboard/toClipboard/copyExtension.ts +2 -0
  26. package/src/api/{nodeUtil.test.ts → getBlocksChangedByTransaction.test.ts} +117 -1
  27. package/src/api/getBlocksChangedByTransaction.ts +422 -0
  28. package/src/api/nodeUtil.ts +0 -250
  29. package/src/blocks/ImageBlockContent/parseImageElement.ts +2 -1
  30. package/src/blocks/TableBlockContent/TableBlockContent.ts +31 -4
  31. package/src/blocks/ToggleWrapper/createToggleWrapper.ts +2 -1
  32. package/src/editor/BlockNoteEditor.ts +1 -1
  33. package/src/editor/editor.css +8 -17
  34. package/src/extensions/BlockChange/BlockChangePlugin.ts +4 -2
  35. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +53 -1
  36. package/src/extensions/SideMenu/SideMenuPlugin.ts +6 -15
  37. package/src/i18n/locales/ar.ts +3 -0
  38. package/src/i18n/locales/de.ts +4 -0
  39. package/src/i18n/locales/en.ts +3 -0
  40. package/src/i18n/locales/es.ts +3 -0
  41. package/src/i18n/locales/fr.ts +3 -0
  42. package/src/i18n/locales/he.ts +3 -0
  43. package/src/i18n/locales/hr.ts +3 -0
  44. package/src/i18n/locales/is.ts +3 -0
  45. package/src/i18n/locales/it.ts +3 -0
  46. package/src/i18n/locales/ja.ts +3 -0
  47. package/src/i18n/locales/ko.ts +4 -1
  48. package/src/i18n/locales/nl.ts +3 -0
  49. package/src/i18n/locales/no.ts +3 -0
  50. package/src/i18n/locales/pl.ts +4 -0
  51. package/src/i18n/locales/pt.ts +3 -0
  52. package/src/i18n/locales/ru.ts +3 -0
  53. package/src/i18n/locales/sk.ts +3 -0
  54. package/src/i18n/locales/uk.ts +3 -0
  55. package/src/i18n/locales/vi.ts +3 -0
  56. package/src/i18n/locales/zh-tw.ts +3 -0
  57. package/src/i18n/locales/zh.ts +3 -0
  58. package/src/index.ts +1 -0
  59. package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +16 -3
  60. package/types/src/api/getBlocksChangedByTransaction.d.ts +63 -0
  61. package/types/src/api/nodeUtil.d.ts +0 -63
  62. package/types/src/blocks/ImageBlockContent/parseImageElement.d.ts +1 -0
  63. package/types/src/editor/BlockNoteEditor.d.ts +1 -1
  64. package/types/src/extensions/BlockChange/BlockChangePlugin.d.ts +1 -1
  65. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +2 -2
  66. package/types/src/i18n/locales/en.d.ts +3 -0
  67. package/types/src/i18n/locales/sk.d.ts +3 -0
  68. package/types/src/index.d.ts +1 -0
  69. package/types/src/schema/inlineContent/internal.d.ts +1 -1
  70. package/dist/en-CsgPjHa4.cjs.map +0 -1
  71. package/dist/en-Dx9fwHD4.js.map +0 -1
  72. /package/types/src/api/{nodeUtil.test.d.ts → getBlocksChangedByTransaction.test.d.ts} +0 -0
@@ -34,8 +34,8 @@ export const TableBlockContent = createStronglyTypedTiptapNode({
34
34
  ];
35
35
  },
36
36
 
37
- renderHTML({ HTMLAttributes }) {
38
- return createDefaultBlockDOMOutputSpec(
37
+ renderHTML({ node, HTMLAttributes }) {
38
+ const domOutputSpec = createDefaultBlockDOMOutputSpec(
39
39
  this.name,
40
40
  "table",
41
41
  {
@@ -44,6 +44,30 @@ export const TableBlockContent = createStronglyTypedTiptapNode({
44
44
  },
45
45
  this.options.domAttributes?.inlineContent || {},
46
46
  );
47
+
48
+ // Need to manually add colgroup element
49
+ const colGroup = document.createElement("colgroup");
50
+ for (const tableCell of node.children[0].children) {
51
+ const colWidths: null | (number | undefined)[] =
52
+ tableCell.attrs["colwidth"];
53
+
54
+ if (colWidths) {
55
+ for (const colWidth of tableCell.attrs["colwidth"]) {
56
+ const col = document.createElement("col");
57
+ if (colWidth) {
58
+ col.style = `width: ${colWidth}px`;
59
+ }
60
+
61
+ colGroup.appendChild(col);
62
+ }
63
+ } else {
64
+ colGroup.appendChild(document.createElement("col"));
65
+ }
66
+ }
67
+
68
+ domOutputSpec.dom.firstChild?.appendChild(colGroup);
69
+
70
+ return domOutputSpec;
47
71
  },
48
72
 
49
73
  // This node view is needed for the `columnResizing` plugin. By default, the
@@ -146,8 +170,11 @@ const TableParagraph = createStronglyTypedTiptapNode({
146
170
  ];
147
171
  },
148
172
 
149
- renderHTML({ HTMLAttributes }) {
150
- return ["p", HTMLAttributes, 0];
173
+ renderHTML({ node, HTMLAttributes }) {
174
+ // Insert a line break if there is no content, in order to preserve the
175
+ // correct cell height. Otherwise, the cell will have a height of zero +
176
+ // padding.
177
+ return ["p", HTMLAttributes, node.childCount ? 0 : ["br"]];
151
178
  },
152
179
  });
153
180
 
@@ -77,7 +77,8 @@ export const createToggleWrapper = (
77
77
  const toggleAddBlockButton = document.createElement("button");
78
78
  toggleAddBlockButton.className = "bn-toggle-add-block-button";
79
79
  toggleAddBlockButton.type = "button";
80
- toggleAddBlockButton.textContent = "Empty toggle. Click to add a block.";
80
+ toggleAddBlockButton.textContent =
81
+ editor.dictionary.toggle_blocks.add_block_button;
81
82
  const toggleAddBlockButtonMouseDown = (event: MouseEvent) =>
82
83
  event.preventDefault();
83
84
  toggleAddBlockButton.addEventListener(
@@ -110,7 +110,7 @@ import { docToBlocks } from "../api/nodeConversions/nodeToBlock.js";
110
110
  import {
111
111
  BlocksChanged,
112
112
  getBlocksChangedByTransaction,
113
- } from "../api/nodeUtil.js";
113
+ } from "../api/getBlocksChangedByTransaction.js";
114
114
  import { nestedListsToBlockNoteStructure } from "../api/parsers/html/util/nestedLists.js";
115
115
  import { CodeBlockOptions } from "../blocks/CodeBlockContent/CodeBlockContent.js";
116
116
  import type { ThreadStore, User } from "../comments/index.js";
@@ -148,25 +148,16 @@ Tippy popups that are appended to document.body directly
148
148
  transition: all 0.2s;
149
149
  }
150
150
 
151
- /* .tableWrapper {
152
- padding
153
- } */
154
-
155
151
  .bn-editor [data-content-type="table"] .tableWrapper {
156
- position: relative;
157
- top: -16px;
158
- left: -16px;
159
- /* padding: 16px; */
160
- min-width: calc(100% + 16px);
161
- padding-bottom: 16px;
152
+ /* Size of + buttons to add rows/columns. */
153
+ --bn-table-widget-size: 22px;
154
+ /* Size of table handles, divided by 2 since half the element is in the cell. */
155
+ --bn-table-handle-size: calc(18px / 2);
162
156
  overflow-y: hidden;
163
- }
164
-
165
- .bn-editor [data-content-type="table"] .tableWrapper-inner {
166
- /* position: relative; */
167
- /* top: -16px;
168
- left: -16px; */
169
- padding: 16px;
157
+ padding: var(--bn-table-handle-size) var(--bn-table-widget-size)
158
+ var(--bn-table-widget-size) var(--bn-table-handle-size);
159
+ position: relative;
160
+ width: 100%;
170
161
  }
171
162
 
172
163
  /* table related: */
@@ -1,7 +1,9 @@
1
1
  import { Plugin, Transaction } from "prosemirror-state";
2
- import { getBlocksChangedByTransaction } from "../../api/nodeUtil.js";
2
+ import {
3
+ BlocksChanged,
4
+ getBlocksChangedByTransaction,
5
+ } from "../../api/getBlocksChangedByTransaction.js";
3
6
  import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
4
- import { BlocksChanged } from "../../index.js";
5
7
 
6
8
  /**
7
9
  * This plugin can filter transactions before they are applied to the editor, but with a higher-level API than `filterTransaction` from prosemirror.
@@ -1,5 +1,11 @@
1
1
  import { isNodeSelection, isTextSelection, posToDOMRect } from "@tiptap/core";
2
- import { EditorState, Plugin, PluginKey, PluginView } from "prosemirror-state";
2
+ import {
3
+ EditorState,
4
+ Plugin,
5
+ PluginKey,
6
+ PluginView,
7
+ TextSelection,
8
+ } from "prosemirror-state";
3
9
  import { EditorView } from "prosemirror-view";
4
10
 
5
11
  import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
@@ -198,6 +204,52 @@ export class FormattingToolbarView implements PluginView {
198
204
  // e.g. the download file button, should still be accessible. Therefore,
199
205
  // logic for hiding when the editor is non-editable is handled
200
206
  // individually in each button.
207
+ const newReferencePos = this.getSelectionBoundingBox();
208
+
209
+ // Workaround to ensure the correct reference position when rendering
210
+ // React components. Without this, e.g. updating styles on React inline
211
+ // content causes the formatting toolbar to be in the wrong place. We
212
+ // know the component has not yet rendered if the reference position has
213
+ // zero dimensions.
214
+ if (newReferencePos.height === 0 && newReferencePos.width === 0) {
215
+ // Updates the reference position again following the render.
216
+ queueMicrotask(() => {
217
+ const nextState = {
218
+ show: true,
219
+ referencePos: this.getSelectionBoundingBox(),
220
+ };
221
+
222
+ this.state = nextState;
223
+ this.emitUpdate();
224
+
225
+ // For some reason, while the selection doesn't actually change and
226
+ // remains correct, it visually appears to be collapsed. This forces
227
+ // a ProseMirror view update, which fixes the issue.
228
+ view.dispatch(
229
+ view.state.tr.setSelection(
230
+ TextSelection.create(
231
+ view.state.doc,
232
+ view.state.selection.from + 1,
233
+ view.state.selection.to,
234
+ ),
235
+ ),
236
+ );
237
+ // 2 separate `dispatch` calls are needed, else ProseMirror realizes
238
+ // that the transaction is a no-op and doesn't update the view.
239
+ view.dispatch(
240
+ view.state.tr.setSelection(
241
+ TextSelection.create(
242
+ view.state.doc,
243
+ view.state.selection.from - 1,
244
+ view.state.selection.to,
245
+ ),
246
+ ),
247
+ );
248
+ });
249
+
250
+ return;
251
+ }
252
+
201
253
  const nextState = {
202
254
  show: true,
203
255
  referencePos: this.getSelectionBoundingBox(),
@@ -242,21 +242,11 @@ export class SideMenuView<
242
242
 
243
243
  this.hoveredBlock = block.node;
244
244
 
245
- // Gets the block's content node, which lets to ignore child blocks when determining the block menu's position.
246
- // TODO: needed?
247
- const blockContent = block.node.firstChild as HTMLElement;
248
-
249
- if (!blockContent) {
250
- return;
251
- }
252
-
253
- // TODO: needed?
254
-
255
245
  // Shows or updates elements.
256
246
  if (this.editor.isEditable) {
257
- const blockContentBoundingBox = blockContent.getBoundingClientRect();
247
+ const blockContentBoundingBox = block.node.getBoundingClientRect();
258
248
  const column = block.node.closest("[data-node-type=column]");
259
- this.updateState({
249
+ this.state = {
260
250
  show: true,
261
251
  referencePos: new DOMRect(
262
252
  column
@@ -275,7 +265,8 @@ export class SideMenuView<
275
265
  block: this.editor.getBlock(
276
266
  this.hoveredBlock!.getAttribute("data-id")!,
277
267
  )!,
278
- });
268
+ };
269
+ this.updateState(this.state);
279
270
  }
280
271
  };
281
272
 
@@ -435,9 +426,9 @@ export class SideMenuView<
435
426
  // We need to check if there is text content that is being dragged (select some text & just drag it)
436
427
  const textContentIsBeingDragged =
437
428
  !event.dataTransfer?.types.includes("blocknote/html") &&
438
- Boolean(this.pmView.dragging);
429
+ !!this.pmView.dragging;
439
430
  // This is the side menu drag from this plugin
440
- const sideMenuIsBeingDragged = Boolean(this.isDragOrigin);
431
+ const sideMenuIsBeingDragged = !!this.isDragOrigin;
441
432
  // Tells us that the current editor instance has a drag ongoing (either text or side menu)
442
433
  const isDragOrigin = textContentIsBeingDragged || sideMenuIsBeingDragged;
443
434
 
@@ -182,6 +182,9 @@ export const ar: Dictionary = {
182
182
  add_button_text: "إضافة ملف",
183
183
  },
184
184
  },
185
+ toggle_blocks: {
186
+ add_block_button: "تبديل فارغ. انقر لإضافة كتلة.",
187
+ },
185
188
  // from react package:
186
189
  side_menu: {
187
190
  add_block_label: "إضافة محتوي",
@@ -217,6 +217,10 @@ export const de: Dictionary = {
217
217
  add_button_text: "Datei hinzufügen",
218
218
  },
219
219
  },
220
+ toggle_blocks: {
221
+ add_block_button:
222
+ "Leerer aufklappbarer Bereich. Klicken, um einen Block hinzuzufügen.",
223
+ },
220
224
  side_menu: {
221
225
  add_block_label: "Block hinzufügen",
222
226
  drag_handle_label: "Blockmenü öffnen",
@@ -197,6 +197,9 @@ export const en = {
197
197
  add_button_text: "Add file",
198
198
  },
199
199
  },
200
+ toggle_blocks: {
201
+ add_block_button: "Empty toggle. Click to add a block.",
202
+ },
200
203
  // from react package:
201
204
  side_menu: {
202
205
  add_block_label: "Add block",
@@ -197,6 +197,9 @@ export const es: Dictionary = {
197
197
  add_button_text: "Agregar archivo",
198
198
  },
199
199
  },
200
+ toggle_blocks: {
201
+ add_block_button: "Toggle vacío. Haz clic para añadir un bloque.",
202
+ },
200
203
  side_menu: {
201
204
  add_block_label: "Agregar bloque",
202
205
  drag_handle_label: "Abrir menú de bloque",
@@ -243,6 +243,9 @@ export const fr: Dictionary = {
243
243
  add_button_text: "Ajouter un fichier",
244
244
  },
245
245
  },
246
+ toggle_blocks: {
247
+ add_block_button: "Toggle vide. Cliquez pour ajouter un bloc.",
248
+ },
246
249
  // from react package:
247
250
  side_menu: {
248
251
  add_block_label: "Ajouter un bloc",
@@ -199,6 +199,9 @@ export const he: Dictionary = {
199
199
  add_button_text: "הוסף קובץ",
200
200
  },
201
201
  },
202
+ toggle_blocks: {
203
+ add_block_button: "מתג ריק. לחץ כדי להוסיף בלוק.",
204
+ },
202
205
  side_menu: {
203
206
  add_block_label: "הוסף בלוק",
204
207
  drag_handle_label: "פתח תפריט בלוק",
@@ -210,6 +210,9 @@ export const hr: Dictionary = {
210
210
  add_button_text: "Dodaj datoteku",
211
211
  },
212
212
  },
213
+ toggle_blocks: {
214
+ add_block_button: "Prazan sklopivi blok. Klikni da dodaš sadržaj.",
215
+ },
213
216
  // from react package:
214
217
  side_menu: {
215
218
  add_block_label: "Dodaj blok",
@@ -211,6 +211,9 @@ export const is: Dictionary = {
211
211
  add_button_text: "Bæta við skrá",
212
212
  },
213
213
  },
214
+ toggle_blocks: {
215
+ add_block_button: "Tóm fellilína. Smelltu til að bæta við blokk.",
216
+ },
214
217
  side_menu: {
215
218
  add_block_label: "Bæta við blokki",
216
219
  drag_handle_label: "Opna blokkarvalmynd",
@@ -219,6 +219,9 @@ export const it: Dictionary = {
219
219
  add_button_text: "Aggiungi file",
220
220
  },
221
221
  },
222
+ toggle_blocks: {
223
+ add_block_button: "Toggle vuoto. Clicca per aggiungere un blocco.",
224
+ },
222
225
  // from react package:
223
226
  side_menu: {
224
227
  add_block_label: "Aggiungi blocco",
@@ -237,6 +237,9 @@ export const ja: Dictionary = {
237
237
  add_button_text: "ファイルを追加",
238
238
  },
239
239
  },
240
+ toggle_blocks: {
241
+ add_block_button: "空のトグルです。クリックしてブロックを追加。",
242
+ },
240
243
  // from react package:
241
244
  side_menu: {
242
245
  add_block_label: "ブロックを追加",
@@ -42,7 +42,7 @@ export const ko: Dictionary = {
42
42
  title: "접을 수 있는 제목1",
43
43
  subtext: "내용을 표시하거나 숨길 수 있는 섹션 제목(대)",
44
44
  aliases: ["h", "제목1", "h1", "대제목", "접기", "토글"],
45
- group: "제목",
45
+ group: "소제목",
46
46
  },
47
47
  toggle_heading_2: {
48
48
  title: "접을 수 있는 제목2",
@@ -210,6 +210,9 @@ export const ko: Dictionary = {
210
210
  add_button_text: "파일 추가",
211
211
  },
212
212
  },
213
+ toggle_blocks: {
214
+ add_block_button: "비어 있는 토글입니다. 클릭하여 블록을 추가하세요.",
215
+ },
213
216
  // from react package:
214
217
  side_menu: {
215
218
  add_block_label: "블록 추가",
@@ -198,6 +198,9 @@ export const nl: Dictionary = {
198
198
  add_button_text: "Bestand toevoegen",
199
199
  },
200
200
  },
201
+ toggle_blocks: {
202
+ add_block_button: "Lege uitklapper. Klik om een blok toe te voegen.",
203
+ },
201
204
  // from react package:
202
205
  side_menu: {
203
206
  add_block_label: "Nieuw blok",
@@ -216,6 +216,9 @@ export const no: Dictionary = {
216
216
  add_button_text: "Legg til fil",
217
217
  },
218
218
  },
219
+ toggle_blocks: {
220
+ add_block_button: "Tomt toggle. Klikk for å legge til en blokk.",
221
+ },
219
222
  side_menu: {
220
223
  add_block_label: "Legg til blokk",
221
224
  drag_handle_label: "Åpne blokkmeny",
@@ -188,6 +188,10 @@ export const pl: Dictionary = {
188
188
  add_button_text: "Dodaj plik",
189
189
  },
190
190
  },
191
+ toggle_blocks: {
192
+ add_block_button:
193
+ "Brak bloków do rozwinięcia. Kliknij, aby dodać pierwszego.",
194
+ },
191
195
  side_menu: {
192
196
  add_block_label: "Dodaj blok",
193
197
  drag_handle_label: "Otwórz menu bloków",
@@ -189,6 +189,9 @@ export const pt: Dictionary = {
189
189
  add_button_text: "Adicionar arquivo",
190
190
  },
191
191
  },
192
+ toggle_blocks: {
193
+ add_block_button: "Toggle vazio. Clique para adicionar um bloco.",
194
+ },
192
195
  // from react package:
193
196
  side_menu: {
194
197
  add_block_label: "Adicionar bloco",
@@ -240,6 +240,9 @@ export const ru: Dictionary = {
240
240
  add_button_text: "Добавить файл",
241
241
  },
242
242
  },
243
+ toggle_blocks: {
244
+ add_block_button: "Пустой переключатель. Нажмите, чтобы добавить блок.",
245
+ },
243
246
  // from react package:
244
247
  side_menu: {
245
248
  add_block_label: "Добавить блок",
@@ -197,6 +197,9 @@ export const sk = {
197
197
  add_button_text: "Pridať súbor",
198
198
  },
199
199
  },
200
+ toggle_blocks: {
201
+ add_block_button: "Prázdne prepínanie. Kliknite pre pridanie bloku.",
202
+ },
200
203
  side_menu: {
201
204
  add_block_label: "Pridať blok",
202
205
  drag_handle_label: "Otvoriť menu bloku",
@@ -222,6 +222,9 @@ export const uk: Dictionary = {
222
222
  add_button_text: "Додати файл",
223
223
  },
224
224
  },
225
+ toggle_blocks: {
226
+ add_block_button: "Порожній перемикач. Натисніть, щоб додати блок.",
227
+ },
225
228
  // from react package:
226
229
  side_menu: {
227
230
  add_block_label: "Додати блок",
@@ -196,6 +196,9 @@ export const vi: Dictionary = {
196
196
  add_button_text: "Thêm tệp",
197
197
  },
198
198
  },
199
+ toggle_blocks: {
200
+ add_block_button: "Toggle trống. Nhấp để thêm khối.",
201
+ },
199
202
  // từ gói phản ứng:
200
203
  side_menu: {
201
204
  add_block_label: "Thêm khối",
@@ -238,6 +238,9 @@ export const zhTW: Dictionary = {
238
238
  add_button_text: "新增檔案",
239
239
  },
240
240
  },
241
+ toggle_blocks: {
242
+ add_block_button: "空的切換區。點擊新增區塊。",
243
+ },
241
244
  // from react package:
242
245
  side_menu: {
243
246
  add_block_label: "新增區塊",
@@ -238,6 +238,9 @@ export const zh: Dictionary = {
238
238
  add_button_text: "添加文件",
239
239
  },
240
240
  },
241
+ toggle_blocks: {
242
+ add_block_button: "空的切换区。点击添加区块。",
243
+ },
241
244
  // from react package:
242
245
  side_menu: {
243
246
  add_block_label: "添加块",
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ export * from "./api/blockManipulation/commands/updateBlock/updateBlock.js";
4
4
  export * from "./api/exporters/html/externalHTMLExporter.js";
5
5
  export * from "./api/exporters/html/internalHTMLSerializer.js";
6
6
  export * from "./api/getBlockInfoFromPos.js";
7
+ export * from "./api/getBlocksChangedByTransaction.js";
7
8
  export * from "./api/nodeUtil.js";
8
9
  export * from "./api/pmUtil.js";
9
10
  export * from "./blocks/AudioBlockContent/AudioBlockContent.js";
@@ -1,4 +1,4 @@
1
- import type { Transaction } from "prosemirror-state";
1
+ import { Transaction } from "prosemirror-state";
2
2
  import { Transform } from "prosemirror-transform";
3
3
  import type { Block, PartialBlock } from "../../../../blocks/defaultBlocks.js";
4
4
  import type { BlockIdentifier, BlockSchema } from "../../../../schema/blocks/types.js";
@@ -8,5 +8,18 @@ export declare const updateBlockCommand: <BSchema extends BlockSchema, I extends
8
8
  tr: Transaction;
9
9
  dispatch?: () => void;
10
10
  }) => boolean;
11
- export declare function updateBlockTr<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(tr: Transform, posBeforeBlock: number, block: PartialBlock<BSchema, I, S>, replaceFromPos?: number, replaceToPos?: number): void;
12
- export declare function updateBlock<BSchema extends BlockSchema = any, I extends InlineContentSchema = any, S extends StyleSchema = any>(tr: Transaction, blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema, I, S>, replaceFromPos?: number, replaceToPos?: number): Block<BSchema, I, S>;
11
+ export declare function updateBlockTr<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(tr: Transform | Transaction, posBeforeBlock: number, block: PartialBlock<BSchema, I, S>, replaceFromPos?: number, replaceToPos?: number): void;
12
+ export declare function updateBlock<BSchema extends BlockSchema = any, I extends InlineContentSchema = any, S extends StyleSchema = any>(tr: Transform, blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema, I, S>, replaceFromPos?: number, replaceToPos?: number): Block<BSchema, I, S>;
13
+ type CellAnchor = {
14
+ row: number;
15
+ col: number;
16
+ offset: number;
17
+ };
18
+ /**
19
+ * Captures the cell anchor from the current selection.
20
+ * @param tr - The transaction to capture the cell anchor from.
21
+ *
22
+ * @returns The cell anchor, or null if no cell is selected.
23
+ */
24
+ export declare function captureCellAnchor(tr: Transform): CellAnchor | null;
25
+ export {};
@@ -0,0 +1,63 @@
1
+ import type { Transaction } from "prosemirror-state";
2
+ import { Block, DefaultBlockSchema, DefaultInlineContentSchema, DefaultStyleSchema } from "../blocks/defaultBlocks.js";
3
+ import type { BlockSchema } from "../schema/index.js";
4
+ import type { InlineContentSchema } from "../schema/inlineContent/types.js";
5
+ import type { StyleSchema } from "../schema/styles/types.js";
6
+ /**
7
+ * This attributes the changes to a specific source.
8
+ */
9
+ export type BlockChangeSource = {
10
+ type: "local";
11
+ } | {
12
+ type: "paste";
13
+ } | {
14
+ type: "drop";
15
+ } | {
16
+ type: "undo" | "redo" | "undo-redo";
17
+ } | {
18
+ type: "yjs-remote";
19
+ };
20
+ export type BlocksChanged<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema> = Array<{
21
+ /**
22
+ * The affected block.
23
+ */
24
+ block: Block<BSchema, ISchema, SSchema>;
25
+ /**
26
+ * The source of the change.
27
+ */
28
+ source: BlockChangeSource;
29
+ } & ({
30
+ type: "insert" | "delete";
31
+ /**
32
+ * Insert and delete changes don't have a previous block.
33
+ */
34
+ prevBlock: undefined;
35
+ } | {
36
+ type: "update";
37
+ /**
38
+ * The previous block.
39
+ */
40
+ prevBlock: Block<BSchema, ISchema, SSchema>;
41
+ } | {
42
+ type: "move";
43
+ /**
44
+ * The affected block.
45
+ */
46
+ block: Block<BSchema, ISchema, SSchema>;
47
+ /**
48
+ * The block before the move.
49
+ */
50
+ prevBlock: Block<BSchema, ISchema, SSchema>;
51
+ /**
52
+ * The previous parent block (if it existed).
53
+ */
54
+ prevParent?: Block<BSchema, ISchema, SSchema>;
55
+ /**
56
+ * The current parent block (if it exists).
57
+ */
58
+ currentParent?: Block<BSchema, ISchema, SSchema>;
59
+ })>;
60
+ /**
61
+ * Get the blocks that were changed by a transaction.
62
+ */
63
+ export declare function getBlocksChangedByTransaction<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema>(transaction: Transaction, appendedTransactions?: Transaction[]): BlocksChanged<BSchema, ISchema, SSchema>;
@@ -1,9 +1,4 @@
1
1
  import type { Node } from "prosemirror-model";
2
- import type { Transaction } from "prosemirror-state";
3
- import { Block, DefaultBlockSchema, DefaultInlineContentSchema, DefaultStyleSchema } from "../blocks/defaultBlocks.js";
4
- import type { BlockSchema } from "../schema/index.js";
5
- import type { InlineContentSchema } from "../schema/inlineContent/types.js";
6
- import type { StyleSchema } from "../schema/styles/types.js";
7
2
  /**
8
3
  * Get a TipTap node by id
9
4
  */
@@ -12,61 +7,3 @@ export declare function getNodeById(id: string, doc: Node): {
12
7
  posBeforeNode: number;
13
8
  } | undefined;
14
9
  export declare function isNodeBlock(node: Node): boolean;
15
- /**
16
- * This attributes the changes to a specific source.
17
- */
18
- export type BlockChangeSource = {
19
- type: "local";
20
- } | {
21
- type: "paste";
22
- } | {
23
- type: "drop";
24
- } | {
25
- type: "undo" | "redo" | "undo-redo";
26
- } | {
27
- type: "yjs-remote";
28
- };
29
- export type BlocksChanged<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema> = Array<{
30
- /**
31
- * The affected block.
32
- */
33
- block: Block<BSchema, ISchema, SSchema>;
34
- /**
35
- * The source of the change.
36
- */
37
- source: BlockChangeSource;
38
- } & ({
39
- type: "insert" | "delete";
40
- /**
41
- * Insert and delete changes don't have a previous block.
42
- */
43
- prevBlock: undefined;
44
- } | {
45
- type: "update";
46
- /**
47
- * The previous block.
48
- */
49
- prevBlock: Block<BSchema, ISchema, SSchema>;
50
- } | {
51
- type: "move";
52
- /**
53
- * The affected block.
54
- */
55
- block: Block<BSchema, ISchema, SSchema>;
56
- /**
57
- * The block before the move.
58
- */
59
- prevBlock: Block<BSchema, ISchema, SSchema>;
60
- /**
61
- * The previous parent block (if it existed).
62
- */
63
- prevParent?: Block<BSchema, ISchema, SSchema>;
64
- /**
65
- * The current parent block (if it exists).
66
- */
67
- currentParent?: Block<BSchema, ISchema, SSchema>;
68
- })>;
69
- /**
70
- * Get the blocks that were changed by a transaction.
71
- */
72
- export declare function getBlocksChangedByTransaction<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema>(transaction: Transaction, appendedTransactions?: Transaction[]): BlocksChanged<BSchema, ISchema, SSchema>;
@@ -1,4 +1,5 @@
1
1
  export declare const parseImageElement: (imageElement: HTMLImageElement) => {
2
2
  url: string | undefined;
3
3
  previewWidth: number | undefined;
4
+ name: string | undefined;
4
5
  };