@knovator/pagecreator-admin 0.0.8 → 0.0.9

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/index.js CHANGED
@@ -3472,6 +3472,45 @@ const PageSearch = () => {
3472
3472
  });
3473
3473
  };
3474
3474
 
3475
+ var call$7 = functionCall;
3476
+ var hasOwn$1 = hasOwnProperty_1;
3477
+ var isPrototypeOf$2 = objectIsPrototypeOf;
3478
+ var regExpFlags = regexpFlags$1;
3479
+
3480
+ var RegExpPrototype$1 = RegExp.prototype;
3481
+
3482
+ var regexpGetFlags = function (R) {
3483
+ var flags = R.flags;
3484
+ return flags === undefined && !('flags' in RegExpPrototype$1) && !hasOwn$1(R, 'flags') && isPrototypeOf$2(RegExpPrototype$1, R)
3485
+ ? call$7(regExpFlags, R) : flags;
3486
+ };
3487
+
3488
+ var PROPER_FUNCTION_NAME = functionName.PROPER;
3489
+ var defineBuiltIn$2 = defineBuiltIn$7;
3490
+ var anObject$5 = anObject$f;
3491
+ var $toString = toString$6;
3492
+ var fails$3 = fails$n;
3493
+ var getRegExpFlags = regexpGetFlags;
3494
+
3495
+ var TO_STRING = 'toString';
3496
+ var RegExpPrototype = RegExp.prototype;
3497
+ var nativeToString = RegExpPrototype[TO_STRING];
3498
+
3499
+ var NOT_GENERIC = fails$3(function () { return nativeToString.call({ source: 'a', flags: 'b' }) != '/a/b'; });
3500
+ // FF44- RegExp#toString has a wrong name
3501
+ var INCORRECT_NAME = PROPER_FUNCTION_NAME && nativeToString.name != TO_STRING;
3502
+
3503
+ // `RegExp.prototype.toString` method
3504
+ // https://tc39.es/ecma262/#sec-regexp.prototype.tostring
3505
+ if (NOT_GENERIC || INCORRECT_NAME) {
3506
+ defineBuiltIn$2(RegExp.prototype, TO_STRING, function toString() {
3507
+ var R = anObject$5(this);
3508
+ var pattern = $toString(R.source);
3509
+ var flags = $toString(getRegExpFlags(R));
3510
+ return '/' + pattern + '/' + flags;
3511
+ }, { unsafe: true });
3512
+ }
3513
+
3475
3514
  var aCallable$6 = aCallable$8;
3476
3515
  var toObject = toObject$5;
3477
3516
  var IndexedObject = indexedObject;
@@ -3515,11 +3554,11 @@ var arrayReduce = {
3515
3554
  right: createMethod(true)
3516
3555
  };
3517
3556
 
3518
- var fails$3 = fails$n;
3557
+ var fails$2 = fails$n;
3519
3558
 
