UNPKG

@lxlib/form

Version:

This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.1.

1,278 lines (1,247 loc) 328 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/platform-browser'), require('@lxlib/acl'), require('@lxlib/theme'), require('@lxlib/util'), require('rxjs'), require('rxjs/operators'), require('@angular/common'), require('@angular/forms'), require('ng-zorro-antd/auto-complete'), require('ng-zorro-antd/button'), require('ng-zorro-antd/card'), require('ng-zorro-antd/cascader'), require('ng-zorro-antd/checkbox'), require('ng-zorro-antd/date-picker'), require('ng-zorro-antd/form'), require('ng-zorro-antd/grid'), require('ng-zorro-antd/icon'), require('ng-zorro-antd/input'), require('ng-zorro-antd/input-number'), require('ng-zorro-antd/mention'), require('ng-zorro-antd/modal'), require('ng-zorro-antd/radio'), require('ng-zorro-antd/rate'), require('ng-zorro-antd/select'), require('ng-zorro-antd/slider'), require('ng-zorro-antd/switch'), require('ng-zorro-antd/tag'), require('ng-zorro-antd/time-picker'), require('ng-zorro-antd/tooltip'), require('ng-zorro-antd/transfer'), require('ng-zorro-antd/tree-select'), require('ng-zorro-antd/upload'), require('ng-zorro-antd/core/animation'), require('date-fns/format'), require('date-fns/parse')) : typeof define === 'function' && define.amd ? define('@lxlib/form', ['exports', '@angular/core', '@angular/platform-browser', '@lxlib/acl', '@lxlib/theme', '@lxlib/util', 'rxjs', 'rxjs/operators', '@angular/common', '@angular/forms', 'ng-zorro-antd/auto-complete', 'ng-zorro-antd/button', 'ng-zorro-antd/card', 'ng-zorro-antd/cascader', 'ng-zorro-antd/checkbox', 'ng-zorro-antd/date-picker', 'ng-zorro-antd/form', 'ng-zorro-antd/grid', 'ng-zorro-antd/icon', 'ng-zorro-antd/input', 'ng-zorro-antd/input-number', 'ng-zorro-antd/mention', 'ng-zorro-antd/modal', 'ng-zorro-antd/radio', 'ng-zorro-antd/rate', 'ng-zorro-antd/select', 'ng-zorro-antd/slider', 'ng-zorro-antd/switch', 'ng-zorro-antd/tag', 'ng-zorro-antd/time-picker', 'ng-zorro-antd/tooltip', 'ng-zorro-antd/transfer', 'ng-zorro-antd/tree-select', 'ng-zorro-antd/upload', 'ng-zorro-antd/core/animation', 'date-fns/format', 'date-fns/parse'], factory) : (global = global || self, factory((global.lxlib = global.lxlib || {}, global.lxlib.form = {}), global.ng.core, global.ng.platformBrowser, global.lxlib.acl, global.lxlib.theme, global.lxlib.util, global.rxjs, global.rxjs.operators, global.ng.common, global.ng.forms, global['ng-zorro-antd/auto-complete'], global['ng-zorro-antd/button'], global['ng-zorro-antd/card'], global['ng-zorro-antd/cascader'], global['ng-zorro-antd/checkbox'], global['ng-zorro-antd/date-picker'], global['ng-zorro-antd/form'], global['ng-zorro-antd/grid'], global['ng-zorro-antd/icon'], global['ng-zorro-antd/input'], global['ng-zorro-antd/input-number'], global['ng-zorro-antd/mention'], global['ng-zorro-antd/modal'], global['ng-zorro-antd/radio'], global['ng-zorro-antd/rate'], global['ng-zorro-antd/select'], global['ng-zorro-antd/slider'], global['ng-zorro-antd/switch'], global['ng-zorro-antd/tag'], global['ng-zorro-antd/time-picker'], global['ng-zorro-antd/tooltip'], global['ng-zorro-antd/transfer'], global['ng-zorro-antd/tree-select'], global['ng-zorro-antd/upload'], global.animation, global.format, global.parse)); }(this, (function (exports, core, platformBrowser, acl, theme, util, rxjs, operators, common, forms, autoComplete, button, card, cascader, checkbox, datePicker, form, grid, icon, input, inputNumber, mention, modal, radio, rate, select, slider, _switch, tag, timePicker, tooltip, transfer, treeSelect, upload, animation, format, parse) { 'use strict'; format = format && Object.prototype.hasOwnProperty.call(format, 'default') ? format['default'] : format; parse = parse && Object.prototype.hasOwnProperty.call(parse, 'default') ? parse['default'] : parse; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __param(paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __exportStar(m, exports) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } function __values(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } function __asyncGenerator(thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } } function __asyncDelegator(o) { var i, p; return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } } function __asyncValues(o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } } function __makeTemplateObject(cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result.default = mod; return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } function __classPrivateFieldGet(receiver, privateMap) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return privateMap.get(receiver); } function __classPrivateFieldSet(receiver, privateMap, value) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to set private field on non-instance"); } privateMap.set(receiver, value); return value; } /** * @fileoverview added by tsickle * Generated from: src/config.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var LxlibFormConfig = /** @class */ (function () { function LxlibFormConfig() { /** * 是否忽略某些数据类型校验 `ERRORSDEFAULT`,默认:`[ 'type', 'enum' ]` * * - `type` 限定 Schema 中 `type` 类型 * - `enum` 限定应当是预设定的枚举值之一 */ this.ingoreKeywords = ['type', 'enum']; /** * 是否实时校验,默认:`true` * - `true` 每一次都校验 * - `false` 提交时校验 */ this.liveValidate = true; /** * 指定表单 `autocomplete` 值,默认:`on` */ this.autocomplete = null; /** * 是否立即呈现错误视觉,默认:`false` */ this.firstVisual = false; /** * 是否只展示错误视觉不显示错误文本,默认:`false` */ this.onlyVisual = false; /** * 自定义通用错误信息 */ this.errors = {}; /** * 按钮风格 */ this.button = { submit_type: 'primary', reset_type: 'default', }; /** * date小部件:`type="string"` 且不指定 `schema.format` 和 `ui.format` 时日期格式,默认:`yyyy-MM-dd HH:mm:ss` */ this.uiDateStringFormat = 'yyyy-MM-dd HH:mm:ss'; /** * date小部件:`type="number"` 且不指定 `schema.format` 和 `ui.format` 时日期格式,默认:`x` 13位Unix Timestamp */ this.uiDateNumberFormat = 'x'; /** * time小部件:`type="string"` 且不指定 `schema.format` 和 `ui.format` 时日期格式,默认:`HH:mm:ss` */ this.uiTimeStringFormat = 'HH:mm:ss'; /** * time小部件:`type="number"` 且不指定 `schema.format` 和 `ui.format` 时日期格式,默认:`x` 13位Unix Timestamp,日期统一使用 `1970-01-01` */ this.uiTimeNumberFormat = 'x'; /** * 指定 `format: 'email'` 的默认Email后缀 */ this.uiEmailSuffixes = ['qq.com', '163.com', 'gmail.com', '126.com', 'aliyun.com']; } LxlibFormConfig.decorators = [ { type: core.Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ LxlibFormConfig.ɵprov = core.ɵɵdefineInjectable({ factory: function LxlibFormConfig_Factory() { return new LxlibFormConfig(); }, token: LxlibFormConfig, providedIn: "root" }); return LxlibFormConfig; }()); if (false) { /** * 是否忽略某些数据类型校验 `ERRORSDEFAULT`,默认:`[ 'type', 'enum' ]` * * - `type` 限定 Schema 中 `type` 类型 * - `enum` 限定应当是预设定的枚举值之一 * @type {?} */ LxlibFormConfig.prototype.ingoreKeywords; /** * [ajv](http://epoberezkin.github.io/ajv/#options) 参数 * @type {?} */ LxlibFormConfig.prototype.ajv; /** * 是否实时校验,默认:`true` * - `true` 每一次都校验 * - `false` 提交时校验 * @type {?} */ LxlibFormConfig.prototype.liveValidate; /** * 指定表单 `autocomplete` 值,默认:`on` * @type {?} */ LxlibFormConfig.prototype.autocomplete; /** * 是否立即呈现错误视觉,默认:`false` * @type {?} */ LxlibFormConfig.prototype.firstVisual; /** * 是否只展示错误视觉不显示错误文本,默认:`false` * @type {?} */ LxlibFormConfig.prototype.onlyVisual; /** * 自定义通用错误信息 * @type {?} */ LxlibFormConfig.prototype.errors; /** * 默认全局布局 * @type {?} */ LxlibFormConfig.prototype.ui; /** * 元素组件大小,用于 `nzSize` 值 * @type {?} */ LxlibFormConfig.prototype.size; /** * 按钮风格 * @type {?} */ LxlibFormConfig.prototype.button; /** * date小部件:`type="string"` 且不指定 `schema.format` 和 `ui.format` 时日期格式,默认:`yyyy-MM-dd HH:mm:ss` * @type {?} */ LxlibFormConfig.prototype.uiDateStringFormat; /** * date小部件:`type="number"` 且不指定 `schema.format` 和 `ui.format` 时日期格式,默认:`x` 13位Unix Timestamp * @type {?} */ LxlibFormConfig.prototype.uiDateNumberFormat; /** * time小部件:`type="string"` 且不指定 `schema.format` 和 `ui.format` 时日期格式,默认:`HH:mm:ss` * @type {?} */ LxlibFormConfig.prototype.uiTimeStringFormat; /** * time小部件:`type="number"` 且不指定 `schema.format` 和 `ui.format` 时日期格式,默认:`x` 13位Unix Timestamp,日期统一使用 `1970-01-01` * @type {?} */ LxlibFormConfig.prototype.uiTimeNumberFormat; /** * 指定 `format: 'email'` 的默认Email后缀 * @type {?} */ LxlibFormConfig.prototype.uiEmailSuffixes; } /** * @fileoverview added by tsickle * Generated from: src/const.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var SF_SEQ = '/'; /** * @fileoverview added by tsickle * Generated from: src/utils.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var FORMATMAPS = { 'date-time': { widget: 'date', showTime: true, format: 'yyyy-MM-ddTHH:mm:ssZ', }, date: { widget: 'date', format: 'yyyy-MM-dd' }, 'full-date': { widget: 'date', format: 'yyyy-MM-dd' }, time: { widget: 'time' }, 'full-time': { widget: 'time' }, week: { widget: 'date', mode: 'week', format: 'yyyy-WW' }, month: { widget: 'date', mode: 'month', format: 'yyyy-MM' }, uri: { widget: 'upload' }, email: { widget: 'autocomplete', type: 'email' }, color: { widget: 'string', type: 'color' }, '': { widget: 'string' }, }; /** * @param {?} o * @return {?} */ function isBlank(o) { return o == null; } /** * @param {?} value * @param {?} defaultValue * @return {?} */ function toBool(value, defaultValue) { value = util.toBoolean(value, true); return value == null ? defaultValue : value; } /** * @param {?} ui * @param {...?} args * @return {?} */ function di(ui) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } if (ui.debug) { // tslint:disable-next-line:no-console console.warn.apply(console, __spread(args)); } } /** * 根据 `$ref` 查找 `definitions` * @param {?} $ref * @param {?} definitions * @return {?} */ function findSchemaDefinition($ref, definitions) { var e_1, _a; /** @type {?} */ var match = /^#\/definitions\/(.*)$/.exec($ref); if (match && match[1]) { // parser JSON Pointer /** @type {?} */ var parts = match[1].split(SF_SEQ); /** @type {?} */ var current = definitions; try { for (var parts_1 = __values(parts), parts_1_1 = parts_1.next(); !parts_1_1.done; parts_1_1 = parts_1.next()) { var part = parts_1_1.value; part = part.replace(/~1/g, SF_SEQ).replace(/~0/g, '~'); if (current.hasOwnProperty(part)) { current = current[part]; } else { throw new Error("Could not find a definition for " + $ref + "."); } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (parts_1_1 && !parts_1_1.done && (_a = parts_1.return)) _a.call(parts_1); } finally { if (e_1) throw e_1.error; } } return current; } throw new Error("Could not find a definition for " + $ref + "."); } /** * 取回Schema,并处理 `$ref` 的关系 * @param {?} schema * @param {?=} definitions * @return {?} */ function retrieveSchema(schema, definitions) { if (definitions === void 0) { definitions = {}; } if (schema.hasOwnProperty('$ref')) { /** @type {?} */ var $refSchema = findSchemaDefinition((/** @type {?} */ (schema.$ref)), definitions); // remove $ref property var $ref = schema.$ref, localSchema = __rest(schema, ["$ref"]); return retrieveSchema(__assign(__assign({}, $refSchema), localSchema), definitions); } return schema; } /** * @param {?} schema * @param {?} ui * @return {?} */ function resolveIf(schema, ui) { if (!(schema.hasOwnProperty('if') && schema.hasOwnProperty('then'))) return null; if (!(/** @type {?} */ (schema.if)).properties) throw new Error("if: does not contain 'properties'"); /** @type {?} */ var allKeys = Object.keys((/** @type {?} */ (schema.properties))); /** @type {?} */ var ifKeys = Object.keys((/** @type {?} */ ((/** @type {?} */ (schema.if)).properties))); detectKey(allKeys, ifKeys); detectKey(allKeys, (/** @type {?} */ ((/** @type {?} */ (schema.then)).required))); schema.required = (/** @type {?} */ (schema.required)).concat((/** @type {?} */ ((/** @type {?} */ (schema.then)).required))); /** @type {?} */ var hasElse = schema.hasOwnProperty('else'); if (hasElse) { detectKey(allKeys, (/** @type {?} */ ((/** @type {?} */ (schema.else)).required))); schema.required = schema.required.concat((/** @type {?} */ ((/** @type {?} */ (schema.else)).required))); } /** @type {?} */ var visibleIf = {}; /** @type {?} */ var visibleElse = {}; ifKeys.forEach((/** * @param {?} key * @return {?} */ function (key) { /** @type {?} */ var cond = (/** @type {?} */ ((/** @type {?} */ (schema.if)).properties))[key].enum; visibleIf[key] = cond; if (hasElse) visibleElse[key] = (/** * @param {?} value * @return {?} */ function (value) { return !(/** @type {?} */ (cond)).includes(value); }); })); (/** @type {?} */ ((/** @type {?} */ (schema.then)).required)).forEach((/** * @param {?} key * @return {?} */ function (key) { return (ui["$" + key].visibleIf = visibleIf); })); if (hasElse) (/** @type {?} */ ((/** @type {?} */ (schema.else)).required)).forEach((/** * @param {?} key * @return {?} */ function (key) { return (ui["$" + key].visibleIf = visibleElse); })); return schema; } /** * @param {?} keys * @param {?} detectKeys * @return {?} */ function detectKey(keys, detectKeys) { detectKeys.forEach((/** * @param {?} key * @return {?} */ function (key) { if (!keys.includes(key)) { throw new Error("if: properties does not contain '" + key + "'"); } })); } /** * @param {?} properties * @param {?} order * @return {?} */ function orderProperties(properties, order) { if (!Array.isArray(order)) return properties; /** @type {?} */ var arrayToHash = (/** * @param {?} arr * @return {?} */ function (arr) { return arr.reduce((/** * @param {?} prev * @param {?} curr * @return {?} */ function (prev, curr) { prev[curr] = true; return prev; }), {}); }); /** @type {?} */ var errorPropList = (/** * @param {?} arr * @return {?} */ function (arr) { return "property [" + arr.join("', '") + "]"; }); /** @type {?} */ var propertyHash = arrayToHash(properties); /** @type {?} */ var orderHash = arrayToHash(order); /** @type {?} */ var extraneous = order.filter((/** * @param {?} prop * @return {?} */ function (prop) { return prop !== '*' && !propertyHash[prop]; })); if (extraneous.length) { throw new Error("ui schema order list contains extraneous " + errorPropList(extraneous)); } /** @type {?} */ var rest = properties.filter((/** * @param {?} prop * @return {?} */ function (prop) { return !orderHash[prop]; })); /** @type {?} */ var restIndex = order.indexOf('*'); if (restIndex === -1) { if (rest.length) { throw new Error("ui schema order list does not contain " + errorPropList(rest)); } return order; } if (restIndex !== order.lastIndexOf('*')) { throw new Error('ui schema order list contains more than one wildcard item'); } /** @type {?} */ var complete = __spread(order); complete.splice.apply(complete, __spread([restIndex, 1], rest)); return complete; } /** * @param {?} list * @param {?} formData * @param {?} readOnly * @return {?} */ function getEnum(list, formData, readOnly) { if (isBlank(list) || !Array.isArray(list) || list.length === 0) return []; if (typeof list[0] !== 'object') { list = list.map((/** * @param {?} item * @return {?} */ function (item) { return (/** @type {?} */ ({ label: item, value: item })); })); } if (formData) { if (!Array.isArray(formData)) formData = [formData]; list.forEach((/** * @param {?} item * @return {?} */ function (item) { if (~formData.indexOf(item.value)) item.checked = true; })); } // fix disabled status if (readOnly) { list.forEach((/** * @param {?} item * @return {?} */ function (item) { return (item.disabled = true); })); } return list; } /** * @param {?} list * @param {?} formData * @param {?} readOnly * @return {?} */ function getCopyEnum(list, formData, readOnly) { return getEnum(util.deepCopy(list || []), formData, readOnly); } /** * @param {?} schema * @param {?} ui * @param {?} formData * @param {?=} asyncArgs * @return {?} */ function getData(schema, ui, formData, asyncArgs) { if (typeof ui.asyncData === 'function') { return ui.asyncData(asyncArgs).pipe(operators.map((/** * @param {?} list * @return {?} */ function (list) { return getEnum(list, formData, (/** @type {?} */ (schema.readOnly))); }))); } return rxjs.of(getCopyEnum((/** @type {?} */ (schema.enum)), formData, (/** @type {?} */ (schema.readOnly)))); } /** * Whether to using date-fns to format a date * @param {?} srv * @return {?} */ function isDateFns(srv) { if (!srv) return false; /** @type {?} */ var data = srv.getDateLocale(); // Compatible date-fns v1.x & v2.x return data != null && !!data.formatDistance; // (!!data.distanceInWords || !!data.formatDistance); } /** * @fileoverview added by tsickle * Generated from: src/model/form.property.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @abstract */ var /** * @abstract */ FormProperty = /** @class */ (function () { function FormProperty(schemaValidatorFactory, schema, ui, formData, parent, path, _options) { this._options = _options; this._errors = null; this._valueChanges = new rxjs.BehaviorSubject(null); this._errorsChanges = new rxjs.BehaviorSubject(null); this._visible = true; this._visibilityChanges = new rxjs.BehaviorSubject(true); this._objErrors = {}; this._value = null; this.schema = schema; this.ui = ui; this.schemaValidator = schemaValidatorFactory.createValidatorFn(schema, { ingoreKeywords: (/** @type {?} */ (this.ui.ingoreKeywords)), debug: (/** @type {?} */ ((/** @type {?} */ (((/** @type {?} */ (ui))))).debug)), }); this.formData = formData || schema.default; this._parent = parent; if (parent) { this._root = parent.root; } else { this._root = (/** @type {?} */ (this)); } this.path = path; } Object.defineProperty(FormProperty.prototype, "valueChanges", { get: /** * @return {?} */ function () { return this._valueChanges; }, enumerable: true, configurable: true }); Object.defineProperty(FormProperty.prototype, "errorsChanges", { get: /** * @return {?} */ function () { return this._errorsChanges; }, enumerable: true, configurable: true }); Object.defineProperty(FormProperty.prototype, "type", { get: /** * @return {?} */ function () { return (/** @type {?} */ (this.schema.type)); }, enumerable: true, configurable: true }); Object.defineProperty(FormProperty.prototype, "parent", { get: /** * @return {?} */ function () { return this._parent; }, enumerable: true, configurable: true }); Object.defineProperty(FormProperty.prototype, "root", { get: /** * @return {?} */ function () { return this._root; }, enumerable: true, configurable: true }); Object.defineProperty(FormProperty.prototype, "value", { get: /** * @return {?} */ function () { return this._value; }, enumerable: true, configurable: true }); Object.defineProperty(FormProperty.prototype, "errors", { get: /** * @return {?} */ function () { return this._errors; }, enumerable: true, configurable: true }); Object.defineProperty(FormProperty.prototype, "visible", { get: /** * @return {?} */ function () { return this._visible; }, enumerable: true, configurable: true }); Object.defineProperty(FormProperty.prototype, "valid", { get: /** * @return {?} */ function () { return this._errors === null || this._errors.length === 0; }, enumerable: true, configurable: true }); Object.defineProperty(FormProperty.prototype, "options", { get: /** * @return {?} */ function () { return this._options; }, enumerable: true, configurable: true }); /** * 更新值且校验数据 * * @param [onlySelf=false] 是否包含上级字段 * @param [emitValueEvent=true] 是否触发值变更通知 */ /** * 更新值且校验数据 * * @param {?=} onlySelf * @param {?=} emitValueEvent * @param {?=} emitValidator * @return {?} */ FormProperty.prototype.updateValueAndValidity = /** * 更新值且校验数据 * * @param {?=} onlySelf * @param {?=} emitValueEvent * @param {?=} emitValidator * @return {?} */ function (onlySelf, emitValueEvent, emitValidator) { if (onlySelf === void 0) { onlySelf = false; } if (emitValueEvent === void 0) { emitValueEvent = true; } if (emitValidator === void 0) { emitValidator = true; } this._updateValue(); if (emitValueEvent) { this.valueChanges.next(this.value); } // `emitValidator` 每一次数据变更已经包含完整错误链路,后续父节点数据变更无须再触发校验 if (emitValidator && this.ui.liveValidate === true) { this._runValidation(); } if (this.parent && !onlySelf) { this.parent.updateValueAndValidity(onlySelf, emitValueEvent, false); } }; /** 根据路径搜索表单属性 */ /** * 根据路径搜索表单属性 * @param {?} path * @return {?} */ FormProperty.prototype.searchProperty = /** * 根据路径搜索表单属性 * @param {?} path * @return {?} */ function (path) { /** @type {?} */ var prop = this; /** @type {?} */ var base = null; /** @type {?} */ var result = null; if (path[0] === SF_SEQ) { base = this.findRoot(); result = base.getProperty(path.substr(1)); } else { while (result === null && prop.parent !== null) { prop = base = prop.parent; result = base.getProperty(path); } } return (/** @type {?} */ (result)); }; /** 查找根表单属性 */ /** * 查找根表单属性 * @return {?} */ FormProperty.prototype.findRoot = /** * 查找根表单属性 * @return {?} */ function () { /** @type {?} */ var property = this; while (property.parent !== null) { property = property.parent; } return (/** @type {?} */ (property)); }; // #region process errors // #region process errors /** * @private * @param {?} value * @return {?} */ FormProperty.prototype.isEmptyData = // #region process errors /** * @private * @param {?} value * @return {?} */ function (value) { if (isBlank(value)) return true; switch (this.type) { case 'string': return ('' + value).length === 0; } return false; }; /** * @internal */ /** * \@internal * @return {?} */ FormProperty.prototype._runValidation = /** * \@internal * @return {?} */ function () { var _this = this; /** @type {?} */ var errors; // The definition of some rules: // 1. Should not ajv validator when is empty data and required fields // 2. Should not ajv validator when is empty data /** @type {?} */ var isEmpty = this.isEmptyData(this._value); if (isEmpty && this.ui._required) { errors = [{ keyword: 'required' }]; } else if (isEmpty) { errors = []; } else { errors = this.schemaValidator(this._value) || []; } /** @type {?} */ var customValidator = ((/** @type {?} */ (this.ui))).validator; if (typeof customValidator === 'function') { /** @type {?} */ var customErrors = customValidator(this.value, this, this.findRoot()); if (customErrors instanceof rxjs.Observable) { customErrors.subscribe((/** * @param {?} res * @return {?} */ function (res) { _this.setCustomErrors(errors, res); _this.widget.detectChanges(); })); return; } this.setCustomErrors(errors, customErrors); return; } this._errors = errors; this.setErrors(this._errors); }; /** * @private * @param {?} errors * @param {?} list * @return {?} */ FormProperty.prototype.setCustomErrors = /** * @private * @param {?} errors * @param {?} list * @return {?} */ function (errors, list) { // fix error format /** @type {?} */ var hasCustomError = list != null && list.length > 0; if (hasCustomError) { list.forEach((/** * @param {?} err * @return {?} */ function (err) { if (!err.message) { throw new Error("The custom validator must contain a 'message' attribute to viewed error text"); } err._custom = true; })); } this._errors = this.mergeErrors(errors, list); this.setErrors(this._errors); }; /** * @private * @param {?} errors * @param {?} newErrors * @return {?} */ FormProperty.prototype.mergeErrors = /** * @private * @param {?} errors * @param {?} newErrors * @return {?} */ function (errors, newErrors) { if (newErrors) { if (Array.isArray(newErrors)) { errors = errors.concat.apply(errors, __spread(newErrors)); } else { errors.push(newErrors); } } return errors; }; /** * @protected * @param {?} errors * @param {?=} emitFormat * @return {?} */ FormProperty.prototype.setErrors = /** * @protected * @param {?} errors * @param {?=} emitFormat * @return {?} */ function (errors, emitFormat) { var _this = this; if (emitFormat === void 0) { emitFormat = true; } if (emitFormat && errors && !this.ui.onlyVisual) { /** @type {?} */ var l_1 = (this.widget && this.widget.l.error) || {}; errors = errors.map((/** * @param {?} err * @return {?} */ function (err) { /** @type {?} */ var message = err._custom === true && err.message ? err.message : (_this.ui.errors || {})[err.keyword] || (/** @type {?} */ (_this._options.errors))[err.keyword] || l_1[err.keyword] || ""; if (message && typeof message === 'function') { message = (/** @type {?} */ (message(err))); } if (message) { if (~((/** @type {?} */ (message))).indexOf('{')) { message = ((/** @type {?} */ (message))).replace(/{([\.a-z0-9]+)}/g, (/** * @param {?} _v * @param {?} key * @return {?} */ function (_v, key) { return (/** @type {?} */ (err.params))[key] || ''; })); } err.message = (/** @type {?} */ (message)); } return err; })); } this._errors = errors; this._errorsChanges.next(errors); // Should send errors to parent field if (this._parent) { this._parent.setParentAndPlatErrors(errors, this.path); } }; /** * @param {?} errors * @param {?} path * @return {?} */ FormProperty.prototype.setParentAndPlatErrors = /** * @param {?} errors * @param {?} path * @return {?} */ function (errors, path) { var _this = this; this._objErrors[path] = errors; /** @type {?} */ var platErrors = []; Object.keys(this._objErrors).forEach((/** * @param {?} p * @return {?} */ function (p) { /** @type {?} */ var property = _this.searchProperty(p); if (property && !property.visible) return; platErrors.push.apply(platErrors, __spread(_this._objErrors[p])); })); this.setErrors(platErrors, false); }; // #endregion // #region condition // #endregion // #region condition /** * @private * @param {?} visible * @return {?} */ FormProperty.prototype.setVisible = // #endregion // #region condition /** * @private * @param {?} visible * @return {?} */ function (visible) { this._visible = visible; this._visibilityChanges.next(visible); // 部分数据源来自 reset this.resetValue(this.value, true); }; // A field is visible if AT LEAST ONE of the properties it depends on is visible AND has a value in the list // A field is visible if AT LEAST ONE of the properties it depends on is visible AND has a value in the list /** * @return {?} */ FormProperty.prototype._bindVisibility = // A field is visible if AT LEAST ONE of the properties it depends on is visible AND has a value in the list /** * @return {?} */ function () { var _this = this; /** @type {?} */ var visibleIf = ((/** @type {?} */ (this.ui))).visibleIf; if (typeof visibleIf === 'object' && Object.keys(visibleIf).length === 0) { this.setVisible(false); } else if (visibleIf !== undefined) { /** @type {?} */ var propertiesBinding = []; var _loop_1 = function (dependencyPath) { if (visibleIf.hasOwnProperty(dependencyPath)) { /** @type {?} */ var property = this_1.searchProperty(dependencyPath); if (property) { /** @type {?} */ var valueCheck = property.valueChanges.pipe(operators.map((/** * @param {?} value * @return {?} */ function (value) { /** @type {?} */ var vi = visibleIf[dependencyPath]; if (typeof vi === 'function') return vi(value); if (vi.indexOf('$ANY$') !== -1) { return value.length > 0; } else { return vi.indexOf(value) !== -1; } }))); /** @type {?} */ var visibilityCheck = property._visibilityChanges; /** @type {?} */ var and = rxjs.combineLatest([valueCheck, visibilityCheck]).pipe(operators.map((/** * @param {?} results * @return {?} */ function (results) { return results[0] && results[1]; }))); propertiesBinding.push(and); } else { console.warn("Can't find property " + dependencyPath + " for visibility check of " + this_1.path); } } }; var this_1 = this; for (var dependencyPath in visibleIf) { _loop_1(dependencyPath); } rxjs.combineLatest(propertiesBinding) .pipe(operators.map((/** * @param {?} values * @return {?} */ function (values) { return values.indexOf(true) !== -1; })), operators.distinctUntilChanged()) .subscribe((/** * @param {?} visible * @return {?} */ function (visible) { return _this.setVisible(visible); })); } }; return FormProperty; }()); if (false) { /** * @type {?} * @private */ FormProperty.prototype._errors; /** * @type {?} * @private */ FormProperty.prototype._valueChanges; /** * @type {?} * @private */ FormProperty.prototype._errorsChanges; /** * @type {?} * @private */ FormProperty.prototype._visible; /** * @type {?} * @private */ FormProperty.prototype._visibilityChanges; /** * @type {?} * @private */ FormProperty.prototype._root; /** * @type {?} * @private */ FormProperty.prototype._parent; /** @type {?} */ FormProperty.prototype._objErrors; /** @type {?} */ FormProperty.pro