@inseefr/lunatic 2.5.0-beta → 2.5.0-fix-last-reached-page

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 (49) hide show
  1. package/README.md +26 -26
  2. package/lib/components/duration/duration.js +52 -0
  3. package/lib/components/duration/duration.scss +17 -0
  4. package/lib/components/duration/durationInput.js +72 -0
  5. package/lib/components/duration/durationUtils.js +31 -0
  6. package/lib/components/duration/formatDuration.js +28 -0
  7. package/lib/components/duration/formatDuration.spec.js +38 -0
  8. package/lib/components/duration/getDurationFromValue.js +64 -0
  9. package/lib/components/duration/index.js +13 -0
  10. package/lib/components/index.js +7 -0
  11. package/lib/components/loop/block-for-loop/block-for-loop.js +5 -7
  12. package/lib/components/modal-controls/modal-controls.js +3 -5
  13. package/lib/components/table/table-orchestrator.js +0 -1
  14. package/lib/src/components/duration/duration.d.ts +4 -0
  15. package/lib/src/components/duration/durationInput.d.ts +7 -0
  16. package/lib/src/components/duration/durationUtils.d.ts +30 -0
  17. package/lib/src/components/duration/formatDuration.d.ts +2 -0
  18. package/lib/src/components/duration/formatDuration.spec.d.ts +1 -0
  19. package/lib/src/components/duration/getDurationFromValue.d.ts +8 -0
  20. package/lib/src/components/duration/index.d.ts +1 -0
  21. package/lib/src/components/index.d.ts +1 -0
  22. package/lib/src/components/loop/block-for-loop/block-for-loop.d.ts +3 -3
  23. package/lib/src/components/modal-controls/modal-controls.d.ts +1 -1
  24. package/lib/src/components/table/table-orchestrator.d.ts +1 -1
  25. package/lib/src/components/type.d.ts +7 -0
  26. package/lib/src/use-lunatic/actions.d.ts +2 -0
  27. package/lib/src/use-lunatic/commons/index.d.ts +6 -7
  28. package/lib/src/use-lunatic/reducer/reduce-on-init.d.ts +1 -1
  29. package/lib/src/use-lunatic/reducer/reduce-on-init.spec.d.ts +1 -0
  30. package/lib/src/use-lunatic/use-lunatic.d.ts +16 -3
  31. package/lib/src/utils/object.d.ts +1 -0
  32. package/lib/stories/duration/duration.stories.js +41 -0
  33. package/lib/stories/duration/source.json +32 -0
  34. package/lib/stories/duration/source1.json +32 -0
  35. package/lib/stories/loop/roster-for-loop.stories.js +85 -2
  36. package/lib/stories/utils/orchestrator.js +16 -3
  37. package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.spec.js +2 -0
  38. package/lib/use-lunatic/commons/index.js +6 -13
  39. package/lib/use-lunatic/reducer/commons/auto-explore-loop.js +1 -3
  40. package/lib/use-lunatic/reducer/reduce-go-to-page.js +1 -3
  41. package/lib/use-lunatic/reducer/reduce-on-init.js +5 -4
  42. package/lib/use-lunatic/reducer/reduce-on-init.spec.js +17 -0
  43. package/lib/use-lunatic/use-lunatic.js +4 -1
  44. package/lib/use-lunatic/use-lunatic.test.js +9 -7
  45. package/lib/utils/object.js +6 -0
  46. package/package.json +1 -1
  47. package/lib/src/utils/store-tools/auto-load.d.ts +0 -6
  48. package/lib/use-lunatic/commons/load-suggesters.js +0 -158
  49. package/lib/utils/store-tools/auto-load.js +0 -162
