@chobantonov/jsonforms-react-shadcn-renderers 0.0.0-stage → 0.1.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 (154) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +157 -2
  3. package/lib/additional/LabelRenderer.d.ts +4 -0
  4. package/lib/additional/index.d.ts +1 -0
  5. package/lib/cells/BooleanCell.d.ts +3 -0
  6. package/lib/cells/Cell.d.ts +3 -0
  7. package/lib/cells/CompositeCell.d.ts +9 -0
  8. package/lib/cells/CompositeDetailDialog.d.ts +3 -0
  9. package/lib/cells/EnumCell.d.ts +3 -0
  10. package/lib/cells/NumberCell.d.ts +3 -0
  11. package/lib/cells/NumberFormatCell.d.ts +4 -0
  12. package/lib/cells/TextCell.d.ts +3 -0
  13. package/lib/cells/asCell.d.ts +12 -0
  14. package/lib/cells/index.d.ts +7 -0
  15. package/lib/complex/AdditionalProperties.d.ts +4 -0
  16. package/lib/complex/AnyOfRenderer.d.ts +7 -0
  17. package/lib/complex/ArrayChoicesControl.d.ts +6 -0
  18. package/lib/complex/ArrayControlRenderer.d.ts +4 -0
  19. package/lib/complex/ArrayPanelToggle.d.ts +6 -0
  20. package/lib/complex/CollectionPager.d.ts +5 -0
  21. package/lib/complex/CombinatorSwitchDialog.d.ts +8 -0
  22. package/lib/complex/DeleteDialog.d.ts +6 -0
  23. package/lib/complex/DetailDialogContent.d.ts +7 -0
  24. package/lib/complex/ErrorIndicator.d.ts +7 -0
  25. package/lib/complex/MixedRenderer.d.ts +6 -0
  26. package/lib/complex/ObjectRenderer.d.ts +3 -0
  27. package/lib/complex/OneOfRenderer.d.ts +5 -0
  28. package/lib/complex/RecursiveTreeRenderer.d.ts +4 -0
  29. package/lib/complex/RowDetailFrame.d.ts +16 -0
  30. package/lib/complex/ScalarCompositionRenderer.d.ts +4 -0
  31. package/lib/complex/TupleAdditionalItems.d.ts +4 -0
  32. package/lib/complex/TupleControlRenderer.d.ts +6 -0
  33. package/lib/complex/TupleField.d.ts +4 -0
  34. package/lib/complex/array/ArrayItemPanels.d.ts +18 -0
  35. package/lib/complex/array/ArrayItemViewProps.d.ts +11 -0
  36. package/lib/complex/array/ArrayListDetail.d.ts +9 -0
  37. package/lib/complex/array/ArrayTable.d.ts +21 -0
  38. package/lib/complex/index.d.ts +10 -0
  39. package/lib/complex/mixed/JsonTypeIcon.d.ts +5 -0
  40. package/lib/complex/mixed/MixedWidgets.d.ts +22 -0
  41. package/lib/complex/mixed/useConfirmation.d.ts +6 -0
  42. package/lib/components/ClearValueButton.d.ts +12 -0
  43. package/lib/components/ScrollRegion.d.ts +4 -0
  44. package/lib/components/TimePicker.d.ts +13 -0
  45. package/lib/components/index.d.ts +2 -0
  46. package/lib/controls/AnyOfStringOrEnumControl.d.ts +4 -0
  47. package/lib/controls/BooleanControl.d.ts +4 -0
  48. package/lib/controls/BooleanToggleControl.d.ts +4 -0
  49. package/lib/controls/ChoiceCards.d.ts +1 -0
  50. package/lib/controls/DateControl.d.ts +4 -0
  51. package/lib/controls/DateTimeControl.d.ts +4 -0
  52. package/lib/controls/EnumControl.d.ts +5 -0
  53. package/lib/controls/InputControl.d.ts +30 -0
  54. package/lib/controls/IntegerControl.d.ts +4 -0
  55. package/lib/controls/NumberControl.d.ts +4 -0
  56. package/lib/controls/OneOfEnumControl.d.ts +3 -0
  57. package/lib/controls/PasswordControl.d.ts +9 -0
  58. package/lib/controls/RadioGroupControl.d.ts +4 -0
  59. package/lib/controls/SliderControl.d.ts +4 -0
  60. package/lib/controls/TextControl.d.ts +4 -0
  61. package/lib/controls/TimeControl.d.ts +4 -0
  62. package/lib/controls/index.d.ts +15 -0
  63. package/lib/index.d.ts +6 -0
  64. package/lib/jsonforms-react-shadcn.cjs.js +3 -0
  65. package/lib/jsonforms-react-shadcn.cjs.js.map +1 -0
  66. package/lib/jsonforms-react-shadcn.esm.js +4040 -0
  67. package/lib/jsonforms-react-shadcn.esm.js.map +1 -0
  68. package/lib/layouts/CategorizationLayout.d.ts +7 -0
  69. package/lib/layouts/GroupLayout.d.ts +4 -0
  70. package/lib/layouts/HorizontalLayout.d.ts +4 -0
  71. package/lib/layouts/Layout.d.ts +5 -0
  72. package/lib/layouts/ValidationIndicator.d.ts +4 -0
  73. package/lib/layouts/VerticalLayout.d.ts +4 -0
  74. package/lib/layouts/index.d.ts +4 -0
  75. package/lib/renderers.d.ts +8 -0
  76. package/lib/util/dateTime.d.ts +12 -0
  77. package/lib/util/groupState.d.ts +1 -0
  78. package/lib/util/useTemporalControl.d.ts +28 -0
  79. package/package.json +86 -3
  80. package/src/additional/LabelRenderer.tsx +8 -0
  81. package/src/additional/index.ts +1 -0
  82. package/src/cells/BooleanCell.tsx +26 -0
  83. package/src/cells/Cell.tsx +101 -0
  84. package/src/cells/CompositeCell.tsx +275 -0
  85. package/src/cells/CompositeDetailDialog.tsx +79 -0
  86. package/src/cells/EnumCell.tsx +74 -0
  87. package/src/cells/NumberCell.tsx +51 -0
  88. package/src/cells/NumberFormatCell.tsx +47 -0
  89. package/src/cells/TextCell.tsx +40 -0
  90. package/src/cells/asCell.tsx +79 -0
  91. package/src/cells/index.ts +7 -0
  92. package/src/complex/AdditionalProperties.tsx +453 -0
  93. package/src/complex/AnyOfRenderer.tsx +341 -0
  94. package/src/complex/ArrayChoicesControl.tsx +303 -0
  95. package/src/complex/ArrayControlRenderer.tsx +400 -0
  96. package/src/complex/ArrayPanelToggle.tsx +33 -0
  97. package/src/complex/CollectionPager.tsx +76 -0
  98. package/src/complex/CombinatorSwitchDialog.tsx +43 -0
  99. package/src/complex/DeleteDialog.tsx +41 -0
  100. package/src/complex/DetailDialogContent.tsx +84 -0
  101. package/src/complex/ErrorIndicator.tsx +136 -0
  102. package/src/complex/MixedRenderer.tsx +262 -0
  103. package/src/complex/ObjectRenderer.tsx +43 -0
  104. package/src/complex/OneOfRenderer.tsx +14 -0
  105. package/src/complex/RecursiveTreeRenderer.tsx +20 -0
  106. package/src/complex/RowDetailFrame.tsx +158 -0
  107. package/src/complex/ScalarCompositionRenderer.tsx +14 -0
  108. package/src/complex/TupleAdditionalItems.tsx +94 -0
  109. package/src/complex/TupleControlRenderer.tsx +54 -0
  110. package/src/complex/TupleField.tsx +41 -0
  111. package/src/complex/array/ArrayItemPanels.tsx +217 -0
  112. package/src/complex/array/ArrayItemViewProps.ts +15 -0
  113. package/src/complex/array/ArrayListDetail.tsx +165 -0
  114. package/src/complex/array/ArrayTable.tsx +535 -0
  115. package/src/complex/index.ts +16 -0
  116. package/src/complex/mixed/JsonTypeIcon.tsx +41 -0
  117. package/src/complex/mixed/MixedWidgets.tsx +326 -0
  118. package/src/complex/mixed/useConfirmation.tsx +34 -0
  119. package/src/components/ClearValueButton.tsx +56 -0
  120. package/src/components/ScrollRegion.tsx +27 -0
  121. package/src/components/TimePicker.tsx +250 -0
  122. package/src/components/index.ts +2 -0
  123. package/src/controls/AnyOfStringOrEnumControl.tsx +44 -0
  124. package/src/controls/BooleanControl.tsx +67 -0
  125. package/src/controls/BooleanToggleControl.tsx +58 -0
  126. package/src/controls/ChoiceCards.tsx +9 -0
  127. package/src/controls/DateControl.tsx +240 -0
  128. package/src/controls/DateTimeControl.tsx +187 -0
  129. package/src/controls/EnumControl.tsx +159 -0
  130. package/src/controls/InputControl.tsx +258 -0
  131. package/src/controls/IntegerControl.tsx +14 -0
  132. package/src/controls/NumberControl.tsx +14 -0
  133. package/src/controls/OneOfEnumControl.tsx +13 -0
  134. package/src/controls/PasswordControl.tsx +216 -0
  135. package/src/controls/RadioGroupControl.tsx +72 -0
  136. package/src/controls/SliderControl.tsx +77 -0
  137. package/src/controls/TextControl.tsx +50 -0
  138. package/src/controls/TimeControl.tsx +135 -0
  139. package/src/controls/index.ts +19 -0
  140. package/src/index.tsx +10 -0
  141. package/src/layouts/CategorizationLayout.tsx +248 -0
  142. package/src/layouts/GroupLayout.tsx +210 -0
  143. package/src/layouts/HorizontalLayout.tsx +12 -0
  144. package/src/layouts/Layout.tsx +62 -0
  145. package/src/layouts/ValidationIndicator.tsx +40 -0
  146. package/src/layouts/VerticalLayout.tsx +12 -0
  147. package/src/layouts/index.ts +4 -0
  148. package/src/renderers.ts +225 -0
  149. package/src/styles.css +482 -0
  150. package/src/tailwind-theme.cjs +42 -0
  151. package/src/theme.css +43 -0
  152. package/src/util/dateTime.ts +80 -0
  153. package/src/util/groupState.ts +5 -0
  154. package/src/util/useTemporalControl.ts +160 -0
