@supernova-studio/client 0.32.0 → 0.34.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.32.0",
3
+ "version": "0.34.0",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -86,7 +86,7 @@ export const DTOCreateDocumentationTabInput = z.object({
86
86
 
87
87
  // If this is page, we will attempt to convert it to tab
88
88
  // If this is tab group, we will add a new tab to it
89
- tabContainerPersistentId: z.string(),
89
+ fromItemPersistentId: z.string(),
90
90
  tabName: z.string(),
91
91
  });
92
92
 
@@ -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,15 @@ export function pageToProsemirrorDoc(
90
90
  };
91
91
  }
92
92
 
93
+ export function blockToProsemirrorNode(
94
+ block: PageBlockEditorModel,
95
+ definitions: PageBlockDefinition[]
96
+ ): ProsemirrorNode | null {
97
+ const definitionsMap = mapByUnique(definitions, d => d.id);
98
+ const nodes = internalBlocksToProsemirrorNodes([block], definitionsMap);
99
+ return nodes[0] ?? null;
100
+ }
101
+
93
102
  //
94
103
  // Sections
95
104
  //
@@ -126,7 +135,7 @@ function sectionColumnToProsemirrorNode(
126
135
  sectionColumn: PageSectionColumnV2,
127
136
  definitionsMap: Map<string, PageBlockDefinition>
128
137
  ): ProsemirrorNode {
129
- const blocks = blocksToProsemirrorNodes(sectionColumn.blocks, definitionsMap);
138
+ const blocks = internalBlocksToProsemirrorNodes(sectionColumn.blocks, definitionsMap);
130
139
 
131
140
  if (!blocks.length) {
132
141
  blocks.push({
@@ -151,7 +160,7 @@ function sectionColumnToProsemirrorNode(
151
160
  // Blocks
152
161
  //
153
162
 
154
- function blocksToProsemirrorNodes(
163
+ function internalBlocksToProsemirrorNodes(
155
164
  blocks: PageBlockEditorModel[],
156
165
  definitionsMap: Map<string, PageBlockDefinition>
157
166
  ): ProsemirrorNode[] {
@@ -170,7 +179,7 @@ function blocksToProsemirrorNodes(
170
179
 
171
180
  if (multiRichTextProp) {
172
181
  // This is list
173
- const node = listTreeBuilder.add(b, multiRichTextProp);
182
+ const node = listTreeBuilder.addWithProperty(b, multiRichTextProp);
174
183
  if (node) {
175
184
  result.push(serializeAsMultiRichTextBlock(node));
176
185
  }
@@ -182,7 +191,7 @@ function blocksToProsemirrorNodes(
182
191
  result.push(serializeAsMultiRichTextBlock(tree));
183
192
  }
184
193
 
185
- const node = blockToProsemirrorNode(b, definition);
194
+ const node = internalBlockToProsemirrorNode(b, definition);
186
195
  node && result.push(node);
187
196
  }
188
197
  });
@@ -195,7 +204,10 @@ function blocksToProsemirrorNodes(
195
204
  return result;
196
205
  }
197
206
 
198
- function blockToProsemirrorNode(block: PageBlockEditorModel, definition: PageBlockDefinition): ProsemirrorNode | null {
207
+ function internalBlockToProsemirrorNode(
208
+ block: PageBlockEditorModel,
209
+ definition: PageBlockDefinition
210
+ ): ProsemirrorNode | null {
199
211
  // Single rich text
200
212
  const richTextProperty = BlockDefinitionUtils.firstRichTextProperty(definition);
201
213
  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: [],