@@ -2,6 +2,7 @@ import { LunaticComponentDefinition, LunaticError, LunaticExpression, LunaticSta
2
2
  import { CSSProperties, FunctionComponent, ReactNode } from 'react';
3
3
  import { SuggesterStatus } from '../use-lunatic/use-suggesters';
4
4
  import useLunatic from '../use-lunatic';
5
+ type Formats = 'PTnHnM' | 'PnYnM';
5
6
  export type VtlExpression = {
6
7
  value: string;
7
8
  type: 'VTL' | 'VTL|MD';
@@ -64,6 +65,12 @@ type ComponentPropsByType = {
64
65
  name: string;
65
66
  };
66
67
  };
68
+ Duration: LunaticBaseProps<string | null> & {
69
+ format: Formats;
70
+ response: {
71
+ name: string;
72
+ };
73
+ };
67
74
  Input: LunaticBaseProps<string> & {
68
75
  maxLength?: number;
69
76
  value: null | string;
@@ -41,6 +41,7 @@ export type ActionInit = {
41
41
  data: LunaticData;
42
42
  source: LunaticSource;
43
43
  initialPage: string;
44
+ lastReachedPage?: string;
44
45
  features: LunaticState['features'];
45
46
  preferences: LunaticState['preferences'];
46
47
  savingType: LunaticState['savingType'];
@@ -102,6 +103,7 @@ export declare const onInit: (payload: {
102
103
  data: LunaticData;
103
104
  source: LunaticSource;
104
105
  initialPage: string;
106
+ lastReachedPage?: string | undefined;
105
107
  features: LunaticState['features'];
106
108
  preferences: LunaticState['preferences'];
107
109
  savingType: LunaticState['savingType'];
@@ -1,13 +1,12 @@
1
1
  export { default as checkLoops } from './check-loops';
2
2
  export { default as createMapPages } from './create-map-pages';
3
- export { default as isPaginatedLoop } from './is-paginated-loop';
4
- export { default as getComponentsFromState } from './get-components-from-state';
5
- export { default as useComponentsFromState } from './use-components-from-state';
6
- export { getPageTag, isNewReachedPage, getNewReachedPage } from './page-tag';
7
- export { default as isFirstLastPage } from './is-First-last-page';
8
- export { default as createExecuteExpression } from './execute-expression';
9
3
  export { default as executeConditionFilter } from './execute-condition-filter';
4
+ export { default as createExecuteExpression } from './execute-expression';
10
5
  export { default as fillComponentExpressions } from './fill-components/fill-component-expressions';
11
- export { default as loadSuggester } from './load-suggesters';
12
6
  export { default as getCompatibleVTLExpression } from './get-compatible-vtl-expression';
7
+ export { default as getComponentsFromState } from './get-components-from-state';
13
8
  export { default as getErrorsWithoutEmptyValue } from './get-errors-without-empty-value';
9
+ export { default as isFirstLastPage } from './is-First-last-page';
10
+ export { default as isPaginatedLoop } from './is-paginated-loop';
11
+ export { getNewReachedPage, getPageTag, isNewReachedPage } from './page-tag';
12
+ export { default as useComponentsFromState } from './use-components-from-state';
@@ -1,5 +1,5 @@
1
- import { LunaticState, LunaticVariable } from '../type';
2
1
  import { ActionInit } from '../actions';
2
+ import { LunaticState, LunaticVariable } from '../type';
3
3
  export type VariablesByType = {
4
4
  EXTERNAL: (LunaticVariable & {
5
5
  variableType: 'EXTERNAL';
@@ -5,7 +5,7 @@ import { LunaticComponentType } from '../components/type';
5
5
  declare const nothing: LunaticState['handleChange'];
6
6
  declare function useLunatic(source: LunaticSource, data: Partial<Record<"EXTERNAL" | "CALCULATED", Record<string, unknown>> & {
7
7
  COLLECTED: Record<string, import("./type").LunaticCollectedValue>;
8
- }> | undefined, { features, preferences, savingType, onChange, management, shortcut, initialPage, autoSuggesterLoading, activeControls, getReferentiel, custom, withOverview, missing, missingStrategy, missingShortcut, dontKnowButton, refusedButton, }: {
8
+ }> | undefined, { features, preferences, savingType, onChange, management, shortcut, initialPage, lastReachedPage, autoSuggesterLoading, activeControls, getReferentiel, custom, withOverview, missing, missingStrategy, missingShortcut, dontKnowButton, refusedButton, }: {
9
9
  features?: LunaticState['features'];
10
10
  preferences?: LunaticState['preferences'];
11
11
  savingType?: LunaticState['savingType'];
@@ -13,6 +13,7 @@ declare function useLunatic(source: LunaticSource, data: Partial<Record<"EXTERNA
13
13
  management?: boolean;
14
14
  shortcut?: boolean;
15
15
  initialPage?: string;
16
+ lastReachedPage?: string;
16
17
  autoSuggesterLoading?: boolean;
17
18
  getReferentiel?: (name: string) => Promise<Array<unknown>>;
18
19
  activeControls?: boolean;
@@ -38,6 +39,12 @@ declare function useLunatic(source: LunaticSource, data: Partial<Record<"EXTERNA
38
39
  name: string;
39
40
  };
40
41
  };
42
+ Duration: import("../components/type").LunaticBaseProps<string | null> & {
43
+ format: "PTnHnM" | "PnYnM";
44
+ response: {
45
+ name: string;
46
+ };
47
+ };
41
48
  Input: import("../components/type").LunaticBaseProps<string> & {
42
49
  maxLength?: number | undefined;
43
50
  value: string | null;
@@ -257,7 +264,7 @@ declare function useLunatic(source: LunaticSource, data: Partial<Record<"EXTERNA
257
264
  }[];
258
265
  };
259
266
  })[] | undefined;
260
- except?: keyof {
267
+ except?: (keyof {
261
268
  InputNumber: import("../components/type").LunaticBaseProps<number | null> & {
262
269
  min: number;
263
270
  max: number;
@@ -267,6 +274,12 @@ declare function useLunatic(source: LunaticSource, data: Partial<Record<"EXTERNA
267
274
  name: string;
268
275
  };
269
276
  };
277
+ Duration: import("../components/type").LunaticBaseProps<string | null> & {
278
+ format: "PTnHnM" | "PnYnM";
279
+ response: {
280
+ name: string;
281
+ };
282
+ };
270
283
  Input: import("../components/type").LunaticBaseProps<string> & {
271
284
  maxLength?: number | undefined;
272
285
  value: string | null;
@@ -485,7 +498,7 @@ declare function useLunatic(source: LunaticSource, data: Partial<Record<"EXTERNA
485
498
  iterations?: number | undefined;
486
499
  }[];
487
500
  };
488
- } | undefined;
501
+ })[] | undefined;
489
502
  }) => import("./commons/fill-components/fill-components").LunaticComponentProps<"Sequence" | "Subsequence" | "RosterForLoop" | "Loop" | "Table" | "Input" | "InputNumber" | "Datepicker" | "CheckboxGroup" | "CheckboxOne" | "CheckboxBoolean" | "Radio" | "Dropdown" | "Textarea" | "FilterDescription" | "PairwiseLinks" | "Suggester" | "ComponentSet" | "Roundabout" | "QuestionExplication">[];
490
503
  goPreviousPage: () => void;
491
504
  goNextPage: (payload?: {}) => void;
@@ -2,3 +2,4 @@
2
2
  * Array.map() but for objet
3
3
  */
4
4
  export declare function objectMap<T extends Record<string, any>, V extends unknown>(object: T, callback: (k: keyof T, v: T[keyof T]) => [k: keyof T, v: V] | null): Record<keyof T, V>;
5
+ export declare function objectKeys<T extends Record<string, unknown>>(object: T): (keyof T)[];
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = exports.TimeDuration = exports.DateDuration = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _defaultArgTypes = _interopRequireDefault(require("../utils/default-arg-types"));
9
+ var _orchestrator = _interopRequireDefault(require("../utils/orchestrator"));
10
+ var _source = _interopRequireDefault(require("./source"));
11
+ var _source2 = _interopRequireDefault(require("./source1"));
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
15
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
17
+ 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; }
18
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
19
+ 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); }
20
+ var stories = {
21
+ title: 'Components/Duration',
22
+ component: _orchestrator["default"],
23
+ argTypes: _defaultArgTypes["default"]
24
+ };
25
+ var _default = stories;
26
+ exports["default"] = _default;
27
+ var Template = function Template(args) {
28
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_orchestrator["default"], _objectSpread({}, args));
29
+ };
30
+ var DateDuration = Template.bind({});
31
+ exports.DateDuration = DateDuration;
32
+ DateDuration.args = {
33
+ id: 'durationAnnéesMois',
34
+ source: _source["default"]
35
+ };
36
+ var TimeDuration = Template.bind({});
37
+ exports.TimeDuration = TimeDuration;
38
+ TimeDuration.args = {
39
+ id: 'durationHeureMinute',
40
+ source: _source2["default"]
41
+ };
@@ -0,0 +1,32 @@
1
+ {
2
+ "components": [
3
+ {
4
+ "id": "kxi788",
5
+ "componentType": "Duration",
6
+ "mandatory": false,
7
+ "format": "PnYnM",
8
+ "page": "1",
9
+ "maxPage": "1",
10
+ "label": {
11
+ "value": "\"➡ 1. \" || \"Duration \"",
12
+ "type": "VTL|MD"
13
+ },
14
+ "description": { "value": "\"Description\"", "type": "VTL|MD" },
15
+ "conditionFilter": { "value": "true", "type": "VTL" },
16
+ "response": { "name": "DUREE" }
17
+ }
18
+ ],
19
+ "variables": [
20
+ {
21
+ "variableType": "COLLECTED",
22
+ "name": "DUREE",
23
+ "values": {
24
+ "PREVIOUS": null,
25
+ "COLLECTED": null,
26
+ "FORCED": null,
27
+ "EDITED": null,
28
+ "INPUTED": null
29
+ }
30
+ }
31
+ ]
32
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "components": [
3
+ {
4
+ "id": "kxi788",
5
+ "componentType": "Duration",
6
+ "mandatory": false,
7
+ "format": "PTnHnM",
8
+ "page": "1",
9
+ "maxPage": "1",
10
+ "label": {
11
+ "value": "\"➡ 1. \" || \"Duration \"",
12
+ "type": "VTL|MD"
13
+ },
14
+ "description": { "value": "\"Description\"", "type": "VTL|MD" },
15
+ "conditionFilter": { "value": "true", "type": "VTL" },
16
+ "response": { "name": "DUREE" }
17
+ }
18
+ ],
19
+ "variables": [
20
+ {
21
+ "variableType": "COLLECTED",
22
+ "name": "DUREE",
23
+ "values": {
24
+ "PREVIOUS": null,
25
+ "COLLECTED": "PT12H50M",
26
+ "FORCED": null,
27
+ "EDITED": null,
28
+ "INPUTED": null
29
+ }
30
+ }
31
+ ]
32
+ }
@@ -3,14 +3,19 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = exports.ReadOnly = exports.Default = void 0;
6
+ exports["default"] = exports.ReadOnly = exports.Filled = exports.Default = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _orchestrator = _interopRequireDefault(require("../utils/orchestrator"));
9
9
  var _sourceRoster = _interopRequireDefault(require("./source-roster"));
10
10
  var _defaultArgTypes = _interopRequireDefault(require("../utils/default-arg-types"));
11
+ var _e2e = require("../../../tests/utils/e2e");
12
+ var _timer = require("../../../tests/utils/timer");
11
13
  var _jsxRuntime = require("react/jsx-runtime");
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
15
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
16
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
17
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
18
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
14
19
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
20
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
16
21
  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; }
@@ -38,4 +43,82 @@ ReadOnly.args = {
38
43
  id: 'roster-for-loop',
39
44
  source: _sourceRoster["default"],
40
45
  readOnly: true
41
- };
46
+ };
47
+ var Filled = Template.bind({});
48
+ exports.Filled = Filled;
49
+ Filled.args = {
50
+ id: 'roster-for-loop',
51
+ source: _sourceRoster["default"]
52
+ };
53
+ Filled.play = /*#__PURE__*/function () {
54
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
55
+ var args, canvasElement, page;
56
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
57
+ while (1) switch (_context.prev = _context.next) {
58
+ case 0:
59
+ args = _ref.args, canvasElement = _ref.canvasElement;
60
+ page = (0, _e2e.playwrightToUserEvent)(canvasElement);
61
+ _context.next = 4;
62
+ return (0, _timer.sleep)(100);
63
+ case 4:
64
+ _context.next = 6;
65
+ return page.getByRole('button', {
66
+ name: 'Ajouter un individu'
67
+ }).click();
68
+ case 6:
69
+ _context.next = 8;
70
+ return page.getByLabel('Prénom', {
71
+ index: 0
72
+ }).fill('John');
73
+ case 8:
74
+ _context.next = 10;
75
+ return page.getByLabel('Prénom', {
76
+ index: 1
77
+ }).fill('Jane');
78
+ case 10:
79
+ _context.next = 12;
80
+ return page.getByRole('button', {
81
+ name: 'Next'
82
+ }).click();
83
+ case 12:
84
+ _context.next = 14;
85
+ return page.getByLabel('John, quel est vôtre âge ?').fill('18');
86
+ case 14:
87
+ _context.next = 16;
88
+ return page.getByRole('button', {
89
+ name: 'Next'
90
+ }).click();
91
+ case 16:
92
+ _context.next = 18;
93
+ return page.getByLabel('Jane, quel est vôtre âge ?').fill('21');
94
+ case 18:
95
+ _context.next = 20;
96
+ return page.getByLabel(/Page/).fill('2.1#1');
97
+ case 20:
98
+ _context.next = 22;
99
+ return page.getByRole('button', {
100
+ name: /Go to page/
101
+ }).click();
102
+ case 22:
103
+ _context.next = 24;
104
+ return page.getByRole('button', {
105
+ name: 'Next'
106
+ }).click();
107
+ case 24:
108
+ _context.next = 26;
109
+ return page.getByRole('button', {
110
+ name: 'Next'
111
+ }).click();
112
+ case 26:
113
+ _context.next = 28;
114
+ return page.getByText('End').shouldBeVisible();
115
+ case 28:
116
+ case "end":
117
+ return _context.stop();
118
+ }
119
+ }, _callee);
120
+ }));
121
+ return function (_x) {
122
+ return _ref2.apply(this, arguments);
123
+ };
124
+ }();
@@ -9,9 +9,9 @@ require("./custom-lunatic.scss");
9
9
  require("./orchestrator.scss");