@@ -0,0 +1,7 @@
1
+ import { LayoutProps } from '@jsonforms/core';
2
+ import React from 'react';
3
+ /** All presentations share identity, visibility and initial-selection rules. */
4
+ export declare const ShadcnCategorizationLayout: (props: LayoutProps) => React.JSX.Element | null;
5
+ export declare const categorizationTester: (uischema: import("@jsonforms/core").UISchemaElement, schema: import("@jsonforms/core").JsonSchema, context: import("@jsonforms/core").TesterContext) => number;
6
+ export declare const categorizationAccordionTester: (uischema: import("@jsonforms/core").UISchemaElement, schema: import("@jsonforms/core").JsonSchema, context: import("@jsonforms/core").TesterContext) => number;
7
+ export declare const categorizationStepperTester: (uischema: import("@jsonforms/core").UISchemaElement, schema: import("@jsonforms/core").JsonSchema, context: import("@jsonforms/core").TesterContext) => number;
@@ -0,0 +1,4 @@
1
+ import { LayoutProps, RankedTester } from '@jsonforms/core';
2
+ import React from 'react';
3
+ export declare const ShadcnGroupLayout: (props: LayoutProps) => React.JSX.Element | null;
4
+ export declare const groupTester: RankedTester;
@@ -0,0 +1,4 @@
1
+ import { LayoutProps, RankedTester } from '@jsonforms/core';
2
+ import React from 'react';
3
+ export declare const ShadcnHorizontalLayout: (props: LayoutProps) => React.JSX.Element;
4
+ export declare const horizontalLayoutTester: RankedTester;
@@ -0,0 +1,5 @@
1
+ import { LayoutProps } from '@jsonforms/core';
2
+ import React from 'react';
3
+ export declare const ShadcnLayout: ({ direction, ...props }: LayoutProps & {
4
+ direction: "row" | "column";
5
+ }) => React.JSX.Element | null;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export declare const ContainerValidationIndicator: ({ count }: {
3
+ count?: number;
4
+ }) => React.JSX.Element;
@@ -0,0 +1,4 @@
1
+ import { LayoutProps, RankedTester } from '@jsonforms/core';
2
+ import React from 'react';
3
+ export declare const ShadcnVerticalLayout: (props: LayoutProps) => React.JSX.Element;
4
+ export declare const verticalLayoutTester: RankedTester;
@@ -0,0 +1,4 @@
1
+ export * from './CategorizationLayout';
2
+ export * from './GroupLayout';
3
+ export * from './HorizontalLayout';
4
+ export * from './VerticalLayout';
@@ -0,0 +1,8 @@
1
+ import { JsonFormsRendererRegistryEntry } from '@jsonforms/core';
2
+ export * from './additional';
3
+ export * from './cells';
4
+ export * from './complex';
5
+ export * from './controls';
6
+ export * from './layouts';
7
+ export declare const shadcnRenderers: JsonFormsRendererRegistryEntry[];
8
+ export declare const advancedShadcnRenderers: JsonFormsRendererRegistryEntry[];
@@ -0,0 +1,12 @@
1
+ export type TimeValue = {
2
+ hours: number;
3
+ minutes: number;
4
+ seconds: number;
5
+ };
6
+ export declare const parseDateValue: (value: unknown) => Date | undefined;
7
+ export declare const formatDateValue: (date: Date) => string;
8
+ export declare const formatDisplayDate: (date: Date, locale?: string) => string;
9
+ export declare const parseTimeValue: (value: unknown) => TimeValue | undefined;
10
+ export declare const formatTimeValue: (time: TimeValue, useSeconds?: boolean) => string;
11
+ export declare const formatDateTimeValue: (date: Date, time: TimeValue) => string;
12
+ export declare const formatDisplayDateTime: (date: Date, time: TimeValue, ampm?: boolean, locale?: string) => string;
@@ -0,0 +1 @@
1
+ export { hasGroupValue, groupHasData, useGroupState, } from '@chobantonov/jsonforms-react-renderer-common/layout/groupState';
@@ -0,0 +1,28 @@
1
+ import type { TimeValue } from './dateTime';
2
+ import type { ControlProps } from '@jsonforms/core';
3
+ import dayjs from 'dayjs';
4
+ declare const saveFormats: {
5
+ date: string;
6
+ time: string;
7
+ dateTime: string;
8
+ };
9
+ /** Shared serialization and bound policy for the three shadcn pickers. */
10
+ export declare function useTemporalControl(props: ControlProps, kind: keyof typeof saveFormats): {
11
+ displayText: string | undefined;
12
+ allowed: (value: Date) => boolean;
13
+ disabledDate: (value: Date) => boolean;
14
+ commit: (value: Date) => void;
15
+ min: Date | undefined;
16
+ max: Date | undefined;
17
+ showHours: boolean;
18
+ showMinutes: boolean;
19
+ useSeconds: boolean;
20
+ ampm: boolean;
21
+ displayFormat: string;
22
+ saveFormat: string;
23
+ placeholder: any;
24
+ options: any;
25
+ selected: dayjs.Dayjs | null;
26
+ selectedTime: TimeValue | undefined;
27
+ };
28
+ export {};
package/package.json CHANGED
@@ -1,6 +1,89 @@
1
1
  {
2
2
  "name": "@chobantonov/jsonforms-react-shadcn-renderers",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Shadcn UI renderers for JSON Forms React",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/kchobantonov/jsonforms-react-renderers.git",
8
+ "directory": "packages/jsonforms-react-shadcn-renderers"
9
+ },
10
+ "bugs": "https://github.com/kchobantonov/jsonforms-react-renderers/issues",
11
+ "homepage": "https://github.com/kchobantonov/jsonforms-react-renderers",
12
+ "license": "MIT",
13
+ "directories": {
14
+ "src": "src"
15
+ },
16
+ "files": [
17
+ "lib",
18
+ "src"
19
+ ],
20
+ "keywords": [
21
+ "shadcn-ui",
22
+ "shadcn",
23
+ "react",
24
+ "renderer",
25
+ "jsonforms",
26
+ "form"
27
+ ],
28
+ "main": "lib/jsonforms-react-shadcn.cjs.js",
29
+ "module": "lib/jsonforms-react-shadcn.esm.js",
30
+ "typings": "lib/index.d.ts",
31
+ "dependencies": {
32
+ "dayjs": "^1.11.11",
33
+ "date-fns": "4.4.0",
34
+ "lucide-react": "1.37.0",
35
+ "lodash": "^4.18.1",
36
+ "@chobantonov/jsonforms-react-renderer-common": "0.1.0"
37
+ },
38
+ "peerDependencies": {
39
+ "@jsonforms/core": "3.9.0-alpha.4",
40
+ "@jsonforms/react": "3.9.0-alpha.4",
41
+ "react": "^18.0.0 || ^19.0.0",
42
+ "react-dom": "^18.0.0 || ^19.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@base-ui/react": "^1.8.0",
46
+ "@jsonforms/core": "3.9.0-alpha.4",
47
+ "@jsonforms/react": "3.9.0-alpha.4",
48
+ "@radix-ui/react-avatar": "^1.2.6",
49
+ "@radix-ui/react-checkbox": "1.3.11",
50
+ "@radix-ui/react-dialog": "1.1.23",
51
+ "@radix-ui/react-popover": "1.1.23",
52
+ "@radix-ui/react-select": "2.3.7",
53
+ "@radix-ui/react-tabs": "1.1.21",
54
+ "@radix-ui/react-tooltip": "^1.2.16",
55
+ "@types/react": "^18.3.23",
56
+ "@types/react-dom": "^18.3.7",
57
+ "@vitest/coverage-v8": "5.1.1",
58
+ "class-variance-authority": "0.7.1",
59
+ "clsx": "2.1.1",
60
+ "jsdom": "^22.0.0",
61
+ "radix-ui": "^1.6.7",
62
+ "react": "^18.3.1",
63
+ "react-day-picker": "10.0.2",
64
+ "react-dom": "^18.3.1",
65
+ "react-resizable-panels": "^4.12.3",
66
+ "rimraf": "^6.1.4",
67
+ "typedoc": "~0.28.20",
68
+ "typescript": "~6.0.3",
69
+ "vite": "npm:@voidzero-dev/vite-plus-core@8.3.8001",
70
+ "vitest": "5.1.1",
71
+ "@types/node": "^22.0.0",
72
+ "@chobantonov/jsonforms-extended-spec": "0.2.0",
73
+ "@types/lodash": "^4.17.27"
74
+ },
75
+ "publishConfig": {
76
+ "access": "public"
77
+ },
78
+ "scripts": {
79
+ "build": "vp build && tsc --emitDeclarationOnly",
80
+ "clean": "rimraf lib coverage dist .nyc_output 2> /dev/null",
81
+ "lint": "vp lint .",
82
+ "lint:fix": "vp run lint --fix",
83
+ "test": "vp test run",
84
+ "test:watch": "vp test",
85
+ "test-cov": "vp test run --coverage",
86
+ "doc": "typedoc --name 'JSON Forms React Shadcn UI Renderers' --excludeExternals --out docs src",
87
+ "tsc": "tsc --build tsconfig.json"
88
+ }
6
89
  }
