@blocknote/core 0.54.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/blocknote.cjs +1 -1
- package/dist/blocknote.js +6 -6
- package/dist/{blocks-CzkqclGj.cjs → blocks-CTB_5Vyj.cjs} +4 -4
- package/dist/blocks-CTB_5Vyj.cjs.map +1 -0
- package/dist/{blocks-CzQLehlc.js → blocks-Dol85hpH.js} +337 -330
- package/dist/blocks-Dol85hpH.js.map +1 -0
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/extensions-B7Rsp_Ft.cjs +58 -0
- package/dist/extensions-B7Rsp_Ft.cjs.map +1 -0
- package/dist/{extensions-DGuhtOgB.js → extensions-D6JcJCwd.js} +389 -346
- package/dist/extensions-D6JcJCwd.js.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +3 -3
- package/dist/{src-BkfZVfaO.js → src-Buuo5l7X.js} +521 -516
- package/dist/{src-BkfZVfaO.js.map → src-Buuo5l7X.js.map} +1 -1
- package/dist/{src-DM3syMdf.cjs → src-C54Ok9E0.cjs} +10 -10
- package/dist/{src-DM3syMdf.cjs.map → src-C54Ok9E0.cjs.map} +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 +205 -205
- package/dist/y.js.map +1 -1
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.js +21 -21
- package/package.json +1 -1
- package/src/api/getBlocksChangedByTransaction.test.ts +211 -0
- package/src/api/getBlocksChangedByTransaction.ts +48 -12
- package/src/api/getChangedRange.ts +54 -0
- package/src/blocks/index.ts +0 -1
- package/src/editor/performance.test.ts +45 -0
- package/src/exporter/Exporter.test.ts +148 -10
- package/src/exporter/Exporter.ts +20 -2
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +21 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +5 -3
- package/src/extensions/TableHandles/TableHandles.browser.test.ts +305 -0
- package/src/extensions/TableHandles/TableHandles.ts +82 -41
- package/src/fonts/inter.css +9 -9
- package/src/schema/blocks/createSpec.ts +4 -5
- package/src/schema/inlineContent/createSpec.ts +4 -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/y/extensions/AttributionExtension.test.ts +8 -9
- package/src/y/versioning/__test__/yhub.test.ts +92 -59
- package/src/y/versioning/yhub.ts +35 -29
- package/types/src/api/getChangedRange.d.ts +14 -0
- package/types/src/blocks/index.d.ts +0 -1
- package/types/src/exporter/Exporter.d.ts +9 -0
- package/types/src/extensions/TableHandles/TableHandles.browser.test.d.ts +1 -0
- package/types/src/extensions/TableHandles/TableHandles.d.ts +3 -0
- package/types/src/schema/nodeViewMutations.d.ts +2 -2
- package/types/src/schema/schema.test.d.ts +1 -0
- package/types/src/y/versioning/yhub.d.ts +3 -2
- package/dist/blocks-CzQLehlc.js.map +0 -1
- package/dist/blocks-CzkqclGj.cjs.map +0 -1
- package/dist/extensions-CSB9ZvuL.cjs +0 -58
- package/dist/extensions-CSB9ZvuL.cjs.map +0 -1
- package/dist/extensions-DGuhtOgB.js.map +0 -1
- package/src/blocks/File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -20
- package/types/src/blocks/File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -6
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { afterEach, describe, expect, it } from "vite-plus/test";
|
|
5
|
+
|
|
6
|
+
import { BlockNoteSchema } from "../blocks/BlockNoteSchema.js";
|
|
7
|
+
import {
|
|
8
|
+
defaultBlockSpecs,
|
|
9
|
+
defaultInlineContentSpecs,
|
|
10
|
+
defaultStyleSpecs,
|
|
11
|
+
} from "../blocks/defaultBlocks.js";
|
|
12
|
+
import { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
13
|
+
import { createExtension } from "../editor/BlockNoteExtension.js";
|
|
14
|
+
import { createBlockSpec } from "./blocks/createSpec.js";
|
|
15
|
+
import { createInlineContentSpec } from "./inlineContent/createSpec.js";
|
|
16
|
+
import { createStyleSpec } from "./styles/createSpec.js";
|
|
17
|
+
|
|
18
|
+
const editorsToCleanup: BlockNoteEditor<any, any, any>[] = [];
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
for (const editor of editorsToCleanup) {
|
|
22
|
+
editor.unmount();
|
|
23
|
+
}
|
|
24
|
+
editorsToCleanup.length = 0;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function createMountedEditor(
|
|
28
|
+
options: Parameters<typeof BlockNoteEditor.create>[0],
|
|
29
|
+
) {
|
|
30
|
+
const editor = BlockNoteEditor.create(options);
|
|
31
|
+
editor.mount(document.createElement("div"));
|
|
32
|
+
editorsToCleanup.push(editor);
|
|
33
|
+
return editor;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// A block spec that registers an editor extension, like
|
|
37
|
+
// `@blocknote/xl-multi-column`'s `ColumnBlock` does with its drop handler.
|
|
38
|
+
const CustomBlockExtension = createExtension(() => ({
|
|
39
|
+
key: "customBlockExtension",
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
const createCustomBlockSpec = createBlockSpec(
|
|
43
|
+
{ type: "customBlock", propSchema: {}, content: "none" },
|
|
44
|
+
{ render: () => ({ dom: document.createElement("div") }) },
|
|
45
|
+
[CustomBlockExtension()],
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const customInlineContent = createInlineContentSpec(
|
|
49
|
+
{ type: "customInlineContent", propSchema: {}, content: "none" },
|
|
50
|
+
{ render: () => ({ dom: document.createElement("span") }) },
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const customStyle = createStyleSpec(
|
|
54
|
+
{ type: "customStyle", propSchema: "boolean" },
|
|
55
|
+
{ render: () => ({ dom: document.createElement("span") }) },
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
describe("CustomBlockNoteSchema.extend", () => {
|
|
59
|
+
it("does not mutate the default specs shared by every default schema", () => {
|
|
60
|
+
const extended = BlockNoteSchema.create().extend({
|
|
61
|
+
blockSpecs: { customBlock: createCustomBlockSpec() },
|
|
62
|
+
inlineContentSpecs: { customInlineContent },
|
|
63
|
+
styleSpecs: { customStyle },
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// The extended schema has the added specs...
|
|
67
|
+
expect(extended.blockSchema).toHaveProperty("customBlock");
|
|
68
|
+
expect(extended.inlineContentSchema).toHaveProperty("customInlineContent");
|
|
69
|
+
expect(extended.styleSchema).toHaveProperty("customStyle");
|
|
70
|
+
|
|
71
|
+
// ...the module-level defaults it was created from are untouched...
|
|
72
|
+
expect(defaultBlockSpecs).not.toHaveProperty("customBlock");
|
|
73
|
+
expect(defaultInlineContentSpecs).not.toHaveProperty("customInlineContent");
|
|
74
|
+
expect(defaultStyleSpecs).not.toHaveProperty("customStyle");
|
|
75
|
+
|
|
76
|
+
// ...so a default schema created afterwards doesn't inherit them.
|
|
77
|
+
const fresh = BlockNoteSchema.create();
|
|
78
|
+
expect(fresh.blockSchema).not.toHaveProperty("customBlock");
|
|
79
|
+
expect(fresh.inlineContentSchema).not.toHaveProperty("customInlineContent");
|
|
80
|
+
expect(fresh.styleSchema).not.toHaveProperty("customStyle");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("does not mutate the spec objects passed to `create`", () => {
|
|
84
|
+
const blockSpecs = { paragraph: defaultBlockSpecs.paragraph };
|
|
85
|
+
|
|
86
|
+
BlockNoteSchema.create({ blockSpecs }).extend({
|
|
87
|
+
blockSpecs: { customBlock: createCustomBlockSpec() },
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(Object.keys(blockSpecs)).toEqual(["paragraph"]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("keeps an extended schema's blocks and their extensions out of later default-schema editors", () => {
|
|
94
|
+
// Regression: extending a default schema used to write the added block
|
|
95
|
+
// specs into the shared default specs, so every editor created afterwards
|
|
96
|
+
// without an explicit schema silently got the extra block types - and the
|
|
97
|
+
// editor extensions they register (e.g. multi-column's drop handler).
|
|
98
|
+
const extendedEditor = createMountedEditor({
|
|
99
|
+
schema: BlockNoteSchema.create().extend({
|
|
100
|
+
blockSpecs: { customBlock: createCustomBlockSpec() },
|
|
101
|
+
}),
|
|
102
|
+
});
|
|
103
|
+
expect(extendedEditor.getExtension(CustomBlockExtension)).toBeDefined();
|
|
104
|
+
|
|
105
|
+
const defaultEditor = createMountedEditor({});
|
|
106
|
+
expect(defaultEditor.schema.blockSchema).not.toHaveProperty("customBlock");
|
|
107
|
+
expect(defaultEditor.pmSchema.nodes).not.toHaveProperty("customBlock");
|
|
108
|
+
expect(defaultEditor.getExtension(CustomBlockExtension)).toBeUndefined();
|
|
109
|
+
});
|
|
110
|
+
});
|
package/src/schema/schema.ts
CHANGED
|
@@ -201,10 +201,19 @@ export class CustomBlockNoteSchema<
|
|
|
201
201
|
[K in keyof AdditionalStyleSpecs]: AdditionalStyleSpecs[K]["config"];
|
|
202
202
|
}
|
|
203
203
|
> {
|
|
204
|
-
// Merge the new specs with existing ones
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
204
|
+
// Merge the new specs with the existing ones into fresh objects. The
|
|
205
|
+
// existing spec objects must not be written to: `BlockNoteSchema.create()`
|
|
206
|
+
// passes the module-level default specs by reference, so mutating them
|
|
207
|
+
// would leak the added specs (and the editor extensions they register) into
|
|
208
|
+
// every default-schema editor created afterwards.
|
|
209
|
+
this.opts = {
|
|
210
|
+
blockSpecs: { ...this.opts.blockSpecs, ...opts.blockSpecs },
|
|
211
|
+
inlineContentSpecs: {
|
|
212
|
+
...this.opts.inlineContentSpecs,
|
|
213
|
+
...opts.inlineContentSpecs,
|
|
214
|
+
},
|
|
215
|
+
styleSpecs: { ...this.opts.styleSpecs, ...opts.styleSpecs },
|
|
216
|
+
};
|
|
208
217
|
|
|
209
218
|
// Reinitialize the block specs with the merged specs
|
|
210
219
|
const {
|
|
@@ -17,15 +17,14 @@ const editors: BlockNoteEditor[] = [];
|
|
|
17
17
|
// No Yjs/collaboration needed — the extension's load plugin only cares that a
|
|
18
18
|
// transaction adds a `y-attributed-*` mark, which we do directly below.
|
|
19
19
|
function createEditor() {
|
|
20
|
-
const resolveUsers = vi.fn(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})),
|
|
20
|
+
const resolveUsers = vi.fn(async (ids: string[]): Promise<User[]> =>
|
|
21
|
+
ids.map((id) => ({
|
|
22
|
+
id,
|
|
23
|
+
username: `name-${id}`,
|
|
24
|
+
avatarUrl: "",
|
|
25
|
+
color: "#123456",
|
|
26
|
+
colorLight: "#abcdef",
|
|
27
|
+
})),
|
|
29
28
|
);
|
|
30
29
|
|
|
31
30
|
const editor = BlockNoteEditor.create({
|
|
@@ -66,15 +66,12 @@ const SNAPSHOT_2: VersionSnapshot = {
|
|
|
66
66
|
|
|
67
67
|
const PATCH_RESPONSE = { success: true, message: "Document updated" };
|
|
68
68
|
|
|
69
|
-
function makeChangeset(
|
|
70
|
-
opts: { nextDoc?: boolean; attributions?: boolean } = {},
|
|
71
|
-
) {
|
|
69
|
+
function makeChangeset(opts: { ydoc?: boolean; attributions?: boolean } = {}) {
|
|
72
70
|
const doc = new Y.Doc();
|
|
73
71
|
const frag = doc.get("default", "XmlFragment");
|
|
74
72
|
frag.insert(0, ["hello"]);
|
|
75
73
|
return {
|
|
76
|
-
|
|
77
|
-
...(opts.nextDoc !== false ? { nextDoc: Y.encodeStateAsUpdate(doc) } : {}),
|
|
74
|
+
...(opts.ydoc !== false ? { ydoc: Y.encodeStateAsUpdate(doc) } : {}),
|
|
78
75
|
...(opts.attributions ? { attributions: new Uint8Array([0]) } : {}),
|
|
79
76
|
};
|
|
80
77
|
}
|
|
@@ -83,7 +80,7 @@ function makeChangeset(
|
|
|
83
80
|
// Helpers
|
|
84
81
|
// ---------------------------------------------------------------------------
|
|
85
82
|
|
|
86
|
-
const BASE_URL = "https://yhub.test";
|
|
83
|
+
const BASE_URL = "https://yhub.test/api";
|
|
87
84
|
const ORG = "test-org";
|
|
88
85
|
const DOC_ID = "test-doc";
|
|
89
86
|
|
|
@@ -162,13 +159,17 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
162
159
|
describe("list", () => {
|
|
163
160
|
it("returns version-tagged entries using the id attribution as snapshot id", async () => {
|
|
164
161
|
fetchSpy.mockResolvedValueOnce(
|
|
165
|
-
mockFetchResponse([VERSION_ENTRY_2, VERSION_ENTRY_1]),
|
|
162
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_2, VERSION_ENTRY_1] }),
|
|
166
163
|
);
|
|
167
164
|
// Current-version probe: latest edit of any kind, then latest version
|
|
168
165
|
// marker. Both are VERSION_ENTRY_2, so latest edit == latest marker → no
|
|
169
166
|
// synthetic "current version" entry.
|
|
170
|
-
fetchSpy.mockResolvedValueOnce(
|
|
171
|
-
|
|
167
|
+
fetchSpy.mockResolvedValueOnce(
|
|
168
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_2] }),
|
|
169
|
+
);
|
|
170
|
+
fetchSpy.mockResolvedValueOnce(
|
|
171
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_2] }),
|
|
172
|
+
);
|
|
172
173
|
|
|
173
174
|
const endpoints = makeEndpoints();
|
|
174
175
|
const snapshots = await endpoints.list();
|
|
@@ -188,16 +189,16 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
188
189
|
it("fetches the full activity timeline (no type:version filter) with grouping defaults", async () => {
|
|
189
190
|
// 1: full activity timeline. 2: latest edit of any kind. 3: latest
|
|
190
191
|
// version marker (the current-version probe makes both 2 & 3).
|
|
191
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
192
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
193
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
192
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
193
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
194
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
194
195
|
|
|
195
196
|
const endpoints = makeEndpoints();
|
|
196
197
|
await endpoints.list();
|
|
197
198
|
|
|
198
199
|
expect(fetchSpy).toHaveBeenCalledTimes(3);
|
|
199
200
|
const versionUrl = new URL(fetchSpy.mock.calls[0][0] as string);
|
|
200
|
-
expect(versionUrl.pathname).toBe(`/activity/${ORG}/${DOC_ID}`);
|
|
201
|
+
expect(versionUrl.pathname).toBe(`/api/activity/v1/${ORG}/${DOC_ID}`);
|
|
201
202
|
// The `type:version` overlay filter is dropped so history entries are
|
|
202
203
|
// returned too.
|
|
203
204
|
expect(versionUrl.searchParams.get("withCustomAttributions")).toBe(null);
|
|
@@ -207,14 +208,14 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
207
208
|
|
|
208
209
|
// Probe A: the latest entry of *any* type (no marker filter).
|
|
209
210
|
const latestUrl = new URL(fetchSpy.mock.calls[1][0] as string);
|
|
210
|
-
expect(latestUrl.pathname).toBe(`/activity/${ORG}/${DOC_ID}`);
|
|
211
|
+
expect(latestUrl.pathname).toBe(`/api/activity/v1/${ORG}/${DOC_ID}`);
|
|
211
212
|
expect(latestUrl.searchParams.get("limit")).toBe("1");
|
|
212
213
|
expect(latestUrl.searchParams.has("withCustomAttributions")).toBe(false);
|
|
213
214
|
|
|
214
215
|
// Probe B: the latest *version marker*, server-filtered to `type:version`
|
|
215
216
|
// so grouping/mergeUsers can't conflate it with a later edit.
|
|
216
217
|
const markerUrl = new URL(fetchSpy.mock.calls[2][0] as string);
|
|
217
|
-
expect(markerUrl.pathname).toBe(`/activity/${ORG}/${DOC_ID}`);
|
|
218
|
+
expect(markerUrl.pathname).toBe(`/api/activity/v1/${ORG}/${DOC_ID}`);
|
|
218
219
|
expect(markerUrl.searchParams.get("limit")).toBe("1");
|
|
219
220
|
expect(markerUrl.searchParams.get("withCustomAttributions")).toBe(
|
|
220
221
|
"type:version",
|
|
@@ -222,9 +223,9 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
222
223
|
});
|
|
223
224
|
|
|
224
225
|
it("forwards group + groupMaxDuration params when configured", async () => {
|
|
225
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
226
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
227
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
226
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
227
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
228
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
228
229
|
|
|
229
230
|
const endpoints = createYHubVersioningEndpoints({
|
|
230
231
|
baseUrl: BASE_URL,
|
|
@@ -242,9 +243,9 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
242
243
|
});
|
|
243
244
|
|
|
244
245
|
it("omits group params by default while keeping the groupMaxGap default", async () => {
|
|
245
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
246
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
247
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
246
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
247
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
248
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
248
249
|
|
|
249
250
|
// `makeEndpoints` builds the factory with no group/groupMaxDuration opts.
|
|
250
251
|
const endpoints = makeEndpoints();
|
|
@@ -275,12 +276,16 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
275
276
|
by: "user-2",
|
|
276
277
|
};
|
|
277
278
|
fetchSpy.mockResolvedValueOnce(
|
|
278
|
-
mockFetchResponse([namedEntry, historyEntry]),
|
|
279
|
+
mockFetchResponse({ activity: [namedEntry, historyEntry] }),
|
|
279
280
|
);
|
|
280
281
|
// Current-version probe: latest edit == latest marker == `namedEntry`, so
|
|
281
282
|
// no synthetic current row.
|
|
282
|
-
fetchSpy.mockResolvedValueOnce(
|
|
283
|
-
|
|
283
|
+
fetchSpy.mockResolvedValueOnce(
|
|
284
|
+
mockFetchResponse({ activity: [namedEntry] }),
|
|
285
|
+
);
|
|
286
|
+
fetchSpy.mockResolvedValueOnce(
|
|
287
|
+
mockFetchResponse({ activity: [namedEntry] }),
|
|
288
|
+
);
|
|
284
289
|
|
|
285
290
|
const endpoints = makeEndpoints();
|
|
286
291
|
const snapshots = await endpoints.list();
|
|
@@ -297,9 +302,9 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
297
302
|
});
|
|
298
303
|
|
|
299
304
|
it("returns empty array when no versions exist", async () => {
|
|
300
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
301
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
302
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
305
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
306
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
307
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
303
308
|
|
|
304
309
|
const endpoints = makeEndpoints();
|
|
305
310
|
const snapshots = await endpoints.list();
|
|
@@ -309,10 +314,14 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
309
314
|
|
|
310
315
|
it("sorts snapshots newest-first", async () => {
|
|
311
316
|
fetchSpy.mockResolvedValueOnce(
|
|
312
|
-
mockFetchResponse([VERSION_ENTRY_1, VERSION_ENTRY_2]),
|
|
317
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_1, VERSION_ENTRY_2] }),
|
|
318
|
+
);
|
|
319
|
+
fetchSpy.mockResolvedValueOnce(
|
|
320
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_2] }),
|
|
321
|
+
);
|
|
322
|
+
fetchSpy.mockResolvedValueOnce(
|
|
323
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_2] }),
|
|
313
324
|
);
|
|
314
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_2]));
|
|
315
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_2]));
|
|
316
325
|
|
|
317
326
|
const endpoints = makeEndpoints();
|
|
318
327
|
const snapshots = await endpoints.list();
|
|
@@ -328,10 +337,14 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
328
337
|
customAttributions: [{ k: "type", v: "version" }],
|
|
329
338
|
};
|
|
330
339
|
fetchSpy.mockResolvedValueOnce(
|
|
331
|
-
mockFetchResponse([VERSION_ENTRY_1, noIdEntry]),
|
|
340
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_1, noIdEntry] }),
|
|
341
|
+
);
|
|
342
|
+
fetchSpy.mockResolvedValueOnce(
|
|
343
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_1] }),
|
|
344
|
+
);
|
|
345
|
+
fetchSpy.mockResolvedValueOnce(
|
|
346
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_1] }),
|
|
332
347
|
);
|
|
333
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_1]));
|
|
334
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_1]));
|
|
335
348
|
|
|
336
349
|
const endpoints = makeEndpoints();
|
|
337
350
|
const snapshots = await endpoints.list();
|
|
@@ -361,9 +374,15 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
361
374
|
};
|
|
362
375
|
// 1: activity fetch. 2 & 3: current-version probe (latest edit, latest
|
|
363
376
|
// marker) — same entry both times, so no newer edit and no current row.
|
|
364
|
-
fetchSpy.mockResolvedValueOnce(
|
|
365
|
-
|
|
366
|
-
|
|
377
|
+
fetchSpy.mockResolvedValueOnce(
|
|
378
|
+
mockFetchResponse({ activity: [versionEntry] }),
|
|
379
|
+
);
|
|
380
|
+
fetchSpy.mockResolvedValueOnce(
|
|
381
|
+
mockFetchResponse({ activity: [versionEntry] }),
|
|
382
|
+
);
|
|
383
|
+
fetchSpy.mockResolvedValueOnce(
|
|
384
|
+
mockFetchResponse({ activity: [versionEntry] }),
|
|
385
|
+
);
|
|
367
386
|
|
|
368
387
|
const snapshots = await endpoints.list();
|
|
369
388
|
|
|
@@ -373,9 +392,15 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
373
392
|
});
|
|
374
393
|
|
|
375
394
|
it("falls back to the attribution name when the store has no entry", async () => {
|
|
376
|
-
fetchSpy.mockResolvedValueOnce(
|
|
377
|
-
|
|
378
|
-
|
|
395
|
+
fetchSpy.mockResolvedValueOnce(
|
|
396
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_1] }),
|
|
397
|
+
);
|
|
398
|
+
fetchSpy.mockResolvedValueOnce(
|
|
399
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_1] }),
|
|
400
|
+
);
|
|
401
|
+
fetchSpy.mockResolvedValueOnce(
|
|
402
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_1] }),
|
|
403
|
+
);
|
|
379
404
|
|
|
380
405
|
const endpoints = makeEndpoints();
|
|
381
406
|
const snapshots = await endpoints.list();
|
|
@@ -395,10 +420,14 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
395
420
|
// version marker (VERSION_ENTRY_2). Since latestEdit.to > VERSION_ENTRY_2.to
|
|
396
421
|
// a synthetic current-version row is prepended.
|
|
397
422
|
fetchSpy.mockResolvedValueOnce(
|
|
398
|
-
mockFetchResponse([VERSION_ENTRY_2, VERSION_ENTRY_1]),
|
|
423
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_2, VERSION_ENTRY_1] }),
|
|
424
|
+
);
|
|
425
|
+
fetchSpy.mockResolvedValueOnce(
|
|
426
|
+
mockFetchResponse({ activity: [latestEdit] }),
|
|
427
|
+
);
|
|
428
|
+
fetchSpy.mockResolvedValueOnce(
|
|
429
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_2] }),
|
|
399
430
|
);
|
|
400
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([latestEdit]));
|
|
401
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_2]));
|
|
402
431
|
|
|
403
432
|
const endpoints = makeEndpoints();
|
|
404
433
|
const snapshots = await endpoints.list();
|
|
@@ -427,12 +456,18 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
427
456
|
};
|
|
428
457
|
// 1: activity list — newest entry is the history edit, not a marker.
|
|
429
458
|
fetchSpy.mockResolvedValueOnce(
|
|
430
|
-
mockFetchResponse(
|
|
459
|
+
mockFetchResponse({
|
|
460
|
+
activity: [historyEdit, VERSION_ENTRY_2, VERSION_ENTRY_1],
|
|
461
|
+
}),
|
|
431
462
|
);
|
|
432
463
|
// 2: latest edit of any kind → the history edit.
|
|
433
|
-
fetchSpy.mockResolvedValueOnce(
|
|
464
|
+
fetchSpy.mockResolvedValueOnce(
|
|
465
|
+
mockFetchResponse({ activity: [historyEdit] }),
|
|
466
|
+
);
|
|
434
467
|
// 3: latest version marker → VERSION_ENTRY_2 (older than the edit).
|
|
435
|
-
fetchSpy.mockResolvedValueOnce(
|
|
468
|
+
fetchSpy.mockResolvedValueOnce(
|
|
469
|
+
mockFetchResponse({ activity: [VERSION_ENTRY_2] }),
|
|
470
|
+
);
|
|
436
471
|
|
|
437
472
|
const endpoints = makeEndpoints();
|
|
438
473
|
const snapshots = await endpoints.list();
|
|
@@ -443,9 +478,9 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
443
478
|
});
|
|
444
479
|
|
|
445
480
|
it("forwards the mergeUsers param when configured", async () => {
|
|
446
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
447
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
448
|
-
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
481
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
482
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
483
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ activity: [] }));
|
|
449
484
|
|
|
450
485
|
const endpoints = createYHubVersioningEndpoints({
|
|
451
486
|
baseUrl: BASE_URL,
|
|
@@ -475,7 +510,7 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
475
510
|
// Only one fetch call (PATCH) — no activity fetch
|
|
476
511
|
expect(fetchSpy).toHaveBeenCalledOnce();
|
|
477
512
|
const [patchUrl, patchInit] = fetchSpy.mock.calls[0];
|
|
478
|
-
expect(patchUrl).toBe(`${BASE_URL}/ydoc/${ORG}/${DOC_ID}`);
|
|
513
|
+
expect(patchUrl).toBe(`${BASE_URL}/ydoc/v1/${ORG}/${DOC_ID}`);
|
|
479
514
|
expect(patchInit.method).toBe("PATCH");
|
|
480
515
|
expect(patchInit.body).toBeInstanceOf(Uint8Array);
|
|
481
516
|
|
|
@@ -510,9 +545,9 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
510
545
|
});
|
|
511
546
|
|
|
512
547
|
expect(snapshot.by).toBe("user-1");
|
|
513
|
-
// The PATCH is attributed to the same user.
|
|
548
|
+
// The PATCH is attributed to the same user via the body, not query params.
|
|
514
549
|
const patchUrl = new URL(fetchSpy.mock.calls[0][0] as string);
|
|
515
|
-
expect(patchUrl.searchParams.
|
|
550
|
+
expect(patchUrl.searchParams.has("userid")).toBe(false);
|
|
516
551
|
});
|
|
517
552
|
|
|
518
553
|
it("creates a version without a name", async () => {
|
|
@@ -587,17 +622,15 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
587
622
|
|
|
588
623
|
// changeset reconstructed by timestamp, NOT by custom attribution
|
|
589
624
|
const url = new URL(fetchSpy.mock.calls[0][0] as string);
|
|
590
|
-
expect(url.pathname).toBe(`/changeset/${ORG}/${DOC_ID}`);
|
|
625
|
+
expect(url.pathname).toBe(`/api/changeset/v1/${ORG}/${DOC_ID}`);
|
|
591
626
|
expect(url.searchParams.get("ydoc")).toBe("true");
|
|
592
627
|
expect(url.searchParams.get("to")).toBe(String(SNAPSHOT_1.createdAt));
|
|
593
628
|
expect(url.searchParams.has("from")).toBe(false);
|
|
594
629
|
expect(url.searchParams.has("withCustomAttributions")).toBe(false);
|
|
595
630
|
});
|
|
596
631
|
|
|
597
|
-
it("throws when changeset has no
|
|
598
|
-
fetchSpy.mockResolvedValueOnce(
|
|
599
|
-
mockFetchResponse({ prevDoc: new Uint8Array() }),
|
|
600
|
-
);
|
|
632
|
+
it("throws when changeset has no ydoc", async () => {
|
|
633
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({}));
|
|
601
634
|
|
|
602
635
|
const endpoints = makeEndpoints();
|
|
603
636
|
await expect(endpoints.getContent(SNAPSHOT_1)).rejects.toThrow(
|
|
@@ -653,7 +686,7 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
653
686
|
|
|
654
687
|
// changeset without attributions
|
|
655
688
|
fetchSpy.mockResolvedValueOnce(
|
|
656
|
-
mockFetchResponse({
|
|
689
|
+
mockFetchResponse({ ydoc: new Uint8Array() }),
|
|
657
690
|
);
|
|
658
691
|
|
|
659
692
|
await expect(endpoints.getAttributions!(SNAPSHOT_1)).rejects.toThrow(
|
|
@@ -682,12 +715,12 @@ describe("createYHubVersioningEndpoints", () => {
|
|
|
682
715
|
|
|
683
716
|
// 1st call: GET changeset by timestamp
|
|
684
717
|
const csUrl = new URL(fetchSpy.mock.calls[0][0] as string);
|
|
685
|
-
expect(csUrl.pathname).toBe(`/changeset/${ORG}/${DOC_ID}`);
|
|
718
|
+
expect(csUrl.pathname).toBe(`/api/changeset/v1/${ORG}/${DOC_ID}`);
|
|
686
719
|
expect(csUrl.searchParams.get("to")).toBe(String(SNAPSHOT_1.createdAt));
|
|
687
720
|
|
|
688
721
|
// 2nd call: POST rollback
|
|
689
722
|
const [rollbackUrl, rollbackInit] = fetchSpy.mock.calls[1];
|
|
690
|
-
expect(rollbackUrl).
|
|
723
|
+
expect(rollbackUrl).toBe(`${BASE_URL}/rollback/v1/${ORG}/${DOC_ID}`);
|
|
691
724
|
expect(rollbackInit.method).toBe("POST");
|
|
692
725
|
|
|
693
726
|
expect(content).toBeInstanceOf(Uint8Array);
|
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,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;
|
|
@@ -19,7 +19,6 @@ export * from "./Code/helpers/parse/parsePreCode.js";
|
|
|
19
19
|
export * from "./Code/helpers/render/createCodeBlock.js";
|
|
20
20
|
export * from "./Code/helpers/toExternalHTML/createPreCode.js";
|
|
21
21
|
export * from "./ToggleWrapper/createToggleWrapper.js";
|
|
22
|
-
export * from "./File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.js";
|
|
23
22
|
export * from "./PageBreak/getPageBreakSlashMenuItems.js";
|
|
24
23
|
export * from "./BlockNoteSchema.js";
|
|
25
24
|
export * from "./defaultBlockHelpers.js";
|