@formicoidea/labre-core-database 1.0.0 → 1.1.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.
@@ -6,16 +6,22 @@ import type { BlockStdScope } from '@formicoidea/labre-core/std';
6
6
  * The popover's items, from the picker alone (held by
7
7
  * `creation-popover.unit.spec.ts`): "New empty source" when the host creates
8
8
  * a database, "Link an existing source" when it lists one, each connecting
9
- * the block it was opened over (`connectDatabaseToSource`). A cancelled
10
- * creation (`null`, or a database with no source) writes nothing.
9
+ * the block it was opened over: `connectDatabaseToSource` for a block with
10
+ * no source, `reconnectDatabaseView` on `viewId` (else the first view) for
11
+ * a hosted block whose source the host no longer resolves (ADR 0035
12
+ * amendment of 2026-10-29). A cancelled creation (`null`, or a database
13
+ * with no source) writes nothing.
11
14
  */
12
- export declare function databaseCreationItems(std: BlockStdScope, picker: DataSourcePickerService, blockId: string): MenuConfig[];
15
+ export declare function databaseCreationItems(std: BlockStdScope, picker: DataSourcePickerService, blockId: string, viewId?: string): MenuConfig[];
13
16
  /**
14
17
  * The creation menu of the `core-database` bundle (ADR 0035 §5, amendment of
15
18
  * 2026-10-28): "Table View" and "Kanban View" insert a native database at
16
19
  * once and open this popover over it, so a host's database is created or
17
20
  * linked only when the reader says which. Escape or a click outside closes
18
- * it and leaves the native database, which renders and stays editable.
19
- * Without a host picker the entries never call it.
21
+ * it and leaves the native database, which renders and stays editable; a
22
+ * host that sets `requireSource` gets it drawn as an empty view whose
23
+ * "Connect a source" reopens this popover (ADR 0035 amendment of
24
+ * 2026-10-29). Closing writes nothing either way. Without a host picker the
25
+ * entries never call it.
20
26
  */
21
27
  export declare function databaseCreationMenu(): DatabaseCreationMenu;
@@ -1,9 +1,9 @@
1
- import { connectDatabaseToSource, } from '@formicoidea/labre-core/blocks/database';
1
+ import { connectDatabaseToSource, DATABASE_CREATION_TITLE, reconnectDatabaseView, } from '@formicoidea/labre-core/blocks/database';
2
2
  import { menu, popMenu, popupTargetFromElement, } from '@formicoidea/labre-core/components/context-menu';
3
3
  import { DataSourcePickerProvider, translateKey, } from '@formicoidea/labre-core/shared/services';
4
4
  import { LinkIcon, PlusIcon } from '@blocksuite/icons/lit';
5
5
  import { dataSourcePickerItems } from './data-source-picker.js';
6
- import { DATABASE_CREATION_LINK_EXISTING, DATABASE_CREATION_NEW_SOURCE, DATABASE_CREATION_TITLE, } from './translations.js';
6
+ import { DATABASE_CREATION_LINK_EXISTING, DATABASE_CREATION_NEW_SOURCE, } from './translations.js';
7
7
  /** The block the entry inserted, while it is still a database. */
