@brikka/locations 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.esm.js ADDED
@@ -0,0 +1,1974 @@
1
+ import { jsxs, Fragment, jsx } from '@soperio/jsx-runtime';
2
+ import { ButtonBarButton, ItemEditDialog } from '@compill/admin';
3
+ import { FormHelper } from '@compill/form';
4
+ import { mapsHelper } from '@compill/form-maps';
5
+ import { useModal, useCopyToClipboard } from '@compill/hooks';
6
+ import { mdiPlus, mdiMapMarker, mdiContentCopy } from '@mdi/js';
7
+ import { FlexCenter } from '@compill/components';
8
+ import { NextImageFill } from '@compill/next';
9
+ import { IconButton } from '@valerya/ui';
10
+ import { SidebarCard } from '@brikka/layout';
11
+
12
+ /******************************************************************************
13
+ Copyright (c) Microsoft Corporation.
14
+
15
+ Permission to use, copy, modify, and/or distribute this software for any
16
+ purpose with or without fee is hereby granted.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
21
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24
+ PERFORMANCE OF THIS SOFTWARE.
25
+ ***************************************************************************** */
26
+
27
+ function __rest(s, e) {
28
+ var t = {};
29
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
30
+ t[p] = s[p];
31
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
32
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
33
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
34
+ t[p[i]] = s[p[i]];
35
+ }
36
+ return t;
37
+ }
38
+
39
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
40
+ var e = new Error(message);
41
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
42
+ };
43
+
44
+ /**
45
+ * Based on Kendo UI Core expression code <https://github.com/telerik/kendo-ui-core#license-information>
46
+ */
47
+
48
+ function Cache(maxSize) {
49
+ this._maxSize = maxSize;
50
+ this.clear();
51
+ }
52
+ Cache.prototype.clear = function () {
53
+ this._size = 0;
54
+ this._values = Object.create(null);
55
+ };
56
+ Cache.prototype.get = function (key) {
57
+ return this._values[key]
58
+ };
59
+ Cache.prototype.set = function (key, value) {
60
+ this._size >= this._maxSize && this.clear();
61
+ if (!(key in this._values)) this._size++;
62
+
63
+ return (this._values[key] = value)
64
+ };
65
+
66
+ var SPLIT_REGEX = /[^.^\]^[]+|(?=\[\]|\.\.)/g,
67
+ DIGIT_REGEX = /^\d+$/,
68
+ LEAD_DIGIT_REGEX = /^\d/,
69
+ SPEC_CHAR_REGEX = /[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g,
70
+ CLEAN_QUOTES_REGEX = /^\s*(['"]?)(.*?)(\1)\s*$/,
71
+ MAX_CACHE_SIZE = 512;
72
+
73
+ var pathCache = new Cache(MAX_CACHE_SIZE),
74
+ setCache = new Cache(MAX_CACHE_SIZE),
75
+ getCache = new Cache(MAX_CACHE_SIZE);
76
+
77
+ var propertyExpr = {
78
+ Cache: Cache,
79
+
80
+ split: split,
81
+
82
+ normalizePath: normalizePath,
83
+
84
+ setter: function (path) {
85
+ var parts = normalizePath(path);
86
+
87
+ return (
88
+ setCache.get(path) ||
89
+ setCache.set(path, function setter(obj, value) {
90
+ var index = 0;
91
+ var len = parts.length;
92
+ var data = obj;
93
+
94
+ while (index < len - 1) {
95
+ var part = parts[index];
96
+ if (
97
+ part === '__proto__' ||
98
+ part === 'constructor' ||
99
+ part === 'prototype'
100
+ ) {
101
+ return obj
102
+ }
103
+
104
+ data = data[parts[index++]];
105
+ }
106
+ data[parts[index]] = value;
107
+ })
108
+ )
109
+ },
110
+
111
+ getter: function (path, safe) {
112
+ var parts = normalizePath(path);
113
+ return (
114
+ getCache.get(path) ||
115
+ getCache.set(path, function getter(data) {
116
+ var index = 0,
117
+ len = parts.length;
118
+ while (index < len) {
119
+ if (data != null || !safe) data = data[parts[index++]];
120
+ else return
121
+ }
122
+ return data
123
+ })
124
+ )
125
+ },
126
+
127
+ join: function (segments) {
128
+ return segments.reduce(function (path, part) {
129
+ return (
130
+ path +
131
+ (isQuoted(part) || DIGIT_REGEX.test(part)
132
+ ? '[' + part + ']'
133
+ : (path ? '.' : '') + part)
134
+ )
135
+ }, '')
136
+ },
137
+
138
+ forEach: function (path, cb, thisArg) {
139
+ forEach(Array.isArray(path) ? path : split(path), cb, thisArg);
140
+ },
141
+ };
142
+
143
+ function normalizePath(path) {
144
+ return (
145
+ pathCache.get(path) ||
146
+ pathCache.set(
147
+ path,
148
+ split(path).map(function (part) {
149
+ return part.replace(CLEAN_QUOTES_REGEX, '$2')
150
+ })
151
+ )
152
+ )
153
+ }
154
+
155
+ function split(path) {
156
+ return path.match(SPLIT_REGEX) || ['']
157
+ }
158
+
159
+ function forEach(parts, iter, thisArg) {
160
+ var len = parts.length,
161
+ part,
162
+ idx,
163
+ isArray,
164
+ isBracket;
165
+
166
+ for (idx = 0; idx < len; idx++) {
167
+ part = parts[idx];
168
+
169
+ if (part) {
170
+ if (shouldBeQuoted(part)) {
171
+ part = '"' + part + '"';
172
+ }
173
+
174
+ isBracket = isQuoted(part);
175
+ isArray = !isBracket && /^\d+$/.test(part);
176
+
177
+ iter.call(thisArg, part, isBracket, isArray, idx, parts);
178
+ }
179
+ }
180
+ }
181
+
182
+ function isQuoted(str) {
183
+ return (
184
+ typeof str === 'string' && str && ["'", '"'].indexOf(str.charAt(0)) !== -1
185
+ )
186
+ }
187
+
188
+ function hasLeadingNumber(part) {
189
+ return part.match(LEAD_DIGIT_REGEX) && !part.match(DIGIT_REGEX)
190
+ }
191
+
192
+ function hasSpecialChars(part) {
193
+ return SPEC_CHAR_REGEX.test(part)
194
+ }
195
+
196
+ function shouldBeQuoted(part) {
197
+ return !isQuoted(part) && (hasLeadingNumber(part) || hasSpecialChars(part))
198
+ }
199
+
200
+ const reWords = /[A-Z\xc0-\xd6\xd8-\xde]?[a-z\xdf-\xf6\xf8-\xff]+(?:['’](?:d|ll|m|re|s|t|ve))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde]|$)|(?:[A-Z\xc0-\xd6\xd8-\xde]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:D|LL|M|RE|S|T|VE))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde](?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])|$)|[A-Z\xc0-\xd6\xd8-\xde]?(?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:d|ll|m|re|s|t|ve))?|[A-Z\xc0-\xd6\xd8-\xde]+(?:['’](?:D|LL|M|RE|S|T|VE))?|\d*(?:1ST|2ND|3RD|(?![123])\dTH)(?=\b|[a-z_])|\d*(?:1st|2nd|3rd|(?![123])\dth)(?=\b|[A-Z_])|\d+|(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?)*/g;
201
+
202
+ const words = (str) => str.match(reWords) || [];
203
+
204
+ const upperFirst = (str) => str[0].toUpperCase() + str.slice(1);
205
+
206
+ const join = (str, d) => words(str).join(d).toLowerCase();
207
+
208
+ const camelCase = (str) =>
209
+ words(str).reduce(
210
+ (acc, next) =>
211
+ `${acc}${
212
+ !acc
213
+ ? next.toLowerCase()
214
+ : next[0].toUpperCase() + next.slice(1).toLowerCase()
215
+ }`,
216
+ '',
217
+ );
218
+
219
+ const pascalCase = (str) => upperFirst(camelCase(str));
220
+
221
+ const snakeCase = (str) => join(str, '_');
222
+
223
+ const kebabCase = (str) => join(str, '-');
224
+
225
+ const sentenceCase = (str) => upperFirst(join(str, ' '));
226
+
227
+ const titleCase = (str) => words(str).map(upperFirst).join(' ');
228
+
229
+ var tinyCase = {
230
+ words,
231
+ upperFirst,
232
+ camelCase,
233
+ pascalCase,
234
+ snakeCase,
235
+ kebabCase,
236
+ sentenceCase,
237
+ titleCase,
238
+ };
239
+
240
+ var toposort$2 = {exports: {}};
241
+
242
+ /**
243
+ * Topological sorting function
244
+ *
245
+ * @param {Array} edges
246
+ * @returns {Array}
247
+ */
248
+
249
+ toposort$2.exports = function(edges) {
250
+ return toposort(uniqueNodes(edges), edges)
251
+ };
252
+
253
+ toposort$2.exports.array = toposort;
254
+
255
+ function toposort(nodes, edges) {
256
+ var cursor = nodes.length
257
+ , sorted = new Array(cursor)
258
+ , visited = {}
259
+ , i = cursor
260
+ // Better data structures make algorithm much faster.
261
+ , outgoingEdges = makeOutgoingEdges(edges)
262
+ , nodesHash = makeNodesHash(nodes);
263
+
264
+ // check for unknown nodes
265
+ edges.forEach(function(edge) {
266
+ if (!nodesHash.has(edge[0]) || !nodesHash.has(edge[1])) {
267
+ throw new Error('Unknown node. There is an unknown node in the supplied edges.')
268
+ }
269
+ });
270
+
271
+ while (i--) {
272
+ if (!visited[i]) visit(nodes[i], i, new Set());
273
+ }
274
+
275
+ return sorted
276
+
277
+ function visit(node, i, predecessors) {
278
+ if(predecessors.has(node)) {
279
+ var nodeRep;
280
+ try {
281
+ nodeRep = ", node was:" + JSON.stringify(node);
282
+ } catch(e) {
283
+ nodeRep = "";
284
+ }
285
+ throw new Error('Cyclic dependency' + nodeRep)
286
+ }
287
+
288
+ if (!nodesHash.has(node)) {
289
+ throw new Error('Found unknown node. Make sure to provided all involved nodes. Unknown node: '+JSON.stringify(node))
290
+ }
291
+
292
+ if (visited[i]) return;
293
+ visited[i] = true;
294
+
295
+ var outgoing = outgoingEdges.get(node) || new Set();
296
+ outgoing = Array.from(outgoing);
297
+
298
+ if (i = outgoing.length) {
299
+ predecessors.add(node);
300
+ do {
301
+ var child = outgoing[--i];
302
+ visit(child, nodesHash.get(child), predecessors);
303
+ } while (i)
304
+ predecessors.delete(node);
305
+ }
306
+
307
+ sorted[--cursor] = node;
308
+ }
309
+ }
310
+
311
+ function uniqueNodes(arr){
312
+ var res = new Set();
313
+ for (var i = 0, len = arr.length; i < len; i++) {
314
+ var edge = arr[i];
315
+ res.add(edge[0]);
316
+ res.add(edge[1]);
317
+ }
318
+ return Array.from(res)
319
+ }
320
+
321
+ function makeOutgoingEdges(arr){
322
+ var edges = new Map();
323
+ for (var i = 0, len = arr.length; i < len; i++) {
324
+ var edge = arr[i];
325
+ if (!edges.has(edge[0])) edges.set(edge[0], new Set());
326
+ if (!edges.has(edge[1])) edges.set(edge[1], new Set());
327
+ edges.get(edge[0]).add(edge[1]);
328
+ }
329
+ return edges
330
+ }
331
+
332
+ function makeNodesHash(arr){
333
+ var res = new Map();
334
+ for (var i = 0, len = arr.length; i < len; i++) {
335
+ res.set(arr[i], i);
336
+ }
337
+ return res
338
+ }
339
+
340
+ var toposort$1 = toposort$2.exports;
341
+
342
+ const toString = Object.prototype.toString;
343
+ const errorToString = Error.prototype.toString;
344
+ const regExpToString = RegExp.prototype.toString;
345
+ const symbolToString = typeof Symbol !== 'undefined' ? Symbol.prototype.toString : () => '';
346
+ const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;
347
+ function printNumber(val) {
348
+ if (val != +val) return 'NaN';
349
+ const isNegativeZero = val === 0 && 1 / val < 0;
350
+ return isNegativeZero ? '-0' : '' + val;
351
+ }
352
+ function printSimpleValue(val, quoteStrings = false) {
353
+ if (val == null || val === true || val === false) return '' + val;
354
+ const typeOf = typeof val;
355
+ if (typeOf === 'number') return printNumber(val);
356
+ if (typeOf === 'string') return quoteStrings ? `"${val}"` : val;
357
+ if (typeOf === 'function') return '[Function ' + (val.name || 'anonymous') + ']';
358
+ if (typeOf === 'symbol') return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)');
359
+ const tag = toString.call(val).slice(8, -1);
360
+ if (tag === 'Date') return isNaN(val.getTime()) ? '' + val : val.toISOString(val);
361
+ if (tag === 'Error' || val instanceof Error) return '[' + errorToString.call(val) + ']';
362
+ if (tag === 'RegExp') return regExpToString.call(val);
363
+ return null;
364
+ }
365
+ function printValue(value, quoteStrings) {
366
+ let result = printSimpleValue(value, quoteStrings);
367
+ if (result !== null) return result;
368
+ return JSON.stringify(value, function (key, value) {
369
+ let result = printSimpleValue(this[key], quoteStrings);
370
+ if (result !== null) return result;
371
+ return value;
372
+ }, 2);
373
+ }
374
+
375
+ function toArray(value) {
376
+ return value == null ? [] : [].concat(value);
377
+ }
378
+
379
+ let strReg = /\$\{\s*(\w+)\s*\}/g;
380
+ class ValidationError extends Error {
381
+ static formatError(message, params) {
382
+ const path = params.label || params.path || 'this';
383
+ if (path !== params.path) params = Object.assign({}, params, {
384
+ path
385
+ });
386
+ if (typeof message === 'string') return message.replace(strReg, (_, key) => printValue(params[key]));
387
+ if (typeof message === 'function') return message(params);
388
+ return message;
389
+ }
390
+ static isError(err) {
391
+ return err && err.name === 'ValidationError';
392
+ }
393
+ constructor(errorOrErrors, value, field, type) {
394
+ super();
395
+ this.value = void 0;
396
+ this.path = void 0;
397
+ this.type = void 0;
398
+ this.errors = void 0;
399
+ this.params = void 0;
400
+ this.inner = void 0;
401
+ this.name = 'ValidationError';
402
+ this.value = value;
403
+ this.path = field;
404
+ this.type = type;
405
+ this.errors = [];
406
+ this.inner = [];
407
+ toArray(errorOrErrors).forEach(err => {
408
+ if (ValidationError.isError(err)) {
409
+ this.errors.push(...err.errors);
410
+ this.inner = this.inner.concat(err.inner.length ? err.inner : err);
411
+ } else {
412
+ this.errors.push(err);
413
+ }
414
+ });
415
+ this.message = this.errors.length > 1 ? `${this.errors.length} errors occurred` : this.errors[0];
416
+ if (Error.captureStackTrace) Error.captureStackTrace(this, ValidationError);
417
+ }
418
+ }
419
+
420
+ let mixed = {
421
+ default: '${path} is invalid',
422
+ required: '${path} is a required field',
423
+ defined: '${path} must be defined',
424
+ notNull: '${path} cannot be null',
425
+ oneOf: '${path} must be one of the following values: ${values}',
426
+ notOneOf: '${path} must not be one of the following values: ${values}',
427
+ notType: ({
428
+ path,
429
+ type,
430
+ value,
431
+ originalValue
432
+ }) => {
433
+ const castMsg = originalValue != null && originalValue !== value ? ` (cast from the value \`${printValue(originalValue, true)}\`).` : '.';
434
+ return type !== 'mixed' ? `${path} must be a \`${type}\` type, ` + `but the final value was: \`${printValue(value, true)}\`` + castMsg : `${path} must match the configured type. ` + `The validated value was: \`${printValue(value, true)}\`` + castMsg;
435
+ }
436
+ };
437
+ let string = {
438
+ length: '${path} must be exactly ${length} characters',
439
+ min: '${path} must be at least ${min} characters',
440
+ max: '${path} must be at most ${max} characters',
441
+ matches: '${path} must match the following: "${regex}"',
442
+ email: '${path} must be a valid email',
443
+ url: '${path} must be a valid URL',
444
+ uuid: '${path} must be a valid UUID',
445
+ trim: '${path} must be a trimmed string',
446
+ lowercase: '${path} must be a lowercase string',
447
+ uppercase: '${path} must be a upper case string'
448
+ };
449
+ let number = {
450
+ min: '${path} must be greater than or equal to ${min}',
451
+ max: '${path} must be less than or equal to ${max}',
452
+ lessThan: '${path} must be less than ${less}',
453
+ moreThan: '${path} must be greater than ${more}',
454
+ positive: '${path} must be a positive number',
455
+ negative: '${path} must be a negative number',
456
+ integer: '${path} must be an integer'
457
+ };
458
+ let date = {
459
+ min: '${path} field must be later than ${min}',
460
+ max: '${path} field must be at earlier than ${max}'
461
+ };
462
+ let boolean = {
463
+ isValue: '${path} field must be ${value}'
464
+ };
465
+ let object = {
466
+ noUnknown: '${path} field has unspecified keys: ${unknown}'
467
+ };
468
+ let array = {
469
+ min: '${path} field must have at least ${min} items',
470
+ max: '${path} field must have less than or equal to ${max} items',
471
+ length: '${path} must have ${length} items'
472
+ };
473
+ Object.assign(Object.create(null), {
474
+ mixed,
475
+ string,
476
+ number,
477
+ date,
478
+ object,
479
+ array,
480
+ boolean
481
+ });
482
+
483
+ const isSchema = obj => obj && obj.__isYupSchema__;
484
+
485
+ class Condition {
486
+ static fromOptions(refs, config) {
487
+ if (!config.then && !config.otherwise) throw new TypeError('either `then:` or `otherwise:` is required for `when()` conditions');
488
+ let {
489
+ is,
490
+ then,
491
+ otherwise
492
+ } = config;
493
+ let check = typeof is === 'function' ? is : (...values) => values.every(value => value === is);
494
+ return new Condition(refs, (values, schema) => {
495
+ var _branch;
496
+ let branch = check(...values) ? then : otherwise;
497
+ return (_branch = branch == null ? void 0 : branch(schema)) != null ? _branch : schema;
498
+ });
499
+ }
500
+ constructor(refs, builder) {
501
+ this.fn = void 0;
502
+ this.refs = refs;
503
+ this.refs = refs;
504
+ this.fn = builder;
505
+ }
506
+ resolve(base, options) {
507
+ let values = this.refs.map(ref =>
508
+ // TODO: ? operator here?
509
+ ref.getValue(options == null ? void 0 : options.value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context));
510
+ let schema = this.fn(values, base, options);
511
+ if (schema === undefined ||
512
+ // @ts-ignore this can be base
513
+ schema === base) {
514
+ return base;
515
+ }
516
+ if (!isSchema(schema)) throw new TypeError('conditions must return a schema object');
517
+ return schema.resolve(options);
518
+ }
519
+ }
520
+
521
+ const prefixes = {
522
+ context: '$',
523
+ value: '.'
524
+ };
525
+ class Reference {
526
+ constructor(key, options = {}) {
527
+ this.key = void 0;
528
+ this.isContext = void 0;
529
+ this.isValue = void 0;
530
+ this.isSibling = void 0;
531
+ this.path = void 0;
532
+ this.getter = void 0;
533
+ this.map = void 0;
534
+ if (typeof key !== 'string') throw new TypeError('ref must be a string, got: ' + key);
535
+ this.key = key.trim();
536
+ if (key === '') throw new TypeError('ref must be a non-empty string');
537
+ this.isContext = this.key[0] === prefixes.context;
538
+ this.isValue = this.key[0] === prefixes.value;
539
+ this.isSibling = !this.isContext && !this.isValue;
540
+ let prefix = this.isContext ? prefixes.context : this.isValue ? prefixes.value : '';
541
+ this.path = this.key.slice(prefix.length);
542
+ this.getter = this.path && propertyExpr.getter(this.path, true);
543
+ this.map = options.map;
544
+ }
545
+ getValue(value, parent, context) {
546
+ let result = this.isContext ? context : this.isValue ? value : parent;
547
+ if (this.getter) result = this.getter(result || {});
548
+ if (this.map) result = this.map(result);
549
+ return result;
550
+ }
551
+
552
+ /**
553
+ *
554
+ * @param {*} value
555
+ * @param {Object} options
556
+ * @param {Object=} options.context
557
+ * @param {Object=} options.parent
558
+ */
559
+ cast(value, options) {
560
+ return this.getValue(value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context);
561
+ }
562
+ resolve() {
563
+ return this;
564
+ }
565
+ describe() {
566
+ return {
567
+ type: 'ref',
568
+ key: this.key
569
+ };
570
+ }
571
+ toString() {
572
+ return `Ref(${this.key})`;
573
+ }
574
+ static isRef(value) {
575
+ return value && value.__isYupRef;
576
+ }
577
+ }
578
+
579
+ // @ts-ignore
580
+ Reference.prototype.__isYupRef = true;
581
+
582
+ const isAbsent = value => value == null;
583
+
584
+ function createValidation(config) {
585
+ function validate({
586
+ value,
587
+ path = '',
588
+ options,
589
+ originalValue,
590
+ schema
591
+ }, panic, next) {
592
+ const {
593
+ name,
594
+ test,
595
+ params,
596
+ message,
597
+ skipAbsent
598
+ } = config;
599
+ let {
600
+ parent,
601
+ context,
602
+ abortEarly = schema.spec.abortEarly
603
+ } = options;
604
+ function resolve(item) {
605
+ return Reference.isRef(item) ? item.getValue(value, parent, context) : item;
606
+ }
607
+ function createError(overrides = {}) {
608
+ const nextParams = Object.assign({
609
+ value,
610
+ originalValue,
611
+ label: schema.spec.label,
612
+ path: overrides.path || path,
613
+ spec: schema.spec
614
+ }, params, overrides.params);
615
+ for (const key of Object.keys(nextParams)) nextParams[key] = resolve(nextParams[key]);
616
+ const error = new ValidationError(ValidationError.formatError(overrides.message || message, nextParams), value, nextParams.path, overrides.type || name);
617
+ error.params = nextParams;
618
+ return error;
619
+ }
620
+ const invalid = abortEarly ? panic : next;
621
+ let ctx = {
622
+ path,
623
+ parent,
624
+ type: name,
625
+ from: options.from,
626
+ createError,
627
+ resolve,
628
+ options,
629
+ originalValue,
630
+ schema
631
+ };
632
+ const handleResult = validOrError => {
633
+ if (ValidationError.isError(validOrError)) invalid(validOrError);else if (!validOrError) invalid(createError());else next(null);
634
+ };
635
+ const handleError = err => {
636
+ if (ValidationError.isError(err)) invalid(err);else panic(err);
637
+ };
638
+ const shouldSkip = skipAbsent && isAbsent(value);
639
+ if (!options.sync) {
640
+ try {
641
+ Promise.resolve(!shouldSkip ? test.call(ctx, value, ctx) : true).then(handleResult, handleError);
642
+ } catch (err) {
643
+ handleError(err);
644
+ }
645
+ return;
646
+ }
647
+ let result;
648
+ try {
649
+ var _result;
650
+ result = !shouldSkip ? test.call(ctx, value, ctx) : true;
651
+ if (typeof ((_result = result) == null ? void 0 : _result.then) === 'function') {
652
+ throw new Error(`Validation test of type: "${ctx.type}" returned a Promise during a synchronous validate. ` + `This test will finish after the validate call has returned`);
653
+ }
654
+ } catch (err) {
655
+ handleError(err);
656
+ return;
657
+ }
658
+ handleResult(result);
659
+ }
660
+ validate.OPTIONS = config;
661
+ return validate;
662
+ }
663
+
664
+ function getIn(schema, path, value, context = value) {
665
+ let parent, lastPart, lastPartDebug;
666
+
667
+ // root path: ''
668
+ if (!path) return {
669
+ parent,
670
+ parentPath: path,
671
+ schema
672
+ };
673
+ propertyExpr.forEach(path, (_part, isBracket, isArray) => {
674
+ let part = isBracket ? _part.slice(1, _part.length - 1) : _part;
675
+ schema = schema.resolve({
676
+ context,
677
+ parent,
678
+ value
679
+ });
680
+ let isTuple = schema.type === 'tuple';
681
+ let idx = isArray ? parseInt(part, 10) : 0;
682
+ if (schema.innerType || isTuple) {
683
+ if (isTuple && !isArray) throw new Error(`Yup.reach cannot implicitly index into a tuple type. the path part "${lastPartDebug}" must contain an index to the tuple element, e.g. "${lastPartDebug}[0]"`);
684
+ if (value && idx >= value.length) {
685
+ throw new Error(`Yup.reach cannot resolve an array item at index: ${_part}, in the path: ${path}. ` + `because there is no value at that index. `);
686
+ }
687
+ parent = value;
688
+ value = value && value[idx];
689
+ schema = isTuple ? schema.spec.types[idx] : schema.innerType;
690
+ }
691
+
692
+ // sometimes the array index part of a path doesn't exist: "nested.arr.child"
693
+ // in these cases the current part is the next schema and should be processed
694
+ // in this iteration. For cases where the index signature is included this
695
+ // check will fail and we'll handle the `child` part on the next iteration like normal
696
+ if (!isArray) {
697
+ if (!schema.fields || !schema.fields[part]) throw new Error(`The schema does not contain the path: ${path}. ` + `(failed at: ${lastPartDebug} which is a type: "${schema.type}")`);
698
+ parent = value;
699
+ value = value && value[part];
700
+ schema = schema.fields[part];
701
+ }
702
+ lastPart = part;
703
+ lastPartDebug = isBracket ? '[' + _part + ']' : '.' + _part;
704
+ });
705
+ return {
706
+ schema,
707
+ parent,
708
+ parentPath: lastPart
709
+ };
710
+ }
711
+
712
+ class ReferenceSet extends Set {
713
+ describe() {
714
+ const description = [];
715
+ for (const item of this.values()) {
716
+ description.push(Reference.isRef(item) ? item.describe() : item);
717
+ }
718
+ return description;
719
+ }
720
+ resolveAll(resolve) {
721
+ let result = [];
722
+ for (const item of this.values()) {
723
+ result.push(resolve(item));
724
+ }
725
+ return result;
726
+ }
727
+ clone() {
728
+ return new ReferenceSet(this.values());
729
+ }
730
+ merge(newItems, removeItems) {
731
+ const next = this.clone();
732
+ newItems.forEach(value => next.add(value));
733
+ removeItems.forEach(value => next.delete(value));
734
+ return next;
735
+ }
736
+ }
737
+
738
+ // tweaked from https://github.com/Kelin2025/nanoclone/blob/0abeb7635bda9b68ef2277093f76dbe3bf3948e1/src/index.js
739
+ function clone(src, seen = new Map()) {
740
+ if (isSchema(src) || !src || typeof src !== 'object') return src;
741
+ if (seen.has(src)) return seen.get(src);
742
+ let copy;
743
+ if (src instanceof Date) {
744
+ // Date
745
+ copy = new Date(src.getTime());
746
+ seen.set(src, copy);
747
+ } else if (src instanceof RegExp) {
748
+ // RegExp
749
+ copy = new RegExp(src);
750
+ seen.set(src, copy);
751
+ } else if (Array.isArray(src)) {
752
+ // Array
753
+ copy = new Array(src.length);
754
+ seen.set(src, copy);
755
+ for (let i = 0; i < src.length; i++) copy[i] = clone(src[i], seen);
756
+ } else if (src instanceof Map) {
757
+ // Map
758
+ copy = new Map();
759
+ seen.set(src, copy);
760
+ for (const [k, v] of src.entries()) copy.set(k, clone(v, seen));
761
+ } else if (src instanceof Set) {
762
+ // Set
763
+ copy = new Set();
764
+ seen.set(src, copy);
765
+ for (const v of src) copy.add(clone(v, seen));
766
+ } else if (src instanceof Object) {
767
+ // Object
768
+ copy = {};
769
+ seen.set(src, copy);
770
+ for (const [k, v] of Object.entries(src)) copy[k] = clone(v, seen);
771
+ } else {
772
+ throw Error(`Unable to clone ${src}`);
773
+ }
774
+ return copy;
775
+ }
776
+
777
+ class Schema {
778
+ constructor(options) {
779
+ this.type = void 0;
780
+ this.deps = [];
781
+ this.tests = void 0;
782
+ this.transforms = void 0;
783
+ this.conditions = [];
784
+ this._mutate = void 0;
785
+ this.internalTests = {};
786
+ this._whitelist = new ReferenceSet();
787
+ this._blacklist = new ReferenceSet();
788
+ this.exclusiveTests = Object.create(null);
789
+ this._typeCheck = void 0;
790
+ this.spec = void 0;
791
+ this.tests = [];
792
+ this.transforms = [];
793
+ this.withMutation(() => {
794
+ this.typeError(mixed.notType);
795
+ });
796
+ this.type = options.type;
797
+ this._typeCheck = options.check;
798
+ this.spec = Object.assign({
799
+ strip: false,
800
+ strict: false,
801
+ abortEarly: true,
802
+ recursive: true,
803
+ nullable: false,
804
+ optional: true,
805
+ coerce: true
806
+ }, options == null ? void 0 : options.spec);
807
+ this.withMutation(s => {
808
+ s.nonNullable();
809
+ });
810
+ }
811
+
812
+ // TODO: remove
813
+ get _type() {
814
+ return this.type;
815
+ }
816
+ clone(spec) {
817
+ if (this._mutate) {
818
+ if (spec) Object.assign(this.spec, spec);
819
+ return this;
820
+ }
821
+
822
+ // if the nested value is a schema we can skip cloning, since
823
+ // they are already immutable
824
+ const next = Object.create(Object.getPrototypeOf(this));
825
+
826
+ // @ts-expect-error this is readonly
827
+ next.type = this.type;
828
+ next._typeCheck = this._typeCheck;
829
+ next._whitelist = this._whitelist.clone();
830
+ next._blacklist = this._blacklist.clone();
831
+ next.internalTests = Object.assign({}, this.internalTests);
832
+ next.exclusiveTests = Object.assign({}, this.exclusiveTests);
833
+
834
+ // @ts-expect-error this is readonly
835
+ next.deps = [...this.deps];
836
+ next.conditions = [...this.conditions];
837
+ next.tests = [...this.tests];
838
+ next.transforms = [...this.transforms];
839
+ next.spec = clone(Object.assign({}, this.spec, spec));
840
+ return next;
841
+ }
842
+ label(label) {
843
+ let next = this.clone();
844
+ next.spec.label = label;
845
+ return next;
846
+ }
847
+ meta(...args) {
848
+ if (args.length === 0) return this.spec.meta;
849
+ let next = this.clone();
850
+ next.spec.meta = Object.assign(next.spec.meta || {}, args[0]);
851
+ return next;
852
+ }
853
+ withMutation(fn) {
854
+ let before = this._mutate;
855
+ this._mutate = true;
856
+ let result = fn(this);
857
+ this._mutate = before;
858
+ return result;
859
+ }
860
+ concat(schema) {
861
+ if (!schema || schema === this) return this;
862
+ if (schema.type !== this.type && this.type !== 'mixed') throw new TypeError(`You cannot \`concat()\` schema's of different types: ${this.type} and ${schema.type}`);
863
+ let base = this;
864
+ let combined = schema.clone();
865
+ const mergedSpec = Object.assign({}, base.spec, combined.spec);
866
+ combined.spec = mergedSpec;
867
+ combined.internalTests = Object.assign({}, base.internalTests, combined.internalTests);
868
+
869
+ // manually merge the blacklist/whitelist (the other `schema` takes
870
+ // precedence in case of conflicts)
871
+ combined._whitelist = base._whitelist.merge(schema._whitelist, schema._blacklist);
872
+ combined._blacklist = base._blacklist.merge(schema._blacklist, schema._whitelist);
873
+
874
+ // start with the current tests
875
+ combined.tests = base.tests;
876
+ combined.exclusiveTests = base.exclusiveTests;
877
+
878
+ // manually add the new tests to ensure
879
+ // the deduping logic is consistent
880
+ combined.withMutation(next => {
881
+ schema.tests.forEach(fn => {
882
+ next.test(fn.OPTIONS);
883
+ });
884
+ });
885
+ combined.transforms = [...base.transforms, ...combined.transforms];
886
+ return combined;
887
+ }
888
+ isType(v) {
889
+ if (v == null) {
890
+ if (this.spec.nullable && v === null) return true;
891
+ if (this.spec.optional && v === undefined) return true;
892
+ return false;
893
+ }
894
+ return this._typeCheck(v);
895
+ }
896
+ resolve(options) {
897
+ let schema = this;
898
+ if (schema.conditions.length) {
899
+ let conditions = schema.conditions;
900
+ schema = schema.clone();
901
+ schema.conditions = [];
902
+ schema = conditions.reduce((prevSchema, condition) => condition.resolve(prevSchema, options), schema);
903
+ schema = schema.resolve(options);
904
+ }
905
+ return schema;
906
+ }
907
+ resolveOptions(options) {
908
+ var _options$strict, _options$abortEarly, _options$recursive;
909
+ return Object.assign({}, options, {
910
+ from: options.from || [],
911
+ strict: (_options$strict = options.strict) != null ? _options$strict : this.spec.strict,
912
+ abortEarly: (_options$abortEarly = options.abortEarly) != null ? _options$abortEarly : this.spec.abortEarly,
913
+ recursive: (_options$recursive = options.recursive) != null ? _options$recursive : this.spec.recursive
914
+ });
915
+ }
916
+
917
+ /**
918
+ * Run the configured transform pipeline over an input value.
919
+ */
920
+
921
+ cast(value, options = {}) {
922
+ let resolvedSchema = this.resolve(Object.assign({
923
+ value
924
+ }, options));
925
+ let allowOptionality = options.assert === 'ignore-optionality';
926
+ let result = resolvedSchema._cast(value, options);
927
+ if (options.assert !== false && !resolvedSchema.isType(result)) {
928
+ if (allowOptionality && isAbsent(result)) {
929
+ return result;
930
+ }
931
+ let formattedValue = printValue(value);
932
+ let formattedResult = printValue(result);
933
+ throw new TypeError(`The value of ${options.path || 'field'} could not be cast to a value ` + `that satisfies the schema type: "${resolvedSchema.type}". \n\n` + `attempted value: ${formattedValue} \n` + (formattedResult !== formattedValue ? `result of cast: ${formattedResult}` : ''));
934
+ }
935
+ return result;
936
+ }
937
+ _cast(rawValue, options) {
938
+ let value = rawValue === undefined ? rawValue : this.transforms.reduce((prevValue, fn) => fn.call(this, prevValue, rawValue, this), rawValue);
939
+ if (value === undefined) {
940
+ value = this.getDefault(options);
941
+ }
942
+ return value;
943
+ }
944
+ _validate(_value, options = {}, panic, next) {
945
+ let {
946
+ path,
947
+ originalValue = _value,
948
+ strict = this.spec.strict
949
+ } = options;
950
+ let value = _value;
951
+ if (!strict) {
952
+ value = this._cast(value, Object.assign({
953
+ assert: false
954
+ }, options));
955
+ }
956
+ let initialTests = [];
957
+ for (let test of Object.values(this.internalTests)) {
958
+ if (test) initialTests.push(test);
959
+ }
960
+ this.runTests({
961
+ path,
962
+ value,
963
+ originalValue,
964
+ options,
965
+ tests: initialTests
966
+ }, panic, initialErrors => {
967
+ // even if we aren't ending early we can't proceed further if the types aren't correct
968
+ if (initialErrors.length) {
969
+ return next(initialErrors, value);
970
+ }
971
+ this.runTests({
972
+ path,
973
+ value,
974
+ originalValue,
975
+ options,
976
+ tests: this.tests
977
+ }, panic, next);
978
+ });
979
+ }
980
+
981
+ /**
982
+ * Executes a set of validations, either schema, produced Tests or a nested
983
+ * schema validate result.
984
+ */
985
+ runTests(runOptions, panic, next) {
986
+ let fired = false;
987
+ let {
988
+ tests,
989
+ value,
990
+ originalValue,
991
+ path,
992
+ options
993
+ } = runOptions;
994
+ let panicOnce = arg => {
995
+ if (fired) return;
996
+ fired = true;
997
+ panic(arg, value);
998
+ };
999
+ let nextOnce = arg => {
1000
+ if (fired) return;
1001
+ fired = true;
1002
+ next(arg, value);
1003
+ };
1004
+ let count = tests.length;
1005
+ let nestedErrors = [];
1006
+ if (!count) return nextOnce([]);
1007
+ let args = {
1008
+ value,
1009
+ originalValue,
1010
+ path,
1011
+ options,
1012
+ schema: this
1013
+ };
1014
+ for (let i = 0; i < tests.length; i++) {
1015
+ const test = tests[i];
1016
+ test(args, panicOnce, function finishTestRun(err) {
1017
+ if (err) {
1018
+ nestedErrors = nestedErrors.concat(err);
1019
+ }
1020
+ if (--count <= 0) {
1021
+ nextOnce(nestedErrors);
1022
+ }
1023
+ });
1024
+ }
1025
+ }
1026
+ asNestedTest({
1027
+ key,
1028
+ index,
1029
+ parent,
1030
+ parentPath,
1031
+ originalParent,
1032
+ options
1033
+ }) {
1034
+ const k = key != null ? key : index;
1035
+ if (k == null) {
1036
+ throw TypeError('Must include `key` or `index` for nested validations');
1037
+ }
1038
+ const isIndex = typeof k === 'number';
1039
+ let value = parent[k];
1040
+ const testOptions = Object.assign({}, options, {
1041
+ // Nested validations fields are always strict:
1042
+ // 1. parent isn't strict so the casting will also have cast inner values
1043
+ // 2. parent is strict in which case the nested values weren't cast either
1044
+ strict: true,
1045
+ parent,
1046
+ value,
1047
+ originalValue: originalParent[k],
1048
+ // FIXME: tests depend on `index` being passed around deeply,
1049
+ // we should not let the options.key/index bleed through
1050
+ key: undefined,
1051
+ // index: undefined,
1052
+ [isIndex ? 'index' : 'key']: k,
1053
+ path: isIndex || k.includes('.') ? `${parentPath || ''}[${value ? k : `"${k}"`}]` : (parentPath ? `${parentPath}.` : '') + key
1054
+ });
1055
+ return (_, panic, next) => this.resolve(testOptions)._validate(value, testOptions, panic, next);
1056
+ }
1057
+ validate(value, options) {
1058
+ let schema = this.resolve(Object.assign({}, options, {
1059
+ value
1060
+ }));
1061
+ return new Promise((resolve, reject) => schema._validate(value, options, (error, parsed) => {
1062
+ if (ValidationError.isError(error)) error.value = parsed;
1063
+ reject(error);
1064
+ }, (errors, validated) => {
1065
+ if (errors.length) reject(new ValidationError(errors, validated));else resolve(validated);
1066
+ }));
1067
+ }
1068
+ validateSync(value, options) {
1069
+ let schema = this.resolve(Object.assign({}, options, {
1070
+ value
1071
+ }));
1072
+ let result;
1073
+ schema._validate(value, Object.assign({}, options, {
1074
+ sync: true
1075
+ }), (error, parsed) => {
1076
+ if (ValidationError.isError(error)) error.value = parsed;
1077
+ throw error;
1078
+ }, (errors, validated) => {
1079
+ if (errors.length) throw new ValidationError(errors, value);
1080
+ result = validated;
1081
+ });
1082
+ return result;
1083
+ }
1084
+ isValid(value, options) {
1085
+ return this.validate(value, options).then(() => true, err => {
1086
+ if (ValidationError.isError(err)) return false;
1087
+ throw err;
1088
+ });
1089
+ }
1090
+ isValidSync(value, options) {
1091
+ try {
1092
+ this.validateSync(value, options);
1093
+ return true;
1094
+ } catch (err) {
1095
+ if (ValidationError.isError(err)) return false;
1096
+ throw err;
1097
+ }
1098
+ }
1099
+ _getDefault(options) {
1100
+ let defaultValue = this.spec.default;
1101
+ if (defaultValue == null) {
1102
+ return defaultValue;
1103
+ }
1104
+ return typeof defaultValue === 'function' ? defaultValue.call(this, options) : clone(defaultValue);
1105
+ }
1106
+ getDefault(options
1107
+ // If schema is defaulted we know it's at least not undefined
1108
+ ) {
1109
+ let schema = this.resolve(options || {});
1110
+ return schema._getDefault(options);
1111
+ }
1112
+ default(def) {
1113
+ if (arguments.length === 0) {
1114
+ return this._getDefault();
1115
+ }
1116
+ let next = this.clone({
1117
+ default: def
1118
+ });
1119
+ return next;
1120
+ }
1121
+ strict(isStrict = true) {
1122
+ return this.clone({
1123
+ strict: isStrict
1124
+ });
1125
+ }
1126
+ nullability(nullable, message) {
1127
+ const next = this.clone({
1128
+ nullable
1129
+ });
1130
+ next.internalTests.nullable = createValidation({
1131
+ message,
1132
+ name: 'nullable',
1133
+ test(value) {
1134
+ return value === null ? this.schema.spec.nullable : true;
1135
+ }
1136
+ });
1137
+ return next;
1138
+ }
1139
+ optionality(optional, message) {
1140
+ const next = this.clone({
1141
+ optional
1142
+ });
1143
+ next.internalTests.optionality = createValidation({
1144
+ message,
1145
+ name: 'optionality',
1146
+ test(value) {
1147
+ return value === undefined ? this.schema.spec.optional : true;
1148
+ }
1149
+ });
1150
+ return next;
1151
+ }
1152
+ optional() {
1153
+ return this.optionality(true);
1154
+ }
1155
+ defined(message = mixed.defined) {
1156
+ return this.optionality(false, message);
1157
+ }
1158
+ nullable() {
1159
+ return this.nullability(true);
1160
+ }
1161
+ nonNullable(message = mixed.notNull) {
1162
+ return this.nullability(false, message);
1163
+ }
1164
+ required(message = mixed.required) {
1165
+ return this.clone().withMutation(next => next.nonNullable(message).defined(message));
1166
+ }
1167
+ notRequired() {
1168
+ return this.clone().withMutation(next => next.nullable().optional());
1169
+ }
1170
+ transform(fn) {
1171
+ let next = this.clone();
1172
+ next.transforms.push(fn);
1173
+ return next;
1174
+ }
1175
+
1176
+ /**
1177
+ * Adds a test function to the schema's queue of tests.
1178
+ * tests can be exclusive or non-exclusive.
1179
+ *
1180
+ * - exclusive tests, will replace any existing tests of the same name.
1181
+ * - non-exclusive: can be stacked
1182
+ *
1183
+ * If a non-exclusive test is added to a schema with an exclusive test of the same name
1184
+ * the exclusive test is removed and further tests of the same name will be stacked.
1185
+ *
1186
+ * If an exclusive test is added to a schema with non-exclusive tests of the same name
1187
+ * the previous tests are removed and further tests of the same name will replace each other.
1188
+ */
1189
+
1190
+ test(...args) {
1191
+ let opts;
1192
+ if (args.length === 1) {
1193
+ if (typeof args[0] === 'function') {
1194
+ opts = {
1195
+ test: args[0]
1196
+ };
1197
+ } else {
1198
+ opts = args[0];
1199
+ }
1200
+ } else if (args.length === 2) {
1201
+ opts = {
1202
+ name: args[0],
1203
+ test: args[1]
1204
+ };
1205
+ } else {
1206
+ opts = {
1207
+ name: args[0],
1208
+ message: args[1],
1209
+ test: args[2]
1210
+ };
1211
+ }
1212
+ if (opts.message === undefined) opts.message = mixed.default;
1213
+ if (typeof opts.test !== 'function') throw new TypeError('`test` is a required parameters');
1214
+ let next = this.clone();
1215
+ let validate = createValidation(opts);
1216
+ let isExclusive = opts.exclusive || opts.name && next.exclusiveTests[opts.name] === true;
1217
+ if (opts.exclusive) {
1218
+ if (!opts.name) throw new TypeError('Exclusive tests must provide a unique `name` identifying the test');
1219
+ }
1220
+ if (opts.name) next.exclusiveTests[opts.name] = !!opts.exclusive;
1221
+ next.tests = next.tests.filter(fn => {
1222
+ if (fn.OPTIONS.name === opts.name) {
1223
+ if (isExclusive) return false;
1224
+ if (fn.OPTIONS.test === validate.OPTIONS.test) return false;
1225
+ }
1226
+ return true;
1227
+ });
1228
+ next.tests.push(validate);
1229
+ return next;
1230
+ }
1231
+ when(keys, options) {
1232
+ if (!Array.isArray(keys) && typeof keys !== 'string') {
1233
+ options = keys;
1234
+ keys = '.';
1235
+ }
1236
+ let next = this.clone();
1237
+ let deps = toArray(keys).map(key => new Reference(key));
1238
+ deps.forEach(dep => {
1239
+ // @ts-ignore readonly array
1240
+ if (dep.isSibling) next.deps.push(dep.key);
1241
+ });
1242
+ next.conditions.push(typeof options === 'function' ? new Condition(deps, options) : Condition.fromOptions(deps, options));
1243
+ return next;
1244
+ }
1245
+ typeError(message) {
1246
+ let next = this.clone();
1247
+ next.internalTests.typeError = createValidation({
1248
+ message,
1249
+ name: 'typeError',
1250
+ skipAbsent: true,
1251
+ test(value) {
1252
+ if (!this.schema._typeCheck(value)) return this.createError({
1253
+ params: {
1254
+ type: this.schema.type
1255
+ }
1256
+ });
1257
+ return true;
1258
+ }
1259
+ });
1260
+ return next;
1261
+ }
1262
+ oneOf(enums, message = mixed.oneOf) {
1263
+ let next = this.clone();
1264
+ enums.forEach(val => {
1265
+ next._whitelist.add(val);
1266
+ next._blacklist.delete(val);
1267
+ });
1268
+ next.internalTests.whiteList = createValidation({
1269
+ message,
1270
+ name: 'oneOf',
1271
+ skipAbsent: true,
1272
+ test(value) {
1273
+ let valids = this.schema._whitelist;
1274
+ let resolved = valids.resolveAll(this.resolve);
1275
+ return resolved.includes(value) ? true : this.createError({
1276
+ params: {
1277
+ values: Array.from(valids).join(', '),
1278
+ resolved
1279
+ }
1280
+ });
1281
+ }
1282
+ });
1283
+ return next;
1284
+ }
1285
+ notOneOf(enums, message = mixed.notOneOf) {
1286
+ let next = this.clone();
1287
+ enums.forEach(val => {
1288
+ next._blacklist.add(val);
1289
+ next._whitelist.delete(val);
1290
+ });
1291
+ next.internalTests.blacklist = createValidation({
1292
+ message,
1293
+ name: 'notOneOf',
1294
+ test(value) {
1295
+ let invalids = this.schema._blacklist;
1296
+ let resolved = invalids.resolveAll(this.resolve);
1297
+ if (resolved.includes(value)) return this.createError({
1298
+ params: {
1299
+ values: Array.from(invalids).join(', '),
1300
+ resolved
1301
+ }
1302
+ });
1303
+ return true;
1304
+ }
1305
+ });
1306
+ return next;
1307
+ }
1308
+ strip(strip = true) {
1309
+ let next = this.clone();
1310
+ next.spec.strip = strip;
1311
+ return next;
1312
+ }
1313
+
1314
+ /**
1315
+ * Return a serialized description of the schema including validations, flags, types etc.
1316
+ *
1317
+ * @param options Provide any needed context for resolving runtime schema alterations (lazy, when conditions, etc).
1318
+ */
1319
+ describe(options) {
1320
+ const next = (options ? this.resolve(options) : this).clone();
1321
+ const {
1322
+ label,
1323
+ meta,
1324
+ optional,
1325
+ nullable
1326
+ } = next.spec;
1327
+ const description = {
1328
+ meta,
1329
+ label,
1330
+ optional,
1331
+ nullable,
1332
+ default: next.getDefault(options),
1333
+ type: next.type,
1334
+ oneOf: next._whitelist.describe(),
1335
+ notOneOf: next._blacklist.describe(),
1336
+ tests: next.tests.map(fn => ({
1337
+ name: fn.OPTIONS.name,
1338
+ params: fn.OPTIONS.params
1339
+ })).filter((n, idx, list) => list.findIndex(c => c.name === n.name) === idx)
1340
+ };
1341
+ return description;
1342
+ }
1343
+ }
1344
+ // @ts-expect-error
1345
+ Schema.prototype.__isYupSchema__ = true;
1346
+ for (const method of ['validate', 'validateSync']) Schema.prototype[`${method}At`] = function (path, value, options = {}) {
1347
+ const {
1348
+ parent,
1349
+ parentPath,
1350
+ schema
1351
+ } = getIn(this, path, value, options.context);
1352
+ return schema[method](parent && parent[parentPath], Object.assign({}, options, {
1353
+ parent,
1354
+ path
1355
+ }));
1356
+ };
1357
+ for (const alias of ['equals', 'is']) Schema.prototype[alias] = Schema.prototype.oneOf;
1358
+ for (const alias of ['not', 'nope']) Schema.prototype[alias] = Schema.prototype.notOneOf;
1359
+
1360
+ //
1361
+ // Number Interfaces
1362
+ //
1363
+
1364
+ /* eslint-disable */
1365
+ /**
1366
+ *
1367
+ * Date.parse with progressive enhancement for ISO 8601 <https://github.com/csnover/js-iso8601>
1368
+ * NON-CONFORMANT EDITION.
1369
+ * © 2011 Colin Snover <http://zetafleet.com>
1370
+ * Released under MIT license.
1371
+ */
1372
+
1373
+ // 1 YYYY 2 MM 3 DD 4 HH 5 mm 6 ss 7 msec 8 Z 9 ± 10 tzHH 11 tzmm
1374
+ var isoReg = /^(\d{4}|[+\-]\d{6})(?:-?(\d{2})(?:-?(\d{2}))?)?(?:[ T]?(\d{2}):?(\d{2})(?::?(\d{2})(?:[,\.](\d{1,}))?)?(?:(Z)|([+\-])(\d{2})(?::?(\d{2}))?)?)?$/;
1375
+ function parseIsoDate(date) {
1376
+ var numericKeys = [1, 4, 5, 6, 7, 10, 11],
1377
+ minutesOffset = 0,
1378
+ timestamp,
1379
+ struct;
1380
+ if (struct = isoReg.exec(date)) {
1381
+ // avoid NaN timestamps caused by “undefined” values being passed to Date.UTC
1382
+ for (var i = 0, k; k = numericKeys[i]; ++i) struct[k] = +struct[k] || 0;
1383
+
1384
+ // allow undefined days and months
1385
+ struct[2] = (+struct[2] || 1) - 1;
1386
+ struct[3] = +struct[3] || 1;
1387
+
1388
+ // allow arbitrary sub-second precision beyond milliseconds
1389
+ struct[7] = struct[7] ? String(struct[7]).substr(0, 3) : 0;
1390
+
1391
+ // timestamps without timezone identifiers should be considered local time
1392
+ if ((struct[8] === undefined || struct[8] === '') && (struct[9] === undefined || struct[9] === '')) timestamp = +new Date(struct[1], struct[2], struct[3], struct[4], struct[5], struct[6], struct[7]);else {
1393
+ if (struct[8] !== 'Z' && struct[9] !== undefined) {
1394
+ minutesOffset = struct[10] * 60 + struct[11];
1395
+ if (struct[9] === '+') minutesOffset = 0 - minutesOffset;
1396
+ }
1397
+ timestamp = Date.UTC(struct[1], struct[2], struct[3], struct[4], struct[5] + minutesOffset, struct[6], struct[7]);
1398
+ }
1399
+ } else timestamp = Date.parse ? Date.parse(date) : NaN;
1400
+ return timestamp;
1401
+ }
1402
+
1403
+ // @ts-ignore
1404
+ let invalidDate = new Date('');
1405
+ let isDate = obj => Object.prototype.toString.call(obj) === '[object Date]';
1406
+ class DateSchema extends Schema {
1407
+ constructor() {
1408
+ super({
1409
+ type: 'date',
1410
+ check(v) {
1411
+ return isDate(v) && !isNaN(v.getTime());
1412
+ }
1413
+ });
1414
+ this.withMutation(() => {
1415
+ this.transform((value, _raw, ctx) => {
1416
+ // null -> InvalidDate isn't useful; treat all nulls as null and let it fail on
1417
+ // nullability check vs TypeErrors
1418
+ if (!ctx.spec.coerce || ctx.isType(value) || value === null) return value;
1419
+ value = parseIsoDate(value);
1420
+
1421
+ // 0 is a valid timestamp equivalent to 1970-01-01T00:00:00Z(unix epoch) or before.
1422
+ return !isNaN(value) ? new Date(value) : DateSchema.INVALID_DATE;
1423
+ });
1424
+ });
1425
+ }
1426
+ prepareParam(ref, name) {
1427
+ let param;
1428
+ if (!Reference.isRef(ref)) {
1429
+ let cast = this.cast(ref);
1430
+ if (!this._typeCheck(cast)) throw new TypeError(`\`${name}\` must be a Date or a value that can be \`cast()\` to a Date`);
1431
+ param = cast;
1432
+ } else {
1433
+ param = ref;
1434
+ }
1435
+ return param;
1436
+ }
1437
+ min(min, message = date.min) {
1438
+ let limit = this.prepareParam(min, 'min');
1439
+ return this.test({
1440
+ message,
1441
+ name: 'min',
1442
+ exclusive: true,
1443
+ params: {
1444
+ min
1445
+ },
1446
+ skipAbsent: true,
1447
+ test(value) {
1448
+ return value >= this.resolve(limit);
1449
+ }
1450
+ });
1451
+ }
1452
+ max(max, message = date.max) {
1453
+ let limit = this.prepareParam(max, 'max');
1454
+ return this.test({
1455
+ message,
1456
+ name: 'max',
1457
+ exclusive: true,
1458
+ params: {
1459
+ max
1460
+ },
1461
+ skipAbsent: true,
1462
+ test(value) {
1463
+ return value <= this.resolve(limit);
1464
+ }
1465
+ });
1466
+ }
1467
+ }
1468
+ DateSchema.INVALID_DATE = invalidDate;
1469
+ DateSchema.prototype;
1470
+
1471
+ // @ts-expect-error
1472
+ function sortFields(fields, excludedEdges = []) {
1473
+ let edges = [];
1474
+ let nodes = new Set();
1475
+ let excludes = new Set(excludedEdges.map(([a, b]) => `${a}-${b}`));
1476
+ function addNode(depPath, key) {
1477
+ let node = propertyExpr.split(depPath)[0];
1478
+ nodes.add(node);
1479
+ if (!excludes.has(`${key}-${node}`)) edges.push([key, node]);
1480
+ }
1481
+ for (const key of Object.keys(fields)) {
1482
+ let value = fields[key];
1483
+ nodes.add(key);
1484
+ if (Reference.isRef(value) && value.isSibling) addNode(value.path, key);else if (isSchema(value) && 'deps' in value) value.deps.forEach(path => addNode(path, key));
1485
+ }
1486
+ return toposort$1.array(Array.from(nodes), edges).reverse();
1487
+ }
1488
+
1489
+ function findIndex(arr, err) {
1490
+ let idx = Infinity;
1491
+ arr.some((key, ii) => {
1492
+ var _err$path;
1493
+ if ((_err$path = err.path) != null && _err$path.includes(key)) {
1494
+ idx = ii;
1495
+ return true;
1496
+ }
1497
+ });
1498
+ return idx;
1499
+ }
1500
+ function sortByKeyOrder(keys) {
1501
+ return (a, b) => {
1502
+ return findIndex(keys, a) - findIndex(keys, b);
1503
+ };
1504
+ }
1505
+
1506
+ const parseJson = (value, _, ctx) => {
1507
+ if (typeof value !== 'string') {
1508
+ return value;
1509
+ }
1510
+ let parsed = value;
1511
+ try {
1512
+ parsed = JSON.parse(value);
1513
+ } catch (err) {
1514
+ /* */
1515
+ }
1516
+ return ctx.isType(parsed) ? parsed : value;
1517
+ };
1518
+
1519
+ // @ts-ignore
1520
+ function deepPartial(schema) {
1521
+ if ('fields' in schema) {
1522
+ const partial = {};
1523
+ for (const [key, fieldSchema] of Object.entries(schema.fields)) {
1524
+ partial[key] = deepPartial(fieldSchema);
1525
+ }
1526
+ return schema.setFields(partial);
1527
+ }
1528
+ if (schema.type === 'array') {
1529
+ const nextArray = schema.optional();
1530
+ if (nextArray.innerType) nextArray.innerType = deepPartial(nextArray.innerType);
1531
+ return nextArray;
1532
+ }
1533
+ if (schema.type === 'tuple') {
1534
+ return schema.optional().clone({
1535
+ types: schema.spec.types.map(deepPartial)
1536
+ });
1537
+ }
1538
+ if ('optional' in schema) {
1539
+ return schema.optional();
1540
+ }
1541
+ return schema;
1542
+ }
1543
+ const deepHas = (obj, p) => {
1544
+ const path = [...propertyExpr.normalizePath(p)];
1545
+ if (path.length === 1) return path[0] in obj;
1546
+ let last = path.pop();
1547
+ let parent = propertyExpr.getter(propertyExpr.join(path), true)(obj);
1548
+ return !!(parent && last in parent);
1549
+ };
1550
+ let isObject = obj => Object.prototype.toString.call(obj) === '[object Object]';
1551
+ function unknown(ctx, value) {
1552
+ let known = Object.keys(ctx.fields);
1553
+ return Object.keys(value).filter(key => known.indexOf(key) === -1);
1554
+ }
1555
+ const defaultSort = sortByKeyOrder([]);
1556
+ function create$3(spec) {
1557
+ return new ObjectSchema(spec);
1558
+ }
1559
+ class ObjectSchema extends Schema {
1560
+ constructor(spec) {
1561
+ super({
1562
+ type: 'object',
1563
+ check(value) {
1564
+ return isObject(value) || typeof value === 'function';
1565
+ }
1566
+ });
1567
+ this.fields = Object.create(null);
1568
+ this._sortErrors = defaultSort;
1569
+ this._nodes = [];
1570
+ this._excludedEdges = [];
1571
+ this.withMutation(() => {
1572
+ if (spec) {
1573
+ this.shape(spec);
1574
+ }
1575
+ });
1576
+ }
1577
+ _cast(_value, options = {}) {
1578
+ var _options$stripUnknown;
1579
+ let value = super._cast(_value, options);
1580
+
1581
+ //should ignore nulls here
1582
+ if (value === undefined) return this.getDefault(options);
1583
+ if (!this._typeCheck(value)) return value;
1584
+ let fields = this.fields;
1585
+ let strip = (_options$stripUnknown = options.stripUnknown) != null ? _options$stripUnknown : this.spec.noUnknown;
1586
+ let props = [].concat(this._nodes, Object.keys(value).filter(v => !this._nodes.includes(v)));
1587
+ let intermediateValue = {}; // is filled during the transform below
1588
+ let innerOptions = Object.assign({}, options, {
1589
+ parent: intermediateValue,
1590
+ __validating: options.__validating || false
1591
+ });
1592
+ let isChanged = false;
1593
+ for (const prop of props) {
1594
+ let field = fields[prop];
1595
+ let exists = (prop in value);
1596
+ if (field) {
1597
+ let fieldValue;
1598
+ let inputValue = value[prop];
1599
+
1600
+ // safe to mutate since this is fired in sequence
1601
+ innerOptions.path = (options.path ? `${options.path}.` : '') + prop;
1602
+ field = field.resolve({
1603
+ value: inputValue,
1604
+ context: options.context,
1605
+ parent: intermediateValue
1606
+ });
1607
+ let fieldSpec = field instanceof Schema ? field.spec : undefined;
1608
+ let strict = fieldSpec == null ? void 0 : fieldSpec.strict;
1609
+ if (fieldSpec != null && fieldSpec.strip) {
1610
+ isChanged = isChanged || prop in value;
1611
+ continue;
1612
+ }
1613
+ fieldValue = !options.__validating || !strict ?
1614
+ // TODO: use _cast, this is double resolving
1615
+ field.cast(value[prop], innerOptions) : value[prop];
1616
+ if (fieldValue !== undefined) {
1617
+ intermediateValue[prop] = fieldValue;
1618
+ }
1619
+ } else if (exists && !strip) {
1620
+ intermediateValue[prop] = value[prop];
1621
+ }
1622
+ if (exists !== prop in intermediateValue || intermediateValue[prop] !== value[prop]) {
1623
+ isChanged = true;
1624
+ }
1625
+ }
1626
+ return isChanged ? intermediateValue : value;
1627
+ }
1628
+ _validate(_value, options = {}, panic, next) {
1629
+ let {
1630
+ from = [],
1631
+ originalValue = _value,
1632
+ recursive = this.spec.recursive
1633
+ } = options;
1634
+ options.from = [{
1635
+ schema: this,
1636
+ value: originalValue
1637
+ }, ...from];
1638
+ // this flag is needed for handling `strict` correctly in the context of
1639
+ // validation vs just casting. e.g strict() on a field is only used when validating
1640
+ options.__validating = true;
1641
+ options.originalValue = originalValue;
1642
+ super._validate(_value, options, panic, (objectErrors, value) => {
1643
+ if (!recursive || !isObject(value)) {
1644
+ next(objectErrors, value);
1645
+ return;
1646
+ }
1647
+ originalValue = originalValue || value;
1648
+ let tests = [];
1649
+ for (let key of this._nodes) {
1650
+ let field = this.fields[key];
1651
+ if (!field || Reference.isRef(field)) {
1652
+ continue;
1653
+ }
1654
+ tests.push(field.asNestedTest({
1655
+ options,
1656
+ key,
1657
+ parent: value,
1658
+ parentPath: options.path,
1659
+ originalParent: originalValue
1660
+ }));
1661
+ }
1662
+ this.runTests({
1663
+ tests,
1664
+ value,
1665
+ originalValue,
1666
+ options
1667
+ }, panic, fieldErrors => {
1668
+ next(fieldErrors.sort(this._sortErrors).concat(objectErrors), value);
1669
+ });
1670
+ });
1671
+ }
1672
+ clone(spec) {
1673
+ const next = super.clone(spec);
1674
+ next.fields = Object.assign({}, this.fields);
1675
+ next._nodes = this._nodes;
1676
+ next._excludedEdges = this._excludedEdges;
1677
+ next._sortErrors = this._sortErrors;
1678
+ return next;
1679
+ }
1680
+ concat(schema) {
1681
+ let next = super.concat(schema);
1682
+ let nextFields = next.fields;
1683
+ for (let [field, schemaOrRef] of Object.entries(this.fields)) {
1684
+ const target = nextFields[field];
1685
+ nextFields[field] = target === undefined ? schemaOrRef : target;
1686
+ }
1687
+ return next.withMutation(s =>
1688
+ // XXX: excludes here is wrong
1689
+ s.setFields(nextFields, [...this._excludedEdges, ...schema._excludedEdges]));
1690
+ }
1691
+ _getDefault(options) {
1692
+ if ('default' in this.spec) {
1693
+ return super._getDefault(options);
1694
+ }
1695
+
1696
+ // if there is no default set invent one
1697
+ if (!this._nodes.length) {
1698
+ return undefined;
1699
+ }
1700
+ let dft = {};
1701
+ this._nodes.forEach(key => {
1702
+ var _innerOptions;
1703
+ const field = this.fields[key];
1704
+ let innerOptions = options;
1705
+ if ((_innerOptions = innerOptions) != null && _innerOptions.value) {
1706
+ innerOptions = Object.assign({}, innerOptions, {
1707
+ parent: innerOptions.value,
1708
+ value: innerOptions.value[key]
1709
+ });
1710
+ }
1711
+ dft[key] = field && 'getDefault' in field ? field.getDefault(innerOptions) : undefined;
1712
+ });
1713
+ return dft;
1714
+ }
1715
+ setFields(shape, excludedEdges) {
1716
+ let next = this.clone();
1717
+ next.fields = shape;
1718
+ next._nodes = sortFields(shape, excludedEdges);
1719
+ next._sortErrors = sortByKeyOrder(Object.keys(shape));
1720
+ // XXX: this carries over edges which may not be what you want
1721
+ if (excludedEdges) next._excludedEdges = excludedEdges;
1722
+ return next;
1723
+ }
1724
+ shape(additions, excludes = []) {
1725
+ return this.clone().withMutation(next => {
1726
+ let edges = next._excludedEdges;
1727
+ if (excludes.length) {
1728
+ if (!Array.isArray(excludes[0])) excludes = [excludes];
1729
+ edges = [...next._excludedEdges, ...excludes];
1730
+ }
1731
+
1732
+ // XXX: excludes here is wrong
1733
+ return next.setFields(Object.assign(next.fields, additions), edges);
1734
+ });
1735
+ }
1736
+ partial() {
1737
+ const partial = {};
1738
+ for (const [key, schema] of Object.entries(this.fields)) {
1739
+ partial[key] = 'optional' in schema && schema.optional instanceof Function ? schema.optional() : schema;
1740
+ }
1741
+ return this.setFields(partial);
1742
+ }
1743
+ deepPartial() {
1744
+ const next = deepPartial(this);
1745
+ return next;
1746
+ }
1747
+ pick(keys) {
1748
+ const picked = {};
1749
+ for (const key of keys) {
1750
+ if (this.fields[key]) picked[key] = this.fields[key];
1751
+ }
1752
+ return this.setFields(picked);
1753
+ }
1754
+ omit(keys) {
1755
+ const fields = Object.assign({}, this.fields);
1756
+ for (const key of keys) {
1757
+ delete fields[key];
1758
+ }
1759
+ return this.setFields(fields);
1760
+ }
1761
+ from(from, to, alias) {
1762
+ let fromGetter = propertyExpr.getter(from, true);
1763
+ return this.transform(obj => {
1764
+ if (!obj) return obj;
1765
+ let newObj = obj;
1766
+ if (deepHas(obj, from)) {
1767
+ newObj = Object.assign({}, obj);
1768
+ if (!alias) delete newObj[from];
1769
+ newObj[to] = fromGetter(obj);
1770
+ }
1771
+ return newObj;
1772
+ });
1773
+ }
1774
+
1775
+ /** Parse an input JSON string to an object */
1776
+ json() {
1777
+ return this.transform(parseJson);
1778
+ }
1779
+ noUnknown(noAllow = true, message = object.noUnknown) {
1780
+ if (typeof noAllow !== 'boolean') {
1781
+ message = noAllow;
1782
+ noAllow = true;
1783
+ }
1784
+ let next = this.test({
1785
+ name: 'noUnknown',
1786
+ exclusive: true,
1787
+ message: message,
1788
+ test(value) {
1789
+ if (value == null) return true;
1790
+ const unknownKeys = unknown(this.schema, value);
1791
+ return !noAllow || unknownKeys.length === 0 || this.createError({
1792
+ params: {
1793
+ unknown: unknownKeys.join(', ')
1794
+ }
1795
+ });
1796
+ }
1797
+ });
1798
+ next.spec.noUnknown = noAllow;
1799
+ return next;
1800
+ }
1801
+ unknown(allow = true, message = object.noUnknown) {
1802
+ return this.noUnknown(!allow, message);
1803
+ }
1804
+ transformKeys(fn) {
1805
+ return this.transform(obj => {
1806
+ if (!obj) return obj;
1807
+ const result = {};
1808
+ for (const key of Object.keys(obj)) result[fn(key)] = obj[key];
1809
+ return result;
1810
+ });
1811
+ }
1812
+ camelCase() {
1813
+ return this.transformKeys(tinyCase.camelCase);
1814
+ }
1815
+ snakeCase() {
1816
+ return this.transformKeys(tinyCase.snakeCase);
1817
+ }
1818
+ constantCase() {
1819
+ return this.transformKeys(key => tinyCase.snakeCase(key).toUpperCase());
1820
+ }
1821
+ describe(options) {
1822
+ let base = super.describe(options);
1823
+ base.fields = {};
1824
+ for (const [key, value] of Object.entries(this.fields)) {
1825
+ var _innerOptions2;
1826
+ let innerOptions = options;
1827
+ if ((_innerOptions2 = innerOptions) != null && _innerOptions2.value) {
1828
+ innerOptions = Object.assign({}, innerOptions, {
1829
+ parent: innerOptions.value,
1830
+ value: innerOptions.value[key]
1831
+ });
1832
+ }
1833
+ base.fields[key] = value.describe(innerOptions);
1834
+ }
1835
+ return base;
1836
+ }
1837
+ }
1838
+ create$3.prototype = ObjectSchema.prototype;
1839
+
1840
+ const editForm = (lat, lng, mapZoom, locationTypeLabel) => FormHelper.array(mapsHelper("location", `Search a ${locationTypeLabel}}`, lat, lng, mapZoom), FormHelper.condition("location", location => location != null && Object.keys(location).length > 0, FormHelper.array(FormHelper.divider(), FormHelper.input("map.addressName", "Name"), FormHelper.input("map.addressStreet", "Address"))));
1841
+ const editInitialValues = () => ({
1842
+ type: "google",
1843
+ location: {}
1844
+ });
1845
+ const editSchema = create$3().shape({
1846
+ // name: Yup.string().required("Please set a name for your organisation"),
1847
+ // type: Yup.string().required("Please select a type"),
1848
+ });
1849
+ function NewLocationButton(_a) {
1850
+ var {
1851
+ api,
1852
+ lat,
1853
+ lng,
1854
+ mapZoom,
1855
+ locationTypeLabel = "location"
1856
+ } = _a,
1857
+ props = __rest(_a, ["api", "lat", "lng", "mapZoom", "locationTypeLabel"]);
1858
+ const {
1859
+ isOpen,
1860
+ onOpen,
1861
+ modalProps
1862
+ } = useModal();
1863
+ return jsxs(Fragment, {
1864
+ children: [jsx(ButtonBarButton, Object.assign({
1865
+ size: "md",
1866
+ icon: mdiPlus,
1867
+ onClick: onOpen
1868
+ }, props, {
1869
+ children: "New Venue"
1870
+ })), isOpen && jsx(ItemEditDialog, Object.assign({
1871
+ api: api,
1872
+ form: editForm(lat, lng, mapZoom, locationTypeLabel),
1873
+ initialValues: editInitialValues,
1874
+ formToQueryData: values => ({
1875
+ type: "google",
1876
+ ext_id: values.map.googleMapsPlaceId,
1877
+ lat: values.map.lat,
1878
+ lng: values.map.lng,
1879
+ name: values.map.addressName,
1880
+ address: values.map.addressStreet,
1881
+ mapZoom
1882
+ }),
1883
+ itemLabel: locationTypeLabel,
1884
+ formikProps: {
1885
+ validationSchema: editSchema
1886
+ }
1887
+ }, modalProps))]
1888
+ });
1889
+ }
1890
+
1891
+ function SidebarMapsCard({
1892
+ title,
1893
+ location
1894
+ }) {
1895
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1896
+ const copy = useCopyToClipboard((_b = (_a = location === null || location === void 0 ? void 0 : location.address) !== null && _a !== void 0 ? _a : location === null || location === void 0 ? void 0 : location.name) !== null && _b !== void 0 ? _b : "", "Address copied!");
1897
+ const googleMapsLink = `https://www.google.com/maps/search/?api=1&query=${location === null || location === void 0 ? void 0 : location.lat},${location === null || location === void 0 ? void 0 : location.lng}`;
1898
+ if (!location) return null;
1899
+ if (!location.name && !location.address && location.media) return null;
1900
+ return jsx(SidebarCard, {
1901
+ icon: mdiMapMarker,
1902
+ title: title || "Location",
1903
+ children: jsxs("div", {
1904
+ bgColor: "white",
1905
+ p: "5",
1906
+ children: [(location.name || location.address) && jsxs(Fragment, {
1907
+ children: [jsxs("div", {
1908
+ ps: "2",
1909
+ dflex: true,
1910
+ alignItems: "center",
1911
+ children: [jsx("span", {
1912
+ flexGrow: true,
1913
+ children: location.name ? location.name : location.address
1914
+ }), jsx("span", {
1915
+ children: jsx(IconButton, {
1916
+ variant: "borderless",
1917
+ scheme: "secondary",
1918
+ size: "lg",
1919
+ rounded: "full",
1920
+ icon: mdiContentCopy,
1921
+ onClick: copy
1922
+ })
1923
+ })]
1924
+ }), location.name && location.address && jsx("div", {
1925
+ ps: "2",
1926
+ textColor: "slate-600",
1927
+ textSize: "sm",
1928
+ children: location.address
1929
+ })]
1930
+ }), location.media && jsxs("div", {
1931
+ aspectRatio: "16/10",
1932
+ group: true,
1933
+ position: "relative",
1934
+ children: [jsx(NextImageFill, {
1935
+ showLoadingStates: true,
1936
+ src: (_d = (_c = location.media) === null || _c === void 0 ? void 0 : _c.url) !== null && _d !== void 0 ? _d : "",
1937
+ alt: "Google Maps",
1938
+ size: '33vw',
1939
+ sm_size: '33vw',
1940
+ md_size: '33vw',
1941
+ lg_size: '448px',
1942
+ xl_size: '448px',
1943
+ x2_size: '448px',
1944
+ width: (_f = (_e = location.media) === null || _e === void 0 ? void 0 : _e.width) !== null && _f !== void 0 ? _f : 0,
1945
+ height: (_h = (_g = location.media) === null || _g === void 0 ? void 0 : _g.height) !== null && _h !== void 0 ? _h : 0
1946
+ }), jsx("a", {
1947
+ href: googleMapsLink,
1948
+ target: "_blank",
1949
+ rel: "nofollow",
1950
+ children: jsx(FlexCenter, {
1951
+ opacity: "0",
1952
+ groupHover_opacity: "100",
1953
+ position: "absolute",
1954
+ top: "0",
1955
+ start: "0",
1956
+ w: "full",
1957
+ h: "full",
1958
+ bgColor: "black",
1959
+ bgOpacity: "50",
1960
+ textColor: "white",
1961
+ fontWeight: "500",
1962
+ textSize: "lg",
1963
+ transition: "all",
1964
+ easing: "in-out",
1965
+ duration: "500",
1966
+ children: "Open in Google Maps"
1967
+ })
1968
+ })]
1969
+ })]
1970
+ })
1971
+ });
1972
+ }
1973
+
1974
+ export { NewLocationButton, SidebarMapsCard };