@@ -0,0 +1,8 @@
1
+ import { LabelProps, RankedTester, rankWith, uiTypeIs } from '@jsonforms/core';
2
+ import React from 'react';
3
+
4
+ export const ShadcnLabelRenderer = ({ text, visible }: LabelProps) => {
5
+ if (!visible) return null;
6
+ return <div className='shadcn-jsonforms-static-label'>{text}</div>;
7
+ };
8
+ export const labelRendererTester: RankedTester = rankWith(1, uiTypeIs('Label'));
@@ -0,0 +1 @@
1
+ export * from './LabelRenderer';
@@ -0,0 +1,26 @@
1
+ import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
2
+ import React from 'react';
3
+ import { CellProps } from '@jsonforms/core';
4
+ import { Checkbox } from '@jsonforms-react-shadcn-ui/checkbox';
5
+
6
+ export const ShadcnBooleanCell = ({
7
+ data,
8
+ enabled,
9
+ visible,
10
+ id,
11
+ path,
12
+ handleChange,
13
+ errors,
14
+ }: CellProps) => {
15
+ const t = useI18n();
16
+ return visible === false ? null : (
17
+ <Checkbox
18
+ id={id}
19
+ aria-label={path || t('control.value')}
20
+ aria-invalid={Boolean(errors)}
21
+ checked={typeof data === 'boolean' ? data : 'indeterminate'}
22
+ disabled={!enabled}
23
+ onCheckedChange={(checked) => handleChange(path, checked === true)}
24
+ />
25
+ );
26
+ };
@@ -0,0 +1,101 @@
1
+ import { dynamicCellEntry } from '@chobantonov/jsonforms-react-renderer-common/dynamic/DynamicUiProvider';
2
+ import {
3
+ ShadcnNumberFormatCell,
4
+ numberFormatCellTester,
5
+ } from './NumberFormatCell';
6
+ import {
7
+ ShadcnBooleanToggleControl,
8
+ booleanToggleControlTester,
9
+ } from '../controls/BooleanToggleControl';
10
+ import {
11
+ ShadcnPasswordControl,
12
+ passwordControlTester,
13
+ } from '../controls/PasswordControl';
14
+ import {
15
+ isIntegerControl,
16
+ isDateControl,
17
+ isTimeControl,
18
+ isDateTimeControl,
19
+ isBooleanControl,
20
+ isEnumControl,
21
+ isOneOfEnumControl,
22
+ isNumberControl,
23
+ isStringControl,
24
+ JsonFormsCellRendererRegistryEntry,
25
+ rankWith,
26
+ } from '@jsonforms/core';
27
+ import { asShadcnCell } from './asCell';
28
+ import { ShadcnDateControl } from '../controls/DateControl';
29
+ import { ShadcnTimeControl } from '../controls/TimeControl';
30
+ import { ShadcnDateTimeControl } from '../controls/DateTimeControl';
31
+ import {
32
+ withJsonFormsControlProps,
33
+ withJsonFormsCellProps,
34
+ } from '@jsonforms/react';
35
+ import {
36
+ ShadcnCompositeCell,
37
+ shadcnCompositeCellTester,
38
+ } from './CompositeCell';
39
+ import { ShadcnBooleanCell } from './BooleanCell';
40
+ import { ShadcnEnumCell } from './EnumCell';
41
+ import { ShadcnNumberCell } from './NumberCell';
42
+ import { ShadcnTextCell } from './TextCell';
43
+
44
+ export { ShadcnTextCell as ShadcnCell } from './TextCell';
45
+ export const shadcnCells: JsonFormsCellRendererRegistryEntry[] = [
46
+ dynamicCellEntry,
47
+ {
48
+ tester: numberFormatCellTester,
49
+ cell: withJsonFormsCellProps(ShadcnNumberFormatCell),
50
+ },
51
+ {
52
+ tester: booleanToggleControlTester,
53
+ cell: asShadcnCell(
54
+ withJsonFormsControlProps(ShadcnBooleanToggleControl),
55
+ ) as any,
56
+ },
57
+ {
58
+ tester: passwordControlTester,
59
+ cell: asShadcnCell(withJsonFormsControlProps(ShadcnPasswordControl)) as any,
60
+ },
61
+ {
62
+ tester: rankWith(5, isOneOfEnumControl),
63
+ cell: withJsonFormsCellProps(ShadcnEnumCell),
64
+ },
65
+ {
66
+ tester: rankWith(3, isDateControl),
67
+ cell: asShadcnCell(withJsonFormsControlProps(ShadcnDateControl)) as any,
68
+ },
69
+ {
70
+ tester: rankWith(3, isTimeControl),
71
+ cell: asShadcnCell(withJsonFormsControlProps(ShadcnTimeControl)) as any,
72
+ },
73
+ {
74
+ tester: rankWith(3, isDateTimeControl),
75
+ cell: asShadcnCell(withJsonFormsControlProps(ShadcnDateTimeControl)) as any,
76
+ },
77
+ {
78
+ tester: shadcnCompositeCellTester,
79
+ cell: withJsonFormsCellProps(ShadcnCompositeCell),
80
+ },
81
+ {
82
+ tester: rankWith(2, isIntegerControl),
83
+ cell: withJsonFormsCellProps(ShadcnNumberCell),
84
+ },
85
+ {
86
+ tester: rankWith(2, isBooleanControl),
87
+ cell: withJsonFormsCellProps(ShadcnBooleanCell),
88
+ },
89
+ {
90
+ tester: rankWith(3, isEnumControl),
91
+ cell: withJsonFormsCellProps(ShadcnEnumCell),
92
+ },
93
+ {
94
+ tester: rankWith(2, isNumberControl),
95
+ cell: withJsonFormsCellProps(ShadcnNumberCell),
96
+ },
97
+ {
98
+ tester: rankWith(1, isStringControl),
99
+ cell: withJsonFormsCellProps(ShadcnTextCell),
100
+ },
101
+ ];
@@ -0,0 +1,275 @@
1
+ import { hasInvalidCompositeEditorDraft } from '@chobantonov/jsonforms-react-renderer-common/cells/useCompositeDraft';
2
+ import { useCompositeCellPresentation } from '@chobantonov/jsonforms-react-renderer-common/cells/useCompositeCellPresentation';
3
+ import { resolveEditorDetail } from '@chobantonov/jsonforms-react-renderer-common/core/detailUiSchema';
4
+ import { CellSummary } from '@chobantonov/jsonforms-react-renderer-common/cells/CellSummary';
5
+ import { ErrorIndicator } from '../complex/ErrorIndicator';
6
+ import { DetailDialogContent } from '../complex/DetailDialogContent';
7
+ import React, { useRef, useState } from 'react';
8
+ import { Pencil, X } from 'lucide-react';
9
+ import {
10
+ CellProps,
11
+ JsonFormsCore,
12
+ JsonFormsRendererRegistryEntry,
13
+ JsonFormsCellRendererRegistryEntry,
14
+ Resolve,
15
+ coreReducer,
16
+ UPDATE_DATA,
17
+ update,
18
+ } from '@jsonforms/core';
19
+ import {
20
+ JsonFormsContext,
21
+ JsonFormsDispatch,
22
+ useJsonForms,
23
+ } from '@jsonforms/react';
24
+ import { shouldConfirm } from '@chobantonov/jsonforms-react-renderer-common/interaction/confirmation';
25
+ import { DeleteDialog } from '../complex/DeleteDialog';
26
+ import { preventsEmpty } from '@chobantonov/jsonforms-react-renderer-common/cells/compositeActions';
27
+ import {
28
+ useI18n,
29
+ useI18nDefault,
30
+ useTranslator,
31
+ } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
32
+ import { Button } from '@jsonforms-react-shadcn-ui/button';
33
+ import {
34
+ Dialog,
35
+ DialogHeader,
36
+ DialogTitle,
37
+ DialogFooter,
38
+ } from '@jsonforms-react-shadcn-ui/dialog';
39
+
40
+ const copy = <T,>(value: T): T =>
41
+ value === undefined ? value : JSON.parse(JSON.stringify(value));
42
+ const equal = (a: unknown, b: unknown) =>
43
+ JSON.stringify(a) === JSON.stringify(b);
44
+ type Props = CellProps & {
45
+ renderers?: JsonFormsRendererRegistryEntry[];
46
+ cells?: JsonFormsCellRendererRegistryEntry[];
47
+ };
48
+
49
+ /** A compact summary with isolated editing; only Apply writes to the form. */
50
+ export const ShadcnCompositeCell = (props: Props) => {
51
+ const parent = useJsonForms();
52
+ const invalidEditorDraft = hasInvalidCompositeEditorDraft(
53
+ parent.core?.additionalErrors,
54
+ props.path,
55
+ );
56
+ const t = useTranslator();
57
+ const d = useI18nDefault();
58
+ const text = useI18n();
59
+ const [pendingDelete, setPendingDelete] = useState<{
60
+ value: unknown;
61
+ path: string;
62
+ }>();
63
+ const [draft, setDraft] = useState<JsonFormsCore>();
64
+ const draftRef = useRef<JsonFormsCore>();
65
+ const [original, setOriginal] = useState<unknown>();
66
+ const options = props.uischema.options ?? {};
67
+ const { errors, summary } = useCompositeCellPresentation(props, t, d);
68
+ const enabled =
69
+ props.enabled &&
70
+ !(parent as any).readonly &&
71
+ !(props.schema as { readOnly?: boolean }).readOnly;
72
+ const label =
73
+ props.schema.title ??
74
+ text(
75
+ props.schema.type === 'array'
76
+ ? 'composite.itemsLabel'
77
+ : 'composite.detailsLabel',
78
+ );
79
+ const current = () => Resolve.data(parent.core?.data, props.path);
80
+ const close = () => {
81
+ draftRef.current = undefined;
82
+ setDraft(undefined);
83
+ };
84
+ const dispatch = (action: any) => {
85
+ if (!enabled || !draftRef.current || action.type !== UPDATE_DATA) return;
86
+ if (
87
+ props.path &&
88
+ action.path !== props.path &&
89
+ !action.path.startsWith(`${props.path}.`)
90
+ )
91
+ return;
92
+ draftRef.current = coreReducer(draftRef.current, action);
93
+ setDraft(draftRef.current);
94
+ };
95
+ const value = draft && Resolve.data(draft.data, props.path);
96
+ const isArray = props.schema.type === 'array';
97
+ const conflicted = !!draft && !equal(current(), original);
98
+ const canClear =
99
+ enabled &&
100
+ !options.disableRemove &&
101
+ value != null &&
102
+ typeof value === 'object' &&
103
+ Object.keys(value).length > 0 &&
104
+ (options.restrict === false || !preventsEmpty(props.schema, isArray));
105
+ if (props.visible === false) return null;
106
+ return (
107
+ <div className='group/composite flex min-w-0 items-center gap-1.5'>
108
+ {(options.showTypeIndicator ??
109
+ props.config?.showTypeIndicator ??
110
+ false) === true &&
111
+ (isArray || props.schema?.type === 'object') && (
112
+ <span aria-hidden='true' className='shrink-0 text-muted-foreground'>
113
+ {isArray ? '[]' : '{}'}
114
+ </span>
115
+ )}
116
+ <span
117
+ className={`min-w-0 flex-1 truncate${
118
+ summary.generated && options.summary?.type !== 'Label'
119
+ ? ' italic text-muted-foreground'
120
+ : ''
121
+ }`}
122
+ >
123
+ {options.summary?.type === 'Label' ? (
124
+ <CellSummary
125
+ schema={props.schema}
126
+ path={props.path}
127
+ uischema={options.summary}
128
+ />
129
+ ) : (
130
+ summary.text
131
+ )}
132
+ </span>
133
+ {errors && <ErrorIndicator errors={errors} path={props.path} />}
134
+ {((!options.summaryOnly && options.summary?.type !== 'Label') ||
135
+ options.detail) && (
136
+ <Button
137
+ type='button'
138
+ variant='ghost'
139
+ size='icon'
140
+ className='h-7 w-7 shrink-0 opacity-0 group-hover/composite:opacity-100 group-focus-within/composite:opacity-100 [@media(hover:none)]:opacity-100'
141
+ title={text('composite.edit', { label })}
142
+ aria-label={text('composite.edit', { label })}
143
+ onClick={() => {
144
+ if (!parent.core) return;
145
+ setOriginal(copy(current()));
146
+ draftRef.current = {
147
+ ...parent.core,
148
+ data: copy(parent.core?.data),
149
+ };
150
+ setDraft(draftRef.current);
151
+ }}
152
+ >
153
+ <Pencil className='h-4 w-4' aria-hidden='true' />
154
+ </Button>
155
+ )}
156
+ {enabled &&
157
+ !options.summaryOnly &&
158
+ (options.summary?.type !== 'Label' || !!options.detail) &&
159
+ props.data !== undefined &&
160
+ options.clearable !== false && (
161
+ <Button
162
+ type='button'
163
+ variant='ghost'
164
+ size='icon'
165
+ className='h-7 w-7 shrink-0 opacity-0 group-hover/composite:opacity-100 group-focus-within/composite:opacity-100 [@media(hover:none)]:opacity-100'
166
+ style={{ color: 'hsl(var(--destructive))' }}
167
+ title={text('composite.remove', { label })}
168
+ aria-label={text('composite.remove', { label })}
169
+ onClick={() => {
170
+ if (
171
+ shouldConfirm(
172
+ {
173
+ catalogId: 'compositeCell',
174
+ operation: 'delete',
175
+ options,
176
+ config: props.config,
177
+ },
178
+ [props.data],
179
+ )
180
+ )
181
+ setPendingDelete({ value: props.data, path: props.path });
182
+ else props.handleChange(props.path, undefined);
183
+ }}
184
+ >
185
+ <X className='h-4 w-4' aria-hidden='true' />
186
+ </Button>
187
+ )}
188
+ <DeleteDialog
189
+ open={!!pendingDelete}
190
+ onCancel={() => setPendingDelete(undefined)}
191
+ onConfirm={() => {
192
+ if (
193
+ pendingDelete &&
194
+ enabled &&
195
+ options.clearable !== false &&
196
+ pendingDelete.path === props.path &&
197
+ pendingDelete.value === props.data
198
+ )
199
+ props.handleChange(props.path, undefined);
200
+ setPendingDelete(undefined);
201
+ }}
202
+ />
203
+ <Dialog open={!!draft} onOpenChange={(open) => !open && close()}>
204
+ <DetailDialogContent
205
+ open={!!draft}
206
+ options={options.dialog}
207
+ aria-describedby={undefined}
208
+ className='max-h-[85vh] overflow-auto sm:max-w-2xl'
209
+ >
210
+ <DialogHeader>
211
+ <DialogTitle>
212
+ {props.schema.title ?? text('composite.detailsTitle')}
213
+ </DialogTitle>
214
+ </DialogHeader>
215
+ {draft && (
216
+ <JsonFormsContext.Provider
217
+ value={{ ...parent, core: draft, dispatch }}
218
+ >
219
+ <JsonFormsDispatch
220
+ schema={props.schema}
221
+ uischema={resolveEditorDetail(
222
+ options.detail,
223
+ parent.uischemas ?? [],
224
+ props.schema,
225
+ props.uischema.scope,
226
+ props.path,
227
+ props.rootSchema,
228
+ { type: 'Control', scope: '#', label: false } as any,
229
+ )}
230
+ path={props.path}
231
+ enabled={enabled}
232
+ renderers={props.renderers}
233
+ cells={props.cells}
234
+ />
235
+ </JsonFormsContext.Provider>
236
+ )}
237
+ <DialogFooter>
238
+ {options.showEmptyButton === true && (
239
+ <Button
240
+ type='button'
241
+ variant='outline'
242
+ disabled={!canClear}
243
+ onClick={() =>
244
+ dispatch(update(props.path, () => (isArray ? [] : {})))
245
+ }
246
+ >
247
+ {options.emptyLabel ?? text('composite.empty')}
248
+ </Button>
249
+ )}
250
+ <Button type='button' variant='outline' onClick={close}>
251
+ {options.cancelLabel ?? text('composite.cancel')}
252
+ </Button>
253
+ <Button
254
+ type='button'
255
+ disabled={!enabled || conflicted || invalidEditorDraft}
256
+ title={conflicted ? text('composite.applyConflict') : undefined}
257
+ onClick={() => {
258
+ if (!enabled || conflicted || invalidEditorDraft) return;
259
+ const next = copy(
260
+ Resolve.data(draftRef.current?.data, props.path),
261
+ );
262
+ if (!equal(next, original))
263
+ props.handleChange(props.path, next);
264
+ close();
265
+ }}
266
+ >
267
+ {options.okLabel ?? text('composite.apply')}
268
+ </Button>
269
+ </DialogFooter>
270
+ </DetailDialogContent>
271
+ </Dialog>
272
+ </div>
273
+ );
274
+ };
275
+ export { compositeCellTester as shadcnCompositeCellTester } from '@chobantonov/jsonforms-react-renderer-common/cells/compositeCellTester';