UNPKG

react-schema-form-wizard

Version:

A customizable React JSON Schema Form library with shadcn/ui components and multi-step support

1,771 lines (1,599 loc) 1.18 MB
import { jsx, jsxs, Fragment } from 'react/jsx-runtime'; import * as React from 'react'; import { createElement, Component, PureComponent, useState, useEffect, useCallback, useMemo, useReducer, createRef } from 'react'; /** Determines whether a `thing` is an object for the purposes of RJSF. In this case, `thing` is an object if it has * the type `object` but is NOT null, an array or a File. * * @param thing - The thing to check to see whether it is an object * @returns - True if it is a non-null, non-array, non-File object */ function isObject$c(thing) { if (typeof thing !== 'object' || thing === null) { return false; } // lastModified is guaranteed to be a number on a File instance // as per https://w3c.github.io/FileAPI/#dfn-lastModified if (typeof thing.lastModified === 'number' && typeof File !== 'undefined' && thing instanceof File) { return false; } // getMonth is guaranteed to be a method on a Date instance // as per https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getmonth if (typeof thing.getMonth === 'function' && typeof Date !== 'undefined' && thing instanceof Date) { return false; } return !Array.isArray(thing); } /** Checks the schema to see if it is allowing additional items, by verifying that `schema.additionalItems` is an * object. The user is warned in the console if `schema.additionalItems` has the value `true`. * * @param schema - The schema object to check * @returns - True if additional items is allowed, otherwise false */ function allowAdditionalItems(schema) { if (schema.additionalItems === true) { console.warn('additionalItems=true is currently not supported'); } return isObject$c(schema.additionalItems); } /** Attempts to convert the string into a number. If an empty string is provided, then `undefined` is returned. If a * `null` is provided, it is returned. If the string ends in a `.` then the string is returned because the user may be * in the middle of typing a float number. If a number ends in a pattern like `.0`, `.20`, `.030`, string is returned * because the user may be typing number that will end in a non-zero digit. Otherwise, the string is wrapped by * `Number()` and if that result is not `NaN`, that number will be returned, otherwise the string `value` will be. * * @param value - The string or null value to convert to a number * @returns - The `value` converted to a number when appropriate, otherwise the `value` */ function asNumber(value) { if (value === '') { return undefined; } if (value === null) { return null; } if (/\.$/.test(value)) { // '3.' can't really be considered a number even if it parses in js. The // user is most likely entering a float. return value; } if (/\.0$/.test(value)) { // we need to return this as a string here, to allow for input like 3.07 return value; } if (/\.\d*0$/.test(value)) { // It's a number, that's cool - but we need it as a string so it doesn't screw // with the user when entering dollar amounts or other values (such as those with // specific precision or number of significant digits) return value; } const n = Number(value); const valid = typeof n === 'number' && !Number.isNaN(n); return valid ? n : value; } /** Below are the list of all the keys into various elements of a RJSFSchema or UiSchema that are used by the various * utility functions. In addition to those keys, there are the special `ADDITIONAL_PROPERTY_FLAG` and * `RJSF_ADDITIONAL_PROPERTIES_FLAG` flags that is added to a schema under certain conditions by the `retrieveSchema()` * utility. */ const ADDITIONAL_PROPERTY_FLAG = '__additional_property'; const ADDITIONAL_PROPERTIES_KEY = 'additionalProperties'; const ALL_OF_KEY = 'allOf'; const ANY_OF_KEY = 'anyOf'; const CONST_KEY = 'const'; const DEFAULT_KEY = 'default'; const DEPENDENCIES_KEY = 'dependencies'; const ENUM_KEY = 'enum'; const ERRORS_KEY = '__errors'; const ID_KEY = '$id'; const IF_KEY = 'if'; const ITEMS_KEY = 'items'; const JUNK_OPTION_ID = '_$junk_option_schema_id$_'; const NAME_KEY = '$name'; const ONE_OF_KEY = 'oneOf'; const PATTERN_PROPERTIES_KEY = 'patternProperties'; const PROPERTIES_KEY = 'properties'; const READONLY_KEY = 'readonly'; const REQUIRED_KEY = 'required'; const SUBMIT_BTN_OPTIONS_KEY = 'submitButtonOptions'; const REF_KEY = '$ref'; const SCHEMA_KEY = '$schema'; /** The path of the discriminator value returned by the schema endpoint. * The discriminator is the value in a `oneOf` that determines which option is selected. */ const DISCRIMINATOR_PATH = ['discriminator', 'propertyName']; /** The name of the `formContext` attribute in the React JSON Schema Form Registry */ const FORM_CONTEXT_NAME = 'formContext'; /** The name of the `layoutGridLookupMap` attribute in the form context */ const LOOKUP_MAP_NAME = 'layoutGridLookupMap'; const RJSF_ADDITIONAL_PROPERTIES_FLAG = '__rjsf_additionalProperties'; const ROOT_SCHEMA_PREFIX = '__rjsf_rootSchema'; const UI_FIELD_KEY = 'ui:field'; const UI_WIDGET_KEY = 'ui:widget'; const UI_OPTIONS_KEY = 'ui:options'; const UI_GLOBAL_OPTIONS_KEY = 'ui:globalOptions'; /** The JSON Schema version strings */ const JSON_SCHEMA_DRAFT_2020_12 = 'https://json-schema.org/draft/2020-12/schema'; /** Get all passed options from ui:options, and ui:<optionName>, returning them in an object with the `ui:` * stripped off. Any `globalOptions` will always be returned, unless they are overridden by options in the `uiSchema`. * * @param [uiSchema={}] - The UI Schema from which to get any `ui:xxx` options * @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options * @returns - An object containing all the `ui:xxx` options with the `ui:` stripped off along with all `globalOptions` */ function getUiOptions(uiSchema = {}, globalOptions = {}) { return Object.keys(uiSchema) .filter((key) => key.indexOf('ui:') === 0) .reduce((options, key) => { const value = uiSchema[key]; if (key === UI_WIDGET_KEY && isObject$c(value)) { console.error('Setting options via ui:widget object is no longer supported, use ui:options instead'); return options; } if (key === UI_OPTIONS_KEY && isObject$c(value)) { return { ...options, ...value }; } return { ...options, [key.substring(3)]: value }; }, { ...globalOptions }); } /** Checks whether the field described by `schema`, having the `uiSchema` and `formData` supports expanding. The UI for * the field can expand if it has additional properties, is not forced as non-expandable by the `uiSchema` and the * `formData` object doesn't already have `schema.maxProperties` elements. * * @param schema - The schema for the field that is being checked * @param [uiSchema={}] - The uiSchema for the field * @param [formData] - The formData for the field * @returns - True if the schema element has additionalProperties, is expandable, and not at the maxProperties limit */ function canExpand(schema, uiSchema = {}, formData) { if (!(schema.additionalProperties || schema.patternProperties)) { return false; } const { expandable = true } = getUiOptions(uiSchema); if (expandable === false) { return expandable; } // if ui:options.expandable was not explicitly set to false, we can add // another property if we have not exceeded maxProperties yet if (schema.maxProperties !== undefined && formData) { return Object.keys(formData).length < schema.maxProperties; } return true; } /** Detect free variable `global` from Node.js. */ var freeGlobal$2 = typeof global == 'object' && global && global.Object === Object && global; /** Detect free variable `self`. */ var freeSelf$1 = typeof self == 'object' && self && self.Object === Object && self; /** Used as a reference to the global object. */ var root$9 = freeGlobal$2 || freeSelf$1 || Function('return this')(); /** Built-in value references. */ var Symbol$8 = root$9.Symbol; /** Used for built-in method references. */ var objectProto$y = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty$s = objectProto$y.hasOwnProperty; /** * Used to resolve the * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ var nativeObjectToString$3 = objectProto$y.toString; /** Built-in value references. */ var symToStringTag$3 = Symbol$8 ? Symbol$8.toStringTag : undefined; /** * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. * * @private * @param {*} value The value to query. * @returns {string} Returns the raw `toStringTag`. */ function getRawTag$2(value) { var isOwn = hasOwnProperty$s.call(value, symToStringTag$3), tag = value[symToStringTag$3]; try { value[symToStringTag$3] = undefined; var unmasked = true; } catch (e) {} var result = nativeObjectToString$3.call(value); if (unmasked) { if (isOwn) { value[symToStringTag$3] = tag; } else { delete value[symToStringTag$3]; } } return result; } /** Used for built-in method references. */ var objectProto$x = Object.prototype; /** * Used to resolve the * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ var nativeObjectToString$2 = objectProto$x.toString; /** * Converts `value` to a string using `Object.prototype.toString`. * * @private * @param {*} value The value to convert. * @returns {string} Returns the converted string. */ function objectToString$2(value) { return nativeObjectToString$2.call(value); } /** `Object#toString` result references. */ var nullTag$1 = '[object Null]', undefinedTag$1 = '[object Undefined]'; /** Built-in value references. */ var symToStringTag$2 = Symbol$8 ? Symbol$8.toStringTag : undefined; /** * The base implementation of `getTag` without fallbacks for buggy environments. * * @private * @param {*} value The value to query. * @returns {string} Returns the `toStringTag`. */ function baseGetTag$8(value) { if (value == null) { return value === undefined ? undefinedTag$1 : nullTag$1; } return (symToStringTag$2 && symToStringTag$2 in Object(value)) ? getRawTag$2(value) : objectToString$2(value); } /** * Creates a unary function that invokes `func` with its argument transformed. * * @private * @param {Function} func The function to wrap. * @param {Function} transform The argument transform. * @returns {Function} Returns the new function. */ function overArg$3(func, transform) { return function(arg) { return func(transform(arg)); }; } /** Built-in value references. */ var getPrototype$4 = overArg$3(Object.getPrototypeOf, Object); /** * Checks if `value` is object-like. A value is object-like if it's not `null` * and has a `typeof` result of "object". * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is object-like, else `false`. * @example * * _.isObjectLike({}); * // => true * * _.isObjectLike([1, 2, 3]); * // => true * * _.isObjectLike(_.noop); * // => false * * _.isObjectLike(null); * // => false */ function isObjectLike$b(value) { return value != null && typeof value == 'object'; } /** `Object#toString` result references. */ var objectTag$9 = '[object Object]'; /** Used for built-in method references. */ var funcProto$5 = Function.prototype, objectProto$w = Object.prototype; /** Used to resolve the decompiled source of functions. */ var funcToString$5 = funcProto$5.toString; /** Used to check objects for own properties. */ var hasOwnProperty$r = objectProto$w.hasOwnProperty; /** Used to infer the `Object` constructor. */ var objectCtorString$1 = funcToString$5.call(Object); /** * Checks if `value` is a plain object, that is, an object created by the * `Object` constructor or one with a `[[Prototype]]` of `null`. * * @static * @memberOf _ * @since 0.8.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. * @example * * function Foo() { * this.a = 1; * } * * _.isPlainObject(new Foo); * // => false * * _.isPlainObject([1, 2, 3]); * // => false * * _.isPlainObject({ 'x': 0, 'y': 0 }); * // => true * * _.isPlainObject(Object.create(null)); * // => true */ function isPlainObject$5(value) { if (!isObjectLike$b(value) || baseGetTag$8(value) != objectTag$9) { return false; } var proto = getPrototype$4(value); if (proto === null) { return true; } var Ctor = hasOwnProperty$r.call(proto, 'constructor') && proto.constructor; return typeof Ctor == 'function' && Ctor instanceof Ctor && funcToString$5.call(Ctor) == objectCtorString$1; } /** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it * * @param formData - The form data around which the error handler is created * @returns - A `FormValidation` object based on the `formData` structure */ function createErrorHandler(formData) { const handler = { // We store the list of errors for this node in a property named __errors // to avoid name collision with a possible sub schema field named // 'errors' (see `utils.toErrorSchema`). [ERRORS_KEY]: [], addError(message) { this[ERRORS_KEY].push(message); }, }; if (Array.isArray(formData)) { return formData.reduce((acc, value, key) => { return { ...acc, [key]: createErrorHandler(value) }; }, handler); } if (isPlainObject$5(formData)) { const formObject = formData; return Object.keys(formObject).reduce((acc, key) => { return { ...acc, [key]: createErrorHandler(formObject[key]) }; }, handler); } return handler; } /** * Removes all key-value entries from the list cache. * * @private * @name clear * @memberOf ListCache */ function listCacheClear$2() { this.__data__ = []; this.size = 0; } /** * Performs a * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) * comparison between two values to determine if they are equivalent. * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. * @returns {boolean} Returns `true` if the values are equivalent, else `false`. * @example * * var object = { 'a': 1 }; * var other = { 'a': 1 }; * * _.eq(object, object); * // => true * * _.eq(object, other); * // => false * * _.eq('a', 'a'); * // => true * * _.eq('a', Object('a')); * // => false * * _.eq(NaN, NaN); * // => true */ function eq$7(value, other) { return value === other || (value !== value && other !== other); } /** * Gets the index at which the `key` is found in `array` of key-value pairs. * * @private * @param {Array} array The array to inspect. * @param {*} key The key to search for. * @returns {number} Returns the index of the matched value, else `-1`. */ function assocIndexOf$5(array, key) { var length = array.length; while (length--) { if (eq$7(array[length][0], key)) { return length; } } return -1; } /** Used for built-in method references. */ var arrayProto$2 = Array.prototype; /** Built-in value references. */ var splice$2 = arrayProto$2.splice; /** * Removes `key` and its value from the list cache. * * @private * @name delete * @memberOf ListCache * @param {string} key The key of the value to remove. * @returns {boolean} Returns `true` if the entry was removed, else `false`. */ function listCacheDelete$2(key) { var data = this.__data__, index = assocIndexOf$5(data, key); if (index < 0) { return false; } var lastIndex = data.length - 1; if (index == lastIndex) { data.pop(); } else { splice$2.call(data, index, 1); } --this.size; return true; } /** * Gets the list cache value for `key`. * * @private * @name get * @memberOf ListCache * @param {string} key The key of the value to get. * @returns {*} Returns the entry value. */ function listCacheGet$2(key) { var data = this.__data__, index = assocIndexOf$5(data, key); return index < 0 ? undefined : data[index][1]; } /** * Checks if a list cache value for `key` exists. * * @private * @name has * @memberOf ListCache * @param {string} key The key of the entry to check. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. */ function listCacheHas$2(key) { return assocIndexOf$5(this.__data__, key) > -1; } /** * Sets the list cache `key` to `value`. * * @private * @name set * @memberOf ListCache * @param {string} key The key of the value to set. * @param {*} value The value to set. * @returns {Object} Returns the list cache instance. */ function listCacheSet$2(key, value) { var data = this.__data__, index = assocIndexOf$5(data, key); if (index < 0) { ++this.size; data.push([key, value]); } else { data[index][1] = value; } return this; } /** * Creates an list cache object. * * @private * @constructor * @param {Array} [entries] The key-value pairs to cache. */ function ListCache$5(entries) { var index = -1, length = entries == null ? 0 : entries.length; this.clear(); while (++index < length) { var entry = entries[index]; this.set(entry[0], entry[1]); } } // Add methods to `ListCache`. ListCache$5.prototype.clear = listCacheClear$2; ListCache$5.prototype['delete'] = listCacheDelete$2; ListCache$5.prototype.get = listCacheGet$2; ListCache$5.prototype.has = listCacheHas$2; ListCache$5.prototype.set = listCacheSet$2; /** * Removes all key-value entries from the stack. * * @private * @name clear * @memberOf Stack */ function stackClear$2() { this.__data__ = new ListCache$5; this.size = 0; } /** * Removes `key` and its value from the stack. * * @private * @name delete * @memberOf Stack * @param {string} key The key of the value to remove. * @returns {boolean} Returns `true` if the entry was removed, else `false`. */ function stackDelete$2(key) { var data = this.__data__, result = data['delete'](key); this.size = data.size; return result; } /** * Gets the stack value for `key`. * * @private * @name get * @memberOf Stack * @param {string} key The key of the value to get. * @returns {*} Returns the entry value. */ function stackGet$2(key) { return this.__data__.get(key); } /** * Checks if a stack value for `key` exists. * * @private * @name has * @memberOf Stack * @param {string} key The key of the entry to check. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. */ function stackHas$2(key) { return this.__data__.has(key); } /** * Checks if `value` is the * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) * * @static * @memberOf _ * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an object, else `false`. * @example * * _.isObject({}); * // => true * * _.isObject([1, 2, 3]); * // => true * * _.isObject(_.noop); * // => true * * _.isObject(null); * // => false */ function isObject$b(value) { var type = typeof value; return value != null && (type == 'object' || type == 'function'); } /** `Object#toString` result references. */ var asyncTag$1 = '[object AsyncFunction]', funcTag$5 = '[object Function]', genTag$3 = '[object GeneratorFunction]', proxyTag$1 = '[object Proxy]'; /** * Checks if `value` is classified as a `Function` object. * * @static * @memberOf _ * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a function, else `false`. * @example * * _.isFunction(_); * // => true * * _.isFunction(/abc/); * // => false */ function isFunction$7(value) { if (!isObject$b(value)) { return false; } // The use of `Object#toString` avoids issues with the `typeof` operator // in Safari 9 which returns 'object' for typed arrays and other constructors. var tag = baseGetTag$8(value); return tag == funcTag$5 || tag == genTag$3 || tag == asyncTag$1 || tag == proxyTag$1; } /** Used to detect overreaching core-js shims. */ var coreJsData$2 = root$9['__core-js_shared__']; /** Used to detect methods masquerading as native. */ var maskSrcKey$1 = (function() { var uid = /[^.]+$/.exec(coreJsData$2 && coreJsData$2.keys && coreJsData$2.keys.IE_PROTO || ''); return uid ? ('Symbol(src)_1.' + uid) : ''; }()); /** * Checks if `func` has its source masked. * * @private * @param {Function} func The function to check. * @returns {boolean} Returns `true` if `func` is masked, else `false`. */ function isMasked$2(func) { return !!maskSrcKey$1 && (maskSrcKey$1 in func); } /** Used for built-in method references. */ var funcProto$4 = Function.prototype; /** Used to resolve the decompiled source of functions. */ var funcToString$4 = funcProto$4.toString; /** * Converts `func` to its source code. * * @private * @param {Function} func The function to convert. * @returns {string} Returns the source code. */ function toSource$3(func) { if (func != null) { try { return funcToString$4.call(func); } catch (e) {} try { return (func + ''); } catch (e) {} } return ''; } /** * Used to match `RegExp` * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). */ var reRegExpChar$1 = /[\\^$.*+?()[\]{}|]/g; /** Used to detect host constructors (Safari). */ var reIsHostCtor$1 = /^\[object .+?Constructor\]$/; /** Used for built-in method references. */ var funcProto$3 = Function.prototype, objectProto$v = Object.prototype; /** Used to resolve the decompiled source of functions. */ var funcToString$3 = funcProto$3.toString; /** Used to check objects for own properties. */ var hasOwnProperty$q = objectProto$v.hasOwnProperty; /** Used to detect if a method is native. */ var reIsNative$1 = RegExp('^' + funcToString$3.call(hasOwnProperty$q).replace(reRegExpChar$1, '\\$&') .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' ); /** * The base implementation of `_.isNative` without bad shim checks. * * @private * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a native function, * else `false`. */ function baseIsNative$2(value) { if (!isObject$b(value) || isMasked$2(value)) { return false; } var pattern = isFunction$7(value) ? reIsNative$1 : reIsHostCtor$1; return pattern.test(toSource$3(value)); } /** * Gets the value at `key` of `object`. * * @private * @param {Object} [object] The object to query. * @param {string} key The key of the property to get. * @returns {*} Returns the property value. */ function getValue$3(object, key) { return object == null ? undefined : object[key]; } /** * Gets the native function at `key` of `object`. * * @private * @param {Object} object The object to query. * @param {string} key The key of the method to get. * @returns {*} Returns the function if it's native, else `undefined`. */ function getNative$8(object, key) { var value = getValue$3(object, key); return baseIsNative$2(value) ? value : undefined; } /* Built-in method references that are verified to be native. */ var Map$5 = getNative$8(root$9, 'Map'); /* Built-in method references that are verified to be native. */ var nativeCreate$5 = getNative$8(Object, 'create'); /** * Removes all key-value entries from the hash. * * @private * @name clear * @memberOf Hash */ function hashClear$2() { this.__data__ = nativeCreate$5 ? nativeCreate$5(null) : {}; this.size = 0; } /** * Removes `key` and its value from the hash. * * @private * @name delete * @memberOf Hash * @param {Object} hash The hash to modify. * @param {string} key The key of the value to remove. * @returns {boolean} Returns `true` if the entry was removed, else `false`. */ function hashDelete$2(key) { var result = this.has(key) && delete this.__data__[key]; this.size -= result ? 1 : 0; return result; } /** Used to stand-in for `undefined` hash values. */ var HASH_UNDEFINED$5 = '__lodash_hash_undefined__'; /** Used for built-in method references. */ var objectProto$u = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty$p = objectProto$u.hasOwnProperty; /** * Gets the hash value for `key`. * * @private * @name get * @memberOf Hash * @param {string} key The key of the value to get. * @returns {*} Returns the entry value. */ function hashGet$2(key) { var data = this.__data__; if (nativeCreate$5) { var result = data[key]; return result === HASH_UNDEFINED$5 ? undefined : result; } return hasOwnProperty$p.call(data, key) ? data[key] : undefined; } /** Used for built-in method references. */ var objectProto$t = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty$o = objectProto$t.hasOwnProperty; /** * Checks if a hash value for `key` exists. * * @private * @name has * @memberOf Hash * @param {string} key The key of the entry to check. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. */ function hashHas$2(key) { var data = this.__data__; return nativeCreate$5 ? (data[key] !== undefined) : hasOwnProperty$o.call(data, key); } /** Used to stand-in for `undefined` hash values. */ var HASH_UNDEFINED$4 = '__lodash_hash_undefined__'; /** * Sets the hash `key` to `value`. * * @private * @name set * @memberOf Hash * @param {string} key The key of the value to set. * @param {*} value The value to set. * @returns {Object} Returns the hash instance. */ function hashSet$2(key, value) { var data = this.__data__; this.size += this.has(key) ? 0 : 1; data[key] = (nativeCreate$5 && value === undefined) ? HASH_UNDEFINED$4 : value; return this; } /** * Creates a hash object. * * @private * @constructor * @param {Array} [entries] The key-value pairs to cache. */ function Hash$2(entries) { var index = -1, length = entries == null ? 0 : entries.length; this.clear(); while (++index < length) { var entry = entries[index]; this.set(entry[0], entry[1]); } } // Add methods to `Hash`. Hash$2.prototype.clear = hashClear$2; Hash$2.prototype['delete'] = hashDelete$2; Hash$2.prototype.get = hashGet$2; Hash$2.prototype.has = hashHas$2; Hash$2.prototype.set = hashSet$2; /** * Removes all key-value entries from the map. * * @private * @name clear * @memberOf MapCache */ function mapCacheClear$2() { this.size = 0; this.__data__ = { 'hash': new Hash$2, 'map': new (Map$5 || ListCache$5), 'string': new Hash$2 }; } /** * Checks if `value` is suitable for use as unique object key. * * @private * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is suitable, else `false`. */ function isKeyable$2(value) { var type = typeof value; return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') ? (value !== '__proto__') : (value === null); } /** * Gets the data for `map`. * * @private * @param {Object} map The map to query. * @param {string} key The reference key. * @returns {*} Returns the map data. */ function getMapData$5(map, key) { var data = map.__data__; return isKeyable$2(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map; } /** * Removes `key` and its value from the map. * * @private * @name delete * @memberOf MapCache * @param {string} key The key of the value to remove. * @returns {boolean} Returns `true` if the entry was removed, else `false`. */ function mapCacheDelete$2(key) { var result = getMapData$5(this, key)['delete'](key); this.size -= result ? 1 : 0; return result; } /** * Gets the map value for `key`. * * @private * @name get * @memberOf MapCache * @param {string} key The key of the value to get. * @returns {*} Returns the entry value. */ function mapCacheGet$2(key) { return getMapData$5(this, key).get(key); } /** * Checks if a map value for `key` exists. * * @private * @name has * @memberOf MapCache * @param {string} key The key of the entry to check. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. */ function mapCacheHas$2(key) { return getMapData$5(this, key).has(key); } /** * Sets the map `key` to `value`. * * @private * @name set * @memberOf MapCache * @param {string} key The key of the value to set. * @param {*} value The value to set. * @returns {Object} Returns the map cache instance. */ function mapCacheSet$2(key, value) { var data = getMapData$5(this, key), size = data.size; data.set(key, value); this.size += data.size == size ? 0 : 1; return this; } /** * Creates a map cache object to store key-value pairs. * * @private * @constructor * @param {Array} [entries] The key-value pairs to cache. */ function MapCache$4(entries) { var index = -1, length = entries == null ? 0 : entries.length; this.clear(); while (++index < length) { var entry = entries[index]; this.set(entry[0], entry[1]); } } // Add methods to `MapCache`. MapCache$4.prototype.clear = mapCacheClear$2; MapCache$4.prototype['delete'] = mapCacheDelete$2; MapCache$4.prototype.get = mapCacheGet$2; MapCache$4.prototype.has = mapCacheHas$2; MapCache$4.prototype.set = mapCacheSet$2; /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE$5 = 200; /** * Sets the stack `key` to `value`. * * @private * @name set * @memberOf Stack * @param {string} key The key of the value to set. * @param {*} value The value to set. * @returns {Object} Returns the stack cache instance. */ function stackSet$2(key, value) { var data = this.__data__; if (data instanceof ListCache$5) { var pairs = data.__data__; if (!Map$5 || (pairs.length < LARGE_ARRAY_SIZE$5 - 1)) { pairs.push([key, value]); this.size = ++data.size; return this; } data = this.__data__ = new MapCache$4(pairs); } data.set(key, value); this.size = data.size; return this; } /** * Creates a stack cache object to store key-value pairs. * * @private * @constructor * @param {Array} [entries] The key-value pairs to cache. */ function Stack$5(entries) { var data = this.__data__ = new ListCache$5(entries); this.size = data.size; } // Add methods to `Stack`. Stack$5.prototype.clear = stackClear$2; Stack$5.prototype['delete'] = stackDelete$2; Stack$5.prototype.get = stackGet$2; Stack$5.prototype.has = stackHas$2; Stack$5.prototype.set = stackSet$2; /** Used to stand-in for `undefined` hash values. */ var HASH_UNDEFINED$3 = '__lodash_hash_undefined__'; /** * Adds `value` to the array cache. * * @private * @name add * @memberOf SetCache * @alias push * @param {*} value The value to cache. * @returns {Object} Returns the cache instance. */ function setCacheAdd$2(value) { this.__data__.set(value, HASH_UNDEFINED$3); return this; } /** * Checks if `value` is in the array cache. * * @private * @name has * @memberOf SetCache * @param {*} value The value to search for. * @returns {number} Returns `true` if `value` is found, else `false`. */ function setCacheHas$2(value) { return this.__data__.has(value); } /** * * Creates an array cache object to store unique values. * * @private * @constructor * @param {Array} [values] The values to cache. */ function SetCache$5(values) { var index = -1, length = values == null ? 0 : values.length; this.__data__ = new MapCache$4; while (++index < length) { this.add(values[index]); } } // Add methods to `SetCache`. SetCache$5.prototype.add = SetCache$5.prototype.push = setCacheAdd$2; SetCache$5.prototype.has = setCacheHas$2; /** * A specialized version of `_.some` for arrays without support for iteratee * shorthands. * * @private * @param {Array} [array] The array to iterate over. * @param {Function} predicate The function invoked per iteration. * @returns {boolean} Returns `true` if any element passes the predicate check, * else `false`. */ function arraySome$2(array, predicate) { var index = -1, length = array == null ? 0 : array.length; while (++index < length) { if (predicate(array[index], index, array)) { return true; } } return false; } /** * Checks if a `cache` value for `key` exists. * * @private * @param {Object} cache The cache to query. * @param {string} key The key of the entry to check. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. */ function cacheHas$5(cache, key) { return cache.has(key); } /** Used to compose bitmasks for value comparisons. */ var COMPARE_PARTIAL_FLAG$b = 1, COMPARE_UNORDERED_FLAG$7 = 2; /** * A specialized version of `baseIsEqualDeep` for arrays with support for * partial deep comparisons. * * @private * @param {Array} array The array to compare. * @param {Array} other The other array to compare. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. * @param {Function} customizer The function to customize comparisons. * @param {Function} equalFunc The function to determine equivalents of values. * @param {Object} stack Tracks traversed `array` and `other` objects. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. */ function equalArrays$3(array, other, bitmask, customizer, equalFunc, stack) { var isPartial = bitmask & COMPARE_PARTIAL_FLAG$b, arrLength = array.length, othLength = other.length; if (arrLength != othLength && !(isPartial && othLength > arrLength)) { return false; } // Check that cyclic values are equal. var arrStacked = stack.get(array); var othStacked = stack.get(other); if (arrStacked && othStacked) { return arrStacked == other && othStacked == array; } var index = -1, result = true, seen = (bitmask & COMPARE_UNORDERED_FLAG$7) ? new SetCache$5 : undefined; stack.set(array, other); stack.set(other, array); // Ignore non-index properties. while (++index < arrLength) { var arrValue = array[index], othValue = other[index]; if (customizer) { var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack); } if (compared !== undefined) { if (compared) { continue; } result = false; break; } // Recursively compare arrays (susceptible to call stack limits). if (seen) { if (!arraySome$2(other, function(othValue, othIndex) { if (!cacheHas$5(seen, othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) { return seen.push(othIndex); } })) { result = false; break; } } else if (!( arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack) )) { result = false; break; } } stack['delete'](array); stack['delete'](other); return result; } /** Built-in value references. */ var Uint8Array$4 = root$9.Uint8Array; /** * Converts `map` to its key-value pairs. * * @private * @param {Object} map The map to convert. * @returns {Array} Returns the key-value pairs. */ function mapToArray$2(map) { var index = -1, result = Array(map.size); map.forEach(function(value, key) { result[++index] = [key, value]; }); return result; } /** * Converts `set` to an array of its values. * * @private * @param {Object} set The set to convert. * @returns {Array} Returns the values. */ function setToArray$4(set) { var index = -1, result = Array(set.size); set.forEach(function(value) { result[++index] = value; }); return result; } /** Used to compose bitmasks for value comparisons. */ var COMPARE_PARTIAL_FLAG$a = 1, COMPARE_UNORDERED_FLAG$6 = 2; /** `Object#toString` result references. */ var boolTag$8 = '[object Boolean]', dateTag$7 = '[object Date]', errorTag$5 = '[object Error]', mapTag$c = '[object Map]', numberTag$8 = '[object Number]', regexpTag$7 = '[object RegExp]', setTag$c = '[object Set]', stringTag$8 = '[object String]', symbolTag$7 = '[object Symbol]'; var arrayBufferTag$7 = '[object ArrayBuffer]', dataViewTag$9 = '[object DataView]'; /** Used to convert symbols to primitives and strings. */ var symbolProto$5 = Symbol$8 ? Symbol$8.prototype : undefined, symbolValueOf$3 = symbolProto$5 ? symbolProto$5.valueOf : undefined; /** * A specialized version of `baseIsEqualDeep` for comparing objects of * the same `toStringTag`. * * **Note:** This function only supports comparing values with tags of * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. * * @private * @param {Object} object The object to compare. * @param {Object} other The other object to compare. * @param {string} tag The `toStringTag` of the objects to compare. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. * @param {Function} customizer The function to customize comparisons. * @param {Function} equalFunc The function to determine equivalents of values. * @param {Object} stack Tracks traversed `object` and `other` objects. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. */ function equalByTag$2(object, other, tag, bitmask, customizer, equalFunc, stack) { switch (tag) { case dataViewTag$9: if ((object.byteLength != other.byteLength) || (object.byteOffset != other.byteOffset)) { return false; } object = object.buffer; other = other.buffer; case arrayBufferTag$7: if ((object.byteLength != other.byteLength) || !equalFunc(new Uint8Array$4(object), new Uint8Array$4(other))) { return false; } return true; case boolTag$8: case dateTag$7: case numberTag$8: // Coerce booleans to `1` or `0` and dates to milliseconds. // Invalid dates are coerced to `NaN`. return eq$7(+object, +other); case errorTag$5: return object.name == other.name && object.message == other.message; case regexpTag$7: case stringTag$8: // Coerce regexes to strings and treat strings, primitives and objects, // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring // for more details. return object == (other + ''); case mapTag$c: var convert = mapToArray$2; case setTag$c: var isPartial = bitmask & COMPARE_PARTIAL_FLAG$a; convert || (convert = setToArray$4); if (object.size != other.size && !isPartial) { return false; } // Assume cyclic values are equal. var stacked = stack.get(object); if (stacked) { return stacked == other; } bitmask |= COMPARE_UNORDERED_FLAG$6; // Recursively compare objects (susceptible to call stack limits). stack.set(object, other); var result = equalArrays$3(convert(object), convert(other), bitmask, customizer, equalFunc, stack); stack['delete'](object); return result; case symbolTag$7: if (symbolValueOf$3) { return symbolValueOf$3.call(object) == symbolValueOf$3.call(other); } } return false; } /** * Appends the elements of `values` to `array`. * * @private * @param {Array} array The array to modify. * @param {Array} values The values to append. * @returns {Array} Returns `array`. */ function arrayPush$4(array, values) { var index = -1, length = values.length, offset = array.length; while (++index < length) { array[offset + index] = values[index]; } return array; } /** * Checks if `value` is classified as an `Array` object. * * @static * @memberOf _ * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an array, else `false`. * @example * * _.isArray([1, 2, 3]); * // => true * * _.isArray(document.body.children); * // => false * * _.isArray('abc'); * // => false * * _.isArray(_.noop); * // => false */ var isArray$i = Array.isArray; /** * The base implementation of `getAllKeys` and `getAllKeysIn` which uses * `keysFunc` and `symbolsFunc` to get the enumerable property names and * symbols of `object`. * * @private * @param {Object} object The object to query. * @param {Function} keysFunc The function to get the keys of `object`. * @param {Function} symbolsFunc The function to get the symbols of `object`. * @returns {Array} Returns the array of property names and symbols. */ function baseGetAllKeys$3(object, keysFunc, symbolsFunc) { var result = keysFunc(object); return isArray$i(object) ? result : arrayPush$4(result, symbolsFunc(object)); } /** * A specialized version of `_.filter` for arrays without support for * iteratee shorthands. * * @private * @param {Array} [array] The array to iterate over. * @param {Function} predicate The function invoked per iteration. * @returns {Array} Returns the new filtered array. */ function arrayFilter$2(array, predicate) { var index = -1, length = array == null ? 0 : array.length, resIndex = 0, result = []; while (++index < length) { var value = array[index]; if (predicate(value, index, array)) { result[resIndex++] = value; } } return result; } /** * This method returns a new empty array. * * @static * @memberOf _ * @since 4.13.0 * @category Util * @returns {Array} Returns the new empty array. * @example * * var arrays = _.times(2, _.stubArray); * * console.log(arrays); * // => [[], []] * * console.log(arrays[0] === arrays[1]); * // => false */ function stubArray$3() { return []; } /** Used for built-in method references. */ var objectProto$s = Object.prototype; /** Built-in value references. */ var propertyIsEnumerable$3 = objectProto$s.propertyIsEnumerable; /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeGetSymbols$3 = Object.getOwnPropertySymbols; /** * Creates an array of the own enumerable symbols of `object`. * * @private * @param {Object} object The object to query. * @returns {Array} Returns the array of symbols. */ var getSymbols$4 = !nativeGetSymbols$3 ? stubArray$3 : function(object) { if (object == null) { return []; } object = Object(object); return arrayFilter$2(nativeGetSymbols$3(object), function(symbol) { return propertyIsEnumerable$3.call(object, symbol); }); }; /** * The base implementation of `_.times` without support for iteratee shorthands * or max array length checks. * * @private * @param {number} n The number of times to invoke `iteratee`. * @param {Function} iteratee The function invoked per iteration. * @returns {Array} Returns the array of results. */ function baseTimes$2(n, iteratee) { var index = -1, result = Array(n); while (++index < n) { result[index] = iteratee(index); } return result; } /** `Object#toString` result references. */ var argsTag$7 = '[object Arguments]'; /** * The base implementation of `_.isArguments`. * * @private * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an `arguments` object, */ function baseIsArguments$2(value) { return isObjectLike$b(value) && baseGetTag$8(value) == argsTag$7; } /** Used for built-in method references. */ var objectProto$r = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty$n = objectProto$r.hasOwnProperty; /** Built-in value references. */ var propertyIsEnumerable$2 = objectProto$r.propertyIsEnumerable; /** * Checks if `value` is likely an `arguments` object. * * @static * @memberOf _ * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an `arguments` object, * else `false`. * @example * * _.isArguments(function() { return arguments; }()); * // => true * * _.isArguments([1, 2, 3]); * // => false */ var isArguments$5 = baseIsArguments$2(function() { return arguments; }()) ? baseIsArguments$2 : function(value) { return isObjectLike$b(value) && hasOwnProperty$n.call(value, 'callee') && !propertyIsEnumerable$2.call(value, 'callee'); }; /** * This method returns `false`. * * @static * @memberOf _ * @since 4.13.0 * @category Util * @returns {boolean} Returns `false`. * @example * * _.times(2, _.stubFalse); * // => [false, false] */ function stubFalse$1() { return false; } /** Detect free variable `exports`. */ var freeExports$2 = typeof exports == 'object' && exports && !exports.nodeType && exports; /** Detect free variable `module`. */ var freeModule$2 = freeExports$2 && typeof module == 'object' && module && !module.nodeType && module; /** Detect the popular CommonJS extension `module.exports`. */ var moduleExports$2 = freeModule$2 && freeModule$2.exports === freeExports$2; /** Built-in value references. */ var Buffer$1 = moduleExports$2 ? root$9.Buffer : undefined; /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeIsBuffer = Buffer$1 ? Buffer$1.isBuffer : undefined; /** * Checks if `value` is a buffer. * * @static * @memberOf _ * @since 4.3.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`. * @example * * _.isBuffer(new Buffer(2)); * // => true * * _.isBuffer(new Uint8Array(2)); * // => false */ var isBuffer$5 = nativeIsBuffer || stubFalse$1; /** Used as references for various `Number` constants. */ var MAX_SAFE_INTEGER$4 = 9007199254740991; /** Used to detect unsigned integer values. */ var reIsUint$1 = /^(?:0|[1-9]\d*)$/; /** * Checks if `value` is a valid array-like index. * * @private * @param {*} value The value to check. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. */ function isIndex$4(value, length) { var type = typeof value; length = length == null ? MAX_SAFE_INTEGER$4 : length; return !!length && (type == 'number' || (type != 'symbol' && reIsUint$1.test(value))) && (value > -1 && value % 1 == 0 && value < length); } /** Used as references for various `Number` constants. */ var MAX_SAFE_INTEGER$3 = 9007199254740991; /** * Checks if `value` is a valid array-like length. * * **Note:** This method is loosely based on * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. * @example * * _.isLength(3); * // => true * * _.isLength(Number.MIN_VALUE); * // => false * * _.isLength(Infinity); * // => false * * _.isLength('3'); * // => false */ function isLength$4(value) { return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER$3; } /** `Object#toString` result references. */ var argsTag$6 = '[object Arguments]', arrayTag$5 = '[object Array]', boolTag$7 = '[object Boolean]', dateTag$6 = '[object Date]', errorTag$4 = '[object Error]', funcTag$4 = '[object Function]', mapTag$b = '[object Map]', numberTag$7 = '[object Number]', objectTag$8 = '[object Object]', regexpTag$6 = '[object RegExp]', setTag$b = '[object Set]', stringTag$7 = '[object String]', weakMapTag$5 = '[object WeakMap]'; var arrayBufferTag$6 = '[object ArrayBuffer]', dataViewTag$8 = '[object DataView]', float32Tag$5 = '[object Float32Array]', float64Tag$5 = '[object Float64Array]', int8Tag$5 = '[object Int8Array]', int16Tag$5 = '[object Int16Array]', int32Tag$5 = '[object Int32Array]', uint8Tag$5 = '[object Uint8Array]', uint8ClampedTag$5 = '[object Uint8ClampedArray]', uint16Tag$5 = '[object Uint16Array]', uint32Tag$5 = '[object Uint32Array]'; /** Used to identify `toStringTag` values of typed arrays. */ var typedArrayTags$1 = {}; typedArrayTags$1[float32Tag$5] = typedArrayTags$1[float64Tag$5] = typedArrayTags$1[int8Tag$5] = typedArrayTags$1[int16Tag$5] = typedArrayTags$1[int32Tag$5] = typedArrayTags$1[uint8Tag$5] = typedArrayTags$1[uint8ClampedTag$5] = typedArrayTags$1[uint16Tag$5] = typedArrayTags$1[uint32Tag$5] = true; typedArrayTags$1[argsTag$6] = typedArrayTags$1[arrayTag$5] = typedArrayTags$1[arrayBufferTag$6] = typedArrayTags$1[boolTag$7] = typedArrayTags$1[dataViewTag$8] = typedArrayTags$1[dateTag$6] = typedArrayTags$1[errorTag$4] = typedArrayTags$1[funcTag$4] = typedArrayTags$1[mapTag$b] = typedArrayTags$1[numberTag$7] = typedArrayTags$1[objectTag$8] = typedArrayTags$1[regexpTag$6] = typedArrayTags$1[setTag$b] = typedArrayTags$1[stringTag$7] = typedArrayTags$1[weakMapTag$5] = false; /** * The base implementation of `_.isTypedArray` without Node.js optimizations. * * @private * @param {*} value The value to check. * @returns {b