@fibery/prosemirror-schema 7.0.2 → 7.1.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.
@@ -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 = {
@@ -15,7 +15,7 @@ const getBlockId = (node) => {
15
15
  const buildBlockIdAttrs = (node, nextId) => ({
16
16
  ...node.attrs,
17
17
  id: nextId,
18
- ...hasLegacyGuidAttr(node.type) ? { guid: nextId } : {}
18
+ ...hasLegacyGuidAttr(node.type) && { guid: nextId }
19
19
  });
20
20
  const FIBERY_VIEW_TYPE = "fiberyView";
21
21
  const getFiberyViewRef = (node) => {
@@ -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 allowSuggestionMarks = (nodes, marks) => {
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 ? INLINE_SUGGESTION_MARK_NAMES : SUGGESTION_MARK_NAMES;
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: allowSuggestionMarks(actualNodes, marks),
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,3 @@
1
+ import { MarkSpec } from "prosemirror-model";
2
+ export declare const COMMENT_MARK_NAME = "comment";
3
+ export declare const comment: MarkSpec;
@@ -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 };
@@ -15,10 +15,10 @@ const createMark = (markType, backgroundProperty, sharedColorGenerator) => {
15
15
  getAttrs: ({ dataset }) => {
16
16
  return {
17
17
  id: dataset.id || false,
18
- meta: Object.keys(dataset).filter((key) => key !== "id" && dataset[key] !== "false").reduce((out, key) => ({
19
- ...out,
20
- [key]: preserveBool(JSON.parse(dataset[key]))
21
- }), { type: markType })
18
+ meta: {
19
+ type: markType,
20
+ ...Object.fromEntries(Object.keys(dataset).filter((key) => key !== "id" && dataset[key] !== "false").map((key) => [key, preserveBool(JSON.parse(dataset[key]))]))
21
+ }
22
22
  };
23
23
  }
24
24
  }],
@@ -126,7 +126,7 @@ const modification = {
126
126
  "data-type": "modification",
127
127
  ...suggestionDomAttrs(mark),
128
128
  "data-mod-type": String(mark.attrs.type),
129
- ...mark.attrs.attrName !== null ? { "data-mod-attr-name": String(mark.attrs.attrName) } : {},
129
+ ...mark.attrs.attrName !== null && { "data-mod-attr-name": String(mark.attrs.attrName) },
130
130
  "data-mod-prev-val": JSON.stringify(mark.attrs.previousValue ?? null),
131
131
  "data-mod-new-val": JSON.stringify(mark.attrs.newValue ?? null)
132
132
  },
@@ -163,7 +163,7 @@ const blockBoundarySuggestion = {
163
163
  {
164
164
  "data-type": "block-boundary-suggestion",
165
165
  ...suggestionDomAttrs(mark),
166
- ...mark.attrs.type !== null ? { "data-change-type": String(mark.attrs.type) } : {}
166
+ ...mark.attrs.type !== null && { "data-change-type": String(mark.attrs.type) }
167
167
  },
168
168
  0
169
169
  ],
@@ -10,8 +10,8 @@ function toBoolean(attr) {
10
10
  }
11
11
  function toNumberOrNull(value) {
12
12
  if (!value) return null;
13
- const parsed = parseFloat(value);
14
- return isNaN(parsed) ? null : parsed;
13
+ const parsed = Number.parseFloat(value);
14
+ return Number.isNaN(parsed) ? null : parsed;
15
15
  }
16
16
  const makeMedia = ({ mediaToDom }) => ({
17
17
  inline: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/prosemirror-schema",
3
- "version": "7.0.2",
3
+ "version": "7.1.1",
4
4
  "description": "Fibery prosemirror schema",
5
5
  "license": "UNLICENSED",
6
6
  "files": [
@@ -17,7 +17,7 @@
17
17
  }
18
18
  },
19
19
  "dependencies": {
20
- "@fibery/helpers": "7.0.0",
20
+ "@fibery/helpers": "7.1.0",
21
21
  "prosemirror-model": "1.25.4",
22
22
  "prosemirror-schema-basic": "1.2.2",
23
23
  "prosemirror-schema-list": "1.5.1",