juxscript 1.1.28 ā 1.1.30
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.d.ts +2 -1
- package/index.d.ts.map +1 -1
- package/index.js +2 -1
- package/lib/components/base/BaseComponent.d.ts +20 -7
- package/lib/components/base/BaseComponent.d.ts.map +1 -1
- package/lib/components/base/BaseComponent.js +64 -15
- package/lib/components/base/BaseComponent.ts +75 -15
- package/lib/components/history/StateHistory.d.ts +91 -0
- package/lib/components/history/StateHistory.d.ts.map +1 -0
- package/lib/components/history/StateHistory.js +154 -0
- package/lib/components/history/StateHistory.ts +200 -0
- package/lib/components/registry.d.ts +10 -36
- package/lib/components/registry.d.ts.map +1 -1
- package/lib/components/registry.js +122 -105
- package/lib/components/registry.ts +141 -112
- package/package.json +1 -1
|
@@ -1,164 +1,193 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* Usage in console:
|
|
6
|
-
* __jux.get('hero-1').state.title = 'New Title'
|
|
7
|
-
* __jux.list()
|
|
8
|
-
* __jux.find('hero')
|
|
9
|
-
* __jux.create('button', 'btn-1', { label: 'Click Me' }).render()
|
|
2
|
+
* Simplified JUX Component Registry
|
|
3
|
+
* Lean console debugging interface
|
|
10
4
|
*/
|
|
11
5
|
|
|
12
6
|
import { BaseComponent } from './base/BaseComponent.js';
|
|
7
|
+
import { stateHistory } from './history/StateHistory.js';
|
|
13
8
|
|
|
14
9
|
class ComponentRegistry {
|
|
15
|
-
private components:
|
|
10
|
+
private components: BaseComponent<any>[] = [];
|
|
16
11
|
|
|
17
|
-
/**
|
|
18
|
-
* Register a component instance
|
|
19
|
-
*/
|
|
20
12
|
register(component: BaseComponent<any>): void {
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
// Avoid duplicates
|
|
14
|
+
if (!this.components.find(c => c._id === component._id)) {
|
|
15
|
+
this.components.push(component);
|
|
16
|
+
}
|
|
23
17
|
}
|
|
24
18
|
|
|
25
|
-
/**
|
|
26
|
-
* Unregister a component
|
|
27
|
-
*/
|
|
28
19
|
unregister(id: string): void {
|
|
29
|
-
this.components.
|
|
30
|
-
console.debug(`[Jux Registry] Unregistered: ${id}`);
|
|
20
|
+
this.components = this.components.filter(c => c._id !== id);
|
|
31
21
|
}
|
|
32
22
|
|
|
33
23
|
/**
|
|
34
|
-
* Get
|
|
24
|
+
* Get component by index or ID
|
|
35
25
|
*/
|
|
36
|
-
get
|
|
37
|
-
|
|
26
|
+
get(indexOrId: number | string): BaseComponent<any> | undefined {
|
|
27
|
+
if (typeof indexOrId === 'number') {
|
|
28
|
+
return this.components[indexOrId];
|
|
29
|
+
}
|
|
30
|
+
return this.components.find(c => c._id === indexOrId);
|
|
38
31
|
}
|
|
39
32
|
|
|
40
33
|
/**
|
|
41
|
-
*
|
|
34
|
+
* Print indexed list to console
|
|
42
35
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
list(): void {
|
|
37
|
+
if (this.components.length === 0) {
|
|
38
|
+
console.log('š No components registered');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log('\nš Registered Components:\n');
|
|
43
|
+
this.components.forEach((comp, idx) => {
|
|
44
|
+
console.log(` [${idx}] ${comp._id} ā ${comp.constructor.name}`);
|
|
45
|
+
});
|
|
46
|
+
console.log(`\nš” Access via: _jux.get(${0}) or _jux.get('${this.components[0]._id}')\n`);
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/**
|
|
48
|
-
*
|
|
50
|
+
* Show component tree with state, history, events
|
|
49
51
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
tree(indexOrId?: number | string): void {
|
|
53
|
+
let comp: BaseComponent<any> | undefined;
|
|
54
|
+
|
|
55
|
+
if (indexOrId === undefined) {
|
|
56
|
+
// Show all components
|
|
57
|
+
this.components.forEach((c, idx) => this._printTree(c, idx));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
comp = this.get(indexOrId);
|
|
62
|
+
if (!comp) {
|
|
63
|
+
console.error(`ā Component not found: ${indexOrId}`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
this._printTree(comp, typeof indexOrId === 'number' ? indexOrId : undefined);
|
|
52
68
|
}
|
|
53
69
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
private _printTree(comp: BaseComponent<any>, index?: number): void {
|
|
71
|
+
const idx = index !== undefined ? `[${index}]` : '';
|
|
72
|
+
const stateChanges = stateHistory.getComponentHistory(comp._id);
|
|
73
|
+
const events = stateHistory.getComponentEvents(comp._id);
|
|
74
|
+
const syncCount = (comp as any)._syncBindings?.length || 0;
|
|
75
|
+
const bindCount = (comp as any)._bindings?.length || 0;
|
|
76
|
+
|
|
77
|
+
console.group(`š³ ${idx} ${comp._id} (${comp.constructor.name})`);
|
|
78
|
+
|
|
79
|
+
console.log('š State:', comp.state);
|
|
80
|
+
|
|
81
|
+
if (stateChanges.length > 0) {
|
|
82
|
+
console.log(`š History: ${stateChanges.length} changes`);
|
|
83
|
+
console.log(' Last 3:', stateChanges.slice(-3).map(s =>
|
|
84
|
+
`${s.property}: ${s.oldValue} ā ${s.newValue}`
|
|
85
|
+
));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (syncCount > 0) {
|
|
89
|
+
console.log(`š Syncs: ${syncCount} active`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (bindCount > 0 || events.length > 0) {
|
|
93
|
+
console.log(`ā” Events: ${bindCount} binds, ${events.length} fired`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
console.log(`\nš” Commands:`);
|
|
97
|
+
console.log(` _jux.get(${index ?? `'${comp._id}'`}).state.prop = value`);
|
|
98
|
+
console.log(` _jux.get(${index ?? `'${comp._id}'`}).rollback()`);
|
|
99
|
+
console.log(` _jux.get(${index ?? `'${comp._id}'`}).timeline()`);
|
|
100
|
+
|
|
101
|
+
console.groupEnd();
|
|
61
102
|
}
|
|
62
103
|
|
|
63
104
|
/**
|
|
64
105
|
* Get all components
|
|
65
106
|
*/
|
|
66
107
|
all(): BaseComponent<any>[] {
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Get components by type (constructor name)
|
|
72
|
-
*/
|
|
73
|
-
byType(typeName: string): BaseComponent<any>[] {
|
|
74
|
-
return Array.from(this.components.values())
|
|
75
|
-
.filter(comp => comp.constructor.name === typeName);
|
|
108
|
+
return this.components;
|
|
76
109
|
}
|
|
77
110
|
|
|
78
111
|
/**
|
|
79
|
-
* Clear
|
|
112
|
+
* Clear registry
|
|
80
113
|
*/
|
|
81
114
|
clear(): void {
|
|
82
|
-
this.components
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Get registry stats
|
|
88
|
-
*/
|
|
89
|
-
stats(): { total: number; types: Record<string, number> } {
|
|
90
|
-
const types: Record<string, number> = {};
|
|
91
|
-
|
|
92
|
-
this.components.forEach(comp => {
|
|
93
|
-
const type = comp.constructor.name;
|
|
94
|
-
types[type] = (types[type] || 0) + 1;
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
total: this.components.size,
|
|
99
|
-
types
|
|
100
|
-
};
|
|
115
|
+
this.components = [];
|
|
116
|
+
stateHistory.clear();
|
|
101
117
|
}
|
|
102
118
|
}
|
|
103
119
|
|
|
104
|
-
// Global singleton instance
|
|
105
120
|
export const registry = new ComponentRegistry();
|
|
106
121
|
|
|
107
|
-
// Expose
|
|
122
|
+
// ā
Expose lean console interface
|
|
108
123
|
if (typeof window !== 'undefined') {
|
|
109
|
-
(window as any).
|
|
110
|
-
|
|
124
|
+
(window as any)._jux = {
|
|
125
|
+
/**
|
|
126
|
+
* Get component by index or ID
|
|
127
|
+
* @example
|
|
128
|
+
* const h = _jux.get(0) // Get first component
|
|
129
|
+
* const h = _jux.get('hero-1') // Get by ID
|
|
130
|
+
* h.state.title = 'New Title' // Direct mutation
|
|
131
|
+
* h.rollback() // Undo last change
|
|
132
|
+
*/
|
|
133
|
+
get: (indexOrId: number | string) => registry.get(indexOrId),
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* List all components with indices
|
|
137
|
+
* @example
|
|
138
|
+
* _jux.list()
|
|
139
|
+
* // [0] hero-1 ā Hero
|
|
140
|
+
* // [1] nav-main ā Nav
|
|
141
|
+
*/
|
|
111
142
|
list: () => registry.list(),
|
|
112
|
-
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Show component tree (state, history, events, syncs)
|
|
146
|
+
* @example
|
|
147
|
+
* _jux.tree() // Show all
|
|
148
|
+
* _jux.tree(0) // Show first component
|
|
149
|
+
* _jux.tree('hero-1') // Show specific component
|
|
150
|
+
*/
|
|
151
|
+
tree: (indexOrId?: number | string) => registry.tree(indexOrId),
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Get all components
|
|
155
|
+
*/
|
|
113
156
|
all: () => registry.all(),
|
|
114
|
-
|
|
115
|
-
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Clear all components and history
|
|
160
|
+
*/
|
|
116
161
|
clear: () => registry.clear(),
|
|
117
162
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return jux[type](id, options);
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
// Debug helper
|
|
129
|
-
debug: (id: string) => {
|
|
130
|
-
const comp = registry.get(id);
|
|
131
|
-
if (!comp) {
|
|
132
|
-
console.error(`Component "${id}" not found`);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
console.group(`š Component: ${id}`);
|
|
136
|
-
console.log('Type:', comp.constructor.name);
|
|
137
|
-
console.log('State:', comp.state);
|
|
138
|
-
console.log('Props:', comp.props);
|
|
139
|
-
console.log('Container:', comp.container);
|
|
140
|
-
console.log('Instance:', comp);
|
|
141
|
-
console.groupEnd();
|
|
163
|
+
/**
|
|
164
|
+
* Access global state history
|
|
165
|
+
*/
|
|
166
|
+
history: {
|
|
167
|
+
stats: () => stateHistory.getStats(),
|
|
168
|
+
timeline: () => stateHistory.getTimeline(),
|
|
169
|
+
clear: () => stateHistory.clear()
|
|
142
170
|
}
|
|
143
171
|
};
|
|
144
172
|
|
|
145
173
|
console.log(`
|
|
146
|
-
šØ
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
174
|
+
šØ JUX DevTools Ready!
|
|
175
|
+
|
|
176
|
+
Quick Commands:
|
|
177
|
+
_jux.list() List all components with indices
|
|
178
|
+
_jux.tree() Show component tree (state, history, events)
|
|
179
|
+
_jux.get(0) Get first component
|
|
180
|
+
_jux.get('hero-1') Get component by ID
|
|
181
|
+
|
|
182
|
+
Direct Manipulation:
|
|
183
|
+
const h = _jux.get(0)
|
|
184
|
+
h.state.title = 'New!' Mutate state directly
|
|
185
|
+
h.rollback() Undo last change
|
|
186
|
+
h.rollforward() Redo change
|
|
187
|
+
h.timeline() View full history
|
|
188
|
+
|
|
189
|
+
History:
|
|
190
|
+
_jux.history.stats() Global statistics
|
|
191
|
+
_jux.history.timeline() Complete timeline
|
|
163
192
|
`);
|
|
164
193
|
}
|