@supernova-studio/client 0.52.17 → 0.52.19

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supernova-studio/client",
3
- "version": "0.52.17",
3
+ "version": "0.52.19",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -36,6 +36,7 @@ export const DTOFigmaComponent = z.object({
36
36
 
37
37
  parentComponentPersistentId: z.string().optional(),
38
38
  componentPropertyDefinitions: DTOFigmaComponentPropertyMap.optional(),
39
+ childrenPersistentIds: z.string().array().optional(),
39
40
  });
40
41
 
41
42
  export const DTOFigmaComponentListResponse = z.object({
@@ -4,6 +4,10 @@ import {
4
4
  PageBlockDefinitionProperty,
5
5
  PageBlockDefinitionRichTextOptions,
6
6
  PageBlockItemImageValue,
7
+ PageBlockItemRichTextEditorListNode,
8
+ PageBlockItemRichTextEditorNode,
9
+ PageBlockItemRichTextEditorParagraphNode,
10
+ PageBlockItemRichTextEditorValue,
7
11
  PageBlockItemRichTextValue,
8
12
  PageBlockItemTableCell,
9
13
  PageBlockItemTableNode,
@@ -23,7 +27,7 @@ import * as Y from "yjs";
23
27
  import { ListNode, ListTreeBuilder } from "./list-tree-builder";
24
28
  import { DocumentationPageEditorModel } from "./model";
25
29
  import { PageBlockEditorModel, PageSectionEditorModel } from "./model/block";
26
- import { pmSchema } from "./prosemirror";
30
+ import { mainEditorProsemirrorSchema } from "./prosemirror";
27
31
  import { ProsemirrorMark, ProsemirrorNode } from "./prosemirror/types";
28
32
  import { BlockDefinitionUtils, BlockParsingUtils } from "./utils";
29
33
 
@@ -59,7 +63,7 @@ export function pageToYXmlFragment(
59
63
  ): Y.XmlFragment {
60
64
  const doc = pageToProsemirrorDoc(page, definitions);
61
65
  // console.log(JSON.stringify(doc, null, 2));
62
- return prosemirrorJSONToYXmlFragment(pmSchema, doc, fragment);
66
+ return prosemirrorJSONToYXmlFragment(mainEditorProsemirrorSchema, doc, fragment);
63
67
  }
64
68
 
65
69
  export function pageToProsemirrorDoc(
@@ -103,6 +107,59 @@ export function blockToProsemirrorNode(
103
107
  return nodes[0] ?? null;
104
108
  }
105
109
 
110
+ export function richTextPropertyValueToProsemirror(
111
+ richTextEditorValue: PageBlockItemRichTextEditorValue
112
+ ): ProsemirrorNode {
113
+ return {
114
+ type: "doc",
115
+ content: richTextEditorValue.value.map(node => {
116
+ return serializeRichTextEditorNode(node);
117
+ }),
118
+ };
119
+ }
120
+
121
+ function serializeRichTextEditorNode(node: PageBlockItemRichTextEditorNode): ProsemirrorNode {
122
+ switch (node.type) {
123
+ case "Paragraph":
124
+ return serializeRichTextEditorParagraphNode(node);
125
+
126
+ case "List":
127
+ return serializeRichTextEditorListNode(node);
128
+ }
129
+ }
130
+
131
+ function serializeRichTextEditorParagraphNode(node: PageBlockItemRichTextEditorParagraphNode): ProsemirrorNode {
132
+ const content = serializeRichText(node.value);
133
+ return {
134
+ type: "paragraph",
135
+ ...(content.length && { content }),
136
+ };
137
+ }
138
+
139
+ function serializeRichTextEditorListNode(node: PageBlockItemRichTextEditorListNode): ProsemirrorNode {
140
+ const type = node.listType === "OL" ? "orderedList" : "bulletList";
141
+ const attrs = node.listType === "OL" ? { start: 1 } : undefined;
142
+ const richTexts = node.value.length ? node.value : [{ spans: [] }];
143
+
144
+ return {
145
+ type,
146
+ ...(attrs && { attrs }),
147
+ content: richTexts.map(n => {
148
+ const content = serializeRichText(n);
149
+
150
+ return {
151
+ type: "listItem",
152
+ content: [
153
+ {
154
+ type: "paragraph",
155
+ ...(content.length && { content }),
156
+ },
157
+ ],
158
+ };
159
+ }),
160
+ };
161
+ }
162
+
106
163
  //
107
164
  // Sections
108
165
  //
@@ -1,2 +1,3 @@
1
- export * from "./schema";
1
+ export * from "./inner-editor-schema";
2
+ export * from "./main-editor-schema";
2
3
  export * from "./types";
@@ -0,0 +1,145 @@
1
+ import { Schema } from "prosemirror-model";
2
+
3
+ const pmSchemaJson = {
4
+ topNode: "doc",
5
+ nodes: {
6
+ paragraph: {
7
+ content: "inline*",
8
+ group: "block",
9
+ parseDOM: [
10
+ {
11
+ tag: "p",
12
+ },
13
+ ],
14
+ },
15
+ listItem: {
16
+ content: "paragraph",
17
+ defining: true,
18
+ parseDOM: [
19
+ {
20
+ tag: "li",
21
+ },
22
+ ],
23
+ },
24
+ doc: {
25
+ content: "block+",
26
+ },
27
+ hardBreak: {
28
+ group: "inline",
29
+ inline: true,
30
+ selectable: false,
31
+ parseDOM: [
32
+ {
33
+ tag: "br",
34
+ },
35
+ ],
36
+ },
37
+ text: {
38
+ group: "inline",
39
+ },
40
+ bulletList: {
41
+ content: "listItem+",
42
+ group: "block list",
43
+ parseDOM: [
44
+ {
45
+ tag: "ul",
46
+ },
47
+ ],
48
+ },
49
+ orderedList: {
50
+ content: "listItem+",
51
+ group: "block list",
52
+ attrs: {
53
+ start: {
54
+ default: 1,
55
+ },
56
+ type: {
57
+ default: null,
58
+ },
59
+ },
60
+ parseDOM: [
61
+ {
62
+ tag: "ol",
63
+ },
64
+ ],
65
+ },
66
+ },
67
+ marks: {
68
+ link: {
69
+ inclusive: false,
70
+ attrs: {
71
+ href: {
72
+ default: null,
73
+ },
74
+ target: {
75
+ default: "_blank",
76
+ },
77
+ rel: {
78
+ default: "noopener noreferrer nofollow",
79
+ },
80
+ class: {
81
+ default: "tiptap-link",
82
+ },
83
+ },
84
+ parseDOM: [
85
+ {
86
+ tag: "a[href]",
87
+ },
88
+ ],
89
+ },
90
+ bold: {
91
+ parseDOM: [
92
+ {
93
+ tag: "strong",
94
+ },
95
+ {
96
+ tag: "b",
97
+ },
98
+ {
99
+ style: "font-weight",
100
+ },
101
+ ],
102
+ },
103
+ italic: {
104
+ parseDOM: [
105
+ {
106
+ tag: "em",
107
+ },
108
+ {
109
+ tag: "i",
110
+ },
111
+ {
112
+ style: "font-style=italic",
113
+ },
114
+ ],
115
+ },
116
+ strike: {
117
+ parseDOM: [
118
+ {
119
+ tag: "s",
120
+ },
121
+ {
122
+ tag: "del",
123
+ },
124
+ {
125
+ tag: "strike",
126
+ },
127
+ {
128
+ style: "text-decoration",
129
+ consuming: false,
130
+ },
131
+ ],
132
+ },
133
+ code: {
134
+ excludes: "bold code italic strike link",
135
+ code: true,
136
+ parseDOM: [
137
+ {
138
+ tag: "code",
139
+ },
140
+ ],
141
+ },
142
+ },
143
+ } as const;
144
+
145
+ export const innerEditorProsemirrorSchema = new Schema(pmSchemaJson);
@@ -1,6 +1,6 @@
1
1
  import { Schema } from "prosemirror-model";
2
2
 
3
- const newSchema = {
3
+ const pmSchemaJson = {
4
4
  topNode: "doc",
5
5
  nodes: {
6
6
  paragraph: {
@@ -574,4 +574,4 @@ const newSchema = {
574
574
  },
575
575
  } as const;
576
576
 
577
- export const pmSchema = new Schema(newSchema);
577
+ export const mainEditorProsemirrorSchema = new Schema(pmSchemaJson);
@@ -10,7 +10,7 @@ export type ProsemirrorNode = {
10
10
 
11
11
  export type ProsemirrorMark = {
12
12
  type: string;
13
- attrs: Record<string, any>;
13
+ attrs?: Record<string, any>;
14
14
  };
15
15
 
16
16
  export type ProsemirrorBlockItem = {
@@ -21,6 +21,9 @@ import {
21
21
  PageBlockItemMultiRichTextValue,
22
22
  PageBlockItemMultiSelectValue,
23
23
  PageBlockItemNumberValue,
24
+ PageBlockItemRichTextEditorListNode,
25
+ PageBlockItemRichTextEditorNode,
26
+ PageBlockItemRichTextEditorParagraphNode,
24
27
  PageBlockItemRichTextEditorValue,
25
28
  PageBlockItemRichTextValue,
26
29
  PageBlockItemSandboxValue,
@@ -85,6 +88,56 @@ export function shallowProsemirrorNodeToBlock(
85
88
  );
86
89
  }
87
90
 
91
+ export function prosemirrorDocToRichTextPropertyValue(
92
+ prosemirrorNode: ProsemirrorNode
93
+ ): PageBlockItemRichTextEditorValue {
94
+ return {
95
+ value: (prosemirrorNode.content ?? [])
96
+ .map(n => prosemirrorNodeToRichTextEditorPropertyNode(n))
97
+ .filter(nonNullFilter),
98
+ };
99
+ }
100
+
101
+ function prosemirrorNodeToRichTextEditorPropertyNode(
102
+ prosemirrorNode: ProsemirrorNode
103
+ ): PageBlockItemRichTextEditorNode | null {
104
+ switch (prosemirrorNode.type) {
105
+ case "paragraph":
106
+ return parseAsParagraphNode(prosemirrorNode);
107
+
108
+ case "orderedList":
109
+ case "bulletList":
110
+ return parseAsListNode(prosemirrorNode);
111
+
112
+ default:
113
+ return null;
114
+ }
115
+ }
116
+
117
+ function parseAsParagraphNode(prosemirrorNode: ProsemirrorNode): PageBlockItemRichTextEditorParagraphNode {
118
+ return {
119
+ type: "Paragraph",
120
+ value: parseRichText(prosemirrorNode.content ?? []),
121
+ };
122
+ }
123
+
124
+ function parseAsListNode(prosemirrorNode: ProsemirrorNode): PageBlockItemRichTextEditorListNode {
125
+ return {
126
+ type: "List",
127
+ listType: prosemirrorNode.type === "orderedList" ? "OL" : "UL",
128
+ value: (prosemirrorNode.content ?? []).map(parseAsListNodeItem).filter(nonNullFilter),
129
+ };
130
+ }
131
+
132
+ function parseAsListNodeItem(prosemirrorNode: ProsemirrorNode): PageBlockText | null {
133
+ if (prosemirrorNode.type !== "listItem") return null;
134
+
135
+ const firstChild = prosemirrorNode.content?.[0];
136
+ if (!firstChild || firstChild.type !== "paragraph") return null;
137
+
138
+ return parseRichText(firstChild.content ?? []);
139
+ }
140
+
88
141
  //
89
142
  // Sections
90
143
  //