3520
3559
  var arrayMethodIsStrict$1 = function (METHOD_NAME, argument) {
3521
3560
  var method = [][METHOD_NAME];
3522
- return !!method && fails$3(function () {
3561
+ return !!method && fails$2(function () {
3523
3562
  // eslint-disable-next-line no-useless-call -- required for testing
3524
3563
  method.call(null, argument || function () { return 1; }, 1);
3525
3564
  });
@@ -3550,45 +3589,6 @@ $$7({ target: 'Array', proto: true, forced: !STRICT_METHOD || CHROME_BUG }, {
3550
3589
  }
3551
3590
  });
3552
3591
 
3553
- var call$7 = functionCall;
3554
- var hasOwn$1 = hasOwnProperty_1;
3555
- var isPrototypeOf$2 = objectIsPrototypeOf;
3556
- var regExpFlags = regexpFlags$1;
3557
-
3558
- var RegExpPrototype$1 = RegExp.prototype;
3559
-
3560
- var regexpGetFlags = function (R) {
3561
- var flags = R.flags;
3562
- return flags === undefined && !('flags' in RegExpPrototype$1) && !hasOwn$1(R, 'flags') && isPrototypeOf$2(RegExpPrototype$1, R)
3563
- ? call$7(regExpFlags, R) : flags;
3564
- };
3565
-
3566
- var PROPER_FUNCTION_NAME = functionName.PROPER;
3567
- var defineBuiltIn$2 = defineBuiltIn$7;
3568
- var anObject$5 = anObject$f;
3569
- var $toString = toString$6;
3570
- var fails$2 = fails$n;
3571
- var getRegExpFlags = regexpGetFlags;
3572
-
3573
- var TO_STRING = 'toString';
3574
- var RegExpPrototype = RegExp.prototype;
3575
- var nativeToString = RegExpPrototype[TO_STRING];
3576
-
3577
- var NOT_GENERIC = fails$2(function () { return nativeToString.call({ source: 'a', flags: 'b' }) != '/a/b'; });
3578
- // FF44- RegExp#toString has a wrong name
3579
- var INCORRECT_NAME = PROPER_FUNCTION_NAME && nativeToString.name != TO_STRING;
3580
-
3581
- // `RegExp.prototype.toString` method
3582
- // https://tc39.es/ecma262/#sec-regexp.prototype.tostring
3583
- if (NOT_GENERIC || INCORRECT_NAME) {
3584
- defineBuiltIn$2(RegExp.prototype, TO_STRING, function toString() {
3585
- var R = anObject$5(this);
3586
- var pattern = $toString(R.source);
3587
- var flags = $toString(getRegExpFlags(R));
3588
- return '/' + pattern + '/' + flags;
3589
- }, { unsafe: true });
3590
- }
3591
-
3592
3592
  var $$6 = _export;
3593
3593
  var $parseInt = numberParseInt;
3594
3594
 
@@ -3617,8 +3617,7 @@ const Form = /*#__PURE__*/forwardRef(({
3617
3617
  setValue,
3618
3618
  control,
3619
3619
  setError,
3620
- watch,
3621
- getValues
3620
+ watch
3622
3621
  } = useForm(); // setting update data in form
3623
3622
 
3624
3623
  useEffect(() => {
@@ -3643,18 +3642,169 @@ const Form = /*#__PURE__*/forwardRef(({
3643
3642
  setValue(key, updates[key]);
3644
3643
  });
3645
3644
  }
3646
- }, [setValue, updates]); // setting default values
3645
+ }, [setValue, updates]);
3646
+
3647
+ const inputRenderer = schema => {
3648
+ var _a, _b, _c, _d, _e, _f;
3649
+
3650
+ let input;
3651
+ if (typeof schema.show !== 'undefined' && !schema.show) return null;
3652
+
3653
+ if (schema.type) {
3654
+ switch (schema.type) {
3655
+ case 'ReactSelect':
3656
+ input = jsx(CustomReactSelect, {
3657
+ options: schema.options,
3658
+ disabled: !_enable,
3659
+ label: schema.label,
3660
+ error: (_b = (_a = errors[schema.accessor]) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.toString(),
3661
+ onChange: value => {
3662
+ if (value) {
3663
+ setValue(schema.accessor, Array.isArray(value) ? value.map(item => item.value) : value.value);
3664
+ if (schema.onChange) schema.onChange(value);
3665
+ }
3666
+ },
3667
+ selectedOptions: schema.selectedOptions,
3668
+ required: schema.required,
3669
+ isMulti: schema.isMulti,
3670
+ isSearchable: schema.isSearchable,
3671
+ onSearch: schema.onSearch,
3672
+ isLoading: schema.isLoading,
3673
+ placeholder: schema.placeholder,
3674
+ wrapperClassName: schema.wrapperClassName,
3675
+ formatOptionLabel: schema.formatOptionLabel
3676
+ });
3677
+ break;
3678
+
3679
+ case 'checkbox':
3680
+ input = jsx(Input.Checkbox, {
3681
+ error: (_d = (_c = errors[schema.accessor]) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.toString(),
3682
+ switchClass: schema.switchClass,
3683
+ label: schema.label,
3684
+ rest: register(schema.accessor, schema.validations || {}),
3685
+ className: "block",
3686
+ disabled: _isUpdating && typeof schema.editable !== 'undefined' && !schema.editable,
3687
+ wrapperClassName: schema.wrapperClassName
3688
+ });
3689
+ break;
3690
+
3691
+ case 'select':
3692
+ input = jsx(Controller, {
3693
+ control: control,
3694
+ name: schema.accessor,
3695
+ render: ({
3696
+ field
3697
+ }) => {
3698
+ var _a, _b;
3699
+
3700
+ return jsx(Input.Select, {
3701
+ options: schema.options,
3702
+ label: schema.label,
3703
+ error: (_b = (_a = errors[schema.accessor]) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.toString(),
3704
+ onChange: e => field.onChange(e.target.value),
3705
+ value: field.value,
3706
+ className: "w-full",
3707
+ disabled: _isUpdating && typeof schema.editable !== 'undefined' && !schema.editable || !_enable,
3708
+ required: schema.required,
3709
+ wrapperClassName: schema.wrapperClassName
3710
+ });
3711
+ }
3712
+ });
3713
+ break;
3714
+
3715
+ case 'text':
3716
+ case 'number':
3717
+ case 'url':
3718
+ default:
3719
+ input = jsx(Input, {
3720
+ rest: register(schema.accessor, schema.validations || {}),
3721
+ label: schema.label,
3722
+ error: (_f = (_e = errors[schema.accessor]) === null || _e === void 0 ? void 0 : _e.message) === null || _f === void 0 ? void 0 : _f.toString(),
3723
+ type: schema.type,
3724
+ className: "w-full p-2",
3725
+ placeholder: schema.placeholder,
3726
+ disabled: _isUpdating && typeof schema.editable !== 'undefined' && !schema.editable || !_enable,
3727
+ required: schema.required,
3728
+ onInput: schema.onInput,
3729
+ wrapperClassName: schema.wrapperClassName
3730
+ });
3731
+ break;
3732
+ }
3733
+ } else if (schema.Input) {
3734
+ input = jsxs("div", Object.assign({
3735
+ className: "kms_input-wrapper"
3736
+ }, {
3737
+ children: [jsx("label", Object.assign({
3738
+ className: "kms_input-label"
3739
+ }, {
3740
+ children: schema.label
3741
+ })), jsx(Controller, {
3742
+ control: control,
3743
+ name: schema.accessor,
3744
+ rules: schema.validations,
3745
+ render: ({
3746
+ field
3747
+ }) => {
3748
+ var _a, _b; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
3749
+
3750
+
3751
+ return schema.Input({
3752
+ field,
3753
+ error: (_b = (_a = errors[schema.accessor]) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.toString(),
3754
+ disabled: _isUpdating && typeof schema.editable !== 'undefined' && !schema.editable || !_enable,
3755
+ setError: msg => setError.call(null, schema.accessor, {
3756
+ type: 'custom',
3757
+ message: msg
3758
+ })
3759
+ });
3760
+ }
3761
+ })]
3762
+ }));
3763
+ } else throw new Error(`Please provide Input or type prop to render input Labeled ${schema.label}`);
3764
+
3765
+ return input;
3766
+ };
3767
+
3768
+ const onFormSubmit = e => __awaiter(void 0, void 0, void 0, function* () {
3769
+ e.preventDefault();
3770
+ handleSubmit(data => {
3771
+ const formattedData = schema.reduce((values, schemaItem) => {
3772
+ // Do not add field if editing is disabled for it
3773
+ if (_isUpdating && typeof schemaItem.editable !== 'undefined' && !schemaItem.editable) return values;
3774
+
3775
+ if (schemaItem.type === 'number') {
3776
+ values[schemaItem.accessor] = data[schemaItem.accessor] === '' ? null : parseInt(data[schemaItem.accessor]);
3777
+ } else values[schemaItem.accessor] = data[schemaItem.accessor];
3647
3778
 
3648
- useEffect(() => {
3649
- if (isEmpty(data)) {
3650
- const defaultValues = schema.reduce((values, schemaItem) => {
3651
- if (typeof schemaItem.defaultValue !== 'undefined') values[schemaItem.accessor] = schemaItem.defaultValue;
3652
3779
  return values;
3653
3780
  }, {});
3654
- reset(defaultValues);
3655
- }
3656
- }, [data, reset, schema]);
3781
+ onSubmit(formattedData);
3782
+ })();
3783
+ });
3657
3784
 
3785
+ return jsx("form", Object.assign({
3786
+ onSubmit: onFormSubmit,
3787
+ ref: ref,
3788
+ className: "khb-form-items"
3789
+ }, {
3790
+ children: schema.map((schema, i) => jsx(React.Fragment, {
3791
+ children: inputRenderer(schema)
3792
+ }, i))
3793
+ }));
3794
+ });
3795
+
3796
+ const SimpleForm = /*#__PURE__*/forwardRef(({
3797
+ schema,
3798
+ onSubmit,
3799
+ isUpdating: _isUpdating = false,
3800
+ enable: _enable = true,
3801
+ register,
3802
+ errors,
3803
+ handleSubmit,
3804
+ setValue,
3805
+ control,
3806
+ setError
3807
+ }, ref) => {
3658
3808
  const inputRenderer = schema => {
3659
3809
  var _a, _b, _c, _d, _e, _f;
3660
3810
 
@@ -3712,8 +3862,9 @@ const Form = /*#__PURE__*/forwardRef(({
3712
3862
  options: schema.options,
3713
3863
  label: schema.label,
3714
3864
  error: (_b = (_a = errors[schema.accessor]) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.toString(),
3715
- onChange: e => field.onChange(e.target.value),
3716
- value: field.value,
3865
+ // onChange={(e) => field.onChange(e.target.value)}
3866
+ rest: field,
3867
+ // value={field.value}
3717
3868
  className: "w-full",
3718
3869
  disabled: _isUpdating && typeof schema.editable !== 'undefined' && !schema.editable || !_enable,
3719
3870
  required: schema.required,
@@ -6613,6 +6764,18 @@ const TileItemsAccordian = ({
6613
6764
  const WidgetForm = ({
6614
6765
  formRef
6615
6766
  }) => {
6767
+ const {
6768
+ register,
6769
+ formState: {
6770
+ errors
6771
+ },
6772
+ handleSubmit,
6773
+ reset,
6774
+ setValue,
6775
+ control,
6776
+ watch,
6777
+ setError
6778
+ } = useForm();
6616
6779
  const {
6617
6780
  baseUrl,
6618
6781
  switchClass
@@ -6683,6 +6846,11 @@ const WidgetForm = ({
6683
6846
  setTilesEnabled(true);
6684
6847
  }
6685
6848
  }, [formState]);
6849
+ useEffect(() => {
6850
+ if (!isEmpty(data)) {
6851
+ reset(data);
6852
+ }
6853
+ }, [data, reset]);
6686
6854
 
6687
6855
  const onChangeSearch = str => {
6688
6856
  if (callerRef.current) clearTimeout(callerRef.current);
@@ -6747,8 +6915,14 @@ const WidgetForm = ({
6747
6915
  return temporaryData;
6748
6916
  });
6749
6917
  }
6750
- }; // Schemas
6918
+ };
6751
6919
 
6920
+ useEffect(() => {
6921
+ const subscription = watch((value, {
6922
+ name
6923
+ }) => onWidgetFormInputChange(value, name));
6924
+ return () => subscription.unsubscribe();
6925
+ }, [watch, onWidgetFormInputChange]); // Schemas
6752
6926
 
6753
6927
  const widgetFormSchema = [{
6754
6928
  label: `${t('widget.name')}`,
@@ -6911,13 +7085,17 @@ const WidgetForm = ({
6911
7085
  return jsxs("div", Object.assign({
6912
7086
  className: "khb_form"
6913
7087
  }, {
6914
- children: [jsx(Form, {
7088
+ children: [jsx(SimpleForm, {
6915
7089
  schema: widgetFormSchema,
6916
7090
  onSubmit: onFormSubmit,
6917
7091
  ref: formRef,
6918
- data: data,
6919
7092
  isUpdating: formState === 'UPDATE',
6920
- watcher: onWidgetFormInputChange
7093
+ register: register,
7094
+ errors: errors,
7095
+ handleSubmit: handleSubmit,
7096
+ setValue: setValue,
7097
+ control: control,
7098
+ setError: setError
6921
7099
  }), !tilesEnabled && jsx(DNDItemsList, {
6922
7100
  items: selectedCollectionItems,
6923
7101
  onDragEnd: onCollectionIndexChange,
@@ -0,0 +1,17 @@
1
+ import React, { MutableRefObject } from 'react';
2
+ import { CombineObjectType, SchemaType } from '../../../types';
3
+ interface SimpleFormProps {
4
+ schema: SchemaType[];
5
+ isUpdating?: boolean;
6
+ onSubmit: (data: CombineObjectType) => void;
7
+ enable?: boolean;
8
+ ref: MutableRefObject<HTMLFormElement | null>;
9
+ register: any;
10
+ errors: any;
11
+ handleSubmit: any;
12
+ setValue: any;
13
+ control: any;
14
+ setError: any;
15
+ }
16
+ declare const SimpleForm: React.ForwardRefExoticComponent<Pick<SimpleFormProps, "schema" | "onSubmit" | "isUpdating" | "enable" | "register" | "errors" | "handleSubmit" | "setValue" | "control" | "setError"> & React.RefAttributes<HTMLFormElement | null>>;
17
+ export default SimpleForm;
@@ -1,2 +1,4 @@
1
1
  import Form from "./Form";
2
+ import SimpleForm from "./SimpleForm";
2
3
  export default Form;
4
+ export { SimpleForm };
@@ -173,7 +173,6 @@ export interface SchemaType extends ReactSelectProps {
173
173
  label: string;
174
174
  }[];
175
175
  isMulti?: boolean;
176
- defaultValue?: string | number | boolean;
177
176
  placeholder?: string;
178
177
  required?: boolean;
179
178
  onChange?: (e: any) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knovator/pagecreator-admin",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "dependencies": {
5
5
  "classnames": "^2.3.1",
6
6
  "react-beautiful-dnd": "^13.1.0",