@rjsf/antd 6.1.1 → 6.2.3

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/dist/index.cjs CHANGED
@@ -144,6 +144,7 @@ function ArrayFieldTemplate(props) {
144
144
  }
145
145
 
146
146
  // src/templates/BaseInputTemplate/index.tsx
147
+ var import_react2 = require("react");
147
148
  var import_antd3 = require("antd");
148
149
  var import_utils3 = require("@rjsf/utils");
149
150
  var import_jsx_runtime3 = require("react/jsx-runtime");
@@ -170,10 +171,19 @@ function BaseInputTemplate(props) {
170
171
  const { formContext } = registry;
171
172
  const inputProps = (0, import_utils3.getInputProps)(schema, type, options, false);
172
173
  const { readonlyAsDisabled = true } = formContext;
174
+ const { ClearButton: ClearButton2 } = registry.templates.ButtonTemplates;
173
175
  const handleNumberChange = (nextValue) => onChange(nextValue);
174
176
  const handleTextChange = onChangeOverride ? onChangeOverride : ({ target }) => onChange(target.value === "" ? options.emptyValue : target.value);
175
177
  const handleBlur = ({ target }) => onBlur(id, target && target.value);
176
178
  const handleFocus = ({ target }) => onFocus(id, target && target.value);
179
+ const handleClear = (0, import_react2.useCallback)(
180
+ (e) => {
181
+ e.preventDefault();
182
+ e.stopPropagation();
183
+ onChange(options.emptyValue ?? "");
184
+ },
185
+ [onChange, options.emptyValue]
186
+ );
177
187
  const input = inputProps.type === "number" || inputProps.type === "integer" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
178
188
  import_antd3.InputNumber,
179
189
  {
@@ -209,6 +219,7 @@ function BaseInputTemplate(props) {
209
219
  );
210
220
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
211
221
  input,
222
+ options.allowClearTextInputs && !readonly && !disabled && value && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ClearButton2, { registry, onClick: handleClear }),
212
223
  Array.isArray(schema.examples) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("datalist", { id: (0, import_utils3.examplesId)(id), children: schema.examples.concat(schema.default && !schema.examples.includes(schema.default) ? [schema.default] : []).map((example) => {
213
224
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: example }, example);
214
225
  }) })
@@ -258,6 +269,7 @@ var import_ArrowUpOutlined = __toESM(require("@ant-design/icons/ArrowUpOutlined"
258
269
  var import_CopyOutlined = __toESM(require("@ant-design/icons/CopyOutlined"), 1);
259
270
  var import_DeleteOutlined = __toESM(require("@ant-design/icons/DeleteOutlined"), 1);
260
271
  var import_PlusCircleOutlined = __toESM(require("@ant-design/icons/PlusCircleOutlined"), 1);
272
+ var import_CloseOutlined = __toESM(require("@ant-design/icons/CloseOutlined"), 1);
261
273
  var import_utils5 = require("@rjsf/utils");
262
274
  var import_jsx_runtime6 = require("react/jsx-runtime");
263
275
  function IconButton(props) {
@@ -327,6 +339,20 @@ function RemoveButton(props) {
327
339
  }
328
340
  );
329
341
  }
342
+ function ClearButton(props) {
343
+ const {
344
+ registry: { translateString }
345
+ } = props;
346
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
347
+ IconButton,
348
+ {
349
+ title: translateString(import_utils5.TranslatableString.ClearButton),
350
+ ...props,
351
+ iconType: "link",
352
+ icon: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_CloseOutlined.default, {})
353
+ }
354
+ );
355
+ }
330
356
 
331
357
  // src/templates/FieldErrorTemplate/index.tsx
332
358
  var import_utils6 = require("@rjsf/utils");
@@ -440,7 +466,7 @@ var import_isNumber = __toESM(require("lodash/isNumber"), 1);
440
466
  var import_isString = __toESM(require("lodash/isString"), 1);
441
467
  var import_utils8 = require("@rjsf/utils");
442
468
  var import_antd8 = require("antd");
443
- var import_react2 = require("react");
469
+ var import_react3 = require("react");
444
470
  var import_jsx_runtime11 = require("react/jsx-runtime");
