@12-apps/ui 6.12.1 → 6.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/dist/_internal/components/data-display/DataViews/DataViewsGrid.js +25 -25
  2. package/dist/_internal/components/data-display/DataViews/DataViewsTableBase.js +27 -27
  3. package/dist/_internal/components/data-display/DataViews/base-card.js +2 -2
  4. package/dist/_internal/components/data-display/DataViews/base-list-card-geometry.js +5 -5
  5. package/dist/_internal/components/data-display/DataViews/base-list-card-slots.js +4 -4
  6. package/dist/_internal/components/data-display/DataViews/base-list-card.js +6 -6
  7. package/dist/_internal/components/data-display/DataViews/data-views-category-pill.js +11 -11
  8. package/dist/_internal/components/data-display/DataViews/data-views-display-panel.js +4 -4
  9. package/dist/_internal/components/data-display/DataViews/data-views-display-tabs.js +3 -3
  10. package/dist/_internal/components/data-display/DataViews/data-views-filter-panel.js +12 -12
  11. package/dist/_internal/components/data-display/DataViews/data-views-grid-bodies.js +4 -4
  12. package/dist/_internal/components/data-display/DataViews/data-views-grid-parts.js +23 -23
  13. package/dist/_internal/components/data-display/DataViews/data-views-inline-bar.js +12 -12
  14. package/dist/_internal/components/data-display/DataViews/data-views-layout-context.js +2 -2
  15. package/dist/_internal/components/data-display/DataViews/data-views-scope-tabs.js +3 -3
  16. package/dist/_internal/components/data-display/DataViews/data-views-shell-toolbar.js +6 -6
  17. package/dist/_internal/components/data-display/DataViews/data-views-toolbar.js +5 -5
  18. package/dist/_internal/components/data-display/DataViews/data-views-types.js +1 -1
  19. package/dist/_internal/components/data-display/DataViews/list-card-rails.js +3 -3
  20. package/dist/_internal/components/data-display/DataViews/use-data-views-state.js +2 -2
  21. package/dist/_internal/components/data-display/DataViews/use-saved-views-controller.js +2 -2
  22. package/dist/_internal/components/form/CategorySelect/CategoryPanel.js +5 -5
  23. package/dist/_internal/components/form/CategorySelect/CategoryPanelList.js +3 -3
  24. package/dist/_internal/components/form/CategorySelect/CategoryQuickActions.js +2 -2
  25. package/dist/_internal/components/form/CategorySelect/CategoryRows.js +2 -2
  26. package/dist/_internal/components/form/CategorySelect/CategorySelect.js +10 -10
  27. package/dist/_internal/components/form/CategorySelect/category-keyboard.js +2 -1
  28. package/dist/_internal/components/form/CategorySelect/category-tree.js +3 -1
  29. package/dist/_internal/components/form/CategorySelect/useCategoryCommit.js +2 -1
  30. package/dist/_internal/components/form/CategorySelect/useCategoryKeyHandler.js +3 -2
  31. package/dist/_internal/components/form/CategorySelect/useCategorySelect.js +2 -2
  32. package/dist/_internal/components/form/total-form/Fields/CategoryField.js +11 -11
  33. package/dist/_internal/components/form/total-form/Fields/index.js +12 -12
  34. package/dist/{chunk-HQBXB5QB.js → chunk-2GB5CIN6.js} +2 -2
  35. package/dist/{chunk-6UGRH32J.js → chunk-4KSOSI3U.js} +4 -4
  36. package/dist/{chunk-IKBQ7CS2.js → chunk-56SMIHWE.js} +2 -2
  37. package/dist/{chunk-LWYXMCX6.js → chunk-5ZZPQ3MT.js} +4 -4
  38. package/dist/{chunk-ZBYWGL5G.js → chunk-6U7NA74A.js} +2 -2
  39. package/dist/{chunk-XQZOMXP3.js → chunk-AWTERXCW.js} +2 -2
  40. package/dist/{chunk-JIEEUHNS.js → chunk-AZSFIQIA.js} +8 -8
  41. package/dist/{chunk-TY6CTYCF.js → chunk-BV5XTGKB.js} +3 -3
  42. package/dist/chunk-BV5XTGKB.js.map +1 -0
  43. package/dist/{chunk-5F4NIRVF.js → chunk-CKZFYGBY.js} +10 -6
  44. package/dist/chunk-CKZFYGBY.js.map +1 -0
  45. package/dist/{chunk-T4JGNZAR.js → chunk-CZPU5TW3.js} +2 -2
  46. package/dist/{chunk-S6T722WH.js → chunk-DEOC5OI7.js} +3 -3
  47. package/dist/{chunk-KWUQZDPL.js → chunk-ECIGNYSI.js} +3 -2
  48. package/dist/chunk-ECIGNYSI.js.map +1 -0
  49. package/dist/{chunk-Q5GXVDXL.js → chunk-EICVL6GS.js} +2 -2
  50. package/dist/{chunk-USBTXEBG.js → chunk-HGBZZDP6.js} +2 -2
  51. package/dist/{chunk-6IAQGSXD.js → chunk-HR7YTBR7.js} +2 -2
  52. package/dist/{chunk-NXTKZSMT.js → chunk-IN642YHK.js} +2 -2
  53. package/dist/{chunk-QBJVRPTF.js → chunk-ISH42UC7.js} +2 -2
  54. package/dist/{chunk-AGKQBS4C.js → chunk-JKLWHENB.js} +3 -3
  55. package/dist/{chunk-SVXSBLVD.js → chunk-KEDI6IRA.js} +2 -2
  56. package/dist/{chunk-C6ATAHBX.js → chunk-LHHAYZ55.js} +1 -1
  57. package/dist/chunk-LHHAYZ55.js.map +1 -0
  58. package/dist/{chunk-Z5E2PXGN.js → chunk-LPYB4Y7C.js} +49 -16
  59. package/dist/chunk-LPYB4Y7C.js.map +1 -0
  60. package/dist/{chunk-DVTCZR3K.js → chunk-LR6MSKTT.js} +7 -5
  61. package/dist/chunk-LR6MSKTT.js.map +1 -0
  62. package/dist/{chunk-CY5X3HNQ.js → chunk-OGGHD64H.js} +2 -2
  63. package/dist/{chunk-QFHUWD3C.js → chunk-QQE2PVLO.js} +3 -3
  64. package/dist/{chunk-N7SBWD2V.js → chunk-RDYBS45D.js} +4 -4
  65. package/dist/{chunk-F6FT2LIR.js → chunk-SCGVB7DS.js} +2 -2
  66. package/dist/{chunk-TDSRBCBG.js → chunk-T4BFDZGU.js} +9 -8
  67. package/dist/chunk-T4BFDZGU.js.map +1 -0
  68. package/dist/{chunk-T6V3DKJ5.js → chunk-WLCVOQCJ.js} +2 -2
  69. package/dist/{chunk-GCC66ZSD.js → chunk-WWM2YTW4.js} +29 -13
  70. package/dist/chunk-WWM2YTW4.js.map +1 -0
  71. package/dist/{chunk-GQTBWJYK.js → chunk-WXBBWSNU.js} +2 -2
  72. package/dist/{chunk-VN6Z6F7R.js → chunk-ZAB65STX.js} +11 -6
  73. package/dist/chunk-ZAB65STX.js.map +1 -0
  74. package/dist/{chunk-HVIB6WMD.js → chunk-ZPIMPOHV.js} +2 -2
  75. package/dist/{chunk-E3IPN3KN.js → chunk-ZUIJ3N7N.js} +2 -2
  76. package/dist/data-display/DataViews.js +31 -31
  77. package/dist/form/CategorySelect.js +10 -10
  78. package/dist/form/total-form.js +12 -12
  79. package/dist/types/components/data-display/DataViews/data-views-category-pill.d.ts +6 -0
  80. package/dist/types/components/data-display/DataViews/data-views-category-pill.d.ts.map +1 -1
  81. package/dist/types/components/data-display/DataViews/data-views-grid-parts.d.ts.map +1 -1
  82. package/dist/types/components/data-display/DataViews/data-views-types.d.ts +21 -0
  83. package/dist/types/components/data-display/DataViews/data-views-types.d.ts.map +1 -1
  84. package/dist/types/components/data-display/DataViews/use-data-views-state.d.ts +10 -2
  85. package/dist/types/components/data-display/DataViews/use-data-views-state.d.ts.map +1 -1
  86. package/dist/types/components/form/CategorySelect/CategoryPanelList.d.ts.map +1 -1
  87. package/dist/types/components/form/CategorySelect/CategoryRows.d.ts +8 -2
  88. package/dist/types/components/form/CategorySelect/CategoryRows.d.ts.map +1 -1
  89. package/dist/types/components/form/CategorySelect/category-keyboard.d.ts +1 -1
  90. package/dist/types/components/form/CategorySelect/category-keyboard.d.ts.map +1 -1
  91. package/dist/types/components/form/CategorySelect/category-tree.d.ts +12 -0
  92. package/dist/types/components/form/CategorySelect/category-tree.d.ts.map +1 -1
  93. package/dist/types/components/form/CategorySelect/useCategoryCommit.d.ts.map +1 -1
  94. package/package.json +1 -1
  95. package/src/components/data-display/DataViews/data-views-category-pill.tsx +7 -0
  96. package/src/components/data-display/DataViews/data-views-grid-parts.tsx +2 -1
  97. package/src/components/data-display/DataViews/data-views-types.ts +24 -0
  98. package/src/components/data-display/DataViews/use-data-views-state.ts +13 -3
  99. package/src/components/form/CategorySelect/CategoryPanelList.tsx +9 -5
  100. package/src/components/form/CategorySelect/CategoryRows.tsx +64 -23
  101. package/src/components/form/CategorySelect/CategorySelect.md +33 -6
  102. package/src/components/form/CategorySelect/category-keyboard.ts +34 -15
  103. package/src/components/form/CategorySelect/category-tree.ts +17 -8
  104. package/src/components/form/CategorySelect/useCategoryCommit.ts +10 -6
  105. package/dist/chunk-5F4NIRVF.js.map +0 -1
  106. package/dist/chunk-C6ATAHBX.js.map +0 -1
  107. package/dist/chunk-DVTCZR3K.js.map +0 -1
  108. package/dist/chunk-GCC66ZSD.js.map +0 -1
  109. package/dist/chunk-KWUQZDPL.js.map +0 -1
  110. package/dist/chunk-TDSRBCBG.js.map +0 -1
  111. package/dist/chunk-TY6CTYCF.js.map +0 -1
  112. package/dist/chunk-VN6Z6F7R.js.map +0 -1
  113. package/dist/chunk-Z5E2PXGN.js.map +0 -1
  114. /package/dist/{chunk-HQBXB5QB.js.map → chunk-2GB5CIN6.js.map} +0 -0
  115. /package/dist/{chunk-6UGRH32J.js.map → chunk-4KSOSI3U.js.map} +0 -0
  116. /package/dist/{chunk-IKBQ7CS2.js.map → chunk-56SMIHWE.js.map} +0 -0
  117. /package/dist/{chunk-LWYXMCX6.js.map → chunk-5ZZPQ3MT.js.map} +0 -0
  118. /package/dist/{chunk-ZBYWGL5G.js.map → chunk-6U7NA74A.js.map} +0 -0
  119. /package/dist/{chunk-XQZOMXP3.js.map → chunk-AWTERXCW.js.map} +0 -0
  120. /package/dist/{chunk-JIEEUHNS.js.map → chunk-AZSFIQIA.js.map} +0 -0
  121. /package/dist/{chunk-T4JGNZAR.js.map → chunk-CZPU5TW3.js.map} +0 -0
  122. /package/dist/{chunk-S6T722WH.js.map → chunk-DEOC5OI7.js.map} +0 -0
  123. /package/dist/{chunk-Q5GXVDXL.js.map → chunk-EICVL6GS.js.map} +0 -0
  124. /package/dist/{chunk-USBTXEBG.js.map → chunk-HGBZZDP6.js.map} +0 -0
  125. /package/dist/{chunk-6IAQGSXD.js.map → chunk-HR7YTBR7.js.map} +0 -0
  126. /package/dist/{chunk-NXTKZSMT.js.map → chunk-IN642YHK.js.map} +0 -0
  127. /package/dist/{chunk-QBJVRPTF.js.map → chunk-ISH42UC7.js.map} +0 -0
  128. /package/dist/{chunk-AGKQBS4C.js.map → chunk-JKLWHENB.js.map} +0 -0
  129. /package/dist/{chunk-SVXSBLVD.js.map → chunk-KEDI6IRA.js.map} +0 -0
  130. /package/dist/{chunk-CY5X3HNQ.js.map → chunk-OGGHD64H.js.map} +0 -0
  131. /package/dist/{chunk-QFHUWD3C.js.map → chunk-QQE2PVLO.js.map} +0 -0
  132. /package/dist/{chunk-N7SBWD2V.js.map → chunk-RDYBS45D.js.map} +0 -0
  133. /package/dist/{chunk-F6FT2LIR.js.map → chunk-SCGVB7DS.js.map} +0 -0
  134. /package/dist/{chunk-T6V3DKJ5.js.map → chunk-WLCVOQCJ.js.map} +0 -0
  135. /package/dist/{chunk-GQTBWJYK.js.map → chunk-WXBBWSNU.js.map} +0 -0
  136. /package/dist/{chunk-HVIB6WMD.js.map → chunk-ZPIMPOHV.js.map} +0 -0
  137. /package/dist/{chunk-E3IPN3KN.js.map → chunk-ZUIJ3N7N.js.map} +0 -0
