@formicoidea/labre-core-database 4.0.0 → 4.2.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,4 +1,4 @@
1
- import { connectDatabaseToSource, DATABASE_CREATION_TITLE, reconnectDatabaseView, } from '@formicoidea/labre-core/blocks/database';
1
+ import { connectDatabaseToSource, DATABASE_CREATION_TITLE, placeViewThroughHost, 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 } from '@blocksuite/icons/lit';
@@ -27,15 +27,34 @@ export function databaseCreationItems(std, picker, blockId, viewId) {
27
27
  const connect = (database, sourceId) => {
28
28
  const model = databaseModel(std, blockId);
29
29
  if (!model)
30
- return;
30
+ return false;
31
31
  if (model.props.externalSourceId === undefined) {
32
- connectDatabaseToSource(std, model, { database, sourceId });
33
- return;
32
+ return connectDatabaseToSource(std, model, { database, sourceId });
34
33
  }
35
34
  const view = viewId ?? model.props.views[0]?.id;
36
- if (view) {
37
- reconnectDatabaseView(std, model, { database, sourceId, viewId: view });
38
- }
35
+ return view
36
+ ? reconnectDatabaseView(std, model, { database, sourceId, viewId: view })
37
+ : false;
38
+ };
39
+ // An existing source goes through the host's `placeView` (issue #701);
40
+ // one the host just created for this gesture does not.
41
+ const connectExisting = (database, sourceId) => {
42
+ const model = databaseModel(std, blockId);
43
+ const reconnects = model?.props.externalSourceId !== undefined;
44
+ const view = reconnects ? (viewId ?? model?.props.views[0]?.id) : undefined;
45
+ placeViewThroughHost({
46
+ picker,
47
+ store: std.store,
48
+ ref: {
49
+ gesture: 'connect',
50
+ databaseId: database.id,
51
+ sourceId,
52
+ docId: std.store.id,
53
+ blockId,
54
+ ...(view === undefined ? {} : { viewId: view }),
55
+ },
56
+ placeNow: () => connect(database, sourceId),
57
+ });
39
58
  };
40
59
  const createDatabase = picker.createDatabase;
41
60
  const list = picker.list();
@@ -67,7 +86,8 @@ export function databaseCreationItems(std, picker, blockId, viewId) {
67
86
  testId: 'database-creation-link-existing',
68
87
  items: dataSourcePickerItems(std, picker, {
69
88
  offerCreate: false,
70
- onPick: ({ database, sourceId }) => connect(database, sourceId),
89
+ // `offerCreate: false`: every pick here is an existing source.
90
+ onPick: ({ database, sourceId }) => connectExisting(database, sourceId),
71
91
  }),
72
92
  },
73
93
  }),
