@carto/ps-react-ui 4.12.2 → 4.14.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 (154) hide show
  1. package/dist/{category-Dnd2_j0x.js → category-CGS_eHr4.js} +2 -2
  2. package/dist/{category-Dnd2_j0x.js.map → category-CGS_eHr4.js.map} +1 -1
  3. package/dist/{change-column-DjjwoPt1.js → change-column-CiVAjOUB.js} +2 -2
  4. package/dist/{change-column-DjjwoPt1.js.map → change-column-CiVAjOUB.js.map} +1 -1
  5. package/dist/components.js +1232 -777
  6. package/dist/components.js.map +1 -1
  7. package/dist/{data-zoom-layout-CkVnm6ej.js → data-zoom-layout-D_FYdnap.js} +2 -2
  8. package/dist/{data-zoom-layout-CkVnm6ej.js.map → data-zoom-layout-D_FYdnap.js.map} +1 -1
  9. package/dist/{download-config-oJIFZ2WC.js → download-config-OKlLLSW_.js} +2 -2
  10. package/dist/{download-config-oJIFZ2WC.js.map → download-config-OKlLLSW_.js.map} +1 -1
  11. package/dist/{lasso-tool-CDFj4zKY.js → lasso-tool-YLFRgb-S.js} +182 -154
  12. package/dist/lasso-tool-YLFRgb-S.js.map +1 -0
  13. package/dist/legend/stores.js +20 -0
  14. package/dist/legend/stores.js.map +1 -0
  15. package/dist/legend.js +1536 -0
  16. package/dist/legend.js.map +1 -0
  17. package/dist/selectors-DwHj6mE2.js +388 -0
  18. package/dist/selectors-DwHj6mE2.js.map +1 -0
  19. package/dist/{spread-DYNpzgh_.js → spread-4MYPOntd.js} +2 -2
  20. package/dist/{spread-DYNpzgh_.js.map → spread-4MYPOntd.js.map} +1 -1
  21. package/dist/{table-B3ZWWhJt.js → table-CTcLOycx.js} +2 -2
  22. package/dist/{table-B3ZWWhJt.js.map → table-CTcLOycx.js.map} +1 -1
  23. package/dist/types/components/index.d.ts +5 -2
  24. package/dist/types/components/lasso-tool/geometry-toolbar.d.ts +13 -0
  25. package/dist/types/components/lasso-tool/icons.d.ts +6 -0
  26. package/dist/types/components/lasso-tool/lasso-tool.d.ts +1 -1
  27. package/dist/types/components/lasso-tool/layer-filters.d.ts +10 -0
  28. package/dist/types/components/lasso-tool/styles.d.ts +1 -1
  29. package/dist/types/components/lasso-tool/types.d.ts +62 -1
  30. package/dist/types/components/responsive-drawer/responsive-drawer.d.ts +35 -3
  31. package/dist/types/legend/components/contexts.d.ts +20 -0
  32. package/dist/types/legend/components/icons.d.ts +12 -0
  33. package/dist/types/legend/components/index.d.ts +26 -0
  34. package/dist/types/legend/components/legend-actions/legend-actions.d.ts +24 -0
  35. package/dist/types/legend/components/legend-actions/styles.d.ts +7 -0
  36. package/dist/types/legend/components/legend-category/legend-category-ui.d.ts +13 -0
  37. package/dist/types/legend/components/legend-category/styles.d.ts +52 -0
  38. package/dist/types/legend/components/legend-config-select/legend-config-select.d.ts +14 -0
  39. package/dist/types/legend/components/legend-config-select/styles.d.ts +44 -0
  40. package/dist/types/legend/components/legend-group/legend-group.d.ts +21 -0
  41. package/dist/types/legend/components/legend-group/styles.d.ts +63 -0
  42. package/dist/types/legend/components/legend-icon/legend-icon-ui.d.ts +10 -0
  43. package/dist/types/legend/components/legend-icon/styles.d.ts +52 -0
  44. package/dist/types/legend/components/legend-item/legend-item-ui.d.ts +14 -0
  45. package/dist/types/legend/components/legend-item/legend-item.d.ts +10 -0
  46. package/dist/types/legend/components/legend-item/styles.d.ts +7 -0
  47. package/dist/types/legend/components/legend-opacity/legend-opacity.d.ts +32 -0
  48. package/dist/types/legend/components/legend-opacity/styles.d.ts +23 -0
  49. package/dist/types/legend/components/legend-proportion/legend-proportion-ui.d.ts +16 -0
  50. package/dist/types/legend/components/legend-proportion/styles.d.ts +37 -0
  51. package/dist/types/legend/components/legend-ramp/legend-ramp-ui.d.ts +20 -0
  52. package/dist/types/legend/components/legend-ramp/styles.d.ts +53 -0
  53. package/dist/types/legend/components/legend-row/legend-row.d.ts +23 -0
  54. package/dist/types/legend/components/legend-row/styles.d.ts +77 -0
  55. package/dist/types/legend/components/legend-row-menu/legend-row-menu.d.ts +18 -0
  56. package/dist/types/legend/components/legend-row-menu/legend-zoom-to.d.ts +15 -0
  57. package/dist/types/legend/components/legend-swatch/legend-swatch.d.ts +26 -0
  58. package/dist/types/legend/components/legend-visibility-toggle/legend-visibility-toggle.d.ts +35 -0
  59. package/dist/types/legend/index.d.ts +88 -0
  60. package/dist/types/legend/provider/index.d.ts +6 -0
  61. package/dist/types/legend/provider/labels.d.ts +27 -0
  62. package/dist/types/legend/provider/legend-config-context.d.ts +7 -0
  63. package/dist/types/legend/provider/legend-provider.d.ts +38 -0
  64. package/dist/types/legend/stores/index.d.ts +5 -0
  65. package/dist/types/legend/stores/legend-context.d.ts +4 -0
  66. package/dist/types/legend/stores/legend-store-registry.d.ts +39 -0
  67. package/dist/types/legend/stores/legend-store.test.d.ts +1 -0
  68. package/dist/types/legend/stores/selectors.d.ts +33 -0
  69. package/dist/types/legend/stores/types.d.ts +275 -0
  70. package/dist/widgets/actions.js +1 -1
  71. package/dist/widgets/bar.js +1 -1
  72. package/dist/widgets/category.js +1 -1
  73. package/dist/widgets/formula.js +1 -1
  74. package/dist/widgets/histogram.js +1 -1
  75. package/dist/widgets/markdown.js +1 -1
  76. package/dist/widgets/pie.js +1 -1
  77. package/dist/widgets/scatterplot.js +1 -1
  78. package/dist/widgets/spread.js +1 -1
  79. package/dist/widgets/table.js +1 -1
  80. package/dist/widgets/timeseries.js +1 -1
  81. package/dist/widgets/utils.js +1 -1
  82. package/dist/widgets/wrapper.js +1 -1
  83. package/dist/widgets-v2/actions.js +1 -1
  84. package/dist/widgets-v2/bar.js +2 -2
  85. package/dist/widgets-v2/category.js +2 -2
  86. package/dist/widgets-v2/formula.js +1 -1
  87. package/dist/widgets-v2/histogram.js +2 -2
  88. package/dist/widgets-v2/markdown.js +1 -1
  89. package/dist/widgets-v2/pie.js +1 -1
  90. package/dist/widgets-v2/scatterplot.js +1 -1
  91. package/dist/widgets-v2/spread.js +2 -2
  92. package/dist/widgets-v2/table.js +3 -3
  93. package/dist/widgets-v2/timeseries.js +2 -2
  94. package/dist/widgets-v2/utils.js +1 -1
  95. package/dist/widgets-v2.js +5 -5
  96. package/package.json +11 -3
  97. package/src/components/geolocation-controls/geolocation-controls.test.tsx +15 -0
  98. package/src/components/geolocation-controls/geolocation-controls.tsx +19 -3
  99. package/src/components/index.ts +10 -0
  100. package/src/components/lasso-tool/const.tsx +1 -0
  101. package/src/components/lasso-tool/geometry-toolbar.test.tsx +138 -0
  102. package/src/components/lasso-tool/geometry-toolbar.tsx +258 -0
  103. package/src/components/lasso-tool/icons.tsx +40 -0
  104. package/src/components/lasso-tool/lasso-tool.tsx +25 -1
  105. package/src/components/lasso-tool/layer-filters.test.tsx +90 -0
  106. package/src/components/lasso-tool/layer-filters.tsx +236 -0
  107. package/src/components/lasso-tool/styles.ts +1 -1
  108. package/src/components/lasso-tool/types.ts +66 -1
  109. package/src/components/responsive-drawer/responsive-drawer.test.tsx +129 -25
  110. package/src/components/responsive-drawer/responsive-drawer.tsx +149 -16
  111. package/src/legend/components/contexts.ts +32 -0
  112. package/src/legend/components/icons.tsx +22 -0
  113. package/src/legend/components/index.ts +39 -0
  114. package/src/legend/components/legend-actions/legend-actions.tsx +57 -0
  115. package/src/legend/components/legend-actions/styles.ts +9 -0
  116. package/src/legend/components/legend-category/legend-category-ui.tsx +91 -0
  117. package/src/legend/components/legend-category/styles.ts +61 -0
  118. package/src/legend/components/legend-config-select/legend-config-select.tsx +96 -0
  119. package/src/legend/components/legend-config-select/styles.ts +48 -0
  120. package/src/legend/components/legend-group/legend-group.test.tsx +115 -0
  121. package/src/legend/components/legend-group/legend-group.tsx +88 -0
  122. package/src/legend/components/legend-group/styles.ts +82 -0
  123. package/src/legend/components/legend-icon/legend-icon-ui.tsx +56 -0
  124. package/src/legend/components/legend-icon/styles.ts +56 -0
  125. package/src/legend/components/legend-item/legend-item-ui.test.tsx +362 -0
  126. package/src/legend/components/legend-item/legend-item-ui.tsx +43 -0
  127. package/src/legend/components/legend-item/legend-item.tsx +34 -0
  128. package/src/legend/components/legend-item/styles.ts +11 -0
  129. package/src/legend/components/legend-opacity/legend-opacity.tsx +179 -0
  130. package/src/legend/components/legend-opacity/styles.ts +28 -0
  131. package/src/legend/components/legend-proportion/legend-proportion-ui.tsx +122 -0
  132. package/src/legend/components/legend-proportion/styles.ts +43 -0
  133. package/src/legend/components/legend-ramp/legend-ramp-ui.tsx +159 -0
  134. package/src/legend/components/legend-ramp/styles.ts +62 -0
  135. package/src/legend/components/legend-row/legend-row.test.tsx +498 -0
  136. package/src/legend/components/legend-row/legend-row.tsx +129 -0
  137. package/src/legend/components/legend-row/styles.ts +111 -0
  138. package/src/legend/components/legend-row-menu/legend-row-menu.tsx +68 -0
  139. package/src/legend/components/legend-row-menu/legend-zoom-to.tsx +35 -0
  140. package/src/legend/components/legend-swatch/legend-swatch.test.tsx +109 -0
  141. package/src/legend/components/legend-swatch/legend-swatch.tsx +237 -0
  142. package/src/legend/components/legend-visibility-toggle/legend-visibility-toggle.tsx +127 -0
  143. package/src/legend/index.ts +121 -0
  144. package/src/legend/provider/index.ts +6 -0
  145. package/src/legend/provider/labels.ts +59 -0
  146. package/src/legend/provider/legend-config-context.ts +15 -0
  147. package/src/legend/provider/legend-provider.tsx +102 -0
  148. package/src/legend/stores/index.ts +46 -0
  149. package/src/legend/stores/legend-context.ts +17 -0
  150. package/src/legend/stores/legend-store-registry.ts +639 -0
  151. package/src/legend/stores/legend-store.test.ts +457 -0
  152. package/src/legend/stores/selectors.ts +65 -0
  153. package/src/legend/stores/types.ts +347 -0
  154. package/dist/lasso-tool-CDFj4zKY.js.map +0 -1