10
10
  var lunatic = _interopRequireWildcard(require("../.."));
11
11
  var _react = _interopRequireWildcard(require("react"));
12
+ var _logger = require("../../utils/logger");
12
13
  var _overview = require("./overview");
13
14
  var _waiting = _interopRequireDefault(require("./waiting"));
14
- var _logger = require("../../utils/logger");
15
15
  var _jsxRuntime = require("react/jsx-runtime");
16
16
  var _excluded = ["source", "data", "management", "shortcut", "activeControls", "features", "initialPage", "getStoreInfo", "missing", "missingStrategy", "missingShortcut", "autoSuggesterLoading", "addExternal", "preferences", "custom", "showOverview", "filterDescription", "getReferentiel", "dontKnowButton", "refusedButton", "readOnly"],
17
17
  _excluded2 = ["id", "componentType", "response", "storeName", "conditionFilter"];
@@ -36,7 +36,8 @@ function getStoreInfoRequired() {
36
36
  }
37
37
  function DevOptions(_ref) {
38
38
  var goToPage = _ref.goToPage,
39
- getData = _ref.getData;
39
+ getData = _ref.getData,
40
+ lastReachedPage = _ref.lastReachedPage;
40
41
  var _useState = (0, _react.useState)(1),
41
42
  _useState2 = _slicedToArray(_useState, 2),
42
43
  toPage = _useState2[0],
@@ -63,6 +64,13 @@ function DevOptions(_ref) {
63
64
  });
