@platecms/delta-cast 0.6.0 → 0.7.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.
@@ -1,190 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FORMATTING_PRIORITY = void 0;
4
- exports.normalizeCast = normalizeCast;
5
- exports.FORMATTING_PRIORITY = {
6
- bold: 1,
7
- italic: 2,
8
- underline: 3,
9
- strikethrough: 4,
10
- highlight: 5,
11
- };
12
- function hasChildren(node) {
13
- return "children" in node && Array.isArray(node.children);
14
- }
15
- function isFormattingNode(node) {
16
- const formattingTypes = ["bold", "italic", "underline", "strikethrough", "highlight"];
17
- return formattingTypes.includes(node.type);
18
- }
19
- function canMerge(node1, node2) {
20
- const mergeableTypes = ["bold", "italic", "underline", "strikethrough", "highlight", "text"];
21
- if (mergeableTypes.includes(node1.type) && node1.type === node2.type) {
22
- return true;
23
- }
24
- return false;
25
- }
26
- function mergeNodes(source, target) {
27
- if (source.type === "text" && target.type === "text") {
28
- target.value = source.value + target.value;
29
- }
30
- else if (source.type === target.type && hasChildren(source) && hasChildren(target)) {
31
- const sourceWithChildren = source;
32
- const targetWithChildren = target;
33
- targetWithChildren.children = [...sourceWithChildren.children, ...targetWithChildren.children];
34
- }
35
- }
36
- function shouldChildBeAboveParent(childType, parentType) {
37
- const childPriority = exports.FORMATTING_PRIORITY[childType] || 999;
38
- const parentPriority = exports.FORMATTING_PRIORITY[parentType] || 999;
39
- return childPriority < parentPriority;
40
- }
41
- function splitParentIntoSeparateNodes(grandParent, parent, child, parentIndexInGrandParent, childIndexInParent) {
42
- const siblingsBeforeChild = parent.children.slice(0, childIndexInParent);
43
- const siblingsAfterChild = parent.children.slice(childIndexInParent + 1);
44
- let insertionOffset = 0;
45
- if (siblingsBeforeChild.length > 0) {
46
- const newBeforeParent = { ...parent, children: siblingsBeforeChild };
47
- grandParent.children.splice(parentIndexInGrandParent, 0, newBeforeParent);
48
- insertionOffset = 1;
49
- }
50
- if (siblingsAfterChild.length > 0) {
51
- const newAfterParent = { ...parent, children: siblingsAfterChild };
52
- grandParent.children.splice(parentIndexInGrandParent + 1 + insertionOffset, 0, newAfterParent);
53
- }
54
- parent.children = [child];
55
- return insertionOffset;
56
- }
57
- function processFormattingChild(grandParent, parent, child, parentIndexInGrandParent, childIndexInParent) {
58
- if (!shouldChildBeAboveParent(child.type, parent.type)) {
59
- return false;
60
- }
61
- let parentIndexInGrandParentOffset = 0;
62
- if (parent.children.length > 1) {
63
- parentIndexInGrandParentOffset += splitParentIntoSeparateNodes(grandParent, parent, child, parentIndexInGrandParent, childIndexInParent);
64
- }
65
- parent.children = child.children;
66
- child.children = [parent];
67
- grandParent.children[parentIndexInGrandParent + parentIndexInGrandParentOffset] = child;
68
- return true;
69
- }
70
- function bubbleFormattingNodes(node, parent, nodeIndexInParent) {
71
- let hasChanges = false;
72
- if (!hasChildren(node)) {
73
- return hasChanges;
74
- }
75
- for (let i = 0; i < node.children.length; i++) {
76
- const child = node.children[i];
77
- if (hasChildren(child)) {
78
- hasChanges = bubbleFormattingNodes(child, node, i) || hasChanges;
79
- }
80
- }
81
- if (!isFormattingNode(node)) {
82
- return hasChanges;
83
- }
84
- if (!parent || nodeIndexInParent === undefined) {
85
- return hasChanges;
86
- }
87
- for (let i = 0; i < node.children.length; i++) {
88
- const child = node.children[i];
89
- if (isFormattingNode(child) && hasChildren(child)) {
90
- hasChanges = processFormattingChild(parent, node, child, nodeIndexInParent, i) || hasChanges;
91
- }
92
- }
93
- return hasChanges;
94
- }
95
- function shouldRemoveEmptyNode(node) {
96
- if (!isFormattingNode(node)) {
97
- return false;
98
- }
99
- if (!hasChildren(node) || node.children.length === 0) {
100
- return true;
101
- }
102
- return false;
103
- }
104
- function mergeAdjacentNodes(node) {
105
- let hasChanges = false;
106
- for (let i = 0; i < node.children.length - 1; i++) {
107
- const current = node.children[i];
108
- const next = node.children[i + 1];
109
- if (canMerge(current, next)) {
110
- mergeNodes(current, next);
111
- node.children.splice(i, 1);
112
- hasChanges = true;
113
- i--;
114
- }
115
- }
116
- for (const child of node.children) {
117
- if (hasChildren(child)) {
118
- hasChanges = mergeAdjacentNodes(child) || hasChanges;
119
- }
120
- }
121
- return hasChanges;
122
- }
123
- function reorderFormattingNodes(node) {
124
- let hasChanges = true;
125
- let anyChanges = false;
126
- while (hasChanges) {
127
- hasChanges = false;
128
- hasChanges = bubbleFormattingNodes(node) || hasChanges;
129
- if (hasChanges) {
130
- anyChanges = true;
131
- }
132
- }
133
- return anyChanges;
134
- }
135
- function removeDuplicateFormatting(node, ancestorsFormattingNodeTypes, parent, nodeIndexInParent) {
136
- let hasChanges = false;
137
- if (!hasChildren(node)) {
138
- return hasChanges;
139
- }
140
- const newAncestorsFormattingNodeTypes = isFormattingNode(node)
141
- ? [...ancestorsFormattingNodeTypes, node.type]
142
- : ancestorsFormattingNodeTypes;
143
- for (let i = 0; i < node.children.length; i++) {
144
- const child = node.children[i];
145
- if (hasChildren(child)) {
146
- hasChanges = removeDuplicateFormatting(child, newAncestorsFormattingNodeTypes, node, i) || hasChanges;
147
- }
148
- }
149
- if (!parent || nodeIndexInParent === undefined) {
150
- return hasChanges;
151
- }
152
- if (ancestorsFormattingNodeTypes.includes(node.type)) {
153
- parent.children.splice(nodeIndexInParent, 1, ...node.children);
154
- hasChanges = true;
155
- }
156
- return hasChanges;
157
- }
158
- function cleanupEmptyNodes(node) {
159
- let hasChanges = false;
160
- if (!hasChildren(node)) {
161
- return hasChanges;
162
- }
163
- for (let i = node.children.length - 1; i >= 0; i--) {
164
- const child = node.children[i];
165
- if (hasChildren(child)) {
166
- hasChanges = cleanupEmptyNodes(child) || hasChanges;
167
- }
168
- }
169
- for (let i = node.children.length - 1; i >= 0; i--) {
170
- const child = node.children[i];
171
- if (shouldRemoveEmptyNode(child)) {
172
- node.children.splice(i, 1);
173
- hasChanges = true;
174
- }
175
- }
176
- return hasChanges;
177
- }
178
- function normalizeCast(root) {
179
- let hasChanges = true;
180
- const currentRoot = JSON.parse(JSON.stringify(root));
181
- while (hasChanges) {
182
- hasChanges = false;
183
- hasChanges = mergeAdjacentNodes(currentRoot) || hasChanges;
184
- hasChanges = reorderFormattingNodes(currentRoot) || hasChanges;
185
- hasChanges = removeDuplicateFormatting(currentRoot, []) || hasChanges;
186
- hasChanges = cleanupEmptyNodes(currentRoot) || hasChanges;
187
- }
188
- return currentRoot;
189
- }
190
- //# sourceMappingURL=normalize-cast.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalize-cast.js","sourceRoot":"","sources":["../../../../../../packages/cast/src/lib/normalize-cast.ts"],"names":[],"mappings":";;;AAgXA,sCAqBC;AA/XY,QAAA,mBAAmB,GAAG;IACjC,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,SAAS,EAAE,CAAC;IACZ,aAAa,EAAE,CAAC;IAChB,SAAS,EAAE,CAAC;CACJ,CAAC;AAKX,SAAS,WAAW,CAAC,IAAsB;IACzC,OAAO,UAAU,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAE,IAA8B,CAAC,QAAQ,CAAC,CAAC;AACvF,CAAC;AAKD,SAAS,gBAAgB,CAAC,IAAa;IACrC,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,CAAC,CAAC;IACtF,OAAO,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC7C,CAAC;AAKD,SAAS,QAAQ,CAAC,KAAc,EAAE,KAAc;IAE9C,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;IAC7F,IAAI,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;QACrE,OAAO,IAAI,CAAC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,CAAC,IAAI,UAAU,CAAC;QAG/D,UAAU,GAAG,yBAAyB,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC;QAGtE,UAAU,GAAG,iBAAiB,CAAC,WAAW,CAAC,IAAI,UAAU,CAAC;IAC5D,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
@@ -1,105 +0,0 @@
1
- import { Node, Literal as UnistLiteral, Parent as UnistParent } from "unist";
2
- export type Content = BlockContent | InlineContent;
3
- export type BlockContent = BlockContentMap[keyof BlockContentMap];
4
- export type InlineContent = InlineContentMap[keyof InlineContentMap];
5
- export interface BlockContentMap {
6
- paragraph: Paragraph;
7
- heading: Heading;
8
- list: List;
9
- listItem: ListItem;
10
- blockquote: Blockquote;
11
- code: Code;
12
- }
13
- export interface InlineContentMap {
14
- text: Text;
15
- bold: Bold;
16
- italic: Italic;
17
- underline: Underline;
18
- strikethrough: Strikethrough;
19
- inlineCode: InlineCode;
20
- highlight: Highlight;
21
- contentValue: InterpolatedContentValue;
22
- externalLink: ExternalLink;
23
- internalLink: InternalLink;
24
- }
25
- export interface Parent extends UnistParent {
26
- children: Content[];
27
- }
28
- export interface Literal extends UnistLiteral {
29
- value: string;
30
- }
31
- export interface Root extends Parent {
32
- type: "root";
33
- }
34
- export interface Paragraph extends Parent {
35
- type: "paragraph";
36
- children: InlineContent[];
37
- }
38
- export interface Heading extends Parent {
39
- type: "heading";
40
- level: 1 | 2 | 3 | 4 | 5 | 6;
41
- children: InlineContent[];
42
- }
43
- export interface List extends Parent {
44
- type: "list";
45
- children: ListItem[];
46
- ordered: boolean;
47
- start?: number;
48
- }
49
- export interface ListItem extends Parent {
50
- type: "listItem";
51
- children: InlineContent[];
52
- }
53
- export interface Blockquote extends Parent {
54
- type: "blockquote";
55
- children: InlineContent[];
56
- }
57
- export interface Code extends Parent {
58
- type: "code";
59
- lang?: string;
60
- children: Text[];
61
- }
62
- export interface Text extends Literal {
63
- type: "text";
64
- }
65
- export interface Bold extends Parent {
66
- type: "bold";
67
- children: InlineContent[];
68
- }
69
- export interface Italic extends Parent {
70
- type: "italic";
71
- children: InlineContent[];
72
- }
73
- export interface Underline extends Parent {
74
- type: "underline";
75
- children: InlineContent[];
76
- }
77
- export interface Strikethrough extends Parent {
78
- type: "strikethrough";
79
- children: InlineContent[];
80
- }
81
- export interface InlineCode extends Literal {
82
- type: "inlineCode";
83
- }
84
- export interface Highlight extends Parent {
85
- type: "highlight";
86
- children: InlineContent[];
87
- }
88
- export interface InterpolatedContentValue extends Node {
89
- type: "contentValue";
90
- prn: string;
91
- value?: Root;
92
- }
93
- export interface ExternalLink extends Parent {
94
- type: "externalLink";
95
- children: Text[];
96
- url: string;
97
- target?: "_parent" | "_top" | "blank" | "self";
98
- }
99
- export interface InternalLink extends Parent {
100
- type: "internalLink";
101
- children: Text[];
102
- prn: string;
103
- url?: string;
104
- target?: "_parent" | "_top" | "blank" | "self";
105
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=schema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../../../packages/cast/src/lib/schemas/schema.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export declare const URL_REGEX: RegExp;
2
- export declare function validateCast(value: unknown): void;
@@ -1,149 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.URL_REGEX = void 0;
4
- exports.validateCast = validateCast;
5
- const invalid_cast_error_1 = require("./invalid-cast.error");
6
- const delta_plate_resource_notation_1 = require("@platecms/delta-plate-resource-notation");
7
- exports.URL_REGEX = /^(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)|mailto:[^\s@]+@[^\s@]+\.[^\s@]+|tel:\+?[0-9\s\-().]{7,}|\/[^\s]*)$/u;
8
- function assertNonNullObject(value) {
9
- if (typeof value !== "object" || value == null) {
10
- throw new invalid_cast_error_1.InvalidCastError(`Invalid object`);
11
- }
12
- }
13
- function assertTextNode(value) {
14
- assertNonNullObject(value);
15
- if ("type" in value && typeof value.type === "string" && value.type !== "text") {
16
- throw new invalid_cast_error_1.InvalidCastError(`Invalid node: ${value.type} node is not a text node`);
17
- }
18
- }
19
- function assertValidParent(value) {
20
- assertNonNullObject(value);
21
- const parent = value;
22
- if (!Array.isArray(parent.children)) {
23
- throw new invalid_cast_error_1.InvalidCastError("Invalid parent: children is not an array");
24
- }
25
- parent.children.forEach(assertValidContent);
26
- }
27
- function assertValidLiteral(value) {
28
- assertNonNullObject(value);
29
- const literal = value;
30
- if (typeof literal.value !== "string") {
31
- throw new invalid_cast_error_1.InvalidCastError("Invalid literal: value is not a string");
32
- }
33
- }
34
- function assertValidHeading(value) {
35
- assertNonNullObject(value);
36
- const list = value;
37
- if (typeof list.level !== "number" || list.level < 1 || list.level > 6) {
38
- throw new invalid_cast_error_1.InvalidCastError("Invalid heading");
39
- }
40
- assertValidParent(list);
41
- }
42
- function assertValidList(value) {
43
- assertNonNullObject(value);
44
- const list = value;
45
- if (typeof list.ordered !== "boolean" || (list.start != null && typeof list.start !== "number")) {
46
- throw new invalid_cast_error_1.InvalidCastError("Invalid list");
47
- }
48
- assertValidParent(list);
49
- }
50
- function assertValidCode(value) {
51
- assertNonNullObject(value);
52
- const code = value;
53
- if (code.lang != null && typeof code.lang !== "string") {
54
- throw new invalid_cast_error_1.InvalidCastError("Invalid code");
55
- }
56
- assertValidParent(code);
57
- }
58
- function assertValidInterpolatedContentValue(value) {
59
- assertNonNullObject(value);
60
- const contentValue = value;
61
- try {
62
- delta_plate_resource_notation_1.PRN.fromString(contentValue.prn);
63
- }
64
- catch (error) {
65
- if (error instanceof delta_plate_resource_notation_1.InvalidPrnError) {
66
- throw new invalid_cast_error_1.InvalidCastError(`Invalid contentValue: invalid PRN ${contentValue.prn}`);
67
- }
68
- throw error;
69
- }
70
- }
71
- function assertValidExternalLink(value) {
72
- assertNonNullObject(value);
73
- assertValidParent(value);
74
- const link = value;
75
- if (typeof link.url !== "string") {
76
- throw new invalid_cast_error_1.InvalidCastError(`Invalid link: invalid url`);
77
- }
78
- if (!exports.URL_REGEX.test(link.url)) {
79
- throw new invalid_cast_error_1.InvalidCastError(`Invalid link: invalid url ${link.url}`);
80
- }
81
- link.children.forEach(assertTextNode);
82
- }
83
- function assertValidInternalLink(value) {
84
- assertNonNullObject(value);
85
- assertValidParent(value);
86
- const link = value;
87
- try {
88
- delta_plate_resource_notation_1.PRN.fromString(link.prn);
89
- }
90
- catch (error) {
91
- if (error instanceof delta_plate_resource_notation_1.InvalidPrnError) {
92
- throw new invalid_cast_error_1.InvalidCastError(`Invalid link: invalid PRN ${link.prn}`);
93
- }
94
- throw error;
95
- }
96
- link.children.forEach(assertTextNode);
97
- }
98
- function assertValidContent(value) {
99
- assertNonNullObject(value);
100
- const content = value;
101
- switch (content.type) {
102
- case "paragraph":
103
- case "listItem":
104
- case "blockquote":
105
- case "bold":
106
- case "italic":
107
- case "underline":
108
- case "strikethrough":
109
- case "highlight":
110
- assertValidParent(content);
111
- break;
112
- case "externalLink":
113
- assertValidExternalLink(content);
114
- break;
115
- case "internalLink":
116
- assertValidInternalLink(content);
117
- break;
118
- case "heading":
119
- assertValidHeading(content);
120
- break;
121
- case "text":
122
- case "inlineCode":
123
- assertValidLiteral(content);
124
- break;
125
- case "list":
126
- assertValidList(content);
127
- break;
128
- case "code":
129
- assertValidCode(content);
130
- break;
131
- case "contentValue":
132
- assertValidInterpolatedContentValue(content);
133
- break;
134
- default:
135
- throw new invalid_cast_error_1.InvalidCastError(`Invalid Content type '${content.type}'.`);
136
- }
137
- }
138
- function validateCast(value) {
139
- assertNonNullObject(value);
140
- const root = value;
141
- if (root.type !== "root") {
142
- throw new invalid_cast_error_1.InvalidCastError("Invalid root: type is not 'root'");
143
- }
144
- if (!Array.isArray(root.children)) {
145
- throw new invalid_cast_error_1.InvalidCastError("Invalid root: children is not an array");
146
- }
147
- root.children.forEach(assertValidContent);
148
- }
149
- //# sourceMappingURL=validate-cast.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validate-cast.js","sourceRoot":"","sources":["../../../../../../packages/cast/src/lib/validate-cast.ts"],"names":[],"mappings":";;;AAwLA,oCAaC;AAxLD,6DAAwD;AACxD,2FAA+E;AAMlE,QAAA,SAAS,GACpB,8KAA8K,CAAC;AAEjL,SAAS,mBAAmB,CAAC,KAAc;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAC/C,MAAM,IAAI,qCAAgB,CAAC,gBAAgB,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACpC,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAE3B,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC/E,MAAM,IAAI,qCAAgB,CAAC,iBAAiB,KAAK,CAAC,IAAI,0BAA0B,CAAC,CAAC;IACpF,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACvC,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAE3B,MAAM,MAAM,GAAG,KAAe,CAAC;IAC/B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,qCAAgB,CAAC,0CAA0C,CAAC,CAAC;IACzE,CAAC;IAGD,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAc;IACxC,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAE3B,MAAM,OAAO,GAAG,KAAgB,CAAC;IACjC,IAA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