dom-render 1.0.83 → 1.0.86
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 +5 -5
- package/DomRender.js +10 -5
- package/DomRenderProxy.d.ts +2 -2
- package/DomRenderProxy.js +2 -0
- package/README.MD +7 -7
- package/RawSet.d.ts +14 -10
- package/RawSet.js +130 -84
- package/configs/Config.d.ts +26 -0
- package/{Config.js → configs/Config.js} +0 -0
- package/configs/TargetAttr.d.ts +6 -0
- package/configs/TargetAttr.js +2 -0
- package/configs/TargetElement.d.ts +11 -0
- package/configs/TargetElement.js +2 -0
- package/dist/bundle.js +324 -271
- package/events/EventManager.d.ts +1 -1
- package/lifecycle/OnProxyDomRender.d.ts +1 -1
- package/messenger/Messenger.d.ts +1 -1
- package/operators/DrTargetElement.js +1 -1
- package/operators/DrThis.js +2 -2
- package/operators/OperatorRender.d.ts +1 -1
- package/package.json +1 -1
- package/Config.d.ts +0 -38
package/DomRender.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Config } from './Config';
|
|
1
|
+
import { Config } from './configs/Config';
|
|
2
2
|
import { ConstructorType } from './types/Types';
|
|
3
3
|
import { RawSet } from './RawSet';
|
|
4
4
|
export declare class DomRender {
|
|
5
|
-
static run<T extends object>(obj: T, target?: Node,
|
|
5
|
+
static run<T extends object>(obj: T, target?: Node | null, oConfig?: Omit<Config, 'window'>): T;
|
|
6
6
|
static createComponent(param: {
|
|
7
|
-
type: ConstructorType<any
|
|
7
|
+
type: ConstructorType<any> | any;
|
|
8
8
|
tagName?: string;
|
|
9
9
|
template?: string;
|
|
10
10
|
styles?: string[] | string;
|
|
11
|
-
}
|
|
12
|
-
static createAttribute(attrName: string, getThisObj: (element: Element, attrValue: string, obj: any, rawSet: RawSet) => any, factory: (element: Element, attrValue: string, obj: any, rawSet: RawSet) => DocumentFragment): import("./
|
|
11
|
+
}): import("./configs/TargetElement").TargetElement;
|
|
12
|
+
static createAttribute(attrName: string, getThisObj: (element: Element, attrValue: string, obj: any, rawSet: RawSet) => any, factory: (element: Element, attrValue: string, obj: any, rawSet: RawSet) => DocumentFragment): import("./configs/TargetAttr").TargetAttr;
|
|
13
13
|
}
|
package/DomRender.js
CHANGED
|
@@ -19,7 +19,7 @@ var DefaultMessenger_1 = require("./messenger/DefaultMessenger");
|
|
|
19
19
|
var DomRender = /** @class */ (function () {
|
|
20
20
|
function DomRender() {
|
|
21
21
|
}
|
|
22
|
-
DomRender.run = function (obj, target,
|
|
22
|
+
DomRender.run = function (obj, target, oConfig) {
|
|
23
23
|
var _a, _b, _c;
|
|
24
24
|
var robj = obj;
|
|
25
25
|
if ('_DomRender_isProxy' in obj) {
|
|
@@ -29,9 +29,13 @@ var DomRender = /** @class */ (function () {
|
|
|
29
29
|
robj = obj;
|
|
30
30
|
return robj;
|
|
31
31
|
}
|
|
32
|
+
var config = oConfig;
|
|
32
33
|
if (!config) {
|
|
33
34
|
config = { window: window };
|
|
34
35
|
}
|
|
36
|
+
if (config && !config.window) {
|
|
37
|
+
config.window = window;
|
|
38
|
+
}
|
|
35
39
|
config.routerType = config.routerType || 'none';
|
|
36
40
|
config.messenger = Types_1.DomRenderFinalProxy.final((_a = config.messenger) !== null && _a !== void 0 ? _a : new DefaultMessenger_1.DefaultMessenger(config));
|
|
37
41
|
var domRender = new DomRenderProxy_1.DomRenderProxy(obj, target, config);
|
|
@@ -46,12 +50,13 @@ var DomRender = /** @class */ (function () {
|
|
|
46
50
|
domRender.run(robj);
|
|
47
51
|
return robj;
|
|
48
52
|
};
|
|
49
|
-
DomRender.createComponent = function (param
|
|
53
|
+
DomRender.createComponent = function (param) {
|
|
50
54
|
var _a, _b;
|
|
51
|
-
|
|
55
|
+
// console.log('===>', typeof param.type, param.type.name, param.type.constructor.name)
|
|
56
|
+
var component = RawSet_1.RawSet.createComponentTargetElement((_a = param.tagName) !== null && _a !== void 0 ? _a : (typeof param.type === 'function' ? param.type.name : param.type.constructor.name), function (e, o, r2, counstructorParam) {
|
|
52
57
|
var _a;
|
|
53
|
-
return new ((_a = param.type).bind.apply(_a, __spreadArray([void 0], counstructorParam, false)))();
|
|
54
|
-
}, (_b = param.template) !== null && _b !== void 0 ? _b : '', Array.isArray(param.styles) ? param.styles : (param.styles ? [param.styles] : undefined)
|
|
58
|
+
return typeof param.type === 'function' ? new ((_a = param.type).bind.apply(_a, __spreadArray([void 0], counstructorParam, false)))() : param.type;
|
|
59
|
+
}, (_b = param.template) !== null && _b !== void 0 ? _b : '', Array.isArray(param.styles) ? param.styles : (param.styles ? [param.styles] : undefined));
|
|
55
60
|
return component;
|
|
56
61
|
};
|
|
57
62
|
DomRender.createAttribute = function (attrName, getThisObj, factory) {
|
package/DomRenderProxy.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RawSet } from './RawSet';
|
|
2
|
-
import { Config } from './Config';
|
|
2
|
+
import { Config } from './configs/Config';
|
|
3
3
|
export declare class DomRenderProxy<T extends object> implements ProxyHandler<T> {
|
|
4
4
|
_domRender_origin: T;
|
|
5
5
|
config: Config;
|
|
@@ -7,7 +7,7 @@ export declare class DomRenderProxy<T extends object> implements ProxyHandler<T>
|
|
|
7
7
|
_rawSets: Map<string, Set<RawSet>>;
|
|
8
8
|
_domRender_proxy?: T;
|
|
9
9
|
_targets: Set<Node>;
|
|
10
|
-
constructor(_domRender_origin: T, target: Node | undefined, config: Config);
|
|
10
|
+
constructor(_domRender_origin: T, target: Node | null | undefined, config: Config);
|
|
11
11
|
static unFinal<T = any>(obj: T): T;
|
|
12
12
|
static final<T = any>(obj: T): T;
|
|
13
13
|
static isFinal<T = any>(obj: T): boolean;
|
package/DomRenderProxy.js
CHANGED
|
@@ -134,7 +134,9 @@ var DomRenderProxy = /** @class */ (function () {
|
|
|
134
134
|
// ------------------->
|
|
135
135
|
}
|
|
136
136
|
else {
|
|
137
|
+
// console.log('---rawSets->', it)
|
|
137
138
|
var rawSets = it.render(_this._domRender_proxy, _this.config);
|
|
139
|
+
// console.log('---rawSets->', rawSets)
|
|
138
140
|
// 대상 attribute 있으면
|
|
139
141
|
// const targetAttrs = (it.point.node as Element).getAttribute(EventManager.normalAttrMapAttrName);
|
|
140
142
|
// if (it?.data.onChangeAttrRender && it.type === RawSetType.TARGET_ELEMENT && targetAttrs) {
|
package/README.MD
CHANGED
|
@@ -7,7 +7,7 @@ DOM-RENDER
|
|
|
7
7
|
|
|
8
8
|
# 🚀 Quick start
|
|
9
9
|
```html
|
|
10
|
-
<script src="https://cdn.jsdelivr.net/npm/dom-render@1.0.
|
|
10
|
+
<script src="https://cdn.jsdelivr.net/npm/dom-render@1.0.86/dist/bundle.js"></script>
|
|
11
11
|
```
|
|
12
12
|
```html
|
|
13
13
|
<!DOCTYPE html>
|
|
@@ -18,7 +18,7 @@ DOM-RENDER
|
|
|
18
18
|
</head>
|
|
19
19
|
<body id="app">
|
|
20
20
|
${this.name}$
|
|
21
|
-
<script src="https://cdn.jsdelivr.net/npm/dom-render@1.0.
|
|
21
|
+
<script src="https://cdn.jsdelivr.net/npm/dom-render@1.0.86/dist/bundle.js"></script>
|
|
22
22
|
<script>
|
|
23
23
|
let data = {
|
|
24
24
|
name: 'my name is dom-render'
|
|
@@ -404,9 +404,9 @@ const config: Config = {
|
|
|
404
404
|
window
|
|
405
405
|
};
|
|
406
406
|
config.targetElements = [
|
|
407
|
-
DomRender.createComponent({type: Main, tagName: 'page-main', template: MainTemplate}
|
|
408
|
-
DomRender.createComponent({type: Second, tagName: 'page-second', template: SecondTemplate}
|
|
409
|
-
DomRender.createComponent({type: Detail, tagName: 'page-detail', template: DetailTemplate}
|
|
407
|
+
DomRender.createComponent({type: Main, tagName: 'page-main', template: MainTemplate}),
|
|
408
|
+
DomRender.createComponent({type: Second, tagName: 'page-second', template: SecondTemplate}),
|
|
409
|
+
DomRender.createComponent({type: Detail, tagName: 'page-detail', template: DetailTemplate})
|
|
410
410
|
]
|
|
411
411
|
config.routerType = 'hash'; // 'hash' | 'path' | 'none';
|
|
412
412
|
const data = DomRender.run(new Data(), document.querySelector('#app')!, config);
|
|
@@ -644,8 +644,8 @@ link attribute
|
|
|
644
644
|
```
|
|
645
645
|
```typescript
|
|
646
646
|
config.targetElements = [
|
|
647
|
-
DomRender.createComponent({type: Profile, template: ProfileTemplate}
|
|
648
|
-
DomRender.createComponent({type: Home, template: HomeTemplate, styles: HomeStyle}
|
|
647
|
+
DomRender.createComponent({type: Profile, template: ProfileTemplate}),
|
|
648
|
+
DomRender.createComponent({type: Home, template: HomeTemplate, styles: HomeStyle})
|
|
649
649
|
]
|
|
650
650
|
|
|
651
651
|
config.targetAttrs = [
|
package/RawSet.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Config
|
|
1
|
+
import { Config } from './configs/Config';
|
|
2
2
|
import { ComponentSet } from './components/ComponentSet';
|
|
3
|
+
import { TargetElement } from './configs/TargetElement';
|
|
4
|
+
import { TargetAttr } from './configs/TargetAttr';
|
|
3
5
|
export declare enum DestroyOptionType {
|
|
4
6
|
NO_DESTROY = "NO_DESTROY",
|
|
5
7
|
NO_MESSENGER_DESTROY = "NO_MESSENGER_DESTROY"
|
|
@@ -49,6 +51,7 @@ export declare type ElementInitCallBack = {
|
|
|
49
51
|
};
|
|
50
52
|
export declare enum RawSetType {
|
|
51
53
|
TEXT = "TEXT",
|
|
54
|
+
STYLE_TEXT = "STYLE_TEXT",
|
|
52
55
|
TARGET_ELEMENT = "TARGET_ELEMENT",
|
|
53
56
|
TARGET_ATTR = "TARGET_ATTR",
|
|
54
57
|
UNKOWN = "UNKOWN"
|
|
@@ -71,10 +74,11 @@ export declare class RawSet {
|
|
|
71
74
|
uuid: string;
|
|
72
75
|
type: RawSetType;
|
|
73
76
|
point: {
|
|
74
|
-
start: Comment;
|
|
77
|
+
start: Comment | Text | HTMLMetaElement;
|
|
75
78
|
node: Node;
|
|
76
|
-
end: Comment;
|
|
79
|
+
end: Comment | Text | HTMLMetaElement;
|
|
77
80
|
thisVariableName?: string | null;
|
|
81
|
+
parent?: Node | null;
|
|
78
82
|
};
|
|
79
83
|
fragment: DocumentFragment;
|
|
80
84
|
detect?: {
|
|
@@ -105,16 +109,18 @@ export declare class RawSet {
|
|
|
105
109
|
static readonly DR_TAGS: never[];
|
|
106
110
|
static readonly DR_ATTRIBUTES: string[];
|
|
107
111
|
constructor(uuid: string, type: RawSetType, point: {
|
|
108
|
-
start: Comment;
|
|
112
|
+
start: Comment | Text | HTMLMetaElement;
|
|
109
113
|
node: Node;
|
|
110
|
-
end: Comment;
|
|
114
|
+
end: Comment | Text | HTMLMetaElement;
|
|
111
115
|
thisVariableName?: string | null;
|
|
116
|
+
parent?: Node | null;
|
|
112
117
|
}, fragment: DocumentFragment, detect?: {
|
|
113
118
|
action: Function;
|
|
114
119
|
} | undefined, data?: any);
|
|
115
120
|
get isConnected(): boolean;
|
|
116
121
|
getUsingTriggerVariables(config?: Config): Set<string>;
|
|
117
122
|
render(obj: any, config: Config): RawSet[];
|
|
123
|
+
generateCSS(id: string, cssRule: CSSRule): void;
|
|
118
124
|
applyEvent(obj: any, fragment?: DocumentFragment, config?: Config): void;
|
|
119
125
|
getAttribute(element: Element, attr: string): string | null;
|
|
120
126
|
getAttributeAndDelete(element: Element, attr: string): string | null;
|
|
@@ -139,13 +145,11 @@ export declare class RawSet {
|
|
|
139
145
|
regex: RegExp;
|
|
140
146
|
random: string;
|
|
141
147
|
}[]): void;
|
|
142
|
-
static drThisCreate(element: Element, drThis: string, drVarOption: string, drStripOption: boolean | string | null, obj: any, config: Config, set?: ComponentSet): DocumentFragment;
|
|
148
|
+
static drThisCreate(rawSet: RawSet, element: Element, drThis: string, drVarOption: string, drStripOption: boolean | string | null, obj: any, config: Config, set?: ComponentSet): DocumentFragment;
|
|
143
149
|
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;
|
|
144
|
-
static createComponentTargetElement(name: string, objFactory: (element: Element, obj: any, rawSet: RawSet, counstructorParam: any[]) => any, template
|
|
150
|
+
static createComponentTargetElement(name: string, objFactory: (element: Element, obj: any, rawSet: RawSet, counstructorParam: any[]) => any, template?: string, styles?: string[]): TargetElement;
|
|
145
151
|
static isExporesion(data: string | null): boolean;
|
|
146
152
|
static exporesionGrouops(data: string | null): RegExpExecArray[];
|
|
147
|
-
static styleTransformLocal(styleBody: string | string[], id: string, styleTagWrap?: boolean
|
|
148
|
-
static metaStart(id: string): string;
|
|
149
|
-
static metaEnd(id: string): string;
|
|
153
|
+
static styleTransformLocal(styleBody: string | string[], id: string, styleTagWrap?: boolean): string;
|
|
150
154
|
static destroy(obj: any | undefined, parameter: any[], config: Config, destroyOptions?: (DestroyOptionType | string)[]): void;
|
|
151
155
|
}
|
package/RawSet.js
CHANGED
|
@@ -50,6 +50,7 @@ var DestroyOptionType;
|
|
|
50
50
|
var RawSetType;
|
|
51
51
|
(function (RawSetType) {
|
|
52
52
|
RawSetType["TEXT"] = "TEXT";
|
|
53
|
+
RawSetType["STYLE_TEXT"] = "STYLE_TEXT";
|
|
53
54
|
RawSetType["TARGET_ELEMENT"] = "TARGET_ELEMENT";
|
|
54
55
|
RawSetType["TARGET_ATTR"] = "TARGET_ATTR";
|
|
55
56
|
RawSetType["UNKOWN"] = "UNKOWN";
|
|
@@ -146,21 +147,28 @@ var RawSet = /** @class */ (function () {
|
|
|
146
147
|
});
|
|
147
148
|
var fag = config.window.document.createDocumentFragment();
|
|
148
149
|
if (cNode.nodeType === Node.TEXT_NODE && cNode.textContent) {
|
|
150
|
+
// console.log('text-->', this, obj, config)
|
|
151
|
+
// console.log('text-->', Array.from(this.fragment.childNodes))
|
|
149
152
|
var textContent = cNode.textContent;
|
|
150
153
|
var runText = RawSet.exporesionGrouops(textContent)[0][1];
|
|
151
154
|
// console.log('--->', RawSet.exporesionGrouops(textContent), textContent,runText, runText[0][1])
|
|
152
|
-
var
|
|
155
|
+
var newNode = void 0;
|
|
153
156
|
if (textContent === null || textContent === void 0 ? void 0 : textContent.startsWith('#')) {
|
|
154
157
|
var r = ScriptUtils_1.ScriptUtils.eval("".concat(__render.bindScript, " return ").concat(runText), Object.assign(obj, { __render: __render }));
|
|
155
158
|
var template = config.window.document.createElement('template');
|
|
156
159
|
template.innerHTML = r;
|
|
157
|
-
|
|
160
|
+
newNode = template.content;
|
|
158
161
|
}
|
|
159
162
|
else {
|
|
160
163
|
var r = ScriptUtils_1.ScriptUtils.eval("".concat(__render.bindScript, " return ").concat(runText), Object.assign(obj, { __render: __render }));
|
|
161
|
-
|
|
164
|
+
newNode = config.window.document.createTextNode(r);
|
|
165
|
+
}
|
|
166
|
+
(_a = cNode.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(newNode, cNode);
|
|
167
|
+
// console.log('-------', this.point.start.parentNode.nodeName)
|
|
168
|
+
// 중요 style value change 됐을때 다시 처리해야되기떄문에: 마지막에 completed 없는 attr 가지고 판단 하니깐
|
|
169
|
+
if (this.type === RawSetType.STYLE_TEXT && this.point.parent) {
|
|
170
|
+
this.point.parent.removeAttribute('completed');
|
|
162
171
|
}
|
|
163
|
-
(_a = cNode.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(n, cNode);
|
|
164
172
|
}
|
|
165
173
|
else if (cNode.nodeType === Node.ELEMENT_NODE) {
|
|
166
174
|
var element = cNode;
|
|
@@ -215,7 +223,7 @@ var RawSet = /** @class */ (function () {
|
|
|
215
223
|
}
|
|
216
224
|
}
|
|
217
225
|
this.applyEvent(obj, genNode, config);
|
|
218
|
-
this.replaceBody(genNode);
|
|
226
|
+
this.replaceBody(genNode); // 중요 여기서 마지막에 연션된 값을 그려준다.
|
|
219
227
|
drAttrs.forEach(function (it) {
|
|
220
228
|
if (it.drCompleteOption) {
|
|
221
229
|
// genNode.childNodes
|
|
@@ -228,46 +236,25 @@ var RawSet = /** @class */ (function () {
|
|
|
228
236
|
}));
|
|
229
237
|
}
|
|
230
238
|
});
|
|
239
|
+
// 중요 style isolation 나중에 :scope로 대체 가능할듯.
|
|
240
|
+
Array.from(window.document.styleSheets).filter(function (it) { return it.ownerNode && it.ownerNode instanceof Element && it.ownerNode.getAttribute('id') && !it.ownerNode.getAttribute('completed'); }).forEach(function (it) {
|
|
241
|
+
var _a;
|
|
242
|
+
var styleElement = it.ownerNode;
|
|
243
|
+
var id = (_a = styleElement.getAttribute('id')) === null || _a === void 0 ? void 0 : _a.split('-')[0];
|
|
244
|
+
if (id) {
|
|
245
|
+
// console.log('------->', id)
|
|
246
|
+
Array.from(it.cssRules).forEach(function (it) {
|
|
247
|
+
_this.generateCSS(id, it);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
it.ownerNode.setAttribute('completed', 'true');
|
|
251
|
+
});
|
|
231
252
|
for (var _p = 0, onThisComponentSetCallBacks_1 = onThisComponentSetCallBacks; _p < onThisComponentSetCallBacks_1.length; _p++) {
|
|
232
253
|
var it_1 = onThisComponentSetCallBacks_1[_p];
|
|
233
254
|
(_c = (_b = it_1.obj).onInitRender) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
234
255
|
}
|
|
235
256
|
for (var _q = 0, onElementInitCallBacks_1 = onElementInitCallBacks; _q < onElementInitCallBacks_1.length; _q++) {
|
|
236
257
|
var it_2 = onElementInitCallBacks_1[_q];
|
|
237
|
-
// 중요 style isolation 나중에 :scope로 대체 가능할듯.
|
|
238
|
-
Array.from(window.document.styleSheets).filter(function (it) { return it.ownerNode && it.ownerNode instanceof Element && it.ownerNode.getAttribute('id') && !it.ownerNode.getAttribute('completed'); }).forEach(function (it) {
|
|
239
|
-
var _a;
|
|
240
|
-
var styleElement = it.ownerNode;
|
|
241
|
-
var id = (_a = styleElement.getAttribute('id')) === null || _a === void 0 ? void 0 : _a.split('-')[0];
|
|
242
|
-
if (id) {
|
|
243
|
-
// console.log('------->', id)
|
|
244
|
-
var start_1 = "#".concat(id, "-start");
|
|
245
|
-
var end_1 = "#".concat(id, "-end");
|
|
246
|
-
Array.from(it.cssRules).filter(function (it) { return it.constructor.name === 'CSSStyleRule'; }).forEach(function (it) {
|
|
247
|
-
var rule = it;
|
|
248
|
-
// rule.selectorText = `${start} ~ *:not(${start} ~ ${end} ~ *) ${rule.selectorText}`;
|
|
249
|
-
// rule.selectorText = `${start} ~ *:not(${start} ~ ${end} ~ ${rule.selectorText})`;
|
|
250
|
-
// console.log('-----', rule, rule.selectorText)
|
|
251
|
-
if (!rule.selectorText.startsWith(':root')) {
|
|
252
|
-
// rule.selectorText = `${start} ~ ${rule.selectorText}:not(${start} ~ ${end} ~ *)`;
|
|
253
|
-
// rule.selectorText = `${start} ~ ${rule.selectorText}:not(${start} ~ ${end} ~ *)`;
|
|
254
|
-
var selectorText = ":is(".concat(start_1, " ~ *:not(").concat(start_1, " ~ ").concat(end_1, " ~ *))");
|
|
255
|
-
if (rule.selectorText.startsWith('.')) {
|
|
256
|
-
rule.selectorText = "".concat(selectorText).concat(rule.selectorText, ", ").concat(selectorText, " ").concat(rule.selectorText);
|
|
257
|
-
// rule.selectorText = `${start} ~ *:not(${start} ~ ${end} ~ *)${rule.selectorText}`;
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
var divText = "".concat(start_1, " ~ ").concat(rule.selectorText, ":not(").concat(start_1, " ~ ").concat(end_1, " ~ *)");
|
|
261
|
-
rule.selectorText = "".concat(selectorText, " ").concat(rule.selectorText, ", ").concat(divText);
|
|
262
|
-
// rule.selectorText = `${selectorText} ${rule.selectorText}`;
|
|
263
|
-
// rule.selectorText = `${rule.selectorText} ~ ${start} ~ *:not(${start} ~ ${end} ~ *)`;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
// console.log(rule.selectorText);
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
it.ownerNode.setAttribute('completed', 'true');
|
|
270
|
-
});
|
|
271
258
|
(_g = (_f = (_e = (_d = it_2.targetElement) === null || _d === void 0 ? void 0 : _d.__render) === null || _e === void 0 ? void 0 : _e.component) === null || _f === void 0 ? void 0 : _f.onInitRender) === null || _g === void 0 ? void 0 : _g.call(_f, Object.freeze({ render: (_h = it_2.targetElement) === null || _h === void 0 ? void 0 : _h.__render, creatorMetaData: (_j = it_2.targetElement) === null || _j === void 0 ? void 0 : _j.__creatorMetaData }));
|
|
272
259
|
(_k = config === null || config === void 0 ? void 0 : config.onElementInit) === null || _k === void 0 ? void 0 : _k.call(config, it_2.name, obj, this, it_2.targetElement);
|
|
273
260
|
}
|
|
@@ -294,6 +281,39 @@ var RawSet = /** @class */ (function () {
|
|
|
294
281
|
}
|
|
295
282
|
return raws;
|
|
296
283
|
};
|
|
284
|
+
RawSet.prototype.generateCSS = function (id, cssRule) {
|
|
285
|
+
var _this = this;
|
|
286
|
+
var start = "#".concat(id, "-start");
|
|
287
|
+
var end = "#".concat(id, "-end");
|
|
288
|
+
if (cssRule.constructor.name === 'CSSStyleRule') {
|
|
289
|
+
var rule = cssRule;
|
|
290
|
+
// rule.selectorText = `${start} ~ *:not(${start} ~ ${end} ~ *) ${rule.selectorText}`;
|
|
291
|
+
// rule.selectorText = `${start} ~ *:not(${start} ~ ${end} ~ ${rule.selectorText})`;
|
|
292
|
+
// console.log('-----', rule, rule.selectorText)
|
|
293
|
+
if (!rule.selectorText.startsWith(':root')) {
|
|
294
|
+
// rule.selectorText = `${start} ~ ${rule.selectorText}:not(${start} ~ ${end} ~ *)`;
|
|
295
|
+
// rule.selectorText = `${start} ~ ${rule.selectorText}:not(${start} ~ ${end} ~ *)`;
|
|
296
|
+
var selectorText = ":is(".concat(start, " ~ *:not(").concat(start, " ~ ").concat(end, " ~ *))");
|
|
297
|
+
if (rule.selectorText.startsWith('.')) {
|
|
298
|
+
rule.selectorText = "".concat(selectorText).concat(rule.selectorText, ", ").concat(selectorText, " ").concat(rule.selectorText);
|
|
299
|
+
// rule.selectorText = `${start} ~ *:not(${start} ~ ${end} ~ *)${rule.selectorText}`;
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
var divText = "".concat(start, " ~ ").concat(rule.selectorText, ":not(").concat(start, " ~ ").concat(end, " ~ *)");
|
|
303
|
+
rule.selectorText = "".concat(selectorText, " ").concat(rule.selectorText, ", ").concat(divText);
|
|
304
|
+
// rule.selectorText = `${selectorText} ${rule.selectorText}`;
|
|
305
|
+
// rule.selectorText = `${rule.selectorText} ~ ${start} ~ *:not(${start} ~ ${end} ~ *)`;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
// console.log(rule.selectorText);
|
|
309
|
+
}
|
|
310
|
+
else if (cssRule.constructor.name === 'CSSMediaRule') {
|
|
311
|
+
var rule = cssRule;
|
|
312
|
+
Array.from(rule.cssRules).forEach(function (it) {
|
|
313
|
+
_this.generateCSS(id, it);
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
};
|
|
297
317
|
RawSet.prototype.applyEvent = function (obj, fragment, config) {
|
|
298
318
|
if (fragment === void 0) { fragment = this.fragment; }
|
|
299
319
|
EventManager_1.eventManager.applyEvent(obj, EventManager_1.eventManager.findAttrElements(fragment, config), config);
|
|
@@ -334,17 +354,19 @@ var RawSet = /** @class */ (function () {
|
|
|
334
354
|
RawSet.prototype.replaceBody = function (genNode) {
|
|
335
355
|
var _a;
|
|
336
356
|
this.childAllRemove();
|
|
337
|
-
(_a = this.point.start.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(genNode, this.point.start.nextSibling);
|
|
357
|
+
(_a = this.point.start.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(genNode, this.point.start.nextSibling); // 중요 start checkpoint 다음인 end checkpoint 앞에 넣는다. 즉 중간 껴넣기 (나중에 meta tag로 변경을 해도될듯하긴한데..)
|
|
338
358
|
};
|
|
339
359
|
// 중요 important
|
|
340
360
|
RawSet.checkPointCreates = function (element, obj, config) {
|
|
341
361
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
362
|
+
// console.log('start==========')
|
|
342
363
|
var thisVariableName = element.__domrender_this_variable_name;
|
|
343
364
|
// console.log('checkPointCreates thisVariableName', thisVariableName);
|
|
344
365
|
var nodeIterator = config.window.document.createNodeIterator(element, NodeFilter.SHOW_ALL, {
|
|
345
366
|
acceptNode: function (node) {
|
|
346
367
|
var _a, _b, _c, _d, _e;
|
|
347
368
|
if (node.nodeType === Node.TEXT_NODE) {
|
|
369
|
+
// console.log('text--->', node.textContent)
|
|
348
370
|
// console.log('????????', node.parentElement, node.parentElement?.getAttribute('dr-pre'));
|
|
349
371
|
// console.log('???????/',node.textContent, node.parentElement?.getAttribute('dr-pre'))
|
|
350
372
|
// TODO: 나중에
|
|
@@ -389,49 +411,68 @@ var RawSet = /** @class */ (function () {
|
|
|
389
411
|
// const a = StringUtils.regexExec(/[$#]\{.*?\}/g, text);
|
|
390
412
|
// const a = StringUtils.betweenRegexpStr('[$#]\\{', '\\}', text); // <--TODO: 나중에..
|
|
391
413
|
var groups = RawSet.exporesionGrouops(text);
|
|
392
|
-
var map = groups.map(function (it) { return ({ uuid: RandomUtils_1.RandomUtils.
|
|
414
|
+
var map = groups.map(function (it) { return ({ uuid: RandomUtils_1.RandomUtils.getRandomString(40), content: it[0], regexArr: it }); });
|
|
393
415
|
var lasterIndex = 0;
|
|
394
416
|
for (var i = 0; i < map.length; i++) {
|
|
395
417
|
var it_4 = map[i];
|
|
396
418
|
var regexArr = it_4.regexArr;
|
|
397
419
|
var preparedText = regexArr.input.substring(lasterIndex, regexArr.index);
|
|
398
|
-
|
|
399
|
-
|
|
420
|
+
// const start = config.window.document.createElement('meta');
|
|
421
|
+
// start.setAttribute('id', `${it.uuid}-start`);
|
|
422
|
+
// const end = config.window.document.createElement('meta');
|
|
423
|
+
// end.setAttribute('id', `${it.uuid}-end`);
|
|
424
|
+
var start = void 0;
|
|
425
|
+
var end = void 0;
|
|
426
|
+
var type = void 0;
|
|
427
|
+
if (currentNode.parentNode && currentNode.parentNode.nodeName.toUpperCase() === 'STYLE') {
|
|
428
|
+
type = RawSetType.STYLE_TEXT;
|
|
429
|
+
start = config.window.document.createTextNode("/*start text ".concat(it_4.uuid, "*/"));
|
|
430
|
+
end = config.window.document.createTextNode("/*end text ".concat(it_4.uuid, "*/"));
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
type = RawSetType.TEXT;
|
|
434
|
+
start = config.window.document.createComment("start text ".concat(it_4.uuid));
|
|
435
|
+
end = config.window.document.createComment("end text ".concat(it_4.uuid));
|
|
436
|
+
}
|
|
400
437
|
// layout setting
|
|
401
|
-
template.content.append(document.createTextNode(preparedText)); //
|
|
402
|
-
template.content.append(start);
|
|
403
|
-
template.content.append(end);
|
|
404
|
-
// content
|
|
438
|
+
template.content.append(document.createTextNode(preparedText)); // 앞 부분 넣고
|
|
439
|
+
template.content.append(start); // add start checkpoint
|
|
440
|
+
template.content.append(end); // add end checkpoint
|
|
441
|
+
// content 안쪽 RawSet render 할때 start 와 end 사이에 fragment 연산해서 들어간다.
|
|
405
442
|
var fragment = config.window.document.createDocumentFragment();
|
|
406
443
|
fragment.append(config.window.document.createTextNode(it_4.content));
|
|
407
|
-
pars.push(new RawSet(it_4.uuid,
|
|
444
|
+
pars.push(new RawSet(it_4.uuid, type, {
|
|
408
445
|
start: start,
|
|
409
446
|
node: currentNode,
|
|
410
447
|
end: end,
|
|
448
|
+
parent: currentNode.parentNode,
|
|
411
449
|
thisVariableName: thisVariableName
|
|
412
450
|
}, fragment));
|
|
413
451
|
lasterIndex = regexArr.index + it_4.content.length;
|
|
414
452
|
}
|
|
415
453
|
template.content.append(config.window.document.createTextNode(text.substring(lasterIndex, text.length)));
|
|
416
|
-
(_b = currentNode === null || currentNode === void 0 ? void 0 : currentNode.parentNode) === null || _b === void 0 ? void 0 : _b.replaceChild(template.content, currentNode);
|
|
454
|
+
(_b = currentNode === null || currentNode === void 0 ? void 0 : currentNode.parentNode) === null || _b === void 0 ? void 0 : _b.replaceChild(template.content, currentNode); // <-- 여기서 text를 fragment로 replace했기때문에 추적 변경이 가능하다.
|
|
417
455
|
}
|
|
418
456
|
else if (currentNode.nodeType === Node.ELEMENT_NODE) {
|
|
419
|
-
var uuid = RandomUtils_1.RandomUtils.
|
|
457
|
+
var uuid = RandomUtils_1.RandomUtils.getRandomString(40);
|
|
420
458
|
var element_3 = currentNode;
|
|
421
459
|
var fragment = config.window.document.createDocumentFragment();
|
|
422
|
-
var start = config.window.document.
|
|
423
|
-
var end = config.window.document.
|
|
424
|
-
|
|
460
|
+
var start = config.window.document.createElement('meta');
|
|
461
|
+
var end = config.window.document.createElement('meta');
|
|
462
|
+
start.setAttribute('id', "".concat(uuid, "-start"));
|
|
463
|
+
end.setAttribute('id', "".concat(uuid, "-end"));
|
|
464
|
+
var type = RawSetType.TARGET_ELEMENT;
|
|
425
465
|
var isElement = ((_d = (_c = config.targetElements) === null || _c === void 0 ? void 0 : _c.map(function (it) { return it.name.toLowerCase(); })) !== null && _d !== void 0 ? _d : []).includes(element_3.tagName.toLowerCase());
|
|
426
466
|
var targetAttrNames_2 = ((_f = (_e = config.targetAttrs) === null || _e === void 0 ? void 0 : _e.map(function (it) { return it.name; })) !== null && _f !== void 0 ? _f : []).concat(RawSet.DR_ATTRIBUTES);
|
|
427
467
|
var isAttr = element_3.getAttributeNames().filter(function (it) { return targetAttrNames_2.includes(it.toLowerCase()); }).length > 0;
|
|
428
468
|
(_g = currentNode === null || currentNode === void 0 ? void 0 : currentNode.parentNode) === null || _g === void 0 ? void 0 : _g.insertBefore(start, currentNode);
|
|
429
469
|
(_h = currentNode === null || currentNode === void 0 ? void 0 : currentNode.parentNode) === null || _h === void 0 ? void 0 : _h.insertBefore(end, currentNode.nextSibling);
|
|
430
470
|
fragment.append(currentNode);
|
|
431
|
-
pars.push(new RawSet(uuid, isElement ?
|
|
471
|
+
pars.push(new RawSet(uuid, isElement ? type : (isAttr ? RawSetType.TARGET_ATTR : RawSetType.UNKOWN), {
|
|
432
472
|
start: start,
|
|
433
473
|
node: currentNode,
|
|
434
474
|
end: end,
|
|
475
|
+
parent: currentNode.parentNode,
|
|
435
476
|
thisVariableName: thisVariableName
|
|
436
477
|
}, fragment));
|
|
437
478
|
}
|
|
@@ -558,16 +599,18 @@ var RawSet = /** @class */ (function () {
|
|
|
558
599
|
});
|
|
559
600
|
});
|
|
560
601
|
};
|
|
561
|
-
RawSet.drThisCreate = function (element, drThis, drVarOption, drStripOption, obj, config, set) {
|
|
602
|
+
RawSet.drThisCreate = function (rawSet, element, drThis, drVarOption, drStripOption, obj, config, set) {
|
|
562
603
|
var _a, _b, _c, _d;
|
|
563
604
|
var fag = config.window.document.createDocumentFragment();
|
|
564
605
|
var n = element.cloneNode(true);
|
|
606
|
+
// console.log('--------',n, n.innerHTML)
|
|
565
607
|
if (set) {
|
|
566
|
-
|
|
567
|
-
var style = RawSet.styleTransformLocal((_a = set.styles) !== null && _a !== void 0 ? _a : [],
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
608
|
+
// const id = RandomUtils.getRandomString(20);
|
|
609
|
+
var style = RawSet.styleTransformLocal((_a = set.styles) !== null && _a !== void 0 ? _a : [], rawSet.uuid, true);
|
|
610
|
+
n.innerHTML = style + ((_b = set.template) !== null && _b !== void 0 ? _b : '');
|
|
611
|
+
// const metaStart = RawSet.metaStart(id);
|
|
612
|
+
// const metaEnd = RawSet.metaEnd(id);
|
|
613
|
+
// n.innerHTML = metaStart + style + (set.template ?? '') + metaEnd;
|
|
571
614
|
// dr-on-create onCreateRender
|
|
572
615
|
var onCreate = element.getAttribute("".concat(EventManager_1.EventManager.attrPrefix, "on-create"));
|
|
573
616
|
var renderScript = '';
|
|
@@ -595,6 +638,7 @@ var RawSet = /** @class */ (function () {
|
|
|
595
638
|
this.drVarDecoding(n, vars);
|
|
596
639
|
this.drThisDecoding(n, thisRandom);
|
|
597
640
|
if (drStripOption && (drStripOption === true || drStripOption === 'true')) {
|
|
641
|
+
// console.log('------childNodes', Array.from(n.childNodes))
|
|
598
642
|
Array.from(n.childNodes).forEach(function (it) { return fag.append(it); });
|
|
599
643
|
}
|
|
600
644
|
else {
|
|
@@ -625,21 +669,22 @@ var RawSet = /** @class */ (function () {
|
|
|
625
669
|
};
|
|
626
670
|
return targetAttribute;
|
|
627
671
|
};
|
|
628
|
-
RawSet.createComponentTargetElement = function (name, objFactory, template, styles
|
|
672
|
+
RawSet.createComponentTargetElement = function (name, objFactory, template, styles) {
|
|
629
673
|
if (template === void 0) { template = ''; }
|
|
630
674
|
if (styles === void 0) { styles = []; }
|
|
631
675
|
var targetElement = {
|
|
632
676
|
name: name,
|
|
633
677
|
styles: styles,
|
|
634
678
|
template: template,
|
|
635
|
-
callBack: function (element, obj, rawSet, attrs) {
|
|
679
|
+
callBack: function (element, obj, rawSet, attrs, config) {
|
|
636
680
|
var _a, _b, _c, _d, _e, _f;
|
|
637
681
|
// console.log('callback------->', element)
|
|
638
682
|
if (!obj.__domrender_components) {
|
|
639
683
|
obj.__domrender_components = {};
|
|
640
684
|
}
|
|
641
685
|
var domrenderComponents = obj.__domrender_components;
|
|
642
|
-
|
|
686
|
+
// const componentKey = '_' + RandomUtils.getRandomString(20);
|
|
687
|
+
var componentKey = rawSet.uuid;
|
|
643
688
|
var attribute = DomUtils_1.DomUtils.getAttributeToObject(element);
|
|
644
689
|
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; var $creatorMetaData = this.__render.creatorMetaData;';
|
|
645
690
|
var render = Object.freeze({
|
|
@@ -722,12 +767,13 @@ var RawSet = /** @class */ (function () {
|
|
|
722
767
|
__render: render
|
|
723
768
|
}));
|
|
724
769
|
}
|
|
725
|
-
var style = RawSet.styleTransformLocal(styles, componentKey, true
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
770
|
+
var style = RawSet.styleTransformLocal(styles, componentKey, true);
|
|
771
|
+
element.innerHTML = style + (applayTemplate !== null && applayTemplate !== void 0 ? applayTemplate : '');
|
|
772
|
+
// const metaStart = RawSet.metaStart(componentKey);
|
|
773
|
+
// const metaEnd = RawSet.metaEnd(componentKey);
|
|
774
|
+
// element.innerHTML = metaStart + style + (applayTemplate ?? '') + metaEnd;
|
|
729
775
|
// console.log('------>', element.innerHTML, obj)
|
|
730
|
-
var data = RawSet.drThisCreate(element, "this.__domrender_components.".concat(componentKey), '', true, obj, config);
|
|
776
|
+
var data = RawSet.drThisCreate(rawSet, element, "this.__domrender_components.".concat(componentKey), '', true, obj, config);
|
|
731
777
|
// 넘어온 innerHTML에 this가 있는걸 다시 복호화해서 제대로 작동하도록한다.
|
|
732
778
|
if (innerHTMLThisRandom) {
|
|
733
779
|
var template_1 = config.window.document.createElement('template');
|
|
@@ -752,9 +798,8 @@ var RawSet = /** @class */ (function () {
|
|
|
752
798
|
return StringUtils_1.StringUtils.regexExec(reg, data !== null && data !== void 0 ? data : '');
|
|
753
799
|
};
|
|
754
800
|
// 중요 스타일 적용 부분
|
|
755
|
-
RawSet.styleTransformLocal = function (styleBody, id, styleTagWrap
|
|
801
|
+
RawSet.styleTransformLocal = function (styleBody, id, styleTagWrap) {
|
|
756
802
|
if (styleTagWrap === void 0) { styleTagWrap = true; }
|
|
757
|
-
if (locale === void 0) { locale = false; }
|
|
758
803
|
// <style id="first">
|
|
759
804
|
// #first ~ *:not(#first ~ style[domstyle] ~ *) {
|
|
760
805
|
// font-size: 30px;
|
|
@@ -764,25 +809,26 @@ var RawSet = /** @class */ (function () {
|
|
|
764
809
|
if (Array.isArray(styleBody)) {
|
|
765
810
|
styleBody = styleBody.join('\n');
|
|
766
811
|
}
|
|
767
|
-
if (locale) {
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
}
|
|
812
|
+
// if (locale) {
|
|
813
|
+
// styleBody = styleBody.replace(/([^}]+){/gm, function (a, b) {
|
|
814
|
+
// if (typeof b === 'string') {
|
|
815
|
+
// b = b.trim();
|
|
816
|
+
// }
|
|
817
|
+
// return `#${id} ~ ${b}:not(#${id} ~ style[domstyle] ~ *), #${id} ~ * ${b} {`;
|
|
818
|
+
// });
|
|
819
|
+
// }
|
|
775
820
|
if (styleTagWrap) {
|
|
776
821
|
styleBody = "<style id='".concat(id, "-style' domstyle>").concat(styleBody, "</style>");
|
|
777
822
|
}
|
|
778
823
|
return styleBody;
|
|
779
824
|
};
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
}
|
|
825
|
+
// public static metaStart(id: string) {
|
|
826
|
+
// return `<meta id='${id}-start' />`;
|
|
827
|
+
// }
|
|
828
|
+
//
|
|
829
|
+
// public static metaEnd(id: string) {
|
|
830
|
+
// return `<meta id='${id}-end' />`;
|
|
831
|
+
// }
|
|
786
832
|
RawSet.destroy = function (obj, parameter, config, destroyOptions) {
|
|
787
833
|
var _a;
|
|
788
834
|
if (destroyOptions === void 0) { destroyOptions = []; }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ConstructorType } from '../types/Types';
|
|
2
|
+
import { RawSet } from '../RawSet';
|
|
3
|
+
import { Router } from '../routers/Router';
|
|
4
|
+
import { Messenger } from '../messenger/Messenger';
|
|
5
|
+
import { TargetElement } from './TargetElement';
|
|
6
|
+
import { TargetAttr } from './TargetAttr';
|
|
7
|
+
export declare type Config = {
|
|
8
|
+
window: Window;
|
|
9
|
+
targetElements?: TargetElement[];
|
|
10
|
+
targetAttrs?: TargetAttr[];
|
|
11
|
+
onElementInit?: (name: string, obj: any, rawSet: RawSet, targetElement: TargetElement) => any;
|
|
12
|
+
onAttrInit?: (name: string, attrValue: string, obj: any, rawSet: RawSet) => any;
|
|
13
|
+
proxyExcludeTyps?: ConstructorType<any>[];
|
|
14
|
+
proxyExcludeOnBeforeReturnSets?: string[];
|
|
15
|
+
proxyExcludeOnBeforeReturnGets?: string[];
|
|
16
|
+
scripts?: {
|
|
17
|
+
[n: string]: any;
|
|
18
|
+
};
|
|
19
|
+
routerType?: 'hash' | 'path' | 'none';
|
|
20
|
+
router?: Router;
|
|
21
|
+
messenger?: Messenger;
|
|
22
|
+
applyEvents?: {
|
|
23
|
+
attrName: string;
|
|
24
|
+
callBack: (elements: Element, attrValue: string, obj: any) => void;
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RawSet } from '../RawSet';
|
|
2
|
+
export declare type TargetAttr = {
|
|
3
|
+
name: string;
|
|
4
|
+
callBack: (target: Element, attrValue: string, obj: any, rawSet: RawSet) => DocumentFragment;
|
|
5
|
+
complete?: (target: Element, attrValue: string, obj: any, rawSet: RawSet) => void;
|
|
6
|
+
};
|