@bigbinary/neeto-form-frontend 4.4.33 → 4.4.35

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.
Files changed (41) hide show
  1. package/app/javascript/src/translations/ar.json +5 -2
  2. package/app/javascript/src/translations/bg.json +5 -2
  3. package/app/javascript/src/translations/ca.json +5 -2
  4. package/app/javascript/src/translations/cs.json +5 -2
  5. package/app/javascript/src/translations/da.json +5 -2
  6. package/app/javascript/src/translations/de.json +5 -2
  7. package/app/javascript/src/translations/es-MX.json +5 -2
  8. package/app/javascript/src/translations/es.json +5 -2
  9. package/app/javascript/src/translations/et.json +5 -2
  10. package/app/javascript/src/translations/fi.json +5 -2
  11. package/app/javascript/src/translations/fil.json +5 -2
  12. package/app/javascript/src/translations/fr.json +5 -2
  13. package/app/javascript/src/translations/he.json +5 -2
  14. package/app/javascript/src/translations/hi.json +5 -2
  15. package/app/javascript/src/translations/hr.json +5 -2
  16. package/app/javascript/src/translations/hu.json +5 -2
  17. package/app/javascript/src/translations/id.json +5 -2
  18. package/app/javascript/src/translations/it.json +5 -2
  19. package/app/javascript/src/translations/ja.json +5 -2
  20. package/app/javascript/src/translations/ko.json +5 -2
  21. package/app/javascript/src/translations/nl.json +5 -2
  22. package/app/javascript/src/translations/pl.json +5 -2
  23. package/app/javascript/src/translations/pt-BR.json +5 -2
  24. package/app/javascript/src/translations/pt.json +5 -2
  25. package/app/javascript/src/translations/ro.json +5 -2
  26. package/app/javascript/src/translations/ru.json +5 -2
  27. package/app/javascript/src/translations/sk.json +5 -2
  28. package/app/javascript/src/translations/sl.json +5 -2
  29. package/app/javascript/src/translations/sv.json +5 -2
  30. package/app/javascript/src/translations/th.json +5 -2
  31. package/app/javascript/src/translations/tr.json +5 -2
  32. package/app/javascript/src/translations/uk.json +5 -2
  33. package/app/javascript/src/translations/vi.json +5 -2
  34. package/app/javascript/src/translations/zh-CN.json +5 -2
  35. package/app/javascript/src/translations/zh-TW.json +5 -2
  36. package/dist/.ready +1 -1
  37. package/dist/cjs/v2/BuildForm.js +41 -34
  38. package/dist/cjs/v2/BuildForm.js.map +1 -1
  39. package/dist/v2/BuildForm.js +49 -42
  40. package/dist/v2/BuildForm.js.map +1 -1
  41. package/package.json +6 -6
@@ -1,8 +1,8 @@
1
- import { Alert, Dialog, Typography, Tooltip, DropdownMenu, Button, Empty, Switch as Switch$1, Sheet, Accordion, Label, Badge, Checkbox, Slider, Spinner } from '@bigbinary/neeto-atoms';
1
+ import { Alert, Dialog, Typography, Tooltip, DropdownMenu, Button, Empty, Switch as Switch$1, Sheet, Select, Accordion, Label, Badge, Checkbox, Slider, Spinner } from '@bigbinary/neeto-atoms';
2
2
  import { useQueryClient } from '@tanstack/react-query';
3
3
  import classnames from 'classnames';
4
4
  import { isPresent, truncate, findBy, isNotPresent, slugify, existsBy, findById, findIndexById, hyphenate, noop, nullSafe, modifyBy, removeBy } from '@bigbinary/neeto-cist';
