UNPKG

@ohayojp.com/components

Version:

Common business components of ohayojp.

23 lines (21 loc) 15 kB
/** * @license ohayojp(cipchk@qq.com) v1.0.0 * (c) 2020 cipchk https://ohayojp.com/ * License: MIT */ !function (t, e) { "object" == typeof exports && "undefined" != typeof module ? e(exports, require("@angular/core"), require("@ohayojp.com/util"), require("rxjs"), require("rxjs/operators"), require("@angular/forms"), require("@ohayojp.com/theme"), require("ng-zorro-antd/core/animation"), require("@angular/common"), require("ng-zorro-antd/core/outlet"), require("ng-zorro-antd/icon"), require("ng-zorro-antd/tooltip")) : "function" == typeof define && define.amd ? define("@ohayojp.com/components/se", ["exports", "@angular/core", "@ohayojp.com/util", "rxjs", "rxjs/operators", "@angular/forms", "@ohayojp.com/theme", "ng-zorro-antd/core/animation", "@angular/common", "ng-zorro-antd/core/outlet", "ng-zorro-antd/icon", "ng-zorro-antd/tooltip"], e) : e(((t = "undefined" != typeof globalThis ? globalThis : t || self).ohayo = t.ohayo || {}, t.ohayo.components = t.ohayo.components || {}, t.ohayo.components.se = {}), t.ng.core, t.ohayo.util, t.rxjs, t.rxjs.operators, t.ng.forms, t.ohayo.theme, t.animation, t.ng.common, t["ng-zorro-antd/core/outlet"], t["ng-zorro-antd/icon"], t["ng-zorro-antd/tooltip"]) }(this, (function (t, e, n, o, r, i, a, l, s, p, u, c) { "use strict"; /*! ***************************************************************************** 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. ***************************************************************************** */function d(t, e, n, o) { var r, i = arguments.length, a = i < 3 ? e : null === o ? o = Object.getOwnPropertyDescriptor(e, n) : o; if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(t, e, n, o); else for (var l = t.length - 1; l >= 0; l--)(r = t[l]) && (a = (i < 3 ? r(a) : i > 3 ? r(e, n, a) : r(e, n)) || a); return i > 3 && a && Object.defineProperty(e, n, a), a } function h(t, e) { if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(t, e) } Object.create; function f(t) { var e = "function" == typeof Symbol && Symbol.iterator, n = e && t[e], o = 0; if (n) return n.call(t); if (t && "number" == typeof t.length) return { next: function () { return t && o >= t.length && (t = void 0), { value: t && t[o++], done: !t } } }; throw new TypeError(e ? "Object is not iterable." : "Symbol.iterator is not defined.") } function y(t, e) { var n = "function" == typeof Symbol && t[Symbol.iterator]; if (!n) return t; var o, r, i = n.call(t), a = []; try { for (; (void 0 === e || e-- > 0) && !(o = i.next()).done;)a.push(o.value) } catch (t) { r = { error: t } } finally { try { o && !o.done && (n = i.return) && n.call(i) } finally { if (r) throw r.error } } return a } function g() { for (var t = [], e = 0; e < arguments.length; e++)t = t.concat(y(arguments[e])); return t } Object.create; var m = function () { function t(t) { this.errorNotify$ = new o.BehaviorSubject(null), this.line = !1, t.attach(this, "se", { size: "default", nzLayout: "horizontal", gutter: 32, col: 2, labelWidth: 150, firstVisual: !1, ingoreDirty: !1 }) } return Object.defineProperty(t.prototype, "gutter", { get: function () { return "horizontal" === this.nzLayout ? this._gutter : 0 }, set: function (t) { this._gutter = n.toNumber(t) }, enumerable: !1, configurable: !0 }), Object.defineProperty(t.prototype, "nzLayout", { get: function () { return this._nzLayout }, set: function (t) { this._nzLayout = t, "inline" === t && (this.size = "compact") }, enumerable: !1, configurable: !0 }), Object.defineProperty(t.prototype, "errors", { set: function (t) { this.setErrors(t) }, enumerable: !1, configurable: !0 }), Object.defineProperty(t.prototype, "errorNotify", { get: function () { return this.errorNotify$.pipe(r.filter((function (t) { return null != t }))) }, enumerable: !1, configurable: !0 }), t.prototype.setErrors = function (t) { var e, n; try { for (var o = f(t), r = o.next(); !r.done; r = o.next()) { var i = r.value; this.errorNotify$.next(i) } } catch (t) { e = { error: t } } finally { try { r && !r.done && (n = o.return) && n.call(o) } finally { if (e) throw e.error } } }, t }(); m.decorators = [{ type: e.Component, args: [{ selector: "se-container, [se-container]", exportAs: "seContainer", template: '\n <div se-title *ngIf="title">\n <ng-container *nzStringTemplateOutlet="title">{{ title }}</ng-container>\n </div>\n <ng-content></ng-content>\n ', host: { "[class.ant-row]": "true", "[class.se__container]": "true", "[class.se__horizontal]": "nzLayout === 'horizontal'", "[class.se__vertical]": "nzLayout === 'vertical'", "[class.se__inline]": "nzLayout === 'inline'", "[class.se__compact]": "size === 'compact'", "[style.margin-left.px]": "-(gutter / 2)", "[style.margin-right.px]": "-(gutter / 2)" }, preserveWhitespaces: !1, changeDetection: e.ChangeDetectionStrategy.OnPush, encapsulation: e.ViewEncapsulation.None }] }], m.ctorParameters = function () { return [{ type: n.OhayoConfigService }] }, m.propDecorators = { colInCon: [{ type: e.Input, args: ["se-container"] }], col: [{ type: e.Input }], labelWidth: [{ type: e.Input }], title: [{ type: e.Input }], gutter: [{ type: e.Input }], nzLayout: [{ type: e.Input }], size: [{ type: e.Input }], firstVisual: [{ type: e.Input }], ingoreDirty: [{ type: e.Input }], line: [{ type: e.Input }], errors: [{ type: e.Input }] }, d([n.InputNumber(null), h("design:type", Number)], m.prototype, "colInCon", void 0), d([n.InputNumber(null), h("design:type", Number)], m.prototype, "col", void 0), d([n.InputNumber(null), h("design:type", Number)], m.prototype, "labelWidth", void 0), d([n.InputBoolean(), h("design:type", Boolean)], m.prototype, "firstVisual", void 0), d([n.InputBoolean(), h("design:type", Boolean)], m.prototype, "ingoreDirty", void 0), d([n.InputBoolean(), h("design:type", Object)], m.prototype, "line", void 0); var b = function () { function t(t, e, n) { if (this.parent = t, this.ren = n, null == t) throw new Error("[se-title] must include 'se-container' component"); this.el = e.nativeElement } return t.prototype.setClass = function () { var t = this.parent.gutter, e = this.el; this.ren.setStyle(e, "padding-left", t / 2 + "px"), this.ren.setStyle(e, "padding-right", t / 2 + "px") }, t.prototype.ngOnInit = function () { this.setClass() }, t }(); b.decorators = [{ type: e.Component, args: [{ selector: "se-title, [se-title]", exportAs: "seTitle", template: "<ng-content></ng-content>", host: { "[class.se__title]": "true" }, preserveWhitespaces: !1, changeDetection: e.ChangeDetectionStrategy.OnPush, encapsulation: e.ViewEncapsulation.None }] }], b.ctorParameters = function () { return [{ type: m, decorators: [{ type: e.Host }, { type: e.Optional }] }, { type: e.ElementRef }, { type: e.Renderer2 }] }; var v = 0, C = function () { function t(t, e, n, i, a) { var l = this; if (this.parent = e, this.rep = n, this.ren = i, this.cdr = a, this.unsubscribe$ = new o.Subject, this.clsMap = [], this.inited = !1, this.onceFlag = !1, this.errorData = {}, this.isBindModel = !1, this.invalid = !1, this._labelWidth = null, this.required = !1, this.controlClass = "", this._id = "_se-" + ++v, this._autoId = !0, null == e) throw new Error("[se] must include 'se-container' component"); this.el = t.nativeElement, e.errorNotify.pipe(r.takeUntil(this.unsubscribe$), r.filter((function (t) { return l.inited && null != l.ngControl && l.ngControl.name === t.name }))).subscribe((function (t) { l.error = t.error, l.updateStatus(l.ngControl.invalid) })) } return Object.defineProperty(t.prototype, "error", { set: function (t) { this.errorData = "string" == typeof t || t instanceof e.TemplateRef ? { "": t } : t }, enumerable: !1, configurable: !0 }), Object.defineProperty(t.prototype, "id", { set: function (t) { this._id = t, this._autoId = !1 }, enumerable: !1, configurable: !0 }), Object.defineProperty(t.prototype, "paddingValue", { get: function () { return this.parent.gutter / 2 }, enumerable: !1, configurable: !0 }), Object.defineProperty(t.prototype, "showErr", { get: function () { return this.invalid && !!this._error && !this.compact }, enumerable: !1, configurable: !0 }), Object.defineProperty(t.prototype, "compact", { get: function () { return "compact" === this.parent.size }, enumerable: !1, configurable: !0 }), Object.defineProperty(t.prototype, "ngControl", { get: function () { return this.ngModel || this.formControlName }, enumerable: !1, configurable: !0 }), t.prototype.setClass = function () { var t = this, e = t.el, n = t.ren, o = t.clsMap, r = t.col, i = t.parent, a = t.cdr, l = t.line, s = t.labelWidth, p = t.rep; this._labelWidth = "horizontal" === i.nzLayout ? null != s ? s : i.labelWidth : null, o.forEach((function (t) { return n.removeClass(e, t) })), o.length = 0; var u = "horizontal" === i.nzLayout ? p.genCls(null != r ? r : i.colInCon || i.col) : []; return o.push.apply(o, g(["ant-form-item"], u, ["se__item"])), (l || i.line) && o.push("se__line"), o.forEach((function (t) { return n.addClass(e, t) })), a.detectChanges(), this }, t.prototype.bindModel = function () { var t, e, n = this; if (this.ngControl && !this.isBindModel) { if (this.isBindModel = !0, this.ngControl.statusChanges.pipe(r.takeUntil(this.unsubscribe$)).subscribe((function (t) { return n.updateStatus("INVALID" === t) })), this._autoId) { var o = this.ngControl.valueAccessor, a = null === (t = (null == o ? void 0 : o.elementRef) || (null == o ? void 0 : o._elementRef)) || void 0 === t ? void 0 : t.nativeElement; a && (a.id ? this._id = a.id : a.id = this._id) } if (!0 !== this.required) { var l = null === (e = this.ngControl) || void 0 === e ? void 0 : e._rawValidators; this.required = null != l.find((function (t) { return t instanceof i.RequiredValidator })), this.cdr.detectChanges() } } }, t.prototype.updateStatus = function (t) { if (!this.ngControl.disabled && !this.ngControl.isDisabled) { this.invalid = !(!this.onceFlag && t && !1 === this.parent.ingoreDirty && !this.ngControl.dirty) && t; var e = this.ngControl.errors; if (null != e && Object.keys(e).length > 0) { var n = Object.keys(e)[0] || "", o = this.errorData[n]; this._error = null != o ? o : this.errorData[""] || "" } this.cdr.detectChanges() } }, t.prototype.checkContent = function () { var t = this.contentElement.nativeElement, e = "se__item-empty"; n.isEmpty(t) ? this.ren.addClass(t, e) : this.ren.removeClass(t, e) }, t.prototype.ngAfterContentInit = function () { this.checkContent() }, t.prototype.ngOnChanges = function () { this.onceFlag = this.parent.firstVisual, this.inited && this.setClass().bindModel() }, t.prototype.ngAfterViewInit = function () { var t = this; this.setClass().bindModel(), this.inited = !0, this.onceFlag && Promise.resolve().then((function () { t.updateStatus(t.ngControl.invalid), t.onceFlag = !1 })) }, t.prototype.ngOnDestroy = function () { var t = this.unsubscribe$; t.next(), t.complete() }, t }(); C.decorators = [{ type: e.Component, args: [{ selector: "se", exportAs: "se", template: '<div class="ant-form-item-label" [class.se__nolabel]="!label" [style.width.px]="_labelWidth">\n <label *ngIf="label" [attr.for]="_id" class="se__label" [ngClass]="{ \'ant-form-item-required\': required }">\n <span class="se__label-text">\n <ng-container *nzStringTemplateOutlet="label">{{ label }}</ng-container>\n </span>\n <span *ngIf="optional || optionalHelp" class="se__label-optional" [class.se__label-optional-no-text]="!optional">\n <ng-container *nzStringTemplateOutlet="optional">{{ optional }}</ng-container>\n <i *ngIf="optionalHelp" nz-tooltip [nzTooltipTitle]="optionalHelp" [nzTooltipColor]="optionalHelpColor" nz-icon nzType="question-circle"></i>\n </span>\n </label>\n</div>\n<div class="ant-form-item-control se__control">\n <div class="ant-form-item-control-input {{ controlClass }}">\n <div class="ant-form-item-control-input-content" (cdkObserveContent)="checkContent()" #contentElement>\n <ng-content></ng-content>\n </div>\n </div>\n <div class="ant-form-item-explain ant-form-item-explain-error" *ngIf="showErr">\n <div @helpMotion>\n <ng-container *nzStringTemplateOutlet="_error">{{ _error }}</ng-container>\n </div>\n </div>\n <div *ngIf="extra && !compact" class="ant-form-item-extra">\n <ng-container *nzStringTemplateOutlet="extra">{{ extra }}</ng-container>\n </div>\n</div>\n', host: { "[style.padding-left.px]": "paddingValue", "[style.padding-right.px]": "paddingValue", "[class.ant-form-item-has-error]": "invalid", "[class.ant-form-item-with-help]": "showErr" }, preserveWhitespaces: !1, animations: [l.helpMotion], changeDetection: e.ChangeDetectionStrategy.OnPush, encapsulation: e.ViewEncapsulation.None }] }], C.ctorParameters = function () { return [{ type: e.ElementRef }, { type: m, decorators: [{ type: e.Optional }, { type: e.Host }] }, { type: a.ResponsiveService }, { type: e.Renderer2 }, { type: e.ChangeDetectorRef }] }, C.propDecorators = { ngModel: [{ type: e.ContentChild, args: [i.NgModel, { static: !0 }] }], formControlName: [{ type: e.ContentChild, args: [i.FormControlName, { static: !0 }] }], contentElement: [{ type: e.ViewChild, args: ["contentElement", { static: !0 }] }], optional: [{ type: e.Input }], optionalHelp: [{ type: e.Input }], optionalHelpColor: [{ type: e.Input }], error: [{ type: e.Input }], extra: [{ type: e.Input }], label: [{ type: e.Input }], col: [{ type: e.Input }], required: [{ type: e.Input }], controlClass: [{ type: e.Input }], line: [{ type: e.Input }], labelWidth: [{ type: e.Input }], id: [{ type: e.Input }] }, d([n.InputNumber(null), h("design:type", Number)], C.prototype, "col", void 0), d([n.InputBoolean(), h("design:type", Object)], C.prototype, "required", void 0), d([n.InputBoolean(null), h("design:type", Boolean)], C.prototype, "line", void 0), d([n.InputNumber(null), h("design:type", Number)], C.prototype, "labelWidth", void 0); var _ = [m, C, b], I = function () { }; I.decorators = [{ type: e.NgModule, args: [{ imports: [s.CommonModule, n.OhayoUtilModule, c.NzToolTipModule, u.NzIconModule, p.NzOutletModule], declarations: g(_), exports: g(_) }] }], t.SEComponent = C, t.SEContainerComponent = m, t.SEModule = I, t.SETitleComponent = b, Object.defineProperty(t, "__esModule", { value: !0 }) })); //# sourceMappingURL=edit.umd.min.js.map