@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,32 @@
1
+ import { Attrs } from "prosemirror-model";
2
+ //#region src/resizable-node-attrs.d.ts
3
+ declare const defaultHeight = 400;
4
+ declare const defaultWidth = 900;
5
+ declare function createDefaultAttrs(): {
6
+ nodeHeight: {
7
+ default: number;
8
+ };
9
+ nodeWidth: {
10
+ default: number;
11
+ };
12
+ nodePageWidth: {
13
+ default: boolean;
14
+ };
15
+ nodeFullWidth: {
16
+ default: boolean;
17
+ };
18
+ };
19
+ declare function createParseDomAttrs(dom: HTMLElement): {
20
+ nodeHeight: string | null;
21
+ nodeWidth: string | null;
22
+ nodePageWidth: string | null;
23
+ nodeFullWidth: string | null;
24
+ };
25
+ declare function createToDomAttrs({ nodeHeight, nodeWidth, nodePageWidth, nodeFullWidth }: Attrs): {
26
+ "data-node-height": any;
27
+ "data-node-width": any;
28
+ "data-node-page-width": any;
29
+ "data-node-full-width": any;
30
+ };
31
+ //#endregion
32
+ export { createDefaultAttrs, createParseDomAttrs, createToDomAttrs, defaultHeight, defaultWidth };
@@ -0,0 +1,29 @@
1
+ //#region src/resizable-node-attrs.ts
2
+ const defaultHeight = 400;
3
+ const defaultWidth = 900;
4
+ function createDefaultAttrs() {
5
+ return {
6
+ nodeHeight: { default: 400 },
7
+ nodeWidth: { default: 900 },
8
+ nodePageWidth: { default: true },
9
+ nodeFullWidth: { default: false }
10
+ };
11
+ }
12
+ function createParseDomAttrs(dom) {
13
+ return {
14
+ nodeHeight: dom.getAttribute("data-node-height"),
15
+ nodeWidth: dom.getAttribute("data-node-width"),
16
+ nodePageWidth: dom.getAttribute("data-node-page-width"),
17
+ nodeFullWidth: dom.getAttribute("data-node-full-width")
18
+ };
19
+ }
20
+ function createToDomAttrs({ nodeHeight, nodeWidth, nodePageWidth, nodeFullWidth }) {
21
+ return {
22
+ "data-node-height": nodeHeight,
23
+ "data-node-width": nodeWidth,
24
+ "data-node-page-width": nodePageWidth,
25
+ "data-node-full-width": nodeFullWidth
26
+ };
27
+ }
28
+ //#endregion
29
+ export { createDefaultAttrs, createParseDomAttrs, createToDomAttrs, defaultHeight, defaultWidth };
@@ -0,0 +1,12 @@
1
+ //#region src/transcription-node-attrs.d.ts
2
+ declare function createDefaultAttrs(): {
3
+ transcription: {
4
+ default: {
5
+ status: string;
6
+ userId: string;
7
+ inserted: boolean;
8
+ };
9
+ };
10
+ };
11
+ //#endregion
12
+ export { createDefaultAttrs };
@@ -0,0 +1,10 @@
1
+ //#region src/transcription-node-attrs.ts
2
+ function createDefaultAttrs() {
3
+ return { transcription: { default: {
4
+ status: "IDLE",
5
+ userId: "",
6
+ inserted: false
7
+ } } };
8
+ }
9
+ //#endregion
10
+ export { createDefaultAttrs };
package/package.json CHANGED
@@ -1,25 +1,20 @@
1
1
  {
2
2
  "name": "@fibery/prosemirror-schema",
3
- "version": "4.22.0",
4
- "private": false,
3
+ "version": "4.23.1",
5
4
  "description": "Fibery prosemirror schema",
5
+ "license": "UNLICENSED",
6
6
  "files": [
7
- "/lib"
7
+ "lib"
8
8
  ],
9
+ "type": "module",
10
+ "sideEffects": false,
9
11
  "main": "./lib/index.js",
12
+ "types": "./lib/index.d.ts",
10
13
  "exports": {
11
14
  ".": {
12
- "@fibery/source": "./index.ts",
13
15
  "types": "./lib/index.d.ts",
14
16
  "default": "./lib/index.js"
15
- },
16
- "./src/nodes/fibery-section": {
17
- "@fibery/source": "./src/nodes/fibery-section.ts",
18
- "default": "./lib/src/nodes/fibery-section.js"
19
- },
20
- "./src/nodes/fibery-section.d.ts": "./lib/src/nodes/fibery-section.d.ts",
21
- "./lib/src/nodes/fibery-section": "./lib/src/nodes/fibery-section.js",
22
- "./lib/src/nodes/fibery-section.d.ts": "./lib/src/nodes/fibery-section.d.ts"
17
+ }
23
18
  },
