@formicoidea/labre-core-database 2.1.1 → 2.3.3

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.
@@ -1,7 +1,7 @@
1
1
  import { menu, popMenu, } from '@formicoidea/labre-core/components/context-menu';
2
2
  import { DOC_UNTITLED, translateKey, } from '@formicoidea/labre-core/shared/services';
3
3
  import { DatabaseTableViewIcon } from '@blocksuite/icons/lit';
4
- import { named, newSourceEntry } from './new-source-entry.js';
4
+ import { named, newSourceEntry, sourceSearch, typedSourceEntry, } from './new-source-entry.js';
5
5
  import { PICKER_EMPTY, PICKER_NEW_DATABASE, PICKER_NEW_SOURCE, PICKER_TITLE, } from './translations.js';
6
6
  function sourceItems(std, picker, database, onPick, offerCreate) {
7
7
  const t = (wording) => translateKey(std, wording[0], wording[1]);
@@ -13,10 +13,10 @@ function sourceItems(std, picker, database, onPick, offerCreate) {
13
13
  }));
14
14
  const createSource = picker.createSource;
15
15
  if (createSource && offerCreate && !std.store.readonly) {
16
- items.push(newSourceEntry(std, picker.sourceName, {
16
+ const entry = {
17
17
  name: t(PICKER_NEW_SOURCE),
18
18
  testId: 'data-source-picker-new-source',
19
- create: sourceName => {
19
+ create: (sourceName) => {
20
20
  createSource
21
21
  .call(picker, database.id, ...named(sourceName))
22
22
  .then(created => {
@@ -33,7 +33,8 @@ function sourceItems(std, picker, database, onPick, offerCreate) {
33
33
  })
34
34
  .catch(console.error);
35
35
  },
36
- }));
36
+ };
37
+ items.push(newSourceEntry(std, picker.sourceName, entry), typedSourceEntry(std, picker.sourceName, database.sources.map(source => source.title), entry));
37
38
  }
38
39
  return items;
39
40
  }
@@ -71,6 +72,7 @@ export function dataSourcePickerItems(std, picker, options) {
71
72
  name: database.title || t(DOC_UNTITLED),
72
73
  prefix: DatabaseTableViewIcon(),
73
74
  options: {
75
+ search: sourceSearch(std),
74
76
  items: sourceItems(std, picker, database, onPick, offerCreate),
75
77
  },
76
78
  }));
@@ -112,6 +114,8 @@ export function popDataSourcePicker(std, picker, target, options) {
112
114
  options: {
113
115
  title: { text: translateKey(std, ...PICKER_TITLE) },
114
116
  testId: 'data-source-picker',
117
+ // A flat list of sources; the list of databases keeps the hidden search.
118
+ search: options.databaseId === undefined ? undefined : sourceSearch(std),
115
119
  items: dataSourcePickerItems(std, picker, options),
116
120
  },
117
121
  });
@@ -1,4 +1,4 @@
1
- import { type MenuConfig } from '@formicoidea/labre-core/components/context-menu';
1
+ import { type MenuConfig, type MenuOptions } from '@formicoidea/labre-core/components/context-menu';
2
2
  import { type DataSourcePickerSourceNaming } from '@formicoidea/labre-core/shared/services';
3
3
  import type { BlockStdScope } from '@formicoidea/labre-core/std';