445
471
  function ObjectFieldTemplate(props) {
446
472
  const {
@@ -493,7 +519,7 @@ function ObjectFieldTemplate(props) {
493
519
  }
494
520
  return defaultColSpan;
495
521
  };
496
- const { getPrefixCls } = (0, import_react2.useContext)(import_antd8.ConfigProvider.ConfigContext);
522
+ const { getPrefixCls } = (0, import_react3.useContext)(import_antd8.ConfigProvider.ConfigContext);
497
523
  const prefixCls = getPrefixCls("form");
498
524
  const labelClsBasic = `${prefixCls}-item-label`;
499
525
  const labelColClassName = (0, import_classnames2.default)(
@@ -583,7 +609,7 @@ function SubmitButton({ uiSchema }) {
583
609
  // src/templates/TitleField/index.tsx
584
610
  var import_classnames3 = __toESM(require("classnames"), 1);
585
611
  var import_antd10 = require("antd");
586
- var import_react3 = require("react");
612
+ var import_react4 = require("react");
587
613
  var import_jsx_runtime14 = require("react/jsx-runtime");
588
614
  function TitleField({
589
615
  id,
@@ -607,7 +633,7 @@ function TitleField({
607
633
  control.focus();
608
634
  }
609
635
  };
610
- const { getPrefixCls } = (0, import_react3.useContext)(import_antd10.ConfigProvider.ConfigContext);
636
+ const { getPrefixCls } = (0, import_react4.useContext)(import_antd10.ConfigProvider.ConfigContext);
611
637
  const prefixCls = getPrefixCls("form");
612
638
  const labelClassName = (0, import_classnames3.default)({
613
639
  [`${prefixCls}-item-required`]: required,
@@ -740,7 +766,8 @@ function generateTemplates() {
740
766
  MoveDownButton,
741
767
  MoveUpButton,
742
768
  RemoveButton,
743
- SubmitButton
769
+ SubmitButton,
770
+ ClearButton
744
771
  },
745
772
  DescriptionFieldTemplate: DescriptionField,
746
773
  ErrorListTemplate: ErrorList,
@@ -756,19 +783,31 @@ function generateTemplates() {
756
783
  }
757
784
  var templates_default = generateTemplates();
758
785
 
786
+ // src/widgets/AltDateTimeWidget/index.tsx
787
+ var import_jsx_runtime16 = require("react/jsx-runtime");
788
+ function AltDateTimeWidget({ time = true, ...props }) {
789
+ const { AltDateWidget: AltDateWidget2 } = props.registry.widgets;
790
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(AltDateWidget2, { time, ...props });
791
+ }
792
+
759
793
  // src/widgets/AltDateWidget/index.tsx
760
794
  var import_antd12 = require("antd");
761
795
  var import_utils11 = require("@rjsf/utils");
762
- var import_jsx_runtime16 = require("react/jsx-runtime");
763
- function AltDateWidget(props) {
764
- const { autofocus, disabled, id, name, onBlur, onFocus, options, readonly, registry } = props;
796
+ var import_jsx_runtime17 = require("react/jsx-runtime");
797
+ function AltDateWidget({ autofocus = false, disabled = false, options, readonly = false, time = false, ...props }) {
798
+ const { id, name, onBlur, onFocus, registry } = props;
765
799
  const { formContext, translateString } = registry;
766
800
  const { rowGutter = 24 } = formContext;
767
- const { elements, handleChange, handleClear, handleSetNow } = (0, import_utils11.useAltDateWidgetProps)(props);
768
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_antd12.Row, { gutter: [Math.floor(rowGutter / 2), Math.floor(rowGutter / 2)], children: [
801
+ const realOptions = { yearsRange: [1900, (/* @__PURE__ */ new Date()).getFullYear() + 2], ...options };
802
+ const { elements, handleChange, handleClear, handleSetNow } = (0, import_utils11.useAltDateWidgetProps)({
803
+ ...props,
804
+ autofocus,
805
+ options: realOptions
806
+ });
807
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_antd12.Row, { gutter: [Math.floor(rowGutter / 2), Math.floor(rowGutter / 2)], children: [
769
808
  elements.map((elemProps, i) => {
770
809
  const elemId = `${id}_${elemProps.type}`;
771
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_antd12.Col, { flex: "88px", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
810
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_antd12.Col, { flex: "88px", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
772
811
  import_utils11.DateElement,
773
812
  {
774
813
  rootId: id,
@@ -784,30 +823,10 @@ function AltDateWidget(props) {
784
823
  }
785
824
  ) }, elemId);
786
825
  }),
787
- !options.hideNowButton && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_antd12.Col, { flex: "88px", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_antd12.Button, { block: true, className: "btn-now", onClick: handleSetNow, type: "primary", children: translateString(import_utils11.TranslatableString.NowLabel) }) }),
788
- !options.hideClearButton && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_antd12.Col, { flex: "88px", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_antd12.Button, { block: true, className: "btn-clear", danger: true, onClick: handleClear, type: "primary", children: translateString(import_utils11.TranslatableString.ClearLabel) }) })
826
+ !options.hideNowButton && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_antd12.Col, { flex: "88px", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_antd12.Button, { block: true, className: "btn-now", onClick: handleSetNow, type: "primary", children: translateString(import_utils11.TranslatableString.NowLabel) }) }),
827
+ !options.hideClearButton && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_antd12.Col, { flex: "88px", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_antd12.Button, { block: true, className: "btn-clear", danger: true, onClick: handleClear, type: "primary", children: translateString(import_utils11.TranslatableString.ClearLabel) }) })
789
828
  ] });
790
829
  }
791
- AltDateWidget.defaultProps = {
792
- autofocus: false,
793
- disabled: false,
794
- options: {
795
- yearsRange: [1900, (/* @__PURE__ */ new Date()).getFullYear() + 2]
796
- },
797
- readonly: false,
798
- time: false
799
- };
800
-
801
- // src/widgets/AltDateTimeWidget/index.tsx
802
- var import_jsx_runtime17 = require("react/jsx-runtime");
803
- function AltDateTimeWidget(props) {
804
- const { AltDateWidget: AltDateWidget2 } = props.registry.widgets;
805
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(AltDateWidget2, { time: true, ...props });
806
- }
807
- AltDateTimeWidget.defaultProps = {
808
- ...AltDateWidget.defaultProps,
809
- time: true
810
- };
811
830
 
812
831
  // src/widgets/CheckboxesWidget/index.tsx
813
832
  var import_antd13 = require("antd");
@@ -1095,10 +1114,10 @@ function RangeWidget(props) {
1095
1114
  }
1096
1115
 
1097
1116
  // src/widgets/SelectWidget/index.tsx
1117
+ var import_react5 = require("react");
1098
1118
  var import_antd20 = require("antd");
1099
1119
  var import_utils19 = require("@rjsf/utils");
1100
1120
  var import_isString2 = __toESM(require("lodash/isString"), 1);
1101
- var import_react4 = require("react");
1102
1121
  var import_jsx_runtime25 = require("react/jsx-runtime");
1103
1122
  var SELECT_STYLE = {
1104
1123
  width: "100%"
@@ -1119,6 +1138,7 @@ function SelectWidget({
1119
1138
  value,
1120
1139
  schema
1121
1140
  }) {
1141
+ const [open, setOpen] = (0, import_react5.useState)(false);
1122
1142
  const { formContext } = registry;
1123
1143
  const { readonlyAsDisabled = true } = formContext;
1124
1144
  const { enumOptions, enumDisabled, emptyValue } = options;
@@ -1131,13 +1151,13 @@ function SelectWidget({
1131
1151
  }
1132
1152
  return false;
1133
1153
  };
1134
- const getPopupContainer = (node) => node.parentNode;
1154
+ const getPopupContainer = SelectWidget.getPopupContainerCallback();
1135
1155
  const selectedIndexes = (0, import_utils19.enumOptionsIndexForValue)(value, enumOptions, multiple);
1136
1156
  const extraProps = {
1137
1157
  name: htmlName || id
1138
1158
  };
1139
1159
  const showPlaceholderOption = !multiple && schema.default === void 0;
1140
- const selectOptions = (0, import_react4.useMemo)(() => {
1160
+ const selectOptions = (0, import_react5.useMemo)(() => {
1141
1161
  if (Array.isArray(enumOptions)) {
1142
1162
  const options2 = enumOptions.map(({ value: optionValue, label: optionLabel }, index) => ({
1143
1163
  disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(optionValue) !== -1,
@@ -1155,6 +1175,7 @@ function SelectWidget({
1155
1175
  return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1156
1176
  import_antd20.Select,
1157
1177
  {
1178
+ open,
1158
1179
  autoFocus: autofocus,
1159
1180
  disabled: disabled || readonlyAsDisabled && readonly,
1160
1181
  getPopupContainer,
@@ -1167,12 +1188,14 @@ function SelectWidget({
1167
1188
  style: SELECT_STYLE,
1168
1189
  value: selectedIndexes,
1169
1190
  ...extraProps,
1191
+ onOpenChange: setOpen,
1170
1192
  filterOption,
1171
1193
  "aria-describedby": (0, import_utils19.ariaDescribedByIds)(id),
1172
1194
  options: selectOptions
1173
1195
  }
1174
1196
  );
1175
1197
  }
1198
+ SelectWidget.getPopupContainerCallback = () => (node) => node.parentElement;
1176
1199
 
1177
1200
  // src/widgets/TextareaWidget/index.tsx
1178
1201
  var import_antd21 = require("antd");