@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.
- package/LICENSE +21 -0
- package/README.md +157 -2
- package/lib/additional/LabelRenderer.d.ts +4 -0
- package/lib/additional/index.d.ts +1 -0
- package/lib/cells/BooleanCell.d.ts +3 -0
- package/lib/cells/Cell.d.ts +3 -0
- package/lib/cells/CompositeCell.d.ts +9 -0
- package/lib/cells/CompositeDetailDialog.d.ts +3 -0
- package/lib/cells/EnumCell.d.ts +3 -0
- package/lib/cells/NumberCell.d.ts +3 -0
- package/lib/cells/NumberFormatCell.d.ts +4 -0
- package/lib/cells/TextCell.d.ts +3 -0
- package/lib/cells/asCell.d.ts +12 -0
- package/lib/cells/index.d.ts +7 -0
- package/lib/complex/AdditionalProperties.d.ts +4 -0
- package/lib/complex/AnyOfRenderer.d.ts +7 -0
- package/lib/complex/ArrayChoicesControl.d.ts +6 -0
- package/lib/complex/ArrayControlRenderer.d.ts +4 -0
- package/lib/complex/ArrayPanelToggle.d.ts +6 -0
- package/lib/complex/CollectionPager.d.ts +5 -0
- package/lib/complex/CombinatorSwitchDialog.d.ts +8 -0
- package/lib/complex/DeleteDialog.d.ts +6 -0
- package/lib/complex/DetailDialogContent.d.ts +7 -0
- package/lib/complex/ErrorIndicator.d.ts +7 -0
- package/lib/complex/MixedRenderer.d.ts +6 -0
- package/lib/complex/ObjectRenderer.d.ts +3 -0
- package/lib/complex/OneOfRenderer.d.ts +5 -0
- package/lib/complex/RecursiveTreeRenderer.d.ts +4 -0
- package/lib/complex/RowDetailFrame.d.ts +16 -0
- package/lib/complex/ScalarCompositionRenderer.d.ts +4 -0
- package/lib/complex/TupleAdditionalItems.d.ts +4 -0
- package/lib/complex/TupleControlRenderer.d.ts +6 -0
- package/lib/complex/TupleField.d.ts +4 -0
- package/lib/complex/array/ArrayItemPanels.d.ts +18 -0
- package/lib/complex/array/ArrayItemViewProps.d.ts +11 -0
- package/lib/complex/array/ArrayListDetail.d.ts +9 -0
- package/lib/complex/array/ArrayTable.d.ts +21 -0
- package/lib/complex/index.d.ts +10 -0
- package/lib/complex/mixed/JsonTypeIcon.d.ts +5 -0
- package/lib/complex/mixed/MixedWidgets.d.ts +22 -0
- package/lib/complex/mixed/useConfirmation.d.ts +6 -0
- package/lib/components/ClearValueButton.d.ts +12 -0
- package/lib/components/ScrollRegion.d.ts +4 -0
- package/lib/components/TimePicker.d.ts +13 -0
- package/lib/components/index.d.ts +2 -0
- package/lib/controls/AnyOfStringOrEnumControl.d.ts +4 -0
- package/lib/controls/BooleanControl.d.ts +4 -0
- package/lib/controls/BooleanToggleControl.d.ts +4 -0
- package/lib/controls/ChoiceCards.d.ts +1 -0
- package/lib/controls/DateControl.d.ts +4 -0
- package/lib/controls/DateTimeControl.d.ts +4 -0
- package/lib/controls/EnumControl.d.ts +5 -0
- package/lib/controls/InputControl.d.ts +30 -0
- package/lib/controls/IntegerControl.d.ts +4 -0
- package/lib/controls/NumberControl.d.ts +4 -0
- package/lib/controls/OneOfEnumControl.d.ts +3 -0
- package/lib/controls/PasswordControl.d.ts +9 -0
- package/lib/controls/RadioGroupControl.d.ts +4 -0
- package/lib/controls/SliderControl.d.ts +4 -0
- package/lib/controls/TextControl.d.ts +4 -0
- package/lib/controls/TimeControl.d.ts +4 -0
- package/lib/controls/index.d.ts +15 -0
- package/lib/index.d.ts +6 -0
- package/lib/jsonforms-react-shadcn.cjs.js +3 -0
- package/lib/jsonforms-react-shadcn.cjs.js.map +1 -0
- package/lib/jsonforms-react-shadcn.esm.js +4040 -0
- package/lib/jsonforms-react-shadcn.esm.js.map +1 -0
- package/lib/layouts/CategorizationLayout.d.ts +7 -0
- package/lib/layouts/GroupLayout.d.ts +4 -0
- package/lib/layouts/HorizontalLayout.d.ts +4 -0
- package/lib/layouts/Layout.d.ts +5 -0
- package/lib/layouts/ValidationIndicator.d.ts +4 -0
- package/lib/layouts/VerticalLayout.d.ts +4 -0
- package/lib/layouts/index.d.ts +4 -0
- package/lib/renderers.d.ts +8 -0
- package/lib/util/dateTime.d.ts +12 -0
- package/lib/util/groupState.d.ts +1 -0
- package/lib/util/useTemporalControl.d.ts +28 -0
- package/package.json +86 -3
- package/src/additional/LabelRenderer.tsx +8 -0
- package/src/additional/index.ts +1 -0
- package/src/cells/BooleanCell.tsx +26 -0
- package/src/cells/Cell.tsx +101 -0
- package/src/cells/CompositeCell.tsx +275 -0
- package/src/cells/CompositeDetailDialog.tsx +79 -0
- package/src/cells/EnumCell.tsx +74 -0
- package/src/cells/NumberCell.tsx +51 -0
- package/src/cells/NumberFormatCell.tsx +47 -0
- package/src/cells/TextCell.tsx +40 -0
- package/src/cells/asCell.tsx +79 -0
- package/src/cells/index.ts +7 -0
- package/src/complex/AdditionalProperties.tsx +453 -0
- package/src/complex/AnyOfRenderer.tsx +341 -0
- package/src/complex/ArrayChoicesControl.tsx +303 -0
- package/src/complex/ArrayControlRenderer.tsx +400 -0
- package/src/complex/ArrayPanelToggle.tsx +33 -0
- package/src/complex/CollectionPager.tsx +76 -0
- package/src/complex/CombinatorSwitchDialog.tsx +43 -0
- package/src/complex/DeleteDialog.tsx +41 -0
- package/src/complex/DetailDialogContent.tsx +84 -0
- package/src/complex/ErrorIndicator.tsx +136 -0
- package/src/complex/MixedRenderer.tsx +262 -0
- package/src/complex/ObjectRenderer.tsx +43 -0
- package/src/complex/OneOfRenderer.tsx +14 -0
- package/src/complex/RecursiveTreeRenderer.tsx +20 -0
- package/src/complex/RowDetailFrame.tsx +158 -0
- package/src/complex/ScalarCompositionRenderer.tsx +14 -0
- package/src/complex/TupleAdditionalItems.tsx +94 -0
- package/src/complex/TupleControlRenderer.tsx +54 -0
- package/src/complex/TupleField.tsx +41 -0
- package/src/complex/array/ArrayItemPanels.tsx +217 -0
- package/src/complex/array/ArrayItemViewProps.ts +15 -0
- package/src/complex/array/ArrayListDetail.tsx +165 -0
- package/src/complex/array/ArrayTable.tsx +535 -0
- package/src/complex/index.ts +16 -0
- package/src/complex/mixed/JsonTypeIcon.tsx +41 -0
- package/src/complex/mixed/MixedWidgets.tsx +326 -0
- package/src/complex/mixed/useConfirmation.tsx +34 -0
- package/src/components/ClearValueButton.tsx +56 -0
- package/src/components/ScrollRegion.tsx +27 -0
- package/src/components/TimePicker.tsx +250 -0
- package/src/components/index.ts +2 -0
- package/src/controls/AnyOfStringOrEnumControl.tsx +44 -0
- package/src/controls/BooleanControl.tsx +67 -0
- package/src/controls/BooleanToggleControl.tsx +58 -0
- package/src/controls/ChoiceCards.tsx +9 -0
- package/src/controls/DateControl.tsx +240 -0
- package/src/controls/DateTimeControl.tsx +187 -0
- package/src/controls/EnumControl.tsx +159 -0
- package/src/controls/InputControl.tsx +258 -0
- package/src/controls/IntegerControl.tsx +14 -0
- package/src/controls/NumberControl.tsx +14 -0
- package/src/controls/OneOfEnumControl.tsx +13 -0
- package/src/controls/PasswordControl.tsx +216 -0
- package/src/controls/RadioGroupControl.tsx +72 -0
- package/src/controls/SliderControl.tsx +77 -0
- package/src/controls/TextControl.tsx +50 -0
- package/src/controls/TimeControl.tsx +135 -0
- package/src/controls/index.ts +19 -0
- package/src/index.tsx +10 -0
- package/src/layouts/CategorizationLayout.tsx +248 -0
- package/src/layouts/GroupLayout.tsx +210 -0
- package/src/layouts/HorizontalLayout.tsx +12 -0
- package/src/layouts/Layout.tsx +62 -0
- package/src/layouts/ValidationIndicator.tsx +40 -0
- package/src/layouts/VerticalLayout.tsx +12 -0
- package/src/layouts/index.ts +4 -0
- package/src/renderers.ts +225 -0
- package/src/styles.css +482 -0
- package/src/tailwind-theme.cjs +42 -0
- package/src/theme.css +43 -0
- package/src/util/dateTime.ts +80 -0
- package/src/util/groupState.ts +5 -0
- 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,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.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
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';
|