UNPKG

tms-vue3-ui

Version:

Vue3基础UI库,提供JSONSchema编辑器,支持基于JSONSchema生成表单。

1,495 lines 380 kB
var De = Object.defineProperty; var je = (e, t, r) => t in e ? De(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r; var R = (e, t, r) => je(e, typeof t != "symbol" ? t + "" : t, r); import { defineComponent, getCurrentInstance, ref, watch, h } from "vue"; var commonjsGlobal = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; function getDefaultExportFromCjs(e) { return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e; } var lib$1 = { exports: {} }, util$1 = {}, types, hasRequiredTypes; function requireTypes() { return hasRequiredTypes || (hasRequiredTypes = 1, types = { ROOT: 0, GROUP: 1, POSITION: 2, SET: 3, RANGE: 4, REPETITION: 5, REFERENCE: 6, CHAR: 7 }), types; } var sets = {}, hasRequiredSets; function requireSets() { if (hasRequiredSets) return sets; hasRequiredSets = 1; const e = requireTypes(), t = () => [{ type: e.RANGE, from: 48, to: 57 }], r = () => [ { type: e.CHAR, value: 95 }, { type: e.RANGE, from: 97, to: 122 }, { type: e.RANGE, from: 65, to: 90 } ].concat(t()), n = () => [ { type: e.CHAR, value: 9 }, { type: e.CHAR, value: 10 }, { type: e.CHAR, value: 11 }, { type: e.CHAR, value: 12 }, { type: e.CHAR, value: 13 }, { type: e.CHAR, value: 32 }, { type: e.CHAR, value: 160 }, { type: e.CHAR, value: 5760 }, { type: e.RANGE, from: 8192, to: 8202 }, { type: e.CHAR, value: 8232 }, { type: e.CHAR, value: 8233 }, { type: e.CHAR, value: 8239 }, { type: e.CHAR, value: 8287 }, { type: e.CHAR, value: 12288 }, { type: e.CHAR, value: 65279 } ], i = () => [ { type: e.CHAR, value: 10 }, { type: e.CHAR, value: 13 }, { type: e.CHAR, value: 8232 }, { type: e.CHAR, value: 8233 } ]; return sets.words = () => ({ type: e.SET, set: r(), not: !1 }), sets.notWords = () => ({ type: e.SET, set: r(), not: !0 }), sets.ints = () => ({ type: e.SET, set: t(), not: !1 }), sets.notInts = () => ({ type: e.SET, set: t(), not: !0 }), sets.whitespace = () => ({ type: e.SET, set: n(), not: !1 }), sets.notWhitespace = () => ({ type: e.SET, set: n(), not: !0 }), sets.anyChar = () => ({ type: e.SET, set: i(), not: !0 }), sets; } var hasRequiredUtil$1; function requireUtil$1() { return hasRequiredUtil$1 || (hasRequiredUtil$1 = 1, function(e) { const t = requireTypes(), r = requireSets(), n = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?", i = { 0: 0, t: 9, n: 10, v: 11, f: 12, r: 13 }; e.strToChars = function(s) { var f = /(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|(0?[0-7]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g; return s = s.replace(f, function(o, d, p, l, m, c, u, a) { if (p) return o; var g = d ? 8 : l ? parseInt(l, 16) : m ? parseInt(m, 16) : c ? parseInt(c, 8) : u ? n.indexOf(u) : i[a], y = String.fromCharCode(g); return /[[\]{}^$.|?*+()]/.test(y) && (y = "\\" + y), y; }), s; }, e.tokenizeClass = (s, f) => { for (var o = [], d = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(?:\\)?([^\]]))|(\])|(?:\\)?([^])/g, p, l; (p = d.exec(s)) != null; ) if (p[1]) o.push(r.words()); else if (p[2]) o.push(r.ints()); else if (p[3]) o.push(r.whitespace()); else if (p[4]) o.push(r.notWords()); else if (p[5]) o.push(r.notInts()); else if (p[6]) o.push(r.notWhitespace()); else if (p[7]) o.push({ type: t.RANGE, from: (p[8] || p[9]).charCodeAt(0), to: p[10].charCodeAt(0) }); else if (l = p[12]) o.push({ type: t.CHAR, value: l.charCodeAt(0) }); else return [o, d.lastIndex]; e.error(f, "Unterminated character class"); }, e.error = (s, f) => { throw new SyntaxError("Invalid regular expression: /" + s + "/: " + f); }; }(util$1)), util$1; } var positions = {}, hasRequiredPositions; function requirePositions() { if (hasRequiredPositions) return positions; hasRequiredPositions = 1; const e = requireTypes(); return positions.wordBoundary = () => ({ type: e.POSITION, value: "b" }), positions.nonWordBoundary = () => ({ type: e.POSITION, value: "B" }), positions.begin = () => ({ type: e.POSITION, value: "^" }), positions.end = () => ({ type: e.POSITION, value: "$" }), positions; } var hasRequiredLib$1; function requireLib$1() { if (hasRequiredLib$1) return lib$1.exports; hasRequiredLib$1 = 1; const e = requireUtil$1(), t = requireTypes(), r = requireSets(), n = requirePositions(); return lib$1.exports = (i) => { var s = 0, f, o, d = { type: t.ROOT, stack: [] }, p = d, l = d.stack, m = [], c = (S) => { e.error(i, `Nothing to repeat at column ${S - 1}`); }, u = e.strToChars(i); for (f = u.length; s < f; ) switch (o = u[s++], o) { // Handle escaped characters, inclues a few sets. case "\\": switch (o = u[s++], o) { case "b": l.push(n.wordBoundary()); break; case "B": l.push(n.nonWordBoundary()); break; case "w": l.push(r.words()); break; case "W": l.push(r.notWords()); break; case "d": l.push(r.ints()); break; case "D": l.push(r.notInts()); break; case "s": l.push(r.whitespace()); break; case "S": l.push(r.notWhitespace()); break; default: /\d/.test(o) ? l.push({ type: t.REFERENCE, value: parseInt(o, 10) }) : l.push({ type: t.CHAR, value: o.charCodeAt(0) }); } break; // Positionals. case "^": l.push(n.begin()); break; case "$": l.push(n.end()); break; // Handle custom sets. case "[": var a; u[s] === "^" ? (a = !0, s++) : a = !1; var g = e.tokenizeClass(u.slice(s), i); s += g[1], l.push({ type: t.SET, set: g[0], not: a }); break; // Class of any character except \n. case ".": l.push(r.anyChar()); break; // Push group onto stack. case "(": var y = { type: t.GROUP, stack: [], remember: !0 }; o = u[s], o === "?" && (o = u[s + 1], s += 2, o === "=" ? y.followedBy = !0 : o === "!" ? y.notFollowedBy = !0 : o !== ":" && e.error( i, `Invalid group, character '${o}' after '?' at column ${s - 1}` ), y.remember = !1), l.push(y), m.push(p), p = y, l = y.stack; break; // Pop group out of stack. case ")": m.length === 0 && e.error(i, `Unmatched ) at column ${s - 1}`), p = m.pop(), l = p.options ? p.options[p.options.length - 1] : p.stack; break; // Use pipe character to give more choices. case "|": p.options || (p.options = [p.stack], delete p.stack); var _ = []; p.options.push(_), l = _; break; // Repetition. // For every repetition, remove last element from last stack // then insert back a RANGE object. // This design is chosen because there could be more than // one repetition symbols in a regex i.e. `a?+{2,3}`. case "{": var b = /^(\d+)(,(\d+)?)?\}/.exec(u.slice(s)), x, v; b !== null ? (l.length === 0 && c(s), x = parseInt(b[1], 10), v = b[2] ? b[3] ? parseInt(b[3], 10) : 1 / 0 : x, s += b[0].length, l.push({ type: t.REPETITION, min: x, max: v, value: l.pop() })) : l.push({ type: t.CHAR, value: 123 }); break; case "?": l.length === 0 && c(s), l.push({ type: t.REPETITION, min: 0, max: 1, value: l.pop() }); break; case "+": l.length === 0 && c(s), l.push({ type: t.REPETITION, min: 1, max: 1 / 0, value: l.pop() }); break; case "*": l.length === 0 && c(s), l.push({ type: t.REPETITION, min: 0, max: 1 / 0, value: l.pop() }); break; // Default is a character that is not `\[](){}?+*^$`. default: l.push({ type: t.CHAR, value: o.charCodeAt(0) }); } return m.length !== 0 && e.error(i, "Unterminated group"), d; }, lib$1.exports.types = t, lib$1.exports; } var lib, hasRequiredLib; function requireLib() { if (hasRequiredLib) return lib; hasRequiredLib = 1; class e { constructor(n, i) { this.low = n, this.high = i, this.length = 1 + i - n; } overlaps(n) { return !(this.high < n.low || this.low > n.high); } touches(n) { return !(this.high + 1 < n.low || this.low - 1 > n.high); } // Returns inclusive combination of SubRanges as a SubRange. add(n) { return new e( Math.min(this.low, n.low), Math.max(this.high, n.high) ); } // Returns subtraction of SubRanges as an array of SubRanges. // (There's a case where subtraction divides it in 2) subtract(n) { return n.low <= this.low && n.high >= this.high ? [] : n.low > this.low && n.high < this.high ? [ new e(this.low, n.low - 1), new e(n.high + 1, this.high) ] : n.low <= this.low ? [new e(n.high + 1, this.high)] : [new e(this.low, n.low - 1)]; } toString() { return this.low == this.high ? this.low.toString() : this.low + "-" + this.high; } } class t { constructor(n, i) { this.ranges = [], this.length = 0, n != null && this.add(n, i); } _update_length() { this.length = this.ranges.reduce((n, i) => n + i.length, 0); } add(n, i) { var s = (f) => { for (var o = 0; o < this.ranges.length && !f.touches(this.ranges[o]); ) o++; for (var d = this.ranges.slice(0, o); o < this.ranges.length && f.touches(this.ranges[o]); ) f = f.add(this.ranges[o]), o++; d.push(f), this.ranges = d.concat(this.ranges.slice(o)), this._update_length(); }; return n instanceof t ? n.ranges.forEach(s) : (i == null && (i = n), s(new e(n, i))), this; } subtract(n, i) { var s = (f) => { for (var o = 0; o < this.ranges.length && !f.overlaps(this.ranges[o]); ) o++; for (var d = this.ranges.slice(0, o); o < this.ranges.length && f.overlaps(this.ranges[o]); ) d = d.concat(this.ranges[o].subtract(f)), o++; this.ranges = d.concat(this.ranges.slice(o)), this._update_length(); }; return n instanceof t ? n.ranges.forEach(s) : (i == null && (i = n), s(new e(n, i))), this; } intersect(n, i) { var s = [], f = (o) => { for (var d = 0; d < this.ranges.length && !o.overlaps(this.ranges[d]); ) d++; for (; d < this.ranges.length && o.overlaps(this.ranges[d]); ) { var p = Math.max(this.ranges[d].low, o.low), l = Math.min(this.ranges[d].high, o.high); s.push(new e(p, l)), d++; } }; return n instanceof t ? n.ranges.forEach(f) : (i == null && (i = n), f(new e(n, i))), this.ranges = s, this._update_length(), this; } index(n) { for (var i = 0; i < this.ranges.length && this.ranges[i].length <= n; ) n -= this.ranges[i].length, i++; return this.ranges[i].low + n; } toString() { return "[ " + this.ranges.join(", ") + " ]"; } clone() { return new t(this); } numbers() { return this.ranges.reduce((n, i) => { for (var s = i.low; s <= i.high; ) n.push(s), s++; return n; }, []); } subranges() { return this.ranges.map((n) => ({ low: n.low, high: n.high, length: 1 + n.high - n.low })); } } return lib = t, lib; } var randexp, hasRequiredRandexp; function requireRandexp() { if (hasRequiredRandexp) return randexp; hasRequiredRandexp = 1; const e = requireLib$1(), t = requireLib(), r = e.types; return randexp = class J { /** * @constructor * @param {RegExp|String} regexp * @param {String} m */ constructor(i, s) { if (this._setDefaults(i), i instanceof RegExp) this.ignoreCase = i.ignoreCase, this.multiline = i.multiline, i = i.source; else if (typeof i == "string") this.ignoreCase = s && s.indexOf("i") !== -1, this.multiline = s && s.indexOf("m") !== -1; else throw new Error("Expected a regexp or string"); this.tokens = e(i); } /** * Checks if some custom properties have been set for this regexp. * * @param {RandExp} randexp * @param {RegExp} regexp */ _setDefaults(i) { this.max = i.max != null ? i.max : J.prototype.max != null ? J.prototype.max : 100, this.defaultRange = i.defaultRange ? i.defaultRange : this.defaultRange.clone(), i.randInt && (this.randInt = i.randInt); } /** * Generates the random string. * * @return {String} */ gen() { return this._gen(this.tokens, []); } /** * Generate random string modeled after given tokens. * * @param {Object} token * @param {Array.<String>} groups * @return {String} */ _gen(i, s) { var f, o, d, p, l; switch (i.type) { case r.ROOT: case r.GROUP: if (i.followedBy || i.notFollowedBy) return ""; for (i.remember && i.groupNumber === void 0 && (i.groupNumber = s.push(null) - 1), f = i.options ? this._randSelect(i.options) : i.stack, o = "", p = 0, l = f.length; p < l; p++) o += this._gen(f[p], s); return i.remember && (s[i.groupNumber] = o), o; case r.POSITION: return ""; case r.SET: var m = this._expand(i); return m.length ? String.fromCharCode(this._randSelect(m)) : ""; case r.REPETITION: for (d = this.randInt( i.min, i.max === 1 / 0 ? i.min + this.max : i.max ), o = "", p = 0; p < d; p++) o += this._gen(i.value, s); return o; case r.REFERENCE: return s[i.value - 1] || ""; case r.CHAR: var c = this.ignoreCase && this._randBool() ? this._toOtherCase(i.value) : i.value; return String.fromCharCode(c); } } /** * If code is alphabetic, converts to other case. * If not alphabetic, returns back code. * * @param {Number} code * @return {Number} */ _toOtherCase(i) { return i + (97 <= i && i <= 122 ? -32 : 65 <= i && i <= 90 ? 32 : 0); } /** * Randomly returns a true or false value. * * @return {Boolean} */ _randBool() { return !this.randInt(0, 1); } /** * Randomly selects and returns a value from the array. * * @param {Array.<Object>} arr * @return {Object} */ _randSelect(i) { return i instanceof t ? i.index(this.randInt(0, i.length - 1)) : i[this.randInt(0, i.length - 1)]; } /** * expands a token to a DiscontinuousRange of characters which has a * length and an index function (for random selecting) * * @param {Object} token * @return {DiscontinuousRange} */ _expand(i) { if (i.type === e.types.CHAR) return new t(i.value); if (i.type === e.types.RANGE) return new t(i.from, i.to); { let s = new t(); for (let f = 0; f < i.set.length; f++) { let o = this._expand(i.set[f]); if (s.add(o), this.ignoreCase) for (let d = 0; d < o.length; d++) { let p = o.index(d), l = this._toOtherCase(p); p !== l && s.add(l); } } return i.not ? this.defaultRange.clone().subtract(s) : this.defaultRange.clone().intersect(s); } } /** * Randomly generates and returns a number between a and b (inclusive). * * @param {Number} a * @param {Number} b * @return {Number} */ randInt(i, s) { return i + Math.floor(Math.random() * (1 + s - i)); } /** * Default range of characters to generate from. */ get defaultRange() { return this._range = this._range || new t(32, 126); } set defaultRange(i) { this._range = i; } /** * * Enables use of randexp with a shorter call. * * @param {RegExp|String| regexp} * @param {String} m * @return {String} */ static randexp(i, s) { var f; return typeof i == "string" && (i = new RegExp(i, s)), i._randexp === void 0 ? (f = new J(i, s), i._randexp = f) : (f = i._randexp, f._setDefaults(i)), f.gen(); } /** * Enables sugary /regexp/.gen syntax. */ static sugar() { RegExp.prototype.gen = function() { return J.randexp(this); }; } }, randexp; } var randexpExports = requireRandexp(); const RandExp = /* @__PURE__ */ getDefaultExportFromCjs(randexpExports); function genRandStringByExp(e) { let t = new RandExp(new RegExp(e)); return t.max = 8, t.gen(); } const ARRAY_KEYWORDS = [ "anyOf", "oneOf", "enum" ]; class Field { constructor(t, r = -1, n = "") { R(this, "value"); R(this, "type", ""); R(this, "_index"); R(this, "_name"); R(this, "_path"); R(this, "_prop"); R(this, "_required"); R(this, "_visible"); R(this, "_children"); R(this, "choices"); R(this, "choiceType"); R(this, "choiceVisible"); R(this, "waitingRender", !1); R(this, "autofillURL", ""); R(this, "autofillBody"); R(this, "autofilled", !1); let { attrs: i } = t, { type: s, default: f } = i; s === "array" ? this.value = Array.isArray(f) ? [...f] : [] : s === "object" ? this.value = f && typeof f == "object" ? Object.assign({}, f) : {} : s === "string" ? this.value = f || "" : this.value = void 0, ["object", "array"].includes(s) && (this._children = []), this._prop = t, this._required = t.attrs.required ?? !1, this._visible = !1, this._index = r, this._name = n || t.name, this._path = t.path; } get index() { return this._index; } get name() { return this._name; } set path(t) { this._path = t; } get path() { return this._path; } get fullname() { if (this.index !== -1) { let t = this.path.replace(/\[\*\]$/, `[${this._index}]`); return this.name && this.name !== "[*]" ? `${t}.${this.name}` : t; } else return this.name ? (this.path ? this.path + "." : "") + this.name : this.path; } get shortname() { if (this.index !== -1) { let t = this.path.split(".").pop(); return t ? t.replace(/\[\*\]$/, `[${this._index}]`) : this.name; } else return this.name; } get depth() { let t = this.fullname; return t ? t.split(/\.|\[\d+\]/).length : 0; } get label() { return this._prop.attrs.title ?? ""; } get description() { return this._prop.attrs.description ?? ""; } get schemaType() { return this._prop.attrs.type; } get itemSchemaType() { var t; return (t = this._prop.items) == null ? void 0 : t.type; } get schemaRequired() { return this._prop.attrs.required ?? !1; } get required() { return this._required; } set required(t) { this._required = t; } get visible() { return this._visible; } set visible(t) { this._visible = t; } get schemaProp() { return this._prop; } get enumGroups() { return this._prop.attrs.enumGroups; } get attachment() { return this._prop.attachment; } get children() { return this._children; } get isOneOf() { return this._prop.isOneOf ?? !1; } isChildOf(t) { return t.fullname === this.path || t.fullname + "[*]" === this.path; } static initialKey(t) { return genRandStringByExp(t); } static initialVal(t, r) { switch (r) { case "boolean": return t === !0; case "integer": return isNaN(parseInt(t)) ? 0 : parseInt(t); case "number": return isNaN(parseFloat(t)) ? 0 : parseFloat(t); case "string": return typeof t == "string" ? t : ""; case "object": return t && typeof t == "object" ? t : {}; case "array": return Array.isArray(t) ? t : []; } return t; } static isOneOfInclusiveGroupName(t) { return t.schemaProp.isOneOfInclusiveGroup ? `${t.path}.${t.schemaProp.isOneOfInclusiveGroup}` : ""; } } class FieldBoolean extends Field { constructor(t, r = -1, n = "") { super(t, r, n), this.type = "checkbox"; } } class FieldText extends Field { constructor(r, n = -1, i = "") { super(r, n, i); R(this, "minlength"); R(this, "maxlength"); R(this, "pattern"); const { attrs: s } = r; if (s.format) switch (s.format) { case "email": this.type = "email"; break; case "password": this.type = "password"; break; case "uri": this.type = "url"; break; case "regex": this.type = "text"; break; case "dateTime": this.type = "dateTime"; break; case "longtext": case "mustache": case "handlebars": case "markdown": case "xml": case "yaml": this.type = "textarea"; break; } else switch (s.type) { case "number": case "integer": this.type = "number"; break; case "json": this.type = "textarea"; break; default: this.type = "text"; } } } function parseChoices(e) { return e == null ? void 0 : e.map((t) => { let r = { value: t.value, label: t.label }; return t.group && (r.group = t.group), r; }); } class FieldArray extends Field { constructor(r, n = -1, i = "") { var f; super(r, n, i); R(this, "choices", []); R(this, "itemGroups"); const { attrs: s } = r; for (const o of ARRAY_KEYWORDS) if (s.hasOwnProperty(o)) switch (o) { case "enum": this.type || (this.type = "select"), (f = s == null ? void 0 : s.enumGroups) != null && f.length && (this.itemGroups = s.enumGroups), this.choiceType = "option", this.choices = parseChoices(s[o]) ?? []; break; case "oneOf": this.type = "radiogroup", this.choiceType = "radio", this.value = this.hasOwnProperty("value") ? this.value : "", this.choices = parseChoices(s[o]) ?? []; break; case "anyOf": this.type = "checkboxgroup", this.choiceType = "checkbox", this.value = Array.isArray(this.value) ? this.value : [], this.choices = parseChoices(s[o]) ?? []; break; } this.type || (this.type = s.type, this.choices = []); } } class FieldObject extends Field { constructor(t, r = -1, n = "") { super(t, r, n); const { attrs: i, items: s } = t; this.type = i.type; } } function createField(e, t, r, n = -1, i = "") { var f; let s; switch (t.attrs.type) { case "boolean": s = new FieldBoolean(t, n, i); break; case "array": s = t.attrs.hasOwnProperty("anyOf") ? new FieldArray(t, n, i) : new FieldObject(t, n, i); break; case "object": s = new FieldObject(t, n, i); break; case "integer": case "number": case "string": for (const o of ARRAY_KEYWORDS) if (t.attrs.hasOwnProperty(o)) { t.items = { type: t.attrs.type, enum: t.attrs[o] }, s = new FieldArray(t, n, i); break; } s || (s = new FieldText(t, n, i)); break; default: s = new FieldText(t, n, i); } if (r && (s.path = r.fullname, t.name === "[*]" && (s.path += "[*]")), e.fields) { let o = e.fields.get(s.fullname); o ? s = o : (r && ["object", "array"].includes(r.type) && ((f = r.children) == null || f.push(s)), e.fields.set(s.fullname, s)); } if (!s) throw Error(`根据属性【${t.fullname}】创建字段失败`); return s; } var browser = { exports: {} }, ms, hasRequiredMs; function requireMs() { if (hasRequiredMs) return ms; hasRequiredMs = 1; var e = 1e3, t = e * 60, r = t * 60, n = r * 24, i = n * 7, s = n * 365.25; ms = function(l, m) { m = m || {}; var c = typeof l; if (c === "string" && l.length > 0) return f(l); if (c === "number" && isFinite(l)) return m.long ? d(l) : o(l); throw new Error( "val is not a non-empty string or a valid number. val=" + JSON.stringify(l) ); }; function f(l) { if (l = String(l), !(l.length > 100)) { var m = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( l ); if (m) { var c = parseFloat(m[1]), u = (m[2] || "ms").toLowerCase(); switch (u) { case "years": case "year": case "yrs": case "yr": case "y": return c * s; case "weeks": case "week": case "w": return c * i; case "days": case "day": case "d": return c * n; case "hours": case "hour": case "hrs": case "hr": case "h": return c * r; case "minutes": case "minute": case "mins": case "min": case "m": return c * t; case "seconds": case "second": case "secs": case "sec": case "s": return c * e; case "milliseconds": case "millisecond": case "msecs": case "msec": case "ms": return c; default: return; } } } } function o(l) { var m = Math.abs(l); return m >= n ? Math.round(l / n) + "d" : m >= r ? Math.round(l / r) + "h" : m >= t ? Math.round(l / t) + "m" : m >= e ? Math.round(l / e) + "s" : l + "ms"; } function d(l) { var m = Math.abs(l); return m >= n ? p(l, m, n, "day") : m >= r ? p(l, m, r, "hour") : m >= t ? p(l, m, t, "minute") : m >= e ? p(l, m, e, "second") : l + " ms"; } function p(l, m, c, u) { var a = m >= c * 1.5; return Math.round(l / c) + " " + u + (a ? "s" : ""); } return ms; } var common, hasRequiredCommon; function requireCommon() { if (hasRequiredCommon) return common; hasRequiredCommon = 1; function e(t) { n.debug = n, n.default = n, n.coerce = p, n.disable = o, n.enable = s, n.enabled = d, n.humanize = requireMs(), n.destroy = l, Object.keys(t).forEach((m) => { n[m] = t[m]; }), n.names = [], n.skips = [], n.formatters = {}; function r(m) { let c = 0; for (let u = 0; u < m.length; u++) c = (c << 5) - c + m.charCodeAt(u), c |= 0; return n.colors[Math.abs(c) % n.colors.length]; } n.selectColor = r; function n(m) { let c, u = null, a, g; function y(..._) { if (!y.enabled) return; const b = y, x = Number(/* @__PURE__ */ new Date()), v = x - (c || x); b.diff = v, b.prev = c, b.curr = x, c = x, _[0] = n.coerce(_[0]), typeof _[0] != "string" && _.unshift("%O"); let S = 0; _[0] = _[0].replace(/%([a-zA-Z%])/g, (w, k) => { if (w === "%%") return "%"; S++; const N = n.formatters[k]; if (typeof N == "function") { const q = _[S]; w = N.call(b, q), _.splice(S, 1), S--; } return w; }), n.formatArgs.call(b, _), (b.log || n.log).apply(b, _); } return y.namespace = m, y.useColors = n.useColors(), y.color = n.selectColor(m), y.extend = i, y.destroy = n.destroy, Object.defineProperty(y, "enabled", { enumerable: !0, configurable: !1, get: () => u !== null ? u : (a !== n.namespaces && (a = n.namespaces, g = n.enabled(m)), g), set: (_) => { u = _; } }), typeof n.init == "function" && n.init(y), y; } function i(m, c) { const u = n(this.namespace + (typeof c > "u" ? ":" : c) + m); return u.log = this.log, u; } function s(m) { n.save(m), n.namespaces = m, n.names = [], n.skips = []; const c = (typeof m == "string" ? m : "").trim().replace(" ", ",").split(",").filter(Boolean); for (const u of c) u[0] === "-" ? n.skips.push(u.slice(1)) : n.names.push(u); } function f(m, c) { let u = 0, a = 0, g = -1, y = 0; for (; u < m.length; ) if (a < c.length && (c[a] === m[u] || c[a] === "*")) c[a] === "*" ? (g = a, y = u, a++) : (u++, a++); else if (g !== -1) a = g + 1, y++, u = y; else return !1; for (; a < c.length && c[a] === "*"; ) a++; return a === c.length; } function o() { const m = [ ...n.names, ...n.skips.map((c) => "-" + c) ].join(","); return n.enable(""), m; } function d(m) { for (const c of n.skips) if (f(m, c)) return !1; for (const c of n.names) if (f(m, c)) return !0; return !1; } function p(m) { return m instanceof Error ? m.stack || m.message : m; } function l() { console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); } return n.enable(n.load()), n; } return common = e, common; } var hasRequiredBrowser; function requireBrowser() { return hasRequiredBrowser || (hasRequiredBrowser = 1, function(e, t) { t.formatArgs = n, t.save = i, t.load = s, t.useColors = r, t.storage = f(), t.destroy = /* @__PURE__ */ (() => { let d = !1; return () => { d || (d = !0, console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")); }; })(), t.colors = [ "#0000CC", "#0000FF", "#0033CC", "#0033FF", "#0066CC", "#0066FF", "#0099CC", "#0099FF", "#00CC00", "#00CC33", "#00CC66", "#00CC99", "#00CCCC", "#00CCFF", "#3300CC", "#3300FF", "#3333CC", "#3333FF", "#3366CC", "#3366FF", "#3399CC", "#3399FF", "#33CC00", "#33CC33", "#33CC66", "#33CC99", "#33CCCC", "#33CCFF", "#6600CC", "#6600FF", "#6633CC", "#6633FF", "#66CC00", "#66CC33", "#9900CC", "#9900FF", "#9933CC", "#9933FF", "#99CC00", "#99CC33", "#CC0000", "#CC0033", "#CC0066", "#CC0099", "#CC00CC", "#CC00FF", "#CC3300", "#CC3333", "#CC3366", "#CC3399", "#CC33CC", "#CC33FF", "#CC6600", "#CC6633", "#CC9900", "#CC9933", "#CCCC00", "#CCCC33", "#FF0000", "#FF0033", "#FF0066", "#FF0099", "#FF00CC", "#FF00FF", "#FF3300", "#FF3333", "#FF3366", "#FF3399", "#FF33CC", "#FF33FF", "#FF6600", "#FF6633", "#FF9900", "#FF9933", "#FFCC00", "#FFCC33" ]; function r() { if (typeof window < "u" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) return !0; if (typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) return !1; let d; return typeof document < "u" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773 typeof window < "u" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31? // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages typeof navigator < "u" && navigator.userAgent && (d = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(d[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/); } function n(d) { if (d[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + d[0] + (this.useColors ? "%c " : " ") + "+" + e.exports.humanize(this.diff), !this.useColors) return; const p = "color: " + this.color; d.splice(1, 0, p, "color: inherit"); let l = 0, m = 0; d[0].replace(/%[a-zA-Z%]/g, (c) => { c !== "%%" && (l++, c === "%c" && (m = l)); }), d.splice(m, 0, p); } t.log = console.debug || console.log || (() => { }); function i(d) { try { d ? t.storage.setItem("debug", d) : t.storage.removeItem("debug"); } catch { } } function s() { let d; try { d = t.storage.getItem("debug"); } catch { } return !d && typeof process < "u" && "env" in process && (d = process.env.DEBUG), d; } function f() { try { return localStorage; } catch { } } e.exports = requireCommon()(t); const { formatters: o } = e.exports; o.j = function(d) { try { return JSON.stringify(d); } catch (p) { return "[UnexpectedJSONParseError]: " + p.message; } }; }(browser, browser.exports)), browser.exports; } var browserExports = requireBrowser(); const Debug = /* @__PURE__ */ getDefaultExportFromCjs(browserExports), debug$7 = Debug("json-schema:model"); var PropAutofillTarget; (function(e) { e.value = "value", e.items = "items"; })(PropAutofillTarget || (PropAutofillTarget = {})); var PropAutofillRunPolicy; (function(e) { e.onCreate = "onCreate", e.onParamChange = "onParamChange", e.onUser = "onUser"; })(PropAutofillRunPolicy || (PropAutofillRunPolicy = {})); class SchemaProp { constructor(t, r, n) { R(this, "_parent"); R(this, "_path"); R(this, "_name"); R(this, "attrs"); R(this, "existIf"); R(this, "lookup"); R(this, "items"); R(this, "attachment"); R(this, "isPattern", !1); R(this, "children"); R(this, "patternChildren"); R(this, "isOneOf", !1); R(this, "isOneOfDefault", !1); R(this, "isOneOfInclusiveGroup", ""); R(this, "isOneOfExclusiveGroup", ""); R(this, "isOneOfChildren", /* @__PURE__ */ new Map()); this._path = t, this._name = r, this.attrs = { type: n ?? "" }; } get parent() { return this._parent; } set parent(t) { this._parent = t; } get path() { if (this._parent) { let t = this._parent.fullname; return this._parent.attrs.type === "array" && (t += "[*]"), t; } return this._path; } set path(t) { this._path = t; } get name() { return this._name; } set name(t) { this._name = t; } get fullname() { return this.name ? this.path ? this.path + (this.name === "[*]" ? "" : ".") + this.name : this.name : this.path; } get fullRegExp() { var i; let t = debug$7.extend("fullRegExp"), { fullname: r } = this, n = r.replace(/^\^/, "").replace(/\$$/, "").replace(/\.\^/g, ".").replace(/\$\./g, ".").replace(/\$\[/g, "[").replaceAll("[*]", "\\[\\d+\\]").replace(new RegExp("\\.", "g"), "\\."); return this.attrs.type === "array" && ((i = this.items) == null ? void 0 : i.type) !== "object" && (t(`属性定义【${r}】为数组类型,数组项目的类型不是对象,需要解决子项目属性匹配`), n += "(\\[\\d+\\])?"), n = "^" + n + "$", t(`属性定义【${r}】的正则表达式为【${n}】`), new RegExp(n); } get parentFullname() { return this.path.replace(/\[\*\]$/, ""); } get isArrayItem() { return /\[\*\]$/.test(this.path); } toJSON() { let t = { ...this }; return delete t.children, delete t.patternChildren, t; } readableValue(t, r) { var i, s, f, o, d, p, l, m; const { attrs: n } = this; switch (n.type) { case "boolean": return t ? "是" : "否"; case "number": case "string": if ((i = n.enum) != null && i.length) if ((s = n.enumGroups) != null && s.length) { const c = n.enumGroups.find((a) => a.assocEnum.value === r[a.assocEnum.property]); if (!c) return ""; const u = n.enum.find((a) => a.group === c.id && a.value === t); return u ? u.label : ""; } else { const c = n.enum.find((u) => u.value === t); return c ? c.label : ""; } else if ((f = n.oneOf) != null && f.length) if ((o = n.enumGroups) != null && o.length) { const c = n.enumGroups.find((a) => a.assocEnum.value === r[a.assocEnum.property]); if (!c) return ""; const u = n.oneOf.find((a) => a.group === c.id && a.value === t); return u ? u.label : ""; } else { const c = n.oneOf.find((u) => u.value === t); if (c) return c.label; } break; case "array": if (!Array.isArray(t) || t.length === 0) return ""; if ((d = n.enum) != null && d.length) if ((p = n.enumGroups) != null && p.length) { const c = n.enumGroups.find((a) => a.assocEnum.value === r[a.assocEnum.property]); return c ? n.enum.filter((a) => a.group === c.id && t.includes(a.value)).map((a) => a.label).join(" ") : ""; } else return n.enum.filter((u) => t.includes(u.value)).map((u) => u.label).join(" "); else if ((l = n.anyOf) != null && l.length) if ((m = n.enumGroups) != null && m.length) { const c = n.enumGroups.find((a) => a.assocEnum.value === r[a.assocEnum.property]); return c ? n.anyOf.filter((a) => a.group === c.id && t.includes(a.value)).map((a) => a.label).join(" ") : ""; } else return n.anyOf.filter((u) => t.includes(u.value)).map((u) => u.label).join(" "); break; } return t; } } function _setDefaultValue(e, t, r, n) { var s; let i = e.name; if (r.length) { let f = r[0], { type: o, default: d } = f.attrs; if (n === !1 && o === "object") if (d && typeof d == "object") d[i] = t; else { f.attrs.default = { [i]: t }; let p = f; for (let l = 1; l < r.length; l++) { let m = r[l]; if (m.attrs.type === "object" && !((s = m.patternChildren) != null && s.includes(p))) if (m.attrs.default && typeof m.attrs.default == "object") { m.attrs.default[p.name] = p.attrs.default; break; } else m.attrs.default = { [p.name]: p.attrs.default }, p = m; else break; } } } e.attrs.default = t; } function* _parseChildren(e, t, r, n = !1) { let i = Object.keys(e); for (let s = 0, f; s < i.length; s++) f = i[s], yield* _parseOne(f, e[f], t, r == null ? void 0 : r.includes(f), n); } function* _parseOne(e, t, r, n, i = !1) { var y, _, b; const s = debug$7.extend("_parseOne"); s(`开始解析属性【${e}】`); let f = ""; r.length && (f = r[0].fullname, r[0].attrs.type === "array" && (f += "[*]")); let o = new SchemaProp(f, e); r.length && (o.parent = r[0], (y = r[0]).children ?? (y.children = []), r[0].children.push(o)), n && (o.attrs.required = n), o.isPattern = i, r.length && i && ((_ = r[0].patternChildren) == null || _.push(o)); let { properties: d, patternProperties: p, items: l, required: m, lookup: c, existIf: u } = t, a = Object.keys(t); for (let x = 0; x < a.length; x++) { let v = a[x]; switch (v) { case "properties": case "patternProperties": case "lookup": case "existIf": case "required": break; case "items": o.items = { type: l.type }, Object.keys(l).forEach((S) => { S !== "properties" && S !== "patternProperties" && Object.assign(o.items, { [S]: l[S] }); }); case "attachment": o.attachment = t.attachment; break; case "type": case "title": case "description": case "format": case "oneOf": case "anyOf": case "enum": case "enumGroups": case "autofill": case "initialName": Object.assign(o.attrs, { [v]: t[v] }); break; case "default": _setDefaultValue(o, t.default, r, i); break; case "isOneOf": if (r.length && t.isOneOf === !0) { o.isOneOf = !0; const { isOneOfChildren: S } = r[0], { isOneOfInclusiveGroup: O, isOneOfExclusiveGroup: w } = t; let k; w ? (S.has(w) || S.set(w, /* @__PURE__ */ new Map()), k = S.get(w)) : (S.has("") || S.set("", /* @__PURE__ */ new Map()), k = S.get("")), k && (O ? k.has(O) ? (b = k.get(O)) == null || b.push(o) : k.set(O, [o]) : k.set(o.name, [o])); } break; case "isOneOfDefault": o[v] = t[v]; break; case "isOneOfInclusiveGroup": case "isOneOfExclusiveGroup": o[v] = t[v]; break; default: Object.assign(o.attrs, { [v]: t[v] }); } } typeof m == "boolean" && (o.attrs.required = m), (t.type === "object" && p && typeof p == "object" || t.type === "array" && (l != null && l.patternProperties) && typeof l.patternProperties == "object") && (o.patternChildren = []), c && typeof c == "object" && (o.lookup = c), u && typeof u == "object" && (o.existIf = u), yield o; let g = Array.isArray(m) ? m : []; t.type === "object" ? (typeof d == "object" && (yield* _parseChildren(d, [o, ...r], g)), typeof p == "object" && (yield* _parseChildren(p, [o, ...r], g, !0))) : t.type === "array" && l && typeof l == "object" && (typeof l.properties == "object" && (yield* _parseChildren(l.properties, [o, ...r], g)), typeof l.patternProperties == "object" && (s(`属性${o.fullname}包含模板属性`), yield* _parseChildren(l.patternProperties, [o, ...r], g, !0))); } const DEFAULT_ROOT_NAME$1 = ""; class SchemaIter { constructor(t, r = DEFAULT_ROOT_NAME$1) { R(this, "_rawSchema"); R(this, "_rootName"); this._rawSchema = t, this._rootName = r; } get rootName() { return this._rootName; } *[Symbol.iterator]() { yield* _parseOne(this._rootName, this._rawSchema, []); } } class Node { constructor(t, r) { R(this, "ctx"); R(this, "rawArgs"); R(this, "_vnode"); this.ctx = t, this.rawArgs = r; } attrOrProps(t = {}, r = {}, n = {}) { const { option: i } = this.rawArgs; let s; return typeof i == "function" ? s = i({ ctx: this.ctx, field: r, item: n }) : s = { ...i, native: void 0 }, { ...t, ...s }; } createElem(t = []) { const r = this.attrOrProps(); return this._vnode = this.ctx.h(this.rawArgs.tag, r, t), this._vnode; } } const option$1 = { native: !0 }, components = { title: { tag: "h1", option: option$1 }, description: { tag: "p", option: option$1 }, error: { tag: "div", option: option$1 }, form: { tag: "div", option: option$1 }, fieldWrap: { tag: "div", option: option$1 }, fieldLabel: { tag: "label", option: option$1 }, fieldDescription: { tag: "div", option: option$1 }, input: { tag: "input", option: option$1 }, textarea: { tag: "textarea", option: option$1 }, radio: { tag: "input", option: option$1 }, radiogroup: { tag: "div", option: option$1 }, select: { tag: "select", option: option$1 }, option: { tag: "option", option: option$1 }, checkbox: { tag: "input", option: option$1 }, checkboxgroup: { tag: "div", option: option$1 }, object: { tag: "div", option: option$1 }, array: { tag: "div", option: option$1 }, file: { tag: "div", option: option$1 }, button: { tag: "button", option: option$1 }, a: { tag: "a", option: option$1 } }, option = { native: !0 }, defaultInput = { tag: "input", option }, defaultGroup = { tag: "div", option }; function getRawCreateArgs(e) { return e.choices && e.type !== "select" ? components[`${e.type}group`] || defaultGroup : components[e.type] || defaultInput; } class FieldNode extends Node { constructor(r, n) { super(r, getRawCreateArgs(n)); R(this, "_field"); this._field = n, this._assocEnum(); } get field() { return this._field; } fieldValue() { const { field: r } = this, n = r.fullname; let i; return i = this.ctx.editDoc.get2(n), i ?? (i = r.value), i; } _assocEnum() { var f, o; const { field: r, ctx: n } = this, i = n.editDoc, s = r.fullname; (f = r.enumGroups) != null && f.length && ((o = r.choices) != null && o.length) && (r.choiceVisible = {}, r.enumGroups.forEach((d) => { var l, m; let { assocEnum: p } = d; !(p != null && p.property) || !(p != null && p.value) || (i.get(p.property) !== p.value ? (l = r.choices) == null || l.forEach((c) => { if (c.group === d.id) { let u = c.group + c.value; r.choiceVisible && (r.choiceVisible[u] = !1); let a = i.get(s); if (r.schemaType === "string") a === c.value && i.set(s, ""); else if (Array.isArray(a) && a.includes(c.value)) { let g = a.indexOf(c.value); a.splice(g, 1); } } }) : (m = r.choices) == null || m.forEach((c) => { if (c.group === d.id) { let u = c.group + c.value; r.choiceVisible && (r.choiceVisible[u] = !0); } })); })); } _autofileValue() { const { editDoc: r, autofillRequest: n } = this.ctx; if (typeof n != "function") return; const { field: i } = this; if (!i.schemaProp.attrs.autofill) return; if (i.waitingRender) { i.waitingRender = !1; return; } const s = i.schemaProp.attrs.autofill; if (s.runPolicy === "onCreate" && i.autofilled === !0) return; const f = (p) => { if (s.target === "value" && typeof s.valuePath == "string") { let l = Jexl.evalSync(s.valuePath, p); this.autofillValue(i, l); } else if (s.target === "items" && typeof s.itemPath == "object") { const l = Jexl.evalSync(s.itemPath.path, p); let m = []; if (Array.isArray(l) && l.length) { let c = s.itemPath.label, u = s.itemPath.value; l.forEach((a) => { m.push({ label: Jexl.evalSync(c, a), value: Jexl.evalSync(u, a) }); }); } JSON.stringify(i.choices) !== JSON.stringify(m) && (i.choices = m, m.length === 1 && this.autofillValue(i, m[0].value), i.waitingRender = !0, this.ctx.editDoc.forceRender()); } }; let o = s.url; if (Array.isArray(s.params) && s.params.length) { let p = s.params.reduce((l, m, c) => { let { name: u, path: a, value: g } = m, y; return a ? y = `${u}=${r.get(a) ?? ""}` : g ? y = `${u}=${g}` : y = "", c === 0 ? y : `${l}&${y}`; }, ""); o += "?" + p; } const d = n(); if (/get/i.test(s.method)) { if (o === i.autofillURL) return; d.get(o).then(f).catch(() => { this.ctx.onMessage("通过接口获取自动填充数据失败"); }); } else if (/post/i.test(s.method)) { let p; if (Array.isArray(s.body) && s.body.length && (p = s.body.reduce((l, m) => { let { bodyPath: c, path: u, value: a } = m; return u ? JSONPointerLodash.set(l, c, r.get(u)) : a && JSONPointerLodash.set(l, c, a), l; }, {})), i.autofillBody && JSON.stringify(i.autofillBody) === JSON.stringify(p)) return; i.autofillBody = p, d.post(s.url, p).then(f).catch(() => { this.ctx.onMessage("通过接口获取自动填充数据失败"); }); } i.autofillURL = o, i.autofilled = !0; } autofillValue(r, n) { } children() { return []; } createElem() { const { field: r } = this, n = this.attrOrProps(r, r), i = this.options(n); let s = this.children(); if (this._vnode = this.ctx.h(this.rawArgs.tag, i, s), r.type === "password") { let f = function() { const d = document.querySelector(".tvu-jdoc__password > input"), p = document.querySelector(".tvu-jdoc__password > span"); (d == null ? void 0 : d.getAttribute("type")) === "password" ? (d == null || d.setAttribute("type", "text"), p && (p.className = "tvu-jdoc__password--open")) : (d == null || d.setAttribute("type", "password"), p && (p.className = "tvu-jdoc__password--close")); }, o = this.ctx.h("span", { class: "tvu-jdoc__password--close", onClick: f }); this._vnode = this.ctx.h("div", { class: "tvu-jdoc__password" }, [ this._vnode, o ]); } return this._vnode; } } const debug$6 = Debug("json-doc:nodes:input"); class Input extends FieldNode { updateModel(t) { const { field: r } = this, n = r.fullname; let i; switch (r.schemaType) { case "boolean": i = !this.ctx.editDoc.get(n), this.ctx.editDoc.set(n, i); break; case "json": try { i = JSON.parse(t), this.ctx.editDoc.set(n, i); } catch { } break; defau