@walkeros/explorer 0.3.0 → 0.5.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/AGENT.md ADDED
@@ -0,0 +1,381 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with
4
+ code in this repository.
5
+
6
+ ## Project Overview
7
+
8
+ **@walkeros/explorer** is a React component library for walkerOS documentation
9
+ and exploration. It provides interactive demos and editors with Monaco Editor
10
+ integration for live code editing, event visualization, and mapping
11
+ configuration.
12
+
13
+ ## Code Standards
14
+
15
+ ### Import Statements
16
+
17
+ - **ALWAYS import modules at the top of files** - Never use inline
18
+ `typeof import()` or dynamic `await import()`
19
+ - Use proper type imports: `import type { Monaco } from '@monaco-editor/react';`
20
+
21
+ ## Development Commands
22
+
23
+ ### Essential Commands
24
+
25
+ ```bash
26
+ npm install # Install dependencies
27
+ npm run start # Start Vite dev server (port 3001) - serves examples from /examples
28
+ npm test # Run Jest tests
29
+ npm run dev # Run tests in watch mode
30
+ npm run build # Build package (tsup for JS/TS, SCSS compilation for styles)
31
+ npm run lint # Type check with tsc and lint with ESLint
32
+ npm run preview # Preview Vite build
33
+ npm run clean # Clean build artifacts and dependencies
34
+ ```
35
+
36
+ ### Testing
37
+
38
+ - **Run all tests**: `npm test`
39
+ - **Watch mode**: `npm run dev`
40
+ - **Test files**: Located in `src/__tests__/` and `src/**/__tests__/`
41
+ - Test setup uses `@testing-library/react` with custom mocks for Monaco Editor
42
+
43
+ **CRITICAL: Test Integrity Rules**
44
+
45
+ - **NEVER create fake/mock tests that pretend to validate real functionality**
46
+ - **NEVER use simple string checks to simulate complex behavior** (e.g.,
47
+ checking if a string contains "WalkerOS" to simulate TypeScript type checking)
48
+ - **NEVER gaslight the user by making tests pass through deception**
49
+ - **If real integration testing is difficult or impossible, EXPLICITLY state
50
+ this limitation to the user**
51
+ - **Be honest about what tests actually verify vs what they appear to verify**
52
+ - **When faced with complex integration testing (Monaco, browser APIs, etc.),
53
+ ask the user how to proceed rather than faking it**
54
+ - **If something isn't working and you don't know why, SAY SO IMMEDIATELY - do
55
+ not keep trying random solutions**
56
+ - **Do not claim success based on passing tests unless those tests actually
57
+ validate the user's requirements**
58
+ - **String manipulation tests (contains, regex) are NOT integration tests - they
59
+ only verify string content**
60
+
61
+ Tests must reflect reality. A passing test should mean the feature actually
62
+ works, not that we fooled ourselves.
63
+
64
+ ## When You Don't Know
65
+
66
+ **If you're stuck or something doesn't work:**
67
+
68
+ 1. **Admit it immediately** - "I don't know why this isn't working"
69
+ 2. **Show what you've tried** - Be transparent about the attempts
70
+ 3. **Ask for help** - "Can you check X in the browser console?" or "Should we
71
+ try a different approach?"
72
+ 4. **Do NOT keep iterating on solutions** without user feedback
73
+ 5. **Do NOT claim progress** when the actual requirement still fails
74
+
75
+ It is ALWAYS better to say "I don't know" than to waste the user's time with
76
+ false solutions.
77
+
78
+ ### Building
79
+
80
+ Build creates:
81
+
82
+ - `dist/index.js` (CJS) and `dist/index.mjs` (ESM) - main module
83
+ - `dist/index.d.ts` - TypeScript declarations
84
+ - `dist/styles.css` - compiled SCSS styles
85
+
86
+ The build is configured in `tsup.config.ts` with SCSS compilation via Sass.
87
+
88
+ ## Architecture
89
+
90
+ ### Component Hierarchy (Atomic Design)
91
+
92
+ The codebase strictly follows **Atomic Design** principles:
93
+
94
+ 1. **Atoms** (`src/components/atoms/`): Base UI elements
95
+ - `Box`, `Button`, `ButtonGroup`, `Header`, `Toggle`
96
+ - Mapping primitives: `mapping-string`, `mapping-number`, `mapping-boolean`
97
+ - Form controls: `icon-button`, `mapping-collapsible`, `field-header`
98
+
99
+ 2. **Molecules** (`src/components/molecules/`): Component combinations
100
+ - Navigation: `mapping-tab-bar`, `mapping-tree-sidebar`, `mapping-breadcrumb`
101
+ - Pane views: `mapping-*-pane-view` (rule, entity, consent, condition, etc.)
102
+ - Editors: `auto-select`, `preview`, `mapping-map-field`
103
+
104
+ 3. **Organisms** (`src/components/organisms/`): Complex integrated components
105
+ - `live-code.tsx` - Generic live code execution (input/config/output panels)
106
+ - `code-box.tsx` - Monaco editor with formatting controls
107
+ - `browser-box.tsx` - Multi-tab editor (HTML/CSS/JS) with live preview
108
+ - `collector-box.tsx` - Collector processing display
109
+ - `config-editor/` - Advanced configuration editor system
110
+
111
+ 4. **Demos** (`src/components/demos/`): Ready-to-use complete demos
112
+ - `MappingDemo.tsx` - Three-panel transformation editor
113
+ - `DestinationDemo.tsx` - Destination testing with event processing
114
+ - `PromotionPlayground.tsx` - Promotion event playground
115
+ - `MappingCode.tsx` - Code-based mapping demo
116
+
117
+ ### RJSF Architecture (Critical Pattern)
118
+
119
+ The project uses **React JSON Schema Form (RJSF)** with a **mandatory
120
+ Field/Widget separation pattern**:
121
+
122
+ **Field Layer** (src/components/atoms/\*-field.tsx):
123
+
124
+ - Converts RJSF `FieldProps` → `WidgetProps`
125
+ - Pass-through only (id, value, onChange, schema, uiSchema, rawErrors, disabled,
126
+ readonly)
127
+ - ~20 lines, no UI logic
128
+ - Examples: `mapping-consent-field.tsx`, `mapping-condition-field.tsx`
129
+
130
+ **Widget Layer** (src/components/atoms/\*.tsx):
131
+
132
+ - Full UI implementation using standard building blocks
133
+ - State management (expand/collapse, previous values, show/hide)
134
+ - Form change handling and cleanup
135
+ - External value sync via `useEffect`
136
+ - Uses shared components: `MappingCollapsible`, `MappingFormWrapper`,
137
+ `IconButton`
138
+ - Examples: `mapping-consent.tsx`, `mapping-condition.tsx`
139
+
140
+ **Field/Widget Registry**:
141
+
142
+ - `src/components/forms/field-registry.ts` - Maps field types to Field
143
+ components
144
+ - `src/components/forms/widget-registry.ts` - Maps widget types to Widget
145
+ components
146
+
147
+ **Common Patterns**:
148
+
149
+ - `MappingCollapsible` - Toggle/checkbox UI wrapper
150
+ - `MappingFormWrapper` - Nested form container with RJSF integration
151
+ - `IconButton` - Action buttons (add, delete, toggle)
152
+ - `cleanFormData()` - Remove empty/undefined values before onChange
153
+
154
+ ### State Management
155
+
156
+ **Hooks** (`src/hooks/`):
157
+
158
+ - `useMappingState.ts` - Core mapping configuration state management
159
+ - `useMappingNavigation.ts` - Navigation state (current path, breadcrumbs, tree
160
+ expansion)
161
+ - `useTreeState.ts` - Tree sidebar expand/collapse state
162
+ - `useMonacoHeight.ts` - Dynamic Monaco editor height calculation
163
+
164
+ **Data Flow**:
165
+
166
+ - Props down, events up (standard React unidirectional flow)
167
+ - Controlled components throughout
168
+ - State deduplication via `useEffect` with deep equality checks
169
+ - Schema passing via `ui:options` in RJSF components
170
+
171
+ ### Utilities
172
+
173
+ **Key utilities** (`src/utils/`):
174
+
175
+ - `clean-form-data.ts` - Remove empty values from form data before submission
176
+ - `mapping-path.ts` - Path manipulation for nested mapping structures
177
+ - `consent-scanner.ts` - Scan and detect consent configuration
178
+ - `type-detector.ts` - **Single source of truth** for node type detection
179
+ - `value-display-formatter.ts` - Format values for display
180
+ - `code-normalizer.ts` - Normalize code strings (whitespace, indentation)
181
+ - `generic-tree-builder.ts` - Build tree structures from flat data
182
+ - `config-validator.ts` - Validate configuration objects
183
+ - `schema-validation.ts` - JSON schema validation helpers
184
+
185
+ **Schemas** (`src/schemas/`):
186
+
187
+ - `config-structures/` - Configuration object structures (destination, mapping
188
+ rule)
189
+ - `mapping-rule-schema.ts` - Mapping rule JSON schema
190
+ - `value-config-schema.ts` - Value configuration schema
191
+
192
+ ### Navigation Architecture (CRITICAL)
193
+
194
+ **Single Source of Truth**: ALL navigation MUST use `detectNodeType()` from
195
+ `src/utils/type-detector.ts`
196
+
197
+ **Two Complementary Systems**:
198
+
199
+ 1. **Structure Definitions** (`ConfigStructureDef`) - Navigation metadata
200
+ - Which pane to open for each property
201
+ - Tree children strategy (entity-action, schema-driven, none)
202
+ - Human-readable titles and descriptions
203
+ - Location: `src/schemas/config-structures/`
204
+
205
+ 2. **JSON Schemas** (`RJSFSchema`) - Validation and forms
206
+ - Value validation rules (types, patterns, enums)
207
+ - Form generation (RJSF uses these)
208
+ - Type inference for primitives (enum, boolean, string, number)
209
+
210
+ **Detection Priority** (implemented in `detectNodeType`):
211
+
212
+ ```typescript
213
+ 1. Structure definition (explicit nodeType property)
214
+ 2. Schema detection (enum, boolean, primitives from JSON Schema)
215
+ 3. Value introspection (fallback for complex types)
216
+ ```
217
+
218
+ **Mandatory Rules**:
219
+
220
+ - NEVER hardcode nodeType based on path patterns
221
+ - NEVER hardcode nodeType based on path length
222
+ - NEVER hardcode nodeType based on property names
223
+ - ALWAYS call `detectNodeType(value, path, structure, schemas)`
224
+ - Navigation hooks MUST receive `config`, `structure`, and `schemas` parameters
225
+
226
+ **Examples**:
227
+
228
+ ```typescript
229
+ // ❌ WRONG - Hardcoded logic
230
+ const nodeType = path.length === 2 ? 'rule' : 'valueConfig';
231
+
232
+ // ❌ WRONG - Property name pattern matching
233
+ const nodeType = path[0] === 'consent' ? 'consent' : 'valueConfig';
234
+
235
+ // ✅ CORRECT - Use detectNodeType
236
+ const value = getValueAtPath(config, path);
237
+ const nodeType = detectNodeType(value, path, structure, schemas);
238
+ ```
239
+
240
+ ## Styling Architecture (CRITICAL)
241
+
242
+ **Complete styling documentation:** [STYLE.md](./STYLE.md)
243
+
244
+ ### Quick Reference
245
+
246
+ **Theme Support (Required)**:
247
+
248
+ ```html
249
+ <html data-theme="dark">
250
+ ...
251
+ </html>
252
+ ```
253
+
254
+ **Monaco Editor Themes**:
255
+
256
+ - Dark: `elbTheme-dark` (Prism Palenight)
257
+ - Light: `elbTheme-light` (GitHub)
258
+ - Automatically sync with `data-theme` attribute
259
+
260
+ **SCSS Rules (MANDATORY):**
261
+
262
+ **✅ DO:**
263
+
264
+ - Use ONLY defined CSS variables from `theme/_variables.scss`
265
+ - Follow BEM naming: `.elb-{component}-{element}--{modifier}`
266
+ - Use `calc(var(--font-size-base) - 1px)` for font size variations
267
+ - Create one SCSS file per component in correct directory
268
+ - Import new files alphabetically in `index.scss`
269
+ - Test in both light and dark themes
270
+
271
+ **❌ DON'T:**
272
+
273
+ - Use undefined CSS variables (e.g., `--bg-secondary`, `--font-size-sm`)
274
+ - Use `--font-family-mono` (correct: `--font-mono`)
275
+ - Hardcode colors, spacing, or font sizes
276
+ - Use inline `style` attributes
277
+
278
+ **See [STYLE.md](./STYLE.md) for:**
279
+
280
+ - Complete CSS Variables Reference (all variables with light/dark values)
281
+ - Grid System (height modes: equal, auto, synced - why Grid is complex)
282
+ - Monaco Editor (theming, tokens, local loading, IntelliSense, debugging)
283
+ - SCSS Architecture & Component Checklist
284
+ - Design Rules (when to add variables, color selection, accessibility)
285
+ - Common Tasks & Troubleshooting
286
+
287
+ ## Path Aliases
288
+
289
+ TypeScript path alias configured in `tsconfig.json`:
290
+
291
+ ```typescript
292
+ "@/*" -> "./src/*"
293
+ ```
294
+
295
+ Example usage:
296
+
297
+ ```typescript
298
+ import { useMappingState } from '@/hooks/useMappingState';
299
+ import { cleanFormData } from '@/utils/clean-form-data';
300
+ ```
301
+
302
+ ## Important Files
303
+
304
+ - `src/index.ts` - Public API exports (add new public components here)
305
+ - `tsup.config.ts` - Build configuration (module + styles)
306
+ - `vite.config.ts` - Dev server config (serves examples/)
307
+ - `jest.config.mjs` - Test configuration
308
+ - `src/styles/index.scss` - Main stylesheet entry
309
+ - `src/styles/PANE_STANDARDS.md` - Pane layout standards
310
+
311
+ ## Code Quality Standards
312
+
313
+ ### Clean Refactoring Policy
314
+
315
+ When refactoring or migrating code patterns:
316
+
317
+ - **NO backward compatibility layers** - Complete the migration fully
318
+ - **NO legacy function preservation** - Delete old patterns entirely
319
+ - **NO migration comments** - Code should be self-documenting
320
+ - **NO inline comments** explaining "what changed" or "migration progress"
321
+ - **NO unnecessary additions** - When asked to update existing code, ONLY modify
322
+ what was requested. Do not add new functions, examples, or features unless
323
+ explicitly asked.
324
+ - Write clean, production-ready code as if the old pattern never existed
325
+
326
+ **Example**:
327
+
328
+ ```typescript
329
+ // ❌ WRONG - Legacy compatibility
330
+ function navigateToPath(path: string[]) {
331
+ // TODO: Migrate to detectNodeType
332
+ // Legacy: const nodeType = path.length === 2 ? 'rule' : 'valueConfig';
333
+ const nodeType = detectNodeType(...); // New pattern
334
+ }
335
+
336
+ // ✅ CORRECT - Clean implementation
337
+ function navigateToPath(path: string[]) {
338
+ const value = getValueAtPath(config, path);
339
+ const nodeType = detectNodeType(value, path, structure, schemas);
340
+ openTab(path, nodeType);
341
+ }
342
+ ```
343
+
344
+ **Rationale**: Migration comments and backward compatibility layers confuse
345
+ future developers and create technical debt. Complete the migration in one clean
346
+ step.
347
+
348
+ ## Component Checklist
349
+
350
+ **Before submitting any component:**
351
+
352
+ - [ ] Placed in correct atomic layer (atoms/molecules/organisms/demos)
353
+ - [ ] TypeScript types exported from component file
354
+ - [ ] SCSS file created in correct directory with BEM naming
355
+ (`elb-{component}-*`)
356
+ - [ ] SCSS imported in `index.scss` (alphabetical order)
357
+ - [ ] All CSS variables exist in `theme/_variables.scss`
358
+ - [ ] No hardcoded values (colors, spacing, fonts)
359
+ - [ ] Uses `calc(var(--font-size-base) - Npx)` for size variations
360
+ - [ ] No inline `style` attributes
361
+ - [ ] Light and dark theme tested
362
+ - [ ] Reuses existing components (MappingCollapsible, IconButton, etc.)
363
+ - [ ] RJSF components follow Field/Widget separation pattern
364
+ - [ ] Content components have no root padding (follows Pane Standards)
365
+ - [ ] Navigation uses `detectNodeType()` (no hardcoded path/length logic)
366
+ - [ ] Build succeeds: `npm run build`
367
+ - [ ] Exported from `src/index.ts` if public API
368
+
369
+ ## Integration with walkerOS
370
+
371
+ This library depends on `@walkeros/core`, `@walkeros/collector`, and
372
+ `@walkeros/web-source-browser`. It provides interactive documentation and
373
+ testing components for the walkerOS ecosystem.
374
+
375
+ **Destination helpers** (`src/helpers/destinations.ts`):
376
+
377
+ - `createGtagDestination()` - Google Analytics 4
378
+ - `createFbqDestination()` - Facebook Pixel
379
+ - `createPlausibleDestination()` - Plausible Analytics
380
+
381
+ Use with `DestinationDemo` to create interactive destination testing interfaces.