@supernova-studio/model 0.35.0 → 0.36.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/dist/index.d.mts +29 -13
- package/dist/index.d.ts +29 -13
- package/dist/index.js +74 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/dsm/elements/data/documentation-block-v2.ts +2 -2
- package/src/dsm/elements/index.ts +1 -0
- package/src/dsm/elements/utils.ts +114 -0
package/package.json
CHANGED
|
@@ -223,8 +223,8 @@ export const PageBlockItemSingleSelectValue = z.object({
|
|
|
223
223
|
export const PageBlockItemStorybookValue = z.object({
|
|
224
224
|
caption: z.string().optional(),
|
|
225
225
|
height: z.number().optional(),
|
|
226
|
-
|
|
227
|
-
value: z.string(),
|
|
226
|
+
embedUrl: z.string().optional(),
|
|
227
|
+
value: z.string().optional(),
|
|
228
228
|
});
|
|
229
229
|
|
|
230
230
|
export const PageBlockItemTextValue = z.object({
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { DocumentationPageContentItem, PageBlockDefinition, PageBlockDefinitionProperty } from "../documentation";
|
|
2
|
+
import { PageBlockItemUntypedValue, PageBlockItemV2 } from "./data";
|
|
3
|
+
import { PageBlockEditorModelV2 } from "./page-block-v2";
|
|
4
|
+
|
|
5
|
+
//
|
|
6
|
+
// Traverse
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Pay attention to correct types!
|
|
11
|
+
*/
|
|
12
|
+
export function mapPageBlockItemValuesV2(
|
|
13
|
+
pageItems: DocumentationPageContentItem[],
|
|
14
|
+
definitionsMap: PageBlockDefinitionsMap,
|
|
15
|
+
fn: (
|
|
16
|
+
block: PageBlockEditorModelV2,
|
|
17
|
+
item: PageBlockItemV2,
|
|
18
|
+
property: PageBlockDefinitionProperty,
|
|
19
|
+
value: PageBlockItemUntypedValue
|
|
20
|
+
) => PageBlockItemUntypedValue
|
|
21
|
+
) {
|
|
22
|
+
traversePageBlockItemsV2(pageItems, (block, item) => {
|
|
23
|
+
Object.entries(item.props).forEach(([propKey, value]) => {
|
|
24
|
+
const property = definitionsMap.getDefinitionProperty(block.data.packageId, propKey);
|
|
25
|
+
if (!property) return;
|
|
26
|
+
|
|
27
|
+
item.props[propKey] = fn(block, item, property, value);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function traversePageBlockItemValuesV2(
|
|
33
|
+
pageItems: DocumentationPageContentItem[],
|
|
34
|
+
definitionsMap: PageBlockDefinitionsMap,
|
|
35
|
+
fn: (
|
|
36
|
+
block: PageBlockEditorModelV2,
|
|
37
|
+
item: PageBlockItemV2,
|
|
38
|
+
property: PageBlockDefinitionProperty,
|
|
39
|
+
value: PageBlockItemUntypedValue
|
|
40
|
+
) => void
|
|
41
|
+
) {
|
|
42
|
+
traversePageBlockItemsV2(pageItems, (block, item) => {
|
|
43
|
+
Object.entries(item.props).forEach(([propKey, value]) => {
|
|
44
|
+
const property = definitionsMap.getDefinitionProperty(block.data.packageId, propKey);
|
|
45
|
+
if (!property) return;
|
|
46
|
+
|
|
47
|
+
fn(block, item, property, value);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function traversePageBlockItemsV2(
|
|
53
|
+
pageItems: DocumentationPageContentItem[],
|
|
54
|
+
fn: (block: PageBlockEditorModelV2, item: PageBlockItemV2) => void
|
|
55
|
+
) {
|
|
56
|
+
traversePageItemsV2(pageItems, block => {
|
|
57
|
+
block.data.items.forEach(item => {
|
|
58
|
+
fn(block, item);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function traversePageItemsV2(
|
|
64
|
+
pageItems: DocumentationPageContentItem[],
|
|
65
|
+
fn: (item: PageBlockEditorModelV2) => void
|
|
66
|
+
): void {
|
|
67
|
+
for (const item of pageItems) {
|
|
68
|
+
switch (item.type) {
|
|
69
|
+
case "Block":
|
|
70
|
+
fn(item);
|
|
71
|
+
|
|
72
|
+
break;
|
|
73
|
+
|
|
74
|
+
case "Section":
|
|
75
|
+
item.items.forEach(i => {
|
|
76
|
+
i.columns.forEach(c => {
|
|
77
|
+
traversePageItemsV2(c.blocks, fn);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//
|
|
87
|
+
// Definitions map
|
|
88
|
+
//
|
|
89
|
+
|
|
90
|
+
export class PageBlockDefinitionsMap {
|
|
91
|
+
private definitionsMap = new Map<string, PageBlockDefinition>();
|
|
92
|
+
private propertiesMap = new Map<string, PageBlockDefinitionProperty>();
|
|
93
|
+
|
|
94
|
+
constructor(definitions: PageBlockDefinition[]) {
|
|
95
|
+
definitions.forEach(d => {
|
|
96
|
+
this.definitionsMap.set(d.id, d);
|
|
97
|
+
d.item.properties.forEach(p => {
|
|
98
|
+
this.propertiesMap.set(this.propertyKey(d.id, p.id), p);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getDefinition(id: string): PageBlockDefinition | undefined {
|
|
104
|
+
return this.definitionsMap.get(id);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
getDefinitionProperty(defId: string, propId: string): PageBlockDefinitionProperty | undefined {
|
|
108
|
+
return this.propertiesMap.get(this.propertyKey(defId, propId));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private propertyKey(defId: string, propId: string): string {
|
|
112
|
+
return `${defId}.${propId}`;
|
|
113
|
+
}
|
|
114
|
+
}
|