juxscript 1.0.128 → 1.0.129
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/index.js +1 -1
- package/lib/componentsv2/base/BaseEngine.js +5 -5
- package/lib/componentsv2/base/BaseSkin.d.ts +21 -0
- package/lib/componentsv2/base/BaseSkin.js +35 -0
- package/lib/componentsv2/base/Neighborhood.d.ts +22 -0
- package/lib/componentsv2/base/Neighborhood.js +56 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -16,7 +16,7 @@ export { List } from './lib/componentsv2/list/List.js';
|
|
|
16
16
|
export { BaseEngine } from './lib/componentsv2/base/BaseEngine.js';
|
|
17
17
|
export { BaseSkin } from './lib/componentsv2/base/BaseSkin.js';
|
|
18
18
|
export { State } from './lib/componentsv2/base/State.js';
|
|
19
|
-
export { GlobalBus } from './lib/componentsv2/base/
|
|
19
|
+
export { GlobalBus } from './lib/componentsv2/base/Neighborhood.js';
|
|
20
20
|
|
|
21
21
|
// Utilities
|
|
22
22
|
export { validateOptions } from './lib/componentsv2/base/OptionsContract.js';
|
|
@@ -11,7 +11,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _BaseEngine_state, _BaseEngine_listeners, _BaseEngine_cleanupListeners, _BaseEngine_plugins, _BaseEngine_emitHistory, _BaseEngine_debugMode, _BaseEngine_validationResult;
|
|
13
13
|
import { State } from './State.js';
|
|
14
|
-
import {
|
|
14
|
+
import { Neighborhood } from './Neighborhood.js';
|
|
15
15
|
import { validateOptions } from './OptionsContract.js';
|
|
16
16
|
/**
|
|
17
17
|
* THE ENGINE AGREEMENT
|
|
@@ -118,9 +118,9 @@ export class BaseEngine {
|
|
|
118
118
|
* @param callback Reaction logic
|
|
119
119
|
*/
|
|
120
120
|
listenTo(channel, callback) {
|
|
121
|
-
|
|
121
|
+
Neighborhood.on(channel, callback);
|
|
122
122
|
// Track for cleanup
|
|
123
|
-
__classPrivateFieldGet(this, _BaseEngine_cleanupListeners, "f").push(() =>
|
|
123
|
+
__classPrivateFieldGet(this, _BaseEngine_cleanupListeners, "f").push(() => Neighborhood.off(channel, callback));
|
|
124
124
|
return this;
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
@@ -160,7 +160,7 @@ export class BaseEngine {
|
|
|
160
160
|
// 2. Notify The Neighborhood (Global Bus)
|
|
161
161
|
// Format: "ComponentID:EventName"
|
|
162
162
|
const globalChannel = `${this.state.id}:${event}`;
|
|
163
|
-
|
|
163
|
+
Neighborhood.emit(globalChannel, {
|
|
164
164
|
...data,
|
|
165
165
|
_event: event,
|
|
166
166
|
_source: this.state.id
|
|
@@ -171,7 +171,7 @@ export class BaseEngine {
|
|
|
171
171
|
* Useful for debugging communication topology from the console.
|
|
172
172
|
*/
|
|
173
173
|
get eventRegistry() {
|
|
174
|
-
return
|
|
174
|
+
return Neighborhood.registry;
|
|
175
175
|
}
|
|
176
176
|
/**
|
|
177
177
|
* DEBUG: Access the Internal State Ledger (History).
|
|
@@ -11,6 +11,7 @@ import { BaseEngine, BaseState } from './BaseEngine.js';
|
|
|
11
11
|
export declare abstract class BaseSkin<TState extends BaseState, TEngine extends BaseEngine<TState>> {
|
|
12
12
|
protected engine: TEngine;
|
|
13
13
|
protected root: HTMLElement | null;
|
|
14
|
+
private _cleanupTasks;
|
|
14
15
|
constructor(engine: TEngine);
|
|
15
16
|
/**
|
|
16
17
|
* CONTRACT: Provide the URL/Path to the structural CSS file.
|
|
@@ -29,6 +30,26 @@ export declare abstract class BaseSkin<TState extends BaseState, TEngine extends
|
|
|
29
30
|
* @param href The URL to the CSS file
|
|
30
31
|
*/
|
|
31
32
|
injectCSSLink(id: string, href: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* Utility: Subscribe to MY Engine's events.
|
|
35
|
+
* "Me" refers to this component instance (Engine + Skin).
|
|
36
|
+
*
|
|
37
|
+
* Use this for internal signals like "loginSuccess", "error", or "animationStart".
|
|
38
|
+
*/
|
|
39
|
+
protected listenToMe(event: string, callback: (data: any) => void): void;
|
|
40
|
+
/**
|
|
41
|
+
* Utility: Subscribe to the Global Bus (The Neighborhood).
|
|
42
|
+
* "Neighbors" refers to other components or global system events.
|
|
43
|
+
*
|
|
44
|
+
* ⚠️ USE SPARINGLY. Ideally, data flows down from the Engine via State.
|
|
45
|
+
* Use this for purely visual coordination like "theme:switched" or "layout:collapse-all".
|
|
46
|
+
*/
|
|
47
|
+
protected listenToNeighbors(channel: string, callback: (data: any) => void): void;
|
|
48
|
+
/**
|
|
49
|
+
* Component Teardown.
|
|
50
|
+
* Removes the root element and cleans up all event listeners.
|
|
51
|
+
*/
|
|
52
|
+
dispose(): void;
|
|
32
53
|
/**
|
|
33
54
|
* Utility: Inject CSS into the document head if not already present.
|
|
34
55
|
* Useful for Skins to seamlessly load their required aesthetics.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Neighborhood } from './Neighborhood.js';
|
|
1
2
|
/**
|
|
2
3
|
* THE SKIN AGREEMENT
|
|
3
4
|
*
|
|
@@ -10,6 +11,7 @@
|
|
|
10
11
|
export class BaseSkin {
|
|
11
12
|
constructor(engine) {
|
|
12
13
|
this.root = null;
|
|
14
|
+
this._cleanupTasks = [];
|
|
13
15
|
this.engine = engine;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
@@ -32,6 +34,39 @@ export class BaseSkin {
|
|
|
32
34
|
link.href = href;
|
|
33
35
|
}
|
|
34
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Utility: Subscribe to MY Engine's events.
|
|
39
|
+
* "Me" refers to this component instance (Engine + Skin).
|
|
40
|
+
*
|
|
41
|
+
* Use this for internal signals like "loginSuccess", "error", or "animationStart".
|
|
42
|
+
*/
|
|
43
|
+
listenToMe(event, callback) {
|
|
44
|
+
this.engine.on(event, callback);
|
|
45
|
+
this._cleanupTasks.push(() => this.engine.off(event, callback));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Utility: Subscribe to the Global Bus (The Neighborhood).
|
|
49
|
+
* "Neighbors" refers to other components or global system events.
|
|
50
|
+
*
|
|
51
|
+
* ⚠️ USE SPARINGLY. Ideally, data flows down from the Engine via State.
|
|
52
|
+
* Use this for purely visual coordination like "theme:switched" or "layout:collapse-all".
|
|
53
|
+
*/
|
|
54
|
+
listenToNeighbors(channel, callback) {
|
|
55
|
+
Neighborhood.on(channel, callback);
|
|
56
|
+
this._cleanupTasks.push(() => Neighborhood.off(channel, callback));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Component Teardown.
|
|
60
|
+
* Removes the root element and cleans up all event listeners.
|
|
61
|
+
*/
|
|
62
|
+
dispose() {
|
|
63
|
+
this._cleanupTasks.forEach(task => task());
|
|
64
|
+
this._cleanupTasks = [];
|
|
65
|
+
if (this.root) {
|
|
66
|
+
this.root.remove();
|
|
67
|
+
this.root = null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
35
70
|
/**
|
|
36
71
|
* Utility: Inject CSS into the document head if not already present.
|
|
37
72
|
* Useful for Skins to seamlessly load their required aesthetics.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type GlobalListener = (data: any) => void;
|
|
2
|
+
/**
|
|
3
|
+
* THE NEIGHBORHOOD (Global Event Mediator)
|
|
4
|
+
*
|
|
5
|
+
* Acts as the certal nervous system where all components post updates.
|
|
6
|
+
* Other components can tune in to specific frequencies (channels) here.
|
|
7
|
+
*/
|
|
8
|
+
export declare class JuxGlobalBus {
|
|
9
|
+
private listeners;
|
|
10
|
+
on(channel: string, callback: GlobalListener): void;
|
|
11
|
+
off(channel: string, callback: GlobalListener): void;
|
|
12
|
+
emit(channel: string, data: any): void;
|
|
13
|
+
/**
|
|
14
|
+
* DEBUG: Read-only Snapshot of active channels and listener identities.
|
|
15
|
+
* usage: juxV2.events.registry
|
|
16
|
+
* Returns: { "channelName": ["functionName", "(anonymous)"] }
|
|
17
|
+
*/
|
|
18
|
+
get registry(): Record<string, string[]>;
|
|
19
|
+
}
|
|
20
|
+
export declare const Neighborhood: JuxGlobalBus;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=Neighborhood.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE NEIGHBORHOOD (Global Event Mediator)
|
|
3
|
+
*
|
|
4
|
+
* Acts as the certal nervous system where all components post updates.
|
|
5
|
+
* Other components can tune in to specific frequencies (channels) here.
|
|
6
|
+
*/
|
|
7
|
+
export class JuxGlobalBus {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.listeners = new Map();
|
|
10
|
+
}
|
|
11
|
+
on(channel, callback) {
|
|
12
|
+
if (!this.listeners.has(channel)) {
|
|
13
|
+
this.listeners.set(channel, new Set());
|
|
14
|
+
}
|
|
15
|
+
this.listeners.get(channel).add(callback);
|
|
16
|
+
}
|
|
17
|
+
off(channel, callback) {
|
|
18
|
+
const set = this.listeners.get(channel);
|
|
19
|
+
if (set) {
|
|
20
|
+
set.delete(callback);
|
|
21
|
+
if (set.size === 0) {
|
|
22
|
+
this.listeners.delete(channel);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
emit(channel, data) {
|
|
27
|
+
const set = this.listeners.get(channel);
|
|
28
|
+
if (set) {
|
|
29
|
+
set.forEach(callback => {
|
|
30
|
+
try {
|
|
31
|
+
callback(data);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
console.error(`Jux GlobalBus Error [${channel}]:`, e);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
// Optional: We could have a wildcard '*' listener here for debuggers/loggers
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* DEBUG: Read-only Snapshot of active channels and listener identities.
|
|
42
|
+
* usage: juxV2.events.registry
|
|
43
|
+
* Returns: { "channelName": ["functionName", "(anonymous)"] }
|
|
44
|
+
*/
|
|
45
|
+
get registry() {
|
|
46
|
+
const snapshot = {};
|
|
47
|
+
this.listeners.forEach((set, channel) => {
|
|
48
|
+
// Map the Set of functions to their names for easier debugging
|
|
49
|
+
snapshot[channel] = Array.from(set).map(fn => fn.name || '(anonymous)');
|
|
50
|
+
});
|
|
51
|
+
return snapshot;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Singleton Instance
|
|
55
|
+
export const Neighborhood = new JuxGlobalBus();
|
|
56
|
+
//# sourceMappingURL=Neighborhood.js.map
|