@supernova-studio/client 0.33.0 → 0.35.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supernova-studio/client",
3
- "version": "0.33.0",
3
+ "version": "0.35.0",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -72,7 +72,7 @@ export function pageToProsemirrorDoc(
72
72
  blockBuffer.push(b);
73
73
  } else if (b.type === "Section") {
74
74
  if (blockBuffer.length) {
75
- children.push(...blocksToProsemirrorNodes(blockBuffer, definitionsMap));
75
+ children.push(...internalBlocksToProsemirrorNodes(blockBuffer, definitionsMap));
76
76
  blockBuffer = [];
77
77
  }
78
78
 
@@ -81,7 +81,7 @@ export function pageToProsemirrorDoc(
81
81
  });
82
82
 
83
83
  if (blockBuffer.length) {
84
- children.push(...blocksToProsemirrorNodes(blockBuffer, definitionsMap));
84
+ children.push(...internalBlocksToProsemirrorNodes(blockBuffer, definitionsMap));
85
85
  }
86
86
 
87
87
  return {
@@ -90,6 +90,13 @@ export function pageToProsemirrorDoc(
90
90
  };
91
91
  }
92
92
 
93
+ export function blockToProsemirrorNode(
94
+ block: PageBlockEditorModel,
95
+ definition: PageBlockDefinition
96
+ ): ProsemirrorNode | null {
97
+ return internalBlockToProsemirrorNode(block, definition);
98
+ }
99
+
93
100
  //
94
101
  // Sections
95
102
  //
