@joiner-platform/cli 0.0.0-stage → 0.1.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 +30 -2
- package/bundled-resources/poe-tile-templates/base/CLAUDE.md +72 -0
- package/bundled-resources/poe-tile-templates/base/README.md +7 -0
- package/bundled-resources/poe-tile-templates/base/_bunfig.toml +8 -0
- package/bundled-resources/poe-tile-templates/base/_gitignore +18 -0
- package/bundled-resources/poe-tile-templates/base/client.ts +12 -0
- package/bundled-resources/poe-tile-templates/base/package.json +36 -0
- package/bundled-resources/poe-tile-templates/base/playwright.config.ts +38 -0
- package/bundled-resources/poe-tile-templates/base/scripts/check-source.ts +148 -0
- package/bundled-resources/poe-tile-templates/base/scripts/dev.ts +19 -0
- package/bundled-resources/poe-tile-templates/base/scripts/doctor.sh +29 -0
- package/bundled-resources/poe-tile-templates/base/scripts/visual-check.ts +64 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/backend-config.ts +9 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/client-config.ts +8 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/data/items.ts +16 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/index.ts +10 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/remove-todo.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/set-todo.ts +20 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/types.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators.test.ts +138 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/schema.ts +40 -0
- package/bundled-resources/poe-tile-templates/base/tests/e2e.test.playwright.ts +92 -0
- package/bundled-resources/poe-tile-templates/base/tests/mobile-viewport.test.playwright.ts +111 -0
- package/bundled-resources/poe-tile-templates/base/tests/render-check.test.playwright.ts +128 -0
- package/bundled-resources/poe-tile-templates/base/tests/screenshot.test.playwright.ts +86 -0
- package/bundled-resources/poe-tile-templates/base/tests/setup-dom.ts +70 -0
- package/bundled-resources/poe-tile-templates/base/tile/src/backend.ts +3 -0
- package/bundled-resources/poe-tile-templates/base/tile/styles.css +47 -0
- package/bundled-resources/poe-tile-templates/base/tsconfig.json +13 -0
- package/bundled-resources/poe-tile-templates/coverage.config.json +6 -0
- package/bundled-resources/poe-tile-templates/index.ts +27 -0
- package/bundled-resources/poe-tile-templates/package.json +31 -0
- package/bundled-resources/poe-tile-templates/phaserjs/package.partial.json +6 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.test.happydom.tsx +98 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.ts +180 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/phaser-scene.ts +174 -0
- package/bundled-resources/poe-tile-templates/phaserjs/vite.config.ts +28 -0
- package/bundled-resources/poe-tile-templates/preact/package.partial.json +9 -0
- package/bundled-resources/poe-tile-templates/preact/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/preact/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/preact/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/preact/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/preact/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.test.happydom.tsx +69 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.tsx +116 -0
- package/bundled-resources/poe-tile-templates/preact/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/react/package.partial.json +12 -0
- package/bundled-resources/poe-tile-templates/react/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/react/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/react/tile/src/entry.tsx +38 -0
- package/bundled-resources/poe-tile-templates/react/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/react/tsconfig.json +14 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.test.happydom.tsx +71 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.tsx +110 -0
- package/bundled-resources/poe-tile-templates/react/vite.config.ts +21 -0
- package/bundled-resources/poe-tile-templates/scripts/cleanup.ts +10 -0
- package/bundled-resources/poe-tile-templates/scripts/generate.ts +57 -0
- package/bundled-resources/poe-tile-templates/scripts/install-diagnostics.ts +52 -0
- package/bundled-resources/poe-tile-templates/scripts/paths.ts +7 -0
- package/bundled-resources/poe-tile-templates/scripts/sdk-dependency-key.ts +288 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-all-sdks.ts +132 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-command.ts +30 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-tarball.ts +397 -0
- package/bundled-resources/poe-tile-templates/solidjs/_bunfig.toml +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/package.partial.json +13 -0
- package/bundled-resources/poe-tile-templates/solidjs/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/solidjs/tests/solid-plugin.ts +49 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/solidjs/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.test.happydom.tsx +70 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.tsx +129 -0
- package/bundled-resources/poe-tile-templates/solidjs/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/tests/check-source.test.ts +131 -0
- package/bundled-resources/poe-tile-templates/tests/dev-script.test.slow.ts +166 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/customized-manager.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/extended-mutators.ts.txt +106 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/multiplayer-verification.test.playwright.ts.txt +103 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/replace-starter-schema.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/phaserjs.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/preact.tsx.txt +69 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/react.tsx.txt +73 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/seating.ts.txt +54 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/solidjs.tsx.txt +70 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/vanilla-js.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/generated-templates.test.ts +278 -0
- package/bundled-resources/poe-tile-templates/tests/happy-dom-version.test.ts +27 -0
- package/bundled-resources/poe-tile-templates/tests/install-diagnostics.test.ts +99 -0
- package/bundled-resources/poe-tile-templates/tests/native-gesture-defaults.test.ts +23 -0
- package/bundled-resources/poe-tile-templates/tests/playwright-version.test.ts +84 -0
- package/bundled-resources/poe-tile-templates/tests/render-check-scaffold.test.ts +56 -0
- package/bundled-resources/poe-tile-templates/tests/sdk-dependency-key.test.ts +129 -0
- package/bundled-resources/poe-tile-templates/tests/visual-check.test.ts +90 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/package.partial.json +3 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.test.happydom.tsx +96 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.ts +113 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/vite.config.ts +17 -0
- package/cli.ts +134 -0
- package/index.ts +96 -0
- package/package.json +48 -5
- package/skills/audio-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/audio-generation/SKILL.md +125 -0
- package/skills/finish-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/finish-prototype/SKILL.md +22 -0
- package/skills/help-me-build/.generated-by-poe-templated-docs +0 -0
- package/skills/help-me-build/SKILL.md +56 -0
- package/skills/image-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/image-generation/SKILL.md +128 -0
- package/skills/one-shot/.generated-by-poe-templated-docs +0 -0
- package/skills/one-shot/SKILL.md +22 -0
- package/skills/platform-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-prototype/SKILL.md +60 -0
- package/skills/platform-subagent/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-subagent/SKILL.md +16 -0
- package/skills/poe-tiles-cli/.generated-by-poe-templated-docs +0 -0
- package/skills/poe-tiles-cli/SKILL.md +609 -0
- package/skills/poe-tiles-cli/references/device-motion.md +40 -0
- package/skills/poe-tiles-cli/references/player-updates.md +41 -0
- package/skills/prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/prototype/SKILL.md +148 -0
- package/skills/publish/.generated-by-poe-templated-docs +0 -0
- package/skills/publish/SKILL.md +73 -0
- package/skills/synced-store/.generated-by-poe-templated-docs +0 -0
- package/skills/synced-store/SKILL.md +583 -0
- package/skills/synced-store/references/actions.md +85 -0
- package/skills/synced-store/references/api-patterns.md +245 -0
- package/skills/synced-store/references/architecture-scaling-and-performance.md +280 -0
- package/skills/synced-store/references/client-api-reference.md +263 -0
- package/skills/synced-store/references/data-visibility.md +95 -0
- package/skills/synced-store/references/external-stores.md +162 -0
- package/skills/synced-store/references/file-uploads.md +216 -0
- package/skills/synced-store/references/getting-user-info-of-members.md +228 -0
- package/skills/synced-store/references/limitations.md +72 -0
- package/skills/synced-store/references/live-data-limit-hook.md +131 -0
- package/skills/synced-store/references/mutator-rules.md +169 -0
- package/skills/synced-store/references/platform.md +49 -0
- package/skills/synced-store/references/schema-and-bindings.md +85 -0
- package/skills/synced-store/references/schema-libraries.md +57 -0
- package/skills/synced-store/references/schema-migrations.md +119 -0
- package/skills/synced-store/references/searchable-tables.md +27 -0
- package/skills/synced-store/references/server-forking.md +115 -0
- package/skills/synced-store/references/singleton-tables.md +61 -0
- package/skills/synced-store/references/sort-keys.md +253 -0
- package/skills/synced-store/references/ui-patterns.md +95 -0
- package/skills/tile-creator/.generated-by-poe-templated-docs +0 -0
- package/skills/tile-creator/SKILL.md +196 -0
- package/skills/tile-creator/references/assets.md +124 -0
- package/skills/tile-creator/references/backend-api.md +308 -0
- package/skills/tile-creator/references/cli-limitations.md +64 -0
- package/skills/tile-creator/references/cli.md +604 -0
- package/skills/tile-creator/references/client-api.md +2407 -0
- package/skills/tile-creator/references/composing-apps.md +166 -0
- package/skills/tile-creator/references/e2e-tests.md +55 -0
- package/skills/tile-creator/references/game-ux-best-practices.md +57 -0
- package/skills/tile-creator/references/migrating-pre-rename-tiles.md +79 -0
- package/skills/tile-creator/references/multiplayer-api-recipe.md +205 -0
- package/skills/tile-creator/references/native-results.md +100 -0
- package/skills/tile-creator/references/platform-integration.md +201 -0
- package/skills/tile-creator/references/power-report.md +199 -0
- package/skills/tile-creator/references/publish-rollout.md +166 -0
- package/skills/tile-creator/references/publishing.md +33 -0
- package/skills/tile-creator/references/push-notification-guidelines.md +58 -0
- package/skills/tile-creator/references/render-check.md +266 -0
- package/skills/tile-creator/references/running-the-client-api-on-a-server-owned-by-the-user.md +95 -0
- package/skills/tile-creator/references/safe-area-insets.md +79 -0
- package/skills/tile-creator/references/sandbox-limitations.md +32 -0
- package/skills/tile-creator/references/scaffolded-tile-folder-structure.md +48 -0
- package/skills/tile-creator/references/scaffolding-a-new-app.md +202 -0
- package/skills/tile-creator/references/simulations.md +125 -0
- package/skills/tile-creator/references/synced-store-client-reference.md +92 -0
- package/skills/tile-creator/references/troubleshooting.md +22 -0
- package/skills/tile-creator/references/turn-based-mutator.md +43 -0
- package/skills/tile-creator/references/user-erasure.md +14 -0
- package/skills/tile-creator/references/vite-plugin.md +166 -0
- package/skills/tile-creator/references/workspace-retention.md +72 -0
- package/src/admin-conversions-client.ts +28 -0
- package/src/admin-reviews-client.ts +36 -0
- package/src/api.generated.ts +1527 -0
- package/src/auth-token.ts +198 -0
- package/src/bounded-read.ts +35 -0
- package/src/bun-version.ts +33 -0
- package/src/checkout-base.ts +207 -0
- package/src/cli-bun-version.ts +16 -0
- package/src/cli-env.ts +28 -0
- package/src/cli-name.ts +23 -0
- package/src/client.ts +2474 -0
- package/src/collect-files.ts +226 -0
- package/src/commands/accounts.ts +55 -0
- package/src/commands/admin-abandon-conversion.ts +60 -0
- package/src/commands/admin-reviews.ts +66 -0
- package/src/commands/admin.ts +219 -0
- package/src/commands/auth.ts +89 -0
- package/src/commands/checkout-prototype.ts +67 -0
- package/src/commands/creator-source-capability.ts +11 -0
- package/src/commands/doctor-bun.ts +145 -0
- package/src/commands/doctor-command.ts +64 -0
- package/src/commands/doctor-package-json.ts +47 -0
- package/src/commands/doctor-sdk-pin.ts +156 -0
- package/src/commands/doctor-store-keys-lexer.ts +213 -0
- package/src/commands/doctor-store-keys-scan.ts +262 -0
- package/src/commands/doctor-store-keys.ts +196 -0
- package/src/commands/doctor.ts +371 -0
- package/src/commands/init/blank-scaffold-templates.ts +397 -0
- package/src/commands/init/index.ts +170 -0
- package/src/commands/init/internal-toolchain.ts +49 -0
- package/src/commands/init/manager-test-template.ts +107 -0
- package/src/commands/init/multiplayer-test-template.ts +217 -0
- package/src/commands/init/name-input.tsx +167 -0
- package/src/commands/init/no-store-scaffold-templates.ts +281 -0
- package/src/commands/init/no-store-scaffold.ts +134 -0
- package/src/commands/init/package-json-scripts.ts +72 -0
- package/src/commands/init/scaffold.ts +960 -0
- package/src/commands/init/sdk-tarball-url.generated.ts +4 -0
- package/src/commands/init/sdk-tarball-url.ts +31 -0
- package/src/commands/init/template-picker.tsx +147 -0
- package/src/commands/inspect-child-entry.ts +107 -0
- package/src/commands/inspect-contract.ts +87 -0
- package/src/commands/inspect-freshness.ts +217 -0
- package/src/commands/inspect-lock.ts +201 -0
- package/src/commands/inspect-options.ts +360 -0
- package/src/commands/inspect-orchestrate.ts +375 -0
- package/src/commands/inspect-process.ts +172 -0
- package/src/commands/inspect-ready.ts +65 -0
- package/src/commands/inspect-report.ts +235 -0
- package/src/commands/inspect-run-state.ts +296 -0
- package/src/commands/inspect-run.ts +157 -0
- package/src/commands/inspect-watchdog.ts +74 -0
- package/src/commands/install-joiner.ts +208 -0
- package/src/commands/login.ts +308 -0
- package/src/commands/models.ts +40 -0
- package/src/commands/parse-options.ts +36 -0
- package/src/commands/remix-package-json.ts +64 -0
- package/src/commands/remix.ts +379 -0
- package/src/commands/sdk-url.ts +141 -0
- package/src/commands/simulations.ts +133 -0
- package/src/commands/skills.ts +108 -0
- package/src/commands/store-files.ts +92 -0
- package/src/commands/stores.ts +703 -0
- package/src/commands/tiles-channel-commands.ts +115 -0
- package/src/commands/tiles-checkout.ts +351 -0
- package/src/commands/tiles-gallery-command.ts +95 -0
- package/src/commands/tiles-get-helpers.ts +27 -0
- package/src/commands/tiles-inspect.ts +276 -0
- package/src/commands/tiles-power-command.ts +308 -0
- package/src/commands/tiles-power-format.ts +396 -0
- package/src/commands/tiles-power-versions.ts +299 -0
- package/src/commands/tiles-publish-helpers.ts +145 -0
- package/src/commands/tiles-upload-command.ts +277 -0
- package/src/commands/tiles-version-commands.ts +201 -0
- package/src/commands/tiles-visibility-command.ts +103 -0
- package/src/commands/tiles.ts +257 -0
- package/src/commands/upgrade.ts +307 -0
- package/src/commit-in-progress.ts +42 -0
- package/src/creator-source-context.ts +97 -0
- package/src/creator-source-publish.ts +52 -0
- package/src/deferred-assets.ts +125 -0
- package/src/distribution.ts +28 -0
- package/src/errors.ts +61 -0
- package/src/install-command.ts +43 -0
- package/src/output.ts +62 -0
- package/src/poe-tile-config-files.ts +100 -0
- package/src/poe-tile-config-players.ts +168 -0
- package/src/poe-tile-config-remix.ts +166 -0
- package/src/poe-tile-config.ts +831 -0
- package/src/power-report-client.ts +55 -0
- package/src/prototype-startup.ts +21 -0
- package/src/publish-change-summary.ts +55 -0
- package/src/publish-overrides-validation.ts +49 -0
- package/src/publish-pack.ts +167 -0
- package/src/publish-phases.ts +57 -0
- package/src/publish-retry.ts +51 -0
- package/src/publish-tile-from-config.ts +434 -0
- package/src/recorder-stream.ts +169 -0
- package/src/remix-provenance.ts +156 -0
- package/src/resolve-client-credential.ts +71 -0
- package/src/resolve-media-uploads.ts +147 -0
- package/src/sdk-dependency.ts +54 -0
- package/src/sdk-skills.ts +85 -0
- package/src/should-skip-client-setup.ts +20 -0
- package/src/simulation-snapshot.ts +123 -0
- package/src/simulation-types.ts +74 -0
- package/src/simulations-client.ts +112 -0
- package/src/source-bundle.ts +466 -0
- package/src/staged-publish-cleanup.ts +44 -0
- package/src/staged-publish-deferred.ts +160 -0
- package/src/staged-publish.ts +401 -0
- package/src/store-file-upload.ts +268 -0
- package/src/store-request.ts +168 -0
- package/src/tar-canonical.ts +41 -0
- package/src/tar-extensions.ts +159 -0
- package/src/tar-extract.ts +193 -0
- package/src/tar-parse.ts +224 -0
- package/src/tar.ts +231 -0
- package/src/template-check-scripts.ts +18 -0
- package/src/tile-gallery-client.ts +82 -0
- package/src/types.ts +258 -0
- package/src/upload-concurrency.ts +54 -0
- package/src/whole-tile.ts +52 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
6
|
+
<meta name="color-scheme" content="light dark">
|
|
7
|
+
<title>{{APP_NAME}}</title>
|
|
8
|
+
<link rel="stylesheet" href="styles.css">
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id="root"></div>
|
|
12
|
+
<script type="module" src="src/entry.tsx"></script>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry point — the only file that imports joiner-sdk.
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
applyNativeAppGestureOverrides,
|
|
6
|
+
createPoe,
|
|
7
|
+
createVerticalScrollBounceMount,
|
|
8
|
+
PostMessageEnvironment,
|
|
9
|
+
} from "joiner-sdk/v1/client.js";
|
|
10
|
+
import { render } from "preact";
|
|
11
|
+
import { todoClientConfig } from "../../client";
|
|
12
|
+
import { App } from "../../ui/App";
|
|
13
|
+
|
|
14
|
+
applyNativeAppGestureOverrides();
|
|
15
|
+
|
|
16
|
+
const environment = new PostMessageEnvironment();
|
|
17
|
+
const Poe = createPoe({ environment });
|
|
18
|
+
const store = Poe.setupStore(todoClientConfig);
|
|
19
|
+
|
|
20
|
+
const root = document.getElementById("root");
|
|
21
|
+
if (root) {
|
|
22
|
+
// Wait for authoritative data (cached locally OR first server pull —
|
|
23
|
+
// whichever wins) before mounting so the UI never paints with empty
|
|
24
|
+
// state on revisit. Resolves immediately when the host sets
|
|
25
|
+
// `is-new` on the parent <poe-tile>, since a fresh instance has no
|
|
26
|
+
// data to load.
|
|
27
|
+
void store.waitForBootstrap().then(
|
|
28
|
+
() => {
|
|
29
|
+
const appRoot = createVerticalScrollBounceMount(root);
|
|
30
|
+
render(<App store={store} />, appRoot);
|
|
31
|
+
},
|
|
32
|
+
() => {
|
|
33
|
+
// Client termination before bootstrap is handled by the host.
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
2
|
+
|
|
3
|
+
@layer base {
|
|
4
|
+
*,
|
|
5
|
+
*::before,
|
|
6
|
+
*::after {
|
|
7
|
+
box-sizing: border-box;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
:root {
|
|
11
|
+
color-scheme: light dark;
|
|
12
|
+
--app-bg-base: #f8f9fa;
|
|
13
|
+
--app-fg-base: #1f2937;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@media (prefers-color-scheme: dark) {
|
|
17
|
+
:root {
|
|
18
|
+
--app-bg-base: #101012;
|
|
19
|
+
--app-fg-base: #f8fafc;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
html,
|
|
24
|
+
body {
|
|
25
|
+
height: 100dvh;
|
|
26
|
+
margin: 0;
|
|
27
|
+
padding: 0;
|
|
28
|
+
overflow: hidden;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
body {
|
|
32
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
33
|
+
background-color: var(--app-bg-base);
|
|
34
|
+
color: var(--app-fg-base);
|
|
35
|
+
-webkit-tap-highlight-color: transparent;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#root {
|
|
39
|
+
height: 100dvh;
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-direction: column;
|
|
42
|
+
overflow-y: auto;
|
|
43
|
+
padding-top: var(--poe-safe-area-inset-top, env(safe-area-inset-top));
|
|
44
|
+
padding-left: var(--poe-safe-area-inset-left, env(safe-area-inset-left));
|
|
45
|
+
padding-right: var(--poe-safe-area-inset-right, env(safe-area-inset-right));
|
|
46
|
+
padding-bottom: var(
|
|
47
|
+
--poe-safe-area-inset-bottom,
|
|
48
|
+
env(safe-area-inset-bottom)
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"jsxImportSource": "preact",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"types": ["bun-types", "vite/client", "joiner-sdk/vite-client"]
|
|
13
|
+
},
|
|
14
|
+
"include": ["tile/src", "synced-store", "ui", "tests", "client.ts"]
|
|
15
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Happy-dom UI tests for the Preact todo app.
|
|
3
|
+
*
|
|
4
|
+
* Renders the App with a real SyncedStoreClient via `createPoeTileTestHarness`.
|
|
5
|
+
* Two clients share the same in-memory backend, which lets us verify that a
|
|
6
|
+
* mutation made by user-2 flows through the sync protocol and appears in
|
|
7
|
+
* user-1's DOM — the core multi-user guarantee of synced-store.
|
|
8
|
+
*/
|
|
9
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
10
|
+
import { cleanup, render, waitFor } from "@testing-library/preact";
|
|
11
|
+
import { createPoeTileTestHarness } from "joiner-sdk/v1/test-utils.js";
|
|
12
|
+
import { todoBackendConfig } from "../synced-store/backend-config";
|
|
13
|
+
import type { TodoSchema } from "../synced-store/schema";
|
|
14
|
+
import { App } from "./App";
|
|
15
|
+
|
|
16
|
+
describe("Todo App UI", () => {
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
cleanup();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("user-1 can add a todo from the UI", async () => {
|
|
22
|
+
const harness = createPoeTileTestHarness<TodoSchema>({
|
|
23
|
+
store: { backendConfig: todoBackendConfig },
|
|
24
|
+
});
|
|
25
|
+
const { store } = await harness.createClient({ userId: "user-1" });
|
|
26
|
+
|
|
27
|
+
const { container } = render(<App store={store} />);
|
|
28
|
+
|
|
29
|
+
await waitFor(() => {
|
|
30
|
+
expect(container.querySelector("#todo-input")).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const input = container.querySelector("#todo-input") as HTMLInputElement;
|
|
34
|
+
const addBtn = container.querySelector("#add-btn") as HTMLButtonElement;
|
|
35
|
+
|
|
36
|
+
input.value = "Buy milk";
|
|
37
|
+
addBtn.click();
|
|
38
|
+
|
|
39
|
+
await waitFor(() => {
|
|
40
|
+
expect(container).toHaveTextContent("Buy milk");
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("todo added by user-2 appears in user-1's UI", async () => {
|
|
45
|
+
const harness = createPoeTileTestHarness<TodoSchema>({
|
|
46
|
+
store: { backendConfig: todoBackendConfig },
|
|
47
|
+
});
|
|
48
|
+
const { store: store1 } = await harness.createClient({ userId: "user-1" });
|
|
49
|
+
const { store: store2 } = await harness.createClient({ userId: "user-2" });
|
|
50
|
+
|
|
51
|
+
const { container } = render(<App store={store1} />);
|
|
52
|
+
|
|
53
|
+
await waitFor(() => {
|
|
54
|
+
expect(container.querySelector("#todo-input")).toBeInTheDocument();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
await store2.mutate.setTodo({
|
|
58
|
+
id: "todo-from-user-2",
|
|
59
|
+
text: "Pick up groceries",
|
|
60
|
+
completed: false,
|
|
61
|
+
createdAt: 1000,
|
|
62
|
+
order: 1,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
await waitFor(() => {
|
|
66
|
+
expect(container).toHaveTextContent("Pick up groceries");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type PoeUserInfo, usableDisplayName } from "joiner-sdk/v1/shared.js";
|
|
2
|
+
import { useEffect, useState } from "preact/hooks";
|
|
3
|
+
import type { TodoItem, TodoStoreClient } from "../client";
|
|
4
|
+
|
|
5
|
+
export function App({ store }: { store: TodoStoreClient }) {
|
|
6
|
+
const [todos, setTodos] = useState<TodoItem[]>([]);
|
|
7
|
+
const [userInfoMap, setUserInfoMap] = useState<Map<string, PoeUserInfo>>(
|
|
8
|
+
new Map(),
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const unsubscribe = store.subscribe(
|
|
13
|
+
(tx) => tx.table("items").entries().toArray(),
|
|
14
|
+
(entries) => {
|
|
15
|
+
const items = entries
|
|
16
|
+
.map(([, v]) => v as TodoItem)
|
|
17
|
+
.sort((a, b) => a.order - b.order);
|
|
18
|
+
setTodos(items);
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
return unsubscribe;
|
|
22
|
+
}, [store]);
|
|
23
|
+
|
|
24
|
+
// Subscribe to the $userInfo system table for display names.
|
|
25
|
+
// $userInfo is auto-populated when a user first connects to the store.
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const unsubscribe = store.subscribe(
|
|
28
|
+
(tx) => tx.table("$userInfo").entries().toArray(),
|
|
29
|
+
(entries) => {
|
|
30
|
+
const map = new Map<string, PoeUserInfo>();
|
|
31
|
+
for (const [, v] of entries) {
|
|
32
|
+
const info = v;
|
|
33
|
+
map.set(info.userId, info);
|
|
34
|
+
}
|
|
35
|
+
setUserInfoMap(map);
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
return unsubscribe;
|
|
39
|
+
}, [store]);
|
|
40
|
+
|
|
41
|
+
function getDisplayName(userId: string): string {
|
|
42
|
+
const info = userInfoMap.get(userId);
|
|
43
|
+
// Never render an internal id (`u_<hex>` / `u_migrated_...` /
|
|
44
|
+
// `private-...`) as a name; the shared masker returns "" when nothing
|
|
45
|
+
// usable is present.
|
|
46
|
+
return usableDisplayName(info) || "Player";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const addTodo = (): void => {
|
|
50
|
+
const input = document.getElementById("todo-input") as HTMLInputElement;
|
|
51
|
+
const text = input.value.trim();
|
|
52
|
+
if (!text) return;
|
|
53
|
+
const now = Date.now();
|
|
54
|
+
const maxOrder = todos.reduce((max, t) => Math.max(max, t.order), 0);
|
|
55
|
+
store.mutate.setTodo({
|
|
56
|
+
id: crypto.randomUUID(),
|
|
57
|
+
text,
|
|
58
|
+
completed: false,
|
|
59
|
+
createdAt: now,
|
|
60
|
+
order: maxOrder + 1,
|
|
61
|
+
});
|
|
62
|
+
input.value = "";
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const toggleTodo = (todo: TodoItem): void => {
|
|
66
|
+
store.mutate.setTodo({ id: todo.id, completed: !todo.completed });
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const deleteTodo = (id: string): void => {
|
|
70
|
+
store.mutate.removeTodo({ id });
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<div>
|
|
75
|
+
<h1>{{ APP_NAME }}</h1>
|
|
76
|
+
<div>
|
|
77
|
+
<input
|
|
78
|
+
id="todo-input"
|
|
79
|
+
placeholder="What needs to be done?"
|
|
80
|
+
onKeyDown={(e) => {
|
|
81
|
+
if (e.key === "Enter") addTodo();
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
84
|
+
<button id="add-btn" type="button" onClick={addTodo}>
|
|
85
|
+
Add
|
|
86
|
+
</button>
|
|
87
|
+
</div>
|
|
88
|
+
<ul id="todo-list">
|
|
89
|
+
{todos.map((todo) => (
|
|
90
|
+
<li key={todo.id}>
|
|
91
|
+
<input
|
|
92
|
+
type="checkbox"
|
|
93
|
+
checked={todo.completed}
|
|
94
|
+
onChange={() => toggleTodo(todo)}
|
|
95
|
+
/>
|
|
96
|
+
<span
|
|
97
|
+
style={{
|
|
98
|
+
textDecoration: todo.completed ? "line-through" : "none",
|
|
99
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
{todo.text}
|
|
102
|
+
</span>
|
|
103
|
+
<span
|
|
104
|
+
style={{ color: "#888", fontSize: "0.85em", marginLeft: "8px" }}
|
|
105
|
+
>
|
|
106
|
+
— {getDisplayName(todo.createdBy)}
|
|
107
|
+
</span>
|
|
108
|
+
<button type="button" onClick={() => deleteTodo(todo.id)}>
|
|
109
|
+
Delete
|
|
110
|
+
</button>
|
|
111
|
+
</li>
|
|
112
|
+
))}
|
|
113
|
+
</ul>
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import preact from "@preact/preset-vite";
|
|
2
|
+
import { poeTile } from "joiner-sdk/vite";
|
|
3
|
+
import { defineConfig } from "vite";
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
root: "tile",
|
|
7
|
+
build: {
|
|
8
|
+
outDir: "../dist",
|
|
9
|
+
emptyOutDir: true,
|
|
10
|
+
rollupOptions: {
|
|
11
|
+
output: {
|
|
12
|
+
entryFileNames: "tile-frontend.js",
|
|
13
|
+
assetFileNames: "[name][extname]",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
plugins: [preact(), poeTile({ backendEntryPoint: "src/backend.ts" })],
|
|
18
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"devDependencies": {
|
|
3
|
+
"@vitejs/plugin-react": "4.7.0",
|
|
4
|
+
"@tailwindcss/postcss": "4.2.2",
|
|
5
|
+
"@testing-library/react": "16.3.2",
|
|
6
|
+
"@types/react": "19.2.14",
|
|
7
|
+
"@types/react-dom": "19.2.3",
|
|
8
|
+
"react": "19.2.5",
|
|
9
|
+
"react-dom": "19.2.5",
|
|
10
|
+
"tailwindcss": "4.2.2"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
6
|
+
<meta name="color-scheme" content="light dark">
|
|
7
|
+
<title>{{APP_NAME}}</title>
|
|
8
|
+
<link rel="stylesheet" href="styles.css">
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id="root"></div>
|
|
12
|
+
<script type="module" src="src/entry.tsx"></script>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry point — the only file that imports joiner-sdk.
|
|
3
|
+
* The App component receives the store as a prop so it can be tested
|
|
4
|
+
* independently without the SDK.
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
applyNativeAppGestureOverrides,
|
|
8
|
+
createPoe,
|
|
9
|
+
createVerticalScrollBounceMount,
|
|
10
|
+
PostMessageEnvironment,
|
|
11
|
+
} from "joiner-sdk/v1/client.js";
|
|
12
|
+
import { createRoot } from "react-dom/client";
|
|
13
|
+
import { todoClientConfig } from "../../client";
|
|
14
|
+
import { App } from "../../ui/App";
|
|
15
|
+
|
|
16
|
+
applyNativeAppGestureOverrides();
|
|
17
|
+
|
|
18
|
+
const environment = new PostMessageEnvironment();
|
|
19
|
+
const Poe = createPoe({ environment });
|
|
20
|
+
const store = Poe.setupStore(todoClientConfig);
|
|
21
|
+
|
|
22
|
+
const root = document.getElementById("root");
|
|
23
|
+
if (root) {
|
|
24
|
+
// Wait for authoritative data (cached locally OR first server pull —
|
|
25
|
+
// whichever wins) before mounting so the UI never paints with empty
|
|
26
|
+
// state on revisit. Resolves immediately when the host sets
|
|
27
|
+
// `is-new` on the parent <poe-tile>, since a fresh instance has no
|
|
28
|
+
// data to load.
|
|
29
|
+
void store.waitForBootstrap().then(
|
|
30
|
+
() => {
|
|
31
|
+
const appRoot = createVerticalScrollBounceMount(root);
|
|
32
|
+
createRoot(appRoot).render(<App store={store} />);
|
|
33
|
+
},
|
|
34
|
+
() => {
|
|
35
|
+
// Client termination before bootstrap is handled by the host.
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
2
|
+
|
|
3
|
+
@layer base {
|
|
4
|
+
*,
|
|
5
|
+
*::before,
|
|
6
|
+
*::after {
|
|
7
|
+
box-sizing: border-box;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
:root {
|
|
11
|
+
color-scheme: light dark;
|
|
12
|
+
--app-bg-base: #f8f9fa;
|
|
13
|
+
--app-fg-base: #1f2937;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@media (prefers-color-scheme: dark) {
|
|
17
|
+
:root {
|
|
18
|
+
--app-bg-base: #101012;
|
|
19
|
+
--app-fg-base: #f8fafc;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
html,
|
|
24
|
+
body {
|
|
25
|
+
height: 100dvh;
|
|
26
|
+
margin: 0;
|
|
27
|
+
padding: 0;
|
|
28
|
+
overflow: hidden;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
body {
|
|
32
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
33
|
+
background-color: var(--app-bg-base);
|
|
34
|
+
color: var(--app-fg-base);
|
|
35
|
+
-webkit-tap-highlight-color: transparent;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#root {
|
|
39
|
+
height: 100dvh;
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-direction: column;
|
|
42
|
+
overflow-y: auto;
|
|
43
|
+
padding-top: var(--poe-safe-area-inset-top, env(safe-area-inset-top));
|
|
44
|
+
padding-left: var(--poe-safe-area-inset-left, env(safe-area-inset-left));
|
|
45
|
+
padding-right: var(--poe-safe-area-inset-right, env(safe-area-inset-right));
|
|
46
|
+
padding-bottom: var(
|
|
47
|
+
--poe-safe-area-inset-bottom,
|
|
48
|
+
env(safe-area-inset-bottom)
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"types": ["bun-types", "vite/client", "joiner-sdk/vite-client"]
|
|
12
|
+
},
|
|
13
|
+
"include": ["tile/src", "synced-store", "ui", "tests", "client.ts"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Happy-dom UI tests for the React todo app.
|
|
3
|
+
*
|
|
4
|
+
* Renders the App with a real SyncedStoreClient via `createPoeTileTestHarness`.
|
|
5
|
+
* Two clients share the same in-memory backend, which lets us verify that a
|
|
6
|
+
* mutation made by user-2 flows through the sync protocol and appears in
|
|
7
|
+
* user-1's DOM — the core multi-user guarantee of synced-store.
|
|
8
|
+
*/
|
|
9
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
10
|
+
import { act, cleanup, render, waitFor } from "@testing-library/react";
|
|
11
|
+
import { createPoeTileTestHarness } from "joiner-sdk/v1/test-utils.js";
|
|
12
|
+
import { todoBackendConfig } from "../synced-store/backend-config";
|
|
13
|
+
import type { TodoSchema } from "../synced-store/schema";
|
|
14
|
+
import { App } from "./App";
|
|
15
|
+
|
|
16
|
+
describe("Todo App UI", () => {
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
cleanup();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("user-1 can add a todo from the UI", async () => {
|
|
22
|
+
const harness = createPoeTileTestHarness<TodoSchema>({
|
|
23
|
+
store: { backendConfig: todoBackendConfig },
|
|
24
|
+
});
|
|
25
|
+
const { store } = await harness.createClient({ userId: "user-1" });
|
|
26
|
+
|
|
27
|
+
const { container } = render(<App store={store} />);
|
|
28
|
+
|
|
29
|
+
await waitFor(() => {
|
|
30
|
+
expect(container.querySelector("#todo-input")).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const input = container.querySelector("#todo-input") as HTMLInputElement;
|
|
34
|
+
const addBtn = container.querySelector("#add-btn") as HTMLButtonElement;
|
|
35
|
+
|
|
36
|
+
await act(async () => {
|
|
37
|
+
input.value = "Buy milk";
|
|
38
|
+
addBtn.click();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
await waitFor(() => {
|
|
42
|
+
expect(container).toHaveTextContent("Buy milk");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("todo added by user-2 appears in user-1's UI", async () => {
|
|
47
|
+
const harness = createPoeTileTestHarness<TodoSchema>({
|
|
48
|
+
store: { backendConfig: todoBackendConfig },
|
|
49
|
+
});
|
|
50
|
+
const { store: store1 } = await harness.createClient({ userId: "user-1" });
|
|
51
|
+
const { store: store2 } = await harness.createClient({ userId: "user-2" });
|
|
52
|
+
|
|
53
|
+
const { container } = render(<App store={store1} />);
|
|
54
|
+
|
|
55
|
+
await waitFor(() => {
|
|
56
|
+
expect(container.querySelector("#todo-input")).toBeInTheDocument();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
await store2.mutate.setTodo({
|
|
60
|
+
id: "todo-from-user-2",
|
|
61
|
+
text: "Pick up groceries",
|
|
62
|
+
completed: false,
|
|
63
|
+
createdAt: 1000,
|
|
64
|
+
order: 1,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
await waitFor(() => {
|
|
68
|
+
expect(container).toHaveTextContent("Pick up groceries");
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { useLiveQuery } from "joiner-sdk/v1/react";
|
|
2
|
+
import { type PoeUserInfo, usableDisplayName } from "joiner-sdk/v1/shared.js";
|
|
3
|
+
import { type ReactNode, useCallback, useMemo } from "react";
|
|
4
|
+
import type { TodoItem, TodoStoreClient } from "../client";
|
|
5
|
+
|
|
6
|
+
export function App({ store }: { store: TodoStoreClient }): ReactNode {
|
|
7
|
+
// Wrap queryFns in useCallback so the subscription doesn't reset every render
|
|
8
|
+
// (useLiveQuery deps on the queryFn reference).
|
|
9
|
+
const { data: rawTodos } = useLiveQuery(
|
|
10
|
+
store,
|
|
11
|
+
useCallback(async (tx) => tx.table("items").entries().toArray(), []),
|
|
12
|
+
);
|
|
13
|
+
const todos = useMemo(
|
|
14
|
+
() =>
|
|
15
|
+
(rawTodos ?? [])
|
|
16
|
+
.map(([, v]) => v as TodoItem)
|
|
17
|
+
.sort((a, b) => a.order - b.order),
|
|
18
|
+
[rawTodos],
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
// $userInfo is auto-populated when a user first connects to the store.
|
|
22
|
+
const { data: rawUserInfo } = useLiveQuery(
|
|
23
|
+
store,
|
|
24
|
+
useCallback(async (tx) => tx.table("$userInfo").entries().toArray(), []),
|
|
25
|
+
);
|
|
26
|
+
const userInfoMap = useMemo(() => {
|
|
27
|
+
const map = new Map<string, PoeUserInfo>();
|
|
28
|
+
for (const [, v] of rawUserInfo ?? []) {
|
|
29
|
+
const info = v;
|
|
30
|
+
map.set(info.userId, info);
|
|
31
|
+
}
|
|
32
|
+
return map;
|
|
33
|
+
}, [rawUserInfo]);
|
|
34
|
+
|
|
35
|
+
function getDisplayName(userId: string): string {
|
|
36
|
+
const info = userInfoMap.get(userId);
|
|
37
|
+
// Never render an internal id (`u_<hex>` / `u_migrated_...` /
|
|
38
|
+
// `private-...`) as a name; the shared masker returns "" when nothing
|
|
39
|
+
// usable is present.
|
|
40
|
+
return usableDisplayName(info) || "Player";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const addTodo = (): void => {
|
|
44
|
+
const input = document.getElementById("todo-input") as HTMLInputElement;
|
|
45
|
+
const text = input.value.trim();
|
|
46
|
+
if (!text) return;
|
|
47
|
+
const now = Date.now();
|
|
48
|
+
const maxOrder = todos.reduce((max, t) => Math.max(max, t.order), 0);
|
|
49
|
+
store.mutate.setTodo({
|
|
50
|
+
id: crypto.randomUUID(),
|
|
51
|
+
text,
|
|
52
|
+
completed: false,
|
|
53
|
+
createdAt: now,
|
|
54
|
+
order: maxOrder + 1,
|
|
55
|
+
});
|
|
56
|
+
input.value = "";
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const toggleTodo = (todo: TodoItem): void => {
|
|
60
|
+
store.mutate.setTodo({ id: todo.id, completed: !todo.completed });
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const deleteTodo = (id: string): void => {
|
|
64
|
+
store.mutate.removeTodo({ id });
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div>
|
|
69
|
+
<h1>{{ APP_NAME }}</h1>
|
|
70
|
+
<div>
|
|
71
|
+
<input
|
|
72
|
+
id="todo-input"
|
|
73
|
+
placeholder="What needs to be done?"
|
|
74
|
+
onKeyDown={(e) => {
|
|
75
|
+
if (e.key === "Enter") addTodo();
|
|
76
|
+
}}
|
|
77
|
+
/>
|
|
78
|
+
<button id="add-btn" type="button" onClick={addTodo}>
|
|
79
|
+
Add
|
|
80
|
+
</button>
|
|
81
|
+
</div>
|
|
82
|
+
<ul id="todo-list">
|
|
83
|
+
{todos.map((todo) => (
|
|
84
|
+
<li key={todo.id}>
|
|
85
|
+
<input
|
|
86
|
+
type="checkbox"
|
|
87
|
+
checked={todo.completed}
|
|
88
|
+
onChange={() => toggleTodo(todo)}
|
|
89
|
+
/>
|
|
90
|
+
<span
|
|
91
|
+
style={{
|
|
92
|
+
textDecoration: todo.completed ? "line-through" : "none",
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
{todo.text}
|
|
96
|
+
</span>
|
|
97
|
+
<span
|
|
98
|
+
style={{ color: "#888", fontSize: "0.85em", marginLeft: "8px" }}
|
|
99
|
+
>
|
|
100
|
+
— {getDisplayName(todo.createdBy)}
|
|
101
|
+
</span>
|
|
102
|
+
<button type="button" onClick={() => deleteTodo(todo.id)}>
|
|
103
|
+
Delete
|
|
104
|
+
</button>
|
|
105
|
+
</li>
|
|
106
|
+
))}
|
|
107
|
+
</ul>
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import react from "@vitejs/plugin-react";
|
|
2
|
+
import { poeTile } from "joiner-sdk/vite";
|
|
3
|
+
import { defineConfig, type PluginOption } from "vite";
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
root: "tile",
|
|
7
|
+
build: {
|
|
8
|
+
outDir: "../dist",
|
|
9
|
+
emptyOutDir: true,
|
|
10
|
+
rollupOptions: {
|
|
11
|
+
output: {
|
|
12
|
+
entryFileNames: "tile-frontend.js",
|
|
13
|
+
assetFileNames: "[name][extname]",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
plugins: [
|
|
18
|
+
react() as PluginOption,
|
|
19
|
+
poeTile({ backendEntryPoint: "src/backend.ts" }),
|
|
20
|
+
],
|
|
21
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
/**
|
|
3
|
+
* Removes generated template dirs.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { rmSync } from "node:fs";
|
|
7
|
+
import { GENERATED_APPS_DIR } from "./paths.ts";
|
|
8
|
+
|
|
9
|
+
rmSync(GENERATED_APPS_DIR, { recursive: true, force: true });
|
|
10
|
+
console.log(" Removed: generated-apps/");
|