@cocoar/vue-file-explorer-core 2.6.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.
@@ -0,0 +1,144 @@
1
+ import { MaybeRefOrGetter, Ref } from 'vue';
2
+ import { CoarTreeNodeMoveEvent } from '@cocoar/vue-ui';
3
+ import { CoarScriptEditorLanguage } from '@cocoar/vue-script-editor';
4
+ import { Asset, AssetOp, AssetOpContext, AssetStore, AssetStoreConfig, FileEditor, FileMeta, SortMode } from './asset-store';
5
+ import { AssetProperty } from './describe-asset';
6
+ /**
7
+ * A tab open in the editor area. Held in `shallowRef` so swaps trigger
8
+ * re-renders without Vue having to track every keystroke inside `content`.
9
+ */
10
+ export interface OpenTab {
11
+ id: string;
12
+ name: string;
13
+ editor: FileEditor;
14
+ language?: CoarScriptEditorLanguage;
15
+ /** Current editor buffer. */
16
+ content: string;
17
+ /** Last persisted content. `content !== savedContent` ⇒ dirty. */
18
+ savedContent: string;
19
+ /**
20
+ * Preview tabs (false) render in italic; opening another file in
21
+ * preview mode replaces them. Editing auto-promotes to pinned.
22
+ */
23
+ pinned: boolean;
24
+ }
25
+ export interface UseFileExplorerOptions<T = unknown> {
26
+ store: AssetStore<T>;
27
+ /** Single funnel for every store failure. Composable has already rolled back. */
28
+ onError?: (op: AssetOp, error: unknown, ctx: AssetOpContext) => void;
29
+ /** 3-stage fallback override slot (`asset.editor` → here → extension default). */
30
+ getFileMeta?: AssetStoreConfig<T>['getFileMeta'];
31
+ /** Discard-dirty / delete confirmations. Default: `window.confirm`. */
32
+ confirm?: (message: string) => boolean;
33
+ /** Folder ids to seed `expanded` with. Default: top-level folders. */
34
+ initialExpandedIds?: readonly string[];
35
+ /**
36
+ * Sibling ordering strategy. Default `'folders-first'` (VSCode pattern).
37
+ * Reactive via `Ref` / getter so a toolbar can swap modes at runtime.
38
+ * In any non-manual mode the composable silently drops the `position` arg
39
+ * on `move` — the comparator decides where the moved node lands.
40
+ */
41
+ sortMode?: MaybeRefOrGetter<SortMode<T>>;
42
+ }
43
+ export interface UseFileExplorerReturn<T = unknown> {
44
+ /** Flat reactive asset list (the store's underlying ref). */
45
+ readonly assets: Readonly<Ref<readonly Asset<T>[]>>;
46
+ /** Root-level slice — pass directly to `<CoarTree :nodes>`. */
47
+ readonly rootNodes: Readonly<Ref<readonly Asset<T>[]>>;
48
+ selectedId: Ref<string | null>;
49
+ /**
50
+ * The asset currently selected in the tree, resolved from `selectedId`.
51
+ * `null` when nothing is selected or the id no longer exists. Drives
52
+ * details / info panels — pair with `describeAsset`.
53
+ */
54
+ readonly selectedAsset: Readonly<Ref<Asset<T> | null>>;
55
+ expanded: Ref<Set<string>>;
56
+ getId: (a: Asset<T>) => string;
57
+ getChildren: (a: Asset<T>) => readonly Asset<T>[] | undefined;
58
+ getLabel: (a: Asset<T>) => string;
59
+ isExpandable: (a: Asset<T>) => boolean;
60
+ /**
61
+ * `true` when `sortMode === 'manual'`. Reactive so a sort-mode toolbar
62
+ * can flip it at runtime. Drives whether `move` honors a `position` arg —
63
+ * future hook for CoarTree's drag mode when the prop is exposed.
64
+ */
65
+ readonly reorderable: Readonly<Ref<boolean>>;
66
+ /**
67
+ * `true` during the initial `store.loadTree()` call. Stays `false` for
68
+ * stores that surface their own reactive `_assets` (they own their load
69
+ * lifecycle). Per-folder lazy loads + per-file content loads live on
70
+ * `loadingNodes` instead — `loading` is strictly the initial-load signal.
71
+ */
72
+ readonly loading: Readonly<Ref<boolean>>;
73
+ /** Files whose content is being loaded via `store.loadContent`. */
74
+ readonly loadingNodes: Readonly<Ref<ReadonlySet<string>>>;
75
+ /** Assets with an in-flight save/rename/delete/move. */
76
+ readonly savingNodes: Readonly<Ref<ReadonlySet<string>>>;
77
+ readonly openTabs: Readonly<Ref<readonly OpenTab[]>>;
78
+ activeId: Ref<string | null>;
79
+ readonly activeTab: Readonly<Ref<OpenTab | null>>;
80
+ readonly anyDirty: Readonly<Ref<boolean>>;
81
+ isDirty: (tab: OpenTab) => boolean;
82
+ /**
83
+ * Update a tab's editor buffer. Auto-pins preview tabs the moment they
84
+ * go dirty (VSCode pattern — dirty preview tabs never exist).
85
+ */
86
+ setContent: (id: string, content: string) => void;
87
+ /** `name` is required — the embedding handles the prompt UI. */
88
+ addFolder: (parentId: string | null, name: string) => Promise<Asset<T> | null>;
89
+ addFiles: (parentId: string | null, files: FileList | readonly File[]) => Promise<void>;
90
+ deleteNode: (asset: Asset<T>) => Promise<void>;
91
+ /** Translates CoarTree's drop event → `store.move(id, parentId, position?)`. */
92
+ moveNode: (e: CoarTreeNodeMoveEvent<Asset<T>>) => Promise<void>;
93
+ rename: (id: string, newName: string) => Promise<void>;
94
+ /**
95
+ * Re-fetch the tree (or one folder's children) from the store. No-op for
96
+ * stores that surface a reactive `_assets` directly — they're already
97
+ * live. Pass a `folderId` to refresh just that folder in lazy mode;
98
+ * `undefined` / `null` runs a full `loadTree()`.
99
+ */
100
+ refresh: (folderId?: string | null) => Promise<void>;
101
+ openFile: (asset: Asset<T>, opts?: {
102
+ pinned: boolean;
103
+ }) => Promise<void>;
104
+ /** Pin (`{pinned: true}`); use on dblclick / Enter / "Open" menu item. */
105
+ activateNode: (asset: Asset<T>) => void;
106
+ saveTab: (id: string) => Promise<boolean>;
107
+ saveActive: () => Promise<void>;
108
+ closeTab: (id: string) => void;
109
+ closeOthers: (keepId: string) => void;
110
+ closeToRight: (anchorId: string) => void;
111
+ closeAll: () => void;
112
+ pinTab: (id: string) => void;
113
+ unpinTab: (id: string) => void;
114
+ /**
115
+ * Move tab `sourceId` to be immediately `before` or `after` `targetId`
116
+ * in the tab bar. No-op for self-drop or unknown ids. Pinned vs. preview
117
+ * status is preserved on the moved tab — consumers that want pinned-only-
118
+ * left ordering should validate before calling.
119
+ */
120
+ reorderTab: (sourceId: string, targetId: string, position: 'before' | 'after') => void;
121
+ /** Walk parentId chain → expand all ancestors → focus + select. */
122
+ revealInTree: (id: string, focusNode?: (id: string) => void) => void;
123
+ /** Asset-name path from root to active file. Empty when no active tab. */
124
+ readonly breadcrumbPath: Readonly<Ref<readonly string[]>>;
125
+ /**
126
+ * Name path from root to `id`, inclusive. Empty when the id isn't found.
127
+ * Drives breadcrumb-style displays for arbitrary nodes (quick-open,
128
+ * recent-files, etc.) — `breadcrumbPath` is the active-tab special case.
129
+ */
130
+ pathOf: (id: string) => string[];
131
+ fileMeta: (asset: Asset<T>) => FileMeta | null;
132
+ /**
133
+ * Framework-known property rows for an asset — Name, Type, Language
134
+ * (script files), Extension, and Path — ready to render in a details /
135
+ * info panel. Returns a fresh array each call. Domain fields that live in
136
+ * `payload` are the consumer's to append.
137
+ */
138
+ describeAsset: (asset: Asset<T>) => AssetProperty[];
139
+ }
140
+ /**
141
+ * `useFileExplorer<T>(options)` — see file docblock for the contract.
142
+ */
143
+ export declare function useFileExplorer<T = unknown>(options: UseFileExplorerOptions<T>): UseFileExplorerReturn<T>;
144
+ //# sourceMappingURL=use-file-explorer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-file-explorer.d.ts","sourceRoot":"","sources":["../src/use-file-explorer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAuE,KAAK,gBAAgB,EAAE,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAC3H,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAE1E,OAAO,KAAK,EACV,KAAK,EAEL,OAAO,EACP,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACR,QAAQ,EACT,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE5E;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAA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{
2
+ "name": "@cocoar/vue-file-explorer-core",
3
+ "version": "2.6.0",
4
+ "description": "VSCode-style file/asset explorer for Vue 3 — composable + types over a pluggable AssetStore<T> backend.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/cocoar-dev/cocoar-ui-vue.git",
9
+ "directory": "packages/file-explorer-core"
10
+ },
11
+ "homepage": "https://docs.cocoar.dev/cocoar-ui-vue/",
12
+ "bugs": "https://github.com/cocoar-dev/cocoar-ui-vue/issues",
13
+ "keywords": [
14
+ "vue",
15
+ "vue3",
16
+ "file-explorer",
17
+ "asset-store",
18
+ "tree"
19
+ ],
20
+ "type": "module",
21
+ "main": "./dist/index.js",
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "import": "./dist/index.js",
27
+ "types": "./dist/index.d.ts"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "scripts": {
34
+ "build": "vite build",
35
+ "test": "vitest run --passWithNoTests",
36
+ "lint": "eslint src/",
37
+ "typecheck": "vue-tsc --noEmit"
38
+ },
39
+ "peerDependencies": {
40
+ "@cocoar/vue-script-editor": "2.6.0",
41
+ "@cocoar/vue-ui": "2.6.0",
42
+ "vue": "^3.5.0"
43
+ },
44
+ "peerDependenciesMeta": {
45
+ "@cocoar/vue-script-editor": {
46
+ "optional": true
47
+ }
48
+ },
49
+ "devDependencies": {
50
+ "@cocoar/vue-script-editor": "workspace:*",
51
+ "@cocoar/vue-ui": "workspace:*",
52
+ "vue": "^3.5.32"
53
+ }
54
+ }