@inseefr/lunatic 2.7.1 → 2.7.2
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/README.md +45 -11
- package/lib/components/checkbox/checkbox-boolean/html/checkbox-boolean.js +3 -3
- package/lib/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.js +2 -1
- package/lib/components/checkbox/checkbox-group/checkbox-group-content.js +0 -2
- package/lib/components/checkbox/checkbox-group/html/checkbox-group-content.js +4 -2
- package/lib/components/checkbox/checkbox-group/html/checkbox-group.js +3 -3
- package/lib/components/checkbox/checkbox-group/lunatic-checkbox-group.js +2 -2
- package/lib/components/checkbox/checkbox-one/lunatic-checkbox-one.js +2 -1
- package/lib/components/checkbox/commons/checkbox-option.js +3 -1
- package/lib/components/commons/components/combo-box/combo-box-container.js +1 -2
- package/lib/components/commons/components/combo-box/combo-box.js +2 -2
- package/lib/components/commons/components/combo-box/selection/LabelOrInput.js +3 -1
- package/lib/components/commons/components/combo-box/selection/input.js +3 -1
- package/lib/components/commons/components/combo-box/selection/selection.js +3 -1
- package/lib/components/commons/components/errors/errors.js +12 -10
- package/lib/components/commons/components/errors/errors.spec.js +6 -6
- package/lib/components/component-set/html/__snapshots__/component-set.spec.tsx.snap +2 -0
- package/lib/components/component-set/html/component-set.js +2 -2
- package/lib/components/datepicker/html/DatepickerField.js +47 -0
- package/lib/components/datepicker/html/__snapshots__/datepicker.spec.tsx.snap +209 -17
- package/lib/components/datepicker/html/datepicker.js +104 -21
- package/lib/components/datepicker/html/datepicker.scss +19 -1
- package/lib/components/datepicker/html/datepicker.spec.js +71 -23
- package/lib/components/datepicker/lunatic-datepicker.js +5 -2
- package/lib/components/dropdown/lunatic-dropdown.js +2 -1
- package/lib/components/duration/duration.js +6 -7
- package/lib/components/duration/duration.scss +6 -14
- package/lib/components/duration/durationInput.js +14 -8
- package/lib/components/duration/durationUtils.js +38 -8
- package/lib/components/input/html/__snapshots__/input.spec.tsx.snap +2 -0
- package/lib/components/input/html/input.js +3 -3
- package/lib/components/input/lunatic-input.js +2 -1
- package/lib/components/input-number/html/__snapshots__/input-number.spec.tsx.snap +2 -2
- package/lib/components/input-number/html/input-number-thousand.js +4 -17
- package/lib/components/input-number/html/input-number.js +3 -5
- package/lib/components/input-number/lunatic-input-number.js +2 -3
- package/lib/components/loop/roster-for-loop/__snapshots__/roster-for-loop.spec.tsx.snap +88 -0
- package/lib/components/loop/roster-for-loop/roster-for-loop.js +7 -3
- package/lib/components/loop/roster-for-loop/roster-for-loop.spec.js +46 -0
- package/lib/components/lunatic-components.js +2 -11
- package/lib/components/radio/html/radio-group-content.js +4 -2
- package/lib/components/radio/html/radio-group.js +3 -3
- package/lib/components/radio/html/radio-option.js +3 -1
- package/lib/components/radio/lunatic-radio-group.js +2 -1
- package/lib/components/suggester/find-best-label/find-best-label.js +5 -5
- package/lib/components/suggester/idb-suggester/check-store.js +6 -3
- package/lib/components/suggester/idb-suggester/idb-suggester.js +8 -7
- package/lib/components/suggester/idb-suggester/suggester-status.js +1 -4
- package/lib/components/suggester/lunatic-suggester.js +7 -4
- package/lib/components/suggester/searching/create-searching.js +19 -42
- package/lib/components/switch/html/switch.js +2 -2
- package/lib/components/switch/lunatic-switch.js +2 -1
- package/lib/components/table/lunatic-table.js +2 -2
- package/lib/components/textarea/html/__snapshots__/textarea.spec.tsx.snap +2 -0
- package/lib/components/textarea/html/textarea.js +6 -4
- package/lib/components/textarea/lunatic-textarea.js +6 -3
- package/lib/hooks/use-auto-focus.js +26 -0
- package/lib/src/components/checkbox/checkbox-boolean/html/checkbox-boolean.d.ts +1 -1
- package/lib/src/components/checkbox/checkbox-group/html/checkbox-group-content.d.ts +2 -1
- package/lib/src/components/checkbox/checkbox-group/html/checkbox-group.d.ts +1 -1
- package/lib/src/components/checkbox/commons/checkbox-option.d.ts +1 -0
- package/lib/src/components/commons/components/combo-box/combo-box-container.d.ts +2 -2
- package/lib/src/components/commons/components/combo-box/combo-box.d.ts +2 -2
- package/lib/src/components/commons/components/combo-box/selection/LabelOrInput.d.ts +1 -0
- package/lib/src/components/commons/components/combo-box/selection/input.d.ts +1 -0
- package/lib/src/components/commons/components/combo-box/selection/selection.d.ts +2 -1
- package/lib/src/components/commons/components/errors/errors.d.ts +6 -3
- package/lib/src/components/datepicker/html/DatepickerField.d.ts +12 -0
- package/lib/src/components/datepicker/html/datepicker.d.ts +4 -3
- package/lib/src/components/datepicker/lunatic-datepicker.d.ts +1 -0
- package/lib/src/components/dropdown/html/dropdown-writable/dropdown-writable.d.ts +1 -1
- package/lib/src/components/dropdown/html/dropdown.d.ts +3 -1
- package/lib/src/components/duration/durationInput.d.ts +6 -2
- package/lib/src/components/duration/durationUtils.d.ts +24 -7
- package/lib/src/components/input/html/input.d.ts +2 -2
- package/lib/src/components/input-number/html/input-number-thousand.d.ts +2 -2
- package/lib/src/components/input-number/html/input-number.d.ts +2 -3
- package/lib/src/components/radio/html/radio-group-content.d.ts +2 -1
- package/lib/src/components/radio/html/radio-group.d.ts +1 -1
- package/lib/src/components/radio/html/radio-option.d.ts +1 -0
- package/lib/src/components/suggester/find-best-label/find-best-label.d.ts +1 -1
- package/lib/src/components/suggester/html/suggester.d.ts +1 -1
- package/lib/src/components/suggester/idb-suggester/check-store.d.ts +5 -2
- package/lib/src/components/suggester/idb-suggester/idb-suggester.d.ts +5 -2
- package/lib/src/components/suggester/idb-suggester/suggester-status.d.ts +1 -4
- package/lib/src/components/suggester/lunatic-suggester.d.ts +1 -1
- package/lib/src/components/suggester/searching/create-searching.d.ts +1 -1
- package/lib/src/components/switch/html/switch.d.ts +1 -1
- package/lib/src/components/textarea/html/textarea.d.ts +3 -2
- package/lib/src/components/type.d.ts +5 -3
- package/lib/src/hooks/use-auto-focus.d.ts +6 -0
- package/lib/src/use-lunatic/actions.d.ts +2 -0
- package/lib/src/use-lunatic/commons/fill-components/fill-component-required.d.ts +383 -0
- package/lib/src/use-lunatic/commons/fill-components/fill-component-value.d.ts +1 -1
- package/lib/src/use-lunatic/commons/fill-components/fill-component-value.spec.d.ts +1 -0
- package/lib/src/use-lunatic/commons/fill-components/fill-from-state.d.ts +20 -0
- package/lib/src/use-lunatic/commons/variables/lunatic-variables-store.d.ts +4 -0
- package/lib/src/use-lunatic/reducer/overview/overview-on-init.d.ts +1 -0
- package/lib/src/use-lunatic/type.d.ts +1 -0
- package/lib/src/use-lunatic/use-lunatic.d.ts +8 -3
- package/lib/src/use-lunatic/use-suggesters.d.ts +2 -1
- package/lib/src/utils/suggester-workers/append-to-index/create-append-task.d.ts +2 -2
- package/lib/src/utils/suggester-workers/worker-path.d.ts +6 -0
- package/lib/stories/behaviour/cleaning/source.json +151 -0
- package/lib/stories/behaviour/cleaning/test.stories.js +82 -0
- package/lib/stories/{questionnaires-test → behaviour}/controls/controls.stories.js +5 -5
- package/lib/stories/{questionnaires-test → behaviour/others}/test.stories.js +7 -7
- package/lib/stories/{paste-questionnaire → behaviour/paste}/test.stories.js +3 -3
- package/lib/stories/{resizing-questionnaire → behaviour/resizing}/test.stories.js +3 -3
- package/lib/stories/date-picker/datepicker.stories.js +32 -29
- package/lib/stories/duration/duration.stories.js +4 -4
- package/lib/stories/duration/{source.json → mois.json} +1 -1
- package/lib/stories/duration/{source1.json → time.json} +1 -1
- package/lib/use-lunatic/commons/fill-components/fill-component-required.js +23 -0
- package/lib/use-lunatic/commons/fill-components/fill-component-value.js +1 -1
- package/lib/use-lunatic/commons/fill-components/fill-component-value.spec.js +67 -0
- package/lib/use-lunatic/commons/fill-components/fill-components.js +2 -1
- package/lib/use-lunatic/commons/fill-components/fill-from-state.js +2 -0
- package/lib/use-lunatic/commons/variables/lunatic-variables-store.js +15 -0
- package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +9 -1
- package/lib/use-lunatic/initial-state.js +2 -1
- package/lib/use-lunatic/reducer/reduce-on-init.js +4 -2
- package/lib/use-lunatic/use-lunatic.js +7 -3
- package/lib/use-lunatic/use-suggesters.js +54 -37
- package/lib/utils/env.js +9 -1
- package/lib/utils/suggester-workers/append-to-index/create-append-task.js +5 -4
- package/lib/utils/suggester-workers/create-worker.js +10 -1
- package/lib/utils/suggester-workers/worker-path.js +29 -0
- package/package.json +24 -11
- package/scripts/build/add-workers-to-public.js +44 -0
- package/scripts/build/workers-paths.js +45 -0
- package/workers-release/lunatic-append-worker-0.3.0.js +2 -0
- package/workers-release/lunatic-append-worker-0.3.0.js.LICENSE.txt +34 -0
- package/workers-release/lunatic-label-worker-0.3.0.js +2 -0
- package/workers-release/lunatic-label-worker-0.3.0.js.LICENSE.txt +13 -0
- package/workers-release/lunatic-search-worker-0.3.0.js +2 -0
- package/workers-release/lunatic-search-worker-0.3.0.js.LICENSE.txt +34 -0
- package/lib/components/datepicker/html/datepicker-container.js +0 -17
- package/lib/components/datepicker/html/datepicker-input.js +0 -35
- package/lib/env.d.js +0 -1
- package/lib/src/components/datepicker/html/datepicker-container.d.ts +0 -3
- package/lib/src/components/datepicker/html/datepicker-input.d.ts +0 -13
- package/lib/src/utils/get-component-value.d.ts +0 -5
- package/lib/src/utils/store-tools/worker-path.d.ts +0 -1
- package/lib/utils/get-component-value.js +0 -34
- package/lib/utils/get-component-value.test.js +0 -57
- package/lib/utils/store-tools/worker-path.js +0 -13
- package/lib/utils/suggester-workers/create-worker-ts.js +0 -54
- /package/lib/src/{utils/get-component-value.test.d.ts → components/loop/roster-for-loop/roster-for-loop.spec.d.ts} +0 -0
- /package/lib/src/utils/suggester-workers/{create-worker-ts.d.ts → create-worker.d.ts} +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_ControlesNonNum_horsBoucle_PasPageFin.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_ControlesNum_horsBoucle_PasPageFin.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_Controles_BouclesLiees2_PasPageFin.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_Controles_BouclesLiees_PasPageFin.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/boucles-n.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/controls-externes.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/controls-externes.stories.js +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/V2_DeclarationsSimples.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/V2_MinMaxSum_Boucles.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/V2_QuestSimple_Boucles.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/V2_TCMRallyeGames.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/test-dylan.json +0 -0
- /package/lib/stories/{paste-questionnaire → behaviour/paste}/source.json +0 -0
- /package/lib/stories/{resizing-questionnaire → behaviour/resizing}/source.json +0 -0
|
@@ -7,8 +7,8 @@ exports["default"] = exports.TimeDuration = exports.DateDuration = void 0;
|
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _defaultArgTypes = _interopRequireDefault(require("../utils/default-arg-types"));
|
|
9
9
|
var _orchestrator = _interopRequireDefault(require("../utils/orchestrator"));
|
|
10
|
-
var
|
|
11
|
-
var
|
|
10
|
+
var _mois = _interopRequireDefault(require("./mois"));
|
|
11
|
+
var _time = _interopRequireDefault(require("./time"));
|
|
12
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
14
|
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); }
|
|
@@ -29,10 +29,10 @@ var Template = function Template(args) {
|
|
|
29
29
|
var DateDuration = exports.DateDuration = Template.bind({});
|
|
30
30
|
DateDuration.args = {
|
|
31
31
|
id: 'durationAnnéesMois',
|
|
32
|
-
source:
|
|
32
|
+
source: _mois["default"]
|
|
33
33
|
};
|
|
34
34
|
var TimeDuration = exports.TimeDuration = Template.bind({});
|
|
35
35
|
TimeDuration.args = {
|
|
36
36
|
id: 'durationHeureMinute',
|
|
37
|
-
source:
|
|
37
|
+
source: _time["default"]
|
|
38
38
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fillComponentRequired = fillComponentRequired;
|
|
7
|
+
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); }
|
|
8
|
+
function ownKeys(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; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
|
+
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); }
|
|
13
|
+
/**
|
|
14
|
+
* Add required attribute on component that are mandatory
|
|
15
|
+
*/
|
|
16
|
+
function fillComponentRequired(component) {
|
|
17
|
+
if (component.mandatory) {
|
|
18
|
+
return _objectSpread(_objectSpread({}, component), {}, {
|
|
19
|
+
required: true
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return component;
|
|
23
|
+
}
|
|
@@ -24,7 +24,7 @@ function getValueForComponent(component, state) {
|
|
|
24
24
|
}
|
|
25
25
|
if ((0, _component.hasResponses)(component)) {
|
|
26
26
|
var _component$responses$, _component$responses;
|
|
27
|
-
return Object.
|
|
27
|
+
return Object.fromEntries((_component$responses$ = (_component$responses = component.responses) === null || _component$responses === void 0 ? void 0 : _component$responses.map(function (_ref) {
|
|
28
28
|
var response = _ref.response;
|
|
29
29
|
return [response.name, state.variables.get(response.name, iteration)];
|
|
30
30
|
})) !== null && _component$responses$ !== void 0 ? _component$responses$ : []);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _fillComponentValue = require("./fill-component-value");
|
|
5
|
+
var _lunaticVariablesStore = require("../variables/lunatic-variables-store");
|
|
6
|
+
var _array = require("../../../utils/array");
|
|
7
|
+
(0, _vitest.describe)('fillComponentValue', function () {
|
|
8
|
+
// Helper to avoid repetition
|
|
9
|
+
var expectFilledComponent = function expectFilledComponent(component) {
|
|
10
|
+
var values = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
11
|
+
var iteration = arguments.length > 2 ? arguments[2] : undefined;
|
|
12
|
+
return (0, _vitest.expect)((0, _fillComponentValue.fillComponentValue)(component, {
|
|
13
|
+
variables: _lunaticVariablesStore.LunaticVariablesStore.makeFromObject(values),
|
|
14
|
+
pager: {
|
|
15
|
+
maxPage: '2',
|
|
16
|
+
page: '1',
|
|
17
|
+
iteration: iteration
|
|
18
|
+
}
|
|
19
|
+
}).value);
|
|
20
|
+
};
|
|
21
|
+
(0, _vitest.describe)('response', function () {
|
|
22
|
+
var component = {
|
|
23
|
+
response: {
|
|
24
|
+
name: 'PRENOM'
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
(0, _vitest.it)('Should work with simple response', function () {
|
|
28
|
+
expectFilledComponent(component, {
|
|
29
|
+
PRENOM: 'John'
|
|
30
|
+
}).toBe('John');
|
|
31
|
+
expectFilledComponent(component).toBe(null);
|
|
32
|
+
});
|
|
33
|
+
(0, _vitest.it)('Should work with simple response as Array', function () {
|
|
34
|
+
expectFilledComponent(component, {
|
|
35
|
+
PRENOM: ['John', 'Renaud']
|
|
36
|
+
}, 1).toBe('Renaud');
|
|
37
|
+
expectFilledComponent(component, {
|
|
38
|
+
PRENOM: ['John', 'Renaud']
|
|
39
|
+
}, 3).toBe(undefined);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
(0, _vitest.describe)('responses', function () {
|
|
43
|
+
var component = {
|
|
44
|
+
responses: (0, _array.times)(3, function (k) {
|
|
45
|
+
return {
|
|
46
|
+
response: {
|
|
47
|
+
name: "NAME".concat(k)
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
(0, _vitest.it)('should work with multiple responses', function () {
|
|
53
|
+
expectFilledComponent(component).toEqual({
|
|
54
|
+
NAME0: null,
|
|
55
|
+
NAME1: null,
|
|
56
|
+
NAME2: null
|
|
57
|
+
});
|
|
58
|
+
expectFilledComponent(component, {
|
|
59
|
+
NAME1: true
|
|
60
|
+
}).toEqual({
|
|
61
|
+
NAME0: null,
|
|
62
|
+
NAME1: true,
|
|
63
|
+
NAME2: null
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -11,6 +11,7 @@ var _fillManagement = _interopRequireDefault(require("./fill-management"));
|
|
|
11
11
|
var _fillMissingResponse = _interopRequireDefault(require("./fill-missing-response"));
|
|
12
12
|
var _fillPagination = _interopRequireDefault(require("./fill-pagination"));
|
|
13
13
|
var _fillSpecificExpression = _interopRequireDefault(require("./fill-specific-expression"));
|
|
14
|
+
var _fillComponentRequired = require("./fill-component-required");
|
|
14
15
|
var _fillIterations = require("./fill-iterations");
|
|
15
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
16
17
|
/**
|
|
@@ -36,7 +37,7 @@ function compose() {
|
|
|
36
37
|
*
|
|
37
38
|
* Force typing for this function since it's doo dynamic
|
|
38
39
|
*/
|
|
39
|
-
var fillComponent = exports.fillComponent = compose(_fillFromState["default"], _fillComponentExpressions["default"], _fillPagination["default"], _fillComponentValue.fillComponentValue, _fillMissingResponse["default"], _fillManagement["default"], _fillIterations.fillIterations, _fillSpecificExpression["default"]);
|
|
40
|
+
var fillComponent = exports.fillComponent = compose(_fillFromState["default"], _fillComponentExpressions["default"], _fillPagination["default"], _fillComponentValue.fillComponentValue, _fillMissingResponse["default"], _fillComponentRequired.fillComponentRequired, _fillManagement["default"], _fillIterations.fillIterations, _fillSpecificExpression["default"]);
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* Fill components with values coming from the state, and interpret VTL expression
|
|
@@ -20,6 +20,7 @@ function fillFromState(component, state) {
|
|
|
20
20
|
goToPage = state.goToPage,
|
|
21
21
|
shortcut = state.shortcut,
|
|
22
22
|
getSuggesterStatus = state.getSuggesterStatus,
|
|
23
|
+
workersBasePath = state.workersBasePath,
|
|
23
24
|
goNextPage = state.goNextPage,
|
|
24
25
|
goPreviousPage = state.goPreviousPage;
|
|
25
26
|
return _objectSpread(_objectSpread({}, component), {}, {
|
|
@@ -29,6 +30,7 @@ function fillFromState(component, state) {
|
|
|
29
30
|
goToPage: goToPage,
|
|
30
31
|
shortcut: shortcut,
|
|
31
32
|
getSuggesterStatus: getSuggesterStatus,
|
|
33
|
+
workersBasePath: workersBasePath,
|
|
32
34
|
goNextPage: goNextPage,
|
|
33
35
|
goPreviousPage: goPreviousPage
|
|
34
36
|
});
|
|
@@ -179,6 +179,21 @@ var LunaticVariablesStore = exports.LunaticVariablesStore = /*#__PURE__*/functio
|
|
|
179
179
|
(0, _missingBehaviour.missingBehaviour)(store, source.missingBlock);
|
|
180
180
|
return store;
|
|
181
181
|
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Create a new store from an object (useful for testing)
|
|
185
|
+
*/
|
|
186
|
+
}, {
|
|
187
|
+
key: "makeFromObject",
|
|
188
|
+
value: function makeFromObject() {
|
|
189
|
+
var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
190
|
+
var store = new LunaticVariablesStore();
|
|
191
|
+
for (var _i = 0, _Object$keys = Object.keys(values); _i < _Object$keys.length; _i++) {
|
|
192
|
+
var name = _Object$keys[_i];
|
|
193
|
+
store.set(name, values[name]);
|
|
194
|
+
}
|
|
195
|
+
return store;
|
|
196
|
+
}
|
|
182
197
|
}]);
|
|
183
198
|
return LunaticVariablesStore;
|
|
184
199
|
}();
|
|
@@ -14,7 +14,15 @@ var _missingBehaviour = require("./behaviours/missing-behaviour");
|
|
|
14
14
|
variables.set('FIRSTNAME', 'John');
|
|
15
15
|
(0, _vitest.expect)(variables.get('FIRSTNAME')).toEqual('John');
|
|
16
16
|
});
|
|
17
|
-
(0, _vitest.it)('should
|
|
17
|
+
(0, _vitest.it)('should create a store from an object', function () {
|
|
18
|
+
var store = _lunaticVariablesStore.LunaticVariablesStore.makeFromObject({
|
|
19
|
+
name: 'John',
|
|
20
|
+
lastname: 'Doe'
|
|
21
|
+
});
|
|
22
|
+
(0, _vitest.expect)(store.get('name')).toEqual('John');
|
|
23
|
+
(0, _vitest.expect)(store.get('lastname')).toEqual('Doe');
|
|
24
|
+
});
|
|
25
|
+
(0, _vitest.it)('should run with simple types', function () {
|
|
18
26
|
(0, _vitest.expect)(variables.run('"Hello world"')).toEqual('Hello world');
|
|
19
27
|
(0, _vitest.expect)(variables.run('true')).toEqual(true);
|
|
20
28
|
(0, _vitest.expect)(variables.run('2')).toEqual(2);
|
|
@@ -65,7 +65,8 @@ function reduceOnInit(state, action) {
|
|
|
65
65
|
activeControls = payload.activeControls,
|
|
66
66
|
goToPage = payload.goToPage,
|
|
67
67
|
goNextPage = payload.goNextPage,
|
|
68
|
-
goPreviousPage = payload.goPreviousPage
|
|
68
|
+
goPreviousPage = payload.goPreviousPage,
|
|
69
|
+
workersBasePath = payload.workersBasePath;
|
|
69
70
|
if (!source || !data) {
|
|
70
71
|
return state;
|
|
71
72
|
}
|
|
@@ -139,7 +140,8 @@ function reduceOnInit(state, action) {
|
|
|
139
140
|
goToPage: goToPage,
|
|
140
141
|
goNextPage: goNextPage,
|
|
141
142
|
goPreviousPage: goPreviousPage,
|
|
142
|
-
shortcut: shortcut
|
|
143
|
+
shortcut: shortcut,
|
|
144
|
+
workersBasePath: workersBasePath
|
|
143
145
|
}), initialPager);
|
|
144
146
|
}
|
|
145
147
|
var reducers = (0, _compose["default"])(reduceOnInit, _overviewOnInit.reduceOverviewOnInit);
|
|
@@ -78,6 +78,8 @@ function useLunatic(source) {
|
|
|
78
78
|
dontKnowButton = _ref$dontKnowButton === void 0 ? DEFAULT_DONT_KNOW : _ref$dontKnowButton,
|
|
79
79
|
_ref$refusedButton = _ref.refusedButton,
|
|
80
80
|
refusedButton = _ref$refusedButton === void 0 ? DEFAULT_REFUSED : _ref$refusedButton,
|
|
81
|
+
_ref$workersBasePath = _ref.workersBasePath,
|
|
82
|
+
workersBasePath = _ref$workersBasePath === void 0 ? undefined : _ref$workersBasePath,
|
|
81
83
|
_ref$trackChanges = _ref.trackChanges,
|
|
82
84
|
trackChanges = _ref$trackChanges === void 0 ? false : _ref$trackChanges;
|
|
83
85
|
var _useReducer = (0, _react.useReducer)(_reducer["default"], _initialState["default"]),
|
|
@@ -109,7 +111,8 @@ function useLunatic(source) {
|
|
|
109
111
|
var getSuggesterStatus = (0, _useSuggesters.useSuggesters)({
|
|
110
112
|
auto: autoSuggesterLoading,
|
|
111
113
|
getReferentiel: getReferentiel,
|
|
112
|
-
suggesters: suggesters
|
|
114
|
+
suggesters: suggesters,
|
|
115
|
+
workersBasePath: workersBasePath
|
|
113
116
|
});
|
|
114
117
|
var compileControls = (0, _react.useCallback)(function () {
|
|
115
118
|
return (0, _compileControls.compileControls)({
|
|
@@ -183,9 +186,10 @@ function useLunatic(source) {
|
|
|
183
186
|
goToPage: goToPage,
|
|
184
187
|
goNextPage: goNextPage,
|
|
185
188
|
goPreviousPage: goPreviousPage,
|
|
186
|
-
withOverview: withOverview
|
|
189
|
+
withOverview: withOverview,
|
|
190
|
+
workersBasePath: workersBasePath
|
|
187
191
|
}));
|
|
188
|
-
}, [source, data, initialPage, features, preferences, savingType, management, shortcut, handleChange, activeControls, withOverview, goToPage, goNextPage, goPreviousPage, lastReachedPage]);
|
|
192
|
+
}, [source, data, initialPage, features, preferences, savingType, management, shortcut, handleChange, activeControls, withOverview, goToPage, goNextPage, goPreviousPage, lastReachedPage, workersBasePath]);
|
|
189
193
|
(0, _react.useEffect)(function () {
|
|
190
194
|
dispatch(actions.updateState({
|
|
191
195
|
getSuggesterStatus: getSuggesterStatus
|
|
@@ -34,8 +34,14 @@ var SuggesterStatus = exports.SuggesterStatus = /*#__PURE__*/function (Suggester
|
|
|
34
34
|
}({});
|
|
35
35
|
function nothing() {}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Update the status ref
|
|
39
|
+
*/
|
|
40
|
+
function setStatus(status,
|
|
41
|
+
// Name of the referentiel
|
|
42
|
+
name,
|
|
43
|
+
// New state
|
|
44
|
+
state) {
|
|
39
45
|
if (status && status.current) {
|
|
40
46
|
var current = status.current;
|
|
41
47
|
if (name in current) current[name] = state;
|
|
@@ -44,7 +50,8 @@ function setStatus(status, name, state) {
|
|
|
44
50
|
function useSuggesters(_ref) {
|
|
45
51
|
var auto = _ref.auto,
|
|
46
52
|
getReferentiel = _ref.getReferentiel,
|
|
47
|
-
suggesters = _ref.suggesters
|
|
53
|
+
suggesters = _ref.suggesters,
|
|
54
|
+
workersBasePath = _ref.workersBasePath;
|
|
48
55
|
var status = (0, _react.useRef)();
|
|
49
56
|
var _useState = (0, _react.useState)(Date.now()),
|
|
50
57
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -69,37 +76,44 @@ function useSuggesters(_ref) {
|
|
|
69
76
|
timestamp: timestamp
|
|
70
77
|
};
|
|
71
78
|
}, [status, timestamp, auto]);
|
|
79
|
+
|
|
80
|
+
// Make all status "idle"
|
|
72
81
|
(0, _react.useEffect)(function () {
|
|
73
|
-
if (suggesters) {
|
|
74
|
-
|
|
75
|
-
var name = _ref2.name;
|
|
76
|
-
return _objectSpread(_objectSpread({}, a), {}, _defineProperty({}, name, SuggesterStatus.idle));
|
|
77
|
-
}, {});
|
|
82
|
+
if (!suggesters) {
|
|
83
|
+
return;
|
|
78
84
|
}
|
|
85
|
+
status.current = suggesters.reduce(function (a, _ref2) {
|
|
86
|
+
var name = _ref2.name;
|
|
87
|
+
return _objectSpread(_objectSpread({}, a), {}, _defineProperty({}, name, SuggesterStatus.idle));
|
|
88
|
+
}, {});
|
|
79
89
|
}, [suggesters, status]);
|
|
90
|
+
|
|
91
|
+
// Index the data
|
|
80
92
|
(0, _react.useEffect)(function () {
|
|
81
93
|
var aborts = [];
|
|
82
94
|
if (typeof getReferentiel === 'function' && Array.isArray(suggesters) && auto) {
|
|
83
|
-
suggesters.forEach(function (
|
|
84
|
-
var
|
|
85
|
-
|
|
86
|
-
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
87
|
-
var isClean, data, _createAppendTask, _createAppendTask2, append, abort, result;
|
|
95
|
+
suggesters.forEach( /*#__PURE__*/function () {
|
|
96
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(store) {
|
|
97
|
+
var name, current, isClean, data, _createAppendTask, _createAppendTask2, append, abort, result;
|
|
88
98
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
89
99
|
while (1) switch (_context.prev = _context.next) {
|
|
90
100
|
case 0:
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
name = store.name;
|
|
102
|
+
current = status.current;
|
|
103
|
+
if (current) {
|
|
104
|
+
_context.next = 4;
|
|
93
105
|
break;
|
|
94
106
|
}
|
|
95
|
-
_context.
|
|
107
|
+
return _context.abrupt("return");
|
|
108
|
+
case 4:
|
|
109
|
+
_context.prev = 4;
|
|
96
110
|
if (!(current[name] === SuggesterStatus.idle)) {
|
|
97
|
-
_context.next =
|
|
111
|
+
_context.next = 10;
|
|
98
112
|
break;
|
|
99
113
|
}
|
|
100
|
-
_context.next =
|
|
114
|
+
_context.next = 8;
|
|
101
115
|
return (0, _initStore.initStore)(store);
|
|
102
|
-
case
|
|
116
|
+
case 8:
|
|
103
117
|
isClean = _context.sent;
|
|
104
118
|
if (!isClean) {
|
|
105
119
|
setStatus(status, name, SuggesterStatus.error);
|
|
@@ -108,20 +122,20 @@ function useSuggesters(_ref) {
|
|
|
108
122
|
setStatus(status, name, SuggesterStatus.pending);
|
|
109
123
|
setTimestamp(Date.now());
|
|
110
124
|
}
|
|
111
|
-
case
|
|
125
|
+
case 10:
|
|
112
126
|
if (!(current[name] === SuggesterStatus.pending)) {
|
|
113
|
-
_context.next =
|
|
127
|
+
_context.next = 20;
|
|
114
128
|
break;
|
|
115
129
|
}
|
|
116
|
-
_context.next =
|
|
130
|
+
_context.next = 13;
|
|
117
131
|
return getReferentiel(name);
|
|
118
|
-
case
|
|
132
|
+
case 13:
|
|
119
133
|
data = _context.sent;
|
|
120
134
|
_createAppendTask = (0, _createAppendTask3.createAppendTask)(store, 1, nothing), _createAppendTask2 = _slicedToArray(_createAppendTask, 2), append = _createAppendTask2[0], abort = _createAppendTask2[1];
|
|
121
135
|
aborts.push(abort);
|
|
122
|
-
_context.next =
|
|
136
|
+
_context.next = 18;
|
|
123
137
|
return append(data);
|
|
124
|
-
case
|
|
138
|
+
case 18:
|
|
125
139
|
result = _context.sent;
|
|
126
140
|
if (result) {
|
|
127
141
|
setStatus(status, name, SuggesterStatus.success);
|
|
@@ -130,28 +144,31 @@ function useSuggesters(_ref) {
|
|
|
130
144
|
setStatus(status, name, SuggesterStatus.error);
|
|
131
145
|
setTimestamp(Date.now());
|
|
132
146
|
}
|
|
133
|
-
case
|
|
134
|
-
_context.next =
|
|
147
|
+
case 20:
|
|
148
|
+
_context.next = 27;
|
|
135
149
|
break;
|
|
136
|
-
case
|
|
137
|
-
_context.prev =
|
|
138
|
-
_context.t0 = _context["catch"](
|
|
150
|
+
case 22:
|
|
151
|
+
_context.prev = 22;
|
|
152
|
+
_context.t0 = _context["catch"](4);
|
|
139
153
|
console.error(_context.t0);
|
|
140
154
|
setStatus(status, name, SuggesterStatus.error);
|
|
141
155
|
setTimestamp(Date.now());
|
|
142
|
-
case
|
|
156
|
+
case 27:
|
|
143
157
|
case "end":
|
|
144
158
|
return _context.stop();
|
|
145
159
|
}
|
|
146
|
-
}, _callee, null, [[
|
|
147
|
-
}))
|
|
148
|
-
|
|
160
|
+
}, _callee, null, [[4, 22]]);
|
|
161
|
+
}));
|
|
162
|
+
return function (_x) {
|
|
163
|
+
return _ref3.apply(this, arguments);
|
|
164
|
+
};
|
|
165
|
+
}());
|
|
149
166
|
return function () {
|
|
150
|
-
aborts.forEach(function (
|
|
151
|
-
|
|
167
|
+
aborts.forEach(function (abort) {
|
|
168
|
+
return abort();
|
|
152
169
|
});
|
|
153
170
|
};
|
|
154
171
|
}
|
|
155
|
-
}, [suggesters, auto, getReferentiel, status]);
|
|
172
|
+
}, [suggesters, auto, getReferentiel, status, workersBasePath]);
|
|
156
173
|
return getSuggesterStatus;
|
|
157
174
|
}
|
package/lib/utils/env.js
CHANGED
|
@@ -5,5 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.isTestEnv = isTestEnv;
|
|
7
7
|
function isTestEnv() {
|
|
8
|
-
|
|
8
|
+
try {
|
|
9
|
+
// using vitest, process.env is defined
|
|
10
|
+
return /test/.test("".concat(process.env.npm_lifecycle_event));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
// process.env is not defined
|
|
13
|
+
// so we are not running as test so we can return false
|
|
14
|
+
// process.env is not defined during storybook running/
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
9
17
|
}
|
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createAppendTask = createAppendTask;
|
|
7
|
-
var _createWorkerTs = require("../create-worker-ts");
|
|
8
|
-
var _workerPath = require("../../store-tools/worker-path");
|
|
9
7
|
var _logger = require("../../logger");
|
|
8
|
+
var _createWorker = require("../create-worker");
|
|
9
|
+
var _workerPath = require("../worker-path");
|
|
10
10
|
function consoleLogging() {
|
|
11
11
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
12
12
|
args[_key] = arguments[_key];
|
|
@@ -17,15 +17,16 @@ function consoleLogging() {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Creates methods to communicate with workers for indexing data
|
|
21
21
|
*/
|
|
22
22
|
function createAppendTask(info, version) {
|
|
23
23
|
var log = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : consoleLogging;
|
|
24
|
+
var workersBasePath = arguments.length > 3 ? arguments[3] : undefined;
|
|
24
25
|
var name = info.name,
|
|
25
26
|
fields = info.fields,
|
|
26
27
|
stopWords = info.stopWords,
|
|
27
28
|
meloto = info.meloto;
|
|
28
|
-
var worker = (0,
|
|
29
|
+
var worker = (0, _createWorker.createWorker)((0, _workerPath.getWorkerPath)(_workerPath.WorkerEnum.APPEND, workersBasePath));
|
|
29
30
|
var start = false;
|
|
30
31
|
var stop = false;
|
|
31
32
|
function launch(entities) {
|
|
@@ -7,6 +7,10 @@ exports.createWorker = void 0;
|
|
|
7
7
|
var _logger = require("../logger");
|
|
8
8
|
// Enable cross domain workers
|
|
9
9
|
|
|
10
|
+
var logStyle = 'color: #915211; font-size: 20px;';
|
|
11
|
+
var getRegisterError = function getRegisterError(workerUrl) {
|
|
12
|
+
return "%cFailed to register Lunatic-Worker at : \"".concat(workerUrl, "\".");
|
|
13
|
+
};
|
|
10
14
|
var testSameOrigin = function testSameOrigin(url) {
|
|
11
15
|
var loc = window.location;
|
|
12
16
|
var a = document.createElement('a');
|
|
@@ -30,8 +34,13 @@ var createWorkerFallback = function createWorkerFallback(workerUrl) {
|
|
|
30
34
|
var url = window.URL || window.webkitURL;
|
|
31
35
|
var blobUrl = url.createObjectURL(blob);
|
|
32
36
|
worker = new Worker(blobUrl);
|
|
37
|
+
worker.onerror = function (event) {
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
console.error(getRegisterError(workerUrl));
|
|
40
|
+
console.error("%cAre you sure that the worker is available at \"".concat(workerUrl, "\" ? \n Did you run \"npx @inseefr/lunatic workers\" to add Lunatic workers to your project ?"), logStyle);
|
|
41
|
+
};
|
|
33
42
|
} catch (e1) {
|
|
34
|
-
console.error("Lunatic-worker : Failed to load web worker : ".concat(workerUrl));
|
|
43
|
+
console.error("Lunatic-worker : Failed to load web worker at : \"".concat(workerUrl, "\""));
|
|
35
44
|
}
|
|
36
45
|
return worker;
|
|
37
46
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WorkerEnum = void 0;
|
|
7
|
+
exports.getWorkerPath = getWorkerPath;
|
|
8
|
+
var _package = _interopRequireDefault(require("../../../package.json"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
var WorkerEnum = exports.WorkerEnum = /*#__PURE__*/function (WorkerEnum) {
|
|
11
|
+
WorkerEnum["APPEND"] = "APPEND";
|
|
12
|
+
WorkerEnum["SEARCH"] = "SEARCH";
|
|
13
|
+
WorkerEnum["LABEL"] = "LABEL";
|
|
14
|
+
return WorkerEnum;
|
|
15
|
+
}({});
|
|
16
|
+
var version = _package["default"].workersVersion;
|
|
17
|
+
var DEFAULT_BASE_PATH = 'workers';
|
|
18
|
+
var WORKER_PATH = {
|
|
19
|
+
APPEND: "lunatic-append-worker-".concat(version, ".js"),
|
|
20
|
+
SEARCH: "lunatic-search-worker-".concat(version, ".js"),
|
|
21
|
+
LABEL: "lunatic-label-worker-".concat(version, ".js")
|
|
22
|
+
};
|
|
23
|
+
function getWorkerPath(workerType, workersBasePath) {
|
|
24
|
+
if (workersBasePath) {
|
|
25
|
+
return "".concat(workersBasePath, "/").concat(WORKER_PATH[workerType]);
|
|
26
|
+
} else {
|
|
27
|
+
return "".concat(DEFAULT_BASE_PATH, "/").concat(WORKER_PATH[workerType]);
|
|
28
|
+
}
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inseefr/lunatic",
|
|
3
|
-
"version": "2.7.
|
|
4
|
-
"workersVersion": "0.
|
|
3
|
+
"version": "2.7.2",
|
|
4
|
+
"workersVersion": "0.3.0",
|
|
5
5
|
"description": "Library of questionnaire components",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -9,9 +9,17 @@
|
|
|
9
9
|
},
|
|
10
10
|
"author": "INSEE (http://www.insee.fr)",
|
|
11
11
|
"contributor": [
|
|
12
|
+
{
|
|
13
|
+
"name": "Jonathan Boyer",
|
|
14
|
+
"email": "contact@grafikart.fr"
|
|
15
|
+
},
|
|
12
16
|
{
|
|
13
17
|
"name": "Laurent Caouissin",
|
|
14
|
-
"email": "laurent.caouissin@
|
|
18
|
+
"email": "laurent.caouissin@insee.fr"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "Dylan Decrulle",
|
|
22
|
+
"email": "dylan.decrulle@insee.fr"
|
|
15
23
|
},
|
|
16
24
|
{
|
|
17
25
|
"name": "Renaud Genevois",
|
|
@@ -26,7 +34,10 @@
|
|
|
26
34
|
"main": "lib/index.js",
|
|
27
35
|
"types": "lib/src/index.d.ts",
|
|
28
36
|
"files": [
|
|
29
|
-
"lib"
|
|
37
|
+
"lib",
|
|
38
|
+
"workers-release",
|
|
39
|
+
"scripts/build/workers-paths.js",
|
|
40
|
+
"scripts/build/add-workers-to-public.js"
|
|
30
41
|
],
|
|
31
42
|
"scripts": {
|
|
32
43
|
"test": "vitest run",
|
|
@@ -42,13 +53,15 @@
|
|
|
42
53
|
"format": "npm run _format -- --write",
|
|
43
54
|
"format:check": "npm run _format -- --list-different",
|
|
44
55
|
"test-coverage": "vitest run --coverage",
|
|
45
|
-
"build": "
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"build
|
|
49
|
-
"
|
|
50
|
-
"storybook": "
|
|
51
|
-
|
|
56
|
+
"build-workers": "node ./scripts/build/build-workers.js",
|
|
57
|
+
"prepare-workers": "npm run build-workers && node ./scripts/build/add-workers-to-public.js",
|
|
58
|
+
"postinstall": "node ./scripts/build/add-workers-to-public.js",
|
|
59
|
+
"build": "babel src --out-dir lib --extensions \".ts,.js,.tsx,.jsx\" --copy-files && tsc --project tsconfig.prod.json && npm run build-workers",
|
|
60
|
+
"storybook": "npm run prepare-workers && storybook dev -p 9999 --no-open",
|
|
61
|
+
"build-storybook": "npm run prepare-workers && storybook build"
|
|
62
|
+
},
|
|
63
|
+
"bin": {
|
|
64
|
+
"workers": "./scripts/build/add-workers-to-public.js"
|
|
52
65
|
},
|
|
53
66
|
"keywords": [
|
|
54
67
|
"react",
|