dom-render 1.0.79 → 1.0.82

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 CHANGED
@@ -3,26 +3,11 @@ import { ConstructorType } from './types/Types';
3
3
  import { RawSet } from './RawSet';
4
4
  export declare class DomRender {
5
5
  static run<T extends object>(obj: T, target?: Node, config?: Config): T;
6
- static addComponent(config: Config, { type, tagName }: {
6
+ static createComponent(param: {
7
7
  type: ConstructorType<any>;
8
8
  tagName?: string;
9
- }, { template, styles, styleLocale }: {
10
- template: string;
11
- styles?: string[];
12
- styleLocale?: boolean;
13
- }): {
14
- add: (source: {
15
- type: ConstructorType<any>;
16
- tagName?: string;
17
- }, front: {
18
- template: string;
19
- styles?: string[];
20
- }) => any;
21
- };
22
- 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): {
23
- add: (attrName: string, getThisObj: (element: Element, attrValue: string, obj: any, rawSet: RawSet) => any, factory: (element: Element, attrValue: string, obj: any, rawSet: RawSet) => DocumentFragment) => any;
24
- };
25
- static addAttributeCallBack(config: Config, attrName: string, callBack: (elements: Element, attrValue: string, obj: any) => void): {
26
- add: (attrName: string, callBack: (elements: Element, attrValue: string, obj: any) => void) => any;
27
- };
9
+ template?: string;
10
+ styles?: string[] | string;
11
+ }, config: Config): import("./Config").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("./Config").TargetAttr;
28
13
  }
