progressive-share-button 1.0.0-alpha.9 → 1.0.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
@@ -5,7 +5,31 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [1.0.0-alpha.9] - 2021-03-01
8
+ ## [1.0.1] - 2023-04-10
9
+
10
+ ### Fixed
11
+
12
+ - There are no code changes to this version, but the documentation now correctly shows the correct import statement for the module. The previous version had the incorrect import statement showing the module having a default export, but it does not. The import statement should be `import { ProgressiveShareButton } from 'progressive-share-button';`.
13
+ - Fixed the dates in this changelog. I had 2021 instead of 2023. I'm not sure how I missed that!
14
+
15
+
16
+ ## [1.0.0] - 2023-03-04
17
+
18
+ - Initial release of 1.0.0.
19
+
20
+ ## [1.0.0-alpha.11] - 2023-03-01
21
+
22
+ ### Fixed
23
+
24
+ - Fixed: Previous solution didn't fix build system issue. Switched the build script to use `tsc` instead of `vite` to build the package.
25
+
26
+ ## [1.0.0-alpha.10] - 2023-03-01
27
+
28
+ ### Fixed
29
+
30
+ - Fixed: The build system didn't include the @types directory in the published package. This has been fixed.
31
+
32
+ ## [1.0.0-alpha.9] - 2023-03-01
9
33
 
10
34
  ### Added
11
35
 
@@ -20,7 +44,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
20
44
 
21
45
  - Fixed: The demo page has some incorrect class names in the example code. These have been corrected.
22
46
 
23
-
24
47
  ## [1.0.0-alpha.8] - 2023-02-27
25
48
 
26
49
  ### Changed
package/README.md CHANGED
@@ -4,6 +4,11 @@ The _Progressive Share Button_ web component is a simple way to add a share butt
4
4
 
