UNPKG

tms-vue3-ui

Version:

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

1,487 lines 392 kB
var M = Object.defineProperty; var D = (e, t, r) => t in e ? M(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r; var P = (e, t, r) => D(e, typeof t != "symbol" ? t + "" : t, r); import { defineComponent, getCurrentInstance, ref, watch, h } from "vue"; 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(u, d, p, l, m, o, c, a) { if (p) return u; var g = d ? 8 : l ? parseInt(l, 16) : m ? parseInt(m, 16) : o ? parseInt(o, 8) : c ? n.indexOf(c) : i[a], y = String.fromCharCode(g); return /[[\]{}^$.|?*+()]/.test(y) && (y = "\\" + y), y; }), s; }, e.tokenizeClass = (s, f) => { for (var u = [], d = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(?:\\)?([^\]]))|(\])|(?:\\)?([^])/g, p, l; (p = d.exec(s)) != null; ) if (p[1]) u.push(r.words()); else if (p[2]) u.push(r.ints()); else if (p[3]) u.push(r.whitespace()); else if (p[4]) u.push(r.notWords()); else if (p[5]) u.push(r.notInts()); else if (p[6]) u.push(r.notWhitespace()); else if (p[7]) u.push({ type: t.RANGE, from: (p[8] || p[9]).charCodeAt(0), to: p[10].charCodeAt(0) }); else if (l = p[12]) u.push({ type: t.CHAR, value: l.charCodeAt(0) }); else return [u, 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, u, d = { type: t.ROOT, stack: [] }, p = d, l = d.stack, m = [], o = (C) => { e.error(i, `Nothing to repeat at column ${C - 1}`); }, c = e.strToChars(i); for (f = c.length; s < f; ) switch (u = c[s++], u) { // Handle escaped characters, inclues a few sets. case "\\": switch (u = c[s++], u) { 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(u) ? l.push({ type: t.REFERENCE, value: parseInt(u, 10) }) : l.push({ type: t.CHAR, value: u.charCodeAt(0) }); } break; // Positionals. case "^": l.push(n.begin()); break; case "$": l.push(n.end()); break; // Handle custom sets. case "[": var a; c[s] === "^" ? (a = !0, s++) : a = !1; var g = e.tokenizeClass(c.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 }; u = c[s], u === "?" && (u = c[s + 1], s += 2, u === "=" ? y.followedBy = !0 : u === "!" ? y.notFollowedBy = !0 : u !== ":" && e.error( i, `Invalid group, character '${u}' 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(c.slice(s)), S, v; b !== null ? (l.length === 0 && o(s), S = parseInt(b[1], 10), v = b[2] ? b[3] ? parseInt(b[3], 10) : 1 / 0 : S, s += b[0].length, l.push({ type: t.REPETITION, min: S, max: v, value: l.pop() })) : l.push({ type: t.CHAR, value: 123 }); break; case "?": l.length === 0 && o(s), l.push({ type: t.REPETITION, min: 0, max: 1, value: l.pop() }); break; case "+": l.length === 0 && o(s), l.push({ type: t.REPETITION, min: 1, max: 1 / 0, value: l.pop() }); break; case "*": l.length === 0 && o(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: u.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 u = 0; u < this.ranges.length && !f.touches(this.ranges[u]); ) u++; for (var d = this.ranges.slice(0, u); u < this.ranges.length && f.touches(this.ranges[u]); ) f = f.add(this.ranges[u]), u++; d.push(f), this.ranges = d.concat(this.ranges.slice(u)), 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 u = 0; u < this.ranges.length && !f.overlaps(this.ranges[u]); ) u++; for (var d = this.ranges.slice(0, u); u < this.ranges.length && f.overlaps(this.ranges[u]); ) d = d.concat(this.ranges[u].subtract(f)), u++; this.ranges = d.concat(this.ranges.slice(u)), 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 = (u) => { for (var d = 0; d < this.ranges.length && !u.overlaps(this.ranges[d]); ) d++; for (; d < this.ranges.length && u.overlaps(this.ranges[d]); ) { var p = Math.max(this.ranges[d].low, u.low), l = Math.min(this.ranges[d].high, u.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 L { /** * @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 : L.prototype.max != null ? L.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, u, 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, u = "", p = 0, l = f.length; p < l; p++) u += this._gen(f[p], s); return i.remember && (s[i.groupNumber] = u), u; 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 ), u = "", p = 0; p < d; p++) u += this._gen(i.value, s); return u; case r.REFERENCE: return s[i.value - 1] || ""; case r.CHAR: var o = this.ignoreCase && this._randBool() ? this._toOtherCase(i.value) : i.value; return String.fromCharCode(o); } } /** * 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 u = this._expand(i.set[f]); if (s.add(u), this.ignoreCase) for (let d = 0; d < u.length; d++) { let p = u.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 L(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 L.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 = "") { P(this, "value"); P(this, "type", ""); P(this, "_index"); P(this, "_name"); P(this, "_path"); P(this, "_prop"); P(this, "_required"); P(this, "_visible"); P(this, "_children"); P(this, "choices"); P(this, "choiceType"); P(this, "choiceVisible"); P(this, "waitingRender", !1); P(this, "autofillURL", ""); P(this, "autofillBody"); P(this, "autofilled", !1); let { attrs: i } = t, { type: s, const: f, default: u } = i; s === "array" ? this.value = Array.isArray(f) ? [...f] : Array.isArray(u) ? [...u] : [] : s === "object" ? this.value = f && typeof f == "object" ? f : u && typeof u == "object" ? Object.assign({}, u) : {} : s === "string" ? this.value = f || u || "" : 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); P(this, "minlength"); P(this, "maxlength"); P(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); P(this, "choices", []); P(this, "itemGroups"); const { attrs: s } = r; for (const u of ARRAY_KEYWORDS) if (s.hasOwnProperty(u)) switch (u) { 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[u]) ?? []; break; case "oneOf": this.type = "radiogroup", this.choiceType = "radio", this.value = this.hasOwnProperty("value") ? this.value : "", this.choices = parseChoices(s[u]) ?? []; break; case "anyOf": this.type = "checkboxgroup", this.choiceType = "checkbox", this.value = Array.isArray(this.value) ? this.value : [], this.choices = parseChoices(s[u]) ?? []; 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 u of ARRAY_KEYWORDS) if (t.attrs.hasOwnProperty(u)) { t.items = { type: t.attrs.type, enum: t.attrs[u] }, 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 u = e.fields.get(s.fullname); u ? s = u : (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$1 = { 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 o = typeof l; if (o === "string" && l.length > 0) return f(l); if (o === "number" && isFinite(l)) return m.long ? d(l) : u(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 o = parseFloat(m[1]), c = (m[2] || "ms").toLowerCase(); switch (c) { case "years": case "year": case "yrs": case "yr": case "y": return o * s; case "weeks": case "week": case "w": return o * i; case "days": case "day": case "d": return o * n; case "hours": case "hour": case "hrs": case "hr": case "h": return o * r; case "minutes": case "minute": case "mins": case "min": case "m": return o * t; case "seconds": case "second": case "secs": case "sec": case "s": return o * e; case "milliseconds": case "millisecond": case "msecs": case "msec": case "ms": return o; default: return; } } } } function u(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, o, c) { var a = m >= o * 1.5; return Math.round(l / o) + " " + c + (a ? "s" : ""); } return ms; } var common$1, hasRequiredCommon$1; function requireCommon$1() { if (hasRequiredCommon$1) return common$1; hasRequiredCommon$1 = 1; function e(t) { n.debug = n, n.default = n, n.coerce = p, n.disable = u, 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 o = 0; for (let c = 0; c < m.length; c++) o = (o << 5) - o + m.charCodeAt(c), o |= 0; return n.colors[Math.abs(o) % n.colors.length]; } n.selectColor = r; function n(m) { let o, c = null, a, g; function y(..._) { if (!y.enabled) return; const b = y, S = Number(/* @__PURE__ */ new Date()), v = S - (o || S); b.diff = v, b.prev = o, b.curr = S, o = S, _[0] = n.coerce(_[0]), typeof _[0] != "string" && _.unshift("%O"); let C = 0; _[0] = _[0].replace(/%([a-zA-Z%])/g, (x, A) => { if (x === "%%") return "%"; C++; const q = n.formatters[A]; if (typeof q == "function") { const k = _[C]; x = q.call(b, k), _.splice(C, 1), C--; } return x; }), 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: () => c !== null ? c : (a !== n.namespaces && (a = n.namespaces, g = n.enabled(m)), g), set: (_) => { c = _; } }), typeof n.init == "function" && n.init(y), y; } function i(m, o) { const c = n(this.namespace + (typeof o > "u" ? ":" : o) + m); return c.log = this.log, c; } function s(m) { n.save(m), n.namespaces = m, n.names = [], n.skips = []; const o = (typeof m == "string" ? m : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean); for (const c of o) c[0] === "-" ? n.skips.push(c.slice(1)) : n.names.push(c); } function f(m, o) { let c = 0, a = 0, g = -1, y = 0; for (; c < m.length; ) if (a < o.length && (o[a] === m[c] || o[a] === "*")) o[a] === "*" ? (g = a, y = c, a++) : (c++, a++); else if (g !== -1) a = g + 1, y++, c = y; else return !1; for (; a < o.length && o[a] === "*"; ) a++; return a === o.length; } function u() { const m = [ ...n.names, ...n.skips.map((o) => "-" + o) ].join(","); return n.enable(""), m; } function d(m) { for (const o of n.skips) if (f(m, o)) return !1; for (const o of n.names) if (f(m, o)) 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$1 = e, common$1; } var hasRequiredBrowser$1; function requireBrowser$1() { return hasRequiredBrowser$1 || (hasRequiredBrowser$1 = 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, (o) => { o !== "%%" && (l++, o === "%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") || 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$1()(t); const { formatters: u } = e.exports; u.j = function(d) { try { return JSON.stringify(d); } catch (p) { return "[UnexpectedJSONParseError]: " + p.message; } }; }(browser$1, browser$1.exports)), browser$1.exports; } var browserExports$1 = requireBrowser$1(); const Debug$1 = /* @__PURE__ */ getDefaultExportFromCjs(browserExports$1), debug$7 = Debug$1("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) { P(this, "_parent"); P(this, "_path"); P(this, "_name"); P(this, "attrs"); P(this, "existIf"); P(this, "lookup"); P(this, "items"); P(this, "attachment"); P(this, "isPattern", !1); P(this, "children"); P(this, "patternChildren"); P(this, "isOneOf", !1); P(this, "isOneOfDefault", !1); P(this, "isOneOfInclusiveGroup", ""); P(this, "isOneOfExclusiveGroup", ""); P(this, "isOneOfChildren", /* @__PURE__ */ new Map()); this._path = t, this._name = r, this.attrs = { type: n ?? "" }; } get title() { return this.attrs.title ?? this.name; } get fullTitle() { if (this.parent) { let t = this.parent.fullTitle; return this.parent.attrs.type === "array" && (t += "[*]"), t ? t + "." + this.title : this.title; } return this.title; } 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 n, i, s; let { fullname: t } = this, r = t.replace(/^\^/, "").replace(/\$$/, "").replace(/\.\^/g, ".").replace(/\$\./g, ".").replace(/\$\[/g, "[").replaceAll("[*]", "\\[\\d+\\]").replace(new RegExp("\\.", "g"), "\\."); return this.attrs.type === "array" && ((n = this.items) == null ? void 0 : n.type) !== "object" && ((i = this.items) == null ? void 0 : i.type) !== "array" ? ((s = this.items) == null ? void 0 : s.type) === "json" ? r += "(\\[\\d+\\])?([.\\[].*)?" : r += "(\\[\\d+\\])?" : this.attrs.type === "json" && (r += "([.\\[].*)?"), r = "^" + r + "$", new RegExp(r); } get fullRegExpNoChild() { let { fullname: t } = this, r = t.replace(/^\^/, "").replace(/\$$/, "").replace(/\.\^/g, ".").replace(/\$\./g, ".").replace(/\$\[/g, "[").replaceAll("[*]", "\\[\\d+\\]").replace(new RegExp("\\.", "g"), "\\."); return r = "^" + r + "$", new RegExp(r); } get parentFullname() { return this.path.replace(/\[\*\]$/, ""); } get isArrayItem() { return /\[\*\]$/.test(this.path); } get isSingleValue() { return !this.isPattern && this.attrs.type !== "array"; } get isFullSingleValue() { return this.parent ? this.isSingleValue && this.parent.isFullSingleValue : this.isSingleValue; } get isLeaf() { var t, r; return this.attrs.type !== "array" && this.attrs.type !== "object" || this.attrs.type === "array" && ((t = this.items) == null ? void 0 : t.type) !== "object" && ((r = this.items) == null ? void 0 : r.type) !== "array"; } toJSON() { let t = { ...this }; return delete t.children, delete t.patternChildren, t; } readableValue(t, r) { var i, s, f, u, 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 o = n.enumGroups.find((a) => a.assocEnum.value === r[a.assocEnum.property]); if (!o) return ""; const c = n.enum.find((a) => a.group === o.id && a.value === t); return c ? c.label : ""; } else { const o = n.enum.find((c) => c.value === t); return o ? o.label : ""; } else if ((f = n.oneOf) != null && f.length) if ((u = n.enumGroups) != null && u.length) { const o = n.enumGroups.find((a) => a.assocEnum.value === r[a.assocEnum.property]); if (!o) return ""; const c = n.oneOf.find((a) => a.group === o.id && a.value === t); return c ? c.label : ""; } else { const o = n.oneOf.find((c) => c.value === t); if (o) return o.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 o = n.enumGroups.find((a) => a.assocEnum.value === r[a.assocEnum.property]); return o ? n.enum.filter((a) => a.group === o.id && t.includes(a.value)).map((a) => a.label).join(" ") : ""; } else return n.enum.filter((c) => t.includes(c.value)).map((c) => c.label).join(" "); else if ((l = n.anyOf) != null && l.length) if ((m = n.enumGroups) != null && m.length) { const o = n.enumGroups.find((a) => a.assocEnum.value === r[a.assocEnum.property]); return o ? n.anyOf.filter((a) => a.group === o.id && t.includes(a.value)).map((a) => a.label).join(" ") : ""; } else return n.anyOf.filter((c) => t.includes(c.value)).map((c) => c.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: u, default: d } = f.attrs; if (n === !1 && u === "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 u = new SchemaProp(f, e); r.length && (u.parent = r[0], (y = r[0]).children ?? (y.children = []), r[0].children.push(u)), n && (u.attrs.required = n), u.isPattern = i, r.length && i && ((_ = r[0].patternChildren) == null || _.push(u)); let { properties: d, patternProperties: p, items: l, required: m, lookup: o, existIf: c } = t, a = Object.keys(t); for (let S = 0; S < a.length; S++) { let v = a[S]; switch (v) { case "properties": case "patternProperties": case "lookup": case "existIf": case "required": break; case "items": u.items = { type: l.type }, Object.keys(l).forEach((C) => { C !== "properties" && C !== "patternProperties" && Object.assign(u.items, { [C]: l[C] }); }); case "attachment": u.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(u.attrs, { [v]: t[v] }); break; case "default": _setDefaultValue(u, t.default, r, i); break; case "isOneOf": if (r.length && t.isOneOf === !0) { u.isOneOf = !0; const { isOneOfChildren: C } = r[0], { isOneOfInclusiveGroup: w, isOneOfExclusiveGroup: x } = t; let A; x ? (C.has(x) || C.set(x, /* @__PURE__ */ new Map()), A = C.get(x)) : (C.has("") || C.set("", /* @__PURE__ */ new Map()), A = C.get("")), A && (w ? A.has(w) ? (b = A.get(w)) == null || b.push(u) : A.set(w, [u]) : A.set(u.name, [u])); } break; case "isOneOfDefault": u[v] = t[v]; break; case "isOneOfInclusiveGroup": case "isOneOfExclusiveGroup": u[v] = t[v]; break; default: Object.assign(u.attrs, { [v]: t[v] }); } } typeof m == "boolean" && (u.attrs.required = m), (t.type === "object" && p && typeof p == "object" || t.type === "array" && (l != null && l.patternProperties) && typeof l.patternProperties == "object") && (u.patternChildren = []), o && typeof o == "object" && (u.lookup = o), c && typeof c == "object" && (u.existIf = c), yield u; let g = Array.isArray(m) ? m : []; t.type === "object" ? (typeof d == "object" && (yield* _parseChildren(d, [u, ...r], g)), typeof p == "object" && (yield* _parseChildren(p, [u, ...r], g, !0))) : t.type === "array" && l && typeof l == "object" && (typeof l.properties == "object" && (yield* _parseChildren(l.properties, [u, ...r], g)), typeof l.patternProperties == "object" && (s(`属性${u.fullname}包含模板属性`), yield* _parseChildren(l.patternProperties, [u, ...r], g, !0))); } const DEFAULT_ROOT_NAME$1 = ""; class SchemaIter { constructor(t, r = DEFAULT_ROOT_NAME$1) { P(this, "_rawSchema"); P(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) { P(this, "ctx"); P(this, "rawArgs"); P(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)); P(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, u; const { field: r, ctx: n } = this, i = n.editDoc, s = r.fullname; (f = r.enumGroups) != null && f.length && ((u = r.choices) != null && u.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((o) => { if (o.group === d.id) { let c = o.group + o.value; r.choiceVisible && (r.choiceVisible[c] = !1); let a = i.get(s); if (r.schemaType === "string") a === o.value && i.set(s, ""); else if (Array.isArray(a) && a.includes(o.value)) { let g = a.indexOf(o.value); a.splice(g, 1); } } }) : (m = r.choices) == null || m.forEach((o) => { if (o.group === d.id) { let c = o.group + o.value; r.choiceVisible && (r.choiceVisible[c] = !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 o = s.itemPath.label, c = s.itemPath.value; l.forEach((a) => { m.push({ label: Jexl.evalSync(o, a), value: Jexl.evalSync(c, 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 u = s.url; if (Array.isArray(s.params) && s.params.length) { let p = s.params.reduce((l, m, o) => { let { name: c, path: a, value: g } = m, y; return a ? y = `${c}=${r.get(a) ?? ""}` : g ? y = `${c}=${g}` : y = "", o === 0 ? y : `${l}&${y}`; }, ""); u += "?" + p; } const d = n(); if (/get/i.test(s.method)) { if (u === i.autofillURL) return; d.get(u).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: o, path: c, value: a } = m; return c ? JSONPointerLodash.set(l, o, r.get(c)) : a && JSONPointerLodash.set(l, o, 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 = u, 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),