@inseefr/lunatic 3.5.0-rc.3 → 3.5.1-rc.1743691949561
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/components/Datepicker/Datepicker.js +1 -1
- package/components/Datepicker/Datepicker.js.map +1 -1
- package/components/Duration/Duration.js +3 -2
- package/components/Duration/Duration.js.map +1 -1
- package/components/Duration/durationUtils.d.ts +0 -1
- package/components/Duration/durationUtils.js.map +1 -1
- package/components/Duration/getDurationFromValue.d.ts +3 -2
- package/components/Duration/getDurationFromValue.js.map +1 -1
- package/components/Input/Input.js +6 -3
- package/components/Input/Input.js.map +1 -1
- package/components/Input/Input.spec.js +25 -0
- package/components/Input/Input.spec.js.map +1 -1
- package/components/InputNumber/InputNumber.js +1 -1
- package/components/InputNumber/InputNumber.js.map +1 -1
- package/components/InputNumber/InputNumber.spec.js +9 -1
- package/components/InputNumber/InputNumber.spec.js.map +1 -1
- package/components/InputNumber/InputNumberThousand.d.ts +2 -1
- package/components/InputNumber/InputNumberThousand.js +8 -2
- package/components/InputNumber/InputNumberThousand.js.map +1 -1
- package/components/Loop/Loop.js +1 -1
- package/components/Loop/Loop.js.map +1 -1
- package/components/Loop/Loop.spec.d.ts +1 -0
- package/components/Loop/Loop.spec.js +39 -0
- package/components/Loop/Loop.spec.js.map +1 -0
- package/components/Roundabout/CustomRoundabout.d.ts +1 -1
- package/components/Roundabout/CustomRoundabout.js +4 -3
- package/components/Roundabout/CustomRoundabout.js.map +1 -1
- package/components/Roundabout/roundabout.spec.js +3 -1
- package/components/Roundabout/roundabout.spec.js.map +1 -1
- package/components/Textarea/Textarea.js +4 -1
- package/components/Textarea/Textarea.js.map +1 -1
- package/components/Textarea/Textarea.spec.js +13 -0
- package/components/Textarea/Textarea.spec.js.map +1 -1
- package/components/shared/CharactersCount/CharactersCount.d.ts +7 -0
- package/components/shared/CharactersCount/CharactersCount.js +20 -0
- package/components/shared/CharactersCount/CharactersCount.js.map +1 -0
- package/components/shared/CharactersCount/CharactersCount.spec.d.ts +1 -0
- package/components/shared/CharactersCount/CharactersCount.spec.js +28 -0
- package/components/shared/CharactersCount/CharactersCount.spec.js.map +1 -0
- package/components/shared/Label/Label.js +1 -1
- package/components/shared/Label/Label.js.map +1 -1
- package/components/shared/Label/Label.spec.js +11 -3
- package/components/shared/Label/Label.spec.js.map +1 -1
- package/components/shared/utils/getCharactersCountId.d.ts +4 -0
- package/components/shared/utils/getCharactersCountId.js +10 -0
- package/components/shared/utils/getCharactersCountId.js.map +1 -0
- package/components/type.d.ts +3 -3
- package/esm/components/Datepicker/Datepicker.js +1 -1
- package/esm/components/Datepicker/Datepicker.js.map +1 -1
- package/esm/components/Duration/Duration.js +3 -2
- package/esm/components/Duration/Duration.js.map +1 -1
- package/esm/components/Duration/durationUtils.d.ts +0 -1
- package/esm/components/Duration/durationUtils.js.map +1 -1
- package/esm/components/Duration/getDurationFromValue.d.ts +3 -2
- package/esm/components/Duration/getDurationFromValue.js.map +1 -1
- package/esm/components/Input/Input.js +6 -3
- package/esm/components/Input/Input.js.map +1 -1
- package/esm/components/Input/Input.spec.js +25 -0
- package/esm/components/Input/Input.spec.js.map +1 -1
- package/esm/components/InputNumber/InputNumber.js +1 -1
- package/esm/components/InputNumber/InputNumber.js.map +1 -1
- package/esm/components/InputNumber/InputNumber.spec.js +9 -1
- package/esm/components/InputNumber/InputNumber.spec.js.map +1 -1
- package/esm/components/InputNumber/InputNumberThousand.d.ts +2 -1
- package/esm/components/InputNumber/InputNumberThousand.js +8 -2
- package/esm/components/InputNumber/InputNumberThousand.js.map +1 -1
- package/esm/components/Loop/Loop.js +1 -1
- package/esm/components/Loop/Loop.js.map +1 -1
- package/esm/components/Loop/Loop.spec.d.ts +1 -0
- package/esm/components/Loop/Loop.spec.js +37 -0
- package/esm/components/Loop/Loop.spec.js.map +1 -0
- package/esm/components/Roundabout/CustomRoundabout.d.ts +1 -1
- package/esm/components/Roundabout/CustomRoundabout.js +4 -3
- package/esm/components/Roundabout/CustomRoundabout.js.map +1 -1
- package/esm/components/Roundabout/roundabout.spec.js +3 -1
- package/esm/components/Roundabout/roundabout.spec.js.map +1 -1
- package/esm/components/Textarea/Textarea.js +4 -1
- package/esm/components/Textarea/Textarea.js.map +1 -1
- package/esm/components/Textarea/Textarea.spec.js +13 -0
- package/esm/components/Textarea/Textarea.spec.js.map +1 -1
- package/esm/components/shared/CharactersCount/CharactersCount.d.ts +7 -0
- package/esm/components/shared/CharactersCount/CharactersCount.js +15 -0
- package/esm/components/shared/CharactersCount/CharactersCount.js.map +1 -0
- package/esm/components/shared/CharactersCount/CharactersCount.spec.d.ts +1 -0
- package/esm/components/shared/CharactersCount/CharactersCount.spec.js +26 -0
- package/esm/components/shared/CharactersCount/CharactersCount.spec.js.map +1 -0
- package/esm/components/shared/Label/Label.js +1 -1
- package/esm/components/shared/Label/Label.js.map +1 -1
- package/esm/components/shared/Label/Label.spec.js +11 -3
- package/esm/components/shared/Label/Label.spec.js.map +1 -1
- package/esm/components/shared/utils/getCharactersCountId.d.ts +4 -0
- package/esm/components/shared/utils/getCharactersCountId.js +7 -0
- package/esm/components/shared/utils/getCharactersCountId.js.map +1 -0
- package/esm/components/type.d.ts +3 -3
- package/esm/index.d.ts +0 -1
- package/esm/index.js +0 -1
- package/esm/index.js.map +1 -1
- package/esm/main.css +20 -0
- package/esm/main.css.map +1 -1
- package/esm/stories/overview/sourceWithHierarchy.json +5151 -0
- package/esm/tests/utils/lunatic.d.ts +0 -4
- package/esm/tests/utils/lunatic.js +0 -4
- package/esm/tests/utils/lunatic.js.map +1 -1
- package/esm/type.source.d.ts +6 -6
- package/esm/type.source.js +0 -1
- package/esm/type.source.js.map +1 -1
- package/esm/use-lunatic/commons/fill-components/fill-components.d.ts +2 -0
- package/esm/use-lunatic/commons/fill-components/fill-components.js +1 -1
- package/esm/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/esm/use-lunatic/commons/page.js +8 -0
- package/esm/use-lunatic/commons/page.js.map +1 -1
- package/esm/use-lunatic/commons/variables/behaviours/cleaning-behaviour.d.ts +1 -1
- package/esm/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js +111 -14
- package/esm/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js.map +1 -1
- package/esm/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +3 -3
- package/esm/use-lunatic/commons/variables/behaviours/resizing-behaviour.js.map +1 -1
- package/esm/use-lunatic/commons/variables/get-questionnaire-data.js +0 -8
- package/esm/use-lunatic/commons/variables/get-questionnaire-data.js.map +1 -1
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.d.ts +2 -2
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.js +5 -3
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.js.map +1 -1
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.spec.js +181 -9
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.spec.js.map +1 -1
- package/esm/use-lunatic/hooks/use-page-has-response.js +50 -35
- package/esm/use-lunatic/hooks/use-page-has-response.js.map +1 -1
- package/esm/use-lunatic/hooks/useOverview.d.ts +1 -1
- package/esm/use-lunatic/hooks/useOverview.js +19 -14
- package/esm/use-lunatic/hooks/useOverview.js.map +1 -1
- package/esm/use-lunatic/hooks/useOverview.spec.d.ts +1 -0
- package/esm/use-lunatic/hooks/useOverview.spec.js +38 -0
- package/esm/use-lunatic/hooks/useOverview.spec.js.map +1 -0
- package/esm/use-lunatic/props/getComponentTypeProps.d.ts +2 -1
- package/esm/use-lunatic/props/propOptions.d.ts +2 -1
- package/esm/use-lunatic/props/propOptions.js +23 -3
- package/esm/use-lunatic/props/propOptions.js.map +1 -1
- package/esm/use-lunatic/props/propOptions.spec.js +46 -5
- package/esm/use-lunatic/props/propOptions.spec.js.map +1 -1
- package/esm/use-lunatic/props/propValue.js +18 -6
- package/esm/use-lunatic/props/propValue.js.map +1 -1
- package/esm/use-lunatic/props/propValue.spec.js +97 -2
- package/esm/use-lunatic/props/propValue.spec.js.map +1 -1
- package/esm/use-lunatic/reducer/reducerInitializer.d.ts +2 -2
- package/esm/use-lunatic/reducer/reducerInitializer.js +25 -32
- package/esm/use-lunatic/reducer/reducerInitializer.js.map +1 -1
- package/esm/use-lunatic/test.utils.d.ts +2 -0
- package/esm/use-lunatic/test.utils.js +13 -0
- package/esm/use-lunatic/test.utils.js.map +1 -0
- package/esm/use-lunatic/type.d.ts +18 -8
- package/esm/use-lunatic/use-lunatic.d.ts +1 -2
- package/esm/use-lunatic/use-lunatic.js +2 -3
- package/esm/use-lunatic/use-lunatic.js.map +1 -1
- package/esm/utils/cast.d.ts +19 -0
- package/esm/utils/cast.js +63 -0
- package/esm/utils/cast.js.map +1 -0
- package/esm/utils/constants/variable-status.d.ts +0 -4
- package/esm/utils/constants/variable-status.js +0 -4
- package/esm/utils/constants/variable-status.js.map +1 -1
- package/esm/utils/variables.spec.js +0 -8
- package/esm/utils/variables.spec.js.map +1 -1
- package/index.d.ts +0 -1
- package/index.js +1 -3
- package/index.js.map +1 -1
- package/main.css +20 -0
- package/main.css.map +1 -1
- package/package.json +60 -69
- package/src/components/Datepicker/Datepicker.tsx +1 -1
- package/src/components/Datepicker/__snapshots__/Datepicker.spec.tsx.snap +2 -2
- package/src/components/Duration/Duration.test.tsx +52 -0
- package/src/components/Duration/Duration.tsx +17 -4
- package/src/components/Duration/durationUtils.ts +0 -2
- package/src/components/Duration/getDurationFromValue.ts +4 -3
- package/src/components/Input/Input.spec.tsx +34 -0
- package/src/components/Input/Input.tsx +26 -18
- package/src/components/Input/__snapshots__/Input.spec.tsx.snap +38 -19
- package/src/components/InputNumber/InputNumber.spec.tsx +15 -1
- package/src/components/InputNumber/InputNumber.tsx +1 -0
- package/src/components/InputNumber/InputNumberThousand.tsx +11 -1
- package/src/components/Loop/Loop.spec.tsx +77 -0
- package/src/components/Loop/Loop.tsx +1 -1
- package/src/components/RosterForLoop/__snapshots__/RosterForLoop.spec.tsx.snap +42 -20
- package/src/components/Roundabout/CustomRoundabout.tsx +13 -4
- package/src/components/Roundabout/roundabout.spec.tsx +3 -0
- package/src/components/Textarea/Textarea.spec.tsx +18 -0
- package/src/components/Textarea/Textarea.tsx +21 -13
- package/src/components/Textarea/__snapshots__/Textarea.spec.tsx.snap +21 -11
- package/src/components/shared/CharactersCount/CharactersCount.spec.tsx +31 -0
- package/src/components/shared/CharactersCount/CharactersCount.tsx +27 -0
- package/src/components/shared/Label/Label.spec.tsx +15 -3
- package/src/components/shared/Label/Label.tsx +1 -1
- package/src/components/shared/utils/getCharactersCountId.test.ts +14 -0
- package/src/components/shared/utils/getCharactersCountId.ts +6 -0
- package/src/components/type.ts +3 -2
- package/src/css/components/Input.scss +10 -0
- package/src/css/components/Roundabout.scss +10 -0
- package/src/index.ts +0 -1
- package/src/stories/accordion/source.json +1 -5
- package/src/stories/behaviour/cleaning/cleaning.stories.jsx +11 -0
- package/src/stories/behaviour/cleaning/loop.json +246 -0
- package/src/stories/behaviour/cleaning/source-loop.json +3 -15
- package/src/stories/behaviour/cleaning/source.json +2 -10
- package/src/stories/behaviour/controls/boucles-n.json +2 -10
- package/src/stories/behaviour/controls/loop.json +2 -10
- package/src/stories/behaviour/controls/roundabout.json +3 -15
- package/src/stories/behaviour/controls/simple-numeric.json +19 -95
- package/src/stories/behaviour/controls/simple.json +7 -35
- package/src/stories/behaviour/filter/dataLoop.json +0 -8
- package/src/stories/behaviour/filter/source.json +0 -12
- package/src/stories/behaviour/filter/sourceLoop.json +0 -12
- package/src/stories/behaviour/missing/source.json +12 -60
- package/src/stories/behaviour/others/V2_DeclarationsSimples.json +14 -70
- package/src/stories/behaviour/others/V2_MinMaxSum_Boucles.json +5 -25
- package/src/stories/behaviour/others/V2_QuestSimple_Boucles.json +107 -535
- package/src/stories/behaviour/others/V2_TCMRallyeGames.json +33 -165
- package/src/stories/behaviour/others/test-dylan.json +5 -25
- package/src/stories/behaviour/paste/source.json +1 -5
- package/src/stories/behaviour/performance/performance.stories.jsx +2 -2
- package/src/stories/behaviour/performance/source.json +4 -20
- package/src/stories/behaviour/resizing/source-resizing-cleaning.json +2 -10
- package/src/stories/behaviour/resizing/source.json +5 -25
- package/src/stories/checkbox-boolean/source.json +1 -5
- package/src/stories/checkbox-group/source.json +16 -80
- package/src/stories/checkbox-group/sourceCondition.json +3 -15
- package/src/stories/checkbox-group/sourceDetail.json +18 -90
- package/src/stories/checkbox-group/sourceLoop.json +2 -10
- package/src/stories/checkbox-one/source.json +1 -5
- package/src/stories/checkbox-one/sourceDetail.json +2 -10
- package/src/stories/date-picker/source.json +1 -5
- package/src/stories/declaration/source.json +2 -10
- package/src/stories/disabled/data.json +0 -16
- package/src/stories/disabled/source.json +7 -35
- package/src/stories/dropdown/data.json +2 -10
- package/src/stories/dropdown/source.json +2 -10
- package/src/stories/duration/mois.json +1 -5
- package/src/stories/duration/time.json +1 -5
- package/src/stories/filter-description/source-options.json +3 -15
- package/src/stories/input/source.json +1 -5
- package/src/stories/input-number/input-number.stories.jsx +5 -0
- package/src/stories/input-number/source-big-number.json +27 -0
- package/src/stories/input-number/source-euro.json +2 -6
- package/src/stories/input-number/source.json +1 -5
- package/src/stories/loop/source-bloc.json +2 -10
- package/src/stories/loop/source-paginated.json +2 -10
- package/src/stories/loop/source-roster.json +2 -10
- package/src/stories/loop/source-with-header.json +2 -10
- package/src/stories/overview/dataLoop.json +24 -120
- package/src/stories/overview/overview.stories.jsx +9 -0
- package/src/stories/overview/source.json +1 -5
- package/src/stories/overview/sourceLoop.json +24 -120
- package/src/stories/overview/sourceWithHierarchy.json +164 -820
- package/src/stories/pairwise/source.json +5 -25
- package/src/stories/question/source.json +2 -10
- package/src/stories/questionnaires/logement/data.json +0 -1288
- package/src/stories/questionnaires/logement/source-sequence.json +564 -2820
- package/src/stories/questionnaires/logement/source-sum.json +280 -1400
- package/src/stories/questionnaires/logement/source.json +564 -2820
- package/src/stories/questionnaires/recensement/source.json +106 -530
- package/src/stories/questionnaires/rp/source.json +8 -40
- package/src/stories/questionnaires/simpsons/source.json +104 -520
- package/src/stories/radio/source.json +1 -5
- package/src/stories/radio/sourceCondition.json +2 -10
- package/src/stories/radio/sourceDetail.json +2 -10
- package/src/stories/radio/sourceHorizontal.json +1 -5
- package/src/stories/roundabout/data1.json +0 -12
- package/src/stories/roundabout/data2.json +0 -16
- package/src/stories/roundabout/source.json +11 -35
- package/src/stories/suggester/source-arbitrary-response.json +6 -30
- package/src/stories/suggester/source-error.json +6 -30
- package/src/stories/suggester/source-multiline.json +0 -16
- package/src/stories/suggester/source-option-responses.json +5 -25
- package/src/stories/suggester/source.json +7 -35
- package/src/stories/summary/data.json +0 -16
- package/src/stories/summary/source.json +7 -35
- package/src/stories/switch/data-forced.json +2 -10
- package/src/stories/switch/source.json +4 -20
- package/src/stories/table/source-colspan.json +8 -40
- package/src/stories/table/table-dynamique.json +1 -5
- package/src/stories/text/source-roster.json +3 -15
- package/src/stories/text/source-table.json +9 -45
- package/src/stories/textarea/source.json +1 -5
- package/src/stories/utils/{SchemaValidator.tsx → SchemaValidator.jsx} +1 -1
- package/src/stories/utils/{orchestrator.tsx → orchestrator.jsx} +9 -13
- package/src/stories/utils/{overview.tsx → overview.jsx} +0 -2
- package/src/tests/utils/lunatic.ts +0 -4
- package/src/type.source.ts +8 -7
- package/src/use-lunatic/__snapshots__/use-lunatic.test.ts.snap +0 -1159
- package/src/use-lunatic/commons/fill-components/fill-components.ts +4 -1
- package/src/use-lunatic/commons/page.ts +10 -0
- package/src/use-lunatic/commons/variables/behaviours/cleaning-behaviour.ts +182 -24
- package/src/use-lunatic/commons/variables/behaviours/resizing-behaviour.ts +2 -5
- package/src/use-lunatic/commons/variables/get-questionnaire-data.ts +0 -12
- package/src/use-lunatic/commons/variables/lunatic-variables-store.spec.ts +207 -9
- package/src/use-lunatic/commons/variables/lunatic-variables-store.ts +7 -4
- package/src/use-lunatic/hooks/use-page-has-response.test.ts +200 -0
- package/src/use-lunatic/hooks/use-page-has-response.ts +67 -44
- package/src/use-lunatic/hooks/useOverview.spec.ts +42 -0
- package/src/use-lunatic/hooks/useOverview.ts +41 -18
- package/src/use-lunatic/props/propOptions.spec.ts +71 -5
- package/src/use-lunatic/props/propOptions.ts +23 -3
- package/src/use-lunatic/props/propValue.spec.ts +105 -2
- package/src/use-lunatic/props/propValue.ts +26 -8
- package/src/use-lunatic/reducer/reducerInitializer.tsx +31 -41
- package/src/use-lunatic/test.utils.ts +17 -0
- package/src/use-lunatic/type.ts +18 -8
- package/src/use-lunatic/use-lunatic.test.ts +15 -44
- package/src/use-lunatic/use-lunatic.ts +7 -7
- package/src/utils/cast.ts +67 -0
- package/src/utils/constants/variable-status.ts +0 -4
- package/src/utils/variables.spec.ts +0 -8
- package/stories/overview/sourceWithHierarchy.json +5151 -0
- package/tests/utils/lunatic.d.ts +0 -4
- package/tests/utils/lunatic.js +0 -4
- package/tests/utils/lunatic.js.map +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/type.source.d.ts +6 -6
- package/type.source.js +0 -1
- package/type.source.js.map +1 -1
- package/use-lunatic/commons/fill-components/fill-components.d.ts +2 -0
- package/use-lunatic/commons/fill-components/fill-components.js +1 -1
- package/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/use-lunatic/commons/page.js +8 -0
- package/use-lunatic/commons/page.js.map +1 -1
- package/use-lunatic/commons/variables/behaviours/cleaning-behaviour.d.ts +1 -1
- package/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js +111 -14
- package/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js.map +1 -1
- package/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +3 -3
- package/use-lunatic/commons/variables/behaviours/resizing-behaviour.js.map +1 -1
- package/use-lunatic/commons/variables/get-questionnaire-data.js +0 -8
- package/use-lunatic/commons/variables/get-questionnaire-data.js.map +1 -1
- package/use-lunatic/commons/variables/lunatic-variables-store.d.ts +2 -2
- package/use-lunatic/commons/variables/lunatic-variables-store.js +5 -3
- package/use-lunatic/commons/variables/lunatic-variables-store.js.map +1 -1
- package/use-lunatic/commons/variables/lunatic-variables-store.spec.js +204 -9
- package/use-lunatic/commons/variables/lunatic-variables-store.spec.js.map +1 -1
- package/use-lunatic/hooks/use-page-has-response.js +49 -34
- package/use-lunatic/hooks/use-page-has-response.js.map +1 -1
- package/use-lunatic/hooks/useOverview.d.ts +1 -1
- package/use-lunatic/hooks/useOverview.js +19 -14
- package/use-lunatic/hooks/useOverview.js.map +1 -1
- package/use-lunatic/hooks/useOverview.spec.d.ts +1 -0
- package/use-lunatic/hooks/useOverview.spec.js +43 -0
- package/use-lunatic/hooks/useOverview.spec.js.map +1 -0
- package/use-lunatic/props/getComponentTypeProps.d.ts +2 -1
- package/use-lunatic/props/propOptions.d.ts +2 -1
- package/use-lunatic/props/propOptions.js +23 -3
- package/use-lunatic/props/propOptions.js.map +1 -1
- package/use-lunatic/props/propOptions.spec.js +46 -5
- package/use-lunatic/props/propOptions.spec.js.map +1 -1
- package/use-lunatic/props/propValue.js +18 -6
- package/use-lunatic/props/propValue.js.map +1 -1
- package/use-lunatic/props/propValue.spec.js +97 -2
- package/use-lunatic/props/propValue.spec.js.map +1 -1
- package/use-lunatic/reducer/reducerInitializer.d.ts +2 -2
- package/use-lunatic/reducer/reducerInitializer.js +25 -32
- package/use-lunatic/reducer/reducerInitializer.js.map +1 -1
- package/use-lunatic/test.utils.d.ts +2 -0
- package/use-lunatic/test.utils.js +17 -0
- package/use-lunatic/test.utils.js.map +1 -0
- package/use-lunatic/type.d.ts +18 -8
- package/use-lunatic/use-lunatic.d.ts +1 -2
- package/use-lunatic/use-lunatic.js +2 -3
- package/use-lunatic/use-lunatic.js.map +1 -1
- package/utils/cast.d.ts +19 -0
- package/utils/cast.js +70 -0
- package/utils/cast.js.map +1 -0
- package/utils/constants/variable-status.d.ts +0 -4
- package/utils/constants/variable-status.js +1 -5
- package/utils/constants/variable-status.js.map +1 -1
- package/utils/variables.spec.js +0 -8
- package/utils/variables.spec.js.map +1 -1
- package/constants/component-types.d.ts +0 -1
- package/constants/component-types.js +0 -5
- package/constants/component-types.js.map +0 -1
- package/constants/declarations.d.ts +0 -9
- package/constants/declarations.js +0 -15
- package/constants/declarations.js.map +0 -1
- package/constants/event-types.d.ts +0 -10
- package/constants/event-types.js +0 -16
- package/constants/event-types.js.map +0 -1
- package/constants/index.d.ts +0 -5
- package/constants/index.js +0 -22
- package/constants/index.js.map +0 -1
- package/constants/indexedDBStore.d.ts +0 -21
- package/constants/indexedDBStore.js +0 -22
- package/constants/indexedDBStore.js.map +0 -1
- package/constants/supported-preferences.d.ts +0 -1
- package/constants/supported-preferences.js +0 -36
- package/constants/supported-preferences.js.map +0 -1
- package/constants/value-types.d.ts +0 -5
- package/constants/value-types.js +0 -9
- package/constants/value-types.js.map +0 -1
- package/constants/variable-types.d.ts +0 -2
- package/constants/variable-types.js +0 -8
- package/constants/variable-types.js.map +0 -1
- package/esm/constants/component-types.d.ts +0 -1
- package/esm/constants/component-types.js +0 -2
- package/esm/constants/component-types.js.map +0 -1
- package/esm/constants/declarations.d.ts +0 -9
- package/esm/constants/declarations.js +0 -12
- package/esm/constants/declarations.js.map +0 -1
- package/esm/constants/event-types.d.ts +0 -10
- package/esm/constants/event-types.js +0 -13
- package/esm/constants/event-types.js.map +0 -1
- package/esm/constants/index.d.ts +0 -5
- package/esm/constants/index.js +0 -6
- package/esm/constants/index.js.map +0 -1
- package/esm/constants/indexedDBStore.d.ts +0 -21
- package/esm/constants/indexedDBStore.js +0 -19
- package/esm/constants/indexedDBStore.js.map +0 -1
- package/esm/constants/supported-preferences.d.ts +0 -1
- package/esm/constants/supported-preferences.js +0 -10
- package/esm/constants/supported-preferences.js.map +0 -1
- package/esm/constants/value-types.d.ts +0 -5
- package/esm/constants/value-types.js +0 -6
- package/esm/constants/value-types.js.map +0 -1
- package/esm/constants/variable-types.d.ts +0 -2
- package/esm/constants/variable-types.js +0 -5
- package/esm/constants/variable-types.js.map +0 -1
- package/esm/utils/getArticulation.d.ts +0 -58
- package/esm/utils/getArticulation.js +0 -78
- package/esm/utils/getArticulation.js.map +0 -1
- package/src/constants/component-types.ts +0 -1
- package/src/constants/declarations.ts +0 -14
- package/src/constants/event-types.ts +0 -13
- package/src/constants/index.ts +0 -5
- package/src/constants/indexedDBStore.ts +0 -20
- package/src/constants/supported-preferences.ts +0 -10
- package/src/constants/value-types.ts +0 -5
- package/src/constants/variable-types.ts +0 -4
- package/src/stories/behaviour/articulation/articulation.stories.tsx +0 -108
- package/src/stories/behaviour/articulation/roundabout.json +0 -348
- package/src/utils/getArticulation.ts +0 -117
- package/utils/getArticulation.d.ts +0 -58
- package/utils/getArticulation.js +0 -77
- package/utils/getArticulation.js.map +0 -1
|
@@ -25,7 +25,7 @@ describe('fillComponentValue', () => {
|
|
|
25
25
|
);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
describe('response', () => {
|
|
28
|
+
describe('single response', () => {
|
|
29
29
|
const component = {
|
|
30
30
|
response: { name: 'PRENOM' },
|
|
31
31
|
} as LunaticComponentDefinition<'Input'>;
|
|
@@ -44,7 +44,7 @@ describe('fillComponentValue', () => {
|
|
|
44
44
|
);
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
|
-
describe('responses', () => {
|
|
47
|
+
describe('multiple responses', () => {
|
|
48
48
|
const component = {
|
|
49
49
|
responses: times(3, (k) => ({
|
|
50
50
|
response: { name: `NAME${k}` },
|
|
@@ -64,4 +64,107 @@ describe('fillComponentValue', () => {
|
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
|
+
|
|
68
|
+
describe('Loop component with nested components', () => {
|
|
69
|
+
const loopComponent = {
|
|
70
|
+
id: 'm7j9kwro',
|
|
71
|
+
componentType: 'Loop',
|
|
72
|
+
components: [
|
|
73
|
+
{
|
|
74
|
+
id: 'm7j9iem8',
|
|
75
|
+
componentType: 'Sequence',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: 'question-m7j9q1ep',
|
|
79
|
+
componentType: 'Question',
|
|
80
|
+
components: [
|
|
81
|
+
{
|
|
82
|
+
id: 'm7j9q1ep',
|
|
83
|
+
componentType: 'Input',
|
|
84
|
+
response: { name: 'VOTREPRENO' },
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: 'question-m7jb81xh',
|
|
90
|
+
componentType: 'Question',
|
|
91
|
+
components: [
|
|
92
|
+
{
|
|
93
|
+
id: 'm7jb81xh',
|
|
94
|
+
componentType: 'InputNumber',
|
|
95
|
+
response: { name: 'VOTREAGE' },
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
} as LunaticComponentDefinition;
|
|
101
|
+
|
|
102
|
+
it('should correctly extract values from nested responses as arrays', () => {
|
|
103
|
+
const values = {
|
|
104
|
+
VOTREPRENO: ['Alice', 'Bob', 'Charlie'],
|
|
105
|
+
VOTREAGE: [22, 30, 40],
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
expectFilledComponent(loopComponent, values).toEqual(values);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should return null for missing responses', () => {
|
|
112
|
+
expectFilledComponent(loopComponent).toEqual({
|
|
113
|
+
VOTREPRENO: null,
|
|
114
|
+
VOTREAGE: null,
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('RosterForLoop', () => {
|
|
120
|
+
const rosterForLoopComponent = {
|
|
121
|
+
id: 'loop-prenom',
|
|
122
|
+
componentType: 'RosterForLoop',
|
|
123
|
+
bindingDependencies: ['PRENOM'],
|
|
124
|
+
lines: {
|
|
125
|
+
min: {
|
|
126
|
+
value: '1',
|
|
127
|
+
type: 'VTL',
|
|
128
|
+
},
|
|
129
|
+
max: {
|
|
130
|
+
value: '10',
|
|
131
|
+
type: 'VTL',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
page: '1',
|
|
135
|
+
components: [
|
|
136
|
+
{
|
|
137
|
+
componentType: 'Input',
|
|
138
|
+
label: {
|
|
139
|
+
value: '"Prénom"',
|
|
140
|
+
type: 'VTL|MD',
|
|
141
|
+
},
|
|
142
|
+
conditionFilter: {
|
|
143
|
+
value: 'true',
|
|
144
|
+
type: 'VTL',
|
|
145
|
+
},
|
|
146
|
+
maxLength: 30,
|
|
147
|
+
bindingDependencies: ['PRENOM'],
|
|
148
|
+
id: 'prenom',
|
|
149
|
+
response: {
|
|
150
|
+
name: 'PRENOM',
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
} as any as LunaticComponentDefinition<'RosterForLoop'>;
|
|
155
|
+
|
|
156
|
+
it('should correctly extract values from nested responses as arrays', () => {
|
|
157
|
+
const values = {
|
|
158
|
+
PRENOM: ['Alice', 'Bob', 'Charlie'],
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
expectFilledComponent(rosterForLoopComponent, values).toEqual(values);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('should return null for missing responses', () => {
|
|
165
|
+
expectFilledComponent(rosterForLoopComponent).toEqual({
|
|
166
|
+
PRENOM: null,
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
67
170
|
});
|
|
@@ -27,14 +27,32 @@ export function getValueProp(
|
|
|
27
27
|
if (hasResponse(component)) {
|
|
28
28
|
return args.variables.get(component.response.name, iteration);
|
|
29
29
|
}
|
|
30
|
-
// For
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
.map((name) => [name, args.variables.get(name!)])
|
|
37
|
-
);
|
|
30
|
+
// For Loop and RosterForLoop, value will be a map of child component values
|
|
31
|
+
if (
|
|
32
|
+
component.componentType === 'Loop' ||
|
|
33
|
+
component.componentType === 'RosterForLoop'
|
|
34
|
+
) {
|
|
35
|
+
return getChildResponseValues(component.components, args.variables);
|
|
38
36
|
}
|
|
39
37
|
return null;
|
|
40
38
|
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get the values of every child components recursively.
|
|
42
|
+
*/
|
|
43
|
+
function getChildResponseValues(
|
|
44
|
+
components: LunaticComponentDefinition[],
|
|
45
|
+
variables: LunaticVariablesStore
|
|
46
|
+
): Record<string, unknown> {
|
|
47
|
+
return Object.fromEntries(
|
|
48
|
+
components.flatMap((c) => {
|
|
49
|
+
if ('response' in c) {
|
|
50
|
+
return [[c.response.name, variables.get(c.response.name)]];
|
|
51
|
+
}
|
|
52
|
+
if ('components' in c) {
|
|
53
|
+
return Object.entries(getChildResponseValues(c.components, variables));
|
|
54
|
+
}
|
|
55
|
+
return [];
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
}
|
|
@@ -38,8 +38,6 @@ const baseState = {
|
|
|
38
38
|
options: { disableFilters: false },
|
|
39
39
|
} satisfies LunaticReducerState;
|
|
40
40
|
|
|
41
|
-
const onChange = { current: () => {} };
|
|
42
|
-
|
|
43
41
|
export function reducerInitializer({
|
|
44
42
|
source,
|
|
45
43
|
data,
|
|
@@ -49,8 +47,8 @@ export function reducerInitializer({
|
|
|
49
47
|
withOverview = false,
|
|
50
48
|
disableFilters = false,
|
|
51
49
|
getReferentiel,
|
|
52
|
-
onVariableChange
|
|
53
|
-
logger
|
|
50
|
+
onVariableChange,
|
|
51
|
+
logger,
|
|
54
52
|
}: {
|
|
55
53
|
source: LunaticSource;
|
|
56
54
|
data: LunaticData;
|
|
@@ -60,13 +58,14 @@ export function reducerInitializer({
|
|
|
60
58
|
withOverview?: LunaticOptions['withOverview'];
|
|
61
59
|
disableFilters?: LunaticOptions['disableFilters'];
|
|
62
60
|
getReferentiel?: LunaticOptions['getReferentiel'];
|
|
63
|
-
onVariableChange
|
|
64
|
-
logger
|
|
61
|
+
onVariableChange: RefObject<LunaticOptions['onVariableChange']>;
|
|
62
|
+
logger: LunaticLogger;
|
|
65
63
|
}): LunaticReducerState {
|
|
66
64
|
const variables = LunaticVariablesStore.makeFromSource(
|
|
67
65
|
source,
|
|
68
66
|
data,
|
|
69
|
-
onVariableChange
|
|
67
|
+
onVariableChange,
|
|
68
|
+
disableFilters
|
|
70
69
|
);
|
|
71
70
|
const pages = checkLoops(createMapPages(source));
|
|
72
71
|
|
|
@@ -112,13 +111,11 @@ export function reducerInitializer({
|
|
|
112
111
|
}
|
|
113
112
|
return result as any;
|
|
114
113
|
} catch (e) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
});
|
|
121
|
-
}
|
|
114
|
+
// If there is an error interpreting a variable, return the raw expression
|
|
115
|
+
logger({
|
|
116
|
+
type: 'ERROR',
|
|
117
|
+
error: e as Error,
|
|
118
|
+
});
|
|
122
119
|
return expressionString;
|
|
123
120
|
}
|
|
124
121
|
};
|
|
@@ -135,9 +132,9 @@ export function reducerInitializer({
|
|
|
135
132
|
const pager = {
|
|
136
133
|
page: initialPager?.page ?? 1,
|
|
137
134
|
maxPage: source.maxPage ? parseInt(source.maxPage, 10) : 1,
|
|
138
|
-
subPage:
|
|
135
|
+
subPage: undefined,
|
|
139
136
|
nbSubPages: undefined,
|
|
140
|
-
iteration:
|
|
137
|
+
iteration: undefined,
|
|
141
138
|
nbIterations: undefined,
|
|
142
139
|
lastReachedPage: lastReachedPage ?? initialPage,
|
|
143
140
|
};
|
|
@@ -147,7 +144,7 @@ export function reducerInitializer({
|
|
|
147
144
|
pager,
|
|
148
145
|
previousPager: pager,
|
|
149
146
|
pages,
|
|
150
|
-
isInLoop:
|
|
147
|
+
isInLoop: false,
|
|
151
148
|
updatedAt: Date.now(),
|
|
152
149
|
overview: withOverview ? buildOverview(source) : [],
|
|
153
150
|
updateBindings,
|
|
@@ -165,29 +162,22 @@ function fillPagerForLoop(state: LunaticReducerState): LunaticReducerState {
|
|
|
165
162
|
return state;
|
|
166
163
|
}
|
|
167
164
|
const { isLoop, subPages, iterations, loopDependencies } = pages[pager.page];
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
// For loop, jump at the first page
|
|
171
|
-
isLoop ||
|
|
172
|
-
// For roundabout, jump at the desired iteration / subpage (only if defined)
|
|
173
|
-
(pager?.iteration !== undefined && subPages)
|
|
174
|
-
) {
|
|
175
|
-
return {
|
|
176
|
-
...state,
|
|
177
|
-
isInLoop: true,
|
|
178
|
-
pager: {
|
|
179
|
-
...pager,
|
|
180
|
-
subPage: pager?.subPage ?? 1,
|
|
181
|
-
nbSubPages: (subPages ?? []).length,
|
|
182
|
-
iteration: pager?.iteration ?? 0,
|
|
183
|
-
nbIterations: forceInt(
|
|
184
|
-
state.executeExpression(iterations, {
|
|
185
|
-
deps: loopDependencies,
|
|
186
|
-
})
|
|
187
|
-
),
|
|
188
|
-
},
|
|
189
|
-
};
|
|
165
|
+
if (!isLoop) {
|
|
166
|
+
return state;
|
|
190
167
|
}
|
|
191
|
-
|
|
192
|
-
|
|
168
|
+
return {
|
|
169
|
+
...state,
|
|
170
|
+
isInLoop: true,
|
|
171
|
+
pager: {
|
|
172
|
+
...pager,
|
|
173
|
+
subPage: pager?.subPage ?? 0,
|
|
174
|
+
nbSubPages: (subPages ?? []).length,
|
|
175
|
+
iteration: pager?.iteration ?? 0,
|
|
176
|
+
nbIterations: forceInt(
|
|
177
|
+
state.executeExpression(iterations, {
|
|
178
|
+
deps: loopDependencies,
|
|
179
|
+
})
|
|
180
|
+
),
|
|
181
|
+
},
|
|
182
|
+
};
|
|
193
183
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LunaticData } from './type';
|
|
2
|
+
|
|
3
|
+
export const dataFromObject = (o: Record<string, unknown>): LunaticData => {
|
|
4
|
+
return {
|
|
5
|
+
EXTERNAL: {},
|
|
6
|
+
COLLECTED: Object.keys(o).reduce(
|
|
7
|
+
(acc, k) => ({
|
|
8
|
+
...acc,
|
|
9
|
+
[k]: {
|
|
10
|
+
COLLECTED: o[k],
|
|
11
|
+
},
|
|
12
|
+
}),
|
|
13
|
+
{}
|
|
14
|
+
),
|
|
15
|
+
CALCULATED: {},
|
|
16
|
+
};
|
|
17
|
+
};
|
package/src/use-lunatic/type.ts
CHANGED
|
@@ -74,10 +74,6 @@ export type PageTag = `${number}.${number}#${number}` | `${number}`;
|
|
|
74
74
|
export type LunaticVariable = Variable;
|
|
75
75
|
export type LunaticCollectedValue = Partial<{
|
|
76
76
|
COLLECTED: unknown;
|
|
77
|
-
EDITED: unknown;
|
|
78
|
-
FORCED: unknown;
|
|
79
|
-
INPUTTED: unknown;
|
|
80
|
-
PREVIOUS: unknown;
|
|
81
77
|
}>;
|
|
82
78
|
|
|
83
79
|
// We need a mapped type to correlate type and variableType
|
|
@@ -337,10 +333,24 @@ export type LunaticState = {
|
|
|
337
333
|
resetChangedData: () => void;
|
|
338
334
|
/** Return `true` as soon as the current page has at least one answer. */
|
|
339
335
|
hasPageResponse: () => boolean;
|
|
340
|
-
/**
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
336
|
+
/**
|
|
337
|
+
* Change several variable values.
|
|
338
|
+
*
|
|
339
|
+
* Be careful when using this function.
|
|
340
|
+
*
|
|
341
|
+
* In most cases, you don't need this function.
|
|
342
|
+
* It's used directly by the components (and available as a props.)
|
|
343
|
+
*
|
|
344
|
+
* - With only one change or with serveral changes
|
|
345
|
+
* @example
|
|
346
|
+
* handleChanges([{name: "MY_VAR", value: "new value"}])
|
|
347
|
+
*
|
|
348
|
+
* handleChanges([
|
|
349
|
+
* {name: "MY_VAR", value: "new value"},
|
|
350
|
+
* {name: "MY_VAR_2", value: "new value 2"}
|
|
351
|
+
* ])
|
|
352
|
+
*/
|
|
353
|
+
handleChanges: LunaticChangesHandler;
|
|
344
354
|
};
|
|
345
355
|
|
|
346
356
|
/** Function taking as arguments the various changes the user has made. */
|
|
@@ -9,29 +9,10 @@ import sourceCheckboxGroup from '../stories/checkbox-group/source.json';
|
|
|
9
9
|
import dataOverview from '../stories/overview/dataLoop.json';
|
|
10
10
|
import sourceCleaningLoop from '../stories/behaviour/cleaning/source-loop.json';
|
|
11
11
|
import sourceCleaningResizing from '../stories/behaviour/resizing/source-resizing-cleaning.json';
|
|
12
|
-
import type {
|
|
12
|
+
import type { PageTag } from './type';
|
|
13
13
|
import { useLunatic } from './use-lunatic';
|
|
14
14
|
import { useCallback } from 'react';
|
|
15
|
-
|
|
16
|
-
const dataFromObject = (o: Record<string, unknown>): LunaticData => {
|
|
17
|
-
return {
|
|
18
|
-
EXTERNAL: {},
|
|
19
|
-
COLLECTED: Object.keys(o).reduce(
|
|
20
|
-
(acc, k) => ({
|
|
21
|
-
...acc,
|
|
22
|
-
[k]: {
|
|
23
|
-
EDITED: null,
|
|
24
|
-
FORCED: null,
|
|
25
|
-
INPUTTED: null,
|
|
26
|
-
PREVIOUS: null,
|
|
27
|
-
COLLECTED: o[k],
|
|
28
|
-
},
|
|
29
|
-
}),
|
|
30
|
-
{}
|
|
31
|
-
),
|
|
32
|
-
CALCULATED: {},
|
|
33
|
-
};
|
|
34
|
-
};
|
|
15
|
+
import { dataFromObject } from './test.utils';
|
|
35
16
|
|
|
36
17
|
describe('use-lunatic()', () => {
|
|
37
18
|
const defaultParams = [
|
|
@@ -252,7 +233,7 @@ describe('use-lunatic()', () => {
|
|
|
252
233
|
useLunatic(sourceCleaningLoop as any, undefined, {})
|
|
253
234
|
);
|
|
254
235
|
act(() => {
|
|
255
|
-
result.current.
|
|
236
|
+
result.current.handleChanges([
|
|
256
237
|
{
|
|
257
238
|
name: 'PRENOM',
|
|
258
239
|
value: ['John', 'Doe', 'Marc'],
|
|
@@ -270,7 +251,7 @@ describe('use-lunatic()', () => {
|
|
|
270
251
|
};
|
|
271
252
|
expectCollectedAgeToEqual([18, 18, 18]);
|
|
272
253
|
act(() => {
|
|
273
|
-
result.current.
|
|
254
|
+
result.current.handleChanges([
|
|
274
255
|
{
|
|
275
256
|
name: 'HIDE_AGE',
|
|
276
257
|
value: true,
|
|
@@ -290,15 +271,11 @@ describe('use-lunatic()', () => {
|
|
|
290
271
|
onChange: spy,
|
|
291
272
|
})
|
|
292
273
|
);
|
|
293
|
-
act(() =>
|
|
294
|
-
result.current.testing.handleChanges([{ name: 'NB', value: 3 }])
|
|
295
|
-
);
|
|
274
|
+
act(() => result.current.handleChanges([{ name: 'NB', value: 3 }]));
|
|
296
275
|
expect(
|
|
297
276
|
(result.current.getData(true).COLLECTED?.PRENOMS as any).COLLECTED
|
|
298
277
|
).toEqual([null, null, null]);
|
|
299
|
-
act(() =>
|
|
300
|
-
result.current.testing.handleChanges([{ name: 'NB', value: 2 }])
|
|
301
|
-
);
|
|
278
|
+
act(() => result.current.handleChanges([{ name: 'NB', value: 2 }]));
|
|
302
279
|
expect(
|
|
303
280
|
(result.current.getData(true).COLLECTED?.PRENOMS as any).COLLECTED
|
|
304
281
|
).toEqual([null, null]);
|
|
@@ -312,13 +289,13 @@ describe('use-lunatic()', () => {
|
|
|
312
289
|
useLunatic(sourceSimpsons as any, undefined, {})
|
|
313
290
|
);
|
|
314
291
|
act(() => {
|
|
315
|
-
result.current.
|
|
292
|
+
result.current.handleChanges([
|
|
316
293
|
{
|
|
317
294
|
name: 'COMMENT',
|
|
318
295
|
value: 'Mon commentaire',
|
|
319
296
|
},
|
|
320
297
|
]);
|
|
321
|
-
result.current.
|
|
298
|
+
result.current.handleChanges([{ name: 'READY', value: true }]);
|
|
322
299
|
});
|
|
323
300
|
hookRef = result;
|
|
324
301
|
});
|
|
@@ -347,7 +324,7 @@ describe('use-lunatic()', () => {
|
|
|
347
324
|
});
|
|
348
325
|
it('should return changes since the last update', () => {
|
|
349
326
|
act(() => {
|
|
350
|
-
hookRef.current.
|
|
327
|
+
hookRef.current.handleChanges([
|
|
351
328
|
{ name: 'COMMENT', value: 'Mon commentaire' },
|
|
352
329
|
{ name: 'READY', value: true },
|
|
353
330
|
]);
|
|
@@ -365,10 +342,10 @@ describe('use-lunatic()', () => {
|
|
|
365
342
|
});
|
|
366
343
|
it('should reset changes with true parameter', () => {
|
|
367
344
|
act(() => {
|
|
368
|
-
hookRef.current.
|
|
345
|
+
hookRef.current.handleChanges([
|
|
369
346
|
{ name: 'COMMENT', value: 'Mon commentaire' },
|
|
370
347
|
]);
|
|
371
|
-
hookRef.current.
|
|
348
|
+
hookRef.current.handleChanges([{ name: 'READY', value: true }]);
|
|
372
349
|
});
|
|
373
350
|
const data = hookRef.current.getChangedData(true);
|
|
374
351
|
expect(data).toMatchObject({
|
|
@@ -385,7 +362,7 @@ describe('use-lunatic()', () => {
|
|
|
385
362
|
});
|
|
386
363
|
it('should reset changes with resetChanges()', () => {
|
|
387
364
|
act(() => {
|
|
388
|
-
hookRef.current.
|
|
365
|
+
hookRef.current.handleChanges([
|
|
389
366
|
{
|
|
390
367
|
name: 'COMMENT',
|
|
391
368
|
value: 'Mon commentaire',
|
|
@@ -396,9 +373,7 @@ describe('use-lunatic()', () => {
|
|
|
396
373
|
hookRef.current.resetChangedData();
|
|
397
374
|
expect(hookRef.current.getChangedData().COLLECTED).toEqual({});
|
|
398
375
|
act(() => {
|
|
399
|
-
hookRef.current.
|
|
400
|
-
{ name: 'READY', value: false },
|
|
401
|
-
]);
|
|
376
|
+
hookRef.current.handleChanges([{ name: 'READY', value: false }]);
|
|
402
377
|
});
|
|
403
378
|
expect(hookRef.current.getChangedData().COLLECTED).toMatchObject({
|
|
404
379
|
READY: {
|
|
@@ -414,9 +389,7 @@ describe('use-lunatic()', () => {
|
|
|
414
389
|
useLunatic(sourceCheckboxGroup as any, undefined, {})
|
|
415
390
|
);
|
|
416
391
|
act(() => {
|
|
417
|
-
result.current.
|
|
418
|
-
{ name: 'NATIO1N1', value: true },
|
|
419
|
-
]);
|
|
392
|
+
result.current.handleChanges([{ name: 'NATIO1N1', value: true }]);
|
|
420
393
|
});
|
|
421
394
|
expect(result.current.hasPageResponse()).toBeTruthy();
|
|
422
395
|
});
|
|
@@ -425,9 +398,7 @@ describe('use-lunatic()', () => {
|
|
|
425
398
|
useLunatic(sourceCheckboxGroup as any, undefined, {})
|
|
426
399
|
);
|
|
427
400
|
act(() => {
|
|
428
|
-
result.current.
|
|
429
|
-
{ name: 'NATIO1N1', value: false },
|
|
430
|
-
]);
|
|
401
|
+
result.current.handleChanges([{ name: 'NATIO1N1', value: false }]);
|
|
431
402
|
});
|
|
432
403
|
expect(result.current.hasPageResponse()).toBeFalsy();
|
|
433
404
|
});
|
|
@@ -6,17 +6,18 @@ import {
|
|
|
6
6
|
handleChangesAction,
|
|
7
7
|
} from './actions';
|
|
8
8
|
import { getPageTag, isFirstLastPage } from './commons';
|
|
9
|
+
|
|
10
|
+
import D from '../i18n';
|
|
11
|
+
import { COLLECTED } from '../utils/constants';
|
|
12
|
+
import { createLunaticProvider } from './lunatic-context';
|
|
9
13
|
import type {
|
|
14
|
+
LunaticSource,
|
|
10
15
|
LunaticChangesHandler,
|
|
11
16
|
LunaticData,
|
|
12
17
|
LunaticOptions,
|
|
13
18
|
LunaticState,
|
|
14
19
|
PageTag,
|
|
15
20
|
} from './type';
|
|
16
|
-
import D from '../i18n';
|
|
17
|
-
import { COLLECTED } from '../utils/constants';
|
|
18
|
-
import { createLunaticProvider } from './lunatic-context';
|
|
19
|
-
import type { LunaticSource } from './type';
|
|
20
21
|
import { compileControls as compileControlsLib } from './commons/compile-controls';
|
|
21
22
|
import { useLoopVariables } from './hooks/use-loop-variables';
|
|
22
23
|
import { getQuestionnaireData } from './commons/variables/get-questionnaire-data';
|
|
@@ -204,6 +205,7 @@ export function useLunatic(
|
|
|
204
205
|
goNextPage,
|
|
205
206
|
goPreviousPage,
|
|
206
207
|
management,
|
|
208
|
+
logger,
|
|
207
209
|
...state,
|
|
208
210
|
});
|
|
209
211
|
|
|
@@ -232,8 +234,6 @@ export function useLunatic(
|
|
|
232
234
|
hasPageResponse: usePageHasResponse(components, state.executeExpression),
|
|
233
235
|
// Components
|
|
234
236
|
Provider,
|
|
235
|
-
|
|
236
|
-
handleChanges,
|
|
237
|
-
},
|
|
237
|
+
handleChanges,
|
|
238
238
|
} satisfies LunaticState;
|
|
239
239
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cast functions that force an unknown type to a specific type
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Force a number (throw if it cannot be converted)
|
|
7
|
+
*/
|
|
8
|
+
export function castNumber(v: unknown): number {
|
|
9
|
+
if (typeof v === 'number') {
|
|
10
|
+
return v;
|
|
11
|
+
}
|
|
12
|
+
if (typeof v === 'string') {
|
|
13
|
+
return parseInt(v, 10);
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(v) && v.length > 0) {
|
|
16
|
+
return castNumber(v[0]);
|
|
17
|
+
}
|
|
18
|
+
throw new Error(`Cannot cast "${v}" to number`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Force a number, with a default value if an unmanageable type is encountered
|
|
23
|
+
*/
|
|
24
|
+
export const castNumberWithDefault =
|
|
25
|
+
(initial: number = 0) =>
|
|
26
|
+
(v: unknown): number => {
|
|
27
|
+
try {
|
|
28
|
+
return castNumber(v);
|
|
29
|
+
} catch {
|
|
30
|
+
return initial;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Force a bool
|
|
36
|
+
*/
|
|
37
|
+
export function castBool(v: unknown): boolean {
|
|
38
|
+
if (typeof v === 'boolean') {
|
|
39
|
+
return v;
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(v) && v.length > 0) {
|
|
42
|
+
return castBool(v[0]);
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(v)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return Boolean(v);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Force a string
|
|
52
|
+
*/
|
|
53
|
+
export function castString(v: unknown): string {
|
|
54
|
+
if (typeof v === 'string') {
|
|
55
|
+
return v;
|
|
56
|
+
}
|
|
57
|
+
if (typeof v === 'number') {
|
|
58
|
+
return v.toString();
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(v)) {
|
|
61
|
+
return v.map(castString).join(', ');
|
|
62
|
+
}
|
|
63
|
+
if (!v) {
|
|
64
|
+
return '';
|
|
65
|
+
}
|
|
66
|
+
return v.toString();
|
|
67
|
+
}
|
|
@@ -15,10 +15,6 @@ const data = {
|
|
|
15
15
|
},
|
|
16
16
|
PRENOMS: {
|
|
17
17
|
COLLECTED: ['Paul', 'Pierre'],
|
|
18
|
-
EDITED: [],
|
|
19
|
-
INPUTTED: [],
|
|
20
|
-
FORCED: [],
|
|
21
|
-
PREVIOUS: [],
|
|
22
18
|
},
|
|
23
19
|
AGE: {},
|
|
24
20
|
},
|
|
@@ -49,10 +45,6 @@ const loopCollectedVariable = {
|
|
|
49
45
|
variableType: 'COLLECTED',
|
|
50
46
|
values: {
|
|
51
47
|
COLLECTED: [],
|
|
52
|
-
PREVIOUS: [],
|
|
53
|
-
FORCED: [],
|
|
54
|
-
EDITED: [],
|
|
55
|
-
INPUTTED: [],
|
|
56
48
|
},
|
|
57
49
|
name: 'PRENOMS',
|
|
58
50
|
} as LunaticVariable;
|