@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.
- package/dist/build-components/getDefaults.d.ts +1 -1
- package/dist/build-components/index.d.ts +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/types/Device.d.ts +2 -2
- package/package.json +1 -1
- package/scripts/prebuild/utils/createBuildComponentsIndex.js +4 -1
- package/scripts/prebuild/utils/createBuildComponentsRootGetDefaults.js +12 -4
- package/scripts/prebuild/utils/validateAllComponentsOrThrow.js +0 -1
- package/src/assets/devices.json +88 -88
- package/src/build-components/getDefaults.ts +55 -21
- package/src/build-components/index.ts +2 -0
- package/src/types/Device.ts +2 -2
- package/src/utils/getDevices.ts +7 -1
package/dist/types/Device.d.ts
CHANGED
|
@@ -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,
|
|
9
|
+
* 1 = highest importance, 100 = lowest importance
|
|
10
10
|
*/
|
|
11
|
-
importance?:
|
|
11
|
+
importance?: number;
|
|
12
12
|
}
|
package/package.json
CHANGED
|
@@ -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]
|
|
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
|
|
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,
|
|
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
|
-
`
|
|
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);
|