sh3-core 0.19.6 → 0.20.1

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.
Files changed (66) hide show
  1. package/dist/app/admin/AuthSettingsView.svelte +3 -9
  2. package/dist/app/admin/MountsView.svelte +276 -0
  3. package/dist/app/admin/MountsView.svelte.d.ts +3 -0
  4. package/dist/app/admin/SystemView.svelte +6 -6
  5. package/dist/app/admin/UsersView.svelte +103 -7
  6. package/dist/app/admin/adminApp.js +1 -0
  7. package/dist/app/admin/adminShard.svelte.js +10 -0
  8. package/dist/apps/lifecycle.js +1 -0
  9. package/dist/apps/types.d.ts +7 -0
  10. package/dist/assets/iconIds.generated.d.ts +1 -1
  11. package/dist/assets/iconIds.generated.js +1 -0
  12. package/dist/assets/icons.svg +5 -0
  13. package/dist/auth/admin-users.svelte.js +2 -1
  14. package/dist/auth/auth.svelte.d.ts +4 -5
  15. package/dist/auth/auth.svelte.js +5 -6
  16. package/dist/auth/types.d.ts +0 -2
  17. package/dist/chrome/CompactChrome.svelte +25 -6
  18. package/dist/chrome/FloatsSheet.svelte +7 -32
  19. package/dist/chrome/FloatsSheet.svelte.d.ts +1 -2
  20. package/dist/chrome/FloatsSheet.svelte.test.js +8 -14
  21. package/dist/chrome/MenuSheet.svelte +154 -148
  22. package/dist/chrome/MenuSheet.svelte.d.ts +1 -2
  23. package/dist/chrome/MenuSheet.svelte.test.js +24 -12
  24. package/dist/createShell.js +32 -21
  25. package/dist/createShell.remoteAuth.test.js +9 -3
  26. package/dist/documents/browse.d.ts +18 -1
  27. package/dist/documents/browse.js +40 -7
  28. package/dist/documents/browse.test.js +35 -35
  29. package/dist/documents/config.d.ts +4 -0
  30. package/dist/documents/config.js +15 -2
  31. package/dist/documents/handle.js +25 -17
  32. package/dist/documents/http-backend.js +10 -2
  33. package/dist/documents/index.d.ts +2 -2
  34. package/dist/documents/index.js +1 -1
  35. package/dist/documents/picker-api.d.ts +4 -2
  36. package/dist/documents/picker-api.test.d.ts +1 -1
  37. package/dist/documents/picker-api.test.js +87 -57
  38. package/dist/documents/picker-primitive.d.ts +4 -0
  39. package/dist/documents/picker-primitive.js +27 -29
  40. package/dist/documents/types.d.ts +17 -5
  41. package/dist/documents/types.js +2 -0
  42. package/dist/layout/presets.test.js +4 -4
  43. package/dist/layout/types.d.ts +1 -1
  44. package/dist/layouts-shard/LayoutsSection.svelte +3 -16
  45. package/dist/primitives/widgets/DocumentFilePicker.svelte +4 -4
  46. package/dist/primitives/widgets/PickerList.svelte +1 -0
  47. package/dist/primitives/widgets/_DocumentBrowser.svelte +5 -8
  48. package/dist/projects-shard/DeleteProjectDialog.svelte +32 -1
  49. package/dist/projects-shard/ProjectManage.svelte +197 -28
  50. package/dist/projects-shard/ProjectManage.svelte.test.d.ts +1 -0
  51. package/dist/projects-shard/ProjectManage.svelte.test.js +320 -0
  52. package/dist/projects-shard/ProjectsSection.svelte +3 -16
  53. package/dist/projects-shard/projectsApi.js +2 -1
  54. package/dist/registry/permission-descriptions.js +4 -0
  55. package/dist/server-shard/types.d.ts +21 -0
  56. package/dist/sh3core-shard/HomeSection.svelte +107 -0
  57. package/dist/sh3core-shard/HomeSection.svelte.d.ts +10 -0
  58. package/dist/sh3core-shard/Sh3Home.svelte +9 -23
  59. package/dist/shards/activate.svelte.d.ts +4 -0
  60. package/dist/shards/activate.svelte.js +9 -1
  61. package/dist/shards/types.d.ts +7 -0
  62. package/dist/shell-shard/tenant-fs-client.js +2 -1
  63. package/dist/transport/apiFetch.js +12 -5
  64. package/dist/version.d.ts +1 -1
  65. package/dist/version.js +1 -1
  66. package/package.json +1 -1
