@cocreate/pwa 1.1.1 → 1.2.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 +15 -0
- package/demo/images/screenshot-1.png +0 -0
- package/demo/index.html +21 -6
- package/demo/manifest.json +30 -6
- package/docs/index.html +1 -1
- package/package.json +2 -2
- package/src/badging.js +10 -0
- package/src/contact-picker.js +11 -0
- package/src/file-share.js +15 -0
- package/src/index.js +68 -49
- package/src/wakeLock.js +9 -0
- package/src/web-share.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## [1.2.1](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.2.0...v1.2.1) (2022-09-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* bump [@cocreate](https://github.com/cocreate) dependencies ([0d2963e](https://github.com/CoCreate-app/CoCreate-pwa/commit/0d2963efe72c1d72709af962adc8155026418b6a))
|
|
7
|
+
* config renameed to CoCreateConfig ([3a250fd](https://github.com/CoCreate-app/CoCreate-pwa/commit/3a250fdec212b81a565a5e56e09a4c3a10aba70b))
|
|
8
|
+
|
|
9
|
+
# [1.2.0](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.1.1...v1.2.0) (2022-09-28)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* updates serviceWorker if online and if serviceWorker has changed. ([cc74fb6](https://github.com/CoCreate-app/CoCreate-pwa/commit/cc74fb619ace71128c1df5d4e60e5baaf04f46df))
|
|
15
|
+
|
|
1
16
|
## [1.1.1](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.1.0...v1.1.1) (2022-09-16)
|
|
2
17
|
|
|
3
18
|
|
|
Binary file
|
package/demo/index.html
CHANGED
|
@@ -2,16 +2,31 @@
|
|
|
2
2
|
<html lang="en">
|
|
3
3
|
|
|
4
4
|
<head>
|
|
5
|
-
<title>
|
|
5
|
+
<title>Im the page title</title>
|
|
6
6
|
<meta charset="utf-8" />
|
|
7
7
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
8
|
-
<meta name="viewport" content="width=device-width
|
|
8
|
+
<meta name="viewport" content="width=device-width; initial-scale=1; viewport-fit=cover" />
|
|
9
9
|
<!-- import the webpage's stylesheet -->
|
|
10
10
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
|
|
11
11
|
<link rel="stylesheet" href="./css/style.css" />
|
|
12
12
|
<!-- Manifest -->
|
|
13
|
-
|
|
13
|
+
<link rel="manifest" href="./manifest.json" />
|
|
14
14
|
<!--<meta name="theme-color" content="red">-->
|
|
15
|
+
|
|
16
|
+
<!--<non-transparent PNG icon sized at 180 by 180 >-->
|
|
17
|
+
<link rel="apple-touch-icon" href="/images/icons/ios.png">
|
|
18
|
+
|
|
19
|
+
<meta name="mobile-web-app-capable" content="yes">
|
|
20
|
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
21
|
+
<!--<hides status bar for a full screen experience omn ios only>-->
|
|
22
|
+
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
|
23
|
+
|
|
24
|
+
<link rel="apple-touch-startup-image" href="ios-startup.png">
|
|
25
|
+
|
|
26
|
+
<link rel="apple-touch-startup-image" href="ios-startup.png" media="orientation: portrait">
|
|
27
|
+
<link rel="apple-touch-startup-image" href="ios-startup-landscape.png" media="orientation: landscape">
|
|
28
|
+
|
|
29
|
+
|
|
15
30
|
</head>
|
|
16
31
|
|
|
17
32
|
<body>
|
|
@@ -45,9 +60,9 @@
|
|
|
45
60
|
<button id="cacheBtn">Uncache</button>
|
|
46
61
|
|
|
47
62
|
<!-- Install button, hidden by default -->
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
|
|
64
|
+
<button actions="install" type="button" hidden>Install</button>
|
|
65
|
+
|
|
51
66
|
|
|
52
67
|
|
|
53
68
|
<!-- <script src="../src/index.js" defer></script> -->
|
package/demo/manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"short_name": "CoCreate",
|
|
3
|
-
"name": "CoCreate
|
|
4
|
-
"description": "
|
|
3
|
+
"name": "CoCreate",
|
|
4
|
+
"description": "Build your business in miutes",
|
|
5
5
|
"orientation": "portrait-primary",
|
|
6
6
|
|
|
7
7
|
"icons": [{
|
|
@@ -42,11 +42,35 @@
|
|
|
42
42
|
{
|
|
43
43
|
"src": "./images/icons/icon-512x512.png",
|
|
44
44
|
"type": "image/png",
|
|
45
|
-
"sizes": "512x512"
|
|
45
|
+
"sizes": "512x512",
|
|
46
|
+
"purpose": "maskable"
|
|
46
47
|
}
|
|
47
48
|
],
|
|
48
|
-
"start_url": "
|
|
49
|
+
"start_url": "/",
|
|
49
50
|
"background_color": "whitesmoke",
|
|
50
|
-
"display": "
|
|
51
|
-
"theme_color": "blue"
|
|
51
|
+
"display": "Fullscreen",
|
|
52
|
+
"theme_color": "blue",
|
|
53
|
+
"screenshots": [{
|
|
54
|
+
"src": "./images/screenshot-1.png",
|
|
55
|
+
"type": "image/png",
|
|
56
|
+
"sizes": "512x512"
|
|
57
|
+
}],
|
|
58
|
+
"categories": "productivity",
|
|
59
|
+
"file_handlers": [
|
|
60
|
+
{
|
|
61
|
+
"action": "/open-file",
|
|
62
|
+
"accept": {
|
|
63
|
+
"text/*": [".txt"]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
"share_target": {
|
|
68
|
+
"action": "/receive-share/",
|
|
69
|
+
"method": "GET",
|
|
70
|
+
"params": {
|
|
71
|
+
"title": "shared_title",
|
|
72
|
+
"url": "shared_url"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
52
76
|
}
|
package/docs/index.html
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/pwa",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.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",
|
|
@@ -60,6 +60,6 @@
|
|
|
60
60
|
"webpack-log": "^3.0.1"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@cocreate/docs": "
|
|
63
|
+
"@cocreate/docs": "1.3.9"
|
|
64
64
|
}
|
|
65
65
|
}
|
package/src/badging.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
async function getContacts() {
|
|
3
|
+
const properties = ['name', 'email', 'tel'];
|
|
4
|
+
const options = { multiple: true };
|
|
5
|
+
try {
|
|
6
|
+
const contacts = await navigator.contacts.select(properties, options);
|
|
7
|
+
console.log(contacts);
|
|
8
|
+
} catch (ex) {
|
|
9
|
+
// Handle any errors here.
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// https://web.dev/learn/pwa/os-integration/
|
|
2
|
+
// Have the user select a file.
|
|
3
|
+
const [ handle ] = await window.showOpenFilePicker();
|
|
4
|
+
// Get the File object from the handle.
|
|
5
|
+
const file = await handle.getFile();
|
|
6
|
+
// Get the file content.
|
|
7
|
+
// Also available, slice(), stream(), arrayBuffer()
|
|
8
|
+
const content = await file.text();
|
|
9
|
+
|
|
10
|
+
// Make a writable stream from the handle.
|
|
11
|
+
const writable = await handle.createWritable();
|
|
12
|
+
// Write the contents of the file to the stream.
|
|
13
|
+
await writable.write(contents);
|
|
14
|
+
// Close the file and write the contents to disk.
|
|
15
|
+
await writable.close();
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import cache from './cache.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const installContainer = document.getElementById('installContainer');
|
|
5
|
-
const installBtn = document.getElementById('installBtn');
|
|
3
|
+
const button = document.querySelector('[actions*="install"]');
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Warn the page must be served over HTTPS
|
|
@@ -10,39 +8,42 @@ const installBtn = document.getElementById('installBtn');
|
|
|
10
8
|
* Installability requires a service worker with a fetch event handler, and
|
|
11
9
|
* if the page isn't served over HTTPS, the service worker won't load.
|
|
12
10
|
*/
|
|
13
|
-
if (window.location.protocol === 'http:') {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
11
|
+
// if (window.location.protocol === 'http:') {
|
|
12
|
+
// const requireHTTPS = document.getElementById('requireHTTPS');
|
|
13
|
+
// const link = requireHTTPS.querySelector('a');
|
|
14
|
+
// link.href = window.location.href.replace('http://', 'https://');
|
|
15
|
+
// requireHTTPS.classList.remove('hidden');
|
|
16
|
+
// }
|
|
19
17
|
|
|
20
18
|
window.addEventListener('beforeinstallprompt', (event) => {
|
|
21
19
|
console.log('👍', 'beforeinstallprompt', event);
|
|
22
20
|
// Stash the event so it can be triggered later.
|
|
23
21
|
window.deferredPrompt = event;
|
|
24
22
|
// Remove the 'hidden' class from the install button container
|
|
25
|
-
|
|
23
|
+
if (button)
|
|
24
|
+
button.removeAttribute('hidden');
|
|
26
25
|
});
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
27
|
+
if (button) {
|
|
28
|
+
button.addEventListener('click', async() => {
|
|
29
|
+
console.log('👍', 'installBtn-clicked');
|
|
30
|
+
const promptEvent = window.deferredPrompt;
|
|
31
|
+
if (!promptEvent) {
|
|
32
|
+
// The deferred prompt isn't available.
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// Show the install prompt.
|
|
36
|
+
promptEvent.prompt();
|
|
37
|
+
// Log the result
|
|
38
|
+
const result = await promptEvent.userChoice;
|
|
39
|
+
console.log('👍', 'userChoice', result);
|
|
40
|
+
// Reset the deferred prompt variable, since
|
|
41
|
+
// prompt() can only be called once.
|
|
42
|
+
window.deferredPrompt = null;
|
|
43
|
+
// Hide the install button.
|
|
44
|
+
button.addAttribute('hidden', '');
|
|
45
|
+
});
|
|
46
|
+
}
|
|
46
47
|
|
|
47
48
|
window.addEventListener('appinstalled', (event) => {
|
|
48
49
|
console.log('👍', 'appinstalled', event);
|
|
@@ -50,31 +51,49 @@ window.addEventListener('appinstalled', (event) => {
|
|
|
50
51
|
window.deferredPrompt = null;
|
|
51
52
|
});
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
async function persistData() {
|
|
55
|
+
if (navigator.storage && navigator.storage.persist) {
|
|
56
|
+
const result = await navigator.storage.persist();
|
|
57
|
+
console.log(`Data persisted: ${result}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if ('serviceWorker' in navigator) {
|
|
62
|
+
let workerPath = '/sw.js'
|
|
63
|
+
if (window.CoCreateConfig && window.CoCreateConfig.serviceWorker) {
|
|
64
|
+
workerPath = window.CoCreateConfig.serviceWorker
|
|
65
|
+
window.localStorage.setItem("serviceWorker", workerPath);
|
|
66
|
+
} else {
|
|
67
|
+
workerPath = window.localStorage.getItem("serviceWorker")
|
|
68
|
+
}
|
|
56
69
|
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
navigator.serviceWorker.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
let isPwa = true
|
|
71
|
+
if (workerPath) {
|
|
72
|
+
navigator.serviceWorker.getRegistrations().then(registrations => {
|
|
73
|
+
console.log(registrations);
|
|
74
|
+
if (registrations.length === 0 || isPwa == true)
|
|
75
|
+
window.addEventListener("load", function(event) {
|
|
76
|
+
navigator.serviceWorker.getRegistration(workerPath).then(registration => {
|
|
77
|
+
if(registration && registration.active) {
|
|
78
|
+
console.log('Service Worker Active')
|
|
79
|
+
} else {
|
|
80
|
+
navigator.serviceWorker.register(workerPath)
|
|
81
|
+
.then(reg => {
|
|
82
|
+
reg.onupdatefound = () => {
|
|
83
|
+
const installingWorker = reg.installing;
|
|
84
|
+
installingWorker.onstatechange = () => {
|
|
85
|
+
console.log('Service Worker', installingWorker.state);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
.catch(err => console.log('SW ERROR', err));
|
|
69
90
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
.catch(err => console.log('SW ERROR', err));
|
|
73
|
-
|
|
74
|
-
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
75
93
|
});
|
|
94
|
+
|
|
76
95
|
}
|
|
77
|
-
}
|
|
96
|
+
}
|
|
78
97
|
|
|
79
98
|
|
|
80
99
|
export default {cache}
|
package/src/wakeLock.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Request a screen wake lock
|
|
2
|
+
const wakeLock = await navigator.wakeLock.request();
|
|
3
|
+
|
|
4
|
+
// Listen for wake lock release
|
|
5
|
+
wakeLock.addEventListener('release', () => {
|
|
6
|
+
console.log(`Screen Wake Lock released: ${wakeLock.released}`);
|
|
7
|
+
});
|
|
8
|
+
// Manually release the wake lock
|
|
9
|
+
wakeLock.release();
|
package/src/web-share.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// https://web.dev/web-share-target/
|