@walkeros/explorer 0.0.7 → 0.3.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.
@@ -1,396 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>LiveCodeJS Example</title>
7
- <style>
8
- body {
9
- font-family: Arial, sans-serif;
10
- max-width: 1200px;
11
- margin: 0 auto;
12
- padding: 20px;
13
- background: #f5f5f5;
14
- }
15
- .container {
16
- background: white;
17
- padding: 20px;
18
- border-radius: 8px;
19
- box-shadow: 0 2px 10px rgba(0,0,0,0.1);
20
- }
21
- h1 {
22
- color: #333;
23
- margin-bottom: 20px;
24
- }
25
- .controls {
26
- margin: 20px 0;
27
- display: flex;
28
- gap: 10px;
29
- flex-wrap: wrap;
30
- }
31
- button {
32
- padding: 8px 16px;
33
- border: 1px solid #ddd;
34
- border-radius: 4px;
35
- background: white;
36
- cursor: pointer;
37
- }
38
- button:hover {
39
- background: #f0f0f0;
40
- }
41
- .btn-primary {
42
- background: #007bff;
43
- color: white;
44
- border-color: #007bff;
45
- }
46
- .btn-primary:hover {
47
- background: #0056b3;
48
- }
49
- .theme-toggle {
50
- position: absolute;
51
- top: 20px;
52
- right: 20px;
53
- background: none;
54
- border: 2px solid #ddd;
55
- border-radius: 50%;
56
- width: 40px;
57
- height: 40px;
58
- cursor: pointer;
59
- font-size: 18px;
60
- display: flex;
61
- align-items: center;
62
- justify-content: center;
63
- transition: all 0.2s ease;
64
- }
65
- .theme-toggle:hover {
66
- border-color: #007bff;
67
- background: rgba(0, 123, 255, 0.1);
68
- }
69
-
70
- /* Dark theme styles */
71
- html[data-theme='dark'] {
72
- color-scheme: dark;
73
- }
74
- html[data-theme='dark'] body {
75
- background: #1a1a1a;
76
- color: #ffffff;
77
- }
78
- html[data-theme='dark'] .container {
79
- background: #2d2d2d;
80
- border: 1px solid #444;
81
- }
82
- html[data-theme='dark'] h1 {
83
- color: #ffffff;
84
- }
85
- html[data-theme='dark'] button {
86
- background: #444;
87
- color: #ffffff;
88
- border-color: #666;
89
- }
90
- html[data-theme='dark'] button:hover {
91
- background: #555;
92
- }
93
- html[data-theme='dark'] .btn-primary {
94
- background: #007bff;
95
- border-color: #007bff;
96
- }
97
- html[data-theme='dark'] .btn-primary:hover {
98
- background: #0056b3;
99
- }
100
- html[data-theme='dark'] .theme-toggle {
101
- border-color: #666;
102
- color: #ffffff;
103
- }
104
- @media (max-width: 768px) {
105
- .controls {
106
- flex-direction: column;
107
- }
108
- .theme-toggle {
109
- top: 10px;
110
- right: 10px;
111
- width: 35px;
112
- height: 35px;
113
- font-size: 16px;
114
- }
115
- }
116
- </style>
117
- </head>
118
- <body>
119
- <button class="theme-toggle" onclick="toggleTheme()" title="Toggle theme">
120
- <span id="theme-icon">🌙</span>
121
- </button>
122
-
123
- <div class="container">
124
- <h1>⚡ LiveCodeJS Example</h1>
125
- <p>JavaScript evaluation with context injection - perfect for testing walkerOS functions and data processing.</p>
126
-
127
- <div id="livecode-js-container" style="height: 500px; border: 1px solid #ddd; border-radius: 8px; margin: 20px 0;"></div>
128
-
129
- <div class="controls">
130
- <button onclick="loadWalkerExample()">WalkerOS Example</button>
131
- <button onclick="loadMappingExample()">Data Mapping</button>
132
- <button onclick="loadAsyncExample()">Async Operations</button>
133
- <button onclick="loadArrayExample()">Array Processing</button>
134
- <button onclick="clearAll()">Clear All</button>
135
- </div>
136
- </div>
137
-
138
- <script src="../explorer.js"></script>
139
- <script>
140
- let liveCodeJS = null;
141
-
142
- // Mock getMappingValue for demo purposes
143
- function getMappingValue(data, path) {
144
- const keys = path.split('.');
145
- let result = data;
146
-
147
- for (const key of keys) {
148
- if (result === null || result === undefined) {
149
- return undefined;
150
- }
151
-
152
- // Handle array indices
153
- if (Array.isArray(result) && !isNaN(parseInt(key))) {
154
- result = result[parseInt(key)];
155
- } else {
156
- result = result[key];
157
- }
158
- }
159
-
160
- return result;
161
- }
162
-
163
- // Mock walker object for demo
164
- const walker = {
165
- push: (event) => {
166
- console.log('Walker event pushed:', event);
167
- return event;
168
- },
169
-
170
- entity: (type, data) => ({
171
- type,
172
- data,
173
- action: (name, actionData = {}) => ({
174
- entity: type,
175
- action: name,
176
- data: { ...data, ...actionData },
177
- timestamp: Date.now()
178
- })
179
- })
180
- };
181
-
182
- document.addEventListener('DOMContentLoaded', () => {
183
- // Initialize LiveCodeJS
184
- liveCodeJS = WalkerExplorer.createLiveCodeJS('#livecode-js-container', {
185
- initCode: `// Welcome to LiveCodeJS!
186
- // JavaScript evaluation with walkerOS context
187
-
188
- return await getMappingValue(
189
- { arr: ['foo', 'bar', 'baz'] },
190
- 'arr.1'
191
- );`,
192
- context: {
193
- getMappingValue,
194
- walker,
195
- // Add more helper functions
196
- deepClone: (obj) => JSON.parse(JSON.stringify(obj)),
197
- flatten: (arr) => arr.flat(Infinity),
198
- groupBy: (arr, key) => arr.reduce((groups, item) => {
199
- const group = item[key];
200
- groups[group] = groups[group] || [];
201
- groups[group].push(item);
202
- return groups;
203
- }, {})
204
- },
205
- layout: 'horizontal',
206
- showHeader: false,
207
- autoEvaluate: true,
208
- evaluationDelay: 500
209
- });
210
-
211
- window.liveCodeJS = liveCodeJS;
212
- });
213
-
214
- window.loadWalkerExample = () => {
215
- liveCodeJS.setCode(`// WalkerOS Entity and Action Example
216
- const product = walker.entity('product', {
217
- id: 'demo-123',
218
- name: 'Amazing Product',
219
- price: 99.99,
220
- category: 'electronics'
221
- });
222
-
223
- // Create tracking events
224
- const viewEvent = product.action('view');
225
- const cartEvent = product.action('cart', { quantity: 2 });
226
- const purchaseEvent = product.action('purchase', {
227
- transaction_id: 'txn_' + Date.now()
228
- });
229
-
230
- // Push events to walker
231
- walker.push(viewEvent);
232
- walker.push(cartEvent);
233
- walker.push(purchaseEvent);
234
-
235
- // Return summary
236
- ({
237
- product: product.data,
238
- events: [viewEvent, cartEvent, purchaseEvent]
239
- });`);
240
- };
241
-
242
- window.loadMappingExample = () => {
243
- liveCodeJS.setCode(`// Data Mapping Examples
244
- const testData = {
245
- user: {
246
- profile: {
247
- name: 'John Doe',
248
- email: 'john@example.com',
249
- preferences: {
250
- theme: 'dark',
251
- notifications: true
252
- }
253
- },
254
- orders: [
255
- { id: '001', total: 99.99, status: 'completed' },
256
- { id: '002', total: 149.50, status: 'pending' },
257
- { id: '003', total: 75.25, status: 'completed' }
258
- ]
259
- }
260
- };
261
-
262
- // Test different mapping paths
263
- const results = {
264
- userName: await getMappingValue(testData, 'user.profile.name'),
265
- userEmail: await getMappingValue(testData, 'user.profile.email'),
266
- theme: await getMappingValue(testData, 'user.profile.preferences.theme'),
267
- firstOrderId: await getMappingValue(testData, 'user.orders.0.id'),
268
- lastOrderTotal: await getMappingValue(testData, 'user.orders.2.total'),
269
- nonExistent: await getMappingValue(testData, 'user.invalid.path')
270
- };
271
-
272
- // Show results
273
- results;`);
274
- };
275
-
276
- window.loadAsyncExample = () => {
277
- liveCodeJS.setCode(`// Async Operations Example
278
- async function fetchUserData(userId) {
279
- // Simulate API call
280
- await new Promise(resolve => setTimeout(resolve, 500));
281
-
282
- return {
283
- id: userId,
284
- name: 'User ' + userId,
285
- lastSeen: new Date().toISOString(),
286
- preferences: {
287
- language: 'en',
288
- timezone: 'UTC'
289
- }
290
- };
291
- }
292
-
293
- async function processUsers(userIds) {
294
- const users = [];
295
-
296
- for (const id of userIds) {
297
- const user = await fetchUserData(id);
298
- users.push(user);
299
- }
300
-
301
- return users;
302
- }
303
-
304
- // Process multiple users
305
- const userIds = [123, 456, 789];
306
- const users = await processUsers(userIds);
307
-
308
- // Extract specific data
309
- const userNames = users.map(user => user.name);
310
- const preferences = users.map(user => user.preferences);
311
-
312
- // Return results
313
- {
314
- totalUsers: users.length,
315
- userNames,
316
- preferences,
317
- fullData: users
318
- };`);
319
- };
320
-
321
- window.loadArrayExample = () => {
322
- liveCodeJS.setCode(`// Array Processing Examples
323
- const events = [
324
- { type: 'page_view', page: '/home', timestamp: 1640995200000 },
325
- { type: 'click', element: 'button', page: '/home', timestamp: 1640995260000 },
326
- { type: 'page_view', page: '/products', timestamp: 1640995320000 },
327
- { type: 'click', element: 'link', page: '/products', timestamp: 1640995380000 },
328
- { type: 'purchase', product_id: '123', page: '/checkout', timestamp: 1640995440000 }
329
- ];
330
-
331
- // Group events by type
332
- const eventsByType = groupBy(events, 'type');
333
-
334
- // Get unique pages
335
- const uniquePages = [...new Set(events.map(e => e.page))];
336
-
337
- // Filter and transform
338
- const clickEvents = events
339
- .filter(e => e.type === 'click')
340
- .map(e => ({
341
- element: e.element,
342
- page: e.page,
343
- time: new Date(e.timestamp).toLocaleTimeString()
344
- }));
345
-
346
- // Calculate time differences
347
- const timeSpans = events
348
- .slice(1)
349
- .map((event, index) => ({
350
- from: events[index].type,
351
- to: event.type,
352
- duration: event.timestamp - events[index].timestamp
353
- }));
354
-
355
- // Return analysis
356
- {
357
- totalEvents: events.length,
358
- eventsByType,
359
- uniquePages,
360
- clickEvents,
361
- timeSpans,
362
- avgDuration: timeSpans.reduce((sum, span) => sum + span.duration, 0) / timeSpans.length
363
- };`);
364
- };
365
-
366
- window.clearAll = () => {
367
- liveCodeJS.clear();
368
- };
369
-
370
- // Theme toggle functionality
371
- window.toggleTheme = () => {
372
- const html = document.documentElement;
373
- const currentTheme = html.getAttribute('data-theme');
374
- const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
375
-
376
- html.setAttribute('data-theme', newTheme);
377
-
378
- // Update icon
379
- const icon = document.getElementById('theme-icon');
380
- icon.textContent = newTheme === 'dark' ? '☀️' : '🌙';
381
-
382
- // Save preference
383
- localStorage.setItem('theme', newTheme);
384
- };
385
-
386
- // Initialize theme from localStorage or default to light
387
- document.addEventListener('DOMContentLoaded', () => {
388
- const savedTheme = localStorage.getItem('theme') || 'light';
389
- document.documentElement.setAttribute('data-theme', savedTheme);
390
-
391
- const icon = document.getElementById('theme-icon');
392
- icon.textContent = savedTheme === 'dark' ? '☀️' : '🌙';
393
- });
394
- </script>
395
- </body>
396
- </html>