use-chisel 0.1.0 → 0.1.2

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 CHANGED
@@ -1,16 +1,55 @@
1
1
  # use-chisel
2
2
 
3
+ ## Combined Workspace
4
+
5
+ `use-chisel/workspace` exports `ChiselWorkspace`, `ChiselPreview`,
6
+ `ChiselWorkspaceStyles`, and the `WorkspaceUser` type. Mount `ChiselPreview`
7
+ in your layout and render `ChiselWorkspace` in an authenticated `/chisel` route.
8
+ Pass `user`, `validateSession: () => Promise<boolean>`, and
9
+ `signOut: () => Promise<void>` through a client component. Authentication and
10
+ route handling belong to the host app; see the repository demo for Supabase Auth
11
+ with Google.
12
+
13
+ Edit, Comment, and View share one toolbar. Threads expand from element pins;
14
+ history appears in the sidebar.
15
+ Use **E** for Edit, **C** for Comment, and **V** for View. **Shift+C** toggles
16
+ all comment pins, threads, and the comments sidebar. Shortcuts are ignored
17
+ while typing in form fields or editable content. Comments are browser-local by
18
+ default. Pass a `CommentStore` with `list()` and `mutate(change)` to share them;
19
+ mutations create a comment, edit its proposal, append one reply, or resolve a
20
+ thread. Implement optional `delete(id)` to expose deletion for authors and site
21
+ owners; enforce these permissions in the backend. Keep the client-generated
22
+ comment/reply UUID when retrying a failed mutation so the adapter can make writes
23
+ idempotent. The demo uses authenticated Supabase endpoints with server-derived
24
+ authors; see `apps/demo/lib/comments.ts` and `supabase/` for its adapter, migrations,
25
+ and reviewer access policies.
26
+ `canManageComments` exposes management controls for other reviewers’ threads; optional
27
+ `getReviewLink(rotate?)` enables sharing a client review link.
28
+ The host must enforce
29
+ these permissions in its backend as the demo does. The tweak editor is development-only. The standalone API below remains
30
+ supported.
31
+
32
+ To close reviews when a site goes live, disable the preview integration and
33
+ return 404 from the workspace route on the server. The demo host implements this
34
+ with `CHISEL_ENABLED=0`; production defaults off and staging explicitly sets `1`.
35
+ This is host configuration, not a client-side security toggle in the npm package.
36
+
3
37
  Dev-only visual editing layer for Next.js apps.
4
38
 
39
+ Supports Next.js 14 through 16 with React 18 or 19, including both App Router and Pages Router projects.
40
+
5
41
  ## Install
6
42
 
7
43
  ```bash
8
44
  npm install use-chisel
9
45
  ```
10
46
 
47
+ Run `npx chisel` to open the hosted Chisel sign-in page. Connecting your project
48
+ to the hosted workspace is not available yet.
49
+
11
50
  ## Use
12
51
 
13
- Mount `Chisel` in your app layout during development:
52
+ Mount `Chisel` in your app layout:
14
53
 
15
54
  ```tsx
16
55
  import { Chisel } from "use-chisel"
@@ -20,13 +59,19 @@ export default function RootLayout({ children }: { children: React.ReactNode })
20
59
  <html lang="en">
21
60
  <body>
22
61
  {children}
23
- {process.env.NODE_ENV === "development" ? <Chisel /> : null}
62
+ <Chisel />
24
63
  </body>
25
64
  </html>
26
65
  )
27
66
  }
28
67
  ```
29
68
 
69
+ Open any route with `?editor` to show the editor:
70
+
71
+ ```txt
72
+ http://localhost:3000?editor
73
+ ```
74
+
30
75
  Add `EditableRegion` when you want copied prompts to include stable source hints:
31
76
 
32
77
  ```tsx
@@ -35,8 +80,28 @@ import { EditableRegion } from "use-chisel"
35
80
  <EditableRegion id="homepage.hero.title">Launch faster</EditableRegion>
36
81
  ```
37
82
 
83
+ Chisel persists route versions in the browser. Local image files are previewed only for the current session; after a reload, re-select the file when prompted. Chisel inspects same-document light DOM. Cross-origin iframes and closed shadow roots are not supported.
84
+
38
85
  ## Publish
39
86
 
40
87
  ```bash
41
88
  npm publish --workspace use-chisel --access public
42
89
  ```
90
+
91
+ A realtime comment adapter can implement optional `CommentStore.subscribe(onChange)`;
92
+ return an unsubscribe function. The workspace refreshes after notifications instead
93
+ of its fallback polling interval. Optional `collaboration` props provide online
94
+ reviewers, page presence, unread thread IDs, and read tracking. A realtime adapter should refresh on reconnect/focus and recover
95
+ when its connection is unavailable. Only acknowledge message activity the reviewer
96
+ has actually seen. The demo's Supabase integration uses these interfaces without
97
+ adding a database SDK dependency to this package.
98
+
99
+ Optional `commentUI` renderers can replace the thread and composer while retaining
100
+ Chisel's workspace behavior. The composer receives
101
+ `renderContent(editor, hasAttachments?, uploading?)` to keep settings, Cancel,
102
+ dictation, and explicit submit in the same form. Custom rich text can be passed as
103
+ optional mutation `body`, with validated upload IDs in `attachmentTokens`. Adapters
104
+ must validate both before storing them and bind uploads to the authenticated user
105
+ and site. Keep the editor and attachment draft when `onSubmit` or `onReply` returns
106
+ `false`; release it only after a successful save. Slate and Supabase remain demo
107
+ dependencies. The built-in local UI remains available without either dependency.
package/bin/chisel.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+
4
+ const url = "https://chisel-review.vercel.app/chisel/start";
5
+ console.log(`Open ${url} to sign in to Chisel.`);
6
+ const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "rundll32" : "xdg-open";
7
+ const args = process.platform === "win32" ? ["url.dll,FileProtocolHandler", url] : [url];
8
+ const browser = spawn(command, args, { detached: true, stdio: "ignore" });
9
+ browser.on("error", () => console.error("Could not open a browser. Open the link above instead."));
10
+ browser.unref();
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export type ChiselProps = {
3
3
  enabled?: boolean;
4
4
  position?: "left" | "right";
5
5
  projectName?: string;
6
+ embedded?: boolean;
6
7
  };
7
8
  export type DOMRectJSON = {
8
9
  x: number;
@@ -34,11 +35,16 @@ export type EditIntent = {
34
35
  before: string | number | null;
35
36
  after: string | number;
36
37
  }>;
38
+ asset?: {
39
+ fileName: string;
40
+ mimeType: string;
41
+ size: number;
42
+ };
37
43
  };
38
44
  type EditableRegionProps = React.HTMLAttributes<HTMLSpanElement> & {
39
45
  id: string;
40
- as?: keyof JSX.IntrinsicElements;
46
+ as?: keyof React.JSX.IntrinsicElements;
41
47
  };
42
48
  export declare function EditableRegion({ id, as, children, ...props }: EditableRegionProps): React.JSX.Element;
43
- export declare function Chisel({ enabled, position, projectName }: ChiselProps): React.JSX.Element | null;
49
+ export declare function Chisel({ enabled, position, projectName, embedded }: ChiselProps): React.JSX.Element | null;
44
50
  export {};