@@ -16,6 +16,18 @@ export declare function foldText(text: string): string;
16
16
  * was filtered out of the payload, or because the tree is deeper than two levels.
17
17
  */
18
18
  export declare function buildCategoryGroups(options: CategorySelectOption[]): CategoryGroup[];
19
+ /**
20
+ * Whether this category IS the leaf, because nothing sits under it.
21
+ *
22
+ * The leaf-only default makes a category a heading and the subcategory the thing
23
+ * you pick — but a childless category has no subcategory to offer instead, so
24
+ * that reading leaves it unpickable and the row does nothing at all. It is the
25
+ * leaf, so it is selectable in its own right, whatever `allowParentSelection`
26
+ * says. Everything below already agreed; only the rows and the activation did
27
+ * not, which is what made a childless category unselectable on the estoque
28
+ * filter while `Marcar tudo` could still select it.
29
+ */
30
+ export declare function isLeafCategory(group: CategoryGroup): boolean;
19
31
  /** Every selectable leaf id across all groups, in display order. */
20
32
  export declare function collectLeafIds(groups: CategoryGroup[]): string[];
21
33
  /** The leaves a category stands for — its subcategories, or itself when childless. */
@@ -1 +1 @@
1
- {"version":3,"file":"category-tree.d.ts","sourceRoot":"","sources":["../../../../../src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CAAC,MAAM,CAAC,CASb;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,EAAE,CAU5F;AAED,yEAAyE;AACzE,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAUjF;AAED,mFAAmF;AACnF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,GAAG,aAAa,CAAC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,2EAA2E;AAC3E,wBAAgB,WAAW,CACzB,MAAM,EAAE,aAAa,EAAE,EACvB,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,GAC1C,cAAc,EAAE,CAelB"}
1
+ {"version":3,"file":"category-tree.d.ts","sourceRoot":"","sources":["../../../../../src/components/form/CategorySelect/category-tree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK7C;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,aAAa,EAAE,CAmBpF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAE5D;AAED,oEAAoE;AACpE,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,EAAE,CAEhE;AAED,sFAAsF;AACtF,wBAAgB,QAAQ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Aa,CAAC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,2EAA2E;AAC3E,wBAAgB,WAAW,CACzB,MAAM,EAAE,aAAa,EAAE,EACvB,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,GAC1C,cAAc,EAAE,CAelB"}
@@ -1 +1 @@
1
- {"version":3,"file":"useCategoryCommit.d.ts","sourceRoot":"","sources":["../../../../../src/components/form/CategorySelect/useCategoryCommit.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACjF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,kEAAkE;AAClE,MAAM,WAAW,eAAe;IAC9B,gEAAgE;IAChE,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,+CAA+C;IAC/C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3B,gEAAgE;IAChE,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,oEAAoE;IACpE,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,gBAAgB,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACjD,mBAAmB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3C;AAED,UAAU,qBAAqB;IAC7B,KAAK,EAAE,mBAAmB,CAAC;IAC3B,KAAK,EAAE,mBAAmB,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,oBAAoB,EAAE,OAAO,CAAC;CAC/B;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,KAAK,EACL,MAAM,EACN,oBAAoB,GACrB,EAAE,qBAAqB,GAAG,eAAe,CAgEzC"}
1
+ {"version":3,"file":"useCategoryCommit.d.ts","sourceRoot":"","sources":["../../../../../src/components/form/CategorySelect/useCategoryCommit.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACjF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,kEAAkE;AAClE,MAAM,WAAW,eAAe;IAC9B,gEAAgE;IAChE,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,+CAA+C;IAC/C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3B,gEAAgE;IAChE,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,oEAAoE;IACpE,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,gBAAgB,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACjD,mBAAmB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3C;AAED,UAAU,qBAAqB;IAC7B,KAAK,EAAE,mBAAmB,CAAC;IAC3B,KAAK,EAAE,mBAAmB,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,oBAAoB,EAAE,OAAO,CAAC;CAC/B;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,KAAK,EACL,MAAM,EACN,oBAAoB,GACrB,EAAE,qBAAqB,GAAG,eAAe,CAmEzC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@12-apps/ui",
3
- "version": "6.12.1",
3
+ "version": "6.13.1",
4
4
  "license": "MIT",
5
5
  "packageManager": "pnpm@10.34.5",
6
6
  "type": "module",
@@ -55,6 +55,12 @@ interface PillControlProps<T extends Record<string, unknown>> {
55
55
  * A category set nests, and flattening it into one list is what made "Massas"
56
56
  * (mercearia) indistinguishable from "Massas" (pratos principais). `control:
57
57
  * "category"` opts a field into the tree, which shows each hit under its parent.
58
+ *
59
+ * {@link FilterFieldConfig.allowParentSelection} decides whether a parent row is
60
+ * itself tickable. It is forwarded rather than fixed here because it is a
61
+ * per-SCREEN question: a filter over a catalogue where products sit on leaves
62
+ * wants "the whole category" as one click, while one whose parents are pure
63
+ * grouping would only offer a tick that means nothing.
58
64
  */
59
65
  export function PillControl<T extends Record<string, unknown>>({
60
66
  fieldId,
@@ -76,6 +82,7 @@ export function PillControl<T extends Record<string, unknown>>({
76
82
  label={layout === "stacked" ? pill.label : undefined}
77
83
  fullWidth={layout === "stacked"}
78
84
  options={pill.options.map(toCategoryOption)}
85
+ allowParentSelection={pill.allowParentSelection ?? false}
79
86
  value={selected}
80
87
  onChange={(next) => emitPillDiff(fieldId, selected, next, onTogglePill)}
81
88
  dataTestId={testId}
@@ -200,8 +200,9 @@ function useGridShellFilters<T extends Record<string, unknown>>({
200
200
  pills: state.pills,
201
201
  ranges: c.ranges,
202
202
  onSearchChange: (value) => c.patch({ search: value }),
203
+ // Updater, never the render's `state` — see {@link DataViewStatePatch}.
203
204
  onTogglePill: (fieldId, value, checked) =>
204
- c.patch({ pills: { ...state.pills, [fieldId]: togglePillValues(state.pills[fieldId], value, checked) } }),
205
+ c.patch(({ pills }) => ({ pills: { ...pills, [fieldId]: togglePillValues(pills[fieldId], value, checked) } })),
205
206
  onChangeRange: (fieldId, range) => c.patch({ ranges: { ...c.ranges, [fieldId]: range } }),
206
207
  onClearField: (fieldId) => c.patch({ pills: { ...state.pills, [fieldId]: [] } }),
207
208
  onClearAll: () => c.patch({ search: "", pills: {}, ranges: {} }),
@@ -109,6 +109,19 @@ export interface FilterFieldConfig<T extends Record<string, unknown>> {
109
109
  * one indistinguishable list.
110
110
  */
111
111
  control?: "checkboxes" | "multiselect" | "category";
112
+ /**
113
+ * Lets a `control: "category"` pill select a PARENT category, not just its
114
+ * children. Off by default, which keeps the leaf-only reading: the parent is
115
+ * a heading and its subcategories are the rows you tick.
116
+ *
117
+ * Turn it on where "the whole category" is a filter a user would reach for —
118
+ * selecting a parent then selects every subcategory under it, and the chip
119
+ * tray collapses that back to one chip bearing the category's name.
120
+ *
121
+ * A category with NO children is selectable either way: it is itself the
122
+ * leaf, so the flag has nothing to gate there.
123
+ */
124
+ allowParentSelection?: boolean;
112
125
  /**
113
126
  * Forces this filter to render as a searchable multi-select dropdown with the
114
127
  * search box always shown, regardless of how many options are currently
@@ -157,6 +170,17 @@ export interface DataViewColumn<T extends Record<string, unknown>> extends GridC
157
170
  export type DataViewsLayout = "cards" | "list" | "board" | "table";
158
171
 
159
172
  /** The full, serializable state a view captures. */
173
+ /**
174
+ * A view-state patch: the fields to merge, or an updater given the CURRENT
175
+ * state. Use the updater whenever the patch derives from state it also changes
176
+ * — a render-scoped snapshot would let two calls in one tick read the same
177
+ * `prev` and the second overwrite the first, which is exactly what a control
178
+ * emitting one call per changed value does.
179
+ */
180
+ export type DataViewStatePatch =
181
+ | Partial<DataViewState>
182
+ | ((prev: DataViewState) => Partial<DataViewState>);
183
+
160
184
  export interface DataViewState {
161
185
  /** Free text matched across every `searchable` column. */
162
186
  search: string;
@@ -20,6 +20,7 @@ import {
20
20
  type DataViewColumn,
21
21
  type DataViewServer,
22
22
  type DataViewState,
23
+ type DataViewStatePatch,
23
24
  type DataViewSyncState,
24
25
  type FilterFieldConfig,
25
26
  type RangeFieldConfig,
@@ -73,7 +74,15 @@ interface UseDataViewsStateArgs<T extends Record<string, unknown>> {
73
74
  export interface DataViewsController<T extends Record<string, unknown>> {
74
75
  state: DataViewState;
75
76
  ranges: Record<string, RangeValue>;
76
- patch: (next: Partial<DataViewState>) => void;
77
+ /**
78
+ * Merge a partial into the view state.
79
+ *
80
+ * The UPDATER form is the one to reach for when the patch is derived from
81
+ * state you are also changing — successive calls within one tick each see the
82
+ * previous call's result, where the object form would have every caller build
83
+ * its patch from the same render-scoped snapshot and the last write would win.
84
+ */
85
+ patch: (next: DataViewStatePatch) => void;
77
86
  matched: T[];
78
87
  gridColumns: GridColumn<T>[];
79
88
  /** Columns eligible for the show/hide menu (hideable, with a text header). */
@@ -229,7 +238,7 @@ function seedState(
229
238
  * same reason changing any other part of the query clears it.
230
239
  */
231
240
  function makeSetScope(
232
- patch: (next: Partial<DataViewState>) => void,
241
+ patch: (next: DataViewStatePatch) => void,
233
242
  clearSelection: () => void,
234
243
  ): (id: string) => void {
235
244
  return (id) => {
@@ -327,7 +336,8 @@ export function useDataViewsState<T extends Record<string, unknown>>({
327
336
 
328
337
  useStateSyncEffects(appliedState, syncState, state, onStateChange, setState);
329
338
 
330
- const patch = (next: Partial<DataViewState>): void => setState((prev) => ({ ...prev, ...next }));
339
+ const patch = (next: DataViewStatePatch): void =>
340
+ setState((prev) => ({ ...prev, ...(typeof next === "function" ? next(prev) : next) }));
331
341
  const matched = useMatchedRows(server, rows, columns, fields, rangeFields, state);
332
342
  // Resolved at READ time, every render: a stale deep link or a saved view naming
333
343
  // a scope that has since been removed falls back to the first declared scope
@@ -5,7 +5,7 @@ import Box from '@mui/material/Box/index.js';
5
5
  import Button from '@mui/material/Button/index.js';
6
6
  import Skeleton from '@mui/material/Skeleton/index.js';
7
7
 
8
- import { categoryCheckState } from './category-tree';
8
+ import { categoryCheckState, isLeafCategory } from './category-tree';
9
9
  import {
10
10
  CategoryHeadRow,
11
11
  CategorySectionHeading,
@@ -125,7 +125,11 @@ function CategoryGroupRows({
125
125
  const { draft, query, single, allowParentSelection, rowIds, activeIndex, sheet } = props;
126
126
  const categoryId = group.category.id;
127
127
  const expanded = props.isExpanded(categoryId);
128
- const asHeading = single && !allowParentSelection;
128
+ // A childless category is the leaf, so it is selectable whatever the mode says
129
+ // — the heading reading has no subcategory to point at, and would leave the
130
+ // row inert.
131
+ const selectable = allowParentSelection || isLeafCategory(group);
132
+ const asHeading = single && !selectable;
129
133
  const selectedCount = group.subcategories.filter((sub) => draft.has(sub.id)).length;
130
134
 
131
135
  return (
@@ -139,9 +143,9 @@ function CategoryGroupRows({
139
143
  expanded={expanded}
140
144
  active={rowIds[activeIndex] === categoryId}
141
145
  sheet={sheet}
142
- checkState={
143
- allowParentSelection ? categoryCheckState(group, draft) : undefined
144
- }
146
+ checkState={selectable ? categoryCheckState(group, draft) : undefined}
147
+ single={single}
148
+ expandable={!isLeafCategory(group)}
145
149
  selectedCount={selectedCount}
146
150
  showCounts={props.showCounts}
147
151
  onToggleExpanded={() => props.onToggleExpanded(categoryId)}
@@ -65,6 +65,10 @@ interface CategoryHeadRowProps {
65
65
  sheet: boolean;
66
66
  /** Absent in leaf-only mode, where the category is a heading with no checkbox. */
67
67
  checkState?: CategoryCheckState;
68
+ /** Single-select draws a radio for the control: choosing a row is exclusive. */
69
+ single: boolean;
70
+ /** False for a childless category — there is nothing under it to disclose. */
71
+ expandable: boolean;
68
72
  selectedCount: number;
69
73
  showCounts: boolean;
70
74
  onToggleExpanded: () => void;
@@ -84,12 +88,59 @@ function rowMeta(
84
88
  return null;
85
89
  }
86
90
 
91
+ /** The disclosure chevron, or the space it would have taken on a childless row. */
92
+ function HeadRowDisclosure({
93
+ option,
94
+ expanded,
95
+ expandable,
96
+ onToggleExpanded,
97
+ dataTestId,
98
+ copy,
99
+ }: Pick<
100
+ CategoryHeadRowProps,
101
+ 'option' | 'expanded' | 'expandable' | 'onToggleExpanded' | 'dataTestId' | 'copy'
102
+ >): React.JSX.Element {
103
+ if (!expandable) {
104
+ return <Box sx={{ width: METRICS.chevronButton, flex: '0 0 auto' }} />;
105
+ }
106
+ return (
107
+ <Box
108
+ component="button"
109
+ type="button"
110
+ tabIndex={-1}
111
+ aria-label={expanded ? copy.collapseCategory(option.name) : copy.expandCategory(option.name)}
112
+ data-testid={`${dataTestId}-expand-${option.id}`}
113
+ sx={(theme) => chevronButtonSx(theme, expanded)}
114
+ onClick={(event: React.MouseEvent) => {
115
+ event.stopPropagation();
116
+ onToggleExpanded();
117
+ }}
118
+ >
119
+ <DisclosureGlyph />
120
+ </Box>
121
+ );
122
+ }
123
+
124
+ /** The row's selection control, or the space it would have taken on a heading. */
125
+ function HeadRowControl({
126
+ checkState,
127
+ single,
128
+ }: Pick<CategoryHeadRowProps, 'checkState' | 'single'>): React.JSX.Element {
129
+ if (!checkState) return <Box sx={{ width: METRICS.boxSize, flex: '0 0 auto' }} />;
130
+ // Single-select commits the moment a row is chosen, so the control is a radio
131
+ // there: a checkbox would promise the accumulation this mode does not do.
132
+ if (single) return <CategoryRadio on={checkState === 'on'} />;
133
+ return <CategoryCheckbox state={checkState} />;
134
+ }
135
+
87
136
  /**
88
137
  * A top-level category row: disclosure chevron, optional checkbox, name, meta.
89
138
  *
90
139
  * The chevron is its OWN button inside the row button — clicking it only folds,
91
140
  * while clicking the row does the row's job (expand as a heading, or tick when
92
- * parents are selectable).
141
+ * the category is selectable). A CHILDLESS category has neither a fold nor a
142
+ * heading to be: it draws no chevron, and it carries the control, because it is
143
+ * itself the leaf.
93
144
  */
94
145
  export function CategoryHeadRow({
95
146
  option,
@@ -98,6 +149,8 @@ export function CategoryHeadRow({
98
149
  active,
99
150
  sheet,
100
151
  checkState,
152
+ single,
153
+ expandable,
101
154
  selectedCount,
102
155
  showCounts,
103
156
  onToggleExpanded,
@@ -111,32 +164,20 @@ export function CategoryHeadRow({
111
164
  component="div"
112
165
  role={checkState ? 'option' : 'button'}
113
166
  aria-selected={checkState ? checkState === 'on' : undefined}
114
- aria-expanded={expanded}
167
+ aria-expanded={expandable ? expanded : undefined}
115
168
  data-testid={`${dataTestId}-category-${option.id}`}
116
169
  sx={(theme) => rowSx(theme, active, sheet)}
117
170
  onClick={onActivate}
118
171
  >
119
- <Box
120
- component="button"
121
- type="button"
122
- tabIndex={-1}
123
- aria-label={
124
- expanded ? copy.collapseCategory(option.name) : copy.expandCategory(option.name)
125
- }
126
- data-testid={`${dataTestId}-expand-${option.id}`}
127
- sx={(theme) => chevronButtonSx(theme, expanded)}
128
- onClick={(event: React.MouseEvent) => {
129
- event.stopPropagation();
130
- onToggleExpanded();
131
- }}
132
- >
133
- <DisclosureGlyph />
134
- </Box>
135
- {checkState ? (
136
- <CategoryCheckbox state={checkState} />
137
- ) : (
138
- <Box sx={{ width: METRICS.boxSize, flex: '0 0 auto' }} />
139
- )}
172
+ <HeadRowDisclosure
173
+ option={option}
174
+ expanded={expanded}
175
+ expandable={expandable}
176
+ onToggleExpanded={onToggleExpanded}
177
+ dataTestId={dataTestId}
178
+ copy={copy}
179
+ />
180
+ <HeadRowControl checkState={checkState} single={single} />
140
181
  <Box component="span" sx={(theme) => rowNameSx(theme, true)}>
141
182
  <HighlightedName text={option.name} query={query} />
142
183
  </Box>
@@ -32,9 +32,36 @@ const options = [
32
32
  Never pre-indent `name` (`"— Águas"`). The row draws the nesting; a baked-in dash
33
33
  travels everywhere the label goes, including the closed trigger.
34
34
 
35
- A category with no children is selectable in its own right. An option whose
36
- `parentId` matches nothing is promoted to top level rather than dropped, so a
37
- partial payload never makes a category invisible.
35
+ An option whose `parentId` matches nothing is promoted to top level rather than
36
+ dropped, so a partial payload never makes a category invisible.
37
+
38
+ ## Which rows are selectable
39
+
40
+ `allowParentSelection` is the switch, and it gates exactly one thing: whether a
41
+ parent that HAS children can be ticked in its own right.
42
+
43
+ | `allowParentSelection` | has children | the row |
44
+ | --- | --- | --- |
45
+ | `false` (default) | yes | a **heading** — no control; its subcategories are what you tick |
46
+ | `false` | no | **selectable** — it is itself the leaf |
47
+ | `true` | yes | **selectable** — ticking it selects **every subcategory under it** |
48
+ | `true` | no | **selectable** |
49
+
50
+ Two of those deserve their reasons written down.
51
+
52
+ **A parent with children, flag on, selects its CHILDREN** — not an id of its own.
53
+ That is what makes the value a caller receives uniform: always leaves, never a
54
+ mix of leaves and groups that every consumer would have to re-expand. The chip
55
+ tray collapses a fully-selected category back to one chip bearing the category's
56
+ name, so the user still sees "Bebidas" rather than six drinks.
57
+
58
+ **A childless category is selectable whatever the flag says.** The leaf-only
59
+ reading makes the category a heading and the subcategory the thing you pick — but
60
+ a childless category has no subcategory to offer instead, so that reading leaves
61
+ the row inert: no control, and a disclosure that opens onto nothing. It IS the
62
+ leaf, so it carries the control and draws no chevron. The rest of the component
63
+ always agreed: `leavesOf` returns its own id, `Marcar tudo` ticks it, and a chip
64
+ appears for it. The flag has nothing to gate there.
38
65
 
39
66
  ## The two modes
40
67
 
@@ -87,8 +114,8 @@ reads `Pai › Filha`, so the chosen leaf keeps its context.
87
114
  | `↑` `↓` | Move the cursor |
88
115
  | `→` | Expand the category |
89
116
  | `←` | Collapse it, or jump from a subcategory to its parent |
90
- | `Space` | Mark the row (single-select: pick it) |
91
- | `Enter` | Apply (single-select: pick) |
117
+ | `Space` | Mark the row (single-select: pick it) — a heading category expands |
118
+ | `Enter` | Apply (single-select: pick, and expand on a heading, as `Space` does) |
92
119
  | `Esc` | Cancel, returning focus to the trigger |
93
120
 
94
121
  `Space`, `←` and `→` belong to the search field **only while it holds text**. The
@@ -122,7 +149,7 @@ design's own values.
122
149
  | `loading` | `boolean` | `false` | Skeleton rows |
123
150
  | `fullWidth` | `boolean` | `false` | |
124
151
  | `showCounts` | `boolean` | `false` | Trailing `count` per row |
125
- | `allowParentSelection` | `boolean` | `false` | Makes categories selectable |
152
+ | `allowParentSelection` | `boolean` | `false` | Lets a parent **with children** be ticked (selecting all of them); see the table above |
126
153
  | `onCreateCategory` | `() => void` | — | CTA on the empty catalogue |
127
154
  | `dataTestId` | `string` | `'category-select'` | |
128
155
 
@@ -1,4 +1,4 @@
1
- import type { CategoryRowRef } from './category-tree';
1
+ import { isLeafCategory, type CategoryRowRef } from './category-tree';
2
2
  import type { CategoryGroup } from './CategorySelect.types';
3
3
 
4
4
  /** What a key handler is allowed to do to the panel. */
@@ -63,33 +63,52 @@ function handleLeft(context: CategoryKeyContext): void {
63
63
  }
64
64
 
65
65
  /**
66
- * Space marks. On a category that is only a HEADING it expands instead — the
67
- * row has no checkbox, so "mark" has nothing to mean there.
66
+ * What a category row does when it is activated — the one answer the click, the
67
+ * Space key and (in single-select) Enter all take, so the three cannot disagree
68
+ * about a row the way they did over a childless category.
69
+ *
70
+ * A category that is only a HEADING expands instead of marking: the row has no
71
+ * control, so "mark" has nothing to mean there. A childless category is not a
72
+ * heading — it is the leaf — so it marks.
68
73
  */
69
- function handleSpace(context: CategoryKeyContext): void {
70
- const row = activeRow(context);
71
- if (!row) return;
74
+ function activateCategoryRow(context: CategoryKeyContext, categoryId: string): void {
75
+ const group = groupOf(context, categoryId);
76
+ if (!group) return;
77
+ if (!context.allowParentSelection && !isLeafCategory(group)) {
78
+ context.toggleExpanded(categoryId);
79
+ return;
80
+ }
72
81
  if (context.single) {
73
- context.pick(row.id);
82
+ context.pick(categoryId);
74
83
  return;
75
84
  }
85
+ context.toggleCategory(group);
86
+ }
87
+
88
+ /** Space marks the row under the cursor. */
89
+ function handleSpace(context: CategoryKeyContext): void {
90
+ const row = activeRow(context);
91
+ if (!row) return;
76
92
  if (row.kind === 'subcategory') {
77
- context.toggleSubcategory(row.id);
93
+ if (context.single) context.pick(row.id);
94
+ else context.toggleSubcategory(row.id);
78
95
  return;
79
96
  }
80
- const group = groupOf(context, row.id);
81
- if (!group) return;
82
- if (context.allowParentSelection) context.toggleCategory(group);
83
- else context.toggleExpanded(row.id);
97
+ activateCategoryRow(context, row.id);
84
98
  }
85
99
 
86
100
  function handleEnter(context: CategoryKeyContext): void {
87
101
  const row = activeRow(context);
88
- if (context.single) {
89
- if (row) context.pick(row.id);
102
+ if (!context.single) {
103
+ context.commit();
104
+ return;
105
+ }
106
+ if (!row) return;
107
+ if (row.kind === 'subcategory') {
108
+ context.pick(row.id);
90
109
  return;
91
110
  }
92
- context.commit();
111
+ activateCategoryRow(context, row.id);
93
112
  }
94
113
 
95
114
  /** Key → behaviour. A map keeps this dispatch flat instead of a long if-chain. */
@@ -47,20 +47,29 @@ export function buildCategoryGroups(options: CategorySelectOption[]): CategoryGr
47
47
  return [...groups.values(), ...orphans];
48
48
  }
49
49
 
50
+ /**
51
+ * Whether this category IS the leaf, because nothing sits under it.
52
+ *
53
+ * The leaf-only default makes a category a heading and the subcategory the thing
54
+ * you pick — but a childless category has no subcategory to offer instead, so
55
+ * that reading leaves it unpickable and the row does nothing at all. It is the
56
+ * leaf, so it is selectable in its own right, whatever `allowParentSelection`
57
+ * says. Everything below already agreed; only the rows and the activation did
58
+ * not, which is what made a childless category unselectable on the estoque
59
+ * filter while `Marcar tudo` could still select it.
60
+ */
61
+ export function isLeafCategory(group: CategoryGroup): boolean {
62
+ return group.subcategories.length === 0;
63
+ }
64
+
50
65
  /** Every selectable leaf id across all groups, in display order. */
51
66
  export function collectLeafIds(groups: CategoryGroup[]): string[] {
52
- return groups.flatMap((group) =>
53
- group.subcategories.length > 0
54
- ? group.subcategories.map((sub) => sub.id)
55
- : [group.category.id],
56
- );
67
+ return groups.flatMap((group) => leavesOf(group));
57
68
  }
58
69
 
59
70
  /** The leaves a category stands for — its subcategories, or itself when childless. */
60
71
  export function leavesOf(group: CategoryGroup): string[] {
61
- return group.subcategories.length > 0
62
- ? group.subcategories.map((sub) => sub.id)
63
- : [group.category.id];
72
+ return isLeafCategory(group) ? [group.category.id] : group.subcategories.map((sub) => sub.id);
64
73
  }
65
74
 
66
75
  export type CategoryCheckState = 'off' | 'partial' | 'on';
@@ -1,5 +1,6 @@
1
1
  import { useCallback, useMemo } from 'react';
2
2
 
3
+ import { isLeafCategory } from './category-tree';
3
4
  import type { CategoryGroup, CategorySelectProps } from './CategorySelect.types';
4
5
  import type { CategorySelectState } from './useCategorySelect';
5
6
 
@@ -63,18 +64,21 @@ export function useCategoryCommit({
63
64
  }, [props]);
64
65
 
65
66
  // A category row means different things per mode: pick the whole category,
66
- // tick all its leaves, or — when it is only a heading — just fold it.
67
+ // tick all its leaves, or — when it is only a heading — just fold it. A
68
+ // CHILDLESS category is never the last of those: it is the leaf, so it acts
69
+ // like one even in the leaf-only default.
67
70
  const activateCategory = useCallback(
68
71
  (group: CategoryGroup) => {
69
- if (allowParentSelection && single) {
70
- pick(group.category.id);
72
+ const selectable = allowParentSelection || isLeafCategory(group);
73
+ if (!selectable) {
74
+ toggleExpanded(group.category.id);
71
75
  return;
72
76
  }
73
- if (allowParentSelection) {
74
- toggleCategory(group);
77
+ if (single) {
78
+ pick(group.category.id);
75
79
  return;
76
80
  }
77
- toggleExpanded(group.category.id);
81
+ toggleCategory(group);
78
82
  },
79
83
  [allowParentSelection, single, pick, toggleCategory, toggleExpanded],
80
84
  );
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/form/CategorySelect/CategoryPanelList.tsx"],"sourcesContent":["'use client';\n\nimport type { CategorySelectCopy } from \"../../../copy\";\nimport Box from '@mui/material/Box/index.js';\nimport Button from '@mui/material/Button/index.js';\nimport Skeleton from '@mui/material/Skeleton/index.js';\n\nimport { categoryCheckState } from './category-tree';\nimport {\n CategoryHeadRow,\n CategorySectionHeading,\n SubcategoryRow,\n} from './CategoryRows';\nimport { emptySx, listSx, skeletonSx } from './CategorySelect.styles';\nimport type { CategoryGroup } from './CategorySelect.types';\n\n/** The design sets these labels in sentence case, not MUI's default caps. */\nconst SENTENCE_CASE = { textTransform: 'none' } as const;\n\n/** How many skeleton rows stand in for the catalogue while it loads. */\nconst SKELETON_ROWS = 6;\n\ninterface PanelListProps {\n /** The words this panel renders. REQUIRED — no default copy. */\n copy: CategorySelectCopy;\n groups: CategoryGroup[];\n query: string;\n draft: ReadonlySet<string>;\n rowIds: string[];\n activeIndex: number;\n sheet: boolean;\n single: boolean;\n loading: boolean;\n showCounts: boolean;\n allowParentSelection: boolean;\n isExpanded: (categoryId: string) => boolean;\n onToggleExpanded: (categoryId: string) => void;\n onActivateCategory: (group: CategoryGroup) => void;\n onActivateSubcategory: (id: string) => void;\n onClearQuery: () => void;\n onCreateCategory?: (name?: string) => void;\n listRef: React.RefObject<HTMLDivElement | null>;\n dataTestId: string;\n}\n\nfunction LoadingRows(): React.JSX.Element {\n return (\n <>\n {Array.from({ length: SKELETON_ROWS }, (_unused, index) => (\n <Skeleton key={index} variant=\"rounded\" sx={skeletonSx} />\n ))}\n </>\n );\n}\n\n/** No categories exist at all — an onboarding moment, not an error. */\nfunction EmptyCatalogue({\n onCreateCategory,\n dataTestId,\n copy,\n}: {\n onCreateCategory?: (name?: string) => void;\n dataTestId: string;\n copy: CategorySelectCopy;\n}): React.JSX.Element {\n return (\n <Box sx={emptySx} data-testid={`${dataTestId}-empty-catalogue`}>\n <strong>{copy.emptyTitle}</strong>\n <p>{copy.purpose}</p>\n {onCreateCategory && (\n <Button variant=\"contained\" size=\"small\" sx={SENTENCE_CASE} onClick={() => onCreateCategory()}>\n {copy.createCategory}\n </Button>\n )}\n </Box>\n );\n}\n\n/** The search found nothing — offer creation, or the way back. */\nfunction NoResults({\n query,\n onClearQuery,\n onCreateCategory,\n dataTestId,\n copy,\n}: {\n query: string;\n onClearQuery: () => void;\n onCreateCategory?: (name?: string) => void;\n dataTestId: string;\n copy: CategorySelectCopy;\n}): React.JSX.Element {\n return (\n <Box sx={emptySx} data-testid={`${dataTestId}-no-results`}>\n <strong>{copy.noResults.title(query)}</strong>\n <p>{copy.noResults.hint}</p>\n <Box sx={{ display: 'flex', gap: '6px', justifyContent: 'center' }}>\n <Button variant=\"outlined\" size=\"small\" sx={SENTENCE_CASE} onClick={onClearQuery}>\n {copy.noResults.clearSearch}\n </Button>\n {onCreateCategory && (\n <Button\n variant=\"contained\"\n size=\"small\"\n sx={SENTENCE_CASE}\n data-testid={`${dataTestId}-create`}\n onClick={() => onCreateCategory(query.trim())}\n >\n {copy.noResults.create(query.trim())}\n </Button>\n )}\n </Box>\n </Box>\n );\n}\n\n/** One group: its heading or head row, then whichever children are visible. */\nfunction CategoryGroupRows({\n group,\n props,\n}: {\n group: CategoryGroup;\n props: PanelListProps;\n}): React.JSX.Element {\n const { draft, query, single, allowParentSelection, rowIds, activeIndex, sheet } = props;\n const categoryId = group.category.id;\n const expanded = props.isExpanded(categoryId);\n const asHeading = single && !allowParentSelection;\n const selectedCount = group.subcategories.filter((sub) => draft.has(sub.id)).length;\n\n return (\n <>\n {asHeading ? (\n <CategorySectionHeading option={group.category} query={query} />\n ) : (\n <CategoryHeadRow\n option={group.category}\n query={query}\n expanded={expanded}\n active={rowIds[activeIndex] === categoryId}\n sheet={sheet}\n checkState={\n allowParentSelection ? categoryCheckState(group, draft) : undefined\n }\n selectedCount={selectedCount}\n showCounts={props.showCounts}\n onToggleExpanded={() => props.onToggleExpanded(categoryId)}\n onActivate={() => props.onActivateCategory(group)}\n dataTestId={props.dataTestId}\n copy={props.copy}\n />\n )}\n {(expanded || asHeading) &&\n group.subcategories.map((sub) => (\n <SubcategoryRow\n key={sub.id}\n option={sub}\n query={query}\n selected={draft.has(sub.id)}\n active={rowIds[activeIndex] === sub.id}\n sheet={sheet}\n single={single}\n showCounts={props.showCounts}\n onActivate={() => props.onActivateSubcategory(sub.id)}\n dataTestId={props.dataTestId}\n />\n ))}\n </>\n );\n}\n\n/** The scrolling body of the panel, including its three non-list states. */\nexport function CategoryPanelList(props: PanelListProps): React.JSX.Element {\n const { groups, loading, query, listRef, sheet, dataTestId, copy } = props;\n\n const body = (): React.JSX.Element => {\n if (loading) return <LoadingRows />;\n if (groups.length === 0 && query.trim().length > 0) {\n return (\n <NoResults copy={copy}\n query={query}\n onClearQuery={props.onClearQuery}\n onCreateCategory={props.onCreateCategory}\n dataTestId={dataTestId}\n />\n );\n }\n if (groups.length === 0) {\n return (\n <EmptyCatalogue copy={copy}\n onCreateCategory={props.onCreateCategory}\n dataTestId={dataTestId}\n />\n );\n }\n return (\n <>\n {groups.map((group) => (\n <CategoryGroupRows key={group.category.id} group={group} props={props} />\n ))}\n </>\n );\n };\n\n return (\n <Box\n ref={listRef}\n role=\"listbox\"\n aria-multiselectable={props.single ? undefined : true}\n tabIndex={-1}\n data-testid={`${dataTestId}-list`}\n sx={listSx(sheet)}\n >\n {body()}\n </Box>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAGA,OAAO,SAAS;AAChB,OAAO,YAAY;AACnB,OAAO,cAAc;AA0CjB,mBAEI,KAiBJ,YAnBA;AA9BJ,IAAM,gBAAgB,EAAE,eAAe,OAAO;AAG9C,IAAM,gBAAgB;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AAK,MAAM,KAAK,EAAE,SAAS,GAAG;AAClD,aACE;AAAA,QAAC;AAAA;AAAA,UAAU;AAAA,UACT;AAAA,UACA,cAAc,MAAM;AAAA,UACpB,kBAAkB,MAAM;AAAA,UACxB;AAAA;AAAA,MACF;AAAA,IAEJ;AACA,QAAI,OAAO,WAAW,GAAG;AACvB,aACE;AAAA,QAAC;AAAA;AAAA,UAAe;AAAA,UACd,kBAAkB,MAAM;AAAA,UACxB;AAAA;AAAA,MACF;AAAA,IAEJ;AACA,WACE,gCACG,iBAAO,IAAI,CAAC,UACX,oBAAC,qBAA0C,OAAc,SAAjC,MAAM,SAAS,EAAgC,CACxE,GACH;AAAA,EAEJ;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,MAAK;AAAA,MACL,wBAAsB,MAAM,SAAS,SAAY;AAAA,MACjD,UAAU;AAAA,MACV,eAAa,GAAG,UAAU;AAAA,MAC1B,IAAI,OAAO,KAAK;AAAA,MAEf,eAAK;AAAA;AAAA,EACR;AAEJ;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/data-display/DataViews/data-views-types.ts"],"sourcesContent":["import type { GridColumn, GridSort } from \"../DataGrid\";\nimport type { DropdownMenuItem } from \"../../navigation/DropdownMenu\";\n// A re-export does not bring the name into local scope, and the state/query\n// types below are written in terms of it.\nimport type { RangeValue } from \"./data-views-range-types\";\n\n/**\n * Shared types for the reusable admin \"DataViews\" table (FUT-88): a filter bar\n * (search-across-all + typed multi-select pills + column visibility) whose full\n * state — filters + sort + visible columns — a saved view (FUT-89) can capture\n * and restore. Each table declares its own columns + filter fields.\n */\n\n/**\n * A single, reusable row action. ONE definition drives BOTH the per-row \"⋮\"\n * kebab menu and the bulk-actions menu (tabwoah model): `onSelect` receives the\n * affected rows — `[row]` from a kebab, the whole selection from the bulk menu.\n * Single-item-only actions (e.g. \"Editar\") set `bulk: false` so they never\n * appear in the bulk menu.\n */\nexport interface RowAction<T extends Record<string, unknown>> {\n /** Stable id (also the `data-testid` suffix). */\n id: string;\n /** Menu label. In the kebab, `rowLabel` overrides it per row when provided. */\n label: string;\n /** Menu-item colour (e.g. `\"error\"` for destructive). */\n color?: DropdownMenuItem[\"color\"];\n /**\n * Runs on the affected rows: `[row]` from the kebab, all selected from bulk.\n * May be async — the bulk menu awaits it and only clears the selection once it\n * settles (keeping the selection on failure so the user can retry).\n */\n onSelect: (rows: T[]) => void | Promise<void>;\n /** Include in the bulk menu (2+ selected). Defaults to `true`. */\n bulk?: boolean;\n /** Include in the per-row kebab. Defaults to `true`. */\n row?: boolean;\n /** Per-row kebab label (e.g. `row.active ? \"Inativar\" : \"Ativar\"`). */\n rowLabel?: (row: T) => string;\n /**\n * Per-row applicability (e.g. state-machine guards). `false` hides the\n * kebab item for that row; in bulk the action runs only on the passing\n * rows and is dropped when none pass. Defaults to applicable.\n */\n isVisible?: (row: T) => boolean;\n}\n\n/** Selection state handed to a card renderer so it can drive its own checkbox. */\nexport interface DataViewCardSelection {\n selected: boolean;\n onToggleSelect: () => void;\n /**\n * Card SIZE multiplier from the toolbar zoom slider. The grid sizes the card's\n * width to `base × scale`; a card passes this to {@link BaseCard} `scale` so its\n * padding + typography grow by the same factor — the whole card scales together\n * (scale 2 → ~2× size). The proportion (aspect ratio) stays constant.\n */\n scale: number;\n}\n\n/**\n * The fixed proportions a {@link BaseCard} tile can take. The tile keeps this\n * ratio and grows in BOTH width and height as the zoom slider widens its grid\n * track, so a grid of cards stays visually uniform.\n */\nexport type CardAspectRatio = \"1:1\" | \"4:3\" | \"16:9\" | \"9:16\" | \"3:4\" | \"3:1\";\n\n/** Numeric width/height factor for each {@link CardAspectRatio} (CSS `aspect-ratio`). */\nexport const CARD_ASPECT_RATIOS: Record<CardAspectRatio, number> = {\n \"1:1\": 1,\n \"4:3\": 4 / 3,\n \"16:9\": 16 / 9,\n \"9:16\": 9 / 16,\n \"3:4\": 3 / 4,\n /**\n * The BANNER tile: too short for media, sized for two lines of text.\n *\n * Every other ratio here is picture-shaped, because they were added for cards\n * built around a thumbnail. A card whose subject is a NAME and a NUMBER — a\n * cart, an order, anything triaged rather than browsed — spends most of a 4:3\n * tile on an icon that repeats down the whole grid and says nothing.\n */\n \"3:1\": 3,\n};\n\n/** One selectable value inside a filter pill. */\nexport interface FilterOption {\n value: string;\n label: string;\n /**\n * Parent option's `value`, for a hierarchical field (`control: \"category\"`).\n * Ignored by the flat controls, so one option list serves both.\n */\n parentId?: string | null;\n}\n\n/** A typed, multi-select filter pill's configuration for a table. */\nexport interface FilterFieldConfig<T extends Record<string, unknown>> {\n /** Stable id; also the default row key when no `accessor` is given. */\n id: string;\n label: string;\n options: FilterOption[];\n /**\n * How the field renders in the filter panel. `checkboxes` (default) is best for\n * a few fixed options; `multiselect` is a compact dropdown for long option\n * lists; `category` is the hierarchical picker, for an option set that nests\n * via {@link FilterOption.parentId} — it renders parents as headings and\n * their children as the selectable rows, rather than flattening the tree into\n * one indistinguishable list.\n */\n control?: \"checkboxes\" | \"multiselect\" | \"category\";\n /**\n * Forces this filter to render as a searchable multi-select dropdown with the\n * search box always shown, regardless of how many options are currently\n * loaded. Use it when the option set can grow unbounded (e.g. a filter backed\n * by a relation such as Roles or Categories). Omit it for a closed value set\n * (an enum), which keeps the plain checkbox / \"search only when long\"\n * behavior.\n */\n searchEnabled?: boolean;\n /**\n * Reads the row's value(s) for this field. A row matches the pill when any of\n * its values is selected. Defaults to `String(row[id])`.\n */\n accessor?: (row: T) => string | string[];\n}\n\n/**\n * The range types live in `data-views-range-types` (this file outgrew the\n * size gate); they are re-exported here so `data-views-types` stays the one\n * name every consumer imports the model from.\n */\nexport type {\n DayRangeFieldConfig,\n NumberRangeFieldConfig,\n RangeFieldConfig,\n RangeFieldKind,\n RangePreset,\n RangeValue,\n} from \"./data-views-range-types\";\n\n/** A grid column that can join the search scan and the column-visibility menu. */\nexport interface DataViewColumn<T extends Record<string, unknown>> extends GridColumn<T> {\n /** Included in \"search across all columns\" (needs a resolvable value). */\n searchable?: boolean;\n /** Toggleable in the column-visibility menu. Defaults to true; set false for\n * structural columns (image thumbnail, actions kebab) that must always show. */\n hideable?: boolean;\n}\n\n/**\n * The DataViews layout (view type): the dense \"Tabela\" grid, the \"Grade\" of\n * cards, the \"Lista\" of full-width rows, or the \"Quadro\" board of state columns.\n * Lives with the state types rather than with the toggle because a saved view\n * CAPTURES it — see {@link DataViewState.layout}.\n */\nexport type DataViewsLayout = \"cards\" | \"list\" | \"board\" | \"table\";\n\n/** The full, serializable state a view captures. */\nexport interface DataViewState {\n /** Free text matched across every `searchable` column. */\n search: string;\n /** fieldId → selected option values (empty/absent = no constraint). */\n pills: Record<string, string[]>;\n /** fieldId → selected numeric range (min/max). Absent/empty = no constraint. */\n ranges?: Record<string, RangeValue>;\n sortBy: GridSort[];\n /** Column ids kept visible; a hideable column not listed here is hidden. */\n visibleColumns: string[];\n /**\n * Column ids in READING ORDER. Absent ⇒ the order the table declared them in.\n *\n * Order is view state for the same reason visibility is: reordering columns is\n * an operator deciding what to read FIRST, and a saved view that restored the\n * columns but not their order would restore half a decision. Ids the table no\n * longer declares are ignored at render, and ids missing from a stale list\n * fall in after it — so a column added since the view was saved appears rather\n * than disappearing.\n */\n order?: string[];\n /**\n * The active SCOPE id — the page-level partition the scope tabs select (see\n * `ScopeConfig`). Optional, so a table that declares no scopes is untouched\n * and no view persisted before scopes existed breaks.\n *\n * Stored raw and RESOLVED at read time: the declared scopes change underneath\n * a saved view, and a view naming a scope that has since been removed must\n * fall back at render rather than break.\n */\n scope?: string;\n /**\n * The layout the view was saved in. Optional — absent means \"whatever the user\n * is currently using\", which is the pre-existing behaviour.\n *\n * A LAYOUT FALLBACK IS NOT A LAYOUT CHANGE: a table rendered as stacked rows\n * on a phone still has `\"table\"` stored here, so the view round-trips the\n * stored layout regardless of the device that opened it.\n */\n layout?: DataViewsLayout;\n}\n\n/** A pristine view state showing every given column and no filters/sort. */\nexport function emptyViewState(visibleColumns: string[]): DataViewState {\n return { search: \"\", pills: {}, ranges: {}, sortBy: [], visibleColumns };\n}\n\n/**\n * The URL-driven slice of {@link DataViewState} — the controls a server-mode host\n * mirrors from the address bar (search / pills / ranges / sort), WITHOUT\n * `visibleColumns`. Supplying it re-applies those controls when its reference\n * changes (e.g. browser back/forward or a deep-link on the same route), merging\n * over the current state so a user's show/hide column choices are preserved —\n * unlike `appliedState`, which fully replaces the state to apply a saved view.\n */\nexport type DataViewSyncState = Pick<\n DataViewState,\n \"search\" | \"pills\" | \"ranges\" | \"sortBy\" | \"scope\"\n>;\n\n/**\n * The query a SERVER-mode table emits whenever its filter/sort/page changes\n * (FUT-180). The host translates this into a backend request (see\n * `@12-apps/shared-helpers/search`) — in server mode the grid never filters,\n * sorts, or paginates in the browser; it renders exactly the page the server\n * returned. `page` is 1-based to match the backend contract.\n */\nexport interface DataViewQuery {\n search: string;\n pills: Record<string, string[]>;\n ranges: Record<string, RangeValue>;\n sortBy: GridSort[];\n /**\n * The RESOLVED active scope (see `resolveScope`), when the table declares\n * scopes. The KEY IS ABSENT for a table that declares none — not present-and-\n * undefined — so a host that never opted in sees a byte-identical query.\n *\n * It carries the resolved id, never the stored one: a deep link or a saved\n * view naming a scope the table no longer declares must not put that id on the\n * wire, where the backend would reject it and replace the page with an error.\n */\n scope?: string;\n page: number;\n pageSize: number;\n}\n\n/**\n * Server-mode wiring for a DataViews table. Its PRESENCE flips the table from\n * in-browser filtering/sorting/pagination to backend-driven: the rows handed in\n * are already the current page, `totalCount` is the unpaginated total, and\n * `onQueryChange` fires (search debounced by the host) whenever the user changes\n * a filter, the sort, or the page. This is the ONLY way an admin list should run\n * (see the app-side `DataViewsTable` wrapper, which requires it).\n */\nexport interface DataViewServer {\n /** Total matched rows across all pages (drives the counter + page count). */\n totalCount: number;\n /** Current 1-based page. */\n page: number;\n /** Rows per page. */\n pageSize: number;\n /** Fired when the effective query changes; the host re-fetches the page. */\n onQueryChange: (query: DataViewQuery) => void;\n /**\n * Per-scope totals for the scope tabs: `scopeId → count`. THE ONLY PIECE OF\n * THIS CONTRACT THAT CANNOT BE DONE CLIENT-SIDE — a count computed from the\n * loaded page is wrong the moment there is a second page, which is the\n * concrete bug scopes exist to fix.\n *\n * Compute it over search + pills + ranges while IGNORING the active scope.\n * Computed WITH the scope applied, every inactive tab reads zero, which is\n * worse than no counts at all.\n *\n * Omit it and the tabs render with no numbers. Nothing is ever invented from\n * the loaded rows to fill the gap.\n */\n scopeCounts?: Record<string, number>;\n}\n\n/**\n * Coerce an opaque persisted state (a saved view's JSON) into a valid\n * DataViewState, filling any missing part with a sane default. Guards against\n * legacy/older shapes so applying a saved view never renders an empty grid.\n */\nexport function coerceViewState(raw: unknown, allColumnIds: string[]): DataViewState {\n const value = (raw ?? {}) as Partial<DataViewState>;\n return {\n search: typeof value.search === \"string\" ? value.search : \"\",\n pills: asRecord<string[]>(value.pills),\n ranges: asRecord<RangeValue>(value.ranges),\n sortBy: Array.isArray(value.sortBy) ? value.sortBy : [],\n visibleColumns: Array.isArray(value.visibleColumns) ? value.visibleColumns : allColumnIds,\n order: Array.isArray(value.order) ? value.order : undefined,\n // Carried through UNVALIDATED against the declared scopes on purpose: a view\n // written before scopes existed has none (⇒ undefined ⇒ the first declared\n // scope at render), and one naming a since-removed scope keeps its stored id\n // here and falls back at READ time. Resolving here would rewrite the view.\n scope: typeof value.scope === \"string\" ? value.scope : undefined,\n layout: isLayout(value.layout) ? value.layout : undefined,\n };\n}\n\n/** Every layout this build knows how to render — the guard's single source. */\nexport const DATA_VIEWS_LAYOUTS: readonly DataViewsLayout[] = [\"cards\", \"list\", \"board\", \"table\"];\n\n/** Is this a layout this build knows how to render? Guards persisted JSON. */\nfunction isLayout(value: unknown): value is DataViewsLayout {\n return DATA_VIEWS_LAYOUTS.includes(value as DataViewsLayout);\n}\n\n/** A persisted map, or an empty one — persisted JSON can hold anything. */\nfunction asRecord<V>(value: unknown): Record<string, V> {\n return value !== null && typeof value === \"object\" ? (value as Record<string, V>) : {};\n}\n\n/** A saved view as consumed by the DataViews UI (FUT-89), with ownership flag. */\nexport interface SavedViewSummary {\n id: string;\n name: string;\n description: string | null;\n state: DataViewState;\n shared: boolean;\n pinned: boolean;\n isDefault: boolean;\n /** True when the current user owns the view (may edit/delete/pin/share it). */\n isOwner: boolean;\n}\n\n/** A saved-view repository record (opaque `state`), as returned to server pages. */\ninterface SavedViewRecordLike {\n id: string;\n name: string;\n description: string | null;\n state: unknown;\n shared: boolean;\n pinned: boolean;\n isDefault: boolean;\n isOwner: boolean;\n}\n\n/** Map a repository record to the client summary (opaque state → DataViewState). */\nexport function toSavedViewSummary(record: SavedViewRecordLike): SavedViewSummary {\n return { ...record, state: (record.state ?? {}) as DataViewState };\n}\n\n/**\n * Dependency-injection contracts for the framework-agnostic DataViewsTableBase:\n * the host app supplies saved-view persistence + router side-effects so the ui\n * component imports neither a backend (server actions) nor a framework router.\n */\n\n/** A saved view's editable fields, as the host persists them. */\nexport interface DataViewSaveInput {\n name: string;\n description: string;\n state: DataViewState;\n shared: boolean;\n pinned: boolean;\n isDefault: boolean;\n}\n\n/** Result of a persistence call — mirrors the app's `Result` without importing it. */\nexport type DataViewMutationResult = { ok: true } | { ok: false; error: string };\n\n/** Injected saved-view persistence (create/update/delete), wired by the host. */\nexport interface DataViewPersistence {\n create: (input: DataViewSaveInput) => Promise<DataViewMutationResult>;\n update: (id: string, input: DataViewSaveInput) => Promise<DataViewMutationResult>;\n remove: (id: string) => Promise<DataViewMutationResult>;\n}\n\n/** Injected router side-effects: sync the `?view=` param and re-fetch on change. */\nexport interface DataViewRouter {\n syncViewParam: (viewId: string | null) => void;\n refresh: () => void;\n}\n"],"mappings":";AAoEO,IAAM,qBAAsD;AAAA,EACjE,OAAO;AAAA,EACP,OAAO,IAAI;AAAA,EACX,QAAQ,KAAK;AAAA,EACb,QAAQ,IAAI;AAAA,EACZ,OAAO,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASX,OAAO;AACT;AAuHO,SAAS,eAAe,gBAAyC;AACtE,SAAO,EAAE,QAAQ,IAAI,OAAO,CAAC,GAAG,QAAQ,CAAC,GAAG,QAAQ,CAAC,GAAG,eAAe;AACzE;AA+EO,SAAS,gBAAgB,KAAc,cAAuC;AACnF,QAAM,QAAS,OAAO,CAAC;AACvB,SAAO;AAAA,IACL,QAAQ,OAAO,MAAM,WAAW,WAAW,MAAM,SAAS;AAAA,IAC1D,OAAO,SAAmB,MAAM,KAAK;AAAA,IACrC,QAAQ,SAAqB,MAAM,MAAM;AAAA,IACzC,QAAQ,MAAM,QAAQ,MAAM,MAAM,IAAI,MAAM,SAAS,CAAC;AAAA,IACtD,gBAAgB,MAAM,QAAQ,MAAM,cAAc,IAAI,MAAM,iBAAiB;AAAA,IAC7E,OAAO,MAAM,QAAQ,MAAM,KAAK,IAAI,MAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA,IAKlD,OAAO,OAAO,MAAM,UAAU,WAAW,MAAM,QAAQ;AAAA,IACvD,QAAQ,SAAS,MAAM,MAAM,IAAI,MAAM,SAAS;AAAA,EAClD;AACF;AAGO,IAAM,qBAAiD,CAAC,SAAS,QAAQ,SAAS,OAAO;AAGhG,SAAS,SAAS,OAA0C;AAC1D,SAAO,mBAAmB,SAAS,KAAwB;AAC7D;AAGA,SAAS,SAAY,OAAmC;AACtD,SAAO,UAAU,QAAQ,OAAO,UAAU,WAAY,QAA8B,CAAC;AACvF;AA4BO,SAAS,mBAAmB,QAA+C;AAChF,SAAO,EAAE,GAAG,QAAQ,OAAQ,OAAO,SAAS,CAAC,EAAoB;AACnE;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/form/CategorySelect/category-tree.ts"],"sourcesContent":["import type {\n CategoryGroup,\n CategorySelectionChip,\n CategorySelectOption,\n} from './CategorySelect.types';\n\n/**\n * Fold a string to its comparison form: no diacritics, lower case.\n *\n * Portuguese category names are full of them (\"Águas\", \"Cápsulas\", \"Grãos\"), and\n * an admin typing \"agua\" or \"graos\" on a hurried phone keyboard means the same\n * thing. Comparing folded forms on both sides makes the search accent-blind in\n * both directions.\n */\nexport function foldText(text: string): string {\n return text\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase();\n}\n\n/**\n * Group a flat `parentId` list into top level + children, preserving input order.\n *\n * An option whose `parentId` names no top-level row is promoted to top level\n * rather than dropped — a category is never invisible just because its parent\n * was filtered out of the payload, or because the tree is deeper than two levels.\n */\nexport function buildCategoryGroups(options: CategorySelectOption[]): CategoryGroup[] {\n const roots = options.filter((option) => !option.parentId);\n const rootIds = new Set(roots.map((root) => root.id));\n const groups = new Map<string, CategoryGroup>(\n roots.map((root) => [root.id, { category: root, subcategories: [] }]),\n );\n const orphans: CategoryGroup[] = [];\n\n options.forEach((option) => {\n if (!option.parentId) return;\n const parent = groups.get(option.parentId);\n if (parent) {\n parent.subcategories.push(option);\n return;\n }\n if (!rootIds.has(option.id)) orphans.push({ category: option, subcategories: [] });\n });\n\n return [...groups.values(), ...orphans];\n}\n\n/** Every selectable leaf id across all groups, in display order. */\nexport function collectLeafIds(groups: CategoryGroup[]): string[] {\n return groups.flatMap((group) =>\n group.subcategories.length > 0\n ? group.subcategories.map((sub) => sub.id)\n : [group.category.id],\n );\n}\n\n/** The leaves a category stands for — its subcategories, or itself when childless. */\nexport function leavesOf(group: CategoryGroup): string[] {\n return group.subcategories.length > 0\n ? group.subcategories.map((sub) => sub.id)\n : [group.category.id];\n}\n\nexport type CategoryCheckState = 'off' | 'partial' | 'on';\n\n/** Whether none, some, or all of a category's leaves are selected. */\nexport function categoryCheckState(\n group: CategoryGroup,\n selected: ReadonlySet<string>,\n): CategoryCheckState {\n const leaves = leavesOf(group);\n const hits = leaves.filter((id) => selected.has(id)).length;\n if (hits === 0) return 'off';\n return hits === leaves.length ? 'on' : 'partial';\n}\n\n/** Select every leaf of a category, or clear them all when already complete. */\nexport function toggleCategoryLeaves(\n group: CategoryGroup,\n selected: ReadonlySet<string>,\n): Set<string> {\n const next = new Set(selected);\n const leaves = leavesOf(group);\n const turningOff = categoryCheckState(group, selected) === 'on';\n leaves.forEach((id) => (turningOff ? next.delete(id) : next.add(id)));\n return next;\n}\n\n/** Add an id when absent, remove it when present. */\nexport function toggleLeaf(id: string, selected: ReadonlySet<string>): Set<string> {\n const next = new Set(selected);\n if (!next.delete(id)) next.add(id);\n return next;\n}\n\n/**\n * Collapse a raw id set into the chips a human reads: a category that is fully\n * selected becomes ONE chip bearing the category's name, rather than one chip\n * per subcategory — \"Bebidas\" instead of six drinks.\n */\nexport function summarizeSelection(\n groups: CategoryGroup[],\n selected: ReadonlySet<string>,\n): CategorySelectionChip[] {\n return groups.flatMap((group): CategorySelectionChip[] => {\n const state = categoryCheckState(group, selected);\n if (state === 'off') return [];\n if (state === 'on') {\n return [{ id: group.category.id, label: group.category.name, whole: true }];\n }\n return group.subcategories\n .filter((sub) => selected.has(sub.id))\n .map((sub) => ({ id: sub.id, label: sub.name, whole: false }));\n });\n}\n\n/**\n * Drop the leaves a chip stands for. A `whole` chip removes the whole category;\n * any other chip removes just that leaf.\n */\nexport function removeChip(\n groups: CategoryGroup[],\n chipId: string,\n selected: ReadonlySet<string>,\n): Set<string> {\n const next = new Set(selected);\n const group = groups.find((candidate) => candidate.category.id === chipId);\n if (group) {\n leavesOf(group).forEach((id) => next.delete(id));\n return next;\n }\n next.delete(chipId);\n return next;\n}\n\n/**\n * Search across BOTH levels, keeping every hit under its parent.\n *\n * A category that matches keeps all of its subcategories, so \"Bebidas\" shows the\n * whole group. A category that does not match keeps only the subcategories that\n * do — the hit still arrives with its parent visible above it, which is the\n * context that tells \"Massas\" (mercearia) from \"Massas\" (pratos principais).\n */\nexport function filterCategoryGroups(groups: CategoryGroup[], query: string): CategoryGroup[] {\n const needle = foldText(query.trim());\n if (!needle) return groups;\n return groups.flatMap((group) => {\n if (foldText(group.category.name).includes(needle)) return [group];\n const subcategories = group.subcategories.filter((sub) =>\n foldText(sub.name).includes(needle),\n );\n return subcategories.length > 0 ? [{ category: group.category, subcategories }] : [];\n });\n}\n\n/** A run of text, flagged when it is the part that matched the query. */\ninterface HighlightSegment {\n text: string;\n match: boolean;\n}\n\n/**\n * Split a label around the query hit so the view can mark it.\n *\n * Slicing uses indices from the FOLDED text but cuts the ORIGINAL, which is safe\n * because folding is per-character here: NFD-stripping combining marks and\n * lower-casing both preserve offsets for the scripts these names use.\n */\nexport function highlightSegments(text: string, query: string): HighlightSegment[] {\n const needle = foldText(query.trim());\n if (!needle) return [{ text, match: false }];\n const at = foldText(text).indexOf(needle);\n if (at < 0) return [{ text, match: false }];\n return [\n { text: text.slice(0, at), match: false },\n { text: text.slice(at, at + needle.length), match: true },\n { text: text.slice(at + needle.length), match: false },\n ].filter((segment) => segment.text.length > 0);\n}\n\n/** A flattened row, so keyboard navigation can walk what is actually on screen. */\nexport interface CategoryRowRef {\n kind: 'category' | 'subcategory';\n id: string;\n /** Owning category id — lets ← jump from a subcategory back to its parent. */\n parentId?: string;\n}\n\n/** The visible rows, in order, honouring which categories are expanded. */\nexport function flattenRows(\n groups: CategoryGroup[],\n isExpanded: (categoryId: string) => boolean,\n): CategoryRowRef[] {\n return groups.flatMap((group) => {\n const head: CategoryRowRef = { kind: 'category', id: group.category.id };\n if (!isExpanded(group.category.id)) return [head];\n return [\n head,\n ...group.subcategories.map(\n (sub): CategoryRowRef => ({\n kind: 'subcategory',\n id: sub.id,\n parentId: group.category.id,\n }),\n ),\n ];\n });\n}\n"],"mappings":";AAcO,SAAS,SAAS,MAAsB;AAC7C,SAAO,KACJ,UAAU,KAAK,EACf,QAAQ,oBAAoB,EAAE,EAC9B,YAAY;AACjB;AASO,SAAS,oBAAoB,SAAkD;AACpF,QAAM,QAAQ,QAAQ,OAAO,CAAC,WAAW,CAAC,OAAO,QAAQ;AACzD,QAAM,UAAU,IAAI,IAAI,MAAM,IAAI,CAAC,SAAS,KAAK,EAAE,CAAC;AACpD,QAAM,SAAS,IAAI;AAAA,IACjB,MAAM,IAAI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