@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 +34 -0
- package/dist/confirm-modal.d.ts +10 -0
- package/dist/doc-history.d.ts +10 -0
- package/dist/frame.d.ts +10 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +711 -0
- package/dist/modal-styles.d.ts +17 -0
- package/dist/mount.d.ts +2 -0
- package/dist/new-doc-modal.d.ts +8 -0
- package/dist/share-modal.d.ts +10 -0
- package/dist/url-hash.d.ts +3 -0
- package/package.json +39 -0
- package/src/confirm-modal.tsx +68 -0
- package/src/doc-history.ts +58 -0
- package/src/frame.tsx +660 -0
- package/src/index.ts +25 -0
- package/src/modal-styles.ts +18 -0
- package/src/mount.tsx +10 -0
- package/src/new-doc-modal.tsx +98 -0
- package/src/share-modal.tsx +349 -0
- package/src/url-hash.ts +13 -0
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;
|
package/dist/frame.d.ts
ADDED
|
@@ -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;
|
package/dist/index.d.ts
ADDED
|
@@ -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";
|