@aiquants/resize-panels 2.0.0 → 2.0.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 (64) hide show
  1. package/dist/GlobalDebugOverlay.d.ts +4 -0
  2. package/dist/Panel.d.ts +13 -0
  3. package/dist/{src/PanelDebugInfo.d.ts → PanelDebugInfo.d.ts} +2 -14
  4. package/dist/PanelGroup.d.ts +2 -0
  5. package/dist/PanelResizeHandle.d.ts +2 -0
  6. package/dist/allocateLayout.d.ts +12 -0
  7. package/dist/context.d.ts +3 -0
  8. package/dist/debugOverlayStore.d.ts +32 -0
  9. package/dist/{src/hooks.d.ts → hooks.d.ts} +8 -23
  10. package/dist/index.d.ts +13 -2
  11. package/dist/reducer.d.ts +8 -0
  12. package/dist/roundHalfToEven.d.ts +1 -0
  13. package/dist/types.d.ts +183 -0
  14. package/dist/utils/simple-logger.d.ts +37 -0
  15. package/dist/utils.d.ts +16 -0
  16. package/package.json +2 -3
  17. package/dist/src/GlobalDebugOverlay.d.ts +0 -21
  18. package/dist/src/GlobalDebugOverlay.d.ts.map +0 -1
  19. package/dist/src/Panel.d.ts +0 -46
  20. package/dist/src/Panel.d.ts.map +0 -1
  21. package/dist/src/PanelDebugInfo.d.ts.map +0 -1
  22. package/dist/src/PanelGroup.d.ts +0 -7
  23. package/dist/src/PanelGroup.d.ts.map +0 -1
  24. package/dist/src/PanelResizeHandle.d.ts +0 -7
  25. package/dist/src/PanelResizeHandle.d.ts.map +0 -1
  26. package/dist/src/allocateLayout.d.ts +0 -60
  27. package/dist/src/allocateLayout.d.ts.map +0 -1
  28. package/dist/src/context.d.ts +0 -12
  29. package/dist/src/context.d.ts.map +0 -1
  30. package/dist/src/debugOverlayStore.d.ts +0 -69
  31. package/dist/src/debugOverlayStore.d.ts.map +0 -1
  32. package/dist/src/hooks.d.ts.map +0 -1
  33. package/dist/src/index.d.ts +0 -32
  34. package/dist/src/index.d.ts.map +0 -1
  35. package/dist/src/reducer.d.ts +0 -49
  36. package/dist/src/reducer.d.ts.map +0 -1
  37. package/dist/src/roundHalfToEven.d.ts +0 -10
  38. package/dist/src/roundHalfToEven.d.ts.map +0 -1
  39. package/dist/src/types.d.ts +0 -481
  40. package/dist/src/types.d.ts.map +0 -1
  41. package/dist/src/utils/simple-logger.d.ts +0 -111
  42. package/dist/src/utils/simple-logger.d.ts.map +0 -1
  43. package/dist/src/utils.d.ts +0 -164
  44. package/dist/src/utils.d.ts.map +0 -1
  45. package/dist/tests/support/dom-harness.d.ts +0 -89
  46. package/dist/tests/support/dom-harness.d.ts.map +0 -1
  47. package/src/GlobalDebugOverlay.tsx +0 -284
  48. package/src/Panel.tsx +0 -297
  49. package/src/PanelDebugInfo.tsx +0 -94
  50. package/src/PanelGroup.tsx +0 -245
  51. package/src/PanelResizeHandle.tsx +0 -758
  52. package/src/allocateLayout.ts +0 -412
  53. package/src/context.ts +0 -25
  54. package/src/debugOverlayStore.ts +0 -355
  55. package/src/hooks.ts +0 -376
  56. package/src/index.ts +0 -93
  57. package/src/reducer.ts +0 -472
  58. package/src/roundHalfToEven.ts +0 -40
  59. package/src/styles/components.entry.css +0 -10
  60. package/src/styles/resize-panels.css +0 -1
  61. package/src/styles/standalone.entry.css +0 -12
  62. package/src/types.ts +0 -505
  63. package/src/utils/simple-logger.ts +0 -186
  64. package/src/utils.ts +0 -320
