@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.
Files changed (83) hide show
  1. package/README.md +75 -0
  2. package/dist/components/array-base/components/array-item-label.cjs +1 -1
  3. package/dist/components/array-base/components/array-item-label.js +1 -1
  4. package/dist/components/checkbox.d.cts +2 -2
  5. package/dist/components/checkbox.d.ts +2 -2
  6. package/dist/components/column.d.ts +2 -2
  7. package/dist/components/context/form-context.d.cts +20 -16
  8. package/dist/components/context/form-context.d.ts +20 -16
  9. package/dist/components/context/index.d.cts +1 -1
  10. package/dist/components/context/index.d.ts +1 -1
  11. package/dist/components/date-picker.d.cts +3 -3
  12. package/dist/components/date-picker.d.ts +3 -3
  13. package/dist/components/file-upload/file-upload-inline.d.ts +8 -8
  14. package/dist/components/file-upload/file-upload.d.ts +8 -8
  15. package/dist/components/file-upload/use-file-upload-feedback.cjs +2 -2
  16. package/dist/components/file-upload/use-file-upload-feedback.js +2 -2
  17. package/dist/components/form-grid.d.ts +2 -2
  18. package/dist/components/form-items-container.cjs +2 -5
  19. package/dist/components/form-items-container.js +2 -5
  20. package/dist/components/form.cjs +3 -5
  21. package/dist/components/form.d.cts +1 -2
  22. package/dist/components/form.d.ts +1 -2
  23. package/dist/components/form.js +3 -5
  24. package/dist/components/icon-picker.cjs +2 -2
  25. package/dist/components/icon-picker.d.ts +3 -3
  26. package/dist/components/icon-picker.js +2 -2
  27. package/dist/components/input.d.cts +2 -2
  28. package/dist/components/json-schema-form-renderer.cjs +34 -7
  29. package/dist/components/json-schema-form-renderer.d.cts +8 -3
  30. package/dist/components/json-schema-form-renderer.d.ts +8 -3
  31. package/dist/components/json-schema-form-renderer.js +32 -7
  32. package/dist/components/number-input.d.cts +2 -2
  33. package/dist/components/number-input.d.ts +2 -2
  34. package/dist/components/object-container.cjs +33 -7
  35. package/dist/components/object-container.js +34 -8
  36. package/dist/components/radio.d.ts +2 -2
  37. package/dist/components/rich-text-editor.cjs +1 -1
  38. package/dist/components/rich-text-editor.js +1 -1
  39. package/dist/components/row.d.ts +2 -2
  40. package/dist/components/schema-field/index.d.cts +1 -1
  41. package/dist/components/schema-field/index.d.ts +1 -1
  42. package/dist/components/schema-field/index.js +1 -1
  43. package/dist/components/schema-field/schema-field-basics.cjs +4 -4
  44. package/dist/components/schema-field/schema-field-basics.d.cts +194 -194
  45. package/dist/components/schema-field/schema-field-basics.d.ts +209 -209
  46. package/dist/components/schema-field/schema-field-basics.js +3 -3
  47. package/dist/components/schema-field/schema-field-extended.d.cts +427 -427
  48. package/dist/components/schema-field/schema-field-extended.d.ts +427 -427
  49. package/dist/components/schema-field/schema-field.cjs +1 -1
  50. package/dist/components/schema-field/schema-field.d.cts +237 -237
  51. package/dist/components/schema-field/schema-field.d.ts +236 -236
  52. package/dist/components/schema-field/schema-field.js +2 -2
  53. package/dist/components/separator.d.cts +2 -2
  54. package/dist/components/separator.d.ts +2 -2
  55. package/dist/components/slider.d.cts +2 -2
  56. package/dist/components/slider.d.ts +2 -2
  57. package/dist/components/switch.d.cts +2 -2
  58. package/dist/components/switch.d.ts +2 -2
  59. package/dist/components/tags-input-inline.d.cts +2 -2
  60. package/dist/components/textarea.d.cts +2 -2
  61. package/dist/components/textarea.d.ts +2 -2
  62. package/dist/hooks/index.js +1 -1
  63. package/dist/hooks/use-form-context.cjs +5 -0
  64. package/dist/hooks/use-form-context.js +5 -1
  65. package/dist/hooks/use-label.cjs +9 -2
  66. package/dist/hooks/use-label.js +9 -2
  67. package/dist/index.cjs +1 -1
  68. package/dist/index.d.cts +2 -2
  69. package/dist/index.d.ts +2 -2
  70. package/dist/index.js +2 -2
  71. package/dist/types/form.d.cts +0 -6
  72. package/dist/types/form.d.ts +0 -6
  73. package/dist/utils/extract-fields-decorators.cjs +37 -0
  74. package/dist/utils/extract-fields-decorators.js +36 -0
  75. package/dist/utils/index.cjs +2 -0
  76. package/dist/utils/index.js +3 -1
  77. package/dist/utils/resolve-responsive-space.cjs +45 -89
  78. package/dist/utils/resolve-responsive-space.js +42 -83
  79. package/dist/utils/transform-schema.cjs +9 -2
  80. package/dist/utils/transform-schema.js +9 -2
  81. package/dist/utils/validate-schema-components.cjs +45 -0
  82. package/dist/utils/validate-schema-components.js +43 -0
  83. package/package.json +4 -3
