@fibery/prosemirror-schema 4.23.1 → 4.24.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/lib/attr-constraints.d.ts +5 -2
- package/lib/attr-constraints.js +48 -5
- package/lib/create-schema.js +24 -3
- package/lib/index.d.ts +4 -3
- package/lib/index.js +4 -3
- package/lib/marks/suggestions.d.ts +14 -0
- package/lib/marks/suggestions.js +179 -0
- package/lib/marks/text-background-color.d.ts +3 -1
- package/lib/marks/text-background-color.js +3 -2
- package/lib/nodes/table-nodes.js +10 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/attr-constraints.d.ts
|
|
2
|
-
type AttrConstraintType = "string" | "number" | "integer" | "boolean" | "null";
|
|
2
|
+
type AttrConstraintType = "string" | "number" | "integer" | "boolean" | "null" | "stringMap";
|
|
3
3
|
type AttrConstraint = {
|
|
4
4
|
type?: ReadonlyArray<AttrConstraintType>;
|
|
5
5
|
enum?: ReadonlyArray<string | number | boolean | null>;
|
|
@@ -7,11 +7,14 @@ type AttrConstraint = {
|
|
|
7
7
|
maximum?: number;
|
|
8
8
|
};
|
|
9
9
|
declare const NODE_ATTR_CONSTRAINTS: Record<string, Record<string, AttrConstraint>>;
|
|
10
|
+
declare const MARK_ATTR_CONSTRAINTS: Record<string, Record<string, AttrConstraint>>;
|
|
10
11
|
declare const validateAttrValue: (nodeType: string, attr: string, value: unknown) => string | null;
|
|
12
|
+
declare const validateMarkAttrValue: (markType: string, attr: string, value: unknown) => string | null;
|
|
11
13
|
type AttrValidationIssue = {
|
|
12
14
|
attr: string;
|
|
13
15
|
message: string;
|
|
14
16
|
};
|
|
15
17
|
declare const validateAttrs: (nodeType: string, attrs: Record<string, unknown>) => AttrValidationIssue[];
|
|
18
|
+
declare const validateMarkAttrs: (markType: string, attrs: Record<string, unknown>) => AttrValidationIssue[];
|
|
16
19
|
//#endregion
|
|
17
|
-
export { AttrConstraint, AttrConstraintType, AttrValidationIssue, NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs };
|
|
20
|
+
export { AttrConstraint, AttrConstraintType, AttrValidationIssue, MARK_ATTR_CONSTRAINTS, NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs, validateMarkAttrValue, validateMarkAttrs };
|
package/lib/attr-constraints.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SUGGESTION_MARK_NAMES } from "./marks/suggestions.js";
|
|
2
|
+
import { ColorToken } from "./marks/text-background-color.js";
|
|
1
3
|
//#region src/attr-constraints.ts
|
|
2
4
|
const NODE_ATTR_CONSTRAINTS = {
|
|
3
5
|
heading: { level: {
|
|
@@ -67,6 +69,41 @@ const NODE_ATTR_CONSTRAINTS = {
|
|
|
67
69
|
},
|
|
68
70
|
fiberyView: { ...resizableConstraints() }
|
|
69
71
|
};
|
|
72
|
+
const MARK_ATTR_CONSTRAINTS = {
|
|
73
|
+
highlight: {
|
|
74
|
+
bgColor: { enum: Object.values(ColorToken) },
|
|
75
|
+
fgColor: { enum: Object.values(ColorToken) }
|
|
76
|
+
},
|
|
77
|
+
...Object.fromEntries(SUGGESTION_MARK_NAMES.map((name) => [name, suggestionConstraints(name)]))
|
|
78
|
+
};
|
|
79
|
+
function suggestionConstraints(markName) {
|
|
80
|
+
const common = {
|
|
81
|
+
id: { type: markName === "blockBoundarySuggestion" ? ["string", "null"] : ["string"] },
|
|
82
|
+
authorId: { type: ["string", "null"] },
|
|
83
|
+
createdAt: { type: ["number", "null"] },
|
|
84
|
+
baggage: { type: ["stringMap", "null"] }
|
|
85
|
+
};
|
|
86
|
+
switch (markName) {
|
|
87
|
+
case "modification": return {
|
|
88
|
+
...common,
|
|
89
|
+
type: { enum: [
|
|
90
|
+
"attr",
|
|
91
|
+
"mark",
|
|
92
|
+
"nodeType"
|
|
93
|
+
] },
|
|
94
|
+
attrName: { type: ["string", "null"] }
|
|
95
|
+
};
|
|
96
|
+
case "blockBoundarySuggestion": return {
|
|
97
|
+
...common,
|
|
98
|
+
type: { enum: [
|
|
99
|
+
"insertion",
|
|
100
|
+
"deletion",
|
|
101
|
+
null
|
|
102
|
+
] }
|
|
103
|
+
};
|
|
104
|
+
default: return common;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
70
107
|
function resizableConstraints() {
|
|
71
108
|
return {
|
|
72
109
|
nodeHeight: { type: ["number", "null"] },
|
|
@@ -95,6 +132,7 @@ const matchesType = (type, value) => {
|
|
|
95
132
|
case "number": return typeof value === "number" && Number.isFinite(value);
|
|
96
133
|
case "integer": return typeof value === "number" && Number.isInteger(value);
|
|
97
134
|
case "null": return value === null;
|
|
135
|
+
case "stringMap": return typeof value === "object" && value !== null && !Array.isArray(value) && Object.values(value).every((member) => typeof member === "string");
|
|
98
136
|
default: return false;
|
|
99
137
|
}
|
|
100
138
|
};
|
|
@@ -105,6 +143,7 @@ const describeType = (type) => {
|
|
|
105
143
|
case "string": return "a string";
|
|
106
144
|
case "boolean": return "a boolean";
|
|
107
145
|
case "null": return "null";
|
|
146
|
+
case "stringMap": return "an object with string values";
|
|
108
147
|
default: return String(type);
|
|
109
148
|
}
|
|
110
149
|
};
|
|
@@ -125,15 +164,17 @@ const checkConstraint = (constraint, value) => {
|
|
|
125
164
|
}
|
|
126
165
|
return true;
|
|
127
166
|
};
|
|
128
|
-
const
|
|
129
|
-
const constraint =
|
|
167
|
+
const validateValue = (table, typeName, attr, value) => {
|
|
168
|
+
const constraint = table[typeName]?.[attr];
|
|
130
169
|
if (constraint === void 0 || checkConstraint(constraint, value)) return null;
|
|
131
170
|
return `must be ${describeExpectation(constraint)}, got [${JSON.stringify(value)}]`;
|
|
132
171
|
};
|
|
133
|
-
const
|
|
172
|
+
const validateAttrValue = (nodeType, attr, value) => validateValue(NODE_ATTR_CONSTRAINTS, nodeType, attr, value);
|
|
173
|
+
const validateMarkAttrValue = (markType, attr, value) => validateValue(MARK_ATTR_CONSTRAINTS, markType, attr, value);
|
|
174
|
+
const validateEntries = (table, typeName, attrs) => {
|
|
134
175
|
const issues = [];
|
|
135
176
|
for (const [attr, value] of Object.entries(attrs)) {
|
|
136
|
-
const message =
|
|
177
|
+
const message = validateValue(table, typeName, attr, value);
|
|
137
178
|
if (message !== null) issues.push({
|
|
138
179
|
attr,
|
|
139
180
|
message
|
|
@@ -141,5 +182,7 @@ const validateAttrs = (nodeType, attrs) => {
|
|
|
141
182
|
}
|
|
142
183
|
return issues;
|
|
143
184
|
};
|
|
185
|
+
const validateAttrs = (nodeType, attrs) => validateEntries(NODE_ATTR_CONSTRAINTS, nodeType, attrs);
|
|
186
|
+
const validateMarkAttrs = (markType, attrs) => validateEntries(MARK_ATTR_CONSTRAINTS, markType, attrs);
|
|
144
187
|
//#endregion
|
|
145
|
-
export { NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs };
|
|
188
|
+
export { MARK_ATTR_CONSTRAINTS, NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs, validateMarkAttrValue, validateMarkAttrs };
|
package/lib/create-schema.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { INLINE_SUGGESTION_MARK_NAMES, SUGGESTION_MARK_NAMES, blockBoundarySuggestion, deletion, insertion, modification } from "./marks/suggestions.js";
|
|
2
|
+
import { textBackgroundColor } from "./marks/text-background-color.js";
|
|
1
3
|
import { code } from "./marks/code.js";
|
|
2
4
|
import { em } from "./marks/em.js";
|
|
3
5
|
import { hintQuery } from "./marks/hint-query.js";
|
|
@@ -5,7 +7,6 @@ import { link } from "./marks/link.js";
|
|
|
5
7
|
import { makeLinkedHighlight, makeLinkedHighlightEntity } from "./marks/linked-highlight.js";
|
|
6
8
|
import { strike } from "./marks/strike.js";
|
|
7
9
|
import { strong } from "./marks/strong.js";
|
|
8
|
-
import { textBackgroundColor } from "./marks/text-background-color.js";
|
|
9
10
|
import { underline } from "./marks/underline.js";
|
|
10
11
|
import { makeCallout } from "./nodes/callout.js";
|
|
11
12
|
import { check_item } from "./nodes/check-item.js";
|
|
@@ -32,6 +33,25 @@ import { Schema } from "prosemirror-model";
|
|
|
32
33
|
import { marks, nodes } from "prosemirror-schema-basic";
|
|
33
34
|
import { addListNodes } from "prosemirror-schema-list";
|
|
34
35
|
//#region src/create-schema.ts
|
|
36
|
+
const allowSuggestionMarks = (nodes, marks) => {
|
|
37
|
+
const probe = new Schema({
|
|
38
|
+
nodes,
|
|
39
|
+
marks
|
|
40
|
+
});
|
|
41
|
+
let result = nodes;
|
|
42
|
+
for (const type of Object.values(probe.nodes)) {
|
|
43
|
+
if (type.isInline || type.isLeaf || type.spec.marks === "_") continue;
|
|
44
|
+
if (type.inlineContent && type.spec.marks === void 0) continue;
|
|
45
|
+
const allowed = type.inlineContent ? INLINE_SUGGESTION_MARK_NAMES : SUGGESTION_MARK_NAMES;
|
|
46
|
+
const existing = type.spec.marks?.split(" ").filter(Boolean) ?? [];
|
|
47
|
+
const merged = [.../* @__PURE__ */ new Set([...existing, ...allowed])].join(" ");
|
|
48
|
+
result = result.update(type.name, {
|
|
49
|
+
...type.spec,
|
|
50
|
+
marks: merged
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
35
55
|
const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaToDom = null, isImageBlockEnabled = false, fiberyViewEnabled = false, emojiOptions } = {}) => {
|
|
36
56
|
nodes.code_block = code_block;
|
|
37
57
|
nodes.paragraph = paragraph;
|
|
@@ -187,9 +207,10 @@ const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaT
|
|
|
187
207
|
}
|
|
188
208
|
});
|
|
189
209
|
}
|
|
210
|
+
const marks = base.spec.marks.addToEnd("strike", strike).addToEnd("underline", underline).addToEnd("hintQuery", hintQuery).addToEnd("highlight", textBackgroundColor).addToEnd("insertion", insertion).addToEnd("deletion", deletion).addToEnd("modification", modification).addToEnd("blockBoundarySuggestion", blockBoundarySuggestion);
|
|
190
211
|
return new Schema({
|
|
191
|
-
nodes: actualNodes,
|
|
192
|
-
marks
|
|
212
|
+
nodes: allowSuggestionMarks(actualNodes, marks),
|
|
213
|
+
marks
|
|
193
214
|
});
|
|
194
215
|
};
|
|
195
216
|
const Basic = {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { AttrConstraint, AttrConstraintType, AttrValidationIssue, NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs } from "./attr-constraints.js";
|
|
1
|
+
import { AttrConstraint, AttrConstraintType, AttrValidationIssue, MARK_ATTR_CONSTRAINTS, NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs, validateMarkAttrValue, validateMarkAttrs } from "./attr-constraints.js";
|
|
2
2
|
import { FIBERY_VIEW_TYPE, buildBlockIdAttrs, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr } from "./block-id-utils.js";
|
|
3
3
|
import { EmojiOptions } from "./nodes/emoji.js";
|
|
4
4
|
import { Basic, createSchema } from "./create-schema.js";
|
|
5
5
|
import { defaultHeight, defaultWidth } from "./resizable-node-attrs.js";
|
|
6
6
|
import { DEFAULT_VIDEO_HEIGHT, DEFAULT_VIDEO_WIDTH } from "./nodes/video.js";
|
|
7
7
|
import { DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE } from "./nodes/callout.js";
|
|
8
|
-
import { ColorToken } from "./marks/text-background-color.js";
|
|
8
|
+
import { ColorToken, isColorToken, validateColorToken } from "./marks/text-background-color.js";
|
|
9
|
+
import { INLINE_SUGGESTION_MARK_NAMES, SUGGESTION_MARKS_EXPR, SUGGESTION_MARK_NAMES, SuggestionBaggage, SuggestionMarkName, isSuggestionBaggage } from "./marks/suggestions.js";
|
|
9
10
|
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 };
|
|
11
|
+
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, INLINE_SUGGESTION_MARK_NAMES, MARK_ATTR_CONSTRAINTS, NODE_ATTR_CONSTRAINTS, Node, SUGGESTION_MARKS_EXPR, SUGGESTION_MARK_NAMES, Schema, type SuggestionBaggage, type SuggestionMarkName, buildBlockIdAttrs, createSchema, defaultHeight, defaultWidth, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr, isColorToken, isSuggestionBaggage, validateAttrValue, validateAttrs, validateColorToken, validateMarkAttrValue, validateMarkAttrs };
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INLINE_SUGGESTION_MARK_NAMES, SUGGESTION_MARKS_EXPR, SUGGESTION_MARK_NAMES, isSuggestionBaggage } from "./marks/suggestions.js";
|
|
2
|
+
import { ColorToken, isColorToken, validateColorToken } from "./marks/text-background-color.js";
|
|
3
|
+
import { MARK_ATTR_CONSTRAINTS, NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs, validateMarkAttrValue, validateMarkAttrs } from "./attr-constraints.js";
|
|
2
4
|
import { FIBERY_VIEW_TYPE, buildBlockIdAttrs, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr } from "./block-id-utils.js";
|
|
3
|
-
import { ColorToken } from "./marks/text-background-color.js";
|
|
4
5
|
import { DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE } from "./nodes/callout.js";
|
|
5
6
|
import { defaultHeight, defaultWidth } from "./resizable-node-attrs.js";
|
|
6
7
|
import { DEFAULT_VIDEO_HEIGHT, DEFAULT_VIDEO_WIDTH } from "./nodes/video.js";
|
|
7
8
|
import { Basic, createSchema } from "./create-schema.js";
|
|
8
9
|
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 };
|
|
10
|
+
export { Basic, ColorToken, DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE, DEFAULT_VIDEO_HEIGHT, DEFAULT_VIDEO_WIDTH, FIBERY_VIEW_TYPE, INLINE_SUGGESTION_MARK_NAMES, MARK_ATTR_CONSTRAINTS, NODE_ATTR_CONSTRAINTS, Node, SUGGESTION_MARKS_EXPR, SUGGESTION_MARK_NAMES, Schema, buildBlockIdAttrs, createSchema, defaultHeight, defaultWidth, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr, isColorToken, isSuggestionBaggage, validateAttrValue, validateAttrs, validateColorToken, validateMarkAttrValue, validateMarkAttrs };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MarkSpec } from "prosemirror-model";
|
|
2
|
+
//#region src/marks/suggestions.d.ts
|
|
3
|
+
declare const SUGGESTION_MARK_NAMES: readonly ["insertion", "deletion", "modification", "blockBoundarySuggestion"];
|
|
4
|
+
type SuggestionMarkName = (typeof SUGGESTION_MARK_NAMES)[number];
|
|
5
|
+
declare const SUGGESTION_MARKS_EXPR: string;
|
|
6
|
+
declare const INLINE_SUGGESTION_MARK_NAMES: readonly ["insertion", "deletion"];
|
|
7
|
+
type SuggestionBaggage = Record<string, string>;
|
|
8
|
+
declare const isSuggestionBaggage: (value: unknown) => value is SuggestionBaggage;
|
|
9
|
+
declare const insertion: MarkSpec;
|
|
10
|
+
declare const deletion: MarkSpec;
|
|
11
|
+
declare const modification: MarkSpec;
|
|
12
|
+
declare const blockBoundarySuggestion: MarkSpec;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { INLINE_SUGGESTION_MARK_NAMES, SUGGESTION_MARKS_EXPR, SUGGESTION_MARK_NAMES, SuggestionBaggage, SuggestionMarkName, blockBoundarySuggestion, deletion, insertion, isSuggestionBaggage, modification };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
//#region src/marks/suggestions.ts
|
|
2
|
+
const SUGGESTION_MARK_NAMES = [
|
|
3
|
+
"insertion",
|
|
4
|
+
"deletion",
|
|
5
|
+
"modification",
|
|
6
|
+
"blockBoundarySuggestion"
|
|
7
|
+
];
|
|
8
|
+
const SUGGESTION_MARKS_EXPR = SUGGESTION_MARK_NAMES.join(" ");
|
|
9
|
+
const INLINE_SUGGESTION_MARK_NAMES = ["insertion", "deletion"];
|
|
10
|
+
const isSuggestionBaggage = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && Object.values(value).every((member) => typeof member === "string");
|
|
11
|
+
const validateBaggage = (value) => {
|
|
12
|
+
if (value !== null && !isSuggestionBaggage(value)) throw new RangeError("Suggestion baggage must be null or an object with string values");
|
|
13
|
+
};
|
|
14
|
+
const commonAttrs = () => ({
|
|
15
|
+
id: { validate: "string" },
|
|
16
|
+
authorId: {
|
|
17
|
+
default: null,
|
|
18
|
+
validate: "string|null"
|
|
19
|
+
},
|
|
20
|
+
createdAt: {
|
|
21
|
+
default: null,
|
|
22
|
+
validate: "number|null"
|
|
23
|
+
},
|
|
24
|
+
baggage: {
|
|
25
|
+
default: null,
|
|
26
|
+
validate: validateBaggage
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const suggestionDomAttrs = (mark) => {
|
|
30
|
+
const attrs = {};
|
|
31
|
+
if (mark.attrs.id !== null) attrs["data-id"] = String(mark.attrs.id);
|
|
32
|
+
if (mark.attrs.authorId !== null) attrs["data-author-id"] = String(mark.attrs.authorId);
|
|
33
|
+
if (mark.attrs.createdAt !== null) attrs["data-created-at"] = String(mark.attrs.createdAt);
|
|
34
|
+
if (mark.attrs.baggage !== null) attrs["data-baggage"] = JSON.stringify(mark.attrs.baggage);
|
|
35
|
+
return attrs;
|
|
36
|
+
};
|
|
37
|
+
const parseJSON = (raw) => {
|
|
38
|
+
if (raw === null) return null;
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(raw);
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const parseCommonAttrs = (dom) => {
|
|
46
|
+
const createdAtRaw = dom.getAttribute("data-created-at");
|
|
47
|
+
const createdAt = createdAtRaw === null ? null : Number(createdAtRaw);
|
|
48
|
+
const baggage = parseJSON(dom.getAttribute("data-baggage"));
|
|
49
|
+
return {
|
|
50
|
+
authorId: dom.getAttribute("data-author-id"),
|
|
51
|
+
createdAt: createdAt !== null && Number.isFinite(createdAt) ? createdAt : null,
|
|
52
|
+
baggage: isSuggestionBaggage(baggage) ? baggage : null
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const getSuggestionAttrs = (dom) => {
|
|
56
|
+
const id = dom.getAttribute("data-id");
|
|
57
|
+
if (!id) return false;
|
|
58
|
+
return {
|
|
59
|
+
id,
|
|
60
|
+
...parseCommonAttrs(dom)
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
const insertion = {
|
|
64
|
+
inclusive: false,
|
|
65
|
+
excludes: "insertion deletion modification",
|
|
66
|
+
attrs: commonAttrs(),
|
|
67
|
+
toDOM: (mark, inline) => [
|
|
68
|
+
"ins",
|
|
69
|
+
{
|
|
70
|
+
...suggestionDomAttrs(mark),
|
|
71
|
+
"data-inline": String(inline)
|
|
72
|
+
},
|
|
73
|
+
0
|
|
74
|
+
],
|
|
75
|
+
parseDOM: [{
|
|
76
|
+
tag: "ins[data-id]",
|
|
77
|
+
getAttrs: getSuggestionAttrs
|
|
78
|
+
}]
|
|
79
|
+
};
|
|
80
|
+
const deletion = {
|
|
81
|
+
inclusive: false,
|
|
82
|
+
excludes: "deletion insertion modification",
|
|
83
|
+
attrs: commonAttrs(),
|
|
84
|
+
toDOM: (mark, inline) => [
|
|
85
|
+
"del",
|
|
86
|
+
{
|
|
87
|
+
...suggestionDomAttrs(mark),
|
|
88
|
+
"data-inline": String(inline)
|
|
89
|
+
},
|
|
90
|
+
0
|
|
91
|
+
],
|
|
92
|
+
parseDOM: [{
|
|
93
|
+
tag: "del[data-id]",
|
|
94
|
+
getAttrs: getSuggestionAttrs
|
|
95
|
+
}]
|
|
96
|
+
};
|
|
97
|
+
const getModificationAttrs = (dom) => {
|
|
98
|
+
const id = dom.getAttribute("data-id");
|
|
99
|
+
const type = dom.getAttribute("data-mod-type");
|
|
100
|
+
if (!id || !type) return false;
|
|
101
|
+
return {
|
|
102
|
+
id,
|
|
103
|
+
type,
|
|
104
|
+
attrName: dom.getAttribute("data-mod-attr-name"),
|
|
105
|
+
previousValue: parseJSON(dom.getAttribute("data-mod-prev-val")),
|
|
106
|
+
newValue: parseJSON(dom.getAttribute("data-mod-new-val")),
|
|
107
|
+
...parseCommonAttrs(dom)
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
const modification = {
|
|
111
|
+
inclusive: false,
|
|
112
|
+
excludes: "deletion insertion",
|
|
113
|
+
attrs: {
|
|
114
|
+
...commonAttrs(),
|
|
115
|
+
type: { validate: "string" },
|
|
116
|
+
attrName: {
|
|
117
|
+
default: null,
|
|
118
|
+
validate: "string|null"
|
|
119
|
+
},
|
|
120
|
+
previousValue: { default: null },
|
|
121
|
+
newValue: { default: null }
|
|
122
|
+
},
|
|
123
|
+
toDOM: (mark, inline) => [
|
|
124
|
+
inline ? "span" : "div",
|
|
125
|
+
{
|
|
126
|
+
"data-type": "modification",
|
|
127
|
+
...suggestionDomAttrs(mark),
|
|
128
|
+
"data-mod-type": String(mark.attrs.type),
|
|
129
|
+
...mark.attrs.attrName !== null ? { "data-mod-attr-name": String(mark.attrs.attrName) } : {},
|
|
130
|
+
"data-mod-prev-val": JSON.stringify(mark.attrs.previousValue ?? null),
|
|
131
|
+
"data-mod-new-val": JSON.stringify(mark.attrs.newValue ?? null)
|
|
132
|
+
},
|
|
133
|
+
0
|
|
134
|
+
],
|
|
135
|
+
parseDOM: [{
|
|
136
|
+
tag: "span[data-type='modification']",
|
|
137
|
+
getAttrs: getModificationAttrs
|
|
138
|
+
}, {
|
|
139
|
+
tag: "div[data-type='modification']",
|
|
140
|
+
getAttrs: getModificationAttrs
|
|
141
|
+
}]
|
|
142
|
+
};
|
|
143
|
+
const getBoundaryAttrs = (dom) => ({
|
|
144
|
+
id: dom.getAttribute("data-id"),
|
|
145
|
+
type: dom.getAttribute("data-change-type"),
|
|
146
|
+
...parseCommonAttrs(dom)
|
|
147
|
+
});
|
|
148
|
+
const blockBoundarySuggestion = {
|
|
149
|
+
inclusive: false,
|
|
150
|
+
attrs: {
|
|
151
|
+
...commonAttrs(),
|
|
152
|
+
id: {
|
|
153
|
+
default: null,
|
|
154
|
+
validate: "string|null"
|
|
155
|
+
},
|
|
156
|
+
type: {
|
|
157
|
+
default: null,
|
|
158
|
+
validate: "string|null"
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
toDOM: (mark, inline) => [
|
|
162
|
+
inline ? "span" : "div",
|
|
163
|
+
{
|
|
164
|
+
"data-type": "block-boundary-suggestion",
|
|
165
|
+
...suggestionDomAttrs(mark),
|
|
166
|
+
...mark.attrs.type !== null ? { "data-change-type": String(mark.attrs.type) } : {}
|
|
167
|
+
},
|
|
168
|
+
0
|
|
169
|
+
],
|
|
170
|
+
parseDOM: [{
|
|
171
|
+
tag: "span[data-type='block-boundary-suggestion']",
|
|
172
|
+
getAttrs: getBoundaryAttrs
|
|
173
|
+
}, {
|
|
174
|
+
tag: "div[data-type='block-boundary-suggestion']",
|
|
175
|
+
getAttrs: getBoundaryAttrs
|
|
176
|
+
}]
|
|
177
|
+
};
|
|
178
|
+
//#endregion
|
|
179
|
+
export { INLINE_SUGGESTION_MARK_NAMES, SUGGESTION_MARKS_EXPR, SUGGESTION_MARK_NAMES, blockBoundarySuggestion, deletion, insertion, isSuggestionBaggage, modification };
|
|
@@ -11,6 +11,8 @@ declare enum ColorToken {
|
|
|
11
11
|
Red = "RED",
|
|
12
12
|
Grey = "GREY"
|
|
13
13
|
}
|
|
14
|
+
declare const isColorToken: (text: string) => text is ColorToken;
|
|
15
|
+
declare const validateColorToken: (color: string | undefined) => ColorToken | undefined;
|
|
14
16
|
declare const textBackgroundColor: MarkSpec;
|
|
15
17
|
//#endregion
|
|
16
|
-
export { ColorToken, textBackgroundColor };
|
|
18
|
+
export { ColorToken, isColorToken, textBackgroundColor, validateColorToken };
|
|
@@ -24,7 +24,8 @@ const persistedRawColorToColorTokenLookup = {
|
|
|
24
24
|
["#f1ebfe"]: "PURPLE",
|
|
25
25
|
["#fce7fb"]: "PINK",
|
|
26
26
|
["#fce9e9"]: "RED",
|
|
27
|
-
["#e7e9eb"]: "GREY"
|
|
27
|
+
["#e7e9eb"]: "GREY",
|
|
28
|
+
["var(--actionMenuHover)"]: "GREY"
|
|
28
29
|
};
|
|
29
30
|
const validateColorToken = (color) => {
|
|
30
31
|
if (!color) return;
|
|
@@ -69,4 +70,4 @@ const textBackgroundColor = {
|
|
|
69
70
|
}
|
|
70
71
|
};
|
|
71
72
|
//#endregion
|
|
72
|
-
export { ColorToken, textBackgroundColor };
|
|
73
|
+
export { ColorToken, isColorToken, textBackgroundColor, validateColorToken };
|
package/lib/nodes/table-nodes.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateColorToken } from "../marks/text-background-color.js";
|
|
1
2
|
import { tableNodes as tableNodes$1 } from "prosemirror-tables";
|
|
2
3
|
//#region src/nodes/table-nodes.ts
|
|
3
4
|
const tableNodes = tableNodes$1({
|
|
@@ -6,10 +7,17 @@ const tableNodes = tableNodes$1({
|
|
|
6
7
|
cellAttributes: { background: {
|
|
7
8
|
default: null,
|
|
8
9
|
getFromDOM(dom) {
|
|
9
|
-
|
|
10
|
+
const el = dom;
|
|
11
|
+
const raw = el.getAttribute("data-cell-bg") || el.style.backgroundColor || null;
|
|
12
|
+
return raw ? validateColorToken(raw) ?? raw : null;
|
|
10
13
|
},
|
|
11
14
|
setDOMAttr(value, attrs) {
|
|
12
|
-
if (value)
|
|
15
|
+
if (!value) return;
|
|
16
|
+
const token = typeof value === "string" ? validateColorToken(value) : void 0;
|
|
17
|
+
if (token) {
|
|
18
|
+
attrs["data-cell-bg"] = token;
|
|
19
|
+
attrs.class = [attrs.class, `bg-${token.toLowerCase()}`].filter(Boolean).join(" ");
|
|
20
|
+
} else attrs.style = (attrs.style || "") + `background-color: ${value};`;
|
|
13
21
|
}
|
|
14
22
|
} }
|
|
15
23
|
});
|