4
4
  export interface NewSourceEntry {
@@ -18,3 +18,21 @@ export declare const named: (sourceName: string | undefined) => [] | [string];
18
18
  * under it, "Create". Only `'ok'` creates; Enter is "Create".
19
19
  */
20
20
  export declare function newSourceEntry(std: BlockStdScope | undefined, naming: DataSourcePickerSourceNaming | undefined, entry: NewSourceEntry): MenuConfig;
21
+ /**
22
+ * The search field of a menu that lists sources (labre recette of 2.1): the
23
+ * menu's own type-to-search, shown from the start so the list reads as
24
+ * searchable.
25
+ */
26
+ export declare function sourceSearch(std: BlockStdScope | undefined): MenuOptions['search'];
27
+ /**
28
+ * "Create source “typed”" at the end of a searched list of sources (labre
29
+ * recette of 2.1): drawn while the search holds a name no listed source
30
+ * bears (case and accents folded); it creates that name at once, the search
31
+ * having been the naming step. When the host refuses the name (a source of
32
+ * another database bears it), the entry stays, disabled, worded with the
33
+ * host's verdict: hidden, it left "No results" and no reason (labre recette
34
+ * of 2.2). Without the host's naming the typed name is created as is
35
+ * (labre recette of 2.2.1: the search is the one naming step of a list of
36
+ * sources).
37
+ */
38
+ export declare function typedSourceEntry(std: BlockStdScope | undefined, naming: DataSourcePickerSourceNaming | undefined, listed: readonly string[], entry: Pick<NewSourceEntry, 'testId' | 'create'>): MenuConfig;
@@ -1,10 +1,10 @@
1
- import { menu, } from '@formicoidea/labre-core/components/context-menu';
1
+ import { foldForSearch, menu, } from '@formicoidea/labre-core/components/context-menu';
2
2
  import { translateKey, } from '@formicoidea/labre-core/shared/services';
3
3
  import { PlusIcon } from '@blocksuite/icons/lit';
4
4
  import { computed, signal } from '@preact/signals-core';
5
5
  import { html } from 'lit';
6
6
  import { styleMap } from 'lit/directives/style-map.js';
7
- import { SOURCE_NAME_CREATE, SOURCE_NAME_EMPTY, SOURCE_NAME_OK, SOURCE_NAME_PLACEHOLDER, SOURCE_NAME_TAKEN, } from './translations.js';
7
+ import { SOURCE_NAME_CREATE, SOURCE_NAME_EMPTY, SOURCE_NAME_OK, SOURCE_NAME_PLACEHOLDER, SOURCE_NAME_TAKEN, SOURCE_SEARCH_CREATE, SOURCE_SEARCH_PLACEHOLDER, } from './translations.js';
8
8
  /** The name as an argument only when there is one: a host without naming is called as in 2.0. */
9
9
  export const named = (sourceName) => sourceName === undefined ? [] : [sourceName];
10
10
  const VERDICT_WORDING = {
@@ -128,3 +128,94 @@ export function newSourceEntry(std, naming, entry) {
128
128
  })(parent);
129
129
  };
130
130
  }
131
+ /**
132
+ * The search field of a menu that lists sources (labre recette of 2.1): the
133
+ * menu's own type-to-search, shown from the start so the list reads as
134
+ * searchable.
135
+ */
136
+ export function sourceSearch(std) {
137
+ return {
138
+ placeholder: std
139
+ ? translateKey(std, ...SOURCE_SEARCH_PLACEHOLDER)
140
+ : SOURCE_SEARCH_PLACEHOLDER[1],
141
+ };
142
+ }
143
+ // Per menu: the host's names are read once it opens (`suggest`), since
144
+ // `check` answers against the names the last `suggest` read.
145
+ const namesRead = new WeakMap();
146
+ function namesReadFor(parent, naming) {
147
+ let read$ = namesRead.get(parent);
148
+ if (!read$) {
149
+ const created$ = signal(false);
150
+ read$ = created$;
151
+ namesRead.set(parent, created$);
152
+ Promise.resolve()
153
+ .then(() => naming.suggest())
154
+ .catch(console.error)
155
+ .finally(() => {
156
+ created$.value = true;
157
+ });
158
+ }
159
+ return read$.value;
160
+ }
161
+ /**
162
+ * "Create source “typed”" at the end of a searched list of sources (labre
163
+ * recette of 2.1): drawn while the search holds a name no listed source
164
+ * bears (case and accents folded); it creates that name at once, the search
165
+ * having been the naming step. When the host refuses the name (a source of
166
+ * another database bears it), the entry stays, disabled, worded with the
167
+ * host's verdict: hidden, it left "No results" and no reason (labre recette
168
+ * of 2.2). Without the host's naming the typed name is created as is
169
+ * (labre recette of 2.2.1: the search is the one naming step of a list of
170
+ * sources).
171
+ */
172
+ export function typedSourceEntry(std, naming, listed, entry) {
173
+ return parent => {
174
+ const typed = parent.searchName$.value;
175
+ const name = typed.trim();
176
+ if (!name)
177
+ return;
178
+ const key = foldForSearch(name);
179
+ if (listed.some(title => foldForSearch(title.trim()) === key))
180
+ return;
181
+ if (naming && !namesReadFor(parent, naming))
182
+ return;
183
+ const verdict = naming ? verdictOf(naming, name) : 'ok';
184
+ if (verdict !== 'ok') {
185
+ return html `<div
186
+ role="status"
187
+ aria-disabled="true"
188
+ data-testid="${entry.testId}-typed"
189
+ data-verdict=${verdict}
190
+ style=${styleMap({
191
+ display: 'flex',
192
+ alignItems: 'center',
193
+ gap: '4px',
194
+ padding: '4px',
195
+ fontSize: '14px',
196
+ lineHeight: '22px',
197
+ color: 'var(--affine-text-disable-color)',
198
+ cursor: 'default',
199
+ })}
200
+ >
201
+ ${PlusIcon()}
202
+ <span style="color: var(--affine-error-color)"
203
+ >${std
204
+ ? translateKey(std, ...VERDICT_WORDING[verdict])
205
+ : VERDICT_WORDING[verdict][1]}</span
206
+ >
207
+ </div>`;
208
+ }
209
+ // The typed text verbatim, so the menu's own search keeps the entry.
210
+ const params = { name: typed };
211
+ return menu.action({
212
+ name: std
213
+ ? translateKey(std, ...SOURCE_SEARCH_CREATE, params)
214
+ : SOURCE_SEARCH_CREATE[1].replace('{{name}}', typed),
215
+ prefix: PlusIcon(),
216
+ testId: `${entry.testId}-typed`,
217
+ class: { 'enter-default': true },
218
+ select: () => entry.create(name),
219
+ })(parent);
220
+ };
221
+ }
@@ -1,9 +1,5 @@
1
1
  import { type ChromeWording } from '@formicoidea/labre-core/shared/services';