@@ -126,7 +133,7 @@ function sectionColumnToProsemirrorNode(
126
133
  sectionColumn: PageSectionColumnV2,
127
134
  definitionsMap: Map<string, PageBlockDefinition>
128
135
  ): ProsemirrorNode {
129
- const blocks = blocksToProsemirrorNodes(sectionColumn.blocks, definitionsMap);
136
+ const blocks = internalBlocksToProsemirrorNodes(sectionColumn.blocks, definitionsMap);
130
137
 
131
138
  if (!blocks.length) {
132
139
  blocks.push({
@@ -151,7 +158,7 @@ function sectionColumnToProsemirrorNode(
151
158
  // Blocks
152
159
  //
153
160
 
154
- function blocksToProsemirrorNodes(
161
+ function internalBlocksToProsemirrorNodes(
155
162
  blocks: PageBlockEditorModel[],
156
163
  definitionsMap: Map<string, PageBlockDefinition>
157
164
  ): ProsemirrorNode[] {
@@ -170,7 +177,7 @@ function blocksToProsemirrorNodes(
170
177
 
171
178
  if (multiRichTextProp) {
172
179
  // This is list
173
- const node = listTreeBuilder.add(b, multiRichTextProp);
180
+ const node = listTreeBuilder.addWithProperty(b, multiRichTextProp);
174
181
  if (node) {
175
182
  result.push(serializeAsMultiRichTextBlock(node));
176
183
  }
@@ -182,7 +189,7 @@ function blocksToProsemirrorNodes(
182
189
  result.push(serializeAsMultiRichTextBlock(tree));
183
190
  }
184
191
 
185
- const node = blockToProsemirrorNode(b, definition);
192
+ const node = internalBlockToProsemirrorNode(b, definition);
186
193
  node && result.push(node);
187
194
  }
188
195
  });
@@ -195,7 +202,10 @@ function blocksToProsemirrorNodes(
195
202
  return result;
196
203
  }
197
204
 
198
- function blockToProsemirrorNode(block: PageBlockEditorModel, definition: PageBlockDefinition): ProsemirrorNode | null {
205
+ function internalBlockToProsemirrorNode(
206
+ block: PageBlockEditorModel,
207
+ definition: PageBlockDefinition
208
+ ): ProsemirrorNode | null {
199
209
  // Single rich text
200
210
  const richTextProperty = BlockDefinitionUtils.firstRichTextProperty(definition);
201
211
  if (richTextProperty) {
@@ -1,6 +1,7 @@
1
1
  export * from "./model";
2
2
  export * from "./prosemirror";
3
3
  export * from "./blocks-to-prosemirror";
4
+ export * from "./list-tree-builder";
4
5
  export * from "./mock";
5
6
  export * from "./prosemirror-to-blocks";
6
7
  export * from "./utils";
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  PageBlockDefinition,
3
+ PageBlockDefinitionMultiRichTextPropertyStyle,
3
4
  PageBlockDefinitionMutiRichTextOptions,
4
5
  PageBlockDefinitionProperty,
5
6
  PageBlockText,
@@ -25,8 +26,20 @@ export type ListItemNode = {
25
26
  export class ListTreeBuilder {
26
27
  private rootNode: ListNode | undefined;
27
28
 
28
- add(block: PageBlockEditorModel, multiRichTextProperty: PageBlockDefinitionProperty): ListNode | undefined {
29
- const list = this.createList(block, multiRichTextProperty);
29
+ addWithProperty(
30
+ block: PageBlockEditorModel,
31
+ multiRichTextProperty: PageBlockDefinitionProperty
32
+ ): ListNode | undefined {
33
+ const parsedOptions = PageBlockDefinitionMutiRichTextOptions.optional().parse(multiRichTextProperty.options);
34
+ return this.add(block, multiRichTextProperty.id, parsedOptions?.multiRichTextStyle || "OL");
35
+ }
36
+
37
+ add(
38
+ block: PageBlockEditorModel,
39
+ multiRichTextPropertyId: string,
40
+ multiRichTextPropertyStyle: PageBlockDefinitionMultiRichTextPropertyStyle
41
+ ) {
42
+ const list = this.createList(block, multiRichTextPropertyId, multiRichTextPropertyStyle);
30
43
 
31
44
  // No root
32
45
  if (!this.rootNode) {
@@ -91,86 +104,14 @@ export class ListTreeBuilder {
91
104
  return currentNode;
92
105
  }
93
106
 
94
- // next(block: PageBlockEditorModel, multiRichTextProperty: PageBlockDefinitionProperty): ListNode | undefined {
95
- // console.log("Next");
96
- // const list = this.createList(block, multiRichTextProperty);
97
-
98
- // if (this.currentList) {
99
- // if (this.currentList.listType === list.listType) {
100
- // // Merge items into the current list
101
- // this.currentList.children.push(...list.leadingChildren);
102
- // return undefined;
103
- // } else {
104
- // // Close the current list and start a new one
105
- // if (!this.currentParentList) {
106
- // const flushed = this.flush();
107
- // this.currentList = list;
108
- // return flushed;
109
- // } else {
110
- // this.currentList = list;
111
- // this.currentParentList.children.push(list);
112
- // this.parentMap.set(list, this.currentParentList);
113
-
114
- // return undefined;
115
- // }
116
- // }
117
- // } else {
118
- // this.currentList = list;
119
- // return undefined;
120
- // }
121
- // }
122
-
123
- // stepIn(block: PageBlockEditorModel, multiRichTextProperty: PageBlockDefinitionProperty): void {
124
- // console.log("Step in");
125
- // if (!this.currentList) {
126
- // throw new Error("Cannot step in without a list");
127
- // }
128
-
129
- // const list = this.createList(block, multiRichTextProperty);
130
-
131
- // this.currentParentList = this.currentList;
132
- // this.currentList = list;
133
- // this.currentParentList.children.push(list);
134
- // this.parentMap.set(list, this.currentParentList);
135
- // }
136
-
137
- // stepOut(block: PageBlockEditorModel, multiRichTextProperty: PageBlockDefinitionProperty): ListNode | undefined {
138
- // console.log("Step out");
139
-
140
- // if (!this.currentList) {
141
- // throw new Error("Cannot step out without a list");
142
- // }
143
-
144
- // if (!this.currentParentList) {
145
- // throw new Error("Cannot step out without a parent list");
146
- // }
147
-
148
- // const newCurrentList = this.currentParentList;
149
- // const newParent = this.parentMap.get(newCurrentList);
150
-
151
- // this.currentList = newCurrentList;
152
- // this.currentParentList = newParent;
153
-
154
- // return this.next(block, multiRichTextProperty);
155
- // }
156
-
157
- // flush(): ListNode | undefined {
158
- // const result = this.currentList;
159
-
160
- // this.currentList = undefined;
161
- // this.currentParentList = undefined;
162
- // this.parentMap.clear();
163
-
164
- // return result;
165
- // }
166
-
167
- private createList(block: PageBlockEditorModel, multiRichTextProperty: PageBlockDefinitionProperty): ListNode {
107
+ private createList(
108
+ block: PageBlockEditorModel,
109
+ multiRichTextPropertyId: string,
110
+ multiRichTextPropertyStyle: PageBlockDefinitionMultiRichTextPropertyStyle
111
+ ): ListNode {
112
+ // private createList(block: PageBlockEditorModel, multiRichTextProperty: PageBlockDefinitionProperty): ListNode {
168
113
  const blockItem = BlockParsingUtils.singleBlockItem(block);
169
- const multiRichTextValue = BlockParsingUtils.multiRichTextPropertyValue(blockItem, multiRichTextProperty.id);
170
-
171
- const parsedOptions = PageBlockDefinitionMutiRichTextOptions.optional().parse(multiRichTextProperty.options);
172
-
173
- const style = parsedOptions?.multiRichTextStyle ?? "Default";
114
+ const multiRichTextValue = BlockParsingUtils.multiRichTextPropertyValue(blockItem, multiRichTextPropertyId);
174
115
 
175
116
  const leadingChildren: ListNode["leadingChildren"] = multiRichTextValue.value.map(t => {
176
117
  return {
@@ -185,7 +126,7 @@ export class ListTreeBuilder {
185
126
 
186
127
  return {
187
128
  type: "List",
188
- listType: style === "OL" ? "Ordered" : "Unordered",
129
+ listType: multiRichTextPropertyStyle === "OL" ? "Ordered" : "Unordered",
189
130
  leadingChildren: leadingChildren,
190
131
  block: block,
191
132
  children: [],