11"use client" ;
22
3- import { useMemo , useState } from "react" ;
3+ import { useMemo , useRef , useState } from "react" ;
44
55import type { BundlePageProps } from "../server/_lib/types.ts" ;
66import { ResponsiveGrain } from "./responsive-grain" ;
77import ShareNav from "./share-nav" ;
8- import { highlightSyntax } from "./share-preview-syntax" ;
8+ import SkillEditorSurface from "./skill-editor-surface" ;
9+ import { DEFAULT_SKILL_DESCRIPTION , parseSkillMarkdown } from "./skill-markdown" ;
10+
11+ const OPENWORK_DEN_URL = "https://openworklabs.com/den" ;
912
1013function toneClass ( item : { tone ?: string } | null | undefined ) : string {
1114 if ( item ?. tone === "agent" ) return "dot-agent" ;
@@ -15,69 +18,47 @@ function toneClass(item: { tone?: string } | null | undefined): string {
1518 return "dot-skill" ;
1619}
1720
18- function CopyIcon ( ) {
19- return (
20- < svg viewBox = "0 0 24 24" fill = "none" stroke = "currentColor" strokeWidth = "2" strokeLinecap = "round" strokeLinejoin = "round" >
21- < rect x = "9" y = "9" width = "13" height = "13" rx = "2" ry = "2" > </ rect >
22- < path d = "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" > </ path >
23- </ svg >
24- ) ;
25- }
26-
27- function CheckIcon ( ) {
28- return (
29- < svg viewBox = "0 0 24 24" fill = "none" stroke = "currentColor" strokeWidth = "2" strokeLinecap = "round" strokeLinejoin = "round" >
30- < polyline points = "20 6 9 17 4 12" > </ polyline >
31- </ svg >
32- ) ;
33- }
34-
35- function countLabel ( text : string | undefined ) : string {
36- const length = String ( text ?? "" ) . trim ( ) . length ;
37- return `${ length } ${ length === 1 ? "character" : "characters" } ` ;
38- }
39-
4021export default function ShareBundlePage ( props : BundlePageProps ) {
41- const [ copyState , setCopyState ] = useState < "ready" | "copied" | "failed" > ( "ready" ) ;
4222 const [ previewCopied , setPreviewCopied ] = useState ( false ) ;
23+ const [ activeSelectionId , setActiveSelectionId ] = useState ( props . previewSelections ?. [ 0 ] ?. id ?? "preview-0" ) ;
24+ const previewCopyTimerRef = useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
4325
44- const shareUrl = props . shareUrl || "" ;
4526 const openInAppUrl = props . openInAppDeepLink || "#" ;
46- const openInWebUrl = props . openInWebAppUrl || "#" ;
47- const jsonUrl = props . jsonUrl || "#" ;
48- const downloadUrl = props . downloadUrl || "#" ;
4927 const title = props . title || "OpenWork bundle" ;
5028 const description = props . description || "OpenWork bundle ready to import." ;
51-
52- const highlightedPreview = useMemo ( ( ) => highlightSyntax ( props . previewText || "" ) , [ props . previewText ] ) ;
53- const previewFooter = props . previewText
54- ? `${ countLabel ( props . previewText ) } ${ props . previewLabel ? ` · ${ props . previewLabel } ` : "" } `
55- : "Preview unavailable" ;
56-
57- const copyShareUrl = async ( ) => {
58- if ( ! shareUrl ) return ;
59-
60- try {
61- await navigator . clipboard . writeText ( shareUrl ) ;
62- setCopyState ( "copied" ) ;
63- } catch {
64- setCopyState ( "failed" ) ;
65- }
66-
67- window . setTimeout ( ( ) => setCopyState ( "ready" ) , 1800 ) ;
68- } ;
29+ const previewSelections = props . previewSelections ?. length
30+ ? props . previewSelections
31+ : [
32+ {
33+ id : "preview-0" ,
34+ name : props . title || "Untitled skill" ,
35+ filename : props . previewFilename || "skill.md" ,
36+ text : props . previewText || "" ,
37+ tone : props . previewTone || "skill" ,
38+ label : props . previewLabel || "Skill preview" ,
39+ } ,
40+ ] ;
41+ const activeSelection = previewSelections . find ( ( selection ) => selection . id === activeSelectionId ) ?? previewSelections [ 0 ] ;
42+ const parsedPreview = useMemo ( ( ) => parseSkillMarkdown ( activeSelection ?. text || "" ) , [ activeSelection ?. text ] ) ;
43+ const previewName = parsedPreview . name || activeSelection ?. name || title ;
44+ const previewDescription = parsedPreview . description || description || DEFAULT_SKILL_DESCRIPTION ;
45+ const previewBody = parsedPreview . body || activeSelection ?. text || "" ;
6946
7047 const copyPreview = async ( ) => {
71- if ( ! props . previewText ) return ;
48+ if ( ! activeSelection ?. text ) return ;
7249
7350 try {
74- await navigator . clipboard . writeText ( props . previewText ) ;
51+ await navigator . clipboard . writeText ( activeSelection . text ) ;
7552 setPreviewCopied ( true ) ;
7653 } catch {
7754 setPreviewCopied ( false ) ;
7855 }
7956
80- window . setTimeout ( ( ) => setPreviewCopied ( false ) , 800 ) ;
57+ if ( previewCopyTimerRef . current ) clearTimeout ( previewCopyTimerRef . current ) ;
58+ previewCopyTimerRef . current = setTimeout ( ( ) => {
59+ setPreviewCopied ( false ) ;
60+ previewCopyTimerRef . current = null ;
61+ } , 800 ) ;
8162 } ;
8263
8364 return (
@@ -115,151 +96,70 @@ export default function ShareBundlePage(props: BundlePageProps) {
11596 < section className = "hero-layout hero-layout-share" >
11697 < div className = "hero-copy" >
11798 < span className = "eyebrow" > { props . typeLabel } </ span >
118- < h1 >
119- { title }
120- </ h1 >
99+ < h1 > { title } </ h1 >
121100 < p className = "hero-body" > { description } </ p >
122- < div className = "button-row" >
101+ < div className = "button-row share-bundle-actions " >
123102 < a className = "button-primary" href = { openInAppUrl } >
124- Open in app
103+ Open in OpenWork app
125104 </ a >
126- < a className = "button-secondary" href = { openInWebUrl } target = "_blank" rel = "noreferrer" >
127- Open in web app
105+ < a className = "button-secondary" href = { OPENWORK_DEN_URL } target = "_blank" rel = "noreferrer" >
106+ Open in an OpenWork den
128107 </ a >
129108 </ div >
130- < p className = "hero-note" > { props . installHint } </ p >
131- </ div >
132-
133- < div className = "share-cards-grid share-bundle-grid" >
134- < article className = "package-card share-card surface-soft" >
135- < h2 className = "simple-app-title" > Package contents</ h2 >
136- < p className = "simple-app-copy" >
137- Everything bundled in this share link.
138- </ p >
139-
140- < div className = "included-section" >
141- < div className = "included-section-header" >
142- < h4 > Package contents</ h4 >
143- < span className = "surface-chip" > Top { props . items ?. length || 1 } </ span >
144- </ div >
145-
146- < div className = "included-list" >
147- { props . items ?. length ? (
148- props . items . map ( ( item ) => (
149- < div className = "included-item" key = { `${ item . kind } -${ item . name } ` } >
150- < div className = "item-left" >
151- < div className = { `item-dot ${ toneClass ( item ) } ` } > </ div >
152- < div className = "item-text" >
153- < span className = "item-title" > { item . name } </ span >
154- < span className = "item-meta" >
155- { item . kind } · { item . meta }
156- </ span >
157- </ div >
158- </ div >
159- </ div >
160- ) )
161- ) : (
162- < div className = "included-item" >
163- < div className = "item-left" >
164- < div className = "item-dot dot-skill" > </ div >
165- < div className = "item-text" >
166- < span className = "item-title" > OpenWork bundle</ span >
167- < span className = "item-meta" > Shared config</ span >
168- </ div >
169- </ div >
170- </ div >
171- ) }
172- </ div >
173- </ div >
174- </ article >
175-
176- < aside className = "preview-panel share-preview-panel" >
177- < div className = "preview-surface" >
178- < div className = "preview-header" >
179- < span className = "preview-eyebrow" > Preview</ span >
180-
181- < div className = "preview-header-actions" >
182- < span className = "preview-filename" >
183- < span className = "preview-filename-dot dot-pending" />
184- { props . previewFilename || "bundle.json" }
185- < button
186- type = "button"
187- className = "clipboard-egg-button preview-copy-button clipboard-egg-inline"
188- title = "Copy preview"
189- aria-label = "Copy preview"
190- onClick = { ( ) => void copyPreview ( ) }
191- >
192- { previewCopied ? < CheckIcon /> : < CopyIcon /> }
193- </ button >
194- </ span >
195- </ div >
196- </ div >
197-
198- < div className = "preview-editor-wrap" >
199- < pre className = "preview-highlight share-preview-readonly" dangerouslySetInnerHTML = { { __html : `${ highlightedPreview } \n` } } />
200- </ div >
201-
202- < div className = "preview-footer" >
203- < span > { previewFooter } </ span >
204- </ div >
205- </ div >
206- </ aside >
207109 </ div >
208110 </ section >
209111
210- < section className = "share-story-grid" >
211- < article className = "result-card" >
212- < span className = "eyebrow" > Bundle details</ span >
213- < h3 > Bundle details</ h3 >
214- < p > Stable metadata for parsing and direct OpenWork import.</ p >
215- < dl className = "metadata-list" >
216- { props . metadataRows ?. map ( ( row ) => (
217- < div className = "metadata-row" key = { row . label } >
218- < dt > { row . label } </ dt >
219- < dd > { row . value } </ dd >
220- </ div >
221- ) ) }
222- </ dl >
223- </ article >
224-
225- < article className = "result-card" >
226- < span className = "eyebrow" > Raw endpoints</ span >
227- < h3 > Raw endpoints</ h3 >
228- < p > Keep the human page and machine payload side by side.</ p >
229- < div className = "url-stack" >
230- < div className = "url-box" >
231- < a href = { jsonUrl } > JSON payload</ a >
232- </ div >
233- < div className = "url-box mono" > { shareUrl } </ div >
234- </ div >
235- < div className = "button-row" >
236- < a className = "button-secondary" href = { downloadUrl } >
237- Download JSON
238- </ a >
239- < button className = "button-secondary" type = "button" onClick = { ( ) => void copyShareUrl ( ) } >
240- { copyState === "copied" ? "Copied!" : "Copy share link" }
241- </ button >
242- </ div >
243- </ article >
244-
245- < article className = "result-card" >
246- < span className = "eyebrow" > Install path</ span >
247- < h3 > Open it in OpenWork</ h3 >
248- < div className = "step-list" >
249- < div className = "step-row" >
112+ < section className = "share-bundle-stack" >
113+ < article className = "result-card share-install-card" >
114+ < div className = "share-inline-steps" >
115+ < div className = "share-inline-step" >
250116 < span className = "step-bullet" > 01</ span >
251- < span > Open the share page or use the deep link directly from this package. </ span >
117+ < span > Open the bundle in OpenWork </ span >
252118 </ div >
253- < div className = "step-row " >
119+ < div className = "share-inline-step " >
254120 < span className = "step-bullet" > 02</ span >
255- < span > OpenWork reads the bundle metadata, then lets you choose an existing worker or a new one. </ span >
121+ < span > Choose the destination worker</ span >
256122 </ div >
257- < div className = "step-row " >
123+ < div className = "share-inline-step " >
258124 < span className = "step-bullet" > 03</ span >
259- < span > Your teammate lands in a clean import path with the packaged skills, agents, and MCP setup ready to apply. </ span >
125+ < span > Happy OpenWorking! </ span >
260126 </ div >
261127 </ div >
262128 </ article >
129+
130+ < article className = "bundle-compact-strip surface-soft" >
131+ < div className = "bundle-strip-header" > Skills:</ div >
132+ < div className = "bundle-strip-list" aria-label = "Skills" >
133+ { previewSelections . map ( ( selection ) => {
134+ const isActive = selection . id === activeSelection ?. id ;
135+ return (
136+ < button
137+ key = { selection . id }
138+ type = "button"
139+ className = { `bundle-strip-chip${ isActive ? " is-active" : "" } ` }
140+ onClick = { ( ) => setActiveSelectionId ( selection . id ) }
141+ disabled = { isActive }
142+ >
143+ < span className = { `preview-filename-dot ${ toneClass ( selection ) } ` } />
144+ { selection . name }
145+ </ button >
146+ ) ;
147+ } ) }
148+ </ div >
149+ </ article >
150+
151+ < SkillEditorSurface
152+ className = "share-bundle-editor"
153+ toneClassName = { toneClass ( activeSelection ) }
154+ filename = "skill.md"
155+ skillName = { previewName }
156+ skillDescription = { previewDescription }
157+ bodyValue = { previewBody }
158+ metadataMode = "readonly"
159+ readOnly = { true }
160+ copied = { previewCopied }
161+ onCopy = { ( ) => void copyPreview ( ) }
162+ />
263163 </ section >
264164 </ >
265165 ) }
0 commit comments