2
2
  import type { TranslationKeyManifestEntry } from '@formicoidea/labre-core/std';
3
- /** The entry that lists the sources the database's views already read. */
4
- export declare const DATABASE_ADD_VIEW_EXISTING_SOURCE: ChromeWording;
5
- /** The entry that asks the host for a new source and adds a table on it. */
6
- export declare const DATABASE_ADD_VIEW_NEW_SOURCE: ChromeWording;
7
3
  /** A source whose schema block has an empty title. */
8
4
  export declare const DATABASE_ADD_VIEW_UNTITLED_SOURCE: ChromeWording;
9
5
  /** The third entry: copy a view of another database (labre REQ-DB-2). */
@@ -69,6 +65,9 @@ export declare const SOURCE_NAME_OK: ChromeWording;
69
65
  export declare const SOURCE_NAME_TAKEN: ChromeWording;
70
66
  export declare const SOURCE_NAME_CREATE: ChromeWording;
71
67
  export declare const SOURCE_NAME_EMPTY: ChromeWording;
68
+ export declare const SOURCE_SEARCH_PLACEHOLDER: ChromeWording;
69
+ /** `{{name}}` is the name as typed in the search field. */
70
+ export declare const SOURCE_SEARCH_CREATE: ChromeWording;
72
71
  export declare const PICKER_EMPTY: ChromeWording;
73
72
  export declare const SLASH_LINKED_VIEW: ChromeWording;
74
73
  export declare const SLASH_LINKED_VIEW_DESCRIPTION: ChromeWording;
@@ -1,15 +1,5 @@
1
1
  import { SAVE_AS_TEMPLATE, } from '@formicoidea/labre-core/shared/services';
2
2
  /* ── "+ view" (ADR 0035 §1, §9c, B11; labre ADR-0046 §5) ──────────────── */
3
- /** The entry that lists the sources the database's views already read. */
4
- export const DATABASE_ADD_VIEW_EXISTING_SOURCE = [
5
- 'com.labre.database.add-view.existing-source',
6
- 'On an existing source',
7
- ];
8
- /** The entry that asks the host for a new source and adds a table on it. */
9
- export const DATABASE_ADD_VIEW_NEW_SOURCE = [
10
- 'com.labre.database.add-view.new-source',
11
- 'With a new source',
12
- ];
13
3
  /** A source whose schema block has an empty title. */
