@formicoidea/labre-core-database 2.5.0 → 3.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.
@@ -124,7 +124,10 @@ let DatabasePageHost = (() => {
124
124
  stays in the gutter (at most 24px, the phone's), so nothing at
125
125
  rest is faded. Its layer covers the padding box only: the two
126
126
  layers below it give back the scrollbars, which sit between the
127
- padding box and the border box. */
127
+ padding box and the border box.
128
+ A mask reads the alpha channel only, never the hue, so its opaque
129
+ stops are spelled currentColor: opaque in either theme and not a
130
+ raw colour the dark-chrome ratchet would count (ADR 0039). */
128
131
  --affine-database-page-fade: min(
129
132
  var(--affine-editor-side-padding, 24px),
130
133
  24px
@@ -133,13 +136,13 @@ let DatabasePageHost = (() => {
133
136
  linear-gradient(
134
137
  to right,
135
138
  transparent,
136
- #000 var(--affine-database-page-fade),
137
- #000 calc(100% - var(--affine-database-page-fade)),
139
+ currentColor var(--affine-database-page-fade),
140
+ currentColor calc(100% - var(--affine-database-page-fade)),
138
141
  transparent
139
142
  )
140
143
  padding-box add,
141
- linear-gradient(#000 0 0) border-box exclude,
142
- linear-gradient(#000 0 0) padding-box;
144
+ linear-gradient(currentColor 0 0) border-box exclude,
145
+ linear-gradient(currentColor 0 0) padding-box;
143
146
  }
144
147
  /* The editor takes the height the heading leaves (std gives it 100%,
145
148
  which overflowed by the heading's height: a scrollbar on a short
@@ -1,5 +1,5 @@
1
- import { type MenuConfig, type MenuOptions } from '@formicoidea/labre-core/components/context-menu';
2
- import { type DataSourcePickerSourceNaming } from '@formicoidea/labre-core/shared/services';
1
+ import { type Menu, type MenuConfig, type MenuOptions } from '@formicoidea/labre-core/components/context-menu';
2
+ import { type ChromeWording, type DataSourcePickerSourceNameVerdict, type DataSourcePickerSourceNaming } from '@formicoidea/labre-core/shared/services';
3
3
  import type { BlockStdScope } from '@formicoidea/labre-core/std';
4
4
  export interface NewSourceEntry {
5
5
  name: string;
@@ -9,6 +9,8 @@ export interface NewSourceEntry {
9
9
  }
10
10
  /** The name as an argument only when there is one: a host without naming is called as in 2.0. */
11
11
  export declare const named: (sourceName: string | undefined) => [] | [string];
12
+ export declare const VERDICT_WORDING: Record<DataSourcePickerSourceNameVerdict, ChromeWording>;
13
+ export declare function verdictOf(naming: DataSourcePickerSourceNaming, name: string): DataSourcePickerSourceNameVerdict;
12
14
  /**
13
15
  * Every entry that creates a source (ADR 0035 amendment of 2026-10-30):
14
16
  * "New source", "New database", "With a new source", "New empty source".
@@ -24,6 +26,11 @@ export declare function newSourceEntry(std: BlockStdScope | undefined, naming: D
24
26
  * searchable.
25
27
  */
26
28
  export declare function sourceSearch(std: BlockStdScope | undefined): MenuOptions['search'];
29
+ /**
30
+ * Whether `suggest` has settled for `parent`, read once per menu: `check`
31
+ * answers against the names the last `suggest` read.
32
+ */
33
+ export declare function namesReadFor(parent: Menu, naming: DataSourcePickerSourceNaming): boolean;
27
34
  /**
28
35
  * "Create source “typed”" at the end of a searched list of sources (labre
29
36
  * recette of 2.1): drawn while the search holds a name no listed source
@@ -3,16 +3,16 @@ 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
- import { styleMap } from 'lit/directives/style-map.js';
6
+ import { styleMap } from '@formicoidea/labre-core/global/lit';
7
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
- const VERDICT_WORDING = {
10
+ export const VERDICT_WORDING = {
11
11
  ok: SOURCE_NAME_OK,
12
12
  taken: SOURCE_NAME_TAKEN,
13
13
  empty: SOURCE_NAME_EMPTY,
14
14
  };
15
- function verdictOf(naming, name) {
15
+ export function verdictOf(naming, name) {
16
16
  try {
17
17
  return naming.check(name);
18
18
  }
@@ -140,10 +140,13 @@ export function sourceSearch(std) {
140
140
  : SOURCE_SEARCH_PLACEHOLDER[1],
141
141
  };
142
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.
143
+ // Per menu: the host's names are read once it opens (`suggest`).
145
144
  const namesRead = new WeakMap();
146
- function namesReadFor(parent, naming) {
145
+ /**
146
+ * Whether `suggest` has settled for `parent`, read once per menu: `check`
147
+ * answers against the names the last `suggest` read.
148
+ */
149
+ export function namesReadFor(parent, naming) {
147
150
  let read$ = namesRead.get(parent);
148
151
  if (!read$) {
149
152
  const created$ = signal(false);
@@ -65,6 +65,10 @@ export declare const SOURCE_NAME_OK: ChromeWording;
65
65
  export declare const SOURCE_NAME_TAKEN: ChromeWording;
66
66
  export declare const SOURCE_NAME_CREATE: ChromeWording;
67
67
  export declare const SOURCE_NAME_EMPTY: ChromeWording;
68
+ /** First in the view settings' "Source" list, with the host's `renameSource`. */
69
+ export declare const SOURCE_RENAME_ENTRY: ChromeWording;
70
+ /** Under the field when `renameSource` rejects (the host's refusals carry their own sentence). */
71
+ export declare const SOURCE_RENAME_FAILED: ChromeWording;
68
72
  export declare const SOURCE_SEARCH_PLACEHOLDER: ChromeWording;
69
73
  /** `{{name}}` is the name as typed in the search field. */
70
74
  export declare const SOURCE_SEARCH_CREATE: ChromeWording;
@@ -144,6 +144,17 @@ export const SOURCE_NAME_EMPTY = [
144
144
  'com.labre.database.source-name.empty',
145
145
  'Give the source a name.',
146
146
  ];
147
+ /* ── Renaming the view's source (issue #576) ──────────────────────────── */
148
+ /** First in the view settings' "Source" list, with the host's `renameSource`. */
149
+ export const SOURCE_RENAME_ENTRY = [
150
+ 'com.labre.database.source-rename.entry',
151
+ 'Rename source',
152
+ ];
153
+ /** Under the field when `renameSource` rejects (the host's refusals carry their own sentence). */
154
+ export const SOURCE_RENAME_FAILED = [
155
+ 'com.labre.database.source-rename.failed',
156
+ 'The source could not be renamed.',
157
+ ];
147
158
  /* ── Searching a list of sources (labre recette of 2.1) ───────────────── */
148
159
  export const SOURCE_SEARCH_PLACEHOLDER = [
149
160
  'com.labre.database.source-search.placeholder',
@@ -186,6 +197,8 @@ const DATABASE_EDITOR_WORDINGS = [
186
197
  SOURCE_NAME_OK,
187
198
  SOURCE_NAME_PLACEHOLDER,
188
199
  SOURCE_NAME_TAKEN,
200
+ SOURCE_RENAME_ENTRY,
201
+ SOURCE_RENAME_FAILED,
189
202
  SOURCE_SEARCH_CREATE,
190
203
  SOURCE_SEARCH_PLACEHOLDER,
191
204
  VIEW_MENU_IMPORT,
@@ -0,0 +1,28 @@
1
+ import { type MenuConfig } from '@formicoidea/labre-core/components/context-menu';
2
+ import { type DataSourcePickerRenameResult, type DataSourcePickerSourceNaming } from '@formicoidea/labre-core/shared/services';
3
+ import type { BlockStdScope } from '@formicoidea/labre-core/std';
4
+ export interface RenameSourceTarget {
5
+ /** The source's name as stored, read each time the step opens ('' when untitled). */
6
+ currentName: () => string;
7
+ /** The host's verb, bound to the view's database and source. */
8
+ rename: (name: string) => Promise<DataSourcePickerRenameResult>;
9
+ /** The host's naming rule, to warn while typing; its verb still decides. */
10
+ naming: DataSourcePickerSourceNaming | undefined;
11
+ }
12
+ /**
13
+ * "Rename source", first in the view settings' "Source" list (issue #576,
14
+ * ADR 0035 amendment of 2026-11-04): a step in the same cascade, as
15
+ * `newSourceEntry` names a new source, opening on the current name. The
16
+ * library writes nothing; the host's `renameSource` renames and its lists
17
+ * follow.
18
+ *
19
+ * Saved on Enter ONLY. The context menu's input calls `onComplete` and
20
+ * blurs on Escape, and the property rename saves on blur, so Escape saves
21
+ * there; here Escape must cancel, so neither `onComplete` nor `onBlur` is
22
+ * given. An unchanged name closes the step without a call; an empty one is
23
+ * refused before the host is asked. While the host answers, the field is
24
+ * dimmed and a second Enter is ignored; a refusal shows the host's message
25
+ * under the field, a rejection a generic one; an answer arriving after the
26
+ * step closed changes nothing.
27
+ */
28
+ export declare function renameSourceEntry(std: BlockStdScope, target: RenameSourceTarget): MenuConfig;
@@ -0,0 +1,135 @@
1
+ import { foldForSearch, menu, } from '@formicoidea/labre-core/components/context-menu';
2
+ import { translateKey, } from '@formicoidea/labre-core/shared/services';
3
+ import { EditIcon } from '@blocksuite/icons/lit';
4
+ import { computed, signal } from '@preact/signals-core';
5
+ import { html } from 'lit';
6
+ import { styleMap } from '@formicoidea/labre-core/global/lit';
7
+ import { namesReadFor, VERDICT_WORDING, verdictOf, } from '../new-source-entry.js';
8
+ import { SOURCE_NAME_EMPTY, SOURCE_NAME_PLACEHOLDER, SOURCE_RENAME_ENTRY, SOURCE_RENAME_FAILED, } from '../translations.js';
9
+ const TEST_ID = 'data-source-picker-rename-source';
10
+ /**
11
+ * "Rename source", first in the view settings' "Source" list (issue #576,
12
+ * ADR 0035 amendment of 2026-11-04): a step in the same cascade, as
13
+ * `newSourceEntry` names a new source, opening on the current name. The
14
+ * library writes nothing; the host's `renameSource` renames and its lists
15
+ * follow.
16
+ *
17
+ * Saved on Enter ONLY. The context menu's input calls `onComplete` and
18
+ * blurs on Escape, and the property rename saves on blur, so Escape saves
19
+ * there; here Escape must cancel, so neither `onComplete` nor `onBlur` is
20
+ * given. An unchanged name closes the step without a call; an empty one is
21
+ * refused before the host is asked. While the host answers, the field is
22
+ * dimmed and a second Enter is ignored; a refusal shows the host's message
23
+ * under the field, a rejection a generic one; an answer arriving after the
24
+ * step closed changes nothing.
25
+ */
26
+ export function renameSourceEntry(std, target) {
27
+ const t = (wording) => translateKey(std, ...wording);
28
+ return parent => {
29
+ const typed$ = signal(undefined);
30
+ const refusal$ = signal(undefined);
31
+ const pending$ = signal(false);
32
+ let opened;
33
+ const original = () => (opened ??= target.currentName());
34
+ const name$ = computed(() => typed$.value ?? original());
35
+ // Never rejects: every outcome, a throwing host included, is caught here.
36
+ const ask = async (step, name) => {
37
+ pending$.value = true;
38
+ refusal$.value = undefined;
39
+ try {
40
+ const result = await target.rename(name);
41
+ if (step.closed)
42
+ return;
43
+ if (result.ok) {
44
+ step.close();
45
+ return;
46
+ }
47
+ refusal$.value = result.message || t(SOURCE_RENAME_FAILED);
48
+ }
49
+ catch (error) {
50
+ console.error(error);
51
+ if (!step.closed)
52
+ refusal$.value = t(SOURCE_RENAME_FAILED);
53
+ }
54
+ finally {
55
+ pending$.value = false;
56
+ }
57
+ };
58
+ const save = (step) => {
59
+ if (pending$.peek())
60
+ return;
61
+ const name = name$.peek().trim();
62
+ if (name === original().trim()) {
63
+ step.close();
64
+ return;
65
+ }
66
+ if (!name) {
67
+ refusal$.value = t(SOURCE_NAME_EMPTY);
68
+ return;
69
+ }
70
+ void ask(step, name);
71
+ };
72
+ const field = step => menu.input({
73
+ initialValue: original(),
74
+ placeholder: t(SOURCE_NAME_PLACEHOLDER),
75
+ style: pending$.value ? { opacity: '0.5', pointerEvents: 'none' } : {},
76
+ onChange: value => {
77
+ typed$.value = value;
78
+ refusal$.value = undefined;
79
+ },
80
+ onEnter: () => {
81
+ save(step);
82
+ // The step closes itself once the host has answered.
83
+ return false;
84
+ },
85
+ })(step);
86
+ // The host's refusal, else its naming rule's early warning. The source's
87
+ // own name, case and accents aside, is never warned about: a rule that
88
+ // counts every live source would call it taken.
89
+ const status = step => {
90
+ const message = refusal$.value ?? warning(step);
91
+ if (!message)
92
+ return;
93
+ return html `<div
94
+ role="status"
95
+ data-testid="${TEST_ID}-status"
96
+ style=${styleMap({
97
+ padding: '0 6px',
98
+ fontSize: '12px',
99
+ lineHeight: '20px',
100
+ color: 'var(--affine-error-color)',
101
+ })}
102
+ >
103
+ ${message}
104
+ </div>`;
105
+ };
106
+ const warning = (step) => {
107
+ const { naming } = target;
108
+ const name = name$.value;
109
+ if (!naming || typed$.value === undefined)
110
+ return;
111
+ if (foldForSearch(name.trim()) === foldForSearch(original().trim())) {
112
+ return;
113
+ }
114
+ if (!namesReadFor(step, naming))
115
+ return;
116
+ const verdict = verdictOf(naming, name);
117
+ return verdict === 'ok' ? undefined : t(VERDICT_WORDING[verdict]);
118
+ };
119
+ return menu.subMenu({
120
+ name: t(SOURCE_RENAME_ENTRY),
121
+ prefix: EditIcon(),
122
+ testId: TEST_ID,
123
+ options: {
124
+ testId: `${TEST_ID}-step`,
125
+ // Each opening starts again from the name as it is now.
126
+ onClose: () => {
127
+ opened = undefined;
128
+ typed$.value = undefined;
129
+ refusal$.value = undefined;
130
+ },
131
+ items: [field, status],
132
+ },
133
+ })(parent);
134
+ };
135
+ }
@@ -50,6 +50,13 @@ export declare function currentSourceTitle(std: BlockStdScope, dataSource: Hoste
50
50
  * labelled with their database; the check matches database and source; a
51
51
  * pick of another database's source stores it on the view. "Create source"
52
52
  * still creates in this block's database.
53
+ *
54
+ * "Rename source" heads the list when the host gives `renameSource` (issue
55
+ * #576): it renames the source the view reads, never another one, and only
56
+ * in the block's own database (a view reading another database's source,
57
+ * under `crossDatabaseViews`, is not offered it: renaming across databases
58
+ * is left to the host's own settings). Absent, on a read-only page, the
59
+ * name stays read-only.
53
60
  */
54
61
  export declare function popChangeSourcePicker(std: BlockStdScope, target: PopupTarget, change: ChangeSourceTarget, reopen: () => void): MenuHandler;
55
62
  /**
@@ -6,6 +6,7 @@ import { html } from 'lit';
6
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
+ import { renameSourceEntry } from './rename-source-entry.js';
9
10
  import { databaseIdOf } from '../view-transfer/import-view.js';
10
11
  import { crossDatabaseViews, databaseLabel, inDatabase, isViewSource, workspaceSources, } from '../workspace-sources.js';
11
12
  /**
@@ -50,6 +51,13 @@ export function currentSourceTitle(std, dataSource) {
50
51
  * labelled with their database; the check matches database and source; a
51
52
  * pick of another database's source stores it on the view. "Create source"
52
53
  * still creates in this block's database.
54
+ *
55
+ * "Rename source" heads the list when the host gives `renameSource` (issue
56
+ * #576): it renames the source the view reads, never another one, and only
57
+ * in the block's own database (a view reading another database's source,
58
+ * under `crossDatabaseViews`, is not offered it: renaming across databases
59
+ * is left to the host's own settings). Absent, on a read-only page, the
60
+ * name stays read-only.
53
61
  */
54
62
  export function popChangeSourcePicker(std, target, change, reopen) {
55
63
  const { dataSource, databaseId, picker, viewId } = change;
@@ -64,6 +72,14 @@ export function popChangeSourcePicker(std, target, change, reopen) {
64
72
  : undefined;
65
73
  const untitled = translateKey(std, ...DATABASE_ADD_VIEW_UNTITLED_SOURCE);
66
74
  const untitledDatabase = translateKey(std, ...DOC_UNTITLED);
75
+ const renameSource = picker.renameSource;
76
+ const rename = renameSource && currentDatabase === undefined
77
+ ? renameSourceEntry(std, {
78
+ currentName: () => dataSource.schema$.peek()?.props.title.toString() ?? '',
79
+ rename: name => renameSource.call(picker, databaseId, current, name),
80
+ naming: picker.sourceName,
81
+ })
82
+ : undefined;
67
83
  return popMenu(target, {
68
84
  options: {
69
85
  title: { text: translateKey(std, ...PICKER_TITLE), onBack: reopen },
@@ -72,6 +88,7 @@ export function popChangeSourcePicker(std, target, change, reopen) {
72
88
  items: [
73
89
  menu.dynamic(() => {
74
90
  const sources = workspaceSources(list.value, databaseId, across);
91
+ const head = rename && !std.store.readonly ? [rename] : [];
75
92
  const items = sources.map(source => {
76
93
  const selected = isViewSource(source, current, currentDatabase);
77
94
  return menu.action({
@@ -88,8 +105,9 @@ export function popChangeSourcePicker(std, target, change, reopen) {
88
105
  });
89
106
  });
90
107
  if (!createSource || std.store.readonly)
91
- return items;
108
+ return [...head, ...items];
92
109
  return [
110
+ ...head,
93
111
  ...items,
94
112
  typedSourceEntry(std, picker.sourceName, sources.map(source => source.title), {
95
113
  testId: 'data-source-picker-new-source',
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.5.0",
4
+ "version": "3.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": "2.5.0",
30
+ "@formicoidea/labre-core": "3.1.0",
31
31
  "@blocksuite/icons": "^2.2.12",
32
32
  "@preact/signals-core": "^1.8.0",
33
33
  "lit": "^3.2.0"