5
- import { equals, path, when, assoc, includes, isEmpty, reject, keys, pick, omit, evolve, map, mergeLeft, isNil, pipe, filter, isNotNil, values, uniq, join, pathSatisfies, assocPath, dissoc, append, pluck, test, paths, difference, prop, startsWith, split, last, either, F, T } from 'ramda';
5
+ import { equals, path, when, assoc, includes, isEmpty, reject, keys, pick, omit, evolve, map, mergeLeft, prop, pipe, filter, isNotNil, values, uniq, join, pathSatisfies, assocPath, dissoc, isNil, append, pluck, test, paths, difference, startsWith, split, last, either, F, T } from 'ramda';
6
6
  import { j as useDeleteQuestion, b as useForm, k as useCreateQuestion, l as useUpdateQuestion, m as useReorderQuestions, Q as QUERY_KEYS } from './useFormApi-B5a0zkAT.js';
7
7
  import { n as QUESTION_ACTIONS, o as INDEPENDENT_LABELS_MAP, q as buildDisplayLabel, r as isElementOverflowing, c as isFunction, s as SELECTABLE_KINDS, t as isAutoGeneratedQuestion, g as fieldWithFallback, u as isRichTextQuestion, v as SPOT_QUESTION_FIELD_CODE, w as isNameQuestion, N as NON_BASIC_LATIN_CHARACTERS_REGEX, x as RESERVED_FIELD_CODES, y as renameKey, j as LABEL_FIELDS, z as isDefaultLanguage, B as buildAddQuestionButtonProps, F as validateEditorContent, G as FIELD_CODES_REJECT_CHARS_REGEX, M as MIN_WORDS_SWITCH_LABEL_PROPS, H as MIN_WORDS, J as isImmutableField, a as QUESTIONS_WITHOUT_FIELD_CODE, K as NON_HIDEABLE_FIELDS, O as NON_READ_ONLY_FIELDS, T as OPINION_LABEL_MAX_LENGTH, U as RICH_TEXT_QUESTIONS, h as ADDRESS_FIELD_WIDTHS, A as ADDRESS_FIELD_TYPES, V as generateDefaultOptions, W as MINIMUM_ADDRESS_FIELDS, X as getDeletedRecords, Y as randomId, Z as getActiveRecords, _ as FILE_TYPES_MAP, $ as FILE_GROUPS, a0 as OPINION_SCALE_MIN_VALUE_OPTIONS, a1 as OPINION_SCALE_MAX_VALUE_OPTIONS, D as DEFAULT_CHOICE_QUESTION_ATTRIBUTES, a2 as MINIMUM_OPTIONS, a3 as IMAGE_HEIGHT_SLIDER_DEFAULTS, a4 as RATING_OPTIONS, a5 as STAR_RATING_MIN_VALUE_OPTIONS, a6 as STAR_RATING_MAX_VALUE_OPTIONS, a7 as STAR_RATING_ICONS_MAP, a8 as buildDisabledAddButtonHelpPopoverProps, a9 as buildReorderPayload, aa as QUESTIONS_INITIAL_VALUE, ab as isMandatoryField, ac as QUESTION_KINDS, Q as QUESTION_KIND, ad as getActiveQuestionKindDetails, ae as DEFAULT_AVAILABLE_LANGUAGES, af as DEFAULT_ADVANCED_FEATURES } from './yup-Cddsv0mm.js';
8
8
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
@@ -22,7 +22,7 @@ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
22
22
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
23
23
  import { t } from 'i18next';
24
24
  import { v4 } from 'uuid';
25
- import { Textarea as Textarea$1, Switch, Input, Select, Form as Form$2, ActionBlock, RadioGroup, Checkbox as Checkbox$1 } from '@bigbinary/neeto-atoms/formik';
25
+ import { Textarea as Textarea$1, Switch, Input, Form as Form$2, ActionBlock, Select as Select$1, RadioGroup, Checkbox as Checkbox$1 } from '@bigbinary/neeto-atoms/formik';
26
26
  import { useFormikContext, useField } from 'formik';
27
27
  import NeetoEditor from '@bigbinary/neeto-editor/v2/Editor';