14
4
  export const DATABASE_ADD_VIEW_UNTITLED_SOURCE = [
15
5
  'com.labre.database.add-view.untitled-source',
@@ -154,6 +144,16 @@ export const SOURCE_NAME_EMPTY = [
154
144
  'com.labre.database.source-name.empty',
155
145
  'Give the source a name.',
156
146
  ];
147
+ /* ── Searching a list of sources (labre recette of 2.1) ───────────────── */
148
+ export const SOURCE_SEARCH_PLACEHOLDER = [
149
+ 'com.labre.database.source-search.placeholder',
150
+ 'Search or create a source',
151
+ ];
152
+ /** `{{name}}` is the name as typed in the search field. */
153
+ export const SOURCE_SEARCH_CREATE = [
154
+ 'com.labre.database.source-search.create',
155
+ 'Create source “{{name}}”',
156
+ ];
157
157
  export const PICKER_EMPTY = [
158
158
  'com.labre.database.picker.empty',
159
159
  'No database to show',
@@ -167,9 +167,7 @@ export const SLASH_LINKED_VIEW_DESCRIPTION = [
167
167
  'Show a view of an existing database.',
168
168
  ];
169
169
  const DATABASE_EDITOR_WORDINGS = [
170
- DATABASE_ADD_VIEW_EXISTING_SOURCE,
171
170
  DATABASE_ADD_VIEW_IMPORT,
172
- DATABASE_ADD_VIEW_NEW_SOURCE,
173
171
  DATABASE_ADD_VIEW_UNTITLED_SOURCE,
174
172
  DATABASE_CREATION_LINK_EXISTING,
175
173
  DATABASE_CREATION_NEW_SOURCE,
@@ -5,60 +5,67 @@ import { type AddViewSource } from './add-view-sources.js';
5
5
  /**
6
6
  * What the data-source picker seam (ADR 0035 §9c, B12) gives "+ view", as
7
7
  * this menu reads it. Both optional: without `createSource` there is no
8
- * "With a new source"; without `extraSourceIds` only the sources the views
8
+ * "Create source “typed”"; without `sources` only the sources the views
9
9
  * already read are listed (the seams table's "When absent").
10
10
  */
11
11
  export interface AddViewSourcePicker {
12
- /** Sources of this database that no view reads yet. */
13
- extraSourceIds?(dataSource: HostedDataSourceBase): readonly string[];
12
+ /** The sources of this database, as the host lists them (the view settings' list). */
13
+ sources?(dataSource: HostedDataSourceBase): readonly {
14
+ id: string;
15
+ title: string;
16
+ }[];
14
17
  /** Creates a source in this database; resolves to its id, or nothing. */
15
18
  createSource?(dataSource: HostedDataSourceBase, sourceName?: string): Promise<string | undefined>;
16
- /** How the host names a new source; absent, "With a new source" creates at once. */
19
+ /** How the host checks a typed name; absent, any name no listed source bears is created. */
17
20
  sourceName?: DataSourcePickerSourceNaming;
18
21
  }
19
22
  /**
20
23
  * The host's data-source picker (`DataSourcePickerProvider`, B12) as "+ view"
21
24
  * reads it, on the database the block shows (`externalSourceId`, the id the
22
- * picker lists it under): its sources no view reads yet, and its
23
- * `createSource`. "+ view" lists them inline rather than popping the picker
24
- * over its own menu: one menu, the presets under each source.
25
+ * picker lists it under): its sources, and its `createSource`. "+ view"
26
+ * lists them inline rather than popping the picker over its own menu: one
27
+ * menu, the presets under each source. `sources` reads the host's list as a
28
+ * 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.
25
30
  */
26
31
  export declare function addViewSourcePicker(picker: DataSourcePickerService): AddViewSourcePicker;
27
32
  /**
28
33
  * What "+ view" draws, decided from the sources alone (pure, held by
29
34
  * `add-view-menu.unit.spec.ts`): the presets themselves when there is
30
- * nothing to choose (one source, no way to create one), otherwise the
31
- * entries, "On an existing source" only when there is one.
35
+ * nothing to choose (one source, no way to create or import one), otherwise
36
+ * the list of sources.
32
37
  */
33
38
  export type AddViewMenuShape = {
34
39
  kind: 'presets';
35
40
  source: AddViewSource | undefined;
36
41
  } | {
37
- kind: 'entries';
38
- existing: AddViewSource[];
39
- newSource: boolean;
42
+ kind: 'list';
43
+ sources: AddViewSource[];
44
+ create: boolean;
40
45
  importView: boolean;
41
46
  };
42
47
  export declare function addViewMenuShape(sources: AddViewSource[], canCreateSource: boolean, canImport?: boolean): AddViewMenuShape;
43
48
  /**
44
49
  * The "+ view" menu of a database whose views read named sources (ADR 0035
45
- * §1, §7, B11; labre ADR-0046 §5 and PRD REQ-DB-7: "+ view has three
46
- * entries"):
50
+ * §1, §7, B11; labre ADR-0046 §5). One source list with the view settings'
51
+ * "Source" (ADR 0035 amendment of 2026-10-30, superseding the three entries
52
+ * of labre PRD REQ-DB-7):
47
53
  *
48
- * 1. "On an existing source": the creatable presets, on one of the sources
49
- * the views read (`existingSources`), a sub-menu per source when there
50
- * are several. With one source and nothing else to offer, the presets
51
- * are the menu itself, as in 0.48.
52
- * 2. "With a new source": asks the picker for a source, then adds a table on
53
- * it. Absent without the picker's `createSource`: that is the host's kill
54
- * switch on creating sources (labre ADR-0046 §10).
55
- * 3. "Import a view from another database" (labre REQ-DB-2): hands the
56
- * picker's `importView` a request whose `add` copies the chosen view
57
- * onto the current view's source (`view-transfer/import-view.ts`, ADR
58
- * 0035 amendment of 2026-10-14). Absent without that verb.
54
+ * 1. The search field, shown from the start (`searchPlaceholder`).
55
+ * 2. Each source of this database (`existingSources`), a sub-menu of the
56
+ * creatable presets. With one source and nothing to create or import,
57
+ * the presets are the menu itself, as in 0.48.
58
+ * 3. "Create source “typed”" (`typedSourceEntry`): creates the typed name
59
+ * through the picker's `createSource`, then adds a table on it. Absent
60
+ * without `createSource`: the host's kill switch on creating sources
61
+ * (labre ADR-0046 §10).
62
+ * 4. Under a divider, "Import a view from another database" (labre
63
+ * REQ-DB-2): hands the picker's `importView` a request whose `add` copies
64
+ * the chosen view onto the current view's source
65
+ * (`view-transfer/import-view.ts`, ADR 0035 amendment of 2026-10-14).
66
+ * Absent without that verb.
59
67
  *
60
68
  * A data source that does not resolve sources (an inline database, a 0.48
61
69
  * host source) has one implicit source: the bar keeps its presets list.
62
-
63
70
  */
64
71
  export declare function databaseAddViewMenu(picker: (context: AddViewMenuContext) => AddViewSourcePicker | null): AddViewMenu;
@@ -4,29 +4,29 @@ import { DataSourcePickerProvider, translateKey, } from '@formicoidea/labre-core
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 { DATABASE_ADD_VIEW_EXISTING_SOURCE, DATABASE_ADD_VIEW_IMPORT, DATABASE_ADD_VIEW_NEW_SOURCE, DATABASE_ADD_VIEW_UNTITLED_SOURCE, } from '../translations.js';
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, newSourceEntry } from '../new-source-entry.js';
9
+ import { named, sourceSearch, typedSourceEntry } from '../new-source-entry.js';
10
10
  import { addViewOnSource } from './add-view-on-source.js';
11
11
  import { existingSources } from './add-view-sources.js';
12
12
  /**
13
13
  * The host's data-source picker (`DataSourcePickerProvider`, B12) as "+ view"
14
14
  * reads it, on the database the block shows (`externalSourceId`, the id the
15
- * picker lists it under): its sources no view reads yet, and its
16
- * `createSource`. "+ view" lists them inline rather than popping the picker
17
- * over its own menu: one menu, the presets under each source.
15
+ * picker lists it under): its sources, and its `createSource`. "+ view"
16
+ * lists them inline rather than popping the picker over its own menu: one
17
+ * menu, the presets under each source. `sources` reads the host's list as a
18
+ * 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.
18
20
  */
19
21
  export function addViewSourcePicker(picker) {
20
22
  const databaseOf = (dataSource) => dataSource.hostModel.props.externalSourceId;
21
23
  const createSource = picker.createSource;
24
+ let list;
22
25
  return {
23
- extraSourceIds: dataSource => {
26
+ sources: dataSource => {
24
27
  const databaseId = databaseOf(dataSource);
25
- const database = picker
26
- .list()
27
- .peek()
28
- .find(candidate => candidate.id === databaseId);
29
- return database?.sources.map(source => source.id) ?? [];
28
+ list ??= picker.list();
29
+ return (list.value.find(candidate => candidate.id === databaseId)?.sources ?? []);
30
30
  },
31
31
  createSource: createSource
32
32
  ? async (dataSource, sourceName) => {
@@ -45,55 +45,83 @@ export function addViewMenuShape(sources, canCreateSource, canImport = false) {
45
45
  return { kind: 'presets', source: sources[0] };
46
46
  }
47
47
  return {
48
- kind: 'entries',
49
- existing: sources,
50
- newSource: canCreateSource,
48
+ kind: 'list',
49
+ sources,
50
+ create: canCreateSource,
51
51
  importView: canImport,
52
52
  };
53
53
  }
54
+ /** The sources "+ view" lists now; read in a `menu.dynamic`, it follows the host's list. */
55
+ function readSources(dataSource, sourcePicker) {
56
+ return existingSources({
57
+ viewSourceIds: dataSource.viewDataList$
58
+ .peek()
59
+ .map(view => view.sourceId),
60
+ resolve: sourceId => {
61
+ const schema = dataSource.sourceOf(sourceId)?.schema;
62
+ return schema
63
+ ? { schemaId: schema.id, title: schema.props.title.toString() }
64
+ : null;
65
+ },
66
+ listed: sourcePicker?.sources?.(dataSource),
67
+ });
68
+ }
69
+ /**
70
+ * What both the items and the search field of "+ view" are drawn from. The
71
+ * shape is decided at the opening, on the sources known then: a host list
72
+ * still on its way leaves the views' sources, and with a way to create or
73
+ * import a source the list shape applies anyway.
74
+ */
75
+ function addViewPlan(context, sourcePicker) {
76
+ const { dataSource } = context;
77
+ if (!(dataSource instanceof HostedDataSourceBase))
78
+ return;
79
+ if (!dataSource.resolvesSources)
80
+ return;
81
+ const sources = readSources(dataSource, sourcePicker);
82
+ const createSource = sourcePicker?.createSource?.bind(sourcePicker);
83
+ const hostPicker = context.std?.getOptional(DataSourcePickerProvider);
84
+ const shape = addViewMenuShape(sources, createSource !== undefined, canImportView(hostPicker, dataSource));
85
+ return { dataSource, createSource, hostPicker, shape };
86
+ }
54
87
  /**
55
88
  * The "+ view" menu of a database whose views read named sources (ADR 0035
56
- * §1, §7, B11; labre ADR-0046 §5 and PRD REQ-DB-7: "+ view has three
57
- * entries"):
89
+ * §1, §7, B11; labre ADR-0046 §5). One source list with the view settings'
90
+ * "Source" (ADR 0035 amendment of 2026-10-30, superseding the three entries
91
+ * of labre PRD REQ-DB-7):
58
92
  *
59
- * 1. "On an existing source": the creatable presets, on one of the sources
60
- * the views read (`existingSources`), a sub-menu per source when there
61
- * are several. With one source and nothing else to offer, the presets
62
- * are the menu itself, as in 0.48.
63
- * 2. "With a new source": asks the picker for a source, then adds a table on
64
- * it. Absent without the picker's `createSource`: that is the host's kill
65
- * switch on creating sources (labre ADR-0046 §10).
66
- * 3. "Import a view from another database" (labre REQ-DB-2): hands the
67
- * picker's `importView` a request whose `add` copies the chosen view
68
- * onto the current view's source (`view-transfer/import-view.ts`, ADR
69
- * 0035 amendment of 2026-10-14). Absent without that verb.
93
+ * 1. The search field, shown from the start (`searchPlaceholder`).
94
+ * 2. Each source of this database (`existingSources`), a sub-menu of the
95
+ * creatable presets. With one source and nothing to create or import,
96
+ * the presets are the menu itself, as in 0.48.
97
+ * 3. "Create source “typed”" (`typedSourceEntry`): creates the typed name
98
+ * through the picker's `createSource`, then adds a table on it. Absent
99
+ * without `createSource`: the host's kill switch on creating sources
100
+ * (labre ADR-0046 §10).
101
+ * 4. Under a divider, "Import a view from another database" (labre
102
+ * REQ-DB-2): hands the picker's `importView` a request whose `add` copies
103
+ * the chosen view onto the current view's source
104
+ * (`view-transfer/import-view.ts`, ADR 0035 amendment of 2026-10-14).
105
+ * Absent without that verb.
70
106
  *
71
107
  * A data source that does not resolve sources (an inline database, a 0.48
72
108
  * host source) has one implicit source: the bar keeps its presets list.
73
-
74
109
  */
75
110
  export function databaseAddViewMenu(picker) {
76
111
  return {
77
- items: context => {
78
- const { dataSource } = context;
79
- if (!(dataSource instanceof HostedDataSourceBase))
112
+ searchPlaceholder: context => {
113
+ if (addViewPlan(context, picker(context))?.shape.kind !== 'list') {
80
114
  return;
81
- if (!dataSource.resolvesSources)
115
+ }
116
+ return sourceSearch(context.std)?.placeholder;
117
+ },
118
+ items: context => {
119
+ const sourcePicker = picker(context);
120
+ const plan = addViewPlan(context, sourcePicker);
121
+ if (!plan)
82
122
  return;
123
+ const { dataSource, createSource, hostPicker, shape } = plan;
83
124
  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
125
  const presetsOn = (source) => dataSource.viewMetas.map(meta => menu.action({
98
126
  name: viewDefaultName(meta, context.std),
99
127
  testId: 'database-add-view-preset',
@@ -102,56 +130,53 @@ export function databaseAddViewMenu(picker) {
102
130
  addViewOnSource(context, dataSource, meta.type, source?.sourceId);
103
131
  },
104
132
  }));
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
133
  if (shape.kind === 'presets') {
109
134
  return presetsOn(shape.source);
110
135
  }
111
- const { existing } = shape;
112
- const items = [];
113
- if (existing.length > 0) {
114
- items.push(menu.subMenu({
115
- name: wording(DATABASE_ADD_VIEW_EXISTING_SOURCE),
116
- options: {
117
- items: existing.length === 1
118
- ? presetsOn(existing[0])
119
- : existing.map(source => menu.subMenu({
120
- name: source.title ||
121
- wording(DATABASE_ADD_VIEW_UNTITLED_SOURCE),
122
- options: { items: presetsOn(source) },
123
- })),
124
- },
125
- }));
126
- }
127
- if (shape.newSource && createSource) {
128
- items.push(newSourceEntry(context.std, sourcePicker?.sourceName, {
129
- name: wording(DATABASE_ADD_VIEW_NEW_SOURCE),
130
- testId: 'database-add-view-new-source',
131
- create: sourceName => {
132
- createSource(dataSource, ...named(sourceName))
133
- .then(sourceId => {
134
- // The source arrived after a round trip: the page may have
135
- // turned read-only meanwhile.
136
- if (sourceId === undefined || dataSource.readonly$.peek()) {
137
- return;
138
- }
139
- addViewOnSource(context, dataSource, 'table', sourceId, 'new');
140
- })
141
- .catch(error => {
142
- console.error(error);
143
- });
144
- },
145
- }));
146
- }
136
+ const create = shape.create && createSource
137
+ ? (sourceName) => {
138
+ createSource(dataSource, ...named(sourceName))
139
+ .then(sourceId => {
140
+ // The source arrived after a round trip: the page may
141
+ // have turned read-only meanwhile.
142
+ if (sourceId === undefined || dataSource.readonly$.peek()) {
143
+ return;
144
+ }
145
+ addViewOnSource(context, dataSource, 'table', sourceId, 'new');
146
+ })
147
+ .catch(error => {
148
+ console.error(error);
149
+ });
150
+ }
151
+ : undefined;
152
+ const items = [
153
+ // Read while drawing, so a host list that arrives with the menu
154
+ // open shows up (labre recette of 2.3.2).
155
+ menu.dynamic(() => {
156
+ const sources = readSources(dataSource, sourcePicker);
157
+ const entries = sources.map(source => menu.subMenu({
158
+ name: source.title || wording(DATABASE_ADD_VIEW_UNTITLED_SOURCE),
159
+ testId: `database-add-view-source-${source.sourceId}`,
160
+ options: { items: presetsOn(source) },
161
+ }));
162
+ if (create) {
163
+ entries.push(typedSourceEntry(context.std, sourcePicker?.sourceName, sources.map(source => source.title), { testId: 'database-add-view-new-source', create }));
164
+ }
165
+ return entries;
166
+ }),
167
+ ];
147
168
  if (shape.importView) {
148
- items.push(menu.action({
149
- name: wording(DATABASE_ADD_VIEW_IMPORT),
150
- prefix: ImportIcon(),
151
- testId: 'database-add-view-import',
152
- select: () => {
153
- requestViewImport(hostPicker, dataSource);
154
- },
169
+ items.push(menu.group({
170
+ items: [
171
+ menu.action({
172
+ name: wording(DATABASE_ADD_VIEW_IMPORT),
173
+ prefix: ImportIcon(),
174
+ testId: 'database-add-view-import',
175
+ select: () => {
176
+ requestViewImport(hostPicker, dataSource);
177
+ },
178
+ }),
179
+ ],
155
180
  }));
156
181
  }
157
182
  return items;
@@ -1,7 +1,6 @@
1
1
  /**
2
- * The sources "+ view" offers (ADR 0035 §1, §9c, B11; labre ADR-0046 §5:
3
- * "+ view has three entries: on an existing source, with a new source, import
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
- * `extraSourceIds` is for the data-source picker (B12): the sources of this
16
- * database that no view reads yet, appended after the shown ones,
17
- * deduplicated the same way.
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. */
@@ -32,6 +34,9 @@ export interface AddViewSourceReader {
32
34
  schemaId: string;
33
35
  title: string;
34
36
  } | null;
35
- extraSourceIds?: readonly string[];
37
+ listed?: readonly {
38
+ id: string;
39
+ title: string;
40
+ }[];
36
41
  }
37
42
  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
- reader.extraSourceIds?.forEach(add);
22
- return [...bySchema.values()];
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 picker to point it at
10
- * another, "New source" included when the host gives `createSource`. One
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,13 @@ 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 picker on this database's sources at `target`, its "back" reopening
40
- * the view settings (`reopen`); a pick points the view at it. The picker's
41
- * own items (`dataSourcePickerItems`, "New source" through `createSource`)
42
- * under its own title, so it reads as the "+ view" picker does.
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.
43
46
  */
44
47
  export declare function popChangeSourcePicker(std: BlockStdScope, target: PopupTarget, change: ChangeSourceTarget, reopen: () => void): MenuHandler;
45
48
  /**
@@ -3,7 +3,7 @@ import { menu, popMenu, } from '@formicoidea/labre-core/components/context-menu'
3
3
  import { DataSourcePickerProvider, translateKey, } from '@formicoidea/labre-core/shared/services';
4
4
  import { ArrowRightSmallIcon, DatabaseTableViewIcon, } from '@blocksuite/icons/lit';
5
5
  import { html } from 'lit';
6
- import { dataSourcePickerItems } from '../data-source-picker.js';
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';
@@ -35,23 +35,60 @@ export function currentSourceTitle(std, dataSource) {
35
35
  translateKey(std, ...DATABASE_ADD_VIEW_UNTITLED_SOURCE));
36
36
  }
37
37
  /**
38
- * Pop the picker on this database's sources at `target`, its "back" reopening
39
- * the view settings (`reopen`); a pick points the view at it. The picker's
40
- * own items (`dataSourcePickerItems`, "New source" through `createSource`)
41
- * under its own title, so it reads as the "+ view" picker does.
38
+ * Pop the list of this database's sources at `target`, its "back" reopening
39
+ * the view settings (`reopen`); a pick points the view at it. One source list
40
+ * with "+ view" (ADR 0035 amendment of 2026-10-30): the search field shown
41
+ * from the start, the view's current source checked (picking it again only
42
+ * closes), and "Create source “typed”" last, which creates the typed name
43
+ * through `createSource` and points the view at it. The search is the naming
44
+ * step: no "New source" sub-step here.
42
45
  */
43
46
  export function popChangeSourcePicker(std, target, change, reopen) {
44
47
  const { dataSource, databaseId, picker, viewId } = change;
48
+ const list = picker.list();
49
+ const createSource = picker.createSource;
50
+ const current = dataSource.viewDataGet(viewId)?.sourceId;
45
51
  return popMenu(target, {
46
52
  options: {
47
53
  title: { text: translateKey(std, ...PICKER_TITLE), onBack: reopen },
48
54
  testId: 'data-source-picker',
49
- items: dataSourcePickerItems(std, picker, {
50
- databaseId,
51
- onPick: ({ sourceId, source }) => {
52
- changeViewSource(dataSource, viewId, sourceId, source);
53
- },
54
- }),
55
+ search: sourceSearch(std),
56
+ items: [
57
+ 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
+ }));
72
+ if (!createSource || std.store.readonly)
73
+ return items;
74
+ return [
75
+ ...items,
76
+ typedSourceEntry(std, picker.sourceName, sources.map(source => source.title), {
77
+ testId: 'data-source-picker-new-source',
78
+ create: sourceName => {
79
+ createSource
80
+ .call(picker, databaseId, ...named(sourceName))
81
+ .then(created => {
82
+ if (created) {
83
+ changeViewSource(dataSource, viewId, created.id, 'new');
84
+ }
85
+ })
86
+ .catch(console.error);
87
+ },
88
+ }),
89
+ ];
90
+ }),
91
+ ],
55
92
  },
56
93
  });
57
94
  }
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.1.1",
4
+ "version": "2.3.3",
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.1.1",
30
+ "@formicoidea/labre-core": "2.3.3",
31
31
  "@blocksuite/icons": "^2.2.12",
32
32
  "@preact/signals-core": "^1.8.0",
33
33
  "lit": "^3.2.0"