@blocknote/xl-multi-column 0.19.0

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 (78) hide show
  1. package/LICENSE +661 -0
  2. package/dist/blocknote-xl-multi-column.js +3038 -0
  3. package/dist/blocknote-xl-multi-column.js.map +1 -0
  4. package/dist/blocknote-xl-multi-column.umd.cjs +69 -0
  5. package/dist/blocknote-xl-multi-column.umd.cjs.map +1 -0
  6. package/dist/webpack-stats.json +1 -0
  7. package/package.json +80 -0
  8. package/src/blocks/Columns/index.ts +15 -0
  9. package/src/blocks/schema.ts +43 -0
  10. package/src/extensions/ColumnResize/ColumnResizeExtension.ts +357 -0
  11. package/src/extensions/DropCursor/MultiColumnDropCursorPlugin.ts +480 -0
  12. package/src/extensions/SuggestionMenu/getMultiColumnSlashMenuItems.tsx +105 -0
  13. package/src/i18n/dictionary.ts +27 -0
  14. package/src/i18n/locales/ar.ts +18 -0
  15. package/src/i18n/locales/de.ts +18 -0
  16. package/src/i18n/locales/en.ts +16 -0
  17. package/src/i18n/locales/es.ts +18 -0
  18. package/src/i18n/locales/fr.ts +18 -0
  19. package/src/i18n/locales/hr.ts +18 -0
  20. package/src/i18n/locales/index.ts +15 -0
  21. package/src/i18n/locales/is.ts +18 -0
  22. package/src/i18n/locales/ja.ts +18 -0
  23. package/src/i18n/locales/ko.ts +18 -0
  24. package/src/i18n/locales/nl.ts +18 -0
  25. package/src/i18n/locales/pl.ts +18 -0
  26. package/src/i18n/locales/pt.ts +18 -0
  27. package/src/i18n/locales/ru.ts +18 -0
  28. package/src/i18n/locales/vi.ts +18 -0
  29. package/src/i18n/locales/zh.ts +18 -0
  30. package/src/index.ts +7 -0
  31. package/src/pm-nodes/Column.ts +87 -0
  32. package/src/pm-nodes/ColumnList.ts +44 -0
  33. package/src/test/commands/__snapshots__/insertBlocks.test.ts.snap +757 -0
  34. package/src/test/commands/__snapshots__/textCursorPosition.test.ts.snap +169 -0
  35. package/src/test/commands/__snapshots__/updateBlock.test.ts.snap +964 -0
  36. package/src/test/commands/insertBlocks.test.ts +206 -0
  37. package/src/test/commands/textCursorPosition.test.ts +19 -0
  38. package/src/test/commands/updateBlock.test.ts +212 -0
  39. package/src/test/conversions/__snapshots__/multi-column/undefined/external.html +1 -0
  40. package/src/test/conversions/__snapshots__/multi-column/undefined/internal.html +1 -0
  41. package/src/test/conversions/__snapshots__/nodeConversion.test.ts.snap +118 -0
  42. package/src/test/conversions/htmlConversion.test.ts +100 -0
  43. package/src/test/conversions/nodeConversion.test.ts +84 -0
  44. package/src/test/conversions/testCases.ts +54 -0
  45. package/src/test/setupTestEnv.ts +99 -0
  46. package/src/vite-env.d.ts +1 -0
  47. package/types/src/blocks/Columns/index.d.ts +32 -0
  48. package/types/src/blocks/schema.d.ts +102 -0
  49. package/types/src/extensions/ColumnResize/ColumnResizeExtension.d.ts +3 -0
  50. package/types/src/extensions/DropCursor/MultiColumnDropCursorPlugin.d.ts +11 -0
  51. package/types/src/extensions/SuggestionMenu/getMultiColumnSlashMenuItems.d.ts +5 -0
  52. package/types/src/i18n/dictionary.d.ts +19 -0
  53. package/types/src/i18n/locales/ar.d.ts +2 -0
  54. package/types/src/i18n/locales/de.d.ts +2 -0
  55. package/types/src/i18n/locales/en.d.ts +16 -0
  56. package/types/src/i18n/locales/es.d.ts +2 -0
  57. package/types/src/i18n/locales/fr.d.ts +2 -0
  58. package/types/src/i18n/locales/hr.d.ts +2 -0
  59. package/types/src/i18n/locales/index.d.ts +15 -0
  60. package/types/src/i18n/locales/is.d.ts +2 -0
  61. package/types/src/i18n/locales/ja.d.ts +2 -0
  62. package/types/src/i18n/locales/ko.d.ts +2 -0
  63. package/types/src/i18n/locales/nl.d.ts +2 -0
  64. package/types/src/i18n/locales/pl.d.ts +2 -0
  65. package/types/src/i18n/locales/pt.d.ts +2 -0
  66. package/types/src/i18n/locales/ru.d.ts +2 -0
  67. package/types/src/i18n/locales/vi.d.ts +2 -0
  68. package/types/src/i18n/locales/zh.d.ts +2 -0
  69. package/types/src/index.d.ts +7 -0
  70. package/types/src/pm-nodes/Column.d.ts +6 -0
  71. package/types/src/pm-nodes/ColumnList.d.ts +6 -0
  72. package/types/src/test/commands/insertBlocks.test.d.ts +1 -0
  73. package/types/src/test/commands/textCursorPosition.test.d.ts +1 -0
  74. package/types/src/test/commands/updateBlock.test.d.ts +1 -0
  75. package/types/src/test/conversions/htmlConversion.test.d.ts +1 -0
  76. package/types/src/test/conversions/nodeConversion.test.d.ts +1 -0
  77. package/types/src/test/conversions/testCases.d.ts +3 -0
  78. package/types/src/test/setupTestEnv.d.ts +1041 -0
