@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,313 @@
1
+ import {
2
+ ControlFormItem,
3
+ usePreTouchErrors,
4
+ useClearAffordance,
5
+ useI18n,
6
+ } from '@chobantonov/jsonforms-react-antd-renderers';
7
+ import { ControlProps, RankedTester } from '@jsonforms/core';
8
+ import { withJsonFormsControlProps } from '@jsonforms/react';
9
+ import { Button, ColorPicker, Input, theme as antTheme } from 'antd';
10
+ import type { AggregationColor } from 'antd/es/color-picker/color';
11
+ import type { ColorFormatType } from 'antd/es/color-picker/interface';
12
+ import {
13
+ extendedColorTester,
14
+ resolveExtendedOption,
15
+ useExtendedTranslator,
16
+ } from '@chobantonov/jsonforms-react-extended-renderers';
17
+ import React, { useState } from 'react';
18
+ import {
19
+ DEFAULT_COLOR_SAVE_FORMAT,
20
+ Rgba,
21
+ asColorSaveFormat,
22
+ parseColor,
23
+ pickerFormatFor,
24
+ placeholderKeyFor,
25
+ serializeColor,
26
+ toCssColor,
27
+ } from '../util/colorFormat';
28
+
29
+ /**
30
+ * Selection follows section 18: schema `format: "color"` **or** UI
31
+ * `options.format: "color"` on a plain string. The shared tester carries both;
32
+ * the antd-local one used to test the schema format alone, so a UI-driven
33
+ * color field on an unannotated string silently rendered as a text box.
34
+ */
35
+ export const antdColorControlTester: RankedTester = extendedColorTester;
36
+
37
+ /** antd's color object to the channels {@link serializeColor} works in. */
38
+ const toRgba = (color: AggregationColor): Rgba => {
39
+ const { r, g, b, a } = color.toRgb();
40
+ return { r, g, b, a: typeof a === 'number' ? a : 1 };
41
+ };
42
+
43
+ /**
44
+ * One field rather than three widgets in a row: the swatch is the input's
45
+ * prefix, the color stays editable as text, and the input and picker each
46
+ * provide a clear affordance.
47
+ *
48
+ * Three things the widget layout has to serve, all from section 18 and
49
+ * Adjustment 8:
50
+ *
51
+ * - **Text and picker share one storage contract.** Whatever either produces is
52
+ * written in `colorSaveFormat`, and neither rewrites a value the user has not
53
+ * edited. Typed text is committed as typed and normalized on blur, so
54
+ * `#ff0` does not turn into `rgb(255, 255, 0)` between two keystrokes and
55
+ * move the caret.
56
+ * - **The picker can clear.** A footer action clears from inside the panel,
57
+ * including when text entry is off.
58
+ * - **An unparseable value stays visible.** It is left in the data for the
59
+ * validator to report rather than being replaced by the picker's fallback
60
+ * black.
61
+ */
62
+ export const AntdColorControl = (props: ControlProps) => {
63
+ const { token } = antTheme.useToken();
64
+ const message = useI18n();
65
+ /*
66
+ See `usePreTouchErrors` in the base package: the filtered message, plus the
67
+ touch state it needs. Unchanged unless filtering is switched on.
68
+ */
69
+ const { errors: filteredErrors, onBlur: onBlurTouch } = usePreTouchErrors({
70
+ errors: props.errors,
71
+ path: props.path,
72
+ schema: props.schema,
73
+ uischema: props.uischema as any,
74
+ config: props.config,
75
+ });
76
+
77
+ const t = useExtendedTranslator();
78
+ const value = typeof props.data === 'string' ? props.data : undefined;
79
+ // Set when an edit was refused rather than committed - currently only
80
+ // `hex3` + transparency, which the specification says must not be quietly
81
+ // flattened to an opaque color.
82
+ const [refused, setRefused] = useState(false);
83
+ // Which channel set the panel is showing. Controlled rather than left to
84
+ // antd, so that every opening starts on the format the value is stored in.
85
+ const [panelFormat, setPanelFormat] = useState<ColorFormatType>();
86
+ // hooks run before the visibility guard
87
+ const { allowClear, affordanceProps } = useClearAffordance(Boolean(value));
88
+
89
+ const options = props.uischema.options;
90
+ // `placeholder`, `focus` and `clearable` are the shared control options the
91
+ // specification lists for this renderer; they are upstream conventions, so
92
+ // they stay flat and are read from the merged element/config view rather
93
+ // than from the `jsonformsExtended` namespace.
94
+ const shared = { ...props.config, ...options } as Record<string, unknown>;
95
+ const clearable = shared.clearable !== false;
96
+ const disabled = !props.enabled || Boolean(props.readonly);
97
+ const saveFormat = asColorSaveFormat(
98
+ resolveExtendedOption(
99
+ options,
100
+ props.config,
101
+ 'colorSaveFormat',
102
+ DEFAULT_COLOR_SAVE_FORMAT,
103
+ ),
104
+ );
105
+ const textEntry =
106
+ resolveExtendedOption<boolean>(
107
+ options,
108
+ props.config,
109
+ 'colorTextEntry',
110
+ true,
111
+ ) !== false;
112
+
113
+ if (!props.visible) return null;
114
+
115
+ const commit = (next?: string) => {
116
+ setRefused(false);
117
+ props.handleChange(props.path, next || undefined);
118
+ };
119
+
120
+ /** Serializes an edit, or refuses it when the format cannot carry it. */
121
+ const commitColor = (color: AggregationColor) => {
122
+ if (color.cleared) {
123
+ commit(undefined);
124
+ return;
125
+ }
126
+ const next = serializeColor(toRgba(color), saveFormat);
127
+ if (next === undefined) {
128
+ setRefused(true);
129
+ return;
130
+ }
131
+ commit(next);
132
+ };
133
+
134
+ /**
135
+ * Rewrites a typed color into the configured representation once the user
136
+ * leaves the field. Text that does not parse is left exactly as typed: it is
137
+ * the validator's job to explain it, not this control's job to guess.
138
+ */
139
+ const normalize = () => {
140
+ const parsed = parseColor(value);
141
+ if (!parsed) return;
142
+ const next = serializeColor(parsed, saveFormat);
143
+ if (next === undefined) {
144
+ // A transparent value under `hex3`. Rejected without committing an
145
+ // opaque replacement, per section 18.
146
+ setRefused(true);
147
+ return;
148
+ }
149
+ setRefused(false);
150
+ if (next !== value) {
151
+ props.handleChange(props.path, next);
152
+ }
153
+ };
154
+
155
+ const guidance = refused ? t('color.hex3Transparency') : undefined;
156
+ const cssColor = toCssColor(value);
157
+
158
+ const swatch = (size: number) => (
159
+ <span
160
+ style={{
161
+ display: 'block',
162
+ width: size,
163
+ height: size,
164
+ borderRadius: token.borderRadiusSM,
165
+ border: `1px solid ${token.colorBorder}`,
166
+ background: cssColor ?? 'transparent',
167
+ cursor: props.enabled ? 'pointer' : 'not-allowed',
168
+ }}
169
+ />
170
+ );
171
+
172
+ const savedPanelFormat = pickerFormatFor(saveFormat);
173
+
174
+ const picker = (children: React.ReactNode) => (
175
+ <ColorPicker
176
+ disabled={disabled}
177
+ // Never the stored text: `hsb(...)` is not CSS, and handing it to the
178
+ // picker would parse as black. An unrecognized value opens the panel
179
+ // empty rather than pretending to be a color.
180
+ value={cssColor ?? null}
181
+ /*
182
+ Controlled, and reset on every open, so the panel always starts on the
183
+ channels the value is actually stored in - `rgb` for an rgb-saving
184
+ field, `hsb` for an hsb-saving one. `defaultFormat` only seeds the
185
+ first render, so a field left on another tab reopened on that tab and
186
+ showed numbers in a model it does not store. Switching tabs while the
187
+ panel is open still works; it changes what is being edited, never what
188
+ is written.
189
+ */
190
+ format={panelFormat ?? savedPanelFormat}
191
+ onFormatChange={setPanelFormat}
192
+ onOpenChange={(open) => {
193
+ if (open) setPanelFormat(savedPanelFormat);
194
+ }}
195
+ panelRender={(panel) => (
196
+ <div>
197
+ {panel}
198
+ {clearable && value !== undefined && value !== '' && (
199
+ <Button
200
+ block
201
+ type='text'
202
+ disabled={disabled}
203
+ data-color-panel-clear=''
204
+ onClick={() => commit(undefined)}
205
+ >
206
+ {message('control.clearValue')}
207
+ </Button>
208
+ )}
209
+ </div>
210
+ )}
211
+ onChangeComplete={commitColor}
212
+ >
213
+ {children}
214
+ </ColorPicker>
215
+ );
216
+
217
+ return (
218
+ <ControlFormItem
219
+ adornmentSchema={props.schema}
220
+ adornmentOptions={props.uischema.options as Record<string, unknown>}
221
+ id={props.id}
222
+ label={props.label}
223
+ required={props.required}
224
+ errors={filteredErrors || undefined}
225
+ help={
226
+ filteredErrors ||
227
+ (guidance ? (
228
+ <span role='alert' data-color-guidance>
229
+ {guidance}
230
+ </span>
231
+ ) : (
232
+ props.description
233
+ ))
234
+ }
235
+ >
236
+ {textEntry ? (
237
+ <Input
238
+ allowClear={clearable && allowClear}
239
+ {...affordanceProps}
240
+ onBlur={() => {
241
+ affordanceProps.onBlur();
242
+ onBlurTouch();
243
+ normalize();
244
+ }}
245
+ // lineHeight 0 stops the prefix span from inheriting the text line box
246
+ styles={{
247
+ prefix: { lineHeight: 0, display: 'flex', alignItems: 'center' },
248
+ }}
249
+ disabled={disabled}
250
+ // An authored hint wins; otherwise the hint is the syntax of the
251
+ // configured representation, which section 18 requires it to reflect.
252
+ placeholder={
253
+ (shared.placeholder as string | undefined) ??
254
+ t(placeholderKeyFor(saveFormat))
255
+ }
256
+ autoFocus={shared.focus === true}
257
+ status={filteredErrors ? 'error' : refused ? 'warning' : undefined}
258
+ value={value ?? ''}
259
+ onChange={(event) => commit(event.currentTarget.value)}
260
+ prefix={picker(
261
+ /*
262
+ A custom trigger rather than antd's default one: that trigger
263
+ carries its own border, padding and min-height, which makes it
264
+ taller than the input's text line and sit off-centre in a prefix.
265
+ A plain swatch can be sized to the line box instead.
266
+ */
267
+ <span role='button' aria-label={t('editor.chooseColor')}>
268
+ {swatch(14)}
269
+ </span>,
270
+ )}
271
+ />
272
+ ) : (
273
+ /*
274
+ `colorTextEntry: false`. The value is not typeable, so the picker is
275
+ the whole control - but the trigger is a real button, because
276
+ removing text entry must not remove keyboard access. The stored text
277
+ is shown verbatim beside the swatch rather than through antd's
278
+ `showText`, which would render the picker's interpretation of the
279
+ value and so display `#000000` for anything it failed to parse.
280
+ */
281
+ picker(
282
+ <button
283
+ type='button'
284
+ disabled={disabled}
285
+ aria-label={t('editor.chooseColor')}
286
+ autoFocus={shared.focus === true}
287
+ data-color-trigger
288
+ style={{
289
+ display: 'inline-flex',
290
+ alignItems: 'center',
291
+ gap: token.paddingXS,
292
+ padding: `${token.paddingXXS}px ${token.paddingXS}px`,
293
+ borderRadius: token.borderRadius,
294
+ border: `1px solid ${
295
+ filteredErrors ? token.colorError : token.colorBorder
296
+ }`,
297
+ background: token.colorBgContainer,
298
+ color: token.colorText,
299
+ font: 'inherit',
300
+ cursor: props.enabled ? 'pointer' : 'not-allowed',
301
+ }}
302
+ >
303
+ {swatch(16)}
304
+ <span>{value ?? ''}</span>
305
+ </button>,
306
+ )
307
+ )}
308
+ </ControlFormItem>
309
+ );
310
+ };
311
+
312
+ export const AntdColorControlRenderer =
313
+ withJsonFormsControlProps(AntdColorControl);
@@ -0,0 +1,393 @@
1
+ import { PickerFormItem } from '../components/PickerFormItem';
2
+ import {
3
+ AntdClearableInput,
4
+ usePreTouchErrors,
5
+ } from '@chobantonov/jsonforms-react-antd-renderers';
6
+ import ScheduleOutlined from '@ant-design/icons/ScheduleOutlined';
7
+ import {
8
+ and,
9
+ ControlElement,
10
+ ControlProps,
11
+ formatIs,
12
+ isStringControl,
13
+ optionIs,
14
+ or,
15
+ RankedTester,
16
+ rankWith,
17
+ uiTypeIs,
18
+ } from '@jsonforms/core';
19
+ import { withJsonFormsControlProps } from '@jsonforms/react';
20
+ import {
21
+ Button,
22
+ Flex,
23
+ Input,
24
+ Popover,
25
+ Select,
26
+ Space,
27
+ Typography,
28
+ theme as antTheme,
29
+ } from 'antd';
30
+ import React from 'react';
31
+ import {
32
+ useCronPicker,
33
+ CRON_FIELDS,
34
+ CronField,
35
+ CronPeriod,
36
+ DEFAULT_CRON,
37
+ FIELD_RANGE,
38
+ formatField,
39
+ labelFor,
40
+ parseField,
41
+ } from '@chobantonov/jsonforms-react-extended-renderers';
42
+
43
+ /**
44
+ * Selected the two ways section 5 describes, like every other temporal control.
45
+ *
46
+ * `format: "cron"` in the **schema** is the route that also gives a validator
47
+ * something to check, where the profile defines the keyword; `options.format`
48
+ * in the **UI schema** picks the same renderer for a plain string and leaves
49
+ * validation to `pattern`. Rank 3 is the shared rank for a format-selected
50
+ * control.
51
+ */
52
+ export const antdCronControlTester: RankedTester = rankWith(
53
+ 3,
54
+ and(
55
+ isStringControl,
56
+ or(formatIs('cron'), and(uiTypeIs('Control'), optionIs('format', 'cron'))),
57
+ ),
58
+ );
59
+
60
+ /** Offered coarsest-repeating first, which is how a schedule is described out loud. */
61
+ const periods: CronPeriod[] = [
62
+ 'year',
63
+ 'month',
64
+ 'week',
65
+ 'day',
66
+ 'hour',
67
+ 'minute',
68
+ 'second',
69
+ ];
70
+
71
+ /** The width of the label column, in characters, from the longest label shown. */
72
+ const labelColumn = 15;
73
+
74
+ /**
75
+ * One field's choices, or its text when it has none.
76
+ *
77
+ * A multi-select rather than a syntax: picking Monday and Friday is the natural
78
+ * way to say `MON,FRI`, and the expression underneath is written from the
79
+ * selection rather than typed. An empty selection is **every value** - which is
80
+ * what `*` means and what clearing this field does, so the clear action and the
81
+ * schedule agree.
82
+ *
83
+ * A field whose value is `L`, `W` or `#` has no list to offer, so it is shown
84
+ * as the text it is. That is the whole of the special-syntax support: it is
85
+ * never reinterpreted, never widened into a list that would mean something
86
+ * else, and never taken away from whoever wrote it.
87
+ */
88
+ const FieldPicker = ({
89
+ field,
90
+ text,
91
+ disabled,
92
+ label,
93
+ onChange,
94
+ }: {
95
+ field: CronField;
96
+ text: string;
97
+ disabled: boolean;
98
+ label: (key: any, values?: Record<string, string | number>) => string;
99
+ onChange: (text: string) => void;
100
+ }) => {
101
+ const name = label(`cron.${field}` as any);
102
+ const values = parseField(text, field);
103
+ const [low, high] = FIELD_RANGE[field];
104
+
105
+ const addon = (
106
+ <Space.Addon
107
+ disabled={disabled}
108
+ style={{ width: `${labelColumn}ch`, justifyContent: 'flex-start' }}
109
+ >
110
+ {name}
111
+ </Space.Addon>
112
+ );
113
+
114
+ if (values === undefined) {
115
+ return (
116
+ <AntdClearableInput
117
+ data={text}
118
+ enabled={!disabled}
119
+ onClear={() => onChange('')}
120
+ >
121
+ {(clear) => (
122
+ <Space.Compact block>
123
+ {addon}
124
+ <Input
125
+ style={{ flex: 1, minWidth: 0 }}
126
+ disabled={disabled}
127
+ value={text}
128
+ aria-label={name}
129
+ suffix={clear}
130
+ onChange={(event) => onChange(event.currentTarget.value)}
131
+ />
132
+ </Space.Compact>
133
+ )}
134
+ </AntdClearableInput>
135
+ );
136
+ }
137
+
138
+ /*
139
+ "Every" is the empty selection, so a field standing for all of its values
140
+ shows nothing chosen rather than every chip at once - which for seconds
141
+ would be sixty of them.
142
+ */
143
+ const selected = values.length === high - low + 1 ? [] : values;
144
+
145
+ return (
146
+ <Space.Compact block>
147
+ {addon}
148
+ <Select
149
+ style={{ flex: 1, minWidth: 0 }}
150
+ mode='multiple'
151
+ disabled={disabled}
152
+ value={selected}
153
+ placeholder={label('cron.every')}
154
+ aria-label={name}
155
+ maxTagCount='responsive'
156
+ /*
157
+ antd's own clear rather than the shared button: this is a row of the
158
+ picker and not the control's value, and what it clears to is "every"
159
+ rather than nothing at all.
160
+ */
161
+ allowClear
162
+ options={Array.from({ length: high - low + 1 }, (_, index) => ({
163
+ value: low + index,
164
+ label: labelFor(low + index, field),
165
+ }))}
166
+ onChange={(next: number[]) => onChange(formatField(next, field))}
167
+ />
168
+ </Space.Compact>
169
+ );
170
+ };
171
+
172
+ /**
173
+ * When something runs, as a schedule rather than as six fields of punctuation.
174
+ *
175
+ * Built like the duration control: **one field, not two widgets**. The
176
+ * expression is the value, it stays editable as text, and the picker hangs off
177
+ * an icon inside the input rather than sitting above it. Clearing follows the
178
+ * shared clear-value contract - `AntdClearableInput`, so the button has a
179
+ * localized name, appears on hover or focus, and returns the property to a
180
+ * missing state rather than to an empty string.
181
+ *
182
+ * The picker asks **how often it repeats** first, because that decides which of
183
+ * the six fields are worth showing: a schedule that runs every hour has nothing
184
+ * to say about which day it is, and five dropdowns reading "every" is a form
185
+ * that hides its own answer. Each field it does show is a list to choose from,
186
+ * and an empty one means every value.
187
+ *
188
+ * The period is a **lens, not data**. It selects nothing on its own - a
189
+ * property with no schedule in it opens with no period chosen and no rows - and
190
+ * the one thing changing it writes is the conditions it is about to hide. What
191
+ * does fill a value in is choosing one: see `withTimeDefaults`, because in cron
192
+ * a field left alone means *every* value, so "nine o'clock" with nothing else
193
+ * said is 3600 executions rather than one.
194
+ *
195
+ * Two things it will not do. It **edits only the field that was touched**, so
196
+ * the other five keep the spelling they were written with. And it **does not
197
+ * write at all** unless the schedule actually changed: OK on an untouched
198
+ * picker leaves the value alone, which is the rule the duration control keeps
199
+ * for `P1DT0H` against `P1D`.
200
+ */
201
+ export const AntdCronControl = (props: ControlProps) => {
202
+ const { token } = antTheme.useToken();
203
+ const {
204
+ label,
205
+ expression,
206
+ open,
207
+ setOpen,
208
+ text,
209
+ period,
210
+ options,
211
+ showActions,
212
+ disabled,
213
+ localError,
214
+ draft,
215
+ changeField,
216
+ changeText,
217
+ changePeriod,
218
+ editedProblem,
219
+ shownFields,
220
+ hasCustomField,
221
+ openOn,
222
+ accept,
223
+ } = useCronPicker(props);
224
+ const { errors: filteredErrors, onBlur: onBlurTouch } = usePreTouchErrors({
225
+ errors: props.errors,
226
+ path: props.path,
227
+ schema: props.schema,
228
+ uischema: props.uischema as ControlElement,
229
+ config: props.config,
230
+ });
231
+ if (!props.visible) return null;
232
+
233
+ const picker = (
234
+ <Flex vertical gap='small' style={{ width: 340 }}>
235
+ <Space.Compact block>
236
+ <Space.Addon
237
+ disabled={disabled}
238
+ style={{ width: `${labelColumn}ch`, justifyContent: 'flex-start' }}
239
+ >
240
+ {label('cron.repeats')}
241
+ </Space.Addon>
242
+ <Select
243
+ style={{ flex: 1, minWidth: 0 }}
244
+ disabled={disabled}
245
+ value={period}
246
+ placeholder={label('cron.chooseRepeats')}
247
+ aria-label={label('cron.repeats')}
248
+ options={periods.map((each) => ({
249
+ value: each,
250
+ label: label(`cron.period.${each}` as any),
251
+ }))}
252
+ onChange={(value) => changePeriod(value as CronPeriod)}
253
+ />
254
+ </Space.Compact>
255
+
256
+ {shownFields.map((field) => (
257
+ <FieldPicker
258
+ key={field}
259
+ field={field}
260
+ text={draft[CRON_FIELDS.indexOf(field)] ?? '*'}
261
+ disabled={disabled}
262
+ label={label}
263
+ onChange={(value) => changeField(field, value)}
264
+ />
265
+ ))}
266
+
267
+ {hasCustomField && (
268
+ <Typography.Text
269
+ type='secondary'
270
+ style={{ fontSize: token.fontSizeSM }}
271
+ >
272
+ {label('cron.advanced')}
273
+ </Typography.Text>
274
+ )}
275
+
276
+ {/*
277
+ The expression the picker is building, inside the picker.
278
+
279
+ Somewhere to see what a selection just wrote without closing the panel,
280
+ and the way in for anything the dropdowns cannot say. With `showActions`
281
+ the field below shows what is saved and this shows what is being edited.
282
+ */}
283
+ <AntdClearableInput
284
+ data={text}
285
+ enabled={!disabled}
286
+ onClear={() => changeText('')}
287
+ >
288
+ {(clear) => (
289
+ <Space.Compact block>
290
+ <Space.Addon
291
+ disabled={disabled}
292
+ style={{
293
+ width: `${labelColumn}ch`,
294
+ justifyContent: 'flex-start',
295
+ }}
296
+ >
297
+ {label('cron.expression')}
298
+ </Space.Addon>
299
+ <Input
300
+ style={{ flex: 1, minWidth: 0 }}
301
+ disabled={disabled}
302
+ value={text}
303
+ placeholder={DEFAULT_CRON}
304
+ status={editedProblem ? 'error' : undefined}
305
+ aria-label={label('cron.expression')}
306
+ suffix={clear}
307
+ onChange={(event) => changeText(event.currentTarget.value)}
308
+ />
309
+ </Space.Compact>
310
+ )}
311
+ </AntdClearableInput>
312
+
313
+ {showActions && (
314
+ <Flex justify='end' gap='small'>
315
+ <Button onClick={() => setOpen(false)}>{label('cron.cancel')}</Button>
316
+ <Button
317
+ type='primary'
318
+ disabled={disabled || Boolean(editedProblem)}
319
+ onClick={accept}
320
+ >
321
+ {label('cron.ok')}
322
+ </Button>
323
+ </Flex>
324
+ )}
325
+ </Flex>
326
+ );
327
+
328
+ /**
329
+ * Opened on what the field currently says, and on nothing when it says
330
+ * nothing.
331
+ *
332
+ * So Cancel restores it, and a schedule edited as text is what the picker
333
+ * picks up rather than whatever was left behind last time.
334
+ */
335
+ return (
336
+ <PickerFormItem props={props} error={localError || filteredErrors}>
337
+ {/*
338
+ One field, like the duration and color controls: the expression stays
339
+ editable as text and the picker hangs off an icon inside the input
340
+ rather than sitting beside it as a second widget.
341
+ */}
342
+ <AntdClearableInput
343
+ clearable={options.clearable !== false}
344
+ data={props.data}
345
+ enabled={!disabled}
346
+ onClear={() => props.handleChange(props.path, undefined)}
347
+ >
348
+ {(clear: React.ReactNode) => (
349
+ <Input
350
+ id={props.id}
351
+ disabled={disabled}
352
+ value={expression}
353
+ placeholder={options.placeholder ?? DEFAULT_CRON}
354
+ autoFocus={options.focus}
355
+ status={localError || filteredErrors ? 'error' : undefined}
356
+ onChange={(event) =>
357
+ props.handleChange(
358
+ props.path,
359
+ event.currentTarget.value || undefined,
360
+ )
361
+ }
362
+ onBlur={onBlurTouch}
363
+ styles={{
364
+ prefix: { lineHeight: 0, display: 'flex', alignItems: 'center' },
365
+ }}
366
+ suffix={clear}
367
+ prefix={
368
+ <Popover
369
+ content={picker}
370
+ open={open}
371
+ placement='bottomLeft'
372
+ trigger='click'
373
+ onOpenChange={openOn}
374
+ >
375
+ <ScheduleOutlined
376
+ role='button'
377
+ aria-label={label('cron.choose')}
378
+ style={{
379
+ cursor: disabled ? 'not-allowed' : 'pointer',
380
+ color: token.colorTextTertiary,
381
+ }}
382
+ />
383
+ </Popover>
384
+ }
385
+ />
386
+ )}
387
+ </AntdClearableInput>
388
+ </PickerFormItem>
389
+ );
390
+ };
391
+
392
+ export const AntdCronControlRenderer =
393
+ withJsonFormsControlProps(AntdCronControl);