@reskin/core 0.0.21 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/reskin-core-directives.umd.js +303 -163
- package/bundles/reskin-core-directives.umd.js.map +1 -1
- package/bundles/reskin-core-guards.umd.js +119 -32
- package/bundles/reskin-core-guards.umd.js.map +1 -1
- package/bundles/reskin-core-interceptors.umd.js +310 -92
- package/bundles/reskin-core-interceptors.umd.js.map +1 -1
- package/bundles/reskin-core-utils.umd.js +220 -77
- package/bundles/reskin-core-utils.umd.js.map +1 -1
- package/directives/auth.directive.d.ts +56 -9
- package/directives/load.styles.directive.d.ts +45 -5
- package/directives/string.template.outlet.directive.d.ts +68 -11
- package/esm2015/directives/auth.directive.js +71 -30
- package/esm2015/directives/load.styles.directive.js +84 -15
- package/esm2015/directives/string.template.outlet.directive.js +118 -60
- package/esm2015/guards/auth.guard.js +117 -30
- package/esm2015/interceptors/blob.interceptor.js +67 -28
- package/esm2015/interceptors/cache.interceptor.js +46 -14
- package/esm2015/interceptors/error.interceptor.js +104 -12
- package/esm2015/interceptors/public-api.js +2 -1
- package/esm2015/interceptors/token.interceptor.js +86 -42
- package/esm2015/interceptors/types.js +5 -0
- package/esm2015/utils/array.js +42 -22
- package/esm2015/utils/dom.js +29 -11
- package/esm2015/utils/form.js +44 -13
- package/esm2015/utils/store.js +101 -26
- package/fesm2015/reskin-core-directives.js +269 -103
- package/fesm2015/reskin-core-directives.js.map +1 -1
- package/fesm2015/reskin-core-guards.js +116 -29
- package/fesm2015/reskin-core-guards.js.map +1 -1
- package/fesm2015/reskin-core-interceptors.js +302 -91
- package/fesm2015/reskin-core-interceptors.js.map +1 -1
- package/fesm2015/reskin-core-utils.js +212 -68
- package/fesm2015/reskin-core-utils.js.map +1 -1
- package/guards/auth.guard.d.ts +85 -5
- package/interceptors/blob.interceptor.d.ts +30 -3
- package/interceptors/cache.interceptor.d.ts +28 -4
- package/interceptors/error.interceptor.d.ts +43 -2
- package/interceptors/public-api.d.ts +1 -0
- package/interceptors/token.interceptor.d.ts +41 -12
- package/interceptors/types.d.ts +68 -0
- package/package.json +1 -1
- package/utils/array.d.ts +8 -1
- package/utils/dom.d.ts +32 -5
- package/utils/form.d.ts +37 -2
- package/utils/store.d.ts +56 -15
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs/operators'), require('@reskin/core/services')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define('@reskin/core/directives', ['exports', '@angular/core', 'rxjs/operators', '@reskin/core/services'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.reskin = global.reskin || {}, global.reskin.core = global.reskin.core || {}, global.reskin.core.directives = {}), global.ng.core, global.rxjs.operators, global.reskin.core.services));
|
|
5
|
-
})(this, (function (exports, i0, operators, i1) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@reskin/core/services')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define('@reskin/core/directives', ['exports', '@angular/core', 'rxjs', 'rxjs/operators', '@reskin/core/services'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.reskin = global.reskin || {}, global.reskin.core = global.reskin.core || {}, global.reskin.core.directives = {}), global.ng.core, global.rxjs, global.rxjs.operators, global.reskin.core.services));
|
|
5
|
+
})(this, (function (exports, i0, rxjs, operators, i1) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopNamespace(e) {
|
|
8
8
|
if (e && e.__esModule) return e;
|
|
@@ -25,18 +25,41 @@
|
|
|
25
25
|
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
|
|
26
26
|
var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* 权限指令
|
|
30
|
+
* 根据权限标识符控制模板的显示与隐藏
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```html
|
|
34
|
+
* <!-- 基础用法 -->
|
|
35
|
+
* <div *rkAuth="'user:edit'">有编辑权限才显示</div>
|
|
36
|
+
*
|
|
37
|
+
* <!-- 多个权限(或关系) -->
|
|
38
|
+
* <div *rkAuth="['user:edit', 'user:delete']">有任一权限即显示</div>
|
|
39
|
+
*
|
|
40
|
+
* <!-- 使用 then/else 模板 -->
|
|
41
|
+
* <ng-container *rkAuth="'user:edit'; then hasAuth; else noAuth"></ng-container>
|
|
42
|
+
* <ng-template #hasAuth let-menu>
|
|
43
|
+
* <p>有权限,菜单信息:{{ menu | json }}</p>
|
|
44
|
+
* </ng-template>
|
|
45
|
+
* <ng-template #noAuth>
|
|
46
|
+
* <p>无权限</p>
|
|
47
|
+
* </ng-template>
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
28
50
|
var RkAuthDirective = /** @class */ (function () {
|
|
29
|
-
function RkAuthDirective(
|
|
30
|
-
this.
|
|
51
|
+
function RkAuthDirective(menuService, viewContainerRef, templateRef) {
|
|
52
|
+
this.menuService = menuService;
|
|
31
53
|
this.viewContainerRef = viewContainerRef;
|
|
32
54
|
this.templateRef = templateRef;
|
|
33
55
|
this.condition = '';
|
|
56
|
+
this.destroy$ = new rxjs.Subject();
|
|
34
57
|
this.thenTemplateRef = templateRef;
|
|
35
58
|
}
|
|
36
59
|
Object.defineProperty(RkAuthDirective.prototype, "rkAuth", {
|
|
37
60
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
61
|
+
* 权限标识符
|
|
62
|
+
* 传递多个标识符时,匹配按"或"运算
|
|
40
63
|
*/
|
|
41
64
|
set: function (condition) {
|
|
42
65
|
this.condition = condition;
|
|
@@ -46,6 +69,9 @@
|
|
|
46
69
|
configurable: true
|
|
47
70
|
});
|
|
48
71
|
Object.defineProperty(RkAuthDirective.prototype, "rkAuthThen", {
|
|
72
|
+
/**
|
|
73
|
+
* 有权限时显示的模板
|
|
74
|
+
*/
|
|
49
75
|
set: function (templateRef) {
|
|
50
76
|
this.thenTemplateRef = templateRef;
|
|
51
77
|
this.updateView();
|
|
@@ -54,6 +80,9 @@
|
|
|
54
80
|
configurable: true
|
|
55
81
|
});
|
|
56
82
|
Object.defineProperty(RkAuthDirective.prototype, "rkAuthElse", {
|
|
83
|
+
/**
|
|
84
|
+
* 无权限时显示的模板
|
|
85
|
+
*/
|
|
57
86
|
set: function (templateRef) {
|
|
58
87
|
this.elseTemplateRef = templateRef;
|
|
59
88
|
this.updateView();
|
|
@@ -62,37 +91,48 @@
|
|
|
62
91
|
configurable: true
|
|
63
92
|
});
|
|
64
93
|
RkAuthDirective.prototype.ngOnDestroy = function () {
|
|
65
|
-
|
|
66
|
-
|
|
94
|
+
this.destroy$.next();
|
|
95
|
+
this.destroy$.complete();
|
|
67
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* 更新视图显示
|
|
99
|
+
*/
|
|
68
100
|
RkAuthDirective.prototype.updateView = function () {
|
|
69
101
|
var _this = this;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
if (_this.elseTemplateRef) {
|
|
81
|
-
_this.viewContainerRef.createEmbeddedView(_this.elseTemplateRef, context);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
102
|
+
if (!this.condition) {
|
|
103
|
+
this.viewContainerRef.clear();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this.checkAuth(this.condition)
|
|
107
|
+
.pipe(operators.takeUntil(this.destroy$))
|
|
108
|
+
.subscribe(function (context) {
|
|
109
|
+
_this.renderView(context);
|
|
84
110
|
});
|
|
85
111
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
112
|
+
/**
|
|
113
|
+
* 渲染视图
|
|
114
|
+
*/
|
|
115
|
+
RkAuthDirective.prototype.renderView = function (context) {
|
|
116
|
+
this.viewContainerRef.clear();
|
|
117
|
+
if (context.status && this.thenTemplateRef) {
|
|
118
|
+
this.viewContainerRef.createEmbeddedView(this.thenTemplateRef, context);
|
|
119
|
+
}
|
|
120
|
+
else if (!context.status && this.elseTemplateRef) {
|
|
121
|
+
this.viewContainerRef.createEmbeddedView(this.elseTemplateRef, context);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* 检查权限
|
|
126
|
+
*/
|
|
127
|
+
RkAuthDirective.prototype.checkAuth = function (tags) {
|
|
128
|
+
var tagList = Array.isArray(tags) ? tags : [tags];
|
|
129
|
+
return this.menuService.requestData().pipe(operators.map(function (response) {
|
|
130
|
+
var matchedMenus = response.data.filter(function (menu) { return tagList.includes(menu.SYSTEM_RESOURCE_GUARD_ID); });
|
|
131
|
+
var context = {
|
|
132
|
+
$implicit: Array.isArray(tags) ? matchedMenus : matchedMenus[0] || null,
|
|
133
|
+
status: matchedMenus.length > 0,
|
|
95
134
|
};
|
|
135
|
+
return context;
|
|
96
136
|
}));
|
|
97
137
|
};
|
|
98
138
|
return RkAuthDirective;
|
|
@@ -112,6 +152,155 @@
|
|
|
112
152
|
type: i0.Input
|
|
113
153
|
}] } });
|
|
114
154
|
|
|
155
|
+
/**
|
|
156
|
+
* 字符串模板输出上下文
|
|
157
|
+
*/
|
|
158
|
+
var RkStringTemplateOutletContext = /** @class */ (function () {
|
|
159
|
+
function RkStringTemplateOutletContext() {
|
|
160
|
+
/** 隐式上下文值 */
|
|
161
|
+
this.$implicit = null;
|
|
162
|
+
}
|
|
163
|
+
return RkStringTemplateOutletContext;
|
|
164
|
+
}());
|
|
165
|
+
/**
|
|
166
|
+
* 字符串模板输出指令
|
|
167
|
+
* 支持动态渲染字符串或 TemplateRef
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```html
|
|
171
|
+
* <!-- 渲染字符串 -->
|
|
172
|
+
* <ng-container *rkStringTemplateOutlet="'Hello World'">
|
|
173
|
+
* <ng-template>默认模板</ng-template>
|
|
174
|
+
* </ng-container>
|
|
175
|
+
*
|
|
176
|
+
* <!-- 渲染 TemplateRef -->
|
|
177
|
+
* <ng-container *rkStringTemplateOutlet="customTemplate; context: { $implicit: data }">
|
|
178
|
+
* </ng-container>
|
|
179
|
+
* <ng-template #customTemplate let-item>
|
|
180
|
+
* <div>{{ item }}</div>
|
|
181
|
+
* </ng-template>
|
|
182
|
+
*
|
|
183
|
+
* <!-- 动态切换 -->
|
|
184
|
+
* <ng-container *rkStringTemplateOutlet="isTemplate ? templateRef : 'Static Text'">
|
|
185
|
+
* </ng-container>
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
var RkStringTemplateOutletDirective = /** @class */ (function () {
|
|
189
|
+
function RkStringTemplateOutletDirective(viewContainerRef, templateRef) {
|
|
190
|
+
this.viewContainerRef = viewContainerRef;
|
|
191
|
+
this.templateRef = templateRef;
|
|
192
|
+
this.embeddedViewRef = null;
|
|
193
|
+
this.context = new RkStringTemplateOutletContext();
|
|
194
|
+
/**
|
|
195
|
+
* 输出内容
|
|
196
|
+
* 可以是字符串或 TemplateRef
|
|
197
|
+
*/
|
|
198
|
+
this.rkStringTemplateOutlet = null;
|
|
199
|
+
/**
|
|
200
|
+
* 模板上下文
|
|
201
|
+
* 当 rkStringTemplateOutlet 是 TemplateRef 时使用
|
|
202
|
+
*/
|
|
203
|
+
this.rkStringTemplateOutletContext = null;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* 类型守卫
|
|
207
|
+
* 用于 Angular 模板类型检查
|
|
208
|
+
*/
|
|
209
|
+
RkStringTemplateOutletDirective.rkTemplateContextGuard = function (_dir, _ctx) {
|
|
210
|
+
return true;
|
|
211
|
+
};
|
|
212
|
+
RkStringTemplateOutletDirective.prototype.ngOnChanges = function (changes) {
|
|
213
|
+
var rkStringTemplateOutlet = changes.rkStringTemplateOutlet, rkStringTemplateOutletContext = changes.rkStringTemplateOutletContext;
|
|
214
|
+
// 更新隐式上下文
|
|
215
|
+
if (rkStringTemplateOutlet) {
|
|
216
|
+
this.context.$implicit = rkStringTemplateOutlet.currentValue;
|
|
217
|
+
}
|
|
218
|
+
// 判断是否需要重建视图
|
|
219
|
+
if (this.shouldRecreateView(rkStringTemplateOutlet, rkStringTemplateOutletContext)) {
|
|
220
|
+
this.recreateView();
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
this.updateContext();
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* 判断是否需要重建视图
|
|
228
|
+
*/
|
|
229
|
+
RkStringTemplateOutletDirective.prototype.shouldRecreateView = function (outletChange, contextChange) {
|
|
230
|
+
// 首次变更需要创建视图
|
|
231
|
+
if (outletChange === null || outletChange === void 0 ? void 0 : outletChange.firstChange) {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
// outlet 在 TemplateRef 和非 TemplateRef 之间切换时需要重建
|
|
235
|
+
if (outletChange && this.isOutletTypeChanged(outletChange)) {
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
// 上下文结构变化时需要重建
|
|
239
|
+
if (contextChange && this.isContextShapeChanged(contextChange)) {
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
return false;
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* 检查 outlet 类型是否变化
|
|
246
|
+
*/
|
|
247
|
+
RkStringTemplateOutletDirective.prototype.isOutletTypeChanged = function (change) {
|
|
248
|
+
var isPreviousTemplate = change.previousValue instanceof i0.TemplateRef;
|
|
249
|
+
var isCurrentTemplate = change.currentValue instanceof i0.TemplateRef;
|
|
250
|
+
return isPreviousTemplate !== isCurrentTemplate;
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* 检查上下文结构是否变化
|
|
254
|
+
*/
|
|
255
|
+
RkStringTemplateOutletDirective.prototype.isContextShapeChanged = function (change) {
|
|
256
|
+
var prevKeys = Object.keys(change.previousValue || {});
|
|
257
|
+
var currKeys = Object.keys(change.currentValue || {});
|
|
258
|
+
if (prevKeys.length !== currKeys.length) {
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
return currKeys.some(function (key) { return !prevKeys.includes(key); });
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* 重建视图
|
|
265
|
+
*/
|
|
266
|
+
RkStringTemplateOutletDirective.prototype.recreateView = function () {
|
|
267
|
+
this.viewContainerRef.clear();
|
|
268
|
+
var isTemplateRef = this.rkStringTemplateOutlet instanceof i0.TemplateRef;
|
|
269
|
+
var templateRef = isTemplateRef ? this.rkStringTemplateOutlet : this.templateRef;
|
|
270
|
+
var context = isTemplateRef ? this.rkStringTemplateOutletContext : this.context;
|
|
271
|
+
this.embeddedViewRef = this.viewContainerRef.createEmbeddedView(templateRef, context || this.context);
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* 更新视图上下文
|
|
275
|
+
*/
|
|
276
|
+
RkStringTemplateOutletDirective.prototype.updateContext = function () {
|
|
277
|
+
if (!this.embeddedViewRef) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
var isTemplateRef = this.rkStringTemplateOutlet instanceof i0.TemplateRef;
|
|
281
|
+
var newContext = isTemplateRef ? this.rkStringTemplateOutletContext : this.context;
|
|
282
|
+
var viewContext = this.embeddedViewRef.context;
|
|
283
|
+
if (newContext) {
|
|
284
|
+
Object.keys(newContext).forEach(function (key) {
|
|
285
|
+
viewContext[key] = newContext[key];
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
return RkStringTemplateOutletDirective;
|
|
290
|
+
}());
|
|
291
|
+
RkStringTemplateOutletDirective.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: RkStringTemplateOutletDirective, deps: [{ token: i0__namespace.ViewContainerRef }, { token: i0__namespace.TemplateRef }], target: i0__namespace.ɵɵFactoryTarget.Directive });
|
|
292
|
+
RkStringTemplateOutletDirective.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.17", type: RkStringTemplateOutletDirective, selector: "[rkStringTemplateOutlet]", inputs: { rkStringTemplateOutlet: "rkStringTemplateOutlet", rkStringTemplateOutletContext: "rkStringTemplateOutletContext" }, usesOnChanges: true, ngImport: i0__namespace });
|
|
293
|
+
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: RkStringTemplateOutletDirective, decorators: [{
|
|
294
|
+
type: i0.Directive,
|
|
295
|
+
args: [{
|
|
296
|
+
selector: '[rkStringTemplateOutlet]',
|
|
297
|
+
}]
|
|
298
|
+
}], ctorParameters: function () { return [{ type: i0__namespace.ViewContainerRef }, { type: i0__namespace.TemplateRef }]; }, propDecorators: { rkStringTemplateOutlet: [{
|
|
299
|
+
type: i0.Input
|
|
300
|
+
}], rkStringTemplateOutletContext: [{
|
|
301
|
+
type: i0.Input
|
|
302
|
+
}] } });
|
|
303
|
+
|
|
115
304
|
/******************************************************************************
|
|
116
305
|
Copyright (c) Microsoft Corporation.
|
|
117
306
|
|
|
@@ -589,149 +778,100 @@
|
|
|
589
778
|
__disposeResources: __disposeResources,
|
|
590
779
|
};
|
|
591
780
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
this.embeddedViewRef = this.viewContainer.createEmbeddedView(templateRef, isTemplateRef ? this.rkStringTemplateOutletContext : this.context);
|
|
609
|
-
};
|
|
610
|
-
RkStringTemplateOutletDirective.prototype.updateContext = function () {
|
|
611
|
-
var e_1, _a;
|
|
612
|
-
var isTemplateRef = this.rkStringTemplateOutlet instanceof i0.TemplateRef;
|
|
613
|
-
var newCtx = isTemplateRef ? this.rkStringTemplateOutletContext : this.context;
|
|
614
|
-
var oldCtx = this.embeddedViewRef.context;
|
|
615
|
-
if (newCtx) {
|
|
616
|
-
try {
|
|
617
|
-
for (var _b = __values(Object.keys(newCtx)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
618
|
-
var propName = _c.value;
|
|
619
|
-
oldCtx[propName] = newCtx[propName];
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
623
|
-
finally {
|
|
624
|
-
try {
|
|
625
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
626
|
-
}
|
|
627
|
-
finally { if (e_1) throw e_1.error; }
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
};
|
|
631
|
-
RkStringTemplateOutletDirective.prototype.ngOnChanges = function (changes) {
|
|
632
|
-
var rkStringTemplateOutletContext = changes.rkStringTemplateOutletContext, rkStringTemplateOutlet = changes.rkStringTemplateOutlet;
|
|
633
|
-
var shouldRecreateView = function () {
|
|
634
|
-
var shouldOutletRecreate = false;
|
|
635
|
-
if (rkStringTemplateOutlet) {
|
|
636
|
-
if (rkStringTemplateOutlet.firstChange) {
|
|
637
|
-
shouldOutletRecreate = true;
|
|
638
|
-
}
|
|
639
|
-
else {
|
|
640
|
-
var isPreviousOutletTemplate = rkStringTemplateOutlet.previousValue instanceof i0.TemplateRef;
|
|
641
|
-
var isCurrentOutletTemplate = rkStringTemplateOutlet.currentValue instanceof i0.TemplateRef;
|
|
642
|
-
shouldOutletRecreate = isPreviousOutletTemplate || isCurrentOutletTemplate;
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
var hasContextShapeChanged = function (ctxChange) {
|
|
646
|
-
var e_2, _a;
|
|
647
|
-
var prevCtxKeys = Object.keys(ctxChange.previousValue || {});
|
|
648
|
-
var currCtxKeys = Object.keys(ctxChange.currentValue || {});
|
|
649
|
-
if (prevCtxKeys.length === currCtxKeys.length) {
|
|
650
|
-
try {
|
|
651
|
-
for (var currCtxKeys_1 = __values(currCtxKeys), currCtxKeys_1_1 = currCtxKeys_1.next(); !currCtxKeys_1_1.done; currCtxKeys_1_1 = currCtxKeys_1.next()) {
|
|
652
|
-
var propName = currCtxKeys_1_1.value;
|
|
653
|
-
if (prevCtxKeys.indexOf(propName) === -1) {
|
|
654
|
-
return true;
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
659
|
-
finally {
|
|
660
|
-
try {
|
|
661
|
-
if (currCtxKeys_1_1 && !currCtxKeys_1_1.done && (_a = currCtxKeys_1.return)) _a.call(currCtxKeys_1);
|
|
662
|
-
}
|
|
663
|
-
finally { if (e_2) throw e_2.error; }
|
|
664
|
-
}
|
|
665
|
-
return false;
|
|
666
|
-
}
|
|
667
|
-
else {
|
|
668
|
-
return true;
|
|
669
|
-
}
|
|
670
|
-
};
|
|
671
|
-
var shouldContextRecreate = rkStringTemplateOutletContext && hasContextShapeChanged(rkStringTemplateOutletContext);
|
|
672
|
-
return shouldContextRecreate || shouldOutletRecreate;
|
|
673
|
-
};
|
|
674
|
-
if (rkStringTemplateOutlet) {
|
|
675
|
-
this.context.$implicit = rkStringTemplateOutlet.currentValue;
|
|
676
|
-
}
|
|
677
|
-
var recreateView = shouldRecreateView();
|
|
678
|
-
if (recreateView) {
|
|
679
|
-
/** recreate view when context shape or outlet change **/
|
|
680
|
-
this.recreateView();
|
|
681
|
-
}
|
|
682
|
-
else {
|
|
683
|
-
/** update context **/
|
|
684
|
-
this.updateContext();
|
|
685
|
-
}
|
|
686
|
-
};
|
|
687
|
-
return RkStringTemplateOutletDirective;
|
|
688
|
-
}());
|
|
689
|
-
RkStringTemplateOutletDirective.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: RkStringTemplateOutletDirective, deps: [{ token: i0__namespace.ViewContainerRef }, { token: i0__namespace.TemplateRef }], target: i0__namespace.ɵɵFactoryTarget.Directive });
|
|
690
|
-
RkStringTemplateOutletDirective.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.17", type: RkStringTemplateOutletDirective, selector: "[rkStringTemplateOutlet]", inputs: { rkStringTemplateOutletContext: "rkStringTemplateOutletContext", rkStringTemplateOutlet: "rkStringTemplateOutlet" }, usesOnChanges: true, ngImport: i0__namespace });
|
|
691
|
-
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: RkStringTemplateOutletDirective, decorators: [{
|
|
692
|
-
type: i0.Directive,
|
|
693
|
-
args: [{
|
|
694
|
-
selector: '[rkStringTemplateOutlet]',
|
|
695
|
-
}]
|
|
696
|
-
}], ctorParameters: function () { return [{ type: i0__namespace.ViewContainerRef }, { type: i0__namespace.TemplateRef }]; }, propDecorators: { rkStringTemplateOutletContext: [{
|
|
697
|
-
type: i0.Input
|
|
698
|
-
}], rkStringTemplateOutlet: [{
|
|
699
|
-
type: i0.Input
|
|
700
|
-
}] } });
|
|
701
|
-
var RkStringTemplateOutletContext = /** @class */ (function () {
|
|
702
|
-
function RkStringTemplateOutletContext() {
|
|
703
|
-
}
|
|
704
|
-
return RkStringTemplateOutletContext;
|
|
705
|
-
}());
|
|
706
|
-
|
|
781
|
+
/**
|
|
782
|
+
* 样式按需加载指令
|
|
783
|
+
* 在指令初始化时加载指定的样式文件,销毁时自动卸载
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
786
|
+
* ```html
|
|
787
|
+
* <!-- 加载单个样式 -->
|
|
788
|
+
* <div [rkLoadStyles]="'assets/styles/theme.css'">内容</div>
|
|
789
|
+
*
|
|
790
|
+
* <!-- 加载多个样式 -->
|
|
791
|
+
* <div [rkLoadStyles]="['assets/styles/theme.css', 'assets/styles/components.css']">内容</div>
|
|
792
|
+
*
|
|
793
|
+
* <!-- 监听加载完成事件 -->
|
|
794
|
+
* <div [rkLoadStyles]="styleUrls" (stylesLoaded)="onLoaded($event)">内容</div>
|
|
795
|
+
* ```
|
|
796
|
+
*/
|
|
707
797
|
var RkLoadStylesDirective = /** @class */ (function () {
|
|
708
|
-
function RkLoadStylesDirective(
|
|
709
|
-
this.
|
|
798
|
+
function RkLoadStylesDirective(styleLoaderService) {
|
|
799
|
+
this.styleLoaderService = styleLoaderService;
|
|
800
|
+
this.destroy$ = new rxjs.Subject();
|
|
801
|
+
this.styleUrls = [];
|
|
802
|
+
/**
|
|
803
|
+
* 样式文件路径
|
|
804
|
+
* 可以是单个路径字符串或路径数组
|
|
805
|
+
*/
|
|
710
806
|
this.hrefs = [];
|
|
711
|
-
|
|
807
|
+
/**
|
|
808
|
+
* 样式加载完成事件
|
|
809
|
+
* 返回每个样式文件的加载结果
|
|
810
|
+
*/
|
|
712
811
|
this.stylesLoaded = new i0.EventEmitter();
|
|
713
|
-
this.styleUrls = [];
|
|
714
812
|
}
|
|
715
813
|
RkLoadStylesDirective.prototype.ngOnInit = function () {
|
|
814
|
+
this.loadStyles();
|
|
815
|
+
};
|
|
816
|
+
RkLoadStylesDirective.prototype.ngOnDestroy = function () {
|
|
817
|
+
this.destroy$.next();
|
|
818
|
+
this.destroy$.complete();
|
|
819
|
+
this.unloadStyles();
|
|
820
|
+
};
|
|
821
|
+
/**
|
|
822
|
+
* 加载样式文件
|
|
823
|
+
*/
|
|
824
|
+
RkLoadStylesDirective.prototype.loadStyles = function () {
|
|
716
825
|
var _a;
|
|
717
826
|
var _this = this;
|
|
718
|
-
this.styleUrls =
|
|
719
|
-
if (this.styleUrls.length
|
|
720
|
-
|
|
721
|
-
_this.stylesLoaded.emit(results);
|
|
722
|
-
});
|
|
827
|
+
this.styleUrls = this.normalizeHrefs(this.hrefs);
|
|
828
|
+
if (this.styleUrls.length === 0) {
|
|
829
|
+
return;
|
|
723
830
|
}
|
|
831
|
+
(_a = this.styleLoaderService)
|
|
832
|
+
.load.apply(_a, __spreadArray([], __read(this.styleUrls))).pipe(operators.takeUntil(this.destroy$))
|
|
833
|
+
.subscribe({
|
|
834
|
+
next: function (results) {
|
|
835
|
+
_this.stylesLoaded.emit(results);
|
|
836
|
+
_this.logLoadResults(results);
|
|
837
|
+
},
|
|
838
|
+
error: function (error) {
|
|
839
|
+
console.error('[RkLoadStyles] 样式加载失败:', error);
|
|
840
|
+
},
|
|
841
|
+
});
|
|
724
842
|
};
|
|
725
|
-
|
|
843
|
+
/**
|
|
844
|
+
* 卸载样式文件
|
|
845
|
+
*/
|
|
846
|
+
RkLoadStylesDirective.prototype.unloadStyles = function () {
|
|
726
847
|
var _a;
|
|
727
|
-
if (this.subscription) {
|
|
728
|
-
this.subscription.unsubscribe();
|
|
729
|
-
}
|
|
730
|
-
// 指令销毁时,自动调用 unload,服务内部会处理引用计数
|
|
731
848
|
if (this.styleUrls.length > 0) {
|
|
732
|
-
(_a = this.
|
|
849
|
+
(_a = this.styleLoaderService).unload.apply(_a, __spreadArray([], __read(this.styleUrls)));
|
|
733
850
|
}
|
|
734
851
|
};
|
|
852
|
+
/**
|
|
853
|
+
* 标准化 hrefs 输入为数组
|
|
854
|
+
*/
|
|
855
|
+
RkLoadStylesDirective.prototype.normalizeHrefs = function (hrefs) {
|
|
856
|
+
if (!hrefs) {
|
|
857
|
+
return [];
|
|
858
|
+
}
|
|
859
|
+
return Array.isArray(hrefs) ? hrefs : [hrefs];
|
|
860
|
+
};
|
|
861
|
+
/**
|
|
862
|
+
* 记录加载结果(仅在开发模式)
|
|
863
|
+
*/
|
|
864
|
+
RkLoadStylesDirective.prototype.logLoadResults = function (results) {
|
|
865
|
+
// 开发模式下记录加载结果
|
|
866
|
+
results.forEach(function (result) {
|
|
867
|
+
if (result.success) {
|
|
868
|
+
console.log("[RkLoadStyles] \u6837\u5F0F\u52A0\u8F7D\u6210\u529F: " + result.href);
|
|
869
|
+
}
|
|
870
|
+
else {
|
|
871
|
+
console.error("[RkLoadStyles] \u6837\u5F0F\u52A0\u8F7D\u5931\u8D25: " + result.href, result.error);
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
};
|
|
735
875
|
return RkLoadStylesDirective;
|
|
736
876
|
}());
|
|
737
877
|
RkLoadStylesDirective.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: RkLoadStylesDirective, deps: [{ token: i1__namespace.RkStyleLoaderService }], target: i0__namespace.ɵɵFactoryTarget.Directive });
|