@@ -0,0 +1,84 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import {
4
+ BlockNoteEditor,
5
+ PartialBlock,
6
+ UniqueID,
7
+ blockToNode,
8
+ nodeToBlock,
9
+ partialBlockToBlockForTesting,
10
+ } from "@blocknote/core";
11
+
12
+ import { multiColumnSchemaTestCases } from "./testCases.js";
13
+
14
+ function addIdsToBlock(block: PartialBlock<any, any, any>) {
15
+ if (!block.id) {
16
+ block.id = UniqueID.options.generateID();
17
+ }
18
+ for (const child of block.children || []) {
19
+ addIdsToBlock(child);
20
+ }
21
+ }
22
+
23
+ function validateConversion(
24
+ block: PartialBlock<any, any, any>,
25
+ editor: BlockNoteEditor<any, any, any>
26
+ ) {
27
+ addIdsToBlock(block);
28
+ const node = blockToNode(block, editor.pmSchema, editor.schema.styleSchema);
29
+
30
+ expect(node).toMatchSnapshot();
31
+
32
+ const outputBlock = nodeToBlock(
33
+ node,
34
+ editor.schema.blockSchema,
35
+ editor.schema.inlineContentSchema,
36
+ editor.schema.styleSchema
37
+ );
38
+
39
+ const fullOriginalBlock = partialBlockToBlockForTesting(
40
+ editor.schema.blockSchema,
41
+ block
42
+ );
43
+
44
+ expect(outputBlock).toStrictEqual(fullOriginalBlock);
45
+ }
46
+
47
+ const testCases = [multiColumnSchemaTestCases];
48
+
49
+ describe("Test BlockNote-Prosemirror conversion", () => {
50
+ for (const testCase of testCases) {
51
+ describe("Case: " + testCase.name, () => {
52
+ let editor: BlockNoteEditor<any, any, any>;
53
+ const div = document.createElement("div");
54
+
55
+ beforeEach(() => {
56
+ editor = testCase.createEditor();
57
+ // Note that we don't necessarily need to mount a root
58
+ // Currently, we do mount to a root so that it reflects the "production" use-case more closely.
59
+
60
+ // However, it would be nice to increased converage and share the same set of tests for these cases:
61
+ // - does render to a root
62
+ // - does not render to a root
63
+ // - runs in server (jsdom) environment using server-util
64
+ editor.mount(div);
65
+ });
66
+
67
+ afterEach(() => {
68
+ editor.mount(undefined);
69
+ editor._tiptapEditor.destroy();
70
+ editor = undefined as any;
71
+
72
+ delete (window as Window & { __TEST_OPTIONS?: any }).__TEST_OPTIONS;
73
+ });
74
+
75
+ for (const document of testCase.documents) {
76
+ // eslint-disable-next-line no-loop-func
77
+ it("Convert " + document.name + " to/from prosemirror", () => {
78
+ // NOTE: only converts first block
79
+ validateConversion(document.blocks[0], editor);
80
+ });
81
+ }
82
+ });
83
+ }
84
+ });
@@ -0,0 +1,54 @@
1
+ import { BlockNoteEditor, EditorTestCases } from "@blocknote/core";
2
+
3
+ import { testEditorSchema } from "../setupTestEnv.js";
4
+
5
+ export const multiColumnSchemaTestCases: EditorTestCases<
6
+ typeof testEditorSchema.blockSchema,
7
+ typeof testEditorSchema.inlineContentSchema,
8
+ typeof testEditorSchema.styleSchema
9
+ > = {
10
+ name: "multi-column-schema",
11
+ createEditor: () => {
12
+ return BlockNoteEditor.create({
13
+ schema: testEditorSchema,
14
+ });
15
+ },
16
+ documents: [
17
+ {
18
+ name: "multi-column",
19
+ blocks: [
20
+ {
21
+ type: "columnList",
22
+ children: [
23
+ {
24
+ type: "column",
25
+ children: [
26
+ {
27
+ type: "paragraph",
28
+ content: "Column Paragraph 0",
29
+ },
30
+ {
31
+ type: "paragraph",
32
+ content: "Column Paragraph 1",
33
+ },
34
+ ],
35
+ },
36
+ {
37
+ type: "column",
38
+ children: [
39
+ {
40
+ type: "paragraph",
41
+ content: "Column Paragraph 2",
42
+ },
43
+ {
44
+ type: "paragraph",
45
+ content: "Column Paragraph 3",
46
+ },
47
+ ],
48
+ },
49
+ ],
50
+ },
51
+ ],
52
+ },
53
+ ],
54
+ };
@@ -0,0 +1,99 @@
1
+ import {
2
+ BlockNoteEditor,
3
+ BlockNoteSchema,
4
+ PartialBlock,
5
+ } from "@blocknote/core";
6
+ import { afterAll, beforeAll, beforeEach } from "vitest";
7
+
8
+ import { withMultiColumn } from "../blocks/schema.js";
9
+
10
+ export const testEditorSchema = withMultiColumn(BlockNoteSchema.create());
11
+
12
+ export function setupTestEnv() {
13
+ let editor: BlockNoteEditor<
14
+ typeof testEditorSchema.blockSchema,
15
+ typeof testEditorSchema.inlineContentSchema,
16
+ typeof testEditorSchema.styleSchema
17
+ >;
18
+ const div = document.createElement("div");
19
+
20
+ beforeAll(() => {
21
+ editor = BlockNoteEditor.create({
22
+ schema: testEditorSchema,
23
+ });
24
+ editor.mount(div);
25
+ });
26
+
27
+ afterAll(() => {
28
+ editor.mount(undefined);
29
+ editor._tiptapEditor.destroy();
30
+ editor = undefined as any;
31
+ });
32
+
33
+ beforeEach(() => {
34
+ editor.replaceBlocks(editor.document, testDocument);
35
+ });
36
+
37
+ return () => editor;
38
+ }
39
+
40
+ const testDocument: PartialBlock<
41
+ typeof testEditorSchema.blockSchema,
42
+ typeof testEditorSchema.inlineContentSchema,
43
+ typeof testEditorSchema.styleSchema
44
+ >[] = [
45
+ {
46
+ id: "paragraph-0",
47
+ type: "paragraph",
48
+ content: "Paragraph 0",
49
+ children: [
50
+ {
51
+ id: "nested-paragraph-0",
52
+ type: "paragraph",
53
+ content: "Nested Paragraph 0",
54
+ },
55
+ ],
56
+ },
57
+ {
58
+ id: "column-list-0",
59
+ type: "columnList",
60
+ children: [
61
+ {
62
+ id: "column-0",
63
+ type: "column",
64
+ children: [
65
+ {
66
+ id: "column-paragraph-0",
67
+ type: "paragraph",
68
+ content: "Column Paragraph 0",
69
+ },
70
+ {
71
+ id: "column-paragraph-1",
72
+ type: "paragraph",
73
+ content: "Column Paragraph 1",
74
+ },
75
+ ],
76
+ },
77
+ {
78
+ id: "column-1",
79
+ type: "column",
80
+ children: [
81
+ {
82
+ id: "column-paragraph-2",
83
+ type: "paragraph",
84
+ content: "Column Paragraph 2",
85
+ },
86
+ {
87
+ id: "column-paragraph-3",
88
+ type: "paragraph",
89
+ content: "Column Paragraph 3",
90
+ },
91
+ ],
92
+ },
93
+ ],
94
+ },
95
+ {
96
+ id: "trailing-paragraph",
97
+ type: "paragraph",
98
+ },
99
+ ];
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,32 @@
1
+ export declare const ColumnBlock: {
2
+ config: {
3
+ type: "column";
4
+ content: "none";
5
+ propSchema: {
6
+ width: {
7
+ default: number;
8
+ };
9
+ };
10
+ };
11
+ implementation: import("@blocknote/core").TiptapBlockImplementation<{
12
+ type: "column";
13
+ content: "none";
14
+ propSchema: {
15
+ width: {
16
+ default: number;
17
+ };
18
+ };
19
+ }, any, import("@blocknote/core").InlineContentSchema, import("@blocknote/core").StyleSchema>;
20
+ };
21
+ export declare const ColumnListBlock: {
22
+ config: {
23
+ type: "columnList";
24
+ content: "none";
25
+ propSchema: {};
26
+ };
27
+ implementation: import("@blocknote/core").TiptapBlockImplementation<{
28
+ type: "columnList";
29
+ content: "none";
30
+ propSchema: {};
31
+ }, any, import("@blocknote/core").InlineContentSchema, import("@blocknote/core").StyleSchema>;
32
+ };
@@ -0,0 +1,102 @@
1
+ import { BlockNoteSchema, InlineContentSchema, StyleSchema } from "@blocknote/core";
2
+ import { ColumnBlock, ColumnListBlock } from "./Columns/index.js";
3
+ export declare const multiColumnSchema: BlockNoteSchema<import("@blocknote/core").BlockSchemaFromSpecs<{
4
+ column: {
5
+ config: {
6
+ type: "column";
7
+ content: "none";
8
+ propSchema: {
9
+ width: {
10
+ default: number;
11
+ };
12
+ };
13
+ };
14
+ implementation: import("@blocknote/core").TiptapBlockImplementation<{
15
+ type: "column";
16
+ content: "none";
17
+ propSchema: {
18
+ width: {
19
+ default: number;
20
+ };
21
+ };
22
+ }, any, InlineContentSchema, StyleSchema>;
23
+ };
24
+ columnList: {
25
+ config: {
26
+ type: "columnList";
27
+ content: "none";
28
+ propSchema: {};
29
+ };
30
+ implementation: import("@blocknote/core").TiptapBlockImplementation<{
31
+ type: "columnList";
32
+ content: "none";
33
+ propSchema: {};
34
+ }, any, InlineContentSchema, StyleSchema>;
35
+ };
36
+ }>, import("@blocknote/core").InlineContentSchemaFromSpecs<{
37
+ text: {
38
+ config: "text";
39
+ implementation: any;
40
+ };
41
+ link: {
42
+ config: "link";
43
+ implementation: any;
44
+ };
45
+ }>, import("@blocknote/core").StyleSchemaFromSpecs<{
46
+ bold: {
47
+ config: {
48
+ type: string;
49
+ propSchema: "boolean";
50
+ };
51
+ implementation: import("@blocknote/core").StyleImplementation;
52
+ };
53
+ italic: {
54
+ config: {
55
+ type: string;
56
+ propSchema: "boolean";
57
+ };
58
+ implementation: import("@blocknote/core").StyleImplementation;
59
+ };
60
+ underline: {
61
+ config: {
62
+ type: string;
63
+ propSchema: "boolean";
64
+ };
65
+ implementation: import("@blocknote/core").StyleImplementation;
66
+ };
67
+ strike: {
68
+ config: {
69
+ type: string;
70
+ propSchema: "boolean";
71
+ };
72
+ implementation: import("@blocknote/core").StyleImplementation;
73
+ };
74
+ code: {
75
+ config: {
76
+ type: string;
77
+ propSchema: "boolean";
78
+ };
79
+ implementation: import("@blocknote/core").StyleImplementation;
80
+ };
81
+ textColor: {
82
+ config: {
83
+ type: string;
84
+ propSchema: "string";
85
+ };
86
+ implementation: import("@blocknote/core").StyleImplementation;
87
+ };
88
+ backgroundColor: {
89
+ config: {
90
+ type: string;
91
+ propSchema: "string";
92
+ };
93
+ implementation: import("@blocknote/core").StyleImplementation;
94
+ };
95
+ }>>;
96
+ /**
97
+ * Adds multi-column support to the given schema.
98
+ */
99
+ export declare const withMultiColumn: <B extends Record<string, import("@blocknote/core").BlockConfig>, I extends InlineContentSchema, S extends StyleSchema>(schema: BlockNoteSchema<B, I, S>) => BlockNoteSchema<B & {
100
+ column: typeof ColumnBlock.config;
101
+ columnList: typeof ColumnListBlock.config;
102
+ }, I, S>;
@@ -0,0 +1,3 @@
1
+ import { BlockNoteEditor } from "@blocknote/core";
2
+ import { Extension } from "@tiptap/core";
3
+ export declare const createColumnResizeExtension: (editor: BlockNoteEditor<any, any, any>) => Extension<any, any>;
@@ -0,0 +1,11 @@
1
+ import type { BlockNoteEditor } from "@blocknote/core";
2
+ import { Plugin } from "prosemirror-state";
3
+ interface DropCursorOptions {
4
+ color?: string | false;
5
+ width?: number;
6
+ class?: string;
7
+ }
8
+ export declare function multiColumnDropCursor(options: DropCursorOptions & {
9
+ editor: BlockNoteEditor<any, any, any>;
10
+ }): Plugin;
11
+ export {};
@@ -0,0 +1,5 @@
1
+ import { BlockNoteEditor, BlockSchema, InlineContentSchema, StyleSchema } from "@blocknote/core";
2
+ import { DefaultReactSuggestionItem } from "@blocknote/react";
3
+ import { multiColumnSchema } from "../../blocks/schema.js";
4
+ export declare function checkMultiColumnBlocksInSchema<I extends InlineContentSchema, S extends StyleSchema>(editor: BlockNoteEditor<any, I, S>): editor is BlockNoteEditor<typeof multiColumnSchema.blockSchema, I, S>;
5
+ export declare function getMultiColumnSlashMenuItems<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(editor: BlockNoteEditor<BSchema, I, S>): Omit<DefaultReactSuggestionItem, "key">[];
@@ -0,0 +1,19 @@
1
+ import type { en } from "./locales/index.js";
2
+ import { BlockNoteEditor } from "@blocknote/core";
3
+ export declare function getMultiColumnDictionary(editor: BlockNoteEditor<any, any, any>): {
4
+ slash_menu: {
5
+ two_columns: {
6
+ title: string;
7
+ subtext: string;
8
+ aliases: string[];
9
+ group: string;
10
+ };
11
+ three_columns: {
12
+ title: string;
13
+ subtext: string;
14
+ aliases: string[];
15
+ group: string;
16
+ };
17
+ };
18
+ };
19
+ export type MultiColumnDictionary = typeof en;
@@ -0,0 +1,2 @@
1
+ import type { MultiColumnDictionary } from "../dictionary.js";
2
+ export declare const ar: MultiColumnDictionary;
@@ -0,0 +1,2 @@
1
+ import type { MultiColumnDictionary } from "../dictionary.js";
2
+ export declare const de: MultiColumnDictionary;
@@ -0,0 +1,16 @@
1
+ export declare const en: {
2
+ slash_menu: {
3
+ two_columns: {
4
+ title: string;
5
+ subtext: string;
6
+ aliases: string[];
7
+ group: string;
8
+ };
9
+ three_columns: {
10
+ title: string;
11
+ subtext: string;
12
+ aliases: string[];
13
+ group: string;
14
+ };
15
+ };
16
+ };
@@ -0,0 +1,2 @@
1
+ import type { MultiColumnDictionary } from "../dictionary.js";
2
+ export declare const es: MultiColumnDictionary;
@@ -0,0 +1,2 @@
1
+ import type { MultiColumnDictionary } from "../dictionary.js";
2
+ export declare const fr: MultiColumnDictionary;
@@ -0,0 +1,2 @@
1
+ import type { MultiColumnDictionary } from "../dictionary.js";
2
+ export declare const hr: MultiColumnDictionary;
@@ -0,0 +1,15 @@
1
+ export * from "./ar.js";
2
+ export * from "./de.js";
3
+ export * from "./en.js";
4
+ export * from "./es.js";
5
+ export * from "./fr.js";
6
+ export * from "./hr.js";
7
+ export * from "./is.js";
8
+ export * from "./ja.js";
9
+ export * from "./ko.js";
10
+ export * from "./nl.js";
11
+ export * from "./pl.js";
12
+ export * from "./pt.js";
13
+ export * from "./ru.js";
14
+ export * from "./vi.js";
15
+ export * from "./zh.js";
@@ -0,0 +1,2 @@
1
+ import type { MultiColumnDictionary } from "../dictionary.js";
2
+ export declare const is: MultiColumnDictionary;
@@ -0,0 +1,2 @@
1
+ import type { MultiColumnDictionary } from "../dictionary.js";
2
+ export declare const ja: MultiColumnDictionary;
@@ -0,0 +1,2 @@
1
+ import type { MultiColumnDictionary } from "../dictionary.js";
2
+ export declare const ko: MultiColumnDictionary;
@@ -0,0 +1,2 @@
1
+ import type { MultiColumnDictionary } from "../dictionary.js";
2
+ export declare const nl: MultiColumnDictionary;
@@ -0,0 +1,2 @@
1
+ import type { MultiColumnDictionary } from "../dictionary.js";
2
+ export declare const pl: MultiColumnDictionary;
@@ -0,0 +1,2 @@
1
+ import type { MultiColumnDictionary } from "../dictionary.js";
2
+ export declare const pt: MultiColumnDictionary;
@@ -0,0 +1,2 @@
1
+ import type { MultiColumnDictionary } from "../dictionary.js";
2
+ export declare const ru: MultiColumnDictionary;
@@ -0,0 +1,2 @@
1
+ import type { MultiColumnDictionary } from "../dictionary.js";
2
+ export declare const vi: MultiColumnDictionary;
@@ -0,0 +1,2 @@
1
+ import type { MultiColumnDictionary } from "../dictionary.js";
2
+ export declare const zh: MultiColumnDictionary;
@@ -0,0 +1,7 @@
1
+ import * as locales from "./i18n/locales/index.js";
2
+ export { locales };
3
+ export * from "./i18n/dictionary.js";
4
+ export * from "./blocks/Columns/index.js";
5
+ export * from "./blocks/schema.js";
6
+ export * from "./extensions/DropCursor/MultiColumnDropCursorPlugin.js";
7
+ export * from "./extensions/SuggestionMenu/getMultiColumnSlashMenuItems.js";
@@ -0,0 +1,6 @@
1
+ export declare const Column: import("@tiptap/core").Node<any, any> & {
2
+ name: "column";
3
+ config: {
4
+ content: "blockContainer+";
5
+ };
6
+ };
@@ -0,0 +1,6 @@
1
+ export declare const ColumnList: import("@tiptap/core").Node<any, any> & {
2
+ name: "columnList";
3
+ config: {
4
+ content: "column column+";
5
+ };
6
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { EditorTestCases } from "@blocknote/core";
2
+ import { testEditorSchema } from "../setupTestEnv.js";
3
+ export declare const multiColumnSchemaTestCases: EditorTestCases<typeof testEditorSchema.blockSchema, typeof testEditorSchema.inlineContentSchema, typeof testEditorSchema.styleSchema>;