@inseefr/lunatic 3.6.15-rc.0 → 3.6.15-rc.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.
Files changed (51) hide show
  1. package/components/Roundabout/Roundabout.js +8 -3
  2. package/components/Roundabout/Roundabout.js.map +1 -1
  3. package/esm/components/Roundabout/Roundabout.js +8 -3
  4. package/esm/components/Roundabout/Roundabout.js.map +1 -1
  5. package/esm/hooks/{useMultiMode.d.ts → useMultimode.d.ts} +2 -2
  6. package/esm/hooks/{useMultiMode.js → useMultimode.js} +5 -5
  7. package/esm/hooks/{useMultiMode.js.map → useMultimode.js.map} +1 -1
  8. package/esm/index.d.ts +2 -1
  9. package/esm/index.js +2 -1
  10. package/esm/index.js.map +1 -1
  11. package/esm/type.source.d.ts +2 -24
  12. package/esm/type.source.js +0 -1
  13. package/esm/type.source.js.map +1 -1
  14. package/esm/use-lunatic/reducer/reduce-go-next-page.js +2 -1
  15. package/esm/use-lunatic/reducer/reduce-go-next-page.js.map +1 -1
  16. package/esm/use-lunatic/type.d.ts +1 -1
  17. package/esm/use-lunatic/use-lunatic.js +3 -3
  18. package/{utils/getArticulation.d.ts → esm/utils/getArticulationState.d.ts} +8 -5
  19. package/esm/utils/{getArticulation.js → getArticulationState.js} +10 -6
  20. package/esm/utils/getArticulationState.js.map +1 -0
  21. package/hooks/{useMultiMode.d.ts → useMultimode.d.ts} +2 -2
  22. package/hooks/{useMultiMode.js → useMultimode.js} +7 -7
  23. package/hooks/{useMultiMode.js.map → useMultimode.js.map} +1 -1
  24. package/index.d.ts +2 -1
  25. package/index.js +5 -3
  26. package/index.js.map +1 -1
  27. package/package.json +15 -15
  28. package/src/components/Roundabout/Roundabout.tsx +8 -3
  29. package/src/hooks/{useMultiMode.ts → useMultimode.ts} +4 -4
  30. package/src/index.ts +2 -1
  31. package/src/stories/behaviour/articulation/articulation.stories.tsx +4 -4
  32. package/src/stories/utils/Orchestrator.tsx +2 -2
  33. package/src/stories/utils/OrchestratorSidebar.tsx +7 -7
  34. package/src/type.source.ts +2 -25
  35. package/src/use-lunatic/reducer/reduce-go-next-page.ts +2 -1
  36. package/src/use-lunatic/type.ts +1 -1
  37. package/src/use-lunatic/use-lunatic.ts +3 -3
  38. package/src/utils/{getArticulation.ts → getArticulationState.ts} +13 -6
  39. package/tsconfig.build.tsbuildinfo +1 -1
  40. package/type.source.d.ts +2 -24
  41. package/type.source.js +0 -1
  42. package/type.source.js.map +1 -1
  43. package/use-lunatic/reducer/reduce-go-next-page.js +2 -1
  44. package/use-lunatic/reducer/reduce-go-next-page.js.map +1 -1
  45. package/use-lunatic/type.d.ts +1 -1
  46. package/use-lunatic/use-lunatic.js +3 -3
  47. package/{esm/utils/getArticulation.d.ts → utils/getArticulationState.d.ts} +8 -5
  48. package/utils/{getArticulation.js → getArticulationState.js} +13 -7
  49. package/utils/getArticulationState.js.map +1 -0
  50. package/esm/utils/getArticulation.js.map +0 -1
  51. package/utils/getArticulation.js.map +0 -1
@@ -1,11 +1,11 @@
1
1
  import source from './roundabout.json';
2
2
  import type { Meta, StoryObj } from '@storybook/react';
3
3
  import { useMemo, useState } from 'react';
4
- import { getArticulation } from '../../../utils/getArticulation';
4
+ import { getArticulationState } from '../../../utils/getArticulationState';
5
5
  import { Orchestrator } from '../../utils/Orchestrator';
6
6
 
7
- type Source = Parameters<typeof getArticulation>[0];
8
- type Data = Parameters<typeof getArticulation>[1];
7
+ type Source = Parameters<typeof getArticulationState>[0];
8
+ type Data = Parameters<typeof getArticulationState>[1];
9
9
 
