@jtfmumm/patchwork-standalone-frame 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 ADDED
@@ -0,0 +1,34 @@
1
+ # @jtfmumm/patchwork-standalone-frame
2
+
3
+ A reusable standalone frame for patchwork tools. Provides keyhive initialization, repo setup, doc history, access control, top bar UI, and sharing modals.
4
+
5
+ ## Usage
6
+
7
+ ```typescript
8
+ import { mountStandaloneApp, type ToolRegistration } from "@jtfmumm/patchwork-standalone-frame";
9
+
10
+ const myTool: ToolRegistration<MyDoc> = {
11
+ id: "my-tool", // matches @patchwork.type
12
+ name: "My Tool", // display name
13
+ defaultTitle: "Untitled", // placeholder for new docs
14
+ init: (doc, repo) => {
15
+ // Initialize a blank document
16
+ },
17
+ getTitle: (doc) => doc.title || "Untitled",
18
+ setTitle: (doc, title) => { doc.title = title; },
19
+ isDocReady: (doc) => !!doc?.title,
20
+ render: (handle, element) => {
21
+ // Mount your UI into `element`, return a cleanup function
22
+ },
23
+ };
24
+
25
+ const root = document.getElementById("root");
26
+ if (root) mountStandaloneApp(root, myTool);
27
+ ```
28
+
29
+ ## Sync server
30
+
31
+ The sync server URL is resolved in this order:
32
+ 1. `VITE_SYNC_URL` environment variable
33
+ 2. `tool.syncUrl` from the registration
34
+ 3. `ws://localhost:3030` (default)
@@ -0,0 +1,10 @@
1
+ interface ConfirmModalProps {
2
+ isOpen: boolean;
3
+ title: string;
4
+ message: string;
5
+ confirmLabel?: string;
6
+ onConfirm: () => void;
7
+ onCancel: () => void;
8
+ }
9
+ export declare function ConfirmModal(props: ConfirmModalProps): import("solid-js").JSX.Element;
10
+ export {};
@@ -0,0 +1,10 @@
1
+ export interface DocHistoryEntry {
2
+ url: string;
3
+ title: string;
4
+ lastOpened: number;
5
+ }
6
+ export declare function activeDocKey(toolId: string, identityHexId: string): string;
7
+ export declare function loadHistory(toolId: string, identityHexId: string): DocHistoryEntry[];
8
+ export declare function upsertHistory(toolId: string, identityHexId: string, url: string, title: string): DocHistoryEntry[];
9
+ export declare function removeFromHistory(toolId: string, identityHexId: string, url: string): DocHistoryEntry[];
10
+ export declare function truncateUrl(url: string): string;
@@ -0,0 +1,10 @@
1
+ import { type AutomergeRepoKeyhive } from "@automerge/automerge-repo-keyhive";
2
+ import type { ToolRegistration } from "./index.ts";
3
+ declare global {
4
+ interface Window {
5
+ hive?: AutomergeRepoKeyhive;
6
+ }
7
+ }
8
+ export declare function StandaloneApp<D>(props: {
9
+ tool: ToolRegistration<D>;
10
+ }): import("solid-js").JSX.Element;
@@ -0,0 +1,22 @@
1
+ import type { Repo, DocHandle } from "@automerge/automerge-repo";
2
+ import type { AutomergeRepoKeyhive } from "@automerge/automerge-repo-keyhive";
3
+ export interface ToolElement extends HTMLDivElement {
4
+ repo: Repo;
5
+ hive?: AutomergeRepoKeyhive;
6
+ }
7
+ export interface ToolRegistration<D = unknown> {
8
+ id: string;
9
+ name: string;
10
+ defaultTitle: string;
11
+ init: (doc: D, repo: Repo) => void;
12
+ getTitle: (doc: D) => string;
13
+ syncUrl?: string;
14
+ setTitle?: (doc: D, title: string) => void;
15
+ isDocReady?: (doc: D) => boolean;
16
+ render: (handle: DocHandle<D>, element: ToolElement) => (() => void);
17
+ }
18
+ export { mountStandaloneApp } from "./mount.tsx";
19
+ export { ShareModal } from "./share-modal.tsx";
20
+ export { ConfirmModal } from "./confirm-modal.tsx";
21
+ export { NewDocModal } from "./new-doc-modal.tsx";
22
+ export { overlayStyle, cardStyle } from "./modal-styles.ts";