@formicoidea/labre-core-database 1.0.0 → 2.0.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.
- package/dist/creation-popover.d.ts +11 -5
- package/dist/creation-popover.js +26 -12
- package/dist/database-page/database-page-root.js +16 -1
- package/dist/translations.d.ts +0 -2
- package/dist/translations.js +0 -6
- package/dist/view-transfer/change-source.js +1 -4
- package/dist/view-transfer/remap-view.js +12 -2
- package/package.json +2 -2
|
@@ -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
|
|
10
|
-
*
|
|
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
|
-
*
|
|
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;
|
package/dist/creation-popover.js
CHANGED
|
@@ -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,
|
|
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
|
|
19
|
-
*
|
|
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
|
-
//
|
|
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
|
-
*
|
|
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
|
},
|
|
@@ -90,10 +90,25 @@ export class DatabasePageRoot extends BlockComponent {
|
|
|
90
90
|
affine-database-page-root:has(dv-table-view-ui[data-page-layout]) {
|
|
91
91
|
width: max-content;
|
|
92
92
|
min-width: 100%;
|
|
93
|
+
/* Widened, the root is no longer centred by its auto margins: it
|
|
94
|
+
pads its left side by what centring gave the page heading (whose
|
|
95
|
+
container in doc-title is the same max-width, centred in the
|
|
96
|
+
viewport), so the heading, the view bar and the rows share one left
|
|
97
|
+
edge and the table grows to the right (labre recette of 1.1). The
|
|
98
|
+
block's sticky view bar reads the same inset. */
|
|
99
|
+
--affine-database-page-inset: max(
|
|
100
|
+
0px,
|
|
101
|
+
calc((100cqw - var(--affine-editor-width, 100cqw)) / 2)
|
|
102
|
+
);
|
|
103
|
+
padding-left: calc(
|
|
104
|
+
var(--affine-database-page-inset) +
|
|
105
|
+
var(--affine-editor-side-padding, 24px)
|
|
106
|
+
);
|
|
93
107
|
}
|
|
94
108
|
/* A phone keeps the page root's narrow padding (page-root-block.ts). */
|
|
95
109
|
@container viewport (width <= 640px) {
|
|
96
|
-
affine-database-page-root
|
|
110
|
+
affine-database-page-root,
|
|
111
|
+
affine-database-page-root:has(dv-table-view-ui[data-page-layout]) {
|
|
97
112
|
padding-left: 24px;
|
|
98
113
|
padding-right: 24px;
|
|
99
114
|
}
|
package/dist/translations.d.ts
CHANGED
|
@@ -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". */
|
package/dist/translations.js
CHANGED
|
@@ -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,
|
|
@@ -53,10 +53,7 @@ export function changeViewSource(dataSource, viewId, sourceId, added) {
|
|
|
53
53
|
? schemaProperties(fromSchema)
|
|
54
54
|
: sourceProperties(dataSource);
|
|
55
55
|
const to = schemaProperties(target.schema);
|
|
56
|
-
|
|
57
|
-
// (inside `remapView`) refuses; its plain JSON is what the view stores.
|
|
58
|
-
const plain = JSON.parse(JSON.stringify(view));
|
|
59
|
-
const { data } = remapView(plain, from, to, defaultMapping(from, to));
|
|
56
|
+
const { data } = remapView(view, from, to, defaultMapping(from, to));
|
|
60
57
|
// The block's `updateView` merges over the stored view: a key the remap
|
|
61
58
|
// removed (a grouping by a property the target lacks) is cleared with an
|
|
62
59
|
// own `undefined`, as the group trait's `groupBySet(undefined)` clears it.
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A plain, JSON-safe copy of a stored view. A host may hand the store's
|
|
3
|
+
* live view (a reactive `Proxy` over the block's props), which
|
|
4
|
+
* `structuredClone` refuses with a `DataCloneError` (labre hit it on
|
|
5
|
+
* import); view data is JSON by construction (ADR 0035 §8), so a JSON
|
|
6
|
+
* round-trip copies every key a view can hold, whatever the input.
|
|
7
|
+
*/
|
|
8
|
+
function plainCopy(view) {
|
|
9
|
+
return JSON.parse(JSON.stringify(view));
|
|
10
|
+
}
|
|
1
11
|
const OPTION_TYPES = new Set(['select', 'multi-select']);
|
|
2
12
|
/** The `header` keys of the presets that name a property. */
|
|
3
13
|
const HEADER_KEYS = ['titleColumn', 'iconColumn', 'imageColumn', 'coverColumn'];
|
|
@@ -32,7 +42,7 @@ function isRecord(value) {
|
|
|
32
42
|
* A mapping onto a property that `to` does not have counts as ignored.
|
|
33
43
|
*/
|
|
34
44
|
export function remapView(view, from, to, mapping) {
|
|
35
|
-
const data =
|
|
45
|
+
const data = plainCopy(view);
|
|
36
46
|
delete data.id;
|
|
37
47
|
delete data.name;
|
|
38
48
|
delete data.sourceId;
|
|
@@ -239,7 +249,7 @@ export function defaultMapping(from, to) {
|
|
|
239
249
|
* REQ-DB-4 names them part of a template.
|
|
240
250
|
*/
|
|
241
251
|
export function viewTemplateData(view) {
|
|
242
|
-
const data =
|
|
252
|
+
const data = plainCopy(view);
|
|
243
253
|
delete data.id;
|
|
244
254
|
delete data.sourceId;
|
|
245
255
|
delete data.sort;
|
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
|
+
"version": "2.0.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": "
|
|
30
|
+
"@formicoidea/labre-core": "2.0.0",
|
|
31
31
|
"@blocksuite/icons": "^2.2.12",
|
|
32
32
|
"@preact/signals-core": "^1.8.0",
|
|
33
33
|
"lit": "^3.2.0"
|