simple-boot-front 1.0.103 → 1.0.104
Sign up to get free protection for your applications and to get access to all the features.
- package/README.MD +388 -388
- package/SimpleBootFront.d.ts +34 -34
- package/SimpleBootFront.js +337 -337
- package/decorators/Component.d.ts +11 -11
- package/decorators/Component.js +30 -30
- package/decorators/Script.d.ts +10 -10
- package/decorators/Script.js +31 -31
- package/decorators/inject/InjectFrontSituationType.d.ts +3 -3
- package/decorators/inject/InjectFrontSituationType.js +7 -7
- package/fetch/Fetcher.d.ts +4 -4
- package/fetch/Fetcher.js +9 -9
- package/lifecycle/OnChangedRender.d.ts +3 -3
- package/lifecycle/OnChangedRender.js +2 -2
- package/lifecycle/OnDestroy.d.ts +3 -3
- package/lifecycle/OnDestroy.js +2 -2
- package/lifecycle/OnFinish.d.ts +3 -3
- package/lifecycle/OnFinish.js +2 -2
- package/lifecycle/OnInit.d.ts +8 -8
- package/lifecycle/OnInit.js +2 -2
- package/lifecycle/OnInitedChild.d.ts +3 -3
- package/lifecycle/OnInitedChild.js +2 -2
- package/option/SimFrontOption.d.ts +14 -14
- package/option/SimFrontOption.js +45 -45
- package/package.json +78 -83
- package/script/ScriptRunnable.d.ts +7 -7
- package/script/ScriptRunnable.js +22 -22
- package/service/CookieService.d.ts +11 -11
- package/service/CookieService.js +54 -54
- package/service/HttpService.d.ts +3 -3
- package/service/HttpService.js +23 -23
- package/service/MetaTagService.d.ts +11 -11
- package/service/MetaTagService.js +52 -52
- package/service/Navigation.d.ts +18 -18
- package/service/Navigation.js +117 -117
- package/service/ScriptService.d.ts +7 -7
- package/service/ScriptService.js +39 -39
- package/service/StorageService.d.ts +12 -12
- package/service/StorageService.js +67 -67
- package/service/view/View.d.ts +6 -6
- package/service/view/View.js +29 -29
- package/service/view/ViewService.d.ts +7 -7
- package/service/view/ViewService.js +46 -46
- package/throwable/RouterError.d.ts +4 -4
- package/throwable/RouterError.js +27 -27
- package/throwable/RouterIntentError.d.ts +4 -4
- package/throwable/RouterIntentError.js +27 -27
- package/throwable/RouterNotFount.d.ts +4 -4
- package/throwable/RouterNotFount.js +27 -27
package/SimpleBootFront.js
CHANGED
@@ -1,337 +1,337 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
3
|
-
var extendStatics = function (d, b) {
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
7
|
-
return extendStatics(d, b);
|
8
|
-
};
|
9
|
-
return function (d, b) {
|
10
|
-
if (typeof b !== "function" && b !== null)
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
12
|
-
extendStatics(d, b);
|
13
|
-
function __() { this.constructor = d; }
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15
|
-
};
|
16
|
-
})();
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
24
|
-
});
|
25
|
-
};
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
30
|
-
function step(op) {
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
32
|
-
while (_) try {
|
33
|
-
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;
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
35
|
-
switch (op[0]) {
|
36
|
-
case 0: case 1: t = op; break;
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
40
|
-
default:
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
45
|
-
if (t[2]) _.ops.pop();
|
46
|
-
_.trys.pop(); continue;
|
47
|
-
}
|
48
|
-
op = body.call(thisArg, _);
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
51
|
-
}
|
52
|
-
};
|
53
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
54
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
55
|
-
if (ar || !(i in from)) {
|
56
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
57
|
-
ar[i] = from[i];
|
58
|
-
}
|
59
|
-
}
|
60
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
61
|
-
};
|
62
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
63
|
-
exports.SimpleBootFront = void 0;
|
64
|
-
var SimFrontOption_1 = require("./option/SimFrontOption");
|
65
|
-
var Component_1 = require("./decorators/Component");
|
66
|
-
var Script_1 = require("./decorators/Script");
|
67
|
-
var DomRender_1 = require("dom-render/DomRender");
|
68
|
-
var SimAtomic_1 = require("simple-boot-core/simstance/SimAtomic");
|
69
|
-
var SimpleApplication_1 = require("simple-boot-core/SimpleApplication");
|
70
|
-
var Intent_1 = require("simple-boot-core/intent/Intent");
|
71
|
-
var Navigation_1 = require("./service/Navigation");
|
72
|
-
var ViewService_1 = require("./service/view/ViewService");
|
73
|
-
var HttpService_1 = require("./service/HttpService");
|
74
|
-
var SimstanceManager_1 = require("simple-boot-core/simstance/SimstanceManager");
|
75
|
-
var IntentManager_1 = require("simple-boot-core/intent/IntentManager");
|
76
|
-
var RouterManager_1 = require("simple-boot-core/route/RouterManager");
|
77
|
-
var ScriptUtils_1 = require("dom-render/utils/script/ScriptUtils");
|
78
|
-
var RawSet_1 = require("dom-render/RawSet");
|
79
|
-
var Types_1 = require("dom-render/types/Types");
|
80
|
-
var InjectFrontSituationType_1 = require("./decorators/inject/InjectFrontSituationType");
|
81
|
-
var SimpleBootFront = (function (_super) {
|
82
|
-
__extends(SimpleBootFront, _super);
|
83
|
-
function SimpleBootFront(rootRouter, option) {
|
84
|
-
var _this = _super.call(this, rootRouter, option) || this;
|
85
|
-
_this.rootRouter = rootRouter;
|
86
|
-
_this.option = option;
|
87
|
-
_this.domRendoerExcludeProxy = [SimpleApplication_1.SimpleApplication, IntentManager_1.IntentManager, RouterManager_1.RouterManager, SimstanceManager_1.SimstanceManager, SimFrontOption_1.SimFrontOption, Navigation_1.Navigation, ViewService_1.ViewService, HttpService_1.HttpService, HTMLElement];
|
88
|
-
_this.domRenderTargetElements = [];
|
89
|
-
_this.domRenderTargetAttrs = [];
|
90
|
-
_this.domRenderConfig = {
|
91
|
-
routerType: 'none',
|
92
|
-
window: option.window,
|
93
|
-
targetElements: _this.domRenderTargetElements,
|
94
|
-
targetAttrs: _this.domRenderTargetAttrs,
|
95
|
-
onElementInit: function (name, obj, rawSet, targetElement) {
|
96
|
-
var _a, _b, _c;
|
97
|
-
var target = (_a = targetElement === null || targetElement === void 0 ? void 0 : targetElement.__render) === null || _a === void 0 ? void 0 : _a.component;
|
98
|
-
var targetKey = 'onInit';
|
99
|
-
var firstCheckMaker = [function (ownerObj, type, idx, saveInjectionConfig) {
|
100
|
-
if (InjectFrontSituationType_1.InjectFrontSituationType.OPENER === (saveInjectionConfig === null || saveInjectionConfig === void 0 ? void 0 : saveInjectionConfig.config.situationType) && rawSet.point.thisVariableName) {
|
101
|
-
return new Proxy(ScriptUtils_1.ScriptUtils.evalReturn(rawSet.point.thisVariableName, obj), new Types_1.DomRenderFinalProxy());
|
102
|
-
}
|
103
|
-
}];
|
104
|
-
if (rawSet.point.thisVariableName) {
|
105
|
-
(_b = target === null || target === void 0 ? void 0 : target.onInit) === null || _b === void 0 ? void 0 : _b.call.apply(_b, __spreadArray([target], _this.simstanceManager.getParameterSim({ target: target, targetKey: targetKey, firstCheckMaker: firstCheckMaker }), false));
|
106
|
-
}
|
107
|
-
else {
|
108
|
-
(_c = target === null || target === void 0 ? void 0 : target.onInit) === null || _c === void 0 ? void 0 : _c.call.apply(_c, __spreadArray([target], _this.simstanceManager.getParameterSim({ target: target, targetKey: targetKey, firstCheckMaker: firstCheckMaker }), false));
|
109
|
-
}
|
110
|
-
},
|
111
|
-
onAttrInit: function (attrName, attrValue, obj, rawSet) {
|
112
|
-
var _a, _b;
|
113
|
-
if (attrName === 'component') {
|
114
|
-
var target_1 = ScriptUtils_1.ScriptUtils.evalReturn(attrValue, obj);
|
115
|
-
var targetKey = 'onInit';
|
116
|
-
var firstCheckMaker = [function (obj, type, idx, saveInjectionConfig) {
|
117
|
-
var _a, _b;
|
118
|
-
if (InjectFrontSituationType_1.InjectFrontSituationType.OPENER === (saveInjectionConfig === null || saveInjectionConfig === void 0 ? void 0 : saveInjectionConfig.config.situationType) && ((_a = target_1 === null || target_1 === void 0 ? void 0 : target_1.__domrender_component_new) === null || _a === void 0 ? void 0 : _a.creator)) {
|
119
|
-
return (_b = target_1 === null || target_1 === void 0 ? void 0 : target_1.__domrender_component_new) === null || _b === void 0 ? void 0 : _b.creator;
|
120
|
-
}
|
121
|
-
}];
|
122
|
-
if (rawSet.point.thisVariableName) {
|
123
|
-
(_a = target_1 === null || target_1 === void 0 ? void 0 : target_1.onInit) === null || _a === void 0 ? void 0 : _a.call.apply(_a, __spreadArray([target_1], _this.simstanceManager.getParameterSim({ target: target_1, targetKey: targetKey, firstCheckMaker: firstCheckMaker }), false));
|
124
|
-
}
|
125
|
-
else {
|
126
|
-
(_b = target_1 === null || target_1 === void 0 ? void 0 : target_1.onInit) === null || _b === void 0 ? void 0 : _b.call.apply(_b, __spreadArray([target_1], _this.simstanceManager.getParameterSim({ target: target_1, targetKey: targetKey, firstCheckMaker: firstCheckMaker }), false));
|
127
|
-
}
|
128
|
-
}
|
129
|
-
},
|
130
|
-
scripts: { application: _this },
|
131
|
-
applyEvents: [{
|
132
|
-
attrName: 'router-link',
|
133
|
-
callBack: function (elements, attrValue, obj) {
|
134
|
-
elements.addEventListener('click', function (event) {
|
135
|
-
var _a;
|
136
|
-
(_a = _this.getSimstanceManager().getOrNewSim(Navigation_1.Navigation)) === null || _a === void 0 ? void 0 : _a.go(attrValue);
|
137
|
-
});
|
138
|
-
}
|
139
|
-
}],
|
140
|
-
proxyExcludeTyps: _this.domRendoerExcludeProxy
|
141
|
-
};
|
142
|
-
_this.option.window.__dirname = 'simple-boot-front__dirname';
|
143
|
-
var targetAttribute = RawSet_1.RawSet.createComponentTargetAttribute('component', function (element, attrValue, obj, rawSet) {
|
144
|
-
return ScriptUtils_1.ScriptUtils.eval("return ".concat(attrValue), obj);
|
145
|
-
}, function (element, attrValue, obj, rawSet) {
|
146
|
-
if (attrValue) {
|
147
|
-
var targetObj = ScriptUtils_1.ScriptUtils.eval("return ".concat(attrValue), obj);
|
148
|
-
var n = element.cloneNode(true);
|
149
|
-
var innerHTML = _this.getComponentInnerHtml(targetObj);
|
150
|
-
n.innerHTML = innerHTML;
|
151
|
-
return RawSet_1.RawSet.drThisCreate(n, attrValue, '', true, obj, _this.option);
|
152
|
-
}
|
153
|
-
var fag = _this.option.window.document.createDocumentFragment();
|
154
|
-
return fag;
|
155
|
-
});
|
156
|
-
_this.domRenderTargetAttrs.push(targetAttribute);
|
157
|
-
option.proxy = {
|
158
|
-
onProxy: function (it) { return _this.createDomRender(it); }
|
159
|
-
};
|
160
|
-
return _this;
|
161
|
-
}
|
162
|
-
SimpleBootFront.prototype.getComponentInnerHtml = function (targetObj) {
|
163
|
-
var _a, _b, _c;
|
164
|
-
var component = (0, Component_1.getComponent)(targetObj);
|
165
|
-
var styles = ((_b = (_a = component === null || component === void 0 ? void 0 : component.styles) === null || _a === void 0 ? void 0 : _a.map(function (it) { return "<style>".concat(it, "</style>"); })) !== null && _b !== void 0 ? _b : []).join(' ');
|
166
|
-
var template = ((_c = component === null || component === void 0 ? void 0 : component.template) !== null && _c !== void 0 ? _c : '');
|
167
|
-
return styles + template;
|
168
|
-
};
|
169
|
-
SimpleBootFront.prototype.createDomRender = function (obj) {
|
170
|
-
var component = (0, Component_1.getComponent)(obj);
|
171
|
-
if (component && typeof obj === 'object') {
|
172
|
-
return DomRender_1.DomRender.run(obj, undefined, this.domRenderConfig);
|
173
|
-
}
|
174
|
-
return obj;
|
175
|
-
};
|
176
|
-
SimpleBootFront.prototype.initRun = function (otherInstanceSim) {
|
177
|
-
var _this = this;
|
178
|
-
_super.prototype.run.call(this, otherInstanceSim);
|
179
|
-
this.initDomRenderScripts();
|
180
|
-
this.initDomRenderTargetElements();
|
181
|
-
this.navigation = this.simstanceManager.getOrNewSim(Navigation_1.Navigation);
|
182
|
-
this.initWriteRootRouter();
|
183
|
-
this.option.window.addEventListener('intent', function (event) {
|
184
|
-
var cevent = event;
|
185
|
-
_this.publishIntent(new Intent_1.Intent(cevent.detail.uri, cevent.detail.data, event));
|
186
|
-
});
|
187
|
-
this.option.window.addEventListener('popstate', function (event) {
|
188
|
-
var intent = new Intent_1.Intent(_this.navigation.url || '/');
|
189
|
-
_this.routing(intent).then(function (it) {
|
190
|
-
_this.afterSetting();
|
191
|
-
});
|
192
|
-
});
|
193
|
-
};
|
194
|
-
SimpleBootFront.prototype.initWriteRootRouter = function () {
|
195
|
-
var _a;
|
196
|
-
var routerAtomic = this.writeRootRouter();
|
197
|
-
var target = this.option.window.document.querySelector(this.option.selector);
|
198
|
-
if (target && routerAtomic && routerAtomic.value) {
|
199
|
-
var val = routerAtomic.value;
|
200
|
-
var domRenderProxy = val._DomRender_proxy;
|
201
|
-
domRenderProxy.initRender(target);
|
202
|
-
(_a = val === null || val === void 0 ? void 0 : val.onInit) === null || _a === void 0 ? void 0 : _a.call(val);
|
203
|
-
}
|
204
|
-
};
|
205
|
-
SimpleBootFront.prototype.writeRootRouter = function () {
|
206
|
-
var _a, _b, _c;
|
207
|
-
var routerAtomic = new SimAtomic_1.SimAtomic(this.rootRouter, this.getSimstanceManager());
|
208
|
-
var target = this.option.window.document.querySelector(this.option.selector);
|
209
|
-
if (target && routerAtomic.value) {
|
210
|
-
var component = routerAtomic.getConfig(Component_1.ComponentMetadataKey);
|
211
|
-
var styles = ((_b = (_a = component === null || component === void 0 ? void 0 : component.styles) === null || _a === void 0 ? void 0 : _a.map(function (it) { return "<style>".concat(it, "</style>"); })) !== null && _b !== void 0 ? _b : []).join(' ');
|
212
|
-
target.innerHTML = "".concat(styles, " ").concat((_c = component === null || component === void 0 ? void 0 : component.template) !== null && _c !== void 0 ? _c : '');
|
213
|
-
}
|
214
|
-
return routerAtomic;
|
215
|
-
};
|
216
|
-
SimpleBootFront.prototype.goRouting = function (url) {
|
217
|
-
var _a;
|
218
|
-
return __awaiter(this, void 0, void 0, function () {
|
219
|
-
var intent, data;
|
220
|
-
return __generator(this, function (_b) {
|
221
|
-
switch (_b.label) {
|
222
|
-
case 0:
|
223
|
-
this.navigation.goNoPopStateEvent(url);
|
224
|
-
intent = new Intent_1.Intent((_a = this.navigation.url) !== null && _a !== void 0 ? _a : '');
|
225
|
-
return [4, this.routing(intent)];
|
226
|
-
case 1:
|
227
|
-
data = _b.sent();
|
228
|
-
this.afterSetting();
|
229
|
-
return [2, data];
|
230
|
-
}
|
231
|
-
});
|
232
|
-
});
|
233
|
-
};
|
234
|
-
SimpleBootFront.prototype.runRouting = function (otherInstanceSim, url) {
|
235
|
-
var _a;
|
236
|
-
return __awaiter(this, void 0, void 0, function () {
|
237
|
-
var intent, data;
|
238
|
-
return __generator(this, function (_b) {
|
239
|
-
switch (_b.label) {
|
240
|
-
case 0:
|
241
|
-
this.initRun(otherInstanceSim);
|
242
|
-
if (url) {
|
243
|
-
this.navigation.goNoPopStateEvent(url);
|
244
|
-
}
|
245
|
-
intent = new Intent_1.Intent((_a = this.navigation.url) !== null && _a !== void 0 ? _a : '');
|
246
|
-
return [4, this.routing(intent)];
|
247
|
-
case 1:
|
248
|
-
data = _b.sent();
|
249
|
-
this.afterSetting();
|
250
|
-
return [2, data];
|
251
|
-
}
|
252
|
-
});
|
253
|
-
});
|
254
|
-
};
|
255
|
-
SimpleBootFront.prototype.run = function (otherInstanceSim, url) {
|
256
|
-
this.initRun(otherInstanceSim);
|
257
|
-
if (url) {
|
258
|
-
this.navigation.go(url);
|
259
|
-
}
|
260
|
-
this.option.window.dispatchEvent(new Event('popstate'));
|
261
|
-
};
|
262
|
-
SimpleBootFront.prototype.afterSetting = function () {
|
263
|
-
var _this = this;
|
264
|
-
this.option.window.document.querySelectorAll('[router-link]').forEach(function (it) {
|
265
|
-
var _a, _b, _c, _d;
|
266
|
-
var link = it.getAttribute('router-link');
|
267
|
-
if (link) {
|
268
|
-
var activeClasss = it.getAttribute('router-active-class');
|
269
|
-
var aClasss = activeClasss === null || activeClasss === void 0 ? void 0 : activeClasss.split(',');
|
270
|
-
var inActiveClasss = it.getAttribute('router-inactive-class');
|
271
|
-
var iClasss = inActiveClasss === null || inActiveClasss === void 0 ? void 0 : inActiveClasss.split(',');
|
272
|
-
if (_this.navigation.path === link) {
|
273
|
-
if (aClasss && aClasss.length > 0) {
|
274
|
-
(_a = it.classList).add.apply(_a, aClasss);
|
275
|
-
}
|
276
|
-
if (iClasss && iClasss.length > 0) {
|
277
|
-
(_b = it.classList).remove.apply(_b, iClasss);
|
278
|
-
}
|
279
|
-
}
|
280
|
-
else {
|
281
|
-
if (aClasss && aClasss.length > 0) {
|
282
|
-
(_c = it.classList).remove.apply(_c, aClasss);
|
283
|
-
}
|
284
|
-
if (iClasss && iClasss.length > 0) {
|
285
|
-
(_d = it.classList).add.apply(_d, iClasss);
|
286
|
-
}
|
287
|
-
}
|
288
|
-
}
|
289
|
-
});
|
290
|
-
};
|
291
|
-
SimpleBootFront.prototype.initDomRenderScripts = function () {
|
292
|
-
var _this = this;
|
293
|
-
var simstanceManager = this.simstanceManager;
|
294
|
-
Script_1.scripts.forEach(function (val, name) {
|
295
|
-
_this.domRenderConfig.scripts[name] = function () {
|
296
|
-
var args = [];
|
297
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
298
|
-
args[_i] = arguments[_i];
|
299
|
-
}
|
300
|
-
var obj;
|
301
|
-
try {
|
302
|
-
obj = simstanceManager.getOrNewSim(val);
|
303
|
-
}
|
304
|
-
catch (e) {
|
305
|
-
obj = simstanceManager.newSim(val);
|
306
|
-
}
|
307
|
-
var render = this.__render;
|
308
|
-
var scriptRunnable = obj;
|
309
|
-
if (render.rawset) {
|
310
|
-
scriptRunnable.rawSets.set(render.rawset, this);
|
311
|
-
}
|
312
|
-
return scriptRunnable.run.apply(scriptRunnable, args);
|
313
|
-
};
|
314
|
-
});
|
315
|
-
};
|
316
|
-
SimpleBootFront.prototype.initDomRenderTargetElements = function () {
|
317
|
-
var _this = this;
|
318
|
-
var selectors = Component_1.componentSelectors;
|
319
|
-
selectors.forEach(function (val, name) {
|
320
|
-
var component = (0, Component_1.getComponent)(val);
|
321
|
-
var items = RawSet_1.RawSet.createComponentTargetElement(name, function (e, obj, r) {
|
322
|
-
var newSim = _this.simstanceManager.newSim(val);
|
323
|
-
return newSim;
|
324
|
-
}, component === null || component === void 0 ? void 0 : component.template, component === null || component === void 0 ? void 0 : component.styles, _this.domRenderConfig);
|
325
|
-
_this.domRenderTargetElements.push(items);
|
326
|
-
});
|
327
|
-
};
|
328
|
-
SimpleBootFront.prototype.getSimstanceManager = function () {
|
329
|
-
return this.simstanceManager;
|
330
|
-
};
|
331
|
-
SimpleBootFront.prototype.go = function (url) {
|
332
|
-
var _a;
|
333
|
-
(_a = this.getSimstanceManager().getOrNewSim(Navigation_1.Navigation)) === null || _a === void 0 ? void 0 : _a.go(url);
|
334
|
-
};
|
335
|
-
return SimpleBootFront;
|
336
|
-
}(SimpleApplication_1.SimpleApplication));
|
337
|
-
exports.SimpleBootFront = SimpleBootFront;
|
1
|
+
"use strict";
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
3
|
+
var extendStatics = function (d, b) {
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
7
|
+
return extendStatics(d, b);
|
8
|
+
};
|
9
|
+
return function (d, b) {
|
10
|
+
if (typeof b !== "function" && b !== null)
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
12
|
+
extendStatics(d, b);
|
13
|
+
function __() { this.constructor = d; }
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15
|
+
};
|
16
|
+
})();
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
24
|
+
});
|
25
|
+
};
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
30
|
+
function step(op) {
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
32
|
+
while (_) try {
|
33
|
+
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;
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
35
|
+
switch (op[0]) {
|
36
|
+
case 0: case 1: t = op; break;
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
40
|
+
default:
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
45
|
+
if (t[2]) _.ops.pop();
|
46
|
+
_.trys.pop(); continue;
|
47
|
+
}
|
48
|
+
op = body.call(thisArg, _);
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
51
|
+
}
|
52
|
+
};
|
53
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
54
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
55
|
+
if (ar || !(i in from)) {
|
56
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
57
|
+
ar[i] = from[i];
|
58
|
+
}
|
59
|
+
}
|
60
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
61
|
+
};
|
62
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
63
|
+
exports.SimpleBootFront = void 0;
|
64
|
+
var SimFrontOption_1 = require("./option/SimFrontOption");
|
65
|
+
var Component_1 = require("./decorators/Component");
|
66
|
+
var Script_1 = require("./decorators/Script");
|
67
|
+
var DomRender_1 = require("dom-render/DomRender");
|
68
|
+
var SimAtomic_1 = require("simple-boot-core/simstance/SimAtomic");
|
69
|
+
var SimpleApplication_1 = require("simple-boot-core/SimpleApplication");
|
70
|
+
var Intent_1 = require("simple-boot-core/intent/Intent");
|
71
|
+
var Navigation_1 = require("./service/Navigation");
|
72
|
+
var ViewService_1 = require("./service/view/ViewService");
|
73
|
+
var HttpService_1 = require("./service/HttpService");
|
74
|
+
var SimstanceManager_1 = require("simple-boot-core/simstance/SimstanceManager");
|
75
|
+
var IntentManager_1 = require("simple-boot-core/intent/IntentManager");
|
76
|
+
var RouterManager_1 = require("simple-boot-core/route/RouterManager");
|
77
|
+
var ScriptUtils_1 = require("dom-render/utils/script/ScriptUtils");
|
78
|
+
var RawSet_1 = require("dom-render/RawSet");
|
79
|
+
var Types_1 = require("dom-render/types/Types");
|
80
|
+
var InjectFrontSituationType_1 = require("./decorators/inject/InjectFrontSituationType");
|
81
|
+
var SimpleBootFront = (function (_super) {
|
82
|
+
__extends(SimpleBootFront, _super);
|
83
|
+
function SimpleBootFront(rootRouter, option) {
|
84
|
+
var _this = _super.call(this, rootRouter, option) || this;
|
85
|
+
_this.rootRouter = rootRouter;
|
86
|
+
_this.option = option;
|
87
|
+
_this.domRendoerExcludeProxy = [SimpleApplication_1.SimpleApplication, IntentManager_1.IntentManager, RouterManager_1.RouterManager, SimstanceManager_1.SimstanceManager, SimFrontOption_1.SimFrontOption, Navigation_1.Navigation, ViewService_1.ViewService, HttpService_1.HttpService, HTMLElement];
|
88
|
+
_this.domRenderTargetElements = [];
|
89
|
+
_this.domRenderTargetAttrs = [];
|
90
|
+
_this.domRenderConfig = {
|
91
|
+
routerType: 'none',
|
92
|
+
window: option.window,
|
93
|
+
targetElements: _this.domRenderTargetElements,
|
94
|
+
targetAttrs: _this.domRenderTargetAttrs,
|
95
|
+
onElementInit: function (name, obj, rawSet, targetElement) {
|
96
|
+
var _a, _b, _c;
|
97
|
+
var target = (_a = targetElement === null || targetElement === void 0 ? void 0 : targetElement.__render) === null || _a === void 0 ? void 0 : _a.component;
|
98
|
+
var targetKey = 'onInit';
|
99
|
+
var firstCheckMaker = [function (ownerObj, type, idx, saveInjectionConfig) {
|
100
|
+
if (InjectFrontSituationType_1.InjectFrontSituationType.OPENER === (saveInjectionConfig === null || saveInjectionConfig === void 0 ? void 0 : saveInjectionConfig.config.situationType) && rawSet.point.thisVariableName) {
|
101
|
+
return new Proxy(ScriptUtils_1.ScriptUtils.evalReturn(rawSet.point.thisVariableName, obj), new Types_1.DomRenderFinalProxy());
|
102
|
+
}
|
103
|
+
}];
|
104
|
+
if (rawSet.point.thisVariableName) {
|
105
|
+
(_b = target === null || target === void 0 ? void 0 : target.onInit) === null || _b === void 0 ? void 0 : _b.call.apply(_b, __spreadArray([target], _this.simstanceManager.getParameterSim({ target: target, targetKey: targetKey, firstCheckMaker: firstCheckMaker }), false));
|
106
|
+
}
|
107
|
+
else {
|
108
|
+
(_c = target === null || target === void 0 ? void 0 : target.onInit) === null || _c === void 0 ? void 0 : _c.call.apply(_c, __spreadArray([target], _this.simstanceManager.getParameterSim({ target: target, targetKey: targetKey, firstCheckMaker: firstCheckMaker }), false));
|
109
|
+
}
|
110
|
+
},
|
111
|
+
onAttrInit: function (attrName, attrValue, obj, rawSet) {
|
112
|
+
var _a, _b;
|
113
|
+
if (attrName === 'component') {
|
114
|
+
var target_1 = ScriptUtils_1.ScriptUtils.evalReturn(attrValue, obj);
|
115
|
+
var targetKey = 'onInit';
|
116
|
+
var firstCheckMaker = [function (obj, type, idx, saveInjectionConfig) {
|
117
|
+
var _a, _b;
|
118
|
+
if (InjectFrontSituationType_1.InjectFrontSituationType.OPENER === (saveInjectionConfig === null || saveInjectionConfig === void 0 ? void 0 : saveInjectionConfig.config.situationType) && ((_a = target_1 === null || target_1 === void 0 ? void 0 : target_1.__domrender_component_new) === null || _a === void 0 ? void 0 : _a.creator)) {
|
119
|
+
return (_b = target_1 === null || target_1 === void 0 ? void 0 : target_1.__domrender_component_new) === null || _b === void 0 ? void 0 : _b.creator;
|
120
|
+
}
|
121
|
+
}];
|
122
|
+
if (rawSet.point.thisVariableName) {
|
123
|
+
(_a = target_1 === null || target_1 === void 0 ? void 0 : target_1.onInit) === null || _a === void 0 ? void 0 : _a.call.apply(_a, __spreadArray([target_1], _this.simstanceManager.getParameterSim({ target: target_1, targetKey: targetKey, firstCheckMaker: firstCheckMaker }), false));
|
124
|
+
}
|
125
|
+
else {
|
126
|
+
(_b = target_1 === null || target_1 === void 0 ? void 0 : target_1.onInit) === null || _b === void 0 ? void 0 : _b.call.apply(_b, __spreadArray([target_1], _this.simstanceManager.getParameterSim({ target: target_1, targetKey: targetKey, firstCheckMaker: firstCheckMaker }), false));
|
127
|
+
}
|
128
|
+
}
|
129
|
+
},
|
130
|
+
scripts: { application: _this },
|
131
|
+
applyEvents: [{
|
132
|
+
attrName: 'router-link',
|
133
|
+
callBack: function (elements, attrValue, obj) {
|
134
|
+
elements.addEventListener('click', function (event) {
|
135
|
+
var _a;
|
136
|
+
(_a = _this.getSimstanceManager().getOrNewSim(Navigation_1.Navigation)) === null || _a === void 0 ? void 0 : _a.go(attrValue);
|
137
|
+
});
|
138
|
+
}
|
139
|
+
}],
|
140
|
+
proxyExcludeTyps: _this.domRendoerExcludeProxy
|
141
|
+
};
|
142
|
+
_this.option.window.__dirname = 'simple-boot-front__dirname';
|
143
|
+
var targetAttribute = RawSet_1.RawSet.createComponentTargetAttribute('component', function (element, attrValue, obj, rawSet) {
|
144
|
+
return ScriptUtils_1.ScriptUtils.eval("return ".concat(attrValue), obj);
|
145
|
+
}, function (element, attrValue, obj, rawSet) {
|
146
|
+
if (attrValue) {
|
147
|
+
var targetObj = ScriptUtils_1.ScriptUtils.eval("return ".concat(attrValue), obj);
|
148
|
+
var n = element.cloneNode(true);
|
149
|
+
var innerHTML = _this.getComponentInnerHtml(targetObj);
|
150
|
+
n.innerHTML = innerHTML;
|
151
|
+
return RawSet_1.RawSet.drThisCreate(n, attrValue, '', true, obj, _this.option);
|
152
|
+
}
|
153
|
+
var fag = _this.option.window.document.createDocumentFragment();
|
154
|
+
return fag;
|
155
|
+
});
|
156
|
+
_this.domRenderTargetAttrs.push(targetAttribute);
|
157
|
+
option.proxy = {
|
158
|
+
onProxy: function (it) { return _this.createDomRender(it); }
|
159
|
+
};
|
160
|
+
return _this;
|
161
|
+
}
|
162
|
+
SimpleBootFront.prototype.getComponentInnerHtml = function (targetObj) {
|
163
|
+
var _a, _b, _c;
|
164
|
+
var component = (0, Component_1.getComponent)(targetObj);
|
165
|
+
var styles = ((_b = (_a = component === null || component === void 0 ? void 0 : component.styles) === null || _a === void 0 ? void 0 : _a.map(function (it) { return "<style>".concat(it, "</style>"); })) !== null && _b !== void 0 ? _b : []).join(' ');
|
166
|
+
var template = ((_c = component === null || component === void 0 ? void 0 : component.template) !== null && _c !== void 0 ? _c : '');
|
167
|
+
return styles + template;
|
168
|
+
};
|
169
|
+
SimpleBootFront.prototype.createDomRender = function (obj) {
|
170
|
+
var component = (0, Component_1.getComponent)(obj);
|
171
|
+
if (component && typeof obj === 'object') {
|
172
|
+
return DomRender_1.DomRender.run(obj, undefined, this.domRenderConfig);
|
173
|
+
}
|
174
|
+
return obj;
|
175
|
+
};
|
176
|
+
SimpleBootFront.prototype.initRun = function (otherInstanceSim) {
|
177
|
+
var _this = this;
|
178
|
+
_super.prototype.run.call(this, otherInstanceSim);
|
179
|
+
this.initDomRenderScripts();
|
180
|
+
this.initDomRenderTargetElements();
|
181
|
+
this.navigation = this.simstanceManager.getOrNewSim(Navigation_1.Navigation);
|
182
|
+
this.initWriteRootRouter();
|
183
|
+
this.option.window.addEventListener('intent', function (event) {
|
184
|
+
var cevent = event;
|
185
|
+
_this.publishIntent(new Intent_1.Intent(cevent.detail.uri, cevent.detail.data, event));
|
186
|
+
});
|
187
|
+
this.option.window.addEventListener('popstate', function (event) {
|
188
|
+
var intent = new Intent_1.Intent(_this.navigation.url || '/');
|
189
|
+
_this.routing(intent).then(function (it) {
|
190
|
+
_this.afterSetting();
|
191
|
+
});
|
192
|
+
});
|
193
|
+
};
|
194
|
+
SimpleBootFront.prototype.initWriteRootRouter = function () {
|
195
|
+
var _a;
|
196
|
+
var routerAtomic = this.writeRootRouter();
|
197
|
+
var target = this.option.window.document.querySelector(this.option.selector);
|
198
|
+
if (target && routerAtomic && routerAtomic.value) {
|
199
|
+
var val = routerAtomic.value;
|
200
|
+
var domRenderProxy = val._DomRender_proxy;
|
201
|
+
domRenderProxy.initRender(target);
|
202
|
+
(_a = val === null || val === void 0 ? void 0 : val.onInit) === null || _a === void 0 ? void 0 : _a.call(val);
|
203
|
+
}
|
204
|
+
};
|
205
|
+
SimpleBootFront.prototype.writeRootRouter = function () {
|
206
|
+
var _a, _b, _c;
|
207
|
+
var routerAtomic = new SimAtomic_1.SimAtomic(this.rootRouter, this.getSimstanceManager());
|
208
|
+
var target = this.option.window.document.querySelector(this.option.selector);
|
209
|
+
if (target && routerAtomic.value) {
|
210
|
+
var component = routerAtomic.getConfig(Component_1.ComponentMetadataKey);
|
211
|
+
var styles = ((_b = (_a = component === null || component === void 0 ? void 0 : component.styles) === null || _a === void 0 ? void 0 : _a.map(function (it) { return "<style>".concat(it, "</style>"); })) !== null && _b !== void 0 ? _b : []).join(' ');
|
212
|
+
target.innerHTML = "".concat(styles, " ").concat((_c = component === null || component === void 0 ? void 0 : component.template) !== null && _c !== void 0 ? _c : '');
|
213
|
+
}
|
214
|
+
return routerAtomic;
|
215
|
+
};
|
216
|
+
SimpleBootFront.prototype.goRouting = function (url) {
|
217
|
+
var _a;
|
218
|
+
return __awaiter(this, void 0, void 0, function () {
|
219
|
+
var intent, data;
|
220
|
+
return __generator(this, function (_b) {
|
221
|
+
switch (_b.label) {
|
222
|
+
case 0:
|
223
|
+
this.navigation.goNoPopStateEvent(url);
|
224
|
+
intent = new Intent_1.Intent((_a = this.navigation.url) !== null && _a !== void 0 ? _a : '');
|
225
|
+
return [4, this.routing(intent)];
|
226
|
+
case 1:
|
227
|
+
data = _b.sent();
|
228
|
+
this.afterSetting();
|
229
|
+
return [2, data];
|
230
|
+
}
|
231
|
+
});
|
232
|
+
});
|
233
|
+
};
|
234
|
+
SimpleBootFront.prototype.runRouting = function (otherInstanceSim, url) {
|
235
|
+
var _a;
|
236
|
+
return __awaiter(this, void 0, void 0, function () {
|
237
|
+
var intent, data;
|
238
|
+
return __generator(this, function (_b) {
|
239
|
+
switch (_b.label) {
|
240
|
+
case 0:
|
241
|
+
this.initRun(otherInstanceSim);
|
242
|
+
if (url) {
|
243
|
+
this.navigation.goNoPopStateEvent(url);
|
244
|
+
}
|
245
|
+
intent = new Intent_1.Intent((_a = this.navigation.url) !== null && _a !== void 0 ? _a : '');
|
246
|
+
return [4, this.routing(intent)];
|
247
|
+
case 1:
|
248
|
+
data = _b.sent();
|
249
|
+
this.afterSetting();
|
250
|
+
return [2, data];
|
251
|
+
}
|
252
|
+
});
|
253
|
+
});
|
254
|
+
};
|
255
|
+
SimpleBootFront.prototype.run = function (otherInstanceSim, url) {
|
256
|
+
this.initRun(otherInstanceSim);
|
257
|
+
if (url) {
|
258
|
+
this.navigation.go(url);
|
259
|
+
}
|
260
|
+
this.option.window.dispatchEvent(new Event('popstate'));
|
261
|
+
};
|
262
|
+
SimpleBootFront.prototype.afterSetting = function () {
|
263
|
+
var _this = this;
|
264
|
+
this.option.window.document.querySelectorAll('[router-link]').forEach(function (it) {
|
265
|
+
var _a, _b, _c, _d;
|
266
|
+
var link = it.getAttribute('router-link');
|
267
|
+
if (link) {
|
268
|
+
var activeClasss = it.getAttribute('router-active-class');
|
269
|
+
var aClasss = activeClasss === null || activeClasss === void 0 ? void 0 : activeClasss.split(',');
|
270
|
+
var inActiveClasss = it.getAttribute('router-inactive-class');
|
271
|
+
var iClasss = inActiveClasss === null || inActiveClasss === void 0 ? void 0 : inActiveClasss.split(',');
|
272
|
+
if (_this.navigation.path === link) {
|
273
|
+
if (aClasss && aClasss.length > 0) {
|
274
|
+
(_a = it.classList).add.apply(_a, aClasss);
|
275
|
+
}
|
276
|
+
if (iClasss && iClasss.length > 0) {
|
277
|
+
(_b = it.classList).remove.apply(_b, iClasss);
|
278
|
+
}
|
279
|
+
}
|
280
|
+
else {
|
281
|
+
if (aClasss && aClasss.length > 0) {
|
282
|
+
(_c = it.classList).remove.apply(_c, aClasss);
|
283
|
+
}
|
284
|
+
if (iClasss && iClasss.length > 0) {
|
285
|
+
(_d = it.classList).add.apply(_d, iClasss);
|
286
|
+
}
|
287
|
+
}
|
288
|
+
}
|
289
|
+
});
|
290
|
+
};
|
291
|
+
SimpleBootFront.prototype.initDomRenderScripts = function () {
|
292
|
+
var _this = this;
|
293
|
+
var simstanceManager = this.simstanceManager;
|
294
|
+
Script_1.scripts.forEach(function (val, name) {
|
295
|
+
_this.domRenderConfig.scripts[name] = function () {
|
296
|
+
var args = [];
|
297
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
298
|
+
args[_i] = arguments[_i];
|
299
|
+
}
|
300
|
+
var obj;
|
301
|
+
try {
|
302
|
+
obj = simstanceManager.getOrNewSim(val);
|
303
|
+
}
|
304
|
+
catch (e) {
|
305
|
+
obj = simstanceManager.newSim(val);
|
306
|
+
}
|
307
|
+
var render = this.__render;
|
308
|
+
var scriptRunnable = obj;
|
309
|
+
if (render.rawset) {
|
310
|
+
scriptRunnable.rawSets.set(render.rawset, this);
|
311
|
+
}
|
312
|
+
return scriptRunnable.run.apply(scriptRunnable, args);
|
313
|
+
};
|
314
|
+
});
|
315
|
+
};
|
316
|
+
SimpleBootFront.prototype.initDomRenderTargetElements = function () {
|
317
|
+
var _this = this;
|
318
|
+
var selectors = Component_1.componentSelectors;
|
319
|
+
selectors.forEach(function (val, name) {
|
320
|
+
var component = (0, Component_1.getComponent)(val);
|
321
|
+
var items = RawSet_1.RawSet.createComponentTargetElement(name, function (e, obj, r) {
|
322
|
+
var newSim = _this.simstanceManager.newSim(val);
|
323
|
+
return newSim;
|
324
|
+
}, component === null || component === void 0 ? void 0 : component.template, component === null || component === void 0 ? void 0 : component.styles, false, _this.domRenderConfig);
|
325
|
+
_this.domRenderTargetElements.push(items);
|
326
|
+
});
|
327
|
+
};
|
328
|
+
SimpleBootFront.prototype.getSimstanceManager = function () {
|
329
|
+
return this.simstanceManager;
|
330
|
+
};
|
331
|
+
SimpleBootFront.prototype.go = function (url) {
|
332
|
+
var _a;
|
333
|
+
(_a = this.getSimstanceManager().getOrNewSim(Navigation_1.Navigation)) === null || _a === void 0 ? void 0 : _a.go(url);
|
334
|
+
};
|
335
|
+
return SimpleBootFront;
|
336
|
+
}(SimpleApplication_1.SimpleApplication));
|
337
|
+
exports.SimpleBootFront = SimpleBootFront;
|