@aiquants/period-slider 0.4.1 → 0.4.2
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/dist/DateSelector.d.ts +0 -3
- package/dist/DateSelector.d.ts.map +1 -1
- package/dist/MonthSelector.d.ts +0 -3
- package/dist/MonthSelector.d.ts.map +1 -1
- package/dist/PeriodSlider.d.ts +15 -4
- package/dist/PeriodSlider.d.ts.map +1 -1
- package/dist/YearSelector.d.ts +0 -3
- package/dist/YearSelector.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +1366 -1247
- package/dist/usePeriodSlider.d.ts +25 -1
- package/dist/usePeriodSlider.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/DateSelector.tsx +24 -11
- package/src/MonthSelector.tsx +25 -14
- package/src/PeriodSlider.tsx +361 -91
- package/src/YearSelector.tsx +30 -13
- package/src/usePeriodSlider.ts +24 -0
package/src/PeriodSlider.tsx
CHANGED
|
@@ -235,7 +235,7 @@ export interface PeriodSliderRangeProps extends BasePeriodSliderProps {
|
|
|
235
235
|
mode: "range"
|
|
236
236
|
/** Controlled selected date range tuple [lower, upper] / 制御時の選択期間タプル */
|
|
237
237
|
range?: [Date, Date]
|
|
238
|
-
/** Initial date range tuple for uncontrolled usage /
|
|
238
|
+
/** Initial date range tuple for uncontrolled usage; with `range` also omitted the selection starts at the domain bounds / 非制御時の初期選択期間タプル。`range` ともに未指定なら選択は定義域の両端から開始 */
|
|
239
239
|
defaultRange?: [Date, Date]
|
|
240
240
|
/** Callback triggered when the selected range changes / 期間変更時コールバック */
|
|
241
241
|
onChangeRange?: (lower: Date, upper: Date) => void
|
|
@@ -260,7 +260,7 @@ export interface PeriodSliderPointProps extends BasePeriodSliderProps {
|
|
|
260
260
|
mode: "point"
|
|
261
261
|
/** Controlled selected point date / 制御時の選択日付 */
|
|
262
262
|
value?: Date
|
|
263
|
-
/** Initial point date for uncontrolled usage /
|
|
263
|
+
/** Initial point date for uncontrolled usage; with `value` also omitted the selection starts at the domain start / 非制御時の初期選択日付。`value` ともに未指定なら選択は定義域の先頭から開始 */
|
|
264
264
|
defaultValue?: Date
|
|
265
265
|
/** Callback triggered when the selected point changes / ポイント変更時コールバック */
|
|
266
266
|
onChangePoint?: (value: Date) => void
|
|
@@ -402,7 +402,11 @@ export const encode = (unit: PeriodSliderUnit, d: Date): number => {
|
|
|
402
402
|
|
|
403
403
|
if (unit === "year") return y
|
|
404
404
|
if (unit === "month") return y * 12 + (m - 1)
|
|
405
|
-
|
|
405
|
+
// Date.UTC は 0-99 年を 1900 年代へ写像するため、日キーだけ年が 1900 年ずれ、99 年から 100 年へ跨いだ瞬間に単調性まで壊れる
|
|
406
|
+
const utcMidnight = new Date(0)
|
|
407
|
+
utcMidnight.setUTCFullYear(y, m - 1, day)
|
|
408
|
+
utcMidnight.setUTCHours(0, 0, 0, 0)
|
|
409
|
+
return Math.floor(utcMidnight.getTime() / (24 * 60 * 60 * 1000))
|
|
406
410
|
}
|
|
407
411
|
|
|
408
412
|
/**
|
|
@@ -414,14 +418,23 @@ export const encode = (unit: PeriodSliderUnit, d: Date): number => {
|
|
|
414
418
|
* @returns Date pinned to the start of the encoded unit / エンコード単位の先頭に揃えた Date
|
|
415
419
|
*/
|
|
416
420
|
export const decode = (unit: PeriodSliderUnit, val: number): Date => {
|
|
417
|
-
|
|
421
|
+
// Date コンストラクタは 0-99 年を 1900 年代へ写像するため、年は必ず setFullYear で書き戻す
|
|
422
|
+
const restored = new Date(0)
|
|
423
|
+
restored.setHours(0, 0, 0, 0)
|
|
424
|
+
if (unit === "year") {
|
|
425
|
+
restored.setFullYear(val, 0, 1)
|
|
426
|
+
return restored
|
|
427
|
+
}
|
|
418
428
|
if (unit === "month") {
|
|
419
429
|
const y = Math.floor(val / 12)
|
|
420
|
-
|
|
421
|
-
|
|
430
|
+
// 剰余演算子は負のキーで負の月を返し、年が 1 つ繰り下がって encode と往復しなくなる
|
|
431
|
+
const m = val - y * 12
|
|
432
|
+
restored.setFullYear(y, m, 1)
|
|
433
|
+
return restored
|
|
422
434
|
}
|
|
423
435
|
const utcDate = new Date(val * 24 * 60 * 60 * 1000)
|
|
424
|
-
|
|
436
|
+
restored.setFullYear(utcDate.getUTCFullYear(), utcDate.getUTCMonth(), utcDate.getUTCDate())
|
|
437
|
+
return restored
|
|
425
438
|
}
|
|
426
439
|
|
|
427
440
|
/**
|
|
@@ -642,6 +655,56 @@ export const getSortedAllowedDates = (allowedDates: Date[] | undefined, unit: Pe
|
|
|
642
655
|
.map((enc) => encMap.get(enc) as Date)
|
|
643
656
|
}
|
|
644
657
|
|
|
658
|
+
/**
|
|
659
|
+
* Maps a date onto its 0-1 position on a rail whose value space is a discrete candidate list.
|
|
660
|
+
* 離散候補日付を値空間とするレール上で、日付を 0-1 の位置比率へ写す関数。
|
|
661
|
+
*
|
|
662
|
+
* Inverse of railRatioToDiscreteIndex: "index" gives every candidate an equal share of the rail, "time"
|
|
663
|
+
* places it proportionally to the elapsed time between the first and the last candidate.
|
|
664
|
+
* railRatioToDiscreteIndex の逆写像 ("index" は等間隔配置、"time" は先頭・末尾候補間の実時間比例配置)。
|
|
665
|
+
*
|
|
666
|
+
* @param dates - Ascending, deduplicated candidate dates / 昇順・重複排除済みの候補日付一覧
|
|
667
|
+
* @param unit - Time resolution unit used to locate the entry / 要素の特定に用いる時間解像度単位
|
|
668
|
+
* @param snapMode - Placement strategy for the candidates / 候補日付の配置方式
|
|
669
|
+
* @param d - Date to place / 配置対象の日付
|
|
670
|
+
* @returns Position ratio between 0 and 1 / 0 から 1 の位置比率
|
|
671
|
+
*/
|
|
672
|
+
const discreteDateToRailRatio = (dates: Date[], unit: PeriodSliderUnit, snapMode: PeriodSliderSnapMode, d: Date): number => {
|
|
673
|
+
const maxIdx = dates.length - 1
|
|
674
|
+
if (maxIdx <= 0) return 0
|
|
675
|
+
const idx = findNearestDateIndex(dates, d, unit)
|
|
676
|
+
if (snapMode === "time") {
|
|
677
|
+
const firstMs = dates[0].getTime()
|
|
678
|
+
const totalMs = dates[maxIdx].getTime() - firstMs
|
|
679
|
+
if (totalMs <= 0) return 0
|
|
680
|
+
return Math.max(0, Math.min(1, (dates[idx].getTime() - firstMs) / totalMs))
|
|
681
|
+
}
|
|
682
|
+
return idx / maxIdx
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Resolves the candidate index a 0-1 rail position points at, in the space discreteDateToRailRatio renders.
|
|
687
|
+
* discreteDateToRailRatio が描画する空間で、0-1 の位置比率が指す候補日付のインデックスを解決する関数。
|
|
688
|
+
*
|
|
689
|
+
* @param dates - Ascending, deduplicated candidate dates / 昇順・重複排除済みの候補日付一覧
|
|
690
|
+
* @param unit - Time resolution unit used to locate the entry / 要素の特定に用いる時間解像度単位
|
|
691
|
+
* @param snapMode - Placement strategy for the candidates / 候補日付の配置方式
|
|
692
|
+
* @param ratio - Position ratio between 0 and 1 / 0 から 1 の位置比率
|
|
693
|
+
* @returns Index of the candidate the ratio resolves to / 比率が解決する候補日付のインデックス
|
|
694
|
+
*/
|
|
695
|
+
const railRatioToDiscreteIndex = (dates: Date[], unit: PeriodSliderUnit, snapMode: PeriodSliderSnapMode, ratio: number): number => {
|
|
696
|
+
const maxIdx = dates.length - 1
|
|
697
|
+
if (maxIdx <= 0) return 0
|
|
698
|
+
const clamped = Math.max(0, Math.min(1, ratio))
|
|
699
|
+
if (snapMode === "time") {
|
|
700
|
+
const firstMs = dates[0].getTime()
|
|
701
|
+
const totalMs = dates[maxIdx].getTime() - firstMs
|
|
702
|
+
if (totalMs <= 0) return 0
|
|
703
|
+
return findNearestDateIndex(dates, new Date(firstMs + clamped * totalMs), unit)
|
|
704
|
+
}
|
|
705
|
+
return Math.max(0, Math.min(maxIdx, Math.round(clamped * maxIdx)))
|
|
706
|
+
}
|
|
707
|
+
|
|
645
708
|
/**
|
|
646
709
|
* Calculates dragging values when dragging knob handles.
|
|
647
710
|
* ハンドルドラッグ時の数値を算出します。
|
|
@@ -975,6 +1038,17 @@ export type VernierHandle = "macro-low" | "macro-high" | "macro-connect" | "micr
|
|
|
975
1038
|
/**
|
|
976
1039
|
* Resolves the target Vernier handle based on pointer primary-axis ratio and cross-axis offset relative to track center.
|
|
977
1040
|
* トラック中心線に対するポインターの直交軸オフセットと主軸比率から、操作対象となるノギスハンドル(マクロまたはミクロ)を判定します。
|
|
1041
|
+
*
|
|
1042
|
+
* @param pointerPrimaryRatio - Pointer position along the track as a 0-1 ratio / トラック主軸上のポインター位置比率 (0-1)
|
|
1043
|
+
* @param pointerCrossAxisOffset - Signed pointer offset from the track center line in pixels / トラック中心線からのポインター直交軸オフセット (ピクセル、符号付き)
|
|
1044
|
+
* @param macroLowRatio - Macro window start position as a 0-1 ratio / マクロ窓開始位置の比率 (0-1)
|
|
1045
|
+
* @param macroHighRatio - Macro window end position as a 0-1 ratio / マクロ窓終了位置の比率 (0-1)
|
|
1046
|
+
* @param microLowRatio - Micro selection start position as a 0-1 ratio / ミクロ選択開始位置の比率 (0-1)
|
|
1047
|
+
* @param microHighRatio - Micro selection end position as a 0-1 ratio / ミクロ選択終了位置の比率 (0-1)
|
|
1048
|
+
* @param orientation - Which rail the macro scale is drawn on (default: "macro-top") / マクロスケールを描くレール (既定: "macro-top")
|
|
1049
|
+
* @param handleHitSlopRatio - Hit slop around a knob as a 0-1 ratio (default: 0.05) / つまみ周辺の当たり判定余裕 (0-1 比率、既定: 0.05)
|
|
1050
|
+
* @param allowConnectHandles - Whether a press inside a band may grab the band itself (default: true) / 帯の内側の押下で帯自体を掴めるか (既定: true)
|
|
1051
|
+
* @returns Handle the press targets / 押下が対象とするハンドル
|
|
978
1052
|
*/
|
|
979
1053
|
export function resolveVernierTargetHandle(
|
|
980
1054
|
pointerPrimaryRatio: number,
|
|
@@ -985,6 +1059,7 @@ export function resolveVernierTargetHandle(
|
|
|
985
1059
|
microHighRatio: number,
|
|
986
1060
|
orientation: "macro-top" | "macro-bottom" | "macro-left" | "macro-right" = "macro-top",
|
|
987
1061
|
handleHitSlopRatio: number = 0.05,
|
|
1062
|
+
allowConnectHandles: boolean = true,
|
|
988
1063
|
): VernierHandle {
|
|
989
1064
|
// orientation に応じて第一レール(上段または左段)がマクロかミクロかを決定
|
|
990
1065
|
const isFirstRailMacro = orientation === "macro-top" || orientation === "macro-left"
|
|
@@ -1001,7 +1076,7 @@ export function resolveVernierTargetHandle(
|
|
|
1001
1076
|
if (distHigh <= handleHitSlopRatio && distHigh < distLow) {
|
|
1002
1077
|
return "macro-high"
|
|
1003
1078
|
}
|
|
1004
|
-
if (pointerPrimaryRatio >= macroLowRatio && pointerPrimaryRatio <= macroHighRatio) {
|
|
1079
|
+
if (allowConnectHandles && pointerPrimaryRatio >= macroLowRatio && pointerPrimaryRatio <= macroHighRatio) {
|
|
1005
1080
|
return "macro-connect"
|
|
1006
1081
|
}
|
|
1007
1082
|
return distLow < distHigh ? "macro-low" : "macro-high"
|
|
@@ -1017,7 +1092,7 @@ export function resolveVernierTargetHandle(
|
|
|
1017
1092
|
if (distHigh <= handleHitSlopRatio && distHigh < distLow) {
|
|
1018
1093
|
return "micro-high"
|
|
1019
1094
|
}
|
|
1020
|
-
if (pointerPrimaryRatio >= microLowRatio && pointerPrimaryRatio <= microHighRatio) {
|
|
1095
|
+
if (allowConnectHandles && pointerPrimaryRatio >= microLowRatio && pointerPrimaryRatio <= microHighRatio) {
|
|
1021
1096
|
return "micro-connect"
|
|
1022
1097
|
}
|
|
1023
1098
|
return distLow < distHigh ? "micro-low" : "micro-high"
|
|
@@ -1167,6 +1242,76 @@ const assertDateRangeTuple = (propName: string, value: unknown): void => {
|
|
|
1167
1242
|
}
|
|
1168
1243
|
}
|
|
1169
1244
|
|
|
1245
|
+
/**
|
|
1246
|
+
* Validates an optional scalar Date prop and fails fast on an unusable value.
|
|
1247
|
+
* 任意のスカラー日付 Props を検証し、利用不能な値で即座に失敗させる関数。
|
|
1248
|
+
*
|
|
1249
|
+
* @param propName - Prop name quoted in the error message / エラーメッセージへ埋め込む Props 名
|
|
1250
|
+
* @param value - Raw prop value supplied by the consumer / 利用側が指定した生の Props 値
|
|
1251
|
+
* @returns Nothing; the function only throws or returns normally / 戻り値なし (正常時は無返却)
|
|
1252
|
+
* @throws RangeError when the value is not a valid Date / 値が有効な Date でない場合
|
|
1253
|
+
*/
|
|
1254
|
+
const assertSelectionDate = (propName: string, value: unknown): void => {
|
|
1255
|
+
if (!isValidDate(value)) throw new RangeError(`PeriodSlider: ${propName} must be a valid Date (received: ${describeDateValue(value)})`)
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* Validates that a selection date lies inside the declared slider domain.
|
|
1260
|
+
* 選択日付が宣言済みのスライダー定義域の内側にあることを検証する関数。
|
|
1261
|
+
*
|
|
1262
|
+
* An out-of-domain selection makes the slider report aria-valuenow outside aria-valuemin / aria-valuemax
|
|
1263
|
+
* and pin the knob to the rail end while its label shows a date the rail does not contain, so it is
|
|
1264
|
+
* rejected instead of being silently clamped.
|
|
1265
|
+
* 定義域外の選択は aria-valuenow が aria-valuemin / aria-valuemax の外側を指し、レール端に貼り付いたつまみが
|
|
1266
|
+
* レール上に存在しない日付を表示するため、黙ってクランプせず拒否。
|
|
1267
|
+
*
|
|
1268
|
+
* @param propName - Prop name quoted in the error message / エラーメッセージへ埋め込む Props 名
|
|
1269
|
+
* @param value - Selection date supplied by the consumer / 利用側が指定した選択日付
|
|
1270
|
+
* @param minDate - Lower domain boundary / 定義域下限
|
|
1271
|
+
* @param maxDate - Upper domain boundary / 定義域上限
|
|
1272
|
+
* @returns Nothing; the function only throws or returns normally / 戻り値なし (正常時は無返却)
|
|
1273
|
+
* @throws RangeError when the value lies outside [minDate, maxDate] / 値が [minDate, maxDate] の外にある場合
|
|
1274
|
+
*/
|
|
1275
|
+
const assertSelectionWithinDomain = (propName: string, value: Date, minDate: Date, maxDate: Date): void => {
|
|
1276
|
+
if (value.getTime() < minDate.getTime() || value.getTime() > maxDate.getTime()) {
|
|
1277
|
+
throw new RangeError(`PeriodSlider: ${propName} must lie within [minDate, maxDate] (received: ${describeDateValue(value)}, minDate: ${describeDateValue(minDate)}, maxDate: ${describeDateValue(maxDate)})`)
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* Validates the range and point selection props for tuple shape, Date validity and domain containment.
|
|
1283
|
+
* range / point モードの選択 Props について、タプル形状・Date 妥当性・定義域内包を検証する関数。
|
|
1284
|
+
*
|
|
1285
|
+
* An omitted prop keeps its specified meaning ("select the start of the domain") and is left alone; every
|
|
1286
|
+
* supplied value is validated, so a malformed one fails fast instead of silently selecting the domain start.
|
|
1287
|
+
* 未指定は仕様上の既定 (定義域先頭を選択) を保つため検証対象外。指定値は全て検証し、不正値が黙って定義域先頭へ化けることを防ぐ。
|
|
1288
|
+
*
|
|
1289
|
+
* @param props - Raw props the component was rendered with / コンポーネントへ渡された生の Props
|
|
1290
|
+
* @param minDate - Lower domain boundary / 定義域下限
|
|
1291
|
+
* @param maxDate - Upper domain boundary / 定義域上限
|
|
1292
|
+
* @returns Nothing; the function only throws or returns normally / 戻り値なし (正常時は無返却)
|
|
1293
|
+
* @throws RangeError when a supplied selection prop is malformed or lies outside the domain / 指定された選択 Props が不正または定義域外の場合
|
|
1294
|
+
*/
|
|
1295
|
+
const assertSelectionProps = (props: PeriodSliderProps, minDate: Date, maxDate: Date): void => {
|
|
1296
|
+
if (props.mode === "range") {
|
|
1297
|
+
for (const propName of ["range", "defaultRange"] as const) {
|
|
1298
|
+
const value = props[propName]
|
|
1299
|
+
if (value === undefined) continue
|
|
1300
|
+
assertDateRangeTuple(propName, value)
|
|
1301
|
+
assertSelectionWithinDomain(`${propName}[0]`, value[0], minDate, maxDate)
|
|
1302
|
+
assertSelectionWithinDomain(`${propName}[1]`, value[1], minDate, maxDate)
|
|
1303
|
+
}
|
|
1304
|
+
return
|
|
1305
|
+
}
|
|
1306
|
+
if (props.mode !== "point") return
|
|
1307
|
+
for (const propName of ["value", "defaultValue"] as const) {
|
|
1308
|
+
const value = props[propName]
|
|
1309
|
+
if (value === undefined) continue
|
|
1310
|
+
assertSelectionDate(propName, value)
|
|
1311
|
+
assertSelectionWithinDomain(propName, value, minDate, maxDate)
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1170
1315
|
/**
|
|
1171
1316
|
* Validates the mandatory vernier props and resolves the micro selection that seeds the uncontrolled state.
|
|
1172
1317
|
* ノギスモードの必須 Props を検証し、非制御ステートの初期値となるミクロ選択期間を解決する関数。
|
|
@@ -1191,8 +1336,13 @@ const assertVernierRanges = (macroRange: [Date, Date], microRange: [Date, Date]
|
|
|
1191
1336
|
}
|
|
1192
1337
|
|
|
1193
1338
|
/**
|
|
1194
|
-
* Resolves the
|
|
1195
|
-
* 昇順の離散候補日付一覧の中で、キーボード 1
|
|
1339
|
+
* Resolves the candidate index reached by one keyboard step inside a sorted allowed-date list.
|
|
1340
|
+
* 昇順の離散候補日付一覧の中で、キーボード 1 操作分の移動先インデックスを解決する関数。
|
|
1341
|
+
*
|
|
1342
|
+
* The index rather than the date is returned so the caller can tell a step that moved from one that could
|
|
1343
|
+
* not, without re-deriving the current index from a date the rail may have rounded to a different unit.
|
|
1344
|
+
* 日付ではなくインデックスを返すことで、呼び出し側は「動いた押下」と「動けなかった押下」を、
|
|
1345
|
+
* 単位丸めで別日付になり得る現在値から再導出せずに判別可能。
|
|
1196
1346
|
*
|
|
1197
1347
|
* @param dates - Ascending, deduplicated allowed dates / 昇順・重複排除済みの候補日付一覧
|
|
1198
1348
|
* @param unit - Time resolution unit used to locate the current entry / 現在値の特定に用いる時間解像度単位
|
|
@@ -1202,15 +1352,14 @@ const assertVernierRanges = (macroRange: [Date, Date], microRange: [Date, Date]
|
|
|
1202
1352
|
* @param delta - Signed number of indices to move / 移動するインデックス数 (符号付き)
|
|
1203
1353
|
* @param isHome - Whether the Home key was pressed / Home キー押下か
|
|
1204
1354
|
* @param isEnd - Whether the End key was pressed / End キー押下か
|
|
1205
|
-
* @returns
|
|
1355
|
+
* @returns Index of the allowed date the handle moves to / つまみの移動先となる候補日付のインデックス
|
|
1206
1356
|
*/
|
|
1207
|
-
const
|
|
1357
|
+
const stepDiscreteIndex = (dates: Date[], unit: PeriodSliderUnit, current: Date, lowerBound: Date, upperBound: Date, delta: number, isHome: boolean, isEnd: boolean): number => {
|
|
1208
1358
|
const lowIdx = findNearestDateIndex(dates, lowerBound, unit)
|
|
1209
1359
|
const highIdx = findNearestDateIndex(dates, upperBound, unit)
|
|
1210
|
-
if (isHome) return
|
|
1211
|
-
if (isEnd) return
|
|
1212
|
-
|
|
1213
|
-
return dates[nextIdx]
|
|
1360
|
+
if (isHome) return lowIdx
|
|
1361
|
+
if (isEnd) return highIdx
|
|
1362
|
+
return Math.max(lowIdx, Math.min(highIdx, findNearestDateIndex(dates, current, unit) + delta))
|
|
1214
1363
|
}
|
|
1215
1364
|
|
|
1216
1365
|
/**
|
|
@@ -1358,6 +1507,9 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
1358
1507
|
// 定義域が欠けたまま描画すると全ての位置計算が無根拠になるため、フック呼び出し前に失敗させる
|
|
1359
1508
|
assertDomainBounds(minDate, maxDate)
|
|
1360
1509
|
|
|
1510
|
+
// 選択 Props も同じ地点で検証する。素通しすると空タプルや null が黙って定義域先頭の選択へ化ける
|
|
1511
|
+
assertSelectionProps(props, minDate, maxDate)
|
|
1512
|
+
|
|
1361
1513
|
// 不正なロケールを黙って ISO 表記へ落とすと、利用側は翻訳が効かない理由に気付けない
|
|
1362
1514
|
if (locale !== undefined) assertLocaleTag("locale", locale)
|
|
1363
1515
|
|
|
@@ -1464,6 +1616,11 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
1464
1616
|
const currentLowVal = draggingValues ? draggingValues[0] : isControlled ? initLow : uncontrolledValues[0]
|
|
1465
1617
|
const currentHighVal = draggingValues ? draggingValues[1] : isControlled ? initHigh : uncontrolledValues[1]
|
|
1466
1618
|
|
|
1619
|
+
// 重複発火の判定基準。「最後に発火した値」を覚えると、利用側が別経路で選択を戻した瞬間に基準が実態から外れ、
|
|
1620
|
+
// その値へ二度と戻れなくなる。いま確定している選択そのものを基準にすればずれようがない
|
|
1621
|
+
const committedValuesRef = useRef<[number, number]>([currentLowVal, currentHighVal])
|
|
1622
|
+
committedValuesRef.current = [currentLowVal, currentHighVal]
|
|
1623
|
+
|
|
1467
1624
|
// ------------------------------------------------------------------
|
|
1468
1625
|
// C-2. ノギススケールの境界とドラッグ状態
|
|
1469
1626
|
// ------------------------------------------------------------------
|
|
@@ -1548,6 +1705,10 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
1548
1705
|
})
|
|
1549
1706
|
}, [isVernierMode, microAllowedDates, microUnit, minTime, maxTime, vernierMicroMinEnc, vernierMicroMaxEnc])
|
|
1550
1707
|
|
|
1708
|
+
// 離散指定は窓内に候補が 1 つでも残っているときだけ成立する。空配列のままでは窓内の連続値として扱う
|
|
1709
|
+
const macroIsDiscreteScale = macroIsDiscrete && sortedMacroAllowedDates.length > 0
|
|
1710
|
+
const microIsDiscreteScale = microIsDiscrete && sortedMicroAllowedDates.length > 0
|
|
1711
|
+
|
|
1551
1712
|
const vernierMicroLowEnc = useMemo(() => {
|
|
1552
1713
|
if (vernierMicroSelection === null) return vernierMicroMinEnc
|
|
1553
1714
|
return encode(microUnit, vernierMicroSelection[0])
|
|
@@ -1562,14 +1723,14 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
1562
1723
|
const vernierMicroLowDate = useMemo(() => decode(microUnit, vernierMicroLowEnc), [microUnit, vernierMicroLowEnc])
|
|
1563
1724
|
const vernierMicroHighDate = useMemo(() => decode(microUnit, vernierMicroHighEnc), [microUnit, vernierMicroHighEnc])
|
|
1564
1725
|
|
|
1565
|
-
// 比率 (0.0 〜 1.0)
|
|
1726
|
+
// 比率 (0.0 〜 1.0)。離散レールは当たり判定と同じ候補空間で描かないと、つまみがポインターから離れて飛ぶ
|
|
1566
1727
|
const macroSpan = Math.max(1, vernierMacroMaxEnc - vernierMacroMinEnc)
|
|
1567
|
-
const macroLowRatio = Math.max(0, Math.min(1, (vernierMacroLowEnc - vernierMacroMinEnc) / macroSpan))
|
|
1568
|
-
const macroHighRatio = Math.max(macroLowRatio, Math.min(1, (vernierMacroHighEnc - vernierMacroMinEnc) / macroSpan))
|
|
1728
|
+
const macroLowRatio = macroIsDiscreteScale ? discreteDateToRailRatio(sortedMacroAllowedDates, macroUnit, snapMode, decode(macroUnit, vernierMacroLowEnc)) : Math.max(0, Math.min(1, (vernierMacroLowEnc - vernierMacroMinEnc) / macroSpan))
|
|
1729
|
+
const macroHighRatio = Math.max(macroLowRatio, macroIsDiscreteScale ? discreteDateToRailRatio(sortedMacroAllowedDates, macroUnit, snapMode, decode(macroUnit, vernierMacroHighEnc)) : Math.min(1, (vernierMacroHighEnc - vernierMacroMinEnc) / macroSpan))
|
|
1569
1730
|
|
|
1570
1731
|
const microSpan = Math.max(1, vernierMicroMaxEnc - vernierMicroMinEnc)
|
|
1571
|
-
const microLowRatio = Math.max(0, Math.min(1, (vernierMicroLowEnc - vernierMicroMinEnc) / microSpan))
|
|
1572
|
-
const microHighRatio = Math.max(microLowRatio, Math.min(1, (vernierMicroHighEnc - vernierMicroMinEnc) / microSpan))
|
|
1732
|
+
const microLowRatio = microIsDiscreteScale ? discreteDateToRailRatio(sortedMicroAllowedDates, microUnit, snapMode, vernierMicroLowDate) : Math.max(0, Math.min(1, (vernierMicroLowEnc - vernierMicroMinEnc) / microSpan))
|
|
1733
|
+
const microHighRatio = Math.max(microLowRatio, microIsDiscreteScale ? discreteDateToRailRatio(sortedMicroAllowedDates, microUnit, snapMode, vernierMicroHighDate) : Math.min(1, (vernierMicroHighEnc - vernierMicroMinEnc) / microSpan))
|
|
1573
1734
|
|
|
1574
1735
|
// ------------------------------------------------------------------
|
|
1575
1736
|
// D. デバウンスとコールバック通知
|
|
@@ -1635,22 +1796,22 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
1635
1796
|
*/
|
|
1636
1797
|
const clampToDomain = useCallback((d: Date): Date => new Date(Math.min(Math.max(d.getTime(), minTime), maxTime)), [minTime, maxTime])
|
|
1637
1798
|
|
|
1638
|
-
const lastEmittedKeyRef = useRef<string | null>(null)
|
|
1639
|
-
|
|
1640
1799
|
const notifyChange = useCallback(
|
|
1641
1800
|
(nextLow: number, nextHigh: number, immediate = false) => {
|
|
1642
|
-
const
|
|
1643
|
-
const
|
|
1644
|
-
|
|
1645
|
-
const key = propsRef.current.mode === "point" ? `${lowDate.getTime()}` : `${lowDate.getTime()}-${highDate.getTime()}`
|
|
1801
|
+
const [committedLow, committedHigh] = committedValuesRef.current
|
|
1802
|
+
const isUnchanged = propsRef.current.mode === "point" ? nextLow === committedLow : nextLow === committedLow && nextHigh === committedHigh
|
|
1646
1803
|
|
|
1647
|
-
|
|
1804
|
+
// 選択が動いていない確定値でコールバックを撃つと、変更駆動の消費側が無意味な再取得を行う。
|
|
1805
|
+
// デバウンス保留中だけは例外で、予約済みの古い値を確定値で上書きしないと指を離した位置が消える
|
|
1806
|
+
if (isUnchanged && rangeEmitRef.current.timerId === null) {
|
|
1648
1807
|
return
|
|
1649
1808
|
}
|
|
1650
1809
|
|
|
1810
|
+
const lowDate = valueToDate(nextLow)
|
|
1811
|
+
const highDate = valueToDate(nextHigh)
|
|
1812
|
+
|
|
1651
1813
|
// ノギスモードは値空間 (rangeMin/rangeMax) が別系統のため、この経路ではなく notifyMicroRange / notifyMacroRange を使う
|
|
1652
1814
|
const doEmit = () => {
|
|
1653
|
-
lastEmittedKeyRef.current = key
|
|
1654
1815
|
// 予約から発火までの間に利用側が別のハンドラへ差し替えることがある。
|
|
1655
1816
|
// 予約時点のスナップショットを閉じ込めると、既に捨てられたクロージャだけが呼ばれる
|
|
1656
1817
|
const p = propsRef.current
|
|
@@ -1887,10 +2048,9 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
1887
2048
|
|
|
1888
2049
|
let nextMacroLowDate: Date
|
|
1889
2050
|
let nextMacroHighDate: Date
|
|
1890
|
-
if (
|
|
1891
|
-
const
|
|
1892
|
-
const
|
|
1893
|
-
const highIdx = Math.max(lowIdx, Math.min(maxIdx, Math.round(nextMacroHighRatio * maxIdx)))
|
|
2051
|
+
if (macroIsDiscreteScale) {
|
|
2052
|
+
const lowIdx = railRatioToDiscreteIndex(sortedMacroAllowedDates, macroUnit, snapMode, nextMacroLowRatio)
|
|
2053
|
+
const highIdx = Math.max(lowIdx, railRatioToDiscreteIndex(sortedMacroAllowedDates, macroUnit, snapMode, nextMacroHighRatio))
|
|
1894
2054
|
nextMacroLowDate = sortedMacroAllowedDates[lowIdx]
|
|
1895
2055
|
nextMacroHighDate = sortedMacroAllowedDates[highIdx]
|
|
1896
2056
|
} else {
|
|
@@ -1977,10 +2137,9 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
1977
2137
|
|
|
1978
2138
|
let nextMicroLowDate: Date
|
|
1979
2139
|
let nextMicroHighDate: Date
|
|
1980
|
-
if (
|
|
1981
|
-
const
|
|
1982
|
-
const
|
|
1983
|
-
const highIdx = Math.max(lowIdx, Math.min(maxIdx, Math.round(nextMicroHighRatio * maxIdx)))
|
|
2140
|
+
if (microIsDiscreteScale) {
|
|
2141
|
+
const lowIdx = railRatioToDiscreteIndex(sortedMicroAllowedDates, microUnit, snapMode, nextMicroLowRatio)
|
|
2142
|
+
const highIdx = Math.max(lowIdx, railRatioToDiscreteIndex(sortedMicroAllowedDates, microUnit, snapMode, nextMicroHighRatio))
|
|
1984
2143
|
nextMicroLowDate = sortedMicroAllowedDates[lowIdx]
|
|
1985
2144
|
nextMicroHighDate = sortedMicroAllowedDates[highIdx]
|
|
1986
2145
|
} else {
|
|
@@ -2058,8 +2217,8 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2058
2217
|
isVertical,
|
|
2059
2218
|
macroUnit,
|
|
2060
2219
|
microUnit,
|
|
2061
|
-
|
|
2062
|
-
|
|
2220
|
+
macroIsDiscreteScale,
|
|
2221
|
+
microIsDiscreteScale,
|
|
2063
2222
|
sortedMacroAllowedDates,
|
|
2064
2223
|
sortedMicroAllowedDates,
|
|
2065
2224
|
vernierMacroMinEnc,
|
|
@@ -2222,7 +2381,8 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2222
2381
|
const pointerRatio = calcRatioFromPos(e.clientX, e.clientY, rect)
|
|
2223
2382
|
if (pointerRatio === null) return
|
|
2224
2383
|
const pointerCrossAxisOffset = isVertical ? e.clientX - (rect.left + rect.width / 2) : e.clientY - (rect.top + rect.height / 2)
|
|
2225
|
-
|
|
2384
|
+
// 帯を隠したまま帯ドラッグだけ残ると、描かれていない当たり判定が生き続ける
|
|
2385
|
+
const targetHandle = resolveVernierTargetHandle(pointerRatio, pointerCrossAxisOffset, macroLowRatio, macroHighRatio, microLowRatio, microHighRatio, vernierOrientation, undefined, !hideConnectBar)
|
|
2226
2386
|
startVernierDrag(e.pointerId, targetHandle, pointerRatio)
|
|
2227
2387
|
return
|
|
2228
2388
|
}
|
|
@@ -2284,11 +2444,34 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2284
2444
|
}
|
|
2285
2445
|
}
|
|
2286
2446
|
|
|
2447
|
+
/**
|
|
2448
|
+
* Re-contains the micro selection into a newly resolved macro window and emits it only when it moved.
|
|
2449
|
+
* 新しく確定したマクロ窓へミクロ選択を収め直し、実際に動いた場合のみ発火する関数。
|
|
2450
|
+
*
|
|
2451
|
+
* @param nextMacroLow - Start date of the macro window just resolved / 確定直後のマクロ窓開始日付
|
|
2452
|
+
* @param nextMacroHigh - End date of the macro window just resolved / 確定直後のマクロ窓終了日付
|
|
2453
|
+
* @returns Nothing / 戻り値なし
|
|
2454
|
+
*/
|
|
2455
|
+
const containMicroRangeIntoMacroWindow = (nextMacroLow: Date, nextMacroHigh: Date): void => {
|
|
2456
|
+
// 次のレンダーでミクロレール端はこの式へ置き換わる。同じ式で収め直さないと aria-valuenow が aria-valuemax の外を指し続ける
|
|
2457
|
+
const nextMicroMinEnc = Math.max(encode(microUnit, nextMacroLow), encode(microUnit, minDate))
|
|
2458
|
+
const nextMicroMaxEnc = Math.min(encode(microUnit, getMacroWindowEndDate(macroUnit, microUnit, nextMacroHigh)), encode(microUnit, maxDate))
|
|
2459
|
+
const clampedLowEnc = Math.max(nextMicroMinEnc, Math.min(nextMicroMaxEnc, vernierMicroLowEnc))
|
|
2460
|
+
const clampedHighEnc = Math.max(clampedLowEnc, Math.min(nextMicroMaxEnc, vernierMicroHighEnc))
|
|
2461
|
+
if (clampedLowEnc === vernierMicroLowEnc && clampedHighEnc === vernierMicroHighEnc) return
|
|
2462
|
+
notifyMicroRange(decode(microUnit, clampedLowEnc), decode(microUnit, clampedHighEnc), true)
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2287
2465
|
/**
|
|
2288
2466
|
* Handles keyboard navigation (ArrowLeft, ArrowRight, PageUp, PageDown, Home, End) for Vernier Caliper handles.
|
|
2289
2467
|
* ノギス (Vernier Caliper) ハンドルのキーボード操作 (ArrowLeft, ArrowRight, PageUp, PageDown, Home, End) を処理するハンドラ。
|
|
2290
2468
|
*
|
|
2291
|
-
*
|
|
2469
|
+
* A press that cannot move the handle emits nothing, and a macro window change re-contains the micro
|
|
2470
|
+
* selection, so keyboard and pointer leave the component in the same state.
|
|
2471
|
+
* 動けない押下は無発火とし、マクロ窓変更時はミクロ選択を窓内へ収め直すことで、キーボードとポインターの終状態を一致。
|
|
2472
|
+
*
|
|
2473
|
+
* @param handle - The Vernier handle being manipulated / 操作対象のノギスハンドル
|
|
2474
|
+
* @returns Keyboard event handler for the given handle / 指定ハンドル用のキーボードイベントハンドラ
|
|
2292
2475
|
*/
|
|
2293
2476
|
const handleVernierKeyDown = (handle: "macro-low" | "macro-high" | "micro-low" | "micro-high") => (e: React.KeyboardEvent<HTMLDivElement>) => {
|
|
2294
2477
|
if (disabled || !isVernierMode || props.mode !== "vernier") return
|
|
@@ -2322,57 +2505,75 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2322
2505
|
}
|
|
2323
2506
|
e.preventDefault()
|
|
2324
2507
|
|
|
2325
|
-
// 離散指定時はポインター操作と同じ候補集合の上を移動しないと、キーボードだけが候補外の日付を発火する
|
|
2326
|
-
const macroIsDiscreteScale = macroIsDiscrete && sortedMacroAllowedDates.length > 0
|
|
2327
|
-
const microIsDiscreteScale = microIsDiscrete && sortedMicroAllowedDates.length > 0
|
|
2328
|
-
|
|
2329
2508
|
if (handle === "macro-low") {
|
|
2330
2509
|
const currentLow = decode(macroUnit, vernierMacroLowEnc)
|
|
2331
2510
|
const currentHigh = decode(macroUnit, vernierMacroHighEnc)
|
|
2511
|
+
// 離散指定時はポインター操作と同じ候補集合の上を移動しないと、キーボードだけが候補外の日付を発火する
|
|
2332
2512
|
if (macroIsDiscreteScale) {
|
|
2333
|
-
|
|
2513
|
+
const nextIdx = stepDiscreteIndex(sortedMacroAllowedDates, macroUnit, currentLow, sortedMacroAllowedDates[0], currentHigh, delta, isHome, isEnd)
|
|
2514
|
+
// 動けなかった押下で確定値を撃つと、変更駆動の消費側が無意味な再取得を行う
|
|
2515
|
+
if (nextIdx === findNearestDateIndex(sortedMacroAllowedDates, currentLow, macroUnit)) return
|
|
2516
|
+
const nextLow = sortedMacroAllowedDates[nextIdx]
|
|
2517
|
+
notifyMacroRange(nextLow, currentHigh, true)
|
|
2518
|
+
containMicroRangeIntoMacroWindow(nextLow, currentHigh)
|
|
2334
2519
|
return
|
|
2335
2520
|
}
|
|
2336
2521
|
let next: number
|
|
2337
2522
|
if (isHome) next = vernierMacroMinEnc
|
|
2338
2523
|
else if (isEnd) next = vernierMacroHighEnc
|
|
2339
2524
|
else next = Math.max(vernierMacroMinEnc, Math.min(vernierMacroHighEnc, vernierMacroLowEnc + delta))
|
|
2340
|
-
|
|
2525
|
+
if (next === vernierMacroLowEnc) return
|
|
2526
|
+
const nextLow = decode(macroUnit, next)
|
|
2527
|
+
notifyMacroRange(nextLow, currentHigh, true)
|
|
2528
|
+
containMicroRangeIntoMacroWindow(nextLow, currentHigh)
|
|
2341
2529
|
} else if (handle === "macro-high") {
|
|
2342
2530
|
const currentLow = decode(macroUnit, vernierMacroLowEnc)
|
|
2343
2531
|
const currentHigh = decode(macroUnit, vernierMacroHighEnc)
|
|
2344
2532
|
if (macroIsDiscreteScale) {
|
|
2345
|
-
|
|
2533
|
+
const nextIdx = stepDiscreteIndex(sortedMacroAllowedDates, macroUnit, currentHigh, currentLow, sortedMacroAllowedDates[sortedMacroAllowedDates.length - 1], delta, isHome, isEnd)
|
|
2534
|
+
if (nextIdx === findNearestDateIndex(sortedMacroAllowedDates, currentHigh, macroUnit)) return
|
|
2535
|
+
const nextHigh = sortedMacroAllowedDates[nextIdx]
|
|
2536
|
+
notifyMacroRange(currentLow, nextHigh, true)
|
|
2537
|
+
containMicroRangeIntoMacroWindow(currentLow, nextHigh)
|
|
2346
2538
|
return
|
|
2347
2539
|
}
|
|
2348
2540
|
let next: number
|
|
2349
2541
|
if (isHome) next = vernierMacroLowEnc
|
|
2350
2542
|
else if (isEnd) next = vernierMacroMaxEnc
|
|
2351
2543
|
else next = Math.max(vernierMacroLowEnc, Math.min(vernierMacroMaxEnc, vernierMacroHighEnc + delta))
|
|
2352
|
-
|
|
2544
|
+
if (next === vernierMacroHighEnc) return
|
|
2545
|
+
const nextHigh = decode(macroUnit, next)
|
|
2546
|
+
notifyMacroRange(currentLow, nextHigh, true)
|
|
2547
|
+
containMicroRangeIntoMacroWindow(currentLow, nextHigh)
|
|
2353
2548
|
} else if (handle === "micro-low") {
|
|
2354
2549
|
const currentLow = decode(microUnit, vernierMicroLowEnc)
|
|
2355
2550
|
const currentHigh = decode(microUnit, vernierMicroHighEnc)
|
|
2356
2551
|
if (microIsDiscreteScale) {
|
|
2357
|
-
|
|
2552
|
+
const nextIdx = stepDiscreteIndex(sortedMicroAllowedDates, microUnit, currentLow, sortedMicroAllowedDates[0], currentHigh, delta, isHome, isEnd)
|
|
2553
|
+
if (nextIdx === findNearestDateIndex(sortedMicroAllowedDates, currentLow, microUnit)) return
|
|
2554
|
+
notifyMicroRange(sortedMicroAllowedDates[nextIdx], currentHigh, true)
|
|
2358
2555
|
return
|
|
2359
2556
|
}
|
|
2360
2557
|
let next: number
|
|
2361
2558
|
if (isHome) next = vernierMicroMinEnc
|
|
2362
2559
|
else if (isEnd) next = vernierMicroHighEnc
|
|
2363
2560
|
else next = Math.max(vernierMicroMinEnc, Math.min(vernierMicroHighEnc, vernierMicroLowEnc + delta))
|
|
2561
|
+
if (next === vernierMicroLowEnc) return
|
|
2364
2562
|
notifyMicroRange(decode(microUnit, next), currentHigh, true)
|
|
2365
2563
|
} else if (handle === "micro-high") {
|
|
2366
2564
|
const currentLow = decode(microUnit, vernierMicroLowEnc)
|
|
2367
2565
|
const currentHigh = decode(microUnit, vernierMicroHighEnc)
|
|
2368
2566
|
if (microIsDiscreteScale) {
|
|
2369
|
-
|
|
2567
|
+
const nextIdx = stepDiscreteIndex(sortedMicroAllowedDates, microUnit, currentHigh, currentLow, sortedMicroAllowedDates[sortedMicroAllowedDates.length - 1], delta, isHome, isEnd)
|
|
2568
|
+
if (nextIdx === findNearestDateIndex(sortedMicroAllowedDates, currentHigh, microUnit)) return
|
|
2569
|
+
notifyMicroRange(currentLow, sortedMicroAllowedDates[nextIdx], true)
|
|
2370
2570
|
return
|
|
2371
2571
|
}
|
|
2372
2572
|
let next: number
|
|
2373
2573
|
if (isHome) next = vernierMicroLowEnc
|
|
2374
2574
|
else if (isEnd) next = vernierMicroMaxEnc
|
|
2375
2575
|
else next = Math.max(vernierMicroLowEnc, Math.min(vernierMicroMaxEnc, vernierMicroHighEnc + delta))
|
|
2576
|
+
if (next === vernierMicroHighEnc) return
|
|
2376
2577
|
notifyMicroRange(currentLow, decode(microUnit, next), true)
|
|
2377
2578
|
}
|
|
2378
2579
|
}
|
|
@@ -2389,6 +2590,26 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2389
2590
|
}
|
|
2390
2591
|
notifyChange(nextVal, nextVal, true)
|
|
2391
2592
|
} else if (p.mode === "vernier") {
|
|
2593
|
+
// 離散指定時はポインター操作・キーボード操作と同じ候補集合の上を移動しないと、ステッパーだけが候補外の日付を発火する
|
|
2594
|
+
if (microIsDiscreteScale) {
|
|
2595
|
+
const maxIdx = sortedMicroAllowedDates.length - 1
|
|
2596
|
+
const curLowIdx = findNearestDateIndex(sortedMicroAllowedDates, vernierMicroLowDate, microUnit)
|
|
2597
|
+
const curHighIdx = findNearestDateIndex(sortedMicroAllowedDates, vernierMicroHighDate, microUnit)
|
|
2598
|
+
const idxSpan = curHighIdx - curLowIdx
|
|
2599
|
+
let nextLowIdx = curLowIdx + delta
|
|
2600
|
+
let nextHighIdx = curHighIdx + delta
|
|
2601
|
+
if (delta < 0 && nextLowIdx < 0) {
|
|
2602
|
+
nextLowIdx = 0
|
|
2603
|
+
nextHighIdx = Math.min(maxIdx, idxSpan)
|
|
2604
|
+
} else if (delta > 0 && nextHighIdx > maxIdx) {
|
|
2605
|
+
nextHighIdx = maxIdx
|
|
2606
|
+
nextLowIdx = Math.max(0, maxIdx - idxSpan)
|
|
2607
|
+
}
|
|
2608
|
+
if (nextLowIdx !== curLowIdx || nextHighIdx !== curHighIdx) {
|
|
2609
|
+
notifyMicroRange(sortedMicroAllowedDates[nextLowIdx], sortedMicroAllowedDates[nextHighIdx], true)
|
|
2610
|
+
}
|
|
2611
|
+
return
|
|
2612
|
+
}
|
|
2392
2613
|
const curLowEnc = vernierMicroLowEnc
|
|
2393
2614
|
const curHighEnc = vernierMicroHighEnc
|
|
2394
2615
|
const minEnc = vernierMicroMinEnc
|
|
@@ -2425,7 +2646,24 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2425
2646
|
}
|
|
2426
2647
|
}
|
|
2427
2648
|
},
|
|
2428
|
-
[
|
|
2649
|
+
[
|
|
2650
|
+
currentLowVal,
|
|
2651
|
+
currentHighVal,
|
|
2652
|
+
rangeMin,
|
|
2653
|
+
rangeMax,
|
|
2654
|
+
isControlled,
|
|
2655
|
+
notifyChange,
|
|
2656
|
+
notifyMicroRange,
|
|
2657
|
+
vernierMicroLowEnc,
|
|
2658
|
+
vernierMicroHighEnc,
|
|
2659
|
+
vernierMicroMinEnc,
|
|
2660
|
+
vernierMicroMaxEnc,
|
|
2661
|
+
microUnit,
|
|
2662
|
+
microIsDiscreteScale,
|
|
2663
|
+
sortedMicroAllowedDates,
|
|
2664
|
+
vernierMicroLowDate,
|
|
2665
|
+
vernierMicroHighDate,
|
|
2666
|
+
],
|
|
2429
2667
|
)
|
|
2430
2668
|
|
|
2431
2669
|
// ------------------------------------------------------------------
|
|
@@ -2521,8 +2759,12 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2521
2759
|
|
|
2522
2760
|
const hoverDate = hoverValue !== null ? valueToDate(hoverValue) : null
|
|
2523
2761
|
|
|
2524
|
-
|
|
2525
|
-
const
|
|
2762
|
+
// 離散ミクロでは先頭・末尾の候補が可動端。生の窓境界で判定すると、末尾候補を越えて候補外の日付を歩き続ける
|
|
2763
|
+
const microStepFloorEnc = microIsDiscreteScale ? encode(microUnit, sortedMicroAllowedDates[0]) : vernierMicroMinEnc
|
|
2764
|
+
const microStepCeilEnc = microIsDiscreteScale ? encode(microUnit, sortedMicroAllowedDates[sortedMicroAllowedDates.length - 1]) : vernierMicroMaxEnc
|
|
2765
|
+
|
|
2766
|
+
const stepperDecreaseDisabled = disabled || (isVernierMode ? vernierMicroLowEnc <= microStepFloorEnc : isPointMode ? currentLowVal <= rangeMin : currentLowVal <= rangeMin && currentHighVal <= rangeMin)
|
|
2767
|
+
const stepperIncreaseDisabled = disabled || (isVernierMode ? vernierMicroHighEnc >= microStepCeilEnc : isPointMode ? currentHighVal >= rangeMax : currentLowVal >= rangeMax && currentHighVal >= rangeMax)
|
|
2526
2768
|
|
|
2527
2769
|
const cursorClass = disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer"
|
|
2528
2770
|
|
|
@@ -2603,38 +2845,42 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2603
2845
|
))}
|
|
2604
2846
|
|
|
2605
2847
|
{/* マクロ選択帯 & ミクロ選択帯 (ノギス時は半円つまみの直径16pxを完全に埋める長さに拡張) */}
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2848
|
+
{!hideConnectBar && (
|
|
2849
|
+
<>
|
|
2850
|
+
<div
|
|
2851
|
+
data-testid="period-slider-connect-macro"
|
|
2852
|
+
className="period-slider-connect-macro"
|
|
2853
|
+
style={
|
|
2854
|
+
isVertical
|
|
2855
|
+
? {
|
|
2856
|
+
bottom: `calc(${macroLowRatio * 100}% - 8px)`,
|
|
2857
|
+
height: `calc(${Math.max(0, (macroHighRatio - macroLowRatio) * 100)}% + 16px)`,
|
|
2858
|
+
}
|
|
2859
|
+
: {
|
|
2860
|
+
left: `calc(${macroLowRatio * 100}% - 8px)`,
|
|
2861
|
+
width: `calc(${Math.max(0, (macroHighRatio - macroLowRatio) * 100)}% + 16px)`,
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2864
|
+
onPointerDown={handleVernierKnobPointerDown("macro-connect")}
|
|
2865
|
+
/>
|
|
2866
|
+
<div
|
|
2867
|
+
data-testid="period-slider-connect-micro"
|
|
2868
|
+
className="period-slider-connect-micro"
|
|
2869
|
+
style={
|
|
2870
|
+
isVertical
|
|
2871
|
+
? {
|
|
2872
|
+
bottom: `calc(${microLowRatio * 100}% - 8px)`,
|
|
2873
|
+
height: `calc(${Math.max(0, (microHighRatio - microLowRatio) * 100)}% + 16px)`,
|
|
2874
|
+
}
|
|
2875
|
+
: {
|
|
2876
|
+
left: `calc(${microLowRatio * 100}% - 8px)`,
|
|
2877
|
+
width: `calc(${Math.max(0, (microHighRatio - microLowRatio) * 100)}% + 16px)`,
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
onPointerDown={handleVernierKnobPointerDown("micro-connect")}
|
|
2881
|
+
/>
|
|
2882
|
+
</>
|
|
2883
|
+
)}
|
|
2638
2884
|
|
|
2639
2885
|
{/* アダプティブ目盛線 (Ticks) */}
|
|
2640
2886
|
{showVernierTicks && (
|
|
@@ -2693,7 +2939,13 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2693
2939
|
data-handle-type="macro-low">
|
|
2694
2940
|
<VernierKnobSvg type="macro" isTop={isMacroFirstRail} isVertical={isVertical} isLeft={isMacroFirstRail} />
|
|
2695
2941
|
{showHairline && <div className="period-slider-hairline" />}
|
|
2696
|
-
|
|
2942
|
+
{tooltipStyle !== "hover" && (
|
|
2943
|
+
<div
|
|
2944
|
+
className={`period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800 ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
|
|
2945
|
+
data-tooltip-style={tooltipStyle}>
|
|
2946
|
+
{formatLabel(macroUnit, props.macroRange[0], formatMacroLabel, locale)}
|
|
2947
|
+
</div>
|
|
2948
|
+
)}
|
|
2697
2949
|
</div>
|
|
2698
2950
|
|
|
2699
2951
|
{/* マクロ上限ハンドル (上半円爪 / 左半円爪) */}
|
|
@@ -2741,7 +2993,13 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2741
2993
|
data-handle-type="macro-high">
|
|
2742
2994
|
<VernierKnobSvg type="macro" isTop={isMacroFirstRail} isVertical={isVertical} isLeft={isMacroFirstRail} />
|
|
2743
2995
|
{showHairline && <div className="period-slider-hairline" />}
|
|
2744
|
-
|
|
2996
|
+
{tooltipStyle !== "hover" && (
|
|
2997
|
+
<div
|
|
2998
|
+
className={`period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800 ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
|
|
2999
|
+
data-tooltip-style={tooltipStyle}>
|
|
3000
|
+
{formatLabel(macroUnit, props.macroRange[1], formatMacroLabel, locale)}
|
|
3001
|
+
</div>
|
|
3002
|
+
)}
|
|
2745
3003
|
</div>
|
|
2746
3004
|
|
|
2747
3005
|
{/* ミクロ下限ハンドル (下半円爪 / 右半円爪) */}
|
|
@@ -2789,7 +3047,13 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2789
3047
|
data-handle-type="micro-low">
|
|
2790
3048
|
<VernierKnobSvg type="micro" isTop={!isMacroFirstRail} isVertical={isVertical} isLeft={!isMacroFirstRail} />
|
|
2791
3049
|
{showHairline && <div className="period-slider-hairline" />}
|
|
2792
|
-
|
|
3050
|
+
{tooltipStyle !== "hover" && (
|
|
3051
|
+
<div
|
|
3052
|
+
className={`period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800 ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
|
|
3053
|
+
data-tooltip-style={tooltipStyle}>
|
|
3054
|
+
{formatLabel(microUnit, vernierMicroLowDate, formatMicroLabel, locale)}
|
|
3055
|
+
</div>
|
|
3056
|
+
)}
|
|
2793
3057
|
</div>
|
|
2794
3058
|
|
|
2795
3059
|
{/* ミクロ上限ハンドル (下半円爪 / 右半円爪) */}
|
|
@@ -2837,7 +3101,13 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2837
3101
|
data-handle-type="micro-high">
|
|
2838
3102
|
<VernierKnobSvg type="micro" isTop={!isMacroFirstRail} isVertical={isVertical} isLeft={!isMacroFirstRail} />
|
|
2839
3103
|
{showHairline && <div className="period-slider-hairline" />}
|
|
2840
|
-
|
|
3104
|
+
{tooltipStyle !== "hover" && (
|
|
3105
|
+
<div
|
|
3106
|
+
className={`period-slider-tooltip absolute whitespace-nowrap rounded bg-slate-900 px-2 py-0.5 font-medium text-white text-xs shadow-md dark:bg-slate-800 ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
|
|
3107
|
+
data-tooltip-style={tooltipStyle}>
|
|
3108
|
+
{formatLabel(microUnit, vernierMicroHighDate, formatMicroLabel, locale)}
|
|
3109
|
+
</div>
|
|
3110
|
+
)}
|
|
2841
3111
|
</div>
|
|
2842
3112
|
</>
|
|
2843
3113
|
) : (
|