@blocknote/core 0.53.0 → 0.54.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/BlockNoteExtension-BJCLnwrE.cjs +2 -0
- package/dist/BlockNoteExtension-BJCLnwrE.cjs.map +1 -0
- package/dist/BlockNoteExtension-CbvDA0F7.js +80 -0
- package/dist/BlockNoteExtension-CbvDA0F7.js.map +1 -0
- package/dist/{UserStore-QbbPFj0z.js → UserStore-C4TzkGEn.js} +3 -3
- package/dist/{UserStore-DCG6lsla.cjs.map → UserStore-C4TzkGEn.js.map} +1 -1
- package/dist/{UserStore-DCG6lsla.cjs → UserStore-mj3fXW4D.cjs} +2 -2
- package/dist/UserStore-mj3fXW4D.cjs.map +1 -0
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.js +6 -6
- package/dist/blocks-CTB_5Vyj.cjs +12 -0
- package/dist/blocks-CTB_5Vyj.cjs.map +1 -0
- package/dist/{blocks-BEJW9OM_.js → blocks-Dol85hpH.js} +680 -670
- package/dist/blocks-Dol85hpH.js.map +1 -0
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +7 -7
- package/dist/comments.js.map +1 -1
- package/dist/en-BuzSuuTq.cjs +2 -0
- package/dist/en-BuzSuuTq.cjs.map +1 -0
- package/dist/{en-CGKXfWma.js → en-uzHzj6eH.js} +10 -1
- package/dist/en-uzHzj6eH.js.map +1 -0
- package/dist/extensions-B7Rsp_Ft.cjs +58 -0
- package/dist/extensions-B7Rsp_Ft.cjs.map +1 -0
- package/dist/{extensions-BR5hkAio.js → extensions-D6JcJCwd.js} +735 -457
- package/dist/extensions-D6JcJCwd.js.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +4 -4
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +199 -1
- package/dist/locales.js.map +1 -1
- package/dist/{src-BUXut68d.js → src-Buuo5l7X.js} +924 -851
- package/dist/src-Buuo5l7X.js.map +1 -0
- package/dist/src-C54Ok9E0.cjs +23 -0
- package/dist/src-C54Ok9E0.cjs.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/y.cjs +1 -1
- package/dist/y.cjs.map +1 -1
- package/dist/y.js +245 -242
- package/dist/y.js.map +1 -1
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +79 -67
- package/dist/yjs.js.map +1 -1
- package/package.json +17 -18
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2505 -763
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +42 -0
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +16 -4
- package/src/api/exporters/markdown/htmlToMarkdown.ts +45 -10
- package/src/api/getBlocksChangedByTransaction.test.ts +211 -0
- package/src/api/getBlocksChangedByTransaction.ts +48 -12
- package/src/api/getChangedRange.ts +54 -0
- package/src/api/nodeConversions/blockToNode.ts +5 -1
- package/src/api/nodeConversions/nodeToBlock.ts +3 -0
- package/src/api/pmUtil.ts +16 -8
- package/src/blocks/Code/CodeBlockOptions.ts +83 -0
- package/src/blocks/Code/block.test.ts +1 -1
- package/src/blocks/Code/block.ts +29 -281
- package/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts +120 -0
- package/src/blocks/Code/helpers/parse/parsePreCode.ts +45 -0
- package/src/blocks/Code/helpers/render/createCodeBlock.ts +98 -0
- package/src/blocks/Code/helpers/toExternalHTML/createPreCode.ts +14 -0
- package/src/blocks/index.ts +3 -1
- package/src/comments/extension.ts +2 -4
- package/src/editor/Block.css +273 -2
- package/src/editor/BlockNoteEditor.ts +25 -4
- package/src/editor/BlockNoteExtension.ts +1 -1
- package/src/editor/managers/ExtensionManager/extensions.ts +6 -0
- package/src/editor/performance.test.ts +45 -0
- package/src/exporter/ExportImage.ts +50 -0
- package/src/exporter/Exporter.test.ts +186 -0
- package/src/exporter/Exporter.ts +66 -14
- package/src/exporter/index.ts +1 -0
- package/src/exporter/mapping.ts +4 -1
- package/src/extensions/FormattingToolbar/FormattingToolbar.ts +10 -8
- package/src/extensions/InlineContentBoundaryEdit/InlineContentBoundaryEdit.ts +109 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +21 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +5 -3
- package/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.ts +192 -0
- package/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.ts +142 -0
- package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.ts +120 -0
- package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.ts +89 -0
- package/src/extensions/SyntaxHighlighting/inlineHighlight.test.ts +135 -0
- package/src/extensions/SyntaxHighlighting/shiki.ts +116 -0
- package/src/extensions/TableHandles/TableHandles.browser.test.ts +305 -0
- package/src/extensions/TableHandles/TableHandles.ts +82 -41
- package/src/extensions/Versioning/inMemoryVersioning.ts +13 -3
- package/src/extensions/index.ts +4 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +51 -2
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +22 -2
- package/src/fonts/inter.css +9 -9
- package/src/i18n/locales/ar.ts +9 -0
- package/src/i18n/locales/de.ts +9 -0
- package/src/i18n/locales/en.ts +9 -0
- package/src/i18n/locales/es.ts +9 -0
- package/src/i18n/locales/fa.ts +9 -0
- package/src/i18n/locales/fr.ts +9 -0
- package/src/i18n/locales/he.ts +9 -0
- package/src/i18n/locales/hr.ts +9 -0
- package/src/i18n/locales/is.ts +9 -0
- package/src/i18n/locales/it.ts +9 -0
- package/src/i18n/locales/ja.ts +9 -0
- package/src/i18n/locales/ko.ts +9 -0
- package/src/i18n/locales/nl.ts +9 -0
- package/src/i18n/locales/no.ts +9 -0
- package/src/i18n/locales/pl.ts +9 -0
- package/src/i18n/locales/pt.ts +9 -0
- package/src/i18n/locales/ru.ts +9 -0
- package/src/i18n/locales/sk.ts +9 -0
- package/src/i18n/locales/uk.ts +9 -0
- package/src/i18n/locales/uz.ts +9 -0
- package/src/i18n/locales/vi.ts +9 -0
- package/src/i18n/locales/zh-tw.ts +9 -0
- package/src/i18n/locales/zh.ts +9 -0
- package/src/index.ts +5 -1
- package/src/schema/blocks/createSpec.ts +5 -7
- package/src/schema/blocks/types.ts +53 -3
- package/src/schema/contentTypePropagation.test.ts +1 -1
- package/src/schema/inlineContent/createSpec.test.ts +161 -0
- package/src/schema/inlineContent/createSpec.ts +175 -17
- package/src/schema/inlineContent/internal.ts +21 -2
- package/src/schema/inlineContent/types.ts +35 -5
- package/src/schema/nodeViewMutations.test.ts +81 -56
- package/src/schema/nodeViewMutations.ts +30 -27
- package/src/schema/schema.test.ts +110 -0
- package/src/schema/schema.ts +13 -4
- package/src/user/UserStore.ts +1 -1
- package/src/util/Store.test.ts +132 -0
- package/src/util/Store.ts +135 -0
- package/src/y/extensions/AttributionExtension.test.ts +18 -9
- package/src/y/extensions/Versioning.test.ts +20 -7
- package/src/y/versioning/__test__/yhub.test.ts +92 -59
- package/src/y/versioning/yhub.ts +35 -29
- package/src/yjs/comments/RESTYjsThreadStore.test.ts +85 -0
- package/src/yjs/comments/RESTYjsThreadStore.ts +7 -1
- package/src/yjs/extensions/ForkYDoc.test.ts +37 -0
- package/src/yjs/extensions/ForkYDoc.ts +26 -1
- package/src/yjs/extensions/RelativePositionMapping.ts +8 -2
- package/src/yjs/extensions/Versioning.test.ts +17 -5
- package/types/src/api/getChangedRange.d.ts +14 -0
- package/types/src/api/pmUtil.d.ts +7 -7
- package/types/src/blocks/Code/CodeBlockOptions.d.ts +61 -0
- package/types/src/blocks/Code/block.d.ts +3 -53
- package/types/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.d.ts +35 -0
- package/types/src/blocks/Code/helpers/parse/parsePreCode.d.ts +8 -0
- package/types/src/blocks/Code/helpers/render/createCodeBlock.d.ts +18 -0
- package/types/src/blocks/Code/helpers/toExternalHTML/createPreCode.d.ts +5 -0
- package/types/src/blocks/index.d.ts +3 -1
- package/types/src/comments/extension.d.ts +1 -15
- package/types/src/editor/BlockNoteEditor.d.ts +3 -3
- package/types/src/editor/BlockNoteExtension.d.ts +1 -1
- package/types/src/exporter/ExportImage.d.ts +36 -0
- package/types/src/exporter/Exporter.d.ts +30 -0
- package/types/src/exporter/Exporter.test.d.ts +1 -0
- package/types/src/exporter/index.d.ts +1 -0
- package/types/src/exporter/mapping.d.ts +1 -1
- package/types/src/extensions/FilePanel/FilePanel.d.ts +1 -1
- package/types/src/extensions/FormattingToolbar/FormattingToolbar.d.ts +1 -1
- package/types/src/extensions/InlineContentBoundaryEdit/InlineContentBoundaryEdit.d.ts +5 -0
- package/types/src/extensions/ShowSelection/ShowSelection.d.ts +1 -5
- package/types/src/extensions/SideMenu/SideMenu.d.ts +1 -1
- package/types/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.d.ts +45 -0
- package/types/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.d.ts +49 -0
- package/types/src/extensions/SuggestionMenu/SuggestionMenu.d.ts +1 -11
- package/types/src/extensions/SyntaxHighlighting/SyntaxHighlighting.d.ts +44 -0
- package/types/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.d.ts +1 -0
- package/types/src/extensions/SyntaxHighlighting/inlineHighlight.test.d.ts +1 -0
- package/types/src/extensions/SyntaxHighlighting/shiki.d.ts +13 -0
- package/types/src/extensions/TableHandles/TableHandles.browser.test.d.ts +1 -0
- package/types/src/extensions/TableHandles/TableHandles.d.ts +4 -1
- package/types/src/extensions/Versioning/Versioning.d.ts +1 -35
- package/types/src/extensions/index.d.ts +4 -0
- package/types/src/i18n/locales/en.d.ts +9 -0
- package/types/src/i18n/locales/fa.d.ts +9 -0
- package/types/src/i18n/locales/sk.d.ts +9 -0
- package/types/src/index.d.ts +2 -1
- package/types/src/schema/blocks/types.d.ts +36 -3
- package/types/src/schema/inlineContent/createSpec.d.ts +35 -3
- package/types/src/schema/inlineContent/createSpec.test.d.ts +1 -0
- package/types/src/schema/inlineContent/internal.d.ts +3 -2
- package/types/src/schema/inlineContent/types.d.ts +22 -3
- package/types/src/schema/nodeViewMutations.d.ts +2 -2
- package/types/src/schema/schema.test.d.ts +1 -0
- package/types/src/user/UserStore.d.ts +1 -1
- package/types/src/util/Store.d.ts +45 -0
- package/types/src/util/Store.test.d.ts +1 -0
- package/types/src/y/extensions/AttributionExtension.d.ts +1 -1
- package/types/src/y/extensions/DiffVersioningExtension.d.ts +1 -1
- package/types/src/y/extensions/ForkYDoc.d.ts +1 -5
- package/types/src/y/extensions/index.d.ts +2 -10
- package/types/src/y/versioning/yhub.d.ts +3 -2
- package/types/src/yjs/comments/RESTYjsThreadStore.test.d.ts +1 -0
- package/types/src/yjs/extensions/ForkYDoc.d.ts +1 -5
- package/types/src/yjs/extensions/index.d.ts +1 -5
- package/dist/BlockNoteExtension-B_IEJHS8.js +0 -38
- package/dist/BlockNoteExtension-B_IEJHS8.js.map +0 -1
- package/dist/BlockNoteExtension-M0znTzxP.cjs +0 -2
- package/dist/BlockNoteExtension-M0znTzxP.cjs.map +0 -1
- package/dist/UserStore-QbbPFj0z.js.map +0 -1
- package/dist/blocks-BEJW9OM_.js.map +0 -1
- package/dist/blocks-BPmJglFo.cjs +0 -12
- package/dist/blocks-BPmJglFo.cjs.map +0 -1
- package/dist/en-C5Z4Ag9_.cjs +0 -2
- package/dist/en-C5Z4Ag9_.cjs.map +0 -1
- package/dist/en-CGKXfWma.js.map +0 -1
- package/dist/extensions-AitWbYdJ.cjs +0 -52
- package/dist/extensions-AitWbYdJ.cjs.map +0 -1
- package/dist/extensions-BR5hkAio.js.map +0 -1
- package/dist/src-BHPuOo7W.cjs +0 -21
- package/dist/src-BHPuOo7W.cjs.map +0 -1
- package/dist/src-BUXut68d.js.map +0 -1
- package/src/blocks/Code/shiki.ts +0 -73
- package/src/blocks/File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -20
- package/types/src/blocks/Code/shiki.d.ts +0 -4
- package/types/src/blocks/File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -6
package/src/y/versioning/yhub.ts
CHANGED
|
@@ -25,7 +25,8 @@ const VERSION_NAMES_MAP = "__bn_version_names";
|
|
|
25
25
|
*/
|
|
26
26
|
export interface YHubVersioningOptions {
|
|
27
27
|
/**
|
|
28
|
-
* Base URL of the YHub API
|
|
28
|
+
* Base URL of the YHub API, including the API prefix
|
|
29
|
+
* (e.g. `"https://yhub.example.com/api"`).
|
|
29
30
|
* Must **not** include a trailing slash.
|
|
30
31
|
*/
|
|
31
32
|
baseUrl: string;
|
|
@@ -79,7 +80,7 @@ export interface YHubVersioningOptions {
|
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
82
|
* Shape of a single activity entry returned by the YHub
|
|
82
|
-
* `GET /activity/{org}/{docId}` endpoint (after `decodeAny`).
|
|
83
|
+
* `GET /api/activity/v1/{org}/{docId}` endpoint (after `decodeAny`).
|
|
83
84
|
*/
|
|
84
85
|
interface YHubActivityEntry {
|
|
85
86
|
/** Start of the change window (unix-ms timestamp). */
|
|
@@ -93,14 +94,12 @@ interface YHubActivityEntry {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
/**
|
|
96
|
-
* Shape returned by the YHub `GET /changeset/{org}/{docId}` endpoint
|
|
97
|
-
* `decodeAny`).
|
|
97
|
+
* Shape returned by the YHub `GET /api/changeset/v1/{org}/{docId}` endpoint
|
|
98
|
+
* (after `decodeAny`).
|
|
98
99
|
*/
|
|
99
100
|
interface YHubChangeset {
|
|
100
|
-
/** Full Y.Doc state
|
|
101
|
-
|
|
102
|
-
/** Full Y.Doc state **after** the changeset window. */
|
|
103
|
-
nextDoc?: Uint8Array;
|
|
101
|
+
/** Full Y.Doc state at the `to` timestamp. */
|
|
102
|
+
ydoc?: Uint8Array;
|
|
104
103
|
/**
|
|
105
104
|
* Encoded {@link Y.ContentMap} describing who authored each change in the
|
|
106
105
|
* window and when. Present when the changeset is requested with
|
|
@@ -109,6 +108,11 @@ interface YHubChangeset {
|
|
|
109
108
|
attributions?: Uint8Array;
|
|
110
109
|
}
|
|
111
110
|
|
|
111
|
+
/** Shape returned by the YHub activity endpoint. */
|
|
112
|
+
interface YHubActivityResponse {
|
|
113
|
+
activity: YHubActivityEntry[];
|
|
114
|
+
}
|
|
115
|
+
|
|
112
116
|
/**
|
|
113
117
|
* Whether an activity entry is a version marker (created with a `type:version`
|
|
114
118
|
* custom attribution) as opposed to a plain edit.
|
|
@@ -228,7 +232,7 @@ async function yhubFetch(
|
|
|
228
232
|
* user: { name: "Alice", color: "#ff0" },
|
|
229
233
|
* provider,
|
|
230
234
|
* versioningEndpoints: createYHubVersioningEndpoints({
|
|
231
|
-
* baseUrl: "https://yhub.example.com",
|
|
235
|
+
* baseUrl: "https://yhub.example.com/api",
|
|
232
236
|
* org: "my-org",
|
|
233
237
|
* docId: "my-doc",
|
|
234
238
|
* }),
|
|
@@ -249,9 +253,10 @@ export function createYHubVersioningEndpoints(
|
|
|
249
253
|
group,
|
|
250
254
|
} = options;
|
|
251
255
|
|
|
252
|
-
const activityUrl = `${baseUrl}/activity/${org}/${docId}`;
|
|
253
|
-
const changesetUrl = `${baseUrl}/changeset/${org}/${docId}`;
|
|
254
|
-
const rollbackUrl = `${baseUrl}/rollback/${org}/${docId}`;
|
|
256
|
+
const activityUrl = `${baseUrl}/activity/v1/${org}/${docId}`;
|
|
257
|
+
const changesetUrl = `${baseUrl}/changeset/v1/${org}/${docId}`;
|
|
258
|
+
const rollbackUrl = `${baseUrl}/rollback/v1/${org}/${docId}`;
|
|
259
|
+
const ydocUrl = `${baseUrl}/ydoc/v1/${org}/${docId}`;
|
|
255
260
|
|
|
256
261
|
return (editor) => {
|
|
257
262
|
/**
|
|
@@ -309,11 +314,11 @@ export function createYHubVersioningEndpoints(
|
|
|
309
314
|
yhubFetch(`${activityUrl}?${latestVersionParams}`, headers),
|
|
310
315
|
]);
|
|
311
316
|
const latestEdit = (
|
|
312
|
-
decodeAny(new Uint8Array(latestBuf)) as
|
|
313
|
-
)[0];
|
|
317
|
+
decodeAny(new Uint8Array(latestBuf)) as YHubActivityResponse
|
|
318
|
+
).activity[0];
|
|
314
319
|
const latestVersion = (
|
|
315
|
-
decodeAny(new Uint8Array(latestVersionBuf)) as
|
|
316
|
-
)[0];
|
|
320
|
+
decodeAny(new Uint8Array(latestVersionBuf)) as YHubActivityResponse
|
|
321
|
+
).activity[0];
|
|
317
322
|
|
|
318
323
|
if (!latestEdit || latestEdit.to <= (latestVersion?.to ?? 0)) {
|
|
319
324
|
return undefined;
|
|
@@ -370,15 +375,14 @@ export function createYHubVersioningEndpoints(
|
|
|
370
375
|
const update = Y.encodeStateAsUpdate(markerDoc);
|
|
371
376
|
|
|
372
377
|
const body: Record<string, unknown> = { update, customAttributions };
|
|
378
|
+
if (by) {
|
|
379
|
+
body.by = by;
|
|
380
|
+
}
|
|
373
381
|
|
|
374
|
-
await yhubFetch(
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
method: "PATCH",
|
|
379
|
-
body: encodeAny(body) as BufferSource,
|
|
380
|
-
},
|
|
381
|
-
);
|
|
382
|
+
await yhubFetch(ydocUrl, headers, {
|
|
383
|
+
method: "PATCH",
|
|
384
|
+
body: encodeAny(body) as BufferSource,
|
|
385
|
+
});
|
|
382
386
|
};
|
|
383
387
|
|
|
384
388
|
/**
|
|
@@ -422,7 +426,7 @@ export function createYHubVersioningEndpoints(
|
|
|
422
426
|
/**
|
|
423
427
|
* Reconstruct the full document state as it was at a given `to` timestamp.
|
|
424
428
|
*
|
|
425
|
-
* The changeset endpoint builds `
|
|
429
|
+
* The changeset endpoint builds `ydoc` purely from the `to` timestamp
|
|
426
430
|
* range — it ignores `withCustomAttributions` for doc reconstruction (that
|
|
427
431
|
* filter only scopes the attribution overlay). So historical document state
|
|
428
432
|
* can only be retrieved by timestamp, never by the version's `id`.
|
|
@@ -436,11 +440,11 @@ export function createYHubVersioningEndpoints(
|
|
|
436
440
|
const buf = await yhubFetch(`${changesetUrl}?${params}`, headers);
|
|
437
441
|
const changeset = decodeAny(new Uint8Array(buf)) as YHubChangeset;
|
|
438
442
|
|
|
439
|
-
if (!changeset.
|
|
443
|
+
if (!changeset.ydoc) {
|
|
440
444
|
throw new Error(`YHub returned no document state at timestamp ${to}.`);
|
|
441
445
|
}
|
|
442
446
|
|
|
443
|
-
return Y.convertUpdateFormatV1ToV2(changeset.
|
|
447
|
+
return Y.convertUpdateFormatV1ToV2(changeset.ydoc);
|
|
444
448
|
};
|
|
445
449
|
|
|
446
450
|
/**
|
|
@@ -504,7 +508,7 @@ export function createYHubVersioningEndpoints(
|
|
|
504
508
|
const to = snapshot.createdAt;
|
|
505
509
|
const snapshotContent = await getContentAt(to);
|
|
506
510
|
|
|
507
|
-
await yhubFetch(
|
|
511
|
+
await yhubFetch(rollbackUrl, headers, {
|
|
508
512
|
method: "POST",
|
|
509
513
|
body: encodeAny({ from: to }) as BufferSource,
|
|
510
514
|
});
|
|
@@ -587,7 +591,9 @@ export function createYHubVersioningEndpoints(
|
|
|
587
591
|
}
|
|
588
592
|
|
|
589
593
|
const buf = await yhubFetch(`${activityUrl}?${params}`, headers);
|
|
590
|
-
const entries = decodeAny(
|
|
594
|
+
const { activity: entries } = decodeAny(
|
|
595
|
+
new Uint8Array(buf),
|
|
596
|
+
) as YHubActivityResponse;
|
|
591
597
|
|
|
592
598
|
const snapshots = sortSnapshotsNewestFirst(
|
|
593
599
|
entries
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
relativePositionToAbsolutePosition,
|
|
6
|
+
ySyncPluginKey,
|
|
7
|
+
} from "y-prosemirror";
|
|
8
|
+
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
|
|
9
|
+
import * as Y from "yjs";
|
|
10
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
11
|
+
import { DefaultThreadStoreAuth } from "../../comments/threadstore/DefaultThreadStoreAuth.js";
|
|
12
|
+
import { withCollaboration } from "../extensions/index.js";
|
|
13
|
+
import { RESTYjsThreadStore } from "./RESTYjsThreadStore.js";
|
|
14
|
+
|
|
15
|
+
function createCollabEditor() {
|
|
16
|
+
const doc = new Y.Doc();
|
|
17
|
+
const fragment = doc.getXmlFragment("doc");
|
|
18
|
+
const editor = BlockNoteEditor.create(
|
|
19
|
+
withCollaboration({
|
|
20
|
+
collaboration: {
|
|
21
|
+
fragment,
|
|
22
|
+
user: { name: "Test User", color: "#FF0000" },
|
|
23
|
+
provider: undefined,
|
|
24
|
+
},
|
|
25
|
+
trailingBlock: false,
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
editor.mount(document.createElement("div"));
|
|
29
|
+
editor.replaceBlocks(editor.document, [
|
|
30
|
+
{ type: "paragraph", content: "Hello World" },
|
|
31
|
+
]);
|
|
32
|
+
return { editor, doc, fragment };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
vi.restoreAllMocks();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("RESTYjsThreadStore", () => {
|
|
40
|
+
it("sends resolvable yjs positions along with the thread", async () => {
|
|
41
|
+
const { editor, doc, fragment } = createCollabEditor();
|
|
42
|
+
|
|
43
|
+
const requests: any[] = [];
|
|
44
|
+
vi.spyOn(globalThis, "fetch").mockImplementation((async (
|
|
45
|
+
_url: any,
|
|
46
|
+
init: any,
|
|
47
|
+
) => {
|
|
48
|
+
requests.push(JSON.parse(init.body));
|
|
49
|
+
return new Response("{}", {
|
|
50
|
+
status: 200,
|
|
51
|
+
headers: { "Content-Type": "application/json" },
|
|
52
|
+
});
|
|
53
|
+
}) as any);
|
|
54
|
+
|
|
55
|
+
const store = new RESTYjsThreadStore(
|
|
56
|
+
"https://example.com/threads",
|
|
57
|
+
{},
|
|
58
|
+
doc.getMap("threads"),
|
|
59
|
+
new DefaultThreadStoreAuth("user-1", "editor"),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
await store.addThreadToDocument({
|
|
63
|
+
threadId: "thread-1",
|
|
64
|
+
selection: { anchor: 3, head: 8 },
|
|
65
|
+
editor,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
expect(requests).toHaveLength(1);
|
|
69
|
+
const { yjs } = requests[0].selection;
|
|
70
|
+
expect(yjs).toBeDefined();
|
|
71
|
+
|
|
72
|
+
// the relative positions must resolve back to the positions we passed in
|
|
73
|
+
const state = ySyncPluginKey.getState(editor.prosemirrorState) as any;
|
|
74
|
+
const resolve = (relPos: any) =>
|
|
75
|
+
relativePositionToAbsolutePosition(
|
|
76
|
+
fragment.doc!,
|
|
77
|
+
state.binding.type,
|
|
78
|
+
Y.createRelativePositionFromJSON(relPos),
|
|
79
|
+
state.binding.mapping,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
expect(resolve(yjs.anchor)).toBe(3);
|
|
83
|
+
expect(resolve(yjs.head)).toBe(8);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -59,7 +59,13 @@ export class RESTYjsThreadStore extends YjsThreadStoreBase {
|
|
|
59
59
|
}) => {
|
|
60
60
|
const { threadId, selection } = options;
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
// Note: the positions have to be resolved against the *binding's* type and
|
|
63
|
+
// mapping. The plugin state has a `type` of its own, but no `mapping`, and
|
|
64
|
+
// its `type` can go stale (e.g. while the doc is forked, see
|
|
65
|
+
// `ForkYDocExtension`).
|
|
66
|
+
const binding = ySyncPluginKey.getState(
|
|
67
|
+
options.editor.prosemirrorState,
|
|
68
|
+
)?.binding;
|
|
63
69
|
const yjsSelection = binding
|
|
64
70
|
? {
|
|
65
71
|
head: absolutePositionToRelativePosition(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it } from "vite-plus/test";
|
|
2
|
+
import { trackPosition } from "../../api/positionMapping.js";
|
|
2
3
|
import * as Y from "yjs";
|
|
3
4
|
import { Awareness } from "y-protocols/awareness";
|
|
4
5
|
import { BlockNoteEditor } from "../../index.js";
|
|
@@ -213,4 +214,40 @@ describe("ForkYDocExtension", () => {
|
|
|
213
214
|
forkYDoc.merge({ keepChanges: true });
|
|
214
215
|
expect(getEditorText(ctx.editor)).toContain("Forked modification");
|
|
215
216
|
});
|
|
217
|
+
|
|
218
|
+
// https://github.com/TypeCellOS/BlockNote/issues/2946
|
|
219
|
+
it("can track positions while forked", () => {
|
|
220
|
+
ctx = createCollabEditor();
|
|
221
|
+
setEditorText(ctx.editor, "Hello World");
|
|
222
|
+
|
|
223
|
+
const forkYDoc = ctx.editor.getExtension(ForkYDocExtension)!;
|
|
224
|
+
forkYDoc.fork();
|
|
225
|
+
|
|
226
|
+
// Store position at "Hello| World"
|
|
227
|
+
const getCursorPos = trackPosition(ctx.editor, 8);
|
|
228
|
+
expect(getCursorPos()).toBe(8);
|
|
229
|
+
|
|
230
|
+
// Insert text at the beginning of "|Hello World"
|
|
231
|
+
ctx.editor._tiptapEditor.commands.insertContentAt(3, "Test ");
|
|
232
|
+
expect(getCursorPos()).toBe(13);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// https://github.com/TypeCellOS/BlockNote/issues/2946
|
|
236
|
+
it("can track positions across fork and merge", () => {
|
|
237
|
+
ctx = createCollabEditor();
|
|
238
|
+
setEditorText(ctx.editor, "Hello World");
|
|
239
|
+
|
|
240
|
+
// Store position at "Hello| World"
|
|
241
|
+
const getCursorPos = trackPosition(ctx.editor, 8);
|
|
242
|
+
|
|
243
|
+
const forkYDoc = ctx.editor.getExtension(ForkYDocExtension)!;
|
|
244
|
+
forkYDoc.fork();
|
|
245
|
+
expect(getCursorPos()).toBe(8);
|
|
246
|
+
|
|
247
|
+
ctx.editor._tiptapEditor.commands.insertContentAt(3, "Test ");
|
|
248
|
+
expect(getCursorPos()).toBe(13);
|
|
249
|
+
|
|
250
|
+
forkYDoc.merge({ keepChanges: true });
|
|
251
|
+
expect(getCursorPos()).toBe(13);
|
|
252
|
+
});
|
|
216
253
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { yUndoPluginKey } from "y-prosemirror";
|
|
1
|
+
import { ySyncPluginKey, yUndoPluginKey } from "y-prosemirror";
|
|
2
2
|
import * as Y from "yjs";
|
|
3
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
3
4
|
import {
|
|
4
5
|
createExtension,
|
|
5
6
|
createStore,
|
|
@@ -11,6 +12,26 @@ import { YSyncExtension } from "./YSync.js";
|
|
|
11
12
|
import { YUndoExtension } from "./YUndo.js";
|
|
12
13
|
import { findTypeInOtherYdoc } from "../utils.js";
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Point the `ySync` plugin state at `fragment`.
|
|
17
|
+
*
|
|
18
|
+
* Swapping the `ySync` plugin reconfigures the ProseMirror state, and
|
|
19
|
+
* ProseMirror carries over the state of plugins that share a key instead of
|
|
20
|
+
* re-initializing them. So the new plugin's `binding` (which is set from its
|
|
21
|
+
* view, via a transaction) ends up on the new fragment, while `type` and `doc`
|
|
22
|
+
* still point at the fragment the editor was bound to before. Anything reading
|
|
23
|
+
* those (e.g. `RelativePositionMappingExtension`) would then mix up the two
|
|
24
|
+
* Y.Docs, so we set them explicitly here.
|
|
25
|
+
*/
|
|
26
|
+
function bindYSyncPluginStateTo(
|
|
27
|
+
editor: BlockNoteEditor<any, any, any>,
|
|
28
|
+
fragment: Y.XmlFragment,
|
|
29
|
+
) {
|
|
30
|
+
editor.transact((tr) =>
|
|
31
|
+
tr.setMeta(ySyncPluginKey, { type: fragment, doc: fragment.doc }),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
14
35
|
export const ForkYDocExtension = createExtension(
|
|
15
36
|
({ editor, options }: ExtensionOptions<CollaborationOptions>) => {
|
|
16
37
|
let forkedState:
|
|
@@ -84,6 +105,8 @@ export const ForkYDocExtension = createExtension(
|
|
|
84
105
|
],
|
|
85
106
|
);
|
|
86
107
|
|
|
108
|
+
bindYSyncPluginStateTo(editor, forkedFragment);
|
|
109
|
+
|
|
87
110
|
// Tell the store that the editor is now forked
|
|
88
111
|
store.setState({ isForked: true });
|
|
89
112
|
},
|
|
@@ -110,6 +133,8 @@ export const ForkYDocExtension = createExtension(
|
|
|
110
133
|
],
|
|
111
134
|
);
|
|
112
135
|
|
|
136
|
+
bindYSyncPluginStateTo(editor, originalFragment);
|
|
137
|
+
|
|
113
138
|
// Reset the undo stack to the original undo stack
|
|
114
139
|
yUndoPluginKey.getState(
|
|
115
140
|
editor.prosemirrorState,
|
|
@@ -51,9 +51,15 @@ export const RelativePositionMappingExtension = createExtension(
|
|
|
51
51
|
const curYSyncPluginState = ySyncPluginKey.getState(
|
|
52
52
|
editor.prosemirrorState,
|
|
53
53
|
) as typeof ySyncPluginState;
|
|
54
|
+
// Resolve against the doc that owns the currently bound type, and not
|
|
55
|
+
// against `curYSyncPluginState.doc`. Those can point at different
|
|
56
|
+
// Y.Docs (e.g. right after forking the doc, see `ForkYDocExtension`),
|
|
57
|
+
// in which case the resolved type wouldn't be part of the bound
|
|
58
|
+
// fragment and the position would be reported as "not found".
|
|
59
|
+
const boundType = curYSyncPluginState.binding.type;
|
|
54
60
|
const pos = relativePositionToAbsolutePosition(
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
boundType.doc,
|
|
62
|
+
boundType,
|
|
57
63
|
relativePosition,
|
|
58
64
|
curYSyncPluginState.binding.mapping,
|
|
59
65
|
);
|
|
@@ -304,15 +304,26 @@ function createInMemoryYjsEndpoints(): VersioningEndpoints<
|
|
|
304
304
|
>();
|
|
305
305
|
const contents = new Map<string, Uint8Array>();
|
|
306
306
|
|
|
307
|
+
// `Date.now()` only has millisecond resolution, so snapshots created in quick
|
|
308
|
+
// succession (as they are in these tests) can share a timestamp, which leaves
|
|
309
|
+
// the newest-first ordering of `list()` ambiguous. Hand out strictly
|
|
310
|
+
// increasing timestamps so creation order is always recoverable.
|
|
311
|
+
let lastTimestamp = 0;
|
|
312
|
+
function nextTimestamp() {
|
|
313
|
+
lastTimestamp = Math.max(Date.now(), lastTimestamp + 1);
|
|
314
|
+
return lastTimestamp;
|
|
315
|
+
}
|
|
316
|
+
|
|
307
317
|
return {
|
|
308
318
|
list: async () =>
|
|
309
319
|
[...snapshots.values()].sort((a, b) => b.createdAt - a.createdAt),
|
|
310
320
|
create: async (fragment, options) => {
|
|
321
|
+
const now = nextTimestamp();
|
|
311
322
|
const snapshot = {
|
|
312
323
|
id: crypto.randomUUID(),
|
|
313
324
|
name: options?.name,
|
|
314
|
-
createdAt:
|
|
315
|
-
updatedAt:
|
|
325
|
+
createdAt: now,
|
|
326
|
+
updatedAt: now,
|
|
316
327
|
restoredFromSnapshotId: options?.restoredFromSnapshot?.id
|
|
317
328
|
? String(options.restoredFromSnapshot.id)
|
|
318
329
|
: undefined,
|
|
@@ -329,11 +340,12 @@ function createInMemoryYjsEndpoints(): VersioningEndpoints<
|
|
|
329
340
|
return data;
|
|
330
341
|
},
|
|
331
342
|
restore: async (fragment, snapshot) => {
|
|
343
|
+
const backupTimestamp = nextTimestamp();
|
|
332
344
|
const backup = {
|
|
333
345
|
id: crypto.randomUUID(),
|
|
334
346
|
name: "Backup",
|
|
335
|
-
createdAt:
|
|
336
|
-
updatedAt:
|
|
347
|
+
createdAt: backupTimestamp,
|
|
348
|
+
updatedAt: backupTimestamp,
|
|
337
349
|
};
|
|
338
350
|
contents.set(backup.id, Y.encodeStateAsUpdate(fragment.doc!));
|
|
339
351
|
snapshots.set(backup.id, backup);
|
|
@@ -347,7 +359,7 @@ function createInMemoryYjsEndpoints(): VersioningEndpoints<
|
|
|
347
359
|
throw new Error(`Snapshot ${String(snapshot.id)} not found`);
|
|
348
360
|
}
|
|
349
361
|
s.name = name;
|
|
350
|
-
s.updatedAt =
|
|
362
|
+
s.updatedAt = nextTimestamp();
|
|
351
363
|
},
|
|
352
364
|
};
|
|
353
365
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Transform } from "prosemirror-transform";
|
|
2
|
+
/**
|
|
3
|
+
* Like ProseMirror's `Transform.changedRange()`, but also accounts for
|
|
4
|
+
* position-preserving steps whose `StepMap` is empty — `AttrStep` (prop-only
|
|
5
|
+
* updates like a heading's `level`) and mark steps. `changedRange()` and tiptap's
|
|
6
|
+
* `getChangedRanges` both miss `AttrStep`, so anything that scopes work to the
|
|
7
|
+
* changed range would silently ignore prop-only updates.
|
|
8
|
+
*
|
|
9
|
+
* O(steps), like `changedRange()`. Returns null when nothing changed.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getChangedRange(transform: Transform): {
|
|
12
|
+
from: number;
|
|
13
|
+
to: number;
|
|
14
|
+
} | null;
|
|
@@ -11,13 +11,13 @@ export declare function getInlineContentSchema<I extends InlineContentSchema>(sc
|
|
|
11
11
|
export declare function getStyleSchema<S extends StyleSchema>(schema: Schema): S;
|
|
12
12
|
export declare function getBlockCache(schema: Schema): import("../index.js").BlockCache<any, any, any>;
|
|
13
13
|
/**
|
|
14
|
-
* Whether `nodeType` is a BlockNote block whose content type
|
|
15
|
-
* it holds unstyled text and only allows the non-formatting
|
|
16
|
-
* marks. Resolved semantically from the block
|
|
17
|
-
* reachable from `schema.cached.blockNoteEditor`.
|
|
14
|
+
* Whether `nodeType` is a BlockNote block or inline content whose content type
|
|
15
|
+
* is `"plain"` — i.e. it holds unstyled text and only allows the non-formatting
|
|
16
|
+
* (`"annotation"`) marks. Resolved semantically from the block / inline content
|
|
17
|
+
* schema (the source of truth), reachable from `schema.cached.blockNoteEditor`.
|
|
18
18
|
*
|
|
19
|
-
* Returns `false` for every
|
|
20
|
-
*
|
|
21
|
-
* keys in
|
|
19
|
+
* Returns `false` for every other node type (`doc`, `blockGroup`, `text`, table
|
|
20
|
+
* sub-nodes, and non-plain blocks / inline content), since those aren't plain
|
|
21
|
+
* content keys in either schema.
|
|
22
22
|
*/
|
|
23
23
|
export declare function isPlainContentNodeType(schema: Schema, nodeType: NodeType): boolean;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
2
|
+
import type { BlockFromConfig } from "../../schema/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Renders a preview of a code block's content (e.g. rendered LaTeX). Takes the
|
|
5
|
+
* same parameters as a block's `render` function and returns the same type,
|
|
6
|
+
* minus `contentDOM` - as a preview never holds the block's editable content.
|
|
7
|
+
*
|
|
8
|
+
* A `renderPreview` function is only responsible for the preview itself. It has
|
|
9
|
+
* no opinion on when, where, or how the preview is displayed - that's up to the
|
|
10
|
+
* code block's `render` function.
|
|
11
|
+
*/
|
|
12
|
+
export type CodeBlockPreview = (block: BlockFromConfig<any, any, any>, editor: BlockNoteEditor<any>) => {
|
|
13
|
+
dom: HTMLElement | DocumentFragment;
|
|
14
|
+
error?: string | null;
|
|
15
|
+
};
|
|
16
|
+
export type CodeBlockOptions = {
|
|
17
|
+
/**
|
|
18
|
+
* Whether to indent lines with a tab when the user presses `Tab` in a code block.
|
|
19
|
+
*
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
indentLineWithTab?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The default language to use for code blocks.
|
|
25
|
+
*
|
|
26
|
+
* @default "text"
|
|
27
|
+
*/
|
|
28
|
+
defaultLanguage?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The languages that are supported in the editor.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* {
|
|
34
|
+
* javascript: {
|
|
35
|
+
* name: "JavaScript",
|
|
36
|
+
* aliases: ["js"],
|
|
37
|
+
* },
|
|
38
|
+
* typescript: {
|
|
39
|
+
* name: "TypeScript",
|
|
40
|
+
* aliases: ["ts"],
|
|
41
|
+
* },
|
|
42
|
+
* }
|
|
43
|
+
*/
|
|
44
|
+
supportedLanguages?: Record<string, {
|
|
45
|
+
/**
|
|
46
|
+
* The display name of the language.
|
|
47
|
+
*/
|
|
48
|
+
name: string;
|
|
49
|
+
/**
|
|
50
|
+
* Aliases for this language.
|
|
51
|
+
*/
|
|
52
|
+
aliases?: string[];
|
|
53
|
+
/**
|
|
54
|
+
* Renders a preview of the result of the code (e.g. rendered LaTeX). When
|
|
55
|
+
* defined, the code block displays this preview instead of the raw source
|
|
56
|
+
* by default, and shows the editable source in a popup when selected.
|
|
57
|
+
*/
|
|
58
|
+
createPreview?: CodeBlockPreview;
|
|
59
|
+
}>;
|
|
60
|
+
};
|
|
61
|
+
export declare function getLanguageId(options: CodeBlockOptions, languageName: string): string | undefined;
|
|
@@ -1,70 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
export type CodeBlockOptions = {
|
|
3
|
-
/**
|
|
4
|
-
* Whether to indent lines with a tab when the user presses `Tab` in a code block.
|
|
5
|
-
*
|
|
6
|
-
* @default true
|
|
7
|
-
*/
|
|
8
|
-
indentLineWithTab?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* The default language to use for code blocks.
|
|
11
|
-
*
|
|
12
|
-
* @default "text"
|
|
13
|
-
*/
|
|
14
|
-
defaultLanguage?: string;
|
|
15
|
-
/**
|
|
16
|
-
* The languages that are supported in the editor.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* {
|
|
20
|
-
* javascript: {
|
|
21
|
-
* name: "JavaScript",
|
|
22
|
-
* aliases: ["js"],
|
|
23
|
-
* },
|
|
24
|
-
* typescript: {
|
|
25
|
-
* name: "TypeScript",
|
|
26
|
-
* aliases: ["ts"],
|
|
27
|
-
* },
|
|
28
|
-
* }
|
|
29
|
-
*/
|
|
30
|
-
supportedLanguages?: Record<string, {
|
|
31
|
-
/**
|
|
32
|
-
* The display name of the language.
|
|
33
|
-
*/
|
|
34
|
-
name: string;
|
|
35
|
-
/**
|
|
36
|
-
* Aliases for this language.
|
|
37
|
-
*/
|
|
38
|
-
aliases?: string[];
|
|
39
|
-
}>;
|
|
40
|
-
/**
|
|
41
|
-
* The highlighter to use for code blocks.
|
|
42
|
-
*/
|
|
43
|
-
createHighlighter?: () => Promise<HighlighterGeneric<any, any>>;
|
|
44
|
-
};
|
|
45
|
-
export type CodeBlockConfig = ReturnType<typeof createCodeBlockConfig>;
|
|
1
|
+
import { CodeBlockOptions } from "./CodeBlockOptions.js";
|
|
46
2
|
export declare const createCodeBlockConfig: (options: CodeBlockOptions) => import("../../index.js").BlockConfig<"codeBlock", {
|
|
47
3
|
readonly language: {
|
|
48
4
|
readonly default: string;
|
|
49
5
|
};
|
|
50
6
|
}, "plain">;
|
|
7
|
+
export type CodeBlockConfig = ReturnType<typeof createCodeBlockConfig>;
|
|
51
8
|
export declare const createCodeBlockSpec: (options?: Partial<{
|
|
52
9
|
indentLineWithTab: boolean;
|
|
53
10
|
defaultLanguage: string;
|
|
54
11
|
supportedLanguages: Record<string, {
|
|
55
|
-
/**
|
|
56
|
-
* The display name of the language.
|
|
57
|
-
*/
|
|
58
12
|
name: string;
|
|
59
|
-
/**
|
|
60
|
-
* Aliases for this language.
|
|
61
|
-
*/
|
|
62
13
|
aliases?: string[];
|
|
14
|
+
createPreview?: import("./CodeBlockOptions.js").CodeBlockPreview;
|
|
63
15
|
}>;
|
|
64
|
-
createHighlighter: () => Promise<HighlighterGeneric<any, any>>;
|
|
65
16
|
}> | undefined) => import("../../index.js").BlockSpec<"codeBlock", {
|
|
66
17
|
readonly language: {
|
|
67
18
|
readonly default: string;
|
|
68
19
|
};
|
|
69
20
|
}, "plain">;
|
|
70
|
-
export declare function getLanguageId(options: CodeBlockOptions, languageName: string): string | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CodeBlockOptions } from "../../CodeBlockOptions.js";
|
|
2
|
+
export declare const CodeKeyboardShortcutsExtension: (options: CodeBlockOptions) => (key: string, blockType: string) => import("../../../../index.js").ExtensionFactoryInstance<{
|
|
3
|
+
readonly key: string;
|
|
4
|
+
readonly keyboardShortcuts: {
|
|
5
|
+
readonly Delete: ({ editor }: {
|
|
6
|
+
editor: import("../../../../index.js").BlockNoteEditor<any, any, any>;
|
|
7
|
+
}) => boolean;
|
|
8
|
+
readonly Tab: ({ editor }: {
|
|
9
|
+
editor: import("../../../../index.js").BlockNoteEditor<any, any, any>;
|
|
10
|
+
}) => boolean;
|
|
11
|
+
readonly Enter: ({ editor }: {
|
|
12
|
+
editor: import("../../../../index.js").BlockNoteEditor<any, any, any>;
|
|
13
|
+
}) => boolean;
|
|
14
|
+
readonly "Shift-Enter": ({ editor }: {
|
|
15
|
+
editor: import("../../../../index.js").BlockNoteEditor<any, any, any>;
|
|
16
|
+
}) => boolean;
|
|
17
|
+
};
|
|
18
|
+
readonly inputRules: readonly [{
|
|
19
|
+
readonly find: RegExp;
|
|
20
|
+
readonly replace: ({ match }: {
|
|
21
|
+
match: RegExpMatchArray;
|
|
22
|
+
range: {
|
|
23
|
+
from: number;
|
|
24
|
+
to: number;
|
|
25
|
+
};
|
|
26
|
+
editor: import("../../../../index.js").BlockNoteEditor<any, any, any>;
|
|
27
|
+
}) => {
|
|
28
|
+
type: string;
|
|
29
|
+
props: {
|
|
30
|
+
language: string;
|
|
31
|
+
};
|
|
32
|
+
content: never[];
|
|
33
|
+
};
|
|
34
|
+
}];
|
|
35
|
+
}>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Schema } from "@tiptap/pm/model";
|
|
2
|
+
export declare const parsePreCode: (el: HTMLElement) => {
|
|
3
|
+
language: string | undefined;
|
|
4
|
+
} | undefined;
|
|
5
|
+
export declare const parsePreCodeContent: ({ el, schema, }: {
|
|
6
|
+
el: HTMLElement;
|
|
7
|
+
schema: Schema;
|
|
8
|
+
}, blockType: string) => import("prosemirror-model").Fragment;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
|
|
2
|
+
import type { BlockFromConfig } from "../../../../schema/index.js";
|
|
3
|
+
export declare const createLanguageSelect: (block: BlockFromConfig<any, any, any>, editor: BlockNoteEditor<any>, selectedLanguage: string, supportedLanguages: Record<string, {
|
|
4
|
+
name: string;
|
|
5
|
+
}>) => {
|
|
6
|
+
dom: HTMLDivElement;
|
|
7
|
+
destroy: () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare const createCodeBlock: (block: BlockFromConfig<any, any, any>, editor: BlockNoteEditor<any>, options?: {
|
|
10
|
+
selectedLanguage: string;
|
|
11
|
+
supportedLanguages: Record<string, {
|
|
12
|
+
name: string;
|
|
13
|
+
}>;
|
|
14
|
+
}) => {
|
|
15
|
+
dom: DocumentFragment;
|
|
16
|
+
contentDOM: HTMLElement;
|
|
17
|
+
destroy: () => void;
|
|
18
|
+
};
|