24
19
  "dependencies": {
25
20
  "prosemirror-model": "1.25.4",
@@ -28,23 +23,9 @@
28
23
  "prosemirror-tables": "1.8.5",
29
24
  "uuid": "11.1.0"
30
25
  },
31
- "devDependencies": {
32
- "typescript": "rc",
33
- "@fibery/babel-preset": "7.4.2"
34
- },
35
26
  "peerDependencies": {
36
27
  "prosemirror-model": "1.25.4",
37
28
  "prosemirror-schema-list": "1.5.1",
38
29
  "prosemirror-tables": "1.8.5"
39
- },
40
- "scripts": {
41
- "build": "rm -rf lib && tsc --project tsconfig.build.json",
42
- "test": "../../scripts/test.sh",
43
- "test:ci": "../../scripts/test.sh --ci",
44
- "test:coverage": "../../scripts/test.sh --ci --coverage",
45
- "lint": "pnpm -w lint .",
46
- "typecheck": "../../scripts/typecheck.sh",
47
- "check": "../../scripts/check.sh"
48
- },
49
- "types": "./lib/index.d.ts"
30
+ }
50
31
  }
@@ -1,14 +0,0 @@
1
- export type AttrConstraintType = "string" | "number" | "integer" | "boolean" | "null";
2
- export type AttrConstraint = {
3
- type?: ReadonlyArray<AttrConstraintType>;
4
- enum?: ReadonlyArray<string | number | boolean | null>;
5
- minimum?: number;
6
- maximum?: number;
7
- };
8
- export declare const NODE_ATTR_CONSTRAINTS: Record<string, Record<string, AttrConstraint>>;
9
- export declare const validateAttrValue: (nodeType: string, attr: string, value: unknown) => string | null;
10
- export type AttrValidationIssue = {
11
- attr: string;
12
- message: string;
13
- };
14
- export declare const validateAttrs: (nodeType: string, attrs: Record<string, unknown>) => AttrValidationIssue[];
@@ -1,185 +0,0 @@
1
- "use strict";
2
- // Value constraints for node attributes, kept as data (JSON-Schema-shaped)
3
- // next to the specs instead of prosemirror-model's attr `validate`: legacy
4
- // documents already contain values that violate these constraints, so they
5
- // must not run when a stored document is parsed (see the validator-stripping
6
- // in create-schema.ts). Consumers apply them only to *incoming* changes (e.g.
7
- // the collaboration block API validates operation payloads). Once broken
8
- // documents are patched, the same table can be compiled into real `validate`
9
- // functions on the specs.
10
- //
11
- // This module is deliberately free of prosemirror-model imports so it can be
12
- // consumed by services pinned to older prosemirror-model versions.
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.validateAttrs = exports.validateAttrValue = exports.NODE_ATTR_CONSTRAINTS = void 0;
15
- // Keyed by schema node-type name; attrs not listed here are unconstrained.
16
- // Identifier attrs (id, guid, viewId) are deliberately absent — they are
17
- // managed by the block-id machinery, not by user-supplied values.
18
- exports.NODE_ATTR_CONSTRAINTS = {
19
- heading: {
20
- level: { type: ["integer"], minimum: 1, maximum: 6 },
21
- },
22
- check_item: {
23
- state: { enum: ["TODO", "DONE"] },
24
- },
25
- list_item: {
26
- state: { enum: ["TODO", "DONE", null] },
27
- },
28
- code_block: {
29
- language: { type: ["string", "null"] },
30
- wrapCode: { type: ["boolean"] },
31
- mode: { enum: ["code", "split", "preview"] },
32
- ...resizableConstraints(),
33
- },
34
- callout: {
35
- color: { type: ["string"] },
36
- iconType: { type: ["string"] },
37
- icon: { type: ["string"] },
38
- },
39
- ordered_list: {
40
- order: { type: ["integer"], minimum: 0 },
41
- },
42
- column: {
43
- columnRatio: { type: ["number"], minimum: 0 },
44
- },
45
- columns: {
46
- ...resizableConstraints(),
47
- },
48
- table_cell: cellConstraints(),
49
- table_header: cellConstraints(),
50
- media: {
51
- url: { type: ["string"] },
52
- compatibleMode: { type: ["boolean"] },
53
- dynamicContent: { type: ["boolean"] },
54
- aspectRatio: { type: ["number", "null"] },
55
- ...resizableConstraints(),
56
- },
57
- video: {
58
- src: { type: ["string"] },
59
- type: { type: ["string"] },
60
- width: { type: ["number"], minimum: 0 },
61
- height: { type: ["number"], minimum: 0 },
62
- title: { type: ["string"] },
63
- alignment: { type: ["string"] },
64
- ...resizableConstraints(),
65
- },
66
- imageBlock: {
67
- src: { type: ["string"] },
68
- alt: { type: ["string", "null"] },
69
- title: { type: ["string", "null"] },
70
- ...resizableConstraints(),
71
- },
72
- fiberyView: {
73
- ...resizableConstraints(),
74
- },
75
- };
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
- function resizableConstraints() {
80
- return {
81
- nodeHeight: { type: ["number", "null"] },
82
- nodeWidth: { type: ["number", "null"] },
83
- nodePageWidth: { type: ["boolean", "null"] },
84
- nodeFullWidth: { type: ["boolean", "null"] },
85
- };
86
- }
87
- // prosemirror-tables cell attrs; colwidth (number[] | null) is out of scope
88
- // of the scalar descriptor format and stays unconstrained.
89
- function cellConstraints() {
90
- return {
91
- colspan: { type: ["integer"], minimum: 1 },
92
- rowspan: { type: ["integer"], minimum: 1 },
93
- background: { type: ["string", "null"] },
94
- };
95
- }
96
- const matchesType = (type, value) => {
97
- switch (type) {
98
- case "string":
99
- return typeof value === "string";
100
- case "boolean":
101
- return typeof value === "boolean";
102
- case "number":
103
- return typeof value === "number" && Number.isFinite(value);
104
- case "integer":
105
- return typeof value === "number" && Number.isInteger(value);
106
- case "null":
107
- return value === null;
108
- default:
109
- return false;
110
- }
111
- };
112
- const describeType = (type) => {
113
- switch (type) {
114
- case "integer":
115
- return "an integer";
116
- case "number":
117
- return "a number";
118
- case "string":
119
- return "a string";
120
- case "boolean":
121
- return "a boolean";
122
- case "null":
123
- return "null";
124
- default:
125
- return String(type);
126
- }
127
- };
128
- const describeExpectation = (constraint) => {
129
- if (constraint.enum !== undefined) {
130
- return `one of [${constraint.enum.map((v) => JSON.stringify(v)).join(", ")}]`;
131
- }
132
- const types = (constraint.type ?? []).map(describeType).join(" or ");
133
- if (constraint.minimum !== undefined && constraint.maximum !== undefined) {
134
- return `${types} between ${constraint.minimum} and ${constraint.maximum}`;
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;
143
- };
144
- const checkConstraint = (constraint, value) => {
145
- if (constraint.enum !== undefined) {
146
- return constraint.enum.includes(value);
147
- }
148
- if (constraint.type !== undefined && !constraint.type.some((type) => matchesType(type, value))) {
149
- return false;
150
- }
151
- if (typeof value === "number") {
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;
160
- };
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
- const validateAttrValue = (nodeType, attr, value) => {
165
- const constraint = exports.NODE_ATTR_CONSTRAINTS[nodeType]?.[attr];
166
- if (constraint === undefined || checkConstraint(constraint, value)) {
167
- return null;
168
- }
169
- return `must be ${describeExpectation(constraint)}, got [${JSON.stringify(value)}]`;
170
- };
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
- const validateAttrs = (nodeType, attrs) => {
176
- const issues = [];
177
- for (const [attr, value] of Object.entries(attrs)) {
178
- const message = (0, exports.validateAttrValue)(nodeType, attr, value);
179
- if (message !== null) {
180
- issues.push({ attr, message });
181
- }
182
- }
183
- return issues;
184
- };
185
- exports.validateAttrs = validateAttrs;
@@ -1,7 +0,0 @@
1
- import type { Node, NodeType } from "prosemirror-model";
2
- export declare const getBlockIdAttr: (type: NodeType) => "id" | null;
3
- export declare const hasLegacyGuidAttr: (type: NodeType) => boolean;
4
- export declare const getBlockId: (node: Node) => string | null;
5
- export declare const buildBlockIdAttrs: (node: Node, nextId: string) => Record<string, unknown>;
6
- export declare const FIBERY_VIEW_TYPE = "fiberyView";
7
- export declare const getFiberyViewRef: (node: Node) => string | null;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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).
9
- const getBlockIdAttr = (type) => {
10
- if (type.isInline || type.name === "doc" || REFERENCE_ID_TYPES.has(type.name)) {
11
- return null;
12
- }
13
- const attrs = type.spec.attrs ?? {};
14
- return "id" in attrs ? "id" : null;
15
- };
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
- const hasLegacyGuidAttr = (type) => {
20
- const attrs = type.spec.attrs ?? {};
21
- return "guid" in attrs;
22
- };
23
- exports.hasLegacyGuidAttr = hasLegacyGuidAttr;
24
- const normalizeId = (value) => (typeof value === "string" && value !== "" ? value : null);
25
- // The effective block id: "id" with a fallback to the legacy "guid".
26
- const getBlockId = (node) => {
27
- if ((0, exports.getBlockIdAttr)(node.type) === null) {
28
- return null;
29
- }
30
- return normalizeId(node.attrs.id) ?? normalizeId(node.attrs.guid);
31
- };
32
- exports.getBlockId = getBlockId;
33
- // Attrs object with the block id set (and mirrored into "guid" on legacy types).
34
- const buildBlockIdAttrs = (node, nextId) => ({
35
- ...node.attrs,
36
- id: nextId,
37
- ...((0, exports.hasLegacyGuidAttr)(node.type) ? { guid: nextId } : {}),
38
- });
39
- exports.buildBlockIdAttrs = buildBlockIdAttrs;
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).
43
- const getFiberyViewRef = (node) => {
44
- if (node.type.name !== exports.FIBERY_VIEW_TYPE) {
45
- return null;
46
- }
47
- return normalizeId(node.attrs.viewId) ?? normalizeId(node.attrs.id);
48
- };
49
- exports.getFiberyViewRef = getFiberyViewRef;
@@ -1,18 +0,0 @@
1
- import type { Node } from "prosemirror-model";
2
- import { Schema, type NodeSpec, type MarkSpec } from "prosemirror-model";
3
- import type { EmojiOptions } from "./nodes/emoji";
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
- export declare const createSchema: ({ sharedColorGenerator, headingToDOM, mediaToDom, isImageBlockEnabled, fiberyViewEnabled, emojiOptions, }?: Params) => Schema;
13
- export declare const Basic: {
14
- nodes: Record<string, NodeSpec>;
15
- marks: Record<string, MarkSpec>;
16
- fibery: Record<string, MarkSpec>;
17
- };
18
- export {};
@@ -1,251 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Basic = exports.createSchema = void 0;
4
- const prosemirror_model_1 = require("prosemirror-model");
5
- const prosemirror_schema_basic_1 = require("prosemirror-schema-basic");
6
- const prosemirror_schema_list_1 = require("prosemirror-schema-list");
7
- const code_1 = require("./marks/code");
8
- const em_1 = require("./marks/em");
9
- const hint_query_1 = require("./marks/hint-query");
10
- const link_1 = require("./marks/link");
11
- const linked_highlight_1 = require("./marks/linked-highlight");
12
- const strike_1 = require("./marks/strike");
13
- const strong_1 = require("./marks/strong");
14
- const text_background_color_1 = require("./marks/text-background-color");
15
- const underline_1 = require("./marks/underline");
16
- const callout_1 = require("./nodes/callout");
17
- const check_item_1 = require("./nodes/check-item");
18
- const check_list_1 = require("./nodes/check-list");
19
- const code_block_1 = require("./nodes/code-block");
20
- const column_1 = require("./nodes/column");
21
- const columns_1 = require("./nodes/columns");
22
- const emoji_1 = require("./nodes/emoji");
23
- const entity_1 = require("./nodes/entity");
24
- const fibery_view_1 = require("./nodes/fibery-view");
25
- const file_1 = require("./nodes/file");
26
- const heading_1 = require("./nodes/heading");
27
- const image_block_1 = require("./nodes/image-block");
28
- const important_1 = require("./nodes/important");
29
- const math_display_1 = require("./nodes/math-display");
30
- const math_inline_1 = require("./nodes/math-inline");
31
- const media_1 = require("./nodes/media");
32
- const mention_1 = require("./nodes/mention");
33
- const note_1 = require("./nodes/note");
34
- const paragraph_1 = require("./nodes/paragraph");
35
- const table_nodes_1 = require("./nodes/table-nodes");
36
- const video_1 = require("./nodes/video");
37
- const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaToDom = null, isImageBlockEnabled = false, fiberyViewEnabled = false, emojiOptions, } = {}) => {
38
- prosemirror_schema_basic_1.nodes.code_block = code_block_1.code_block;
39
- prosemirror_schema_basic_1.nodes.paragraph = paragraph_1.paragraph;
40
- prosemirror_schema_basic_1.nodes.heading = (0, heading_1.makeHeading)({ headingToDOM });
41
- const base = new prosemirror_model_1.Schema({
42
- nodes: prosemirror_schema_basic_1.nodes,
43
- marks: {
44
- link: link_1.link,
45
- em: em_1.em,
46
- strong: strong_1.strong,
47
- code: code_1.code,
48
- linkedhighlight: (0, linked_highlight_1.makeLinkedHighlight)({ sharedColorGenerator }),
49
- linkedhighlightentity: (0, linked_highlight_1.makeLinkedHighlightEntity)({ sharedColorGenerator }),
50
- },
51
- });
52
- const customNodes = {
53
- note: note_1.note,
54
- important: important_1.important,
55
- entity: entity_1.entity,
56
- mention: mention_1.mention,
57
- media: (0, media_1.makeMedia)({ mediaToDom }),
58
- check_item: check_item_1.check_item,
59
- check_list: check_list_1.check_list,
60
- video: video_1.video,
61
- file: file_1.file,
62
- emoji: (0, emoji_1.makeEmoji)(emojiOptions),
63
- callout: (0, callout_1.makeCallout)(emojiOptions),
64
- columns: columns_1.columns,
65
- column: column_1.column,
66
- math_display: math_display_1.math_display,
67
- math_inline: math_inline_1.math_inline,
68
- };
69
- let actualNodes = (0, prosemirror_schema_list_1.addListNodes)(base.spec.nodes, "paragraph block*", "block")
70
- .append({ ...table_nodes_1.tableNodes })
71
- .append(customNodes);
72
- if (fiberyViewEnabled) {
73
- actualNodes = actualNodes.append({ fiberyView: fibery_view_1.fiberyView });
74
- }
75
- if (isImageBlockEnabled) {
76
- actualNodes = actualNodes.addToStart("imageBlock", image_block_1.imageBlock);
77
- }
78
- else {
79
- actualNodes = actualNodes.addToEnd("imageBlock", image_block_1.imageBlock);
80
- }
81
- actualNodes = actualNodes.update("doc", {
82
- content: `(block | columns)+`,
83
- });
84
- // prosemirror-tables@1.7.0+ added validate constraints to cell attrs
85
- // (colspan, rowspan, colwidth). Legacy Fibery documents may not satisfy
86
- // these validators. Drop all validators so those documents can still be parsed.
87
- for (const cellType of ["table_cell", "table_header"]) {
88
- const cellSpec = actualNodes.get(cellType);
89
- const attrsWithoutValidate = {};
90
- for (const [key, attrSpec] of Object.entries(cellSpec.attrs ?? {})) {
91
- const { validate: _, ...rest } = attrSpec;
92
- attrsWithoutValidate[key] = rest;
93
- }
94
- actualNodes = actualNodes.update(cellType, {
95
- ...cellSpec,
96
- attrs: attrsWithoutValidate,
97
- });
98
- }
99
- // prosemirror-schema-list@1.5.0+ added validate:"number" to the order attr,
100
- // which rejects legacy documents where order was stored as null. Drop the
101
- // validator so those documents can still be parsed.
102
- const orderedListSpec = actualNodes.get("ordered_list");
103
- actualNodes = actualNodes.update("ordered_list", {
104
- ...orderedListSpec,
105
- attrs: { order: { default: 1 } },
106
- });
107
- const listItemSpec = actualNodes.get("list_item");
108
- actualNodes = actualNodes.update("list_item", {
109
- ...listItemSpec,
110
- attrs: {
111
- ...listItemSpec.attrs,
112
- state: { default: null },
113
- id: { default: null },
114
- },
115
- parseDOM: [
116
- {
117
- tag: "li[data-check-item-state]",
118
- getAttrs: (dom) => {
119
- const el = dom;
120
- const state = el.getAttribute("data-check-item-state");
121
- // Strip the "[] "/"[x] " text prefix added by the clipboard serializer so
122
- // it doesn't appear as document content when pasting back into Fibery.
123
- // getAttrs runs before ProseMirror walks the children, so mutation is safe.
124
- const firstBlock = el.firstChild;
125
- if (firstBlock !== null && firstBlock.nodeType === 1 /* ELEMENT_NODE */) {
126
- const firstText = firstBlock.firstChild;
127
- if (firstText !== null && firstText.nodeType === 3 /* TEXT_NODE */) {
128
- const text = firstText.textContent ?? "";
129
- if (text.startsWith("[ ] ") || text.startsWith("[x] ")) {
130
- const rest = text.slice(4);
131
- if (rest) {
132
- firstText.textContent = rest;
133
- }
134
- else {
135
- firstBlock.removeChild(firstText);
136
- }
137
- }
138
- }
139
- }
140
- return {
141
- state: state === "TODO" || state === "DONE" ? state : null,
142
- id: el.getAttribute("data-list-item-id") ?? null,
143
- };
144
- },
145
- },
146
- {
147
- tag: "li",
148
- getAttrs: (dom) => {
149
- const el = dom;
150
- const firstChild = el.firstChild;
151
- if (firstChild === null) {
152
- return false;
153
- }
154
- // Support pasting from external editors that output [ ] / [x] as text
155
- // without data-check-item-state. Check text directly in <li> or inside
156
- // the first block element (e.g. <p>).
157
- let textNode = null;
158
- let textParent = null;
159
- if (firstChild.nodeType === 3 /* TEXT_NODE */) {
160
- textNode = firstChild;
161
- textParent = el;
162
- }
163
- else if (firstChild.nodeType === 1 /* ELEMENT_NODE */ && firstChild.firstChild?.nodeType === 3) {
164
- textNode = firstChild.firstChild;
165
- textParent = firstChild;
166
- }
167
- if (textNode === null) {
168
- return false;
169
- }
170
- const text = textNode.textContent ?? "";
171
- const state = text.startsWith("[ ] ") ? "TODO" : text.startsWith("[x] ") ? "DONE" : null;
172
- if (state === null) {
173
- return false;
174
- }
175
- const rest = text.slice(4);
176
- if (rest) {
177
- textNode.textContent = rest;
178
- }
179
- else {
180
- textParent.removeChild(textNode);
181
- }
182
- return { state, id: null };
183
- },
184
- },
185
- { tag: "li" },
186
- ],
187
- toDOM(node) {
188
- const { state, id } = node.attrs;
189
- const attrs = {};
190
- if (state) {
191
- attrs["data-check-item-state"] = state;
192
- }
193
- if (id) {
194
- attrs["data-list-item-id"] = id;
195
- }
196
- return Object.keys(attrs).length ? ["li", attrs, 0] : ["li", 0];
197
- },
198
- });
199
- // Every block node carries a unified "id" attr so blocks are addressable in
200
- // collaborative editing and block-level APIs. paragraph/heading/code_block
201
- // declare it in their own specs (mirrored into the deprecated "guid");
202
- // check_list/check_item/columns/fiberyView/list_item already have "id".
203
- // toDOM/parseDOM are deliberately left untouched here so pasted HTML never
204
- // carries an id and cannot introduce duplicates.
205
- const blocksNeedingId = [
206
- "blockquote",
207
- "horizontal_rule",
208
- "bullet_list",
209
- "ordered_list",
210
- "table",
211
- "table_row",
212
- "table_cell",
213
- "table_header",
214
- "note",
215
- "important",
216
- "callout",
217
- "media",
218
- "video",
219
- "imageBlock",
220
- "math_display",
221
- "column",
222
- ];
223
- for (const name of blocksNeedingId) {
224
- const spec = actualNodes.get(name);
225
- actualNodes = actualNodes.update(name, {
226
- ...spec,
227
- attrs: { ...spec.attrs, id: { default: null } },
228
- });
229
- }
230
- return new prosemirror_model_1.Schema({
231
- nodes: actualNodes,
232
- marks: base.spec.marks
233
- .addToEnd("strike", strike_1.strike)
234
- .addToEnd("underline", underline_1.underline)
235
- .addToEnd("hintQuery", hint_query_1.hintQuery)
236
- // We leave mark key as "highlight" only because we don't want to do migration.
237
- // "TextBackgroundColor" term is used everywhere through codebase.
238
- .addToEnd("highlight", text_background_color_1.textBackgroundColor),
239
- });
240
- };
241
- exports.createSchema = createSchema;
242
- exports.Basic = {
243
- nodes: prosemirror_schema_basic_1.nodes,
244
- marks: prosemirror_schema_basic_1.marks,
245
- fibery: {
246
- link: link_1.link,
247
- strike: strike_1.strike,
248
- underline: underline_1.underline,
249
- textBackgroundColor: text_background_color_1.textBackgroundColor,
250
- },
251
- };