d2coreui 23.0.56 → 23.0.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/README.md +154 -154
- package/components/date/dateRangeInputAdvancedPanel.js +5 -5
- package/components/date/dateRangeInputAdvancedPanel.js.map +1 -1
- package/components/date/dateRangeInputConfirm.js +5 -5
- package/components/date/dateRangeInputConfirm.js.map +1 -1
- package/components/date/dateTimeInput.d.ts +12 -3
- package/components/date/dateTimeInput.js +72 -11
- package/components/date/dateTimeInput.js.map +1 -1
- package/components/grid/config/columnTransfer.js +61 -43
- package/components/grid/config/columnTransfer.js.map +1 -1
- package/components/grid/config/dataGridEditor.d.ts +4 -3
- package/components/grid/config/dataGridEditor.js +16 -4
- package/components/grid/config/dataGridEditor.js.map +1 -1
- package/components/grid/dataGrid.d.ts +20 -5
- package/components/grid/dataGrid.js +13 -7
- package/components/grid/dataGrid.js.map +1 -1
- package/components/grid/export/contextMenu.d.ts +3 -2
- package/components/grid/export/contextMenu.js.map +1 -1
- package/components/grid/export/worker/pdfExport.js.map +1 -1
- package/components/grid/extendedDataGrid.d.ts +11 -4
- package/components/grid/extendedDataGrid.js +34 -24
- package/components/grid/extendedDataGrid.js.map +1 -1
- package/components/grid/header/simpleHeader.d.ts +1 -1
- package/components/grid/header/simpleHeader.js +3 -2
- package/components/grid/header/simpleHeader.js.map +1 -1
- package/components/input/autoCompleteInput.d.ts +3 -0
- package/components/input/autoCompleteInput.js +18 -3
- package/components/input/autoCompleteInput.js.map +1 -1
- package/components/modal/impl/draggableModal.d.ts +1 -1
- package/components/modal/impl/draggableModal.js.map +1 -1
- package/components/modal/impl/draggableModalInner.js +23 -11
- package/components/modal/impl/draggableModalInner.js.map +1 -1
- package/components/modal/impl/draggableModalReducer.d.ts +2 -3
- package/components/modal/impl/draggableModalReducer.js +9 -7
- package/components/modal/impl/draggableModalReducer.js.map +1 -1
- package/components/modal/impl/draggableModalStyles.js +126 -126
- package/components/modal/impl/draggableModalStyles.js.map +1 -1
- package/components/modal/impl/resizeHandle.js.map +1 -1
- package/components/modal/modalDialog.d.ts +3 -2
- package/components/modal/modalDialog.js +3 -2
- package/components/modal/modalDialog.js.map +1 -1
- package/i18n/components.cs.json +2 -0
- package/i18n/components.sk.json +2 -0
- package/i18n/components.uk.json +2 -0
- package/package.json +1 -1
- package/style/index.less +240 -240
|
@@ -15,8 +15,12 @@ interface DateTimeInputProps extends Omit<HTMLAttributes<HTMLDivElement>, "onCha
|
|
|
15
15
|
* Editable tokens: `YYYY`, `YY`, `MM`, `DD`, `HH`, `mm`, `ss`, `SSS` and the UTC offset `Z` (`+02:00`) or
|
|
16
16
|
* `ZZ` (`+0200`); other characters are literals. Fields missing from the mask are taken from the start
|
|
17
17
|
* of the current day. A 2-digit year keeps the century of the previous value (without one, `> 70` means 19xx,
|
|
18
|
-
* otherwise 20xx).
|
|
19
|
-
*
|
|
18
|
+
* otherwise 20xx). A wall clock inside a DST gap and a day that does not exist (31.02.) are invalid.
|
|
19
|
+
* Including the UTC offset makes both instants of a DST fold enterable. `Z?` (`d2core/dayjs/ambiguousTime`) is shown as `Z` - always, so that the input
|
|
20
|
+
* does not change its layout while typed into.
|
|
21
|
+
* `HH?` (`d2core/dayjs/ambiguousTime`) is the hour shown as `A2` / `B2` in the repeated hour of a DST fold; `A` or
|
|
22
|
+
* `B` typed in place of the leading digit picks the occurrence, a repeated hour typed without it is the second
|
|
23
|
+
* one (`B`), a letter outside a DST fold is invalid.
|
|
20
24
|
*/
|
|
21
25
|
mask: string;
|
|
22
26
|
/**
|
|
@@ -129,7 +133,7 @@ interface MaskSegment {
|
|
|
129
133
|
index: number;
|
|
130
134
|
/** length of the segment in the rendered value */
|
|
131
135
|
length: number;
|
|
132
|
-
/** numeric field description - undefined for the UTC-offset segment */
|
|
136
|
+
/** numeric field description - undefined for the UTC-offset segment; the `HH?` segment has the `HH` entry */
|
|
133
137
|
entry: InfoEntry | undefined;
|
|
134
138
|
min: number;
|
|
135
139
|
max: number;
|
|
@@ -166,6 +170,11 @@ export default class DateTimeInput extends React.Component<DateTimeInputProps, D
|
|
|
166
170
|
/** The underlying `<input>` element, `undefined` before mount or with {@link DateTimeInputProps.renderAsCalendar}. */
|
|
167
171
|
get input(): HTMLInputElement | undefined;
|
|
168
172
|
private getLayout;
|
|
173
|
+
/**
|
|
174
|
+
* A typed text can stand for a value shown differently (`02` of a repeated hour is `B2`). When that value is the
|
|
175
|
+
* current one, the `value` prop does not change and MaskedInput would keep the typed text.
|
|
176
|
+
*/
|
|
177
|
+
private rewriteInputIfShownDifferently;
|
|
169
178
|
/** Moves the keyboard focus to the text input. */
|
|
170
179
|
focus(): void;
|
|
171
180
|
private canStep;
|
|
@@ -23,6 +23,7 @@ import { createStyles } from "antd-style";
|
|
|
23
23
|
import WithCss from "d2coreui/components/style/withCss";
|
|
24
24
|
import i18n from "d2core/i18n/i18n";
|
|
25
25
|
import { DEFAULT_FORMAT_CHARACTERS, ESCAPE_CHAR } from "d2coreui/components/input/mask/helpers";
|
|
26
|
+
import { AMBIGUOUS_HOUR_TOKEN, AMBIGUOUS_UTC_OFFSET_TOKEN, getWallClockInstants, replaceAmbiguousTimeTokens } from "d2core/dayjs/ambiguousTime";
|
|
26
27
|
const useStyles = createStyles(({ token, css }, props) => {
|
|
27
28
|
// antd colours prefix/suffix by status in every variant except borderless
|
|
28
29
|
const statusAffix = props.variant !== "borderless";
|
|
@@ -127,8 +128,11 @@ const OFFSET_TOKENS = [
|
|
|
127
128
|
* a literal of the generated pattern - letters of the mask are always turned into field slots.
|
|
128
129
|
*/
|
|
129
130
|
const SIGN_FORMAT_CHAR = "S";
|
|
130
|
-
|
|
131
|
+
/** MaskedInput format character for the leading position of the `HH?` hour - a digit, or `A`/`B` of a DST fold. */
|
|
132
|
+
const HOUR_LETTER_FORMAT_CHAR = "F";
|
|
133
|
+
const MASK_FORMAT_CHARACTERS = {
|
|
131
134
|
[SIGN_FORMAT_CHAR]: { validate: (char) => char === "+" || char === "-" },
|
|
135
|
+
[HOUR_LETTER_FORMAT_CHAR]: { validate: (char) => /^[0-9ABab]$/.test(char), transform: (char) => char.toUpperCase() },
|
|
132
136
|
};
|
|
133
137
|
const MAX_UTC_OFFSET_MINUTES = 14 * 60;
|
|
134
138
|
const MIN_TIME = dayjs.unix(0);
|
|
@@ -160,10 +164,13 @@ function findInfoEntry(token) {
|
|
|
160
164
|
return undefined;
|
|
161
165
|
}
|
|
162
166
|
function escapePatternChar(char) {
|
|
163
|
-
return char in DEFAULT_FORMAT_CHARACTERS || char
|
|
167
|
+
return char in DEFAULT_FORMAT_CHARACTERS || char in MASK_FORMAT_CHARACTERS || char === ESCAPE_CHAR
|
|
164
168
|
? ESCAPE_CHAR + char
|
|
165
169
|
: char;
|
|
166
170
|
}
|
|
171
|
+
function toInputMask(mask) {
|
|
172
|
+
return replaceAmbiguousTimeTokens(mask, (token) => token === AMBIGUOUS_UTC_OFFSET_TOKEN ? "Z" : token);
|
|
173
|
+
}
|
|
167
174
|
/**
|
|
168
175
|
* Walks the mask once and records, for every editable field, where it lands in the value as
|
|
169
176
|
* dayjs renders it. Both the MaskedInput pattern and the parser positions are derived from
|
|
@@ -186,6 +193,14 @@ function buildMaskLayout(mask) {
|
|
|
186
193
|
i += offset.token.length;
|
|
187
194
|
continue;
|
|
188
195
|
}
|
|
196
|
+
if (mask.startsWith(AMBIGUOUS_HOUR_TOKEN, i)) {
|
|
197
|
+
const found = findInfoEntry("HH");
|
|
198
|
+
segments.push({ token: AMBIGUOUS_HOUR_TOKEN, index: renderIndex, length: 2, entry: found.entry, min: found.min, max: found.max });
|
|
199
|
+
pattern += HOUR_LETTER_FORMAT_CHAR + "1";
|
|
200
|
+
renderIndex += 2;
|
|
201
|
+
i += AMBIGUOUS_HOUR_TOKEN.length;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
189
204
|
const token = NUMBER_TOKENS.find((t) => mask.startsWith(t, i));
|
|
190
205
|
const found = token !== undefined ? findInfoEntry(token) : undefined;
|
|
191
206
|
if (token !== undefined && found !== undefined) {
|
|
@@ -204,6 +219,14 @@ function buildMaskLayout(mask) {
|
|
|
204
219
|
}
|
|
205
220
|
const CALENDAR_ICON_WIDTH = 28;
|
|
206
221
|
let measureContext = null;
|
|
222
|
+
// CSS takes an unquoted family name only if it is made of identifiers - the canvas ignores the whole `font` when one
|
|
223
|
+
// is not (e.g. the token `fontFamily: "72"`) and keeps measuring in its default 10px font
|
|
224
|
+
function quoteFontFamilies(fontFamily) {
|
|
225
|
+
return fontFamily.split(",")
|
|
226
|
+
.map((family) => family.trim())
|
|
227
|
+
.map((family) => /^["']/.test(family) || /^-?[a-zA-Z_][\w-]*(\s+-?[a-zA-Z_][\w-]*)*$/.test(family) ? family : `"${family}"`)
|
|
228
|
+
.join(", ");
|
|
229
|
+
}
|
|
207
230
|
function measureTextWidth(text, font) {
|
|
208
231
|
measureContext !== null && measureContext !== void 0 ? measureContext : (measureContext = document.createElement("canvas").getContext("2d"));
|
|
209
232
|
if (!measureContext) {
|
|
@@ -248,7 +271,7 @@ export default class DateTimeInput extends React.Component {
|
|
|
248
271
|
}
|
|
249
272
|
};
|
|
250
273
|
this.layoutMask = props.mask;
|
|
251
|
-
this.layout = buildMaskLayout(props.mask);
|
|
274
|
+
this.layout = buildMaskLayout(toInputMask(props.mask));
|
|
252
275
|
this.state = {
|
|
253
276
|
valid: DateTimeInput.isValidValue(props.value, props.minDateTime, props.maxDateTime, props.allowClear),
|
|
254
277
|
currentPos: null,
|
|
@@ -298,10 +321,25 @@ export default class DateTimeInput extends React.Component {
|
|
|
298
321
|
getLayout() {
|
|
299
322
|
if (this.layoutMask !== this.props.mask) {
|
|
300
323
|
this.layoutMask = this.props.mask;
|
|
301
|
-
this.layout = buildMaskLayout(this.props.mask);
|
|
324
|
+
this.layout = buildMaskLayout(toInputMask(this.props.mask));
|
|
302
325
|
}
|
|
303
326
|
return this.layout;
|
|
304
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* A typed text can stand for a value shown differently (`02` of a repeated hour is `B2`). When that value is the
|
|
330
|
+
* current one, the `value` prop does not change and MaskedInput would keep the typed text.
|
|
331
|
+
*/
|
|
332
|
+
rewriteInputIfShownDifferently(inputString, time) {
|
|
333
|
+
const maskedInput = this.inputRef.current;
|
|
334
|
+
const shown = time.locale("locale.d2000").format(toInputMask(this.props.mask));
|
|
335
|
+
if (maskedInput === null || shown === inputString) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const { selectionStart, selectionEnd } = maskedInput.input;
|
|
339
|
+
maskedInput.mask.setValue(shown);
|
|
340
|
+
maskedInput.setInputValue(maskedInput.mask.getValue());
|
|
341
|
+
maskedInput.input.setSelectionRange(selectionStart, selectionEnd);
|
|
342
|
+
}
|
|
305
343
|
/** Moves the keyboard focus to the text input. */
|
|
306
344
|
focus() {
|
|
307
345
|
var _a;
|
|
@@ -491,8 +529,10 @@ export default class DateTimeInput extends React.Component {
|
|
|
491
529
|
*/
|
|
492
530
|
getInputTextWidth(fontFamily, fontSize) {
|
|
493
531
|
// all digits as "0" so that the width holds for any value, not just today's
|
|
494
|
-
|
|
495
|
-
|
|
532
|
+
// and as the widest hour of a DST fold
|
|
533
|
+
const mask = toInputMask(this.props.mask).replace(AMBIGUOUS_HOUR_TOKEN, "[B0]");
|
|
534
|
+
const sample = dayjs().locale("locale.d2000").format(mask).replace(/\d/g, "0");
|
|
535
|
+
return Math.ceil(measureTextWidth(sample, `${fontSize}px ${quoteFontFamilies(fontFamily)}`));
|
|
496
536
|
}
|
|
497
537
|
/** Renders the masked input with its calendar icon, without the popup. */
|
|
498
538
|
renderInput() {
|
|
@@ -530,7 +570,7 @@ export default class DateTimeInput extends React.Component {
|
|
|
530
570
|
event.stopPropagation();
|
|
531
571
|
}
|
|
532
572
|
} },
|
|
533
|
-
React.createElement(MaskedInput, { mask: this.getLayout().pattern, formatCharacters:
|
|
573
|
+
React.createElement(MaskedInput, { mask: this.getLayout().pattern, formatCharacters: MASK_FORMAT_CHARACTERS, variant: variant, status: mergedStatus, ref: this.inputRef, style: maskedInputStyle, size: size, value: (this.state.focused || unix !== D2000UnixTimeNullValue * 1000) ? ((_a = value === null || value === void 0 ? void 0 : value.locale("locale.d2000").format(toInputMask(this.props.mask))) !== null && _a !== void 0 ? _a : "") : "", placeholder: (!this.state.focused && unix === D2000UnixTimeNullValue * 1000) ? "Null Time" : undefined, onFocus: (event => {
|
|
534
574
|
event.target.selectionStart = event.target.selectionEnd = this.state.currentPos;
|
|
535
575
|
this.setState({ focused: true });
|
|
536
576
|
}), onBlur: () => {
|
|
@@ -540,6 +580,7 @@ export default class DateTimeInput extends React.Component {
|
|
|
540
580
|
const value = DateTimeInput.parseDateTimeFormat(this.props.value, inputString, this.getLayout(), event.target.selectionStart);
|
|
541
581
|
const valid = DateTimeInput.isValidValue(value.time, this.props.minDateTime, this.props.maxDateTime, this.props.allowClear) || (!!this.props.allowClear && !inputString);
|
|
542
582
|
if (value.time !== undefined && valid) {
|
|
583
|
+
this.rewriteInputIfShownDifferently(inputString, value.time);
|
|
543
584
|
onChange === null || onChange === void 0 ? void 0 : onChange(value.time.clone());
|
|
544
585
|
}
|
|
545
586
|
else if (!!this.props.allowClear && !inputString) {
|
|
@@ -642,6 +683,7 @@ export default class DateTimeInput extends React.Component {
|
|
|
642
683
|
// fields the mask does not carry keep the value they have in `base`
|
|
643
684
|
const nominal = DateTimeInput.toWallClock(base);
|
|
644
685
|
let time = base;
|
|
686
|
+
let occurrence = undefined;
|
|
645
687
|
// iterated in DATE_TIME_DATA_MAP order, not in mask order - the day has to be set after
|
|
646
688
|
// the year and the month so that it is not clamped by the month it is temporarily in
|
|
647
689
|
for (const v of DATE_TIME_DATA_MAP) {
|
|
@@ -649,7 +691,12 @@ export default class DateTimeInput extends React.Component {
|
|
|
649
691
|
if (segment === undefined) {
|
|
650
692
|
continue;
|
|
651
693
|
}
|
|
652
|
-
let
|
|
694
|
+
let text = value.substring(segment.index, segment.index + segment.length);
|
|
695
|
+
if (segment.token === AMBIGUOUS_HOUR_TOKEN && (text[0] === "A" || text[0] === "B")) {
|
|
696
|
+
occurrence = text[0];
|
|
697
|
+
text = text.substring(1);
|
|
698
|
+
}
|
|
699
|
+
let val = Number(text);
|
|
653
700
|
if (isNaN(val) || val < segment.min || val > segment.max) {
|
|
654
701
|
return invalid;
|
|
655
702
|
}
|
|
@@ -663,14 +710,28 @@ export default class DateTimeInput extends React.Component {
|
|
|
663
710
|
nominal[v.part] = val;
|
|
664
711
|
time = time === null || time === void 0 ? void 0 : time.set(v.unit === "d" ? 'D' : v.unit, val);
|
|
665
712
|
}
|
|
666
|
-
// `time` has already
|
|
667
|
-
// the
|
|
668
|
-
// of a DST fold are reachable
|
|
713
|
+
// `time` has already rolled a wall clock that does not exist (DST gap, 31.02.) over to another one, so the
|
|
714
|
+
// instant is rebuilt from the typed reading - with the UTC offset when the mask carries it, so that both sides
|
|
715
|
+
// of a DST fold are reachable
|
|
669
716
|
const offsetSegment = layout.segments.find((s) => s.entry === undefined);
|
|
670
717
|
if (offsetSegment !== undefined) {
|
|
671
718
|
const offset = DateTimeInput.parseUtcOffset(value.substring(offsetSegment.index, offsetSegment.index + offsetSegment.length));
|
|
672
719
|
time = offset === undefined ? undefined : DateTimeInput.resolveWallClock(nominal, offset);
|
|
673
720
|
}
|
|
721
|
+
else {
|
|
722
|
+
const utcMs = Date.UTC(nominal.y, nominal.M, nominal.D, nominal.h, nominal.m, nominal.s, nominal.ms);
|
|
723
|
+
const instants = getWallClockInstants(utcMs, (ms) => dayjs(ms))
|
|
724
|
+
.filter((instant) => DateTimeInput.isSameWallClock(DateTimeInput.toWallClock(instant), nominal));
|
|
725
|
+
if (occurrence !== undefined) {
|
|
726
|
+
time = instants.length === 2 ? instants[occurrence === "A" ? 0 : 1] : undefined;
|
|
727
|
+
}
|
|
728
|
+
else if (instants.length === 0) {
|
|
729
|
+
time = undefined;
|
|
730
|
+
}
|
|
731
|
+
else if (layout.segments.some((s) => s.token === AMBIGUOUS_HOUR_TOKEN)) {
|
|
732
|
+
time = instants[instants.length - 1];
|
|
733
|
+
}
|
|
734
|
+
}
|
|
674
735
|
if (time === undefined) {
|
|
675
736
|
return invalid;
|
|
676
737
|
}
|