cli-jaw 2.17.63 → 2.17.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/code-mode/store.js +35 -6
- package/dist/src/code-mode/store.js.map +1 -1
- package/dist/src/routes/code-native.js +11 -2
- package/dist/src/routes/code-native.js.map +1 -1
- package/package.json +1 -1
- package/public/dist/.vite/manifest.json +21 -9
- package/public/dist/assets/CodeCanvas-c_omHvtV.js +3 -0
- package/public/dist/assets/FolderPanel-DOLT_syh.js +3 -0
- package/public/dist/assets/{FolderPanel-BHEYcjea.css → FolderPanel-DgoqN1cX.css} +1 -1
- package/public/dist/assets/icons-QgChTDzZ.js +1 -0
- package/public/dist/assets/manager-Bq8-tr-M.js +5 -0
- package/public/dist/assets/manager-C6UJc985.css +1 -0
- package/public/dist/manager/index.html +2 -2
- package/public/manager/src/App.tsx +3 -3
- package/public/manager/src/AppChrome.tsx +1 -1
- package/public/manager/src/background-tasks/BackgroundTaskMonitorPanel.tsx +41 -7
- package/public/manager/src/background-tasks/background-task-monitor.css +1 -4
- package/public/manager/src/code/CodeSessionList.tsx +95 -35
- package/public/manager/src/code/code-controller-runtime.ts +66 -8
- package/public/manager/src/code/code-controller-types.ts +4 -0
- package/public/manager/src/code/code-session-client.ts +1 -1
- package/public/manager/src/code/code-session-sidebar.css +32 -0
- package/public/manager/src/code/code.css +2 -4
- package/public/manager/src/code/session-order.ts +9 -0
- package/public/manager/src/components/CommandBar.tsx +0 -10
- package/public/manager/src/components/InstanceGroups.tsx +2 -0
- package/public/manager/src/components/InstanceListContent.tsx +2 -0
- package/public/manager/src/components/InstanceRow.tsx +146 -89
- package/public/manager/src/components/SidebarRail.tsx +6 -5
- package/public/manager/src/components/ThemeSwitch.tsx +46 -22
- package/public/manager/src/components/context-menu/ContextMenu.tsx +207 -0
- package/public/manager/src/components/context-menu/context-menu.css +111 -0
- package/public/manager/src/components/context-menu/icons.tsx +48 -0
- package/public/manager/src/folder-panel/FolderContextMenu.tsx +43 -17
- package/public/manager/src/folder-panel/FolderPanel.tsx +9 -1
- package/public/manager/src/folder-panel/FolderPanelOverlays.tsx +2 -0
- package/public/manager/src/folder-panel/FolderTreeRows.tsx +6 -1
- package/public/manager/src/folder-panel/folder-panel.css +0 -33
- package/public/manager/src/folder-panel/use-folder-context-menu.ts +6 -19
- package/public/manager/src/hooks/useDashboardRegistry.ts +24 -1
- package/public/manager/src/jaw-ceo/JawCeoConsolePanels.tsx +71 -9
- package/public/manager/src/jaw-ceo/jaw-ceo-console.css +5 -7
- package/public/manager/src/main.tsx +2 -0
- package/public/manager/src/manager-components.css +1 -34
- package/public/manager/src/manager-desktop-titlebar.css +117 -0
- package/public/manager/src/manager-layout.css +0 -1
- package/public/manager/src/manager-p0-1-1.css +0 -42
- package/public/manager/src/manager-polish.css +0 -88
- package/public/dist/assets/CodeCanvas-CVbdp0S-.js +0 -3
- package/public/dist/assets/FolderPanel-CJvwRwIV.js +0 -3
- package/public/dist/assets/manager-CCXm5Yfe.js +0 -5
- package/public/dist/assets/manager-D9rhKFKc.css +0 -1
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-CkEUZM6i.js";import{c as r}from"./api-B9RiiOMM.js";import{t as i}from"./desktop-bridge-DbRfkg8l.js";import{n as a,t as o}from"./client-platform-WO8m6kPQ.js";import{t as s}from"./copy-text-WsUHYigB.js";import{n as c,t as l}from"./folder-drag-payload-BhV9yzhH.js";var u=e(t(),1);function d(e){return{name:e.name,path:e.path,kind:e.kind===`folder`?`directory`:`file`,size:e.size}}function f(e,t){for(let n of e){if(n.path===t)return n;let e=f(n.children??[],t);if(e)return e}return null}function p(e){return{kind:`electron-folder`,label:`Folder`,canPickRoot:!0,getInitialRoot:async()=>null,pickRoot:async()=>{let t=await e.pickFolder();if(!t.ok&&t.error===`cancelled`)return null;if(!t.ok)throw Error(t.error??`Failed to pick folder`);return t.path??null},registerGitWorktreeRoot:async(t,n,r)=>{let i=await e.registerGitWorktreeRoot?.(t,n,r);if(!i?.ok)throw Error(i?.error??`Failed to register worktree root`)},authorizeRoot:async t=>{let n=await e.authorizeRoot?.(t);if(!n?.ok)throw Error(n?.error??`Failed to authorize folder root`);return n.path??t},listDir:async t=>{let n=await e.listDir(t);if(!n.ok||!n.entries)throw Error(n.error??`Failed to list directory`);return n.entries},readFile:async t=>{let n=await e.readFile(t);if(!n.ok||n.content===void 0)throw Error(n.error??`Failed to read file`);return{content:n.content,...n.binary===void 0?{}:{binary:n.binary}}},movePath:async(t,n)=>{let r=await e.movePath(t,n);if(!r.ok)throw Error(r.error??`Failed to move path`);return r},createFile:async(t,n)=>{let r=await e.createFile(t,n);if(!r.ok)throw Error(r.error??`Failed to create file`);return r},createFolder:async(t,n)=>{let r=await e.createFolder(t,n);if(!r.ok)throw Error(r.error??`Failed to create folder`);return r},renamePath:async(t,n)=>{let r=await e.renamePath(t,n);if(!r.ok)throw Error(r.error??`Failed to rename path`);return r},revealPath:async t=>{let n=await e.revealPath(t);if(!n.ok)throw Error(n.error??`Failed to reveal path`)},watchDir:t=>e.watchDir(t),unwatchDir:t=>e.unwatchDir(t),onDirChange:t=>e.onDirChange(t)}}function m(e,t){return{kind:`notes-vault`,label:t?`Notes: ${t.split(`/`).pop()||t}`:`Notes vault`,canPickRoot:!1,getInitialRoot:async()=>``,listDir:async t=>{if(!t)return e.map(d);let n=f(e,t);return!n||n.kind!==`folder`?[]:(n.children??[]).map(d)},readFile:async e=>({content:(await r(e)).content,binary:!1})}}var h=n();function g(e){return(0,h.jsxs)(`div`,{className:`folder-action-row`,"aria-label":`Folder actions`,children:[(0,h.jsx)(`button`,{type:`button`,className:`folder-action-btn`,disabled:!e.hasSelection,onClick:e.onCopyPath,children:`Copy`}),(0,h.jsx)(`button`,{type:`button`,className:`folder-action-btn`,disabled:!e.hasSelection,onClick:e.onCopyRelativePath,children:`Relative`}),(0,h.jsx)(`button`,{type:`button`,className:`folder-action-btn`,disabled:!e.hasSelection||!e.canReveal,onClick:e.onReveal,children:`Finder`}),(0,h.jsx)(`button`,{type:`button`,className:`folder-action-btn`,disabled:!e.canMutate,onClick:e.onCreateFile,children:`New File`}),(0,h.jsx)(`button`,{type:`button`,className:`folder-action-btn`,disabled:!e.canMutate,onClick:e.onCreateFolder,children:`New Folder`}),(0,h.jsx)(`button`,{type:`button`,className:`folder-action-btn`,disabled:!e.hasSelection||!e.canMutate,onClick:e.onRename,children:`Rename`})]})}function _(e){return(0,h.jsxs)(`div`,{className:`folder-context-menu`,role:`menu`,style:{left:e.x,top:e.y},onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:[(0,h.jsx)(`button`,{type:`button`,role:`menuitem`,onClick:e.onCopyPath,children:`Copy Path`}),(0,h.jsx)(`button`,{type:`button`,role:`menuitem`,onClick:e.onCopyRelativePath,children:`Copy Relative Path`}),(0,h.jsx)(`button`,{type:`button`,role:`menuitem`,disabled:!e.canReveal,onClick:e.onReveal,children:e.entry.kind===`directory`?`Open Folder`:`Reveal in Finder`}),(0,h.jsx)(`button`,{type:`button`,role:`menuitem`,disabled:!e.canMutate,onClick:e.onCreateFile,children:`New File`}),(0,h.jsx)(`button`,{type:`button`,role:`menuitem`,disabled:!e.canMutate,onClick:e.onCreateFolder,children:`New Folder`}),(0,h.jsx)(`button`,{type:`button`,role:`menuitem`,disabled:!e.canMutate,onClick:e.onRename,children:`Rename`}),e.canRefresh&&(0,h.jsx)(`button`,{type:`button`,role:`menuitem`,onClick:e.onRefresh,children:`Refresh`})]})}function v(e){return(0,h.jsxs)(`div`,{className:`folder-move-confirm`,role:`dialog`,"aria-label":`Confirm folder move`,children:[(0,h.jsxs)(`div`,{className:`folder-move-confirm__title`,children:[`Move "`,e.source.name,`" into "`,e.target.name,`"?`]}),(0,h.jsxs)(`label`,{className:`folder-move-confirm__option`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:e.skipChecked,onChange:t=>e.onSkipCheckedChange(t.target.checked)}),`Don't ask again for internal moves this session`]}),(0,h.jsxs)(`div`,{className:`folder-move-confirm__actions`,children:[(0,h.jsx)(`button`,{type:`button`,className:`folder-action-btn`,disabled:e.busy,onClick:e.onCancel,children:`Cancel`}),(0,h.jsx)(`button`,{type:`button`,className:`folder-action-btn is-primary`,disabled:e.busy,onClick:e.onConfirm,children:e.busy?`Moving...`:`Move`})]})]})}function y(e){return(0,h.jsxs)(h.Fragment,{children:[e.pendingMove&&(0,h.jsx)(v,{source:e.pendingMove.source,target:e.pendingMove.target,busy:e.isMoving,skipChecked:e.skipMoveConfirmChecked,onSkipCheckedChange:e.onSkipMoveConfirmCheckedChange,onCancel:e.onCancelMove,onConfirm:e.onConfirmMove}),e.contextMenu&&(0,h.jsx)(_,{entry:e.contextMenu.entry,x:e.contextMenu.x,y:e.contextMenu.y,canReveal:e.canReveal,canRefresh:e.canRefresh,canMutate:e.canMutate,onCopyPath:e.onCopyContextPath,onCopyRelativePath:e.onCopyContextRelativePath,onReveal:e.onRevealContextPath,onRefresh:e.onRefreshContext,onCreateFile:e.onCreateContextFile,onCreateFolder:e.onCreateContextFolder,onRename:e.onRenameContextPath})]})}function b(e){return e===null?`Open Folder`:e.split(`/`).pop()||e}function x(e){return e.split(`/`).filter(Boolean).pop()||e}function S(e){return e.branch?e.branch:e.detached?e.head?`detached ${e.head}`:`detached`:e.head??`worktree`}function ee(e){let[t,n]=(0,u.useState)(!1),r=e.gitSummary?.loading?`Git ...`:e.gitSummary?.available?`${e.gitSummary.branch??e.gitSummary.head??`detached`} / ${e.gitSummary.dirty?`dirty`:`clean`}`:e.gitSummary?.error?`Git unavailable`:null,i=e.worktreeSummary?.worktrees??[],a=e.rootPath!==null&&(e.worktreeSummary?.loading||e.worktreeSummary?.error||i.length>0),o=e.worktreeSummary?.loading?`Worktrees ...`:i.length>0?`Worktrees ${i.length}`:`Worktrees`;return(0,h.jsxs)(`div`,{className:`folder-toolbar`,children:[(0,h.jsx)(`button`,{type:`button`,className:`folder-pick-btn`,onClick:e.onPickFolder,disabled:!e.canPickRoot,children:e.canPickRoot?b(e.rootPath):e.label}),r&&(0,h.jsx)(`span`,{className:e.gitSummary?.error?`folder-git-summary is-error`:`folder-git-summary`,title:e.gitSummary?.error??void 0,children:r}),a&&(0,h.jsxs)(`div`,{className:`folder-worktree`,children:[(0,h.jsx)(`button`,{type:`button`,className:`folder-worktree-btn`,onClick:()=>n(e=>!e),disabled:e.worktreeSummary?.loading||i.length===0,title:e.worktreeSummary?.error??void 0,children:o}),t&&i.length>0&&(0,h.jsx)(`div`,{className:`folder-worktree-menu`,role:`menu`,"aria-label":`Git worktrees`,children:i.map(t=>(0,h.jsxs)(`div`,{className:`folder-worktree-row`,role:`group`,"aria-label":t.path,children:[(0,h.jsxs)(`button`,{type:`button`,className:`folder-worktree-open`,onClick:()=>{n(!1),e.onOpenWorktree?.(t.path)},children:[(0,h.jsxs)(`span`,{className:`folder-worktree-title`,children:[x(t.path),t.current&&(0,h.jsx)(`span`,{className:`folder-worktree-current`,children:`Current`})]}),(0,h.jsxs)(`span`,{className:`folder-worktree-meta`,children:[S(t),` · `,t.path]})]}),(0,h.jsxs)(`span`,{className:`folder-worktree-actions`,children:[(0,h.jsx)(`button`,{type:`button`,onClick:()=>e.onCopyWorktreePath?.(t.path),children:`Copy`}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>e.onRevealWorktreePath?.(t.path),children:`Finder`})]})]},t.path))})]}),e.rootPath!==null&&e.gitSummary?.available&&e.onOpenWorktreeOps&&(0,h.jsx)(`button`,{type:`button`,className:`folder-worktree-btn`,onClick:e.onOpenWorktreeOps,children:`Ops`}),e.rootPath!==null&&(0,h.jsx)(`button`,{type:`button`,className:`folder-refresh`,onClick:e.onRefresh,"aria-label":`Refresh folder`,children:`↻`})]})}async function C(e,t){return await(await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)})).json()}async function w(e){let t=e.repoRoot??void 0;try{let n=i()?.git,r=n?await n.previewWorktreeOperation(e.folderPanelRoot,t,e.operation):null,a=r?.ok?r:await C(`/api/dashboard/git/worktree-operation-preview`,{folderPanelRoot:e.folderPanelRoot,...t?{repoRoot:t}:{},operation:e.operation});return{ok:a.ok,preview:a.preview??null,error:a.ok?null:a.error??`Failed to preview git operation`}}catch(e){return{ok:!1,preview:null,error:e instanceof Error?e.message:`Failed to preview git operation`}}}async function T(e){let t=e.repoRoot??void 0;try{let n=i()?.git,r=n?await n.runWorktreeOperation(e.folderPanelRoot,t,e.operation,e.confirmed):null,a=r?.ok?r:await C(`/api/dashboard/git/worktree-operation`,{folderPanelRoot:e.folderPanelRoot,...t?{repoRoot:t}:{},operation:e.operation,confirmed:e.confirmed});return{ok:a.ok,repoRoot:a.repoRoot??null,preview:a.preview??null,stdout:a.stdout??``,worktrees:a.worktrees??[],error:a.ok?null:a.error??`Git operation failed`}}catch(e){return{ok:!1,repoRoot:null,preview:null,stdout:``,worktrees:[],error:e instanceof Error?e.message:`Git operation failed`}}}function E(e){return e.length>0?e.join(` `):`Command unavailable`}function D(e){return e.status===`running`?`Running`:e.status===`succeeded`?`Done`:e.status===`blocked`?`Blocked`:e.status===`cancelled`?`Cancelled`:`Failed`}function te(e){return e.history.length===0?null:(0,h.jsxs)(`div`,{className:`folder-worktree-history`,"aria-label":`Git worktree operation history`,children:[(0,h.jsx)(`div`,{className:`folder-worktree-history__title`,children:`Recent operations`}),e.history.map(t=>(0,h.jsxs)(`div`,{className:`folder-worktree-history__item is-${t.status}`,children:[(0,h.jsxs)(`div`,{className:`folder-worktree-history__main`,children:[(0,h.jsx)(`span`,{className:`folder-worktree-history__label`,children:t.operationLabel}),(0,h.jsx)(`span`,{className:`folder-worktree-history__status`,children:D(t)})]}),(0,h.jsx)(`div`,{className:`folder-worktree-history__command`,title:E(t.commandPreview),children:E(t.commandPreview)}),t.stdout&&(0,h.jsx)(`pre`,{className:`folder-worktree-history__output`,children:t.stdout}),t.stderr&&(0,h.jsx)(`pre`,{className:`folder-worktree-history__output is-error`,children:t.stderr}),t.error&&(0,h.jsx)(`div`,{className:`folder-worktree-history__error`,children:t.error}),(0,h.jsx)(`button`,{type:`button`,className:`folder-worktree-history__retry`,disabled:e.busy||t.status===`running`,onClick:()=>e.onRetry(t.operation),children:`Retry with confirmation`})]},t.id))]})}function ne(e){return e.split(`/`).filter(Boolean).pop()||e}function re(e){return e?e.command.join(` `):`Preview unavailable`}function ie(e){let[t,n]=(0,u.useState)(`worktree-add`),[r,i]=(0,u.useState)(``),[a,o]=(0,u.useState)(``),[s,c]=(0,u.useState)(!1),[l,d]=(0,u.useState)(e.worktrees.find(e=>!e.current)?.path??e.worktrees[0]?.path??``),[f,p]=(0,u.useState)(!1),[m,g]=(0,u.useState)(!1),[_,v]=(0,u.useState)(!1),[y,b]=(0,u.useState)(null),[x,S]=(0,u.useState)(null),ee=(0,u.useCallback)(e=>{n(e.type),g(!1),e.type===`worktree-add`&&(i(e.path),o(e.branch),c(e.createBranch)),e.type===`worktree-remove`&&(d(e.path),p(e.force))},[]),C=(0,u.useMemo)(()=>t===`worktree-add`?{type:t,path:r,branch:a,createBranch:s}:t===`worktree-remove`?{type:t,path:l,force:f}:{type:t},[a,s,f,t,l,r]);(0,u.useEffect)(()=>{let t=!1;return g(!1),v(!0),b(null),S(null),(async()=>{let n=await w({folderPanelRoot:e.folderPanelRoot,repoRoot:e.repoRoot,operation:C});t||(v(!1),S(n.preview),b(n.error))})(),()=>{t=!0}},[C,e.folderPanelRoot,e.repoRoot]);let T=m&&x!==null&&!y&&!_&&!e.busy,E=t===`worktree-remove`;return(0,h.jsx)(`div`,{className:`folder-worktree-ops`,role:`dialog`,"aria-label":`Git worktree operations`,children:(0,h.jsxs)(`div`,{className:`folder-worktree-ops__panel`,children:[(0,h.jsxs)(`div`,{className:`folder-worktree-ops__header`,children:[(0,h.jsx)(`span`,{children:`Worktree Ops`}),(0,h.jsx)(`button`,{type:`button`,onClick:e.onClose,disabled:e.busy,children:`Close`})]}),(0,h.jsx)(`div`,{className:`folder-worktree-ops__row`,children:(0,h.jsxs)(`label`,{children:[`Operation`,(0,h.jsxs)(`select`,{value:t,onChange:e=>n(e.target.value),disabled:e.busy,children:[(0,h.jsx)(`option`,{value:`worktree-add`,children:`Add worktree`}),(0,h.jsx)(`option`,{value:`worktree-remove`,children:`Remove worktree`}),(0,h.jsx)(`option`,{value:`worktree-prune`,children:`Prune stale worktrees`})]})]})}),t===`worktree-add`&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`div`,{className:`folder-worktree-ops__row`,children:(0,h.jsxs)(`label`,{children:[`Path`,(0,h.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),placeholder:`/Users/jun/...`,disabled:e.busy})]})}),(0,h.jsxs)(`div`,{className:`folder-worktree-ops__row`,children:[(0,h.jsxs)(`label`,{children:[`Branch / ref`,(0,h.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),placeholder:`feature/name`,disabled:e.busy})]}),(0,h.jsxs)(`label`,{className:`folder-worktree-ops__check`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),disabled:e.busy}),`Create branch`]})]})]}),E&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`div`,{className:`folder-worktree-ops__row`,children:(0,h.jsxs)(`label`,{children:[`Worktree`,(0,h.jsx)(`select`,{value:l,onChange:e=>d(e.target.value),disabled:e.busy,children:e.worktrees.map(e=>(0,h.jsxs)(`option`,{value:e.path,children:[ne(e.path),` - `,e.path]},e.path))})]})}),(0,h.jsxs)(`label`,{className:`folder-worktree-ops__warning`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked),disabled:e.busy}),`Force remove dirty worktree`]})]}),(0,h.jsx)(`div`,{className:`folder-worktree-ops__preview`,"aria-busy":_,children:_?`Previewing command...`:re(x)}),y&&(0,h.jsx)(`div`,{className:`folder-worktree-ops__warning`,children:y}),E&&!f&&(0,h.jsx)(`div`,{className:`folder-worktree-ops__hint`,children:`Dirty worktrees are blocked unless force remove is explicitly checked.`}),E&&f&&(0,h.jsx)(`div`,{className:`folder-worktree-ops__hint`,children:`Preview changes to git worktree remove --force for this target.`}),(0,h.jsxs)(`label`,{className:`folder-worktree-ops__check`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:m,onChange:e=>g(e.target.checked),disabled:x===null||!!y||e.busy}),`I understand this will run the previewed git command.`]}),(0,h.jsxs)(`div`,{className:`folder-worktree-ops__actions`,children:[(0,h.jsx)(`button`,{type:`button`,className:`folder-action-btn`,onClick:e.onClose,disabled:e.busy,children:`Cancel`}),(0,h.jsx)(`button`,{type:`button`,className:`folder-action-btn is-primary`,disabled:!T,onClick:()=>e.onRun(C,x),children:e.busy?`Running...`:`Run`})]}),(0,h.jsx)(te,{history:e.history,busy:e.busy,onRetry:ee})]})})}function ae(e){let t=e.lastIndexOf(`/`);return t>0?e.slice(0,t):`/`}function O(e,t){return t===e||t.startsWith(`${e}/`)}function oe(e,t){if(!e)return t;let n=e.endsWith(`/`)?e:`${e}/`;return t.startsWith(n)?t.slice(n.length):t}function se(e,t){let n=new Map(e);for(let e of t)n.delete(e);return n}function ce(e){let t=(0,u.useRef)(null);return(0,u.useEffect)(()=>{let e=t.current;e&&(e.focus(),e.select())},[e.initialName]),(0,h.jsx)(`form`,{className:`folder-inline-editor`,"aria-label":e.label,onSubmit:n=>{n.preventDefault();let r=t.current?.value.trim()??``;r&&e.onSubmit(r)},children:(0,h.jsx)(`input`,{ref:t,className:`folder-inline-editor__input`,defaultValue:e.initialName,disabled:e.busy,onBlur:()=>{e.busy||e.onCancel()},onKeyDown:t=>{t.key===`Escape`&&(t.preventDefault(),e.onCancel()),t.stopPropagation()}})})}function k(){return o()}function le(e){if(typeof HTMLElement>`u`||!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;let t=e.tagName.toLowerCase();return t===`input`||t===`textarea`||t===`select`||!!e.closest(`[contenteditable="true"], .cm-editor, .ProseMirror, [data-milkdown-root], [role="textbox"]`)}function ue(e,t=k()){return a(t)?e.metaKey:e.ctrlKey}function de(e,t){if(le(e.target??null))return null;let n=e.key.toLowerCase(),r=e.code??``,i=a(t.platform??k())?e.metaKey:e.ctrlKey,o=i&&e.altKey&&!e.shiftKey;return t.chordActive?n===`escape`?`cancel-chord`:i||e.altKey||e.shiftKey?null:n===`p`||r===`KeyP`?`copy-path`:n===`r`||r===`KeyR`?`reveal-path`:`cancel-chord`:i&&!e.altKey&&!e.shiftKey&&(n===`k`||r===`KeyK`)?`start-chord`:o&&(n===`c`||r===`KeyC`)?`copy-path`:o&&(n===`r`||r===`KeyR`)?`reveal-path`:i&&!e.altKey&&n===`c`?e.shiftKey?`copy-path`:`copy-relative-path`:null}function A(e){window.dispatchEvent(new CustomEvent(`jaw-folder-panel-drag`,{detail:{active:e}}))}function fe(e){let t=e.inlineMutation&&e.inlineMutation.kind!==`rename`&&e.inlineMutation.parentDirectory===e.parentPath?e.inlineMutation:null;return(0,h.jsxs)(h.Fragment,{children:[t&&(0,h.jsxs)(`div`,{className:`folder-entry folder-entry-inline`,children:[e.depth>0&&(0,h.jsx)(`span`,{className:`folder-indent`,"aria-hidden":`true`,children:Array.from({length:e.depth},(e,t)=>(0,h.jsx)(`span`,{className:`folder-indent-guide`},t))}),(0,h.jsx)(`span`,{className:`folder-entry-disclosure is-placeholder`,"aria-hidden":`true`,children:`·`}),(0,h.jsx)(ce,{initialName:t.initialName,busy:e.isMutating,label:t.kind===`file`?`New file name`:`New folder name`,onSubmit:e.submitInlineMutation,onCancel:e.cancelInlineMutation})]}),e.entries.map(t=>(0,h.jsxs)(`div`,{children:[(()=>{let n=e.decorationsByPath.get(t.path),r=e.inlineMutation?.kind===`rename`&&e.inlineMutation.targetPath===t.path?e.inlineMutation:null;return(0,h.jsxs)(`div`,{className:[`folder-entry`,`folder-entry-${t.kind}`,n?.className??``,e.selectedPaths.has(t.path)?`is-selected`:``,e.focusedPath===t.path?`is-focused`:``,e.dropTargetPath===t.path?`is-drop-target`:``,e.dragSelection?.primaryEntry.path===t.path?`is-dragging`:``].filter(Boolean).join(` `),role:`treeitem`,"aria-selected":e.selectedPaths.has(t.path),draggable:e.canUseNativeActions,onDragStart:n=>{if(!e.canUseNativeActions)return;let r=e.getDragSelectionFor(t);e.setDragSelection(r),A(!0),n.dataTransfer.effectAllowed=`copyMove`,n.dataTransfer.setData(l,c(r)),n.dataTransfer.setData(`text/plain`,r.entries.map(e=>e.path).join(`
|
|
2
|
-
`))},onDragEnd:()=>{A(!1),e.setDragSelection(null),e.setDropTargetPath(null)},onDragOver:n=>{let r=e.dragSelection?.primaryEntry;r&&t.kind===`directory`&&r.path!==t.path&&(r.kind===`directory`&&O(r.path,t.path)||(n.preventDefault(),n.dataTransfer.dropEffect=`move`,e.setDropTargetPath(t.path)))},onDragLeave:()=>{e.dropTargetPath===t.path&&e.setDropTargetPath(null)},onDrop:n=>{e.dragSelection&&t.kind===`directory`&&(n.preventDefault(),A(!1),e.setDropTargetPath(null),e.requestMove(e.dragSelection.primaryEntry,t))},children:[e.depth>0&&(0,h.jsx)(`span`,{className:`folder-indent`,"aria-hidden":`true`,children:Array.from({length:e.depth},(e,t)=>(0,h.jsx)(`span`,{className:`folder-indent-guide`},t))}),(0,h.jsx)(`button`,{type:`button`,className:t.kind===`directory`?`folder-entry-disclosure`:`folder-entry-disclosure is-placeholder`,"aria-label":t.kind===`directory`?e.expanded.has(t.path)?`Collapse ${t.name}`:`Expand ${t.name}`:void 0,"aria-expanded":t.kind===`directory`?e.expanded.has(t.path):void 0,tabIndex:t.kind===`directory`?0:-1,disabled:t.kind!==`directory`,onClick:n=>{n.stopPropagation(),t.kind===`directory`&&e.toggleEntryExpansion(t)},children:t.kind===`directory`?e.expanded.has(t.path)?`▾`:`▸`:`·`}),r?(0,h.jsx)(ce,{initialName:r.initialName,busy:e.isMutating,label:`Rename`,onSubmit:e.submitInlineMutation,onCancel:e.cancelInlineMutation}):(0,h.jsxs)(`button`,{type:`button`,className:`folder-entry-btn`,"data-folder-path":t.path,onKeyDown:n=>e.handleEntryKeyDown(n,t),onContextMenu:n=>{n.preventDefault(),e.openContextMenu(t,n.clientX,n.clientY)},onClick:n=>e.selectEntry(t,{range:n.shiftKey,toggle:ue(n),preview:!1}),onDoubleClick:()=>{t.kind===`directory`?e.toggleEntryExpansion(t):e.openFileEntry(t)},children:[(0,h.jsx)(`span`,{className:`folder-entry-name`,children:t.name}),n?.label&&(0,h.jsx)(`span`,{className:`folder-entry-git-badge`,title:n.title,"aria-label":n.title??n.label,children:n.label})]})]})})(),t.kind===`directory`&&e.expanded.has(t.path)&&e.childrenCache.has(t.path)&&(0,h.jsx)(fe,{...e,entries:e.childrenCache.get(t.path),parentPath:t.path,depth:e.depth+1})]},t.path))]})}function pe(e){return(0,h.jsxs)(`div`,{className:`folder-unavailable`,children:[(0,h.jsx)(`div`,{className:`folder-unavailable__title`,children:`Folder unavailable`}),(0,h.jsx)(`div`,{className:`folder-unavailable__path`,title:e.path,children:e.path}),(0,h.jsx)(`div`,{className:`folder-unavailable__error`,children:e.error}),(0,h.jsxs)(`div`,{className:`folder-unavailable__actions`,children:[(0,h.jsx)(`button`,{type:`button`,className:`folder-action-btn`,onClick:e.onOpenFolder,children:`Open Folder`}),(0,h.jsx)(`button`,{type:`button`,className:`folder-action-btn`,onClick:e.onClear,children:`Clear`})]})]})}function me(e){return(0,h.jsxs)(`div`,{ref:e.treeRef,className:e.rootPath===null?`folder-tree folder-empty-root`:`folder-tree`,role:`tree`,"aria-multiselectable":`true`,children:[(0,h.jsx)(fe,{entries:e.entries,parentPath:e.rootPath,depth:0,expanded:e.expanded,childrenCache:e.childrenCache,selectedPaths:e.folderSelection.selectedPaths,focusedPath:e.folderSelection.selection.focusedPath,decorationsByPath:e.decorationsByPath,dropTargetPath:e.dropTargetPath,dragSelection:e.dragSelection,inlineMutation:e.inlineMutation,isMutating:e.isMutating,canUseNativeActions:e.canUseNativeActions,setDragSelection:e.setDragSelection,setDropTargetPath:e.setDropTargetPath,getDragSelectionFor:e.folderSelection.getDragSelectionFor,requestMove:e.requestMove,handleEntryKeyDown:e.handleEntryKeyDown,selectEntry:e.selectEntry,toggleEntryExpansion:e.toggleEntryExpansion,openFileEntry:e.openFileEntry,openContextMenu:e.openContextMenu,submitInlineMutation:e.submitInlineMutation,cancelInlineMutation:e.cancelInlineMutation}),e.rootPath===null&&!e.error&&(0,h.jsx)(`div`,{className:`folder-empty-root__content`,children:`Choose a folder to browse files.`}),e.unavailableRoot&&(0,h.jsx)(pe,{path:e.unavailableRoot.path,error:e.unavailableRoot.error,onOpenFolder:e.onPickFolder,onClear:e.onClearUnavailableRoot}),e.entries.length===0&&!e.inlineMutation&&!e.error&&!e.unavailableRoot&&e.rootPath!==null&&(0,h.jsx)(`div`,{className:`folder-empty`,children:e.sourceKind===`notes-vault`?`No notes in vault`:`Empty directory`})]})}var j={selectedPaths:[],focusedPath:null,anchorPath:null};function he(e,t,n){let r=[],i=e=>{for(let a of e)r.push(a),a.kind===`directory`&&n.has(a.path)&&i(t.get(a.path)??[])};return i(e),r}function ge(e,t){let n=new Set(t),r=e.selectedPaths.filter(e=>n.has(e)),i=e.focusedPath&&n.has(e.focusedPath)?e.focusedPath:r[0]??null;return{selectedPaths:r,focusedPath:i,anchorPath:e.anchorPath&&n.has(e.anchorPath)?e.anchorPath:i}}function M(e,t,n,r={}){if(!n.includes(t))return e;if(r.range&&e.anchorPath&&n.includes(e.anchorPath))return{selectedPaths:ye(n,e.anchorPath,t),focusedPath:t,anchorPath:e.anchorPath};if(r.toggle){let r=new Set(e.selectedPaths);return r.has(t)?r.delete(t):r.add(t),r.size===0&&r.add(t),{selectedPaths:n.filter(e=>r.has(e)),focusedPath:t,anchorPath:t}}return{selectedPaths:[t],focusedPath:t,anchorPath:t}}function _e(e,t,n,r){if(t.length===0)return j;let i=e.focusedPath&&t.includes(e.focusedPath)?e.focusedPath:e.selectedPaths.find(e=>t.includes(e))??t[0],a=t.indexOf(i),o=t[Math.max(0,Math.min(t.length-1,a+(n===`down`?1:-1)))];if(r){let n=e.anchorPath&&t.includes(e.anchorPath)?e.anchorPath:i;return{selectedPaths:ye(t,n,o),focusedPath:o,anchorPath:n}}return{selectedPaths:[o],focusedPath:o,anchorPath:o}}function ve(e,t){return e.filter(e=>t.has(e.path))}function ye(e,t,n){let r=e.indexOf(t),i=e.indexOf(n);if(r<0||i<0)return[n];let a=Math.min(r,i),o=Math.max(r,i);return e.slice(a,o+1)}function N(e){return Array.from(e.entries())}function be(e){return new Map(e)}function xe(e,t){return!e||t&&e.rootPath!==t?null:e}function Se(e){return{rootPath:e.rootPath,entries:e.entries,expandedPaths:Array.from(e.expanded),childrenCache:N(e.childrenCache),selection:e.selection}}function P(e){return/not a git repository/i.test(e)}async function Ce(e,t){return await(await fetch(`/api/dashboard/git/status-map`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({folderPanelRoot:e,...t.repoRoot?{repoRoot:t.repoRoot}:{},options:{includeIgnored:t.includeIgnored!==!1,includeUntracked:t.includeUntracked!==!1}})})).json()}async function F(e,t={}){let n=i()?.git,r=n?await n.getStatusMap(e,t.repoRoot,{includeIgnored:t.includeIgnored!==!1,includeUntracked:t.includeUntracked!==!1}):null,a=r?.ok?r:await Ce(e,t);if(a.ok&&a.status)return{ok:!0,status:a.status};let o=a.error??`Failed to load git status`;return{ok:!1,quiet:P(o),error:o}}var I={available:!1,loading:!1,error:null,repoRoot:null,branch:null,head:null,dirty:!1,decorationsByPath:new Map},we={modified:`M`,added:`A`,deleted:`D`,renamed:`R`,untracked:`?`,ignored:`·`,conflict:`U`,submodule:`S`};function L(e){return{className:`git-${e.kind}`,label:we[e.kind],title:[e.kind,e.staged?`staged`:``,e.unstaged?`unstaged`:``].filter(Boolean).join(` · `)}}function R(e){let t=e.kinds[0]??`modified`;return{className:`git-${t}`,label:`${we[t]}${e.changedCount>1?e.changedCount:``}`,title:`${e.changedCount} changed item${e.changedCount===1?``:`s`}`}}function z(e){let t=new Map;for(let n of e.files)t.set(n.path,L(n));for(let n of e.directories)t.set(n.path,R(n));return{available:!0,loading:!1,error:null,repoRoot:e.repoRoot,branch:e.branch,head:e.head,dirty:e.dirty,decorationsByPath:t}}function Te(e){let{rootPath:t,repoRoot:n,enabled:r,refreshToken:i}=e,[a,o]=(0,u.useState)(I);return(0,u.useEffect)(()=>{if(!r||t===null){o(I);return}let e=!1,i=window.setTimeout(()=>{o(e=>({...e,loading:!0,error:null})),(async()=>{let r=await F(t,{...n?{repoRoot:n}:{},includeIgnored:!0,includeUntracked:!0});if(!e){if(r.ok){o(z(r.status));return}if(n&&/repo root mismatch/i.test(r.error)){let n=await F(t,{includeIgnored:!0,includeUntracked:!0});if(e)return;if(n.ok){o(z(n.status));return}o(n.quiet?I:{...I,error:n.error});return}o(r.quiet?I:{...I,error:r.error})}})()},250);return()=>{e=!0,window.clearTimeout(i)}},[r,i,n,t]),a}function B(e){return/not a git repository/i.test(e)}async function V(e,t){return await(await fetch(`/api/dashboard/git/worktrees`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({folderPanelRoot:e,...t?{repoRoot:t}:{}})})).json()}async function H(e,t){let n=t??void 0;try{let t=i()?.git,r=t?await t.getWorktrees(e,n):null,a=r?.ok?r:await V(e,n);if(a.ok)return{ok:!0,repoRoot:a.repoRoot??n??null,worktrees:a.worktrees??[],error:null};let o=a.error??`Failed to load git worktrees`;return{ok:!1,repoRoot:null,worktrees:[],error:B(o)?null:o}}catch(e){let t=e instanceof Error?e.message:`Failed to load git worktrees`;return{ok:!1,repoRoot:null,worktrees:[],error:B(t)?null:t}}}var U={available:!1,loading:!1,error:null,repoRoot:null,worktrees:[]};function Ee(e){let{folderPanelRoot:t,repoRoot:n,enabled:r,refreshToken:i}=e,[a,o]=(0,u.useState)(0),[s,c]=(0,u.useState)(U),l=(0,u.useCallback)(()=>o(e=>e+1),[]);return(0,u.useEffect)(()=>{if(!r||t===null){c(U);return}let e=!1;return c(e=>({...e,loading:!0,error:null})),(async()=>{let r=await H(t,n??void 0);e||c({available:r.ok&&r.worktrees.length>0,loading:!1,error:r.error,repoRoot:r.repoRoot,worktrees:r.worktrees})})(),()=>{e=!0}},[r,t,a,i,n]),(0,u.useMemo)(()=>({...s,refresh:l}),[l,s])}function De(e=1600){let[t,n]=(0,u.useState)(!1),r=(0,u.useRef)(null),i=(0,u.useCallback)(()=>{r.current!==null&&window.clearTimeout(r.current),r.current=null,n(!1)},[]),a=(0,u.useCallback)(()=>{r.current!==null&&window.clearTimeout(r.current),n(!0),r.current=window.setTimeout(()=>{r.current=null,n(!1)},e)},[e]);return(0,u.useEffect)(()=>()=>i(),[i]),{folderChordActive:t,startFolderChord:a,cancelFolderChord:i}}function Oe(e){let t=e.onPreviewFile,[n,r]=(0,u.useState)(()=>e.initialSelection??j),i=(0,u.useMemo)(()=>he(e.entries,e.childrenCache,e.expanded),[e.childrenCache,e.entries,e.expanded]),a=(0,u.useMemo)(()=>i.map(e=>e.path),[i]),o=(0,u.useMemo)(()=>new Set(n.selectedPaths),[n.selectedPaths]),s=(0,u.useMemo)(()=>ve(i,o),[o,i]),c=n.focusedPath??s[0]?.path??null,l=i.find(e=>e.path===c)??s[0]??null;return(0,u.useEffect)(()=>{r(e=>ge(e,a))},[a]),{selection:n,visibleEntries:i,visiblePaths:a,selectedPaths:o,selectedPath:c,selectedEntries:s,selectedEntry:l,selectEntry:(0,u.useCallback)((e,n={})=>{r(t=>M(t,e.path,a,n)),e.kind===`file`&&n.preview!==!1&&t?.(e.path)},[t,a]),selectOnlyPath:(0,u.useCallback)(e=>{r(e&&a.includes(e)?{selectedPaths:[e],focusedPath:e,anchorPath:e}:j)},[a]),resetSelection:(0,u.useCallback)(()=>{r(j)},[]),moveKeyboardSelection:(0,u.useCallback)((e,t)=>{r(n=>_e(n,a,e,t))},[a]),getDragSelectionFor:(0,u.useCallback)(e=>o.has(e.path)?{primaryEntry:e,entries:s}:{primaryEntry:e,entries:[e]},[s,o])}}var ke=120,Ae=80;function W(e){return e===`watch`?`Updated from file changes`:e===`move`?`Updated after move`:e===`mutation`?`Updated after file change`:e===`git-operation`?`Updated after git operation`:e===`worktree-switch`?`Updated worktree`:e===`root`?`Updated folder root`:`Updated folder`}function je(e){let{rootPath:t,expanded:n,source:r,loadDir:i,loadChildren:a,bumpGitRefresh:o,onGitRefresh:s,refreshWorktrees:c}=e,[l,d]=(0,u.useState)(null),[f,p]=(0,u.useState)(null),[m,h]=(0,u.useState)(!1),g=(0,u.useRef)(!1),_=(0,u.useRef)(null),v=(0,u.useRef)(null),y=(0,u.useRef)(async()=>void 0),b=(0,u.useRef)(!0);(0,u.useEffect)(()=>(b.current=!0,()=>{b.current=!1}),[]);let x=(0,u.useCallback)(()=>{v.current!==null&&(window.clearTimeout(v.current),v.current=null)},[]),S=(0,u.useCallback)(async(e,r={})=>{if(t!==null){if(g.current){let t=_.current;_.current=t?{reason:e,options:{extraPaths:Array.from(new Set([...t.options.extraPaths??[],...r.extraPaths??[]]))}}:{reason:e,options:r};return}g.current=!0,b.current&&(h(!0),d(e===`watch`?`Refreshing changed files...`:`Refreshing folder...`));try{let l=Array.from(new Set([...Array.from(n),...r.extraPaths??[]])).slice(0,Ae);await i(t);for(let e of l)await a(e,{force:!0});if(o(),s?.(),c(),!b.current)return;let u=Math.max(0,n.size-l.length);d(u>0?`${W(e)}; ${u} collapsed/overflow branches skipped`:W(e))}finally{g.current=!1,b.current&&h(!1);let e=_.current;_.current=null,e&&b.current&&y.current(e.reason,e.options)}}},[o,n,a,i,s,c,t]),ee=(0,u.useCallback)(async(e=`manual`,t={})=>{await S(e,t)},[S]);(0,u.useEffect)(()=>{y.current=S},[S]);let C=(0,u.useCallback)(()=>{x(),v.current=window.setTimeout(()=>{v.current=null,y.current(`watch`)},ke)},[x]);return(0,u.useEffect)(()=>{if(!r.watchDir||!r.onDirChange||t===null)return;let e=!1;(async()=>{let n=await r.watchDir?.(t);e||(n&&!n.ok?p(`Watch disabled: ${n.error??`failed to watch directory`}`):p(null))})();let n=r.onDirChange(()=>{C()});return()=>{e=!0,x(),n(),r.unwatchDir?.(t)}},[x,t,C,r]),{isRefreshing:m,refreshStatus:l,watchStatus:f,refreshVisibleTree:ee}}function Me(e){let{selectedFilePath:t,rootPath:n,selectedPath:r,visiblePaths:i,selectOnlyPath:a}=e,o=(0,u.useRef)(null);(0,u.useEffect)(()=>{let e=t??null,s=e!==o.current;s&&(o.current=e),(s||!r)&&e&&n&&O(n,e)&&e!==r&&i.includes(e)&&a(e)},[n,a,t,r,i])}var Ne=8,G=0;function K(){return G+=1,`folder-git-op-${Date.now()}-${G}`}function q(e){return/dirty|uncommitted|confirmation required|not registered|outside home|symlink/i.test(e)}function J(e,t){return{id:K(),operation:e,startedAt:new Date().toISOString(),finishedAt:null,operationLabel:t?.label??e.type,commandPreview:t?.command??[],status:`running`,stdout:``,stderr:``,error:null}}function Y(e,t){return[t,...e].slice(0,Ne)}function Pe(e,t,n){return e.map(e=>e.id===t?n.ok?{...e,finishedAt:new Date().toISOString(),status:`succeeded`,stdout:n.stdout,error:null}:{...e,finishedAt:new Date().toISOString(),status:q(n.error)?`blocked`:`failed`,error:n.error}:e)}function Fe(e){let{rootPath:t,source:n,worktreeState:r,openFolderRoot:i,refreshVisibleTree:a,bumpGitRefresh:o,setActionStatus:c,setError:l}=e,[d,f]=(0,u.useState)(!1),[p,m]=(0,u.useState)(!1),[h,g]=(0,u.useState)([]);return{open:d,setOpen:f,busy:p,history:h,openWorktreeRoot:(0,u.useCallback)(async e=>{await i(e,{registerGitWorktree:!0,repoRoot:r.repoRoot})},[i,r.repoRoot]),copyWorktreePath:(0,u.useCallback)(async e=>{let t=await s(e);t.ok?(c(`Copied worktree path`),l(null)):l(t.error??`Failed to copy worktree path`)},[c,l]),revealWorktreePath:(0,u.useCallback)(async e=>{if(t&&n.registerGitWorktreeRoot&&n.revealPath)try{await n.registerGitWorktreeRoot(t,r.repoRoot??void 0,e),await n.revealPath(e),c(`Opened worktree in Finder`),l(null)}catch(e){l(e.message)}},[t,c,l,n,r.repoRoot]),runWorktreeOperation:(0,u.useCallback)(async(e,n)=>{if(!t)return;let i=J(e,n),s=!1;g(e=>Y(e,i)),m(!0);try{let n=await T({folderPanelRoot:t,repoRoot:r.repoRoot,operation:e,confirmed:!0});if(!n.ok){let e=n.error??`Git operation failed`;throw g(t=>Pe(t,i.id,{ok:!1,error:e})),s=!0,Error(e)}g(e=>Pe(e,i.id,{ok:!0,stdout:n.stdout})),s=!0,c(n.preview?.label??`Git worktree operation completed`),l(null),f(!1),r.refresh(),o(),await a(`git-operation`)}catch(e){let t=e.message;s||g(e=>Pe(e,i.id,{ok:!1,error:t})),l(t)}finally{m(!1)}},[o,a,t,c,l,r])}}function Ie(e){let[t,n]=(0,u.useState)(null),[r,i]=(0,u.useState)(!1),a=(0,u.useCallback)(()=>e.rootPath?e.selectedEntry?e.selectedEntry.kind===`directory`?e.selectedEntry.path:ae(e.selectedEntry.path):e.rootPath:null,[e.rootPath,e.selectedEntry]),o=(0,u.useCallback)(t=>{let r=a();r&&(t!==`file`||e.source.createFile)&&(t!==`directory`||e.source.createFolder)&&(e.setExpanded(e=>new Set(e).add(r)),n({kind:t,parentDirectory:r,initialName:t===`file`?`untitled.txt`:`untitled`}),e.closeContextMenu())},[e,a]),s=(0,u.useCallback)(async(t,r,a)=>{let o=t===`file`?e.source.createFile:e.source.createFolder;if(!o)return;let s=t===`file`?`New file name`:`New folder name`;if(!a.trim()){e.setError(`${s} required`);return}i(!0);try{let i=(await o(r,a.trim())).entry;t===`directory`&&e.selectedEntry?.path===r&&e.setExpanded(e=>new Set(e).add(r)),e.setActionStatus(t===`file`?`Created file`:`Created folder`),e.setError(null),n(null),await e.refreshAfterMutation(r,i?.path??null)}catch(t){e.setError(t.message)}finally{i(!1)}},[e]),c=(0,u.useCallback)(()=>{e.selectedEntry&&e.source.renamePath&&(n({kind:`rename`,parentDirectory:ae(e.selectedEntry.path),targetPath:e.selectedEntry.path,initialName:e.selectedEntry.name}),e.closeContextMenu())},[e]),l=(0,u.useCallback)(async(t,r)=>{if(!t.targetPath||!e.source.renamePath)return;let a=r.trim();if(!a||a===t.initialName){n(null);return}i(!0);try{let r=await e.source.renamePath(t.targetPath,a),i=t.parentDirectory,o=r.entry?.path??null,s=o?e.renamedPreviewPath(e.selectedFilePath,t.targetPath,o):null;e.setActionStatus(`Renamed`),e.setError(null),n(null),await e.refreshAfterMutation(i,o,[t.targetPath]),s&&e.onPreviewFile?.(s)}catch(t){e.setError(t.message)}finally{i(!1)}},[e]);return{inlineMutation:t,isMutating:r,requestCreateEntry:o,requestRenameSelectedEntry:c,submitInlineMutation:(0,u.useCallback)(e=>{t&&(t.kind===`rename`?l(t,e):s(t.kind,t.parentDirectory,e))},[t,s,l]),cancelInlineMutation:()=>n(null)}}function Le(e){let[t,n]=(0,u.useState)(null),r=(0,u.useCallback)(()=>n(null),[]),i=(0,u.useCallback)((t,r,i)=>{e.selectedPaths.has(t.path)||e.selectOnlyPath(t.path),n({entry:t,x:r,y:i})},[e]);return(0,u.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(null)},i=()=>{document.activeElement instanceof HTMLIFrameElement&&n(null)};return window.addEventListener(`pointerdown`,r),window.addEventListener(`keydown`,e),window.addEventListener(`blur`,i),()=>{window.removeEventListener(`pointerdown`,r),window.removeEventListener(`keydown`,e),window.removeEventListener(`blur`,i)}},[r,t]),{contextMenu:t,closeContextMenu:r,openContextMenu:i}}function Re(){return i()?.folder??null}function ze(e,t,n){return!e||!O(t,e)?null:e===t?n:`${n}${e.slice(t.length)}`}function Be(e){let t=Re(),n=e.repoRootPath??null,r=e.gitRefreshVersion??0,i=e.onGitRefresh,a=e.onRepoRootChange,o=(0,u.useRef)(!1),c=(0,u.useMemo)(()=>t?p(t):m(e.notesTree??[],e.notesRoot??null),[t,e.notesRoot,e.notesTree]),l=(0,u.useMemo)(()=>xe(e.sessionState??null,e.externalRootPath??null),[e.externalRootPath,e.sessionState]),[d,f]=(0,u.useState)(()=>l?.rootPath??null),[_,v]=(0,u.useState)(()=>l?.entries??[]),[b,x]=(0,u.useState)(()=>new Set(l?.expandedPaths??[])),[S,C]=(0,u.useState)(()=>l?be(l.childrenCache):new Map),[w,T]=(0,u.useState)(null),[E,D]=(0,u.useState)(null),[te,ne]=(0,u.useState)(null),[re,ce]=(0,u.useState)(null),[k,le]=(0,u.useState)(null),[ue,A]=(0,u.useState)(!1),[fe,pe]=(0,u.useState)(!1),[j,he]=(0,u.useState)(!1),[ge,M]=(0,u.useState)(null),[_e,ve]=(0,u.useState)(0),ye=(0,u.useRef)(null),N=(0,u.useRef)(null),{folderChordActive:P,startFolderChord:Ce,cancelFolderChord:F}=De(),I=e.onPreviewFile,we=e.selectedFilePath,L=Oe({entries:_,childrenCache:S,expanded:b,initialSelection:l?.selection,onPreviewFile:I}),R=L.selectedEntry,z=L.selectedEntries,B=Le({selectedPaths:L.selectedPaths,selectOnlyPath:L.selectOnlyPath});Me({selectedFilePath:e.selectedFilePath,rootPath:d,selectedPath:L.selectedPath,visiblePaths:L.visiblePaths,selectOnlyPath:L.selectOnlyPath}),(0,u.useEffect)(()=>{e.onSessionStateChange?.(Se({rootPath:d,entries:_,expanded:b,childrenCache:S,selection:L.selection}))},[S,_,b,L.selection,e.onSessionStateChange,d]);let V=(0,u.useCallback)(async e=>{try{let t=await c.listDir(e);return v(t),T(null),D(t=>t?.path===e?null:t),{ok:!0}}catch(e){let t=e.message;return T(t),{ok:!1,error:t}}},[c]),H=(0,u.useCallback)(async(t,n={})=>{try{let r=t;if(n.registerGitWorktree){if(!d)throw Error(`Current folder root required`);await c.registerGitWorktreeRoot?.(d,n.repoRoot??void 0,t)}else c.authorizeRoot&&(r=await c.authorizeRoot(t));d&&c.unwatchDir&&c.unwatchDir(d),e.onRootChange?.(r),f(r),x(new Set),C(new Map),v([]),L.resetSelection(),T(null),D(null);let i=await V(r);i.ok||D({path:r,error:i.error}),ve(e=>e+1)}catch(e){T(e.message)}},[L,V,e,d,c]),U=(0,u.useCallback)(async(e,t={})=>{if(t.force||!S.has(e))try{let t=await c.listDir(e);C(n=>new Map(n).set(e,t))}catch(e){T(e.message)}},[S,c]),ke=(0,u.useCallback)(()=>{ve(e=>e+1)},[]),Ae=(0,u.useCallback)(e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),U(e)),n})},[U]),W=(0,u.useCallback)(async()=>{if(c.pickRoot)try{let e=await c.pickRoot();e&&await H(e)}catch(e){T(e.message)}},[H,c]),Ne=(0,u.useCallback)(()=>{e.onRootChange?.(null),f(null),v([]),L.resetSelection(),D(null),T(null)},[L,e]);(0,u.useEffect)(()=>{if(o.current||d!==null||e.externalRootPath)return;let t=!1;return(async()=>{let e=await c.getInitialRoot();t||(o.current=!0,f(e),e!==null&&await V(e))})(),()=>{t=!0}},[V,e.externalRootPath,d,c]),(0,u.useEffect)(()=>{let t=e.externalRootPath;if(t){if(t===d){if(_.length>0||N.current===t)return;N.current=t}else N.current=null;H(t)}},[_.length,H,e.externalRootPath,d]);let G=Te({rootPath:d,enabled:c.kind===`electron-folder`,refreshToken:_e+r}),K=Ee({folderPanelRoot:d,repoRoot:G.repoRoot??n,enabled:c.kind===`electron-folder`&&G.available,refreshToken:_e+r}),q=je({rootPath:d,expanded:b,source:c,loadDir:V,loadChildren:U,bumpGitRefresh:ke,onGitRefresh:i,refreshWorktrees:K.refresh}),J=q.refreshVisibleTree,Y=Fe({rootPath:d,source:c,worktreeState:K,openFolderRoot:H,refreshVisibleTree:J,bumpGitRefresh:ke,setActionStatus:M,setError:T});(0,u.useEffect)(()=>{G.repoRoot&&G.repoRoot!==n&&a?.(G.repoRoot)},[G.repoRoot,a,n]);let Pe=c.kind===`electron-folder`,Be=!!(c.createFile&&c.createFolder&&c.renamePath),Ve=(0,u.useCallback)(async(e,t)=>{if(!d)return;let n=ae(e);C(e=>se(e,[n,t])),await J(`move`,{extraPaths:[n,t]})},[J,d]),He=(0,u.useCallback)(async(e,t,n=[])=>{d&&(C(t=>se(t,[e,...n])),await J(`mutation`,{extraPaths:[e]}),t&&L.selectOnlyPath(t))},[L,J,d]),Ue=(0,u.useCallback)(async e=>{if(c.movePath){A(!0);try{let t=(await c.movePath(e.source.path,e.target.path)).moved?.to??e.source.path;L.selectOnlyPath(t),M(`Moved ${e.source.name}`),le(null),await Ve(e.source.path,e.target.path)}catch(e){T(e.message)}finally{A(!1)}}},[L,Ve,c]),We=(0,u.useCallback)((e,t)=>{if(!c.movePath||e.path===t.path||e.kind===`directory`&&O(e.path,t.path))return;let n={source:e,target:t};if(fe){Ue(n);return}he(!1),le(n)},[Ue,fe,c.movePath]),X=Ie({rootPath:d,selectedEntry:R,selectedFilePath:we,source:c,folderSelection:L,refreshAfterMutation:He,renamedPreviewPath:ze,onPreviewFile:I,closeContextMenu:B.closeContextMenu,setExpanded:x,setActionStatus:M,setError:T}),Z=(0,u.useCallback)((e,t)=>{L.selectEntry(e,t),B.closeContextMenu()},[B,L]),Ge=(0,u.useCallback)(e=>{e.kind===`file`&&Z(e)},[Z]),Q=(0,u.useCallback)(e=>{L.selectEntry(e,{preview:!1}),B.closeContextMenu(),e.kind===`directory`&&Ae(e.path)},[B,L,Ae]),Ke=(0,u.useCallback)(async(e,t)=>{let n=t===`relative`?oe(d,e.path):e.path,r=await s(n);r.ok?(L.selectOnlyPath(e.path),M(t===`relative`?`Copied relative path`:`Copied path`),T(null)):T(r.error??`Failed to copy path`)},[L,d]),qe=(0,u.useCallback)(async e=>{if(c.revealPath)try{await c.revealPath(e.path),L.selectOnlyPath(e.path),M(e.kind===`directory`?`Opened folder in Finder`:`Revealed file in Finder`),T(null)}catch(e){T(e.message)}},[L,c]),$=(0,u.useCallback)(async e=>{if(z.length===0)return;let t=z.map(t=>e===`relative`?oe(d,t.path):t.path).join(`
|
|
3
|
-
`),n=await s(t);n.ok?(M(e===`relative`?`Copied relative paths`:`Copied paths`),T(null)):T(n.error??`Failed to copy paths`)},[d,z]),Je=(0,u.useCallback)(async()=>{R&&await qe(R)},[qe,R]),Ye=(0,u.useCallback)((e,t)=>{if(e.key===`ArrowUp`||e.key===`ArrowDown`){e.preventDefault(),e.stopPropagation(),L.moveKeyboardSelection(e.key===`ArrowDown`?`down`:`up`,e.shiftKey);return}if(e.key===`ArrowRight`){e.preventDefault(),t.kind===`directory`&&!b.has(t.path)&&Q(t);return}if(e.key===`ArrowLeft`){e.preventDefault(),t.kind===`directory`&&b.has(t.path)&&Q(t);return}let n=de(e,{chordActive:P});if(n){e.preventDefault(),e.stopPropagation(),n===`start-chord`&&Ce(),n===`cancel-chord`&&F();let r=L.selectedPaths.has(t.path);n===`copy-path`&&(F(),r?$(`absolute`):Ke(t,`absolute`)),n===`copy-relative-path`&&(F(),r?$(`relative`):Ke(t,`relative`)),n===`reveal-path`&&(F(),r?Je():qe(t));return}if(e.key===`Enter`){e.preventDefault(),t.kind===`directory`?Q(t):Z(t);return}e.key===` `&&(e.preventDefault(),Z(t))},[F,Ke,$,b,P,L,qe,Je,Z,Ce,Q]);return(0,u.useEffect)(()=>{let e=L.selection.focusedPath;if(!e)return;let t=ye.current?.querySelectorAll(`.folder-entry-btn[data-folder-path]`);Array.from(t??[]).find(t=>t.dataset.folderPath===e)?.focus()},[L.selection.focusedPath]),(0,h.jsxs)(`div`,{className:`folder-panel`,children:[(0,h.jsx)(ee,{canPickRoot:c.canPickRoot,label:c.label,rootPath:d,onPickFolder:()=>void W(),onRefresh:()=>{d!==null&&J(`manual`)},gitSummary:c.kind===`electron-folder`?G:void 0,worktreeSummary:c.kind===`electron-folder`?K:void 0,onOpenWorktree:e=>void Y.openWorktreeRoot(e),onCopyWorktreePath:e=>void Y.copyWorktreePath(e),onRevealWorktreePath:e=>void Y.revealWorktreePath(e),onOpenWorktreeOps:()=>Y.setOpen(!0)}),d!==null&&(0,h.jsx)(g,{hasSelection:!!R,canReveal:!!c.revealPath,onCopyPath:()=>void $(`absolute`),onCopyRelativePath:()=>void $(`relative`),onReveal:()=>void Je(),canMutate:Be,onCreateFile:()=>X.requestCreateEntry(`file`),onCreateFolder:()=>X.requestCreateEntry(`directory`),onRename:()=>X.requestRenameSelectedEntry()}),w&&(0,h.jsx)(`div`,{className:`folder-error`,children:w}),q.watchStatus&&!w&&(0,h.jsx)(`div`,{className:`folder-status`,children:q.watchStatus}),q.refreshStatus&&!w&&!q.watchStatus&&(0,h.jsx)(`div`,{className:`folder-status`,children:q.refreshStatus}),ge&&!w&&!q.refreshStatus&&!q.watchStatus&&(0,h.jsx)(`div`,{className:`folder-status`,children:ge}),P&&(0,h.jsx)(`div`,{className:`folder-shortcut-hint`,children:`Folder shortcut: press P to copy path or R to reveal`}),Y.open&&d!==null&&(0,h.jsx)(ie,{folderPanelRoot:d,repoRoot:K.repoRoot,worktrees:K.worktrees,busy:Y.busy,history:Y.history,onRun:(e,t)=>void Y.runWorktreeOperation(e,t),onClose:()=>Y.setOpen(!1)}),(0,h.jsx)(me,{treeRef:ye,rootPath:d,error:w,entries:_,expanded:b,childrenCache:S,folderSelection:L,decorationsByPath:G.decorationsByPath,dropTargetPath:re,dragSelection:te,inlineMutation:X.inlineMutation,isMutating:X.isMutating,canUseNativeActions:Pe,sourceKind:c.kind,unavailableRoot:E,setDragSelection:ne,setDropTargetPath:ce,requestMove:We,handleEntryKeyDown:Ye,selectEntry:Z,toggleEntryExpansion:Q,openFileEntry:Ge,openContextMenu:B.openContextMenu,submitInlineMutation:X.submitInlineMutation,cancelInlineMutation:X.cancelInlineMutation,onPickFolder:()=>void W(),onClearUnavailableRoot:Ne}),(0,h.jsx)(y,{pendingMove:k,contextMenu:B.contextMenu,isMoving:ue,skipMoveConfirmChecked:j,canReveal:!!c.revealPath,canRefresh:!!d,canMutate:Be,onSkipMoveConfirmCheckedChange:he,onCancelMove:()=>le(null),onConfirmMove:()=>{k&&(j&&pe(!0),Ue(k))},onCopyContextPath:()=>{B.closeContextMenu(),$(`absolute`)},onCopyContextRelativePath:()=>{B.closeContextMenu(),$(`relative`)},onRevealContextPath:()=>{B.closeContextMenu(),Je()},onRefreshContext:()=>{B.closeContextMenu(),J(`manual`)},onCreateContextFile:()=>X.requestCreateEntry(`file`),onCreateContextFolder:()=>X.requestCreateEntry(`directory`),onRenameContextPath:()=>X.requestRenameSelectedEntry()})]})}export{Be as FolderPanel};
|