@civitai/blocks-react 0.54.0 → 0.55.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 +258 -0
- package/dist/live.d.ts +24 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +24 -0
- package/dist/live.js.map +1 -0
- package/dist/testing.d.ts +16 -22
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +15 -23
- package/dist/testing.js.map +1 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -1196,6 +1196,264 @@ For non-React or advanced use, the transport primitives are exported too:
|
|
|
1196
1196
|
`readAllowedOriginsFromEnv`, `getTransport`, and `sendTypedRequest`. Hooks are the
|
|
1197
1197
|
recommended surface; reach for these only when a hook doesn't fit.
|
|
1198
1198
|
|
|
1199
|
+
## The `/testing` subexport
|
|
1200
|
+
|
|
1201
|
+
`@civitai/blocks-react/testing` is the **host-simulation** entry point: it stands
|
|
1202
|
+
in for civitai.com so your block can run in `vitest`/`happy-dom` and in a local
|
|
1203
|
+
dev harness. It is a normal, published subpath of a `0.x` package — see
|
|
1204
|
+
[Stability](#stability-of-testing) below for exactly what that does and does not
|
|
1205
|
+
promise.
|
|
1206
|
+
|
|
1207
|
+
**Everything on this subpath is a mock.** No network, no Buzz, no real backend.
|
|
1208
|
+
Until `0.55.0` that was not true: `createLiveHost`, which talks to the real
|
|
1209
|
+
Civitai backend and spends the token holder's own Buzz, was exported from here
|
|
1210
|
+
too, one autocomplete entry from `createMockHost`. It now lives on its own
|
|
1211
|
+
subpath — see [The `/live` subexport](#the-live-subexport) below.
|
|
1212
|
+
|
|
1213
|
+
### The whole surface
|
|
1214
|
+
|
|
1215
|
+
This section is **the one place the surface is written down**, and it is not
|
|
1216
|
+
prose: `test/subpathSurfaces.test.ts` parses the two marked regions below and
|
|
1217
|
+
fails if they disagree with what `src/testing.tsx` actually exports — in either
|
|
1218
|
+
direction. Every other mention of this subpath (module docblock, `AGENTS.md`)
|
|
1219
|
+
points here rather than repeating the list, because a second copy is exactly
|
|
1220
|
+
what went stale in [#334](https://github.com/civitai/civitai-app-starters/issues/334).
|
|
1221
|
+
|
|
1222
|
+
**Values**
|
|
1223
|
+
|
|
1224
|
+
<!-- TESTING-SURFACE:VALUES:BEGIN -->
|
|
1225
|
+
|
|
1226
|
+
| Export | What it is |
|
|
1227
|
+
|---|---|
|
|
1228
|
+
| `resetTransport` | Drops the cached singleton transport. Call it in `beforeEach` so each test starts clean. |
|
|
1229
|
+
| `createMockHost` | A framework-agnostic fake of the embedding host — answers every `*_RESULT` message, with knobs for generation cost/latency/failure, Buzz balance, app + shared storage, consent, maturity. Returns a `MockHost`; call `.install()` and keep the returned teardown. **No network, no Buzz.** |
|
|
1230
|
+
| `readMockHostUrlOptions` | Reads the harness URL toggles (`?viewer` `?consent` `?fail` `?theme` `?pick` `?balance` `?latency` `?seed` …) into a `Partial<MockHostOptions>`. `Harness` applies it for you; call it directly only in a hand-rolled harness. |
|
|
1231
|
+
| `Harness` | The React wrapper: installs a `createMockHost` on mount, tears it down on unmount, and renders an optional on-screen outbound-message log. Takes every `MockHostOptions` field plus `applyUrlToggles` and `showLog`. |
|
|
1232
|
+
|
|
1233
|
+
<!-- TESTING-SURFACE:VALUES:END -->
|
|
1234
|
+
|
|
1235
|
+
**Types** — the transitive closure that makes those values nameable: each is the
|
|
1236
|
+
declared type of an option, of a `MockHost` member, or of a property of one of
|
|
1237
|
+
those, so you can hoist a sub-object out of an options literal and give it a
|
|
1238
|
+
type.
|
|
1239
|
+
|
|
1240
|
+
<!-- TESTING-SURFACE:TYPES:BEGIN -->
|
|
1241
|
+
|
|
1242
|
+
```text
|
|
1243
|
+
CannedPick
|
|
1244
|
+
CostSpec
|
|
1245
|
+
HarnessProps
|
|
1246
|
+
ImageSpec
|
|
1247
|
+
MockBuzzBalance
|
|
1248
|
+
MockBuzzHandle
|
|
1249
|
+
MockBuzzScenario
|
|
1250
|
+
MockCannedImageScan
|
|
1251
|
+
MockGenerationScenario
|
|
1252
|
+
MockHost
|
|
1253
|
+
MockHostFailMode
|
|
1254
|
+
MockHostOptions
|
|
1255
|
+
MockHostScenarioPatch
|
|
1256
|
+
MockSharedScenario
|
|
1257
|
+
MockSharedSeed
|
|
1258
|
+
MockStorageScenario
|
|
1259
|
+
```
|
|
1260
|
+
|
|
1261
|
+
<!-- TESTING-SURFACE:TYPES:END -->
|
|
1262
|
+
|
|
1263
|
+
That is the complete list. Nothing else is exported.
|
|
1264
|
+
|
|
1265
|
+
### In a test
|
|
1266
|
+
|
|
1267
|
+
```ts
|
|
1268
|
+
import {
|
|
1269
|
+
createMockHost,
|
|
1270
|
+
resetTransport,
|
|
1271
|
+
type MockHostOptions,
|
|
1272
|
+
type MockGenerationScenario,
|
|
1273
|
+
} from '@civitai/blocks-react/testing';
|
|
1274
|
+
|
|
1275
|
+
resetTransport();
|
|
1276
|
+
|
|
1277
|
+
// Hoisting a sub-object out of the options literal is why the scenario types
|
|
1278
|
+
// are exported.
|
|
1279
|
+
const generation: MockGenerationScenario = { costPerGen: 12, latencyMs: 0 };
|
|
1280
|
+
const options: MockHostOptions = { viewer: null, failMode: 'some', generation };
|
|
1281
|
+
|
|
1282
|
+
const host = createMockHost(options);
|
|
1283
|
+
const uninstall = host.install();
|
|
1284
|
+
host.setScenario({ failMode: 'none' }); // live-tune mid-test
|
|
1285
|
+
uninstall();
|
|
1286
|
+
```
|
|
1287
|
+
|
|
1288
|
+
### In a dev harness
|
|
1289
|
+
|
|
1290
|
+
```tsx
|
|
1291
|
+
import { Harness } from '@civitai/blocks-react/testing';
|
|
1292
|
+
|
|
1293
|
+
export function DevRoot() {
|
|
1294
|
+
return (
|
|
1295
|
+
<Harness failMode="some" showLog>
|
|
1296
|
+
<App />
|
|
1297
|
+
</Harness>
|
|
1298
|
+
);
|
|
1299
|
+
}
|
|
1300
|
+
```
|
|
1301
|
+
|
|
1302
|
+
`<Harness>` fires host messages from `window.location.origin`, and the transport
|
|
1303
|
+
drops inbound messages from origins outside its allowlist — so a dev harness
|
|
1304
|
+
must include its own origin, e.g. `VITE_BLOCK_ALLOWED_PARENT_ORIGINS=http://localhost:5173`.
|
|
1305
|
+
Otherwise `BLOCK_INIT` never lands.
|
|
1306
|
+
|
|
1307
|
+
### Stability of `/testing`
|
|
1308
|
+
|
|
1309
|
+
[#334](https://github.com/civitai/civitai-app-starters/issues/334) offered a
|
|
1310
|
+
fork: *document the undocumented surface*, **or** *mark the subpath explicitly
|
|
1311
|
+
unstable*. This package took the **first** branch, and only the first. The
|
|
1312
|
+
section above is that documentation.
|
|
1313
|
+
|
|
1314
|
+
Concretely, and with no guarantee beyond what is actually enforced:
|
|
1315
|
+
|
|
1316
|
+
- **It is a normal subpath of a `0.x` package**, on the same footing as `.`,
|
|
1317
|
+
`./ui` and `./live` — no stronger, no weaker. Under semver `0.x`, a **minor
|
|
1318
|
+
may break it**. It is not `@internal`, and it is not "unsupported": fleet
|
|
1319
|
+
blocks import it from their dev harnesses and from their test suites.
|
|
1320
|
+
- **What is enforced** is that a change to the exported *symbol set* cannot ship
|
|
1321
|
+
silently. `test/subpathSurfaces.test.ts` fails on growth and on shrinkage, and
|
|
1322
|
+
it fails again unless the README section above is updated to match — so any
|
|
1323
|
+
such change is a deliberate edit that a reviewer sees and a changeset names.
|
|
1324
|
+
- **What is *not* promised** is the *shape* of the mock-host option and result
|
|
1325
|
+
types. They describe a fake host whose fidelity tracks the real one; a
|
|
1326
|
+
property may be added, tightened or renamed in a minor. The ledger asserts
|
|
1327
|
+
names, not shapes, and deliberately so.
|
|
1328
|
+
|
|
1329
|
+
What is *not* listed above is genuinely internal and carries no guarantee. Until
|
|
1330
|
+
`0.55.0` this subpath also re-exported 25 symbols with no documentation — the
|
|
1331
|
+
catalog client (`fetchCatalog`, `buildCatalogUrl`, `edgeThumb`, `modelToCard`,
|
|
1332
|
+
`DEFAULT_LIMIT`, …), the in-harness picker overlay (`openPickerOverlay`),
|
|
1333
|
+
`decodeBlockTokenPayload`, `disallowedAccountError`, `mockParentMessage`, and
|
|
1334
|
+
the `MockHostProvider` alias — plus `createLiveHost` / `LiveHostOptions`, which
|
|
1335
|
+
moved to `./live` rather than disappearing. See the `0.55.0` changelog entry for
|
|
1336
|
+
the full list and for the three removals that had a measured fleet consumer. If
|
|
1337
|
+
you were importing one of the internal ones, it lives at a path this package
|
|
1338
|
+
does not publish — open an issue rather than reaching into `dist/internal/`.
|
|
1339
|
+
|
|
1340
|
+
## The `/live` subexport
|
|
1341
|
+
|
|
1342
|
+
> ### 🔴 `@civitai/blocks-react/live` spends real Buzz
|
|
1343
|
+
>
|
|
1344
|
+
> `createLiveHost` forwards the App-Block postMessage protocol to the **real
|
|
1345
|
+
> Civitai backend** over a pasted short-lived dev block token —
|
|
1346
|
+
> `blocks.submitWorkflow` included — and a successful generation **debits the
|
|
1347
|
+
> token holder's own Buzz**. There is no dry-run mode and no confirmation. It
|
|
1348
|
+
> exists for one caller: a `pnpm dev:live` harness. **It must never appear in a
|
|
1349
|
+
> test suite.** The free one is `createMockHost`, on `./testing`.
|
|
1350
|
+
|
|
1351
|
+
### Why it has its own subpath
|
|
1352
|
+
|
|
1353
|
+
Until `0.55.0` this code was exported from `./testing`. The argument for moving
|
|
1354
|
+
it, in full, is that **a client which spends the caller's money should not be
|
|
1355
|
+
reachable through an import path named `testing`** — the import line is the one
|
|
1356
|
+
piece of context that travels with every call site, and `…/testing` actively
|
|
1357
|
+
asserts the opposite of what this module does. That is
|
|
1358
|
+
[#334](https://github.com/civitai/civitai-app-starters/issues/334)'s literal
|
|
1359
|
+
closing condition.
|
|
1360
|
+
|
|
1361
|
+
Two arguments that were made for this change and **do not hold** — recorded so
|
|
1362
|
+
they are not made again:
|
|
1363
|
+
|
|
1364
|
+
- **It does not shrink the install.** Measured: **+4,447 B**. See
|
|
1365
|
+
[What the host-simulation subpaths cost you](#what-the-host-simulation-subpaths-cost-you).
|
|
1366
|
+
- **It does not close a wrong-autocomplete hazard**, because there was none to
|
|
1367
|
+
close. `createMockHost(options: MockHostOptions = {})` is callable bare;
|
|
1368
|
+
`createLiveHost(options: LiveHostOptions)` takes a **required** argument whose
|
|
1369
|
+
`blockToken` is a **required** short-lived RS256 JWT that a human mints and
|
|
1370
|
+
pastes by hand. `createLiveHost()` and `createLiveHost({})` do not compile, so
|
|
1371
|
+
nobody reaches this module by picking the wrong completion. Earlier revisions
|
|
1372
|
+
of this file, of the changeset, and of #334 called the two signatures
|
|
1373
|
+
"near-identical"; none of them had read the signatures.
|
|
1374
|
+
|
|
1375
|
+
### The whole surface
|
|
1376
|
+
|
|
1377
|
+
One value and one type. `test/subpathSurfaces.test.ts` pins the runtime export
|
|
1378
|
+
set, failing on growth and on shrinkage.
|
|
1379
|
+
|
|
1380
|
+
| Export | What it is |
|
|
1381
|
+
|---|---|
|
|
1382
|
+
| `createLiveHost` | 🔴 **Real backend, real Buzz.** Installs a host that proxies the block's `postMessage` traffic to civitai.com using a dev block token. Returns a handle; call `.install()` and keep the teardown, exactly like `createMockHost`. |
|
|
1383
|
+
| `LiveHostOptions` *(type)* | Options for the above. `blockToken` is required; everything else (`backendBaseUrl`, `viewer`, `theme`, `context`, `onOutbound`, …) has a default. |
|
|
1384
|
+
|
|
1385
|
+
### In a `dev:live` harness
|
|
1386
|
+
|
|
1387
|
+
```ts
|
|
1388
|
+
import { createLiveHost, type LiveHostOptions } from '@civitai/blocks-react/live';
|
|
1389
|
+
|
|
1390
|
+
// The token is a SHORT-LIVED dev block token pasted into the harness env, never
|
|
1391
|
+
// an API key: `POST /api/v1/blocks/dev-token`, ~4h, re-minted by hand.
|
|
1392
|
+
const options: LiveHostOptions = {
|
|
1393
|
+
blockToken: devBlockToken,
|
|
1394
|
+
theme: 'dark',
|
|
1395
|
+
};
|
|
1396
|
+
|
|
1397
|
+
const host = createLiveHost(options);
|
|
1398
|
+
const uninstall = host.install();
|
|
1399
|
+
```
|
|
1400
|
+
|
|
1401
|
+
### Stability of `/live`
|
|
1402
|
+
|
|
1403
|
+
The same terms as `./testing`: a normal subpath of a `0.x` package where a minor
|
|
1404
|
+
may break it, with the runtime symbol set pinned by
|
|
1405
|
+
`test/subpathSurfaces.test.ts` so it cannot change silently.
|
|
1406
|
+
|
|
1407
|
+
🔴 One cost worth stating plainly: publishing and documenting this subpath makes
|
|
1408
|
+
[#334](https://github.com/civitai/civitai-app-starters/issues/334) **item 3** —
|
|
1409
|
+
getting the live-host code out of the tarball entirely — *harder*, not easier.
|
|
1410
|
+
`./live` is now a named public entry point, so removing it later is a breaking
|
|
1411
|
+
change on a surface consumers pin against, where before it was one export among
|
|
1412
|
+
many on a subpath nobody was told to rely on.
|
|
1413
|
+
|
|
1414
|
+
## What the host-simulation subpaths cost you
|
|
1415
|
+
|
|
1416
|
+
Seven `dist/` modules — 266,790 B of JavaScript plus 77,338 B of `.d.ts` — are
|
|
1417
|
+
reachable only from `./testing` and `./live`, and from nothing under `.` or
|
|
1418
|
+
`./ui`. Measured by walking the built module graph:
|
|
1419
|
+
|
|
1420
|
+
```text
|
|
1421
|
+
118,590 dist/internal/mockHost.js ← ./testing (createMockHost)
|
|
1422
|
+
86,688 dist/internal/liveHost.js ← ./live (createLiveHost)
|
|
1423
|
+
29,508 dist/internal/pickerOverlay.js ← ./live (via liveHost)
|
|
1424
|
+
15,351 dist/internal/catalog.js ← ./live (via pickerOverlay)
|
|
1425
|
+
9,141 dist/testing.js
|
|
1426
|
+
4,697 dist/internal/consent.js ← BOTH hosts import it
|
|
1427
|
+
2,815 dist/live.js
|
|
1428
|
+
```
|
|
1429
|
+
|
|
1430
|
+
**They ship in every install**, production dependency trees included. They are
|
|
1431
|
+
tree-shaken out of application *bundles* — no block ships a mock host to a
|
|
1432
|
+
browser — so this is `node_modules` weight, not bundle weight.
|
|
1433
|
+
|
|
1434
|
+
🔴 **Splitting `createLiveHost` onto its own subpath removed none of this — it
|
|
1435
|
+
ADDS 4,447 B of code, and trimming the export list moved nothing either.**
|
|
1436
|
+
Measured with `pnpm pack` on both sides of the split, in a detached worktree so
|
|
1437
|
+
neither pack is contaminated by the other change in this release: **319 → 323
|
|
1438
|
+
entries, 1,590,099 B → 1,597,161 B uncompressed.** The only files that differ are
|
|
1439
|
+
|
|
1440
|
+
```text
|
|
1441
|
+
+6,048 dist/live.* (new: .js 2,815, .d.ts 2,839, + maps)
|
|
1442
|
+
-1,692 dist/testing.* (the re-export and its docblock leaving)
|
|
1443
|
+
+91 package.json (the new exports-map key)
|
|
1444
|
+
+2,615 README.md (this section)
|
|
1445
|
+
```
|
|
1446
|
+
|
|
1447
|
+
`liveHost.js`, `pickerOverlay.js` and `catalog.js` do not appear in that diff at
|
|
1448
|
+
all — they are byte-identical and still in the tarball. `files` is
|
|
1449
|
+
`["dist", "README.md"]` and `tsconfig` compiles all of `src/**/*`, so the
|
|
1450
|
+
`exports` map has no bearing whatsoever on tarball contents; it decides only what
|
|
1451
|
+
a consumer can *name*.
|
|
1452
|
+
**The `/live` split buys safety, not size.** Moving these bytes needs the code
|
|
1453
|
+
deleted or published as a second artifact; that is
|
|
1454
|
+
[#334](https://github.com/civitai/civitai-app-starters/issues/334) item 3, and it
|
|
1455
|
+
is not done here.
|
|
1456
|
+
|
|
1199
1457
|
## Examples
|
|
1200
1458
|
|
|
1201
1459
|
Runnable, minimal blocks — one per feature, each with its own README:
|
package/dist/live.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@civitai/blocks-react/live` — THE REAL BACKEND. THIS SPENDS REAL BUZZ.
|
|
3
|
+
*
|
|
4
|
+
* `createLiveHost` forwards the App-Block postMessage protocol to the REAL
|
|
5
|
+
* Civitai backend over a pasted short-lived dev block token,
|
|
6
|
+
* `blocks.submitWorkflow` included. A successful generation DEBITS THE TOKEN
|
|
7
|
+
* HOLDER'S OWN BUZZ. There is no dry-run mode and no confirmation. It exists for
|
|
8
|
+
* one caller: a `pnpm dev:live` harness. The free one is `createMockHost`, on
|
|
9
|
+
* `@civitai/blocks-react/testing`.
|
|
10
|
+
*
|
|
11
|
+
* WHY ITS OWN SUBPATH (#334): a client that spends the caller's money should not
|
|
12
|
+
* be reachable through an import path named `testing`. The import line is the
|
|
13
|
+
* one piece of context that travels with every call site, so it is where the
|
|
14
|
+
* warning belongs. It does NOT make the package smaller — `files` is
|
|
15
|
+
* `["dist", "README.md"]` and `tsconfig` compiles the whole source tree, so the
|
|
16
|
+
* code ships either way.
|
|
17
|
+
*
|
|
18
|
+
* Surface, rationale and stability are documented in exactly one place — README
|
|
19
|
+
* § "The `/live` subexport". Do not restate them here; a second copy is what
|
|
20
|
+
* went stale and became #334. `test/subpathSurfaces.test.ts` pins this module's
|
|
21
|
+
* runtime export set.
|
|
22
|
+
*/
|
|
23
|
+
export { createLiveHost, type LiveHostOptions } from './internal/liveHost.js';
|
|
24
|
+
//# sourceMappingURL=live.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live.d.ts","sourceRoot":"","sources":["../src/live.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/live.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@civitai/blocks-react/live` — THE REAL BACKEND. THIS SPENDS REAL BUZZ.
|
|
3
|
+
*
|
|
4
|
+
* `createLiveHost` forwards the App-Block postMessage protocol to the REAL
|
|
5
|
+
* Civitai backend over a pasted short-lived dev block token,
|
|
6
|
+
* `blocks.submitWorkflow` included. A successful generation DEBITS THE TOKEN
|
|
7
|
+
* HOLDER'S OWN BUZZ. There is no dry-run mode and no confirmation. It exists for
|
|
8
|
+
* one caller: a `pnpm dev:live` harness. The free one is `createMockHost`, on
|
|
9
|
+
* `@civitai/blocks-react/testing`.
|
|
10
|
+
*
|
|
11
|
+
* WHY ITS OWN SUBPATH (#334): a client that spends the caller's money should not
|
|
12
|
+
* be reachable through an import path named `testing`. The import line is the
|
|
13
|
+
* one piece of context that travels with every call site, so it is where the
|
|
14
|
+
* warning belongs. It does NOT make the package smaller — `files` is
|
|
15
|
+
* `["dist", "README.md"]` and `tsconfig` compiles the whole source tree, so the
|
|
16
|
+
* code ships either way.
|
|
17
|
+
*
|
|
18
|
+
* Surface, rationale and stability are documented in exactly one place — README
|
|
19
|
+
* § "The `/live` subexport". Do not restate them here; a second copy is what
|
|
20
|
+
* went stale and became #334. `test/subpathSurfaces.test.ts` pins this module's
|
|
21
|
+
* runtime export set.
|
|
22
|
+
*/
|
|
23
|
+
export { createLiveHost } from './internal/liveHost.js';
|
|
24
|
+
//# sourceMappingURL=live.js.map
|
package/dist/live.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live.js","sourceRoot":"","sources":["../src/live.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,cAAc,EAAwB,MAAM,wBAAwB,CAAC"}
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* surface — block apps should never import from here in production code (the
|
|
4
|
-
* `./testing` subpath keeps accidental prod imports visible in review).
|
|
2
|
+
* `@civitai/blocks-react/testing` — the HOST-SIMULATION subpath.
|
|
5
3
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* host (usable from node/jsdom/happy-dom tests AND a dev harness).
|
|
10
|
-
* - `<Harness>` / `<MockHostProvider>` — a thin React wrapper that installs a
|
|
11
|
-
* mock host for local dev, with an optional on-screen message log.
|
|
4
|
+
* This is NOT "two test helpers". It is the surface a block app's dev harness
|
|
5
|
+
* and test suite use to stand in for civitai.com: a mock host, a React wrapper
|
|
6
|
+
* around it, and a transport reset.
|
|
12
7
|
*
|
|
13
|
-
*
|
|
8
|
+
* EVERYTHING HERE IS A MOCK. No network, no Buzz, no real backend. That is a
|
|
9
|
+
* property of the subpath, not a claim in a comment: `createLiveHost`, which
|
|
10
|
+
* spends the token holder's own Buzz, lives at `@civitai/blocks-react/live`
|
|
11
|
+
* (#334).
|
|
12
|
+
*
|
|
13
|
+
* Surface, rationale and stability are documented in exactly one place — README
|
|
14
|
+
* § "The `/testing` subexport". Do not restate them here; a second copy is what
|
|
15
|
+
* went stale and became #334. `test/subpathSurfaces.test.ts` pins that ledger to
|
|
16
|
+
* this module (runtime values and, via the TypeScript checker, types) and to the
|
|
17
|
+
* README section, failing on growth and on shrinkage alike.
|
|
14
18
|
*/
|
|
15
19
|
import { type ReactNode } from 'react';
|
|
16
20
|
import { __resetTransport } from './internal/singleton.js';
|
|
17
21
|
import { type MockHostOptions } from './internal/mockHost.js';
|
|
18
22
|
export { __resetTransport as resetTransport };
|
|
19
|
-
export { createMockHost, readMockHostUrlOptions,
|
|
20
|
-
export { createLiveHost, decodeBlockTokenPayload, type LiveHostOptions, } from './internal/liveHost.js';
|
|
21
|
-
export { buildCatalogUrl, fetchCatalog, modelToCard, responseToPage, edgeThumb, cardToCheckpoint, cardToResource, filterCardsByFamily, CATALOG_API_BASE, CATALOG_API_BASE_BLOCKS, DEFAULT_LIMIT, type CatalogQuery, type CatalogCard, type CatalogPage, type CatalogResult, type CatalogModelType, } from './internal/catalog.js';
|
|
22
|
-
export { openPickerOverlay, type PickerOverlayHandle, type PickerSelection, type OpenPickerOptions, } from './internal/pickerOverlay.js';
|
|
23
|
-
/**
|
|
24
|
-
* Builds a `MessageEvent` that mimics a parent-frame postMessage so tests can
|
|
25
|
-
* exercise `IframeTransport.handleMessage` without a real cross-frame setup.
|
|
26
|
-
*/
|
|
27
|
-
export declare function mockParentMessage(data: unknown, origin: string): MessageEvent;
|
|
23
|
+
export { createMockHost, readMockHostUrlOptions, type MockHost, type MockHostOptions, type MockHostFailMode, type MockHostScenarioPatch, type MockGenerationScenario, type MockBuzzScenario, type MockBuzzBalance, type MockBuzzHandle, type MockStorageScenario, type MockSharedScenario, type MockSharedSeed, type MockCannedImageScan, type CostSpec, type ImageSpec, type CannedPick, } from './internal/mockHost.js';
|
|
28
24
|
/**
|
|
29
|
-
* Props for the dev
|
|
25
|
+
* Props for the dev {@link Harness}.
|
|
30
26
|
*/
|
|
31
27
|
export interface HarnessProps extends MockHostOptions {
|
|
32
28
|
/** The block app to render inside the mocked host. */
|
|
@@ -66,6 +62,4 @@ export interface HarnessProps extends MockHostOptions {
|
|
|
66
62
|
* );
|
|
67
63
|
*/
|
|
68
64
|
export declare function Harness({ children, applyUrlToggles, showLog, ...options }: HarnessProps): import("react/jsx-runtime").JSX.Element;
|
|
69
|
-
/** Alias of {@link Harness} — same component, clearer name when used as a context provider. */
|
|
70
|
-
export declare const MockHostProvider: typeof Harness;
|
|
71
65
|
//# sourceMappingURL=testing.d.ts.map
|
package/dist/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAA+B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,gBAAgB,IAAI,cAAc,EAAE,CAAC;AAE9C,OAAO,EACL,cAAc,EACd,sBAAsB,EAKtB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,UAAU,GAChB,MAAM,wBAAwB,CAAC;AAYhC;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,sDAAsD;IACtD,QAAQ,EAAE,SAAS,CAAC;IACpB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgDD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,OAAO,CAAC,EACtB,QAAQ,EACR,eAAsB,EACtB,OAAc,EACd,GAAG,OAAO,EACX,EAAE,YAAY,2CAuEd"}
|
package/dist/testing.js
CHANGED
|
@@ -1,33 +1,27 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* surface — block apps should never import from here in production code (the
|
|
5
|
-
* `./testing` subpath keeps accidental prod imports visible in review).
|
|
3
|
+
* `@civitai/blocks-react/testing` — the HOST-SIMULATION subpath.
|
|
6
4
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* host (usable from node/jsdom/happy-dom tests AND a dev harness).
|
|
11
|
-
* - `<Harness>` / `<MockHostProvider>` — a thin React wrapper that installs a
|
|
12
|
-
* mock host for local dev, with an optional on-screen message log.
|
|
5
|
+
* This is NOT "two test helpers". It is the surface a block app's dev harness
|
|
6
|
+
* and test suite use to stand in for civitai.com: a mock host, a React wrapper
|
|
7
|
+
* around it, and a transport reset.
|
|
13
8
|
*
|
|
14
|
-
*
|
|
9
|
+
* EVERYTHING HERE IS A MOCK. No network, no Buzz, no real backend. That is a
|
|
10
|
+
* property of the subpath, not a claim in a comment: `createLiveHost`, which
|
|
11
|
+
* spends the token holder's own Buzz, lives at `@civitai/blocks-react/live`
|
|
12
|
+
* (#334).
|
|
13
|
+
*
|
|
14
|
+
* Surface, rationale and stability are documented in exactly one place — README
|
|
15
|
+
* § "The `/testing` subexport". Do not restate them here; a second copy is what
|
|
16
|
+
* went stale and became #334. `test/subpathSurfaces.test.ts` pins that ledger to
|
|
17
|
+
* this module (runtime values and, via the TypeScript checker, types) and to the
|
|
18
|
+
* README section, failing on growth and on shrinkage alike.
|
|
15
19
|
*/
|
|
16
20
|
import { useEffect, useRef, useState } from 'react';
|
|
17
21
|
import { __resetTransport } from './internal/singleton.js';
|
|
18
22
|
import { createMockHost, readMockHostUrlOptions, } from './internal/mockHost.js';
|
|
19
23
|
export { __resetTransport as resetTransport };
|
|
20
|
-
export { createMockHost, readMockHostUrlOptions,
|
|
21
|
-
export { createLiveHost, decodeBlockTokenPayload, } from './internal/liveHost.js';
|
|
22
|
-
export { buildCatalogUrl, fetchCatalog, modelToCard, responseToPage, edgeThumb, cardToCheckpoint, cardToResource, filterCardsByFamily, CATALOG_API_BASE, CATALOG_API_BASE_BLOCKS, DEFAULT_LIMIT, } from './internal/catalog.js';
|
|
23
|
-
export { openPickerOverlay, } from './internal/pickerOverlay.js';
|
|
24
|
-
/**
|
|
25
|
-
* Builds a `MessageEvent` that mimics a parent-frame postMessage so tests can
|
|
26
|
-
* exercise `IframeTransport.handleMessage` without a real cross-frame setup.
|
|
27
|
-
*/
|
|
28
|
-
export function mockParentMessage(data, origin) {
|
|
29
|
-
return new MessageEvent('message', { data, origin, source: null });
|
|
30
|
-
}
|
|
24
|
+
export { createMockHost, readMockHostUrlOptions, } from './internal/mockHost.js';
|
|
31
25
|
/**
|
|
32
26
|
* What the harness chrome's `consent=` readout says, from the TWO INDEPENDENT
|
|
33
27
|
* booleans that describe consent in the mock host.
|
|
@@ -124,8 +118,6 @@ export function Harness({ children, applyUrlToggles = true, showLog = true, ...o
|
|
|
124
118
|
.map((m, i) => `${i + 1}. ${m.type} ${JSON.stringify(m.payload ?? {})}`)
|
|
125
119
|
.join('\n') })] }))] }));
|
|
126
120
|
}
|
|
127
|
-
/** Alias of {@link Harness} — same component, clearer name when used as a context provider. */
|
|
128
|
-
export const MockHostProvider = Harness;
|
|
129
121
|
// Minimal console / terminal aesthetic: dark terminal slab, monospace, a
|
|
130
122
|
// subtle accent top border, dim chrome text with brighter accents for the
|
|
131
123
|
// live readout values. Compact + unobtrusive — shared chrome rendered by
|
package/dist/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.tsx"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACL,cAAc,EACd,sBAAsB,GAEvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,gBAAgB,IAAI,cAAc,EAAE,CAAC;AAE9C,OAAO,EACL,cAAc,EACd,sBAAsB,GAoBvB,MAAM,wBAAwB,CAAC;AAkChC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAS,mBAAmB,CAAC,IAG5B;IACC,+EAA+E;IAC/E,8DAA8D;IAC9D,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC;IAChD,MAAM,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;IACtC,IAAI,SAAS;QAAE,OAAO,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC;IACvD,OAAO,OAAO,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,aAAa,CAAC;AACzD,CAAC;AAED;;;;GAIG;AACH,SAAS,YAAY,CAAC,KAA0B;IAC9C,OAAO,KAAK,KAAK,aAAa,IAAI,KAAK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ACV,CAAC;AAEX,MAAM,eAAe,GAAG;IACtB,MAAM,EAAE,SAAS;IACjB,UAAU,EAAE,CAAC;IACb,SAAS,EAAE,kCAAkC;IAC7C,SAAS,EAAE,GAAG;IACd,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,SAAS;IAChB,aAAa,EAAE,MAAM;CACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@civitai/blocks-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.55.0",
|
|
4
4
|
"description": "React hooks and iframe transport for Civitai Apps. Pairs with @civitai/app-sdk/blocks.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"./testing": {
|
|
22
22
|
"types": "./dist/testing.d.ts",
|
|
23
23
|
"import": "./dist/testing.js"
|
|
24
|
+
},
|
|
25
|
+
"./live": {
|
|
26
|
+
"types": "./dist/live.d.ts",
|
|
27
|
+
"import": "./dist/live.js"
|
|
24
28
|
}
|
|
25
29
|
},
|
|
26
30
|
"files": [
|
|
@@ -31,8 +35,8 @@
|
|
|
31
35
|
"node": ">=20"
|
|
32
36
|
},
|
|
33
37
|
"dependencies": {
|
|
34
|
-
"@civitai/
|
|
35
|
-
"@civitai/
|
|
38
|
+
"@civitai/theme": "0.3.1",
|
|
39
|
+
"@civitai/components": "0.4.1"
|
|
36
40
|
},
|
|
37
41
|
"comment-peerDependencies": [
|
|
38
42
|
"The @civitai/app-sdk floor is DERIVED, not chosen: it is the lowest published",
|
|
@@ -153,7 +157,7 @@
|
|
|
153
157
|
"react-dom": "^19.0.0",
|
|
154
158
|
"typescript": "^5.9.2",
|
|
155
159
|
"vitest": "^4.1.11",
|
|
156
|
-
"@civitai/app-sdk": "^0.
|
|
160
|
+
"@civitai/app-sdk": "^0.48.0"
|
|
157
161
|
},
|
|
158
162
|
"publishConfig": {
|
|
159
163
|
"access": "public"
|