@inseefr/lunatic 2.4.7-datePicker → 2.4.7-gotopage

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.
@@ -14,12 +14,6 @@ var _jsxRuntime = require("react/jsx-runtime");
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
15
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
16
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
18
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
19
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
20
- 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; }
21
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
22
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
23
17
  function Datepicker(_ref) {
24
18
  var disabled = _ref.disabled,
25
19
  readOnly = _ref.readOnly,
@@ -33,21 +27,10 @@ function Datepicker(_ref) {
33
27
  errors = _ref.errors,
34
28
  description = _ref.description;
35
29
  var labelId = "lunatic-datepicker-".concat(id);
36
-
37
- // store the date value in the local date state
38
- var _useState = (0, _react.useState)(value || ''),
39
- _useState2 = _slicedToArray(_useState, 2),
40
- date = _useState2[0],
41
- setDate = _useState2[1];
42
-
43
- // custom event handler to update date value
44
- var handleDateChange = function handleDateChange(event) {
45
- var inputValue = event.target.value;
46
- setDate(inputValue);
47
- if (onChange) {
48
- onChange(inputValue);
49
- }
50
- };
30
+ var handleChange = (0, _react.useCallback)(function (e) {
31
+ var value = e.target.value;
32
+ onChange(value);
33
+ }, [onChange]);
51
34
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_datepickerContainer["default"], {
52
35
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Label, {
53
36
  htmlFor: id,
@@ -59,8 +42,8 @@ function Datepicker(_ref) {
59
42
  labelId: labelId,
60
43
  readOnly: readOnly,
61
44
  disabled: disabled,
62
- value: date,
63
- onChange: handleDateChange,
45
+ value: value,
46
+ onChange: handleChange,
64
47
  min: min,
65
48
  max: max
66
49
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
  var _actions = require("../actions");
8
+ var _pageTag = require("../commons/page-tag");
8
9
  var _commons = require("./commons");
9
10
  var _reduceGoNextPage = _interopRequireDefault(require("./reduce-go-next-page"));
10
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -15,14 +16,13 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
15
16
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
16
17
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
17
18
  function validateChange(state) {
18
- var updatedState = _objectSpread({}, state);
19
- if ((0, _commons.isOnEmptyPage)(updatedState)) {
20
- return (0, _reduceGoNextPage["default"])(updatedState, {
19
+ if ((0, _commons.isOnEmptyPage)(state)) {
20
+ return (0, _reduceGoNextPage["default"])(state, {
21
21
  type: _actions.ActionKind.GO_NEXT_PAGE,
22
22
  payload: {}
23
23
  });
24
24
  }
25
- return updatedState;
25
+ return state;
26
26
  }
27
27
  function resolveSubPage(state, action) {
28
28
  var pager = state.pager,
@@ -54,26 +54,42 @@ function resolveSubPage(state, action) {
54
54
  function reduceGoToPage(state, action) {
55
55
  var isInLoop = state.isInLoop,
56
56
  pager = state.pager;
57
- var _action$payload2 = action.payload,
58
- newPage = _action$payload2.page,
59
- iteration = _action$payload2.iteration;
60
- if (iteration !== undefined) {
61
- return resolveSubPage(state, action);
57
+ var newState = _objectSpread({}, state);
58
+
59
+ // The page contains non digit, extract information from it
60
+ if (action.payload.page.match(/\D/)) {
61
+ var _pager = (0, _pageTag.getPagerFromPageTag)(action.payload.page);
62
+ if (_pager) {
63
+ action.payload.iteration = _pager.iteration;
64
+ action.payload.subPage = _pager.subPage;
65
+ action.payload.page = _pager.page;
66
+ }
62
67
  }
63
- if (!isInLoop) return _objectSpread(_objectSpread({}, state), {}, {
64
- pager: _objectSpread(_objectSpread({}, pager), {}, {
65
- subPage: undefined,
66
- nbSubPages: undefined,
67
- iteration: undefined,
68
- nbIterations: undefined,
69
- page: newPage
70
- })
71
- });
72
- // TODO: fix when redirect to loop component
73
- // How to calculate nbSubPages & nbIterations?
74
- // How to calculate lazy variables we need?
75
- // Handle setLoopBindings with the good iteration
76
- return validateChange(state);
68
+
69
+ // The page is still not a number, cancel the action
70
+ if (action.payload.page.match(/\D/)) {
71
+ console.error("Cannot reach page \"".concat(action.payload.page, "\", not a number"));
72
+ return state;
73
+ }
74
+ if (action.payload.iteration !== undefined) {
75
+ newState = resolveSubPage(state, action);
76
+ } else if (!isInLoop) {
77
+ newState = _objectSpread(_objectSpread({}, state), {}, {
78
+ pager: _objectSpread(_objectSpread({}, pager), {}, {
79
+ subPage: undefined,
80
+ nbSubPages: undefined,
81
+ iteration: undefined,
82
+ nbIterations: undefined,
83
+ page: action.payload.page
84
+ })
85
+ });
86
+ // TODO: fix when redirect to loop component
87
+ // How to calculate nbSubPages & nbIterations?
88
+ // How to calculate lazy variables we need?
89
+ // Handle setLoopBindings with the good iteration
90
+ }
91
+
92
+ return validateChange(newState);
77
93
  }
78
94
  var _default = reduceGoToPage;
79
95
  exports["default"] = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inseefr/lunatic",
3
- "version": "2.4.7-datePicker",
3
+ "version": "2.4.7-gotopage",
4
4
  "workersVersion": "0.2.5-experimental",
5
5
  "description": "Library of questionnaire components",
6
6
  "repository": {