react-stately 3.47.0 → 3.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/dist/exports/index.cjs +6 -0
  2. package/dist/exports/index.cjs.map +1 -1
  3. package/dist/exports/index.js +5 -1
  4. package/dist/exports/index.js.map +1 -1
  5. package/dist/exports/index.mjs +5 -1
  6. package/dist/exports/index.mjs.map +1 -1
  7. package/dist/exports/useTokenFieldState.cjs +25 -0
  8. package/dist/exports/useTokenFieldState.cjs.map +1 -0
  9. package/dist/exports/useTokenFieldState.js +19 -0
  10. package/dist/exports/useTokenFieldState.js.map +1 -0
  11. package/dist/exports/useTokenFieldState.mjs +19 -0
  12. package/dist/exports/useTokenFieldState.mjs.map +1 -0
  13. package/dist/private/color/Color.cjs.map +1 -1
  14. package/dist/private/color/Color.js.map +1 -1
  15. package/dist/private/color/Color.mjs.map +1 -1
  16. package/dist/private/combobox/useComboBoxState.cjs +2 -1
  17. package/dist/private/combobox/useComboBoxState.cjs.map +1 -1
  18. package/dist/private/combobox/useComboBoxState.js +2 -1
  19. package/dist/private/combobox/useComboBoxState.js.map +1 -1
  20. package/dist/private/combobox/useComboBoxState.mjs +2 -1
  21. package/dist/private/combobox/useComboBoxState.mjs.map +1 -1
  22. package/dist/private/data/useTreeData.cjs +1 -0
  23. package/dist/private/data/useTreeData.cjs.map +1 -1
  24. package/dist/private/data/useTreeData.js +1 -0
  25. package/dist/private/data/useTreeData.js.map +1 -1
  26. package/dist/private/data/useTreeData.mjs +1 -0
  27. package/dist/private/data/useTreeData.mjs.map +1 -1
  28. package/dist/private/datepicker/useDateRangePickerState.cjs +1 -0
  29. package/dist/private/datepicker/useDateRangePickerState.cjs.map +1 -1
  30. package/dist/private/datepicker/useDateRangePickerState.js +1 -0
  31. package/dist/private/datepicker/useDateRangePickerState.js.map +1 -1
  32. package/dist/private/datepicker/useDateRangePickerState.mjs +1 -0
  33. package/dist/private/datepicker/useDateRangePickerState.mjs.map +1 -1
  34. package/dist/private/datepicker/utils.cjs.map +1 -1
  35. package/dist/private/datepicker/utils.js.map +1 -1
  36. package/dist/private/datepicker/utils.mjs.map +1 -1
  37. package/dist/private/form/useFormValidationState.cjs +1 -1
  38. package/dist/private/form/useFormValidationState.cjs.map +1 -1
  39. package/dist/private/form/useFormValidationState.js +1 -1
  40. package/dist/private/form/useFormValidationState.js.map +1 -1
  41. package/dist/private/form/useFormValidationState.mjs +1 -1
  42. package/dist/private/form/useFormValidationState.mjs.map +1 -1
  43. package/dist/private/grid/useGridState.cjs +12 -10
  44. package/dist/private/grid/useGridState.cjs.map +1 -1
  45. package/dist/private/grid/useGridState.js +12 -10
  46. package/dist/private/grid/useGridState.js.map +1 -1
  47. package/dist/private/grid/useGridState.mjs +12 -10
  48. package/dist/private/grid/useGridState.mjs.map +1 -1
  49. package/dist/private/layout/ListLayout.cjs +0 -3
  50. package/dist/private/layout/ListLayout.cjs.map +1 -1
  51. package/dist/private/layout/ListLayout.js +0 -3
  52. package/dist/private/layout/ListLayout.js.map +1 -1
  53. package/dist/private/layout/ListLayout.mjs +0 -3
  54. package/dist/private/layout/ListLayout.mjs.map +1 -1
  55. package/dist/private/menu/useMenuTriggerState.cjs.map +1 -1
  56. package/dist/private/menu/useMenuTriggerState.js.map +1 -1
  57. package/dist/private/menu/useMenuTriggerState.mjs.map +1 -1
  58. package/dist/private/menu/useSubmenuTriggerState.cjs +3 -1
  59. package/dist/private/menu/useSubmenuTriggerState.cjs.map +1 -1
  60. package/dist/private/menu/useSubmenuTriggerState.js +3 -1
  61. package/dist/private/menu/useSubmenuTriggerState.js.map +1 -1
  62. package/dist/private/menu/useSubmenuTriggerState.mjs +3 -1
  63. package/dist/private/menu/useSubmenuTriggerState.mjs.map +1 -1
  64. package/dist/private/overlays/useOverlayTriggerState.cjs +4 -1
  65. package/dist/private/overlays/useOverlayTriggerState.cjs.map +1 -1
  66. package/dist/private/overlays/useOverlayTriggerState.js +5 -2
  67. package/dist/private/overlays/useOverlayTriggerState.js.map +1 -1
  68. package/dist/private/overlays/useOverlayTriggerState.mjs +5 -2
  69. package/dist/private/overlays/useOverlayTriggerState.mjs.map +1 -1
  70. package/dist/private/select/useSelectState.cjs +1 -0
  71. package/dist/private/select/useSelectState.cjs.map +1 -1
  72. package/dist/private/select/useSelectState.js +1 -0
  73. package/dist/private/select/useSelectState.js.map +1 -1
  74. package/dist/private/select/useSelectState.mjs +1 -0
  75. package/dist/private/select/useSelectState.mjs.map +1 -1
  76. package/dist/private/slider/useSliderState.cjs.map +1 -1
  77. package/dist/private/slider/useSliderState.js.map +1 -1
  78. package/dist/private/slider/useSliderState.mjs.map +1 -1
  79. package/dist/private/table/TableUtils.cjs +13 -1
  80. package/dist/private/table/TableUtils.cjs.map +1 -1
  81. package/dist/private/table/TableUtils.js +13 -1
  82. package/dist/private/table/TableUtils.js.map +1 -1
  83. package/dist/private/table/TableUtils.mjs +13 -1
  84. package/dist/private/table/TableUtils.mjs.map +1 -1
  85. package/dist/private/table/useTableState.cjs +1 -0
  86. package/dist/private/table/useTableState.cjs.map +1 -1
  87. package/dist/private/table/useTableState.js +1 -0
  88. package/dist/private/table/useTableState.js.map +1 -1
  89. package/dist/private/table/useTableState.mjs +1 -0
  90. package/dist/private/table/useTableState.mjs.map +1 -1
  91. package/dist/private/tokenfield/TokenFieldValue.cjs +287 -0
  92. package/dist/private/tokenfield/TokenFieldValue.cjs.map +1 -0
  93. package/dist/private/tokenfield/TokenFieldValue.js +285 -0
  94. package/dist/private/tokenfield/TokenFieldValue.js.map +1 -0
  95. package/dist/private/tokenfield/TokenFieldValue.mjs +282 -0
  96. package/dist/private/tokenfield/TokenFieldValue.mjs.map +1 -0
  97. package/dist/private/tokenfield/useTokenFieldState.cjs +37 -0
  98. package/dist/private/tokenfield/useTokenFieldState.cjs.map +1 -0
  99. package/dist/private/tokenfield/useTokenFieldState.js +32 -0
  100. package/dist/private/tokenfield/useTokenFieldState.js.map +1 -0
  101. package/dist/private/tokenfield/useTokenFieldState.mjs +32 -0
  102. package/dist/private/tokenfield/useTokenFieldState.mjs.map +1 -0
  103. package/dist/private/tooltip/useTooltipTriggerState.cjs +18 -6
  104. package/dist/private/tooltip/useTooltipTriggerState.cjs.map +1 -1
  105. package/dist/private/tooltip/useTooltipTriggerState.js +19 -7
  106. package/dist/private/tooltip/useTooltipTriggerState.js.map +1 -1
  107. package/dist/private/tooltip/useTooltipTriggerState.mjs +19 -7
  108. package/dist/private/tooltip/useTooltipTriggerState.mjs.map +1 -1
  109. package/dist/private/virtualizer/ScrollAnchor.cjs +136 -0
  110. package/dist/private/virtualizer/ScrollAnchor.cjs.map +1 -0
  111. package/dist/private/virtualizer/ScrollAnchor.js +132 -0
  112. package/dist/private/virtualizer/ScrollAnchor.js.map +1 -0
  113. package/dist/private/virtualizer/ScrollAnchor.mjs +131 -0
  114. package/dist/private/virtualizer/ScrollAnchor.mjs.map +1 -0
  115. package/dist/private/virtualizer/Virtualizer.cjs +50 -1
  116. package/dist/private/virtualizer/Virtualizer.cjs.map +1 -1
  117. package/dist/private/virtualizer/Virtualizer.js +54 -1
  118. package/dist/private/virtualizer/Virtualizer.js.map +1 -1
  119. package/dist/private/virtualizer/Virtualizer.mjs +50 -1
  120. package/dist/private/virtualizer/Virtualizer.mjs.map +1 -1
  121. package/dist/private/virtualizer/useVirtualizerState.cjs +2 -1
  122. package/dist/private/virtualizer/useVirtualizerState.cjs.map +1 -1
  123. package/dist/private/virtualizer/useVirtualizerState.js +2 -1
  124. package/dist/private/virtualizer/useVirtualizerState.js.map +1 -1
  125. package/dist/private/virtualizer/useVirtualizerState.mjs +2 -1
  126. package/dist/private/virtualizer/useVirtualizerState.mjs.map +1 -1
  127. package/dist/types/exports/index.d.ts +4 -0
  128. package/dist/types/exports/useTokenFieldState.d.ts +4 -0
  129. package/dist/types/src/combobox/useComboBoxState.d.ts +1 -1
  130. package/dist/types/src/menu/useMenuTriggerState.d.ts +1 -1
  131. package/dist/types/src/overlays/useOverlayTriggerState.d.ts +9 -0
  132. package/dist/types/src/table/useTableState.d.ts +7 -0
  133. package/dist/types/src/tokenfield/TokenFieldValue.d.ts +71 -0
  134. package/dist/types/src/tokenfield/useTokenFieldState.d.ts +19 -0
  135. package/dist/types/src/tooltip/useTooltipTriggerState.d.ts +5 -0
  136. package/dist/types/src/virtualizer/ScrollAnchor.d.ts +81 -0
  137. package/dist/types/src/virtualizer/Virtualizer.d.ts +1 -0
  138. package/dist/types/src/virtualizer/types.d.ts +2 -0
  139. package/package.json +5 -5
  140. package/useTokenFieldState/package.json +5 -0
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;AAUM,MAAM,4CAAsC;IACjD,UAAU;IACV,aAAa;IACb,iBAAiB;IACjB,eAAe;IACf,gBAAgB;IAChB,cAAc;IACd,SAAS;IACT,UAAU;IACV,cAAc;IACd,cAAc;IACd,OAAO;AACT;AAEA,MAAM,8CAAuC;IAC3C,GAAG,yCAAoB;IACvB,aAAa;IACb,OAAO;AACT;AAEO,MAAM,4CAA8C;IACzD,WAAW;IACX,mBAAmB;IACnB,kBAAkB,EAAE;AACtB;AAEO,MAAM,4CAAmD,CAAA,GAAA,0BAAY,EAAoB,CAAC;AAK1F,MAAM,2CAAqC;AAwB3C,SAAS,0CAA0B,KAA6B;IACrE,gEAAgE;IAChE,IAAI,KAAK,CAAC,yCAA2B,EAAE;QACrC,IAAI,sBACF,kBAAkB,qBAClB,iBAAiB,oBACjB,gBAAgB,mBAChB,eAAe,oBACf,gBAAgB,EACjB,GAAG,KAAK,CAAC,yCAA2B;QACrC,OAAO;gCACL;+BACA;8BACA;6BACA;8BACA;QACF;IACF;IAEA,sDAAsD;IACtD,OAAO,iDAA2B;AACpC;AAEA,SAAS,iDAA8B,KAA6B;IAClE,IAAI,aACF,SAAS,mBACT,eAAe,QACf,IAAI,SACJ,KAAK,qBACL,iBAAiB,YACjB,QAAQ,sBACR,qBAAqB,QACtB,GAAG;IAE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AAO,OAAO,MAAM,GAChB;QACE,WAAW;QACX,kBAAkB;QAClB,mBAAmB;IACrB,IACA;AACN;AAEA,SAAS,wCAAkB,CAA0B,EAAE,CAA0B;IAC/E,IAAI,MAAM,GACR,OAAO;IAGT,OACE,CAAC,CAAC,KACF,CAAC,CAAC,KACF,EAAE,SAAS,KAAK,EAAE,SAAS,IAC3B,EAAE,gBAAgB,CAAC,MAAM,KAAK,EAAE,gBAAgB,CAAC,MAAM,IACvD,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC,GAAG,IAAM,MAAM,EAAE,gBAAgB,CAAC,EAAE,KAC9D,OAAO,OAAO,CAAC,EAAE,iBAAiB,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,GAAK,EAAE,iBAAiB,CAAC,EAAE,KAAK;AAErF;AAEO,SAAS,0CAAgB,GAAG,OAA2B;IAC5D,IAAI,SAAS,IAAI;IACjB,IAAI,YAAY;IAChB,IAAI,oBAAoB;QACtB,GAAG,yCAAoB;IACzB;IAEA,KAAK,IAAI,KAAK,QAAS;QACrB,KAAK,IAAI,KAAK,EAAE,gBAAgB,CAC9B,OAAO,GAAG,CAAC;QAGb,8CAA8C;QAC9C,cAAc,EAAE,SAAS;QACzB,IAAK,IAAI,OAAO,kBACd,iBAAiB,CAAC,IAAI,KAAK,EAAE,iBAAiB,CAAC,IAAI;IAEvD;IAEA,kBAAkB,KAAK,GAAG,CAAC;IAC3B,OAAO;mBACL;QACA,kBAAkB;eAAI;SAAO;2BAC7B;IACF;AACF","sources":["packages/react-stately/src/form/useFormValidationState.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Context, createContext, useContext, useEffect, useMemo, useRef, useState} from 'react';\nimport {\n Validation,\n ValidationErrors,\n ValidationFunction,\n ValidationResult\n} from '@react-types/shared';\n\nexport const VALID_VALIDITY_STATE: ValidityState = {\n badInput: false,\n customError: false,\n patternMismatch: false,\n rangeOverflow: false,\n rangeUnderflow: false,\n stepMismatch: false,\n tooLong: false,\n tooShort: false,\n typeMismatch: false,\n valueMissing: false,\n valid: true\n};\n\nconst CUSTOM_VALIDITY_STATE: ValidityState = {\n ...VALID_VALIDITY_STATE,\n customError: true,\n valid: false\n};\n\nexport const DEFAULT_VALIDATION_RESULT: ValidationResult = {\n isInvalid: false,\n validationDetails: VALID_VALIDITY_STATE,\n validationErrors: []\n};\n\nexport const FormValidationContext: Context<ValidationErrors> = createContext<ValidationErrors>({});\n\n// Private props that we pass from useFormValidationState to children.\n// Ideally we'd use a Symbol for this, but React doesn't support them: https://github.com/facebook/react/issues/7552\n// This needs to be stable across server and client module evaluation for SSR hydration.\nexport const privateValidationStateProp: string = '__reactAriaFormValidationState';\n\ninterface FormValidationProps<T> extends Validation<T> {\n builtinValidation?: ValidationResult;\n name?: string | string[];\n value: T | null;\n}\n\nexport interface FormValidationState {\n /** Realtime validation results, updated as the user edits the value. */\n realtimeValidation: ValidationResult;\n /** Currently displayed validation results, updated when the user commits their changes. */\n displayValidation: ValidationResult;\n /**\n * Updates the current validation result. Not displayed to the user until `commitValidation` is\n * called.\n */\n updateValidation(result: ValidationResult): void;\n /** Resets the displayed validation state to valid when the user resets the form. */\n resetValidation(): void;\n /** Commits the realtime validation so it is displayed to the user. */\n commitValidation(): void;\n}\n\nexport function useFormValidationState<T>(props: FormValidationProps<T>): FormValidationState {\n // Private prop for parent components to pass state to children.\n if (props[privateValidationStateProp]) {\n let {\n realtimeValidation,\n displayValidation,\n updateValidation,\n resetValidation,\n commitValidation\n } = props[privateValidationStateProp] as FormValidationState;\n return {\n realtimeValidation,\n displayValidation,\n updateValidation,\n resetValidation,\n commitValidation\n };\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useFormValidationStateImpl(props);\n}\n\nfunction useFormValidationStateImpl<T>(props: FormValidationProps<T>): FormValidationState {\n let {\n isInvalid,\n validationState,\n name,\n value,\n builtinValidation,\n validate,\n validationBehavior = 'aria'\n } = props;\n\n // backward compatibility.\n if (validationState) {\n isInvalid ||= validationState === 'invalid';\n }\n\n // If the isInvalid prop is controlled, update validation result in realtime.\n let controlledError: ValidationResult | null =\n isInvalid !== undefined\n ? {\n isInvalid,\n validationErrors: [],\n validationDetails: CUSTOM_VALIDITY_STATE\n }\n : null;\n\n // Perform custom client side validation.\n let clientError: ValidationResult | null = useMemo(() => {\n if (!validate || value == null) {\n return null;\n }\n let validateErrors = runValidate(validate, value);\n return getValidationResult(validateErrors);\n }, [validate, value]);\n\n if (builtinValidation?.validationDetails.valid) {\n builtinValidation = undefined;\n }\n\n // Get relevant server errors from the form.\n let serverErrors = useContext(FormValidationContext);\n let serverErrorMessages = useMemo(() => {\n if (name) {\n return Array.isArray(name)\n ? name.flatMap(name => asArray(serverErrors[name]))\n : asArray(serverErrors[name]);\n }\n return [];\n }, [serverErrors, name]);\n\n // Show server errors when the form gets a new value, and clear when the user changes the value.\n let [lastServerErrors, setLastServerErrors] = useState(serverErrors);\n let [isServerErrorCleared, setServerErrorCleared] = useState(false);\n if (serverErrors !== lastServerErrors) {\n setLastServerErrors(serverErrors);\n setServerErrorCleared(false);\n }\n\n let serverError: ValidationResult | null = useMemo(\n () => getValidationResult(isServerErrorCleared ? [] : serverErrorMessages),\n [isServerErrorCleared, serverErrorMessages]\n );\n\n // Track the next validation state in a ref until commitValidation is called.\n let nextValidation = useRef(DEFAULT_VALIDATION_RESULT);\n let [currentValidity, setCurrentValidity] = useState(DEFAULT_VALIDATION_RESULT);\n\n let lastError = useRef(DEFAULT_VALIDATION_RESULT);\n let commitValidation = () => {\n if (!commitQueued) {\n return;\n }\n\n setCommitQueued(false);\n let error = clientError || builtinValidation || nextValidation.current;\n if (!isEqualValidation(error, lastError.current)) {\n lastError.current = error;\n setCurrentValidity(error);\n }\n };\n\n let [commitQueued, setCommitQueued] = useState(false);\n useEffect(commitValidation);\n\n // realtimeValidation is used to update the native input element's state based on custom validation logic.\n // displayValidation is the currently displayed validation state that the user sees (e.g. on input change/form submit).\n // With validationBehavior=\"aria\", all errors are displayed in realtime rather than on submit.\n let realtimeValidation =\n controlledError || serverError || clientError || builtinValidation || DEFAULT_VALIDATION_RESULT;\n let displayValidation =\n validationBehavior === 'native'\n ? controlledError || serverError || currentValidity\n : controlledError || serverError || clientError || builtinValidation || currentValidity;\n\n return {\n realtimeValidation,\n displayValidation,\n updateValidation(value) {\n // If validationBehavior is 'aria', update in realtime. Otherwise, store in a ref until commit.\n if (validationBehavior === 'aria' && !isEqualValidation(currentValidity, value)) {\n setCurrentValidity(value);\n } else {\n nextValidation.current = value;\n }\n },\n resetValidation() {\n // Update the currently displayed validation state to valid on form reset,\n // even if the native validity says it isn't. It'll show again on the next form submit.\n let error = DEFAULT_VALIDATION_RESULT;\n if (!isEqualValidation(error, lastError.current)) {\n lastError.current = error;\n setCurrentValidity(error);\n }\n\n // Do not commit validation after the next render. This avoids a condition where\n // useSelect calls commitValidation inside an onReset handler.\n if (validationBehavior === 'native') {\n setCommitQueued(false);\n }\n\n setServerErrorCleared(true);\n },\n commitValidation() {\n // Commit validation state so the user sees it on blur/change/submit. Also clear any server errors.\n // Wait until after the next render to commit so that the latest value has been validated.\n if (validationBehavior === 'native') {\n setCommitQueued(true);\n }\n setServerErrorCleared(true);\n }\n };\n}\n\nfunction asArray<T>(v: T | T[]): T[] {\n if (!v) {\n return [];\n }\n\n return Array.isArray(v) ? v : [v];\n}\n\nfunction runValidate<T>(validate: ValidationFunction<T>, value: T): string[] {\n if (typeof validate === 'function') {\n let e = validate(value);\n if (e && typeof e !== 'boolean') {\n return asArray(e);\n }\n }\n\n return [];\n}\n\nfunction getValidationResult(errors: string[]): ValidationResult | null {\n return errors.length\n ? {\n isInvalid: true,\n validationErrors: errors,\n validationDetails: CUSTOM_VALIDITY_STATE\n }\n : null;\n}\n\nfunction isEqualValidation(a: ValidationResult | null, b: ValidationResult | null): boolean {\n if (a === b) {\n return true;\n }\n\n return (\n !!a &&\n !!b &&\n a.isInvalid === b.isInvalid &&\n a.validationErrors.length === b.validationErrors.length &&\n a.validationErrors.every((a, i) => a === b.validationErrors[i]) &&\n Object.entries(a.validationDetails).every(([k, v]) => b.validationDetails[k] === v)\n );\n}\n\nexport function mergeValidation(...results: ValidationResult[]): ValidationResult {\n let errors = new Set<string>();\n let isInvalid = false;\n let validationDetails = {\n ...VALID_VALIDITY_STATE\n };\n\n for (let v of results) {\n for (let e of v.validationErrors) {\n errors.add(e);\n }\n\n // Only these properties apply for checkboxes.\n isInvalid ||= v.isInvalid;\n for (let key in validationDetails) {\n validationDetails[key] ||= v.validationDetails[key];\n }\n }\n\n validationDetails.valid = !isInvalid;\n return {\n isInvalid,\n validationErrors: [...errors],\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useFormValidationState.cjs.map"}
1
+ {"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;AAUM,MAAM,4CAAsC;IACjD,UAAU;IACV,aAAa;IACb,iBAAiB;IACjB,eAAe;IACf,gBAAgB;IAChB,cAAc;IACd,SAAS;IACT,UAAU;IACV,cAAc;IACd,cAAc;IACd,OAAO;AACT;AAEA,MAAM,8CAAuC;IAC3C,GAAG,yCAAoB;IACvB,aAAa;IACb,OAAO;AACT;AAEO,MAAM,4CAA8C;IACzD,WAAW;IACX,mBAAmB;IACnB,kBAAkB,EAAE;AACtB;AAEO,MAAM,4CAAmD,CAAA,GAAA,0BAAY,EAAoB,CAAC;AAK1F,MAAM,2CAAqC;AAwB3C,SAAS,0CAA0B,KAA6B;IACrE,gEAAgE;IAChE,IAAI,KAAK,CAAC,yCAA2B,EAAE;QACrC,IAAI,sBACF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AO;mBACL;QACA,kBAAkB;eAAI;SAAO;2BAC7B;IACF;AACF","sources":["packages/react-stately/src/form/useFormValidationState.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Context, createContext, useContext, useEffect, useMemo, useRef, useState} from 'react';\nimport {\n Validation,\n ValidationErrors,\n ValidationFunction,\n ValidationResult\n} from '@react-types/shared';\n\nexport const VALID_VALIDITY_STATE: ValidityState = {\n badInput: false,\n customError: false,\n patternMismatch: false,\n rangeOverflow: false,\n rangeUnderflow: false,\n stepMismatch: false,\n tooLong: false,\n tooShort: false,\n typeMismatch: false,\n valueMissing: false,\n valid: true\n};\n\nconst CUSTOM_VALIDITY_STATE: ValidityState = {\n ...VALID_VALIDITY_STATE,\n customError: true,\n valid: false\n};\n\nexport const DEFAULT_VALIDATION_RESULT: ValidationResult = {\n isInvalid: false,\n validationDetails: VALID_VALIDITY_STATE,\n validationErrors: []\n};\n\nexport const FormValidationContext: Context<ValidationErrors> = createContext<ValidationErrors>({});\n\n// Private props that we pass from useFormValidationState to children.\n// Ideally we'd use a Symbol for this, but React doesn't support them: https://github.com/facebook/react/issues/7552\n// This needs to be stable across server and client module evaluation for SSR hydration.\nexport const privateValidationStateProp: string = '__reactAriaFormValidationState';\n\ninterface FormValidationProps<T> extends Validation<T> {\n builtinValidation?: ValidationResult;\n name?: string | string[];\n value: T | null;\n}\n\nexport interface FormValidationState {\n /** Realtime validation results, updated as the user edits the value. */\n realtimeValidation: ValidationResult;\n /** Currently displayed validation results, updated when the user commits their changes. */\n displayValidation: ValidationResult;\n /**\n * Updates the current validation result. Not displayed to the user until `commitValidation` is\n * called.\n */\n updateValidation(result: ValidationResult): void;\n /** Resets the displayed validation state to valid when the user resets the form. */\n resetValidation(): void;\n /** Commits the realtime validation so it is displayed to the user. */\n commitValidation(): void;\n}\n\nexport function useFormValidationState<T>(props: FormValidationProps<T>): FormValidationState {\n // Private prop for parent components to pass state to children.\n if (props[privateValidationStateProp]) {\n let {\n realtimeValidation,\n displayValidation,\n updateValidation,\n resetValidation,\n commitValidation\n } = props[privateValidationStateProp] as FormValidationState;\n return {\n realtimeValidation,\n displayValidation,\n updateValidation,\n resetValidation,\n commitValidation\n };\n }\n\n // oxlint-disable-next-line react/react-compiler, react-hooks/rules-of-hooks\n return useFormValidationStateImpl(props);\n}\n\nfunction useFormValidationStateImpl<T>(props: FormValidationProps<T>): FormValidationState {\n let {\n isInvalid,\n validationState,\n name,\n value,\n builtinValidation,\n validate,\n validationBehavior = 'aria'\n } = props;\n\n // backward compatibility.\n if (validationState) {\n isInvalid ||= validationState === 'invalid';\n }\n\n // If the isInvalid prop is controlled, update validation result in realtime.\n let controlledError: ValidationResult | null =\n isInvalid !== undefined\n ? {\n isInvalid,\n validationErrors: [],\n validationDetails: CUSTOM_VALIDITY_STATE\n }\n : null;\n\n // Perform custom client side validation.\n let clientError: ValidationResult | null = useMemo(() => {\n if (!validate || value == null) {\n return null;\n }\n let validateErrors = runValidate(validate, value);\n return getValidationResult(validateErrors);\n }, [validate, value]);\n\n if (builtinValidation?.validationDetails.valid) {\n builtinValidation = undefined;\n }\n\n // Get relevant server errors from the form.\n let serverErrors = useContext(FormValidationContext);\n let serverErrorMessages = useMemo(() => {\n if (name) {\n return Array.isArray(name)\n ? name.flatMap(name => asArray(serverErrors[name]))\n : asArray(serverErrors[name]);\n }\n return [];\n }, [serverErrors, name]);\n\n // Show server errors when the form gets a new value, and clear when the user changes the value.\n let [lastServerErrors, setLastServerErrors] = useState(serverErrors);\n let [isServerErrorCleared, setServerErrorCleared] = useState(false);\n if (serverErrors !== lastServerErrors) {\n setLastServerErrors(serverErrors);\n setServerErrorCleared(false);\n }\n\n let serverError: ValidationResult | null = useMemo(\n () => getValidationResult(isServerErrorCleared ? [] : serverErrorMessages),\n [isServerErrorCleared, serverErrorMessages]\n );\n\n // Track the next validation state in a ref until commitValidation is called.\n let nextValidation = useRef(DEFAULT_VALIDATION_RESULT);\n let [currentValidity, setCurrentValidity] = useState(DEFAULT_VALIDATION_RESULT);\n\n let lastError = useRef(DEFAULT_VALIDATION_RESULT);\n let commitValidation = () => {\n if (!commitQueued) {\n return;\n }\n\n setCommitQueued(false);\n let error = clientError || builtinValidation || nextValidation.current;\n if (!isEqualValidation(error, lastError.current)) {\n lastError.current = error;\n setCurrentValidity(error);\n }\n };\n\n let [commitQueued, setCommitQueued] = useState(false);\n useEffect(commitValidation);\n\n // realtimeValidation is used to update the native input element's state based on custom validation logic.\n // displayValidation is the currently displayed validation state that the user sees (e.g. on input change/form submit).\n // With validationBehavior=\"aria\", all errors are displayed in realtime rather than on submit.\n let realtimeValidation =\n controlledError || serverError || clientError || builtinValidation || DEFAULT_VALIDATION_RESULT;\n let displayValidation =\n validationBehavior === 'native'\n ? controlledError || serverError || currentValidity\n : controlledError || serverError || clientError || builtinValidation || currentValidity;\n\n return {\n realtimeValidation,\n displayValidation,\n updateValidation(value) {\n // If validationBehavior is 'aria', update in realtime. Otherwise, store in a ref until commit.\n if (validationBehavior === 'aria' && !isEqualValidation(currentValidity, value)) {\n setCurrentValidity(value);\n } else {\n nextValidation.current = value;\n }\n },\n resetValidation() {\n // Update the currently displayed validation state to valid on form reset,\n // even if the native validity says it isn't. It'll show again on the next form submit.\n let error = DEFAULT_VALIDATION_RESULT;\n if (!isEqualValidation(error, lastError.current)) {\n lastError.current = error;\n setCurrentValidity(error);\n }\n\n // Do not commit validation after the next render. This avoids a condition where\n // useSelect calls commitValidation inside an onReset handler.\n if (validationBehavior === 'native') {\n setCommitQueued(false);\n }\n\n setServerErrorCleared(true);\n },\n commitValidation() {\n // Commit validation state so the user sees it on blur/change/submit. Also clear any server errors.\n // Wait until after the next render to commit so that the latest value has been validated.\n if (validationBehavior === 'native') {\n setCommitQueued(true);\n }\n setServerErrorCleared(true);\n }\n };\n}\n\nfunction asArray<T>(v: T | T[]): T[] {\n if (!v) {\n return [];\n }\n\n return Array.isArray(v) ? v : [v];\n}\n\nfunction runValidate<T>(validate: ValidationFunction<T>, value: T): string[] {\n if (typeof validate === 'function') {\n let e = validate(value);\n if (e && typeof e !== 'boolean') {\n return asArray(e);\n }\n }\n\n return [];\n}\n\nfunction getValidationResult(errors: string[]): ValidationResult | null {\n return errors.length\n ? {\n isInvalid: true,\n validationErrors: errors,\n validationDetails: CUSTOM_VALIDITY_STATE\n }\n : null;\n}\n\nfunction isEqualValidation(a: ValidationResult | null, b: ValidationResult | null): boolean {\n if (a === b) {\n return true;\n }\n\n return (\n !!a &&\n !!b &&\n a.isInvalid === b.isInvalid &&\n a.validationErrors.length === b.validationErrors.length &&\n a.validationErrors.every((a, i) => a === b.validationErrors[i]) &&\n Object.entries(a.validationDetails).every(([k, v]) => b.validationDetails[k] === v)\n );\n}\n\nexport function mergeValidation(...results: ValidationResult[]): ValidationResult {\n let errors = new Set<string>();\n let isInvalid = false;\n let validationDetails = {\n ...VALID_VALIDITY_STATE\n };\n\n for (let v of results) {\n for (let e of v.validationErrors) {\n errors.add(e);\n }\n\n // Only these properties apply for checkboxes.\n isInvalid ||= v.isInvalid;\n for (let key in validationDetails) {\n validationDetails[key] ||= v.validationDetails[key];\n }\n }\n\n validationDetails.valid = !isInvalid;\n return {\n isInvalid,\n validationErrors: [...errors],\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useFormValidationState.cjs.map"}
@@ -48,7 +48,7 @@ function $d085204f885ad67a$export$fc1a364ae1f3ff10(props) {
48
48
  commitValidation: commitValidation
49
49
  };
50
50
  }
