@formicoidea/labre-core-database 2.3.3 → 2.4.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.
@@ -32,6 +32,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
32
32
  }
33
33
  return useValue ? value : void 0;
34
34
  };
35
+ import { POPUP_ROOT_ATTR } from '@formicoidea/labre-core/components/context-menu';
35
36
  import { SignalWatcher, WithDisposable } from '@formicoidea/labre-core/global/lit';
36
37
  import { BlockStdScope, ShadowlessElement, } from '@formicoidea/labre-core/std';
37
38
  import { css, html, nothing } from 'lit';
@@ -192,6 +193,10 @@ let DatabasePageHost = (() => {
192
193
  }
193
194
  connectedCallback() {
194
195
  super.connectedCallback();
196
+ // The popups of the page hang here, beside its viewport: the viewport
197
+ // masks and contains what it holds, so a menu hung in the editor was cut
198
+ // at its edges, under the host's sidebar (labre recette of 2.4).
199
+ this.setAttribute(POPUP_ROOT_ATTR, '');
195
200
  this.addEventListener('dragover', stopFileDrop, true);
196
201
  this.addEventListener('drop', stopFileDrop, true);
197
202
  this.holdSelection();
@@ -181,6 +181,8 @@ export function typedSourceEntry(std, naming, listed, entry) {
181
181
  if (naming && !namesReadFor(parent, naming))
182
182
  return;
183
183
  const verdict = naming ? verdictOf(naming, name) : 'ok';
184
+ // No "+" on a refused name (labre recette of 2.3.3): an icon made the
185
+ // status line read as a button.
184
186
  if (verdict !== 'ok') {
185
187
  return html `<div
186
188
  role="status"
@@ -198,7 +200,6 @@ export function typedSourceEntry(std, naming, listed, entry) {
198
200
  cursor: 'default',
199
201
  })}
200
202
  >
201
- ${PlusIcon()}
202
203
  <span style="color: var(--affine-error-color)"
203
204
  >${std
204
205
  ? translateKey(std, ...VERDICT_WORDING[verdict])
@@ -186,6 +186,8 @@ const DATABASE_EDITOR_WORDINGS = [
186
186
  SOURCE_NAME_OK,
187
187
  SOURCE_NAME_PLACEHOLDER,
188
188
  SOURCE_NAME_TAKEN,
189
+ SOURCE_SEARCH_CREATE,
190
+ SOURCE_SEARCH_PLACEHOLDER,
189
191
  VIEW_MENU_IMPORT,
190
192
  VIEW_SETTINGS_SOURCE,
191
193
  ];
@@ -14,6 +14,12 @@ export interface AddViewSourcePicker {
14
14
  id: string;
15
15
  title: string;
16
16
  }[];
17
+ /**
18
+ * The sources of the OTHER databases, in the order to list them, under a
19
+ * host with `crossDatabaseViews` (ADR 0035 amendment of 2026-10-30);
20
+ * absent or empty, "+ view" lists this database's alone, as in 2.3.
21
+ */
22
+ otherSources?(dataSource: HostedDataSourceBase): readonly AddViewSource[];
17
23
  /** Creates a source in this database; resolves to its id, or nothing. */
18
24
  createSource?(dataSource: HostedDataSourceBase, sourceName?: string): Promise<string | undefined>;
19
25
  /** How the host checks a typed name; absent, any name no listed source bears is created. */
@@ -26,7 +32,9 @@ export interface AddViewSourcePicker {
26
32
  * lists them inline rather than popping the picker over its own menu: one
27
33
  * menu, the presets under each source. `sources` reads the host's list as a
28
34
  * signal, asked for once per adapter: a host may fill it after its first
29
- * `list()` (labre recette of 2.3.2), and the open menu redraws then.
35
+ * `list()` (labre recette of 2.3.2), and the open menu redraws then. With
36
+ * `crossDatabaseViews`, `otherSources` reads the other databases' sources
37
+ * from the same list (`workspaceSources`: by name, labelled).
30
38
  */
31
39
  export declare function addViewSourcePicker(picker: DataSourcePickerService): AddViewSourcePicker;
32
40
  /**
@@ -54,7 +62,10 @@ export declare function addViewMenuShape(sources: AddViewSource[], canCreateSour
54
62
  * 1. The search field, shown from the start (`searchPlaceholder`).
55
63
  * 2. Each source of this database (`existingSources`), a sub-menu of the
56
64
  * creatable presets. With one source and nothing to create or import,
57
- * the presets are the menu itself, as in 0.48.
65
+ * the presets are the menu itself, as in 0.48. Under a host with
66
+ * `crossDatabaseViews`, then each source of the other databases, by
67
+ * name, labelled with its database; a view added there stores it
68
+ * (`databaseId`, ADR 0035 amendment of 2026-10-30).
58
69
  * 3. "Create source “typed”" (`typedSourceEntry`): creates the typed name
59
70
  * through the picker's `createSource`, then adds a table on it. Absent
60
71
  * without `createSource`: the host's kill switch on creating sources
@@ -1,12 +1,13 @@
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
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
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
  /**
@@ -16,18 +17,38 @@ import { existingSources } from './add-view-sources.js';
16
17
  * lists them inline rather than popping the picker over its own menu: one
17
18
  * menu, the presets under each source. `sources` reads the host's list as a
18
19
  * signal, asked for once per adapter: a host may fill it after its first
19
- * `list()` (labre recette of 2.3.2), and the open menu redraws then.
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).
20
23
  */
21
24
  export function addViewSourcePicker(picker) {
22
25
  const databaseOf = (dataSource) => dataSource.hostModel.props.externalSourceId;
23
26
  const createSource = picker.createSource;
24
27
  let list;
28
+ const databases = () => {
29
+ list ??= picker.list();
30
+ return list.value;
31
+ };
25
32
  return {
26
33
  sources: dataSource => {
27
34
  const databaseId = databaseOf(dataSource);
28
- list ??= picker.list();
29
- return (list.value.find(candidate => candidate.id === databaseId)?.sources ?? []);
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);
@@ -51,11 +72,22 @@ export function addViewMenuShape(sources, canCreateSource, canImport = false) {
51
72
  importView: canImport,
52
73
  };
53
74
  }
54
- /** The sources "+ view" lists now; read in a `menu.dynamic`, it follows the host's list. */
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
+ */
55
82
  function readSources(dataSource, sourcePicker) {
56
- return existingSources({
83
+ const home = dataSource.hostModel.props.externalSourceId;
84
+ const own = existingSources({
57
85
  viewSourceIds: dataSource.viewDataList$
58
86
  .peek()
87
+ .filter(view => {
88
+ const databaseId = viewDatabaseId(view);
89
+ return databaseId === undefined || databaseId === home;
90
+ })
59
91
  .map(view => view.sourceId),
60
92
  resolve: sourceId => {
61
93
  const schema = dataSource.sourceOf(sourceId)?.schema;
@@ -65,6 +97,7 @@ function readSources(dataSource, sourcePicker) {
65
97
  },
66
98
  listed: sourcePicker?.sources?.(dataSource),
67
99
  });
100
+ return [...own, ...(sourcePicker?.otherSources?.(dataSource) ?? [])];
68
101
  }
69
102
  /**
70
103
  * What both the items and the search field of "+ view" are drawn from. The
@@ -93,7 +126,10 @@ function addViewPlan(context, sourcePicker) {
93
126
  * 1. The search field, shown from the start (`searchPlaceholder`).
94
127
  * 2. Each source of this database (`existingSources`), a sub-menu of the
95
128
  * creatable presets. With one source and nothing to create or import,
96
- * the presets are the menu itself, as in 0.48.
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).
97
133
  * 3. "Create source “typed”" (`typedSourceEntry`): creates the typed name
98
134
  * through the picker's `createSource`, then adds a table on it. Absent
99
135
  * without `createSource`: the host's kill switch on creating sources
@@ -127,7 +163,11 @@ export function databaseAddViewMenu(picker) {
127
163
  testId: 'database-add-view-preset',
128
164
  prefix: html `<uni-lit .uni=${meta.renderer.icon}></uni-lit>`,
129
165
  select: () => {
130
- addViewOnSource(context, dataSource, meta.type, source?.sourceId);
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);
131
171
  },
132
172
  }));
133
173
  if (shape.kind === 'presets') {
@@ -156,6 +196,14 @@ export function databaseAddViewMenu(picker) {
156
196
  const sources = readSources(dataSource, sourcePicker);
157
197
  const entries = sources.map(source => menu.subMenu({
158
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)),
159
207
  testId: `database-add-view-source-${source.sourceId}`,
160
208
  options: { items: presetsOn(source) },
161
209
  }));
@@ -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 = sourceId === undefined ? {} : { sourceId };
20
- if (sourceId !== undefined) {
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) {
@@ -25,6 +25,13 @@ export interface AddViewSource {
25
25
  schemaId: string;
26
26
  /** The source's name as its schema block's title holds it; may be empty. */
27
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;
28
35
  }
29
36
  export interface AddViewSourceReader {
30
37
  /** Each stored view's `sourceId`, in the order of the views. */
@@ -43,6 +43,13 @@ export declare function currentSourceTitle(std: BlockStdScope, dataSource: Hoste
43
43
  * closes), and "Create source “typed”" last, which creates the typed name
44
44
  * through `createSource` and points the view at it. The search is the naming
45
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.
46
53
  */
47
54
  export declare function popChangeSourcePicker(std: BlockStdScope, target: PopupTarget, change: ChangeSourceTarget, reopen: () => void): MenuHandler;
48
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
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
@@ -42,12 +43,27 @@ export function currentSourceTitle(std, dataSource) {
42
43
  * closes), and "Create source “typed”" last, which creates the typed name
43
44
  * through `createSource` and points the view at it. The search is the naming
44
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.
45
53
  */
46
54
  export function popChangeSourcePicker(std, target, change, reopen) {
47
55
  const { dataSource, databaseId, picker, viewId } = change;
48
56
  const list = picker.list();
49
57
  const createSource = picker.createSource;
50
- const current = dataSource.viewDataGet(viewId)?.sourceId;
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);
51
67
  return popMenu(target, {
52
68
  options: {
53
69
  title: { text: translateKey(std, ...PICKER_TITLE), onBack: reopen },
@@ -55,20 +71,22 @@ export function popChangeSourcePicker(std, target, change, reopen) {
55
71
  search: sourceSearch(std),
56
72
  items: [
57
73
  menu.dynamic(() => {
58
- const sources = list.value.find(database => database.id === databaseId)?.sources ??
59
- [];
60
- const items = sources.map(source => menu.action({
61
- name: source.title ||
62
- translateKey(std, ...DATABASE_ADD_VIEW_UNTITLED_SOURCE),
63
- prefix: DatabaseTableViewIcon(),
64
- isSelected: source.id === current,
65
- testId: `data-source-picker-source-${source.id}`,
66
- select: () => {
67
- if (source.id === current)
68
- return;
69
- changeViewSource(dataSource, viewId, source.id, 'existing');
70
- },
71
- }));
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
+ });
72
90
  if (!createSource || std.store.readonly)
73
91
  return items;
74
92
  return [
@@ -1,4 +1,4 @@
1
- import type { HostedDataSourceBase, HostedSource } from '@formicoidea/labre-core/blocks/database';
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`, as one undo step, and
18
- * report `DatabaseViewSourceChanged { source: added }` once. `false`, with
19
- * nothing written, when the view already reads that source, the page is
20
- * read-only (re-read here: a source created by the host took a round trip),
21
- * the view is drawn through a fallback preset (its stored data belongs to a
22
- * preset this client does not have) or `resolveSource` knows no such source.
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;
@@ -1,3 +1,4 @@
1
+ import { viewDatabaseId, } from '@formicoidea/labre-core/blocks/database';
1
2
  import { DataViewEventTraceKey, } from '@formicoidea/labre-core/data-view';
2
3
  import { propertyOptions, sourceProperties } from './import-view.js';
3
4
  import { defaultMapping, remapView } from './remap-view.js';
@@ -11,6 +12,11 @@ import { defaultMapping, remapView } from './remap-view.js';
11
12
  * column, filter, sort and grouping under its new id, and one the target
12
13
  * lacks leaves them. `openIn`, `colorRules` and any other key are carried
13
14
  * as `remapView` carries them.
15
+ *
16
+ * A source of another database (ADR 0035 amendment of 2026-10-30, under a
17
+ * host with `crossDatabaseViews`) is named by its `databaseId` too, stored
18
+ * on the view; going back to the block's own database removes it, so a
19
+ * view reading its block's database stores exactly what it did in 2.3.
14
20
  */
15
21
  /** A source's schema block as a correspondence reads it (`props.columns`). */
16
22
  export function schemaProperties(schema) {
@@ -22,25 +28,36 @@ export function schemaProperties(schema) {
22
28
  }));
23
29
  }
24
30
  /** The keys `remapView` leaves to the caller: never cleared here. */
25
- const CALLER_KEYS = new Set(['id', 'name', 'sourceId']);
31
+ const CALLER_KEYS = new Set(['id', 'name', 'sourceId', 'databaseId']);
26
32
  /**
27
- * Point view `viewId` of `dataSource` at `sourceId`, as one undo step, and
28
- * report `DatabaseViewSourceChanged { source: added }` once. `false`, with
29
- * nothing written, when the view already reads that source, the page is
30
- * read-only (re-read here: a source created by the host took a round trip),
31
- * the view is drawn through a fallback preset (its stored data belongs to a
32
- * preset this client does not have) or `resolveSource` knows no such source.
33
+ * Point view `viewId` of `dataSource` at `sourceId` of `databaseId` (absent
34
+ * or the block's own: the block's database), as one undo step, and report
35
+ * `DatabaseViewSourceChanged { source: added }` once. `false`, with nothing
36
+ * written, when the view already reads that source of that database, the
37
+ * page is read-only (re-read here: a source created by the host took a
38
+ * round trip), the view is drawn through a fallback preset (its stored data
39
+ * belongs to a preset this client does not have) or `resolveSource` knows
40
+ * no such source. The same `sourceId` in another database is another
41
+ * source.
33
42
  */
34
- export function changeViewSource(dataSource, viewId, sourceId, added) {
43
+ export function changeViewSource(dataSource, viewId, sourceId, added, databaseId) {
35
44
  const view = dataSource.viewDataGet(viewId);
36
- if (!view || view.sourceId === sourceId)
45
+ if (!view)
37
46
  return false;
47
+ const home = dataSource.hostModel.props.externalSourceId;
48
+ // `undefined`: the block's database, however the caller named it.
49
+ const targetDatabase = databaseId === undefined || databaseId === home ? undefined : databaseId;
50
+ const storedDatabase = viewDatabaseId(view);
51
+ const fromDatabase = storedDatabase === home ? undefined : storedDatabase;
52
+ if (view.sourceId === sourceId && fromDatabase === targetDatabase) {
53
+ return false;
54
+ }
38
55
  if (dataSource.readonly$.peek())
39
56
  return false;
40
57
  if (dataSource.viewManager.viewGet(viewId)?.shownAsFallback$.peek()) {
41
58
  return false;
42
59
  }
43
- const target = dataSource.sourceOf(sourceId);
60
+ const target = dataSource.sourceOf(sourceId, targetDatabase);
44
61
  if (!target)
45
62
  return false;
46
63
  // The data source answers for the current view's source; another view's
@@ -48,7 +65,7 @@ export function changeViewSource(dataSource, viewId, sourceId, added) {
48
65
  const storedSource = typeof view.sourceId === 'string' ? view.sourceId : undefined;
49
66
  const fromSchema = viewId === dataSource.viewManager.currentViewId$.peek()
50
67
  ? null
51
- : dataSource.sourceOf(storedSource)?.schema;
68
+ : dataSource.sourceOf(storedSource, fromDatabase)?.schema;
52
69
  const from = fromSchema
53
70
  ? schemaProperties(fromSchema)
54
71
  : sourceProperties(dataSource);
@@ -62,11 +79,19 @@ export function changeViewSource(dataSource, viewId, sourceId, added) {
62
79
  if (!CALLER_KEYS.has(key) && !(key in data))
63
80
  cleared[key] = undefined;
64
81
  }
82
+ // Back home, the view's `databaseId` goes (an own `undefined`, as above);
83
+ // a view that never had one gets no key at all.
84
+ const database = targetDatabase !== undefined
85
+ ? { databaseId: targetDatabase }
86
+ : 'databaseId' in view
87
+ ? { databaseId: undefined }
88
+ : {};
65
89
  dataSource.hostModel.store.captureSync();
66
90
  dataSource.viewDataUpdate(viewId, () => ({
67
91
  ...cleared,
68
92
  ...data,
69
93
  sourceId,
94
+ ...database,
70
95
  }));
71
96
  dataSource.serviceGet(DataViewEventTraceKey)?.('DatabaseViewSourceChanged', {
72
97
  source: added,
@@ -18,11 +18,13 @@ export declare function databaseIdOf(dataSource: DataSource): string | undefined
18
18
  /** Whether the picker can import a view into this data source now. */
19
19
  export declare function canImportView(picker: DataSourcePickerService | null | undefined, dataSource: DataSource): boolean;
20
20
  /**
21
- * Add `imported` as a new view of `dataSource`, on `sourceId`, and show it;
22
- * its id, or `null` when nothing was added. Re-checks read-only (the host's
23
- * dialog took time) and refuses a layout this database does not add.
21
+ * Add `imported` as a new view of `dataSource`, on `sourceId` (of
22
+ * `databaseId`, a source of another database, ADR 0035 amendment of
23
+ * 2026-10-30), and show it; its id, or `null` when nothing was added.
24
+ * Re-checks read-only (the host's dialog took time) and refuses a layout
25
+ * this database does not add.
24
26
  */
25
- export declare function addImportedView(dataSource: DataSource, sourceId: string | undefined, imported: DataSourcePickerImportedView): string | null;
27
+ export declare function addImportedView(dataSource: DataSource, sourceId: string | undefined, imported: DataSourcePickerImportedView, databaseId?: string): string | null;
26
28
  /**
27
29
  * Ask the host to import a view into `dataSource` (the full page's "Import a
28
30
  * view", the "+ view" third entry). Nothing without the picker's verb, on a
@@ -1,4 +1,4 @@
1
- import { HostedDataSourceBase } from '@formicoidea/labre-core/blocks/database';
1
+ import { HostedDataSourceBase, viewDatabaseId, } from '@formicoidea/labre-core/blocks/database';
2
2
  import { DataViewEventTraceKey, } from '@formicoidea/labre-core/data-view';
3
3
  import { nanoid } from '@formicoidea/labre-core/store';
4
4
  import { remapView, viewTemplateData } from './remap-view.js';
@@ -45,11 +45,13 @@ export function canImportView(picker, dataSource) {
45
45
  databaseIdOf(dataSource) !== undefined);
46
46
  }
47
47
  /**
48
- * Add `imported` as a new view of `dataSource`, on `sourceId`, and show it;
49
- * its id, or `null` when nothing was added. Re-checks read-only (the host's
50
- * dialog took time) and refuses a layout this database does not add.
48
+ * Add `imported` as a new view of `dataSource`, on `sourceId` (of
49
+ * `databaseId`, a source of another database, ADR 0035 amendment of
50
+ * 2026-10-30), and show it; its id, or `null` when nothing was added.
51
+ * Re-checks read-only (the host's dialog took time) and refuses a layout
52
+ * this database does not add.
51
53
  */
52
- export function addImportedView(dataSource, sourceId, imported) {
54
+ export function addImportedView(dataSource, sourceId, imported, databaseId) {
53
55
  if (dataSource.readonly$.peek())
54
56
  return null;
55
57
  const mode = imported.view.mode;
@@ -69,6 +71,7 @@ export function addImportedView(dataSource, sourceId, imported) {
69
71
  name,
70
72
  mode,
71
73
  ...(sourceId === undefined ? {} : { sourceId }),
74
+ ...(databaseId === undefined ? {} : { databaseId }),
72
75
  });
73
76
  dataSource.viewManager.setCurrentView(id);
74
77
  dataSource.serviceGet(DataViewEventTraceKey)?.('DatabaseViewAdded', {
@@ -84,6 +87,17 @@ function currentSourceId(dataSource) {
84
87
  const sourceId = view?.sourceId;
85
88
  return typeof sourceId === 'string' ? sourceId : undefined;
86
89
  }
90
+ /**
91
+ * The current view's stored `databaseId` when it reads a source of another
92
+ * database than its block's (ADR 0035 amendment of 2026-10-30); absent,
93
+ * the block's.
94
+ */
95
+ function currentForeignDatabase(dataSource, home) {
96
+ const viewId = dataSource.viewManager.currentViewId$.peek();
97
+ const view = viewId ? dataSource.viewDataGet(viewId) : undefined;
98
+ const databaseId = viewDatabaseId(view);
99
+ return databaseId === home ? undefined : databaseId;
100
+ }
87
101
  /**
88
102
  * Ask the host to import a view into `dataSource` (the full page's "Import a
89
103
  * view", the "+ view" third entry). Nothing without the picker's verb, on a
@@ -97,12 +111,14 @@ export function requestViewImport(picker, dataSource) {
97
111
  if (dataSource.readonly$.peek())
98
112
  return;
99
113
  const sourceId = currentSourceId(dataSource);
114
+ // The copy reads the current view's source, in that view's database.
115
+ const foreign = currentForeignDatabase(dataSource, databaseId);
100
116
  const request = {
101
- databaseId,
117
+ databaseId: foreign ?? databaseId,
102
118
  ...(sourceId === undefined ? {} : { sourceId }),
103
119
  properties: sourceProperties(dataSource),
104
120
  layouts: dataSource.viewMetas.map(meta => meta.type),
105
- add: imported => addImportedView(dataSource, sourceId, imported),
121
+ add: imported => addImportedView(dataSource, sourceId, imported, foreign),
106
122
  };
107
123
  importView.call(picker, request);
108
124
  }
@@ -115,7 +131,7 @@ export function currentViewTemplate(dataSource) {
115
131
  return null;
116
132
  const sourceId = currentSourceId(dataSource);
117
133
  return {
118
- databaseId,
134
+ databaseId: currentForeignDatabase(dataSource, databaseId) ?? databaseId,
119
135
  ...(sourceId === undefined ? {} : { sourceId }),
120
136
  name: view.name,
121
137
  view: viewTemplateData(view),
@@ -15,7 +15,10 @@ export interface RemapDropped {
15
15
  colorRules: number;
16
16
  }
17
17
  export interface RemappedView {
18
- /** The view's data for this database, without `id`, `name` or `sourceId`. */
18
+ /**
19
+ * The view's data for this database, without `id`, `name`, `sourceId` or
20
+ * `databaseId`.
21
+ */
19
22
  data: Record<string, unknown>;
20
23
  dropped: RemapDropped;
21
24
  }
@@ -42,8 +45,10 @@ type Json = Record<string, unknown>;
42
45
  * but a rule that loses any condition is removed whole and counted: a
43
46
  * rule with fewer conditions would colour rows its author never meant;
44
47
  * its colour is the shared palette's and is kept as is;
45
- * - `id`, `name` and `sourceId` are left to the caller; any other key is
46
- * copied as is.
48
+ * - `id`, `name`, `sourceId` and `databaseId` (the database of a source of
49
+ * another database, ADR 0035 amendment of 2026-10-30) are left to the
50
+ * caller: a copy names the source it reads where it lands; any other key
51
+ * is copied as is.
47
52
  *
48
53
  * A mapping onto a property that `to` does not have counts as ignored.
49
54
  */
@@ -36,8 +36,10 @@ function isRecord(value) {
36
36
  * but a rule that loses any condition is removed whole and counted: a
37
37
  * rule with fewer conditions would colour rows its author never meant;
38
38
  * its colour is the shared palette's and is kept as is;
39
- * - `id`, `name` and `sourceId` are left to the caller; any other key is
40
- * copied as is.
39
+ * - `id`, `name`, `sourceId` and `databaseId` (the database of a source of
40
+ * another database, ADR 0035 amendment of 2026-10-30) are left to the
41
+ * caller: a copy names the source it reads where it lands; any other key
42
+ * is copied as is.
41
43
  *
42
44
  * A mapping onto a property that `to` does not have counts as ignored.
43
45
  */
@@ -46,6 +48,7 @@ export function remapView(view, from, to, mapping) {
46
48
  delete data.id;
47
49
  delete data.name;
48
50
  delete data.sourceId;
51
+ delete data.databaseId;
49
52
  const dropped = {
50
53
  filters: 0,
51
54
  sorts: 0,
@@ -252,6 +255,7 @@ export function viewTemplateData(view) {
252
255
  const data = plainCopy(view);
253
256
  delete data.id;
254
257
  delete data.sourceId;
258
+ delete data.databaseId;
255
259
  delete data.sort;
256
260
  if (isRecord(data.filter))
257
261
  data.filter = { ...data.filter, conditions: [] };
@@ -0,0 +1,48 @@
1
+ import type { DataSourcePickerDatabase, DataSourcePickerService } from '@formicoidea/labre-core/shared/services';
2
+ import { type TemplateResult } from 'lit';
3
+ /**
4
+ * One source list for the whole workspace (ADR 0035 amendment of
5
+ * 2026-10-30, labre « Base de données v3 »): under a host with
6
+ * `crossDatabaseViews`, a view's settings › "Source" and "+ view" list the
7
+ * sources of every database the picker lists, not only the block's. Pure,
8
+ * so the order is held by a unit spec without a DOM.
9
+ *
10
+ * - The block's own database first, in the host's order (as in 2.3), then
11
+ * the other databases' sources by name (accents and case folded, numbers
12
+ * in numeric order), a tie by database title then by id, so the order
13
+ * never depends on the host's list of databases.
14
+ * - A source of another database carries its database (`databaseId`,
15
+ * `databaseTitle`): the entry labels it, a pick stores it on the view.
16
+ * - Without `crossDatabaseViews` only the block's database is listed: the
17
+ * 2.3 list, whatever the picker returns.
18
+ */
19
+ export interface WorkspaceSource {
20
+ /** What a view stores as its `sourceId`. */
21
+ sourceId: string;
22
+ title: string;
23
+ /** Set for a source of ANOTHER database than the block's; absent, the block's. */
24
+ databaseId?: string;
25
+ /** That database's title, for the entry's label. */
26
+ databaseTitle?: string;
27
+ }
28
+ /** Whether the host lets a view read a source of another database. */
29
+ export declare function crossDatabaseViews(picker: Pick<DataSourcePickerService, 'crossDatabaseViews'> | null | undefined): boolean;
30
+ export declare function workspaceSources(databases: readonly DataSourcePickerDatabase[], homeDatabaseId: string | undefined, acrossDatabases: boolean): WorkspaceSource[];
31
+ /**
32
+ * A source's database as a trailing argument, only when it is another one:
33
+ * a call about the block's own database is made exactly as in 2.3.
34
+ */
35
+ export declare const inDatabase: (databaseId: string | undefined) => [] | [string];
36
+ /**
37
+ * Whether `source` is the one a view reads, by database AND source: the same
38
+ * `sourceId` in another database is another source. `viewDatabaseId`
39
+ * absent is the block's database, as `source.databaseId` absent is.
40
+ */
41
+ export declare function isViewSource(source: WorkspaceSource, viewSourceId: string | undefined, viewDatabaseId: string | undefined): boolean;
42
+ /**
43
+ * The postfix of a source of another database: its database's title, grey,
44
+ * on the right (and the check of the current source after it, since a
45
+ * postfix replaces the menu's own check). `undefined` for the block's own
46
+ * sources, so their entries stay the 2.3 ones.
47
+ */
48
+ export declare function databaseLabel(source: WorkspaceSource, untitled: string, selected?: boolean): TemplateResult | undefined;
@@ -0,0 +1,60 @@
1
+ import { DoneIcon } from '@blocksuite/icons/lit';
2
+ import { html } from 'lit';
3
+ /** Whether the host lets a view read a source of another database. */
4
+ export function crossDatabaseViews(picker) {
5
+ return picker?.crossDatabaseViews === true;
6
+ }
7
+ const collator = new Intl.Collator(undefined, {
8
+ sensitivity: 'base',
9
+ numeric: true,
10
+ });
11
+ export function workspaceSources(databases, homeDatabaseId, acrossDatabases) {
12
+ const home = databases.find(database => database.id === homeDatabaseId);
13
+ const own = (home?.sources ?? []).map(source => ({
14
+ sourceId: source.id,
15
+ title: source.title,
16
+ }));
17
+ if (!acrossDatabases)
18
+ return own;
19
+ const others = databases
20
+ .filter(database => database.id !== homeDatabaseId)
21
+ .flatMap(database => database.sources.map(source => ({
22
+ sourceId: source.id,
23
+ title: source.title,
24
+ databaseId: database.id,
25
+ databaseTitle: database.title,
26
+ })));
27
+ others.sort((a, b) => collator.compare(a.title, b.title) ||
28
+ collator.compare(a.databaseTitle ?? '', b.databaseTitle ?? '') ||
29
+ (a.databaseId ?? '').localeCompare(b.databaseId ?? '') ||
30
+ a.sourceId.localeCompare(b.sourceId));
31
+ return [...own, ...others];
32
+ }
33
+ /**
34
+ * A source's database as a trailing argument, only when it is another one:
35
+ * a call about the block's own database is made exactly as in 2.3.
36
+ */
37
+ export const inDatabase = (databaseId) => databaseId === undefined ? [] : [databaseId];
38
+ /**
39
+ * Whether `source` is the one a view reads, by database AND source: the same
40
+ * `sourceId` in another database is another source. `viewDatabaseId`
41
+ * absent is the block's database, as `source.databaseId` absent is.
42
+ */
43
+ export function isViewSource(source, viewSourceId, viewDatabaseId) {
44
+ return (source.sourceId === viewSourceId && source.databaseId === viewDatabaseId);
45
+ }
46
+ /**
47
+ * The postfix of a source of another database: its database's title, grey,
48
+ * on the right (and the check of the current source after it, since a
49
+ * postfix replaces the menu's own check). `undefined` for the block's own
50
+ * sources, so their entries stay the 2.3 ones.
51
+ */
52
+ export function databaseLabel(source, untitled, selected = false) {
53
+ if (source.databaseId === undefined)
54
+ return undefined;
55
+ return html `<span
56
+ data-testid="source-database-label"
57
+ style="margin-left: auto; padding-left: 8px; font-size: 12px; color: var(--affine-text-secondary-color); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px;"
58
+ >${source.databaseTitle || untitled}</span
59
+ >${selected ? DoneIcon() : undefined}`;
60
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formicoidea/labre-core-database",
3
3
  "description": "Labre core-database editing chrome for @formicoidea/labre-core.",
4
- "version": "2.3.3",
4
+ "version": "2.4.1",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "author": "lajola",
@@ -27,7 +27,7 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@formicoidea/labre-core": "2.3.3",
30
+ "@formicoidea/labre-core": "2.4.1",
31
31
  "@blocksuite/icons": "^2.2.12",
32
32
  "@preact/signals-core": "^1.8.0",
33
33
  "lit": "^3.2.0"