@bigbinary/neeto-form-frontend 1.0.6 → 1.0.8
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.js +75 -110
- package/dist/main.css +0 -10995
- package/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14,8 +14,10 @@ import require$$0$1 from 'os';
|
|
|
14
14
|
import require$$8 from 'zlib';
|
|
15
15
|
import require$$1$2 from 'path';
|
|
16
16
|
import require$$6 from 'fs';
|
|
17
|
-
import { reject, omit, insert, isEmpty, compose as compose$1, trim as trim$2, either, isNil, values as values$1, equals, not, times } from 'ramda';
|
|
17
|
+
import { assoc, prop, reject, omit, insert, isEmpty, compose as compose$1, trim as trim$2, either, isNil, values as values$1, equals, not, times } from 'ramda';
|
|
18
18
|
import { Input as Input$2, Textarea as Textarea$1, Checkbox, ActionBlock } from '@bigbinary/neetoui/formik';
|
|
19
|
+
import { withImmutableActions } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
20
|
+
import create$1 from 'zustand';
|
|
19
21
|
import classnames from 'classnames';
|
|
20
22
|
import { Up, Down, MenuHorizontal, Delete, Plus, Email as Email$1, Phone as Phone$1, Input as Input$3, NeetoInvisible, MultipleChoice as MultipleChoice$1, ListDot, Dropdown as Dropdown$2, Rating as Rating$2, Smiley, Calendar, Check, Close } from '@bigbinary/neeto-icons';
|
|
21
23
|
import { Editor as Editor$1, EditorContent } from '@bigbinary/neeto-editor';
|
|
@@ -3229,6 +3231,52 @@ const FormQueryClientProvider = _ref => {
|
|
|
3229
3231
|
}, children);
|
|
3230
3232
|
};
|
|
3231
3233
|
|
|
3234
|
+
const NeetoFormProvider = _ref => {
|
|
3235
|
+
let children = _ref.children;
|
|
3236
|
+
return /*#__PURE__*/React__default.createElement(FormQueryClientProvider, null, children);
|
|
3237
|
+
};
|
|
3238
|
+
|
|
3239
|
+
function _typeof$4(obj) {
|
|
3240
|
+
"@babel/helpers - typeof";
|
|
3241
|
+
|
|
3242
|
+
return _typeof$4 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
3243
|
+
return typeof obj;
|
|
3244
|
+
} : function (obj) {
|
|
3245
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
3246
|
+
}, _typeof$4(obj);
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3249
|
+
function _toPrimitive(input, hint) {
|
|
3250
|
+
if (_typeof$4(input) !== "object" || input === null) return input;
|
|
3251
|
+
var prim = input[Symbol.toPrimitive];
|
|
3252
|
+
if (prim !== undefined) {
|
|
3253
|
+
var res = prim.call(input, hint || "default");
|
|
3254
|
+
if (_typeof$4(res) !== "object") return res;
|
|
3255
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
3256
|
+
}
|
|
3257
|
+
return (hint === "string" ? String : Number)(input);
|
|
3258
|
+
}
|
|
3259
|
+
|
|
3260
|
+
function _toPropertyKey(arg) {
|
|
3261
|
+
var key = _toPrimitive(arg, "string");
|
|
3262
|
+
return _typeof$4(key) === "symbol" ? key : String(key);
|
|
3263
|
+
}
|
|
3264
|
+
|
|
3265
|
+
function _defineProperty$6(obj, key, value) {
|
|
3266
|
+
key = _toPropertyKey(key);
|
|
3267
|
+
if (key in obj) {
|
|
3268
|
+
Object.defineProperty(obj, key, {
|
|
3269
|
+
value: value,
|
|
3270
|
+
enumerable: true,
|
|
3271
|
+
configurable: true,
|
|
3272
|
+
writable: true
|
|
3273
|
+
});
|
|
3274
|
+
} else {
|
|
3275
|
+
obj[key] = value;
|
|
3276
|
+
}
|
|
3277
|
+
return obj;
|
|
3278
|
+
}
|
|
3279
|
+
|
|
3232
3280
|
function _arrayWithHoles$4(arr) {
|
|
3233
3281
|
if (Array.isArray(arr)) return arr;
|
|
3234
3282
|
}
|
|
@@ -3284,101 +3332,6 @@ function _slicedToArray$4(arr, i) {
|
|
|
3284
3332
|
return _arrayWithHoles$4(arr) || _iterableToArrayLimit$4(arr, i) || _unsupportedIterableToArray$f(arr, i) || _nonIterableRest$4();
|
|
3285
3333
|
}
|
|
3286
3334
|
|
|
3287
|
-
const buildFormReducer = function () {
|
|
3288
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3289
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
3290
|
-
switch (action.type) {
|
|
3291
|
-
case "SET_FORM_DATA":
|
|
3292
|
-
return action.payload;
|
|
3293
|
-
default:
|
|
3294
|
-
return state;
|
|
3295
|
-
}
|
|
3296
|
-
};
|
|
3297
|
-
|
|
3298
|
-
const BuildFormStateContext = /*#__PURE__*/React__default.createContext();
|
|
3299
|
-
const BuildFormDispatchContext = /*#__PURE__*/React__default.createContext();
|
|
3300
|
-
const initialState = {
|
|
3301
|
-
values: {},
|
|
3302
|
-
dirty: false,
|
|
3303
|
-
isSubmitting: false,
|
|
3304
|
-
isValid: true,
|
|
3305
|
-
errors: [],
|
|
3306
|
-
submitForm: () => {},
|
|
3307
|
-
resetForm: () => {}
|
|
3308
|
-
};
|
|
3309
|
-
const BuildFormProvider = _ref => {
|
|
3310
|
-
let children = _ref.children;
|
|
3311
|
-
const _React$useReducer = React__default.useReducer(buildFormReducer, initialState),
|
|
3312
|
-
_React$useReducer2 = _slicedToArray$4(_React$useReducer, 2),
|
|
3313
|
-
state = _React$useReducer2[0],
|
|
3314
|
-
dispatch = _React$useReducer2[1];
|
|
3315
|
-
return /*#__PURE__*/React__default.createElement(BuildFormStateContext.Provider, {
|
|
3316
|
-
value: state
|
|
3317
|
-
}, /*#__PURE__*/React__default.createElement(BuildFormDispatchContext.Provider, {
|
|
3318
|
-
value: dispatch
|
|
3319
|
-
}, children));
|
|
3320
|
-
};
|
|
3321
|
-
const useBuildFormState = () => {
|
|
3322
|
-
const context = React__default.useContext(BuildFormStateContext);
|
|
3323
|
-
if (context === undefined) {
|
|
3324
|
-
throw new Error("useBuildFormState must be used within a BuildFormProvider");
|
|
3325
|
-
}
|
|
3326
|
-
return context;
|
|
3327
|
-
};
|
|
3328
|
-
const useBuildFormDispatch = () => {
|
|
3329
|
-
const context = React__default.useContext(BuildFormDispatchContext);
|
|
3330
|
-
if (context === undefined) {
|
|
3331
|
-
throw new Error("useBuildFormDispatch must be used within a BuildFormProvider");
|
|
3332
|
-
}
|
|
3333
|
-
return context;
|
|
3334
|
-
};
|
|
3335
|
-
|
|
3336
|
-
const NeetoFormProvider = _ref => {
|
|
3337
|
-
let children = _ref.children;
|
|
3338
|
-
return /*#__PURE__*/React__default.createElement(FormQueryClientProvider, null, /*#__PURE__*/React__default.createElement(BuildFormProvider, null, children));
|
|
3339
|
-
};
|
|
3340
|
-
|
|
3341
|
-
function _typeof$4(obj) {
|
|
3342
|
-
"@babel/helpers - typeof";
|
|
3343
|
-
|
|
3344
|
-
return _typeof$4 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
3345
|
-
return typeof obj;
|
|
3346
|
-
} : function (obj) {
|
|
3347
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
3348
|
-
}, _typeof$4(obj);
|
|
3349
|
-
}
|
|
3350
|
-
|
|
3351
|
-
function _toPrimitive(input, hint) {
|
|
3352
|
-
if (_typeof$4(input) !== "object" || input === null) return input;
|
|
3353
|
-
var prim = input[Symbol.toPrimitive];
|
|
3354
|
-
if (prim !== undefined) {
|
|
3355
|
-
var res = prim.call(input, hint || "default");
|
|
3356
|
-
if (_typeof$4(res) !== "object") return res;
|
|
3357
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
3358
|
-
}
|
|
3359
|
-
return (hint === "string" ? String : Number)(input);
|
|
3360
|
-
}
|
|
3361
|
-
|
|
3362
|
-
function _toPropertyKey(arg) {
|
|
3363
|
-
var key = _toPrimitive(arg, "string");
|
|
3364
|
-
return _typeof$4(key) === "symbol" ? key : String(key);
|
|
3365
|
-
}
|
|
3366
|
-
|
|
3367
|
-
function _defineProperty$6(obj, key, value) {
|
|
3368
|
-
key = _toPropertyKey(key);
|
|
3369
|
-
if (key in obj) {
|
|
3370
|
-
Object.defineProperty(obj, key, {
|
|
3371
|
-
value: value,
|
|
3372
|
-
enumerable: true,
|
|
3373
|
-
configurable: true,
|
|
3374
|
-
writable: true
|
|
3375
|
-
});
|
|
3376
|
-
} else {
|
|
3377
|
-
obj[key] = value;
|
|
3378
|
-
}
|
|
3379
|
-
return obj;
|
|
3380
|
-
}
|
|
3381
|
-
|
|
3382
3335
|
const QUERY_KEYS = {
|
|
3383
3336
|
QUESTIONS: "questions",
|
|
3384
3337
|
SUBMISSIONS: "submissions",
|
|
@@ -30666,6 +30619,21 @@ function useTranslation(ns) {
|
|
|
30666
30619
|
});
|
|
30667
30620
|
}
|
|
30668
30621
|
|
|
30622
|
+
/** @type {import("neetocommons/react-utils").ZustandStoreHook} */
|
|
30623
|
+
const useBuildFormStore = create$1(withImmutableActions(set => ({
|
|
30624
|
+
formState: {
|
|
30625
|
+
values: {},
|
|
30626
|
+
dirty: false,
|
|
30627
|
+
isSubmitting: false,
|
|
30628
|
+
isValid: true,
|
|
30629
|
+
errors: [],
|
|
30630
|
+
submitForm: () => {},
|
|
30631
|
+
resetForm: () => {}
|
|
30632
|
+
},
|
|
30633
|
+
setFormData: payload => set(assoc("formState", payload))
|
|
30634
|
+
})));
|
|
30635
|
+
const useBuildFormState = () => useBuildFormStore(prop("formState"));
|
|
30636
|
+
|
|
30669
30637
|
const ListItem = _ref => {
|
|
30670
30638
|
let _ref$icon = _ref.icon,
|
|
30671
30639
|
Icon = _ref$icon === void 0 ? null : _ref$icon,
|
|
@@ -35435,22 +35403,19 @@ const Form = _ref => {
|
|
|
35435
35403
|
errors = formikContext.errors,
|
|
35436
35404
|
submitForm = formikContext.submitForm,
|
|
35437
35405
|
resetForm = formikContext.resetForm;
|
|
35438
|
-
const
|
|
35406
|
+
const setFormData = useBuildFormStore(prop("setFormData"));
|
|
35439
35407
|
useEffect(() => {
|
|
35440
|
-
|
|
35441
|
-
|
|
35442
|
-
|
|
35443
|
-
|
|
35444
|
-
|
|
35445
|
-
|
|
35446
|
-
|
|
35447
|
-
|
|
35448
|
-
|
|
35449
|
-
resetForm,
|
|
35450
|
-
setShouldValidate
|
|
35451
|
-
}
|
|
35408
|
+
setFormData({
|
|
35409
|
+
values,
|
|
35410
|
+
dirty,
|
|
35411
|
+
isSubmitting,
|
|
35412
|
+
isValid,
|
|
35413
|
+
errors,
|
|
35414
|
+
submitForm,
|
|
35415
|
+
resetForm,
|
|
35416
|
+
setShouldValidate
|
|
35452
35417
|
});
|
|
35453
|
-
}, [formId,
|
|
35418
|
+
}, [formId, setFormData, values, dirty, isSubmitting, isValid, errors, submitForm, resetForm, setShouldValidate]);
|
|
35454
35419
|
const questions = values.questions;
|
|
35455
35420
|
useEffect(() => {
|
|
35456
35421
|
onValueChange?.(questions);
|