@bigbinary/neeto-form-frontend 1.2.56 → 1.3.1

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 CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as React$2 from 'react';
2
2
  import React__default, { useState, useRef, useEffect, useContext, useLayoutEffect as useLayoutEffect$1, forwardRef, useImperativeHandle, Fragment, useReducer, useCallback as useCallback$1, useMemo as useMemo$1, createContext, createElement } from 'react';
3
3
  import { useFormikContext, useField, FieldArray, Form as Form$1, Formik, Field, FastField } from 'formik';
4
- import { noop as noop$4, findBy, slugify, filterBy, isNotEmpty, truncate, humanize, removeBy, isPresent as isPresent$1, isNotPresent, findById, notEqualsDeep } from '@bigbinary/neeto-cist';
5
- import { withEventTargetValue, showThumbsUpToastr, getQueryParams, dateFormat } from '@bigbinary/neeto-commons-frontend/utils';
4
+ import { noop as noop$4, findBy, slugify, toLabelAndValue, filterBy, isNotEmpty, truncate, humanize, removeBy, isPresent as isPresent$1, isNotPresent, findById, notEqualsDeep } from '@bigbinary/neeto-cist';
5
+ import { showThumbsUpToastr, withEventTargetValue, getQueryParams, dateFormat } from '@bigbinary/neeto-commons-frontend/utils';
6
6
  import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
7
- import { Tooltip, Dropdown as Dropdown$2, Alert, Typography, Button as Button$1, Label, Checkbox as Checkbox$1, Toastr, MultiEmailInput, DatePicker, Input as Input$2, Radio as Radio$1, Select, Textarea as Textarea$1, Spinner as Spinner$2 } from '@bigbinary/neetoui';
8
- import { assoc, mergeLeft, prop, isEmpty, path, values, compose as compose$1, trim, useWith, split, either, isNil, equals, difference, reject, pluck, keys, pick, omit, isNotNil, insert, not, pipe as pipe$1, toLower, map, includes, identity, times, clamp as clamp$2, filter as filter$1 } from 'ramda';
7
+ import { Tooltip, Dropdown as Dropdown$2, Alert, Typography, Button as Button$1, Label, Checkbox as Checkbox$1, Toastr, MultiEmailInput, DatePicker, Input as Input$2, Radio as Radio$1, Select as Select$1, Textarea as Textarea$1, Spinner as Spinner$2 } from '@bigbinary/neetoui';
8
+ import { assoc, mergeLeft, compose as compose$1, isEmpty, trim, useWith, path, split, either, isNil, values, equals, modify, prop, range, difference, without, reject, pluck, keys, pick, omit, includes, __, isNotNil, insert, not, pipe as pipe$1, toLower, map, identity, clamp as clamp$2, filter as filter$1 } from 'ramda';
9
9
  import { useQuery, useQueryClient, useMutation } from 'react-query';
10
10
  import i18next, { t as t$4 } from 'i18next';
11
11
  import { Input, Email as Email$2, Phone as Phone$2, Globe, Up, Down, MenuHorizontal, Delete, Plus, NeetoInvisible, Checkbox as Checkbox$2, Radio, Dropdown as Dropdown$3, Rating as Rating$4, Smiley, Calendar, Upload, Check, Close, FileGeneric } from '@bigbinary/neeto-icons';
