@vercel/geistdocs 1.25.1-canary.47f1ad5 → 1.25.1-canary.4e75e60
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/dist/cli/index.js +1 -1
- package/dist/components/callout.d.ts.map +1 -1
- package/dist/components/callout.js +1 -1
- package/dist/controls.d.ts.map +1 -1
- package/dist/controls.js +3 -2
- package/dist/internal/chat/context.d.ts +2 -0
- package/dist/internal/chat/context.d.ts.map +1 -1
- package/dist/internal/chat/context.js +24 -3
- package/dist/internal/chat/loading-skeleton.d.ts +7 -0
- package/dist/internal/chat/loading-skeleton.d.ts.map +1 -0
- package/dist/internal/chat/loading-skeleton.js +46 -0
- package/dist/internal/chat/message.d.ts.map +1 -1
- package/dist/internal/chat/message.js +23 -3
- package/dist/internal/chat/shell.d.ts.map +1 -1
- package/dist/internal/chat/shell.js +9 -14
- package/dist/internal/chat/sources.d.ts.map +1 -1
- package/dist/internal/chat/sources.js +4 -1
- package/dist/internal/mousedown-navigation-utils.d.ts +5 -0
- package/dist/internal/mousedown-navigation-utils.d.ts.map +1 -0
- package/dist/internal/mousedown-navigation-utils.js +95 -0
- package/dist/internal/mousedown-navigation.d.ts +10 -0
- package/dist/internal/mousedown-navigation.d.ts.map +1 -0
- package/dist/internal/mousedown-navigation.js +42 -0
- package/dist/internal/navbar/navbar-shell.d.ts.map +1 -1
- package/dist/internal/navbar/navbar-shell.js +2 -1
- package/dist/internal/page-actions-client.d.ts.map +1 -1
- package/dist/internal/page-actions-client.js +4 -21
- package/dist/internal/provider-client.d.ts.map +1 -1
- package/dist/internal/provider-client.js +28 -4
- package/dist/internal/sidebar.d.ts.map +1 -1
- package/dist/internal/sidebar.js +15 -14
- package/dist/mdx.d.ts.map +1 -1
- package/dist/mdx.js +2 -4
- package/dist/pages/docs.d.ts.map +1 -1
- package/dist/pages/docs.js +8 -5
- package/dist/routes/chat.d.ts +1 -1
- package/dist/routes/chat.js +1 -1
- package/docs/agents.md +1 -1
- package/docs/llms.txt +35 -9
- package/docs/manifest.json +1 -1
- package/docs/pages/ask-ai.md +2 -2
- package/docs/pages/md.md +1 -1
- package/docs/pages/syntax.md +31 -5
- package/package.json +2 -2
- package/template/content/docs/ask-ai.cn.mdx +2 -2
- package/template/content/docs/ask-ai.mdx +2 -2
- package/template/content/docs/md.mdx +1 -1
- package/template/content/docs/syntax.mdx +32 -5
- package/template/package.json +2 -2
package/dist/cli/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{program as T}from"commander";import{access as ce,copyFile as le}from"fs/promises";import{join as pe}from"path";import{cancel as de,intro as ge,isCancel as ue,log as fe,outro as me,spinner as he,text as we}from"@clack/prompts";import{spawn as te}from"child_process";import{readFileSync as se}from"fs";import{cp as ne,readFile as ae,rename as re,writeFile as ie}from"fs/promises";import{join as $}from"path";import{fileURLToPath as oe}from"url";var g="@vercel/geistdocs",m=(e,t=[],s={})=>new Promise((n,a)=>{let r=te(e,t,{stdio:"inherit",...s});r.on("error",a),r.on("close",i=>{if(i===0){n();return}a(new Error(`Command failed with exit code ${i}: ${[e,...t].join(" ")}`))})}),A=["dependencies","devDependencies","optionalDependencies","peerDependencies"],_=()=>JSON.parse(se(new URL("../../package.json",import.meta.url),"utf8")).version,P=async e=>{let t=$(e,"package.json"),s=await ae(t,"utf8");return JSON.parse(s)},x=async(e,t)=>{let s=$(e,"package.json");await ie(s,`${JSON.stringify(t,null,2)}
|
|
3
|
-
`,"utf8")},R=(e,t)=>{for(let s of A){let n=e[s];if(n&&t in n)return n[t]}},V=(e,t)=>!!R(e,t),b=(e,t,s)=>{let n=!1;for(let a of A){let r=e[a];r&&t in r&&(r[t]=s,n=!0)}return n},j=()=>oe(new URL("../../template",import.meta.url)),F=async e=>{await ne(j(),e,{recursive:!0});let t=$(e,".gitignore"),s=$(e,"_gitignore");try{await re(s,t)}catch{}};var ye=async e=>{await F(e)},Pe=async e=>{try{return await ce(e),!0}catch{return!1}},ve=async()=>{await Pe(".env.example")&&await le(".env.example",".env.local")},Te=async e=>{let t=await P(e),s=_();return b(t,g,s)?(await x(e,t),!0):!1},ke=async e=>{await m("pnpm",["install"],{cwd:e,env:process.env,stdio:"inherit"})},$e=async e=>{await m("git",["init"],{cwd:e,env:process.env,stdio:"inherit"}),await m("git",["add","."],{cwd:e,env:process.env,stdio:"inherit"}),await m("git",["commit","-m","\u2728 Initial commit"],{cwd:e,env:process.env,stdio:"inherit"})},xe=async()=>{let e=await we({message:"What is your project named?",placeholder:"my-app",validate(t){if(t.length===0)return"Please enter a project name."}});return ue(e)&&(de("Operation cancelled."),process.exit(0)),e.toString()},G=async e=>{try{ge("Let's start a Geistdocs project!");let t=process.cwd(),s=e.name||await xe(),n=he(),a=pe(t,s);n.start("Copying bundled template..."),await ye(s),n.message("Setting up environment variables..."),process.chdir(a),await ve(),n.message("Rewriting package dependency versions..."),await Te(a),n.message("Installing dependencies..."),await ke(a),e.disableGit||(n.message("Initializing Git repository..."),await $e(a)),n.stop("Project initialized successfully!"),me("Run `pnpm dev` to start the development server.")}catch(t){let s=t instanceof Error?t.message:`Failed to initialize project: ${t}`;fe.error(s),process.exit(1)}};import{readFileSync as be,writeFileSync as Fe}from"fs";import{mkdir as De,readFile as N,writeFile as Se}from"fs/promises";import{dirname as Ce,extname as Re,relative as M,resolve as S}from"path";import{intro as je,isCancel as Ee,log as h,multiselect as Ne,outro as D,spinner as Ue}from"@clack/prompts";import{glob as Oe}from"glob";import{Node as v,Project as Ie,SyntaxKind as Je}from"ts-morph";var Le="geistdocs.tsx",Ae="content/docs/**/*.mdx",U=".translation-cache.json",E=8,B=()=>({version:1,entries:{}}),_e=async e=>{let t=await N(e),{createHash:s}=await import("crypto");return s("sha256").update(t).digest("hex")},Ve=e=>{let t=S(process.cwd(),e);return be(t,"utf8")},z=e=>v.isObjectLiteralExpression(e)?e.getProperties().flatMap(t=>{if(v.isPropertyAssignment(t)){let s=t.getNameNode();if(v.isIdentifier(s)||v.isStringLiteral(s))return[s.getText().replaceAll(/['"]/g,"")]}return[]}).filter(Boolean):[],Ge=e=>{try{let t=new Ie({compilerOptions:{allowJs:!0,jsx:4,module:99,target:10},skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!0}),s=Ve(e),r=t.createSourceFile(e,s,{overwrite:!0}).getVariableDeclarations().find(l=>l.getName()==="translations")?.getInitializer();if(!r)return[];if(v.isObjectLiteralExpression(r))return z(r);let i=r.getFirstDescendantByKind(Je.ObjectLiteralExpression);return i?z(i):[]}catch(t){let s=t instanceof Error?t.message:`${t}`;return h.warn(`Failed to read locales from ${e}: ${s}`),[]}},Be=async()=>{let e=await Ne({message:"Which locales should be translated?",options:[{value:"cn",label:"Chinese (cn)"},{value:"jp",label:"Japanese (jp)"},{value:"es",label:"Spanish (es)"},{value:"fr",label:"French (fr)"},{value:"de",label:"German (de)"}],required:!0});return Ee(e)&&(D("Translation cancelled"),process.exit(0)),e},ze=async e=>(await Oe(e,{cwd:process.cwd(),absolute:!0,nodir:!0})).sort(),He=async()=>{let e=S(process.cwd(),U);try{let t=await N(e,"utf8"),s=JSON.parse(t);return s.version!==1||!s.entries?B():{version:1,entries:s.entries}}catch{return B()}},H=e=>{let t=S(process.cwd(),U),s=JSON.stringify(e,null,2);Fe(t,s,"utf8")},Me=async e=>{let t=await Promise.all(e.map(async s=>[s,await _e(s)]));return Object.fromEntries(t)},Ke=(e,t)=>{let s=Re(e);return`${e.slice(0,-s.length)}.${t}${s}`},K=(e,t)=>`${M(process.cwd(),e)}::${t}`,qe=(e,t,s,n,a=!1)=>{let r=[],i=0;for(let l of t){let c=s[l];for(let o of e){let d=Ke(l,o),u=K(l,o),f=n.entries[u];if(!a&&f?.hash===c){i+=1;continue}r.push({locale:o,sourceFile:l,sourceHash:c,targetFile:d})}}return{tasks:r,skippedCount:i}},Xe=async e=>{await De(Ce(e),{recursive:!0})},We=async(e,t,s)=>{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,locale:s})});if(!n.ok){let r=await n.text();throw new Error(`API request failed (${n.status}): ${r}`)}let a=await n.json();if(!a.translation)throw new Error("API response did not include a translation");return a.translation},Ye=async(e,t,s)=>{let n=await N(e.sourceFile,"utf8"),a=await We(t,n,e.locale);await Xe(e.targetFile),await Se(e.targetFile,a,"utf8"),s.entries[K(e.sourceFile,e.locale)]={hash:e.sourceHash,updatedAt:new Date().toISOString()}},q=async(e,t)=>{je("Translate MDX content");let s=e??Ae,n=t.url||process.env.GEISTDOCS_TRANSLATE_URL||"https://geistdocs.com/translate",a=Ge(t.config??Le),r=await ze(s);r.length===0&&(h.error(`No MDX files found matching pattern: ${s}`),D("Translation cancelled"),process.exit(1)),h.info(`Found ${r.length} MDX file(s) matching pattern`),a.length===0&&(a=await Be());let i=S(process.cwd(),U),l=await He();await H(l),h.info(`Using cache: ${i}`);let c=await Me(r),{tasks:o,skippedCount:d}=qe(a,r,c,l,t.force);if(o.length===0){h.success("All translations are up to date!"),D(`Skipped ${d} file(s) (unchanged)`);return}let u=[];for(let y=0;y<o.length;y+=E)u.push(o.slice(y,y+E));h.info(`Processing ${o.length} translation(s) in ${u.length} batch(es) of up to ${E}`),d>0&&h.info(`Skipped ${d} translation(s) (unchanged)`);let f=Ue();f.start("Translating content...");let k=0;for(let y of u)await Promise.all(y.map(async L=>{await Ye(L,n,l),k+=1,f.message(`Translated ${k}/${o.length}: ${M(process.cwd(),L.targetFile)}`)})),await H(l);f.stop("Translation complete!"),D(`Created/updated ${o.length} file(s)`)};import{access as Ze,copyFile as Qe,mkdir as Z,rm as J}from"fs/promises";import{dirname as et,join as w}from"path";import{intro as tt,log as p,outro as C,spinner as Q}from"@clack/prompts";import{glob as st}from"glob";var nt=["**/*"],at=["content/docs/**"],O=".geistdocs-tmp",rt=async(e,t)=>{let s=w(e,t);await J(s,{recursive:!0,force:!0}),await Z(s,{recursive:!0})},I=async e=>await J(e,{recursive:!0,force:!0}),X=async(e,t,s)=>(await st(e,{cwd:s,nodir:!0,dot:!0,ignore:[".git/**",...t]})).sort(),it=async e=>{try{return await Ze(e),!0}catch{return!1}},ot=async(e,t,s)=>{let n=w(t,e),a=w(s,e);return await it(n)?(await Qe(n,a),{success:!0}):{success:!1,error:`Source file not found: ${n}`}},ct=async(e,t)=>{let s=w(t,e);return await J(s,{force:!0}),{success:!0}},W=20,Y=async(e,t,s)=>{let n=[];for(let a=0;a<e.length;a+=s){let r=e.slice(a,a+s),i=await Promise.all(r.map(t));n.push(...i)}return n},lt=async(e,t,s,n,a)=>{let r={success:[],deleted:[],failed:[]},i=[...new Set(e.map(c=>et(w(n,c))))];a.message(`Creating ${i.length} directories...`),await Promise.all(i.map(c=>Z(c,{recursive:!0}))),a.message(`Updating ${e.length} files...`);let l=await Y(e,async c=>{let o=await ot(c,s,n);return{file:c,...o}},W);for(let{file:c,success:o,error:d}of l)o?r.success.push(c):r.failed.push({file:c,error:d??"Unknown error"});if(t.length>0){a.message(`Deleting ${t.length} files...`);let c=await Y(t,async o=>{try{return await ct(o,n),{file:o,success:!0}}catch(d){let u=d instanceof Error?d.message:`${d}`;return{file:o,success:!1,error:u}}},W);for(let o of c)o.success?r.deleted.push(o.file):r.failed.push({file:o.file,error:o.error})}return r},pt=e=>{if(e.success.length>0){p.success(`Successfully updated ${e.success.length} files:`);for(let t of e.success)p.info(` \u2713 ${t}`)}if(e.deleted.length>0){p.success(`Deleted ${e.deleted.length} files:`);for(let t of e.deleted)p.info(` \u{1F5D1} ${t}`)}if(e.failed.length>0){p.warn(`Failed to update ${e.failed.length} files:`);for(let{file:t,error:s}of e.failed)p.error(` \u2717 ${t}: ${s}`)}},dt=e=>e.includes("canary")?"canary":"latest",gt=async e=>{let t=await fetch(`https://registry.npmjs.org/${encodeURIComponent(g)}`);if(!t.ok)throw new Error(`Failed to resolve ${g}@${e}`);let n=(await t.json())["dist-tags"]?.[e];if(!n)throw new Error(`Could not find dist-tag ${e} for ${g}`);return n},ut=async e=>{let t=await P(e),s=R(t,g);if(!s)return{currentVersion:s,nextVersion:void 0,updated:!1};let n=dt(s),a=await gt(n);return s===a?{currentVersion:s,nextVersion:a,updateTag:n,updated:!1}:(b(t,g,a),await x(e,t),{currentVersion:s,nextVersion:a,updateTag:n,updated:!0})},ft=async(e,t,s)=>{let n=await P(e);if(!V(n,g))return!1;t&&t.length>0&&p.warn("Ignoring file patterns for a package-based site. This update will bump the package version instead."),s?.sync&&p.warn("Ignoring --sync for a package-based site. Runtime updates now come from the package version.");let{currentVersion:a,nextVersion:r,updateTag:i,updated:l}=await ut(e);if(!l)return p.success(a?`@vercel/geistdocs is already at ${r} (${i}).`:"No package version update was needed."),C("Package-based site is already up to date."),!0;p.info(`Bumping ${g} from ${a} to ${r} (${i})`);let c=Q();return c.start("Installing updated package version..."),await m("pnpm",["install"],{cwd:e}),c.stop("Package update complete!"),C("Please review and test the upgraded package version."),!0},mt=async(e,t,s,n,a)=>{let r=w(e,O),i=Q(),l=a?.sync?r:t;i.start("Preparing template snapshot..."),a?.sync&&(await rt(e,O),await F(r)),i.message("Scanning for files...");let c=await X(s,n,l),o=[];if(a?.sync){i.message("Comparing with local files...");let u=await X(s,n,e),f=new Set(c);o=u.filter(k=>!f.has(k))}if(i.stop(`Found ${c.length} files to update`),c.length===0&&o.length===0){p.warn("No files matched the patterns. Nothing to update."),a?.sync&&await I(r),C("Update cancelled.");return}p.info(`Patterns: ${s.length}`),p.info(`Files to update: ${c.length}`),a?.sync&&p.info(`Files to delete: ${o.length}`),i.start("Updating files...");let d=await lt(c,o,l,e,i);a?.sync&&(i.message("Cleaning up..."),await I(r)),i.stop("Update complete!"),pt(d),C("Please review and test the changes carefully.")},ee=async(e,t)=>{let s=process.cwd(),n=j(),a=e&&e.length>0?e:nt,r=e&&e.length>0?[]:at;try{if(tt("Let's update your Geistdocs project!"),await ft(s,e,t))return;p.info("Template source: bundled package snapshot"),e&&e.length>0&&p.info(`Updating specific files: ${e.join(", ")}`),t?.sync&&p.info("Sync mode enabled: will delete files removed from template"),await mt(s,n,a,r,t)}catch(i){let l=i instanceof Error?i.message:`${i}`;try{await I(w(s,O))}catch{}p.error(`Failed to update project: ${l}`),process.exit(1)}};T.name("geistdocs").description("CLI for Geistdocs projects").version("1.25.1-canary.47f1ad5","-v, --version","Output the current version");T.command("init").description("Initialize a new Geistdocs project").option("--name <name>","Name of the project").option("--disable-git","Disable git initialization").action(G);T.command("update [files...]").description("Update a Geistdocs project (optionally specify files/patterns to update)").option("--sync","Delete local files that no longer exist in the template").action(ee);T.command("translate [pattern]").description("Translate MDX file(s) to one or more locales (default: content/docs/**/*.mdx)").option("--config <path>","Path to config file to load locales from (defaults to geistdocs.tsx)").option("--url <url>","Custom translation API URL (defaults to GEISTDOCS_TRANSLATE_URL or https://geistdocs.com/translate)").option("--force","Force re-translation of all files, ignoring cache").action(q);T.parse(process.argv);
|
|
3
|
+
`,"utf8")},R=(e,t)=>{for(let s of A){let n=e[s];if(n&&t in n)return n[t]}},V=(e,t)=>!!R(e,t),b=(e,t,s)=>{let n=!1;for(let a of A){let r=e[a];r&&t in r&&(r[t]=s,n=!0)}return n},j=()=>oe(new URL("../../template",import.meta.url)),F=async e=>{await ne(j(),e,{recursive:!0});let t=$(e,".gitignore"),s=$(e,"_gitignore");try{await re(s,t)}catch{}};var ye=async e=>{await F(e)},Pe=async e=>{try{return await ce(e),!0}catch{return!1}},ve=async()=>{await Pe(".env.example")&&await le(".env.example",".env.local")},Te=async e=>{let t=await P(e),s=_();return b(t,g,s)?(await x(e,t),!0):!1},ke=async e=>{await m("pnpm",["install"],{cwd:e,env:process.env,stdio:"inherit"})},$e=async e=>{await m("git",["init"],{cwd:e,env:process.env,stdio:"inherit"}),await m("git",["add","."],{cwd:e,env:process.env,stdio:"inherit"}),await m("git",["commit","-m","\u2728 Initial commit"],{cwd:e,env:process.env,stdio:"inherit"})},xe=async()=>{let e=await we({message:"What is your project named?",placeholder:"my-app",validate(t){if(t.length===0)return"Please enter a project name."}});return ue(e)&&(de("Operation cancelled."),process.exit(0)),e.toString()},G=async e=>{try{ge("Let's start a Geistdocs project!");let t=process.cwd(),s=e.name||await xe(),n=he(),a=pe(t,s);n.start("Copying bundled template..."),await ye(s),n.message("Setting up environment variables..."),process.chdir(a),await ve(),n.message("Rewriting package dependency versions..."),await Te(a),n.message("Installing dependencies..."),await ke(a),e.disableGit||(n.message("Initializing Git repository..."),await $e(a)),n.stop("Project initialized successfully!"),me("Run `pnpm dev` to start the development server.")}catch(t){let s=t instanceof Error?t.message:`Failed to initialize project: ${t}`;fe.error(s),process.exit(1)}};import{readFileSync as be,writeFileSync as Fe}from"fs";import{mkdir as De,readFile as N,writeFile as Se}from"fs/promises";import{dirname as Ce,extname as Re,relative as M,resolve as S}from"path";import{intro as je,isCancel as Ee,log as h,multiselect as Ne,outro as D,spinner as Ue}from"@clack/prompts";import{glob as Oe}from"glob";import{Node as v,Project as Ie,SyntaxKind as Je}from"ts-morph";var Le="geistdocs.tsx",Ae="content/docs/**/*.mdx",U=".translation-cache.json",E=8,B=()=>({version:1,entries:{}}),_e=async e=>{let t=await N(e),{createHash:s}=await import("crypto");return s("sha256").update(t).digest("hex")},Ve=e=>{let t=S(process.cwd(),e);return be(t,"utf8")},z=e=>v.isObjectLiteralExpression(e)?e.getProperties().flatMap(t=>{if(v.isPropertyAssignment(t)){let s=t.getNameNode();if(v.isIdentifier(s)||v.isStringLiteral(s))return[s.getText().replaceAll(/['"]/g,"")]}return[]}).filter(Boolean):[],Ge=e=>{try{let t=new Ie({compilerOptions:{allowJs:!0,jsx:4,module:99,target:10},skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!0}),s=Ve(e),r=t.createSourceFile(e,s,{overwrite:!0}).getVariableDeclarations().find(l=>l.getName()==="translations")?.getInitializer();if(!r)return[];if(v.isObjectLiteralExpression(r))return z(r);let i=r.getFirstDescendantByKind(Je.ObjectLiteralExpression);return i?z(i):[]}catch(t){let s=t instanceof Error?t.message:`${t}`;return h.warn(`Failed to read locales from ${e}: ${s}`),[]}},Be=async()=>{let e=await Ne({message:"Which locales should be translated?",options:[{value:"cn",label:"Chinese (cn)"},{value:"jp",label:"Japanese (jp)"},{value:"es",label:"Spanish (es)"},{value:"fr",label:"French (fr)"},{value:"de",label:"German (de)"}],required:!0});return Ee(e)&&(D("Translation cancelled"),process.exit(0)),e},ze=async e=>(await Oe(e,{cwd:process.cwd(),absolute:!0,nodir:!0})).sort(),He=async()=>{let e=S(process.cwd(),U);try{let t=await N(e,"utf8"),s=JSON.parse(t);return s.version!==1||!s.entries?B():{version:1,entries:s.entries}}catch{return B()}},H=e=>{let t=S(process.cwd(),U),s=JSON.stringify(e,null,2);Fe(t,s,"utf8")},Me=async e=>{let t=await Promise.all(e.map(async s=>[s,await _e(s)]));return Object.fromEntries(t)},Ke=(e,t)=>{let s=Re(e);return`${e.slice(0,-s.length)}.${t}${s}`},K=(e,t)=>`${M(process.cwd(),e)}::${t}`,qe=(e,t,s,n,a=!1)=>{let r=[],i=0;for(let l of t){let c=s[l];for(let o of e){let d=Ke(l,o),u=K(l,o),f=n.entries[u];if(!a&&f?.hash===c){i+=1;continue}r.push({locale:o,sourceFile:l,sourceHash:c,targetFile:d})}}return{tasks:r,skippedCount:i}},Xe=async e=>{await De(Ce(e),{recursive:!0})},We=async(e,t,s)=>{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,locale:s})});if(!n.ok){let r=await n.text();throw new Error(`API request failed (${n.status}): ${r}`)}let a=await n.json();if(!a.translation)throw new Error("API response did not include a translation");return a.translation},Ye=async(e,t,s)=>{let n=await N(e.sourceFile,"utf8"),a=await We(t,n,e.locale);await Xe(e.targetFile),await Se(e.targetFile,a,"utf8"),s.entries[K(e.sourceFile,e.locale)]={hash:e.sourceHash,updatedAt:new Date().toISOString()}},q=async(e,t)=>{je("Translate MDX content");let s=e??Ae,n=t.url||process.env.GEISTDOCS_TRANSLATE_URL||"https://geistdocs.com/translate",a=Ge(t.config??Le),r=await ze(s);r.length===0&&(h.error(`No MDX files found matching pattern: ${s}`),D("Translation cancelled"),process.exit(1)),h.info(`Found ${r.length} MDX file(s) matching pattern`),a.length===0&&(a=await Be());let i=S(process.cwd(),U),l=await He();await H(l),h.info(`Using cache: ${i}`);let c=await Me(r),{tasks:o,skippedCount:d}=qe(a,r,c,l,t.force);if(o.length===0){h.success("All translations are up to date!"),D(`Skipped ${d} file(s) (unchanged)`);return}let u=[];for(let y=0;y<o.length;y+=E)u.push(o.slice(y,y+E));h.info(`Processing ${o.length} translation(s) in ${u.length} batch(es) of up to ${E}`),d>0&&h.info(`Skipped ${d} translation(s) (unchanged)`);let f=Ue();f.start("Translating content...");let k=0;for(let y of u)await Promise.all(y.map(async L=>{await Ye(L,n,l),k+=1,f.message(`Translated ${k}/${o.length}: ${M(process.cwd(),L.targetFile)}`)})),await H(l);f.stop("Translation complete!"),D(`Created/updated ${o.length} file(s)`)};import{access as Ze,copyFile as Qe,mkdir as Z,rm as J}from"fs/promises";import{dirname as et,join as w}from"path";import{intro as tt,log as p,outro as C,spinner as Q}from"@clack/prompts";import{glob as st}from"glob";var nt=["**/*"],at=["content/docs/**"],O=".geistdocs-tmp",rt=async(e,t)=>{let s=w(e,t);await J(s,{recursive:!0,force:!0}),await Z(s,{recursive:!0})},I=async e=>await J(e,{recursive:!0,force:!0}),X=async(e,t,s)=>(await st(e,{cwd:s,nodir:!0,dot:!0,ignore:[".git/**",...t]})).sort(),it=async e=>{try{return await Ze(e),!0}catch{return!1}},ot=async(e,t,s)=>{let n=w(t,e),a=w(s,e);return await it(n)?(await Qe(n,a),{success:!0}):{success:!1,error:`Source file not found: ${n}`}},ct=async(e,t)=>{let s=w(t,e);return await J(s,{force:!0}),{success:!0}},W=20,Y=async(e,t,s)=>{let n=[];for(let a=0;a<e.length;a+=s){let r=e.slice(a,a+s),i=await Promise.all(r.map(t));n.push(...i)}return n},lt=async(e,t,s,n,a)=>{let r={success:[],deleted:[],failed:[]},i=[...new Set(e.map(c=>et(w(n,c))))];a.message(`Creating ${i.length} directories...`),await Promise.all(i.map(c=>Z(c,{recursive:!0}))),a.message(`Updating ${e.length} files...`);let l=await Y(e,async c=>{let o=await ot(c,s,n);return{file:c,...o}},W);for(let{file:c,success:o,error:d}of l)o?r.success.push(c):r.failed.push({file:c,error:d??"Unknown error"});if(t.length>0){a.message(`Deleting ${t.length} files...`);let c=await Y(t,async o=>{try{return await ct(o,n),{file:o,success:!0}}catch(d){let u=d instanceof Error?d.message:`${d}`;return{file:o,success:!1,error:u}}},W);for(let o of c)o.success?r.deleted.push(o.file):r.failed.push({file:o.file,error:o.error})}return r},pt=e=>{if(e.success.length>0){p.success(`Successfully updated ${e.success.length} files:`);for(let t of e.success)p.info(` \u2713 ${t}`)}if(e.deleted.length>0){p.success(`Deleted ${e.deleted.length} files:`);for(let t of e.deleted)p.info(` \u{1F5D1} ${t}`)}if(e.failed.length>0){p.warn(`Failed to update ${e.failed.length} files:`);for(let{file:t,error:s}of e.failed)p.error(` \u2717 ${t}: ${s}`)}},dt=e=>e.includes("canary")?"canary":"latest",gt=async e=>{let t=await fetch(`https://registry.npmjs.org/${encodeURIComponent(g)}`);if(!t.ok)throw new Error(`Failed to resolve ${g}@${e}`);let n=(await t.json())["dist-tags"]?.[e];if(!n)throw new Error(`Could not find dist-tag ${e} for ${g}`);return n},ut=async e=>{let t=await P(e),s=R(t,g);if(!s)return{currentVersion:s,nextVersion:void 0,updated:!1};let n=dt(s),a=await gt(n);return s===a?{currentVersion:s,nextVersion:a,updateTag:n,updated:!1}:(b(t,g,a),await x(e,t),{currentVersion:s,nextVersion:a,updateTag:n,updated:!0})},ft=async(e,t,s)=>{let n=await P(e);if(!V(n,g))return!1;t&&t.length>0&&p.warn("Ignoring file patterns for a package-based site. This update will bump the package version instead."),s?.sync&&p.warn("Ignoring --sync for a package-based site. Runtime updates now come from the package version.");let{currentVersion:a,nextVersion:r,updateTag:i,updated:l}=await ut(e);if(!l)return p.success(a?`@vercel/geistdocs is already at ${r} (${i}).`:"No package version update was needed."),C("Package-based site is already up to date."),!0;p.info(`Bumping ${g} from ${a} to ${r} (${i})`);let c=Q();return c.start("Installing updated package version..."),await m("pnpm",["install"],{cwd:e}),c.stop("Package update complete!"),C("Please review and test the upgraded package version."),!0},mt=async(e,t,s,n,a)=>{let r=w(e,O),i=Q(),l=a?.sync?r:t;i.start("Preparing template snapshot..."),a?.sync&&(await rt(e,O),await F(r)),i.message("Scanning for files...");let c=await X(s,n,l),o=[];if(a?.sync){i.message("Comparing with local files...");let u=await X(s,n,e),f=new Set(c);o=u.filter(k=>!f.has(k))}if(i.stop(`Found ${c.length} files to update`),c.length===0&&o.length===0){p.warn("No files matched the patterns. Nothing to update."),a?.sync&&await I(r),C("Update cancelled.");return}p.info(`Patterns: ${s.length}`),p.info(`Files to update: ${c.length}`),a?.sync&&p.info(`Files to delete: ${o.length}`),i.start("Updating files...");let d=await lt(c,o,l,e,i);a?.sync&&(i.message("Cleaning up..."),await I(r)),i.stop("Update complete!"),pt(d),C("Please review and test the changes carefully.")},ee=async(e,t)=>{let s=process.cwd(),n=j(),a=e&&e.length>0?e:nt,r=e&&e.length>0?[]:at;try{if(tt("Let's update your Geistdocs project!"),await ft(s,e,t))return;p.info("Template source: bundled package snapshot"),e&&e.length>0&&p.info(`Updating specific files: ${e.join(", ")}`),t?.sync&&p.info("Sync mode enabled: will delete files removed from template"),await mt(s,n,a,r,t)}catch(i){let l=i instanceof Error?i.message:`${i}`;try{await I(w(s,O))}catch{}p.error(`Failed to update project: ${l}`),process.exit(1)}};T.name("geistdocs").description("CLI for Geistdocs projects").version("1.25.1-canary.4e75e60","-v, --version","Output the current version");T.command("init").description("Initialize a new Geistdocs project").option("--name <name>","Name of the project").option("--disable-git","Disable git initialization").action(G);T.command("update [files...]").description("Update a Geistdocs project (optionally specify files/patterns to update)").option("--sync","Delete local files that no longer exist in the template").action(ee);T.command("translate [pattern]").description("Translate MDX file(s) to one or more locales (default: content/docs/**/*.mdx)").option("--config <path>","Path to config file to load locales from (defaults to geistdocs.tsx)").option("--url <url>","Custom translation API URL (defaults to GEISTDOCS_TRANSLATE_URL or https://geistdocs.com/translate)").option("--force","Force re-translation of all files, ignoring cache").action(q);T.parse(process.argv);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callout.d.ts","sourceRoot":"","sources":["../../src/components/callout.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvD,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAE9E,UAAU,qBAAsB,SAAQ,cAAc,CAAC,KAAK,CAAC;IAC3D,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED,KAAK,YAAY,GAAG,IAAI,CAAC,qBAAqB,EAAE,OAAO,CAAC,GAAG;IACzD,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,+BAA+B,YAAY,
|
|
1
|
+
{"version":3,"file":"callout.d.ts","sourceRoot":"","sources":["../../src/components/callout.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvD,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAE9E,UAAU,qBAAsB,SAAQ,cAAc,CAAC,KAAK,CAAC;IAC3D,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED,KAAK,YAAY,GAAG,IAAI,CAAC,qBAAqB,EAAE,OAAO,CAAC,GAAG;IACzD,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,+BAA+B,YAAY,4CASlE,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,sDAM9B,qBAAqB,4CAcvB,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,yBAAyB,cAAc,CAAC,GAAG,CAAC,4CAExE,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,yBAGhC,cAAc,CAAC,KAAK,CAAC,4CAEvB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { cn } from "@vercel/geistcn/utils";
|
|
3
3
|
import { IconInformation } from "@vercel/geistcn-assets/icons";
|
|
4
|
-
export const Callout = ({ children, title, ...props }) => (_jsxs(CalloutContainer, { ...props, children: [title ? _jsx(CalloutTitle, { children: title }) : null, _jsx(CalloutDescription, { children: children })] }));
|
|
4
|
+
export const Callout = ({ children, title, ...props }) => (_jsxs(CalloutContainer, { ...props, children: [title ? _jsx(CalloutTitle, { children: title }) : null, _jsx(CalloutDescription, { className: title ? "[&:has(>p:first-child)]:mt-[7px]" : undefined, children: children })] }));
|
|
5
5
|
export const CalloutContainer = ({ children, className, icon, type: _type, ...props }) => (_jsxs("div", { className: cn("my-4 flex items-start justify-start gap-3 rounded-[6px] bg-gray-100 px-4 py-3 font-normal text-copy-14 **:leading-[150%] [&_code]:text-[12px]!", "[&_ul]:list-none [&_ul]:pl-0! [&_ul_li]:relative [&_ul_li]:pl-6! [&_ul_li]:before:absolute [&_ul_li]:before:top-[0.6em] [&_ul_li]:before:left-0 [&_ul_li]:before:size-[5px] [&_ul_li]:before:rounded-full [&_ul_li]:before:bg-gray-600 [&_ul_li]:before:content-['']", className), ...props, children: [icon ?? (_jsx(IconInformation, { className: "mt-0.5 size-4 flex-none", color: "gray-900" })), _jsx("div", { className: "min-w-0 flex-1", children: children })] }));
|
|
6
6
|
export const CalloutTitle = ({ className, ...props }) => (_jsx("p", { className: cn("my-0! font-medium", className), ...props }));
|
|
7
7
|
export const CalloutDescription = ({ className, ...props }) => (_jsx("div", { className: cn("prose-no-margin", className), ...props }));
|
package/dist/controls.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controls.d.ts","sourceRoot":"","sources":["../src/controls.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAS5D,UAAU,iBAAiB;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,YAAY,GAAI,wBAAwB,iBAAiB,4CAqBrE,CAAC;AAEF,eAAO,MAAM,WAAW,+CA0CvB,CAAC;AAEF,eAAO,MAAM,gBAAgB,sDA+B5B,CAAC;AAEF,UAAU,gBAAgB;IACxB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAC;IACpD,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;CAChD;AAED,eAAO,MAAM,WAAW,GAAI,0DAOzB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"controls.d.ts","sourceRoot":"","sources":["../src/controls.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAS5D,UAAU,iBAAiB;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,YAAY,GAAI,wBAAwB,iBAAiB,4CAqBrE,CAAC;AAEF,eAAO,MAAM,WAAW,+CA0CvB,CAAC;AAEF,eAAO,MAAM,gBAAgB,sDA+B5B,CAAC;AAEF,UAAU,gBAAgB;IACxB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAC;IACpD,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;CAChD;AAED,eAAO,MAAM,WAAW,GAAI,0DAOzB,gBAAgB,mDA+BlB,CAAC"}
|
package/dist/controls.js
CHANGED
|
@@ -39,16 +39,17 @@ export const LanguageSelector = () => {
|
|
|
39
39
|
return (_jsxs(DropdownMenu, { children: [_jsxs(DropdownMenuTrigger, { "aria-label": "Select Language", className: "flex items-center justify-center rounded-md p-2 hover:bg-gray-alpha-100 focus-visible:shadow-[var(--ds-focus-ring)] focus-visible:outline-none active:bg-gray-alpha-300", children: [_jsx(IconLanguages, { className: "size-4.5" }), _jsx("span", { className: "sr-only", children: "Select Language" })] }), _jsx(DropdownMenuContent, { align: "end", children: locales.map((lang) => (_jsxs(DropdownMenuItem, { className: "flex cursor-pointer items-center justify-between", disabled: locale === lang.locale, onClick: () => onChange?.(lang.locale), children: [lang.name, locale === lang.locale && _jsx(IconCheck, { className: "size-4" })] }, lang.locale))) })] }));
|
|
40
40
|
};
|
|
41
41
|
export const AskAIButton = ({ children, className, prompt, size = "small", variant = "secondary", ...props }) => {
|
|
42
|
-
const { enabled, isOpen, setIsOpen, setPrompt } = useGeistdocsChat();
|
|
42
|
+
const { enabled, isOpen, preloadChat, setIsOpen, setPrompt } = useGeistdocsChat();
|
|
43
43
|
if (!enabled) {
|
|
44
44
|
return null;
|
|
45
45
|
}
|
|
46
46
|
return (_jsx(Button, { className: cn("shrink-0", className), onClick: () => {
|
|
47
|
+
preloadChat();
|
|
47
48
|
if (prompt) {
|
|
48
49
|
setPrompt(prompt);
|
|
49
50
|
setIsOpen(true);
|
|
50
51
|
return;
|
|
51
52
|
}
|
|
52
53
|
setIsOpen(!isOpen);
|
|
53
|
-
}, size: size, typeName: "button", variant: variant, ...props, children: children ?? _jsx("span", { children: "Ask AI" }) }));
|
|
54
|
+
}, onFocus: preloadChat, onMouseEnter: preloadChat, size: size, typeName: "button", variant: variant, ...props, children: children ?? _jsx("span", { children: "Ask AI" }) }));
|
|
54
55
|
};
|
|
@@ -3,7 +3,9 @@ interface GeistdocsChatContextValue {
|
|
|
3
3
|
basePath?: string;
|
|
4
4
|
enabled: boolean;
|
|
5
5
|
footer?: React.ReactNode;
|
|
6
|
+
hasBeenOpened: boolean;
|
|
6
7
|
isOpen: boolean;
|
|
8
|
+
preloadChat: () => void;
|
|
7
9
|
prompt: string;
|
|
8
10
|
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
9
11
|
setPrompt: React.Dispatch<React.SetStateAction<string>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/context.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/context.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAIpD,UAAU,yBAAyB;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IACzD,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IACxD,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAMD,eAAO,MAAM,gBAAgB,iCAQ5B,CAAC;AAEF,UAAU,0BAA0B;IAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,UAAU,GAAG,OAAO,CAAC,CAAC;CAC5D;AAED,eAAO,MAAM,qBAAqB,GAAI,uBAGnC,0BAA0B,4CAyD5B,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from "react";
|
|
4
4
|
const CHAT_OPEN_STORAGE_KEY = "geistdocs:chat-open";
|
|
5
5
|
const GeistdocsChatContext = createContext(null);
|
|
6
6
|
export const useGeistdocsChat = () => {
|
|
@@ -12,13 +12,24 @@ export const useGeistdocsChat = () => {
|
|
|
12
12
|
};
|
|
13
13
|
export const GeistdocsChatProvider = ({ children, config, }) => {
|
|
14
14
|
const [isOpen, setIsOpen] = useState(false);
|
|
15
|
+
const [hasBeenOpened, setHasBeenOpened] = useState(false);
|
|
15
16
|
const [prompt, setPrompt] = useState("");
|
|
17
|
+
const preloadChat = useCallback(() => setHasBeenOpened(true), []);
|
|
16
18
|
useEffect(() => {
|
|
17
19
|
const stored = window.localStorage.getItem(CHAT_OPEN_STORAGE_KEY);
|
|
18
20
|
if (stored !== null) {
|
|
19
|
-
|
|
21
|
+
const open = stored === "true";
|
|
22
|
+
setIsOpen(open);
|
|
23
|
+
if (open) {
|
|
24
|
+
setHasBeenOpened(true);
|
|
25
|
+
}
|
|
20
26
|
}
|
|
21
27
|
}, []);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (isOpen) {
|
|
30
|
+
setHasBeenOpened(true);
|
|
31
|
+
}
|
|
32
|
+
}, [isOpen]);
|
|
22
33
|
useEffect(() => {
|
|
23
34
|
window.localStorage.setItem(CHAT_OPEN_STORAGE_KEY, String(isOpen));
|
|
24
35
|
}, [isOpen]);
|
|
@@ -26,12 +37,22 @@ export const GeistdocsChatProvider = ({ children, config, }) => {
|
|
|
26
37
|
basePath: config.basePath,
|
|
27
38
|
footer: config.ai?.footer,
|
|
28
39
|
enabled: config.ai?.enabled !== false,
|
|
40
|
+
hasBeenOpened,
|
|
29
41
|
isOpen,
|
|
42
|
+
preloadChat,
|
|
30
43
|
prompt,
|
|
31
44
|
setIsOpen,
|
|
32
45
|
setPrompt,
|
|
33
46
|
suggestions: config.ai?.suggestions ?? [],
|
|
34
47
|
title: config.title,
|
|
35
|
-
}), [
|
|
48
|
+
}), [
|
|
49
|
+
config.ai,
|
|
50
|
+
config.basePath,
|
|
51
|
+
config.title,
|
|
52
|
+
hasBeenOpened,
|
|
53
|
+
isOpen,
|
|
54
|
+
preloadChat,
|
|
55
|
+
prompt,
|
|
56
|
+
]);
|
|
36
57
|
return (_jsx(GeistdocsChatContext.Provider, { value: value, children: children }));
|
|
37
58
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const ChatConversationSkeleton: () => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare const ChatEmptySkeleton: () => import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare const ChatLoadingSkeleton: ({ isMobile, title, }: {
|
|
4
|
+
isMobile: boolean;
|
|
5
|
+
title: string;
|
|
6
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
//# sourceMappingURL=loading-skeleton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loading-skeleton.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/loading-skeleton.tsx"],"names":[],"mappings":"AAsCA,eAAO,MAAM,wBAAwB,+CAyCpC,CAAC;AAEF,eAAO,MAAM,iBAAiB,+CAsB7B,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,sBAGjC;IACD,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,4CAmBA,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Skeleton } from "@vercel/geistcn/components/skeleton";
|
|
4
|
+
import { cn } from "@vercel/geistcn/utils";
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
const getMessageCount = async (title) => {
|
|
7
|
+
const name = title.replaceAll(" ", "").toLowerCase();
|
|
8
|
+
if ("databases" in indexedDB) {
|
|
9
|
+
const databases = await indexedDB.databases();
|
|
10
|
+
if (!databases.some((database) => database.name === name)) {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
const request = indexedDB.open(name);
|
|
16
|
+
request.onerror = () => resolve(0);
|
|
17
|
+
request.onupgradeneeded = () => {
|
|
18
|
+
request.transaction?.abort();
|
|
19
|
+
resolve(0);
|
|
20
|
+
};
|
|
21
|
+
request.onsuccess = () => {
|
|
22
|
+
const database = request.result;
|
|
23
|
+
if (!database.objectStoreNames.contains("messages")) {
|
|
24
|
+
database.close();
|
|
25
|
+
resolve(0);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const transaction = database.transaction("messages", "readonly");
|
|
29
|
+
const count = transaction.objectStore("messages").count();
|
|
30
|
+
count.onerror = () => resolve(0);
|
|
31
|
+
count.onsuccess = () => resolve(count.result);
|
|
32
|
+
transaction.oncomplete = () => database.close();
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export const ChatConversationSkeleton = () => (_jsxs("div", { className: "relative flex flex-1 flex-col justify-start gap-7 overflow-hidden px-4 pt-12 pb-4", children: [_jsxs("div", { className: "relative mr-2 ml-auto w-[260px]", children: [_jsx("div", { className: "relative min-h-10 animate-pulse rounded-[10px] bg-gray-200" }), _jsx("svg", { "aria-hidden": "true", className: "absolute right-[2.5px] -bottom-[0.5px] z-10 translate-x-1/2 fill-gray-200/80", height: "14", viewBox: "0 0 18 14", width: "18", children: _jsx("path", { d: "M0.866025 8.80383L11.2583 0.803833C11.2583 0.803833 12.0621 9.5 17.2583 13.1961C12.0621 13.1961 0.866025 8.80383 0.866025 8.80383Z" }) })] }), _jsx(Skeleton, { height: 25, width: "20%" }), _jsxs("div", { className: "flex shrink-0 flex-col gap-4", children: [_jsxs("div", { className: "w-[80%] flex-1 space-y-2", children: [_jsx(Skeleton, { height: 20, width: "66%" }), _jsx(Skeleton, { height: 20, width: "100%" }), _jsx(Skeleton, { height: 20, width: "75%" })] }), _jsxs("div", { className: "w-[80%] flex-1 space-y-2", children: [_jsx(Skeleton, { height: 20, width: "50%" }), _jsx(Skeleton, { height: 20, width: "100%" }), _jsx(Skeleton, { height: 20, width: "83%" }), _jsx(Skeleton, { height: 20, width: "66%" })] }), _jsxs("div", { className: "w-[80%] flex-1 space-y-2", children: [_jsx(Skeleton, { height: 20, width: "75%" }), _jsx(Skeleton, { height: 20, width: "100%" }), _jsx(Skeleton, { height: 20, width: "50%" })] }), _jsxs("div", { className: "w-[80%] flex-1 space-y-2", children: [_jsx(Skeleton, { height: 20, width: "66%" }), _jsx(Skeleton, { height: 20, width: "100%" }), _jsx(Skeleton, { height: 20, width: "75%" }), _jsx(Skeleton, { height: 20, width: "33%" })] })] }), _jsx("div", { className: "absolute inset-x-0 bottom-0 h-52 bg-gradient-to-t from-background-100 via-background-100 to-transparent" })] }));
|
|
37
|
+
export const ChatEmptySkeleton = () => (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "flex h-16 shrink-0 items-center justify-between px-3.5 py-2", children: [_jsx(Skeleton, { height: 20, width: 56 }), _jsx("div", { className: "flex items-center gap-1", children: [0, 1, 2, 3].map((item) => (_jsx(Skeleton, { height: 32, rounded: true, width: 32 }, item))) })] }), _jsxs("div", { className: "flex min-h-0 flex-1 flex-col justify-end", children: [_jsxs("div", { className: "flex flex-col gap-2 px-4 pt-4", children: [[0, 1, 2, 3].map((item) => (_jsx(Skeleton, { block: true, height: 36, width: "100%" }, item))), _jsx(Skeleton, { className: "mt-3 mb-2 ml-2", height: 16, width: "72%" })] }), _jsx("div", { className: "p-4", children: _jsx(Skeleton, { block: true, className: "rounded-[12px]", height: 88, width: "100%" }) })] })] }));
|
|
38
|
+
export const ChatLoadingSkeleton = ({ isMobile, title, }) => {
|
|
39
|
+
const [conversation, setConversation] = useState(false);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
getMessageCount(title).then((count) => setConversation(count > 0));
|
|
42
|
+
}, [title]);
|
|
43
|
+
return (_jsx("div", { className: cn("fixed z-45 flex flex-col bg-background-100", isMobile
|
|
44
|
+
? "inset-x-0 bottom-0 h-[80dvh] rounded-t-xl"
|
|
45
|
+
: "inset-y-0 right-0 w-[400px] border-l"), children: conversation ? _jsx(ChatConversationSkeleton, {}) : _jsx(ChatEmptySkeleton, {}) }));
|
|
46
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/message.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/message.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAA6B,UAAU,EAAE,MAAM,YAAY,CAAC;AAoGnE,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC,cAAc,CAAC,GAAG;IAC1D,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;CAChD,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,+BAA+B,YAAY,4CASlE,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;AAEjE,eAAO,MAAM,cAAc,GAAI,mCAI5B,mBAAmB,4CAqBrB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC,OAAO,UAAU,CAAC,CAAC;AAErE,eAAO,MAAM,eAAe,gEACA,oBAAoB,6CAa/C,CAAC"}
|
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { cjk } from "@streamdown/cjk";
|
|
4
4
|
import { code } from "@streamdown/code";
|
|
5
|
+
import { Modal, ModalAction, ModalActions, ModalBody, ModalHeader, ModalSubtitle, ModalTitle, } from "@vercel/geistcn/components/modal";
|
|
5
6
|
import { cn } from "@vercel/geistcn/utils";
|
|
6
|
-
import {
|
|
7
|
+
import { IconArrowUpRightSmall } from "@vercel/geistcn-assets/icons";
|
|
8
|
+
import { memo, useState } from "react";
|
|
7
9
|
import { Streamdown } from "streamdown";
|
|
10
|
+
const LinkSafetyModal = ({ isOpen, onClose, onConfirm, url, }) => {
|
|
11
|
+
return (_jsxs(Modal, { active: isOpen, drawer: false, onClickOutside: onClose, style: {
|
|
12
|
+
background: "var(--ds-background-200)",
|
|
13
|
+
boxShadow: "var(--ds-shadow-modal)",
|
|
14
|
+
}, width: 448, children: [_jsxs(ModalBody, { className: "bg-background-200", padding: 24, children: [_jsxs(ModalHeader, { children: [_jsx(ModalTitle, { children: "Open external link?" }), _jsx(ModalSubtitle, { children: "You\u2019re about to visit an external website." })] }), _jsx("div", { className: "break-all rounded-md bg-gray-100 p-3 font-mono text-copy-13", children: url })] }), _jsxs(ModalActions, { children: [_jsx(ModalAction, { onClick: onClose, variant: "secondary", children: "Cancel" }), _jsx(ModalAction, { onClick: onConfirm, children: "Open link" })] })] }));
|
|
15
|
+
};
|
|
16
|
+
const ChatLink = ({ children, className, href, node: _node, ...props }) => {
|
|
17
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
18
|
+
const external = typeof href === "string" &&
|
|
19
|
+
(href.startsWith("http://") || href.startsWith("https://"));
|
|
20
|
+
if (!external) {
|
|
21
|
+
return (_jsx("a", { className: cn("font-normal text-gray-1000! underline decoration-1 decoration-gray-700 underline-offset-4 hover:text-gray-1000! hover:decoration-gray-1000 hover:opacity-100!", className), href: href, ...props, children: children }));
|
|
22
|
+
}
|
|
23
|
+
return (_jsxs(_Fragment, { children: [_jsxs("button", { className: cn("group wrap-anywhere cursor-pointer appearance-none text-left font-normal text-gray-1000! no-underline hover:text-gray-1000! hover:opacity-100!", className), onClick: () => setIsOpen(true), type: "button", children: [_jsx("span", { className: "underline decoration-1 decoration-gray-700 underline-offset-4 group-hover:decoration-gray-1000", children: children }), _jsxs("span", { className: "whitespace-nowrap", children: ["\u00a0", _jsx("span", { className: "inline-flex -translate-y-1 align-text-bottom", children: _jsx(IconArrowUpRightSmall, { size: 16 }) })] })] }), _jsx(LinkSafetyModal, { isOpen: isOpen, onClose: () => setIsOpen(false), onConfirm: () => {
|
|
24
|
+
window.open(href, "_blank", "noreferrer");
|
|
25
|
+
setIsOpen(false);
|
|
26
|
+
}, url: href })] }));
|
|
27
|
+
};
|
|
8
28
|
export const Message = ({ className, from, ...props }) => (_jsx("div", { className: cn("group flex w-full flex-col gap-2 py-4 [&>div]:max-w-[80%]", from === "user" ? "is-user items-end" : "is-assistant items-start", className), ...props }));
|
|
9
29
|
export const MessageContent = ({ children, className, ...props }) => (_jsxs("div", { className: cn("relative flex min-h-10 w-fit min-w-0 max-w-full flex-col gap-2 whitespace-normal rounded-[12px] px-4 py-2 text-left text-sm leading-relaxed", "group-[.is-user]:bg-gray-1000 group-[.is-user]:text-white group-[.is-user]:dark:bg-gray-100 group-[.is-user]:dark:text-gray-1000", "group-[.is-assistant]:min-h-0 group-[.is-assistant]:px-0 group-[.is-assistant]:py-0 group-[.is-assistant]:text-gray-1000", className), ...props, children: [_jsx("div", { className: "is-user:dark", children: children }), _jsx("svg", { "aria-hidden": "true", className: "absolute right-[2.5px] -bottom-[0.5px] hidden translate-x-1/2 group-[.is-user]:block group-[.is-user]:fill-gray-1000 group-[.is-user]:dark:fill-gray-100", height: "14", viewBox: "0 0 18 14", width: "18", children: _jsx("path", { d: "M0.866025 8.80383L11.2583 0.803833C11.2583 0.803833 12.0621 9.5 17.2583 13.1961C12.0621 13.1961 0.866025 8.80383 0.866025 8.80383Z" }) })] }));
|
|
10
|
-
export const MessageResponse = memo(({ className, ...props }) => (_jsx(Streamdown, { className: cn("size-full whitespace-normal text-left text-sm leading-relaxed [&>*:first-child]:mt-0 [&>*:last-child]:mb-0", className), plugins: { code, cjk }, ...props })), (prevProps, nextProps) => prevProps.children === nextProps.children);
|
|
30
|
+
export const MessageResponse = memo(({ className, ...props }) => (_jsx(Streamdown, { className: cn("size-full whitespace-normal text-left text-sm leading-relaxed [&>*:first-child]:mt-0 [&>*:last-child]:mb-0", className), components: { a: ChatLink }, linkSafety: { enabled: true, renderModal: LinkSafetyModal }, plugins: { code, cjk }, ...props })), (prevProps, nextProps) => prevProps.children === nextProps.children);
|
|
11
31
|
MessageResponse.displayName = "MessageResponse";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/shell.tsx"],"names":[],"mappings":"AAgYA,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/shell.tsx"],"names":[],"mappings":"AAgYA,eAAO,MAAM,kBAAkB,sDAsD9B,CAAC"}
|
|
@@ -189,23 +189,18 @@ const GeistdocsChatErrorBoundary = catchError(GeistdocsChatErrorFallback);
|
|
|
189
189
|
export const GeistdocsChatShell = () => {
|
|
190
190
|
const { enabled, isOpen, setIsOpen } = useGeistdocsChat();
|
|
191
191
|
const isMobile = useIsMobile();
|
|
192
|
-
useEffect(() => {
|
|
193
|
-
const handleKeyDown = (event) => {
|
|
194
|
-
if ((event.metaKey || event.ctrlKey) &&
|
|
195
|
-
!event.altKey &&
|
|
196
|
-
!event.shiftKey &&
|
|
197
|
-
event.key.toLowerCase() === "i") {
|
|
198
|
-
event.preventDefault();
|
|
199
|
-
setIsOpen((prev) => !prev);
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
203
|
-
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
204
|
-
}, [setIsOpen]);
|
|
205
192
|
if (!enabled) {
|
|
206
193
|
return null;
|
|
207
194
|
}
|
|
208
|
-
return (_jsxs(_Fragment, { children: [
|
|
195
|
+
return (_jsxs(_Fragment, { children: [isOpen ? (_jsx("style", { children: `
|
|
196
|
+
html {
|
|
197
|
+
scrollbar-width: none !important;
|
|
198
|
+
-ms-overflow-style: none !important;
|
|
199
|
+
}
|
|
200
|
+
html::-webkit-scrollbar {
|
|
201
|
+
display: none !important;
|
|
202
|
+
}
|
|
203
|
+
` })) : null, _jsx(Portal.Root, { children: _jsx("div", { className: cn(
|
|
209
204
|
// z-45 keeps the panel above the sticky navbar (z-40) but below
|
|
210
205
|
// modal surfaces like the search command menu, dialogs, and
|
|
211
206
|
// dropdowns (z-50), so opening the command menu paints over an
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/sources.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAEL,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;AAEjD,eAAO,MAAM,OAAO,GAAI,yBAAyB,YAAY,4CAK5D,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,OAAO,kBAAkB,CAAC,GAAG;IAC5E,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,0CAK5B,mBAAmB,4CAerB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE5E,eAAO,MAAM,cAAc,GAAI,yBAG5B,mBAAmB,4CAErB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjE,eAAO,MAAM,MAAM,GAAI,qCAAqC,WAAW,
|
|
1
|
+
{"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/sources.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAEL,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;AAEjD,eAAO,MAAM,OAAO,GAAI,yBAAyB,YAAY,4CAK5D,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,OAAO,kBAAkB,CAAC,GAAG;IAC5E,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,0CAK5B,mBAAmB,4CAerB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE5E,eAAO,MAAM,cAAc,GAAI,yBAG5B,mBAAmB,4CAErB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjE,eAAO,MAAM,MAAM,GAAI,qCAAqC,WAAW,4CAgBtE,CAAC"}
|
|
@@ -6,4 +6,7 @@ import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "../ui/coll
|
|
|
6
6
|
export const Sources = ({ className, ...props }) => (_jsx(Collapsible, { className: cn("not-prose text-gray-600 text-xs", className), ...props }));
|
|
7
7
|
export const SourcesTrigger = ({ className, count, children, ...props }) => (_jsx(CollapsibleTrigger, { className: cn("group flex items-center rounded-md border-none bg-transparent", className), ...props, children: children ?? (_jsxs(_Fragment, { children: [_jsxs("p", { className: "font-medium", children: ["Used ", count, " sources"] }), _jsx(IconChevronDown, { className: "h-4 w-4 transition-transform duration-200 group-data-[state=open]:rotate-180" })] })) }));
|
|
8
8
|
export const SourcesContent = ({ className, ...props }) => (_jsx(CollapsibleContent, { className: cn("flex flex-col", className), ...props }));
|
|
9
|
-
export const Source = ({ href, title, children, ...props }) =>
|
|
9
|
+
export const Source = ({ href, title, children, ...props }) => {
|
|
10
|
+
const external = href.startsWith("http://") || href.startsWith("https://");
|
|
11
|
+
return (_jsx("a", { className: "inline-flex min-w-0 max-w-full items-center underline underline-offset-1", href: href, rel: external ? "noreferrer" : undefined, target: external ? "_blank" : undefined, ...props, children: children ?? (_jsx("span", { className: "truncate font-medium text-gray-1000", children: title })) }));
|
|
12
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PointerEvent as ReactPointerEvent } from "react";
|
|
2
|
+
export declare const getMouseDownRouterHref: (href: string, basePath: string | undefined) => string;
|
|
3
|
+
export declare const findMouseDownNavigationAnchor: (target: EventTarget | null, boundary: EventTarget | null) => HTMLAnchorElement | null;
|
|
4
|
+
export declare const shouldNavigateOnPointerDown: (event: ReactPointerEvent, anchor: HTMLAnchorElement) => boolean;
|
|
5
|
+
//# sourceMappingURL=mousedown-navigation-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mousedown-navigation-utils.d.ts","sourceRoot":"","sources":["../../src/internal/mousedown-navigation-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAwB/D,eAAO,MAAM,sBAAsB,GACjC,MAAM,MAAM,EACZ,UAAU,MAAM,GAAG,SAAS,WAoB7B,CAAC;AAEF,eAAO,MAAM,6BAA6B,GACxC,QAAQ,WAAW,GAAG,IAAI,EAC1B,UAAU,WAAW,GAAG,IAAI,KAC3B,iBAAiB,GAAG,IAWtB,CAAC;AAyBF,eAAO,MAAM,2BAA2B,GACtC,OAAO,iBAAiB,EACxB,QAAQ,iBAAiB,YA0C1B,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const TRAILING_SLASH_PATTERN = /\/$/;
|
|
2
|
+
const normalizeRouterBasePath = (basePath) => {
|
|
3
|
+
if (!basePath || basePath === "/") {
|
|
4
|
+
return "";
|
|
5
|
+
}
|
|
6
|
+
const normalized = basePath.startsWith("/") ? basePath : `/${basePath}`;
|
|
7
|
+
return normalized.replace(TRAILING_SLASH_PATTERN, "");
|
|
8
|
+
};
|
|
9
|
+
const NESTED_CONTROL_TAGS = new Set([
|
|
10
|
+
"BUTTON",
|
|
11
|
+
"INPUT",
|
|
12
|
+
"LABEL",
|
|
13
|
+
"SELECT",
|
|
14
|
+
"SUMMARY",
|
|
15
|
+
"TEXTAREA",
|
|
16
|
+
]);
|
|
17
|
+
const HANDLED_KEY = "__geistdocsMouseDownNavigationHandled";
|
|
18
|
+
export const getMouseDownRouterHref = (href, basePath) => {
|
|
19
|
+
const normalizedBasePath = normalizeRouterBasePath(basePath);
|
|
20
|
+
if (!normalizedBasePath) {
|
|
21
|
+
return href;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const url = new URL(href, window.location.origin);
|
|
25
|
+
if (url.pathname === normalizedBasePath) {
|
|
26
|
+
return `/${url.search}${url.hash}`;
|
|
27
|
+
}
|
|
28
|
+
if (url.pathname.startsWith(`${normalizedBasePath}/`)) {
|
|
29
|
+
return `${url.pathname.slice(normalizedBasePath.length)}${url.search}${url.hash}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return href;
|
|
34
|
+
}
|
|
35
|
+
return href;
|
|
36
|
+
};
|
|
37
|
+
export const findMouseDownNavigationAnchor = (target, boundary) => {
|
|
38
|
+
let element = target;
|
|
39
|
+
while (element && element !== boundary) {
|
|
40
|
+
if (element.tagName === "A") {
|
|
41
|
+
return element;
|
|
42
|
+
}
|
|
43
|
+
element = element.parentElement;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
};
|
|
47
|
+
const startsOnNestedControl = (target, anchor) => {
|
|
48
|
+
if (anchor.hasAttribute("data-no-mousedown-nav")) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
let element = target;
|
|
52
|
+
while (element && element !== anchor) {
|
|
53
|
+
if (element.hasAttribute("data-no-mousedown-nav") ||
|
|
54
|
+
NESTED_CONTROL_TAGS.has(element.tagName) ||
|
|
55
|
+
element.getAttribute("role") === "button") {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
element = element.parentElement;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
export const shouldNavigateOnPointerDown = (event, anchor) => {
|
|
63
|
+
if (event.defaultPrevented ||
|
|
64
|
+
event.button !== 0 ||
|
|
65
|
+
event.pointerType !== "mouse" ||
|
|
66
|
+
event.altKey ||
|
|
67
|
+
event.ctrlKey ||
|
|
68
|
+
event.metaKey ||
|
|
69
|
+
event.shiftKey ||
|
|
70
|
+
startsOnNestedControl(event.target, anchor)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const nativeEvent = event.nativeEvent;
|
|
74
|
+
if (nativeEvent[HANDLED_KEY] === true) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const target = anchor.getAttribute("target");
|
|
78
|
+
if ((target && target !== "_self") || anchor.hasAttribute("download")) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
const href = anchor.getAttribute("href");
|
|
82
|
+
if (!href || href.startsWith("#")) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
if (new URL(href, window.location.origin).origin !== window.location.origin) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
nativeEvent[HANDLED_KEY] = true;
|
|
94
|
+
return true;
|
|
95
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Starts same-origin mouse navigation on pointer down, matching Vercel's
|
|
4
|
+
* marketing navbar behavior. Browser click behavior remains the fallback for
|
|
5
|
+
* keyboard activation, touch, modified clicks, downloads, and external links.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MouseDownNavigation: ({ children }: {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
//# sourceMappingURL=mousedown-navigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mousedown-navigation.d.ts","sourceRoot":"","sources":["../../src/internal/mousedown-navigation.tsx"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,SAAS,EAIf,MAAM,OAAO,CAAC;AAQf;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,cAAc;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,4CAkDxE,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useRouter } from "next/navigation";
|
|
4
|
+
import { useCallback, useRef, } from "react";
|
|
5
|
+
import { useGeistdocsConfig } from "./config-context";
|
|
6
|
+
import { findMouseDownNavigationAnchor, getMouseDownRouterHref, shouldNavigateOnPointerDown, } from "./mousedown-navigation-utils";
|
|
7
|
+
/**
|
|
8
|
+
* Starts same-origin mouse navigation on pointer down, matching Vercel's
|
|
9
|
+
* marketing navbar behavior. Browser click behavior remains the fallback for
|
|
10
|
+
* keyboard activation, touch, modified clicks, downloads, and external links.
|
|
11
|
+
*/
|
|
12
|
+
export const MouseDownNavigation = ({ children }) => {
|
|
13
|
+
const router = useRouter();
|
|
14
|
+
const { basePath } = useGeistdocsConfig();
|
|
15
|
+
const navigated = useRef(false);
|
|
16
|
+
const onPointerDownCapture = useCallback((event) => {
|
|
17
|
+
// A drag-off has no follow-up click inside this wrapper. Clear stale
|
|
18
|
+
// state at the beginning of every pointer interaction.
|
|
19
|
+
navigated.current = false;
|
|
20
|
+
const anchor = findMouseDownNavigationAnchor(event.target, event.currentTarget);
|
|
21
|
+
if (!(anchor && shouldNavigateOnPointerDown(event, anchor))) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const href = anchor.getAttribute("href");
|
|
25
|
+
if (!href) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
navigated.current = true;
|
|
29
|
+
router.push(getMouseDownRouterHref(href, basePath), {
|
|
30
|
+
scroll: anchor.getAttribute("data-scroll") !== "false",
|
|
31
|
+
});
|
|
32
|
+
}, [basePath, router]);
|
|
33
|
+
const onClickCapture = useCallback((event) => {
|
|
34
|
+
if (navigated.current) {
|
|
35
|
+
// Prevent Next.js/the browser from navigating a second time without
|
|
36
|
+
// stopping propagation, so click handlers and analytics still run.
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
navigated.current = false;
|
|
39
|
+
}
|
|
40
|
+
}, []);
|
|
41
|
+
return (_jsx("div", { onClickCapture: onClickCapture, onPointerDownCapture: onPointerDownCapture, style: { display: "contents" }, children: children }));
|
|
42
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navbar-shell.d.ts","sourceRoot":"","sources":["../../../src/internal/navbar/navbar-shell.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"navbar-shell.d.ts","sourceRoot":"","sources":["../../../src/internal/navbar/navbar-shell.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAM5D,eAAO,MAAM,WAAW,GAAI,cAAc;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,4CAqBhE,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { cn } from "@vercel/geistcn/utils";
|
|
4
4
|
import { useEffect, useState } from "react";
|
|
5
|
+
import { MouseDownNavigation } from "../mousedown-navigation";
|
|
5
6
|
// Sticky navbar shell that reveals its bottom divider (a box-shadow, so it
|
|
6
7
|
// doesn't consume the 64px content row) only once the page is scrolled —
|
|
7
8
|
// matching the vercel.com header.
|
|
@@ -13,5 +14,5 @@ export const NavbarShell = ({ children }) => {
|
|
|
13
14
|
window.addEventListener("scroll", onScroll, { passive: true });
|
|
14
15
|
return () => window.removeEventListener("scroll", onScroll);
|
|
15
16
|
}, []);
|
|
16
|
-
return (_jsx("header", { className: cn("sticky top-0 z-40 flex h-16 justify-center bg-background-200 transition-shadow motion-reduce:transition-none", scrolled && "shadow-[0_1px_0_0_var(--ds-gray-alpha-400)]"), "data-scrolled": scrolled ? "" : undefined, children: children }));
|
|
17
|
+
return (_jsx("header", { className: cn("sticky top-0 z-40 flex h-16 justify-center bg-background-200 transition-shadow motion-reduce:transition-none", scrolled && "shadow-[0_1px_0_0_var(--ds-gray-alpha-400)]"), "data-scrolled": scrolled ? "" : undefined, children: _jsx(MouseDownNavigation, { children: children }) }));
|
|
17
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-actions-client.d.ts","sourceRoot":"","sources":["../../src/internal/page-actions-client.tsx"],"names":[],"mappings":"AAoBA,OAAO,EAKL,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAgBjD,UAAU,gBAAgB;IACxB,MAAM,EAAE,IAAI,CACV,eAAe,EACf,IAAI,GAAG,UAAU,GAAG,QAAQ,GAAG,aAAa,GAAG,QAAQ,CACxD,CAAC;IACF;;;;OAIG;IACH,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC5B,IAAI,EAAE;QACJ,WAAW,EAAE,MAAM,CAAC;QACpB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH;AAED,UAAU,oCAAoC;IAC5C,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,GAAG,aAAa,GAAG,QAAQ,CAAC,CAAC;IACrE,YAAY,EAAE,SAAS,EAAE,CAAC;CAC3B;
|
|
1
|
+
{"version":3,"file":"page-actions-client.d.ts","sourceRoot":"","sources":["../../src/internal/page-actions-client.tsx"],"names":[],"mappings":"AAoBA,OAAO,EAKL,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAgBjD,UAAU,gBAAgB;IACxB,MAAM,EAAE,IAAI,CACV,eAAe,EACf,IAAI,GAAG,UAAU,GAAG,QAAQ,GAAG,aAAa,GAAG,QAAQ,CACxD,CAAC;IACF;;;;OAIG;IACH,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC5B,IAAI,EAAE;QACJ,WAAW,EAAE,MAAM,CAAC;QACpB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH;AAED,UAAU,oCAAoC;IAC5C,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,GAAG,aAAa,GAAG,QAAQ,CAAC,CAAC;IACrE,YAAY,EAAE,SAAS,EAAE,CAAC;CAC3B;AAqrBD,eAAO,MAAM,oBAAoB,GAAI,yBAIlC,gBAAgB,mDAyGlB,CAAC;AAEF,eAAO,MAAM,+BAA+B,GAAI,2BAG7C,oCAAoC,4CAiBtC,CAAC"}
|
|
@@ -198,7 +198,7 @@ const DesktopPageActions = ({ askAIEnabled, checked, copyEnabled, editSourceEnab
|
|
|
198
198
|
};
|
|
199
199
|
export const GeistdocsPageActions = ({ config, page, only, }) => {
|
|
200
200
|
const isMobile = useIsMobile();
|
|
201
|
-
const { enabled: chatEnabled, setIsOpen, setPrompt } = useGeistdocsChat();
|
|
201
|
+
const { enabled: chatEnabled, preloadChat, setIsOpen, setPrompt, } = useGeistdocsChat();
|
|
202
202
|
const [menuView, setMenuView] = useState("main");
|
|
203
203
|
const openInChatRef = useRef(null);
|
|
204
204
|
const providersBackRef = useRef(null);
|
|
@@ -211,25 +211,7 @@ export const GeistdocsPageActions = ({ config, page, only, }) => {
|
|
|
211
211
|
await navigator.clipboard.writeText(await fetchMarkdown());
|
|
212
212
|
});
|
|
213
213
|
const handleViewMarkdown = () => {
|
|
214
|
-
|
|
215
|
-
// markdown into a blob URL — keeps `.md` URLs out of the address bar
|
|
216
|
-
// and browser history (agents should cite canonical page URLs).
|
|
217
|
-
const viewer = window.open("about:blank", "_blank");
|
|
218
|
-
if (!viewer) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
fetchMarkdown()
|
|
222
|
-
.then((markdown) => {
|
|
223
|
-
const blob = new Blob([markdown], {
|
|
224
|
-
type: "text/plain;charset=utf-8",
|
|
225
|
-
});
|
|
226
|
-
const blobUrl = URL.createObjectURL(blob);
|
|
227
|
-
viewer.location.href = blobUrl;
|
|
228
|
-
setTimeout(() => URL.revokeObjectURL(blobUrl), 60_000);
|
|
229
|
-
})
|
|
230
|
-
.catch(() => {
|
|
231
|
-
viewer.close();
|
|
232
|
-
});
|
|
214
|
+
window.open(markdownUrl, "_blank", "noopener");
|
|
233
215
|
};
|
|
234
216
|
const editSourceUrl = getEditSourceUrl({
|
|
235
217
|
github: config.github,
|
|
@@ -250,13 +232,14 @@ export const GeistdocsPageActions = ({ config, page, only, }) => {
|
|
|
250
232
|
const showDesktop = only !== "mobile";
|
|
251
233
|
const showMobile = only !== "desktop";
|
|
252
234
|
const onAskAI = () => {
|
|
235
|
+
preloadChat();
|
|
253
236
|
setPrompt(getPageQuery(page.url, window.location.origin));
|
|
254
237
|
setIsOpen(true);
|
|
255
238
|
};
|
|
256
239
|
// Desktop variant aligns beside the title (self-end); the mobile variant is
|
|
257
240
|
// rendered below the description and left-aligned.
|
|
258
241
|
const rootClassName = only === "mobile" ? "@min-[961px]:hidden" : "self-end @max-[960px]:hidden";
|
|
259
|
-
return (_jsxs("div", { className: rootClassName, children: [showDesktop ? (_jsx(DesktopPageActions, { askAIEnabled: askAIEnabled, checked: checked, copyEnabled: copyEnabled, editSourceEnabled: editSourceEnabled, editSourceUrl: editSourceUrl, isMobile: isMobile, menuView: menuView, onAskAI: onAskAI, onCopy: handleCopy, onPrefetchMarkdown: prefetchMarkdown, onViewMarkdown: handleViewMarkdown, openInChatEnabled: openInChatEnabled, openInChatRef: openInChatRef, otherProviders: otherProviders, providersBackRef: providersBackRef, query: query, setMenuView: setMenuView, v0Provider: v0Provider })) : null, showMobile && (copyEnabled || askAIEnabled) ? (_jsx(InlinePageActions, { askAIEnabled: askAIEnabled, checked: checked, copyEnabled: copyEnabled, onAskAI: onAskAI, onCopy: handleCopy, onPrefetchMarkdown: prefetchMarkdown, onViewMarkdown: handleViewMarkdown })) : null, _jsx("span", { "aria-live": "polite", className: "sr-only", children: checked ? "Page copied" : "" })] }));
|
|
242
|
+
return (_jsxs("div", { className: rootClassName, onFocusCapture: preloadChat, onPointerEnter: preloadChat, children: [showDesktop ? (_jsx(DesktopPageActions, { askAIEnabled: askAIEnabled, checked: checked, copyEnabled: copyEnabled, editSourceEnabled: editSourceEnabled, editSourceUrl: editSourceUrl, isMobile: isMobile, menuView: menuView, onAskAI: onAskAI, onCopy: handleCopy, onPrefetchMarkdown: prefetchMarkdown, onViewMarkdown: handleViewMarkdown, openInChatEnabled: openInChatEnabled, openInChatRef: openInChatRef, otherProviders: otherProviders, providersBackRef: providersBackRef, query: query, setMenuView: setMenuView, v0Provider: v0Provider })) : null, showMobile && (copyEnabled || askAIEnabled) ? (_jsx(InlinePageActions, { askAIEnabled: askAIEnabled, checked: checked, copyEnabled: copyEnabled, onAskAI: onAskAI, onCopy: handleCopy, onPrefetchMarkdown: prefetchMarkdown, onViewMarkdown: handleViewMarkdown })) : null, _jsx("span", { "aria-live": "polite", className: "sr-only", children: checked ? "Page copied" : "" })] }));
|
|
260
243
|
};
|
|
261
244
|
export const GeistdocsTableOfContentsActions = ({ config, extraActions, }) => {
|
|
262
245
|
const actions = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-client.d.ts","sourceRoot":"","sources":["../../src/internal/provider-client.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,
|
|
1
|
+
{"version":3,"file":"provider-client.d.ts","sourceRoot":"","sources":["../../src/internal/provider-client.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EACL,KAAK,cAAc,EAKpB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAcjD,MAAM,WAAW,sBACf,SAAQ,cAAc,CAAC,OAAO,YAAY,CAAC;IAC3C,MAAM,EAAE,eAAe,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAgFD,eAAO,MAAM,iBAAiB,GAAI,OAAO,sBAAsB,4CAQ9D,CAAC"}
|