@fibery/prosemirror-schema 4.22.0 → 4.23.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.
Files changed (153) hide show
  1. package/lib/attr-constraints.d.ts +17 -0
  2. package/lib/attr-constraints.js +145 -0
  3. package/lib/block-id-utils.d.ts +10 -0
  4. package/lib/block-id-utils.js +26 -0
  5. package/lib/create-schema.d.ts +19 -0
  6. package/lib/create-schema.js +206 -0
  7. package/lib/index.d.ts +10 -10
  8. package/lib/index.js +9 -31
  9. package/lib/marks/code.d.ts +8 -0
  10. package/lib/marks/code.js +13 -0
  11. package/lib/marks/em.d.ts +9 -0
  12. package/lib/marks/em.js +22 -0
  13. package/lib/marks/hint-query.d.ts +5 -0
  14. package/lib/marks/hint-query.js +20 -0
  15. package/lib/marks/link.d.ts +10 -0
  16. package/lib/marks/link.js +43 -0
  17. package/lib/marks/linked-highlight.d.ts +13 -0
  18. package/lib/marks/linked-highlight.js +44 -0
  19. package/lib/marks/strike.d.ts +5 -0
  20. package/lib/marks/strike.js +7 -0
  21. package/lib/marks/strong.d.ts +9 -0
  22. package/lib/marks/strong.js +32 -0
  23. package/lib/marks/text-background-color.d.ts +16 -0
  24. package/lib/marks/text-background-color.js +72 -0
  25. package/lib/marks/underline.d.ts +5 -0
  26. package/lib/marks/underline.js +7 -0
  27. package/lib/nodes/callout.d.ts +31 -0
  28. package/lib/nodes/callout.js +59 -0
  29. package/lib/nodes/check-item.d.ts +14 -0
  30. package/lib/nodes/check-item.js +33 -0
  31. package/lib/nodes/check-list.d.ts +16 -0
  32. package/lib/nodes/check-list.js +24 -0
  33. package/lib/nodes/code-block.d.ts +5 -0
  34. package/lib/nodes/code-block.js +81 -0
  35. package/lib/nodes/column.d.ts +5 -0
  36. package/lib/nodes/column.js +29 -0
  37. package/lib/nodes/columns.d.ts +5 -0
  38. package/lib/nodes/columns.js +35 -0
  39. package/lib/nodes/emoji.d.ts +33 -0
  40. package/lib/nodes/emoji.js +42 -0
  41. package/lib/nodes/entity.d.ts +22 -0
  42. package/lib/nodes/entity.js +49 -0
  43. package/lib/nodes/fibery-view.d.ts +5 -0
  44. package/lib/nodes/fibery-view.js +39 -0
  45. package/lib/nodes/file.d.ts +39 -0
  46. package/lib/nodes/file.js +42 -0
  47. package/lib/nodes/heading.d.ts +7 -0
  48. package/lib/nodes/heading.js +63 -0
  49. package/lib/nodes/image-block.d.ts +5 -0
  50. package/lib/nodes/image-block.js +44 -0
  51. package/lib/nodes/important.d.ts +5 -0
  52. package/lib/nodes/important.js +15 -0
  53. package/lib/nodes/math-display.d.ts +5 -0
  54. package/lib/nodes/math-display.js +15 -0
  55. package/lib/nodes/math-inline.d.ts +5 -0
  56. package/lib/nodes/math-inline.js +15 -0
  57. package/lib/nodes/media.d.ts +7 -0
  58. package/lib/nodes/media.js +58 -0
  59. package/lib/nodes/mention.d.ts +14 -0
  60. package/lib/nodes/mention.js +37 -0
  61. package/lib/nodes/note.d.ts +5 -0
  62. package/lib/nodes/note.js +15 -0
  63. package/lib/nodes/paragraph.d.ts +5 -0
  64. package/lib/nodes/paragraph.js +33 -0
  65. package/lib/nodes/table-nodes.d.ts +5 -0
  66. package/lib/nodes/table-nodes.js +17 -0
  67. package/lib/nodes/types/inline-content.d.ts +12 -0
  68. package/lib/nodes/types/inline-content.js +0 -0
  69. package/lib/nodes/types/text.d.ts +8 -0
  70. package/lib/nodes/types/text.js +0 -0
  71. package/lib/nodes/video.d.ts +7 -0
  72. package/lib/nodes/video.js +50 -0
  73. package/lib/resizable-node-attrs.d.ts +32 -0
  74. package/lib/resizable-node-attrs.js +29 -0
  75. package/lib/transcription-node-attrs.d.ts +12 -0
  76. package/lib/transcription-node-attrs.js +10 -0
  77. package/package.json +8 -27
  78. package/lib/src/attr-constraints.d.ts +0 -14
  79. package/lib/src/attr-constraints.js +0 -185
  80. package/lib/src/block-id-utils.d.ts +0 -7
  81. package/lib/src/block-id-utils.js +0 -49
  82. package/lib/src/create-schema.d.ts +0 -18
  83. package/lib/src/create-schema.js +0 -251
  84. package/lib/src/marks/code.d.ts +0 -5
  85. package/lib/src/marks/code.js +0 -13
  86. package/lib/src/marks/em.d.ts +0 -6
  87. package/lib/src/marks/em.js +0 -19
  88. package/lib/src/marks/hint-query.d.ts +0 -2
  89. package/lib/src/marks/hint-query.js +0 -23
  90. package/lib/src/marks/link.d.ts +0 -7
  91. package/lib/src/marks/link.js +0 -39
  92. package/lib/src/marks/linked-highlight.d.ts +0 -11
  93. package/lib/src/marks/linked-highlight.js +0 -57
  94. package/lib/src/marks/strike.d.ts +0 -2
  95. package/lib/src/marks/strike.js +0 -7
  96. package/lib/src/marks/strong.d.ts +0 -6
  97. package/lib/src/marks/strong.js +0 -32
  98. package/lib/src/marks/text-background-color.d.ts +0 -13
  99. package/lib/src/marks/text-background-color.js +0 -90
  100. package/lib/src/marks/underline.d.ts +0 -2
  101. package/lib/src/marks/underline.js +0 -7
  102. package/lib/src/nodes/callout.d.ts +0 -28
  103. package/lib/src/nodes/callout.js +0 -62
  104. package/lib/src/nodes/check-item.d.ts +0 -11
  105. package/lib/src/nodes/check-item.js +0 -34
  106. package/lib/src/nodes/check-list.d.ts +0 -13
  107. package/lib/src/nodes/check-list.js +0 -31
  108. package/lib/src/nodes/code-block.d.ts +0 -2
  109. package/lib/src/nodes/code-block.js +0 -112
  110. package/lib/src/nodes/column.d.ts +0 -2
  111. package/lib/src/nodes/column.js +0 -35
  112. package/lib/src/nodes/columns.d.ts +0 -2
  113. package/lib/src/nodes/columns.js +0 -37
  114. package/lib/src/nodes/emoji.d.ts +0 -31
  115. package/lib/src/nodes/emoji.js +0 -51
  116. package/lib/src/nodes/entity.d.ts +0 -20
  117. package/lib/src/nodes/entity.js +0 -50
  118. package/lib/src/nodes/fibery-view.d.ts +0 -2
  119. package/lib/src/nodes/fibery-view.js +0 -43
  120. package/lib/src/nodes/file.d.ts +0 -36
  121. package/lib/src/nodes/file.js +0 -41
  122. package/lib/src/nodes/heading.d.ts +0 -4
  123. package/lib/src/nodes/heading.js +0 -39
  124. package/lib/src/nodes/image-block.d.ts +0 -2
  125. package/lib/src/nodes/image-block.js +0 -43
  126. package/lib/src/nodes/important.d.ts +0 -2
  127. package/lib/src/nodes/important.js +0 -11
  128. package/lib/src/nodes/math-display.d.ts +0 -2
  129. package/lib/src/nodes/math-display.js +0 -16
  130. package/lib/src/nodes/math-inline.d.ts +0 -2
  131. package/lib/src/nodes/math-inline.js +0 -16
  132. package/lib/src/nodes/media.d.ts +0 -4
  133. package/lib/src/nodes/media.js +0 -74
  134. package/lib/src/nodes/mention.d.ts +0 -11
  135. package/lib/src/nodes/mention.js +0 -38
  136. package/lib/src/nodes/note.d.ts +0 -2
  137. package/lib/src/nodes/note.js +0 -11
  138. package/lib/src/nodes/paragraph.d.ts +0 -2
  139. package/lib/src/nodes/paragraph.js +0 -27
  140. package/lib/src/nodes/table-nodes.d.ts +0 -2
  141. package/lib/src/nodes/table-nodes.js +0 -21
  142. package/lib/src/nodes/types/inline-content.d.ts +0 -10
  143. package/lib/src/nodes/types/inline-content.js +0 -2
  144. package/lib/src/nodes/types/text.d.ts +0 -5
  145. package/lib/src/nodes/types/text.js +0 -2
  146. package/lib/src/nodes/video.d.ts +0 -4
  147. package/lib/src/nodes/video.js +0 -55
  148. package/lib/src/resizable-node-attrs.d.ts +0 -29
  149. package/lib/src/resizable-node-attrs.js +0 -40
  150. package/lib/src/transcription-node-attrs.d.ts +0 -9
  151. package/lib/src/transcription-node-attrs.js +0 -10
  152. package/lib/test-helpers/index.d.ts +0 -4
  153. package/lib/test-helpers/index.js +0 -21