@@ -13,13 +13,14 @@ import { DEFAULT_PAGE_INDEX, DEFAULT_PAGE_SIZE } from '@bigbinary/neeto-commons-
13
13
  import { useMutationWithInvalidation, withImmutableActions, withT, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
14
14
  import axios from 'axios';
15
15
  import ReactDOM, { unstable_batchedUpdates, flushSync as flushSync$1 } from 'react-dom';
16
- import { Input as Input$1, Textarea, Checkbox, ActionBlock } from '@bigbinary/neetoui/formik';
16
+ import { Input as Input$1, Textarea, Checkbox, Select, ActionBlock } from '@bigbinary/neetoui/formik';
17
17
  import { useTranslation, Trans } from 'react-i18next';
18
18
  import { create as create$1 } from 'zustand';
19
19
  import classnames from 'classnames';
20
+ import { Editor as Editor$1, isEditorEmpty, EditorContent } from '@bigbinary/neeto-editor';
21
+ import { shallow } from 'zustand/shallow';
20
22
  import * as yup from 'yup';
21
23
  import { object, array, string } from 'yup';
22
- import { Editor as Editor$1, isEditorEmpty, EditorContent } from '@bigbinary/neeto-editor';
23
24
  import useHotkeys from '@bigbinary/neeto-hotkeys';
24
25
  import dayjs from 'dayjs';
25
26
  import { validation, PhoneNumberInput, PhoneNumber as PhoneNumber$1 } from '@bigbinary/neeto-molecules/PhoneNumber';
@@ -769,6 +770,7 @@ var QUESTIONS_INITIAL_VALUE = {
769
770
  };
770
771
  var RESERVED_FIELD_CODES = ["month", "date", "time"];
771
772
  var SELECTABLE_KINDS = ["radio", "checkbox", "dropdown"];
773
+ var RICH_TEXT_QUESTIONS = ["paragraph", "termsandcondition"];
772
774
 
773
775
  function _arrayWithHoles$3(arr) {
774
776
  if (Array.isArray(arr)) return arr;
@@ -9804,6 +9806,28 @@ var formHelpers = {
9804
9806
  pushToList: pushToList
9805
9807
  };
9806
9808
 
9809
+ var isBlank = compose$1(isEmpty, trim);
9810
+ var parseServerError = function parseServerError(error) {
9811
+ var _error$notice;
9812
+ return (_error$notice = error.notice) !== null && _error$notice !== void 0 ? _error$notice : t$4("neetoForm.common.somethingWentWrong");
9813
+ };
9814
+ var isEmptyValues = function isEmptyValues(obj) {
9815
+ return either(isNil, isEmpty)(obj) ? true : values(obj).every(function (value) {
9816
+ if (isEmpty(value)) {
9817
+ return true;
9818
+ } else if (Array.isArray(value)) {
9819
+ return equals([false, false, false], value);
9820
+ }
9821
+ return !value;
9822
+ });
9823
+ };
9824
+
9825
+ // eslint-disable-next-line react-hooks/rules-of-hooks
9826
+ var dotPath = useWith(path, [split(".")]);
9827
+ var isFunction$1 = function isFunction(obj) {
9828
+ return typeof obj === "function";
9829
+ };
9830
+
9807
9831
  /** @type {import("neetocommons/react-utils").ZustandStoreHook} */
9808
9832
  var useBuildFormStore = create$1(withImmutableActions(function (set) {
9809
9833
  return {
@@ -9818,10 +9842,11 @@ var useBuildFormStore = create$1(withImmutableActions(function (set) {
9818
9842
  selectedLanguage: i18next.resolvedLanguage,
9819
9843
  formId: null,
9820
9844
  enabled: false,
9821
- title: ""
9845
+ title: "",
9846
+ richTextFieldsToReset: []
9822
9847
  },
9823
- setFormData: function setFormData(payload) {
9824
- return set(assoc("formState", payload));
9848
+ setFormData: function setFormData(arg) {
9849
+ return set(modify("formState", isFunction$1(arg) ? arg : mergeLeft(arg)));
9825
9850
  }
9826
9851
  };
9827
9852
  }));
@@ -10039,7 +10064,8 @@ var Accordion = function Accordion(_ref) {
10039
10064
  showAddQuestionDivider = _ref.showAddQuestionDivider,
10040
10065
  isDeletable = _ref.isDeletable,
10041
10066
  kindUniqueOn = _ref.kindUniqueOn,
10042
- disabledAddButtonTooltipProps = _ref.disabledAddButtonTooltipProps;
10067
+ disabledAddButtonTooltipProps = _ref.disabledAddButtonTooltipProps,
10068
+ dragHandleProps = _ref.dragHandleProps;
10043
10069
  var _useState = useState(false),
10044
10070
  _useState2 = _slicedToArray$3(_useState, 2),
10045
10071
  isAddQuestionOpen = _useState2[0],
@@ -10053,14 +10079,14 @@ var Accordion = function Accordion(_ref) {
10053
10079
  className: classnames("neeto-form-engine-question-accordion relative", {
10054
10080
  "pr-4 md:pr-8": showAddQuestionDivider
10055
10081
  })
10056
- }, /*#__PURE__*/React__default.createElement("div", {
10082
+ }, /*#__PURE__*/React__default.createElement("div", _extends$8({
10057
10083
  "data-cy": "neeto-form-engine-question-accordion-header",
10058
10084
  className: classnames({
10059
10085
  "neeto-form-engine-question-accordion__header flex h-10 cursor-pointer select-none items-center justify-between px-3 py-2": true,
10060
10086
  "neeto-ui-text-gray-700 border": !isExpanded,
10061
10087
  "neeto-ui-bg-gray-800 neeto-ui-text-white rounded-b-none": isExpanded
10062
10088
  })
10063
- }, /*#__PURE__*/React__default.createElement("div", {
10089
+ }, dragHandleProps), /*#__PURE__*/React__default.createElement("div", {
10064
10090
  className: "neeto-form-engine-question-accordion__header-left flex items-center overflow-hidden"
10065
10091
  }, /*#__PURE__*/React__default.createElement("div", {
10066
10092
  className: "flex w-8 items-center"
@@ -10264,6 +10290,39 @@ var Condition$1 = function Condition(_ref) {
10264
10290
  })));
10265
10291
  };
10266
10292
 
10293
+ var getActiveQuestionKindDetails = function getActiveQuestionKindDetails(_ref) {
10294
+ var allQuestionKinds = _ref.allQuestionKinds,
10295
+ item = _ref.item;
10296
+ var kind = item.kind,
10297
+ label = item.label;
10298
+ var _findBy = findBy({
10299
+ type: kind
10300
+ }, allQuestionKinds),
10301
+ FieldComponent = _findBy.component,
10302
+ FieldIcon = _findBy.icon,
10303
+ isSingular = _findBy.isSingular;
10304
+ return {
10305
+ kind: kind,
10306
+ label: label,
10307
+ FieldComponent: FieldComponent,
10308
+ FieldIcon: FieldIcon,
10309
+ isSingular: isSingular
10310
+ };
10311
+ };
10312
+ var generateArray = function generateArray(start, end) {
10313
+ return range(start, end + 1);
10314
+ };
10315
+
10316
+ var validateEditorContent = function validateEditorContent(editorRef) {
10317
+ return function () {
10318
+ var _editorRef$current;
10319
+ return (_editorRef$current = editorRef.current) !== null && _editorRef$current !== void 0 && (_editorRef$current = _editorRef$current.editor) !== null && _editorRef$current !== void 0 && _editorRef$current.isEmpty ? t$4("neetoForm.common.thisFieldIsRequired") : "";
10320
+ };
10321
+ };
10322
+ var generateRatingOptions = function generateRatingOptions(range) {
10323
+ return generateArray.apply(void 0, _toConsumableArray$1(range)).map(toLabelAndValue);
10324
+ };
10325
+
10267
10326
  var _FILE_TYPES_MAP;
10268
10327
  var FILE_TYPES = {
10269
10328
  DOCUMENTS: "documents",
@@ -10280,6 +10339,8 @@ var STAR_RATING_ICONS_MAP = {
10280
10339
  trophy: MemoizedTrophy,
10281
10340
  zap: MemoizedZap
10282
10341
  };
10342
+ var STAR_RATING_MAX_VALUE_OPTIONS = generateRatingOptions([3, 10]);
10343
+ var STAR_RATING_MIN_VALUE_OPTIONS = generateRatingOptions([0, 1]);
10283
10344
  var FILE_TYPES_MAP = (_FILE_TYPES_MAP = {}, _defineProperty$6(_FILE_TYPES_MAP, FILE_TYPES.DOCUMENTS, ["pdf", "doc", "docx", "xls", "xlsx", "csv", "txt", "rtf", "html", "zip", "md"]), _defineProperty$6(_FILE_TYPES_MAP, FILE_TYPES.IMAGES, ["jpg", "jpeg", "png", "gif"]), _defineProperty$6(_FILE_TYPES_MAP, FILE_TYPES.AUDIO_VIDEO, ["mp3", "wma", "mpg", "flv", "avi"]), _FILE_TYPES_MAP);
10284
10345
  var DEFAULT_ALLOWED_FILE_TYPES = values(FILE_TYPES_MAP).flat().join(", ");
10285
10346
  var FILE_GROUPS = [{
@@ -10292,8 +10353,6 @@ var FILE_GROUPS = [{
10292
10353
  label: t$4("neetoForm.fileTypes.audioVideo"),
10293
10354
  name: FILE_TYPES.AUDIO_VIDEO
10294
10355
  }];
10295
- var STAR_RATING_MIN_COUNT = 0;
10296
- var STAR_RATING_MAX_COUNT = 10;
10297
10356
 
10298
10357
  var Dropdown$1 = function Dropdown(_ref) {
10299
10358
  var item = _ref.item,
@@ -10421,25 +10480,6 @@ var Email$1 = withT(function (_ref) {
10421
10480
  }));
10422
10481
  });
10423
10482
 
10424
- var isBlank = compose$1(isEmpty, trim);
10425
- var parseServerError = function parseServerError(error) {
10426
- var _error$notice;
10427
- return (_error$notice = error.notice) !== null && _error$notice !== void 0 ? _error$notice : t$4("neetoForm.common.somethingWentWrong");
10428
- };
10429
- var isEmptyValues = function isEmptyValues(obj) {
10430
- return either(isNil, isEmpty)(obj) ? true : values(obj).every(function (value) {
10431
- if (isEmpty(value)) {
10432
- return true;
10433
- } else if (Array.isArray(value)) {
10434
- return equals([false, false, false], value);
10435
- }
10436
- return !value;
10437
- });
10438
- };
10439
-
10440
- // eslint-disable-next-line react-hooks/rules-of-hooks
10441
- var dotPath = useWith(path, [split(".")]);
10442
-
10443
10483
  var FileGroup = function FileGroup(_ref) {
10444
10484
  var name = _ref.name,
10445
10485
  label = _ref.label,
@@ -10944,32 +10984,6 @@ var SingleChoice$1 = function SingleChoice(_ref) {
10944
10984
  }));
10945
10985
  };
10946
10986
 
10947
- var validateEditorContent = function validateEditorContent(editorRef) {
10948
- return function () {
10949
- var _editorRef$current;
10950
- return (_editorRef$current = editorRef.current) !== null && _editorRef$current !== void 0 && (_editorRef$current = _editorRef$current.editor) !== null && _editorRef$current !== void 0 && _editorRef$current.isEmpty ? t$4("neetoForm.common.thisFieldIsRequired") : "";
10951
- };
10952
- };
10953
- var validateStarRatingCount = function validateStarRatingCount(value) {
10954
- try {
10955
- var schema = yup.number().integer().transform(function (value) {
10956
- return isNaN(value) ? null : value;
10957
- }).min(STAR_RATING_MIN_COUNT, t$4("neetoForm.error.minCount", {
10958
- field: t$4("neetoForm.common.count"),
10959
- value: STAR_RATING_MIN_COUNT
10960
- })).max(STAR_RATING_MAX_COUNT, t$4("neetoForm.error.maxCount", {
10961
- field: t$4("neetoForm.common.count"),
10962
- value: STAR_RATING_MAX_COUNT
10963
- })).nullable().required(t$4("neetoForm.common.fieldReq", {
10964
- field: t$4("neetoForm.common.count")
10965
- }));
10966
- schema.validateSync(value);
10967
- return undefined;
10968
- } catch (error) {
10969
- return error.message;
10970
- }
10971
- };
10972
-
10973
10987
  var StarRating$3 = function StarRating(_ref) {
10974
10988
  var name = _ref.name,
10975
10989
  isRequired = _ref.isRequired,
@@ -10977,21 +10991,13 @@ var StarRating$3 = function StarRating(_ref) {
10977
10991
  enableFieldCode = _ref.enableFieldCode;
10978
10992
  var _useTranslation = useTranslation(),
10979
10993
  t = _useTranslation.t;
10980
- var _useField = useField("".concat(name, ".shape")),
10994
+ var _useFormikContext = useFormikContext(),
10995
+ setFieldValue = _useFormikContext.setFieldValue;
10996
+ var _useField = useField("".concat(name, ".iconType")),
10981
10997
  _useField2 = _slicedToArray$3(_useField, 3),
10982
- shape = _useField2[0].value;
10998
+ iconType = _useField2[0].value;
10983
10999
  _useField2[1];
10984
- var setShape = _useField2[2].setValue;
10985
- var _useField3 = useField({
10986
- name: "".concat(name, ".count"),
10987
- validate: validateStarRatingCount
10988
- }),
10989
- _useField4 = _slicedToArray$3(_useField3, 3),
10990
- countField = _useField4[0],
10991
- _useField4$ = _useField4[1],
10992
- countTouched = _useField4$.touched,
10993
- countError = _useField4$.error,
10994
- setCount = _useField4[2].setValue;
11000
+ var setIconType = _useField2[2].setValue;
10995
11001
  return /*#__PURE__*/React__default.createElement("div", {
10996
11002
  className: "space-y-4"
10997
11003
  }, /*#__PURE__*/React__default.createElement("div", {
@@ -11002,22 +11008,31 @@ var StarRating$3 = function StarRating(_ref) {
11002
11008
  label: t("neetoForm.questions.common.questionFields.field.question"),
11003
11009
  name: "".concat(name, ".label"),
11004
11010
  rows: 1
11005
- })), /*#__PURE__*/React__default.createElement(InputWithMaxLength, _extends$8({
11006
- required: true
11007
- }, countField, {
11008
- error: countTouched ? countError : "",
11009
- label: t("neetoForm.common.count"),
11010
- max: STAR_RATING_MAX_COUNT,
11011
- min: STAR_RATING_MIN_COUNT,
11012
- type: "number",
11013
- onChange: withEventTargetValue(setCount)
11014
- })), /*#__PURE__*/React__default.createElement(Label, null, t("neetoForm.common.icon")), /*#__PURE__*/React__default.createElement("div", {
11011
+ })), /*#__PURE__*/React__default.createElement("div", {
11012
+ className: "flex space-x-4"
11013
+ }, /*#__PURE__*/React__default.createElement(Select, {
11014
+ className: "w-1/2",
11015
+ label: t("neetoForm.common.start"),
11016
+ name: "".concat(name, ".minValue"),
11017
+ options: STAR_RATING_MIN_VALUE_OPTIONS,
11018
+ onChange: function onChange(option) {
11019
+ return setFieldValue("".concat(name, ".minValue"), option === null || option === void 0 ? void 0 : option.value);
11020
+ }
11021
+ }), /*#__PURE__*/React__default.createElement(Select, {
11022
+ className: "w-1/2",
11023
+ label: t("neetoForm.common.end"),
11024
+ name: "".concat(name, ".maxValue"),
11025
+ options: STAR_RATING_MAX_VALUE_OPTIONS,
11026
+ onChange: function onChange(option) {
11027
+ return setFieldValue("".concat(name, ".maxValue"), option === null || option === void 0 ? void 0 : option.value);
11028
+ }
11029
+ })), /*#__PURE__*/React__default.createElement(Label, null, t("neetoForm.common.shape")), /*#__PURE__*/React__default.createElement("div", {
11015
11030
  className: "flex gap-2"
11016
11031
  }, Object.entries(STAR_RATING_ICONS_MAP).map(function (_ref2) {
11017
11032
  var _ref3 = _slicedToArray$3(_ref2, 2),
11018
11033
  name = _ref3[0],
11019
- Shape = _ref3[1];
11020
- var isActive = name === shape;
11034
+ IconType = _ref3[1];
11035
+ var isActive = name === iconType;
11021
11036
  return /*#__PURE__*/React__default.createElement("div", {
11022
11037
  key: name,
11023
11038
  className: classnames("flex h-10 w-10 items-center justify-center gap-2", "neeto-ui-border-gray-800 neeto-ui-rounded-full cursor-pointer border", "transition-all duration-300 ease-in-out", {
@@ -11025,9 +11040,9 @@ var StarRating$3 = function StarRating(_ref) {
11025
11040
  "neeto-ui-text-white neeto-ui-bg-gray-800": isActive
11026
11041
  }),
11027
11042
  onClick: function onClick() {
11028
- return setShape(name);
11043
+ return setIconType(name);
11029
11044
  }
11030
- }, /*#__PURE__*/React__default.createElement(Shape, null));
11045
+ }, /*#__PURE__*/React__default.createElement(IconType, null));
11031
11046
  })), !isRequired && /*#__PURE__*/React__default.createElement("div", {
11032
11047
  className: "w-full"
11033
11048
  }, /*#__PURE__*/React__default.createElement(Checkbox, {
@@ -11039,18 +11054,42 @@ var StarRating$3 = function StarRating(_ref) {
11039
11054
  }));
11040
11055
  };
11041
11056
 
11042
- var useUpdateEditorContent = function useUpdateEditorContent(editorRef, fieldName, value) {
11057
+ var useUpdateEditorContent = function useUpdateEditorContent(_ref) {
11058
+ var editorRef = _ref.editorRef,
11059
+ fieldName = _ref.fieldName,
11060
+ value = _ref.value,
11061
+ initialValue = _ref.initialValue,
11062
+ fieldCode = _ref.fieldCode;
11043
11063
  var initialStateRef = useRef({
11044
11064
  language: "",
11045
11065
  value: null
11046
11066
  });
11047
- var _useBuildFormState = useBuildFormState(),
11048
- formId = _useBuildFormState.formId,
11049
- language = _useBuildFormState.selectedLanguage;
11067
+ var _useBuildFormStore = useBuildFormStore(function (store) {
11068
+ return {
11069
+ setFormData: store["setFormData"]
11070
+ };
11071
+ }, shallow),
11072
+ setFormData = _useBuildFormStore.setFormData;
11073
+ var _useBuildFormStore2 = useBuildFormStore(function (store) {
11074
+ var _store$formState, _store$formState2;
11075
+ return {
11076
+ formId: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["formId"],
11077
+ selectedLanguage: (_store$formState2 = store["formState"]) === null || _store$formState2 === void 0 ? void 0 : _store$formState2["selectedLanguage"]
11078
+ };
11079
+ }, shallow),
11080
+ formId = _useBuildFormStore2.formId,
11081
+ language = _useBuildFormStore2.selectedLanguage;
11082
+ var shouldReset = useBuildFormStore(function (store) {
11083
+ return store.formState.richTextFieldsToReset.includes(fieldCode);
11084
+ });
11050
11085
  var setEditorContent = function setEditorContent(content) {
11051
11086
  var _editorRef$current$ed;
11052
11087
  return (_editorRef$current$ed = editorRef.current.editor) === null || _editorRef$current$ed === void 0 || (_editorRef$current$ed = _editorRef$current$ed.commands) === null || _editorRef$current$ed === void 0 ? void 0 : _editorRef$current$ed.setContent(content);
11053
11088
  };
11089
+ if (shouldReset) {
11090
+ setEditorContent(initialValue);
11091
+ setFormData(modify("richTextFieldsToReset", without([fieldCode])));
11092
+ }
11054
11093
  useEffect(function () {
11055
11094
  if (initialStateRef.current["language"] !== language) {
11056
11095
  initialStateRef.current["language"] = language;
@@ -11077,11 +11116,13 @@ var useUpdateEditorContent = function useUpdateEditorContent(editorRef, fieldNam
11077
11116
 
11078
11117
  var Terms$1 = function Terms(_ref) {
11079
11118
  var name = _ref.name,
11119
+ item = _ref.item,
11080
11120
  isLabelDisabled = _ref.isLabelDisabled;
11081
11121
  var editorRef = useRef({
11082
11122
  editor: {}
11083
11123
  });
11084
11124
  var fieldName = "".concat(name, ".label");
11125
+ var fieldCode = item.fieldCode;
11085
11126
  var _useField = useField({
11086
11127
  name: fieldName,
11087
11128
  validate: validateEditorContent(editorRef)
@@ -11091,10 +11132,17 @@ var Terms$1 = function Terms(_ref) {
11091
11132
  _useField2$ = _useField2[1],
11092
11133
  touched = _useField2$.touched,
11093
11134
  error = _useField2$.error,
11135
+ initialValue = _useField2$.initialValue,
11094
11136
  _useField2$2 = _useField2[2],
11095
11137
  setTouched = _useField2$2.setTouched,
11096
11138
  setValue = _useField2$2.setValue;
11097
- useUpdateEditorContent(editorRef, fieldName, value);
11139
+ useUpdateEditorContent({
11140
+ editorRef: editorRef,
11141
+ fieldName: fieldName,
11142
+ value: value,
11143
+ initialValue: initialValue,
11144
+ fieldCode: fieldCode
11145
+ });
11098
11146
  return /*#__PURE__*/React__default.createElement("div", {
11099
11147
  className: "w-full cursor-auto"
11100
11148
  }, /*#__PURE__*/React__default.createElement(Editor$1, {
@@ -11136,11 +11184,13 @@ var Fields = {
11136
11184
 
11137
11185
  var Editor = function Editor(_ref) {
11138
11186
  var name = _ref.name,
11187
+ item = _ref.item,
11139
11188
  isLabelDisabled = _ref.isLabelDisabled;
11140
11189
  var editorRef = useRef({
11141
11190
  editor: {}
11142
11191
  });
11143
11192
  var fieldName = "".concat(name, ".label");
11193
+ var fieldCode = item.fieldCode;
11144
11194
  var _useField = useField({
11145
11195
  name: fieldName,
11146
11196
  validate: validateEditorContent(editorRef)
@@ -11150,10 +11200,17 @@ var Editor = function Editor(_ref) {
11150
11200
  _useField2$ = _useField2[1],
11151
11201
  touched = _useField2$.touched,
11152
11202
  error = _useField2$.error,
11203
+ initialValue = _useField2$.initialValue,
11153
11204
  _useField2$2 = _useField2[2],
11154
11205
  setTouched = _useField2$2.setTouched,
11155
11206
  setValue = _useField2$2.setValue;
11156
- useUpdateEditorContent(editorRef, fieldName, value);
11207
+ useUpdateEditorContent({
11208
+ editorRef: editorRef,
11209
+ fieldName: fieldName,
11210
+ value: value,
11211
+ initialValue: initialValue,
11212
+ fieldCode: fieldCode
11213
+ });
11157
11214
  return /*#__PURE__*/React__default.createElement("div", {
11158
11215
  className: "w-full cursor-auto"
11159
11216
  }, /*#__PURE__*/React__default.createElement(Editor$1, {
@@ -11334,8 +11391,9 @@ var QUESTION_KINDS = [{
11334
11391
  defaults: {
11335
11392
  label: "",
11336
11393
  isRequired: true,
11337
- count: 5,
11338
- shape: "star"
11394
+ minValue: 1,
11395
+ maxValue: 5,
11396
+ iconType: "star"
11339
11397
  }
11340
11398
  }, {
11341
11399
  type: "rating",
@@ -11419,7 +11477,8 @@ var FormField = function FormField(props) {
11419
11477
  allQuestionKinds = props.allQuestionKinds,
11420
11478
  getActiveKindDetails = props.getActiveKindDetails,
11421
11479
  kindUniqueOn = props.kindUniqueOn,
11422
- disabledAddButtonTooltipProps = props.disabledAddButtonTooltipProps;
11480
+ disabledAddButtonTooltipProps = props.disabledAddButtonTooltipProps,
11481
+ dragHandleProps = props.dragHandleProps;
11423
11482
  var _getActiveKindDetails = getActiveKindDetails({
11424
11483
  allQuestionKinds: allQuestionKinds,
11425
11484
  item: item
@@ -11431,6 +11490,7 @@ var FormField = function FormField(props) {
11431
11490
  isSingular = _getActiveKindDetails.isSingular;
11432
11491
  return /*#__PURE__*/React__default.createElement(Accordion, {
11433
11492
  disabledAddButtonTooltipProps: disabledAddButtonTooltipProps,
11493
+ dragHandleProps: dragHandleProps,
11434
11494
  isDeletable: isDeletable,
11435
11495
  isExpanded: isExpanded,
11436
11496
  kindUniqueOn: kindUniqueOn,
@@ -11479,11 +11539,12 @@ var Question = function Question(_ref) {
11479
11539
  var draggableProps = _ref3.draggableProps,
11480
11540
  dragHandleProps = _ref3.dragHandleProps,
11481
11541
  innerRef = _ref3.innerRef;
11482
- return /*#__PURE__*/React__default.createElement("div", _extends$8({}, draggableProps, dragHandleProps, {
11542
+ return /*#__PURE__*/React__default.createElement("div", _extends$8({}, draggableProps, {
11483
11543
  ref: innerRef
11484
11544
  }), /*#__PURE__*/React__default.createElement(FormField, _extends$8({
11485
11545
  allQuestionKinds: allQuestionKinds,
11486
11546
  disabledAddButtonTooltipProps: disabledAddButtonTooltipProps,
11547
+ dragHandleProps: dragHandleProps,
11487
11548
  getActiveKindDetails: getActiveKindDetails,
11488
11549
  kindUniqueOn: kindUniqueOn,
11489
11550
  isDeletable: isDeletable(item),
@@ -11874,6 +11935,15 @@ var Form = function Form(_ref) {
11874
11935
  if (isNotEmpty(questionLabel)) return truncate(questionLabel, 40);
11875
11936
  return humanize(questionKind);
11876
11937
  };
11938
+ var richTextQuestions = filterBy({
11939
+ kind: includes(__, RICH_TEXT_QUESTIONS)
11940
+ }, questions);
11941
+ var resetFormData = function resetFormData() {
11942
+ resetForm();
11943
+ setFormData({
11944
+ richTextFieldsToReset: pluck("fieldCode", richTextQuestions)
11945
+ });
11946
+ };
11877
11947
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Alert, {
11878
11948
  isOpen: isNotNil(deleteQuestionIndex),
11879
11949
  submitButtonLabel: t("neetoForm.common.delete"),
@@ -11963,36 +12033,14 @@ var Form = function Form(_ref) {
11963
12033
  }))), showActionBlock && /*#__PURE__*/React__default.createElement("div", {
11964
12034
  className: "neeto-ui-border-gray-300 flex-shrink-0 border-t py-4"
11965
12035
  }, /*#__PURE__*/React__default.createElement(ActionBlock, {
11966
- className: "space-x-2",
12036
+ submitButtonProps: submitButtonProps,
11967
12037
  cancelButtonProps: _objectSpread$h({
11968
- label: t("neetoForm.common.reset")
11969
- }, cancelButtonProps),
11970
- submitButtonProps: _objectSpread$h({
11971
- disabled: isSubmitting || !dirty
11972
- }, submitButtonProps)
12038
+ label: t("neetoForm.common.reset"),
12039
+ onClick: resetFormData
12040
+ }, cancelButtonProps)
11973
12041
  }))));
11974
12042
  };
11975
12043
 
11976
- var getActiveQuestionKindDetails = function getActiveQuestionKindDetails(_ref) {
11977
- var allQuestionKinds = _ref.allQuestionKinds,
11978
- item = _ref.item;
11979
- var kind = item.kind,
11980
- label = item.label;
11981
- var _findBy = findBy({
11982
- type: kind
11983
- }, allQuestionKinds),
11984
- FieldComponent = _findBy.component,
11985
- FieldIcon = _findBy.icon,
11986
- isSingular = _findBy.isSingular;
11987
- return {
11988
- kind: kind,
11989
- label: label,
11990
- FieldComponent: FieldComponent,
11991
- FieldIcon: FieldIcon,
11992
- isSingular: isSingular
11993
- };
11994
- };
11995
-
11996
12044
  /* eslint-disable @bigbinary/neeto/file-name-and-export-name-standards */
11997
12045
  var requiredLabelValidation = function requiredLabelValidation(schema, field) {
11998
12046
  return schema.trim().required(i18next.t("neetoForm.common.fieldReq", {
@@ -16149,13 +16197,13 @@ var getMultipleOptionsFromURL = function getMultipleOptionsFromURL(_ref2) {
16149
16197
  });
16150
16198
  };
16151
16199
  var getStarRatingFromUrl = function getStarRatingFromUrl(_ref3) {
16152
- var starCount = _ref3.starCount,
16200
+ var minValue = _ref3.minValue,
16201
+ maxValue = _ref3.maxValue,
16153
16202
  fieldCodes = _ref3.fieldCodes,
16154
16203
  fieldCode = _ref3.fieldCode;
16155
16204
  var fieldCodeValue = fieldCodes[fieldCode];
16156
16205
  var rating = parseInt(fieldCodeValue);
16157
- if (!rating || rating < 0) return "";
16158
- return "".concat(rating >= starCount ? starCount : rating, " / ").concat(starCount);
16206
+ return isNil(rating) || isNaN(rating) ? "" : clamp$2(minValue, maxValue, rating);
16159
16207
  };
16160
16208
  var getAdditionalGuestsFromUrl = function getAdditionalGuestsFromUrl(_ref4) {
16161
16209
  var fieldCodes = _ref4.fieldCodes,
@@ -16212,7 +16260,8 @@ var generateInitValues = function generateInitValues(_ref7) {
16212
16260
  kind = question.kind,
16213
16261
  optionsAttributes = question.optionsAttributes,
16214
16262
  fieldCode = question.fieldCode,
16215
- count = question.count;
16263
+ minValue = question.minValue,
16264
+ maxValue = question.maxValue;
16216
16265
  switch (kind) {
16217
16266
  case QUESTION_KIND.CONDITION.value:
16218
16267
  {
@@ -16300,7 +16349,8 @@ var generateInitValues = function generateInitValues(_ref7) {
16300
16349
  {
16301
16350
  var _valuesMap$id$value4, _valuesMap7;
16302
16351
  initValues[id] = (_valuesMap$id$value4 = (_valuesMap7 = valuesMap) === null || _valuesMap7 === void 0 || (_valuesMap7 = _valuesMap7[id]) === null || _valuesMap7 === void 0 ? void 0 : _valuesMap7.value) !== null && _valuesMap$id$value4 !== void 0 ? _valuesMap$id$value4 : getStarRatingFromUrl({
16303
- starCount: count,
16352
+ minValue: minValue,
16353
+ maxValue: maxValue,
16304
16354
  fieldCodes: fieldCodes,
16305
16355
  fieldCode: fieldCode
16306
16356
  });
@@ -16425,6 +16475,10 @@ var renderButtonsInOrder = function renderButtonsInOrder(buttonsArray, shouldRev
16425
16475
  var orderedButtons = shouldReverse ? buttonsArray.reverse() : buttonsArray;
16426
16476
  return map(identity, orderedButtons);
16427
16477
  };
16478
+ var getSelectedRating = function getSelectedRating(value) {
16479
+ var parsedValue = parseInt(value);
16480
+ return isNaN(parsedValue) ? -1 : parsedValue;
16481
+ };
16428
16482
 
16429
16483
  var _excluded$3 = ["value"];
16430
16484
  function ownKeys$8(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -26692,7 +26746,7 @@ var OptionsField = function OptionsField(_ref) {
26692
26746
  options = _question$optionsAttr === void 0 ? [] : _question$optionsAttr;
26693
26747
  var isDropdown = kind === QUESTION_KIND.DROPDOWN.value;
26694
26748
  var label = fieldWithFallback(question, "label");
26695
- var Component = isDropdown ? Select : Choices$1;
26749
+ var Component = isDropdown ? Select$1 : Choices$1;
26696
26750
  var transformedOptions = isDropdown ? options.map(function (option) {
26697
26751
  return {
26698
26752
  label: fieldWithFallback(option, "label"),
@@ -26912,20 +26966,19 @@ var RichTextEditor = function RichTextEditor(_ref) {
26912
26966
  }));
26913
26967
  };
26914
26968
 
26915
- var _excluded$1 = ["value", "shape", "label", "rating", "count"];
26969
+ var _excluded$1 = ["value", "iconType", "label", "rating"];
26916
26970
  var RatingButton = function RatingButton(_ref) {
26917
26971
  var _ref$value = _ref.value,
26918
- value = _ref$value === void 0 ? "0" : _ref$value,
26919
- shape = _ref.shape,
26972
+ value = _ref$value === void 0 ? 0 : _ref$value,
26973
+ iconType = _ref.iconType,
26920
26974
  label = _ref.label,
26921
26975
  rating = _ref.rating,
26922
- count = _ref.count,
26923
26976
  otherProps = _objectWithoutProperties$1(_ref, _excluded$1);
26924
26977
  var handleClick = function handleClick(e) {
26925
26978
  return e.currentTarget.nextElementSibling.click();
26926
26979
  };
26927
- var Icon = ICONS_MAP[shape];
26928
- var selectedRating = value ? String(value).split(" / ")[0] : 0;
26980
+ var Icon = ICONS_MAP[iconType];
26981
+ var selectedRating = getSelectedRating(value);
26929
26982
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("button", {
26930
26983
  className: classnames({
26931
26984
  active: rating === value
@@ -26935,24 +26988,24 @@ var RatingButton = function RatingButton(_ref) {
26935
26988
  }, /*#__PURE__*/React__default.createElement(Icon, {
26936
26989
  size: 24,
26937
26990
  className: classnames("neeto-form-engine-star-rating__icon", {
26938
- "neeto-form-engine-star-rating__icon--active": rating <= Number(selectedRating)
26991
+ "neeto-form-engine-star-rating__icon--active": rating <= selectedRating
26939
26992
  })
26940
26993
  }), /*#__PURE__*/React__default.createElement("label", {
26941
26994
  className: "neeto-form-engine-label"
26942
26995
  }, label)), /*#__PURE__*/React__default.createElement("input", _extends$8({
26943
26996
  hidden: true,
26944
- checked: "".concat(rating, " / ").concat(count) === value,
26997
+ checked: equals(rating, value),
26945
26998
  type: "radio",
26946
- value: "".concat(rating, " / ").concat(count)
26999
+ value: rating
26947
27000
  }, otherProps)));
26948
27001
  };
26949
27002
  var RatingButton$1 = /*#__PURE__*/React__default.memo(RatingButton);
26950
27003
 
26951
- var _excluded = ["label", "count", "shape", "error"];
27004
+ var _excluded = ["label", "minValue", "maxValue", "error"];
26952
27005
  var StarRating = function StarRating(_ref) {
26953
27006
  var label = _ref.label,
26954
- count = _ref.count,
26955
- shape = _ref.shape,
27007
+ minValue = _ref.minValue,
27008
+ maxValue = _ref.maxValue,
26956
27009
  error = _ref.error,
26957
27010
  props = _objectWithoutProperties$1(_ref, _excluded);
26958
27011
  return /*#__PURE__*/React__default.createElement("div", {
@@ -26963,15 +27016,13 @@ var StarRating = function StarRating(_ref) {
26963
27016
  className: "neeto-form-engine-label"
26964
27017
  }, label)), /*#__PURE__*/React__default.createElement("div", {
26965
27018
  className: "neeto-form-engine-star-rating__row"
26966
- }, times(function (index) {
27019
+ }, generateArray(minValue, maxValue).map(function (index) {
26967
27020
  return /*#__PURE__*/React__default.createElement(RatingButton$1, _extends$8({
26968
- count: count,
26969
- shape: shape,
26970
27021
  key: index,
26971
- label: index + 1,
26972
- rating: index + 1
27022
+ label: index,
27023
+ rating: index
26973
27024
  }, props));
26974
- }, count)), !!error && typeof error === "string" && /*#__PURE__*/React__default.createElement("p", {
27025
+ })), !!error && typeof error === "string" && /*#__PURE__*/React__default.createElement("p", {
26975
27026
  className: "neeto-form-engine-input__error",
26976
27027
  "data-cy": "neeto-form-engine-star-rating-error"
26977
27028
  }, error));
@@ -26984,10 +27035,10 @@ var StarRatingField = function StarRatingField(_ref) {
26984
27035
  var name = question.id,
26985
27036
  kind = question.kind,
26986
27037
  isRequired = question.isRequired,
26987
- count = question.count,
26988
- shape = question.shape;
27038
+ minValue = question.minValue,
27039
+ maxValue = question.maxValue,
27040
+ iconType = question.iconType;
26989
27041
  var label = fieldWithFallback(question, "label");
26990
- var sanitizedCount = clamp$2(0, 10, parseInt(count)) || 0;
26991
27042
  return /*#__PURE__*/React__default.createElement(Field, {
26992
27043
  name: name,
26993
27044
  validate: validateFieldValue({
@@ -27000,9 +27051,10 @@ var StarRatingField = function StarRatingField(_ref) {
27000
27051
  var meta = _ref2.meta,
27001
27052
  field = _ref2.field;
27002
27053
  return /*#__PURE__*/React__default.createElement(StarRating$1, _extends$8({
27054
+ iconType: iconType,
27055
+ maxValue: maxValue,
27056
+ minValue: minValue,
27003
27057
  name: name,
27004
- shape: shape,
27005
- count: sanitizedCount,
27006
27058
  error: meta.touched ? meta.error : "",
27007
27059
  label: getLabel(label, isRequired)
27008
27060
  }, field));
@@ -27018,7 +27070,7 @@ var TermsField = function TermsField(_ref) {
27018
27070
  kind = question.kind,
27019
27071
  isRequired = question.isRequired,
27020
27072
  nodeId = question.nodeId;
27021
- var label = fieldWithFallback(question, "label");
27073
+ var label = fieldWithFallback(question, "label", true);
27022
27074
  return /*#__PURE__*/React__default.createElement(Field, {
27023
27075
  name: name || nodeId,
27024
27076
  validate: validateFieldValue({
@@ -27104,14 +27156,16 @@ var _QUESTION_TO_COMPONEN;
27104
27156
  var QUESTION_TO_COMPONENT_MAP = (_QUESTION_TO_COMPONEN = {}, _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.TEXT.value, TextField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.NAME.value, NameField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.EMAIL.value, EmailField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.INTEGER.value, TextField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.DECIMAL.value, TextField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.PHONE.value, PhoneNumberField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.QUESTION.value, TextField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.TEXTAREA.value, TextField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.CHECKBOX.value, OptionsField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.RADIO.value, OptionsField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.DROPDOWN.value, OptionsField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.RATING.value, RatingField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.PARAGRAPH.value, function (_ref) {
27105
27157
  var question = _ref.question;
27106
27158
  return /*#__PURE__*/React__default.createElement(EditorContent, {
27107
- content: isEmpty(question.label) ? question.labelFallback : question.label
27159
+ content: fieldWithFallback(question, "label", true)
27108
27160
  });
27109
27161
  }), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.TERMS.value, TermsField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.DATE.value, DateField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.STAR_RATING.value, StarRatingField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.ADDITIONAL_GUESTS.value, MultipleEmailInput), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.RICH_TEXT.value, RichTextEditor), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.CONDITION.value, ConditionField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.FILE_UPLOAD.value, FileUploadField), _QUESTION_TO_COMPONEN);
27110
27162
 
27111
27163
  var fieldWithFallback = function fieldWithFallback(question, fieldName) {
27164
+ var hasRichContent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
27112
27165
  var fallback = question["".concat(fieldName, "Fallback")];
27113
27166
  var field = question[fieldName];
27114
- return isEmpty(field) && isNotNil(fallback) ? fallback : field;
27167
+ var isFieldEmpty = hasRichContent ? isEditorEmpty(field) : isEmpty(field);
27168
+ return isFieldEmpty && isNotNil(fallback) ? fallback : field;
27115
27169
  };
27116
27170
  var getFieldComponent = function getFieldComponent(_ref) {
27117
27171
  var kind = _ref.kind;