@waveform-playlist/ui-components 15.0.0-next.13 → 15.0.0-next.15
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/index.d.mts +15 -4
- package/dist/index.d.ts +15 -4
- package/dist/index.js +60 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -515,13 +515,21 @@ declare const TimescaleLoopRegion: react__default.FC<TimescaleLoopRegionProps>;
|
|
|
515
515
|
*/
|
|
516
516
|
type TimeFormat = 'seconds' | 'thousandths' | 'hh:mm:ss' | 'hh:mm:ss.u' | 'hh:mm:ss.uu' | 'hh:mm:ss.uuu';
|
|
517
517
|
/**
|
|
518
|
-
* Format seconds according to the specified format
|
|
518
|
+
* Format seconds according to the specified format. A negative, `NaN` or
|
|
519
|
+
* infinite time prints as 0.
|
|
519
520
|
*/
|
|
520
521
|
declare function formatTime(seconds: number, format: TimeFormat): string;
|
|
521
522
|
/**
|
|
522
|
-
* Parse a
|
|
523
|
+
* Parse text typed for a time back to seconds, or `null` when it is not a
|
|
524
|
+
* time: empty text, a negative number, letters, a number followed by
|
|
525
|
+
* anything else, a number too large to be finite, or a value that is not a
|
|
526
|
+
* string. Spaces around the text are ignored.
|
|
527
|
+
*
|
|
528
|
+
* The numeric formats (`seconds`, `thousandths`) read a plain number. The
|
|
529
|
+
* clock formats also read the shorter forms `1.5` (seconds) and `1:30`
|
|
530
|
+
* (minutes and seconds) besides `01:02:03.5`.
|
|
523
531
|
*/
|
|
524
|
-
declare function parseTime(timeStr: string, format: TimeFormat): number;
|
|
532
|
+
declare function parseTime(timeStr: string, format: TimeFormat): number | null;
|
|
525
533
|
|
|
526
534
|
interface SelectionTimeInputsProps {
|
|
527
535
|
selectionStart: number;
|
|
@@ -684,7 +692,10 @@ interface TimeInputProps {
|
|
|
684
692
|
*
|
|
685
693
|
* Uses BaseInput for consistent theming. Displays time in the specified
|
|
686
694
|
* format and parses user input on blur. `onChange` fires only when the text
|
|
687
|
-
* was edited, so moving focus through the input never rounds the value
|
|
695
|
+
* was edited, so moving focus through the input never rounds the value, and
|
|
696
|
+
* only when the text is a time (`parseTime`): text it cannot read is dropped
|
|
697
|
+
* and the input shows `value` again. In the clock formats `1.5` and `1:30`
|
|
698
|
+
* are read as well as `00:01:30`.
|
|
688
699
|
*/
|
|
689
700
|
declare const TimeInput: react__default.FC<TimeInputProps>;
|
|
690
701
|
|
package/dist/index.d.ts
CHANGED
|
@@ -515,13 +515,21 @@ declare const TimescaleLoopRegion: react__default.FC<TimescaleLoopRegionProps>;
|
|
|
515
515
|
*/
|
|
516
516
|
type TimeFormat = 'seconds' | 'thousandths' | 'hh:mm:ss' | 'hh:mm:ss.u' | 'hh:mm:ss.uu' | 'hh:mm:ss.uuu';
|
|
517
517
|
/**
|
|
518
|
-
* Format seconds according to the specified format
|
|
518
|
+
* Format seconds according to the specified format. A negative, `NaN` or
|
|
519
|
+
* infinite time prints as 0.
|
|
519
520
|
*/
|
|
520
521
|
declare function formatTime(seconds: number, format: TimeFormat): string;
|
|
521
522
|
/**
|
|
522
|
-
* Parse a
|
|
523
|
+
* Parse text typed for a time back to seconds, or `null` when it is not a
|
|
524
|
+
* time: empty text, a negative number, letters, a number followed by
|
|
525
|
+
* anything else, a number too large to be finite, or a value that is not a
|
|
526
|
+
* string. Spaces around the text are ignored.
|
|
527
|
+
*
|
|
528
|
+
* The numeric formats (`seconds`, `thousandths`) read a plain number. The
|
|
529
|
+
* clock formats also read the shorter forms `1.5` (seconds) and `1:30`
|
|
530
|
+
* (minutes and seconds) besides `01:02:03.5`.
|
|
523
531
|
*/
|
|
524
|
-
declare function parseTime(timeStr: string, format: TimeFormat): number;
|
|
532
|
+
declare function parseTime(timeStr: string, format: TimeFormat): number | null;
|
|
525
533
|
|
|
526
534
|
interface SelectionTimeInputsProps {
|
|
527
535
|
selectionStart: number;
|
|
@@ -684,7 +692,10 @@ interface TimeInputProps {
|
|
|
684
692
|
*
|
|
685
693
|
* Uses BaseInput for consistent theming. Displays time in the specified
|
|
686
694
|
* format and parses user input on blur. `onChange` fires only when the text
|
|
687
|
-
* was edited, so moving focus through the input never rounds the value
|
|
695
|
+
* was edited, so moving focus through the input never rounds the value, and
|
|
696
|
+
* only when the text is a time (`parseTime`): text it cannot read is dropped
|
|
697
|
+
* and the input shows `value` again. In the clock formats `1.5` and `1:30`
|
|
698
|
+
* are read as well as `00:01:30`.
|
|
688
699
|
*/
|
|
689
700
|
declare const TimeInput: react__default.FC<TimeInputProps>;
|
|
690
701
|
|
package/dist/index.js
CHANGED
|
@@ -2226,49 +2226,84 @@ var import_react20 = require("react");
|
|
|
2226
2226
|
var import_react19 = require("react");
|
|
2227
2227
|
|
|
2228
2228
|
// src/utils/timeFormat.ts
|
|
2229
|
+
function printable(seconds) {
|
|
2230
|
+
return Number.isFinite(seconds) && seconds > 0 ? seconds : 0;
|
|
2231
|
+
}
|
|
2232
|
+
function digits(whole) {
|
|
2233
|
+
return whole < 1e21 ? String(whole) : whole.toLocaleString("en-US", { useGrouping: false });
|
|
2234
|
+
}
|
|
2235
|
+
function fixed(n, decimals) {
|
|
2236
|
+
return n < 1e21 ? n.toFixed(decimals) : n.toLocaleString("en-US", {
|
|
2237
|
+
useGrouping: false,
|
|
2238
|
+
minimumFractionDigits: decimals,
|
|
2239
|
+
maximumFractionDigits: decimals
|
|
2240
|
+
});
|
|
2241
|
+
}
|
|
2229
2242
|
function clockFormat(seconds, decimals) {
|
|
2230
|
-
const
|
|
2231
|
-
const
|
|
2232
|
-
const
|
|
2233
|
-
|
|
2243
|
+
const remainder = seconds % 60;
|
|
2244
|
+
const rounded = remainder.toFixed(decimals);
|
|
2245
|
+
const carry = Number(rounded) >= 60;
|
|
2246
|
+
const totalMinutes = Math.round((seconds - remainder) / 60) + (carry ? 1 : 0);
|
|
2247
|
+
const secs = (carry ? 0 .toFixed(decimals) : rounded).padStart(
|
|
2248
|
+
decimals > 0 ? decimals + 3 : 2,
|
|
2249
|
+
"0"
|
|
2250
|
+
);
|
|
2251
|
+
return digits(Math.floor(totalMinutes / 60)).padStart(2, "0") + ":" + String(totalMinutes % 60).padStart(2, "0") + ":" + secs;
|
|
2234
2252
|
}
|
|
2235
2253
|
function formatTime(seconds, format) {
|
|
2254
|
+
const safe = printable(seconds);
|
|
2236
2255
|
switch (format) {
|
|
2237
2256
|
case "seconds":
|
|
2238
|
-
return
|
|
2257
|
+
return fixed(safe, 0);
|
|
2239
2258
|
case "thousandths":
|
|
2240
|
-
return
|
|
2259
|
+
return fixed(safe, 3);
|
|
2241
2260
|
case "hh:mm:ss":
|
|
2242
|
-
return clockFormat(
|
|
2261
|
+
return clockFormat(safe, 0);
|
|
2243
2262
|
case "hh:mm:ss.u":
|
|
2244
|
-
return clockFormat(
|
|
2263
|
+
return clockFormat(safe, 1);
|
|
2245
2264
|
case "hh:mm:ss.uu":
|
|
2246
|
-
return clockFormat(
|
|
2265
|
+
return clockFormat(safe, 2);
|
|
2247
2266
|
case "hh:mm:ss.uuu":
|
|
2248
|
-
return clockFormat(
|
|
2267
|
+
return clockFormat(safe, 3);
|
|
2249
2268
|
default:
|
|
2250
|
-
return clockFormat(
|
|
2269
|
+
return clockFormat(safe, 3);
|
|
2251
2270
|
}
|
|
2252
2271
|
}
|
|
2272
|
+
var DECIMAL = /^(\d+(\.\d*)?|\.\d+)$/;
|
|
2273
|
+
var WHOLE = /^\d+$/;
|
|
2274
|
+
var SECONDS_PER_UNIT = [3600, 60, 1];
|
|
2275
|
+
function parseNumber(text) {
|
|
2276
|
+
if (!DECIMAL.test(text)) return null;
|
|
2277
|
+
const value = Number(text);
|
|
2278
|
+
return Number.isFinite(value) ? value : null;
|
|
2279
|
+
}
|
|
2280
|
+
function parseClock(text) {
|
|
2281
|
+
const parts = text.split(":");
|
|
2282
|
+
if (parts.length > 3) return null;
|
|
2283
|
+
const units = SECONDS_PER_UNIT.slice(3 - parts.length);
|
|
2284
|
+
let total = 0;
|
|
2285
|
+
for (let i = 0; i < parts.length; i++) {
|
|
2286
|
+
const isLast = i === parts.length - 1;
|
|
2287
|
+
if (!(isLast ? DECIMAL : WHOLE).test(parts[i])) return null;
|
|
2288
|
+
const value = Number(parts[i]);
|
|
2289
|
+
if (i > 0 && value >= 60) return null;
|
|
2290
|
+
total += value * units[i];
|
|
2291
|
+
}
|
|
2292
|
+
return Number.isFinite(total) ? total : null;
|
|
2293
|
+
}
|
|
2253
2294
|
function parseTime(timeStr, format) {
|
|
2254
|
-
if (
|
|
2295
|
+
if (typeof timeStr !== "string") return null;
|
|
2296
|
+
const text = timeStr.trim();
|
|
2255
2297
|
switch (format) {
|
|
2256
2298
|
case "seconds":
|
|
2257
2299
|
case "thousandths":
|
|
2258
|
-
return
|
|
2300
|
+
return parseNumber(text);
|
|
2259
2301
|
case "hh:mm:ss":
|
|
2260
2302
|
case "hh:mm:ss.u":
|
|
2261
2303
|
case "hh:mm:ss.uu":
|
|
2262
|
-
case "hh:mm:ss.uuu":
|
|
2263
|
-
const parts = timeStr.split(":");
|
|
2264
|
-
if (parts.length !== 3) return 0;
|
|
2265
|
-
const hours = parseInt(parts[0], 10) || 0;
|
|
2266
|
-
const minutes = parseInt(parts[1], 10) || 0;
|
|
2267
|
-
const seconds = parseFloat(parts[2]) || 0;
|
|
2268
|
-
return hours * 3600 + minutes * 60 + seconds;
|
|
2269
|
-
}
|
|
2304
|
+
case "hh:mm:ss.uuu":
|
|
2270
2305
|
default:
|
|
2271
|
-
return
|
|
2306
|
+
return parseClock(text);
|
|
2272
2307
|
}
|
|
2273
2308
|
}
|
|
2274
2309
|
|
|
@@ -2293,7 +2328,9 @@ var TimeInput = ({
|
|
|
2293
2328
|
if (draft === null) return;
|
|
2294
2329
|
setDraft(null);
|
|
2295
2330
|
if (activeDraft === null) return;
|
|
2296
|
-
|
|
2331
|
+
const parsed = parseTime(activeDraft.text, format);
|
|
2332
|
+
if (parsed === null) return;
|
|
2333
|
+
onChange?.(parsed);
|
|
2297
2334
|
};
|
|
2298
2335
|
const handleKeyDown = (e) => {
|
|
2299
2336
|
if (e.key === "Enter") {
|