@inseefr/lunatic 2.7.17 → 2.7.19

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 CHANGED
@@ -124,7 +124,8 @@ Lunatic uses webWorkers to take the load off the main execution frame (e.g. list
124
124
 
125
125
  Workers are normally installed when the library is installed (postinstall scripts). If this is not the case, you can always manually run the command `npx @inseefr/lunatic workers` at the root of your project to add Lunatic workers to your project.
126
126
 
127
- Lunatic workers are added to the `public/workers` folder of the current project when the library is installed.
127
+ By default: Lunatic workers are added to the `public/workers` folder of the current project when the library is installed.
128
+ If you want to install inside another folder, just run `npx @inseefr/lunatic workers my-custom-folder`. Workers will be available to the `my-custom-folder/workers` folder of the current project.
128
129
 
129
130
  If a new version of Lunatic offers new workers, they will be automatically updated.
130
131
  This ensures that you always have the right version of workers for the version of Lunatic you're using.
@@ -22,3 +22,7 @@ export declare function firstValueItem<T = unknown>(items: T | T[]): T | undefin
22
22
  * - subArray([1, 2, 3]) // [[1], [1, 2], [1, 2, 3]]
23
23
  */
24
24
  export declare function subArrays<T = unknown>(items: T[] | T): T[][];
25
+ /**
26
+ * Calculates the depth of an array
27
+ */
28
+ export declare function depth(arr: unknown, base?: number): number;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.cleaningBehaviour = cleaningBehaviour;
7
+ var _array = require("../../../../utils/array");
7
8
  /**
8
9
  * Cleaning behaviour for the store
9
10
  * When a variable changes, other variables can be reset
@@ -32,8 +33,12 @@ function cleaningBehaviour(store, cleaning) {
32
33
  if (skipCleaning) {
33
34
  continue;
34
35
  }
35
- store.set(variableName, getValueAtIteration(initialValues[variableName], iteration), {
36
- iteration: iteration
36
+
37
+ // Variable may be top level, so we need to deduce expected iteration
38
+ var variableDepth = (0, _array.depth)(initialValues[variableName]);
39
+ var variableIteration = variableDepth === 0 ? undefined : iteration === null || iteration === void 0 ? void 0 : iteration.slice(0, (0, _array.depth)(initialValues[variableName]));
40
+ store.set(variableName, getValueAtIteration(initialValues[variableName], variableIteration), {
41
+ iteration: variableIteration
37
42
  });
38
43
  } catch (e) {
39
44
  // If we have an error, skip this cleaning
@@ -287,6 +287,8 @@ var _lunaticVariablesStore = require("./lunatic-variables-store");
287
287
  READY: {
288
288
  PRENOM: 'READY'
289
289
  }
290
+ }, {
291
+ PRENOM: [null]
290
292
  });
291
293
  variables.set('READY', false, {
292
294
  iteration: [1]
@@ -308,6 +310,21 @@ var _lunaticVariablesStore = require("./lunatic-variables-store");
308
310
  });
309
311
  (0, _vitest.expect)(variables.get('PRENOM')).toEqual(['John', null, 'Marc']);
310
312
  });
313
+ (0, _vitest.it)('should clean root variables even when in an iteration', function () {
314
+ variables.set('PRENOM', 'John');
315
+ variables.set('READY', [true, true, true]);
316
+ (0, _cleaningBehaviour.cleaningBehaviour)(variables, {
317
+ READY: {
318
+ PRENOM: 'READY'
319
+ }
320
+ }, {
321
+ PRENOM: null
322
+ });
323
+ variables.set('READY', false, {
324
+ iteration: [1]
325
+ });
326
+ (0, _vitest.expect)(variables.get('PRENOM')).toEqual(null);
327
+ });
311
328
  });
312
329
  (0, _vitest.describe)('missing', function () {
313
330
  (0, _vitest.beforeEach)(function () {
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.depth = depth;
6
7
  exports.firstValueItem = firstValueItem;
7
8
  exports.getAtIndex = getAtIndex;
8
9
  exports.resizeArray = resizeArray;
@@ -115,4 +116,15 @@ function subArrays(items) {
115
116
  arrays.push(items.slice(0, i));
116
117
  }
117
118
  return arrays;
119
+ }
120
+
121
+ /**
122
+ * Calculates the depth of an array
123
+ */
124
+ function depth(arr) {
125
+ var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
126
+ if (!Array.isArray(arr)) {
127
+ return base;
128
+ }
129
+ return depth(arr[0], base + 1);
118
130
  }
@@ -14,7 +14,7 @@ var WorkerEnum = exports.WorkerEnum = /*#__PURE__*/function (WorkerEnum) {
14
14
  return WorkerEnum;
15
15
  }({});
16
16
  var version = _package["default"].workersVersion;
17
- var DEFAULT_BASE_PATH = 'workers';
17
+ var DEFAULT_BASE_PATH = "".concat(window.location.origin, "/workers");
18
18
  var WORKER_PATH = {
19
19
  APPEND: "lunatic-append-worker-".concat(version, ".js"),
20
20
  SEARCH: "lunatic-search-worker-".concat(version, ".js"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inseefr/lunatic",
3
- "version": "2.7.17",
3
+ "version": "2.7.19",
4
4
  "workersVersion": "0.3.0",
5
5
  "description": "Library of questionnaire components",
6
6
  "repository": {
@@ -3,7 +3,15 @@ const path = require('path');
3
3
 
4
4
  const version = lunaticPackageJson.workersVersion;
5
5
 
6
- const currentPublicFolder = path.resolve(`${process.cwd()}/public/workers`);
6
+ /**
7
+ * process.argv return an array, for example, for this command "node ./my-script.js hello"
8
+ * process.argv = ["node", "./my-script.js", "hello"], process.argv[2] = "hello" (or undefined if no argument)
9
+ */
10
+ const getPublicFolder = () => process.argv[2] || 'public';
11
+
12
+ const currentPublicFolder = path.resolve(
13
+ `${process.cwd()}/${getPublicFolder()}/workers`
14
+ );
7
15
  const workersReleaseFolder = path.resolve(__dirname, '../../workers-release');
8
16
 
9
17
  const workersPath = {