oa-componentbook 1.0.1-stage.352 → 1.0.1-stage.353

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.
@@ -8,6 +8,9 @@ Object.defineProperty(exports, "__esModule", {
8
8
  });
9
9
  exports.default = FormWidget;
10
10
  require("core-js/modules/web.dom-collections.iterator.js");
11
+ require("core-js/modules/es.regexp.constructor.js");
12
+ require("core-js/modules/es.regexp.exec.js");
13
+ require("core-js/modules/es.regexp.to-string.js");
11
14
  require("core-js/modules/es.array.includes.js");
12
15
  require("core-js/modules/es.string.includes.js");
13
16
  var _antd = require("antd");
@@ -43,7 +46,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
43
46
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
44
47
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* eslint-disable */
45
48
  function FormWidget(props) {
46
- var _cancel$type, _cancel$size, _clear$type, _clear$size, _submit$type;
49
+ var _cancel$type, _cancel$size, _clear$type, _clear$size, _submit$type, _submit$disabled;
47
50
  const [form] = _antd.Form.useForm();
48
51
  const [dynamicRules, setDynamicRules] = (0, _react.useState)({});
49
52
  const {
@@ -61,20 +64,39 @@ function FormWidget(props) {
61
64
  visible,
62
65
  clear
63
66
  } = cta !== null && cta !== void 0 ? cta : {};
64
- const getFieldRules = item => {
65
- return dynamicRules[item === null || item === void 0 ? void 0 : item.name] || (item === null || item === void 0 ? void 0 : item.rules) || [];
67
+ const getFieldRules = (itemData, item) => {
68
+ console.log(item, "item");
69
+ console.log(itemData, "itemData");
70
+ if (item.customRulesCheck) {
71
+ return dynamicRules[item === null || item === void 0 ? void 0 : item.name] || (item === null || item === void 0 ? void 0 : item.rules) || [];
72
+ } else {
73
+ return getInputRules(itemData, item);
74
+ }
66
75
  };
67
76
  const getInputRules = (itemData, item) => {
68
77
  var _ref;
78
+ console.log(itemData, item, "getInputRules");
69
79
  if (itemData !== null && itemData !== void 0 && itemData.customRules) {
70
80
  for (const key in itemData === null || itemData === void 0 ? void 0 : itemData.customRules) {
71
81
  if (item[key]) {
72
82
  var _itemData$customRules;
73
- return itemData === null || itemData === void 0 || (_itemData$customRules = itemData.customRules[key]) === null || _itemData$customRules === void 0 ? void 0 : _itemData$customRules.map(r => (r === null || r === void 0 ? void 0 : r.checkValidator) && (r === null || r === void 0 ? void 0 : r.rule));
83
+ return itemData === null || itemData === void 0 || (_itemData$customRules = itemData.customRules[key]) === null || _itemData$customRules === void 0 ? void 0 : _itemData$customRules.map(r => {
84
+ var _r$rule;
85
+ if (r !== null && r !== void 0 && (_r$rule = r.rule) !== null && _r$rule !== void 0 && _r$rule.pattern) {
86
+ r.rule.pattern = new RegExp(r.rule.pattern);
87
+ }
88
+ return (r === null || r === void 0 ? void 0 : r.checkValidator) && (r === null || r === void 0 ? void 0 : r.rule);
89
+ });
74
90
  }
75
91
  }
76
92
  }
77
- return (_ref = itemData || item) === null || _ref === void 0 || (_ref = _ref.rules) === null || _ref === void 0 ? void 0 : _ref.map(r => (r === null || r === void 0 ? void 0 : r.checkValidator) && (r === null || r === void 0 ? void 0 : r.rule));
93
+ return (_ref = itemData || item) === null || _ref === void 0 || (_ref = _ref.rules) === null || _ref === void 0 ? void 0 : _ref.map(r => {
94
+ var _r$rule2;
95
+ if (r !== null && r !== void 0 && (_r$rule2 = r.rule) !== null && _r$rule2 !== void 0 && _r$rule2.pattern) {
96
+ r.rule.pattern = new RegExp(r.rule.pattern);
97
+ }
98
+ return (r === null || r === void 0 ? void 0 : r.checkValidator) && (r === null || r === void 0 ? void 0 : r.rule);
99
+ });
78
100
  };
79
101
  const handleDynamicRuleUpdate = (fieldName, value, dynamicRulesConfig) => {
80
102
  if (!dynamicRulesConfig) return;
@@ -82,6 +104,7 @@ function FormWidget(props) {
82
104
  var _config$conditions;
83
105
  let [targetField, config] = _ref2;
84
106
  const condition = (_config$conditions = config.conditions) === null || _config$conditions === void 0 ? void 0 : _config$conditions.find(c => c.type === "equals" ? value == c.value : c.type == "not_equals" ? value != c.value : c.type == "includes" ? value === null || value === void 0 ? void 0 : value.includes(c.value) : c.validator ? c.validator(value) : false);
107
+ console.log(condition, "condition");
85
108
  const newRules = condition ? condition.rules : config.defaultRules || [];
86
109
  setDynamicRules(prev => _objectSpread(_objectSpread({}, prev), {}, {
87
110
  [targetField]: newRules
@@ -93,6 +116,7 @@ function FormWidget(props) {
93
116
  }
94
117
  });
95
118
  };
119
+ console.log(dynamicRules, "dynamicrule");
96
120
  const dynamicClassInCaseOfUpload = item => {
97
121
  if ((item === null || item === void 0 ? void 0 : item.width) === "full") {
98
122
  return "cstUplaodWithFullWidth";
@@ -114,7 +138,7 @@ function FormWidget(props) {
114
138
  };
115
139
  const renderFieldWidget = (item, index, itemData) => {
116
140
  if ((item === null || item === void 0 ? void 0 : item.widget) === "date" && (item === null || item === void 0 ? void 0 : item.visible) !== false) {
117
- var _item$props, _item$props$getDisabl;
141
+ var _item$props, _item$props$getDisabl, _item$disabled;
118
142
  return /*#__PURE__*/_react.default.createElement(_antd.Form.Item, {
119
143
  value: item === null || item === void 0 ? void 0 : item.value,
120
144
  name: item === null || item === void 0 ? void 0 : item.name,
@@ -127,11 +151,12 @@ function FormWidget(props) {
127
151
  width: "100%"
128
152
  },
129
153
  disabledDateFunction: item === null || item === void 0 || (_item$props = item.props) === null || _item$props === void 0 || (_item$props$getDisabl = _item$props.getDisabledDateLogic) === null || _item$props$getDisabl === void 0 ? void 0 : _item$props$getDisabl.call(_item$props, item.valueProp),
154
+ disabled: (_item$disabled = item.disabled) !== null && _item$disabled !== void 0 ? _item$disabled : false,
130
155
  defaultValue: item.defaultValue
131
156
  }, item === null || item === void 0 ? void 0 : item.props)));
132
157
  }
133
158
  if ((item === null || item === void 0 ? void 0 : item.widget) === "select" && (item === null || item === void 0 ? void 0 : item.visible) !== false) {
134
- var _item$disabled, _item$showSearch, _item$optionLabelProp;
159
+ var _item$disabled2, _item$showSearch, _item$optionLabelProp;
135
160
  return /*#__PURE__*/_react.default.createElement(_antd.Form.Item, {
136
161
  name: item === null || item === void 0 ? void 0 : item.name,
137
162
  label: item === null || item === void 0 ? void 0 : item.label,
@@ -141,7 +166,7 @@ function FormWidget(props) {
141
166
  options: item === null || item === void 0 ? void 0 : item.value,
142
167
  placeholder: item === null || item === void 0 ? void 0 : item.placeholder,
143
168
  defaultValue: item.defaultValueRequired && (item === null || item === void 0 ? void 0 : item.defaultValue) !== "" ? item === null || item === void 0 ? void 0 : item.defaultValue : undefined,
144
- disabled: (_item$disabled = item.disabled) !== null && _item$disabled !== void 0 ? _item$disabled : false
169
+ disabled: (_item$disabled2 = item.disabled) !== null && _item$disabled2 !== void 0 ? _item$disabled2 : false
145
170
  }, (item === null || item === void 0 ? void 0 : item.onChange) && {
146
171
  onChange: value => {
147
172
  // Call the original onChange if provided
@@ -170,12 +195,14 @@ function FormWidget(props) {
170
195
  })));
171
196
  }
172
197
  if ((item === null || item === void 0 ? void 0 : item.widget) === "textArea") {
198
+ var _item$disabled3;
173
199
  return /*#__PURE__*/_react.default.createElement(_antd.Form.Item, {
174
200
  name: item === null || item === void 0 ? void 0 : item.name,
175
201
  label: item === null || item === void 0 ? void 0 : item.label,
176
202
  rules: item === null || item === void 0 ? void 0 : item.rules
177
203
  }, /*#__PURE__*/_react.default.createElement(_CustomTextArea.default, {
178
204
  rows: 4,
205
+ disabled: (_item$disabled3 = item.disabled) !== null && _item$disabled3 !== void 0 ? _item$disabled3 : false,
179
206
  placeholder: item === null || item === void 0 ? void 0 : item.placeholder
180
207
  }));
181
208
  }
@@ -196,7 +223,7 @@ function FormWidget(props) {
196
223
  return /*#__PURE__*/_react.default.createElement(_antd.Form.Item, {
197
224
  name: "".concat(item === null || item === void 0 ? void 0 : item.name).concat(index ? index : ""),
198
225
  label: renderLabelWithTooltip(item === null || item === void 0 ? void 0 : item.label, item === null || item === void 0 ? void 0 : item.tooltip),
199
- rules: getInputRules(itemData, item),
226
+ rules: getFieldRules(itemData, item),
200
227
  extra: item === null || item === void 0 ? void 0 : item.helpText,
201
228
  initialValue: item === null || item === void 0 ? void 0 : item.value
202
229
  }, /*#__PURE__*/_react.default.createElement(_CustomInput.default, _extends({}, item === null || item === void 0 ? void 0 : item.props, {
@@ -209,13 +236,14 @@ function FormWidget(props) {
209
236
  })));
210
237
  }
211
238
  if ((item === null || item === void 0 ? void 0 : item.widget) === "checkbox") {
212
- var _item$rules, _item$className;
239
+ var _item$rules, _item$disabled4, _item$className;
213
240
  return /*#__PURE__*/_react.default.createElement(_FormWidgetStyle.BgColorCheckBox, null, /*#__PURE__*/_react.default.createElement(_antd.Form.Item, {
214
241
  name: "".concat(item === null || item === void 0 ? void 0 : item.name).concat(index ? index : ""),
215
242
  rules: item === null || item === void 0 || (_item$rules = item.rules) === null || _item$rules === void 0 ? void 0 : _item$rules.map(r => (r === null || r === void 0 ? void 0 : r.checkValidator) && (r === null || r === void 0 ? void 0 : r.rule)).filter(Boolean),
216
243
  valuePropName: "checked",
217
244
  initialValue: item === null || item === void 0 ? void 0 : item.checked
218
245
  }, /*#__PURE__*/_react.default.createElement(_CustomCheckBox.default, {
246
+ disabled: (_item$disabled4 = item.disabled) !== null && _item$disabled4 !== void 0 ? _item$disabled4 : false,
219
247
  size: "large",
220
248
  label: item === null || item === void 0 ? void 0 : item.label,
221
249
  className: (_item$className = item === null || item === void 0 ? void 0 : item.className) !== null && _item$className !== void 0 ? _item$className : ""
@@ -253,7 +281,7 @@ function FormWidget(props) {
253
281
  }
254
282
  };
255
283
  const renderWidget = item => {
256
- var _item$value, _item$value2, _item$value2$map, _item$value3, _item$value4, _item$value5, _item$value6, _item$iconConfig, _item$subType, _item$disabled2;
284
+ var _item$value, _item$value2, _item$value2$map, _item$value3, _item$value4, _item$value5, _item$value6, _item$iconConfig, _item$subType, _item$disabled5;
257
285
  switch (item === null || item === void 0 ? void 0 : item.type) {
258
286
  case "simpleList":
259
287
  if ((item === null || item === void 0 || (_item$value = item.value) === null || _item$value === void 0 ? void 0 : _item$value.length) === 0) return null;
@@ -355,7 +383,7 @@ function FormWidget(props) {
355
383
  }, /*#__PURE__*/_react.default.createElement(_CustomButton.default, _extends({
356
384
  type: (_item$subType = item === null || item === void 0 ? void 0 : item.subType) !== null && _item$subType !== void 0 ? _item$subType : "primary",
357
385
  label: item === null || item === void 0 ? void 0 : item.label,
358
- disabled: (_item$disabled2 = item === null || item === void 0 ? void 0 : item.disabled) !== null && _item$disabled2 !== void 0 ? _item$disabled2 : false,
386
+ disabled: (_item$disabled5 = item === null || item === void 0 ? void 0 : item.disabled) !== null && _item$disabled5 !== void 0 ? _item$disabled5 : false,
359
387
  onClick: () => {
360
388
  if (item !== null && item !== void 0 && item.onClick) {
361
389
  item.onClick(item === null || item === void 0 ? void 0 : item.action, item === null || item === void 0 ? void 0 : item.key);
@@ -467,6 +495,7 @@ function FormWidget(props) {
467
495
  }
468
496
  })), submit && /*#__PURE__*/_react.default.createElement(_antd.Form.Item, null, /*#__PURE__*/_react.default.createElement(_CustomButton.default, {
469
497
  type: (_submit$type = submit === null || submit === void 0 ? void 0 : submit.type) !== null && _submit$type !== void 0 ? _submit$type : "primary",
498
+ disabled: (_submit$disabled = submit.disabled) !== null && _submit$disabled !== void 0 ? _submit$disabled : false,
470
499
  onClick: () => {
471
500
  var _form$validateFields3;
472
501
  form === null || form === void 0 || (_form$validateFields3 = form.validateFields()) === null || _form$validateFields3 === void 0 || _form$validateFields3.then(value => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oa-componentbook",
3
- "version": "1.0.1-stage.352",
3
+ "version": "1.0.1-stage.353",
4
4
  "private": false,
5
5
  "description": "Reusable components",
6
6
  "main": "build/index.js",