5
5
  The web component is a wrapper around the [Web Share API](https://w3c.github.io/web-share/) that attempts to display a share icon appropriate to the user's device with icons that will be recognizable to iOS/Mac, Android and Windows. If the device type can't be determined, the component will display a Windows share icon.
6
6
 
7
+ ## Demo
8
+
9
+ Check out the demo page, [https://johnfmorton.github.io/progressive-share-button/](https://johnfmorton.github.io/progressive-share-button/), to see the component in action.
10
+
11
+
7
12
  ## Basic Usage
8
13
 
9
14
  The most basic usage of the component is to use no attributes. The component will share the current page's URL.
@@ -18,7 +23,9 @@ You may also pass the URL to be shared. The component will share the URL that ha
18
23
  <progressive-share-button url="https://example.com" />
19
24
  ```
20
25
 
21
- This will render one of the following, depending on the device and browser. This example shows the Windows sharing icon, the Android sharing icon, and the iOS sharing icon.
26
+ This will render one of the following, depending on the device and browser.
27
+
28
+ This example image below shows the Windows sharing icon, the Android sharing icon, and the iOS/Mac sharing icon.
22
29
 
23
30
  ![Basic Example](./img/button-examples.png)
24
31
 
@@ -41,10 +48,10 @@ npm install progressive-share-button
41
48
  main.js, if installed with npm
42
49
 
43
50
  ```javascript
44
- // Import the component, which is the default export, so no curly braces are needed.
45
- import ProgressiveShareButton from 'progressive-share-button';
51
+ // Import the component
52
+ import { ProgressiveShareButton } from 'progressive-share-button';
46
53
  // Initialize the component
47
- ProgressiveShareButton.init();
54
+ ProgressiveShareButton();
48
55
  ```
49
56
 
50
57
  ### Customizing the component name
@@ -69,9 +76,7 @@ customElements.define('my-share-button', ProgressiveShareButtonClass);
69
76
 
70
77
  ## Typescript support
71
78
 
72
- WIP: ~~~The component is written in Typescript and includes a type definition file. If you are using Typescript, you can import the component directly into your project.~~~
73
-
74
-
79
+ The component is written in Typescript and includes type definitions. If you are using Typescript, you can import the component directly into your project and see code completion hints. See the [Custom events](#custom-events) section for more information about using the custom event type definitions.
75
80
 
76
81
  ## Customizing the Component
77
82
 
@@ -220,29 +225,50 @@ https://w3c.github.io/web-share/demos/share-files.html
220
225
 
221
226
  There are two custom event emitted by the component: `progressive-share-success` and `progressive-share-fail`.
222
227
 
223
- | Event name | Description |
224
- | --- | --- |
225
- | `progressive-share-success` | Emitted when the Web Share API is supported and the data is successfully shared. |
226
- | `progressive-share-fail` | Emitted when the Web Share API is supported but the data is not successfully shared. This is typically emitted when a user opens the share dialog box but exits out of it without sharing. |
227
-
228
+ | Event name | Description | TypeScript type |
229
+ | --- | --- | --- |
230
+ | `progressive-share-success` | Emitted when the Web Share API is supported and the data is successfully shared. | `ProgressiveShareSuccessEvent` |
231
+ | `progressive-share-fail` | Emitted when the Web Share API is supported but the data is not successfully shared. This is typically emitted when a user opens the share dialog box but exits out of it without sharing. | `ProgressiveShareFailEvent` |
228
232
 
233
+ If you're writing in Typescript, you can import the custom event types and use them like this:
229
234
 
230
- ```javascript
231
- // example of listening for the custom events
235
+ ```typescript
236
+ import { ProgressiveShareSuccessEvent, ProgressiveShareFailEvent } from 'progressive-share-button';
232
237
  document.addEventListener('progressive-share-success', (e) => {
233
- // e.detail contains the share data that was shared
234
- console.log('The progressive-share-success event was heard.', e.detail);
235
- });
238
+ const { detail } = e as ProgressiveShareSuccessEvent
239
+ // e.detail contains the share data
240
+ // check if e.detail exists
241
+ if (detail) {
242
+ console.log('The progressive-share-success event was heard.', detail)
243
+ }
244
+ })
236
245
  document.addEventListener('progressive-share-fail', (e) => {
237
- // e.detail contains the error message
238
- console.log('The progressive-share-fail event was heard.', e.detail);
239
- });
246
+ const { detail } = e as ProgressiveShareFailEvent
247
+ // check if e.detail exists
248
+ if (detail) {
249
+ console.log('The progressive-share-fail event was heard.', detail)
250
+ }
251
+ })
240
252
  ```
241
253
 
242
- ## Demo
243
-
244
- [https://johnfmorton.github.io/progressive-share-button/](https://johnfmorton.github.io/progressive-share-button/)
254
+ Or if you're writing in Javascript, you can skip importing the types and just use the `detail` property of the event object.
245
255
 
256
+ ```javascript
257
+ document.addEventListener('progressive-share-success', (e) => {
258
+ const { detail } = e
259
+ // check if e.detail exists
260
+ if (detail) {
261
+ console.log('The progressive-share-success event was heard.', detail)
262
+ }
263
+ })
264
+ document.addEventListener('progressive-share-fail', (e) => {
265
+ const { detail } = e
266
+ // check if e.detail exists
267
+ if (detail) {
268
+ console.log('The progressive-share-fail event was heard.', detail)
269
+ }
270
+ })
271
+ ```
246
272
  ## License
247
273
 
248
274
  MIT
@@ -0,0 +1,15 @@
1
+ declare module "progressive-share-button" {
2
+ export interface ProgressiveShareSuccessEvent extends Event {
3
+ detail: any;
4
+ }
5
+ export interface ProgressiveShareFailEvent extends Event {
6
+ detail: any;
7
+ }
8
+ class ProgressiveShareButtonClass extends HTMLElement {
9
+ iconSize: () => string;
10
+ constructor();
11
+ share(): void;
12
+ }
13
+ const ProgressiveShareButton: () => boolean;
14
+ export { ProgressiveShareButton, ProgressiveShareButtonClass };
15
+ }
@@ -1,3 +1,10 @@
1
+ /**
2
+ * name: progressive-share-button
3
+ * version: v1.0.1
4
+ * description: A web componet that creates a OS-native share button.
5
+ * author: John F. Morton <john@johnfmorton.com> (https://supergeekery.com)
6
+ * repository: https://github.com/johnfmorton/progressive-share-button
7
+ */
1
8
  var __defProp = Object.defineProperty;
2
9
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
10
  var __publicField = (obj, key, value) => {
@@ -16,7 +23,7 @@ class ProgressiveShareButtonClass extends HTMLElement {
16
23
  } else if (size) {
17
24
  return size;
18
25
  } else {
19
- return 24 + "px";
26
+ return "24px";
20
27
  }
21
28
  };
22
29
  function _isNumeric(value) {
@@ -88,12 +95,15 @@ class ProgressiveShareButtonClass extends HTMLElement {
88
95
  if (!data.url && !data.text && !data.title) {
89
96
  data.url = window.location.href;
90
97
  }
91
- let shareEvent = new CustomEvent("progressive-share-success", {
92
- bubbles: true,
93
- cancelable: false,
94
- composed: true,
95
- detail: data
96
- });
98
+ let shareEvent = new CustomEvent(
99
+ "progressive-share-success",
100
+ {
101
+ bubbles: true,
102
+ cancelable: false,
103
+ composed: true,
104
+ detail: data
105
+ }
106
+ );
97
107
  if (navigator.share) {
98
108
  if (debug == 1) {
99
109
  console.debug("data to be shared", data);
@@ -101,15 +111,12 @@ class ProgressiveShareButtonClass extends HTMLElement {
101
111
  navigator.share(data).then(() => {
102
112
  this.dispatchEvent(shareEvent);
103
113
  }).catch((e) => {
104
- let shareEventFail = new CustomEvent(
105
- "progressive-share-fail",
106
- {
107
- bubbles: true,
108
- cancelable: false,
109
- composed: true,
110
- detail: e
111
- }
112
- );
114
+ let shareEventFail = new CustomEvent("progressive-share-fail", {
115
+ bubbles: true,
116
+ cancelable: false,
117
+ composed: true,
118
+ detail: e
119
+ });
113
120
  this.dispatchEvent(shareEventFail);
114
121
  });
115
122
  }
@@ -118,7 +125,7 @@ class ProgressiveShareButtonClass extends HTMLElement {
118
125
  }
119
126
  }
120
127
  }
121
- function init() {
128
+ const ProgressiveShareButton = () => {
122
129
  if (typeof navigator.share === "function") {
123
130
  console.log(
124
131
  "ProgressiveShareButton support initialized. <progressive-share-success /> element now available"
@@ -133,9 +140,6 @@ function init() {
133
140
  ProgressiveShareButtonClass
134
141
  );
135
142
  return true;
136
- }
137
- const main = {
138
- init
139
143
  };
140
144
  const iosShareIcon = '<svg xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 84.53 108.43" class="icon"><title>Share icon</title><desc>Square with upward arrow</desc><path d="m76.21,33.15h-23.38v5.28h23.38c1.72,0,3.04,1.32,3.04,2.91v58.77c0,1.58-1.32,2.91-3.04,2.91H8.32c-1.72,0-3.04-1.32-3.04-2.9v-58.64c0-1.58,1.32-2.91,3.04-2.91h20.74v-5.28H8.32c-4.62,0-8.32,3.7-8.32,8.19v58.77c0,4.49,3.7,8.19,8.32,8.19h67.88c4.62,0,8.32-3.7,8.32-8.19v-58.77c0-4.62-3.7-8.32-8.32-8.32h0Z"/><path d="m39.62,8.58v69.21h5.28V8.58l13.6,10.04,3.17-4.23L42.26,0l-19.41,14.4,3.17,4.23,13.6-10.04Z"/></svg>';
141
145
  const androidShareIcon = '<svg id="b" xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 18.19 21.46" class="icon"><title>Share icon</title><desc>Circle with smaller circles radiating out</desc><g id="c"><path d="m15.1,15.29c-.89,0-1.7.38-2.28.98l-6.98-3.84c.24-.43.38-.94.38-1.49s-.14-1.03-.38-1.49l7.22-4.03c.55.48,1.25.77,2.04.77,1.7,0,3.1-1.39,3.1-3.1s-1.39-3.1-3.1-3.1-3.1,1.39-3.1,3.1c0,.67.22,1.27.58,1.78l-7.18,4.01c-.58-.62-1.39-1.03-2.3-1.03-1.7,0-3.1,1.39-3.1,3.1s1.39,3.1,3.1,3.1c.91,0,1.73-.41,2.3-1.03l6.98,3.84c-.26.46-.41.96-.41,1.51,0,1.7,1.39,3.1,3.1,3.1s3.1-1.39,3.1-3.1-1.37-3.07-3.07-3.07h0Zm0-14.54c1.32,0,2.38,1.08,2.38,2.38s-1.08,2.38-2.38,2.38-2.38-1.08-2.38-2.38,1.06-2.38,2.38-2.38ZM3.1,13.32c-1.32,0-2.38-1.08-2.38-2.38s1.08-2.38,2.38-2.38,2.38,1.08,2.38,2.38-1.06,2.38-2.38,2.38Zm12,7.44c-1.32,0-2.38-1.08-2.38-2.38s1.08-2.38,2.38-2.38,2.38,1.08,2.38,2.38-1.08,2.38-2.38,2.38Z"/></g></svg>';
@@ -185,6 +189,6 @@ function _getBoolean(stringValue) {
185
189
  }
186
190
  }
187
191
  export {
188
- ProgressiveShareButtonClass,
189
- main as default
192
+ ProgressiveShareButton,
193
+ ProgressiveShareButtonClass
190
194
  };
@@ -1,3 +1,10 @@
1
+ /**
2
+ * name: progressive-share-button
3
+ * version: v1.0.1
4
+ * description: A web componet that creates a OS-native share button.
5
+ * author: John F. Morton <john@johnfmorton.com> (https://supergeekery.com)
6
+ * repository: https://github.com/johnfmorton/progressive-share-button
7
+ */
1
8
  (function(global, factory) {
2
9
  typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["progressive-share-button"] = {}));
3
10
  })(this, function(exports2) {
@@ -20,7 +27,7 @@ var __publicField = (obj, key, value) => {
20
27
  } else if (size) {
21
28
  return size;
22
29
  } else {
23
- return 24 + "px";
30
+ return "24px";
24
31
  }
25
32
  };
26
33
  function _isNumeric(value) {
@@ -92,12 +99,15 @@ var __publicField = (obj, key, value) => {
92
99
  if (!data.url && !data.text && !data.title) {
93
100
  data.url = window.location.href;
94
101
  }
95
- let shareEvent = new CustomEvent("progressive-share-success", {
96
- bubbles: true,
97
- cancelable: false,
98
- composed: true,
99
- detail: data
100
- });
102
+ let shareEvent = new CustomEvent(
103
+ "progressive-share-success",
104
+ {
105
+ bubbles: true,
106
+ cancelable: false,
107
+ composed: true,
108
+ detail: data
109
+ }
110
+ );
101
111
  if (navigator.share) {
102
112
  if (debug == 1) {
103
113
  console.debug("data to be shared", data);
@@ -105,15 +115,12 @@ var __publicField = (obj, key, value) => {
105
115
  navigator.share(data).then(() => {
106
116
  this.dispatchEvent(shareEvent);
107
117
  }).catch((e) => {
108
- let shareEventFail = new CustomEvent(
109
- "progressive-share-fail",
110
- {
111
- bubbles: true,
112
- cancelable: false,
113
- composed: true,
114
- detail: e
115
- }
116
- );
118
+ let shareEventFail = new CustomEvent("progressive-share-fail", {
119
+ bubbles: true,
120
+ cancelable: false,
121
+ composed: true,
122
+ detail: e
123
+ });
117
124
  this.dispatchEvent(shareEventFail);
118
125
  });
119
126
  }
@@ -122,7 +129,7 @@ var __publicField = (obj, key, value) => {
122
129
  }
123
130
  }
124
131
  }
125
- function init() {
132
+ const ProgressiveShareButton = () => {
126
133
  if (typeof navigator.share === "function") {
127
134
  console.log(
128
135
  "ProgressiveShareButton support initialized. <progressive-share-success /> element now available"
@@ -137,9 +144,6 @@ var __publicField = (obj, key, value) => {
137
144
  ProgressiveShareButtonClass
138
145
  );
139
146
  return true;
140
- }
141
- const main = {
142
- init
143
147
  };
144
148
  const iosShareIcon = '<svg xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 84.53 108.43" class="icon"><title>Share icon</title><desc>Square with upward arrow</desc><path d="m76.21,33.15h-23.38v5.28h23.38c1.72,0,3.04,1.32,3.04,2.91v58.77c0,1.58-1.32,2.91-3.04,2.91H8.32c-1.72,0-3.04-1.32-3.04-2.9v-58.64c0-1.58,1.32-2.91,3.04-2.91h20.74v-5.28H8.32c-4.62,0-8.32,3.7-8.32,8.19v58.77c0,4.49,3.7,8.19,8.32,8.19h67.88c4.62,0,8.32-3.7,8.32-8.19v-58.77c0-4.62-3.7-8.32-8.32-8.32h0Z"/><path d="m39.62,8.58v69.21h5.28V8.58l13.6,10.04,3.17-4.23L42.26,0l-19.41,14.4,3.17,4.23,13.6-10.04Z"/></svg>';
145
149
  const androidShareIcon = '<svg id="b" xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 18.19 21.46" class="icon"><title>Share icon</title><desc>Circle with smaller circles radiating out</desc><g id="c"><path d="m15.1,15.29c-.89,0-1.7.38-2.28.98l-6.98-3.84c.24-.43.38-.94.38-1.49s-.14-1.03-.38-1.49l7.22-4.03c.55.48,1.25.77,2.04.77,1.7,0,3.1-1.39,3.1-3.1s-1.39-3.1-3.1-3.1-3.1,1.39-3.1,3.1c0,.67.22,1.27.58,1.78l-7.18,4.01c-.58-.62-1.39-1.03-2.3-1.03-1.7,0-3.1,1.39-3.1,3.1s1.39,3.1,3.1,3.1c.91,0,1.73-.41,2.3-1.03l6.98,3.84c-.26.46-.41.96-.41,1.51,0,1.7,1.39,3.1,3.1,3.1s3.1-1.39,3.1-3.1-1.37-3.07-3.07-3.07h0Zm0-14.54c1.32,0,2.38,1.08,2.38,2.38s-1.08,2.38-2.38,2.38-2.38-1.08-2.38-2.38,1.06-2.38,2.38-2.38ZM3.1,13.32c-1.32,0-2.38-1.08-2.38-2.38s1.08-2.38,2.38-2.38,2.38,1.08,2.38,2.38-1.06,2.38-2.38,2.38Zm12,7.44c-1.32,0-2.38-1.08-2.38-2.38s1.08-2.38,2.38-2.38,2.38,1.08,2.38,2.38-1.08,2.38-2.38,2.38Z"/></g></svg>';
@@ -188,7 +192,7 @@ var __publicField = (obj, key, value) => {
188
192
  return JSON.parse(stringValue);
189
193
  }
190
194
  }
195
+ exports2.ProgressiveShareButton = ProgressiveShareButton;
191
196
  exports2.ProgressiveShareButtonClass = ProgressiveShareButtonClass;
192
- exports2.default = main;
193
- Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
197
+ Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
194
198
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "progressive-share-button",
3
- "version": "1.0.0-alpha.9",
3
+ "version": "1.0.1",
4
4
  "description": "A web componet that creates a OS-native share button.",
5
5
  "files": [
6
6
  "dist"
@@ -10,9 +10,9 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/johnfmorton/progressive-share-button"
12
12
  },
13
- "module": "./es/progressive-share-button.es.js",
13
+ "module": "./dist/progressive-share-button.es.js",
14
14
  "unpkg": "./dist/progressive-share-button.umd.js",
15
- "types": "./@types/progressive-share-button.d.ts",
15
+ "types": "./dist/progressive-share-button.d.ts",
16
16
  "exports": {
17
17
  ".": {
18
18
  "import": "./dist/progressive-share-button.es.js",
@@ -20,8 +20,10 @@
20
20
  }
21
21
  },
22
22
  "scripts": {
23
+ "clean": "rm -rf dist es demo",
23
24
  "dev": "vite --host 0.0.0.0 --port 8888",
24
- "build": "vite build",
25
+ "vite-build": "vite build --config vite.demo.config.js",
26
+ "build": "vite build --config vite.demo.config.js && vite build && tsc lib/progressive-share-button.ts --declaration --emitDeclarationOnly --outFile dist/progressive-share-button.d.ts",
25
27
  "preview": "vite preview",
26
28
  "test": "echo \"Error: no test specified\" && exit 1"
27
29
  },
@@ -35,6 +37,11 @@
35
37
  "author": "John F. Morton <john@johnfmorton.com> (https://supergeekery.com)",
36
38
  "license": "MIT",
37
39
  "devDependencies": {
38
- "vite": "^4.1.3"
40
+ "autoprefixer": "^10.4.13",
41
+ "postcss": "^8.4.21",
42
+ "tailwindcss": "^3.2.7",
43
+ "typescript": "^4.9.5",
44
+ "vite": "^4.1.3",
45
+ "vite-plugin-banner": "^0.7.0"
39
46
  }
40
47
  }