@nervure/datetime 0.0.0-stage → 0.2.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 +28 -0
- package/LICENSE +21 -0
- package/README.md +79 -2
- package/cdn/nervure-datetime.min.js +74 -0
- package/dist/calendar.d.ts +51 -0
- package/dist/calendar.js +125 -0
- package/dist/cdn.d.ts +1 -0
- package/dist/cdn.js +13 -0
- package/dist/core.d.ts +15 -0
- package/dist/core.js +876 -0
- package/dist/element.d.ts +35 -0
- package/dist/element.js +176 -0
- package/dist/i18n.d.ts +43 -0
- package/dist/i18n.js +130 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/model.d.ts +41 -0
- package/dist/model.js +280 -0
- package/dist/react.d.ts +19 -0
- package/dist/react.js +45 -0
- package/dist/style.css +71 -0
- package/dist/styles.d.ts +1 -0
- package/dist/styles.js +74 -0
- package/dist/types.d.ts +128 -0
- package/dist/types.js +1 -0
- package/dist/vue.d.ts +72 -0
- package/dist/vue.js +49 -0
- package/dist/zone.d.ts +22 -0
- package/dist/zone.js +81 -0
- package/package.json +102 -4
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PickerOptions, PickerValue, Selection } from './types.ts';
|
|
2
|
+
declare const Base: typeof HTMLElement;
|
|
3
|
+
/**
|
|
4
|
+
* `<nv-datetime mode="range" presets locale="fr" zone="Europe/Paris" name="period">`.
|
|
5
|
+
* Draws a text field with its panel, or the calendar itself with `inline`. Light DOM: the CSS of the page applies.
|
|
6
|
+
* `change` fires with the selection in `event.detail`; `value` reads and sets the ISO value.
|
|
7
|
+
*/
|
|
8
|
+
export declare class NvDateTime extends Base {
|
|
9
|
+
static readonly observedAttributes: readonly ["mode", "value", "zone", "zones", "locale", "min", "max", "months", "time", "seconds", "minute-step", "hour12", "first-day", "week-numbers", "presets", "granularity", "granularities", "compare", "orientation", "inline", "placeholder", "accent", "theme", "name", "disabled"];
|
|
10
|
+
private picker;
|
|
11
|
+
private extra;
|
|
12
|
+
connectedCallback(): void;
|
|
13
|
+
disconnectedCallback(): void;
|
|
14
|
+
attributeChangedCallback(name: string, before: string | null, after: string | null): void;
|
|
15
|
+
/** The ISO value: a text, a list (`multiple`) or `{ start, end }` (`range`). */
|
|
16
|
+
get value(): PickerValue;
|
|
17
|
+
set value(value: PickerValue | Date);
|
|
18
|
+
/** The value, its two instants, its zone and its text. */
|
|
19
|
+
get selection(): Selection | null;
|
|
20
|
+
/** Options an attribute cannot carry: `disable` as a function, `format`, `labels`, your own periods. */
|
|
21
|
+
set options(options: PickerOptions);
|
|
22
|
+
open(): void;
|
|
23
|
+
close(): void;
|
|
24
|
+
private parse;
|
|
25
|
+
private read;
|
|
26
|
+
private render;
|
|
27
|
+
}
|
|
28
|
+
/** Registers `<nv-datetime>` (or another tag name), once. */
|
|
29
|
+
export declare function defineDateTimeElement(tag?: string): void;
|
|
30
|
+
declare global {
|
|
31
|
+
interface HTMLElementTagNameMap {
|
|
32
|
+
'nv-datetime': NvDateTime;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export {};
|
package/dist/element.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { createDatePicker } from "./core.js";
|
|
2
|
+
const ATTRS = [
|
|
3
|
+
'mode',
|
|
4
|
+
'value',
|
|
5
|
+
'zone',
|
|
6
|
+
'zones',
|
|
7
|
+
'locale',
|
|
8
|
+
'min',
|
|
9
|
+
'max',
|
|
10
|
+
'months',
|
|
11
|
+
'time',
|
|
12
|
+
'seconds',
|
|
13
|
+
'minute-step',
|
|
14
|
+
'hour12',
|
|
15
|
+
'first-day',
|
|
16
|
+
'week-numbers',
|
|
17
|
+
'presets',
|
|
18
|
+
'granularity',
|
|
19
|
+
'granularities',
|
|
20
|
+
'compare',
|
|
21
|
+
'orientation',
|
|
22
|
+
'inline',
|
|
23
|
+
'placeholder',
|
|
24
|
+
'accent',
|
|
25
|
+
'theme',
|
|
26
|
+
'name',
|
|
27
|
+
'disabled',
|
|
28
|
+
];
|
|
29
|
+
// On the server there is no HTMLElement: the class is defined but never registered.
|
|
30
|
+
const Base = typeof HTMLElement === 'undefined' ? Object : HTMLElement;
|
|
31
|
+
/**
|
|
32
|
+
* `<nv-datetime mode="range" presets locale="fr" zone="Europe/Paris" name="period">`.
|
|
33
|
+
* Draws a text field with its panel, or the calendar itself with `inline`. Light DOM: the CSS of the page applies.
|
|
34
|
+
* `change` fires with the selection in `event.detail`; `value` reads and sets the ISO value.
|
|
35
|
+
*/
|
|
36
|
+
export class NvDateTime extends Base {
|
|
37
|
+
static observedAttributes = ATTRS;
|
|
38
|
+
picker = null;
|
|
39
|
+
extra = {};
|
|
40
|
+
connectedCallback() {
|
|
41
|
+
this.render();
|
|
42
|
+
}
|
|
43
|
+
disconnectedCallback() {
|
|
44
|
+
this.picker?.destroy();
|
|
45
|
+
this.picker = null;
|
|
46
|
+
}
|
|
47
|
+
attributeChangedCallback(name, before, after) {
|
|
48
|
+
if (!this.isConnected || before === after)
|
|
49
|
+
return;
|
|
50
|
+
if (name === 'value')
|
|
51
|
+
this.picker?.setValue(this.parse(after));
|
|
52
|
+
else if (name === 'inline' || name === 'name' || name === 'disabled')
|
|
53
|
+
this.render();
|
|
54
|
+
else
|
|
55
|
+
this.picker?.update(this.read());
|
|
56
|
+
}
|
|
57
|
+
/** The ISO value: a text, a list (`multiple`) or `{ start, end }` (`range`). */
|
|
58
|
+
get value() {
|
|
59
|
+
return this.picker?.getValue() ?? null;
|
|
60
|
+
}
|
|
61
|
+
set value(value) {
|
|
62
|
+
this.picker?.setValue(value);
|
|
63
|
+
}
|
|
64
|
+
/** The value, its two instants, its zone and its text. */
|
|
65
|
+
get selection() {
|
|
66
|
+
return this.picker?.getSelection() ?? null;
|
|
67
|
+
}
|
|
68
|
+
/** Options an attribute cannot carry: `disable` as a function, `format`, `labels`, your own periods. */
|
|
69
|
+
set options(options) {
|
|
70
|
+
this.extra = options;
|
|
71
|
+
this.picker?.update({ ...this.read(), ...options });
|
|
72
|
+
}
|
|
73
|
+
open() {
|
|
74
|
+
this.picker?.open();
|
|
75
|
+
}
|
|
76
|
+
close() {
|
|
77
|
+
this.picker?.close();
|
|
78
|
+
}
|
|
79
|
+
parse(text) {
|
|
80
|
+
if (!text)
|
|
81
|
+
return null;
|
|
82
|
+
const t = text.trim();
|
|
83
|
+
if (t.startsWith('{') || t.startsWith('[')) {
|
|
84
|
+
try {
|
|
85
|
+
return JSON.parse(t);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// "2026-01-01/2026-03-31" for a range, "2026-01-01,2026-01-05" for several days
|
|
92
|
+
if (t.includes('/')) {
|
|
93
|
+
const [start, end] = t.split('/');
|
|
94
|
+
return { start: start, end: end };
|
|
95
|
+
}
|
|
96
|
+
return t.includes(',') ? t.split(',').map((s) => s.trim()) : t;
|
|
97
|
+
}
|
|
98
|
+
read() {
|
|
99
|
+
const get = (key) => this.getAttribute(key) ?? undefined;
|
|
100
|
+
const flag = (key) => this.hasAttribute(key) ? this.getAttribute(key) !== 'false' : undefined;
|
|
101
|
+
const number = (key) => this.hasAttribute(key) ? Number(this.getAttribute(key)) : undefined;
|
|
102
|
+
return {
|
|
103
|
+
mode: get('mode'),
|
|
104
|
+
zone: get('zone'),
|
|
105
|
+
zones: get('zones')
|
|
106
|
+
?.split(',')
|
|
107
|
+
.map((z) => z.trim())
|
|
108
|
+
.filter(Boolean),
|
|
109
|
+
locale: get('locale'),
|
|
110
|
+
min: get('min'),
|
|
111
|
+
max: get('max'),
|
|
112
|
+
months: number('months'),
|
|
113
|
+
time: flag('time'),
|
|
114
|
+
seconds: flag('seconds'),
|
|
115
|
+
minuteStep: number('minute-step'),
|
|
116
|
+
hour12: flag('hour12'),
|
|
117
|
+
firstDay: number('first-day'),
|
|
118
|
+
weekNumbers: flag('week-numbers'),
|
|
119
|
+
presets: flag('presets'),
|
|
120
|
+
granularity: get('granularity'),
|
|
121
|
+
granularities: get('granularities')
|
|
122
|
+
?.split(',')
|
|
123
|
+
.map((g) => g.trim())
|
|
124
|
+
.filter(Boolean),
|
|
125
|
+
// compare, compare="true": the reader chooses; compare="previousPeriod": fixed
|
|
126
|
+
compare: !this.hasAttribute('compare')
|
|
127
|
+
? undefined
|
|
128
|
+
: ['', 'true'].includes(get('compare') ?? '')
|
|
129
|
+
? true
|
|
130
|
+
: get('compare'),
|
|
131
|
+
orientation: get('orientation'),
|
|
132
|
+
inline: flag('inline'),
|
|
133
|
+
placeholder: get('placeholder'),
|
|
134
|
+
accent: get('accent'),
|
|
135
|
+
theme: get('theme'),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
render() {
|
|
139
|
+
const value = this.picker ? this.picker.getValue() : this.parse(this.getAttribute('value'));
|
|
140
|
+
this.picker?.destroy();
|
|
141
|
+
this.replaceChildren();
|
|
142
|
+
const inline = this.hasAttribute('inline') && this.getAttribute('inline') !== 'false';
|
|
143
|
+
let field = null;
|
|
144
|
+
if (!inline) {
|
|
145
|
+
const input = this.ownerDocument.createElement('input');
|
|
146
|
+
input.type = 'text';
|
|
147
|
+
input.className = 'nv-datetime-field';
|
|
148
|
+
const name = this.getAttribute('name');
|
|
149
|
+
if (name)
|
|
150
|
+
input.name = name;
|
|
151
|
+
input.disabled = this.hasAttribute('disabled');
|
|
152
|
+
const label = this.getAttribute('aria-label');
|
|
153
|
+
if (label)
|
|
154
|
+
input.setAttribute('aria-label', label);
|
|
155
|
+
this.append(input);
|
|
156
|
+
field = input;
|
|
157
|
+
}
|
|
158
|
+
this.picker = createDatePicker(field ?? this, {
|
|
159
|
+
...this.read(),
|
|
160
|
+
...this.extra,
|
|
161
|
+
value,
|
|
162
|
+
onChange: (selection) => {
|
|
163
|
+
this.extra.onChange?.(selection);
|
|
164
|
+
this.dispatchEvent(new CustomEvent('change', { detail: selection, bubbles: true }));
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** Registers `<nv-datetime>` (or another tag name), once. */
|
|
170
|
+
export function defineDateTimeElement(tag = 'nv-datetime') {
|
|
171
|
+
if (typeof customElements === 'undefined' || customElements.get(tag))
|
|
172
|
+
return;
|
|
173
|
+
customElements.define(tag, tag === 'nv-datetime' ? NvDateTime : class extends NvDateTime {
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
defineDateTimeElement();
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { PeriodName } from './calendar.ts';
|
|
2
|
+
export interface Labels {
|
|
3
|
+
today: string;
|
|
4
|
+
now: string;
|
|
5
|
+
clear: string;
|
|
6
|
+
apply: string;
|
|
7
|
+
cancel: string;
|
|
8
|
+
from: string;
|
|
9
|
+
to: string;
|
|
10
|
+
time: string;
|
|
11
|
+
/** Short word before a week number: "W" in "W49". */
|
|
12
|
+
week: string;
|
|
13
|
+
/** Short word before a quarter number: "Q" in "Q4", "T" in "T4". */
|
|
14
|
+
quarter: string;
|
|
15
|
+
previous: string;
|
|
16
|
+
next: string;
|
|
17
|
+
zone: string;
|
|
18
|
+
/** Tab of a free range in the period mode. */
|
|
19
|
+
custom: string;
|
|
20
|
+
compareTo: string;
|
|
21
|
+
previousYear: string;
|
|
22
|
+
previousPeriod: string;
|
|
23
|
+
none: string;
|
|
24
|
+
periods: Record<PeriodName, string>;
|
|
25
|
+
}
|
|
26
|
+
/** The languages the words of the picker are written in. Month and day names exist for every language of the platform. */
|
|
27
|
+
export declare const LANGUAGES: readonly string[];
|
|
28
|
+
/** The words of the picker for a locale, with the reader's own replacements. */
|
|
29
|
+
export declare function labelsFor(locale: string, custom?: Partial<Omit<Labels, 'periods'>> & {
|
|
30
|
+
periods?: Partial<Labels['periods']>;
|
|
31
|
+
}): Labels;
|
|
32
|
+
/** Right-to-left scripts (Arabic, Persian, Urdu...). */
|
|
33
|
+
export declare function isRtl(locale: string): boolean;
|
|
34
|
+
/** First day of the week of a locale: 0 Monday to 6 Sunday. */
|
|
35
|
+
export declare function firstDayOf(locale: string): number;
|
|
36
|
+
/** True when the locale writes hours as 1 to 12 with AM and PM. */
|
|
37
|
+
export declare function uses12Hours(locale: string): boolean;
|
|
38
|
+
/** The twelve month names. */
|
|
39
|
+
export declare function monthNames(locale: string, width?: 'long' | 'short'): string[];
|
|
40
|
+
/** The seven day names, from the first day of the week. */
|
|
41
|
+
export declare function weekdayNames(locale: string, firstDay: number, width?: 'long' | 'short' | 'narrow'): string[];
|
|
42
|
+
/** A number in the digits of the locale (Arabic-Indic digits in `ar-EG`). */
|
|
43
|
+
export declare const digits: (n: number, locale: string, minimum?: number) => string;
|
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
const KEYS = [
|
|
2
|
+
'today',
|
|
3
|
+
'now',
|
|
4
|
+
'clear',
|
|
5
|
+
'apply',
|
|
6
|
+
'cancel',
|
|
7
|
+
'from',
|
|
8
|
+
'to',
|
|
9
|
+
'time',
|
|
10
|
+
'week',
|
|
11
|
+
'quarter',
|
|
12
|
+
'previous',
|
|
13
|
+
'next',
|
|
14
|
+
'zone',
|
|
15
|
+
];
|
|
16
|
+
const PERIOD_KEYS = [
|
|
17
|
+
'yesterday',
|
|
18
|
+
'last7',
|
|
19
|
+
'last30',
|
|
20
|
+
'thisWeek',
|
|
21
|
+
'lastWeek',
|
|
22
|
+
'thisMonth',
|
|
23
|
+
'lastMonth',
|
|
24
|
+
'thisQuarter',
|
|
25
|
+
'lastQuarter',
|
|
26
|
+
'thisYear',
|
|
27
|
+
'lastYear',
|
|
28
|
+
'yearToDate',
|
|
29
|
+
];
|
|
30
|
+
const EXTRA_KEYS = ['custom', 'compareTo', 'previousYear', 'previousPeriod', 'none'];
|
|
31
|
+
// One line per language, in the order of KEYS, PERIOD_KEYS ("today" is used for both), then EXTRA_KEYS
|
|
32
|
+
const WORDS = {
|
|
33
|
+
en: 'Today|Now|Clear|Apply|Cancel|From|To|Time|W|Q|Previous|Next|Time zone|Yesterday|Last 7 days|Last 30 days|This week|Last week|This month|Last month|This quarter|Last quarter|This year|Last year|Year to date|Custom|Compare to|Same period last year|Previous period|None',
|
|
34
|
+
fr: "Aujourd'hui|Maintenant|Effacer|Appliquer|Annuler|Du|Au|Heure|S|T|Précédent|Suivant|Fuseau horaire|Hier|7 derniers jours|30 derniers jours|Cette semaine|Semaine dernière|Ce mois-ci|Mois dernier|Ce trimestre|Trimestre dernier|Cette année|Année dernière|Depuis le début de l'année|Personnalisé|Comparer à|Même période N-1|Période précédente|Aucune",
|
|
35
|
+
de: 'Heute|Jetzt|Löschen|Übernehmen|Abbrechen|Von|Bis|Uhrzeit|KW|Q|Zurück|Weiter|Zeitzone|Gestern|Letzte 7 Tage|Letzte 30 Tage|Diese Woche|Letzte Woche|Dieser Monat|Letzter Monat|Dieses Quartal|Letztes Quartal|Dieses Jahr|Letztes Jahr|Seit Jahresbeginn|Benutzerdefiniert|Vergleichen mit|Gleicher Zeitraum im Vorjahr|Vorheriger Zeitraum|Keiner',
|
|
36
|
+
es: 'Hoy|Ahora|Borrar|Aplicar|Cancelar|Desde|Hasta|Hora|S|T|Anterior|Siguiente|Zona horaria|Ayer|Últimos 7 días|Últimos 30 días|Esta semana|Semana pasada|Este mes|Mes pasado|Este trimestre|Trimestre pasado|Este año|Año pasado|Año hasta la fecha|Personalizado|Comparar con|Mismo periodo del año anterior|Periodo anterior|Ninguno',
|
|
37
|
+
it: "Oggi|Adesso|Cancella|Applica|Annulla|Dal|Al|Ora|S|T|Precedente|Successivo|Fuso orario|Ieri|Ultimi 7 giorni|Ultimi 30 giorni|Questa settimana|Settimana scorsa|Questo mese|Mese scorso|Questo trimestre|Trimestre scorso|Quest'anno|Anno scorso|Da inizio anno|Personalizzato|Confronta con|Stesso periodo anno precedente|Periodo precedente|Nessuno",
|
|
38
|
+
pt: 'Hoje|Agora|Limpar|Aplicar|Cancelar|De|Até|Hora|S|T|Anterior|Seguinte|Fuso horário|Ontem|Últimos 7 dias|Últimos 30 dias|Esta semana|Semana passada|Este mês|Mês passado|Este trimestre|Trimestre passado|Este ano|Ano passado|Desde o início do ano|Personalizado|Comparar com|Mesmo período do ano anterior|Período anterior|Nenhum',
|
|
39
|
+
nl: 'Vandaag|Nu|Wissen|Toepassen|Annuleren|Van|Tot|Tijd|W|K|Vorige|Volgende|Tijdzone|Gisteren|Laatste 7 dagen|Laatste 30 dagen|Deze week|Vorige week|Deze maand|Vorige maand|Dit kwartaal|Vorig kwartaal|Dit jaar|Vorig jaar|Dit jaar tot nu|Aangepast|Vergelijken met|Zelfde periode vorig jaar|Vorige periode|Geen',
|
|
40
|
+
sv: 'Idag|Nu|Rensa|Använd|Avbryt|Från|Till|Tid|V|K|Föregående|Nästa|Tidszon|Igår|Senaste 7 dagarna|Senaste 30 dagarna|Denna vecka|Förra veckan|Denna månad|Förra månaden|Detta kvartal|Förra kvartalet|I år|Förra året|Hittills i år|Anpassad|Jämför med|Samma period föregående år|Föregående period|Ingen',
|
|
41
|
+
da: 'I dag|Nu|Ryd|Anvend|Annuller|Fra|Til|Tid|U|K|Forrige|Næste|Tidszone|I går|Seneste 7 dage|Seneste 30 dage|Denne uge|Sidste uge|Denne måned|Sidste måned|Dette kvartal|Sidste kvartal|I år|Sidste år|År til dato|Tilpasset|Sammenlign med|Samme periode sidste år|Forrige periode|Ingen',
|
|
42
|
+
nb: 'I dag|Nå|Tøm|Bruk|Avbryt|Fra|Til|Tid|U|K|Forrige|Neste|Tidssone|I går|Siste 7 dager|Siste 30 dager|Denne uken|Forrige uke|Denne måneden|Forrige måned|Dette kvartalet|Forrige kvartal|I år|I fjor|Hittil i år|Egendefinert|Sammenlign med|Samme periode i fjor|Forrige periode|Ingen',
|
|
43
|
+
fi: 'Tänään|Nyt|Tyhjennä|Käytä|Peruuta|Alkaen|Asti|Aika|Vk|Q|Edellinen|Seuraava|Aikavyöhyke|Eilen|Viimeiset 7 päivää|Viimeiset 30 päivää|Tämä viikko|Viime viikko|Tämä kuukausi|Viime kuukausi|Tämä neljännes|Viime neljännes|Tämä vuosi|Viime vuosi|Vuoden alusta|Mukautettu|Vertaa|Sama jakso viime vuonna|Edellinen jakso|Ei mitään',
|
|
44
|
+
pl: 'Dzisiaj|Teraz|Wyczyść|Zastosuj|Anuluj|Od|Do|Godzina|Tydz.|Kw.|Poprzedni|Następny|Strefa czasowa|Wczoraj|Ostatnie 7 dni|Ostatnie 30 dni|Ten tydzień|Poprzedni tydzień|Ten miesiąc|Poprzedni miesiąc|Ten kwartał|Poprzedni kwartał|Ten rok|Poprzedni rok|Od początku roku|Niestandardowy|Porównaj z|Ten sam okres rok wcześniej|Poprzedni okres|Brak',
|
|
45
|
+
cs: 'Dnes|Nyní|Vymazat|Použít|Zrušit|Od|Do|Čas|T|Q|Předchozí|Další|Časové pásmo|Včera|Posledních 7 dní|Posledních 30 dní|Tento týden|Minulý týden|Tento měsíc|Minulý měsíc|Toto čtvrtletí|Minulé čtvrtletí|Tento rok|Minulý rok|Od začátku roku|Vlastní|Porovnat s|Stejné období loni|Předchozí období|Žádné',
|
|
46
|
+
sk: 'Dnes|Teraz|Vymazať|Použiť|Zrušiť|Od|Do|Čas|T|Q|Predchádzajúci|Ďalší|Časové pásmo|Včera|Posledných 7 dní|Posledných 30 dní|Tento týždeň|Minulý týždeň|Tento mesiac|Minulý mesiac|Tento štvrťrok|Minulý štvrťrok|Tento rok|Minulý rok|Od začiatku roka|Vlastné|Porovnať s|Rovnaké obdobie vlani|Predchádzajúce obdobie|Žiadne',
|
|
47
|
+
hu: 'Ma|Most|Törlés|Alkalmaz|Mégse|Ettől|Eddig|Idő|H|N|Előző|Következő|Időzóna|Tegnap|Elmúlt 7 nap|Elmúlt 30 nap|Ez a hét|Múlt hét|Ez a hónap|Múlt hónap|Ez a negyedév|Múlt negyedév|Idén|Tavaly|Év eleje óta|Egyéni|Összehasonlítás|Előző év azonos időszaka|Előző időszak|Nincs',
|
|
48
|
+
ro: 'Astăzi|Acum|Șterge|Aplică|Anulează|De la|Până la|Ora|S|T|Anterior|Următor|Fus orar|Ieri|Ultimele 7 zile|Ultimele 30 de zile|Săptămâna aceasta|Săptămâna trecută|Luna aceasta|Luna trecută|Trimestrul acesta|Trimestrul trecut|Anul acesta|Anul trecut|De la începutul anului|Personalizat|Compară cu|Aceeași perioadă a anului trecut|Perioada anterioară|Niciuna',
|
|
49
|
+
bg: 'Днес|Сега|Изчисти|Приложи|Отказ|От|До|Час|С|Тр|Предишен|Следващ|Часова зона|Вчера|Последните 7 дни|Последните 30 дни|Тази седмица|Миналата седмица|Този месец|Миналия месец|Това тримесечие|Миналото тримесечие|Тази година|Миналата година|От началото на годината|По избор|Сравни с|Същият период миналата година|Предишен период|Без',
|
|
50
|
+
el: 'Σήμερα|Τώρα|Καθαρισμός|Εφαρμογή|Ακύρωση|Από|Έως|Ώρα|Εβδ|Τρ|Προηγούμενο|Επόμενο|Ζώνη ώρας|Χθες|Τελευταίες 7 ημέρες|Τελευταίες 30 ημέρες|Αυτή την εβδομάδα|Προηγούμενη εβδομάδα|Αυτόν τον μήνα|Προηγούμενος μήνας|Αυτό το τρίμηνο|Προηγούμενο τρίμηνο|Φέτος|Πέρσι|Από την αρχή του έτους|Προσαρμοσμένο|Σύγκριση με|Ίδια περίοδος πέρσι|Προηγούμενη περίοδος|Καμία',
|
|
51
|
+
hr: 'Danas|Sada|Očisti|Primijeni|Odustani|Od|Do|Vrijeme|T|Kv|Prethodno|Sljedeće|Vremenska zona|Jučer|Zadnjih 7 dana|Zadnjih 30 dana|Ovaj tjedan|Prošli tjedan|Ovaj mjesec|Prošli mjesec|Ovo tromjesečje|Prošlo tromjesečje|Ova godina|Prošla godina|Od početka godine|Prilagođeno|Usporedi s|Isto razdoblje prošle godine|Prethodno razdoblje|Ništa',
|
|
52
|
+
sl: 'Danes|Zdaj|Počisti|Uporabi|Prekliči|Od|Do|Čas|T|Č|Prejšnji|Naslednji|Časovni pas|Včeraj|Zadnjih 7 dni|Zadnjih 30 dni|Ta teden|Prejšnji teden|Ta mesec|Prejšnji mesec|To četrtletje|Prejšnje četrtletje|Letos|Lani|Od začetka leta|Po meri|Primerjaj z|Enako obdobje lani|Prejšnje obdobje|Brez',
|
|
53
|
+
uk: 'Сьогодні|Зараз|Очистити|Застосувати|Скасувати|Від|До|Час|Тиж|Кв|Попередній|Наступний|Часовий пояс|Вчора|Останні 7 днів|Останні 30 днів|Цей тиждень|Минулий тиждень|Цей місяць|Минулий місяць|Цей квартал|Минулий квартал|Цей рік|Минулий рік|З початку року|Власний|Порівняти з|Той самий період торік|Попередній період|Немає',
|
|
54
|
+
ru: 'Сегодня|Сейчас|Очистить|Применить|Отмена|С|По|Время|Нед|Кв|Назад|Вперёд|Часовой пояс|Вчера|Последние 7 дней|Последние 30 дней|Эта неделя|Прошлая неделя|Этот месяц|Прошлый месяц|Этот квартал|Прошлый квартал|Этот год|Прошлый год|С начала года|Свой|Сравнить с|Тот же период год назад|Предыдущий период|Нет',
|
|
55
|
+
tr: 'Bugün|Şimdi|Temizle|Uygula|İptal|Başlangıç|Bitiş|Saat|H|Ç|Önceki|Sonraki|Saat dilimi|Dün|Son 7 gün|Son 30 gün|Bu hafta|Geçen hafta|Bu ay|Geçen ay|Bu çeyrek|Geçen çeyrek|Bu yıl|Geçen yıl|Yıl başından bugüne|Özel|Karşılaştır|Geçen yılın aynı dönemi|Önceki dönem|Yok',
|
|
56
|
+
ca: "Avui|Ara|Esborra|Aplica|Cancel·la|Des de|Fins a|Hora|S|T|Anterior|Següent|Fus horari|Ahir|Últims 7 dies|Últims 30 dies|Aquesta setmana|Setmana passada|Aquest mes|Mes passat|Aquest trimestre|Trimestre passat|Aquest any|Any passat|Des de l'inici de l'any|Personalitzat|Compara amb|Mateix període de l'any anterior|Període anterior|Cap",
|
|
57
|
+
lt: 'Šiandien|Dabar|Išvalyti|Taikyti|Atšaukti|Nuo|Iki|Laikas|Sav|Ketv|Ankstesnis|Kitas|Laiko juosta|Vakar|Paskutinės 7 dienos|Paskutinės 30 dienų|Ši savaitė|Praėjusi savaitė|Šis mėnuo|Praėjęs mėnuo|Šis ketvirtis|Praėjęs ketvirtis|Šie metai|Praėję metai|Nuo metų pradžios|Pasirinktinis|Palyginti su|Tas pats laikotarpis pernai|Ankstesnis laikotarpis|Nėra',
|
|
58
|
+
lv: 'Šodien|Tagad|Notīrīt|Lietot|Atcelt|No|Līdz|Laiks|Ned|Cet|Iepriekšējais|Nākamais|Laika josla|Vakar|Pēdējās 7 dienas|Pēdējās 30 dienas|Šī nedēļa|Pagājušā nedēļa|Šis mēnesis|Pagājušais mēnesis|Šis ceturksnis|Pagājušais ceturksnis|Šis gads|Pagājušais gads|Kopš gada sākuma|Pielāgots|Salīdzināt ar|Tas pats periods pērn|Iepriekšējais periods|Nav',
|
|
59
|
+
et: 'Täna|Praegu|Tühjenda|Rakenda|Tühista|Alates|Kuni|Aeg|Näd|Kv|Eelmine|Järgmine|Ajavöönd|Eile|Viimased 7 päeva|Viimased 30 päeva|See nädal|Eelmine nädal|See kuu|Eelmine kuu|See kvartal|Eelmine kvartal|See aasta|Eelmine aasta|Aasta algusest|Kohandatud|Võrdle|Sama periood eelmisel aastal|Eelmine periood|Puudub',
|
|
60
|
+
ar: 'اليوم|الآن|مسح|تطبيق|إلغاء|من|إلى|الوقت|أ|ر|السابق|التالي|المنطقة الزمنية|أمس|آخر 7 أيام|آخر 30 يومًا|هذا الأسبوع|الأسبوع الماضي|هذا الشهر|الشهر الماضي|هذا الربع|الربع الماضي|هذه السنة|السنة الماضية|منذ بداية السنة|مخصص|مقارنة مع|الفترة نفسها من السنة الماضية|الفترة السابقة|بدون',
|
|
61
|
+
};
|
|
62
|
+
/** The languages the words of the picker are written in. Month and day names exist for every language of the platform. */
|
|
63
|
+
export const LANGUAGES = Object.keys(WORDS);
|
|
64
|
+
const languageOf = (locale) => locale.toLowerCase().split(/[-_]/)[0];
|
|
65
|
+
/** The words of the picker for a locale, with the reader's own replacements. */
|
|
66
|
+
export function labelsFor(locale, custom = {}) {
|
|
67
|
+
const lang = languageOf(locale);
|
|
68
|
+
const words = (WORDS[lang === 'no' ? 'nb' : lang] ?? WORDS.en).split('|');
|
|
69
|
+
const out = { periods: {} };
|
|
70
|
+
KEYS.forEach((k, i) => (out[k] = words[i]));
|
|
71
|
+
out.periods.today = out.today;
|
|
72
|
+
PERIOD_KEYS.forEach((k, i) => (out.periods[k] = words[KEYS.length + i]));
|
|
73
|
+
EXTRA_KEYS.forEach((k, i) => (out[k] = words[KEYS.length + PERIOD_KEYS.length + i]));
|
|
74
|
+
const { periods, ...rest } = custom;
|
|
75
|
+
return { ...out, ...rest, periods: { ...out.periods, ...periods } };
|
|
76
|
+
}
|
|
77
|
+
/** Right-to-left scripts (Arabic, Persian, Urdu...). */
|
|
78
|
+
export function isRtl(locale) {
|
|
79
|
+
try {
|
|
80
|
+
const l = new Intl.Locale(locale);
|
|
81
|
+
const info = l.getTextInfo?.() ?? l.textInfo;
|
|
82
|
+
if (info)
|
|
83
|
+
return info.direction === 'rtl';
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
/* an unknown tag: the language code decides */
|
|
87
|
+
}
|
|
88
|
+
return ['ar', 'fa', 'ur', 'ps', 'dv', 'ckb'].includes(languageOf(locale));
|
|
89
|
+
}
|
|
90
|
+
/** First day of the week of a locale: 0 Monday to 6 Sunday. */
|
|
91
|
+
export function firstDayOf(locale) {
|
|
92
|
+
try {
|
|
93
|
+
const l = new Intl.Locale(locale);
|
|
94
|
+
const info = l.getWeekInfo?.() ?? l.weekInfo;
|
|
95
|
+
if (info)
|
|
96
|
+
return (info.firstDay + 6) % 7; // Intl: 1 Monday to 7 Sunday
|
|
97
|
+
const region = l.maximize().region ?? '';
|
|
98
|
+
if (['US', 'CA', 'MX', 'BR', 'JP', 'KR', 'IL', 'IN', 'PH', 'SA', 'ZA', 'CO', 'PE', 'VE'].includes(region))
|
|
99
|
+
return 6;
|
|
100
|
+
if (['EG', 'DZ', 'MA', 'TN', 'IQ', 'SY', 'JO', 'KW', 'QA', 'BH', 'OM', 'LY', 'AF', 'IR'].includes(region))
|
|
101
|
+
return region === 'MA' || region === 'TN' ? 0 : 5;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
/* an unknown tag: Monday */
|
|
105
|
+
}
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
/** True when the locale writes hours as 1 to 12 with AM and PM. */
|
|
109
|
+
export function uses12Hours(locale) {
|
|
110
|
+
try {
|
|
111
|
+
return new Intl.DateTimeFormat(locale, { hour: 'numeric' }).resolvedOptions().hour12 === true;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const noonUtc = (y, m, d) => new Date(Date.UTC(y, m - 1, d, 12));
|
|
118
|
+
/** The twelve month names. */
|
|
119
|
+
export function monthNames(locale, width = 'long') {
|
|
120
|
+
const f = new Intl.DateTimeFormat(locale, { month: width, timeZone: 'UTC' });
|
|
121
|
+
return Array.from({ length: 12 }, (_, i) => f.format(noonUtc(2024, i + 1, 15)));
|
|
122
|
+
}
|
|
123
|
+
/** The seven day names, from the first day of the week. */
|
|
124
|
+
export function weekdayNames(locale, firstDay, width = 'short') {
|
|
125
|
+
const f = new Intl.DateTimeFormat(locale, { weekday: width, timeZone: 'UTC' });
|
|
126
|
+
// 2024-01-01 is a Monday
|
|
127
|
+
return Array.from({ length: 7 }, (_, i) => f.format(noonUtc(2024, 1, 1 + ((firstDay + i) % 7))));
|
|
128
|
+
}
|
|
129
|
+
/** A number in the digits of the locale (Arabic-Indic digits in `ar-EG`). */
|
|
130
|
+
export const digits = (n, locale, minimum = 1) => new Intl.NumberFormat(locale, { useGrouping: false, minimumIntegerDigits: minimum }).format(n);
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './core.ts';
|
|
2
|
+
export { addDays, addMonths, dateText, isoWeek, monthGrid, parseDate, quarterOf, startOfWeek } from './calendar.ts';
|
|
3
|
+
export { firstDayOf, isRtl, monthNames, weekdayNames } from './i18n.ts';
|
|
4
|
+
export { offsetText, resolveZone, today, zoneLabel } from './zone.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from "./core.js";
|
|
2
|
+
export { addDays, addMonths, dateText, isoWeek, monthGrid, parseDate, quarterOf, startOfWeek } from "./calendar.js";
|
|
3
|
+
export { firstDayOf, isRtl, monthNames, weekdayNames } from "./i18n.js";
|
|
4
|
+
export { offsetText, resolveZone, today, zoneLabel } from "./zone.js";
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type PlainDate, type PlainTime } from './calendar.ts';
|
|
2
|
+
import type { Labels } from './i18n.ts';
|
|
3
|
+
import type { Comparison, Granularity, Mode, PickerOptions, PickerValue, Selection } from './types.ts';
|
|
4
|
+
export declare const MIDNIGHT: PlainTime;
|
|
5
|
+
/** What is picked. `dates` holds one day (date, week, month, quarter, year, time), two (range) or several (multiple). */
|
|
6
|
+
export interface Pick {
|
|
7
|
+
dates: PlainDate[];
|
|
8
|
+
/** Time of the first and of the last day, when the hour is picked. */
|
|
9
|
+
times: [PlainTime, PlainTime];
|
|
10
|
+
}
|
|
11
|
+
export interface Shape {
|
|
12
|
+
mode: Mode;
|
|
13
|
+
time: boolean;
|
|
14
|
+
seconds: boolean;
|
|
15
|
+
zone: string;
|
|
16
|
+
locale: string;
|
|
17
|
+
hour12: boolean | undefined;
|
|
18
|
+
}
|
|
19
|
+
export declare const emptyPick: () => Pick;
|
|
20
|
+
/** True when the pick is whole: a range has its two days. */
|
|
21
|
+
export declare const complete: (pick: Pick, mode: Mode) => boolean;
|
|
22
|
+
/** Reads a value for a mode. An unreadable value gives an empty pick. */
|
|
23
|
+
export declare function readValue(value: PickerValue | Date | undefined, shape: Shape): Pick;
|
|
24
|
+
/** The pick as ISO text, in the form of its mode. */
|
|
25
|
+
export declare function writeValue(pick: Pick, shape: Shape): PickerValue;
|
|
26
|
+
/** First instant of the pick and the instant just after it. */
|
|
27
|
+
export declare function bounds(pick: Pick, shape: Shape): [Date | null, Date | null];
|
|
28
|
+
/** The pick as the field writes it. */
|
|
29
|
+
export declare function textOf(pick: Pick, shape: Shape, labels: Labels, custom?: Intl.DateTimeFormatOptions): string;
|
|
30
|
+
/** The whole selection: value, instants, zone and text. */
|
|
31
|
+
export declare function selectionOf(pick: Pick, shape: Shape, labels: Labels, format?: PickerOptions['format']): Selection;
|
|
32
|
+
/** Last day of a month, for the grids. */
|
|
33
|
+
export declare const lastOfMonth: (y: number, m: number) => PlainDate;
|
|
34
|
+
/** The mode a tab of the period block picks with. */
|
|
35
|
+
export declare const innerMode: (granularity: Granularity) => Mode;
|
|
36
|
+
/** First and last day (both included) of a pick, whatever its mode. Null while the pick is not whole. */
|
|
37
|
+
export declare function spanOf(pick: Pick, mode: Mode): [PlainDate, PlainDate] | null;
|
|
38
|
+
/** The tab that fits a first and a last day: a whole year, quarter, month or ISO week, one day, else a free range. */
|
|
39
|
+
export declare function granularityOf(first: PlainDate, last: PlainDate): Granularity;
|
|
40
|
+
/** The period to compare with: the same days one year before, or as many days just before. */
|
|
41
|
+
export declare function comparedSpan(first: PlainDate, last: PlainDate, kind: Comparison): [PlainDate, PlainDate] | null;
|