@tiptap/cli 1.1.11 → 1.1.12

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/index.js CHANGED
@@ -1,35 +1,35 @@
1
1
  #!/usr/bin/env node
2
- import rn from"path";import{Command as nn}from"commander";import{z as J}from"zod";import{createPrompt as Ut,useState as Re,useKeypress as Dt,usePrefix as Lt,usePagination as zt,useRef as We,useMemo as Te,useEffect as Vt,isBackspaceKey as Wt,isEnterKey as Gt,isUpKey as Ie,isDownKey as Ge,isNumberKey as Kt,Separator as ie,ValidationError as Bt,makeTheme as Yt}from"@inquirer/core";import Ke from"yoctocolors-cjs";import Jt from"@inquirer/figures";import Ht from"ansi-escapes";import{Separator as Bn}from"@inquirer/core";var qt={icon:{cursor:Jt.pointer},style:{disabled:e=>Ke.dim(`- ${e}`),description:e=>Ke.cyan(e)},helpMode:"auto",indexMode:"hidden"};function q(e){return!ie.isSeparator(e)&&!e.disabled}function Xt(e){return e.map(t=>{if(ie.isSeparator(t))return t;if(typeof t=="string")return{value:t,name:t,short:t,disabled:!1};let r=t.name??String(t.value),n={value:t.value,name:r,short:t.short??r,disabled:t.disabled??!1};return t.description&&(n.description=t.description),n})}var te=Ut((e,t)=>{let{loop:r=!0,pageSize:n=7,instructions:s}=e,o=We(!0),a=Yt(qt,e.theme),[i,l]=Re("idle"),u=Lt({status:i,theme:a}),m=We(),[x,k]=Re(!0),v=Te(()=>Xt(e.choices),[e.choices]),$=Te(()=>{let w=v.findIndex(q),T=v.findLastIndex(q);if(w===-1)throw new Bt("[select prompt] No selectable choices. All choices are disabled.");return{first:w,last:T}},[v]),y=Te(()=>"default"in e?v.findIndex(w=>q(w)&&w.value===e.default):-1,[e.default,v]),[j,W]=Re(y===-1?$.first:y),O=v[j];Dt((w,T)=>{if(clearTimeout(m.current),k(!1),Gt(w))l("done"),t(O.value);else if(Ie(w)||Ge(w)){if(T.clearLine(0),r||Ie(w)&&j!==$.first||Ge(w)&&j!==$.last){let _=Ie(w)?-1:1,I=j;do I=(I+_+v.length)%v.length;while(!q(v[I]));W(I)}}else if(Kt(w)&&!Number.isNaN(Number(T.line))){let _=Number(T.line)-1,I=v[_];I!=null&&q(I)&&W(_),m.current=setTimeout(()=>{T.clearLine(0)},700)}else if(Wt(w))T.clearLine(0);else{let _=T.line.toLowerCase(),I=v.findIndex(ee=>ie.isSeparator(ee)||!q(ee)?!1:ee.name.toLowerCase().startsWith(_));I!==-1&&W(I),m.current=setTimeout(()=>{T.clearLine(0)},700)}}),Vt(()=>()=>{clearTimeout(m.current)},[]);let G=a.style.message(e.message,i),K="",H="";(a.helpMode==="always"||a.helpMode==="auto"&&x&&(s===void 0||s))&&(typeof s=="string"?K=s:K=` (${[`${a.style.key("\u2191\u2193")} to navigate`,`${a.style.key("enter")} to select`,a.indexMode==="number"?`${a.style.key("1-9")} to jump`:"","type to filter"].filter(T=>T!=="").join(", ")})`,v.length>n&&(a.helpMode==="always"||a.helpMode==="auto"&&o.current)&&(H=`
3
- ${a.style.help("(Use arrow keys to reveal more choices)")}`,o.current=!1));let B=zt({items:v,active:j,renderItem({item:w,isActive:T,index:_}){if(ie.isSeparator(w))return` ${w.separator}`;let I=a.indexMode==="number"?`${_+1}. `:"";if(w.disabled){let be=typeof w.disabled=="string"?w.disabled:"(disabled)";return a.style.disabled(`${I}${w.name} ${be}`)}let ee=T?a.style.highlight:be=>be,Mt=T?a.icon.cursor:" ";return ee(`${Mt} ${I}${w.name}`)},pageSize:n,loop:r});if(i==="done")return`${u} ${G} ${a.style.answer(O.short)}`;let _t=O.description?`
4
- ${a.style.description(O.description)}`:"";return`${[u,G,K].filter(Boolean).join(" ")}
5
- ${B}${H}${_t}${Ht.cursorHide}`});import{checkbox as sn,Separator as bt}from"@inquirer/prompts";import gr from"path";var M="1";var Ce="6",Be="7";import R from"path";import{createMatchPath as Zt}from"tsconfig-paths";async function P(e,t){return Zt(t.absoluteBaseUrl,t.paths)(e,void 0,()=>!0,[".ts",".tsx"])}import{cosmiconfig as sr}from"cosmiconfig";import or from"fast-glob";import{loadConfig as ir}from"tsconfig-paths";import{z as g}from"zod";import Je from"path";var A={"next-app":{name:"next-app",label:"Next.js",links:{installation:"https://example.com/docs/installation/next"}},"next-pages":{name:"next-pages",label:"Next.js",links:{installation:"https://example.com/docs/installation/next"}},remix:{name:"remix",label:"Remix",links:{installation:"https://example.com/docs/installation/remix"}},"react-router":{name:"react-router",label:"React Router",links:{installation:"https://example.com/docs/installation/react-router"}},vite:{name:"vite",label:"Vite",links:{installation:"https://example.com/docs/installation/vite"}},astro:{name:"astro",label:"Astro",links:{installation:"https://example.com/docs/installation/astro"}},laravel:{name:"laravel",label:"Laravel",links:{installation:"https://example.com/docs/installation/laravel"}},"tanstack-start":{name:"tanstack-start",label:"TanStack Start",links:{installation:"https://example.com/docs/installation/tanstack"}},gatsby:{name:"gatsby",label:"Gatsby",links:{installation:"https://example.com/docs/installation/gatsby"}},manual:{name:"manual",label:"Manual",links:{installation:"https://example.com/docs/installation/manual"}}};import Qt from"path";import er from"fs-extra";function Ye(e="",t=!0){let r=Qt.join(e,"package.json");return er.readJSONSync(r,{throws:t})}import qe from"fast-glob";import He from"fs-extra";import{loadConfig as tr}from"tsconfig-paths";var Xe=["**/node_modules/**",".next","public","dist","build"];async function b(e){let[t,r,n,s,o]=await Promise.all([qe.glob("**/{next,vite,astro,app}.config.*|gatsby-config.*|composer.json|react-router.config.*",{cwd:e,deep:3,ignore:Xe}),He.pathExists(Je.resolve(e,"src")),nr(e),rr(e),Ye(e,!1)]),a=await He.pathExists(Je.resolve(e,`${r?"src/":""}app`)),i={framework:A.manual,isSrcDir:r,isRSC:!1,isTsx:n,aliasPrefix:s};return t.find(l=>l.startsWith("next.config."))?.length?(i.framework=a?A["next-app"]:A["next-pages"],i.isRSC=a,i):t.find(l=>l.startsWith("astro.config."))?.length?(i.framework=A.astro,i):t.find(l=>l.startsWith("gatsby-config."))?.length?(i.framework=A.gatsby,i):t.find(l=>l.startsWith("composer.json"))?.length?(i.framework=A.laravel,i):Object.keys(o?.dependencies??{}).find(l=>l.startsWith("@remix-run/"))?(i.framework=A.remix,i):t.find(l=>l.startsWith("app.config."))?.length&&[...Object.keys(o?.dependencies??{}),...Object.keys(o?.devDependencies??{})].find(l=>l.startsWith("@tanstack/start"))?(i.framework=A["tanstack-start"],i):t.find(l=>l.startsWith("react-router.config."))?.length?(i.framework=A["react-router"],i):(t.find(l=>l.startsWith("vite.config."))?.length&&(i.framework=A.vite),i)}async function rr(e){let t=await tr(e);if(t?.resultType==="failed"||!Object.entries(t?.paths).length)return null;for(let[r,n]of Object.entries(t.paths))if(n.includes("./*")||n.includes("./src/*")||n.includes("./app/*")||n.includes("./resources/js/*"))return r.replace(/\/\*$/,"")??null;return Object.keys(t?.paths)?.[0].replace(/\/\*$/,"")??null}async function nr(e){return(await qe.glob("tsconfig.*",{cwd:e,deep:1,ignore:Xe})).length>0}async function Ze(e,t=null){let[r,n]=await Promise.all([N(e),t?Promise.resolve(t):b(e)]);if(r)return r;if(!n)return null;let s={rsc:n.isRSC,tsx:n.isTsx,aliases:{components:`${n.aliasPrefix}/components`,contexts:`${n.aliasPrefix}/contexts`,hooks:`${n.aliasPrefix}/hooks`,tiptapIcons:`${n.aliasPrefix}/components/tiptap-icons`,lib:`${n.aliasPrefix}/lib`,tiptapExtensions:`${n.aliasPrefix}/components/tiptap-extensions`,tiptapNodes:`${n.aliasPrefix}/components/tiptap-nodes`,tiptapUi:`${n.aliasPrefix}/components/tiptap-ui`,tiptapUiPrimitives:`${n.aliasPrefix}/components/tiptap-ui-primitives`,styles:`${n.aliasPrefix}/styles`}};return await re(e,s)}var pe="@/components",ce="@/contexts",le="@/hooks",me="@/components/tiptap-icons",ne="@/lib",fe="@/components/tiptap-extension",ue="@/components/tiptap-node",ge="@/components/tiptap-ui",de="@/components/tiptap-ui-primitive",he="@/styles",ar=sr("components",{searchPlaces:["components.json"]}),X=g.object({rsc:g.coerce.boolean().default(!1),tsx:g.coerce.boolean().default(!0),aliases:g.object({components:g.string(),contexts:g.string().optional(),hooks:g.string().optional(),tiptapIcons:g.string().optional(),lib:g.string().optional(),tiptapExtensions:g.string().optional(),tiptapNodes:g.string().optional(),tiptapUi:g.string().optional(),tiptapUiPrimitives:g.string().optional(),styles:g.string().optional()})}),Qe=X.extend({resolvedPaths:g.object({cwd:g.string(),components:g.string(),contexts:g.string(),hooks:g.string(),tiptapIcons:g.string(),lib:g.string(),tiptapExtensions:g.string(),tiptapNodes:g.string(),tiptapUi:g.string(),tiptapUiPrimitives:g.string(),styles:g.string()})}),pr=g.record(Qe);async function N(e){let t=await ar.search(e),r;if(t)r=X.parse(t.config),r.aliases={components:r.aliases.components??pe,contexts:r.aliases.contexts??ce,hooks:r.aliases.hooks??le,tiptapIcons:r.aliases.tiptapIcons??me,lib:r.aliases.lib??ne,tiptapExtensions:r.aliases.tiptapExtensions??fe,tiptapNodes:r.aliases.tiptapNodes??ue,tiptapUi:r.aliases.tiptapUi??ge,tiptapUiPrimitives:r.aliases.tiptapUiPrimitives??de,styles:r.aliases.styles??he};else{let n=await b(e);r=X.parse({rsc:n?.isRSC??!1,tsx:n?.isTsx??!0,aliases:{components:pe,contexts:ce,hooks:le,tiptapIcons:me,lib:ne,tiptapExtensions:fe,tiptapNodes:ue,tiptapUi:ge,tiptapUiPrimitives:de,styles:he}})}return await re(e,r)}async function re(e,t){let r=await ir(e);if(r.resultType==="failed")throw new Error(`Failed to load ${t.tsx?"tsconfig":"jsconfig"}.json. ${r.message??""}`.trim());return Qe.parse({...t,resolvedPaths:{cwd:e,components:await P(t.aliases.components,r),contexts:t.aliases.contexts?await P(t.aliases.contexts,r):R.resolve(await P(t.aliases.components,r)??e,"..","contexts"),hooks:t.aliases.hooks?await P(t.aliases.hooks,r):R.resolve(await P(t.aliases.components,r)??e,"..","hooks"),tiptapIcons:t.aliases.tiptapIcons?await P(t.aliases.tiptapIcons,r):R.resolve(await P(t.aliases.components,r)??e,"tiptap-icons"),lib:t.aliases.lib?await P(t.aliases.lib,r):R.resolve(await P(ne,r)??e,".."),tiptapExtensions:t.aliases.tiptapExtensions?await P(t.aliases.tiptapExtensions,r):R.resolve(await P(t.aliases.components,r)??e,"tiptap-extension"),tiptapNodes:t.aliases.tiptapNodes?await P(t.aliases.tiptapNodes,r):R.resolve(await P(t.aliases.components,r)??e,"tiptap-node"),tiptapUi:t.aliases.tiptapUi?await P(t.aliases.tiptapUi,r):R.resolve(await P(t.aliases.components,r)??e,"tiptap-ui"),tiptapUiPrimitives:t.aliases.tiptapUiPrimitives?await P(t.aliases.tiptapUiPrimitives,r):R.resolve(await P(t.aliases.components,r)??e,"tiptap-ui-primitive"),styles:t.aliases.styles?await P(t.aliases.styles,r):R.resolve(e,"styles")}})}async function et(e){let t={};for(let n of Object.keys(e.aliases)){if(!cr(n,e))continue;let s=e.resolvedPaths[n],o=await Ee(e.resolvedPaths.cwd,s);if(!o){t[n]=e;continue}t[n]=await N(o)}let r=pr.safeParse(t);return r.success?r.data:null}async function Ee(e,t){let r=je(e,t),n=R.relative(r,t),o=(await or.glob("**/package.json",{cwd:r,deep:3,ignore:["**/node_modules/**","**/dist/**","**/build/**","**/public/**"]})).map(a=>R.dirname(a)).find(a=>n.startsWith(a));return o?R.join(r,o):null}function cr(e,t){return Object.keys(t.resolvedPaths).includes(e)}function je(e,t){let r=e.split(R.sep),n=t.split(R.sep),s=[];for(let o=0;o<Math.min(r.length,n.length)&&r[o]===n[o];o++)s.push(r[o]);return s.join(R.sep)}import{cyan as lr,green as mr,red as fr,yellow as ur}from"kleur/colors";var f={error:fr,warn:ur,info:lr,success:mr};var p={error(...e){console.log(f.error(e.join(" ")))},warn(...e){console.log(f.warn(e.join(" ")))},info(...e){console.log(f.info(e.join(" ")))},success(...e){console.log(f.success(e.join(" ")))},log(...e){console.log(e.join(" "))},break(){console.log("")}};import tt from"fs-extra";async function rt(e){let t={};if(!tt.existsSync(e.cwd)||!tt.existsSync(gr.resolve(e.cwd,"package.json")))return t[M]=!0,{errors:t,config:null};try{let r=await N(e.cwd);return{errors:t,config:r}}catch(r){console.log("[preFlightAdd] - ",r),p.break(),p.error(`An invalid ${f.info("components.json")} file was found at ${f.info(e.cwd)}.
6
- Before you can add components, you must create a valid ${f.info("components.json")} file by running the ${f.info("init")} command.`),p.error(`Learn more at ${f.info("link-here")}.`),p.break(),process.exit(0)}}import Z from"path";import{z as dr}from"zod";function S(e){if(p.error("Something went wrong. Please check the error below for more details."),p.error("If the problem persists, please open an issue on GitHub."),p.error(""),typeof e=="string"&&(p.error(e),p.break(),process.exit(0)),e instanceof dr.ZodError){p.error("Validation failed:");for(let[t,r]of Object.entries(e.flatten().fieldErrors))p.error(`- ${f.info(t)}: ${r}`);p.break(),process.exit(0)}e instanceof Error&&(p.error(e.message),p.break(),process.exit(0)),p.break(),process.exit(0)}import{z as d}from"zod";var nt=d.enum(["registry:context","registry:extension","registry:hook","registry:icon","registry:lib","registry:node","registry:template","registry:ui-primitive","registry:ui","registry:page","registry:component","registry:style","registry:asset"]),hr=d.enum(["free","paid"]).default("free"),st=d.object({path:d.string(),content:d.string().optional(),type:nt,target:d.string().optional()}),U=d.object({name:d.string(),type:nt,description:d.string().optional(),dependencies:d.array(d.string()).optional(),devDependencies:d.array(d.string()).optional(),registryDependencies:d.array(d.string()).optional(),files:d.array(st).optional(),meta:d.record(d.string(),d.any()).optional(),plan:hr.optional(),hidden:d.boolean().default(!0)}),$s=d.array(U),ot=d.array(U.extend({files:d.array(d.union([d.string(),st])).optional()})),it=U.pick({dependencies:!0,devDependencies:!0,files:!0});import ye from"fs-extra";import at from"path";import wr from"os";import{execa as xr}from"execa";import Vs from"node-fetch";import{HttpsProxyAgent as vr}from"https-proxy-agent";import yr from"ora";function h(e,t){return yr({text:e,isSilent:t?.silent})}import Ys from"yaml";var kr=process.env.REGISTRY_URL||"https://template.tiptap.dev",Js=`${kr}/api/auth`;var Pr="//registry.tiptap.dev/:_authToken";var Hs=process.env.https_proxy?new vr(process.env.https_proxy):void 0;async function pt(e,t){try{let r=await Sr(t);return r||(e==="npm"?await br(t):await Rr())}catch{return null}}async function Sr(e){let t=at.join(e,".npmrc");if(ye.existsSync(t)){let r=await ye.readFile(t,"utf8");return ct(r)}return null}async function br(e){let{stdout:t}=await xr("npm",["config","get",Pr],{cwd:e});return t&&t!=="undefined"?t.trim():null}async function Rr(){let e=at.join(wr.homedir(),".npmrc");if(ye.existsSync(e)){let t=await ye.readFile(e,"utf8");return ct(t)}return null}function ct(e){let t=e.split(`
7
- `).filter(n=>n.startsWith("//registry.tiptap.dev/:_authToken="));return t.length===0?null:t[0].split("=")[1]?.trim()||null}import{detect as Tr}from"@antfu/ni";async function D(e,{withFallback:t}={withFallback:!1}){let r=await Tr({programmatic:!0,cwd:e});if(r==="deno"&&(r=void 0),r==="yarn@berry")return"yarn";if(r==="pnpm@6")return"pnpm";if(r==="bun")return"bun";if(!t)return r??"npm";let n=process.env.npm_config_user_agent||"";return n.startsWith("yarn")?"yarn":n.startsWith("pnpm")?"pnpm":n.startsWith("bun")?"bun":"npm"}import Oe from"deepmerge";import{HttpsProxyAgent as Ir}from"https-proxy-agent";import lt from"node-fetch";import{z as Cr}from"zod";var se=process.env.REGISTRY_URL||"https://template.tiptap.dev",mt=process.env.https_proxy?new Ir(process.env.https_proxy):void 0;async function Ae(e){try{let[t]=await oe(["index.json"],e);return ot.parse(t)}catch(t){p.error(`
8
- `),S(t)}}async function ft(){try{let e=`${se}/api/registry/free`,t=await lt(e,{agent:mt});if(!t.ok)throw new Error(`Failed to fetch from ${f.info(e)}.
2
+ import Qr from"path";import{Command as es}from"commander";import{z as Y}from"zod";import{createPrompt as Mt,useState as Re,useKeypress as Dt,usePrefix as Lt,usePagination as zt,useRef as Ve,useMemo as Te,useEffect as Wt,isBackspaceKey as Vt,isEnterKey as Kt,isUpKey as Ie,isDownKey as Ke,isNumberKey as Gt,Separator as ne,ValidationError as Bt,makeTheme as Yt}from"@inquirer/core";import Ge from"yoctocolors-cjs";import Jt from"@inquirer/figures";import Ht from"ansi-escapes";import{Separator as Ks}from"@inquirer/core";var qt={icon:{cursor:Jt.pointer},style:{disabled:e=>Ge.dim(`- ${e}`),description:e=>Ge.cyan(e)},helpMode:"auto",indexMode:"hidden"};function J(e){return!ne.isSeparator(e)&&!e.disabled}function Xt(e){return e.map(t=>{if(ne.isSeparator(t))return t;if(typeof t=="string")return{value:t,name:t,short:t,disabled:!1};let r=t.name??String(t.value),s={value:t.value,name:r,short:t.short??r,disabled:t.disabled??!1};return t.description&&(s.description=t.description),s})}var oe=Mt((e,t)=>{let{loop:r=!0,pageSize:s=7,instructions:n}=e,i=Ve(!0),a=Yt(qt,e.theme),[o,m]=Re("idle"),u=Lt({status:o,theme:a}),d=Ve(),[h,l]=Re(!0),x=Te(()=>Xt(e.choices),[e.choices]),$=Te(()=>{let w=x.findIndex(J),R=x.findLastIndex(J);if(w===-1)throw new Bt("[select prompt] No selectable choices. All choices are disabled.");return{first:w,last:R}},[x]),v=Te(()=>"default"in e?x.findIndex(w=>J(w)&&w.value===e.default):-1,[e.default,x]),[K,Z]=Re(v===-1?$.first:v),j=x[K];Dt((w,R)=>{if(clearTimeout(d.current),l(!1),Kt(w))m("done"),t(j.value);else if(Ie(w)||Ke(w)){if(R.clearLine(0),r||Ie(w)&&K!==$.first||Ke(w)&&K!==$.last){let _=Ie(w)?-1:1,T=K;do T=(T+_+x.length)%x.length;while(!J(x[T]));Z(T)}}else if(Gt(w)&&!Number.isNaN(Number(R.line))){let _=Number(R.line)-1,T=x[_];T!=null&&J(T)&&Z(_),d.current=setTimeout(()=>{R.clearLine(0)},700)}else if(Vt(w))R.clearLine(0);else{let _=R.line.toLowerCase(),T=x.findIndex(Q=>ne.isSeparator(Q)||!J(Q)?!1:Q.name.toLowerCase().startsWith(_));T!==-1&&Z(T),d.current=setTimeout(()=>{R.clearLine(0)},700)}}),Wt(()=>()=>{clearTimeout(d.current)},[]);let G=a.style.message(e.message,o),B="",A="";(a.helpMode==="always"||a.helpMode==="auto"&&h&&(n===void 0||n))&&(typeof n=="string"?B=n:B=` (${[`${a.style.key("\u2191\u2193")} to navigate`,`${a.style.key("enter")} to select`,a.indexMode==="number"?`${a.style.key("1-9")} to jump`:"","type to filter"].filter(R=>R!=="").join(", ")})`,x.length>s&&(a.helpMode==="always"||a.helpMode==="auto"&&i.current)&&(A=`
3
+ ${a.style.help("(Use arrow keys to reveal more choices)")}`,i.current=!1));let F=zt({items:x,active:K,renderItem({item:w,isActive:R,index:_}){if(ne.isSeparator(w))return` ${w.separator}`;let T=a.indexMode==="number"?`${_+1}. `:"";if(w.disabled){let Se=typeof w.disabled=="string"?w.disabled:"(disabled)";return a.style.disabled(`${T}${w.name} ${Se}`)}let Q=R?a.style.highlight:Se=>Se,_t=R?a.icon.cursor:" ";return Q(`${_t} ${T}${w.name}`)},pageSize:s,loop:r});if(o==="done")return`${u} ${G} ${a.style.answer(j.short)}`;let ve=j.description?`
4
+ ${a.style.description(j.description)}`:"";return`${[u,G,B].filter(Boolean).join(" ")}
5
+ ${F}${A}${ve}${Ht.cursorHide}`});import{checkbox as Rt,Separator as St}from"@inquirer/prompts";import lr from"path";var M="1";var Ce="6",Be="7";import S from"path";import{createMatchPath as Zt}from"tsconfig-paths";async function k(e,t){return Zt(t.absoluteBaseUrl,t.paths)(e,void 0,()=>!0,[".ts",".tsx"])}import{cosmiconfig as nr}from"cosmiconfig";import or from"fast-glob";import{loadConfig as ir}from"tsconfig-paths";import{z as f}from"zod";import Je from"path";var b={"next-app":{name:"next-app",label:"Next.js",links:{installation:"https://example.com/docs/installation/next"}},"next-pages":{name:"next-pages",label:"Next.js",links:{installation:"https://example.com/docs/installation/next"}},remix:{name:"remix",label:"Remix",links:{installation:"https://example.com/docs/installation/remix"}},"react-router":{name:"react-router",label:"React Router",links:{installation:"https://example.com/docs/installation/react-router"}},vite:{name:"vite",label:"Vite",links:{installation:"https://example.com/docs/installation/vite"}},astro:{name:"astro",label:"Astro",links:{installation:"https://example.com/docs/installation/astro"}},laravel:{name:"laravel",label:"Laravel",links:{installation:"https://example.com/docs/installation/laravel"}},"tanstack-start":{name:"tanstack-start",label:"TanStack Start",links:{installation:"https://example.com/docs/installation/tanstack"}},gatsby:{name:"gatsby",label:"Gatsby",links:{installation:"https://example.com/docs/installation/gatsby"}},manual:{name:"manual",label:"Manual",links:{installation:"https://example.com/docs/installation/manual"}}};import Qt from"path";import er from"fs-extra";function Ye(e="",t=!0){let r=Qt.join(e,"package.json");return er.readJSONSync(r,{throws:t})}import qe from"fast-glob";import He from"fs-extra";import{loadConfig as tr}from"tsconfig-paths";var Xe=["**/node_modules/**",".next","public","dist","build"];async function I(e){let[t,r,s,n,i]=await Promise.all([qe.glob("**/{next,vite,astro,app}.config.*|gatsby-config.*|composer.json|react-router.config.*",{cwd:e,deep:3,ignore:Xe}),He.pathExists(Je.resolve(e,"src")),sr(e),rr(e),Ye(e,!1)]),a=await He.pathExists(Je.resolve(e,`${r?"src/":""}app`)),o={framework:b.manual,isSrcDir:r,isRSC:!1,isTsx:s,aliasPrefix:n};return t.find(m=>m.startsWith("next.config."))?.length?(o.framework=a?b["next-app"]:b["next-pages"],o.isRSC=a,o):t.find(m=>m.startsWith("astro.config."))?.length?(o.framework=b.astro,o):t.find(m=>m.startsWith("gatsby-config."))?.length?(o.framework=b.gatsby,o):t.find(m=>m.startsWith("composer.json"))?.length?(o.framework=b.laravel,o):Object.keys(i?.dependencies??{}).find(m=>m.startsWith("@remix-run/"))?(o.framework=b.remix,o):t.find(m=>m.startsWith("app.config."))?.length&&[...Object.keys(i?.dependencies??{}),...Object.keys(i?.devDependencies??{})].find(m=>m.startsWith("@tanstack/start"))?(o.framework=b["tanstack-start"],o):t.find(m=>m.startsWith("react-router.config."))?.length?(o.framework=b["react-router"],o):(t.find(m=>m.startsWith("vite.config."))?.length&&(o.framework=b.vite),o)}async function rr(e){let t=await tr(e);if(t?.resultType==="failed"||!Object.entries(t?.paths).length)return null;for(let[r,s]of Object.entries(t.paths))if(s.includes("./*")||s.includes("./src/*")||s.includes("./app/*")||s.includes("./resources/js/*"))return r.replace(/\/\*$/,"")??null;return Object.keys(t?.paths)?.[0].replace(/\/\*$/,"")??null}async function sr(e){return(await qe.glob("tsconfig.*",{cwd:e,deep:1,ignore:Xe})).length>0}async function Ze(e,t=null){let[r,s]=await Promise.all([O(e),t?Promise.resolve(t):I(e)]);if(r)return r;if(!s)return null;let n={rsc:s.isRSC,tsx:s.isTsx,aliases:{components:`${s.aliasPrefix}/components`,contexts:`${s.aliasPrefix}/contexts`,hooks:`${s.aliasPrefix}/hooks`,tiptapIcons:`${s.aliasPrefix}/components/tiptap-icons`,lib:`${s.aliasPrefix}/lib`,tiptapExtensions:`${s.aliasPrefix}/components/tiptap-extensions`,tiptapNodes:`${s.aliasPrefix}/components/tiptap-nodes`,tiptapUi:`${s.aliasPrefix}/components/tiptap-ui`,tiptapUiPrimitives:`${s.aliasPrefix}/components/tiptap-ui-primitives`,tiptapUiUtils:`${s.aliasPrefix}/components/tiptap-ui-utils`,styles:`${s.aliasPrefix}/styles`}};return await ee(e,n)}var ae="@/components",pe="@/contexts",ce="@/hooks",le="@/components/tiptap-icons",te="@/lib",me="@/components/tiptap-extension",fe="@/components/tiptap-node",ue="@/components/tiptap-ui",de="@/components/tiptap-ui-primitive",ge="@/components/tiptap-ui-utils",ye="@/styles",ar=nr("components",{searchPlaces:["components.json"]}),H=f.object({rsc:f.coerce.boolean().default(!1),tsx:f.coerce.boolean().default(!0),aliases:f.object({components:f.string(),contexts:f.string().optional(),hooks:f.string().optional(),tiptapIcons:f.string().optional(),lib:f.string().optional(),tiptapExtensions:f.string().optional(),tiptapNodes:f.string().optional(),tiptapUi:f.string().optional(),tiptapUiPrimitives:f.string().optional(),tiptapUiUtils:f.string().optional(),styles:f.string().optional()})}),Qe=H.extend({resolvedPaths:f.object({cwd:f.string(),components:f.string(),contexts:f.string(),hooks:f.string(),tiptapIcons:f.string(),lib:f.string(),tiptapExtensions:f.string(),tiptapNodes:f.string(),tiptapUi:f.string(),tiptapUiPrimitives:f.string(),tiptapUiUtils:f.string(),styles:f.string()})}),pr=f.record(Qe);async function O(e){let t=await ar.search(e),r;if(t)r=H.parse(t.config),r.aliases={components:r.aliases.components??ae,contexts:r.aliases.contexts??pe,hooks:r.aliases.hooks??ce,tiptapIcons:r.aliases.tiptapIcons??le,lib:r.aliases.lib??te,tiptapExtensions:r.aliases.tiptapExtensions??me,tiptapNodes:r.aliases.tiptapNodes??fe,tiptapUi:r.aliases.tiptapUi??ue,tiptapUiPrimitives:r.aliases.tiptapUiPrimitives??de,tiptapUiUtils:r.aliases.tiptapUiUtils??ge,styles:r.aliases.styles??ye};else{let s=await I(e);r=H.parse({rsc:s?.isRSC??!1,tsx:s?.isTsx??!0,aliases:{components:ae,contexts:pe,hooks:ce,tiptapIcons:le,lib:te,tiptapExtensions:me,tiptapNodes:fe,tiptapUi:ue,tiptapUiPrimitives:de,tiptapUiUtils:ge,styles:ye}})}return await ee(e,r)}async function ee(e,t){let r=await ir(e);if(r.resultType==="failed")throw new Error(`Failed to load ${t.tsx?"tsconfig":"jsconfig"}.json. ${r.message??""}`.trim());return Qe.parse({...t,resolvedPaths:{cwd:e,components:await k(t.aliases.components,r),contexts:t.aliases.contexts?await k(t.aliases.contexts,r):S.resolve(await k(t.aliases.components,r)??e,"..","contexts"),hooks:t.aliases.hooks?await k(t.aliases.hooks,r):S.resolve(await k(t.aliases.components,r)??e,"..","hooks"),tiptapIcons:t.aliases.tiptapIcons?await k(t.aliases.tiptapIcons,r):S.resolve(await k(t.aliases.components,r)??e,"tiptap-icons"),lib:t.aliases.lib?await k(t.aliases.lib,r):S.resolve(await k(te,r)??e,".."),tiptapExtensions:t.aliases.tiptapExtensions?await k(t.aliases.tiptapExtensions,r):S.resolve(await k(t.aliases.components,r)??e,"tiptap-extension"),tiptapNodes:t.aliases.tiptapNodes?await k(t.aliases.tiptapNodes,r):S.resolve(await k(t.aliases.components,r)??e,"tiptap-node"),tiptapUi:t.aliases.tiptapUi?await k(t.aliases.tiptapUi,r):S.resolve(await k(t.aliases.components,r)??e,"tiptap-ui"),tiptapUiPrimitives:t.aliases.tiptapUiPrimitives?await k(t.aliases.tiptapUiPrimitives,r):S.resolve(await k(t.aliases.components,r)??e,"tiptap-ui-primitive"),tiptapUiUtils:t.aliases.tiptapUiUtils?await k(t.aliases.tiptapUiUtils,r):S.resolve(await k(t.aliases.components,r)??e,"tiptap-ui-utils"),styles:t.aliases.styles?await k(t.aliases.styles,r):S.resolve(e,"styles")}})}async function et(e){let t={};for(let s of Object.keys(e.aliases)){if(!cr(s,e))continue;let n=e.resolvedPaths[s],i=await Ee(e.resolvedPaths.cwd,n);if(!i){t[s]=e;continue}t[s]=await O(i)}let r=pr.safeParse(t);return r.success?r.data:null}async function Ee(e,t){let r=je(e,t),s=S.relative(r,t),i=(await or.glob("**/package.json",{cwd:r,deep:3,ignore:["**/node_modules/**","**/dist/**","**/build/**","**/public/**"]})).map(a=>S.dirname(a)).find(a=>s.startsWith(a));return i?S.join(r,i):null}function cr(e,t){return Object.keys(t.resolvedPaths).includes(e)}function je(e,t){let r=e.split(S.sep),s=t.split(S.sep),n=[];for(let i=0;i<Math.min(r.length,s.length)&&r[i]===s[i];i++)n.push(r[i]);return n.join(S.sep)}import D from"chalk";var c={cyan:D.cyan,magenta:D.magenta,gray:D.gray,white:D.white,yellow:D.yellow,green:D.green,red:D.red,blue:D.blue};var p={error(...e){console.log(c.red(e.join(" ")))},warn(...e){console.log(c.yellow(e.join(" ")))},info(...e){console.log(c.blue(e.join(" ")))},success(...e){console.log(c.green(e.join(" ")))},log(...e){console.log(e.join(" "))},break(){console.log("")}};import tt from"fs-extra";async function rt(e){let t={};if(!tt.existsSync(e.cwd)||!tt.existsSync(lr.resolve(e.cwd,"package.json")))return t[M]=!0,{errors:t,config:null};try{let r=await O(e.cwd);return{errors:t,config:r}}catch(r){console.log("[preFlightAdd] - ",r),p.break(),p.error(`Make sure you are in a valid project directory. Run ${c.cyan("npx @tiptap/cli init")} to create a new project.`),p.break(),process.exit(0)}}import q from"path";import{z as mr}from"zod";function P(e){if(p.error("Something went wrong. Please check the error below for more details."),p.error("If the problem persists, please open an issue on GitHub."),p.error(""),typeof e=="string"&&(p.error(e),p.break(),process.exit(0)),e instanceof mr.ZodError){p.error("Validation failed:");for(let[t,r]of Object.entries(e.flatten().fieldErrors))p.error(`- ${c.blue(t)}: ${r}`);p.break(),process.exit(0)}e instanceof Error&&(p.error(e.message),p.break(),process.exit(0)),p.break(),process.exit(0)}import{z as y}from"zod";var st=y.enum(["registry:context","registry:extension","registry:hook","registry:icon","registry:lib","registry:node","registry:template","registry:ui-primitive","registry:ui","registry:ui-utils","registry:page","registry:component","registry:style","registry:asset"]),fr=y.enum(["free","paid"]).default("free"),nt=y.object({path:y.string(),content:y.string().optional(),type:st,target:y.string().optional()}),L=y.object({name:y.string(),type:st,description:y.string().optional(),dependencies:y.array(y.string()).optional(),devDependencies:y.array(y.string()).optional(),registryDependencies:y.array(y.string()).optional(),files:y.array(nt).optional(),meta:y.record(y.string(),y.any()).optional(),plan:fr.optional(),hidden:y.boolean().default(!0)}),On=y.array(L),ot=y.array(L.extend({files:y.array(y.union([y.string(),nt])).optional()})),it=L.pick({dependencies:!0,devDependencies:!0,files:!0});import he from"fs-extra";import at from"path";import gr from"os";import{execa as yr}from"execa";import Wn from"node-fetch";import{HttpsProxyAgent as hr}from"https-proxy-agent";import ur from"chalk";import dr from"ora";function g(e,t){return dr({text:ur.bold(e),isSilent:t?.silent})}import Yn from"yaml";import qn from"chalk";var wr=process.env.REGISTRY_URL||"https://template.tiptap.dev",Xn=`${wr}/api/auth`;var xr="//registry.tiptap.dev/:_authToken";var Zn=process.env.https_proxy?new hr(process.env.https_proxy):void 0;async function pt(e,t){try{let r=await kr(t);return r||(e==="npm"?await br(t):await Pr())}catch{return null}}async function kr(e){let t=at.join(e,".npmrc");if(he.existsSync(t)){let r=await he.readFile(t,"utf8");return ct(r)}return null}async function br(e){let{stdout:t}=await yr("npm",["config","get",xr],{cwd:e});return t&&t!=="undefined"?t.trim():null}async function Pr(){let e=at.join(gr.homedir(),".npmrc");if(he.existsSync(e)){let t=await he.readFile(e,"utf8");return ct(t)}return null}function ct(e){let t=e.split(`
6
+ `).filter(s=>s.startsWith("//registry.tiptap.dev/:_authToken="));return t.length===0?null:t[0].split("=")[1]?.trim()||null}import{detect as vr}from"@antfu/ni";async function z(e,{withFallback:t}={withFallback:!1}){let r=await vr({programmatic:!0,cwd:e});if(r==="deno"&&(r=void 0),r==="yarn@berry")return"yarn";if(r==="pnpm@6")return"pnpm";if(r==="bun")return"bun";if(!t)return r??"npm";let s=process.env.npm_config_user_agent||"";return s.startsWith("yarn")?"yarn":s.startsWith("pnpm")?"pnpm":s.startsWith("bun")?"bun":"npm"}import Ae from"deepmerge";import{HttpsProxyAgent as Sr}from"https-proxy-agent";import lt from"node-fetch";import{z as Rr}from"zod";var re=process.env.REGISTRY_URL||"https://template.tiptap.dev",mt=process.env.https_proxy?new Sr(process.env.https_proxy):void 0;async function Oe(e){try{let[t]=await se(["index.json"],e);return ot.parse(t)}catch(t){p.error(`
7
+ `),P(t)}}async function ft(){try{let e=`${re}/api/registry/free`,t=await lt(e,{agent:mt});if(!t.ok)throw new Error(`Failed to fetch from ${c.blue(e)}.
9
8
  ${t.statusText}`);return await t.json()}catch(e){p.error(`
10
- `),S(e)}}async function oe(e,t){try{let r=null;if(t){let s=await D(t.resolvedPaths.cwd);r=await pt(s,t.resolvedPaths.cwd)}return await Promise.all(e.map(async s=>{let o=gt(s),a={};r&&(a.Authorization=`Bearer ${r}`);let i=await lt(o,{agent:mt,headers:a});if(!i.ok){let l={400:"Bad request",401:"Unauthorized",403:"Forbidden",404:"Not found",500:"Internal server error"};if(i.status===401)throw new Error(`You are not authorized to access the component at ${f.info(o)}.
11
- Please run 'tiptap auth login' to authenticate with the registry, or make sure your token is valid.`);if(i.status===404)throw new Error(`The component at ${f.info(o)} was not found.
12
- It may not exist at the registry. Please make sure it is a valid component.`);if(i.status===403)throw new Error(`You do not have access to the component at ${f.info(o)}.
9
+ `),P(e)}}async function se(e,t){try{let r=null;if(t){let n=await z(t.resolvedPaths.cwd);r=await pt(n,t.resolvedPaths.cwd)}return await Promise.all(e.map(async n=>{let i=dt(n),a={};r&&(a.Authorization=`Bearer ${r}`);let o=await lt(i,{agent:mt,headers:a});if(!o.ok){let m={400:"Bad request",401:"Unauthorized",403:"Forbidden",404:"Not found",500:"Internal server error"};if(o.status===401)throw new Error(`You are not authorized to access the component at ${c.blue(i)}.
10
+ Please run 'tiptap auth login' to authenticate with the registry, or make sure your token is valid.`);if(o.status===404)throw new Error(`The component at ${c.blue(i)} was not found.
11
+ It may not exist at the registry. Please make sure it is a valid component.`);if(o.status===403)throw new Error(`You do not have access to the component at ${c.blue(i)}.
13
12
  Your account may not have the required subscription plan for this component.
14
- Please upgrade your subscription or use a component available in your current plan.`);let u=await i.json(),m=u&&typeof u=="object"&&"error"in u?u.error:i.statusText||l[i.status];throw new Error(`Failed to fetch from ${f.info(o)}.
15
- ${m}`)}return i.json()}))}catch(r){return p.error(`
16
- `),S(r),[]}}async function ut(e,t){try{if(!await Ae(t))return null;e.includes("index")&&e.unshift("index");let n=await $e(e,t),s=await oe(n,t),o=Cr.array(U).parse(s);if(!o)return null;let i=(await b(t.resolvedPaths.cwd))?.framework.name,l=Oe.all(o.map(x=>x.dependencies??[])),u=Oe.all(o.map(x=>x.devDependencies??[])),m=jr(u,i);return it.parse({dependencies:l,devDependencies:m,files:Oe.all(o.map(x=>x.files??[]))})}catch(r){return S(r),null}}async function Er(e,t){let r=new Set,n=[];async function s(o){let a=gt(dt(o)?o:`components/${o}.json`);if(!r.has(a)){r.add(a);try{let[i]=await oe([a],t),l=U.parse(i);if(n.push(a),l.registryDependencies)for(let u of l.registryDependencies)await s(u)}catch(i){console.error(`Error fetching or parsing registry item at ${o}:`,i)}}}return await s(e),Array.from(new Set(n))}async function $e(e,t){let r=[];for(let n of e){let s=await Er(n,t);r.push(...s)}return Array.from(new Set(r))}function gt(e){if(dt(e))return new URL(e).toString();if(!se)throw new Error("No registry URL found");if(e==="index.json")return`${se}/r/${e}`;if(e.startsWith("components/")){let t=e.replace("components/","").replace(".json","");return`${se}/api/registry/components/${t}`}return`${se}/${e}`}function dt(e){try{return new URL(e),!0}catch{return!1}}function ht(){return new Map([["registry:ui","tiptapUi"],["registry:ui-primitive","tiptapUiPrimitives"],["registry:extension","tiptapExtensions"],["registry:node","tiptapNodes"],["registry:context","contexts"],["registry:hook","hooks"],["registry:lib","lib"],["registry:context","components"],["registry:template","tiptapTemplates"],["registry:component","components"],["registry:icon","titpapIcons"],["registry:style","styles"]])}function yt(e){let t=new Map;return e.forEach(r=>{r.registryDependencies&&r.registryDependencies.forEach(n=>{t.set(n,r)})}),t}function jr(e,t){let r=Array.isArray(e)?e:[];if(!r.length)return[];let n=r.map(a=>String(a)),s=n.includes("sass"),o=n.includes("sass-embedded");if(s&&o){let a=[...n];return t&&(t==="vite"?a=a.filter(i=>i!=="sass"):(t==="next-app"||t==="next-pages")&&(a=a.filter(i=>i!=="sass-embedded"))),a}return n}import{execa as Or}from"execa";import Y from"chalk";var c={cyan:Y.hex("#46caff"),gray:Y.gray,magenta:Y.hex("#f64d90"),white:Y.white,yellow:Y.yellow,green:Y.green,red:Y.red};async function Ne(e,t,r){if(e=Array.from(new Set(e)),!e?.length)return;r={silent:!1,...r};let n=h("Installing dependencies.",{silent:r.silent}).start(),s=await D(t.resolvedPaths.cwd);await Or(s,[s==="npm"?"install":"add",...s==="npm"?["--save"]:[],...e],{cwd:t.resolvedPaths.cwd}),n.stopAndPersist({symbol:c.cyan("\u2714")})}import{existsSync as kt,promises as Fe}from"fs";import E,{basename as Kr}from"path";import{promises as Dr}from"fs";import{tmpdir as Lr}from"os";import xt from"path";var we=async({sourceFile:e,config:t})=>{let r=e.getImportDeclarations();for(let n of r){let s=Ar(n.getModuleSpecifierValue(),t);s&&n.setModuleSpecifier(s)}return e};function Ar(e,t){if(!e.startsWith("@/registry/")){let r=t.aliases.components.split("/")[0];return e.replace(/^@\//,`${r}/`)}return e.match(/@\/registry\/tiptap-templates\/([^/]+)\/components\//)?e.replace(/@\/registry\/tiptap-templates\/([^/]+)\/components\//,`${t.aliases.components}/tiptap-templates/$1/`):e.match(/@\/registry\/tiptap-templates\/([^/]+)\/(?!components\/)/)?e.replace(/@\/registry\/tiptap-templates\/([^/]+)\//,`${t.aliases.components}/tiptap-templates/$1/`):t.aliases.components&&e.match(/@\/registry\/components/)?e.replace(/@\/registry\/components/,t.aliases.components):t.aliases.contexts&&e.match(/@\/registry\/contexts/)?e.replace(/@\/registry\/contexts/,t.aliases.contexts):t.aliases.tiptapExtensions&&e.match(/@\/registry\/tiptap-extension/)?e.replace(/@\/registry\/tiptap-extension/,t.aliases.tiptapExtensions):t.aliases.hooks&&e.match(/@\/registry\/hooks/)?e.replace(/@\/registry\/hooks/,t.aliases.hooks):t.aliases.tiptapIcons&&e.match(/@\/registry\/tiptap-icons/)?e.replace(/@\/registry\/tiptap-icons/,t.aliases.tiptapIcons):t.aliases.lib&&e.match(/@\/registry\/lib/)?e.replace(/@\/registry\/lib/,t.aliases.lib):t.aliases.tiptapNodes&&e.match(/@\/registry\/tiptap-node/)?e.replace(/@\/registry\/tiptap-node/,t.aliases.tiptapNodes):t.aliases.tiptapUiPrimitives&&e.match(/@\/registry\/tiptap-ui-primitive/)?e.replace(/@\/registry\/tiptap-ui-primitive/,t.aliases.tiptapUiPrimitives):t.aliases.tiptapUi&&e.match(/@\/registry\/tiptap-ui/)?e.replace(/@\/registry\/tiptap-ui/,t.aliases.tiptapUi):t.aliases.styles&&e.match(/@\/registry\/styles/)?e.replace(/@\/registry\/styles/,t.aliases.styles):e.replace(/^@\/registry\/[^/]+(?:\/.*\/)?/,t.aliases.components+"/")}import{transformFromAstSync as $r}from"@babel/core";import{parse as Nr}from"@babel/parser";import Fr from"@babel/plugin-transform-typescript";import*as xe from"recast";var _r={sourceType:"module",allowImportExportEverywhere:!0,allowReturnOutsideFunction:!0,startLine:1,tokens:!0,plugins:["asyncGenerators","bigInt","classPrivateMethods","classPrivateProperties","classProperties","classStaticBlock","decimal","decorators-legacy","doExpressions","dynamicImport","exportDefaultFrom","exportNamespaceFrom","functionBind","functionSent","importAssertions","importMeta","nullishCoalescingOperator","numericSeparator","objectRestSpread","optionalCatchBinding","optionalChaining",["pipelineOperator",{proposal:"minimal"}],["recordAndTuple",{syntaxType:"hash"}],"throwExpressions","topLevelAwait","v8intrinsic","typescript","jsx"]},wt=async({sourceFile:e,config:t})=>{let r=e.getFullText();if(t.tsx)return r;let n=xe.parse(r,{parser:{parse:o=>Nr(o,_r)}}),s=$r(n,r,{cloneInputAst:!1,code:!1,ast:!0,plugins:[Fr],configFile:!1});if(!s||!s.ast)throw new Error("Failed to transform JSX");return xe.print(s.ast).code};import{SyntaxKind as Mr}from"ts-morph";var Ur=/^["']use client["']$/g,ve=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let r=e.getFirstChildByKind(Mr.ExpressionStatement);return r&&Ur.test(r.getText())&&r.remove(),e};var ke=async({sourceFile:e,config:t})=>{if((await b(t.resolvedPaths.cwd))?.framework.name==="vite"){let n=e.getFullText();n=n.replace(/process\.env\.NEXT_PUBLIC_([A-Za-z0-9_]+)/g,"import.meta.env.VITE_$1"),n=n.replace(/process\.env\.([A-Za-z0-9_]+)/g,"import.meta.env.$1"),e.replaceWithText(n)}return e};import{Project as zr,ScriptKind as Vr}from"ts-morph";var Wr=new zr({compilerOptions:{}});async function Gr(e){let t=await Dr.mkdtemp(xt.join(Lr(),"tiptap-"));return xt.join(t,e)}async function vt(e,t=[we,ve,ke]){let r=await Gr(e.filename),n=Wr.createSourceFile(r,e.raw,{scriptKind:Vr.TSX});for(let s of t)await s({sourceFile:n,...e});return e.transformJsx?await wt({sourceFile:n,...e}):n.getText()}import{confirm as Br}from"@inquirer/prompts";import _e from"chalk";async function Me(e,t,r){if(!e?.length)return{filesCreated:[],filesUpdated:[],filesSkipped:[]};r={overwrite:!1,force:!1,silent:!1,...r};let n=h("Updating files.",{silent:r.silent})?.start(),[s]=await Promise.all([b(t.resolvedPaths.cwd)]),o=[],a=[],i=[];for(let u of e){if(!u.content)continue;let m=Xr(u,t,{isSrcDir:s?.isSrcDir,framework:s?.framework.name,commonRoot:Jr(e.map(y=>y.path),u.path)});if(!m)continue;let x=Kr(u.path),k=E.dirname(m);t.tsx||(m=m.replace(/\.tsx?$/,y=>y===".tsx"?".jsx":".js"));let v=kt(m),$=await vt({filename:u.path,raw:u.content,config:t,transformJsx:!t.tsx},[we,ve,ke]);if(v){let y=await Fe.readFile(m,"utf-8"),[j,W]=await Promise.all([Pt(y),Pt($)]);if(j===W){i.push(E.relative(t.resolvedPaths.cwd,m));continue}}if(v&&!r.overwrite){if(n.stop(),r.rootSpinner&&r.rootSpinner.stop(),!await Br({message:_e.white(`The file ${f.info(x)} already exists. Would you like to overwrite?`),theme:{prefix:_e.hex("#46caff")("?"),style:{answer:j=>_e.white(j)}}})){i.push(E.relative(t.resolvedPaths.cwd,m)),r.rootSpinner&&r.rootSpinner.start();continue}n?.start(),r.rootSpinner&&r.rootSpinner.start()}kt(k)||await Fe.mkdir(k,{recursive:!0}),await Fe.writeFile(m,$,"utf-8"),v?a.push(E.relative(t.resolvedPaths.cwd,m)):o.push(E.relative(t.resolvedPaths.cwd,m))}if(!(o.length||a.length)&&!i.length&&n?.info("No files updated."),o.length){if(n?.succeed(`Created ${o.length} ${o.length===1?"file":"files"}:`),!r.silent)for(let u of o)p.log(` - ${u}`)}else n?.stop();if(a.length&&(h(`Updated ${a.length} ${a.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let u of a)p.log(` - ${u}`);if(i.length&&(h(`Skipped ${i.length} ${a.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:r.silent})?.info(),!r.silent))for(let u of i)p.log(` - ${u}`);return r.silent||p.break(),{filesCreated:o,filesUpdated:a,filesSkipped:i}}function Yr(e,t,r){return r||(e.type==="registry:ui"?t.resolvedPaths.tiptapUi:e.type==="registry:ui-primitive"?t.resolvedPaths.tiptapUiPrimitives:e.type==="registry:extension"?t.resolvedPaths.tiptapExtensions:e.type==="registry:node"?t.resolvedPaths.tiptapNodes:e.type==="registry:icon"?t.resolvedPaths.tiptapIcons:e.type==="registry:hook"?t.resolvedPaths.hooks:e.type==="registry:lib"?t.resolvedPaths.lib:e.type==="registry:context"?t.resolvedPaths.contexts:e.type==="registry:template"||e.type==="registry:component"?t.resolvedPaths.components:e.type==="registry:style"?t.resolvedPaths.styles:t.resolvedPaths.components)}function Jr(e,t){let r=e.map(a=>a.replace(/^\//,"")),n=t.replace(/^\//,""),s=n.split("/").slice(0,-1).join("/");if(!s)return"";let o=s.split("/");for(let a=o.length;a>0;a--){let i=o.slice(0,a).join("/");if(r.some(u=>u!==n&&u.startsWith(i+"/")))return"/"+i}return"/"+s}async function Pt(e){return e.replace(/\r\n/g,`
17
- `).trim()}function Hr(e,t){if(!t)return"";if(t==="next-app")return e;if(t==="next-pages"){let r=e.replace(/^app\//,"pages/");return r=r.replace(/\/page(\.[jt]sx?)$/,"$1"),r}if(t==="react-router"){let r=e.replace(/^app\//,"app/routes/");return r=r.replace(/\/page(\.[jt]sx?)$/,"$1"),r}if(t==="laravel"){let r=e.replace(/^app\//,"resources/js/pages/");return r=r.replace(/\/page(\.[jt]sx?)$/,"$1"),r}return""}function qr(e,t){let r=e.replace(/^\/|\/$/g,""),n=t.replace(/^\/|\/$/g,""),s=r.split("/"),o=n.split("/"),a=o[o.length-1],i=s.findIndex(l=>l===a);return i===-1?s[s.length-1]:s.slice(i+1).join("/")}function Xr(e,t,r){if(!e.target&&e.path.includes("tiptap-templates/")&&e.type!=="registry:page"){let o=e.path.match(/tiptap-templates\/([^/]+)\/(.*)/);if(o){let[,a,i]=o;if(i.startsWith("components/")){let l=i.replace("components/","");return E.join(t.resolvedPaths.components,"tiptap-templates",a,l)}return E.join(t.resolvedPaths.components,"tiptap-templates",a,i)}}if(e.target&&e.path.includes("tiptap-templates/")&&e.target.includes("/data/")){let o=e.path.match(/tiptap-templates\/([^/]+)\//);if(o){let a=o[1],i=e.target.split("/data/")[1];return E.join(t.resolvedPaths.components,"tiptap-templates",a,"data",i)}}if(e.target){if(e.target.startsWith("~/"))return E.join(t.resolvedPaths.cwd,e.target.replace("~/",""));let o=e.target;return e.type==="registry:page"&&(o=Hr(o,r.framework),!o)?"":r.isSrcDir?E.join(t.resolvedPaths.cwd,"src",o.replace("src/","")):E.join(t.resolvedPaths.cwd,o.replace("src/",""))}let n=Yr(e,t),s=qr(e.path,n);return E.join(n,s)}import{z as Qr}from"zod";import{execa as Zr}from"execa";async function St(e,t,r){if(e=Array.from(new Set(e)),!e?.length)return;r={silent:!1,...r};let n=h("Installing development dependencies.",{silent:r.silent})?.start(),s=await D(t.resolvedPaths.cwd);n?.start(),await Zr(s,[s==="npm"?"install":"add",s==="npm"?"--save-dev":"-D",...e],{cwd:t.resolvedPaths.cwd}),n?.stopAndPersist({symbol:c.cyan("\u2714")})}async function Pe(e,t,r){r={overwrite:!1,silent:!1,isNewProject:!1,...r};let n=await et(t);return n&&n.tiptapUi&&n.tiptapUi.resolvedPaths.cwd!==t.resolvedPaths.cwd?await tn(e,t,n,{...r}):await en(e,t,r)}async function en(e,t,r){let n=h("Checking registry.",{silent:r.silent}).start(),s=await ut(e,t);return s?(n.stopAndPersist({symbol:c.cyan("\u2714")}),await Ne(s.dependencies,t,{silent:r.silent}),await St(s.devDependencies,t,{silent:r.silent}),await Me(s.files,t,{overwrite:r.overwrite,silent:r.silent})):(n?.fail(),S(new Error("Failed to fetch components from registry.")))}async function tn(e,t,r,n){let s=h("Checking registry.",{silent:n.silent}).start(),o=await $e(e,t),a=await oe(o,t),i=Qr.array(U).parse(a);if(!i.length)return s?.fail(),S(new Error("Failed to fetch components from registry."));s.stopAndPersist({symbol:c.cyan("\u2714")});let l=yt(i),u=ht(),m=[],x=[],k=[],v=h("Installing components.")?.start();for(let y of i){let j=u.get(y.type),W=l.get(y.name);if(!j)continue;let O=(y.type==="registry:ui"||W?.type==="registry:ui")&&r.tiptapUi||t;if(!O.resolvedPaths.tiptapUi)continue;let G=je(t.resolvedPaths.cwd,O.resolvedPaths.tiptapUi),K=await Ee(G,O.resolvedPaths.cwd)??O.resolvedPaths.cwd;await Ne(y.dependencies||[],O,{silent:!0});let H=await Me(y.files||[],O,{overwrite:n.overwrite,silent:!0,rootSpinner:v});m.push(...H.filesCreated.map(B=>Z.relative(G,Z.join(K,B)))),x.push(...H.filesUpdated.map(B=>Z.relative(G,Z.join(K,B)))),k.push(...H.filesSkipped.map(B=>Z.relative(G,Z.join(K,B))))}if(v.stopAndPersist({symbol:c.cyan("\u2714")}),m.sort(),x.sort(),k.sort(),!(m.length||x.length)&&!k.length&&h("No files updated.",{silent:n.silent})?.info(),m.length){h(`Created ${m.length} ${m.length===1?"file":"files"}:`,{silent:n.silent})?.stopAndPersist({symbol:c.cyan("\u2714")});for(let y of m)p.log(` - ${y}`)}if(x.length){h(`Updated ${x.length} ${x.length===1?"file":"files"}:`,{silent:n.silent})?.info();for(let y of x)p.log(` - ${y}`)}if(k.length){h(`Skipped ${k.length} ${k.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:n.silent})?.info();for(let y of k)p.log(` - ${y}`)}return{filesCreated:m,filesUpdated:x,filesSkipped:k}}function Ue(e){return e.split(/[-_]/).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}var on=J.object({components:J.array(J.string()).optional(),cwd:J.string(),path:J.string().optional(),silent:J.boolean(),overwrite:J.boolean()}),Rt={free:"Free",paid:"Paid"},Tt=1e3,L={divider:c.gray("-----------------------------------------"),warning:c.magenta(" Some components (marked as Paid) require an active subscription!"),emptyRegistry:c.red(" No components or templates found"),operationCancelled:c.red(" Operation cancelled"),missingDirectory:c.red(" Missing directory or empty project. Please create a new project first.")},Se={icon:{cursor:c.cyan("\u276F"),checked:"\u25CF"},style:{highlight:e=>c.cyan(e),answer:e=>c.white(e)},prefix:{done:c.cyan("\u2714"),idle:c.white("?")},helpMode:"always"},an={...Se,icon:{...Se.icon,checked:"\u25CF",cursor:" "}};function pn(e,t){return t?e.filter(r=>t.includes(r.name)):e}var De=e=>`
13
+ Please upgrade your subscription or use a component available in your current plan.`);let u=await o.json(),d=u&&typeof u=="object"&&"error"in u?u.error:o.statusText||m[o.status];throw new Error(`Failed to fetch from ${c.blue(i)}.
14
+ ${d}`)}return o.json()}))}catch(r){return p.error(`
15
+ `),P(r),[]}}async function ut(e,t){try{if(!await Oe(t))return null;e.includes("index")&&e.unshift("index");let s=await Ue(e,t),n=await se(s,t),i=Rr.array(L).parse(n);if(!i)return null;let o=(await I(t.resolvedPaths.cwd))?.framework.name,m=Ae.all(i.map(h=>h.dependencies??[])),u=Ae.all(i.map(h=>h.devDependencies??[])),d=Ir(u,o);return it.parse({dependencies:m,devDependencies:d,files:Ae.all(i.map(h=>h.files??[]))})}catch(r){return P(r),null}}async function Tr(e,t){let r=new Set,s=[];async function n(i){let a=dt(gt(i)?i:`components/${i}.json`);if(!r.has(a)){r.add(a);try{let[o]=await se([a],t),m=L.parse(o);if(s.push(a),m.registryDependencies)for(let u of m.registryDependencies)await n(u)}catch(o){console.error(`Error fetching or parsing registry item at ${i}:`,o)}}}return await n(e),Array.from(new Set(s))}async function Ue(e,t){let r=[];for(let s of e){let n=await Tr(s,t);r.push(...n)}return Array.from(new Set(r))}function dt(e){if(gt(e))return new URL(e).toString();if(!re)throw new Error("No registry URL found");if(e==="index.json")return`${re}/r/${e}`;if(e.startsWith("components/")){let t=e.replace("components/","").replace(".json","");return`${re}/api/registry/components/${t}`}return`${re}/${e}`}function gt(e){try{return new URL(e),!0}catch{return!1}}function yt(){return new Map([["registry:ui","tiptapUi"],["registry:ui-primitive","tiptapUiPrimitives"],["registry:ui-utils","tiptapUiUtils"],["registry:extension","tiptapExtensions"],["registry:node","tiptapNodes"],["registry:context","contexts"],["registry:hook","hooks"],["registry:lib","lib"],["registry:context","components"],["registry:template","tiptapTemplates"],["registry:component","components"],["registry:icon","titpapIcons"],["registry:style","styles"]])}function ht(e){let t=new Map;return e.forEach(r=>{r.registryDependencies&&r.registryDependencies.forEach(s=>{t.set(s,r)})}),t}function Ir(e,t){let r=Array.isArray(e)?e:[];if(!r.length)return[];let s=r.map(n=>String(n));if(t){let n=s.includes("sass"),i=s.includes("sass-embedded");if(n&&i){let a=[...s],o=[b.astro.name,b.laravel.name,b.vite.name,b.remix.name,b["tanstack-start"].name,b["react-router"].name],m=[b["next-app"].name,b["next-pages"].name,b.gatsby.name];return o.includes(t)?a=a.filter(u=>u!=="sass"):m.includes(t)&&(a=a.filter(u=>u!=="sass-embedded")),a.filter(u=>u!=="sass-embedded")}}return s}import{execa as Cr}from"execa";async function $e(e,t,r){if(e=Array.from(new Set(e)),!e?.length)return;r={silent:!1,...r};let s=g("Installing dependencies.",{silent:r.silent}).start(),n=await z(t.resolvedPaths.cwd);await Cr(n,[n==="npm"?"install":"add",...n==="npm"?["--save"]:[],...e],{cwd:t.resolvedPaths.cwd}),s.stopAndPersist({symbol:c.cyan("\u2714")})}import{existsSync as bt,promises as Fe}from"fs";import E,{basename as Wr}from"path";import{promises as Nr}from"fs";import{tmpdir as _r}from"os";import xt from"path";var we=async({sourceFile:e,config:t})=>{let r=e.getImportDeclarations();for(let s of r){let n=Er(s.getModuleSpecifierValue(),t);n&&s.setModuleSpecifier(n)}return e};function Er(e,t){if(!e.startsWith("@/registry/")){let r=t.aliases.components.split("/")[0];return e.replace(/^@\//,`${r}/`)}return e.match(/@\/registry\/tiptap-templates\/([^/]+)\/components\//)?e.replace(/@\/registry\/tiptap-templates\/([^/]+)\/components\//,`${t.aliases.components}/tiptap-templates/$1/`):e.match(/@\/registry\/tiptap-templates\/([^/]+)\/(?!components\/)/)?e.replace(/@\/registry\/tiptap-templates\/([^/]+)\//,`${t.aliases.components}/tiptap-templates/$1/`):t.aliases.components&&e.match(/@\/registry\/components/)?e.replace(/@\/registry\/components/,t.aliases.components):t.aliases.contexts&&e.match(/@\/registry\/contexts/)?e.replace(/@\/registry\/contexts/,t.aliases.contexts):t.aliases.tiptapExtensions&&e.match(/@\/registry\/tiptap-extension/)?e.replace(/@\/registry\/tiptap-extension/,t.aliases.tiptapExtensions):t.aliases.hooks&&e.match(/@\/registry\/hooks/)?e.replace(/@\/registry\/hooks/,t.aliases.hooks):t.aliases.tiptapIcons&&e.match(/@\/registry\/tiptap-icons/)?e.replace(/@\/registry\/tiptap-icons/,t.aliases.tiptapIcons):t.aliases.lib&&e.match(/@\/registry\/lib/)?e.replace(/@\/registry\/lib/,t.aliases.lib):t.aliases.tiptapNodes&&e.match(/@\/registry\/tiptap-node/)?e.replace(/@\/registry\/tiptap-node/,t.aliases.tiptapNodes):t.aliases.tiptapUiPrimitives&&e.match(/@\/registry\/tiptap-ui-primitive/)?e.replace(/@\/registry\/tiptap-ui-primitive/,t.aliases.tiptapUiPrimitives):t.aliases.tiptapUiUtils&&e.match(/@\/registry\/tiptap-ui-utils/)?e.replace(/@\/registry\/tiptap-ui-utils/,t.aliases.tiptapUiUtils):t.aliases.tiptapUi&&e.match(/@\/registry\/tiptap-ui/)?e.replace(/@\/registry\/tiptap-ui/,t.aliases.tiptapUi):t.aliases.styles&&e.match(/@\/registry\/styles/)?e.replace(/@\/registry\/styles/,t.aliases.styles):e.replace(/^@\/registry\/[^/]+(?:\/.*\/)?/,t.aliases.components+"/")}import{transformFromAstSync as jr}from"@babel/core";import{parse as Ar}from"@babel/parser";import Or from"@babel/plugin-transform-typescript";import*as xe from"recast";var Ur={sourceType:"module",allowImportExportEverywhere:!0,allowReturnOutsideFunction:!0,startLine:1,tokens:!0,plugins:["asyncGenerators","bigInt","classPrivateMethods","classPrivateProperties","classProperties","classStaticBlock","decimal","decorators-legacy","doExpressions","dynamicImport","exportDefaultFrom","exportNamespaceFrom","functionBind","functionSent","importAssertions","importMeta","nullishCoalescingOperator","numericSeparator","objectRestSpread","optionalCatchBinding","optionalChaining",["pipelineOperator",{proposal:"minimal"}],["recordAndTuple",{syntaxType:"hash"}],"throwExpressions","topLevelAwait","v8intrinsic","typescript","jsx"]},wt=async({sourceFile:e,config:t})=>{let r=e.getFullText();if(t.tsx)return r;let s=xe.parse(r,{parser:{parse:i=>Ar(i,Ur)}}),n=jr(s,r,{cloneInputAst:!1,code:!1,ast:!0,plugins:[Or],configFile:!1});if(!n||!n.ast)throw new Error("Failed to transform JSX");return xe.print(n.ast).code};import{SyntaxKind as $r}from"ts-morph";var Fr=/^["']use client["']$/g,ke=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let r=e.getFirstChildByKind($r.ExpressionStatement);return r&&Fr.test(r.getText())&&r.remove(),e};import{Project as Mr,ScriptKind as Dr}from"ts-morph";var Lr=new Mr({compilerOptions:{}});async function zr(e){let t=await Nr.mkdtemp(xt.join(_r(),"tiptap-"));return xt.join(t,e)}async function kt(e,t=[we,ke]){if(e.filename.endsWith(".scss")||e.filename.endsWith(".css")||e.filename.endsWith(".json"))return e.raw;let r=await zr(e.filename),s=Lr.createSourceFile(r,e.raw,{scriptKind:Dr.TSX});for(let n of t)await n({sourceFile:s,...e});return e.transformJsx?await wt({sourceFile:s,...e}):s.getText()}import{confirm as Vr}from"@inquirer/prompts";import be from"chalk";async function Ne(e,t,r){let s={filesCreated:[],filesUpdated:[],filesSkipped:[],errors:[]};if(!e?.length)return s;r={overwrite:!1,force:!1,silent:!1,...r};let n=g("Updating files.",{silent:r.silent})?.start();try{let[i]=await Promise.all([I(t.resolvedPaths.cwd)]);for(let a of e)try{if(!a.content)continue;let o;try{o=Jr(a,t,{isSrcDir:i?.isSrcDir,framework:i?.framework.name,commonRoot:Gr(e.map(l=>l.path),a.path)})}catch(l){s.errors.push({file:a.path,error:`Failed to resolve file path: ${l instanceof Error?l.message:String(l)}`});continue}if(!o)continue;let m=Wr(a.path),u=E.dirname(o);t.tsx||(o=o.replace(/\.tsx?$/,l=>l===".tsx"?".jsx":".js"));let d=!1;try{d=bt(o)}catch(l){s.errors.push({file:o,error:`Failed to check if file exists: ${l instanceof Error?l.message:String(l)}`});continue}let h;try{h=await kt({filename:a.path,raw:a.content,config:t,transformJsx:!t.tsx},[we,ke])}catch(l){s.errors.push({file:o,error:`Failed to transform content: ${l instanceof Error?l.message:String(l)}`});continue}if(d)try{let l=await Fe.readFile(o,"utf-8"),[x,$]=await Promise.all([Pt(l),Pt(h)]);if(x===$){s.filesSkipped.push(E.relative(t.resolvedPaths.cwd,o));continue}}catch(l){s.errors.push({file:o,error:`Failed to read or normalize existing file: ${l instanceof Error?l.message:String(l)}`});continue}if(d&&!r.overwrite){n?.stop(),r.rootSpinner&&r.rootSpinner?.stop();try{if(!await Vr({message:be.white(`The file ${c.blue(m)} already exists. Would you like to overwrite?`),theme:{prefix:be.hex("#46caff")("?"),style:{answer:x=>be.white(x)}}})){s.filesSkipped.push(E.relative(t.resolvedPaths.cwd,o)),r.rootSpinner&&r.rootSpinner.start();continue}}catch(l){s.errors.push({file:o,error:`Failed to get user confirmation: ${l instanceof Error?l.message:String(l)}`});continue}finally{n?.start(),r.rootSpinner&&r.rootSpinner.start()}}try{bt(u)||await Fe.mkdir(u,{recursive:!0}),await Fe.writeFile(o,h,"utf-8"),d?s.filesUpdated.push(E.relative(t.resolvedPaths.cwd,o)):s.filesCreated.push(E.relative(t.resolvedPaths.cwd,o))}catch(l){s.errors.push({file:o,error:`Failed to write file: ${l instanceof Error?l.message:String(l)}`})}}catch(o){s.errors.push({file:a.path||"unknown",error:`Unexpected error processing file: ${o instanceof Error?o.message:String(o)}`})}}catch(i){p.error(`An error occurred while updating files: ${i instanceof Error?i.message:String(i)}`)}finally{if(!(s.filesCreated.length||s.filesUpdated.length)&&!s.filesSkipped.length&&n?.info("No files updated."),s.filesCreated.length){if(n?.stopAndPersist({symbol:c.cyan("\u2714"),text:be.bold(`Created ${s.filesCreated.length} ${s.filesCreated.length===1?"file":"files"}:`)}),!r.silent)for(let a of s.filesCreated)p.log(` - ${a}`)}else n?.stop();if(s.filesUpdated.length&&(g(`Updated ${s.filesUpdated.length} ${s.filesUpdated.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let a of s.filesUpdated)p.log(` - ${a}`);if(s.filesSkipped.length&&(g(`Skipped ${s.filesSkipped.length} ${s.filesUpdated.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:r.silent})?.info(),!r.silent))for(let a of s.filesSkipped)p.log(` - ${a}`);if(s.errors.length&&(g(`Failed to process ${s.errors.length} ${s.errors.length===1?"file":"files"}:`,{silent:r.silent})?.fail(),!r.silent))for(let{file:a,error:o}of s.errors)p.error(` - ${a}: ${o}`);r.silent||p.break()}return s}function Kr(e,t,r){return r||(e.type==="registry:ui"?t.resolvedPaths.tiptapUi:e.type==="registry:ui-primitive"?t.resolvedPaths.tiptapUiPrimitives:e.type==="registry:ui-utils"?t.resolvedPaths.tiptapUiUtils:e.type==="registry:extension"?t.resolvedPaths.tiptapExtensions:e.type==="registry:node"?t.resolvedPaths.tiptapNodes:e.type==="registry:icon"?t.resolvedPaths.tiptapIcons:e.type==="registry:hook"?t.resolvedPaths.hooks:e.type==="registry:lib"?t.resolvedPaths.lib:e.type==="registry:context"?t.resolvedPaths.contexts:e.type==="registry:template"||e.type==="registry:component"?t.resolvedPaths.components:e.type==="registry:style"?t.resolvedPaths.styles:t.resolvedPaths.components)}function Gr(e,t){let r=e.map(a=>a.replace(/^\//,"")),s=t.replace(/^\//,""),n=s.split("/").slice(0,-1).join("/");if(!n)return"";let i=n.split("/");for(let a=i.length;a>0;a--){let o=i.slice(0,a).join("/");if(r.some(u=>u!==s&&u.startsWith(o+"/")))return"/"+o}return"/"+n}async function Pt(e){return e.replace(/\r\n/g,`
16
+ `).trim()}function Br(e,t){if(!t)return"";if(t==="next-app")return e;if(t==="next-pages"){let r=e.replace(/^app\//,"pages/");return r=r.replace(/\/page(\.[jt]sx?)$/,"$1"),r}if(t==="react-router"){let r=e.replace(/^app\//,"app/routes/");return r=r.replace(/\/page(\.[jt]sx?)$/,"$1"),r}if(t==="laravel"){let r=e.replace(/^app\//,"resources/js/pages/");return r=r.replace(/\/page(\.[jt]sx?)$/,"$1"),r}return""}function Yr(e,t){let r=e.replace(/^\/|\/$/g,""),s=t.replace(/^\/|\/$/g,""),n=r.split("/"),i=s.split("/"),a=i[i.length-1],o=n.findIndex(m=>m===a);return o===-1?n[n.length-1]:n.slice(o+1).join("/")}function Jr(e,t,r){if(!e.target&&e.path.includes("tiptap-templates/")&&e.type!=="registry:page"){let i=e.path.match(/tiptap-templates\/([^/]+)\/(.*)/);if(i){let[,a,o]=i;if(o.startsWith("components/")){let m=o.replace("components/","");return E.join(t.resolvedPaths.components,"tiptap-templates",a,m)}return E.join(t.resolvedPaths.components,"tiptap-templates",a,o)}}if(e.target&&e.path.includes("tiptap-templates/")&&e.target.includes("/data/")){let i=e.path.match(/tiptap-templates\/([^/]+)\//);if(i){let a=i[1],o=e.target.split("/data/")[1];return E.join(t.resolvedPaths.components,"tiptap-templates",a,"data",o)}}if(e.target){if(e.target.startsWith("~/"))return E.join(t.resolvedPaths.cwd,e.target.replace("~/",""));let i=e.target;return e.type==="registry:page"&&(i=Br(i,r.framework),!i)?"":r.isSrcDir?E.join(t.resolvedPaths.cwd,"src",i.replace("src/","")):E.join(t.resolvedPaths.cwd,i.replace("src/",""))}let s=Kr(e,t),n=Yr(e.path,s);return E.join(s,n)}import{z as qr}from"zod";import{execa as Hr}from"execa";async function vt(e,t,r){if(e=Array.from(new Set(e)),!e?.length)return;r={silent:!1,...r};let s=g("Installing development dependencies.",{silent:r.silent})?.start(),n=await z(t.resolvedPaths.cwd);s?.start(),await Hr(n,[n==="npm"?"install":"add",n==="npm"?"--save-dev":"-D",...e],{cwd:t.resolvedPaths.cwd}),s?.stopAndPersist({symbol:c.cyan("\u2714")})}async function Pe(e,t,r){r={overwrite:!1,silent:!1,isNewProject:!1,...r};let s=await et(t);return s&&s.tiptapUi&&s.tiptapUi.resolvedPaths.cwd!==t.resolvedPaths.cwd?await Zr(e,t,s,{...r}):await Xr(e,t,r)}async function Xr(e,t,r){let s=g("Checking registry.",{silent:r.silent}).start(),n=await ut(e,t);return n?(s.stopAndPersist({symbol:c.cyan("\u2714")}),await $e(n.dependencies,t,{silent:r.silent}),await vt(n.devDependencies,t,{silent:r.silent}),await Ne(n.files,t,{overwrite:r.overwrite,silent:r.silent})):(s?.fail(),P(new Error("Failed to fetch components from registry.")))}async function Zr(e,t,r,s){let n=g("Checking registry.",{silent:s.silent}).start(),i=await Ue(e,t),a=await se(i,t),o=qr.array(L).parse(a);if(!o.length)return n?.fail(),P(new Error("Failed to fetch components from registry."));n.stopAndPersist({symbol:c.cyan("\u2714")});let m=ht(o),u=yt(),d=[],h=[],l=[],x=g("Installing components.")?.start();for(let v of o){let K=u.get(v.type),Z=m.get(v.name);if(!K)continue;let j=(v.type==="registry:ui"||Z?.type==="registry:ui")&&r.tiptapUi||t;if(!j.resolvedPaths.tiptapUi)continue;let G=je(t.resolvedPaths.cwd,j.resolvedPaths.tiptapUi),B=await Ee(G,j.resolvedPaths.cwd)??j.resolvedPaths.cwd;await $e(v.dependencies||[],j,{silent:!0});let A=await Ne(v.files||[],j,{overwrite:s.overwrite,silent:!0,rootSpinner:x});if(A.errors&&A.errors.length>0){g(`Encountered ${A.errors.length} errors:`,{silent:s.silent})?.fail();for(let{file:F,error:ve}of A.errors)p.error(` - ${F}: ${ve}`)}d.push(...A.filesCreated.map(F=>q.relative(G,q.join(B,F)))),h.push(...A.filesUpdated.map(F=>q.relative(G,q.join(B,F)))),l.push(...A.filesSkipped.map(F=>q.relative(G,q.join(B,F))))}if(x.stopAndPersist({symbol:c.cyan("\u2714")}),d.sort(),h.sort(),l.sort(),!(d.length||h.length)&&!l.length&&g("No files updated.",{silent:s.silent})?.info(),d.length){g(`Created ${d.length} ${d.length===1?"file":"files"}:`,{silent:s.silent})?.stopAndPersist({symbol:c.cyan("\u2714")});for(let v of d)p.log(` - ${v}`)}if(h.length){g(`Updated ${h.length} ${h.length===1?"file":"files"}:`,{silent:s.silent})?.info();for(let v of h)p.log(` - ${v}`)}if(l.length){g(`Skipped ${l.length} ${l.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:s.silent})?.info();for(let v of l)p.log(` - ${v}`)}return{filesCreated:d,filesUpdated:h,filesSkipped:l}}function _e(e){return e.split(/[-_]/).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}var ts=Y.object({components:Y.array(Y.string()).optional(),cwd:Y.string(),path:Y.string().optional(),silent:Y.boolean(),overwrite:Y.boolean()}),Tt={free:"Free",paid:"Paid"},rs=1e3,N={divider:c.gray("----------------------------------------------"),warning:c.magenta(" Some components (marked as Paid) require an active subscription!"),emptyRegistry:c.red(" No components or templates found"),operationCancelled:c.red(" Operation cancelled"),missingDirectory:c.red(" Missing directory or empty project. Please create a new project first.")},Me={icon:{cursor:c.cyan("\u276F"),checked:"\u25CF"},style:{highlight:e=>c.cyan(e)},prefix:{done:c.cyan("\u2714"),idle:"?"},helpMode:"always"},It={...Me,icon:{...Me.icon,checked:"\u25CF",cursor:" "}};function ss(e,t){return t?e.filter(r=>t.includes(r.name)):e}var De=e=>`
18
17
  ${c.gray(e)}
19
- `;function Le(e){for(let t=0;t<e;t++)process.stdout.write("\x1B[1A"),process.stdout.write("\x1B[2K")}var cn=e=>({templates:e.filter(t=>t.type==="registry:template"),ui:e.filter(t=>t.type==="registry:ui"),primitives:e.filter(t=>t.type==="registry:ui-primitive"),nodes:e.filter(t=>t.type==="registry:node")});async function ln(e){let t=c.white("What would you like to integrate:"),r=De(" Use arrow-keys \u25B2\u25BC / [Return] to submit"),n=[],s=e.ui.length===0&&e.nodes.length===0;if(e.templates.length===0||n.push({name:"Templates",value:"templates"}),s||n.push({name:"Components",value:"components"}),n.length===0)return p.break(),console.log(L.emptyRegistry),null;try{console.log(L.divider);let a=await te({message:t,instructions:r,pageSize:Tt,theme:Se,choices:n});return console.log(L.divider),a}catch{return Le(4),console.log(L.operationCancelled),null}}async function mn(e,t){let r=[];if(!t)return r;let n=(s,o)=>{let a=s.filter(i=>t.includes(i.name));a.length>0&&(r.push(new bt(c.gray(` ${o}`))),a.forEach(i=>{let l=Rt[i.plan||"free"];r.push({name:`${Ue(i.name)} (${l})`,value:i.name})}),r.push(new bt(" ")))};return n(e.ui,"UI COMPONENTS"),n(e.nodes,"NODE COMPONENTS"),n(e.primitives,"PRIMITIVES"),r}async function fn(e,t){let r=De(`${L.warning}
20
- [Space] to select / [A] to toggle all / [I] to invert / [Return] to submit`),n=await mn(e,t);if(n.length===0)return[];try{let s=await sn({message:c.white("Select the components you want to add:"),instructions:r,required:!0,pageSize:20,choices:n,theme:an});return console.log(""),s}catch{return Le(25),console.log(L.operationCancelled),[]}}async function un(e){try{let t=De(" Use arrow-keys \u25B2\u25BC / [Return] to submit"),r=e.map(n=>{let s=Rt[n.plan||"free"],o=n.description?` - ${n.description}`:"";return{name:`${Ue(n.name)}${o} (${s})`,value:n.name}});return await te({message:c.white("Select the template you want to add:"),instructions:t,pageSize:Tt,choices:r,theme:Se})}catch{return Le(4),console.log(L.operationCancelled),""}}async function ze(e){if(e.components?.length)return e.components;let t=await Ae();if(!t)return p.break(),S(new Error("[prompts] - Failed to fetch registry index.")),[];let r=t.filter(Boolean),n=cn(r),s=await ln(n);if(!s)return[];let o=await ft();if(!o)return p.break(),S(new Error("[prompts] - Failed to fetch free components.")),[];switch(s){case"components":return await fn(n,o)||[];case"templates":{let a=pn(n.templates,o),i=await un(a);return i?[i]:[]}default:return[]}}var It=new nn().name("add").description("add Tiptap components and templates to your project").argument("[components...]","the components to add").option("-o, --overwrite","overwrite existing files.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-p, --path <path>","the path to add the component to.").option("-s, --silent","mute output.",!1).action(async(e,t)=>{try{let r=on.parse({components:e,cwd:rn.resolve(t.cwd),...t});if(r.components?.length||(r.components=await ze(r)),!r.components?.length)return;let{errors:n,config:s}=await rt(r);if(n[M]&&(p.warn(`
21
- ${L.missingDirectory}`),process.exit(0)),!s)throw new Error(`Failed to read config at ${f.info(r.cwd)}.`);await Pe(r.components,s,r)}catch(r){p.break(),S(r)}});import{Command as gn}from"commander";var Ct=new gn().name("info").description("get information about your project").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async e=>{p.info("> project info"),console.log(await b(e.cwd)),p.break(),p.info("> config"),console.log(await N(e.cwd))});import $t from"path";import{Command as On}from"commander";import{confirm as An}from"@inquirer/prompts";import{z as V}from"zod";import dn from"path";import Et from"fs-extra";async function jt(e){let t={};if(!Et.existsSync(e.cwd)||!Et.existsSync(dn.resolve(e.cwd,"package.json")))return t[M]=!0,{errors:t,projectInfo:null};let r=h("Verifying framework.",{silent:e.silent}).start(),n=await b(e.cwd);(!n||n?.framework.name==="manual")&&(t[Be]=!0,r?.fail(),p.break(),n?.framework.links.installation&&p.error(`We could not detect a supported framework at ${f.info(e.cwd)}.
22
- Visit ${f.info(n?.framework.links.installation)} to manually configure your project.
23
- Once configured, you can use the cli to add components.`),p.break(),process.exit(0)),r?.succeed(`Verifying framework. Found ${f.info(n.framework.label)}.`);let s=h("Validating import alias.",{silent:e.silent}).start();return n?.aliasPrefix?s?.succeed():(t[Ce]=!0,s?.fail()),Object.keys(t).length>0&&(t[Ce]&&(p.break(),p.error("No import alias found in your tsconfig.json file."),n?.framework.links.installation&&p.error(`Visit ${f.info(n?.framework.links.installation)} to learn how to set an import alias.`)),p.break(),process.exit(0)),{errors:t,projectInfo:n}}import hn from"os";import z from"path";import C from"fs-extra";import{execa as F}from"execa";import{parse as yn}from"jsonc-parser";import{input as wn}from"@inquirer/prompts";var xn="https://codeload.github.com/shadcn-ui/ui/tar.gz/main",Q={next:"next",vite:"vite","next-monorepo":"next-monorepo"},vn=(e,t="")=>wn({message:c.white(e),default:t,required:!0,validate:r=>r.length>128?"Name should be less than 128 characters.":!0,theme:{prefix:{done:c.cyan("\u2714"),idle:c.white("?")},style:{answer:r=>c.white(r)}}}),kn=async(e,t)=>{let r=`
18
+ `;function Le(e){for(let t=0;t<e;t++)process.stdout.write("\x1B[1A"),process.stdout.write("\x1B[2K")}var ns=e=>({templates:e.filter(t=>t.type==="registry:template"),ui:e.filter(t=>t.type==="registry:ui"),primitives:e.filter(t=>t.type==="registry:ui-primitive"),uiUtils:e.filter(t=>t.type==="registry:ui-utils"),nodes:e.filter(t=>t.type==="registry:node")});async function os(e,t=!0){let r="What would you like to integrate:",s=De(" Use arrow-keys \u25B2\u25BC / [Return] to submit"),n=[],i=e.ui.length===0&&e.nodes.length===0;if(e.templates.length===0||n.push({name:"Templates",value:"templates"}),i||n.push({name:"Components",value:"components"}),n.length===0)return p.break(),console.log(N.emptyRegistry),null;try{t&&console.log(N.divider);let o=await oe({message:r,instructions:s,pageSize:rs,theme:Me,choices:n});return t&&console.log(N.divider),o}catch{return Le(4),console.log(N.operationCancelled),null}}async function is(e,t){let r=[];if(!t)return r;let s=(n,i)=>{let a=n.filter(o=>t.includes(o.name));a.length>0&&(r.push(new St(c.gray(` ${i}`))),a.forEach(o=>{let m=Tt[o.plan||"free"];r.push({name:`${_e(o.name)} (${m})`,value:o.name})}),r.push(new St(" ")))};return s(e.ui,"UI COMPONENTS"),s(e.nodes,"NODE COMPONENTS"),s(e.primitives,"PRIMITIVES"),r}async function as(e,t){let r=De(`${N.warning}
19
+ [Space] to select / [A] to toggle all / [I] to invert / [Return] to submit`),s=await is(e,t);if(s.length===0)return[];try{let n=await Rt({message:"Select the components you want to add:",instructions:r,required:!0,pageSize:20,choices:s,theme:It});return console.log(""),n}catch{return Le(25),console.log(N.operationCancelled),[]}}async function ps(e){try{let t=De(`${N.warning}
20
+ [Space] to select / [A] to toggle all / [I] to invert / [Return] to submit`),r=e.map(s=>{let n=Tt[s.plan||"free"],i=s.description?` - ${s.description}`:"";return{name:`${_e(s.name)}${i} (${n})`,value:s.name}});return await Rt({message:"Select the templates you want to add:",instructions:t,required:!0,pageSize:20,choices:r,theme:It})}catch{return Le(25),console.log(N.operationCancelled),[]}}async function ze(e,t=!0){if(e.components?.length)return e.components;let r=await Oe();if(!r)return p.break(),P(new Error("[prompts] - Failed to fetch registry index.")),[];let s=r.filter(Boolean),n=ns(s),i=await os(n,t);if(!i)return[];let a=await ft();if(!a)return p.break(),P(new Error("[prompts] - Failed to fetch free components.")),[];switch(i){case"components":return await as(n,a)||[];case"templates":{let o=ss(n.templates,a);return await ps(o)||[]}default:return[]}}var Ct=new es().name("add").description("add Tiptap components and templates to your project").argument("[components...]","the components to add").option("-o, --overwrite","overwrite existing files.",!1).option("-c, --cwd <cwd>","the working directory. Defaults to the current directory.",process.cwd()).option("-p, --path <path>","the path to add the component to.").option("-s, --silent","mute output.",!1).action(async(e,t)=>{try{let r=ts.parse({components:e,cwd:Qr.resolve(t.cwd),...t});if(r.components?.length||(r.components=await ze(r)),!r.components?.length)return;let{errors:s,config:n}=await rt(r);if(s[M]&&(p.warn(`
21
+ ${N.missingDirectory}`),process.exit(0)),!n)throw new Error(`Failed to read config at ${c.blue(r.cwd)}.`);await Pe(r.components,n,r)}catch(r){p.break(),P(r)}});import{Command as cs}from"commander";var Et=new cs().name("info").description("get information about your project").option("-c, --cwd <cwd>","the working directory. Defaults to the current directory.",process.cwd()).action(async e=>{p.info("> project info"),console.log(await I(e.cwd)),p.break(),p.info("> config"),console.log(await O(e.cwd))});import $t from"path";import{Command as Cs}from"commander";import{confirm as Es}from"@inquirer/prompts";import{z as V}from"zod";import ls from"path";import jt from"fs-extra";import ms from"chalk";async function At(e){let t={};if(!jt.existsSync(e.cwd)||!jt.existsSync(ls.resolve(e.cwd,"package.json")))return t[M]=!0,{errors:t,projectInfo:null};let r=g("Verifying framework.",{silent:e.silent}).start(),s=await I(e.cwd);(!s||s?.framework.name==="manual")&&(t[Be]=!0,r?.fail(),p.break(),s?.framework.links.installation&&p.error(`We could not detect a supported framework at ${c.blue(e.cwd)}.
22
+ Visit ${c.blue(s?.framework.links.installation)} to manually configure your project.
23
+ Once configured, you can use the cli to add components.`),p.break(),process.exit(0)),r?.stopAndPersist({symbol:c.cyan("\u2714"),text:ms.bold(`Verifying framework. Found ${c.blue(s.framework.label)}.`)});let n=g("Validating import alias.",{silent:e.silent}).start();return s?.aliasPrefix?n?.stopAndPersist({symbol:c.cyan("\u2714")}):(t[Ce]=!0,n?.fail()),Object.keys(t).length>0&&(t[Ce]&&(p.break(),p.error("No import alias found in your tsconfig.json file."),s?.framework.links.installation&&p.error(`Visit ${c.blue(s?.framework.links.installation)} to learn how to set an import alias.`)),p.break(),process.exit(0)),{errors:t,projectInfo:s}}import fs from"os";import W from"path";import C from"fs-extra";import{execa as U}from"execa";import{parse as us}from"jsonc-parser";import{input as ds}from"@inquirer/prompts";import gs from"chalk";var ys="https://codeload.github.com/shadcn-ui/ui/tar.gz/main",X={next:"next",vite:"vite","next-monorepo":"next-monorepo"},hs=(e,t="")=>ds({message:e,default:t,required:!0,validate:r=>r.length>128?"Name should be less than 128 characters.":!0,theme:{prefix:{done:c.cyan("\u2714"),idle:"?"}}}),ws=async(e,t)=>{let r=`
24
24
  ${c.gray(" Use arrow-keys \u25B2\u25BC / [Return] to submit")}
25
- `;return te({message:c.white(e),instructions:r,theme:{icon:{cursor:c.cyan("\u276F")},style:{highlight:n=>c.cyan(n),answer:n=>c.white(n)},prefix:{done:c.cyan("\u2714"),idle:c.white("?")},helpMode:"always"},choices:t})};async function Ot(e){let t={srcDir:!1,...e},r=t.framework&&Q[t.framework]?t.framework:"next",n="my-app",s="latest";if(!t.framework){let i=`The path ${c.cyan(t.cwd)} does not contain a package.json file.
26
- Would you like to start a new project?`;r=await kn(i,[{name:"Next.js",value:"next"},{name:"Vite + React + TypeScript",value:"vite"}])}n=await vn("What is your project named?",n);let o=await D(t.cwd,{withFallback:!0}),a=z.join(t.cwd,n);return await Pn(t.cwd,n),r===Q.next?await Sn(a,{version:s,cwd:t.cwd,packageManager:o,srcDir:!!t.srcDir}):r===Q.vite?await bn(a,{cwd:t.cwd,packageManager:o,projectName:n}):r===Q["next-monorepo"]&&await Cn(a,{packageManager:o}),{projectPath:a,projectName:n,framework:r}}async function Pn(e,t){try{await C.access(e,C.constants.W_OK)}catch{p.break(),p.error(`The path ${f.info(e)} is not writable.`),p.error(`It is likely you do not have write permissions for this folder or the path ${f.info(e)} does not exist.`),p.break(),process.exit(0)}C.existsSync(z.resolve(e,t,"package.json"))&&(p.break(),p.error(`A project with the name ${f.info(t)} already exists.`),p.error("Please choose a different name and try again."),p.break(),process.exit(0))}async function Sn(e,t){let r=h("Creating a new Next.js project. This may take a few minutes.").start(),n=["--tailwind","--eslint","--typescript","--app",t.srcDir?"--src-dir":"--no-src-dir","--no-import-alias",`--use-${t.packageManager}`];(t.version.startsWith("15")||t.version.startsWith("latest")||t.version.startsWith("canary"))&&n.push("--turbopack");try{await F("npx",[`create-next-app@${t.version}`,e,"--silent",...n],{cwd:t.cwd}),await At(e),r.stopAndPersist({symbol:c.cyan("\u2714")})}catch{r?.fail("Something went wrong creating a new Next.js project."),p.break(),p.error("Something went wrong creating a new Next.js project. Please try again."),process.exit(0)}}async function bn(e,t){let r=h("Creating a new Vite + React + TypeScript project. This may take a few minutes.").start();try{await F("npm",["create","vite@latest",t.projectName,"--","--template","react-ts"],{cwd:t.cwd}),await F(t.packageManager,["install"],{cwd:e}),await Rn(e),await At(e),r.stopAndPersist({symbol:c.cyan("\u2714")})}catch(n){r?.fail("Something went wrong creating a new Vite project."),S(n)}}async function Rn(e){try{await Tn(e),await In(e)}catch{p.warn("Failed to set up TypeScript path aliases, but project creation succeeded")}}async function Tn(e){let t=async r=>{let n=z.join(e,r);if(!await C.pathExists(n))return;let s=await C.readFile(n,"utf-8"),o=yn(s);o.compilerOptions={...o.compilerOptions,baseUrl:".",paths:{...o.compilerOptions?.paths||{},"@/*":["./src/*"]}};let a=JSON.stringify(o,null,2);await C.writeFile(n,a)};await t("tsconfig.json"),await t("tsconfig.app.json")}async function In(e){let t=z.join(e,"vite.config.ts"),n=(await C.readFile(t,"utf-8")).replace("import { defineConfig } from 'vite'",`import { defineConfig } from 'vite'
25
+ `;return oe({message:e,instructions:r,theme:{icon:{cursor:c.cyan("\u276F")},prefix:{done:c.cyan("\u2714"),idle:"?"},helpMode:"always"},choices:t})};async function Ot(e){let t={srcDir:!1,...e},r=t.framework&&X[t.framework]?t.framework:"next",s="my-app",n="latest";if(!t.framework){let o=`The path ${c.cyan(t.cwd)} does not contain a package.json file.
26
+ Would you like to start a new project?`;r=await ws(o,[{name:"Next.js",value:"next"},{name:"Vite + React + TypeScript",value:"vite"}])}s=await hs("What is your project named?",s);let i=await z(t.cwd,{withFallback:!0}),a=W.join(t.cwd,s);return await xs(t.cwd,s),r===X.next?await ks(a,{version:n,cwd:t.cwd,packageManager:i,srcDir:!!t.srcDir}):r===X.vite?await bs(a,{cwd:t.cwd,packageManager:i,projectName:s}):r===X["next-monorepo"]&&await Rs(a,{packageManager:i}),{projectPath:a,projectName:s,framework:r}}async function xs(e,t){try{await C.access(e,C.constants.W_OK)}catch{p.break(),p.error(`The path ${c.blue(e)} is not writable.`),p.error(`It is likely you do not have write permissions for this folder or the path ${c.blue(e)} does not exist.`),p.break(),process.exit(0)}C.existsSync(W.resolve(e,t,"package.json"))&&(p.break(),p.error(`A project with the name ${c.blue(t)} already exists.`),p.error("Please choose a different name and try again."),p.break(),process.exit(0))}async function ks(e,t){let r=g("Creating a new Next.js project. This may take a few minutes.").start(),s=["--tailwind","--eslint","--typescript","--app",t.srcDir?"--src-dir":"--no-src-dir","--no-import-alias",`--use-${t.packageManager}`];(t.version.startsWith("15")||t.version.startsWith("latest")||t.version.startsWith("canary"))&&s.push("--turbopack");try{await U("npx",[`create-next-app@${t.version}`,e,"--silent",...s],{cwd:t.cwd}),await Ut(e),r.stopAndPersist({symbol:c.cyan("\u2714")})}catch{r?.fail("Something went wrong creating a new Next.js project."),p.break(),p.error("Something went wrong creating a new Next.js project. Please try again."),process.exit(0)}}async function bs(e,t){let r=g("Creating a new Vite + React + TypeScript project. This may take a few minutes.").start();try{await U("npm",["create","vite@latest",t.projectName,"--","--template","react-ts"],{cwd:t.cwd}),await U(t.packageManager,["install"],{cwd:e}),await Ps(e),await Ut(e),r.stopAndPersist({symbol:c.cyan("\u2714")})}catch(s){r?.fail("Something went wrong creating a new Vite project."),P(s)}}async function Ps(e){try{await vs(e),await Ss(e)}catch{p.warn("Failed to set up TypeScript path aliases, but project creation succeeded")}}async function vs(e){let t=async r=>{let s=W.join(e,r);if(!await C.pathExists(s))return;let n=await C.readFile(s,"utf-8"),i=us(n);i.compilerOptions={...i.compilerOptions,baseUrl:".",paths:{...i.compilerOptions?.paths||{},"@/*":["./src/*"]}};let a=JSON.stringify(i,null,2);await C.writeFile(s,a)};await t("tsconfig.json"),await t("tsconfig.app.json")}async function Ss(e){let t=W.join(e,"vite.config.ts"),s=(await C.readFile(t,"utf-8")).replace("import { defineConfig } from 'vite'",`import { defineConfig } from 'vite'
27
27
  import path from 'path'`).replace("plugins: [react()]",`plugins: [react()],
28
28
  resolve: {
29
29
  alias: {
30
30
  '@': path.resolve(__dirname, './src')
31
31
  }
32
- }`);await C.writeFile(t,n)}async function Cn(e,t){let r=h("Creating a new Next.js monorepo. This may take a few minutes.").start();try{await En(e),await F(t.packageManager,["install"],{cwd:e}),await jn(e),r?.succeed("Creating a new Next.js monorepo.")}catch(n){r?.fail("Something went wrong creating a new Next.js monorepo."),S(n)}}async function En(e){let t=z.join(hn.tmpdir(),`tiptap-framework-${Date.now()}`);await C.ensureDir(t);let r=await fetch(xn);if(!r.ok)throw new Error(`Failed to download framework: ${r.statusText}`);let n=z.resolve(t,"framework.tar.gz");await C.writeFile(n,Buffer.from(await r.arrayBuffer())),await F("tar",["-xzf",n,"-C",t,"--strip-components=2","ui-main/templates/monorepo-next"]);let s=z.resolve(t,"monorepo-next");await C.move(s,e),await C.remove(t)}async function jn(e){let t=process.cwd();try{await F("git",["--version"],{cwd:e}),await F("git",["init"],{cwd:e}),await F("git",["add","-A"],{cwd:e}),await F("git",["commit","-m","Initial commit"],{cwd:e}),await F("cd",[t])}catch{p.warn("Failed to initialize git repository, but project creation succeeded")}}async function At(e){let t=z.join(e,"README.md"),r=`# Tiptap Editor Project
32
+ }`);await C.writeFile(t,s)}async function Rs(e,t){let r=g("Creating a new Next.js monorepo. This may take a few minutes.").start();try{await Ts(e),await U(t.packageManager,["install"],{cwd:e}),await Is(e),r?.stopAndPersist({symbol:c.cyan("\u2714"),text:gs.bold(`Created a new Next.js monorepo at ${c.blue(e)}`)})}catch(s){r?.fail("Something went wrong creating a new Next.js monorepo."),P(s)}}async function Ts(e){let t=W.join(fs.tmpdir(),`tiptap-framework-${Date.now()}`);await C.ensureDir(t);let r=await fetch(ys);if(!r.ok)throw new Error(`Failed to download framework: ${r.statusText}`);let s=W.resolve(t,"framework.tar.gz");await C.writeFile(s,Buffer.from(await r.arrayBuffer())),await U("tar",["-xzf",s,"-C",t,"--strip-components=2","ui-main/templates/monorepo-next"]);let n=W.resolve(t,"monorepo-next");await C.move(n,e),await C.remove(t)}async function Is(e){let t=process.cwd();try{await U("git",["--version"],{cwd:e}),await U("git",["init"],{cwd:e}),await U("git",["add","-A"],{cwd:e}),await U("git",["commit","-m","Initial commit"],{cwd:e}),await U("cd",[t])}catch{p.warn("Failed to initialize git repository, but project creation succeeded")}}async function Ut(e){let t=W.join(e,"README.md"),r=`# Tiptap Editor Project
33
33
 
34
34
  Thank you for installing the Tiptap Simple Editor template via the Tiptap CLI! This README will help you get started quickly.
35
35
 
@@ -74,5 +74,5 @@ http://localhost:3000/simple
74
74
  ## Documentation
75
75
  To learn more about the Tiptap Simple Editor and how to customize it, visit the official documentation:
76
76
  [Tiptap Simple Editor Documentation](https://tiptap.dev/docs/ui-components/templates/simple-editor)
77
- `;try{await C.writeFile(t,r,"utf-8"),console.log(`Updated README.md in ${e}`)}catch(n){console.error(`Error updating README.md: ${n}`)}}var $n=V.object({cwd:V.string(),components:V.array(V.string()).optional(),silent:V.boolean(),isNewProject:V.boolean(),srcDir:V.boolean().optional(),framework:V.string().optional().refine(e=>!e||Q[e],{message:"Invalid framework. Please use 'next' or 'vite'."})}),Ve=(e,t=!0)=>An({message:c.white(e),default:t,theme:{prefix:{done:c.cyan("\u2714"),idle:c.white("?")},style:{answer:r=>c.white(r),message:r=>c.white(r)}}}),Nt=new On().name("init").description("initialize your project and install dependencies").argument("[components...]","the components to add").option("-f, --framework <framework>","the framework to use. (next, vite)").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-s, --silent","mute output.",!1).option("--src-dir","use the src directory when creating a new project (specific to next).",!1).action(async(e,t)=>{try{let r=$n.parse({cwd:$t.resolve(t.cwd),isNewProject:!1,components:e,...t});await Nn(r),p.log(`${f.success("Success!")} Project initialization completed.`),p.break()}catch(r){p.break(),S(r)}});async function Nn(e){let{cwd:t,skipPreflight:r,components:n,silent:s}=e,o,a,i={...e};if(r)o=await b(t);else{let k=await jt(e);if(k.errors[M]){let{projectPath:$,framework:y}=await Ot(e);$||process.exit(0),i={...i,cwd:$,isNewProject:!0},a=y}o=k.projectInfo}if(a==="next-monorepo"){let k=$t.resolve(i.cwd,"apps/web");return await N(k)}let l=await Ze(i.cwd,o),u=l?await _n(l):await Fn(await N(i.cwd)),m=n||[];m.length||(await Ve("Would you like to add a template or UI components to your project?")||(p.info(""),process.exit(0)),m=await ze({...i,overwrite:!1}),m.length||(p.info(""),process.exit(0)));let x=await re(i.cwd,u);return await Pe(m,x,{overwrite:!1,silent:s,isNewProject:i.isNewProject||o?.framework.name==="next-app"}),x}async function Fn(e=null){p.info("");let t=await Ve(`Would you like to use ${c.cyan("TypeScript")} (recommended)?`,e?.tsx??!0),r=await Ve(`Are you using ${c.cyan("React Server Components")}?`,e?.rsc??!0);return X.parse({rsc:r,tsx:t,aliases:{components:pe,contexts:ce,hooks:le,tiptapIcons:me,lib:ne,tiptapExtensions:fe,tiptapNodes:ue,tiptapUi:ge,tiptapUiPrimitives:de,styles:he}})}async function _n(e){return X.parse({rsc:e?.rsc,tsx:e?.tsx,aliases:e?.aliases})}import{Command as Un}from"commander";var Ft={name:"@tiptap/cli",version:"1.1.11",description:"Tiptap CLI",publishConfig:{access:"public"},author:{name:"tiptap",url:"https://github.com/ueberdosis/tiptap"},files:["dist"],keywords:["cli","components","nextjs","react","templates","tiptap","tiptap-cli","ui"],type:"module",exports:{".":{types:"./dist/index.d.ts",default:"./dist/index.js"}},bin:"./dist/index.js",scripts:{dev:"tsup --watch",build:"tsup",typecheck:"tsc --noEmit",clean:"rm -rf dist","start:dev":"cross-env REGISTRY_URL=http://localhost:3000 node dist/index.js","start:prod":"cross-env REGISTRY_URL=https://template.tiptap.dev node dist/index.js",start:"node dist/index.js","pub:beta":"pnpm build && pnpm publish --no-git-checks --access public --tag beta","pub:release":"pnpm build && pnpm publish --access public"},dependencies:{"@antfu/ni":"^23.3.1","@babel/core":"^7.26.10","@babel/parser":"^7.27.0","@babel/plugin-transform-typescript":"^7.27.0","@inquirer/core":"^10.1.10","@inquirer/figures":"^1.0.11","@inquirer/prompts":"^7.4.1","@inquirer/type":"^3.0.6","ansi-escapes":"^7.0.0",chalk:"^5.4.1",commander:"^13.1.0",cosmiconfig:"^9.0.0",deepmerge:"^4.3.1",execa:"^9.5.2","fast-glob":"^3.3.3","fs-extra":"^11.3.0","https-proxy-agent":"^7.0.6","jsonc-parser":"^3.3.1",kleur:"^4.1.5","node-fetch":"^3.3.2",ora:"^8.2.0",recast:"^0.23.11","ts-morph":"^25.0.1","tsconfig-paths":"^4.2.0",yaml:"^2.7.1","yoctocolors-cjs":"^2.1.2",zod:"^3.24.2"},devDependencies:{"@babel/plugin-transform-typescript":"^7.26.5","@types/babel__core":"^7.20.5","@types/fs-extra":"^11.0.4","@types/prompts":"^2.4.9",tsup:"^8.4.0","type-fest":"^4.39.1"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function Dn(){let e=new Un().name("tiptap").description("add components and dependencies to your project").version(Ft.version||"1.0.0","-v, --version","display the version number");e.addCommand(Nt).addCommand(It).addCommand(Ct),e.parse()}Dn();
77
+ `;try{await C.writeFile(t,r,"utf-8")}catch{}}import js from"chalk";var As=V.object({cwd:V.string(),components:V.array(V.string()).optional(),silent:V.boolean(),isNewProject:V.boolean(),srcDir:V.boolean().optional(),framework:V.string().optional().refine(e=>!e||X[e],{message:"Invalid framework. Please use 'next' or 'vite'."})}),We=(e,t=!0)=>Es({message:e,default:t,theme:{prefix:{done:c.cyan("\u2714"),idle:"?"}}}),Ft=new Cs().name("init").description("initialize your project and install dependencies").argument("[components...]","the components to add").option("-f, --framework <framework>","the framework to use. (next, vite)").option("-c, --cwd <cwd>","the working directory. Defaults to the current directory.",process.cwd()).option("-s, --silent","mute output.",!1).option("--src-dir","use the src directory when creating a new project (specific to next).",!1).action(async(e,t)=>{try{let r=As.parse({cwd:$t.resolve(t.cwd),isNewProject:!1,components:e,...t});await Os(r),p.log(js.bold(`${c.cyan("Success!")} Project initialization completed.`)),p.break()}catch(r){p.break(),P(r)}});async function Os(e){let{cwd:t,skipPreflight:r,components:s,silent:n}=e,i,a,o={...e};if(r)i=await I(t);else{let l=await At(e);if(l.errors[M]){let{projectPath:$,framework:v}=await Ot(e);$||process.exit(0),o={...o,cwd:$,isNewProject:!0},a=v}i=l.projectInfo}if(a==="next-monorepo"){let l=$t.resolve(o.cwd,"apps/web");return await O(l)}let m=await Ze(o.cwd,i),u=m?await $s(m):await Us(await O(o.cwd)),d=s||[];d.length||(await We("Would you like to add a template or UI components to your project?")||(p.info(""),process.exit(0)),d=await ze({...o,overwrite:!1},!1),d.length||(p.info(""),process.exit(0)));let h=await ee(o.cwd,u);return await Pe(d,h,{overwrite:!1,silent:n,isNewProject:o.isNewProject||i?.framework.name==="next-app"}),h}async function Us(e=null){p.info("");let t=await We(`Would you like to use ${c.cyan("TypeScript")} (recommended)?`,e?.tsx??!0),r=await We(`Are you using ${c.cyan("React Server Components")}?`,e?.rsc??!0);return H.parse({rsc:r,tsx:t,aliases:{components:ae,contexts:pe,hooks:ce,tiptapIcons:le,lib:te,tiptapExtensions:me,tiptapNodes:fe,tiptapUi:ue,tiptapUiPrimitives:de,tiptapUiUtils:ge,styles:ye}})}async function $s(e){return H.parse({rsc:e?.rsc,tsx:e?.tsx,aliases:e?.aliases})}import{Command as Ns}from"commander";var Nt={name:"@tiptap/cli",version:"1.1.12",description:"Tiptap CLI",publishConfig:{access:"public"},author:{name:"tiptap",url:"https://github.com/ueberdosis/tiptap"},files:["dist"],keywords:["cli","components","nextjs","react","templates","tiptap","tiptap-cli","ui"],type:"module",exports:{".":{types:"./dist/index.d.ts",default:"./dist/index.js"}},bin:"./dist/index.js",scripts:{dev:"tsup --watch",build:"tsup",typecheck:"tsc --noEmit",clean:"rm -rf dist","start:dev":"cross-env REGISTRY_URL=http://localhost:3000 node dist/index.js","start:prod":"cross-env REGISTRY_URL=https://template.tiptap.dev node dist/index.js",start:"node dist/index.js","pub:beta":"pnpm build && pnpm publish --no-git-checks --access public --tag beta","pub:release":"pnpm build && pnpm publish --access public"},dependencies:{"@antfu/ni":"^23.3.1","@babel/core":"^7.26.10","@babel/parser":"^7.27.0","@babel/plugin-transform-typescript":"^7.27.0","@inquirer/core":"^10.1.10","@inquirer/figures":"^1.0.11","@inquirer/prompts":"^7.4.1","@inquirer/type":"^3.0.6","ansi-escapes":"^7.0.0",chalk:"^5.4.1",commander:"^13.1.0",cosmiconfig:"^9.0.0",deepmerge:"^4.3.1",execa:"^9.5.2","fast-glob":"^3.3.3","fs-extra":"^11.3.0","https-proxy-agent":"^7.0.6","jsonc-parser":"^3.3.1","node-fetch":"^3.3.2",ora:"^8.2.0",recast:"^0.23.11","ts-morph":"^25.0.1","tsconfig-paths":"^4.2.0",yaml:"^2.7.1","yoctocolors-cjs":"^2.1.2",zod:"^3.24.3"},devDependencies:{"@babel/plugin-transform-typescript":"^7.26.5","@types/babel__core":"^7.20.5","@types/fs-extra":"^11.0.4","@types/prompts":"^2.4.9",tsup:"^8.4.0","type-fest":"^4.40.0"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function _s(){let e=new Ns().name("tiptap").description("add components and dependencies to your project").version(Nt.version||"1.0.0","-v, --version","display the version number");e.addCommand(Ft).addCommand(Ct).addCommand(Et),e.parse()}_s();
78
78
  //# sourceMappingURL=index.js.map