slicejs-web-framework 2.3.1 → 2.3.2

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.
@@ -0,0 +1,258 @@
1
+ /**
2
+ * ContextManager debug panel.
3
+ */
4
+ export default class ContextManagerDebugger extends HTMLElement {
5
+ constructor() {
6
+ super();
7
+ this.isOpen = false;
8
+ this.filterText = '';
9
+ }
10
+
11
+ /**
12
+ * Initialize panel UI.
13
+ * @returns {Promise<void>}
14
+ */
15
+ async init() {
16
+ this.innerHTML = this.renderTemplate();
17
+ slice.stylesManager.registerComponentStyles('ContextManagerDebugger', this.renderStyles());
18
+ this.cacheElements();
19
+ this.bindEvents();
20
+ this.renderList();
21
+ }
22
+
23
+ /**
24
+ * Toggle panel visibility.
25
+ * @returns {void}
26
+ */
27
+ toggle() {
28
+ this.isOpen = !this.isOpen;
29
+ this.container.classList.toggle('active', this.isOpen);
30
+ if (this.isOpen) {
31
+ this.renderList();
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Show panel.
37
+ * @returns {void}
38
+ */
39
+ open() {
40
+ this.isOpen = true;
41
+ this.container.classList.add('active');
42
+ this.renderList();
43
+ }
44
+
45
+ /**
46
+ * Hide panel.
47
+ * @returns {void}
48
+ */
49
+ close() {
50
+ this.isOpen = false;
51
+ this.container.classList.remove('active');
52
+ }
53
+
54
+ cacheElements() {
55
+ this.container = this.querySelector('#context-debugger');
56
+ this.list = this.querySelector('#context-list');
57
+ this.filterInput = this.querySelector('#context-filter');
58
+ this.countLabel = this.querySelector('#context-count');
59
+ this.refreshButton = this.querySelector('#context-refresh');
60
+ this.closeButton = this.querySelector('#context-close');
61
+ }
62
+
63
+ bindEvents() {
64
+ this.refreshButton.addEventListener('click', () => this.renderList());
65
+ this.closeButton.addEventListener('click', () => this.close());
66
+ this.filterInput.addEventListener('input', (event) => {
67
+ this.filterText = event.target.value.trim().toLowerCase();
68
+ this.renderList();
69
+ });
70
+ }
71
+
72
+ renderList() {
73
+ if (!slice?.context?.contexts) {
74
+ this.list.textContent = 'ContextManager not available.';
75
+ this.countLabel.textContent = '0';
76
+ return;
77
+ }
78
+
79
+ const items = [];
80
+ slice.context.contexts.forEach((value, name) => {
81
+ if (this.filterText && !name.toLowerCase().includes(this.filterText)) {
82
+ return;
83
+ }
84
+ const keys = value?.state ? Object.keys(value.state).length : 0;
85
+ items.push({ name, keys, state: value?.state || {} });
86
+ });
87
+
88
+ items.sort((a, b) => a.name.localeCompare(b.name));
89
+
90
+ this.countLabel.textContent = String(items.length);
91
+ this.list.innerHTML = items.length
92
+ ? items.map((item) => {
93
+ const preview = JSON.stringify(item.state, null, 2);
94
+ return `
95
+ <div class="context-row">
96
+ <div class="context-header">
97
+ <div class="context-name">${item.name}</div>
98
+ <div class="context-keys">${item.keys} keys</div>
99
+ </div>
100
+ <pre class="context-preview">${this.escapeHtml(preview)}</pre>
101
+ </div>
102
+ `;
103
+ }).join('')
104
+ : '<div class="empty">No contexts</div>';
105
+ }
106
+
107
+ escapeHtml(value) {
108
+ return value
109
+ .replace(/&/g, '&amp;')
110
+ .replace(/</g, '&lt;')
111
+ .replace(/>/g, '&gt;')
112
+ .replace(/"/g, '&quot;')
113
+ .replace(/'/g, '&#39;');
114
+ }
115
+
116
+ renderTemplate() {
117
+ return `
118
+ <div id="context-debugger">
119
+ <div class="context-header">
120
+ <div class="title">Contexts</div>
121
+ <div class="actions">
122
+ <button id="context-refresh" class="btn">Refresh</button>
123
+ <button id="context-close" class="btn">Close</button>
124
+ </div>
125
+ </div>
126
+ <div class="context-toolbar">
127
+ <input id="context-filter" type="text" placeholder="Filter contexts" />
128
+ <div class="count">Total: <span id="context-count">0</span></div>
129
+ </div>
130
+ <div class="context-list" id="context-list"></div>
131
+ </div>
132
+ `;
133
+ }
134
+
135
+ renderStyles() {
136
+ return `
137
+ #context-debugger {
138
+ position: fixed;
139
+ bottom: 20px;
140
+ left: 20px;
141
+ width: min(380px, calc(100vw - 40px));
142
+ max-height: 60vh;
143
+ background: var(--primary-background-color);
144
+ border: 1px solid var(--medium-color);
145
+ border-radius: 12px;
146
+ box-shadow: 0 16px 32px rgba(0, 0, 0, 0.15);
147
+ display: none;
148
+ flex-direction: column;
149
+ z-index: 10001;
150
+ overflow: hidden;
151
+ }
152
+
153
+ #context-debugger.active {
154
+ display: flex;
155
+ }
156
+
157
+ #context-debugger * {
158
+ box-sizing: border-box;
159
+ }
160
+
161
+ .context-header {
162
+ display: flex;
163
+ justify-content: space-between;
164
+ align-items: center;
165
+ padding: 12px 14px;
166
+ background: var(--tertiary-background-color);
167
+ border-bottom: 1px solid var(--medium-color);
168
+ }
169
+
170
+ .context-header .title {
171
+ font-weight: 600;
172
+ color: var(--font-primary-color);
173
+ }
174
+
175
+ .context-header .actions {
176
+ display: flex;
177
+ gap: 8px;
178
+ }
179
+
180
+ .context-header .btn {
181
+ padding: 6px 10px;
182
+ border-radius: 6px;
183
+ border: 1px solid var(--medium-color);
184
+ background: var(--primary-background-color);
185
+ color: var(--font-primary-color);
186
+ cursor: pointer;
187
+ font-size: 12px;
188
+ }
189
+
190
+ .context-toolbar {
191
+ display: flex;
192
+ gap: 10px;
193
+ align-items: center;
194
+ padding: 10px 12px;
195
+ border-bottom: 1px solid var(--medium-color);
196
+ }
197
+
198
+ .context-toolbar input {
199
+ flex: 1;
200
+ min-width: 0;
201
+ padding: 6px 8px;
202
+ border-radius: 6px;
203
+ border: 1px solid var(--medium-color);
204
+ background: var(--primary-background-color);
205
+ color: var(--font-primary-color);
206
+ }
207
+
208
+ .context-list {
209
+ padding: 10px 12px;
210
+ overflow: auto;
211
+ display: flex;
212
+ flex-direction: column;
213
+ gap: 10px;
214
+ }
215
+
216
+ .context-row {
217
+ border: 1px solid var(--medium-color);
218
+ border-radius: 8px;
219
+ background: var(--tertiary-background-color);
220
+ padding: 10px;
221
+ display: flex;
222
+ flex-direction: column;
223
+ gap: 6px;
224
+ }
225
+
226
+ .context-name {
227
+ font-weight: 600;
228
+ color: var(--font-primary-color);
229
+ }
230
+
231
+ .context-keys {
232
+ font-size: 12px;
233
+ color: var(--font-secondary-color);
234
+ }
235
+
236
+ .context-preview {
237
+ background: var(--primary-background-color);
238
+ border-radius: 6px;
239
+ padding: 8px;
240
+ border: 1px solid var(--medium-color);
241
+ max-height: 180px;
242
+ overflow: auto;
243
+ font-size: 11px;
244
+ font-family: monospace;
245
+ color: var(--font-primary-color);
246
+ }
247
+
248
+ .empty {
249
+ color: var(--font-secondary-color);
250
+ font-size: 12px;
251
+ text-align: center;
252
+ padding: 12px 0;
253
+ }
254
+ `;
255
+ }
256
+ }
257
+
258
+ customElements.define('slice-contextmanager-debugger', ContextManagerDebugger);