@ohhwells/bridge 0.1.24 → 0.1.25

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,327 +1,304 @@
1
- # @ohhwells/bridge
2
-
3
- The OhhWells canvas editor bridge — a standalone npm package that enables inline text and image editing for any site deployed on the OhhWells platform.
4
-
5
- ## What it does
6
-
7
- When a studio owner opens their site in the OhhWells canvas editor, the bridge:
8
-
9
- - Connects the iframe (the live site) to the parent canvas editor via `postMessage`
10
- - Enables click-to-edit for text, images, and background images
11
- - Handles draft saving and content hydration
12
- - Shows the "Add Section" insert line between sections in the canvas editor
13
- - Provides state toggle UI for editing hidden content (hover states, form views)
14
- - Injects scoped styles that never leak into the host template
15
-
16
- ---
17
-
18
- ## Installation
19
-
20
- ```bash
21
- npm install @ohhwells/bridge
22
- ```
23
-
24
- ---
25
-
26
- ## Template setup (required steps)
27
-
28
- ### 1. Import styles
29
-
30
- In your root layout file, import the bridge stylesheet **once**:
31
-
32
- ```ts
33
- import '@ohhwells/bridge/styles'
34
- ```
35
-
36
- ### 2. Add the loader surface
37
-
38
- The loader is a full-screen spinner shown while the bridge fetches personalised content. It hides itself once content is ready. Add this **before** your main content in the `<body>`:
39
-
40
- ```tsx
41
- import { OHW_LOADER_STYLE, OhwLoaderSpinner } from '@ohhwells/bridge'
42
-
43
- // Inside <body>:
44
- <div
45
- id="ohw-loader"
46
- suppressHydrationWarning
47
- style={{ ...OHW_LOADER_STYLE, display: 'none' }}
48
- >
49
- <OhwLoaderSpinner />
50
- </div>
51
-
52
- {/* Inline script — shows the loader immediately on the client before React hydrates */}
53
- <script
54
- dangerouslySetInnerHTML={{
55
- __html: `(function(){try{
56
- var p=location.hostname.split(".");
57
- var fromHost=p.length>=3&&p[0]!=="www"?p[0]:"";
58
- var fromQuery=new URLSearchParams(location.search).get("subdomain")||"";
59
- if(!fromHost&&!fromQuery)return;
60
- var e=document.getElementById("ohw-loader");
61
- if(e)e.style.display="flex"
62
- }catch(e){}})();`,
63
- }}
64
- />
65
- ```
66
-
67
- The inline script detects whether the page is being loaded under a subdomain (personalised content mode) and shows the loader before React has a chance to hydrate, preventing a flash of the default content.
68
-
69
- ### 3. Mount `OhhwellsBridge`
70
-
71
- Add `<OhhwellsBridge />` inside a `<Suspense>` boundary in your root layout. It must be in `<Suspense>` because it calls `useSearchParams()` internally.
72
-
73
- ```tsx
74
- import { Suspense } from 'react'
75
- import { OhhwellsBridge } from '@ohhwells/bridge'
76
-
77
- export default function RootLayout({ children }) {
78
- return (
79
- <html lang="en">
80
- <body>
81
- {/* loader + inline script here (see step 2) */}
82
-
83
- <Suspense>
84
- <OhhwellsBridge />
85
- </Suspense>
86
-
87
- {/* rest of your layout */}
88
- {children}
89
- </body>
90
- </html>
91
- )
92
- }
93
- ```
94
-
95
- The bridge activates automatically when the page is loaded inside the OhhWells canvas editor. It does nothing in production (live site) mode.
96
-
97
- ### 4. Mark sections
98
-
99
- Every top-level section on each page must have a unique `data-ohw-section` attribute. This is what the canvas editor uses to:
100
- - Show the "Add Section" insert line between sections
101
- - Persist widget insertions (saving which section a widget was inserted after)
102
-
103
- ```tsx
104
- // Good section element is the direct content root
105
- <section data-ohw-section="hero">
106
- ...
107
- </section>
108
-
109
- // Also fine — any element type works
110
- <div data-ohw-section="testimonials">
111
- ...
112
- </div>
113
- ```
114
-
115
- **Naming rules:**
116
- - Use `kebab-case`
117
- - Must be unique across the entire page
118
- - Must be stable — if a section is renamed, any saved widget insertions referencing that name will break
119
-
120
- **Example a page with multiple sections:**
121
-
122
- ```tsx
123
- export default function HomePage() {
124
- return (
125
- <>
126
- <section data-ohw-section="hero">...</section>
127
- <section data-ohw-section="lagree-intro">...</section>
128
- <section data-ohw-section="classes-strip">...</section>
129
- <section data-ohw-section="testimonials">...</section>
130
- <section data-ohw-section="plan-form">...</section>
131
- </>
132
- )
133
- }
134
- ```
135
-
136
- ### 5. Mark editable elements
137
-
138
- Add `data-ohw-editable` and `data-ohw-key` to any element the studio owner should be able to edit:
139
-
140
- ```tsx
141
- {/* Editable rich text (bold, italic, etc.) */}
142
- <h1
143
- data-ohw-editable="text"
144
- data-ohw-key="hero-heading"
145
- >
146
- Welcome to the studio
147
- </h1>
148
-
149
- {/* Editable plain text (no formatting) */}
150
- <p
151
- data-ohw-editable="plain"
152
- data-ohw-key="hero-subtitle"
153
- >
154
- Book your first class
155
- </p>
156
-
157
- {/* Editable image */}
158
- <img
159
- data-ohw-editable="image"
160
- data-ohw-key="hero-image"
161
- src="/hero.jpg"
162
- alt="Hero"
163
- />
164
-
165
- {/* Editable background image */}
166
- <div
167
- data-ohw-editable="bg-image"
168
- data-ohw-key="hero-bg"
169
- style={{ backgroundImage: 'url(/bg.jpg)' }}
170
- />
171
- ```
172
-
173
- **Key naming rules:**
174
- - Must be globally unique across all pages
175
- - Use `kebab-case`
176
- - Must be stable — changing a key orphans any saved content for that element
177
-
178
- ---
179
-
180
- ## SchedulingWidget (vibe-coder placement)
181
-
182
- `SchedulingWidget` lets a template builder embed a scheduling/booking section directly in their template JSX, without going through the "Add Section" flow. The canvas editor treats it exactly like a dynamically-inserted scheduling widget — the studio owner can connect a schedule, switch it, and clear it.
183
-
184
- ### Basic usage
185
-
186
- ```tsx
187
- import { SchedulingWidget } from '@ohhwells/bridge'
188
-
189
- export default function ClassesPage() {
190
- return (
191
- <>
192
- <PageHeader ... />
193
- <ClassLibrary ... />
194
- <SchedulingWidget />
195
- <WordmarkBand ... />
196
- </>
197
- )
198
- }
199
- ```
200
-
201
- No props are required. The widget auto-generates a stable identity via React's `useId()` so the bridge can track which schedule is connected to it across saves.
202
-
203
- ### Props
204
-
205
- | Prop | Type | Default | Description |
206
- |---|---|---|---|
207
- | `insertAfter` | `string` | auto | Stable identifier used as the tracker key. Only set this manually if you need two `SchedulingWidget`s on the same page. |
208
- | `initialScheduleId` | `string \| null` | `undefined` | Set by the bridge internally after hydration. Do not pass this yourself. |
209
- | `notifyOnConnect` | `boolean` | `false` | Set by the bridge internally. Do not pass this yourself. |
210
-
211
- ### How it works
212
-
213
- 1. The widget renders immediately with a loading skeleton.
214
- 2. It sends `ow:request-schedule-config` to the bridge (running in the same window).
215
- 3. The bridge looks up the tracker for a saved `scheduleId` for this widget:
216
- - **Found** → responds with `ow:schedule-config { scheduleId }` → widget loads that schedule.
217
- - **Not found (first time)** → bridge adopts the widget (adds it to the tracker, notifies the canvas editor), responds with `scheduleId: null` → widget shows empty state with an "Add Schedule" button.
218
- 4. In the canvas editor, the studio owner clicks "Add Schedule" → selects a schedule → the widget updates and the connection is saved.
219
- 5. On the live site, the widget fetches the saved schedule by ID and renders it.
220
-
221
- ### Multiple widgets on one page
222
-
223
- Each `SchedulingWidget` must have a unique `insertAfter` to be tracked independently:
224
-
225
- ```tsx
226
- <SchedulingWidget insertAfter="classes-morning" />
227
- <SchedulingWidget insertAfter="classes-evening" />
228
- ```
229
-
230
- If you omit `insertAfter` on both, `useId()` auto-generates different stable IDs for each, so they are tracked separately anyway.
231
-
232
- ### Empty state on live site
233
-
234
- If the studio owner has never connected a schedule to this widget, it renders nothing on the live site (no empty placeholder is shown to visitors).
235
-
236
- ---
237
-
238
- ## Editable states (advanced)
239
-
240
- For elements with multiple display states (e.g. a contact form with default/success/error views), wrap each state in a `data-ohw-state-view` and mark the container with `data-ohw-editable-state`:
241
-
242
- ```tsx
243
- <div
244
- data-ohw-editable-state="default,success,error"
245
- data-ohw-key="contact-form"
246
- >
247
- <div data-ohw-state-view="default">
248
- {/* default form UI */}
249
- </div>
250
- <div data-ohw-state-view="success">
251
- {/* success message */}
252
- </div>
253
- <div data-ohw-state-view="error">
254
- {/* error message */}
255
- </div>
256
- </div>
257
- ```
258
-
259
- The bridge shows a state toggle in the canvas editor to switch between states.
260
-
261
- ---
262
-
263
- ## Local development workflow
264
-
265
- When iterating on the bridge package itself:
266
-
267
- ```bash
268
- # 1. Build the package
269
- cd ohhwells-bridge
270
- npm run build
271
-
272
- # 2. Link it globally (one-time setup)
273
- npm link
274
-
275
- # 3. In your template repo, use the local build instead of the npm version
276
- cd rebound-template
277
- npm link @ohhwells/bridge
278
- ```
279
-
280
- After that, every `npm run build` in `ohhwells-bridge` is picked up by the template immediately (no re-link needed). To go back to the npm version:
281
-
282
- ```bash
283
- cd rebound-template
284
- npm unlink @ohhwells/bridge
285
- npm install
286
- ```
287
-
288
- ---
289
-
290
- ## Publishing
291
-
292
- The package publishes automatically via GitHub Actions on push to `main` (production tag) or `staging` (next tag). To publish manually:
293
-
294
- ```bash
295
- npm run build
296
- npm publish --access public
297
- ```
298
-
299
- ---
300
-
301
- ## Design tokens
302
-
303
- The package ships the full OhhWells design token set, scoped to `[data-ohw-bridge-root]` so styles never leak into the host template.
304
-
305
- ### Semantic colors (CSS variables on `[data-ohw-bridge-root]`)
306
-
307
- | Token | Light | Dark |
308
- |---|---|---|
309
- | `primary` | `#0f172a` | `#f8fafc` |
310
- | `primary-foreground` | `#f8fafc` | `#0f172a` |
311
- | `background` | `#ffffff` | `#020617` |
312
- | `foreground` | `#020617` | `#f8fafc` |
313
- | `muted` | `#f1f5f9` | `#1e293b` |
314
- | `muted-foreground` | `#64748b` | `#94a3b8` |
315
- | `border` | `#e2e8f0` | `#334155` |
316
- | `destructive` | `#dc2626` | `#7f1d1d` |
317
- | `success` | `#16a34a` | `#22c55e` |
318
-
319
- ### Brand palette
320
-
321
- Re:Bound brand colors: `bone`, `ivory`, `sand`, `linen`, `stone`, `clay`, `umber`, `umber-deep`, `espresso`, `clove`, `ink`, `ash`, `carbon`.
322
-
323
- ---
324
-
325
- ## License
326
-
327
- MIT
1
+ # @ohhwells/bridge
2
+
3
+ The OhhWells canvas editor bridge — a standalone npm package that enables inline text and image editing for any site deployed on the OhhWells platform.
4
+
5
+ ## What it does
6
+
7
+ When a studio owner opens their site in the OhhWells canvas editor, the bridge:
8
+
9
+ - Connects the iframe (the live site) to the parent canvas editor via `postMessage`
10
+ - Enables click-to-edit for text, images, and background images
11
+ - Handles draft saving and content hydration
12
+ - Shows the "Add Section" insert line between sections in the canvas editor
13
+ - Provides state toggle UI for editing hidden content (hover states, form views)
14
+ - Injects scoped styles that never leak into the host template
15
+
16
+ ---
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @ohhwells/bridge
22
+ ```
23
+
24
+ ---
25
+
26
+ ## Template setup (required steps)
27
+
28
+ ### 1. Import styles
29
+
30
+ In your root layout file, import the bridge stylesheet **once**:
31
+
32
+ ```ts
33
+ import "@ohhwells/bridge/styles";
34
+ ```
35
+
36
+ ### 2. Add the loader surface
37
+
38
+ The loader is a full-screen spinner shown while the bridge fetches personalised content. It hides itself once content is ready. Add this **before** your main content in the `<body>`:
39
+
40
+ ```tsx
41
+ import { OHW_LOADER_STYLE, OhwLoaderSpinner } from "@ohhwells/bridge";
42
+
43
+ // Inside <body>:
44
+ <div
45
+ id="ohw-loader"
46
+ suppressHydrationWarning
47
+ style={{ ...OHW_LOADER_STYLE, display: "none" }}
48
+ >
49
+ <OhwLoaderSpinner />
50
+ </div>;
51
+
52
+ {
53
+ /* Inline script — shows the loader immediately on the client before React hydrates */
54
+ }
55
+ <script
56
+ dangerouslySetInnerHTML={{
57
+ __html: `(function(){try{
58
+ var p=location.hostname.split(".");
59
+ var fromHost=p.length>=3&&p[0]!=="www"?p[0]:"";
60
+ var fromQuery=new URLSearchParams(location.search).get("subdomain")||"";
61
+ if(!fromHost&&!fromQuery)return;
62
+ var e=document.getElementById("ohw-loader");
63
+ if(e)e.style.display="flex"
64
+ }catch(e){}})();`,
65
+ }}
66
+ />;
67
+ ```
68
+
69
+ The inline script detects whether the page is being loaded under a subdomain (personalised content mode) and shows the loader before React has a chance to hydrate, preventing a flash of the default content.
70
+
71
+ ### 3. Mount `OhhwellsBridge`
72
+
73
+ Add `<OhhwellsBridge />` inside a `<Suspense>` boundary in your root layout. It must be in `<Suspense>` because it calls `useSearchParams()` internally.
74
+
75
+ ```tsx
76
+ import { Suspense } from "react";
77
+ import { OhhwellsBridge } from "@ohhwells/bridge";
78
+
79
+ export default function RootLayout({ children }) {
80
+ return (
81
+ <html lang="en">
82
+ <body>
83
+ {/* loader + inline script here (see step 2) */}
84
+
85
+ <Suspense>
86
+ <OhhwellsBridge />
87
+ </Suspense>
88
+
89
+ {/* rest of your layout */}
90
+ {children}
91
+ </body>
92
+ </html>
93
+ );
94
+ }
95
+ ```
96
+
97
+ The bridge activates automatically when the page is loaded inside the OhhWells canvas editor. It does nothing in production (live site) mode.
98
+
99
+ ### 4. Mark sections
100
+
101
+ Every top-level section on each page must have a unique `data-ohw-section` attribute. This is what the canvas editor uses to:
102
+
103
+ - Show the "Add Section" insert line between sections
104
+ - Persist widget insertions (saving which section a widget was inserted after)
105
+
106
+ ```tsx
107
+ // Good — section element is the direct content root
108
+ <section data-ohw-section="hero">
109
+ ...
110
+ </section>
111
+
112
+ // Also fine — any element type works
113
+ <div data-ohw-section="testimonials">
114
+ ...
115
+ </div>
116
+ ```
117
+
118
+ **Naming rules:**
119
+
120
+ - Use `kebab-case`
121
+ - Must be unique across the entire page
122
+ - Must be stable — if a section is renamed, any saved widget insertions referencing that name will break
123
+
124
+ **Example — a page with multiple sections:**
125
+
126
+ ```tsx
127
+ export default function HomePage() {
128
+ return (
129
+ <>
130
+ <section data-ohw-section="hero">...</section>
131
+ <section data-ohw-section="lagree-intro">...</section>
132
+ <section data-ohw-section="classes-strip">...</section>
133
+ <section data-ohw-section="testimonials">...</section>
134
+ <section data-ohw-section="plan-form">...</section>
135
+ </>
136
+ );
137
+ }
138
+ ```
139
+
140
+ ### 5. Mark editable elements
141
+
142
+ Add `data-ohw-editable` and `data-ohw-key` to any element the studio owner should be able to edit:
143
+
144
+ ```tsx
145
+ {
146
+ /* Editable rich text (bold, italic, etc.) */
147
+ }
148
+ <h1 data-ohw-editable="text" data-ohw-key="hero-heading">
149
+ Welcome to the studio
150
+ </h1>;
151
+
152
+ {
153
+ /* Editable plain text (no formatting) */
154
+ }
155
+ <p data-ohw-editable="plain" data-ohw-key="hero-subtitle">
156
+ Book your first class
157
+ </p>;
158
+
159
+ {
160
+ /* Editable image */
161
+ }
162
+ <img
163
+ data-ohw-editable="image"
164
+ data-ohw-key="hero-image"
165
+ src="/hero.jpg"
166
+ alt="Hero"
167
+ />;
168
+
169
+ {
170
+ /* Editable background image */
171
+ }
172
+ <div
173
+ data-ohw-editable="bg-image"
174
+ data-ohw-key="hero-bg"
175
+ style={{ backgroundImage: "url(/bg.jpg)" }}
176
+ />;
177
+ ```
178
+
179
+ **Key naming rules:**
180
+
181
+ - Must be globally unique across all pages
182
+ - Use `kebab-case`
183
+ - Must be stable — changing a key orphans any saved content for that element
184
+
185
+ ---
186
+
187
+ ## Editable states (advanced)
188
+
189
+ For elements with multiple display states (e.g. a contact form with default/success/error views), wrap each state in a `data-ohw-state-view` and mark the container with `data-ohw-editable-state`:
190
+
191
+ ```tsx
192
+ <div
193
+ data-ohw-editable-state="default,success,error"
194
+ data-ohw-key="contact-form"
195
+ >
196
+ <div data-ohw-state-view="default">{/* default form UI */}</div>
197
+ <div data-ohw-state-view="success">{/* success message */}</div>
198
+ <div data-ohw-state-view="error">{/* error message */}</div>
199
+ </div>
200
+ ```
201
+
202
+ The bridge shows a state toggle in the canvas editor to switch between states.
203
+
204
+ ---
205
+
206
+ ## Local development workflow
207
+
208
+ When iterating on the bridge package itself:
209
+
210
+ ```bash
211
+ # 1. Build the package
212
+ cd ohhwells-bridge
213
+ npm run build
214
+
215
+ # 2. Link it globally (one-time setup)
216
+ npm link
217
+
218
+ # 3. In your template repo, use the local build instead of the npm version
219
+ cd rebound-template
220
+ npm link @ohhwells/bridge
221
+ ```
222
+
223
+ After that, every `npm run build` in `ohhwells-bridge` is picked up by the template immediately (no re-link needed). To go back to the npm version:
224
+
225
+ ```bash
226
+ cd rebound-template
227
+ npm unlink @ohhwells/bridge
228
+ npm install
229
+ ```
230
+
231
+ ---
232
+
233
+ ## Publishing
234
+
235
+ The package publishes automatically via GitHub Actions on push to `main` (production tag) or `staging` (next tag). To publish manually:
236
+
237
+ ```bash
238
+ npm run build
239
+ npm publish --access public
240
+ ```
241
+
242
+ ---
243
+
244
+ ## Link popover (Canvas Editor)
245
+
246
+ `LinkPopover` is rendered inside `OhhwellsBridge` (iframe portal) when editing link destinations. It implements the Figma shadcn kit panel (nodes 8365-7616 / 8382-4161) — anchored popover, not a centered dialog.
247
+
248
+ ```tsx
249
+ // Used internally by OhhwellsBridge — external consumers rarely mount this directly.
250
+ import { LinkPopover } from "@ohhwells/bridge";
251
+ ```
252
+
253
+ The iframe bridge reports page sections on `ow:ready`:
254
+
255
+ ```json
256
+ { "type": "ow:ready", "version": "1", "nodes": [...], "sections": [{ "id": "hero", "label": "Hero" }] }
257
+ ```
258
+
259
+ Templates must mark sections with `data-ohw-section` (and optional `data-ohw-section-label`).
260
+
261
+ ### Local link-editor testing (dev fixtures)
262
+
263
+ Without the canvas editor parent, add `ohw-fixtures=1` to the edit URL. This preloads Re:Bound pages and sections into the link popover:
264
+
265
+ ```
266
+ http://localhost:3000 /?mode=edit&ohw-fixtures=1
267
+ ```
268
+
269
+ 1. Click a nav link label (e.g. **Pricing**) → toolbar → chain icon
270
+ 2. Pick **About** in Destination → **Choose a section** → **Personal training**
271
+ 3. **Save** — href becomes `/about#personal-training`
272
+ 4. Open `http://localhost:3001/about#personal-training` (without `mode=edit`) to verify scroll
273
+
274
+ In edit mode link clicks are blocked; check `href` in DevTools or test on a normal page load.
275
+
276
+ ---
277
+
278
+ ## Design tokens
279
+
280
+ The package ships the full OhhWells design token set, scoped to `[data-ohw-bridge-root]` so styles never leak into the host template.
281
+
282
+ ### Semantic colors (CSS variables on `[data-ohw-bridge-root]`)
283
+
284
+ | Token | Light | Dark |
285
+ | -------------------- | --------- | --------- |
286
+ | `primary` | `#0f172a` | `#f8fafc` |
287
+ | `primary-foreground` | `#f8fafc` | `#0f172a` |
288
+ | `background` | `#ffffff` | `#020617` |
289
+ | `foreground` | `#020617` | `#f8fafc` |
290
+ | `muted` | `#f1f5f9` | `#1e293b` |
291
+ | `muted-foreground` | `#64748b` | `#94a3b8` |
292
+ | `border` | `#e2e8f0` | `#334155` |
293
+ | `destructive` | `#dc2626` | `#7f1d1d` |
294
+ | `success` | `#16a34a` | `#22c55e` |
295
+
296
+ ### Brand palette
297
+
298
+ Re:Bound brand colors: `bone`, `ivory`, `sand`, `linen`, `stone`, `clay`, `umber`, `umber-deep`, `espresso`, `clove`, `ink`, `ash`, `carbon`.
299
+
300
+ ---
301
+
302
+ ## License
303
+
304
+ MIT