@aiquants/resize-panels 1.9.0 → 2.0.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 (80) hide show
  1. package/README.md +129 -22
  2. package/dist/GlobalDebugOverlay-Cf3GOn2A.cjs +1 -0
  3. package/dist/{GlobalDebugOverlay-Do70T2l6.js → GlobalDebugOverlay-DQtUdNeF.js} +28 -28
  4. package/dist/debugOverlayStore-D7FT6zPE.js +135 -0
  5. package/dist/debugOverlayStore-DY09saU8.cjs +1 -0
  6. package/dist/index-DZ0itiBD.js +1299 -0
  7. package/dist/index-DqATP_BA.cjs +2 -0
  8. package/dist/index.cjs +1 -1
  9. package/dist/index.d.ts +2 -29
  10. package/dist/index.js +25 -13
  11. package/dist/src/GlobalDebugOverlay.d.ts.map +1 -0
  12. package/dist/src/Panel.d.ts +46 -0
  13. package/dist/src/Panel.d.ts.map +1 -0
  14. package/dist/src/PanelDebugInfo.d.ts +34 -0
  15. package/dist/src/PanelDebugInfo.d.ts.map +1 -0
  16. package/dist/src/PanelGroup.d.ts.map +1 -0
  17. package/dist/src/PanelResizeHandle.d.ts.map +1 -0
  18. package/dist/src/allocateLayout.d.ts +60 -0
  19. package/dist/src/allocateLayout.d.ts.map +1 -0
  20. package/dist/src/context.d.ts.map +1 -0
  21. package/dist/{debugOverlayStore.d.ts → src/debugOverlayStore.d.ts} +10 -2
  22. package/dist/src/debugOverlayStore.d.ts.map +1 -0
  23. package/dist/src/hooks.d.ts +48 -0
  24. package/dist/src/hooks.d.ts.map +1 -0
  25. package/dist/src/index.d.ts +32 -0
  26. package/dist/src/index.d.ts.map +1 -0
  27. package/dist/src/reducer.d.ts +49 -0
  28. package/dist/src/reducer.d.ts.map +1 -0
  29. package/dist/src/roundHalfToEven.d.ts.map +1 -0
  30. package/dist/{types.d.ts → src/types.d.ts} +164 -60
  31. package/dist/src/types.d.ts.map +1 -0
  32. package/dist/src/utils/simple-logger.d.ts.map +1 -0
  33. package/dist/src/utils.d.ts +164 -0
  34. package/dist/src/utils.d.ts.map +1 -0
  35. package/dist/styles/resize-panels.standalone.css +1 -1
  36. package/dist/tests/support/dom-harness.d.ts +89 -0
  37. package/dist/tests/support/dom-harness.d.ts.map +1 -0
  38. package/package.json +1 -1
  39. package/src/GlobalDebugOverlay.tsx +3 -3
  40. package/src/Panel.tsx +203 -541
  41. package/src/PanelDebugInfo.tsx +52 -106
  42. package/src/PanelGroup.tsx +27 -42
  43. package/src/PanelResizeHandle.tsx +470 -509
  44. package/src/allocateLayout.ts +412 -0
  45. package/src/debugOverlayStore.ts +19 -15
  46. package/src/hooks.ts +187 -779
  47. package/src/index.ts +12 -3
  48. package/src/reducer.ts +364 -1126
  49. package/src/types.ts +149 -63
  50. package/src/utils.ts +205 -164
  51. package/dist/GlobalDebugOverlay-sEQN6exo.cjs +0 -1
  52. package/dist/GlobalDebugOverlay.d.ts.map +0 -1
  53. package/dist/Panel.d.ts +0 -7
  54. package/dist/Panel.d.ts.map +0 -1
  55. package/dist/PanelDebugInfo.d.ts +0 -26
  56. package/dist/PanelDebugInfo.d.ts.map +0 -1
  57. package/dist/PanelGroup.d.ts.map +0 -1
  58. package/dist/PanelResizeHandle.d.ts.map +0 -1
  59. package/dist/context.d.ts.map +0 -1
  60. package/dist/debugOverlayStore-Cntyxboe.js +0 -141
  61. package/dist/debugOverlayStore-Dkl-fHoa.cjs +0 -1
  62. package/dist/debugOverlayStore.d.ts.map +0 -1
  63. package/dist/hooks.d.ts +0 -45
  64. package/dist/hooks.d.ts.map +0 -1
  65. package/dist/index-B6YGX2DH.js +0 -2009
  66. package/dist/index-DssZUxGw.cjs +0 -2
  67. package/dist/index.d.ts.map +0 -1
  68. package/dist/reducer.d.ts +0 -39
  69. package/dist/reducer.d.ts.map +0 -1
  70. package/dist/roundHalfToEven.d.ts.map +0 -1
  71. package/dist/types.d.ts.map +0 -1
  72. package/dist/utils/simple-logger.d.ts.map +0 -1
  73. package/dist/utils.d.ts +0 -61
  74. package/dist/utils.d.ts.map +0 -1
  75. /package/dist/{GlobalDebugOverlay.d.ts → src/GlobalDebugOverlay.d.ts} +0 -0
  76. /package/dist/{PanelGroup.d.ts → src/PanelGroup.d.ts} +0 -0
  77. /package/dist/{PanelResizeHandle.d.ts → src/PanelResizeHandle.d.ts} +0 -0
  78. /package/dist/{context.d.ts → src/context.d.ts} +0 -0
  79. /package/dist/{roundHalfToEven.d.ts → src/roundHalfToEven.d.ts} +0 -0
  80. /package/dist/{utils → src/utils}/simple-logger.d.ts +0 -0