@@ -1,355 +0,0 @@
1
- /**
2
- * @file Debug overlay store utilities
3
- * デバッグオーバーレイのストアユーティリティ
4
- */
5
-
6
- import { useSyncExternalStore } from "react"
7
- import type { ContainerSize, PanelDirection, PanelLayoutData, ResizeHandleLayoutData } from "./types"
8
-
9
- /**
10
- * Panel layout data enriched with the DOM measurement the overlay compares it against.
11
- * オーバーレイが突き合わせる DOM 実測値を添えたパネルレイアウトデータ。
12
- */
13
- export type DebugPanelSnapshot = PanelLayoutData & {
14
- measuredPixelSize?: number
15
- measuredPercentageSize?: number
16
- }
17
-
18
- /**
19
- * Snapshot of the debug overlay state across panel groups.
20
- * デバッグオーバーレイのスナップショット状態を表す構造体。
21
- */
22
- export type DebugOverlaySnapshot = {
23
- ownerId: string | null
24
- groups: DebugGroupState[]
25
- }
26
-
27
- /**
28
- * Aggregated state for a panel group tracked by the debug overlay.
29
- * デバッグオーバーレイが追跡するパネルグループの集約状態。
30
- */
31
- export type DebugGroupState = {
32
- groupId: string
33
- displayName: string
34
- direction: PanelDirection
35
- containerSize: ContainerSize
36
- panels: DebugPanelSnapshot[]
37
- handles: ResizeHandleLayoutData[]
38
- index: number
39
- }
40
-
41
- type DebugGroupUpdate = {
42
- displayName: string
43
- direction: PanelDirection
44
- containerSize: ContainerSize
45
- panels: DebugPanelSnapshot[]
46
- handles: ResizeHandleLayoutData[]
47
- }
48
-
49
- type StoreListener = () => void
50
-
51
- type DebugGroupEntry = DebugGroupState & {
52
- serializedPanels: string
53
- serializedHandles: string
54
- }
55
-
56
- const serializePanels = (panels: DebugPanelSnapshot[]) => {
57
- return JSON.stringify(
58
- panels.map((panel) => ({
59
- id: panel.id,
60
- size: panel.size,
61
- sizeUnit: panel.sizeUnit,
62
- preferredPercentageSize: panel.preferredPercentageSize,
63
- preferredPixelSize: panel.preferredPixelSize,
64
- minSize: panel.minSize ?? null,
65
- maxSize: panel.maxSize ?? null,
66
- collapseFromStart: panel.collapseFromStart,
67
- collapseFromEnd: panel.collapseFromEnd,
68
- collapsed: panel.collapsed,
69
- collapsedByDirection: panel.collapsedByDirection,
70
- preferenceBeforeCollapse: panel.preferenceBeforeCollapse,
71
- pixelAdjustPriority: panel.pixelAdjustPriority ?? null,
72
- flexAdjustPriority: panel.flexAdjustPriority ?? null,
73
- measuredPixelSize: panel.measuredPixelSize ?? null,
74
- measuredPercentageSize: panel.measuredPercentageSize ?? null,
75
- })),
76
- )
77
- }
78
-
79
- const serializeHandles = (handles: ResizeHandleLayoutData[]) => {
80
- return JSON.stringify(
81
- handles.map((handle) => ({
82
- id: handle.id,
83
- thickness: handle.thickness,
84
- visible: handle.visible,
85
- direction: handle.direction,
86
- startPanelId: handle.startPanelId ?? null,
87
- endPanelId: handle.endPanelId ?? null,
88
- })),
89
- )
90
- }
91
-
92
- const createDebugOverlayStore = () => {
93
- const listeners = new Set<StoreListener>()
94
- const groups = new Map<string, DebugGroupEntry>()
95
- const enabledGroups = new Set<string>()
96
- let ownerId: string | null = null
97
- let orderCounter = 0
98
- let snapshotDirty = true
99
- let cachedGroups: DebugGroupState[] = []
100
- let cachedSnapshot: DebugOverlaySnapshot = {
101
- ownerId: null,
102
- groups: cachedGroups,
103
- }
104
-
105
- // リスナーへ変更通知
106
- const notify = () => {
107
- for (const listener of listeners) {
108
- listener()
109
- }
110
- }
111
-
112
- // スナップショット再計算フラグを設定して通知
113
- const emitChange = () => {
114
- snapshotDirty = true
115
- notify()
116
- }
117
-
118
- // 有効なグループから次のオーバーレイオーナーを決定
119
- const resolveOwner = () => {
120
- const previousOwner = ownerId
121
- if (previousOwner && enabledGroups.has(previousOwner)) {
122
- return false
123
- }
124
- ownerId = null
125
- const iterator = enabledGroups.values().next()
126
- if (!iterator.done) {
127
- ownerId = iterator.value
128
- }
129
- return previousOwner !== ownerId
130
- }
131
-
132
- // リスナー登録とサブスクリプション管理
133
- const subscribe = (listener: StoreListener) => {
134
- listeners.add(listener)
135
- return () => {
136
- listeners.delete(listener)
137
- }
138
- }
139
-
140
- // スナップショット取得 (必要に応じて再構築)
141
- const getSnapshot = (): DebugOverlaySnapshot => {
142
- if (resolveOwner()) {
143
- snapshotDirty = true
144
- }
145
-
146
- if (snapshotDirty) {
147
- const sorted = Array.from(groups.values()).sort((a, b) => a.index - b.index)
148
- cachedGroups = sorted.map(({ serializedPanels, serializedHandles, ...publicGroup }) => publicGroup)
149
- cachedSnapshot = {
150
- ownerId,
151
- groups: cachedGroups,
152
- }
153
- snapshotDirty = false
154
- }
155
-
156
- return cachedSnapshot
157
- }
158
-
159
- // グループを有効化してオーバーレイ対象へ追加
160
- const enableGroup = (groupId: string) => {
161
- const previousSize = enabledGroups.size
162
- enabledGroups.add(groupId)
163
- if (enabledGroups.size === previousSize) {
164
- return
165
- }
166
- if (resolveOwner()) {
167
- emitChange()
168
- }
169
- }
170
-
171
- // グループを無効化してオーバーレイ対象から除外
172
- const disableGroup = (groupId: string) => {
173
- if (!enabledGroups.delete(groupId)) {
174
- return
175
- }
176
- if (resolveOwner()) {
177
- emitChange()
178
- }
179
- }
180
-
181
- // グループ状態を更新 (差分検出して変更時のみ通知)
182
- const updateGroup = (groupId: string, update: DebugGroupUpdate) => {
183
- const existing = groups.get(groupId)
184
- const index = existing?.index ?? orderCounter++
185
- const serializedPanels = serializePanels(update.panels)
186
- const serializedHandles = serializeHandles(update.handles)
187
-
188
- // 各プロパティの変更検出
189
- const displayChanged = existing?.displayName !== update.displayName
190
- const directionChanged = existing?.direction !== update.direction
191
- const containerChanged = existing ? existing.containerSize.width !== update.containerSize.width || existing.containerSize.height !== update.containerSize.height : true
192
-
193
- // パネル配列の変更を詳細検証
194
- let panelsChanged = existing?.serializedPanels !== serializedPanels
195
- if (!panelsChanged && existing) {
196
- if (existing.panels.length !== update.panels.length) {
197
- panelsChanged = true
198
- } else {
199
- for (let index = 0; index < update.panels.length; index += 1) {
200
- const prevPanel = existing.panels[index]
201
- const nextPanel = update.panels[index]
202
- if (!(prevPanel && nextPanel)) {
203
- panelsChanged = true
204
- break
205
- }
206
- if (
207
- prevPanel.id !== nextPanel.id ||
208
- prevPanel.size !== nextPanel.size ||
209
- prevPanel.preferredPercentageSize !== nextPanel.preferredPercentageSize ||
210
- prevPanel.preferredPixelSize !== nextPanel.preferredPixelSize ||
211
- prevPanel.collapsed !== nextPanel.collapsed ||
212
- prevPanel.measuredPixelSize !== nextPanel.measuredPixelSize ||
213
- prevPanel.measuredPercentageSize !== nextPanel.measuredPercentageSize
214
- ) {
215
- panelsChanged = true
216
- break
217
- }
218
- }
219
- }
220
- }
221
-
222
- // ハンドル配列の変更を詳細検証
223
- let handlesChanged = existing?.serializedHandles !== serializedHandles
224
- if (!handlesChanged && existing) {
225
- if (existing.handles.length !== update.handles.length) {
226
- handlesChanged = true
227
- } else {
228
- for (let index = 0; index < update.handles.length; index += 1) {
229
- const prevHandle = existing.handles[index]
230
- const nextHandle = update.handles[index]
231
- if (!(prevHandle && nextHandle)) {
232
- handlesChanged = true
233
- break
234
- }
235
- if (
236
- prevHandle.id !== nextHandle.id ||
237
- prevHandle.thickness !== nextHandle.thickness ||
238
- prevHandle.visible !== nextHandle.visible ||
239
- prevHandle.direction !== nextHandle.direction ||
240
- prevHandle.startPanelId !== nextHandle.startPanelId ||
241
- prevHandle.endPanelId !== nextHandle.endPanelId
242
- ) {
243
- handlesChanged = true
244
- break
245
- }
246
- }
247
- }
248
- }
249
-
250
- // 空のグループは初回のみスキップ
251
- if (!existing && update.panels.length === 0 && update.handles.length === 0) {
252
- return
253
- }
254
-
255
- // 変更なければスキップ
256
- if (existing && !displayChanged && !directionChanged && !containerChanged && !panelsChanged && !handlesChanged) {
257
- return
258
- }
259
-
260
- // 状態をクローンして保存
261
- const clonedPanels = update.panels.map((panel) => ({ ...panel }))
262
- const clonedHandles = update.handles.map((handle) => ({ ...handle }))
263
- const clonedContainer = { ...update.containerSize }
264
-
265
- groups.set(groupId, {
266
- groupId,
267
- displayName: update.displayName,
268
- direction: update.direction,
269
- containerSize: clonedContainer,
270
- panels: clonedPanels,
271
- handles: clonedHandles,
272
- index,
273
- serializedPanels,
274
- serializedHandles,
275
- })
276
-
277
- emitChange()
278
- }
279
-
280
- // グループを削除
281
- const removeGroup = (groupId: string) => {
282
- const removed = groups.delete(groupId)
283
- const disabledNow = enabledGroups.delete(groupId)
284
- const ownerChanged = resolveOwner()
285
-
286
- if (removed || disabledNow || ownerChanged) {
287
- emitChange()
288
- }
289
- }
290
-
291
- return {
292
- subscribe,
293
- getSnapshot,
294
- getOwnerId: () => {
295
- if (resolveOwner()) {
296
- snapshotDirty = true
297
- }
298
- return ownerId
299
- },
300
- enableGroup,
301
- disableGroup,
302
- updateGroup,
303
- removeGroup,
304
- }
305
- }
306
-
307
- const debugOverlayStore = createDebugOverlayStore()
308
-
309
- /**
310
- * Subscribe to the identifier of the panel group that renders the overlay.
311
- * オーバーレイを描画するパネルグループ識別子を購読するフック。
312
- */
313
- export const useDebugOverlayOwnerId = () => {
314
- return useSyncExternalStore(debugOverlayStore.subscribe, debugOverlayStore.getOwnerId, debugOverlayStore.getOwnerId)
315
- }
316
-
317
- /**
318
- * Subscribe to the aggregate debug overlay snapshot.
319
- * 集約されたデバッグオーバーレイのスナップショットを購読するフック。
320
- */
321
- export const useDebugOverlaySnapshot = () => {
322
- return useSyncExternalStore(debugOverlayStore.subscribe, debugOverlayStore.getSnapshot, debugOverlayStore.getSnapshot)
323
- }
324
-
325
- /**
326
- * Enable a panel group for inclusion in the debug overlay.
327
- * デバッグオーバーレイへの取り込み対象としてパネルグループを有効化するメソッド。
328
- */
329
- export const enableDebugOverlayGroup = (groupId: string) => {
330
- debugOverlayStore.enableGroup(groupId)
331
- }
332
-
333
- /**
334
- * Disable a panel group from the debug overlay without erasing cached data.
335
- * キャッシュを保持したままパネルグループをデバッグオーバーレイ対象から外すメソッド。
336
- */
337
- export const disableDebugOverlayGroup = (groupId: string) => {
338
- debugOverlayStore.disableGroup(groupId)
339
- }
340
-
341
- /**
342
- * Persist the latest panel group measurements into the debug overlay store.
343
- * 最新のパネルグループ測定値をデバッグオーバーレイストアに保存するメソッド。
344
- */
345
- export const updateDebugOverlayGroup = (groupId: string, update: DebugGroupUpdate) => {
346
- debugOverlayStore.updateGroup(groupId, update)
347
- }
348
-
349
- /**
350
- * Remove a panel group from the debug overlay store entirely.
351
- * パネルグループをデバッグオーバーレイストアから完全に削除するメソッド。
352
- */
353
- export const removeDebugOverlayGroup = (groupId: string) => {
354
- debugOverlayStore.removeGroup(groupId)
355
- }