@aiquants/period-slider 0.10.2 → 0.11.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.
- package/CHANGELOG.md +41 -0
- package/README.md +34 -13
- package/dist/DateSelector.d.ts +1 -1
- package/dist/DateSelector.d.ts.map +1 -1
- package/dist/VirtualDateDropdown.d.ts +141 -0
- package/dist/VirtualDateDropdown.d.ts.map +1 -0
- package/dist/dateOptionDomain.d.ts +175 -0
- package/dist/dateOptionDomain.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1983 -1678
- package/dist/styles/period-slider.css +1 -1
- package/dist/styles/period-slider.standalone.css +1 -1
- package/package.json +5 -3
- package/src/DateSelector.tsx +72 -128
- package/src/VirtualDateDropdown.tsx +562 -0
- package/src/dateOptionDomain.ts +327 -0
- package/src/styles/period-slider.css +111 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,47 @@ All notable changes to `@aiquants/period-slider` are documented here.
|
|
|
7
7
|
|
|
8
8
|
## Unreleased
|
|
9
9
|
|
|
10
|
+
## 0.11.0
|
|
11
|
+
|
|
12
|
+
### 利用側の契約が変わる点
|
|
13
|
+
|
|
14
|
+
- **`DateSelector` の `variant="dropdown"` は、ネイティブ `<select>` ではなく仮想化されたコンボボックスを描きます**。
|
|
15
|
+
選択肢は配列として実体化されず、境界から導いた添字空間 (件数・添字の日付・機械可読値・表示テキスト・日付の添字) として
|
|
16
|
+
持ちます。ポップアップは `@aiquants/virtualscroll` が可視行だけを描くため、境界を動かす費用は連続範囲で O(1)、
|
|
17
|
+
`allowedDates` 指定時は二分探索の O(log n) で、選択肢の数に比例しません。実測 (デモのノギス、マクロ年 × ミクロ日の
|
|
18
|
+
ドラッグ): 1 移動あたり 31.1 ms → 16.6 ms (計測器の下限)、スクリプト 0.473 s → 0.076 s、レイアウト 0.345 s → 0.022 s。
|
|
19
|
+
100 年分 (36,525 日) の定義域でも、閉じた DOM は定義域の広さに対して不変 (`<option>` 0 個)、境界変更は 1.0〜1.1 ms、開く時間 71〜78 ms、
|
|
20
|
+
フリングのフレーム時間中央値 16.7 ms で、1,663 日・365,250 日と同じ値です (ネイティブ `<select>` は 36,525 日で
|
|
21
|
+
1 変更あたり 192 + 134 ms、365,250 日では描画が完了しません)。Props・エクスポート・`DateSelectorProps` の型は 1 つも
|
|
22
|
+
変わりません。
|
|
23
|
+
- 操作要素は `<input type="text" readonly role="combobox">` になり、`value` は人間が読むテキスト、機械可読値は
|
|
24
|
+
`data-value` (`yyyy-MM-dd`) です。`<select>` の `value` / `options` / `selectOption` を前提にしたテストと DOM 参照は
|
|
25
|
+
README「各種セレクタ」の `DateSelector` の項の移行表に従ってください。
|
|
26
|
+
- ポップアップは `document.body` へポータルされ、下に余地が無ければ上へ反転して視野内へ収まります。各行は
|
|
27
|
+
`aria-posinset` / `aria-setsize` を集合全体の件数で持ち、キーボード (矢印・`Home` / `End` / `PageUp` / `PageDown` /
|
|
28
|
+
`Enter` / `Escape` / 先頭一致入力) は操作要素が `aria-activedescendant` 方式で担います。タッチでは OS のホイール式
|
|
29
|
+
ピッカーは現れず、代わりに 44px の行・ソフトキーボードを上げない読み取り専用の操作要素・視野内に収まる配置で
|
|
30
|
+
補います。
|
|
31
|
+
- ポップアップの重なり順は公開 CSS 変数 `--aqps-z-date-popup` (既定 60) で差し替えられます。`document.body` へ
|
|
32
|
+
ポータルされるため、本パッケージでホストの層と直接重なるのはこの要素だけです (他の 8 つの `--aqps-z-*` は
|
|
33
|
+
スライダーのルートが作る積層文脈の内側にあります)。公開変数は 16 個から 17 個になりました。
|
|
34
|
+
- ポップアップの配色モードは、ポータル先の祖先ではなく**操作要素自身の位置**で解決し、`data-color-mode="light|dark"`
|
|
35
|
+
として運びます。`.dark` を部分木へ限定したホスト (`@custom-variant dark (&:where(.dark, .dark *))` が許す形) でも、
|
|
36
|
+
暗色のページの上に明色のポップアップが載りません。
|
|
37
|
+
- `variant="date"` と `variant="split-dropdown"`、`MonthSelector` と `YearSelector` は変わりません。
|
|
38
|
+
- **`@aiquants/virtualscroll` が peer dependency になりました**。ホストは自分で導入し (`pnpm add @aiquants/virtualscroll`)、
|
|
39
|
+
同梱スタイルシート `@aiquants/virtualscroll/styles/virtualscroll.css` (非 Tailwind ホストは `.standalone.css`) を
|
|
40
|
+
本パッケージのスタイルシートと並べて読み込んでください。本パッケージのスタイルシート成果物には含まれません。
|
|
41
|
+
|
|
42
|
+
### 修正
|
|
43
|
+
|
|
44
|
+
- **100 年規模の定義域で `variant="dropdown"` が `maxDate` の日そのものを落としていました**。`Asia/Tokyo` は 1948〜1951 年に
|
|
45
|
+
夏時間を実施しており、先頭だけを 0 時へ正規化して `addDays` で刻む展開は遷移後の日付を 1 時へずらし、上限との比較が
|
|
46
|
+
1 日早く終わっていました (36,525 日で 36,524 件、最新日が上限の前日)。選択肢は暦日の通番 (`Date.UTC` によるローカル暦日の
|
|
47
|
+
日数) で数えるため、この形の欠落は構造的に起きません。
|
|
48
|
+
- 機械可読値の `yyyy-MM-dd` は date-fns の `format` ではなく暦の構成要素から組み立てます。1〜275760 年で出力は
|
|
49
|
+
バイト一致し、0 年以下は紀元年ではなく ISO 8601 の拡張表記 (`0000-01-01`、`-000001-01-01`) になります。
|
|
50
|
+
|
|
10
51
|
## 0.10.2
|
|
11
52
|
|
|
12
53
|
### 修正
|
package/README.md
CHANGED
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
- **充実した日付セレクタ**:
|
|
47
47
|
- `YearSelector`: ドロップダウンと ◀▶ ステッパーで年を選択。
|
|
48
48
|
- `MonthSelector`: カレンダー入力 (`variant="date"`, 既定) / ドロップダウン (`variant="dropdown"`) 対応の月セレクタ。連続した境界のほか、実データに存在する月だけを選ばせる離散集合 (`allowedMonths`) に対応。
|
|
49
|
-
- `DateSelector`: 日付入力 (`variant="date"`, 既定)
|
|
49
|
+
- `DateSelector`: 日付入力 (`variant="date"`, 既定)、日付範囲全体を仮想化したコンボボックス (`variant="dropdown"`、100 年分の日でも定数費用)、年月日の 3 分割セレクト (`variant="split-dropdown"`) に対応。離散集合 (`allowedDates`) にも対応。
|
|
50
50
|
- 3 セレクタの ◀▶ とスライダーのステッパーは同じ部品を共有し、押せる間だけホバーで強調され、44px の当たり判定とキーボードフォーカスのリングを持ちます。境界に着いたボタンはフォーカスを保ち、タブ順にも残ったまま使用不可 (`aria-disabled="true"`) になります。どのボタンも `type="button"` のため、ホストの `<form>` の中に置いても押下でフォームを送信しません。
|
|
51
51
|
- **カラーテーマ・メリハリ対比 & ダークモード**:
|
|
52
52
|
- `colorScheme`: 6 系統のカラーパレット (`"blue-rose"` [既定], `"indigo-amber"`, `"teal-emerald"`, `"violet-fuchsia"`, `"slate-sky"`, `"monochrome"`) をサポート。
|
|
53
53
|
- ノギス 2 段スケールにおける広域マクロ (青系) と確定ミクロ (赤系) の明確なメリハリ対比、および境界を結ぶ台形プロジェクション光の動的 2 色グラデーション。
|
|
54
54
|
- トラック、ノブ、目盛線、ツールチップ、セレクタ群 (`YearSelector`, `MonthSelector`, `DateSelector`) を含む Tailwind `.dark` クラスによるダークモード完全対応。
|
|
55
|
-
- **CSS カスタムプロパティによるスタイリング API**: 配色 11 個に加え、重なり順 (z-index)
|
|
55
|
+
- **CSS カスタムプロパティによるスタイリング API**: 配色 11 個に加え、重なり順 (z-index) 9 個、インジケーターラベルの配色・文字寸法・余白・角丸 7 個とノギスのレール離隔 1 個の計 28 変数を `--aqps-` 接頭辞で公開。対応する Props は持たず、自前の CSS か `style` プロップで上書きします。既定値は現在の描画結果そのもののため、何も与えなければ見た目は一切変わりません。
|
|
56
56
|
- **垂直レイアウト対応 (`isVertical`)**:
|
|
57
57
|
- `isVertical={true}` によりダッシュボードのサイドバーや狭小パネルに最適な垂直指向スライダーを提供。
|
|
58
58
|
- つまみのラベルはつまみの左側、ホバーガイドのラベルはトラックの右側へ排他配置し、垂直時の重なりを構造的に回避。つまみ左端からラベル右端までの実測離隔は 16px です (スタイルシートの 1 つの宣言 `right: calc(100% + var(--ps-vertical-label-gap))` が決めます。`--ps-vertical-label-gap` は内部変数であり、上書きしてよい公開の CSS カスタムプロパティではありません — 名前も値も予告なく変わります)。
|
|
@@ -68,9 +68,13 @@
|
|
|
68
68
|
## インストール
|
|
69
69
|
|
|
70
70
|
```bash
|
|
71
|
-
pnpm add @aiquants/period-slider
|
|
71
|
+
pnpm add @aiquants/period-slider @aiquants/virtualscroll
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
+
`@aiquants/virtualscroll` は peer dependency です。`DateSelector` の `variant="dropdown"` はポップアップの行をこのパッケージで仮想化して描くため、ホストが自分で導入し、同梱スタイルシート (`@aiquants/virtualscroll/styles/virtualscroll.css`、非 Tailwind ホストは `.standalone.css`) も読み込んでください (下の「スタイル読み込み」)。
|
|
75
|
+
|
|
76
|
+
0.10.x から上げる場合、`DateSelector` の `variant="dropdown"` が描くのはネイティブ `<select>` ではなく `role="combobox"` の読み取り専用 `<input>` と仮想化されたポップアップです。`<select>` / `<option>` を前提にしたテストや DOM 参照の移行先は「各種セレクタ」の `DateSelector` の項にあります。
|
|
77
|
+
|
|
74
78
|
0.9.0 から上げる場合は、同梱の `CHANGELOG.md` の「利用側の契約が変わる点」を先に読んでください (使用不可のステッパーの属性、矢印の要素、レール方向の予約、セレクタのルート幅、公開エクスポート、ドラッグのポインター捕捉、ノギスのコールバックの重複抑止)。
|
|
75
79
|
|
|
76
80
|
`jsdom` でこのコンポーネントを描画するテストは、`jsdom` が実装していないブラウザ API のシムが要ります (`ResizeObserver`、`window.matchMedia`、`Element.prototype.setPointerCapture` / `releasePointerCapture` / `hasPointerCapture`)。`createPortal` で別文書 (`<iframe>` やポップアウトのウィンドウ) へ描く場合は、`Element.prototype` が文書ごとに別であるため、その文書の `Element` へも同じシムを載せてください (スライダー側は操作のリスナーもホイールの登録も、自分が描かれている文書の `window` へ張ります)。
|
|
@@ -84,11 +88,15 @@ pnpm add @aiquants/period-slider
|
|
|
84
88
|
```typescript
|
|
85
89
|
// A. Tailwind CSS v4 プロジェクトの場合: パッケージ固有のコンポーネントクラスのみを読み込む
|
|
86
90
|
import "@aiquants/period-slider/styles/period-slider.css"
|
|
91
|
+
import "@aiquants/virtualscroll/styles/virtualscroll.css"
|
|
87
92
|
|
|
88
93
|
// B. 非 Tailwind (スタンドアロン) 環境の場合: 自己完結 CSS を読み込む
|
|
89
94
|
import "@aiquants/period-slider/styles/period-slider.standalone.css"
|
|
95
|
+
import "@aiquants/virtualscroll/styles/virtualscroll.standalone.css"
|
|
90
96
|
```
|
|
91
97
|
|
|
98
|
+
peer dependency の `@aiquants/virtualscroll` のスタイルシートは、本パッケージの成果物には含まれません (2 つのパッケージの事前生成 CSS は連結では再現できないため)。`DateSelector` の `variant="dropdown"` を使わないホストでも、読み込みは無害です。
|
|
99
|
+
|
|
92
100
|
| 成果物 | 含まれるもの | 用途 |
|
|
93
101
|
| :--- | :--- | :--- |
|
|
94
102
|
| `styles/period-slider.css` | 手書きコンポーネントクラス (`.period-slider-*`) のみ。テーマ変数・ユーティリティ・preflight は含まない | ホスト側に Tailwind CSS v4 ビルドがある場合 |
|
|
@@ -120,7 +128,7 @@ import "@aiquants/period-slider/styles/period-slider.standalone.css"
|
|
|
120
128
|
ISO 8601 はフォールバックではなく、本パッケージの仕様上の既定値です。英語などの自然言語表記を既定にすると汎用パッケージへ 1 つの言語を焼き付けることになり、`Intl` の出力は ICU / Node のバージョン間で変化するためです。
|
|
121
129
|
|
|
122
130
|
- **優先順位**: フォーマッタ Props (`formatLabel` / `formatMacroLabel` / `formatMicroLabel` / `formatAriaValueText`、`DateSelector` の `formatYearOption` / `formatMonthOption` / `formatDayOption`) が最優先、次に `locale`、最後に ISO 8601 既定です。
|
|
123
|
-
- **地域化されるのは人間が読むテキストのみ**: `<input type="date">` の `value` / `min` / `max` は常に `yyyy-MM-dd`、`<input type="month">` は常に `yyyy-MM`、`<option value>` は常に ISO 文字列 (`yyyy-MM
|
|
131
|
+
- **地域化されるのは人間が読むテキストのみ**: `<input type="date">` の `value` / `min` / `max` は常に `yyyy-MM-dd`、`<input type="month">` は常に `yyyy-MM`、`DateSelector` の `variant="dropdown"` が操作要素に持つ `data-value` は常に `yyyy-MM-dd`、`<option value>` は常に ISO 文字列 (`yyyy-MM`) または生の数値 (年セレクト、`variant="split-dropdown"` の 3 セレクト) です。
|
|
124
132
|
- **アクセシブル名は `locale` では変わりません**: ボタン・セレクト・つまみの名称は英語既定のままです。翻訳するには `lowerAriaLabel` / `decreaseAriaLabel` / `selectAriaLabel` などのアクセシブル名 Props を渡してください。
|
|
125
133
|
- **Fail Fast**: 空文字列や `Intl.DateTimeFormat` が受理しない値 (`"en_US"`、非文字列等) を渡した場合、既定の ISO へ黙って戻さず `RangeError` を送出します (メッセージは [実行時バリデーション](#実行時バリデーション-fail-fast) 参照)。`"xx-YY"` のように構造として妥当なタグは、対応する翻訳データが無くても受理されます。
|
|
126
134
|
|
|
@@ -649,7 +657,7 @@ DOM 要素の特定は CSS クラス名ではなく `data-*` 属性で行いま
|
|
|
649
657
|
|
|
650
658
|
アクセント色 (つまみのグロー・波紋) は `monochrome` を除きマクロ色と同一値です。各プリセットの実値は `COLOR_SCHEME_PALETTES` からも取得できます。
|
|
651
659
|
|
|
652
|
-
ダークモードは、祖先要素に `.dark` クラスを付与するだけで、スライダー (トラック、ノブ、グロー光、目盛線、ツールチップ) および全セレクタ (`YearSelector`, `MonthSelector`, `DateSelector`)
|
|
660
|
+
ダークモードは、祖先要素に `.dark` クラスを付与するだけで、スライダー (トラック、ノブ、グロー光、目盛線、ツールチップ) および全セレクタ (`YearSelector`, `MonthSelector`, `DateSelector`) が自動でダークパレットに適応します。`.dark` は文書のルートに限らず任意の部分木に置けます — `DateSelector` の `variant="dropdown"` が `document.body` へポータルするポップアップも、操作要素自身の位置から配色モードを解決するため、部分木に限定した `.dark` に追従します。
|
|
653
661
|
|
|
654
662
|
### CSS カスタムプロパティ (スタイリング API)
|
|
655
663
|
|
|
@@ -678,9 +686,9 @@ DOM 要素の特定は CSS クラス名ではなく `data-*` 属性で行いま
|
|
|
678
686
|
```
|
|
679
687
|
|
|
680
688
|
> [!IMPORTANT]
|
|
681
|
-
> **配色の 11 変数と、それ以外の
|
|
689
|
+
> **配色の 11 変数と、それ以外の 17 変数では、B の書き方が違います。**
|
|
682
690
|
> 配色の 11 変数はパッケージ自身が `[data-color-scheme="<preset>"]` — **スライダーのルート要素そのもの** — に宣言しているため、祖先要素 (`body` や `:root`) に書いた値は届きません (要素自身が持つ宣言が、祖先から継承した値に必ず勝つため)。セレクタがスライダーのルート要素自身に一致する形 (上の例の `[data-mode]` など) で書いてください。
|
|
683
|
-
> 残る
|
|
691
|
+
> 残る 17 変数はパッケージがどこにも宣言せず、参照側で `var(--aqps-…, <既定値>)` のフォールバックとしてのみ既定値を与えます。したがって祖先要素・ルート要素・`style` プロップのいずれに書いても届きます。
|
|
684
692
|
|
|
685
693
|
#### 配色 (`colorScheme` プリセットが与える 11 変数)
|
|
686
694
|
|
|
@@ -714,10 +722,12 @@ DOM 要素の特定は CSS クラス名ではなく `data-*` 属性で行いま
|
|
|
714
722
|
| `--aqps-z-hover-tooltip` | オーバーレイ**内部**での追従ラベルと点の前後。器が積層文脈を作るため、この値がつまみへ届くことはない | `25` |
|
|
715
723
|
| `--aqps-z-handle-wrapper` | `.period-slider-handle-wrapper` の層 | `2` |
|
|
716
724
|
| `--aqps-z-handle-wrapper-active` | `.period-slider-handle-wrapper.is-active` の層 | `10` |
|
|
725
|
+
| `--aqps-z-date-popup` | `DateSelector` の `variant="dropdown"` が開くポップアップの層。`document.body` へポータルされるため、**ホストの層と直接重なるのはこれだけ** | `60` |
|
|
717
726
|
|
|
718
727
|
> [!NOTE]
|
|
719
728
|
> ノギスの 4 つの半円つまみは通常状態の層を上下段で変えており (上段 15 / 下段 20)、これはインラインスタイルが持ちます。`--aqps-z-handle` はこの 2 値を潰さないよう丸つまみだけに効きます。
|
|
720
729
|
> `--aqps-z-handle-wrapper` / `--aqps-z-handle-wrapper-active` が対象とする `.period-slider-handle-wrapper` は、現在のコンポーネントが描画する要素ではありません。公開済みのクラス契約として規則だけが残っているため、このクラスを自前のマークアップで使う場合にのみ意味を持ちます。
|
|
730
|
+
> `--aqps-z-date-popup` 以外の 8 つはスライダーのルート要素が作る積層文脈の内側で前後を決めます。ホストのヘッダーやモーダルとの前後を調整する場合、body 直下に立つポップアップだけは別の層にあるため、この 1 つを個別に与えてください。
|
|
721
731
|
|
|
722
732
|
#### インジケーターラベルの見た目と離隔
|
|
723
733
|
|
|
@@ -815,7 +825,7 @@ export function SelectorsExample() {
|
|
|
815
825
|
| `minDate` | `Date` | `undefined` | 選択可能な最小日付 (年のみ使用)。`minYear` と併用時は厳しい方を採用 |
|
|
816
826
|
| `maxDate` | `Date` | `undefined` | 選択可能な最大日付 (年のみ使用)。`maxYear` と併用時は厳しい方を採用 |
|
|
817
827
|
| `onChange` | `(date: Date, year: number) => void` | `undefined` | 年変更時コールバック。`date` は該当年の 1 月 1 日ローカル 0 時 |
|
|
818
|
-
| `disabled` | `boolean` | `false` | 無効化フラグ。`true` の間は `onChange` を発火せず、◀▶
|
|
828
|
+
| `disabled` | `boolean` | `false` | 無効化フラグ。`true` の間は `onChange` を発火せず、◀▶ とコンボボックス・セレクト・入力をネイティブに無効化する (タブ順から外れ、ポップアップも開かない) |
|
|
819
829
|
| `className` | `string` | `""` | ルート要素の追加 CSS クラス |
|
|
820
830
|
| `style` | `React.CSSProperties` | `undefined` | ルート要素のインラインスタイル |
|
|
821
831
|
| `children` | `React.ReactNode` | `undefined` | ルート要素末尾へ追加描画する子要素 |
|
|
@@ -879,7 +889,7 @@ const allowedMonths = useMemo(() => baseMonths.map((yyyymm) => new Date(Math.tru
|
|
|
879
889
|
| :--- | :--- | :--- | :--- |
|
|
880
890
|
| `value` | `Date` | `undefined` | 制御時の選択日付 (日単位に正規化)。`initialDate` 未指定時は必須。`initialDate` 指定時も `value` が優先 |
|
|
881
891
|
| `initialDate` | `Date` | `undefined` | 非制御時の初期選択日付。`value` 未指定時は必須。`value` 指定時は無視 |
|
|
882
|
-
| `variant` | `"date" \| "dropdown" \| "split-dropdown"` | `"date"` | `"date"`: `<input type="date">`、`"dropdown"`: `YYYY-MM-DD
|
|
892
|
+
| `variant` | `"date" \| "dropdown" \| "split-dropdown"` | `"date"` | `"date"`: `<input type="date">`、`"dropdown"`: 日単位の全選択肢を仮想化した `role="combobox"` (行は `YYYY-MM-DD`、定義域の広さに費用が比例しない)、`"split-dropdown"`: 年・月・日の 3 分割 `<select>` |
|
|
883
893
|
| `allowedDates` | `Date[]` | `undefined` | 選択可能な離散日付配列。空配列は「選択可能日なし」を意味する。境界で絞り込み・日単位で重複排除される |
|
|
884
894
|
| `minYear` | `number` | `undefined` | 選択可能な最小年 (その年の 1 月 1 日)。`minDate` と併用時は厳しい方を採用 |
|
|
885
895
|
| `maxYear` | `number` | `undefined` | 選択可能な最大年 (その年の 12 月 31 日)。`maxDate` と併用時は厳しい方を採用 |
|
|
@@ -892,11 +902,11 @@ const allowedMonths = useMemo(() => baseMonths.map((yyyymm) => new Date(Math.tru
|
|
|
892
902
|
| `children` | `React.ReactNode` | `undefined` | ルート要素末尾へ追加描画する子要素 |
|
|
893
903
|
| `prevDateAriaLabel` | `string` | `"Previous day"` | 前日ボタンのアクセシブル名 |
|
|
894
904
|
| `nextDateAriaLabel` | `string` | `"Next day"` | 翌日ボタンのアクセシブル名 |
|
|
895
|
-
| `selectAriaLabel` | `string` | `"Date"` |
|
|
905
|
+
| `selectAriaLabel` | `string` | `"Date"` | コンボボックス (とそのポップアップの listbox) および日付入力のアクセシブル名 |
|
|
896
906
|
| `yearAriaLabel` | `string` | `"Year"` | 年セレクトのアクセシブル名 (`variant="split-dropdown"` のみ) |
|
|
897
907
|
| `monthAriaLabel` | `string` | `"Month"` | 月セレクトのアクセシブル名 (`variant="split-dropdown"` のみ) |
|
|
898
908
|
| `dayAriaLabel` | `string` | `"Day"` | 日セレクトのアクセシブル名 (`variant="split-dropdown"` のみ) |
|
|
899
|
-
| `locale` | `string` | `undefined` | 選択肢テキストのロケール (BCP 47 言語タグ)。未指定は ISO 8601 (`variant="dropdown"` は `YYYY-MM-DD`、`variant="split-dropdown"` は `2024` / `01` / `15`)、指定時は `Intl.DateTimeFormat` 書式。`<input type="date">`
|
|
909
|
+
| `locale` | `string` | `undefined` | 選択肢テキストのロケール (BCP 47 言語タグ)。未指定は ISO 8601 (`variant="dropdown"` は `YYYY-MM-DD`、`variant="split-dropdown"` は `2024` / `01` / `15`)、指定時は `Intl.DateTimeFormat` 書式。`<input type="date">` の値・コンボボックスの `data-value`・`<option value>` は常に `yyyy-MM-dd` または生の数値。空文字列・不正タグ・非文字列は `RangeError` |
|
|
900
910
|
| `formatYearOption` | `(year: number) => string` | `undefined` | `variant="split-dropdown"` の年選択肢テキスト生成関数 (`locale` より優先) |
|
|
901
911
|
| `formatMonthOption` | `(month: number) => string` | `undefined` | `variant="split-dropdown"` の月選択肢テキスト生成関数。引数は 1〜12 (`locale` より優先) |
|
|
902
912
|
| `formatDayOption` | `(day: number) => string` | `undefined` | `variant="split-dropdown"` の日選択肢テキスト生成関数。引数は 1〜31 (`locale` より優先) |
|
|
@@ -905,13 +915,24 @@ const allowedMonths = useMemo(() => baseMonths.map((yyyymm) => new Date(Math.tru
|
|
|
905
915
|
境界要件と挙動:
|
|
906
916
|
|
|
907
917
|
- `value` (制御) と `initialDate` (非制御) はいずれか一方が必須です。共に省略した場合は `RangeError` を送出し、選択日付を壁時計時刻から推定しません。
|
|
908
|
-
- `variant="dropdown"`: `allowedDates`
|
|
918
|
+
- `variant="dropdown"`: `allowedDates` を指定しない場合、下限と上限の双方が必須です。選択肢は `minDate` 〜 `maxDate` の全日 (降順) ですが、配列としては実体化しません。件数は境界から算出し、行の日付・テキストは描画時に導出し、DOM に存在するのはポップアップの可視行だけです。境界を動かす費用は連続範囲で O(1)、`allowedDates` 指定時は二分探索の O(log n) で、100 年分 (36,525 日) の定義域でも 1 か月分と同じ費用で動きます。ポインタ移動ごとに境界を動かすホスト (ノギスの連動セレクタなど) でも、この変種を日単位のまま使えます。
|
|
909
919
|
- `variant="split-dropdown"`: 下限と上限の双方が必須で、`allowedDates` との併用は `RangeError` になります。存在しない日付になる年・月へ切り替えた場合 (1 月 31 日を選択中に 2 月へ変更等)、月末日へ丸めず選択を破棄し、`onChange` を発火しません。選択肢のテキストは既定でゼロ埋めの数値 (`2024` / `01` / `15`) で、`locale` または `formatYearOption` / `formatMonthOption` / `formatDayOption` で変更できます。
|
|
910
920
|
- `variant="date"`: 境界は任意です。指定した場合は `<input>` の `min` / `max` 属性へ反映されます。
|
|
911
921
|
- ステッパーは離散指定時に隣接する選択可能日へ移動し、集合の端では使用不可 (`aria-disabled="true"`) になります。
|
|
912
922
|
- 選択可能集合外の日付は丸められず破棄され、`onChange` は発火しません。
|
|
913
923
|
|
|
914
|
-
DOM 契約: ルート要素は `data-variant="date|dropdown|split-dropdown"` を持ち、現在値が選択可能集合の外にある場合は `data-out-of-range="true"` が付与されます。`variant="
|
|
924
|
+
DOM 契約: ルート要素は `data-variant="date|dropdown|split-dropdown"` を持ち、現在値が選択可能集合の外にある場合は `data-out-of-range="true"` が付与されます。`variant="split-dropdown"` ではさらに、各 `<select>` の先頭に現在値を表示する選択不可のプレースホルダ `<option value="">` が描画され (このとき `select.value === ""`)、`variant="date"` では `<input type="date">` が保持値をそのまま表示します。
|
|
925
|
+
|
|
926
|
+
`variant="dropdown"` の DOM 契約:
|
|
927
|
+
|
|
928
|
+
- 操作要素は `<input type="text" readonly role="combobox">` で、`value` には人間が読むテキスト (`locale` 書式)、`data-value` には常に `yyyy-MM-dd` の機械可読値を持ちます。`aria-expanded` / `aria-haspopup="listbox"` / `aria-controls` (開いている間) / `aria-activedescendant` (アクティブ行が描画されている間) を持ち、`data-testid="period-slider-date-combobox"` で引けます。集合外の保持値は行にならず、操作要素の表示テキストとしてだけ現れます。
|
|
929
|
+
- ポップアップは `document.body` へポータルされ (`data-testid="period-slider-date-popup"`)、開いた時点の操作要素の位置から解決した配色モードを `data-color-mode="light|dark"` として持ち、操作要素の下に開き、余地が無ければ上へ反転して視野内へ収まります。中の `role="listbox"` (アクセシブル名は `selectAriaLabel`) が `role="option"` の行を持ち、各行は `aria-selected` / `aria-posinset` / `aria-setsize` (集合全体の件数) / `data-active` (キーボードの現在位置) を持ち、`data-testid="period-slider-date-option"` で引けます。DOM に存在する行は可視窓の分だけで、集合全体の件数は `aria-setsize` から読みます。
|
|
930
|
+
- キーボード: `ArrowDown` / `ArrowUp` (閉じていれば開く、開いていれば 1 行移動)、`Home` / `End` (先頭 = 最新日 / 末尾 = 最古日)、`PageDown` / `PageUp` (1 窓 = 7 行)、`Enter` (閉じていれば開く、開いていればアクティブ行を確定)、`Escape` (閉じる・発火しない)、`Tab` (閉じる)、数字と `-` / `/` / `.` (先頭一致入力。`yyyy` / `yyyyMM` / `yyyyMMdd` として解釈し、走査せずに当該日へ飛ぶ)。行の押下でも DOM フォーカスは操作要素から離れません。
|
|
931
|
+
- 閉じる契機: 行の確定、`Escape`、`Tab`、操作要素からのフォーカス喪失、ポップアップ外の `pointerdown`。
|
|
932
|
+
- ポップアップは `.period-slider` の外に立つため、`colorScheme` の変数 (`--aqps-*`) は届きません。選択中の行のアクセント色はパッケージ既定の色です。重なり順だけは `--aqps-z-date-popup` (既定 60) で差し替えられます。
|
|
933
|
+
- ダークモードは `.dark` の位置に依存しません。ポップアップの祖先 (`document.body` の側) に `.dark` が無くても、**操作要素自身の位置**で解決したモードを `data-color-mode` として運ぶため、`.dark` を部分木へ限定したホストでも暗色で開きます。
|
|
934
|
+
|
|
935
|
+
`<select>` を前提にしていたテストの移行: `select.value` → `combobox.getAttribute("data-value")`、`select.options` を数える → 開いてから `aria-setsize` を読む (`renderedRows.length` は可視窓の分だけ)、`selectOption(value)` → 開いて行を押すか、ISO の数字を打って `Enter`。Playwright なら `getByRole("combobox", { name: "Date" })` はそのまま解決します (`toHaveValue` は `locale` 書式のテキストと比較されるので、ISO は `toHaveAttribute("data-value", …)` で読みます)。
|
|
915
936
|
|
|
916
937
|
### React フック
|
|
917
938
|
|
package/dist/DateSelector.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export interface DateSelectorProps {
|
|
|
32
32
|
/**
|
|
33
33
|
* UI Variant:
|
|
34
34
|
* - "date": Native input[type="date"] (default / 既定)
|
|
35
|
-
* - "dropdown":
|
|
35
|
+
* - "dropdown": Virtualized combobox over yyyy-MM-dd options; requires a bounded range or allowedDates
|
|
36
36
|
* - "split-dropdown": Three separate selects for year, month, and day; requires a bounded range and rejects allowedDates
|
|
37
37
|
*/
|
|
38
38
|
variant?: "date" | "dropdown" | "split-dropdown";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateSelector.d.ts","sourceRoot":"","sources":["../src/DateSelector.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"DateSelector.d.ts","sourceRoot":"","sources":["../src/DateSelector.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAkB9B;;;;;;;;;;GAUG;AACH,MAAM,WAAW,iBAAiB;IAC9B,qJAAqJ;IACrJ,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,uIAAuI;IACvI,WAAW,CAAC,EAAE,IAAI,CAAA;IAClB,iFAAiF;IACjF,QAAQ,CAAC,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;IAC3B,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,+GAA+G;IAC/G,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,+GAA+G;IAC/G,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gHAAgH;IAChH,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,gHAAgH;IAChH,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,4GAA4G;IAC5G,YAAY,CAAC,EAAE,IAAI,EAAE,CAAA;IACrB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,gBAAgB,CAAA;IAChD,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAC3B,6BAA6B;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,qFAAqF;IACrF,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,6EAA6E;IAC7E,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,qFAAqF;IACrF,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,oGAAoG;IACpG,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,sGAAsG;IACtG,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,kGAAkG;IAClG,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,0PAA0P;IAC1P,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,gKAAgK;IAChK,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IAC3C,oMAAoM;IACpM,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IAC7C,gMAAgM;IAChM,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;CAC5C;AAsgBD;;;GAGG;AACH,eAAO,MAAM,YAAY,oCAnWa,iBAAiB,KAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CA2XzE,CAAA"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { DateOptionDomain } from './dateOptionDomain.js';
|
|
3
|
+
/** Row height in px, matching the package's WCAG 2.5.5 target size / 行高 (px)。本パッケージの WCAG 2.5.5 当たり判定と一致 */
|
|
4
|
+
export declare const DATE_OPTION_ROW_HEIGHT = 44;
|
|
5
|
+
/**
|
|
6
|
+
* Total border thickness the popup's own frame takes out of its height, in px.
|
|
7
|
+
* ポップアップの枠線が自身の高さから差し引く合計の太さ (px)。
|
|
8
|
+
*
|
|
9
|
+
* The popup is a border-box, so the band the rows scroll in is `height - POPUP_BORDER_TOTAL`.
|
|
10
|
+
* Handing the outer height to the scroller instead makes every derived quantity (clip window, max
|
|
11
|
+
* scroll position, thumb mapping, rendered row count) that many pixels wrong, which the scroller
|
|
12
|
+
* reports as a warning and otherwise shows as a row that can never be scrolled fully into view.
|
|
13
|
+
* The stylesheet's own border width is the source of truth; a unit test pins the two together.
|
|
14
|
+
* ポップアップは border-box であり、行がスクロールする帯は `height - POPUP_BORDER_TOTAL`。
|
|
15
|
+
* 外側の高さをスクローラへ渡すと、クリップ窓・最大スクロール位置・つまみ写像・描画行数のすべてが
|
|
16
|
+
* その分ずれる (スクローラは警告を出すが、症状としては「最後まで送り込めない行」になる)。
|
|
17
|
+
* 真実の源はスタイルシートの枠線幅であり、両者は単体テストで固定する。
|
|
18
|
+
*/
|
|
19
|
+
export declare const POPUP_BORDER_TOTAL = 2;
|
|
20
|
+
/**
|
|
21
|
+
* Props of the virtualized day-resolution combobox.
|
|
22
|
+
* 仮想化された日単位コンボボックスの Props。
|
|
23
|
+
*/
|
|
24
|
+
export interface VirtualDateDropdownProps {
|
|
25
|
+
/** Index space of the selectable days, in descending order / 選択可能日の添字空間 (降順) */
|
|
26
|
+
domain: DateOptionDomain;
|
|
27
|
+
/** Index of the held value inside the domain, or {@link NO_OPTION_INDEX} when it is outside the selectable set / 保持値の領域内添字 (選択可能集合の外では {@link NO_OPTION_INDEX}) */
|
|
28
|
+
selectedIndex: number;
|
|
29
|
+
/** Option text of the held value, shown by the control whether or not it is selectable / 保持値の表示テキスト (選択可否に関わらず操作要素が表示) */
|
|
30
|
+
displayLabel: string;
|
|
31
|
+
/**
|
|
32
|
+
* Machine-readable yyyy-MM-dd of the held value, published as `data-value`.
|
|
33
|
+
* 保持値の機械可読値 (yyyy-MM-dd)。`data-value` として公開。
|
|
34
|
+
*
|
|
35
|
+
* A native `<select>` carried the ISO value in `value` and the localised text in the selected
|
|
36
|
+
* option's label, so the two surfaces were separate. A text input has only one, which the user
|
|
37
|
+
* reads, so the machine surface has to be named explicitly instead of disappearing.
|
|
38
|
+
* ネイティブ `<select>` は ISO 値を `value`、地域化テキストを選択中 option のラベルに持ち、
|
|
39
|
+
* 2 つの面が分かれていた。テキスト入力は面が 1 つ (利用者が読むもの) しかないため、
|
|
40
|
+
* 機械可読の面は消えるのではなく明示的に名前を持つ必要がある。
|
|
41
|
+
*/
|
|
42
|
+
machineValue: string;
|
|
43
|
+
/** Disabled flag / 無効化フラグ */
|
|
44
|
+
disabled: boolean;
|
|
45
|
+
/** Accessible name of the combobox and of its popup / コンボボックスとポップアップのアクセシブル名 */
|
|
46
|
+
ariaLabel: string;
|
|
47
|
+
/** Commits the date of an index the user picked / 利用者が選んだ添字の日付を確定する関数 */
|
|
48
|
+
onCommitIndex: (index: number) => void;
|
|
49
|
+
/** Class name of the control element / 操作要素のクラス名 */
|
|
50
|
+
controlClassName: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolves the index whose date best matches a partially typed date, without scanning the options.
|
|
54
|
+
* 部分入力された日付に最も合致する添字を、選択肢を走査せずに解決する関数。
|
|
55
|
+
*
|
|
56
|
+
* The digits of the buffer are read as `yyyy`, `yyyyMM`, `yyyyMMdd`, so the target date is computed
|
|
57
|
+
* and located through {@link DateOptionDomain.indexOf} instead of prefix-matching every label: a
|
|
58
|
+
* type-ahead over a century of days costs the same as over a month of days.
|
|
59
|
+
* バッファの数字を `yyyy` / `yyyyMM` / `yyyyMMdd` として読み、対象日付を算出して
|
|
60
|
+
* {@link DateOptionDomain.indexOf} で引く (全ラベルの前方一致照合を行わない)。
|
|
61
|
+
* 100 年分の日付に対する先頭一致入力の費用は 1 か月分と同じ。
|
|
62
|
+
*
|
|
63
|
+
* @param buffer - Digits typed so far, separators already stripped / これまでに入力された数字 (区切り文字は除去済み)
|
|
64
|
+
* @param domain - Option domain to locate the date in / 日付を引く対象の選択肢領域
|
|
65
|
+
* @returns Matching index, or {@link NO_OPTION_INDEX} when the buffer cannot name a day in the set / 合致する添字 (集合内の日を名指せない場合は {@link NO_OPTION_INDEX})
|
|
66
|
+
*/
|
|
67
|
+
export declare const resolveTypeAheadIndex: (buffer: string, domain: DateOptionDomain) => number;
|
|
68
|
+
/**
|
|
69
|
+
* Colour mode the popup paints itself in.
|
|
70
|
+
* ポップアップが自身を塗る配色モード。
|
|
71
|
+
*/
|
|
72
|
+
export type PopupColorMode = "light" | "dark";
|
|
73
|
+
/**
|
|
74
|
+
* Resolves the colour mode that applies at an element's own place in the tree.
|
|
75
|
+
* 要素自身が木の中で置かれた位置に適用される配色モードを解決する関数。
|
|
76
|
+
*
|
|
77
|
+
* The popup is portaled to `document.body`, so an ancestor-path rule (`.dark .period-slider-date-popup`)
|
|
78
|
+
* only reaches it when `.dark` sits above `<body>`. A host that scopes `.dark` to a subtree — which this
|
|
79
|
+
* package's own `@custom-variant dark (&:where(.dark, .dark *))` explicitly permits — would otherwise get
|
|
80
|
+
* a light popup over a dark page. Reading the mode where the control actually stands, and carrying it on
|
|
81
|
+
* the popup as `data-color-mode`, makes the two agree wherever the host puts the class.
|
|
82
|
+
* ポップアップは `document.body` へポータルされるため、祖先経路の規則 (`.dark .period-slider-date-popup`)
|
|
83
|
+
* が届くのは `.dark` が `<body>` より上にある場合だけ。`.dark` を部分木へ限定するホスト
|
|
84
|
+
* (本パッケージの `@custom-variant dark (&:where(.dark, .dark *))` が明示的に許す形) では、
|
|
85
|
+
* 暗色のページの上に明色のポップアップが載る。操作要素が実際に立つ位置でモードを読み、
|
|
86
|
+
* `data-color-mode` としてポップアップへ運ぶことで、クラスの置き場所に関わらず両者が一致。
|
|
87
|
+
*
|
|
88
|
+
* @param element - Element whose place in the tree decides the mode / 木の中の位置がモードを決める要素
|
|
89
|
+
* @returns Colour mode applying at that element / その要素に適用される配色モード
|
|
90
|
+
*/
|
|
91
|
+
export declare const resolveColorMode: (element: Element) => PopupColorMode;
|
|
92
|
+
/**
|
|
93
|
+
* Geometry of the popup relative to the viewport.
|
|
94
|
+
* 視野に対するポップアップの配置情報。
|
|
95
|
+
*/
|
|
96
|
+
export interface PopupGeometry {
|
|
97
|
+
/** Distance from the viewport top in px / 視野上端からの距離 (px) */
|
|
98
|
+
top: number;
|
|
99
|
+
/** Distance from the viewport left in px / 視野左端からの距離 (px) */
|
|
100
|
+
left: number;
|
|
101
|
+
/** Popup width in px, the control's width plus the scrollbar gutter / ポップアップの幅 (px。操作要素の幅 + スクロールバー分) */
|
|
102
|
+
width: number;
|
|
103
|
+
/** Popup height in px / ポップアップの高さ (px) */
|
|
104
|
+
height: number;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Places the popup below the control, flipping it above and clamping it when there is no room.
|
|
108
|
+
* ポップアップを操作要素の下に配置し、余地が無い場合は上へ反転・視野内へクランプする関数。
|
|
109
|
+
*
|
|
110
|
+
* A native `<select>` popup is placed by the browser and is always on screen; a DOM popup that only
|
|
111
|
+
* ever opens downward is unusable in the last row of a card, which is exactly where these selectors
|
|
112
|
+
* sit, so the placement is computed rather than declared in CSS.
|
|
113
|
+
* ネイティブ `<select>` のポップアップはブラウザが配置し常に画面内にあるが、下方向にしか開かない
|
|
114
|
+
* DOM ポップアップはカード最下段 (まさにこのセレクタが置かれる場所) では使えないため、
|
|
115
|
+
* 配置は CSS で宣言せず算出する。
|
|
116
|
+
*
|
|
117
|
+
* @param anchor - Bounding rect of the control / 操作要素の矩形
|
|
118
|
+
* @param desiredHeight - Height the popup asks for / ポップアップが要求する高さ
|
|
119
|
+
* @param viewportHeight - Height of the visual viewport / 視野の高さ
|
|
120
|
+
* @param viewportWidth - Width of the visual viewport / 視野の幅
|
|
121
|
+
* @returns Geometry to apply to the popup / ポップアップへ適用する配置情報
|
|
122
|
+
*/
|
|
123
|
+
export declare const resolvePopupGeometry: (anchor: {
|
|
124
|
+
top: number;
|
|
125
|
+
bottom: number;
|
|
126
|
+
left: number;
|
|
127
|
+
width: number;
|
|
128
|
+
}, desiredHeight: number, viewportHeight: number, viewportWidth: number) => PopupGeometry;
|
|
129
|
+
/**
|
|
130
|
+
* Day-resolution combobox whose popup renders only the rows it shows.
|
|
131
|
+
* 表示行のみを描画するポップアップを持つ日単位コンボボックス。
|
|
132
|
+
*
|
|
133
|
+
* The popup is not mounted while closed, so a host that moves `minDate` / `maxDate` on every
|
|
134
|
+
* pointer move pays only the O(1) recomputation of the domain: there is no option list to rebuild
|
|
135
|
+
* and no `<option>` LayoutObject to re-lay out.
|
|
136
|
+
* 閉じている間ポップアップはマウントされないため、ポインタ移動ごとに `minDate` / `maxDate` を
|
|
137
|
+
* 動かすホストが払う費用は領域の O(1) 再計算のみ (作り直す選択肢配列も、再レイアウトされる
|
|
138
|
+
* `<option>` の LayoutObject も存在しない)。
|
|
139
|
+
*/
|
|
140
|
+
export declare const VirtualDateDropdown: React.FC<VirtualDateDropdownProps>;
|
|
141
|
+
//# sourceMappingURL=VirtualDateDropdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualDateDropdown.d.ts","sourceRoot":"","sources":["../src/VirtualDateDropdown.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAG1D,4GAA4G;AAC5G,eAAO,MAAM,sBAAsB,KAAK,CAAA;AAQxC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,kBAAkB,IAAI,CAAA;AA4BnC;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACrC,gFAAgF;IAChF,MAAM,EAAE,gBAAgB,CAAA;IACxB,mKAAmK;IACnK,aAAa,EAAE,MAAM,CAAA;IACrB,0HAA0H;IAC1H,YAAY,EAAE,MAAM,CAAA;IACpB;;;;;;;;;;OAUG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB,6BAA6B;IAC7B,QAAQ,EAAE,OAAO,CAAA;IACjB,gFAAgF;IAChF,SAAS,EAAE,MAAM,CAAA;IACjB,yEAAyE;IACzE,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACtC,oDAAoD;IACpD,gBAAgB,EAAE,MAAM,CAAA;CAC3B;AAiBD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,EAAE,QAAQ,gBAAgB,KAAG,MAwBhF,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,MAAM,CAAA;AAE7C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB,GAAI,SAAS,OAAO,KAAG,cAKnD,CAAA;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC1B,4DAA4D;IAC5D,GAAG,EAAE,MAAM,CAAA;IACX,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAA;IACZ,yGAAyG;IACzG,KAAK,EAAE,MAAM,CAAA;IACb,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,eAAe,MAAM,EAAE,gBAAgB,MAAM,EAAE,eAAe,MAAM,KAAG,aAUjL,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CAuTlE,CAAA"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Lazily derived option domain of a bounded or discrete day-resolution selector.
|
|
3
|
+
*
|
|
4
|
+
* Describes the option set of a date dropdown as an index space instead of an array: the count is
|
|
5
|
+
* computed from the bounds, and the date / machine value / human label of index `i` are derived on
|
|
6
|
+
* demand. A bound change therefore costs O(1) for a continuous range and O(log n) for a discrete
|
|
7
|
+
* one, never O(count), and nothing proportional to the option count is ever allocated.
|
|
8
|
+
*
|
|
9
|
+
* 日単位セレクタの選択肢集合を「配列」ではなく「添字空間」として記述するモジュール。
|
|
10
|
+
* 件数は境界から算出し、添字 i の日付・機械可読値・表示ラベルは要求時に導出する。
|
|
11
|
+
* 境界変更の費用は連続範囲で O(1)、離散集合で O(log n) であり、件数に比例した確保は一切行わない。
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Index returned for a date that is not a member of the option set.
|
|
15
|
+
* 選択肢集合に属さない日付に対して返される添字。
|
|
16
|
+
*
|
|
17
|
+
* Every consumer compares against this name rather than against a bare `-1`, so the sentinel has
|
|
18
|
+
* one definition and a caller cannot accidentally treat it as a usable index.
|
|
19
|
+
* 全ての利用側は裸の `-1` ではなく本名で比較する (番兵の定義を 1 箇所に保ち、使える添字として
|
|
20
|
+
* 誤って扱われることを防ぐため)。
|
|
21
|
+
*/
|
|
22
|
+
export declare const NO_OPTION_INDEX = -1;
|
|
23
|
+
/**
|
|
24
|
+
* Converts a calendar day to a civil day serial number.
|
|
25
|
+
* 暦日を「日通番」へ変換する関数。
|
|
26
|
+
*
|
|
27
|
+
* Counting days through `Date.UTC` of the *local* calendar parts makes the serial exact across DST
|
|
28
|
+
* transitions and across time zones whose offset is not a whole number of hours: a local day is
|
|
29
|
+
* never 23 or 25 hours long in the serial space, so `serial(a) - serial(b)` is the true number of
|
|
30
|
+
* calendar days between two dates.
|
|
31
|
+
* ローカル暦の構成要素を `Date.UTC` へ渡して数えるため、通番は夏時間の遷移や 30 分刻みの
|
|
32
|
+
* タイムゾーンでも厳密 (通番空間ではローカル日が 23 時間や 25 時間になることがない)。
|
|
33
|
+
*
|
|
34
|
+
* @param date - Date whose local calendar day is counted / ローカル暦日を数える対象の日付
|
|
35
|
+
* @returns Integer day serial, monotonically increasing by 1 per calendar day / 暦日ごとに 1 増える整数の日通番
|
|
36
|
+
*/
|
|
37
|
+
export declare const toDaySerial: (date: Date) => number;
|
|
38
|
+
/**
|
|
39
|
+
* Rebuilds the local-midnight Date of a civil day serial number.
|
|
40
|
+
* 日通番からローカル 0 時の Date を復元する関数。
|
|
41
|
+
*
|
|
42
|
+
* @param serial - Integer day serial produced by {@link toDaySerial} / {@link toDaySerial} が返した整数の日通番
|
|
43
|
+
* @returns Date at 00:00:00.000 local time of that calendar day / その暦日のローカル 0 時を指す Date
|
|
44
|
+
*/
|
|
45
|
+
export declare const fromDaySerial: (serial: number) => Date;
|
|
46
|
+
/**
|
|
47
|
+
* Renders a date as the machine-readable yyyy-MM-dd value of an option.
|
|
48
|
+
* 日付を選択肢の機械可読値 (yyyy-MM-dd) へ整形する関数。
|
|
49
|
+
*
|
|
50
|
+
* Built from the calendar parts rather than through a date library because this runs once per
|
|
51
|
+
* rendered row and per commit, and a token-driven formatter costs about 19x more for identical
|
|
52
|
+
* output. Output is byte-identical to `date-fns` `format(date, "yyyy-MM-dd")` for every year from 1
|
|
53
|
+
* to 275760; at and below year 0 it emits the ISO 8601 rendering (`0000-01-01`, `-000001-01-01`)
|
|
54
|
+
* rather than the era year the library reports (`0001-01-01`, `0002-01-01`), because ISO 8601 is
|
|
55
|
+
* what this package's value surface promises.
|
|
56
|
+
* 日付ライブラリを介さず暦の構成要素から組むのは、描画行ごと・確定ごとに走る経路であり、
|
|
57
|
+
* トークン解釈型の書式化は同一出力に約 19 倍の費用を要するため。
|
|
58
|
+
* 出力は 1〜275760 年で `date-fns` の `format(date, "yyyy-MM-dd")` とバイト一致。
|
|
59
|
+
* 0 年以下では紀元表記ではなく ISO 8601 の拡張表記を出す (本パッケージの値の面が約束するのは
|
|
60
|
+
* ISO 8601 であるため)。
|
|
61
|
+
*
|
|
62
|
+
* @param date - Date to render / 整形対象の日付
|
|
63
|
+
* @returns Zero-padded yyyy-MM-dd of the local calendar day / ローカル暦日の 0 埋め yyyy-MM-dd
|
|
64
|
+
*/
|
|
65
|
+
export declare const formatIsoDay: (date: Date) => string;
|
|
66
|
+
/**
|
|
67
|
+
* Index space of the option set a day-resolution dropdown presents, in descending date order.
|
|
68
|
+
* 日単位ドロップダウンが提示する選択肢集合の添字空間 (日付の降順)。
|
|
69
|
+
*
|
|
70
|
+
* Index 0 is the latest selectable day, matching the descending order the package has always
|
|
71
|
+
* presented. Every accessor is O(1) for a continuous range and O(1) for a discrete one once the
|
|
72
|
+
* index range is resolved; none of them allocates per option.
|
|
73
|
+
* 添字 0 は最新の選択可能日で、本パッケージが従来提示してきた降順と一致。
|
|
74
|
+
* 各アクセサは連続範囲で O(1)、離散集合でも添字範囲解決後は O(1) であり、選択肢ごとの確保を行わない。
|
|
75
|
+
*/
|
|
76
|
+
export interface DateOptionDomain {
|
|
77
|
+
/** Number of selectable days; 0 means nothing is selectable / 選択可能日数 (0 は「選択可能日なし」) */
|
|
78
|
+
readonly count: number;
|
|
79
|
+
/** Local-midnight Date of the option at `index` / 添字 index の選択肢が表す日付 (ローカル 0 時) */
|
|
80
|
+
dateAt(index: number): Date;
|
|
81
|
+
/** Machine-readable yyyy-MM-dd of the option at `index` / 添字 index の選択肢の機械可読値 (yyyy-MM-dd) */
|
|
82
|
+
valueAt(index: number): string;
|
|
83
|
+
/** Human-facing option text of the option at `index` / 添字 index の選択肢の表示テキスト */
|
|
84
|
+
labelAt(index: number): string;
|
|
85
|
+
/** Index of a date inside the set, or {@link NO_OPTION_INDEX} when it is not selectable / 集合内での添字 (選択不可なら {@link NO_OPTION_INDEX}) */
|
|
86
|
+
indexOf(date: Date): number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Builds the option domain of a continuous, bounded day range without materializing it.
|
|
90
|
+
* 連続した境界付き日付範囲の選択肢領域を、実体化せずに構築する関数。
|
|
91
|
+
*
|
|
92
|
+
* @param minBound - Inclusive lower bound, normalized to local midnight / 下限 (ローカル 0 時に正規化済み・含む)
|
|
93
|
+
* @param maxBound - Inclusive upper bound, normalized to local midnight / 上限 (ローカル 0 時に正規化済み・含む)
|
|
94
|
+
* @param locale - BCP 47 language tag enabling Intl label formatting / Intl ラベル書式を有効化する BCP 47 言語タグ
|
|
95
|
+
* @returns Descending option domain of every calendar day in the range / 範囲内全暦日の降順選択肢領域
|
|
96
|
+
*/
|
|
97
|
+
export declare const createContinuousDateOptionDomain: (minBound: Date, maxBound: Date, locale: string | undefined) => DateOptionDomain;
|
|
98
|
+
/**
|
|
99
|
+
* Builds the option domain of a discrete date set, addressing the caller's own ascending array.
|
|
100
|
+
* 離散日付集合の選択肢領域を、呼び出し側の昇順配列をそのまま参照して構築する関数。
|
|
101
|
+
*
|
|
102
|
+
* The bounds are applied as an index window `[loIndex, hiIndex]` found by binary search, so a
|
|
103
|
+
* moving bound never copies, filters or re-sorts the array the host owns.
|
|
104
|
+
* 境界は二分探索で求めた添字窓 `[loIndex, hiIndex]` として適用するため、境界が動いても
|
|
105
|
+
* ホストが所有する配列の複製・絞り込み・再ソートは発生しない。
|
|
106
|
+
*
|
|
107
|
+
* @param ascending - Ascending, deduplicated, local-midnight dates owned by the caller / 呼び出し側が所有する昇順・重複排除済みのローカル 0 時日付
|
|
108
|
+
* @param loIndex - First in-bounds index, or a value greater than hiIndex when the window is empty / 境界内の先頭添字 (空窓時は hiIndex より大きい値)
|
|
109
|
+
* @param hiIndex - Last in-bounds index / 境界内の末尾添字
|
|
110
|
+
* @param locale - BCP 47 language tag enabling Intl label formatting / Intl ラベル書式を有効化する BCP 47 言語タグ
|
|
111
|
+
* @returns Descending option domain over the in-bounds window / 境界内の窓を降順に見せる選択肢領域
|
|
112
|
+
*/
|
|
113
|
+
export declare const createDiscreteDateOptionDomain: (ascending: readonly Date[], loIndex: number, hiIndex: number, locale: string | undefined) => DateOptionDomain;
|
|
114
|
+
/**
|
|
115
|
+
* Option domain presented when no day is selectable at all.
|
|
116
|
+
* 選択可能な日が 1 つも無い場合に提示される選択肢領域。
|
|
117
|
+
*
|
|
118
|
+
* The three accessors throw rather than inventing a date, because an empty domain has no index to
|
|
119
|
+
* serve and a substituted value would propagate a day the user never chose.
|
|
120
|
+
* 3 つのアクセサは日付を捏造せず送出する (空領域には提供できる添字が無く、代替値は利用者が
|
|
121
|
+
* 選んでいない日を伝播させるため)。
|
|
122
|
+
*/
|
|
123
|
+
export declare const EMPTY_DATE_OPTION_DOMAIN: DateOptionDomain;
|
|
124
|
+
/**
|
|
125
|
+
* Index window of a discrete ascending date list that falls inside the resolved bounds.
|
|
126
|
+
* 昇順離散日付配列のうち、解決済み境界の内側に入る添字窓。
|
|
127
|
+
*/
|
|
128
|
+
export interface DiscreteIndexWindow {
|
|
129
|
+
/** First in-bounds index / 境界内の先頭添字 */
|
|
130
|
+
readonly loIndex: number;
|
|
131
|
+
/** Last in-bounds index; smaller than loIndex when the window is empty / 境界内の末尾添字 (空窓時は loIndex より小さい) */
|
|
132
|
+
readonly hiIndex: number;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Finds the index window of a discrete ascending date list that falls inside the resolved bounds.
|
|
136
|
+
* 昇順離散日付配列のうち、解決済み境界の内側に入る添字窓を求める関数。
|
|
137
|
+
*
|
|
138
|
+
* @param ascending - Ascending, deduplicated dates / 昇順・重複排除済みの日付
|
|
139
|
+
* @param minBound - Inclusive lower bound, or null when unbounded / 下限 (無制限時は null・含む)
|
|
140
|
+
* @param maxBound - Inclusive upper bound, or null when unbounded / 上限 (無制限時は null・含む)
|
|
141
|
+
* @returns First and last in-bounds index; `loIndex > hiIndex` when the window is empty / 境界内の先頭・末尾添字 (空窓時は loIndex > hiIndex)
|
|
142
|
+
*/
|
|
143
|
+
export declare const resolveDiscreteIndexWindow: (ascending: readonly Date[], minBound: Date | null, maxBound: Date | null) => DiscreteIndexWindow;
|
|
144
|
+
/**
|
|
145
|
+
* Finds the nearest date of a discrete set strictly on one side of a reference time.
|
|
146
|
+
* 離散集合のうち、基準時刻の片側にある最も近い日付を求める関数。
|
|
147
|
+
*
|
|
148
|
+
* Binary search inside the in-bounds window replaces the linear scan a stepper button would
|
|
149
|
+
* otherwise run per render, which is what makes a discrete set of any size cost the same.
|
|
150
|
+
* 境界内の窓に対する二分探索が、ステッパーボタンが本来レンダーごとに行う線形走査を置き換える
|
|
151
|
+
* (これにより任意の大きさの離散集合が同一費用になる)。
|
|
152
|
+
*
|
|
153
|
+
* @param ascending - Ascending, deduplicated dates / 昇順・重複排除済みの日付
|
|
154
|
+
* @param loIndex - First in-bounds index / 境界内の先頭添字
|
|
155
|
+
* @param hiIndex - Last in-bounds index / 境界内の末尾添字
|
|
156
|
+
* @param time - Reference epoch milliseconds, excluded from the result / 基準のエポックミリ秒 (結果から除外)
|
|
157
|
+
* @param direction - -1 for the latest earlier date, 1 for the earliest later date / -1 で直前の日付、1 で直後の日付
|
|
158
|
+
* @returns Neighbouring date, or null when the window holds none on that side / 隣接日付 (その側に無い場合は null)
|
|
159
|
+
*/
|
|
160
|
+
export declare const findDiscreteNeighbour: (ascending: readonly Date[], loIndex: number, hiIndex: number, time: number, direction: -1 | 1) => Date | null;
|
|
161
|
+
/**
|
|
162
|
+
* Normalizes, deduplicates and sorts the discrete allowed dates without applying the bounds.
|
|
163
|
+
* 離散日付配列を正規化・重複排除・昇順ソートする関数 (境界は適用しない)。
|
|
164
|
+
*
|
|
165
|
+
* Leaving the bounds out is what lets a moving bound cost O(log n): the array is derived once per
|
|
166
|
+
* `allowedDates` content, and the bounds are then an index window over it.
|
|
167
|
+
* 境界を含めないことが、動く境界の費用を O(log n) にする鍵
|
|
168
|
+
* (配列は `allowedDates` の内容ごとに 1 度導出し、境界はその上の添字窓になる)。
|
|
169
|
+
*
|
|
170
|
+
* @param allowedDates - Caller supplied discrete dates / 呼び出し側が指定した離散日付
|
|
171
|
+
* @param assertValid - Per-entry validator invoked with the entry index / 要素添字付きで呼ばれる要素検証関数
|
|
172
|
+
* @returns Ascending, deduplicated local-midnight dates / 昇順・重複排除済みのローカル 0 時日付
|
|
173
|
+
*/
|
|
174
|
+
export declare const normalizeAllowedDates: (allowedDates: readonly Date[], assertValid: (index: number, entry: Date) => void) => Date[];
|
|
175
|
+
//# sourceMappingURL=dateOptionDomain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateOptionDomain.d.ts","sourceRoot":"","sources":["../src/dateOptionDomain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAgBH;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,KAAK,CAAA;AAEjC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,KAAG,MAMxC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,MAAM,KAAG,IAO9C,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,IAAI,KAAG,MAIzC,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC7B,uFAAuF;IACvF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,mFAAmF;IACnF,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,8FAA8F;IAC9F,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;IAC9B,+EAA+E;IAC/E,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;IAC9B,sIAAsI;IACtI,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAAA;CAC9B;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,gCAAgC,GAAI,UAAU,IAAI,EAAE,UAAU,IAAI,EAAE,QAAQ,MAAM,GAAG,SAAS,KAAG,gBAgB7G,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,8BAA8B,GAAI,WAAW,SAAS,IAAI,EAAE,EAAE,SAAS,MAAM,EAAE,SAAS,MAAM,EAAE,QAAQ,MAAM,GAAG,SAAS,KAAG,gBAsBzI,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,EAAE,gBAYtC,CAAA;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAChC,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,0GAA0G;IAC1G,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAC3B;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,GAAI,WAAW,SAAS,IAAI,EAAE,EAAE,UAAU,IAAI,GAAG,IAAI,EAAE,UAAU,IAAI,GAAG,IAAI,KAAG,mBAwBrH,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,qBAAqB,GAAI,WAAW,SAAS,IAAI,EAAE,EAAE,SAAS,MAAM,EAAE,SAAS,MAAM,EAAE,MAAM,MAAM,EAAE,WAAW,CAAC,CAAC,GAAG,CAAC,KAAG,IAAI,GAAG,IAwB5I,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,GAAI,cAAc,SAAS,IAAI,EAAE,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,KAAK,IAAI,KAAG,IAAI,EAY5H,CAAA"}
|