@voidable/ui-liveview 0.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.md ADDED
@@ -0,0 +1,25 @@
1
+ The MIT License (MIT)
2
+ =====================
3
+
4
+ Copyright © `2026` `Kaz Walker`
5
+
6
+ Permission is hereby granted, free of charge, to any person
7
+ obtaining a copy of this software and associated documentation
8
+ files (the “Software”), to deal in the Software without
9
+ restriction, including without limitation the rights to use,
10
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the
12
+ Software is furnished to do so, subject to the following
13
+ conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,74 @@
1
+ declare type ListenerEntry = [event: string, handler: (e: Event) => void];
2
+
3
+ /**
4
+ * LiveView JS hooks that bridge CustomEvents emitted by Voidable web
5
+ * components to Phoenix LiveView's `pushEvent()` channel.
6
+ *
7
+ * Usage in HEEx:
8
+ * ```heex
9
+ * <void-button phx-hook="VoidEvent" data-void-events="void-click">
10
+ * Click me
11
+ * </void-button>
12
+ * ```
13
+ */
14
+ /** Minimal LiveView hook shape used by phoenix_live_view. */
15
+ declare interface ViewHookInstance {
16
+ el: HTMLElement;
17
+ pushEvent(event: string, payload: object): void;
18
+ handleEvent(event: string, callback: (payload: object) => void): void;
19
+ mounted?(): void;
20
+ updated?(): void;
21
+ destroyed?(): void;
22
+ disconnected?(): void;
23
+ reconnected?(): void;
24
+ beforeUpdate?(): void;
25
+ beforeDestroy?(): void;
26
+ }
27
+
28
+ /**
29
+ * DOM-patching callbacks that preserve web component client state during
30
+ * LiveView's morphdom updates.
31
+ *
32
+ * Usage:
33
+ * ```js
34
+ * import { VoidDOM } from "@voidable/ui-liveview";
35
+ * const liveSocket = new LiveSocket("/live", Socket, {
36
+ * dom: {
37
+ * onBeforeElUpdated(from, to) {
38
+ * VoidDOM.onBeforeElUpdated(from, to);
39
+ * },
40
+ * },
41
+ * });
42
+ * ```
43
+ */
44
+ export declare const VoidDOM: {
45
+ /**
46
+ * Call from `dom.onBeforeElUpdated` in your LiveSocket config.
47
+ *
48
+ * When LiveView patches the DOM via morphdom, client-managed attributes on
49
+ * `void-*` custom elements can be lost if they weren't in the server-rendered
50
+ * markup. This callback copies them from the outgoing element to the incoming
51
+ * one so the component keeps its visual state.
52
+ */
53
+ onBeforeElUpdated(fromEl: Element, toEl: Element): void;
54
+ };
55
+
56
+ /** Extended hook instance carrying private bookkeeping state. */
57
+ declare interface VoidEventInstance extends ViewHookInstance {
58
+ _listeners: ListenerEntry[];
59
+ _boundEvents: string[];
60
+ }
61
+
62
+ /**
63
+ * A map of LiveView hooks to spread into the `hooks` option of `LiveSocket`.
64
+ *
65
+ * ```js
66
+ * import { VoidHooks } from "@voidable/ui-liveview";
67
+ * const liveSocket = new LiveSocket("/live", Socket, {
68
+ * hooks: { ...VoidHooks },
69
+ * });
70
+ * ```
71
+ */
72
+ export declare const VoidHooks: Record<string, Partial<ViewHookInstance> & ThisType<VoidEventInstance>>;
73
+
74
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,48 @@
1
+ //#region src/hooks.ts
2
+ function e(e) {
3
+ return (e.dataset.voidEvents || "").split(",").filter(Boolean);
4
+ }
5
+ function t(e, t) {
6
+ for (let n of t) {
7
+ let t = (t) => {
8
+ e.pushEvent(n, t.detail || {});
9
+ };
10
+ e.el.addEventListener(n, t), e._listeners.push([n, t]);
11
+ }
12
+ e._boundEvents = t;
13
+ }
14
+ function n(e) {
15
+ for (let [t, n] of e._listeners) e.el.removeEventListener(t, n);
16
+ e._listeners = [], e._boundEvents = [];
17
+ }
18
+ var r = { VoidEvent: {
19
+ mounted() {
20
+ this._listeners = [], this._boundEvents = [];
21
+ let n = e(this.el);
22
+ t(this, n);
23
+ },
24
+ updated() {
25
+ let r = e(this.el), i = this._boundEvents || [];
26
+ r.length === i.length && r.every((e, t) => e === i[t]) || (n(this), t(this, r));
27
+ },
28
+ destroyed() {
29
+ n(this);
30
+ }
31
+ } }, i = [
32
+ "aria-expanded",
33
+ "aria-selected",
34
+ "aria-checked",
35
+ "aria-hidden"
36
+ ], a = [
37
+ "open",
38
+ "active",
39
+ "checked",
40
+ "selected"
41
+ ], o = { onBeforeElUpdated(e, t) {
42
+ if (e.tagName.startsWith("VOID-")) {
43
+ for (let n of i) e.hasAttribute(n) && !t.hasAttribute(n) && t.setAttribute(n, e.getAttribute(n));
44
+ for (let n of a) e.hasAttribute(n) && !t.hasAttribute(n) && t.setAttribute(n, e.getAttribute(n));
45
+ }
46
+ } };
47
+ //#endregion
48
+ export { o as VoidDOM, r as VoidHooks };
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@voidable/ui-liveview",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "development": "./src/index.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": ["dist"],
14
+ "scripts": {
15
+ "build": "vite build",
16
+ "typecheck": "tsc --noEmit"
17
+ },
18
+ "peerDependencies": {
19
+ "@voidable/ui": "workspace:*",
20
+ "phoenix_live_view": ">=1.0.0"
21
+ },
22
+ "devDependencies": {
23
+ "@voidable/ui": "workspace:*",
24
+ "typescript": "^6.0.0",
25
+ "vite": "^8.0.0",
26
+ "vite-plugin-dts": "^4.5.0"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/VoidableUI/Voidable",
31
+ "directory": "packages/liveview"
32
+ }
33
+ }