@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.
@@ -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,95 @@ 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
+ // No "+" on a refused name (labre recette of 2.3.3): an icon made the
185
+ // status line read as a button.
186
+ if (verdict !== 'ok') {
187
+ return html `<div
188
+ role="status"
189
+ aria-disabled="true"
190
+ data-testid="${entry.testId}-typed"
191
+ data-verdict=${verdict}
192
+ style=${styleMap({
193
+ display: 'flex',
194
+ alignItems: 'center',
195
+ gap: '4px',
196
+ padding: '4px',
197
+ fontSize: '14px',
198
+ lineHeight: '22px',
199
+ color: 'var(--affine-text-disable-color)',
200
+ cursor: 'default',
201
+ })}
202
+ >
203
+ <span style="color: var(--affine-error-color)"
204
+ >${std
205
+ ? translateKey(std, ...VERDICT_WORDING[verdict])
206
+ : VERDICT_WORDING[verdict][1]}</span
207
+ >
208
+ </div>`;
209
+ }
210
+ // The typed text verbatim, so the menu's own search keeps the entry.
211
+ const params = { name: typed };
212
+ return menu.action({
213
+ name: std
214
+ ? translateKey(std, ...SOURCE_SEARCH_CREATE, params)
215
+ : SOURCE_SEARCH_CREATE[1].replace('{{name}}', typed),
216
+ prefix: PlusIcon(),
217
+ testId: `${entry.testId}-typed`,
218
+ class: { 'enter-default': true },
219
+ select: () => entry.create(name),
220
+ })(parent);
221
+ };
222
+ }
@@ -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,
@@ -188,6 +186,8 @@ const DATABASE_EDITOR_WORDINGS = [
188
186
  SOURCE_NAME_OK,
189
187
  SOURCE_NAME_PLACEHOLDER,
190
188
  SOURCE_NAME_TAKEN,
189
+ SOURCE_SEARCH_CREATE,
190
+ SOURCE_SEARCH_PLACEHOLDER,
191
191
  VIEW_MENU_IMPORT,
192
192
  VIEW_SETTINGS_SOURCE,
193
193
  ];
@@ -5,60 +5,78 @@ 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
+ }[];
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[];
14
23
  /** Creates a source in this database; resolves to its id, or nothing. */
15
24
  createSource?(dataSource: HostedDataSourceBase, sourceName?: string): Promise<string | undefined>;
16
- /** How the host names a new source; absent, "With a new source" creates at once. */
25
+ /** How the host checks a typed name; absent, any name no listed source bears is created. */
17
26
  sourceName?: DataSourcePickerSourceNaming;
18
27
  }
19
28
  /**
20
29
  * The host's data-source picker (`DataSourcePickerProvider`, B12) as "+ view"
21
30
  * 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.
31
+ * picker lists it under): its sources, and its `createSource`. "+ view"
32
+ * lists them inline rather than popping the picker over its own menu: one
33
+ * menu, the presets under each source. `sources` reads the host's list as a
34
+ * signal, asked for once per adapter: a host may fill it after its first
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).
25
38
  */
26
39
  export declare function addViewSourcePicker(picker: DataSourcePickerService): AddViewSourcePicker;
27
40
  /**
28
41
  * What "+ view" draws, decided from the sources alone (pure, held by
29
42
  * `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.
43
+ * nothing to choose (one source, no way to create or import one), otherwise
44
+ * the list of sources.
32
45
  */
33
46
  export type AddViewMenuShape = {
34
47
  kind: 'presets';
35
48
  source: AddViewSource | undefined;
36
49
  } | {
37
- kind: 'entries';
38
- existing: AddViewSource[];
39
- newSource: boolean;
50
+ kind: 'list';
51
+ sources: AddViewSource[];
52
+ create: boolean;
40
53
  importView: boolean;
41
54
  };
42
55
  export declare function addViewMenuShape(sources: AddViewSource[], canCreateSource: boolean, canImport?: boolean): AddViewMenuShape;
43
56
  /**
44
57
  * 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"):
58
+ * §1, §7, B11; labre ADR-0046 §5). One source list with the view settings'
59
+ * "Source" (ADR 0035 amendment of 2026-10-30, superseding the three entries
60
+ * of labre PRD REQ-DB-7):
47
61
  *
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.
62
+ * 1. The search field, shown from the start (`searchPlaceholder`).
63
+ * 2. Each source of this database (`existingSources`), a sub-menu of the
64
+ * creatable presets. With one source and nothing to create or import,
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).
69
+ * 3. "Create source “typed”" (`typedSourceEntry`): creates the typed name
70
+ * through the picker's `createSource`, then adds a table on it. Absent
71
+ * without `createSource`: the host's kill switch on creating sources
72
+ * (labre ADR-0046 §10).
73
+ * 4. Under a divider, "Import a view from another database" (labre
74
+ * REQ-DB-2): hands the picker's `importView` a request whose `add` copies
75
+ * the chosen view onto the current view's source
76
+ * (`view-transfer/import-view.ts`, ADR 0035 amendment of 2026-10-14).
77
+ * Absent without that verb.
59
78
  *
60
79
  * A data source that does not resolve sources (an inline database, a 0.48
61
80
  * host source) has one implicit source: the bar keeps its presets list.
62
-
63
81
  */
64
82
  export declare function databaseAddViewMenu(picker: (context: AddViewMenuContext) => AddViewSourcePicker | null): AddViewMenu;