8
8
  function databaseModel(std, blockId) {
9
9
  const model = std.store.getModelById(blockId);
@@ -15,15 +15,26 @@ function databaseModel(std, blockId) {
15
15
  * The popover's items, from the picker alone (held by
16
16
  * `creation-popover.unit.spec.ts`): "New empty source" when the host creates
17
17
  * a database, "Link an existing source" when it lists one, each connecting
18
- * the block it was opened over (`connectDatabaseToSource`). A cancelled
19
- * creation (`null`, or a database with no source) writes nothing.
18
+ * the block it was opened over: `connectDatabaseToSource` for a block with
19
+ * no source, `reconnectDatabaseView` on `viewId` (else the first view) for
20
+ * a hosted block whose source the host no longer resolves (ADR 0035
21
+ * amendment of 2026-10-29). A cancelled creation (`null`, or a database
22
+ * with no source) writes nothing.
20
23
  */
21
- export function databaseCreationItems(std, picker, blockId) {
24
+ export function databaseCreationItems(std, picker, blockId, viewId) {
22
25
  const t = (wording) => translateKey(std, wording[0], wording[1]);
23
26
  const connect = (database, sourceId) => {
24
27
  const model = databaseModel(std, blockId);
25
- if (model)
28
+ if (!model)
29
+ return;
30
+ if (model.props.externalSourceId === undefined) {
26
31
  connectDatabaseToSource(std, model, { database, sourceId });
32
+ return;
33
+ }
34
+ const view = viewId ?? model.props.views[0]?.id;
35
+ if (view) {
36
+ reconnectDatabaseView(std, model, { database, sourceId, viewId: view });
37
+ }
27
38
  };
28
39
  const createDatabase = picker.createDatabase;
29
40
  const list = picker.list();
@@ -47,9 +58,9 @@ export function databaseCreationItems(std, picker, blockId) {
47
58
  menu.subMenu({
48
59
  name: t(DATABASE_CREATION_LINK_EXISTING),
49
60
  prefix: LinkIcon(),
50
- // A sub-menu entry takes no test id: the class names the entry, the
51
- // test id the menu it opens.
61
+ // The entry's test id names the entry, the options' the menu it opens.
52
62
  class: 'database-creation-link-existing',
63
+ testId: 'database-creation-link-existing-entry',
53
64
  hide: () => list.value.length === 0,
54
65
  options: {
55
66
  testId: 'database-creation-link-existing',
@@ -66,12 +77,15 @@ export function databaseCreationItems(std, picker, blockId) {
66
77
  * 2026-10-28): "Table View" and "Kanban View" insert a native database at
67
78
  * once and open this popover over it, so a host's database is created or
68
79
  * linked only when the reader says which. Escape or a click outside closes
69
- * it and leaves the native database, which renders and stays editable.
70
- * Without a host picker the entries never call it.
80
+ * it and leaves the native database, which renders and stays editable; a
81
+ * host that sets `requireSource` gets it drawn as an empty view whose
82
+ * "Connect a source" reopens this popover (ADR 0035 amendment of
83
+ * 2026-10-29). Closing writes nothing either way. Without a host picker the
84
+ * entries never call it.
71
85
  */
72
86
  export function databaseCreationMenu() {
73
87
  return {
74
- open: ({ std, blockId, anchor }) => {
88
+ open: ({ std, blockId, anchor, viewId }) => {
75
89
  const picker = std.getOptional(DataSourcePickerProvider);
76
90
  if (!picker)
77
91
  return;
@@ -79,7 +93,7 @@ export function databaseCreationMenu() {
79
93
  options: {
80
94
  title: { text: translateKey(std, ...DATABASE_CREATION_TITLE) },
81
95
  testId: 'database-creation-popover',
82
- items: databaseCreationItems(std, picker, blockId),
96
+ items: databaseCreationItems(std, picker, blockId, viewId),
83
97
  },
84
98
  });
85
99
  },
@@ -8,8 +8,6 @@ export declare const DATABASE_ADD_VIEW_NEW_SOURCE: ChromeWording;
8
8
  export declare const DATABASE_ADD_VIEW_UNTITLED_SOURCE: ChromeWording;
9
9
  /** The third entry: copy a view of another database (labre REQ-DB-2). */
10
10
  export declare const DATABASE_ADD_VIEW_IMPORT: ChromeWording;
11
- /** The popover over a database just inserted, before it has a source. */
12
- export declare const DATABASE_CREATION_TITLE: ChromeWording;
13
11
  /** Asks the host for a new database and connects the block to its source. */
14
12
  export declare const DATABASE_CREATION_NEW_SOURCE: ChromeWording;
15
13
  /** The sources of the databases the host lists, without "New database". */
@@ -21,11 +21,6 @@ export const DATABASE_ADD_VIEW_IMPORT = [
21
21
  'Import a view from another database',
22
22
  ];
23
23
  /* ── The creation popover (ADR 0035 §5, amendment of 2026-10-28) ──────── */
24
- /** The popover over a database just inserted, before it has a source. */
25
- export const DATABASE_CREATION_TITLE = [
26
- 'com.labre.database.creation.title',
27
- 'Connect a source',
28
- ];
29
24
  /** Asks the host for a new database and connects the block to its source. */
30
25
  export const DATABASE_CREATION_NEW_SOURCE = [
31
26
  'com.labre.database.creation.new-source',
@@ -157,7 +152,6 @@ const DATABASE_EDITOR_WORDINGS = [
157
152
  DATABASE_ADD_VIEW_UNTITLED_SOURCE,
158
153
  DATABASE_CREATION_LINK_EXISTING,
159
154
  DATABASE_CREATION_NEW_SOURCE,
160
- DATABASE_CREATION_TITLE,
161
155
  DATABASE_PAGE_HOST_MISSING,
162
156
  PICKER_EMPTY,
163
157
  PICKER_NEW_DATABASE,
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": "1.0.0",
4
+ "version": "1.1.0",
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": "1.0.0",
30
+ "@formicoidea/labre-core": "1.1.0",
31
31
  "@blocksuite/icons": "^2.2.12",
32
32
  "@preact/signals-core": "^1.8.0",
33
33
  "lit": "^3.2.0"