spikijs 1.0.2 → 1.0.5

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/package.json +5 -2
  3. package/spiki.d.ts +74 -0
package/README.md CHANGED
@@ -21,7 +21,7 @@ npm install spikijs
21
21
  You can use the CDN directly in your HTML using a standard script tag:
22
22
 
23
23
  ```html
24
- <script src="https://unpkg.com/spikijs@1.0.2/spiki.min.js"></script>
24
+ <script src="https://unpkg.com/spikijs@1.0.0/spiki.min.js"></script>
25
25
 
26
26
  ```
27
27
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "spikijs",
3
3
  "license": "MIT",
4
- "version": "1.0.2",
4
+ "version": "1.0.5",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -12,10 +12,12 @@
12
12
  "url": "https://github.com/novver/spikijs/issues"
13
13
  },
14
14
  "main": "./spiki.esm.min.js",
15
+ "types": "./spiki.d.ts",
15
16
  "unpkg": "./spiki.min.js",
16
17
  "jsdelivr": "./spiki.min.js",
17
18
  "exports": {
18
19
  ".": {
20
+ "types": "./spiki.d.ts",
19
21
  "development": "./spiki.esm.js",
20
22
  "default": "./spiki.esm.min.js"
21
23
  }
@@ -24,6 +26,7 @@
24
26
  "spiki.esm.js",
25
27
  "spiki.esm.min.js",
26
28
  "spiki.js",
27
- "spiki.min.js"
29
+ "spiki.min.js",
30
+ "spiki.d.ts"
28
31
  ]
29
32
  }
package/spiki.d.ts ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Interface representing the internal properties injected by Spiki.
3
+ * These are available via 'this' inside your component.
4
+ */
5
+ export interface SpikiInstance {
6
+ /**
7
+ * The root DOM element of the component (the one with s-data).
8
+ */
9
+ readonly $root: HTMLElement;
10
+
11
+ /**
12
+ * References to DOM elements marked with `s-ref`.
13
+ * Example: <input s-ref="box"> becomes this.$refs.box
14
+ */
15
+ readonly $refs: Record<string, HTMLElement>;
16
+
17
+ /**
18
+ * Access to the global reactive store.
19
+ */
20
+ readonly $store: Record<string, any>;
21
+
22
+ /**
23
+ * Lifecycle hook: Called immediately after the component is mounted.
24
+ */
25
+ init?(): void;
26
+
27
+ /**
28
+ * Lifecycle hook: Called when the component is removed from the DOM.
29
+ */
30
+ destroy?(): void;
31
+
32
+ /**
33
+ * Index signature to allow dynamic properties.
34
+ * This prevents TypeScript errors when accessing variables
35
+ * injected by 's-for' loops (e.g., this.item, this.index).
36
+ */
37
+ [key: string]: any;
38
+ }
39
+
40
+ /**
41
+ * Type helper for the data factory.
42
+ * It ensures 'this' inside your methods includes both your data
43
+ * and Spiki's internal properties ($refs, $root, etc).
44
+ */
45
+ type ComponentFactory<T> = () => T & ThisType<T & SpikiInstance>;
46
+
47
+ interface Spiki {
48
+ /**
49
+ * Registers a new component.
50
+ *
51
+ * @param name The name matching the 's-data' attribute in HTML.
52
+ * @param factory A function that returns the initial state object.
53
+ */
54
+ data<T extends object>(name: string, factory: ComponentFactory<T>): void;
55
+
56
+ /**
57
+ * Starts the Spiki engine.
58
+ * Scans the DOM for 's-data' elements and mounts them.
59
+ */
60
+ start(): void;
61
+
62
+ /**
63
+ * Retrieves a value from the global store.
64
+ */
65
+ store<T = any>(key: string): T;
66
+
67
+ /**
68
+ * Sets a value in the global store.
69
+ */
70
+ store<T = any>(key: string, value: T): T;
71
+ }
72
+
73
+ declare const spiki: Spiki;
74
+ export default spiki;