@rjsf/antd 6.1.2 → 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/antd.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@rjsf/core'), require('antd'), require('@rjsf/utils'), require('react/jsx-runtime'), require('classnames'), require('react'), require('@ant-design/icons/ExclamationCircleOutlined'), require('@ant-design/icons/ArrowDownOutlined'), require('@ant-design/icons/ArrowUpOutlined'), require('@ant-design/icons/CopyOutlined'), require('@ant-design/icons/DeleteOutlined'), require('@ant-design/icons/PlusCircleOutlined'), require('lodash/isObject'), require('lodash/isNumber'), require('lodash/isString'), require('dayjs')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@rjsf/core', 'antd', '@rjsf/utils', 'react/jsx-runtime', 'classnames', 'react', '@ant-design/icons/ExclamationCircleOutlined', '@ant-design/icons/ArrowDownOutlined', '@ant-design/icons/ArrowUpOutlined', '@ant-design/icons/CopyOutlined', '@ant-design/icons/DeleteOutlined', '@ant-design/icons/PlusCircleOutlined', 'lodash/isObject', 'lodash/isNumber', 'lodash/isString', 'dayjs'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/antd"] = {}, global.core, global.antd, global.utils, global.jsxRuntime, global.classNames, global.react, global.ExclamationCircleOutlined, global.ArrowDownOutlined, global.ArrowUpOutlined, global.CopyOutlined, global.DeleteOutlined, global.PlusCircleOutlined, global.isObject, global.isNumber, global.isString, global.dayjs));
5
- })(this, (function (exports, core, antd, utils, jsxRuntime, classNames, react, ExclamationCircleOutlined, ArrowDownOutlined, ArrowUpOutlined, CopyOutlined, DeleteOutlined, PlusCircleOutlined, isObject, isNumber, isString, dayjs) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@rjsf/core'), require('antd'), require('@rjsf/utils'), require('react/jsx-runtime'), require('classnames'), require('react'), require('@ant-design/icons/ExclamationCircleOutlined'), require('@ant-design/icons/ArrowDownOutlined'), require('@ant-design/icons/ArrowUpOutlined'), require('@ant-design/icons/CopyOutlined'), require('@ant-design/icons/DeleteOutlined'), require('@ant-design/icons/PlusCircleOutlined'), require('@ant-design/icons/CloseOutlined'), require('lodash/isObject'), require('lodash/isNumber'), require('lodash/isString'), require('dayjs')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@rjsf/core', 'antd', '@rjsf/utils', 'react/jsx-runtime', 'classnames', 'react', '@ant-design/icons/ExclamationCircleOutlined', '@ant-design/icons/ArrowDownOutlined', '@ant-design/icons/ArrowUpOutlined', '@ant-design/icons/CopyOutlined', '@ant-design/icons/DeleteOutlined', '@ant-design/icons/PlusCircleOutlined', '@ant-design/icons/CloseOutlined', 'lodash/isObject', 'lodash/isNumber', 'lodash/isString', 'dayjs'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/antd"] = {}, global.core, global.antd, global.utils, global.jsxRuntime, global.classNames, global.react, global.ExclamationCircleOutlined, global.ArrowDownOutlined, global.ArrowUpOutlined, global.CopyOutlined, global.DeleteOutlined, global.PlusCircleOutlined, global.CloseOutlined, global.isObject, global.isNumber, global.isString, global.dayjs));
5
+ })(this, (function (exports, core, antd, utils, jsxRuntime, classNames, react, ExclamationCircleOutlined, ArrowDownOutlined, ArrowUpOutlined, CopyOutlined, DeleteOutlined, PlusCircleOutlined, CloseOutlined, isObject, isNumber, isString, dayjs) { 'use strict';
6
6
 
7
7
  // src/index.ts
8
8
  var BTN_GRP_STYLE = {
@@ -116,10 +116,19 @@
116
116
  const { formContext } = registry;
117
117
  const inputProps = utils.getInputProps(schema, type, options, false);
118
118
  const { readonlyAsDisabled = true } = formContext;
119
+ const { ClearButton: ClearButton2 } = registry.templates.ButtonTemplates;
119
120
  const handleNumberChange = (nextValue) => onChange(nextValue);
120
121
  const handleTextChange = onChangeOverride ? onChangeOverride : ({ target }) => onChange(target.value === "" ? options.emptyValue : target.value);
121
122
  const handleBlur = ({ target }) => onBlur(id, target && target.value);
122
123
  const handleFocus = ({ target }) => onFocus(id, target && target.value);
124
+ const handleClear = react.useCallback(
125
+ (e) => {
126
+ e.preventDefault();
127
+ e.stopPropagation();
128
+ onChange(options.emptyValue ?? "");
129
+ },
130
+ [onChange, options.emptyValue]
131
+ );
123
132
  const input = inputProps.type === "number" || inputProps.type === "integer" ? /* @__PURE__ */ jsxRuntime.jsx(
124
133
  antd.InputNumber,
125
134
  {
@@ -155,6 +164,7 @@
155
164
  );
156
165
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
157
166
  input,
167
+ options.allowClearTextInputs && !readonly && !disabled && value && /* @__PURE__ */ jsxRuntime.jsx(ClearButton2, { registry, onClick: handleClear }),
158
168
  Array.isArray(schema.examples) && /* @__PURE__ */ jsxRuntime.jsx("datalist", { id: utils.examplesId(id), children: schema.examples.concat(schema.default && !schema.examples.includes(schema.default) ? [schema.default] : []).map((example) => {
159
169
  return /* @__PURE__ */ jsxRuntime.jsx("option", { value: example }, example);
160
170
  }) })
@@ -253,6 +263,20 @@
253
263
  }
254
264
  );
255
265
  }
266
+ function ClearButton(props) {
267
+ const {
268
+ registry: { translateString }
269
+ } = props;
270
+ return /* @__PURE__ */ jsxRuntime.jsx(
271
+ IconButton,
272
+ {
273
+ title: translateString(utils.TranslatableString.ClearButton),
274
+ ...props,
275
+ iconType: "link",
276
+ icon: /* @__PURE__ */ jsxRuntime.jsx(CloseOutlined, {})
277
+ }
278
+ );
279
+ }
256
280
  function FieldErrorTemplate(props) {
257
281
  const { errors = [], fieldPathId } = props;
258
282
  if (errors.length === 0) {
@@ -621,7 +645,8 @@
621
645
  MoveDownButton,
622
646
  MoveUpButton,
623
647
  RemoveButton,
624
- SubmitButton
648
+ SubmitButton,
649
+ ClearButton
625
650
  },
626
651
  DescriptionFieldTemplate: DescriptionField,
627
652
  ErrorListTemplate: ErrorList,
@@ -636,11 +661,20 @@
636
661
  };
637
662
  }
638
663
  var templates_default = generateTemplates();
639
- function AltDateWidget(props) {
640
- const { autofocus, disabled, id, name, onBlur, onFocus, options, readonly, registry } = props;
664
+ function AltDateTimeWidget({ time = true, ...props }) {
665
+ const { AltDateWidget: AltDateWidget2 } = props.registry.widgets;
666
+ return /* @__PURE__ */ jsxRuntime.jsx(AltDateWidget2, { time, ...props });
667
+ }
668
+ function AltDateWidget({ autofocus = false, disabled = false, options, readonly = false, time = false, ...props }) {
669
+ const { id, name, onBlur, onFocus, registry } = props;
641
670
  const { formContext, translateString } = registry;
642
671
  const { rowGutter = 24 } = formContext;
643
- const { elements, handleChange, handleClear, handleSetNow } = utils.useAltDateWidgetProps(props);
672
+ const realOptions = { yearsRange: [1900, (/* @__PURE__ */ new Date()).getFullYear() + 2], ...options };
673
+ const { elements, handleChange, handleClear, handleSetNow } = utils.useAltDateWidgetProps({
674
+ ...props,
675
+ autofocus,
676
+ options: realOptions
677
+ });
644
678
  return /* @__PURE__ */ jsxRuntime.jsxs(antd.Row, { gutter: [Math.floor(rowGutter / 2), Math.floor(rowGutter / 2)], children: [
645
679
  elements.map((elemProps, i) => {
646
680
  const elemId = `${id}_${elemProps.type}`;
@@ -664,23 +698,6 @@
664
698
  !options.hideClearButton && /* @__PURE__ */ jsxRuntime.jsx(antd.Col, { flex: "88px", children: /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { block: true, className: "btn-clear", danger: true, onClick: handleClear, type: "primary", children: translateString(utils.TranslatableString.ClearLabel) }) })
665
699
  ] });
666
700
  }
667
- AltDateWidget.defaultProps = {
668
- autofocus: false,
669
- disabled: false,
670
- options: {
671
- yearsRange: [1900, (/* @__PURE__ */ new Date()).getFullYear() + 2]
672
- },
673
- readonly: false,
674
- time: false
675
- };
676
- function AltDateTimeWidget(props) {
677
- const { AltDateWidget: AltDateWidget2 } = props.registry.widgets;
678
- return /* @__PURE__ */ jsxRuntime.jsx(AltDateWidget2, { time: true, ...props });
679
- }
680
- AltDateTimeWidget.defaultProps = {
681
- ...AltDateWidget.defaultProps,
682
- time: true
683
- };
684
701
  function CheckboxesWidget({
685
702
  autofocus,
686
703
  disabled,
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,7 +1114,7 @@ function RangeWidget(props) {
1095
1114
  }
1096
1115
 
1097
1116
  // src/widgets/SelectWidget/index.tsx
1098
- var import_react4 = require("react");
1117
+ var import_react5 = require("react");
1099
1118
  var import_antd20 = require("antd");
1100
1119
  var import_utils19 = require("@rjsf/utils");
1101
1120
  var import_isString2 = __toESM(require("lodash/isString"), 1);
@@ -1119,7 +1138,7 @@ function SelectWidget({
1119
1138
  value,
1120
1139
  schema
1121
1140
  }) {
1122
- const [open, setOpen] = (0, import_react4.useState)(false);
1141
+ const [open, setOpen] = (0, import_react5.useState)(false);
1123
1142
  const { formContext } = registry;
1124
1143
  const { readonlyAsDisabled = true } = formContext;
1125
1144
  const { enumOptions, enumDisabled, emptyValue } = options;
@@ -1138,7 +1157,7 @@ function SelectWidget({
1138
1157
  name: htmlName || id
1139
1158
  };
1140
1159
  const showPlaceholderOption = !multiple && schema.default === void 0;
1141
- const selectOptions = (0, import_react4.useMemo)(() => {
1160
+ const selectOptions = (0, import_react5.useMemo)(() => {
1142
1161
  if (Array.isArray(enumOptions)) {
1143
1162
  const options2 = enumOptions.map(({ value: optionValue, label: optionLabel }, index) => ({
1144
1163
  disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(optionValue) !== -1,