grommet 2.20.0 → 2.20.1

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.
@@ -63,7 +63,7 @@ var padStyle = function padStyle(_ref) {
63
63
  };
64
64
 
65
65
  var basicStyle = function basicStyle(props) {
66
- return (0, _styledComponents.css)(["border:none;", ";", " ", " ", ""], radiusStyle(props), padStyle(props), fontStyle(props), props.icon && "\n > svg {\n display: flex;\n align-self: center;\n }\n ");
66
+ return (0, _styledComponents.css)(["border:none;", ";", " ", " ", ""], radiusStyle(props), padStyle(props), fontStyle(props), props.icon && "\n > svg {\n display: flex;\n align-self: center;\n vertical-align: middle;\n }\n ");
67
67
  };
68
68
 
69
69
  var getPath = function getPath(theme, path) {
@@ -179,7 +179,9 @@ var fillStyle = function fillStyle(fillContainer) {
179
179
  return undefined;
180
180
  };
181
181
 
182
- var plainStyle = (0, _styledComponents.css)(["outline:none;border:none;padding:0;text-align:inherit;color:inherit;"]);
182
+ var plainStyle = function plainStyle(props) {
183
+ return (0, _styledComponents.css)(["outline:none;border:none;padding:0;text-align:inherit;color:inherit;", ""], props.icon && "\n > svg {\n display: flex;\n align-self: center;\n vertical-align: middle;\n }\n ");
184
+ };
183
185
 
184
186
  var StyledButtonKind = _styledComponents["default"].button.withConfig({
185
187
  // don't let kind attribute leak to DOM
@@ -191,7 +193,7 @@ var StyledButtonKind = _styledComponents["default"].button.withConfig({
191
193
  displayName: "StyledButtonKind",
192
194
  componentId: "sc-1vhfpnt-0"
193
195
  })(["display:inline-block;box-sizing:border-box;cursor:pointer;font:inherit;text-decoration:none;margin:0;background:transparent;overflow:visible;text-transform:none;", " ", " ", " ", " ", " ", " ", " ", " &:focus{", "}&:focus:not(:focus-visible){", "}", " ", " ", ""], _utils.genericStyles, function (props) {
194
- return props.plain && plainStyle;
196
+ return props.plain && plainStyle(props);
195
197
  }, function (props) {
196
198
  return !props.disabled && props.active && _utils.activeStyle;
197
199
  }, function (props) {
@@ -177,7 +177,7 @@ var normalizeForTimezone = function normalizeForTimezone(value, timestamp) {
177
177
 
178
178
  if (timestamp && typeof timestamp === 'string') {
179
179
  hourDelta = parseInt(timestamp == null ? void 0 : timestamp.split(':')[0], 10);
180
- valueOffset = hourDelta * 60 * 1000; // ms
180
+ valueOffset = hourDelta * 60 * 60 * 1000; // ms
181
181
  }
182
182
 
183
183
  var localOffset = new Date().getTimezoneOffset() * 60 * 1000;
@@ -174,8 +174,15 @@ var textToValue = function textToValue(text, schema, range, timestamp) {
174
174
  parts.m = pullDigits(text, index);
175
175
  index += parts.m.length;
176
176
  } else if (_char3 === 'd') {
177
- parts.d = pullDigits(text, index);
178
- index += parts.d.length;
177
+ var _parts, _parts$d;
178
+
179
+ parts.d = pullDigits(text, index); // when format is something like yyyy/mm/dd,
180
+ // '0' as incomplete day can cause date to be
181
+ // prematurely calculated.
182
+ // ex: 2022/01/0 would reutrn 2021/12/31 in addDate()
183
+
184
+ if (parts.d === '0') delete parts.d;
185
+ index += ((_parts = parts) == null ? void 0 : (_parts$d = _parts.d) == null ? void 0 : _parts$d.length) || 0;
179
186
  } else if (_char3 === 'y') {
180
187
  parts.y = pullDigits(text, index);
181
188
  index += parts.y.length;
@@ -114,20 +114,18 @@ var validate = function validate(rule, fieldValue, formValue, format, messages)
114
114
  var validateName = function validateName(validationRules, required) {
115
115
  return function (name, formValue, format, messages) {
116
116
  var fieldValue = getFieldValue(name, formValue);
117
- var validationResult; // ValidateArg is something that gets passed in from a FormField component
118
- // See 'validate' prop in FormField
117
+ var validationResult;
119
118
 
120
119
  if (required && ( // false is for CheckBox
121
120
  fieldValue === undefined || fieldValue === '' || fieldValue === false || Array.isArray(fieldValue) && !fieldValue.length)) {
122
- // There is no value at that name, and one is required
123
121
  validationResult = format({
124
122
  id: 'form.required',
125
123
  messages: messages
126
124
  });
127
125
  } else if (validationRules) {
128
126
  if (Array.isArray(validationRules)) {
129
- validationRules.some(function (validator) {
130
- validationResult = validate(validator, fieldValue, formValue, format, messages);
127
+ validationRules.some(function (rule) {
128
+ validationResult = validate(rule, fieldValue, formValue, format, messages);
131
129
  return !!validationResult;
132
130
  });
133
131
  } else {
@@ -137,8 +135,7 @@ var validateName = function validateName(validationRules, required) {
137
135
 
138
136
  return validationResult;
139
137
  };
140
- }; // validations is an array from Object.entries()
141
- // Validates all keys in formValue
138
+ }; // Validates all keys in formValue
142
139
 
143
140
 
144
141
  var validateForm = function validateForm(validationRules, formValue, format, messages, omitValid) {
@@ -213,28 +210,32 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
213
210
  touched = _useState2[0],
214
211
  setTouched = _useState2[1];
215
212
 
216
- var _useState3 = (0, _react.useState)(defaultValidationResults),
213
+ var _useState3 = (0, _react.useState)({
214
+ errors: errorsProp,
215
+ infos: infosProp
216
+ }),
217
217
  validationResults = _useState3[0],
218
- setValidationResults = _useState3[1]; // when onBlur input validation is triggered, we need to complete any
219
- // potential click events before running the onBlur validation.
220
- // otherwise, click events like reset, etc. may not be registered.
221
- // for a detailed scenario/discussion,
222
- // see: https://github.com/grommet/grommet/issues/4863
223
- // the value of pendingValidation is the name of the FormField
224
- // awaiting validation.
218
+ setValidationResults = _useState3[1]; // maintain a copy of validationResults in a ref for useEffects
219
+ // which can't depend on validationResults directly without
220
+ // causing infinite renders.
225
221
 
226
222
 
227
- var _useState4 = (0, _react.useState)(undefined),
228
- pendingValidation = _useState4[0],
229
- setPendingValidation = _useState4[1];
223
+ var validationResultsRef = (0, _react.useRef)({}); // Simulated onMount state. Consider Form to be mounted once it has
224
+ // accounted for values originating from controlled inputs (available
225
+ // at second rendering).
226
+
227
+ var _useState4 = (0, _react.useState)('unmounted'),
228
+ mounted = _useState4[0],
229
+ setMounted = _useState4[1];
230
230
 
231
231
  (0, _react.useEffect)(function () {
232
- setPendingValidation(undefined);
233
- setValidationResults({
234
- errors: errorsProp,
235
- infos: infosProp
236
- });
237
- }, [errorsProp, infosProp]);
232
+ if (!mounted) setMounted('mounting');else if (mounted === 'mounting') setMounted('mounted');
233
+ }, [mounted]); // `pendingValidation` is the name of the FormField awaiting validation.
234
+
235
+ var _useState5 = (0, _react.useState)(undefined),
236
+ pendingValidation = _useState5[0],
237
+ setPendingValidation = _useState5[1];
238
+
238
239
  var validationRulesRef = (0, _react.useRef)({});
239
240
  var requiredFields = (0, _react.useRef)([]);
240
241
  var buildValid = (0, _react.useCallback)(function (nextErrors) {
@@ -257,95 +258,90 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
257
258
  }).forEach(function (n) {
258
259
  return delete nextValidations[n];
259
260
  });
260
- }; // On initial mount, when validateOn is change or blur,
261
- // set validation results for any set fields and calculate whether
262
- // the form is valid overall.
261
+ };
263
262
 
263
+ var applyValidationRules = (0, _react.useCallback)(function (validationRules) {
264
+ var _validateForm = validateForm(validationRules, value, format, messages),
265
+ validatedErrors = _validateForm[0],
266
+ validatedInfos = _validateForm[1];
264
267
 
265
- (0, _react.useEffect)(function () {
266
- var validationsForSetFields = Object.entries(validationRulesRef.current).filter(function (_ref3) {
267
- var n = _ref3[0];
268
- return getFieldValue(n, value);
269
- });
268
+ setValidationResults(function (prevValidationResults) {
269
+ // Keep any previous errors and infos for untouched keys,
270
+ // these may have come from a Submit.
271
+ var nextErrors = _extends({}, prevValidationResults.errors, validatedErrors);
272
+
273
+ var nextInfos = _extends({}, prevValidationResults.infos, validatedInfos); // Remove previous errors and infos for keys no longer in the
274
+ // form, these may have been fields removed from a dynamic form.
270
275
 
271
- if (validationsForSetFields.length > 0 && validateOn !== 'submit') {
272
- var _validateForm = validateForm(validationsForSetFields, value, format, messages),
273
- errors = _validateForm[0],
274
- infos = _validateForm[1];
275
276
 
276
- filterRemovedFields(errors);
277
- filterRemovedFields(infos);
277
+ filterRemovedFields(nextErrors);
278
+ filterRemovedFields(nextInfos);
278
279
  var nextValidationResults = {
279
- errors: errors,
280
- infos: infos,
281
- valid: buildValid(errors)
280
+ errors: nextErrors,
281
+ infos: nextInfos
282
282
  };
283
- if (onValidate) onValidate(nextValidationResults);
284
- setValidationResults(nextValidationResults);
285
- } // We only want to run this for the value we have on initial mount.
286
- // We don't want subsequent changes to the value to re-run this.
287
- // eslint-disable-next-line react-hooks/exhaustive-deps
283
+ if (onValidate) onValidate(_extends({}, nextValidationResults, {
284
+ valid: buildValid(nextErrors)
285
+ }));
286
+ validationResultsRef.current = nextValidationResults;
287
+ return nextValidationResults;
288
+ });
289
+ }, [buildValid, format, messages, onValidate, value]); // Validate all fields holding values onMount if set to
290
+ // validate when blur or change.
288
291
 
289
- }, []); // Currently, onBlur validation will trigger after a timeout of 120ms.
292
+ (0, _react.useEffect)(function () {
293
+ var validationRules = Object.entries(validationRulesRef.current); // Use simulated onMount state to account for values provided by
294
+ // controlled inputs.
295
+
296
+ if (mounted !== 'mounted' && ['blur', 'change'].includes(validateOn) && Object.keys(value).length > 0 && Object.keys(touched).length === 0) {
297
+ applyValidationRules(validationRules.filter(function (_ref3) {
298
+ var n = _ref3[0];
299
+ return value[n];
300
+ }) // Exlude empty arrays which may be initial values in
301
+ // an input such as DateInput.
302
+ .filter(function (_ref4) {
303
+ var n = _ref4[0];
304
+ return !(Array.isArray(value[n]) && value[n].length === 0);
305
+ }));
306
+ }
307
+ }, [applyValidationRules, mounted, touched, validateOn, value]); // Run validation against fields with pendingValidations from onBlur
308
+ // and/or onChange.
290
309
 
291
310
  (0, _react.useEffect)(function () {
311
+ var validationRules = Object.entries(validationRulesRef.current);
292
312
  var timer = setTimeout(function () {
293
- if (pendingValidation) {
294
- // run validations on the pending one and any other touched fields
295
- var _validateForm2 = validateForm(Object.entries(validationRulesRef.current).filter(function (_ref4) {
296
- var n = _ref4[0];
313
+ if (pendingValidation && ['blur', 'change'].includes(validateOn)) {
314
+ applyValidationRules(validationRules.filter(function (_ref5) {
315
+ var n = _ref5[0];
297
316
  return touched[n] || pendingValidation.includes(n);
298
- }), value, format, messages),
299
- validatedErrors = _validateForm2[0],
300
- validatedInfos = _validateForm2[1];
301
-
317
+ }));
302
318
  setPendingValidation(undefined);
303
- setValidationResults(function (prevValidationResults) {
304
- // keep any previous errors and infos for untouched keys,
305
- // these may have come from a submit
306
- var nextErrors = _extends({}, prevValidationResults.errors, validatedErrors);
307
-
308
- var nextInfos = _extends({}, prevValidationResults.infos, validatedInfos);
309
-
310
- filterRemovedFields(nextErrors);
311
- filterRemovedFields(nextInfos);
312
- var nextValidationResults = {
313
- errors: nextErrors,
314
- infos: nextInfos,
315
- valid: buildValid(nextErrors)
316
- };
317
- if (onValidate) onValidate(nextValidationResults);
318
- return nextValidationResults;
319
- });
320
- } // a timeout is needed to ensure that a click event (like one on a reset
321
- // button) completes prior to running the validation. without a timeout,
322
- // the blur will always complete and trigger a validation prematurely
323
- // The following values have been empirically tested, but 120 was
324
- // selected because it is the largest value
319
+ } // Complete any potential click events before running onBlur validation.
320
+ // Otherwise, click events like reset, etc. may not be registered. For a
321
+ // detailed scenario/discussion, see: https://github.com/grommet/grommet/issues/4863
322
+ // Values empirically tested; 120 was selected because it is the largest
325
323
  // Chrome: 100, Safari: 120, Firefox: 80
326
324
 
327
325
  }, 120);
328
326
  return function () {
329
327
  return clearTimeout(timer);
330
328
  };
331
- }, [buildValid, format, messages, pendingValidation, onValidate, touched, value, requiredFields]); // clear any errors when value changes
329
+ }, [applyValidationRules, pendingValidation, touched, validateOn]); // Re-run validation rules for all fields with prior errors.
330
+ // if validate=blur this helps re-validate if there are errors
331
+ // as the user fixes them (basically act like validate=change for that)
332
332
 
333
333
  (0, _react.useEffect)(function () {
334
- if (validateOn !== 'change') setPendingValidation(undefined);
335
- setValidationResults(function (prevValidationResults) {
336
- var _validateForm3 = validateForm(Object.entries(validationRulesRef.current).filter(function (_ref5) {
337
- var n = _ref5[0];
338
- return prevValidationResults.errors[n] || prevValidationResults.infos[n];
339
- }), value, format, messages),
340
- nextErrors = _validateForm3[0],
341
- nextInfos = _validateForm3[1];
334
+ var _validationResultsRef;
342
335
 
343
- return {
344
- errors: _extends({}, prevValidationResults.errors, nextErrors),
345
- infos: _extends({}, prevValidationResults.infos, nextInfos)
346
- };
347
- });
348
- }, [format, messages, touched, validateOn, value]); // There are three basic patterns of handling form input value state:
336
+ var validationRules = Object.entries(validationRulesRef.current);
337
+
338
+ if ((_validationResultsRef = validationResultsRef.current) != null && _validationResultsRef.errors && Object.keys(validationResultsRef.current.errors).length > 0) {
339
+ applyValidationRules(validationRules.filter(function (_ref6) {
340
+ var n = _ref6[0];
341
+ return touched[n] && validationResultsRef.current.errors[n];
342
+ }));
343
+ }
344
+ }, [applyValidationRules, touched]); // There are three basic patterns of handling form input value state:
349
345
  //
350
346
  // 1 - form controlled
351
347
  //
@@ -379,15 +375,15 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
379
375
  //
380
376
 
381
377
  var formContextValue = (0, _react.useMemo)(function () {
382
- var useFormInput = function useFormInput(_ref6) {
383
- var name = _ref6.name,
384
- componentValue = _ref6.value,
385
- initialValue = _ref6.initialValue,
386
- validateArg = _ref6.validate;
378
+ var useFormInput = function useFormInput(_ref7) {
379
+ var name = _ref7.name,
380
+ componentValue = _ref7.value,
381
+ initialValue = _ref7.initialValue,
382
+ validateArg = _ref7.validate;
387
383
 
388
- var _useState5 = (0, _react.useState)(initialValue),
389
- inputValue = _useState5[0],
390
- setInputValue = _useState5[1];
384
+ var _useState6 = (0, _react.useState)(initialValue),
385
+ inputValue = _useState6[0],
386
+ setInputValue = _useState6[1];
391
387
 
392
388
  var formValue = name ? getFieldValue(name, value) : undefined; // for dynamic forms, we need to track when an input has been added to
393
389
  // the form value. if the input is unmounted, we will delete its
@@ -430,7 +426,8 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
430
426
  };
431
427
  }, // eslint-disable-next-line react-hooks/exhaustive-deps
432
428
  [] // only run onmount and unmount
433
- );
429
+ ); // Create validation rules for fields
430
+
434
431
  (0, _react.useEffect)(function () {
435
432
  if (validateArg) {
436
433
  if (!validationRulesRef.current[name]) {
@@ -478,15 +475,16 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
478
475
  }];
479
476
  };
480
477
 
481
- var useFormField = function useFormField(_ref7) {
482
- var errorArg = _ref7.error,
483
- infoArg = _ref7.info,
484
- name = _ref7.name,
485
- required = _ref7.required,
486
- disabled = _ref7.disabled,
487
- validateArg = _ref7.validate;
478
+ var useFormField = function useFormField(_ref8) {
479
+ var errorArg = _ref8.error,
480
+ infoArg = _ref8.info,
481
+ name = _ref8.name,
482
+ required = _ref8.required,
483
+ disabled = _ref8.disabled,
484
+ validateArg = _ref8.validate;
488
485
  var error = disabled ? undefined : errorArg || validationResults.errors[name];
489
- var info = infoArg || validationResults.infos[name];
486
+ var info = infoArg || validationResults.infos[name]; // Create validation rules for field
487
+
490
488
  (0, _react.useEffect)(function () {
491
489
  var index = requiredFields.current.indexOf(name);
492
490
 
@@ -557,9 +555,9 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
557
555
  event.preventDefault();
558
556
  setPendingValidation(undefined);
559
557
 
560
- var _validateForm4 = validateForm(Object.entries(validationRulesRef.current), value, format, messages, true),
561
- nextErrors = _validateForm4[0],
562
- nextInfos = _validateForm4[1];
558
+ var _validateForm2 = validateForm(Object.entries(validationRulesRef.current), value, format, messages, true),
559
+ nextErrors = _validateForm2[0],
560
+ nextInfos = _validateForm2[1];
563
561
 
564
562
  setValidationResults(function () {
565
563
  var nextValidationResults = {
@@ -569,6 +567,7 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
569
567
  valid: buildValid(nextErrors)
570
568
  };
571
569
  if (onValidate) onValidate(nextValidationResults);
570
+ validationResultsRef.current = nextValidationResults;
572
571
  return nextValidationResults;
573
572
  });
574
573
 
@@ -147,6 +147,7 @@ var FieldBorderPosition = function FieldBorderPosition() {
147
147
  gap: "medium"
148
148
  }, borderPositions && borderPositions.map(function (example, index) {
149
149
  return /*#__PURE__*/_react["default"].createElement(FormExample, {
150
+ key: example.name,
150
151
  borderPosition: example.name,
151
152
  theme: example.theme,
152
153
  index: index
@@ -270,6 +270,10 @@ var FormField = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
270
270
  if (child && child.type && 'FileInput'.indexOf(child.type.displayName) !== -1) isFileInputComponent = true;
271
271
  })) ;
272
272
 
273
+ if (component && component.displayName === 'FileInput' && !isFileInputComponent) {
274
+ isFileInputComponent = true;
275
+ }
276
+
273
277
  if (!themeBorder) {
274
278
  contents = /*#__PURE__*/_react["default"].createElement(_Box.Box, _extends({}, themeContentProps, contentProps), contents);
275
279
  }
@@ -378,7 +382,7 @@ var FormField = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
378
382
  }, outerProps, {
379
383
  style: outerStyle,
380
384
  onFocus: function onFocus(event) {
381
- setFocus((0, _DOM.shouldKeepFocus)());
385
+ setFocus((0, _DOM.containsFocus)(formFieldRef.current) && (0, _DOM.shouldKeepFocus)());
382
386
  if (_onFocus) _onFocus(event);
383
387
  },
384
388
  onBlur: function onBlur(event) {
@@ -326,7 +326,7 @@ var TextInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
326
326
  ref: itemRef
327
327
  }, /*#__PURE__*/_react["default"].createElement(_Button.Button, {
328
328
  active: activeSuggestionIndex === index,
329
- fill: true,
329
+ fill: "horizontal",
330
330
  plain: !child ? undefined : true,
331
331
  align: "start",
332
332
  kind: !child ? 'option' : undefined,
@@ -52,7 +52,7 @@ var padStyle = function padStyle(_ref) {
52
52
  };
53
53
 
54
54
  var basicStyle = function basicStyle(props) {
55
- return css(["border:none;", ";", " ", " ", ""], radiusStyle(props), padStyle(props), fontStyle(props), props.icon && "\n > svg {\n display: flex;\n align-self: center;\n }\n ");
55
+ return css(["border:none;", ";", " ", " ", ""], radiusStyle(props), padStyle(props), fontStyle(props), props.icon && "\n > svg {\n display: flex;\n align-self: center;\n vertical-align: middle;\n }\n ");
56
56
  };
57
57
 
58
58
  var getPath = function getPath(theme, path) {
@@ -168,7 +168,10 @@ var fillStyle = function fillStyle(fillContainer) {
168
168
  return undefined;
169
169
  };
170
170
 
171
- var plainStyle = css(["outline:none;border:none;padding:0;text-align:inherit;color:inherit;"]);
171
+ var plainStyle = function plainStyle(props) {
172
+ return css(["outline:none;border:none;padding:0;text-align:inherit;color:inherit;", ""], props.icon && "\n > svg {\n display: flex;\n align-self: center;\n vertical-align: middle;\n }\n ");
173
+ };
174
+
172
175
  var StyledButtonKind = styled.button.withConfig({
173
176
  // don't let kind attribute leak to DOM
174
177
  // https://styled-components.com/docs/api#shouldforwardprop
@@ -179,7 +182,7 @@ var StyledButtonKind = styled.button.withConfig({
179
182
  displayName: "StyledButtonKind",
180
183
  componentId: "sc-1vhfpnt-0"
181
184
  })(["display:inline-block;box-sizing:border-box;cursor:pointer;font:inherit;text-decoration:none;margin:0;background:transparent;overflow:visible;text-transform:none;", " ", " ", " ", " ", " ", " ", " ", " &:focus{", "}&:focus:not(:focus-visible){", "}", " ", " ", ""], genericStyles, function (props) {
182
- return props.plain && plainStyle;
185
+ return props.plain && plainStyle(props);
183
186
  }, function (props) {
184
187
  return !props.disabled && props.active && activeStyle;
185
188
  }, function (props) {
@@ -130,7 +130,7 @@ export var normalizeForTimezone = function normalizeForTimezone(value, timestamp
130
130
 
131
131
  if (timestamp && typeof timestamp === 'string') {
132
132
  hourDelta = parseInt(timestamp == null ? void 0 : timestamp.split(':')[0], 10);
133
- valueOffset = hourDelta * 60 * 1000; // ms
133
+ valueOffset = hourDelta * 60 * 60 * 1000; // ms
134
134
  }
135
135
 
136
136
  var localOffset = new Date().getTimezoneOffset() * 60 * 1000;
@@ -163,8 +163,15 @@ export var textToValue = function textToValue(text, schema, range, timestamp) {
163
163
  parts.m = pullDigits(text, index);
164
164
  index += parts.m.length;
165
165
  } else if (_char3 === 'd') {
166
- parts.d = pullDigits(text, index);
167
- index += parts.d.length;
166
+ var _parts, _parts$d;
167
+
168
+ parts.d = pullDigits(text, index); // when format is something like yyyy/mm/dd,
169
+ // '0' as incomplete day can cause date to be
170
+ // prematurely calculated.
171
+ // ex: 2022/01/0 would reutrn 2021/12/31 in addDate()
172
+
173
+ if (parts.d === '0') delete parts.d;
174
+ index += ((_parts = parts) == null ? void 0 : (_parts$d = _parts.d) == null ? void 0 : _parts$d.length) || 0;
168
175
  } else if (_char3 === 'y') {
169
176
  parts.y = pullDigits(text, index);
170
177
  index += parts.y.length;