51
- // eslint-disable-next-line react-hooks/rules-of-hooks
51
+ // oxlint-disable-next-line react/react-compiler, react-hooks/rules-of-hooks
52
52
  return $d085204f885ad67a$var$useFormValidationStateImpl(props);
53
53
  }
54
54
  function $d085204f885ad67a$var$useFormValidationStateImpl(props) {
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAUM,MAAM,4CAAsC;IACjD,UAAU;IACV,aAAa;IACb,iBAAiB;IACjB,eAAe;IACf,gBAAgB;IAChB,cAAc;IACd,SAAS;IACT,UAAU;IACV,cAAc;IACd,cAAc;IACd,OAAO;AACT;AAEA,MAAM,8CAAuC;IAC3C,GAAG,yCAAoB;IACvB,aAAa;IACb,OAAO;AACT;AAEO,MAAM,4CAA8C;IACzD,WAAW;IACX,mBAAmB;IACnB,kBAAkB,EAAE;AACtB;AAEO,MAAM,4CAAmD,CAAA,GAAA,oBAAY,EAAoB,CAAC;AAK1F,MAAM,2CAAqC;AAwB3C,SAAS,0CAA0B,KAA6B;IACrE,gEAAgE;IAChE,IAAI,KAAK,CAAC,yCAA2B,EAAE;QACrC,IAAI,sBACF,kBAAkB,qBAClB,iBAAiB,oBACjB,gBAAgB,mBAChB,eAAe,oBACf,gBAAgB,EACjB,GAAG,KAAK,CAAC,yCAA2B;QACrC,OAAO;gCACL;+BACA;8BACA;6BACA;8BACA;QACF;IACF;IAEA,sDAAsD;IACtD,OAAO,iDAA2B;AACpC;AAEA,SAAS,iDAA8B,KAA6B;IAClE,IAAI,aACF,SAAS,mBACT,eAAe,QACf,IAAI,SACJ,KAAK,qBACL,iBAAiB,YACjB,QAAQ,sBACR,qBAAqB,QACtB,GAAG;IAEJ,0BAA0B;IAC1B,IAAI,iBACF,cAAA,YAAc,oBAAoB;IAGpC,6EAA6E;IAC7E,IAAI,kBACF,cAAc,YACV;mBACE;QACA,kBAAkB,EAAE;QACpB,mBAAmB;IACrB,IACA;IAEN,yCAAyC;IACzC,IAAI,cAAuC,CAAA,GAAA,cAAM,EAAE;QACjD,IAAI,CAAC,YAAY,SAAS,MACxB,OAAO;QAET,IAAI,iBAAiB,kCAAY,UAA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,KAAK,EAAE,gBAAgB,CAAC,MAAM,IACvD,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC,GAAG,IAAM,MAAM,EAAE,gBAAgB,CAAC,EAAE,KAC9D,OAAO,OAAO,CAAC,EAAE,iBAAiB,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,GAAK,EAAE,iBAAiB,CAAC,EAAE,KAAK;AAErF;AAEO,SAAS,0CAAgB,GAAG,OAA2B;IAC5D,IAAI,SAAS,IAAI;IACjB,IAAI,YAAY;IAChB,IAAI,oBAAoB;QACtB,GAAG,yCAAoB;IACzB;IAEA,KAAK,IAAI,KAAK,QAAS;YAQnB,oBAAkB;QAPpB,KAAK,IAAI,KAAK,EAAE,gBAAgB,CAC9B,OAAO,GAAG,CAAC;QAGb,8CAA8C;QAC9C,cAAA,YAAc,EAAE,SAAS;QACzB,IAAK,IAAI,OAAO,kBACd,CAAA,qBAAA,kBAAiB,CAAC,OAAA,IAAI,KAAtB,kBAAiB,CAAC,KAAI,GAAK,EAAE,iBAAiB,CAAC,IAAI;IAEvD;IAEA,kBAAkB,KAAK,GAAG,CAAC;IAC3B,OAAO;mBACL;QACA,kBAAkB;eAAI;SAAO;2BAC7B;IACF;AACF","sources":["packages/react-stately/src/form/useFormValidationState.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Context, createContext, useContext, useEffect, useMemo, useRef, useState} from 'react';\nimport {\n Validation,\n ValidationErrors,\n ValidationFunction,\n ValidationResult\n} from '@react-types/shared';\n\nexport const VALID_VALIDITY_STATE: ValidityState = {\n badInput: false,\n customError: false,\n patternMismatch: false,\n rangeOverflow: false,\n rangeUnderflow: false,\n stepMismatch: false,\n tooLong: false,\n tooShort: false,\n typeMismatch: false,\n valueMissing: false,\n valid: true\n};\n\nconst CUSTOM_VALIDITY_STATE: ValidityState = {\n ...VALID_VALIDITY_STATE,\n customError: true,\n valid: false\n};\n\nexport const DEFAULT_VALIDATION_RESULT: ValidationResult = {\n isInvalid: false,\n validationDetails: VALID_VALIDITY_STATE,\n validationErrors: []\n};\n\nexport const FormValidationContext: Context<ValidationErrors> = createContext<ValidationErrors>({});\n\n// Private props that we pass from useFormValidationState to children.\n// Ideally we'd use a Symbol for this, but React doesn't support them: https://github.com/facebook/react/issues/7552\n// This needs to be stable across server and client module evaluation for SSR hydration.\nexport const privateValidationStateProp: string = '__reactAriaFormValidationState';\n\ninterface FormValidationProps<T> extends Validation<T> {\n builtinValidation?: ValidationResult;\n name?: string | string[];\n value: T | null;\n}\n\nexport interface FormValidationState {\n /** Realtime validation results, updated as the user edits the value. */\n realtimeValidation: ValidationResult;\n /** Currently displayed validation results, updated when the user commits their changes. */\n displayValidation: ValidationResult;\n /**\n * Updates the current validation result. Not displayed to the user until `commitValidation` is\n * called.\n */\n updateValidation(result: ValidationResult): void;\n /** Resets the displayed validation state to valid when the user resets the form. */\n resetValidation(): void;\n /** Commits the realtime validation so it is displayed to the user. */\n commitValidation(): void;\n}\n\nexport function useFormValidationState<T>(props: FormValidationProps<T>): FormValidationState {\n // Private prop for parent components to pass state to children.\n if (props[privateValidationStateProp]) {\n let {\n realtimeValidation,\n displayValidation,\n updateValidation,\n resetValidation,\n commitValidation\n } = props[privateValidationStateProp] as FormValidationState;\n return {\n realtimeValidation,\n displayValidation,\n updateValidation,\n resetValidation,\n commitValidation\n };\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useFormValidationStateImpl(props);\n}\n\nfunction useFormValidationStateImpl<T>(props: FormValidationProps<T>): FormValidationState {\n let {\n isInvalid,\n validationState,\n name,\n value,\n builtinValidation,\n validate,\n validationBehavior = 'aria'\n } = props;\n\n // backward compatibility.\n if (validationState) {\n isInvalid ||= validationState === 'invalid';\n }\n\n // If the isInvalid prop is controlled, update validation result in realtime.\n let controlledError: ValidationResult | null =\n isInvalid !== undefined\n ? {\n isInvalid,\n validationErrors: [],\n validationDetails: CUSTOM_VALIDITY_STATE\n }\n : null;\n\n // Perform custom client side validation.\n let clientError: ValidationResult | null = useMemo(() => {\n if (!validate || value == null) {\n return null;\n }\n let validateErrors = runValidate(validate, value);\n return getValidationResult(validateErrors);\n }, [validate, value]);\n\n if (builtinValidation?.validationDetails.valid) {\n builtinValidation = undefined;\n }\n\n // Get relevant server errors from the form.\n let serverErrors = useContext(FormValidationContext);\n let serverErrorMessages = useMemo(() => {\n if (name) {\n return Array.isArray(name)\n ? name.flatMap(name => asArray(serverErrors[name]))\n : asArray(serverErrors[name]);\n }\n return [];\n }, [serverErrors, name]);\n\n // Show server errors when the form gets a new value, and clear when the user changes the value.\n let [lastServerErrors, setLastServerErrors] = useState(serverErrors);\n let [isServerErrorCleared, setServerErrorCleared] = useState(false);\n if (serverErrors !== lastServerErrors) {\n setLastServerErrors(serverErrors);\n setServerErrorCleared(false);\n }\n\n let serverError: ValidationResult | null = useMemo(\n () => getValidationResult(isServerErrorCleared ? [] : serverErrorMessages),\n [isServerErrorCleared, serverErrorMessages]\n );\n\n // Track the next validation state in a ref until commitValidation is called.\n let nextValidation = useRef(DEFAULT_VALIDATION_RESULT);\n let [currentValidity, setCurrentValidity] = useState(DEFAULT_VALIDATION_RESULT);\n\n let lastError = useRef(DEFAULT_VALIDATION_RESULT);\n let commitValidation = () => {\n if (!commitQueued) {\n return;\n }\n\n setCommitQueued(false);\n let error = clientError || builtinValidation || nextValidation.current;\n if (!isEqualValidation(error, lastError.current)) {\n lastError.current = error;\n setCurrentValidity(error);\n }\n };\n\n let [commitQueued, setCommitQueued] = useState(false);\n useEffect(commitValidation);\n\n // realtimeValidation is used to update the native input element's state based on custom validation logic.\n // displayValidation is the currently displayed validation state that the user sees (e.g. on input change/form submit).\n // With validationBehavior=\"aria\", all errors are displayed in realtime rather than on submit.\n let realtimeValidation =\n controlledError || serverError || clientError || builtinValidation || DEFAULT_VALIDATION_RESULT;\n let displayValidation =\n validationBehavior === 'native'\n ? controlledError || serverError || currentValidity\n : controlledError || serverError || clientError || builtinValidation || currentValidity;\n\n return {\n realtimeValidation,\n displayValidation,\n updateValidation(value) {\n // If validationBehavior is 'aria', update in realtime. Otherwise, store in a ref until commit.\n if (validationBehavior === 'aria' && !isEqualValidation(currentValidity, value)) {\n setCurrentValidity(value);\n } else {\n nextValidation.current = value;\n }\n },\n resetValidation() {\n // Update the currently displayed validation state to valid on form reset,\n // even if the native validity says it isn't. It'll show again on the next form submit.\n let error = DEFAULT_VALIDATION_RESULT;\n if (!isEqualValidation(error, lastError.current)) {\n lastError.current = error;\n setCurrentValidity(error);\n }\n\n // Do not commit validation after the next render. This avoids a condition where\n // useSelect calls commitValidation inside an onReset handler.\n if (validationBehavior === 'native') {\n setCommitQueued(false);\n }\n\n setServerErrorCleared(true);\n },\n commitValidation() {\n // Commit validation state so the user sees it on blur/change/submit. Also clear any server errors.\n // Wait until after the next render to commit so that the latest value has been validated.\n if (validationBehavior === 'native') {\n setCommitQueued(true);\n }\n setServerErrorCleared(true);\n }\n };\n}\n\nfunction asArray<T>(v: T | T[]): T[] {\n if (!v) {\n return [];\n }\n\n return Array.isArray(v) ? v : [v];\n}\n\nfunction runValidate<T>(validate: ValidationFunction<T>, value: T): string[] {\n if (typeof validate === 'function') {\n let e = validate(value);\n if (e && typeof e !== 'boolean') {\n return asArray(e);\n }\n }\n\n return [];\n}\n\nfunction getValidationResult(errors: string[]): ValidationResult | null {\n return errors.length\n ? {\n isInvalid: true,\n validationErrors: errors,\n validationDetails: CUSTOM_VALIDITY_STATE\n }\n : null;\n}\n\nfunction isEqualValidation(a: ValidationResult | null, b: ValidationResult | null): boolean {\n if (a === b) {\n return true;\n }\n\n return (\n !!a &&\n !!b &&\n a.isInvalid === b.isInvalid &&\n a.validationErrors.length === b.validationErrors.length &&\n a.validationErrors.every((a, i) => a === b.validationErrors[i]) &&\n Object.entries(a.validationDetails).every(([k, v]) => b.validationDetails[k] === v)\n );\n}\n\nexport function mergeValidation(...results: ValidationResult[]): ValidationResult {\n let errors = new Set<string>();\n let isInvalid = false;\n let validationDetails = {\n ...VALID_VALIDITY_STATE\n };\n\n for (let v of results) {\n for (let e of v.validationErrors) {\n errors.add(e);\n }\n\n // Only these properties apply for checkboxes.\n isInvalid ||= v.isInvalid;\n for (let key in validationDetails) {\n validationDetails[key] ||= v.validationDetails[key];\n }\n }\n\n validationDetails.valid = !isInvalid;\n return {\n isInvalid,\n validationErrors: [...errors],\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useFormValidationState.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AAUM,MAAM,4CAAsC;IACjD,UAAU;IACV,aAAa;IACb,iBAAiB;IACjB,eAAe;IACf,gBAAgB;IAChB,cAAc;IACd,SAAS;IACT,UAAU;IACV,cAAc;IACd,cAAc;IACd,OAAO;AACT;AAEA,MAAM,8CAAuC;IAC3C,GAAG,yCAAoB;IACvB,aAAa;IACb,OAAO;AACT;AAEO,MAAM,4CAA8C;IACzD,WAAW;IACX,mBAAmB;IACnB,kBAAkB,EAAE;AACtB;AAEO,MAAM,4CAAmD,CAAA,GAAA,oBAAY,EAAoB,CAAC;AAK1F,MAAM,2CAAqC;AAwB3C,SAAS,0CAA0B,KAA6B;IACrE,gEAAgE;IAChE,IAAI,KAAK,CAAC,yCAA2B,EAAE;QACrC,IAAI,sBACF,kBAAkB,qBAClB,iBAAiB,oBACjB,gBAAgB,mBAChB,eAAe,oBACf,gBAAgB,EACjB,GAAG,KAAK,CAAC,yCAA2B;QACrC,OAAO;gCACL;+BACA;8BACA;6BACA;8BACA;QACF;IACF;IAEA,4EAA4E;IAC5E,OAAO,iDAA2B;AACpC;AAEA,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 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Context, createContext, useContext, useEffect, useMemo, useRef, useState} from 'react';\nimport {\n Validation,\n ValidationErrors,\n ValidationFunction,\n ValidationResult\n} from '@react-types/shared';\n\nexport const VALID_VALIDITY_STATE: ValidityState = {\n badInput: false,\n customError: false,\n patternMismatch: false,\n rangeOverflow: false,\n rangeUnderflow: false,\n stepMismatch: false,\n tooLong: false,\n tooShort: false,\n typeMismatch: false,\n valueMissing: false,\n valid: true\n};\n\nconst CUSTOM_VALIDITY_STATE: ValidityState = {\n ...VALID_VALIDITY_STATE,\n customError: true,\n valid: false\n};\n\nexport const DEFAULT_VALIDATION_RESULT: ValidationResult = {\n isInvalid: false,\n validationDetails: VALID_VALIDITY_STATE,\n validationErrors: []\n};\n\nexport const FormValidationContext: Context<ValidationErrors> = createContext<ValidationErrors>({});\n\n// Private props that we pass from useFormValidationState to children.\n// Ideally we'd use a Symbol for this, but React doesn't support them: https://github.com/facebook/react/issues/7552\n// This needs to be stable across server and client module evaluation for SSR hydration.\nexport const privateValidationStateProp: string = '__reactAriaFormValidationState';\n\ninterface FormValidationProps<T> extends Validation<T> {\n builtinValidation?: ValidationResult;\n name?: string | string[];\n value: T | null;\n}\n\nexport interface FormValidationState {\n /** Realtime validation results, updated as the user edits the value. */\n realtimeValidation: ValidationResult;\n /** Currently displayed validation results, updated when the user commits their changes. */\n displayValidation: ValidationResult;\n /**\n * Updates the current validation result. Not displayed to the user until `commitValidation` is\n * called.\n */\n updateValidation(result: ValidationResult): void;\n /** Resets the displayed validation state to valid when the user resets the form. */\n resetValidation(): void;\n /** Commits the realtime validation so it is displayed to the user. */\n commitValidation(): void;\n}\n\nexport function useFormValidationState<T>(props: FormValidationProps<T>): FormValidationState {\n // Private prop for parent components to pass state to children.\n if (props[privateValidationStateProp]) {\n let {\n realtimeValidation,\n displayValidation,\n updateValidation,\n resetValidation,\n commitValidation\n } = props[privateValidationStateProp] as FormValidationState;\n return {\n realtimeValidation,\n displayValidation,\n updateValidation,\n resetValidation,\n commitValidation\n };\n }\n\n // oxlint-disable-next-line react/react-compiler, react-hooks/rules-of-hooks\n return useFormValidationStateImpl(props);\n}\n\nfunction useFormValidationStateImpl<T>(props: FormValidationProps<T>): FormValidationState {\n let {\n isInvalid,\n validationState,\n name,\n value,\n builtinValidation,\n validate,\n validationBehavior = 'aria'\n } = props;\n\n // backward compatibility.\n if (validationState) {\n isInvalid ||= validationState === 'invalid';\n }\n\n // If the isInvalid prop is controlled, update validation result in realtime.\n let controlledError: ValidationResult | null =\n isInvalid !== undefined\n ? {\n isInvalid,\n validationErrors: [],\n validationDetails: CUSTOM_VALIDITY_STATE\n }\n : null;\n\n // Perform custom client side validation.\n let clientError: ValidationResult | null = useMemo(() => {\n if (!validate || value == null) {\n return null;\n }\n let validateErrors = runValidate(validate, value);\n return getValidationResult(validateErrors);\n }, [validate, value]);\n\n if (builtinValidation?.validationDetails.valid) {\n builtinValidation = undefined;\n }\n\n // Get relevant server errors from the form.\n let serverErrors = useContext(FormValidationContext);\n let serverErrorMessages = useMemo(() => {\n if (name) {\n return Array.isArray(name)\n ? name.flatMap(name => asArray(serverErrors[name]))\n : asArray(serverErrors[name]);\n }\n return [];\n }, [serverErrors, name]);\n\n // Show server errors when the form gets a new value, and clear when the user changes the value.\n let [lastServerErrors, setLastServerErrors] = useState(serverErrors);\n let [isServerErrorCleared, setServerErrorCleared] = useState(false);\n if (serverErrors !== lastServerErrors) {\n setLastServerErrors(serverErrors);\n setServerErrorCleared(false);\n }\n\n let serverError: ValidationResult | null = useMemo(\n () => getValidationResult(isServerErrorCleared ? [] : serverErrorMessages),\n [isServerErrorCleared, serverErrorMessages]\n );\n\n // Track the next validation state in a ref until commitValidation is called.\n let nextValidation = useRef(DEFAULT_VALIDATION_RESULT);\n let [currentValidity, setCurrentValidity] = useState(DEFAULT_VALIDATION_RESULT);\n\n let lastError = useRef(DEFAULT_VALIDATION_RESULT);\n let commitValidation = () => {\n if (!commitQueued) {\n return;\n }\n\n setCommitQueued(false);\n let error = clientError || builtinValidation || nextValidation.current;\n if (!isEqualValidation(error, lastError.current)) {\n lastError.current = error;\n setCurrentValidity(error);\n }\n };\n\n let [commitQueued, setCommitQueued] = useState(false);\n useEffect(commitValidation);\n\n // realtimeValidation is used to update the native input element's state based on custom validation logic.\n // displayValidation is the currently displayed validation state that the user sees (e.g. on input change/form submit).\n // With validationBehavior=\"aria\", all errors are displayed in realtime rather than on submit.\n let realtimeValidation =\n controlledError || serverError || clientError || builtinValidation || DEFAULT_VALIDATION_RESULT;\n let displayValidation =\n validationBehavior === 'native'\n ? controlledError || serverError || currentValidity\n : controlledError || serverError || clientError || builtinValidation || currentValidity;\n\n return {\n realtimeValidation,\n displayValidation,\n updateValidation(value) {\n // If validationBehavior is 'aria', update in realtime. Otherwise, store in a ref until commit.\n if (validationBehavior === 'aria' && !isEqualValidation(currentValidity, value)) {\n setCurrentValidity(value);\n } else {\n nextValidation.current = value;\n }\n },\n resetValidation() {\n // Update the currently displayed validation state to valid on form reset,\n // even if the native validity says it isn't. It'll show again on the next form submit.\n let error = DEFAULT_VALIDATION_RESULT;\n if (!isEqualValidation(error, lastError.current)) {\n lastError.current = error;\n setCurrentValidity(error);\n }\n\n // Do not commit validation after the next render. This avoids a condition where\n // useSelect calls commitValidation inside an onReset handler.\n if (validationBehavior === 'native') {\n setCommitQueued(false);\n }\n\n setServerErrorCleared(true);\n },\n commitValidation() {\n // Commit validation state so the user sees it on blur/change/submit. Also clear any server errors.\n // Wait until after the next render to commit so that the latest value has been validated.\n if (validationBehavior === 'native') {\n setCommitQueued(true);\n }\n setServerErrorCleared(true);\n }\n };\n}\n\nfunction asArray<T>(v: T | T[]): T[] {\n if (!v) {\n return [];\n }\n\n return Array.isArray(v) ? v : [v];\n}\n\nfunction runValidate<T>(validate: ValidationFunction<T>, value: T): string[] {\n if (typeof validate === 'function') {\n let e = validate(value);\n if (e && typeof e !== 'boolean') {\n return asArray(e);\n }\n }\n\n return [];\n}\n\nfunction getValidationResult(errors: string[]): ValidationResult | null {\n return errors.length\n ? {\n isInvalid: true,\n validationErrors: errors,\n validationDetails: CUSTOM_VALIDITY_STATE\n }\n : null;\n}\n\nfunction isEqualValidation(a: ValidationResult | null, b: ValidationResult | null): boolean {\n if (a === b) {\n return true;\n }\n\n return (\n !!a &&\n !!b &&\n a.isInvalid === b.isInvalid &&\n a.validationErrors.length === b.validationErrors.length &&\n a.validationErrors.every((a, i) => a === b.validationErrors[i]) &&\n Object.entries(a.validationDetails).every(([k, v]) => b.validationDetails[k] === v)\n );\n}\n\nexport function mergeValidation(...results: ValidationResult[]): ValidationResult {\n let errors = new Set<string>();\n let isInvalid = false;\n let validationDetails = {\n ...VALID_VALIDITY_STATE\n };\n\n for (let v of results) {\n for (let e of v.validationErrors) {\n errors.add(e);\n }\n\n // Only these properties apply for checkboxes.\n isInvalid ||= v.isInvalid;\n for (let key in validationDetails) {\n validationDetails[key] ||= v.validationDetails[key];\n }\n }\n\n validationDetails.valid = !isInvalid;\n return {\n isInvalid,\n validationErrors: [...errors],\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useFormValidationState.js.map"}
@@ -48,7 +48,7 @@ function $fd2148440a13ec26$export$fc1a364ae1f3ff10(props) {
48
48
  commitValidation: commitValidation
49
49
  };
