@inseefr/lunatic 3.5.0-rc.2 → 3.5.0-rc.3

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/esm/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { ModalControls } from './components/shared/ModalControls/ModalControls';
7
7
  export { Button } from './components/shared/Button/Button';
8
8
  export { LunaticComponents } from './components/LunaticComponents';
9
9
  export { useLunatic } from './use-lunatic/use-lunatic';
10
- export { useArticulation } from './hooks/useArticulation';
10
+ export { getArticulation } from './utils/getArticulation';
11
11
  export type { LunaticComponentDefinition, LunaticControl, LunaticData, LunaticValues, LunaticError, LunaticExpression, LunaticVariable, LunaticCollectedValue, LunaticStateVariable, LunaticState, LunaticPager, LunaticOptions, LunaticChangesHandler, } from './use-lunatic/type';
12
12
  export type { LunaticComponentProps, LunaticExtraProps, } from './components/type';
13
13
  export type { LunaticSlotComponents } from './components/shared/HOC/slottableComponent';
package/esm/index.js CHANGED
@@ -7,7 +7,7 @@ export { ModalControls } from './components/shared/ModalControls/ModalControls';
7
7
  export { Button } from './components/shared/Button/Button';
8
8
  export { LunaticComponents } from './components/LunaticComponents';
9
9
  export { useLunatic } from './use-lunatic/use-lunatic';
10
- export { useArticulation } from './hooks/useArticulation';
10
+ export { getArticulation } from './utils/getArticulation';
11
11
  // Export errors (useful for typeof)
12
12
  export { VTLMissingDependencies, VTLExpressionError, VTLMissingDependency, VTLInterpretationError, } from './use-lunatic/commons/variables/errors';
13
13
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  import type { LunaticSource } from '../type.source';
2
- import type { LunaticData } from '../use-lunatic/type';
2
+ import type { LunaticData, PageTag } from '../use-lunatic/type';
3
3
  import { type ReactNode } from 'react';
