@chobantonov/jsonforms-react-antd-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 +22 -0
- package/README.md +103 -2
- package/lib/additional/LabelRenderer.d.ts +13 -0
- package/lib/additional/ListWithDetailMasterItem.d.ts +9 -0
- package/lib/additional/ListWithDetailRenderer.d.ts +8 -0
- package/lib/additional/index.d.ts +4 -0
- package/lib/additional/unwrapped.d.ts +6 -0
- package/lib/antd-controls/AntdCheckbox.d.ts +10 -0
- package/lib/antd-controls/AntdClearValueButton.d.ts +44 -0
- package/lib/antd-controls/AntdClearableInput.d.ts +19 -0
- package/lib/antd-controls/AntdDatePicker.d.ts +7 -0
- package/lib/antd-controls/AntdDateTimePicker.d.ts +7 -0
- package/lib/antd-controls/AntdFile.d.ts +7 -0
- package/lib/antd-controls/AntdInputInteger.d.ts +3 -0
- package/lib/antd-controls/AntdInputNumber.d.ts +3 -0
- package/lib/antd-controls/AntdInputNumberFormat.d.ts +6 -0
- package/lib/antd-controls/AntdInputText.d.ts +6 -0
- package/lib/antd-controls/AntdNumericInput.d.ts +9 -0
- package/lib/antd-controls/AntdOtp.d.ts +33 -0
- package/lib/antd-controls/AntdPassword.d.ts +6 -0
- package/lib/antd-controls/AntdRadioGroup.d.ts +6 -0
- package/lib/antd-controls/AntdRevealButton.d.ts +32 -0
- package/lib/antd-controls/AntdSelect.d.ts +7 -0
- package/lib/antd-controls/AntdSlider.d.ts +21 -0
- package/lib/antd-controls/AntdTimePicker.d.ts +6 -0
- package/lib/antd-controls/AntdToggle.d.ts +6 -0
- package/lib/antd-controls/FileFeedback.d.ts +6 -0
- package/lib/antd-controls/index.d.ts +18 -0
- package/lib/antd-controls/useTemporalPicker.d.ts +49 -0
- package/lib/cells/AntdCompositeCell.d.ts +8 -0
- package/lib/cells/BooleanCell.d.ts +6 -0
- package/lib/cells/BooleanToggleCell.d.ts +5 -0
- package/lib/cells/CompositeDetailDialog.d.ts +15 -0
- package/lib/cells/CustomizableCells.d.ts +9 -0
- package/lib/cells/DateCell.d.ts +6 -0
- package/lib/cells/EnumCell.d.ts +11 -0
- package/lib/cells/IntegerCell.d.ts +6 -0
- package/lib/cells/NumberCell.d.ts +10 -0
- package/lib/cells/NumberFormatCell.d.ts +10 -0
- package/lib/cells/OneOfEnumCell.d.ts +11 -0
- package/lib/cells/PasswordCell.d.ts +5 -0
- package/lib/cells/TextCell.d.ts +10 -0
- package/lib/cells/TimeCell.d.ts +6 -0
- package/lib/cells/index.d.ts +14 -0
- package/lib/complex/AdditionalProperties.d.ts +4 -0
- package/lib/complex/AnyOfRenderer.d.ts +31 -0
- package/lib/complex/ArrayControlRenderer.d.ts +8 -0
- package/lib/complex/ChipsControl.d.ts +22 -0
- package/lib/complex/CollectionPager.d.ts +5 -0
- package/lib/complex/DataCell.d.ts +16 -0
- package/lib/complex/DeleteDialog.d.ts +14 -0
- package/lib/complex/DetailModal.d.ts +6 -0
- package/lib/complex/EnumArrayRenderer.d.ts +6 -0
- package/lib/complex/ErrorFeedback.d.ts +6 -0
- package/lib/complex/MixedRenderer.d.ts +6 -0
- package/lib/complex/MultiSelectControl.d.ts +17 -0
- package/lib/complex/ObjectRenderer.d.ts +5 -0
- package/lib/complex/OneOfRenderer.d.ts +6 -0
- package/lib/complex/OneOfTabRenderer.d.ts +5 -0
- package/lib/complex/RecursiveTreeRenderer.d.ts +4 -0
- package/lib/complex/RowDetailFrame.d.ts +10 -0
- package/lib/complex/ScalarCompositionRenderer.d.ts +4 -0
- package/lib/complex/TabSwitchConfirmDialog.d.ts +9 -0
- package/lib/complex/TableControl.d.ts +9 -0
- package/lib/complex/TableToolbar.d.ts +21 -0
- package/lib/complex/TupleAdditionalItems.d.ts +13 -0
- package/lib/complex/TupleControlRenderer.d.ts +6 -0
- package/lib/complex/TupleField.d.ts +4 -0
- package/lib/complex/ValidationIcon.d.ts +8 -0
- package/lib/complex/additionalProperties/AntdAdditionalPropertyActions.d.ts +9 -0
- package/lib/complex/additionalProperties/AntdAdditionalPropertyRenameDialog.d.ts +11 -0
- package/lib/complex/index.d.ts +20 -0
- package/lib/complex/mixed/AntdJsonTypeIcon.d.ts +4 -0
- package/lib/complex/mixed/AntdMixedNavigationContext.d.ts +5 -0
- package/lib/complex/mixed/AntdMixedSplitPane.d.ts +5 -0
- package/lib/complex/mixed/AntdMixedTree.d.ts +15 -0
- package/lib/complex/mixed/AntdMixedTypeSelector.d.ts +12 -0
- package/lib/complex/mixed/AntdNestedMixedNavigation.d.ts +7 -0
- package/lib/complex/mixed/mixedTree.d.ts +2 -0
- package/lib/complex/unwrapped.d.ts +10 -0
- package/lib/controls/AnyOfStringOrEnumControl.d.ts +9 -0
- package/lib/controls/BooleanControl.d.ts +6 -0
- package/lib/controls/BooleanToggleControl.d.ts +6 -0
- package/lib/controls/ChoiceCards.d.ts +1 -0
- package/lib/controls/DateControl.d.ts +6 -0
- package/lib/controls/DateTimeControl.d.ts +6 -0
- package/lib/controls/EnumControl.d.ts +7 -0
- package/lib/controls/FileControl.d.ts +7 -0
- package/lib/controls/InputControl.d.ts +6 -0
- package/lib/controls/IntegerControl.d.ts +6 -0
- package/lib/controls/NativeControl.d.ts +6 -0
- package/lib/controls/NumberControl.d.ts +6 -0
- package/lib/controls/OneOfEnumControl.d.ts +7 -0
- package/lib/controls/OneOfRadioGroupControl.d.ts +6 -0
- package/lib/controls/PasswordControl.d.ts +18 -0
- package/lib/controls/PasswordOtpControl.d.ts +38 -0
- package/lib/controls/RadioGroup.d.ts +3 -0
- package/lib/controls/RadioGroupControl.d.ts +6 -0
- package/lib/controls/SliderControl.d.ts +6 -0
- package/lib/controls/TextControl.d.ts +6 -0
- package/lib/controls/TimeControl.d.ts +6 -0
- package/lib/controls/index.d.ts +20 -0
- package/lib/controls/unwrapped.d.ts +19 -0
- package/lib/index.d.ts +50 -0
- package/lib/jsonforms-react-antd.cjs.js +39 -0
- package/lib/jsonforms-react-antd.cjs.js.map +1 -0
- package/lib/jsonforms-react-antd.esm.js +4235 -0
- package/lib/jsonforms-react-antd.esm.js.map +1 -0
- package/lib/layouts/ArrayLayout.d.ts +5 -0
- package/lib/layouts/ArrayLayoutRenderer.d.ts +8 -0
- package/lib/layouts/ArrayPanel.d.ts +7 -0
- package/lib/layouts/ArrayToolbar.d.ts +17 -0
- package/lib/layouts/CategorizationAccordionLayout.d.ts +21 -0
- package/lib/layouts/CategorizationLayout.d.ts +14 -0
- package/lib/layouts/CategorizationStepperLayout.d.ts +10 -0
- package/lib/layouts/CategoryHeader.d.ts +39 -0
- package/lib/layouts/ContainerIndicator.d.ts +37 -0
- package/lib/layouts/GroupLayout.d.ts +6 -0
- package/lib/layouts/HorizontalLayout.d.ts +10 -0
- package/lib/layouts/ValidationIndicator.d.ts +13 -0
- package/lib/layouts/VerticalLayout.d.ts +10 -0
- package/lib/layouts/arrayTitle.d.ts +2 -0
- package/lib/layouts/index.d.ts +11 -0
- package/lib/layouts/unwrapped.d.ts +11 -0
- package/lib/locale/index.d.ts +1 -0
- package/lib/util/additionalPropertyName.d.ts +2 -0
- package/lib/util/arrayChoices.d.ts +2 -0
- package/lib/util/categoryState.d.ts +3 -0
- package/lib/util/cellFrame.d.ts +27 -0
- package/lib/util/cellMode.d.ts +29 -0
- package/lib/util/clearAffordance.d.ts +1 -0
- package/lib/util/combinators.d.ts +1 -0
- package/lib/util/compositeActions.d.ts +1 -0
- package/lib/util/compositeSummary.d.ts +1 -0
- package/lib/util/configNamespaces.d.ts +1 -0
- package/lib/util/confirmation.d.ts +2 -0
- package/lib/util/datejs.d.ts +4 -0
- package/lib/util/debounce.d.ts +1 -0
- package/lib/util/dynamicProperties.d.ts +1 -0
- package/lib/util/focus.d.ts +1 -0
- package/lib/util/groupState.d.ts +1 -0
- package/lib/util/index.d.ts +25 -0
- package/lib/util/layout.d.ts +18 -0
- package/lib/util/layoutSizing.d.ts +6 -0
- package/lib/util/literalPropertySchema.d.ts +1 -0
- package/lib/util/locale.d.ts +68 -0
- package/lib/util/numeric.d.ts +1 -0
- package/lib/util/pendingChanges.d.ts +2 -0
- package/lib/util/preTouchErrors.d.ts +2 -0
- package/lib/util/rendererLocale.d.ts +2 -0
- package/lib/util/temporalBounds.d.ts +35 -0
- package/lib/util/temporalFormats.d.ts +26 -0
- package/lib/util/theme.d.ts +9 -0
- package/lib/util/translate.d.ts +1 -0
- package/lib/util/tuple.d.ts +2 -0
- package/lib/util/useConfirmation.d.ts +7 -0
- package/lib/util/validationIndicator.d.ts +2 -0
- package/lib/util/visuallyHidden.d.ts +1 -0
- package/package.json +89 -3
- package/src/additional/LabelRenderer.tsx +21 -0
- package/src/additional/ListWithDetailMasterItem.tsx +124 -0
- package/src/additional/ListWithDetailRenderer.tsx +243 -0
- package/src/additional/index.ts +14 -0
- package/src/additional/unwrapped.ts +8 -0
- package/src/antd-controls/AntdCheckbox.tsx +56 -0
- package/src/antd-controls/AntdClearValueButton.tsx +96 -0
- package/src/antd-controls/AntdClearableInput.tsx +63 -0
- package/src/antd-controls/AntdDatePicker.tsx +26 -0
- package/src/antd-controls/AntdDateTimePicker.tsx +31 -0
- package/src/antd-controls/AntdFile.tsx +395 -0
- package/src/antd-controls/AntdInputInteger.tsx +10 -0
- package/src/antd-controls/AntdInputNumber.tsx +10 -0
- package/src/antd-controls/AntdInputNumberFormat.tsx +63 -0
- package/src/antd-controls/AntdInputText.tsx +124 -0
- package/src/antd-controls/AntdNumericInput.tsx +83 -0
- package/src/antd-controls/AntdOtp.tsx +132 -0
- package/src/antd-controls/AntdPassword.tsx +106 -0
- package/src/antd-controls/AntdRadioGroup.tsx +60 -0
- package/src/antd-controls/AntdRevealButton.tsx +74 -0
- package/src/antd-controls/AntdSelect.tsx +113 -0
- package/src/antd-controls/AntdSlider.tsx +114 -0
- package/src/antd-controls/AntdTimePicker.tsx +25 -0
- package/src/antd-controls/AntdToggle.tsx +70 -0
- package/src/antd-controls/FileFeedback.tsx +37 -0
- package/src/antd-controls/index.ts +18 -0
- package/src/antd-controls/useTemporalPicker.ts +130 -0
- package/src/cells/AntdCompositeCell.tsx +228 -0
- package/src/cells/BooleanCell.tsx +33 -0
- package/src/cells/BooleanToggleCell.tsx +38 -0
- package/src/cells/CompositeDetailDialog.tsx +100 -0
- package/src/cells/CustomizableCells.ts +9 -0
- package/src/cells/DateCell.tsx +17 -0
- package/src/cells/EnumCell.tsx +30 -0
- package/src/cells/IntegerCell.tsx +17 -0
- package/src/cells/NumberCell.tsx +20 -0
- package/src/cells/NumberFormatCell.tsx +37 -0
- package/src/cells/OneOfEnumCell.tsx +32 -0
- package/src/cells/PasswordCell.tsx +22 -0
- package/src/cells/TextCell.tsx +22 -0
- package/src/cells/TimeCell.tsx +17 -0
- package/src/cells/index.ts +40 -0
- package/src/complex/AdditionalProperties.tsx +422 -0
- package/src/complex/AnyOfRenderer.tsx +158 -0
- package/src/complex/ArrayControlRenderer.tsx +121 -0
- package/src/complex/ChipsControl.tsx +205 -0
- package/src/complex/CollectionPager.tsx +26 -0
- package/src/complex/DataCell.tsx +82 -0
- package/src/complex/DeleteDialog.tsx +44 -0
- package/src/complex/DetailModal.tsx +110 -0
- package/src/complex/EnumArrayRenderer.tsx +148 -0
- package/src/complex/ErrorFeedback.tsx +51 -0
- package/src/complex/MixedRenderer.tsx +325 -0
- package/src/complex/MultiSelectControl.tsx +205 -0
- package/src/complex/ObjectRenderer.tsx +55 -0
- package/src/complex/OneOfRenderer.tsx +299 -0
- package/src/complex/OneOfTabRenderer.tsx +123 -0
- package/src/complex/RecursiveTreeRenderer.tsx +20 -0
- package/src/complex/RowDetailFrame.tsx +99 -0
- package/src/complex/ScalarCompositionRenderer.tsx +14 -0
- package/src/complex/TabSwitchConfirmDialog.tsx +36 -0
- package/src/complex/TableControl.tsx +646 -0
- package/src/complex/TableToolbar.tsx +80 -0
- package/src/complex/TupleAdditionalItems.tsx +100 -0
- package/src/complex/TupleControlRenderer.tsx +78 -0
- package/src/complex/TupleField.tsx +44 -0
- package/src/complex/ValidationIcon.tsx +30 -0
- package/src/complex/additionalProperties/AntdAdditionalPropertyActions.tsx +56 -0
- package/src/complex/additionalProperties/AntdAdditionalPropertyRenameDialog.tsx +56 -0
- package/src/complex/index.ts +48 -0
- package/src/complex/mixed/AntdJsonTypeIcon.tsx +40 -0
- package/src/complex/mixed/AntdMixedNavigationContext.ts +8 -0
- package/src/complex/mixed/AntdMixedSplitPane.tsx +51 -0
- package/src/complex/mixed/AntdMixedTree.tsx +287 -0
- package/src/complex/mixed/AntdMixedTypeSelector.tsx +60 -0
- package/src/complex/mixed/AntdNestedMixedNavigation.tsx +39 -0
- package/src/complex/mixed/mixedTree.ts +9 -0
- package/src/complex/unwrapped.ts +15 -0
- package/src/controls/AnyOfStringOrEnumControl.tsx +123 -0
- package/src/controls/BooleanControl.tsx +17 -0
- package/src/controls/BooleanToggleControl.tsx +24 -0
- package/src/controls/ChoiceCards.tsx +13 -0
- package/src/controls/DateControl.tsx +19 -0
- package/src/controls/DateTimeControl.tsx +22 -0
- package/src/controls/EnumControl.tsx +29 -0
- package/src/controls/FileControl.tsx +44 -0
- package/src/controls/InputControl.tsx +94 -0
- package/src/controls/IntegerControl.tsx +16 -0
- package/src/controls/NativeControl.tsx +79 -0
- package/src/controls/NumberControl.tsx +18 -0
- package/src/controls/OneOfEnumControl.tsx +32 -0
- package/src/controls/OneOfRadioGroupControl.tsx +25 -0
- package/src/controls/PasswordControl.tsx +43 -0
- package/src/controls/PasswordOtpControl.tsx +61 -0
- package/src/controls/RadioGroup.tsx +8 -0
- package/src/controls/RadioGroupControl.tsx +21 -0
- package/src/controls/SliderControl.tsx +19 -0
- package/src/controls/TextControl.tsx +17 -0
- package/src/controls/TimeControl.tsx +20 -0
- package/src/controls/index.ts +69 -0
- package/src/controls/unwrapped.ts +35 -0
- package/src/index.ts +267 -0
- package/src/layouts/ArrayLayout.tsx +435 -0
- package/src/layouts/ArrayLayoutRenderer.tsx +54 -0
- package/src/layouts/ArrayPanel.tsx +51 -0
- package/src/layouts/ArrayToolbar.tsx +67 -0
- package/src/layouts/CategorizationAccordionLayout.tsx +217 -0
- package/src/layouts/CategorizationLayout.tsx +149 -0
- package/src/layouts/CategorizationStepperLayout.tsx +164 -0
- package/src/layouts/CategoryHeader.tsx +107 -0
- package/src/layouts/ContainerIndicator.tsx +83 -0
- package/src/layouts/GroupLayout.tsx +307 -0
- package/src/layouts/HorizontalLayout.tsx +50 -0
- package/src/layouts/ValidationIndicator.tsx +43 -0
- package/src/layouts/VerticalLayout.tsx +50 -0
- package/src/layouts/arrayTitle.tsx +30 -0
- package/src/layouts/index.ts +35 -0
- package/src/layouts/unwrapped.ts +17 -0
- package/src/locale/index.ts +1 -0
- package/src/util/additionalPropertyName.ts +11 -0
- package/src/util/arrayChoices.ts +21 -0
- package/src/util/categoryState.ts +17 -0
- package/src/util/cellFrame.tsx +52 -0
- package/src/util/cellMode.tsx +145 -0
- package/src/util/clearAffordance.ts +2 -0
- package/src/util/combinators.ts +6 -0
- package/src/util/compositeActions.ts +2 -0
- package/src/util/compositeSummary.ts +2 -0
- package/src/util/configNamespaces.ts +4 -0
- package/src/util/confirmation.ts +15 -0
- package/src/util/datejs.tsx +42 -0
- package/src/util/debounce.ts +2 -0
- package/src/util/dynamicProperties.ts +6 -0
- package/src/util/focus.ts +2 -0
- package/src/util/groupState.ts +8 -0
- package/src/util/index.ts +25 -0
- package/src/util/layout.tsx +121 -0
- package/src/util/layoutSizing.ts +33 -0
- package/src/util/literalPropertySchema.ts +2 -0
- package/src/util/locale.ts +222 -0
- package/src/util/numeric.ts +2 -0
- package/src/util/pendingChanges.tsx +6 -0
- package/src/util/preTouchErrors.ts +10 -0
- package/src/util/rendererLocale.ts +10 -0
- package/src/util/temporalBounds.ts +106 -0
- package/src/util/temporalFormats.ts +95 -0
- package/src/util/theme.ts +9 -0
- package/src/util/translate.ts +6 -0
- package/src/util/tuple.ts +16 -0
- package/src/util/uiSchemaCycle.tsx +2 -0
- package/src/util/useConfirmation.tsx +25 -0
- package/src/util/validationIndicator.ts +10 -0
- package/src/util/visuallyHidden.ts +2 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Flex, Input, Select, Tag, theme as antTheme } from 'antd';
|
|
3
|
+
import {
|
|
4
|
+
ControlProps,
|
|
5
|
+
RankedTester,
|
|
6
|
+
rankWith,
|
|
7
|
+
and,
|
|
8
|
+
uiTypeIs,
|
|
9
|
+
} from '@jsonforms/core';
|
|
10
|
+
import { withJsonFormsControlProps } from '@jsonforms/react';
|
|
11
|
+
import { ControlFormItem } from '../util/cellMode';
|
|
12
|
+
import { usePreTouchErrors } from '../util/preTouchErrors';
|
|
13
|
+
import { useI18n } from '../util/translate';
|
|
14
|
+
import {
|
|
15
|
+
addChoice,
|
|
16
|
+
arrayChoicesOf,
|
|
17
|
+
asArrayValue,
|
|
18
|
+
canAddChoice,
|
|
19
|
+
canRemoveChoice,
|
|
20
|
+
isChipsControl,
|
|
21
|
+
isSelected,
|
|
22
|
+
removeChoiceAt,
|
|
23
|
+
resolveItemSchema,
|
|
24
|
+
} from '../util/arrayChoices';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `variant: "chips"` — an array of strings as removable tokens.
|
|
28
|
+
*
|
|
29
|
+
* **The tokens are drawn here rather than by antd's `Select` in tags mode**,
|
|
30
|
+
* and the reason is duplicates. `uniqueItems` is optional for chips, so
|
|
31
|
+
* `["a", "a"]` is legal data the specification expects to survive: "otherwise
|
|
32
|
+
* free-entry chips may retain repeated strings", and "remove the selected
|
|
33
|
+
* occurrence when duplicates exist". A `Select` keys its tags by value, so two
|
|
34
|
+
* equal tokens are one entry to it and closing either removes both. Tags of our
|
|
35
|
+
* own are identified by **position**, which is what makes removing the intended
|
|
36
|
+
* occurrence possible at all.
|
|
37
|
+
*
|
|
38
|
+
* What is free here is entry, not validation: item constraints still apply to
|
|
39
|
+
* every stored value, and a schema that narrows the items to a finite list
|
|
40
|
+
* turns the adder into a chooser.
|
|
41
|
+
*/
|
|
42
|
+
export const chipsControlTester: RankedTester = rankWith(
|
|
43
|
+
6,
|
|
44
|
+
and(uiTypeIs('Control'), isChipsControl),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
export const ChipsControl = (props: ControlProps) => {
|
|
48
|
+
const t = useI18n();
|
|
49
|
+
const { token } = antTheme.useToken();
|
|
50
|
+
const [draft, setDraft] = useState('');
|
|
51
|
+
const {
|
|
52
|
+
data,
|
|
53
|
+
enabled,
|
|
54
|
+
id,
|
|
55
|
+
label,
|
|
56
|
+
path,
|
|
57
|
+
required,
|
|
58
|
+
rootSchema,
|
|
59
|
+
schema,
|
|
60
|
+
uischema,
|
|
61
|
+
visible,
|
|
62
|
+
} = props;
|
|
63
|
+
// See `usePreTouchErrors`; unchanged unless filtering is on.
|
|
64
|
+
const { errors, onFocus, onBlur } = usePreTouchErrors({
|
|
65
|
+
errors: props.errors,
|
|
66
|
+
path: props.path,
|
|
67
|
+
schema: props.schema,
|
|
68
|
+
uischema: props.uischema as any,
|
|
69
|
+
config: props.config,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const options = {
|
|
73
|
+
...props.config,
|
|
74
|
+
...uischema.options,
|
|
75
|
+
} as Record<string, any>;
|
|
76
|
+
const values = asArrayValue(data);
|
|
77
|
+
const itemSchema = resolveItemSchema(schema, rootSchema);
|
|
78
|
+
const choices = arrayChoicesOf(itemSchema);
|
|
79
|
+
const unique = schema.uniqueItems === true;
|
|
80
|
+
const limits = {
|
|
81
|
+
minItems: schema.minItems,
|
|
82
|
+
maxItems: schema.maxItems,
|
|
83
|
+
restrict: options.restrict !== false,
|
|
84
|
+
};
|
|
85
|
+
const addable = enabled !== false && canAddChoice(values, limits);
|
|
86
|
+
const removable = enabled !== false && canRemoveChoice(values, limits);
|
|
87
|
+
|
|
88
|
+
if (!visible) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const commit = (next: unknown[]) => props.handleChange(path, next);
|
|
93
|
+
|
|
94
|
+
const add = (value: string) => {
|
|
95
|
+
if (!addable || value === '') {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
// `unique` refuses rather than collapses, so a `uniqueItems` array cannot
|
|
99
|
+
// be pushed into an invalid state from here.
|
|
100
|
+
const next = addChoice(values, value, unique);
|
|
101
|
+
if (next !== values) {
|
|
102
|
+
commit(next);
|
|
103
|
+
}
|
|
104
|
+
setDraft('');
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/** The label to show for a stored value, which may not be a known choice. */
|
|
108
|
+
const labelFor = (value: unknown): string => {
|
|
109
|
+
const choice = choices?.find((entry) => entry.value === value);
|
|
110
|
+
return choice ? choice.label : String(value);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const remaining = choices?.filter(
|
|
114
|
+
(choice) => !unique || !isSelected(values, choice.value),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<ControlFormItem
|
|
119
|
+
hideRequiredAsterisk={uischema.options?.hideRequiredAsterisk}
|
|
120
|
+
id={id}
|
|
121
|
+
label={label}
|
|
122
|
+
required={required}
|
|
123
|
+
errors={errors || undefined}
|
|
124
|
+
help={errors || props.description}
|
|
125
|
+
>
|
|
126
|
+
<Flex data-chips vertical gap={token.paddingXS}>
|
|
127
|
+
{values.length > 0 && (
|
|
128
|
+
<Flex wrap gap={token.paddingXXS}>
|
|
129
|
+
{values.map((value, index) => (
|
|
130
|
+
/*
|
|
131
|
+
Keyed and closed by **position**, never by value. Two equal
|
|
132
|
+
tokens are two tokens, and closing the second must not take the
|
|
133
|
+
first with it.
|
|
134
|
+
*/
|
|
135
|
+
<Tag
|
|
136
|
+
key={`${index}-${String(value)}`}
|
|
137
|
+
closable={removable}
|
|
138
|
+
data-chip={index}
|
|
139
|
+
onClose={(event) => {
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
if (removable) {
|
|
142
|
+
commit(removeChoiceAt(values, index));
|
|
143
|
+
}
|
|
144
|
+
}}
|
|
145
|
+
>
|
|
146
|
+
{labelFor(value)}
|
|
147
|
+
</Tag>
|
|
148
|
+
))}
|
|
149
|
+
</Flex>
|
|
150
|
+
)}
|
|
151
|
+
{choices ? (
|
|
152
|
+
/*
|
|
153
|
+
A finite item schema turns entry into selection: the specification
|
|
154
|
+
says "the schema determines whether entry is free or choice-limited;
|
|
155
|
+
no separate free-entry option is introduced".
|
|
156
|
+
*/
|
|
157
|
+
<Select
|
|
158
|
+
data-chips-select
|
|
159
|
+
disabled={!addable}
|
|
160
|
+
autoFocus={options.focus === true}
|
|
161
|
+
style={{ width: '100%' }}
|
|
162
|
+
placeholder={options.placeholder}
|
|
163
|
+
// Controlled as empty: the chosen value goes into the tag list
|
|
164
|
+
// above, not into the selector.
|
|
165
|
+
value={null}
|
|
166
|
+
showSearch={{
|
|
167
|
+
optionFilterProp: 'label',
|
|
168
|
+
filterOption: (input, option) =>
|
|
169
|
+
String(option?.label ?? '')
|
|
170
|
+
.toLowerCase()
|
|
171
|
+
.includes(input.toLowerCase()),
|
|
172
|
+
}}
|
|
173
|
+
notFoundContent={t('enum.noMatches')}
|
|
174
|
+
onChange={(value: string) => add(value)}
|
|
175
|
+
options={(remaining ?? []).map((choice) => ({
|
|
176
|
+
value: choice.value as string,
|
|
177
|
+
label: choice.label,
|
|
178
|
+
}))}
|
|
179
|
+
/>
|
|
180
|
+
) : (
|
|
181
|
+
<Input
|
|
182
|
+
data-chips-input
|
|
183
|
+
disabled={!addable}
|
|
184
|
+
autoFocus={options.focus === true}
|
|
185
|
+
placeholder={options.placeholder ?? t('chips.addPlaceholder')}
|
|
186
|
+
value={draft}
|
|
187
|
+
/*
|
|
188
|
+
A partial token "remains a local draft until explicitly
|
|
189
|
+
committed", so nothing is written while typing - only on Enter.
|
|
190
|
+
*/
|
|
191
|
+
onChange={(event) => setDraft(event.currentTarget.value)}
|
|
192
|
+
onPressEnter={() => add(draft)}
|
|
193
|
+
onFocus={onFocus}
|
|
194
|
+
onBlur={() => {
|
|
195
|
+
setDraft('');
|
|
196
|
+
onBlur();
|
|
197
|
+
}}
|
|
198
|
+
/>
|
|
199
|
+
)}
|
|
200
|
+
</Flex>
|
|
201
|
+
</ControlFormItem>
|
|
202
|
+
);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export default withJsonFormsControlProps(ChipsControl);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Pagination, theme } from 'antd';
|
|
3
|
+
import { CollectionPage } from '@chobantonov/jsonforms-react-renderer-common/collections/collectionPagination';
|
|
4
|
+
export const CollectionPager = ({ page }: { page: CollectionPage }) => {
|
|
5
|
+
const { token } = theme.useToken();
|
|
6
|
+
return !page.enabled || page.total === 0 ? null : (
|
|
7
|
+
<div
|
|
8
|
+
data-collection-footer
|
|
9
|
+
style={{
|
|
10
|
+
display: 'flex',
|
|
11
|
+
justifyContent: 'flex-end',
|
|
12
|
+
paddingBlock: 12,
|
|
13
|
+
borderTop: `1px solid ${token.colorBorderSecondary}`,
|
|
14
|
+
}}
|
|
15
|
+
>
|
|
16
|
+
<Pagination
|
|
17
|
+
current={page.current}
|
|
18
|
+
pageSize={page.size}
|
|
19
|
+
total={page.total}
|
|
20
|
+
pageSizeOptions={page.choices}
|
|
21
|
+
showSizeChanger
|
|
22
|
+
onChange={page.change}
|
|
23
|
+
/>
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ControlElement,
|
|
3
|
+
encode,
|
|
4
|
+
JsonFormsCellRendererRegistryEntry,
|
|
5
|
+
JsonFormsRendererRegistryEntry,
|
|
6
|
+
JsonSchema,
|
|
7
|
+
Resolve,
|
|
8
|
+
} from '@jsonforms/core';
|
|
9
|
+
import { DispatchCell } from '@jsonforms/react';
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import { CellFrame } from '../util/cellFrame';
|
|
12
|
+
|
|
13
|
+
export interface DataCellProps {
|
|
14
|
+
path: string;
|
|
15
|
+
propName?: string;
|
|
16
|
+
schema: JsonSchema;
|
|
17
|
+
rootSchema: JsonSchema;
|
|
18
|
+
errors: string;
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
renderers?: JsonFormsRendererRegistryEntry[];
|
|
21
|
+
cells?: JsonFormsCellRendererRegistryEntry[];
|
|
22
|
+
/** Per-column options from the array uischema's `cells` entry. */
|
|
23
|
+
cellOptions?: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const controlWithoutLabel = (
|
|
27
|
+
scope: string,
|
|
28
|
+
options?: Record<string, unknown>,
|
|
29
|
+
): ControlElement => ({
|
|
30
|
+
type: 'Control',
|
|
31
|
+
scope: scope,
|
|
32
|
+
label: false,
|
|
33
|
+
// `cells: { <prop>: { summary, detail } }` from the array's uischema reaches
|
|
34
|
+
// the cell here, which is how composite columns know how to summarise
|
|
35
|
+
// themselves and what to show in their detail dialog.
|
|
36
|
+
options,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const DataCell = ({
|
|
40
|
+
path,
|
|
41
|
+
propName,
|
|
42
|
+
schema,
|
|
43
|
+
rootSchema,
|
|
44
|
+
errors,
|
|
45
|
+
enabled,
|
|
46
|
+
renderers,
|
|
47
|
+
cells,
|
|
48
|
+
cellOptions,
|
|
49
|
+
}: DataCellProps) => {
|
|
50
|
+
return (
|
|
51
|
+
<CellFrame errors={errors} path={path}>
|
|
52
|
+
{schema.properties && propName !== undefined ? (
|
|
53
|
+
<DispatchCell
|
|
54
|
+
schema={Resolve.schema(
|
|
55
|
+
schema,
|
|
56
|
+
`#/properties/${encode(propName)}`,
|
|
57
|
+
rootSchema,
|
|
58
|
+
)}
|
|
59
|
+
uischema={controlWithoutLabel(
|
|
60
|
+
`#/properties/${encode(propName)}`,
|
|
61
|
+
cellOptions,
|
|
62
|
+
)}
|
|
63
|
+
path={path}
|
|
64
|
+
enabled={enabled}
|
|
65
|
+
renderers={renderers}
|
|
66
|
+
cells={cells}
|
|
67
|
+
/>
|
|
68
|
+
) : (
|
|
69
|
+
<DispatchCell
|
|
70
|
+
schema={schema}
|
|
71
|
+
uischema={controlWithoutLabel('#', cellOptions)}
|
|
72
|
+
path={path}
|
|
73
|
+
enabled={enabled}
|
|
74
|
+
renderers={renderers}
|
|
75
|
+
cells={cells}
|
|
76
|
+
/>
|
|
77
|
+
)}
|
|
78
|
+
</CellFrame>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default DataCell;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Modal } from 'antd';
|
|
3
|
+
import { useI18n } from '../util/translate';
|
|
4
|
+
|
|
5
|
+
export interface DeleteDialogProps {
|
|
6
|
+
open: boolean;
|
|
7
|
+
onConfirm(): void;
|
|
8
|
+
onCancel(): void;
|
|
9
|
+
title?: string;
|
|
10
|
+
message?: string;
|
|
11
|
+
acceptText?: string;
|
|
12
|
+
declineText?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface WithDeleteDialogSupport {
|
|
16
|
+
openDeleteDialog(path: string, data: number): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const DeleteDialog = React.memo(function DeleteDialog({
|
|
20
|
+
open,
|
|
21
|
+
onConfirm,
|
|
22
|
+
onCancel,
|
|
23
|
+
title,
|
|
24
|
+
message,
|
|
25
|
+
acceptText,
|
|
26
|
+
declineText,
|
|
27
|
+
}: DeleteDialogProps) {
|
|
28
|
+
const t = useI18n();
|
|
29
|
+
return (
|
|
30
|
+
<Modal
|
|
31
|
+
title={title ?? t('confirm.delete.title')}
|
|
32
|
+
open={open}
|
|
33
|
+
onOk={onConfirm}
|
|
34
|
+
onCancel={onCancel}
|
|
35
|
+
okText={acceptText ?? t('confirm.accept')}
|
|
36
|
+
okButtonProps={{ danger: true }}
|
|
37
|
+
cancelText={declineText ?? t('confirm.decline')}
|
|
38
|
+
aria-labelledby='alert-dialog-confirmdelete-title'
|
|
39
|
+
aria-describedby='alert-dialog-confirmdelete-description'
|
|
40
|
+
>
|
|
41
|
+
<p>{message ?? t('confirm.delete.message')}</p>
|
|
42
|
+
</Modal>
|
|
43
|
+
);
|
|
44
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Modal, Button, Tooltip } from 'antd';
|
|
3
|
+
import { FullscreenOutlined, FullscreenExitOutlined } from '@ant-design/icons';
|
|
4
|
+
import {
|
|
5
|
+
useDetailDialog,
|
|
6
|
+
DetailDialogOptions,
|
|
7
|
+
} from '@chobantonov/jsonforms-react-renderer-common/interaction/detailDialog';
|
|
8
|
+
import { useTranslator } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
9
|
+
|
|
10
|
+
export const DetailModal = ({
|
|
11
|
+
options = {},
|
|
12
|
+
...props
|
|
13
|
+
}: React.ComponentProps<typeof Modal> & { options?: DetailDialogOptions }) => {
|
|
14
|
+
const t = useTranslator();
|
|
15
|
+
const surface = React.useRef<HTMLDivElement>(null);
|
|
16
|
+
const geometry = useDetailDialog(
|
|
17
|
+
!!props.open,
|
|
18
|
+
options,
|
|
19
|
+
() => surface.current?.firstElementChild as HTMLElement | null,
|
|
20
|
+
);
|
|
21
|
+
const [restoredWidth, setRestoredWidth] = React.useState<string>();
|
|
22
|
+
if (!props.open && restoredWidth !== undefined) setRestoredWidth(undefined);
|
|
23
|
+
const toggle = () => {
|
|
24
|
+
if (!geometry.maximized) {
|
|
25
|
+
// Native CSS resizing writes an inline width on the content container.
|
|
26
|
+
const container = surface.current
|
|
27
|
+
?.firstElementChild as HTMLElement | null;
|
|
28
|
+
if (container?.style.width) setRestoredWidth(container.style.width);
|
|
29
|
+
}
|
|
30
|
+
geometry.toggle();
|
|
31
|
+
};
|
|
32
|
+
const styles =
|
|
33
|
+
typeof props.styles === 'function' ? props.styles({ props }) : props.styles;
|
|
34
|
+
const label = geometry.maximized
|
|
35
|
+
? t('dialog.restore', 'Restore dialog')
|
|
36
|
+
: t('dialog.maximize', 'Maximize dialog');
|
|
37
|
+
return (
|
|
38
|
+
<Modal
|
|
39
|
+
{...props}
|
|
40
|
+
centered={props.centered ?? true}
|
|
41
|
+
width={geometry.style.width ?? props.width}
|
|
42
|
+
style={{
|
|
43
|
+
...props.style,
|
|
44
|
+
top: props.centered === false ? 16 : 0,
|
|
45
|
+
paddingBottom: 0,
|
|
46
|
+
}}
|
|
47
|
+
styles={{
|
|
48
|
+
...styles,
|
|
49
|
+
container: {
|
|
50
|
+
...styles?.container,
|
|
51
|
+
width: geometry.maximized ? '100%' : restoredWidth,
|
|
52
|
+
resize: geometry.style.resize,
|
|
53
|
+
minWidth: 280,
|
|
54
|
+
minHeight: 160,
|
|
55
|
+
maxWidth: geometry.style.maxWidth,
|
|
56
|
+
height: geometry.style.height,
|
|
57
|
+
maxHeight: geometry.style.maxHeight,
|
|
58
|
+
overflow: 'hidden',
|
|
59
|
+
display: 'flex',
|
|
60
|
+
flexDirection: 'column',
|
|
61
|
+
},
|
|
62
|
+
body: {
|
|
63
|
+
...styles?.body,
|
|
64
|
+
flex: '1 1 auto',
|
|
65
|
+
minHeight: 0,
|
|
66
|
+
maxHeight: undefined,
|
|
67
|
+
overflow: 'auto',
|
|
68
|
+
},
|
|
69
|
+
header: { ...styles?.header, flexShrink: 0 },
|
|
70
|
+
footer: {
|
|
71
|
+
...styles?.footer,
|
|
72
|
+
flexShrink: 0,
|
|
73
|
+
marginTop: 'auto',
|
|
74
|
+
paddingTop: 12,
|
|
75
|
+
textAlign: 'end',
|
|
76
|
+
},
|
|
77
|
+
}}
|
|
78
|
+
modalRender={(node) => (
|
|
79
|
+
<div ref={surface} style={{ translate: geometry.style.translate }}>
|
|
80
|
+
{node}
|
|
81
|
+
</div>
|
|
82
|
+
)}
|
|
83
|
+
title={
|
|
84
|
+
<div
|
|
85
|
+
{...geometry.dragProps}
|
|
86
|
+
style={{ ...geometry.dragProps.style, paddingRight: 56 }}
|
|
87
|
+
>
|
|
88
|
+
{props.title}
|
|
89
|
+
{geometry.options.maximizable !== false && (
|
|
90
|
+
<Tooltip title={label}>
|
|
91
|
+
<Button
|
|
92
|
+
type='text'
|
|
93
|
+
aria-label={label}
|
|
94
|
+
style={{ position: 'absolute', right: 48, top: 12 }}
|
|
95
|
+
icon={
|
|
96
|
+
geometry.maximized ? (
|
|
97
|
+
<FullscreenExitOutlined />
|
|
98
|
+
) : (
|
|
99
|
+
<FullscreenOutlined />
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
onClick={toggle}
|
|
103
|
+
/>
|
|
104
|
+
</Tooltip>
|
|
105
|
+
)}
|
|
106
|
+
</div>
|
|
107
|
+
}
|
|
108
|
+
/>
|
|
109
|
+
);
|
|
110
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
and,
|
|
3
|
+
ControlProps,
|
|
4
|
+
DispatchPropsOfMultiEnumControl,
|
|
5
|
+
hasType,
|
|
6
|
+
isDescriptionHidden,
|
|
7
|
+
JsonSchema,
|
|
8
|
+
OwnPropsOfEnum,
|
|
9
|
+
Paths,
|
|
10
|
+
RankedTester,
|
|
11
|
+
rankWith,
|
|
12
|
+
resolveSchema,
|
|
13
|
+
schemaMatches,
|
|
14
|
+
schemaSubPathMatches,
|
|
15
|
+
uiTypeIs,
|
|
16
|
+
} from '@jsonforms/core';
|
|
17
|
+
|
|
18
|
+
import { withJsonFormsMultiEnumProps } from '@jsonforms/react';
|
|
19
|
+
import { Flex, Form } from 'antd';
|
|
20
|
+
import isEmpty from 'lodash/isEmpty';
|
|
21
|
+
import merge from 'lodash/merge';
|
|
22
|
+
import React from 'react';
|
|
23
|
+
import { AntdCheckbox } from '../antd-controls/AntdCheckbox';
|
|
24
|
+
import { useFocus } from '../util';
|
|
25
|
+
|
|
26
|
+
export const EnumArrayRenderer = ({
|
|
27
|
+
config,
|
|
28
|
+
id,
|
|
29
|
+
schema,
|
|
30
|
+
visible,
|
|
31
|
+
errors,
|
|
32
|
+
description,
|
|
33
|
+
label,
|
|
34
|
+
required,
|
|
35
|
+
path,
|
|
36
|
+
options,
|
|
37
|
+
data,
|
|
38
|
+
addItem,
|
|
39
|
+
removeItem,
|
|
40
|
+
uischema,
|
|
41
|
+
rootSchema,
|
|
42
|
+
enabled,
|
|
43
|
+
}: ControlProps & OwnPropsOfEnum & DispatchPropsOfMultiEnumControl) => {
|
|
44
|
+
const [focused, onFocus, onBlur] = useFocus();
|
|
45
|
+
const isValid = errors.length === 0;
|
|
46
|
+
const appliedUiSchemaOptions = merge({}, config, uischema.options);
|
|
47
|
+
const vertical = uischema.options?.vertical === true;
|
|
48
|
+
const showDescription = !isDescriptionHidden(
|
|
49
|
+
visible,
|
|
50
|
+
description,
|
|
51
|
+
focused,
|
|
52
|
+
appliedUiSchemaOptions.showUnfocusedDescription,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
if (!visible) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<Form.Item
|
|
61
|
+
required={required && !appliedUiSchemaOptions.hideRequiredAsterisk}
|
|
62
|
+
hasFeedback={!isValid}
|
|
63
|
+
validateStatus={isValid ? 'success' : 'error'}
|
|
64
|
+
label={label}
|
|
65
|
+
help={!isValid ? errors : showDescription ? description : null}
|
|
66
|
+
>
|
|
67
|
+
{/*
|
|
68
|
+
Same orientation encoding as the radio group: `vertical` false (the
|
|
69
|
+
default) lays the choices out in a wrapping row, true stacks them.
|
|
70
|
+
The checkboxes are individual controls rather than an antd
|
|
71
|
+
Checkbox.Group, so the group role and orientation are declared here.
|
|
72
|
+
*/}
|
|
73
|
+
<Flex
|
|
74
|
+
aria-orientation={vertical ? 'vertical' : 'horizontal'}
|
|
75
|
+
gap={vertical ? 4 : 8}
|
|
76
|
+
role='group'
|
|
77
|
+
vertical={vertical}
|
|
78
|
+
wrap={!vertical}
|
|
79
|
+
>
|
|
80
|
+
{(options ?? []).map((option: any, index: number) => {
|
|
81
|
+
const optionPath = Paths.compose(path, `${index}`);
|
|
82
|
+
const checkboxValue = data?.includes(option.value) ? true : false;
|
|
83
|
+
return (
|
|
84
|
+
<AntdCheckbox
|
|
85
|
+
id={id + '-input-' + option.value}
|
|
86
|
+
key={option.value}
|
|
87
|
+
label={option.label}
|
|
88
|
+
isValid={isEmpty(errors)}
|
|
89
|
+
path={optionPath}
|
|
90
|
+
handleChange={(_childPath, newValue) =>
|
|
91
|
+
newValue
|
|
92
|
+
? addItem(path, option.value)
|
|
93
|
+
: removeItem?.(path, option.value)
|
|
94
|
+
}
|
|
95
|
+
data={checkboxValue}
|
|
96
|
+
errors={errors}
|
|
97
|
+
schema={schema}
|
|
98
|
+
visible={visible}
|
|
99
|
+
rootSchema={rootSchema}
|
|
100
|
+
uischema={uischema}
|
|
101
|
+
enabled={enabled}
|
|
102
|
+
inputProps={{
|
|
103
|
+
onFocus,
|
|
104
|
+
onBlur,
|
|
105
|
+
}}
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
})}
|
|
109
|
+
</Flex>
|
|
110
|
+
</Form.Item>
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const hasOneOfItems = (schema: JsonSchema): boolean =>
|
|
115
|
+
schema.oneOf !== undefined &&
|
|
116
|
+
schema.oneOf.length > 0 &&
|
|
117
|
+
(schema.oneOf as JsonSchema[]).every((entry: JsonSchema) => {
|
|
118
|
+
return entry.const !== undefined;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const hasEnumItems = (schema: JsonSchema): boolean =>
|
|
122
|
+
schema.type === 'string' && schema.enum !== undefined;
|
|
123
|
+
|
|
124
|
+
export const enumArrayRendererTester: RankedTester = rankWith(
|
|
125
|
+
5,
|
|
126
|
+
and(
|
|
127
|
+
uiTypeIs('Control'),
|
|
128
|
+
and(
|
|
129
|
+
schemaMatches(
|
|
130
|
+
(schema) =>
|
|
131
|
+
hasType(schema, 'array') &&
|
|
132
|
+
!Array.isArray(schema.items) &&
|
|
133
|
+
schema.uniqueItems === true,
|
|
134
|
+
),
|
|
135
|
+
schemaSubPathMatches('items', (schema, rootSchema) => {
|
|
136
|
+
const resolvedSchema = schema.$ref
|
|
137
|
+
? resolveSchema(rootSchema, schema.$ref, rootSchema)
|
|
138
|
+
: schema;
|
|
139
|
+
return (
|
|
140
|
+
!!resolvedSchema &&
|
|
141
|
+
(hasOneOfItems(resolvedSchema) || hasEnumItems(resolvedSchema))
|
|
142
|
+
);
|
|
143
|
+
}),
|
|
144
|
+
),
|
|
145
|
+
),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
export default withJsonFormsMultiEnumProps(EnumArrayRenderer);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Button, Popover, Tooltip } from 'antd';
|
|
3
|
+
import {
|
|
4
|
+
ErrorSummaryList,
|
|
5
|
+
useErrorFeedback,
|
|
6
|
+
} from '@chobantonov/jsonforms-react-renderer-common/validation/errorSummary';
|
|
7
|
+
|
|
8
|
+
export const ErrorFeedback = ({
|
|
9
|
+
errors,
|
|
10
|
+
path,
|
|
11
|
+
children,
|
|
12
|
+
local = false,
|
|
13
|
+
}: React.PropsWithChildren<{
|
|
14
|
+
errors: string;
|
|
15
|
+
path?: string;
|
|
16
|
+
local?: boolean;
|
|
17
|
+
}>) => {
|
|
18
|
+
const { setOpen, count, entries, message } = useErrorFeedback(
|
|
19
|
+
errors,
|
|
20
|
+
path,
|
|
21
|
+
local,
|
|
22
|
+
);
|
|
23
|
+
if (count <= 1)
|
|
24
|
+
return (
|
|
25
|
+
<Tooltip
|
|
26
|
+
onOpenChange={setOpen}
|
|
27
|
+
trigger={['hover', 'focus']}
|
|
28
|
+
title={<span style={{ whiteSpace: 'pre-line' }}>{message}</span>}
|
|
29
|
+
>
|
|
30
|
+
{children}
|
|
31
|
+
</Tooltip>
|
|
32
|
+
);
|
|
33
|
+
return (
|
|
34
|
+
<Popover
|
|
35
|
+
onOpenChange={setOpen}
|
|
36
|
+
trigger={['hover', 'focus', 'click']}
|
|
37
|
+
content={
|
|
38
|
+
<ErrorSummaryList
|
|
39
|
+
entries={entries}
|
|
40
|
+
renderToggle={(label, toggle, expanded) => (
|
|
41
|
+
<Button type='link' onClick={toggle} aria-expanded={expanded}>
|
|
42
|
+
{label}
|
|
43
|
+
</Button>
|
|
44
|
+
)}
|
|
45
|
+
/>
|
|
46
|
+
}
|
|
47
|
+
>
|
|
48
|
+
{children}
|
|
49
|
+
</Popover>
|
|
50
|
+
);
|
|
51
|
+
};
|