package/src/types.ts CHANGED
@@ -3,14 +3,24 @@
3
3
  * リサイザブルパネルコンポーネントの型定義
4
4
  */
5
5
 
6
- import type { CSSProperties, ReactNode } from "react"
6
+ import type { CSSProperties, HTMLAttributes, ReactNode } from "react"
7
7
 
8
8
  /**
9
- * Pixel threshold used to decide when panels snap closed or open.
10
- * パネルのスナップ判定に利用するピクセル閾値。
9
+ * Pixel threshold under which a panel is treated as visually closed.
10
+ * パネルが見た目上閉じていると扱われるピクセル閾値。
11
11
  */
12
12
  export const PANEL_SNAP_THRESHOLD = 12
13
13
 
14
+ /**
15
+ * Numeric tolerance for layout arithmetic, in pixels.
16
+ * レイアウト演算の許容誤差 (px)。
17
+ *
18
+ * Sizes are IEEE-754 doubles produced by divisions, so exact comparisons would freeze drags on a 1 ulp
19
+ * difference. Everything below this tolerance is treated as equality.
20
+ * サイズは除算由来の倍精度値であり、厳密比較では 1 ulp の差でドラッグが凍結する。この許容値未満は同値とみなす。
21
+ */
22
+ export const PANEL_ALLOCATION_EPSILON = 1e-6
23
+
14
24
  /**
15
25
  * Default thickness in pixels for the resize handle interactive area.
16
26
  * リサイズハンドルのインタラクティブ領域のデフォルト厚み (px)。
@@ -54,8 +64,8 @@ export const PANEL_INDICATOR_BAR_LENGTH_HORIZONTAL = 32
54
64
  export const PANEL_INDICATOR_BAR_LENGTH_VERTICAL = 64
55
65
 
56
66
  /**
57
- * Spacing in pixels between visual indicator dots in the handle.
58
- * ハンドル内の視覚インジケーター点同士のピクセル間隔。
67
+ * Spacing in pixels between visual indicators of handles that share a boundary.
68
+ * 境界を共有するハンドルの視覚インジケーター同士のピクセル間隔。
59
69
  */
