@fairfox/polly 0.23.0 → 0.25.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/README.md +55 -1
- package/dist/cli/polly.js +21 -1
- package/dist/cli/polly.js.map +3 -3
- package/dist/src/actions/error.d.ts +26 -0
- package/dist/src/actions/event-delegation.d.ts +48 -0
- package/dist/src/actions/form.d.ts +72 -0
- package/dist/src/actions/index.d.ts +13 -0
- package/dist/src/actions/index.js +525 -0
- package/dist/src/actions/index.js.map +15 -0
- package/dist/src/actions/overlay.d.ts +26 -0
- package/dist/src/actions/registry.d.ts +25 -0
- package/dist/src/actions/store.d.ts +26 -0
- package/dist/src/actions/testing.d.ts +26 -0
- package/dist/src/background/index.js +26 -1
- package/dist/src/background/index.js.map +2 -2
- package/dist/src/background/message-router.js +26 -1
- package/dist/src/background/message-router.js.map +2 -2
- package/dist/src/client/index.js +27 -2
- package/dist/src/client/index.js.map +3 -3
- package/dist/src/elysia/index.js +27 -2
- package/dist/src/elysia/index.js.map +3 -3
- package/dist/src/elysia/peer-repo-plugin.d.ts +1 -1
- package/dist/src/index.js +26 -1
- package/dist/src/index.js.map +2 -2
- package/dist/src/mesh-node.d.ts +89 -0
- package/dist/src/mesh-node.js +619 -0
- package/dist/src/mesh-node.js.map +14 -0
- package/dist/src/mesh.d.ts +10 -0
- package/dist/src/mesh.js +951 -24
- package/dist/src/mesh.js.map +17 -9
- package/dist/src/peer.d.ts +1 -0
- package/dist/src/peer.js +130 -84
- package/dist/src/peer.js.map +11 -10
- package/dist/src/polly-ui/ActionForm.d.ts +21 -0
- package/dist/src/polly-ui/ActionInput.d.ts +41 -0
- package/dist/src/polly-ui/ConfirmDialog.d.ts +24 -0
- package/dist/src/polly-ui/Layout.d.ts +51 -0
- package/dist/src/polly-ui/Modal.d.ts +52 -0
- package/dist/src/polly-ui/OverlayRoot.d.ts +10 -0
- package/dist/src/polly-ui/TextInput.d.ts +31 -0
- package/dist/src/polly-ui/Toast.d.ts +19 -0
- package/dist/src/polly-ui/index.css +319 -0
- package/dist/src/polly-ui/index.d.ts +17 -0
- package/dist/src/polly-ui/index.js +953 -0
- package/dist/src/polly-ui/index.js.map +22 -0
- package/dist/src/polly-ui/internal/focus-trap.d.ts +10 -0
- package/dist/src/polly-ui/internal/input-base.d.ts +18 -0
- package/dist/src/polly-ui/internal/scroll-lock.d.ts +9 -0
- package/dist/src/polly-ui/styles.css +70 -0
- package/dist/src/polly-ui/theme.css +163 -0
- package/dist/src/shared/adapters/index.js +26 -1
- package/dist/src/shared/adapters/index.js.map +2 -2
- package/dist/src/shared/lib/blob-cache.d.ts +58 -0
- package/dist/src/shared/lib/blob-store-impl.d.ts +33 -0
- package/dist/src/shared/lib/blob-store.d.ts +87 -0
- package/dist/src/shared/lib/blob-transfer.d.ts +58 -0
- package/dist/src/shared/lib/context-helpers.js +26 -1
- package/dist/src/shared/lib/context-helpers.js.map +2 -2
- package/dist/src/shared/lib/crdt-specialised.d.ts +1 -1
- package/dist/src/shared/lib/crdt-state.d.ts +1 -1
- package/dist/src/shared/lib/errors.js +26 -1
- package/dist/src/shared/lib/errors.js.map +2 -2
- package/dist/src/shared/lib/keyring-storage.d.ts +57 -0
- package/dist/src/shared/lib/mesh-client.d.ts +91 -0
- package/dist/src/shared/lib/mesh-network-adapter.d.ts +1 -1
- package/dist/src/shared/lib/mesh-signaling-client.d.ts +6 -0
- package/dist/src/shared/lib/mesh-state.d.ts +1 -1
- package/dist/src/shared/lib/mesh-webrtc-adapter.d.ts +20 -1
- package/dist/src/shared/lib/message-bus.js +26 -1
- package/dist/src/shared/lib/message-bus.js.map +2 -2
- package/dist/src/shared/lib/peer-relay-adapter.d.ts +1 -1
- package/dist/src/shared/lib/peer-repo-server.d.ts +1 -1
- package/dist/src/shared/lib/peer-state.d.ts +1 -1
- package/dist/src/shared/lib/resource.js +26 -1
- package/dist/src/shared/lib/resource.js.map +2 -2
- package/dist/src/shared/lib/state.js +26 -1
- package/dist/src/shared/lib/state.js.map +2 -2
- package/dist/src/shared/lib/test-helpers.js +26 -1
- package/dist/src/shared/lib/test-helpers.js.map +2 -2
- package/dist/src/shared/lib/wasm-init.d.ts +17 -0
- package/dist/src/shared/state/app-state.js +26 -1
- package/dist/src/shared/state/app-state.js.map +2 -2
- package/dist/src/shared/types/messages.js +26 -1
- package/dist/src/shared/types/messages.js.map +2 -2
- package/dist/tools/quality/src/cli.js +647 -28
- package/dist/tools/quality/src/cli.js.map +11 -5
- package/dist/tools/quality/src/css/check-layout.d.ts +19 -0
- package/dist/tools/quality/src/css/check-quality.d.ts +24 -0
- package/dist/tools/quality/src/css/check-unused.d.ts +20 -0
- package/dist/tools/quality/src/css/check-vars.d.ts +22 -0
- package/dist/tools/quality/src/css/shared.d.ts +33 -0
- package/dist/tools/quality/src/index.d.ts +37 -0
- package/dist/tools/quality/src/index.js +735 -0
- package/dist/tools/quality/src/index.js.map +16 -0
- package/dist/tools/quality/src/logger.d.ts +26 -0
- package/dist/tools/quality/src/no-as-casting.d.ts +44 -0
- package/dist/tools/test/src/adapters/index.js +26 -1
- package/dist/tools/test/src/adapters/index.js.map +2 -2
- package/dist/tools/test/src/browser/index.js +26 -1
- package/dist/tools/test/src/browser/index.js.map +2 -2
- package/dist/tools/test/src/browser/run.js +238 -0
- package/dist/tools/test/src/browser/run.js.map +11 -0
- package/dist/tools/test/src/index.js +26 -1
- package/dist/tools/test/src/index.js.map +2 -2
- package/dist/tools/test/src/test-utils.js +26 -1
- package/dist/tools/test/src/test-utils.js.map +2 -2
- package/dist/tools/test/src/visual/compare.d.ts +23 -0
- package/dist/tools/test/src/visual/harness.d.ts +53 -0
- package/dist/tools/test/src/visual/index.d.ts +12 -0
- package/dist/tools/test/src/visual/index.js +13968 -0
- package/dist/tools/test/src/visual/index.js.map +41 -0
- package/dist/tools/verify/src/cli.js +3 -3
- package/dist/tools/verify/src/cli.js.map +1 -1
- package/dist/tools/verify/src/config.js +26 -1
- package/dist/tools/verify/src/config.js.map +2 -2
- package/package.json +42 -3
package/README.md
CHANGED
|
@@ -125,6 +125,53 @@ First-time key exchange between devices uses a pairing token displayed as a QR c
|
|
|
125
125
|
|
|
126
126
|
The three tiers coexist in one application — public settings in `$sharedState`, collaborative documents in `$peerState`, private notes in `$meshState`. See [docs/STATE.md](docs/STATE.md) for the full decision tree and [docs/RFC-041-choosing.md](docs/RFC-041-choosing.md) for the design rationale.
|
|
127
127
|
|
|
128
|
+
### Node and Bun are first-class mesh peers
|
|
129
|
+
|
|
130
|
+
Archival cron, LLM proxies, admin CLIs, headless bridges — every always-on participant gets the same state primitives as the browser, without monkey-patching globals or writing bespoke transport wiring. Polly ships a factory that accepts injectable transport and storage:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { createMeshClient, $meshState } from "@fairfox/polly/mesh";
|
|
134
|
+
import { bootstrapCliKeyring, fileKeyringStorage } from "@fairfox/polly/mesh/node";
|
|
135
|
+
import { RTCPeerConnection } from "werift"; // or '@roamhq/wrtc'
|
|
136
|
+
|
|
137
|
+
const storage = fileKeyringStorage("~/.fairfox/keyring.json");
|
|
138
|
+
const keyring = await bootstrapCliKeyring({ storage }); // first run prompts for a pairing token
|
|
139
|
+
|
|
140
|
+
const client = await createMeshClient({
|
|
141
|
+
signaling: { url: "wss://example.com/polly/signaling", peerId: "cli-a1b2" },
|
|
142
|
+
rtc: { RTCPeerConnection },
|
|
143
|
+
keyring,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const doc = $meshState("agenda", { items: [] });
|
|
147
|
+
await doc.loaded;
|
|
148
|
+
await client.close();
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
`createMeshClient` is runtime-agnostic — in a browser the `rtc` option is optional because `globalThis.RTCPeerConnection` exists. The `@fairfox/polly/mesh/node` subpath adds filesystem-backed keyring storage, atomic writes with `0600` permissions, and the stdin bootstrap flow. Neither `werift` nor `@roamhq/wrtc` is bundled; both are declared as optional peer dependencies. Pick the one that fits your deployment — `werift` installs cleanly anywhere (pure TypeScript, no native deps), `@roamhq/wrtc` is faster but needs prebuilt binaries for your platform.
|
|
152
|
+
|
|
153
|
+
### Blob storage for large files
|
|
154
|
+
|
|
155
|
+
CRDT documents shouldn't carry binary payloads — the op history grows with every sync. Polly ships a content-addressed blob store that transfers files peer-to-peer over the same WebRTC channels as `$meshState`, with no server storage. Documents hold lightweight `BlobRef` values; the bytes live in a local IndexedDB cache and move between peers in 64 KiB chunks.
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { createBlobStore, createBlobRef } from "@fairfox/polly/mesh";
|
|
159
|
+
|
|
160
|
+
const blobs = createBlobStore(webrtcAdapter, { encrypt: { key: docKey } });
|
|
161
|
+
|
|
162
|
+
// Sender
|
|
163
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
164
|
+
const ref = await createBlobRef({ bytes, filename: file.name, mimeType: file.type });
|
|
165
|
+
await blobs.put(ref, bytes); // caches locally, announces to peers
|
|
166
|
+
doc.value = { ...doc.value, attachment: ref };
|
|
167
|
+
|
|
168
|
+
// Receiver (on any connected peer)
|
|
169
|
+
const received = await blobs.get(ref.hash); // fetches from peers, verifies hash
|
|
170
|
+
const url = await blobs.url(ref.hash); // object URL for <img src>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
SHA-256 content addressing deduplicates across peers and documents. Encryption is optional — when configured, the sender encrypts once (XSalsa20-Poly1305) and chunks the ciphertext; the receiver reassembles, decrypts, and verifies the plaintext hash against the `BlobRef`. See [docs/RFC-042-blob-sync.md](docs/RFC-042-blob-sync.md) for the design.
|
|
174
|
+
|
|
128
175
|
## Verification that plugs in
|
|
129
176
|
|
|
130
177
|
A popup and a background script both write to the same state. A content script reads it mid-update. Tests miss these bugs because they depend on timing.
|
|
@@ -243,13 +290,20 @@ polly format Format your code
|
|
|
243
290
|
polly test Run tests
|
|
244
291
|
polly verify Run formal verification
|
|
245
292
|
polly visualize Generate architecture diagrams (Structurizr DSL)
|
|
293
|
+
polly quality Run conformance checks (no-as-casting)
|
|
246
294
|
```
|
|
247
295
|
|
|
248
296
|
## Quality tooling
|
|
249
297
|
|
|
250
298
|
Polly ships conformance checks and a browser test harness that consuming applications can adopt directly.
|
|
251
299
|
|
|
252
|
-
**No-as-casting check.** Bans TypeScript `as` type assertions codebase-wide (only `as const` and the explicit escape hatch `as unknown as` are allowed). Violations include pattern-specific fix advice.
|
|
300
|
+
**No-as-casting check.** Bans TypeScript `as` type assertions codebase-wide (only `as const` and the explicit escape hatch `as unknown as` are allowed). Violations include pattern-specific fix advice. Run as a CLI:
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
polly quality [--root <dir>] [--exclude-packages <names>] [--exclude-files <names>]
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Or import it programmatically for integration into custom check scripts:
|
|
253
307
|
|
|
254
308
|
```typescript
|
|
255
309
|
import { checkNoAsCasting } from "@fairfox/polly/quality";
|
package/dist/cli/polly.js
CHANGED
|
@@ -155,6 +155,22 @@ async function test() {
|
|
|
155
155
|
throw new Error(`Tests failed with exit code ${exitCode}`);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
+
async function testBrowser() {
|
|
159
|
+
const bundledCli = `${__dirname2}/../tools/test/src/browser/run.js`;
|
|
160
|
+
const monorepoCli = `${__dirname2}/../tools/test/src/browser/run.ts`;
|
|
161
|
+
const browserCli = await Bun.file(bundledCli).exists() ? bundledCli : monorepoCli;
|
|
162
|
+
const proc = Bun.spawn(["bun", browserCli, ...commandArgs], {
|
|
163
|
+
cwd,
|
|
164
|
+
stdout: "inherit",
|
|
165
|
+
stderr: "inherit",
|
|
166
|
+
stdin: "inherit",
|
|
167
|
+
env: process.env
|
|
168
|
+
});
|
|
169
|
+
const exitCode = await proc.exited;
|
|
170
|
+
if (exitCode !== 0) {
|
|
171
|
+
throw new Error(`Browser tests failed with exit code ${exitCode}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
158
174
|
async function check() {
|
|
159
175
|
const checks = [
|
|
160
176
|
{ name: "Type checking", fn: typecheck },
|
|
@@ -205,6 +221,7 @@ Usage:
|
|
|
205
221
|
polly lint [--fix] Lint your code
|
|
206
222
|
polly format Format your code
|
|
207
223
|
polly test [args] Run tests
|
|
224
|
+
polly test:browser [dir] Run *.browser.{ts,tsx} in Puppeteer
|
|
208
225
|
polly verify [args] Run formal verification
|
|
209
226
|
polly visualize [args] Generate architecture diagrams
|
|
210
227
|
polly quality [args] Run quality conformance checks
|
|
@@ -243,6 +260,9 @@ async function main() {
|
|
|
243
260
|
case "test":
|
|
244
261
|
await test();
|
|
245
262
|
break;
|
|
263
|
+
case "test:browser":
|
|
264
|
+
await testBrowser();
|
|
265
|
+
break;
|
|
246
266
|
case "verify":
|
|
247
267
|
await verify();
|
|
248
268
|
break;
|
|
@@ -272,4 +292,4 @@ async function main() {
|
|
|
272
292
|
}
|
|
273
293
|
main();
|
|
274
294
|
|
|
275
|
-
//# debugId=
|
|
295
|
+
//# debugId=962EF67B5CBBAF2264756E2164756E21
|
package/dist/cli/polly.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../cli/polly.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"#!/usr/bin/env bun\n/**\n * Polly CLI\n *\n * Command-line tool for building multi-execution-context applications\n * with reactive state and cross-context messaging.\n *\n * Supports: Chrome extensions, PWAs, Node/Bun/Deno apps with workers\n *\n * Usage:\n * polly init [name] [--type=TYPE] Create a new project\n * polly check Run all checks (typecheck, lint, test, build)\n * polly build [options] Build the project\n * polly dev Build with watch mode\n * polly typecheck Type check your code\n * polly lint [--fix] Lint your code\n * polly format Format your code\n * polly test [args] Run tests (requires bun test)\n * polly verify [args] Run formal verification\n * polly visualize [args] Generate architecture diagrams\n * polly quality [args] Run quality conformance checks\n * polly help Show help\n *\n * Project Types (init --type):\n * extension Chrome/Firefox extension (default)\n * pwa Progressive Web App with workers\n * websocket WebSocket server application\n * generic Generic TypeScript project\n *\n * Options:\n * --prod Build for production (minified)\n * --config <path> Path to config file (default: polly.config.ts)\n * --fix Auto-fix lint/format issues\n * --type=TYPE Project type for init command\n */\n\n// Use Bun built-ins instead of Node.js APIs\nconst __dirname = import.meta.dir;\n\nconst command = process.argv[2];\nconst commandArgs = process.argv.slice(3);\nconst cwd = process.cwd();\n\n// Parse arguments\nconst args = {\n prod: process.argv.includes(\"--prod\"),\n config: process.argv.includes(\"--config\")\n ? process.argv[process.argv.indexOf(\"--config\") + 1]\n : undefined,\n};\n\n/**\n * Load user's configuration\n */\nasync function loadConfig() {\n const configPaths = [\n args.config,\n `${cwd}/polly.config.ts`,\n `${cwd}/polly.config.js`,\n `${cwd}/polly.config.mjs`,\n ].filter(Boolean) as string[];\n\n for (const configPath of configPaths) {\n // Use Bun.file().exists() instead of existsSync\n if (await Bun.file(configPath).exists()) {\n try {\n const config = await import(configPath);\n return config.default || config;\n } catch (error) {\n console.log(`❌ Failed to load config: ${configPath}`);\n throw error;\n }\n }\n }\n return {\n srcDir: \"src\",\n distDir: \"dist\",\n manifest: \"manifest.json\",\n };\n}\n\n/**\n * Build command - build the extension\n */\nasync function build() {\n const config = await loadConfig();\n\n // Check if bundled (published) or in monorepo\n const bundledScript = `${__dirname}/../scripts/build-extension.js`;\n const monorepoScript = `${__dirname}/../scripts/build-extension.ts`;\n const buildScriptPath = (await Bun.file(bundledScript).exists()) ? bundledScript : monorepoScript;\n\n // Pass config via environment\n process.env[\"WEB_EXT_SRC\"] = `${cwd}/${config.srcDir || \"src\"}`;\n process.env[\"WEB_EXT_DIST\"] = `${cwd}/${config.distDir || \"dist\"}`;\n process.env[\"WEB_EXT_MANIFEST\"] = `${cwd}/${config.manifest || \"manifest.json\"}`;\n process.env[\"WEB_EXT_CWD\"] = cwd;\n process.env[\"WEB_EXT_PROD\"] = args.prod ? \"true\" : \"false\";\n\n // Run build\n const proc = Bun.spawn([\"bun\", buildScriptPath], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n process.exit(exitCode);\n }\n}\n\n/**\n * Dev command - build with watch mode\n */\nasync function dev() {\n await build();\n}\n\n/**\n * Verify command - delegate to @fairfox/web-ext-verify\n */\nasync function verify() {\n // Check if bundled (published) or in monorepo\n const bundledCli = `${__dirname}/../tools/verify/src/cli.js`;\n const monorepoCli = `${__dirname}/../tools/verify/src/cli.ts`;\n const verifyCli = (await Bun.file(bundledCli).exists()) ? bundledCli : monorepoCli;\n\n const proc = Bun.spawn([\"bun\", verifyCli, ...commandArgs], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n stdin: \"inherit\",\n env: process.env,\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Verification failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Visualize command - delegate to @fairfox/polly-visualize\n */\nasync function visualize() {\n // Check if bundled (published) or in monorepo\n const bundledCli = `${__dirname}/../tools/visualize/src/cli.js`;\n const monorepoCli = `${__dirname}/../tools/visualize/src/cli.ts`;\n const visualizeCli = (await Bun.file(bundledCli).exists()) ? bundledCli : monorepoCli;\n\n const proc = Bun.spawn([\"bun\", visualizeCli, ...commandArgs], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n stdin: \"inherit\",\n env: process.env,\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Visualization failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Quality command - delegate to @fairfox/polly-quality\n */\nasync function quality() {\n const bundledCli = `${__dirname}/../tools/quality/src/cli.js`;\n const monorepoCli = `${__dirname}/../tools/quality/src/cli.ts`;\n const qualityCli = (await Bun.file(bundledCli).exists()) ? bundledCli : monorepoCli;\n\n const proc = Bun.spawn([\"bun\", qualityCli, ...commandArgs], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n stdin: \"inherit\",\n env: process.env,\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Quality checks failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Typecheck command - run TypeScript type checking\n */\nasync function typecheck() {\n const proc = Bun.spawn([\"bunx\", \"tsc\", \"--noEmit\"], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Type checking failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Lint command - run Biome linter\n */\nasync function lint() {\n const fix = commandArgs.includes(\"--fix\");\n const lintArgs = fix ? [\"check\", \"--write\", \".\"] : [\"check\", \".\"];\n\n const proc = Bun.spawn([\"bunx\", \"@biomejs/biome\", ...lintArgs], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Linting failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Format command - run Biome formatter\n */\nasync function format() {\n const proc = Bun.spawn([\"bunx\", \"@biomejs/biome\", \"format\", \"--write\", \".\"], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Formatting failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Test command - delegate to @fairfox/polly-test\n */\nasync function test() {\n // Check if bundled (published) or in monorepo\n const bundledCli = `${__dirname}/../tools/test/src/cli.js`;\n const monorepoCli = `${__dirname}/../tools/test/src/cli.ts`;\n const testCli = (await Bun.file(bundledCli).exists()) ? bundledCli : monorepoCli;\n\n const proc = Bun.spawn([\"bun\", testCli, ...commandArgs], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n stdin: \"inherit\",\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Tests failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Check command - run all quality checks in sequence\n */\nasync function check() {\n const checks = [\n { name: \"Type checking\", fn: typecheck },\n { name: \"Linting\", fn: lint },\n { name: \"Testing\", fn: test },\n { name: \"Building\", fn: build },\n { name: \"Verification\", fn: verify, optional: true },\n { name: \"Visualization\", fn: visualize, optional: true },\n ];\n\n for (const { name, fn, optional } of checks) {\n try {\n await fn();\n } catch (_error) {\n if (optional) {\n continue;\n }\n console.log(`\\n\\x1b[31m✗ ${name} failed\\x1b[0m\\n`);\n process.exit(1);\n }\n }\n}\n\n/**\n * Init command - delegate to @fairfox/polly-init\n */\nasync function init() {\n // Check if bundled (published) or in monorepo\n const bundledCli = `${__dirname}/../tools/init/src/cli.js`;\n const monorepoCli = `${__dirname}/../tools/init/src/cli.ts`;\n const initCli = (await Bun.file(bundledCli).exists()) ? bundledCli : monorepoCli;\n\n const proc = Bun.spawn([\"bun\", initCli, ...commandArgs], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n stdin: \"inherit\",\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Initialization failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Help command — prints usage from the docstring at the top of this file\n */\nfunction help() {\n console.log(`Polly CLI — multi-execution-context framework\n\nUsage:\n polly init [name] [--type=TYPE] Create a new project\n polly check Run all checks (typecheck, lint, test, build)\n polly build [options] Build the project\n polly dev Build with watch mode\n polly typecheck Type check your code\n polly lint [--fix] Lint your code\n polly format Format your code\n polly test [args] Run tests\n polly verify [args] Run formal verification\n polly visualize [args] Generate architecture diagrams\n polly quality [args] Run quality conformance checks\n polly help Show this help\n\nOptions:\n --prod Build for production (minified)\n --config <path> Path to config file (default: polly.config.ts)\n --fix Auto-fix lint/format issues\n --type=TYPE Project type for init command (pwa, extension, websocket, generic)`);\n}\n\n/**\n * Main entry point\n */\nasync function main() {\n try {\n switch (command) {\n case \"init\":\n await init();\n break;\n case \"check\":\n await check();\n break;\n case \"build\":\n await build();\n break;\n case \"dev\":\n await dev();\n break;\n case \"typecheck\":\n await typecheck();\n break;\n case \"lint\":\n await lint();\n break;\n case \"format\":\n await format();\n break;\n case \"test\":\n await test();\n break;\n case \"verify\":\n await verify();\n break;\n case \"visualize\":\n await visualize();\n break;\n case \"quality\":\n await quality();\n break;\n case \"help\":\n case \"--help\":\n case \"-h\":\n case undefined:\n help();\n break;\n default:\n console.log(`❌ Unknown command: ${command}\\n`);\n help();\n process.exit(1);\n }\n } catch (error) {\n console.log(\"\\n❌ Command failed:\", error);\n process.exit(1);\n }\n}\n\nmain();\n"
|
|
5
|
+
"#!/usr/bin/env bun\n/**\n * Polly CLI\n *\n * Command-line tool for building multi-execution-context applications\n * with reactive state and cross-context messaging.\n *\n * Supports: Chrome extensions, PWAs, Node/Bun/Deno apps with workers\n *\n * Usage:\n * polly init [name] [--type=TYPE] Create a new project\n * polly check Run all checks (typecheck, lint, test, build)\n * polly build [options] Build the project\n * polly dev Build with watch mode\n * polly typecheck Type check your code\n * polly lint [--fix] Lint your code\n * polly format Format your code\n * polly test [args] Run tests (requires bun test)\n * polly test:browser [dir] Run *.browser.{ts,tsx} in Puppeteer\n * polly verify [args] Run formal verification\n * polly visualize [args] Generate architecture diagrams\n * polly quality [args] Run quality conformance checks\n * polly help Show help\n *\n * Project Types (init --type):\n * extension Chrome/Firefox extension (default)\n * pwa Progressive Web App with workers\n * websocket WebSocket server application\n * generic Generic TypeScript project\n *\n * Options:\n * --prod Build for production (minified)\n * --config <path> Path to config file (default: polly.config.ts)\n * --fix Auto-fix lint/format issues\n * --type=TYPE Project type for init command\n */\n\n// Use Bun built-ins instead of Node.js APIs\nconst __dirname = import.meta.dir;\n\nconst command = process.argv[2];\nconst commandArgs = process.argv.slice(3);\nconst cwd = process.cwd();\n\n// Parse arguments\nconst args = {\n prod: process.argv.includes(\"--prod\"),\n config: process.argv.includes(\"--config\")\n ? process.argv[process.argv.indexOf(\"--config\") + 1]\n : undefined,\n};\n\n/**\n * Load user's configuration\n */\nasync function loadConfig() {\n const configPaths = [\n args.config,\n `${cwd}/polly.config.ts`,\n `${cwd}/polly.config.js`,\n `${cwd}/polly.config.mjs`,\n ].filter(Boolean) as string[];\n\n for (const configPath of configPaths) {\n // Use Bun.file().exists() instead of existsSync\n if (await Bun.file(configPath).exists()) {\n try {\n const config = await import(configPath);\n return config.default || config;\n } catch (error) {\n console.log(`❌ Failed to load config: ${configPath}`);\n throw error;\n }\n }\n }\n return {\n srcDir: \"src\",\n distDir: \"dist\",\n manifest: \"manifest.json\",\n };\n}\n\n/**\n * Build command - build the extension\n */\nasync function build() {\n const config = await loadConfig();\n\n // Check if bundled (published) or in monorepo\n const bundledScript = `${__dirname}/../scripts/build-extension.js`;\n const monorepoScript = `${__dirname}/../scripts/build-extension.ts`;\n const buildScriptPath = (await Bun.file(bundledScript).exists()) ? bundledScript : monorepoScript;\n\n // Pass config via environment\n process.env[\"WEB_EXT_SRC\"] = `${cwd}/${config.srcDir || \"src\"}`;\n process.env[\"WEB_EXT_DIST\"] = `${cwd}/${config.distDir || \"dist\"}`;\n process.env[\"WEB_EXT_MANIFEST\"] = `${cwd}/${config.manifest || \"manifest.json\"}`;\n process.env[\"WEB_EXT_CWD\"] = cwd;\n process.env[\"WEB_EXT_PROD\"] = args.prod ? \"true\" : \"false\";\n\n // Run build\n const proc = Bun.spawn([\"bun\", buildScriptPath], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n process.exit(exitCode);\n }\n}\n\n/**\n * Dev command - build with watch mode\n */\nasync function dev() {\n await build();\n}\n\n/**\n * Verify command - delegate to @fairfox/web-ext-verify\n */\nasync function verify() {\n // Check if bundled (published) or in monorepo\n const bundledCli = `${__dirname}/../tools/verify/src/cli.js`;\n const monorepoCli = `${__dirname}/../tools/verify/src/cli.ts`;\n const verifyCli = (await Bun.file(bundledCli).exists()) ? bundledCli : monorepoCli;\n\n const proc = Bun.spawn([\"bun\", verifyCli, ...commandArgs], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n stdin: \"inherit\",\n env: process.env,\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Verification failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Visualize command - delegate to @fairfox/polly-visualize\n */\nasync function visualize() {\n // Check if bundled (published) or in monorepo\n const bundledCli = `${__dirname}/../tools/visualize/src/cli.js`;\n const monorepoCli = `${__dirname}/../tools/visualize/src/cli.ts`;\n const visualizeCli = (await Bun.file(bundledCli).exists()) ? bundledCli : monorepoCli;\n\n const proc = Bun.spawn([\"bun\", visualizeCli, ...commandArgs], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n stdin: \"inherit\",\n env: process.env,\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Visualization failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Quality command - delegate to @fairfox/polly-quality\n */\nasync function quality() {\n const bundledCli = `${__dirname}/../tools/quality/src/cli.js`;\n const monorepoCli = `${__dirname}/../tools/quality/src/cli.ts`;\n const qualityCli = (await Bun.file(bundledCli).exists()) ? bundledCli : monorepoCli;\n\n const proc = Bun.spawn([\"bun\", qualityCli, ...commandArgs], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n stdin: \"inherit\",\n env: process.env,\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Quality checks failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Typecheck command - run TypeScript type checking\n */\nasync function typecheck() {\n const proc = Bun.spawn([\"bunx\", \"tsc\", \"--noEmit\"], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Type checking failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Lint command - run Biome linter\n */\nasync function lint() {\n const fix = commandArgs.includes(\"--fix\");\n const lintArgs = fix ? [\"check\", \"--write\", \".\"] : [\"check\", \".\"];\n\n const proc = Bun.spawn([\"bunx\", \"@biomejs/biome\", ...lintArgs], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Linting failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Format command - run Biome formatter\n */\nasync function format() {\n const proc = Bun.spawn([\"bunx\", \"@biomejs/biome\", \"format\", \"--write\", \".\"], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Formatting failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Test command - delegate to @fairfox/polly-test\n */\nasync function test() {\n // Check if bundled (published) or in monorepo\n const bundledCli = `${__dirname}/../tools/test/src/cli.js`;\n const monorepoCli = `${__dirname}/../tools/test/src/cli.ts`;\n const testCli = (await Bun.file(bundledCli).exists()) ? bundledCli : monorepoCli;\n\n const proc = Bun.spawn([\"bun\", testCli, ...commandArgs], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n stdin: \"inherit\",\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Tests failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Browser test command — bundles *.browser.{ts,tsx} files, serves them,\n * opens a Puppeteer page, and collects results. Consumers use this to\n * run tests written with @fairfox/polly/test/browser in a real browser.\n */\nasync function testBrowser() {\n const bundledCli = `${__dirname}/../tools/test/src/browser/run.js`;\n const monorepoCli = `${__dirname}/../tools/test/src/browser/run.ts`;\n const browserCli = (await Bun.file(bundledCli).exists()) ? bundledCli : monorepoCli;\n\n const proc = Bun.spawn([\"bun\", browserCli, ...commandArgs], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n stdin: \"inherit\",\n env: process.env,\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Browser tests failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Check command - run all quality checks in sequence\n */\nasync function check() {\n const checks = [\n { name: \"Type checking\", fn: typecheck },\n { name: \"Linting\", fn: lint },\n { name: \"Testing\", fn: test },\n { name: \"Building\", fn: build },\n { name: \"Verification\", fn: verify, optional: true },\n { name: \"Visualization\", fn: visualize, optional: true },\n ];\n\n for (const { name, fn, optional } of checks) {\n try {\n await fn();\n } catch (_error) {\n if (optional) {\n continue;\n }\n console.log(`\\n\\x1b[31m✗ ${name} failed\\x1b[0m\\n`);\n process.exit(1);\n }\n }\n}\n\n/**\n * Init command - delegate to @fairfox/polly-init\n */\nasync function init() {\n // Check if bundled (published) or in monorepo\n const bundledCli = `${__dirname}/../tools/init/src/cli.js`;\n const monorepoCli = `${__dirname}/../tools/init/src/cli.ts`;\n const initCli = (await Bun.file(bundledCli).exists()) ? bundledCli : monorepoCli;\n\n const proc = Bun.spawn([\"bun\", initCli, ...commandArgs], {\n cwd,\n stdout: \"inherit\",\n stderr: \"inherit\",\n stdin: \"inherit\",\n });\n\n const exitCode = await proc.exited;\n if (exitCode !== 0) {\n throw new Error(`Initialization failed with exit code ${exitCode}`);\n }\n}\n\n/**\n * Help command — prints usage from the docstring at the top of this file\n */\nfunction help() {\n console.log(`Polly CLI — multi-execution-context framework\n\nUsage:\n polly init [name] [--type=TYPE] Create a new project\n polly check Run all checks (typecheck, lint, test, build)\n polly build [options] Build the project\n polly dev Build with watch mode\n polly typecheck Type check your code\n polly lint [--fix] Lint your code\n polly format Format your code\n polly test [args] Run tests\n polly test:browser [dir] Run *.browser.{ts,tsx} in Puppeteer\n polly verify [args] Run formal verification\n polly visualize [args] Generate architecture diagrams\n polly quality [args] Run quality conformance checks\n polly help Show this help\n\nOptions:\n --prod Build for production (minified)\n --config <path> Path to config file (default: polly.config.ts)\n --fix Auto-fix lint/format issues\n --type=TYPE Project type for init command (pwa, extension, websocket, generic)`);\n}\n\n/**\n * Main entry point\n */\nasync function main() {\n try {\n switch (command) {\n case \"init\":\n await init();\n break;\n case \"check\":\n await check();\n break;\n case \"build\":\n await build();\n break;\n case \"dev\":\n await dev();\n break;\n case \"typecheck\":\n await typecheck();\n break;\n case \"lint\":\n await lint();\n break;\n case \"format\":\n await format();\n break;\n case \"test\":\n await test();\n break;\n case \"test:browser\":\n await testBrowser();\n break;\n case \"verify\":\n await verify();\n break;\n case \"visualize\":\n await visualize();\n break;\n case \"quality\":\n await quality();\n break;\n case \"help\":\n case \"--help\":\n case \"-h\":\n case undefined:\n help();\n break;\n default:\n console.log(`❌ Unknown command: ${command}\\n`);\n help();\n process.exit(1);\n }\n } catch (error) {\n console.log(\"\\n❌ Command failed:\", error);\n process.exit(1);\n }\n}\n\nmain();\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;AAsCA,IAAM,aAAY,YAAY;AAE9B,IAAM,UAAU,QAAQ,KAAK;AAC7B,IAAM,cAAc,QAAQ,KAAK,MAAM,CAAC;AACxC,IAAM,MAAM,QAAQ,IAAI;AAGxB,IAAM,OAAO;AAAA,EACX,MAAM,QAAQ,KAAK,SAAS,QAAQ;AAAA,EACpC,QAAQ,QAAQ,KAAK,SAAS,UAAU,IACpC,QAAQ,KAAK,QAAQ,KAAK,QAAQ,UAAU,IAAI,KAChD;AACN;AAKA,eAAe,UAAU,GAAG;AAAA,EAC1B,MAAM,cAAc;AAAA,IAClB,KAAK;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACL,EAAE,OAAO,OAAO;AAAA,EAEhB,WAAW,cAAc,aAAa;AAAA,IAEpC,IAAI,MAAM,IAAI,KAAK,UAAU,EAAE,OAAO,GAAG;AAAA,MACvC,IAAI;AAAA,QACF,MAAM,SAAS,MAAa;AAAA,QAC5B,OAAO,OAAO,WAAW;AAAA,QACzB,OAAO,OAAO;AAAA,QACd,QAAQ,IAAI,iCAA2B,YAAY;AAAA,QACnD,MAAM;AAAA;AAAA,IAEV;AAAA,EACF;AAAA,EACA,OAAO;AAAA,IACL,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,UAAU;AAAA,E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,yBAAsB,KAAK;AAAA,IACvC,QAAQ,KAAK,CAAC;AAAA;AAAA;AAIlB,KAAK;",
|
|
8
|
+
"debugId": "962EF67B5CBBAF2264756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global error surface for action handlers.
|
|
3
|
+
*
|
|
4
|
+
* Actions that fail set the errorState signal via `submitError`; a `<Toast>`
|
|
5
|
+
* component consumes that signal and renders a dismissable message. Handlers
|
|
6
|
+
* that catch expected failures (validation, quota) may call `setError` directly.
|
|
7
|
+
*/
|
|
8
|
+
export type ErrorSeverity = "error" | "warning" | "info";
|
|
9
|
+
export type ErrorEntry = {
|
|
10
|
+
id: string;
|
|
11
|
+
message: string;
|
|
12
|
+
severity: ErrorSeverity;
|
|
13
|
+
action?: string;
|
|
14
|
+
createdAt: number;
|
|
15
|
+
};
|
|
16
|
+
export declare const errorState: import("@preact/signals-core").Signal<ErrorEntry[]>;
|
|
17
|
+
export declare function setError(message: string, opts?: {
|
|
18
|
+
severity?: ErrorSeverity;
|
|
19
|
+
action?: string;
|
|
20
|
+
}): string;
|
|
21
|
+
export declare function clearError(id?: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Convenience wrapper for an action's catch block.
|
|
24
|
+
* Logs the action name + error and surfaces a user-visible message.
|
|
25
|
+
*/
|
|
26
|
+
export declare function submitError(action: string, err: unknown): string;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event delegation core.
|
|
3
|
+
*
|
|
4
|
+
* One document listener dispatches `data-action` events to typed handlers.
|
|
5
|
+
* Walks up the DOM with `closest('[data-action]')`, parses `data-action-*`
|
|
6
|
+
* attributes into a camelCase object, and hands the dispatch to the caller.
|
|
7
|
+
*
|
|
8
|
+
* Forms are skipped on click — a `<form data-action="...">` responds to
|
|
9
|
+
* submit only, so clicks on form children don't bubble into its action.
|
|
10
|
+
* Escape closes the topmost overlay by calling the overlay registry.
|
|
11
|
+
* Enter/Space on non-interactive elements with `data-action` fire the
|
|
12
|
+
* action (Space is prevented to stop page scroll). Click outside any
|
|
13
|
+
* `[data-overlay-id]` element also pops the top overlay.
|
|
14
|
+
*/
|
|
15
|
+
/** Elements that natively fire click on Enter/Space. */
|
|
16
|
+
export declare const INTERACTIVE_TAGS: Set<string>;
|
|
17
|
+
/** Event types that may trigger a data-action dispatch. */
|
|
18
|
+
export declare const ACTION_EVENT_TYPES: Set<string>;
|
|
19
|
+
/** Parsed action dispatch — what the runtime resolves before invoking a handler. */
|
|
20
|
+
export type ActionDispatch = {
|
|
21
|
+
action: string;
|
|
22
|
+
element: HTMLElement;
|
|
23
|
+
event: Event;
|
|
24
|
+
data: Record<string, string>;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Parse `data-action-*` attributes into camelCase key-value pairs.
|
|
28
|
+
*
|
|
29
|
+
* `data-action-text-set-id="42"` becomes `{ textSetId: "42" }`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseActionData(element: HTMLElement): Record<string, string>;
|
|
32
|
+
/**
|
|
33
|
+
* Close the topmost overlay by dispatching `overlay:close` on its element.
|
|
34
|
+
* Overlays mark themselves with `data-overlay-id`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function closeTopOverlay(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Resolve a DOM event to an ActionDispatch, or null if no data-action matches.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveAction(event: Event): ActionDispatch | null;
|
|
41
|
+
/**
|
|
42
|
+
* Install document-level listeners for the delegation system.
|
|
43
|
+
* Returns a cleanup function that removes every listener it installed.
|
|
44
|
+
*/
|
|
45
|
+
export declare function installEventDelegation(onDispatch: (dispatch: ActionDispatch) => void, options?: {
|
|
46
|
+
onEscape?: () => void;
|
|
47
|
+
onOutsideOverlayClick?: () => void;
|
|
48
|
+
}): () => void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form primitive.
|
|
3
|
+
*
|
|
4
|
+
* `createForm` returns a typed form store: per-field signals, an aggregated
|
|
5
|
+
* values signal, open/close/submit methods, and three auto-registered action
|
|
6
|
+
* handlers (`{name}:open`, `{name}:close`, `{name}:submit`) that callers spread
|
|
7
|
+
* into their global action registry.
|
|
8
|
+
*
|
|
9
|
+
* Lifecycle:
|
|
10
|
+
* open → resets fields to initialValues, applies onOpen overrides,
|
|
11
|
+
* sets isOpen = true, records data-action-* data in openParams
|
|
12
|
+
* typing → uncontrolled inputs keep their own state; controlled inputs
|
|
13
|
+
* write fields.X.value directly
|
|
14
|
+
* submit → reads FormData from the form element, merges into fields,
|
|
15
|
+
* runs optional validate, calls user onSubmit with final values,
|
|
16
|
+
* closes on success, sets errorState on failure
|
|
17
|
+
* close → resets and sets isOpen = false
|
|
18
|
+
* guard → autonomous effect; if guard() returns false while open, close()
|
|
19
|
+
*/
|
|
20
|
+
import { type ReadonlySignal, type Signal } from "@preact/signals";
|
|
21
|
+
import type { ActionRegistry } from "./registry.ts";
|
|
22
|
+
export type FormOpenContext<TStores> = {
|
|
23
|
+
data: Record<string, string>;
|
|
24
|
+
stores: TStores;
|
|
25
|
+
};
|
|
26
|
+
export type FormSubmitContext<TValues, TStores> = {
|
|
27
|
+
values: TValues;
|
|
28
|
+
stores: TStores;
|
|
29
|
+
};
|
|
30
|
+
export type FormConfig<TValues extends Record<string, string>, TStores> = {
|
|
31
|
+
/** Used as action namespace: `{name}:open`, `{name}:close`, `{name}:submit`. */
|
|
32
|
+
name: string;
|
|
33
|
+
initialValues: TValues;
|
|
34
|
+
onSubmit: (ctx: FormSubmitContext<TValues, TStores>) => void | Promise<void>;
|
|
35
|
+
/** Invoked on open; return partial overrides to pre-populate fields. */
|
|
36
|
+
onOpen?: (ctx: FormOpenContext<TStores>) => Partial<TValues> | undefined;
|
|
37
|
+
/** Returns false while open → form auto-closes (entity-deletion guard). */
|
|
38
|
+
guard?: (ctx: {
|
|
39
|
+
stores: TStores;
|
|
40
|
+
}) => boolean;
|
|
41
|
+
/** Synchronous validation. Returning keys blocks submit. */
|
|
42
|
+
validate?: (values: TValues) => Partial<Record<keyof TValues, string>> | null;
|
|
43
|
+
};
|
|
44
|
+
export type FormStore<TValues extends Record<string, string>, TStores> = {
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly isOpen: ReadonlySignal<boolean>;
|
|
47
|
+
readonly values: ReadonlySignal<TValues>;
|
|
48
|
+
readonly fields: {
|
|
49
|
+
[K in keyof TValues]: Signal<TValues[K]>;
|
|
50
|
+
};
|
|
51
|
+
readonly errors: ReadonlySignal<Partial<Record<keyof TValues, string>>>;
|
|
52
|
+
readonly isSubmitting: ReadonlySignal<boolean>;
|
|
53
|
+
readonly openParams: ReadonlySignal<Record<string, string>>;
|
|
54
|
+
open(override?: Partial<TValues>, params?: Record<string, string>): void;
|
|
55
|
+
close(): void;
|
|
56
|
+
submit(event?: Event): Promise<void>;
|
|
57
|
+
/** Late-binds stores; required before guard/onOpen/onSubmit can access stores. */
|
|
58
|
+
bindStores(getStores: () => TStores): void;
|
|
59
|
+
/** Action handler entries. Spread into the user's ActionRegistry. */
|
|
60
|
+
actions: ActionRegistry<TStores>;
|
|
61
|
+
};
|
|
62
|
+
export declare function createForm<TValues extends Record<string, string>, TStores>(config: FormConfig<TValues, TStores>): FormStore<TValues, TStores>;
|
|
63
|
+
/**
|
|
64
|
+
* Compose many forms into a single set: merged actions, closeAll, openForm signal.
|
|
65
|
+
*/
|
|
66
|
+
export type FormSet<TStores> = {
|
|
67
|
+
actions: ActionRegistry<TStores>;
|
|
68
|
+
openForm: ReadonlySignal<string | null>;
|
|
69
|
+
closeAll(): void;
|
|
70
|
+
bindStores(getStores: () => TStores): void;
|
|
71
|
+
};
|
|
72
|
+
export declare function createFormSet<TStores>(forms: readonly FormStore<Record<string, string>, TStores>[]): FormSet<TStores>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API for `@fairfox/polly/actions`.
|
|
3
|
+
*
|
|
4
|
+
* The action registry pattern: one document listener, one typed registry,
|
|
5
|
+
* components are logic-free consumers of signals that emit `data-action`.
|
|
6
|
+
*/
|
|
7
|
+
export { clearError, type ErrorEntry, type ErrorSeverity, errorState, setError, submitError, } from "./error.ts";
|
|
8
|
+
export { ACTION_EVENT_TYPES, type ActionDispatch, closeTopOverlay as closeTopOverlayViaDom, INTERACTIVE_TAGS, installEventDelegation, parseActionData, resolveAction, } from "./event-delegation.ts";
|
|
9
|
+
export { createForm, createFormSet, type FormConfig, type FormOpenContext, type FormSet, type FormStore, type FormSubmitContext, } from "./form.ts";
|
|
10
|
+
export { closeTopOverlay, hasOpenOverlay, type OverlayEntry, overlayStack, popOverlay, pushOverlay, resetOverlayStack, topOverlay, } from "./overlay.ts";
|
|
11
|
+
export type { ActionContext, ActionHandler, ActionRegistry, } from "./registry.ts";
|
|
12
|
+
export { createStore, StoreProvider, type StoreProviderProps, useStores } from "./store.tsx";
|
|
13
|
+
export { createMockElement, createMockStores, createMockSubmitEvent, runAction, } from "./testing.ts";
|