@@ -36,6 +36,14 @@ export declare class DatabasePageHost extends DatabasePageHost_base {
36
36
  connectedCallback(): void;
37
37
  disconnectedCallback(): void;
38
38
  protected willUpdate(changed: PropertyValues<this>): void;
39
+ /**
40
+ * The page's editor host is a tab stop of its own (`tabindex="0"`, set on
41
+ * connect for the keys of a block selection), and the root keeps the Tab
42
+ * pressed there (`fallbackKeymap`): between the heading and the views, Tab
43
+ * from the title stopped on it, and so did Shift+Tab from the view toolbar
44
+ * (#678). Out of the tab order, the host stays focusable by script.
45
+ */
46
+ protected updated(changed: PropertyValues<this>): void;
39
47
  render(): import("lit-html").TemplateResult<1>;
40
48
  accessor store: BlockStdOptions['store'];
41
49
  /** The page-scope view extensions the host mounts its page editor with. */
@@ -203,6 +203,8 @@ let DatabasePageHost = (() => {
203
203
  this.addEventListener('dragover', stopFileDrop, true);
204
204
  this.addEventListener('drop', stopFileDrop, true);
205
205
  this.holdSelection();
206
+ // Reconnected, the editor host takes its tab stop back: drop it again.
207
+ this.requestUpdate();
206
208
  }
207
209
  disconnectedCallback() {
208
210
  super.disconnectedCallback();
@@ -232,6 +234,19 @@ let DatabasePageHost = (() => {
232
234
  // `std.render()` builds a new editor host each call: once per editor.
233
235
  this.editorHost = this._std?.render();
234
236
  }
237
+ /**
238
+ * The page's editor host is a tab stop of its own (`tabindex="0"`, set on
239
+ * connect for the keys of a block selection), and the root keeps the Tab
240
+ * pressed there (`fallbackKeymap`): between the heading and the views, Tab
241
+ * from the title stopped on it, and so did Shift+Tab from the view toolbar
242
+ * (#678). Out of the tab order, the host stays focusable by script.
243
+ */
244
+ updated(changed) {
245
+ super.updated(changed);
246
+ if (this.editorHost && this.editorHost.tabIndex !== -1) {
247
+ this.editorHost.tabIndex = -1;
248
+ }
249
+ }
235
250
  render() {
236
251
  // The page viewport the page extensions, and `<doc-title>`, look for
237
252
  // above their host.
@@ -1,4 +1,4 @@
1
- import { insertLinkedDatabaseView } from '@formicoidea/labre-core/blocks/database';
1
+ import { insertLinkedDatabaseView, placeViewThroughHost, } from '@formicoidea/labre-core/blocks/database';
2
2
  import { popupTargetFromElement } from '@formicoidea/labre-core/components/context-menu';
3
3
  import { getSelectedModelsCommand } from '@formicoidea/labre-core/shared/commands';
4
4
  import { DataSourcePickerProvider } from '@formicoidea/labre-core/shared/services';
@@ -36,13 +36,28 @@ export const linkedViewSlashMenuConfig = {
36
36
  if (!after || !anchor)
37
37
  return;
38
38
  popDataSourcePicker(std, picker, popupTargetFromElement(anchor), {
39
- onPick: ({ database, sourceId }) => {
40
- insertLinkedDatabaseView(std, {
39
+ onPick: ({ database, sourceId, source }) => {
40
+ const insert = () => insertLinkedDatabaseView(std, {
41
41
  after,
42
42
  database,
43
43
  sourceId,
44
44
  viewType: 'table',
45
45
  removeEmptyLine: true,
46
+ }) !== null;
47
+ // A source the host just created for this pick is no placement
48
+ // to confirm (issue #701).
49
+ placeViewThroughHost({
50
+ picker,
51
+ store: std.store,
52
+ ref: source === 'new'
53
+ ? null
54
+ : {
55
+ gesture: 'linked-view',
56
+ databaseId: database.id,
57
+ sourceId,
58
+ docId: std.store.id,
59
+ },
60
+ placeNow: insert,
46
61
  });
47
62
  },
48
63
  });
@@ -1,4 +1,4 @@
1
- import { HostedDataSourceBase, viewDatabaseId, } from '@formicoidea/labre-core/blocks/database';
1
+ import { HostedDataSourceBase, placeViewThroughHost, viewDatabaseId, } from '@formicoidea/labre-core/blocks/database';
2
2
  import { menu } from '@formicoidea/labre-core/components/context-menu';
3
3
  import { DataSourcePickerProvider, DOC_UNTITLED, translateKey, } from '@formicoidea/labre-core/shared/services';
4
4
  import { viewDefaultName, } from '@formicoidea/labre-core/data-view';
@@ -163,11 +163,32 @@ export function databaseAddViewMenu(picker) {
163
163
  testId: 'database-add-view-preset',
164
164
  prefix: html `<uni-lit .uni=${meta.renderer.icon}></uni-lit>`,
165
165
  select: () => {
166
- if (source?.databaseId === undefined) {
167
- addViewOnSource(context, dataSource, meta.type, source?.sourceId);
166
+ const addNow = () => {
167
+ if (source?.databaseId === undefined) {
168
+ return !!addViewOnSource(context, dataSource, meta.type, source?.sourceId);
169
+ }
170
+ return !!addViewOnSource(context, dataSource, meta.type, source.sourceId, 'existing', source.databaseId);
171
+ };
172
+ const model = dataSource.hostModel;
173
+ const databaseId = source?.databaseId ?? model.props.externalSourceId;
174
+ if (!hostPicker?.placeView || databaseId === undefined) {
175
+ addNow();
168
176
  return;
169
177
  }
170
- addViewOnSource(context, dataSource, meta.type, source.sourceId, 'existing', source.databaseId);
178
+ placeViewThroughHost({
179
+ picker: hostPicker,
180
+ store: model.store,
181
+ ref: {
182
+ gesture: 'add-view',
183
+ databaseId,
184
+ ...(source?.sourceId === undefined
185
+ ? {}
186
+ : { sourceId: source.sourceId }),
187
+ docId: model.store.id,
188
+ blockId: model.id,
189
+ },
190
+ placeNow: addNow,
191
+ });
171
192
  },
172
193
  }));
173
194
  if (shape.kind === 'presets') {
@@ -1,4 +1,4 @@
1
- import { HostedDataSourceBase } from '@formicoidea/labre-core/blocks/database';
1
+ import { HostedDataSourceBase, placeViewThroughHost, } from '@formicoidea/labre-core/blocks/database';
2
2
  import { menu, popMenu, } from '@formicoidea/labre-core/components/context-menu';
3
3
  import { DataSourcePickerProvider, DOC_UNTITLED, translateKey, } from '@formicoidea/labre-core/shared/services';
4
4
  import { ArrowRightSmallIcon, DatabaseTableViewIcon, } from '@blocksuite/icons/lit';
@@ -100,7 +100,19 @@ export function popChangeSourcePicker(std, target, change, reopen) {
100
100
  select: () => {
101
101
  if (selected)
102
102
  return;
103
- changeViewSource(dataSource, viewId, source.sourceId, 'existing', ...inDatabase(source.databaseId));
103
+ placeViewThroughHost({
104
+ picker,
105
+ store: std.store,
106
+ ref: {
107
+ gesture: 'change-source',
108
+ databaseId: source.databaseId ?? databaseId,
109
+ sourceId: source.sourceId,
110
+ docId: std.store.id,
111
+ blockId: dataSource.hostModel.id,
112
+ viewId,
113
+ },
114
+ placeNow: () => changeViewSource(dataSource, viewId, source.sourceId, 'existing', ...inDatabase(source.databaseId)),
115
+ });
104
116
  },
105
117
  });
106
118
  });
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": "4.0.0",
4
+ "version": "4.2.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": "4.0.0",
30
+ "@formicoidea/labre-core": "4.2.0",
31
31
  "@blocksuite/icons": "^2.2.12",
32
32
  "@preact/signals-core": "^1.8.0",
33
33
  "lit": "^3.2.0"