64
65
  },
65
66
  children: "Go to page ".concat(toPage)
67
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Button, {
68
+ onClick: function onClick() {
69
+ return goToPage({
70
+ page: "".concat(lastReachedPage)
71
+ });
72
+ },
73
+ children: "Go to lastReachedPage : ".concat(lastReachedPage)
66
74
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Input, {
67
75
  id: "page-to-jump",
68
76
  value: toPage,
@@ -78,6 +86,7 @@ function Pager(_ref2) {
78
86
  var goPrevious = _ref2.goPrevious,
79
87
  goNext = _ref2.goNext,
80
88
  goToPage = _ref2.goToPage,
89
+ lastReachedPage = _ref2.lastReachedPage,
81
90
  isLast = _ref2.isLast,
82
91
  isFirst = _ref2.isFirst,
83
92
  pageTag = _ref2.pageTag,
@@ -101,7 +110,8 @@ function Pager(_ref2) {
101
110
  children: ["PAGE: ", pageTag]
102
111
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(DevOptions, {
103
112
  goToPage: goToPage,
104
- getData: getData
113
+ getData: getData,
114
+ lastReachedPage: lastReachedPage
105
115
  })]
106
116
  });
107
117
  }
@@ -172,6 +182,7 @@ function OrchestratorForStories(_ref3) {
172
182
  goPreviousPage = _lunatic$useLunatic.goPreviousPage,
173
183
  goNextPage = _lunatic$useLunatic.goNextPage,
174
184
  goToPage = _lunatic$useLunatic.goToPage,
185
+ pager = _lunatic$useLunatic.pager,
175
186
  pageTag = _lunatic$useLunatic.pageTag,
176
187
  isFirstPage = _lunatic$useLunatic.isFirstPage,
177
188
  isLastPage = _lunatic$useLunatic.isLastPage,
@@ -181,6 +192,7 @@ function OrchestratorForStories(_ref3) {
181
192
  getData = _lunatic$useLunatic.getData,
182
193
  Provider = _lunatic$useLunatic.Provider;
183
194
  var components = getComponents();
195
+ var lastReachedPage = pager.lastReachedPage;
184
196
  var _useState3 = (0, _react.useState)({}),
185
197
  _useState4 = _slicedToArray(_useState3, 2),
186
198
  errorActive = _useState4[0],
@@ -239,6 +251,7 @@ function OrchestratorForStories(_ref3) {
239
251
  goPrevious: goPreviousPage,
240
252
  goNext: handleGoNext,
241
253
  goToPage: goToPage,
254
+ lastReachedPage: lastReachedPage,
242
255
  isLast: isLastPage,
243
256
  isFirst: isFirstPage,
244
257
  pageTag: pageTag,
@@ -69,6 +69,8 @@ var variables = {
69
69
  var fakeExecute = function fakeExecute(bindings) {
70
70
  return function (expression) {
71
71
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
72
+ // Assume this code doesn't provide vulnerabilities (only in test)
73
+ // eslint-disable-next-line no-new-func
72
74
  return _construct(Function, _toConsumableArray(Object.keys(bindings)).concat(["return ".concat(expression.value)])).apply(void 0, _toConsumableArray(Object.values(bindings).map(function (value) {
73
75
  return options.iteration !== undefined && Array.isArray(value) ? value[options.iteration] : value;
74
76
  })));
@@ -81,12 +81,6 @@ Object.defineProperty(exports, "isPaginatedLoop", {
81
81
  return _isPaginatedLoop["default"];
82
82
  }
83
83
  });
84
- Object.defineProperty(exports, "loadSuggester", {
85
- enumerable: true,
86
- get: function get() {
87
- return _loadSuggesters["default"];
88
- }
89
- });
90
84
  Object.defineProperty(exports, "useComponentsFromState", {
91
85
  enumerable: true,
92
86
  get: function get() {
@@ -95,15 +89,14 @@ Object.defineProperty(exports, "useComponentsFromState", {
95
89
  });
96
90
  var _checkLoops = _interopRequireDefault(require("./check-loops"));
97
91
  var _createMapPages = _interopRequireDefault(require("./create-map-pages"));
98
- var _isPaginatedLoop = _interopRequireDefault(require("./is-paginated-loop"));
99
- var _getComponentsFromState = _interopRequireDefault(require("./get-components-from-state"));
100
- var _useComponentsFromState = _interopRequireDefault(require("./use-components-from-state"));
101
- var _pageTag = require("./page-tag");
102
- var _isFirstLastPage = _interopRequireDefault(require("./is-First-last-page"));
103
- var _executeExpression = _interopRequireDefault(require("./execute-expression"));
104
92
  var _executeConditionFilter = _interopRequireDefault(require("./execute-condition-filter"));
93
+ var _executeExpression = _interopRequireDefault(require("./execute-expression"));
105
94
  var _fillComponentExpressions = _interopRequireDefault(require("./fill-components/fill-component-expressions"));
106
- var _loadSuggesters = _interopRequireDefault(require("./load-suggesters"));
107
95
  var _getCompatibleVtlExpression = _interopRequireDefault(require("./get-compatible-vtl-expression"));
96
+ var _getComponentsFromState = _interopRequireDefault(require("./get-components-from-state"));
108
97
  var _getErrorsWithoutEmptyValue = _interopRequireDefault(require("./get-errors-without-empty-value"));
98
+ var _isFirstLastPage = _interopRequireDefault(require("./is-First-last-page"));
99
+ var _isPaginatedLoop = _interopRequireDefault(require("./is-paginated-loop"));
100
+ var _pageTag = require("./page-tag");
101
+ var _useComponentsFromState = _interopRequireDefault(require("./use-components-from-state"));
109
102
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -27,9 +27,7 @@ function autoExploreLoop(state) {
27
27
  newPager.page = firstSubPage[0].toString();
28
28
  newPager.subPage = firstSubPage[1] - 1; // Subpage starts at 0
29
29
  newPager.nbSubPages = maxSubPage;
30
- newPager.nbIterations = state.executeExpression(page.iterations, {
31
- iteration: newPager.iteration
32
- });
30
+ newPager.nbIterations = state.executeExpression(page.iterations);
33
31
  newPager.iteration = isForward ? 0 : newPager.nbIterations - 1;
34
32
  }
35
33
  return _objectSpread(_objectSpread({}, state), {}, {
@@ -51,9 +51,7 @@ function reduceGoToPage(state, action) {
51
51
  if (action.payload.subPage !== undefined) {
52
52
  var _parentPage$subPages;
53
53
  newPager.nbSubPages = (_parentPage$subPages = parentPage.subPages) === null || _parentPage$subPages === void 0 ? void 0 : _parentPage$subPages.length;
54
- newPager.nbIterations = state.executeExpression(parentPage.iterations, {
55
- iteration: newPager.iteration
56
- });
54
+ newPager.nbIterations = state.executeExpression(parentPage.iterations);
57
55
  }
58
56
 
59
57
  // Prevent an out of bound iteration
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
  var _commons = require("../commons");
8
- var _pageTag = require("../commons/page-tag");
9
8
  var _compose = _interopRequireDefault(require("../commons/compose"));
9
+ var _pageTag = require("../commons/page-tag");
10
10
  var _overviewOnInit = require("./overview/overview-on-init");
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
12
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
@@ -35,14 +35,14 @@ function getInitalValueFromCollected(variable, data) {
35
35
  var _data$name = data[name],
36
36
  COLLECTED = _data$name.COLLECTED,
37
37
  FORCED = _data$name.FORCED;
38
- fromData = COLLECTED || FORCED;
38
+ fromData = COLLECTED !== null && COLLECTED !== void 0 ? COLLECTED : FORCED;
39
39
  }
40
40
  if ('values' in variable && variable.values) {
41
41
  var _fromData;
42
42
  var _variable$values = variable.values,
43
43
  _COLLECTED = _variable$values.COLLECTED,
44
44
  _FORCED = _variable$values.FORCED;
45
- return (_fromData = fromData) !== null && _fromData !== void 0 ? _fromData : _FORCED || _COLLECTED;
45
+ return (_fromData = fromData) !== null && _fromData !== void 0 ? _fromData : _FORCED !== null && _FORCED !== void 0 ? _FORCED : _COLLECTED;
46
46
  }
47
47
  return undefined;
48
48
  }
@@ -171,6 +171,7 @@ function reduceOnInit(state, action) {
171
171
  var source = payload.source,
172
172
  data = payload.data,
173
173
  initialPage = payload.initialPage,
174
+ lastReachedPage = payload.lastReachedPage,
174
175
  features = payload.features,
175
176
  handleChange = payload.handleChange,
176
177
  preferences = payload.preferences,
@@ -202,7 +203,7 @@ function reduceOnInit(state, action) {
202
203
  nbSubPages: undefined,
203
204
  iteration: undefined,
204
205
  nbIterations: undefined,
205
- lastReachedPage: initialPage
206
+ lastReachedPage: lastReachedPage !== null && lastReachedPage !== void 0 ? lastReachedPage : initialPage
206
207
  };
207
208
  var _isFirstLastPage = (0, _commons.isFirstLastPage)(pager),
208
209
  isFirstPage = _isFirstLastPage.isFirstPage,
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _source = _interopRequireDefault(require("../../stories/radio/source.json"));
5
+ var _lunatic = require("../../../tests/utils/lunatic");
6
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
7
+ (0, _vitest.describe)('reduce-on-init', function () {
8
+ (0, _vitest.describe)('init variables', function () {
9
+ (0, _vitest.it)('should init false variable correctly', function () {
10
+ var state = (0, _lunatic.generateState)(_source["default"], {
11
+ Q2: false
12
+ });
13
+ (0, _vitest.expect)(state.variables).toHaveProperty('Q2');
14
+ (0, _vitest.expect)(state.variables.Q2.value).toEqual(false);
15
+ });
16
+ });
17
+ });
@@ -56,6 +56,8 @@ function useLunatic(source) {
56
56
  shortcut = _ref$shortcut === void 0 ? false : _ref$shortcut,
57
57
  _ref$initialPage = _ref.initialPage,
58
58
  initialPage = _ref$initialPage === void 0 ? '1' : _ref$initialPage,
59
+ _ref$lastReachedPage = _ref.lastReachedPage,
60
+ lastReachedPage = _ref$lastReachedPage === void 0 ? undefined : _ref$lastReachedPage,
59
61
  _ref$autoSuggesterLoa = _ref.autoSuggesterLoading,
60
62
  autoSuggesterLoading = _ref$autoSuggesterLoa === void 0 ? false : _ref$autoSuggesterLoa,
61
63
  _ref$activeControls = _ref.activeControls,
@@ -166,6 +168,7 @@ function useLunatic(source) {
166
168
  source: source,
167
169
  data: data,
168
170
  initialPage: initialPage,
171
+ lastReachedPage: lastReachedPage,
169
172
  features: features,
170
173
  preferences: preferences,
171
174
  savingType: savingType,
@@ -176,7 +179,7 @@ function useLunatic(source) {
176
179
  goToPage: goToPage,
177
180
  withOverview: withOverview
178
181
  }));
179
- }, [source, data, initialPage, features, preferences, savingType, management, shortcut, handleChange, activeControls, withOverview, goToPage]);
182
+ }, [source, data, initialPage, features, preferences, savingType, management, shortcut, handleChange, activeControls, withOverview, goToPage, lastReachedPage]);
180
183
  (0, _react.useEffect)(function () {
181
184
  dispatch(actions.updateState({
182
185
  getSuggesterStatus: getSuggesterStatus