@cocreate/events 1.22.0 → 1.23.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ # [1.23.0](https://github.com/CoCreate-app/CoCreate-events/compare/v1.22.1...v1.23.0) (2024-09-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * observer-target attribute ([92593d3](https://github.com/CoCreate-app/CoCreate-events/commit/92593d32c4b53fe97dab511e44dd1c9f345d708e))
7
+
8
+
9
+ ### Features
10
+
11
+ * *-insert-adjacent attribute to apply value using insertAdjacentHTML() ([3d2151d](https://github.com/CoCreate-app/CoCreate-events/commit/3d2151d91d56ad53df006343e4f18b3aa1a99b1d))
12
+
13
+ ## [1.22.1](https://github.com/CoCreate-app/CoCreate-events/compare/v1.22.0...v1.22.1) (2024-08-24)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * parse flag ([53ce700](https://github.com/CoCreate-app/CoCreate-events/commit/53ce700cca7d90919b933d102cda5f73fe3261c5))
19
+
1
20
  # [1.22.0](https://github.com/CoCreate-app/CoCreate-events/compare/v1.21.0...v1.22.0) (2024-06-19)
2
21
 
3
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/events",
3
- "version": "1.22.0",
3
+ "version": "1.23.0",
4
4
  "description": "A simple events component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "events",
package/src/index.js CHANGED
@@ -146,7 +146,10 @@ const CoCreateEvents = {
146
146
  if (events.includes('observer')) {
147
147
  let target;
148
148
  for (let attribute of el.attributes) {
149
- if ([`${prefix}-selector`, `${prefix}-closest`, `${prefix}-parent`, `${prefix}-next`, `${prefix}-previous`].includes(attribute.name)) {
149
+ if (attribute.name === 'observe-target') {
150
+ target = attribute.value
151
+ break;
152
+ } else if ([`${prefix}-selector`, `${prefix}-closest`, `${prefix}-parent`, `${prefix}-next`, `${prefix}-previous`].includes(attribute.name)) {
150
153
  target = attribute.value
151
154
  break;
152
155
  }
@@ -225,6 +228,7 @@ const CoCreateEvents = {
225
228
  const self = this;
226
229
  // TODO: support empty value when prefix-attribute defined, add and remove the attribute
227
230
  let targetAttribute = element.getAttribute(`${prefix}-attribute`);
231
+ let targetPosition = element.getAttribute(`${prefix}-insert-adjacent`);
228
232
  // targetAttribute = checkMediaQueries(targetAttribute)
229
233
  // if (targetAttribute === false)
230
234
  // return
@@ -318,6 +322,7 @@ const CoCreateEvents = {
318
322
 
319
323
  groupValues = groupValues.map(x => x.trim());
320
324
  let groupAttribute = el.getAttribute(`${prefix}-attribute`) || 'class';
325
+ let groupPosition = el.getAttribute(`${prefix}-insert-adjacent`);
321
326
  // groupAttribute = checkMediaQueries(groupAttribute)
322
327
  // if (!groupAttribute)
323
328
  // return
@@ -325,10 +330,10 @@ const CoCreateEvents = {
325
330
  let groupKey = el.getAttribute(`${prefix}-key`)
326
331
 
327
332
  // el.removeAttribute(prefix)
328
- self.setValue(prefix, el, groupAttribute, groupValues, groupKey, 'deactivate', events)
333
+ self.setValue(prefix, el, groupAttribute, groupValues, groupKey, 'deactivate', events, groupPosition)
329
334
  let targetElements = queryElements({ el, prefix });
330
335
  for (let i = 0; i < targetElements.length; i++)
331
- self.setValue(prefix, targetElements[i], groupAttribute, groupValues, groupKey, 'deactivate', events)
336
+ self.setValue(prefix, targetElements[i], groupAttribute, groupValues, groupKey, 'deactivate', events, groupPosition)
332
337
 
333
338
  });
334
339
  }
@@ -352,8 +357,9 @@ const CoCreateEvents = {
352
357
  for (let i = 0; i < targetElements.length; i++) {
353
358
  if (!targetAttribute && targetAttribute !== '' && ['click', 'focus', 'blur'].includes(prefix)) {
354
359
  targetElements[i][prefix]()
355
- } else
356
- this.setValue(prefix, targetElements[i], targetAttribute, values, targetKey, null, events)
360
+ } else {
361
+ this.setValue(prefix, targetElements[i], targetAttribute, values, targetKey, null, events, targetPosition)
362
+ }
357
363
  }
358
364
 
359
365
  document.dispatchEvent(new CustomEvent(`${prefix}End`, {
@@ -362,11 +368,11 @@ const CoCreateEvents = {
362
368
 
363
369
  },
364
370
 
365
- setValue: async function (prefix, element, attrName, values, key, deactivate, events) {
371
+ setValue: async function (prefix, element, attrName, values, key, deactivate, events, targetPosition) {
366
372
  if (events && events.includes('mouseout')) {
367
373
  if (element.matches(':hover')) {
368
374
  element.addEventListener('mouseout', () => {
369
- this.setValue(prefix, element, attrName, values, key, deactivate, events);
375
+ this.setValue(prefix, element, attrName, values, key, deactivate, events, targetPosition);
370
376
  }, { once: true });
371
377
  return;
372
378
  }
@@ -434,15 +440,15 @@ const CoCreateEvents = {
434
440
  element[attrName.substring(1)]()
435
441
  } else if (attrName) {
436
442
  element.setAttribute(attrName, newValue);
443
+ } else if (targetPosition) {
444
+ element.insertAdjacentHTML(targetPosition, newValue);
437
445
  } else {
438
446
  if (!attrName && ['click', 'focus', 'blur'].includes(newValue)) {
439
447
  element[newValue]()
440
448
  } else if (['click', 'focus', 'blur'].includes(attrName)) {
441
449
  element[attrName]()
442
450
  }
443
-
444
451
  }
445
-
446
452
  }
447
453
  }
448
454
  },
@@ -578,15 +584,21 @@ function checkCondition(condition, value) {
578
584
  if (operatorMatch)
579
585
  condition = operatorMatch[2].trim()
580
586
 
587
+ let parse = true
581
588
  if (condition === 'true') {
582
589
  return !!value[0];
583
590
  } else if (condition === 'false') {
584
591
  return !value[0];
592
+ } else if (condition === '[]' && typeof value[0] === 'string') {
593
+ parse = false
585
594
  }
586
595
 
596
+
597
+
587
598
  // TODO: why parse updated conditin to boolean false
588
- if (condition !== 'false')
599
+ if (parse && condition !== 'false')
589
600
  condition = parseCondition(condition);
601
+
590
602
  let result;
591
603
 
592
604
  if (condition === '$template') {