@pixpilot/formily-shadcn 0.9.1 → 0.10.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/README.md +75 -0
- package/dist/components/array-base/components/array-item-label.cjs +1 -1
- package/dist/components/array-base/components/array-item-label.js +1 -1
- package/dist/components/checkbox.d.cts +2 -2
- package/dist/components/checkbox.d.ts +2 -2
- package/dist/components/column.d.ts +2 -2
- package/dist/components/context/form-context.d.cts +20 -16
- package/dist/components/context/form-context.d.ts +20 -16
- package/dist/components/context/index.d.cts +1 -1
- package/dist/components/context/index.d.ts +1 -1
- package/dist/components/date-picker.d.cts +3 -3
- package/dist/components/date-picker.d.ts +3 -3
- package/dist/components/file-upload/file-upload-inline.d.ts +8 -8
- package/dist/components/file-upload/file-upload.d.ts +8 -8
- package/dist/components/file-upload/use-file-upload-feedback.cjs +2 -2
- package/dist/components/file-upload/use-file-upload-feedback.js +2 -2
- package/dist/components/form-grid.d.ts +2 -2
- package/dist/components/form-items-container.cjs +2 -5
- package/dist/components/form-items-container.js +2 -5
- package/dist/components/form.cjs +3 -5
- package/dist/components/form.d.cts +1 -2
- package/dist/components/form.d.ts +1 -2
- package/dist/components/form.js +3 -5
- package/dist/components/icon-picker.cjs +2 -2
- package/dist/components/icon-picker.d.ts +3 -3
- package/dist/components/icon-picker.js +2 -2
- package/dist/components/input.d.cts +2 -2
- package/dist/components/json-schema-form-renderer.cjs +34 -7
- package/dist/components/json-schema-form-renderer.d.cts +8 -3
- package/dist/components/json-schema-form-renderer.d.ts +8 -3
- package/dist/components/json-schema-form-renderer.js +32 -7
- package/dist/components/number-input.d.cts +2 -2
- package/dist/components/number-input.d.ts +2 -2
- package/dist/components/object-container.cjs +33 -7
- package/dist/components/object-container.js +34 -8
- package/dist/components/radio.d.ts +2 -2
- package/dist/components/rich-text-editor.cjs +1 -1
- package/dist/components/rich-text-editor.js +1 -1
- package/dist/components/row.d.ts +2 -2
- package/dist/components/schema-field/index.d.cts +1 -1
- package/dist/components/schema-field/index.d.ts +1 -1
- package/dist/components/schema-field/index.js +1 -1
- package/dist/components/schema-field/schema-field-basics.cjs +4 -4
- package/dist/components/schema-field/schema-field-basics.d.cts +194 -194
- package/dist/components/schema-field/schema-field-basics.d.ts +209 -209
- package/dist/components/schema-field/schema-field-basics.js +3 -3
- package/dist/components/schema-field/schema-field-extended.d.cts +427 -427
- package/dist/components/schema-field/schema-field-extended.d.ts +427 -427
- package/dist/components/schema-field/schema-field.cjs +1 -1
- package/dist/components/schema-field/schema-field.d.cts +237 -237
- package/dist/components/schema-field/schema-field.d.ts +236 -236
- package/dist/components/schema-field/schema-field.js +2 -2
- package/dist/components/separator.d.cts +2 -2
- package/dist/components/separator.d.ts +2 -2
- package/dist/components/slider.d.cts +2 -2
- package/dist/components/slider.d.ts +2 -2
- package/dist/components/switch.d.cts +2 -2
- package/dist/components/switch.d.ts +2 -2
- package/dist/components/tags-input-inline.d.cts +2 -2
- package/dist/components/textarea.d.cts +2 -2
- package/dist/components/textarea.d.ts +2 -2
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/use-form-context.cjs +5 -0
- package/dist/hooks/use-form-context.js +5 -1
- package/dist/hooks/use-label.cjs +9 -2
- package/dist/hooks/use-label.js +9 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/types/form.d.cts +0 -6
- package/dist/types/form.d.ts +0 -6
- package/dist/utils/extract-fields-decorators.cjs +37 -0
- package/dist/utils/extract-fields-decorators.js +36 -0
- package/dist/utils/index.cjs +2 -0
- package/dist/utils/index.js +3 -1
- package/dist/utils/resolve-responsive-space.cjs +45 -89
- package/dist/utils/resolve-responsive-space.js +42 -83
- package/dist/utils/transform-schema.cjs +9 -2
- package/dist/utils/transform-schema.js +9 -2
- package/dist/utils/validate-schema-components.cjs +45 -0
- package/dist/utils/validate-schema-components.js +43 -0
- package/package.json +4 -3
|
@@ -9,74 +9,44 @@ const densitySpaceMap = {
|
|
|
9
9
|
comfortable: "lg"
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
* Space
|
|
13
|
-
*
|
|
12
|
+
* Space-Y spacing configuration
|
|
13
|
+
* Controls vertical spacing between form items
|
|
14
14
|
*/
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const spaceYConfig = {
|
|
16
|
+
fixed: {
|
|
17
|
+
sm: "space-y-3",
|
|
18
|
+
md: "space-y-4",
|
|
19
|
+
lg: "space-y-6"
|
|
20
|
+
},
|
|
21
|
+
responsive: "space-y-3 md:space-y-4 lg:space-y-6"
|
|
19
22
|
};
|
|
20
23
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
24
|
+
* Gap-Y spacing configuration
|
|
25
|
+
* Controls vertical gaps in containers
|
|
23
26
|
*/
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
const gapYConfig = {
|
|
28
|
+
fixed: {
|
|
29
|
+
sm: "gap-y-3",
|
|
30
|
+
md: "gap-y-4",
|
|
31
|
+
lg: "gap-y-6"
|
|
32
|
+
},
|
|
33
|
+
responsive: "gap-y-3 md:gap-y-4 lg:gap-y-6"
|
|
28
34
|
};
|
|
29
35
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* - Tablet (md:): normal (space-y-4)
|
|
33
|
-
* - Desktop (lg:): comfortable (space-y-6)
|
|
34
|
-
*/
|
|
35
|
-
const autoResponsiveSpaceClasses = "space-y-3 md:space-y-4 lg:space-y-6";
|
|
36
|
-
/**
|
|
37
|
-
* Responsive breakpoint classes for responsive density mode using gap
|
|
38
|
-
* - Mobile (default): compact (gap-y-3)
|
|
39
|
-
* - Tablet (md:): normal (gap-y-4)
|
|
40
|
-
* - Desktop (lg:): comfortable (gap-y-6)
|
|
41
|
-
*/
|
|
42
|
-
const autoResponsiveGapClasses = "gap-y-3 md:gap-y-4 lg:gap-y-6";
|
|
43
|
-
/**
|
|
44
|
-
* Checks if density is responsive mode
|
|
45
|
-
*
|
|
46
|
-
* @param density - Density value
|
|
47
|
-
* @returns true if density is 'responsive'
|
|
48
|
-
*/
|
|
49
|
-
function isResponsiveDensity(density) {
|
|
50
|
-
return density === "responsive";
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Resolves responsive space value from FormSpace configuration
|
|
54
|
-
* Priority:
|
|
55
|
-
* 1. If responsive is set → use it (ignore density)
|
|
56
|
-
* 2. If density is 'responsive' → return undefined (handled separately with responsive classes)
|
|
57
|
-
* 3. If only other density is set → use density-based mapping
|
|
58
|
-
* 4. Default to undefined (responsive mode)
|
|
59
|
-
*
|
|
60
|
-
* @param formSpace - FormSpace configuration
|
|
61
|
-
* @returns Space value ('sm' | 'md' | 'lg') or undefined for responsive mode
|
|
62
|
-
*/
|
|
63
|
-
function resolveResponsiveSpace(formSpace) {
|
|
64
|
-
if (!formSpace) return;
|
|
65
|
-
if (formSpace.responsive) return formSpace.responsive.desktop || formSpace.responsive.tablet || formSpace.responsive.mobile || "lg";
|
|
66
|
-
if (isResponsiveDensity(formSpace.density)) return;
|
|
67
|
-
if (formSpace.density && !isResponsiveDensity(formSpace.density)) return densitySpaceMap[formSpace.density];
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Gets the Tailwind class for a given space value
|
|
36
|
+
* Resolves spacing class based on density and spacing configuration
|
|
37
|
+
* Generic utility that works with any spacing config
|
|
71
38
|
*
|
|
72
|
-
* @param
|
|
73
|
-
* @
|
|
39
|
+
* @param density - Density value ('compact' | 'normal' | 'comfortable' | 'responsive')
|
|
40
|
+
* @param config - Spacing configuration with fixed and responsive classes
|
|
41
|
+
* @returns Tailwind utility class(es)
|
|
74
42
|
*/
|
|
75
|
-
function
|
|
76
|
-
return
|
|
43
|
+
function resolveSpacingClass(density, config) {
|
|
44
|
+
if (!density || density === "responsive") return config.responsive;
|
|
45
|
+
const space = densitySpaceMap[density];
|
|
46
|
+
return config.fixed[space];
|
|
77
47
|
}
|
|
78
48
|
/**
|
|
79
|
-
* Resolves responsive space and returns the Tailwind class(es)
|
|
49
|
+
* Resolves responsive space and returns the Tailwind space-y class(es)
|
|
80
50
|
* For responsive density, returns responsive breakpoint classes
|
|
81
51
|
* For fixed density, returns single space class
|
|
82
52
|
*
|
|
@@ -84,25 +54,10 @@ function getSpaceClass(space) {
|
|
|
84
54
|
* @returns Tailwind utility class(es)
|
|
85
55
|
*/
|
|
86
56
|
function resolveResponsiveSpaceClass(formSpace) {
|
|
87
|
-
|
|
88
|
-
if (formSpace.responsive && !isResponsiveDensity(formSpace.density)) {
|
|
89
|
-
const space$1 = resolveResponsiveSpace(formSpace);
|
|
90
|
-
return space$1 ? getSpaceClass(space$1) : autoResponsiveSpaceClasses;
|
|
91
|
-
}
|
|
92
|
-
const space = resolveResponsiveSpace(formSpace);
|
|
93
|
-
return space ? getSpaceClass(space) : autoResponsiveSpaceClasses;
|
|
57
|
+
return resolveSpacingClass(formSpace?.density, spaceYConfig);
|
|
94
58
|
}
|
|
95
59
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* @param space - Space value
|
|
99
|
-
* @returns Tailwind utility gap class
|
|
100
|
-
*/
|
|
101
|
-
function getGapClass(space) {
|
|
102
|
-
return gapClassMap[space];
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Resolves responsive space and returns the Tailwind gap class(es)
|
|
60
|
+
* Resolves responsive space and returns the Tailwind gap-y class(es)
|
|
106
61
|
* For responsive density, returns responsive breakpoint classes
|
|
107
62
|
* For fixed density, returns single gap class
|
|
108
63
|
*
|
|
@@ -110,14 +65,18 @@ function getGapClass(space) {
|
|
|
110
65
|
* @returns Tailwind utility gap class(es)
|
|
111
66
|
*/
|
|
112
67
|
function resolveResponsiveGapClass(formSpace) {
|
|
113
|
-
|
|
114
|
-
if (formSpace.responsive && !isResponsiveDensity(formSpace.density)) {
|
|
115
|
-
const space$1 = resolveResponsiveSpace(formSpace);
|
|
116
|
-
return space$1 ? getGapClass(space$1) : autoResponsiveGapClasses;
|
|
117
|
-
}
|
|
118
|
-
const space = resolveResponsiveSpace(formSpace);
|
|
119
|
-
return space ? getGapClass(space) : autoResponsiveGapClasses;
|
|
68
|
+
return resolveSpacingClass(formSpace?.density, gapYConfig);
|
|
120
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Deprecated: Use resolveSpacingClass instead
|
|
72
|
+
* @deprecated
|
|
73
|
+
*/
|
|
74
|
+
const autoResponsiveSpaceClasses = spaceYConfig.responsive;
|
|
75
|
+
/**
|
|
76
|
+
* Deprecated: Use resolveSpacingClass instead
|
|
77
|
+
* @deprecated
|
|
78
|
+
*/
|
|
79
|
+
const autoResponsiveGapClasses = gapYConfig.responsive;
|
|
121
80
|
|
|
122
81
|
//#endregion
|
|
123
|
-
export {
|
|
82
|
+
export { gapYConfig, resolveResponsiveGapClass, resolveResponsiveSpaceClass, resolveSpacingClass, spaceYConfig };
|
|
@@ -26,15 +26,22 @@ const inputSchemaMap = {
|
|
|
26
26
|
},
|
|
27
27
|
object: { "x-component": "ObjectContainer" }
|
|
28
28
|
};
|
|
29
|
-
function transformSchema(schema) {
|
|
29
|
+
function transformSchema(schema, fieldsDecorators) {
|
|
30
30
|
(0, json_schema_traverse.default)(schema, {
|
|
31
31
|
allKeys: true,
|
|
32
32
|
cb: (currentSchema) => {
|
|
33
33
|
const { type } = currentSchema;
|
|
34
|
+
const xComponent = currentSchema["x-component"];
|
|
34
35
|
if (typeof type === "string" && type in inputSchemaMap) {
|
|
35
36
|
const mapping = inputSchemaMap[type];
|
|
36
37
|
if (currentSchema["x-component"] == null) currentSchema["x-component"] = mapping["x-component"];
|
|
37
|
-
|
|
38
|
+
}
|
|
39
|
+
if (!["Hidden", "hidden"].includes(currentSchema["x-component"])) {
|
|
40
|
+
if (currentSchema["x-decorator"] == null) {
|
|
41
|
+
const userDecorator = xComponent != null && fieldsDecorators != null && fieldsDecorators[xComponent] != null ? fieldsDecorators[xComponent] : null;
|
|
42
|
+
if (userDecorator != null) currentSchema["x-decorator"] = userDecorator;
|
|
43
|
+
else if (typeof type === "string" && type in inputSchemaMap) currentSchema["x-decorator"] = inputSchemaMap[type]["x-decorator"];
|
|
44
|
+
}
|
|
38
45
|
}
|
|
39
46
|
}
|
|
40
47
|
});
|
|
@@ -24,15 +24,22 @@ const inputSchemaMap = {
|
|
|
24
24
|
},
|
|
25
25
|
object: { "x-component": "ObjectContainer" }
|
|
26
26
|
};
|
|
27
|
-
function transformSchema(schema) {
|
|
27
|
+
function transformSchema(schema, fieldsDecorators) {
|
|
28
28
|
traverse(schema, {
|
|
29
29
|
allKeys: true,
|
|
30
30
|
cb: (currentSchema) => {
|
|
31
31
|
const { type } = currentSchema;
|
|
32
|
+
const xComponent = currentSchema["x-component"];
|
|
32
33
|
if (typeof type === "string" && type in inputSchemaMap) {
|
|
33
34
|
const mapping = inputSchemaMap[type];
|
|
34
35
|
if (currentSchema["x-component"] == null) currentSchema["x-component"] = mapping["x-component"];
|
|
35
|
-
|
|
36
|
+
}
|
|
37
|
+
if (!["Hidden", "hidden"].includes(currentSchema["x-component"])) {
|
|
38
|
+
if (currentSchema["x-decorator"] == null) {
|
|
39
|
+
const userDecorator = xComponent != null && fieldsDecorators != null && fieldsDecorators[xComponent] != null ? fieldsDecorators[xComponent] : null;
|
|
40
|
+
if (userDecorator != null) currentSchema["x-decorator"] = userDecorator;
|
|
41
|
+
else if (typeof type === "string" && type in inputSchemaMap) currentSchema["x-decorator"] = inputSchemaMap[type]["x-decorator"];
|
|
42
|
+
}
|
|
36
43
|
}
|
|
37
44
|
}
|
|
38
45
|
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let json_schema_traverse = require("json-schema-traverse");
|
|
3
|
+
json_schema_traverse = require_rolldown_runtime.__toESM(json_schema_traverse);
|
|
4
|
+
|
|
5
|
+
//#region src/utils/validate-schema-components.ts
|
|
6
|
+
/**
|
|
7
|
+
* Validates schema components against the provided React components.
|
|
8
|
+
*
|
|
9
|
+
* For x-component and x-decorator references, they must match a component key
|
|
10
|
+
* in the provided components object.
|
|
11
|
+
*
|
|
12
|
+
* Throws an error if:
|
|
13
|
+
* - An x-component reference doesn't match any available component key
|
|
14
|
+
* - An x-decorator reference doesn't match any available component key
|
|
15
|
+
*
|
|
16
|
+
* @param schema - The ISchema to validate
|
|
17
|
+
* @param components - Record of available React components (includes both components and decorators)
|
|
18
|
+
* @throws {Error} If validation fails
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const components = { Input, NumberInput, Checkbox, FormItem };
|
|
22
|
+
* validateSchemaComponents(schema, components);
|
|
23
|
+
*/
|
|
24
|
+
function validateSchemaComponents(schema, components) {
|
|
25
|
+
const componentKeys = Object.keys(components);
|
|
26
|
+
const errors = [];
|
|
27
|
+
(0, json_schema_traverse.default)(schema, {
|
|
28
|
+
allKeys: true,
|
|
29
|
+
cb: (currentSchema, jsonPointer) => {
|
|
30
|
+
const current = currentSchema;
|
|
31
|
+
const xComponent = current["x-component"];
|
|
32
|
+
const xDecorator = current["x-decorator"];
|
|
33
|
+
if (xComponent != null && typeof xComponent === "string") {
|
|
34
|
+
if (!componentKeys.includes(xComponent)) errors.push(`Component '${xComponent}' at path '${jsonPointer}' is not registered in the provided components.`);
|
|
35
|
+
}
|
|
36
|
+
if (xDecorator != null && typeof xDecorator === "string") {
|
|
37
|
+
if (!componentKeys.includes(xDecorator)) errors.push(`Decorator '${xDecorator}' at path '${jsonPointer}' is not registered in the provided components.`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (errors.length > 0) throw new Error(`Schema validation failed:\n${errors.join("\n")}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
exports.validateSchemaComponents = validateSchemaComponents;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import traverse from "json-schema-traverse";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/validate-schema-components.ts
|
|
4
|
+
/**
|
|
5
|
+
* Validates schema components against the provided React components.
|
|
6
|
+
*
|
|
7
|
+
* For x-component and x-decorator references, they must match a component key
|
|
8
|
+
* in the provided components object.
|
|
9
|
+
*
|
|
10
|
+
* Throws an error if:
|
|
11
|
+
* - An x-component reference doesn't match any available component key
|
|
12
|
+
* - An x-decorator reference doesn't match any available component key
|
|
13
|
+
*
|
|
14
|
+
* @param schema - The ISchema to validate
|
|
15
|
+
* @param components - Record of available React components (includes both components and decorators)
|
|
16
|
+
* @throws {Error} If validation fails
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const components = { Input, NumberInput, Checkbox, FormItem };
|
|
20
|
+
* validateSchemaComponents(schema, components);
|
|
21
|
+
*/
|
|
22
|
+
function validateSchemaComponents(schema, components) {
|
|
23
|
+
const componentKeys = Object.keys(components);
|
|
24
|
+
const errors = [];
|
|
25
|
+
traverse(schema, {
|
|
26
|
+
allKeys: true,
|
|
27
|
+
cb: (currentSchema, jsonPointer) => {
|
|
28
|
+
const current = currentSchema;
|
|
29
|
+
const xComponent = current["x-component"];
|
|
30
|
+
const xDecorator = current["x-decorator"];
|
|
31
|
+
if (xComponent != null && typeof xComponent === "string") {
|
|
32
|
+
if (!componentKeys.includes(xComponent)) errors.push(`Component '${xComponent}' at path '${jsonPointer}' is not registered in the provided components.`);
|
|
33
|
+
}
|
|
34
|
+
if (xDecorator != null && typeof xDecorator === "string") {
|
|
35
|
+
if (!componentKeys.includes(xDecorator)) errors.push(`Decorator '${xDecorator}' at path '${jsonPointer}' is not registered in the provided components.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
if (errors.length > 0) throw new Error(`Schema validation failed:\n${errors.join("\n")}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { validateSchemaComponents };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixpilot/formily-shadcn",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"description": "Formily integration for shadcn/ui components",
|
|
6
6
|
"author": "m.doaie <m.doaie@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -35,12 +35,13 @@
|
|
|
35
35
|
"@iconify-json/fa": "^1.2.2",
|
|
36
36
|
"@iconify-json/mdi": "^1.2.3",
|
|
37
37
|
"@iconify/react": "^6.0.2",
|
|
38
|
+
"@pixpilot/env": "^0.2.1",
|
|
38
39
|
"@pixpilot/string": "^2.3.0",
|
|
39
40
|
"json-schema-traverse": "^1.0.0",
|
|
40
41
|
"lucide-react": "^0.554.0",
|
|
41
42
|
"pretty-bytes": "^7.1.0",
|
|
42
|
-
"@pixpilot/shadcn": "0.
|
|
43
|
-
"@pixpilot/shadcn
|
|
43
|
+
"@pixpilot/shadcn-ui": "0.5.1",
|
|
44
|
+
"@pixpilot/shadcn": "0.4.0"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@storybook/react": "^10.1.8",
|