@cratis/components 0.1.9 → 0.1.12

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 (258) hide show
  1. package/dist/cjs/CommandForm/CommandFormFields.js +9 -3
  2. package/dist/cjs/CommandForm/CommandFormFields.js.map +1 -1
  3. package/dist/cjs/CommandForm/ValidationMessage.js +24 -0
  4. package/dist/cjs/CommandForm/ValidationMessage.js.map +1 -0
  5. package/dist/cjs/CommandForm/asCommandFormField.js +47 -0
  6. package/dist/cjs/CommandForm/asCommandFormField.js.map +1 -0
  7. package/dist/cjs/CommandForm/fields/CheckboxField.js +13 -0
  8. package/dist/cjs/CommandForm/fields/CheckboxField.js.map +1 -0
  9. package/dist/cjs/CommandForm/fields/DropdownField.js +13 -0
  10. package/dist/cjs/CommandForm/fields/DropdownField.js.map +1 -0
  11. package/dist/cjs/CommandForm/fields/InputTextField.js +13 -0
  12. package/dist/cjs/CommandForm/fields/InputTextField.js.map +1 -0
  13. package/dist/cjs/CommandForm/fields/NumberField.js +13 -0
  14. package/dist/cjs/CommandForm/fields/NumberField.js.map +1 -0
  15. package/dist/cjs/CommandForm/fields/SliderField.js +17 -0
  16. package/dist/cjs/CommandForm/fields/SliderField.js.map +1 -0
  17. package/dist/cjs/CommandForm/fields/TextAreaField.js +13 -0
  18. package/dist/cjs/CommandForm/fields/TextAreaField.js.map +1 -0
  19. package/dist/cjs/CommandForm/index.js +15 -7
  20. package/dist/cjs/CommandForm/index.js.map +1 -1
  21. package/dist/cjs/PivotViewer/PivotViewer.css +1258 -0
  22. package/dist/cjs/PivotViewer/PivotViewer.js +14 -0
  23. package/dist/cjs/PivotViewer/PivotViewer.js.map +1 -1
  24. package/dist/cjs/PivotViewer/components/PivotCanvas.js +33 -10
  25. package/dist/cjs/PivotViewer/components/PivotCanvas.js.map +1 -1
  26. package/dist/cjs/PivotViewer/components/PivotViewerMain.js +1 -1
  27. package/dist/cjs/PivotViewer/components/PivotViewerMain.js.map +1 -1
  28. package/dist/cjs/PivotViewer/components/Spinner.css +77 -0
  29. package/dist/cjs/PivotViewer/components/pivot/sprites.js +79 -15
  30. package/dist/cjs/PivotViewer/components/pivot/sprites.js.map +1 -1
  31. package/dist/cjs/PivotViewer/components/pivot/visibility.js +36 -10
  32. package/dist/cjs/PivotViewer/components/pivot/visibility.js.map +1 -1
  33. package/dist/cjs/PivotViewer/engine/layout.js +2 -1
  34. package/dist/cjs/PivotViewer/engine/layout.js.map +1 -1
  35. package/dist/cjs/PivotViewer/hooks/usePivotEngine.js +37 -2
  36. package/dist/cjs/PivotViewer/hooks/usePivotEngine.js.map +1 -1
  37. package/dist/cjs/PivotViewer/index.js +3 -0
  38. package/dist/cjs/PivotViewer/index.js.map +1 -1
  39. package/dist/cjs/PivotViewer/types.js +22 -0
  40. package/dist/cjs/PivotViewer/types.js.map +1 -0
  41. package/dist/cjs/TimeMachine/EventsView.css +213 -0
  42. package/dist/cjs/TimeMachine/TimeMachine.css +567 -0
  43. package/dist/cjs/TimeMachine/TimeMachine.js +8 -3
  44. package/dist/cjs/TimeMachine/TimeMachine.js.map +1 -1
  45. package/dist/esm/CommandForm/CommandForm.stories.d.ts +1 -0
  46. package/dist/esm/CommandForm/CommandForm.stories.d.ts.map +1 -1
  47. package/dist/esm/CommandForm/CommandForm.stories.js +34 -1
  48. package/dist/esm/CommandForm/CommandForm.stories.js.map +1 -1
  49. package/dist/esm/CommandForm/CommandFormFields.d.ts.map +1 -1
  50. package/dist/esm/CommandForm/CommandFormFields.js +9 -3
  51. package/dist/esm/CommandForm/CommandFormFields.js.map +1 -1
  52. package/dist/esm/CommandForm/UserRegistrationCommand.d.ts +63 -0
  53. package/dist/esm/CommandForm/UserRegistrationCommand.d.ts.map +1 -0
  54. package/dist/esm/CommandForm/UserRegistrationCommand.js +143 -0
  55. package/dist/esm/CommandForm/UserRegistrationCommand.js.map +1 -0
  56. package/dist/esm/CommandForm/ValidationMessage.d.ts +8 -0
  57. package/dist/esm/CommandForm/ValidationMessage.d.ts.map +1 -0
  58. package/dist/esm/CommandForm/ValidationMessage.js +22 -0
  59. package/dist/esm/CommandForm/ValidationMessage.js.map +1 -0
  60. package/dist/esm/CommandForm/asCommandFormField.d.ts +32 -0
  61. package/dist/esm/CommandForm/asCommandFormField.d.ts.map +1 -0
  62. package/dist/esm/CommandForm/asCommandFormField.js +45 -0
  63. package/dist/esm/CommandForm/asCommandFormField.js.map +1 -0
  64. package/dist/esm/CommandForm/fields/CheckboxField.d.ts +10 -0
  65. package/dist/esm/CommandForm/fields/CheckboxField.d.ts.map +1 -0
  66. package/dist/esm/CommandForm/fields/CheckboxField.js +11 -0
  67. package/dist/esm/CommandForm/fields/CheckboxField.js.map +1 -0
  68. package/dist/esm/CommandForm/fields/DropdownField.d.ts +15 -0
  69. package/dist/esm/CommandForm/fields/DropdownField.d.ts.map +1 -0
  70. package/dist/esm/CommandForm/fields/DropdownField.js +11 -0
  71. package/dist/esm/CommandForm/fields/DropdownField.js.map +1 -0
  72. package/dist/esm/CommandForm/fields/InputTextField.d.ts +11 -0
  73. package/dist/esm/CommandForm/fields/InputTextField.d.ts.map +1 -0
  74. package/dist/esm/CommandForm/fields/InputTextField.js +11 -0
  75. package/dist/esm/CommandForm/fields/InputTextField.js.map +1 -0
  76. package/dist/esm/CommandForm/fields/NumberField.d.ts +13 -0
  77. package/dist/esm/CommandForm/fields/NumberField.d.ts.map +1 -0
  78. package/dist/esm/CommandForm/fields/NumberField.js +11 -0
  79. package/dist/esm/CommandForm/fields/NumberField.js.map +1 -0
  80. package/dist/esm/CommandForm/fields/SliderField.d.ts +12 -0
  81. package/dist/esm/CommandForm/fields/SliderField.d.ts.map +1 -0
  82. package/dist/esm/CommandForm/fields/SliderField.js +15 -0
  83. package/dist/esm/CommandForm/fields/SliderField.js.map +1 -0
  84. package/dist/esm/CommandForm/fields/TextAreaField.d.ts +12 -0
  85. package/dist/esm/CommandForm/fields/TextAreaField.d.ts.map +1 -0
  86. package/dist/esm/CommandForm/fields/TextAreaField.js +11 -0
  87. package/dist/esm/CommandForm/fields/TextAreaField.js.map +1 -0
  88. package/dist/esm/CommandForm/fields/index.d.ts +7 -0
  89. package/dist/esm/CommandForm/fields/index.d.ts.map +1 -0
  90. package/dist/esm/CommandForm/fields/index.js +7 -0
  91. package/dist/esm/CommandForm/fields/index.js.map +1 -0
  92. package/dist/esm/CommandForm/index.d.ts +3 -4
  93. package/dist/esm/CommandForm/index.d.ts.map +1 -1
  94. package/dist/esm/CommandForm/index.js +8 -4
  95. package/dist/esm/CommandForm/index.js.map +1 -1
  96. package/dist/esm/PivotViewer/PivotViewer.css +1258 -0
  97. package/dist/esm/PivotViewer/PivotViewer.d.ts.map +1 -1
  98. package/dist/esm/PivotViewer/PivotViewer.js +14 -0
  99. package/dist/esm/PivotViewer/PivotViewer.js.map +1 -1
  100. package/dist/esm/PivotViewer/PivotViewer.stories.d.ts +1 -0
  101. package/dist/esm/PivotViewer/PivotViewer.stories.d.ts.map +1 -1
  102. package/dist/esm/PivotViewer/PivotViewer.stories.js +43 -3
  103. package/dist/esm/PivotViewer/PivotViewer.stories.js.map +1 -1
  104. package/dist/esm/PivotViewer/components/PivotCanvas.d.ts.map +1 -1
  105. package/dist/esm/PivotViewer/components/PivotCanvas.js +33 -10
  106. package/dist/esm/PivotViewer/components/PivotCanvas.js.map +1 -1
  107. package/dist/esm/PivotViewer/components/PivotViewerMain.js +1 -1
  108. package/dist/esm/PivotViewer/components/PivotViewerMain.js.map +1 -1
  109. package/dist/esm/PivotViewer/components/Spinner.css +77 -0
  110. package/dist/esm/PivotViewer/components/pivot/sprites.d.ts.map +1 -1
  111. package/dist/esm/PivotViewer/components/pivot/sprites.js +79 -15
  112. package/dist/esm/PivotViewer/components/pivot/sprites.js.map +1 -1
  113. package/dist/esm/PivotViewer/components/pivot/visibility.d.ts.map +1 -1
  114. package/dist/esm/PivotViewer/components/pivot/visibility.js +36 -10
  115. package/dist/esm/PivotViewer/components/pivot/visibility.js.map +1 -1
  116. package/dist/esm/PivotViewer/engine/layout.js +2 -1
  117. package/dist/esm/PivotViewer/engine/layout.js.map +1 -1
  118. package/dist/esm/PivotViewer/engine/pivot.worker.d.ts.map +1 -1
  119. package/dist/esm/PivotViewer/engine/pivot.worker.js +22 -7
  120. package/dist/esm/PivotViewer/engine/pivot.worker.js.map +1 -1
  121. package/dist/esm/PivotViewer/hooks/useFilteredData.d.ts +2 -2
  122. package/dist/esm/PivotViewer/hooks/useFilteredData.d.ts.map +1 -1
  123. package/dist/esm/PivotViewer/hooks/useFilteredData.js +4 -2
  124. package/dist/esm/PivotViewer/hooks/useFilteredData.js.map +1 -1
  125. package/dist/esm/PivotViewer/hooks/usePivotEngine.d.ts.map +1 -1
  126. package/dist/esm/PivotViewer/hooks/usePivotEngine.js +37 -2
  127. package/dist/esm/PivotViewer/hooks/usePivotEngine.js.map +1 -1
  128. package/dist/esm/PivotViewer/index.d.ts +2 -1
  129. package/dist/esm/PivotViewer/index.d.ts.map +1 -1
  130. package/dist/esm/PivotViewer/index.js +1 -0
  131. package/dist/esm/PivotViewer/index.js.map +1 -1
  132. package/dist/esm/PivotViewer/types.d.ts +4 -1
  133. package/dist/esm/PivotViewer/types.d.ts.map +1 -1
  134. package/dist/esm/PivotViewer/types.js +19 -2
  135. package/dist/esm/PivotViewer/types.js.map +1 -1
  136. package/dist/esm/TimeMachine/EventsView.css +213 -0
  137. package/dist/esm/TimeMachine/TimeMachine.css +567 -0
  138. package/dist/esm/TimeMachine/TimeMachine.d.ts.map +1 -1
  139. package/dist/esm/TimeMachine/TimeMachine.js +8 -3
  140. package/dist/esm/TimeMachine/TimeMachine.js.map +1 -1
  141. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  142. package/package.json +31 -32
  143. package/.storybook/main.ts +0 -24
  144. package/CommandDialog/CommandDialog.stories.tsx +0 -25
  145. package/CommandDialog/CommandDialog.tsx +0 -161
  146. package/CommandDialog/index.ts +0 -4
  147. package/CommandForm/CommandForm.stories.tsx +0 -24
  148. package/CommandForm/CommandForm.tsx +0 -266
  149. package/CommandForm/CommandFormField.tsx +0 -27
  150. package/CommandForm/CommandFormFields.tsx +0 -142
  151. package/CommandForm/DatePickerField.tsx +0 -57
  152. package/CommandForm/DropdownField.tsx +0 -65
  153. package/CommandForm/InputTextField.tsx +0 -62
  154. package/CommandForm/SliderField.tsx +0 -68
  155. package/CommandForm/index.ts +0 -10
  156. package/Common/ErrorBoundary.stories.tsx +0 -10
  157. package/Common/ErrorBoundary.tsx +0 -41
  158. package/Common/FormElement.stories.tsx +0 -10
  159. package/Common/FormElement.tsx +0 -20
  160. package/Common/Page.stories.tsx +0 -10
  161. package/Common/Page.tsx +0 -21
  162. package/Common/index.ts +0 -6
  163. package/DataPage/DataPage.stories.tsx +0 -10
  164. package/DataPage/DataPage.tsx +0 -191
  165. package/DataPage/index.ts +0 -4
  166. package/DataTables/DataTableForObservableQuery.stories.tsx +0 -10
  167. package/DataTables/DataTableForObservableQuery.tsx +0 -97
  168. package/DataTables/DataTableForQuery.stories.tsx +0 -10
  169. package/DataTables/DataTableForQuery.tsx +0 -97
  170. package/DataTables/index.ts +0 -5
  171. package/Dialogs/BusyIndicatorDialog.stories.tsx +0 -26
  172. package/Dialogs/BusyIndicatorDialog.tsx +0 -26
  173. package/Dialogs/ConfirmationDialog.stories.tsx +0 -36
  174. package/Dialogs/ConfirmationDialog.tsx +0 -75
  175. package/Dialogs/index.ts +0 -5
  176. package/Dropdown/Dropdown.tsx +0 -23
  177. package/Dropdown/index.ts +0 -4
  178. package/PivotViewer/PivotViewer.stories.tsx +0 -24
  179. package/PivotViewer/PivotViewer.tsx +0 -791
  180. package/PivotViewer/components/AxisLabels.tsx +0 -69
  181. package/PivotViewer/components/DetailPanel.tsx +0 -108
  182. package/PivotViewer/components/FilterPanel.tsx +0 -189
  183. package/PivotViewer/components/FilterPanelContainer.tsx +0 -10
  184. package/PivotViewer/components/PivotCanvas.tsx +0 -660
  185. package/PivotViewer/components/PivotViewerMain.tsx +0 -229
  186. package/PivotViewer/components/RangeHistogramFilter.tsx +0 -220
  187. package/PivotViewer/components/Spinner.tsx +0 -21
  188. package/PivotViewer/components/Toolbar.tsx +0 -130
  189. package/PivotViewer/components/ToolbarContainer.tsx +0 -10
  190. package/PivotViewer/components/index.ts +0 -12
  191. package/PivotViewer/components/pivot/animation.ts +0 -108
  192. package/PivotViewer/components/pivot/buckets.ts +0 -152
  193. package/PivotViewer/components/pivot/colorResolver.ts +0 -67
  194. package/PivotViewer/components/pivot/constants.ts +0 -46
  195. package/PivotViewer/components/pivot/sprites.ts +0 -265
  196. package/PivotViewer/components/pivot/visibility.ts +0 -319
  197. package/PivotViewer/constants.ts +0 -9
  198. package/PivotViewer/engine/layout.ts +0 -149
  199. package/PivotViewer/engine/pivot.worker.ts +0 -86
  200. package/PivotViewer/engine/store.ts +0 -437
  201. package/PivotViewer/engine/types.ts +0 -255
  202. package/PivotViewer/hooks/index.ts +0 -13
  203. package/PivotViewer/hooks/useContainerDimensions.ts +0 -45
  204. package/PivotViewer/hooks/useDimensionState.ts +0 -53
  205. package/PivotViewer/hooks/useFilterOptions.ts +0 -36
  206. package/PivotViewer/hooks/useFilterPanelDrag.ts +0 -49
  207. package/PivotViewer/hooks/useFilterState.ts +0 -106
  208. package/PivotViewer/hooks/useFilteredData.ts +0 -119
  209. package/PivotViewer/hooks/usePanning.ts +0 -163
  210. package/PivotViewer/hooks/usePivotEngine.ts +0 -252
  211. package/PivotViewer/hooks/useSelectedItem.ts +0 -402
  212. package/PivotViewer/hooks/useWheelZoom.ts +0 -114
  213. package/PivotViewer/hooks/useZoomState.ts +0 -34
  214. package/PivotViewer/index.ts +0 -7
  215. package/PivotViewer/types.ts +0 -59
  216. package/PivotViewer/utils/animations.ts +0 -249
  217. package/PivotViewer/utils/constants.ts +0 -20
  218. package/PivotViewer/utils/index.ts +0 -6
  219. package/PivotViewer/utils/selection.ts +0 -292
  220. package/PivotViewer/utils/utils.ts +0 -259
  221. package/TimeMachine/EventsView.stories.tsx +0 -10
  222. package/TimeMachine/EventsView.tsx +0 -119
  223. package/TimeMachine/Properties.stories.tsx +0 -10
  224. package/TimeMachine/Properties.tsx +0 -98
  225. package/TimeMachine/ReadModelView.stories.tsx +0 -10
  226. package/TimeMachine/ReadModelView.tsx +0 -143
  227. package/TimeMachine/TimeMachine.stories.tsx +0 -10
  228. package/TimeMachine/TimeMachine.tsx +0 -244
  229. package/TimeMachine/index.ts +0 -8
  230. package/TimeMachine/types.ts +0 -23
  231. package/dist/cjs/CommandForm/DatePickerField.js +0 -31
  232. package/dist/cjs/CommandForm/DatePickerField.js.map +0 -1
  233. package/dist/cjs/CommandForm/DropdownField.js +0 -31
  234. package/dist/cjs/CommandForm/DropdownField.js.map +0 -1
  235. package/dist/cjs/CommandForm/InputTextField.js +0 -32
  236. package/dist/cjs/CommandForm/InputTextField.js.map +0 -1
  237. package/dist/cjs/CommandForm/SliderField.js +0 -34
  238. package/dist/cjs/CommandForm/SliderField.js.map +0 -1
  239. package/dist/esm/CommandForm/DatePickerField.d.ts +0 -20
  240. package/dist/esm/CommandForm/DatePickerField.d.ts.map +0 -1
  241. package/dist/esm/CommandForm/DatePickerField.js +0 -29
  242. package/dist/esm/CommandForm/DatePickerField.js.map +0 -1
  243. package/dist/esm/CommandForm/DropdownField.d.ts +0 -24
  244. package/dist/esm/CommandForm/DropdownField.d.ts.map +0 -1
  245. package/dist/esm/CommandForm/DropdownField.js +0 -29
  246. package/dist/esm/CommandForm/DropdownField.js.map +0 -1
  247. package/dist/esm/CommandForm/InputTextField.d.ts +0 -20
  248. package/dist/esm/CommandForm/InputTextField.d.ts.map +0 -1
  249. package/dist/esm/CommandForm/InputTextField.js +0 -30
  250. package/dist/esm/CommandForm/InputTextField.js.map +0 -1
  251. package/dist/esm/CommandForm/SliderField.d.ts +0 -23
  252. package/dist/esm/CommandForm/SliderField.d.ts.map +0 -1
  253. package/dist/esm/CommandForm/SliderField.js +0 -32
  254. package/dist/esm/CommandForm/SliderField.js.map +0 -1
  255. package/global.d.ts +0 -11
  256. package/index.ts +0 -22
  257. package/useOverlayZIndex.ts +0 -32
  258. package/vite.config.ts +0 -80
