d2coreui 23.0.46 → 23.0.48

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.
@@ -0,0 +1,164 @@
1
+ import dayjs from "d2core/dayjs";
2
+ import i18n from "d2core/i18n/i18n";
3
+ export const MAX_QUICK_RANGES = 5;
4
+ export var IntervalDateType;
5
+ (function (IntervalDateType) {
6
+ IntervalDateType["CURRENT_DAY"] = "CURRENT_DAY";
7
+ IntervalDateType["SELECTED_DAY"] = "SELECTED_DAY";
8
+ })(IntervalDateType || (IntervalDateType = {}));
9
+ export var IntervalShiftUnit;
10
+ (function (IntervalShiftUnit) {
11
+ IntervalShiftUnit["DAY"] = "DAY";
12
+ IntervalShiftUnit["WEEK"] = "WEEK";
13
+ IntervalShiftUnit["MONTH"] = "MONTH";
14
+ IntervalShiftUnit["QUARTER"] = "QUARTER";
15
+ IntervalShiftUnit["YEAR"] = "YEAR";
16
+ })(IntervalShiftUnit || (IntervalShiftUnit = {}));
17
+ const DEFAULT_STORAGE_KEY = "d2coreui.dateRangeInput.intervals";
18
+ class LocalStorageIntervalStorage {
19
+ constructor(storageKey) {
20
+ this.storageKey = storageKey;
21
+ }
22
+ read(suffix) {
23
+ try {
24
+ const raw = window.localStorage.getItem(`${this.storageKey}.${suffix}`);
25
+ const parsed = raw ? JSON.parse(raw) : [];
26
+ return Promise.resolve(Array.isArray(parsed) ? parsed : []);
27
+ }
28
+ catch (error) {
29
+ return Promise.resolve([]);
30
+ }
31
+ }
32
+ write(suffix, value) {
33
+ try {
34
+ window.localStorage.setItem(`${this.storageKey}.${suffix}`, JSON.stringify(value));
35
+ }
36
+ catch (error) {
37
+ return Promise.reject(error);
38
+ }
39
+ return Promise.resolve();
40
+ }
41
+ loadQuickRanges() {
42
+ return this.read("quickRanges");
43
+ }
44
+ saveQuickRanges(ranges) {
45
+ return this.write("quickRanges", ranges);
46
+ }
47
+ loadIntervals() {
48
+ return this.read("savedIntervals");
49
+ }
50
+ saveIntervals(intervals) {
51
+ return this.write("savedIntervals", intervals);
52
+ }
53
+ }
54
+ export function resolveIntervalStorage(storage) {
55
+ if (storage === false) {
56
+ return null;
57
+ }
58
+ if (storage === undefined || storage === true) {
59
+ return new LocalStorageIntervalStorage(DEFAULT_STORAGE_KEY);
60
+ }
61
+ if ("storageKey" in storage) {
62
+ return new LocalStorageIntervalStorage(storage.storageKey);
63
+ }
64
+ return storage;
65
+ }
66
+ export function intervalShiftUnitName(unit) {
67
+ switch (unit) {
68
+ case IntervalShiftUnit.DAY:
69
+ return i18n("Day");
70
+ case IntervalShiftUnit.WEEK:
71
+ return i18n("Week");
72
+ case IntervalShiftUnit.MONTH:
73
+ return i18n("Month");
74
+ case IntervalShiftUnit.QUARTER:
75
+ return i18n("Quarter");
76
+ case IntervalShiftUnit.YEAR:
77
+ return i18n("Year");
78
+ }
79
+ }
80
+ export function intervalDateTypeName(dateType) {
81
+ switch (dateType) {
82
+ case IntervalDateType.CURRENT_DAY:
83
+ return i18n("Current Day");
84
+ case IntervalDateType.SELECTED_DAY:
85
+ return i18n("Selected Day");
86
+ }
87
+ }
88
+ function applyShift(base, unit, shift) {
89
+ switch (unit) {
90
+ case IntervalShiftUnit.DAY:
91
+ return base.add(shift, "day");
92
+ case IntervalShiftUnit.WEEK:
93
+ return base.add(shift, "week");
94
+ case IntervalShiftUnit.MONTH:
95
+ return base.add(shift, "month");
96
+ case IntervalShiftUnit.QUARTER:
97
+ return base.add(shift, "quarter");
98
+ case IntervalShiftUnit.YEAR:
99
+ return base.add(shift, "year");
100
+ }
101
+ }
102
+ export function resolveIntervalBound(bound, edge, now = dayjs()) {
103
+ var _a;
104
+ let base;
105
+ if (bound.dateType === IntervalDateType.CURRENT_DAY) {
106
+ base = now;
107
+ }
108
+ else {
109
+ if (!bound.date) {
110
+ return null;
111
+ }
112
+ base = dayjs(bound.date);
113
+ if (!base.isValid()) {
114
+ return null;
115
+ }
116
+ }
117
+ const anchored = edge === "from" ? base.startOf("day") : base.endOf("day");
118
+ return applyShift(anchored, bound.shiftUnit, (_a = bound.shift) !== null && _a !== void 0 ? _a : 0);
119
+ }
120
+ export function resolveInterval(interval, now = dayjs()) {
121
+ const from = resolveIntervalBound(interval.from, "from", now);
122
+ const to = resolveIntervalBound(interval.to, "to", now);
123
+ return from && to ? [from, to] : null;
124
+ }
125
+ export function validateInterval(interval) {
126
+ if (!interval.name.trim()) {
127
+ return i18n("Name must be filled in.");
128
+ }
129
+ for (const bound of [interval.from, interval.to]) {
130
+ if (bound.dateType === IntervalDateType.SELECTED_DAY && !bound.date) {
131
+ return i18n("Date must be filled in for the selected day.");
132
+ }
133
+ if (!Number.isInteger(bound.shift)) {
134
+ return i18n("Shift must be a whole number.");
135
+ }
136
+ }
137
+ const resolved = resolveInterval(interval);
138
+ if (!resolved) {
139
+ return i18n("Interval cannot be resolved.");
140
+ }
141
+ if (!resolved[0].isBefore(resolved[1])) {
142
+ return i18n("From must be before To.");
143
+ }
144
+ return null;
145
+ }
146
+ export function createEmptyInterval() {
147
+ const bound = () => ({
148
+ dateType: IntervalDateType.CURRENT_DAY,
149
+ date: null,
150
+ shiftUnit: IntervalShiftUnit.DAY,
151
+ shift: 0,
152
+ });
153
+ return {
154
+ id: `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,
155
+ name: "",
156
+ from: bound(),
157
+ to: bound(),
158
+ };
159
+ }
160
+ export function addQuickRange(ranges, from, to) {
161
+ const next = [{ from: from.toISOString(), to: to.toISOString() }, ...ranges];
162
+ return next.slice(0, MAX_QUICK_RANGES);
163
+ }
164
+ //# sourceMappingURL=savedIntervals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"savedIntervals.js","sourceRoot":"","sources":["../../../../components/date/savedIntervals.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,cAAc,CAAC;AACjC,OAAO,IAAI,MAAM,kBAAkB,CAAC;AAEpC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,MAAM,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AI,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import {Dayjs} from \"dayjs\";\r\nimport dayjs from \"d2core/dayjs\";\r\nimport i18n from \"d2core/i18n/i18n\";\r\n\r\nexport const MAX_QUICK_RANGES = 5;\r\n\r\nexport enum IntervalDateType {\r\n CURRENT_DAY = \"CURRENT_DAY\",\r\n SELECTED_DAY = \"SELECTED_DAY\",\r\n}\r\n\r\nexport enum IntervalShiftUnit {\r\n DAY = \"DAY\",\r\n WEEK = \"WEEK\",\r\n MONTH = \"MONTH\",\r\n QUARTER = \"QUARTER\",\r\n YEAR = \"YEAR\",\r\n}\r\n\r\nexport interface IntervalBound {\r\n dateType: IntervalDateType\r\n /** ISO 8601, only meaningful for {@link IntervalDateType.SELECTED_DAY} */\r\n date?: string | null\r\n shiftUnit: IntervalShiftUnit\r\n shift: number\r\n}\r\n\r\nexport interface SavedInterval {\r\n id: string\r\n name: string\r\n from: IntervalBound\r\n to: IntervalBound\r\n}\r\n\r\nexport interface QuickRange {\r\n /** ISO 8601 */\r\n from: string\r\n /** ISO 8601 */\r\n to: string\r\n}\r\n\r\nexport interface IntervalStorageProvider {\r\n loadQuickRanges(): Promise<QuickRange[]>\r\n\r\n saveQuickRanges(ranges: QuickRange[]): Promise<void>\r\n\r\n loadIntervals(): Promise<SavedInterval[]>\r\n\r\n saveIntervals(intervals: SavedInterval[]): Promise<void>\r\n}\r\n\r\nexport type IntervalStorage = boolean | { storageKey: string } | IntervalStorageProvider\r\n\r\nconst DEFAULT_STORAGE_KEY = \"d2coreui.dateRangeInput.intervals\";\r\n\r\nclass LocalStorageIntervalStorage implements IntervalStorageProvider {\r\n constructor(private readonly storageKey: string) {\r\n }\r\n\r\n private read<T>(suffix: string): Promise<T[]> {\r\n try {\r\n const raw = window.localStorage.getItem(`${this.storageKey}.${suffix}`);\r\n const parsed = raw ? JSON.parse(raw) : [];\r\n return Promise.resolve(Array.isArray(parsed) ? parsed : []);\r\n } catch (error) {\r\n return Promise.resolve([]);\r\n }\r\n }\r\n\r\n private write(suffix: string, value: unknown): Promise<void> {\r\n try {\r\n window.localStorage.setItem(`${this.storageKey}.${suffix}`, JSON.stringify(value));\r\n } catch (error) {\r\n return Promise.reject(error);\r\n }\r\n return Promise.resolve();\r\n }\r\n\r\n loadQuickRanges(): Promise<QuickRange[]> {\r\n return this.read<QuickRange>(\"quickRanges\");\r\n }\r\n\r\n saveQuickRanges(ranges: QuickRange[]): Promise<void> {\r\n return this.write(\"quickRanges\", ranges);\r\n }\r\n\r\n loadIntervals(): Promise<SavedInterval[]> {\r\n return this.read<SavedInterval>(\"savedIntervals\");\r\n }\r\n\r\n saveIntervals(intervals: SavedInterval[]): Promise<void> {\r\n return this.write(\"savedIntervals\", intervals);\r\n }\r\n}\r\n\r\nexport function resolveIntervalStorage(storage: IntervalStorage | undefined): IntervalStorageProvider | null {\r\n if (storage === false) {\r\n return null;\r\n }\r\n if (storage === undefined || storage === true) {\r\n return new LocalStorageIntervalStorage(DEFAULT_STORAGE_KEY);\r\n }\r\n if (\"storageKey\" in storage) {\r\n return new LocalStorageIntervalStorage(storage.storageKey);\r\n }\r\n return storage;\r\n}\r\n\r\nexport function intervalShiftUnitName(unit: IntervalShiftUnit): string {\r\n switch (unit) {\r\n case IntervalShiftUnit.DAY:\r\n return i18n(\"Day\");\r\n case IntervalShiftUnit.WEEK:\r\n return i18n(\"Week\");\r\n case IntervalShiftUnit.MONTH:\r\n return i18n(\"Month\");\r\n case IntervalShiftUnit.QUARTER:\r\n return i18n(\"Quarter\");\r\n case IntervalShiftUnit.YEAR:\r\n return i18n(\"Year\");\r\n }\r\n}\r\n\r\nexport function intervalDateTypeName(dateType: IntervalDateType): string {\r\n switch (dateType) {\r\n case IntervalDateType.CURRENT_DAY:\r\n return i18n(\"Current Day\");\r\n case IntervalDateType.SELECTED_DAY:\r\n return i18n(\"Selected Day\");\r\n }\r\n}\r\n\r\nfunction applyShift(base: Dayjs, unit: IntervalShiftUnit, shift: number): Dayjs {\r\n switch (unit) {\r\n case IntervalShiftUnit.DAY:\r\n return base.add(shift, \"day\");\r\n case IntervalShiftUnit.WEEK:\r\n return base.add(shift, \"week\");\r\n case IntervalShiftUnit.MONTH:\r\n return base.add(shift, \"month\");\r\n case IntervalShiftUnit.QUARTER:\r\n return base.add(shift, \"quarter\");\r\n case IntervalShiftUnit.YEAR:\r\n return base.add(shift, \"year\");\r\n }\r\n}\r\n\r\nexport function resolveIntervalBound(bound: IntervalBound, edge: \"from\" | \"to\", now: Dayjs = dayjs()): Dayjs | null {\r\n let base: Dayjs;\r\n if (bound.dateType === IntervalDateType.CURRENT_DAY) {\r\n base = now;\r\n } else {\r\n if (!bound.date) {\r\n return null;\r\n }\r\n base = dayjs(bound.date);\r\n if (!base.isValid()) {\r\n return null;\r\n }\r\n }\r\n const anchored = edge === \"from\" ? base.startOf(\"day\") : base.endOf(\"day\");\r\n return applyShift(anchored, bound.shiftUnit, bound.shift ?? 0);\r\n}\r\n\r\nexport function resolveInterval(interval: SavedInterval, now: Dayjs = dayjs()): [Dayjs, Dayjs] | null {\r\n const from = resolveIntervalBound(interval.from, \"from\", now);\r\n const to = resolveIntervalBound(interval.to, \"to\", now);\r\n return from && to ? [from, to] : null;\r\n}\r\n\r\nexport function validateInterval(interval: SavedInterval): string | null {\r\n if (!interval.name.trim()) {\r\n return i18n(\"Name must be filled in.\");\r\n }\r\n for (const bound of [interval.from, interval.to]) {\r\n if (bound.dateType === IntervalDateType.SELECTED_DAY && !bound.date) {\r\n return i18n(\"Date must be filled in for the selected day.\");\r\n }\r\n if (!Number.isInteger(bound.shift)) {\r\n return i18n(\"Shift must be a whole number.\");\r\n }\r\n }\r\n const resolved = resolveInterval(interval);\r\n if (!resolved) {\r\n return i18n(\"Interval cannot be resolved.\");\r\n }\r\n if (!resolved[0].isBefore(resolved[1])) {\r\n return i18n(\"From must be before To.\");\r\n }\r\n return null;\r\n}\r\n\r\nexport function createEmptyInterval(): SavedInterval {\r\n const bound = (): IntervalBound => ({\r\n dateType: IntervalDateType.CURRENT_DAY,\r\n date: null,\r\n shiftUnit: IntervalShiftUnit.DAY,\r\n shift: 0,\r\n });\r\n return {\r\n id: `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,\r\n name: \"\",\r\n from: bound(),\r\n to: bound(),\r\n };\r\n}\r\n\r\nexport function addQuickRange(ranges: QuickRange[], from: Dayjs, to: Dayjs): QuickRange[] {\r\n const next = [{from: from.toISOString(), to: to.toISOString()}, ...ranges];\r\n return next.slice(0, MAX_QUICK_RANGES);\r\n}\r\n"]}
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import { SavedInterval } from "./savedIntervals";
3
+ export interface SavedIntervalsDialogProps {
4
+ open: boolean;
5
+ intervals: SavedInterval[];
6
+ onSave(intervals: SavedInterval[]): Promise<void> | void;
7
+ onCancel(): void;
8
+ }
9
+ export default function SavedIntervalsDialog({ open, intervals, onSave, onCancel }: SavedIntervalsDialogProps): React.JSX.Element;
@@ -0,0 +1,220 @@
1
+ import React, { useEffect, useMemo, useRef, useState } from "react";
2
+ import { Button, Divider, Input, InputNumber, Select, Space, Typography } from "antd";
3
+ import { DeleteOutlined, PlusOutlined } from "@ant-design/icons";
4
+ import dayjs from "d2core/dayjs";
5
+ import i18n from "d2core/i18n/i18n";
6
+ import { LocaleHolder } from "d2core/i18n/localeHolder";
7
+ import { createStyles } from "antd-style";
8
+ import { ModalDialog } from "../modal/modalDialog";
9
+ import ExtendedDataGrid from "../grid/extendedDataGrid";
10
+ import DateTimeInput from "./dateTimeInput";
11
+ import { createEmptyInterval, IntervalDateType, intervalDateTypeName, IntervalShiftUnit, intervalShiftUnitName, resolveIntervalBound, validateInterval, } from "./savedIntervals";
12
+ const useStyles = createStyles(({ token, css }) => {
13
+ return {
14
+ invalidRow: css `
15
+ && .ag-cell {
16
+ color: ${token.colorError};
17
+ }
18
+ `,
19
+ grid: css `
20
+ height: 220px;
21
+ `,
22
+ };
23
+ });
24
+ const DATE_TYPES = [IntervalDateType.CURRENT_DAY, IntervalDateType.SELECTED_DAY];
25
+ const SHIFT_UNITS = [
26
+ IntervalShiftUnit.DAY,
27
+ IntervalShiftUnit.WEEK,
28
+ IntervalShiftUnit.MONTH,
29
+ IntervalShiftUnit.QUARTER,
30
+ IntervalShiftUnit.YEAR,
31
+ ];
32
+ export default function SavedIntervalsDialog({ open, intervals, onSave, onCancel }) {
33
+ var _a, _b, _c, _d;
34
+ const { styles } = useStyles();
35
+ const dateMask = LocaleHolder.getDateFormat(true);
36
+ const [draft, setDraft] = useState(intervals);
37
+ const [selectedId, setSelectedId] = useState((_b = (_a = intervals[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null);
38
+ const [saving, setSaving] = useState(false);
39
+ const bodyRef = useRef(null);
40
+ useEffect(() => {
41
+ var _a, _b;
42
+ if (open) {
43
+ setDraft(intervals);
44
+ setSelectedId((_b = (_a = intervals[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null);
45
+ }
46
+ }, [open, intervals]);
47
+ const errors = useMemo(() => {
48
+ const map = new Map();
49
+ draft.forEach(interval => {
50
+ const error = validateInterval(interval);
51
+ if (error) {
52
+ map.set(interval.id, error);
53
+ }
54
+ });
55
+ return map;
56
+ }, [draft]);
57
+ const selected = (_c = draft.find(interval => interval.id === selectedId)) !== null && _c !== void 0 ? _c : null;
58
+ const dirty = JSON.stringify(draft) !== JSON.stringify(intervals);
59
+ const updateSelected = (change) => {
60
+ if (!selected) {
61
+ return;
62
+ }
63
+ setDraft(draft.map(interval => interval.id === selected.id ? Object.assign(Object.assign({}, interval), change) : interval));
64
+ };
65
+ const updateBound = (edge, change) => {
66
+ if (!selected) {
67
+ return;
68
+ }
69
+ updateSelected({ [edge]: Object.assign(Object.assign({}, selected[edge]), change) });
70
+ };
71
+ const addInterval = () => {
72
+ const interval = createEmptyInterval();
73
+ setDraft([...draft, interval]);
74
+ setSelectedId(interval.id);
75
+ };
76
+ const removeSelected = () => {
77
+ var _a, _b;
78
+ if (!selected) {
79
+ return;
80
+ }
81
+ const index = draft.findIndex(interval => interval.id === selected.id);
82
+ const next = draft.filter(interval => interval.id !== selected.id);
83
+ setDraft(next);
84
+ setSelectedId((_b = (_a = next[Math.min(index, next.length - 1)]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null);
85
+ };
86
+ const formatBound = (bound, edge) => {
87
+ const resolved = resolveIntervalBound(bound, edge);
88
+ return resolved ? resolved.format(dateMask) : "-";
89
+ };
90
+ const boundColumns = (edge, title) => [
91
+ {
92
+ headerName: `${title} (${i18n("Shift Type")})`,
93
+ colId: `${edge}-shiftUnit`,
94
+ group: title,
95
+ initialWidth: 140,
96
+ valueGetter: (params) => params.data ? intervalShiftUnitName(params.data[edge].shiftUnit) : "",
97
+ },
98
+ {
99
+ headerName: `${title} (${i18n("Shift")})`,
100
+ colId: `${edge}-shift`,
101
+ group: title,
102
+ initialWidth: 100,
103
+ valueGetter: (params) => { var _a; return (_a = params.data) === null || _a === void 0 ? void 0 : _a[edge].shift; },
104
+ },
105
+ {
106
+ headerName: `${title} (${i18n("Date Type")})`,
107
+ colId: `${edge}-dateType`,
108
+ group: title,
109
+ initialWidth: 140,
110
+ valueGetter: (params) => params.data ? intervalDateTypeName(params.data[edge].dateType) : "",
111
+ },
112
+ {
113
+ headerName: `${title} (${i18n("Date")})`,
114
+ colId: `${edge}-date`,
115
+ group: title,
116
+ initialWidth: 130,
117
+ valueGetter: (params) => {
118
+ var _a;
119
+ const bound = (_a = params.data) === null || _a === void 0 ? void 0 : _a[edge];
120
+ return bound && bound.dateType === IntervalDateType.SELECTED_DAY && bound.date
121
+ ? dayjs(bound.date).format(dateMask)
122
+ : "";
123
+ },
124
+ },
125
+ ];
126
+ const columns = [
127
+ {
128
+ headerName: i18n("Index"),
129
+ colId: "index",
130
+ group: i18n("Basic Columns"),
131
+ initialWidth: 80,
132
+ valueGetter: (params) => params.data ? draft.findIndex(interval => interval.id === params.data.id) + 1 : "",
133
+ },
134
+ {
135
+ headerName: i18n("Name"),
136
+ colId: "name",
137
+ field: "name",
138
+ group: i18n("Basic Columns"),
139
+ initialWidth: 200,
140
+ },
141
+ ...boundColumns("from", i18n("From")),
142
+ ...boundColumns("to", i18n("To")),
143
+ ];
144
+ const renderBoundForm = (edge, title) => {
145
+ const bound = selected === null || selected === void 0 ? void 0 : selected[edge];
146
+ const selectedDay = (bound === null || bound === void 0 ? void 0 : bound.dateType) === IntervalDateType.SELECTED_DAY;
147
+ return (React.createElement(React.Fragment, null,
148
+ React.createElement(Divider, { orientation: "left", style: { margin: "8px 0" } }, title),
149
+ React.createElement("div", { style: { display: "grid", gridTemplateColumns: "auto 1fr auto 1fr", gap: 8, alignItems: "center" } },
150
+ React.createElement("span", null, i18n("Date Type")),
151
+ React.createElement(Select, { disabled: !selected, value: bound === null || bound === void 0 ? void 0 : bound.dateType, onChange: dateType => updateBound(edge, { dateType }), options: DATE_TYPES.map(type => ({ value: type, label: intervalDateTypeName(type) })) }),
152
+ React.createElement("span", null, i18n("Date")),
153
+ React.createElement(DateTimeInput, { mask: dateMask, allowClear: true, disabled: !selected || !selectedDay, value: selectedDay && (bound === null || bound === void 0 ? void 0 : bound.date) ? dayjs(bound.date) : null, getPopupContainer: () => { var _a; return (_a = bodyRef.current) !== null && _a !== void 0 ? _a : document.body; }, onChange: (value) => updateBound(edge, { date: value ? value.toISOString() : null }) }),
154
+ React.createElement("span", null, i18n("Shift Type")),
155
+ React.createElement(Select, { disabled: !selected, value: bound === null || bound === void 0 ? void 0 : bound.shiftUnit, onChange: shiftUnit => updateBound(edge, { shiftUnit }), options: SHIFT_UNITS.map(unit => ({ value: unit, label: intervalShiftUnitName(unit) })) }),
156
+ React.createElement("span", null, i18n("Shift")),
157
+ React.createElement(InputNumber, { style: { width: "100%" }, disabled: !selected, precision: 0, value: bound === null || bound === void 0 ? void 0 : bound.shift, onChange: shift => updateBound(edge, { shift: shift !== null && shift !== void 0 ? shift : 0 }) }))));
158
+ };
159
+ const close = () => {
160
+ if (!dirty) {
161
+ onCancel();
162
+ return;
163
+ }
164
+ ModalDialog.confirm({
165
+ mode: "YES_NO",
166
+ title: i18n("Discard changes?"),
167
+ content: i18n("The saved intervals have been changed. Close the dialog without saving?"),
168
+ onOk: onCancel,
169
+ });
170
+ };
171
+ return (React.createElement(ModalDialog, { mode: "OK_CANCEL", open: open, title: i18n("Saved Intervals Configuration"), initialWidth: 1000, initialHeight: 700, okText: i18n("Save"), okButtonProps: { disabled: errors.size > 0 }, confirmLoading: saving, onOk: async () => {
172
+ setSaving(true);
173
+ try {
174
+ await onSave(draft);
175
+ }
176
+ finally {
177
+ setSaving(false);
178
+ }
179
+ }, onCancel: close },
180
+ React.createElement("div", { ref: bodyRef, style: { position: "relative" } },
181
+ React.createElement("div", { className: styles.grid },
182
+ React.createElement(ExtendedDataGrid, { panelStyle: { padding: 0 }, defaultGridConfiguration: { pageSize: -1 }, onLoadData: (callback) => callback(draft.length), onRowDataUpdated: (event) => {
183
+ if (event.api.getDisplayedRowCount() > 0) {
184
+ event.api.hideOverlay();
185
+ }
186
+ else {
187
+ event.api.showNoRowsOverlay();
188
+ }
189
+ }, columnDefs: columns, rowData: draft, rowSelection: "single", selectedIds: selectedId ? [selectedId] : [], onSelectionChanged: (event) => { var _a, _b; return setSelectedId((_b = (_a = event.api.getSelectedRows()[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null); }, rowClassRules: {
190
+ [styles.invalidRow]: (params) => !!params.data && errors.has(params.data.id),
191
+ }, toolbar: {
192
+ toolbarButtons: (React.createElement(Space, null,
193
+ React.createElement(Button, { icon: React.createElement(PlusOutlined, null), onClick: addInterval }),
194
+ React.createElement(Button, { icon: React.createElement(DeleteOutlined, null), disabled: !selected, onClick: removeSelected }))),
195
+ } })),
196
+ React.createElement("div", { style: {
197
+ marginTop: 12,
198
+ display: "grid",
199
+ gridTemplateColumns: "auto 1fr",
200
+ gap: 8,
201
+ alignItems: "center"
202
+ } },
203
+ React.createElement("span", null, i18n("Name")),
204
+ React.createElement(Input, { disabled: !selected, value: (_d = selected === null || selected === void 0 ? void 0 : selected.name) !== null && _d !== void 0 ? _d : "", onChange: event => updateSelected({ name: event.target.value }) })),
205
+ renderBoundForm("from", i18n("From")),
206
+ renderBoundForm("to", i18n("To")),
207
+ React.createElement(Divider, { orientation: "left", style: { margin: "8px 0" } }, i18n("Result")),
208
+ React.createElement(Space, { size: "large" },
209
+ React.createElement("span", null,
210
+ i18n("From"),
211
+ ": ",
212
+ React.createElement(Typography.Text, { strong: true }, selected ? formatBound(selected.from, "from") : "-")),
213
+ React.createElement("span", null,
214
+ i18n("To"),
215
+ ": ",
216
+ React.createElement(Typography.Text, { strong: true }, selected ? formatBound(selected.to, "to") : "-"))),
217
+ selected && errors.has(selected.id) &&
218
+ React.createElement(Typography.Text, { type: "danger", style: { display: "block", marginTop: 8 } }, errors.get(selected.id)))));
219
+ }
220
+ //# sourceMappingURL=savedIntervalsDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"savedIntervalsDialog.js","sourceRoot":"","sources":["../../../../components/date/savedIntervalsDialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAC,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAClE,OAAO,EAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAC,MAAM,MAAM,CAAC;AACpF,OAAO,EAAC,cAAc,EAAE,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAG/D,OAAO,KAAK,MAAM,cAAc,CAAC;AACjC,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AACxC,OAAO,EAAC,WA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ography} from \"antd\";\r\nimport {DeleteOutlined, PlusOutlined} from \"@ant-design/icons\";\r\nimport {RowDataUpdatedEvent, SelectionChangedEvent, ValueGetterParams} from \"ag-grid-community\";\r\nimport {Dayjs} from \"dayjs\";\r\nimport dayjs from \"d2core/dayjs\";\r\nimport i18n from \"d2core/i18n/i18n\";\r\nimport {LocaleHolder} from \"d2core/i18n/localeHolder\";\r\nimport {createStyles} from \"antd-style\";\r\nimport {ModalDialog, ModalDialogMode} from \"../modal/modalDialog\";\r\nimport ExtendedDataGrid from \"../grid/extendedDataGrid\";\r\nimport {DataGridColDef} from \"../grid/dataGrid\";\r\nimport DateTimeInput from \"./dateTimeInput\";\r\nimport {\r\n createEmptyInterval,\r\n IntervalBound,\r\n IntervalDateType,\r\n intervalDateTypeName,\r\n IntervalShiftUnit,\r\n intervalShiftUnitName,\r\n resolveIntervalBound,\r\n SavedInterval,\r\n validateInterval,\r\n} from \"./savedIntervals\";\r\n\r\nexport interface SavedIntervalsDialogProps {\r\n open: boolean\r\n intervals: SavedInterval[]\r\n\r\n onSave(intervals: SavedInterval[]): Promise<void> | void\r\n\r\n onCancel(): void\r\n}\r\n\r\nconst useStyles = createStyles(({token, css}) => {\r\n return {\r\n invalidRow: css`\r\n && .ag-cell {\r\n color: ${token.colorError};\r\n }\r\n `,\r\n grid: css`\r\n height: 220px;\r\n `,\r\n }\r\n});\r\n\r\nconst DATE_TYPES = [IntervalDateType.CURRENT_DAY, IntervalDateType.SELECTED_DAY];\r\nconst SHIFT_UNITS = [\r\n IntervalShiftUnit.DAY,\r\n IntervalShiftUnit.WEEK,\r\n IntervalShiftUnit.MONTH,\r\n IntervalShiftUnit.QUARTER,\r\n IntervalShiftUnit.YEAR,\r\n];\r\n\r\nexport default function SavedIntervalsDialog({open, intervals, onSave, onCancel}: SavedIntervalsDialogProps) {\r\n const {styles} = useStyles();\r\n const dateMask = LocaleHolder.getDateFormat(true);\r\n const [draft, setDraft] = useState<SavedInterval[]>(intervals);\r\n const [selectedId, setSelectedId] = useState<string | null>(intervals[0]?.id ?? null);\r\n const [saving, setSaving] = useState(false);\r\n const bodyRef = useRef<HTMLDivElement>(null);\r\n\r\n useEffect(() => {\r\n if (open) {\r\n setDraft(intervals);\r\n setSelectedId(intervals[0]?.id ?? null);\r\n }\r\n }, [open, intervals]);\r\n\r\n const errors = useMemo(() => {\r\n const map = new Map<string, string>();\r\n draft.forEach(interval => {\r\n const error = validateInterval(interval);\r\n if (error) {\r\n map.set(interval.id, error);\r\n }\r\n });\r\n return map;\r\n }, [draft]);\r\n\r\n const selected = draft.find(interval => interval.id === selectedId) ?? null;\r\n const dirty = JSON.stringify(draft) !== JSON.stringify(intervals);\r\n\r\n const updateSelected = (change: Partial<SavedInterval>) => {\r\n if (!selected) {\r\n return;\r\n }\r\n setDraft(draft.map(interval => interval.id === selected.id ? {...interval, ...change} : interval));\r\n };\r\n\r\n const updateBound = (edge: \"from\" | \"to\", change: Partial<IntervalBound>) => {\r\n if (!selected) {\r\n return;\r\n }\r\n updateSelected({[edge]: {...selected[edge], ...change}} as Partial<SavedInterval>);\r\n };\r\n\r\n const addInterval = () => {\r\n const interval = createEmptyInterval();\r\n setDraft([...draft, interval]);\r\n setSelectedId(interval.id);\r\n };\r\n\r\n const removeSelected = () => {\r\n if (!selected) {\r\n return;\r\n }\r\n const index = draft.findIndex(interval => interval.id === selected.id);\r\n const next = draft.filter(interval => interval.id !== selected.id);\r\n setDraft(next);\r\n setSelectedId(next[Math.min(index, next.length - 1)]?.id ?? null);\r\n };\r\n\r\n const formatBound = (bound: IntervalBound, edge: \"from\" | \"to\") => {\r\n const resolved = resolveIntervalBound(bound, edge);\r\n return resolved ? resolved.format(dateMask) : \"-\";\r\n };\r\n\r\n const boundColumns = (edge: \"from\" | \"to\", title: string): DataGridColDef[] => [\r\n {\r\n headerName: `${title} (${i18n(\"Shift Type\")})`,\r\n colId: `${edge}-shiftUnit`,\r\n group: title,\r\n initialWidth: 140,\r\n valueGetter: (params: ValueGetterParams<SavedInterval>) =>\r\n params.data ? intervalShiftUnitName(params.data[edge].shiftUnit) : \"\",\r\n },\r\n {\r\n headerName: `${title} (${i18n(\"Shift\")})`,\r\n colId: `${edge}-shift`,\r\n group: title,\r\n initialWidth: 100,\r\n valueGetter: (params: ValueGetterParams<SavedInterval>) => params.data?.[edge].shift,\r\n },\r\n {\r\n headerName: `${title} (${i18n(\"Date Type\")})`,\r\n colId: `${edge}-dateType`,\r\n group: title,\r\n initialWidth: 140,\r\n valueGetter: (params: ValueGetterParams<SavedInterval>) =>\r\n params.data ? intervalDateTypeName(params.data[edge].dateType) : \"\",\r\n },\r\n {\r\n headerName: `${title} (${i18n(\"Date\")})`,\r\n colId: `${edge}-date`,\r\n group: title,\r\n initialWidth: 130,\r\n valueGetter: (params: ValueGetterParams<SavedInterval>) => {\r\n const bound = params.data?.[edge];\r\n return bound && bound.dateType === IntervalDateType.SELECTED_DAY && bound.date\r\n ? dayjs(bound.date).format(dateMask)\r\n : \"\";\r\n },\r\n },\r\n ];\r\n\r\n const columns: DataGridColDef[] = [\r\n {\r\n headerName: i18n(\"Index\"),\r\n colId: \"index\",\r\n group: i18n(\"Basic Columns\"),\r\n initialWidth: 80,\r\n valueGetter: (params: ValueGetterParams<SavedInterval>) =>\r\n params.data ? draft.findIndex(interval => interval.id === params.data!.id) + 1 : \"\",\r\n },\r\n {\r\n headerName: i18n(\"Name\"),\r\n colId: \"name\",\r\n field: \"name\",\r\n group: i18n(\"Basic Columns\"),\r\n initialWidth: 200,\r\n },\r\n ...boundColumns(\"from\", i18n(\"From\")),\r\n ...boundColumns(\"to\", i18n(\"To\")),\r\n ];\r\n\r\n const renderBoundForm = (edge: \"from\" | \"to\", title: string) => {\r\n const bound = selected?.[edge];\r\n const selectedDay = bound?.dateType === IntervalDateType.SELECTED_DAY;\r\n return (\r\n <>\r\n <Divider orientation=\"left\" style={{margin: \"8px 0\"}}>{title}</Divider>\r\n <div style={{display: \"grid\", gridTemplateColumns: \"auto 1fr auto 1fr\", gap: 8, alignItems: \"center\"}}>\r\n <span>{i18n(\"Date Type\")}</span>\r\n <Select\r\n disabled={!selected}\r\n value={bound?.dateType}\r\n onChange={dateType => updateBound(edge, {dateType})}\r\n options={DATE_TYPES.map(type => ({value: type, label: intervalDateTypeName(type)}))}\r\n />\r\n <span>{i18n(\"Date\")}</span>\r\n <DateTimeInput\r\n mask={dateMask}\r\n allowClear\r\n disabled={!selected || !selectedDay}\r\n value={selectedDay && bound?.date ? dayjs(bound.date) : null}\r\n getPopupContainer={() => bodyRef.current ?? document.body}\r\n onChange={(value: Dayjs | null) => updateBound(edge, {date: value ? value.toISOString() : null})}\r\n />\r\n <span>{i18n(\"Shift Type\")}</span>\r\n <Select\r\n disabled={!selected}\r\n value={bound?.shiftUnit}\r\n onChange={shiftUnit => updateBound(edge, {shiftUnit})}\r\n options={SHIFT_UNITS.map(unit => ({value: unit, label: intervalShiftUnitName(unit)}))}\r\n />\r\n <span>{i18n(\"Shift\")}</span>\r\n <InputNumber\r\n style={{width: \"100%\"}}\r\n disabled={!selected}\r\n precision={0}\r\n value={bound?.shift}\r\n onChange={shift => updateBound(edge, {shift: shift ?? 0})}\r\n />\r\n </div>\r\n </>\r\n );\r\n };\r\n\r\n const close = () => {\r\n if (!dirty) {\r\n onCancel();\r\n return;\r\n }\r\n ModalDialog.confirm({\r\n mode: ModalDialogMode.YES_NO,\r\n title: i18n(\"Discard changes?\"),\r\n content: i18n(\"The saved intervals have been changed. Close the dialog without saving?\"),\r\n onOk: onCancel,\r\n });\r\n };\r\n\r\n return (\r\n <ModalDialog\r\n mode={ModalDialogMode.OK_CANCEL}\r\n open={open}\r\n title={i18n(\"Saved Intervals Configuration\")}\r\n initialWidth={1000}\r\n initialHeight={700}\r\n okText={i18n(\"Save\")}\r\n okButtonProps={{disabled: errors.size > 0}}\r\n confirmLoading={saving}\r\n onOk={async () => {\r\n setSaving(true);\r\n try {\r\n await onSave(draft);\r\n } finally {\r\n setSaving(false);\r\n }\r\n }}\r\n onCancel={close}\r\n >\r\n <div ref={bodyRef} style={{position: \"relative\"}}>\r\n <div className={styles.grid}>\r\n <ExtendedDataGrid<SavedInterval>\r\n panelStyle={{padding: 0}}\r\n defaultGridConfiguration={{pageSize: -1}}\r\n onLoadData={(callback) => callback(draft.length)}\r\n onRowDataUpdated={(event: RowDataUpdatedEvent<SavedInterval>) => {\r\n if (event.api.getDisplayedRowCount() > 0) {\r\n event.api.hideOverlay();\r\n } else {\r\n event.api.showNoRowsOverlay();\r\n }\r\n }}\r\n columnDefs={columns}\r\n rowData={draft}\r\n rowSelection={\"single\"}\r\n selectedIds={selectedId ? [selectedId] : []}\r\n onSelectionChanged={(event: SelectionChangedEvent<SavedInterval>) =>\r\n setSelectedId(event.api.getSelectedRows()[0]?.id ?? null)}\r\n rowClassRules={{\r\n [styles.invalidRow]: (params) => !!params.data && errors.has(params.data.id),\r\n }}\r\n toolbar={{\r\n toolbarButtons: (\r\n <Space>\r\n <Button icon={<PlusOutlined/>} onClick={addInterval}/>\r\n <Button icon={<DeleteOutlined/>} disabled={!selected} onClick={removeSelected}/>\r\n </Space>\r\n ),\r\n }}\r\n />\r\n </div>\r\n <div style={{\r\n marginTop: 12,\r\n display: \"grid\",\r\n gridTemplateColumns: \"auto 1fr\",\r\n gap: 8,\r\n alignItems: \"center\"\r\n }}>\r\n <span>{i18n(\"Name\")}</span>\r\n <Input\r\n disabled={!selected}\r\n value={selected?.name ?? \"\"}\r\n onChange={event => updateSelected({name: event.target.value})}\r\n />\r\n </div>\r\n {renderBoundForm(\"from\", i18n(\"From\"))}\r\n {renderBoundForm(\"to\", i18n(\"To\"))}\r\n <Divider orientation=\"left\" style={{margin: \"8px 0\"}}>{i18n(\"Result\")}</Divider>\r\n <Space size=\"large\">\r\n <span>{i18n(\"From\")}: <Typography.Text\r\n strong>{selected ? formatBound(selected.from, \"from\") : \"-\"}</Typography.Text></span>\r\n <span>{i18n(\"To\")}: <Typography.Text\r\n strong>{selected ? formatBound(selected.to, \"to\") : \"-\"}</Typography.Text></span>\r\n </Space>\r\n {selected && errors.has(selected.id) &&\r\n <Typography.Text type=\"danger\"\r\n style={{display: \"block\", marginTop: 8}}>{errors.get(selected.id)}</Typography.Text>\r\n }\r\n </div>\r\n </ModalDialog>\r\n );\r\n}\r\n"]}
@@ -12,6 +12,8 @@ export const headerButtonGeometry = (token) => {
12
12
  export const useDraggableModalStyles = createStyles(({ token, css, prefixCls }) => {
13
13
  const modalCls = `.${prefixCls}-modal`;
14
14
  const contentPaddingInline = token.paddingContentHorizontalLG;
15
+ const scrollbarInset = token.paddingXS;
16
+ const bodyPaddingInline = contentPaddingInline - scrollbarInset;
15
17
  const headerButtons = headerButtonGeometry(token);
16
18
  const handleSize = 44;
17
19
  const handleOverhang = 10;
@@ -44,12 +46,13 @@ export const useDraggableModalStyles = createStyles(({ token, css, prefixCls })
44
46
  width: 100%;
45
47
  height: 100%;
46
48
  /*
47
- * Deliberate deviation from the antd 5 default: the content carries no vertical inset
48
- * at all. The top one belongs to the title (so the whole header area can be grabbed for
49
+ * Deliberate deviation from the antd 5 default: the content carries no inset at all.
50
+ * The top one belongs to the title (so the whole header area can be grabbed for
49
51
  * dragging) and the bottom one to the footer, which keeps both dividers surrounded by
50
- * padding instead of glued to the text. Horizontal inset is the antd default.
52
+ * padding instead of glued to the text. Horizontally it keeps only the slice the
53
+ * body's scrollbars are drawn in, so they never sit on the dialog edge.
51
54
  */
52
- padding: 0 ${contentPaddingInline}px;
55
+ padding: 0 ${scrollbarInset}px;
53
56
  }
54
57
 
55
58
  ${modalCls}-header,
@@ -57,12 +60,11 @@ export const useDraggableModalStyles = createStyles(({ token, css, prefixCls })
57
60
  flex: 0 0 auto;
58
61
  /*
59
62
  * When the app configures dividers (Modal headerBorderBottom / footerBorderTop
60
- * tokens - d2ui does), antd draws them on the header/footer box, which is inset by
61
- * the content padding. The line then stops short of the dialog edges and reads as
62
- * if the content had no padding. Bleed the box out to the content edges and keep
63
- * the title/buttons where they were.
63
+ * tokens - d2ui does), antd draws them on the header/footer box. Bleed the box back
64
+ * out over the content's scrollbar slice so the lines still span the dialog; the
65
+ * title/buttons keep their own full inset and do not move.
64
66
  */
65
- margin-inline: -${contentPaddingInline}px;
67
+ margin-inline: -${scrollbarInset}px;
66
68
  }
67
69
 
68
70
  /*
@@ -95,11 +97,24 @@ export const useDraggableModalStyles = createStyles(({ token, css, prefixCls })
95
97
  inset-inline-end: ${headerButtons.secondButtonInset}px;
96
98
  }
97
99
 
98
- /* the only part that shrinks/grows with the dialog; min-height:0 lets it actually shrink in a flex column */
100
+ /*
101
+ * The only part that shrinks/grows with the dialog; min-height:0 lets it actually shrink
102
+ * in a flex column.
103
+ *
104
+ * Most of the horizontal inset lives here and not on the content on purpose. The body is
105
+ * the scroll container, so anything sticking out of its content box becomes a horizontal
106
+ * scrollbar - and antd's own <Row gutter={n}> does exactly that: it sets
107
+ * margin-inline: -n/2 and is therefore n px wider than its parent (the matching padding
108
+ * on each Col puts the visible content back, so only the scrollbar shows it). With the
109
+ * whole inset on the content the body was flush with its children and every dialog whose
110
+ * form starts with a gutter row had a permanent n/2 px horizontal scrollbar. Owning the
111
+ * padding, the body absorbs those negative margins like a plain antd modal body does.
112
+ */
99
113
  ${modalCls}-body {
100
114
  flex: 1 1 auto;
101
115
  min-height: 0;
102
116
  overflow: auto;
117
+ padding-inline: ${bodyPaddingInline}px;
103
118
  }
104
119
  `,
105
120
  wrapWithoutFooter: css `
@@ -1 +1 @@
1
- {"version":3,"file":"draggableModalStyles.js","sourceRoot":"","sources":["../../../../../components/modal/impl/draggableModalStyles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AAgBxC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAwB,EAAE,EAAE;IAC7D,MAAM,IAAI,GAAG,KAAK,CAAC,aAAa,CAAC;IACjC,MAAM,YAAY,GAAG,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC,gBAAgB,GAAG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BAAiB,EAAE,GAAG,CAAA;cAChB,QAAQ,IAAI,QAAQ;kCACA,KAAK,CAAC,OAAO;;SAEtC;QACD,KAAK,EAAE,GAAG,CAAA;;;;;;;;uBAQK,KAAK,CAAC,OAAO,MAAM,oBAAoB;SACrD;QACD,YAAY,EAAE,GAAG,CAAA;;sBAEH,cAAc;uBACb,cAAc;qBAChB,UAAU;sBACT,UAAU;;SAEvB;QACD,iBAAiB,EAAE,GAAG,CAAA;;qBAET,cAAc,GAAG,KAAK,CAAC,UAAU;sBAChC,cAAc,GAAG,KAAK,CAAC,UAAU;qBAClC,UAAU;sBACT,UAAU;sBACV,KAAK,CAAC,aAAa,MAAM,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,iBAAiB;;;SAG/E;KACJ,CAAC;AACN,CAAC,CAAC,CAAC","sourcesContent":["import {createStyles} from \"antd-style\";\n\n/** the antd tokens the header-button geometry is derived from */\ninterface HeaderButtonToken {\n controlHeight: number\n padding: number\n marginXXS: number\n lineHeightHeading5: number\n fontSizeHeading5: number\n}\n\n/**\n * Geometry of the buttons in the top-right corner of the header. Mirrors antd's own close-button\n * math (prepareToken in antd/es/modal/style) so our maximize button lines up with antd's close\n * button, and so the title knows how much room to leave for them.\n */\nexport const headerButtonGeometry = (token: HeaderButtonToken) => {\n const size = token.controlHeight;\n const headerHeight = token.lineHeightHeading5 * token.fontSizeHeading5 + token.padding * 2;\n const inset = (headerHeight - size) / 2;\n const gap = token.marginXXS;\n return {\n /** inset-inline-end of the button sitting left of the close button */\n secondButtonInset: inset + size + gap,\n /** horizontal space the title has to leave free so `count` buttons do not cover it */\n reserve: (count: number): number => count <= 0 ? 0 : inset + count * size + (count - 1) * gap,\n }\n};\n\n/**\n * Styles of the resizable/draggable modal.\n *\n * Only what dragging + resizing actually needs is defined here (flex layout so the body can\n * grow/scroll, the drag cursor on the title, the resize handle). Everything that antd 5 styles\n * through its own Modal tokens - header/footer spacing, title typography - is deliberately NOT\n * overridden, so the dialog looks like a plain antd 5 Modal. The exception is the content inset,\n * see below.\n */\nexport const useDraggableModalStyles = createStyles(({token, css, prefixCls}) => {\n const modalCls = `.${prefixCls}-modal`;\n\n // horizontal inset of the content - antd's default contentPadding, mirrored here so the\n // header/footer dividers can be bled back out to the dialog edges\n const contentPaddingInline = token.paddingContentHorizontalLG;\n\n const headerButtons = headerButtonGeometry(token);\n\n // the grab area reaches slightly outside the content so it does not sit on top of the footer buttons\n const handleSize = 44;\n const handleOverhang = 10;\n // the visible corner marker inside the grab area\n const markerSize = 12;\n\n return {\n wrap: css`\n overflow: hidden !important;\n\n ${modalCls} {\n display: flex;\n max-width: none;\n transform-origin: 50% 50% !important;\n }\n\n /*\n * rc-dialog puts an unclassed wrapper div between .ant-modal and .ant-modal-content.\n * As a flex item with width:auto it only shrink-wraps its content, so the dialog would\n * not follow the resized width. The focus sentinels matched by the same selector keep\n * their inline width:0, so they are not affected.\n */\n ${modalCls} > div {\n width: 100%;\n }\n\n /* the height comes from the modal state - content has to fill it and lay the parts out vertically */\n ${modalCls}-content {\n display: flex;\n flex-direction: column;\n flex: 1;\n width: 100%;\n height: 100%;\n /*\n * Deliberate deviation from the antd 5 default: the content carries no vertical inset\n * at all. The top one belongs to the title (so the whole header area can be grabbed for\n * dragging) and the bottom one to the footer, which keeps both dividers surrounded by\n * padding instead of glued to the text. Horizontal inset is the antd default.\n */\n padding: 0 ${contentPaddingInline}px;\n }\n\n ${modalCls}-header,\n ${modalCls}-footer {\n flex: 0 0 auto;\n /*\n * When the app configures dividers (Modal headerBorderBottom / footerBorderTop\n * tokens - d2ui does), antd draws them on the header/footer box, which is inset by\n * the content padding. The line then stops short of the dialog edges and reads as\n * if the content had no padding. Bleed the box out to the content edges and keep\n * the title/buttons where they were.\n */\n margin-inline: -${contentPaddingInline}px;\n }\n\n /*\n * The header contributes no spacing of its own - all of it lives on the drag area inside\n * (see the title style below), so every pixel down to the divider drags the dialog. The gap\n * to the body stays at the antd default (marginXS) and sits below the divider.\n */\n ${modalCls}-header {\n padding: 0;\n margin-bottom: ${token.marginXS}px;\n }\n\n /*\n * Mirror of the header: the footer carries the content's bottom inset itself, so the\n * divider has padding below it instead of sitting right on the buttons. The gap above the\n * divider stays at the antd default (marginSM).\n */\n ${modalCls}-footer {\n padding: ${token.padding}px ${contentPaddingInline}px;\n margin-top: ${token.marginSM}px;\n }\n\n /*\n * The maximize button reuses antd's .ant-modal-close markup so it looks and behaves like\n * the close button next to it (hover, focus ring, icon size); it only gets parked one\n * button width to the left. antd positions the close button with a two-class selector, so\n * this override has to be at least as specific.\n */\n ${modalCls} .ant-design-draggable-modal-maximize {\n inset-inline-end: ${headerButtons.secondButtonInset}px;\n }\n\n /* the only part that shrinks/grows with the dialog; min-height:0 lets it actually shrink in a flex column */\n ${modalCls}-body {\n flex: 1 1 auto;\n min-height: 0;\n overflow: auto;\n }\n `,\n /*\n * The bottom inset normally lives on the footer (see above). Dialogs rendered without one -\n * every NO_BUTTONS ModalDialog, and anything passing footer={null} - would otherwise have\n * their content flush against the bottom edge, so the content takes the inset back. The\n * extra selector level is needed to outweigh the padding-block: 0 above.\n */\n wrapWithoutFooter: css`\n ${modalCls} ${modalCls}-content {\n padding-bottom: ${token.padding}px;\n }\n `,\n title: css`\n cursor: move;\n user-select: none;\n /*\n * Carries the whole header inset - the content's vertical padding and the horizontal\n * padding the header would otherwise have - so the entire header area is a drag handle,\n * right up to the dialog edges and down to the divider.\n */\n padding: ${token.padding}px ${contentPaddingInline}px;\n `,\n resizeHandle: css`\n position: absolute;\n right: -${handleOverhang}px;\n bottom: -${handleOverhang}px;\n width: ${handleSize}px;\n height: ${handleSize}px;\n cursor: se-resize;\n `,\n resizeHandleInner: css`\n position: absolute;\n right: ${handleOverhang + token.paddingXXS}px;\n bottom: ${handleOverhang + token.paddingXXS}px;\n width: ${markerSize}px;\n height: ${markerSize}px;\n border: ${token.lineWidthBold}px ${token.lineType} ${token.colorTextTertiary};\n border-top: 0;\n border-left: 0;\n `,\n };\n});\n"]}
1
+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,GAAG,EAAE,CAAC;IAEtB,OAAO;QACH,IAAI,EAAE,GAAG,CAAA;;;cAGH,QAAQ;;;;;;;;;;;;cAYR,QAAQ;;;;;cAKR,QAAQ;;;;;;;;;;;;;6BAaO,cAAc;;;cAG7B,QAAQ;cACR,QAAQ;;;;;;;;kCAQY,cAAc;;;;;;;;cAQlC,QAAQ;;iCAEW,KAAK,CAAC,QAAQ;;;;;;;;cAQjC,QAAQ;2BACK,KAAK,CAAC,OAAO,MAAM,oBAAoB;8BACpC,KAAK,CAAC,QAAQ;;;;;;;;;cAS9B,QAAQ;oCACc,aAAa,CAAC,iBAAiB;;;;;;;;;;;;;;;;cAgBrD,QAAQ;;;;kCAIY,iBAAiB;;SAE1C;QAOD,iBAAiB,EAAE,GAAG,CAAA;cAChB,QAAQ,IAAI,QAAQ;kCACA,KAAK,CAAC,OAAO;;SAEtC;QACD,KAAK,EAAE,GAAG,CAAA;;;;;;;;uBAQK,KAAK,CAAC,OAAO,MAAM,oBAAoB;SACrD;QACD,YAAY,EAAE,GAAG,CAAA;;sBAEH,cAAc;uBACb,cAAc;qBAChB,UAAU;sBACT,UAAU;;SAEvB;QACD,iBAAiB,EAAE,GAAG,CAAA;;qBAET,cAAc,GAAG,KAAK,CAAC,UAAU;sBAChC,cAAc,GAAG,KAAK,CAAC,UAAU;qBAClC,UAAU;sBACT,UAAU;sBACV,KAAK,CAAC,aAAa,MAAM,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,iBAAiB;;;SAG/E;KACJ,CAAC;AACN,CAAC,CAAC,CAAC","sourcesContent":["import {createStyles} from \"antd-style\";\n\n/** the antd tokens the header-button geometry is derived from */\ninterface HeaderButtonToken {\n controlHeight: number\n padding: number\n marginXXS: number\n lineHeightHeading5: number\n fontSizeHeading5: number\n}\n\n/**\n * Geometry of the buttons in the top-right corner of the header. Mirrors antd's own close-button\n * math (prepareToken in antd/es/modal/style) so our maximize button lines up with antd's close\n * button, and so the title knows how much room to leave for them.\n */\nexport const headerButtonGeometry = (token: HeaderButtonToken) => {\n const size = token.controlHeight;\n const headerHeight = token.lineHeightHeading5 * token.fontSizeHeading5 + token.padding * 2;\n const inset = (headerHeight - size) / 2;\n const gap = token.marginXXS;\n return {\n /** inset-inline-end of the button sitting left of the close button */\n secondButtonInset: inset + size + gap,\n /** horizontal space the title has to leave free so `count` buttons do not cover it */\n reserve: (count: number): number => count <= 0 ? 0 : inset + count * size + (count - 1) * gap,\n }\n};\n\n/**\n * Styles of the resizable/draggable modal.\n *\n * Only what dragging + resizing actually needs is defined here (flex layout so the body can\n * grow/scroll, the drag cursor on the title, the resize handle). Everything that antd 5 styles\n * through its own Modal tokens - header/footer spacing, title typography - is deliberately NOT\n * overridden, so the dialog looks like a plain antd 5 Modal. The exception is the content inset,\n * see below.\n */\nexport const useDraggableModalStyles = createStyles(({token, css, prefixCls}) => {\n const modalCls = `.${prefixCls}-modal`;\n\n // antd's default horizontal contentPadding, mirrored here because the parts carry it themselves\n const contentPaddingInline = token.paddingContentHorizontalLG;\n\n /*\n * That inset is split between the content and the body. The body is the scroll container, and a\n * scrollbar is always drawn at its border edge - so the content keeps the outer slice to push the\n * body's scrollbars off the dialog edge, and the body keeps the rest as the gap between a\n * scrollbar and the text (which is also what absorbs negative margins, see the body rule).\n */\n const scrollbarInset = token.paddingXS;\n const bodyPaddingInline = contentPaddingInline - scrollbarInset;\n\n const headerButtons = headerButtonGeometry(token);\n\n // the grab area reaches slightly outside the content so it does not sit on top of the footer buttons\n const handleSize = 44;\n const handleOverhang = 10;\n // the visible corner marker inside the grab area\n const markerSize = 12;\n\n return {\n wrap: css`\n overflow: hidden !important;\n\n ${modalCls} {\n display: flex;\n max-width: none;\n transform-origin: 50% 50% !important;\n }\n\n /*\n * rc-dialog puts an unclassed wrapper div between .ant-modal and .ant-modal-content.\n * As a flex item with width:auto it only shrink-wraps its content, so the dialog would\n * not follow the resized width. The focus sentinels matched by the same selector keep\n * their inline width:0, so they are not affected.\n */\n ${modalCls} > div {\n width: 100%;\n }\n\n /* the height comes from the modal state - content has to fill it and lay the parts out vertically */\n ${modalCls}-content {\n display: flex;\n flex-direction: column;\n flex: 1;\n width: 100%;\n height: 100%;\n /*\n * Deliberate deviation from the antd 5 default: the content carries no inset at all.\n * The top one belongs to the title (so the whole header area can be grabbed for\n * dragging) and the bottom one to the footer, which keeps both dividers surrounded by\n * padding instead of glued to the text. Horizontally it keeps only the slice the\n * body's scrollbars are drawn in, so they never sit on the dialog edge.\n */\n padding: 0 ${scrollbarInset}px;\n }\n\n ${modalCls}-header,\n ${modalCls}-footer {\n flex: 0 0 auto;\n /*\n * When the app configures dividers (Modal headerBorderBottom / footerBorderTop\n * tokens - d2ui does), antd draws them on the header/footer box. Bleed the box back\n * out over the content's scrollbar slice so the lines still span the dialog; the\n * title/buttons keep their own full inset and do not move.\n */\n margin-inline: -${scrollbarInset}px;\n }\n\n /*\n * The header contributes no spacing of its own - all of it lives on the drag area inside\n * (see the title style below), so every pixel down to the divider drags the dialog. The gap\n * to the body stays at the antd default (marginXS) and sits below the divider.\n */\n ${modalCls}-header {\n padding: 0;\n margin-bottom: ${token.marginXS}px;\n }\n\n /*\n * Mirror of the header: the footer carries the content's bottom inset itself, so the\n * divider has padding below it instead of sitting right on the buttons. The gap above the\n * divider stays at the antd default (marginSM).\n */\n ${modalCls}-footer {\n padding: ${token.padding}px ${contentPaddingInline}px;\n margin-top: ${token.marginSM}px;\n }\n\n /*\n * The maximize button reuses antd's .ant-modal-close markup so it looks and behaves like\n * the close button next to it (hover, focus ring, icon size); it only gets parked one\n * button width to the left. antd positions the close button with a two-class selector, so\n * this override has to be at least as specific.\n */\n ${modalCls} .ant-design-draggable-modal-maximize {\n inset-inline-end: ${headerButtons.secondButtonInset}px;\n }\n\n /*\n * The only part that shrinks/grows with the dialog; min-height:0 lets it actually shrink\n * in a flex column.\n *\n * Most of the horizontal inset lives here and not on the content on purpose. The body is\n * the scroll container, so anything sticking out of its content box becomes a horizontal\n * scrollbar - and antd's own <Row gutter={n}> does exactly that: it sets\n * margin-inline: -n/2 and is therefore n px wider than its parent (the matching padding\n * on each Col puts the visible content back, so only the scrollbar shows it). With the\n * whole inset on the content the body was flush with its children and every dialog whose\n * form starts with a gutter row had a permanent n/2 px horizontal scrollbar. Owning the\n * padding, the body absorbs those negative margins like a plain antd modal body does.\n */\n ${modalCls}-body {\n flex: 1 1 auto;\n min-height: 0;\n overflow: auto;\n padding-inline: ${bodyPaddingInline}px;\n }\n `,\n /*\n * The bottom inset normally lives on the footer (see above). Dialogs rendered without one -\n * every NO_BUTTONS ModalDialog, and anything passing footer={null} - would otherwise have\n * their content flush against the bottom edge, so the content takes the inset back. The\n * extra selector level is needed to outweigh the padding-block: 0 above.\n */\n wrapWithoutFooter: css`\n ${modalCls} ${modalCls}-content {\n padding-bottom: ${token.padding}px;\n }\n `,\n title: css`\n cursor: move;\n user-select: none;\n /*\n * Carries the whole header inset - the content's vertical padding and the horizontal\n * padding the header would otherwise have - so the entire header area is a drag handle,\n * right up to the dialog edges and down to the divider.\n */\n padding: ${token.padding}px ${contentPaddingInline}px;\n `,\n resizeHandle: css`\n position: absolute;\n right: -${handleOverhang}px;\n bottom: -${handleOverhang}px;\n width: ${handleSize}px;\n height: ${handleSize}px;\n cursor: se-resize;\n `,\n resizeHandleInner: css`\n position: absolute;\n right: ${handleOverhang + token.paddingXXS}px;\n bottom: ${handleOverhang + token.paddingXXS}px;\n width: ${markerSize}px;\n height: ${markerSize}px;\n border: ${token.lineWidthBold}px ${token.lineType} ${token.colorTextTertiary};\n border-top: 0;\n border-left: 0;\n `,\n };\n});\n"]}
@@ -100,5 +100,26 @@
100
100
  "First Page": "První strana",
101
101
  "Previous Page": "Předchozí strana",
102
102
  "Next Page": "Následující strana",
103
- "Last Page": "Poslední strana"
103
+ "Last Page": "Poslední strana",
104
+ "Index": "Index",
105
+ "Name": "Název",
106
+ "From": "Od",
107
+ "To": "Do",
108
+ "Date": "Datum",
109
+ "Date Type": "Typ data",
110
+ "Shift": "Posun",
111
+ "Shift Type": "Typ posunu",
112
+ "Save": "Uložit",
113
+ "Result": "Výsledek",
114
+ "Current Day": "Aktuální den",
115
+ "Selected Day": "Zvolený den",
116
+ "Save Current Interval to Quick Access": "Uložit aktuální interval do rychlého přístupu",
117
+ "Saved Intervals Configuration": "Konfigurace uložených intervalů",
118
+ "Discard changes?": "Zahodit změny?",
119
+ "The saved intervals have been changed. Close the dialog without saving?": "Uložené intervaly byly změněny. Zavřít okno bez uložení?",
120
+ "Name must be filled in.": "Název musí být vyplněn.",
121
+ "Date must be filled in for the selected day.": "U zvoleného dne musí být vyplněno datum.",
122
+ "Shift must be a whole number.": "Posun musí být celé číslo.",
123
+ "Interval cannot be resolved.": "Interval nelze vyhodnotit.",
124
+ "From must be before To.": "Od musí být dříve než Do."
104
125
  }