dom-render 1.0.73 → 1.0.74
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/Config.d.ts +1 -1
- package/DomRender.d.ts +23 -0
- package/DomRender.js +51 -2
- package/README.MD +77 -21
- package/RawSet.d.ts +2 -1
- package/RawSet.js +40 -17
- package/dist/bundle.js +130 -37
- package/events/EventManager.js +1 -1
- package/lifecycle/OnDestroyRender.d.ts +4 -0
- package/lifecycle/OnDestroyRender.js +2 -0
- package/package.json +1 -1
- package/routers/Router.d.ts +3 -0
- package/routers/Router.js +26 -4
package/Config.d.ts
CHANGED
package/DomRender.d.ts
CHANGED
@@ -1,4 +1,27 @@
|
|
1
1
|
import { Config } from './Config';
|
2
|
+
import { ConstructorType } from './types/Types';
|
3
|
+
import { RawSet } from './RawSet';
|
2
4
|
export declare class DomRender {
|
3
5
|
static run<T extends object>(obj: T, target?: Node, config?: Config): T;
|
6
|
+
static addComponent(config: Config, { type, tagName }: {
|
7
|
+
type: ConstructorType<any>;
|
8
|
+
tagName?: string;
|
9
|
+
}, { template, styles }: {
|
10
|
+
template: string;
|
11
|
+
styles?: string[];
|
12
|
+
}): {
|
13
|
+
add: (source: {
|
14
|
+
type: ConstructorType<any>;
|
15
|
+
tagName?: string;
|
16
|
+
}, front: {
|
17
|
+
template: string;
|
18
|
+
styles?: string[];
|
19
|
+
}) => any;
|
20
|
+
};
|
21
|
+
static addAttribute(config: Config, attrName: string, getThisObj: (element: Element, attrValue: string, obj: any, rawSet: RawSet) => any, factory: (element: Element, attrValue: string, obj: any, rawSet: RawSet) => DocumentFragment): {
|
22
|
+
add: (attrName: string, getThisObj: (element: Element, attrValue: string, obj: any, rawSet: RawSet) => any, factory: (element: Element, attrValue: string, obj: any, rawSet: RawSet) => DocumentFragment) => any;
|
23
|
+
};
|
24
|
+
static addAttributeCallBack(config: Config, attrName: string, callBack: (elements: Element, attrValue: string, obj: any) => void): {
|
25
|
+
add: (attrName: string, callBack: (elements: Element, attrValue: string, obj: any) => void) => any;
|
26
|
+
};
|
4
27
|
}
|
package/DomRender.js
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
4
|
+
if (ar || !(i in from)) {
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
6
|
+
ar[i] = from[i];
|
7
|
+
}
|
8
|
+
}
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
10
|
+
};
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
12
|
exports.DomRender = void 0;
|
4
13
|
var DomRenderProxy_1 = require("./DomRenderProxy");
|
5
14
|
var PathRouter_1 = require("./routers/PathRouter");
|
6
15
|
var HashRouter_1 = require("./routers/HashRouter");
|
16
|
+
var RawSet_1 = require("./RawSet");
|
7
17
|
var DomRender = /** @class */ (function () {
|
8
18
|
function DomRender() {
|
9
19
|
}
|
@@ -20,7 +30,7 @@ var DomRender = /** @class */ (function () {
|
|
20
30
|
if (!config) {
|
21
31
|
config = { window: window };
|
22
32
|
}
|
23
|
-
config.routerType = config.routerType || '
|
33
|
+
config.routerType = config.routerType || 'none';
|
24
34
|
var domRender = new DomRenderProxy_1.DomRenderProxy(obj, target, config);
|
25
35
|
var dest = new Proxy(obj, domRender);
|
26
36
|
robj = dest;
|
@@ -33,7 +43,46 @@ var DomRender = /** @class */ (function () {
|
|
33
43
|
domRender.run(robj);
|
34
44
|
return robj;
|
35
45
|
};
|
46
|
+
DomRender.addComponent = function (config, _a, _b) {
|
47
|
+
var _c;
|
48
|
+
var type = _a.type, _d = _a.tagName, tagName = _d === void 0 ? type.name : _d;
|
49
|
+
var template = _b.template, _e = _b.styles, styles = _e === void 0 ? [] : _e;
|
50
|
+
var component = RawSet_1.RawSet.createComponentTargetElement(tagName, function (e, o, r2, counstructorParam) {
|
51
|
+
// console.log('------->',counstructorParam)
|
52
|
+
return new (type.bind.apply(type, __spreadArray([void 0], counstructorParam, false)))();
|
53
|
+
}, template, styles, config);
|
54
|
+
config.targetElements = (_c = config.targetElements) !== null && _c !== void 0 ? _c : [];
|
55
|
+
config.targetElements.push(component);
|
56
|
+
return {
|
57
|
+
add: function (source, front) {
|
58
|
+
return DomRender.addComponent(config, source, front);
|
59
|
+
}
|
60
|
+
};
|
61
|
+
};
|
62
|
+
DomRender.addAttribute = function (config, attrName, getThisObj, factory) {
|
63
|
+
var _a;
|
64
|
+
var targetAttribute = RawSet_1.RawSet.createComponentTargetAttribute(attrName, getThisObj, factory);
|
65
|
+
config.targetAttrs = (_a = config.targetAttrs) !== null && _a !== void 0 ? _a : [];
|
66
|
+
config.targetAttrs.push(targetAttribute);
|
67
|
+
return {
|
68
|
+
add: function (attrName, getThisObj, factory) {
|
69
|
+
return DomRender.addAttribute(config, attrName, getThisObj, factory);
|
70
|
+
}
|
71
|
+
};
|
72
|
+
};
|
73
|
+
DomRender.addAttributeCallBack = function (config, attrName, callBack) {
|
74
|
+
var _a;
|
75
|
+
config.applyEvents = (_a = config.applyEvents) !== null && _a !== void 0 ? _a : [];
|
76
|
+
config.applyEvents.push({
|
77
|
+
attrName: attrName,
|
78
|
+
callBack: callBack
|
79
|
+
});
|
80
|
+
return {
|
81
|
+
add: function (attrName, callBack) {
|
82
|
+
return DomRender.addAttributeCallBack(config, attrName, callBack);
|
83
|
+
}
|
84
|
+
};
|
85
|
+
};
|
36
86
|
return DomRender;
|
37
87
|
}());
|
38
88
|
exports.DomRender = DomRender;
|
39
|
-
// export default DomRender;
|
package/README.MD
CHANGED
@@ -328,17 +328,16 @@ validator
|
|
328
328
|
|
329
329
|
- [examples](./examples/router)
|
330
330
|
|
331
|
-
* config routerType: 'hash' | 'path' (default: '
|
331
|
+
* config routerType: 'hash' | 'path' | 'none' (default: 'none')
|
332
332
|
```typescript
|
333
333
|
// Config
|
334
334
|
const config: Config = {
|
335
335
|
window
|
336
336
|
};
|
337
|
-
config
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
];
|
337
|
+
DomRender.addComponent(config, {type: Main, tagName: 'page-main'}, {template: MainTemplate})
|
338
|
+
.add({type: Second, tagName: 'page-second'}, {template: SecondTemplate})
|
339
|
+
.add({type: Detail, tagName: 'page-detail'}, {template: DetailTemplate});
|
340
|
+
config.routerType = 'hash';
|
342
341
|
config.routerType = 'hash';
|
343
342
|
const data = DomRender.run(new Data(), document.querySelector('#app')!, config);
|
344
343
|
```
|
@@ -453,8 +452,12 @@ Code base
|
|
453
452
|
|
454
453
|
|
455
454
|
## LifeCycle
|
455
|
+
* OnCreateRender
|
456
|
+
* onCreateRender(): created call
|
456
457
|
* OnInitRender
|
457
458
|
* onInitRender(): init render call
|
459
|
+
* OnDestroyRender
|
460
|
+
* onDestroyRender(): component Destroy call
|
458
461
|
|
459
462
|
## Script
|
460
463
|
```typescript
|
@@ -476,23 +479,76 @@ const data = config.scripts.concat('head', 'tail')
|
|
476
479
|
```
|
477
480
|
|
478
481
|
---
|
479
|
-
# Component
|
482
|
+
# Component, Attribute, AttributeCallBack
|
483
|
+
# 😃 examples
|
484
|
+
- [examples](./examples/component_script_attr)
|
485
|
+
```html
|
486
|
+
<body id="app">
|
487
|
+
${this.name}$
|
488
|
+
<h1>component</h1>
|
489
|
+
<profile dr-on-component-init="$component.name='jhone'; $component.age=55;"><b>${#component#.details}$</b></profile>
|
490
|
+
<profile dr-on-component-init="$component.name='cal'; $component.age=56;"><b>detail-2</b></profile>
|
491
|
+
<profile dr-on-component-init="$component.name='rose'; $component.age=57;">
|
492
|
+
<profile dr-on-component-init="$component.name='rose-sub'; $component.age=156;">
|
493
|
+
<b>${this.name}$</b>
|
494
|
+
</profile>
|
495
|
+
</profile>
|
496
|
+
<h3>component data link and detect</h3>
|
497
|
+
<Profile dr-if="this.toggle" dr-detect="$component.age = this.age" dr-on-component-init="$component.name='papa'; $component.age=58;">
|
498
|
+
<b>${this.name}$</b>
|
499
|
+
</Profile>
|
500
|
+
|
501
|
+
<button dr-event-click="this.name = new Date().toString();">change name</button>
|
502
|
+
<button dr-event-click="this.age = Date.now();">change age</button>
|
503
|
+
<button dr-event-click="this.toggle = !this.toggle;">change toggle</button>
|
504
|
+
|
505
|
+
<j1>component constructor, on-create, dr-on-component-init</j1>
|
506
|
+
<home dr-constructor="[this.name, this.age, 'home welcom']" dr-on-create="{type: 'onCreate', data: 'datadata'}" dr-on-component-init="$component.onInit('data')"></home>
|
507
|
+
|
508
|
+
|
509
|
+
|
510
|
+
<h1>scripts</h1>
|
511
|
+
<div>
|
512
|
+
${$scripts.concat('hello', 'tail')}$
|
513
|
+
</div>
|
514
|
+
|
515
|
+
<h1>attr</h1>
|
516
|
+
<button link="this.link">
|
517
|
+
link attribute
|
518
|
+
</button>
|
519
|
+
<h1>attrCallBack</h1>
|
520
|
+
<input id="callback" type="text" wow>
|
521
|
+
</body>
|
522
|
+
```
|
480
523
|
```typescript
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
524
|
+
DomRender
|
525
|
+
.addComponent(config, {type: Profile}, {template: ProfileTemplate})
|
526
|
+
.add({type: Home}, {template: HomeTemplate});
|
527
|
+
|
528
|
+
DomRender.addAttribute(config, 'link',
|
529
|
+
(element: Element, attrValue: string, obj: any, rawSet: RawSet) => {
|
530
|
+
return obj;
|
531
|
+
},
|
532
|
+
(element: Element, attrValue: string, obj: any, rawSet: RawSet) => {
|
533
|
+
const fag = window.document.createDocumentFragment();
|
534
|
+
if (attrValue) {
|
535
|
+
const n = element.cloneNode(true) as Element;
|
536
|
+
attrValue = ScriptUtils.eval(`return ${attrValue}`, obj)
|
537
|
+
n.addEventListener('click', () => {
|
538
|
+
location.href = attrValue;
|
539
|
+
});
|
540
|
+
fag.append(n);
|
541
|
+
}
|
542
|
+
return fag;
|
543
|
+
}
|
544
|
+
);
|
490
545
|
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
})
|
546
|
+
DomRender.addAttributeCallBack(config, 'wow', (e, a, o) => {
|
547
|
+
e.addEventListener('click', (event) => {
|
548
|
+
alert((event.target as any).value);
|
549
|
+
})
|
550
|
+
})
|
551
|
+
const data = DomRender.run(new Data(), document.querySelector('#app')!, config);
|
496
552
|
```
|
497
553
|
using component
|
498
554
|
```html
|
package/RawSet.d.ts
CHANGED
@@ -90,7 +90,7 @@ export declare class RawSet {
|
|
90
90
|
}[]): void;
|
91
91
|
static drThisCreate(element: Element, drThis: string, drVarOption: string, drStripOption: boolean | string | null, obj: any, config: Config): DocumentFragment;
|
92
92
|
static createComponentTargetAttribute(name: string, getThisObj: (element: Element, attrValue: string, obj: any, rawSet: RawSet) => any, factory: (element: Element, attrValue: string, obj: any, rawSet: RawSet) => DocumentFragment): TargetAttr;
|
93
|
-
static createComponentTargetElement(name: string, objFactory: (element: Element, obj: any, rawSet: RawSet) => any, template: string | undefined, styles: string[] | undefined, config: Config): TargetElement;
|
93
|
+
static createComponentTargetElement(name: string, objFactory: (element: Element, obj: any, rawSet: RawSet, counstructorParam: any[]) => any, template: string | undefined, styles: string[] | undefined, config: Config): TargetElement;
|
94
94
|
static exporesionGrouops(data: string): RegExpExecArray[];
|
95
95
|
}
|
96
96
|
export declare type Render = {
|
@@ -109,6 +109,7 @@ export declare type Render = {
|
|
109
109
|
export declare type CreatorMetaData = {
|
110
110
|
thisVariableName?: string | null;
|
111
111
|
thisFullVariableName?: string | null;
|
112
|
+
componentKey?: string | null;
|
112
113
|
rawSet: RawSet;
|
113
114
|
innerHTML: string;
|
114
115
|
rootCreator: any;
|
package/RawSet.js
CHANGED
@@ -339,23 +339,24 @@ var RawSet = /** @class */ (function () {
|
|
339
339
|
// const targetElement = config?.targetElements?.find(it => (!drAttr.drIf && !drAttr.drForOf && !drAttr.drFor && !drAttr.drRepeat) && it.name.toLowerCase() === element.tagName.toLowerCase());
|
340
340
|
var targetElement = (_9 = config === null || config === void 0 ? void 0 : config.targetElements) === null || _9 === void 0 ? void 0 : _9.find(function (it) { return it.name.toLowerCase() === element_2.tagName.toLowerCase(); });
|
341
341
|
if (targetElement) {
|
342
|
-
var
|
342
|
+
var documentFragment = targetElement.callBack(element_2, obj, this_1);
|
343
343
|
// console.log('target-->',name, documentFragment)
|
344
|
-
if (
|
344
|
+
if (documentFragment) {
|
345
345
|
var detectAction_1 = element_2.getAttribute(RawSet.DR_DETECT_NAME);
|
346
|
-
|
346
|
+
var render_1 = documentFragment.render;
|
347
|
+
if (detectAction_1 && render_1) {
|
347
348
|
this_1.detect = {
|
348
349
|
action: function () {
|
349
350
|
var script = "var $component = this.__render.component; var $element = this.__render.element; var $innerHTML = this.__render.innerHTML; var $attribute = this.__render.attribute; ".concat(detectAction_1, " ");
|
350
351
|
ScriptUtils_1.ScriptUtils.eval(script, Object.assign(obj, {
|
351
|
-
__render:
|
352
|
+
__render: render_1
|
352
353
|
}));
|
353
354
|
}
|
354
355
|
};
|
355
356
|
}
|
356
357
|
// fag.append(documentFragment)
|
357
|
-
var rr = RawSet.checkPointCreates(
|
358
|
-
(_10 = element_2.parentNode) === null || _10 === void 0 ? void 0 : _10.replaceChild(
|
358
|
+
var rr = RawSet.checkPointCreates(documentFragment, config);
|
359
|
+
(_10 = element_2.parentNode) === null || _10 === void 0 ? void 0 : _10.replaceChild(documentFragment, element_2);
|
359
360
|
raws.push.apply(raws, rr);
|
360
361
|
onElementInitCallBack.push({
|
361
362
|
name: targetElement.name.toLowerCase(),
|
@@ -422,6 +423,20 @@ var RawSet = /** @class */ (function () {
|
|
422
423
|
var it_2 = onAttrInitCallBack_1[_25];
|
423
424
|
var r = (_22 = config === null || config === void 0 ? void 0 : config.onAttrInit) === null || _22 === void 0 ? void 0 : _22.call(config, it_2.attrName, it_2.attrValue, obj, this);
|
424
425
|
}
|
426
|
+
// component destroy
|
427
|
+
if (obj.__domrender_components) {
|
428
|
+
Object.entries(obj.__domrender_components).forEach(function (_a) {
|
429
|
+
var _b, _c;
|
430
|
+
var key = _a[0], value = _a[1];
|
431
|
+
var domrenderComponentNew = value.__domrender_component_new;
|
432
|
+
var rawSet = domrenderComponentNew === null || domrenderComponentNew === void 0 ? void 0 : domrenderComponentNew.rawSet;
|
433
|
+
if (rawSet && !rawSet.isConnected) {
|
434
|
+
(_c = (_b = obj.__domrender_components[key]) === null || _b === void 0 ? void 0 : _b.onDestroyRender) === null || _c === void 0 ? void 0 : _c.call(_b, domrenderComponentNew);
|
435
|
+
delete obj.__domrender_components[key];
|
436
|
+
}
|
437
|
+
// console.log('destroy', key, value);
|
438
|
+
});
|
439
|
+
}
|
425
440
|
return raws;
|
426
441
|
};
|
427
442
|
RawSet.prototype.applyEvent = function (obj, fragment, config) {
|
@@ -753,21 +768,16 @@ var RawSet = /** @class */ (function () {
|
|
753
768
|
styles: styles,
|
754
769
|
template: template,
|
755
770
|
callBack: function (element, obj, rawSet) {
|
756
|
-
var _a, _b, _c, _d;
|
771
|
+
var _a, _b, _c, _d, _e;
|
757
772
|
// console.log('callback------->')
|
758
773
|
if (!obj.__domrender_components) {
|
759
774
|
obj.__domrender_components = {};
|
760
775
|
}
|
761
776
|
var domrenderComponents = obj.__domrender_components;
|
762
777
|
var componentKey = '_' + RandomUtils_1.RandomUtils.getRandomString(20);
|
763
|
-
// console.log('callback settttt---a-->', componentKey, objFactory, objFactory(element, obj, rawSet))
|
764
|
-
domrenderComponents[componentKey] = objFactory(element, obj, rawSet);
|
765
|
-
var instance = domrenderComponents[componentKey];
|
766
778
|
var attribute = DomUtils_1.DomUtils.getAttributeToObject(element);
|
767
|
-
var onCreate = element.getAttribute('dr-on-create');
|
768
779
|
var renderScript = 'var $component = this.__render.component; var $element = this.__render.element; var $router = this.__render.router; var $innerHTML = this.__render.innerHTML; var $attribute = this.__render.attribute;';
|
769
780
|
var render = Object.freeze({
|
770
|
-
component: instance,
|
771
781
|
element: element,
|
772
782
|
innerHTML: element.innerHTML,
|
773
783
|
attribute: attribute,
|
@@ -777,18 +787,31 @@ var RawSet = /** @class */ (function () {
|
|
777
787
|
scripts: EventManager_1.EventManager.setBindProperty((_a = config.scripts) !== null && _a !== void 0 ? _a : {}, obj)
|
778
788
|
// eslint-disable-next-line no-use-before-define
|
779
789
|
});
|
790
|
+
var constructor = element.getAttribute('dr-constructor');
|
791
|
+
var constructorParam = [];
|
792
|
+
if (constructor) {
|
793
|
+
var script = "".concat(renderScript, " return ").concat(constructor, " ");
|
794
|
+
var param = (_b = ScriptUtils_1.ScriptUtils.eval(script, obj)) !== null && _b !== void 0 ? _b : [];
|
795
|
+
if (!Array.isArray(param)) {
|
796
|
+
param = [param];
|
797
|
+
}
|
798
|
+
constructorParam = param;
|
799
|
+
}
|
800
|
+
domrenderComponents[componentKey] = objFactory(element, obj, rawSet, constructorParam);
|
801
|
+
var instance = domrenderComponents[componentKey];
|
802
|
+
render = __assign({ component: instance }, render);
|
803
|
+
var onCreate = element.getAttribute('dr-on-create');
|
780
804
|
this.__render = render;
|
781
805
|
var createParam;
|
782
806
|
if (onCreate) {
|
783
807
|
var script = "".concat(renderScript, " return ").concat(onCreate, " ");
|
784
808
|
createParam = ScriptUtils_1.ScriptUtils.eval(script, obj);
|
785
|
-
if (createParam) {
|
786
|
-
(_b = instance === null || instance === void 0 ? void 0 : instance.onCreateRender) === null || _b === void 0 ? void 0 : _b.call(instance, createParam);
|
787
|
-
}
|
788
809
|
}
|
789
|
-
|
810
|
+
(_c = instance === null || instance === void 0 ? void 0 : instance.onCreateRender) === null || _c === void 0 ? void 0 : _c.call(instance, createParam);
|
811
|
+
var i = instance.__domrender_component_new = ((_d = instance.__domrender_component_new) !== null && _d !== void 0 ? _d : new Proxy({}, new Types_1.DomRenderFinalProxy()));
|
790
812
|
i.thisVariableName = rawSet.point.thisVariableName;
|
791
813
|
i.thisFullVariableName = "this.__domrender_components.".concat(componentKey);
|
814
|
+
i.componentKey = componentKey;
|
792
815
|
i.rawSet = rawSet;
|
793
816
|
i.innerHTML = element.innerHTML;
|
794
817
|
i.rootCreator = new Proxy(obj, new Types_1.DomRenderFinalProxy());
|
@@ -812,7 +835,7 @@ var RawSet = /** @class */ (function () {
|
|
812
835
|
__render: render
|
813
836
|
}));
|
814
837
|
}
|
815
|
-
var innerHTML = ((
|
838
|
+
var innerHTML = ((_e = styles === null || styles === void 0 ? void 0 : styles.map(function (it) { return "<style>".concat(it, "</style>"); })) !== null && _e !== void 0 ? _e : []).join(' ') + (applayTemplate !== null && applayTemplate !== void 0 ? applayTemplate : '');
|
816
839
|
element.innerHTML = innerHTML;
|
817
840
|
// console.log('------>', element.innerHTML, obj)
|
818
841
|
var data = RawSet.drThisCreate(element, "this.__domrender_components.".concat(componentKey), '', true, obj, config);
|
package/dist/bundle.js
CHANGED
@@ -53,6 +53,15 @@ var __assign = function () {
|
|
53
53
|
|
54
54
|
return __assign.apply(this, arguments);
|
55
55
|
};
|
56
|
+
function __spreadArray(to, from, pack) {
|
57
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
58
|
+
if (ar || !(i in from)) {
|
59
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
60
|
+
ar[i] = from[i];
|
61
|
+
}
|
62
|
+
}
|
63
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
64
|
+
}
|
56
65
|
|
57
66
|
var ValidUtils = /** @class */ (function () {
|
58
67
|
function ValidUtils() {
|
@@ -617,7 +626,7 @@ var EventManager = /** @class */ (function () {
|
|
617
626
|
var elements = Array.from(childNodes).filter(function (it) { return it.nodeType === 1; }).map(function (it) { return it; });
|
618
627
|
elements.forEach(function (it) {
|
619
628
|
var _a;
|
620
|
-
(_a = config === null || config === void 0 ? void 0 : config.applyEvents) === null || _a === void 0 ? void 0 : _a.filter(function (ta) { return it.getAttribute(ta.attrName); }).forEach(function (ta) { return ta.callBack(it, it.getAttribute(ta.attrName), obj); });
|
629
|
+
(_a = config === null || config === void 0 ? void 0 : config.applyEvents) === null || _a === void 0 ? void 0 : _a.filter(function (ta) { return it.getAttribute(ta.attrName) !== null; }).forEach(function (ta) { return ta.callBack(it, it.getAttribute(ta.attrName), obj); });
|
621
630
|
});
|
622
631
|
};
|
623
632
|
// eslint-disable-next-line no-undef
|
@@ -1570,23 +1579,24 @@ var RawSet = /** @class */ (function () {
|
|
1570
1579
|
// const targetElement = config?.targetElements?.find(it => (!drAttr.drIf && !drAttr.drForOf && !drAttr.drFor && !drAttr.drRepeat) && it.name.toLowerCase() === element.tagName.toLowerCase());
|
1571
1580
|
var targetElement = (_9 = config === null || config === void 0 ? void 0 : config.targetElements) === null || _9 === void 0 ? void 0 : _9.find(function (it) { return it.name.toLowerCase() === element_2.tagName.toLowerCase(); });
|
1572
1581
|
if (targetElement) {
|
1573
|
-
var
|
1582
|
+
var documentFragment = targetElement.callBack(element_2, obj, this_1);
|
1574
1583
|
// console.log('target-->',name, documentFragment)
|
1575
|
-
if (
|
1584
|
+
if (documentFragment) {
|
1576
1585
|
var detectAction_1 = element_2.getAttribute(RawSet.DR_DETECT_NAME);
|
1577
|
-
|
1586
|
+
var render_1 = documentFragment.render;
|
1587
|
+
if (detectAction_1 && render_1) {
|
1578
1588
|
this_1.detect = {
|
1579
1589
|
action: function () {
|
1580
1590
|
var script = "var $component = this.__render.component; var $element = this.__render.element; var $innerHTML = this.__render.innerHTML; var $attribute = this.__render.attribute; ".concat(detectAction_1, " ");
|
1581
1591
|
ScriptUtils.eval(script, Object.assign(obj, {
|
1582
|
-
__render:
|
1592
|
+
__render: render_1
|
1583
1593
|
}));
|
1584
1594
|
}
|
1585
1595
|
};
|
1586
1596
|
}
|
1587
1597
|
// fag.append(documentFragment)
|
1588
|
-
var rr = RawSet.checkPointCreates(
|
1589
|
-
(_10 = element_2.parentNode) === null || _10 === void 0 ? void 0 : _10.replaceChild(
|
1598
|
+
var rr = RawSet.checkPointCreates(documentFragment, config);
|
1599
|
+
(_10 = element_2.parentNode) === null || _10 === void 0 ? void 0 : _10.replaceChild(documentFragment, element_2);
|
1590
1600
|
raws.push.apply(raws, rr);
|
1591
1601
|
onElementInitCallBack.push({
|
1592
1602
|
name: targetElement.name.toLowerCase(),
|
@@ -1653,6 +1663,20 @@ var RawSet = /** @class */ (function () {
|
|
1653
1663
|
var it_2 = onAttrInitCallBack_1[_25];
|
1654
1664
|
(_22 = config === null || config === void 0 ? void 0 : config.onAttrInit) === null || _22 === void 0 ? void 0 : _22.call(config, it_2.attrName, it_2.attrValue, obj, this);
|
1655
1665
|
}
|
1666
|
+
// component destroy
|
1667
|
+
if (obj.__domrender_components) {
|
1668
|
+
Object.entries(obj.__domrender_components).forEach(function (_a) {
|
1669
|
+
var _b, _c;
|
1670
|
+
var key = _a[0], value = _a[1];
|
1671
|
+
var domrenderComponentNew = value.__domrender_component_new;
|
1672
|
+
var rawSet = domrenderComponentNew === null || domrenderComponentNew === void 0 ? void 0 : domrenderComponentNew.rawSet;
|
1673
|
+
if (rawSet && !rawSet.isConnected) {
|
1674
|
+
(_c = (_b = obj.__domrender_components[key]) === null || _b === void 0 ? void 0 : _b.onDestroyRender) === null || _c === void 0 ? void 0 : _c.call(_b, domrenderComponentNew);
|
1675
|
+
delete obj.__domrender_components[key];
|
1676
|
+
}
|
1677
|
+
// console.log('destroy', key, value);
|
1678
|
+
});
|
1679
|
+
}
|
1656
1680
|
return raws;
|
1657
1681
|
};
|
1658
1682
|
RawSet.prototype.applyEvent = function (obj, fragment, config) {
|
@@ -1984,21 +2008,16 @@ var RawSet = /** @class */ (function () {
|
|
1984
2008
|
styles: styles,
|
1985
2009
|
template: template,
|
1986
2010
|
callBack: function (element, obj, rawSet) {
|
1987
|
-
var _a, _b, _c, _d;
|
2011
|
+
var _a, _b, _c, _d, _e;
|
1988
2012
|
// console.log('callback------->')
|
1989
2013
|
if (!obj.__domrender_components) {
|
1990
2014
|
obj.__domrender_components = {};
|
1991
2015
|
}
|
1992
2016
|
var domrenderComponents = obj.__domrender_components;
|
1993
2017
|
var componentKey = '_' + RandomUtils.getRandomString(20);
|
1994
|
-
// console.log('callback settttt---a-->', componentKey, objFactory, objFactory(element, obj, rawSet))
|
1995
|
-
domrenderComponents[componentKey] = objFactory(element, obj, rawSet);
|
1996
|
-
var instance = domrenderComponents[componentKey];
|
1997
2018
|
var attribute = DomUtils.getAttributeToObject(element);
|
1998
|
-
var onCreate = element.getAttribute('dr-on-create');
|
1999
2019
|
var renderScript = 'var $component = this.__render.component; var $element = this.__render.element; var $router = this.__render.router; var $innerHTML = this.__render.innerHTML; var $attribute = this.__render.attribute;';
|
2000
2020
|
var render = Object.freeze({
|
2001
|
-
component: instance,
|
2002
2021
|
element: element,
|
2003
2022
|
innerHTML: element.innerHTML,
|
2004
2023
|
attribute: attribute,
|
@@ -2008,18 +2027,31 @@ var RawSet = /** @class */ (function () {
|
|
2008
2027
|
scripts: EventManager.setBindProperty((_a = config.scripts) !== null && _a !== void 0 ? _a : {}, obj)
|
2009
2028
|
// eslint-disable-next-line no-use-before-define
|
2010
2029
|
});
|
2030
|
+
var constructor = element.getAttribute('dr-constructor');
|
2031
|
+
var constructorParam = [];
|
2032
|
+
if (constructor) {
|
2033
|
+
var script = "".concat(renderScript, " return ").concat(constructor, " ");
|
2034
|
+
var param = (_b = ScriptUtils.eval(script, obj)) !== null && _b !== void 0 ? _b : [];
|
2035
|
+
if (!Array.isArray(param)) {
|
2036
|
+
param = [param];
|
2037
|
+
}
|
2038
|
+
constructorParam = param;
|
2039
|
+
}
|
2040
|
+
domrenderComponents[componentKey] = objFactory(element, obj, rawSet, constructorParam);
|
2041
|
+
var instance = domrenderComponents[componentKey];
|
2042
|
+
render = __assign({ component: instance }, render);
|
2043
|
+
var onCreate = element.getAttribute('dr-on-create');
|
2011
2044
|
this.__render = render;
|
2012
2045
|
var createParam;
|
2013
2046
|
if (onCreate) {
|
2014
2047
|
var script = "".concat(renderScript, " return ").concat(onCreate, " ");
|
2015
2048
|
createParam = ScriptUtils.eval(script, obj);
|
2016
|
-
if (createParam) {
|
2017
|
-
(_b = instance === null || instance === void 0 ? void 0 : instance.onCreateRender) === null || _b === void 0 ? void 0 : _b.call(instance, createParam);
|
2018
|
-
}
|
2019
2049
|
}
|
2020
|
-
|
2050
|
+
(_c = instance === null || instance === void 0 ? void 0 : instance.onCreateRender) === null || _c === void 0 ? void 0 : _c.call(instance, createParam);
|
2051
|
+
var i = instance.__domrender_component_new = ((_d = instance.__domrender_component_new) !== null && _d !== void 0 ? _d : new Proxy({}, new DomRenderFinalProxy()));
|
2021
2052
|
i.thisVariableName = rawSet.point.thisVariableName;
|
2022
2053
|
i.thisFullVariableName = "this.__domrender_components.".concat(componentKey);
|
2054
|
+
i.componentKey = componentKey;
|
2023
2055
|
i.rawSet = rawSet;
|
2024
2056
|
i.innerHTML = element.innerHTML;
|
2025
2057
|
i.rootCreator = new Proxy(obj, new DomRenderFinalProxy());
|
@@ -2043,7 +2075,7 @@ var RawSet = /** @class */ (function () {
|
|
2043
2075
|
__render: render
|
2044
2076
|
}));
|
2045
2077
|
}
|
2046
|
-
var innerHTML = ((
|
2078
|
+
var innerHTML = ((_e = styles === null || styles === void 0 ? void 0 : styles.map(function (it) { return "<style>".concat(it, "</style>"); })) !== null && _e !== void 0 ? _e : []).join(' ') + (applayTemplate !== null && applayTemplate !== void 0 ? applayTemplate : '');
|
2047
2079
|
element.innerHTML = innerHTML;
|
2048
2080
|
// console.log('------>', element.innerHTML, obj)
|
2049
2081
|
var data = RawSet.drThisCreate(element, "this.__domrender_components.".concat(componentKey), '', true, obj, config);
|
@@ -2435,14 +2467,26 @@ var Router = /** @class */ (function () {
|
|
2435
2467
|
function Router(rootObj, window) {
|
2436
2468
|
this.rootObj = rootObj;
|
2437
2469
|
this.window = window;
|
2470
|
+
this.attachCallbacks = new Set();
|
2438
2471
|
this.go(this.getUrl());
|
2439
2472
|
}
|
2473
|
+
Router.prototype.addAttachCallback = function (callback) {
|
2474
|
+
this.attachCallbacks.add(callback);
|
2475
|
+
};
|
2440
2476
|
Router.prototype.attach = function () {
|
2477
|
+
var _this = this;
|
2441
2478
|
var proxy = this.rootObj._DomRender_proxy;
|
2442
2479
|
if (proxy) {
|
2443
|
-
var key = "___".concat(EventManager.ROUTER_VARNAME
|
2480
|
+
var key = "___".concat(EventManager.ROUTER_VARNAME);
|
2444
2481
|
proxy.render(key);
|
2445
2482
|
}
|
2483
|
+
this.attachCallbacks.forEach(function (it) {
|
2484
|
+
it(_this.getRouteData());
|
2485
|
+
});
|
2486
|
+
};
|
2487
|
+
Router.prototype.testRegexp = function (regexp) {
|
2488
|
+
var b = RegExp(regexp).test(this.getPath());
|
2489
|
+
return b;
|
2446
2490
|
};
|
2447
2491
|
Router.prototype.getRouteData = function (urlExpression) {
|
2448
2492
|
var newVar = {
|
@@ -2460,7 +2504,7 @@ var Router = /** @class */ (function () {
|
|
2460
2504
|
newVar.pathData = data_1;
|
2461
2505
|
}
|
2462
2506
|
}
|
2463
|
-
return newVar;
|
2507
|
+
return Object.freeze(newVar);
|
2464
2508
|
};
|
2465
2509
|
// eslint-disable-next-line no-dupe-class-members
|
2466
2510
|
Router.prototype.go = function (path, urlExpressionOrData, dataOrTitle, title) {
|
@@ -2479,8 +2523,16 @@ var Router = /** @class */ (function () {
|
|
2479
2523
|
this.attach();
|
2480
2524
|
};
|
2481
2525
|
Router.prototype.getPathData = function (urlExpression, currentUrl) {
|
2482
|
-
if (currentUrl === void 0) { currentUrl = this.getPath(); }
|
2483
2526
|
// console.log('getPathData-->', urlExpression, currentUrl);
|
2527
|
+
// const regexps = StringUtils.regexExec(/(\{(?:\{??[^{]*?\}))/g, urlExpression);
|
2528
|
+
// const regexpMap = new Map<string, string>()
|
2529
|
+
// regexps.forEach((item, idx) => {
|
2530
|
+
// const key = `{${idx}}`;
|
2531
|
+
// const value = item[0];
|
2532
|
+
// urlExpression = urlExpression.replace(value, key)
|
2533
|
+
// regexpMap.set(key, value)
|
2534
|
+
// })
|
2535
|
+
if (currentUrl === void 0) { currentUrl = this.getPath(); }
|
2484
2536
|
var urls = currentUrl.split('?')[0].split('/');
|
2485
2537
|
var urlExpressions = urlExpression.split('/');
|
2486
2538
|
if (urls.length !== urlExpressions.length) {
|
@@ -2489,6 +2541,7 @@ var Router = /** @class */ (function () {
|
|
2489
2541
|
var data = {};
|
2490
2542
|
for (var i = 0; i < urlExpressions.length; i++) {
|
2491
2543
|
var it_1 = urlExpressions[i];
|
2544
|
+
// it = regexpMap.get(it) ?? it;
|
2492
2545
|
var urlit = urls[i];
|
2493
2546
|
// ex) {serialNo:[0-9]+} or {no} ..
|
2494
2547
|
var execResult = /^\{(.+)\}$/g.exec(it_1);
|
@@ -2500,7 +2553,8 @@ var Router = /** @class */ (function () {
|
|
2500
2553
|
}
|
2501
2554
|
// regex check
|
2502
2555
|
var _a = execResult[1].split(':'), name_1 = _a[0], regex = _a[1]; // group1
|
2503
|
-
|
2556
|
+
var regExp = RegExp(regex);
|
2557
|
+
if (regex && !regExp.test(urlit)) {
|
2504
2558
|
return;
|
2505
2559
|
}
|
2506
2560
|
data[name_1] = urlit;
|
@@ -2646,7 +2700,7 @@ var DomRender = /** @class */ (function () {
|
|
2646
2700
|
if (!config) {
|
2647
2701
|
config = { window: window };
|
2648
2702
|
}
|
2649
|
-
config.routerType = config.routerType || '
|
2703
|
+
config.routerType = config.routerType || 'none';
|
2650
2704
|
var domRender = new DomRenderProxy(obj, target, config);
|
2651
2705
|
var dest = new Proxy(obj, domRender);
|
2652
2706
|
robj = dest;
|
@@ -2659,9 +2713,48 @@ var DomRender = /** @class */ (function () {
|
|
2659
2713
|
domRender.run(robj);
|
2660
2714
|
return robj;
|
2661
2715
|
};
|
2716
|
+
DomRender.addComponent = function (config, _a, _b) {
|
2717
|
+
var _c;
|
2718
|
+
var type = _a.type, _d = _a.tagName, tagName = _d === void 0 ? type.name : _d;
|
2719
|
+
var template = _b.template, _e = _b.styles, styles = _e === void 0 ? [] : _e;
|
2720
|
+
var component = RawSet.createComponentTargetElement(tagName, function (e, o, r2, counstructorParam) {
|
2721
|
+
// console.log('------->',counstructorParam)
|
2722
|
+
return new (type.bind.apply(type, __spreadArray([void 0], counstructorParam, false)))();
|
2723
|
+
}, template, styles, config);
|
2724
|
+
config.targetElements = (_c = config.targetElements) !== null && _c !== void 0 ? _c : [];
|
2725
|
+
config.targetElements.push(component);
|
2726
|
+
return {
|
2727
|
+
add: function (source, front) {
|
2728
|
+
return DomRender.addComponent(config, source, front);
|
2729
|
+
}
|
2730
|
+
};
|
2731
|
+
};
|
2732
|
+
DomRender.addAttribute = function (config, attrName, getThisObj, factory) {
|
2733
|
+
var _a;
|
2734
|
+
var targetAttribute = RawSet.createComponentTargetAttribute(attrName, getThisObj, factory);
|
2735
|
+
config.targetAttrs = (_a = config.targetAttrs) !== null && _a !== void 0 ? _a : [];
|
2736
|
+
config.targetAttrs.push(targetAttribute);
|
2737
|
+
return {
|
2738
|
+
add: function (attrName, getThisObj, factory) {
|
2739
|
+
return DomRender.addAttribute(config, attrName, getThisObj, factory);
|
2740
|
+
}
|
2741
|
+
};
|
2742
|
+
};
|
2743
|
+
DomRender.addAttributeCallBack = function (config, attrName, callBack) {
|
2744
|
+
var _a;
|
2745
|
+
config.applyEvents = (_a = config.applyEvents) !== null && _a !== void 0 ? _a : [];
|
2746
|
+
config.applyEvents.push({
|
2747
|
+
attrName: attrName,
|
2748
|
+
callBack: callBack
|
2749
|
+
});
|
2750
|
+
return {
|
2751
|
+
add: function (attrName, callBack) {
|
2752
|
+
return DomRender.addAttributeCallBack(config, attrName, callBack);
|
2753
|
+
}
|
2754
|
+
};
|
2755
|
+
};
|
2662
2756
|
return DomRender;
|
2663
|
-
}());
|
2664
|
-
// export default DomRender;
|
2757
|
+
}());
|
2665
2758
|
|
2666
2759
|
var RenderManager = /** @class */ (function () {
|
2667
2760
|
function RenderManager() {
|
@@ -2887,34 +2980,34 @@ var CountLessThanEqualsUnCheckedValidatorArray = /** @class */ (function (_super
|
|
2887
2980
|
return CountLessThanEqualsUnCheckedValidatorArray;
|
2888
2981
|
}(ValidatorArray));
|
2889
2982
|
|
2890
|
-
var
|
2891
|
-
__extends(
|
2892
|
-
function
|
2983
|
+
var CountLessThanUnCheckedValidatorArray = /** @class */ (function (_super) {
|
2984
|
+
__extends(CountLessThanUnCheckedValidatorArray, _super);
|
2985
|
+
function CountLessThanUnCheckedValidatorArray(count, value, target, event, autoValid) {
|
2893
2986
|
if (autoValid === void 0) { autoValid = true; }
|
2894
2987
|
var _this = _super.call(this, value, target, event, autoValid) || this;
|
2895
2988
|
_this.count = count;
|
2896
2989
|
return _this;
|
2897
2990
|
}
|
2898
|
-
|
2991
|
+
CountLessThanUnCheckedValidatorArray.prototype.valid = function () {
|
2899
2992
|
var _a;
|
2900
|
-
return ((_a = this.value) !== null && _a !== void 0 ? _a : []).filter(function (it) { return !it.checked; }).length
|
2993
|
+
return ((_a = this.value) !== null && _a !== void 0 ? _a : []).filter(function (it) { return !it.checked; }).length < this.count;
|
2901
2994
|
};
|
2902
|
-
return
|
2995
|
+
return CountLessThanUnCheckedValidatorArray;
|
2903
2996
|
}(ValidatorArray));
|
2904
2997
|
|
2905
|
-
var
|
2906
|
-
__extends(
|
2907
|
-
function
|
2998
|
+
var CountUnCheckedValidatorArray = /** @class */ (function (_super) {
|
2999
|
+
__extends(CountUnCheckedValidatorArray, _super);
|
3000
|
+
function CountUnCheckedValidatorArray(count, value, target, event, autoValid) {
|
2908
3001
|
if (autoValid === void 0) { autoValid = true; }
|
2909
3002
|
var _this = _super.call(this, value, target, event, autoValid) || this;
|
2910
3003
|
_this.count = count;
|
2911
3004
|
return _this;
|
2912
3005
|
}
|
2913
|
-
|
3006
|
+
CountUnCheckedValidatorArray.prototype.valid = function () {
|
2914
3007
|
var _a;
|
2915
|
-
return ((_a = this.value) !== null && _a !== void 0 ? _a : []).filter(function (it) { return !it.checked; }).length
|
3008
|
+
return ((_a = this.value) !== null && _a !== void 0 ? _a : []).filter(function (it) { return !it.checked; }).length >= this.count;
|
2916
3009
|
};
|
2917
|
-
return
|
3010
|
+
return CountUnCheckedValidatorArray;
|
2918
3011
|
}(ValidatorArray));
|
2919
3012
|
|
2920
3013
|
var EmptyValidator = /** @class */ (function (_super) {
|
package/events/EventManager.js
CHANGED
@@ -190,7 +190,7 @@ var EventManager = /** @class */ (function () {
|
|
190
190
|
var elements = Array.from(childNodes).filter(function (it) { return it.nodeType === 1; }).map(function (it) { return it; });
|
191
191
|
elements.forEach(function (it) {
|
192
192
|
var _a;
|
193
|
-
(_a = config === null || config === void 0 ? void 0 : config.applyEvents) === null || _a === void 0 ? void 0 : _a.filter(function (ta) { return it.getAttribute(ta.attrName); }).forEach(function (ta) { return ta.callBack(it, it.getAttribute(ta.attrName), obj); });
|
193
|
+
(_a = config === null || config === void 0 ? void 0 : config.applyEvents) === null || _a === void 0 ? void 0 : _a.filter(function (ta) { return it.getAttribute(ta.attrName) !== null; }).forEach(function (ta) { return ta.callBack(it, it.getAttribute(ta.attrName), obj); });
|
194
194
|
});
|
195
195
|
};
|
196
196
|
// eslint-disable-next-line no-undef
|
package/package.json
CHANGED
package/routers/Router.d.ts
CHANGED
@@ -8,8 +8,11 @@ export declare type RouteData = {
|
|
8
8
|
export declare abstract class Router {
|
9
9
|
rootObj: any;
|
10
10
|
window: Window;
|
11
|
+
private attachCallbacks;
|
11
12
|
constructor(rootObj: any, window: Window);
|
13
|
+
addAttachCallback(callback: (routeData: RouteData) => void): void;
|
12
14
|
attach(): void;
|
15
|
+
testRegexp(regexp: string): boolean;
|
13
16
|
abstract test(urlExpression: string): boolean;
|
14
17
|
abstract set(path: string, data?: any, title?: string): void;
|
15
18
|
getRouteData(urlExpression?: string): RouteData;
|
package/routers/Router.js
CHANGED
@@ -17,14 +17,26 @@ var Router = /** @class */ (function () {
|
|
17
17
|
function Router(rootObj, window) {
|
18
18
|
this.rootObj = rootObj;
|
19
19
|
this.window = window;
|
20
|
+
this.attachCallbacks = new Set();
|
20
21
|
this.go(this.getUrl());
|
21
22
|
}
|
23
|
+
Router.prototype.addAttachCallback = function (callback) {
|
24
|
+
this.attachCallbacks.add(callback);
|
25
|
+
};
|
22
26
|
Router.prototype.attach = function () {
|
27
|
+
var _this = this;
|
23
28
|
var proxy = this.rootObj._DomRender_proxy;
|
24
29
|
if (proxy) {
|
25
|
-
var key = "___".concat(EventManager_1.EventManager.ROUTER_VARNAME
|
30
|
+
var key = "___".concat(EventManager_1.EventManager.ROUTER_VARNAME);
|
26
31
|
proxy.render(key);
|
27
32
|
}
|
33
|
+
this.attachCallbacks.forEach(function (it) {
|
34
|
+
it(_this.getRouteData());
|
35
|
+
});
|
36
|
+
};
|
37
|
+
Router.prototype.testRegexp = function (regexp) {
|
38
|
+
var b = RegExp(regexp).test(this.getPath());
|
39
|
+
return b;
|
28
40
|
};
|
29
41
|
Router.prototype.getRouteData = function (urlExpression) {
|
30
42
|
var newVar = {
|
@@ -42,7 +54,7 @@ var Router = /** @class */ (function () {
|
|
42
54
|
newVar.pathData = data_1;
|
43
55
|
}
|
44
56
|
}
|
45
|
-
return newVar;
|
57
|
+
return Object.freeze(newVar);
|
46
58
|
};
|
47
59
|
// eslint-disable-next-line no-dupe-class-members
|
48
60
|
Router.prototype.go = function (path, urlExpressionOrData, dataOrTitle, title) {
|
@@ -61,8 +73,16 @@ var Router = /** @class */ (function () {
|
|
61
73
|
this.attach();
|
62
74
|
};
|
63
75
|
Router.prototype.getPathData = function (urlExpression, currentUrl) {
|
64
|
-
if (currentUrl === void 0) { currentUrl = this.getPath(); }
|
65
76
|
// console.log('getPathData-->', urlExpression, currentUrl);
|
77
|
+
// const regexps = StringUtils.regexExec(/(\{(?:\{??[^{]*?\}))/g, urlExpression);
|
78
|
+
// const regexpMap = new Map<string, string>()
|
79
|
+
// regexps.forEach((item, idx) => {
|
80
|
+
// const key = `{${idx}}`;
|
81
|
+
// const value = item[0];
|
82
|
+
// urlExpression = urlExpression.replace(value, key)
|
83
|
+
// regexpMap.set(key, value)
|
84
|
+
// })
|
85
|
+
if (currentUrl === void 0) { currentUrl = this.getPath(); }
|
66
86
|
var urls = currentUrl.split('?')[0].split('/');
|
67
87
|
var urlExpressions = urlExpression.split('/');
|
68
88
|
if (urls.length !== urlExpressions.length) {
|
@@ -71,6 +91,7 @@ var Router = /** @class */ (function () {
|
|
71
91
|
var data = {};
|
72
92
|
for (var i = 0; i < urlExpressions.length; i++) {
|
73
93
|
var it_1 = urlExpressions[i];
|
94
|
+
// it = regexpMap.get(it) ?? it;
|
74
95
|
var urlit = urls[i];
|
75
96
|
// ex) {serialNo:[0-9]+} or {no} ..
|
76
97
|
var execResult = /^\{(.+)\}$/g.exec(it_1);
|
@@ -82,7 +103,8 @@ var Router = /** @class */ (function () {
|
|
82
103
|
}
|
83
104
|
// regex check
|
84
105
|
var _a = execResult[1].split(':'), name_1 = _a[0], regex = _a[1]; // group1
|
85
|
-
|
106
|
+
var regExp = RegExp(regex);
|
107
|
+
if (regex && !regExp.test(urlit)) {
|
86
108
|
return;
|
87
109
|
}
|
88
110
|
data[name_1] = urlit;
|