4
4
  type ArticulationItem = {
5
5
  label: string;
@@ -13,12 +13,12 @@ type Item = {
13
13
  cells: {
14
14
  label: string;
15
15
  value: ReactNode;
16
- page?: string;
17
16
  }[];
18
17
  progress: number;
18
+ page: PageTag;
19
19
  };
20
20
  /**
21
- * Hook to get articulation state
21
+ * Retrieve the articulation state
22
22
  *
23
23
  * ## Why this hook
24
24
  *
@@ -50,7 +50,7 @@ type Item = {
50
50
  * - source is the ID of the roundabout component
51
51
  * - items define the field to extract from the roundabout data
52
52
  */
53
- export declare function useArticulation(source: LunaticSource & {
53
+ export declare function getArticulation(source: LunaticSource & {
54
54
  articulation: Articulation;
55
55
  }, data: LunaticData): {
56
56
  items: Item[];
@@ -1,9 +1,8 @@
1
1
  import { reducerInitializer } from '../use-lunatic/reducer/reducerInitializer';
2
- import { useMemo } from 'react';
3
- import { times } from '../utils/array';
4
- import { forceInt } from '../utils/number';
2
+ import { times } from './array';
3
+ import { forceInt } from './number';
5
4
  /**
6
- * Hook to get articulation state
5
+ * Retrieve the articulation state
7
6
  *
8
7
  * ## Why this hook
9
8
  *
@@ -35,19 +34,15 @@ import { forceInt } from '../utils/number';
35
34
  * - source is the ID of the roundabout component
36
35
  * - items define the field to extract from the roundabout data
37
36
  */
38
- export function useArticulation(source, data) {
39
- const roundabout = useMemo(() => findComponentById(source.components, source.articulation.source), [source]);
40
- const { variables } = useMemo(() => reducerInitializer({ source, data }), [source, data]);
41
- const iterations = useMemo(() => { var _a; return forceInt(variables.run((_a = roundabout === null || roundabout === void 0 ? void 0 : roundabout.iterations.value) !== null && _a !== void 0 ? _a : '0')); },
42
- // eslint-disable-next-line react-hooks/exhaustive-deps
43
- [source, data]);
44
- const rows = useMemo(() => {
45
- return times(iterations, (k) => source.articulation.items.map((item) => ({
46
- label: item.label,
47
- value: variables.run(item.value, { iteration: [k] }),
48
- })));
49
- // eslint-disable-next-line react-hooks/exhaustive-deps
50
- }, [source, data, iterations, roundabout === null || roundabout === void 0 ? void 0 : roundabout.progressVariable]);
37
+ export function getArticulation(source, data) {
38
+ var _a;
39
+ const roundabout = findComponentById(source.components, source.articulation.source);
40
+ const { variables } = reducerInitializer({ source, data });
41
+ const iterations = forceInt(variables.run((_a = roundabout === null || roundabout === void 0 ? void 0 : roundabout.iterations.value) !== null && _a !== void 0 ? _a : '0'));
42
+ const rows = times(iterations, (k) => source.articulation.items.map((item) => ({
43
+ label: item.label,
44
+ value: variables.run(item.value, { iteration: [k] }),
45
+ })));
51
46
  if (!roundabout) {
52
47
  return {
53
48
  items: [],
@@ -59,7 +54,9 @@ export function useArticulation(source, data) {
59
54
  return ({
60
55
  cells: row,
61
56
  progress: forceInt((_a = variables.get(roundabout.progressVariable, [k])) !== null && _a !== void 0 ? _a : -1),
62
- page: roundabout.page ? `${roundabout.page}.1#${k + 1}` : '1',
57
+ page: (roundabout.page
58
+ ? `${roundabout.page}.1#${k + 1}`
59
+ : '1'),
63
60
  });
64
61
  }),
65
62
  };
@@ -78,4 +75,4 @@ function findComponentById(components, id) {
78
75
  }
79
76
  return null;
80
77
  }
81
- //# sourceMappingURL=useArticulation.js.map
78
+ //# sourceMappingURL=getArticulation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getArticulation.js","sourceRoot":"","sources":["../../src/utils/getArticulation.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAE/E,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAqBpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,eAAe,CAC9B,MAAsD,EACtD,IAAiB;;IAEjB,MAAM,UAAU,GAAG,iBAAiB,CACnC,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,YAAY,CAAC,MAAM,CAC1B,CAAC;IACF,MAAM,EAAE,SAAS,EAAE,GAAG,kBAAkB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3D,MAAM,UAAU,GAAG,QAAQ,CAC1B,SAAS,CAAC,GAAG,CAAC,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,UAAU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C;YACvB,MAAM,KAAK,GAAG,iBAAiB,CAAC,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;YAClD,IAAI,KAAK,EAAE,CAAC;gBACX,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC"}
package/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { ModalControls } from './components/shared/ModalControls/ModalControls';
7
7
  export { Button } from './components/shared/Button/Button';
8
8
  export { LunaticComponents } from './components/LunaticComponents';
9
9
  export { useLunatic } from './use-lunatic/use-lunatic';
10
- export { useArticulation } from './hooks/useArticulation';
10
+ export { getArticulation } from './utils/getArticulation';
11
11
  export type { LunaticComponentDefinition, LunaticControl, LunaticData, LunaticValues, LunaticError, LunaticExpression, LunaticVariable, LunaticCollectedValue, LunaticStateVariable, LunaticState, LunaticPager, LunaticOptions, LunaticChangesHandler, } from './use-lunatic/type';
12
12
  export type { LunaticComponentProps, LunaticExtraProps, } from './components/type';
13
13
  export type { LunaticSlotComponents } from './components/shared/HOC/slottableComponent';
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VTLInterpretationError = exports.VTLMissingDependency = exports.VTLExpressionError = exports.VTLMissingDependencies = exports.useArticulation = exports.useLunatic = exports.LunaticComponents = exports.Button = exports.ModalControls = exports.components = void 0;
3
+ exports.VTLInterpretationError = exports.VTLMissingDependency = exports.VTLExpressionError = exports.VTLMissingDependencies = exports.getArticulation = exports.useLunatic = exports.LunaticComponents = exports.Button = exports.ModalControls = exports.components = void 0;
4
4
  /**
5
5
  * We should remove this export to avoid `import * as lunatic from "@inseefr/lunatic"` in orchestrators
6
6
  * but this is a breaking change
@@ -15,8 +15,8 @@ var LunaticComponents_1 = require("./components/LunaticComponents");
15
15
  Object.defineProperty(exports, "LunaticComponents", { enumerable: true, get: function () { return LunaticComponents_1.LunaticComponents; } });
16
16
  var use_lunatic_1 = require("./use-lunatic/use-lunatic");
17
17
  Object.defineProperty(exports, "useLunatic", { enumerable: true, get: function () { return use_lunatic_1.useLunatic; } });
18
- var useArticulation_1 = require("./hooks/useArticulation");
19
- Object.defineProperty(exports, "useArticulation", { enumerable: true, get: function () { return useArticulation_1.useArticulation; } });
18
+ var getArticulation_1 = require("./utils/getArticulation");
19
+ Object.defineProperty(exports, "getArticulation", { enumerable: true, get: function () { return getArticulation_1.getArticulation; } });
20
20
  // Export errors (useful for typeof)
21
21
  var errors_1 = require("./use-lunatic/commons/variables/errors");
22
22
  Object.defineProperty(exports, "VTLMissingDependencies", { enumerable: true, get: function () { return errors_1.VTLMissingDependencies; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inseefr/lunatic",
3
- "version": "3.5.0-rc.2",
3
+ "version": "3.5.0-rc.3",
4
4
  "description": "Library of questionnaire components",
5
5
  "repository": {
6
6
  "type": "git",
@@ -219,7 +219,6 @@
219
219
  "src/hooks/use-auto-focus.ts",
220
220
  "src/hooks/use-track-changes.ts",
221
221
  "src/hooks/use-why-render.ts",
222
- "src/hooks/useArticulation.ts",
223
222
  "src/hooks/useDebounce.ts",
224
223
  "src/hooks/useDocumentEvent.ts",
225
224
  "src/hooks/useKeyboardKey.ts",
@@ -458,6 +457,7 @@
458
457
  "src/utils/dom.ts",
459
458
  "src/utils/env.ts",
460
459
  "src/utils/function.ts",
460
+ "src/utils/getArticulation.ts",
461
461
  "src/utils/is-element.ts",
462
462
  "src/utils/is-object.ts",
463
463
  "src/utils/logger.ts",
@@ -1349,9 +1349,6 @@
1349
1349
  "esm/hooks/use-why-render.d.ts",
1350
1350
  "esm/hooks/use-why-render.js",
1351
1351
  "esm/hooks/use-why-render.js.map",
1352
- "esm/hooks/useArticulation.d.ts",
1353
- "esm/hooks/useArticulation.js",
1354
- "esm/hooks/useArticulation.js.map",
1355
1352
  "esm/hooks/useDebounce.d.ts",
1356
1353
  "esm/hooks/useDebounce.js",
1357
1354
  "esm/hooks/useDebounce.js.map",
@@ -1612,6 +1609,9 @@
1612
1609
  "esm/utils/function.d.ts",
1613
1610
  "esm/utils/function.js",
1614
1611
  "esm/utils/function.js.map",
1612
+ "esm/utils/getArticulation.d.ts",
1613
+ "esm/utils/getArticulation.js",
1614
+ "esm/utils/getArticulation.js.map",
1615
1615
  "esm/utils/is-element.d.ts",
1616
1616
  "esm/utils/is-element.js",
1617
1617
  "esm/utils/is-element.js.map",
@@ -1675,9 +1675,6 @@
1675
1675
  "hooks/use-why-render.d.ts",
1676
1676
  "hooks/use-why-render.js",
1677
1677
  "hooks/use-why-render.js.map",
1678
- "hooks/useArticulation.d.ts",
1679
- "hooks/useArticulation.js",
1680
- "hooks/useArticulation.js.map",
1681
1678
  "hooks/useDebounce.d.ts",
1682
1679
  "hooks/useDebounce.js",
1683
1680
  "hooks/useDebounce.js.map",
@@ -1939,6 +1936,9 @@
1939
1936
  "utils/function.d.ts",
1940
1937
  "utils/function.js",
1941
1938
  "utils/function.js.map",
1939
+ "utils/getArticulation.d.ts",
1940
+ "utils/getArticulation.js",
1941
+ "utils/getArticulation.js.map",
1942
1942
  "utils/is-element.d.ts",
1943
1943
  "utils/is-element.js",
1944
1944
  "utils/is-element.js.map",
package/src/index.ts CHANGED
@@ -8,7 +8,7 @@ export { Button } from './components/shared/Button/Button';
8
8
 
9
9
  export { LunaticComponents } from './components/LunaticComponents';
10
10
  export { useLunatic } from './use-lunatic/use-lunatic';
11
- export { useArticulation } from './hooks/useArticulation';
11
+ export { getArticulation } from './utils/getArticulation';
12
12
 
13
13
  export type {
14
14
  LunaticComponentDefinition,
@@ -1,11 +1,11 @@
1
1
  import Orchestrator from '../../utils/orchestrator';
2
2
  import source from './roundabout.json';
3
3
  import type { Meta, StoryObj } from '@storybook/react';
4
- import { useState } from 'react';
5
- import { useArticulation } from '../../../hooks/useArticulation';
4
+ import { useMemo, useState } from 'react';
5
+ import { getArticulation } from '../../../utils/getArticulation';
6
6
 
7
- type Source = Parameters<typeof useArticulation>[0];
8
- type Data = Parameters<typeof useArticulation>[1];
7
+ type Source = Parameters<typeof getArticulation>[0];
8
+ type Data = Parameters<typeof getArticulation>[1];
9
9
 
10
10
  type Props = {
11
11
  source: Source;
@@ -15,7 +15,10 @@ type Props = {
15
15
  function StoryComponent({ source, data }: Props) {
16
16
  const [page, setPage] = useState(null as null | string);
17
17
  const gotoNav = () => setPage(null);
18
- const { items } = useArticulation(source, data);
18
+ const { items } = useMemo(
19
+ () => getArticulation(source, data),
20
+ [source, data]
21
+ );
19
22
 
20
23
  if (page) {
21
24
  return (
@@ -3,11 +3,11 @@ import type {
3
3
  ComponentRoundaboutDefinition,
4
4
  LunaticSource,
5
5
  } from '../type.source';
6
- import type { LunaticData } from '../use-lunatic/type';
6
+ import type { LunaticData, PageTag } from '../use-lunatic/type';
7
7
  import { reducerInitializer } from '../use-lunatic/reducer/reducerInitializer';
8
- import { type ReactNode, useMemo } from 'react';
9
- import { times } from '../utils/array';
10
- import { forceInt } from '../utils/number';
8
+ import { type ReactNode } from 'react';
9
+ import { times } from './array';
10
+ import { forceInt } from './number';
11
11
 
12
12
  type ArticulationItem = {
13
13
  label: string;
@@ -23,13 +23,13 @@ type Item = {
23
23
  cells: {
24
24
  label: string;
25
25
  value: ReactNode;
26
- page?: string;
27
26
  }[];
28
27
  progress: number; // -1: not completed, 0: started, 1: finished
28
+ page: PageTag;
29
29
  };
30
30
 
31
31
  /**
32
- * Hook to get articulation state
32
+ * Retrieve the articulation state
33
33
  *
34
34
  * ## Why this hook
35
35
  *
@@ -61,35 +61,26 @@ type Item = {
61
61
  * - source is the ID of the roundabout component
62
62
  * - items define the field to extract from the roundabout data
63
63
  */
64
- export function useArticulation(
64
+ export function getArticulation(
65
65
  source: LunaticSource & { articulation: Articulation },
66
66
  data: LunaticData
67
67
  ): { items: Item[] } {
68
- const roundabout = useMemo(
69
- () => findComponentById(source.components, source.articulation.source),
70
- [source]
68
+ const roundabout = findComponentById(
69
+ source.components,
70
+ source.articulation.source
71
71
  );
72
- const { variables } = useMemo(
73
- () => reducerInitializer({ source, data }),
74
- [source, data]
72
+ const { variables } = reducerInitializer({ source, data });
73
+ const iterations = forceInt(
74
+ variables.run(roundabout?.iterations.value ?? '0')
75
75
  );
76
76
 
77
- const iterations = useMemo(
78
- () => forceInt(variables.run(roundabout?.iterations.value ?? '0')),
79
- // eslint-disable-next-line react-hooks/exhaustive-deps
80
- [source, data]
77
+ const rows = times(iterations, (k) =>
78
+ source.articulation.items.map((item) => ({
79
+ label: item.label,
80
+ value: variables.run(item.value, { iteration: [k] }) as ReactNode,
81
+ }))
81
82
  );
82
83
 
83
- const rows = useMemo(() => {
84
- return times(iterations, (k) =>
85
- source.articulation.items.map((item) => ({
86
- label: item.label,
87
- value: variables.run(item.value, { iteration: [k] }) as ReactNode,
88
- }))
89
- );
90
- // eslint-disable-next-line react-hooks/exhaustive-deps
91
- }, [source, data, iterations, roundabout?.progressVariable]);
92
-
93
84
  if (!roundabout) {
94
85
  return {
95
86
  items: [],
@@ -100,7 +91,9 @@ export function useArticulation(
100
91
  items: rows.map((row, k) => ({
101
92
  cells: row,
102
93
  progress: forceInt(variables.get(roundabout.progressVariable, [k]) ?? -1),
103
- page: roundabout.page ? `${roundabout.page}.1#${k + 1}` : '1',
94
+ page: (roundabout.page
95
+ ? `${roundabout.page}.1#${k + 1}`
96
+ : '1') as PageTag,
104
97
  })),
105
98
  };
106
99
  }