@inseefr/lunatic 2.7.0-rc.5 → 2.7.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.
- package/README.md +45 -11
- package/lib/components/checkbox/checkbox-boolean/html/checkbox-boolean.js +3 -3
- package/lib/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.js +2 -1
- package/lib/components/checkbox/checkbox-group/checkbox-group-content.js +0 -2
- package/lib/components/checkbox/checkbox-group/html/checkbox-group-content.js +4 -2
- package/lib/components/checkbox/checkbox-group/html/checkbox-group.js +3 -3
- package/lib/components/checkbox/checkbox-group/lunatic-checkbox-group.js +2 -2
- package/lib/components/checkbox/checkbox-one/lunatic-checkbox-one.js +2 -1
- package/lib/components/checkbox/commons/checkbox-option.js +3 -1
- package/lib/components/commons/components/combo-box/combo-box-container.js +1 -2
- package/lib/components/commons/components/combo-box/combo-box.js +2 -2
- package/lib/components/commons/components/combo-box/selection/LabelOrInput.js +3 -1
- package/lib/components/commons/components/combo-box/selection/input.js +3 -1
- package/lib/components/commons/components/combo-box/selection/selection.js +3 -1
- package/lib/components/commons/components/errors/errors.js +12 -10
- package/lib/components/commons/components/errors/errors.spec.js +6 -6
- package/lib/components/component-set/html/__snapshots__/component-set.spec.tsx.snap +2 -0
- package/lib/components/component-set/html/component-set.js +2 -2
- package/lib/components/datepicker/html/DatepickerField.js +47 -0
- package/lib/components/datepicker/html/__snapshots__/datepicker.spec.tsx.snap +209 -17
- package/lib/components/datepicker/html/datepicker.js +104 -21
- package/lib/components/datepicker/html/datepicker.scss +19 -1
- package/lib/components/datepicker/html/datepicker.spec.js +71 -23
- package/lib/components/datepicker/lunatic-datepicker.js +5 -2
- package/lib/components/dropdown/lunatic-dropdown.js +2 -1
- package/lib/components/duration/duration.js +6 -7
- package/lib/components/duration/duration.scss +6 -14
- package/lib/components/duration/durationInput.js +14 -8
- package/lib/components/duration/durationUtils.js +38 -8
- package/lib/components/input/html/__snapshots__/input.spec.tsx.snap +2 -0
- package/lib/components/input/html/input.js +3 -3
- package/lib/components/input/lunatic-input.js +2 -1
- package/lib/components/input-number/html/__snapshots__/input-number.spec.tsx.snap +2 -2
- package/lib/components/input-number/html/input-number-thousand.js +4 -17
- package/lib/components/input-number/html/input-number.js +3 -5
- package/lib/components/input-number/lunatic-input-number.js +2 -3
- package/lib/components/loop/roster-for-loop/__snapshots__/roster-for-loop.spec.tsx.snap +88 -0
- package/lib/components/loop/roster-for-loop/roster-for-loop.js +7 -3
- package/lib/components/loop/roster-for-loop/roster-for-loop.spec.js +46 -0
- package/lib/components/lunatic-components.js +2 -11
- package/lib/components/radio/html/radio-group-content.js +4 -2
- package/lib/components/radio/html/radio-group.js +3 -3
- package/lib/components/radio/html/radio-option.js +3 -1
- package/lib/components/radio/lunatic-radio-group.js +2 -1
- package/lib/components/suggester/find-best-label/find-best-label.js +5 -5
- package/lib/components/suggester/idb-suggester/check-store.js +6 -3
- package/lib/components/suggester/idb-suggester/idb-suggester.js +8 -7
- package/lib/components/suggester/idb-suggester/suggester-status.js +1 -4
- package/lib/components/suggester/lunatic-suggester.js +7 -4
- package/lib/components/suggester/searching/create-searching.js +5 -5
- package/lib/components/switch/html/switch.js +2 -2
- package/lib/components/switch/lunatic-switch.js +2 -1
- package/lib/components/table/lunatic-table.js +2 -2
- package/lib/components/textarea/html/__snapshots__/textarea.spec.tsx.snap +2 -0
- package/lib/components/textarea/html/textarea.js +6 -4
- package/lib/components/textarea/lunatic-textarea.js +6 -3
- package/lib/hooks/use-auto-focus.js +26 -0
- package/lib/src/components/checkbox/checkbox-boolean/html/checkbox-boolean.d.ts +1 -1
- package/lib/src/components/checkbox/checkbox-group/html/checkbox-group-content.d.ts +2 -1
- package/lib/src/components/checkbox/checkbox-group/html/checkbox-group.d.ts +1 -1
- package/lib/src/components/checkbox/commons/checkbox-option.d.ts +1 -0
- package/lib/src/components/commons/components/combo-box/combo-box-container.d.ts +2 -2
- package/lib/src/components/commons/components/combo-box/combo-box.d.ts +2 -2
- package/lib/src/components/commons/components/combo-box/selection/LabelOrInput.d.ts +1 -0
- package/lib/src/components/commons/components/combo-box/selection/input.d.ts +1 -0
- package/lib/src/components/commons/components/combo-box/selection/selection.d.ts +2 -1
- package/lib/src/components/commons/components/errors/errors.d.ts +6 -3
- package/lib/src/components/datepicker/html/DatepickerField.d.ts +12 -0
- package/lib/src/components/datepicker/html/datepicker.d.ts +4 -3
- package/lib/src/components/datepicker/lunatic-datepicker.d.ts +1 -0
- package/lib/src/components/dropdown/html/dropdown-writable/dropdown-writable.d.ts +1 -1
- package/lib/src/components/dropdown/html/dropdown.d.ts +3 -1
- package/lib/src/components/duration/durationInput.d.ts +6 -2
- package/lib/src/components/duration/durationUtils.d.ts +24 -7
- package/lib/src/components/input/html/input.d.ts +2 -2
- package/lib/src/components/input-number/html/input-number-thousand.d.ts +2 -2
- package/lib/src/components/input-number/html/input-number.d.ts +2 -3
- package/lib/src/components/radio/html/radio-group-content.d.ts +2 -1
- package/lib/src/components/radio/html/radio-group.d.ts +1 -1
- package/lib/src/components/radio/html/radio-option.d.ts +1 -0
- package/lib/src/components/suggester/find-best-label/find-best-label.d.ts +1 -1
- package/lib/src/components/suggester/html/suggester.d.ts +1 -1
- package/lib/src/components/suggester/idb-suggester/check-store.d.ts +5 -2
- package/lib/src/components/suggester/idb-suggester/idb-suggester.d.ts +5 -2
- package/lib/src/components/suggester/idb-suggester/suggester-status.d.ts +1 -4
- package/lib/src/components/suggester/lunatic-suggester.d.ts +1 -1
- package/lib/src/components/suggester/searching/create-searching.d.ts +1 -1
- package/lib/src/components/switch/html/switch.d.ts +1 -1
- package/lib/src/components/textarea/html/textarea.d.ts +3 -2
- package/lib/src/components/type.d.ts +5 -3
- package/lib/src/hooks/use-auto-focus.d.ts +6 -0
- package/lib/src/use-lunatic/actions.d.ts +2 -0
- package/lib/src/use-lunatic/commons/fill-components/fill-component-required.d.ts +383 -0
- package/lib/src/use-lunatic/commons/fill-components/fill-component-value.d.ts +1 -1
- package/lib/src/use-lunatic/commons/fill-components/fill-component-value.spec.d.ts +1 -0
- package/lib/src/use-lunatic/commons/fill-components/fill-from-state.d.ts +20 -0
- package/lib/src/use-lunatic/commons/variables/lunatic-variables-store.d.ts +4 -0
- package/lib/src/use-lunatic/reducer/overview/overview-on-init.d.ts +1 -0
- package/lib/src/use-lunatic/type.d.ts +1 -0
- package/lib/src/use-lunatic/use-lunatic.d.ts +9 -5
- package/lib/src/use-lunatic/use-suggesters.d.ts +2 -1
- package/lib/src/utils/suggester-workers/append-to-index/create-append-task.d.ts +2 -2
- package/lib/src/utils/suggester-workers/worker-path.d.ts +1 -1
- package/lib/stories/behaviour/cleaning/source.json +151 -0
- package/lib/stories/behaviour/cleaning/test.stories.js +82 -0
- package/lib/stories/{questionnaires-test → behaviour}/controls/controls.stories.js +5 -5
- package/lib/stories/{questionnaires-test → behaviour/others}/test.stories.js +7 -7
- package/lib/stories/{paste-questionnaire → behaviour/paste}/test.stories.js +3 -3
- package/lib/stories/{resizing-questionnaire → behaviour/resizing}/test.stories.js +3 -3
- package/lib/stories/date-picker/datepicker.stories.js +32 -29
- package/lib/stories/duration/duration.stories.js +4 -4
- package/lib/stories/duration/{source.json → mois.json} +1 -1
- package/lib/stories/duration/{source1.json → time.json} +1 -1
- package/lib/use-lunatic/commons/fill-components/fill-component-required.js +23 -0
- package/lib/use-lunatic/commons/fill-components/fill-component-value.js +1 -1
- package/lib/use-lunatic/commons/fill-components/fill-component-value.spec.js +67 -0
- package/lib/use-lunatic/commons/fill-components/fill-components.js +2 -1
- package/lib/use-lunatic/commons/fill-components/fill-from-state.js +2 -0
- package/lib/use-lunatic/commons/variables/lunatic-variables-store.js +20 -0
- package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +15 -1
- package/lib/use-lunatic/initial-state.js +2 -1
- package/lib/use-lunatic/reducer/reduce-on-init.js +4 -2
- package/lib/use-lunatic/use-lunatic.js +12 -10
- package/lib/use-lunatic/use-suggesters.js +54 -37
- package/lib/utils/env.js +9 -1
- package/lib/utils/suggester-workers/append-to-index/create-append-task.js +4 -3
- package/lib/utils/suggester-workers/{create-worker-ts.js → create-worker.js} +10 -1
- package/lib/utils/suggester-workers/worker-path.js +5 -4
- package/package.json +20 -10
- package/scripts/build/add-workers-to-public.js +31 -31
- package/scripts/build/workers-paths.js +18 -7
- package/workers-release/{lunatic-append-worker-0.3.0-experimental.js → lunatic-append-worker-0.3.0.js} +1 -1
- package/workers-release/{lunatic-label-worker-0.3.0-experimental.js → lunatic-label-worker-0.3.0.js} +1 -1
- package/workers-release/{lunatic-searching-worker-0.3.0-experimental.js → lunatic-search-worker-0.3.0.js} +1 -1
- package/lib/components/datepicker/html/datepicker-container.js +0 -17
- package/lib/components/datepicker/html/datepicker-input.js +0 -35
- package/lib/env.d.js +0 -1
- package/lib/src/components/datepicker/html/datepicker-container.d.ts +0 -3
- package/lib/src/components/datepicker/html/datepicker-input.d.ts +0 -13
- package/lib/src/utils/get-component-value.d.ts +0 -5
- package/lib/utils/get-component-value.js +0 -34
- package/lib/utils/get-component-value.test.js +0 -57
- /package/lib/src/{utils/get-component-value.test.d.ts → components/loop/roster-for-loop/roster-for-loop.spec.d.ts} +0 -0
- /package/lib/src/utils/suggester-workers/{create-worker-ts.d.ts → create-worker.d.ts} +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_ControlesNonNum_horsBoucle_PasPageFin.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_ControlesNum_horsBoucle_PasPageFin.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_Controles_BouclesLiees2_PasPageFin.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_Controles_BouclesLiees_PasPageFin.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/boucles-n.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/controls-externes.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/controls-externes.stories.js +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/V2_DeclarationsSimples.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/V2_MinMaxSum_Boucles.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/V2_QuestSimple_Boucles.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/V2_TCMRallyeGames.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/test-dylan.json +0 -0
- /package/lib/stories/{paste-questionnaire → behaviour/paste}/source.json +0 -0
- /package/lib/stories/{resizing-questionnaire → behaviour/resizing}/source.json +0 -0
- /package/workers-release/{lunatic-append-worker-0.3.0-experimental.js.LICENSE.txt → lunatic-append-worker-0.3.0.js.LICENSE.txt} +0 -0
- /package/workers-release/{lunatic-label-worker-0.3.0-experimental.js.LICENSE.txt → lunatic-label-worker-0.3.0.js.LICENSE.txt} +0 -0
- /package/workers-release/{lunatic-searching-worker-0.3.0-experimental.js.LICENSE.txt → lunatic-search-worker-0.3.0.js.LICENSE.txt} +0 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Lunatic
|
|
4
4
|
|
|
5
|
-
[](https://github.com/InseeFr/Lunatic/actions/workflows/ci-main.yaml)
|
|
6
6
|
[](https://badge.fury.io/js/%40inseefr%2Flunatic)
|
|
7
7
|
[](https://sonarcloud.io/dashboard?id=InseeFr_Lunatic)
|
|
8
8
|
[](https://sonarcloud.io/dashboard?id=InseeFr_Lunatic)
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
|
|
11
11
|
Lunatic is a front-end library in the form of a React hook and component libraries for generating a questionnaire from the [Lunatic-Model](https://github.com/InseeFr/Lunatic-Model) data format.
|
|
12
12
|
|
|
13
|
+
- [Storybook 2.7](https://inseefr.github.io/Lunatic/storybook-2.7), branch `2.7`
|
|
14
|
+
- [Storybook 2.6](https://inseefr.github.io/Lunatic/storybook-2.6), branch `2.6`
|
|
13
15
|
- [Storybook v1](https://inseefr.github.io/Lunatic/storybook-0.3.9), branch `v1-main`
|
|
14
|
-
- [Storybook 2.7](https://inseefr.github.io/Lunatic/storybook), branch `2.7`
|
|
15
|
-
- [Storybook 2.6](https://inseefr.github.io/Lunatic/storybook-beta), branch `2.6`
|
|
16
16
|
- [Documentation](https://inseefr.github.io/Lunatic/en/)
|
|
17
17
|
|
|
18
18
|
## Table of Contents
|
|
@@ -80,7 +80,7 @@ And it returns an object that allows you to control the questionnaire:
|
|
|
80
80
|
- `getData()`, returns the collected data in the questionnaire.
|
|
81
81
|
- `loopVariables`, is an array containing the list of variables used for the current loop.
|
|
82
82
|
|
|
83
|
-
For more information on the types of this return, you can refer to the available types in the [source code](https://github.com/InseeFr/Lunatic/blob/
|
|
83
|
+
For more information on the types of this return, you can refer to the available types in the [source code](https://github.com/InseeFr/Lunatic/blob/2.7/src/use-lunatic/type.ts). You can also find an example of using the hook in the [Storybook section](https://github.com/InseeFr/Lunatic/blob/2.7/src/stories/utils/orchestrator.jsx#L121-L152).
|
|
84
84
|
|
|
85
85
|
### Components
|
|
86
86
|
|
|
@@ -107,10 +107,46 @@ function App({ source, data }) {
|
|
|
107
107
|
}
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
-
All the components offered by Lunatic are available in the [src/components](https://github.com/InseeFr/Lunatic/
|
|
110
|
+
All the components offered by Lunatic are available in the [src/components](https://github.com/InseeFr/Lunatic/tree/2.7/src/components) folder.
|
|
111
111
|
|
|
112
112
|
To activate the **autofocus**, you need to pass a key in the `autoFocusKey` property of `LunaticComponents`. As soon as this value changes, the first field is focused (a good solution is to pass the `pageTag` provided by `useLunatic`).
|
|
113
113
|
|
|
114
|
+
### Workers
|
|
115
|
+
|
|
116
|
+
#### General
|
|
117
|
+
|
|
118
|
+
Lunatic uses webWorkers to take the load off the main execution frame (e.g. list search).
|
|
119
|
+
|
|
120
|
+
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.
|
|
121
|
+
|
|
122
|
+
Lunatic workers are added to the `public/workers` folder of the current project when the library is installed.
|
|
123
|
+
|
|
124
|
+
If a new version of Lunatic offers new workers, they will be automatically updated.
|
|
125
|
+
This ensures that you always have the right version of workers for the version of Lunatic you're using.
|
|
126
|
+
|
|
127
|
+
A good practice is to add the `public/workers` folder to your `.gitignore.`
|
|
128
|
+
|
|
129
|
+
#### How it works
|
|
130
|
+
|
|
131
|
+
Workers are loaded into the latest version (version `workersVersion` of package.json) of the public `workers` folder.
|
|
132
|
+
|
|
133
|
+
It's up to you if you want to load them at runtime from another location.
|
|
134
|
+
Simply specify the base url of the workers folder to useLunatic.
|
|
135
|
+
|
|
136
|
+
For example, if your workers are hosted on the server `http://localhost:9090/static/final-workers`.
|
|
137
|
+
We would then have the workers available at the addresses :
|
|
138
|
+
|
|
139
|
+
- `http://localhost:9090/static/final-workers/lunatic-append-worker-0.3.0.js`
|
|
140
|
+
- `http://localhost:9090/static/final-workers/lunatic-label-worker-0.3.0.js`
|
|
141
|
+
- `http://localhost:9090/static/final-workers/lunatic-search-worker-0.3.0.js`
|
|
142
|
+
|
|
143
|
+
You'll need to specify the `workersBasePath` props in the useLunatic:
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
const { getComponents } = useLunatic(source, data,
|
|
147
|
+
{ features, preferences, ..., workersBasePath: 'http://localhost:9090/static/final-workers' })
|
|
148
|
+
```
|
|
149
|
+
|
|
114
150
|
## Customization
|
|
115
151
|
|
|
116
152
|
By default, the components offered by Lunatic are quite simple with a minimal style. You can customize the fields with your own CSS, but for more complex cases, you can also replace the basic components using the `custom` property that you can pass when calling `useLunatic`.
|
|
@@ -134,13 +170,13 @@ This section covers the internal working of the `useLunatic()` hook. The goal is
|
|
|
134
170
|
|
|
135
171
|
### General Functioning
|
|
136
172
|
|
|
137
|
-
The hook is based on an [internal state](https://github.com/InseeFr/Lunatic/blob/
|
|
173
|
+
The hook is based on an [internal state](https://github.com/InseeFr/Lunatic/blob/2.7/src/use-lunatic/type.ts#L79-L187) that is updated through a [reducer](https://reactjs.org/docs/hooks-reference.html#usereducer) system. The [actions](https://github.com/InseeFr/Lunatic/blob/2.7/src/use-lunatic/actions.ts) affecting this state are limited:
|
|
138
174
|
|
|
139
175
|
- An action `'use-lunatic/on-init'` allows initialization of the state from the data received as a parameter of the hook.
|
|
140
176
|
- The actions `'use-lunatic/go-previous'`, `'use-lunatic/go-next'`, and `'use-lunatic/go-to-page'` are called during navigation using the methods returned by the hook.
|
|
141
177
|
- The action `use-lunatic/handle-change` is the most important action and is called whenever data is changed in the questionnaire.
|
|
142
178
|
|
|
143
|
-
All the [reducers corresponding to these actions are available here](https://github.com/InseeFr/Lunatic/blob/
|
|
179
|
+
All the [reducers corresponding to these actions are available here](https://github.com/InseeFr/Lunatic/blob/2.7/src/use-lunatic/reducer/reducer.ts). Generally, they are broken down into several methods depending on the part of the state they modify.
|
|
144
180
|
|
|
145
181
|
### Pages and Pager
|
|
146
182
|
|
|
@@ -148,7 +184,7 @@ At initialization, the questionnaire scenario is modeled as an object which is s
|
|
|
148
184
|
|
|
149
185
|
### VTL Execution
|
|
150
186
|
|
|
151
|
-
Another important point of Lunatic is the execution of VTL expressions which allow making certain properties dynamic (labels, errors, etc.). This filling is done [when the state changes](https://github.com/InseeFr/Lunatic/blob/
|
|
187
|
+
Another important point of Lunatic is the execution of VTL expressions which allow making certain properties dynamic (labels, errors, etc.). This filling is done [when the state changes](https://github.com/InseeFr/Lunatic/blob/2.7/src/use-lunatic/commons/use-components-from-state.ts).
|
|
152
188
|
|
|
153
189
|
To facilitate expression execution, an `executeExpression()` method is exposed in the Lunatic state. This method is accompanied by an `updateBindings()` method which allows updating internal values. This expression execution system uses a memoization system to not re-execute the same expression multiple times. When the `use-lunatic/handle-change` action is executed, the values ("bindings") are updated to memorize the values associated with the different VTL variables. Similarly, the values of calculated variables on which the modified variable depends are forgotten to refresh the value during the next execution.
|
|
154
190
|
|
|
@@ -158,9 +194,7 @@ To facilitate expression execution, an `executeExpression()` method is exposed i
|
|
|
158
194
|
|
|
159
195
|
- Stable branches follow the glob pattern `'2.*'`, like `2.6` or `2.7`.
|
|
160
196
|
- We can maintain if needs, the old stable branches
|
|
161
|
-
- `
|
|
162
|
-
- `develop` branch is temporarily maintained. (actually `develop` is the `2.7` branch = the future main release)
|
|
163
|
-
- `develop` branch will be deleted soon with this new convention
|
|
197
|
+
- `2.7` branch is currently the most advanced branch
|
|
164
198
|
|
|
165
199
|
### Commits and feature branches
|
|
166
200
|
|
|
@@ -24,10 +24,10 @@ function CheckboxBoolean(_ref) {
|
|
|
24
24
|
id: id,
|
|
25
25
|
onClick: onClick !== null && onClick !== void 0 ? onClick : _function.voidFunction,
|
|
26
26
|
label: label,
|
|
27
|
-
description: description
|
|
27
|
+
description: description,
|
|
28
|
+
invalid: !!errors
|
|
28
29
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
|
|
29
|
-
errors: errors
|
|
30
|
-
activeId: id
|
|
30
|
+
errors: errors
|
|
31
31
|
})]
|
|
32
32
|
});
|
|
33
33
|
}
|
|
@@ -7,6 +7,7 @@ exports["default"] = void 0;
|
|
|
7
7
|
var _lunaticComponentWithoutLabel = _interopRequireDefault(require("../../commons/components/lunatic-component-without-label"));
|
|
8
8
|
var _useOnHandleChange = _interopRequireDefault(require("../../commons/use-on-handle-change"));
|
|
9
9
|
var _checkboxBoolean = _interopRequireDefault(require("./html/checkbox-boolean"));
|
|
10
|
+
var _errors = require("../../commons/components/errors/errors");
|
|
10
11
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
13
|
function LunaticCheckboxBoolean(_ref) {
|
|
@@ -45,7 +46,7 @@ function LunaticCheckboxBoolean(_ref) {
|
|
|
45
46
|
onClick: onChange,
|
|
46
47
|
disabled: disabled,
|
|
47
48
|
label: label,
|
|
48
|
-
errors: errors
|
|
49
|
+
errors: (0, _errors.getComponentErrors)(errors, id)
|
|
49
50
|
})
|
|
50
51
|
});
|
|
51
52
|
}
|
|
@@ -4,11 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
7
|
var _commons = require("../commons");
|
|
9
8
|
require("./checkbox.scss");
|
|
10
9
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
10
|
function CheckboxGroupContent(_ref) {
|
|
13
11
|
var options = _ref.options,
|
|
14
12
|
id = _ref.id;
|
|
@@ -10,7 +10,8 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
10
10
|
function CheckboxGroupContent(_ref) {
|
|
11
11
|
var options = _ref.options,
|
|
12
12
|
id = _ref.id,
|
|
13
|
-
shortcut = _ref.shortcut
|
|
13
|
+
shortcut = _ref.shortcut,
|
|
14
|
+
invalid = _ref.invalid;
|
|
14
15
|
var maxIndex = options.length;
|
|
15
16
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
16
17
|
children: options.map(function (option, index) {
|
|
@@ -30,7 +31,8 @@ function CheckboxGroupContent(_ref) {
|
|
|
30
31
|
label: label,
|
|
31
32
|
description: description,
|
|
32
33
|
shortcut: shortcut,
|
|
33
|
-
codeModality: shortcut ? codeModality : undefined
|
|
34
|
+
codeModality: shortcut ? codeModality : undefined,
|
|
35
|
+
invalid: invalid
|
|
34
36
|
})
|
|
35
37
|
}, checkboxId);
|
|
36
38
|
})
|
|
@@ -23,10 +23,10 @@ function CheckboxGroup(_ref) {
|
|
|
23
23
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_checkboxGroupContent["default"], {
|
|
24
24
|
id: id,
|
|
25
25
|
options: options,
|
|
26
|
-
shortcut: shortcut
|
|
26
|
+
shortcut: shortcut,
|
|
27
|
+
invalid: !!errors
|
|
27
28
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
|
|
28
|
-
errors: errors
|
|
29
|
-
activeId: id
|
|
29
|
+
errors: errors
|
|
30
30
|
})]
|
|
31
31
|
});
|
|
32
32
|
}
|
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
7
|
var _lunaticComponentWithoutLabel = _interopRequireDefault(require("../../commons/components/lunatic-component-without-label"));
|
|
9
8
|
var _checkboxGroup = _interopRequireDefault(require("./html/checkbox-group"));
|
|
9
|
+
var _errors = require("../../commons/components/errors/errors");
|
|
10
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
12
|
function LunaticCheckboxGroup(_ref) {
|
|
@@ -53,7 +53,7 @@ function LunaticCheckboxGroup(_ref) {
|
|
|
53
53
|
id: id,
|
|
54
54
|
options: options,
|
|
55
55
|
label: label,
|
|
56
|
-
errors: errors,
|
|
56
|
+
errors: (0, _errors.getComponentErrors)(errors, id),
|
|
57
57
|
shortcut: shortcut
|
|
58
58
|
})
|
|
59
59
|
});
|
|
@@ -7,6 +7,7 @@ exports["default"] = void 0;
|
|
|
7
7
|
var _lunaticComponentWithoutLabel = _interopRequireDefault(require("../../commons/components/lunatic-component-without-label"));
|
|
8
8
|
var _useOnHandleChange = _interopRequireDefault(require("../../commons/use-on-handle-change"));
|
|
9
9
|
var _checkboxOne = _interopRequireDefault(require("./html/checkbox-one"));
|
|
10
|
+
var _errors = require("../../commons/components/errors/errors");
|
|
10
11
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
13
|
function LunaticCheckboxOne(_ref) {
|
|
@@ -45,7 +46,7 @@ function LunaticCheckboxOne(_ref) {
|
|
|
45
46
|
className: "lunatic-checkbox-one",
|
|
46
47
|
options: options,
|
|
47
48
|
value: value,
|
|
48
|
-
errors: errors,
|
|
49
|
+
errors: (0, _errors.getComponentErrors)(errors, id),
|
|
49
50
|
onSelect: onSelect,
|
|
50
51
|
label: label,
|
|
51
52
|
shortcut: shortcut
|
|
@@ -20,7 +20,8 @@ function CheckboxOption(_ref) {
|
|
|
20
20
|
label = _ref.label,
|
|
21
21
|
description = _ref.description,
|
|
22
22
|
codeModality = _ref.codeModality,
|
|
23
|
-
shortcut = _ref.shortcut
|
|
23
|
+
shortcut = _ref.shortcut,
|
|
24
|
+
invalid = _ref.invalid;
|
|
24
25
|
var onClickOption = (0, _react.useCallback)(function () {
|
|
25
26
|
onClick(!checked);
|
|
26
27
|
}, [checked, onClick]);
|
|
@@ -41,6 +42,7 @@ function CheckboxOption(_ref) {
|
|
|
41
42
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
42
43
|
id: id,
|
|
43
44
|
role: "checkbox",
|
|
45
|
+
"aria-invalid": invalid,
|
|
44
46
|
className: "lunatic-input-checkbox",
|
|
45
47
|
"aria-checked": checked,
|
|
46
48
|
tabIndex: 0,
|
|
@@ -21,8 +21,7 @@ function ComboBoxContainer(_ref) {
|
|
|
21
21
|
id: "".concat(classNamePrefix !== null && classNamePrefix !== void 0 ? classNamePrefix : 'lunatic', "-combo-box-container-").concat(id),
|
|
22
22
|
className: (0, _classnames["default"])(className, "".concat(classNamePrefix !== null && classNamePrefix !== void 0 ? classNamePrefix : 'lunatic', "-combo-box-container"), "".concat(classNamePrefix !== null && classNamePrefix !== void 0 ? classNamePrefix : 'lunatic', "-suggester-").concat(classStyle), "lunatic-suggester-default-style", classStyle),
|
|
23
23
|
children: [children, errors && /*#__PURE__*/(0, _jsxRuntime.jsx)(_errors["default"], {
|
|
24
|
-
errors: errors
|
|
25
|
-
activeId: id
|
|
24
|
+
errors: errors
|
|
26
25
|
})]
|
|
27
26
|
});
|
|
28
27
|
}
|
|
@@ -131,7 +131,6 @@ function ComboBox(_ref) {
|
|
|
131
131
|
children: messageError
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
|
-
console.log(readOnly);
|
|
135
134
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_comboBoxContainer["default"], {
|
|
136
135
|
id: id,
|
|
137
136
|
className: className,
|
|
@@ -163,7 +162,8 @@ function ComboBox(_ref) {
|
|
|
163
162
|
selectedIndex: selectedIndex,
|
|
164
163
|
options: options,
|
|
165
164
|
onChange: handleChange,
|
|
166
|
-
classNamePrefix: classNamePrefix
|
|
165
|
+
classNamePrefix: classNamePrefix,
|
|
166
|
+
invalid: !!errors
|
|
167
167
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_panel.Panel, {
|
|
168
168
|
optionRenderer: optionRenderer,
|
|
169
169
|
options: options,
|
|
@@ -29,7 +29,8 @@ function LabelOrInput(props) {
|
|
|
29
29
|
readOnly = props.readOnly,
|
|
30
30
|
id = props.id,
|
|
31
31
|
focused = props.focused,
|
|
32
|
-
onChange = props.onChange
|
|
32
|
+
onChange = props.onChange,
|
|
33
|
+
invalid = props.invalid;
|
|
33
34
|
if (displayLabel) {
|
|
34
35
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_labelSelection["default"], {
|
|
35
36
|
labelRenderer: labelRenderer,
|
|
@@ -42,6 +43,7 @@ function LabelOrInput(props) {
|
|
|
42
43
|
});
|
|
43
44
|
}
|
|
44
45
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_input["default"], {
|
|
46
|
+
invalid: invalid,
|
|
45
47
|
id: "combobox-input-".concat(id),
|
|
46
48
|
className: "lunatic-combo-box-input",
|
|
47
49
|
onChange: onChange,
|
|
@@ -20,7 +20,8 @@ function Input(_ref) {
|
|
|
20
20
|
id = _ref.id,
|
|
21
21
|
labelledBy = _ref.labelledBy,
|
|
22
22
|
focused = _ref.focused,
|
|
23
|
-
className = _ref.className
|
|
23
|
+
className = _ref.className,
|
|
24
|
+
invalid = _ref.invalid;
|
|
24
25
|
var inputEl = (0, _react.useRef)(null);
|
|
25
26
|
(0, _react.useEffect)(function () {
|
|
26
27
|
if (inputEl.current && focused) {
|
|
@@ -41,6 +42,7 @@ function Input(_ref) {
|
|
|
41
42
|
onChange: onChange,
|
|
42
43
|
value: value,
|
|
43
44
|
"aria-label": "lunatic-combo-box",
|
|
45
|
+
"aria-invalid": invalid,
|
|
44
46
|
title: "combo-box",
|
|
45
47
|
autoComplete: "off",
|
|
46
48
|
autoCapitalize: "off",
|
|
@@ -23,7 +23,8 @@ function Selection(_ref) {
|
|
|
23
23
|
editable = _ref.editable,
|
|
24
24
|
labelId = _ref.labelId,
|
|
25
25
|
id = _ref.id,
|
|
26
|
-
classNamePrefix = _ref.classNamePrefix
|
|
26
|
+
classNamePrefix = _ref.classNamePrefix,
|
|
27
|
+
invalid = _ref.invalid;
|
|
27
28
|
var onChangeEx = (0, _react.useCallback)(function (e) {
|
|
28
29
|
onChange === null || onChange === void 0 || onChange(e.target.value);
|
|
29
30
|
}, [onChange]);
|
|
@@ -34,6 +35,7 @@ function Selection(_ref) {
|
|
|
34
35
|
"aria-owns": "".concat(id, "-list"),
|
|
35
36
|
classNamePrefix: classNamePrefix,
|
|
36
37
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_LabelOrInput.LabelOrInput, {
|
|
38
|
+
invalid: invalid,
|
|
37
39
|
labelRenderer: labelRenderer,
|
|
38
40
|
placeholder: placeholder,
|
|
39
41
|
selectedIndex: selectedIndex,
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
+
exports.getComponentErrors = getComponentErrors;
|
|
7
8
|
require("./errors.scss");
|
|
8
9
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
10
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
@@ -12,19 +13,17 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
12
13
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
14
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
14
15
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
+
/**
|
|
17
|
+
* Display a list of error as simple red text
|
|
18
|
+
*/
|
|
15
19
|
function Errors(_ref) {
|
|
16
|
-
var errors = _ref.errors
|
|
17
|
-
activeId = _ref.activeId;
|
|
20
|
+
var errors = _ref.errors;
|
|
18
21
|
if (!errors) {
|
|
19
22
|
return null;
|
|
20
23
|
}
|
|
21
|
-
var activeErrors = getActiveErrors(errors, activeId);
|
|
22
|
-
if (!activeErrors) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
24
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
26
25
|
className: "lunatic-errors",
|
|
27
|
-
children:
|
|
26
|
+
children: errors.map(function (_ref2) {
|
|
28
27
|
var id = _ref2.id,
|
|
29
28
|
errorMessage = _ref2.errorMessage;
|
|
30
29
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
@@ -34,15 +33,18 @@ function Errors(_ref) {
|
|
|
34
33
|
})
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
|
-
function
|
|
36
|
+
function getComponentErrors(errors, componentId) {
|
|
37
|
+
if (!componentId || !errors) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
38
40
|
var activeErrors = Object.entries(errors).find(function (_ref3) {
|
|
39
41
|
var _ref4 = _slicedToArray(_ref3, 1),
|
|
40
42
|
k = _ref4[0];
|
|
41
|
-
return
|
|
43
|
+
return componentId === null || componentId === void 0 ? void 0 : componentId.trim().endsWith(k);
|
|
42
44
|
});
|
|
43
45
|
if (Array.isArray(activeErrors) && Array.isArray(activeErrors[1])) {
|
|
44
46
|
return activeErrors[1];
|
|
45
47
|
}
|
|
46
|
-
return
|
|
48
|
+
return undefined;
|
|
47
49
|
}
|
|
48
50
|
var _default = exports["default"] = Errors;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
4
|
var _react = require("@testing-library/react");
|
|
4
5
|
var _vitest = require("vitest");
|
|
5
|
-
var _errors =
|
|
6
|
+
var _errors = _interopRequireWildcard(require("./errors"));
|
|
6
7
|
var _typeSource = require("../../../../use-lunatic/type-source");
|
|
7
8
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
-
function
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
9
11
|
(0, _vitest.describe)('Errors component', function () {
|
|
10
12
|
var errors = {
|
|
11
13
|
id1: [{
|
|
@@ -28,16 +30,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
28
30
|
};
|
|
29
31
|
(0, _vitest.it)('renders null when no active errors', function () {
|
|
30
32
|
var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_errors["default"], {
|
|
31
|
-
errors: errors,
|
|
32
|
-
activeId: "id3"
|
|
33
|
+
errors: (0, _errors.getComponentErrors)(errors, 'id3')
|
|
33
34
|
})),
|
|
34
35
|
container = _render.container;
|
|
35
36
|
(0, _vitest.expect)(container.firstChild).toBeNull();
|
|
36
37
|
});
|
|
37
38
|
(0, _vitest.it)('renders active errors', function () {
|
|
38
39
|
var _render2 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_errors["default"], {
|
|
39
|
-
errors: errors,
|
|
40
|
-
activeId: "id2"
|
|
40
|
+
errors: (0, _errors.getComponentErrors)(errors, 'id2')
|
|
41
41
|
})),
|
|
42
42
|
getByText = _render2.getByText;
|
|
43
43
|
(0, _vitest.expect)(getByText('Error 2 message')).toBeInTheDocument();
|
|
@@ -47,6 +47,7 @@ exports[`ComponentSet > renders without crashing 1`] = `
|
|
|
47
47
|
</span>
|
|
48
48
|
</label>
|
|
49
49
|
<input
|
|
50
|
+
aria-invalid="false"
|
|
50
51
|
aria-labelledby="label-toto1"
|
|
51
52
|
autocomplete="off"
|
|
52
53
|
id="toto1"
|
|
@@ -108,6 +109,7 @@ exports[`ComponentSet > should handle readOnly in sub-components 1`] = `
|
|
|
108
109
|
</span>
|
|
109
110
|
</label>
|
|
110
111
|
<input
|
|
112
|
+
aria-invalid="false"
|
|
111
113
|
aria-labelledby="label-toto1"
|
|
112
114
|
autocomplete="off"
|
|
113
115
|
id="toto1"
|
|
@@ -7,6 +7,7 @@ exports.ComponentSet = void 0;
|
|
|
7
7
|
exports.ComponentSetBase = ComponentSetBase;
|
|
8
8
|
var _commons = require("../../commons");
|
|
9
9
|
var _componentSetLegend = require("./component-set-legend");
|
|
10
|
+
var _errors = require("../../commons/components/errors/errors");
|
|
10
11
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
12
|
function ComponentSetBase(_ref) {
|
|
12
13
|
var id = _ref.id,
|
|
@@ -20,8 +21,7 @@ function ComponentSetBase(_ref) {
|
|
|
20
21
|
id: labelId,
|
|
21
22
|
children: legendText
|
|
22
23
|
}), children, /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
|
|
23
|
-
errors: errors,
|
|
24
|
-
activeId: id
|
|
24
|
+
errors: (0, _errors.getComponentErrors)(errors, id)
|
|
25
25
|
})]
|
|
26
26
|
});
|
|
27
27
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DatepickerField = DatepickerField;
|
|
7
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
function DatepickerField(_ref) {
|
|
11
|
+
var label = _ref.label,
|
|
12
|
+
id = _ref.id,
|
|
13
|
+
description = _ref.description,
|
|
14
|
+
onChange = _ref.onChange,
|
|
15
|
+
value = _ref.value,
|
|
16
|
+
max = _ref.max,
|
|
17
|
+
readOnly = _ref.readOnly,
|
|
18
|
+
disabled = _ref.disabled;
|
|
19
|
+
var handleChange = function handleChange(e) {
|
|
20
|
+
if (!Number.isNaN(e.target.valueAsNumber) && (max && e.target.valueAsNumber > max || e.target.valueAsNumber < 1)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
onChange(e.target.valueAsNumber);
|
|
24
|
+
};
|
|
25
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
26
|
+
className: (0, _classnames["default"])('lunaticDatepickerField', !max && 'lunaticDatepickerFieldLarge'),
|
|
27
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
|
|
28
|
+
htmlFor: id,
|
|
29
|
+
children: [label, /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
30
|
+
className: "lunaticDatepickerHint",
|
|
31
|
+
children: description
|
|
32
|
+
})]
|
|
33
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
34
|
+
id: id,
|
|
35
|
+
type: "number",
|
|
36
|
+
min: 1,
|
|
37
|
+
max: max,
|
|
38
|
+
readOnly: readOnly,
|
|
39
|
+
disabled: disabled,
|
|
40
|
+
value: Number.isNaN(value) ? '' : value,
|
|
41
|
+
onChange: handleChange,
|
|
42
|
+
onFocus: function onFocus(e) {
|
|
43
|
+
return e.target.select();
|
|
44
|
+
}
|
|
45
|
+
})]
|
|
46
|
+
});
|
|
47
|
+
}
|