@chobantonov/jsonforms-react-antd-extended-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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +46 -2
  3. package/lib/cells/asCell.d.ts +32 -0
  4. package/lib/components/AntdArrayFrame.d.ts +8 -0
  5. package/lib/components/AntdEditorButton.d.ts +10 -0
  6. package/lib/components/AntdEditorFrame.d.ts +3 -0
  7. package/lib/components/AntdEditorLoading.d.ts +8 -0
  8. package/lib/components/AntdEditorSurface.d.ts +7 -0
  9. package/lib/components/AntdMaskInput.d.ts +40 -0
  10. package/lib/components/PickerFormItem.d.ts +6 -0
  11. package/lib/hooks/useAntdEditorTheme.d.ts +8 -0
  12. package/lib/index.d.ts +45 -0
  13. package/lib/jsonforms-react-antd-extended.cjs.js +2 -0
  14. package/lib/jsonforms-react-antd-extended.cjs.js.map +1 -0
  15. package/lib/jsonforms-react-antd-extended.esm.js +906 -0
  16. package/lib/jsonforms-react-antd-extended.esm.js.map +1 -0
  17. package/lib/renderers/AntdAgGridControlRenderer.d.ts +2 -0
  18. package/lib/renderers/AntdButtonRenderer.d.ts +3 -0
  19. package/lib/renderers/AntdColorControlRenderer.d.ts +30 -0
  20. package/lib/renderers/AntdCronControlRenderer.d.ts +43 -0
  21. package/lib/renderers/AntdDurationControlRenderer.d.ts +5 -0
  22. package/lib/renderers/AntdMarkupLabelRenderer.d.ts +18 -0
  23. package/lib/renderers/AntdMaskControlRenderer.d.ts +9 -0
  24. package/lib/renderers/AntdMonacoControlRenderer.d.ts +1 -0
  25. package/lib/renderers/AntdNullControlRenderer.d.ts +5 -0
  26. package/lib/renderers/AntdSplitLayoutRenderer.d.ts +6 -0
  27. package/lib/renderers/index.d.ts +8 -0
  28. package/lib/util/colorFormat.d.ts +11 -0
  29. package/package.json +78 -3
  30. package/src/cells/asCell.tsx +47 -0
  31. package/src/components/AntdArrayFrame.tsx +69 -0
  32. package/src/components/AntdEditorButton.tsx +37 -0
  33. package/src/components/AntdEditorFrame.tsx +16 -0
  34. package/src/components/AntdEditorLoading.tsx +13 -0
  35. package/src/components/AntdEditorSurface.tsx +52 -0
  36. package/src/components/AntdMaskInput.tsx +95 -0
  37. package/src/components/PickerFormItem.tsx +23 -0
  38. package/src/hooks/useAntdEditorTheme.ts +63 -0
  39. package/src/index.tsx +166 -0
  40. package/src/renderers/AntdAgGridControlRenderer.tsx +56 -0
  41. package/src/renderers/AntdButtonRenderer.tsx +49 -0
  42. package/src/renderers/AntdColorControlRenderer.tsx +313 -0
  43. package/src/renderers/AntdCronControlRenderer.tsx +393 -0
  44. package/src/renderers/AntdDurationControlRenderer.tsx +274 -0
  45. package/src/renderers/AntdMarkupLabelRenderer.tsx +27 -0
  46. package/src/renderers/AntdMaskControlRenderer.tsx +19 -0
  47. package/src/renderers/AntdMonacoControlRenderer.tsx +21 -0
  48. package/src/renderers/AntdNullControlRenderer.tsx +70 -0
  49. package/src/renderers/AntdSplitLayoutRenderer.tsx +122 -0
  50. package/src/renderers/index.ts +8 -0
  51. package/src/util/colorFormat.ts +42 -0
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import { Button } from 'antd';
3
+ import type { EditorActionProps } from '@chobantonov/jsonforms-react-extended-renderers';
4
+
5
+ /**
6
+ * Maps the renderer-agnostic action props onto antd's Button.
7
+ * Follows Ant Design Pro's toolbar convention: the primary action carries an
8
+ * icon and a label, destructive ones are icon-only with a tooltip.
9
+ */
10
+ export const AntdEditorButton = ({
11
+ variant,
12
+ icon,
13
+ children,
14
+ ...props
15
+ }: EditorActionProps) => (
16
+ <Button
17
+ {...props}
18
+ icon={icon}
19
+ type={variant === 'primary' ? 'primary' : 'default'}
20
+ danger={variant === 'danger'}
21
+ >
22
+ {children}
23
+ </Button>
24
+ );
25
+
26
+ /** Borderless variant used for the editor's maximize/restore toggle. */
27
+ export const AntdEditorToggleButton = ({
28
+ icon,
29
+ children,
30
+ // our own union; antd's Button has an unrelated `variant` prop
31
+ variant: _variant,
32
+ ...props
33
+ }: EditorActionProps) => (
34
+ <Button {...props} icon={icon} type='text' size='small'>
35
+ {children}
36
+ </Button>
37
+ );
@@ -0,0 +1,16 @@
1
+ import { ControlFormItem } from '@chobantonov/jsonforms-react-antd-renderers';
2
+ import React from 'react';
3
+ import { EditorControlFrameProps } from '@chobantonov/jsonforms-react-extended-renderers';
4
+ export const AntdEditorFrame = ({
5
+ children,
6
+ ...props
7
+ }: EditorControlFrameProps) => (
8
+ <ControlFormItem
9
+ label={props.label}
10
+ required={props.required}
11
+ errors={props.errors || undefined}
12
+ help={props.errors || props.description}
13
+ >
14
+ {children}
15
+ </ControlFormItem>
16
+ );
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { Alert, Skeleton } from 'antd';
3
+
4
+ /** Placeholder while a lazily loaded control (Monaco, AG Grid) is fetched. */
5
+ export const AntdEditorLoading = ({ label }: { label?: string }) => (
6
+ <Skeleton.Node active style={{ width: '100%', height: 120 }}>
7
+ <span style={{ fontSize: 12 }}>{label}</span>
8
+ </Skeleton.Node>
9
+ );
10
+
11
+ export const AntdEditorLoadError = ({ label }: { label?: string }) => (
12
+ <Alert type='error' showIcon message={label} />
13
+ );
@@ -0,0 +1,52 @@
1
+ import React from 'react';
2
+ import { theme as antTheme } from 'antd';
3
+ import type { EditorSurfaceProps } from '@chobantonov/jsonforms-react-extended-renderers';
4
+
5
+ /**
6
+ * Chrome matching antd's Input.TextArea: same border, radius, background and
7
+ * hover/focus/error transitions, with the editor in place of the textarea.
8
+ */
9
+ export const AntdEditorSurface = ({
10
+ children,
11
+ hovered,
12
+ focused,
13
+ disabled,
14
+ invalid,
15
+ maximized,
16
+ }: EditorSurfaceProps) => {
17
+ const { token } = antTheme.useToken();
18
+ const borderColor = invalid
19
+ ? focused || hovered
20
+ ? token.colorErrorBorderHover
21
+ : token.colorError
22
+ : disabled
23
+ ? token.colorBorder
24
+ : focused
25
+ ? token.colorPrimary
26
+ : hovered
27
+ ? token.colorPrimaryHover
28
+ : token.colorBorder;
29
+ return (
30
+ <div
31
+ style={{
32
+ position: 'relative',
33
+ height: maximized ? '100%' : undefined,
34
+ overflow: 'hidden',
35
+ boxSizing: 'border-box',
36
+ border: `${token.lineWidth}px ${token.lineType} ${borderColor}`,
37
+ borderRadius: token.borderRadius,
38
+ background: disabled
39
+ ? token.colorBgContainerDisabled
40
+ : token.colorBgContainer,
41
+ boxShadow: focused
42
+ ? `0 0 0 ${token.controlOutlineWidth}px ${
43
+ invalid ? token.colorErrorOutline : token.controlOutline
44
+ }`
45
+ : undefined,
46
+ transition: `border-color ${token.motionDurationMid}, box-shadow ${token.motionDurationMid}`,
47
+ }}
48
+ >
49
+ {children}
50
+ </div>
51
+ );
52
+ };
@@ -0,0 +1,95 @@
1
+ import { CellProps, WithClassname } from '@jsonforms/core';
2
+ import { AntdClearableInput } from '@chobantonov/jsonforms-react-antd-renderers';
3
+ import { Input } from 'antd';
4
+ import type { InputRef } from 'antd';
5
+ import React, { useRef, useCallback } from 'react';
6
+ import { useMaskedInput } from '@chobantonov/jsonforms-react-renderer-common/formats/useMaskedInput';
7
+
8
+ /**
9
+ * The masked text field.
10
+ *
11
+ * Written in the shape of a cell rather than as a whole control, so the frame
12
+ * comes from `InputControl` like every other antd input - label, description,
13
+ * required marker and error message included. It is registered as a renderer
14
+ * only; see Adjustment 11.10 for why there is no masked table cell.
15
+ *
16
+ * Three decisions are worth reading before changing anything here.
17
+ *
18
+ * **The engine is driven by hand, not through maska's `MaskInput`.** That class
19
+ * assigns `input.value` directly and announces the result with a
20
+ * `CustomEvent('input')`. React tracks a controlled input's value through a
21
+ * patched `value` setter, so the assignment updates React's tracker and the
22
+ * synthetic `onChange` that would follow is suppressed; the CustomEvent does
23
+ * not bubble, so React's root listener never sees it either. The binding would
24
+ * silently stop reporting edits. `MaskInput` also normalizes the field's value
25
+ * in a microtask after it attaches, which is exactly the mount-time rewrite the
26
+ * specification forbids. Only the pure `Mask` is used, and the binding is here.
27
+ *
28
+ * **Edits commit immediately.** The text control debounces by 300ms; this one
29
+ * does not, because the displayed text and the stored value are two different
30
+ * strings and keeping a third, in-flight one would mean the field could not
31
+ * tell a draft from data the host had replaced underneath it. Committing in
32
+ * step makes the rule below exact, and leaves nothing for a detail dialog's
33
+ * Apply to flush.
34
+ *
35
+ * **The draft is only trusted while it still means the stored value.** There is
36
+ * no effect synchronizing state to props: the typed text is used when it still
37
+ * round-trips to what is in the data, and otherwise the display is derived from
38
+ * the data. An external replacement therefore wins automatically, which is what
39
+ * the pending-edit contract asks for - "data replacement policy must not
40
+ * silently let an outdated draft overwrite the replacement."
41
+ */
42
+ export const AntdMaskInput = React.memo(function AntdMaskInput(
43
+ props: CellProps &
44
+ WithClassname & {
45
+ inputProps?: React.ComponentProps<typeof Input>;
46
+ },
47
+ ) {
48
+ const { data, className, id, enabled, inputProps } = props;
49
+ const inputRef = useRef<InputRef>(null);
50
+ const getInput = useCallback(() => inputRef.current?.input, []);
51
+ const {
52
+ appliedUiSchemaOptions,
53
+ settings,
54
+ display,
55
+ onClear,
56
+ onChange,
57
+ onCompositionStart,
58
+ onCompositionEnd,
59
+ } = useMaskedInput(props, getInput, 'commit');
60
+
61
+ return (
62
+ <AntdClearableInput
63
+ clearable={appliedUiSchemaOptions.clearable !== false}
64
+ data={data}
65
+ enabled={enabled}
66
+ onClear={onClear}
67
+ >
68
+ <Input
69
+ ref={inputRef}
70
+ value={display}
71
+ onChange={onChange}
72
+ onCompositionStart={onCompositionStart}
73
+ onCompositionEnd={onCompositionEnd}
74
+ className={className}
75
+ id={id}
76
+ disabled={!enabled}
77
+ autoFocus={appliedUiSchemaOptions.focus}
78
+ style={{ width: '100%' }}
79
+ /*
80
+ The mask is the fallback hint, which is the convention in the
81
+ neighbouring Vuetify family and which the specification permits so
82
+ long as a renderer says which it does: `###-###` shows the shape of
83
+ the field without claiming to be a real value. An explicit empty
84
+ placeholder suppresses it, as section 18 requires.
85
+ */
86
+ placeholder={
87
+ appliedUiSchemaOptions.placeholder ??
88
+ (typeof settings?.mask === 'string' ? settings.mask : undefined)
89
+ }
90
+ data-mask-input
91
+ {...inputProps}
92
+ />
93
+ </AntdClearableInput>
94
+ );
95
+ });
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import type { ControlProps } from '@jsonforms/core';
3
+ import { ControlFormItem } from '@chobantonov/jsonforms-react-antd-renderers';
4
+
5
+ export function PickerFormItem({
6
+ props,
7
+ error,
8
+ children,
9
+ }: React.PropsWithChildren<{ props: ControlProps; error?: string }>) {
10
+ return (
11
+ <ControlFormItem
12
+ adornmentSchema={props.schema}
13
+ adornmentOptions={props.uischema.options as Record<string, unknown>}
14
+ id={props.id}
15
+ required={props.required}
16
+ errors={error || undefined}
17
+ label={props.label}
18
+ help={error || props.description}
19
+ >
20
+ {children}
21
+ </ControlFormItem>
22
+ );
23
+ }
@@ -0,0 +1,63 @@
1
+ import { theme as antTheme } from 'antd';
2
+ import type { EditorTheme } from '@chobantonov/jsonforms-react-extended-renderers';
3
+
4
+ /**
5
+ * antd exposes no `isDark` flag, but `colorBgBase` is the seed background the
6
+ * active algorithm sets (#fff for defaultAlgorithm, #000 for darkAlgorithm), so
7
+ * its luminance is an exact read of the configured theme - unlike inspecting the
8
+ * DOM it works even when the host paints no background of its own.
9
+ */
10
+ export const useAntdEditorTheme = (): EditorTheme => {
11
+ const { token } = antTheme.useToken();
12
+ // antd's seed leaves colorBgBase as '' unless the host sets it, and the
13
+ // algorithms do not fill it in - so `??` is not enough, empty strings have to
14
+ // be skipped too. colorBgContainer is always a real color.
15
+ const base = firstColor(token.colorBgBase, token.colorBgContainer);
16
+ return {
17
+ isDark: isDark(base),
18
+ background: token.colorBgContainer,
19
+ foreground: token.colorText,
20
+ border: token.colorBorderSecondary ?? token.colorBorder,
21
+ accent: token.colorPrimary,
22
+ headerBackground: token.colorFillAlter ?? token.colorFillQuaternary,
23
+ headerForeground: token.colorTextHeading ?? token.colorText,
24
+ rowHover: token.controlItemBgHover,
25
+ selectedRowBackground: token.controlItemBgActive,
26
+ fontFamily: token.fontFamily,
27
+ };
28
+ };
29
+
30
+ const firstColor = (...candidates: unknown[]): string | undefined =>
31
+ candidates.find(
32
+ (value): value is string =>
33
+ typeof value === 'string' && value.trim() !== '',
34
+ );
35
+
36
+ const isDark = (color: unknown): boolean | undefined => {
37
+ if (typeof color !== 'string') return undefined;
38
+ const rgb = color.startsWith('#')
39
+ ? hexToRgb(color)
40
+ : color
41
+ .match(/[\d.]+/g)
42
+ ?.map(Number)
43
+ .slice(0, 3);
44
+ if (!rgb || rgb.length < 3) return undefined;
45
+ return rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114 < 128;
46
+ };
47
+
48
+ const hexToRgb = (hex: string): number[] | undefined => {
49
+ const value = hex.replace('#', '');
50
+ const full =
51
+ value.length === 3
52
+ ? value
53
+ .split('')
54
+ .map((c) => c + c)
55
+ .join('')
56
+ : value;
57
+ if (full.length < 6) return undefined;
58
+ return [
59
+ parseInt(full.slice(0, 2), 16),
60
+ parseInt(full.slice(2, 4), 16),
61
+ parseInt(full.slice(4, 6), 16),
62
+ ];
63
+ };
package/src/index.tsx ADDED
@@ -0,0 +1,166 @@
1
+ import {
2
+ extendedAgGridTester,
3
+ markupLabelTester,
4
+ monacoControlTester,
5
+ createExtendedRenderers,
6
+ } from '@chobantonov/jsonforms-react-extended-renderers';
7
+ import { AntdAgGridControlRenderer } from './renderers/AntdAgGridControlRenderer';
8
+ import { AntdMonacoControlRenderer } from './renderers/AntdMonacoControlRenderer';
9
+ import {
10
+ JsonFormsCellRendererRegistryEntry,
11
+ JsonFormsRendererRegistryEntry,
12
+ } from '@jsonforms/core';
13
+ import { Alert, Button } from 'antd';
14
+ import React from 'react';
15
+ import {
16
+ AntdButtonRenderer,
17
+ AntdColorControlRenderer,
18
+ AntdCronControlRenderer,
19
+ AntdMarkupLabelRenderer,
20
+ AntdDurationControlRenderer,
21
+ AntdMaskControlRenderer,
22
+ AntdNullControlRenderer,
23
+ AntdSplitLayoutRenderer,
24
+ antdButtonRendererTester,
25
+ antdColorControlTester,
26
+ antdCronControlTester,
27
+ antdDurationControlTester,
28
+ antdMaskControlTester,
29
+ antdNullControlTester,
30
+ antdSplitLayoutTester,
31
+ } from './renderers';
32
+ import { asCell } from './cells/asCell';
33
+
34
+ export type AntdExtendedRendererOptions = {
35
+ components?: Record<string, React.ComponentType<any>>;
36
+ };
37
+
38
+ export const createAntdExtendedRenderers = (
39
+ options: AntdExtendedRendererOptions = {},
40
+ ): JsonFormsRendererRegistryEntry[] => {
41
+ return [
42
+ { tester: extendedAgGridTester, renderer: AntdAgGridControlRenderer },
43
+ { tester: monacoControlTester, renderer: AntdMonacoControlRenderer },
44
+ {
45
+ tester: antdButtonRendererTester,
46
+ renderer: AntdButtonRenderer,
47
+ },
48
+ { tester: antdColorControlTester, renderer: AntdColorControlRenderer },
49
+ /*
50
+ Ahead of the extended set's own entry for the same tester: both rank 3,
51
+ and JSON Forms breaks a tie by taking the first maximum, so the one with
52
+ antd's typography wins.
53
+ */
54
+ { tester: markupLabelTester, renderer: AntdMarkupLabelRenderer },
55
+ { tester: antdCronControlTester, renderer: AntdCronControlRenderer },
56
+ {
57
+ tester: antdDurationControlTester,
58
+ renderer: AntdDurationControlRenderer,
59
+ },
60
+ { tester: antdMaskControlTester, renderer: AntdMaskControlRenderer },
61
+ { tester: antdNullControlTester, renderer: AntdNullControlRenderer },
62
+ { tester: antdSplitLayoutTester, renderer: AntdSplitLayoutRenderer },
63
+ ...createExtendedRenderers({
64
+ components: {
65
+ Alert,
66
+ Button,
67
+ ...options.components,
68
+ },
69
+ includeButtonRenderer: false,
70
+ }),
71
+ ];
72
+ };
73
+
74
+ export const antdExtendedRenderers = createAntdExtendedRenderers();
75
+
76
+ /**
77
+ * The extended controls, registered as **cells**.
78
+ *
79
+ * Both array presentations - the AG Grid renderer and the antd table - draw a
80
+ * column through `DispatchCell` against the *cells* registry, never the
81
+ * renderer registry, because dispatching a renderer would pick the object
82
+ * renderer and inline a whole detail form in the cell. The consequence is
83
+ * easy to miss: a control that exists only as a **renderer** is unreachable
84
+ * in a column, and the column silently falls back to `TextCell` - a colour
85
+ * field shows `#3366ff` as text, a duration shows `P2DT3H`.
86
+ *
87
+ * These entries close that. They are the **same components**, not cell-only
88
+ * copies: `ControlFormItem` already drops the label and the inline message
89
+ * when it is inside a `CellModeProvider`, which is exactly what a column
90
+ * needs, so there is nothing for a second implementation to do.
91
+ *
92
+ * Kept out of the base `antdCells` because the components live here, and the
93
+ * base renderer set must not depend on the extended one. That makes this
94
+ * opt-in: a host that does not concatenate it keeps the text fallback.
95
+ *
96
+ * `monacoControlTester` is deliberately absent. A code editor is not a cell -
97
+ * it draws no `ControlFormItem`, it wants height a row does not have, and the
98
+ * composite detail dialog is where a value that large belongs.
99
+ */
100
+ export const createAntdExtendedCells =
101
+ (): JsonFormsCellRendererRegistryEntry[] =>
102
+ [
103
+ {
104
+ tester: antdColorControlTester,
105
+ cell: asCell(AntdColorControlRenderer),
106
+ },
107
+ {
108
+ tester: antdCronControlTester,
109
+ cell: asCell(AntdCronControlRenderer),
110
+ },
111
+ {
112
+ tester: antdDurationControlTester,
113
+ cell: asCell(AntdDurationControlRenderer),
114
+ },
115
+ { tester: antdMaskControlTester, cell: asCell(AntdMaskControlRenderer) },
116
+ { tester: antdNullControlTester, cell: asCell(AntdNullControlRenderer) },
117
+ /*
118
+ `asCell` is why these are not registered directly, and the cast is
119
+ what is left after it: a cell entry is typed `CellProps` while these
120
+ read `ControlProps`. See `asCell.tsx` for the one field the two
121
+ registries genuinely disagree about.
122
+ */
123
+ ] as unknown as JsonFormsCellRendererRegistryEntry[];
124
+
125
+ export const antdExtendedCells = createAntdExtendedCells();
126
+ export const advancedAntdRenderers = antdExtendedRenderers;
127
+
128
+ export * from '@chobantonov/jsonforms-react-extended-renderers';
129
+ export * from './renderers';
130
+ export * from './components/AntdMaskInput';
131
+ export {
132
+ EMPTY_DURATION,
133
+ parseDuration,
134
+ formatDuration,
135
+ } from '@chobantonov/jsonforms-react-renderer-common/formats/duration';
136
+ export type { DurationParts } from '@chobantonov/jsonforms-react-renderer-common/formats/duration';
137
+ export * from './cells/asCell';
138
+
139
+ export * from './renderers/AntdMonacoControlRenderer';
140
+
141
+ export * from './renderers/AntdAgGridControlRenderer';
142
+
143
+ export * from './util/colorFormat';
144
+
145
+ export {
146
+ DEFAULT_MASK_TOKENS,
147
+ MASKA_DEFAULT_TOKENS,
148
+ compileTokenPattern,
149
+ toMaskTokens,
150
+ DEFAULT_MASK_SETTINGS,
151
+ resolveMaskSettings,
152
+ createMask,
153
+ storedValue,
154
+ fitsMask,
155
+ displayValue,
156
+ codePointLength,
157
+ withinMaxLength,
158
+ nextCaret,
159
+ maskEdit,
160
+ } from '@chobantonov/jsonforms-react-renderer-common/formats/maskFormat';
161
+ export type {
162
+ MaskPattern,
163
+ MaskTokenSpec,
164
+ MaskTokenSpecs,
165
+ MaskSettings,
166
+ } from '@chobantonov/jsonforms-react-renderer-common/formats/maskFormat';
@@ -0,0 +1,56 @@
1
+ import { createDeleteConfirmation } from '@chobantonov/jsonforms-react-renderer-common/interaction/createDeleteConfirmation';
2
+ import React from 'react';
3
+ import {
4
+ ValidationIcon,
5
+ ConnectedCellFrame,
6
+ RowDetailFrame,
7
+ useConfirmation,
8
+ } from '@chobantonov/jsonforms-react-antd-renderers';
9
+ import { createAgGridControlRenderer } from '@chobantonov/jsonforms-react-extended-renderers';
10
+ import {
11
+ DeleteOutlined,
12
+ PlusOutlined,
13
+ EditOutlined,
14
+ EyeOutlined,
15
+ EyeInvisibleOutlined,
16
+ } from '@ant-design/icons';
17
+ import { AntdEditorButton } from '../components/AntdEditorButton';
18
+ import { AntdArrayFrame } from '../components/AntdArrayFrame';
19
+ import { AntdEditorFrame } from '../components/AntdEditorFrame';
20
+ import {
21
+ AntdEditorLoadError,
22
+ AntdEditorLoading,
23
+ } from '../components/AntdEditorLoading';
24
+ import { useAntdEditorTheme } from '../hooks/useAntdEditorTheme';
25
+ /**
26
+ * The grid's own confirmation, supplied from this side of the boundary.
27
+ *
28
+ * The agnostic renderer knows only that something would be discarded; the
29
+ * catalog id - `agGrid`, section 14's name for this renderer - belongs here,
30
+ * with the renderer set that actually registers it. That keeps the
31
+ * framework-agnostic package free of both antd and the policy vocabulary.
32
+ */
33
+ const useAgGridRemoveConfirmation = createDeleteConfirmation(
34
+ useConfirmation,
35
+ 'agGrid',
36
+ );
37
+
38
+ export const AntdAgGridControlRenderer = createAgGridControlRenderer({
39
+ RowErrorIndicator: ({ message }) => (
40
+ <ValidationIcon errorMessages={message} id={React.useId()} />
41
+ ),
42
+ Frame: AntdEditorFrame,
43
+ RowDetailFrame,
44
+ EditIcon: EditOutlined,
45
+ ShowDetailsIcon: EyeOutlined,
46
+ HideDetailsIcon: EyeInvisibleOutlined,
47
+ ArrayFrame: AntdArrayFrame,
48
+ CellFrame: ConnectedCellFrame,
49
+ Button: AntdEditorButton,
50
+ AddIcon: PlusOutlined,
51
+ RemoveIcon: DeleteOutlined,
52
+ useEditorTheme: useAntdEditorTheme,
53
+ Loading: AntdEditorLoading,
54
+ LoadError: AntdEditorLoadError,
55
+ useRemoveConfirmation: useAgGridRemoveConfirmation,
56
+ });
@@ -0,0 +1,49 @@
1
+ import { RankedTester } from '@jsonforms/core';
2
+ import {
3
+ buttonRendererTester,
4
+ createButtonRenderer,
5
+ } from '@chobantonov/jsonforms-react-extended-renderers';
6
+
7
+ /*
8
+ Section 14's closed set, restated rather than imported: the base package
9
+ publishes its types from a build, and a renderer set should not need that
10
+ build to be up to date before it can compile.
11
+ */
12
+ type ButtonSemanticColor =
13
+ | 'primary'
14
+ | 'secondary'
15
+ | 'alternative'
16
+ | 'success'
17
+ | 'warning'
18
+ | 'error';
19
+ import { Button } from 'antd';
20
+
21
+ export const antdButtonRendererTester = buttonRendererTester as RankedTester;
22
+
23
+ /**
24
+ * Section 14's semantic colors, mapped onto antd's button props.
25
+ *
26
+ * The names are semantic rather than visual on purpose - `error` rather than
27
+ * `red` - so a theme decides what they look like. antd expresses the
28
+ * destructive one as a separate `danger` flag rather than a type, and has no
29
+ * distinct `warning` button, which takes the same treatment.
30
+ */
31
+ const COLORS: Record<ButtonSemanticColor, Record<string, unknown>> = {
32
+ primary: { type: 'primary' },
33
+ secondary: { type: 'default' },
34
+ alternative: { type: 'dashed' },
35
+ success: { type: 'primary' },
36
+ warning: { type: 'default', danger: true },
37
+ error: { type: 'primary', danger: true },
38
+ };
39
+
40
+ export const AntdButtonRenderer = createButtonRenderer({
41
+ ButtonComponent: Button,
42
+ buttonProps: { htmlType: 'button', type: 'primary' },
43
+ getButtonProps: ({ pending, color, uischema }: any) => ({
44
+ // "Pending/loading covers the complete fireActionEvent promise."
45
+ loading: pending,
46
+ block: uischema.options?.fullWidth === true,
47
+ ...(color ? (COLORS[color] ?? {}) : {}),
48
+ }),
49
+ });