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,GAMM,SAAS,0CAAS,KAAyB;IAChD,OAAO,SAAS,QAAS,CAAA,CAAC,MAAM,UAAoB,OAAO,OAAO,KAAK,CAAC,oBAAoB,IAAG;AACjG;AAEO,SAAS,0CAAoB,KAAyB;IAC3D,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B,OAAO;IAET,IAAI,QAAQ,MAAM,KAAK,CAAC;IACxB,6DAA6D;IAC7D,IAAI,CAAC,OAAO;QACV,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,cAC3B,QAAQ,IAAI,CACV,CAAC,OAAO,EAAE,MAAM,6GAA6G,CAAC,EAC9H;QAGJ,OAAO;IACT;IACA,OAAO,WAAW,KAAK,CAAC,EAAE;AAC5B;AAEO,SAAS,0CAAiB,KAAsB,EAAE,UAAkB;IACzE,IAAI,OAAO,UAAU,UAAU;QAC7B,IAAI,QAAQ,MAAM,KAAK,CAAC;QACxB,IAAI,CAAC,OACH,MAAM,IAAI,MAAM;QAElB,OAAO,aAAc,CAAA,WAAW,KAAK,CAAC,EAAE,IAAI,GAAE;IAChD;IACA,OAAO;AACT;AAEO,SAAS,0CACd,QAA4C,EAC5C,UAAkB;IAElB,OAAO,YAAY,OAAO,0CAAiB,UAAU,cAAc,OAAO,gBAAgB;AAC5F;AAGO,SAAS,0CAAY,QAAyB,EAAE,U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IAAI,WAAW;IACf,IAAI,eAAyB,EAAE;IAC/B,UAAU,OAAO,CAAC,SAAU,IAAI;QAC9B,IAAI,QAAQ,KAAK,cAAc;QAC/B,IAAI,UAAU,KAAK,KAAK,CAAC,QAAQ,WAAW;QAC5C,WAAW;QACX,YAAY;QACZ,aAAa,IAAI,CAAC;IACpB;IAEA,OAAO;AACT","sources":["packages/react-stately/src/table/TableUtils.ts"],"sourcesContent":["/*\n * Copyright 2022 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 {ColumnSize} from './Column';\nimport {Key} from '@react-types/shared';\n\n// numbers and percents are considered static. *fr units or a lack of units are considered dynamic.\nexport function isStatic(width?: ColumnSize | null): boolean {\n return width != null && (!isNaN(width as number) || String(width).match(/^(\\d+)(?=%$)/) !== null);\n}\n\nexport function parseFractionalUnit(width?: ColumnSize | null): number {\n if (!width || typeof width === 'number') {\n return 1;\n }\n let match = width.match(/^(.+)(?=fr$)/);\n // if width is the incorrect format, just default it to a 1fr\n if (!match) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `width: ${width} is not a supported format, width should be a number (ex. 150), percentage (ex. '50%') or fr unit (ex. '2fr')`,\n \"defaulting to '1fr'\"\n );\n }\n return 1;\n }\n return parseFloat(match[0]);\n}\n\nexport function parseStaticWidth(width: number | string, tableWidth: number): number {\n if (typeof width === 'string') {\n let match = width.match(/^(\\d+)(?=%$)/);\n if (!match) {\n throw new Error('Only percentages or numbers are supported for static column widths');\n }\n return tableWidth * (parseFloat(match[0]) / 100);\n }\n return width;\n}\n\nexport function getMaxWidth(\n maxWidth: number | string | null | undefined,\n tableWidth: number\n): number {\n return maxWidth != null ? parseStaticWidth(maxWidth, tableWidth) : Number.MAX_SAFE_INTEGER;\n}\n\n// cannot support FR units, we'd need to know everything else in the table to do that\nexport function getMinWidth(minWidth: number | string, tableWidth: number): number {\n return minWidth != null ? parseStaticWidth(minWidth, tableWidth) : 0;\n}\n\nexport interface IColumn {\n minWidth?: number | string;\n maxWidth?: number | string;\n width?: number | string;\n defaultWidth?: number | string;\n key: Key;\n}\n\ninterface FlexItem {\n frozen: boolean;\n baseSize: number;\n hypotheticalMainSize: number;\n min: number;\n max: number;\n flex: number;\n targetMainSize: number;\n violation: number;\n}\n\n/**\n * Implements the flex algorithm described in https://www.w3.org/TR/css-flexbox-1/#layout-algorithm\n * It makes a few constraint/assumptions: 1. All basis values are 0 unless it is a static width,\n * then the basis is the static width 2. All flex grow and shrink values are equal to the FR\n * specified on the column, grow and shrink for the same column are equal 3. We only have one row An\n * example of the setup can be seen here https://jsfiddle.net/snowystinger/wv0ymjaf/61/ where I let\n * the browser figure out the flex of the columns. Note: We differ in one key aspect, all of our\n * column widths must be whole numbers, so we avoid browser sub pixel rounding errors. To do this,\n * we use a cascading rounding algorithm to ensure that the sum of the widths is maintained while\n * distributing the rounding remainder across the columns.\n *\n * As noted in the chrome source code, this algorithm is very accurate, but has the potential to be\n * quadratic. They have deemed this to be acceptable because the number of elements is usually small\n * and the flex factors are usually not high variance. I believe we can make the same assumptions.\n * Particularly once resizing is started, it will convert all columns to the left to static widths,\n * so it will cut down on the number of FR columns.\n *\n * There are likely faster ways to do this, I've chosen to stick to the spec as closely as possible\n * for readability, accuracy, and for the note that this behaving quadratically is unlikely to be a\n * problem.\n *\n * @param availableWidth - The visible width of the table.\n * @param columns - The table defined columns.\n * @param changedColumns - Any columns we want to override, for example, during resizing.\n * @param getDefaultWidth - A function that returns the default width of a column by its index.\n * @param getDefaultMinWidth - A function that returns the default min width of a column by its\n * index.\n */\nexport function calculateColumnSizes(\n availableWidth: number,\n columns: IColumn[],\n changedColumns: Map<Key, ColumnSize>,\n getDefaultWidth?: (index: number) => ColumnSize | null | undefined,\n getDefaultMinWidth?: (index: number) => ColumnSize | null | undefined\n): number[] {\n let hasNonFrozenItems = false;\n let flexItems: FlexItem[] = columns.map((column, index) => {\n let width: ColumnSize = (\n changedColumns.get(column.key) != null\n ? (changedColumns.get(column.key) ?? '1fr')\n : (column.width ?? column.defaultWidth ?? getDefaultWidth?.(index) ?? '1fr')\n ) as ColumnSize;\n let frozen = false;\n let baseSize = 0;\n let flex = 0;\n let targetMainSize = 0;\n if (isStatic(width)) {\n baseSize = parseStaticWidth(width, availableWidth);\n frozen = true;\n } else {\n flex = parseFractionalUnit(width);\n if (flex <= 0) {\n frozen = true;\n }\n }\n\n let min = getMinWidth(column.minWidth ?? getDefaultMinWidth?.(index) ?? 0, availableWidth);\n let max = getMaxWidth(column.maxWidth, availableWidth);\n let hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));\n\n // 9.7.1\n // We don't make use of flex basis, it's always 0, so we are always in 'grow' mode.\n // 9.7.2\n if (frozen) {\n targetMainSize = hypotheticalMainSize;\n } else if (baseSize > hypotheticalMainSize) {\n frozen = true;\n targetMainSize = hypotheticalMainSize;\n }\n\n // 9.7.3\n if (!frozen) {\n hasNonFrozenItems = true;\n }\n return {\n frozen,\n baseSize,\n hypotheticalMainSize,\n min,\n max,\n flex,\n targetMainSize,\n violation: 0\n };\n });\n\n // 9.7.4\n // 9.7.4.a\n while (hasNonFrozenItems) {\n // 9.7.4.b\n /**\n * Calculate the remaining free space as for initial free space,\n * above (9.7.3). If the sum of the unfrozen flex items’ flex factors is\n * less than one, multiply the initial free space by this sum (of flex factors).\n * If the magnitude of this value is less than the magnitude of\n * the remaining free space, use this as the remaining free space.\n */\n let usedWidth = 0;\n let flexFactors = 0;\n flexItems.forEach(item => {\n if (item.frozen) {\n usedWidth += item.targetMainSize;\n } else {\n usedWidth += item.baseSize;\n flexFactors += item.flex;\n }\n });\n\n let remainingFreeSpace = availableWidth - usedWidth;\n // we only support integer FR's, and because of hasNonFrozenItems, we know that flexFactors > 0\n // so no need to check for flexFactors < 1\n // 9.7.4.c\n /**\n * If the remaining free space is zero\n * - Do nothing.\n * Else // remember, we're always in grow mode\n * - Find the ratio of the item’s flex grow factor to the\n * sum of the flex grow factors of all unfrozen items on\n * the line. Set the item’s target main size to its flex\n * base size plus a fraction of the remaining free space\n * proportional to the ratio.\n */\n if (remainingFreeSpace > 0) {\n flexItems.forEach(item => {\n if (!item.frozen) {\n let ratio = item.flex / flexFactors;\n item.targetMainSize = item.baseSize + ratio * remainingFreeSpace;\n }\n });\n }\n\n // 9.7.4.d\n /**\n * Fix min/max violations. Clamp each non-frozen item’s\n * target main size by its used min and max main sizes\n * and floor its content-box size at zero. If the item’s\n * target main size was made smaller by this, it’s a max\n * violation. If the item’s target main size was made\n * larger by this, it’s a min violation.\n */\n let totalViolation = 0;\n flexItems.forEach(item => {\n item.violation = 0;\n if (!item.frozen) {\n let {min, max, targetMainSize} = item;\n item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));\n\n item.violation = item.targetMainSize - targetMainSize;\n totalViolation += item.violation;\n }\n });\n\n // 9.7.4.e\n /**\n * Freeze over-flexed items. The total violation is the\n * sum of the adjustments from the previous step\n * ∑(clamped size - unclamped size). If the total violation is:\n * Zero\n * - Freeze all items.\n *\n * Positive\n * - Freeze all the items with min violations.\n *\n * Negative\n * - Freeze all the items with max violations.\n */\n hasNonFrozenItems = false;\n flexItems.forEach(item => {\n if (totalViolation === 0 || Math.sign(totalViolation) === Math.sign(item.violation)) {\n item.frozen = true;\n } else if (!item.frozen) {\n hasNonFrozenItems = true;\n }\n });\n }\n\n return cascadeRounding(flexItems);\n}\n\nfunction cascadeRounding(flexItems: FlexItem[]): number[] {\n /*\n Given an array of floats that sum to an integer, this rounds the floats\n and returns an array of integers with the same sum.\n */\n\n let fpTotal = 0;\n let intTotal = 0;\n let roundedArray: number[] = [];\n flexItems.forEach(function (item) {\n let float = item.targetMainSize;\n let integer = Math.round(float + fpTotal) - intTotal;\n fpTotal += float;\n intTotal += integer;\n roundedArray.push(integer);\n });\n\n return roundedArray;\n}\n"],"names":[],"version":3,"file":"TableUtils.js.map"}
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAMM,SAAS,0CAAS,KAAyB;IAChD,OAAO,SAAS,QAAS,CAAA,CAAC,MAAM,UAAoB,OAAO,OAAO,KAAK,CAAC,oBAAoB,IAAG;AACjG;AAEO,SAAS,0CAAoB,KAAyB;IAC3D,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B,OAAO;IAET,IAAI,QAAQ,MAAM,KAAK,CAAC;IACxB,6DAA6D;IAC7D,IAAI,CAAC,OAAO;QACV,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,cAC3B,QAAQ,IAAI,CACV,CAAC,OAAO,EAAE,MAAM,6GAA6G,CAAC,EAC9H;QAGJ,OAAO;IACT;IACA,OAAO,WAAW,KAAK,CAAC,EAAE;AAC5B;AAEO,SAAS,0CAAiB,KAAsB,EAAE,UAAkB;IACzE,IAAI,OAAO,UAAU,UAAU;QAC7B,IAAI,QAAQ,MAAM,KAAK,CAAC;QACxB,IAAI,CAAC,OACH,MAAM,IAAI,MAAM;QAElB,OAAO,aAAc,CAAA,WAAW,KAAK,CAAC,EAAE,IAAI,GAAE;IAChD;IACA,OAAO;AACT;AAEO,SAAS,0CACd,QAA4C,EAC5C,UAAkB;IAElB,OAAO,YAAY,OAAO,0CAAiB,UAAU,cAAc,OAAO,gBAAgB;AAC5F;AAGO,SAAS,0CAAY,QAAyB,EAAE,UAAkB;IACvE,OAAO,YAAY,OAAO,0CAAiB,UAAU,cAAc;AACrE;AAiDO,SAAS,0CACd,cAAsB,EACtB,OAAkB,EAClB,cAAoC,EACpC,eAAkE,EAClE,kBAAqE;IAErE,IAAI,gBAAgB;IACpB,IAAI,eAAe,KAAK,KAAK,CAAC;IAC9B,IAAI,qBAAqB,iBAAiB,eAAe;IACzD,iBAAiB;I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QAAQ;QAC9D,WAAW,CAAC,YAAY,MAAM,GAAG,EAAE,GAAG,OAAO,cAAc,MAAM;IACnE;IAEA,OAAO;AACT;AAEA,SAAS,sCAAgB,SAAqB;IAC5C;;;EAGA,GAEA,IAAI,UAAU;IACd,IAAI,WAAW;IACf,IAAI,eAAyB,EAAE;IAC/B,UAAU,OAAO,CAAC,SAAU,IAAI;QAC9B,IAAI,QAAQ,KAAK,cAAc;QAC/B,IAAI,UAAU,KAAK,KAAK,CAAC,QAAQ,WAAW;QAC5C,WAAW;QACX,YAAY;QACZ,aAAa,IAAI,CAAC;IACpB;IAEA,OAAO;AACT","sources":["packages/react-stately/src/table/TableUtils.ts"],"sourcesContent":["/*\n * Copyright 2022 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 {ColumnSize} from './Column';\nimport {Key} from '@react-types/shared';\n\n// numbers and percents are considered static. *fr units or a lack of units are considered dynamic.\nexport function isStatic(width?: ColumnSize | null): boolean {\n return width != null && (!isNaN(width as number) || String(width).match(/^(\\d+)(?=%$)/) !== null);\n}\n\nexport function parseFractionalUnit(width?: ColumnSize | null): number {\n if (!width || typeof width === 'number') {\n return 1;\n }\n let match = width.match(/^(.+)(?=fr$)/);\n // if width is the incorrect format, just default it to a 1fr\n if (!match) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `width: ${width} is not a supported format, width should be a number (ex. 150), percentage (ex. '50%') or fr unit (ex. '2fr')`,\n \"defaulting to '1fr'\"\n );\n }\n return 1;\n }\n return parseFloat(match[0]);\n}\n\nexport function parseStaticWidth(width: number | string, tableWidth: number): number {\n if (typeof width === 'string') {\n let match = width.match(/^(\\d+)(?=%$)/);\n if (!match) {\n throw new Error('Only percentages or numbers are supported for static column widths');\n }\n return tableWidth * (parseFloat(match[0]) / 100);\n }\n return width;\n}\n\nexport function getMaxWidth(\n maxWidth: number | string | null | undefined,\n tableWidth: number\n): number {\n return maxWidth != null ? parseStaticWidth(maxWidth, tableWidth) : Number.MAX_SAFE_INTEGER;\n}\n\n// cannot support FR units, we'd need to know everything else in the table to do that\nexport function getMinWidth(minWidth: number | string, tableWidth: number): number {\n return minWidth != null ? parseStaticWidth(minWidth, tableWidth) : 0;\n}\n\nexport interface IColumn {\n minWidth?: number | string;\n maxWidth?: number | string;\n width?: number | string;\n defaultWidth?: number | string;\n key: Key;\n}\n\ninterface FlexItem {\n frozen: boolean;\n baseSize: number;\n hypotheticalMainSize: number;\n min: number;\n max: number;\n flex: number;\n targetMainSize: number;\n violation: number;\n}\n\n/**\n * Implements the flex algorithm described in https://www.w3.org/TR/css-flexbox-1/#layout-algorithm\n * It makes a few constraint/assumptions: 1. All basis values are 0 unless it is a static width,\n * then the basis is the static width 2. All flex grow and shrink values are equal to the FR\n * specified on the column, grow and shrink for the same column are equal 3. We only have one row An\n * example of the setup can be seen here https://jsfiddle.net/snowystinger/wv0ymjaf/61/ where I let\n * the browser figure out the flex of the columns. Note: We differ in one key aspect, all of our\n * column widths must be whole numbers, so we avoid browser sub pixel rounding errors. To do this,\n * we use a cascading rounding algorithm to ensure that the sum of the widths is maintained while\n * distributing the rounding remainder across the columns.\n *\n * As noted in the chrome source code, this algorithm is very accurate, but has the potential to be\n * quadratic. They have deemed this to be acceptable because the number of elements is usually small\n * and the flex factors are usually not high variance. I believe we can make the same assumptions.\n * Particularly once resizing is started, it will convert all columns to the left to static widths,\n * so it will cut down on the number of FR columns.\n *\n * There are likely faster ways to do this, I've chosen to stick to the spec as closely as possible\n * for readability, accuracy, and for the note that this behaving quadratically is unlikely to be a\n * problem.\n *\n * @param availableWidth - The visible width of the table.\n * @param columns - The table defined columns.\n * @param changedColumns - Any columns we want to override, for example, during resizing.\n * @param getDefaultWidth - A function that returns the default width of a column by its index.\n * @param getDefaultMinWidth - A function that returns the default min width of a column by its\n * index.\n */\nexport function calculateColumnSizes(\n availableWidth: number,\n columns: IColumn[],\n changedColumns: Map<Key, ColumnSize>,\n getDefaultWidth?: (index: number) => ColumnSize | null | undefined,\n getDefaultMinWidth?: (index: number) => ColumnSize | null | undefined\n): number[] {\n let originalWidth = availableWidth;\n let flooredWidth = Math.floor(availableWidth);\n let hasFractionalWidth = availableWidth - flooredWidth > 0;\n availableWidth = flooredWidth;\n let hasNonFrozenItems = false;\n let flexItems: FlexItem[] = columns.map((column, index) => {\n let width: ColumnSize = (\n changedColumns.get(column.key) != null\n ? (changedColumns.get(column.key) ?? '1fr')\n : (column.width ?? column.defaultWidth ?? getDefaultWidth?.(index) ?? '1fr')\n ) as ColumnSize;\n let frozen = false;\n let baseSize = 0;\n let flex = 0;\n let targetMainSize = 0;\n if (isStatic(width)) {\n baseSize = parseStaticWidth(width, availableWidth);\n frozen = true;\n } else {\n flex = parseFractionalUnit(width);\n if (flex <= 0) {\n frozen = true;\n }\n }\n\n let min = getMinWidth(column.minWidth ?? getDefaultMinWidth?.(index) ?? 0, availableWidth);\n let max = getMaxWidth(column.maxWidth, availableWidth);\n let hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));\n\n // 9.7.1\n // We don't make use of flex basis, it's always 0, so we are always in 'grow' mode.\n // 9.7.2\n if (frozen) {\n targetMainSize = hypotheticalMainSize;\n } else if (baseSize > hypotheticalMainSize) {\n frozen = true;\n targetMainSize = hypotheticalMainSize;\n }\n\n // 9.7.3\n if (!frozen) {\n hasNonFrozenItems = true;\n }\n return {\n frozen,\n baseSize,\n hypotheticalMainSize,\n min,\n max,\n flex,\n targetMainSize,\n violation: 0\n };\n });\n\n // 9.7.4\n // 9.7.4.a\n while (hasNonFrozenItems) {\n // 9.7.4.b\n /**\n * Calculate the remaining free space as for initial free space,\n * above (9.7.3). If the sum of the unfrozen flex items’ flex factors is\n * less than one, multiply the initial free space by this sum (of flex factors).\n * If the magnitude of this value is less than the magnitude of\n * the remaining free space, use this as the remaining free space.\n */\n let usedWidth = 0;\n let flexFactors = 0;\n flexItems.forEach(item => {\n if (item.frozen) {\n usedWidth += item.targetMainSize;\n } else {\n usedWidth += item.baseSize;\n flexFactors += item.flex;\n }\n });\n\n let remainingFreeSpace = availableWidth - usedWidth;\n // we only support integer FR's, and because of hasNonFrozenItems, we know that flexFactors > 0\n // so no need to check for flexFactors < 1\n // 9.7.4.c\n /**\n * If the remaining free space is zero\n * - Do nothing.\n * Else // remember, we're always in grow mode\n * - Find the ratio of the item’s flex grow factor to the\n * sum of the flex grow factors of all unfrozen items on\n * the line. Set the item’s target main size to its flex\n * base size plus a fraction of the remaining free space\n * proportional to the ratio.\n */\n if (remainingFreeSpace > 0) {\n flexItems.forEach(item => {\n if (!item.frozen) {\n let ratio = item.flex / flexFactors;\n item.targetMainSize = item.baseSize + ratio * remainingFreeSpace;\n }\n });\n }\n\n // 9.7.4.d\n /**\n * Fix min/max violations. Clamp each non-frozen item’s\n * target main size by its used min and max main sizes\n * and floor its content-box size at zero. If the item’s\n * target main size was made smaller by this, it’s a max\n * violation. If the item’s target main size was made\n * larger by this, it’s a min violation.\n */\n let totalViolation = 0;\n flexItems.forEach(item => {\n item.violation = 0;\n if (!item.frozen) {\n let {min, max, targetMainSize} = item;\n item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));\n\n item.violation = item.targetMainSize - targetMainSize;\n totalViolation += item.violation;\n }\n });\n\n // 9.7.4.e\n /**\n * Freeze over-flexed items. The total violation is the\n * sum of the adjustments from the previous step\n * ∑(clamped size - unclamped size). If the total violation is:\n * Zero\n * - Freeze all items.\n *\n * Positive\n * - Freeze all the items with min violations.\n *\n * Negative\n * - Freeze all the items with max violations.\n */\n hasNonFrozenItems = false;\n flexItems.forEach(item => {\n if (totalViolation === 0 || Math.sign(totalViolation) === Math.sign(item.violation)) {\n item.frozen = true;\n } else if (!item.frozen) {\n hasNonFrozenItems = true;\n }\n });\n }\n\n let columnSizes = cascadeRounding(flexItems);\n\n // Give the leftover sub-pixel width to the last column so the columns sum\n // exactly to the (possibly fractional) available width.\n if (hasFractionalWidth && columnSizes.length > 0) {\n let tableFractionalWidth = originalWidth.toString().split('.')[1];\n let columnWidth = columnSizes[columnSizes.length - 1].toString();\n columnSizes[columnSizes.length - 1] = Number(columnWidth + '.' + tableFractionalWidth);\n }\n\n return columnSizes;\n}\n\nfunction cascadeRounding(flexItems: FlexItem[]): number[] {\n /*\n Given an array of floats that sum to an integer, this rounds the floats\n and returns an array of integers with the same sum.\n */\n\n let fpTotal = 0;\n let intTotal = 0;\n let roundedArray: number[] = [];\n flexItems.forEach(function (item) {\n let float = item.targetMainSize;\n let integer = Math.round(float + fpTotal) - intTotal;\n fpTotal += float;\n intTotal += integer;\n roundedArray.push(integer);\n });\n\n return roundedArray;\n}\n"],"names":[],"version":3,"file":"TableUtils.js.map"}
@@ -36,6 +36,10 @@ function $56195eeda89edca1$export$f556054ce4358701(minWidth, tableWidth) {
36
36
  return minWidth != null ? $56195eeda89edca1$export$7bbad27896f7ae9f(minWidth, tableWidth) : 0;
37
37
  }
38
38
  function $56195eeda89edca1$export$55d50dc687385491(availableWidth, columns, changedColumns, getDefaultWidth, getDefaultMinWidth) {
39
+ let originalWidth = availableWidth;
40
+ let flooredWidth = Math.floor(availableWidth);
41
+ let hasFractionalWidth = availableWidth - flooredWidth > 0;
42
+ availableWidth = flooredWidth;
39
43
  let hasNonFrozenItems = false;
40
44
  let flexItems = columns.map((column, index)=>{
41
45
  let width = changedColumns.get(column.key) != null ? changedColumns.get(column.key) ?? '1fr' : column.width ?? column.defaultWidth ?? getDefaultWidth?.(index) ?? '1fr';
@@ -149,7 +153,15 @@ function $56195eeda89edca1$export$55d50dc687385491(availableWidth, columns, chan
149
153
  else if (!item.frozen) hasNonFrozenItems = true;
150
154
  });
151
155
  }
152
- return $56195eeda89edca1$var$cascadeRounding(flexItems);
156
+ let columnSizes = $56195eeda89edca1$var$cascadeRounding(flexItems);
157
+ // Give the leftover sub-pixel width to the last column so the columns sum
158
+ // exactly to the (possibly fractional) available width.
159
+ if (hasFractionalWidth && columnSizes.length > 0) {
160
+ let tableFractionalWidth = originalWidth.toString().split('.')[1];
161
+ let columnWidth = columnSizes[columnSizes.length - 1].toString();
162
+ columnSizes[columnSizes.length - 1] = Number(columnWidth + '.' + tableFractionalWidth);
163
+ }
164
+ return columnSizes;
153
165
  }
154
166
  function $56195eeda89edca1$var$cascadeRounding(flexItems) {
155
167
  /*
@@ -1 +1 @@
1
- {"mappings":"AAAA;;;;;;;;;;CAUC,GAMM,SAAS,0CAAS,KAAyB;IAChD,OAAO,SAAS,QAAS,CAAA,CAAC,MAAM,UAAoB,OAAO,OAAO,KAAK,CAAC,oBAAoB,IAAG;AACjG;AAEO,SAAS,0CAAoB,KAAyB;IAC3D,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B,OAAO;IAET,IAAI,QAAQ,MAAM,KAAK,CAAC;IACxB,6DAA6D;IAC7D,IAAI,CAAC,OAAO;QACV,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,cAC3B,QAAQ,IAAI,CACV,CAAC,OAAO,EAAE,MAAM,6GAA6G,CAAC,EAC9H;QAGJ,OAAO;IACT;IACA,OAAO,WAAW,KAAK,CAAC,EAAE;AAC5B;AAEO,SAAS,0CAAiB,KAAsB,EAAE,UAAkB;IACzE,IAAI,OAAO,UAAU,UAAU;QAC7B,IAAI,QAAQ,MAAM,KAAK,CAAC;QACxB,IAAI,CAAC,OACH,MAAM,IAAI,MAAM;QAElB,OAAO,aAAc,CAAA,WAAW,KAAK,CAAC,EAAE,IAAI,GAAE;IAChD;IACA,OAAO;AACT;AAEO,SAAS,0CACd,QAA4C,EAC5C,UAAkB;IAElB,OAAO,YAAY,OAAO,0CAAiB,UAAU,cAAc,OAAO,gBAAgB;AAC5F;AAGO,SAAS,0CA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T","sources":["packages/react-stately/src/table/TableUtils.ts"],"sourcesContent":["/*\n * Copyright 2022 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 {ColumnSize} from './Column';\nimport {Key} from '@react-types/shared';\n\n// numbers and percents are considered static. *fr units or a lack of units are considered dynamic.\nexport function isStatic(width?: ColumnSize | null): boolean {\n return width != null && (!isNaN(width as number) || String(width).match(/^(\\d+)(?=%$)/) !== null);\n}\n\nexport function parseFractionalUnit(width?: ColumnSize | null): number {\n if (!width || typeof width === 'number') {\n return 1;\n }\n let match = width.match(/^(.+)(?=fr$)/);\n // if width is the incorrect format, just default it to a 1fr\n if (!match) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `width: ${width} is not a supported format, width should be a number (ex. 150), percentage (ex. '50%') or fr unit (ex. '2fr')`,\n \"defaulting to '1fr'\"\n );\n }\n return 1;\n }\n return parseFloat(match[0]);\n}\n\nexport function parseStaticWidth(width: number | string, tableWidth: number): number {\n if (typeof width === 'string') {\n let match = width.match(/^(\\d+)(?=%$)/);\n if (!match) {\n throw new Error('Only percentages or numbers are supported for static column widths');\n }\n return tableWidth * (parseFloat(match[0]) / 100);\n }\n return width;\n}\n\nexport function getMaxWidth(\n maxWidth: number | string | null | undefined,\n tableWidth: number\n): number {\n return maxWidth != null ? parseStaticWidth(maxWidth, tableWidth) : Number.MAX_SAFE_INTEGER;\n}\n\n// cannot support FR units, we'd need to know everything else in the table to do that\nexport function getMinWidth(minWidth: number | string, tableWidth: number): number {\n return minWidth != null ? parseStaticWidth(minWidth, tableWidth) : 0;\n}\n\nexport interface IColumn {\n minWidth?: number | string;\n maxWidth?: number | string;\n width?: number | string;\n defaultWidth?: number | string;\n key: Key;\n}\n\ninterface FlexItem {\n frozen: boolean;\n baseSize: number;\n hypotheticalMainSize: number;\n min: number;\n max: number;\n flex: number;\n targetMainSize: number;\n violation: number;\n}\n\n/**\n * Implements the flex algorithm described in https://www.w3.org/TR/css-flexbox-1/#layout-algorithm\n * It makes a few constraint/assumptions: 1. All basis values are 0 unless it is a static width,\n * then the basis is the static width 2. All flex grow and shrink values are equal to the FR\n * specified on the column, grow and shrink for the same column are equal 3. We only have one row An\n * example of the setup can be seen here https://jsfiddle.net/snowystinger/wv0ymjaf/61/ where I let\n * the browser figure out the flex of the columns. Note: We differ in one key aspect, all of our\n * column widths must be whole numbers, so we avoid browser sub pixel rounding errors. To do this,\n * we use a cascading rounding algorithm to ensure that the sum of the widths is maintained while\n * distributing the rounding remainder across the columns.\n *\n * As noted in the chrome source code, this algorithm is very accurate, but has the potential to be\n * quadratic. They have deemed this to be acceptable because the number of elements is usually small\n * and the flex factors are usually not high variance. I believe we can make the same assumptions.\n * Particularly once resizing is started, it will convert all columns to the left to static widths,\n * so it will cut down on the number of FR columns.\n *\n * There are likely faster ways to do this, I've chosen to stick to the spec as closely as possible\n * for readability, accuracy, and for the note that this behaving quadratically is unlikely to be a\n * problem.\n *\n * @param availableWidth - The visible width of the table.\n * @param columns - The table defined columns.\n * @param changedColumns - Any columns we want to override, for example, during resizing.\n * @param getDefaultWidth - A function that returns the default width of a column by its index.\n * @param getDefaultMinWidth - A function that returns the default min width of a column by its\n * index.\n */\nexport function calculateColumnSizes(\n availableWidth: number,\n columns: IColumn[],\n changedColumns: Map<Key, ColumnSize>,\n getDefaultWidth?: (index: number) => ColumnSize | null | undefined,\n getDefaultMinWidth?: (index: number) => ColumnSize | null | undefined\n): number[] {\n let hasNonFrozenItems = false;\n let flexItems: FlexItem[] = columns.map((column, index) => {\n let width: ColumnSize = (\n changedColumns.get(column.key) != null\n ? (changedColumns.get(column.key) ?? '1fr')\n : (column.width ?? column.defaultWidth ?? getDefaultWidth?.(index) ?? '1fr')\n ) as ColumnSize;\n let frozen = false;\n let baseSize = 0;\n let flex = 0;\n let targetMainSize = 0;\n if (isStatic(width)) {\n baseSize = parseStaticWidth(width, availableWidth);\n frozen = true;\n } else {\n flex = parseFractionalUnit(width);\n if (flex <= 0) {\n frozen = true;\n }\n }\n\n let min = getMinWidth(column.minWidth ?? getDefaultMinWidth?.(index) ?? 0, availableWidth);\n let max = getMaxWidth(column.maxWidth, availableWidth);\n let hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));\n\n // 9.7.1\n // We don't make use of flex basis, it's always 0, so we are always in 'grow' mode.\n // 9.7.2\n if (frozen) {\n targetMainSize = hypotheticalMainSize;\n } else if (baseSize > hypotheticalMainSize) {\n frozen = true;\n targetMainSize = hypotheticalMainSize;\n }\n\n // 9.7.3\n if (!frozen) {\n hasNonFrozenItems = true;\n }\n return {\n frozen,\n baseSize,\n hypotheticalMainSize,\n min,\n max,\n flex,\n targetMainSize,\n violation: 0\n };\n });\n\n // 9.7.4\n // 9.7.4.a\n while (hasNonFrozenItems) {\n // 9.7.4.b\n /**\n * Calculate the remaining free space as for initial free space,\n * above (9.7.3). If the sum of the unfrozen flex items’ flex factors is\n * less than one, multiply the initial free space by this sum (of flex factors).\n * If the magnitude of this value is less than the magnitude of\n * the remaining free space, use this as the remaining free space.\n */\n let usedWidth = 0;\n let flexFactors = 0;\n flexItems.forEach(item => {\n if (item.frozen) {\n usedWidth += item.targetMainSize;\n } else {\n usedWidth += item.baseSize;\n flexFactors += item.flex;\n }\n });\n\n let remainingFreeSpace = availableWidth - usedWidth;\n // we only support integer FR's, and because of hasNonFrozenItems, we know that flexFactors > 0\n // so no need to check for flexFactors < 1\n // 9.7.4.c\n /**\n * If the remaining free space is zero\n * - Do nothing.\n * Else // remember, we're always in grow mode\n * - Find the ratio of the item’s flex grow factor to the\n * sum of the flex grow factors of all unfrozen items on\n * the line. Set the item’s target main size to its flex\n * base size plus a fraction of the remaining free space\n * proportional to the ratio.\n */\n if (remainingFreeSpace > 0) {\n flexItems.forEach(item => {\n if (!item.frozen) {\n let ratio = item.flex / flexFactors;\n item.targetMainSize = item.baseSize + ratio * remainingFreeSpace;\n }\n });\n }\n\n // 9.7.4.d\n /**\n * Fix min/max violations. Clamp each non-frozen item’s\n * target main size by its used min and max main sizes\n * and floor its content-box size at zero. If the item’s\n * target main size was made smaller by this, it’s a max\n * violation. If the item’s target main size was made\n * larger by this, it’s a min violation.\n */\n let totalViolation = 0;\n flexItems.forEach(item => {\n item.violation = 0;\n if (!item.frozen) {\n let {min, max, targetMainSize} = item;\n item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));\n\n item.violation = item.targetMainSize - targetMainSize;\n totalViolation += item.violation;\n }\n });\n\n // 9.7.4.e\n /**\n * Freeze over-flexed items. The total violation is the\n * sum of the adjustments from the previous step\n * ∑(clamped size - unclamped size). If the total violation is:\n * Zero\n * - Freeze all items.\n *\n * Positive\n * - Freeze all the items with min violations.\n *\n * Negative\n * - Freeze all the items with max violations.\n */\n hasNonFrozenItems = false;\n flexItems.forEach(item => {\n if (totalViolation === 0 || Math.sign(totalViolation) === Math.sign(item.violation)) {\n item.frozen = true;\n } else if (!item.frozen) {\n hasNonFrozenItems = true;\n }\n });\n }\n\n return cascadeRounding(flexItems);\n}\n\nfunction cascadeRounding(flexItems: FlexItem[]): number[] {\n /*\n Given an array of floats that sum to an integer, this rounds the floats\n and returns an array of integers with the same sum.\n */\n\n let fpTotal = 0;\n let intTotal = 0;\n let roundedArray: number[] = [];\n flexItems.forEach(function (item) {\n let float = item.targetMainSize;\n let integer = Math.round(float + fpTotal) - intTotal;\n fpTotal += float;\n intTotal += integer;\n roundedArray.push(integer);\n });\n\n return roundedArray;\n}\n"],"names":[],"version":3,"file":"TableUtils.mjs.map"}
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAMM,SAAS,0CAAS,KAAyB;IAChD,OAAO,SAAS,QAAS,CAAA,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* 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 {ColumnSize} from './Column';\nimport {Key} from '@react-types/shared';\n\n// numbers and percents are considered static. *fr units or a lack of units are considered dynamic.\nexport function isStatic(width?: ColumnSize | null): boolean {\n return width != null && (!isNaN(width as number) || String(width).match(/^(\\d+)(?=%$)/) !== null);\n}\n\nexport function parseFractionalUnit(width?: ColumnSize | null): number {\n if (!width || typeof width === 'number') {\n return 1;\n }\n let match = width.match(/^(.+)(?=fr$)/);\n // if width is the incorrect format, just default it to a 1fr\n if (!match) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `width: ${width} is not a supported format, width should be a number (ex. 150), percentage (ex. '50%') or fr unit (ex. '2fr')`,\n \"defaulting to '1fr'\"\n );\n }\n return 1;\n }\n return parseFloat(match[0]);\n}\n\nexport function parseStaticWidth(width: number | string, tableWidth: number): number {\n if (typeof width === 'string') {\n let match = width.match(/^(\\d+)(?=%$)/);\n if (!match) {\n throw new Error('Only percentages or numbers are supported for static column widths');\n }\n return tableWidth * (parseFloat(match[0]) / 100);\n }\n return width;\n}\n\nexport function getMaxWidth(\n maxWidth: number | string | null | undefined,\n tableWidth: number\n): number {\n return maxWidth != null ? parseStaticWidth(maxWidth, tableWidth) : Number.MAX_SAFE_INTEGER;\n}\n\n// cannot support FR units, we'd need to know everything else in the table to do that\nexport function getMinWidth(minWidth: number | string, tableWidth: number): number {\n return minWidth != null ? parseStaticWidth(minWidth, tableWidth) : 0;\n}\n\nexport interface IColumn {\n minWidth?: number | string;\n maxWidth?: number | string;\n width?: number | string;\n defaultWidth?: number | string;\n key: Key;\n}\n\ninterface FlexItem {\n frozen: boolean;\n baseSize: number;\n hypotheticalMainSize: number;\n min: number;\n max: number;\n flex: number;\n targetMainSize: number;\n violation: number;\n}\n\n/**\n * Implements the flex algorithm described in https://www.w3.org/TR/css-flexbox-1/#layout-algorithm\n * It makes a few constraint/assumptions: 1. All basis values are 0 unless it is a static width,\n * then the basis is the static width 2. All flex grow and shrink values are equal to the FR\n * specified on the column, grow and shrink for the same column are equal 3. We only have one row An\n * example of the setup can be seen here https://jsfiddle.net/snowystinger/wv0ymjaf/61/ where I let\n * the browser figure out the flex of the columns. Note: We differ in one key aspect, all of our\n * column widths must be whole numbers, so we avoid browser sub pixel rounding errors. To do this,\n * we use a cascading rounding algorithm to ensure that the sum of the widths is maintained while\n * distributing the rounding remainder across the columns.\n *\n * As noted in the chrome source code, this algorithm is very accurate, but has the potential to be\n * quadratic. They have deemed this to be acceptable because the number of elements is usually small\n * and the flex factors are usually not high variance. I believe we can make the same assumptions.\n * Particularly once resizing is started, it will convert all columns to the left to static widths,\n * so it will cut down on the number of FR columns.\n *\n * There are likely faster ways to do this, I've chosen to stick to the spec as closely as possible\n * for readability, accuracy, and for the note that this behaving quadratically is unlikely to be a\n * problem.\n *\n * @param availableWidth - The visible width of the table.\n * @param columns - The table defined columns.\n * @param changedColumns - Any columns we want to override, for example, during resizing.\n * @param getDefaultWidth - A function that returns the default width of a column by its index.\n * @param getDefaultMinWidth - A function that returns the default min width of a column by its\n * index.\n */\nexport function calculateColumnSizes(\n availableWidth: number,\n columns: IColumn[],\n changedColumns: Map<Key, ColumnSize>,\n getDefaultWidth?: (index: number) => ColumnSize | null | undefined,\n getDefaultMinWidth?: (index: number) => ColumnSize | null | undefined\n): number[] {\n let originalWidth = availableWidth;\n let flooredWidth = Math.floor(availableWidth);\n let hasFractionalWidth = availableWidth - flooredWidth > 0;\n availableWidth = flooredWidth;\n let hasNonFrozenItems = false;\n let flexItems: FlexItem[] = columns.map((column, index) => {\n let width: ColumnSize = (\n changedColumns.get(column.key) != null\n ? (changedColumns.get(column.key) ?? '1fr')\n : (column.width ?? column.defaultWidth ?? getDefaultWidth?.(index) ?? '1fr')\n ) as ColumnSize;\n let frozen = false;\n let baseSize = 0;\n let flex = 0;\n let targetMainSize = 0;\n if (isStatic(width)) {\n baseSize = parseStaticWidth(width, availableWidth);\n frozen = true;\n } else {\n flex = parseFractionalUnit(width);\n if (flex <= 0) {\n frozen = true;\n }\n }\n\n let min = getMinWidth(column.minWidth ?? getDefaultMinWidth?.(index) ?? 0, availableWidth);\n let max = getMaxWidth(column.maxWidth, availableWidth);\n let hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));\n\n // 9.7.1\n // We don't make use of flex basis, it's always 0, so we are always in 'grow' mode.\n // 9.7.2\n if (frozen) {\n targetMainSize = hypotheticalMainSize;\n } else if (baseSize > hypotheticalMainSize) {\n frozen = true;\n targetMainSize = hypotheticalMainSize;\n }\n\n // 9.7.3\n if (!frozen) {\n hasNonFrozenItems = true;\n }\n return {\n frozen,\n baseSize,\n hypotheticalMainSize,\n min,\n max,\n flex,\n targetMainSize,\n violation: 0\n };\n });\n\n // 9.7.4\n // 9.7.4.a\n while (hasNonFrozenItems) {\n // 9.7.4.b\n /**\n * Calculate the remaining free space as for initial free space,\n * above (9.7.3). If the sum of the unfrozen flex items’ flex factors is\n * less than one, multiply the initial free space by this sum (of flex factors).\n * If the magnitude of this value is less than the magnitude of\n * the remaining free space, use this as the remaining free space.\n */\n let usedWidth = 0;\n let flexFactors = 0;\n flexItems.forEach(item => {\n if (item.frozen) {\n usedWidth += item.targetMainSize;\n } else {\n usedWidth += item.baseSize;\n flexFactors += item.flex;\n }\n });\n\n let remainingFreeSpace = availableWidth - usedWidth;\n // we only support integer FR's, and because of hasNonFrozenItems, we know that flexFactors > 0\n // so no need to check for flexFactors < 1\n // 9.7.4.c\n /**\n * If the remaining free space is zero\n * - Do nothing.\n * Else // remember, we're always in grow mode\n * - Find the ratio of the item’s flex grow factor to the\n * sum of the flex grow factors of all unfrozen items on\n * the line. Set the item’s target main size to its flex\n * base size plus a fraction of the remaining free space\n * proportional to the ratio.\n */\n if (remainingFreeSpace > 0) {\n flexItems.forEach(item => {\n if (!item.frozen) {\n let ratio = item.flex / flexFactors;\n item.targetMainSize = item.baseSize + ratio * remainingFreeSpace;\n }\n });\n }\n\n // 9.7.4.d\n /**\n * Fix min/max violations. Clamp each non-frozen item’s\n * target main size by its used min and max main sizes\n * and floor its content-box size at zero. If the item’s\n * target main size was made smaller by this, it’s a max\n * violation. If the item’s target main size was made\n * larger by this, it’s a min violation.\n */\n let totalViolation = 0;\n flexItems.forEach(item => {\n item.violation = 0;\n if (!item.frozen) {\n let {min, max, targetMainSize} = item;\n item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));\n\n item.violation = item.targetMainSize - targetMainSize;\n totalViolation += item.violation;\n }\n });\n\n // 9.7.4.e\n /**\n * Freeze over-flexed items. The total violation is the\n * sum of the adjustments from the previous step\n * ∑(clamped size - unclamped size). If the total violation is:\n * Zero\n * - Freeze all items.\n *\n * Positive\n * - Freeze all the items with min violations.\n *\n * Negative\n * - Freeze all the items with max violations.\n */\n hasNonFrozenItems = false;\n flexItems.forEach(item => {\n if (totalViolation === 0 || Math.sign(totalViolation) === Math.sign(item.violation)) {\n item.frozen = true;\n } else if (!item.frozen) {\n hasNonFrozenItems = true;\n }\n });\n }\n\n let columnSizes = cascadeRounding(flexItems);\n\n // Give the leftover sub-pixel width to the last column so the columns sum\n // exactly to the (possibly fractional) available width.\n if (hasFractionalWidth && columnSizes.length > 0) {\n let tableFractionalWidth = originalWidth.toString().split('.')[1];\n let columnWidth = columnSizes[columnSizes.length - 1].toString();\n columnSizes[columnSizes.length - 1] = Number(columnWidth + '.' + tableFractionalWidth);\n }\n\n return columnSizes;\n}\n\nfunction cascadeRounding(flexItems: FlexItem[]): number[] {\n /*\n Given an array of floats that sum to an integer, this rounds the floats\n and returns an array of integers with the same sum.\n */\n\n let fpTotal = 0;\n let intTotal = 0;\n let roundedArray: number[] = [];\n flexItems.forEach(function (item) {\n let float = item.targetMainSize;\n let integer = Math.round(float + fpTotal) - intTotal;\n fpTotal += float;\n intTotal += integer;\n roundedArray.push(integer);\n });\n\n return roundedArray;\n}\n"],"names":[],"version":3,"file":"TableUtils.mjs.map"}
@@ -39,6 +39,7 @@ function $7e461d6cedc2cde6$export$907bcc6c48325fd6(props) {
39
39
  selectionMode: selectionMode,
40
40
  columns: []
41
41
  }), // eslint-disable-next-line react-hooks/exhaustive-deps
42
+ // oxlint-disable-next-line react/react-compiler, react-hooks/exhaustive-deps
42
43
  [
43
44
  props.children,
44
45
  showSelectionCheckboxes,
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAgGD,MAAM,gDAA0B;IAC9B,WAAW;IACX,YAAY;AACd;AAMO,SAAS,0CAAgC,KAAyB;IACvE,IAAI,CAAC,8BAA8B,8BAA8B,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC7E,IAAI,iBAAC,gBAAgB,iCAAQ,uBAAuB,mBAAE,eAAe,cAAE,aAAa,MAAK,GAAG;IAE5F,IAAI,UAAU,CAAA,GAAA,oBAAM,EAClB,IAAO,CAAA;YACL,yBAAyB,2BAA2B,kBAAkB;YACtE,iBAAiB;2BACjB;YACA,SAAS,EAAE;QACb,CAAA,GACA,uDAAuD;IACvD;QAAC,MAAM,QAAQ;QAAE;QAAyB;QAAe;KAAgB;IAG3E,IAAI,aAAa,CAAA,GAAA,uCAAY,EAC3B,OACA,CAAA,GAAA,wBAAU,EAAE,CAAA,QAAS,IAAI,CAAA,GAAA,yCAAc,EAAE,OAAO,MAAM,UAAU;QAAC;KAAQ,GACzE;IAEF,IAAI,gBAAC,YAAY,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,sCAAW,EAAE;QAClD,GAAG,KAAK;oBACR;QACA,kBAAkB,MAAM,gBAAgB,IAAI;IAC9C;IAEA,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,4CAAiB,EACrD,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,WACnD,MAAM,mBAAmB,GAAG,IAAI,IAAI,MAAM,mBAAmB,IAAI,IAAI,OACrE,MAAM,gBAAgB;IAGxB,OAAO;oBACL;sBACA;0BACA;QACA,yBAAyB,MAAM,uBAAuB,IAAI;QAC1D,gBAAgB,MAAM,cAAc,IAAI;QACxC,8BAA8B,WAAW,IAAI,KAAK,KAAK;uCACvD;QACA,MAAK,SAAc,EAAE,SAAsC;YACzD,MAAM,YAAY,GAAG;gBACnB,QAAQ;gBACR,WACE,aACC,CAAA,MAAM,cAAc,EAAE,WAAW,YAC9B,6CAAuB,CAAC,MAAM,cAAc,CAAC,SAAS,CAAC,GACvD,WAAU;YAClB;QACF;sBACA;QACA,WAAU,GAAG;YACX,gBAAgB,CAAA;gBACd,IAAI,UAAU,IAAI,IAAI;gBACtB,IAAI,QAAQ,GAAG,CAAC,MACd,QAAQ,MAAM,CAAC;qBAEf,QAAQ,GAAG,CAAC;gBAGd,OAAO;YACT;QACF;oBACA;IACF;AACF;AAKO,SAAS,0CACd,KAAoB,EACpB,QAA4E;IAE5E,IAAI,aAAa,CAAA,GAAA,oBAAM,EACrB,IAAO,WAAW,MAAM,UAAU,CAAC,MAAM,CAAE,YAAY,MAAM,UAAU,EACvE;QAAC,MAAM,UAAU;QAAE;KAAS;IAE9B,IAAI,mBAAmB,MAAM,gBAAgB,CAAC,cAAc,CAAC;IAC7D,8DAA8D;IAE9D,OAAO;QACL,GAAG,KAAK;oBACR;0BACA;IACF;AACF","sources":["packages/react-stately/src/table/useTableState.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {\n Expandable,\n Key,\n MultipleSelection,\n Node,\n SelectionMode,\n Sortable,\n SortDescriptor,\n SortDirection\n} from '@react-types/shared';\nimport {GridState, useGridState} from '../grid/useGridState';\nimport {ITableCollection, TableCollection} from './TableCollection';\nimport {MultipleSelectionState} from '../selection/types';\nimport {MultipleSelectionStateProps} from '../selection/useMultipleSelectionState';\nimport {ReactElement, useCallback, useMemo, useState} from 'react';\nimport {TableBodyProps} from './TableBody';\nimport {TableHeaderProps} from './TableHeader';\nimport {useCollection} from '../collections/useCollection';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface TableProps<T> extends MultipleSelection, Sortable, Expandable {\n /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n children: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>];\n /** A list of row keys to disable. */\n disabledKeys?: Iterable<Key>;\n /**\n * Whether pressing the escape key should clear selection in the table or not.\n *\n * Most experiences should not modify this option as it eliminates a keyboard user's ability to\n * easily clear selection. Only use if the escape key is being handled externally or should not\n * trigger selection clearing contextually.\n *\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none';\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n /** The id of the column that displays hierarchical data. */\n treeColumn?: Key;\n}\n\nexport interface TableState<T> extends GridState<T, ITableCollection<T>> {\n /** A collection of rows and columns in the table. */\n collection: ITableCollection<T>;\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes: boolean;\n /** The current sorted column and direction. */\n sortDescriptor: SortDescriptor | null;\n /** Calls the provided onSortChange handler with the provided column key and sort direction. */\n sort(columnKey: Key, direction?: 'ascending' | 'descending'): void;\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 * Set whether keyboard navigation is disabled, such as when the arrow keys should be handled by a\n * component within a cell.\n */\n setKeyboardNavigationDisabled: (val: boolean) => void;\n /** A set of keys for items that are expanded. */\n expandedKeys: Set<Key>;\n /** Toggles the expanded state for a row by its key. */\n toggleKey(key: Key): void;\n /** The id of the column that displays hierarchical data. */\n treeColumn: Key | null;\n}\n\nexport interface CollectionBuilderContext<T> {\n showSelectionCheckboxes: boolean;\n showDragButtons: boolean;\n selectionMode: SelectionMode;\n columns: Node<T>[];\n}\n\nexport interface TableStateProps<T> extends MultipleSelectionStateProps, Expandable, Sortable {\n /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n children?: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>];\n /** A pre-constructed collection to use instead of building one from items and children. */\n collection?: ITableCollection<T>;\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes?: boolean;\n /**\n * Whether the row drag button should be displayed.\n *\n * @private\n */\n showDragButtons?: boolean;\n /** @private - Do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState;\n /** The id of the column that displays hierarchical data. */\n treeColumn?: Key;\n}\n\nconst OPPOSITE_SORT_DIRECTION = {\n ascending: 'descending' as SortDirection,\n descending: 'ascending' as SortDirection\n};\n\n/**\n * Provides state management for a table component. Handles building a collection of columns and\n * rows from props. In addition, it tracks row selection and manages sort order changes.\n */\nexport function useTableState<T extends object>(props: TableStateProps<T>): TableState<T> {\n let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = useState(false);\n let {selectionMode = 'none', showSelectionCheckboxes, showDragButtons, treeColumn = null} = props;\n\n let context = useMemo(\n () => ({\n showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n showDragButtons: showDragButtons,\n selectionMode,\n columns: []\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [props.children, showSelectionCheckboxes, selectionMode, showDragButtons]\n );\n\n let collection = useCollection<T, ITableCollection<T>>(\n props,\n useCallback(nodes => new TableCollection(nodes, null, context), [context]),\n context\n );\n let {disabledKeys, selectionManager} = useGridState({\n ...props,\n collection,\n disabledBehavior: props.disabledBehavior || 'selection'\n });\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n props.onExpandedChange\n );\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n showSelectionCheckboxes: props.showSelectionCheckboxes || false,\n sortDescriptor: props.sortDescriptor ?? null,\n isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,\n setKeyboardNavigationDisabled,\n sort(columnKey: Key, direction?: 'ascending' | 'descending') {\n props.onSortChange?.({\n column: columnKey,\n direction:\n direction ??\n (props.sortDescriptor?.column === columnKey\n ? OPPOSITE_SORT_DIRECTION[props.sortDescriptor.direction]\n : 'ascending')\n });\n },\n expandedKeys,\n toggleKey(key) {\n setExpandedKeys(keys => {\n let newKeys = new Set(keys);\n if (newKeys.has(key)) {\n newKeys.delete(key);\n } else {\n newKeys.add(key);\n }\n\n return newKeys;\n });\n },\n treeColumn\n };\n}\n\n/**\n * Filters a collection using the provided filter function and returns a new TableState.\n */\nexport function UNSTABLE_useFilteredTableState<T extends object>(\n state: TableState<T>,\n filterFn: ((nodeValue: string, node: Node<T>) => boolean) | null | undefined\n): TableState<T> {\n let collection = useMemo(\n () => (filterFn ? state.collection.filter!(filterFn) : state.collection),\n [state.collection, filterFn]\n ) as ITableCollection<T>;\n let selectionManager = state.selectionManager.withCollection(collection);\n // TODO: handle focus key reset? That logic is in useGridState\n\n return {\n ...state,\n collection,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useTableState.cjs.map"}
1
+ {"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAuGD,MAAM,gDAA0B;IAC9B,WAAW;IACX,YAAY;AACd;AAMO,SAAS,0CAAgC,KAAyB;IACvE,IAAI,CAAC,8BAA8B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IAAI,IAAI;gBACtB,IAAI,QAAQ,GAAG,CAAC,MACd,QAAQ,MAAM,CAAC;qBAEf,QAAQ,GAAG,CAAC;gBAGd,OAAO;YACT;QACF;oBACA;IACF;AACF;AAKO,SAAS,0CACd,KAAoB,EACpB,QAA4E;IAE5E,IAAI,aAAa,CAAA,GAAA,oBAAM,EACrB,IAAO,WAAW,MAAM,UAAU,CAAC,MAAM,CAAE,YAAY,MAAM,UAAU,EACvE;QAAC,MAAM,UAAU;QAAE;KAAS;IAE9B,IAAI,mBAAmB,MAAM,gBAAgB,CAAC,cAAc,CAAC;IAC7D,8DAA8D;IAE9D,OAAO;QACL,GAAG,KAAK;oBACR;0BACA;IACF;AACF","sources":["packages/react-stately/src/table/useTableState.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {\n Expandable,\n Key,\n MultipleSelection,\n Node,\n SelectionMode,\n Sortable,\n SortDescriptor,\n SortDirection\n} from '@react-types/shared';\nimport {GridState, useGridState} from '../grid/useGridState';\nimport {ITableCollection, TableCollection} from './TableCollection';\nimport {MultipleSelectionState} from '../selection/types';\nimport {MultipleSelectionStateProps} from '../selection/useMultipleSelectionState';\nimport {ReactElement, useCallback, useMemo, useState} from 'react';\nimport {TableBodyProps} from './TableBody';\nimport {TableHeaderProps} from './TableHeader';\nimport {useCollection} from '../collections/useCollection';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface TableProps<T> extends MultipleSelection, Sortable, Expandable {\n /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n children: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>];\n /** A list of row keys to disable. */\n disabledKeys?: Iterable<Key>;\n /**\n * Whether pressing the escape key should clear selection in the table or not.\n *\n * Most experiences should not modify this option as it eliminates a keyboard user's ability to\n * easily clear selection. Only use if the escape key is being handled externally or should not\n * trigger selection clearing contextually.\n *\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none';\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n /** The id of the column that displays hierarchical data. */\n treeColumn?: Key;\n /**\n * Whether keyboard navigation to focusable elements within the cells is\n * via the left/right arrow keys or the tab key.\n *\n * @default 'arrow'\n */\n keyboardNavigationBehavior?: 'arrow' | 'tab';\n}\n\nexport interface TableState<T> extends GridState<T, ITableCollection<T>> {\n /** A collection of rows and columns in the table. */\n collection: ITableCollection<T>;\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes: boolean;\n /** The current sorted column and direction. */\n sortDescriptor: SortDescriptor | null;\n /** Calls the provided onSortChange handler with the provided column key and sort direction. */\n sort(columnKey: Key, direction?: 'ascending' | 'descending'): void;\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 * Set whether keyboard navigation is disabled, such as when the arrow keys should be handled by a\n * component within a cell.\n */\n setKeyboardNavigationDisabled: (val: boolean) => void;\n /** A set of keys for items that are expanded. */\n expandedKeys: Set<Key>;\n /** Toggles the expanded state for a row by its key. */\n toggleKey(key: Key): void;\n /** The id of the column that displays hierarchical data. */\n treeColumn: Key | null;\n}\n\nexport interface CollectionBuilderContext<T> {\n showSelectionCheckboxes: boolean;\n showDragButtons: boolean;\n selectionMode: SelectionMode;\n columns: Node<T>[];\n}\n\nexport interface TableStateProps<T> extends MultipleSelectionStateProps, Expandable, Sortable {\n /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n children?: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>];\n /** A pre-constructed collection to use instead of building one from items and children. */\n collection?: ITableCollection<T>;\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes?: boolean;\n /**\n * Whether the row drag button should be displayed.\n *\n * @private\n */\n showDragButtons?: boolean;\n /** @private - Do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState;\n /** The id of the column that displays hierarchical data. */\n treeColumn?: Key;\n}\n\nconst OPPOSITE_SORT_DIRECTION = {\n ascending: 'descending' as SortDirection,\n descending: 'ascending' as SortDirection\n};\n\n/**\n * Provides state management for a table component. Handles building a collection of columns and\n * rows from props. In addition, it tracks row selection and manages sort order changes.\n */\nexport function useTableState<T extends object>(props: TableStateProps<T>): TableState<T> {\n let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = useState(false);\n let {selectionMode = 'none', showSelectionCheckboxes, showDragButtons, treeColumn = null} = props;\n\n let context = useMemo(\n () => ({\n showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n showDragButtons: showDragButtons,\n selectionMode,\n columns: []\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n // oxlint-disable-next-line react/react-compiler, react-hooks/exhaustive-deps\n [props.children, showSelectionCheckboxes, selectionMode, showDragButtons]\n );\n\n let collection = useCollection<T, ITableCollection<T>>(\n props,\n useCallback(nodes => new TableCollection(nodes, null, context), [context]),\n context\n );\n let {disabledKeys, selectionManager} = useGridState({\n ...props,\n collection,\n disabledBehavior: props.disabledBehavior || 'selection'\n });\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n props.onExpandedChange\n );\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n showSelectionCheckboxes: props.showSelectionCheckboxes || false,\n sortDescriptor: props.sortDescriptor ?? null,\n isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,\n setKeyboardNavigationDisabled,\n sort(columnKey: Key, direction?: 'ascending' | 'descending') {\n props.onSortChange?.({\n column: columnKey,\n direction:\n direction ??\n (props.sortDescriptor?.column === columnKey\n ? OPPOSITE_SORT_DIRECTION[props.sortDescriptor.direction]\n : 'ascending')\n });\n },\n expandedKeys,\n toggleKey(key) {\n setExpandedKeys(keys => {\n let newKeys = new Set(keys);\n if (newKeys.has(key)) {\n newKeys.delete(key);\n } else {\n newKeys.add(key);\n }\n\n return newKeys;\n });\n },\n treeColumn\n };\n}\n\n/**\n * Filters a collection using the provided filter function and returns a new TableState.\n */\nexport function UNSTABLE_useFilteredTableState<T extends object>(\n state: TableState<T>,\n filterFn: ((nodeValue: string, node: Node<T>) => boolean) | null | undefined\n): TableState<T> {\n let collection = useMemo(\n () => (filterFn ? state.collection.filter!(filterFn) : state.collection),\n [state.collection, filterFn]\n ) as ITableCollection<T>;\n let selectionManager = state.selectionManager.withCollection(collection);\n // TODO: handle focus key reset? That logic is in useGridState\n\n return {\n ...state,\n collection,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useTableState.cjs.map"}
@@ -32,6 +32,7 @@ function $d5cc3b32ccfc476f$export$907bcc6c48325fd6(props) {
32
32
  selectionMode: selectionMode,
33
33
  columns: []
34
34
  }), // eslint-disable-next-line react-hooks/exhaustive-deps
35
+ // oxlint-disable-next-line react/react-compiler, react-hooks/exhaustive-deps
35
36
  [
36
37
  props.children,
37
38
  showSelectionCheckboxes,
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAgGD,MAAM,gDAA0B;IAC9B,WAAW;IACX,YAAY;AACd;AAMO,SAAS,0CAAgC,KAAyB;IACvE,IAAI,CAAC,8BAA8B,8BAA8B,GAAG,CAAA,GAAA,eAAO,EAAE;IAC7E,IAAI,iBAAC,gBAAgB,iCAAQ,uBAAuB,mBAAE,eAAe,cAAE,aAAa,MAAK,GAAG;IAE5F,IAAI,UAAU,CAAA,GAAA,cAA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M,CAAC;qBAEf,QAAQ,GAAG,CAAC;gBAGd,OAAO;YACT;QACF;oBACA;IACF;AACF;AAKO,SAAS,0CACd,KAAoB,EACpB,QAA4E;IAE5E,IAAI,aAAa,CAAA,GAAA,cAAM,EACrB,IAAO,WAAW,MAAM,UAAU,CAAC,MAAM,CAAE,YAAY,MAAM,UAAU,EACvE;QAAC,MAAM,UAAU;QAAE;KAAS;IAE9B,IAAI,mBAAmB,MAAM,gBAAgB,CAAC,cAAc,CAAC;IAC7D,8DAA8D;IAE9D,OAAO;QACL,GAAG,KAAK;oBACR;0BACA;IACF;AACF","sources":["packages/react-stately/src/table/useTableState.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {\n Expandable,\n Key,\n MultipleSelection,\n Node,\n SelectionMode,\n Sortable,\n SortDescriptor,\n SortDirection\n} from '@react-types/shared';\nimport {GridState, useGridState} from '../grid/useGridState';\nimport {ITableCollection, TableCollection} from './TableCollection';\nimport {MultipleSelectionState} from '../selection/types';\nimport {MultipleSelectionStateProps} from '../selection/useMultipleSelectionState';\nimport {ReactElement, useCallback, useMemo, useState} from 'react';\nimport {TableBodyProps} from './TableBody';\nimport {TableHeaderProps} from './TableHeader';\nimport {useCollection} from '../collections/useCollection';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface TableProps<T> extends MultipleSelection, Sortable, Expandable {\n /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n children: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>];\n /** A list of row keys to disable. */\n disabledKeys?: Iterable<Key>;\n /**\n * Whether pressing the escape key should clear selection in the table or not.\n *\n * Most experiences should not modify this option as it eliminates a keyboard user's ability to\n * easily clear selection. Only use if the escape key is being handled externally or should not\n * trigger selection clearing contextually.\n *\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none';\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n /** The id of the column that displays hierarchical data. */\n treeColumn?: Key;\n}\n\nexport interface TableState<T> extends GridState<T, ITableCollection<T>> {\n /** A collection of rows and columns in the table. */\n collection: ITableCollection<T>;\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes: boolean;\n /** The current sorted column and direction. */\n sortDescriptor: SortDescriptor | null;\n /** Calls the provided onSortChange handler with the provided column key and sort direction. */\n sort(columnKey: Key, direction?: 'ascending' | 'descending'): void;\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 * Set whether keyboard navigation is disabled, such as when the arrow keys should be handled by a\n * component within a cell.\n */\n setKeyboardNavigationDisabled: (val: boolean) => void;\n /** A set of keys for items that are expanded. */\n expandedKeys: Set<Key>;\n /** Toggles the expanded state for a row by its key. */\n toggleKey(key: Key): void;\n /** The id of the column that displays hierarchical data. */\n treeColumn: Key | null;\n}\n\nexport interface CollectionBuilderContext<T> {\n showSelectionCheckboxes: boolean;\n showDragButtons: boolean;\n selectionMode: SelectionMode;\n columns: Node<T>[];\n}\n\nexport interface TableStateProps<T> extends MultipleSelectionStateProps, Expandable, Sortable {\n /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n children?: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>];\n /** A pre-constructed collection to use instead of building one from items and children. */\n collection?: ITableCollection<T>;\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes?: boolean;\n /**\n * Whether the row drag button should be displayed.\n *\n * @private\n */\n showDragButtons?: boolean;\n /** @private - Do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState;\n /** The id of the column that displays hierarchical data. */\n treeColumn?: Key;\n}\n\nconst OPPOSITE_SORT_DIRECTION = {\n ascending: 'descending' as SortDirection,\n descending: 'ascending' as SortDirection\n};\n\n/**\n * Provides state management for a table component. Handles building a collection of columns and\n * rows from props. In addition, it tracks row selection and manages sort order changes.\n */\nexport function useTableState<T extends object>(props: TableStateProps<T>): TableState<T> {\n let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = useState(false);\n let {selectionMode = 'none', showSelectionCheckboxes, showDragButtons, treeColumn = null} = props;\n\n let context = useMemo(\n () => ({\n showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n showDragButtons: showDragButtons,\n selectionMode,\n columns: []\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [props.children, showSelectionCheckboxes, selectionMode, showDragButtons]\n );\n\n let collection = useCollection<T, ITableCollection<T>>(\n props,\n useCallback(nodes => new TableCollection(nodes, null, context), [context]),\n context\n );\n let {disabledKeys, selectionManager} = useGridState({\n ...props,\n collection,\n disabledBehavior: props.disabledBehavior || 'selection'\n });\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n props.onExpandedChange\n );\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n showSelectionCheckboxes: props.showSelectionCheckboxes || false,\n sortDescriptor: props.sortDescriptor ?? null,\n isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,\n setKeyboardNavigationDisabled,\n sort(columnKey: Key, direction?: 'ascending' | 'descending') {\n props.onSortChange?.({\n column: columnKey,\n direction:\n direction ??\n (props.sortDescriptor?.column === columnKey\n ? OPPOSITE_SORT_DIRECTION[props.sortDescriptor.direction]\n : 'ascending')\n });\n },\n expandedKeys,\n toggleKey(key) {\n setExpandedKeys(keys => {\n let newKeys = new Set(keys);\n if (newKeys.has(key)) {\n newKeys.delete(key);\n } else {\n newKeys.add(key);\n }\n\n return newKeys;\n });\n },\n treeColumn\n };\n}\n\n/**\n * Filters a collection using the provided filter function and returns a new TableState.\n */\nexport function UNSTABLE_useFilteredTableState<T extends object>(\n state: TableState<T>,\n filterFn: ((nodeValue: string, node: Node<T>) => boolean) | null | undefined\n): TableState<T> {\n let collection = useMemo(\n () => (filterFn ? state.collection.filter!(filterFn) : state.collection),\n [state.collection, filterFn]\n ) as ITableCollection<T>;\n let selectionManager = state.selectionManager.withCollection(collection);\n // TODO: handle focus key reset? That logic is in useGridState\n\n return {\n ...state,\n collection,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useTableState.js.map"}
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAuGD,MAAM,gDAA0B;IAC9B,WAAW;IACX,YAAY;AACd;AAMO,SAAS,0CAAgC,KAAyB;IACvE,IAAI,CAAC,8BAA8B,8BAA8B,GAAG,CAAA,GAAA,eAAO,EAAE;IAC7E,IAAI,iBAAC,gBAAgB,iCAAQ,uBAAuB,mBAAE,eAAe,cAAE,aAAa,MAAK,GAAG;IAE5F,IAAI,UAAU,CAAA,GAAA,cAAM,EAClB,IAAO,CAAA;YACL,yBAAyB,2BAA2B,kBAAkB;YACtE,iBAAiB;2BACjB;YACA,SAAS,EAAE;QACb,CAAA,GACA,uDAAuD;IACvD,6EAA6E;IAC7E;QAAC,MAAM,QAAQ;QAAE;QAAyB;QAAe;KAAgB;IAG3E,IAAI,aAAa,CAAA,GAAA,yCAAY,EAC3B,OACA,CAAA,GAAA,kBAAU,EAAE,CAAA,QAAS,IAAI,CAAA,GAAA,yCAAc,EAAE,OAAO,MAAM,UAAU;QAAC;KAAQ,GACzE;IAEF,IAAI,gBAAC,YAAY,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,yCAAW,EAAE;QAClD,GAAG,KAAK;oBACR;QACA,kBAAkB,M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ights 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 {\n Expandable,\n Key,\n MultipleSelection,\n Node,\n SelectionMode,\n Sortable,\n SortDescriptor,\n SortDirection\n} from '@react-types/shared';\nimport {GridState, useGridState} from '../grid/useGridState';\nimport {ITableCollection, TableCollection} from './TableCollection';\nimport {MultipleSelectionState} from '../selection/types';\nimport {MultipleSelectionStateProps} from '../selection/useMultipleSelectionState';\nimport {ReactElement, useCallback, useMemo, useState} from 'react';\nimport {TableBodyProps} from './TableBody';\nimport {TableHeaderProps} from './TableHeader';\nimport {useCollection} from '../collections/useCollection';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface TableProps<T> extends MultipleSelection, Sortable, Expandable {\n /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n children: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>];\n /** A list of row keys to disable. */\n disabledKeys?: Iterable<Key>;\n /**\n * Whether pressing the escape key should clear selection in the table or not.\n *\n * Most experiences should not modify this option as it eliminates a keyboard user's ability to\n * easily clear selection. Only use if the escape key is being handled externally or should not\n * trigger selection clearing contextually.\n *\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none';\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n /** The id of the column that displays hierarchical data. */\n treeColumn?: Key;\n /**\n * Whether keyboard navigation to focusable elements within the cells is\n * via the left/right arrow keys or the tab key.\n *\n * @default 'arrow'\n */\n keyboardNavigationBehavior?: 'arrow' | 'tab';\n}\n\nexport interface TableState<T> extends GridState<T, ITableCollection<T>> {\n /** A collection of rows and columns in the table. */\n collection: ITableCollection<T>;\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes: boolean;\n /** The current sorted column and direction. */\n sortDescriptor: SortDescriptor | null;\n /** Calls the provided onSortChange handler with the provided column key and sort direction. */\n sort(columnKey: Key, direction?: 'ascending' | 'descending'): void;\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 * Set whether keyboard navigation is disabled, such as when the arrow keys should be handled by a\n * component within a cell.\n */\n setKeyboardNavigationDisabled: (val: boolean) => void;\n /** A set of keys for items that are expanded. */\n expandedKeys: Set<Key>;\n /** Toggles the expanded state for a row by its key. */\n toggleKey(key: Key): void;\n /** The id of the column that displays hierarchical data. */\n treeColumn: Key | null;\n}\n\nexport interface CollectionBuilderContext<T> {\n showSelectionCheckboxes: boolean;\n showDragButtons: boolean;\n selectionMode: SelectionMode;\n columns: Node<T>[];\n}\n\nexport interface TableStateProps<T> extends MultipleSelectionStateProps, Expandable, Sortable {\n /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n children?: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>];\n /** A pre-constructed collection to use instead of building one from items and children. */\n collection?: ITableCollection<T>;\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes?: boolean;\n /**\n * Whether the row drag button should be displayed.\n *\n * @private\n */\n showDragButtons?: boolean;\n /** @private - Do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState;\n /** The id of the column that displays hierarchical data. */\n treeColumn?: Key;\n}\n\nconst OPPOSITE_SORT_DIRECTION = {\n ascending: 'descending' as SortDirection,\n descending: 'ascending' as SortDirection\n};\n\n/**\n * Provides state management for a table component. Handles building a collection of columns and\n * rows from props. In addition, it tracks row selection and manages sort order changes.\n */\nexport function useTableState<T extends object>(props: TableStateProps<T>): TableState<T> {\n let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = useState(false);\n let {selectionMode = 'none', showSelectionCheckboxes, showDragButtons, treeColumn = null} = props;\n\n let context = useMemo(\n () => ({\n showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n showDragButtons: showDragButtons,\n selectionMode,\n columns: []\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n // oxlint-disable-next-line react/react-compiler, react-hooks/exhaustive-deps\n [props.children, showSelectionCheckboxes, selectionMode, showDragButtons]\n );\n\n let collection = useCollection<T, ITableCollection<T>>(\n props,\n useCallback(nodes => new TableCollection(nodes, null, context), [context]),\n context\n );\n let {disabledKeys, selectionManager} = useGridState({\n ...props,\n collection,\n disabledBehavior: props.disabledBehavior || 'selection'\n });\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n props.onExpandedChange\n );\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n showSelectionCheckboxes: props.showSelectionCheckboxes || false,\n sortDescriptor: props.sortDescriptor ?? null,\n isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,\n setKeyboardNavigationDisabled,\n sort(columnKey: Key, direction?: 'ascending' | 'descending') {\n props.onSortChange?.({\n column: columnKey,\n direction:\n direction ??\n (props.sortDescriptor?.column === columnKey\n ? OPPOSITE_SORT_DIRECTION[props.sortDescriptor.direction]\n : 'ascending')\n });\n },\n expandedKeys,\n toggleKey(key) {\n setExpandedKeys(keys => {\n let newKeys = new Set(keys);\n if (newKeys.has(key)) {\n newKeys.delete(key);\n } else {\n newKeys.add(key);\n }\n\n return newKeys;\n });\n },\n treeColumn\n };\n}\n\n/**\n * Filters a collection using the provided filter function and returns a new TableState.\n */\nexport function UNSTABLE_useFilteredTableState<T extends object>(\n state: TableState<T>,\n filterFn: ((nodeValue: string, node: Node<T>) => boolean) | null | undefined\n): TableState<T> {\n let collection = useMemo(\n () => (filterFn ? state.collection.filter!(filterFn) : state.collection),\n [state.collection, filterFn]\n ) as ITableCollection<T>;\n let selectionManager = state.selectionManager.withCollection(collection);\n // TODO: handle focus key reset? That logic is in useGridState\n\n return {\n ...state,\n collection,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useTableState.js.map"}
@@ -32,6 +32,7 @@ function $178a7f94e1b4b497$export$907bcc6c48325fd6(props) {
32
32
  selectionMode: selectionMode,
33
33
  columns: []
34
34
  }), // eslint-disable-next-line react-hooks/exhaustive-deps
35
+ // oxlint-disable-next-line react/react-compiler, react-hooks/exhaustive-deps
35
36
  [
36
37
  props.children,
37
38
  showSelectionCheckboxes,
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAgGD,MAAM,gDAA0B;IAC9B,WAAW;IACX,YAAY;AACd;AAMO,SAAS,0CAAgC,KAAyB;IACvE,IAAI,CAAC,8BAA8B,8BAA8B,GAAG,CAAA,GAAA,eAAO,EAAE;IAC7E,IAAI,iBAAC,gBAAgB,iCAAQ,uBAAuB,mBAAE,eAAe,cAAE,aAAa,MAAK,GAAG;IAE5F,IAAI,UAAU,CAAA,GAAA,cAAM,EAClB,IAAO,CAAA;YACL,yBAAyB,2BAA2B,kBAAkB;YACtE,iBAAiB;2BACjB;YACA,SAAS,EAAE;QACb,CAAA,GACA,uDAAuD;IACvD;QAAC,MAAM,QAAQ;QAAE;QAAyB;QAAe;KAAgB;IAG3E,IAAI,aAAa,CAAA,GAAA,yCAAY,EAC3B,OACA,CAAA,GAAA,kBAAU,EAAE,CAAA,QAAS,IAAI,CAAA,GAAA,yCAAc,EAAE,OAAO,MAAM,UAAU;QAAC;KAAQ,GACzE;IAEF,IAAI,gBAAC,YAAY,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,yCAAW,EAAE;QAClD,GAAG,KAAK;oBACR;QACA,kBAAkB,MAAM,gBAAgB,IAAI;IAC9C;IAEA,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,yCAAiB,EACrD,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,WACnD,MAAM,mBAAmB,GAAG,IAAI,IAAI,MAAM,mBAAmB,IAAI,IAAI,OACrE,MAAM,gBAAgB;IAGxB,OAAO;oBACL;sBACA;0BACA;QACA,yBAAyB,MAAM,uBAAuB,IAAI;QAC1D,gBAAgB,MAAM,cAAc,IAAI;QACxC,8BAA8B,WAAW,IAAI,KAAK,KAAK;uCACvD;QACA,MAAK,SAAc,EAAE,SAAsC;YACzD,MAAM,YAAY,GAAG;gBACnB,QAAQ;gBACR,WACE,aACC,CAAA,MAAM,cAAc,EAAE,WAAW,YAC9B,6CAAuB,CAAC,MAAM,cAAc,CAAC,SAAS,CAAC,GACvD,WAAU;YAClB;QACF;sBACA;QACA,WAAU,GAAG;YACX,gBAAgB,CAAA;gBACd,IAAI,UAAU,IAAI,IAAI;gBACtB,IAAI,QAAQ,GAAG,CAAC,MACd,QAAQ,MAAM,CAAC;qBAEf,QAAQ,GAAG,CAAC;gBAGd,OAAO;YACT;QACF;oBACA;IACF;AACF;AAKO,SAAS,0CACd,KAAoB,EACpB,QAA4E;IAE5E,IAAI,aAAa,CAAA,GAAA,cAAM,EACrB,IAAO,WAAW,MAAM,UAAU,CAAC,MAAM,CAAE,YAAY,MAAM,UAAU,EACvE;QAAC,MAAM,UAAU;QAAE;KAAS;IAE9B,IAAI,mBAAmB,MAAM,gBAAgB,CAAC,cAAc,CAAC;IAC7D,8DAA8D;IAE9D,OAAO;QACL,GAAG,KAAK;oBACR;0BACA;IACF;AACF","sources":["packages/react-stately/src/table/useTableState.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {\n Expandable,\n Key,\n MultipleSelection,\n Node,\n SelectionMode,\n Sortable,\n SortDescriptor,\n SortDirection\n} from '@react-types/shared';\nimport {GridState, useGridState} from '../grid/useGridState';\nimport {ITableCollection, TableCollection} from './TableCollection';\nimport {MultipleSelectionState} from '../selection/types';\nimport {MultipleSelectionStateProps} from '../selection/useMultipleSelectionState';\nimport {ReactElement, useCallback, useMemo, useState} from 'react';\nimport {TableBodyProps} from './TableBody';\nimport {TableHeaderProps} from './TableHeader';\nimport {useCollection} from '../collections/useCollection';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface TableProps<T> extends MultipleSelection, Sortable, Expandable {\n /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n children: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>];\n /** A list of row keys to disable. */\n disabledKeys?: Iterable<Key>;\n /**\n * Whether pressing the escape key should clear selection in the table or not.\n *\n * Most experiences should not modify this option as it eliminates a keyboard user's ability to\n * easily clear selection. Only use if the escape key is being handled externally or should not\n * trigger selection clearing contextually.\n *\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none';\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n /** The id of the column that displays hierarchical data. */\n treeColumn?: Key;\n}\n\nexport interface TableState<T> extends GridState<T, ITableCollection<T>> {\n /** A collection of rows and columns in the table. */\n collection: ITableCollection<T>;\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes: boolean;\n /** The current sorted column and direction. */\n sortDescriptor: SortDescriptor | null;\n /** Calls the provided onSortChange handler with the provided column key and sort direction. */\n sort(columnKey: Key, direction?: 'ascending' | 'descending'): void;\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 * Set whether keyboard navigation is disabled, such as when the arrow keys should be handled by a\n * component within a cell.\n */\n setKeyboardNavigationDisabled: (val: boolean) => void;\n /** A set of keys for items that are expanded. */\n expandedKeys: Set<Key>;\n /** Toggles the expanded state for a row by its key. */\n toggleKey(key: Key): void;\n /** The id of the column that displays hierarchical data. */\n treeColumn: Key | null;\n}\n\nexport interface CollectionBuilderContext<T> {\n showSelectionCheckboxes: boolean;\n showDragButtons: boolean;\n selectionMode: SelectionMode;\n columns: Node<T>[];\n}\n\nexport interface TableStateProps<T> extends MultipleSelectionStateProps, Expandable, Sortable {\n /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n children?: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>];\n /** A pre-constructed collection to use instead of building one from items and children. */\n collection?: ITableCollection<T>;\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes?: boolean;\n /**\n * Whether the row drag button should be displayed.\n *\n * @private\n */\n showDragButtons?: boolean;\n /** @private - Do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState;\n /** The id of the column that displays hierarchical data. */\n treeColumn?: Key;\n}\n\nconst OPPOSITE_SORT_DIRECTION = {\n ascending: 'descending' as SortDirection,\n descending: 'ascending' as SortDirection\n};\n\n/**\n * Provides state management for a table component. Handles building a collection of columns and\n * rows from props. In addition, it tracks row selection and manages sort order changes.\n */\nexport function useTableState<T extends object>(props: TableStateProps<T>): TableState<T> {\n let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = useState(false);\n let {selectionMode = 'none', showSelectionCheckboxes, showDragButtons, treeColumn = null} = props;\n\n let context = useMemo(\n () => ({\n showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n showDragButtons: showDragButtons,\n selectionMode,\n columns: []\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [props.children, showSelectionCheckboxes, selectionMode, showDragButtons]\n );\n\n let collection = useCollection<T, ITableCollection<T>>(\n props,\n useCallback(nodes => new TableCollection(nodes, null, context), [context]),\n context\n );\n let {disabledKeys, selectionManager} = useGridState({\n ...props,\n collection,\n disabledBehavior: props.disabledBehavior || 'selection'\n });\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n props.onExpandedChange\n );\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n showSelectionCheckboxes: props.showSelectionCheckboxes || false,\n sortDescriptor: props.sortDescriptor ?? null,\n isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,\n setKeyboardNavigationDisabled,\n sort(columnKey: Key, direction?: 'ascending' | 'descending') {\n props.onSortChange?.({\n column: columnKey,\n direction:\n direction ??\n (props.sortDescriptor?.column === columnKey\n ? OPPOSITE_SORT_DIRECTION[props.sortDescriptor.direction]\n : 'ascending')\n });\n },\n expandedKeys,\n toggleKey(key) {\n setExpandedKeys(keys => {\n let newKeys = new Set(keys);\n if (newKeys.has(key)) {\n newKeys.delete(key);\n } else {\n newKeys.add(key);\n }\n\n return newKeys;\n });\n },\n treeColumn\n };\n}\n\n/**\n * Filters a collection using the provided filter function and returns a new TableState.\n */\nexport function UNSTABLE_useFilteredTableState<T extends object>(\n state: TableState<T>,\n filterFn: ((nodeValue: string, node: Node<T>) => boolean) | null | undefined\n): TableState<T> {\n let collection = useMemo(\n () => (filterFn ? state.collection.filter!(filterFn) : state.collection),\n [state.collection, filterFn]\n ) as ITableCollection<T>;\n let selectionManager = state.selectionManager.withCollection(collection);\n // TODO: handle focus key reset? That logic is in useGridState\n\n return {\n ...state,\n collection,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useTableState.mjs.map"}
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAuGD,MAAM,gDAA0B;IAC9B,WAAW;IACX,YAAY;AACd;AAMO,SAAS,0CAAgC,KAAyB;IACvE,IAAI,CAAC,8BA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,IAAI,IAAI;gBACtB,IAAI,QAAQ,GAAG,CAAC,MACd,QAAQ,MAAM,CAAC;qBAEf,QAAQ,GAAG,CAAC;gBAGd,OAAO;YACT;QACF;oBACA;IACF;AACF;AAKO,SAAS,0CACd,KAAoB,EACpB,QAA4E;IAE5E,IAAI,aAAa,CAAA,GAAA,cAAM,EACrB,IAAO,WAAW,MAAM,UAAU,CAAC,MAAM,CAAE,YAAY,MAAM,UAAU,EACvE;QAAC,MAAM,UAAU;QAAE;KAAS;IAE9B,IAAI,mBAAmB,MAAM,gBAAgB,CAAC,cAAc,CAAC;IAC7D,8DAA8D;IAE9D,OAAO;QACL,GAAG,KAAK;oBACR;0BACA;IACF;AACF","sources":["packages/react-stately/src/table/useTableState.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {\n Expandable,\n Key,\n MultipleSelection,\n Node,\n SelectionMode,\n Sortable,\n SortDescriptor,\n SortDirection\n} from '@react-types/shared';\nimport {GridState, useGridState} from '../grid/useGridState';\nimport {ITableCollection, TableCollection} from './TableCollection';\nimport {MultipleSelectionState} from '../selection/types';\nimport {MultipleSelectionStateProps} from '../selection/useMultipleSelectionState';\nimport {ReactElement, useCallback, useMemo, useState} from 'react';\nimport {TableBodyProps} from './TableBody';\nimport {TableHeaderProps} from './TableHeader';\nimport {useCollection} from '../collections/useCollection';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface TableProps<T> extends MultipleSelection, Sortable, Expandable {\n /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n children: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>];\n /** A list of row keys to disable. */\n disabledKeys?: Iterable<Key>;\n /**\n * Whether pressing the escape key should clear selection in the table or not.\n *\n * Most experiences should not modify this option as it eliminates a keyboard user's ability to\n * easily clear selection. Only use if the escape key is being handled externally or should not\n * trigger selection clearing contextually.\n *\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none';\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n /** The id of the column that displays hierarchical data. */\n treeColumn?: Key;\n /**\n * Whether keyboard navigation to focusable elements within the cells is\n * via the left/right arrow keys or the tab key.\n *\n * @default 'arrow'\n */\n keyboardNavigationBehavior?: 'arrow' | 'tab';\n}\n\nexport interface TableState<T> extends GridState<T, ITableCollection<T>> {\n /** A collection of rows and columns in the table. */\n collection: ITableCollection<T>;\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes: boolean;\n /** The current sorted column and direction. */\n sortDescriptor: SortDescriptor | null;\n /** Calls the provided onSortChange handler with the provided column key and sort direction. */\n sort(columnKey: Key, direction?: 'ascending' | 'descending'): void;\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 * Set whether keyboard navigation is disabled, such as when the arrow keys should be handled by a\n * component within a cell.\n */\n setKeyboardNavigationDisabled: (val: boolean) => void;\n /** A set of keys for items that are expanded. */\n expandedKeys: Set<Key>;\n /** Toggles the expanded state for a row by its key. */\n toggleKey(key: Key): void;\n /** The id of the column that displays hierarchical data. */\n treeColumn: Key | null;\n}\n\nexport interface CollectionBuilderContext<T> {\n showSelectionCheckboxes: boolean;\n showDragButtons: boolean;\n selectionMode: SelectionMode;\n columns: Node<T>[];\n}\n\nexport interface TableStateProps<T> extends MultipleSelectionStateProps, Expandable, Sortable {\n /** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */\n children?: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>];\n /** A pre-constructed collection to use instead of building one from items and children. */\n collection?: ITableCollection<T>;\n /** Whether the row selection checkboxes should be displayed. */\n showSelectionCheckboxes?: boolean;\n /**\n * Whether the row drag button should be displayed.\n *\n * @private\n */\n showDragButtons?: boolean;\n /** @private - Do not use unless you know what you're doing. */\n UNSAFE_selectionState?: MultipleSelectionState;\n /** The id of the column that displays hierarchical data. */\n treeColumn?: Key;\n}\n\nconst OPPOSITE_SORT_DIRECTION = {\n ascending: 'descending' as SortDirection,\n descending: 'ascending' as SortDirection\n};\n\n/**\n * Provides state management for a table component. Handles building a collection of columns and\n * rows from props. In addition, it tracks row selection and manages sort order changes.\n */\nexport function useTableState<T extends object>(props: TableStateProps<T>): TableState<T> {\n let [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = useState(false);\n let {selectionMode = 'none', showSelectionCheckboxes, showDragButtons, treeColumn = null} = props;\n\n let context = useMemo(\n () => ({\n showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n showDragButtons: showDragButtons,\n selectionMode,\n columns: []\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n // oxlint-disable-next-line react/react-compiler, react-hooks/exhaustive-deps\n [props.children, showSelectionCheckboxes, selectionMode, showDragButtons]\n );\n\n let collection = useCollection<T, ITableCollection<T>>(\n props,\n useCallback(nodes => new TableCollection(nodes, null, context), [context]),\n context\n );\n let {disabledKeys, selectionManager} = useGridState({\n ...props,\n collection,\n disabledBehavior: props.disabledBehavior || 'selection'\n });\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n props.onExpandedChange\n );\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n showSelectionCheckboxes: props.showSelectionCheckboxes || false,\n sortDescriptor: props.sortDescriptor ?? null,\n isKeyboardNavigationDisabled: collection.size === 0 || isKeyboardNavigationDisabled,\n setKeyboardNavigationDisabled,\n sort(columnKey: Key, direction?: 'ascending' | 'descending') {\n props.onSortChange?.({\n column: columnKey,\n direction:\n direction ??\n (props.sortDescriptor?.column === columnKey\n ? OPPOSITE_SORT_DIRECTION[props.sortDescriptor.direction]\n : 'ascending')\n });\n },\n expandedKeys,\n toggleKey(key) {\n setExpandedKeys(keys => {\n let newKeys = new Set(keys);\n if (newKeys.has(key)) {\n newKeys.delete(key);\n } else {\n newKeys.add(key);\n }\n\n return newKeys;\n });\n },\n treeColumn\n };\n}\n\n/**\n * Filters a collection using the provided filter function and returns a new TableState.\n */\nexport function UNSTABLE_useFilteredTableState<T extends object>(\n state: TableState<T>,\n filterFn: ((nodeValue: string, node: Node<T>) => boolean) | null | undefined\n): TableState<T> {\n let collection = useMemo(\n () => (filterFn ? state.collection.filter!(filterFn) : state.collection),\n [state.collection, filterFn]\n ) as ITableCollection<T>;\n let selectionManager = state.selectionManager.withCollection(collection);\n // TODO: handle focus key reset? That logic is in useGridState\n\n return {\n ...state,\n collection,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useTableState.mjs.map"}