@tiptap/cli 1.1.11 → 3.0.0
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/LICENSE.md +45 -0
- package/dist/index.js +325 -50
- package/dist/index.js.map +1 -1
- package/package.json +18 -15
- package/LICENSE +0 -21
package/dist/index.js
CHANGED
|
@@ -1,78 +1,353 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
${
|
|
4
|
-
${
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
`),
|
|
9
|
-
${
|
|
10
|
-
|
|
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)}.
|
|
2
|
+
import oo from"path";import{Command as io}from"commander";import{z as ae}from"zod";import{createPrompt as hr,useState as Ue,useKeypress as yr,usePrefix as wr,usePagination as xr,useRef as gt,useMemo as Fe,useEffect as kr,isBackspaceKey as vr,isEnterKey as Pr,isUpKey as De,isDownKey as ht,isNumberKey as Tr,Separator as ye,ValidationError as br,makeTheme as Sr}from"@inquirer/core";import yt from"yoctocolors-cjs";import Ir from"@inquirer/figures";import Cr from"ansi-escapes";import{Separator as Zo}from"@inquirer/core";var Er={icon:{cursor:Ir.pointer},style:{disabled:e=>yt.dim(`- ${e}`),description:e=>yt.cyan(e)},helpMode:"auto",indexMode:"hidden"};function ce(e){return!ye.isSeparator(e)&&!e.disabled}function Ar(e){return e.map(t=>{if(ye.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 we=hr((e,t)=>{let{loop:r=!0,pageSize:n=7,instructions:o}=e,c=gt(!0),s=Sr(Er,e.theme),[a,m]=Ue("idle"),w=wr({status:a,theme:s}),g=gt(),[v,f]=Ue(!0),y=Fe(()=>Ar(e.choices),[e.choices]),$=Fe(()=>{let d=y.findIndex(ce),k=y.findLastIndex(ce);if(d===-1)throw new br("[select prompt] No selectable choices. All choices are disabled.");return{first:d,last:k}},[y]),b=Fe(()=>"default"in e?y.findIndex(d=>ce(d)&&d.value===e.default):-1,[e.default,y]),[F,L]=Ue(b===-1?$.first:b),_=y[F];yr((d,k)=>{if(clearTimeout(g.current),f(!1),Pr(d))m("done"),t(_.value);else if(De(d)||ht(d)){if(k.clearLine(0),r||De(d)&&F!==$.first||ht(d)&&F!==$.last){let P=De(d)?-1:1,N=F;do N=(N+P+y.length)%y.length;while(!ce(y[N]));L(N)}}else if(Tr(d)&&!Number.isNaN(Number(k.line))){let P=Number(k.line)-1,N=y[P];N!=null&&ce(N)&&L(P),g.current=setTimeout(()=>{k.clearLine(0)},700)}else if(vr(d))k.clearLine(0);else{let P=k.line.toLowerCase(),N=y.findIndex(te=>ye.isSeparator(te)||!ce(te)?!1:te.name.toLowerCase().startsWith(P));N!==-1&&L(N),g.current=setTimeout(()=>{k.clearLine(0)},700)}}),kr(()=>()=>{clearTimeout(g.current)},[]);let W=s.style.message(e.message,a),J="",l="";(s.helpMode==="always"||s.helpMode==="auto"&&v&&(o===void 0||o))&&(typeof o=="string"?J=o:J=` (${[`${s.style.key("\u2191\u2193")} to navigate`,`${s.style.key("enter")} to select`,s.indexMode==="number"?`${s.style.key("1-9")} to jump`:"","type to filter"].filter(k=>k!=="").join(", ")})`,y.length>n&&(s.helpMode==="always"||s.helpMode==="auto"&&c.current)&&(l=`
|
|
3
|
+
${s.style.help("(Use arrow keys to reveal more choices)")}`,c.current=!1));let u=xr({items:y,active:F,renderItem({item:d,isActive:k,index:P}){if(ye.isSeparator(d))return` ${d.separator}`;let N=s.indexMode==="number"?`${P+1}. `:"";if(d.disabled){let _e=typeof d.disabled=="string"?d.disabled:"(disabled)";return s.style.disabled(`${N}${d.name} ${_e}`)}let te=k?s.style.highlight:_e=>_e,gr=k?s.icon.cursor:" ";return te(`${gr} ${N}${d.name}`)},pageSize:n,loop:r});if(a==="done")return`${w} ${W} ${s.style.answer(_.short)}`;let x=_.description?`
|
|
4
|
+
${s.style.description(_.description)}`:"";return`${[w,W,J].filter(Boolean).join(" ")}
|
|
5
|
+
${u}${l}${x}${Cr.cursorHide}`});import{checkbox as or,Separator as nr}from"@inquirer/prompts";import Wr from"path";var q="1";var Me="6",wt="7";import U from"path";import{createMatchPath as Rr}from"tsconfig-paths";async function E(e,t){return Rr(t.absoluteBaseUrl,t.paths)(e,void 0,()=>!0,[".ts",".tsx"])}import{cosmiconfig as Ur}from"cosmiconfig";import Fr from"fast-glob";import{loadConfig as Dr}from"tsconfig-paths";import{z as S}from"zod";import kt from"path";var h={"next-app":{name:"next-app",label:"Next.js",links:{installation:"https://tiptap.dev/docs/ui-components/install/next"}},"next-pages":{name:"next-pages",label:"Next.js",links:{installation:"https://tiptap.dev/docs/ui-components/install/next"}},"react-router":{name:"react-router",label:"React Router",links:{installation:"https://tiptap.dev/docs/ui-components/install/react-router"}},vite:{name:"vite",label:"Vite",links:{installation:"https://tiptap.dev/docs/ui-components/install/vite"}},astro:{name:"astro",label:"Astro",links:{installation:"https://tiptap.dev/docs/ui-components/install/astro"}},laravel:{name:"laravel",label:"Laravel",links:{installation:"https://tiptap.dev/docs/ui-components/install/laravel"}},"tanstack-start":{name:"tanstack-start",label:"TanStack Start",links:{installation:"https://tiptap.dev/docs/ui-components/install/tanstack"}},manual:{name:"manual",label:"Manual",links:{installation:"https://tiptap.dev/docs/ui-components/install/next"}}};import Nr from"path";import jr from"fs-extra";function xt(e="",t=!0){let r=Nr.join(e,"package.json");return jr.readJSONSync(r,{throws:t})}import Pt from"fast-glob";import vt from"fs-extra";import{loadConfig as $r}from"tsconfig-paths";var Tt=["**/node_modules/**",".next","public","dist","build"];async function O(e){let[t,r,n,o,c]=await Promise.all([Pt.glob("**/{next,vite,astro,app}.config.*|gatsby-config.*|composer.json|react-router.config.*",{cwd:e,deep:3,ignore:Tt}),vt.pathExists(kt.resolve(e,"src")),_r(e),Or(e),xt(e,!1)]),s=await vt.pathExists(kt.resolve(e,`${r?"src/":""}app`)),a={framework:h.manual,isSrcDir:r,isRSC:!1,isTsx:n,aliasPrefix:o};return t.find(m=>m.startsWith("next.config."))?.length?(a.framework=s?h["next-app"]:h["next-pages"],a.isRSC=s,a):t.find(m=>m.startsWith("astro.config."))?.length?(a.framework=h.astro,a):t.find(m=>m.startsWith("composer.json"))?.length?(a.framework=h.laravel,a):t.find(m=>m.startsWith("app.config."))?.length&&[...Object.keys(c?.dependencies??{}),...Object.keys(c?.devDependencies??{})].find(m=>m.startsWith("@tanstack/start"))?(a.framework=h["tanstack-start"],a):t.find(m=>m.startsWith("react-router.config."))?.length?(a.framework=h["react-router"],a):(t.find(m=>m.startsWith("vite.config."))?.length&&(a.framework=h.vite),a)}async function Or(e){let t=await $r(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 _r(e){return(await Pt.glob("tsconfig.*",{cwd:e,deep:1,ignore:Tt})).length>0}async function bt(e,t=null){let[r,n]=await Promise.all([K(e),t?Promise.resolve(t):O(e)]);if(r)return r;if(!n)return null;let o={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`,tiptapUiUtils:`${n.aliasPrefix}/components/tiptap-ui-utils`,styles:`${n.aliasPrefix}/styles`}};return await re(e,o)}var Le="@/components",Be="@/contexts",We="@/hooks",ze="@/components/tiptap-icons",ke="@/lib",Ke="@/components/tiptap-extension",Ve="@/components/tiptap-node",Je="@/components/tiptap-ui",Ye="@/components/tiptap-ui-primitive",Ge="@/components/tiptap-ui-utils",qe="@/styles",Mr=Ur("components",{searchPlaces:["components.json"]}),ne=S.object({rsc:S.coerce.boolean().default(!1),tsx:S.coerce.boolean().default(!0),aliases:S.object({components:S.string(),contexts:S.string().optional(),hooks:S.string().optional(),tiptapIcons:S.string().optional(),lib:S.string().optional(),tiptapExtensions:S.string().optional(),tiptapNodes:S.string().optional(),tiptapUi:S.string().optional(),tiptapUiPrimitives:S.string().optional(),tiptapUiUtils:S.string().optional(),styles:S.string().optional()})}),St=ne.extend({resolvedPaths:S.object({cwd:S.string(),components:S.string(),contexts:S.string(),hooks:S.string(),tiptapIcons:S.string(),lib:S.string(),tiptapExtensions:S.string(),tiptapNodes:S.string(),tiptapUi:S.string(),tiptapUiPrimitives:S.string(),tiptapUiUtils:S.string(),styles:S.string()})}),Lr=S.record(St);async function K(e){let t=await Mr.search(e),r=await O(e),n={components:Le,contexts:Be,hooks:We,tiptapIcons:ze,lib:ke,tiptapExtensions:Ke,tiptapNodes:Ve,tiptapUi:Je,tiptapUiPrimitives:Ye,tiptapUiUtils:Ge,styles:qe},o=(s,a)=>Object.fromEntries(Object.entries(s).map(([m,w])=>[m,w.replace(/^@/,a)])),c;if(t){let s={...n,...t.config.aliases};r?.aliasPrefix?c=ne.parse({...t.config,aliases:o(s,r.aliasPrefix)}):c=ne.parse({...t.config,aliases:s})}else{let s=n;r?.aliasPrefix&&(s=o(s,r.aliasPrefix)),c=ne.parse({rsc:r?.isRSC??!1,tsx:r?.isTsx??!0,aliases:s})}return await re(e,c)}async function re(e,t){let r=await Dr(e);if(r.resultType==="failed")throw new Error(`Failed to load ${t.tsx?"tsconfig":"jsconfig"}.json. ${r.message??""}`.trim());return St.parse({...t,resolvedPaths:{cwd:e,components:await E(t.aliases.components,r),contexts:t.aliases.contexts?await E(t.aliases.contexts,r):U.resolve(await E(t.aliases.components,r)??e,"..","contexts"),hooks:t.aliases.hooks?await E(t.aliases.hooks,r):U.resolve(await E(t.aliases.components,r)??e,"..","hooks"),tiptapIcons:t.aliases.tiptapIcons?await E(t.aliases.tiptapIcons,r):U.resolve(await E(t.aliases.components,r)??e,"tiptap-icons"),lib:t.aliases.lib?await E(t.aliases.lib,r):U.resolve(await E(ke,r)??e,".."),tiptapExtensions:t.aliases.tiptapExtensions?await E(t.aliases.tiptapExtensions,r):U.resolve(await E(t.aliases.components,r)??e,"tiptap-extension"),tiptapNodes:t.aliases.tiptapNodes?await E(t.aliases.tiptapNodes,r):U.resolve(await E(t.aliases.components,r)??e,"tiptap-node"),tiptapUi:t.aliases.tiptapUi?await E(t.aliases.tiptapUi,r):U.resolve(await E(t.aliases.components,r)??e,"tiptap-ui"),tiptapUiPrimitives:t.aliases.tiptapUiPrimitives?await E(t.aliases.tiptapUiPrimitives,r):U.resolve(await E(t.aliases.components,r)??e,"tiptap-ui-primitive"),tiptapUiUtils:t.aliases.tiptapUiUtils?await E(t.aliases.tiptapUiUtils,r):U.resolve(await E(t.aliases.components,r)??e,"tiptap-ui-utils"),styles:t.aliases.styles?await E(t.aliases.styles,r):U.resolve(e,"styles")}})}async function It(e){let t={};for(let n of Object.keys(e.aliases)){if(!Br(n,e))continue;let o=e.resolvedPaths[n],c=await He(e.resolvedPaths.cwd,o);if(!c){t[n]=e;continue}t[n]=await K(c)}let r=Lr.safeParse(t);return r.success?r.data:null}async function He(e,t){let r=Xe(e,t),n=U.relative(r,t),c=(await Fr.glob("**/package.json",{cwd:r,deep:3,ignore:["**/node_modules/**","**/dist/**","**/build/**","**/public/**"]})).map(s=>U.dirname(s)).find(s=>n.startsWith(s));return c?U.join(r,c):null}function Br(e,t){return Object.keys(t.resolvedPaths).includes(e)}function Xe(e,t){let r=e.split(U.sep),n=t.split(U.sep),o=[];for(let c=0;c<Math.min(r.length,n.length)&&r[c]===n[c];c++)o.push(r[c]);return o.join(U.sep)}import H from"chalk";var p={cyan:H.cyan,magenta:H.magenta,gray:H.gray,white:H.white,yellow:H.yellow,green:H.green,red:H.red,blue:H.blue};var i={error(...e){console.log(p.red(e.join(" ")))},warn(...e){console.log(p.yellow(e.join(" ")))},info(...e){console.log(p.cyan(e.join(" ")))},success(...e){console.log(p.green(e.join(" ")))},log(...e){console.log(e.join(" "))},break(){console.log("")}};import Ct from"fs-extra";async function Et(e){let t={};if(!Ct.existsSync(e.cwd)||!Ct.existsSync(Wr.resolve(e.cwd,"package.json")))return t[q]=!0,{errors:t,config:null};try{let r=await K(e.cwd);return{errors:t,config:r}}catch(r){console.log("[preFlightAdd] - ",r),i.break(),i.error(`Make sure you are in a valid project directory. Run ${p.cyan("npx @tiptap/cli init")} to create a new project.`),i.break(),process.exit(0)}}import le from"path";import{z as zr}from"zod";function A(e){if(i.error("Something went wrong. Please check the error below for more details."),i.error("If the problem persists, please open an issue on GitHub."),i.error(""),typeof e=="string"&&(i.error(e),i.break(),process.exit(0)),e instanceof zr.ZodError){i.error("Validation failed:");for(let[t,r]of Object.entries(e.flatten().fieldErrors))i.error(`- ${p.cyan(t)}: ${r}`);i.break(),process.exit(0)}e instanceof Error&&(i.error(e.message),i.break(),process.exit(0)),i.break(),process.exit(0)}import{z as C}from"zod";var At=C.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"]),Ze=["start","team","growth","enterprise"],Kr=["open-source","light"],Vr=[...Ze,...Kr],Jr=C.array(C.enum(Vr)).default([]),Rt=C.object({path:C.string(),content:C.string().optional(),type:At,target:C.string().optional()}),X=C.object({name:C.string(),type:At,description:C.string().optional(),dependencies:C.array(C.string()).optional(),devDependencies:C.array(C.string()).optional(),registryDependencies:C.array(C.string()).optional(),files:C.array(Rt).optional(),meta:C.record(C.string(),C.any()).optional(),plans:Jr.optional(),hide:C.boolean().default(!1).optional()}),Mi=C.array(X),Nt=C.array(X.extend({files:C.array(C.union([C.string(),Rt])).optional()})),jt=X.pick({dependencies:!0,devDependencies:!0,files:!0});import et from"deepmerge";import{HttpsProxyAgent as Gr}from"https-proxy-agent";import $t from"node-fetch";import{z as qr}from"zod";import Yr from"conf";var Qe=class{config;constructor(){this.config=new Yr({projectName:"tiptap-cli",schema:{bearerToken:{type:"string"},authToken:{type:"string"},email:{type:"string"},loginDate:{type:"string"},plans:{type:"array"}}})}setBearerToken(t,r){try{this.config.set("bearerToken",t),this.config.set("loginDate",new Date().toISOString()),r?.email&&this.config.set("email",r.email),r?.plans&&this.config.set("plans",r.plans)}catch(n){i.error(`Failed to store bearer token: ${n instanceof Error?n.message:"Unknown error"}`)}}getBearerToken(){try{return this.config.get("bearerToken")||null}catch(t){return i.error(`Failed to retrieve bearer token: ${t instanceof Error?t.message:"Unknown error"}`),null}}setAuthToken(t,r){try{this.config.set("authToken",t),this.config.set("loginDate",new Date().toISOString()),r?.email&&this.config.set("email",r.email),r?.plans&&this.config.set("plans",r.plans)}catch(n){i.error(`Failed to store auth token: ${n instanceof Error?n.message:"Unknown error"}`)}}getAuthToken(){try{return this.config.get("authToken")||null}catch(t){return i.error(`Failed to retrieve auth token: ${t instanceof Error?t.message:"Unknown error"}`),null}}getUserInfo(){return{email:this.config.get("email"),plans:this.config.get("plans")||[],loginDate:this.config.get("loginDate")}}getTokenExpiration(){let t=this.config.get("loginDate");if(!t)return null;let r=new Date(t),n=new Date(r);return n.setMonth(n.getMonth()+11),n.toISOString()}isValidToken(){let t=this.getBearerToken(),r=this.getAuthToken();if(!t&&!r)return!1;let n=this.getTokenExpiration();return n&&new Date(n)<=new Date?(this.clear(),!1):!0}clear(){try{this.config.clear()}catch(t){i.error(`Failed to clear token storage: ${t instanceof Error?t.message:"Unknown error"}`)}}hasPlan(t){return(this.config.get("plans")||[]).includes(t)}},R=new Qe;var oe="https://template.tiptap.dev",Ot=process.env.https_proxy?new Gr(process.env.https_proxy):void 0;async function pe(e){try{let[t]=await ge(["index.json"],e);return Nt.parse(t)}catch(t){i.error(`
|
|
6
|
+
`),A(t)}}async function _t(){try{let e=`${oe}/api/registry/free`,t=await $t(e,{agent:Ot});if(!t.ok)throw new Error(`Failed to fetch from ${p.cyan(e)}.
|
|
7
|
+
${t.statusText}`);return await t.json()}catch(e){i.error(`
|
|
8
|
+
`),A(e)}}async function ge(e,t){try{let r=R.getBearerToken();return await Promise.all(e.map(async o=>{let c=Ft(o),s={};r&&(s.Authorization=`Bearer ${r}`);let a=await $t(c,{agent:Ot,headers:s});if(!a.ok){let m={400:"Bad request",401:"Unauthorized",403:"Forbidden",404:"Not found",500:"Internal server error"};if(a.status===401)throw R.clear(),new Error(`You are not authorized to access the component at ${p.cyan(c)}.
|
|
9
|
+
Please run ${p.cyan("@tiptap/cli login")} to log in to your Tiptap Cloud account.`);if(a.status===404)throw new Error(`The component at ${p.cyan(c)} was not found.
|
|
10
|
+
It may not exist at the registry. Please make sure it is a valid component.`);if(a.status===403)throw new Error(`You do not have access to the component at ${p.cyan(c)}.
|
|
13
11
|
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
|
|
15
|
-
${
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
${
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
${
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
Please upgrade your subscription or use a component available in your current plan.`);let w=await a.json(),g=w&&typeof w=="object"&&"error"in w?w.error:a.statusText||m[a.status];throw new Error(`Failed to fetch from ${p.cyan(c)}.
|
|
13
|
+
${g}`)}return a.json()}))}catch(r){return i.error(`
|
|
14
|
+
`),A(r),[]}}async function Ut(e,t){try{if(!await pe(t))return null;e.includes("index")&&e.unshift("index");let n=await tt(e,t),o=await ge(n,t),c=qr.array(X).parse(o);if(!c)return null;let a=(await O(t.resolvedPaths.cwd))?.framework.name,m=et.all(c.map(v=>v.dependencies??[])),w=et.all(c.map(v=>v.devDependencies??[])),g=Xr(w,a);return jt.parse({dependencies:m,devDependencies:g,files:et.all(c.map(v=>v.files??[]))})}catch(r){return A(r),null}}async function Hr(e,t){let r=new Set,n=[];async function o(c){let s=Ft(Dt(c)?c:`components/${c}.json`);if(!r.has(s)){r.add(s);try{let[a]=await ge([s],t),m=X.parse(a);if(n.push(s),m.registryDependencies)for(let w of m.registryDependencies)await o(w)}catch(a){console.error(`Error fetching or parsing registry item at ${c}:`,a)}}}return await o(e),Array.from(new Set(n))}async function tt(e,t){let r=[];for(let n of e){let o=await Hr(n,t);r.push(...o)}return Array.from(new Set(r))}function Ft(e){if(Dt(e))return new URL(e).toString();if(!oe)throw new Error("No registry URL found");if(e==="index.json")return`${oe}/r/${e}`;if(e.startsWith("components/")){let t=e.replace("components/","").replace(".json","");return`${oe}/api/registry/components/${t}`}return`${oe}/${e}`}function Dt(e){try{return new URL(e),!0}catch{return!1}}function Mt(){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 Lt(e){let t=new Map;return e.forEach(r=>{r.registryDependencies&&r.registryDependencies.forEach(n=>{t.set(n,r)})}),t}function Xr(e,t){let r=Array.isArray(e)?e:[];if(!r.length)return[];let n=r.map(o=>String(o));if(t){let o=n.includes("sass"),c=n.includes("sass-embedded");if(o||c){let s=[...n],a=[h.astro.name,h.laravel.name,h.vite.name,h["tanstack-start"].name,h["react-router"].name],m=[h["next-app"].name,h["next-pages"].name];return a.includes(t)?s=s.filter(w=>w!=="sass"):m.includes(t)&&(s=s.filter(w=>w!=="sass-embedded")),s}}return n}import Zr from"chalk";import Qr from"ora";function T(e,t){return Qr({text:Zr.bold(e),isSilent:t?.silent})}import{detect as en}from"@antfu/ni";async function z(e,{withFallback:t}={withFallback:!1}){let r=await en({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{execa as tn}from"execa";async function rt(e,t,r){if(e=Array.from(new Set(e)),!e?.length)return;r={silent:!1,...r};let n=T("Installing dependencies.",{silent:r.silent}).start(),o=await z(t.resolvedPaths.cwd);await tn(o,[o==="npm"?"install":"add",...o==="npm"?["--save"]:[],...e],{cwd:t.resolvedPaths.cwd}),n.stopAndPersist({symbol:p.cyan("\u2714")})}import{existsSync as Vt,promises as nt}from"fs";import B,{basename as xn}from"path";import{promises as un}from"fs";import{tmpdir as dn}from"os";import zt from"path";var ve=async({sourceFile:e,config:t})=>{let r=e.getImportDeclarations();for(let n of r){let o=rn(n.getModuleSpecifierValue(),t);o&&n.setModuleSpecifier(o)}return e};function rn(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 nn}from"@babel/core";import{parse as on}from"@babel/parser";import sn from"@babel/plugin-transform-typescript";import*as Pe from"recast";var an={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"]},Bt=async({sourceFile:e,config:t})=>{let r=e.getFullText();if(t.tsx)return r;let n=Pe.parse(r,{parser:{parse:c=>on(c,an)}}),o=nn(n,r,{cloneInputAst:!1,code:!1,ast:!0,plugins:[sn],configFile:!1});if(!o||!o.ast)throw new Error("Failed to transform JSX");return Pe.print(o.ast).code};import{SyntaxKind as cn}from"ts-morph";var pn=/^["']use client["']$/g,Te=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let r=e.getFirstChildByKind(cn.ExpressionStatement);return r&&pn.test(r.getText())&&r.remove(),e};import{Node as be,SyntaxKind as I}from"ts-morph";var ln=[{name:"cta",matchType:"contains",caseSensitive:!1},{name:"initialContent",matchType:"exact",caseSensitive:!0,onlyInFiles:["notion-like-editor.tsx"]},{name:"JSONContent",matchType:"exact",caseSensitive:!0,onlyInFiles:["notion-like-editor.tsx"]},{name:"onCreate",matchType:"exact",caseSensitive:!0,onlyInFiles:["notion-like-editor.tsx"]},{name:"getDocumentId",matchType:"exact",caseSensitive:!0,onlyInFiles:["notion-like-editor.tsx"]}];function j(e,t,r){return t.some(n=>{if(n.onlyInFiles&&!n.onlyInFiles.some(s=>r.endsWith(s)))return!1;let o=n.caseSensitive?e:e.toLowerCase(),c=n.caseSensitive?n.name:n.name.toLowerCase();switch(n.matchType){case"exact":return o===c;case"contains":return o.includes(c);case"startsWith":return o.startsWith(c);case"endsWith":return o.endsWith(c);case"regex":return n.pattern?new RegExp(n.pattern,n.caseSensitive?"":"i").test(o):!1;default:return!1}})}function mn(e,t){let r=t.name;return r===h["next-app"].name||r===h["next-pages"].name?`NEXT_PUBLIC_${e}`:r===h.astro.name?`PUBLIC_${e}`:r===h.vite.name||r===h["tanstack-start"].name||r===h["react-router"].name?`VITE_${e}`:(r===h.laravel.name||r===h.manual.name,e)}function Wt(e){return e.replace(/^(NEXT_PUBLIC_|VITE_|PUBLIC_)/,"")}async function fn(e,t){let r=await O(t.resolvedPaths.cwd);if(!r)return;let n=[],o=e.getDescendantsOfKind(I.BinaryExpression);for(let a of o)if(a.getOperatorToken().getKind()===I.BarBarToken){let w=a.getLeft().getText();if(w.match(/^process\.env\.[A-Z_]+$/)){let g=w.match(/process\.env\.([A-Z_]+)/);if(g&&g[1]){let v=Wt(g[1]),f=r.framework.name,y;f===h.astro.name?y=`import.meta.env.PUBLIC_${v}`:f===h.vite.name||f===h["tanstack-start"].name||f===h["react-router"].name?y=`import.meta.env.VITE_${v}`:f===h["next-app"].name||f===h["next-pages"].name?y=`process.env.NEXT_PUBLIC_${v}`:y=`process.env.${v}`;let $=a.getRight().getText(),b=`${y} || ${$}`;n.push({node:a,newText:b})}}}let c=e.getDescendantsOfKind(I.CallExpression);for(let a of c){let w=a.getExpression().getText();if(w.match(/^alert$/)){let g=a.getArguments();if(g.length>0){let f=g[0].getText();if(f.includes("TIPTAP_COLLAB_TOKEN")||f.includes("COLLAB_DOC_PREFIX")||f.includes("TIPTAP_AI_TOKEN")){let y=f,$=["COLLAB_DOC_PREFIX","TIPTAP_COLLAB_APP_ID","TIPTAP_COLLAB_TOKEN","TIPTAP_AI_APP_ID","TIPTAP_AI_TOKEN","USE_JWT_TOKEN_API_ENDPOINT"];for(let b of $){let F=mn(b,r.framework);y=y.replace(new RegExp(b,"g"),F)}if(y!==f){let b=`${w}(${y})`;n.push({node:a,newText:b})}}}}}let s=e.getDescendantsOfKind(I.PropertyAccessExpression);for(let a of s){let m=a.getText();if(m.match(/^process\.env\.[A-Z_]+$/)){if(a.getParent()?.getKind()===I.BinaryExpression)continue;let g=m.match(/process\.env\.([A-Z_]+)/);if(g&&g[1]){let v=Wt(g[1]),f=r.framework.name,y;f===h.astro.name?y=`import.meta.env.PUBLIC_${v}`:f===h.vite.name||f===h["tanstack-start"].name||f===h["react-router"].name?y=`import.meta.env.VITE_${v}`:f===h["next-app"].name||f===h["next-pages"].name?y=`process.env.NEXT_PUBLIC_${v}`:y=`process.env.${v}`,n.push({node:a,newText:y})}}}for(let{node:a,newText:m}of n)try{a.replaceWithText(m)}catch(w){console.warn(`Skipping transformation of node: ${w}`)}}var Se=async({sourceFile:e,config:t})=>{let r=ln,n=e.getFilePath(),o=[],c=e.getImportDeclarations();for(let l of c){let u=l.getModuleSpecifierValue();if(r.some(P=>j(u,[P],n))){o.push({node:l,action:"remove"});continue}let x=l.getDefaultImport();if(x&&j(x.getText(),r,n)){o.push({node:l,action:"remove"});continue}let d=l.getNamedImports(),k=d.filter(P=>j(P.getName(),r,n));k.length>0&&(k.forEach(N=>o.push({node:N,action:"remove"})),d.filter(N=>!k.includes(N)).length===0&&!x&&o.push({node:l,action:"remove"}))}let s=e.getExportDeclarations();for(let l of s){let u=l.getNamedExports(),x=u.filter(d=>j(d.getName(),r,n));x.length>0&&(x.forEach(k=>o.push({node:k,action:"remove"})),u.filter(k=>!x.includes(k)).length===0&&o.push({node:l,action:"remove"}))}let a=e.getVariableStatements();for(let l of a){let u=l.getDeclarations(),x=u.filter(d=>j(d.getName(),r,n));x.length>0&&(u.length===x.length?o.push({node:l,action:"remove"}):x.forEach(d=>o.push({node:d,action:"remove"})))}let m=e.getFunctions();for(let l of m){let u=l.getName();u&&j(u,r,n)&&o.push({node:l,action:"remove"})}let w=e.getInterfaces();for(let l of w){let u=l.getName();j(u,r,n)&&o.push({node:l,action:"remove"})}let g=e.getTypeAliases();for(let l of g){let u=l.getName();j(u,r,n)&&o.push({node:l,action:"remove"})}let v=e.getDescendantsOfKind(I.PropertySignature);for(let l of v){let u=l.getName();u&&j(u,r,n)&&o.push({node:l,action:"remove"})}let f=e.getDescendantsOfKind(I.JsxElement);for(let l of f){let u=l.getOpeningElement().getTagNameNode().getText();j(u,r,n)&&o.push({node:l,action:"replace",newText:""})}let y=e.getDescendantsOfKind(I.JsxSelfClosingElement);for(let l of y){let u=l.getTagNameNode().getText();j(u,r,n)&&o.push({node:l,action:"replace",newText:""})}let $=e.getDescendantsOfKind(I.PropertyAssignment);for(let l of $){let u=l.getName();u&&j(u,r,n)&&o.push({node:l,action:"remove"})}let b=e.getDescendantsOfKind(I.JsxAttribute);for(let l of b){let u=l.getNameNode().getText();u&&j(u,r,n)&&o.push({node:l,action:"remove"})}let F=e.getDescendantsOfKind(I.Parameter);for(let l of F){let u=l.getName();if(u&&j(u,r,n)){let x=l.getParent();if(x&&(be.isFunctionDeclaration(x)||be.isArrowFunction(x)||be.isFunctionExpression(x)||be.isMethodDeclaration(x))){let d=x.getParameters(),k=d.indexOf(l);if(k!==-1){if(k===d.length-1&&k>0){let P=l.getPreviousSibling();P?.getKind()===I.CommaToken&&o.push({node:P,action:"remove"})}else{let P=l.getNextSibling();P?.getKind()===I.CommaToken&&o.push({node:P,action:"remove"})}o.push({node:l,action:"remove"})}}}}let L=e.getDescendantsOfKind(I.CallExpression);for(let l of L){let u=l.getArguments();for(let x=0;x<u.length;x++){let d=u[x],k=d.getText();if(j(k,r,n)){if(x===u.length-1){let P=d.getPreviousSibling();P&&P.getKind()===I.CommaToken&&o.push({node:P,action:"remove"})}else{let P=d.getNextSibling();P&&P.getKind()===I.CommaToken&&o.push({node:P,action:"remove"})}o.push({node:d,action:"remove"})}}}let _=e.getDescendantsOfKind(I.BindingElement);for(let l of _){let u=l.getName();if(u&&j(u,r,n)){let x=l.getParent();if(x){let d=x.getDescendantsOfKind(I.BindingElement);if(d.indexOf(l)===d.length-1){let P=l.getPreviousSibling();P?.getKind()===I.CommaToken&&o.push({node:P,action:"remove"})}else{let P=l.getNextSibling();P?.getKind()===I.CommaToken&&o.push({node:P,action:"remove"})}}o.push({node:l,action:"remove"})}}let W=e.getDescendantsOfKind(I.Identifier);for(let l of W){let u=l.getText();if(j(u,r,n)){let x=l.getParent();if(x){let d=x.getKind();if(d===I.CallExpression){let k=x;k.getExpression()===l?o.push({node:k,action:"remove"}):k.getArguments().findIndex(te=>te===l)!==-1&&o.push({node:l,action:"remove"})}if(d===I.PropertyAccessExpression){let k=x;k.getName()===u&&o.push({node:k,action:"remove"})}if((d===I.VariableDeclaration||d===I.BinaryExpression||d===I.IfStatement||d===I.ConditionalExpression)&&o.push({node:l,action:"remove"}),d===I.PropertyAssignment){let k=x;k.getInitializer()===l&&o.push({node:k,action:"remove"})}}}}let J=e.getDescendantsOfKind(I.ShorthandPropertyAssignment);for(let l of J){let u=l.getName();u&&j(u,r,n)&&o.push({node:l,action:"remove"})}await fn(e,t),o.sort((l,u)=>{let x=l.node.getStart?.()??0;return(u.node.getStart?.()??0)-x});for(let{node:l,action:u,newText:x}of o)try{if(l.wasForgotten?.()===!0)continue;u==="remove"?typeof l.remove=="function"&&l.remove():u==="replace"&&x!==void 0&&l.replaceWithText(x)}catch{}return e};import{Project as gn,ScriptKind as hn}from"ts-morph";var yn=new gn({compilerOptions:{}});async function wn(e){let t=await un.mkdtemp(zt.join(dn(),"tiptap-"));return zt.join(t,e)}async function Kt(e,t=[ve,Te,Se]){if(e.filename.endsWith(".scss")||e.filename.endsWith(".css")||e.filename.endsWith(".json"))return e.raw;let r=await wn(e.filename),n=yn.createSourceFile(r,e.raw,{scriptKind:hn.TSX});for(let o of t)await o({sourceFile:n,...e});return e.transformJsx?await Bt({sourceFile:n,...e}):n.getText()}import{confirm as kn}from"@inquirer/prompts";import Ie from"chalk";async function ot(e,t,r){let n={filesCreated:[],filesUpdated:[],filesSkipped:[],errors:[]};if(!e?.length)return n;r={overwrite:!1,force:!1,silent:!1,...r};let o=T("Updating files.",{silent:r.silent})?.start();try{let[c]=await Promise.all([O(t.resolvedPaths.cwd)]);for(let s of e)try{if(!s.content)continue;let a;try{a=Sn(s,t,{isSrcDir:c?.isSrcDir,framework:c?.framework.name,commonRoot:Pn(e.map(f=>f.path),s.path)})}catch(f){n.errors.push({file:s.path,error:`Failed to resolve file path: ${f instanceof Error?f.message:String(f)}`});continue}if(!a)continue;let m=xn(s.path),w=B.dirname(a);t.tsx||(a=a.replace(/\.tsx?$/,f=>f===".tsx"?".jsx":".js"));let g=!1;try{g=Vt(a)}catch(f){n.errors.push({file:a,error:`Failed to check if file exists: ${f instanceof Error?f.message:String(f)}`});continue}let v;try{v=await Kt({filename:s.path,raw:s.content,config:t,transformJsx:!t.tsx},[ve,Te,Se])}catch(f){n.errors.push({file:a,error:`Failed to transform content: ${f instanceof Error?f.message:String(f)}`});continue}if(g)try{let f=await nt.readFile(a,"utf-8"),[y,$]=await Promise.all([Jt(f),Jt(v)]);if(y===$){n.filesSkipped.push(B.relative(t.resolvedPaths.cwd,a));continue}}catch(f){n.errors.push({file:a,error:`Failed to read or normalize existing file: ${f instanceof Error?f.message:String(f)}`});continue}if(g&&!r.overwrite){o?.stop(),r.rootSpinner&&r.rootSpinner?.stop();try{if(!await kn({message:Ie.white(`The file ${p.cyan(m)} already exists. Would you like to overwrite?`),theme:{prefix:Ie.hex("#46caff")("?"),style:{answer:y=>Ie.white(y)}}})){n.filesSkipped.push(B.relative(t.resolvedPaths.cwd,a)),r.rootSpinner&&r.rootSpinner.start();continue}}catch(f){n.errors.push({file:a,error:`Failed to get user confirmation: ${f instanceof Error?f.message:String(f)}`});continue}finally{o?.start(),r.rootSpinner&&r.rootSpinner.start()}}try{Vt(w)||await nt.mkdir(w,{recursive:!0}),await nt.writeFile(a,v,"utf-8"),g?n.filesUpdated.push(B.relative(t.resolvedPaths.cwd,a)):n.filesCreated.push(B.relative(t.resolvedPaths.cwd,a))}catch(f){n.errors.push({file:a,error:`Failed to write file: ${f instanceof Error?f.message:String(f)}`})}}catch(a){n.errors.push({file:s.path||"unknown",error:`Unexpected error processing file: ${a instanceof Error?a.message:String(a)}`})}}catch(c){i.error(`An error occurred while updating files: ${c instanceof Error?c.message:String(c)}`)}finally{if(!(n.filesCreated.length||n.filesUpdated.length)&&!n.filesSkipped.length&&o?.info("No files updated."),n.filesCreated.length){if(o?.stopAndPersist({symbol:p.cyan("\u2714"),text:Ie.bold(`Created ${n.filesCreated.length} ${n.filesCreated.length===1?"file":"files"}:`)}),!r.silent)for(let s of n.filesCreated)i.log(` - ${s}`)}else o?.stop();if(n.filesUpdated.length&&(T(`Updated ${n.filesUpdated.length} ${n.filesUpdated.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let s of n.filesUpdated)i.log(` - ${s}`);if(n.filesSkipped.length&&(T(`Skipped ${n.filesSkipped.length} ${n.filesUpdated.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:r.silent})?.info(),!r.silent))for(let s of n.filesSkipped)i.log(` - ${s}`);if(n.errors.length&&(T(`Failed to process ${n.errors.length} ${n.errors.length===1?"file":"files"}:`,{silent:r.silent})?.fail(),!r.silent))for(let{file:s,error:a}of n.errors)i.error(` - ${s}: ${a}`);r.silent||i.break()}return n}function vn(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 Pn(e,t){let r=e.map(s=>s.replace(/^\//,"")),n=t.replace(/^\//,""),o=n.split("/").slice(0,-1).join("/");if(!o)return"";let c=o.split("/");for(let s=c.length;s>0;s--){let a=c.slice(0,s).join("/");if(r.some(w=>w!==n&&w.startsWith(a+"/")))return"/"+a}return"/"+o}async function Jt(e){return e.replace(/\r\n/g,`
|
|
15
|
+
`).trim()}function Tn(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 bn(e,t){let r=e.replace(/^\/|\/$/g,""),n=t.replace(/^\/|\/$/g,""),o=r.split("/"),c=n.split("/"),s=c[c.length-1],a=o.findIndex(m=>m===s);return a===-1?o[o.length-1]:o.slice(a+1).join("/")}function Sn(e,t,r){if(!e.target&&e.path.includes("tiptap-templates/")&&e.type!=="registry:page"){let c=e.path.match(/tiptap-templates\/([^/]+)\/(.*)/);if(c){let[,s,a]=c;if(a.startsWith("components/")){let m=a.replace("components/","");return B.join(t.resolvedPaths.components,"tiptap-templates",s,m)}return B.join(t.resolvedPaths.components,"tiptap-templates",s,a)}}if(e.target&&e.path.includes("tiptap-templates/")&&e.target.includes("/data/")){let c=e.path.match(/tiptap-templates\/([^/]+)\//);if(c){let s=c[1],a=e.target.split("/data/")[1];return B.join(t.resolvedPaths.components,"tiptap-templates",s,"data",a)}}if(e.target){if(e.target.startsWith("~/"))return B.join(t.resolvedPaths.cwd,e.target.replace("~/",""));let c=e.target;return e.type==="registry:page"&&(c=Tn(c,r.framework),!c)?"":r.isSrcDir?B.join(t.resolvedPaths.cwd,"src",c.replace("src/","")):B.join(t.resolvedPaths.cwd,c.replace("src/",""))}let n=vn(e,t),o=bn(e.path,n);return B.join(n,o)}import{z as Cn}from"zod";import{execa as In}from"execa";async function it(e,t,r){if(e=Array.from(new Set(e)),!e?.length)return;r={silent:!1,...r};let n=T("Installing development dependencies.",{silent:r.silent})?.start(),o=await z(t.resolvedPaths.cwd);n?.start(),await In(o,[o==="npm"?"install":"add",o==="npm"?"--save-dev":"-D",...e],{cwd:t.resolvedPaths.cwd}),n?.stopAndPersist({symbol:p.cyan("\u2714")})}async function Ce(e,t,r){r={overwrite:!1,silent:!1,isNewProject:!1,...r};let n=await It(t);return n&&n.tiptapUi&&n.tiptapUi.resolvedPaths.cwd!==t.resolvedPaths.cwd?await An(e,t,n,{...r}):await En(e,t,r)}async function En(e,t,r){let n=T("Checking registry.",{silent:r.silent}).start(),o=await Ut(e,t);return o?(n.stopAndPersist({symbol:p.cyan("\u2714")}),await rt(o.dependencies,t,{silent:r.silent}),await it(o.devDependencies,t,{silent:r.silent}),await ot(o.files,t,{overwrite:r.overwrite,silent:r.silent})):(n?.fail(),A(new Error("Failed to fetch components from registry.")))}async function An(e,t,r,n){let o=T("Checking registry.",{silent:n.silent}).start(),c=await tt(e,t),s=await ge(c,t),a=Cn.array(X).parse(s);if(!a.length)return o?.fail(),A(new Error("Failed to fetch components from registry."));o.stopAndPersist({symbol:p.cyan("\u2714")});let m=Lt(a),w=Mt(),g=[],v=[],f=[],y=T("Installing components.")?.start();for(let b of a){let F=w.get(b.type),L=m.get(b.name);if(!F)continue;let _=(b.type==="registry:ui"||L?.type==="registry:ui")&&r.tiptapUi||t;if(!_.resolvedPaths.tiptapUi)continue;let W=Xe(t.resolvedPaths.cwd,_.resolvedPaths.tiptapUi),J=await He(W,_.resolvedPaths.cwd)??_.resolvedPaths.cwd;await rt(b.dependencies||[],_,{silent:!0}),await it(b.devDependencies||[],_,{silent:!0});let l=await ot(b.files||[],_,{overwrite:n.overwrite,silent:!0,rootSpinner:y});if(l.errors&&l.errors.length>0){T(`Encountered ${l.errors.length} errors:`,{silent:n.silent})?.fail();for(let{file:u,error:x}of l.errors)i.error(` - ${u}: ${x}`)}g.push(...l.filesCreated.map(u=>le.relative(W,le.join(J,u)))),v.push(...l.filesUpdated.map(u=>le.relative(W,le.join(J,u)))),f.push(...l.filesSkipped.map(u=>le.relative(W,le.join(J,u))))}if(y.stopAndPersist({symbol:p.cyan("\u2714")}),g.sort(),v.sort(),f.sort(),!(g.length||v.length)&&!f.length&&T("No files updated.",{silent:n.silent})?.info(),g.length){T(`Created ${g.length} ${g.length===1?"file":"files"}:`,{silent:n.silent})?.stopAndPersist({symbol:p.cyan("\u2714")});for(let b of g)i.log(` - ${b}`)}if(v.length){T(`Updated ${v.length} ${v.length===1?"file":"files"}:`,{silent:n.silent})?.info();for(let b of v)i.log(` - ${b}`)}if(f.length){T(`Skipped ${f.length} ${f.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:n.silent})?.info();for(let b of f)i.log(` - ${b}`)}return{filesCreated:g,filesUpdated:v,filesSkipped:f}}function st(e){return e.split(/[-_]/).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}import Re from"node-fetch";import{HttpsProxyAgent as Mn}from"https-proxy-agent";import Ln from"chalk";import D from"fs-extra";import ie from"path";import Rn from"os";import{execa as Z}from"execa";import Yt from"yaml";var Y="https://registry.tiptap.dev/",se="//registry.tiptap.dev/:_authToken",me="@tiptap-pro:registry",fe="@tiptap-cloud:registry";async function Nn(e){try{let t=ie.join(e,".gitignore"),r=".npmrc",n="";if(await D.pathExists(t)&&(n=await D.readFile(t,"utf8")),!n.split(`
|
|
16
|
+
`).some(s=>s.trim()===r||s.trim()==="/.npmrc"||s.trim()==="**/.npmrc")){let s=n.trim()?`${n}
|
|
17
|
+
|
|
18
|
+
# Authentication tokens
|
|
19
|
+
${r}
|
|
20
|
+
`:`# Authentication tokens
|
|
21
|
+
${r}
|
|
22
|
+
`;await D.writeFile(t,s)}}catch(t){i.warn(`Could not update .gitignore: ${t instanceof Error?t.message:"Unknown error"}`)}}async function Ee(e,t,r){try{let n=!1;switch(t){case"npm":await jn(e,r),n=!0;break;case"yarn":await $n(e,r),n=await D.pathExists(ie.join(r,".npmrc"));break;case"pnpm":case"bun":await Gt(ie.join(r,".npmrc"),e),n=!0;break}return n&&await Nn(r),!0}catch(n){return i.error(`Error saving auth token: ${n instanceof Error?n.message:"Unknown error"}`),!1}}async function jn(e,t){await Z("npm",["config","set",me,Y,"--location=project"],{cwd:t}),await Z("npm",["config","set",fe,Y,"--location=project"],{cwd:t}),await Z("npm",["config","set",se,e,"--location=project"],{cwd:t})}async function $n(e,t){try{let{stdout:r}=await Z("yarn",["--version"],{cwd:t});r.startsWith("1.")?(await Z("yarn",["config","set",me,Y,"--location=project"],{cwd:t}),await Z("yarn",["config","set",fe,Y,"--location=project"],{cwd:t}),await Z("yarn",["config","set",se,e,"--location=project"],{cwd:t})):await On(e,t)}catch{await Gt(ie.join(t,".npmrc"),e)}}async function On(e,t){let r=ie.join(t,".yarnrc.yml"),n={};if(D.existsSync(r)){let o=await D.readFile(r,"utf8");try{n=Yt.parse(o)||{}}catch{}}n.npmScopes||(n.npmScopes={}),n.npmScopes["tiptap-pro"]={npmRegistryServer:Y,npmAuthToken:e},await D.writeFile(r,Yt.stringify(n))}async function Gt(e,t){let r="";D.existsSync(e)&&(r=await D.readFile(e,"utf8"));let{lines:n,processedKeys:o}=_n(r,t);o.has(me)||n.push(`${me}=${Y}`),o.has(fe)||n.push(`${fe}=${Y}`),o.has(se)||n.push(`${se}=${t}`),n.length>0&&n[n.length-1]!==""&&n.push(""),await D.writeFile(e,n.join(`
|
|
23
|
+
`))}function _n(e,t){let r=[],n=new Set,o=e.split(`
|
|
24
|
+
`);for(let c of o){let s=c.trim();if(!s){r.push(c);continue}if(s.startsWith("#")){r.push(c);continue}let a=c.indexOf("=");if(a!==-1){let m=c.substring(0,a).trim();m===me?(r.push(`${me}=${Y}`),n.add(m)):m===fe?(r.push(`${fe}=${Y}`),n.add(m)):m===se?(r.push(`${se}=${t}`),n.add(m)):r.push(c)}else r.push(c)}return{lines:r,processedKeys:n}}async function Ae(e,t){try{let r=await Un(t);return r||(e==="npm"?await Fn(t):await Dn())}catch{return null}}async function Un(e){let t=ie.join(e,".npmrc");if(D.existsSync(t)){let r=await D.readFile(t,"utf8");return qt(r)}return null}async function Fn(e){let{stdout:t}=await Z("npm",["config","get",se],{cwd:e});return t&&t!=="undefined"?t.trim():null}async function Dn(){let e=ie.join(Rn.homedir(),".npmrc");if(D.existsSync(e)){let t=await D.readFile(e,"utf8");return qt(t)}return null}function qt(e){let t=e.split(`
|
|
25
|
+
`).filter(n=>n.startsWith("//registry.tiptap.dev/:_authToken="));return t.length===0?null:t[0].split("=")[1]?.trim()||null}var Ne=`${oe}/api/cli/v1`,je=process.env.https_proxy?new Mn(process.env.https_proxy):void 0;async function Ht({email:e,password:t,packageManager:r,writeConfig:n=!0,cwd:o}){let c=T("Authenticating with Tiptap registry...")?.start();try{if(!e||!t)return c?.fail("Authentication failed"),{success:!1,error:"Invalid credentials"};let s=await Bn(e,t),a=[];try{let m=await Re(`${Ne}/plans`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s.bearerToken}`},agent:je});m.ok&&(a=(await m.json()).map(g=>g.name))}catch{i.warn("Could not fetch user plans")}return R.setBearerToken(s.bearerToken,{email:e,plans:a}),R.setAuthToken(s.authToken),n&&!await Ee(s.authToken,r,o)?(c?.fail("Failed to save authentication token"),{success:!1,error:"Could not save authentication token"}):(c?.stopAndPersist({symbol:p.cyan("\u2714"),text:Ln.bold("Authentication successful")}),{success:!0,tokens:s})}catch(s){return c?.fail("Authentication failed"),{success:!1,error:s instanceof Error?s.message:"Unknown error during authentication"}}}async function Bn(e,t){let r=await Re(`${Ne}/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e,password:t}),agent:je});if(!r.ok)throw new Error(`Error ${r.status}: ${r.statusText}`);let n=await r.json();return{bearerToken:n.token,authToken:n.authToken}}async function he(){try{let e=R.getBearerToken();if(!e)return{authenticated:!1};if(!R.isValidToken())return{authenticated:!1};let t=[];try{let o=await Re(`${Ne}/plans`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},agent:je});if(!o.ok)return R.clear(),{authenticated:!1};t=(await o.json()).map(a=>a.name);let s=R.getUserInfo();R.setBearerToken(e,{email:s.email,plans:t})}catch{return R.clear(),{authenticated:!1}}let r=R.getUserInfo(),n=R.getTokenExpiration();return{authenticated:!0,user:r.email||"unknown user",plans:t,expires:n,token:e}}catch(e){return i.error(`Auth status check error: ${e instanceof Error?e.message:"Unknown error"}`),{authenticated:!1}}}async function Xt(){try{let e=R.getBearerToken();return e&&((await Re(`${Ne}/logout`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},agent:je})).ok||i.warn("Logout API call failed, but clearing local tokens anyway")),R.clear(),{success:!0}}catch(e){return R.clear(),{success:!1,error:e instanceof Error?e.message:"Unknown error during logout"}}}import{Command as at}from"commander";import{execa as Wn}from"execa";import{z as ue}from"zod";import{confirm as zn,input as Kn,password as Vn}from"@inquirer/prompts";import Jn from"chalk";var Zt=ue.object({cwd:ue.string(),email:ue.string().optional(),password:ue.string().optional(),writeConfig:ue.boolean().optional(),showMessage:ue.boolean().default(!0)}),Yn=(e,t={})=>Kn({message:e,required:t.required??!0,validate:t.validate??(r=>r?!0:"This field is required"),theme:{prefix:{done:p.cyan("\u2713"),idle:"?"}}}),Gn=(e,t={})=>Vn({message:e,validate:t.validate??(r=>r?!0:"This field is required"),mask:"*",theme:{prefix:{done:p.cyan("\u2713"),idle:"?"}}}),ct=(e,t=!0)=>zn({message:e,default:t,theme:{prefix:{done:p.cyan("\u2713"),idle:"?"}}});function qn(e){switch(e){case"npm":return".npmrc (via npm config)";case"yarn":return".yarnrc.yml or .npmrc (depending on Yarn version)";case"pnpm":case"bun":return".npmrc";default:return"configuration file"}}async function Hn(e,t,r){i.log(`To use this token, add it to your project's package manager configuration in ${p.cyan(r)}:`),e==="npm"?(i.log("Run these commands in your project directory:"),i.log(" npm config set @tiptap-pro:registry https://registry.tiptap.dev/"),i.log(` npm config set //registry.tiptap.dev/:_authToken ${t}`),i.log(`
|
|
26
|
+
Or add to your project's .npmrc file:`),i.log(" @tiptap-pro:registry=https://registry.tiptap.dev/"),i.log(` //registry.tiptap.dev/:_authToken=${t}`)):e==="yarn"?await Xn(r)?(i.log("Run these commands in your project directory:"),i.log(" yarn config set @tiptap-pro:registry https://registry.tiptap.dev/"),i.log(` yarn config set //registry.tiptap.dev/:_authToken ${t}`)):(i.log("Add to your project's .yarnrc.yml file:"),i.log(`npmScopes:
|
|
27
|
+
tiptap-pro:
|
|
28
|
+
npmRegistryServer: "https://registry.tiptap.dev/"
|
|
29
|
+
npmAuthToken: "${t}"`)):(e==="pnpm"||e==="bun")&&(i.log("Add to your project's .npmrc file:"),i.log(p.cyan(`@tiptap-pro:registry=https://registry.tiptap.dev/
|
|
30
|
+
//registry.tiptap.dev/:_authToken=${t}`)))}async function Xn(e){try{return(await Wn("yarn",["--version"],{cwd:e})).stdout.startsWith("1.")}catch{return!1}}async function pt(e){let{email:t,password:r,writeConfig:n,showMessage:o}=e,{cwd:c}=e;t||(t=await Yn("Email:",{validate:m=>m?!0:"Please enter your email"})),r||(r=await Gn("Password:",{validate:m=>m?!0:"Please enter your password"})),(!t||!r)&&(i.error("Authentication cancelled"),process.exit(0));let s=await z(c);if(n===void 0){let m=qn(s);n=await ct(`Would you like to save the auth token to your ${m}?`),n===void 0&&(i.error("Authentication cancelled"),process.exit(0))}let a=await Ht({email:t,password:r,packageManager:s,writeConfig:n??!1,cwd:c});return a.success&&a.tokens?(n&&o?(i.log(`
|
|
31
|
+
Registry auth token saved to project directory for ${p.cyan(s)}`),i.log(`.npmrc file saved at: ${p.cyan(c)}`),i.log(`Project path: ${p.cyan(c)}`)):a.tokens.authToken&&o&&(i.log(`
|
|
32
|
+
Registry Auth Token: ${p.cyan(a.tokens.authToken)}`),i.log("This token should be added to your project's configuration:"),await Hn(s,a.tokens.authToken,c)),o&&i.log("Bearer token saved globally for CLI authentication"),!0):(i.error("Authentication failed: "+a.error),!1)}async function Zn(e){let t=await z(e),r=await he();if(r.authenticated){if(i.success(`Authenticated as ${p.cyan(r.user??"unknown user")}`),r.plans&&r.plans.length>0?r.plans.length===1?i.log(`Plan: ${p.cyan(r.plans[0])}`):i.log(`Plans: ${p.cyan(r.plans.join(", "))}`):i.log(`Plans: ${p.cyan("No active plans")}`),r.expires){let o=new Date(r.expires),c=new Date,s=Math.ceil((o.getTime()-c.getTime())/(1e3*60*60*24));s>30?i.log(`Token expires: ${p.cyan(o.toDateString())} (${s} days)`):s>0?i.log(`Token expires: ${p.yellow(o.toDateString())} (${s} days)`):i.log(`Token expires: ${p.red("Expired")}`)}if(r.token){let o=r.token.substring(0,10)+"...";i.log(`Bearer token: ${p.cyan(o)}`)}let n=await Ae(t,e);if(n){let o=n.substring(0,10)+"...";i.log(`Registry token: ${p.cyan(o)}`)}else i.log(`Registry token: ${p.yellow("Not configured for this project")}`),i.log(`Run ${p.cyan("@tiptap/cli login --write-config")} to configure for this project`)}else i.log("Not authenticated with Tiptap registry"),i.log(`Run ${p.cyan("@tiptap/cli login")} to authenticate`)}var Qt=new at().command("login").description("log in to your Tiptap Cloud account").option("-e, --email <email>","your account email").option("-p, --password <password>","your account password").option("--write-config","write the auth token to your package manager config",void 0).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async e=>{try{let t=Zt.parse(e);await pt(t)}catch(t){A(t)}}),er=new at().command("status").description("review your Tiptap Cloud authentication status").description("log out from your Tiptap registry account").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async e=>{let t=Zt.parse(e),{cwd:r}=t;try{await Zn(r)}catch(n){A(n)}}),tr=new at().command("logout").description("log out from your Tiptap registry account").action(async()=>{try{let e=T("Logging out...")?.start(),t=await Xt();t.success?e?.stopAndPersist({symbol:p.cyan("\u2714"),text:Jn.bold("Successfully logged out")}):(e?.fail("Logout failed"),i.error("Logout failed: "+t.error))}catch(e){A(e)}});import Qn from"chalk";function eo(e){return e.some(t=>t.plans&&t.plans.some(r=>Ze.includes(r)))}async function $e(e,t){try{if(!eo(e))return!0;if((await he()).authenticated){let n=await z(t);await to(n,t)||await ro(n,t)}else{if(i.log("You're trying to install a Pro component or template, but you're not logged in."),i.log(`Run ${p.cyan("@tiptap/cli login")} to log in or create a new account at https://cloud.tiptap.dev.`),!await ct("Would you like to login now?",!0))return i.log("Authentication cancelled. Cannot download paid components."),i.log("You can still download free components by running the command again and selecting only free components."),!1;if(!await pt({cwd:t,writeConfig:!0,showMessage:!1}))return!1}return!0}catch(r){return i.error(`Authentication check failed: ${r instanceof Error?r.message:"Unknown error"}`),!1}}async function to(e,t){try{return!!await Ae(e,t)}catch{return!1}}async function ro(e,t){let r=T("Creating registry configuration...")?.start();try{if(!(await he()).authenticated)return r?.fail("Cannot create configuration - user not authenticated"),!1;let o=R.getAuthToken();if(!o)return r?.fail("No authentication token found"),!1;if(!await Ee(o,e,t))return r?.fail("Failed to save authentication token"),!1;r?.stopAndPersist({symbol:p.cyan("\u2714"),text:Qn.bold(".npmrc created successfully")})}catch(n){r?.fail("Failed to create registry configuration"),i.error(`Configuration error: ${n instanceof Error?n.message:"Unknown error"}`)}}function no(e){let t=e.name;return t===h["next-app"].name||t===h["next-pages"].name?"NEXT_PUBLIC_":t===h.astro.name?"PUBLIC_":t===h.vite.name||t===h["tanstack-start"].name||t===h["react-router"].name?"VITE_":(t===h.laravel.name||t===h.manual.name,"")}function Oe(e){let t=no(e);i.break(),i.log(p.cyan("Set up your environment variables to connect to Tiptap Cloud:")),i.log(`- ${p.yellow(`${t}COLLAB_DOC_PREFIX`)} - Prefix for identifying collaborative documents`),i.log(`- ${p.yellow(`${t}TIPTAP_COLLAB_APP_ID`)} - Your collaboration App ID`),i.log(`- ${p.yellow(`${t}TIPTAP_COLLAB_TOKEN`)} - JWT token for accessing Collaboration services (do not use in production)`),i.log(`- ${p.yellow(`${t}TIPTAP_AI_APP_ID`)} - Your AI App ID`),i.log(`- ${p.yellow(`${t}TIPTAP_AI_TOKEN`)} - JWT token for accessing AI services (do not use in production)`),i.log(`Follow this guide: ${p.cyan("https://tiptap.dev/docs/ui-components/templates/notion-like-editor")}`)}function rr(){i.break(),i.log(p.cyan("Configure your styles to ensure your editor renders correctly:")),i.log("- Import the required CSS/SCSS files for your chosen components"),i.log("- Set up your CSS variables and theme configuration"),i.log(`Follow the complete style setup guide: ${p.cyan("https://tiptap.dev/docs/ui-components/getting-started/style")}`)}var so=ae.object({components:ae.array(ae.string()).optional(),cwd:ae.string(),path:ae.string().optional(),silent:ae.boolean(),overwrite:ae.boolean()}),ao=1e3,G={divider:p.gray("----------------------------------------------"),warning:p.magenta(" Some components (marked as Paid) require an active subscription!"),emptyRegistry:p.red(" No components or templates found"),operationCancelled:p.red(" Operation cancelled"),missingDirectory:p.red(" Missing directory or empty project. Please create a new project first.")},lt={icon:{cursor:p.cyan("\u276F"),checked:"\u25CF"},style:{highlight:e=>p.cyan(e)},prefix:{done:p.cyan("\u2714"),idle:"?"},helpMode:"always"},ir={...lt,icon:{...lt.icon,checked:"\u25CF",cursor:" "}};function co(e,t){return t?e.filter(r=>t.includes(r.name)):e}var mt=e=>`
|
|
33
|
+
${p.gray(e)}
|
|
34
|
+
`;function ft(e){for(let t=0;t<e;t++)process.stdout.write("\x1B[1A"),process.stdout.write("\x1B[2K")}var po=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 lo(e,t=!0){let r="What would you like to integrate:",n=mt(" Use arrow-keys \u25B2\u25BC / [Return] to submit"),o=[],c=e.ui.length===0&&e.nodes.length===0;if(e.templates.length===0||o.push({name:"Templates",value:"templates"}),c||o.push({name:"Components",value:"components"}),o.length===0)return i.break(),console.log(G.emptyRegistry),null;try{t&&console.log(G.divider);let a=await we({message:r,instructions:n,pageSize:ao,theme:lt,choices:o});return t&&console.log(G.divider),a}catch{return ft(4),console.log(G.operationCancelled),null}}async function mo(e,t){let r=[];if(!t)return r;let n=(o,c)=>{let s=o.filter(a=>t.includes(a.name));s.length>0&&(r.push(new nr(p.gray(` ${c}`))),s.forEach(a=>{let m=a.plans&&a.plans.length?a.plans.includes("light")?"Open Source":"Available from Start plan":"Free";r.push({name:`${st(a.name)} (${m})`,value:a.name})}),r.push(new nr(" ")))};return n(e.ui,"UI COMPONENTS"),n(e.nodes,"NODE COMPONENTS"),n(e.primitives,"PRIMITIVES"),r}async function fo(e,t){let r=mt(`${G.warning}
|
|
35
|
+
[Space] to select / [A] to toggle all / [I] to invert / [Return] to submit`),n=await mo(e,t);if(n.length===0)return[];try{let o=await or({message:"Select the components you want to add:",instructions:r,required:!0,pageSize:20,choices:n,theme:ir});return console.log(""),o}catch{return ft(25),console.log(G.operationCancelled),[]}}async function uo(e){try{let t=mt(`${G.warning}
|
|
36
|
+
[Space] to select / [A] to toggle all / [I] to invert / [Return] to submit`),r=e.map(n=>{let o=n.plans&&n.plans.length?n.plans.includes("light")?"Open Source":"Available from Start plan":"Free",c=n.description?` - ${n.description}`:"";return{name:`${st(n.name)}${c} (${o})`,value:n.name}});return await or({message:"Select the templates you want to add:",instructions:t,required:!0,pageSize:20,choices:r,theme:ir})}catch{return ft(25),console.log(G.operationCancelled),[]}}async function ut(e,t=!0){if(e.components?.length)return e.components;let r=await pe();if(!r)return i.break(),A(new Error("[prompts] - Failed to fetch registry index.")),[];let n=po(r),o=await lo(n,t);if(!o)return[];let c=r.filter(a=>!(a.hide??!1)).map(a=>a.name);if(!await _t())return i.break(),A(new Error("[prompts] - Failed to fetch free components.")),[];switch(o){case"components":return await fo(n,c)||[];case"templates":{let a=co(n.templates,c);return await uo(a)||[]}default:return[]}}var sr=new io().name("add").description("add a Tiptap UI component or template 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=so.parse({components:e,cwd:oo.resolve(t.cwd),...t});if(r.components?.length||(r.components=await ut(r)),!r.components?.length)return;let n=await pe();if(!n)throw new Error("Failed to fetch registry index.");let o=r.components.map(g=>{let v=n.find(f=>f.name===g);return{name:g,plans:v?.plans||[]}});await $e(o,r.cwd)||(i.error("Authentication failed. Cannot proceed with paid component download."),i.log("You can try again with only free components, or authenticate first."),process.exit(1));let{errors:s,config:a}=await Et(r);if(s[q]&&(i.warn(`
|
|
37
|
+
${G.missingDirectory}`),process.exit(0)),!a)throw new Error(`Failed to read config at ${p.cyan(r.cwd)}.`);if((await Ce(r.components,a,r))?.filesCreated.some(g=>g.includes("notion"))){let g=await O(r.cwd);g&&Oe(g.framework)}}catch(r){i.break(),A(r)}});import{Command as go}from"commander";var ar=new go().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=>{i.info("> project info"),console.log(await O(e.cwd)),i.break();try{let t=await K(e.cwd);i.info("> config"),console.log(t)}catch{i.info("")}});import fr from"path";import{Command as Uo}from"commander";import{confirm as Fo}from"@inquirer/prompts";import{z as ee}from"zod";import ho from"path";import cr from"fs-extra";import yo from"chalk";async function pr(e){let t={};if(!cr.existsSync(e.cwd)||!cr.existsSync(ho.resolve(e.cwd,"package.json")))return t[q]=!0,{errors:t,projectInfo:null};let r=T("Verifying framework.",{silent:e.silent}).start(),n=await O(e.cwd);(!n||n?.framework.name==="manual")&&(t[wt]=!0,r?.fail(),i.break(),n?.framework.links.installation&&i.error(`We could not detect a supported framework at ${p.cyan(e.cwd)}.
|
|
38
|
+
Visit ${p.cyan(n?.framework.links.installation)} to manually configure your project.
|
|
39
|
+
Once configured, you can use the cli to add components.`),i.break(),process.exit(0)),r?.stopAndPersist({symbol:p.cyan("\u2714"),text:yo.bold(`Verifying framework. Found ${p.cyan(n.framework.label)}.`)});let o=T("Validating import alias.",{silent:e.silent}).start();return n?.aliasPrefix?o?.stopAndPersist({symbol:p.cyan("\u2714")}):(t[Me]=!0,o?.fail()),Object.keys(t).length>0&&(t[Me]&&(i.break(),i.error("No import alias found in your tsconfig.json file."),n?.framework.links.installation&&i.error(`Visit ${p.cyan(n?.framework.links.installation)} to learn how to set an import alias.`)),i.break(),process.exit(0)),{errors:t,projectInfo:n}}import wo from"os";import Q from"path";import M from"fs-extra";import{execa as V}from"execa";import{parse as xo}from"jsonc-parser";import{input as ko}from"@inquirer/prompts";import vo from"chalk";var Po="https://codeload.github.com/shadcn-ui/ui/tar.gz/main",de={next:"next",vite:"vite","next-monorepo":"next-monorepo"},To=(e,t="")=>ko({message:e,default:t,required:!0,validate:r=>r.length>128?"Name should be less than 128 characters.":!0,theme:{prefix:{done:p.cyan("\u2714"),idle:"?"}}}),bo=async(e,t)=>{let r=`
|
|
40
|
+
${p.gray(" Use arrow-keys \u25B2\u25BC / [Return] to submit")}
|
|
41
|
+
`;return we({message:e,instructions:r,theme:{icon:{cursor:p.cyan("\u276F")},prefix:{done:p.cyan("\u2714"),idle:"?"},helpMode:"always"},choices:t})};async function lr(e){let t={srcDir:!1,...e},r=t.framework&&de[t.framework]?t.framework:"next",n="my-app",o="latest";if(!t.framework){let a=`The path ${p.cyan(t.cwd)} does not contain a package.json file.
|
|
42
|
+
Would you like to start a new project?`;r=await bo(a,[{name:"Next.js",value:"next"},{name:"Vite + React + TypeScript",value:"vite"}])}n=await To("What is your project named?",n);let c=await z(t.cwd,{withFallback:!0}),s=Q.join(t.cwd,n);return await So(t.cwd,n),r===de.next?await Io(s,{version:o,cwd:t.cwd,packageManager:c,srcDir:!!t.srcDir}):r===de.vite?await Co(s,{cwd:t.cwd,packageManager:c,projectName:n}):r===de["next-monorepo"]&&await No(s,{packageManager:c}),{projectPath:s,projectName:n,framework:r}}async function So(e,t){try{await M.access(e,M.constants.W_OK)}catch{i.break(),i.error(`The path ${p.cyan(e)} is not writable.`),i.error(`It is likely you do not have write permissions for this folder or the path ${p.cyan(e)} does not exist.`),i.break(),process.exit(0)}M.existsSync(Q.resolve(e,t,"package.json"))&&(i.break(),i.error(`A project with the name ${p.cyan(t)} already exists.`),i.error("Please choose a different name and try again."),i.break(),process.exit(0))}async function Io(e,t){let r=T("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 V("npx",[`create-next-app@${t.version}`,e,"--silent",...n],{cwd:t.cwd}),await mr(e),r.stopAndPersist({symbol:p.cyan("\u2714")})}catch{r?.fail("Something went wrong creating a new Next.js project."),i.break(),i.error("Something went wrong creating a new Next.js project. Please try again."),process.exit(0)}}async function Co(e,t){let r=T("Creating a new Vite + React + TypeScript project. This may take a few minutes.").start();try{await V("npm",["create","vite@latest",t.projectName,"--","--template","react-ts"],{cwd:t.cwd}),await V(t.packageManager,["install"],{cwd:e}),await Eo(e),await mr(e),r.stopAndPersist({symbol:p.cyan("\u2714")})}catch(n){r?.fail("Something went wrong creating a new Vite project."),A(n)}}async function Eo(e){try{await Ao(e),await Ro(e)}catch{i.warn("Failed to set up TypeScript path aliases, but project creation succeeded")}}async function Ao(e){let t=async r=>{let n=Q.join(e,r);if(!await M.pathExists(n))return;let o=await M.readFile(n,"utf-8"),c=xo(o);c.compilerOptions={...c.compilerOptions,baseUrl:".",paths:{...c.compilerOptions?.paths||{},"@/*":["./src/*"]}};let s=JSON.stringify(c,null,2);await M.writeFile(n,s)};await t("tsconfig.json"),await t("tsconfig.app.json")}async function Ro(e){let t=Q.join(e,"vite.config.ts"),n=(await M.readFile(t,"utf-8")).replace("import { defineConfig } from 'vite'",`import { defineConfig } from 'vite'
|
|
27
43
|
import path from 'path'`).replace("plugins: [react()]",`plugins: [react()],
|
|
28
44
|
resolve: {
|
|
29
45
|
alias: {
|
|
30
46
|
'@': path.resolve(__dirname, './src')
|
|
31
47
|
}
|
|
32
|
-
}`);await
|
|
48
|
+
}`);await M.writeFile(t,n)}async function No(e,t){let r=T("Creating a new Next.js monorepo. This may take a few minutes.").start();try{await jo(e),await V(t.packageManager,["install"],{cwd:e}),await $o(e),r?.stopAndPersist({symbol:p.cyan("\u2714"),text:vo.bold(`Created a new Next.js monorepo at ${p.cyan(e)}`)})}catch(n){r?.fail("Something went wrong creating a new Next.js monorepo."),A(n)}}async function jo(e){let t=Q.join(wo.tmpdir(),`tiptap-framework-${Date.now()}`);await M.ensureDir(t);let r=await fetch(Po);if(!r.ok)throw new Error(`Failed to download framework: ${r.statusText}`);let n=Q.resolve(t,"framework.tar.gz");await M.writeFile(n,Buffer.from(await r.arrayBuffer())),await V("tar",["-xzf",n,"-C",t,"--strip-components=2","ui-main/templates/monorepo-next"]);let o=Q.resolve(t,"monorepo-next");await M.move(o,e),await M.remove(t)}async function $o(e){let t=process.cwd();try{await V("git",["--version"],{cwd:e}),await V("git",["init"],{cwd:e}),await V("git",["add","-A"],{cwd:e}),await V("git",["commit","-m","Initial commit"],{cwd:e}),await V("cd",[t])}catch{i.warn("Failed to initialize git repository, but project creation succeeded")}}var Oo=`# Simple template
|
|
49
|
+
|
|
50
|
+
Integrate the Tiptap open source editor with UI components and open source extensions.
|
|
51
|
+
|
|
52
|
+
The Simple Editor Template is a fully working setup for the Tiptap editor. It includes commonly used open source extensions and UI components, all MIT licensed and ready to customize.
|
|
33
53
|
|
|
34
|
-
|
|
54
|
+
**Quick Links:**
|
|
55
|
+
- [View in Full Screen](http://template.tiptap.dev/preview/templates/simple)
|
|
56
|
+
- [GitHub Repository](https://github.com/ueberdosis/tiptap-ui-components/tree/main/apps/web/src/components/tiptap-templates/simple)
|
|
35
57
|
|
|
36
|
-
##
|
|
37
|
-
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
Add the Simple Editor Template to your project using the Tiptap CLI:
|
|
38
61
|
|
|
39
62
|
\`\`\`bash
|
|
40
|
-
|
|
63
|
+
npx @tiptap/cli add simple-editor
|
|
41
64
|
\`\`\`
|
|
42
65
|
|
|
43
|
-
|
|
44
|
-
Install dependencies (if you haven't already):
|
|
66
|
+
## Style
|
|
45
67
|
|
|
46
|
-
|
|
47
|
-
|
|
68
|
+
> **Missing styles?** If you haven't added the styles yet, make sure to [follow the style setup guide](/ui-components/getting-started/style) to ensure your editor and components render correctly.
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
After installation, use the SimpleEditor component in your React or Next.js project:
|
|
73
|
+
|
|
74
|
+
\`\`\`jsx
|
|
75
|
+
import { SimpleEditor } from '@/components/tiptap-templates/simple/simple-editor'
|
|
76
|
+
|
|
77
|
+
export default function App() {
|
|
78
|
+
return <SimpleEditor />
|
|
79
|
+
}
|
|
48
80
|
\`\`\`
|
|
49
|
-
or use yarn or pnpm.
|
|
50
81
|
|
|
51
|
-
|
|
82
|
+
## Features
|
|
83
|
+
|
|
84
|
+
A fully responsive rich text editor with built-in support for common formatting and layout tools. All components are open source and easy to extend.
|
|
85
|
+
|
|
86
|
+
- **Responsive design**: Mobile-friendly by default
|
|
87
|
+
- **Dark and light mode**: Supported out-of-the-box
|
|
88
|
+
- **Formatting**: Bold, Italic, Underline
|
|
89
|
+
- **Lists**: Bullet, Ordered, Checkboxes
|
|
90
|
+
- **Text alignment**: Left, Center, Right, Justified
|
|
91
|
+
- **Headings**: Multiple levels via dropdown
|
|
92
|
+
- **Image upload**
|
|
93
|
+
- **Link editing:** UI for adding and editing links
|
|
94
|
+
- **Undo / Redo:** History management
|
|
95
|
+
|
|
96
|
+
### Used reference components
|
|
97
|
+
|
|
98
|
+
#### Hooks
|
|
99
|
+
|
|
100
|
+
- \`use-mobile\`
|
|
101
|
+
- \`use-window-size\`
|
|
102
|
+
|
|
103
|
+
#### Icons
|
|
104
|
+
|
|
105
|
+
- \`arrow-left-icon\`
|
|
106
|
+
- \`highlighter-icon\`
|
|
107
|
+
- \`link-icon\`
|
|
108
|
+
- \`moon-star-icon\`
|
|
109
|
+
- \`sun-icon\`
|
|
110
|
+
|
|
111
|
+
#### Extensions
|
|
112
|
+
|
|
113
|
+
- \`selection-extension\`
|
|
114
|
+
- \`link-extension\`
|
|
115
|
+
- \`trailing-node-extension\`
|
|
116
|
+
|
|
117
|
+
#### Lib
|
|
118
|
+
|
|
119
|
+
- \`tiptap-utils\`
|
|
120
|
+
|
|
121
|
+
#### UI Components
|
|
122
|
+
|
|
123
|
+
- \`blockquote-button\`
|
|
124
|
+
- \`code-block-button\`
|
|
125
|
+
- \`color-highlight-button\`
|
|
126
|
+
- \`color-highlight-popover\`
|
|
127
|
+
- \`heading-button\`
|
|
128
|
+
- \`heading-dropdown-menu\`
|
|
129
|
+
- \`image-upload-button\`
|
|
130
|
+
- \`link-popover\`
|
|
131
|
+
- \`list-button\`
|
|
132
|
+
- \`list-dropdown-menu\`
|
|
133
|
+
- \`mark-button\`
|
|
134
|
+
- \`text-align-button\`
|
|
135
|
+
- \`undo-redo-button\`
|
|
136
|
+
|
|
137
|
+
#### Node Components
|
|
138
|
+
|
|
139
|
+
- \`code-block-node\`
|
|
140
|
+
- \`image-node\`
|
|
141
|
+
- \`image-upload-node\`
|
|
142
|
+
- \`list-node\`
|
|
143
|
+
- \`paragraph-node\`
|
|
144
|
+
|
|
145
|
+
#### Primitives
|
|
146
|
+
|
|
147
|
+
- \`button\`
|
|
148
|
+
- \`spacer\`
|
|
149
|
+
- \`toolbar\`
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
The Simple Editor Template and all included components are MIT licensed. You're free to use, modify, and extend the code as needed.
|
|
154
|
+
|
|
155
|
+
## Future compatibility
|
|
156
|
+
|
|
157
|
+
You can extend this template with additional features as your needs grow.
|
|
158
|
+
|
|
159
|
+
Paid Tiptap Cloud features will have matching UI components that integrate just as easily! No rework needed.`,_o=`# Notion-like Editor
|
|
160
|
+
|
|
161
|
+
A Notion-style Tiptap editor with collaboration, AI, and rich UI components. Fully customizable and easy to integrate.
|
|
162
|
+
|
|
163
|
+
The **Notion-like Editor Template** is a fully featured block-based editor that replicates the familiar Notion experience. It supports collaboration, AI assistance, emoji, drag & drop, advanced formatting\u2014and it's fully customizable.
|
|
164
|
+
|
|
165
|
+
## Installation
|
|
166
|
+
|
|
167
|
+
Install the Notion-like editor with the Tiptap CLI:
|
|
52
168
|
|
|
53
169
|
\`\`\`bash
|
|
54
|
-
|
|
170
|
+
npx @tiptap/cli add notion-like-editor
|
|
55
171
|
\`\`\`
|
|
56
|
-
or yarn or pnpm.
|
|
57
172
|
|
|
58
|
-
|
|
59
|
-
To apply the correct styles to the editor, manually import these files into your main CSS/SCSS entry point:
|
|
173
|
+
## Styling
|
|
60
174
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
175
|
+
> **Note:** If the editor doesn't look right, make sure you've followed the [style setup guide](/ui-components/getting-started/style).
|
|
176
|
+
|
|
177
|
+
## Configuration
|
|
178
|
+
|
|
179
|
+
Before running the app, configure the required constants inside \`tiptap-collab-utils.ts\`. This is necessary to enable features like AI or collaboration.
|
|
180
|
+
|
|
181
|
+
### Environment Variables
|
|
182
|
+
|
|
183
|
+
Provide values for the following environment variables:
|
|
184
|
+
|
|
185
|
+
- \`COLLAB_DOC_PREFIX\` - Prefix for identifying collaborative documents
|
|
186
|
+
- \`TIPTAP_COLLAB_APP_ID\` - Your collaboration App ID
|
|
187
|
+
- \`TIPTAP_COLLAB_TOKEN\` - JWT token for accessing Collaboration services
|
|
188
|
+
- \`TIPTAP_AI_APP_ID\` - Your AI App ID
|
|
189
|
+
- \`TIPTAP_AI_TOKEN\` - JWT token for accessing AI services
|
|
190
|
+
|
|
191
|
+
The above environment variables should be available in the client-side. Depending on your framework, use the following prefixes to expose them to the client:
|
|
192
|
+
|
|
193
|
+
- **[Next.js](/ui-components/install/next)**: \`NEXT_PUBLIC_\`. For example, \`NEXT_PUBLIC_COLLAB_DOC_PREFIX\`.
|
|
194
|
+
- **[Vite + React](/ui-components/install/vite)**: \`VITE_\`. For example, \`VITE_COLLAB_DOC_PREFIX\`.
|
|
195
|
+
- **Other frameworks**: Follow the specific rules of your framework, and define the variables in the \`tiptap-collab-utils.ts\` file.
|
|
196
|
+
|
|
197
|
+
### JWT Authentication
|
|
198
|
+
|
|
199
|
+
Collaboration and AI features require a valid server-generated JWT token passed to the editor. See the \`fetchCollabToken\` function in \`tiptap-collab-utils.ts\` for an example.
|
|
200
|
+
|
|
201
|
+
> See the full guide on JWT authentication at [https://tiptap.dev/docs/guides/authentication](https://tiptap.dev/docs/guides/authentication).
|
|
202
|
+
|
|
203
|
+
> **Important:** To get started quickly, you can use the example JWT tokens from your Tiptap Cloud account and store them in the \`TIPTAP_COLLAB_TOKEN\` and \`TIPTAP_AI_TOKEN\` environment variables. However, example JWT tokens are valid for a short time and should not be used in production. In production, implement an API endpoint that generates JWTs on the server side.
|
|
204
|
+
|
|
205
|
+
### \`room\` prop
|
|
206
|
+
|
|
207
|
+
Use the \`room\` prop to distinguish collaborative documents. Each session should use a unique room ID.
|
|
208
|
+
|
|
209
|
+
## Usage
|
|
210
|
+
|
|
211
|
+
Import and render the \`NotionEditor\` component in your React app:
|
|
212
|
+
|
|
213
|
+
\`\`\`tsx
|
|
214
|
+
import { NotionEditor } from '@/components/tiptap-templates/notion/notion-like-editor'
|
|
215
|
+
|
|
216
|
+
export default function App() {
|
|
217
|
+
return <NotionEditor room="my-document-room" placeholder="Start writing..." />
|
|
218
|
+
}
|
|
64
219
|
\`\`\`
|
|
65
220
|
|
|
66
|
-
|
|
221
|
+
## Features
|
|
222
|
+
|
|
223
|
+
The template includes all the essentials of a modern Notion-style editor:
|
|
224
|
+
|
|
225
|
+
- **Real-time collaboration**: Live cursors and user presence
|
|
226
|
+
- **AI assistance**: Inline AI tools for writing and editing
|
|
227
|
+
- **Responsive design**: Mobile-ready UI with adaptive toolbars
|
|
228
|
+
- **Dark/light mode**: Fully themed out of the box
|
|
229
|
+
- **Slash commands**: \`/\` menu for quick formatting
|
|
230
|
+
- **Floating toolbar**: Context-aware formatting
|
|
231
|
+
- **Drag and drop**: Block-level reordering
|
|
232
|
+
- **Emoji support**: GitHub-style emoji picker
|
|
233
|
+
- **Mentions**: \`@user\` autocomplete
|
|
234
|
+
- **Rich formatting**:
|
|
235
|
+
- Bold, italic, underline, strikethrough
|
|
236
|
+
- Highlight and color
|
|
237
|
+
- Superscript / subscript
|
|
238
|
+
- Syntax-highlighted code blocks
|
|
239
|
+
- **Block types**:
|
|
240
|
+
- Headings, lists, blockquotes, dividers, math
|
|
241
|
+
- **Media support**: Drag & drop image upload
|
|
242
|
+
- **Link management**: With inline previews
|
|
243
|
+
- **Text alignment**: Left, center, right, justified
|
|
244
|
+
- **Undo/Redo**: Full editing history
|
|
245
|
+
- **Context menus**: Right-click enhancements
|
|
246
|
+
|
|
247
|
+
## Component Breakdown
|
|
248
|
+
|
|
249
|
+
### Hooks
|
|
250
|
+
|
|
251
|
+
- \`use-mobile\`
|
|
252
|
+
- \`use-window-size\`
|
|
253
|
+
- \`use-ui-editor-state\`
|
|
254
|
+
|
|
255
|
+
### Icons
|
|
256
|
+
|
|
257
|
+
- \`arrow-left-icon\`
|
|
258
|
+
- \`chevron-right-icon\`
|
|
259
|
+
- \`highlighter-icon\`
|
|
260
|
+
- \`link-icon\`
|
|
261
|
+
- \`more-vertical-icon\`
|
|
262
|
+
|
|
263
|
+
### Tiptap Extensions
|
|
264
|
+
|
|
265
|
+
- \`collaboration\`, \`collaboration-cursor\`
|
|
266
|
+
- \`selection-extension\`
|
|
267
|
+
- \`link-extension\`
|
|
268
|
+
- \`trailing-node-extension\`
|
|
269
|
+
- \`ai-extension\`
|
|
270
|
+
- \`emoji-extension\`
|
|
271
|
+
- \`mention-extension\`
|
|
272
|
+
- \`mathematics-extension\`
|
|
273
|
+
- \`unique-id-extension\`
|
|
274
|
+
|
|
275
|
+
### Libs
|
|
276
|
+
|
|
277
|
+
- \`tiptap-utils\`
|
|
278
|
+
- \`tiptap-collab-utils\`
|
|
279
|
+
|
|
280
|
+
### UI Components
|
|
281
|
+
|
|
282
|
+
- \`ai-menu\`
|
|
283
|
+
- \`blockquote-button\`
|
|
284
|
+
- \`code-block-button\`
|
|
285
|
+
- \`color-highlight-button\`, \`color-highlight-popover\`
|
|
286
|
+
- \`drag-context-menu\`
|
|
287
|
+
- \`emoji-dropdown-menu\`
|
|
288
|
+
- \`heading-button\`, \`heading-dropdown-menu\`
|
|
289
|
+
- \`image-upload-button\`
|
|
290
|
+
- \`link-popover\`
|
|
291
|
+
- \`list-button\`, \`list-dropdown-menu\`
|
|
292
|
+
- \`mark-button\`
|
|
293
|
+
- \`mention-dropdown-menu\`
|
|
294
|
+
- \`slash-dropdown-menu\`
|
|
295
|
+
- \`text-align-button\`
|
|
296
|
+
- \`turn-into-dropdown\`
|
|
297
|
+
- \`undo-redo-button\`
|
|
298
|
+
|
|
299
|
+
### Nodes
|
|
300
|
+
|
|
301
|
+
- \`code-block-node\`
|
|
302
|
+
- \`image-node\`, \`image-upload-node\`
|
|
303
|
+
- \`list-node\`
|
|
304
|
+
- \`paragraph-node\`
|
|
305
|
+
|
|
306
|
+
### Notion-specific
|
|
307
|
+
|
|
308
|
+
- \`notion-like-editor-header\`
|
|
309
|
+
- \`notion-toolbar-floating\`
|
|
310
|
+
- \`mobile-toolbar\`
|
|
311
|
+
- \`collaboration-users\`
|
|
312
|
+
- \`theme-toggle\`
|
|
313
|
+
|
|
314
|
+
### Primitives
|
|
315
|
+
|
|
316
|
+
- \`button\`, \`button-group\`
|
|
317
|
+
- \`dropdown-menu\`
|
|
318
|
+
- \`separator\`, \`spacer\`, \`toolbar\`
|
|
319
|
+
|
|
320
|
+
### Contexts
|
|
321
|
+
|
|
322
|
+
- \`app-context\`
|
|
323
|
+
- \`user-context\`
|
|
324
|
+
- \`collab-context\`
|
|
325
|
+
|
|
326
|
+
## Collaboration
|
|
327
|
+
|
|
328
|
+
To use collaboration:
|
|
329
|
+
|
|
330
|
+
1. Pass a unique \`room\` ID to \`NotionEditor\`
|
|
331
|
+
2. Enable JWT auth for each user session
|
|
332
|
+
3. User presence and cursors are handled automatically
|
|
333
|
+
4. Operational transformation handles concurrent edits
|
|
334
|
+
5. Sync and save are managed out-of-the-box
|
|
335
|
+
|
|
336
|
+
\`\`\`tsx
|
|
337
|
+
<NotionEditor room="team-notes" placeholder="Share your ideas..." />
|
|
338
|
+
\`\`\`
|
|
339
|
+
|
|
340
|
+
## AI Integration
|
|
341
|
+
|
|
342
|
+
The built-in AI tools let you:
|
|
67
343
|
|
|
344
|
+
- **Generate content** from prompts
|
|
345
|
+
- **Improve** existing text
|
|
346
|
+
- **Get smart completions** based on context
|
|
68
347
|
|
|
69
|
-
|
|
70
|
-
Once the server is running, you can access the Tiptap Simple Editor template by visiting the /simple route in your application.
|
|
348
|
+
> **AI Configuration:** Make sure to configure your AI provider. Check the [AI Generation extension docs](/content-ai/capabilities/generation/overview) for setup steps.
|
|
71
349
|
|
|
72
|
-
|
|
350
|
+
## Extendability
|
|
73
351
|
|
|
74
|
-
|
|
75
|
-
To learn more about the Tiptap Simple Editor and how to customize it, visit the official documentation:
|
|
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();
|
|
352
|
+
This template is designed to grow with your needs. New Tiptap Cloud features will be seamlessly compatible with the same UI system\u2014no rewrites required.`;async function mr(e,t){let r=Q.join(e,"README.md"),n={"simple-editor":Oo,"notion-like-editor":_o},o=t&&t in n?n[t]:"";try{o.trim()&&await M.writeFile(r,o,"utf-8")}catch{}}import Do from"chalk";var Mo=ee.object({cwd:ee.string(),components:ee.array(ee.string()).optional(),silent:ee.boolean(),isNewProject:ee.boolean(),srcDir:ee.boolean().optional(),framework:ee.string().optional().refine(e=>!e||de[e],{message:"Invalid framework. Please use 'next' or 'vite'."})}),dt=(e,t=!0)=>Fo({message:e,default:t,theme:{prefix:{done:p.cyan("\u2714"),idle:"?"}}}),ur=new Uo().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=Mo.parse({cwd:fr.resolve(t.cwd),isNewProject:!1,components:e,...t}),n=await Lo(r);i.log(Do.bold(`${p.cyan("Success!")} Project initialization completed.`)),n?.filesCreated.some(s=>s.includes("tiptap-templates")||s.includes("tiptap-ui"))&&rr();let c=n?.filesCreated.some(s=>s.includes("notion"));n.framework&&c&&Oe(n.framework),i.break()}catch(r){i.break(),A(r)}});async function Lo(e){let{cwd:t,skipPreflight:r,components:n,silent:o}=e,c,s,a={...e};if(r)c=await O(t);else{let y=await pr(e);if(y.errors[q]){let{projectPath:b,framework:F}=await lr(e);b||process.exit(0),a={...a,cwd:b,isNewProject:!0},s=F}c=y.projectInfo}if(s==="next-monorepo"){let y=fr.resolve(a.cwd,"apps/web");return{config:await K(y),projectInfo:c,framework:s,selectedComponents:[],filesCreated:[],filesUpdated:[],filesSkipped:[],errors:[]}}let m=await bt(a.cwd,c),w=m?await Wo(m):await Bo(await K(a.cwd)),g=n||[];if(!g.length){if(!await dt("Would you like to add a template or UI components to your project?"))return i.info(""),{config:await re(a.cwd,w),projectInfo:c,framework:s,selectedComponents:[],filesCreated:[],filesUpdated:[],filesSkipped:[],errors:[]};if(g=await ut({...a,overwrite:!1},!1),!g.length)return i.info(""),{config:await re(a.cwd,w),projectInfo:c,framework:s,selectedComponents:[],filesCreated:[],filesUpdated:[],filesSkipped:[],errors:[]};let $=await pe();if(!$)throw new Error("Failed to fetch registry index.");let b=g.map(L=>{let _=$.find(W=>W.name===L);return{name:L,plans:_?.plans||[]}});await $e(b,a.cwd)||(i.error("Authentication failed. Cannot proceed with paid component download."),i.log("You can try again with only free components, or authenticate first."),process.exit(1))}let v=await re(a.cwd,w),f=await Ce(g,v,{overwrite:!1,silent:o,isNewProject:a.isNewProject||c?.framework.name==="next-app"});return{config:v,projectInfo:c,framework:s,selectedComponents:g,filesCreated:f?.filesCreated||[],filesUpdated:f?.filesUpdated||[],filesSkipped:f?.filesSkipped||[]}}async function Bo(e=null){i.info("");let t=await dt(`Would you like to use ${p.cyan("TypeScript")} (recommended)?`,e?.tsx??!0),r=await dt(`Are you using ${p.cyan("React Server Components")}?`,e?.rsc??!0);return ne.parse({rsc:r,tsx:t,aliases:{components:Le,contexts:Be,hooks:We,tiptapIcons:ze,lib:ke,tiptapExtensions:Ke,tiptapNodes:Ve,tiptapUi:Je,tiptapUiPrimitives:Ye,tiptapUiUtils:Ge,styles:qe}})}async function Wo(e){return ne.parse({rsc:e?.rsc,tsx:e?.tsx,aliases:e?.aliases})}import{Command as Ko}from"commander";var dr={name:"@tiptap/cli",version:"3.0.0",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"],license:"SEE LICENSE IN LICENSE.md",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.28.0","@babel/parser":"^7.28.0","@babel/plugin-transform-typescript":"^7.28.0","@inquirer/core":"^10.1.14","@inquirer/figures":"^1.0.12","@inquirer/prompts":"^7.6.0","@inquirer/type":"^3.0.7","ansi-escapes":"^7.0.0",chalk:"^5.4.1",commander:"^13.1.0",conf:"^14.0.0",cosmiconfig:"^9.0.0",deepmerge:"^4.3.1",execa:"^9.6.0","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.8.0","yoctocolors-cjs":"^2.1.2",zod:"^3.25.76"},devDependencies:{"@babel/plugin-transform-typescript":"^7.26.5","@types/babel__core":"^7.20.5","@types/conf":"^3.0.3","@types/fs-extra":"^11.0.4","@types/prompts":"^2.4.9","cross-env":"^7.0.3",tsup:"^8.5.0","type-fest":"^4.41.0"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function Vo(){let e=new Ko().name("tiptap").description("add components and dependencies to your project").version(dr.version||"1.0.0","-v, --version","display the CLI version number");e.addCommand(ur).addCommand(sr).addCommand(ar).addCommand(Qt).addCommand(tr).addCommand(er),e.parse()}Vo();
|
|
78
353
|
//# sourceMappingURL=index.js.map
|