@cocreate/pwa 1.22.0 → 1.22.1

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,11 @@
1
+ ## [1.22.1](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.22.0...v1.22.1) (2025-04-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * dispatch end event on action element rather than document ([c14b2f3](https://github.com/CoCreate-app/CoCreate-pwa/commit/c14b2f3e92e50f3487aefd66a479e4222c835ab6))
7
+ * update observer observe param to type and and attributeName to attributeFilter ([5545765](https://github.com/CoCreate-app/CoCreate-pwa/commit/554576546507eda1c7577ae593e5c660572ba774))
8
+
1
9
  # [1.22.0](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.21.0...v1.22.0) (2025-01-18)
2
10
 
3
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/pwa",
3
- "version": "1.22.0",
3
+ "version": "1.22.1",
4
4
  "description": "A simple pwa component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "pwa",
@@ -65,7 +65,7 @@ function handleError(error, action) {
65
65
  }
66
66
 
67
67
  function dispatchEvent(action) {
68
- document.dispatchEvent(
68
+ action.element.dispatchEvent(
69
69
  new CustomEvent(action.endEvent, {
70
70
  detail: {
71
71
  data: action
package/src/index.js CHANGED
@@ -145,7 +145,7 @@ async function persistData() {
145
145
 
146
146
  observer.init({
147
147
  name: "initPwa",
148
- observe: ["addedNodes"],
148
+ types: ["addedNodes"],
149
149
  selector: '[actions="install"]',
150
150
  callback: (mutation) => {
151
151
  init();
package/src/web-share.js CHANGED
@@ -23,60 +23,68 @@
23
23
  * For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app.
24
24
  */
25
25
 
26
- import Observer from '@cocreate/observer'
27
- import Actions from '@cocreate/actions'
26
+ import Observer from "@cocreate/observer";
27
+ import Actions from "@cocreate/actions";
28
28
 
29
29
  const selector = "[share]";
30
30
 
31
31
  async function init(element) {
32
- if (element && !(element instanceof HTMLCollection) && !Array.isArray(element))
33
- element = [element]
34
- else if (!element) {
35
- element = document.querySelectorAll(selector)
36
- }
37
-
38
- for (let i = 0; i < element.length; i++)
39
- element[i].addEventListener('click', function (e) {
40
- share(e.target);
41
- });
32
+ if (
33
+ element &&
34
+ !(element instanceof HTMLCollection) &&
35
+ !Array.isArray(element)
36
+ )
37
+ element = [element];
38
+ else if (!element) {
39
+ element = document.querySelectorAll(selector);
40
+ }
42
41
 
42
+ for (let i = 0; i < element.length; i++)
43
+ element[i].addEventListener("click", function (e) {
44
+ share(e.target);
45
+ });
43
46
  }
44
47
 
45
48
  function share(element) {
46
- if (navigator.share && element) {
47
- let title = element.getAttribute('share-title') || document.title;
48
- let text = element.getAttribute('share-text') || document.querySelector('meta[name="description"]')?.content || '';
49
- let url = element.getAttribute('share-url') || window.location.href;
49
+ if (navigator.share && element) {
50
+ let title = element.getAttribute("share-title") || document.title;
51
+ let text =
52
+ element.getAttribute("share-text") ||
53
+ document.querySelector('meta[name="description"]')?.content ||
54
+ "";
55
+ let url = element.getAttribute("share-url") || window.location.href;
50
56
 
51
- navigator.share({
52
- title: title,
53
- text: text,
54
- url: url
55
- })
56
- .then(() => console.log('Successful share'))
57
- .catch((error) => console.log('Error sharing', error));
58
- } else {
59
- console.log('Web Share API is not supported or element is not provided.');
60
- }
57
+ navigator
58
+ .share({
59
+ title: title,
60
+ text: text,
61
+ url: url
62
+ })
63
+ .then(() => console.log("Successful share"))
64
+ .catch((error) => console.log("Error sharing", error));
65
+ } else {
66
+ console.log(
67
+ "Web Share API is not supported or element is not provided."
68
+ );
69
+ }
61
70
  }
62
71
 
63
72
  Observer.init({
64
- name: 'webshare',
65
- observe: ['addedNodes'],
66
- selector: '[share]',
67
- callback: (mutation) => {
68
- init(mutation.target)
69
- }
73
+ name: "webshare",
74
+ types: ["addedNodes"],
75
+ selector: "[share]",
76
+ callback: (mutation) => {
77
+ init(mutation.target);
78
+ }
70
79
  });
71
80
 
72
81
  Actions.init({
73
- name: "share",
74
- callback: (action) => {
75
- share(action.element);
76
- }
77
- })
78
-
79
- init()
82
+ name: "share",
83
+ callback: (action) => {
84
+ share(action.element);
85
+ }
86
+ });
80
87
 
81
- export default { init }
88
+ init();
82
89
 
90
+ export default { init };