60
70
  export const PANEL_VISIBLE_INDICATOR_SPACING = 8
61
71
 
@@ -101,24 +111,6 @@ export const PANEL_EXPAND_THRESHOLD_MAX = 20
101
111
  */
102
112
  export const PANEL_HANDLE_VISIBILITY_THRESHOLD = 0.05
103
113
 
104
- /**
105
- * Retry intervals in milliseconds when awaiting layout stabilization.
106
- * レイアウトの安定化を待機するときに使用するミリ秒単位の再試行間隔。
107
- */
108
- export const PANEL_RESIZE_RETRY_INTERVALS = [10, 50, 100, 200, 300, 500, 800] as const
109
-
110
- /**
111
- * Tolerance used to decide whether pixel-based panel adjustments are significant.
112
- * ピクセル基準パネルの補正を有効とみなすための誤差許容値。
113
- */
114
- export const PANEL_PIXEL_MUTATION_TOLERANCE = 0.0
115
-
116
- /**
117
- * Minimum pixel threshold used when clamping snap calculations.
118
- * スナップ計算を補正する際に用いる最小ピクセル閾値。
119
- */
120
- export const PANEL_MIN_SNAP_THRESHOLD = 0.0
121
-
122
114
  /**
123
115
  * Layout direction of panels
124
116
  * パネルのレイアウト方向
@@ -176,12 +168,18 @@ export type CollapsibleConfig = {
176
168
  }
177
169
 
178
170
  /**
179
- * Axis-aligned container measurement including inner (borderless) and outer dimensions.
180
- * 枠線控除後と控除前の両方の寸法を含む軸方向コンテナ計測値。
171
+ * Axis-aligned container measurement.
172
+ * 軸方向のコンテナ計測値。
173
+ *
174
+ * `content` is what every layout number is relative to: percentage sizes resolve against it and the
175
+ * allocator fills exactly this length. `border` is the same box plus padding and borders, used only when a
176
+ * caller needs the element's outer footprint.
177
+ * すべてのレイアウト数値の基準は `content`: パーセンテージ指定はこの長さに解決され、配分器はこの長さを満たす。
178
+ * `border` は同じ軸のパディング・枠線を含む外形で、要素の外寸が必要な場合にのみ使う。
181
179
  */
182
180
  export type ContainerAxisMeasurement = {
183
- inner: number
184
- outer: number
181
+ content: number
182
+ border: number
185
183
  }
186
184
 
187
185
  /**
@@ -196,60 +194,134 @@ export type LayoutConstraintViolationReason = "minimum-exceeded" | "maximum-insu
196
194
  */
197
195
  export type LayoutConstraintViolation = {
198
196
  reason: LayoutConstraintViolationReason
199
- totalMinimumSize: number | null
200
- totalMaximumSize: number | null
197
+ totalMinimumSize: number
198
+ totalMaximumSize: number
201
199
  availableContainerSize: number
202
200
  }
203
201
 
204
202
  /**
205
- * Layout data for a single panel
206
- * 単一パネルのレイアウトデータ
203
+ * Canonical layout state of a single panel.
204
+ * 単一パネルの正準レイアウト状態。
205
+ *
206
+ * The state separates three roles and never stores the same quantity twice: configuration comes from the
207
+ * component's props, the preference is what the user asked for (a share of the container for flexible
208
+ * panels, an absolute length for pixel panels), and `size` is the allocator's answer for the current
209
+ * container. Everything else — the rendered flex basis, the handle position, the percentage shown in the
210
+ * debug overlay — is derived from those.
211
+ * 状態は 3 つの役割に分かれ、同じ量を二重に持たない: 構成はコンポーネントの props 由来、希望値は利用者の要求
212
+ * (柔軟パネルはコンテナ比、ピクセルパネルは絶対長)、`size` は現在のコンテナに対する配分器の答え。描画される
213
+ * flex basis・ハンドル位置・デバッグ表示の割合は、すべてここから導出される。
207
214
  */
