@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/dist/optionText.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { PeriodOptionScope, PeriodSliderUnit } from './PeriodSlider.js';
|
|
|
11
11
|
* a public entry point whose arguments can arrive from JavaScript, where no union is enforced.
|
|
12
12
|
* フォーマッタ Props は型検査を受けるが、本関数は公開の入口であり JavaScript からも引数が届くため検証する。
|
|
13
13
|
*
|
|
14
|
-
* @param date - Date to render / 描画対象の日付
|
|
14
|
+
* @param date - Date to render; both built-in tiers read it by its time value in the system time zone / 描画対象の日付 (組み込みのどちらの段も時刻値をシステムのタイムゾーンで読む)
|
|
15
15
|
* @param unit - Precision to name / 名乗る精度
|
|
16
16
|
* @param scope - Scope selecting the built-in option set / 組み込みオプション集合を選ぶ区分
|
|
17
17
|
* @param formatLocale - BCP 47 language tag enabling Intl formatting (the `formatLocale` prop, not the UI chrome `locale`) / Intl 書式を有効化する BCP 47 言語タグ (UI クロームの `locale` ではなく `formatLocale` prop)
|
package/dist/optionText.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optionText.d.ts","sourceRoot":"","sources":["../src/optionText.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAsD,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"optionText.d.ts","sourceRoot":"","sources":["../src/optionText.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAsD,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AA8ElI;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,IAAI,EAAE,MAAM,gBAAgB,EAAE,OAAO,iBAAiB,EAAE,eAAe,MAAM,KAAG,MAUtH,CAAA"}
|
package/dist/selectorMemo.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PeriodSliderUnit } from './PeriodSlider.js';
|
|
1
2
|
/**
|
|
2
3
|
* Date-typed props every selector carries.
|
|
3
4
|
* 全セレクタが持つ Date 型 Props。
|
|
@@ -13,39 +14,46 @@ export interface SelectorDateProps {
|
|
|
13
14
|
maxDate?: Date;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
|
-
* Key of a valid Date at a selector's unit: the
|
|
17
|
-
* セレクタの単位での有効な Date のキー (
|
|
17
|
+
* Key of a valid Date at a selector's unit: the integer key of the unit containing it, as the selector's validation reads that unit, paired with the year start.
|
|
18
|
+
* セレクタの単位での有効な Date のキー (セレクタの検証が読むとおりの、その日付を含む単位の整数キーと年の開始月の対)。
|
|
18
19
|
*
|
|
19
|
-
* The
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* The unit key is keyInsideDateRange's, the function encodeInsideDateRange validates the selectors' Date props with, so the key is
|
|
21
|
+
* `NaN` exactly where that validation throws for the date, by construction. yearStartMonth is an integer in [0, 11], so the pair is
|
|
22
|
+
* injective: a render that changes yearStartMonth changes the key even when the year number stays. The memo comparators compare the
|
|
23
|
+
* shown date by this key and the uncontrolled selection adopts `initialDate` exactly when it changes (`useUncontrolledSelection`), so a
|
|
24
|
+
* render a comparator skips is a render that would not adopt.
|
|
25
|
+
* 単位のキーは keyInsideDateRange のもの (encodeInsideDateRange がセレクタの Date 型 Props の検証に使う関数) であり、キーが `NaN` になるのは、
|
|
26
|
+
* その検証がその日付で例外を投げる場合と構成上一致する。yearStartMonth は 0 以上 11 以下の整数であるため対は単射で、yearStartMonth を変えた描画は
|
|
27
|
+
* 年番号が変わらなくてもキーが変わる。メモ比較器は表示する日付をこのキーで比べ、非制御の選択はこのキーが変わったときにだけ `initialDate` を取り込む
|
|
22
28
|
* (`useUncontrolledSelection`)。比較器が省く描画は、取り込みを起こさない描画と一致する。
|
|
23
29
|
*
|
|
24
|
-
* @param date - Date to key /
|
|
25
|
-
* @param
|
|
26
|
-
* @
|
|
30
|
+
* @param date - Valid Date to key / キー化する有効な Date
|
|
31
|
+
* @param unit - Unit the selector draws / セレクタが描く単位
|
|
32
|
+
* @param yearStartMonth - Calendar month a year starts in, 0-based: YearSelector's yearStartMonth, 0 for the other selectors / 1 年が始まる暦月 (0 始まり。YearSelector はその yearStartMonth、他のセレクタは 0)
|
|
33
|
+
* @returns `key * 12 + yearStartMonth` for the key keyInsideDateRange returns, or `NaN` where it returns null (the unit starts outside the Date range) / keyInsideDateRange が返すキーに対する `key * 12 + yearStartMonth` (null を返す日付、つまり単位の始まりが表現範囲の外なら `NaN`)
|
|
34
|
+
* @throws RangeError when date is not a valid Date or yearStartMonth is not an integer in [0, 11] (raised by keyInsideDateRange) / date が有効な Date でない場合、yearStartMonth が 0 以上 11 以下の整数でない場合 (keyInsideDateRange が送出)
|
|
27
35
|
*/
|
|
28
|
-
export declare const selectorUnitKey: (date: Date,
|
|
36
|
+
export declare const selectorUnitKey: (date: Date, unit: PeriodSliderUnit, yearStartMonth: number) => number;
|
|
29
37
|
/**
|
|
30
38
|
* Whether two renders of a selector carry the same Date-typed props at the selector's unit, never judging an unusable one equal.
|
|
31
39
|
* 2 つの描画の Date 型 Props がセレクタの単位で等しいかの判定 (使えない値は等しいとみなさない)。
|
|
32
40
|
*
|
|
33
|
-
* Each prop keys
|
|
34
|
-
* selector's validation
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* 各 Props を `
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
* Each prop keys through `optionalDateMemoKey` with `keyOf`, the selector's `selectorUnitKey` closure, so the key is `NaN` exactly
|
|
42
|
+
* where the selector's validation throws for the prop, by construction: a non-Date, `null`, an Invalid Date, or a date whose unit
|
|
43
|
+
* starts outside the Date range (for `DateSelector variant="split-dropdown"`, also a date whose year does). The shown date (`value`
|
|
44
|
+
* when controlled, `initialDate` otherwise) and both bounds are compared by that key. A controlled render does not draw `initialDate`,
|
|
45
|
+
* so its moves are not compared, but a render that supplies an unusable one is never skipped: the selector validates every Date prop
|
|
46
|
+
* on every render.
|
|
47
|
+
* 各 Props を `keyOf` (セレクタの `selectorUnitKey` のクロージャ) で `optionalDateMemoKey` によりキー化するため、キーが `NaN` になるのは、
|
|
48
|
+
* セレクタの検証がその Props で例外を投げる場合 (Date でない値・`null`・Invalid Date・単位の始まりが表現範囲の外の日付。
|
|
49
|
+
* `DateSelector variant="split-dropdown"` では年の始まりが外の日付も) と構成上一致する。表示する日付 (制御なら `value`、それ以外は `initialDate`) と
|
|
50
|
+
* 両境界をそのキーで比べる。制御中は `initialDate` を描かないため動きは比べないが、使えない値を渡した描画は省かない
|
|
51
|
+
* (セレクタは毎描画ですべての Date 型 Props を検証する)。
|
|
44
52
|
*
|
|
45
53
|
* @param prev - Props of the previous render / 前回の描画の Props
|
|
46
54
|
* @param next - Props of the next render / 今回の描画の Props
|
|
47
|
-
* @param
|
|
55
|
+
* @param keyOf - Unit key of a valid Date: the selector's `selectorUnitKey` closure, the key its uncontrolled selection adopts by / 有効な Date の単位のキー (セレクタの `selectorUnitKey` のクロージャ。非制御の選択が取り込みを決めるキーと同じ)
|
|
48
56
|
* @returns `true` when the Date props allow the next render to be skipped / Date 型 Props に関して今回の描画を省けるなら `true`
|
|
49
57
|
*/
|
|
50
|
-
export declare const areSelectorDatePropsEqual: (prev: SelectorDateProps, next: SelectorDateProps,
|
|
58
|
+
export declare const areSelectorDatePropsEqual: (prev: SelectorDateProps, next: SelectorDateProps, keyOf: (date: Date) => number) => boolean;
|
|
51
59
|
//# sourceMappingURL=selectorMemo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectorMemo.d.ts","sourceRoot":"","sources":["../src/selectorMemo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"selectorMemo.d.ts","sourceRoot":"","sources":["../src/selectorMemo.ts"],"names":[],"mappings":"AAKA,OAAO,EAAsB,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAE1E;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAC9B,8BAA8B;IAC9B,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,2CAA2C;IAC3C,WAAW,CAAC,EAAE,IAAI,CAAA;IAClB,uBAAuB;IACvB,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,uBAAuB;IACvB,OAAO,CAAC,EAAE,IAAI,CAAA;CACjB;AAQD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,IAAI,EAAE,MAAM,gBAAgB,EAAE,gBAAgB,MAAM,KAAG,MAG5F,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,yBAAyB,GAAI,MAAM,iBAAiB,EAAE,MAAM,iBAAiB,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,KAAG,OAO3H,CAAA"}
|
|
@@ -44,26 +44,34 @@ export interface CommittedRef<T> extends React.RefObject<T> {
|
|
|
44
44
|
* A recorded hand-off stops being the state's last queued update in one way that shows in the next render of the hook:
|
|
45
45
|
* a hand-off made during a render (a returned function called from the host's render body) leaves the queue with that
|
|
46
46
|
* render when React throws the render away, and the restarted render holds an older state. The state this render pass
|
|
47
|
-
* holds is then not the recorded object, so the record is dropped and the next equal value is handed over again.
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
47
|
+
* holds is then not the recorded object, so the record is dropped and the next equal value is handed over again. A
|
|
48
|
+
* hook's state is a reducer whose setter has no eager path (useHookState in usePeriodSlider.ts), so the state that
|
|
49
|
+
* discarded render computed is never the base a later hand-off is compared with. The hook's record of its own
|
|
50
|
+
* re-placement clears the record and never leaves it stale.
|
|
51
51
|
* Until the hook renders again the record stands, so an equal call made between React throwing such a render away and
|
|
52
|
-
* the next render of the hook is skipped
|
|
53
|
-
* render
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
52
|
+
* the next render of the hook is skipped. A later render that hands the value over again stores it (the restarted
|
|
53
|
+
* render of a transition that still calls the function); when none does (a transition reverted before it commits), the
|
|
54
|
+
* call draws and notifies nothing. While Suspense keeps a transition held, React renders it again and throws it away
|
|
55
|
+
* after every commit, and the host's render-phase call hands the same value over again: the mirror, this record and the
|
|
56
|
+
* hook's known value keep returning to that value until the transition commits or is reverted, so shifts step from it
|
|
57
|
+
* and a commit-path call with that value is neither drawn nor notified. A render that skips the recorded update because
|
|
58
|
+
* of its lower priority drops the record too, which costs one more hand-off of an equal value, at the caller's priority.
|
|
59
|
+
* A hand-off made while handling an event never leaves the queue before it is applied. The write only ever deletes:
|
|
60
|
+
* made in a render that never commits, it can only add a hand-off, never cause one to be skipped.
|
|
57
61
|
* 記録した受け渡しがステートの最後に積んだ更新でなくなる道は 1 つで、次のフックの描画に現れる。描画の中で行った受け渡し (ホストの描画本体から
|
|
58
62
|
* 呼んだ返す関数) は、React がその描画を捨てると描画とともにキューから消え、やり直す描画は古いステートを持つ。このときこの描画が持つステートは
|
|
59
|
-
*
|
|
60
|
-
*
|
|
63
|
+
* 記録したオブジェクトではないため、記録を消し、次の同じ値はもう一度渡す。フックのステートは即時の経路を持たない設定関数のリデューサー
|
|
64
|
+
* (usePeriodSlider.ts の useHookState) のため、捨てた描画が求めたステートが後の受け渡しの比較の基準になることはない。
|
|
61
65
|
* フック自身の収め直しの記録は記録を消すため、記録を古くしない。次にフックを描くまでは記録が残るため、React がそうした描画を捨ててから
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
66
|
+
* 次にフックを描くまでの同じ値の呼び出しは省かれる。値を保存するのは、それをもう一度渡す後の描画 (まだ関数を呼ぶ移行のやり直し) だけで、
|
|
67
|
+
* 渡す描画が無ければ (確定する前に取り消した移行)、その呼び出しは何も描かず、何も通知しない。Suspense が移行を保留している間は、
|
|
68
|
+
* React が確定のたびにその移行を描き直して捨て、ホストの描画中の呼び出しが同じ値を渡し直すため、写し・この記録・フックの知っている値は、
|
|
69
|
+
* その移行が確定するか取り消されるまでその値に戻り続ける (シフトはそこから進み、その値と同じ確定経路の呼び出しは描かれず、通知もされない)。
|
|
70
|
+
* 記録した更新を優先度が低いために飛ばした描画も記録を消すが、同じ値の受け渡しが呼び出し側の優先度で 1 度増えるだけである。
|
|
71
|
+
* 事象の処理中に行った受け渡しは、当てられる前にキューから消えることがない。この書き込みは消すだけで、確定しない描画で行っても
|
|
72
|
+
* 受け渡しが増えるだけであり、省く判断は生まない。
|
|
65
73
|
*
|
|
66
|
-
* @param state - The state object this render pass holds (the
|
|
74
|
+
* @param state - The state object this render pass holds (the useHookState value, before the render derives the re-placed value) / この描画が持つステートのオブジェクト (描画が収め直した値を導く前の useHookState の値)
|
|
67
75
|
* @returns Nothing / なし
|
|
68
76
|
*/
|
|
69
77
|
forgetHandedUnless(state: T): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCommittedRef.d.ts","sourceRoot":"","sources":["../src/useCommittedRef.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IACvD;;;;;;OAMG;IACH,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IAEpB;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;IAE7B;;;;;;;;;OASG;IACH,YAAY,IAAI,IAAI,CAAA;IAEpB
|
|
1
|
+
{"version":3,"file":"useCommittedRef.d.ts","sourceRoot":"","sources":["../src/useCommittedRef.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IACvD;;;;;;OAMG;IACH,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IAEpB;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;IAE7B;;;;;;;;;OASG;IACH,YAAY,IAAI,IAAI,CAAA;IAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,kBAAkB,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;CACrC;AAoHD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAS5D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePeriodSlider.d.ts","sourceRoot":"","sources":["../src/usePeriodSlider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC9E,OAAO,EAIH,KAAK,4BAA4B,EAQjC,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,6BAA6B,EAClC,KAAK,6BAA6B,EAQrC,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAiD,KAAK,eAAe,EAAE,KAAK,iBAAiB,EAAgD,KAAK,oBAAoB,EAAE,KAAK,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"usePeriodSlider.d.ts","sourceRoot":"","sources":["../src/usePeriodSlider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC9E,OAAO,EAIH,KAAK,4BAA4B,EAQjC,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,6BAA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,EAAE,IAAI,KAAK,IAAI,CAAA;IACvC,kRAAkR;IAClR,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;IAClC,ghBAAghB;IAChhB,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACxC,ugBAAugB;IACvgB,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACxC,oEAAoE;IACpE,YAAY,EAAE,MAAM,IAAI,CAAA;IACxB,wEAAwE;IACxE,uBAAuB,EAAE,aAAa,CAAA;IACtC,sEAAsE;IACtE,qBAAqB,EAAE,aAAa,CAAA;IACpC,iIAAiI;IACjI,kBAAkB,EAAE,aAAa,CAAA;IACjC,iGAAiG;IACjG,WAAW,EAAE,6BAA6B,CAAA;CAC7C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,4BAA4B,GAAG,2BAA2B,CAiaxG"}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Uncontrolled selection of a selector: adopts `initialDate` in the render that turns the selector uncontrolled or moves `initialDate` to another unit, and otherwise keeps the held value, the user's latest choice included.
|
|
3
3
|
* セレクタの非制御の選択 (非制御になった描画と `initialDate` が別の単位へ動いた描画で `initialDate` を取り込み、それ以外は利用者の最後の選択を含む保持値を持ち越す)。
|
|
4
4
|
*
|
|
5
|
-
* The unit key is `
|
|
6
|
-
* render the comparator skips is one that would not adopt, and a move within the unit keeps the
|
|
7
|
-
* render is skipped. The mount seeds the state. A later adoption, and the `null` source a controlled render stands for, is derived
|
|
5
|
+
* The unit key is `keyOf(shownDate)`, the key the selector's memo comparator compares the shown date by (the selector's
|
|
6
|
+
* `selectorUnitKey` closure), so a render the comparator skips is one that would not adopt, and a move within the unit keeps the
|
|
7
|
+
* user's choice whether or not the render is skipped. The mount seeds the state. A later adoption, and the `null` source a controlled render stands for, is derived
|
|
8
8
|
* by the render (drawSelection), so the adopting render draws the adopted value from its first commit. It is recorded from a layout
|
|
9
9
|
* effect of the commit that drew it, so that update takes a second commit, which draws the same value. No render writes the state.
|
|
10
10
|
* React keeps the state every render computes in the hook queue, including a render it discards or leaves suspended (a transition
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* effect and record nothing: the record runs when the tree is shown, from that render's props, so an adoption or a controlled
|
|
18
18
|
* interlude undone while hidden leaves the held selection, pick included. The returned setter records a choice through an
|
|
19
19
|
* updater; it is computed from committed state because no render writes this state and every record lands inside its own commit.
|
|
20
|
-
* 単位のキーは `
|
|
20
|
+
* 単位のキーは `keyOf(shownDate)` で、セレクタのメモ比較器が表示する日付を比べるキー (セレクタの `selectorUnitKey` のクロージャ) と同じ。このため比較器が省く描画は
|
|
21
21
|
* 取り込みを起こさない描画であり、単位の中の移動は、描画が省かれても省かれなくても利用者の選択を残す。マウントは状態の初期化で取り込む。
|
|
22
22
|
* それ以降の取り込みと、制御の描画が表す `null` の出どころは描画が導き (drawSelection)、取り込む描画はその最初の確定から取り込んだ値を描く。
|
|
23
23
|
* 記録はそれを描いた確定のレイアウト副作用で行い、その更新は同じ値を描く 2 回目の確定を伴う。どの描画もステートを書かない。React はフックの
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
* (利用者の選択を含む) を残す。返す設定関数は更新関数で選択を記録し、どの描画もこのステートを書かず、記録は自分の確定の中で済むため、
|
|
31
31
|
* 確定したステートから計算される。
|
|
32
32
|
*
|
|
33
|
-
* @param shownDate - Date the render shows (`value` when controlled, `initialDate` otherwise), validated by the selector before its first hook so
|
|
33
|
+
* @param shownDate - Date the render shows (`value` when controlled, `initialDate` otherwise), validated by the selector before its first hook, so its key is never `NaN` (a `NaN` key would never equal itself) / 描画が示す日付 (制御なら `value`、それ以外は `initialDate`)。セレクタが最初のフックより前に検証済みのため、そのキーは `NaN` にならない (`NaN` のキーは自身と等しくならないため)
|
|
34
34
|
* @param isControlled - Whether the render is controlled (`value !== undefined`) / 制御の描画か (`value !== undefined`)
|
|
35
|
-
* @param
|
|
35
|
+
* @param keyOf - Unit key of a date: the selector's `selectorUnitKey` closure, the key its memo comparator compares the shown date by / 日付の単位のキー (セレクタの `selectorUnitKey` のクロージャ。メモ比較器が表示する日付を比べるキーと同じ)
|
|
36
36
|
* @param adopt - Held value adopted from a date / 日付から取り込む保持値
|
|
37
37
|
* @returns The held value the render draws when uncontrolled, and the setter recording the user's choice / 非制御の描画が描く保持値と、利用者の選択を記録する更新関数
|
|
38
38
|
*/
|
|
39
|
-
export declare function useUncontrolledSelection<T>(shownDate: Date, isControlled: boolean,
|
|
39
|
+
export declare function useUncontrolledSelection<T>(shownDate: Date, isControlled: boolean, keyOf: (date: Date) => number, adopt: (date: Date) => T): readonly [T, (choice: T) => void];
|
|
40
40
|
//# sourceMappingURL=useUncontrolledSelection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUncontrolledSelection.d.ts","sourceRoot":"","sources":["../src/useUncontrolledSelection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUncontrolledSelection.d.ts","sourceRoot":"","sources":["../src/useUncontrolledSelection.ts"],"names":[],"mappings":"AAiCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC,CAU9K"}
|
package/package.json
CHANGED
package/src/DateSelector.tsx
CHANGED
|
@@ -48,9 +48,9 @@ import {
|
|
|
48
48
|
import { assertCandidateListInput, dateMemoKey, describeValue, isValidDate } from "./inputValue"
|
|
49
49
|
import { areLabelOverridesEqual, type PeriodSliderLabelOverrides, type PeriodSliderLocale } from "./labels"
|
|
50
50
|
import { formatOptionText } from "./optionText"
|
|
51
|
-
import { assertLocaleTag, encodeInsideDateRange, formatLabel, type PeriodOptionFormatter, type PeriodSliderUnit, sentinelBoundRemedy } from "./PeriodSlider"
|
|
51
|
+
import { assertLocaleTag, encodeInsideDateRange, formatLabel, keyInsideDateRange, type PeriodOptionFormatter, type PeriodSliderUnit, sentinelBoundRemedy } from "./PeriodSlider"
|
|
52
52
|
import { STEPPER_ROW_GAP_CLASS, StepperButton } from "./StepperButton"
|
|
53
|
-
import { areSelectorDatePropsEqual } from "./selectorMemo"
|
|
53
|
+
import { areSelectorDatePropsEqual, selectorUnitKey } from "./selectorMemo"
|
|
54
54
|
import { assertSelectorStepper, type SelectorStepper } from "./selectorStep"
|
|
55
55
|
import { useResolvedLabels } from "./useResolvedLabels"
|
|
56
56
|
import { useUncontrolledSelection } from "./useUncontrolledSelection"
|
|
@@ -263,14 +263,37 @@ const namesLocalDay = (date: Date, year: number, month: number, day: number): bo
|
|
|
263
263
|
* -271821 年 1 月 1 日はどのタイムゾーンでも表現範囲の外 (範囲は同年 4 月 20 日 UTC から) で、同年 1〜4 月の 1 日も外。年の始まりが範囲に入れば、
|
|
264
264
|
* 1 月からその日付の月までの各 1 日も入る (1 月 1 日と、始まりの表現を既に要求している日との間にあるため)。その日付より後の月は `listPartOptions` が区切る。
|
|
265
265
|
*
|
|
266
|
+
* The predicate is keyInsideDateRange's at unit year under the calendar year, the function encodeInsideDateRange validates with, and
|
|
267
|
+
* `assertSplitYearProp`, the held-selection check and the split-dropdown memo key (`splitDropdownDayKey`) all read it, so they reject
|
|
268
|
+
* exactly the same dates. keyInsideDateRange reads a date by its time value in the system time zone (`normalizeDateByUnit` reads a
|
|
269
|
+
* plain copy at every unit), so the raw prop, its day start (`toStartOfDay`, which the held-selection check reads) and the drawn year
|
|
270
|
+
* (`activeDate.getFullYear()`) name the same year, a Date subclass whose getters report another zone included.
|
|
271
|
+
* 判定は暦年のもとの年の単位の keyInsideDateRange (encodeInsideDateRange が検証に使う関数) であり、`assertSplitYearProp`・保持中の選択の検査・
|
|
272
|
+
* 分割セレクトのメモのキー (`splitDropdownDayKey`) がどれもこれを読むため、拒む日付はちょうど一致する。keyInsideDateRange は日付を時刻値の
|
|
273
|
+
* システムのタイムゾーンで読む (`normalizeDateByUnit` はどの単位も素の複製を読む) ため、Props そのもの・その日の始まり (`toStartOfDay`。
|
|
274
|
+
* 保持中の選択の検査が読む)・描く年 (`activeDate.getFullYear()`) は同じ年を名乗る (ゲッターが別のタイムゾーンを名乗る Date の派生クラスも)。
|
|
275
|
+
*
|
|
266
276
|
* @param date - Valid Date; the render passes one whose day already starts inside the Date range, the memo comparator any valid Date / 有効な Date (描画はその日の始まりが表現範囲に入ると検証済みのものを、メモ比較器は任意の有効な Date を渡す)
|
|
267
|
-
* @returns True when January 1 of its
|
|
277
|
+
* @returns True when January 1 of its year starts inside the Date range / その年の 1 月 1 日の始まりが表現範囲に入れば true
|
|
278
|
+
* @throws RangeError when date is not a valid Date (raised by keyInsideDateRange); every caller passes a valid one / date が有効な Date でない場合 (keyInsideDateRange が送出)。呼び出し側はどれも有効な Date を渡す
|
|
279
|
+
*/
|
|
280
|
+
const yearStartsInsideDateRange = (date: Date): boolean => keyInsideDateRange(date, "year", 0) !== null
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Unit key of a valid Date for this selector: the `selectorUnitKey` of the day the validation reads.
|
|
284
|
+
* 本セレクタでの有効な Date の単位のキー (検証が読む日の `selectorUnitKey`)。
|
|
285
|
+
*
|
|
286
|
+
* The memo comparator and the uncontrolled selection share it, so a render the comparator skips is one that would not adopt.
|
|
287
|
+
* メモ比較器と非制御の選択が共有するため、比較器が省く描画は取り込みを起こさない描画と一致する。
|
|
288
|
+
*
|
|
289
|
+
* @param date - Valid Date / 有効な Date
|
|
290
|
+
* @returns `selectorUnitKey` at unit day, or `NaN` when the day starts outside the Date range / 日の単位の `selectorUnitKey` (日の始まりが表現範囲外なら `NaN`)
|
|
268
291
|
*/
|
|
269
|
-
const
|
|
292
|
+
const dayKey = (date: Date): number => selectorUnitKey(date, "day", 0)
|
|
270
293
|
|
|
271
294
|
/**
|
|
272
|
-
*
|
|
273
|
-
* `variant="split-dropdown"` の検証どおりの、有効な Date
|
|
295
|
+
* Unit key of a valid Date as `variant="split-dropdown"` validates it: `dayKey`, or `NaN` when the date's year does not start inside the Date range.
|
|
296
|
+
* `variant="split-dropdown"` の検証どおりの、有効な Date の単位のキー (`dayKey`。その年の始まりが Date の表現範囲に入らなければ `NaN`)。
|
|
274
297
|
*
|
|
275
298
|
* The memo comparator keys the Date props of a split-dropdown render by it, so a key is `NaN` exactly where `assertSplitYearProp`
|
|
276
299
|
* (the same predicate) or the day-start check rejects the prop, and a render that rejects one is never skipped.
|
|
@@ -278,9 +301,9 @@ const yearStartsInsideDateRange = (date: Date): boolean => !Number.isNaN(startOf
|
|
|
278
301
|
* 日の始まりの検査がその Props を拒む場合とちょうど一致し、拒む描画は省かれない。
|
|
279
302
|
*
|
|
280
303
|
* @param date - Valid Date / 有効な Date
|
|
281
|
-
* @returns
|
|
304
|
+
* @returns `dayKey(date)`, or `NaN` when its year or its day starts outside the Date range / `dayKey(date)` (年か日の始まりが表現範囲の外なら `NaN`)
|
|
282
305
|
*/
|
|
283
|
-
const
|
|
306
|
+
const splitDropdownDayKey = (date: Date): number => (yearStartsInsideDateRange(date) ? dayKey(date) : Number.NaN)
|
|
284
307
|
|
|
285
308
|
/**
|
|
286
309
|
* Asserts that a Date prop of `variant="split-dropdown"` falls in a year whose January 1 starts inside the Date range, failing fast otherwise.
|
|
@@ -291,6 +314,8 @@ const splitDropdownDayStart = (date: Date): Date => (yearStartsInsideDateRange(d
|
|
|
291
314
|
* handed to `formatOption`). `variant="date"` and `"dropdown"` draw only days and keep accepting such a date.
|
|
292
315
|
* `YearSelector` が年の始まりを表現できない日付を拒むのと同じく、ここで prop 名を名指して拒否する (拒まなければ、その年の年と月の部位が名指す日付の無い
|
|
293
316
|
* 選択肢になり、テキストは空、`formatOption` には Invalid Date が届く)。日しか描かない `variant="date"` / `"dropdown"` は引き続き受け付ける。
|
|
317
|
+
* The year test is `yearStartsInsideDateRange`, the predicate the split-dropdown memo key (`splitDropdownDayKey`) reads.
|
|
318
|
+
* 年の判定は `yearStartsInsideDateRange` で、分割セレクトのメモのキー (`splitDropdownDayKey`) が読む述語と同じ。
|
|
294
319
|
*
|
|
295
320
|
* @param propName - Prop name reported in the error message / エラーメッセージに載せるプロパティ名
|
|
296
321
|
* @param date - Date already accepted by `assertValidDateProp` / `assertValidDateProp` を通過した日付
|
|
@@ -409,8 +434,8 @@ const DateSelectorComponent = (props: DateSelectorProps): React.JSX.Element => {
|
|
|
409
434
|
const resolvedLabels = useResolvedLabels(locale, labels)
|
|
410
435
|
|
|
411
436
|
const isControlled = value !== undefined
|
|
412
|
-
// 分割セレクトの比較器が読む
|
|
413
|
-
const [currentDate, setCurrentDate] = useUncontrolledSelection(effectiveDate, isControlled,
|
|
437
|
+
// 分割セレクトの比較器が読む splitDropdownDayKey は、最初のフックより前の検証が拒む日付でだけ dayKey と異なるため、取り込みのキーはどの変種でも dayKey で足りる
|
|
438
|
+
const [currentDate, setCurrentDate] = useUncontrolledSelection(effectiveDate, isControlled, dayKey, toStartOfDay)
|
|
414
439
|
const valueTime = value?.getTime()
|
|
415
440
|
const activeDate = useMemo(() => (value !== undefined ? toStartOfDay(value) : currentDate), [valueTime, currentDate])
|
|
416
441
|
// 非制御の選択は、非制御になった描画と initialDate が別の日へ動いた描画でこの描画のうちに取り込み、それ以外は利用者の選択を
|
|
@@ -723,13 +748,13 @@ const DateSelectorComponent = (props: DateSelectorProps): React.JSX.Element => {
|
|
|
723
748
|
* Memo comparator of `DateSelector`: true only when every prop its output depends on is unchanged, never for a prop the render rejects.
|
|
724
749
|
* `DateSelector` のメモ比較器 (描画結果が依存する Props がすべて不変のときだけ true。描画が拒否する Props では常に false)。
|
|
725
750
|
*
|
|
726
|
-
* Date props are compared by the day
|
|
727
|
-
* render-time validation and throws the same named RangeError as on the first mount; the comparator itself never
|
|
728
|
-
* next render is `variant="split-dropdown"`, a date whose year starts outside the Date range keys to `NaN`
|
|
729
|
-
* so the render that rejects it is not skipped either, including a controlled `initialDate` moved into such a year.
|
|
730
|
-
* Date 型 Props は `areSelectorDatePropsEqual`
|
|
751
|
+
* Date props are compared through `areSelectorDatePropsEqual` by `dayKey`, the day the validation reads, so an invalid one on a
|
|
752
|
+
* re-render reaches the render-time validation and throws the same named RangeError as on the first mount; the comparator itself never
|
|
753
|
+
* throws. When the next render is `variant="split-dropdown"`, a date whose year starts outside the Date range keys to `NaN`
|
|
754
|
+
* (`splitDropdownDayKey`), so the render that rejects it is not skipped either, including a controlled `initialDate` moved into such a year.
|
|
755
|
+
* Date 型 Props は `areSelectorDatePropsEqual` で `dayKey` (検証が読む日) により比べるため、再描画で渡した不正な値も描画時の検証へ届き、
|
|
731
756
|
* 初回のマウントと同じく Props 名を名指す RangeError になる (比較器自身は例外を投げない)。今回の描画が `variant="split-dropdown"` なら、
|
|
732
|
-
* 年の始まりが表現範囲の外にある日付のキーは `NaN` になり (`
|
|
757
|
+
* 年の始まりが表現範囲の外にある日付のキーは `NaN` になり (`splitDropdownDayKey`)、制御中の `initialDate` をその年へ動かした描画も含め、
|
|
733
758
|
* それを拒む描画も省かない。
|
|
734
759
|
*
|
|
735
760
|
* @param prev - Props of the previous render / 前回の描画の Props
|
|
@@ -739,7 +764,7 @@ const DateSelectorComponent = (props: DateSelectorProps): React.JSX.Element => {
|
|
|
739
764
|
export const areDateSelectorPropsEqual = (prev: DateSelectorProps, next: DateSelectorProps): boolean => {
|
|
740
765
|
// 分割セレクトは日付の年の始まりも検証するため、その検査が拒む日付をキーでも NaN にする。variant が変わる描画は下の比較が必ず選ぶので、
|
|
741
766
|
// 今回の描画の variant で読めば足りる
|
|
742
|
-
if (!areSelectorDatePropsEqual(prev, next, next.variant === "split-dropdown" ?
|
|
767
|
+
if (!areSelectorDatePropsEqual(prev, next, next.variant === "split-dropdown" ? splitDropdownDayKey : dayKey)) return false
|
|
743
768
|
if (prev.variant !== next.variant) return false
|
|
744
769
|
if (prev.disabled !== next.disabled) return false
|
|
745
770
|
if (prev.className !== next.className) return false
|
|
@@ -770,11 +795,11 @@ export const areDateSelectorPropsEqual = (prev: DateSelectorProps, next: DateSel
|
|
|
770
795
|
* `allowedDates` is compared by reference, so consumers memoize the array; `stepper` is compared field by field, and a render that adds or
|
|
771
796
|
* removes it, or that switches between controlled and uncontrolled, is never skipped (the stepper has to be validated, and the
|
|
772
797
|
* component has to change which owner it renders).
|
|
773
|
-
* Date props go through `areSelectorDatePropsEqual
|
|
774
|
-
* and so does a date `variant="split-dropdown"` rejects for its year.
|
|
798
|
+
* Date props go through `areSelectorDatePropsEqual` by the key the validation's own function computes, so an invalid one on a re-render
|
|
799
|
+
* throws the same named RangeError as on the first mount, and so does a date `variant="split-dropdown"` rejects for its year.
|
|
775
800
|
* 描画結果が依存する Props の変化時のみ再描画する日単位セレクタ。`allowedDates` は参照比較のため利用側でメモ化、`stepper` はフィールドごとに比較し、
|
|
776
801
|
* 付け外しと、制御・非制御の切り替えは描画を省かない (引き受けを検証し、描く持ち主を切り替えるため)。
|
|
777
|
-
* Date 型 Props は `areSelectorDatePropsEqual`
|
|
802
|
+
* Date 型 Props は `areSelectorDatePropsEqual` で検証と同じ関数が求めるキーにより比べるため、再描画で渡した不正な値も、`variant="split-dropdown"` が年で拒む日付も、
|
|
778
803
|
* 初回のマウントと同じ名指しの RangeError になる。
|
|
779
804
|
*/
|
|
780
805
|
export const DateSelector = memo(DateSelectorComponent, areDateSelectorPropsEqual)
|
package/src/MonthSelector.tsx
CHANGED
|
@@ -25,9 +25,9 @@ import type React from "react"
|
|
|
25
25
|
import { memo, useMemo } from "react"
|
|
26
26
|
import { assertCandidateListInput, describeValue, isValidDate } from "./inputValue"
|
|
27
27
|
import { areLabelOverridesEqual, type PeriodSliderLabelOverrides, type PeriodSliderLocale } from "./labels"
|
|
28
|
-
import { assertLocaleTag, encodeInsideDateRange, formatIsoYear, formatLabel, type PeriodOptionFormatter, sentinelBoundRemedy } from "./PeriodSlider"
|
|
28
|
+
import { assertLocaleTag, decode, encodeInsideDateRange, formatIsoYear, formatLabel, keyInsideDateRange, type PeriodOptionFormatter, sentinelBoundRemedy } from "./PeriodSlider"
|
|
29
29
|
import { STEPPER_ROW_GAP_CLASS, StepperButton } from "./StepperButton"
|
|
30
|
-
import { areSelectorDatePropsEqual } from "./selectorMemo"
|
|
30
|
+
import { areSelectorDatePropsEqual, selectorUnitKey } from "./selectorMemo"
|
|
31
31
|
import { assertSelectorStepper, type SelectorStepper } from "./selectorStep"
|
|
32
32
|
import { useResolvedLabels } from "./useResolvedLabels"
|
|
33
33
|
import { useUncontrolledSelection } from "./useUncontrolledSelection"
|
|
@@ -113,16 +113,37 @@ function monthStart(year: number, monthIndex: number): Date {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
|
-
* Resolves the first day of the month a date falls in.
|
|
117
|
-
*
|
|
116
|
+
* Resolves the first day of the month a date falls in, as the selector's validation reads that month: the month of the date's time value in the system time zone.
|
|
117
|
+
* セレクタの検証が読むとおりの、日付が属する月の初日を解決する関数 (日付の時刻値のシステムのタイムゾーンでの月)。
|
|
118
|
+
*
|
|
119
|
+
* The month is keyInsideDateRange's at unit month, the function encodeInsideDateRange validates every Date prop with, so the drawn
|
|
120
|
+
* month, both bounds, the allowedMonths entries, the memo comparator and the uncontrolled selection read the month the validation
|
|
121
|
+
* judged. A Date whose own getters report another time zone (a Date subclass such as a `TZDate` of `@date-fns/tz`) is read by its
|
|
122
|
+
* time value as well.
|
|
123
|
+
* 月は keyInsideDateRange の月 (encodeInsideDateRange がすべての Date 型 Props の検証に使う関数) であり、描く月・両境界・allowedMonths の要素・
|
|
124
|
+
* メモ比較器・非制御の選択は、検証が判定した月を読む。自身のゲッターが別のタイムゾーンを名乗る Date (`@date-fns/tz` の `TZDate` のような Date の派生クラス)
|
|
125
|
+
* も時刻値で読む。
|
|
118
126
|
*
|
|
119
127
|
* @param date - Valid Date / 有効な日付
|
|
120
|
-
* @returns First
|
|
128
|
+
* @returns First instant of that month's first day (the decode of its key), or an Invalid Date when the month starts outside the Date range / その月の初日の最初の時刻 (キーの decode。月の始まりが表現範囲外なら Invalid Date)
|
|
121
129
|
*/
|
|
122
130
|
function monthStartOf(date: Date): Date {
|
|
123
|
-
|
|
131
|
+
const key = keyInsideDateRange(date, "month", 0)
|
|
132
|
+
return decode("month", key === null ? Number.NaN : key, 0)
|
|
124
133
|
}
|
|
125
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Unit key of a valid Date for this selector: the `selectorUnitKey` of the month the validation reads.
|
|
137
|
+
* 本セレクタでの有効な Date の単位のキー (検証が読む月の `selectorUnitKey`)。
|
|
138
|
+
*
|
|
139
|
+
* The memo comparator and the uncontrolled selection share it, so a render the comparator skips is one that would not adopt.
|
|
140
|
+
* メモ比較器と非制御の選択が共有するため、比較器が省く描画は取り込みを起こさない描画と一致する。
|
|
141
|
+
*
|
|
142
|
+
* @param date - Valid Date / 有効な日付
|
|
143
|
+
* @returns `selectorUnitKey` at unit month, or `NaN` when the month starts outside the Date range / 月の単位の `selectorUnitKey` (月の始まりが表現範囲外なら `NaN`)
|
|
144
|
+
*/
|
|
145
|
+
const monthKey = (date: Date): number => selectorUnitKey(date, "month", 0)
|
|
146
|
+
|
|
126
147
|
/**
|
|
127
148
|
* Format a date as the yyyy-MM string used by the input, the select and the option list.
|
|
128
149
|
* input / select / 選択肢で共用する yyyy-MM 文字列への整形。
|
|
@@ -215,12 +236,12 @@ function assertValidYearProp(year: number | undefined, propName: string, boundar
|
|
|
215
236
|
* `minYear` と `minDate` の双方を満たす最も厳しい下限月の解決。
|
|
216
237
|
*
|
|
217
238
|
* @param minYear - Lower bound year / 下限年
|
|
218
|
-
* @param minDate - Lower bound date /
|
|
239
|
+
* @param minDate - Lower bound date, already validated, read by the month the validation judged (`monthStartOf`) / 検証済みの下限日付 (検証が判定した月で読む。`monthStartOf`)
|
|
219
240
|
* @returns First day of the strictest lower month, or null when neither is declared / 最も厳しい下限月の 1 日。いずれも未宣言なら null
|
|
220
241
|
*/
|
|
221
242
|
function resolveLowerBound(minYear: number | undefined, minDate: Date | undefined): Date | null {
|
|
222
243
|
const fromYear = minYear === undefined ? null : monthStart(minYear, 0)
|
|
223
|
-
const fromDate = minDate === undefined ? null :
|
|
244
|
+
const fromDate = minDate === undefined ? null : monthStartOf(minDate)
|
|
224
245
|
if (fromYear !== null && fromDate !== null) return fromYear >= fromDate ? fromYear : fromDate
|
|
225
246
|
if (fromYear !== null) return fromYear
|
|
226
247
|
return fromDate
|
|
@@ -231,12 +252,12 @@ function resolveLowerBound(minYear: number | undefined, minDate: Date | undefine
|
|
|
231
252
|
* `maxYear` と `maxDate` の双方を満たす最も厳しい上限月の解決。
|
|
232
253
|
*
|
|
233
254
|
* @param maxYear - Upper bound year / 上限年
|
|
234
|
-
* @param maxDate - Upper bound date /
|
|
255
|
+
* @param maxDate - Upper bound date, already validated, read by the month the validation judged (`monthStartOf`) / 検証済みの上限日付 (検証が判定した月で読む。`monthStartOf`)
|
|
235
256
|
* @returns First day of the strictest upper month, or null when neither is declared / 最も厳しい上限月の 1 日。いずれも未宣言なら null
|
|
236
257
|
*/
|
|
237
258
|
function resolveUpperBound(maxYear: number | undefined, maxDate: Date | undefined): Date | null {
|
|
238
259
|
const fromYear = maxYear === undefined ? null : monthStart(maxYear, 11)
|
|
239
|
-
const fromDate = maxDate === undefined ? null :
|
|
260
|
+
const fromDate = maxDate === undefined ? null : monthStartOf(maxDate)
|
|
240
261
|
if (fromYear !== null && fromDate !== null) return fromYear <= fromDate ? fromYear : fromDate
|
|
241
262
|
if (fromYear !== null) return fromYear
|
|
242
263
|
return fromDate
|
|
@@ -287,7 +308,7 @@ function representableMonthOrNull(month: Date): Date | null {
|
|
|
287
308
|
* the resolved bounds and sort the rest ascending.
|
|
288
309
|
* 離散月配列を月初へ正規化・重複排除し、解決済み境界の外の要素を除外して昇順に並べる関数。
|
|
289
310
|
*
|
|
290
|
-
* @param allowedMonths - Caller supplied months, already validated,
|
|
311
|
+
* @param allowedMonths - Caller supplied months, already validated, each read by the month the validation judged (`monthStartOf`; the day part is ignored) / 検証済みの呼び出し側指定月 (各要素を検証が判定した月で読む。`monthStartOf`。日は無視)
|
|
291
312
|
* @param minBound - Resolved lower bound month, or null when unbounded / 解決済み下限月 (無制限時は null)
|
|
292
313
|
* @param maxBound - Resolved upper bound month, or null when unbounded / 解決済み上限月 (無制限時は null)
|
|
293
314
|
* @returns Ascending, deduplicated first-of-month dates inside the bounds (possibly empty) / 境界内の昇順・重複排除済み月初日付 (空の場合あり)
|
|
@@ -295,7 +316,7 @@ function representableMonthOrNull(month: Date): Date | null {
|
|
|
295
316
|
function resolveSelectableMonths(allowedMonths: Date[], minBound: Date | null, maxBound: Date | null): Date[] {
|
|
296
317
|
const byTime = new Map<number, Date>()
|
|
297
318
|
for (const entry of allowedMonths) {
|
|
298
|
-
const normalized =
|
|
319
|
+
const normalized = monthStartOf(entry)
|
|
299
320
|
if (minBound !== null && normalized < minBound) continue
|
|
300
321
|
if (maxBound !== null && normalized > maxBound) continue
|
|
301
322
|
if (!byTime.has(normalized.getTime())) byTime.set(normalized.getTime(), normalized)
|
|
@@ -384,8 +405,8 @@ const MonthSelectorComponent = (props: MonthSelectorProps): React.JSX.Element =>
|
|
|
384
405
|
const resolvedLabels = useResolvedLabels(locale, labels)
|
|
385
406
|
|
|
386
407
|
const isControlled = value !== undefined
|
|
387
|
-
const [currentDate, setCurrentDate] = useUncontrolledSelection(effectiveDate, isControlled,
|
|
388
|
-
const activeDate = useMemo(() => (value !== undefined ?
|
|
408
|
+
const [currentDate, setCurrentDate] = useUncontrolledSelection(effectiveDate, isControlled, monthKey, monthStartOf)
|
|
409
|
+
const activeDate = useMemo(() => (value !== undefined ? monthStartOf(value) : currentDate), [value?.getTime(), currentDate])
|
|
389
410
|
|
|
390
411
|
const minTime = minDate?.getTime()
|
|
391
412
|
const maxTime = maxDate?.getTime()
|
|
@@ -551,17 +572,18 @@ const MonthSelectorComponent = (props: MonthSelectorProps): React.JSX.Element =>
|
|
|
551
572
|
* Memo comparator of `MonthSelector`: true only when every prop its output depends on is unchanged, never for a prop the render rejects.
|
|
552
573
|
* `MonthSelector` のメモ比較器 (描画結果が依存する Props がすべて不変のときだけ true。描画が拒否する Props では常に false)。
|
|
553
574
|
*
|
|
554
|
-
* Date props are compared
|
|
555
|
-
* render-time validation and throws the same named RangeError as on the first mount
|
|
556
|
-
*
|
|
557
|
-
*
|
|
575
|
+
* Date props are compared through `areSelectorDatePropsEqual` by `monthKey`, the month the validation and the render read, so an
|
|
576
|
+
* invalid one on a re-render reaches the render-time validation and throws the same named RangeError as on the first mount, and a
|
|
577
|
+
* skipped render draws the month a fresh mount would; the comparator itself never throws.
|
|
578
|
+
* Date 型 Props は `areSelectorDatePropsEqual` で `monthKey` (検証と描画が読む月) により比べるため、再描画で渡した不正な値も描画時の検証へ届き、
|
|
579
|
+
* 初回のマウントと同じく Props 名を名指す RangeError になり、省いた描画は新規のマウントと同じ月を描く (比較器自身は例外を投げない)。
|
|
558
580
|
*
|
|
559
581
|
* @param prev - Props of the previous render / 前回の描画の Props
|
|
560
582
|
* @param next - Props of the next render / 今回の描画の Props
|
|
561
583
|
* @returns True when the next render may be skipped / 今回の描画を省けるなら true
|
|
562
584
|
*/
|
|
563
585
|
export const areMonthSelectorPropsEqual = (prev: MonthSelectorProps, next: MonthSelectorProps): boolean => {
|
|
564
|
-
if (!areSelectorDatePropsEqual(prev, next,
|
|
586
|
+
if (!areSelectorDatePropsEqual(prev, next, monthKey)) return false
|
|
565
587
|
if (prev.variant !== next.variant) return false
|
|
566
588
|
if (prev.disabled !== next.disabled) return false
|
|
567
589
|
if (prev.className !== next.className) return false
|