feat: add workspace templates and tab visibility
This commit is contained in:
@@ -11,7 +11,10 @@
|
||||
|
||||
let contributions = {};
|
||||
let plugins = [];
|
||||
let discoveredWorkspaceTools = [];
|
||||
let workspaceTools = [];
|
||||
let workspaceMetadata = null;
|
||||
let metadataWorkspaceRoot = '';
|
||||
let toolsLoaded = false;
|
||||
let requestedToolKind = '';
|
||||
let requestedToolRequest = null;
|
||||
@@ -27,6 +30,7 @@
|
||||
['activity', 40],
|
||||
['browser', 50],
|
||||
['inbox', 50],
|
||||
['secrets', 60],
|
||||
['search', 90],
|
||||
]);
|
||||
|
||||
@@ -34,6 +38,12 @@
|
||||
$: workspaceRootPath = selectedWorkspace?.rootPath || selectedWorkspace?.name || selectedWorkspace?.id || '';
|
||||
$: workspaceTitle = selectedWorkspace?.title || selectedWorkspace?.name || selectedWorkspace?.id || selectedWorkspaceName;
|
||||
$: workspaceType = selectedWorkspace?.type || 'workspace';
|
||||
$: if (workspaceRootPath !== metadataWorkspaceRoot) {
|
||||
metadataWorkspaceRoot = workspaceRootPath;
|
||||
workspaceMetadata = null;
|
||||
if (workspaceRootPath) loadWorkspaceMetadata(workspaceRootPath);
|
||||
}
|
||||
$: workspaceTools = sortWorkspaceTools(filterWorkspaceTools(discoveredWorkspaceTools, workspaceMetadata));
|
||||
$: if (workspaceRootPath !== requestedWorkspaceRoot) {
|
||||
requestedWorkspaceRoot = workspaceRootPath;
|
||||
requestedToolRequest = null;
|
||||
@@ -83,6 +93,29 @@
|
||||
});
|
||||
}
|
||||
|
||||
function filterWorkspaceTools(tools, metadata) {
|
||||
if (!Array.isArray(metadata?.workspaceTools)) return tools;
|
||||
const allowedPluginIds = new Set(metadata.workspaceTools);
|
||||
return tools.filter(tool => allowedPluginIds.has(tool.pluginId));
|
||||
}
|
||||
|
||||
function resultOrError(response, fallbackValue) {
|
||||
if (Array.isArray(response) && typeof response[1] === 'string') {
|
||||
return [response[0] || fallbackValue, response[1] || ''];
|
||||
}
|
||||
return typeof response === 'string' ? [fallbackValue, response] : [response || fallbackValue, ''];
|
||||
}
|
||||
|
||||
async function loadWorkspaceMetadata(rootPath) {
|
||||
try {
|
||||
const [metadata, err] = resultOrError(await App.GetWorkspaceMetadata(rootPath), null);
|
||||
if (rootPath !== workspaceRootPath) return;
|
||||
workspaceMetadata = err ? null : metadata;
|
||||
} catch (_) {
|
||||
if (rootPath === workspaceRootPath) workspaceMetadata = null;
|
||||
}
|
||||
}
|
||||
|
||||
function selectTool(tool, toolRequest = null) {
|
||||
activeToolKey = toolKey(tool);
|
||||
activeToolRequest = toolRequest;
|
||||
@@ -137,7 +170,7 @@
|
||||
plugins.filter(pl => pl.enabled && (pl.status === 'loaded' || pl.status === 'degraded')).map(pl => pl.manifest?.id)
|
||||
);
|
||||
|
||||
workspaceTools = sortWorkspaceTools((contributions.workspaceItems || []).filter(tool => enabledIds.has(tool.pluginId)));
|
||||
discoveredWorkspaceTools = (contributions.workspaceItems || []).filter(tool => enabledIds.has(tool.pluginId));
|
||||
} catch (e) {
|
||||
console.error('[WorkspaceHost] loadTools error:', e);
|
||||
} finally {
|
||||
|
||||
@@ -15,6 +15,11 @@
|
||||
let currentWorkspaceId = '';
|
||||
let showCreate = false;
|
||||
let newWorkspaceName = '';
|
||||
let workspaceTemplates = [];
|
||||
let templatePluginNames = {};
|
||||
let selectedTemplateId = 'default';
|
||||
let createError = '';
|
||||
let templatesLoading = false;
|
||||
let creating = false;
|
||||
let renamingId = '';
|
||||
let renameValue = '';
|
||||
@@ -22,6 +27,7 @@
|
||||
|
||||
onMount(() => {
|
||||
loadWorkspaces();
|
||||
loadWorkspaceTemplates();
|
||||
window.addEventListener('verstak:workspace-active-changed', onActiveWorkspaceChanged);
|
||||
});
|
||||
|
||||
@@ -35,9 +41,49 @@
|
||||
}
|
||||
|
||||
function resultOrError(response, fallbackValue) {
|
||||
if (Array.isArray(response) && typeof response[1] === 'string') {
|
||||
return [response[0] || fallbackValue, response[1] || ''];
|
||||
}
|
||||
return typeof response === 'string' ? [fallbackValue, response] : [response, ''];
|
||||
}
|
||||
|
||||
$: selectedTemplate = workspaceTemplates.find(template => template.id === selectedTemplateId) || workspaceTemplates[0] || null;
|
||||
|
||||
function toolLabel(pluginId) {
|
||||
return templatePluginNames[pluginId] || String(pluginId || '').replace(/^verstak\./, '');
|
||||
}
|
||||
|
||||
async function loadWorkspaceTemplates() {
|
||||
templatesLoading = true;
|
||||
try {
|
||||
const [templates, plugins] = await Promise.all([
|
||||
App.ListWorkspaceTemplates ? App.ListWorkspaceTemplates() : [],
|
||||
App.GetPlugins ? App.GetPlugins() : [],
|
||||
]);
|
||||
const [list, err] = resultOrError(templates, []);
|
||||
if (err) {
|
||||
createError = err;
|
||||
workspaceTemplates = [];
|
||||
return;
|
||||
}
|
||||
workspaceTemplates = Array.isArray(list) ? list : [];
|
||||
templatePluginNames = (Array.isArray(plugins) ? plugins : []).reduce((names, plugin) => {
|
||||
const id = plugin?.manifest?.id;
|
||||
const name = plugin?.manifest?.name;
|
||||
if (id && name) names[id] = name;
|
||||
return names;
|
||||
}, {});
|
||||
if (!workspaceTemplates.some(template => template.id === selectedTemplateId)) {
|
||||
selectedTemplateId = workspaceTemplates[0]?.id || '';
|
||||
}
|
||||
} catch (error) {
|
||||
createError = String(error);
|
||||
workspaceTemplates = [];
|
||||
} finally {
|
||||
templatesLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function wsName(workspace) {
|
||||
return String(workspace?.name || workspace?.rootPath || '');
|
||||
}
|
||||
@@ -107,12 +153,19 @@
|
||||
|
||||
async function doCreate() {
|
||||
const name = newWorkspaceName.trim();
|
||||
if (!name) return;
|
||||
if (!name) {
|
||||
createError = 'Name is required';
|
||||
return;
|
||||
}
|
||||
if (!selectedTemplate) {
|
||||
createError = 'Choose a workspace template';
|
||||
return;
|
||||
}
|
||||
creating = true;
|
||||
localError = '';
|
||||
const [, err] = resultOrError(await App.CreateWorkspace(name, 'default'), null);
|
||||
createError = '';
|
||||
const [, err] = resultOrError(await App.CreateWorkspace(name, selectedTemplate.id), null);
|
||||
if (err) {
|
||||
localError = err;
|
||||
createError = err;
|
||||
creating = false;
|
||||
return;
|
||||
}
|
||||
@@ -124,6 +177,20 @@
|
||||
if (created) await selectWorkspace(created);
|
||||
}
|
||||
|
||||
function openCreateDialog() {
|
||||
showCreate = true;
|
||||
newWorkspaceName = '';
|
||||
createError = '';
|
||||
if (!workspaceTemplates.length && !templatesLoading) loadWorkspaceTemplates();
|
||||
}
|
||||
|
||||
function closeCreateDialog() {
|
||||
if (creating) return;
|
||||
showCreate = false;
|
||||
newWorkspaceName = '';
|
||||
createError = '';
|
||||
}
|
||||
|
||||
function startRename(workspace) {
|
||||
renamingId = wsName(workspace);
|
||||
renameValue = renamingId;
|
||||
@@ -180,7 +247,7 @@
|
||||
<div class="wt">
|
||||
<div class="wt-header">
|
||||
<span class="wt-title">Workspaces</span>
|
||||
<button class="wt-btn" on:click={() => { showCreate = true; newWorkspaceName = ''; }} title="New workspace" type="button">+</button>
|
||||
<button class="wt-btn" on:click={openCreateDialog} title="New workspace" type="button">+</button>
|
||||
</div>
|
||||
|
||||
{#if loading}
|
||||
@@ -222,15 +289,43 @@
|
||||
</div>
|
||||
|
||||
{#if showCreate}
|
||||
<div class="wt-create">
|
||||
<div class="wt-create-header">
|
||||
<span>New workspace</span>
|
||||
<button class="wt-btn btn-ghost" on:click={() => { showCreate = false; newWorkspaceName = ''; }} type="button">Close</button>
|
||||
</div>
|
||||
<input type="text" bind:value={newWorkspaceName} placeholder="Name..." disabled={creating} />
|
||||
<div class="wt-create-actions">
|
||||
<button class="wt-btn-primary" on:click={doCreate} type="button" disabled={creating || !newWorkspaceName.trim()}>{creating ? '...' : 'Create'}</button>
|
||||
<button class="wt-btn" on:click={() => { showCreate = false; newWorkspaceName = ''; }} type="button" disabled={creating}>Cancel</button>
|
||||
<div class="workspace-create-overlay" data-workspace-create-modal role="dialog" aria-modal="true" aria-label="Create workspace">
|
||||
<div class="workspace-create-modal">
|
||||
<div class="workspace-create-header">
|
||||
<div>
|
||||
<h2>New workspace</h2>
|
||||
</div>
|
||||
<button class="wt-btn" on:click={closeCreateDialog} type="button" disabled={creating}>Close</button>
|
||||
</div>
|
||||
<label class="workspace-create-field">
|
||||
<span>Name</span>
|
||||
<input data-workspace-name type="text" bind:value={newWorkspaceName} placeholder="Workspace name" disabled={creating} on:keydown={(event) => event.key === 'Enter' && doCreate()} />
|
||||
</label>
|
||||
<label class="workspace-create-field">
|
||||
<span>Template</span>
|
||||
<select data-workspace-template bind:value={selectedTemplateId} disabled={creating || templatesLoading || !workspaceTemplates.length}>
|
||||
{#each workspaceTemplates as template (template.id)}
|
||||
<option value={template.id}>{template.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
{#if selectedTemplate}
|
||||
<div class="workspace-template-summary">
|
||||
<p data-workspace-template-description>{selectedTemplate.description}</p>
|
||||
<div class="workspace-template-tools" data-workspace-template-tools>
|
||||
{#each selectedTemplate.workspaceTools || [] as pluginId (pluginId)}
|
||||
<span>{toolLabel(pluginId)}</span>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{#if createError}
|
||||
<p class="workspace-create-error" data-workspace-create-error role="alert">{createError}</p>
|
||||
{/if}
|
||||
<div class="workspace-create-actions">
|
||||
<button class="wt-btn-primary" on:click={doCreate} type="button" disabled={creating || templatesLoading || !selectedTemplate}>{creating ? 'Creating...' : 'Create workspace'}</button>
|
||||
<button class="wt-btn" on:click={closeCreateDialog} type="button" disabled={creating}>Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -261,11 +356,19 @@
|
||||
.wt-icon-btn.danger:hover:not(:disabled) { color: var(--vt-color-danger); background: var(--vt-color-danger-muted); border-color: rgba(233,69,96,0.35); }
|
||||
.wt-rename { flex: 1; min-width: 0; background: #0f1424; border: 1px solid var(--vt-color-border-strong); color: var(--vt-color-text-primary); padding: 0.2rem 0.35rem; border-radius: var(--vt-radius-sm); font-size: 0.78rem; }
|
||||
.wt-rename:focus { outline: none; border-color: var(--vt-color-accent); box-shadow: var(--vt-focus-ring); }
|
||||
.wt-create { position: absolute; bottom: 0; left: 0; right: 0; background: var(--vt-color-surface-muted); border-top: 1px solid var(--vt-color-border); padding: 0.6rem; z-index: 10; }
|
||||
.wt-create-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.4rem; color: var(--vt-color-text-muted); font-size: 0.7rem; text-transform: uppercase; }
|
||||
.wt-create input { width: 100%; background: #0f1424; border: 1px solid var(--vt-color-border-strong); color: var(--vt-color-text-primary); padding: 0.35rem 0.5rem; border-radius: var(--vt-radius-sm); font-size: 0.8rem; margin-bottom: 0.4rem; box-sizing: border-box; }
|
||||
.wt-create input:focus { outline: none; border-color: var(--vt-color-accent); box-shadow: var(--vt-focus-ring); }
|
||||
.wt-create-actions { display: flex; gap: 0.4rem; justify-content: flex-end; }
|
||||
.workspace-create-overlay { position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center; padding: 1rem; background: rgba(4, 8, 18, 0.7); }
|
||||
.workspace-create-modal { width: min(34rem, 100%); display: grid; gap: 0.85rem; padding: 1rem; border: 1px solid var(--vt-color-border-strong); border-radius: var(--vt-radius-lg); background: var(--vt-color-surface); box-shadow: 0 18px 44px rgba(0, 0, 0, 0.38); }
|
||||
.workspace-create-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
|
||||
.workspace-create-header h2 { margin: 0; font-size: 1rem; }
|
||||
.workspace-create-field { display: grid; gap: 0.35rem; color: var(--vt-color-text-muted); font-size: 0.75rem; }
|
||||
.workspace-create-field input, .workspace-create-field select { width: 100%; min-height: 2rem; box-sizing: border-box; border: 1px solid var(--vt-color-border-strong); border-radius: var(--vt-radius-sm); background: #0f1424; color: var(--vt-color-text-primary); padding: 0.35rem 0.5rem; font: inherit; font-size: 0.84rem; }
|
||||
.workspace-create-field input:focus, .workspace-create-field select:focus { outline: none; border-color: var(--vt-color-accent); box-shadow: var(--vt-focus-ring); }
|
||||
.workspace-template-summary { display: grid; gap: 0.55rem; padding: 0.75rem; border: 1px solid var(--vt-color-border); border-radius: var(--vt-radius-md); background: var(--vt-color-surface-muted); }
|
||||
.workspace-template-summary p { margin: 0; color: var(--vt-color-text-secondary); font-size: 0.8rem; line-height: 1.45; }
|
||||
.workspace-template-tools { display: flex; flex-wrap: wrap; gap: 0.35rem; }
|
||||
.workspace-template-tools span { min-height: 1.35rem; display: inline-flex; align-items: center; padding: 0 0.35rem; border: 1px solid var(--vt-color-border-strong); border-radius: var(--vt-radius-sm); color: var(--vt-color-text-secondary); font-size: 0.72rem; }
|
||||
.workspace-create-error { margin: 0; color: var(--vt-color-danger); font-size: 0.78rem; line-height: 1.4; }
|
||||
.workspace-create-actions { display: flex; gap: 0.4rem; justify-content: flex-end; }
|
||||
.wt-btn-primary { background: var(--vt-color-accent); color: #101827; border: none; padding: 0.3rem 0.6rem; border-radius: var(--vt-radius-sm); cursor: pointer; font-size: 0.75rem; font-weight: 600; }
|
||||
.wt-btn-primary:hover:not(:disabled) { background: #3dbb92; }
|
||||
.wt-btn-primary:disabled, .wt-btn:disabled, .wt-icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
|
||||
@@ -255,6 +255,7 @@
|
||||
error: ''
|
||||
},
|
||||
'verstak.todo': makeTodoPluginState(),
|
||||
'verstak.secrets': makeSecretsPluginState(),
|
||||
'verstak.search': {
|
||||
status: 'loaded',
|
||||
enabled: true,
|
||||
@@ -288,6 +289,8 @@
|
||||
vaultPluginState.desiredPlugins.push({ id: 'verstak.trash', version: '0.1.0', source: 'official' });
|
||||
vaultPluginState.enabledPlugins.push('verstak.todo');
|
||||
vaultPluginState.desiredPlugins.push({ id: 'verstak.todo', version: '0.1.0', source: 'official' });
|
||||
vaultPluginState.enabledPlugins.push('verstak.secrets');
|
||||
vaultPluginState.desiredPlugins.push({ id: 'verstak.secrets', version: '0.1.0', source: 'official' });
|
||||
var appSettings = { currentVaultPath: '/tmp/verstak-test/vault', recentVaults: [] };
|
||||
var workbenchPreferences = {};
|
||||
var openedResources = [];
|
||||
@@ -301,6 +304,7 @@
|
||||
var trashPayloads = {};
|
||||
window.__wailsMockExternalOpens = [];
|
||||
var workspaceTree = makeDefaultWorkspaceTree();
|
||||
var workspaceMetadata = {};
|
||||
var reloadResponseMode = 'tuple';
|
||||
var syncState = makeDefaultSyncState();
|
||||
|
||||
@@ -334,6 +338,93 @@
|
||||
return { id: name, parentId: '', type: 'space', title: name, name: name, rootPath: name, status: 'active', order: order };
|
||||
}
|
||||
|
||||
function cloneJson(value) {
|
||||
return JSON.parse(JSON.stringify(value));
|
||||
}
|
||||
|
||||
function builtInWorkspaceTemplates() {
|
||||
return [
|
||||
{
|
||||
id: 'default',
|
||||
name: 'General',
|
||||
description: 'Everyday workspace with notes, files, journal, activity, and browser captures.',
|
||||
version: 2,
|
||||
workspaceTools: ['verstak.notes', 'verstak.files', 'verstak.journal', 'verstak.activity', 'verstak.browser-inbox'],
|
||||
folders: ['Notes', 'Files'],
|
||||
features: { files: true, notes: true, activity: true, journal: true, 'browser-inbox': true },
|
||||
},
|
||||
{
|
||||
id: 'project',
|
||||
name: 'Project',
|
||||
description: 'Project planning with todos, journal, activity, and browser captures.',
|
||||
version: 1,
|
||||
workspaceTools: ['verstak.notes', 'verstak.files', 'verstak.todo', 'verstak.journal', 'verstak.activity', 'verstak.browser-inbox'],
|
||||
folders: ['Notes', 'Files'],
|
||||
features: { files: true, notes: true, todo: true, journal: true, activity: true, 'browser-inbox': true },
|
||||
},
|
||||
{
|
||||
id: 'writing',
|
||||
name: 'Writing',
|
||||
description: 'Focused notes, files, and journal workspace for documentation and writing.',
|
||||
version: 1,
|
||||
workspaceTools: ['verstak.notes', 'verstak.files', 'verstak.journal'],
|
||||
folders: ['Notes', 'Files'],
|
||||
features: { files: true, notes: true, journal: true },
|
||||
},
|
||||
{
|
||||
id: 'admin',
|
||||
name: 'Admin',
|
||||
description: 'Infrastructure workspace with secrets, todos, and journal.',
|
||||
version: 1,
|
||||
workspaceTools: ['verstak.notes', 'verstak.files', 'verstak.secrets', 'verstak.todo', 'verstak.journal'],
|
||||
folders: ['Notes', 'Files', 'Secrets'],
|
||||
features: { files: true, notes: true, secrets: true, todo: true, journal: true },
|
||||
},
|
||||
{
|
||||
id: 'minimal',
|
||||
name: 'Minimal',
|
||||
description: 'Only notes and files for a lightweight workspace.',
|
||||
version: 1,
|
||||
workspaceTools: ['verstak.notes', 'verstak.files'],
|
||||
folders: ['Notes', 'Files'],
|
||||
features: { files: true, notes: true },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function workspaceTemplateByID(templateID) {
|
||||
var id = String(templateID || 'default');
|
||||
return builtInWorkspaceTemplates().find(function (template) { return template.id === id; }) || null;
|
||||
}
|
||||
|
||||
function metadataForTemplate(name, template) {
|
||||
var now = new Date().toISOString();
|
||||
var folders = { notes: 'Notes', files: 'Files' };
|
||||
if (template.features.secrets) folders.secrets = 'Secrets';
|
||||
return {
|
||||
workspaceName: name,
|
||||
createdFromTemplate: {
|
||||
templateId: template.id,
|
||||
templateName: template.name,
|
||||
templateVersion: template.version,
|
||||
appliedAt: now,
|
||||
workspaceTools: template.workspaceTools.slice(),
|
||||
},
|
||||
features: Object.assign({}, template.features),
|
||||
folders: folders,
|
||||
workspaceTools: template.workspaceTools.slice(),
|
||||
updatedAt: now,
|
||||
};
|
||||
}
|
||||
|
||||
function genericWorkspaceMetadata(name) {
|
||||
return {
|
||||
workspaceName: name,
|
||||
features: { files: true },
|
||||
folders: { notes: 'Notes', files: 'Files' },
|
||||
};
|
||||
}
|
||||
|
||||
function makeDefaultVaultFiles() {
|
||||
return {
|
||||
'': { type: 'folder', modifiedAt: new Date().toISOString() },
|
||||
@@ -405,6 +496,31 @@
|
||||
};
|
||||
}
|
||||
|
||||
function makeSecretsPluginState() {
|
||||
return {
|
||||
status: 'loaded',
|
||||
enabled: true,
|
||||
manifest: {
|
||||
schemaVersion: 1,
|
||||
id: 'verstak.secrets',
|
||||
name: 'Secrets',
|
||||
version: '0.1.0',
|
||||
apiVersion: '0.1.0',
|
||||
description: 'Encrypted global and workspace-scoped secret manager.',
|
||||
source: 'official',
|
||||
icon: 'key-round',
|
||||
provides: ['secret-store', 'secrets.read-ui', 'secrets.write-ui'],
|
||||
permissions: ['secrets.read', 'secrets.write', 'ui.register'],
|
||||
frontend: { entry: 'frontend/dist/index.js' },
|
||||
contributes: {
|
||||
workspaceItems: [{ id: 'verstak.secrets.workspace', title: 'Secrets', icon: 'key-round', component: 'SecretsView' }]
|
||||
}
|
||||
},
|
||||
rootPath: '/tmp/verstak-test/plugins/secrets',
|
||||
error: ''
|
||||
};
|
||||
}
|
||||
|
||||
function makeDefaultSyncState() {
|
||||
return {
|
||||
configured: false,
|
||||
@@ -3281,6 +3397,9 @@
|
||||
if (pluginId === 'verstak.todo' && assetPath === 'frontend/dist/index.js') {
|
||||
return Promise.resolve(todoBundle());
|
||||
}
|
||||
if (pluginId === 'verstak.secrets' && assetPath === 'frontend/dist/index.js') {
|
||||
return Promise.resolve(simplePluginBundle('verstak.secrets', 'SecretsView', 'secrets-root', 'Secrets'));
|
||||
}
|
||||
if (pluginId === 'verstak.search' && assetPath === 'frontend/dist/index.js') {
|
||||
return Promise.resolve(searchPluginBundle());
|
||||
}
|
||||
@@ -3507,15 +3626,30 @@
|
||||
ListWorkspaces: function () {
|
||||
return Promise.resolve(listWorkspacesFromTree());
|
||||
},
|
||||
CreateWorkspace: function (name) {
|
||||
ListWorkspaceTemplates: function () {
|
||||
return Promise.resolve(builtInWorkspaceTemplates().map(function (template) {
|
||||
return {
|
||||
id: template.id,
|
||||
name: template.name,
|
||||
description: template.description,
|
||||
version: template.version,
|
||||
workspaceTools: template.workspaceTools.slice()
|
||||
};
|
||||
}));
|
||||
},
|
||||
CreateWorkspace: function (name, templateID) {
|
||||
var norm = normalizeVaultPath(name, false);
|
||||
if (norm.error || norm.path !== String(name || '').trim() || norm.path.indexOf('/') !== -1) {
|
||||
return Promise.resolve(norm.error || 'invalid-workspace-name');
|
||||
}
|
||||
if (vaultFiles[norm.path]) return Promise.resolve('conflict: ' + norm.path);
|
||||
var template = workspaceTemplateByID(templateID);
|
||||
if (!template) return Promise.resolve('template-not-found: ' + String(templateID || ''));
|
||||
vaultFiles[norm.path] = { type: 'folder', modifiedAt: new Date().toISOString() };
|
||||
vaultFiles[norm.path + '/Notes'] = { type: 'folder', modifiedAt: new Date().toISOString() };
|
||||
vaultFiles[norm.path + '/Notes/Overview.md'] = { type: 'file', content: '# Overview\n', modifiedAt: new Date().toISOString() };
|
||||
template.folders.forEach(function (folder) {
|
||||
vaultFiles[norm.path + '/' + folder] = { type: 'folder', modifiedAt: new Date().toISOString() };
|
||||
});
|
||||
workspaceMetadata[norm.path] = metadataForTemplate(norm.path, template);
|
||||
workspaceTree.nodes.push(makeWorkspaceNode(norm.path, workspaceTree.nodes.length + 1));
|
||||
return Promise.resolve({ name: norm.path, rootPath: norm.path });
|
||||
},
|
||||
@@ -3537,6 +3671,10 @@
|
||||
if (n.id !== oldNorm.path) return n;
|
||||
return makeWorkspaceNode(newNorm.path, n.order);
|
||||
});
|
||||
if (workspaceMetadata[oldNorm.path]) {
|
||||
workspaceMetadata[newNorm.path] = Object.assign({}, workspaceMetadata[oldNorm.path], { workspaceName: newNorm.path });
|
||||
delete workspaceMetadata[oldNorm.path];
|
||||
}
|
||||
if (workspaceTree.currentNodeId === oldNorm.path) workspaceTree.currentNodeId = newNorm.path;
|
||||
return Promise.resolve('');
|
||||
},
|
||||
@@ -3548,6 +3686,7 @@
|
||||
return path === norm.path || path.indexOf(norm.path + '/') === 0;
|
||||
}).forEach(function (path) { delete vaultFiles[path]; });
|
||||
workspaceTree.nodes = workspaceTree.nodes.filter(function (n) { return n.id !== norm.path; });
|
||||
delete workspaceMetadata[norm.path];
|
||||
if (workspaceTree.currentNodeId === norm.path) workspaceTree.currentNodeId = workspaceTree.nodes[0] ? workspaceTree.nodes[0].id : '';
|
||||
return Promise.resolve({ originalPath: norm.path, trashPath: '.verstak/trash/workspaces/mock/' + norm.path, trashId: 'mock', deletedAt: new Date().toISOString() });
|
||||
},
|
||||
@@ -3555,14 +3694,15 @@
|
||||
var norm = normalizeVaultPath(name, false);
|
||||
if (norm.error) return Promise.resolve(norm.error);
|
||||
if (!vaultFiles[norm.path]) return Promise.resolve('not-found: ' + norm.path);
|
||||
return Promise.resolve({
|
||||
workspaceName: norm.path,
|
||||
features: { files: true },
|
||||
folders: { notes: 'Notes', files: 'Files' }
|
||||
});
|
||||
return Promise.resolve(cloneJson(workspaceMetadata[norm.path] || genericWorkspaceMetadata(norm.path)));
|
||||
},
|
||||
UpdateWorkspaceMetadata: function (name, patch) {
|
||||
return Promise.resolve(Object.assign({ workspaceName: name, features: { files: true }, folders: { notes: 'Notes', files: 'Files' } }, patch || {}));
|
||||
var norm = normalizeVaultPath(name, false);
|
||||
if (norm.error) return Promise.resolve(norm.error);
|
||||
if (!vaultFiles[norm.path]) return Promise.resolve('not-found: ' + norm.path);
|
||||
var next = Object.assign({}, workspaceMetadata[norm.path] || genericWorkspaceMetadata(norm.path), patch || {}, { workspaceName: norm.path, updatedAt: new Date().toISOString() });
|
||||
workspaceMetadata[norm.path] = next;
|
||||
return Promise.resolve(cloneJson(next));
|
||||
},
|
||||
GetCurrentWorkspace: function () {
|
||||
var found = workspaceTree.nodes.find(function (n) { return n.id === workspaceTree.currentNodeId; });
|
||||
@@ -3891,6 +4031,7 @@
|
||||
error: ''
|
||||
},
|
||||
'verstak.todo': makeTodoPluginState(),
|
||||
'verstak.secrets': makeSecretsPluginState(),
|
||||
'verstak.search': {
|
||||
status: 'loaded',
|
||||
enabled: true,
|
||||
@@ -3923,6 +4064,8 @@
|
||||
vaultPluginState.desiredPlugins.push({ id: 'verstak.trash', version: '0.1.0', source: 'official' });
|
||||
vaultPluginState.enabledPlugins.push('verstak.todo');
|
||||
vaultPluginState.desiredPlugins.push({ id: 'verstak.todo', version: '0.1.0', source: 'official' });
|
||||
vaultPluginState.enabledPlugins.push('verstak.secrets');
|
||||
vaultPluginState.desiredPlugins.push({ id: 'verstak.secrets', version: '0.1.0', source: 'official' });
|
||||
appSettings = { currentVaultPath: '/tmp/verstak-test/vault', recentVaults: [] };
|
||||
workbenchPreferences = {};
|
||||
openedResources = [];
|
||||
@@ -3933,6 +4076,7 @@
|
||||
trashPayloads = {};
|
||||
window.__wailsMockExternalOpens = [];
|
||||
workspaceTree = makeDefaultWorkspaceTree();
|
||||
workspaceMetadata = {};
|
||||
reloadResponseMode = 'tuple';
|
||||
syncState = makeDefaultSyncState();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user