208
215
  export interface PanelLayoutData {
209
216
  id: string
210
- size: number
211
- percentageSize?: number
212
- preferredPercentageSize?: number
213
- preferredPixelSize?: number
217
+ /** Which preference field drives this panel. どちらの希望値でサイズが決まるか。 */
214
218
  sizeUnit: SizeUnit
215
- originalPixelSize?: number
219
+ /** Allocated length in pixels for the current container. 現在のコンテナに対する配分結果 (px)。 */
220
+ size: number
221
+ /**
222
+ * Ratio weight of a flexible panel, expressed as a share of the container in percent.
223
+ * 柔軟パネルの重み (コンテナ比 %)。
224
+ *
225
+ * Only the ratio between panels matters — unless the panel declares `flexAdjustPriority`, which turns the
226
+ * same number into an absolute claim on that share of the container.
227
+ * 意味を持つのはパネル間の比だけ。ただし `flexAdjustPriority` を宣言したパネルでは、同じ数値が
228
+ * 「コンテナのその割合」という絶対的な要求になる。
229
+ */
230
+ preferredPercentageSize: number
231
+ /** Requested absolute length of a pixel panel. ピクセルパネルの希望絶対長 (px)。 */
232
+ preferredPixelSize: number
216
233
  minSize?: FlexibleSize
217
234
  maxSize?: FlexibleSize
218
- autoMinSize?: FlexibleSize
219
235
  collapseFromStart: boolean
220
236
  collapseFromEnd: boolean
221
- collapsedByDirection?: PanelCollapseDirection | null
237
+ collapsed: boolean
238
+ collapsedByDirection: PanelCollapseDirection | null
239
+ /**
240
+ * Preference captured when the panel collapsed, restored verbatim on expand.
241
+ * 折りたたみ時に退避し、展開時にそのまま復元する希望値。
242
+ */
243
+ preferenceBeforeCollapse: number
222
244
  /**
223
- * Skip automatic growth for flexible panels that were manually reduced to a zero footprint.
224
- * 手動でゼロ相当まで縮めた柔軟パネルを自動拡張対象から外すフラグ。
245
+ * Preference the component last authored through its props, used to tell a prop change from a re-registration.
246
+ * コンポーネントが props で最後に宣言した希望値。prop 変更と単なる再登録を区別するために保持。
225
247
  */
226
- excludeFromAutoGrowth?: boolean
227
- collapsed?: boolean
228
- sizeBeforeCollapse?: number
229
- percentageSizeBeforeCollapse?: number
230
- preferredPercentageSizeBeforeCollapse?: number
231
- preferredPixelSizeBeforeCollapse?: number
248
+ authoredPreference: number
249
+ /** Serving order among pixel panels, higher first. ピクセルパネル間の充当順位 (大きいほど先)。 */
232
250
  pixelAdjustPriority?: number
251
+ /**
252
+ * Serving order among flexible panels, higher first; absent means pure ratio sharing.
253
+ * 柔軟パネル間の充当順位 (大きいほど先)。未指定なら純粋な比例配分。
254
+ *
255
+ * Declaring it changes how `preferredPercentageSize` is read: the panel claims that share of the container
256
+ * before the ratio panels divide what is left.
257
+ * 宣言すると `preferredPercentageSize` の読み方が変わり、比例配分のパネルが残りを分ける前に
258
+ * コンテナのその割合を確保する。
259
+ */
233
260
  flexAdjustPriority?: number
234
- measuredPixelSize?: number
235
- measuredPercentageSize?: number
236
- measuredPixelSizeBeforeCollapse?: number
237
261
  }
238
262
 
