@dooboostore/dom-render 1.0.102 → 1.0.103
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/DomRender.d.ts +21 -6
- package/DomRender.js +54 -23
- package/DomRenderProxy.d.ts +7 -3
- package/DomRenderProxy.js +120 -49
- package/README.MD +380 -65
- package/components/ComponentBase.d.ts +11 -9
- package/components/ComponentBase.js +41 -14
- package/components/ComponentSet.d.ts +2 -2
- package/components/appender/Appender.d.ts +2 -2
- package/components/checkbox/CheckBox.d.ts +4 -4
- package/components/choose/Choose.d.ts +4 -4
- package/components/choose/Choose.js +0 -16
- package/components/details/Details.d.ts +5 -5
- package/components/forOf/ForOf.d.ts +2 -2
- package/components/if/If.d.ts +2 -2
- package/components/index.d.ts +26 -24
- package/components/index.js +2 -1
- package/components/input/Input.d.ts +2 -2
- package/components/input/Input.js +27 -24
- package/components/promise/PromiseSwitch.d.ts +6 -6
- package/components/promise/PromiseSwitch.js +15 -0
- package/components/radio/Radio.d.ts +4 -4
- package/components/router/Route.d.ts +32 -0
- package/components/router/Route.js +116 -0
- package/components/select/Select.d.ts +3 -3
- package/components/select/Select.js +2 -2
- package/components/this/This.d.ts +9 -2
- package/components/this/This.js +24 -2
- package/components/timer/Timer.d.ts +2 -2
- package/configs/Config.d.ts +6 -1
- package/decorators/DomRenderNoProxy.d.ts +2 -0
- package/decorators/DomRenderNoProxy.js +15 -0
- package/dist/bundle.js +2 -0
- package/events/EventManager.d.ts +16 -4
- package/events/EventManager.js +320 -140
- package/index.d.ts +48 -1
- package/index.js +40 -0
- package/lifecycle/OnDestroyRender.d.ts +1 -1
- package/lifecycle/OnProxyDomRender.d.ts +1 -0
- package/lifecycle/OnProxyDomRender.js +1 -1
- package/operators/DrForOf.js +2 -1
- package/operators/DrIf.js +3 -2
- package/operators/DrTargetElement.js +2 -1
- package/operators/DrTargetElementIsElement.d.ts +0 -5
- package/operators/DrTargetElementIsElement.js +2 -1
- package/operators/DrThis.js +40 -11
- package/operators/OperatorExecuter.js +3 -1
- package/package.json +5 -4
- package/rawsets/Attrs.d.ts +2 -0
- package/rawsets/RawSet.d.ts +2 -2
- package/rawsets/RawSet.js +48 -33
- package/routers/HashRouter.d.ts +5 -4
- package/routers/HashRouter.js +8 -5
- package/routers/PathRouter.d.ts +5 -4
- package/routers/PathRouter.js +6 -4
- package/routers/Router.d.ts +22 -8
- package/routers/Router.js +44 -24
package/rawsets/RawSet.js
CHANGED
|
@@ -10,9 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { RandomUtils } from '@dooboostore/core/random/RandomUtils';
|
|
11
11
|
import { StringUtils } from '@dooboostore/core/string/StringUtils';
|
|
12
12
|
import { ScriptUtils } from '@dooboostore/core-web/script/ScriptUtils';
|
|
13
|
-
import { EventManager
|
|
13
|
+
import { EventManager } from '../events/EventManager';
|
|
14
14
|
import { Range } from '../iterators/Range';
|
|
15
|
-
import {
|
|
15
|
+
import { ElementUtils } from '@dooboostore/core-web/element/ElementUtils';
|
|
16
16
|
import { DrPre } from '../operators/DrPre';
|
|
17
17
|
import { Dr } from '../operators/Dr';
|
|
18
18
|
import { DrIf } from '../operators/DrIf';
|
|
@@ -40,6 +40,7 @@ import { isOnInitRender } from '../lifecycle/OnInitRender';
|
|
|
40
40
|
import { isOnCreatedThisChild } from '../lifecycle/OnCreatedThisChild';
|
|
41
41
|
import { isOnDestroyRender } from '../lifecycle/OnDestroyRender';
|
|
42
42
|
import { DrTargetElementIsElement } from '../operators/DrTargetElementIsElement';
|
|
43
|
+
import { ObjectUtils } from '@dooboostore/core';
|
|
43
44
|
export class RawSet {
|
|
44
45
|
constructor(uuid, type, point, dataSet, detect) {
|
|
45
46
|
this.uuid = uuid;
|
|
@@ -49,13 +50,18 @@ export class RawSet {
|
|
|
49
50
|
this.detect = detect;
|
|
50
51
|
this.findNearThis = (obj, rawSet = this) => {
|
|
51
52
|
const path = this.findNearThisPath(rawSet);
|
|
52
|
-
if (path)
|
|
53
|
-
|
|
53
|
+
if (path) {
|
|
54
|
+
const optionalPath = ObjectUtils.Path.toOptionalChainPath(path);
|
|
55
|
+
// console.log('ppppp-', path, optionalPath)
|
|
56
|
+
return ScriptUtils.evalReturn(optionalPath, obj);
|
|
57
|
+
}
|
|
54
58
|
};
|
|
55
59
|
this.findParentThis = (obj, rawSet = this) => {
|
|
56
60
|
const path = this.findParentThisPath(rawSet);
|
|
57
|
-
if (path)
|
|
58
|
-
|
|
61
|
+
if (path) {
|
|
62
|
+
const optionalPath = ObjectUtils.Path.toOptionalChainPath(path);
|
|
63
|
+
return ScriptUtils.evalReturn(optionalPath, obj);
|
|
64
|
+
}
|
|
59
65
|
};
|
|
60
66
|
this.findNearThisPath = (rawSet = this) => {
|
|
61
67
|
const paths = this.findThisPaths(rawSet);
|
|
@@ -151,7 +157,7 @@ export class RawSet {
|
|
|
151
157
|
// 중요 render 처리 부분
|
|
152
158
|
render(obj, config) {
|
|
153
159
|
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
160
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
155
161
|
// console.log('render!!!!!!!!!!!!!!')
|
|
156
162
|
const genNode = config.window.document.importNode(this.dataSet.fragment, true);
|
|
157
163
|
const raws = [];
|
|
@@ -164,7 +170,7 @@ export class RawSet {
|
|
|
164
170
|
// console.log('cNodecNodecNode', cNode);
|
|
165
171
|
let attribute = {};
|
|
166
172
|
if (cNode.nodeType === Node.ELEMENT_NODE) {
|
|
167
|
-
attribute =
|
|
173
|
+
attribute = ElementUtils.getAttributeToObject(cNode);
|
|
168
174
|
}
|
|
169
175
|
const __render = Object.freeze({
|
|
170
176
|
rawSet: this,
|
|
@@ -177,7 +183,7 @@ export class RawSet {
|
|
|
177
183
|
scriptUtils: ScriptUtils,
|
|
178
184
|
nearThis: this.findNearThis(obj),
|
|
179
185
|
parentThis: this.findParentThis(obj),
|
|
180
|
-
bindScript: `
|
|
186
|
+
bindScript: ` /** render **/
|
|
181
187
|
const ${EventManager.SCRIPTS_VARNAME} = this.__render.scripts;
|
|
182
188
|
const ${EventManager.RAWSET_VARNAME} = this.__render.rawSet;
|
|
183
189
|
const ${EventManager.ELEMENT_VARNAME} = this.__render.element;
|
|
@@ -242,6 +248,7 @@ export class RawSet {
|
|
|
242
248
|
drStripElement: this.getAttributeAndDelete(element, RawSet.DR_STRIP_NAME),
|
|
243
249
|
drReplaceTargetElementIs: this.getAttributeAndDelete(element, RawSet.DR_REPLACE_TARGET_ELEMENT_IS_NAME),
|
|
244
250
|
drItOption: this.getAttributeAndDelete(element, RawSet.DR_IT_OPTIONNAME),
|
|
251
|
+
drIfOption: this.getAttributeAndDelete(element, RawSet.DR_IF_OPTIONNAME),
|
|
245
252
|
drVarOption: this.getAttributeAndDelete(element, RawSet.DR_VAR_OPTIONNAME),
|
|
246
253
|
drNextOption: this.getAttributeAndDelete(element, RawSet.DR_NEXT_OPTIONNAME),
|
|
247
254
|
drAfterOption: this.getAttributeAndDelete(element, RawSet.DR_AFTER_OPTIONNAME),
|
|
@@ -249,7 +256,9 @@ export class RawSet {
|
|
|
249
256
|
drCompleteOption: this.getAttributeAndDelete(element, RawSet.DR_COMPLETE_OPTIONNAME),
|
|
250
257
|
drStripOption: this.getAttributeAndDelete(element, RawSet.DR_STRIP_OPTIONNAME),
|
|
251
258
|
drDestroyOption: this.getAttributeAndDelete(element, RawSet.DR_DESTROY_OPTIONNAME),
|
|
252
|
-
drKeyOption: this.getAttributeAndDelete(element, RawSet.DR_KEY_OPTIONNAME)
|
|
259
|
+
drKeyOption: this.getAttributeAndDelete(element, RawSet.DR_KEY_OPTIONNAME),
|
|
260
|
+
drDetectIfOption: this.getAttribute(element, RawSet.DR_DETECT_IF_OPTIONNAME),
|
|
261
|
+
drHasKeysOption: this.getAttribute(element, RawSet.DR_HAS_KEYS_OPTIONNAME),
|
|
253
262
|
};
|
|
254
263
|
drAttrs.push(drAttr);
|
|
255
264
|
// 아래 순서 중요
|
|
@@ -318,7 +327,7 @@ export class RawSet {
|
|
|
318
327
|
}
|
|
319
328
|
}
|
|
320
329
|
for (const it of onElementInitCallBacks) {
|
|
321
|
-
if (isOnInitRender(this.dataSet.render.currentThis)) {
|
|
330
|
+
if (isOnInitRender((_s = this.dataSet.render) === null || _s === void 0 ? void 0 : _s.currentThis)) {
|
|
322
331
|
// TODO: 나중에 파라미터 들어가야될듯. 지금은 리팩토링하느라 빠짐
|
|
323
332
|
// console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!', it, this.dataSet);
|
|
324
333
|
// dr-on-init:arguments
|
|
@@ -344,20 +353,20 @@ export class RawSet {
|
|
|
344
353
|
// }
|
|
345
354
|
this.dataSet.render.currentThis.onInitRender({}, this);
|
|
346
355
|
}
|
|
347
|
-
(
|
|
356
|
+
(_t = config === null || config === void 0 ? void 0 : config.onElementInit) === null || _t === void 0 ? void 0 : _t.call(config, it.name, obj, this, it.targetElement);
|
|
348
357
|
}
|
|
349
358
|
// TODO: 이부분도 위에 targetElement 처럼 해야될까?
|
|
350
359
|
for (const it of onAttrInitCallBacks) {
|
|
351
|
-
(
|
|
360
|
+
(_u = config === null || config === void 0 ? void 0 : config.onAttrInit) === null || _u === void 0 ? void 0 : _u.call(config, it.attrName, it.attrValue, obj, this);
|
|
352
361
|
}
|
|
353
362
|
// component destroy
|
|
354
363
|
if (obj.__domrender_components) {
|
|
355
364
|
Object.entries(obj.__domrender_components).forEach(([key, value]) => {
|
|
356
|
-
var _a, _b;
|
|
365
|
+
var _a, _b, _c;
|
|
357
366
|
const rawSet = value.__rawSet;
|
|
358
|
-
const drAttrs = rawSet === null || rawSet === void 0 ? void 0 : rawSet.dataSet.render.attribute;
|
|
367
|
+
const drAttrs = (_a = rawSet === null || rawSet === void 0 ? void 0 : rawSet.dataSet.render) === null || _a === void 0 ? void 0 : _a.attribute;
|
|
359
368
|
if (rawSet && !rawSet.isConnected) {
|
|
360
|
-
const destroyOptions = (
|
|
369
|
+
const destroyOptions = (_c = (_b = drAttrs === null || drAttrs === void 0 ? void 0 : drAttrs.drDestroyOption) === null || _b === void 0 ? void 0 : _b.split(',')) !== null && _c !== void 0 ? _c : [];
|
|
361
370
|
RawSet.destroy(obj.__domrender_components[key], { rawSet: rawSet }, config, destroyOptions);
|
|
362
371
|
delete obj.__domrender_components[key];
|
|
363
372
|
}
|
|
@@ -446,10 +455,10 @@ export class RawSet {
|
|
|
446
455
|
return styleBody;
|
|
447
456
|
}
|
|
448
457
|
applyEvent(obj, fragment = this.dataSet.fragment, config) {
|
|
449
|
-
eventManager.applyEvent(obj, eventManager.findAttrElements(fragment, config), config);
|
|
458
|
+
this.dataSet.config.eventManager.applyEvent(obj, this.dataSet.config.eventManager.findAttrElements(fragment, config), config);
|
|
450
459
|
}
|
|
451
460
|
onRenderedEvent(obj, nodes, config) {
|
|
452
|
-
eventManager.onRenderedEvent(obj, nodes, config);
|
|
461
|
+
this.dataSet.config.eventManager.onRenderedEvent(obj, nodes, config);
|
|
453
462
|
}
|
|
454
463
|
getAttribute(element, attr) {
|
|
455
464
|
const data = element.getAttribute(attr);
|
|
@@ -466,7 +475,7 @@ export class RawSet {
|
|
|
466
475
|
let data = element.getAttribute(RawSet.DR_APPENDER_NAME);
|
|
467
476
|
// if (data && !/\[[0-9]+\]/g.test(data)) {
|
|
468
477
|
if (data && !/\[.+\]/g.test(data)) {
|
|
469
|
-
const currentIndex = ScriptUtils.evalReturn(`${data}?.length -1`, obj);
|
|
478
|
+
const currentIndex = ScriptUtils.evalReturn(`${ObjectUtils.Path.toOptionalChainPath(data)}?.length -1`, obj);
|
|
470
479
|
// console.log('------?', currentIndex)
|
|
471
480
|
// if (currentIndex === undefined || isNaN(currentIndex)) {
|
|
472
481
|
// return undefined;
|
|
@@ -564,14 +573,15 @@ export class RawSet {
|
|
|
564
573
|
const isAttr = element.getAttributeNames().filter(it => {
|
|
565
574
|
const value = element.getAttribute(it);
|
|
566
575
|
// link일때
|
|
567
|
-
if (linkNames.includes(it)) {
|
|
576
|
+
if (value && linkNames.includes(it)) {
|
|
568
577
|
linkVariables.set(it, value);
|
|
569
578
|
}
|
|
570
579
|
else if (value && RawSet.isExpression(value)) { // 표현식있을떄
|
|
571
580
|
let variablePath = RawSet.expressionGroups(value)[0][1];
|
|
572
581
|
// normal Attribute 초반에 셋팅해주기.
|
|
573
582
|
variablePath = variablePath.replace(/#[^#]*#/g, '({})');
|
|
574
|
-
const cval = ScriptUtils.evalReturn(variablePath, Object.assign(obj));
|
|
583
|
+
const cval = ScriptUtils.evalReturn(ObjectUtils.Path.toOptionalChainPath(variablePath), Object.assign(obj));
|
|
584
|
+
// const cval = ScriptUtils.evalReturn(variablePath, Object.assign(obj));
|
|
575
585
|
if (cval === null) {
|
|
576
586
|
element.removeAttribute(it);
|
|
577
587
|
}
|
|
@@ -829,6 +839,7 @@ export class RawSet {
|
|
|
829
839
|
return thisRandom;
|
|
830
840
|
}
|
|
831
841
|
static drThisBindEncoding(element, variable, config) {
|
|
842
|
+
var _a;
|
|
832
843
|
element.querySelectorAll(`[${RawSet.DR_THIS_NAME}]`).forEach(eIt => {
|
|
833
844
|
let message = eIt.innerHTML;
|
|
834
845
|
// StringUtils.regexExec(/([^(dr\-)])?this(?=.?)/g, message).reverse().forEach(it => {
|
|
@@ -838,7 +849,8 @@ export class RawSet {
|
|
|
838
849
|
});
|
|
839
850
|
eIt.innerHTML = message;
|
|
840
851
|
});
|
|
841
|
-
const
|
|
852
|
+
const targetElements = (_a = config.config.targetElements) !== null && _a !== void 0 ? _a : [];
|
|
853
|
+
const targetElementNames = targetElements.map(it => it.name.replaceAll('.', '\\.').replaceAll(':', '\\:')).join(',');
|
|
842
854
|
const thisRandom = RandomUtils.uuid();
|
|
843
855
|
element.querySelectorAll(targetElementNames).forEach(it => {
|
|
844
856
|
it.innerHTML = it.innerHTML.replace(variable, thisRandom);
|
|
@@ -857,7 +869,9 @@ export class RawSet {
|
|
|
857
869
|
return thisRandom;
|
|
858
870
|
}
|
|
859
871
|
static drThisBindDecoding(element, config) {
|
|
860
|
-
|
|
872
|
+
var _a;
|
|
873
|
+
const targetElements = (_a = config.config.targetElements) !== null && _a !== void 0 ? _a : [];
|
|
874
|
+
const targetElementNames = targetElements.map(it => it.name.replaceAll('.', '\\.').replaceAll(':', '\\:')).join(',');
|
|
861
875
|
element.querySelectorAll(targetElementNames).forEach(it => {
|
|
862
876
|
it.innerHTML = it.innerHTML.replace(RegExp(config.asIs, 'g'), config.toBe);
|
|
863
877
|
});
|
|
@@ -925,8 +939,8 @@ export class RawSet {
|
|
|
925
939
|
}
|
|
926
940
|
static drThisCreate(rawSet, element, drThis, drVarOption, drStripOption, obj, config, set) {
|
|
927
941
|
return __awaiter(this, void 0, void 0, function* () {
|
|
928
|
-
var _a, _b, _c, _d, _e;
|
|
929
|
-
var
|
|
942
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
943
|
+
var _h;
|
|
930
944
|
// console.log('ttttttttttttttttttttt',element.innerHTML, drThis, set, obj);
|
|
931
945
|
const fag = config.window.document.createDocumentFragment();
|
|
932
946
|
const targetElement = element.cloneNode(true);
|
|
@@ -938,7 +952,7 @@ export class RawSet {
|
|
|
938
952
|
targetElement.innerHTML = style + ((_b = set.template) !== null && _b !== void 0 ? _b : '');
|
|
939
953
|
}
|
|
940
954
|
else {
|
|
941
|
-
targetObj = ScriptUtils.evalReturn(drThis, obj);
|
|
955
|
+
targetObj = ScriptUtils.evalReturn(ObjectUtils.Path.toOptionalChainPath(drThis), obj);
|
|
942
956
|
}
|
|
943
957
|
const componentKey = rawSet.uuid;
|
|
944
958
|
const renderScript = ` /*drThisCreate*/
|
|
@@ -991,15 +1005,14 @@ export class RawSet {
|
|
|
991
1005
|
targetObj === null || targetObj === void 0 ? void 0 : targetObj.onCreateRenderData(onCreateDataParam);
|
|
992
1006
|
}
|
|
993
1007
|
// 부모에게도 자식 this 생성된거 알려주는 callback
|
|
994
|
-
if (onCreateDataParam.render.parentThis && isOnCreatedThisChild(onCreateDataParam.render.parentThis)) {
|
|
1008
|
+
if (((_d = onCreateDataParam === null || onCreateDataParam === void 0 ? void 0 : onCreateDataParam.render) === null || _d === void 0 ? void 0 : _d.parentThis) && isOnCreatedThisChild((_e = onCreateDataParam === null || onCreateDataParam === void 0 ? void 0 : onCreateDataParam.render) === null || _e === void 0 ? void 0 : _e.parentThis)) {
|
|
995
1009
|
onCreateDataParam.render.parentThis.onCreatedThisChild(targetObj, onCreateDataParam);
|
|
996
1010
|
}
|
|
997
1011
|
// dr-on-create onCreateRender
|
|
998
1012
|
const onCreate = element.getAttribute(RawSet.DR_ON_CREATE_ARGUMENTS_OPTIONNAME);
|
|
999
1013
|
let createParam = [];
|
|
1000
1014
|
if (onCreate) {
|
|
1001
|
-
|
|
1002
|
-
createParam = ScriptUtils.eval(script, obj);
|
|
1015
|
+
createParam = ScriptUtils.evalReturn({ bodyScript: renderScript, returnScript: ObjectUtils.Path.toOptionalChainPath(onCreate) }, obj);
|
|
1003
1016
|
if (!Array.isArray(createParam)) {
|
|
1004
1017
|
createParam = [createParam];
|
|
1005
1018
|
}
|
|
@@ -1012,7 +1025,7 @@ export class RawSet {
|
|
|
1012
1025
|
// const normalAttrMap = element.getAttribute(EventManager.normalAttrMapAttrName);
|
|
1013
1026
|
const targetAttrObject = RawSet.getAttributeObject(element, { script: renderScript, obj: obj, renderData: render });
|
|
1014
1027
|
if (targetAttrObject) {
|
|
1015
|
-
(
|
|
1028
|
+
(_f = (_h = rawSet.dataSet).render) !== null && _f !== void 0 ? _f : (_h.render = {});
|
|
1016
1029
|
rawSet.dataSet.render.attribute = targetAttrObject;
|
|
1017
1030
|
Object.entries(targetAttrObject).forEach(([key, cval], index) => {
|
|
1018
1031
|
// console.log('ooooooooooooooooo', key, cval);
|
|
@@ -1048,7 +1061,7 @@ export class RawSet {
|
|
|
1048
1061
|
// RawSet.replaceInnerHTML(element, {asIs: `#${innerHTMLName}#`, toBe: innerHTMLNameReplaceKey})
|
|
1049
1062
|
// }
|
|
1050
1063
|
// 이걸 왜 뺐었지... 다시넣었음 그런데 조금 로직이.. 검증이..
|
|
1051
|
-
const innerHTMLName = (
|
|
1064
|
+
const innerHTMLName = (_g = targetElement.getAttribute(RawSet.DR_COMPONENT_INNER_HTML_NAME_OPTIONNAME)) !== null && _g !== void 0 ? _g : 'innerHTML';
|
|
1052
1065
|
if (innerHTMLName) {
|
|
1053
1066
|
RawSet.replaceInnerHTML(targetElement, { asIs: `#${innerHTMLName}#`, toBe: element.innerHTML });
|
|
1054
1067
|
}
|
|
@@ -1205,7 +1218,7 @@ export class RawSet {
|
|
|
1205
1218
|
//
|
|
1206
1219
|
// // dr-constructor
|
|
1207
1220
|
if (constructor) {
|
|
1208
|
-
let param = (_c = ScriptUtils.evalReturn({ bodyScript: renderScript, returnScript: constructor }, Object.assign(obj, { __render: render }))) !== null && _c !== void 0 ? _c : [];
|
|
1221
|
+
let param = (_c = ScriptUtils.evalReturn({ bodyScript: renderScript, returnScript: ObjectUtils.Path.toOptionalChainPath(constructor) }, Object.assign(obj, { __render: render }))) !== null && _c !== void 0 ? _c : [];
|
|
1209
1222
|
if (!Array.isArray(param)) {
|
|
1210
1223
|
param = [param];
|
|
1211
1224
|
}
|
|
@@ -1346,7 +1359,7 @@ export class RawSet {
|
|
|
1346
1359
|
if (!element) {
|
|
1347
1360
|
return undefined;
|
|
1348
1361
|
}
|
|
1349
|
-
const attribute =
|
|
1362
|
+
const attribute = ElementUtils.getAttributeToObject(element);
|
|
1350
1363
|
const normalAttribute = attribute[EventManager.normalAttrMapAttrName];
|
|
1351
1364
|
if (normalAttribute) {
|
|
1352
1365
|
new Map(JSON.parse(normalAttribute)).forEach((v, k) => {
|
|
@@ -1427,6 +1440,8 @@ RawSet.drAttrsOriginName = {
|
|
|
1427
1440
|
drStripElement: RawSet.DR_STRIP_NAME,
|
|
1428
1441
|
drReplaceTargetElementIs: RawSet.DR_REPLACE_TARGET_ELEMENT_IS_NAME,
|
|
1429
1442
|
drStripOption: RawSet.DR_STRIP_OPTIONNAME,
|
|
1443
|
+
drIfOption: RawSet.DR_IF_OPTIONNAME,
|
|
1444
|
+
drDetectIfOption: RawSet.DR_DETECT_IF_OPTIONNAME,
|
|
1430
1445
|
drDestroyOption: RawSet.DR_DESTROY_OPTIONNAME,
|
|
1431
1446
|
drHasKeysOption: RawSet.DR_HAS_KEYS_OPTIONNAME,
|
|
1432
1447
|
drKeyOption: RawSet.DR_KEY_OPTIONNAME
|
package/routers/HashRouter.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { RouteAction, Router, RouterConfig } from './Router';
|
|
1
|
+
import { ChangeStateResult, RouteAction, Router, RouterConfig } from './Router';
|
|
2
2
|
export declare class HashRouter extends Router {
|
|
3
3
|
constructor(config: RouterConfig);
|
|
4
4
|
getSearchParams(data?: {
|
|
5
5
|
delete?: string[];
|
|
6
6
|
append?: [[string, string]];
|
|
7
7
|
}): URLSearchParams;
|
|
8
|
-
push(path: RouteAction, data?: any, title?: string):
|
|
9
|
-
replace(path: RouteAction, data?: any, title?: string):
|
|
8
|
+
push(path: RouteAction, data?: any, title?: string): ChangeStateResult;
|
|
9
|
+
replace(path: RouteAction, data?: any, title?: string): ChangeStateResult;
|
|
10
10
|
setDeleteHashSearchParam(name: string, data?: any, title?: string): void;
|
|
11
11
|
pushDeleteHashSearchParam(name: string | string[], data: any, title: string | undefined): void;
|
|
12
12
|
pushDeleteSearchParam(name: string | string[], data?: any, title?: string): void;
|
|
@@ -15,7 +15,8 @@ export declare class HashRouter extends Router {
|
|
|
15
15
|
replaceDeleteSearchParam(name: string | string[], data?: any, title?: string): void;
|
|
16
16
|
replaceAddSearchParam(params: [[string, string]], data?: any, title?: string): void;
|
|
17
17
|
getUrl(): string;
|
|
18
|
-
|
|
18
|
+
getHref(): string;
|
|
19
|
+
getPathName(): string;
|
|
19
20
|
getHashSearchParams(data?: {
|
|
20
21
|
delete?: string[];
|
|
21
22
|
append?: [[string, string]];
|
package/routers/HashRouter.js
CHANGED
|
@@ -18,18 +18,18 @@ export class HashRouter extends Router {
|
|
|
18
18
|
}
|
|
19
19
|
push(path, data, title = '') {
|
|
20
20
|
if (path === '/') {
|
|
21
|
-
super.pushState(data, title, '/');
|
|
21
|
+
return super.pushState(data, title, '/');
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
super.pushState(data, title, `#${this.toUrl(path)}`);
|
|
24
|
+
return super.pushState(data, title, `#${this.toUrl(path)}`);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
replace(path, data, title) {
|
|
28
28
|
if (path === '/') {
|
|
29
|
-
super.replaceState(data, title, '/');
|
|
29
|
+
return super.replaceState(data, title, '/');
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
|
-
super.replaceState(data, title, `#${this.toUrl(path)}`);
|
|
32
|
+
return super.replaceState(data, title, `#${this.toUrl(path)}`);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
setDeleteHashSearchParam(name, data, title) {
|
|
@@ -65,7 +65,10 @@ export class HashRouter extends Router {
|
|
|
65
65
|
getUrl() {
|
|
66
66
|
return LocationUtils.hash(this.config.window) || '/';
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
getHref() {
|
|
69
|
+
return this.config.window.location.href;
|
|
70
|
+
}
|
|
71
|
+
getPathName() {
|
|
69
72
|
return LocationUtils.hashPath(this.config.window) || '/';
|
|
70
73
|
}
|
|
71
74
|
getHashSearchParams(data) {
|
package/routers/PathRouter.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { RouteAction, Router, RouterConfig } from './Router';
|
|
1
|
+
import { ChangeStateResult, RouteAction, Router, RouterConfig } from './Router';
|
|
2
2
|
export declare class PathRouter extends Router {
|
|
3
3
|
constructor(config: RouterConfig);
|
|
4
4
|
getSearchParams(data?: {
|
|
5
5
|
delete?: string[];
|
|
6
6
|
append?: [[string, string]];
|
|
7
7
|
}): URLSearchParams;
|
|
8
|
-
push(path: RouteAction, data?: any, title?: string):
|
|
9
|
-
replace(path: RouteAction, data?: any, title?: string):
|
|
8
|
+
push(path: RouteAction, data?: any, title?: string): ChangeStateResult;
|
|
9
|
+
replace(path: RouteAction, data?: any, title?: string): ChangeStateResult;
|
|
10
10
|
pushDeleteSearchParam(name: string, data?: any, title?: string): void;
|
|
11
11
|
pushDeleteHashSearchParam(name: string, data?: any, title?: string): void;
|
|
12
12
|
pushAddSearchParam(params: [[string, string]], data?: any, title?: string): void;
|
|
@@ -14,7 +14,8 @@ export declare class PathRouter extends Router {
|
|
|
14
14
|
replaceDeleteHashSearchParam(name: string | string[], data?: any, title?: string): void;
|
|
15
15
|
replaceAddSearchParam(params: [[string, string]], data?: any, title?: string): void;
|
|
16
16
|
getUrl(): string;
|
|
17
|
-
|
|
17
|
+
getHref(): string;
|
|
18
|
+
getPathName(): string;
|
|
18
19
|
getHashSearchParams(data?: {
|
|
19
20
|
delete?: string[];
|
|
20
21
|
append?: [[string, string]];
|
package/routers/PathRouter.js
CHANGED
|
@@ -15,11 +15,10 @@ export class PathRouter extends Router {
|
|
|
15
15
|
return searchParams;
|
|
16
16
|
}
|
|
17
17
|
push(path, data, title = '') {
|
|
18
|
-
|
|
19
|
-
super.pushState(data, title, this.toUrl(path));
|
|
18
|
+
return super.pushState(data, title, this.toUrl(path));
|
|
20
19
|
}
|
|
21
20
|
replace(path, data, title = '') {
|
|
22
|
-
super.replaceState(data, title, this.toUrl(path));
|
|
21
|
+
return super.replaceState(data, title, this.toUrl(path));
|
|
23
22
|
}
|
|
24
23
|
pushDeleteSearchParam(name, data, title) {
|
|
25
24
|
const s = this.getSearchParams({ delete: [name] });
|
|
@@ -53,7 +52,10 @@ export class PathRouter extends Router {
|
|
|
53
52
|
const url = new URL(this.config.window.document.location.href);
|
|
54
53
|
return url.pathname + url.search;
|
|
55
54
|
}
|
|
56
|
-
|
|
55
|
+
getHref() {
|
|
56
|
+
return this.config.window.location.href;
|
|
57
|
+
}
|
|
58
|
+
getPathName() {
|
|
57
59
|
return this.config.window.location.pathname;
|
|
58
60
|
}
|
|
59
61
|
getHashSearchParams(data) {
|
package/routers/Router.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ConvertUtils } from '@dooboostore/core/convert/ConvertUtils';
|
|
2
|
+
import { Observable } from '@dooboostore/core/message';
|
|
2
3
|
import ToURLSearchParamsParams = ConvertUtils.ToURLSearchParamsParams;
|
|
3
4
|
export type RouteData = {
|
|
4
5
|
path: string;
|
|
@@ -7,19 +8,29 @@ export type RouteData = {
|
|
|
7
8
|
searchParams: URLSearchParams;
|
|
8
9
|
pathData?: any;
|
|
9
10
|
router: Router;
|
|
11
|
+
currentTarget?: PopCurrentState;
|
|
10
12
|
};
|
|
13
|
+
export type PopStateCurrentTargetDomrenderRouter = {
|
|
14
|
+
currentTargetName: 'domRenderRouter';
|
|
15
|
+
};
|
|
16
|
+
export type PopCurrentState = PopStateCurrentTargetDomrenderRouter;
|
|
17
|
+
export declare const isPopStateCurrentTargetDomrenderRouter: (obj: any) => obj is PopStateCurrentTargetDomrenderRouter;
|
|
11
18
|
export type RouterConfig<T = any> = {
|
|
12
19
|
rootObject?: T;
|
|
13
20
|
window: Window;
|
|
14
21
|
disableAttach?: boolean;
|
|
15
22
|
};
|
|
23
|
+
export type ChangeStateResult = {
|
|
24
|
+
data?: any;
|
|
25
|
+
};
|
|
16
26
|
export type RouteAction = string | {
|
|
17
27
|
path?: string;
|
|
18
28
|
searchParams?: ToURLSearchParamsParams;
|
|
19
29
|
};
|
|
20
30
|
export declare abstract class Router<T = any> {
|
|
21
|
-
private
|
|
31
|
+
private behaviorSubject;
|
|
22
32
|
private _config;
|
|
33
|
+
get observable(): Observable<RouteData>;
|
|
23
34
|
get searchParamObject(): {
|
|
24
35
|
[key: string]: string | string[];
|
|
25
36
|
};
|
|
@@ -27,15 +38,17 @@ export declare abstract class Router<T = any> {
|
|
|
27
38
|
constructor(config: RouterConfig<any>);
|
|
28
39
|
getSearchFirstParamsObject<T = any>(defaultValue?: T): T & import("@dooboostore/core/types").FieldType<T, string>;
|
|
29
40
|
getHashSearchFirstParamsObject<T = any>(): import("@dooboostore/core/types").FieldType<T, string>;
|
|
30
|
-
addChangeCallback(callback: (routeData: RouteData) => void): void;
|
|
31
41
|
attach(): Promise<void>;
|
|
32
42
|
testRegexp(regexp: string): boolean;
|
|
33
43
|
test(urlExpression: string): boolean;
|
|
34
|
-
getRouteData(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
getRouteData(config?: {
|
|
45
|
+
urlExpression?: string;
|
|
46
|
+
currentTarget?: PopCurrentState;
|
|
47
|
+
}): RouteData;
|
|
48
|
+
pushState(data: any, title: string | undefined, path: string): ChangeStateResult;
|
|
49
|
+
replaceState(data: any, title: string | undefined, path: string): ChangeStateResult;
|
|
50
|
+
private dispatchPopStateEvent;
|
|
51
|
+
reload(data?: any): void;
|
|
39
52
|
getData(): any;
|
|
40
53
|
getPathData(urlExpression: string, currentUrl?: string): any;
|
|
41
54
|
go(config: {
|
|
@@ -63,6 +76,7 @@ export declare abstract class Router<T = any> {
|
|
|
63
76
|
append?: [[string, string]];
|
|
64
77
|
}): URLSearchParams;
|
|
65
78
|
abstract getUrl(): string;
|
|
66
|
-
abstract
|
|
79
|
+
abstract getHref(): string;
|
|
80
|
+
abstract getPathName(): string;
|
|
67
81
|
}
|
|
68
82
|
//# sourceMappingURL=Router.d.ts.map
|
package/routers/Router.js
CHANGED
|
@@ -7,10 +7,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { getDomRenderProxy } from '../DomRenderProxy';
|
|
10
11
|
import { EventManager } from '../events/EventManager';
|
|
11
12
|
import { ConvertUtils } from '@dooboostore/core/convert/ConvertUtils';
|
|
13
|
+
import { BehaviorSubject } from '@dooboostore/core/message';
|
|
12
14
|
import { Expression } from '@dooboostore/core/expression/Expression';
|
|
15
|
+
export const isPopStateCurrentTargetDomrenderRouter = (obj) => (obj === null || obj === void 0 ? void 0 : obj.currentTargetName) === 'domRenderRouter';
|
|
16
|
+
/*
|
|
17
|
+
this.option.window.addEventListener('popstate', (event) => { // history.back, forward에만 popstate 발생되고 값이 도출된다
|
|
18
|
+
console.log('popstate-------!!', event.state, this.domRenderConfig.window.history.state)
|
|
19
|
+
})
|
|
20
|
+
*/
|
|
13
21
|
export class Router {
|
|
22
|
+
get observable() {
|
|
23
|
+
return this.behaviorSubject.asObservable();
|
|
24
|
+
}
|
|
14
25
|
get searchParamObject() {
|
|
15
26
|
return ConvertUtils.toObject(this.getSearchParams());
|
|
16
27
|
}
|
|
@@ -18,14 +29,15 @@ export class Router {
|
|
|
18
29
|
return this._config;
|
|
19
30
|
}
|
|
20
31
|
constructor(config) {
|
|
21
|
-
this.changeCallbacks = new Set();
|
|
22
32
|
this._config = config;
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
this.behaviorSubject = new BehaviorSubject(this.getRouteData());
|
|
34
|
+
this.config.window.addEventListener('popstate', (event) => {
|
|
35
|
+
if (!isPopStateCurrentTargetDomrenderRouter(event.state)) {
|
|
36
|
+
// console.log('-------');
|
|
37
|
+
const routeData = this.getRouteData();
|
|
38
|
+
this.behaviorSubject.next(routeData);
|
|
39
|
+
}
|
|
27
40
|
});
|
|
28
|
-
// this.go({path:this.getUrl()});
|
|
29
41
|
}
|
|
30
42
|
getSearchFirstParamsObject(defaultValue) {
|
|
31
43
|
const a = ConvertUtils.toObject(this.getSearchParams(), { firstValue: true });
|
|
@@ -34,12 +46,9 @@ export class Router {
|
|
|
34
46
|
getHashSearchFirstParamsObject() {
|
|
35
47
|
return ConvertUtils.toObject(this.getHashSearchParams(), { firstValue: true });
|
|
36
48
|
}
|
|
37
|
-
addChangeCallback(callback) {
|
|
38
|
-
this.changeCallbacks.add(callback);
|
|
39
|
-
}
|
|
40
49
|
attach() {
|
|
41
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const proxy = this.config.rootObject
|
|
51
|
+
const proxy = getDomRenderProxy(this.config.rootObject);
|
|
43
52
|
if (proxy) {
|
|
44
53
|
const key = `___${EventManager.ROUTER_VARNAME}`;
|
|
45
54
|
yield proxy.render(key);
|
|
@@ -47,7 +56,7 @@ export class Router {
|
|
|
47
56
|
});
|
|
48
57
|
}
|
|
49
58
|
testRegexp(regexp) {
|
|
50
|
-
const b = RegExp(regexp).test(this.
|
|
59
|
+
const b = RegExp(regexp).test(this.getPathName());
|
|
51
60
|
return b;
|
|
52
61
|
}
|
|
53
62
|
test(urlExpression) {
|
|
@@ -58,9 +67,9 @@ export class Router {
|
|
|
58
67
|
return false;
|
|
59
68
|
}
|
|
60
69
|
}
|
|
61
|
-
getRouteData(
|
|
70
|
+
getRouteData(config) {
|
|
62
71
|
const newVar = {
|
|
63
|
-
path: this.
|
|
72
|
+
path: this.getPathName(),
|
|
64
73
|
url: this.getUrl(),
|
|
65
74
|
searchParams: this.getSearchParams()
|
|
66
75
|
};
|
|
@@ -68,31 +77,40 @@ export class Router {
|
|
|
68
77
|
if (data) {
|
|
69
78
|
newVar.data = data;
|
|
70
79
|
}
|
|
71
|
-
if (urlExpression) {
|
|
72
|
-
const data = this.getPathData(urlExpression);
|
|
80
|
+
if (config === null || config === void 0 ? void 0 : config.urlExpression) {
|
|
81
|
+
const data = this.getPathData(config.urlExpression);
|
|
73
82
|
if (data) {
|
|
74
83
|
newVar.pathData = data;
|
|
75
84
|
}
|
|
76
85
|
}
|
|
77
86
|
newVar.router = this;
|
|
87
|
+
newVar.currentTarget = config === null || config === void 0 ? void 0 : config.currentTarget;
|
|
78
88
|
return Object.freeze(newVar);
|
|
79
89
|
}
|
|
80
90
|
pushState(data, title, path) {
|
|
81
|
-
this.config.
|
|
91
|
+
// data = this.config.changeStateConvertDate?this.config.changeStateConvertDate(data): data;
|
|
92
|
+
// console.log('--->pushState', data);
|
|
93
|
+
this.config.window.history.pushState(data, title !== null && title !== void 0 ? title : '', path);
|
|
94
|
+
this.behaviorSubject.next(this.getRouteData({ currentTarget: { currentTargetName: 'domRenderRouter' } }));
|
|
95
|
+
return { data };
|
|
82
96
|
}
|
|
83
97
|
replaceState(data, title, path) {
|
|
84
|
-
this.config.
|
|
98
|
+
// data = this.config.changeStateConvertDate?this.config.changeStateConvertDate(data): data;
|
|
99
|
+
// console.log('--->replaceState', data);
|
|
100
|
+
this.config.window.history.replaceState(data, title !== null && title !== void 0 ? title : '', path);
|
|
101
|
+
this.behaviorSubject.next(this.getRouteData({ currentTarget: { currentTargetName: 'domRenderRouter' } }));
|
|
102
|
+
return { data };
|
|
85
103
|
}
|
|
86
|
-
dispatchPopStateEvent() {
|
|
87
|
-
this.config.window.dispatchEvent(new
|
|
104
|
+
dispatchPopStateEvent(data) {
|
|
105
|
+
this.config.window.dispatchEvent(new PopStateEvent('popstate', { state: Object.assign(Object.assign({}, data), { currentTargetName: 'domRenderRouter' }) }));
|
|
88
106
|
}
|
|
89
|
-
reload() {
|
|
90
|
-
this.config.window.dispatchEvent(new
|
|
107
|
+
reload(data) {
|
|
108
|
+
this.config.window.dispatchEvent(new PopStateEvent('popstate', { state: data }));
|
|
91
109
|
}
|
|
92
110
|
getData() {
|
|
93
111
|
return this.config.window.history.state;
|
|
94
112
|
}
|
|
95
|
-
getPathData(urlExpression, currentUrl = this.
|
|
113
|
+
getPathData(urlExpression, currentUrl = this.getPathName()) {
|
|
96
114
|
return Expression.Path.pathNameData(currentUrl, urlExpression);
|
|
97
115
|
}
|
|
98
116
|
go(config) {
|
|
@@ -100,6 +118,7 @@ export class Router {
|
|
|
100
118
|
if (typeof config === 'string') {
|
|
101
119
|
config = { path: config };
|
|
102
120
|
}
|
|
121
|
+
// let data: ChangeStateResult | undefined = undefined;
|
|
103
122
|
if (config === null || config === void 0 ? void 0 : config.replace) {
|
|
104
123
|
this.replace(config.path, config.data, config.title);
|
|
105
124
|
}
|
|
@@ -109,8 +128,9 @@ export class Router {
|
|
|
109
128
|
if (!this.config.disableAttach) {
|
|
110
129
|
yield this.attach();
|
|
111
130
|
}
|
|
131
|
+
// console.log('----------', data, config)
|
|
112
132
|
if (!config.disabledPopEvent) {
|
|
113
|
-
this.dispatchPopStateEvent();
|
|
133
|
+
this.dispatchPopStateEvent(config === null || config === void 0 ? void 0 : config.data);
|
|
114
134
|
}
|
|
115
135
|
});
|
|
116
136
|
}
|
|
@@ -121,7 +141,7 @@ export class Router {
|
|
|
121
141
|
targetPath = data;
|
|
122
142
|
}
|
|
123
143
|
else {
|
|
124
|
-
const tpath = (_a = data.path) !== null && _a !== void 0 ? _a : this.
|
|
144
|
+
const tpath = (_a = data.path) !== null && _a !== void 0 ? _a : this.getPathName();
|
|
125
145
|
const s = data.searchParams ? ConvertUtils.toURLSearchParams(data.searchParams).toString() : '';
|
|
126
146
|
// data.searchParams
|
|
127
147
|
targetPath = `${tpath}${s.length > 0 ? '?' : ''}${s}`;
|