@ailuracode/alpine-network 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) ailuracode
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # @ailuracode/alpine-network
2
+
3
+ Network connectivity magic for Alpine.js.
4
+
5
+ **[Full documentation →](../../docs/network.md)**
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @ailuracode/alpine-network alpinejs
11
+ ```
12
+
13
+ ## Quick example
14
+
15
+ ```js
16
+ import Alpine from "alpinejs";
17
+ import network from "@ailuracode/alpine-network";
18
+
19
+ Alpine.plugin(network);
20
+ Alpine.start();
21
+ ```
22
+
23
+ ```html
24
+ <div x-show="!$network.isOnline">You are offline</div>
25
+ <button :disabled="!$network.isOnline">Save</button>
26
+ ```
27
+
28
+ ## API summary
29
+
30
+ | | |
31
+ |-|-|
32
+ | **Magic** | `$network` |
33
+ | **Properties** | `isOnline` (boolean) |
34
+
35
+ ## License
36
+
37
+ MIT
@@ -0,0 +1,13 @@
1
+ /// <reference types="@types/alpinejs" />
2
+
3
+ export interface NetworkMagic {
4
+ isOnline: boolean;
5
+ }
6
+
7
+ declare global {
8
+ namespace Alpine {
9
+ interface Magics<T> {
10
+ $network: NetworkMagic;
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,16 @@
1
+ import AlpineType from 'alpinejs';
2
+
3
+ interface NetworkMagic {
4
+ isOnline: boolean;
5
+ }
6
+ /** Alpine.js network plugin. Registers reactive magic `$network`. */
7
+ declare function networkPlugin(Alpine: AlpineType.Alpine): void;
8
+ declare global {
9
+ namespace Alpine {
10
+ interface Magics<T> {
11
+ $network: NetworkMagic;
12
+ }
13
+ }
14
+ }
15
+
16
+ export { type NetworkMagic, networkPlugin as default };
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ // src/index.ts
2
+ function networkPlugin(Alpine) {
3
+ const state = Alpine.reactive({ isOnline: navigator.onLine });
4
+ Alpine.magic("network", () => state);
5
+ const update = () => {
6
+ state.isOnline = navigator.onLine;
7
+ };
8
+ window.addEventListener("online", update);
9
+ window.addEventListener("offline", update);
10
+ }
11
+ export {
12
+ networkPlugin as default
13
+ };
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type AlpineType from \"alpinejs\";\n\nexport interface NetworkMagic {\n isOnline: boolean;\n}\n\n/** Alpine.js network plugin. Registers reactive magic `$network`. */\nexport default function networkPlugin(Alpine: AlpineType.Alpine): void {\n const state = Alpine.reactive<NetworkMagic>({ isOnline: navigator.onLine });\n\n Alpine.magic(\"network\", () => state);\n\n const update = () => {\n state.isOnline = navigator.onLine;\n };\n\n window.addEventListener(\"online\", update);\n window.addEventListener(\"offline\", update);\n}\n\ndeclare global {\n namespace Alpine {\n interface Magics<T> {\n $network: NetworkMagic;\n }\n }\n}\n"],"mappings":";AAOe,SAAR,cAA+B,QAAiC;AACrE,QAAM,QAAQ,OAAO,SAAuB,EAAE,UAAU,UAAU,OAAO,CAAC;AAE1E,SAAO,MAAM,WAAW,MAAM,KAAK;AAEnC,QAAM,SAAS,MAAM;AACnB,UAAM,WAAW,UAAU;AAAA,EAC7B;AAEA,SAAO,iBAAiB,UAAU,MAAM;AACxC,SAAO,iBAAiB,WAAW,MAAM;AAC3C;","names":[]}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@ailuracode/alpine-network",
3
+ "version": "1.0.0",
4
+ "description": "Alpine.js network connectivity magic",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "ailuracode",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/ailuracode/alpine.git",
14
+ "directory": "packages/network"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/ailuracode/alpine/issues"
18
+ },
19
+ "homepage": "https://github.com/ailuracode/alpine/tree/master/packages/network#readme",
20
+ "files": [
21
+ "dist",
22
+ "README.md"
23
+ ],
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ },
29
+ "./global": {
30
+ "types": "./dist/global.d.ts"
31
+ }
32
+ },
33
+ "types": "./dist/global.d.ts",
34
+ "peerDependencies": {
35
+ "alpinejs": "^3.0.0",
36
+ "@types/alpinejs": "^3.13.11"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "@types/alpinejs": {
40
+ "optional": true
41
+ }
42
+ },
43
+ "keywords": [
44
+ "alpinejs",
45
+ "alpine",
46
+ "plugin",
47
+ "network",
48
+ "online",
49
+ "offline",
50
+ "connectivity"
51
+ ],
52
+ "scripts": {
53
+ "build": "tsup src/index.ts --format esm --dts --clean --sourcemap --out-dir dist && cp src/global.d.ts dist/global.d.ts",
54
+ "test": "vitest run --config ../../vitest.config.js test"
55
+ }
56
+ }