@@ -0,0 +1,121 @@
1
+ // ─── Internal imports (used to assemble the curated `Legend` const) ─────────
2
+ import { LegendProvider } from './provider/legend-provider'
3
+ import { LegendGroup } from './components/legend-group/legend-group'
4
+ import { LegendRow } from './components/legend-row/legend-row'
5
+ import { LegendActions } from './components/legend-actions/legend-actions'
6
+ import { LegendVisibilityToggle } from './components/legend-visibility-toggle/legend-visibility-toggle'
7
+ import { LegendRowMenu } from './components/legend-row-menu/legend-row-menu'
8
+ import { LegendZoomTo } from './components/legend-row-menu/legend-zoom-to'
9
+ import { LegendOpacity } from './components/legend-opacity/legend-opacity'
10
+ import { LegendConfigSelect } from './components/legend-config-select/legend-config-select'
11
+ import { LegendItem } from './components/legend-item/legend-item'
12
+ import { LegendItemUI } from './components/legend-item/legend-item-ui'
13
+ import { LegendSwatch } from './components/legend-swatch/legend-swatch'
14
+ import { LegendCategoryUI } from './components/legend-category/legend-category-ui'
15
+ import { LegendRampUI } from './components/legend-ramp/legend-ramp-ui'
16
+ import { LegendProportionUI } from './components/legend-proportion/legend-proportion-ui'
17
+ import { LegendIconUI } from './components/legend-icon/legend-icon-ui'
18
+
19
+ /**
20
+ * Curated namespace export — the entry point to the legend module.
21
+ *
22
+ * Composable, widgets-v2 style: the lib ships wrapper shells + standalone
23
+ * store-connected actions, and the **app mounts the legend** in its own
24
+ * chrome (panel/drawer/sidebar). `Legend.Row`/`Legend.Group` partition their
25
+ * children — `<Legend.Actions>` renders in the sticky header (hover-fade),
26
+ * everything else in the collapsible body.
27
+ *
28
+ * ```tsx
29
+ * import { Legend } from '@carto/ps-react-ui/legend'
30
+ *
31
+ * <Legend.Provider id='map-legend' layers={layers} groups={groups}>
32
+ * <Legend.Group groupId='demographics'>
33
+ * <Legend.Actions>
34
+ * <Legend.VisibilityToggle /> // tri-state group eye
35
+ * </Legend.Actions>
36
+ * <Legend.Row layerId='income'>
37
+ * // Actions read L→R: options · opacity · visibility
38
+ * <Legend.Actions>
39
+ * <Legend.RowMenu>
40
+ * <Legend.ZoomTo onZoomTo={zoomTo} />
41
+ * </Legend.RowMenu>
42
+ * <Legend.Opacity.Trigger />
43
+ * <Legend.VisibilityToggle /> // layer eye
44
+ * </Legend.Actions>
45
+ * <Legend.ConfigSelect />
46
+ * <Legend.Item />
47
+ * <Legend.Opacity.Popover /> // anchors to the row header
48
+ * </Legend.Row>
49
+ * </Legend.Group>
50
+ * </Legend.Provider>
51
+ * ```
52
+ *
53
+ * @experimental This API is new and may change in a future release.
54
+ */
55
+ export const Legend = {
56
+ // Composition shell
57
+ Provider: LegendProvider,
58
+ Group: LegendGroup,
59
+ Row: LegendRow,
60
+ Actions: LegendActions,
61
+
62
+ // Store-connected actions & controls (context-driven)
63
+ VisibilityToggle: LegendVisibilityToggle,
64
+ RowMenu: LegendRowMenu,
65
+ ZoomTo: LegendZoomTo,
66
+ Opacity: LegendOpacity,
67
+ ConfigSelect: LegendConfigSelect,
68
+ Item: LegendItem,
69
+
70
+ // Pure UI
71
+ ItemUI: LegendItemUI,
72
+ Swatch: LegendSwatch,
73
+ CategoryUI: LegendCategoryUI,
74
+ RampUI: LegendRampUI,
75
+ ProportionUI: LegendProportionUI,
76
+ IconUI: LegendIconUI,
77
+ } as const
78
+
79
+ // ─── Labels ────────────────────────────────────────────────────────────────
80
+ // Exported separately so consumers can build customized label sets via spread.
81
+ export { DEFAULT_LEGEND_LABELS } from './provider'
82
+
83
+ // ─── Types ─────────────────────────────────────────────────────────────────
84
+ export type { LegendProviderProps, LegendLabels } from './provider'
85
+ export type { LegendGroupProps } from './components/legend-group/legend-group'
86
+ export type { LegendRowProps } from './components/legend-row/legend-row'
87
+ export type { LegendActionsProps } from './components/legend-actions/legend-actions'
88
+ export type { LegendVisibilityToggleProps } from './components/legend-visibility-toggle/legend-visibility-toggle'
89
+ export type { LegendRowMenuProps } from './components/legend-row-menu/legend-row-menu'
90
+ export type { LegendZoomToProps } from './components/legend-row-menu/legend-zoom-to'
91
+ export type { LegendRowContextValue } from './components/contexts'
92
+ export type { LegendItemUIProps } from './components/legend-item/legend-item-ui'
93
+ export type { LegendSwatchProps } from './components/legend-swatch/legend-swatch'
94
+ export type { LegendCategoryUIProps } from './components/legend-category/legend-category-ui'
95
+ export type { LegendRampUIProps } from './components/legend-ramp/legend-ramp-ui'
96
+ export type { LegendProportionUIProps } from './components/legend-proportion/legend-proportion-ui'
97
+ export type { LegendIconUIProps } from './components/legend-icon/legend-icon-ui'
98
+
99
+ // Store entity & variable types (re-exported for convenience; full store API
100
+ // lives at `@carto/ps-react-ui/legend/stores`).
101
+ export type {
102
+ LegendPosition,
103
+ LegendVisibility,
104
+ LegendOrientation,
105
+ LegendSwatchShape,
106
+ LegendFillPattern,
107
+ LegendStrokeStyle,
108
+ LegendVariable,
109
+ LegendCategoryItem,
110
+ LegendCategoryVariable,
111
+ LegendRampStop,
112
+ LegendRampVariable,
113
+ LegendProportionVariable,
114
+ LegendIconItem,
115
+ LegendIconVariable,
116
+ LegendConfigSection,
117
+ LegendLayer,
118
+ LegendGroup as LegendGroupModel,
119
+ LegendLayerInput,
120
+ LegendGroupInput,
121
+ } from './stores'
@@ -0,0 +1,6 @@
1
+ export { LegendProvider } from './legend-provider'
2
+ export type { LegendProviderProps } from './legend-provider'
3
+ export { LegendConfigContext, useLegendConfig } from './legend-config-context'
4
+ export type { LegendConfig } from './legend-config-context'
5
+ export { DEFAULT_LEGEND_LABELS } from './labels'
6
+ export type { LegendLabels } from './labels'
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Every user-facing string in the legend module. Override any subset via
3
+ * `<Legend.Provider labels={{ … }}>` — pure `*UI` components also accept a
4
+ * `labels` prop directly for store-free composition.
5
+ */
6
+ export interface LegendLabels {
7
+ // Layer row
8
+ expandLayer: string
9
+ collapseLayer: string
10
+ hideLayer: string
11
+ showLayer: string
12
+
13
+ // Row overflow menu
14
+ layerOptions: string
15
+ zoomTo: string
16
+
17
+ // Group
18
+ hideGroup: string
19
+ showGroup: string
20
+ expandGroup: string
21
+ collapseGroup: string
22
+
23
+ // Row controls
24
+ opacity: string
25
+ attribute: string
26
+
27
+ // Item renderers
28
+ radiusRangeBy: string
29
+ colorBasedOn: string
30
+ colorGradient: string
31
+ /** Prefix for the largest proportion break, e.g. `"MAX: "`. */
32
+ maxPrefix: string
33
+ /** Prefix for the smallest proportion break, e.g. `"MIN: "`. */
34
+ minPrefix: string
35
+ }
36
+
37
+ export const DEFAULT_LEGEND_LABELS: LegendLabels = {
38
+ expandLayer: 'Expand layer',
39
+ collapseLayer: 'Collapse layer',
40
+ hideLayer: 'Hide layer',
41
+ showLayer: 'Show layer',
42
+
43
+ layerOptions: 'Layer options',
44
+ zoomTo: 'Zoom to',
45
+
46
+ hideGroup: 'Hide group',
47
+ showGroup: 'Show group',
48
+ expandGroup: 'Expand group',
49
+ collapseGroup: 'Collapse group',
50
+
51
+ opacity: 'Opacity',
52
+ attribute: 'Attribute',
53
+
54
+ radiusRangeBy: 'Radius range by',
55
+ colorBasedOn: 'Color based on',
56
+ colorGradient: 'Color gradient',
57
+ maxPrefix: 'MAX: ',
58
+ minPrefix: 'MIN: ',
59
+ }
@@ -0,0 +1,15 @@
1
+ import { createContext, useContext } from 'react'
2
+ import { DEFAULT_LEGEND_LABELS, type LegendLabels } from './labels'
3
+
4
+ /** Per-panel configuration delivered by `Legend.Provider` to all containers. */
5
+ export interface LegendConfig {
6
+ labels: LegendLabels
7
+ }
8
+
9
+ export const LegendConfigContext = createContext<LegendConfig>({
10
+ labels: DEFAULT_LEGEND_LABELS,
11
+ })
12
+
13
+ export function useLegendConfig(): LegendConfig {
14
+ return useContext(LegendConfigContext)
15
+ }
@@ -0,0 +1,102 @@
1
+ import { useLayoutEffect, useMemo, useState, type ReactNode } from 'react'
2
+ import {
3
+ LegendContext,
4
+ createLegendStore,
5
+ getLegendStore,
6
+ hasLegendStore,
7
+ registerLegendStore,
8
+ setLegendStoreEntry,
9
+ unregisterLegendStore,
10
+ } from '../stores'
11
+ import type {
12
+ LegendGroupInput,
13
+ LegendLayerInput,
14
+ LegendStoreApi,
15
+ } from '../stores'
16
+ import { LegendConfigContext, type LegendConfig } from './legend-config-context'
17
+ import { DEFAULT_LEGEND_LABELS, type LegendLabels } from './labels'
18
+
19
+ export interface LegendProviderProps {
20
+ /** Unique id for this legend panel — keys its store. */
21
+ id: string
22
+ /**
23
+ * Layer definitions. Interactive fields (visible/opacity/…) are seeded.
24
+ * Pass stable references — `layers`, `groups`, and each layer's `variables`
25
+ * should be memoized or module constants (same contract as widgets-v2
26
+ * `data`); the store bails out of unchanged syncs by reference.
27
+ */
28
+ layers: LegendLayerInput[]
29
+ /** Optional group definitions for grouping layers. */
30
+ groups?: LegendGroupInput[]
31
+ /** Override any subset of the legend's user-facing strings. */
32
+ labels?: Partial<LegendLabels>
33
+ /**
34
+ * When `true` (the default), the per-panel store survives unmount so
35
+ * visibility/opacity/order are preserved across remounts — the common case
36
+ * for a legend that toggles in and out of view. Consumers must call
37
+ * `deleteLegendStore(id)` when the legend is permanently removed. Set to
38
+ * `false` to tear the store down on unmount.
39
+ */
40
+ keepAlive?: boolean
41
+ children: ReactNode
42
+ }
43
+
44
+ /**
45
+ * Legend panel shell. Creates a per-panel Zustand store keyed by `id`, syncs
46
+ * the consumer's `layers`/`groups` definitions onto it (preserving interactive
47
+ * state), and exposes the `id` via `LegendContext` so descendants resolve their
48
+ * store with `useLegendId()`. Labels are surfaced via `LegendConfigContext`.
49
+ *
50
+ * Modeled on the widgets-v2 `Widget.Provider`.
51
+ *
52
+ * @experimental This API is new and may change in a future release.
53
+ */
54
+ export function LegendProvider({
55
+ id,
56
+ layers,
57
+ groups,
58
+ labels,
59
+ keepAlive = true,
60
+ children,
61
+ }: LegendProviderProps) {
62
+ // Lazy init — reuse an existing keepAlive store, otherwise create one and
63
+ // synchronously place it in the registry so descendants can call
64
+ // useLegendStore(id, ...) on first render.
65
+ const [store] = useState<LegendStoreApi>(() => {
66
+ if (hasLegendStore(id)) return getLegendStore(id)
67
+ const created = createLegendStore(id, { layers, groups })
68
+ setLegendStoreEntry(id, created)
69
+ return created
70
+ })
71
+
72
+ useLayoutEffect(() => {
73
+ registerLegendStore(id, store)
74
+ return () => {
75
+ unregisterLegendStore(id, { keepAlive })
76
+ }
77
+ }, [id, store, keepAlive])
78
+
79
+ // Sync definitions in. The store's `_sync` preserves interactive state of
80
+ // known layers/groups and bails out (no state change) when the merged result
81
+ // is reference-identical, so stable props are a no-op.
82
+ useLayoutEffect(() => {
83
+ store.getState()._sync(layers, groups ?? [])
84
+ }, [store, layers, groups])
85
+
86
+ const config = useMemo<LegendConfig>(
87
+ () => ({
88
+ labels: labels
89
+ ? { ...DEFAULT_LEGEND_LABELS, ...labels }
90
+ : DEFAULT_LEGEND_LABELS,
91
+ }),
92
+ [labels],
93
+ )
94
+
95
+ return (
96
+ <LegendContext.Provider value={id}>
97
+ <LegendConfigContext.Provider value={config}>
98
+ {children}
99
+ </LegendConfigContext.Provider>
100
+ </LegendContext.Provider>
101
+ )
102
+ }
@@ -0,0 +1,46 @@
1
+ export type {
2
+ LegendPosition,
3
+ LegendOrientation,
4
+ LegendSwatchShape,
5
+ LegendFillPattern,
6
+ LegendStrokeStyle,
7
+ LegendCategoryItem,
8
+ LegendCategoryVariable,
9
+ LegendRampStop,
10
+ LegendRampVariable,
11
+ LegendProportionVariable,
12
+ LegendIconItem,
13
+ LegendIconVariable,
14
+ LegendVariable,
15
+ LegendConfigSection,
16
+ LegendLayer,
17
+ LegendGroup,
18
+ LegendLayerInput,
19
+ LegendGroupInput,
20
+ LegendState,
21
+ LegendStoreApi,
22
+ LegendInit,
23
+ } from './types'
24
+
25
+ export { LegendContext, useLegendId } from './legend-context'
26
+
27
+ export {
28
+ createLegendStore,
29
+ getLegendStore,
30
+ hasLegendStore,
31
+ deleteLegendStore,
32
+ clearAllLegendStores,
33
+ setLegendStoreEntry,
34
+ registerLegendStore,
35
+ unregisterLegendStore,
36
+ useLegendStore,
37
+ useLegendShallow,
38
+ } from './legend-store-registry'
39
+
40
+ export type { LegendVisibility } from './selectors'
41
+ export {
42
+ selectOrderedGroups,
43
+ selectLayersByGroup,
44
+ selectOrderedLayers,
45
+ selectGroupVisibility,
46
+ } from './selectors'
@@ -0,0 +1,17 @@
1
+ import { createContext, useContext } from 'react'
2
+
3
+ /** @experimental This API is new and may change in a future release. */
4
+ export const LegendContext = createContext<string | null>(null)
5
+
6
+ /** @experimental This API is new and may change in a future release. */
7
+ export function useLegendId(): string {
8
+ const id = useContext(LegendContext)
9
+ if (id == null) {
10
+ throw new Error(
11
+ 'useLegendId() must be called inside <Legend.Provider>. ' +
12
+ 'If you are calling from outside the Provider tree, use the hooks ' +
13
+ '(useLegendStore, useLegendShallow) directly with an explicit id.',
14
+ )
15
+ }
16
+ return id
17
+ }