@fibery/prosemirror-schema 7.0.2 → 7.1.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/attr-constraints.js +3 -1
- package/lib/create-schema.js +8 -4
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/marks/comment.d.ts +3 -0
- package/lib/marks/comment.js +25 -0
- package/package.json +1 -1
package/lib/attr-constraints.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { COMMENT_MARK_NAME } from "./marks/comment.js";
|
|
1
2
|
import { SUGGESTION_MARK_NAMES } from "./marks/suggestions.js";
|
|
2
3
|
import { ColorToken } from "./marks/text-background-color.js";
|
|
3
4
|
// src/attr-constraints.ts
|
|
@@ -80,7 +81,8 @@ const MARK_ATTR_CONSTRAINTS = {
|
|
|
80
81
|
bgColor: { enum: Object.values(ColorToken) },
|
|
81
82
|
fgColor: { enum: Object.values(ColorToken) }
|
|
82
83
|
},
|
|
83
|
-
...Object.fromEntries(SUGGESTION_MARK_NAMES.map((name) => [name, suggestionConstraints(name)]))
|
|
84
|
+
...Object.fromEntries(SUGGESTION_MARK_NAMES.map((name) => [name, suggestionConstraints(name)])),
|
|
85
|
+
[COMMENT_MARK_NAME]: { id: { type: ["string"] } }
|
|
84
86
|
};
|
|
85
87
|
function suggestionConstraints(markName) {
|
|
86
88
|
const common = {
|
package/lib/create-schema.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { code } from "./marks/code.js";
|
|
2
|
+
import { COMMENT_MARK_NAME, comment } from "./marks/comment.js";
|
|
2
3
|
import { em } from "./marks/em.js";
|
|
3
4
|
import { hintQuery } from "./marks/hint-query.js";
|
|
4
5
|
import { link } from "./marks/link.js";
|
|
@@ -35,7 +36,10 @@ import { Schema } from "prosemirror-model";
|
|
|
35
36
|
import { marks, nodes } from "prosemirror-schema-basic";
|
|
36
37
|
import { addListNodes } from "prosemirror-schema-list";
|
|
37
38
|
// src/create-schema.ts
|
|
38
|
-
const
|
|
39
|
+
const INLINE_ANNOTATION_MARK_NAMES = [...INLINE_SUGGESTION_MARK_NAMES, COMMENT_MARK_NAME];
|
|
40
|
+
const NODE_ANNOTATION_MARK_NAMES = [...SUGGESTION_MARK_NAMES, COMMENT_MARK_NAME];
|
|
41
|
+
const isTableInternal = (type) => type.spec.tableRole === "table" || type.spec.tableRole === "row";
|
|
42
|
+
const allowAnnotationMarks = (nodes, marks) => {
|
|
39
43
|
const probe = new Schema({
|
|
40
44
|
nodes,
|
|
41
45
|
marks
|
|
@@ -44,7 +48,7 @@ const allowSuggestionMarks = (nodes, marks) => {
|
|
|
44
48
|
for (const type of Object.values(probe.nodes)) {
|
|
45
49
|
if (type.isInline || type.isLeaf || type.spec.marks === "_") continue;
|
|
46
50
|
if (type.inlineContent && type.spec.marks === void 0) continue;
|
|
47
|
-
const allowed = type.inlineContent ?
|
|
51
|
+
const allowed = type.inlineContent ? INLINE_ANNOTATION_MARK_NAMES : isTableInternal(type) ? SUGGESTION_MARK_NAMES : NODE_ANNOTATION_MARK_NAMES;
|
|
48
52
|
const existing = type.spec.marks?.split(" ").filter(Boolean) ?? [];
|
|
49
53
|
const merged = [.../* @__PURE__ */ new Set([...existing, ...allowed])].join(" ");
|
|
50
54
|
result = result.update(type.name, {
|
|
@@ -211,9 +215,9 @@ const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaT
|
|
|
211
215
|
}
|
|
212
216
|
});
|
|
213
217
|
}
|
|
214
|
-
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);
|
|
218
|
+
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).addToEnd(COMMENT_MARK_NAME, comment);
|
|
215
219
|
return new Schema({
|
|
216
|
-
nodes:
|
|
220
|
+
nodes: allowAnnotationMarks(actualNodes, marks),
|
|
217
221
|
marks
|
|
218
222
|
});
|
|
219
223
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE } from "./nodes/callout
|
|
|
9
9
|
import { CellAlign, cellAlignValues } from "./nodes/table-nodes.js";
|
|
10
10
|
import { ColorToken, isColorToken, validateColorToken } from "./marks/text-background-color.js";
|
|
11
11
|
import { INLINE_SUGGESTION_MARK_NAMES, SUGGESTION_MARKS_EXPR, SUGGESTION_MARK_NAMES, SuggestionBaggage, SuggestionMarkName, isSuggestionBaggage } from "./marks/suggestions.js";
|
|
12
|
+
import { COMMENT_MARK_NAME } from "./marks/comment.js";
|
|
12
13
|
import { EmojiOptions } from "./nodes/emoji.js";
|
|
13
14
|
import { Node, Schema } from "prosemirror-model";
|
|
14
|
-
export { type AttrConstraint, type AttrConstraintType, type AttrValidationIssue, Basic, type CellAlign, ColorToken, DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE, DEFAULT_VIDEO_HEIGHT, DEFAULT_VIDEO_WIDTH, type EmojiOptions, type EntityAttributes, FIBERY_VIEW_TYPE, INLINE_SUGGESTION_MARK_NAMES, MARK_ATTR_CONSTRAINTS, type MentionAttributes, NODE_ATTR_CONSTRAINTS, Node, SUGGESTION_MARKS_EXPR, SUGGESTION_MARK_NAMES, Schema, type SuggestionBaggage, type SuggestionMarkName, buildBlockIdAttrs, cellAlignValues, createSchema, defaultHeight, defaultWidth, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr, isColorToken, isSuggestionBaggage, validateAttrValue, validateAttrs, validateColorToken, validateMarkAttrValue, validateMarkAttrs };
|
|
15
|
+
export { type AttrConstraint, type AttrConstraintType, type AttrValidationIssue, Basic, COMMENT_MARK_NAME, type CellAlign, ColorToken, DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE, DEFAULT_VIDEO_HEIGHT, DEFAULT_VIDEO_WIDTH, type EmojiOptions, type EntityAttributes, FIBERY_VIEW_TYPE, INLINE_SUGGESTION_MARK_NAMES, MARK_ATTR_CONSTRAINTS, type MentionAttributes, NODE_ATTR_CONSTRAINTS, Node, SUGGESTION_MARKS_EXPR, SUGGESTION_MARK_NAMES, Schema, type SuggestionBaggage, type SuggestionMarkName, buildBlockIdAttrs, cellAlignValues, createSchema, defaultHeight, defaultWidth, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr, isColorToken, isSuggestionBaggage, validateAttrValue, validateAttrs, validateColorToken, validateMarkAttrValue, validateMarkAttrs };
|
package/lib/index.js
CHANGED
|
@@ -7,5 +7,6 @@ import { DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE } from "./nodes/callout
|
|
|
7
7
|
import { cellAlignValues } from "./nodes/table-nodes.js";
|
|
8
8
|
import { ColorToken, isColorToken, validateColorToken } from "./marks/text-background-color.js";
|
|
9
9
|
import { INLINE_SUGGESTION_MARK_NAMES, SUGGESTION_MARKS_EXPR, SUGGESTION_MARK_NAMES, isSuggestionBaggage } from "./marks/suggestions.js";
|
|
10
|
+
import { COMMENT_MARK_NAME } from "./marks/comment.js";
|
|
10
11
|
import { Node, Schema } from "prosemirror-model";
|
|
11
|
-
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, cellAlignValues, createSchema, defaultHeight, defaultWidth, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr, isColorToken, isSuggestionBaggage, validateAttrValue, validateAttrs, validateColorToken, validateMarkAttrValue, validateMarkAttrs };
|
|
12
|
+
export { Basic, COMMENT_MARK_NAME, 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, cellAlignValues, createSchema, defaultHeight, defaultWidth, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr, isColorToken, isSuggestionBaggage, validateAttrValue, validateAttrs, validateColorToken, validateMarkAttrValue, validateMarkAttrs };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/marks/comment.ts
|
|
2
|
+
const COMMENT_MARK_NAME = "comment";
|
|
3
|
+
const ANCHOR_ATTR = "data-comment-anchor";
|
|
4
|
+
const getCommentAttrs = (dom) => {
|
|
5
|
+
const id = dom.getAttribute(ANCHOR_ATTR);
|
|
6
|
+
return id ? { id } : false;
|
|
7
|
+
};
|
|
8
|
+
const comment = {
|
|
9
|
+
inclusive: false,
|
|
10
|
+
excludes: "",
|
|
11
|
+
attrs: { id: { validate: "string" } },
|
|
12
|
+
toDOM: (mark, inline) => [
|
|
13
|
+
inline ? "span" : "div",
|
|
14
|
+
{ [ANCHOR_ATTR]: String(mark.attrs.id) },
|
|
15
|
+
0
|
|
16
|
+
],
|
|
17
|
+
parseDOM: [{
|
|
18
|
+
tag: `span[${ANCHOR_ATTR}]`,
|
|
19
|
+
getAttrs: getCommentAttrs
|
|
20
|
+
}, {
|
|
21
|
+
tag: `div[${ANCHOR_ATTR}]`,
|
|
22
|
+
getAttrs: getCommentAttrs
|
|
23
|
+
}]
|
|
24
|
+
};
|
|
25
|
+
export { COMMENT_MARK_NAME, comment };
|