@ukhomeoffice/cop-react-form-renderer 5.41.0 → 5.42.0
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/components/CheckYourAnswers/Answer.js +1 -2
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +4 -8
- package/dist/components/CheckYourAnswers/index.js +1 -2
- package/dist/components/CollectionPage/CollectionPage.js +2 -4
- package/dist/components/CollectionPage/index.js +1 -2
- package/dist/components/CollectionSummary/BannerStrip.js +2 -4
- package/dist/components/CollectionSummary/CollectionSummary.js +2 -4
- package/dist/components/CollectionSummary/Confirmation.js +4 -8
- package/dist/components/CollectionSummary/SummaryCard.js +9 -18
- package/dist/components/CollectionSummary/index.js +1 -2
- package/dist/components/FormComponent/Collection.js +4 -6
- package/dist/components/FormComponent/Container.js +2 -4
- package/dist/components/FormComponent/FormComponent.js +1 -2
- package/dist/components/FormComponent/helpers/addLabel.js +1 -2
- package/dist/components/FormComponent/helpers/getComponentDisabled.js +1 -2
- package/dist/components/FormComponent/helpers/getComponentError.js +1 -2
- package/dist/components/FormComponent/helpers/getComponentFieldSet.js +2 -3
- package/dist/components/FormComponent/index.js +1 -2
- package/dist/components/FormPage/FormPage.js +2 -4
- package/dist/components/FormPage/index.js +1 -2
- package/dist/components/FormRenderer/FormRenderer.js +2 -4
- package/dist/components/FormRenderer/handlers/cyaAction.js +1 -2
- package/dist/components/FormRenderer/handlers/getPageId.js +1 -2
- package/dist/components/FormRenderer/handlers/index.js +1 -2
- package/dist/components/FormRenderer/handlers/navigate.js +1 -2
- package/dist/components/FormRenderer/handlers/submissionError.js +1 -2
- package/dist/components/FormRenderer/helpers/canActionProceed.js +1 -2
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +1 -2
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +2 -3
- package/dist/components/FormRenderer/helpers/getCYA.js +1 -2
- package/dist/components/FormRenderer/helpers/getFormState.js +1 -2
- package/dist/components/FormRenderer/helpers/getNextPageId.js +2 -3
- package/dist/components/FormRenderer/helpers/getPage.js +1 -2
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +1 -2
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +1 -2
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +1 -2
- package/dist/components/FormRenderer/helpers/index.js +1 -2
- package/dist/components/FormRenderer/index.js +1 -2
- package/dist/components/FormRenderer/onCYAAction.js +1 -2
- package/dist/components/FormRenderer/onPageAction.js +1 -2
- package/dist/components/FormRenderer/onTaskAction.js +1 -2
- package/dist/components/PageActions/ActionButton.js +2 -4
- package/dist/components/PageActions/PageActions.js +1 -2
- package/dist/components/PageActions/index.js +1 -2
- package/dist/components/SummaryList/GroupAction.js +1 -2
- package/dist/components/SummaryList/RowAction.js +1 -2
- package/dist/components/SummaryList/SummaryList.js +2 -4
- package/dist/components/SummaryList/SummaryListHeadingRow.js +1 -2
- package/dist/components/SummaryList/SummaryListRow.js +1 -2
- package/dist/components/SummaryList/SummaryListTitleRow.js +1 -2
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +1 -2
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +1 -2
- package/dist/components/SummaryList/index.js +1 -2
- package/dist/components/TaskList/Task.js +2 -4
- package/dist/components/TaskList/TaskList.js +3 -6
- package/dist/components/TaskList/TaskState.js +2 -4
- package/dist/components/TaskList/index.js +1 -2
- package/dist/context/HooksContext/HooksContext.js +3 -6
- package/dist/context/HooksContext/index.js +1 -2
- package/dist/context/ValidationContext/ValidationContext.js +2 -4
- package/dist/context/ValidationContext/index.js +1 -2
- package/dist/hooks/useAxios.js +1 -2
- package/dist/hooks/useGetRequest.js +6 -12
- package/dist/hooks/useHooks.js +1 -2
- package/dist/hooks/useRefData.js +3 -6
- package/dist/hooks/useValidation.js +1 -2
- package/dist/index.js +1 -2
- package/dist/models/CollectionLabels.js +1 -2
- package/dist/models/ComponentTypes.js +1 -2
- package/dist/models/EventTypes.js +1 -2
- package/dist/models/FormPages.js +1 -2
- package/dist/models/FormTypes.js +1 -2
- package/dist/models/HubFormats.js +1 -2
- package/dist/models/PageAction.js +3 -6
- package/dist/models/TaskStates.js +2 -4
- package/dist/models/index.js +1 -2
- package/dist/setupTests.js +6 -11
- package/dist/utils/CheckYourAnswers/getCYAAction.js +1 -2
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +1 -2
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +1 -2
- package/dist/utils/CheckYourAnswers/getCYARow.js +2 -3
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +1 -2
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +1 -2
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +1 -2
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +1 -2
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +1 -2
- package/dist/utils/CheckYourAnswers/index.js +1 -2
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +2 -4
- package/dist/utils/CollectionPage/addCollectionPageEntry.js +1 -2
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +1 -2
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +1 -2
- package/dist/utils/CollectionPage/getCollectionPageActiveId.js +1 -2
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +1 -2
- package/dist/utils/CollectionPage/getCollectionPageData.js +1 -2
- package/dist/utils/CollectionPage/getQuickEditPage.js +2 -3
- package/dist/utils/CollectionPage/index.js +1 -2
- package/dist/utils/CollectionPage/mergeCollectionPages.js +1 -2
- package/dist/utils/CollectionPage/removeCollectionPageEntry.js +1 -2
- package/dist/utils/CollectionPage/setCollectionPageData.js +1 -2
- package/dist/utils/Component/addShowWhen.js +1 -2
- package/dist/utils/Component/applyToComponentTree.js +1 -2
- package/dist/utils/Component/cleanAttributes.js +2 -4
- package/dist/utils/Component/elevateNestedComponents.js +3 -4
- package/dist/utils/Component/getComponent.js +2 -4
- package/dist/utils/Component/getDefaultValue.js +1 -2
- package/dist/utils/Component/getDefaultValueFromConfig.js +1 -2
- package/dist/utils/Component/index.js +1 -2
- package/dist/utils/Component/isEditable.js +2 -4
- package/dist/utils/Component/optionIsSelected.js +1 -2
- package/dist/utils/Component/setupContainerComponentsPath.js +1 -2
- package/dist/utils/Component/showComponent.js +1 -2
- package/dist/utils/Component/wrapInFormGroup.js +1 -2
- package/dist/utils/Condition/index.js +1 -2
- package/dist/utils/Condition/meetsAllConditions.js +1 -2
- package/dist/utils/Condition/meetsCondition.js +1 -2
- package/dist/utils/Condition/meetsOneCondition.js +1 -2
- package/dist/utils/Condition/setupConditions.js +1 -2
- package/dist/utils/Container/getEditableComponents.js +1 -2
- package/dist/utils/Container/index.js +1 -2
- package/dist/utils/Container/setupNesting.js +3 -4
- package/dist/utils/Container/showContainer.js +1 -2
- package/dist/utils/Data/applyFormula.js +1 -2
- package/dist/utils/Data/getAutocompleteSource.js +51 -18
- package/dist/utils/Data/getAutocompleteSource.test.js +89 -221
- package/dist/utils/Data/getDataPath.js +1 -2
- package/dist/utils/Data/getOptions.js +1 -2
- package/dist/utils/Data/getSourceData.js +1 -2
- package/dist/utils/Data/index.js +1 -2
- package/dist/utils/Data/refDataToOptions.js +1 -2
- package/dist/utils/Data/setDataItem.js +1 -2
- package/dist/utils/Data/setupFormData.js +1 -2
- package/dist/utils/Data/setupRefDataUrlForComponent.js +1 -2
- package/dist/utils/FormPage/applyConditionalProperties.js +1 -2
- package/dist/utils/FormPage/getFormPage.js +1 -2
- package/dist/utils/FormPage/getFormPages.js +1 -2
- package/dist/utils/FormPage/getPageActions.js +1 -2
- package/dist/utils/FormPage/getPageTitle.js +1 -2
- package/dist/utils/FormPage/getParagraphFromText.js +1 -2
- package/dist/utils/FormPage/index.js +1 -2
- package/dist/utils/FormPage/showFormPage.js +1 -2
- package/dist/utils/FormPage/showFormPageCYA.js +1 -2
- package/dist/utils/FormPage/useComponent.js +1 -2
- package/dist/utils/Format/formatData.js +1 -2
- package/dist/utils/Format/formatDataForComponent.js +2 -4
- package/dist/utils/Format/formatDataForForm.js +1 -2
- package/dist/utils/Format/formatDataForPage.js +2 -4
- package/dist/utils/Format/index.js +1 -2
- package/dist/utils/Hub/getFormHub.js +1 -2
- package/dist/utils/Hub/index.js +1 -2
- package/dist/utils/Meta/constants.js +2 -4
- package/dist/utils/Meta/documents/getDocuments.js +1 -2
- package/dist/utils/Meta/documents/index.js +1 -2
- package/dist/utils/Meta/documents/setDocumentsForField.js +1 -2
- package/dist/utils/Meta/index.js +1 -2
- package/dist/utils/Operate/checkValueIsTruthy.js +1 -2
- package/dist/utils/Operate/getFirstOf.js +1 -2
- package/dist/utils/Operate/getIndexOfMatchingValueIn.js +1 -2
- package/dist/utils/Operate/index.js +1 -2
- package/dist/utils/Operate/persistValueInFormData.js +1 -2
- package/dist/utils/Operate/runPageOperations.js +1 -2
- package/dist/utils/Operate/setValueInFormData.js +1 -2
- package/dist/utils/Operate/shouldRun.js +1 -2
- package/dist/utils/Validate/additional/conditionallyRequired.js +1 -2
- package/dist/utils/Validate/additional/index.js +1 -2
- package/dist/utils/Validate/additional/mustBeAfter.js +1 -2
- package/dist/utils/Validate/additional/mustBeBefore.js +1 -2
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +1 -2
- package/dist/utils/Validate/additional/mustBeGreaterThan.js +1 -2
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +1 -2
- package/dist/utils/Validate/additional/mustBeInThePast.js +1 -2
- package/dist/utils/Validate/additional/mustBeLessThan.js +1 -2
- package/dist/utils/Validate/additional/mustBeLongerThan.js +1 -2
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +1 -2
- package/dist/utils/Validate/additional/mustBeShorterThan.js +1 -2
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +1 -2
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +1 -2
- package/dist/utils/Validate/additional/mustNotContainSql.js +1 -2
- package/dist/utils/Validate/additional/mustSelectOnlyOne.js +1 -2
- package/dist/utils/Validate/additional/utils.js +3 -6
- package/dist/utils/Validate/index.js +1 -2
- package/dist/utils/Validate/validateCollection.js +1 -2
- package/dist/utils/Validate/validateComponent.js +2 -3
- package/dist/utils/Validate/validateContainer.js +1 -2
- package/dist/utils/Validate/validateDate.js +2 -4
- package/dist/utils/Validate/validateEmail.js +1 -2
- package/dist/utils/Validate/validateMultifile.js +2 -4
- package/dist/utils/Validate/validatePage.js +1 -2
- package/dist/utils/Validate/validateRegex.js +1 -2
- package/dist/utils/Validate/validateRequired.js +1 -2
- package/dist/utils/Validate/validateTextArea.js +1 -2
- package/dist/utils/Validate/validateTime.js +1 -2
- package/dist/utils/index.js +1 -2
- package/package.json +2 -2
|
@@ -10,7 +10,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
10
10
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
11
11
|
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); }
|
|
12
12
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
13
|
-
var JSON_ONLY_PROPERTIES = ['source', 'use', 'show_when', 'options', 'additionalValidation', 'full_path', 'fullPath', 'formData'];
|
|
13
|
+
var JSON_ONLY_PROPERTIES = exports.JSON_ONLY_PROPERTIES = ['source', 'use', 'show_when', 'options', 'additionalValidation', 'full_path', 'fullPath', 'formData'];
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* This method removes and properties that are entirely specific to the JSON
|
|
@@ -23,7 +23,6 @@ var JSON_ONLY_PROPERTIES = ['source', 'use', 'show_when', 'options', 'additional
|
|
|
23
23
|
* @param {Array} alsoRemove An array of additional properties to remove.
|
|
24
24
|
* @returns A clean(er) JSON object.
|
|
25
25
|
*/
|
|
26
|
-
exports.JSON_ONLY_PROPERTIES = JSON_ONLY_PROPERTIES;
|
|
27
26
|
var cleanAttributes = function cleanAttributes(options) {
|
|
28
27
|
var alsoRemove = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
29
28
|
var removeKeys = Array.isArray(alsoRemove) ? [].concat(JSON_ONLY_PROPERTIES, alsoRemove) : JSON_ONLY_PROPERTIES;
|
|
@@ -38,5 +37,4 @@ var cleanAttributes = function cleanAttributes(options) {
|
|
|
38
37
|
}
|
|
39
38
|
return {};
|
|
40
39
|
};
|
|
41
|
-
var _default = cleanAttributes;
|
|
42
|
-
exports.default = _default;
|
|
40
|
+
var _default = exports.default = cleanAttributes;
|
|
@@ -35,12 +35,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
35
35
|
*/
|
|
36
36
|
var elevateNestedComponents = function elevateNestedComponents(components, data) {
|
|
37
37
|
var allComponents = [];
|
|
38
|
-
components === null || components === void 0
|
|
38
|
+
components === null || components === void 0 || components.forEach(function (component) {
|
|
39
39
|
allComponents.push(component);
|
|
40
40
|
// If the component wasn't shown we shouldn't elevate anything nested under it
|
|
41
41
|
if ((0, _showComponent.default)(component, data)) {
|
|
42
42
|
var _component$data;
|
|
43
|
-
(_component$data = component.data) === null || _component$data === void 0 || (_component$data = _component$data.options) === null || _component$data === void 0
|
|
43
|
+
(_component$data = component.data) === null || _component$data === void 0 || (_component$data = _component$data.options) === null || _component$data === void 0 || _component$data.forEach(function (option) {
|
|
44
44
|
// If this option has nested components and is
|
|
45
45
|
// selected, then add its nested components to the array.
|
|
46
46
|
var sourceData = (data === null || data === void 0 ? void 0 : data[component.id]) || _Data.default.getSource(data, component.full_path);
|
|
@@ -53,5 +53,4 @@ var elevateNestedComponents = function elevateNestedComponents(components, data)
|
|
|
53
53
|
});
|
|
54
54
|
return allComponents;
|
|
55
55
|
};
|
|
56
|
-
var _default = elevateNestedComponents;
|
|
57
|
-
exports.default = _default;
|
|
56
|
+
var _default = exports.default = elevateNestedComponents;
|
|
@@ -263,14 +263,13 @@ var getChildJsx = function getChildJsx(parent, paramChild) {
|
|
|
263
263
|
* @param {*} parentConfig parent component which the childrenConfigs will be under
|
|
264
264
|
* @param {*} childrenConfigs array of configurations for the child components
|
|
265
265
|
*/
|
|
266
|
-
var getChildrenJsx = function getChildrenJsx(parentConfig, childrenConfigs) {
|
|
266
|
+
var getChildrenJsx = exports.getChildrenJsx = function getChildrenJsx(parentConfig, childrenConfigs) {
|
|
267
267
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, childrenConfigs.map(function (config) {
|
|
268
268
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
|
|
269
269
|
key: config.id
|
|
270
270
|
}, getChildJsx(parentConfig, config));
|
|
271
271
|
}));
|
|
272
272
|
};
|
|
273
|
-
exports.getChildrenJsx = getChildrenJsx;
|
|
274
273
|
/**
|
|
275
274
|
* Get a renderable component, based on a configuration object.
|
|
276
275
|
* @param {object} config The configuration object for the component.
|
|
@@ -293,5 +292,4 @@ var getComponent = function getComponent(config) {
|
|
|
293
292
|
}
|
|
294
293
|
return component;
|
|
295
294
|
};
|
|
296
|
-
var _default = getComponent;
|
|
297
|
-
exports.default = _default;
|
|
295
|
+
var _default = exports.default = getComponent;
|
|
@@ -20,5 +20,4 @@ var getDefaultValue = function getDefaultValue(component, formData) {
|
|
|
20
20
|
var defaultValue = (0, _getDefaultValueFromConfig.default)(component, formData);
|
|
21
21
|
return defaultValue || DEFAULT_VALUES[component.type] || '';
|
|
22
22
|
};
|
|
23
|
-
var _default = getDefaultValue;
|
|
24
|
-
exports.default = _default;
|
|
23
|
+
var _default = exports.default = getDefaultValue;
|
|
@@ -7,10 +7,8 @@ exports.default = exports.EDITABLE_TYPES = void 0;
|
|
|
7
7
|
var _models = require("../../models");
|
|
8
8
|
// Local imports
|
|
9
9
|
|
|
10
|
-
var EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CALCULATION, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.FILE, _models.ComponentTypes.MULTI_FILE, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.SELECT, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA, _models.ComponentTypes.TIME];
|
|
11
|
-
exports.EDITABLE_TYPES = EDITABLE_TYPES;
|
|
10
|
+
var EDITABLE_TYPES = exports.EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CALCULATION, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.FILE, _models.ComponentTypes.MULTI_FILE, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.SELECT, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA, _models.ComponentTypes.TIME];
|
|
12
11
|
var isEditable = function isEditable(options) {
|
|
13
12
|
return EDITABLE_TYPES.includes(options === null || options === void 0 ? void 0 : options.type) || (options === null || options === void 0 ? void 0 : options.isEditable) || false;
|
|
14
13
|
};
|
|
15
|
-
var _default = isEditable;
|
|
16
|
-
exports.default = _default;
|
|
14
|
+
var _default = exports.default = isEditable;
|
|
@@ -27,9 +27,9 @@ var nestComponents = function nestComponents(container) {
|
|
|
27
27
|
}
|
|
28
28
|
if (component.type === _models.ComponentTypes.RADIOS) {
|
|
29
29
|
var _ret$data;
|
|
30
|
-
(_ret$data = ret.data) === null || _ret$data === void 0 || (_ret$data = _ret$data.options) === null || _ret$data === void 0
|
|
30
|
+
(_ret$data = ret.data) === null || _ret$data === void 0 || (_ret$data = _ret$data.options) === null || _ret$data === void 0 || _ret$data.forEach(function (option, optionIndex) {
|
|
31
31
|
var _option$nested;
|
|
32
|
-
(_option$nested = option.nested) === null || _option$nested === void 0
|
|
32
|
+
(_option$nested = option.nested) === null || _option$nested === void 0 || _option$nested.forEach(function (nest, nestIndex) {
|
|
33
33
|
if (nest.type === _models.ComponentTypes.CONTAINER) {
|
|
34
34
|
// eslint-disable-next-line no-use-before-define
|
|
35
35
|
ret.data.options[optionIndex].nested[nestIndex] = setupNesting(nest);
|
|
@@ -49,5 +49,4 @@ var setupNesting = function setupNesting(container) {
|
|
|
49
49
|
}
|
|
50
50
|
return container;
|
|
51
51
|
};
|
|
52
|
-
var _default = setupNesting;
|
|
53
|
-
exports.default = _default;
|
|
52
|
+
var _default = exports.default = setupNesting;
|
|
@@ -52,5 +52,4 @@ var showContainer = function showContainer(container, data) {
|
|
|
52
52
|
// the container has no editable components. In either case, it should be shown.
|
|
53
53
|
return true;
|
|
54
54
|
};
|
|
55
|
-
var _default = showContainer;
|
|
56
|
-
exports.default = _default;
|
|
55
|
+
var _default = exports.default = showContainer;
|
|
@@ -19,26 +19,59 @@ var getAutocompleteSource = function getAutocompleteSource(config) {
|
|
|
19
19
|
var labelMaker = config !== null && config !== void 0 && config.item ? _copReactComponents.Utils.itemLabel(config.item) : null;
|
|
20
20
|
return function (query, populateResults) {
|
|
21
21
|
var lcQuery = query ? query.toLowerCase() : '';
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
|
|
23
|
+
// go through all options and give them a grade
|
|
24
|
+
|
|
25
|
+
var results = options.map(function (opt) {
|
|
24
26
|
var label = labelMaker ? labelMaker(opt) : opt.label || '';
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
var lcLabel = label.toLowerCase();
|
|
28
|
+
|
|
29
|
+
// result 'score'
|
|
30
|
+
var grade = 0;
|
|
31
|
+
|
|
32
|
+
// highest result - match at start of string
|
|
33
|
+
var index = lcLabel.indexOf(lcQuery);
|
|
34
|
+
if (index === 0) {
|
|
35
|
+
grade = 1;
|
|
36
|
+
} else if (index > 0) {
|
|
37
|
+
grade = lcLabel.substring(index - 1).startsWith(" ") ? 2 : 3;
|
|
38
|
+
} else {
|
|
39
|
+
var _config$item;
|
|
40
|
+
if (opt.synonyms) {
|
|
41
|
+
var match = opt.synonyms.some(function (synonym) {
|
|
42
|
+
return synonym.toLowerCase().includes(lcQuery);
|
|
43
|
+
});
|
|
44
|
+
if (match) {
|
|
45
|
+
grade = 4;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!grade && (_config$item = config.item) !== null && _config$item !== void 0 && _config$item.extraFieldsToSearch) {
|
|
49
|
+
var found = config.item.extraFieldsToSearch.some(function (field) {
|
|
50
|
+
if (typeof opt[field] !== 'string') {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return opt[field].toLowerCase().includes(lcQuery);
|
|
54
|
+
});
|
|
55
|
+
if (found) grade = 5;
|
|
37
56
|
}
|
|
38
|
-
|
|
39
|
-
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
grade: grade,
|
|
60
|
+
label: label,
|
|
61
|
+
opt: opt
|
|
62
|
+
};
|
|
63
|
+
}).filter(function (result) {
|
|
64
|
+
return result.grade > 0;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// sort results and then map to just opts
|
|
68
|
+
populateResults(results
|
|
69
|
+
// the sort prioritises grade but also sorts by string value
|
|
70
|
+
.sort(function (r1, r2) {
|
|
71
|
+
return (r1.grade - r2.grade) * 16 + r1.label.localeCompare(r2.label);
|
|
72
|
+
}).map(function (r) {
|
|
73
|
+
return r.opt;
|
|
40
74
|
}));
|
|
41
75
|
};
|
|
42
76
|
};
|
|
43
|
-
var _default = getAutocompleteSource;
|
|
44
|
-
exports.default = _default;
|
|
77
|
+
var _default = exports.default = getAutocompleteSource;
|