@formicoidea/labre-core-database 0.49.0 → 0.50.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,5 +1,5 @@
1
1
  import { DataSourcePickerProvider, } from '@formicoidea/labre-core/shared/services';
2
- import { PROPERTIES_PANEL_TITLE, VIEW_MENU_GROUP, VIEW_MENU_IMPORT, VIEW_MENU_LAYOUT, VIEW_MENU_OPEN_IN, VIEW_MENU_SAVE_TEMPLATE, } from '../translations.js';
2
+ import { PROPERTIES_PANEL_TITLE, VIEW_MENU_COLOR_RULES, VIEW_MENU_GROUP, VIEW_MENU_IMPORT, VIEW_MENU_LAYOUT, VIEW_MENU_OPEN_IN, VIEW_MENU_SAVE_TEMPLATE, } from '../translations.js';
3
3
  import { canImportView, currentViewTemplate, requestViewImport, } from '../view-transfer/import-view.js';
4
4
  /** The current view's options button on the page: what knows the view. */
5
5
  function viewOptions(std, hostBlockId) {
@@ -36,6 +36,7 @@ export function databasePageViewCommands(hostBlockId) {
36
36
  setting(hostBlockId, 'group', VIEW_MENU_GROUP, 1),
37
37
  setting(hostBlockId, 'open-in', VIEW_MENU_OPEN_IN, 2),
38
38
  setting(hostBlockId, 'properties', PROPERTIES_PANEL_TITLE, 3),
39
+ setting(hostBlockId, 'color-rules', VIEW_MENU_COLOR_RULES, 4),
39
40
  {
40
41
  id: 'database.view.save-template',
41
42
  owner: 'core',
@@ -44,7 +45,7 @@ export function databasePageViewCommands(hostBlockId) {
44
45
  labelFallback: VIEW_MENU_SAVE_TEMPLATE[1],
45
46
  category: 'view',
46
47
  surfaces: ['view-menu'],
47
- order: 4,
48
+ order: 5,
48
49
  scope: 'page',
49
50
  defaultKeys: { mac: [], other: [] },
50
51
  when: std => {
@@ -71,7 +72,7 @@ export function databasePageViewCommands(hostBlockId) {
71
72
  labelFallback: VIEW_MENU_IMPORT[1],
72
73
  category: 'transfer',
73
74
  surfaces: ['view-menu'],
74
- order: 5,
75
+ order: 6,
75
76
  scope: 'page',
76
77
  defaultKeys: { mac: [], other: [] },
77
78
  when: std => {
@@ -18,16 +18,16 @@ declare const DatabasePropertiesPanel_base: typeof ShadowlessElement & import("@
18
18
  * request). It draws nothing of its own beyond the shared side-panel header:
19
19
  * the list is the data-view's own `data-view-properties-setting`, the very
20
20
  * list the view options' "Properties" pops, so hiding, showing and
21
- * reordering write through the same `Property` methods, once.
21
+ * reordering write through the same `Property` methods, once. A row's click
22
+ * opens the property's menu (the table header's: rename, type, duplicate,
23
+ * delete) and "New property" adds one, both from that list.
22
24
  *
23
25
  * A host mounts it with `std` (the editor that shows the database) and
24
26
  * `request`; it follows the block as it mounts and unmounts. Read-only, the
25
27
  * list is drawn and inert.
26
28
  *
27
- * ponytail: the panel lists the view's properties and their visibility only;
28
- * rename, retype and "+ property" stay in the table header's own menu, and
29
- * the host-panels verbs of §10 (for a host that draws its own panel) are not
30
- * written: the Labre app mounts this element. Add them to
29
+ * ponytail: the host-panels verbs of §10 (for a host that draws its own
30
+ * panel) are not written: the Labre app mounts this element. Add them to
31
31
  * `@labre/affine/host-panels` when a host draws its own.
32
32
  */
33
33
  export declare class DatabasePropertiesPanel extends DatabasePropertiesPanel_base {
@@ -36,6 +36,7 @@ export declare class DatabasePropertiesPanel extends DatabasePropertiesPanel_bas
36
36
  private readonly _mounts$;
37
37
  connectedCallback(): void;
38
38
  private _t;
39
+ private readonly _wording;
39
40
  private readonly _close;
40
41
  private _renderHeader;
41
42
  private _renderBody;
@@ -65,16 +65,16 @@ export function propertiesPanelView(std, request) {
65
65
  * request). It draws nothing of its own beyond the shared side-panel header:
66
66
  * the list is the data-view's own `data-view-properties-setting`, the very
67
67
  * list the view options' "Properties" pops, so hiding, showing and
68
- * reordering write through the same `Property` methods, once.
68
+ * reordering write through the same `Property` methods, once. A row's click
69
+ * opens the property's menu (the table header's: rename, type, duplicate,
70
+ * delete) and "New property" adds one, both from that list.
69
71
  *
70
72
  * A host mounts it with `std` (the editor that shows the database) and
71
73
  * `request`; it follows the block as it mounts and unmounts. Read-only, the
72
74
  * list is drawn and inert.
73
75
  *
74
- * ponytail: the panel lists the view's properties and their visibility only;
75
- * rename, retype and "+ property" stay in the table header's own menu, and
76
- * the host-panels verbs of §10 (for a host that draws its own panel) are not
77
- * written: the Labre app mounts this element. Add them to
76
+ * ponytail: the host-panels verbs of §10 (for a host that draws its own
77
+ * panel) are not written: the Labre app mounts this element. Add them to
78
78
  * `@labre/affine/host-panels` when a host draws its own.
79
79
  */
80
80
  let DatabasePropertiesPanel = (() => {
@@ -222,6 +222,7 @@ let DatabasePropertiesPanel = (() => {
222
222
  <div class="affine-database-properties-panel-list" ?inert=${readonly}>
223
223
  <data-view-properties-setting
224
224
  .view=${view}
225
+ .wording=${this._wording}
225
226
  ></data-view-properties-setting>
226
227
  </div>`;
227
228
  }
@@ -248,6 +249,7 @@ let DatabasePropertiesPanel = (() => {
248
249
  super(...arguments);
249
250
  /** Bumped when a block mounts or unmounts, so the view is looked up again. */
250
251
  this._mounts$ = signal(0);
252
+ this._wording = (wording) => this._t(wording);
251
253
  this._close = () => {
252
254
  this.std.getOptional(PropertiesPanelProvider)?.close();
253
255
  };
@@ -18,8 +18,19 @@ export declare const VIEW_MENU_GROUP: ChromeWording;
18
18
  * is the panel title for the same reason (`PROPERTIES_PANEL_TITLE`).
19
19
  */
20
20
  export declare const VIEW_MENU_OPEN_IN: ChromeWording;
21
+ /**
22
+ * "Conditional colors" (ADR 0036): the view settings' own entry
23
+ * (`DATA_VIEW_COLOR_RULES`), one chrome word, one key, declared once by
24
+ * `@labre/data-view`, so not listed below.
25
+ */
26
+ export declare const VIEW_MENU_COLOR_RULES: ChromeWording;
21
27
  export declare const VIEW_MENU_SAVE_TEMPLATE: ChromeWording;
22
28
  export declare const VIEW_MENU_IMPORT: ChromeWording;
29
+ /**
30
+ * Declared once by `@labre/data-view` (`DATA_VIEW_PROPERTIES`, the list's own
31
+ * title, in its view options popover too), so not listed below. Restated, not
32
+ * imported: this bundle imports core alone (`core-database-boundary`).
33
+ */
23
34
  export declare const PROPERTIES_PANEL_TITLE: ChromeWording;
24
35
  /** The panel's "Show all" over the view's hidden properties. */
25
36
  export declare const PROPERTIES_PANEL_SHOW_ALL: ChromeWording;
@@ -43,6 +43,15 @@ export const VIEW_MENU_OPEN_IN = [
43
43
  'com.labre.data-view.open-in',
44
44
  'Open pages in',
45
45
  ];
46
+ /**
47
+ * "Conditional colors" (ADR 0036): the view settings' own entry
48
+ * (`DATA_VIEW_COLOR_RULES`), one chrome word, one key, declared once by
49
+ * `@labre/data-view`, so not listed below.
50
+ */
51
+ export const VIEW_MENU_COLOR_RULES = [
52
+ 'com.labre.data-view.color-rules',
53
+ 'Conditional colors',
54
+ ];
46
55
  export const VIEW_MENU_SAVE_TEMPLATE = [
47
56
  'com.labre.database.view-menu.save-template',
48
57
  'Save as template',
@@ -52,6 +61,11 @@ export const VIEW_MENU_IMPORT = [
52
61
  'Import a view…',
53
62
  ];
54
63
  /* ── The properties panel (ADR 0035 §9b, issue B10) ────────────────────── */
64
+ /**
65
+ * Declared once by `@labre/data-view` (`DATA_VIEW_PROPERTIES`, the list's own
66
+ * title, in its view options popover too), so not listed below. Restated, not
67
+ * imported: this bundle imports core alone (`core-database-boundary`).
68
+ */
55
69
  export const PROPERTIES_PANEL_TITLE = [
56
70
  'com.labre.database.properties-panel.title',
57
71
  'Properties',
@@ -117,7 +131,6 @@ const DATABASE_EDITOR_WORDINGS = [
117
131
  PICKER_TITLE,
118
132
  PROPERTIES_PANEL_HIDE_ALL,
119
133
  PROPERTIES_PANEL_SHOW_ALL,
120
- PROPERTIES_PANEL_TITLE,
121
134
  PROPERTIES_PANEL_UNAVAILABLE,
122
135
  SLASH_LINKED_VIEW,
123
136
  SLASH_LINKED_VIEW_DESCRIPTION,
@@ -2,14 +2,17 @@ import type { DataSourcePickerProperty } from '@formicoidea/labre-core/shared/se
2
2
  /**
3
3
  * What a copied view lost on the way (labre PRD REQ-DB-2: "the dialog says
4
4
  * so"): conditions of its filter and keys of its sort that pointed at an
5
- * ignored property, the grouping by one, and the columns of the ignored
6
- * properties.
5
+ * ignored property, the grouping by one, the columns of the ignored
6
+ * properties, and its colour rules that read one (ADR 0036; `colorRules`
7
+ * arrived in 0.50, a field a 0.49 reader of this type never reads).
8
+ * Held by `remap-dropped-signature.unit.spec.ts`.
7
9
  */
8
10
  export interface RemapDropped {
9
11
  filters: number;
10
12
  sorts: number;
11
13
  group: boolean;
12
14
  properties: number;
15
+ colorRules: number;
13
16
  }
14
17
  export interface RemappedView {
15
18
  /** The view's data for this database, without `id`, `name` or `sourceId`. */
@@ -35,6 +38,10 @@ type Json = Record<string, unknown>;
35
38
  * kept its id;
36
39
  * - a manual order of rows (`sort.manuallySort`, a group's
37
40
  * `manuallyCardSort`) names rows of the other database: emptied;
41
+ * - a colour rule (`colorRules`, ADR 0036) is rewritten as a filter is,
42
+ * but a rule that loses any condition is removed whole and counted: a
43
+ * rule with fewer conditions would colour rows its author never meant;
44
+ * its colour is the shared palette's and is kept as is;
38
45
  * - `id`, `name` and `sourceId` are left to the caller; any other key is
39
46
  * copied as is.
40
47
  *
@@ -50,6 +57,8 @@ export declare function defaultMapping(from: readonly DataSourcePickerProperty[]
50
57
  /**
51
58
  * What a view template keeps of a view (labre PRD REQ-DB-4): everything but
52
59
  * its filters, its sorts and its manual orders, which belong to one view.
60
+ * Its colour rules (`colorRules`, ADR 0036) are kept, conditions included:
61
+ * REQ-DB-4 names them part of a template.
53
62
  */
54
63
  export declare function viewTemplateData(view: Readonly<Json>): Json;
55
64
  export {};
@@ -22,6 +22,10 @@ function isRecord(value) {
22
22
  * kept its id;
23
23
  * - a manual order of rows (`sort.manuallySort`, a group's
24
24
  * `manuallyCardSort`) names rows of the other database: emptied;
25
+ * - a colour rule (`colorRules`, ADR 0036) is rewritten as a filter is,
26
+ * but a rule that loses any condition is removed whole and counted: a
27
+ * rule with fewer conditions would colour rows its author never meant;
28
+ * its colour is the shared palette's and is kept as is;
25
29
  * - `id`, `name` and `sourceId` are left to the caller; any other key is
26
30
  * copied as is.
27
31
  *
@@ -37,6 +41,7 @@ export function remapView(view, from, to, mapping) {
37
41
  sorts: 0,
38
42
  group: false,
39
43
  properties: 0,
44
+ colorRules: 0,
40
45
  };
41
46
  const fromById = new Map(from.map(p => [p.id, p]));
42
47
  const toById = new Map(to.map(p => [p.id, p]));
@@ -99,7 +104,7 @@ export function remapView(view, from, to, mapping) {
99
104
  }
100
105
  return { value, empty: false };
101
106
  };
102
- const remapFilter = (filter) => {
107
+ const remapFilter = (filter, onDrop) => {
103
108
  if (filter.type === 'group') {
104
109
  const conditions = Array.isArray(filter.conditions)
105
110
  ? filter.conditions
@@ -108,7 +113,7 @@ export function remapView(view, from, to, mapping) {
108
113
  for (const condition of conditions) {
109
114
  if (!isRecord(condition))
110
115
  continue;
111
- const next = remapFilter(condition);
116
+ const next = remapFilter(condition, onDrop);
112
117
  if (next)
113
118
  kept.push(next);
114
119
  }
@@ -118,7 +123,7 @@ export function remapView(view, from, to, mapping) {
118
123
  const sourceId = typeof left?.name === 'string' ? left.name : undefined;
119
124
  const id = target(sourceId);
120
125
  if (!sourceId || !id) {
121
- dropped.filters += 1;
126
+ onDrop();
122
127
  return null;
123
128
  }
124
129
  let empty = false;
@@ -132,24 +137,43 @@ export function remapView(view, from, to, mapping) {
132
137
  })
133
138
  : filter.args;
134
139
  if (empty) {
135
- dropped.filters += 1;
140
+ onDrop();
136
141
  return null;
137
142
  }
138
143
  return { ...filter, left: { ...left, name: id }, args };
139
144
  };
145
+ // A nested group left empty is dropped with its conditions; the root
146
+ // stays, an empty group being "no filter".
147
+ const prune = (group) => ({
148
+ ...group,
149
+ conditions: group.conditions
150
+ .map(c => (c.type === 'group' ? prune(c) : c))
151
+ .filter(c => c.type !== 'group' || c.conditions.length > 0),
152
+ });
140
153
  if (isRecord(data.filter)) {
141
- const root = remapFilter(data.filter);
142
- // A nested group left empty is dropped with its conditions; the root
143
- // stays, an empty group being "no filter".
144
- const prune = (group) => ({
145
- ...group,
146
- conditions: group.conditions
147
- .map(c => (c.type === 'group' ? prune(c) : c))
148
- .filter(c => c.type !== 'group' || c.conditions.length > 0),
154
+ const root = remapFilter(data.filter, () => {
155
+ dropped.filters += 1;
149
156
  });
150
157
  if (root)
151
158
  data.filter = prune(root);
152
159
  }
160
+ if (Array.isArray(data.colorRules)) {
161
+ const kept = [];
162
+ for (const rule of data.colorRules) {
163
+ if (!isRecord(rule) || !isRecord(rule.filter))
164
+ continue;
165
+ let lost = false;
166
+ const filter = remapFilter(rule.filter, () => {
167
+ lost = true;
168
+ });
169
+ if (lost || !filter) {
170
+ dropped.colorRules += 1;
171
+ continue;
172
+ }
173
+ kept.push({ ...rule, filter: prune(filter) });
174
+ }
175
+ data.colorRules = kept;
176
+ }
153
177
  if (isRecord(data.sort)) {
154
178
  const sortBy = Array.isArray(data.sort.sortBy) ? data.sort.sortBy : [];
155
179
  const kept = [];
@@ -211,6 +235,8 @@ export function defaultMapping(from, to) {
211
235
  /**
212
236
  * What a view template keeps of a view (labre PRD REQ-DB-4): everything but
213
237
  * its filters, its sorts and its manual orders, which belong to one view.
238
+ * Its colour rules (`colorRules`, ADR 0036) are kept, conditions included:
239
+ * REQ-DB-4 names them part of a template.
214
240
  */
215
241
  export function viewTemplateData(view) {
216
242
  const data = structuredClone(view);
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": "0.49.0",
4
+ "version": "0.50.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": "0.49.0",
30
+ "@formicoidea/labre-core": "0.50.0",
31
31
  "@blocksuite/icons": "^2.2.12",
32
32
  "@preact/signals-core": "^1.8.0",
33
33
  "lit": "^3.2.0"