28
28
  import { isEditorEmpty } from '@bigbinary/neeto-editor/v2/utils';
@@ -347,13 +347,17 @@ var Card = function Card(_ref) {
347
347
  "data-testid": "edit-question",
348
348
  key: "edit",
349
349
  label: t("neetoForm.common.edit"),
350
- onClick: onEdit
350
+ onClick: function onClick() {
351
+ return onEdit(question);
352
+ }
351
353
  }, {
352
354
  "data-testid": "clone-question",
353
355
  key: "clone",
354
356
  label: t("neetoForm.common.clone"),
355
357
  isVisible: !isSingular && isFunction(onClone),
356
- onClick: onClone
358
+ onClick: function onClick() {
359
+ return onClone(question);
360
+ }
357
361
  }].concat(_toConsumableArray(extraMenuItems), [{
358
362
  "data-testid": "delete-question",
359
363
  key: "delete",
@@ -1110,6 +1114,7 @@ var Form$1 = function Form(_ref) {
1110
1114
  isSmsUpdatesEnabledByDefault = advancedFeatures.smsUpdatesEnabledByDefault;
1111
1115
  var kind = values.kind;
1112
1116
  var questionKinds = isEdit ? allQuestionKinds : availableQuestionKinds;
1117
+ var kindOptions = buildKindOptions(questionKinds);
1113
1118
  var questionKindUniquenessPattern = mergeLeft(isEdit && kindUniqueOn ? kindUniqueOn(values) : {}, {
1114
1119
  type: kind
1115
1120
  });
@@ -1139,16 +1144,22 @@ var Form$1 = function Form(_ref) {
1139
1144
  var isBasicSettingsVisible = !isRequired && (!isImmutable || shouldShowHideSwitch);
1140
1145
  var shouldShowRequiredSwitch = isBasicSettingsVisible && !isImmutable && !includes(kind, [QUESTION_TYPES.PARAGRAPH, QUESTION_TYPES.ADDRESS, QUESTION_TYPES.SPOT]);
1141
1146
  var isSettingsBlockVisible = kind !== QUESTION_TYPES.SPOT && (isBasicSettingsVisible || canMarkResponsesAsReadOnly || isTextarea || shouldShowSendSmsUpdatesSwitch);
1142
- var handleKindChange = function handleKindChange(option) {
1143
- var data = buildQuestionData(option);
1147
+ var handleKindChange = function handleKindChange(value) {
1148
+ var data = buildQuestionData(value);
1144
1149
  updateFormState(data);
1145
1150
  };
1146
- var buildQuestionData = function buildQuestionData(option) {
1147
- if (isNil(option)) {
1151
+
1152
+ // atoms Select reports the option's value, not the option object, and
1153
+ // clears to "" rather than null.
1154
+ var buildQuestionData = function buildQuestionData(value) {
1155
+ var _findBy;
1156
+ if (isNotPresent(value)) {
1148
1157
  return INITIAL_VALUES;
1149
1158
  }
1150
- var label = option.label,
1151
- value = option.value;
1159
+ var _ref3 = (_findBy = findBy({
1160
+ value: value
1161
+ }, kindOptions)) !== null && _findBy !== void 0 ? _findBy : {},
1162
+ label = _ref3.label;
1152
1163
  var kind = extractKindFromOption(value);
1153
1164
  var questionKind = getQuestionKind(availableQuestionKinds, {
1154
1165
  type: kind,
@@ -1188,16 +1199,14 @@ var Form$1 = function Form(_ref) {
1188
1199
  children: [/*#__PURE__*/jsx(Select, {
1189
1200
  isClearable: true,
1190
1201
  isSearchable: true,
1191
- defaultValue: buildDefaultValueForKind(questionKind),
1192
- filterOption: filterKindOption,
1193
- innerRef: initialFocusRef,
1194
- isDisabled: isEdit,
1195
- name: "kind",
1196
- options: buildKindOptions(questionKinds),
1197
- formatOptionLabel: function formatOptionLabel(option, _ref3) {
1198
- var context = _ref3.context;
1199
- return context === "menu" ? /*#__PURE__*/jsx(KindOption, _objectSpread$d({}, option)) : option.label;
1202
+ formatOptionLabel: function formatOptionLabel(option) {
1203
+ return /*#__PURE__*/jsx(KindOption, _objectSpread$d({}, option));
1200
1204
  },
1205
+ formatTriggerLabel: prop("label"),
1206
+ isDisabled: isEdit,
1207
+ options: kindOptions,
1208
+ ref: initialFocusRef,
1209
+ value: buildDefaultValueForKind(questionKind),
1201
1210
  label: t("neetoForm.questions.common.questionFields.field.questionType"),
1202
1211
  onChange: handleKindChange
1203
1212
  }), isRichTextQuestion(kind) ? /*#__PURE__*/jsxs(Fragment, {
@@ -1477,6 +1486,9 @@ var Edit = function Edit(_ref) {
1477
1486
  })
1478
1487
  }), /*#__PURE__*/jsx(Form$2, {
1479
1488
  formikProps: {
1489
+ // Sheet keeps children mounted, so this renders once before a
1490
+ // question is selected; without this those empty values stick.
1491
+ enableReinitialize: true,
1480
1492
  initialValues: _objectSpread$b(_objectSpread$b({}, question), {}, {
1481
1493
  isMinWordsEnabled: isPresent(question.minWords)
1482
1494
  }),
@@ -1724,11 +1736,11 @@ var ManagePane = function ManagePane(_ref) {
1724
1736
  placeholder: t("neetoForm.questions.address.fieldLabelPlaceholder")
1725
1737
  }), /*#__PURE__*/jsxs("div", {
1726
1738
  className: "grid grid-cols-2 gap-6",
1727
- children: [/*#__PURE__*/jsx(Select, {
1739
+ children: [/*#__PURE__*/jsx(Select$1, {
1728
1740
  label: t("neetoForm.questions.address.width"),
1729
1741
  name: "width",
1730
1742
  options: Object.values(ADDRESS_FIELD_WIDTH_OPTIONS)
1731
- }), /*#__PURE__*/jsx(Select, {
1743
+ }), /*#__PURE__*/jsx(Select$1, {
1732
1744
  label: t("neetoForm.questions.address.type"),
1733
1745
  name: "fieldType",
1734
1746
  options: Object.values(ADDRESS_FIELD_TYPE_OPTIONS),
@@ -2404,7 +2416,7 @@ var OpinionScale = function OpinionScale() {
2404
2416
  return /*#__PURE__*/jsxs(Fragment, {
2405
2417
  children: [/*#__PURE__*/jsxs("div", {
2406
2418
  className: "flex space-x-4",
2407
- children: [/*#__PURE__*/jsx(Select, {
2419
+ children: [/*#__PURE__*/jsx(Select$1, {
2408
2420
  className: "w-1/2",
2409
2421
  "data-testid": "neeto-form-engine-opinion-scale-min-value",
2410
2422
  label: t("neetoForm.common.start"),
@@ -2413,7 +2425,7 @@ var OpinionScale = function OpinionScale() {
2413
2425
  onChange: function onChange(option) {
2414
2426
  return setFieldValue("minValue", option === null || option === void 0 ? void 0 : option.value);
2415
2427
  }
2416
- }), /*#__PURE__*/jsx(Select, {
2428
+ }), /*#__PURE__*/jsx(Select$1, {
2417
2429
  className: "w-1/2",
2418
2430
  "data-testid": "neeto-form-engine-opinion-scale-max-value",
2419
2431
  label: t("neetoForm.common.end"),
@@ -2604,7 +2616,7 @@ var StarRating = function StarRating() {
2604
2616
  return /*#__PURE__*/jsxs(Fragment, {
2605
2617
  children: [/*#__PURE__*/jsxs("div", {
2606
2618
  className: "flex space-x-4",
2607
- children: [/*#__PURE__*/jsx(Select, {
2619
+ children: [/*#__PURE__*/jsx(Select$1, {
2608
2620
  className: "w-1/2",
2609
2621
  "data-testid": "neeto-form-engine-star-rating-min-value",
2610
2622
  label: t("neetoForm.common.start"),
@@ -2613,7 +2625,7 @@ var StarRating = function StarRating() {
2613
2625
  onChange: function onChange(option) {
2614
2626
  return setFieldValue("minValue", option === null || option === void 0 ? void 0 : option.value);
2615
2627
  }
2616
- }), /*#__PURE__*/jsx(Select, {
2628
+ }), /*#__PURE__*/jsx(Select$1, {
2617
2629
  className: "w-1/2",
2618
2630
  "data-testid": "neeto-form-engine-star-rating-max-value",
2619
2631
  label: t("neetoForm.common.end"),
@@ -2727,20 +2739,11 @@ var buildKindOptions = function buildKindOptions(kinds) {
2727
2739
  };
2728
2740
  });
2729
2741
  };
2730
- var filterKindOption = function filterKindOption(option, rawInput) {
2731
- var _option$data$searchTe, _option$data;
2732
- var query = rawInput === null || rawInput === void 0 ? void 0 : rawInput.trim().toLowerCase();
2733
- if (!query) return true;
2734
- var searchTerms = (_option$data$searchTe = (_option$data = option.data) === null || _option$data === void 0 ? void 0 : _option$data.searchTerms) !== null && _option$data$searchTe !== void 0 ? _option$data$searchTe : [];
2735
- return searchTerms.some(function (term) {
2736
- return term.includes(query);
2737
- });
2738
- };
2739
2742
  var extractKindFromOption = pipe(split("-"), last);
2743
+
2744
+ // atoms Select takes a scalar value, not a `{ value }` object.
2740
2745
  var buildDefaultValueForKind = function buildDefaultValueForKind(questionKind) {
2741
- return isPresent(questionKind) ? {
2742
- value: transformValueForOption(questionKind)
2743
- } : undefined;
2746
+ return isPresent(questionKind) ? transformValueForOption(questionKind) : undefined;
2744
2747
  };
2745
2748
  var hideSwitchLabelProps = function hideSwitchLabelProps(helpUrl) {
2746
2749
  return helpUrl ? {
@@ -2983,17 +2986,21 @@ var Form = function Form(_ref) {
2983
2986
  setSelectedAction(QUESTION_ACTIONS.ADD);
2984
2987
  setIsManageQuestionPaneOpen(true);
2985
2988
  };
2986
- var handleEdit = function handleEdit() {
2989
+
2990
+ // The dropdown menu portals out of the card, so its clicks never reach the
2991
+ // card's onClick — actions take the question rather than the selected one.
2992
+ var handleEdit = function handleEdit(question) {
2993
+ setSelectedQuestion(question);
2987
2994
  setSelectedAction(QUESTION_ACTIONS.EDIT);
2988
2995
  setIsManageQuestionPaneOpen(true);
2989
2996
  };
2990
- var handleClone = function handleClone() {
2997
+ var handleClone = function handleClone(question) {
2991
2998
  var values = duplicateFieldData({
2992
- item: selectedQuestion,
2999
+ item: question,
2993
3000
  questionKinds: availableQuestionKinds,
2994
3001
  questions: questions
2995
3002
  });
2996
- var displayOrder = selectedQuestion.displayOrder + 1;
3003
+ var displayOrder = question.displayOrder + 1;
2997
3004
  var attributes = mergeLeft({
2998
3005
  displayOrder: displayOrder
2999
3006
  }, values);