@formicoidea/labre-core-database 2.1.1 → 2.4.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.
- package/dist/data-source-picker.js +8 -4
- package/dist/new-source-entry.d.ts +19 -1
- package/dist/new-source-entry.js +94 -2
- package/dist/translations.d.ts +3 -4
- package/dist/translations.js +12 -12
- package/dist/view-bar/add-view-menu.d.ts +44 -26
- package/dist/view-bar/add-view-menu.js +167 -94
- package/dist/view-bar/add-view-on-source.d.ts +5 -1
- package/dist/view-bar/add-view-on-source.js +10 -3
- package/dist/view-bar/add-view-sources.d.ts +19 -7
- package/dist/view-bar/add-view-sources.js +15 -2
- package/dist/view-settings/source-entry.d.ts +16 -6
- package/dist/view-settings/source-entry.js +67 -12
- package/dist/view-transfer/change-source.d.ts +16 -8
- package/dist/view-transfer/change-source.js +36 -11
- package/dist/view-transfer/import-view.d.ts +6 -4
- package/dist/view-transfer/import-view.js +24 -8
- package/dist/view-transfer/remap-view.d.ts +8 -3
- package/dist/view-transfer/remap-view.js +6 -2
- package/dist/workspace-sources.d.ts +48 -0
- package/dist/workspace-sources.js +60 -0
- package/package.json +2 -2
|
@@ -1,33 +1,54 @@
|
|
|
1
|
-
import { HostedDataSourceBase } from '@formicoidea/labre-core/blocks/database';
|
|
1
|
+
import { HostedDataSourceBase, viewDatabaseId, } from '@formicoidea/labre-core/blocks/database';
|
|
2
2
|
import { menu } from '@formicoidea/labre-core/components/context-menu';
|
|
3
|
-
import { DataSourcePickerProvider, translateKey, } from '@formicoidea/labre-core/shared/services';
|
|
3
|
+
import { DataSourcePickerProvider, DOC_UNTITLED, translateKey, } from '@formicoidea/labre-core/shared/services';
|
|
4
4
|
import { viewDefaultName, } from '@formicoidea/labre-core/data-view';
|
|
5
5
|
import { ImportIcon } from '@blocksuite/icons/lit';
|
|
6
6
|
import { html } from 'lit';
|
|
7
|
-
import {
|
|
7
|
+
import { DATABASE_ADD_VIEW_IMPORT, DATABASE_ADD_VIEW_UNTITLED_SOURCE, } from '../translations.js';
|
|
8
8
|
import { canImportView, requestViewImport, } from '../view-transfer/import-view.js';
|
|
9
|
-
import { named,
|
|
9
|
+
import { named, sourceSearch, typedSourceEntry } from '../new-source-entry.js';
|
|
10
|
+
import { crossDatabaseViews, databaseLabel, workspaceSources, } from '../workspace-sources.js';
|
|
10
11
|
import { addViewOnSource } from './add-view-on-source.js';
|
|
11
12
|
import { existingSources } from './add-view-sources.js';
|
|
12
13
|
/**
|
|
13
14
|
* The host's data-source picker (`DataSourcePickerProvider`, B12) as "+ view"
|
|
14
15
|
* reads it, on the database the block shows (`externalSourceId`, the id the
|
|
15
|
-
* picker lists it under): its sources
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* picker lists it under): its sources, and its `createSource`. "+ view"
|
|
17
|
+
* lists them inline rather than popping the picker over its own menu: one
|
|
18
|
+
* menu, the presets under each source. `sources` reads the host's list as a
|
|
19
|
+
* signal, asked for once per adapter: a host may fill it after its first
|
|
20
|
+
* `list()` (labre recette of 2.3.2), and the open menu redraws then. With
|
|
21
|
+
* `crossDatabaseViews`, `otherSources` reads the other databases' sources
|
|
22
|
+
* from the same list (`workspaceSources`: by name, labelled).
|
|
18
23
|
*/
|
|
19
24
|
export function addViewSourcePicker(picker) {
|
|
20
25
|
const databaseOf = (dataSource) => dataSource.hostModel.props.externalSourceId;
|
|
21
26
|
const createSource = picker.createSource;
|
|
27
|
+
let list;
|
|
28
|
+
const databases = () => {
|
|
29
|
+
list ??= picker.list();
|
|
30
|
+
return list.value;
|
|
31
|
+
};
|
|
22
32
|
return {
|
|
23
|
-
|
|
33
|
+
sources: dataSource => {
|
|
24
34
|
const databaseId = databaseOf(dataSource);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
.peek()
|
|
28
|
-
.find(candidate => candidate.id === databaseId);
|
|
29
|
-
return database?.sources.map(source => source.id) ?? [];
|
|
35
|
+
return (databases().find(candidate => candidate.id === databaseId)?.sources ??
|
|
36
|
+
[]);
|
|
30
37
|
},
|
|
38
|
+
otherSources: crossDatabaseViews(picker)
|
|
39
|
+
? dataSource => workspaceSources(databases(), databaseOf(dataSource), true).flatMap(source => source.databaseId === undefined
|
|
40
|
+
? []
|
|
41
|
+
: [
|
|
42
|
+
{
|
|
43
|
+
sourceId: source.sourceId,
|
|
44
|
+
// Unloaded: its database and id stand for its schema.
|
|
45
|
+
schemaId: `${source.databaseId}:${source.sourceId}`,
|
|
46
|
+
title: source.title,
|
|
47
|
+
databaseId: source.databaseId,
|
|
48
|
+
databaseTitle: source.databaseTitle,
|
|
49
|
+
},
|
|
50
|
+
])
|
|
51
|
+
: undefined,
|
|
31
52
|
createSource: createSource
|
|
32
53
|
? async (dataSource, sourceName) => {
|
|
33
54
|
const databaseId = databaseOf(dataSource);
|
|
@@ -45,113 +66,165 @@ export function addViewMenuShape(sources, canCreateSource, canImport = false) {
|
|
|
45
66
|
return { kind: 'presets', source: sources[0] };
|
|
46
67
|
}
|
|
47
68
|
return {
|
|
48
|
-
kind: '
|
|
49
|
-
|
|
50
|
-
|
|
69
|
+
kind: 'list',
|
|
70
|
+
sources,
|
|
71
|
+
create: canCreateSource,
|
|
51
72
|
importView: canImport,
|
|
52
73
|
};
|
|
53
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* The sources "+ view" lists now; read in a `menu.dynamic`, it follows the
|
|
77
|
+
* host's list. This database's first (the views' and the host's), then,
|
|
78
|
+
* under `crossDatabaseViews`, the other databases' (ADR 0035 amendment of
|
|
79
|
+
* 2026-10-30). A view reading another database's source names none of this
|
|
80
|
+
* database's.
|
|
81
|
+
*/
|
|
82
|
+
function readSources(dataSource, sourcePicker) {
|
|
83
|
+
const home = dataSource.hostModel.props.externalSourceId;
|
|
84
|
+
const own = existingSources({
|
|
85
|
+
viewSourceIds: dataSource.viewDataList$
|
|
86
|
+
.peek()
|
|
87
|
+
.filter(view => {
|
|
88
|
+
const databaseId = viewDatabaseId(view);
|
|
89
|
+
return databaseId === undefined || databaseId === home;
|
|
90
|
+
})
|
|
91
|
+
.map(view => view.sourceId),
|
|
92
|
+
resolve: sourceId => {
|
|
93
|
+
const schema = dataSource.sourceOf(sourceId)?.schema;
|
|
94
|
+
return schema
|
|
95
|
+
? { schemaId: schema.id, title: schema.props.title.toString() }
|
|
96
|
+
: null;
|
|
97
|
+
},
|
|
98
|
+
listed: sourcePicker?.sources?.(dataSource),
|
|
99
|
+
});
|
|
100
|
+
return [...own, ...(sourcePicker?.otherSources?.(dataSource) ?? [])];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* What both the items and the search field of "+ view" are drawn from. The
|
|
104
|
+
* shape is decided at the opening, on the sources known then: a host list
|
|
105
|
+
* still on its way leaves the views' sources, and with a way to create or
|
|
106
|
+
* import a source the list shape applies anyway.
|
|
107
|
+
*/
|
|
108
|
+
function addViewPlan(context, sourcePicker) {
|
|
109
|
+
const { dataSource } = context;
|
|
110
|
+
if (!(dataSource instanceof HostedDataSourceBase))
|
|
111
|
+
return;
|
|
112
|
+
if (!dataSource.resolvesSources)
|
|
113
|
+
return;
|
|
114
|
+
const sources = readSources(dataSource, sourcePicker);
|
|
115
|
+
const createSource = sourcePicker?.createSource?.bind(sourcePicker);
|
|
116
|
+
const hostPicker = context.std?.getOptional(DataSourcePickerProvider);
|
|
117
|
+
const shape = addViewMenuShape(sources, createSource !== undefined, canImportView(hostPicker, dataSource));
|
|
118
|
+
return { dataSource, createSource, hostPicker, shape };
|
|
119
|
+
}
|
|
54
120
|
/**
|
|
55
121
|
* The "+ view" menu of a database whose views read named sources (ADR 0035
|
|
56
|
-
* §1, §7, B11; labre ADR-0046 §5
|
|
57
|
-
* entries
|
|
122
|
+
* §1, §7, B11; labre ADR-0046 §5). One source list with the view settings'
|
|
123
|
+
* "Source" (ADR 0035 amendment of 2026-10-30, superseding the three entries
|
|
124
|
+
* of labre PRD REQ-DB-7):
|
|
58
125
|
*
|
|
59
|
-
* 1.
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* are the menu itself, as in 0.48.
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* 3. "
|
|
67
|
-
* picker's `
|
|
68
|
-
*
|
|
69
|
-
*
|
|
126
|
+
* 1. The search field, shown from the start (`searchPlaceholder`).
|
|
127
|
+
* 2. Each source of this database (`existingSources`), a sub-menu of the
|
|
128
|
+
* creatable presets. With one source and nothing to create or import,
|
|
129
|
+
* the presets are the menu itself, as in 0.48. Under a host with
|
|
130
|
+
* `crossDatabaseViews`, then each source of the other databases, by
|
|
131
|
+
* name, labelled with its database; a view added there stores it
|
|
132
|
+
* (`databaseId`, ADR 0035 amendment of 2026-10-30).
|
|
133
|
+
* 3. "Create source “typed”" (`typedSourceEntry`): creates the typed name
|
|
134
|
+
* through the picker's `createSource`, then adds a table on it. Absent
|
|
135
|
+
* without `createSource`: the host's kill switch on creating sources
|
|
136
|
+
* (labre ADR-0046 §10).
|
|
137
|
+
* 4. Under a divider, "Import a view from another database" (labre
|
|
138
|
+
* REQ-DB-2): hands the picker's `importView` a request whose `add` copies
|
|
139
|
+
* the chosen view onto the current view's source
|
|
140
|
+
* (`view-transfer/import-view.ts`, ADR 0035 amendment of 2026-10-14).
|
|
141
|
+
* Absent without that verb.
|
|
70
142
|
*
|
|
71
143
|
* A data source that does not resolve sources (an inline database, a 0.48
|
|
72
144
|
* host source) has one implicit source: the bar keeps its presets list.
|
|
73
|
-
|
|
74
145
|
*/
|
|
75
146
|
export function databaseAddViewMenu(picker) {
|
|
76
147
|
return {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (!(dataSource instanceof HostedDataSourceBase))
|
|
148
|
+
searchPlaceholder: context => {
|
|
149
|
+
if (addViewPlan(context, picker(context))?.shape.kind !== 'list') {
|
|
80
150
|
return;
|
|
81
|
-
|
|
151
|
+
}
|
|
152
|
+
return sourceSearch(context.std)?.placeholder;
|
|
153
|
+
},
|
|
154
|
+
items: context => {
|
|
155
|
+
const sourcePicker = picker(context);
|
|
156
|
+
const plan = addViewPlan(context, sourcePicker);
|
|
157
|
+
if (!plan)
|
|
82
158
|
return;
|
|
159
|
+
const { dataSource, createSource, hostPicker, shape } = plan;
|
|
83
160
|
const wording = (w) => context.std ? translateKey(context.std, ...w) : w[1];
|
|
84
|
-
const sourcePicker = picker(context);
|
|
85
|
-
const sources = existingSources({
|
|
86
|
-
viewSourceIds: dataSource.viewDataList$
|
|
87
|
-
.peek()
|
|
88
|
-
.map(view => view.sourceId),
|
|
89
|
-
resolve: sourceId => {
|
|
90
|
-
const schema = dataSource.sourceOf(sourceId)?.schema;
|
|
91
|
-
return schema
|
|
92
|
-
? { schemaId: schema.id, title: schema.props.title.toString() }
|
|
93
|
-
: null;
|
|
94
|
-
},
|
|
95
|
-
extraSourceIds: sourcePicker?.extraSourceIds?.(dataSource),
|
|
96
|
-
});
|
|
97
161
|
const presetsOn = (source) => dataSource.viewMetas.map(meta => menu.action({
|
|
98
162
|
name: viewDefaultName(meta, context.std),
|
|
99
163
|
testId: 'database-add-view-preset',
|
|
100
164
|
prefix: html `<uni-lit .uni=${meta.renderer.icon}></uni-lit>`,
|
|
101
165
|
select: () => {
|
|
102
|
-
|
|
166
|
+
if (source?.databaseId === undefined) {
|
|
167
|
+
addViewOnSource(context, dataSource, meta.type, source?.sourceId);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
addViewOnSource(context, dataSource, meta.type, source.sourceId, 'existing', source.databaseId);
|
|
103
171
|
},
|
|
104
172
|
}));
|
|
105
|
-
const createSource = sourcePicker?.createSource?.bind(sourcePicker);
|
|
106
|
-
const hostPicker = context.std?.getOptional(DataSourcePickerProvider);
|
|
107
|
-
const shape = addViewMenuShape(sources, createSource !== undefined, canImportView(hostPicker, dataSource));
|
|
108
173
|
if (shape.kind === 'presets') {
|
|
109
174
|
return presetsOn(shape.source);
|
|
110
175
|
}
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
176
|
+
const create = shape.create && createSource
|
|
177
|
+
? (sourceName) => {
|
|
178
|
+
createSource(dataSource, ...named(sourceName))
|
|
179
|
+
.then(sourceId => {
|
|
180
|
+
// The source arrived after a round trip: the page may
|
|
181
|
+
// have turned read-only meanwhile.
|
|
182
|
+
if (sourceId === undefined || dataSource.readonly$.peek()) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
addViewOnSource(context, dataSource, 'table', sourceId, 'new');
|
|
186
|
+
})
|
|
187
|
+
.catch(error => {
|
|
188
|
+
console.error(error);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
: undefined;
|
|
192
|
+
const items = [
|
|
193
|
+
// Read while drawing, so a host list that arrives with the menu
|
|
194
|
+
// open shows up (labre recette of 2.3.2).
|
|
195
|
+
menu.dynamic(() => {
|
|
196
|
+
const sources = readSources(dataSource, sourcePicker);
|
|
197
|
+
const entries = sources.map(source => menu.subMenu({
|
|
198
|
+
name: source.title || wording(DATABASE_ADD_VIEW_UNTITLED_SOURCE),
|
|
199
|
+
postfix: source.sourceId === undefined
|
|
200
|
+
? undefined
|
|
201
|
+
: databaseLabel({
|
|
202
|
+
sourceId: source.sourceId,
|
|
203
|
+
title: source.title,
|
|
204
|
+
databaseId: source.databaseId,
|
|
205
|
+
databaseTitle: source.databaseTitle,
|
|
206
|
+
}, wording(DOC_UNTITLED)),
|
|
207
|
+
testId: `database-add-view-source-${source.sourceId}`,
|
|
208
|
+
options: { items: presetsOn(source) },
|
|
209
|
+
}));
|
|
210
|
+
if (create) {
|
|
211
|
+
entries.push(typedSourceEntry(context.std, sourcePicker?.sourceName, sources.map(source => source.title), { testId: 'database-add-view-new-source', create }));
|
|
212
|
+
}
|
|
213
|
+
return entries;
|
|
214
|
+
}),
|
|
215
|
+
];
|
|
147
216
|
if (shape.importView) {
|
|
148
|
-
items.push(menu.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
217
|
+
items.push(menu.group({
|
|
218
|
+
items: [
|
|
219
|
+
menu.action({
|
|
220
|
+
name: wording(DATABASE_ADD_VIEW_IMPORT),
|
|
221
|
+
prefix: ImportIcon(),
|
|
222
|
+
testId: 'database-add-view-import',
|
|
223
|
+
select: () => {
|
|
224
|
+
requestViewImport(hostPicker, dataSource);
|
|
225
|
+
},
|
|
226
|
+
}),
|
|
227
|
+
],
|
|
155
228
|
}));
|
|
156
229
|
}
|
|
157
230
|
return items;
|
|
@@ -13,5 +13,9 @@ import type { AddViewMenuContext } from '@formicoidea/labre-core/data-view';
|
|
|
13
13
|
* own source current, and when that is another schema the default data is
|
|
14
14
|
* derived again from it. All three writes are one gesture: the add captures
|
|
15
15
|
* the undo step, the two updates land in it.
|
|
16
|
+
*
|
|
17
|
+
* `databaseId` names the database of a source of ANOTHER database than the
|
|
18
|
+
* block's (ADR 0035 amendment of 2026-10-30), written with `sourceId`;
|
|
19
|
+
* absent, the view reads the block's database and stores no such key.
|
|
16
20
|
*/
|
|
17
|
-
export declare function addViewOnSource(context: AddViewMenuContext, dataSource: HostedDataSourceBase, type: string, sourceId: string | undefined, added?: 'existing' | 'new'): string;
|
|
21
|
+
export declare function addViewOnSource(context: AddViewMenuContext, dataSource: HostedDataSourceBase, type: string, sourceId: string | undefined, added?: 'existing' | 'new', databaseId?: string): string;
|
|
@@ -11,13 +11,20 @@
|
|
|
11
11
|
* own source current, and when that is another schema the default data is
|
|
12
12
|
* derived again from it. All three writes are one gesture: the add captures
|
|
13
13
|
* the undo step, the two updates land in it.
|
|
14
|
+
*
|
|
15
|
+
* `databaseId` names the database of a source of ANOTHER database than the
|
|
16
|
+
* block's (ADR 0035 amendment of 2026-10-30), written with `sourceId`;
|
|
17
|
+
* absent, the view reads the block's database and stores no such key.
|
|
14
18
|
*/
|
|
15
|
-
export function addViewOnSource(context, dataSource, type, sourceId, added = 'existing') {
|
|
19
|
+
export function addViewOnSource(context, dataSource, type, sourceId, added = 'existing', databaseId) {
|
|
16
20
|
const schemaBefore = dataSource.schema$.peek()?.id;
|
|
17
21
|
const id = context.addView(type, added);
|
|
18
22
|
// Never an own `sourceId: undefined` key: absent is the stored reading.
|
|
19
|
-
const source =
|
|
20
|
-
|
|
23
|
+
const source = {
|
|
24
|
+
...(sourceId === undefined ? {} : { sourceId }),
|
|
25
|
+
...(databaseId === undefined ? {} : { databaseId }),
|
|
26
|
+
};
|
|
27
|
+
if (sourceId !== undefined || databaseId !== undefined) {
|
|
21
28
|
dataSource.viewDataUpdate(id, () => source);
|
|
22
29
|
}
|
|
23
30
|
if (dataSource.schema$.peek()?.id === schemaBefore) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The sources "+ view" offers (ADR 0035 §1, §9c, B11;
|
|
3
|
-
*
|
|
4
|
-
* a view from another database").
|
|
2
|
+
* The sources "+ view" offers (ADR 0035 §1, §9c, B11; one source list with a
|
|
3
|
+
* view's settings › "Source", amendment of 2026-10-30).
|
|
5
4
|
*
|
|
6
5
|
* Pure, so the list is held by a unit spec without a DOM. "Existing" means
|
|
7
6
|
* the sources the block's views already read, in the order of the views,
|
|
@@ -12,9 +11,12 @@
|
|
|
12
11
|
* view added there names its source. A view whose source does not resolve is
|
|
13
12
|
* skipped: nothing can be added on a source that is not there.
|
|
14
13
|
*
|
|
15
|
-
* `
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* `listed` is the data-source picker's (B12) list of this database's
|
|
15
|
+
* sources, the one the view settings show: with it, those come first, in the
|
|
16
|
+
* picker's order and under its titles, whether their schema is loaded or
|
|
17
|
+
* not (labre recette of 2.3.1: a source no view reads does not resolve until
|
|
18
|
+
* a view reads it, and was dropped), then the sources views read that the
|
|
19
|
+
* picker does not list.
|
|
18
20
|
*/
|
|
19
21
|
export interface AddViewSource {
|
|
20
22
|
/** What the new view stores as its `sourceId`; `undefined` stores none. */
|
|
@@ -23,6 +25,13 @@ export interface AddViewSource {
|
|
|
23
25
|
schemaId: string;
|
|
24
26
|
/** The source's name as its schema block's title holds it; may be empty. */
|
|
25
27
|
title: string;
|
|
28
|
+
/**
|
|
29
|
+
* A source of ANOTHER database (ADR 0035 amendment of 2026-10-30, under
|
|
30
|
+
* `crossDatabaseViews`): what the new view stores as its `databaseId`,
|
|
31
|
+
* and the title its entry is labelled with. Absent: the block's database.
|
|
32
|
+
*/
|
|
33
|
+
databaseId?: string;
|
|
34
|
+
databaseTitle?: string;
|
|
26
35
|
}
|
|
27
36
|
export interface AddViewSourceReader {
|
|
28
37
|
/** Each stored view's `sourceId`, in the order of the views. */
|
|
@@ -32,6 +41,9 @@ export interface AddViewSourceReader {
|
|
|
32
41
|
schemaId: string;
|
|
33
42
|
title: string;
|
|
34
43
|
} | null;
|
|
35
|
-
|
|
44
|
+
listed?: readonly {
|
|
45
|
+
id: string;
|
|
46
|
+
title: string;
|
|
47
|
+
}[];
|
|
36
48
|
}
|
|
37
49
|
export declare function existingSources(reader: AddViewSourceReader): AddViewSource[];
|
|
@@ -18,6 +18,19 @@ export function existingSources(reader) {
|
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
reader.viewSourceIds.forEach(add);
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const fromViews = [...bySchema.values()];
|
|
22
|
+
if (!reader.listed)
|
|
23
|
+
return fromViews;
|
|
24
|
+
const listed = reader.listed.map(source => ({
|
|
25
|
+
sourceId: source.id,
|
|
26
|
+
// Unloaded, its id stands for its schema: nothing else can match it.
|
|
27
|
+
schemaId: reader.resolve(source.id)?.schemaId ?? source.id,
|
|
28
|
+
title: source.title,
|
|
29
|
+
}));
|
|
30
|
+
const ids = new Set(listed.map(source => source.sourceId));
|
|
31
|
+
const schemas = new Set(listed.map(source => source.schemaId));
|
|
32
|
+
return [
|
|
33
|
+
...listed,
|
|
34
|
+
...fromViews.filter(source => !ids.has(source.sourceId) && !schemas.has(source.schemaId)),
|
|
35
|
+
];
|
|
23
36
|
}
|
|
@@ -6,8 +6,8 @@ import type { BlockStdScope } from '@formicoidea/labre-core/std';
|
|
|
6
6
|
import type { ReadonlySignal } from '@preact/signals-core';
|
|
7
7
|
/**
|
|
8
8
|
* "Source" in a view's settings (ADR 0035 amendment of 2026-10-28): which
|
|
9
|
-
* source of its database the view reads, and the
|
|
10
|
-
* another
|
|
9
|
+
* source of its database the view reads, and the list to point it at
|
|
10
|
+
* another or at one created from its search (`createSource`). One
|
|
11
11
|
* predicate and one opener for the two places that offer it, the view
|
|
12
12
|
* settings menu (`databaseViewSettingsMenu`) and the full page's
|
|
13
13
|
* `database.view.source` command, so they cannot disagree.
|
|
@@ -36,10 +36,20 @@ export declare function changeSourceTarget(std: BlockStdScope, dataSource: DataS
|
|
|
36
36
|
/** The current source's title, or "Untitled source". */
|
|
37
37
|
export declare function currentSourceTitle(std: BlockStdScope, dataSource: HostedDataSourceBase): string;
|
|
38
38
|
/**
|
|
39
|
-
* Pop the
|
|
40
|
-
* the view settings (`reopen`); a pick points the view at it.
|
|
41
|
-
*
|
|
42
|
-
*
|
|
39
|
+
* Pop the list of this database's sources at `target`, its "back" reopening
|
|
40
|
+
* the view settings (`reopen`); a pick points the view at it. One source list
|
|
41
|
+
* with "+ view" (ADR 0035 amendment of 2026-10-30): the search field shown
|
|
42
|
+
* from the start, the view's current source checked (picking it again only
|
|
43
|
+
* closes), and "Create source “typed”" last, which creates the typed name
|
|
44
|
+
* through `createSource` and points the view at it. The search is the naming
|
|
45
|
+
* step: no "New source" sub-step here.
|
|
46
|
+
*
|
|
47
|
+
* Under a host with `crossDatabaseViews` (amendment of 2026-10-30, "a view
|
|
48
|
+
* may read a source of another database"), the list holds every database's
|
|
49
|
+
* sources (`workspaceSources`): this one's first, then the others by name,
|
|
50
|
+
* labelled with their database; the check matches database and source; a
|
|
51
|
+
* pick of another database's source stores it on the view. "Create source"
|
|
52
|
+
* still creates in this block's database.
|
|
43
53
|
*/
|
|
44
54
|
export declare function popChangeSourcePicker(std: BlockStdScope, target: PopupTarget, change: ChangeSourceTarget, reopen: () => void): MenuHandler;
|
|
45
55
|
/**
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { HostedDataSourceBase } from '@formicoidea/labre-core/blocks/database';
|
|
2
2
|
import { menu, popMenu, } from '@formicoidea/labre-core/components/context-menu';
|
|
3
|
-
import { DataSourcePickerProvider, translateKey, } from '@formicoidea/labre-core/shared/services';
|
|
3
|
+
import { DataSourcePickerProvider, DOC_UNTITLED, translateKey, } from '@formicoidea/labre-core/shared/services';
|
|
4
4
|
import { ArrowRightSmallIcon, DatabaseTableViewIcon, } from '@blocksuite/icons/lit';
|
|
5
5
|
import { html } from 'lit';
|
|
6
|
-
import {
|
|
6
|
+
import { named, sourceSearch, typedSourceEntry } from '../new-source-entry.js';
|
|
7
7
|
import { DATABASE_ADD_VIEW_UNTITLED_SOURCE, PICKER_TITLE, VIEW_SETTINGS_SOURCE, } from '../translations.js';
|
|
8
8
|
import { changeViewSource } from '../view-transfer/change-source.js';
|
|
9
9
|
import { databaseIdOf } from '../view-transfer/import-view.js';
|
|
10
|
+
import { crossDatabaseViews, databaseLabel, inDatabase, isViewSource, workspaceSources, } from '../workspace-sources.js';
|
|
10
11
|
/**
|
|
11
12
|
* Whether `view` offers "Source" now: a database whose views name their
|
|
12
13
|
* source (`resolvesSources`), the picker naming it (`databaseIdOf`, the
|
|
@@ -35,23 +36,77 @@ export function currentSourceTitle(std, dataSource) {
|
|
|
35
36
|
translateKey(std, ...DATABASE_ADD_VIEW_UNTITLED_SOURCE));
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
|
-
* Pop the
|
|
39
|
-
* the view settings (`reopen`); a pick points the view at it.
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Pop the list of this database's sources at `target`, its "back" reopening
|
|
40
|
+
* the view settings (`reopen`); a pick points the view at it. One source list
|
|
41
|
+
* with "+ view" (ADR 0035 amendment of 2026-10-30): the search field shown
|
|
42
|
+
* from the start, the view's current source checked (picking it again only
|
|
43
|
+
* closes), and "Create source “typed”" last, which creates the typed name
|
|
44
|
+
* through `createSource` and points the view at it. The search is the naming
|
|
45
|
+
* step: no "New source" sub-step here.
|
|
46
|
+
*
|
|
47
|
+
* Under a host with `crossDatabaseViews` (amendment of 2026-10-30, "a view
|
|
48
|
+
* may read a source of another database"), the list holds every database's
|
|
49
|
+
* sources (`workspaceSources`): this one's first, then the others by name,
|
|
50
|
+
* labelled with their database; the check matches database and source; a
|
|
51
|
+
* pick of another database's source stores it on the view. "Create source"
|
|
52
|
+
* still creates in this block's database.
|
|
42
53
|
*/
|
|
43
54
|
export function popChangeSourcePicker(std, target, change, reopen) {
|
|
44
55
|
const { dataSource, databaseId, picker, viewId } = change;
|
|
56
|
+
const list = picker.list();
|
|
57
|
+
const createSource = picker.createSource;
|
|
58
|
+
const across = crossDatabaseViews(picker);
|
|
59
|
+
const stored = dataSource.viewDataGet(viewId);
|
|
60
|
+
const current = typeof stored?.sourceId === 'string' ? stored.sourceId : undefined;
|
|
61
|
+
// The block's own database reads as absent, as `WorkspaceSource` says it.
|
|
62
|
+
const currentDatabase = typeof stored?.databaseId === 'string' && stored.databaseId !== databaseId
|
|
63
|
+
? stored.databaseId
|
|
64
|
+
: undefined;
|
|
65
|
+
const untitled = translateKey(std, ...DATABASE_ADD_VIEW_UNTITLED_SOURCE);
|
|
66
|
+
const untitledDatabase = translateKey(std, ...DOC_UNTITLED);
|
|
45
67
|
return popMenu(target, {
|
|
46
68
|
options: {
|
|
47
69
|
title: { text: translateKey(std, ...PICKER_TITLE), onBack: reopen },
|
|
48
70
|
testId: 'data-source-picker',
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
71
|
+
search: sourceSearch(std),
|
|
72
|
+
items: [
|
|
73
|
+
menu.dynamic(() => {
|
|
74
|
+
const sources = workspaceSources(list.value, databaseId, across);
|
|
75
|
+
const items = sources.map(source => {
|
|
76
|
+
const selected = isViewSource(source, current, currentDatabase);
|
|
77
|
+
return menu.action({
|
|
78
|
+
name: source.title || untitled,
|
|
79
|
+
prefix: DatabaseTableViewIcon(),
|
|
80
|
+
postfix: databaseLabel(source, untitledDatabase, selected),
|
|
81
|
+
isSelected: selected,
|
|
82
|
+
testId: `data-source-picker-source-${source.sourceId}`,
|
|
83
|
+
select: () => {
|
|
84
|
+
if (selected)
|
|
85
|
+
return;
|
|
86
|
+
changeViewSource(dataSource, viewId, source.sourceId, 'existing', ...inDatabase(source.databaseId));
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
if (!createSource || std.store.readonly)
|
|
91
|
+
return items;
|
|
92
|
+
return [
|
|
93
|
+
...items,
|
|
94
|
+
typedSourceEntry(std, picker.sourceName, sources.map(source => source.title), {
|
|
95
|
+
testId: 'data-source-picker-new-source',
|
|
96
|
+
create: sourceName => {
|
|
97
|
+
createSource
|
|
98
|
+
.call(picker, databaseId, ...named(sourceName))
|
|
99
|
+
.then(created => {
|
|
100
|
+
if (created) {
|
|
101
|
+
changeViewSource(dataSource, viewId, created.id, 'new');
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
.catch(console.error);
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
];
|
|
108
|
+
}),
|
|
109
|
+
],
|
|
55
110
|
},
|
|
56
111
|
});
|
|
57
112
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type HostedDataSourceBase, type HostedSource } from '@formicoidea/labre-core/blocks/database';
|
|
2
2
|
import type { DataSourcePickerProperty } from '@formicoidea/labre-core/shared/services';
|
|
3
3
|
/**
|
|
4
4
|
* Pointing a view at another source of its database (ADR 0035 amendment of
|
|
@@ -10,15 +10,23 @@ import type { DataSourcePickerProperty } from '@formicoidea/labre-core/shared/se
|
|
|
10
10
|
* column, filter, sort and grouping under its new id, and one the target
|
|
11
11
|
* lacks leaves them. `openIn`, `colorRules` and any other key are carried
|
|
12
12
|
* as `remapView` carries them.
|
|
13
|
+
*
|
|
14
|
+
* A source of another database (ADR 0035 amendment of 2026-10-30, under a
|
|
15
|
+
* host with `crossDatabaseViews`) is named by its `databaseId` too, stored
|
|
16
|
+
* on the view; going back to the block's own database removes it, so a
|
|
17
|
+
* view reading its block's database stores exactly what it did in 2.3.
|
|
13
18
|
*/
|
|
14
19
|
/** A source's schema block as a correspondence reads it (`props.columns`). */
|
|
15
20
|
export declare function schemaProperties(schema: HostedSource['schema']): DataSourcePickerProperty[];
|
|
16
21
|
/**
|
|
17
|
-
* Point view `viewId` of `dataSource` at `sourceId
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
22
|
+
* Point view `viewId` of `dataSource` at `sourceId` of `databaseId` (absent
|
|
23
|
+
* or the block's own: the block's database), as one undo step, and report
|
|
24
|
+
* `DatabaseViewSourceChanged { source: added }` once. `false`, with nothing
|
|
25
|
+
* written, when the view already reads that source of that database, the
|
|
26
|
+
* page is read-only (re-read here: a source created by the host took a
|
|
27
|
+
* round trip), the view is drawn through a fallback preset (its stored data
|
|
28
|
+
* belongs to a preset this client does not have) or `resolveSource` knows
|
|
29
|
+
* no such source. The same `sourceId` in another database is another
|
|
30
|
+
* source.
|
|
23
31
|
*/
|
|
24
|
-
export declare function changeViewSource(dataSource: HostedDataSourceBase, viewId: string, sourceId: string, added: 'existing' | 'new'): boolean;
|
|
32
|
+
export declare function changeViewSource(dataSource: HostedDataSourceBase, viewId: string, sourceId: string, added: 'existing' | 'new', databaseId?: string): boolean;
|