@aiquants/period-slider 0.18.0 → 0.19.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 +72 -0
- package/README.md +6 -4
- package/dist/DateSelector.d.ts +9 -9
- package/dist/DateSelector.d.ts.map +1 -1
- package/dist/MonthSelector.d.ts +5 -4
- package/dist/MonthSelector.d.ts.map +1 -1
- package/dist/PeriodSlider.d.ts +23 -4
- package/dist/PeriodSlider.d.ts.map +1 -1
- package/dist/VirtualDateDropdown.d.ts +15 -10
- package/dist/VirtualDateDropdown.d.ts.map +1 -1
- package/dist/YearSelector.d.ts +7 -4
- package/dist/YearSelector.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1925 -1915
- package/dist/optionText.d.ts +1 -1
- package/dist/optionText.d.ts.map +1 -1
- package/dist/selectorMemo.d.ts +30 -22
- package/dist/selectorMemo.d.ts.map +1 -1
- package/dist/useCommittedRef.d.ts +23 -15
- package/dist/useCommittedRef.d.ts.map +1 -1
- package/dist/usePeriodSlider.d.ts.map +1 -1
- package/dist/useUncontrolledSelection.d.ts +7 -7
- package/dist/useUncontrolledSelection.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/DateSelector.tsx +45 -20
- package/src/MonthSelector.tsx +41 -19
- package/src/PeriodSlider.tsx +39 -14
- package/src/VirtualDateDropdown.tsx +104 -88
- package/src/YearSelector.tsx +26 -27
- package/src/optionText.ts +6 -4
- package/src/selectorMemo.ts +41 -25
- package/src/useCommittedRef.ts +23 -15
- package/src/usePeriodSlider.ts +80 -50
- package/src/useUncontrolledSelection.ts +8 -9
package/src/PeriodSlider.tsx
CHANGED
|
@@ -662,8 +662,16 @@ export const yearKeyOfCivil = (year: number, monthIndex: number, yearStartMonth:
|
|
|
662
662
|
* Normalizes a date to the start of the specified unit.
|
|
663
663
|
* 指定した単位 (year, month, day) の先頭に日付を正規化します。
|
|
664
664
|
*
|
|
665
|
+
* Every unit reads d by its time value in the system time zone, through a plain copy, never through d's own getters: a Date
|
|
666
|
+
* subclass whose getters report another zone (a `TZDate` of `@date-fns/tz`, a `UTCDate` of `@date-fns/utc`) falls in the same
|
|
667
|
+
* unit as a plain Date of the same instant. This is the package's one reading of a Date; encode, keyInsideDateRange and every
|
|
668
|
+
* unit decision built on them (the body, the hooks, the three selectors) inherit it.
|
|
669
|
+
* どの単位も d を、自身のゲッターではなく時刻値のシステムのタイムゾーンでの読み (素の Date の複製) で読む。ゲッターが別のタイムゾーンを名乗る
|
|
670
|
+
* Date の派生クラス (`@date-fns/tz` の `TZDate`、`@date-fns/utc` の `UTCDate`) も、同じ時刻の素の Date と同じ単位に属する。これがパッケージの
|
|
671
|
+
* 唯一の Date の読み方で、encode・keyInsideDateRange とその上の単位の判定 (本体・フック・3 セレクタ) はすべてこれを継ぐ。
|
|
672
|
+
*
|
|
665
673
|
* @param unit - Time resolution unit / 時間解像度単位
|
|
666
|
-
* @param d - Date to normalize / 正規化対象の日付
|
|
674
|
+
* @param d - Date to normalize, read by its time value / 正規化対象の日付 (時刻値で読む)
|
|
667
675
|
* @param yearStartMonth - Calendar month a `unit: "year"` period starts in, 0-based; 0 keeps the calendar year (default: 0) / `unit: "year"` の 1 年が始まる暦月 (0 始まり)。0 は暦年 (既定: 0)
|
|
668
676
|
* @returns New Date pinned to the start of the unit / 単位先頭に揃えた新しい Date
|
|
669
677
|
* @throws RangeError when unit is not "year", "month" or "day", judged first (`normalizeDateByUnit: unit must be one of "year", "month", "day" (received: ...)`), when d is absent or an Invalid Date, or when yearStartMonth is not an integer in [0, 11] / unit が "year"・"month"・"day" でない場合 (最初に判定)、d が未指定または Invalid Date の場合、yearStartMonth が 0 以上 11 以下の整数でない場合
|
|
@@ -674,8 +682,9 @@ export const normalizeDateByUnit = (unit: PeriodSliderUnit, d: Date, yearStartMo
|
|
|
674
682
|
assertYearStartMonth("normalizeDateByUnit", yearStartMonth)
|
|
675
683
|
const normalized = new Date(d.getTime())
|
|
676
684
|
if (unit === "year") {
|
|
685
|
+
// 年月は d のゲッターでなく複製から読む。派生クラスのゲッターは別のタイムゾーンの年月を名乗り、複製を読む月・日の単位と別の暦になる。
|
|
677
686
|
// 月と日を 1 回で書かないと、月だけ先に書いた時点で月末日が桁溢れし、1 か月先へ飛ぶ
|
|
678
|
-
normalized.setFullYear(yearKeyOfCivil(
|
|
687
|
+
normalized.setFullYear(yearKeyOfCivil(normalized.getFullYear(), normalized.getMonth(), yearStartMonth), yearStartMonth, 1)
|
|
679
688
|
normalized.setHours(0, 0, 0, 0)
|
|
680
689
|
} else if (unit === "month") {
|
|
681
690
|
normalized.setDate(1)
|
|
@@ -691,7 +700,7 @@ export const normalizeDateByUnit = (unit: PeriodSliderUnit, d: Date, yearStartMo
|
|
|
691
700
|
* 日付を比較用数値キーにエンコードします。
|
|
692
701
|
*
|
|
693
702
|
* @param unit - Time resolution unit / 時間解像度単位
|
|
694
|
-
* @param d - Date to encode / エンコード対象の日付
|
|
703
|
+
* @param d - Date to encode, read by its time value in the system time zone (normalizeDateByUnit) / エンコード対象の日付 (時刻値をシステムのタイムゾーンで読む。normalizeDateByUnit)
|
|
695
704
|
* @param yearStartMonth - Calendar month a `unit: "year"` period starts in, 0-based; 0 keeps the calendar year (default: 0) / `unit: "year"` の 1 年が始まる暦月 (0 始まり)。0 は暦年 (既定: 0)
|
|
696
705
|
* @returns Integer key that is strictly monotonic in time for the given unit / 単位ごとに時間について厳密単調な整数キー
|
|
697
706
|
* @throws RangeError when unit is not "year", "month" or "day", judged first (`encode: unit must be one of "year", "month", "day" (received: ...)`), when d is absent or an Invalid Date, or when yearStartMonth is not an integer in [0, 11] / unit が "year"・"month"・"day" でない場合 (最初に判定)、d が未指定または Invalid Date の場合、yearStartMonth が 0 以上 11 以下の整数でない場合
|
|
@@ -830,8 +839,13 @@ export const keyInsideDateRange = (date: Date, unit: PeriodSliderUnit, yearStart
|
|
|
830
839
|
* 月・年の加算は shiftCivilMonths に従い年月日を 1 度で書くため、表現範囲の最後の月への加算も月末日からその日付を返す。
|
|
831
840
|
* Invalid Date になるのは和そのものが Date の表現範囲を越えるときだけ。
|
|
832
841
|
*
|
|
842
|
+
* The calendar fields are read from a plain copy of d's time value in the system time zone, as normalizeDateByUnit reads them,
|
|
843
|
+
* so a Date subclass whose getters report another zone steps from the same date as a plain Date of the same instant.
|
|
844
|
+
* 暦の欄は normalizeDateByUnit と同じく d の時刻値の複製からシステムのタイムゾーンで読むため、ゲッターが別のタイムゾーンを名乗る Date の派生クラスも、
|
|
845
|
+
* 同じ時刻の素の Date と同じ日付から進む。
|
|
846
|
+
*
|
|
833
847
|
* @param unit - Time resolution unit to step by / 加減算する時間解像度単位
|
|
834
|
-
* @param d - Base date / 起点日付
|
|
848
|
+
* @param d - Base date, read by its time value / 起点日付 (時刻値で読む)
|
|
835
849
|
* @param amount - Signed whole number of units to add / 加減算する整数の単位数 (符号付き)
|
|
836
850
|
* @returns New Date advanced by amount units, or an Invalid Date when the sum lies past the Date range / amount 単位進めた新しい Date (和が Date の表現範囲を越える場合は Invalid Date)
|
|
837
851
|
* @throws RangeError when unit is not "year", "month" or "day", judged first (`addUnit: unit must be one of "year", "month", "day" (received: ...)`), when d is absent or an Invalid Date (`addUnit: d must be a valid Date (received: ...)`), or when amount is not an integer (`addUnit: amount must be an integer number of units (received: ...)`) / unit が "year"・"month"・"day" でない場合 (最初に判定)、d が未指定または Invalid Date の場合、amount が整数でない場合
|
|
@@ -847,7 +861,7 @@ export const addUnit = (unit: PeriodSliderUnit, d: Date, amount: number): Date =
|
|
|
847
861
|
if (unit === "year" || unit === "month") {
|
|
848
862
|
// date-fns の加算は加算先の月末を先に組むため、表現範囲の最後の月へ届く加算は結果が表現できても Invalid Date になる。
|
|
849
863
|
// 年月日を 1 度で書けば月末日からでも桁溢れしない
|
|
850
|
-
shifted.setFullYear(...shiftCivilMonths(
|
|
864
|
+
shifted.setFullYear(...shiftCivilMonths(shifted.getFullYear(), shifted.getMonth(), shifted.getDate(), unit === "year" ? amount * 12 : amount))
|
|
851
865
|
return shifted
|
|
852
866
|
}
|
|
853
867
|
shifted.setDate(shifted.getDate() + amount)
|
|
@@ -927,6 +941,8 @@ export const getMacroWindowStartDate = (macroUnit: PeriodSliderUnit, microUnit:
|
|
|
927
941
|
* (年の末尾は 12 月ではなく `yearStartMonth` から数えて 12 番目の月。現地 0 時、0 時の無い日はその日の最初の瞬間)。
|
|
928
942
|
* 最後の単位はキーで数えるため、0-99 年は自分の年のまま、始まりが表現範囲の外にある期間も最後の単位を返す。
|
|
929
943
|
* それ以外の組では d 自身のミクロ単位の始まり。
|
|
944
|
+
* d is read by its time value in the system time zone (a plain copy), as normalizeDateByUnit reads it.
|
|
945
|
+
* d は normalizeDateByUnit と同じく時刻値の複製からシステムのタイムゾーンで読む。
|
|
930
946
|
*
|
|
931
947
|
* @param macroUnit - Macro scale unit / マクロ側の時間解像度単位
|
|
932
948
|
* @param microUnit - Micro scale unit / ミクロ側の時間解像度単位
|
|
@@ -941,12 +957,14 @@ export const getMacroWindowEndDate = (macroUnit: PeriodSliderUnit, microUnit: Pe
|
|
|
941
957
|
if (!isValidDate(d)) throw new RangeError(`getMacroWindowEndDate: d must be a valid Date (received: ${describeValue(d)})`)
|
|
942
958
|
assertYearStartMonth("getMacroWindowEndDate", yearStartMonth)
|
|
943
959
|
let lastKey: number
|
|
960
|
+
// 期間の年月は d のゲッターでなく複製から読む。派生クラスのゲッターは別のタイムゾーンの年月を名乗り、残りの組 (normalizeDateByUnit) と別の期間を指す
|
|
961
|
+
const plain = new Date(d.getTime())
|
|
944
962
|
if (macroUnit === "year" && microUnit !== "year") {
|
|
945
963
|
// 年の末尾は開始月から数えて 12 番目の月。暦年固定で 12 月を書くと、開始月をずらした年は自分が含まない月を末尾として名乗る
|
|
946
|
-
const [lastYear, lastMonth] = shiftCivilMonths(yearKeyOfCivil(
|
|
964
|
+
const [lastYear, lastMonth] = shiftCivilMonths(yearKeyOfCivil(plain.getFullYear(), plain.getMonth(), yearStartMonth), yearStartMonth, 1, 11)
|
|
947
965
|
lastKey = microUnit === "month" ? lastYear * 12 + lastMonth : dayKeyOfCivil(lastYear, lastMonth, daysInMonth(lastYear, lastMonth))
|
|
948
966
|
} else if (macroUnit === "month" && microUnit === "day") {
|
|
949
|
-
lastKey = dayKeyOfCivil(
|
|
967
|
+
lastKey = dayKeyOfCivil(plain.getFullYear(), plain.getMonth(), daysInMonth(plain.getFullYear(), plain.getMonth()))
|
|
950
968
|
} else {
|
|
951
969
|
// d 自身のミクロ単位の始まりを返す組。その始まりが範囲の外だと正規化は送出せずに Invalid Date を返し、clampDateInto を素通りして別の関数の名で落ちる
|
|
952
970
|
encodeInsideDateRange("getMacroWindowEndDate", "d", d, microUnit, yearStartMonth, "")
|
|
@@ -1064,7 +1082,7 @@ export interface PeriodQuarter {
|
|
|
1064
1082
|
* 四半期の境界は `yearStartMonth` を 3 で割った剰余だけで決まり、番号は `yearStartMonth` そのもので決まる。
|
|
1065
1083
|
* 0・3・6・9 では境界が暦四半期と一致して番号だけがずれ、他の 8 通りでは境界自体が動く。
|
|
1066
1084
|
*
|
|
1067
|
-
* @param d - Date to classify / 判定対象の日付
|
|
1085
|
+
* @param d - Date to classify, read by its time value in the system time zone (a plain copy), as normalizeDateByUnit reads it / 判定対象の日付 (normalizeDateByUnit と同じく時刻値の複製をシステムのタイムゾーンで読む)
|
|
1068
1086
|
* @param yearStartMonth - Calendar month a year starts in, 0-based; required, so the calendar year is never assumed / 1 年が始まる暦月 (0 始まり)。必須であり暦年を暗黙に仮定しない
|
|
1069
1087
|
* @returns Quarter coordinates of the date / 日付の四半期座標
|
|
1070
1088
|
* @throws RangeError when d is absent or an Invalid Date, or when yearStartMonth is not an integer in [0, 11] / d が未指定または Invalid Date の場合、yearStartMonth が 0 以上 11 以下の整数でない場合
|
|
@@ -1075,11 +1093,12 @@ export const resolveQuarter = (d: Date, yearStartMonth: number): PeriodQuarter =
|
|
|
1075
1093
|
// ずらした年の定義はパッケージに 1 つしかない。ここで年を導き直すと、レールが名乗る年と
|
|
1076
1094
|
// ラベルが印字する年が別の規則で決まることになる
|
|
1077
1095
|
const year = normalizeDateByUnit("year", d, yearStartMonth).getFullYear()
|
|
1096
|
+
// 月も年と同じく d のゲッターでなく複製から読む。派生クラスのゲッターは別のタイムゾーンの月を名乗り、年と別の暦の四半期を指す
|
|
1097
|
+
const startDate = new Date(d.getTime())
|
|
1078
1098
|
// 剰余は開始月より前の暦月で負を返し、四半期が 0 以下へ落ちる。+12 してもう一度畳む
|
|
1079
|
-
const monthsIntoYear = (((
|
|
1099
|
+
const monthsIntoYear = (((startDate.getMonth() - yearStartMonth) % 12) + 12) % 12
|
|
1080
1100
|
// monthsIntoYear は 0-11 に閉じており商は 0-3。序数が値域を外れることはない
|
|
1081
1101
|
const quarter = (Math.floor(monthsIntoYear / 3) + 1) as 1 | 2 | 3 | 4
|
|
1082
|
-
const startDate = new Date(d.getTime())
|
|
1083
1102
|
// 年・月・日を 1 回で書かないと、月だけ先に書いた時点で月末日が桁溢れし 1 か月先へ飛ぶ。
|
|
1084
1103
|
// 第 2 引数は 12 を超え得るが、同じ呼び出しなら翌年へ正しく繰り上がる
|
|
1085
1104
|
startDate.setFullYear(year, yearStartMonth + 3 * (quarter - 1), 1)
|
|
@@ -1149,15 +1168,17 @@ export const formatIsoYear = (year: number): string => (year >= 0 ? String(year)
|
|
|
1149
1168
|
* 指定単位における日付の ISO 8601 暦表記 (ロケール非依存) を生成する関数。
|
|
1150
1169
|
*
|
|
1151
1170
|
* @param unit - Time resolution unit deciding the precision / 精度を決める時間解像度単位
|
|
1152
|
-
* @param d - Valid date to render / 表記対象の有効な日付
|
|
1171
|
+
* @param d - Valid date to render, read by its time value in the system time zone (a plain copy) / 表記対象の有効な日付 (時刻値の複製をシステムのタイムゾーンで読む)
|
|
1153
1172
|
* @returns "2025" for year, "2025-01" for month, "2025-01-15" for day / year は "2025"、month は "2025-01"、day は "2025-01-15"
|
|
1154
1173
|
*/
|
|
1155
1174
|
const formatIsoByUnit = (unit: PeriodSliderUnit, d: Date): string => {
|
|
1156
|
-
|
|
1175
|
+
// Intl の経路は時刻値をシステムのタイムゾーンで読む。派生クラスのゲッターを読むと、formatLocale の有無で別の日を名乗る
|
|
1176
|
+
const plain = new Date(d.getTime())
|
|
1177
|
+
const year = formatIsoYear(plain.getFullYear())
|
|
1157
1178
|
if (unit === "year") return year
|
|
1158
|
-
const month = String(
|
|
1179
|
+
const month = String(plain.getMonth() + 1).padStart(2, "0")
|
|
1159
1180
|
if (unit === "month") return `${year}-${month}`
|
|
1160
|
-
const day = String(
|
|
1181
|
+
const day = String(plain.getDate()).padStart(2, "0")
|
|
1161
1182
|
return `${year}-${month}-${day}`
|
|
1162
1183
|
}
|
|
1163
1184
|
|
|
@@ -1171,6 +1192,10 @@ const formatIsoByUnit = (unit: PeriodSliderUnit, d: Date): string => {
|
|
|
1171
1192
|
* into a generic package, and Intl output drifts between ICU versions.
|
|
1172
1193
|
* 解決順序は customFormat が最優先、次に formatLocale 指定時の Intl.DateTimeFormat、未指定時はロケール非依存の ISO 8601。
|
|
1173
1194
|
* ISO 表記は本パッケージの仕様上の既定値であり代替値ではない (自然言語既定は汎用パッケージに 1 言語を焼き付け、Intl 出力は ICU 版で揺れるため)。
|
|
1195
|
+
* Both built-in tiers read d by its time value in the system time zone, so a Date subclass whose getters report another zone is
|
|
1196
|
+
* labelled as a plain Date of the same instant; customFormat receives d as passed.
|
|
1197
|
+
* 組み込みの 2 段はどちらも d を時刻値のシステムのタイムゾーンで読むため、ゲッターが別のタイムゾーンを名乗る Date の派生クラスも、同じ時刻の
|
|
1198
|
+
* 素の Date と同じ表記になる (customFormat には渡された d をそのまま渡す)。
|
|
1174
1199
|
*
|
|
1175
1200
|
* @param unit - Time resolution unit deciding the precision / 精度を決める時間解像度単位
|
|
1176
1201
|
* @param d - Date to format / 書式化対象の日付
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* アクセシブル名・値の面を保ちながら、キャレットとソフトキーボードを操作から外す。
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { VirtualScroll, type VirtualScrollHandle
|
|
17
|
+
import { VirtualScroll, type VirtualScrollHandle } from "@aiquants/virtualscroll"
|
|
18
18
|
import type React from "react"
|
|
19
19
|
import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react"
|
|
20
20
|
import { createPortal } from "react-dom"
|
|
@@ -285,18 +285,23 @@ const clampActiveIndex = (index: number, count: number): number => (index < coun
|
|
|
285
285
|
*
|
|
286
286
|
* Rows take the domain, the held value's index and the active index from the render that made the row renderer, which is
|
|
287
287
|
* memoized on them, so a render that changes none of them (the popup following a page scroll) re-renders no row, and a row
|
|
288
|
-
* the scroller renders on its own reads the same render as the rest of the popup. Functions that outlive their render (
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
288
|
+
* the scroller renders on its own reads the same render as the rest of the popup. Functions that outlive their render (a row's
|
|
289
|
+
* click) and the effect that re-anchors the popup read the last committed render through useCommittedRef; the handlers React
|
|
290
|
+
* attaches as props, and the active row's ref, read their own render, which is the committed one. No render writes a ref or
|
|
291
|
+
* the state. An active index the domain no longer contains is drawn on the last row by the render that shrinks the domain, and
|
|
292
|
+
* the commit that drew it records it as the held index from a layout effect, leaving alone a move queued after that render
|
|
293
|
+
* read the state. The control's two IDREFs name only elements in the DOM: `aria-controls` names the listbox under the same
|
|
294
|
+
* condition that renders the popup, and `aria-activedescendant` is not a prop — the active row's ref writes it in the commit
|
|
295
|
+
* that attaches the row, and the cleanup it returns, holding the control it wrote to, removes it in the commit that detaches
|
|
296
|
+
* the row, including when Activity or Suspense hides the subtree.
|
|
294
297
|
* 行は、行の描画関数を作った描画の領域・保持値の添字・アクティブ添字を読み、描画関数はそれらでメモ化する。どれも変えない描画
|
|
295
298
|
* (ページのスクロールに追従するポップアップ) は行を 1 つも描き直さず、スクローラが自分で描く行もポップアップの他の部分と同じ描画を読む。
|
|
296
|
-
* 描画より長く生きる関数 (
|
|
297
|
-
* React が Props
|
|
298
|
-
*
|
|
299
|
-
* (その描画がステートを読んだ後に積まれた移動は上書きしない)
|
|
299
|
+
* 描画より長く生きる関数 (行の押下) と引き直しのエフェクトは useCommittedRef を通して最後に確定した描画を読み、
|
|
300
|
+
* React が Props として付ける処理関数とアクティブ行の ref は自身の描画 (確定した描画) を読む。どの描画も ref にもステートにも書かない。
|
|
301
|
+
* 領域が含まなくなったアクティブ添字は、領域を縮めた描画が末尾の行として描き、それを描いた確定がレイアウト副作用で保持する添字へ記録する
|
|
302
|
+
* (その描画がステートを読んだ後に積まれた移動は上書きしない)。操作要素の 2 つの IDREF は DOM に在る要素だけを指す。`aria-controls` は
|
|
303
|
+
* ポップアップを描くのと同じ条件で listbox を名乗り、`aria-activedescendant` は Props ではなく、アクティブ行の ref が行を付けた確定で書き、
|
|
304
|
+
* 書いた操作要素を持つ後始末が行を外す確定 (Activity・Suspense による退避を含む) で消す。
|
|
300
305
|
*/
|
|
301
306
|
export const VirtualDateDropdown: React.FC<VirtualDateDropdownProps> = ({ domain, selectedIndex, openAnchorIndex, displayLabel, machineValue, disabled, ariaLabel, locale, labels, onCommitIndex, controlClassName }) => {
|
|
302
307
|
const reactId = useId()
|
|
@@ -307,7 +312,6 @@ export const VirtualDateDropdown: React.FC<VirtualDateDropdownProps> = ({ domain
|
|
|
307
312
|
|
|
308
313
|
const [isOpen, setIsOpen] = useState(false)
|
|
309
314
|
const [heldActiveIndex, setActiveIndex] = useState(NO_OPTION_INDEX)
|
|
310
|
-
const [isActiveRendered, setIsActiveRendered] = useState(true)
|
|
311
315
|
const [geometry, setGeometry] = useState<PopupGeometry | null>(null)
|
|
312
316
|
const [colorMode, setColorMode] = useState<PopupColorMode | null>(null)
|
|
313
317
|
|
|
@@ -317,8 +321,8 @@ export const VirtualDateDropdown: React.FC<VirtualDateDropdownProps> = ({ domain
|
|
|
317
321
|
const typeAheadRef = useRef<{ buffer: string; at: number }>({ buffer: "", at: 0 })
|
|
318
322
|
|
|
319
323
|
const count = domain.count
|
|
320
|
-
//
|
|
321
|
-
//
|
|
324
|
+
// 件数が縮むと、保持していたアクティブ添字が範囲外に取り残される。確定後に寄せるまで待つと、その間の確定は
|
|
325
|
+
// アクティブ行を描かず (名指しも無く)、Enter が境界検査に弾かれる。描く添字はこの描画の件数で寄せて導き、
|
|
322
326
|
// 状態への記録はそれを描いた確定のレイアウト副作用に回す。描画中に記録すると、確定しない描画 (Suspense が保留した移行) の
|
|
323
327
|
// 寄せた値を React が同値判定の基準に残し、利用者がその添字へ動かす打鍵が描画を起こさずに捨てられる
|
|
324
328
|
const activeIndex = clampActiveIndex(heldActiveIndex, count)
|
|
@@ -391,9 +395,8 @@ export const VirtualDateDropdown: React.FC<VirtualDateDropdownProps> = ({ domain
|
|
|
391
395
|
return () => document.removeEventListener("pointerdown", onPointerDown, true)
|
|
392
396
|
}, [isOpen, close])
|
|
393
397
|
|
|
394
|
-
//
|
|
395
|
-
//
|
|
396
|
-
// aria-controls / aria-activedescendant が存在しない要素を指したまま残り、読み上げが嘘をつく
|
|
398
|
+
// open() が開ける条件を見るのは入口だけ。開いたまま境界が狭まって選択肢が 0 になるとポップアップは消えるのに
|
|
399
|
+
// aria-expanded="true" が残り、disabled になると無効な操作要素の下でポップアップが操作できるまま残る
|
|
397
400
|
useEffect(() => {
|
|
398
401
|
if (isOpen && (disabled || count === 0)) close()
|
|
399
402
|
}, [isOpen, disabled, count, close])
|
|
@@ -510,16 +513,29 @@ export const VirtualDateDropdown: React.FC<VirtualDateDropdownProps> = ({ domain
|
|
|
510
513
|
const getItem = useCallback((index: number) => index, [])
|
|
511
514
|
const getItemHeight = useCallback(() => DATE_OPTION_ROW_HEIGHT, [])
|
|
512
515
|
|
|
513
|
-
// aria-activedescendant
|
|
514
|
-
//
|
|
515
|
-
//
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
516
|
+
// aria-activedescendant は DOM に在る行しか指せない (WAI-ARIA)。どの行が DOM に在るかはスクローラが自分の状態で決め、描画範囲の通知は
|
|
517
|
+
// 確定より後のアニメーションフレームで届くため、通知から導くと窓を動かした確定が消えた行を指し、戻した確定が名指しを欠く。そこで属性は
|
|
518
|
+
// Props として描かず、アクティブ行の ref が行を付けた確定で書き、行を外す確定で返した後始末が消す。後始末は付けた時点の操作要素を閉包に持つ。
|
|
519
|
+
// 隠れた Activity・Suspense が退避するときは操作要素の ref が行より先に外れ、外す時点で ref を読むと消し損ねて、隠れている間に閉じた
|
|
520
|
+
// ポップアップの消えた行を表示後も指し続ける。外す処理 (変更の段階) は付ける処理 (レイアウトの段階) より先に走り、消すのは自分が書いた値の
|
|
521
|
+
// ときだけなので、次のアクティブ行の名指しは消さない
|
|
522
|
+
const activeOptionId = activeIndex === NO_OPTION_INDEX ? null : optionId(activeIndex)
|
|
523
|
+
/**
|
|
524
|
+
* Ref of the active row: names it on the combobox control while the row is attached.
|
|
525
|
+
* アクティブ行の ref。行が付いている間だけ操作要素からその行を名指す関数。
|
|
526
|
+
*
|
|
527
|
+
* @returns Cleanup React runs when the row detaches (deleted, or hidden by Activity / Suspense); removes the name only while it is still this row's / 行が外れるとき (削除、または Activity / Suspense による退避) に React が呼ぶ後始末。名指しがまだこの行のときだけ消す
|
|
528
|
+
* @throws Error when the row attaches without the control or an active option id / 操作要素かアクティブ添字が無いまま行が付いた場合
|
|
529
|
+
*/
|
|
530
|
+
const nameActiveRow = useCallback((): (() => void) => {
|
|
531
|
+
const control = controlRef.current
|
|
532
|
+
// この ref はアクティブ行にだけ付き、操作要素はポータルより前の兄弟として先に付く。満たされないのは不変条件の破れ
|
|
533
|
+
if (control === null || activeOptionId === null) throw new Error("VirtualDateDropdown: the active row attached without its combobox control or an active option id, so aria-activedescendant has nothing to name it on")
|
|
534
|
+
control.setAttribute("aria-activedescendant", activeOptionId)
|
|
535
|
+
return () => {
|
|
536
|
+
if (control.getAttribute("aria-activedescendant") === activeOptionId) control.removeAttribute("aria-activedescendant")
|
|
537
|
+
}
|
|
538
|
+
}, [activeOptionId])
|
|
523
539
|
|
|
524
540
|
// 行は描画の値を閉包から読む。スクローラが自分の状態だけで行を描き足すときに呼ぶのは確定した描画の関数であり、
|
|
525
541
|
// 描き足した行も aria-setsize や他の行と同じ領域を読む。依存配列は行の見た目を決める値に限り、領域は所有側が
|
|
@@ -539,6 +555,7 @@ export const VirtualDateDropdown: React.FC<VirtualDateDropdownProps> = ({ domain
|
|
|
539
555
|
aria-setsize={domain.count}
|
|
540
556
|
data-testid="period-slider-date-option"
|
|
541
557
|
data-active={isActive ? "true" : undefined}
|
|
558
|
+
ref={isActive ? nameActiveRow : undefined}
|
|
542
559
|
className="period-slider-date-option"
|
|
543
560
|
style={{ height: DATE_OPTION_ROW_HEIGHT }}
|
|
544
561
|
onClick={() => commitRef.current(index)}>
|
|
@@ -546,69 +563,69 @@ export const VirtualDateDropdown: React.FC<VirtualDateDropdownProps> = ({ domain
|
|
|
546
563
|
</div>
|
|
547
564
|
)
|
|
548
565
|
},
|
|
549
|
-
[domain, selectedIndex, activeIndex, optionId, commitRef],
|
|
566
|
+
[domain, selectedIndex, activeIndex, optionId, commitRef, nameActiveRow],
|
|
550
567
|
)
|
|
551
568
|
|
|
552
569
|
// 配置と配色モードはどちらも操作要素の実測から来る。片方だけで描くと、最初のフレームだけ
|
|
553
|
-
//
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
570
|
+
// 明色のポップアップが暗色のページに載る。listbox を描く条件はこの 1 つで、aria-controls も同じ条件で名乗る。
|
|
571
|
+
// 開いている (isOpen) だけで名乗ると、配置の実測前の最初の確定と、件数 0 で閉じる前の確定で、存在しない listbox を指す
|
|
572
|
+
const isPopupShown = isOpen && geometry !== null && colorMode !== null && count > 0
|
|
573
|
+
const popup = isPopupShown ? (
|
|
574
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: ポップアップの外枠が拾うのは「フォーカスを奪わせない」ための mousedown 抑止だけで、操作機能は持たない。操作は内側の role="option" と操作要素が担う
|
|
575
|
+
<div
|
|
576
|
+
ref={popupRef}
|
|
577
|
+
className="period-slider-date-popup"
|
|
578
|
+
data-testid="period-slider-date-popup"
|
|
579
|
+
data-color-mode={colorMode}
|
|
580
|
+
style={{ top: geometry.top, left: geometry.left, width: geometry.width, height: geometry.height }}
|
|
581
|
+
onMouseDown={(event) => {
|
|
582
|
+
// 行や余白を掴んでも操作要素からフォーカスを奪わない (コンボボックスは DOM
|
|
583
|
+
// フォーカスを操作要素に保持し続ける契約)。pointer 系は抑止しないため、
|
|
584
|
+
// スクロールバーのドラッグは妨げない
|
|
585
|
+
event.preventDefault()
|
|
586
|
+
}}>
|
|
587
|
+
<VirtualScroll
|
|
588
|
+
ref={scrollRef}
|
|
589
|
+
itemCount={count}
|
|
590
|
+
getItem={getItem}
|
|
591
|
+
getItemHeight={getItemHeight}
|
|
592
|
+
viewportSize={geometry.height - POPUP_BORDER_TOTAL}
|
|
593
|
+
initialScrollIndex={activeIndex !== NO_OPTION_INDEX ? activeIndex : undefined}
|
|
594
|
+
className="h-full w-full"
|
|
595
|
+
testId="period-slider-date-listbox-pane"
|
|
596
|
+
locale={locale}
|
|
597
|
+
labels={engineLabels}
|
|
598
|
+
contentProps={{
|
|
599
|
+
id: listboxId,
|
|
600
|
+
role: "listbox",
|
|
601
|
+
"aria-label": ariaLabel,
|
|
602
|
+
}}
|
|
603
|
+
scrollBarOptions={{
|
|
604
|
+
width: POPUP_SCROLLBAR_WIDTH,
|
|
605
|
+
// ポップアップとその子孫はページのタブ順から除外する (APG)。
|
|
606
|
+
// 未指定だと矢印ボタンが tabIndex=0 のままポップアップのタブ順へ露出する
|
|
607
|
+
enableArrowButtons: false,
|
|
608
|
+
enableThumbDrag: true,
|
|
609
|
+
enableTrackClick: true,
|
|
610
|
+
// 必ず false。スクローラの既定は有効で、直径 40px の円がポップアップの上へ重なる。
|
|
611
|
+
// 大きなスクロール面を親指で送るための部品であり、操作要素の幅に合わせた
|
|
612
|
+
// 1 列のリストでは行を覆うだけで、ネイティブのポップアップにも無い
|
|
613
|
+
tapScrollCircleOptions: { enabled: false },
|
|
614
|
+
}}
|
|
615
|
+
behaviorOptions={{
|
|
616
|
+
// 必ず false。true だと各行ラッパーに tabIndex=-1 が付いてポップアップが
|
|
617
|
+
// タブ順に入り、pointerdown で行へフォーカスが移って操作要素から奪う。
|
|
618
|
+
// キーボード操作は aria-activedescendant 方式で本コンポーネントが担う
|
|
619
|
+
enableKeyboardNavigation: false,
|
|
620
|
+
// 必ず "contain"。端に達してもホイールをページへ連鎖させない (ネイティブ
|
|
621
|
+
// <select> と同じ)。既定 "auto" では末尾の次のノッチでページ本体が動き、
|
|
622
|
+
// 固定配置のポップアップが操作要素から離れて見える
|
|
623
|
+
overscrollBehavior: "contain",
|
|
568
624
|
}}>
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
getItemHeight={getItemHeight}
|
|
574
|
-
viewportSize={geometry.height - POPUP_BORDER_TOTAL}
|
|
575
|
-
initialScrollIndex={activeIndex !== NO_OPTION_INDEX ? activeIndex : undefined}
|
|
576
|
-
onRangeChange={handleRangeChange}
|
|
577
|
-
className="h-full w-full"
|
|
578
|
-
testId="period-slider-date-listbox-pane"
|
|
579
|
-
locale={locale}
|
|
580
|
-
labels={engineLabels}
|
|
581
|
-
contentProps={{
|
|
582
|
-
id: listboxId,
|
|
583
|
-
role: "listbox",
|
|
584
|
-
"aria-label": ariaLabel,
|
|
585
|
-
}}
|
|
586
|
-
scrollBarOptions={{
|
|
587
|
-
width: POPUP_SCROLLBAR_WIDTH,
|
|
588
|
-
// ポップアップとその子孫はページのタブ順から除外する (APG)。
|
|
589
|
-
// 未指定だと矢印ボタンが tabIndex=0 のままポップアップのタブ順へ露出する
|
|
590
|
-
enableArrowButtons: false,
|
|
591
|
-
enableThumbDrag: true,
|
|
592
|
-
enableTrackClick: true,
|
|
593
|
-
// 必ず false。スクローラの既定は有効で、直径 40px の円がポップアップの上へ重なる。
|
|
594
|
-
// 大きなスクロール面を親指で送るための部品であり、操作要素の幅に合わせた
|
|
595
|
-
// 1 列のリストでは行を覆うだけで、ネイティブのポップアップにも無い
|
|
596
|
-
tapScrollCircleOptions: { enabled: false },
|
|
597
|
-
}}
|
|
598
|
-
behaviorOptions={{
|
|
599
|
-
// 必ず false。true だと各行ラッパーに tabIndex=-1 が付いてポップアップが
|
|
600
|
-
// タブ順に入り、pointerdown で行へフォーカスが移って操作要素から奪う。
|
|
601
|
-
// キーボード操作は aria-activedescendant 方式で本コンポーネントが担う
|
|
602
|
-
enableKeyboardNavigation: false,
|
|
603
|
-
// 必ず "contain"。端に達してもホイールをページへ連鎖させない (ネイティブ
|
|
604
|
-
// <select> と同じ)。既定 "auto" では末尾の次のノッチでページ本体が動き、
|
|
605
|
-
// 固定配置のポップアップが操作要素から離れて見える
|
|
606
|
-
overscrollBehavior: "contain",
|
|
607
|
-
}}>
|
|
608
|
-
{renderOption}
|
|
609
|
-
</VirtualScroll>
|
|
610
|
-
</div>
|
|
611
|
-
) : null
|
|
625
|
+
{renderOption}
|
|
626
|
+
</VirtualScroll>
|
|
627
|
+
</div>
|
|
628
|
+
) : null
|
|
612
629
|
|
|
613
630
|
return (
|
|
614
631
|
<>
|
|
@@ -619,10 +636,9 @@ export const VirtualDateDropdown: React.FC<VirtualDateDropdownProps> = ({ domain
|
|
|
619
636
|
readOnly
|
|
620
637
|
aria-label={ariaLabel}
|
|
621
638
|
aria-expanded={isOpen}
|
|
622
|
-
aria-controls={
|
|
639
|
+
aria-controls={isPopupShown ? listboxId : undefined}
|
|
623
640
|
aria-haspopup="listbox"
|
|
624
641
|
aria-autocomplete="none"
|
|
625
|
-
aria-activedescendant={isOpen && activeIndex !== NO_OPTION_INDEX && isActiveRendered ? optionId(activeIndex) : undefined}
|
|
626
642
|
disabled={disabled}
|
|
627
643
|
value={displayLabel}
|
|
628
644
|
className={controlClassName}
|
package/src/YearSelector.tsx
CHANGED
|
@@ -22,9 +22,9 @@ import type React from "react"
|
|
|
22
22
|
import { memo, useMemo } from "react"
|
|
23
23
|
import { assertCandidateListInput, describeValue, isValidDate } from "./inputValue"
|
|
24
24
|
import { areLabelOverridesEqual, type PeriodSliderLabelOverrides, type PeriodSliderLocale } from "./labels"
|
|
25
|
-
import { assertLocaleTag, encodeInsideDateRange, formatLabel, isYearStartMonth, type PeriodOptionFormatter, resolveYearStartMonth, sentinelBoundRemedy } from "./PeriodSlider"
|
|
25
|
+
import { assertLocaleTag, encodeInsideDateRange, formatLabel, isYearStartMonth, type PeriodOptionFormatter, resolveYearStartMonth, sentinelBoundRemedy, yearKeyOfCivil } from "./PeriodSlider"
|
|
26
26
|
import { STEPPER_ROW_GAP_CLASS, StepperButton } from "./StepperButton"
|
|
27
|
-
import { areSelectorDatePropsEqual } from "./selectorMemo"
|
|
27
|
+
import { areSelectorDatePropsEqual, selectorUnitKey } from "./selectorMemo"
|
|
28
28
|
import { assertSelectorStepper, type SelectorStepper } from "./selectorStep"
|
|
29
29
|
import { useResolvedLabels } from "./useResolvedLabels"
|
|
30
30
|
import { useUncontrolledSelection } from "./useUncontrolledSelection"
|
|
@@ -114,29 +114,22 @@ function yearStart(year: number, yearStartMonth: number): Date {
|
|
|
114
114
|
* Resolves the year a date belongs to when a year starts in the given calendar month.
|
|
115
115
|
* 年の開始月を指定したときに、日付が属する年を解決する関数。
|
|
116
116
|
*
|
|
117
|
-
* The rule is the package's single definition of a shifted year, shared with `normalizeDateByUnit`
|
|
118
|
-
* and `encode`: a year is named by the calendar year its first month falls in.
|
|
119
|
-
*
|
|
120
|
-
*
|
|
117
|
+
* The rule is the package's single definition of a shifted year (`yearKeyOfCivil`), shared with `normalizeDateByUnit`
|
|
118
|
+
* and `encode`: a year is named by the calendar year its first month falls in. The date is read as `normalizeDateByUnit`
|
|
119
|
+
* reads it, by its time value in the system time zone (a plain copy), so the drawn year is the year the validation
|
|
120
|
+
* (`encodeInsideDateRange`) and the memo key (`selectorUnitKey`) judge, a Date subclass whose getters report another zone included.
|
|
121
|
+
* ずらした年の定義はパッケージで 1 つだけ (`yearKeyOfCivil`。`normalizeDateByUnit` / `encode` と同じ規約)。
|
|
122
|
+
* 年は先頭月が属する暦年で名付ける。日付は `normalizeDateByUnit` と同じく時刻値の複製をシステムのタイムゾーンで読むため、描く年は
|
|
123
|
+
* 検証 (`encodeInsideDateRange`) とメモのキー (`selectorUnitKey`) が判定する年と一致する (ゲッターが別のタイムゾーンを名乗る Date の派生クラスも)。
|
|
121
124
|
*
|
|
122
|
-
* @param date - Date to classify / 判定対象の日付
|
|
125
|
+
* @param date - Date to classify, read by its time value / 判定対象の日付 (時刻値で読む)
|
|
123
126
|
* @param yearStartMonth - Calendar month a year starts in, 0-based / 1 年が始まる暦月 (0 始まり)
|
|
124
127
|
* @returns Year number, named by the calendar year its first month falls in / 先頭月が属する暦年で名付けた年番号
|
|
125
128
|
*/
|
|
126
129
|
function yearOf(date: Date, yearStartMonth: number): number {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Resolves the first day of the year a date belongs to when a year starts in the given calendar month.
|
|
132
|
-
* 年の開始月を指定したときに、日付が属する年の初日を解決する関数。
|
|
133
|
-
*
|
|
134
|
-
* @param date - Valid Date to classify / 判定対象の有効な日付
|
|
135
|
-
* @param yearStartMonth - Calendar month a year starts in, 0-based / 1 年が始まる暦月 (0 始まり)
|
|
136
|
-
* @returns First day of that year, or an Invalid Date when it starts outside the Date range / その年の初日 (始まりが表現範囲外なら Invalid Date)
|
|
137
|
-
*/
|
|
138
|
-
function yearStartOf(date: Date, yearStartMonth: number): Date {
|
|
139
|
-
return yearStart(yearOf(date, yearStartMonth), yearStartMonth)
|
|
130
|
+
// 派生クラスのゲッターは別のタイムゾーンの年月を名乗る。検証と同じく複製から読まないと、検証が受け付けた年と別の年を描く
|
|
131
|
+
const plain = new Date(date.getTime())
|
|
132
|
+
return yearKeyOfCivil(plain.getFullYear(), plain.getMonth(), yearStartMonth)
|
|
140
133
|
}
|
|
141
134
|
|
|
142
135
|
/**
|
|
@@ -353,11 +346,12 @@ const YearSelectorComponent = (props: YearSelectorProps): React.JSX.Element => {
|
|
|
353
346
|
const resolvedLabels = useResolvedLabels(locale, labels)
|
|
354
347
|
|
|
355
348
|
const isControlled = value !== undefined
|
|
356
|
-
// 年の区切りは yearStartMonth
|
|
349
|
+
// 年の区切りは yearStartMonth が決めるため、キーは年番号と開始月の対にする。区切りを変えた描画は、同じ initialDate で年番号が変わらなくても
|
|
350
|
+
// キーが変わり、その描画で取り込み直す
|
|
357
351
|
const [year, setYear] = useUncontrolledSelection(
|
|
358
352
|
effectiveDate,
|
|
359
353
|
isControlled,
|
|
360
|
-
(date) =>
|
|
354
|
+
(date) => selectorUnitKey(date, "year", yearStartMonth),
|
|
361
355
|
(date) => yearOf(date, yearStartMonth),
|
|
362
356
|
)
|
|
363
357
|
|
|
@@ -462,10 +456,13 @@ const YearSelectorComponent = (props: YearSelectorProps): React.JSX.Element => {
|
|
|
462
456
|
* Memo comparator of `YearSelector`: true only when every prop its output depends on is unchanged, never for a prop the render rejects.
|
|
463
457
|
* `YearSelector` のメモ比較器 (描画結果が依存する Props がすべて不変のときだけ true。描画が拒否する Props では常に false)。
|
|
464
458
|
*
|
|
465
|
-
* Date props are compared
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
459
|
+
* Date props are compared through `areSelectorDatePropsEqual` by `selectorUnitKey` at unit year under the render's yearStartMonth,
|
|
460
|
+
* the key the validation's own function computes, so an invalid one on a re-render reaches the render-time validation and throws the
|
|
461
|
+
* same named RangeError as on the first mount. The comparator itself never throws: yearStartMonth is compared first, and an invalid
|
|
462
|
+
* one never reaches the key.
|
|
463
|
+
* Date 型 Props は `areSelectorDatePropsEqual` で、今回の描画の yearStartMonth のもとの年の `selectorUnitKey` (検証と同じ関数が求めるキー) により比べるため、
|
|
464
|
+
* 再描画で渡した不正な値も描画時の検証へ届き、初回のマウントと同じく Props 名を名指す RangeError になる。比較器自身は例外を投げない
|
|
465
|
+
* (yearStartMonth を先に比べ、不正な値はキーへ届かない)。
|
|
469
466
|
*
|
|
470
467
|
* @param prev - Props of the previous render / 前回の描画の Props
|
|
471
468
|
* @param next - Props of the next render / 今回の描画の Props
|
|
@@ -476,7 +473,9 @@ export const areYearSelectorPropsEqual = (prev: YearSelectorProps, next: YearSel
|
|
|
476
473
|
// 制御値の変化が「等しい」と判定されて描画ごと捨てられる。比較器は本体と同じ年定義を読む
|
|
477
474
|
const startMonth = yearStartMonthMemoKey(next.yearStartMonth)
|
|
478
475
|
if (yearStartMonthMemoKey(prev.yearStartMonth) !== startMonth) return false
|
|
479
|
-
|
|
476
|
+
// keyInsideDateRange は不正な yearStartMonth で例外を投げる。上の比較は不正な開始月を NaN として必ず不一致にするため、
|
|
477
|
+
// ここへ届くのは有効な開始月だけで、比較器は例外を投げない
|
|
478
|
+
if (!areSelectorDatePropsEqual(prev, next, (date) => selectorUnitKey(date, "year", startMonth))) return false
|
|
480
479
|
if (prev.disabled !== next.disabled) return false
|
|
481
480
|
if (prev.className !== next.className) return false
|
|
482
481
|
if (prev.style !== next.style) return false
|
package/src/optionText.ts
CHANGED
|
@@ -83,16 +83,18 @@ const getPartFormat = (part: PeriodSliderUnit, formatLocale: string): Intl.DateT
|
|
|
83
83
|
* (自然言語既定は汎用パッケージに 1 言語を焼き付け、Intl 出力は ICU 版で揺れるため)。
|
|
84
84
|
*
|
|
85
85
|
* @param part - Calendar part to render / 整形対象の暦要素
|
|
86
|
-
* @param anchor - Date carrying the part value, and the calendar context Intl needs / 対象値を保持し Intl が必要とする暦文脈も与える日付
|
|
86
|
+
* @param anchor - Date carrying the part value, and the calendar context Intl needs; both tiers read it by its time value in the system time zone / 対象値を保持し Intl が必要とする暦文脈も与える日付 (どちらの段も時刻値をシステムのタイムゾーンで読む)
|
|
87
87
|
* @param formatLocale - BCP 47 language tag enabling Intl formatting / Intl 書式を有効化する BCP 47 言語タグ
|
|
88
88
|
* @returns Zero-padded digits, or the Intl rendering when a format locale is supplied / 0 埋め数字 (formatLocale 指定時は Intl 書式)
|
|
89
89
|
*/
|
|
90
90
|
const formatDatePart = (part: PeriodSliderUnit, anchor: Date, formatLocale: string | undefined): string => {
|
|
91
91
|
if (formatLocale !== undefined) return getPartFormat(part, formatLocale).format(anchor)
|
|
92
|
+
// Intl の段は時刻値をシステムのタイムゾーンで読む。派生クラスのゲッターを読むと、formatLocale の有無で別の部位を名乗る
|
|
93
|
+
const plain = new Date(anchor.getTime())
|
|
92
94
|
// 年だけは 0 埋め桁数が固定ではない (0 年以下は ISO 8601 の拡張表記)。ここで桁数を書き直すと
|
|
93
95
|
// 同じ 1 日がウィジェットの中で 2 通りの ISO 表記を持つ
|
|
94
|
-
if (part === "year") return formatIsoYear(PART_READERS.year(
|
|
95
|
-
return String(PART_READERS[part](
|
|
96
|
+
if (part === "year") return formatIsoYear(PART_READERS.year(plain))
|
|
97
|
+
return String(PART_READERS[part](plain)).padStart(ISO_DIGITS_BY_PART[part], "0")
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
/**
|
|
@@ -107,7 +109,7 @@ const formatDatePart = (part: PeriodSliderUnit, anchor: Date, formatLocale: stri
|
|
|
107
109
|
* a public entry point whose arguments can arrive from JavaScript, where no union is enforced.
|
|
108
110
|
* フォーマッタ Props は型検査を受けるが、本関数は公開の入口であり JavaScript からも引数が届くため検証する。
|
|
109
111
|
*
|
|
110
|
-
* @param date - Date to render / 描画対象の日付
|
|
112
|
+
* @param date - Date to render; both built-in tiers read it by its time value in the system time zone / 描画対象の日付 (組み込みのどちらの段も時刻値をシステムのタイムゾーンで読む)
|
|
111
113
|
* @param unit - Precision to name / 名乗る精度
|
|
112
114
|
* @param scope - Scope selecting the built-in option set / 組み込みオプション集合を選ぶ区分
|
|
113
115
|
* @param formatLocale - BCP 47 language tag enabling Intl formatting (the `formatLocale` prop, not the UI chrome `locale`) / Intl 書式を有効化する BCP 47 言語タグ (UI クロームの `locale` ではなく `formatLocale` prop)
|