@@ -31,36 +31,43 @@ export function createDocumentHandle(tenantId, shardId, backend, options) {
31
31
  return true;
32
32
  return options.extensions.some((ext) => path.endsWith(ext));
33
33
  }
34
- function emitChange(type, path) {
35
- documentChanges.emit({ type, path, tenantId, shardId });
34
+ function resolveTenant(opts) {
35
+ var _a;
36
+ return (_a = opts === null || opts === void 0 ? void 0 : opts.scope) !== null && _a !== void 0 ? _a : tenantId;
37
+ }
38
+ function emitChange(type, path, tid) {
39
+ documentChanges.emit({ type, path, tenantId: tid, shardId });
36
40
  }
37
41
  const handle = {
38
- async list() {
39
- const all = await backend.list(tenantId, shardId);
42
+ async list(opts) {
43
+ const tid = resolveTenant(opts);
44
+ const all = await backend.list(tid, shardId);
40
45
  if (!options.extensions || options.extensions.length === 0)
41
46
  return all;
42
47
  return all.filter((meta) => matchesExtensions(meta.path));
43
48
  },
44
- async read(path) {
45
- const content = await backend.read(tenantId, shardId, path);
49
+ async read(path, opts) {
50
+ const content = await backend.read(resolveTenant(opts), shardId, path);
46
51
  if (content === null)
47
52
  return null;
48
53
  // Phase 1: text format only. Binary returns as-is from the backend
49
54
  // but the handle types it as string for text-format handles.
50
55
  return typeof content === 'string' ? content : new TextDecoder().decode(content);
51
56
  },
52
- async write(path, content) {
53
- const existed = await backend.exists(tenantId, shardId, path);
54
- await backend.write(tenantId, shardId, path, content);
55
- emitChange(existed ? 'update' : 'create', path);
57
+ async write(path, content, opts) {
58
+ const tid = resolveTenant(opts);
59
+ const existed = await backend.exists(tid, shardId, path);
60
+ await backend.write(tid, shardId, path, content);
61
+ emitChange(existed ? 'update' : 'create', path, tid);
56
62
  },
57
- async delete(path) {
58
- const existed = await backend.exists(tenantId, shardId, path);
59
- await backend.delete(tenantId, shardId, path);
63
+ async delete(path, opts) {
64
+ const tid = resolveTenant(opts);
65
+ const existed = await backend.exists(tid, shardId, path);
66
+ await backend.delete(tid, shardId, path);
60
67
  if (existed)
61
- emitChange('delete', path);
68
+ emitChange('delete', path, tid);
62
69
  },
63
- async rename(oldPath, newPath) {
70
+ async rename(oldPath, newPath, opts) {
64
71
  if (!matchesExtensions(newPath)) {
65
72
  throw new Error(`Cannot rename to ${newPath}: violates handle extensions filter`);
66
73
  }
@@ -69,12 +76,13 @@ export function createDocumentHandle(tenantId, shardId, backend, options) {
69
76
  throw new Error(`Cannot rename: active autosave on ${oldPath}; flush and dispose first`);
70
77
  }
71
78
  }
72
- await backend.rename(tenantId, shardId, oldPath, newPath);
79
+ const tid = resolveTenant(opts);
80
+ await backend.rename(tid, shardId, oldPath, newPath);
73
81
  documentChanges.emit({
74
82
  type: 'rename',
75
83
  path: newPath,
76
84
  oldPath,
77
- tenantId,
85
+ tenantId: tid,
78
86
  shardId,
79
87
  });
80
88
  },
@@ -52,8 +52,16 @@ export class HttpDocumentBackend {
52
52
  const url = `${__classPrivateFieldGet(this, _HttpDocumentBackend_baseUrl, "f")}/api/docs/${tenantId}/${shardId}/${path}`;
53
53
  const headers = Object.assign(Object.assign({}, __classPrivateFieldGet(this, _HttpDocumentBackend_instances, "m", _HttpDocumentBackend_authHeaders).call(this)), { 'Content-Type': typeof content === 'string' ? 'text/plain' : 'application/octet-stream' });
54
54
  const res = await apiFetch(url, { method: 'PUT', headers, body: content, credentials: 'include' });
55
- if (!res.ok)
56
- throw new Error(`Document write failed: ${res.status}`);
55
+ if (!res.ok) {
56
+ let detail = `HTTP ${res.status}`;
57
+ try {
58
+ const b = await res.json();
59
+ if (b.error)
60
+ detail = b.error;
61
+ }
62
+ catch ( /* body not JSON */_a) { /* body not JSON */ }
63
+ throw new Error(`Document write failed: ${detail}`);
64
+ }
57
65
  }
58
66
  async delete(tenantId, shardId, path) {
59
67
  const url = `${__classPrivateFieldGet(this, _HttpDocumentBackend_baseUrl, "f")}/api/docs/${tenantId}/${shardId}/${path}`;
@@ -1,8 +1,8 @@
1
- export type { DocumentFormat, DocumentHandleOptions, DocumentMeta, DocumentChange, DocumentBackend, DocumentHandle, AutosaveController, } from './types';
1
+ export type { DocumentFormat, DocumentHandleOptions, DocumentMeta, DocumentChange, DocumentBackend, DocumentHandle, AutosaveController, ScopeOption, } from './types';
2
2
  export { MemoryDocumentBackend, IndexedDBDocumentBackend } from './backends';
3
3
  export { HttpDocumentBackend } from './http-backend';
4
4
  export { createDocumentHandle } from './handle';
5
5
  export { documentChanges } from './notifications';
6
- export { getActiveScopeId, getTenantId, getDocumentBackend, __setActiveScope, __setTenantId, __setDocumentBackend, } from './config';
6
+ export { getActiveScopeId, getTenantId, getDocumentBackend, __setActiveScope, __setTenantId, __setDocumentBackend, __setScopeResolver, } from './config';
7
7
  export type { SyncPolicy, SyncPolicyRule, DocStatus, ConflictFile, ConflictBranch, } from './sync-types';
8
8
  export { PERMISSION_SYNC_PEER, PERMISSION_SYNC_POLICY, } from './sync-types';
@@ -5,5 +5,5 @@ export { MemoryDocumentBackend, IndexedDBDocumentBackend } from './backends';
5
5
  export { HttpDocumentBackend } from './http-backend';
6
6
  export { createDocumentHandle } from './handle';
7
7
  export { documentChanges } from './notifications';
8
- export { getActiveScopeId, getTenantId, getDocumentBackend, __setActiveScope, __setTenantId, __setDocumentBackend, } from './config';
8
+ export { getActiveScopeId, getTenantId, getDocumentBackend, __setActiveScope, __setTenantId, __setDocumentBackend, __setScopeResolver, } from './config';
9
9
  export { PERMISSION_SYNC_PEER, PERMISSION_SYNC_POLICY, } from './sync-types';
@@ -3,14 +3,16 @@ import type { DocEntry, OpenerValue, SaverValue } from '../primitives/widgets/Do
3
3
  export type DocListFn = () => Promise<DocEntry[]>;
4
4
  /** Options for `ctx.documentPicker.open()`. */
5
5
  export interface DocumentOpenOptions {
6
- /** Element to anchor the popup to. Defaults to viewport center. */
6
+ /** When set, the browser opens as a popup anchored to this element.
7
+ * When omitted (default), the browser opens as a centered modal. */
7
8
  anchor?: HTMLElement;
8
9
  }
9
10
  /** Options for `ctx.documentPicker.save()`. */
10
11
  export interface DocumentSaveOptions {
11
12
  /** Pre-fill the filename input in the save dialog. */
12
13
  suggestedName?: string;
13
- /** Element to anchor the popup to. Defaults to viewport center. */
14
+ /** When set, the browser opens as a popup anchored to this element.
15
+ * When omitted (default), the browser opens as a centered modal. */
14
16
  anchor?: HTMLElement;
15
17
  }
16
18
  /** Programmatic document picker API — available on `ctx.documentPicker`. */
@@ -1 +1 @@
1
- export {};
1
+ import '../sh3Runtime.svelte';
@@ -1,35 +1,41 @@
1
1
  import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { sh3 } from '../sh3Runtime.svelte';
2
+ import '../sh3Runtime.svelte'; // intercepted by vi.mock below
3
3
  import { createDocumentPicker } from './picker-primitive';
4
+ const { mockPopupShow, mockModalOpen } = vi.hoisted(() => ({
5
+ mockPopupShow: vi.fn(),
6
+ mockModalOpen: vi.fn(),
7
+ }));
4
8
  vi.mock('../sh3Runtime.svelte', () => ({
5
9
  sh3: {
6
- popup: {
7
- show: vi.fn(),
8
- },
10
+ popup: { show: mockPopupShow },
11
+ modal: { open: mockModalOpen },
9
12
  },
10
13
  }));
11
- const mockShow = sh3.popup.show;
12
14
  function mockPopup() {
13
- let capturedCommit = null;
14
- let capturedCancel = null;
15
- const handle = {
16
- close: vi.fn(),
15
+ let captured = null;
16
+ const handle = { close: vi.fn() };
17
+ mockPopupShow.mockImplementation((_Content, _opts, props) => {
18
+ captured = props;
19
+ return handle;
20
+ });
21
+ return {
22
+ commit: (v) => { captured === null || captured === void 0 ? void 0 : captured.onCommit(v); },
23
+ cancel: () => { captured === null || captured === void 0 ? void 0 : captured.onCancel(); },
24
+ dismiss: () => { handle.close(); },
25
+ handle,
17
26
  };
18
- mockShow.mockImplementation((_Content, _opts, props) => {
19
- capturedCommit = props.onCommit;
20
- capturedCancel = props.onCancel;
27
+ }
28
+ function mockModal() {
29
+ let captured = null;
30
+ const handle = { close: vi.fn() };
31
+ mockModalOpen.mockImplementation((_Content, props) => {
32
+ captured = props;
21
33
  return handle;
22
34
  });
23
35
  return {
24
- commit: (v) => {
25
- capturedCommit === null || capturedCommit === void 0 ? void 0 : capturedCommit(v);
26
- },
27
- cancel: () => {
28
- capturedCancel === null || capturedCancel === void 0 ? void 0 : capturedCancel();
29
- },
30
- dismiss: () => {
31
- handle.close();
32
- },
36
+ commit: (v) => { captured === null || captured === void 0 ? void 0 : captured.onCommit(v); },
37
+ cancel: () => { captured === null || captured === void 0 ? void 0 : captured.onCancel(); },
38
+ dismiss: () => { handle.close(); },
33
39
  handle,
34
40
  };
35
41
  }
@@ -38,34 +44,35 @@ beforeEach(() => {
38
44
  });
39
45
  describe('createDocumentPicker', () => {
40
46
  const sampleDoc = { shardId: 'my-shard', path: 'readme.md' };
41
- describe('open()', () => {
47
+ describe('open() — modal (no anchor)', () => {
42
48
  it('resolves with OpenerValue when user commits', async () => {
43
49
  const listFn = async () => [{ shardId: 'my-shard', path: 'readme.md', size: 100, lastModified: 0 }];
44
50
  const picker = createDocumentPicker(listFn);
45
- const popup = mockPopup();
51
+ const modal = mockModal();
46
52
  const promise = picker.open();
47
- await vi.waitFor(() => expect(mockShow).toHaveBeenCalledOnce());
48
- popup.commit(sampleDoc);
53
+ await vi.waitFor(() => expect(mockModalOpen).toHaveBeenCalledOnce());
54
+ modal.commit(sampleDoc);
49
55
  const result = await promise;
50
56
  expect(result).toEqual({ shardId: 'my-shard', path: 'readme.md' });
57
+ expect(mockPopupShow).not.toHaveBeenCalled();
51
58
  });
52
59
  it('resolves with null when user cancels', async () => {
53
60
  const listFn = async () => [];
54
61
  const picker = createDocumentPicker(listFn);
55
- const popup = mockPopup();
62
+ const modal = mockModal();
56
63
  const promise = picker.open();
57
- await vi.waitFor(() => expect(mockShow).toHaveBeenCalledOnce());
58
- popup.cancel();
64
+ await vi.waitFor(() => expect(mockModalOpen).toHaveBeenCalledOnce());
65
+ modal.cancel();
59
66
  const result = await promise;
60
67
  expect(result).toBeNull();
61
68
  });
62
- it('resolves with null when popup is dismissed externally', async () => {
69
+ it('resolves with null when modal is dismissed externally', async () => {
63
70
  const listFn = async () => [];
64
71
  const picker = createDocumentPicker(listFn);
65
- const popup = mockPopup();
72
+ const modal = mockModal();
66
73
  const promise = picker.open();
67
- await vi.waitFor(() => expect(mockShow).toHaveBeenCalledOnce());
68
- popup.dismiss();
74
+ await vi.waitFor(() => expect(mockModalOpen).toHaveBeenCalledOnce());
75
+ modal.dismiss();
69
76
  const result = await promise;
70
77
  expect(result).toBeNull();
71
78
  });
@@ -74,59 +81,82 @@ describe('createDocumentPicker', () => {
74
81
  const picker = createDocumentPicker(listFn);
75
82
  const promise = picker.open();
76
83
  await expect(promise).rejects.toThrow('network error');
77
- expect(mockShow).not.toHaveBeenCalled();
84
+ expect(mockModalOpen).not.toHaveBeenCalled();
85
+ expect(mockPopupShow).not.toHaveBeenCalled();
78
86
  });
79
- it('uses anchor element position when provided', async () => {
87
+ it('passes mode and dismissOnBackdrop to modal', async () => {
88
+ const listFn = async () => [];
89
+ const picker = createDocumentPicker(listFn);
90
+ mockModal();
91
+ picker.open();
92
+ await vi.waitFor(() => expect(mockModalOpen).toHaveBeenCalledOnce());
93
+ const call = mockModalOpen.mock.calls[0];
94
+ expect(call[1].mode).toBe('open');
95
+ expect(call[2]).toEqual({ dismissOnBackdrop: true, boxStyle: 'max-width: min(800px, 95vw);' });
96
+ });
97
+ });
98
+ describe('open() — popup (with anchor)', () => {
99
+ it('uses popup when anchor element is provided', async () => {
80
100
  const listFn = async () => [];
81
101
  const picker = createDocumentPicker(listFn);
82
102
  mockPopup();
83
103
  const el = document.createElement('div');
84
104
  picker.open({ anchor: el });
85
- await vi.waitFor(() => expect(mockShow).toHaveBeenCalledOnce());
86
- const call = mockShow.mock.calls[0];
105
+ await vi.waitFor(() => expect(mockPopupShow).toHaveBeenCalledOnce());
106
+ expect(mockModalOpen).not.toHaveBeenCalled();
107
+ const call = mockPopupShow.mock.calls[0];
87
108
  expect(call[1].anchor).toEqual({ x: 0, y: 0 });
88
109
  });
89
110
  });
90
- describe('save()', () => {
111
+ describe('save() — modal (no anchor)', () => {
91
112
  it('resolves with SaverValue string when user commits a filename', async () => {
92
113
  const listFn = async () => [];
93
114
  const picker = createDocumentPicker(listFn);
94
- const popup = mockPopup();
115
+ const modal = mockModal();
95
116
  const promise = picker.save();
96
- await vi.waitFor(() => expect(mockShow).toHaveBeenCalledOnce());
97
- popup.commit('my-shard/report.txt');
117
+ await vi.waitFor(() => expect(mockModalOpen).toHaveBeenCalledOnce());
118
+ modal.commit('my-shard/report.txt');
98
119
  const result = await promise;
99
120
  expect(result).toBe('my-shard/report.txt');
100
121
  });
101
122
  it('resolves with null when user cancels', async () => {
102
123
  const listFn = async () => [];
103
124
  const picker = createDocumentPicker(listFn);
104
- const popup = mockPopup();
125
+ const modal = mockModal();
105
126
  const promise = picker.save();
106
- await vi.waitFor(() => expect(mockShow).toHaveBeenCalledOnce());
107
- popup.cancel();
127
+ await vi.waitFor(() => expect(mockModalOpen).toHaveBeenCalledOnce());
128
+ modal.cancel();
108
129
  const result = await promise;
109
130
  expect(result).toBeNull();
110
131
  });
111
132
  it('passes suggestedName as prop', async () => {
112
133
  const listFn = async () => [];
113
134
  const picker = createDocumentPicker(listFn);
114
- mockPopup();
135
+ mockModal();
115
136
  picker.save({ suggestedName: 'draft.txt' });
116
- await vi.waitFor(() => expect(mockShow).toHaveBeenCalledOnce());
117
- const call = mockShow.mock.calls[0];
118
- expect(call[2].suggestedName).toBe('draft.txt');
137
+ await vi.waitFor(() => expect(mockModalOpen).toHaveBeenCalledOnce());
138
+ const call = mockModalOpen.mock.calls[0];
139
+ expect(call[1].suggestedName).toBe('draft.txt');
140
+ });
141
+ it('passes mode to modal', async () => {
142
+ const listFn = async () => [];
143
+ const picker = createDocumentPicker(listFn);
144
+ mockModal();
145
+ picker.save();
146
+ await vi.waitFor(() => expect(mockModalOpen).toHaveBeenCalledOnce());
147
+ const call = mockModalOpen.mock.calls[0];
148
+ expect(call[1].mode).toBe('save');
119
149
  });
120
150
  });
121
- it('defaults anchor to viewport center when not provided', async () => {
122
- const listFn = async () => [];
123
- const picker = createDocumentPicker(listFn);
124
- mockPopup();
125
- const w = window.innerWidth;
126
- const h = window.innerHeight;
127
- picker.open();
128
- await vi.waitFor(() => expect(mockShow).toHaveBeenCalledOnce());
129
- const call = mockShow.mock.calls[0];
130
- expect(call[1].anchor).toEqual({ x: w / 2, y: h / 2 });
151
+ describe('save() popup (with anchor)', () => {
152
+ it('uses popup when anchor element is provided', async () => {
153
+ const listFn = async () => [];
154
+ const picker = createDocumentPicker(listFn);
155
+ mockPopup();
156
+ const el = document.createElement('div');
157
+ picker.save({ anchor: el });
158
+ await vi.waitFor(() => expect(mockPopupShow).toHaveBeenCalledOnce());
159
+ expect(mockModalOpen).not.toHaveBeenCalled();
160
+ });
131
161
  });
132
162
  });
@@ -3,5 +3,9 @@ import type { DocumentPickerApi, DocListFn } from './picker-api';
3
3
  * Create a document picker API bound to a document listing function.
4
4
  * The listFn is derived from the shard's document zone + browse permission
5
5
  * and baked in at construction time so callers don't pass their own scope.
6
+ *
7
+ * When an `anchor` element is provided the browser opens as a popup
8
+ * (anchored near the element). Without an anchor it opens as a centered
9
+ * modal (the expected default for file-browser dialogs).
6
10
  */
7
11
  export declare function createDocumentPicker(listFn: DocListFn): DocumentPickerApi;
@@ -1,57 +1,55 @@
1
1
  import { sh3 } from '../sh3Runtime.svelte';
2
2
  import DocumentBrowser from '../primitives/widgets/_DocumentBrowser.svelte';
3
+ const BOX_STYLE = 'max-width: min(800px, 95vw);';
4
+ const MODAL_OPTS = { dismissOnBackdrop: true, boxStyle: BOX_STYLE };
3
5
  /**
4
6
  * Create a document picker API bound to a document listing function.
5
7
  * The listFn is derived from the shard's document zone + browse permission
6
8
  * and baked in at construction time so callers don't pass their own scope.
9
+ *
10
+ * When an `anchor` element is provided the browser opens as a popup
11
+ * (anchored near the element). Without an anchor it opens as a centered
12
+ * modal (the expected default for file-browser dialogs).
7
13
  */
8
14
  export function createDocumentPicker(listFn) {
9
- function anchorOrDefault(anchor) {
15
+ /** Resolve handle for either popup (anchored) or modal (centered) path. */
16
+ function openBrowser(browserProps, anchor) {
10
17
  if (anchor) {
11
18
  const rect = anchor.getBoundingClientRect();
12
- return { x: rect.left + rect.width / 2, y: rect.top };
19
+ return sh3.popup.show(DocumentBrowser, { anchor: { x: rect.left + rect.width / 2, y: rect.top } }, browserProps);
13
20
  }
14
- return { x: window.innerWidth / 2, y: window.innerHeight / 2 };
21
+ return sh3.modal.open(DocumentBrowser, browserProps, MODAL_OPTS);
22
+ }
23
+ function wrapHandle(handle, resolve) {
24
+ const origClose = handle.close;
25
+ handle.close = () => {
26
+ origClose();
27
+ resolve(null);
28
+ };
15
29
  }
16
30
  async function open(opts) {
17
31
  const docs = await listFn();
18
32
  return new Promise((resolve) => {
19
- const handle = sh3.popup.show(DocumentBrowser, { anchor: anchorOrDefault(opts === null || opts === void 0 ? void 0 : opts.anchor) }, {
33
+ const handle = openBrowser({
20
34
  mode: 'open',
21
35
  docs,
22
- onCommit: (value) => {
23
- resolve(value);
24
- },
25
- onCancel: () => {
26
- resolve(null);
27
- },
28
- });
29
- const origClose = handle.close;
30
- handle.close = () => {
31
- origClose();
32
- resolve(null);
33
- };
36
+ onCommit: (value) => { resolve(value); },
37
+ onCancel: () => { resolve(null); },
38
+ }, opts === null || opts === void 0 ? void 0 : opts.anchor);
39
+ wrapHandle(handle, resolve);
34
40
  });
35
41
  }
36
42
  async function save(opts) {
37
43
  const docs = await listFn();
38
44
  return new Promise((resolve) => {
39
- const handle = sh3.popup.show(DocumentBrowser, { anchor: anchorOrDefault(opts === null || opts === void 0 ? void 0 : opts.anchor) }, {
45
+ const handle = openBrowser({
40
46
  mode: 'save',
41
47
  docs,
42
48
  suggestedName: opts === null || opts === void 0 ? void 0 : opts.suggestedName,
43
- onCommit: (value) => {
44
- resolve(value);
45
- },
46
- onCancel: () => {
47
- resolve(null);
48
- },
49
- });
50
- const origClose = handle.close;
51
- handle.close = () => {
52
- origClose();
53
- resolve(null);
54
- };
49
+ onCommit: (value) => { resolve(value); },
50
+ onCancel: () => { resolve(null); },
51
+ }, opts === null || opts === void 0 ? void 0 : opts.anchor);
52
+ wrapHandle(handle, resolve);
55
53
  });
56
54
  }
57
55
  return { open, save };
@@ -34,6 +34,8 @@ export declare const PERMISSION_DOCUMENTS_READ = "documents:read";
34
34
  * `browse`.
35
35
  */
36
36
  export declare const PERMISSION_DOCUMENTS_WRITE = "documents:write";
37
+ /** Permission to manage document mount points (admin-only). */
38
+ export declare const PERMISSION_DOCUMENTS_MOUNT = "documents:mount";
37
39
  /**
38
40
  * Format hint for document content. Determines whether reads return a string
39
41
  * (`text`) or an `ArrayBuffer` (`binary`).
@@ -158,23 +160,33 @@ export interface DocumentBackend {
158
160
  /**
159
161
  * Shard-facing document handle returned by `ctx.documents()`. Binds
160
162
  * the tenant, shard, and backend so shard code only deals in paths.
163
+ *
164
+ * All read/write/list/delete/rename methods accept an optional scope
165
+ * override for cross-scope document transfers (e.g. moving documents
166
+ * between a personal tenant and a project). When omitted, the handle's
167
+ * bound tenant is used.
161
168
  */
169
+ /** Optional scope override for cross-tenant operations. */
170
+ export interface ScopeOption {
171
+ /** Override the handle's bound tenant for a single operation. */
172
+ scope?: string;
173
+ }
162
174
  export interface DocumentHandle {
163
175
  /** List documents matching the handle's extensions filter. */
164
- list(): Promise<DocumentMeta[]>;
176
+ list(opts?: ScopeOption): Promise<DocumentMeta[]>;
165
177
  /** Read a document by path. Returns null if not found. */
166
- read(path: string): Promise<string | null>;
178
+ read(path: string, opts?: ScopeOption): Promise<string | null>;
167
179
  /** Write (create or overwrite) a document. Explicit save. */
168
- write(path: string, content: string): Promise<void>;
180
+ write(path: string, content: string, opts?: ScopeOption): Promise<void>;
169
181
  /** Delete a document. */
170
- delete(path: string): Promise<void>;
182
+ delete(path: string, opts?: ScopeOption): Promise<void>;
171
183
  /**
172
184
  * Rename a document. Throws if there is an active autosave controller
173
185
  * for oldPath (caller must flush and dispose first). Throws if newPath
174
186
  * already exists or if oldPath does not. Subject to the handle's
175
187
  * extensions filter — newPath must satisfy the filter.
176
188
  */
177
- rename(oldPath: string, newPath: string): Promise<void>;
189
+ rename(oldPath: string, newPath: string, opts?: ScopeOption): Promise<void>;
178
190
  /** Check existence without reading content. */
179
191
  exists(path: string): Promise<boolean>;
180
192
  /** Fetch sync-state metadata for a path. Null if the doc does not exist. */
@@ -45,6 +45,8 @@ export const PERMISSION_DOCUMENTS_READ = 'documents:read';
45
45
  * `browse`.
46
46
  */
47
47
  export const PERMISSION_DOCUMENTS_WRITE = 'documents:write';
48
+ /** Permission to manage document mount points (admin-only). */
49
+ export const PERMISSION_DOCUMENTS_MOUNT = 'documents:mount';
48
50
  /** Type guard: narrows a DocumentChange to the rename variant. */
49
51
  export function isRename(change) {
50
52
  return change.type === 'rename';
@@ -25,7 +25,7 @@ describe('normalizeInitialLayout', () => {
25
25
  });
26
26
  it('canonicalizes a preset list, using tree as default and preserving variants', () => {
27
27
  const authorTree = { docked: leafNode, floats: [] };
28
- const companionTree = {
28
+ const compactTree = {
29
29
  docked: { type: 'slot', slotId: 's2', viewId: 'v2' },
30
30
  floats: [],
31
31
  };
@@ -33,7 +33,7 @@ describe('normalizeInitialLayout', () => {
33
33
  {
34
34
  name: 'author',
35
35
  tree: authorTree,
36
- variants: { companion: companionTree },
36
+ variants: { compact: compactTree },
37
37
  },
38
38
  ];
39
39
  const result = normalizeInitialLayout(presets);
@@ -42,7 +42,7 @@ describe('normalizeInitialLayout', () => {
42
42
  name: 'author',
43
43
  variants: {
44
44
  default: authorTree,
45
- companion: companionTree,
45
+ compact: compactTree,
46
46
  },
47
47
  },
48
48
  ]);
@@ -54,7 +54,7 @@ describe('normalizeInitialLayout', () => {
54
54
  expect(result).toEqual([{ name: 'x', variants: { default: tree } }]);
55
55
  });
56
56
  it('throws if a preset has neither tree nor variants.default', () => {
57
- const bad = [{ name: 'broken', variants: { companion: { docked: leafNode, floats: [] } } }];
57
+ const bad = [{ name: 'broken', variants: { compact: { docked: leafNode, floats: [] } } }];
58
58
  expect(() => normalizeInitialLayout(bad)).toThrow(/must provide either 'tree' or 'variants.default'/);
59
59
  });
60
60
  it('when a preset has both tree and variants.default, variants.default wins', () => {
@@ -176,7 +176,7 @@ export interface LayoutTree {
176
176
  * manifest; users switch between them at runtime. The ergonomic `tree`
177
177
  * field is shorthand for `variants.default`; the normalizer canonicalizes
178
178
  * every preset into a variants-only shape on load. v1 always uses the
179
- * `default` variant; other variant keys (e.g. `companion`) are reserved
179
+ * `default` variant; other variant keys (e.g. `compact`) are reserved
180
180
  * for the rescoped DF10 selection policy and are persisted but inert.
181
181
  */
182
182
  export interface LayoutPreset {
@@ -11,6 +11,7 @@
11
11
  import { toastManager } from '../overlays/toast';
12
12
  import { sh3 } from '../sh3Runtime.svelte';
13
13
  import { makeSelectionApi } from '../actions/selection.svelte';
14
+ import HomeSection from '../sh3core-shard/HomeSection.svelte';
14
15
  import iconsUrl from '../assets/icons.svg';
15
16
 
16
17
  const layouts = $derived(getLayouts());
@@ -41,8 +42,7 @@
41
42
  </script>
42
43
 
43
44
  {#if layouts.length > 0}
44
- <section class="saved-layouts-section">
45
- <h2 class="saved-layouts-heading">Saved Layouts</h2>
45
+ <HomeSection title="Saved Layouts" persistKey="layouts">
46
46
  <div class="saved-layouts-grid">
47
47
  {#each layouts as layout (layout.id)}
48
48
  <button
@@ -64,23 +64,10 @@
64
64
  </button>
65
65
  {/each}
66
66
  </div>
67
- </section>
67
+ </HomeSection>
68
68
  {/if}
69
69
 
70
70
  <style>
71
- .saved-layouts-section {
72
- width: 100%;
73
- max-width: 720px;
74
- margin-bottom: 28px;
75
- }
76
- .saved-layouts-heading {
77
- font-size: 13px;
78
- font-weight: 600;
79
- text-transform: uppercase;
80
- letter-spacing: 0.06em;
81
- color: var(--sh3-fg-subtle);
82
- margin: 0 0 12px;
83
- }
84
71
  .saved-layouts-grid {
85
72
  display: grid;
86
73
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
@@ -58,9 +58,8 @@
58
58
  return;
59
59
  }
60
60
 
61
- const popupHandle = sh3.popup.show(
61
+ const modalHandle = sh3.modal.open(
62
62
  DocumentBrowser,
63
- { anchor: trigger },
64
63
  {
65
64
  mode,
66
65
  docs,
@@ -69,10 +68,11 @@
69
68
  },
70
69
  onCancel: () => {},
71
70
  },
71
+ { dismissOnBackdrop: true, boxStyle: 'max-width: min(800px, 95vw);' },
72
72
  );
73
73
 
74
- const origClose = popupHandle.close;
75
- popupHandle.close = () => {
74
+ const origClose = modalHandle.close;
75
+ modalHandle.close = () => {
76
76
  origClose();
77
77
  onOpenClosed();
78
78
  };
@@ -65,6 +65,7 @@
65
65
  <label class="sh3-picker__row">
66
66
  <input
67
67
  type="checkbox"
68
+ class="sh3-base-check"
68
69
  checked={value.includes(item.id)}
69
70
  {disabled}
70
71
  onchange={() => toggleId(item.id)}