@fibery/prosemirror-schema 4.22.0 → 4.23.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.
Files changed (79) hide show
  1. package/lib/index.d.ts +10 -10
  2. package/lib/index.js +9 -31
  3. package/lib/src/attr-constraints.d.ts +15 -12
  4. package/lib/src/attr-constraints.js +128 -168
  5. package/lib/src/block-id-utils.d.ts +10 -7
  6. package/lib/src/block-id-utils.js +16 -39
  7. package/lib/src/create-schema.d.ts +16 -15
  8. package/lib/src/create-schema.js +204 -249
  9. package/lib/src/marks/code.d.ts +5 -2
  10. package/lib/src/marks/code.js +10 -10
  11. package/lib/src/marks/em.d.ts +5 -2
  12. package/lib/src/marks/em.js +19 -16
  13. package/lib/src/marks/hint-query.d.ts +5 -2
  14. package/lib/src/marks/hint-query.js +19 -22
  15. package/lib/src/marks/link.d.ts +5 -2
  16. package/lib/src/marks/link.js +40 -36
  17. package/lib/src/marks/linked-highlight.d.ts +9 -7
  18. package/lib/src/marks/linked-highlight.js +38 -51
  19. package/lib/src/marks/strike.d.ts +5 -2
  20. package/lib/src/marks/strike.js +6 -6
  21. package/lib/src/marks/strong.d.ts +5 -2
  22. package/lib/src/marks/strong.js +29 -29
  23. package/lib/src/marks/text-background-color.d.ts +15 -12
  24. package/lib/src/marks/text-background-color.js +63 -81
  25. package/lib/src/marks/underline.d.ts +5 -2
  26. package/lib/src/marks/underline.js +6 -6
  27. package/lib/src/nodes/callout.d.ts +29 -26
  28. package/lib/src/nodes/callout.js +55 -58
  29. package/lib/src/nodes/check-item.d.ts +13 -10
  30. package/lib/src/nodes/check-item.js +32 -33
  31. package/lib/src/nodes/check-list.d.ts +14 -11
  32. package/lib/src/nodes/check-list.js +23 -30
  33. package/lib/src/nodes/code-block.d.ts +5 -2
  34. package/lib/src/nodes/code-block.js +70 -101
  35. package/lib/src/nodes/column.d.ts +5 -2
  36. package/lib/src/nodes/column.js +28 -34
  37. package/lib/src/nodes/columns.d.ts +5 -2
  38. package/lib/src/nodes/columns.js +34 -36
  39. package/lib/src/nodes/emoji.d.ts +28 -26
  40. package/lib/src/nodes/emoji.js +38 -47
  41. package/lib/src/nodes/entity.d.ts +18 -16
  42. package/lib/src/nodes/entity.js +48 -49
  43. package/lib/src/nodes/fibery-view.d.ts +5 -2
  44. package/lib/src/nodes/fibery-view.js +38 -42
  45. package/lib/src/nodes/file.d.ts +37 -34
  46. package/lib/src/nodes/file.js +41 -40
  47. package/lib/src/nodes/heading.d.ts +6 -3
  48. package/lib/src/nodes/heading.js +57 -33
  49. package/lib/src/nodes/image-block.d.ts +5 -2
  50. package/lib/src/nodes/image-block.js +43 -42
  51. package/lib/src/nodes/important.d.ts +5 -2
  52. package/lib/src/nodes/important.js +14 -10
  53. package/lib/src/nodes/math-display.d.ts +5 -2
  54. package/lib/src/nodes/math-display.js +14 -15
  55. package/lib/src/nodes/math-inline.d.ts +5 -2
  56. package/lib/src/nodes/math-inline.js +14 -15
  57. package/lib/src/nodes/media.d.ts +6 -3
  58. package/lib/src/nodes/media.js +52 -68
  59. package/lib/src/nodes/mention.d.ts +12 -9
  60. package/lib/src/nodes/mention.js +36 -37
  61. package/lib/src/nodes/note.d.ts +5 -2
  62. package/lib/src/nodes/note.js +14 -10
  63. package/lib/src/nodes/paragraph.d.ts +5 -2
  64. package/lib/src/nodes/paragraph.js +32 -26
  65. package/lib/src/nodes/table-nodes.d.ts +5 -2
  66. package/lib/src/nodes/table-nodes.js +16 -20
  67. package/lib/src/nodes/types/inline-content.d.ts +10 -8
  68. package/lib/src/nodes/types/inline-content.js +0 -2
  69. package/lib/src/nodes/types/text.d.ts +7 -4
  70. package/lib/src/nodes/types/text.js +0 -2
  71. package/lib/src/nodes/video.d.ts +7 -4
  72. package/lib/src/nodes/video.js +49 -54
  73. package/lib/src/resizable-node-attrs.d.ts +29 -26
  74. package/lib/src/resizable-node-attrs.js +23 -34
  75. package/lib/src/transcription-node-attrs.d.ts +10 -7
  76. package/lib/src/transcription-node-attrs.js +8 -8
  77. package/lib/test-helpers/index.d.ts +7 -4
  78. package/lib/test-helpers/index.js +11 -15
  79. package/package.json +11 -4
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 { defaultHeight, defaultWidth } from "./src/resizable-node-attrs.js";
2
+ import { EmojiOptions } from "./src/nodes/emoji.js";
3
+ import { Basic, createSchema } from "./src/create-schema.js";
4
+ import { AttrConstraint, AttrConstraintType, AttrValidationIssue, NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs } from "./src/attr-constraints.js";
5
+ import { FIBERY_VIEW_TYPE, buildBlockIdAttrs, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr } from "./src/block-id-utils.js";
6
+ import { DEFAULT_VIDEO_HEIGHT, DEFAULT_VIDEO_WIDTH } from "./src/nodes/video.js";
7
+ import { DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE } from "./src/nodes/callout.js";
8
+ import { ColorToken } from "./src/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 { defaultHeight, defaultWidth } from "./src/resizable-node-attrs.js";
2
+ import { ColorToken } from "./src/marks/text-background-color.js";
3
+ import { DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE } from "./src/nodes/callout.js";
4
+ import { DEFAULT_VIDEO_HEIGHT, DEFAULT_VIDEO_WIDTH } from "./src/nodes/video.js";
5
+ import { Basic, createSchema } from "./src/create-schema.js";
6
+ import { NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs } from "./src/attr-constraints.js";
7
+ import { FIBERY_VIEW_TYPE, buildBlockIdAttrs, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr } from "./src/block-id-utils.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 };
@@ -1,14 +1,17 @@
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;
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;
7
8
  };
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;
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;
13
14
  };