10
10
  type Props = {
11
11
  source: Source;
@@ -16,7 +16,7 @@ function StoryComponent({ source, data }: Props) {
16
16
  const [page, setPage] = useState(null as null | string);
17
17
  const gotoNav = () => setPage(null);
18
18
  const { items } = useMemo(
19
- () => getArticulation(source, data),
19
+ () => getArticulationState(source, data),
20
20
  [source, data]
21
21
  );
22
22
 
@@ -98,7 +98,7 @@ function OrchestratorForStories(props: Readonly<Props>) {
98
98
  getData,
99
99
  Provider,
100
100
  hasPageResponse,
101
- getMultiMode,
101
+ getMultimode,
102
102
  } = useLunatic(source, data, {
103
103
  initialPage,
104
104
  disableFilters,
@@ -249,7 +249,7 @@ function OrchestratorForStories(props: Readonly<Props>) {
249
249
  pageTag={pageTag}
250
250
  pager={pager}
251
251
  hasPageResponse={hasPageResponse()}
252
- getMultiMode={props.multiMode ? getMultiMode : null}
252
+ getMultimode={props.multiMode ? getMultimode : null}
253
253
  onLogData={() => console.log('Data', getData(true))}
254
254
  onLogComponents={() => console.log('Components', components)}
255
255
  >
@@ -17,7 +17,7 @@ type Props = PropsWithChildren<
17
17
  > & {
18
18
  hasPageResponse: unknown;
19
19
  onLogData: () => void;
20
- getMultiMode: LunaticState['getMultiMode'] | null;
20
+ getMultimode: LunaticState['getMultimode'] | null;
21
21
  onLogComponents: () => void;
22
22
  };
23
23
 
@@ -30,7 +30,7 @@ export function OrchestratorSidebar({
30
30
  pageTag,
31
31
  pager,
32
32
  children,
33
- getMultiMode,
33
+ getMultimode,
34
34
  hasPageResponse,
35
35
  onLogData,
36
36
  onLogComponents,
@@ -116,9 +116,9 @@ export function OrchestratorSidebar({
116
116
  </li>
117
117
  </ul>
118
118
  </div>
119
- {getMultiMode && (
119
+ {getMultimode && (
120
120
  <div>
121
- <MultiMode getMultiMode={getMultiMode} />
121
+ <MultiMode getMultimode={getMultimode} />
122
122
  </div>
123
123
  )}
124
124
  {children}
@@ -126,10 +126,10 @@ export function OrchestratorSidebar({
126
126
  );
127
127
  }
128
128
 
129
- function MultiMode(props: Pick<LunaticState, 'getMultiMode'>) {
130
- const [state, setState] = useState<ReturnType<typeof props.getMultiMode>>({});
129
+ function MultiMode(props: Pick<LunaticState, 'getMultimode'>) {
130
+ const [state, setState] = useState<ReturnType<typeof props.getMultimode>>({});
131
131
  const onClick = () => {
132
- setState(props.getMultiMode);
132
+ setState(props.getMultimode);
133
133
  };
134
134
  return (
135
135
  <div className="space-y-2">
@@ -1,4 +1,3 @@
1
- /* eslint-disable */
2
1
  /**
3
2
  * This file was automatically generated by json-schema-to-typescript.
4
3
  * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
@@ -351,13 +350,13 @@ export type LunaticSource = {
351
350
  multimode?: {
352
351
  questionnaire: {
353
352
  rules: {
354
- [k: string]: VTLExpression1;
353
+ [k: string]: VTLExpression;
355
354
  };
356
355
  };
357
356
  leaf: {
358
357
  source: string;
359
358
  rules: {
360
- [k: string]: VTLExpression2;
359
+ [k: string]: VTLExpression;
361
360
  };
362
361
  };
363
362
  };
@@ -501,25 +500,3 @@ export type SuggesterDefinition = {
501
500
  */
502
501
  stopWords?: string[];
503
502
  };
504
- export type VTLExpression1 = {
505
- /**
506
- * Valid VTL Expression
507
- */
508
- value: string;
509
- /**
510
- * Variables used in the expression
511
- */
512
- bindingDependencies?: string[];
513
- type: 'VTL' | 'VTL|MD' | 'TXT';
514
- };
515
- export type VTLExpression2 = {
516
- /**
517
- * Valid VTL Expression
518
- */
519
- value: string;
520
- /**
521
- * Variables used in the expression
522
- */
523
- bindingDependencies?: string[];
524
- type: 'VTL' | 'VTL|MD' | 'TXT';
525
- };
@@ -5,6 +5,7 @@ import type { LunaticReducerState } from '../type';
5
5
  import { autoExploreLoop } from './commons/auto-explore-loop';
6
6
  import { reduceHandleChanges } from './reduce-handle-changes';
7
7
  import { ActionKind } from '../actions';
8
+ import { ArticulationState } from '../../utils/getArticulationState';
8
9
 
9
10
  export function reduceGoNextPage(
10
11
  state: LunaticReducerState
@@ -51,7 +52,7 @@ export function reduceGoNextPage(
51
52
  responses: [
52
53
  {
53
54
  name: firstComponent.progressVariable,
54
- value: 1,
55
+ value: ArticulationState.COMPLETED,
55
56
  iteration: [newState.previousPager.iteration],
56
57
  },
57
58
  ],
@@ -359,7 +359,7 @@ export type LunaticState = {
359
359
  */
360
360
  handleChanges: LunaticChangesHandler;
361
361
  /** Return the multimode state **/
362
- getMultiMode: () => Record<string, boolean>;
362
+ getMultimode: () => Record<string, boolean>;
363
363
  };
364
364
 
365
365
  /** Function taking as arguments the various changes the user has made. */
@@ -33,7 +33,7 @@ import { useRefSync } from '../hooks/useRefSync';
33
33
  import { ConsoleLogger } from './logger/ConsoleLogger';
34
34
  import { useWarnDepChange } from './hooks/useWarnDepChange';
35
35
  import { useCallbackOnNextRender } from './hooks/useCallbackOnNextRender';
36
- import { useMultiMode } from '../hooks/useMultiMode';
36
+ import { useMultimode } from '../hooks/useMultimode';
37
37
 
38
38
  const empty = {}; // Keep the same empty object (to avoid problem with useEffect dependencies)
39
39
  const DEFAULT_DATA = empty as LunaticData;
@@ -199,7 +199,7 @@ export function useLunatic(
199
199
  (variableNames?: string[]) => getData(false, variableNames)
200
200
  );
201
201
 
202
- const { getMultiMode } = useMultiMode(source, state.variables);
202
+ const { getMultimode } = useMultimode(source, state.variables);
203
203
 
204
204
  const pageTag = getPageTag(state.pager);
205
205
  const { isFirstPage, isLastPage } = isFirstLastPage(state.pager);
@@ -244,6 +244,6 @@ export function useLunatic(
244
244
  // Components
245
245
  Provider,
246
246
  handleChanges,
247
- getMultiMode,
247
+ getMultimode,
248
248
  } satisfies LunaticState;
249
249
  }
@@ -9,6 +9,12 @@ import { type ReactNode } from 'react';
9
9
  import { times } from './array';
10
10
  import { forceInt } from './number';
11
11
 
12
+ export enum ArticulationState {
13
+ COMPLETED = 1,
14
+ STARTED = 0,
15
+ NOT_STARTED = -1,
16
+ }
17
+
12
18
  type ArticulationItem = {
13
19
  label: string;
14
20
  value: string;
@@ -24,16 +30,14 @@ type Item = {
24
30
  label: string;
25
31
  value: ReactNode;
26
32
  }[];
27
- progress: number; // -1: not completed, 0: started, 1: finished
33
+ progress: ArticulationState; // -1: not completed, 0: started, 1: finished
28
34
  page: PageTag;
29
35
  };
30
36
 
31
37
  /**
32
38
  * Retrieve the articulation state
33
39
  *
34
- * ## Why this hook
35
- *
36
- * The goal of this hook is to provide insights about a roundabout using extra information inserted in the JSON source
40
+ * The goal of this function is to provide insights about a roundabout using extra information inserted in the JSON source
37
41
  * provided to Lunatic.
38
42
  *
39
43
  * For instance
@@ -61,7 +65,7 @@ type Item = {
61
65
  * - source is the ID of the roundabout component
62
66
  * - items define the field to extract from the roundabout data
63
67
  */
64
- export function getArticulation(
68
+ export function getArticulationState(
65
69
  source: LunaticSource & { articulation: Articulation },
66
70
  data: LunaticData
67
71
  ): { items: Item[] } {
@@ -90,7 +94,10 @@ export function getArticulation(
90
94
  return {
91
95
  items: rows.map((row, k) => ({
92
96
  cells: row,
93
- progress: forceInt(variables.get(roundabout.progressVariable, [k]) ?? -1),
97
+ progress: forceInt(
98
+ variables.get(roundabout.progressVariable, [k]) ??
99
+ ArticulationState.NOT_STARTED
100
+ ),
94
101
  page: (roundabout.page
95
102
  ? `${roundabout.page}.1#${k + 1}`
96
103
  : '1') as PageTag,