dom-render 1.0.78 → 1.0.81

Sign up to get free protection for your applications and to get access to all the features.
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,38 +643,53 @@ 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
625
684
  ```html
626
685
  <my-element dr-on-component-init="$component.say();"></my-element>
686
+
687
+ <home value="${this.name}$" wow="${this.color}$">
688
+ ${#component#.homeName}$
689
+ <home value="${#component#.homeName}$" wow="${#component#.homeColor}$" dr-component-name="sub_component" dr-component-inner-html-name="innerHTML">
690
+ ${#sub_component#.homeName}$
691
+ </home>
692
+ </home>
627
693
  ```
628
694
  - attribute
629
695
  - dr-on-component-init: component created init call script
@@ -631,6 +697,10 @@ using component
631
697
  - $element: element instance
632
698
  - $attribute: element attribute object
633
699
  - $innerHTML: element innerHTML string
700
+ - #component#: component instance
701
+ - #innerHTML#: element innerHTML
702
+ - dr-component-name: renaming component variable name (default: component)
703
+ - dr-inner-html-name: renaming innerHTML variable name (default: innerHTML)
634
704
  ---
635
705
 
636
706
  # License
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;
package/RawSet.js CHANGED
@@ -303,7 +303,7 @@ var RawSet = /** @class */ (function () {
303
303
  (_a = this.point.start.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(genNode, this.point.start.nextSibling);
304
304
  };
305
305
  // 중요 important
306
- RawSet.checkPointCreates = function (element, config) {
306
+ RawSet.checkPointCreates = function (element, obj, config) {
307
307
  var _a, _b, _c, _d, _e, _f, _g, _h;
308
308
  var thisVariableName = element.__domrender_this_variable_name;
309
309
  // console.log('checkPointCreates thisVariableName', thisVariableName);
@@ -596,7 +596,7 @@ var RawSet = /** @class */ (function () {
596
596
  styles: styles,
597
597
  template: template,
598
598
  callBack: function (element, obj, rawSet, attrs) {
599
- var _a, _b, _c, _d;
599
+ var _a, _b, _c, _d, _e, _f;
600
600
  // console.log('callback------->', element)
601
601
  if (!obj.__domrender_components) {
602
602
  obj.__domrender_components = {};
@@ -666,15 +666,17 @@ var RawSet = /** @class */ (function () {
666
666
  (_d = instance === null || instance === void 0 ? void 0 : instance.onCreateRender) === null || _d === void 0 ? void 0 : _d.call.apply(_d, __spreadArray([instance], createParam, false));
667
667
  var applayTemplate = element.innerHTML;
668
668
  var innerHTMLThisRandom;
669
+ var componentName = (_e = element.getAttribute("".concat(EventManager_1.EventManager.attrPrefix, "component-name"))) !== null && _e !== void 0 ? _e : 'component';
670
+ var innerHTMLName = (_f = element.getAttribute("".concat(EventManager_1.EventManager.attrPrefix, "component-inner-html-name"))) !== null && _f !== void 0 ? _f : 'innerHTML';
669
671
  if (applayTemplate) {
670
672
  // if (rawSet.point.thisVariableName) {
671
673
  // 넘어온 innerHTML에 this가 있으면 해당안되게 우선 치환.
672
674
  innerHTMLThisRandom = RandomUtils_1.RandomUtils.uuid();
673
675
  applayTemplate = applayTemplate.replace(/this\./g, innerHTMLThisRandom);
674
676
  // }
675
- applayTemplate = applayTemplate.replace(/#component#/g, 'this');
677
+ applayTemplate = applayTemplate.replace(RegExp("#".concat(componentName, "#"), 'g'), 'this');
676
678
  }
677
- applayTemplate = template.replace(/#innerHTML#/g, applayTemplate);
679
+ applayTemplate = template.replace(RegExp("#".concat(innerHTMLName, "#"), 'g'), applayTemplate);
678
680
  // dr-on-component-init
679
681
  var oninit = element.getAttribute("".concat(EventManager_1.EventManager.attrPrefix, "on-component-init")); // dr-on-component-init
680
682
  if (oninit) {