@fibery/prosemirror-schema 4.19.0-next.1 → 4.19.0-next.3
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/lib/src/create-schema.d.ts +1 -1
- package/lib/src/create-schema.js +45 -40
- package/lib/src/nodes/callout.d.ts +1 -1
- package/lib/src/nodes/code-block.js +15 -4
- package/lib/src/nodes/emoji.d.ts +2 -2
- package/lib/src/nodes/file.d.ts +2 -2
- package/lib/src/nodes/heading.js +9 -3
- package/lib/src/nodes/paragraph.js +9 -5
- package/package.json +7 -7
|
@@ -9,7 +9,7 @@ type Params = {
|
|
|
9
9
|
mediaToDom?: ((node: Node) => HTMLElement) | null;
|
|
10
10
|
emojiOptions?: EmojiOptions;
|
|
11
11
|
};
|
|
12
|
-
export declare const createSchema: ({ sharedColorGenerator, headingToDOM, mediaToDom, isImageBlockEnabled, fiberyViewEnabled, emojiOptions, }?: Params) =>
|
|
12
|
+
export declare const createSchema: ({ sharedColorGenerator, headingToDOM, mediaToDom, isImageBlockEnabled, fiberyViewEnabled, emojiOptions, }?: Params) => Schema;
|
|
13
13
|
export declare const Basic: {
|
|
14
14
|
nodes: Record<string, NodeSpec>;
|
|
15
15
|
marks: Record<string, MarkSpec>;
|
package/lib/src/create-schema.js
CHANGED
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.Basic = exports.createSchema = void 0;
|
|
37
4
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
@@ -67,11 +34,10 @@ const note_1 = require("./nodes/note");
|
|
|
67
34
|
const paragraph_1 = require("./nodes/paragraph");
|
|
68
35
|
const table_nodes_1 = require("./nodes/table-nodes");
|
|
69
36
|
const video_1 = require("./nodes/video");
|
|
70
|
-
const createSchema =
|
|
37
|
+
const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaToDom = null, isImageBlockEnabled = false, fiberyViewEnabled = false, emojiOptions, } = {}) => {
|
|
71
38
|
prosemirror_schema_basic_1.nodes.code_block = code_block_1.code_block;
|
|
72
39
|
prosemirror_schema_basic_1.nodes.paragraph = paragraph_1.paragraph;
|
|
73
40
|
prosemirror_schema_basic_1.nodes.heading = (0, heading_1.makeHeading)({ headingToDOM });
|
|
74
|
-
const { deletion, insertion, modification } = await Promise.resolve().then(() => __importStar(require("@handlewithcare/prosemirror-suggest-changes")));
|
|
75
41
|
const base = new prosemirror_model_1.Schema({
|
|
76
42
|
nodes: prosemirror_schema_basic_1.nodes,
|
|
77
43
|
marks: {
|
|
@@ -114,8 +80,22 @@ const createSchema = async ({ sharedColorGenerator = null, headingToDOM = null,
|
|
|
114
80
|
}
|
|
115
81
|
actualNodes = actualNodes.update("doc", {
|
|
116
82
|
content: `(block | columns)+`,
|
|
117
|
-
marks: "insertion modification deletion",
|
|
118
83
|
});
|
|
84
|
+
// prosemirror-tables@1.7.0+ added validate constraints to cell attrs
|
|
85
|
+
// (colspan, rowspan, colwidth). Legacy Fibery documents may not satisfy
|
|
86
|
+
// these validators. Drop all validators so those documents can still be parsed.
|
|
87
|
+
for (const cellType of ["table_cell", "table_header"]) {
|
|
88
|
+
const cellSpec = actualNodes.get(cellType);
|
|
89
|
+
const attrsWithoutValidate = {};
|
|
90
|
+
for (const [key, attrSpec] of Object.entries(cellSpec.attrs ?? {})) {
|
|
91
|
+
const { validate: _, ...rest } = attrSpec;
|
|
92
|
+
attrsWithoutValidate[key] = rest;
|
|
93
|
+
}
|
|
94
|
+
actualNodes = actualNodes.update(cellType, {
|
|
95
|
+
...cellSpec,
|
|
96
|
+
attrs: attrsWithoutValidate,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
119
99
|
// prosemirror-schema-list@1.5.0+ added validate:"number" to the order attr,
|
|
120
100
|
// which rejects legacy documents where order was stored as null. Drop the
|
|
121
101
|
// validator so those documents can still be parsed.
|
|
@@ -216,6 +196,34 @@ const createSchema = async ({ sharedColorGenerator = null, headingToDOM = null,
|
|
|
216
196
|
return Object.keys(attrs).length ? ["li", attrs, 0] : ["li", 0];
|
|
217
197
|
},
|
|
218
198
|
});
|
|
199
|
+
// Every block node carries a unified "id" attr so blocks are addressable in
|
|
200
|
+
// collaborative editing and block-level APIs. paragraph/heading/code_block
|
|
201
|
+
// declare it in their own specs (mirrored into the deprecated "guid");
|
|
202
|
+
// check_list/check_item/columns/fiberyView/list_item already have "id".
|
|
203
|
+
// toDOM/parseDOM are deliberately left untouched here so pasted HTML never
|
|
204
|
+
// carries an id and cannot introduce duplicates.
|
|
205
|
+
const blocksNeedingId = [
|
|
206
|
+
"blockquote",
|
|
207
|
+
"horizontal_rule",
|
|
208
|
+
"bullet_list",
|
|
209
|
+
"ordered_list",
|
|
210
|
+
"table",
|
|
211
|
+
"note",
|
|
212
|
+
"important",
|
|
213
|
+
"callout",
|
|
214
|
+
"media",
|
|
215
|
+
"video",
|
|
216
|
+
"imageBlock",
|
|
217
|
+
"math_display",
|
|
218
|
+
"column",
|
|
219
|
+
];
|
|
220
|
+
for (const name of blocksNeedingId) {
|
|
221
|
+
const spec = actualNodes.get(name);
|
|
222
|
+
actualNodes = actualNodes.update(name, {
|
|
223
|
+
...spec,
|
|
224
|
+
attrs: { ...(spec.attrs ?? {}), id: { default: null } },
|
|
225
|
+
});
|
|
226
|
+
}
|
|
219
227
|
return new prosemirror_model_1.Schema({
|
|
220
228
|
nodes: actualNodes,
|
|
221
229
|
marks: base.spec.marks
|
|
@@ -224,10 +232,7 @@ const createSchema = async ({ sharedColorGenerator = null, headingToDOM = null,
|
|
|
224
232
|
.addToEnd("hintQuery", hint_query_1.hintQuery)
|
|
225
233
|
// We leave mark key as "highlight" only because we don't want to do migration.
|
|
226
234
|
// "TextBackgroundColor" term is used everywhere through codebase.
|
|
227
|
-
.addToEnd("highlight", text_background_color_1.textBackgroundColor)
|
|
228
|
-
.addToEnd("insertion", insertion)
|
|
229
|
-
.addToEnd("deletion", deletion)
|
|
230
|
-
.addToEnd("modification", modification),
|
|
235
|
+
.addToEnd("highlight", text_background_color_1.textBackgroundColor),
|
|
231
236
|
});
|
|
232
237
|
};
|
|
233
238
|
exports.createSchema = createSchema;
|
|
@@ -46,6 +46,9 @@ exports.code_block = {
|
|
|
46
46
|
isolating: true,
|
|
47
47
|
defining: true,
|
|
48
48
|
attrs: {
|
|
49
|
+
// "id" is the unified block identifier; "guid" is deprecated and mirrors
|
|
50
|
+
// "id" until all consumers (client editor, fibery backend) read "id".
|
|
51
|
+
id: { default: null },
|
|
49
52
|
guid: { default: "" },
|
|
50
53
|
language: { default: null },
|
|
51
54
|
wrapCode: { default: false },
|
|
@@ -58,7 +61,7 @@ exports.code_block = {
|
|
|
58
61
|
preserveWhitespace: "full",
|
|
59
62
|
getAttrs: (domNode) => {
|
|
60
63
|
const dom = domNode;
|
|
61
|
-
const
|
|
64
|
+
const id = dom.getAttribute("data-guid") || (0, uuid_1.v4)();
|
|
62
65
|
const language = getLanguageFromBitbucketStyle(dom.parentElement) ||
|
|
63
66
|
getLanguageFromEditorStyle(dom.parentElement) ||
|
|
64
67
|
getLanguageFromCode(dom) ||
|
|
@@ -66,7 +69,14 @@ exports.code_block = {
|
|
|
66
69
|
const wrapCodeAttr = dom.getAttribute("data-wrap-code");
|
|
67
70
|
const wrapCode = wrapCodeAttr === "true";
|
|
68
71
|
removeLastNewLine(dom);
|
|
69
|
-
return {
|
|
72
|
+
return {
|
|
73
|
+
id,
|
|
74
|
+
guid: id,
|
|
75
|
+
language,
|
|
76
|
+
wrapCode,
|
|
77
|
+
mode: dom.getAttribute("data-mode") || "split",
|
|
78
|
+
...(0, resizable_node_attrs_1.createParseDomAttrs)(dom),
|
|
79
|
+
};
|
|
70
80
|
},
|
|
71
81
|
},
|
|
72
82
|
// Handle GitHub/Gist paste
|
|
@@ -82,14 +92,15 @@ exports.code_block = {
|
|
|
82
92
|
},
|
|
83
93
|
],
|
|
84
94
|
toDOM(node) {
|
|
85
|
-
const
|
|
95
|
+
const id = node.attrs.id || node.attrs.guid || "";
|
|
86
96
|
return [
|
|
87
97
|
"pre",
|
|
88
98
|
[
|
|
89
99
|
"code",
|
|
90
100
|
{
|
|
91
101
|
"data-language": node.attrs.language,
|
|
92
|
-
"data-
|
|
102
|
+
"data-id": id,
|
|
103
|
+
"data-guid": id,
|
|
93
104
|
"data-wrap-code": node.attrs.wrapCode || false,
|
|
94
105
|
"data-mode": node.attrs.mode || "split",
|
|
95
106
|
...(0, resizable_node_attrs_1.createToDomAttrs)(node.attrs),
|
package/lib/src/nodes/emoji.d.ts
CHANGED
|
@@ -16,14 +16,14 @@ export declare const makeEmoji: ({ getEmoji }?: EmojiOptions) => {
|
|
|
16
16
|
group: string;
|
|
17
17
|
selectable: false;
|
|
18
18
|
draggable: false;
|
|
19
|
-
leafText: (node: import("
|
|
19
|
+
leafText: (node: import("prosemirror-model").Node) => any;
|
|
20
20
|
parseDOM: {
|
|
21
21
|
tag: string;
|
|
22
22
|
getAttrs(domNode: HTMLElement): {
|
|
23
23
|
code: string;
|
|
24
24
|
};
|
|
25
25
|
}[];
|
|
26
|
-
toDOM(node: import("
|
|
26
|
+
toDOM(node: import("prosemirror-model").Node): [string, {
|
|
27
27
|
"data-emoji-node": string;
|
|
28
28
|
"data-emoji-code": any;
|
|
29
29
|
}, any];
|
package/lib/src/nodes/file.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare const file: {
|
|
|
18
18
|
group: string;
|
|
19
19
|
selectable: false;
|
|
20
20
|
draggable: false;
|
|
21
|
-
leafText: (node: import("
|
|
21
|
+
leafText: (node: import("prosemirror-model").Node) => any;
|
|
22
22
|
parseDOM: {
|
|
23
23
|
tag: string;
|
|
24
24
|
getAttrs(domNode: HTMLElement): {
|
|
@@ -28,7 +28,7 @@ export declare const file: {
|
|
|
28
28
|
type: string | null;
|
|
29
29
|
};
|
|
30
30
|
}[];
|
|
31
|
-
toDOM(node: import("
|
|
31
|
+
toDOM(node: import("prosemirror-model").Node): [string, {
|
|
32
32
|
"data-file-href": any;
|
|
33
33
|
"data-size": any;
|
|
34
34
|
"data-type": any;
|
package/lib/src/nodes/heading.js
CHANGED
|
@@ -5,12 +5,18 @@ const uuid_1 = require("uuid");
|
|
|
5
5
|
const parseGuid = (dom) => {
|
|
6
6
|
return dom.getAttribute("guid") || (0, uuid_1.v4)();
|
|
7
7
|
};
|
|
8
|
-
const makeGetAttrs = (level) => (dom) =>
|
|
8
|
+
const makeGetAttrs = (level) => (dom) => {
|
|
9
|
+
const id = parseGuid(dom);
|
|
10
|
+
return { level, id, guid: id };
|
|
11
|
+
};
|
|
9
12
|
const makeHeading = ({ headingToDOM }) => ({
|
|
10
13
|
content: "inline*",
|
|
11
14
|
group: "block",
|
|
12
15
|
attrs: {
|
|
13
16
|
level: { default: 1 },
|
|
17
|
+
// "id" is the unified block identifier; "guid" is deprecated and mirrors
|
|
18
|
+
// "id" until all consumers (client editor, fibery backend) read "id".
|
|
19
|
+
id: { default: null },
|
|
14
20
|
guid: { default: "" },
|
|
15
21
|
},
|
|
16
22
|
defining: true,
|
|
@@ -26,8 +32,8 @@ const makeHeading = ({ headingToDOM }) => ({
|
|
|
26
32
|
if (headingToDOM) {
|
|
27
33
|
return headingToDOM(node);
|
|
28
34
|
}
|
|
29
|
-
const
|
|
30
|
-
return ["h" + node.attrs.level, { guid }, 0];
|
|
35
|
+
const id = node.attrs.id || node.attrs.guid;
|
|
36
|
+
return ["h" + node.attrs.level, { "data-id": id, guid: id }, 0];
|
|
31
37
|
},
|
|
32
38
|
});
|
|
33
39
|
exports.makeHeading = makeHeading;
|
|
@@ -6,18 +6,22 @@ exports.paragraph = {
|
|
|
6
6
|
content: "inline*",
|
|
7
7
|
group: "block",
|
|
8
8
|
attrs: {
|
|
9
|
+
// "id" is the unified block identifier; "guid" is deprecated and mirrors
|
|
10
|
+
// "id" until all consumers (client editor, fibery backend) read "id".
|
|
11
|
+
id: { default: null },
|
|
9
12
|
guid: { default: "" },
|
|
10
13
|
},
|
|
11
14
|
parseDOM: [
|
|
12
15
|
{
|
|
13
16
|
tag: "p",
|
|
14
|
-
getAttrs: (dom) =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
getAttrs: (dom) => {
|
|
18
|
+
const id = dom.getAttribute("data-guid") || (0, uuid_1.v4)();
|
|
19
|
+
return { id, guid: id };
|
|
20
|
+
},
|
|
17
21
|
},
|
|
18
22
|
],
|
|
19
23
|
toDOM(node) {
|
|
20
|
-
const
|
|
21
|
-
return ["p", { "data-
|
|
24
|
+
const id = node.attrs.id || node.attrs.guid;
|
|
25
|
+
return ["p", { "data-id": id, "data-guid": id }, 0];
|
|
22
26
|
},
|
|
23
27
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/prosemirror-schema",
|
|
3
|
-
"version": "4.19.0-next.
|
|
3
|
+
"version": "4.19.0-next.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Fibery prosemirror schema",
|
|
6
6
|
"files": [
|
|
@@ -22,29 +22,29 @@
|
|
|
22
22
|
"./lib/src/nodes/fibery-section.d.ts": "./lib/src/nodes/fibery-section.d.ts"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@handlewithcare/prosemirror-suggest-changes": "^0.1.8",
|
|
26
25
|
"prosemirror-model": "1.25.4",
|
|
27
26
|
"prosemirror-schema-basic": "1.2.2",
|
|
28
27
|
"prosemirror-schema-list": "1.5.1",
|
|
29
|
-
"prosemirror-tables": "1.
|
|
28
|
+
"prosemirror-tables": "1.8.5",
|
|
30
29
|
"uuid": "11.1.0"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
|
-
"typescript": "
|
|
32
|
+
"typescript": "rc",
|
|
34
33
|
"@fibery/babel-preset": "7.4.2"
|
|
35
34
|
},
|
|
36
35
|
"peerDependencies": {
|
|
37
36
|
"prosemirror-model": "1.25.4",
|
|
38
37
|
"prosemirror-schema-list": "1.5.1",
|
|
39
|
-
"prosemirror-tables": "1.
|
|
38
|
+
"prosemirror-tables": "1.8.5"
|
|
40
39
|
},
|
|
41
40
|
"scripts": {
|
|
42
41
|
"build": "rm -rf lib && tsc --project tsconfig.build.json",
|
|
43
42
|
"test": "../../scripts/test.sh",
|
|
44
43
|
"test:ci": "../../scripts/test.sh --ci",
|
|
45
44
|
"test:coverage": "../../scripts/test.sh --ci --coverage",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
45
|
+
"lint": "pnpm -w lint .",
|
|
46
|
+
"typecheck": "../../scripts/typecheck.sh",
|
|
47
|
+
"check": "../../scripts/check.sh"
|
|
48
48
|
},
|
|
49
49
|
"types": "./lib/index.d.ts"
|
|
50
50
|
}
|