263
+ /**
264
+ * Layout state of one panel group: the container it was measured against, its panels in DOM order, and
265
+ * whether the panels' constraints can be satisfied at that size.
266
+ * パネルグループのレイアウト状態: 計測対象のコンテナ長・DOM 順のパネル一覧・制約充足可否。
267
+ */
268
+ export interface PanelGroupLayoutState {
269
+ /** Content-box length of the group along its axis; 0 until the first measurement. 軸方向の内容領域長 (未計測は 0)。 */
270
+ containerSize: number
271
+ panels: PanelLayoutData[]
272
+ violation: LayoutConstraintViolation | null
273
+ }
274
+
275
+ /**
276
+ * Configuration and preference a panel publishes when it registers with its group.
277
+ * パネルがグループへ登録する際に公開する構成と希望値。
278
+ */
279
+ export type PanelRegistration = Omit<PanelLayoutData, "size" | "collapsedByDirection" | "preferenceBeforeCollapse" | "authoredPreference">
280
+
281
+ /**
282
+ * One panel's persisted length, kept with its identifier so a stored layout can never be applied to a
283
+ * different set of panels.
284
+ * 保存されたパネル 1 枚分の長さ。別構成のパネルへ誤って適用されないよう識別子を伴う。
285
+ */
286
+ export type PersistedPanelSize = {
287
+ id: string
288
+ size: number
289
+ /** Whether the panel was collapsed when the layout was written. 保存時に折りたたまれていたか。 */
290
+ collapsed: boolean
291
+ }
292
+
293
+ /**
294
+ * Actions accepted by the panel group reducer.
295
+ * パネルグループのリデューサーが受け付けるアクション。
296
+ */
297
+ export type PanelAction =
298
+ | { type: "SET_CONTAINER_SIZE"; containerSize: number }
299
+ | { type: "REGISTER_PANEL"; panel: PanelRegistration }
300
+ | { type: "UNREGISTER_PANEL"; id: string }
301
+ | { type: "REORDER_PANELS"; ids: string[] }
302
+ | { type: "RESIZE_PANELS"; startId: string; endId: string; startSize: number }
303
+ | { type: "COLLAPSE_PANEL"; id: string; from: PanelCollapseDirection }
304
+ | { type: "EXPAND_PANEL"; id: string; from: PanelCollapseDirection; targetSize?: number }
305
+ | { type: "RESTORE_LAYOUT"; entries: PersistedPanelSize[] }
306
+
239
307
  /**
240
308
  * Props for the Panel component
241
309
  * Panel コンポーネントのプロパティ
242
310
  */