@@ -6,9 +6,14 @@ import React from "react";
6
6
  interface JsonSchemaFormRendererProps extends Omit<React.ComponentProps<typeof Form>, 'form'> {
7
7
  schema: ISchema;
8
8
  children?: React.ReactNode;
9
- schemaField?: React.FC<{
10
- schema: ISchema;
11
- }>;
9
+ values?: Record<string, any>;
10
+ components?: {
11
+ fields?: Record<string, {
12
+ component: React.ComponentType<any>;
13
+ decorator?: string;
14
+ }>;
15
+ decorators?: Record<string, React.ComponentType<any>>;
16
+ };
12
17
  }
13
18
  declare const JsonSchemaFormRenderer: React.FC<JsonSchemaFormRendererProps>;
14
19
  //#endregion
@@ -1,24 +1,49 @@
1
+ import { extractFieldsDecorators } from "../utils/extract-fields-decorators.js";
1
2
  import { transformSchema } from "../utils/transform-schema.js";
3
+ import { validateSchemaComponents } from "../utils/validate-schema-components.js";
2
4
  import "../utils/index.js";
3
5
  import { Form as Form$1 } from "./form.js";
4
- import { SchemaField } from "./schema-field/schema-field.js";
6
+ import { schemaFieldBasicComponents } from "./schema-field/schema-field-basics.js";
5
7
  import "./schema-field/index.js";
8
+ import { createSchemaField } from "@formily/react";
6
9
  import React, { useMemo } from "react";
7
10
  import { jsx, jsxs } from "react/jsx-runtime";
8
11
  import { createForm } from "@formily/core";
12
+ import { isDevelopment } from "@pixpilot/env";
9
13
 
10
14
  //#region src/components/json-schema-form-renderer.tsx
11
15
  const JsonSchemaFormRenderer = (props) => {
12
- const { schema, children, schemaField,...rest } = props;
13
- const form = useMemo(() => createForm(), []);
16
+ const { schema, children, settings: configProp, components: componentsProp, values,...rest } = props;
17
+ const form = useMemo(() => createForm({ values: values || {} }), [values]);
14
18
  const formSchema = useMemo(() => {
15
- return transformSchema(schema);
16
- }, [schema]);
17
- const SchemaFieldComponent = schemaField || SchemaField;
19
+ return transformSchema(schema, extractFieldsDecorators(componentsProp?.fields));
20
+ }, [schema, componentsProp]);
21
+ const SchemaField = React.useMemo(() => {
22
+ const mergedComponents = { ...schemaFieldBasicComponents };
23
+ if (componentsProp?.fields) Object.entries(componentsProp.fields).forEach(([key, field]) => {
24
+ mergedComponents[key] = field.component;
25
+ });
26
+ if (componentsProp?.decorators) Object.assign(mergedComponents, componentsProp.decorators);
27
+ if (isDevelopment()) validateSchemaComponents(formSchema, mergedComponents);
28
+ return createSchemaField({
29
+ components: mergedComponents,
30
+ scope: {}
31
+ });
32
+ }, [formSchema, componentsProp]);
33
+ const config = useMemo(() => {
34
+ return {
35
+ ...configProp,
36
+ label: {
37
+ useFieldNameAsLabel: true,
38
+ ...configProp?.label || {}
39
+ }
40
+ };
41
+ }, [configProp]);
18
42
  return /* @__PURE__ */ jsxs(Form$1, {
19
43
  ...rest,
20
44
  form,
21
- children: [/* @__PURE__ */ jsx(SchemaFieldComponent, { schema: formSchema }), children]
45
+ settings: config,
46
+ children: [/* @__PURE__ */ jsx(SchemaField, { schema: formSchema }), children]
22
47
  });