package/DomRender.js CHANGED
@@ -46,44 +46,17 @@ var DomRender = /** @class */ (function () {
46
46
  domRender.run(robj);
47
47
  return robj;
48
48
  };
49
- DomRender.addComponent = function (config, _a, _b) {
50
- var _c;
51
- var type = _a.type, _d = _a.tagName, tagName = _d === void 0 ? type.name : _d;
52
- var template = _b.template, _e = _b.styles, styles = _e === void 0 ? [] : _e, _f = _b.styleLocale, styleLocale = _f === void 0 ? false : _f;
53
- var component = RawSet_1.RawSet.createComponentTargetElement(tagName, function (e, o, r2, counstructorParam) {
54
- return new (type.bind.apply(type, __spreadArray([void 0], counstructorParam, false)))();
55
- }, template, styles, styleLocale, config);
56
- config.targetElements = (_c = config.targetElements) !== null && _c !== void 0 ? _c : [];
57
- config.targetElements.push(component);
58
- return {
59
- add: function (source, front) {
60
- return DomRender.addComponent(config, source, front);
61
- }
62
- };
49
+ DomRender.createComponent = function (param, config) {
50
+ var _a, _b;
51
+ var component = RawSet_1.RawSet.createComponentTargetElement((_a = param.tagName) !== null && _a !== void 0 ? _a : param.type.name, function (e, o, r2, counstructorParam) {
52
+ 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), false, config);
55
+ return component;
63
56
  };
64
- DomRender.addAttribute = function (config, attrName, getThisObj, factory) {
65
- var _a;
57
+ DomRender.createAttribute = function (attrName, getThisObj, factory) {
66
58
  var targetAttribute = RawSet_1.RawSet.createComponentTargetAttribute(attrName, getThisObj, factory);
67
- config.targetAttrs = (_a = config.targetAttrs) !== null && _a !== void 0 ? _a : [];
68
- config.targetAttrs.push(targetAttribute);
69
- return {
70
- add: function (attrName, getThisObj, factory) {
71
- return DomRender.addAttribute(config, attrName, getThisObj, factory);
72
- }
73
- };
74
- };
75
- DomRender.addAttributeCallBack = function (config, attrName, callBack) {
76
- var _a;
77
- config.applyEvents = (_a = config.applyEvents) !== null && _a !== void 0 ? _a : [];
78
- config.applyEvents.push({
79
- attrName: attrName,
80
- callBack: callBack
81
- });
82
- return {
83
- add: function (attrName, callBack) {
84
- return DomRender.addAttributeCallBack(config, attrName, callBack);
85
- }
86
- };
59
+ return targetAttribute;
87
60
  };
88
61
  return DomRender;
89
62
  }());
package/DomRenderProxy.js CHANGED
@@ -64,7 +64,7 @@ var DomRenderProxy = /** @class */ (function () {
64
64
  (_d = (_c = this._domRender_proxy) === null || _c === void 0 ? void 0 : _c.onCreateRender) === null || _d === void 0 ? void 0 : _d.call(_c, createParam);
65
65
  var innerHTML = (_e = target.innerHTML) !== null && _e !== void 0 ? _e : '';
66
66
  this._targets.add(target);
67
- var rawSets = RawSet_1.RawSet.checkPointCreates(target, this.config);
67
+ var rawSets = RawSet_1.RawSet.checkPointCreates(target, this._domRender_proxy, this.config);
68
68
  // console.log('initRender -------rawSet', rawSets)
69
69
  // 중요 초기에 한번 튕겨줘야함.
70
70
  EventManager_1.eventManager.applyEvent(this._domRender_proxy, EventManager_1.eventManager.findAttrElements(target, this.config), this.config);
@@ -182,6 +182,7 @@ var DomRenderProxy = /** @class */ (function () {
182
182
  }
183
183
  else {
184
184
  var strings = paths.reverse();
185
+ // array같은경우도 키값으로 접근하기때문에 특정 인덱스를 찾아서 그부분만 바꿔줄수 있다.
185
186
  var fullPathStr_1 = strings.map(function (it) { return isNaN(Number(it)) ? '.' + it : "[".concat(it, "]"); }).join('').slice(1);
186
187
  if (lastDoneExecute) {
187
188
  var iterable = this._rawSets.get(fullPathStr_1);
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.78/dist/bundle.js"></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/dom-render@1.0.81/dist/bundle.js"></script>
11
11
  ```
12
12
  ```html
13
13
  <!DOCTYPE html>
@@ -119,6 +119,45 @@ const data = DomRender.run(new Data(), document.querySelector('#app')!);
119
119
  ```
120
120
  </details>
121
121
 
122
+ <details>
123
+ <summary>dr-appender<strong>🔻(click)</strong></summary>
124
+
125
+ ```html
126
+ <h3>appender</h3>
127
+ <ul>
128
+ <li dr-appender="this.appender">
129
+ ${#it#}$
130
+ </li>
131
+ </ul>
132
+ <button dr-event-click="this.append()">appending</button>
133
+ <button dr-event-click="this.modifyAppender(0)">idx 0 modify</button>
134
+ <button dr-event-click="this.clearAppend()">appender clear</button>
135
+ ```
136
+
137
+ ```typescript
138
+ class Data {
139
+ appender = new Appender();
140
+
141
+ constructor() {
142
+ this.appender.push('init' + RandomUtils.uuid(), 'init' + RandomUtils.uuid());
143
+ }
144
+
145
+ append() {
146
+ this.appender.push(RandomUtils.uuid(), RandomUtils.uuid());
147
+ }
148
+
149
+ clearAppend() {
150
+ this.appender.clear()
151
+ }
152
+
153
+ modifyAppender(idx: number) {
154
+ this.appender[idx][0] = RandomUtils.uuid();
155
+ }
156
+ }
157
+
158
+ ```
159
+ </details>
160
+
122
161
  <details>
123
162
  <summary>dr-repeat<strong>🔻(click)</strong></summary>
124
163
 
@@ -364,11 +403,12 @@ validator
364
403
  const config: Config = {
365
404
  window
366
405
  };
367
- DomRender.addComponent(config, {type: Main, tagName: 'page-main'}, {template: MainTemplate})
368
- .add({type: Second, tagName: 'page-second'}, {template: SecondTemplate})
369
- .add({type: Detail, tagName: 'page-detail'}, {template: DetailTemplate});
370
- config.routerType = 'hash';
371
- config.routerType = 'hash';
406
+ config.targetElements = [
407
+ DomRender.createComponent({type: Main, tagName: 'page-main', template: MainTemplate}, config),
408
+ DomRender.createComponent({type: Second, tagName: 'page-second', template: SecondTemplate}, config),
409
+ DomRender.createComponent({type: Detail, tagName: 'page-detail', template: DetailTemplate}, config)
410
+ ]
411
+ config.routerType = 'hash'; // 'hash' | 'path' | 'none';
372
412
  const data = DomRender.run(new Data(), document.querySelector('#app')!, config);
373
413
  ```
374
414
  ```html
@@ -464,6 +504,17 @@ for (let data of new Range(100,55, 10)) {
464
504
  const rangeArray = new Range(100,55, 10).toArray();
465
505
  ```
466
506
  </details>
507
+ <details>
508
+ <summary>Appender<strong>🔻(click)</strong></summary>
509
+
510
+ ```javascript
511
+ const appender = new Appender<number>([1, 2]);
512
+ appender.push(3, 4)
513
+ for (const data of appender) {
514
+ console.log('----appender item--->', data);
515
+ }
516
+ ```
517
+ </details>
467
518
 
468
519
  ## Detect Get, Set
469
520
  <details>
@@ -592,33 +643,41 @@ link attribute
592
643
  </body>
593
644
  ```
594
645
  ```typescript
595
- DomRender
596
- .addComponent(config, {type: Profile}, {template: ProfileTemplate})
597
- .add({type: Home}, {template: HomeTemplate});
598
-
599
- DomRender.addAttribute(config, 'link',
600
- (element: Element, attrValue: string, obj: any, rawSet: RawSet) => {
601
- return obj;
602
- },
603
- (element: Element, attrValue: string, obj: any, rawSet: RawSet) => {
604
- const fag = window.document.createDocumentFragment();
605
- if (attrValue) {
606
- const n = element.cloneNode(true) as Element;
607
- attrValue = ScriptUtils.eval(`return ${attrValue}`, obj)
608
- n.addEventListener('click', () => {
609
- location.href = attrValue;
610
- });
611
- fag.append(n);
646
+ config.targetElements = [
647
+ DomRender.createComponent({type: Profile, template: ProfileTemplate}, config),
648
+ DomRender.createComponent({type: Home, template: HomeTemplate, styles: HomeStyle}, config)
649
+ ]
650
+
651
+ config.targetAttrs = [
652
+ DomRender.createAttribute('link',
653
+ (element: Element, attrValue: string, obj: any, rawSet: RawSet) => {
654
+ return obj;
655
+ },
656
+ (element: Element, attrValue: string, obj: any, rawSet: RawSet) => {
657
+ const fag = window.document.createDocumentFragment();
658
+ if (attrValue) {
659
+ const n = element.cloneNode(true) as Element;
660
+ attrValue = ScriptUtils.eval(`return ${attrValue}`, obj)
661
+ n.addEventListener('click', () => {
662
+ location.href = attrValue;
663
+ });
664
+ fag.append(n);
665
+ }
666
+ return fag;
612
667
  }
613
- return fag;
614
- }
615
- );
616
-
617
- DomRender.addAttributeCallBack(config, 'wow', (e, a, o) => {
618
- e.addEventListener('click', (event) => {
619
- alert((event.target as any).value);
620
- })
621
- })
668
+ )
669
+ ]
670
+
671
+ config.applyEvents = [
672
+ {
673
+ attrName: 'wow',
674
+ callBack: (e, a, o) => {
675
+ e.addEventListener('click', (event) => {
676
+ alert((event.target as any).value);
677
+ })
678
+ }
679
+ }
680
+ ]
622
681
  const data = DomRender.run(new Data(), document.querySelector('#app')!, config);
623
682
  ```
624
683
  using component
package/RawSet.d.ts CHANGED
@@ -120,7 +120,7 @@ export declare class RawSet {
120
120
  getAttributeAndDelete(element: Element, attr: string): string | null;
121
121
  getDrAppendAttributeAndDelete(element: Element, obj: any): string | null;
122
122
  replaceBody(genNode: Node): void;
123
- static checkPointCreates(element: Node, config: Config): RawSet[];
123
+ static checkPointCreates(element: Node, obj: any, config: Config): RawSet[];
124
124
  childAllRemove(): void;
125
125
  static drItOtherEncoding(element: Element | DocumentFragment): string;
126
126
  static drItOtherDecoding(element: Element | DocumentFragment, random: string): void;
@@ -145,5 +145,7 @@ export declare class RawSet {
145
145
  static isExporesion(data: string | null): boolean;
146
146
  static exporesionGrouops(data: string | null): RegExpExecArray[];
147
147
  static styleTransformLocal(styleBody: string | string[], id: string, styleTagWrap?: boolean, locale?: boolean): string;
148
+ static metaStart(id: string): string;
149
+ static metaEnd(id: string): string;
148
150
  static destroy(obj: any | undefined, parameter: any[], config: Config, destroyOptions?: (DestroyOptionType | string)[]): void;
149
151
  }
package/RawSet.js CHANGED
@@ -118,7 +118,7 @@ var RawSet = /** @class */ (function () {
118
118
  // console.log('usingTriggerVariable----------->', usingTriggerVariables)
119
119
  return usingTriggerVariables;
120
120
  };
121
- // 중요 render
121
+ // 중요 render 처리 부분
122
122
  RawSet.prototype.render = function (obj, config) {
123
123
  var _this = this;
124
124
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
@@ -234,6 +234,33 @@ var RawSet = /** @class */ (function () {
234
234
  }
235
235
  for (var _q = 0, onElementInitCallBacks_1 = onElementInitCallBacks; _q < onElementInitCallBacks_1.length; _q++) {
236
236
  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 = "".concat(start_1, " ~ ").concat(rule.selectorText, ":not(").concat(start_1, " ~ ").concat(end_1, " ~ *)");
253
+ // if (rule.selectorText.startsWith('.')) {
254
+ // rule.selectorText = `${start} ~ *:not(${start} ~ ${end} ~ *)${rule.selectorText}`;
255
+ // } else {
256
+ // rule.selectorText = `${rule.selectorText} ~ ${start} ~ *:not(${start} ~ ${end} ~ *)`;
257
+ // }
258
+ }
259
+ // console.log(rule.selectorText);
260
+ });
261
+ }
262
+ it.ownerNode.setAttribute('completed', 'true');
263
+ });
237
264
  (_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 }));
238
265
  (_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);
239
266
  }
@@ -303,7 +330,7 @@ var RawSet = /** @class */ (function () {
303
330
  (_a = this.point.start.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(genNode, this.point.start.nextSibling);
304
331
  };
305
332
  // 중요 important
306
- RawSet.checkPointCreates = function (element, config) {
333
+ RawSet.checkPointCreates = function (element, obj, config) {
307
334
  var _a, _b, _c, _d, _e, _f, _g, _h;
308
335
  var thisVariableName = element.__domrender_this_variable_name;
309
336
  // console.log('checkPointCreates thisVariableName', thisVariableName);
@@ -530,7 +557,10 @@ var RawSet = /** @class */ (function () {
530
557
  var n = element.cloneNode(true);
531
558
  if (set) {
532
559
  var id = RandomUtils_1.RandomUtils.getRandomString(20);
533
- n.innerHTML = RawSet.styleTransformLocal((_a = set.styles) !== null && _a !== void 0 ? _a : [], id, true, set.styleLocale) + ((_b = set.template) !== null && _b !== void 0 ? _b : '');
560
+ var style = RawSet.styleTransformLocal((_a = set.styles) !== null && _a !== void 0 ? _a : [], id, true, set.styleLocale);
561
+ var metaStart = RawSet.metaStart(id);
562
+ var metaEnd = RawSet.metaEnd(id);
563
+ n.innerHTML = metaStart + style + ((_b = set.template) !== null && _b !== void 0 ? _b : '') + metaEnd;
534
564
  // dr-on-create onCreateRender
535
565
  var onCreate = element.getAttribute("".concat(EventManager_1.EventManager.attrPrefix, "on-create"));
536
566
  var renderScript = '';
@@ -685,8 +715,10 @@ var RawSet = /** @class */ (function () {
685
715
  __render: render
686
716
  }));
687
717
  }
688
- var innerHTML = RawSet.styleTransformLocal(styles, componentKey, true, styleLocale) + (applayTemplate !== null && applayTemplate !== void 0 ? applayTemplate : '');
689
- element.innerHTML = innerHTML;
718
+ var style = RawSet.styleTransformLocal(styles, componentKey, true, styleLocale);
719
+ var metaStart = RawSet.metaStart(componentKey);
720
+ var metaEnd = RawSet.metaEnd(componentKey);
721
+ element.innerHTML = metaStart + style + (applayTemplate !== null && applayTemplate !== void 0 ? applayTemplate : '') + metaEnd;
690
722
  // console.log('------>', element.innerHTML, obj)
691
723
  var data = RawSet.drThisCreate(element, "this.__domrender_components.".concat(componentKey), '', true, obj, config);
692
724
  // 넘어온 innerHTML에 this가 있는걸 다시 복호화해서 제대로 작동하도록한다.
@@ -712,6 +744,7 @@ var RawSet = /** @class */ (function () {
712
744
  var reg = /(?:[$#]\{(?:(([$#]\{)??[^$#]?[^{]*?)\}[$#]))/g;
713
745
  return StringUtils_1.StringUtils.regexExec(reg, data !== null && data !== void 0 ? data : '');
714
746
  };
747
+ // 중요 스타일 적용 부분
715
748
  RawSet.styleTransformLocal = function (styleBody, id, styleTagWrap, locale) {
716
749
  if (styleTagWrap === void 0) { styleTagWrap = true; }
717
750
  if (locale === void 0) { locale = false; }
@@ -733,10 +766,16 @@ var RawSet = /** @class */ (function () {
733
766
  });
734
767
  }
735
768
  if (styleTagWrap) {
736
- styleBody = "<style id='".concat(id, "' domstyle>").concat(styleBody, "</style>");
769
+ styleBody = "<style id='".concat(id, "-style' domstyle>").concat(styleBody, "</style>");
737
770
  }
738
771
  return styleBody;
739
772
  };
773
+ RawSet.metaStart = function (id) {
774
+ return "<meta id='".concat(id, "-start' />");
775
+ };
776
+ RawSet.metaEnd = function (id) {
777
+ return "<meta id='".concat(id, "-end' />");
778
+ };
740
779
  RawSet.destroy = function (obj, parameter, config, destroyOptions) {
741
780
  var _a;
742
781
  if (destroyOptions === void 0) { destroyOptions = []; }