ngx-bit
Version:
A flexible NG-ZORRO helper library
417 lines (400 loc) • 17.4 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('ngx-bit'), require('ng-zorro-antd/grid'), require('@angular/forms'), require('rxjs/operators'), require('ng-zorro-antd/switch'), require('ng-zorro-antd/message'), require('ng-zorro-antd/upload'), require('@angular/common/http')) :
typeof define === 'function' && define.amd ? define('ngx-bit/directive', ['exports', '@angular/core', 'ngx-bit', 'ng-zorro-antd/grid', '@angular/forms', 'rxjs/operators', 'ng-zorro-antd/switch', 'ng-zorro-antd/message', 'ng-zorro-antd/upload', '@angular/common/http'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ngx-bit'] = global['ngx-bit'] || {}, global['ngx-bit'].directive = {}), global.ng.core, global['ngx-bit'], global.grid, global.ng.forms, global.rxjs.operators, global._switch, global.message, global.upload, global.ng.common.http));
}(this, (function (exports, core, ngxBit, grid, forms, operators, _switch, message, upload, http) { 'use strict';
var BitBackDirective = /** @class */ (function () {
function BitBackDirective(bit) {
this.bit = bit;
}
BitBackDirective.prototype.onClick = function () {
this.bit.back();
};
return BitBackDirective;
}());
BitBackDirective.decorators = [
{ type: core.Directive, args: [{
selector: '[bitBack]'
},] }
];
BitBackDirective.ctorParameters = function () { return [
{ type: ngxBit.BitService }
]; };
BitBackDirective.propDecorators = {
onClick: [{ type: core.HostListener, args: ['click',] }]
};
var BitColDirective = /** @class */ (function () {
function BitColDirective(nzColDirective, config) {
this.nzColDirective = nzColDirective;
this.config = config;
}
BitColDirective.prototype.ngOnInit = function () {
if (!this.config.col.hasOwnProperty(this.bitCol)) {
return;
}
var col = this.config.col[this.bitCol];
this.nzColDirective.nzXs = col.hasOwnProperty('nzXs') ? col.nzXs : null;
this.nzColDirective.nzSm = col.hasOwnProperty('nzSm') ? col.nzSm : null;
this.nzColDirective.nzMd = col.hasOwnProperty('nzMd') ? col.nzMd : null;
this.nzColDirective.nzLg = col.hasOwnProperty('nzLg') ? col.nzLg : null;
this.nzColDirective.nzXl = col.hasOwnProperty('nzXl') ? col.nzXl : null;
this.nzColDirective.nzXXl = col.hasOwnProperty('nzXXl') ? col.nzXXl : null;
this.nzColDirective.setHostClassMap();
};
return BitColDirective;
}());
BitColDirective.decorators = [
{ type: core.Directive, args: [{
selector: '[bitCol]'
},] }
];
BitColDirective.ctorParameters = function () { return [
{ type: grid.NzColDirective },
{ type: ngxBit.BitConfig }
]; };
BitColDirective.propDecorators = {
bitCol: [{ type: core.Input }]
};
var BitFormSubmitDirective = /** @class */ (function () {
function BitFormSubmitDirective(form) {
this.form = form;
this.bitFormSubmit = new core.EventEmitter();
}
BitFormSubmitDirective.prototype.ngOnInit = function () {
var _this = this;
this.form.ngSubmit.subscribe(function (_) {
var controls = _this.form.control.controls;
for (var key in controls) {
if (controls.hasOwnProperty(key)) {
controls[key].markAsDirty();
controls[key].updateValueAndValidity();
}
}
_this.bitFormSubmit.emit(_this.form.value);
});
};
return BitFormSubmitDirective;
}());
BitFormSubmitDirective.decorators = [
{ type: core.Directive, args: [{
selector: 'form[bitFormSubmit]'
},] }
];
BitFormSubmitDirective.ctorParameters = function () { return [
{ type: forms.FormGroupDirective }
]; };
BitFormSubmitDirective.propDecorators = {
bitFormSubmit: [{ type: core.Output }]
};
var BitHistoryDirective = /** @class */ (function () {
function BitHistoryDirective(bit) {
this.bit = bit;
}
BitHistoryDirective.prototype.onClick = function () {
this.bit.history(this.bitHistory);
};
return BitHistoryDirective;
}());
BitHistoryDirective.decorators = [
{ type: core.Directive, args: [{
selector: '[bitHistory]'
},] }
];
BitHistoryDirective.ctorParameters = function () { return [
{ type: ngxBit.BitService }
]; };
BitHistoryDirective.propDecorators = {
bitHistory: [{ type: core.Input }],
onClick: [{ type: core.HostListener, args: ['click',] }]
};
var BitI18nUpdateDirective = /** @class */ (function () {
function BitI18nUpdateDirective(bit, formGroupName) {
this.bit = bit;
this.formGroupName = formGroupName;
}
BitI18nUpdateDirective.prototype.ngOnInit = function () {
var _this = this;
this.changes = this.formGroupName.valueChanges.subscribe(function (value) {
var emptyI18n = [];
for (var ID in value) {
if (value.hasOwnProperty(ID)) {
if (!value[ID]) {
emptyI18n.push(ID);
}
}
}
Reflect.set(_this.bit.i18nTooltip, _this.formGroupName.name, emptyI18n);
});
};
BitI18nUpdateDirective.prototype.ngOnDestroy = function () {
this.changes.unsubscribe();
};
return BitI18nUpdateDirective;
}());
BitI18nUpdateDirective.decorators = [
{ type: core.Directive, args: [{
selector: '[formGroupName][bitI18nUpdate]'
},] }
];
BitI18nUpdateDirective.ctorParameters = function () { return [
{ type: ngxBit.BitService },
{ type: forms.FormGroupName }
]; };
var BitOpenDirective = /** @class */ (function () {
function BitOpenDirective(bit) {
this.bit = bit;
}
BitOpenDirective.prototype.onClick = function () {
this.bit.open(this.bitOpen, this.extras);
};
return BitOpenDirective;
}());
BitOpenDirective.decorators = [
{ type: core.Directive, args: [{
selector: '[bitOpen]'
},] }
];
BitOpenDirective.ctorParameters = function () { return [
{ type: ngxBit.BitService }
]; };
BitOpenDirective.propDecorators = {
bitOpen: [{ type: core.Input }],
extras: [{ type: core.Input }],
onClick: [{ type: core.HostListener, args: ['click',] }]
};
var BitSearchChangeDirective = /** @class */ (function () {
function BitSearchChangeDirective(model) {
this.model = model;
this.after = new core.EventEmitter();
}
BitSearchChangeDirective.prototype.ngOnInit = function () {
var _this = this;
this.model.update.pipe(operators.switchMap(function (_) { return _this.bitSearchChange.afterSearch(); })).subscribe(function (_) {
_this.after.emit(true);
});
};
return BitSearchChangeDirective;
}());
BitSearchChangeDirective.decorators = [
{ type: core.Directive, args: [{
selector: '[bitSearchChange]'
},] }
];
BitSearchChangeDirective.ctorParameters = function () { return [
{ type: forms.NgModel }
]; };
BitSearchChangeDirective.propDecorators = {
bitSearchChange: [{ type: core.Input }],
after: [{ type: core.Output }]
};
var BitSearchClearDirective = /** @class */ (function () {
function BitSearchClearDirective() {
this.after = new core.EventEmitter();
}
BitSearchClearDirective.prototype.onClick = function () {
var _this = this;
this.bitSearchClear.clearSearch(this.reset).subscribe(function () {
_this.after.emit(true);
});
};
return BitSearchClearDirective;
}());
BitSearchClearDirective.decorators = [
{ type: core.Directive, args: [{
selector: 'button[bitSearchClear]'
},] }
];
BitSearchClearDirective.propDecorators = {
bitSearchClear: [{ type: core.Input }],
reset: [{ type: core.Input }],
after: [{ type: core.Output }],
onClick: [{ type: core.HostListener, args: ['click',] }]
};
var BitSearchStartDirective = /** @class */ (function () {
function BitSearchStartDirective() {
this.after = new core.EventEmitter();
}
BitSearchStartDirective.prototype.onenter = function (el) {
if (el.tagName.toLowerCase() !== 'input') {
return;
}
this.afterSearch();
};
BitSearchStartDirective.prototype.onclick = function (el) {
if (el.tagName.toLowerCase() === 'input') {
return;
}
this.afterSearch();
};
BitSearchStartDirective.prototype.afterSearch = function () {
var _this = this;
this.bitSearchStart.afterSearch().subscribe(function () {
_this.after.emit(true);
});
};
return BitSearchStartDirective;
}());
BitSearchStartDirective.decorators = [
{ type: core.Directive, args: [{
selector: '[bitSearchStart]'
},] }
];
BitSearchStartDirective.propDecorators = {
bitSearchStart: [{ type: core.Input }],
after: [{ type: core.Output }],
onenter: [{ type: core.HostListener, args: ['keydown.enter', ['$event.target'],] }],
onclick: [{ type: core.HostListener, args: ['click', ['$event.target'],] }]
};
var BitStatusChangeDirective = /** @class */ (function () {
function BitStatusChangeDirective(nzSwitchComponent, bit, message) {
this.bit = bit;
this.message = message;
this.bitControl = false;
this.response = new core.EventEmitter();
nzSwitchComponent.nzControl = true;
}
BitStatusChangeDirective.prototype.onclick = function () {
var _this = this;
this.bitStatusChange.subscribe(function (res) {
if (!res.error) {
_this.message.success(_this.bit.l.StatusSuccess);
}
else {
if (!_this.bitControl) {
_this.message.error(_this.bit.l.StatusError);
}
else {
_this.response.emit(res);
}
}
});
};
return BitStatusChangeDirective;
}());
BitStatusChangeDirective.decorators = [
{ type: core.Directive, args: [{
selector: 'nz-switch[bitStatusChange]'
},] }
];
BitStatusChangeDirective.ctorParameters = function () { return [
{ type: _switch.NzSwitchComponent },
{ type: ngxBit.BitService },
{ type: message.NzMessageService }
]; };
BitStatusChangeDirective.propDecorators = {
bitStatusChange: [{ type: core.Input }],
bitControl: [{ type: core.Input }],
response: [{ type: core.Output }],
onclick: [{ type: core.HostListener, args: ['click',] }]
};
var BitUploadDirective = /** @class */ (function () {
function BitUploadDirective(config, http, nzUploadComponent) {
nzUploadComponent.nzSize = !config.api.uploadSize ? 5120 : config.api.uploadSize;
nzUploadComponent.nzShowUploadList = false;
if (config.api.uploadStorage === 'default') {
nzUploadComponent.nzAction = config.url.api + config.api.upload;
nzUploadComponent.nzWithCredentials = config.api.withCredentials;
return;
}
nzUploadComponent.nzAction = config.api.upload;
nzUploadComponent.nzData = function (file) {
var url = config.url.api + config.api.uploadFetchSigned;
return http.request(config.api.uploadFetchSignedMethod, url, {
withCredentials: config.api.withCredentials
}).pipe(operators.map(function (res) {
var sep = file.name.split('.');
var ext = sep.length > 1 ? '.' + sep.pop().toLowerCase() : '';
file.key = res.filename + ext;
switch (config.api.uploadStorage) {
case 'oss':
return {
key: file.key,
policy: res.option.policy,
OSSAccessKeyId: res.option.access_key_id,
Signature: res.option.signature
};
case 'obs':
return {
key: file.key,
policy: res.option.policy,
AccessKeyId: res.option.access_key_id,
signature: res.option.signature
};
case 'cos':
return {
key: file.key,
policy: res.option.policy,
'q-sign-algorithm': res.option.sign_algorithm,
'q-ak': res.option.ak,
'q-key-time': res.option.key_time,
'q-signature': res.option.signature
};
}
}));
};
}
return BitUploadDirective;
}());
BitUploadDirective.decorators = [
{ type: core.Directive, args: [{
selector: 'nz-upload[bitUpload]'
},] }
];
BitUploadDirective.ctorParameters = function () { return [
{ type: ngxBit.BitConfig },
{ type: http.HttpClient },
{ type: upload.NzUploadComponent }
]; };
var BitDirectiveModule = /** @class */ (function () {
function BitDirectiveModule() {
}
return BitDirectiveModule;
}());
BitDirectiveModule.decorators = [
{ type: core.NgModule, args: [{
declarations: [
BitBackDirective,
BitColDirective,
BitFormSubmitDirective,
BitHistoryDirective,
BitI18nUpdateDirective,
BitOpenDirective,
BitSearchChangeDirective,
BitSearchClearDirective,
BitSearchStartDirective,
BitStatusChangeDirective,
BitUploadDirective
],
exports: [
BitBackDirective,
BitColDirective,
BitFormSubmitDirective,
BitHistoryDirective,
BitI18nUpdateDirective,
BitOpenDirective,
BitSearchChangeDirective,
BitSearchClearDirective,
BitSearchStartDirective,
BitStatusChangeDirective,
BitUploadDirective
]
},] }
];
/**
* Generated bundle index. Do not edit.
*/
exports.BitBackDirective = BitBackDirective;
exports.BitColDirective = BitColDirective;
exports.BitDirectiveModule = BitDirectiveModule;
exports.BitFormSubmitDirective = BitFormSubmitDirective;
exports.BitHistoryDirective = BitHistoryDirective;
exports.BitI18nUpdateDirective = BitI18nUpdateDirective;
exports.BitOpenDirective = BitOpenDirective;
exports.BitSearchChangeDirective = BitSearchChangeDirective;
exports.BitSearchClearDirective = BitSearchClearDirective;
exports.BitSearchStartDirective = BitSearchStartDirective;
exports.BitStatusChangeDirective = BitStatusChangeDirective;
exports.BitUploadDirective = BitUploadDirective;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=ngx-bit-directive.umd.js.map