23
48
  };
24
49
  JsonSchemaFormRenderer.displayName = "JsonSchemaFormRenderer";
@@ -1,9 +1,9 @@
1
- import * as react10 from "react";
1
+ import * as react6 from "react";
2
2
 
3
3
  //#region src/components/number-input.d.ts
4
4
  /**
5
5
  * Formily-connected Number Input component
6
6
  */
7
- declare const NumberInput: react10.ForwardRefExoticComponent<Omit<Partial<react10.ClassAttributes<HTMLInputElement> & react10.InputHTMLAttributes<HTMLInputElement>>, "ref"> & react10.RefAttributes<unknown>>;
7
+ declare const NumberInput: react6.ForwardRefExoticComponent<Omit<Partial<react6.ClassAttributes<HTMLInputElement> & react6.InputHTMLAttributes<HTMLInputElement>>, "ref"> & react6.RefAttributes<unknown>>;
8
8
  //#endregion
9
9
  export { NumberInput };
@@ -1,9 +1,9 @@
1
- import * as react14 from "react";
1
+ import * as react6 from "react";
2
2
 
3
3
  //#region src/components/number-input.d.ts
4
4
  /**
5
5
  * Formily-connected Number Input component
6
6
  */
7
- declare const NumberInput: react14.ForwardRefExoticComponent<Omit<Partial<react14.ClassAttributes<HTMLInputElement> & react14.InputHTMLAttributes<HTMLInputElement>>, "ref"> & react14.RefAttributes<unknown>>;
7
+ declare const NumberInput: react6.ForwardRefExoticComponent<Omit<Partial<react6.ClassAttributes<HTMLInputElement> & react6.InputHTMLAttributes<HTMLInputElement>>, "ref"> & react6.RefAttributes<unknown>>;
8
8
  //#endregion
9
9
  export { NumberInput };
@@ -11,19 +11,45 @@ let __pixpilot_shadcn = require("@pixpilot/shadcn");
11
11
  __pixpilot_shadcn = require_rolldown_runtime.__toESM(__pixpilot_shadcn);
12
12
 
13
13
  //#region src/components/object-container.tsx
