@trismegisto/primitives 3.4.0 → 4.0.1
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/MIGRATION.md +831 -0
- package/README.md +8 -0
- package/dist/assignee.js +1 -1
- package/dist/assignee.js.map +1 -1
- package/dist/attachment.js +31 -2
- package/dist/attachment.js.map +1 -1
- package/dist/back-stack.d.ts +32 -0
- package/dist/back-stack.js +166 -0
- package/dist/back-stack.js.map +1 -0
- package/dist/bottom-sheet-gesture.d.ts +22 -0
- package/dist/bottom-sheet-gesture.js +58 -0
- package/dist/bottom-sheet-gesture.js.map +1 -0
- package/dist/calendar-display.d.ts +60 -0
- package/dist/calendar-display.js +132 -0
- package/dist/calendar-display.js.map +1 -0
- package/dist/calendar-external.d.ts +30 -0
- package/dist/calendar-external.js +129 -0
- package/dist/calendar-external.js.map +1 -0
- package/dist/calendar-grid-nav.d.ts +52 -0
- package/dist/calendar-grid-nav.js +91 -0
- package/dist/calendar-grid-nav.js.map +1 -0
- package/dist/calendar-hit.d.ts +33 -0
- package/dist/calendar-hit.js +57 -0
- package/dist/calendar-hit.js.map +1 -0
- package/dist/calendar-index.d.ts +20 -0
- package/dist/calendar-index.js +98 -0
- package/dist/calendar-index.js.map +1 -0
- package/dist/calendar-interaction.d.ts +83 -0
- package/dist/calendar-interaction.js +136 -0
- package/dist/calendar-interaction.js.map +1 -0
- package/dist/calendar-layout.d.ts +275 -0
- package/dist/calendar-layout.js +546 -0
- package/dist/calendar-layout.js.map +1 -0
- package/dist/calendar-now.d.ts +64 -0
- package/dist/calendar-now.js +122 -0
- package/dist/calendar-now.js.map +1 -0
- package/dist/calendar-pointer.d.ts +90 -0
- package/dist/calendar-pointer.js +357 -0
- package/dist/calendar-pointer.js.map +1 -0
- package/dist/calendar-rules.d.ts +139 -0
- package/dist/calendar-rules.js +265 -0
- package/dist/calendar-rules.js.map +1 -0
- package/dist/calendar-series.d.ts +27 -0
- package/dist/calendar-series.js +150 -0
- package/dist/calendar-series.js.map +1 -0
- package/dist/calendar-timeline.d.ts +75 -0
- package/dist/calendar-timeline.js +141 -0
- package/dist/calendar-timeline.js.map +1 -0
- package/dist/calendar-zone.d.ts +101 -0
- package/dist/calendar-zone.js +319 -0
- package/dist/calendar-zone.js.map +1 -0
- package/dist/camera-capture.d.ts +101 -0
- package/dist/camera-capture.js +206 -0
- package/dist/camera-capture.js.map +1 -0
- package/dist/data-grid-clipboard.d.ts +85 -0
- package/dist/data-grid-clipboard.js +223 -0
- package/dist/data-grid-clipboard.js.map +1 -0
- package/dist/data-grid-cursor.d.ts +165 -0
- package/dist/data-grid-cursor.js +219 -0
- package/dist/data-grid-cursor.js.map +1 -0
- package/dist/data-grid-export.d.ts +6 -1
- package/dist/data-grid-export.js +10 -18
- package/dist/data-grid-export.js.map +1 -1
- package/dist/data-grid-measure.d.ts +1 -1
- package/dist/data-grid-measure.js +2 -1
- package/dist/data-grid-measure.js.map +1 -1
- package/dist/data-grid.d.ts +7 -0
- package/dist/data-grid.js.map +1 -1
- package/dist/download.d.ts +15 -0
- package/dist/download.js +39 -0
- package/dist/download.js.map +1 -0
- package/dist/drag-drop.d.ts +1 -1
- package/dist/drag-drop.js +91 -24
- package/dist/drag-drop.js.map +1 -1
- package/dist/event-calendar-edit.d.ts +37 -5
- package/dist/event-calendar-edit.js +144 -13
- package/dist/event-calendar-edit.js.map +1 -1
- package/dist/event-calendar.d.ts +130 -11
- package/dist/event-calendar.js +195 -29
- package/dist/event-calendar.js.map +1 -1
- package/dist/file-upload-edit.d.ts +43 -0
- package/dist/file-upload-edit.js +64 -0
- package/dist/file-upload-edit.js.map +1 -0
- package/dist/file-upload-entries.d.ts +84 -0
- package/dist/file-upload-entries.js +214 -0
- package/dist/file-upload-entries.js.map +1 -0
- package/dist/file-upload.d.ts +74 -5
- package/dist/file-upload.js +165 -41
- package/dist/file-upload.js.map +1 -1
- package/dist/focus.d.ts +11 -0
- package/dist/focus.js +80 -4
- package/dist/focus.js.map +1 -1
- package/dist/gallery.d.ts +15 -4
- package/dist/gallery.js +28 -7
- package/dist/gallery.js.map +1 -1
- package/dist/gesture.d.ts +90 -0
- package/dist/gesture.js +165 -0
- package/dist/gesture.js.map +1 -0
- package/dist/graph-centrality.d.ts +36 -0
- package/dist/graph-centrality.js +160 -0
- package/dist/graph-centrality.js.map +1 -0
- package/dist/graph-components.d.ts +49 -0
- package/dist/graph-components.js +344 -0
- package/dist/graph-components.js.map +1 -0
- package/dist/graph-core.d.ts +124 -0
- package/dist/graph-core.js +275 -0
- package/dist/graph-core.js.map +1 -0
- package/dist/graph-order.d.ts +27 -0
- package/dist/graph-order.js +105 -0
- package/dist/graph-order.js.map +1 -0
- package/dist/graph-paths.d.ts +39 -0
- package/dist/graph-paths.js +105 -0
- package/dist/graph-paths.js.map +1 -0
- package/dist/graph-traverse.d.ts +89 -0
- package/dist/graph-traverse.js +164 -0
- package/dist/graph-traverse.js.map +1 -0
- package/dist/graph.d.ts +30 -0
- package/dist/graph.js +31 -0
- package/dist/graph.js.map +1 -0
- package/dist/icalendar.d.ts +33 -5
- package/dist/icalendar.js +269 -9
- package/dist/icalendar.js.map +1 -1
- package/dist/image-crop-io.d.ts +5 -1
- package/dist/image-crop-io.js +18 -5
- package/dist/image-crop-io.js.map +1 -1
- package/dist/image-crop.d.ts +84 -0
- package/dist/image-crop.js +131 -0
- package/dist/image-crop.js.map +1 -1
- package/dist/incident.js +2 -2
- package/dist/index.d.ts +32 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -1
- package/dist/messages-data-grid.d.ts +42 -7
- package/dist/messages-data-grid.js +51 -0
- package/dist/messages-data-grid.js.map +1 -1
- package/dist/messages-en.js +11 -0
- package/dist/messages-en.js.map +1 -1
- package/dist/messages-es.js +11 -0
- package/dist/messages-es.js.map +1 -1
- package/dist/messages-event-calendar-pro.d.ts +105 -0
- package/dist/messages-event-calendar-pro.js +273 -0
- package/dist/messages-event-calendar-pro.js.map +1 -0
- package/dist/messages-resumable-upload.d.ts +106 -0
- package/dist/messages-resumable-upload.js +256 -0
- package/dist/messages-resumable-upload.js.map +1 -0
- package/dist/messages-rich-text.d.ts +120 -0
- package/dist/messages-rich-text.js +235 -0
- package/dist/messages-rich-text.js.map +1 -0
- package/dist/messages-secret.d.ts +32 -0
- package/dist/messages-secret.js +62 -0
- package/dist/messages-secret.js.map +1 -0
- package/dist/messages.d.ts +14 -0
- package/dist/messages.js +11 -0
- package/dist/messages.js.map +1 -1
- package/dist/mobile.d.ts +25 -0
- package/dist/mobile.js +45 -0
- package/dist/mobile.js.map +1 -0
- package/dist/native.d.ts +71 -0
- package/dist/native.js +147 -0
- package/dist/native.js.map +1 -0
- package/dist/payments.js +1 -1
- package/dist/payments.js.map +1 -1
- package/dist/popover-overlay.d.ts +4 -1
- package/dist/popover-overlay.js +10 -3
- package/dist/popover-overlay.js.map +1 -1
- package/dist/recurrence-editor.d.ts +3 -1
- package/dist/recurrence-editor.js +6 -0
- package/dist/recurrence-editor.js.map +1 -1
- package/dist/recurrence.d.ts +70 -10
- package/dist/recurrence.js +363 -24
- package/dist/recurrence.js.map +1 -1
- package/dist/resource-usage.js +1 -1
- package/dist/resource-usage.js.map +1 -1
- package/dist/resumable-upload-field.d.ts +57 -0
- package/dist/resumable-upload-field.js +196 -0
- package/dist/resumable-upload-field.js.map +1 -0
- package/dist/resumable-upload-store.d.ts +40 -0
- package/dist/resumable-upload-store.js +209 -0
- package/dist/resumable-upload-store.js.map +1 -0
- package/dist/resumable-upload-xhr.d.ts +37 -0
- package/dist/resumable-upload-xhr.js +180 -0
- package/dist/resumable-upload-xhr.js.map +1 -0
- package/dist/resumable-upload.d.ts +268 -0
- package/dist/resumable-upload.js +1221 -0
- package/dist/resumable-upload.js.map +1 -0
- package/dist/rich-text-atoms.d.ts +114 -0
- package/dist/rich-text-atoms.js +328 -0
- package/dist/rich-text-atoms.js.map +1 -0
- package/dist/rich-text-commands.d.ts +2 -2
- package/dist/rich-text-commands.js +1 -1
- package/dist/rich-text-commands.js.map +1 -1
- package/dist/rich-text-dom.d.ts +48 -4
- package/dist/rich-text-dom.js +337 -15
- package/dist/rich-text-dom.js.map +1 -1
- package/dist/rich-text-editor.d.ts +238 -3
- package/dist/rich-text-editor.js +1670 -26
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/rich-text-image.d.ts +62 -0
- package/dist/rich-text-image.js +152 -0
- package/dist/rich-text-image.js.map +1 -0
- package/dist/rich-text-markdown-shortcuts.d.ts +21 -0
- package/dist/rich-text-markdown-shortcuts.js +89 -0
- package/dist/rich-text-markdown-shortcuts.js.map +1 -0
- package/dist/rich-text-markdown.d.ts +57 -0
- package/dist/rich-text-markdown.js +1245 -0
- package/dist/rich-text-markdown.js.map +1 -0
- package/dist/rich-text-model.d.ts +129 -4
- package/dist/rich-text-model.js +554 -33
- package/dist/rich-text-model.js.map +1 -1
- package/dist/rich-text-paste.d.ts +35 -0
- package/dist/rich-text-paste.js +254 -0
- package/dist/rich-text-paste.js.map +1 -0
- package/dist/rich-text-sanitize.d.ts +18 -16
- package/dist/rich-text-sanitize.js +203 -10
- package/dist/rich-text-sanitize.js.map +1 -1
- package/dist/rich-text-schema.d.ts +51 -2
- package/dist/rich-text-schema.js +52 -10
- package/dist/rich-text-schema.js.map +1 -1
- package/dist/rich-text-suggest.d.ts +109 -0
- package/dist/rich-text-suggest.js +181 -0
- package/dist/rich-text-suggest.js.map +1 -0
- package/dist/rich-text-table.d.ts +125 -0
- package/dist/rich-text-table.js +478 -0
- package/dist/rich-text-table.js.map +1 -0
- package/dist/rich-text-validation.d.ts +29 -0
- package/dist/rich-text-validation.js +46 -0
- package/dist/rich-text-validation.js.map +1 -0
- package/dist/rich-text.d.ts +8 -0
- package/dist/rich-text.js +8 -0
- package/dist/rich-text.js.map +1 -1
- package/dist/scheduling.d.ts +6 -0
- package/dist/scheduling.js.map +1 -1
- package/dist/secret.d.ts +120 -0
- package/dist/secret.js +310 -0
- package/dist/secret.js.map +1 -0
- package/dist/service-graph.js +62 -42
- package/dist/service-graph.js.map +1 -1
- package/dist/tabs-overflow.d.ts +27 -0
- package/dist/tabs-overflow.js +36 -0
- package/dist/tabs-overflow.js.map +1 -1
- package/dist/viewport-gestures.d.ts +144 -0
- package/dist/viewport-gestures.js +352 -0
- package/dist/viewport-gestures.js.map +1 -0
- package/dist/viewport.d.ts +98 -0
- package/dist/viewport.js +241 -0
- package/dist/viewport.js.map +1 -0
- package/dist/workflow.d.ts +0 -7
- package/dist/workflow.js +22 -30
- package/dist/workflow.js.map +1 -1
- package/dist/workspace.d.ts +3 -4
- package/dist/workspace.js +2 -2
- package/dist/workspace.js.map +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* O "agora" da agenda, sem framework e sem DOM: a hora de parede atual no fuso de exibição, o estado de cada evento
|
|
3
|
+
* (passado, em andamento, futuro) e um relógio que acorda **no minuto cheio** seguinte (não um intervalo fixo de 60 s,
|
|
4
|
+
* que deriva), pausável quando a agenda sai da tela e ressincronizado quando a aba volta a ficar visível.
|
|
5
|
+
*
|
|
6
|
+
* As cascas ligam `pause()`/`resume()` ao `IntersectionObserver` e `sync()` ao `visibilitychange`; o resto é cálculo.
|
|
7
|
+
*/
|
|
8
|
+
import type { IsoDate } from './date';
|
|
9
|
+
import type { EventCalendarEntry, WallTime } from './event-calendar';
|
|
10
|
+
/** Fonte do instante atual: `Date`, texto ISO ou milissegundos; ausente = o relógio do sistema. */
|
|
11
|
+
export type CalendarNowSource = Date | string | number | null | undefined;
|
|
12
|
+
/** O instante (ms) de uma fonte do "agora" (`now` do componente); inválida ou ausente → o relógio do sistema. */
|
|
13
|
+
export declare function resolveCalendarNow(source: CalendarNowSource, clock?: () => number): number;
|
|
14
|
+
/** Milissegundos até o próximo minuto cheio (entre 1 e 60 000). */
|
|
15
|
+
export declare function msUntilNextMinute(now: number): number;
|
|
16
|
+
/** Hora de parede do "agora" no fuso de exibição (vazio = o do ambiente). */
|
|
17
|
+
export declare function calendarNowWall(now: number, timeZone?: string | null): WallTime;
|
|
18
|
+
/** Estado de um evento em relação ao "agora". */
|
|
19
|
+
export type CalendarEntryTimeState = 'past' | 'ongoing' | 'future';
|
|
20
|
+
/**
|
|
21
|
+
* Passado (terminou), em andamento (começou e não terminou) ou futuro, **por instante**. Um prazo (duração zero) nunca
|
|
22
|
+
* está em andamento: antes do instante é futuro; no instante ou depois, passado.
|
|
23
|
+
*/
|
|
24
|
+
export declare function calendarEntryTimeState(entry: EventCalendarEntry, now: number, timeZone?: string | null): CalendarEntryTimeState;
|
|
25
|
+
/** Situação de um prazo (`kind: 'deadline'`): vencido, vence em `soonHours` horas, ou nenhum dos dois. */
|
|
26
|
+
export type CalendarDeadlineState = 'overdue' | 'soon' | null;
|
|
27
|
+
/** Prazo vencido (antes do "agora") ou próximo (nas próximas `soonHours` horas, padrão 24). Outro evento → `null`. */
|
|
28
|
+
export declare function calendarDeadlineState(entry: EventCalendarEntry, now: number, timeZone?: string | null, soonHours?: number): CalendarDeadlineState;
|
|
29
|
+
/**
|
|
30
|
+
* Intenção efetiva de um evento: a do próprio evento; num prazo sem intenção definida, `danger` quando vencido e
|
|
31
|
+
* `warning` quando vence em breve (§9.5 da especificação).
|
|
32
|
+
*/
|
|
33
|
+
export declare function calendarEffectiveIntent(entry: EventCalendarEntry, now: number, timeZone?: string | null, soonHours?: number): EventCalendarEntry['event']['intent'];
|
|
34
|
+
/** Posição do "agora" numa coluna: o dia e o minuto de parede (a linha só aparece na coluna desse dia). */
|
|
35
|
+
export interface CalendarNowMark {
|
|
36
|
+
readonly date: IsoDate;
|
|
37
|
+
readonly minutes: number;
|
|
38
|
+
}
|
|
39
|
+
/** Temporizador injetável (testes usam um falso). */
|
|
40
|
+
export interface CalendarClockTimers {
|
|
41
|
+
readonly setTimeout: (fn: () => void, ms: number) => unknown;
|
|
42
|
+
readonly clearTimeout: (handle: unknown) => void;
|
|
43
|
+
}
|
|
44
|
+
/** O relógio da agenda: chama `tick(agora)` a cada minuto cheio enquanto ativo. */
|
|
45
|
+
export interface CalendarClock {
|
|
46
|
+
/** Para de acordar (a agenda saiu da tela). */
|
|
47
|
+
pause(): void;
|
|
48
|
+
/** Volta a acordar, avisando o instante atual na hora (a agenda voltou à tela). */
|
|
49
|
+
resume(): void;
|
|
50
|
+
/** Reagenda a partir do relógio de agora e avisa (a aba voltou a ficar visível, o relógio do sistema mudou). */
|
|
51
|
+
sync(): void;
|
|
52
|
+
/** Desliga de vez. */
|
|
53
|
+
dispose(): void;
|
|
54
|
+
readonly running: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Cria o relógio do minuto: avisa `tick` uma vez ao começar e depois sempre no próximo minuto cheio (um único
|
|
58
|
+
* temporizador por vez, reagendado a cada aviso). `now` dá o instante (padrão `Date.now`).
|
|
59
|
+
*/
|
|
60
|
+
export declare function createCalendarClock(tick: (now: number) => void, options?: {
|
|
61
|
+
readonly now?: () => number;
|
|
62
|
+
readonly timers?: CalendarClockTimers;
|
|
63
|
+
readonly autoStart?: boolean;
|
|
64
|
+
}): CalendarClock;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { instantToWallTime } from './calendar-zone';
|
|
2
|
+
import { entryInstants } from './event-calendar';
|
|
3
|
+
const MINUTE = 60_000;
|
|
4
|
+
/** O instante (ms) de uma fonte do "agora" (`now` do componente); inválida ou ausente → o relógio do sistema. */
|
|
5
|
+
export function resolveCalendarNow(source, clock = Date.now) {
|
|
6
|
+
if (source instanceof Date)
|
|
7
|
+
return Number.isNaN(source.getTime()) ? clock() : source.getTime();
|
|
8
|
+
if (typeof source === 'number')
|
|
9
|
+
return Number.isFinite(source) ? source : clock();
|
|
10
|
+
if (typeof source === 'string' && source) {
|
|
11
|
+
const ms = Date.parse(source);
|
|
12
|
+
return Number.isNaN(ms) ? clock() : ms;
|
|
13
|
+
}
|
|
14
|
+
return clock();
|
|
15
|
+
}
|
|
16
|
+
/** Milissegundos até o próximo minuto cheio (entre 1 e 60 000). */
|
|
17
|
+
export function msUntilNextMinute(now) {
|
|
18
|
+
const rest = MINUTE - (((now % MINUTE) + MINUTE) % MINUTE);
|
|
19
|
+
return rest === 0 ? MINUTE : rest;
|
|
20
|
+
}
|
|
21
|
+
/** Hora de parede do "agora" no fuso de exibição (vazio = o do ambiente). */
|
|
22
|
+
export function calendarNowWall(now, timeZone) {
|
|
23
|
+
return instantToWallTime(now, timeZone);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Passado (terminou), em andamento (começou e não terminou) ou futuro, **por instante**. Um prazo (duração zero) nunca
|
|
27
|
+
* está em andamento: antes do instante é futuro; no instante ou depois, passado.
|
|
28
|
+
*/
|
|
29
|
+
export function calendarEntryTimeState(entry, now, timeZone) {
|
|
30
|
+
const { start, end } = entryInstants(entry, timeZone);
|
|
31
|
+
if (end <= start)
|
|
32
|
+
return now >= start ? 'past' : 'future';
|
|
33
|
+
if (now >= end)
|
|
34
|
+
return 'past';
|
|
35
|
+
if (now >= start)
|
|
36
|
+
return 'ongoing';
|
|
37
|
+
return 'future';
|
|
38
|
+
}
|
|
39
|
+
/** Prazo vencido (antes do "agora") ou próximo (nas próximas `soonHours` horas, padrão 24). Outro evento → `null`. */
|
|
40
|
+
export function calendarDeadlineState(entry, now, timeZone, soonHours = 24) {
|
|
41
|
+
if (entry.event.kind !== 'deadline')
|
|
42
|
+
return null;
|
|
43
|
+
const { start } = entryInstants(entry, timeZone);
|
|
44
|
+
if (start <= now)
|
|
45
|
+
return 'overdue';
|
|
46
|
+
if (start - now <= Math.max(0, soonHours) * 3_600_000)
|
|
47
|
+
return 'soon';
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Intenção efetiva de um evento: a do próprio evento; num prazo sem intenção definida, `danger` quando vencido e
|
|
52
|
+
* `warning` quando vence em breve (§9.5 da especificação).
|
|
53
|
+
*/
|
|
54
|
+
export function calendarEffectiveIntent(entry, now, timeZone, soonHours = 24) {
|
|
55
|
+
if (entry.event.intent)
|
|
56
|
+
return entry.event.intent;
|
|
57
|
+
const state = calendarDeadlineState(entry, now, timeZone, soonHours);
|
|
58
|
+
return state === 'overdue' ? 'danger' : state === 'soon' ? 'warning' : undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Cria o relógio do minuto: avisa `tick` uma vez ao começar e depois sempre no próximo minuto cheio (um único
|
|
62
|
+
* temporizador por vez, reagendado a cada aviso). `now` dá o instante (padrão `Date.now`).
|
|
63
|
+
*/
|
|
64
|
+
export function createCalendarClock(tick, options = {}) {
|
|
65
|
+
const now = options.now ?? Date.now;
|
|
66
|
+
const timers = options.timers ?? {
|
|
67
|
+
setTimeout: (fn, ms) => globalThis.setTimeout(fn, ms),
|
|
68
|
+
clearTimeout: (handle) => globalThis.clearTimeout(handle),
|
|
69
|
+
};
|
|
70
|
+
let handle = null;
|
|
71
|
+
let running = false;
|
|
72
|
+
let disposed = false;
|
|
73
|
+
const clear = () => {
|
|
74
|
+
if (handle !== null)
|
|
75
|
+
timers.clearTimeout(handle);
|
|
76
|
+
handle = null;
|
|
77
|
+
};
|
|
78
|
+
const schedule = () => {
|
|
79
|
+
clear();
|
|
80
|
+
if (!running || disposed)
|
|
81
|
+
return;
|
|
82
|
+
handle = timers.setTimeout(() => {
|
|
83
|
+
handle = null;
|
|
84
|
+
fire();
|
|
85
|
+
}, msUntilNextMinute(now()));
|
|
86
|
+
};
|
|
87
|
+
const fire = () => {
|
|
88
|
+
if (!running || disposed)
|
|
89
|
+
return;
|
|
90
|
+
tick(now());
|
|
91
|
+
schedule();
|
|
92
|
+
};
|
|
93
|
+
const clock = {
|
|
94
|
+
pause() {
|
|
95
|
+
running = false;
|
|
96
|
+
clear();
|
|
97
|
+
},
|
|
98
|
+
resume() {
|
|
99
|
+
if (disposed || running)
|
|
100
|
+
return;
|
|
101
|
+
running = true;
|
|
102
|
+
fire();
|
|
103
|
+
},
|
|
104
|
+
sync() {
|
|
105
|
+
if (!running || disposed)
|
|
106
|
+
return;
|
|
107
|
+
fire();
|
|
108
|
+
},
|
|
109
|
+
dispose() {
|
|
110
|
+
disposed = true;
|
|
111
|
+
running = false;
|
|
112
|
+
clear();
|
|
113
|
+
},
|
|
114
|
+
get running() {
|
|
115
|
+
return running;
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
if (options.autoStart ?? true)
|
|
119
|
+
clock.resume();
|
|
120
|
+
return clock;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=calendar-now.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-now.js","sourceRoot":"","sources":["../src/calendar-now.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type CalendarColumnGeometry } from './calendar-hit';
|
|
2
|
+
import type { EventCalendarEntry } from './event-calendar';
|
|
3
|
+
import { type CalendarGestureMode, type CalendarGestureRange } from './calendar-interaction';
|
|
4
|
+
/** Rolagem automática do rolador enquanto o ponteiro está perto da borda (um passo por quadro). */
|
|
5
|
+
export interface CalendarAutoScroll {
|
|
6
|
+
/** Posição vertical do ponteiro (px de tela). */
|
|
7
|
+
update(clientY: number): void;
|
|
8
|
+
stop(): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Rola `scroller` quando o ponteiro chega a menos de uma linha de hora da borda, com velocidade proporcional à
|
|
12
|
+
* proximidade (até ~1 linha de hora a cada 150 ms). `onScroll(delta)` avisa quanto rolou (para o gesto recalcular).
|
|
13
|
+
*/
|
|
14
|
+
export declare function createCalendarAutoScroll(scroller: HTMLElement | null, hourPx: number, onScroll: (delta: number) => void): CalendarAutoScroll;
|
|
15
|
+
/** O que a casca passa para a seleção por arraste. */
|
|
16
|
+
export interface CalendarCreateBinding {
|
|
17
|
+
readonly host: HTMLElement;
|
|
18
|
+
readonly scroller: HTMLElement | null;
|
|
19
|
+
readonly timed: boolean;
|
|
20
|
+
readonly window: {
|
|
21
|
+
readonly start: number;
|
|
22
|
+
readonly end: number;
|
|
23
|
+
};
|
|
24
|
+
readonly step: number;
|
|
25
|
+
readonly defaultDuration: number;
|
|
26
|
+
/** Altura de uma hora (px), para a rolagem automática. */
|
|
27
|
+
readonly hourPx: number;
|
|
28
|
+
/** A prévia mudou (`null` = sumiu). */
|
|
29
|
+
preview(range: CalendarGestureRange | null): void;
|
|
30
|
+
/** Soltou: `dragged` diz se houve arraste (sem ele, foi clique: a casca cria a duração padrão). */
|
|
31
|
+
commit(range: CalendarGestureRange, dragged: boolean): void;
|
|
32
|
+
cancel(): void;
|
|
33
|
+
}
|
|
34
|
+
/** As colunas (ou células do mês) medidas agora. */
|
|
35
|
+
export declare function measureCalendarColumns(host: HTMLElement, timed: boolean): CalendarColumnGeometry[];
|
|
36
|
+
/**
|
|
37
|
+
* Começa a seleção de um período no `pointerdown` de uma coluna (ou célula) vazia. Devolve `false` quando o alvo é um
|
|
38
|
+
* controle (evento, "+N", botão do dia): ali o gesto é outro. Mouse e caneta: arrasta depois do limiar; toque: só depois
|
|
39
|
+
* da pressão longa (antes disso o dedo rola a grade). Esc, `pointercancel` e a janela perder o foco cancelam.
|
|
40
|
+
*/
|
|
41
|
+
export declare function beginCalendarCreate(event: PointerEvent, binding: CalendarCreateBinding): boolean;
|
|
42
|
+
/** Deslize horizontal: troca o período quando passa de um terço da largura ou foi "jogado" (`GESTURE_FLING_VELOCITY`). */
|
|
43
|
+
export declare function calendarSwipeDecision(dx: number, velocityX: number, width: number): -1 | 0 | 1;
|
|
44
|
+
/**
|
|
45
|
+
* Liga o deslize horizontal entre períodos ao elemento (só toque, fora dos eventos e dos painéis; a rolagem vertical
|
|
46
|
+
* continua nativa). `progress(dx)` acompanha o dedo; `commit(dir)` troca o período (+1 = próximo; em `rtl`, a casca
|
|
47
|
+
* inverte); `cancel()` volta.
|
|
48
|
+
*/
|
|
49
|
+
export declare function bindCalendarSwipe(element: HTMLElement, handlers: {
|
|
50
|
+
progress(dx: number): void;
|
|
51
|
+
commit(direction: -1 | 1): void;
|
|
52
|
+
cancel(): void;
|
|
53
|
+
}): () => void;
|
|
54
|
+
/** Fator da pinça na grade de horas: de 0,5× a 2× da altura de hora padrão. */
|
|
55
|
+
export declare function calendarPinchFactor(startFactor: number, startDistance: number, distance: number): number;
|
|
56
|
+
/**
|
|
57
|
+
* Pinça com dois dedos no rolador da grade de horas: muda a altura da hora (`onScale(fator)`) preservando o horário sob o
|
|
58
|
+
* centro do gesto (o `scrollTop` é corrigido pela mesma razão).
|
|
59
|
+
*/
|
|
60
|
+
export declare function bindCalendarPinch(scroller: HTMLElement, onScale: (factor: number) => void, initial?: number): () => void;
|
|
61
|
+
/** O que a casca passa para um gesto na linha do tempo (criar, mover, redimensionar pelas duas pontas). */
|
|
62
|
+
export interface CalendarTimelineBinding {
|
|
63
|
+
readonly host: HTMLElement;
|
|
64
|
+
readonly date: string;
|
|
65
|
+
readonly mode: CalendarGestureMode;
|
|
66
|
+
readonly entry?: EventCalendarEntry;
|
|
67
|
+
readonly window: {
|
|
68
|
+
readonly start: number;
|
|
69
|
+
readonly end: number;
|
|
70
|
+
};
|
|
71
|
+
readonly step: number;
|
|
72
|
+
readonly defaultDuration: number;
|
|
73
|
+
readonly rtl: boolean;
|
|
74
|
+
preview(range: CalendarGestureRange | null): void;
|
|
75
|
+
commit(range: CalendarGestureRange, dragged: boolean): void;
|
|
76
|
+
cancel(): void;
|
|
77
|
+
}
|
|
78
|
+
/** As linhas medidas (`.hm-resource-calendar__track[data-resource]`). */
|
|
79
|
+
export declare function measureCalendarTimelineRows(host: HTMLElement): {
|
|
80
|
+
resourceId: string;
|
|
81
|
+
top: number;
|
|
82
|
+
bottom: number;
|
|
83
|
+
left: number;
|
|
84
|
+
right: number;
|
|
85
|
+
}[];
|
|
86
|
+
/**
|
|
87
|
+
* Começa um gesto na linha do tempo: criar no vazio da linha, ou mover/redimensionar um evento (entre horas e entre
|
|
88
|
+
* recursos). Mesmas regras de ponteiro da grade: limiar no mouse, pressão longa no toque, Esc cancela.
|
|
89
|
+
*/
|
|
90
|
+
export declare function beginCalendarTimelineGesture(event: PointerEvent, binding: CalendarTimelineBinding): boolean;
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ligação dos gestos da agenda ao DOM, a mesma nas duas cascas (Angular e React): seleção de um período por arraste
|
|
3
|
+
* (com pressão longa no toque), rolagem automática perto da borda e Esc para cancelar. O estado do gesto é o de
|
|
4
|
+
* `calendar-interaction` e o ponto sob o ponteiro vem de `calendar-hit` (geometrias medidas, sem `elementsFromPoint`).
|
|
5
|
+
*/
|
|
6
|
+
import { GESTURE_LONG_PRESS_MS, GESTURE_TAP_SLOP, bindDrag, isFling, movePan, panVelocity, startPan } from './gesture';
|
|
7
|
+
import { calendarSlotAt, calendarTimelineSlotAt } from './calendar-hit';
|
|
8
|
+
import { armCalendarGesture, calendarAutoScrollStep, calendarGestureRange, cancelCalendarGesture, endCalendarGesture, moveCalendarGesture, startCalendarGesture, } from './calendar-interaction';
|
|
9
|
+
/**
|
|
10
|
+
* Rola `scroller` quando o ponteiro chega a menos de uma linha de hora da borda, com velocidade proporcional à
|
|
11
|
+
* proximidade (até ~1 linha de hora a cada 150 ms). `onScroll(delta)` avisa quanto rolou (para o gesto recalcular).
|
|
12
|
+
*/
|
|
13
|
+
export function createCalendarAutoScroll(scroller, hourPx, onScroll) {
|
|
14
|
+
const view = scroller?.ownerDocument.defaultView;
|
|
15
|
+
let pointer = null;
|
|
16
|
+
let frame = 0;
|
|
17
|
+
const maxStep = Math.max(1, Math.round((hourPx * 16) / 150));
|
|
18
|
+
const tick = () => {
|
|
19
|
+
frame = 0;
|
|
20
|
+
if (!scroller || pointer === null)
|
|
21
|
+
return;
|
|
22
|
+
const rect = scroller.getBoundingClientRect();
|
|
23
|
+
const step = calendarAutoScrollStep(pointer, rect.top, rect.bottom, hourPx, maxStep);
|
|
24
|
+
if (!step)
|
|
25
|
+
return;
|
|
26
|
+
const before = scroller.scrollTop;
|
|
27
|
+
scroller.scrollTop = before + step;
|
|
28
|
+
const delta = scroller.scrollTop - before;
|
|
29
|
+
if (delta)
|
|
30
|
+
onScroll(delta);
|
|
31
|
+
if (delta && view)
|
|
32
|
+
frame = view.requestAnimationFrame(tick);
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
update(clientY) {
|
|
36
|
+
pointer = clientY;
|
|
37
|
+
if (!frame && view)
|
|
38
|
+
frame = view.requestAnimationFrame(tick);
|
|
39
|
+
},
|
|
40
|
+
stop() {
|
|
41
|
+
pointer = null;
|
|
42
|
+
if (frame && view)
|
|
43
|
+
view.cancelAnimationFrame(frame);
|
|
44
|
+
frame = 0;
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const pointerKind = (event) => (event.pointerType === 'touch' ? 'touch' : event.pointerType === 'pen' ? 'pen' : 'mouse');
|
|
49
|
+
/** As colunas (ou células do mês) medidas agora. */
|
|
50
|
+
export function measureCalendarColumns(host, timed) {
|
|
51
|
+
const selector = timed ? '.hm-event-calendar__column[data-date]' : '.hm-event-calendar__cell[data-date]';
|
|
52
|
+
return Array.from(host.querySelectorAll(selector)).map((el) => {
|
|
53
|
+
const r = el.getBoundingClientRect();
|
|
54
|
+
return { date: el.dataset['date'], resourceId: el.dataset['resource'] ?? null, left: r.left, right: r.right, top: r.top, bottom: r.bottom };
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Começa a seleção de um período no `pointerdown` de uma coluna (ou célula) vazia. Devolve `false` quando o alvo é um
|
|
59
|
+
* controle (evento, "+N", botão do dia): ali o gesto é outro. Mouse e caneta: arrasta depois do limiar; toque: só depois
|
|
60
|
+
* da pressão longa (antes disso o dedo rola a grade). Esc, `pointercancel` e a janela perder o foco cancelam.
|
|
61
|
+
*/
|
|
62
|
+
export function beginCalendarCreate(event, binding) {
|
|
63
|
+
const target = event.target;
|
|
64
|
+
if (!target || target.closest('button, a, input, [role="button"]'))
|
|
65
|
+
return false;
|
|
66
|
+
if (event.pointerType === 'mouse' && event.button !== 0)
|
|
67
|
+
return false;
|
|
68
|
+
const doc = binding.host.ownerDocument;
|
|
69
|
+
const view = doc.defaultView;
|
|
70
|
+
let columns = measureCalendarColumns(binding.host, binding.timed);
|
|
71
|
+
const slotAt = (x, y) => calendarSlotAt(columns, x, y, binding.window, binding.timed);
|
|
72
|
+
const origin = slotAt(event.clientX, event.clientY);
|
|
73
|
+
if (!origin)
|
|
74
|
+
return false;
|
|
75
|
+
let gesture = startCalendarGesture('create', origin, pointerKind(event), { x: event.clientX, y: event.clientY, time: event.timeStamp || Date.now() });
|
|
76
|
+
let last = { x: event.clientX, y: event.clientY };
|
|
77
|
+
const range = () => calendarGestureRange(gesture, { step: binding.step, defaultDuration: binding.defaultDuration });
|
|
78
|
+
const show = () => {
|
|
79
|
+
if (gesture.phase === 'dragging')
|
|
80
|
+
binding.preview(range());
|
|
81
|
+
};
|
|
82
|
+
const scroll = createCalendarAutoScroll(binding.timed ? binding.scroller : null, binding.hourPx, () => {
|
|
83
|
+
columns = measureCalendarColumns(binding.host, binding.timed);
|
|
84
|
+
const slot = slotAt(last.x, last.y);
|
|
85
|
+
if (slot)
|
|
86
|
+
gesture = { ...gesture, current: slot };
|
|
87
|
+
show();
|
|
88
|
+
});
|
|
89
|
+
// Toque: a pressão longa arma o gesto; dali em diante o dedo não rola a página.
|
|
90
|
+
const blockScroll = (e) => {
|
|
91
|
+
if (gesture.phase === 'dragging')
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
};
|
|
94
|
+
const timer = gesture.pointer === 'touch'
|
|
95
|
+
? view?.setTimeout(() => {
|
|
96
|
+
gesture = armCalendarGesture(gesture, gesture.startTime + GESTURE_LONG_PRESS_MS);
|
|
97
|
+
if (gesture.phase === 'dragging') {
|
|
98
|
+
view.navigator.vibrate?.(10);
|
|
99
|
+
show();
|
|
100
|
+
}
|
|
101
|
+
}, GESTURE_LONG_PRESS_MS)
|
|
102
|
+
: undefined;
|
|
103
|
+
const stop = () => {
|
|
104
|
+
if (timer !== undefined)
|
|
105
|
+
view?.clearTimeout(timer);
|
|
106
|
+
scroll.stop();
|
|
107
|
+
doc.removeEventListener('pointermove', move);
|
|
108
|
+
doc.removeEventListener('pointerup', up);
|
|
109
|
+
doc.removeEventListener('pointercancel', cancel);
|
|
110
|
+
doc.removeEventListener('keydown', key, true);
|
|
111
|
+
doc.removeEventListener('touchmove', blockScroll);
|
|
112
|
+
view?.removeEventListener('blur', cancel);
|
|
113
|
+
};
|
|
114
|
+
const move = (e) => {
|
|
115
|
+
if (e.pointerId !== event.pointerId)
|
|
116
|
+
return;
|
|
117
|
+
last = { x: e.clientX, y: e.clientY };
|
|
118
|
+
gesture = moveCalendarGesture(gesture, slotAt(e.clientX, e.clientY), { x: e.clientX, y: e.clientY, time: e.timeStamp || Date.now() });
|
|
119
|
+
if (gesture.phase === 'cancelled') {
|
|
120
|
+
stop();
|
|
121
|
+
binding.preview(null);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (gesture.phase === 'dragging') {
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
if (binding.timed)
|
|
127
|
+
scroll.update(e.clientY);
|
|
128
|
+
show();
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const up = (e) => {
|
|
132
|
+
if (e.pointerId !== event.pointerId)
|
|
133
|
+
return;
|
|
134
|
+
stop();
|
|
135
|
+
// Toque solto antes da pressão longa: foi toque (o clique do navegador cuida do `dateClick`), não criação.
|
|
136
|
+
if (gesture.pointer === 'touch' && gesture.phase === 'pressed') {
|
|
137
|
+
binding.preview(null);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
gesture = endCalendarGesture(gesture);
|
|
141
|
+
const r = range();
|
|
142
|
+
if (r)
|
|
143
|
+
binding.commit(r, gesture.dragged);
|
|
144
|
+
};
|
|
145
|
+
const cancel = () => {
|
|
146
|
+
stop();
|
|
147
|
+
gesture = cancelCalendarGesture(gesture);
|
|
148
|
+
binding.preview(null);
|
|
149
|
+
binding.cancel();
|
|
150
|
+
};
|
|
151
|
+
const key = (e) => {
|
|
152
|
+
if (e.key !== 'Escape')
|
|
153
|
+
return;
|
|
154
|
+
e.preventDefault();
|
|
155
|
+
e.stopPropagation();
|
|
156
|
+
cancel();
|
|
157
|
+
};
|
|
158
|
+
doc.addEventListener('pointermove', move);
|
|
159
|
+
doc.addEventListener('pointerup', up);
|
|
160
|
+
doc.addEventListener('pointercancel', cancel);
|
|
161
|
+
doc.addEventListener('keydown', key, true);
|
|
162
|
+
doc.addEventListener('touchmove', blockScroll, { passive: false });
|
|
163
|
+
view?.addEventListener('blur', cancel);
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
// ------------------------------------------------------------------ mobile: deslizar entre períodos e pinçar
|
|
167
|
+
/** Deslize horizontal: troca o período quando passa de um terço da largura ou foi "jogado" (`GESTURE_FLING_VELOCITY`). */
|
|
168
|
+
export function calendarSwipeDecision(dx, velocityX, width) {
|
|
169
|
+
if (width > 0 && Math.abs(dx) >= width / 3)
|
|
170
|
+
return dx < 0 ? 1 : -1;
|
|
171
|
+
if (isFling(velocityX) && Math.abs(dx) >= GESTURE_TAP_SLOP)
|
|
172
|
+
return velocityX < 0 ? 1 : -1;
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Liga o deslize horizontal entre períodos ao elemento (só toque, fora dos eventos e dos painéis; a rolagem vertical
|
|
177
|
+
* continua nativa). `progress(dx)` acompanha o dedo; `commit(dir)` troca o período (+1 = próximo; em `rtl`, a casca
|
|
178
|
+
* inverte); `cancel()` volta.
|
|
179
|
+
*/
|
|
180
|
+
export function bindCalendarSwipe(element, handlers) {
|
|
181
|
+
return bindDrag(element, {
|
|
182
|
+
start(event) {
|
|
183
|
+
if (event.pointerType !== 'touch')
|
|
184
|
+
return null;
|
|
185
|
+
const target = event.target;
|
|
186
|
+
if (target?.closest('.hm-event-calendar__event, .hm-event-calendar__panel, .hm-event-calendar__toolbar, button, input'))
|
|
187
|
+
return null;
|
|
188
|
+
return startPan({ x: event.clientX, y: event.clientY, time: event.timeStamp }, 'x');
|
|
189
|
+
},
|
|
190
|
+
move(state, event) {
|
|
191
|
+
const next = movePan(state, { x: event.clientX, y: event.clientY, time: event.timeStamp });
|
|
192
|
+
if (next.phase === 'began' || next.phase === 'changed')
|
|
193
|
+
handlers.progress(next.dx);
|
|
194
|
+
return next;
|
|
195
|
+
},
|
|
196
|
+
end(state, _event, completed) {
|
|
197
|
+
if (!completed || state.phase === 'failed' || state.phase === 'possible')
|
|
198
|
+
return handlers.cancel();
|
|
199
|
+
const dir = calendarSwipeDecision(state.dx, panVelocity(state).x, element.clientWidth);
|
|
200
|
+
if (dir)
|
|
201
|
+
handlers.commit(dir);
|
|
202
|
+
else
|
|
203
|
+
handlers.cancel();
|
|
204
|
+
},
|
|
205
|
+
}, { touchAction: 'pan-y' });
|
|
206
|
+
}
|
|
207
|
+
/** Fator da pinça na grade de horas: de 0,5× a 2× da altura de hora padrão. */
|
|
208
|
+
export function calendarPinchFactor(startFactor, startDistance, distance) {
|
|
209
|
+
if (!(startDistance > 0))
|
|
210
|
+
return startFactor;
|
|
211
|
+
return Math.min(2, Math.max(0.5, startFactor * (distance / startDistance)));
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Pinça com dois dedos no rolador da grade de horas: muda a altura da hora (`onScale(fator)`) preservando o horário sob o
|
|
215
|
+
* centro do gesto (o `scrollTop` é corrigido pela mesma razão).
|
|
216
|
+
*/
|
|
217
|
+
export function bindCalendarPinch(scroller, onScale, initial = 1) {
|
|
218
|
+
const touches = new Map();
|
|
219
|
+
let factor = initial;
|
|
220
|
+
let start = null;
|
|
221
|
+
const distance = () => {
|
|
222
|
+
const [a, b] = [...touches.values()];
|
|
223
|
+
return a && b ? Math.hypot(a.x - b.x, a.y - b.y) : 0;
|
|
224
|
+
};
|
|
225
|
+
const down = (e) => {
|
|
226
|
+
if (e.pointerType !== 'touch')
|
|
227
|
+
return;
|
|
228
|
+
touches.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
229
|
+
if (touches.size === 2)
|
|
230
|
+
start = { distance: distance(), factor };
|
|
231
|
+
};
|
|
232
|
+
const move = (e) => {
|
|
233
|
+
if (!touches.has(e.pointerId))
|
|
234
|
+
return;
|
|
235
|
+
touches.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
236
|
+
if (!start || touches.size !== 2)
|
|
237
|
+
return;
|
|
238
|
+
const next = calendarPinchFactor(start.factor, start.distance, distance());
|
|
239
|
+
if (next === factor)
|
|
240
|
+
return;
|
|
241
|
+
const [a, b] = [...touches.values()];
|
|
242
|
+
const rect = scroller.getBoundingClientRect();
|
|
243
|
+
const center = (a.y + b.y) / 2 - rect.top;
|
|
244
|
+
const ratio = next / factor;
|
|
245
|
+
factor = next;
|
|
246
|
+
onScale(factor);
|
|
247
|
+
scroller.scrollTop = Math.max(0, (scroller.scrollTop + center) * ratio - center);
|
|
248
|
+
};
|
|
249
|
+
const up = (e) => {
|
|
250
|
+
touches.delete(e.pointerId);
|
|
251
|
+
if (touches.size < 2)
|
|
252
|
+
start = null;
|
|
253
|
+
};
|
|
254
|
+
scroller.addEventListener('pointerdown', down);
|
|
255
|
+
scroller.addEventListener('pointermove', move);
|
|
256
|
+
scroller.addEventListener('pointerup', up);
|
|
257
|
+
scroller.addEventListener('pointercancel', up);
|
|
258
|
+
return () => {
|
|
259
|
+
scroller.removeEventListener('pointerdown', down);
|
|
260
|
+
scroller.removeEventListener('pointermove', move);
|
|
261
|
+
scroller.removeEventListener('pointerup', up);
|
|
262
|
+
scroller.removeEventListener('pointercancel', up);
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/** As linhas medidas (`.hm-resource-calendar__track[data-resource]`). */
|
|
266
|
+
export function measureCalendarTimelineRows(host) {
|
|
267
|
+
return Array.from(host.querySelectorAll('.hm-resource-calendar__track[data-resource]')).map((el) => {
|
|
268
|
+
const r = el.getBoundingClientRect();
|
|
269
|
+
return { resourceId: el.dataset['resource'], top: r.top, bottom: r.bottom, left: r.left, right: r.right };
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Começa um gesto na linha do tempo: criar no vazio da linha, ou mover/redimensionar um evento (entre horas e entre
|
|
274
|
+
* recursos). Mesmas regras de ponteiro da grade: limiar no mouse, pressão longa no toque, Esc cancela.
|
|
275
|
+
*/
|
|
276
|
+
export function beginCalendarTimelineGesture(event, binding) {
|
|
277
|
+
if (event.pointerType === 'mouse' && event.button !== 0)
|
|
278
|
+
return false;
|
|
279
|
+
const doc = binding.host.ownerDocument;
|
|
280
|
+
const view = doc.defaultView;
|
|
281
|
+
let rows = measureCalendarTimelineRows(binding.host);
|
|
282
|
+
const slotAt = (x, y) => calendarTimelineSlotAt(rows, binding.date, x, y, binding.window, binding.rtl);
|
|
283
|
+
const origin = slotAt(event.clientX, event.clientY);
|
|
284
|
+
if (!origin)
|
|
285
|
+
return false;
|
|
286
|
+
let gesture = startCalendarGesture(binding.mode, origin, pointerKind(event), { x: event.clientX, y: event.clientY, time: event.timeStamp || Date.now() }, { entry: binding.entry });
|
|
287
|
+
const range = () => calendarGestureRange(gesture, { step: binding.step, defaultDuration: binding.defaultDuration });
|
|
288
|
+
const timer = gesture.pointer === 'touch'
|
|
289
|
+
? view?.setTimeout(() => {
|
|
290
|
+
gesture = armCalendarGesture(gesture, gesture.startTime + GESTURE_LONG_PRESS_MS);
|
|
291
|
+
if (gesture.phase === 'dragging')
|
|
292
|
+
binding.preview(range());
|
|
293
|
+
}, GESTURE_LONG_PRESS_MS)
|
|
294
|
+
: undefined;
|
|
295
|
+
const blockScroll = (e) => {
|
|
296
|
+
if (gesture.phase === 'dragging')
|
|
297
|
+
e.preventDefault();
|
|
298
|
+
};
|
|
299
|
+
const stop = () => {
|
|
300
|
+
if (timer !== undefined)
|
|
301
|
+
view?.clearTimeout(timer);
|
|
302
|
+
doc.removeEventListener('pointermove', move);
|
|
303
|
+
doc.removeEventListener('pointerup', up);
|
|
304
|
+
doc.removeEventListener('pointercancel', cancel);
|
|
305
|
+
doc.removeEventListener('keydown', key, true);
|
|
306
|
+
doc.removeEventListener('touchmove', blockScroll);
|
|
307
|
+
};
|
|
308
|
+
const move = (e) => {
|
|
309
|
+
if (e.pointerId !== event.pointerId)
|
|
310
|
+
return;
|
|
311
|
+
rows = rows.length ? rows : measureCalendarTimelineRows(binding.host);
|
|
312
|
+
gesture = moveCalendarGesture(gesture, slotAt(e.clientX, e.clientY), { x: e.clientX, y: e.clientY, time: e.timeStamp || Date.now() });
|
|
313
|
+
if (gesture.phase === 'cancelled') {
|
|
314
|
+
stop();
|
|
315
|
+
binding.preview(null);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (gesture.phase === 'dragging') {
|
|
319
|
+
e.preventDefault();
|
|
320
|
+
binding.preview(range());
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
const up = (e) => {
|
|
324
|
+
if (e.pointerId !== event.pointerId)
|
|
325
|
+
return;
|
|
326
|
+
stop();
|
|
327
|
+
if (gesture.pointer === 'touch' && gesture.phase === 'pressed') {
|
|
328
|
+
binding.preview(null);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
gesture = endCalendarGesture(gesture);
|
|
332
|
+
const r = range();
|
|
333
|
+
binding.preview(null);
|
|
334
|
+
if (r && (gesture.dragged || binding.mode === 'create'))
|
|
335
|
+
binding.commit(r, gesture.dragged);
|
|
336
|
+
};
|
|
337
|
+
const cancel = () => {
|
|
338
|
+
stop();
|
|
339
|
+
gesture = cancelCalendarGesture(gesture);
|
|
340
|
+
binding.preview(null);
|
|
341
|
+
binding.cancel();
|
|
342
|
+
};
|
|
343
|
+
const key = (e) => {
|
|
344
|
+
if (e.key !== 'Escape')
|
|
345
|
+
return;
|
|
346
|
+
e.preventDefault();
|
|
347
|
+
e.stopPropagation();
|
|
348
|
+
cancel();
|
|
349
|
+
};
|
|
350
|
+
doc.addEventListener('pointermove', move);
|
|
351
|
+
doc.addEventListener('pointerup', up);
|
|
352
|
+
doc.addEventListener('pointercancel', cancel);
|
|
353
|
+
doc.addEventListener('keydown', key, true);
|
|
354
|
+
doc.addEventListener('touchmove', blockScroll, { passive: false });
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
//# sourceMappingURL=calendar-pointer.js.map
|