50
50
  }
51
- // eslint-disable-next-line react-hooks/rules-of-hooks
51
+ // oxlint-disable-next-line react/react-compiler, react-hooks/rules-of-hooks
52
52
  return $fd2148440a13ec26$var$useFormValidationStateImpl(props);
53
53
  }
54
54
  function $fd2148440a13ec26$var$useFormValidationStateImpl(props) {
@@ -1 +1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,CAAC,EAAE,iBAAiB,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,GAAK,EAAE,iBAAiB,CAAC,EAAE,KAAK;AAErF;AAEO,SAAS,0CAAgB,GAAG,OAA2B;IAC5D,IAAI,SAAS,IAAI;IACjB,IAAI,YAAY;IAChB,IAAI,oBAAoB;QACtB,GAAG,yCAAoB;IACzB;IAEA,KAAK,IAAI,KAAK,QAAS;QACrB,KAAK,IAAI,KAAK,EAAE,gBAAgB,CAC9B,OAAO,GAAG,CAAC;QAGb,8CAA8C;QAC9C,cAAc,EAAE,SAAS;QACzB,IAAK,IAAI,OAAO,kBACd,iBAAiB,CAAC,IAAI,KAAK,EAAE,iBAAiB,CAAC,IAAI;IAEvD;IAEA,kBAAkB,KAAK,GAAG,CAAC;IAC3B,OAAO;mBACL;QACA,kBAAkB;eAAI;SAAO;2BAC7B;IACF;AACF","sources":["packages/react-stately/src/form/useFormValidationState.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Context, createContext, useContext, useEffect, useMemo, useRef, useState} from 'react';\nimport {\n Validation,\n ValidationErrors,\n ValidationFunction,\n ValidationResult\n} from '@react-types/shared';\n\nexport const VALID_VALIDITY_STATE: ValidityState = {\n badInput: false,\n customError: false,\n patternMismatch: false,\n rangeOverflow: false,\n rangeUnderflow: false,\n stepMismatch: false,\n tooLong: false,\n tooShort: false,\n typeMismatch: false,\n valueMissing: false,\n valid: true\n};\n\nconst CUSTOM_VALIDITY_STATE: ValidityState = {\n ...VALID_VALIDITY_STATE,\n customError: true,\n valid: false\n};\n\nexport const DEFAULT_VALIDATION_RESULT: ValidationResult = {\n isInvalid: false,\n validationDetails: VALID_VALIDITY_STATE,\n validationErrors: []\n};\n\nexport const FormValidationContext: Context<ValidationErrors> = createContext<ValidationErrors>({});\n\n// Private props that we pass from useFormValidationState to children.\n// Ideally we'd use a Symbol for this, but React doesn't support them: https://github.com/facebook/react/issues/7552\n// This needs to be stable across server and client module evaluation for SSR hydration.\nexport const privateValidationStateProp: string = '__reactAriaFormValidationState';\n\ninterface FormValidationProps<T> extends Validation<T> {\n builtinValidation?: ValidationResult;\n name?: string | string[];\n value: T | null;\n}\n\nexport interface FormValidationState {\n /** Realtime validation results, updated as the user edits the value. */\n realtimeValidation: ValidationResult;\n /** Currently displayed validation results, updated when the user commits their changes. */\n displayValidation: ValidationResult;\n /**\n * Updates the current validation result. Not displayed to the user until `commitValidation` is\n * called.\n */\n updateValidation(result: ValidationResult): void;\n /** Resets the displayed validation state to valid when the user resets the form. */\n resetValidation(): void;\n /** Commits the realtime validation so it is displayed to the user. */\n commitValidation(): void;\n}\n\nexport function useFormValidationState<T>(props: FormValidationProps<T>): FormValidationState {\n // Private prop for parent components to pass state to children.\n if (props[privateValidationStateProp]) {\n let {\n realtimeValidation,\n displayValidation,\n updateValidation,\n resetValidation,\n commitValidation\n } = props[privateValidationStateProp] as FormValidationState;\n return {\n realtimeValidation,\n displayValidation,\n updateValidation,\n resetValidation,\n commitValidation\n };\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useFormValidationStateImpl(props);\n}\n\nfunction useFormValidationStateImpl<T>(props: FormValidationProps<T>): FormValidationState {\n let {\n isInvalid,\n validationState,\n name,\n value,\n builtinValidation,\n validate,\n validationBehavior = 'aria'\n } = props;\n\n // backward compatibility.\n if (validationState) {\n isInvalid ||= validationState === 'invalid';\n }\n\n // If the isInvalid prop is controlled, update validation result in realtime.\n let controlledError: ValidationResult | null =\n isInvalid !== undefined\n ? {\n isInvalid,\n validationErrors: [],\n validationDetails: CUSTOM_VALIDITY_STATE\n }\n : null;\n\n // Perform custom client side validation.\n let clientError: ValidationResult | null = useMemo(() => {\n if (!validate || value == null) {\n return null;\n }\n let validateErrors = runValidate(validate, value);\n return getValidationResult(validateErrors);\n }, [validate, value]);\n\n if (builtinValidation?.validationDetails.valid) {\n builtinValidation = undefined;\n }\n\n // Get relevant server errors from the form.\n let serverErrors = useContext(FormValidationContext);\n let serverErrorMessages = useMemo(() => {\n if (name) {\n return Array.isArray(name)\n ? name.flatMap(name => asArray(serverErrors[name]))\n : asArray(serverErrors[name]);\n }\n return [];\n }, [serverErrors, name]);\n\n // Show server errors when the form gets a new value, and clear when the user changes the value.\n let [lastServerErrors, setLastServerErrors] = useState(serverErrors);\n let [isServerErrorCleared, setServerErrorCleared] = useState(false);\n if (serverErrors !== lastServerErrors) {\n setLastServerErrors(serverErrors);\n setServerErrorCleared(false);\n }\n\n let serverError: ValidationResult | null = useMemo(\n () => getValidationResult(isServerErrorCleared ? [] : serverErrorMessages),\n [isServerErrorCleared, serverErrorMessages]\n );\n\n // Track the next validation state in a ref until commitValidation is called.\n let nextValidation = useRef(DEFAULT_VALIDATION_RESULT);\n let [currentValidity, setCurrentValidity] = useState(DEFAULT_VALIDATION_RESULT);\n\n let lastError = useRef(DEFAULT_VALIDATION_RESULT);\n let commitValidation = () => {\n if (!commitQueued) {\n return;\n }\n\n setCommitQueued(false);\n let error = clientError || builtinValidation || nextValidation.current;\n if (!isEqualValidation(error, lastError.current)) {\n lastError.current = error;\n setCurrentValidity(error);\n }\n };\n\n let [commitQueued, setCommitQueued] = useState(false);\n useEffect(commitValidation);\n\n // realtimeValidation is used to update the native input element's state based on custom validation logic.\n // displayValidation is the currently displayed validation state that the user sees (e.g. on input change/form submit).\n // With validationBehavior=\"aria\", all errors are displayed in realtime rather than on submit.\n let realtimeValidation =\n controlledError || serverError || clientError || builtinValidation || DEFAULT_VALIDATION_RESULT;\n let displayValidation =\n validationBehavior === 'native'\n ? controlledError || serverError || currentValidity\n : controlledError || serverError || clientError || builtinValidation || currentValidity;\n\n return {\n realtimeValidation,\n displayValidation,\n updateValidation(value) {\n // If validationBehavior is 'aria', update in realtime. Otherwise, store in a ref until commit.\n if (validationBehavior === 'aria' && !isEqualValidation(currentValidity, value)) {\n setCurrentValidity(value);\n } else {\n nextValidation.current = value;\n }\n },\n resetValidation() {\n // Update the currently displayed validation state to valid on form reset,\n // even if the native validity says it isn't. It'll show again on the next form submit.\n let error = DEFAULT_VALIDATION_RESULT;\n if (!isEqualValidation(error, lastError.current)) {\n lastError.current = error;\n setCurrentValidity(error);\n }\n\n // Do not commit validation after the next render. This avoids a condition where\n // useSelect calls commitValidation inside an onReset handler.\n if (validationBehavior === 'native') {\n setCommitQueued(false);\n }\n\n setServerErrorCleared(true);\n },\n commitValidation() {\n // Commit validation state so the user sees it on blur/change/submit. Also clear any server errors.\n // Wait until after the next render to commit so that the latest value has been validated.\n if (validationBehavior === 'native') {\n setCommitQueued(true);\n }\n setServerErrorCleared(true);\n }\n };\n}\n\nfunction asArray<T>(v: T | T[]): T[] {\n if (!v) {\n return [];\n }\n\n return Array.isArray(v) ? v : [v];\n}\n\nfunction runValidate<T>(validate: ValidationFunction<T>, value: T): string[] {\n if (typeof validate === 'function') {\n let e = validate(value);\n if (e && typeof e !== 'boolean') {\n return asArray(e);\n }\n }\n\n return [];\n}\n\nfunction getValidationResult(errors: string[]): ValidationResult | null {\n return errors.length\n ? {\n isInvalid: true,\n validationErrors: errors,\n validationDetails: CUSTOM_VALIDITY_STATE\n }\n : null;\n}\n\nfunction isEqualValidation(a: ValidationResult | null, b: ValidationResult | null): boolean {\n if (a === b) {\n return true;\n }\n\n return (\n !!a &&\n !!b &&\n a.isInvalid === b.isInvalid &&\n a.validationErrors.length === b.validationErrors.length &&\n a.validationErrors.every((a, i) => a === b.validationErrors[i]) &&\n Object.entries(a.validationDetails).every(([k, v]) => b.validationDetails[k] === v)\n );\n}\n\nexport function mergeValidation(...results: ValidationResult[]): ValidationResult {\n let errors = new Set<string>();\n let isInvalid = false;\n let validationDetails = {\n ...VALID_VALIDITY_STATE\n };\n\n for (let v of results) {\n for (let e of v.validationErrors) {\n errors.add(e);\n }\n\n // Only these properties apply for checkboxes.\n isInvalid ||= v.isInvalid;\n for (let key in validationDetails) {\n validationDetails[key] ||= v.validationDetails[key];\n }\n }\n\n validationDetails.valid = !isInvalid;\n return {\n isInvalid,\n validationErrors: [...errors],\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useFormValidationState.mjs.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AAUM,MAAM,4CAAsC;IACjD,UAAU;IACV,aAAa;IACb,iBAAiB;IACjB,eAAe;IACf,gBAAgB;IAChB,cAAc;IACd,SAAS;IACT,UAAU;IACV,cAAc;IACd,cAAc;IACd,OAAO;AACT;AAEA,MAAM,8CAAuC;IAC3C,GAAG,yCAAoB;IACvB,aAAa;IACb,OAAO;AACT;AAEO,MAAM,4CAA8C;IACzD,WAAW;IACX,mBAAmB;IACnB,kBAAkB,EAAE;AACtB;AAEO,MAAM,4CAAmD,CAAA,GAAA,oBAAY,EAAoB,CAAC;AAK1F,MAAM,2CAAqC;AAwB3C,SAAS,0CAA0B,KAA6B;IACrE,gEAAgE;IAChE,IAAI,KAAK,CAAC,yCAA2B,EAAE;QACrC,IAAI,sBACF,kBAAkB,qBAClB,iBAAiB,oBACjB,gBAAgB,mBAChB,eAAe,oBACf,gBAAgB,EACjB,GAAG,KAAK,CAAC,yCAA2B;QACrC,OAAO;gCACL;+BACA;8BACA;6BACA;8BACA;QACF;IACF;IAEA,4EAA4E;IAC5E,OAAO,iDAA2B;AACpC;AAEA,SAAS,iDAA8B,KAA6B;IAClE,IAAI,aACF,SAAS,mBACT,eAAe,QACf,IAAI,SACJ,KAAK,qBACL,iBAAiB,YACjB,QAAQ,sBACR,qBAAqB,QACtB,GAAG;IAEJ,0BAA0B;IAC1B,IAAI,iBACF,cAAc,oBAAoB;IAGpC,6EAA6E;IAC7E,IA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,SAAS,wCAAkB,CAA0B,EAAE,CAA0B;IAC/E,IAAI,MAAM,GACR,OAAO;IAGT,OACE,CAAC,CAAC,KACF,CAAC,CAAC,KACF,EAAE,SAAS,KAAK,EAAE,SAAS,IAC3B,EAAE,gBAAgB,CAAC,MAAM,KAAK,EAAE,gBAAgB,CAAC,MAAM,IACvD,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC,GAAG,IAAM,MAAM,EAAE,gBAAgB,CAAC,EAAE,KAC9D,OAAO,OAAO,CAAC,EAAE,iBAAiB,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,GAAK,EAAE,iBAAiB,CAAC,EAAE,KAAK;AAErF;AAEO,SAAS,0CAAgB,GAAG,OAA2B;IAC5D,IAAI,SAAS,IAAI;IACjB,IAAI,YAAY;IAChB,IAAI,oBAAoB;QACtB,GAAG,yCAAoB;IACzB;IAEA,KAAK,IAAI,KAAK,QAAS;QACrB,KAAK,IAAI,KAAK,EAAE,gBAAgB,CAC9B,OAAO,GAAG,CAAC;QAGb,8CAA8C;QAC9C,cAAc,EAAE,SAAS;QACzB,IAAK,IAAI,OAAO,kBACd,iBAAiB,CAAC,IAAI,KAAK,EAAE,iBAAiB,CAAC,IAAI;IAEvD;IAEA,kBAAkB,KAAK,GAAG,CAAC;IAC3B,OAAO;mBACL;QACA,kBAAkB;eAAI;SAAO;2BAC7B;IACF;AACF","sources":["packages/react-stately/src/form/useFormValidationState.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Context, createContext, useContext, useEffect, useMemo, useRef, useState} from 'react';\nimport {\n Validation,\n ValidationErrors,\n ValidationFunction,\n ValidationResult\n} from '@react-types/shared';\n\nexport const VALID_VALIDITY_STATE: ValidityState = {\n badInput: false,\n customError: false,\n patternMismatch: false,\n rangeOverflow: false,\n rangeUnderflow: false,\n stepMismatch: false,\n tooLong: false,\n tooShort: false,\n typeMismatch: false,\n valueMissing: false,\n valid: true\n};\n\nconst CUSTOM_VALIDITY_STATE: ValidityState = {\n ...VALID_VALIDITY_STATE,\n customError: true,\n valid: false\n};\n\nexport const DEFAULT_VALIDATION_RESULT: ValidationResult = {\n isInvalid: false,\n validationDetails: VALID_VALIDITY_STATE,\n validationErrors: []\n};\n\nexport const FormValidationContext: Context<ValidationErrors> = createContext<ValidationErrors>({});\n\n// Private props that we pass from useFormValidationState to children.\n// Ideally we'd use a Symbol for this, but React doesn't support them: https://github.com/facebook/react/issues/7552\n// This needs to be stable across server and client module evaluation for SSR hydration.\nexport const privateValidationStateProp: string = '__reactAriaFormValidationState';\n\ninterface FormValidationProps<T> extends Validation<T> {\n builtinValidation?: ValidationResult;\n name?: string | string[];\n value: T | null;\n}\n\nexport interface FormValidationState {\n /** Realtime validation results, updated as the user edits the value. */\n realtimeValidation: ValidationResult;\n /** Currently displayed validation results, updated when the user commits their changes. */\n displayValidation: ValidationResult;\n /**\n * Updates the current validation result. Not displayed to the user until `commitValidation` is\n * called.\n */\n updateValidation(result: ValidationResult): void;\n /** Resets the displayed validation state to valid when the user resets the form. */\n resetValidation(): void;\n /** Commits the realtime validation so it is displayed to the user. */\n commitValidation(): void;\n}\n\nexport function useFormValidationState<T>(props: FormValidationProps<T>): FormValidationState {\n // Private prop for parent components to pass state to children.\n if (props[privateValidationStateProp]) {\n let {\n realtimeValidation,\n displayValidation,\n updateValidation,\n resetValidation,\n commitValidation\n } = props[privateValidationStateProp] as FormValidationState;\n return {\n realtimeValidation,\n displayValidation,\n updateValidation,\n resetValidation,\n commitValidation\n };\n }\n\n // oxlint-disable-next-line react/react-compiler, react-hooks/rules-of-hooks\n return useFormValidationStateImpl(props);\n}\n\nfunction useFormValidationStateImpl<T>(props: FormValidationProps<T>): FormValidationState {\n let {\n isInvalid,\n validationState,\n name,\n value,\n builtinValidation,\n validate,\n validationBehavior = 'aria'\n } = props;\n\n // backward compatibility.\n if (validationState) {\n isInvalid ||= validationState === 'invalid';\n }\n\n // If the isInvalid prop is controlled, update validation result in realtime.\n let controlledError: ValidationResult | null =\n isInvalid !== undefined\n ? {\n isInvalid,\n validationErrors: [],\n validationDetails: CUSTOM_VALIDITY_STATE\n }\n : null;\n\n // Perform custom client side validation.\n let clientError: ValidationResult | null = useMemo(() => {\n if (!validate || value == null) {\n return null;\n }\n let validateErrors = runValidate(validate, value);\n return getValidationResult(validateErrors);\n }, [validate, value]);\n\n if (builtinValidation?.validationDetails.valid) {\n builtinValidation = undefined;\n }\n\n // Get relevant server errors from the form.\n let serverErrors = useContext(FormValidationContext);\n let serverErrorMessages = useMemo(() => {\n if (name) {\n return Array.isArray(name)\n ? name.flatMap(name => asArray(serverErrors[name]))\n : asArray(serverErrors[name]);\n }\n return [];\n }, [serverErrors, name]);\n\n // Show server errors when the form gets a new value, and clear when the user changes the value.\n let [lastServerErrors, setLastServerErrors] = useState(serverErrors);\n let [isServerErrorCleared, setServerErrorCleared] = useState(false);\n if (serverErrors !== lastServerErrors) {\n setLastServerErrors(serverErrors);\n setServerErrorCleared(false);\n }\n\n let serverError: ValidationResult | null = useMemo(\n () => getValidationResult(isServerErrorCleared ? [] : serverErrorMessages),\n [isServerErrorCleared, serverErrorMessages]\n );\n\n // Track the next validation state in a ref until commitValidation is called.\n let nextValidation = useRef(DEFAULT_VALIDATION_RESULT);\n let [currentValidity, setCurrentValidity] = useState(DEFAULT_VALIDATION_RESULT);\n\n let lastError = useRef(DEFAULT_VALIDATION_RESULT);\n let commitValidation = () => {\n if (!commitQueued) {\n return;\n }\n\n setCommitQueued(false);\n let error = clientError || builtinValidation || nextValidation.current;\n if (!isEqualValidation(error, lastError.current)) {\n lastError.current = error;\n setCurrentValidity(error);\n }\n };\n\n let [commitQueued, setCommitQueued] = useState(false);\n useEffect(commitValidation);\n\n // realtimeValidation is used to update the native input element's state based on custom validation logic.\n // displayValidation is the currently displayed validation state that the user sees (e.g. on input change/form submit).\n // With validationBehavior=\"aria\", all errors are displayed in realtime rather than on submit.\n let realtimeValidation =\n controlledError || serverError || clientError || builtinValidation || DEFAULT_VALIDATION_RESULT;\n let displayValidation =\n validationBehavior === 'native'\n ? controlledError || serverError || currentValidity\n : controlledError || serverError || clientError || builtinValidation || currentValidity;\n\n return {\n realtimeValidation,\n displayValidation,\n updateValidation(value) {\n // If validationBehavior is 'aria', update in realtime. Otherwise, store in a ref until commit.\n if (validationBehavior === 'aria' && !isEqualValidation(currentValidity, value)) {\n setCurrentValidity(value);\n } else {\n nextValidation.current = value;\n }\n },\n resetValidation() {\n // Update the currently displayed validation state to valid on form reset,\n // even if the native validity says it isn't. It'll show again on the next form submit.\n let error = DEFAULT_VALIDATION_RESULT;\n if (!isEqualValidation(error, lastError.current)) {\n lastError.current = error;\n setCurrentValidity(error);\n }\n\n // Do not commit validation after the next render. This avoids a condition where\n // useSelect calls commitValidation inside an onReset handler.\n if (validationBehavior === 'native') {\n setCommitQueued(false);\n }\n\n setServerErrorCleared(true);\n },\n commitValidation() {\n // Commit validation state so the user sees it on blur/change/submit. Also clear any server errors.\n // Wait until after the next render to commit so that the latest value has been validated.\n if (validationBehavior === 'native') {\n setCommitQueued(true);\n }\n setServerErrorCleared(true);\n }\n };\n}\n\nfunction asArray<T>(v: T | T[]): T[] {\n if (!v) {\n return [];\n }\n\n return Array.isArray(v) ? v : [v];\n}\n\nfunction runValidate<T>(validate: ValidationFunction<T>, value: T): string[] {\n if (typeof validate === 'function') {\n let e = validate(value);\n if (e && typeof e !== 'boolean') {\n return asArray(e);\n }\n }\n\n return [];\n}\n\nfunction getValidationResult(errors: string[]): ValidationResult | null {\n return errors.length\n ? {\n isInvalid: true,\n validationErrors: errors,\n validationDetails: CUSTOM_VALIDITY_STATE\n }\n : null;\n}\n\nfunction isEqualValidation(a: ValidationResult | null, b: ValidationResult | null): boolean {\n if (a === b) {\n return true;\n }\n\n return (\n !!a &&\n !!b &&\n a.isInvalid === b.isInvalid &&\n a.validationErrors.length === b.validationErrors.length &&\n a.validationErrors.every((a, i) => a === b.validationErrors[i]) &&\n Object.entries(a.validationDetails).every(([k, v]) => b.validationDetails[k] === v)\n );\n}\n\nexport function mergeValidation(...results: ValidationResult[]): ValidationResult {\n let errors = new Set<string>();\n let isInvalid = false;\n let validationDetails = {\n ...VALID_VALIDITY_STATE\n };\n\n for (let v of results) {\n for (let e of v.validationErrors) {\n errors.add(e);\n }\n\n // Only these properties apply for checkboxes.\n isInvalid ||= v.isInvalid;\n for (let key in validationDetails) {\n validationDetails[key] ||= v.validationDetails[key];\n }\n }\n\n validationDetails.valid = !isInvalid;\n return {\n isInvalid,\n validationErrors: [...errors],\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useFormValidationState.mjs.map"}
@@ -15,12 +15,13 @@ $parcel$export(module.exports, "useGridState", function () { return $04106318314
15
15
 
16
16
  function $041063183149bf8f$export$4007ac09ff9c68ed(props) {
17
17
  let { collection: collection, focusMode: focusMode } = props;
18
- // eslint-disable-next-line react-hooks/rules-of-hooks
18
+ // oxlint-disable-next-line react/react-compiler, react-hooks/rules-of-hooks
19
19
  let selectionState = props.UNSAFE_selectionState || (0, $0af3d14a0ed99bae$exports.useMultipleSelectionState)(props);
20
20
  let disabledKeys = (0, $7FqS7$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
21
21
  props.disabledKeys
22
22
  ]);
23
23
  let setFocusedKey = selectionState.setFocusedKey;
24
+ // oxlint-disable-next-line react/react-compiler
24
25
  selectionState.setFocusedKey = (key, child)=>{
25
26
  // If focusMode is cell and an item is focused, focus a child cell instead.
26
27
  if (focusMode === 'cell' && key != null) {
@@ -52,17 +53,18 @@ function $041063183149bf8f$export$4007ac09ff9c68ed(props) {
52
53
  const diff = cachedRows.length - rows.length;
53
54
  let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1);
54
55
  let newRow = null;
55
- while(index >= 0){
56
- if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {
57
- newRow = rows[index];
56
+ // Find the nearest focusable row at or after the deleted position...
57
+ for(let i = Math.max(0, index); i < rows.length; i++)if (!selectionManager.isDisabled(rows[i].key) && rows[i].type !== 'headerrow') {
58
+ newRow = rows[i];
59
+ break;
60
+ }
61
+ // ...otherwise the nearest focusable row before it. (Mirrors useListState's
62
+ // getKeyAfter/getKeyBefore walk.)
63
+ if (newRow === null) {
64
+ for(let i = index - 1; i >= 0; i--)if (!selectionManager.isDisabled(rows[i].key) && rows[i].type !== 'headerrow') {
65
+ newRow = rows[i];
58
66
  break;
59
67
  }
60
- // Find next, not disabled row.
61
- if (index < rows.length - 1) index++;
62
- else {
63
- if (index > parentNode.index) index = parentNode.index;
64
- index--;
65
- }
66
68
  }
67
69
  if (newRow) {
68
70
  const childNodes = newRow.hasChildNodes ? [
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;AAuCO,SAAS,0CACd,KAA6B;IAE7B,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG;IAC9B,sDAAsD;IACtD,IAAI,iBAAiB,MAAM,qBAAqB,IAAI,CAAA,GAAA,mDAAwB,EAAE;IAC9E,IAAI,eAAe,CAAA,GAAA,oBAAM,EACvB,IAAO,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,OAC9D;QAAC,MAAM,YAAY;KAAC;IAGtB,IAAI,gBAAgB,eAAe,aAAa;IAChD,eAAe,aAAa,GAAG,CAAC,KAAK;QACnC,2EAA2E;QAC3E,IAAI,cAAc,UAAU,OAAO,MAAM;YACvC,IAAI,OAAO,WAAW,OAAO,CAAC;YAC9B,IAAI,MAAM,SAAS,QAAQ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AAa;oBACrF,SAAS,IAAI,CAAC,MAAM;oBACpB;gBACF;gBACA,+BAA+B;gBAC/B,IAAI,QAAQ,KAAK,MAAM,GAAG,GACxB;qBAEK;oBACL,IAAI,QAAQ,WAAW,KAAK,EAC1B,QAAQ,WAAW,KAAK;oBAE1B;gBACF;YACF;YACA,IAAI,QAAQ;gBACV,MAAM,aAAa,OAAO,aAAa,GAAG;uBAAI,CAAA,GAAA,uCAAY,EAAE,QAAQ;iBAAY,GAAG,EAAE;gBACrF,MAAM,aACJ,OAAO,aAAa,IAAI,eAAe,QAAQ,QAAQ,KAAK,KAAK,GAAG,WAAW,MAAM,GACjF,UAAU,CAAC,KAAK,KAAK,CAAC,CAAC,GAAG,GAC1B,OAAO,GAAG;gBAChB,eAAe,aAAa,CAAC;YAC/B,OACE,eAAe,aAAa,CAAC;QAEjC;QACA,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;QAAkB;QAAgB,eAAe,UAAU;KAAC;IAE5E,OAAO;oBACL;sBACA;QACA,8BAA8B;0BAC9B;IACF;AACF","sources":["packages/react-stately/src/grid/useGridState.ts"],"sourcesContent":["import {getChildNodes, getFirstItem, getLastItem} from '../collections/getChildNodes';\nimport {GridNode, IGridCollection} from './GridCollection';\nimport {Key} from '@react-types/shared';\nimport {MultipleSelectionState} from '../selection/types';\nimport {\n MultipleSelectionStateProps,\n useMultipleSelectionState\n} from '../selection/useMultipleSelectionState';\nimport {SelectionManager} from '../selection/SelectionManager';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface GridState<T, C extends IGridCollection<T>> {\n collection: C;\n /** A set of keys for rows that are disabled. */\n disabledKeys: Set<Key>;\n /** A selection manager to read and update row selection state. */\n selectionManager: SelectionManager;\n /**\n * Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a\n * component within a cell.\n */\n isKeyboardNavigationDisabled: boolean;\n}\n\nexport interface GridStateOptions<\n T,\n C extends IGridCollection<T>\n> extends MultipleSelectionStateProps {\n collection: C;\n disabledKeys?: Iterable<Key>;\n focusMode?: 'row' | 'cell';\n /** @private - Do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState;\n}\n\n/**\n * Provides state management for a grid component. Handles row selection and focusing a grid cell's\n * focusable child if applicable.\n */\nexport function useGridState<T extends object, C extends IGridCollection<T>>(\n props: GridStateOptions<T, C>\n): GridState<T, C> {\n let {collection, focusMode} = props;\n // eslint-disable-next-line react-hooks/rules-of-hooks\n let selectionState = props.UNSAFE_selectionState || useMultipleSelectionState(props);\n let disabledKeys = useMemo(\n () => (props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()),\n [props.disabledKeys]\n );\n\n let setFocusedKey = selectionState.setFocusedKey;\n selectionState.setFocusedKey = (key, child) => {\n // If focusMode is cell and an item is focused, focus a child cell instead.\n if (focusMode === 'cell' && key != null) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n let children = getChildNodes(item, collection);\n if (child === 'last') {\n key = getLastItem(children)?.key ?? null;\n } else {\n key = getFirstItem(children)?.key ?? null;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n let selectionManager = useMemo(\n () => new SelectionManager(collection, selectionState),\n [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef<C | null>(null);\n useEffect(() => {\n if (\n selectionState.focusedKey != null &&\n cachedCollection.current &&\n !collection.getItem(selectionState.focusedKey)\n ) {\n const node = cachedCollection.current.getItem(selectionState.focusedKey);\n const parentNode =\n node?.parentKey != null &&\n (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column')\n ? cachedCollection.current.getItem(node.parentKey)\n : node;\n if (!parentNode) {\n selectionState.setFocusedKey(null);\n return;\n }\n const cachedRows = cachedCollection.current.rows;\n const rows = collection.rows;\n const diff = cachedRows.length - rows.length;\n let index = Math.min(\n diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index,\n rows.length - 1\n );\n let newRow: GridNode<T> | null = null;\n while (index >= 0) {\n if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {\n newRow = rows[index];\n break;\n }\n // Find next, not disabled row.\n if (index < rows.length - 1) {\n index++;\n // Otherwise, find previous, not disabled row.\n } else {\n if (index > parentNode.index) {\n index = parentNode.index;\n }\n index--;\n }\n }\n if (newRow) {\n const childNodes = newRow.hasChildNodes ? [...getChildNodes(newRow, collection)] : [];\n const keyToFocus =\n newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length\n ? childNodes[node.index].key\n : newRow.key;\n selectionState.setFocusedKey(keyToFocus);\n } else {\n selectionState.setFocusedKey(null);\n }\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useGridState.cjs.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;AAuCO,SAAS,0CACd,KAA6B;IAE7B,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG;IAC9B,4EAA4E;IAC5E,IAAI,iBAAiB,MAAM,qBAAqB,IAAI,CAAA,GAAA,mDAAwB,EAAE;IAC9E,IAAI,eAAe,CAAA,GAAA,oBAAM,EACvB,IAAO,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,OAC9D;QAAC,MAAM,YAAY;KAAC;IAGtB,IAAI,gBAAgB,eAAe,aAAa;IAChD,gDAAgD;IAChD,eAAe,aAAa,GAAG,CAAC,KAAK;QACnC,2EAA2E;QAC3E,IAAI,cAAc,UAAU,OAAO,MAAM;YACvC,IAAI,OAAO,WAAW,OAAO,CAAC;YAC9B,IAAI,MAAM,SAAS,QAAQ;gBACzB,IAAI,WAAW,CAAA,GAAA,uCAAY,EAAE,MAAM;gBACnC,IAAI,UAAU,QACZ,MAAM,CAAA,GAAA,qCAAU,EAAE,WAAW,OAAO;qBAEpC,MAAM,CAAA,GAAA,sCAAW,EAAE,WAAW,OA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AM;gBACnB,IAAK,IAAI,IAAI,QAAQ,GAAG,KAAK,GAAG,IAC9B,IAAI,CAAC,iBAAiB,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,aAAa;oBAC7E,SAAS,IAAI,CAAC,EAAE;oBAChB;gBACF;YAEJ;YACA,IAAI,QAAQ;gBACV,MAAM,aAAa,OAAO,aAAa,GAAG;uBAAI,CAAA,GAAA,uCAAY,EAAE,QAAQ;iBAAY,GAAG,EAAE;gBACrF,MAAM,aACJ,OAAO,aAAa,IAAI,eAAe,QAAQ,QAAQ,KAAK,KAAK,GAAG,WAAW,MAAM,GACjF,UAAU,CAAC,KAAK,KAAK,CAAC,CAAC,GAAG,GAC1B,OAAO,GAAG;gBAChB,eAAe,aAAa,CAAC;YAC/B,OACE,eAAe,aAAa,CAAC;QAEjC;QACA,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;QAAkB;QAAgB,eAAe,UAAU;KAAC;IAE5E,OAAO;oBACL;sBACA;QACA,8BAA8B;0BAC9B;IACF;AACF","sources":["packages/react-stately/src/grid/useGridState.ts"],"sourcesContent":["import {getChildNodes, getFirstItem, getLastItem} from '../collections/getChildNodes';\nimport {GridNode, IGridCollection} from './GridCollection';\nimport {Key} from '@react-types/shared';\nimport {MultipleSelectionState} from '../selection/types';\nimport {\n MultipleSelectionStateProps,\n useMultipleSelectionState\n} from '../selection/useMultipleSelectionState';\nimport {SelectionManager} from '../selection/SelectionManager';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface GridState<T, C extends IGridCollection<T>> {\n collection: C;\n /** A set of keys for rows that are disabled. */\n disabledKeys: Set<Key>;\n /** A selection manager to read and update row selection state. */\n selectionManager: SelectionManager;\n /**\n * Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a\n * component within a cell.\n */\n isKeyboardNavigationDisabled: boolean;\n}\n\nexport interface GridStateOptions<\n T,\n C extends IGridCollection<T>\n> extends MultipleSelectionStateProps {\n collection: C;\n disabledKeys?: Iterable<Key>;\n focusMode?: 'row' | 'cell';\n /** @private - Do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState;\n}\n\n/**\n * Provides state management for a grid component. Handles row selection and focusing a grid cell's\n * focusable child if applicable.\n */\nexport function useGridState<T extends object, C extends IGridCollection<T>>(\n props: GridStateOptions<T, C>\n): GridState<T, C> {\n let {collection, focusMode} = props;\n // oxlint-disable-next-line react/react-compiler, react-hooks/rules-of-hooks\n let selectionState = props.UNSAFE_selectionState || useMultipleSelectionState(props);\n let disabledKeys = useMemo(\n () => (props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()),\n [props.disabledKeys]\n );\n\n let setFocusedKey = selectionState.setFocusedKey;\n // oxlint-disable-next-line react/react-compiler\n selectionState.setFocusedKey = (key, child) => {\n // If focusMode is cell and an item is focused, focus a child cell instead.\n if (focusMode === 'cell' && key != null) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n let children = getChildNodes(item, collection);\n if (child === 'last') {\n key = getLastItem(children)?.key ?? null;\n } else {\n key = getFirstItem(children)?.key ?? null;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n let selectionManager = useMemo(\n () => new SelectionManager(collection, selectionState),\n [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef<C | null>(null);\n useEffect(() => {\n if (\n selectionState.focusedKey != null &&\n cachedCollection.current &&\n !collection.getItem(selectionState.focusedKey)\n ) {\n const node = cachedCollection.current.getItem(selectionState.focusedKey);\n const parentNode =\n node?.parentKey != null &&\n (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column')\n ? cachedCollection.current.getItem(node.parentKey)\n : node;\n if (!parentNode) {\n selectionState.setFocusedKey(null);\n return;\n }\n const cachedRows = cachedCollection.current.rows;\n const rows = collection.rows;\n const diff = cachedRows.length - rows.length;\n let index = Math.min(\n diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index,\n rows.length - 1\n );\n let newRow: GridNode<T> | null = null;\n // Find the nearest focusable row at or after the deleted position...\n for (let i = Math.max(0, index); i < rows.length; i++) {\n if (!selectionManager.isDisabled(rows[i].key) && rows[i].type !== 'headerrow') {\n newRow = rows[i];\n break;\n }\n }\n // ...otherwise the nearest focusable row before it. (Mirrors useListState's\n // getKeyAfter/getKeyBefore walk.)\n if (newRow === null) {\n for (let i = index - 1; i >= 0; i--) {\n if (!selectionManager.isDisabled(rows[i].key) && rows[i].type !== 'headerrow') {\n newRow = rows[i];\n break;\n }\n }\n }\n if (newRow) {\n const childNodes = newRow.hasChildNodes ? [...getChildNodes(newRow, collection)] : [];\n const keyToFocus =\n newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length\n ? childNodes[node.index].key\n : newRow.key;\n selectionState.setFocusedKey(keyToFocus);\n } else {\n selectionState.setFocusedKey(null);\n }\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useGridState.cjs.map"}
@@ -9,12 +9,13 @@ import {useMemo as $48ZBF$useMemo, useRef as $48ZBF$useRef, useEffect as $48ZBF$
9
9
 
10
10
  function $5f05a272399e60e1$export$4007ac09ff9c68ed(props) {
11
11
  let { collection: collection, focusMode: focusMode } = props;
12
- // eslint-disable-next-line react-hooks/rules-of-hooks
12
+ // oxlint-disable-next-line react/react-compiler, react-hooks/rules-of-hooks
13
13
  let selectionState = props.UNSAFE_selectionState || (0, $8696e7d7c3c9007a$export$253fe78d46329472)(props);
14
14
  let disabledKeys = (0, $48ZBF$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
15
15
  props.disabledKeys
16
16
  ]);
17
17
  let setFocusedKey = selectionState.setFocusedKey;
18
+ // oxlint-disable-next-line react/react-compiler
18
19
  selectionState.setFocusedKey = (key, child)=>{
19
20
  // If focusMode is cell and an item is focused, focus a child cell instead.
20
21
  if (focusMode === 'cell' && key != null) {
@@ -48,17 +49,18 @@ function $5f05a272399e60e1$export$4007ac09ff9c68ed(props) {
48
49
  const diff = cachedRows.length - rows.length;
49
50
  let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1);
50
51
  let newRow = null;
51
- while(index >= 0){
52
- if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {
53
- newRow = rows[index];
52
+ // Find the nearest focusable row at or after the deleted position...
53
+ for(let i = Math.max(0, index); i < rows.length; i++)if (!selectionManager.isDisabled(rows[i].key) && rows[i].type !== 'headerrow') {
54
+ newRow = rows[i];
55
+ break;
56
+ }
57
+ // ...otherwise the nearest focusable row before it. (Mirrors useListState's
58
+ // getKeyAfter/getKeyBefore walk.)
59
+ if (newRow === null) {
60
+ for(let i = index - 1; i >= 0; i--)if (!selectionManager.isDisabled(rows[i].key) && rows[i].type !== 'headerrow') {
61
+ newRow = rows[i];
54
62
  break;
55
63
  }
56
- // Find next, not disabled row.
57
- if (index < rows.length - 1) index++;
58
- else {
59
- if (index > parentNode.index) index = parentNode.index;
60
- index--;
61
- }
62
64
  }
63
65
  if (newRow) {
64
66
  const childNodes = newRow.hasChildNodes ? [
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAuCO,SAAS,0CACd,KAA6B;IAE7B,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG;IAC9B,sDAAsD;IACtD,IAAI,iBAAiB,MAAM,qBAAqB,IAAI,CAAA,GAAA,yCAAwB,EAAE;IAC9E,IAAI,eAAe,CAAA,GAAA,cAAM,EACvB,IAAO,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,OAC9D;QAAC,MAAM,YAAY;KAAC;IAGtB,IAAI,gBAAgB,eAAe,aAAa;IAChD,eAAe,aAAa,GAAG,CAAC,KAAK;QACnC,2EAA2E;QAC3E,IAAI,cAA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,QAAQ,KAAK,GAAG,CAClB,OAAO,IAAI,KAAK,GAAG,CAAC,WAAW,KAAK,GAAG,OAAO,GAAG,KAAK,WAAW,KAAK,EACtE,KAAK,MAAM,GAAG;YAEhB,IAAI,SAA6B;YACjC,MAAO,SAAS,EAAG;gBACjB,IAAI,CAAC,iBAAiB,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,aAAa;oBACrF,SAAS,IAAI,CAAC,MAAM;oBACpB;gBACF;gBACA,+BAA+B;gBAC/B,IAAI,QAAQ,KAAK,MAAM,GAAG,GACxB;qBAEK;oBACL,IAAI,QAAQ,WAAW,KAAK,EAC1B,QAAQ,WAAW,KAAK;oBAE1B;gBACF;YACF;YACA,IAAI,QAAQ;gBACV,MAAM,aAAa,OAAO,aAAa,GAAG;uBAAI,CAAA,GAAA,yCAAY,EAAE,QAAQ;iBAAY,GAAG,EAAE;gBACrF,MAAM,aACJ,OAAO,aAAa,IAAI,eAAe,QAAQ,QAAQ,KAAK,KAAK,GAAG,WAAW,MAAM,GACjF,UAAU,CAAC,KAAK,KAAK,CAAC,CAAC,GAAG,GAC1B,OAAO,GAAG;gBAChB,eAAe,aAAa,CAAC;YAC/B,OACE,eAAe,aAAa,CAAC;QAEjC;QACA,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;QAAkB;QAAgB,eAAe,UAAU;KAAC;IAE5E,OAAO;oBACL;sBACA;QACA,8BAA8B;0BAC9B;IACF;AACF","sources":["packages/react-stately/src/grid/useGridState.ts"],"sourcesContent":["import {getChildNodes, getFirstItem, getLastItem} from '../collections/getChildNodes';\nimport {GridNode, IGridCollection} from './GridCollection';\nimport {Key} from '@react-types/shared';\nimport {MultipleSelectionState} from '../selection/types';\nimport {\n MultipleSelectionStateProps,\n useMultipleSelectionState\n} from '../selection/useMultipleSelectionState';\nimport {SelectionManager} from '../selection/SelectionManager';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface GridState<T, C extends IGridCollection<T>> {\n collection: C;\n /** A set of keys for rows that are disabled. */\n disabledKeys: Set<Key>;\n /** A selection manager to read and update row selection state. */\n selectionManager: SelectionManager;\n /**\n * Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a\n * component within a cell.\n */\n isKeyboardNavigationDisabled: boolean;\n}\n\nexport interface GridStateOptions<\n T,\n C extends IGridCollection<T>\n> extends MultipleSelectionStateProps {\n collection: C;\n disabledKeys?: Iterable<Key>;\n focusMode?: 'row' | 'cell';\n /** @private - Do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState;\n}\n\n/**\n * Provides state management for a grid component. Handles row selection and focusing a grid cell's\n * focusable child if applicable.\n */\nexport function useGridState<T extends object, C extends IGridCollection<T>>(\n props: GridStateOptions<T, C>\n): GridState<T, C> {\n let {collection, focusMode} = props;\n // eslint-disable-next-line react-hooks/rules-of-hooks\n let selectionState = props.UNSAFE_selectionState || useMultipleSelectionState(props);\n let disabledKeys = useMemo(\n () => (props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()),\n [props.disabledKeys]\n );\n\n let setFocusedKey = selectionState.setFocusedKey;\n selectionState.setFocusedKey = (key, child) => {\n // If focusMode is cell and an item is focused, focus a child cell instead.\n if (focusMode === 'cell' && key != null) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n let children = getChildNodes(item, collection);\n if (child === 'last') {\n key = getLastItem(children)?.key ?? null;\n } else {\n key = getFirstItem(children)?.key ?? null;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n let selectionManager = useMemo(\n () => new SelectionManager(collection, selectionState),\n [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef<C | null>(null);\n useEffect(() => {\n if (\n selectionState.focusedKey != null &&\n cachedCollection.current &&\n !collection.getItem(selectionState.focusedKey)\n ) {\n const node = cachedCollection.current.getItem(selectionState.focusedKey);\n const parentNode =\n node?.parentKey != null &&\n (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column')\n ? cachedCollection.current.getItem(node.parentKey)\n : node;\n if (!parentNode) {\n selectionState.setFocusedKey(null);\n return;\n }\n const cachedRows = cachedCollection.current.rows;\n const rows = collection.rows;\n const diff = cachedRows.length - rows.length;\n let index = Math.min(\n diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index,\n rows.length - 1\n );\n let newRow: GridNode<T> | null = null;\n while (index >= 0) {\n if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {\n newRow = rows[index];\n break;\n }\n // Find next, not disabled row.\n if (index < rows.length - 1) {\n index++;\n // Otherwise, find previous, not disabled row.\n } else {\n if (index > parentNode.index) {\n index = parentNode.index;\n }\n index--;\n }\n }\n if (newRow) {\n const childNodes = newRow.hasChildNodes ? [...getChildNodes(newRow, collection)] : [];\n const keyToFocus =\n newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length\n ? childNodes[node.index].key\n : newRow.key;\n selectionState.setFocusedKey(keyToFocus);\n } else {\n selectionState.setFocusedKey(null);\n }\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useGridState.js.map"}
1
+ {"mappings":";;;;;;;;;AAuCO,SAAS,0CACd,KAA6B;IAE7B,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG;IAC9B,4EAA4E;IAC5E,IAAI,iBAAiB,MAAM,qBAAqB,IAAI,CAAA,GAAA,yCAAwB,EAAE;IAC9E,IAAI,eAAe,CAAA,GAAA,cAAM,EACvB,IAAO,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,OAC9D;QAAC,MAAM,YAAY;KAAC;IAGtB,IAAI,gBAAgB,eAAe,aAAa;IAChD,gDAAgD;IAChD,eAAe,aAAa,GAAG,CAAC,KAAK;QACnC,2EAA2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LastItem} from '../collections/getChildNodes';\nimport {GridNode, IGridCollection} from './GridCollection';\nimport {Key} from '@react-types/shared';\nimport {MultipleSelectionState} from '../selection/types';\nimport {\n MultipleSelectionStateProps,\n useMultipleSelectionState\n} from '../selection/useMultipleSelectionState';\nimport {SelectionManager} from '../selection/SelectionManager';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface GridState<T, C extends IGridCollection<T>> {\n collection: C;\n /** A set of keys for rows that are disabled. */\n disabledKeys: Set<Key>;\n /** A selection manager to read and update row selection state. */\n selectionManager: SelectionManager;\n /**\n * Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a\n * component within a cell.\n */\n isKeyboardNavigationDisabled: boolean;\n}\n\nexport interface GridStateOptions<\n T,\n C extends IGridCollection<T>\n> extends MultipleSelectionStateProps {\n collection: C;\n disabledKeys?: Iterable<Key>;\n focusMode?: 'row' | 'cell';\n /** @private - Do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState;\n}\n\n/**\n * Provides state management for a grid component. Handles row selection and focusing a grid cell's\n * focusable child if applicable.\n */\nexport function useGridState<T extends object, C extends IGridCollection<T>>(\n props: GridStateOptions<T, C>\n): GridState<T, C> {\n let {collection, focusMode} = props;\n // oxlint-disable-next-line react/react-compiler, react-hooks/rules-of-hooks\n let selectionState = props.UNSAFE_selectionState || useMultipleSelectionState(props);\n let disabledKeys = useMemo(\n () => (props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()),\n [props.disabledKeys]\n );\n\n let setFocusedKey = selectionState.setFocusedKey;\n // oxlint-disable-next-line react/react-compiler\n selectionState.setFocusedKey = (key, child) => {\n // If focusMode is cell and an item is focused, focus a child cell instead.\n if (focusMode === 'cell' && key != null) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n let children = getChildNodes(item, collection);\n if (child === 'last') {\n key = getLastItem(children)?.key ?? null;\n } else {\n key = getFirstItem(children)?.key ?? null;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n let selectionManager = useMemo(\n () => new SelectionManager(collection, selectionState),\n [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef<C | null>(null);\n useEffect(() => {\n if (\n selectionState.focusedKey != null &&\n cachedCollection.current &&\n !collection.getItem(selectionState.focusedKey)\n ) {\n const node = cachedCollection.current.getItem(selectionState.focusedKey);\n const parentNode =\n node?.parentKey != null &&\n (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column')\n ? cachedCollection.current.getItem(node.parentKey)\n : node;\n if (!parentNode) {\n selectionState.setFocusedKey(null);\n return;\n }\n const cachedRows = cachedCollection.current.rows;\n const rows = collection.rows;\n const diff = cachedRows.length - rows.length;\n let index = Math.min(\n diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index,\n rows.length - 1\n );\n let newRow: GridNode<T> | null = null;\n // Find the nearest focusable row at or after the deleted position...\n for (let i = Math.max(0, index); i < rows.length; i++) {\n if (!selectionManager.isDisabled(rows[i].key) && rows[i].type !== 'headerrow') {\n newRow = rows[i];\n break;\n }\n }\n // ...otherwise the nearest focusable row before it. (Mirrors useListState's\n // getKeyAfter/getKeyBefore walk.)\n if (newRow === null) {\n for (let i = index - 1; i >= 0; i--) {\n if (!selectionManager.isDisabled(rows[i].key) && rows[i].type !== 'headerrow') {\n newRow = rows[i];\n break;\n }\n }\n }\n if (newRow) {\n const childNodes = newRow.hasChildNodes ? [...getChildNodes(newRow, collection)] : [];\n const keyToFocus =\n newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length\n ? childNodes[node.index].key\n : newRow.key;\n selectionState.setFocusedKey(keyToFocus);\n } else {\n selectionState.setFocusedKey(null);\n }\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useGridState.js.map"}
@@ -9,12 +9,13 @@ import {useMemo as $974D5$useMemo, useRef as $974D5$useRef, useEffect as $974D5$
9
9
 
10
10
  function $183b79a1dd6664c1$export$4007ac09ff9c68ed(props) {
11
11
  let { collection: collection, focusMode: focusMode } = props;
12
- // eslint-disable-next-line react-hooks/rules-of-hooks
12
+ // oxlint-disable-next-line react/react-compiler, react-hooks/rules-of-hooks
13
13
  let selectionState = props.UNSAFE_selectionState || (0, $60f19cefd567a3e4$export$253fe78d46329472)(props);
14
14
  let disabledKeys = (0, $974D5$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
15
15
  props.disabledKeys
16
16
  ]);
17
17
  let setFocusedKey = selectionState.setFocusedKey;
18
+ // oxlint-disable-next-line react/react-compiler
18
19
  selectionState.setFocusedKey = (key, child)=>{
19
20
  // If focusMode is cell and an item is focused, focus a child cell instead.
20
21
  if (focusMode === 'cell' && key != null) {
@@ -46,17 +47,18 @@ function $183b79a1dd6664c1$export$4007ac09ff9c68ed(props) {
46
47
  const diff = cachedRows.length - rows.length;
47
48
  let index = Math.min(diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index, rows.length - 1);
48
49
  let newRow = null;
49
- while(index >= 0){
50
- if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {
51
- newRow = rows[index];
50
+ // Find the nearest focusable row at or after the deleted position...
51
+ for(let i = Math.max(0, index); i < rows.length; i++)if (!selectionManager.isDisabled(rows[i].key) && rows[i].type !== 'headerrow') {
52
+ newRow = rows[i];
53
+ break;
54
+ }
55
+ // ...otherwise the nearest focusable row before it. (Mirrors useListState's
56
+ // getKeyAfter/getKeyBefore walk.)
57
+ if (newRow === null) {
58
+ for(let i = index - 1; i >= 0; i--)if (!selectionManager.isDisabled(rows[i].key) && rows[i].type !== 'headerrow') {
59
+ newRow = rows[i];
52
60
  break;
53
61
  }
54
- // Find next, not disabled row.
55
- if (index < rows.length - 1) index++;
56
- else {
57
- if (index > parentNode.index) index = parentNode.index;
58
- index--;
59
- }
60
62
  }
61
63
  if (newRow) {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/useGridState.ts"],"sourcesContent":["import {getChildNodes, getFirstItem, getLastItem} from '../collections/getChildNodes';\nimport {GridNode, IGridCollection} from './GridCollection';\nimport {Key} from '@react-types/shared';\nimport {MultipleSelectionState} from '../selection/types';\nimport {\n MultipleSelectionStateProps,\n useMultipleSelectionState\n} from '../selection/useMultipleSelectionState';\nimport {SelectionManager} from '../selection/SelectionManager';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface GridState<T, C extends IGridCollection<T>> {\n collection: C;\n /** A set of keys for rows that are disabled. */\n disabledKeys: Set<Key>;\n /** A selection manager to read and update row selection state. */\n selectionManager: SelectionManager;\n /**\n * Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a\n * component within a cell.\n */\n isKeyboardNavigationDisabled: boolean;\n}\n\nexport interface GridStateOptions<\n T,\n C extends IGridCollection<T>\n> extends MultipleSelectionStateProps {\n collection: C;\n disabledKeys?: Iterable<Key>;\n focusMode?: 'row' | 'cell';\n /** @private - Do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState;\n}\n\n/**\n * Provides state management for a grid component. Handles row selection and focusing a grid cell's\n * focusable child if applicable.\n */\nexport function useGridState<T extends object, C extends IGridCollection<T>>(\n props: GridStateOptions<T, C>\n): GridState<T, C> {\n let {collection, focusMode} = props;\n // eslint-disable-next-line react-hooks/rules-of-hooks\n let selectionState = props.UNSAFE_selectionState || useMultipleSelectionState(props);\n let disabledKeys = useMemo(\n () => (props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()),\n [props.disabledKeys]\n );\n\n let setFocusedKey = selectionState.setFocusedKey;\n selectionState.setFocusedKey = (key, child) => {\n // If focusMode is cell and an item is focused, focus a child cell instead.\n if (focusMode === 'cell' && key != null) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n let children = getChildNodes(item, collection);\n if (child === 'last') {\n key = getLastItem(children)?.key ?? null;\n } else {\n key = getFirstItem(children)?.key ?? null;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n let selectionManager = useMemo(\n () => new SelectionManager(collection, selectionState),\n [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef<C | null>(null);\n useEffect(() => {\n if (\n selectionState.focusedKey != null &&\n cachedCollection.current &&\n !collection.getItem(selectionState.focusedKey)\n ) {\n const node = cachedCollection.current.getItem(selectionState.focusedKey);\n const parentNode =\n node?.parentKey != null &&\n (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column')\n ? cachedCollection.current.getItem(node.parentKey)\n : node;\n if (!parentNode) {\n selectionState.setFocusedKey(null);\n return;\n }\n const cachedRows = cachedCollection.current.rows;\n const rows = collection.rows;\n const diff = cachedRows.length - rows.length;\n let index = Math.min(\n diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index,\n rows.length - 1\n );\n let newRow: GridNode<T> | null = null;\n while (index >= 0) {\n if (!selectionManager.isDisabled(rows[index].key) && rows[index].type !== 'headerrow') {\n newRow = rows[index];\n break;\n }\n // Find next, not disabled row.\n if (index < rows.length - 1) {\n index++;\n // Otherwise, find previous, not disabled row.\n } else {\n if (index > parentNode.index) {\n index = parentNode.index;\n }\n index--;\n }\n }\n if (newRow) {\n const childNodes = newRow.hasChildNodes ? [...getChildNodes(newRow, collection)] : [];\n const keyToFocus =\n newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length\n ? childNodes[node.index].key\n : newRow.key;\n selectionState.setFocusedKey(keyToFocus);\n } else {\n selectionState.setFocusedKey(null);\n }\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useGridState.mjs.map"}
1
+ {"mappings":";;;;;;;;;AAuCO,SAAS,0CACd,KAA6B;IAE7B,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG;IAC9B,4EAA4E;IAC5E,IAAI,iBAAiB,MAAM,qBAAqB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","sources":["packages/react-stately/src/grid/useGridState.ts"],"sourcesContent":["import {getChildNodes, getFirstItem, getLastItem} from '../collections/getChildNodes';\nimport {GridNode, IGridCollection} from './GridCollection';\nimport {Key} from '@react-types/shared';\nimport {MultipleSelectionState} from '../selection/types';\nimport {\n MultipleSelectionStateProps,\n useMultipleSelectionState\n} from '../selection/useMultipleSelectionState';\nimport {SelectionManager} from '../selection/SelectionManager';\nimport {useEffect, useMemo, useRef} from 'react';\n\nexport interface GridState<T, C extends IGridCollection<T>> {\n collection: C;\n /** A set of keys for rows that are disabled. */\n disabledKeys: Set<Key>;\n /** A selection manager to read and update row selection state. */\n selectionManager: SelectionManager;\n /**\n * Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a\n * component within a cell.\n */\n isKeyboardNavigationDisabled: boolean;\n}\n\nexport interface GridStateOptions<\n T,\n C extends IGridCollection<T>\n> extends MultipleSelectionStateProps {\n collection: C;\n disabledKeys?: Iterable<Key>;\n focusMode?: 'row' | 'cell';\n /** @private - Do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState;\n}\n\n/**\n * Provides state management for a grid component. Handles row selection and focusing a grid cell's\n * focusable child if applicable.\n */\nexport function useGridState<T extends object, C extends IGridCollection<T>>(\n props: GridStateOptions<T, C>\n): GridState<T, C> {\n let {collection, focusMode} = props;\n // oxlint-disable-next-line react/react-compiler, react-hooks/rules-of-hooks\n let selectionState = props.UNSAFE_selectionState || useMultipleSelectionState(props);\n let disabledKeys = useMemo(\n () => (props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()),\n [props.disabledKeys]\n );\n\n let setFocusedKey = selectionState.setFocusedKey;\n // oxlint-disable-next-line react/react-compiler\n selectionState.setFocusedKey = (key, child) => {\n // If focusMode is cell and an item is focused, focus a child cell instead.\n if (focusMode === 'cell' && key != null) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n let children = getChildNodes(item, collection);\n if (child === 'last') {\n key = getLastItem(children)?.key ?? null;\n } else {\n key = getFirstItem(children)?.key ?? null;\n }\n }\n }\n\n setFocusedKey(key, child);\n };\n\n let selectionManager = useMemo(\n () => new SelectionManager(collection, selectionState),\n [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef<C | null>(null);\n useEffect(() => {\n if (\n selectionState.focusedKey != null &&\n cachedCollection.current &&\n !collection.getItem(selectionState.focusedKey)\n ) {\n const node = cachedCollection.current.getItem(selectionState.focusedKey);\n const parentNode =\n node?.parentKey != null &&\n (node.type === 'cell' || node.type === 'rowheader' || node.type === 'column')\n ? cachedCollection.current.getItem(node.parentKey)\n : node;\n if (!parentNode) {\n selectionState.setFocusedKey(null);\n return;\n }\n const cachedRows = cachedCollection.current.rows;\n const rows = collection.rows;\n const diff = cachedRows.length - rows.length;\n let index = Math.min(\n diff > 1 ? Math.max(parentNode.index - diff + 1, 0) : parentNode.index,\n rows.length - 1\n );\n let newRow: GridNode<T> | null = null;\n // Find the nearest focusable row at or after the deleted position...\n for (let i = Math.max(0, index); i < rows.length; i++) {\n if (!selectionManager.isDisabled(rows[i].key) && rows[i].type !== 'headerrow') {\n newRow = rows[i];\n break;\n }\n }\n // ...otherwise the nearest focusable row before it. (Mirrors useListState's\n // getKeyAfter/getKeyBefore walk.)\n if (newRow === null) {\n for (let i = index - 1; i >= 0; i--) {\n if (!selectionManager.isDisabled(rows[i].key) && rows[i].type !== 'headerrow') {\n newRow = rows[i];\n break;\n }\n }\n }\n if (newRow) {\n const childNodes = newRow.hasChildNodes ? [...getChildNodes(newRow, collection)] : [];\n const keyToFocus =\n newRow.hasChildNodes && parentNode !== node && node && node.index < childNodes.length\n ? childNodes[node.index].key\n : newRow.key;\n selectionState.setFocusedKey(keyToFocus);\n } else {\n selectionState.setFocusedKey(null);\n }\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n isKeyboardNavigationDisabled: false,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useGridState.mjs.map"}
@@ -126,9 +126,6 @@ class $d474db7fa4a60716$export$cacbb3924155d68e extends (0, $4b8e6a761bc1571f$ex
126
126
  return node.layoutInfo.rect.intersects(rect) || node.layoutInfo.isSticky || node.layoutInfo.type === 'header' || node.layoutInfo.type === 'loader' || this.virtualizer.isPersistedKey(node.layoutInfo.key);
127
127
  }
128
128
  shouldInvalidateEverything(invalidationContext) {
129
- // Invalidate cache if the size of the collection changed.
130
- // In this case, we need to recalculate the entire layout.
131
- // Also invalidate if fixed sizes/gaps change.
132
129
  let options = invalidationContext.layoutOptions;
133
130
  return invalidationContext.sizeChanged || this.rowSize !== (options?.rowSize ?? options?.rowHeight ?? this.rowSize) || this.orientation !== (options?.orientation ?? this.orientation) || this.headingSize !== (options?.headingSize ?? options?.headingHeight ?? this.headingSize) || this.loaderSize !== (options?.loaderSize ?? options?.loaderHeight ?? this.loaderSize) || this.gap !== (options?.gap ?? this.gap) || this.padding !== (options?.padding ?? this.padding);
134
131
  }