@developer_tribe/react-builder 0.1.24 → 0.1.25

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.
@@ -6,7 +6,7 @@ export interface Device {
6
6
  type: 'phone' | 'tablet';
7
7
  /**
8
8
  * Relative importance for generic targeting and display ordering.
9
- * 1 = highest importance, 5 = lowest importance
9
+ * 1 = highest importance, 100 = lowest importance
10
10
  */
11
- importance?: 1 | 2 | 3 | 4 | 5;
11
+ importance?: number;
12
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@developer_tribe/react-builder",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "type": "module",
5
5
  "restricted": true,
6
6
  "main": "dist/index.cjs.js",
@@ -15,8 +15,11 @@ export async function createBuildComponentsIndex(validated, paths) {
15
15
  .join('\n');
16
16
 
17
17
  const renderNodeExport = `export { default as RenderNode } from './RenderNode.generated';`;
18
+ const getDefaultsExport = `export { getDefaults } from './getDefaults';`;
18
19
 
19
- const sections = [renderNodeExport, exportLines].filter(Boolean).join('\n\n');
20
+ const sections = [renderNodeExport, getDefaultsExport, exportLines]
21
+ .filter(Boolean)
22
+ .join('\n\n');
20
23
 
21
24
  const fileContent =
22
25
  `/* AUTO-GENERATED FILE - DO NOT EDIT */\n\n` +
@@ -32,7 +32,7 @@ export async function createBuildComponentsRootGetDefaults(validated, paths) {
32
32
  const switchCases = validated
33
33
  .map(({ componentName, patternJson }) => {
34
34
  const type = patternJson?.pattern?.type;
35
- return ` case ${JSON.stringify(type)}:\n return get${componentName}Defaults() as Partial<Types[T]>`;
35
+ return ` case ${JSON.stringify(type)}:\n defaults = get${componentName}Defaults() as Partial<Types[T]>;\n break;`;
36
36
  })
37
37
  .join('\n');
38
38
 
@@ -43,12 +43,20 @@ export async function createBuildComponentsRootGetDefaults(validated, paths) {
43
43
  `${nodeImport}\n\n` +
44
44
  `export type Types = {\n${typesMap}\n};\n\n` +
45
45
  `export type List<T> = T extends keyof Types ? Types[T] : never;\n\n` +
46
- `export function getDefaults<T extends keyof Types>(type: T, _node: NodeData<List<T>>): Partial<Types[T]> {\n` +
46
+ `export function getDefaults<T extends keyof Types>(type: T, node: NodeData<List<T>>): Partial<Types[T]> {\n` +
47
+ ` let defaults: Partial<Types[T]> = {};\n\n` +
47
48
  ` switch (type as unknown as string) {\n` +
48
49
  `${switchCases}\n` +
49
50
  ` default:\n` +
50
- ` return {};\n` +
51
- ` }\n` +
51
+ ` defaults = {} as Partial<Types[T]>;\n` +
52
+ ` }\n\n` +
53
+ ` if ((node as unknown as { type?: string })?.type !== (type as unknown as string)) {\n` +
54
+ ` throw new Error(\n` +
55
+ ` \`getDefaults: node.type mismatch; expected \${String(type)}, received \${(node as unknown as { type?: string })?.type ?? 'undefined'}\`\n` +
56
+ ` );\n` +
57
+ ` }\n\n` +
58
+ ` (node as unknown as { attributes?: unknown }).attributes = defaults as Types[T];\n\n` +
59
+ ` return defaults;\n` +
52
60
  `}\n`;
53
61
 
54
62
  const formatted = await formatWithPrettier(fileContent);
@@ -26,7 +26,6 @@ async function getAllEntriesInComponentsRoot(paths) {
26
26
  );
27
27
  });
28
28
  }
29
-
30
29
  // single-use: ensure all entries are directories
31
30
  function ensureAllEntriesAreFolders(dirents, paths) {
32
31
  const { COMPONENTS_ROOT } = paths;