@ohayojp/form
Version:
1,218 lines (1,208 loc) • 261 kB
JavaScript
/**
* @license ohayojp(cipchk@qq.com) v1.0.2
* (c) 2020 cipchk https://ohayojp.com/
* License: MIT
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/cdk/platform'), require('@angular/core'), require('@angular/platform-browser'), require('@ohayojp/acl'), require('@ohayojp/theme'), require('@ohayojp/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')) :
typeof define === 'function' && define.amd ? define('@ohayojp/form', ['exports', '@angular/cdk/platform', '@angular/core', '@angular/platform-browser', '@ohayojp/acl', '@ohayojp/theme', '@ohayojp/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'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ohayojp = global.ohayojp || {}, global.ohayojp.form = {}), global.ng.cdk.platform, global.ng.core, global.ng.platformBrowser, global.ohayo.acl, global.ohayo.theme, global.ohayo.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['ng-zorro-antd/core/animation'], global.format));
}(this, (function (exports, platform, 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) { 'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var format__default = /*#__PURE__*/_interopDefaultLegacy(format);
/**
* @fileoverview added by tsickle
* Generated from: src/config.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var SF_DEFAULT_CONFIG = {
formatMap: {
'date-time': {
widget: 'date',
showTime: true,
format: "yyyy-MM-dd'T'HH:mm:ss.SSSxxx",
},
date: { widget: 'date', format: 'yyyy-MM-dd' },
'full-date': { widget: 'date', format: 'yyyy-MM-dd' },
time: { widget: 'time', format: 'HH:mm:ss.SSSxxx' },
'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' },
},
ingoreKeywords: ['type', 'enum'],
liveValidate: true,
autocomplete: null,
firstVisual: false,
onlyVisual: false,
errors: {},
ui: ( /** @type {?} */({})),
button: ( /** @type {?} */({ submit_type: 'primary', reset_type: 'default' })),
uiDateStringFormat: 'yyyy-MM-dd HH:mm:ss',
uiDateNumberFormat: 'T',
uiTimeStringFormat: 'HH:mm:ss',
uiTimeNumberFormat: 'T',
uiEmailSuffixes: ['qq.com', '163.com', 'gmail.com', '126.com', 'aliyun.com'],
};
/**
* @param {?} srv
* @return {?}
*/
function mergeConfig(srv) {
return ( /** @type {?} */(srv.merge('sf', SF_DEFAULT_CONFIG)));
}
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* 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 (Object.prototype.hasOwnProperty.call(b, 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 };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, 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;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, 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/const.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var SF_SEQ = '/';
/**
* @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(Object.assign(Object.assign({}, $refSchema), localSchema), definitions);
}
return schema;
}
/**
* @param {?} _schema
* @param {?} _ui
* @return {?}
*/
function resolveIfSchema(_schema, _ui) {
/** @type {?} */
var fn = ( /**
* @param {?} schema
* @param {?} ui
* @return {?}
*/function (schema, ui) {
resolveIf(schema, ui);
Object.keys(( /** @type {?} */(schema.properties))).forEach(( /**
* @param {?} key
* @return {?}
*/function (/**
* @param {?} key
* @return {?}
*/ key) {
/** @type {?} */
var property = ( /** @type {?} */(schema.properties))[key];
/** @type {?} */
var uiKey = "$" + key;
if (property.items) {
fn(property.items, ui[uiKey].$items);
}
if (property.properties) {
fn(property, ui[uiKey]);
}
}));
});
fn(_schema, _ui);
}
/**
* @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 (/**
* @param {?} key
* @return {?}
*/ 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 (/**
* @param {?} key
* @return {?}
*/ key) { return (ui["$" + key].visibleIf = visibleIf); }));
if (hasElse) {
( /** @type {?} */(( /** @type {?} */(schema.else)).required)).forEach(( /**
* @param {?} key
* @return {?}
*/function (/**
* @param {?} key
* @return {?}
*/ key) { return (ui["$" + key].visibleIf = visibleElse); }));
}
return schema;
}
/**
* @param {?} keys
* @param {?} detectKeys
* @return {?}
*/
function detectKey(keys, detectKeys) {
detectKeys.forEach(( /**
* @param {?} key
* @return {?}
*/function (/**
* @param {?} key
* @return {?}
*/ 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 (/**
* @param {?} prop
* @return {?}
*/ 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 (/**
* @param {?} prop
* @return {?}
*/ 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);
}
/**
* @abstract
*/
var FormProperty = /** @class */ (function () {
/**
* @param {?} schemaValidatorFactory
* @param {?} schema
* @param {?} ui
* @param {?} formData
* @param {?} parent
* @param {?} path
* @param {?} _options
*/
function FormProperty(schemaValidatorFactory, schema, ui, formData, parent, path, _options) {
this._options = _options;
this._errors = null;
this._valueChanges = new rxjs.BehaviorSubject({ path: null, pathValue: null, value: 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", {
/**
* @return {?}
*/
get: function () {
return this._valueChanges;
},
enumerable: false,
configurable: true
});
Object.defineProperty(FormProperty.prototype, "errorsChanges", {
/**
* @return {?}
*/
get: function () {
return this._errorsChanges;
},
enumerable: false,
configurable: true
});
Object.defineProperty(FormProperty.prototype, "type", {
/**
* @return {?}
*/
get: function () {
return ( /** @type {?} */(this.schema.type));
},
enumerable: false,
configurable: true
});
Object.defineProperty(FormProperty.prototype, "parent", {
/**
* @return {?}
*/
get: function () {
return this._parent;
},
enumerable: false,
configurable: true
});
Object.defineProperty(FormProperty.prototype, "root", {
/**
* @return {?}
*/
get: function () {
return this._root;
},
enumerable: false,
configurable: true
});
Object.defineProperty(FormProperty.prototype, "value", {
/**
* @return {?}
*/
get: function () {
return this._value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(FormProperty.prototype, "errors", {
/**
* @return {?}
*/
get: function () {
return this._errors;
},
enumerable: false,
configurable: true
});
Object.defineProperty(FormProperty.prototype, "visible", {
/**
* @return {?}
*/
get: function () {
return this._visible;
},
enumerable: false,
configurable: true
});
Object.defineProperty(FormProperty.prototype, "valid", {
/**
* @return {?}
*/
get: function () {
return this._errors === null || this._errors.length === 0;
},
enumerable: false,
configurable: true
});
Object.defineProperty(FormProperty.prototype, "options", {
/**
* @return {?}
*/
get: function () {
return this._options;
},
enumerable: false,
configurable: true
});
/**
* 更新值且校验数据
* @param {?=} options
* @return {?}
*/
FormProperty.prototype.updateValueAndValidity = function (options) {
options = Object.assign({ onlySelf: false, emitValidator: true, emitValueEvent: true, updatePath: '', updateValue: null }, options);
this._updateValue();
if (options.emitValueEvent) {
options.updatePath = options.updatePath || this.path;
options.updateValue = options.updateValue || this.value;
this.valueChanges.next({ value: this.value, path: options.updatePath, pathValue: options.updateValue });
}
// `emitValidator` 每一次数据变更已经包含完整错误链路,后续父节点数据变更无须再触发校验
if (options.emitValidator && this.ui.liveValidate === true) {
this._runValidation();
}
if (this.parent && !options.onlySelf) {
this.parent.updateValueAndValidity(Object.assign(Object.assign({}, options), { emitValidator: false }));
}
};
/**
* 根据路径搜索表单属性
* @param {?} path
* @return {?}
*/
FormProperty.prototype.searchProperty = 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 = function () {
/** @type {?} */
var property = this;
while (property.parent !== null) {
property = property.parent;
}
return ( /** @type {?} */(property));
};
// #region process errors
/**
* @private
* @param {?} value
* @return {?}
*/
FormProperty.prototype.isEmptyData = function (value) {
if (isBlank(value))
return true;
switch (this.type) {
case 'string':
return ('' + value).length === 0;
}
return false;
};
/**
* \@internal
* @return {?}
*/
FormProperty.prototype._runValidation = 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 (/**
* @param {?} res
* @return {?}
*/ 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 = function (errors, list) {
// fix error format
/** @type {?} */
var hasCustomError = list != null && list.length > 0;
if (hasCustomError) {
list.forEach(( /**
* @param {?} err
* @return {?}
*/function (/**
* @param {?} err
* @return {?}
*/ 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 = 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 = 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 = function (errors, path) {
var _this = this;
this._objErrors[path] = errors;
/** @type {?} */
var platErrors = [];
Object.keys(this._objErrors).forEach(( /**
* @param {?} p
* @return {?}
*/function (/**
* @param {?} p
* @return {?}
*/ 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
/**
* @private
* @param {?} visible
* @return {?}
*/
FormProperty.prototype.setVisible = function (visible) {
var _a, _b;
this._visible = visible;
this._visibilityChanges.next(visible);
// 部分数据源来自 reset
if (((_b = (_a = this.root.widget) === null || _a === void 0 ? void 0 : _a.sfComp) === null || _b === void 0 ? void 0 : _b._inited) === true) {
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
/**
* @return {?}
*/
FormProperty.prototype._bindVisibility = 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 {?} res
* @return {?}
*/function (/**
* @param {?} res
* @return {?}
*/ res) {
/** @type {?} */
var vi = visibleIf[dependencyPath];
if (typeof vi === 'function') {
return vi(res.value);
}
if (vi.indexOf('$ANY$') !== -1) {
return res.value.length > 0;
}
else {
return vi.indexOf(res.value) !== -1;
}
})));
/** @type {?} */
var visibilityCheck = property._visibilityChanges;
/** @type {?} */
var and = rxjs.combineLatest([valueCheck, visibilityCheck]).pipe(operators.map(( /**
* @param {?} results
* @return {?}
*/function (/**
* @param {?} results
* @return {?}
*/ 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 (/**
* @param {?} values
* @return {?}
*/ values) { return values.indexOf(true) !== -1; })), operators.distinctUntilChanged())
.subscribe(( /**
* @param {?} visible
* @return {?}
*/function (/**
* @param {?} visible
* @return {?}
*/ 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.prototype.schemaValidator;
/** @type {?} */
FormProperty.prototype.schema;
/** @type {?} */
FormProperty.prototype.ui;