@twobirds/microcomponents 0.1.9 → 0.1.10

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/dist/MC.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"MC.d.ts","sourceRoot":"","sources":["../src/MC.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAM3C,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,GAAG,EAAE,WAAW,CAAC;CACjB;AAmED,iBAAS,GAAG,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,QAE1F;AAED,iBAAS,EAAE,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,EAAE,IAAI,GAAE,OAAe,GAAI,kCAAkC,CAGtJ;AAED,iBAAS,GAAG,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,GAAI,kCAAkC,CAGhI;AAED,cAAM,gBAAgB;IACrB,OAAO,UAAS;;IAGhB,IAAI;CAGJ;AAGD,iBAAS,OAAO,CACf,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,GAAQ,EACd,MAAM,GAAE,MAAY,EACpB,UAAU,CAAC,EAAE,gBAAgB,QA8C7B;AAiDD,cAAM,MAAM;IACX,OAAO,CAAC,OAAO,CAAe;gBAElB,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE;IAU3C,IAAI,MAAM,IAAI,GAAG,CAEhB;CAED;AAED,cAAM,EAAG,SAAQ,MAAM;gBACV,MAAM,CAAC,EAAE,GAAG;CAGxB;AAED,cAAM,EAAG,SAAQ,MAAM;gBACV,MAAM,EAAE,WAAW;IAI/B,MAAM,CAAC,GAAG,CAAE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,IAAI;IAexB,OAAO,IAAI,EAAE,GAAG,IAAI;IAMpB,QAAQ,IAAI,EAAE,EAAE,GAAG,IAAI;IAMvB,WAAW,IAAI,EAAE,EAAE,GAAG,IAAI;CAQ7B;AA8HD,iBAAS,QAAQ,CAAC,MAAM,GAAE,OAAc,GAAG,OAAO,CAkBjD;AAID,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC"}
package/dist/MC.js CHANGED
@@ -54,14 +54,16 @@ function one(domNode, eventName, handler) {
54
54
  }
55
55
  class BubbleController {
56
56
  stopped = false;
57
- constructor() {
58
- }
57
+ constructor() { }
59
58
  stop() {
60
59
  this.stopped = true;
61
60
  }
62
61
  }
