@cocreate/pwa 1.18.2 → 1.19.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 +14 -0
- package/package.json +1 -1
- package/src/index.js +1 -0
- package/src/service-worker.js +16 -5
- package/src/web-share.js +81 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.19.1](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.19.0...v1.19.1) (2024-04-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* uncommented checkCache ([7372303](https://github.com/CoCreate-app/CoCreate-pwa/commit/737230325c59346687b699b3dfc0496be038f5a6))
|
|
7
|
+
|
|
8
|
+
# [1.19.0](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.18.2...v1.19.0) (2024-03-18)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* web share api using share, share-title, share-text, share-url ([b760a1f](https://github.com/CoCreate-app/CoCreate-pwa/commit/b760a1f5ae4b9376b4adac3b9456b706d83f9fbc))
|
|
14
|
+
|
|
1
15
|
## [1.18.2](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.18.1...v1.18.2) (2024-02-05)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
package/src/service-worker.js
CHANGED
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
const cacheName = "dynamic-v2";
|
|
26
|
+
const updatedOn = new Date('2024-04-28T03:15:28.668Z');
|
|
27
|
+
|
|
26
28
|
let organization_id = ""
|
|
27
29
|
let storage = true
|
|
28
30
|
|
|
@@ -46,14 +48,23 @@ self.addEventListener("fetch", async (e) => {
|
|
|
46
48
|
caches
|
|
47
49
|
.match(e.request)
|
|
48
50
|
.then(async (cacheResponse) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
let fetchedOn
|
|
52
|
+
if (cacheResponse && cacheType !== 'false') {
|
|
53
|
+
fetchedOn = cacheResponse.headers.get('fetched-on')
|
|
54
|
+
if (fetchedOn)
|
|
55
|
+
fetchedOn = new Date(fetchedOn)
|
|
56
|
+
}
|
|
52
57
|
|
|
53
|
-
|
|
58
|
+
const organization = cacheResponse.headers.get('organization')
|
|
59
|
+
|
|
60
|
+
if (!navigator.onLine || !!cacheResponse && cacheType !== 'false' && (!fetchedOn && !organization || fetchedOn > updatedOn)) {
|
|
61
|
+
console.log('servering cache fetchOn greater', fetchedOn > updatedOn, organization)
|
|
62
|
+
const lastModified = cacheResponse.headers.get('last-modified')
|
|
54
63
|
sendCacheUpdate(e.request.url, organization, lastModified);
|
|
55
64
|
return cacheResponse;
|
|
56
65
|
} else {
|
|
66
|
+
console.log('fetching fetchOn less', fetchedOn > updatedOn)
|
|
67
|
+
|
|
57
68
|
const networkResponse = await fetch(e.request);
|
|
58
69
|
|
|
59
70
|
if (!organization_id)
|
|
@@ -178,7 +189,7 @@ const sendCacheUpdate = (url, organization, lastModified) => {
|
|
|
178
189
|
});
|
|
179
190
|
|
|
180
191
|
fetchTimeout = null;
|
|
181
|
-
returnedFromCache = {};
|
|
192
|
+
// returnedFromCache = {};
|
|
182
193
|
}, 500);
|
|
183
194
|
};
|
|
184
195
|
|
package/src/web-share.js
CHANGED
|
@@ -1 +1,82 @@
|
|
|
1
1
|
// https://web.dev/web-share-target/
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (C) 2023 CoCreate and Contributors.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
********************************************************************************/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Commercial Licensing Information:
|
|
21
|
+
* For commercial use of this software without the copyleft provisions of the AGPLv3,
|
|
22
|
+
* you must obtain a commercial license from CoCreate LLC.
|
|
23
|
+
* For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import Observer from '@cocreate/observer'
|
|
27
|
+
import Actions from '@cocreate/actions'
|
|
28
|
+
|
|
29
|
+
const selector = "[share]";
|
|
30
|
+
|
|
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
|
+
});
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
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;
|
|
50
|
+
|
|
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
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
Observer.init({
|
|
64
|
+
name: 'webshare',
|
|
65
|
+
observe: ['addedNodes'],
|
|
66
|
+
target: '[share]',
|
|
67
|
+
callback: (mutation) => {
|
|
68
|
+
init(mutation.target)
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
Actions.init({
|
|
73
|
+
name: "share",
|
|
74
|
+
callback: (action) => {
|
|
75
|
+
share(action.element);
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
init()
|
|
80
|
+
|
|
81
|
+
export default { init }
|
|
82
|
+
|