|
|
|
|
@ -15,9 +15,9 @@ import type {
|
|
|
|
|
import type { TimeRangeEndpoint } from './types';
|
|
|
|
|
|
|
|
|
|
import { timeRangePickerMorfo } from '../../../morfo/components/time-range-picker';
|
|
|
|
|
import type { SomaRuntime, SomaRuntimePart } from '../../runtime.svelte';
|
|
|
|
|
|
|
|
|
|
const attrs = createAttrs(timeRangePickerMorfo);
|
|
|
|
|
import type { SomaRuntimePart } from '../../runtime.svelte';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface TimeRangePickerOpts
|
|
|
|
|
@ -62,6 +62,8 @@ export interface TimeRangePickerOpts
|
|
|
|
|
export class TimeRangePickerProvider {
|
|
|
|
|
readonly opts: TimeRangePickerOpts;
|
|
|
|
|
readonly runtimePart: SomaRuntimePart;
|
|
|
|
|
readonly soma: Soma;
|
|
|
|
|
readonly runtime: SomaRuntime;
|
|
|
|
|
static readonly ctx = context<TimeRangePickerProvider>('TimeRangePicker');
|
|
|
|
|
static get(): TimeRangePickerProvider | undefined {
|
|
|
|
|
return this.ctx.getOr(undefined) as TimeRangePickerProvider | undefined;
|
|
|
|
|
@ -73,27 +75,25 @@ export class TimeRangePickerProvider {
|
|
|
|
|
return new TimeRangePickerProvider(opts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
readonly soma = Soma.get();
|
|
|
|
|
|
|
|
|
|
private constructor(opts: TimeRangePickerOpts) {
|
|
|
|
|
this.opts = opts;
|
|
|
|
|
this.runtimePart = Soma.require()
|
|
|
|
|
.runtime(timeRangePickerMorfo, {})
|
|
|
|
|
.part('provider', {
|
|
|
|
|
id: opts.id,
|
|
|
|
|
ref: opts.ref,
|
|
|
|
|
owner: this,
|
|
|
|
|
context: TimeRangePickerProvider.ctx
|
|
|
|
|
});
|
|
|
|
|
this.soma = Soma.require();
|
|
|
|
|
this.runtime = this.soma.runtime(timeRangePickerMorfo, {});
|
|
|
|
|
this.runtimePart = this.runtime.part('provider', {
|
|
|
|
|
id: opts.id,
|
|
|
|
|
ref: opts.ref,
|
|
|
|
|
owner: this,
|
|
|
|
|
context: TimeRangePickerProvider.ctx
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Resolved hour cycle — same rule as TimeField/TimePicker. */
|
|
|
|
|
readonly resolvedHourCycle: HourCycle = $derived.by(() => {
|
|
|
|
|
const explicit = this.opts.hourCycle.current;
|
|
|
|
|
if (explicit === 12 || explicit === 24) return explicit;
|
|
|
|
|
const fromService = this.soma?.dates?.getHourCycle?.();
|
|
|
|
|
const fromService = this.soma.dates?.getHourCycle?.();
|
|
|
|
|
if (fromService === 12 || fromService === 24) return fromService;
|
|
|
|
|
const locale = this.opts.locale.current || this.soma?.langs.getLocale() || 'en';
|
|
|
|
|
const locale = this.opts.locale.current || this.soma.langs.getLocale() || 'en';
|
|
|
|
|
return new Intl.DateTimeFormat(locale, { hour: 'numeric' }).resolvedOptions().hour12 ? 12 : 24;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|