|
| 1 | +# EFX-FORMS KNOWLEDGE BASE |
| 2 | + |
| 3 | +**Generated:** 2025-05-18 |
| 4 | +**Commit:** HEAD |
| 5 | +**Branch:** main |
| 6 | + |
| 7 | +## OVERVIEW |
| 8 | + |
| 9 | +Effector-based React form library. TypeScript, flat src/ structure, Playwright CT testing. Dual CJS/ESM build. |
| 10 | + |
| 11 | +## STRUCTURE |
| 12 | + |
| 13 | +``` |
| 14 | +efx-forms/ |
| 15 | +├── src/ # All source code (flat, no subdirs) |
| 16 | +├── src/tests/ # Component tests (Playwright CT) |
| 17 | +├── playwright/ # Test infrastructure |
| 18 | +├── lib/ # Build output (gitignored) |
| 19 | +└── package.json # Main: index.js, Types: index.d.ts |
| 20 | +``` |
| 21 | + |
| 22 | +## WHERE TO LOOK |
| 23 | + |
| 24 | +| Task | Location | Notes | |
| 25 | +|------|----------|-------| |
| 26 | +| Core form logic | src/form.ts | 12.5K lines, main state machine | |
| 27 | +| Components | src/*Component.tsx | FormComponent, FieldComponent, etc. | |
| 28 | +| Hooks | src/use*.ts | 12 hooks: useForm, useField, etc. | |
| 29 | +| Types | src/types.ts | 9.7K lines, all TS interfaces | |
| 30 | +| Validators | src/validators.ts | Built-in validators (required, email, etc.) | |
| 31 | +| Utils | src/utils.ts | truthyFy, shapeFy, flattenObjectKeys | |
| 32 | +| Tests | src/tests/*.spec.tsx | Playwright CT, .spec.tsx naming | |
| 33 | +| Test infra | playwright/ | CT config, fixtures | |
| 34 | + |
| 35 | +## CODE MAP |
| 36 | + |
| 37 | +| Symbol | Type | Location | Role | |
| 38 | +|--------|------|----------|------| |
| 39 | +| Form | Component | src/ | Main form wrapper, context provider | |
| 40 | +| Field | Component | src/ | Field wrapper, validation, state sync | |
| 41 | +| getForm | Function | src/forms.ts | Registry: get form instance by name | |
| 42 | +| useFormInstance | Hook | src/ | Get form from context | |
| 43 | +| $values | Store | src/form.ts | Form values store | |
| 44 | +| $errors | Store | src/form.ts | Form errors store | |
| 45 | +| submit | Effect | src/form.ts | Form submit effect | |
| 46 | +| OnSendParams | Type | src/tests/components/Hooks/ | Test state capture | |
| 47 | + |
| 48 | +## CONVENTIONS |
| 49 | + |
| 50 | +**Naming:** |
| 51 | +- Components: `*Component.tsx` (FormComponent, FieldComponent) |
| 52 | +- Hooks: `use*.ts` (useForm, useField, useFieldData) |
| 53 | +- Tests: `*.spec.tsx` or `*.spec.ts` |
| 54 | + |
| 55 | +**Selectors:** |
| 56 | +- Use `data-test` attributes (NOT data-testid) |
| 57 | +- Centralized in `src/tests/selectors.ts` as `sel` object |
| 58 | + |
| 59 | +**State Capture (tests):** |
| 60 | +- `OnSendParams` type captures form snapshots |
| 61 | +- `SendFormData` helper component with "Set Data" button |
| 62 | +- Pattern: `await sendData.click()` then verify `data.form.values` |
| 63 | + |
| 64 | +**Re-render (tests):** |
| 65 | +- `component.update(<Component ... />)` for prop changes |
| 66 | + |
| 67 | +## ANTI-PATTERNS (THIS PROJECT) |
| 68 | + |
| 69 | +**TypeScript:** |
| 70 | +- ❌ `Record<string, any>` - pervasive throughout codebase |
| 71 | +- ❌ `Store<any>` - constants.ts, useStoreProp hooks |
| 72 | +- ❌ `ComponentType<any>` - FieldComponent props |
| 73 | +- ❌ Index signatures: `[any: string]: any` in types.ts |
| 74 | +- ✅ ESLint: `@typescript-eslint/no-explicit-any` is OFF |
| 75 | + |
| 76 | +**Build:** |
| 77 | +- ❌ Custom `npmize` bash script (not standard npm pack) |
| 78 | +- ❌ No GitHub Actions (uses .sisyphus/ custom CI) |
| 79 | + |
| 80 | +**Structure:** |
| 81 | +- ❌ Flat src/ - no components/, hooks/, utils/ directories |
| 82 | +- ❌ Tests in src/tests/ (excluded via tsconfig) |
| 83 | + |
| 84 | +## UNIQUE STYLES |
| 85 | + |
| 86 | +**Sub-path imports:** |
| 87 | +- `efx-forms/validators` → src/validators.ts |
| 88 | +- `efx-forms/FormDataProvider` → src/FormDataProvider.tsx |
| 89 | +- `efx-forms/utils` → src/utils.ts |
| 90 | +- No `exports` field in package.json - works via direct file paths |
| 91 | + |
| 92 | +**Build output:** |
| 93 | +- `lib/` - CJS (default) |
| 94 | +- `lib/mjs/` - ESM (created by npmize with `{"type": "module"}`) |
| 95 | + |
| 96 | +**Test patterns:** |
| 97 | +- Playwright CT (not Jest/Vitest) |
| 98 | +- No mocking - real components via `mount()` |
| 99 | +- Multi-browser: Chromium + Firefox |
| 100 | + |
| 101 | +## COMMANDS |
| 102 | + |
| 103 | +```bash |
| 104 | +# Build (CJS + ESM) |
| 105 | +npm run build # rm -rf lib/* && tsc && ./npmize |
| 106 | + |
| 107 | +# Publish |
| 108 | +npm run publish-lib # Publish to npm |
| 109 | +npm run publish-beta # Publish with --tag beta |
| 110 | +npm run publish-dryrun # Dry run |
| 111 | + |
| 112 | +# Test |
| 113 | +npm test # Playwright CT |
| 114 | +npm run test:open # Playwright UI mode |
| 115 | + |
| 116 | +# Lint |
| 117 | +npm run lint # ESLint |
| 118 | +``` |
| 119 | + |
| 120 | +## NOTES |
| 121 | + |
| 122 | +**Gotchas:** |
| 123 | +- `lib/` is gitignored - build before publish |
| 124 | +- `noImplicitAny: false` - allows implicit any |
| 125 | +- Tests excluded from TypeScript build |
| 126 | +- Beta releases: `npm run publish-beta` |
| 127 | +- Dual CJS/ESM requires npmize post-build step |
| 128 | + |
| 129 | +**Peer Dependencies:** |
| 130 | +- effector: >=23.0.0 <24.0.0 |
| 131 | +- effector-react: >=23.0.0 <24.0.0 |
| 132 | +- lodash: ^4.17.0 |
| 133 | +- react: >=16.8.0 <20.0.0 |
0 commit comments