63
62
  function trigger(domNode, event, data = {}, bubble = 'l', controller) {
64
- const eventName = /^_mc/.test(event) ? event : getMcEventName(event), bubbleController = !!controller ? controller : new BubbleController(), ev = new CustomEvent(eventName, { detail: { data, control: bubbleController }, bubbles: false });
63
+ const eventName = /^_mc/.test(event) ? event : getMcEventName(event), bubbleController = controller ? controller : new BubbleController(), ev = new CustomEvent(eventName, {
64
+ detail: { data, control: bubbleController },
65
+ bubbles: false,
66
+ });
65
67
  if (bubbleController.stopped)
66
68
  return;
67
69
  if (/l/.test(bubble)) {
@@ -77,13 +79,13 @@ function trigger(domNode, event, data = {}, bubble = 'l', controller) {
77
79
  setTimeout(() => {
78
80
  if (bubble.indexOf('u') > -1) {
79
81
  let parentMc = domNode.parentElement?.closest('[data-mc]');
80
- if (!!parentMc) {
82
+ if (parentMc) {
81
83
  parentMc?._mc.trigger(eventName, data, bubble, bubbleController);
82
84
  }
83
85
  }
84
86
  if (bubble.indexOf('d') > -1) {
85
87
  let childNodes = domNode._mc.children();
86
- if (!!childNodes) {
88
+ if (childNodes) {
87
89
  childNodes.forEach((_mc) => _mc.trigger(eventName, data, bubble));
88
90
  }
89
91
  }
@@ -101,7 +103,7 @@ function autoAttachListeners(element) {
101
103
  typeof that.constructor.prototype[key] === 'function')
102
104
  .forEach((key) => {
103
105
  let once = /^one/.test(key), withoutOnOne = key.replace(/^on[e]{0,1}/, ''), nativeEventName = withoutOnOne.toLowerCase();
104
- if (('on' + nativeEventName) in target) {
106
+ if ('on' + nativeEventName in target) {
105
107
  let listener = (ev) => {
106
108
  that[key](ev);
107
109
  };
@@ -122,7 +124,7 @@ function getMcChildNodes(domNode) {
122
124
  domNode.setAttribute('temp_id', id);
123
125
  const mcArray = [...domNode.querySelectorAll(selector)]
124
126
  .filter((e) => !!e._mc)
125
- .map(e => e._mc);
127
+ .map((e) => e._mc);
126
128
  domNode.removeAttribute('temp_id');
127
129
  return mcArray.length ? mcArray : null;
128
130
  }
@@ -150,7 +152,6 @@ class DC extends McBase {
150
152
  static add(target, key, element = {}) {
151
153
  return add(target, key, element);
152
154
  }
153
- ;
154
155
  static remove(target, key) {
155
156
  remove(target, key);
156
157
  }
@@ -170,7 +171,7 @@ class DC extends McBase {
170
171
  let currentNode = this?.target, result = [];
171
172
  if (!isDOM(currentNode))
172
173
  return [];
173
- while (currentNode = (currentNode.closest('[data-mc]'))) {
174
+ while ((currentNode = currentNode.closest('[data-mc]'))) {
174
175
  if (currentNode?._mc) {
175
176
  result.push(currentNode?._mc);
176
177
  }
@@ -195,16 +196,14 @@ class DC extends McBase {
195
196
  return [];
196
197
  const mcArray = [...target.querySelectorAll('[data-mc]')]
197
198
  .filter((e) => !!e._mc)
198
- .map(e => e._mc);
199
+ .map((e) => e._mc);
199
200
  return mcArray.length ? mcArray : null;
200
201
  }
201
202
  }
202
203
  const loadingDCs = new Set();
203
204
  function attachDC(element) {
204
205
  return () => {
205
- const elements = Array
206
- .from(document.querySelectorAll(`[data-mc*="${element}"]`))
207
- .filter(element => element instanceof HTMLElement);
206
+ const elements = Array.from(document.querySelectorAll(`[data-mc*="${element}"]`)).filter((element) => element instanceof HTMLElement);
208
207
  if (elements.length === 0)
209
208
  return;
210
209
  const Klass = customElements.get(element);
@@ -213,14 +212,14 @@ function attachDC(element) {
213
212
  DC.add(node, Klass.name, new Klass(node));
214
213
  }
215
214
  catch (error) {
216
- if (!!Klass['create']) {
215
+ if (Klass['create']) {
217
216
  let element = Klass.create(node);
218
217
  element.setAttribute('data-mc', node.getAttribute('data-mc'));
219
218
  node.replaceWith(element);
220
219
  node = element;
221
220
  }
222
221
  else {
223
- throw (`Class ${Klass.name} doesn't have a callable constructor AND class doesn't have a static .create() method.`);
222
+ throw `Class ${Klass.name} doesn't have a callable constructor AND class doesn't have a static .create() method.`;
224
223
  }
225
224
  }
226
225
  const new_mc = node
@@ -233,7 +232,6 @@ function attachDC(element) {
233
232
  });
234
233
  };
235
234
  }
236
- ;
237
235
  function makeLoadScript(element) {
238
236
  if (loadingDCs.has(element))
239
237
  return;
@@ -259,17 +257,20 @@ function makeLoadScript(element) {
259
257
  }
260
258
  function loadUndefinedMCs() {
261
259
  [...document.querySelectorAll(':not(:defined)')]
262
- .filter((element) => !!element
263
- && !customElements.get(element.tagName.toLowerCase())
264
- && !loadingDCs.has(element.tagName.toLowerCase()))
260
+ .filter((element) => !!element &&
261
+ !customElements.get(element.tagName.toLowerCase()) &&
262
+ !loadingDCs.has(element.tagName.toLowerCase()))
265
263
  .forEach((el) => {
266
264
  makeLoadScript(el.tagName.toLowerCase());
267
265
  });
268
266
  [...document.querySelectorAll('[data-mc]:not([data-mc=""]')]
269
267
  .filter((element) => !!element)
270
268
  .forEach((el) => {
271
- const _mc = el.getAttribute('data-mc')?.split(' ').filter(name => name !== '');
272
- _mc?.forEach(element => {
269
+ const _mc = el
270
+ .getAttribute('data-mc')
271
+ ?.split(' ')
272
+ .filter((name) => name !== '');
273
+ _mc?.forEach((element) => {
273
274
  const isDefined = customElements.get(element);
274
275
  if (!loadingDCs.has(element) && !isDefined) {
275
276
  makeLoadScript(element);
package/dist/MC.min.js CHANGED
@@ -87,14 +87,16 @@ function one(domNode, eventName, handler) {
87
87
  }
88
88
  class BubbleController {
89
89
  stopped = false;
90
- constructor() {
91
- }
90
+ constructor() { }
92
91
  stop() {
93
92
  this.stopped = true;
94
93
  }
95
94
  }
96
95
  function trigger(domNode, event, data = {}, bubble = 'l', controller) {
97
- const eventName = /^_mc/.test(event) ? event : getMcEventName(event), bubbleController = !!controller ? controller : new BubbleController(), ev = new CustomEvent(eventName, { detail: { data, control: bubbleController }, bubbles: false });
96
+ const eventName = /^_mc/.test(event) ? event : getMcEventName(event), bubbleController = controller ? controller : new BubbleController(), ev = new CustomEvent(eventName, {
97
+ detail: { data, control: bubbleController },
98
+ bubbles: false,
99
+ });
98
100
  if (bubbleController.stopped)
99
101
  return;
100
102
  if (/l/.test(bubble)) {
@@ -110,13 +112,13 @@ function trigger(domNode, event, data = {}, bubble = 'l', controller) {
110
112
  setTimeout(() => {
111
113
  if (bubble.indexOf('u') > -1) {
112
114
  let parentMc = domNode.parentElement?.closest('[data-mc]');
113
- if (!!parentMc) {
115
+ if (parentMc) {
114
116
  parentMc?._mc.trigger(eventName, data, bubble, bubbleController);
115
117
  }
116
118
  }
117
119
  if (bubble.indexOf('d') > -1) {
118
120
  let childNodes = domNode._mc.children();
119
- if (!!childNodes) {
121
+ if (childNodes) {
120
122
  childNodes.forEach((_mc) => _mc.trigger(eventName, data, bubble));
121
123
  }
122
124
  }
@@ -134,7 +136,7 @@ function autoAttachListeners(element) {
134
136
  typeof that.constructor.prototype[key] === 'function')
135
137
  .forEach((key) => {
136
138
  let once = /^one/.test(key), withoutOnOne = key.replace(/^on[e]{0,1}/, ''), nativeEventName = withoutOnOne.toLowerCase();
137
- if (('on' + nativeEventName) in target) {
139
+ if ('on' + nativeEventName in target) {
138
140
  let listener = (ev) => {
139
141
  that[key](ev);
140
142
  };
@@ -155,7 +157,7 @@ function getMcChildNodes(domNode) {
155
157
  domNode.setAttribute('temp_id', id);
156
158
  const mcArray = [...domNode.querySelectorAll(selector)]
157
159
  .filter((e) => !!e._mc)
158
- .map(e => e._mc);
160
+ .map((e) => e._mc);
159
161
  domNode.removeAttribute('temp_id');
160
162
  return mcArray.length ? mcArray : null;
161
163
  }
@@ -183,7 +185,6 @@ class DC extends McBase {
183
185
  static add(target, key, element = {}) {
184
186
  return add(target, key, element);
185
187
  }
186
- ;
187
188
  static remove(target, key) {
188
189
  remove(target, key);
189
190
  }
@@ -203,7 +204,7 @@ class DC extends McBase {
203
204
  let currentNode = this?.target, result = [];
204
205
  if (!isDOM(currentNode))
205
206
  return [];
206
- while (currentNode = (currentNode.closest('[data-mc]'))) {
207
+ while ((currentNode = currentNode.closest('[data-mc]'))) {
207
208
  if (currentNode?._mc) {
208
209
  result.push(currentNode?._mc);
209
210
  }
@@ -228,16 +229,14 @@ class DC extends McBase {
228
229
  return [];
229
230
  const mcArray = [...target.querySelectorAll('[data-mc]')]
230
231
  .filter((e) => !!e._mc)
231
- .map(e => e._mc);
232
+ .map((e) => e._mc);
232
233
  return mcArray.length ? mcArray : null;
233
234
  }
234
235
  }
235
236
  const loadingDCs = new Set();
236
237
  function attachDC(element) {
237
238
  return () => {
238
- const elements = Array
239
- .from(document.querySelectorAll(`[data-mc*="${element}"]`))
240
- .filter(element => element instanceof HTMLElement);
239
+ const elements = Array.from(document.querySelectorAll(`[data-mc*="${element}"]`)).filter((element) => element instanceof HTMLElement);
241
240
  if (elements.length === 0)
242
241
  return;
243
242
  const Klass = customElements.get(element);
@@ -246,14 +245,14 @@ function attachDC(element) {
246
245
  DC.add(node, Klass.name, new Klass(node));
247
246
  }
248
247
  catch (error) {
249
- if (!!Klass['create']) {
248
+ if (Klass['create']) {
250
249
  let element = Klass.create(node);
251
250
  element.setAttribute('data-mc', node.getAttribute('data-mc'));
252
251
  node.replaceWith(element);
253
252
  node = element;
254
253
  }
255
254
  else {
256
- throw (`Class ${Klass.name} doesn't have a callable constructor AND class doesn't have a static .create() method.`);
255
+ throw `Class ${Klass.name} doesn't have a callable constructor AND class doesn't have a static .create() method.`;
257
256
  }
258
257
  }
259
258
  const new_mc = node
@@ -266,7 +265,6 @@ function attachDC(element) {
266
265
  });
267
266
  };
268
267
  }
269
- ;
270
268
  function makeLoadScript(element) {
271
269
  if (loadingDCs.has(element))
272
270
  return;
@@ -292,17 +290,20 @@ function makeLoadScript(element) {
292
290
  }
293
291
  function loadUndefinedMCs() {
294
292
  [...document.querySelectorAll(':not(:defined)')]
295
- .filter((element) => !!element
296
- && !customElements.get(element.tagName.toLowerCase())
297
- && !loadingDCs.has(element.tagName.toLowerCase()))
293
+ .filter((element) => !!element &&
294
+ !customElements.get(element.tagName.toLowerCase()) &&
295
+ !loadingDCs.has(element.tagName.toLowerCase()))
298
296
  .forEach((el) => {
299
297
  makeLoadScript(el.tagName.toLowerCase());
300
298
  });
301
299
  [...document.querySelectorAll('[data-mc]:not([data-mc=""]')]
302
300
  .filter((element) => !!element)
303
301
  .forEach((el) => {
304
- const _mc = el.getAttribute('data-mc')?.split(' ').filter(name => name !== '');
305
- _mc?.forEach(element => {
302
+ const _mc = el
303
+ .getAttribute('data-mc')
304
+ ?.split(' ')
305
+ .filter((name) => name !== '');
306
+ _mc?.forEach((element) => {
306
307
  const isDefined = customElements.get(element);
307
308
  if (!loadingDCs.has(element) && !isDefined) {
308
309
  makeLoadScript(element);