243
- export interface PanelProps {
311
+ // aria-hidden は折りたたみ状態から決まるため、利用者の指定は黙って捨てられる
312
+ export interface PanelProps extends Omit<HTMLAttributes<HTMLDivElement>, "id" | "children" | "className" | "style" | "aria-hidden"> {
244
313
  id?: string
314
+ /**
315
+ * Initial size. A percentage (or bare number) makes the panel flexible, pixels make it fixed.
316
+ * 初期サイズ。パーセンテージ (数値のみの指定を含む) なら柔軟パネル、ピクセルなら固定パネル。
317
+ * @default { value: 50, unit: "percentage" }
318
+ */
245
319
  defaultSize?: FlexibleSize
246
320
  minSize?: FlexibleSize
247
321
  maxSize?: FlexibleSize
248
- autoMinSize?: FlexibleSize
249
322
  className?: string
250
323
  style?: CSSProperties
251
324
  children?: ReactNode
252
- order?: number
253
325
  collapsible?: CollapsibleConfig
254
326
  defaultCollapsed?: boolean
255
327
  pixelAdjustPriority?: number
@@ -261,12 +333,11 @@ export interface PanelProps {
261
333
  * Props for the PanelGroup component
262
334
  * PanelGroup コンポーネントのプロパティ
263
335
  */
264
- export interface PanelGroupProps {
336
+ export interface PanelGroupProps extends Omit<HTMLAttributes<HTMLDivElement>, "id" | "children" | "className" | "style"> {
265
337
  id?: string
266
338
  direction: PanelDirection
267
- storageKey?: string
268
339
  className?: string
269
- style?: React.CSSProperties
340
+ style?: CSSProperties
270
341
  children?: ReactNode
271
342
  showDebugInfo?: boolean
272
343
  onLayout?: (panelSizes: number[]) => void
@@ -279,16 +350,25 @@ export interface PanelGroupProps {
279
350
  */
280
351
  export interface PanelGroupContextValue {
281
352
  direction: PanelDirection
282
- registerPanel: (panel: PanelLayoutData) => void
353
+ registerPanel: (panel: PanelRegistration) => void
283
354
  unregisterPanel: (id: string) => void
284
355
  getPanel: (id: string) => PanelLayoutData | undefined
285
356
  panels: PanelLayoutData[]
286
- isContainerReady: boolean
357
+ /** Content-box length of the group along its axis. グループ軸方向の内容領域長。 */
358
+ containerSize: number
359
+ /**
360
+ * Key that changes whenever the document order of the group's panels and handle anchors changes.
361
+ * グループのパネルとハンドルのアンカーの文書順が変わるたびに変化する鍵。
362
+ *
363
+ * A handle that moves to another boundary leaves the panel id sequence untouched, so the panels alone
364
+ * cannot tell a handle that its neighbours changed.
365
+ * ハンドルが別の境界へ移ってもパネルの id 列は変わらないため、パネルだけではハンドルへ隣の変化を伝えられない。
366
+ */
367
+ layoutOrderKey: string
287
368
  showDebugInfo: boolean
288
- resizePanels: (leftId: string, rightId: string, leftSize: number, rightSize: number) => void
369
+ resizePanels: (startId: string, endId: string, startSize: number) => void
289
370
  collapsePanel: (id: string, from: PanelCollapseDirection) => void
290
371
  expandPanel: (id: string, from: PanelCollapseDirection, targetSize?: number) => void
291
- containerSize: ContainerSize
292
372
  reportPanelMeasurement: (id: string, measurement: PanelMeasurement | null) => void
293
373
  panelMeasurements: Record<string, PanelMeasurement>
294
374
  reportHandleMeasurement: (id: string, measurement: ResizeHandleLayoutData | null) => void
@@ -349,12 +429,18 @@ export interface PanelResizeHandleIndicatorConfig {
349
429
  * Props for the PanelResizeHandle component
350
430
  * PanelResizeHandle コンポーネントのプロパティ
351
431
  */
352
- export interface PanelResizeHandleProps {
432
+ /**
433
+ * ARIA attributes the handle computes from the layout; a consumer value would be silently discarded.
434
+ * ハンドルがレイアウトから算出する ARIA 属性 (利用者の指定は黙って捨てられるため受け付けない)。
435
+ */
436
+ type OwnedSeparatorAria = "role" | "aria-orientation" | "aria-valuenow" | "aria-valuemin" | "aria-valuemax" | "aria-disabled" | "aria-hidden"
437
+
438
+ export interface PanelResizeHandleProps extends Omit<HTMLAttributes<HTMLButtonElement>, "id" | "children" | "className" | "style" | "title" | OwnedSeparatorAria> {
353
439
  id?: string
354
440
  disabled?: boolean
355
441
  onDragging?: (isDragging: boolean) => void
356
442
  className?: string
357
- style?: React.CSSProperties
443
+ style?: CSSProperties
358
444
  children?: ReactNode
359
445
  /**
360
446
  * Primary axis thickness of the handle's interactive area in pixels.
@@ -414,6 +500,6 @@ export interface ResizeHandleLayoutData {
414
500
  thickness: number
415
501
  direction: PanelDirection
416
502
  visible: boolean
417
- startPanelId?: string | null
418
- endPanelId?: string | null
503
+ startPanelId: string | null
504
+ endPanelId: string | null
419
505
  }