@fibery/prosemirror-schema 4.21.0 → 4.23.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.
- package/lib/index.d.ts +10 -8
- package/lib/index.js +9 -26
- package/lib/src/attr-constraints.d.ts +15 -12
- package/lib/src/attr-constraints.js +128 -168
- package/lib/src/block-id-utils.d.ts +10 -7
- package/lib/src/block-id-utils.js +16 -39
- package/lib/src/create-schema.d.ts +16 -15
- package/lib/src/create-schema.js +204 -249
- package/lib/src/marks/code.d.ts +5 -2
- package/lib/src/marks/code.js +10 -10
- package/lib/src/marks/em.d.ts +5 -2
- package/lib/src/marks/em.js +19 -16
- package/lib/src/marks/hint-query.d.ts +5 -2
- package/lib/src/marks/hint-query.js +19 -22
- package/lib/src/marks/link.d.ts +5 -2
- package/lib/src/marks/link.js +40 -36
- package/lib/src/marks/linked-highlight.d.ts +9 -7
- package/lib/src/marks/linked-highlight.js +38 -51
- package/lib/src/marks/strike.d.ts +5 -2
- package/lib/src/marks/strike.js +6 -6
- package/lib/src/marks/strong.d.ts +5 -2
- package/lib/src/marks/strong.js +29 -29
- package/lib/src/marks/text-background-color.d.ts +16 -2
- package/lib/src/marks/text-background-color.js +63 -81
- package/lib/src/marks/underline.d.ts +5 -2
- package/lib/src/marks/underline.js +6 -6
- package/lib/src/nodes/callout.d.ts +29 -28
- package/lib/src/nodes/callout.js +58 -36
- package/lib/src/nodes/check-item.d.ts +13 -10
- package/lib/src/nodes/check-item.js +32 -33
- package/lib/src/nodes/check-list.d.ts +14 -11
- package/lib/src/nodes/check-list.js +23 -30
- package/lib/src/nodes/code-block.d.ts +5 -2
- package/lib/src/nodes/code-block.js +70 -101
- package/lib/src/nodes/column.d.ts +5 -2
- package/lib/src/nodes/column.js +28 -34
- package/lib/src/nodes/columns.d.ts +5 -2
- package/lib/src/nodes/columns.js +34 -36
- package/lib/src/nodes/emoji.d.ts +28 -26
- package/lib/src/nodes/emoji.js +38 -47
- package/lib/src/nodes/entity.d.ts +18 -16
- package/lib/src/nodes/entity.js +48 -49
- package/lib/src/nodes/fibery-view.d.ts +5 -2
- package/lib/src/nodes/fibery-view.js +38 -42
- package/lib/src/nodes/file.d.ts +37 -34
- package/lib/src/nodes/file.js +41 -40
- package/lib/src/nodes/heading.d.ts +6 -3
- package/lib/src/nodes/heading.js +57 -33
- package/lib/src/nodes/image-block.d.ts +5 -2
- package/lib/src/nodes/image-block.js +43 -42
- package/lib/src/nodes/important.d.ts +5 -2
- package/lib/src/nodes/important.js +14 -10
- package/lib/src/nodes/math-display.d.ts +5 -2
- package/lib/src/nodes/math-display.js +14 -15
- package/lib/src/nodes/math-inline.d.ts +5 -2
- package/lib/src/nodes/math-inline.js +14 -15
- package/lib/src/nodes/media.d.ts +6 -3
- package/lib/src/nodes/media.js +52 -68
- package/lib/src/nodes/mention.d.ts +12 -9
- package/lib/src/nodes/mention.js +36 -37
- package/lib/src/nodes/note.d.ts +5 -2
- package/lib/src/nodes/note.js +14 -10
- package/lib/src/nodes/paragraph.d.ts +5 -2
- package/lib/src/nodes/paragraph.js +32 -26
- package/lib/src/nodes/table-nodes.d.ts +5 -2
- package/lib/src/nodes/table-nodes.js +16 -20
- package/lib/src/nodes/types/inline-content.d.ts +10 -8
- package/lib/src/nodes/types/inline-content.js +0 -2
- package/lib/src/nodes/types/text.d.ts +7 -4
- package/lib/src/nodes/types/text.js +0 -2
- package/lib/src/nodes/video.d.ts +7 -4
- package/lib/src/nodes/video.js +49 -54
- package/lib/src/resizable-node-attrs.d.ts +29 -26
- package/lib/src/resizable-node-attrs.js +23 -34
- package/lib/src/transcription-node-attrs.d.ts +10 -7
- package/lib/src/transcription-node-attrs.js +8 -8
- package/lib/test-helpers/index.d.ts +7 -4
- package/lib/test-helpers/index.js +11 -15
- package/package.json +11 -4
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { defaultHeight, defaultWidth } from "./src/resizable-node-attrs.js";
|
|
2
|
+
import { EmojiOptions } from "./src/nodes/emoji.js";
|
|
3
|
+
import { Basic, createSchema } from "./src/create-schema.js";
|
|
4
|
+
import { AttrConstraint, AttrConstraintType, AttrValidationIssue, NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs } from "./src/attr-constraints.js";
|
|
5
|
+
import { FIBERY_VIEW_TYPE, buildBlockIdAttrs, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr } from "./src/block-id-utils.js";
|
|
6
|
+
import { DEFAULT_VIDEO_HEIGHT, DEFAULT_VIDEO_WIDTH } from "./src/nodes/video.js";
|
|
7
|
+
import { DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE } from "./src/nodes/callout.js";
|
|
8
|
+
import { ColorToken } from "./src/marks/text-background-color.js";
|
|
9
|
+
import { Node, Schema } from "prosemirror-model";
|
|
10
|
+
export { type AttrConstraint, type AttrConstraintType, type AttrValidationIssue, Basic, ColorToken, DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE, DEFAULT_VIDEO_HEIGHT, DEFAULT_VIDEO_WIDTH, type EmojiOptions, FIBERY_VIEW_TYPE, NODE_ATTR_CONSTRAINTS, Node, Schema, buildBlockIdAttrs, createSchema, defaultHeight, defaultWidth, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr, validateAttrValue, validateAttrs };
|
package/lib/index.js
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var create_schema_1 = require("./src/create-schema");
|
|
11
|
-
Object.defineProperty(exports, "createSchema", { enumerable: true, get: function () { return create_schema_1.createSchema; } });
|
|
12
|
-
Object.defineProperty(exports, "Basic", { enumerable: true, get: function () { return create_schema_1.Basic; } });
|
|
13
|
-
var attr_constraints_1 = require("./src/attr-constraints");
|
|
14
|
-
Object.defineProperty(exports, "NODE_ATTR_CONSTRAINTS", { enumerable: true, get: function () { return attr_constraints_1.NODE_ATTR_CONSTRAINTS; } });
|
|
15
|
-
Object.defineProperty(exports, "validateAttrValue", { enumerable: true, get: function () { return attr_constraints_1.validateAttrValue; } });
|
|
16
|
-
Object.defineProperty(exports, "validateAttrs", { enumerable: true, get: function () { return attr_constraints_1.validateAttrs; } });
|
|
17
|
-
var block_id_utils_1 = require("./src/block-id-utils");
|
|
18
|
-
Object.defineProperty(exports, "getBlockId", { enumerable: true, get: function () { return block_id_utils_1.getBlockId; } });
|
|
19
|
-
Object.defineProperty(exports, "getBlockIdAttr", { enumerable: true, get: function () { return block_id_utils_1.getBlockIdAttr; } });
|
|
20
|
-
Object.defineProperty(exports, "hasLegacyGuidAttr", { enumerable: true, get: function () { return block_id_utils_1.hasLegacyGuidAttr; } });
|
|
21
|
-
Object.defineProperty(exports, "buildBlockIdAttrs", { enumerable: true, get: function () { return block_id_utils_1.buildBlockIdAttrs; } });
|
|
22
|
-
Object.defineProperty(exports, "getFiberyViewRef", { enumerable: true, get: function () { return block_id_utils_1.getFiberyViewRef; } });
|
|
23
|
-
Object.defineProperty(exports, "FIBERY_VIEW_TYPE", { enumerable: true, get: function () { return block_id_utils_1.FIBERY_VIEW_TYPE; } });
|
|
24
|
-
var video_1 = require("./src/nodes/video");
|
|
25
|
-
Object.defineProperty(exports, "DEFAULT_VIDEO_WIDTH", { enumerable: true, get: function () { return video_1.DEFAULT_VIDEO_WIDTH; } });
|
|
26
|
-
Object.defineProperty(exports, "DEFAULT_VIDEO_HEIGHT", { enumerable: true, get: function () { return video_1.DEFAULT_VIDEO_HEIGHT; } });
|
|
1
|
+
import { defaultHeight, defaultWidth } from "./src/resizable-node-attrs.js";
|
|
2
|
+
import { ColorToken } from "./src/marks/text-background-color.js";
|
|
3
|
+
import { DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE } from "./src/nodes/callout.js";
|
|
4
|
+
import { DEFAULT_VIDEO_HEIGHT, DEFAULT_VIDEO_WIDTH } from "./src/nodes/video.js";
|
|
5
|
+
import { Basic, createSchema } from "./src/create-schema.js";
|
|
6
|
+
import { NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs } from "./src/attr-constraints.js";
|
|
7
|
+
import { FIBERY_VIEW_TYPE, buildBlockIdAttrs, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr } from "./src/block-id-utils.js";
|
|
8
|
+
import { Node, Schema } from "prosemirror-model";
|
|
9
|
+
export { Basic, ColorToken, DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE, DEFAULT_VIDEO_HEIGHT, DEFAULT_VIDEO_WIDTH, FIBERY_VIEW_TYPE, NODE_ATTR_CONSTRAINTS, Node, Schema, buildBlockIdAttrs, createSchema, defaultHeight, defaultWidth, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr, validateAttrValue, validateAttrs };
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
//#region src/attr-constraints.d.ts
|
|
2
|
+
type AttrConstraintType = "string" | "number" | "integer" | "boolean" | "null";
|
|
3
|
+
type AttrConstraint = {
|
|
4
|
+
type?: ReadonlyArray<AttrConstraintType>;
|
|
5
|
+
enum?: ReadonlyArray<string | number | boolean | null>;
|
|
6
|
+
minimum?: number;
|
|
7
|
+
maximum?: number;
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
declare const NODE_ATTR_CONSTRAINTS: Record<string, Record<string, AttrConstraint>>;
|
|
10
|
+
declare const validateAttrValue: (nodeType: string, attr: string, value: unknown) => string | null;
|
|
11
|
+
type AttrValidationIssue = {
|
|
12
|
+
attr: string;
|
|
13
|
+
message: string;
|
|
13
14
|
};
|
|
14
|
-
|
|
15
|
+
declare const validateAttrs: (nodeType: string, attrs: Record<string, unknown>) => AttrValidationIssue[];
|
|
16
|
+
//#endregion
|
|
17
|
+
export { AttrConstraint, AttrConstraintType, AttrValidationIssue, NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs };
|
|
@@ -1,185 +1,145 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
title: { type: ["string", "null"] },
|
|
70
|
-
...resizableConstraints(),
|
|
71
|
-
},
|
|
72
|
-
fiberyView: {
|
|
73
|
-
...resizableConstraints(),
|
|
74
|
-
},
|
|
1
|
+
//#region src/attr-constraints.ts
|
|
2
|
+
const NODE_ATTR_CONSTRAINTS = {
|
|
3
|
+
heading: { level: {
|
|
4
|
+
type: ["integer"],
|
|
5
|
+
minimum: 1,
|
|
6
|
+
maximum: 6
|
|
7
|
+
} },
|
|
8
|
+
check_item: { state: { enum: ["TODO", "DONE"] } },
|
|
9
|
+
list_item: { state: { enum: [
|
|
10
|
+
"TODO",
|
|
11
|
+
"DONE",
|
|
12
|
+
null
|
|
13
|
+
] } },
|
|
14
|
+
code_block: {
|
|
15
|
+
language: { type: ["string", "null"] },
|
|
16
|
+
wrapCode: { type: ["boolean"] },
|
|
17
|
+
mode: { enum: [
|
|
18
|
+
"code",
|
|
19
|
+
"split",
|
|
20
|
+
"preview"
|
|
21
|
+
] },
|
|
22
|
+
...resizableConstraints()
|
|
23
|
+
},
|
|
24
|
+
callout: {
|
|
25
|
+
color: { type: ["string"] },
|
|
26
|
+
iconType: { type: ["string"] },
|
|
27
|
+
icon: { type: ["string"] }
|
|
28
|
+
},
|
|
29
|
+
ordered_list: { order: {
|
|
30
|
+
type: ["integer"],
|
|
31
|
+
minimum: 0
|
|
32
|
+
} },
|
|
33
|
+
column: { columnRatio: {
|
|
34
|
+
type: ["number"],
|
|
35
|
+
minimum: 0
|
|
36
|
+
} },
|
|
37
|
+
columns: { ...resizableConstraints() },
|
|
38
|
+
table_cell: cellConstraints(),
|
|
39
|
+
table_header: cellConstraints(),
|
|
40
|
+
media: {
|
|
41
|
+
url: { type: ["string"] },
|
|
42
|
+
compatibleMode: { type: ["boolean"] },
|
|
43
|
+
dynamicContent: { type: ["boolean"] },
|
|
44
|
+
aspectRatio: { type: ["number", "null"] },
|
|
45
|
+
...resizableConstraints()
|
|
46
|
+
},
|
|
47
|
+
video: {
|
|
48
|
+
src: { type: ["string"] },
|
|
49
|
+
type: { type: ["string"] },
|
|
50
|
+
width: {
|
|
51
|
+
type: ["number"],
|
|
52
|
+
minimum: 0
|
|
53
|
+
},
|
|
54
|
+
height: {
|
|
55
|
+
type: ["number"],
|
|
56
|
+
minimum: 0
|
|
57
|
+
},
|
|
58
|
+
title: { type: ["string"] },
|
|
59
|
+
alignment: { type: ["string"] },
|
|
60
|
+
...resizableConstraints()
|
|
61
|
+
},
|
|
62
|
+
imageBlock: {
|
|
63
|
+
src: { type: ["string"] },
|
|
64
|
+
alt: { type: ["string", "null"] },
|
|
65
|
+
title: { type: ["string", "null"] },
|
|
66
|
+
...resizableConstraints()
|
|
67
|
+
},
|
|
68
|
+
fiberyView: { ...resizableConstraints() }
|
|
75
69
|
};
|
|
76
|
-
// The resizable attr set (resizable-node-attrs.ts). parseDOM stores string or
|
|
77
|
-
// null values in legacy documents, but new writes must be numeric/boolean;
|
|
78
|
-
// null stays allowed as the editor's own "unset" value.
|
|
79
70
|
function resizableConstraints() {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
71
|
+
return {
|
|
72
|
+
nodeHeight: { type: ["number", "null"] },
|
|
73
|
+
nodeWidth: { type: ["number", "null"] },
|
|
74
|
+
nodePageWidth: { type: ["boolean", "null"] },
|
|
75
|
+
nodeFullWidth: { type: ["boolean", "null"] }
|
|
76
|
+
};
|
|
86
77
|
}
|
|
87
|
-
// prosemirror-tables cell attrs; colwidth (number[] | null) is out of scope
|
|
88
|
-
// of the scalar descriptor format and stays unconstrained.
|
|
89
78
|
function cellConstraints() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
79
|
+
return {
|
|
80
|
+
colspan: {
|
|
81
|
+
type: ["integer"],
|
|
82
|
+
minimum: 1
|
|
83
|
+
},
|
|
84
|
+
rowspan: {
|
|
85
|
+
type: ["integer"],
|
|
86
|
+
minimum: 1
|
|
87
|
+
},
|
|
88
|
+
background: { type: ["string", "null"] }
|
|
89
|
+
};
|
|
95
90
|
}
|
|
96
91
|
const matchesType = (type, value) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return typeof value === "number" && Number.isInteger(value);
|
|
106
|
-
case "null":
|
|
107
|
-
return value === null;
|
|
108
|
-
default:
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
92
|
+
switch (type) {
|
|
93
|
+
case "string": return typeof value === "string";
|
|
94
|
+
case "boolean": return typeof value === "boolean";
|
|
95
|
+
case "number": return typeof value === "number" && Number.isFinite(value);
|
|
96
|
+
case "integer": return typeof value === "number" && Number.isInteger(value);
|
|
97
|
+
case "null": return value === null;
|
|
98
|
+
default: return false;
|
|
99
|
+
}
|
|
111
100
|
};
|
|
112
101
|
const describeType = (type) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return "a boolean";
|
|
122
|
-
case "null":
|
|
123
|
-
return "null";
|
|
124
|
-
default:
|
|
125
|
-
return String(type);
|
|
126
|
-
}
|
|
102
|
+
switch (type) {
|
|
103
|
+
case "integer": return "an integer";
|
|
104
|
+
case "number": return "a number";
|
|
105
|
+
case "string": return "a string";
|
|
106
|
+
case "boolean": return "a boolean";
|
|
107
|
+
case "null": return "null";
|
|
108
|
+
default: return String(type);
|
|
109
|
+
}
|
|
127
110
|
};
|
|
128
111
|
const describeExpectation = (constraint) => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
if (constraint.minimum !== undefined) {
|
|
137
|
-
return `${types} of at least ${constraint.minimum}`;
|
|
138
|
-
}
|
|
139
|
-
if (constraint.maximum !== undefined) {
|
|
140
|
-
return `${types} of at most ${constraint.maximum}`;
|
|
141
|
-
}
|
|
142
|
-
return types;
|
|
112
|
+
if (constraint.enum !== void 0) return `one of [${constraint.enum.map((v) => JSON.stringify(v)).join(", ")}]`;
|
|
113
|
+
const types = (constraint.type ?? []).map(describeType).join(" or ");
|
|
114
|
+
if (constraint.minimum !== void 0 && constraint.maximum !== void 0) return `${types} between ${constraint.minimum} and ${constraint.maximum}`;
|
|
115
|
+
if (constraint.minimum !== void 0) return `${types} of at least ${constraint.minimum}`;
|
|
116
|
+
if (constraint.maximum !== void 0) return `${types} of at most ${constraint.maximum}`;
|
|
117
|
+
return types;
|
|
143
118
|
};
|
|
144
119
|
const checkConstraint = (constraint, value) => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (constraint.minimum !== undefined && value < constraint.minimum) {
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
if (constraint.maximum !== undefined && value > constraint.maximum) {
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return true;
|
|
120
|
+
if (constraint.enum !== void 0) return constraint.enum.includes(value);
|
|
121
|
+
if (constraint.type !== void 0 && !constraint.type.some((type) => matchesType(type, value))) return false;
|
|
122
|
+
if (typeof value === "number") {
|
|
123
|
+
if (constraint.minimum !== void 0 && value < constraint.minimum) return false;
|
|
124
|
+
if (constraint.maximum !== void 0 && value > constraint.maximum) return false;
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
160
127
|
};
|
|
161
|
-
// null = valid (or unconstrained); otherwise a message like
|
|
162
|
-
// "must be an integer between 1 and 6, got [\"banana\"]" — the caller
|
|
163
|
-
// prefixes it with the node type and attr name.
|
|
164
128
|
const validateAttrValue = (nodeType, attr, value) => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
return `must be ${describeExpectation(constraint)}, got [${JSON.stringify(value)}]`;
|
|
129
|
+
const constraint = NODE_ATTR_CONSTRAINTS[nodeType]?.[attr];
|
|
130
|
+
if (constraint === void 0 || checkConstraint(constraint, value)) return null;
|
|
131
|
+
return `must be ${describeExpectation(constraint)}, got [${JSON.stringify(value)}]`;
|
|
170
132
|
};
|
|
171
|
-
exports.validateAttrValue = validateAttrValue;
|
|
172
|
-
// Validates exactly the keys present in `attrs` — defaults and values already
|
|
173
|
-
// stored in a document are never re-checked, so documents with legacy-invalid
|
|
174
|
-
// attrs keep loading and stay editable on other keys.
|
|
175
133
|
const validateAttrs = (nodeType, attrs) => {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
134
|
+
const issues = [];
|
|
135
|
+
for (const [attr, value] of Object.entries(attrs)) {
|
|
136
|
+
const message = validateAttrValue(nodeType, attr, value);
|
|
137
|
+
if (message !== null) issues.push({
|
|
138
|
+
attr,
|
|
139
|
+
message
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return issues;
|
|
184
143
|
};
|
|
185
|
-
|
|
144
|
+
//#endregion
|
|
145
|
+
export { NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { Node, NodeType } from "prosemirror-model";
|
|
2
|
+
//#region src/block-id-utils.d.ts
|
|
3
|
+
declare const getBlockIdAttr: (type: NodeType) => "id" | null;
|
|
4
|
+
declare const hasLegacyGuidAttr: (type: NodeType) => boolean;
|
|
5
|
+
declare const getBlockId: (node: Node) => string | null;
|
|
6
|
+
declare const buildBlockIdAttrs: (node: Node, nextId: string) => Record<string, unknown>;
|
|
7
|
+
declare const FIBERY_VIEW_TYPE = "fiberyView";
|
|
8
|
+
declare const getFiberyViewRef: (node: Node) => string | null;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { FIBERY_VIEW_TYPE, buildBlockIdAttrs, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr };
|
|
@@ -1,49 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getFiberyViewRef = exports.FIBERY_VIEW_TYPE = exports.buildBlockIdAttrs = exports.getBlockId = exports.hasLegacyGuidAttr = exports.getBlockIdAttr = void 0;
|
|
4
|
-
// Node types whose "id" attr references another entity rather than
|
|
5
|
-
// identifying the block itself — never generate or rewrite these ids.
|
|
6
|
-
const REFERENCE_ID_TYPES = new Set(["fiberyView"]);
|
|
7
|
-
// Returns the block-identifier attr of a node type, or null when the type
|
|
8
|
-
// carries no block id (inline nodes, the doc itself, reference ids).
|
|
1
|
+
//#region src/block-id-utils.ts
|
|
2
|
+
const REFERENCE_ID_TYPES = /* @__PURE__ */ new Set(["fiberyView"]);
|
|
9
3
|
const getBlockIdAttr = (type) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
const attrs = type.spec.attrs ?? {};
|
|
14
|
-
return "id" in attrs ? "id" : null;
|
|
4
|
+
if (type.isInline || type.name === "doc" || REFERENCE_ID_TYPES.has(type.name)) return null;
|
|
5
|
+
return "id" in (type.spec.attrs ?? {}) ? "id" : null;
|
|
15
6
|
};
|
|
16
|
-
exports.getBlockIdAttr = getBlockIdAttr;
|
|
17
|
-
// paragraph/heading/code_block keep the deprecated "guid" attr mirrored to
|
|
18
|
-
// "id" until all consumers (references, highlights) read "id".
|
|
19
7
|
const hasLegacyGuidAttr = (type) => {
|
|
20
|
-
|
|
21
|
-
return "guid" in attrs;
|
|
8
|
+
return "guid" in (type.spec.attrs ?? {});
|
|
22
9
|
};
|
|
23
|
-
|
|
24
|
-
const normalizeId = (value) => (typeof value === "string" && value !== "" ? value : null);
|
|
25
|
-
// The effective block id: "id" with a fallback to the legacy "guid".
|
|
10
|
+
const normalizeId = (value) => typeof value === "string" && value !== "" ? value : null;
|
|
26
11
|
const getBlockId = (node) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
return normalizeId(node.attrs.id) ?? normalizeId(node.attrs.guid);
|
|
12
|
+
if (getBlockIdAttr(node.type) === null) return null;
|
|
13
|
+
return normalizeId(node.attrs.id) ?? normalizeId(node.attrs.guid);
|
|
31
14
|
};
|
|
32
|
-
exports.getBlockId = getBlockId;
|
|
33
|
-
// Attrs object with the block id set (and mirrored into "guid" on legacy types).
|
|
34
15
|
const buildBlockIdAttrs = (node, nextId) => ({
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
16
|
+
...node.attrs,
|
|
17
|
+
id: nextId,
|
|
18
|
+
...hasLegacyGuidAttr(node.type) ? { guid: nextId } : {}
|
|
38
19
|
});
|
|
39
|
-
|
|
40
|
-
exports.FIBERY_VIEW_TYPE = "fiberyView";
|
|
41
|
-
// The embedded view entity reference of a fiberyView node: "viewId" with a
|
|
42
|
-
// fallback to the deprecated "id" (documents saved before "viewId" existed).
|
|
20
|
+
const FIBERY_VIEW_TYPE = "fiberyView";
|
|
43
21
|
const getFiberyViewRef = (node) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
return normalizeId(node.attrs.viewId) ?? normalizeId(node.attrs.id);
|
|
22
|
+
if (node.type.name !== "fiberyView") return null;
|
|
23
|
+
return normalizeId(node.attrs.viewId) ?? normalizeId(node.attrs.id);
|
|
48
24
|
};
|
|
49
|
-
|
|
25
|
+
//#endregion
|
|
26
|
+
export { FIBERY_VIEW_TYPE, buildBlockIdAttrs, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr };
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { EmojiOptions } from "./nodes/emoji.js";
|
|
2
|
+
import { MarkSpec, Node, NodeSpec, Schema } from "prosemirror-model";
|
|
3
|
+
//#region src/create-schema.d.ts
|
|
4
4
|
type Params = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
isImageBlockEnabled?: boolean;
|
|
6
|
+
fiberyViewEnabled?: boolean;
|
|
7
|
+
sharedColorGenerator?: any;
|
|
8
|
+
headingToDOM?: ((node: Node) => HTMLElement) | null;
|
|
9
|
+
mediaToDom?: ((node: Node) => HTMLElement) | null;
|
|
10
|
+
emojiOptions?: EmojiOptions;
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
declare const createSchema: ({ sharedColorGenerator, headingToDOM, mediaToDom, isImageBlockEnabled, fiberyViewEnabled, emojiOptions }?: Params) => Schema;
|
|
13
|
+
declare const Basic: {
|
|
14
|
+
nodes: Record<string, NodeSpec>;
|
|
15
|
+
marks: Record<string, MarkSpec>;
|
|
16
|
+
fibery: Record<string, MarkSpec>;
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Basic, createSchema };
|