14
+ /**
15
+ * Header gap spacing configuration
16
+ * Uses smaller gaps since headers have less content
17
+ */
18
+ const headerConfig = {
19
+ fixed: {
20
+ sm: "gap-1.5 text-lg",
21
+ md: "gap-2 text-xl",
22
+ lg: "gap-2.5 text-2xl"
23
+ },
24
+ responsive: "gap-1.5 text-lg md:gap-2 md:text-xl lg:gap-2.5 lg:text-2xl"
25
+ };
26
+ /**
27
+ * Card padding spacing configuration
28
+ * Controls vertical padding of the Card component
29
+ */
30
+ const cardPaddingConfig = {
31
+ fixed: {
32
+ sm: "py-5",
33
+ md: "py-6",
34
+ lg: "py-7"
35
+ },
36
+ responsive: "py-5 md:py-6 lg:py-7"
37
+ };
14
38
  const ObjectContainer = ({ className, children, label, description,...rest }) => {
15
39
  const effectiveLabel = require_use_label.useLabel(label);
16
40
  const desc = require_use_description.useDescription(description);
17
- const { objectContainerProps, density, responsive } = require_use_form_context.useFormContext();
18
- const gapClass = require_resolve_responsive_space.resolveResponsiveGapClass({
19
- density,
20
- responsive
21
- });
41
+ const { objectContainerProps, density } = require_use_form_context.useFormContext();
42
+ const gapClass = require_resolve_responsive_space.resolveResponsiveGapClass({ density });
43
+ const headerGapClass = require_resolve_responsive_space.resolveSpacingClass(density, headerConfig);
44
+ const cardPaddingClass = require_resolve_responsive_space.resolveSpacingClass(density, cardPaddingConfig);
22
45
  const { className: itemsContainerClassName } = objectContainerProps || {};
23
46
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.Card, {
24
47
  ...rest,
25
- className: (0, __pixpilot_shadcn.cn)("bg-transparent", gapClass, className),
26
- children: [(effectiveLabel != null || desc != null) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.CardHeader, { children: [effectiveLabel != null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.CardTitle, { children: effectiveLabel }), desc != null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.CardDescription, { children: desc })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_form_items_container.FormItemContainer, {
48
+ className: (0, __pixpilot_shadcn.cn)("bg-transparent", gapClass, cardPaddingClass, className),
49
+ children: [(effectiveLabel != null || desc != null) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.CardHeader, {
50
+ className: headerGapClass,
51
+ children: [effectiveLabel != null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.CardTitle, { children: effectiveLabel }), desc != null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.CardDescription, { children: desc })]
52
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_form_items_container.FormItemContainer, {
27
53
  as: __pixpilot_shadcn.CardContent,
28
54
  className: itemsContainerClassName,
29
55
  children
@@ -1,4 +1,4 @@
1
- import { resolveResponsiveGapClass } from "../utils/resolve-responsive-space.js";
1
+ import { resolveResponsiveGapClass, resolveSpacingClass } from "../utils/resolve-responsive-space.js";
2
2
  import { useDescription } from "../hooks/use-description.js";
3
3
  import { useFormContext } from "../hooks/use-form-context.js";
4
4
  import { useLabel } from "../hooks/use-label.js";
@@ -8,19 +8,45 @@ import { jsx, jsxs } from "react/jsx-runtime";
8
8
  import { Card, CardContent, CardDescription, CardHeader, CardTitle, cn } from "@pixpilot/shadcn";
9
9
 
10
10
  //#region src/components/object-container.tsx
11
+ /**
12
+ * Header gap spacing configuration
13
+ * Uses smaller gaps since headers have less content
14
+ */
15
+ const headerConfig = {
16
+ fixed: {
17
+ sm: "gap-1.5 text-lg",
18
+ md: "gap-2 text-xl",
19
+ lg: "gap-2.5 text-2xl"
20
+ },
21
+ responsive: "gap-1.5 text-lg md:gap-2 md:text-xl lg:gap-2.5 lg:text-2xl"
22
+ };
23
+ /**
24
+ * Card padding spacing configuration
25
+ * Controls vertical padding of the Card component
26
+ */
27
+ const cardPaddingConfig = {
28
+ fixed: {
29
+ sm: "py-5",
30
+ md: "py-6",
31
+ lg: "py-7"
32
+ },
33
+ responsive: "py-5 md:py-6 lg:py-7"
34
+ };
11
35
  const ObjectContainer = ({ className, children, label, description,...rest }) => {
12
36
  const effectiveLabel = useLabel(label);
13
37
  const desc = useDescription(description);
14
- const { objectContainerProps, density, responsive } = useFormContext();
15
- const gapClass = resolveResponsiveGapClass({
16
- density,
17
- responsive
18
- });
38
+ const { objectContainerProps, density } = useFormContext();
39
+ const gapClass = resolveResponsiveGapClass({ density });
40
+ const headerGapClass = resolveSpacingClass(density, headerConfig);
41
+ const cardPaddingClass = resolveSpacingClass(density, cardPaddingConfig);
19
42
  const { className: itemsContainerClassName } = objectContainerProps || {};
20
43
  return /* @__PURE__ */ jsxs(Card, {
21
44
  ...rest,
22
- className: cn("bg-transparent", gapClass, className),
23
- children: [(effectiveLabel != null || desc != null) && /* @__PURE__ */ jsxs(CardHeader, { children: [effectiveLabel != null && /* @__PURE__ */ jsx(CardTitle, { children: effectiveLabel }), desc != null && /* @__PURE__ */ jsx(CardDescription, { children: desc })] }), /* @__PURE__ */ jsx(FormItemContainer, {
45
+ className: cn("bg-transparent", gapClass, cardPaddingClass, className),
46
+ children: [(effectiveLabel != null || desc != null) && /* @__PURE__ */ jsxs(CardHeader, {
47
+ className: headerGapClass,
48
+ children: [effectiveLabel != null && /* @__PURE__ */ jsx(CardTitle, { children: effectiveLabel }), desc != null && /* @__PURE__ */ jsx(CardDescription, { children: desc })]
49
+ }), /* @__PURE__ */ jsx(FormItemContainer, {
24
50
  as: CardContent,
25
51
  className: itemsContainerClassName,
26
52
  children
@@ -1,5 +1,5 @@
1
1
  import { FC } from "react";
2
- import * as react_jsx_runtime3 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime2 from "react/jsx-runtime";
3
3
  import { RadioGroup } from "@pixpilot/shadcn";
4
4
 
5
5
  //#region src/components/radio.d.ts
@@ -15,7 +15,7 @@ type RadioProps = {
15
15
  /**
16
16
  * Radio component with options rendering
17
17
  */
18
- declare function Radio(props: RadioProps): react_jsx_runtime3.JSX.Element;
18
+ declare function Radio(props: RadioProps): react_jsx_runtime2.JSX.Element;
19
19
  declare namespace Radio {
20
20
  var displayName: string;
21
21
  }
@@ -11,7 +11,7 @@ react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
11
11
  //#region src/components/rich-text-editor.tsx
12
12
  const RichTextEditorBase = (props) => {
13
13
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn_ui.RichTextEditor, {
14
- ...require_use_form_context.useFormContext()?.config?.richTextEditor,
14
+ ...require_use_form_context.useFormContext()?.settings?.richTextEditor,
15
15
  ...props,
16
16
  children: "RichTextEditor"
17
17
  });
@@ -7,7 +7,7 @@ import { jsx } from "react/jsx-runtime";
7
7
  //#region src/components/rich-text-editor.tsx
8
8
  const RichTextEditorBase = (props) => {
9
9
  return /* @__PURE__ */ jsx(RichTextEditor, {
10
- ...useFormContext()?.config?.richTextEditor,
10
+ ...useFormContext()?.settings?.richTextEditor,
11
11
  ...props,
12
12
  children: "RichTextEditor"
13
13
  });
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import * as react_jsx_runtime1 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime3 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/components/row.d.ts
5
5
  interface IRowProps {
@@ -36,6 +36,6 @@ interface IRowProps {
36
36
  declare function Row({
37
37
  className,
38
38
  children
39
- }: IRowProps): react_jsx_runtime1.JSX.Element;
39
+ }: IRowProps): react_jsx_runtime3.JSX.Element;
40
40
  //#endregion
41
41
  export { Row };
@@ -1,3 +1,3 @@
1
1
  import { SchemaField, schemaFieldComponents } from "./schema-field.cjs";
2
- import { SchemaFieldBasicComponents, SchemaFieldBasics } from "./schema-field-basics.cjs";
2
+ import { SchemaFieldBasics, schemaFieldBasicComponents } from "./schema-field-basics.cjs";
3
3
  import { SchemaFieldExtended, schemaFieldExtendedComponents } from "./schema-field-extended.cjs";
@@ -1,3 +1,3 @@
1
1
  import { SchemaField, schemaFieldComponents } from "./schema-field.js";
2
- import { SchemaFieldBasicComponents, SchemaFieldBasics } from "./schema-field-basics.js";
2
+ import { SchemaFieldBasics, schemaFieldBasicComponents } from "./schema-field-basics.js";
3
3
  import { SchemaFieldExtended, schemaFieldExtendedComponents } from "./schema-field-extended.js";
@@ -1,3 +1,3 @@
1
- import { SchemaFieldBasicComponents, SchemaFieldBasics } from "./schema-field-basics.js";
1
+ import { SchemaFieldBasics, schemaFieldBasicComponents } from "./schema-field-basics.js";
2
2
  import { SchemaField, schemaFieldComponents } from "./schema-field.js";
3
3
  import { SchemaFieldExtended, schemaFieldExtendedComponents } from "./schema-field-extended.js";
@@ -26,7 +26,7 @@ let __formily_react = require("@formily/react");
26
26
  __formily_react = require_rolldown_runtime.__toESM(__formily_react);
27
27
 
28
28
  //#region src/components/schema-field/schema-field-basics.tsx
29
- const SchemaFieldBasicComponents = {
29
+ const schemaFieldBasicComponents = {
30
30
  FormItem: require_form_item.FormItem,
31
31
  Hidden: require_hidden.Hidden,
32
32
  Input: require_input.Input,
@@ -47,8 +47,8 @@ const SchemaFieldBasicComponents = {
47
47
  ArrayPopover: require_array_popover.ArrayPopover,
48
48
  ObjectContainer: require_object_container.ObjectContainer
49
49
  };
50
- const SchemaFieldBasics = (0, __formily_react.createSchemaField)({ components: SchemaFieldBasicComponents });
50
+ const SchemaFieldBasics = (0, __formily_react.createSchemaField)({ components: schemaFieldBasicComponents });
51
51
 
52
52
  //#endregion
53
- exports.SchemaFieldBasicComponents = SchemaFieldBasicComponents;
54
- exports.SchemaFieldBasics = SchemaFieldBasics;
53
+ exports.SchemaFieldBasics = SchemaFieldBasics;
54
+ exports.schemaFieldBasicComponents = schemaFieldBasicComponents;