14
- export declare const validateAttrs: (nodeType: string, attrs: Record<string, unknown>) => AttrValidationIssue[];
15
+ declare const validateAttrs: (nodeType: string, attrs: Record<string, unknown>) => AttrValidationIssue[];
16
+ //#endregion
17
+ export { AttrConstraint, AttrConstraintType, AttrValidationIssue, NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs };
@@ -1,185 +1,145 @@
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
- },
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() }
75
69
  };
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
70
  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
- };
71
+ return {
72
+ nodeHeight: { type: ["number", "null"] },
73
+ nodeWidth: { type: ["number", "null"] },
74
+ nodePageWidth: { type: ["boolean", "null"] },
75
+ nodeFullWidth: { type: ["boolean", "null"] }
76
+ };
86
77
  }
87
- // prosemirror-tables cell attrs; colwidth (number[] | null) is out of scope
88
- // of the scalar descriptor format and stays unconstrained.
89
78
  function cellConstraints() {
90
- return {
91
- colspan: { type: ["integer"], minimum: 1 },
92
- rowspan: { type: ["integer"], minimum: 1 },
93
- background: { type: ["string", "null"] },
94
- };
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
+ };
95
90
  }
96
91
  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
- }
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
+ }
111
100
  };
112
101
  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
- }
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
+ }
127
110
  };
128
111
  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;
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;
143
118
  };
144
119
  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;
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;
160
127
  };
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
128
  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)}]`;
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)}]`;
170
132
  };
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
133
  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;
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;
184
143
  };
185
- exports.validateAttrs = validateAttrs;
144
+ //#endregion
145
+ export { NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs };
@@ -1,7 +1,10 @@
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
+ 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 };
@@ -1,49 +1,26 @@
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).
1
+ //#region src/block-id-utils.ts
2
+ const REFERENCE_ID_TYPES = /* @__PURE__ */ new Set(["fiberyView"]);
9
3
  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;
4
+ if (type.isInline || type.name === "doc" || REFERENCE_ID_TYPES.has(type.name)) return null;
5
+ return "id" in (type.spec.attrs ?? {}) ? "id" : null;
15
6
  };
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
7
  const hasLegacyGuidAttr = (type) => {
20
- const attrs = type.spec.attrs ?? {};
21
- return "guid" in attrs;
8
+ return "guid" in (type.spec.attrs ?? {});
22
9
  };
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".
10
+ const normalizeId = (value) => typeof value === "string" && value !== "" ? value : null;
26
11
  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);
12
+ if (getBlockIdAttr(node.type) === null) return null;
13
+ return normalizeId(node.attrs.id) ?? normalizeId(node.attrs.guid);
31
14
  };
32
- exports.getBlockId = getBlockId;
33
- // Attrs object with the block id set (and mirrored into "guid" on legacy types).
34
15
  const buildBlockIdAttrs = (node, nextId) => ({
35
- ...node.attrs,
36
- id: nextId,
37
- ...((0, exports.hasLegacyGuidAttr)(node.type) ? { guid: nextId } : {}),
16
+ ...node.attrs,
17
+ id: nextId,
18
+ ...hasLegacyGuidAttr(node.type) ? { guid: nextId } : {}
38
19
  });
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).
20
+ const FIBERY_VIEW_TYPE = "fiberyView";
43
21
  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);
22
+ if (node.type.name !== "fiberyView") return null;
23
+ return normalizeId(node.attrs.viewId) ?? normalizeId(node.attrs.id);
48
24
  };
49
- exports.getFiberyViewRef = getFiberyViewRef;
25
+ //#endregion
26
+ export { FIBERY_VIEW_TYPE, buildBlockIdAttrs, getBlockId, getBlockIdAttr, getFiberyViewRef, hasLegacyGuidAttr };
@@ -1,18 +1,19 @@
1
- import type { Node } from "prosemirror-model";
2
- import { Schema, type NodeSpec, type MarkSpec } from "prosemirror-model";
3
- import type { EmojiOptions } from "./nodes/emoji";
1
+ import { EmojiOptions } from "./nodes/emoji.js";
2
+ import { MarkSpec, Node, NodeSpec, Schema } from "prosemirror-model";
3
+ //#region src/create-schema.d.ts
4
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;
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
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>;
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
17
  };
18
- export {};
18
+ //#endregion
19
+ export { Basic, createSchema };