sanity-plugin-recurring-dates 1.4.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +49 -0
- package/dist/index.js +1714 -4161
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2520 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +41 -35
- package/src/components/CustomRule/Monthly.tsx +1 -1
- package/src/utils.ts +1 -0
- package/dist/index.esm.js +0 -4950
- package/dist/index.esm.js.map +0 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2520 @@
|
|
|
1
|
+
import { set, unset, ObjectInputMember, defineField, definePlugin } from "sanity";
|
|
2
|
+
import { ChevronLeftIcon, ChevronRightIcon, CalendarIcon, WarningOutlineIcon, TrashIcon } from "@sanity/icons";
|
|
3
|
+
import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
|
|
4
|
+
import { Card, Text, Box, Grid, TextInput, useForwardedRef, Flex, Select, Button, useClickOutside, LayerProvider, Popover, Stack, Dialog, Radio } from "@sanity/ui";
|
|
5
|
+
import upperFirst from "lodash/upperFirst.js";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import React__default, { useState, createContext, forwardRef, useRef, useCallback, useEffect, useMemo, Fragment, PureComponent } from "react";
|
|
8
|
+
import { rrulestr, Weekday, RRule, datetime } from "rrule";
|
|
9
|
+
import { Feedback } from "sanity-plugin-utils";
|
|
10
|
+
import { toDate as toDate$1, format as format$1 } from "date-fns-tz";
|
|
11
|
+
import { format, parse, DEFAULT_DATE_FORMAT as DEFAULT_DATE_FORMAT$1, DEFAULT_TIME_FORMAT } from "@sanity/util/legacyDateFormat";
|
|
12
|
+
import require$$0 from "react-is";
|
|
13
|
+
import range from "lodash/range.js";
|
|
14
|
+
const DEFAULT_RECURRENCES = [
|
|
15
|
+
"RRULE:FREQ=DAILY;INTERVAL=1",
|
|
16
|
+
"RRULE:FREQ=WEEKLY;INTERVAL=1",
|
|
17
|
+
"RRULE:FREQ=MONTHLY;INTERVAL=1",
|
|
18
|
+
"RRULE:FREQ=YEARLY;INTERVAL=1"
|
|
19
|
+
], DEFAULT_CONFIG = {
|
|
20
|
+
defaultRecurrences: DEFAULT_RECURRENCES
|
|
21
|
+
}, DAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], DEFAULT_COUNTS = [
|
|
22
|
+
5,
|
|
23
|
+
// yearly
|
|
24
|
+
12,
|
|
25
|
+
// monthly
|
|
26
|
+
12,
|
|
27
|
+
// weekly
|
|
28
|
+
30
|
|
29
|
+
// daily
|
|
30
|
+
], validateRRuleString = (recurrence) => {
|
|
31
|
+
try {
|
|
32
|
+
return rrulestr(recurrence), !1;
|
|
33
|
+
} catch {
|
|
34
|
+
return !0;
|
|
35
|
+
}
|
|
36
|
+
}, validateRRuleStrings = (recurrences) => recurrences.some((recurrence) => validateRRuleString(recurrence));
|
|
37
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
38
|
+
if (r == null) return {};
|
|
39
|
+
var t = {};
|
|
40
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
41
|
+
if (e.indexOf(n) !== -1) continue;
|
|
42
|
+
t[n] = r[n];
|
|
43
|
+
}
|
|
44
|
+
return t;
|
|
45
|
+
}
|
|
46
|
+
function _extends() {
|
|
47
|
+
return _extends = Object.assign ? Object.assign.bind() : function(n) {
|
|
48
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
49
|
+
var t = arguments[e];
|
|
50
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
51
|
+
}
|
|
52
|
+
return n;
|
|
53
|
+
}, _extends.apply(null, arguments);
|
|
54
|
+
}
|
|
55
|
+
var propTypes$1 = { exports: {} };
|
|
56
|
+
/*
|
|
57
|
+
object-assign
|
|
58
|
+
(c) Sindre Sorhus
|
|
59
|
+
@license MIT
|
|
60
|
+
*/
|
|
61
|
+
var objectAssign, hasRequiredObjectAssign;
|
|
62
|
+
function requireObjectAssign() {
|
|
63
|
+
if (hasRequiredObjectAssign) return objectAssign;
|
|
64
|
+
hasRequiredObjectAssign = 1;
|
|
65
|
+
var getOwnPropertySymbols = Object.getOwnPropertySymbols, hasOwnProperty = Object.prototype.hasOwnProperty, propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
|
66
|
+
function toObject(val) {
|
|
67
|
+
if (val == null)
|
|
68
|
+
throw new TypeError("Object.assign cannot be called with null or undefined");
|
|
69
|
+
return Object(val);
|
|
70
|
+
}
|
|
71
|
+
function shouldUseNative() {
|
|
72
|
+
try {
|
|
73
|
+
if (!Object.assign)
|
|
74
|
+
return !1;
|
|
75
|
+
var test1 = new String("abc");
|
|
76
|
+
if (test1[5] = "de", Object.getOwnPropertyNames(test1)[0] === "5")
|
|
77
|
+
return !1;
|
|
78
|
+
for (var test2 = {}, i = 0; i < 10; i++)
|
|
79
|
+
test2["_" + String.fromCharCode(i)] = i;
|
|
80
|
+
var order2 = Object.getOwnPropertyNames(test2).map(function(n) {
|
|
81
|
+
return test2[n];
|
|
82
|
+
});
|
|
83
|
+
if (order2.join("") !== "0123456789")
|
|
84
|
+
return !1;
|
|
85
|
+
var test3 = {};
|
|
86
|
+
return "abcdefghijklmnopqrst".split("").forEach(function(letter) {
|
|
87
|
+
test3[letter] = letter;
|
|
88
|
+
}), Object.keys(Object.assign({}, test3)).join("") === "abcdefghijklmnopqrst";
|
|
89
|
+
} catch {
|
|
90
|
+
return !1;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return objectAssign = shouldUseNative() ? Object.assign : function(target, source) {
|
|
94
|
+
for (var from, to = toObject(target), symbols, s = 1; s < arguments.length; s++) {
|
|
95
|
+
from = Object(arguments[s]);
|
|
96
|
+
for (var key in from)
|
|
97
|
+
hasOwnProperty.call(from, key) && (to[key] = from[key]);
|
|
98
|
+
if (getOwnPropertySymbols) {
|
|
99
|
+
symbols = getOwnPropertySymbols(from);
|
|
100
|
+
for (var i = 0; i < symbols.length; i++)
|
|
101
|
+
propIsEnumerable.call(from, symbols[i]) && (to[symbols[i]] = from[symbols[i]]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return to;
|
|
105
|
+
}, objectAssign;
|
|
106
|
+
}
|
|
107
|
+
var ReactPropTypesSecret_1, hasRequiredReactPropTypesSecret;
|
|
108
|
+
function requireReactPropTypesSecret() {
|
|
109
|
+
if (hasRequiredReactPropTypesSecret) return ReactPropTypesSecret_1;
|
|
110
|
+
hasRequiredReactPropTypesSecret = 1;
|
|
111
|
+
var ReactPropTypesSecret = "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";
|
|
112
|
+
return ReactPropTypesSecret_1 = ReactPropTypesSecret, ReactPropTypesSecret_1;
|
|
113
|
+
}
|
|
114
|
+
var has, hasRequiredHas;
|
|
115
|
+
function requireHas() {
|
|
116
|
+
return hasRequiredHas || (hasRequiredHas = 1, has = Function.call.bind(Object.prototype.hasOwnProperty)), has;
|
|
117
|
+
}
|
|
118
|
+
var checkPropTypes_1, hasRequiredCheckPropTypes;
|
|
119
|
+
function requireCheckPropTypes() {
|
|
120
|
+
if (hasRequiredCheckPropTypes) return checkPropTypes_1;
|
|
121
|
+
hasRequiredCheckPropTypes = 1;
|
|
122
|
+
var printWarning = function() {
|
|
123
|
+
};
|
|
124
|
+
if (process.env.NODE_ENV !== "production") {
|
|
125
|
+
var ReactPropTypesSecret = requireReactPropTypesSecret(), loggedTypeFailures = {}, has2 = requireHas();
|
|
126
|
+
printWarning = function(text) {
|
|
127
|
+
var message = "Warning: " + text;
|
|
128
|
+
typeof console < "u" && console.error(message);
|
|
129
|
+
try {
|
|
130
|
+
throw new Error(message);
|
|
131
|
+
} catch {
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
|
|
136
|
+
if (process.env.NODE_ENV !== "production") {
|
|
137
|
+
for (var typeSpecName in typeSpecs)
|
|
138
|
+
if (has2(typeSpecs, typeSpecName)) {
|
|
139
|
+
var error;
|
|
140
|
+
try {
|
|
141
|
+
if (typeof typeSpecs[typeSpecName] != "function") {
|
|
142
|
+
var err = Error(
|
|
143
|
+
(componentName || "React class") + ": " + location + " type `" + typeSpecName + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof typeSpecs[typeSpecName] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."
|
|
144
|
+
);
|
|
145
|
+
throw err.name = "Invariant Violation", err;
|
|
146
|
+
}
|
|
147
|
+
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
|
|
148
|
+
} catch (ex) {
|
|
149
|
+
error = ex;
|
|
150
|
+
}
|
|
151
|
+
if (error && !(error instanceof Error) && printWarning(
|
|
152
|
+
(componentName || "React class") + ": type specification of " + location + " `" + typeSpecName + "` is invalid; the type checker function must return `null` or an `Error` but returned a " + typeof error + ". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."
|
|
153
|
+
), error instanceof Error && !(error.message in loggedTypeFailures)) {
|
|
154
|
+
loggedTypeFailures[error.message] = !0;
|
|
155
|
+
var stack = getStack ? getStack() : "";
|
|
156
|
+
printWarning(
|
|
157
|
+
"Failed " + location + " type: " + error.message + (stack ?? "")
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return checkPropTypes.resetWarningCache = function() {
|
|
164
|
+
process.env.NODE_ENV !== "production" && (loggedTypeFailures = {});
|
|
165
|
+
}, checkPropTypes_1 = checkPropTypes, checkPropTypes_1;
|
|
166
|
+
}
|
|
167
|
+
var factoryWithTypeCheckers, hasRequiredFactoryWithTypeCheckers;
|
|
168
|
+
function requireFactoryWithTypeCheckers() {
|
|
169
|
+
if (hasRequiredFactoryWithTypeCheckers) return factoryWithTypeCheckers;
|
|
170
|
+
hasRequiredFactoryWithTypeCheckers = 1;
|
|
171
|
+
var ReactIs = require$$0, assign = requireObjectAssign(), ReactPropTypesSecret = requireReactPropTypesSecret(), has2 = requireHas(), checkPropTypes = requireCheckPropTypes(), printWarning = function() {
|
|
172
|
+
};
|
|
173
|
+
process.env.NODE_ENV !== "production" && (printWarning = function(text) {
|
|
174
|
+
var message = "Warning: " + text;
|
|
175
|
+
typeof console < "u" && console.error(message);
|
|
176
|
+
try {
|
|
177
|
+
throw new Error(message);
|
|
178
|
+
} catch {
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
function emptyFunctionThatReturnsNull() {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
|
|
185
|
+
var ITERATOR_SYMBOL = typeof Symbol == "function" && Symbol.iterator, FAUX_ITERATOR_SYMBOL = "@@iterator";
|
|
186
|
+
function getIteratorFn(maybeIterable) {
|
|
187
|
+
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
|
|
188
|
+
if (typeof iteratorFn == "function")
|
|
189
|
+
return iteratorFn;
|
|
190
|
+
}
|
|
191
|
+
var ANONYMOUS = "<<anonymous>>", ReactPropTypes = {
|
|
192
|
+
array: createPrimitiveTypeChecker("array"),
|
|
193
|
+
bigint: createPrimitiveTypeChecker("bigint"),
|
|
194
|
+
bool: createPrimitiveTypeChecker("boolean"),
|
|
195
|
+
func: createPrimitiveTypeChecker("function"),
|
|
196
|
+
number: createPrimitiveTypeChecker("number"),
|
|
197
|
+
object: createPrimitiveTypeChecker("object"),
|
|
198
|
+
string: createPrimitiveTypeChecker("string"),
|
|
199
|
+
symbol: createPrimitiveTypeChecker("symbol"),
|
|
200
|
+
any: createAnyTypeChecker(),
|
|
201
|
+
arrayOf: createArrayOfTypeChecker,
|
|
202
|
+
element: createElementTypeChecker(),
|
|
203
|
+
elementType: createElementTypeTypeChecker(),
|
|
204
|
+
instanceOf: createInstanceTypeChecker,
|
|
205
|
+
node: createNodeChecker(),
|
|
206
|
+
objectOf: createObjectOfTypeChecker,
|
|
207
|
+
oneOf: createEnumTypeChecker,
|
|
208
|
+
oneOfType: createUnionTypeChecker,
|
|
209
|
+
shape: createShapeTypeChecker,
|
|
210
|
+
exact: createStrictShapeTypeChecker
|
|
211
|
+
};
|
|
212
|
+
function is(x, y) {
|
|
213
|
+
return x === y ? x !== 0 || 1 / x === 1 / y : x !== x && y !== y;
|
|
214
|
+
}
|
|
215
|
+
function PropTypeError(message, data) {
|
|
216
|
+
this.message = message, this.data = data && typeof data == "object" ? data : {}, this.stack = "";
|
|
217
|
+
}
|
|
218
|
+
PropTypeError.prototype = Error.prototype;
|
|
219
|
+
function createChainableTypeChecker(validate) {
|
|
220
|
+
if (process.env.NODE_ENV !== "production")
|
|
221
|
+
var manualPropTypeCallCache = {}, manualPropTypeWarningCount = 0;
|
|
222
|
+
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
|
|
223
|
+
if (componentName = componentName || ANONYMOUS, propFullName = propFullName || propName, secret !== ReactPropTypesSecret) {
|
|
224
|
+
if (throwOnDirectAccess) {
|
|
225
|
+
var err = new Error(
|
|
226
|
+
"Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types"
|
|
227
|
+
);
|
|
228
|
+
throw err.name = "Invariant Violation", err;
|
|
229
|
+
} else if (process.env.NODE_ENV !== "production" && typeof console < "u") {
|
|
230
|
+
var cacheKey = componentName + ":" + propName;
|
|
231
|
+
!manualPropTypeCallCache[cacheKey] && // Avoid spamming the console because they are often not actionable except for lib authors
|
|
232
|
+
manualPropTypeWarningCount < 3 && (printWarning(
|
|
233
|
+
"You are manually calling a React.PropTypes validation function for the `" + propFullName + "` prop on `" + componentName + "`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details."
|
|
234
|
+
), manualPropTypeCallCache[cacheKey] = !0, manualPropTypeWarningCount++);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return props[propName] == null ? isRequired ? props[propName] === null ? new PropTypeError("The " + location + " `" + propFullName + "` is marked as required " + ("in `" + componentName + "`, but its value is `null`.")) : new PropTypeError("The " + location + " `" + propFullName + "` is marked as required in " + ("`" + componentName + "`, but its value is `undefined`.")) : null : validate(props, propName, componentName, location, propFullName);
|
|
238
|
+
}
|
|
239
|
+
var chainedCheckType = checkType.bind(null, !1);
|
|
240
|
+
return chainedCheckType.isRequired = checkType.bind(null, !0), chainedCheckType;
|
|
241
|
+
}
|
|
242
|
+
function createPrimitiveTypeChecker(expectedType) {
|
|
243
|
+
function validate(props, propName, componentName, location, propFullName, secret) {
|
|
244
|
+
var propValue = props[propName], propType = getPropType(propValue);
|
|
245
|
+
if (propType !== expectedType) {
|
|
246
|
+
var preciseType = getPreciseType(propValue);
|
|
247
|
+
return new PropTypeError(
|
|
248
|
+
"Invalid " + location + " `" + propFullName + "` of type " + ("`" + preciseType + "` supplied to `" + componentName + "`, expected ") + ("`" + expectedType + "`."),
|
|
249
|
+
{ expectedType }
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
return createChainableTypeChecker(validate);
|
|
255
|
+
}
|
|
256
|
+
function createAnyTypeChecker() {
|
|
257
|
+
return createChainableTypeChecker(emptyFunctionThatReturnsNull);
|
|
258
|
+
}
|
|
259
|
+
function createArrayOfTypeChecker(typeChecker) {
|
|
260
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
261
|
+
if (typeof typeChecker != "function")
|
|
262
|
+
return new PropTypeError("Property `" + propFullName + "` of component `" + componentName + "` has invalid PropType notation inside arrayOf.");
|
|
263
|
+
var propValue = props[propName];
|
|
264
|
+
if (!Array.isArray(propValue)) {
|
|
265
|
+
var propType = getPropType(propValue);
|
|
266
|
+
return new PropTypeError("Invalid " + location + " `" + propFullName + "` of type " + ("`" + propType + "` supplied to `" + componentName + "`, expected an array."));
|
|
267
|
+
}
|
|
268
|
+
for (var i = 0; i < propValue.length; i++) {
|
|
269
|
+
var error = typeChecker(propValue, i, componentName, location, propFullName + "[" + i + "]", ReactPropTypesSecret);
|
|
270
|
+
if (error instanceof Error)
|
|
271
|
+
return error;
|
|
272
|
+
}
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
return createChainableTypeChecker(validate);
|
|
276
|
+
}
|
|
277
|
+
function createElementTypeChecker() {
|
|
278
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
279
|
+
var propValue = props[propName];
|
|
280
|
+
if (!isValidElement(propValue)) {
|
|
281
|
+
var propType = getPropType(propValue);
|
|
282
|
+
return new PropTypeError("Invalid " + location + " `" + propFullName + "` of type " + ("`" + propType + "` supplied to `" + componentName + "`, expected a single ReactElement."));
|
|
283
|
+
}
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
return createChainableTypeChecker(validate);
|
|
287
|
+
}
|
|
288
|
+
function createElementTypeTypeChecker() {
|
|
289
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
290
|
+
var propValue = props[propName];
|
|
291
|
+
if (!ReactIs.isValidElementType(propValue)) {
|
|
292
|
+
var propType = getPropType(propValue);
|
|
293
|
+
return new PropTypeError("Invalid " + location + " `" + propFullName + "` of type " + ("`" + propType + "` supplied to `" + componentName + "`, expected a single ReactElement type."));
|
|
294
|
+
}
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
return createChainableTypeChecker(validate);
|
|
298
|
+
}
|
|
299
|
+
function createInstanceTypeChecker(expectedClass) {
|
|
300
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
301
|
+
if (!(props[propName] instanceof expectedClass)) {
|
|
302
|
+
var expectedClassName = expectedClass.name || ANONYMOUS, actualClassName = getClassName(props[propName]);
|
|
303
|
+
return new PropTypeError("Invalid " + location + " `" + propFullName + "` of type " + ("`" + actualClassName + "` supplied to `" + componentName + "`, expected ") + ("instance of `" + expectedClassName + "`."));
|
|
304
|
+
}
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
return createChainableTypeChecker(validate);
|
|
308
|
+
}
|
|
309
|
+
function createEnumTypeChecker(expectedValues) {
|
|
310
|
+
if (!Array.isArray(expectedValues))
|
|
311
|
+
return process.env.NODE_ENV !== "production" && (arguments.length > 1 ? printWarning(
|
|
312
|
+
"Invalid arguments supplied to oneOf, expected an array, got " + arguments.length + " arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z])."
|
|
313
|
+
) : printWarning("Invalid argument supplied to oneOf, expected an array.")), emptyFunctionThatReturnsNull;
|
|
314
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
315
|
+
for (var propValue = props[propName], i = 0; i < expectedValues.length; i++)
|
|
316
|
+
if (is(propValue, expectedValues[i]))
|
|
317
|
+
return null;
|
|
318
|
+
var valuesString = JSON.stringify(expectedValues, function(key, value) {
|
|
319
|
+
var type = getPreciseType(value);
|
|
320
|
+
return type === "symbol" ? String(value) : value;
|
|
321
|
+
});
|
|
322
|
+
return new PropTypeError("Invalid " + location + " `" + propFullName + "` of value `" + String(propValue) + "` " + ("supplied to `" + componentName + "`, expected one of " + valuesString + "."));
|
|
323
|
+
}
|
|
324
|
+
return createChainableTypeChecker(validate);
|
|
325
|
+
}
|
|
326
|
+
function createObjectOfTypeChecker(typeChecker) {
|
|
327
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
328
|
+
if (typeof typeChecker != "function")
|
|
329
|
+
return new PropTypeError("Property `" + propFullName + "` of component `" + componentName + "` has invalid PropType notation inside objectOf.");
|
|
330
|
+
var propValue = props[propName], propType = getPropType(propValue);
|
|
331
|
+
if (propType !== "object")
|
|
332
|
+
return new PropTypeError("Invalid " + location + " `" + propFullName + "` of type " + ("`" + propType + "` supplied to `" + componentName + "`, expected an object."));
|
|
333
|
+
for (var key in propValue)
|
|
334
|
+
if (has2(propValue, key)) {
|
|
335
|
+
var error = typeChecker(propValue, key, componentName, location, propFullName + "." + key, ReactPropTypesSecret);
|
|
336
|
+
if (error instanceof Error)
|
|
337
|
+
return error;
|
|
338
|
+
}
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
return createChainableTypeChecker(validate);
|
|
342
|
+
}
|
|
343
|
+
function createUnionTypeChecker(arrayOfTypeCheckers) {
|
|
344
|
+
if (!Array.isArray(arrayOfTypeCheckers))
|
|
345
|
+
return process.env.NODE_ENV !== "production" && printWarning("Invalid argument supplied to oneOfType, expected an instance of array."), emptyFunctionThatReturnsNull;
|
|
346
|
+
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
347
|
+
var checker = arrayOfTypeCheckers[i];
|
|
348
|
+
if (typeof checker != "function")
|
|
349
|
+
return printWarning(
|
|
350
|
+
"Invalid argument supplied to oneOfType. Expected an array of check functions, but received " + getPostfixForTypeWarning(checker) + " at index " + i + "."
|
|
351
|
+
), emptyFunctionThatReturnsNull;
|
|
352
|
+
}
|
|
353
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
354
|
+
for (var expectedTypes = [], i2 = 0; i2 < arrayOfTypeCheckers.length; i2++) {
|
|
355
|
+
var checker2 = arrayOfTypeCheckers[i2], checkerResult = checker2(props, propName, componentName, location, propFullName, ReactPropTypesSecret);
|
|
356
|
+
if (checkerResult == null)
|
|
357
|
+
return null;
|
|
358
|
+
checkerResult.data && has2(checkerResult.data, "expectedType") && expectedTypes.push(checkerResult.data.expectedType);
|
|
359
|
+
}
|
|
360
|
+
var expectedTypesMessage = expectedTypes.length > 0 ? ", expected one of type [" + expectedTypes.join(", ") + "]" : "";
|
|
361
|
+
return new PropTypeError("Invalid " + location + " `" + propFullName + "` supplied to " + ("`" + componentName + "`" + expectedTypesMessage + "."));
|
|
362
|
+
}
|
|
363
|
+
return createChainableTypeChecker(validate);
|
|
364
|
+
}
|
|
365
|
+
function createNodeChecker() {
|
|
366
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
367
|
+
return isNode(props[propName]) ? null : new PropTypeError("Invalid " + location + " `" + propFullName + "` supplied to " + ("`" + componentName + "`, expected a ReactNode."));
|
|
368
|
+
}
|
|
369
|
+
return createChainableTypeChecker(validate);
|
|
370
|
+
}
|
|
371
|
+
function invalidValidatorError(componentName, location, propFullName, key, type) {
|
|
372
|
+
return new PropTypeError(
|
|
373
|
+
(componentName || "React class") + ": " + location + " type `" + propFullName + "." + key + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + type + "`."
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
function createShapeTypeChecker(shapeTypes) {
|
|
377
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
378
|
+
var propValue = props[propName], propType = getPropType(propValue);
|
|
379
|
+
if (propType !== "object")
|
|
380
|
+
return new PropTypeError("Invalid " + location + " `" + propFullName + "` of type `" + propType + "` " + ("supplied to `" + componentName + "`, expected `object`."));
|
|
381
|
+
for (var key in shapeTypes) {
|
|
382
|
+
var checker = shapeTypes[key];
|
|
383
|
+
if (typeof checker != "function")
|
|
384
|
+
return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
|
|
385
|
+
var error = checker(propValue, key, componentName, location, propFullName + "." + key, ReactPropTypesSecret);
|
|
386
|
+
if (error)
|
|
387
|
+
return error;
|
|
388
|
+
}
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
return createChainableTypeChecker(validate);
|
|
392
|
+
}
|
|
393
|
+
function createStrictShapeTypeChecker(shapeTypes) {
|
|
394
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
395
|
+
var propValue = props[propName], propType = getPropType(propValue);
|
|
396
|
+
if (propType !== "object")
|
|
397
|
+
return new PropTypeError("Invalid " + location + " `" + propFullName + "` of type `" + propType + "` " + ("supplied to `" + componentName + "`, expected `object`."));
|
|
398
|
+
var allKeys = assign({}, props[propName], shapeTypes);
|
|
399
|
+
for (var key in allKeys) {
|
|
400
|
+
var checker = shapeTypes[key];
|
|
401
|
+
if (has2(shapeTypes, key) && typeof checker != "function")
|
|
402
|
+
return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
|
|
403
|
+
if (!checker)
|
|
404
|
+
return new PropTypeError(
|
|
405
|
+
"Invalid " + location + " `" + propFullName + "` key `" + key + "` supplied to `" + componentName + "`.\nBad object: " + JSON.stringify(props[propName], null, " ") + `
|
|
406
|
+
Valid keys: ` + JSON.stringify(Object.keys(shapeTypes), null, " ")
|
|
407
|
+
);
|
|
408
|
+
var error = checker(propValue, key, componentName, location, propFullName + "." + key, ReactPropTypesSecret);
|
|
409
|
+
if (error)
|
|
410
|
+
return error;
|
|
411
|
+
}
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
return createChainableTypeChecker(validate);
|
|
415
|
+
}
|
|
416
|
+
function isNode(propValue) {
|
|
417
|
+
switch (typeof propValue) {
|
|
418
|
+
case "number":
|
|
419
|
+
case "string":
|
|
420
|
+
case "undefined":
|
|
421
|
+
return !0;
|
|
422
|
+
case "boolean":
|
|
423
|
+
return !propValue;
|
|
424
|
+
case "object":
|
|
425
|
+
if (Array.isArray(propValue))
|
|
426
|
+
return propValue.every(isNode);
|
|
427
|
+
if (propValue === null || isValidElement(propValue))
|
|
428
|
+
return !0;
|
|
429
|
+
var iteratorFn = getIteratorFn(propValue);
|
|
430
|
+
if (iteratorFn) {
|
|
431
|
+
var iterator = iteratorFn.call(propValue), step;
|
|
432
|
+
if (iteratorFn !== propValue.entries) {
|
|
433
|
+
for (; !(step = iterator.next()).done; )
|
|
434
|
+
if (!isNode(step.value))
|
|
435
|
+
return !1;
|
|
436
|
+
} else
|
|
437
|
+
for (; !(step = iterator.next()).done; ) {
|
|
438
|
+
var entry = step.value;
|
|
439
|
+
if (entry && !isNode(entry[1]))
|
|
440
|
+
return !1;
|
|
441
|
+
}
|
|
442
|
+
} else
|
|
443
|
+
return !1;
|
|
444
|
+
return !0;
|
|
445
|
+
default:
|
|
446
|
+
return !1;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function isSymbol(propType, propValue) {
|
|
450
|
+
return propType === "symbol" ? !0 : propValue ? propValue["@@toStringTag"] === "Symbol" || typeof Symbol == "function" && propValue instanceof Symbol : !1;
|
|
451
|
+
}
|
|
452
|
+
function getPropType(propValue) {
|
|
453
|
+
var propType = typeof propValue;
|
|
454
|
+
return Array.isArray(propValue) ? "array" : propValue instanceof RegExp ? "object" : isSymbol(propType, propValue) ? "symbol" : propType;
|
|
455
|
+
}
|
|
456
|
+
function getPreciseType(propValue) {
|
|
457
|
+
if (typeof propValue > "u" || propValue === null)
|
|
458
|
+
return "" + propValue;
|
|
459
|
+
var propType = getPropType(propValue);
|
|
460
|
+
if (propType === "object") {
|
|
461
|
+
if (propValue instanceof Date)
|
|
462
|
+
return "date";
|
|
463
|
+
if (propValue instanceof RegExp)
|
|
464
|
+
return "regexp";
|
|
465
|
+
}
|
|
466
|
+
return propType;
|
|
467
|
+
}
|
|
468
|
+
function getPostfixForTypeWarning(value) {
|
|
469
|
+
var type = getPreciseType(value);
|
|
470
|
+
switch (type) {
|
|
471
|
+
case "array":
|
|
472
|
+
case "object":
|
|
473
|
+
return "an " + type;
|
|
474
|
+
case "boolean":
|
|
475
|
+
case "date":
|
|
476
|
+
case "regexp":
|
|
477
|
+
return "a " + type;
|
|
478
|
+
default:
|
|
479
|
+
return type;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
function getClassName(propValue) {
|
|
483
|
+
return !propValue.constructor || !propValue.constructor.name ? ANONYMOUS : propValue.constructor.name;
|
|
484
|
+
}
|
|
485
|
+
return ReactPropTypes.checkPropTypes = checkPropTypes, ReactPropTypes.resetWarningCache = checkPropTypes.resetWarningCache, ReactPropTypes.PropTypes = ReactPropTypes, ReactPropTypes;
|
|
486
|
+
}, factoryWithTypeCheckers;
|
|
487
|
+
}
|
|
488
|
+
var factoryWithThrowingShims, hasRequiredFactoryWithThrowingShims;
|
|
489
|
+
function requireFactoryWithThrowingShims() {
|
|
490
|
+
if (hasRequiredFactoryWithThrowingShims) return factoryWithThrowingShims;
|
|
491
|
+
hasRequiredFactoryWithThrowingShims = 1;
|
|
492
|
+
var ReactPropTypesSecret = requireReactPropTypesSecret();
|
|
493
|
+
function emptyFunction() {
|
|
494
|
+
}
|
|
495
|
+
function emptyFunctionWithReset() {
|
|
496
|
+
}
|
|
497
|
+
return emptyFunctionWithReset.resetWarningCache = emptyFunction, factoryWithThrowingShims = function() {
|
|
498
|
+
function shim(props, propName, componentName, location, propFullName, secret) {
|
|
499
|
+
if (secret !== ReactPropTypesSecret) {
|
|
500
|
+
var err = new Error(
|
|
501
|
+
"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types"
|
|
502
|
+
);
|
|
503
|
+
throw err.name = "Invariant Violation", err;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
shim.isRequired = shim;
|
|
507
|
+
function getShim() {
|
|
508
|
+
return shim;
|
|
509
|
+
}
|
|
510
|
+
var ReactPropTypes = {
|
|
511
|
+
array: shim,
|
|
512
|
+
bigint: shim,
|
|
513
|
+
bool: shim,
|
|
514
|
+
func: shim,
|
|
515
|
+
number: shim,
|
|
516
|
+
object: shim,
|
|
517
|
+
string: shim,
|
|
518
|
+
symbol: shim,
|
|
519
|
+
any: shim,
|
|
520
|
+
arrayOf: getShim,
|
|
521
|
+
element: shim,
|
|
522
|
+
elementType: shim,
|
|
523
|
+
instanceOf: getShim,
|
|
524
|
+
node: shim,
|
|
525
|
+
objectOf: getShim,
|
|
526
|
+
oneOf: getShim,
|
|
527
|
+
oneOfType: getShim,
|
|
528
|
+
shape: getShim,
|
|
529
|
+
exact: getShim,
|
|
530
|
+
checkPropTypes: emptyFunctionWithReset,
|
|
531
|
+
resetWarningCache: emptyFunction
|
|
532
|
+
};
|
|
533
|
+
return ReactPropTypes.PropTypes = ReactPropTypes, ReactPropTypes;
|
|
534
|
+
}, factoryWithThrowingShims;
|
|
535
|
+
}
|
|
536
|
+
var hasRequiredPropTypes;
|
|
537
|
+
function requirePropTypes() {
|
|
538
|
+
if (hasRequiredPropTypes) return propTypes$1.exports;
|
|
539
|
+
if (hasRequiredPropTypes = 1, process.env.NODE_ENV !== "production") {
|
|
540
|
+
var ReactIs = require$$0, throwOnDirectAccess = !0;
|
|
541
|
+
propTypes$1.exports = requireFactoryWithTypeCheckers()(ReactIs.isElement, throwOnDirectAccess);
|
|
542
|
+
} else
|
|
543
|
+
propTypes$1.exports = requireFactoryWithThrowingShims()();
|
|
544
|
+
return propTypes$1.exports;
|
|
545
|
+
}
|
|
546
|
+
var propTypesExports = /* @__PURE__ */ requirePropTypes(), FOCUS_GROUP = "data-focus-lock", FOCUS_DISABLED = "data-focus-lock-disabled", FOCUS_ALLOW = "data-no-focus-lock", FOCUS_AUTO = "data-autofocus-inside", FOCUS_NO_AUTOFOCUS = "data-no-autofocus";
|
|
547
|
+
function assignRef(ref, value) {
|
|
548
|
+
return typeof ref == "function" ? ref(value) : ref && (ref.current = value), ref;
|
|
549
|
+
}
|
|
550
|
+
function useCallbackRef(initialValue, callback) {
|
|
551
|
+
var ref = useState(function() {
|
|
552
|
+
return {
|
|
553
|
+
// value
|
|
554
|
+
value: initialValue,
|
|
555
|
+
// last callback
|
|
556
|
+
callback,
|
|
557
|
+
// "memoized" public interface
|
|
558
|
+
facade: {
|
|
559
|
+
get current() {
|
|
560
|
+
return ref.value;
|
|
561
|
+
},
|
|
562
|
+
set current(value) {
|
|
563
|
+
var last = ref.value;
|
|
564
|
+
last !== value && (ref.value = value, ref.callback(value, last));
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
})[0];
|
|
569
|
+
return ref.callback = callback, ref.facade;
|
|
570
|
+
}
|
|
571
|
+
var useIsomorphicLayoutEffect = typeof window < "u" ? React.useLayoutEffect : React.useEffect, currentValues = /* @__PURE__ */ new WeakMap();
|
|
572
|
+
function useMergeRefs(refs, defaultValue) {
|
|
573
|
+
var callbackRef = useCallbackRef(null, function(newValue) {
|
|
574
|
+
return refs.forEach(function(ref) {
|
|
575
|
+
return assignRef(ref, newValue);
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
return useIsomorphicLayoutEffect(function() {
|
|
579
|
+
var oldValue = currentValues.get(callbackRef);
|
|
580
|
+
if (oldValue) {
|
|
581
|
+
var prevRefs_1 = new Set(oldValue), nextRefs_1 = new Set(refs), current_1 = callbackRef.current;
|
|
582
|
+
prevRefs_1.forEach(function(ref) {
|
|
583
|
+
nextRefs_1.has(ref) || assignRef(ref, null);
|
|
584
|
+
}), nextRefs_1.forEach(function(ref) {
|
|
585
|
+
prevRefs_1.has(ref) || assignRef(ref, current_1);
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
currentValues.set(callbackRef, refs);
|
|
589
|
+
}, [refs]), callbackRef;
|
|
590
|
+
}
|
|
591
|
+
var hiddenGuard = {
|
|
592
|
+
width: "1px",
|
|
593
|
+
height: "0px",
|
|
594
|
+
padding: 0,
|
|
595
|
+
overflow: "hidden",
|
|
596
|
+
position: "fixed",
|
|
597
|
+
top: "1px",
|
|
598
|
+
left: "1px"
|
|
599
|
+
}, __assign = function() {
|
|
600
|
+
return __assign = Object.assign || function(t) {
|
|
601
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
602
|
+
s = arguments[i];
|
|
603
|
+
for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
|
|
604
|
+
}
|
|
605
|
+
return t;
|
|
606
|
+
}, __assign.apply(this, arguments);
|
|
607
|
+
};
|
|
608
|
+
function ItoI(a) {
|
|
609
|
+
return a;
|
|
610
|
+
}
|
|
611
|
+
function innerCreateMedium(defaults, middleware) {
|
|
612
|
+
middleware === void 0 && (middleware = ItoI);
|
|
613
|
+
var buffer = [], assigned = !1, medium = {
|
|
614
|
+
read: function() {
|
|
615
|
+
if (assigned)
|
|
616
|
+
throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");
|
|
617
|
+
return buffer.length ? buffer[buffer.length - 1] : defaults;
|
|
618
|
+
},
|
|
619
|
+
useMedium: function(data) {
|
|
620
|
+
var item = middleware(data, assigned);
|
|
621
|
+
return buffer.push(item), function() {
|
|
622
|
+
buffer = buffer.filter(function(x) {
|
|
623
|
+
return x !== item;
|
|
624
|
+
});
|
|
625
|
+
};
|
|
626
|
+
},
|
|
627
|
+
assignSyncMedium: function(cb) {
|
|
628
|
+
for (assigned = !0; buffer.length; ) {
|
|
629
|
+
var cbs = buffer;
|
|
630
|
+
buffer = [], cbs.forEach(cb);
|
|
631
|
+
}
|
|
632
|
+
buffer = {
|
|
633
|
+
push: function(x) {
|
|
634
|
+
return cb(x);
|
|
635
|
+
},
|
|
636
|
+
filter: function() {
|
|
637
|
+
return buffer;
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
},
|
|
641
|
+
assignMedium: function(cb) {
|
|
642
|
+
assigned = !0;
|
|
643
|
+
var pendingQueue = [];
|
|
644
|
+
if (buffer.length) {
|
|
645
|
+
var cbs = buffer;
|
|
646
|
+
buffer = [], cbs.forEach(cb), pendingQueue = buffer;
|
|
647
|
+
}
|
|
648
|
+
var executeQueue = function() {
|
|
649
|
+
var cbs2 = pendingQueue;
|
|
650
|
+
pendingQueue = [], cbs2.forEach(cb);
|
|
651
|
+
}, cycle = function() {
|
|
652
|
+
return Promise.resolve().then(executeQueue);
|
|
653
|
+
};
|
|
654
|
+
cycle(), buffer = {
|
|
655
|
+
push: function(x) {
|
|
656
|
+
pendingQueue.push(x), cycle();
|
|
657
|
+
},
|
|
658
|
+
filter: function(filter) {
|
|
659
|
+
return pendingQueue = pendingQueue.filter(filter), buffer;
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
return medium;
|
|
665
|
+
}
|
|
666
|
+
function createMedium(defaults, middleware) {
|
|
667
|
+
return middleware === void 0 && (middleware = ItoI), innerCreateMedium(defaults, middleware);
|
|
668
|
+
}
|
|
669
|
+
function createSidecarMedium(options) {
|
|
670
|
+
options === void 0 && (options = {});
|
|
671
|
+
var medium = innerCreateMedium(null);
|
|
672
|
+
return medium.options = __assign({ async: !0, ssr: !1 }, options), medium;
|
|
673
|
+
}
|
|
674
|
+
var mediumFocus = createMedium({}, function(_ref2) {
|
|
675
|
+
var target = _ref2.target, currentTarget = _ref2.currentTarget;
|
|
676
|
+
return {
|
|
677
|
+
target,
|
|
678
|
+
currentTarget
|
|
679
|
+
};
|
|
680
|
+
}), mediumBlur = createMedium(), mediumEffect = createMedium(), mediumSidecar = createSidecarMedium({
|
|
681
|
+
async: !0,
|
|
682
|
+
ssr: typeof document < "u"
|
|
683
|
+
}), focusScope = /* @__PURE__ */ createContext(void 0), emptyArray = [], FocusLock = /* @__PURE__ */ forwardRef(function(props, parentRef) {
|
|
684
|
+
var _extends2, _useState = useState(), realObserved = _useState[0], setObserved = _useState[1], observed = useRef(), isActive = useRef(!1), originalFocusedElement = useRef(null), _useState2 = useState({}), update = _useState2[1], children = props.children, _props$disabled = props.disabled, disabled = _props$disabled === void 0 ? !1 : _props$disabled, _props$noFocusGuards = props.noFocusGuards, noFocusGuards = _props$noFocusGuards === void 0 ? !1 : _props$noFocusGuards, _props$persistentFocu = props.persistentFocus, persistentFocus = _props$persistentFocu === void 0 ? !1 : _props$persistentFocu, _props$crossFrame = props.crossFrame, crossFrame = _props$crossFrame === void 0 ? !0 : _props$crossFrame, _props$autoFocus = props.autoFocus, autoFocus = _props$autoFocus === void 0 ? !0 : _props$autoFocus, allowTextSelection = props.allowTextSelection, group = props.group, className = props.className, whiteList = props.whiteList, hasPositiveIndices = props.hasPositiveIndices, _props$shards = props.shards, shards = _props$shards === void 0 ? emptyArray : _props$shards, _props$as = props.as, Container = _props$as === void 0 ? "div" : _props$as, _props$lockProps = props.lockProps, containerProps = _props$lockProps === void 0 ? {} : _props$lockProps, SideCar = props.sideCar, _props$returnFocus = props.returnFocus, shouldReturnFocus = _props$returnFocus === void 0 ? !1 : _props$returnFocus, focusOptions = props.focusOptions, onActivationCallback = props.onActivation, onDeactivationCallback = props.onDeactivation, _useState3 = useState({}), id = _useState3[0], onActivation = useCallback(function(_ref2) {
|
|
685
|
+
var captureFocusRestore2 = _ref2.captureFocusRestore;
|
|
686
|
+
if (!originalFocusedElement.current) {
|
|
687
|
+
var _document, activeElement = (_document = document) == null ? void 0 : _document.activeElement;
|
|
688
|
+
originalFocusedElement.current = activeElement, activeElement !== document.body && (originalFocusedElement.current = captureFocusRestore2(activeElement));
|
|
689
|
+
}
|
|
690
|
+
observed.current && onActivationCallback && onActivationCallback(observed.current), isActive.current = !0, update();
|
|
691
|
+
}, [onActivationCallback]), onDeactivation = useCallback(function() {
|
|
692
|
+
isActive.current = !1, onDeactivationCallback && onDeactivationCallback(observed.current), update();
|
|
693
|
+
}, [onDeactivationCallback]), returnFocus = useCallback(function(allowDefer) {
|
|
694
|
+
var focusRestore = originalFocusedElement.current;
|
|
695
|
+
if (focusRestore) {
|
|
696
|
+
var returnFocusTo = (typeof focusRestore == "function" ? focusRestore() : focusRestore) || document.body, howToReturnFocus = typeof shouldReturnFocus == "function" ? shouldReturnFocus(returnFocusTo) : shouldReturnFocus;
|
|
697
|
+
if (howToReturnFocus) {
|
|
698
|
+
var returnFocusOptions = typeof howToReturnFocus == "object" ? howToReturnFocus : void 0;
|
|
699
|
+
originalFocusedElement.current = null, allowDefer ? Promise.resolve().then(function() {
|
|
700
|
+
return returnFocusTo.focus(returnFocusOptions);
|
|
701
|
+
}) : returnFocusTo.focus(returnFocusOptions);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}, [shouldReturnFocus]), onFocus3 = useCallback(function(event) {
|
|
705
|
+
isActive.current && mediumFocus.useMedium(event);
|
|
706
|
+
}, []), onBlur3 = mediumBlur.useMedium, setObserveNode = useCallback(function(newObserved) {
|
|
707
|
+
observed.current !== newObserved && (observed.current = newObserved, setObserved(newObserved));
|
|
708
|
+
}, []);
|
|
709
|
+
process.env.NODE_ENV !== "production" && (typeof allowTextSelection < "u" && console.warn("React-Focus-Lock: allowTextSelection is deprecated and enabled by default"), useEffect(function() {
|
|
710
|
+
!observed.current && typeof Container != "string" && console.error("FocusLock: could not obtain ref to internal node");
|
|
711
|
+
}, []));
|
|
712
|
+
var lockProps = _extends((_extends2 = {}, _extends2[FOCUS_DISABLED] = disabled && "disabled", _extends2[FOCUS_GROUP] = group, _extends2), containerProps), hasLeadingGuards = noFocusGuards !== !0, hasTailingGuards = hasLeadingGuards && noFocusGuards !== "tail", mergedRef = useMergeRefs([parentRef, setObserveNode]), focusScopeValue = useMemo(function() {
|
|
713
|
+
return {
|
|
714
|
+
observed,
|
|
715
|
+
shards,
|
|
716
|
+
enabled: !disabled,
|
|
717
|
+
active: isActive.current
|
|
718
|
+
};
|
|
719
|
+
}, [disabled, isActive.current, shards, realObserved]);
|
|
720
|
+
return /* @__PURE__ */ React__default.createElement(Fragment, null, hasLeadingGuards && [
|
|
721
|
+
/* @__PURE__ */ React__default.createElement("div", {
|
|
722
|
+
key: "guard-first",
|
|
723
|
+
"data-focus-guard": !0,
|
|
724
|
+
tabIndex: disabled ? -1 : 0,
|
|
725
|
+
style: hiddenGuard
|
|
726
|
+
}),
|
|
727
|
+
hasPositiveIndices ? /* @__PURE__ */ React__default.createElement("div", {
|
|
728
|
+
key: "guard-nearest",
|
|
729
|
+
"data-focus-guard": !0,
|
|
730
|
+
tabIndex: disabled ? -1 : 1,
|
|
731
|
+
style: hiddenGuard
|
|
732
|
+
}) : null
|
|
733
|
+
], !disabled && /* @__PURE__ */ React__default.createElement(SideCar, {
|
|
734
|
+
id,
|
|
735
|
+
sideCar: mediumSidecar,
|
|
736
|
+
observed: realObserved,
|
|
737
|
+
disabled,
|
|
738
|
+
persistentFocus,
|
|
739
|
+
crossFrame,
|
|
740
|
+
autoFocus,
|
|
741
|
+
whiteList,
|
|
742
|
+
shards,
|
|
743
|
+
onActivation,
|
|
744
|
+
onDeactivation,
|
|
745
|
+
returnFocus,
|
|
746
|
+
focusOptions,
|
|
747
|
+
noFocusGuards
|
|
748
|
+
}), /* @__PURE__ */ React__default.createElement(Container, _extends({
|
|
749
|
+
ref: mergedRef
|
|
750
|
+
}, lockProps, {
|
|
751
|
+
className,
|
|
752
|
+
onBlur: onBlur3,
|
|
753
|
+
onFocus: onFocus3
|
|
754
|
+
}), /* @__PURE__ */ React__default.createElement(focusScope.Provider, {
|
|
755
|
+
value: focusScopeValue
|
|
756
|
+
}, children)), hasTailingGuards && /* @__PURE__ */ React__default.createElement("div", {
|
|
757
|
+
"data-focus-guard": !0,
|
|
758
|
+
tabIndex: disabled ? -1 : 0,
|
|
759
|
+
style: hiddenGuard
|
|
760
|
+
}));
|
|
761
|
+
});
|
|
762
|
+
FocusLock.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
763
|
+
children: propTypesExports.node,
|
|
764
|
+
disabled: propTypesExports.bool,
|
|
765
|
+
returnFocus: propTypesExports.oneOfType([propTypesExports.bool, propTypesExports.object, propTypesExports.func]),
|
|
766
|
+
focusOptions: propTypesExports.object,
|
|
767
|
+
noFocusGuards: propTypesExports.bool,
|
|
768
|
+
hasPositiveIndices: propTypesExports.bool,
|
|
769
|
+
allowTextSelection: propTypesExports.bool,
|
|
770
|
+
autoFocus: propTypesExports.bool,
|
|
771
|
+
persistentFocus: propTypesExports.bool,
|
|
772
|
+
crossFrame: propTypesExports.bool,
|
|
773
|
+
group: propTypesExports.string,
|
|
774
|
+
className: propTypesExports.string,
|
|
775
|
+
whiteList: propTypesExports.func,
|
|
776
|
+
shards: propTypesExports.arrayOf(propTypesExports.any),
|
|
777
|
+
as: propTypesExports.oneOfType([propTypesExports.string, propTypesExports.func, propTypesExports.object]),
|
|
778
|
+
lockProps: propTypesExports.object,
|
|
779
|
+
onActivation: propTypesExports.func,
|
|
780
|
+
onDeactivation: propTypesExports.func,
|
|
781
|
+
sideCar: propTypesExports.any.isRequired
|
|
782
|
+
} : {};
|
|
783
|
+
function _setPrototypeOf(t, e) {
|
|
784
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(t2, e2) {
|
|
785
|
+
return t2.__proto__ = e2, t2;
|
|
786
|
+
}, _setPrototypeOf(t, e);
|
|
787
|
+
}
|
|
788
|
+
function _inheritsLoose(t, o) {
|
|
789
|
+
t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
|
|
790
|
+
}
|
|
791
|
+
function _typeof(o) {
|
|
792
|
+
"@babel/helpers - typeof";
|
|
793
|
+
return _typeof = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(o2) {
|
|
794
|
+
return typeof o2;
|
|
795
|
+
} : function(o2) {
|
|
796
|
+
return o2 && typeof Symbol == "function" && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
|
|
797
|
+
}, _typeof(o);
|
|
798
|
+
}
|
|
799
|
+
function toPrimitive(t, r) {
|
|
800
|
+
if (_typeof(t) != "object" || !t) return t;
|
|
801
|
+
var e = t[Symbol.toPrimitive];
|
|
802
|
+
if (e !== void 0) {
|
|
803
|
+
var i = e.call(t, r);
|
|
804
|
+
if (_typeof(i) != "object") return i;
|
|
805
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
806
|
+
}
|
|
807
|
+
return (r === "string" ? String : Number)(t);
|
|
808
|
+
}
|
|
809
|
+
function toPropertyKey(t) {
|
|
810
|
+
var i = toPrimitive(t, "string");
|
|
811
|
+
return _typeof(i) == "symbol" ? i : i + "";
|
|
812
|
+
}
|
|
813
|
+
function _defineProperty(e, r, t) {
|
|
814
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
815
|
+
value: t,
|
|
816
|
+
enumerable: !0,
|
|
817
|
+
configurable: !0,
|
|
818
|
+
writable: !0
|
|
819
|
+
}) : e[r] = t, e;
|
|
820
|
+
}
|
|
821
|
+
function withSideEffect(reducePropsToState2, handleStateChangeOnClient2) {
|
|
822
|
+
if (process.env.NODE_ENV !== "production") {
|
|
823
|
+
if (typeof reducePropsToState2 != "function")
|
|
824
|
+
throw new Error("Expected reducePropsToState to be a function.");
|
|
825
|
+
if (typeof handleStateChangeOnClient2 != "function")
|
|
826
|
+
throw new Error("Expected handleStateChangeOnClient to be a function.");
|
|
827
|
+
}
|
|
828
|
+
function getDisplayName(WrappedComponent) {
|
|
829
|
+
return WrappedComponent.displayName || WrappedComponent.name || "Component";
|
|
830
|
+
}
|
|
831
|
+
return function(WrappedComponent) {
|
|
832
|
+
if (process.env.NODE_ENV !== "production" && typeof WrappedComponent != "function")
|
|
833
|
+
throw new Error("Expected WrappedComponent to be a React component.");
|
|
834
|
+
var mountedInstances = [], state;
|
|
835
|
+
function emitChange() {
|
|
836
|
+
state = reducePropsToState2(mountedInstances.map(function(instance) {
|
|
837
|
+
return instance.props;
|
|
838
|
+
})), handleStateChangeOnClient2(state);
|
|
839
|
+
}
|
|
840
|
+
var SideEffect = /* @__PURE__ */ function(_PureComponent) {
|
|
841
|
+
_inheritsLoose(SideEffect2, _PureComponent);
|
|
842
|
+
function SideEffect2() {
|
|
843
|
+
return _PureComponent.apply(this, arguments) || this;
|
|
844
|
+
}
|
|
845
|
+
SideEffect2.peek = function() {
|
|
846
|
+
return state;
|
|
847
|
+
};
|
|
848
|
+
var _proto = SideEffect2.prototype;
|
|
849
|
+
return _proto.componentDidMount = function() {
|
|
850
|
+
mountedInstances.push(this), emitChange();
|
|
851
|
+
}, _proto.componentDidUpdate = function() {
|
|
852
|
+
emitChange();
|
|
853
|
+
}, _proto.componentWillUnmount = function() {
|
|
854
|
+
var index = mountedInstances.indexOf(this);
|
|
855
|
+
mountedInstances.splice(index, 1), emitChange();
|
|
856
|
+
}, _proto.render = function() {
|
|
857
|
+
return /* @__PURE__ */ React__default.createElement(WrappedComponent, this.props);
|
|
858
|
+
}, SideEffect2;
|
|
859
|
+
}(PureComponent);
|
|
860
|
+
return _defineProperty(SideEffect, "displayName", "SideEffect(" + getDisplayName(WrappedComponent) + ")"), SideEffect;
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
var toArray = function(a) {
|
|
864
|
+
for (var ret = Array(a.length), i = 0; i < a.length; ++i)
|
|
865
|
+
ret[i] = a[i];
|
|
866
|
+
return ret;
|
|
867
|
+
}, asArray = function(a) {
|
|
868
|
+
return Array.isArray(a) ? a : [a];
|
|
869
|
+
}, getFirst = function(a) {
|
|
870
|
+
return Array.isArray(a) ? a[0] : a;
|
|
871
|
+
}, isElementHidden = function(node) {
|
|
872
|
+
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
873
|
+
return !1;
|
|
874
|
+
var computedStyle = window.getComputedStyle(node, null);
|
|
875
|
+
return !computedStyle || !computedStyle.getPropertyValue ? !1 : computedStyle.getPropertyValue("display") === "none" || computedStyle.getPropertyValue("visibility") === "hidden";
|
|
876
|
+
}, getParentNode = function(node) {
|
|
877
|
+
return node.parentNode && node.parentNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE ? (
|
|
878
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
879
|
+
node.parentNode.host
|
|
880
|
+
) : node.parentNode;
|
|
881
|
+
}, isTopNode = function(node) {
|
|
882
|
+
return node === document || node && node.nodeType === Node.DOCUMENT_NODE;
|
|
883
|
+
}, isInert = function(node) {
|
|
884
|
+
return node.hasAttribute("inert");
|
|
885
|
+
}, isVisibleUncached = function(node, checkParent) {
|
|
886
|
+
return !node || isTopNode(node) || !isElementHidden(node) && !isInert(node) && checkParent(getParentNode(node));
|
|
887
|
+
}, isVisibleCached = function(visibilityCache, node) {
|
|
888
|
+
var cached = visibilityCache.get(node);
|
|
889
|
+
if (cached !== void 0)
|
|
890
|
+
return cached;
|
|
891
|
+
var result = isVisibleUncached(node, isVisibleCached.bind(void 0, visibilityCache));
|
|
892
|
+
return visibilityCache.set(node, result), result;
|
|
893
|
+
}, isAutoFocusAllowedUncached = function(node, checkParent) {
|
|
894
|
+
return node && !isTopNode(node) ? isAutoFocusAllowed(node) ? checkParent(getParentNode(node)) : !1 : !0;
|
|
895
|
+
}, isAutoFocusAllowedCached = function(cache, node) {
|
|
896
|
+
var cached = cache.get(node);
|
|
897
|
+
if (cached !== void 0)
|
|
898
|
+
return cached;
|
|
899
|
+
var result = isAutoFocusAllowedUncached(node, isAutoFocusAllowedCached.bind(void 0, cache));
|
|
900
|
+
return cache.set(node, result), result;
|
|
901
|
+
}, getDataset = function(node) {
|
|
902
|
+
return node.dataset;
|
|
903
|
+
}, isHTMLButtonElement = function(node) {
|
|
904
|
+
return node.tagName === "BUTTON";
|
|
905
|
+
}, isHTMLInputElement = function(node) {
|
|
906
|
+
return node.tagName === "INPUT";
|
|
907
|
+
}, isRadioElement = function(node) {
|
|
908
|
+
return isHTMLInputElement(node) && node.type === "radio";
|
|
909
|
+
}, notHiddenInput = function(node) {
|
|
910
|
+
return !((isHTMLInputElement(node) || isHTMLButtonElement(node)) && (node.type === "hidden" || node.disabled));
|
|
911
|
+
}, isAutoFocusAllowed = function(node) {
|
|
912
|
+
var attribute = node.getAttribute(FOCUS_NO_AUTOFOCUS);
|
|
913
|
+
return ![!0, "true", ""].includes(attribute);
|
|
914
|
+
}, isGuard = function(node) {
|
|
915
|
+
var _a;
|
|
916
|
+
return !!(node && (!((_a = getDataset(node)) === null || _a === void 0) && _a.focusGuard));
|
|
917
|
+
}, isNotAGuard = function(node) {
|
|
918
|
+
return !isGuard(node);
|
|
919
|
+
}, isDefined = function(x) {
|
|
920
|
+
return !!x;
|
|
921
|
+
}, tabSort = function(a, b) {
|
|
922
|
+
var aTab = Math.max(0, a.tabIndex), bTab = Math.max(0, b.tabIndex), tabDiff = aTab - bTab, indexDiff = a.index - b.index;
|
|
923
|
+
if (tabDiff) {
|
|
924
|
+
if (!aTab)
|
|
925
|
+
return 1;
|
|
926
|
+
if (!bTab)
|
|
927
|
+
return -1;
|
|
928
|
+
}
|
|
929
|
+
return tabDiff || indexDiff;
|
|
930
|
+
}, getTabIndex = function(node) {
|
|
931
|
+
return node.tabIndex < 0 && !node.hasAttribute("tabindex") ? 0 : node.tabIndex;
|
|
932
|
+
}, orderByTabIndex = function(nodes, filterNegative, keepGuards) {
|
|
933
|
+
return toArray(nodes).map(function(node, index) {
|
|
934
|
+
var tabIndex = getTabIndex(node);
|
|
935
|
+
return {
|
|
936
|
+
node,
|
|
937
|
+
index,
|
|
938
|
+
tabIndex: keepGuards && tabIndex === -1 ? (node.dataset || {}).focusGuard ? 0 : -1 : tabIndex
|
|
939
|
+
};
|
|
940
|
+
}).filter(function(data) {
|
|
941
|
+
return !filterNegative || data.tabIndex >= 0;
|
|
942
|
+
}).sort(tabSort);
|
|
943
|
+
}, tabbables = [
|
|
944
|
+
"button:enabled",
|
|
945
|
+
"select:enabled",
|
|
946
|
+
"textarea:enabled",
|
|
947
|
+
"input:enabled",
|
|
948
|
+
// elements with explicit roles will also use explicit tabindex
|
|
949
|
+
// '[role="button"]',
|
|
950
|
+
"a[href]",
|
|
951
|
+
"area[href]",
|
|
952
|
+
"summary",
|
|
953
|
+
"iframe",
|
|
954
|
+
"object",
|
|
955
|
+
"embed",
|
|
956
|
+
"audio[controls]",
|
|
957
|
+
"video[controls]",
|
|
958
|
+
"[tabindex]",
|
|
959
|
+
"[contenteditable]",
|
|
960
|
+
"[autofocus]"
|
|
961
|
+
], queryTabbables = tabbables.join(","), queryGuardTabbables = "".concat(queryTabbables, ", [data-focus-guard]"), getFocusablesWithShadowDom = function(parent, withGuards) {
|
|
962
|
+
return toArray((parent.shadowRoot || parent).children).reduce(function(acc, child) {
|
|
963
|
+
return acc.concat(child.matches(withGuards ? queryGuardTabbables : queryTabbables) ? [child] : [], getFocusablesWithShadowDom(child));
|
|
964
|
+
}, []);
|
|
965
|
+
}, getFocusablesWithIFrame = function(parent, withGuards) {
|
|
966
|
+
var _a;
|
|
967
|
+
return parent instanceof HTMLIFrameElement && (!((_a = parent.contentDocument) === null || _a === void 0) && _a.body) ? getFocusables([parent.contentDocument.body], withGuards) : [parent];
|
|
968
|
+
}, getFocusables = function(parents, withGuards) {
|
|
969
|
+
return parents.reduce(function(acc, parent) {
|
|
970
|
+
var _a, focusableWithShadowDom = getFocusablesWithShadowDom(parent, withGuards), focusableWithIframes = (_a = []).concat.apply(_a, focusableWithShadowDom.map(function(node) {
|
|
971
|
+
return getFocusablesWithIFrame(node, withGuards);
|
|
972
|
+
}));
|
|
973
|
+
return acc.concat(
|
|
974
|
+
// add all tabbables inside and within shadow DOMs in DOM order
|
|
975
|
+
focusableWithIframes,
|
|
976
|
+
// add if node is tabbable itself
|
|
977
|
+
parent.parentNode ? toArray(parent.parentNode.querySelectorAll(queryTabbables)).filter(function(node) {
|
|
978
|
+
return node === parent;
|
|
979
|
+
}) : []
|
|
980
|
+
);
|
|
981
|
+
}, []);
|
|
982
|
+
}, getParentAutofocusables = function(parent) {
|
|
983
|
+
var parentFocus = parent.querySelectorAll("[".concat(FOCUS_AUTO, "]"));
|
|
984
|
+
return toArray(parentFocus).map(function(node) {
|
|
985
|
+
return getFocusables([node]);
|
|
986
|
+
}).reduce(function(acc, nodes) {
|
|
987
|
+
return acc.concat(nodes);
|
|
988
|
+
}, []);
|
|
989
|
+
}, filterFocusable = function(nodes, visibilityCache) {
|
|
990
|
+
return toArray(nodes).filter(function(node) {
|
|
991
|
+
return isVisibleCached(visibilityCache, node);
|
|
992
|
+
}).filter(function(node) {
|
|
993
|
+
return notHiddenInput(node);
|
|
994
|
+
});
|
|
995
|
+
}, filterAutoFocusable = function(nodes, cache) {
|
|
996
|
+
return cache === void 0 && (cache = /* @__PURE__ */ new Map()), toArray(nodes).filter(function(node) {
|
|
997
|
+
return isAutoFocusAllowedCached(cache, node);
|
|
998
|
+
});
|
|
999
|
+
}, getTabbableNodes = function(topNodes, visibilityCache, withGuards) {
|
|
1000
|
+
return orderByTabIndex(filterFocusable(getFocusables(topNodes, withGuards), visibilityCache), !0, withGuards);
|
|
1001
|
+
}, getFocusableNodes = function(topNodes, visibilityCache) {
|
|
1002
|
+
return orderByTabIndex(filterFocusable(getFocusables(topNodes), visibilityCache), !1);
|
|
1003
|
+
}, parentAutofocusables = function(topNode, visibilityCache) {
|
|
1004
|
+
return filterFocusable(getParentAutofocusables(topNode), visibilityCache);
|
|
1005
|
+
}, contains = function(scope, element) {
|
|
1006
|
+
return scope.shadowRoot ? contains(scope.shadowRoot, element) : Object.getPrototypeOf(scope).contains !== void 0 && Object.getPrototypeOf(scope).contains.call(scope, element) ? !0 : toArray(scope.children).some(function(child) {
|
|
1007
|
+
var _a;
|
|
1008
|
+
if (child instanceof HTMLIFrameElement) {
|
|
1009
|
+
var iframeBody = (_a = child.contentDocument) === null || _a === void 0 ? void 0 : _a.body;
|
|
1010
|
+
return iframeBody ? contains(iframeBody, element) : !1;
|
|
1011
|
+
}
|
|
1012
|
+
return contains(child, element);
|
|
1013
|
+
});
|
|
1014
|
+
}, filterNested = function(nodes) {
|
|
1015
|
+
for (var contained = /* @__PURE__ */ new Set(), l = nodes.length, i = 0; i < l; i += 1)
|
|
1016
|
+
for (var j = i + 1; j < l; j += 1) {
|
|
1017
|
+
var position = nodes[i].compareDocumentPosition(nodes[j]);
|
|
1018
|
+
(position & Node.DOCUMENT_POSITION_CONTAINED_BY) > 0 && contained.add(j), (position & Node.DOCUMENT_POSITION_CONTAINS) > 0 && contained.add(i);
|
|
1019
|
+
}
|
|
1020
|
+
return nodes.filter(function(_, index) {
|
|
1021
|
+
return !contained.has(index);
|
|
1022
|
+
});
|
|
1023
|
+
}, getTopParent = function(node) {
|
|
1024
|
+
return node.parentNode ? getTopParent(node.parentNode) : node;
|
|
1025
|
+
}, getAllAffectedNodes = function(node) {
|
|
1026
|
+
var nodes = asArray(node);
|
|
1027
|
+
return nodes.filter(Boolean).reduce(function(acc, currentNode) {
|
|
1028
|
+
var group = currentNode.getAttribute(FOCUS_GROUP);
|
|
1029
|
+
return acc.push.apply(acc, group ? filterNested(toArray(getTopParent(currentNode).querySelectorAll("[".concat(FOCUS_GROUP, '="').concat(group, '"]:not([').concat(FOCUS_DISABLED, '="disabled"])')))) : [currentNode]), acc;
|
|
1030
|
+
}, []);
|
|
1031
|
+
}, safeProbe = function(cb) {
|
|
1032
|
+
try {
|
|
1033
|
+
return cb();
|
|
1034
|
+
} catch {
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
}, getActiveElement = function(inDocument) {
|
|
1038
|
+
if (inDocument === void 0 && (inDocument = document), !(!inDocument || !inDocument.activeElement)) {
|
|
1039
|
+
var activeElement = inDocument.activeElement;
|
|
1040
|
+
return activeElement.shadowRoot ? getActiveElement(activeElement.shadowRoot) : activeElement instanceof HTMLIFrameElement && safeProbe(function() {
|
|
1041
|
+
return activeElement.contentWindow.document;
|
|
1042
|
+
}) ? getActiveElement(activeElement.contentWindow.document) : activeElement;
|
|
1043
|
+
}
|
|
1044
|
+
}, focusInFrame = function(frame, activeElement) {
|
|
1045
|
+
return frame === activeElement;
|
|
1046
|
+
}, focusInsideIframe = function(topNode, activeElement) {
|
|
1047
|
+
return !!toArray(topNode.querySelectorAll("iframe")).some(function(node) {
|
|
1048
|
+
return focusInFrame(node, activeElement);
|
|
1049
|
+
});
|
|
1050
|
+
}, focusInside = function(topNode, activeElement) {
|
|
1051
|
+
return activeElement === void 0 && (activeElement = getActiveElement(getFirst(topNode).ownerDocument)), !activeElement || activeElement.dataset && activeElement.dataset.focusGuard ? !1 : getAllAffectedNodes(topNode).some(function(node) {
|
|
1052
|
+
return contains(node, activeElement) || focusInsideIframe(node, activeElement);
|
|
1053
|
+
});
|
|
1054
|
+
}, focusIsHidden = function(inDocument) {
|
|
1055
|
+
inDocument === void 0 && (inDocument = document);
|
|
1056
|
+
var activeElement = getActiveElement(inDocument);
|
|
1057
|
+
return activeElement ? toArray(inDocument.querySelectorAll("[".concat(FOCUS_ALLOW, "]"))).some(function(node) {
|
|
1058
|
+
return contains(node, activeElement);
|
|
1059
|
+
}) : !1;
|
|
1060
|
+
}, findSelectedRadio = function(node, nodes) {
|
|
1061
|
+
return nodes.filter(isRadioElement).filter(function(el) {
|
|
1062
|
+
return el.name === node.name;
|
|
1063
|
+
}).filter(function(el) {
|
|
1064
|
+
return el.checked;
|
|
1065
|
+
})[0] || node;
|
|
1066
|
+
}, correctNode = function(node, nodes) {
|
|
1067
|
+
return isRadioElement(node) && node.name ? findSelectedRadio(node, nodes) : node;
|
|
1068
|
+
}, correctNodes = function(nodes) {
|
|
1069
|
+
var resultSet = /* @__PURE__ */ new Set();
|
|
1070
|
+
return nodes.forEach(function(node) {
|
|
1071
|
+
return resultSet.add(correctNode(node, nodes));
|
|
1072
|
+
}), nodes.filter(function(node) {
|
|
1073
|
+
return resultSet.has(node);
|
|
1074
|
+
});
|
|
1075
|
+
}, pickFirstFocus = function(nodes) {
|
|
1076
|
+
return nodes[0] && nodes.length > 1 ? correctNode(nodes[0], nodes) : nodes[0];
|
|
1077
|
+
}, pickFocusable = function(nodes, node) {
|
|
1078
|
+
return nodes.indexOf(correctNode(node, nodes));
|
|
1079
|
+
}, NEW_FOCUS = "NEW_FOCUS", newFocus = function(innerNodes, innerTabbables, outerNodes, activeElement, lastNode) {
|
|
1080
|
+
var cnt = innerNodes.length, firstFocus = innerNodes[0], lastFocus = innerNodes[cnt - 1], isOnGuard = isGuard(activeElement);
|
|
1081
|
+
if (!(activeElement && innerNodes.indexOf(activeElement) >= 0)) {
|
|
1082
|
+
var activeIndex = activeElement !== void 0 ? outerNodes.indexOf(activeElement) : -1, lastIndex = lastNode ? outerNodes.indexOf(lastNode) : activeIndex, lastNodeInside = lastNode ? innerNodes.indexOf(lastNode) : -1;
|
|
1083
|
+
if (activeIndex === -1)
|
|
1084
|
+
return lastNodeInside !== -1 ? lastNodeInside : NEW_FOCUS;
|
|
1085
|
+
if (lastNodeInside === -1)
|
|
1086
|
+
return NEW_FOCUS;
|
|
1087
|
+
var indexDiff = activeIndex - lastIndex, firstNodeIndex = outerNodes.indexOf(firstFocus), lastNodeIndex = outerNodes.indexOf(lastFocus), correctedNodes = correctNodes(outerNodes), currentFocusableIndex = activeElement !== void 0 ? correctedNodes.indexOf(activeElement) : -1, previousFocusableIndex = lastNode ? correctedNodes.indexOf(lastNode) : currentFocusableIndex, tabbableNodes = correctedNodes.filter(function(node) {
|
|
1088
|
+
return node.tabIndex >= 0;
|
|
1089
|
+
}), currentTabbableIndex = activeElement !== void 0 ? tabbableNodes.indexOf(activeElement) : -1, previousTabbableIndex = lastNode ? tabbableNodes.indexOf(lastNode) : currentTabbableIndex, focusIndexDiff = currentTabbableIndex >= 0 && previousTabbableIndex >= 0 ? (
|
|
1090
|
+
// old/new are tabbables, measure distance in tabbable space
|
|
1091
|
+
previousTabbableIndex - currentTabbableIndex
|
|
1092
|
+
) : (
|
|
1093
|
+
// or else measure in focusable space
|
|
1094
|
+
previousFocusableIndex - currentFocusableIndex
|
|
1095
|
+
);
|
|
1096
|
+
if (!indexDiff && lastNodeInside >= 0 || innerTabbables.length === 0)
|
|
1097
|
+
return lastNodeInside;
|
|
1098
|
+
var returnFirstNode = pickFocusable(innerNodes, innerTabbables[0]), returnLastNode = pickFocusable(innerNodes, innerTabbables[innerTabbables.length - 1]);
|
|
1099
|
+
if (activeIndex <= firstNodeIndex && isOnGuard && Math.abs(indexDiff) > 1)
|
|
1100
|
+
return returnLastNode;
|
|
1101
|
+
if (activeIndex >= lastNodeIndex && isOnGuard && Math.abs(indexDiff) > 1)
|
|
1102
|
+
return returnFirstNode;
|
|
1103
|
+
if (indexDiff && Math.abs(focusIndexDiff) > 1)
|
|
1104
|
+
return lastNodeInside;
|
|
1105
|
+
if (activeIndex <= firstNodeIndex)
|
|
1106
|
+
return returnLastNode;
|
|
1107
|
+
if (activeIndex > lastNodeIndex)
|
|
1108
|
+
return returnFirstNode;
|
|
1109
|
+
if (indexDiff)
|
|
1110
|
+
return Math.abs(indexDiff) > 1 ? lastNodeInside : (cnt + lastNodeInside + indexDiff) % cnt;
|
|
1111
|
+
}
|
|
1112
|
+
}, findAutoFocused = function(autoFocusables) {
|
|
1113
|
+
return function(node) {
|
|
1114
|
+
var _a, autofocus = (_a = getDataset(node)) === null || _a === void 0 ? void 0 : _a.autofocus;
|
|
1115
|
+
return (
|
|
1116
|
+
// @ts-expect-error
|
|
1117
|
+
node.autofocus || //
|
|
1118
|
+
autofocus !== void 0 && autofocus !== "false" || //
|
|
1119
|
+
autoFocusables.indexOf(node) >= 0
|
|
1120
|
+
);
|
|
1121
|
+
};
|
|
1122
|
+
}, pickAutofocus = function(nodesIndexes, orderedNodes, groups) {
|
|
1123
|
+
var nodes = nodesIndexes.map(function(_a) {
|
|
1124
|
+
var node = _a.node;
|
|
1125
|
+
return node;
|
|
1126
|
+
}), autoFocusable = filterAutoFocusable(nodes.filter(findAutoFocused(groups)));
|
|
1127
|
+
return autoFocusable && autoFocusable.length ? pickFirstFocus(autoFocusable) : pickFirstFocus(filterAutoFocusable(orderedNodes));
|
|
1128
|
+
}, getParents = function(node, parents) {
|
|
1129
|
+
return parents === void 0 && (parents = []), parents.push(node), node.parentNode && getParents(node.parentNode.host || node.parentNode, parents), parents;
|
|
1130
|
+
}, getCommonParent = function(nodeA, nodeB) {
|
|
1131
|
+
for (var parentsA = getParents(nodeA), parentsB = getParents(nodeB), i = 0; i < parentsA.length; i += 1) {
|
|
1132
|
+
var currentParent = parentsA[i];
|
|
1133
|
+
if (parentsB.indexOf(currentParent) >= 0)
|
|
1134
|
+
return currentParent;
|
|
1135
|
+
}
|
|
1136
|
+
return !1;
|
|
1137
|
+
}, getTopCommonParent = function(baseActiveElement, leftEntry, rightEntries) {
|
|
1138
|
+
var activeElements = asArray(baseActiveElement), leftEntries = asArray(leftEntry), activeElement = activeElements[0], topCommon = !1;
|
|
1139
|
+
return leftEntries.filter(Boolean).forEach(function(entry) {
|
|
1140
|
+
topCommon = getCommonParent(topCommon || entry, entry) || topCommon, rightEntries.filter(Boolean).forEach(function(subEntry) {
|
|
1141
|
+
var common = getCommonParent(activeElement, subEntry);
|
|
1142
|
+
common && (!topCommon || contains(common, topCommon) ? topCommon = common : topCommon = getCommonParent(common, topCommon));
|
|
1143
|
+
});
|
|
1144
|
+
}), topCommon;
|
|
1145
|
+
}, allParentAutofocusables = function(entries, visibilityCache) {
|
|
1146
|
+
return entries.reduce(function(acc, node) {
|
|
1147
|
+
return acc.concat(parentAutofocusables(node, visibilityCache));
|
|
1148
|
+
}, []);
|
|
1149
|
+
}, reorderNodes = function(srcNodes, dstNodes) {
|
|
1150
|
+
var remap = /* @__PURE__ */ new Map();
|
|
1151
|
+
return dstNodes.forEach(function(entity) {
|
|
1152
|
+
return remap.set(entity.node, entity);
|
|
1153
|
+
}), srcNodes.map(function(node) {
|
|
1154
|
+
return remap.get(node);
|
|
1155
|
+
}).filter(isDefined);
|
|
1156
|
+
}, focusSolver = function(topNode, lastNode) {
|
|
1157
|
+
var activeElement = getActiveElement(asArray(topNode).length > 0 ? document : getFirst(topNode).ownerDocument), entries = getAllAffectedNodes(topNode).filter(isNotAGuard), commonParent = getTopCommonParent(activeElement || topNode, topNode, entries), visibilityCache = /* @__PURE__ */ new Map(), anyFocusable = getFocusableNodes(entries, visibilityCache), innerElements = anyFocusable.filter(function(_a) {
|
|
1158
|
+
var node = _a.node;
|
|
1159
|
+
return isNotAGuard(node);
|
|
1160
|
+
});
|
|
1161
|
+
if (innerElements[0]) {
|
|
1162
|
+
var outerNodes = getFocusableNodes([commonParent], visibilityCache).map(function(_a) {
|
|
1163
|
+
var node = _a.node;
|
|
1164
|
+
return node;
|
|
1165
|
+
}), orderedInnerElements = reorderNodes(outerNodes, innerElements), innerFocusables = orderedInnerElements.map(function(_a) {
|
|
1166
|
+
var node = _a.node;
|
|
1167
|
+
return node;
|
|
1168
|
+
}), innerTabbable = orderedInnerElements.filter(function(_a) {
|
|
1169
|
+
var tabIndex = _a.tabIndex;
|
|
1170
|
+
return tabIndex >= 0;
|
|
1171
|
+
}).map(function(_a) {
|
|
1172
|
+
var node = _a.node;
|
|
1173
|
+
return node;
|
|
1174
|
+
}), newId = newFocus(innerFocusables, innerTabbable, outerNodes, activeElement, lastNode);
|
|
1175
|
+
if (newId === NEW_FOCUS) {
|
|
1176
|
+
var focusNode = (
|
|
1177
|
+
// first try only tabbable, and the fallback to all focusable, as long as at least one element should be picked for focus
|
|
1178
|
+
pickAutofocus(anyFocusable, innerTabbable, allParentAutofocusables(entries, visibilityCache)) || pickAutofocus(anyFocusable, innerFocusables, allParentAutofocusables(entries, visibilityCache))
|
|
1179
|
+
);
|
|
1180
|
+
if (focusNode)
|
|
1181
|
+
return { node: focusNode };
|
|
1182
|
+
console.warn("focus-lock: cannot find any node to move focus into");
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
return newId === void 0 ? newId : orderedInnerElements[newId];
|
|
1186
|
+
}
|
|
1187
|
+
}, expandFocusableNodes = function(topNode) {
|
|
1188
|
+
var entries = getAllAffectedNodes(topNode).filter(isNotAGuard), commonParent = getTopCommonParent(topNode, topNode, entries), outerNodes = orderByTabIndex(getFocusables([commonParent], !0), !0, !0), innerElements = getFocusables(entries, !1);
|
|
1189
|
+
return outerNodes.map(function(_a) {
|
|
1190
|
+
var node = _a.node, index = _a.index;
|
|
1191
|
+
return {
|
|
1192
|
+
node,
|
|
1193
|
+
index,
|
|
1194
|
+
lockItem: innerElements.indexOf(node) >= 0,
|
|
1195
|
+
guard: isGuard(node)
|
|
1196
|
+
};
|
|
1197
|
+
});
|
|
1198
|
+
}, focusOn = function(target, focusOptions) {
|
|
1199
|
+
target && ("focus" in target && target.focus(focusOptions), "contentWindow" in target && target.contentWindow && target.contentWindow.focus());
|
|
1200
|
+
}, guardCount = 0, lockDisabled = !1, moveFocusInside = function(topNode, lastNode, options) {
|
|
1201
|
+
options === void 0 && (options = {});
|
|
1202
|
+
var focusable = focusSolver(topNode, lastNode);
|
|
1203
|
+
if (!lockDisabled && focusable) {
|
|
1204
|
+
if (guardCount > 2) {
|
|
1205
|
+
console.error("FocusLock: focus-fighting detected. Only one focus management system could be active. See https://github.com/theKashey/focus-lock/#focus-fighting"), lockDisabled = !0, setTimeout(function() {
|
|
1206
|
+
lockDisabled = !1;
|
|
1207
|
+
}, 1);
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
guardCount++, focusOn(focusable.node, options.focusOptions), guardCount--;
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
function weakRef(value) {
|
|
1214
|
+
if (!value)
|
|
1215
|
+
return null;
|
|
1216
|
+
if (typeof WeakRef > "u")
|
|
1217
|
+
return function() {
|
|
1218
|
+
return value || null;
|
|
1219
|
+
};
|
|
1220
|
+
var w = value ? new WeakRef(value) : null;
|
|
1221
|
+
return function() {
|
|
1222
|
+
return w?.deref() || null;
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
var recordElementLocation = function(element) {
|
|
1226
|
+
if (!element)
|
|
1227
|
+
return null;
|
|
1228
|
+
for (var stack = [], currentElement = element; currentElement && currentElement !== document.body; )
|
|
1229
|
+
stack.push({
|
|
1230
|
+
current: weakRef(currentElement),
|
|
1231
|
+
parent: weakRef(currentElement.parentElement),
|
|
1232
|
+
left: weakRef(currentElement.previousElementSibling),
|
|
1233
|
+
right: weakRef(currentElement.nextElementSibling)
|
|
1234
|
+
}), currentElement = currentElement.parentElement;
|
|
1235
|
+
return {
|
|
1236
|
+
element: weakRef(element),
|
|
1237
|
+
stack,
|
|
1238
|
+
ownerDocument: element.ownerDocument
|
|
1239
|
+
};
|
|
1240
|
+
}, restoreFocusTo = function(location) {
|
|
1241
|
+
var _a, _b, _c, _d, _e;
|
|
1242
|
+
if (location)
|
|
1243
|
+
for (var stack = location.stack, ownerDocument = location.ownerDocument, visibilityCache = /* @__PURE__ */ new Map(), _i = 0, stack_1 = stack; _i < stack_1.length; _i++) {
|
|
1244
|
+
var line = stack_1[_i], parent_1 = (_a = line.parent) === null || _a === void 0 ? void 0 : _a.call(line);
|
|
1245
|
+
if (parent_1 && ownerDocument.contains(parent_1)) {
|
|
1246
|
+
for (var left = (_b = line.left) === null || _b === void 0 ? void 0 : _b.call(line), savedCurrent = line.current(), current = parent_1.contains(savedCurrent) ? savedCurrent : void 0, right = (_c = line.right) === null || _c === void 0 ? void 0 : _c.call(line), focusables = getTabbableNodes([parent_1], visibilityCache), aim = (
|
|
1247
|
+
// that is element itself
|
|
1248
|
+
(_e = (_d = current ?? left?.nextElementSibling) !== null && _d !== void 0 ? _d : (
|
|
1249
|
+
// or somebody to the right, still close enough
|
|
1250
|
+
right
|
|
1251
|
+
)) !== null && _e !== void 0 ? _e : (
|
|
1252
|
+
// or somebody to the left, something?
|
|
1253
|
+
left
|
|
1254
|
+
)
|
|
1255
|
+
); aim; ) {
|
|
1256
|
+
for (var _f = 0, focusables_1 = focusables; _f < focusables_1.length; _f++) {
|
|
1257
|
+
var focusable = focusables_1[_f];
|
|
1258
|
+
if (aim?.contains(focusable.node))
|
|
1259
|
+
return focusable.node;
|
|
1260
|
+
}
|
|
1261
|
+
aim = aim.nextElementSibling;
|
|
1262
|
+
}
|
|
1263
|
+
if (focusables.length)
|
|
1264
|
+
return focusables[0].node;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
}, captureFocusRestore = function(targetElement) {
|
|
1268
|
+
var location = recordElementLocation(targetElement);
|
|
1269
|
+
return function() {
|
|
1270
|
+
return restoreFocusTo(location);
|
|
1271
|
+
};
|
|
1272
|
+
}, getRelativeFocusable = function(element, scope, useTabbables) {
|
|
1273
|
+
if (!element || !scope)
|
|
1274
|
+
return console.error("no element or scope given"), {};
|
|
1275
|
+
var shards = asArray(scope);
|
|
1276
|
+
if (shards.every(function(shard) {
|
|
1277
|
+
return !contains(shard, element);
|
|
1278
|
+
}))
|
|
1279
|
+
return console.error("Active element is not contained in the scope"), {};
|
|
1280
|
+
var focusables = useTabbables ? getTabbableNodes(shards, /* @__PURE__ */ new Map()) : getFocusableNodes(shards, /* @__PURE__ */ new Map()), current = focusables.findIndex(function(_a) {
|
|
1281
|
+
var node = _a.node;
|
|
1282
|
+
return node === element;
|
|
1283
|
+
});
|
|
1284
|
+
if (current !== -1)
|
|
1285
|
+
return {
|
|
1286
|
+
prev: focusables[current - 1],
|
|
1287
|
+
next: focusables[current + 1],
|
|
1288
|
+
first: focusables[0],
|
|
1289
|
+
last: focusables[focusables.length - 1]
|
|
1290
|
+
};
|
|
1291
|
+
}, getBoundary = function(shards, useTabbables) {
|
|
1292
|
+
var set2 = useTabbables ? getTabbableNodes(asArray(shards), /* @__PURE__ */ new Map()) : getFocusableNodes(asArray(shards), /* @__PURE__ */ new Map());
|
|
1293
|
+
return {
|
|
1294
|
+
first: set2[0],
|
|
1295
|
+
last: set2[set2.length - 1]
|
|
1296
|
+
};
|
|
1297
|
+
}, defaultOptions$1 = function(options) {
|
|
1298
|
+
return Object.assign({
|
|
1299
|
+
scope: document.body,
|
|
1300
|
+
cycle: !0,
|
|
1301
|
+
onlyTabbable: !0
|
|
1302
|
+
}, options);
|
|
1303
|
+
}, moveFocus = function(fromElement, options, cb) {
|
|
1304
|
+
options === void 0 && (options = {});
|
|
1305
|
+
var newOptions = defaultOptions$1(options), solution = getRelativeFocusable(fromElement, newOptions.scope, newOptions.onlyTabbable);
|
|
1306
|
+
if (solution) {
|
|
1307
|
+
var target = cb(solution, newOptions.cycle);
|
|
1308
|
+
target && focusOn(target.node, newOptions.focusOptions);
|
|
1309
|
+
}
|
|
1310
|
+
}, focusNextElement = function(fromElement, options) {
|
|
1311
|
+
options === void 0 && (options = {}), moveFocus(fromElement, options, function(_a, cycle) {
|
|
1312
|
+
var next = _a.next, first = _a.first;
|
|
1313
|
+
return next || cycle && first;
|
|
1314
|
+
});
|
|
1315
|
+
}, focusPrevElement = function(fromElement, options) {
|
|
1316
|
+
options === void 0 && (options = {}), moveFocus(fromElement, options, function(_a, cycle) {
|
|
1317
|
+
var prev = _a.prev, last = _a.last;
|
|
1318
|
+
return prev || cycle && last;
|
|
1319
|
+
});
|
|
1320
|
+
}, pickBoundary = function(scope, options, what) {
|
|
1321
|
+
var _a, boundary = getBoundary(scope, (_a = options.onlyTabbable) !== null && _a !== void 0 ? _a : !0), node = boundary[what];
|
|
1322
|
+
node && focusOn(node.node, options.focusOptions);
|
|
1323
|
+
}, focusFirstElement = function(scope, options) {
|
|
1324
|
+
options === void 0 && (options = {}), pickBoundary(scope, options, "first");
|
|
1325
|
+
}, focusLastElement = function(scope, options) {
|
|
1326
|
+
options === void 0 && (options = {}), pickBoundary(scope, options, "last");
|
|
1327
|
+
};
|
|
1328
|
+
function deferAction(action) {
|
|
1329
|
+
setTimeout(action, 1);
|
|
1330
|
+
}
|
|
1331
|
+
var extractRef = function(ref) {
|
|
1332
|
+
return ref && "current" in ref ? ref.current : ref;
|
|
1333
|
+
}, focusOnBody = function() {
|
|
1334
|
+
return document && document.activeElement === document.body;
|
|
1335
|
+
}, isFreeFocus = function() {
|
|
1336
|
+
return focusOnBody() || focusIsHidden();
|
|
1337
|
+
}, lastActiveTrap = null, lastActiveFocus = null, tryRestoreFocus = function() {
|
|
1338
|
+
return null;
|
|
1339
|
+
}, lastPortaledElement = null, focusWasOutsideWindow = !1, windowFocused = !1, defaultWhitelist = function() {
|
|
1340
|
+
return !0;
|
|
1341
|
+
}, focusWhitelisted = function(activeElement) {
|
|
1342
|
+
return (lastActiveTrap.whiteList || defaultWhitelist)(activeElement);
|
|
1343
|
+
}, recordPortal = function(observerNode, portaledElement) {
|
|
1344
|
+
lastPortaledElement = {
|
|
1345
|
+
observerNode,
|
|
1346
|
+
portaledElement
|
|
1347
|
+
};
|
|
1348
|
+
}, focusIsPortaledPair = function(element) {
|
|
1349
|
+
return lastPortaledElement && lastPortaledElement.portaledElement === element;
|
|
1350
|
+
};
|
|
1351
|
+
function autoGuard(startIndex, end, step, allNodes) {
|
|
1352
|
+
var lastGuard = null, i = startIndex;
|
|
1353
|
+
do {
|
|
1354
|
+
var item = allNodes[i];
|
|
1355
|
+
if (item.guard)
|
|
1356
|
+
item.node.dataset.focusAutoGuard && (lastGuard = item);
|
|
1357
|
+
else if (item.lockItem) {
|
|
1358
|
+
if (i !== startIndex)
|
|
1359
|
+
return;
|
|
1360
|
+
lastGuard = null;
|
|
1361
|
+
} else
|
|
1362
|
+
break;
|
|
1363
|
+
} while ((i += step) !== end);
|
|
1364
|
+
lastGuard && (lastGuard.node.tabIndex = 0);
|
|
1365
|
+
}
|
|
1366
|
+
var focusWasOutside = function(crossFrameOption) {
|
|
1367
|
+
return crossFrameOption ? !!focusWasOutsideWindow : focusWasOutsideWindow === "meanwhile";
|
|
1368
|
+
}, checkInHost = function checkInHost2(check, el, boundary) {
|
|
1369
|
+
return el && (el.host === check && (!el.activeElement || boundary.contains(el.activeElement)) || el.parentNode && checkInHost2(check, el.parentNode, boundary));
|
|
1370
|
+
}, withinHost = function(activeElement, workingArea) {
|
|
1371
|
+
return workingArea.some(function(area) {
|
|
1372
|
+
return checkInHost(activeElement, area, area);
|
|
1373
|
+
});
|
|
1374
|
+
}, getNodeFocusables = function(nodes) {
|
|
1375
|
+
return getFocusableNodes(nodes, /* @__PURE__ */ new Map());
|
|
1376
|
+
}, isNotFocusable = function(node) {
|
|
1377
|
+
return !getNodeFocusables([node.parentNode]).some(function(el) {
|
|
1378
|
+
return el.node === node;
|
|
1379
|
+
});
|
|
1380
|
+
}, activateTrap = function() {
|
|
1381
|
+
var result = !1;
|
|
1382
|
+
if (lastActiveTrap) {
|
|
1383
|
+
var _lastActiveTrap = lastActiveTrap, observed = _lastActiveTrap.observed, persistentFocus = _lastActiveTrap.persistentFocus, autoFocus = _lastActiveTrap.autoFocus, shards = _lastActiveTrap.shards, crossFrame = _lastActiveTrap.crossFrame, focusOptions = _lastActiveTrap.focusOptions, noFocusGuards = _lastActiveTrap.noFocusGuards, workingNode = observed || lastPortaledElement && lastPortaledElement.portaledElement;
|
|
1384
|
+
if (focusOnBody() && lastActiveFocus && lastActiveFocus !== document.body && (!document.body.contains(lastActiveFocus) || isNotFocusable(lastActiveFocus))) {
|
|
1385
|
+
var newTarget = tryRestoreFocus();
|
|
1386
|
+
newTarget && newTarget.focus();
|
|
1387
|
+
}
|
|
1388
|
+
var activeElement = document && document.activeElement;
|
|
1389
|
+
if (workingNode) {
|
|
1390
|
+
var workingArea = [workingNode].concat(shards.map(extractRef).filter(Boolean)), shouldForceRestoreFocus = function() {
|
|
1391
|
+
if (!focusWasOutside(crossFrame) || !noFocusGuards || !lastActiveFocus || windowFocused)
|
|
1392
|
+
return !1;
|
|
1393
|
+
var nodes = getNodeFocusables(workingArea), lastIndex = nodes.findIndex(function(_ref2) {
|
|
1394
|
+
var node = _ref2.node;
|
|
1395
|
+
return node === lastActiveFocus;
|
|
1396
|
+
});
|
|
1397
|
+
return lastIndex === 0 || lastIndex === nodes.length - 1;
|
|
1398
|
+
};
|
|
1399
|
+
if ((!activeElement || focusWhitelisted(activeElement)) && (persistentFocus || shouldForceRestoreFocus() || !isFreeFocus() || !lastActiveFocus && autoFocus) && (workingNode && !(focusInside(workingArea) || activeElement && withinHost(activeElement, workingArea) || focusIsPortaledPair(activeElement)) && (document && !lastActiveFocus && activeElement && !autoFocus ? (activeElement.blur && activeElement.blur(), document.body.focus()) : (result = moveFocusInside(workingArea, lastActiveFocus, {
|
|
1400
|
+
focusOptions
|
|
1401
|
+
}), lastPortaledElement = {})), lastActiveFocus = document && document.activeElement, lastActiveFocus !== document.body && (tryRestoreFocus = captureFocusRestore(lastActiveFocus)), focusWasOutsideWindow = !1), document && activeElement !== document.activeElement && document.querySelector("[data-focus-auto-guard]")) {
|
|
1402
|
+
var newActiveElement = document && document.activeElement, allNodes = expandFocusableNodes(workingArea), focusedIndex = allNodes.map(function(_ref2) {
|
|
1403
|
+
var node = _ref2.node;
|
|
1404
|
+
return node;
|
|
1405
|
+
}).indexOf(newActiveElement);
|
|
1406
|
+
focusedIndex > -1 && (allNodes.filter(function(_ref3) {
|
|
1407
|
+
var guard = _ref3.guard, node = _ref3.node;
|
|
1408
|
+
return guard && node.dataset.focusAutoGuard;
|
|
1409
|
+
}).forEach(function(_ref4) {
|
|
1410
|
+
var node = _ref4.node;
|
|
1411
|
+
return node.removeAttribute("tabIndex");
|
|
1412
|
+
}), autoGuard(focusedIndex, allNodes.length, 1, allNodes), autoGuard(focusedIndex, -1, -1, allNodes));
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
return result;
|
|
1417
|
+
}, onTrap = function(event) {
|
|
1418
|
+
activateTrap() && event && (event.stopPropagation(), event.preventDefault());
|
|
1419
|
+
}, onBlur = function() {
|
|
1420
|
+
return deferAction(activateTrap);
|
|
1421
|
+
}, onFocus = function(event) {
|
|
1422
|
+
var source = event.target, currentNode = event.currentTarget;
|
|
1423
|
+
currentNode.contains(source) || recordPortal(currentNode, source);
|
|
1424
|
+
}, FocusWatcher = function() {
|
|
1425
|
+
return null;
|
|
1426
|
+
}, onWindowFocus = function() {
|
|
1427
|
+
windowFocused = !0;
|
|
1428
|
+
}, onWindowBlur = function() {
|
|
1429
|
+
windowFocused = !1, focusWasOutsideWindow = "just", deferAction(function() {
|
|
1430
|
+
focusWasOutsideWindow = "meanwhile";
|
|
1431
|
+
});
|
|
1432
|
+
}, attachHandler = function() {
|
|
1433
|
+
document.addEventListener("focusin", onTrap), document.addEventListener("focusout", onBlur), window.addEventListener("focus", onWindowFocus), window.addEventListener("blur", onWindowBlur);
|
|
1434
|
+
}, detachHandler = function() {
|
|
1435
|
+
document.removeEventListener("focusin", onTrap), document.removeEventListener("focusout", onBlur), window.removeEventListener("focus", onWindowFocus), window.removeEventListener("blur", onWindowBlur);
|
|
1436
|
+
};
|
|
1437
|
+
function reducePropsToState(propsList) {
|
|
1438
|
+
return propsList.filter(function(_ref6) {
|
|
1439
|
+
var disabled = _ref6.disabled;
|
|
1440
|
+
return !disabled;
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
var focusLockAPI = {
|
|
1444
|
+
moveFocusInside,
|
|
1445
|
+
focusInside,
|
|
1446
|
+
focusNextElement,
|
|
1447
|
+
focusPrevElement,
|
|
1448
|
+
focusFirstElement,
|
|
1449
|
+
focusLastElement,
|
|
1450
|
+
captureFocusRestore
|
|
1451
|
+
};
|
|
1452
|
+
function handleStateChangeOnClient(traps) {
|
|
1453
|
+
var trap = traps.slice(-1)[0];
|
|
1454
|
+
trap && !lastActiveTrap && attachHandler();
|
|
1455
|
+
var lastTrap = lastActiveTrap, sameTrap = lastTrap && trap && trap.id === lastTrap.id;
|
|
1456
|
+
lastActiveTrap = trap, lastTrap && !sameTrap && (lastTrap.onDeactivation(), traps.filter(function(_ref7) {
|
|
1457
|
+
var id = _ref7.id;
|
|
1458
|
+
return id === lastTrap.id;
|
|
1459
|
+
}).length || lastTrap.returnFocus(!trap)), trap ? (lastActiveFocus = null, (!sameTrap || lastTrap.observed !== trap.observed) && trap.onActivation(focusLockAPI), activateTrap(), deferAction(activateTrap)) : (detachHandler(), lastActiveFocus = null);
|
|
1460
|
+
}
|
|
1461
|
+
mediumFocus.assignSyncMedium(onFocus);
|
|
1462
|
+
mediumBlur.assignMedium(onBlur);
|
|
1463
|
+
mediumEffect.assignMedium(function(cb) {
|
|
1464
|
+
return cb(focusLockAPI);
|
|
1465
|
+
});
|
|
1466
|
+
var FocusTrap = withSideEffect(reducePropsToState, handleStateChangeOnClient)(FocusWatcher), FocusLockCombination = /* @__PURE__ */ forwardRef(function(props, ref) {
|
|
1467
|
+
return /* @__PURE__ */ React__default.createElement(FocusLock, _extends({
|
|
1468
|
+
sideCar: FocusTrap,
|
|
1469
|
+
ref
|
|
1470
|
+
}, props));
|
|
1471
|
+
}), _ref = FocusLock.propTypes || {}, propTypes = _objectWithoutPropertiesLoose(_ref, ["sideCar"]);
|
|
1472
|
+
FocusLockCombination.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {};
|
|
1473
|
+
const millisecondsInWeek = 6048e5, constructFromSymbol = Symbol.for("constructDateFrom");
|
|
1474
|
+
function constructFrom(date, value) {
|
|
1475
|
+
return typeof date == "function" ? date(value) : date && typeof date == "object" && constructFromSymbol in date ? date[constructFromSymbol](value) : date instanceof Date ? new date.constructor(value) : new Date(value);
|
|
1476
|
+
}
|
|
1477
|
+
function toDate(argument, context) {
|
|
1478
|
+
return constructFrom(argument, argument);
|
|
1479
|
+
}
|
|
1480
|
+
function addDays(date, amount, options) {
|
|
1481
|
+
const _date = toDate(date);
|
|
1482
|
+
return isNaN(amount) ? constructFrom(date, NaN) : (amount && _date.setDate(_date.getDate() + amount), _date);
|
|
1483
|
+
}
|
|
1484
|
+
function addMonths(date, amount, options) {
|
|
1485
|
+
const _date = toDate(date);
|
|
1486
|
+
if (isNaN(amount)) return constructFrom(date, NaN);
|
|
1487
|
+
if (!amount)
|
|
1488
|
+
return _date;
|
|
1489
|
+
const dayOfMonth = _date.getDate(), endOfDesiredMonth = constructFrom(date, _date.getTime());
|
|
1490
|
+
endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
|
|
1491
|
+
const daysInMonth = endOfDesiredMonth.getDate();
|
|
1492
|
+
return dayOfMonth >= daysInMonth ? endOfDesiredMonth : (_date.setFullYear(
|
|
1493
|
+
endOfDesiredMonth.getFullYear(),
|
|
1494
|
+
endOfDesiredMonth.getMonth(),
|
|
1495
|
+
dayOfMonth
|
|
1496
|
+
), _date);
|
|
1497
|
+
}
|
|
1498
|
+
let defaultOptions = {};
|
|
1499
|
+
function getDefaultOptions() {
|
|
1500
|
+
return defaultOptions;
|
|
1501
|
+
}
|
|
1502
|
+
function startOfWeek(date, options) {
|
|
1503
|
+
const defaultOptions2 = getDefaultOptions(), weekStartsOn = defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0, _date = toDate(date), day = _date.getDay(), diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
|
|
1504
|
+
return _date.setDate(_date.getDate() - diff), _date.setHours(0, 0, 0, 0), _date;
|
|
1505
|
+
}
|
|
1506
|
+
function normalizeDates(context, ...dates) {
|
|
1507
|
+
const normalize = constructFrom.bind(
|
|
1508
|
+
null,
|
|
1509
|
+
dates.find((date) => typeof date == "object")
|
|
1510
|
+
);
|
|
1511
|
+
return dates.map(normalize);
|
|
1512
|
+
}
|
|
1513
|
+
function startOfDay(date, options) {
|
|
1514
|
+
const _date = toDate(date);
|
|
1515
|
+
return _date.setHours(0, 0, 0, 0), _date;
|
|
1516
|
+
}
|
|
1517
|
+
function addWeeks(date, amount, options) {
|
|
1518
|
+
return addDays(date, amount * 7);
|
|
1519
|
+
}
|
|
1520
|
+
function isSameDay(laterDate, earlierDate, options) {
|
|
1521
|
+
const [dateLeft_, dateRight_] = normalizeDates(
|
|
1522
|
+
options?.in,
|
|
1523
|
+
laterDate,
|
|
1524
|
+
earlierDate
|
|
1525
|
+
);
|
|
1526
|
+
return +startOfDay(dateLeft_) == +startOfDay(dateRight_);
|
|
1527
|
+
}
|
|
1528
|
+
function normalizeInterval(context, interval) {
|
|
1529
|
+
const [start, end] = normalizeDates(context, interval.start, interval.end);
|
|
1530
|
+
return { start, end };
|
|
1531
|
+
}
|
|
1532
|
+
function eachWeekOfInterval(interval, options) {
|
|
1533
|
+
const { start, end } = normalizeInterval(options?.in, interval);
|
|
1534
|
+
let reversed = +start > +end;
|
|
1535
|
+
const startDateWeek = startOfWeek(reversed ? end : start), endDateWeek = startOfWeek(reversed ? start : end);
|
|
1536
|
+
startDateWeek.setHours(15), endDateWeek.setHours(15);
|
|
1537
|
+
const endTime = +endDateWeek.getTime();
|
|
1538
|
+
let currentDate = startDateWeek, step = 1;
|
|
1539
|
+
const dates = [];
|
|
1540
|
+
for (; +currentDate <= endTime; )
|
|
1541
|
+
currentDate.setHours(0), dates.push(constructFrom(start, currentDate)), currentDate = addWeeks(currentDate, step), currentDate.setHours(15);
|
|
1542
|
+
return reversed ? dates.reverse() : dates;
|
|
1543
|
+
}
|
|
1544
|
+
function startOfMonth(date, options) {
|
|
1545
|
+
const _date = toDate(date);
|
|
1546
|
+
return _date.setDate(1), _date.setHours(0, 0, 0, 0), _date;
|
|
1547
|
+
}
|
|
1548
|
+
function getWeekYear(date, options) {
|
|
1549
|
+
const _date = toDate(date), year = _date.getFullYear(), defaultOptions2 = getDefaultOptions(), firstWeekContainsDate = defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1, firstWeekOfNextYear = constructFrom(date, 0);
|
|
1550
|
+
firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate), firstWeekOfNextYear.setHours(0, 0, 0, 0);
|
|
1551
|
+
const startOfNextYear = startOfWeek(firstWeekOfNextYear), firstWeekOfThisYear = constructFrom(date, 0);
|
|
1552
|
+
firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate), firstWeekOfThisYear.setHours(0, 0, 0, 0);
|
|
1553
|
+
const startOfThisYear = startOfWeek(firstWeekOfThisYear);
|
|
1554
|
+
return +_date >= +startOfNextYear ? year + 1 : +_date >= +startOfThisYear ? year : year - 1;
|
|
1555
|
+
}
|
|
1556
|
+
function startOfWeekYear(date, options) {
|
|
1557
|
+
const defaultOptions2 = getDefaultOptions(), firstWeekContainsDate = defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1, year = getWeekYear(date), firstWeek = constructFrom(date, 0);
|
|
1558
|
+
return firstWeek.setFullYear(year, 0, firstWeekContainsDate), firstWeek.setHours(0, 0, 0, 0), startOfWeek(firstWeek);
|
|
1559
|
+
}
|
|
1560
|
+
function getWeek(date, options) {
|
|
1561
|
+
const _date = toDate(date), diff = +startOfWeek(_date) - +startOfWeekYear(_date);
|
|
1562
|
+
return Math.round(diff / millisecondsInWeek) + 1;
|
|
1563
|
+
}
|
|
1564
|
+
function getDaysInMonth(date, options) {
|
|
1565
|
+
const _date = toDate(date), year = _date.getFullYear(), monthIndex = _date.getMonth(), lastDayOfMonth2 = constructFrom(_date, 0);
|
|
1566
|
+
return lastDayOfMonth2.setFullYear(year, monthIndex + 1, 0), lastDayOfMonth2.setHours(0, 0, 0, 0), lastDayOfMonth2.getDate();
|
|
1567
|
+
}
|
|
1568
|
+
function lastDayOfMonth(date, options) {
|
|
1569
|
+
const _date = toDate(date), month = _date.getMonth();
|
|
1570
|
+
return _date.setFullYear(_date.getFullYear(), month + 1, 0), _date.setHours(0, 0, 0, 0), toDate(_date);
|
|
1571
|
+
}
|
|
1572
|
+
function isSameMonth(laterDate, earlierDate, options) {
|
|
1573
|
+
const [laterDate_, earlierDate_] = normalizeDates(
|
|
1574
|
+
options?.in,
|
|
1575
|
+
laterDate,
|
|
1576
|
+
earlierDate
|
|
1577
|
+
);
|
|
1578
|
+
return laterDate_.getFullYear() === earlierDate_.getFullYear() && laterDate_.getMonth() === earlierDate_.getMonth();
|
|
1579
|
+
}
|
|
1580
|
+
function setMonth(date, month, options) {
|
|
1581
|
+
const _date = toDate(date), year = _date.getFullYear(), day = _date.getDate(), midMonth = constructFrom(date, 0);
|
|
1582
|
+
midMonth.setFullYear(year, month, 15), midMonth.setHours(0, 0, 0, 0);
|
|
1583
|
+
const daysInMonth = getDaysInMonth(midMonth);
|
|
1584
|
+
return _date.setMonth(month, Math.min(day, daysInMonth)), _date;
|
|
1585
|
+
}
|
|
1586
|
+
function setDate(date, dayOfMonth, options) {
|
|
1587
|
+
const _date = toDate(date);
|
|
1588
|
+
return _date.setDate(dayOfMonth), _date;
|
|
1589
|
+
}
|
|
1590
|
+
function setHours(date, hours, options) {
|
|
1591
|
+
const _date = toDate(date);
|
|
1592
|
+
return _date.setHours(hours), _date;
|
|
1593
|
+
}
|
|
1594
|
+
function setMinutes(date, minutes, options) {
|
|
1595
|
+
const date_ = toDate(date);
|
|
1596
|
+
return date_.setMinutes(minutes), date_;
|
|
1597
|
+
}
|
|
1598
|
+
function setYear(date, year, options) {
|
|
1599
|
+
const date_ = toDate(date);
|
|
1600
|
+
return isNaN(+date_) ? constructFrom(date, NaN) : (date_.setFullYear(year), date_);
|
|
1601
|
+
}
|
|
1602
|
+
function CalendarDay(props) {
|
|
1603
|
+
const { date, focused, isCurrentMonth, isToday, onSelect, selected } = props, handleClick = useCallback(() => {
|
|
1604
|
+
onSelect(date);
|
|
1605
|
+
}, [date, onSelect]);
|
|
1606
|
+
return /* @__PURE__ */ jsx("div", { "aria-selected": selected, "data-ui": "CalendarDay", children: /* @__PURE__ */ jsx(
|
|
1607
|
+
Card,
|
|
1608
|
+
{
|
|
1609
|
+
"aria-label": date.toDateString(),
|
|
1610
|
+
"aria-pressed": selected,
|
|
1611
|
+
as: "button",
|
|
1612
|
+
__unstable_focusRing: !0,
|
|
1613
|
+
"data-weekday": !0,
|
|
1614
|
+
"data-focused": focused ? "true" : "",
|
|
1615
|
+
role: "button",
|
|
1616
|
+
tabIndex: -1,
|
|
1617
|
+
onClick: handleClick,
|
|
1618
|
+
padding: 3,
|
|
1619
|
+
radius: 2,
|
|
1620
|
+
selected,
|
|
1621
|
+
tone: isToday || selected ? "primary" : "default",
|
|
1622
|
+
children: /* @__PURE__ */ jsx(
|
|
1623
|
+
Text,
|
|
1624
|
+
{
|
|
1625
|
+
muted: !selected && !isCurrentMonth,
|
|
1626
|
+
style: { textAlign: "center" },
|
|
1627
|
+
weight: isCurrentMonth ? "medium" : "regular",
|
|
1628
|
+
children: date.getDate()
|
|
1629
|
+
}
|
|
1630
|
+
)
|
|
1631
|
+
}
|
|
1632
|
+
) });
|
|
1633
|
+
}
|
|
1634
|
+
const MONTH_NAMES = [
|
|
1635
|
+
"January",
|
|
1636
|
+
"February",
|
|
1637
|
+
"March",
|
|
1638
|
+
"April",
|
|
1639
|
+
"May",
|
|
1640
|
+
"June",
|
|
1641
|
+
"July",
|
|
1642
|
+
"August",
|
|
1643
|
+
"September",
|
|
1644
|
+
"October",
|
|
1645
|
+
"November",
|
|
1646
|
+
"December"
|
|
1647
|
+
], WEEK_DAY_NAMES = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], HOURS_24 = range(0, 24), ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"], TAIL_WEEKDAYS = [1, 2, 3, 4, 5, 6], getWeekStartsOfMonth = (date) => {
|
|
1648
|
+
const firstDay = startOfMonth(date);
|
|
1649
|
+
return eachWeekOfInterval({
|
|
1650
|
+
start: firstDay,
|
|
1651
|
+
end: lastDayOfMonth(firstDay)
|
|
1652
|
+
});
|
|
1653
|
+
}, getWeekDaysFromWeekStarts = (weekStarts) => weekStarts.map((weekStart) => [
|
|
1654
|
+
weekStart,
|
|
1655
|
+
...TAIL_WEEKDAYS.map((d) => addDays(weekStart, d))
|
|
1656
|
+
]), getWeeksOfMonth = (date) => getWeekDaysFromWeekStarts(getWeekStartsOfMonth(date)).map(
|
|
1657
|
+
(days) => ({
|
|
1658
|
+
number: getWeek(days[0]),
|
|
1659
|
+
days
|
|
1660
|
+
})
|
|
1661
|
+
);
|
|
1662
|
+
function CalendarMonth(props) {
|
|
1663
|
+
return /* @__PURE__ */ jsx(Box, { "aria-hidden": props.hidden || !1, "data-ui": "CalendarMonth", children: /* @__PURE__ */ jsxs(Grid, { gap: 1, style: { gridTemplateColumns: "repeat(7, minmax(44px, 46px))" }, children: [
|
|
1664
|
+
WEEK_DAY_NAMES.map((weekday) => /* @__PURE__ */ jsx(Box, { paddingY: 2, children: /* @__PURE__ */ jsx(Text, { size: 1, weight: "medium", style: { textAlign: "center" }, children: weekday }) }, weekday)),
|
|
1665
|
+
getWeeksOfMonth(props.date).map(
|
|
1666
|
+
(week, weekIdx) => week.days.map((date, dayIdx) => {
|
|
1667
|
+
const focused = props.focused && isSameDay(date, props.focused), selected = props.selected && isSameDay(date, props.selected), isToday = isSameDay(date, /* @__PURE__ */ new Date()), isCurrentMonth = props.focused && isSameMonth(date, props.focused);
|
|
1668
|
+
return /* @__PURE__ */ jsx(
|
|
1669
|
+
CalendarDay,
|
|
1670
|
+
{
|
|
1671
|
+
date,
|
|
1672
|
+
focused,
|
|
1673
|
+
isCurrentMonth,
|
|
1674
|
+
isToday,
|
|
1675
|
+
onSelect: props.onSelect,
|
|
1676
|
+
selected
|
|
1677
|
+
},
|
|
1678
|
+
`${weekIdx}-${dayIdx}`
|
|
1679
|
+
);
|
|
1680
|
+
})
|
|
1681
|
+
)
|
|
1682
|
+
] }) });
|
|
1683
|
+
}
|
|
1684
|
+
const features = {
|
|
1685
|
+
dayPresets: !1,
|
|
1686
|
+
timePresets: !1
|
|
1687
|
+
}, LazyTextInput = React__default.forwardRef(function({ onChange, onBlur: onBlur3, onKeyPress, value, ...rest }, forwardedRef) {
|
|
1688
|
+
const [inputValue, setInputValue] = React__default.useState(), handleChange = React__default.useCallback((event) => {
|
|
1689
|
+
setInputValue(event.currentTarget.value);
|
|
1690
|
+
}, []), checkEvent = React__default.useCallback(
|
|
1691
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1692
|
+
(event) => {
|
|
1693
|
+
event.currentTarget.value !== `${value}` && onChange && onChange(event), setInputValue(void 0);
|
|
1694
|
+
},
|
|
1695
|
+
[onChange, value]
|
|
1696
|
+
), handleBlur = React__default.useCallback(
|
|
1697
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1698
|
+
(e) => {
|
|
1699
|
+
checkEvent(e), onBlur3 && onBlur3(e);
|
|
1700
|
+
},
|
|
1701
|
+
[checkEvent, onBlur3]
|
|
1702
|
+
), handleKeyPress = React__default.useCallback(
|
|
1703
|
+
(e) => {
|
|
1704
|
+
e.key === "Enter" && checkEvent(e), onKeyPress && onKeyPress(e);
|
|
1705
|
+
},
|
|
1706
|
+
[checkEvent, onKeyPress]
|
|
1707
|
+
);
|
|
1708
|
+
return /* @__PURE__ */ jsx(
|
|
1709
|
+
TextInput,
|
|
1710
|
+
{
|
|
1711
|
+
...rest,
|
|
1712
|
+
"data-testid": "date-input",
|
|
1713
|
+
ref: forwardedRef,
|
|
1714
|
+
value: inputValue === void 0 ? value : inputValue,
|
|
1715
|
+
onChange: handleChange,
|
|
1716
|
+
onBlur: handleBlur,
|
|
1717
|
+
onKeyPress: handleKeyPress
|
|
1718
|
+
}
|
|
1719
|
+
);
|
|
1720
|
+
}), YearInput = ({ onChange, ...props }) => {
|
|
1721
|
+
const handleChange = React__default.useCallback(
|
|
1722
|
+
(event) => {
|
|
1723
|
+
const numericValue = parseInt(event.currentTarget.value, 10);
|
|
1724
|
+
isNaN(numericValue) || onChange(numericValue);
|
|
1725
|
+
},
|
|
1726
|
+
[onChange]
|
|
1727
|
+
);
|
|
1728
|
+
return /* @__PURE__ */ jsx(LazyTextInput, { ...props, onChange: handleChange, inputMode: "numeric" });
|
|
1729
|
+
}, PRESERVE_FOCUS_ELEMENT = /* @__PURE__ */ jsx(
|
|
1730
|
+
"span",
|
|
1731
|
+
{
|
|
1732
|
+
"data-preserve-focus": !0,
|
|
1733
|
+
style: { overflow: "hidden", position: "absolute", outline: "none" },
|
|
1734
|
+
tabIndex: -1
|
|
1735
|
+
}
|
|
1736
|
+
), Calendar = forwardRef(function(props, forwardedRef) {
|
|
1737
|
+
const {
|
|
1738
|
+
selectTime,
|
|
1739
|
+
onFocusedDateChange,
|
|
1740
|
+
selectedDate = /* @__PURE__ */ new Date(),
|
|
1741
|
+
focusedDate = selectedDate,
|
|
1742
|
+
timeStep = 1,
|
|
1743
|
+
onSelect,
|
|
1744
|
+
...restProps
|
|
1745
|
+
} = props, setFocusedDate = useCallback(
|
|
1746
|
+
(date) => onFocusedDateChange(date),
|
|
1747
|
+
[onFocusedDateChange]
|
|
1748
|
+
), setFocusedDateMonth = useCallback(
|
|
1749
|
+
(month) => setFocusedDate(setDate(setMonth(focusedDate, month), 1)),
|
|
1750
|
+
[focusedDate, setFocusedDate]
|
|
1751
|
+
), handleFocusedMonthChange = useCallback(
|
|
1752
|
+
(e) => setFocusedDateMonth(Number(e.currentTarget.value)),
|
|
1753
|
+
[setFocusedDateMonth]
|
|
1754
|
+
), moveFocusedDate = useCallback(
|
|
1755
|
+
(by) => setFocusedDate(addMonths(focusedDate, by)),
|
|
1756
|
+
[focusedDate, setFocusedDate]
|
|
1757
|
+
), setFocusedDateYear = useCallback(
|
|
1758
|
+
(year) => setFocusedDate(setYear(focusedDate, year)),
|
|
1759
|
+
[focusedDate, setFocusedDate]
|
|
1760
|
+
), handleDateChange = useCallback(
|
|
1761
|
+
(date) => {
|
|
1762
|
+
onSelect(setMinutes(setHours(date, selectedDate.getHours()), selectedDate.getMinutes()));
|
|
1763
|
+
},
|
|
1764
|
+
[onSelect, selectedDate]
|
|
1765
|
+
), handleMinutesChange = useCallback(
|
|
1766
|
+
(event) => {
|
|
1767
|
+
const m = Number(event.currentTarget.value);
|
|
1768
|
+
onSelect(setMinutes(selectedDate, m));
|
|
1769
|
+
},
|
|
1770
|
+
[onSelect, selectedDate]
|
|
1771
|
+
), handleHoursChange = useCallback(
|
|
1772
|
+
(event) => {
|
|
1773
|
+
const m = Number(event.currentTarget.value);
|
|
1774
|
+
onSelect(setHours(selectedDate, m));
|
|
1775
|
+
},
|
|
1776
|
+
[onSelect, selectedDate]
|
|
1777
|
+
);
|
|
1778
|
+
useCallback(
|
|
1779
|
+
(hours, mins) => {
|
|
1780
|
+
onSelect(setHours(setMinutes(selectedDate, mins), hours));
|
|
1781
|
+
},
|
|
1782
|
+
[onSelect, selectedDate]
|
|
1783
|
+
);
|
|
1784
|
+
const ref = useForwardedRef(forwardedRef), focusCurrentWeekDay = useCallback(() => {
|
|
1785
|
+
ref.current?.querySelector('[data-focused="true"]')?.focus();
|
|
1786
|
+
}, [ref]), handleKeyDown = useCallback(
|
|
1787
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1788
|
+
(event) => {
|
|
1789
|
+
if (ARROW_KEYS.includes(event.key)) {
|
|
1790
|
+
if (event.preventDefault(), event.target.hasAttribute("data-calendar-grid")) {
|
|
1791
|
+
focusCurrentWeekDay();
|
|
1792
|
+
return;
|
|
1793
|
+
}
|
|
1794
|
+
event.key === "ArrowUp" && onFocusedDateChange(addDays(focusedDate, -7)), event.key === "ArrowDown" && onFocusedDateChange(addDays(focusedDate, 7)), event.key === "ArrowLeft" && onFocusedDateChange(addDays(focusedDate, -1)), event.key === "ArrowRight" && onFocusedDateChange(addDays(focusedDate, 1)), ref.current?.querySelector("[data-preserve-focus]")?.focus();
|
|
1795
|
+
}
|
|
1796
|
+
},
|
|
1797
|
+
[ref, focusCurrentWeekDay, onFocusedDateChange, focusedDate]
|
|
1798
|
+
);
|
|
1799
|
+
useEffect(() => {
|
|
1800
|
+
focusCurrentWeekDay();
|
|
1801
|
+
}, [focusCurrentWeekDay]), useEffect(() => {
|
|
1802
|
+
document.activeElement?.matches(
|
|
1803
|
+
"[data-calendar-grid], [data-calendar-grid] [data-preserve-focus]"
|
|
1804
|
+
) && focusCurrentWeekDay();
|
|
1805
|
+
}, [ref, focusCurrentWeekDay, focusedDate]), useCallback(
|
|
1806
|
+
() => handleDateChange(addDays(/* @__PURE__ */ new Date(), -1)),
|
|
1807
|
+
[handleDateChange]
|
|
1808
|
+
), useCallback(() => handleDateChange(/* @__PURE__ */ new Date()), [handleDateChange]), useCallback(
|
|
1809
|
+
() => handleDateChange(addDays(/* @__PURE__ */ new Date(), 1)),
|
|
1810
|
+
[handleDateChange]
|
|
1811
|
+
);
|
|
1812
|
+
const handleNowClick = useCallback(() => onSelect(/* @__PURE__ */ new Date()), [onSelect]);
|
|
1813
|
+
return /* @__PURE__ */ jsxs(Box, { "data-ui": "Calendar", ...restProps, ref, children: [
|
|
1814
|
+
/* @__PURE__ */ jsxs(Box, { padding: 2, children: [
|
|
1815
|
+
features.dayPresets,
|
|
1816
|
+
/* @__PURE__ */ jsxs(Flex, { children: [
|
|
1817
|
+
/* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(
|
|
1818
|
+
CalendarMonthSelect,
|
|
1819
|
+
{
|
|
1820
|
+
moveFocusedDate,
|
|
1821
|
+
onChange: handleFocusedMonthChange,
|
|
1822
|
+
value: focusedDate?.getMonth()
|
|
1823
|
+
}
|
|
1824
|
+
) }),
|
|
1825
|
+
/* @__PURE__ */ jsx(Box, { marginLeft: 2, children: /* @__PURE__ */ jsx(
|
|
1826
|
+
CalendarYearSelect,
|
|
1827
|
+
{
|
|
1828
|
+
moveFocusedDate,
|
|
1829
|
+
onChange: setFocusedDateYear,
|
|
1830
|
+
value: focusedDate.getFullYear()
|
|
1831
|
+
}
|
|
1832
|
+
) })
|
|
1833
|
+
] }),
|
|
1834
|
+
/* @__PURE__ */ jsxs(
|
|
1835
|
+
Box,
|
|
1836
|
+
{
|
|
1837
|
+
"data-calendar-grid": !0,
|
|
1838
|
+
onKeyDown: handleKeyDown,
|
|
1839
|
+
marginTop: 2,
|
|
1840
|
+
overflow: "hidden",
|
|
1841
|
+
tabIndex: 0,
|
|
1842
|
+
children: [
|
|
1843
|
+
/* @__PURE__ */ jsx(
|
|
1844
|
+
CalendarMonth,
|
|
1845
|
+
{
|
|
1846
|
+
date: focusedDate,
|
|
1847
|
+
focused: focusedDate,
|
|
1848
|
+
onSelect: handleDateChange,
|
|
1849
|
+
selected: selectedDate
|
|
1850
|
+
}
|
|
1851
|
+
),
|
|
1852
|
+
PRESERVE_FOCUS_ELEMENT
|
|
1853
|
+
]
|
|
1854
|
+
}
|
|
1855
|
+
)
|
|
1856
|
+
] }),
|
|
1857
|
+
selectTime && /* @__PURE__ */ jsxs(Box, { padding: 2, style: { borderTop: "1px solid var(--card-border-color)" }, children: [
|
|
1858
|
+
/* @__PURE__ */ jsxs(Flex, { align: "center", children: [
|
|
1859
|
+
/* @__PURE__ */ jsxs(Flex, { align: "center", flex: 1, children: [
|
|
1860
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
|
|
1861
|
+
Select,
|
|
1862
|
+
{
|
|
1863
|
+
"aria-label": "Select hour",
|
|
1864
|
+
value: selectedDate?.getHours(),
|
|
1865
|
+
onChange: handleHoursChange,
|
|
1866
|
+
children: HOURS_24.map((h) => /* @__PURE__ */ jsx("option", { value: h, children: `${h}`.padStart(2, "0") }, h))
|
|
1867
|
+
}
|
|
1868
|
+
) }),
|
|
1869
|
+
/* @__PURE__ */ jsx(Box, { paddingX: 1, children: /* @__PURE__ */ jsx(Text, { children: ":" }) }),
|
|
1870
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
|
|
1871
|
+
Select,
|
|
1872
|
+
{
|
|
1873
|
+
"aria-label": "Select minutes",
|
|
1874
|
+
value: selectedDate?.getMinutes(),
|
|
1875
|
+
onChange: handleMinutesChange,
|
|
1876
|
+
children: range(0, 60, timeStep).map((m) => /* @__PURE__ */ jsx("option", { value: m, children: `${m}`.padStart(2, "0") }, m))
|
|
1877
|
+
}
|
|
1878
|
+
) })
|
|
1879
|
+
] }),
|
|
1880
|
+
/* @__PURE__ */ jsx(Box, { marginLeft: 2, children: /* @__PURE__ */ jsx(Button, { text: "Set to current time", mode: "bleed", onClick: handleNowClick }) })
|
|
1881
|
+
] }),
|
|
1882
|
+
features.timePresets
|
|
1883
|
+
] })
|
|
1884
|
+
] });
|
|
1885
|
+
});
|
|
1886
|
+
function CalendarMonthSelect(props) {
|
|
1887
|
+
const { moveFocusedDate, onChange, value } = props, handlePrevMonthClick = useCallback(() => moveFocusedDate(-1), [moveFocusedDate]), handleNextMonthClick = useCallback(() => moveFocusedDate(1), [moveFocusedDate]);
|
|
1888
|
+
return /* @__PURE__ */ jsxs(Flex, { flex: 1, children: [
|
|
1889
|
+
/* @__PURE__ */ jsx(
|
|
1890
|
+
Button,
|
|
1891
|
+
{
|
|
1892
|
+
"aria-label": "Go to previous month",
|
|
1893
|
+
onClick: handlePrevMonthClick,
|
|
1894
|
+
mode: "bleed",
|
|
1895
|
+
icon: ChevronLeftIcon,
|
|
1896
|
+
paddingX: 2,
|
|
1897
|
+
radius: 0
|
|
1898
|
+
}
|
|
1899
|
+
),
|
|
1900
|
+
/* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(Select, { radius: 0, value, onChange, children: MONTH_NAMES.map((m, i) => (
|
|
1901
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
1902
|
+
/* @__PURE__ */ jsx("option", { value: i, children: m }, i)
|
|
1903
|
+
)) }) }),
|
|
1904
|
+
/* @__PURE__ */ jsx(
|
|
1905
|
+
Button,
|
|
1906
|
+
{
|
|
1907
|
+
"aria-label": "Go to next month",
|
|
1908
|
+
mode: "bleed",
|
|
1909
|
+
icon: ChevronRightIcon,
|
|
1910
|
+
onClick: handleNextMonthClick,
|
|
1911
|
+
paddingX: 2,
|
|
1912
|
+
radius: 0
|
|
1913
|
+
}
|
|
1914
|
+
)
|
|
1915
|
+
] });
|
|
1916
|
+
}
|
|
1917
|
+
function CalendarYearSelect(props) {
|
|
1918
|
+
const { moveFocusedDate, onChange, value } = props, handlePrevYearClick = useCallback(() => moveFocusedDate(-12), [moveFocusedDate]), handleNextYearClick = useCallback(() => moveFocusedDate(12), [moveFocusedDate]);
|
|
1919
|
+
return /* @__PURE__ */ jsxs(Flex, { children: [
|
|
1920
|
+
/* @__PURE__ */ jsx(
|
|
1921
|
+
Button,
|
|
1922
|
+
{
|
|
1923
|
+
"aria-label": "Previous year",
|
|
1924
|
+
onClick: handlePrevYearClick,
|
|
1925
|
+
mode: "bleed",
|
|
1926
|
+
icon: ChevronLeftIcon,
|
|
1927
|
+
paddingX: 2,
|
|
1928
|
+
radius: 0
|
|
1929
|
+
}
|
|
1930
|
+
),
|
|
1931
|
+
/* @__PURE__ */ jsx(YearInput, { value, onChange, radius: 0, style: { width: 65 } }),
|
|
1932
|
+
/* @__PURE__ */ jsx(
|
|
1933
|
+
Button,
|
|
1934
|
+
{
|
|
1935
|
+
"aria-label": "Next year",
|
|
1936
|
+
onClick: handleNextYearClick,
|
|
1937
|
+
mode: "bleed",
|
|
1938
|
+
icon: ChevronRightIcon,
|
|
1939
|
+
paddingX: 2,
|
|
1940
|
+
radius: 0
|
|
1941
|
+
}
|
|
1942
|
+
)
|
|
1943
|
+
] });
|
|
1944
|
+
}
|
|
1945
|
+
const DatePicker = React__default.forwardRef(function(props, ref) {
|
|
1946
|
+
const { value = /* @__PURE__ */ new Date(), onChange, ...rest } = props, [focusedDate, setFocusedDay] = React__default.useState(), handleSelect = React__default.useCallback(
|
|
1947
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1948
|
+
(nextDate) => {
|
|
1949
|
+
onChange(nextDate), setFocusedDay(void 0);
|
|
1950
|
+
},
|
|
1951
|
+
[onChange]
|
|
1952
|
+
);
|
|
1953
|
+
return /* @__PURE__ */ jsx(
|
|
1954
|
+
Calendar,
|
|
1955
|
+
{
|
|
1956
|
+
...rest,
|
|
1957
|
+
ref,
|
|
1958
|
+
selectedDate: value,
|
|
1959
|
+
onSelect: handleSelect,
|
|
1960
|
+
focusedDate: focusedDate || value,
|
|
1961
|
+
onFocusedDateChange: setFocusedDay
|
|
1962
|
+
}
|
|
1963
|
+
);
|
|
1964
|
+
}), DateTimeInput = forwardRef(function(props, ref) {
|
|
1965
|
+
const { value, inputValue, onInputChange, onChange, selectTime, timeStep, ...rest } = props, [popoverRef, setPopoverRef] = useState(null), forwardedRef = useForwardedRef(ref), buttonRef = useRef(null), [isPickerOpen, setPickerOpen] = useState(!1);
|
|
1966
|
+
useClickOutside(() => setPickerOpen(!1), [popoverRef]);
|
|
1967
|
+
const handleDeactivation = useCallback(() => {
|
|
1968
|
+
forwardedRef.current?.focus(), forwardedRef.current?.select();
|
|
1969
|
+
}, [forwardedRef]), handleKeyUp = useCallback((e) => {
|
|
1970
|
+
e.key === "Escape" && setPickerOpen(!1);
|
|
1971
|
+
}, []), handleClick = useCallback(() => setPickerOpen(!0), []), suffix = /* @__PURE__ */ jsx(Box, { padding: 1, children: /* @__PURE__ */ jsx(
|
|
1972
|
+
Button,
|
|
1973
|
+
{
|
|
1974
|
+
ref: buttonRef,
|
|
1975
|
+
icon: CalendarIcon,
|
|
1976
|
+
mode: "bleed",
|
|
1977
|
+
padding: 2,
|
|
1978
|
+
onClick: handleClick,
|
|
1979
|
+
style: { display: "block" },
|
|
1980
|
+
"data-testid": "select-date-button"
|
|
1981
|
+
}
|
|
1982
|
+
) });
|
|
1983
|
+
return /* @__PURE__ */ jsx(
|
|
1984
|
+
LazyTextInput,
|
|
1985
|
+
{
|
|
1986
|
+
ref: forwardedRef,
|
|
1987
|
+
...rest,
|
|
1988
|
+
value: inputValue,
|
|
1989
|
+
onChange: onInputChange,
|
|
1990
|
+
suffix: isPickerOpen ? (
|
|
1991
|
+
// Note: we're conditionally inserting the popover here due to an
|
|
1992
|
+
// issue with popovers rendering incorrectly on subsequent renders
|
|
1993
|
+
// see https://github.com/sanity-io/design/issues/519
|
|
1994
|
+
/* @__PURE__ */ jsx(LayerProvider, { zOffset: 1e3, children: /* @__PURE__ */ jsx(
|
|
1995
|
+
Popover,
|
|
1996
|
+
{
|
|
1997
|
+
constrainSize: !0,
|
|
1998
|
+
"data-testid": "date-input-dialog",
|
|
1999
|
+
portal: !0,
|
|
2000
|
+
content: /* @__PURE__ */ jsx(Box, { overflow: "auto", children: /* @__PURE__ */ jsx(FocusLockCombination, { onDeactivation: handleDeactivation, children: /* @__PURE__ */ jsx(
|
|
2001
|
+
DatePicker,
|
|
2002
|
+
{
|
|
2003
|
+
selectTime,
|
|
2004
|
+
timeStep,
|
|
2005
|
+
onKeyUp: handleKeyUp,
|
|
2006
|
+
value,
|
|
2007
|
+
onChange
|
|
2008
|
+
}
|
|
2009
|
+
) }) }),
|
|
2010
|
+
open: !0,
|
|
2011
|
+
placement: "bottom",
|
|
2012
|
+
ref: setPopoverRef,
|
|
2013
|
+
radius: 2,
|
|
2014
|
+
children: suffix
|
|
2015
|
+
}
|
|
2016
|
+
) })
|
|
2017
|
+
) : suffix
|
|
2018
|
+
}
|
|
2019
|
+
);
|
|
2020
|
+
}), DEFAULT_PLACEHOLDER_TIME = /* @__PURE__ */ new Date(), CommonDateTimeInput = React__default.forwardRef(function(props, ref) {
|
|
2021
|
+
const {
|
|
2022
|
+
id,
|
|
2023
|
+
deserialize: deserialize2,
|
|
2024
|
+
formatInputValue,
|
|
2025
|
+
onChange,
|
|
2026
|
+
parseInputValue,
|
|
2027
|
+
placeholder,
|
|
2028
|
+
readOnly,
|
|
2029
|
+
selectTime,
|
|
2030
|
+
serialize: serialize2,
|
|
2031
|
+
timeStep,
|
|
2032
|
+
value,
|
|
2033
|
+
...restProps
|
|
2034
|
+
} = props, [localValue, setLocalValue] = React__default.useState(null);
|
|
2035
|
+
useEffect(() => {
|
|
2036
|
+
setLocalValue(null);
|
|
2037
|
+
}, [value]);
|
|
2038
|
+
const handleDatePickerInputChange = React__default.useCallback(
|
|
2039
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2040
|
+
(event) => {
|
|
2041
|
+
const nextInputValue = event.currentTarget.value, result = nextInputValue === "" ? null : parseInputValue(nextInputValue);
|
|
2042
|
+
result === null ? (onChange(null), typeof value > "u" && localValue && setLocalValue(null)) : result.isValid ? onChange(serialize2(result.date)) : setLocalValue(nextInputValue);
|
|
2043
|
+
},
|
|
2044
|
+
[parseInputValue, onChange, value, localValue, serialize2]
|
|
2045
|
+
), handleDatePickerChange = React__default.useCallback(
|
|
2046
|
+
(nextDate) => {
|
|
2047
|
+
onChange(nextDate ? serialize2(nextDate) : null);
|
|
2048
|
+
},
|
|
2049
|
+
[serialize2, onChange]
|
|
2050
|
+
), forwardedRef = useForwardedRef(ref), parseResult = localValue ? parseInputValue(localValue) : value ? deserialize2(value) : null, inputValue = localValue || (parseResult?.isValid ? formatInputValue(parseResult.date) : value);
|
|
2051
|
+
return readOnly ? /* @__PURE__ */ jsx(TextInput, { value: inputValue, readOnly: !0, disabled: readOnly }) : /* @__PURE__ */ jsx(
|
|
2052
|
+
DateTimeInput,
|
|
2053
|
+
{
|
|
2054
|
+
...restProps,
|
|
2055
|
+
id,
|
|
2056
|
+
selectTime,
|
|
2057
|
+
timeStep,
|
|
2058
|
+
placeholder: placeholder || `e.g. ${formatInputValue(DEFAULT_PLACEHOLDER_TIME)}`,
|
|
2059
|
+
ref: forwardedRef,
|
|
2060
|
+
value: parseResult?.date,
|
|
2061
|
+
inputValue: inputValue || "",
|
|
2062
|
+
readOnly: !!readOnly,
|
|
2063
|
+
onInputChange: handleDatePickerInputChange,
|
|
2064
|
+
onChange: handleDatePickerChange,
|
|
2065
|
+
customValidity: parseResult?.error
|
|
2066
|
+
}
|
|
2067
|
+
);
|
|
2068
|
+
}), VALUE_FORMAT = "YYYY-MM-DD", DEFAULT_DATE_FORMAT = VALUE_FORMAT;
|
|
2069
|
+
function parseOptions(options = {}) {
|
|
2070
|
+
return {
|
|
2071
|
+
dateFormat: options.dateFormat || DEFAULT_DATE_FORMAT,
|
|
2072
|
+
calendarTodayLabel: options.calendarTodayLabel || "Today"
|
|
2073
|
+
};
|
|
2074
|
+
}
|
|
2075
|
+
const deserialize = (value) => parse(value, VALUE_FORMAT), serialize = (date) => format(date, VALUE_FORMAT);
|
|
2076
|
+
function DateInput(props) {
|
|
2077
|
+
const { id, onChange, type, value, readOnly, ...rest } = props, { dateFormat } = parseOptions(type.options), handleChange = useCallback(
|
|
2078
|
+
(nextDate) => {
|
|
2079
|
+
onChange(nextDate || null);
|
|
2080
|
+
},
|
|
2081
|
+
[onChange]
|
|
2082
|
+
), formatInputValue = useCallback((date) => format(date, dateFormat), [dateFormat]), parseInputValue = useCallback(
|
|
2083
|
+
(inputValue) => parse(inputValue, dateFormat),
|
|
2084
|
+
[dateFormat]
|
|
2085
|
+
);
|
|
2086
|
+
return /* @__PURE__ */ jsx(
|
|
2087
|
+
CommonDateTimeInput,
|
|
2088
|
+
{
|
|
2089
|
+
id,
|
|
2090
|
+
...rest,
|
|
2091
|
+
deserialize,
|
|
2092
|
+
formatInputValue,
|
|
2093
|
+
onChange: handleChange,
|
|
2094
|
+
parseInputValue,
|
|
2095
|
+
readOnly,
|
|
2096
|
+
selectTime: !1,
|
|
2097
|
+
serialize,
|
|
2098
|
+
value
|
|
2099
|
+
}
|
|
2100
|
+
);
|
|
2101
|
+
}
|
|
2102
|
+
function Monthly(props) {
|
|
2103
|
+
const { byweekday, setByweekday } = props, { weekday: dayNo, n: weekNo } = byweekday && Array.isArray(byweekday) ? byweekday[0] : { weekday: null, n: null }, handleChange = useCallback(
|
|
2104
|
+
(event) => {
|
|
2105
|
+
const { value, name } = event.currentTarget;
|
|
2106
|
+
if (name == "week")
|
|
2107
|
+
if (value == "")
|
|
2108
|
+
setByweekday(null);
|
|
2109
|
+
else {
|
|
2110
|
+
const newWeekday = new Weekday(dayNo || 0, Number(value));
|
|
2111
|
+
setByweekday([newWeekday]);
|
|
2112
|
+
}
|
|
2113
|
+
else if (name == "day") {
|
|
2114
|
+
const newWeekday = new Weekday(Number(value), weekNo || 1);
|
|
2115
|
+
setByweekday([newWeekday]);
|
|
2116
|
+
}
|
|
2117
|
+
},
|
|
2118
|
+
[dayNo, setByweekday, weekNo]
|
|
2119
|
+
);
|
|
2120
|
+
return useEffect(() => {
|
|
2121
|
+
weekNo || setByweekday(null);
|
|
2122
|
+
}), /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "center", children: [
|
|
2123
|
+
/* @__PURE__ */ jsx(Text, { style: { whiteSpace: "nowrap" }, children: "On the" }),
|
|
2124
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(Select, { name: "week", value: weekNo?.toString(), onChange: handleChange, children: [
|
|
2125
|
+
/* @__PURE__ */ jsx("option", { value: "", children: "same day" }),
|
|
2126
|
+
/* @__PURE__ */ jsx("option", { value: "1", children: "first" }),
|
|
2127
|
+
/* @__PURE__ */ jsx("option", { value: "2", children: "second" }),
|
|
2128
|
+
/* @__PURE__ */ jsx("option", { value: "3", children: "third" }),
|
|
2129
|
+
/* @__PURE__ */ jsx("option", { value: "4", children: "fourth" }),
|
|
2130
|
+
/* @__PURE__ */ jsx("option", { value: "5", children: "fifth" }),
|
|
2131
|
+
/* @__PURE__ */ jsx("option", { value: "-1", children: "last" })
|
|
2132
|
+
] }) }),
|
|
2133
|
+
weekNo && /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Select, { name: "day", value: dayNo || 0, onChange: handleChange, children: DAYS.map((day, i) => {
|
|
2134
|
+
const weekday = new Weekday(i);
|
|
2135
|
+
return /* @__PURE__ */ jsx("option", { value: weekday.weekday, children: day }, weekday.weekday);
|
|
2136
|
+
}) }) })
|
|
2137
|
+
] });
|
|
2138
|
+
}
|
|
2139
|
+
function Weekly(props) {
|
|
2140
|
+
const { byweekday, setByweekday } = props, currentWeekdays = useMemo(() => Array.isArray(byweekday) ? byweekday.map((weekday) => weekday.weekday) : [], [byweekday]), handleChange = useCallback(
|
|
2141
|
+
(event) => {
|
|
2142
|
+
const value = Number(event.currentTarget.value), index = currentWeekdays.indexOf(value);
|
|
2143
|
+
index === -1 ? currentWeekdays.push(value) : currentWeekdays.splice(index, 1), setByweekday(
|
|
2144
|
+
currentWeekdays.length ? currentWeekdays.map((currentWeekday) => new Weekday(Number(currentWeekday))) : null
|
|
2145
|
+
);
|
|
2146
|
+
},
|
|
2147
|
+
[currentWeekdays, setByweekday]
|
|
2148
|
+
);
|
|
2149
|
+
return /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
2150
|
+
/* @__PURE__ */ jsx(Text, { style: { whiteSpace: "nowrap" }, children: "Repeats on" }),
|
|
2151
|
+
/* @__PURE__ */ jsx(Grid, { columns: DAYS.length, gap: 1, children: DAYS.map((day, i) => {
|
|
2152
|
+
const weekday = new Weekday(i);
|
|
2153
|
+
return /* @__PURE__ */ jsx(
|
|
2154
|
+
Button,
|
|
2155
|
+
{
|
|
2156
|
+
mode: currentWeekdays && currentWeekdays.includes(i) ? "default" : "ghost",
|
|
2157
|
+
tone: currentWeekdays && currentWeekdays.includes(i) ? "primary" : "default",
|
|
2158
|
+
text: weekday.toString(),
|
|
2159
|
+
value: i,
|
|
2160
|
+
style: { cursor: "pointer" },
|
|
2161
|
+
onClick: handleChange
|
|
2162
|
+
},
|
|
2163
|
+
day
|
|
2164
|
+
);
|
|
2165
|
+
}) })
|
|
2166
|
+
] });
|
|
2167
|
+
}
|
|
2168
|
+
function CustomRule({
|
|
2169
|
+
open,
|
|
2170
|
+
onClose,
|
|
2171
|
+
onChange,
|
|
2172
|
+
initialValue,
|
|
2173
|
+
startDate,
|
|
2174
|
+
endDate,
|
|
2175
|
+
dateTimeOptions
|
|
2176
|
+
}) {
|
|
2177
|
+
const initialRule = useMemo(() => initialValue ? rrulestr(initialValue) : new RRule(), [initialValue]), [frequency, setFrequency] = useState(initialRule.origOptions.freq || 1), [interval, setInterval] = useState(
|
|
2178
|
+
initialRule.origOptions.interval && initialRule.origOptions.interval > 0 ? initialRule.origOptions.interval : 1
|
|
2179
|
+
), [count, setCount] = useState(initialRule.origOptions.count || null), [until, setUntil] = useState(
|
|
2180
|
+
initialRule.origOptions.until || null
|
|
2181
|
+
), [byweekday, setByweekday] = useState(
|
|
2182
|
+
initialRule.origOptions.byweekday || null
|
|
2183
|
+
), [untilValid, setUntilValid] = useState(!0), handleChange = useCallback(
|
|
2184
|
+
(event) => {
|
|
2185
|
+
const { name, value } = event.currentTarget;
|
|
2186
|
+
name === "freq" ? setFrequency(Number(value)) : name === "interval" ? setInterval(Number(value) > 1 ? Number(value) : 1) : name === "count" && setCount(Number(value));
|
|
2187
|
+
},
|
|
2188
|
+
[]
|
|
2189
|
+
), getUntilDate = useCallback(() => {
|
|
2190
|
+
const fromDate = new Date(startDate || Date.now());
|
|
2191
|
+
return frequency === RRule.YEARLY ? fromDate.setFullYear(fromDate.getFullYear() + DEFAULT_COUNTS[frequency]) : frequency === RRule.MONTHLY ? fromDate.setMonth(fromDate.getMonth() + DEFAULT_COUNTS[frequency]) : frequency === RRule.WEEKLY ? fromDate.setDate(fromDate.getDate() + DEFAULT_COUNTS[frequency] * 7) : frequency === RRule.DAILY && fromDate.setDate(fromDate.getDate() + DEFAULT_COUNTS[frequency]), fromDate.setHours(23, 59, 59, 999), fromDate;
|
|
2192
|
+
}, [frequency, startDate]), handleUntilChange = useCallback(
|
|
2193
|
+
(date) => {
|
|
2194
|
+
if (date) {
|
|
2195
|
+
const untilDate = toDate$1(`${date}T23:59:59`);
|
|
2196
|
+
endDate && untilDate < toDate$1(endDate) || startDate && untilDate < toDate$1(startDate) ? setUntilValid(!1) : setUntilValid(!0), setUntil(untilDate);
|
|
2197
|
+
}
|
|
2198
|
+
},
|
|
2199
|
+
[endDate, startDate]
|
|
2200
|
+
), handleEndChange = useCallback(
|
|
2201
|
+
(event) => {
|
|
2202
|
+
const { value } = event.currentTarget;
|
|
2203
|
+
if (!value)
|
|
2204
|
+
setUntil(null), setCount(null);
|
|
2205
|
+
else if (value == "count")
|
|
2206
|
+
setCount(DEFAULT_COUNTS[frequency]), setUntil(null);
|
|
2207
|
+
else if (value == "until") {
|
|
2208
|
+
const untilDate = getUntilDate();
|
|
2209
|
+
setUntil(untilDate), setCount(null);
|
|
2210
|
+
}
|
|
2211
|
+
},
|
|
2212
|
+
[frequency, getUntilDate]
|
|
2213
|
+
), handleConfirm = useCallback(() => {
|
|
2214
|
+
const newOptions = {
|
|
2215
|
+
freq: frequency,
|
|
2216
|
+
interval,
|
|
2217
|
+
count: count || null,
|
|
2218
|
+
until: until || null,
|
|
2219
|
+
byweekday: frequency === RRule.WEEKLY || frequency === RRule.MONTHLY ? byweekday : null
|
|
2220
|
+
}, newRule = new RRule(newOptions);
|
|
2221
|
+
onClose(), onChange(set(newRule.toString(), ["rrule"]));
|
|
2222
|
+
}, [byweekday, count, frequency, interval, onChange, onClose, until]), formatUntilValue = useCallback((date) => format$1(date, "yyyy-MM-dd"), []);
|
|
2223
|
+
return open ? /* @__PURE__ */ jsx(
|
|
2224
|
+
Dialog,
|
|
2225
|
+
{
|
|
2226
|
+
header: "Custom recurrence",
|
|
2227
|
+
id: "dialog-example",
|
|
2228
|
+
onClose,
|
|
2229
|
+
zOffset: 1e3,
|
|
2230
|
+
width: 1,
|
|
2231
|
+
children: /* @__PURE__ */ jsxs(Flex, { direction: "column", children: [
|
|
2232
|
+
/* @__PURE__ */ jsx(Box, { flex: 1, overflow: "auto", padding: 4, children: /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
|
|
2233
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, align: "center", children: [
|
|
2234
|
+
/* @__PURE__ */ jsx(Text, { style: { whiteSpace: "nowrap" }, children: "Repeat every" }),
|
|
2235
|
+
/* @__PURE__ */ jsx(Box, { style: { width: "75px" }, children: /* @__PURE__ */ jsx(
|
|
2236
|
+
TextInput,
|
|
2237
|
+
{
|
|
2238
|
+
name: "interval",
|
|
2239
|
+
type: "number",
|
|
2240
|
+
min: 1,
|
|
2241
|
+
value: interval,
|
|
2242
|
+
onChange: handleChange
|
|
2243
|
+
}
|
|
2244
|
+
) }),
|
|
2245
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(Select, { name: "freq", value: frequency, onChange: handleChange, children: [
|
|
2246
|
+
/* @__PURE__ */ jsx("option", { value: RRule.YEARLY, children: "year(s)" }),
|
|
2247
|
+
/* @__PURE__ */ jsx("option", { value: RRule.MONTHLY, children: "month(s)" }),
|
|
2248
|
+
/* @__PURE__ */ jsx("option", { value: RRule.WEEKLY, children: "week(s)" }),
|
|
2249
|
+
/* @__PURE__ */ jsx("option", { value: RRule.DAILY, children: "day(s)" })
|
|
2250
|
+
] }) })
|
|
2251
|
+
] }),
|
|
2252
|
+
frequency === RRule.MONTHLY && /* @__PURE__ */ jsx(Monthly, { byweekday, setByweekday }),
|
|
2253
|
+
frequency === RRule.WEEKLY && /* @__PURE__ */ jsx(Weekly, { byweekday, setByweekday }),
|
|
2254
|
+
/* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
2255
|
+
/* @__PURE__ */ jsx(Text, { children: "Ends" }),
|
|
2256
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, paddingY: 2, align: "center", children: [
|
|
2257
|
+
/* @__PURE__ */ jsx(
|
|
2258
|
+
Radio,
|
|
2259
|
+
{
|
|
2260
|
+
checked: !count && !until,
|
|
2261
|
+
name: "ends",
|
|
2262
|
+
onChange: handleEndChange,
|
|
2263
|
+
value: "",
|
|
2264
|
+
id: "ends-never"
|
|
2265
|
+
}
|
|
2266
|
+
),
|
|
2267
|
+
/* @__PURE__ */ jsx(Text, { htmlFor: "ends-never", as: "label", children: "Never" })
|
|
2268
|
+
] }),
|
|
2269
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, align: "center", children: [
|
|
2270
|
+
/* @__PURE__ */ jsx(
|
|
2271
|
+
Radio,
|
|
2272
|
+
{
|
|
2273
|
+
checked: !!until,
|
|
2274
|
+
name: "ends",
|
|
2275
|
+
onChange: handleEndChange,
|
|
2276
|
+
value: "until",
|
|
2277
|
+
id: "ends-until"
|
|
2278
|
+
}
|
|
2279
|
+
),
|
|
2280
|
+
/* @__PURE__ */ jsx(Text, { htmlFor: "ends-until", as: "label", style: { width: "75px" }, children: "On" }),
|
|
2281
|
+
/* @__PURE__ */ jsx(Box, { style: { width: "200px" }, children: /* @__PURE__ */ jsx(
|
|
2282
|
+
DateInput,
|
|
2283
|
+
{
|
|
2284
|
+
id: "until",
|
|
2285
|
+
onChange: handleUntilChange,
|
|
2286
|
+
type: {
|
|
2287
|
+
name: "until",
|
|
2288
|
+
title: "Date",
|
|
2289
|
+
options: dateTimeOptions
|
|
2290
|
+
},
|
|
2291
|
+
value: formatUntilValue(until ? new Date(until) : getUntilDate()),
|
|
2292
|
+
readOnly: !until
|
|
2293
|
+
}
|
|
2294
|
+
) }),
|
|
2295
|
+
!untilValid && /* @__PURE__ */ jsx(Feedback, { tone: "critical", children: /* @__PURE__ */ jsx(Text, { size: 1, children: "Until date must be after event ends" }) })
|
|
2296
|
+
] }),
|
|
2297
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, align: "center", children: [
|
|
2298
|
+
/* @__PURE__ */ jsx(
|
|
2299
|
+
Radio,
|
|
2300
|
+
{
|
|
2301
|
+
checked: !!count,
|
|
2302
|
+
name: "ends",
|
|
2303
|
+
onChange: handleEndChange,
|
|
2304
|
+
value: "count",
|
|
2305
|
+
id: "ends-count"
|
|
2306
|
+
}
|
|
2307
|
+
),
|
|
2308
|
+
/* @__PURE__ */ jsx(Text, { htmlFor: "ends-count", as: "label", style: { width: "75px" }, children: "After" }),
|
|
2309
|
+
/* @__PURE__ */ jsx(Box, { style: { width: "75px" }, children: /* @__PURE__ */ jsx(
|
|
2310
|
+
TextInput,
|
|
2311
|
+
{
|
|
2312
|
+
name: "count",
|
|
2313
|
+
type: "number",
|
|
2314
|
+
value: count || DEFAULT_COUNTS[frequency],
|
|
2315
|
+
onChange: handleChange,
|
|
2316
|
+
disabled: !count
|
|
2317
|
+
}
|
|
2318
|
+
) }),
|
|
2319
|
+
/* @__PURE__ */ jsx(Text, { style: { whiteSpace: "nowrap" }, children: "occurrence(s)" })
|
|
2320
|
+
] })
|
|
2321
|
+
] })
|
|
2322
|
+
] }) }),
|
|
2323
|
+
/* @__PURE__ */ jsx(Box, { paddingX: 4, paddingY: 3, style: { borderTop: "1px solid var(--card-border-color)" }, children: /* @__PURE__ */ jsxs(Flex, { gap: 2, justify: "flex-end", children: [
|
|
2324
|
+
/* @__PURE__ */ jsx(Button, { text: "Cancel", mode: "ghost", onClick: onClose }),
|
|
2325
|
+
/* @__PURE__ */ jsx(Button, { text: "Done", tone: "positive", onClick: handleConfirm, disabled: !untilValid })
|
|
2326
|
+
] }) })
|
|
2327
|
+
] })
|
|
2328
|
+
}
|
|
2329
|
+
) : /* @__PURE__ */ jsx(Fragment$1, {});
|
|
2330
|
+
}
|
|
2331
|
+
function RemoveEndDate({
|
|
2332
|
+
title,
|
|
2333
|
+
onChange
|
|
2334
|
+
}) {
|
|
2335
|
+
const handleUnsetClick = useCallback(() => {
|
|
2336
|
+
onChange(unset(["endDate"]));
|
|
2337
|
+
}, [onChange]);
|
|
2338
|
+
return /* @__PURE__ */ jsx(Card, { padding: 4, radius: 2, tone: "caution", "data-ui": "Alert", children: /* @__PURE__ */ jsxs(Flex, { children: [
|
|
2339
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, children: /* @__PURE__ */ jsx(WarningOutlineIcon, {}) }) }),
|
|
2340
|
+
/* @__PURE__ */ jsxs(Stack, { space: 3, flex: 1, marginLeft: 3, children: [
|
|
2341
|
+
/* @__PURE__ */ jsxs(Text, { size: 1, weight: "semibold", children: [
|
|
2342
|
+
"The ",
|
|
2343
|
+
title ? upperFirst(title) : "current",
|
|
2344
|
+
" field has an end date"
|
|
2345
|
+
] }),
|
|
2346
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { as: "p", muted: !0, size: 1, children: "This field has an end date value, but the end date is currently disabled for this field." }) }),
|
|
2347
|
+
/* @__PURE__ */ jsx(
|
|
2348
|
+
Button,
|
|
2349
|
+
{
|
|
2350
|
+
icon: TrashIcon,
|
|
2351
|
+
tone: "critical",
|
|
2352
|
+
text: /* @__PURE__ */ jsx(Fragment$1, { children: "Remove end date" }),
|
|
2353
|
+
onClick: handleUnsetClick,
|
|
2354
|
+
width: "fill"
|
|
2355
|
+
}
|
|
2356
|
+
)
|
|
2357
|
+
] })
|
|
2358
|
+
] }) });
|
|
2359
|
+
}
|
|
2360
|
+
function RecurringDates(props) {
|
|
2361
|
+
const { onChange, members, value: currentValue, schemaType, pluginConfig } = props, { options, title } = schemaType, { defaultRecurrences, hideEndDate, hideCustom, dateTimeOptions, dateOnly, validation } = {
|
|
2362
|
+
...pluginConfig,
|
|
2363
|
+
...options
|
|
2364
|
+
}, [open, setOpen] = useState(!1), onClose = useCallback(() => setOpen(!1), []), onOpen = useCallback(() => setOpen(!0), []), handleChange = useCallback(
|
|
2365
|
+
(event) => {
|
|
2366
|
+
const { value } = event.currentTarget;
|
|
2367
|
+
value == "custom" ? onOpen() : onChange(set(value, ["rrule"]));
|
|
2368
|
+
},
|
|
2369
|
+
[onChange, onOpen]
|
|
2370
|
+
), invalidRecurrences = validateRRuleStrings(defaultRecurrences), startDateMember = members.find(
|
|
2371
|
+
(member) => member.kind === "field" && member.name === "startDate"
|
|
2372
|
+
), endDateMember = members.find(
|
|
2373
|
+
(member) => member.kind === "field" && member.name === "endDate"
|
|
2374
|
+
), rruleMember = members.find((member) => member.kind === "field" && member.name === "rrule"), availableRecurrences = [...defaultRecurrences];
|
|
2375
|
+
currentValue && !availableRecurrences.includes(currentValue?.rrule) && availableRecurrences.push(currentValue?.rrule);
|
|
2376
|
+
const renderProps = {
|
|
2377
|
+
renderField: props.renderField,
|
|
2378
|
+
renderInput: props.renderInput,
|
|
2379
|
+
renderItem: props.renderItem,
|
|
2380
|
+
renderPreview: props.renderPreview
|
|
2381
|
+
};
|
|
2382
|
+
startDateMember?.kind == "field" && (startDateMember.field.schemaType.options = {
|
|
2383
|
+
...startDateMember?.field?.schemaType.options,
|
|
2384
|
+
...dateTimeOptions
|
|
2385
|
+
}, dateOnly === !0 ? startDateMember.field.schemaType.name = "date" : startDateMember.field.schemaType.name = "datetime", validation?.startDate ? startDateMember.field.schemaType.validation = (CustomValidation) => validation?.startDate?.(CustomValidation) : startDateMember.field.schemaType.validation = (DefaultRule) => DefaultRule.required(), options?.fieldTitles?.startDate && (startDateMember.field.schemaType.title = options.fieldTitles.startDate), options?.fieldDescriptions?.startDate && (startDateMember.field.schemaType.description = options.fieldDescriptions.startDate)), endDateMember?.kind == "field" && (endDateMember.field.schemaType.options = {
|
|
2386
|
+
...endDateMember?.field?.schemaType.options,
|
|
2387
|
+
...dateTimeOptions
|
|
2388
|
+
}, dateOnly === !0 ? endDateMember.field.schemaType.name = "date" : endDateMember.field.schemaType.name = "datetime", validation?.endDate ? endDateMember.field.schemaType.validation = (CustomValidation) => validation?.endDate?.(CustomValidation) : endDateMember.field.schemaType.validation = (DefaultRule) => DefaultRule.min(DefaultRule.valueOfField("startDate")), options?.fieldTitles?.endDate && (endDateMember.field.schemaType.title = options.fieldTitles.endDate), options?.fieldDescriptions?.endDate && (endDateMember.field.schemaType.description = options.fieldDescriptions.endDate));
|
|
2389
|
+
const hasEndDate = currentValue?.endDate;
|
|
2390
|
+
return /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
2391
|
+
/* @__PURE__ */ jsxs(Grid, { columns: hideEndDate ? 1 : 2, gap: 3, children: [
|
|
2392
|
+
hasEndDate && hideEndDate && /* @__PURE__ */ jsx(RemoveEndDate, { title, onChange }),
|
|
2393
|
+
/* @__PURE__ */ jsx(Flex, { align: "flex-end", gap: 2, children: /* @__PURE__ */ jsx(Box, { flex: 1, children: startDateMember && /* @__PURE__ */ jsx(ObjectInputMember, { member: startDateMember, ...renderProps }) }) }),
|
|
2394
|
+
!hideEndDate && /* @__PURE__ */ jsx(Flex, { align: "flex-end", gap: 2, children: /* @__PURE__ */ jsx(Box, { flex: 1, children: endDateMember && /* @__PURE__ */ jsx(ObjectInputMember, { member: endDateMember, ...renderProps }) }) })
|
|
2395
|
+
] }),
|
|
2396
|
+
invalidRecurrences ? /* @__PURE__ */ jsx(Feedback, { tone: "critical", children: /* @__PURE__ */ jsxs(Text, { size: 1, children: [
|
|
2397
|
+
/* @__PURE__ */ jsx("strong", { children: "Error:" }),
|
|
2398
|
+
" An invalid RRULE string was provided in the",
|
|
2399
|
+
" ",
|
|
2400
|
+
/* @__PURE__ */ jsx("code", { children: "defaultRecurrences" }),
|
|
2401
|
+
" array. Check plugin configuration."
|
|
2402
|
+
] }) }) : /* @__PURE__ */ jsxs(Select, { onChange: handleChange, value: currentValue?.rrule, children: [
|
|
2403
|
+
/* @__PURE__ */ jsx("option", { value: "", children: "Doesn't repeat" }),
|
|
2404
|
+
availableRecurrences.map((recurrence) => {
|
|
2405
|
+
if (!recurrence)
|
|
2406
|
+
return null;
|
|
2407
|
+
const rule = rrulestr(recurrence);
|
|
2408
|
+
return rule.options.until = rule?.options?.until && datetime(
|
|
2409
|
+
rule?.options?.until?.getFullYear(),
|
|
2410
|
+
rule?.options?.until?.getMonth() + 1,
|
|
2411
|
+
rule?.options?.until?.getDate(),
|
|
2412
|
+
rule?.options?.until?.getHours(),
|
|
2413
|
+
rule?.options?.until?.getMinutes(),
|
|
2414
|
+
rule?.options?.until?.getSeconds()
|
|
2415
|
+
), /* @__PURE__ */ jsx("option", { value: recurrence, children: upperFirst(rule.toText()) }, recurrence);
|
|
2416
|
+
}),
|
|
2417
|
+
!hideCustom && /* @__PURE__ */ jsx("option", { value: "custom", children: "Custom..." })
|
|
2418
|
+
] }),
|
|
2419
|
+
rruleMember && /* @__PURE__ */ jsx(ObjectInputMember, { member: rruleMember, ...renderProps }),
|
|
2420
|
+
/* @__PURE__ */ jsx(
|
|
2421
|
+
CustomRule,
|
|
2422
|
+
{
|
|
2423
|
+
open,
|
|
2424
|
+
onClose,
|
|
2425
|
+
onChange,
|
|
2426
|
+
initialValue: currentValue?.rrule,
|
|
2427
|
+
startDate: startDateMember?.kind == "field" ? startDateMember?.field?.value : void 0,
|
|
2428
|
+
endDate: endDateMember?.kind == "field" ? endDateMember?.field?.value : void 0,
|
|
2429
|
+
dateTimeOptions
|
|
2430
|
+
}
|
|
2431
|
+
)
|
|
2432
|
+
] });
|
|
2433
|
+
}
|
|
2434
|
+
function RecurringDatesPreview(props) {
|
|
2435
|
+
const { startDate, endDate, rrule, schemaType, pluginConfig } = props, options = schemaType?.options, { dateTimeOptions, dateOnly } = {
|
|
2436
|
+
...pluginConfig,
|
|
2437
|
+
...options
|
|
2438
|
+
}, rule = rrule && rrulestr(rrule);
|
|
2439
|
+
rule && (rule.options.until = rule?.options?.until && datetime(
|
|
2440
|
+
rule?.options?.until?.getFullYear(),
|
|
2441
|
+
rule?.options?.until?.getMonth() + 1,
|
|
2442
|
+
rule?.options?.until?.getDate(),
|
|
2443
|
+
rule?.options?.until?.getHours(),
|
|
2444
|
+
rule?.options?.until?.getMinutes(),
|
|
2445
|
+
rule?.options?.until?.getSeconds()
|
|
2446
|
+
));
|
|
2447
|
+
const dateFormat = dateTimeOptions?.dateFormat || DEFAULT_DATE_FORMAT$1, timeFormat = dateTimeOptions?.timeFormat || DEFAULT_TIME_FORMAT, start = startDate ? new Date(startDate) : void 0, end = endDate ? new Date(endDate) : void 0, sameDay = start && end && start.toDateString() === end.toDateString();
|
|
2448
|
+
let title = "No start date";
|
|
2449
|
+
dateOnly ? (title = start ? format(start, dateFormat) : "No start date", end && !sameDay && (title += ` - ${format(end, dateFormat)}`)) : (title = start ? format(start, `${dateFormat} ${timeFormat}`) : "No start date", end && (title += ` - ${format(end, sameDay ? timeFormat : `${dateFormat} ${timeFormat}`)}`));
|
|
2450
|
+
const previewProps = {
|
|
2451
|
+
title,
|
|
2452
|
+
subtitle: rule && upperFirst(rule.toText())
|
|
2453
|
+
};
|
|
2454
|
+
return props.renderDefault({ ...previewProps, ...props });
|
|
2455
|
+
}
|
|
2456
|
+
var recurringDateSchema = (config) => {
|
|
2457
|
+
const { dateTimeOptions, dateOnly, validation, fieldTitles, fieldDescriptions } = config;
|
|
2458
|
+
return defineField({
|
|
2459
|
+
name: "recurringDates",
|
|
2460
|
+
title: "Dates",
|
|
2461
|
+
type: "object",
|
|
2462
|
+
icon: CalendarIcon,
|
|
2463
|
+
fields: [
|
|
2464
|
+
defineField({
|
|
2465
|
+
title: fieldTitles?.startDate || "Start Date",
|
|
2466
|
+
description: fieldDescriptions?.startDate || "",
|
|
2467
|
+
name: "startDate",
|
|
2468
|
+
type: dateOnly ? "date" : "datetime",
|
|
2469
|
+
options: dateTimeOptions,
|
|
2470
|
+
validation: (Rule) => validation?.startDate ? validation.startDate(Rule) : Rule.required()
|
|
2471
|
+
}),
|
|
2472
|
+
defineField({
|
|
2473
|
+
title: fieldTitles?.endDate || "End Date",
|
|
2474
|
+
description: fieldDescriptions?.endDate || "",
|
|
2475
|
+
name: "endDate",
|
|
2476
|
+
type: dateOnly ? "date" : "datetime",
|
|
2477
|
+
options: dateTimeOptions,
|
|
2478
|
+
validation: (Rule) => validation?.endDate ? validation.endDate(Rule) : Rule.min(Rule.valueOfField("startDate"))
|
|
2479
|
+
}),
|
|
2480
|
+
defineField({
|
|
2481
|
+
title: "Recurring event",
|
|
2482
|
+
name: "recurs",
|
|
2483
|
+
type: "boolean"
|
|
2484
|
+
}),
|
|
2485
|
+
defineField({
|
|
2486
|
+
title: "RRULE",
|
|
2487
|
+
name: "rrule",
|
|
2488
|
+
type: "string",
|
|
2489
|
+
hidden: !0
|
|
2490
|
+
})
|
|
2491
|
+
],
|
|
2492
|
+
components: {
|
|
2493
|
+
input: (props) => RecurringDates({ ...props, pluginConfig: config }),
|
|
2494
|
+
preview: (props) => RecurringDatesPreview({ ...props, pluginConfig: config })
|
|
2495
|
+
},
|
|
2496
|
+
preview: {
|
|
2497
|
+
select: {
|
|
2498
|
+
startDate: "startDate",
|
|
2499
|
+
endDate: "endDate",
|
|
2500
|
+
rrule: "rrule"
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
});
|
|
2504
|
+
};
|
|
2505
|
+
const recurringDates = definePlugin((config) => {
|
|
2506
|
+
const pluginConfig = {
|
|
2507
|
+
...DEFAULT_CONFIG,
|
|
2508
|
+
...config
|
|
2509
|
+
};
|
|
2510
|
+
return {
|
|
2511
|
+
name: "sanity-plugin-recurring-dates",
|
|
2512
|
+
schema: {
|
|
2513
|
+
types: [recurringDateSchema(pluginConfig)]
|
|
2514
|
+
}
|
|
2515
|
+
};
|
|
2516
|
+
});
|
|
2517
|
+
export {
|
|
2518
|
+
recurringDates
|
|
2519
|
+
};
|
|
2520
|
+
//# sourceMappingURL=index.mjs.map
|