raycast / extensions

Everything you need to extend Raycast.
https://developers.raycast.com
MIT License
5.42k stars 3.12k forks source link

[Obsidian] ... #3694

Closed AZ915 closed 1 year ago

AZ915 commented 1 year ago

Extension

https://github.com/raycast/extensions/tree/9f3584132237295c2bbebc03e2de252eb5eb560c/extensions/obsidian/

Description

Error:

TypeError: Cannot read properties of undefined (reading 'length')

Cn:searchNoteCommand.js:139:3987

---
136: `),n=n.replaceAll("{newline}",`
137: `),n=n.replaceAll("{nl}",`
138: `),n}async function ja(n){let{appendSelectedTemplate:e}=(0,O.getPreferenceValues)();e=e||"{content}";try{let t=await(0,O.getSelectedText)();if(t.trim()=="")(0,O.showToast)({title:"No text selected",message:"Make sure to select some text.",style:O.Toast.Style.Failure});else{let s=e.replaceAll("{content}",t);return s=await St(s),z.default.appendFileSync(n.path,`
139: `+s),(0,O.showToast)({title:"Added selected text to note",style:O.Toast.Style.Success}),!0}}catch{(0,O.showToast)({title:"Couldn't copy selected text",message:"Maybe you didn't select anything.",style:O.Toast.Style.Failure})}}var wn=n=>"obsidian://open?path="+encodeURIComponent(n);function pi(n,e,t,s){let i=z.default.readdirSync(n);s=s||[];for(let r of i)z.default.statSync(n+"/"+r).isDirectory()&&!r.includes(".obsidian")?s=pi(n+"/"+r,e,t,s):Bd(r,t)&&r!==".md"&&!r.includes(".excalidraw")&&!n.includes(".obsidian")&&xd(n,e)&&s.push(Pa.default.join(n,"/",r));return s}function xd(n,e){for(let t of e)if(n.includes(t))return!1;return!0}function Bd(n,e){for(let t of e)if(n.endsWith(t))return!0;return!1}function ka(){let e=(0,O.getPreferenceValues)().excludedFolders;if(e){let t=e.split(",");for(let s=0;s<t.length;s++)t[s]=t[s].trim();return t}else return[]}var On=require("@raycast/api"),be=V(require("react")),tl=V(require("fs"));var An=require("@raycast/api"),kn=require("react");var D=require("@raycast/api"),De=V(require("react")),Ka=V(require("fs"));var I=require("react/jsx-runtime");function Ua(n){let{note:e,vault:t,pref:s,onDelete:i,action:r}=n,[o,a]=(0,De.useState)(e.content),[l,c]=(0,De.useState)(ne(e,t)),u=!Ka.default.existsSync(e.path);u&&Ea(t);function f(){let h=se(e.path);e.content=h,a(h)}function d(){let h=yn([e]);e.tags=h}function p(h){switch(+h){case 0:c(!l);break;case 2:i&&i(e,t),Oa(t,e);break;case 1:f(),d(),gi(t,e);break;case 3:f(),d(),gi(t,e)}}function y(){return e.tags.length>0?(0,I.jsx)(D.List.Item.Detail.Metadata.TagList,{title:"Tags",children:e.tags.map(h=>(0,I.jsx)(D.List.Item.Detail.Metadata.TagList.Item,{text:h},h))}):null}function m(){let h=wa(e.content,"url");return h?(0,I.jsx)(D.List.Item.Detail.Metadata.Link,{target:h,text:"View",title:"URL"}):null}return u?null:(0,I.jsx)(D.List.Item,{title:e.title,accessories:[{text:l?"\u2B50\uFE0F":""}],detail:(0,I.jsx)(D.List.Item.Detail,{markdown:bt(o),metadata:s.showMetadata?(0,I.jsxs)(D.List.Item.Detail.Metadata,{children:[(0,I.jsx)(D.List.Item.Detail.Metadata.Label,{title:"Character Count",text:o.length.toString()}),(0,I.jsx)(D.List.Item.Detail.Metadata.Label,{title:"Word Count",text:bi(o).toString()}),(0,I.jsx)(D.List.Item.Detail.Metadata.Label,{title:"Reading Time",text:xa(o).toString()+" min read"}),(0,I.jsx)(y,{}),(0,I.jsx)(m,{}),(0,I.jsx)(D.List.Item.Detail.Metadata.Separator,{}),(0,I.jsx)(D.List.Item.Detail.Metadata.Label,{title:"Creation Date",text:Ba(e).toLocaleDateString()}),(0,I.jsx)(D.List.Item.Detail.Metadata.Label,{title:"File Size",text:Va(e).toFixed(2)+" KB"}),(0,I.jsx)(D.List.Item.Detail.Metadata.Label,{title:"Note Path",text:Ra(e.path.split(t.path)[1],55)})]}):(0,I.jsx)(De.default.Fragment,{})}),actions:(0,I.jsx)(D.ActionPanel,{children:(0,I.jsx)(De.default.Fragment,{children:r&&r(e,t,p)})})})}var Fe=require("@raycast/api"),Ya=V(require("react")),ue=require("react/jsx-runtime");function Ja(n){let{setNotes:e,allNotes:t,tags:s,searchArguments:i}=n;function r(){if(i&&i.tagArgument!=""&&i.tagArgument)return i.tagArgument.startsWith("#")?i.tagArgument:"#"+i.tagArgument}function o(f){e&&t&&(f!="all"?e&&e(t.filter(d=>d.tags.includes(f))):e&&e(t))}function a(){return(0,ue.jsxs)(Ya.default.Fragment,{children:[(0,ue.jsx)(Fe.List.Dropdown.Item,{title:"All",value:"all"}),(0,ue.jsx)(Fe.List.Dropdown.Section,{title:"Tags"}),s.map(f=>(0,ue.jsx)(Fe.List.Dropdown.Item,{title:f,value:f},f))]})}function l(){return(0,ue.jsx)(Fe.List.Dropdown,{tooltip:"Search For",defaultValue:r()??"",onChange:o,children:a()})}function c(){return(0,ue.jsx)(Fe.List.Dropdown,{tooltip:"Search For",defaultValue:"all",onChange:o,children:a()})}function u(){return r()?l():c()}return(0,ue.jsx)(u,{})}function Ga(n,e,t){return e.length===0?n:(e=e.toLowerCase(),t?n.filter(s=>s.content.toLowerCase().includes(e)||s.title.toLowerCase().includes(e)||s.path.toLowerCase().includes(e)):n.filter(s=>s.title.toLowerCase().includes(e)))}var Si=require("react/jsx-runtime");function Cn(n){let{notes:e,allNotes:t,vault:s,isLoading:i,title:r,searchArguments:o,setNotes:a,action:l,onDelete:c,onSearchChange:u}=n,f=(0,An.getPreferenceValues)(),[d,p]=(0,kn.useState)(o?o.searchArgument:""),m=(0,kn.useMemo)(()=>Ga(e??[],d,f.searchContent),[e,d]).slice(0,vi),h=yn(t??[]),g=e===void 0;return e!==void 0&&(g=e.length==0),i!==void 0&&(g=i),(0,Si.jsx)(An.List,{throttle:!0,isLoading:g,isShowingDetail:f.showDetail,onSearchTextChange:N=>{p(N)},navigationTitle:r,searchText:d,searchBarAccessory:(0,Si.jsx)(Ja,{tags:h,setNotes:a,allNotes:t,searchArguments:o}),children:m?.map(N=>(0,Si.jsx)(Ua,{note:N,vault:s,pref:f,onDelete:c,action:l},N.path))})}var A=require("@raycast/api"),K=V(require("react"));var F=require("@raycast/api"),Wa=V(require("fs"));var Tn=require("react/jsx-runtime");function Qa(n){let{note:e,actionCallback:t}=n,{pop:s}=(0,F.useNavigation)(),{appendTemplate:i}=(0,F.getPreferenceValues)();async function r(o){let a=await St(o.content);Wa.default.appendFileSync(e.path,`
140: `+a),(0,F.showToast)({title:"Added text to note",style:F.Toast.Style.Success}),s(),t(3)}return(0,Tn.jsx)(F.Form,{navigationTitle:"Add text to: "+e.title,actions:(0,Tn.jsx)(F.ActionPanel,{children:(0,Tn.jsx)(F.Action.SubmitForm,{title:"Submit",onSubmit:r})}),children:(0,Tn.jsx)(F.Form.TextArea,{title:`Add text to:
141: `+e.title,id:"content",placeholder:"Text",defaultValue:i})})}var M=require("@raycast/api"),Xa=V(require("fs")),Ha=require("react");var En=require("react/jsx-runtime");function za(n){let{note:e,actionCallback:t}=n,{pop:s}=(0,M.useNavigation)(),[i]=(0,Ha.useState)(se(e.path,!1));async function r(o){let a=o.content;a=await St(a);let l={title:"Override note",message:'Are you sure you want to override the note: "'+e.title+'"?',icon:M.Icon.ExclamationMark};await(0,M.confirmAlert)(l)&&(Xa.default.writeFileSync(e.path,a),(0,M.showToast)({title:"Edited note",style:M.Toast.Style.Success}),t(1),s())}return(0,En.jsx)(M.Form,{navigationTitle:"Edit: "+e.title,actions:(0,En.jsx)(M.ActionPanel,{children:(0,En.jsx)(M.Action.SubmitForm,{title:"Submit",onSubmit:r})}),children:(0,En.jsx)(M.Form.TextArea,{title:`Edit:
142: `+e.title,id:"content",placeholder:"Text",enableMarkdown:!0,defaultValue:i})})}var $e=require("@raycast/api"),wt=require("react");var Nt=require("react/jsx-runtime");function Za(n){let{note:e,notes:t,showTitle:s,vault:i,actionCallback:r}=n,{pop:o}=(0,$e.useNavigation)(),a=e?.content;a=bt(a??"");let[l,c]=(0,wt.useState)(e?ne(e,i):!1),[u,f]=(0,wt.useState)(a);function d(){if(e){let y=se(e.path);e.content=y,f(y)}}(0,wt.useEffect)(d,[e]);function p(y,m=void 0){switch(r&&r(y),+y){case 0:c(!l);break;case 2:o();break;case 1:d();break;case 3:d()}}return(0,Nt.jsx)($e.Detail,{isLoading:e===void 0,navigationTitle:s?l?"\u2B50 "+e?.title:e?.title:"",markdown:u,actions:e?(0,Nt.jsxs)($e.ActionPanel,{children:[(0,Nt.jsx)(At,{note:e,notes:t,vault:i,actionCallback:p}),(0,Nt.jsx)(vt,{note:e,notes:t,vault:i,actionCallback:p})]}):null})}var v=require("react/jsx-runtime");function Vd(n){let{path:e}=n;return(0,v.jsx)(A.Action.ShowInFinder,{title:"Show in Finder",icon:A.Icon.Finder,path:e,shortcut:{modifiers:["opt"],key:"enter"}})}function Rd(n){let{note:e,vault:t,actionCallback:s}=n;return(0,v.jsx)(A.Action.Push,{title:"Edit Note",target:(0,v.jsx)(za,{note:e,vault:t,actionCallback:s}),shortcut:{modifiers:["opt"],key:"e"},icon:A.Icon.Pencil})}function jd(n){let{note:e,actionCallback:t}=n;return(0,v.jsx)(A.Action.Push,{title:"Append to Note",target:(0,v.jsx)(Qa,{note:e,actionCallback:t}),shortcut:{modifiers:["opt"],key:"a"},icon:A.Icon.Pencil})}function Kd(n){let{note:e,actionCallback:t}=n;return(0,v.jsx)(A.Action,{title:"Append Selected Text to Note",shortcut:{modifiers:["opt"],key:"s"},onAction:async()=>{await ja(e)&&t(3)},icon:A.Icon.Pencil})}function Ud(n){let{note:e}=n;return(0,v.jsx)(A.Action.CopyToClipboard,{title:"Copy Note Content",content:e.content,shortcut:{modifiers:["opt"],key:"c"}})}function Yd(n){let{note:e}=n;return(0,v.jsx)(A.Action.Paste,{title:"Paste Note Content",content:e.content,shortcut:{modifiers:["opt"],key:"v"}})}function Jd(n){let{note:e}=n;return(0,v.jsx)(A.Action.CopyToClipboard,{title:"Copy Markdown Link",icon:A.Icon.Link,content:`[${e.title}](${wn(e.path)})`,shortcut:{modifiers:["opt"],key:"l"}})}function Gd(n){let{note:e}=n;return(0,v.jsx)(A.Action.CopyToClipboard,{title:"Copy Obsidian URI",icon:A.Icon.Link,content:wn(e.path),shortcut:{modifiers:["opt"],key:"u"}})}function Wd(n){let{note:e,vault:t,actionCallback:s}=n,[i,r]=(0,K.useState)(ne(e,t));return(0,v.jsx)(A.Action,{title:i?"Unpin Note":"Pin Note",shortcut:{modifiers:["opt"],key:"p"},onAction:()=>{i?(bn(e,t),r(!i),s(0)):(Aa(e,t),r(!i),s(0))},icon:i?A.Icon.XMarkCircle:A.Icon.Pin})}function Qd(n){let{note:e,vault:t,actionCallback:s}=n;return(0,v.jsx)(A.Action,{title:"Delete Note",shortcut:{modifiers:["opt"],key:"d"},onAction:async()=>{await $a(e,t)&&s(2)},icon:{source:A.Icon.Trash,tintColor:A.Color.Red}})}function Xd(n){let{note:e,notes:t,vault:s,actionCallback:i}=n;return(0,v.jsx)(A.Action.Push,{title:"Quick Look",target:(0,v.jsx)(Za,{note:e,notes:t,vault:s,showTitle:!0,actionCallback:i}),icon:A.Icon.Eye})}function Hd(n){let{path:e}=n;return(0,v.jsx)(A.Action.Open,{title:"Open in Obsidian",target:wn(e),icon:Mn})}function zd(n){let{note:e,vault:t}=n;return(0,v.jsx)(A.Action.Open,{title:"Open in new Pane",target:"obsidian://advanced-uri?vault="+encodeURIComponent(t.name)+"&filepath="+encodeURIComponent(e.path.replace(t.path,""))+"&newpane=true",icon:Mn})}function el(n){let{vault:e}=n;return(0,v.jsx)(A.Action.ShowInFinder,{title:"Show in Finder",icon:A.Icon.Finder,path:e.path})}function Zd(n){let{vault:e,str:t,notes:s}=n,i=s.filter(o=>o.content.includes(t)),r=i.length;if(r>0){let o=(0,v.jsx)(Cn,{vault:e,notes:i,title:`${r} notes mentioning "${t}"`,action:(a,l,c)=>(0,v.jsxs)(K.default.Fragment,{children:[(0,v.jsx)(At,{note:a,notes:s,vault:l,actionCallback:c}),(0,v.jsx)(vt,{note:a,notes:s,vault:l,actionCallback:c})]})});return(0,v.jsx)(A.Action.Push,{title:`Show Mentioning Notes (${r})`,target:o,icon:A.Icon.Megaphone})}else return(0,v.jsx)(K.default.Fragment,{})}function eh(n){let{note:e}=n,t=Ma(e.content);if(t.length===1){let s=t[0];return(0,v.jsxs)(K.default.Fragment,{children:[(0,v.jsx)(A.Action.Paste,{title:"Paste Code",icon:A.Icon.Code,content:s.code}),(0,v.jsx)(A.Action.CopyToClipboard,{title:"Copy Code",icon:A.Icon.Code,content:s.code})]})}else return t.length>1?(0,v.jsx)(A.Action.Push,{title:"Copy Code",icon:A.Icon.Code,target:(0,v.jsx)(A.List,{isShowingDetail:!0,children:t?.map(s=>(0,v.jsx)(A.List.Item,{title:s.code,detail:(0,v.jsx)(A.List.Item.Detail,{markdown:"```\n"+s.code+"```"}),subtitle:s.language,actions:(0,v.jsxs)(A.ActionPanel,{children:[(0,v.jsx)(A.Action.Paste,{title:"Paste Code",icon:A.Icon.Code,content:s.code}),(0,v.jsx)(A.Action.CopyToClipboard,{title:"Copy Code",icon:A.Icon.Code,content:s.code})]})},s.code))})}):(0,v.jsx)(K.default.Fragment,{})}function vt(n){let{notes:e,note:t,vault:s,actionCallback:i}=n;return(0,v.jsxs)(K.default.Fragment,{children:[(0,v.jsx)(Vd,{path:t.path}),(0,v.jsx)(Zd,{vault:s,str:t.title,notes:e}),(0,v.jsx)(eh,{note:t}),(0,v.jsx)(Rd,{note:t,vault:s,actionCallback:i}),(0,v.jsx)(jd,{note:t,actionCallback:i}),(0,v.jsx)(Kd,{note:t,actionCallback:i}),(0,v.jsx)(Ud,{note:t}),(0,v.jsx)(Yd,{note:t}),(0,v.jsx)(Jd,{note:t}),(0,v.jsx)(Gd,{note:t}),(0,v.jsx)(Wd,{note:t,vault:s,actionCallback:i}),(0,v.jsx)(Qd,{note:t,vault:s,actionCallback:i})]})}function At(n){let{note:e,notes:t,vault:s,actionCallback:i}=n,{primaryAction:r}=(0,A.getPreferenceValues)(),[o,a]=_a([s],"obsidian-advanced-uri"),l=(0,v.jsx)(Xd,{note:e,notes:t,vault:s,actionCallback:i}),c=(0,v.jsx)(Hd,{path:e.path}),u=o.includes(s)?(0,v.jsx)(zd,{note:e,vault:s}):null;return r=="quicklook"?(0,v.jsxs)(K.default.Fragment,{children:[l,c,u]}):r=="obsidian"?(0,v.jsxs)(K.default.Fragment,{children:[c,u,l]}):r=="newpane"?(0,v.jsxs)(K.default.Fragment,{children:[u,c,l]}):(0,v.jsxs)(K.default.Fragment,{children:[c,u,l]})}var kt=require("react/jsx-runtime");function Ni(n){let{showTitle:e,vault:t,searchArguments:s}=n,[i,r]=(0,be.useState)([]),[o,a]=(0,be.useState)([]);function l(c){r(i.filter(u=>u.path!==c.path)),a(o.filter(u=>u.path!==c.path))}return(0,be.useEffect)(()=>{async function c(){try{await tl.default.promises.access(t.path+"/.");let u=Nn(t);r(u),a(u)}catch{(0,On.showToast)({title:"The path set in preferences doesn't exist",message:"Please set a valid path in preferences",style:On.Toast.Style.Failure})}}c()},[]),(0,kt.jsx)(Cn,{title:e?"Search Note in "+t.name:"",notes:i,allNotes:o,setNotes:r,vault:t,onDelete:l,searchArguments:s,action:(c,u,f)=>(0,kt.jsxs)(be.default.Fragment,{children:[(0,kt.jsx)(At,{note:c,notes:o,vault:u,actionCallback:f}),(0,kt.jsx)(vt,{notes:o,note:c,vault:u,actionCallback:f})]})})}var Se=require("@raycast/api");var xe=require("react/jsx-runtime");function nl(n){let{vaults:e,target:t}=n;return(0,xe.jsx)(Se.List,{children:e?.map(s=>(0,xe.jsx)(Se.List.Item,{title:s.name,actions:(0,xe.jsxs)(Se.ActionPanel,{children:[(0,xe.jsx)(Se.Action.Push,{title:"Select Vault",target:t(s)}),(0,xe.jsx)(el,{vault:s})]})},s.key))})}var sl=require("@raycast/api"),th=require("react/jsx-runtime");function il(){return(0,th.jsx)(sl.Detail,{markdown:`# No vaults found
---

Ni:searchNoteCommand.js:142:5939
ol:searchNoteCommand.js:144:195
zt:index.js:5:2490

Steps To Reproduce

  1. Set 'Search Note' command to a hotkey
  2. Use the hotkey
  3. See error

Current Behaviour

SCR-20221128-ey6

I've restarted my computer, I didn't really do any other troubleshooting Reloading immediately gives the same error This issue has only happened to me with 'Search Note', I use 'Create Note', 'Daily Note', 'Open Vault', and 'Random Note' without issue. The issue also appears to be unrelated to the specific keystrokes used for the hotkey, I have it set to 'Cmd'->'Cmd' by default, but I've also tried 'Cmd'->'Shift'->'E' and found the same issue

Expected Behaviour

Opens a panel that shows all Obsidian notes with a preview as well as options to filter by tag and search by name

raycastbot commented 1 year ago

Thank you for opening this issue!

🔔 @marcjulianschwarz you might want to have a look.