@@ -1,660 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
5
- import * as PIXI from 'pixi.js';
6
- import type { ItemId, LayoutResult, GroupingResult } from '../engine/types';
7
- import type { ViewMode } from './Toolbar';
8
- import { createCssColorResolver, resolveCardColors } from './pivot/colorResolver';
9
- import { createCardSprite as createCardSpriteExternal, updateCardContent as updateCardContentExternal, clearSpritePool } from './pivot/sprites';
10
- import { syncSpritesToViewport } from './pivot/visibility';
11
- import { updateBucketBackgrounds as updateBucketBackgroundsExternal, updateHighlight as updateHighlightExternal } from './pivot/buckets';
12
- import { startAnimationLoop as startAnimationLoopExternal, updatePositions as updatePositionsExternal } from './pivot/animation';
13
- import { ANIMATION_SPEED, DEFAULT_COLORS, type CardSprite, type CardColors } from './pivot/constants';
14
-
15
- export interface PivotCanvasProps<TItem extends object> {
16
- /** Original items array */
17
- items: TItem[];
18
-
19
- /** Layout positions */
20
- layout: LayoutResult;
21
-
22
- /** Grouping information */
23
- grouping: GroupingResult;
24
-
25
- /** Visible item IDs */
26
- visibleIds: Uint32Array;
27
-
28
- /** Card dimensions */
29
- cardWidth: number;
30
- cardHeight: number;
31
-
32
- /** Zoom level */
33
- zoomLevel: number;
34
-
35
- /** Pan offset */
36
- panX: number;
37
- panY: number;
38
-
39
- /** Viewport dimensions (visible area) */
40
- viewportWidth: number;
41
- viewportHeight: number;
42
-
43
- /** Selected item ID */
44
- selectedId: ItemId | null;
45
-
46
- /** Hovered group index */
47
- hoveredGroupIndex: number | null;
48
-
49
- /** Current view mode */
50
- viewMode: ViewMode;
51
-
52
- /** Is zooming animation in progress */
53
- isZooming?: boolean;
54
-
55
- /** Card renderer function */
56
- cardRenderer?: (item: TItem) => ReactNode;
57
-
58
- /** ID resolver */
59
- resolveId: (item: TItem, index: number) => string | number;
60
-
61
- /** Click handler */
62
- onCardClick: (item: TItem, e: MouseEvent, id: number | string) => void;
63
-
64
- /** Pan handlers */
65
- onPanStart: (e: MouseEvent) => void;
66
- onPanMove: (e: MouseEvent) => void;
67
- onPanEnd: () => void;
68
- containerRef: React.RefObject<HTMLDivElement | null>;
69
- }
70
-
71
- // `CardSprite` type moved to ./pivot/constants and imported above
72
-
73
- // constants and CardColors type moved to ./pivot/constants
74
-
75
- export function PivotCanvas<TItem extends object>({
76
- items,
77
- layout,
78
- grouping,
79
- visibleIds,
80
- cardWidth,
81
- cardHeight,
82
- zoomLevel,
83
- panX,
84
- panY,
85
- viewportWidth,
86
- viewportHeight,
87
- selectedId,
88
- hoveredGroupIndex,
89
- isZooming: _isZooming = false,
90
- resolveId: _resolveId,
91
- onCardClick,
92
- onPanStart,
93
- onPanMove,
94
- onPanEnd,
95
- viewMode,
96
- cardRenderer,
97
- containerRef,
98
- }: PivotCanvasProps<TItem>) {
99
- console.log('[PivotCanvas] Render', { viewMode });
100
- // Use the containerRef passed from the parent viewport so we append the Pixi
101
- // canvas and spacer into the actual scrollable element.
102
- const parentContainerRef = containerRef;
103
- // Mark intentionally-unused destructured props as used to satisfy lint
104
- void _isZooming;
105
- void _resolveId;
106
- const canvasRef = useRef<HTMLCanvasElement | null>(null);
107
- const spacerRef = useRef<HTMLDivElement | null>(null);
108
- const appRef = useRef<PIXI.Application | null>(null);
109
- const rootRef = useRef<PIXI.Container | null>(null);
110
- const bucketsContainerRef = useRef<PIXI.Container | null>(null);
111
- const spritesRef = useRef<Map<ItemId, CardSprite>>(new Map());
112
- const animationFrameRef = useRef<number>(0);
113
- const mountedRef = useRef(true);
114
- const [pixiReady, setPixiReady] = useState(false);
115
- const isAnimatingRef = useRef(false);
116
- const needsRenderRef = useRef(false);
117
- const initializingRef = useRef(false);
118
- const isViewTransitionRef = useRef(false);
119
- const lastViewChangeTimeRef = useRef(0);
120
- const previousViewModeRef = useRef<ViewMode>(viewMode);
121
- const prevLayoutRef = useRef<LayoutResult | null>(null);
122
- const prevGroupingRef = useRef<GroupingResult | null>(null);
123
- const cardColorsRef = useRef<CardColors>(DEFAULT_COLORS);
124
- void cardRenderer; // unused in Pixi renderer but keep prop compatibility
125
-
126
- const cssColorResolver = useMemo(() => createCssColorResolver(), []);
127
-
128
- const onPanStartRef = useRef(onPanStart);
129
- const onPanMoveRef = useRef(onPanMove);
130
- const onPanEndRef = useRef(onPanEnd);
131
- const onCardClickRef = useRef(onCardClick);
132
- const prevPanRef = useRef({ x: panX, y: panY });
133
-
134
- // Initialize Pixi Application
135
- useEffect(() => {
136
- // ... existing code ...
137
- onPanMoveRef.current = onPanMove;
138
- onPanEndRef.current = onPanEnd;
139
- onCardClickRef.current = onCardClick;
140
- }, [onPanStart, onPanMove, onPanEnd, onCardClick]);
141
-
142
- useEffect(() => {
143
- cardColorsRef.current = resolveCardColors(cssColorResolver);
144
- }, [cssColorResolver]);
145
-
146
- useEffect(() => {
147
- // Reset mounted flag
148
- mountedRef.current = true;
149
-
150
- if (!parentContainerRef || !parentContainerRef.current) {
151
- return;
152
- }
153
-
154
- // Prevent multiple simultaneous initializations
155
- if (initializingRef.current || appRef.current) {
156
- return;
157
- }
158
-
159
- initializingRef.current = true;
160
- let app: PIXI.Application | null = null;
161
- // Handler references declared here so cleanup can remove them later.
162
-
163
- (async () => {
164
- try {
165
- // Prefer the new init API (v8+) to avoid deprecation issues. Fall back
166
- // to the constructor options when `init` is not available.
167
- const options = {
168
- backgroundAlpha: 0,
169
- antialias: false,
170
- autoStart: false,
171
- autoDensity: true,
172
- resolution: window.devicePixelRatio || 1,
173
- width: viewportWidth > 0 ? viewportWidth : 800,
174
- height: viewportHeight > 0 ? viewportHeight : 600,
175
- } as PIXI.ApplicationOptions;
176
-
177
- app = new PIXI.Application();
178
- if ((app as any).init && typeof (app as any).init === 'function') {
179
- // init may return a promise in some builds
180
-
181
- // @ts-ignore
182
- await app.init(options);
183
- } else {
184
- // Fall back to constructor that accepts options
185
- app.destroy?.();
186
- app = new PIXI.Application(options);
187
- }
188
-
189
- if (!mountedRef.current || !parentContainerRef.current) {
190
- // Component unmounted during initialization
191
- if (app && typeof app.destroy === 'function') app.destroy(true, { children: true });
192
- initializingRef.current = false;
193
- return;
194
- }
195
-
196
- appRef.current = app;
197
-
198
- // Create containers in correct z-order
199
- // 1. Bucket backgrounds (zebra striping) - bottom
200
- const bucketsContainer = new PIXI.Container();
201
- bucketsContainerRef.current = bucketsContainer;
202
- app.stage.addChild(bucketsContainer);
203
-
204
- // 2. Cards container - on top of buckets
205
- const root = new PIXI.Container();
206
- rootRef.current = root;
207
- app.stage.addChild(root);
208
-
209
- // Resolve canvas element (different Pixi builds expose it as `view` or
210
- // `canvas`).
211
- const canvasEl = (app.view ?? (app as any).canvas ?? app.renderer?.view) as HTMLCanvasElement | undefined;
212
-
213
- // Place canvas outside the scrollable content so native scrolling
214
- // doesn't move the canvas DOM element itself. We overlay the canvas
215
- // on top of the scroll area by inserting it into the parent element
216
- // (or the container itself if parent is not available). This ensures
217
- // the Pixi canvas remains stable while we move the Pixi world inside
218
- // it to represent camera pan.
219
- const overlayParent = parentContainerRef.current.parentElement ?? parentContainerRef.current;
220
- if (canvasEl) {
221
- if (canvasEl.parentElement) {
222
- canvasEl.parentElement.removeChild(canvasEl);
223
- }
224
- overlayParent.appendChild(canvasEl);
225
- canvasRef.current = canvasEl;
226
- } else if ((app as any).canvas) {
227
- const c = (app as any).canvas;
228
- if (c.parentElement) {
229
- c.parentElement.removeChild(c);
230
- }
231
- overlayParent.appendChild(c);
232
- canvasRef.current = c;
233
- }
234
-
235
- // Position the canvas to overlay the scrollable container area.
236
- if (canvasRef.current && parentContainerRef.current) {
237
- const parentBounds = parentContainerRef.current.getBoundingClientRect();
238
- void parentBounds;
239
- canvasRef.current.style.position = 'absolute';
240
- // Place canvas relative to the overlayParent's coordinate space.
241
- // If overlayParent is the immediate parent, top/left 0 aligns it.
242
- const offsetLeft = parentContainerRef.current.offsetLeft;
243
- const offsetTop = parentContainerRef.current.offsetTop;
244
- canvasRef.current.style.left = `${offsetLeft}px`;
245
- canvasRef.current.style.top = `${offsetTop}px`;
246
- canvasRef.current.style.width = `${parentContainerRef.current.clientWidth}px`;
247
- canvasRef.current.style.height = `${parentContainerRef.current.clientHeight}px`;
248
- // Place canvas behind the scrollable container (which has z-index 1)
249
- // so scrollbars appear on top.
250
- canvasRef.current.style.zIndex = '0';
251
- // Disable pointer events on canvas so they pass through to the viewport if needed,
252
- // though viewport is on top anyway.
253
- canvasRef.current.style.pointerEvents = 'none';
254
- }
255
-
256
- // We handle clicks and interactions manually in PivotViewerMain now,
257
- // so we don't need to configure Pixi events on the container.
258
- // This avoids z-index conflicts and event propagation issues.
259
-
260
- // Make canvas fill container with absolute positioning
261
- if (canvasRef.current) {
262
- canvasRef.current.style.display = 'block';
263
- // Ensure canvas does not capture events so they pass through to the viewport
264
- canvasRef.current.style.pointerEvents = 'none';
265
- }
266
-
267
- // Setup stage events for background panning
268
- app.stage.eventMode = 'static';
269
- app.stage.hitArea = new PIXI.Rectangle(0, 0, viewportWidth, viewportHeight);
270
-
271
- app.stage.on('pointerdown', (e) => {
272
- // Only handle if it reached the stage (background)
273
- // Sprites stop propagation, so this is safe
274
- onPanStartRef.current(e.nativeEvent as unknown as MouseEvent);
275
- });
276
-
277
- app.stage.on('globalpointermove', (e) => {
278
- onPanMoveRef.current(e.nativeEvent as unknown as MouseEvent);
279
- });
280
-
281
- app.stage.on('globalpointerup', () => {
282
- onPanEndRef.current();
283
- });
284
-
285
- // We no longer need manual event listeners on parentEl because Pixi
286
- // is now listening to events on parentEl directly via setTargetElement.
287
- // This allows Pixi to handle hit testing through the transparent container.
288
- const parentEl = parentContainerRef.current;
289
- if (parentEl) {
290
- // handleMouseDown = (e: Event) => onPanStartRef.current(e as unknown);
291
- // handleMouseMove = (e: Event) => onPanMoveRef.current(e as unknown);
292
- // handleMouseUp = () => onPanEndRef.current();
293
- // parentEl.addEventListener('mousedown', handleMouseDown);
294
- // parentEl.addEventListener('mousemove', handleMouseMove);
295
- // parentEl.addEventListener('mouseup', handleMouseUp);
296
- // parentEl.addEventListener('mouseleave', handleMouseUp);
297
- // window.addEventListener('mouseup', handleMouseUp);
298
- // window.addEventListener('pointerup', handleMouseUp);
299
- }
300
-
301
- // Immediately size to container to avoid delay
302
- if (viewportWidth > 0 && viewportHeight > 0) {
303
- app.renderer?.resize(viewportWidth, viewportHeight);
304
- }
305
-
306
- setPixiReady(true);
307
- initializingRef.current = false;
308
-
309
- // Trigger initial render
310
- needsRenderRef.current = true;
311
- app.renderer?.render(app.stage);
312
- } catch (error) {
313
- console.error('Failed to initialize Pixi.js:', error);
314
- initializingRef.current = false;
315
- }
316
- })();
317
-
318
- return () => {
319
- mountedRef.current = false;
320
- setPixiReady(false);
321
- cancelAnimationFrame(animationFrameRef.current);
322
-
323
- if (appRef.current && typeof appRef.current.destroy === 'function') {
324
- appRef.current.destroy(true, { children: true });
325
- appRef.current = null;
326
- rootRef.current = null;
327
- }
328
-
329
- // Clear sprite pool to avoid holding onto destroyed textures
330
- clearSpritePool();
331
-
332
- // Remove any event listeners we attached to the parent container
333
- try {
334
- const parentEl = parentContainerRef.current;
335
- if (parentEl) {
336
- // if (handleMouseDown) parentEl.removeEventListener('mousedown', handleMouseDown);
337
- // if (handleMouseMove) parentEl.removeEventListener('mousemove', handleMouseMove);
338
- // if (handleMouseUp) parentEl.removeEventListener('mouseup', handleMouseUp);
339
- // if (handleMouseUp) parentEl.removeEventListener('mouseleave', handleMouseUp);
340
- // if (handleMouseUp) {
341
- // window.removeEventListener('mouseup', handleMouseUp);
342
- // window.removeEventListener('pointerup', handleMouseUp);
343
- // }
344
- }
345
- } catch (e) {
346
- void e;
347
- }
348
- // Remove DOM nodes we appended
349
- try {
350
- if (canvasRef.current && canvasRef.current.parentElement) {
351
- canvasRef.current.parentElement.removeChild(canvasRef.current);
352
- }
353
- } catch (e) {
354
- void e;
355
- }
356
- };
357
- }, [viewportWidth, viewportHeight]);
358
-
359
- // Handle canvas resize
360
- useEffect(() => {
361
- if (!parentContainerRef || !parentContainerRef.current || !appRef.current || !pixiReady) return;
362
-
363
- const container = parentContainerRef.current;
364
- const app = appRef.current;
365
-
366
- let resizeTimeout: ReturnType<typeof setTimeout>;
367
-
368
- const handleResize = () => {
369
- // Size canvas to viewport dimensions from props
370
- if (viewportWidth > 0 && viewportHeight > 0) {
371
- app.renderer?.resize(viewportWidth, viewportHeight);
372
- app.stage.hitArea = new PIXI.Rectangle(0, 0, viewportWidth, viewportHeight);
373
-
374
- // Keep canvas DOM size in sync with container
375
- if (canvasRef.current && parentContainerRef.current) {
376
- canvasRef.current.style.width = `${parentContainerRef.current.clientWidth}px`;
377
- canvasRef.current.style.height = `${parentContainerRef.current.clientHeight}px`;
378
- // Also update left/top in case the container moved
379
- canvasRef.current.style.left = `${parentContainerRef.current.offsetLeft}px`;
380
- canvasRef.current.style.top = `${parentContainerRef.current.offsetTop}px`;
381
- }
382
- }
383
- };
384
-
385
- const debouncedResize = () => {
386
- clearTimeout(resizeTimeout);
387
- resizeTimeout = setTimeout(handleResize, 150);
388
- };
389
-
390
- // Initial resize (immediate)
391
- handleResize();
392
-
393
- // Watch for size changes (debounced)
394
- const resizeObserver = new ResizeObserver(debouncedResize);
395
- resizeObserver.observe(container);
396
-
397
- return () => {
398
- clearTimeout(resizeTimeout);
399
- resizeObserver.disconnect();
400
- };
401
- }, [pixiReady, viewportWidth, viewportHeight]);
402
-
403
- // Update bucket backgrounds only when layout/grouping changes
404
- useEffect(() => {
405
- if (!bucketsContainerRef.current || !pixiReady) return;
406
- updateBucketBackgroundsExternal(bucketsContainerRef.current, parentContainerRef.current, grouping, layout, zoomLevel, cardColorsRef.current, viewMode);
407
- needsRenderRef.current = true;
408
- appRef.current?.renderer?.render(appRef.current.stage);
409
- }, [grouping, layout, zoomLevel, viewMode, pixiReady]);
410
-
411
- useEffect(() => {
412
- if (!rootRef.current || !pixiReady) {
413
- return;
414
- }
415
-
416
- // Check if this is a view mode change (not just pan/scroll)
417
- const viewModeChanged = previousViewModeRef.current !== viewMode;
418
- const groupingChanged = prevGroupingRef.current !== grouping;
419
-
420
- if (viewModeChanged || groupingChanged) {
421
- isViewTransitionRef.current = true;
422
- lastViewChangeTimeRef.current = Date.now();
423
- previousViewModeRef.current = viewMode;
424
- prevGroupingRef.current = grouping;
425
- }
426
-
427
- // Update spacer dimensions to match scaled world size
428
- if (spacerRef.current) {
429
- const spacer = spacerRef.current;
430
- const worldWidth = (layout.totalWidth || viewportWidth) * zoomLevel;
431
- const worldHeight = (layout.totalHeight || viewportHeight) * zoomLevel;
432
- spacer.style.width = `${Math.max(worldWidth, viewportWidth)}px`;
433
- spacer.style.height = `${Math.max(worldHeight, viewportHeight)}px`;
434
- }
435
-
436
- // Ensure scroll spacer matches layout so the container becomes scrollable and
437
- // native scrollLeft/scrollTop reflect the camera position.
438
- if (parentContainerRef.current) {
439
- const spacer = spacerRef.current;
440
- if (spacer) {
441
- // Debug: log spacer and layout values to detect mismatches
442
- }
443
- }
444
-
445
- const panDeltaX = panX - prevPanRef.current.x;
446
- const panDeltaY = panY - prevPanRef.current.y;
447
- prevPanRef.current = { x: panX, y: panY };
448
-
449
- // Sync sprites into viewport and create/remove as needed
450
- // Provide wrappers for sprite creation and content update so helpers have required context
451
- syncSpritesToViewport({
452
- root: rootRef.current,
453
- container: parentContainerRef.current,
454
- sprites: spritesRef.current,
455
- layout,
456
- visibleIds,
457
- items,
458
- cardWidth,
459
- cardHeight,
460
- panX,
461
- panY,
462
- panDeltaX,
463
- panDeltaY,
464
- zoomLevel,
465
- viewportWidth,
466
- viewportHeight,
467
- createCardSprite: (id: string | number, x: number, y: number) => createCardSpriteExternal(
468
- id,
469
- x,
470
- y,
471
- items as any,
472
- (item: TItem, e: any, id: string | number) => (onCardClickRef.current as any)(item, e, id),
473
- (onPanStart as any),
474
- cardWidth,
475
- cardHeight,
476
- cardColorsRef.current
477
- ),
478
- updateCardContent: (sprite: CardSprite | any, item: any) => updateCardContentExternal(sprite, item, selectedId, cardWidth, cardHeight, cardColorsRef.current),
479
- isViewTransition: isViewTransitionRef.current || (Date.now() - lastViewChangeTimeRef.current < 1000),
480
- prevLayout: prevLayoutRef.current,
481
- });
482
- needsRenderRef.current = true;
483
- startAnimationLoopExternal({
484
- mountedRef,
485
- appRef,
486
- animationFrameRef,
487
- isAnimatingRef,
488
- needsRenderRef,
489
- spritesRef,
490
- isViewTransitionRef,
491
- });
492
- }, [layout, visibleIds, items, cardWidth, cardHeight, pixiReady, zoomLevel, panX, panY, grouping, viewMode]);
493
-
494
- // Update prevLayoutRef after processing layout changes
495
- useEffect(() => {
496
- prevLayoutRef.current = layout;
497
- }, [layout]);
498
-
499
- useEffect(() => {
500
- if (!rootRef.current || !bucketsContainerRef.current) return;
501
-
502
- // Camera transform: move world opposite to camera position. Prefer the
503
- // native container scroll positions where available (they are authoritative
504
- // during user scrolls) and fall back to the passed pan props.
505
- const effectivePanX = parentContainerRef.current ? parentContainerRef.current.scrollLeft : panX;
506
- const effectivePanY = parentContainerRef.current ? parentContainerRef.current.scrollTop : panY;
507
-
508
- // Apply zoom and position to root and buckets.
509
- rootRef.current.scale.set(zoomLevel);
510
- bucketsContainerRef.current.scale.set(zoomLevel);
511
- rootRef.current.position.set(-effectivePanX, -effectivePanY);
512
- bucketsContainerRef.current.position.set(-effectivePanX, -effectivePanY);
513
- appRef.current?.renderer?.render(appRef.current.stage);
514
- }, [zoomLevel, panX, panY]);
515
-
516
- useEffect(() => {
517
- if (!rootRef.current) return;
518
- updateSelection();
519
- needsRenderRef.current = true;
520
- appRef.current?.renderer.render(appRef.current.stage);
521
- }, [selectedId, items]);
522
-
523
- useEffect(() => {
524
- if (!rootRef.current) return;
525
- updateHighlight();
526
- needsRenderRef.current = true;
527
- appRef.current?.renderer.render(appRef.current.stage);
528
- }, [hoveredGroupIndex, layout, grouping]);
529
-
530
- // Note: animation loop and bucket background updates are delegated to
531
- // external helpers (`startAnimationLoopExternal` and
532
- // `updateBucketBackgroundsExternal`) and invoked where needed. We don't
533
- // expose local wrappers to avoid unused-function lint warnings.
534
-
535
- // Listen to native scroll events on the parent container so we update the
536
- // Pixi world immediately when the user scrolls (native scrollbar or
537
- // programmatic). This ensures `syncSpritesToViewport` runs on scroll and
538
- // creates/destroys sprites as the viewport moves.
539
- useEffect(() => {
540
- if (!pixiReady || !parentContainerRef || !parentContainerRef.current || !appRef.current || !rootRef.current) return;
541
-
542
- const container = parentContainerRef.current;
543
- const app = appRef.current;
544
-
545
- // rAF-batched scroll handling: store the latest scroll values and process
546
- // them once per animation frame to avoid heavy synchronous work inside
547
- // the scroll event which causes jank and de-synchronisation between the
548
- // compositor and Pixi render updates.
549
- const lastScroll = { x: container.scrollLeft, y: container.scrollTop };
550
- const pendingRef = { scheduled: false } as { scheduled: boolean };
551
-
552
- const processScroll = () => {
553
- pendingRef.scheduled = false;
554
- try {
555
- // Read directly from container to ensure consistency with visibility logic
556
- // and to handle cases where scroll changes without event (e.g. resize clamping)
557
- const effectivePanX = container.scrollLeft;
558
- const effectivePanY = container.scrollTop;
559
-
560
- // Update lastScroll to keep it in sync
561
- lastScroll.x = effectivePanX;
562
- lastScroll.y = effectivePanY;
563
-
564
- if (rootRef.current && bucketsContainerRef.current) {
565
- rootRef.current.scale.set(zoomLevel);
566
- bucketsContainerRef.current.scale.set(zoomLevel);
567
- const invScale = zoomLevel && zoomLevel !== 0 ? 1 / zoomLevel : 1;
568
- void invScale;
569
- rootRef.current.position.set(-effectivePanX, -effectivePanY);
570
- bucketsContainerRef.current.position.set(-effectivePanX, -effectivePanY);
571
- }
572
-
573
- syncSpritesToViewport({
574
- root: rootRef.current,
575
- container: parentContainerRef.current,
576
- sprites: spritesRef.current,
577
- layout,
578
- visibleIds,
579
- items,
580
- cardWidth,
581
- cardHeight,
582
- panX,
583
- panY,
584
- zoomLevel,
585
- viewportWidth,
586
- viewportHeight,
587
- createCardSprite: (id: string | number, x: number, y: number) => createCardSpriteExternal(
588
- id, x, y, items as any,
589
- (item, e, id) => (onCardClickRef.current as any)(item, e, id),
590
- (e) => (onPanStartRef.current as any)(e, true), // Explicitly mark as on-card for Pixi events
591
- cardWidth, cardHeight, cardColorsRef.current
592
- ),
593
- updateCardContent: (sprite: CardSprite | any, item: any) => updateCardContentExternal(sprite, item, selectedId, cardWidth, cardHeight, cardColorsRef.current),
594
- isViewTransition: isViewTransitionRef.current || (Date.now() - lastViewChangeTimeRef.current < 1000),
595
- });
596
- needsRenderRef.current = true;
597
- app.renderer?.render(app.stage);
598
- } catch (e) {
599
- console.error('[PivotCanvas] processScroll error', e);
600
- }
601
- };
602
-
603
- const onScroll = () => {
604
- // capture latest scroll positions quickly and schedule work
605
- lastScroll.x = container.scrollLeft;
606
- lastScroll.y = container.scrollTop;
607
- if (!pendingRef.scheduled) {
608
- pendingRef.scheduled = true;
609
- requestAnimationFrame(processScroll);
610
- }
611
- };
612
-
613
- container.addEventListener('scroll', onScroll, { passive: true });
614
-
615
- return () => {
616
- container.removeEventListener('scroll', onScroll);
617
- };
618
- }, [pixiReady, layout, visibleIds, items, cardWidth, cardHeight, zoomLevel, viewportWidth, viewportHeight, panX, panY, grouping, viewMode, selectedId, onCardClick, onPanStart]);
619
-
620
- function createCardSprite(id: ItemId, x: number, y: number): CardSprite {
621
- return createCardSpriteExternal(
622
- id, x, y, items as any,
623
- (item, e, id) => (onCardClickRef.current as any)(item, e, id),
624
- (e) => (onPanStartRef.current as any)(e, true),
625
- cardWidth, cardHeight, cardColorsRef.current
626
- );
627
- }
628
- // Mark these helpers as used (they may be referenced externally or via callbacks)
629
- void createCardSprite;
630
-
631
- function updateCardContent(sprite: CardSprite, item: TItem) {
632
- return updateCardContentExternal(sprite as any, item as any, selectedId, cardWidth, cardHeight, cardColorsRef.current) as any;
633
- }
634
-
635
- function updatePositions(): boolean {
636
- return updatePositionsExternal(spritesRef.current, isViewTransitionRef, ANIMATION_SPEED);
637
- }
638
-
639
- void updatePositions;
640
-
641
- function updateSelection() {
642
- const sprites = spritesRef.current;
643
-
644
- for (const sprite of sprites.values()) {
645
- const val = (items as any)[String(sprite.itemId)];
646
- updateCardContent(sprite, val);
647
- }
648
- }
649
-
650
- function updateHighlight() {
651
- updateHighlightExternal(bucketsContainerRef.current, parentContainerRef.current, grouping, layout, hoveredGroupIndex, cardWidth, zoomLevel);
652
- }
653
-
654
- void updateHighlight;
655
-
656
- // This component renders into the parent `containerRef` (we append Pixi canvas
657
- // and spacer directly into that DOM node). Return null so we don't replace or
658
- // reassign the parent's ref which must remain the scrollable viewport element.
659
- return null;
660
- }