@@ -0,0 +1,17 @@
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;
8
+ };
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;
14
+ };
15
+ declare const validateAttrs: (nodeType: string, attrs: Record<string, unknown>) => AttrValidationIssue[];
16
+ //#endregion
17
+ export { AttrConstraint, AttrConstraintType, AttrValidationIssue, NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs };
@@ -0,0 +1,145 @@
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() }
69
+ };
70
+ function resizableConstraints() {
71
+ return {
72
+ nodeHeight: { type: ["number", "null"] },
73
+ nodeWidth: { type: ["number", "null"] },
74
+ nodePageWidth: { type: ["boolean", "null"] },
75
+ nodeFullWidth: { type: ["boolean", "null"] }
76
+ };
77
+ }
78
+ function cellConstraints() {
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
+ };
90
+ }
91
+ const matchesType = (type, value) => {
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
+ }
100
+ };
101
+ const describeType = (type) => {
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
+ }
110
+ };
111
+ const describeExpectation = (constraint) => {
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;
118
+ };
119
+ const checkConstraint = (constraint, value) => {
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;
127
+ };
128
+ const validateAttrValue = (nodeType, attr, 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)}]`;
132
+ };
133
+ const validateAttrs = (nodeType, attrs) => {
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;
143
+ };
144
+ //#endregion
145
+ export { NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs };
@@ -0,0 +1,10 @@
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 };
@@ -0,0 +1,26 @@
1
+ //#region src/block-id-utils.ts
2
+ const REFERENCE_ID_TYPES = /* @__PURE__ */ new Set(["fiberyView"]);
3
+ const getBlockIdAttr = (type) => {
4
+ if (type.isInline || type.name === "doc" || REFERENCE_ID_TYPES.has(type.name)) return null;
5
+ return "id" in (type.spec.attrs ?? {}) ? "id" : null;
6
+ };
7
+ const hasLegacyGuidAttr = (type) => {
8
+ return "guid" in (type.spec.attrs ?? {});
9
+ };
10
+ const normalizeId = (value) => typeof value === "string" && value !== "" ? value : null;
11
+ const getBlockId = (node) => {
12
+ if (getBlockIdAttr(node.type) === null) return null;
13
+ return normalizeId(node.attrs.id) ?? normalizeId(node.attrs.guid);
14
+ };
15
+ const buildBlockIdAttrs = (node, nextId) => ({
16
+ ...node.attrs,
17
+ id: nextId,
18
+ ...hasLegacyGuidAttr(node.type) ? { guid: nextId } : {}
19
+ });
20
+ const FIBERY_VIEW_TYPE = "fiberyView";
21
+ const getFiberyViewRef = (node) => {
22
+ if (node.type.name !== "fiberyView") return null;
23
+ return normalizeId(node.attrs.viewId) ?? normalizeId(node.attrs.id);
24
+ };
25
+ //#endregion
26
+ export { FIBERY_VIEW_TYPE, buildBlockIdAttrs, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr };
@@ -0,0 +1,19 @@
1
+ import { EmojiOptions } from "./nodes/emoji.js";
2
+ import { MarkSpec, Node, NodeSpec, Schema } from "prosemirror-model";
3
+ //#region src/create-schema.d.ts
4
+ type Params = {
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
+ };
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
+ };
18
+ //#endregion
19
+ export { Basic, createSchema };
@@ -0,0 +1,206 @@
1
+ import { code } from "./marks/code.js";
2
+ import { em } from "./marks/em.js";
3
+ import { hintQuery } from "./marks/hint-query.js";
4
+ import { link } from "./marks/link.js";
5
+ import { makeLinkedHighlight, makeLinkedHighlightEntity } from "./marks/linked-highlight.js";
6
+ import { strike } from "./marks/strike.js";
7
+ import { strong } from "./marks/strong.js";
8
+ import { textBackgroundColor } from "./marks/text-background-color.js";
9
+ import { underline } from "./marks/underline.js";
10
+ import { makeCallout } from "./nodes/callout.js";
11
+ import { check_item } from "./nodes/check-item.js";
12
+ import { check_list } from "./nodes/check-list.js";
13
+ import { code_block } from "./nodes/code-block.js";
14
+ import { column } from "./nodes/column.js";
15
+ import { columns } from "./nodes/columns.js";
16
+ import { makeEmoji } from "./nodes/emoji.js";
17
+ import { entity } from "./nodes/entity.js";
18
+ import { fiberyView } from "./nodes/fibery-view.js";
19
+ import { file } from "./nodes/file.js";
20
+ import { makeHeading } from "./nodes/heading.js";
21
+ import { imageBlock } from "./nodes/image-block.js";
22
+ import { important } from "./nodes/important.js";
23
+ import { math_display } from "./nodes/math-display.js";
24
+ import { math_inline } from "./nodes/math-inline.js";
25
+ import { makeMedia } from "./nodes/media.js";
26
+ import { mention } from "./nodes/mention.js";
27
+ import { note } from "./nodes/note.js";
28
+ import { paragraph } from "./nodes/paragraph.js";
29
+ import { tableNodes } from "./nodes/table-nodes.js";
30
+ import { video } from "./nodes/video.js";
31
+ import { Schema } from "prosemirror-model";
32
+ import { marks, nodes } from "prosemirror-schema-basic";
33
+ import { addListNodes } from "prosemirror-schema-list";
34
+ //#region src/create-schema.ts
35
+ const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaToDom = null, isImageBlockEnabled = false, fiberyViewEnabled = false, emojiOptions } = {}) => {
36
+ nodes.code_block = code_block;
37
+ nodes.paragraph = paragraph;
38
+ nodes.heading = makeHeading({ headingToDOM });
39
+ const base = new Schema({
40
+ nodes,
41
+ marks: {
42
+ link,
43
+ em,
44
+ strong,
45
+ code,
46
+ linkedhighlight: makeLinkedHighlight({ sharedColorGenerator }),
47
+ linkedhighlightentity: makeLinkedHighlightEntity({ sharedColorGenerator })
48
+ }
49
+ });
50
+ const customNodes = {
51
+ note,
52
+ important,
53
+ entity,
54
+ mention,
55
+ media: makeMedia({ mediaToDom }),
56
+ check_item,
57
+ check_list,
58
+ video,
59
+ file,
60
+ emoji: makeEmoji(emojiOptions),
61
+ callout: makeCallout(emojiOptions),
62
+ columns,
63
+ column,
64
+ math_display,
65
+ math_inline
66
+ };
67
+ let actualNodes = addListNodes(base.spec.nodes, "paragraph block*", "block").append({ ...tableNodes }).append(customNodes);
68
+ if (fiberyViewEnabled) actualNodes = actualNodes.append({ fiberyView });
69
+ if (isImageBlockEnabled) actualNodes = actualNodes.addToStart("imageBlock", imageBlock);
70
+ else actualNodes = actualNodes.addToEnd("imageBlock", imageBlock);
71
+ actualNodes = actualNodes.update("doc", { content: `(block | columns)+` });
72
+ for (const cellType of ["table_cell", "table_header"]) {
73
+ const cellSpec = actualNodes.get(cellType);
74
+ const attrsWithoutValidate = {};
75
+ for (const [key, attrSpec] of Object.entries(cellSpec.attrs ?? {})) {
76
+ const { validate: _, ...rest } = attrSpec;
77
+ attrsWithoutValidate[key] = rest;
78
+ }
79
+ actualNodes = actualNodes.update(cellType, {
80
+ ...cellSpec,
81
+ attrs: attrsWithoutValidate
82
+ });
83
+ }
84
+ const orderedListSpec = actualNodes.get("ordered_list");
85
+ actualNodes = actualNodes.update("ordered_list", {
86
+ ...orderedListSpec,
87
+ attrs: { order: { default: 1 } }
88
+ });
89
+ const listItemSpec = actualNodes.get("list_item");
90
+ actualNodes = actualNodes.update("list_item", {
91
+ ...listItemSpec,
92
+ attrs: {
93
+ ...listItemSpec.attrs,
94
+ state: { default: null },
95
+ id: { default: null }
96
+ },
97
+ parseDOM: [
98
+ {
99
+ tag: "li[data-check-item-state]",
100
+ getAttrs: (dom) => {
101
+ const el = dom;
102
+ const state = el.getAttribute("data-check-item-state");
103
+ const firstBlock = el.firstChild;
104
+ if (firstBlock !== null && firstBlock.nodeType === 1) {
105
+ const firstText = firstBlock.firstChild;
106
+ if (firstText !== null && firstText.nodeType === 3) {
107
+ const text = firstText.textContent ?? "";
108
+ if (text.startsWith("[ ] ") || text.startsWith("[x] ")) {
109
+ const rest = text.slice(4);
110
+ if (rest) firstText.textContent = rest;
111
+ else firstBlock.removeChild(firstText);
112
+ }
113
+ }
114
+ }
115
+ return {
116
+ state: state === "TODO" || state === "DONE" ? state : null,
117
+ id: el.getAttribute("data-list-item-id") ?? null
118
+ };
119
+ }
120
+ },
121
+ {
122
+ tag: "li",
123
+ getAttrs: (dom) => {
124
+ const el = dom;
125
+ const firstChild = el.firstChild;
126
+ if (firstChild === null) return false;
127
+ let textNode = null;
128
+ let textParent = null;
129
+ if (firstChild.nodeType === 3) {
130
+ textNode = firstChild;
131
+ textParent = el;
132
+ } else if (firstChild.nodeType === 1 && firstChild.firstChild?.nodeType === 3) {
133
+ textNode = firstChild.firstChild;
134
+ textParent = firstChild;
135
+ }
136
+ if (textNode === null) return false;
137
+ const text = textNode.textContent ?? "";
138
+ const state = text.startsWith("[ ] ") ? "TODO" : text.startsWith("[x] ") ? "DONE" : null;
139
+ if (state === null) return false;
140
+ const rest = text.slice(4);
141
+ if (rest) textNode.textContent = rest;
142
+ else textParent.removeChild(textNode);
143
+ return {
144
+ state,
145
+ id: null
146
+ };
147
+ }
148
+ },
149
+ { tag: "li" }
150
+ ],
151
+ toDOM(node) {
152
+ const { state, id } = node.attrs;
153
+ const attrs = {};
154
+ if (state) attrs["data-check-item-state"] = state;
155
+ if (id) attrs["data-list-item-id"] = id;
156
+ return Object.keys(attrs).length ? [
157
+ "li",
158
+ attrs,
159
+ 0
160
+ ] : ["li", 0];
161
+ }
162
+ });
163
+ for (const name of [
164
+ "blockquote",
165
+ "horizontal_rule",
166
+ "bullet_list",
167
+ "ordered_list",
168
+ "table",
169
+ "table_row",
170
+ "table_cell",
171
+ "table_header",
172
+ "note",
173
+ "important",
174
+ "callout",
175
+ "media",
176
+ "video",
177
+ "imageBlock",
178
+ "math_display",
179
+ "column"
180
+ ]) {
181
+ const spec = actualNodes.get(name);
182
+ actualNodes = actualNodes.update(name, {
183
+ ...spec,
184
+ attrs: {
185
+ ...spec.attrs,
186
+ id: { default: null }
187
+ }
188
+ });
189
+ }
190
+ return new Schema({
191
+ nodes: actualNodes,
192
+ marks: base.spec.marks.addToEnd("strike", strike).addToEnd("underline", underline).addToEnd("hintQuery", hintQuery).addToEnd("highlight", textBackgroundColor)
193
+ });
194
+ };
195
+ const Basic = {
196
+ nodes,
197
+ marks,
198
+ fibery: {
199
+ link,
200
+ strike,
201
+ underline,
202
+ textBackgroundColor
203
+ }
204
+ };
205
+ //#endregion
206
+ export { Basic, createSchema };
package/lib/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export { defaultHeight, defaultWidth } from "./src/resizable-node-attrs";
2
- export { Node, Schema } from "prosemirror-model";
3
- export { createSchema, Basic } from "./src/create-schema";
4
- export { NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs } from "./src/attr-constraints";
5
- export type { AttrConstraint, AttrConstraintType, AttrValidationIssue } from "./src/attr-constraints";
6
- export { getBlockId, getBlockIdAttr, hasLegacyGuidAttr, buildBlockIdAttrs, getFiberyViewRef, FIBERY_VIEW_TYPE, } from "./src/block-id-utils";
7
- export { DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT } from "./src/nodes/video";
8
- export { DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE } from "./src/nodes/callout";
9
- export { ColorToken } from "./src/marks/text-background-color";
10
- export type { EmojiOptions } from "./src/nodes/emoji";
1
+ import { AttrConstraint, AttrConstraintType, AttrValidationIssue, NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs } from "./attr-constraints.js";
2
+ import { FIBERY_VIEW_TYPE, buildBlockIdAttrs, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr } from "./block-id-utils.js";
3
+ import { EmojiOptions } from "./nodes/emoji.js";
4
+ import { Basic, createSchema } from "./create-schema.js";
5
+ import { defaultHeight, defaultWidth } from "./resizable-node-attrs.js";
6
+ import { DEFAULT_VIDEO_HEIGHT, DEFAULT_VIDEO_WIDTH } from "./nodes/video.js";
7
+ import { DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE } from "./nodes/callout.js";
8
+ import { ColorToken } from "./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,31 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ColorToken = exports.DEFAULT_CALLOUT_ICON_TYPE = exports.DEFAULT_CALLOUT_ICON = exports.DEFAULT_VIDEO_HEIGHT = exports.DEFAULT_VIDEO_WIDTH = exports.FIBERY_VIEW_TYPE = exports.getFiberyViewRef = exports.buildBlockIdAttrs = exports.hasLegacyGuidAttr = exports.getBlockIdAttr = exports.getBlockId = exports.validateAttrs = exports.validateAttrValue = exports.NODE_ATTR_CONSTRAINTS = exports.Basic = exports.createSchema = exports.Schema = exports.Node = exports.defaultWidth = exports.defaultHeight = void 0;
4
- var resizable_node_attrs_1 = require("./src/resizable-node-attrs");
5
- Object.defineProperty(exports, "defaultHeight", { enumerable: true, get: function () { return resizable_node_attrs_1.defaultHeight; } });
6
- Object.defineProperty(exports, "defaultWidth", { enumerable: true, get: function () { return resizable_node_attrs_1.defaultWidth; } });
7
- var prosemirror_model_1 = require("prosemirror-model");
8
- Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return prosemirror_model_1.Node; } });
9
- Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return prosemirror_model_1.Schema; } });
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; } });
27
- var callout_1 = require("./src/nodes/callout");
28
- Object.defineProperty(exports, "DEFAULT_CALLOUT_ICON", { enumerable: true, get: function () { return callout_1.DEFAULT_CALLOUT_ICON; } });
29
- Object.defineProperty(exports, "DEFAULT_CALLOUT_ICON_TYPE", { enumerable: true, get: function () { return callout_1.DEFAULT_CALLOUT_ICON_TYPE; } });
30
- var text_background_color_1 = require("./src/marks/text-background-color");
31
- Object.defineProperty(exports, "ColorToken", { enumerable: true, get: function () { return text_background_color_1.ColorToken; } });
1
+ import { NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs } from "./attr-constraints.js";
2
+ import { FIBERY_VIEW_TYPE, buildBlockIdAttrs, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr } from "./block-id-utils.js";
3
+ import { ColorToken } from "./marks/text-background-color.js";
4
+ import { DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE } from "./nodes/callout.js";
5
+ import { defaultHeight, defaultWidth } from "./resizable-node-attrs.js";
6
+ import { DEFAULT_VIDEO_HEIGHT, DEFAULT_VIDEO_WIDTH } from "./nodes/video.js";
7
+ import { Basic, createSchema } from "./create-schema.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 };
@@ -0,0 +1,8 @@
1
+ import { MarkSpec } from "prosemirror-model";
2
+ //#region src/marks/code.d.ts
3
+ /**
4
+ Code font mark. Represented as a `<code>` element.
5
+ */
6
+ declare const code: MarkSpec;
7
+ //#endregion
8
+ export { code };
@@ -0,0 +1,13 @@
1
+ //#region src/marks/code.ts
2
+ const codeDOM = ["code", 0];
3
+ /**
4
+ Code font mark. Represented as a `<code>` element.
5
+ */
6
+ const code = {
7
+ parseDOM: [{ tag: "code" }],
8
+ toDOM() {
9
+ return codeDOM;
10
+ }
11
+ };
12
+ //#endregion
13
+ export { code };
@@ -0,0 +1,9 @@
1
+ import { MarkSpec } from "prosemirror-model";
2
+ //#region src/marks/em.d.ts
3
+ /**
4
+ An emphasis mark. Rendered as an `<em>` element. Has parse rules
5
+ that also match `<i>` and `font-style: italic`.
6
+ */
7
+ declare const em: MarkSpec;
8
+ //#endregion
9
+ export { em };
@@ -0,0 +1,22 @@
1
+ //#region src/marks/em.ts
2
+ const emDOM = ["em", 0];
3
+ /**
4
+ An emphasis mark. Rendered as an `<em>` element. Has parse rules
5
+ that also match `<i>` and `font-style: italic`.
6
+ */
7
+ const em = {
8
+ parseDOM: [
9
+ { tag: "i" },
10
+ { tag: "em" },
11
+ { style: "font-style=italic" },
12
+ {
13
+ style: "font-style=normal",
14
+ clearMark: (m) => m.type.name === "em"
15
+ }
16
+ ],
17
+ toDOM() {
18
+ return emDOM;
19
+ }
20
+ };
21
+ //#endregion
22
+ export { em };
@@ -0,0 +1,5 @@
1
+ import { MarkSpec } from "prosemirror-model";
2
+ //#region src/marks/hint-query.d.ts
3
+ declare const hintQuery: MarkSpec;
4
+ //#endregion
5
+ export { hintQuery };
@@ -0,0 +1,20 @@
1
+ //#region src/marks/hint-query.ts
2
+ const hintQuery = {
3
+ excludes: "searchQuery",
4
+ inclusive: true,
5
+ group: "searchQuery",
6
+ attrs: {
7
+ trigger: { default: "" },
8
+ guid: { default: "" }
9
+ },
10
+ parseDOM: [{ tag: "span[data-hint-query]" }],
11
+ toDOM(node) {
12
+ return ["span", {
13
+ "data-hint-query": "true",
14
+ "data-trigger": node.attrs.trigger,
15
+ "data-guid": node.attrs.guid
16
+ }];
17
+ }
18
+ };
19
+ //#endregion
20
+ export { hintQuery };
@@ -0,0 +1,10 @@
1
+ import { MarkSpec } from "prosemirror-model";
2
+ //#region src/marks/link.d.ts
3
+ /**
4
+ A link. Has `href` and `title` attributes. `title`
5
+ defaults to the empty string. Rendered and parsed as an `<a>`
6
+ element.
7
+ */
8
+ declare const link: MarkSpec;
9
+ //#endregion
10
+ export { link };
@@ -0,0 +1,43 @@
1
+ //#region src/marks/link.ts
2
+ const httpRegex = /^[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b[-a-zA-Z0-9()@:%_+.~#?&/=]*$/;
3
+ /**
4
+ A link. Has `href` and `title` attributes. `title`
5
+ defaults to the empty string. Rendered and parsed as an `<a>`
6
+ element.
7
+ */
8
+ const link = {
9
+ attrs: {
10
+ href: {},
11
+ title: { default: null }
12
+ },
13
+ inclusive: false,
14
+ parseDOM: [{
15
+ tag: "a[href]",
16
+ getAttrs(domNode) {
17
+ const dom = domNode;
18
+ return {
19
+ href: dom.getAttribute("href"),
20
+ title: dom.getAttribute("title")
21
+ };
22
+ }
23
+ }],
24
+ toDOM(node) {
25
+ const { href } = node.attrs;
26
+ let fixedHref = href;
27
+ if (href && !href.startsWith("mailto:") && !fixedHref.startsWith("http") && !fixedHref.startsWith("/")) {
28
+ if (httpRegex.test(href)) fixedHref = `https://${href}`;
29
+ }
30
+ return [
31
+ "a",
32
+ {
33
+ href: fixedHref,
34
+ target: "_blank",
35
+ class: "prosemirror-link",
36
+ rel: "noopener noreferrer nofollow"
37
+ },
38
+ 0
39
+ ];
40
+ }
41
+ };
42
+ //#endregion
43
+ export { link };
@@ -0,0 +1,13 @@
1
+ import { MarkSpec } from "prosemirror-model";
2
+ //#region src/marks/linked-highlight.d.ts
3
+ type Generator = {
4
+ generate: (typeId?: string) => string;
5
+ };
6
+ declare const makeLinkedHighlight: ({ sharedColorGenerator }: {
7
+ sharedColorGenerator?: Generator;
8
+ }) => MarkSpec;
9
+ declare const makeLinkedHighlightEntity: ({ sharedColorGenerator }: {
10
+ sharedColorGenerator?: Generator;
11
+ }) => MarkSpec;
12
+ //#endregion
13
+ export { makeLinkedHighlight, makeLinkedHighlightEntity };