@formicoidea/labre-core 0.47.1 → 0.48.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/_pkgs/affine-block-database/view.js +5 -0
- package/dist/_pkgs/affine-block-embed-doc/embed-linked-doc-block/configs/new-doc.d.ts +25 -0
- package/dist/_pkgs/affine-block-embed-doc/embed-linked-doc-block/configs/new-doc.js +71 -0
- package/dist/_pkgs/affine-block-embed-doc/embed-linked-doc-block/configs/slash-menu.js +3 -11
- package/dist/_pkgs/affine-fragment-doc-title/index.d.ts +1 -1
- package/dist/_pkgs/affine-fragment-doc-title/index.js +1 -1
- package/dist/_pkgs/affine-fragment-doc-title/title-band/band-cell.d.ts +22 -0
- package/dist/_pkgs/affine-fragment-doc-title/title-band/band-cell.js +125 -0
- package/dist/_pkgs/affine-fragment-doc-title/title-band/format.d.ts +7 -19
- package/dist/_pkgs/affine-fragment-doc-title/title-band/format.js +0 -38
- package/dist/_pkgs/affine-fragment-doc-title/title-band/show-here.d.ts +19 -0
- package/dist/_pkgs/affine-fragment-doc-title/title-band/show-here.js +61 -0
- package/dist/_pkgs/affine-fragment-doc-title/title-band/title-band.d.ts +28 -18
- package/dist/_pkgs/affine-fragment-doc-title/title-band/title-band.js +225 -207
- package/dist/_pkgs/affine-fragment-doc-title/translations.d.ts +7 -4
- package/dist/_pkgs/affine-fragment-doc-title/translations.js +12 -9
- package/dist/_pkgs/affine-shared/services/linked-doc-creation-service.d.ts +15 -6
- package/dist/_pkgs/affine-shared/services/title-band-service.d.ts +10 -7
- package/dist/_pkgs/affine-shared/utils/model/doc.d.ts +10 -2
- package/dist/_pkgs/affine-shared/utils/model/doc.js +17 -7
- package/dist/_pkgs/data-view/core/component/tags/multi-tag-select.d.ts +7 -2
- package/dist/_pkgs/data-view/core/component/tags/multi-tag-select.js +22 -15
- package/dist/_pkgs/data-view/core/effect.js +2 -0
- package/dist/_pkgs/data-view/core/property/index.d.ts +1 -0
- package/dist/_pkgs/data-view/core/property/index.js +1 -0
- package/dist/_pkgs/data-view/core/property/standalone-cell.d.ts +95 -0
- package/dist/_pkgs/data-view/core/property/standalone-cell.js +306 -0
- package/dist/_pkgs/data-view/core/view-manager/property.d.ts +6 -0
- package/dist/_pkgs/data-view/property-presets/multi-select/cell-renderer.js +1 -1
- package/dist/_pkgs/data-view/property-presets/select/cell-renderer.js +1 -1
- package/dist/_pkgs/data-view/property-presets/text/cell-renderer.js +3 -1
- package/package.json +1 -1
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ViewExtensionProvider, } from '../affine-ext-loader/index.js';
|
|
2
2
|
import { DatabaseBlockModel } from '../affine-model/index.js';
|
|
3
3
|
import { SlashMenuConfigExtension } from '../affine-widget-slash-menu/index.js';
|
|
4
|
+
import { StandaloneCellMetaExtension } from '../data-view/index.js';
|
|
4
5
|
import { BlockViewExtension, FlavourExtension } from '../std/index.js';
|
|
5
6
|
import { literal } from 'lit/static-html.js';
|
|
6
7
|
import { z } from 'zod';
|
|
7
8
|
import { DatabaseConfigExtension } from './config.js';
|
|
8
9
|
import { databaseSlashMenuConfig } from './configs/slash-menu.js';
|
|
9
10
|
import { effects } from './effects.js';
|
|
11
|
+
import { linkColumnConfig } from './properties/link/cell-renderer.js';
|
|
10
12
|
const optionsSchema = z.object({
|
|
11
13
|
configure: z
|
|
12
14
|
.function()
|
|
@@ -29,6 +31,9 @@ export class DatabaseViewExtension extends ViewExtensionProvider {
|
|
|
29
31
|
FlavourExtension('affine:database'),
|
|
30
32
|
BlockViewExtension('affine:database', literal `affine-database`),
|
|
31
33
|
SlashMenuConfigExtension('affine:database', databaseSlashMenuConfig),
|
|
34
|
+
// The title band draws a `link` / `url` property with the table's link
|
|
35
|
+
// cell; it sits below this package and cannot import it (ADR 0035 §11).
|
|
36
|
+
StandaloneCellMetaExtension(linkColumnConfig),
|
|
32
37
|
]);
|
|
33
38
|
if (options) {
|
|
34
39
|
context.register(DatabaseConfigExtension({ configure: options.configure }));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BlockStdScope } from '../../../std/index.js';
|
|
2
|
+
import type { BlockModel } from '../../../store/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Whether the slash menu offers "New Page" here: the card's schema is
|
|
5
|
+
* registered, and the host, if it creates docs, does not refuse it on this
|
|
6
|
+
* editor (`LinkedDocCreationProvider.canCreateLinkedDoc`).
|
|
7
|
+
*/
|
|
8
|
+
export declare function canCreateDocHere(std: BlockStdScope, model: BlockModel): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The slash menu's "New Page": creates a page and leaves a CARD of it
|
|
11
|
+
* (`affine:embed-linked-doc`) right after the block the gesture was typed in.
|
|
12
|
+
* A paragraph the gesture left empty is replaced by the card, as Notion turns
|
|
13
|
+
* the line into the page. A card shows a child where its parent places it; an
|
|
14
|
+
* inline mention is only a reference (Labre ADR-0045 §9, host side).
|
|
15
|
+
*
|
|
16
|
+
* The page comes from the host's `LinkedDocCreationProvider` when there is
|
|
17
|
+
* one (the host persists it, registers it, decides its parent), else from the
|
|
18
|
+
* workspace (`createDefaultDoc`, the playground and standalone editors).
|
|
19
|
+
*
|
|
20
|
+
* One undo step for the card and the removed line. When no card can go there
|
|
21
|
+
* (a parent whose schema refuses it, an edgeless text for one), the gesture
|
|
22
|
+
* falls back on the inline mention it used to leave, so it always yields a way
|
|
23
|
+
* to the page. Returns the new page's id, or null on a read-only store.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createDocFromSlash(std: BlockStdScope, model: BlockModel): string | null;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { insertContent } from '../../../affine-rich-text/index.js';
|
|
2
|
+
import { REFERENCE_NODE } from '../../../affine-shared/consts/index.js';
|
|
3
|
+
import { LinkedDocCreationProvider, TelemetryProvider, } from '../../../affine-shared/services/index.js';
|
|
4
|
+
import { createDefaultDoc, writeDefaultDocBlocks, } from '../../../affine-shared/utils/index.js';
|
|
5
|
+
const LINKED_DOC = 'affine:embed-linked-doc';
|
|
6
|
+
/**
|
|
7
|
+
* Whether the slash menu offers "New Page" here: the card's schema is
|
|
8
|
+
* registered, and the host, if it creates docs, does not refuse it on this
|
|
9
|
+
* editor (`LinkedDocCreationProvider.canCreateLinkedDoc`).
|
|
10
|
+
*/
|
|
11
|
+
export function canCreateDocHere(std, model) {
|
|
12
|
+
if (!model.store.schema.flavourSchemaMap.has(LINKED_DOC))
|
|
13
|
+
return false;
|
|
14
|
+
const creation = std.getOptional(LinkedDocCreationProvider);
|
|
15
|
+
return creation?.canCreateLinkedDoc?.(std.host) ?? true;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The slash menu's "New Page": creates a page and leaves a CARD of it
|
|
19
|
+
* (`affine:embed-linked-doc`) right after the block the gesture was typed in.
|
|
20
|
+
* A paragraph the gesture left empty is replaced by the card, as Notion turns
|
|
21
|
+
* the line into the page. A card shows a child where its parent places it; an
|
|
22
|
+
* inline mention is only a reference (Labre ADR-0045 §9, host side).
|
|
23
|
+
*
|
|
24
|
+
* The page comes from the host's `LinkedDocCreationProvider` when there is
|
|
25
|
+
* one (the host persists it, registers it, decides its parent), else from the
|
|
26
|
+
* workspace (`createDefaultDoc`, the playground and standalone editors).
|
|
27
|
+
*
|
|
28
|
+
* One undo step for the card and the removed line. When no card can go there
|
|
29
|
+
* (a parent whose schema refuses it, an edgeless text for one), the gesture
|
|
30
|
+
* falls back on the inline mention it used to leave, so it always yields a way
|
|
31
|
+
* to the page. Returns the new page's id, or null on a read-only store.
|
|
32
|
+
*/
|
|
33
|
+
export function createDocFromSlash(std, model) {
|
|
34
|
+
const { store } = std;
|
|
35
|
+
if (store.readonly)
|
|
36
|
+
return null;
|
|
37
|
+
const pageId = createNewDoc(std).id;
|
|
38
|
+
store.captureSync();
|
|
39
|
+
if (insertCard(store, model, pageId)) {
|
|
40
|
+
std.getOptional(TelemetryProvider)?.track('BlockCreated', {
|
|
41
|
+
blockType: LINKED_DOC,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
insertContent(std, model, REFERENCE_NODE, {
|
|
46
|
+
reference: { type: 'LinkedPage', pageId },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return pageId;
|
|
50
|
+
}
|
|
51
|
+
function createNewDoc(std) {
|
|
52
|
+
const creation = std.getOptional(LinkedDocCreationProvider);
|
|
53
|
+
if (!creation)
|
|
54
|
+
return createDefaultDoc(std.store.workspace);
|
|
55
|
+
const doc = creation.createLinkedDoc(std.host, '');
|
|
56
|
+
doc.load(() => writeDefaultDocBlocks(doc));
|
|
57
|
+
// The new page's first undo must not empty it (as in `createDefaultDoc`).
|
|
58
|
+
doc.resetHistory();
|
|
59
|
+
return doc;
|
|
60
|
+
}
|
|
61
|
+
function insertCard(store, anchor, pageId) {
|
|
62
|
+
const parent = store.getParent(anchor);
|
|
63
|
+
if (!parent || !store.schema.isValid(LINKED_DOC, parent.flavour)) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const cardId = store.addBlock(LINKED_DOC, { pageId }, parent, parent.children.indexOf(anchor) + 1);
|
|
67
|
+
if (anchor.flavour === 'affine:paragraph' && anchor.text?.length === 0) {
|
|
68
|
+
store.deleteBlock(anchor);
|
|
69
|
+
}
|
|
70
|
+
return cardId;
|
|
71
|
+
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { EmbedLinkedDocBlockSchema } from '../../../affine-model/index.js';
|
|
2
|
-
import { insertContent } from '../../../affine-rich-text/index.js';
|
|
3
|
-
import { REFERENCE_NODE } from '../../../affine-shared/consts/index.js';
|
|
4
|
-
import { createDefaultDoc } from '../../../affine-shared/utils/index.js';
|
|
5
2
|
import { SlashMenuConfigIdentifier, } from '../../../affine-widget-slash-menu/index.js';
|
|
6
3
|
import { LinkedPageIcon, PlusIcon } from '@blocksuite/icons/lit';
|
|
7
4
|
import {} from '../../../store/index.js';
|
|
8
5
|
import { EMBED_DOC_SLASH_LINKED_DOC_CAPTION, EMBED_DOC_SLASH_LINKED_DOC_DESCRIPTION, EMBED_DOC_SLASH_LINKED_DOC_NAME, EMBED_DOC_SLASH_NEW_DOC_DESCRIPTION, EMBED_DOC_SLASH_NEW_DOC_NAME, } from '../../translations.js';
|
|
6
|
+
import { canCreateDocHere, createDocFromSlash } from './new-doc.js';
|
|
9
7
|
import { LinkDocTooltip, NewDocTooltip } from './tooltips.js';
|
|
10
8
|
const linkedDocSlashMenuConfig = {
|
|
11
9
|
items: [
|
|
@@ -21,15 +19,9 @@ const linkedDocSlashMenuConfig = {
|
|
|
21
19
|
captionWording: EMBED_DOC_SLASH_NEW_DOC_NAME,
|
|
22
20
|
},
|
|
23
21
|
group: '3_Page@0',
|
|
24
|
-
when: ({ model }) => model
|
|
22
|
+
when: ({ std, model }) => canCreateDocHere(std, model),
|
|
25
23
|
action: ({ std, model }) => {
|
|
26
|
-
|
|
27
|
-
insertContent(std, model, REFERENCE_NODE, {
|
|
28
|
-
reference: {
|
|
29
|
-
type: 'LinkedPage',
|
|
30
|
-
pageId: newDoc.id,
|
|
31
|
-
},
|
|
32
|
-
});
|
|
24
|
+
createDocFromSlash(std, model);
|
|
33
25
|
},
|
|
34
26
|
},
|
|
35
27
|
{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { DocTitle } from './doc-title.js';
|
|
2
|
-
export {
|
|
2
|
+
export { type ChipTag, chipValueView, type ChipValueView, formatPropertyValue, isPropertyValueEmpty, } from './title-band/format.js';
|
|
3
3
|
export { LABRE_TITLE_BAND, TitleBand } from './title-band/title-band.js';
|
|
4
4
|
export { getDocTitleByEditorHost } from './utils.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { DocTitle } from './doc-title.js';
|
|
2
|
-
export {
|
|
2
|
+
export { chipValueView, formatPropertyValue, isPropertyValueEmpty, } from './title-band/format.js';
|
|
3
3
|
export { LABRE_TITLE_BAND, TitleBand } from './title-band/title-band.js';
|
|
4
4
|
export { getDocTitleByEditorHost } from './utils.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TitleBandProperty } from '../../affine-shared/services/index.js';
|
|
2
|
+
import { type PropertyMetaConfig } from '../../data-view/index.js';
|
|
3
|
+
/** The data-view cell type that draws a band property of `type`, if any. */
|
|
4
|
+
export declare function bandCellType(type: string): string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* The cell's meta: one a package above registered for that cell type (the
|
|
7
|
+
* database block's `link`), else this package's preset. Without its
|
|
8
|
+
* registration a link is drawn by the `text` cell.
|
|
9
|
+
*/
|
|
10
|
+
export declare function bandCellMeta(type: string, registered: (cellType: string) => PropertyMetaConfig | null): PropertyMetaConfig | null;
|
|
11
|
+
export declare function isBandReadonlyType(type: string): boolean;
|
|
12
|
+
/** The value in the raw shape of the cell type `cellType` reads. */
|
|
13
|
+
export declare function bandCellValue(cellType: string, value: unknown): unknown;
|
|
14
|
+
/** The property's config as the cell reads it: a select's tags, complete. */
|
|
15
|
+
export declare function bandCellData(cellType: string, property: TitleBandProperty): Record<string, unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* What the band writes back for a value a cell commits: `null` for an empty
|
|
18
|
+
* one (the seam's "clear"), the value itself otherwise.
|
|
19
|
+
*/
|
|
20
|
+
export declare function bandWriteValue(value: unknown): unknown;
|
|
21
|
+
/** Whether a committed value is the one the chip already shows. */
|
|
22
|
+
export declare function sameBandValue(cellType: string, current: unknown, next: unknown): boolean;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { selectOptionColors, } from '../../data-view/index.js';
|
|
2
|
+
import { propertyPresets } from '../../data-view/property-presets/index.js';
|
|
3
|
+
import { chipOptions } from './format.js';
|
|
4
|
+
/**
|
|
5
|
+
* Which data-view cell draws a band property, and the value and config that
|
|
6
|
+
* cell is handed (ADR 0035 §11, amended 2026-10-13: the chips are the table's
|
|
7
|
+
* own cells).
|
|
8
|
+
*
|
|
9
|
+
* The band speaks the data-view types (§9d), plus the aliases a host's sheet
|
|
10
|
+
* holds whose shape a preset already reads: a URL is the table's `link` cell,
|
|
11
|
+
* the text-like types the `text` cell, the time stamps a read-only `date`.
|
|
12
|
+
* A type with no cell here (`relation`, `image`, an invented one) keeps the
|
|
13
|
+
* band's plain-text reading and opens the properties panel instead.
|
|
14
|
+
*
|
|
15
|
+
* The host's JSON is never trusted to have the preset's shape: a renderer
|
|
16
|
+
* that meets a string where it maps an array throws mid-render, so each value
|
|
17
|
+
* is narrowed to its cell's raw shape, and anything else reads as empty.
|
|
18
|
+
*/
|
|
19
|
+
const CELL_TYPES = Object.assign(Object.create(null), {
|
|
20
|
+
checkbox: 'checkbox',
|
|
21
|
+
select: 'select',
|
|
22
|
+
'multi-select': 'multi-select',
|
|
23
|
+
date: 'date',
|
|
24
|
+
'created-time': 'date',
|
|
25
|
+
'modified-time': 'date',
|
|
26
|
+
number: 'number',
|
|
27
|
+
progress: 'progress',
|
|
28
|
+
text: 'text',
|
|
29
|
+
'rich-text': 'text',
|
|
30
|
+
title: 'text',
|
|
31
|
+
email: 'text',
|
|
32
|
+
phone: 'text',
|
|
33
|
+
link: 'link',
|
|
34
|
+
url: 'link',
|
|
35
|
+
});
|
|
36
|
+
/** Drawn by their cell, never edited from the band. */
|
|
37
|
+
const READ_ONLY_TYPES = new Set(['created-time', 'modified-time']);
|
|
38
|
+
const PRESETS = new Map([
|
|
39
|
+
propertyPresets.checkboxPropertyConfig,
|
|
40
|
+
propertyPresets.datePropertyConfig,
|
|
41
|
+
propertyPresets.multiSelectPropertyConfig,
|
|
42
|
+
propertyPresets.numberPropertyConfig,
|
|
43
|
+
propertyPresets.progressPropertyConfig,
|
|
44
|
+
propertyPresets.selectPropertyConfig,
|
|
45
|
+
propertyPresets.textPropertyConfig,
|
|
46
|
+
].map(meta => [meta.type, meta]));
|
|
47
|
+
const DEFAULT_TAG_COLOR = selectOptionColors.at(-1)?.color ?? '';
|
|
48
|
+
/** The data-view cell type that draws a band property of `type`, if any. */
|
|
49
|
+
export function bandCellType(type) {
|
|
50
|
+
return CELL_TYPES[type];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The cell's meta: one a package above registered for that cell type (the
|
|
54
|
+
* database block's `link`), else this package's preset. Without its
|
|
55
|
+
* registration a link is drawn by the `text` cell.
|
|
56
|
+
*/
|
|
57
|
+
export function bandCellMeta(type, registered) {
|
|
58
|
+
const cellType = bandCellType(type);
|
|
59
|
+
if (!cellType)
|
|
60
|
+
return null;
|
|
61
|
+
return (registered(cellType) ??
|
|
62
|
+
PRESETS.get(cellType) ??
|
|
63
|
+
(cellType === 'link' ? (PRESETS.get('text') ?? null) : null));
|
|
64
|
+
}
|
|
65
|
+
export function isBandReadonlyType(type) {
|
|
66
|
+
return READ_ONLY_TYPES.has(type);
|
|
67
|
+
}
|
|
68
|
+
const isFiniteNumber = (value) => typeof value === 'number' && Number.isFinite(value);
|
|
69
|
+
/** The value in the raw shape of the cell type `cellType` reads. */
|
|
70
|
+
export function bandCellValue(cellType, value) {
|
|
71
|
+
switch (cellType) {
|
|
72
|
+
case 'checkbox':
|
|
73
|
+
return value === true;
|
|
74
|
+
case 'select':
|
|
75
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
76
|
+
case 'multi-select':
|
|
77
|
+
return Array.isArray(value)
|
|
78
|
+
? value.filter((id) => typeof id === 'string')
|
|
79
|
+
: undefined;
|
|
80
|
+
case 'date':
|
|
81
|
+
case 'number':
|
|
82
|
+
case 'progress':
|
|
83
|
+
return isFiniteNumber(value) ? value : undefined;
|
|
84
|
+
default:
|
|
85
|
+
if (typeof value === 'string')
|
|
86
|
+
return value;
|
|
87
|
+
if (isFiniteNumber(value))
|
|
88
|
+
return String(value);
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** The property's config as the cell reads it: a select's tags, complete. */
|
|
93
|
+
export function bandCellData(cellType, property) {
|
|
94
|
+
if (cellType !== 'select' && cellType !== 'multi-select') {
|
|
95
|
+
return property.data;
|
|
96
|
+
}
|
|
97
|
+
const options = chipOptions(property).map(tag => ({
|
|
98
|
+
id: tag.id,
|
|
99
|
+
value: tag.label,
|
|
100
|
+
color: tag.color ?? DEFAULT_TAG_COLOR,
|
|
101
|
+
}));
|
|
102
|
+
return { ...property.data, options };
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* What the band writes back for a value a cell commits: `null` for an empty
|
|
106
|
+
* one (the seam's "clear"), the value itself otherwise.
|
|
107
|
+
*/
|
|
108
|
+
export function bandWriteValue(value) {
|
|
109
|
+
if (value === undefined)
|
|
110
|
+
return null;
|
|
111
|
+
if (typeof value === 'string' && value.trim() === '')
|
|
112
|
+
return null;
|
|
113
|
+
if (typeof value === 'number' && Number.isNaN(value))
|
|
114
|
+
return null;
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
/** Whether a committed value is the one the chip already shows. */
|
|
118
|
+
export function sameBandValue(cellType, current, next) {
|
|
119
|
+
const a = bandWriteValue(bandCellValue(cellType, current));
|
|
120
|
+
const b = bandWriteValue(next);
|
|
121
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
122
|
+
return a.length === b.length && a.every((item, i) => item === b[i]);
|
|
123
|
+
}
|
|
124
|
+
return a === b;
|
|
125
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TitleBandProperty } from '../../affine-shared/services/index.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* A property's value as one line of text — pure, render-free, so a host's own
|
|
4
|
+
* properties panel can show what a chip reads (`formatPropertyValue`,
|
|
5
|
+
* re-exported by `@labre/affine/host-panels`), and the band can still read
|
|
6
|
+
* a type no data-view cell draws (`relation`, an unknown one).
|
|
7
7
|
*
|
|
8
8
|
* The value is the JSON a data-view cell of `type` holds (ADR 0035 §9d), and
|
|
9
9
|
* the shapes below are the data-view presets' own: an option id for `select`,
|
|
@@ -11,12 +11,9 @@ import type { TitleBandProperty } from '../../affine-shared/services/index.js';
|
|
|
11
11
|
* formatted with the number preset's options, so a chip and a database cell
|
|
12
12
|
* read the same.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* band does not know: it is drawn as plain text and opens no editor. The
|
|
18
|
-
* upgrade path is a hosted data source for the page's sheet once
|
|
19
|
-
* `HostedDataSourceBase` exists (ADR 0035 §7, issue B1).
|
|
14
|
+
* The chips themselves no longer read this: each value is drawn and edited by
|
|
15
|
+
* the data-view cell of its type (`./band-cell.ts`, ADR 0035 §11 amended
|
|
16
|
+
* 2026-10-13). This text is the host panels' reading and the band's fallback.
|
|
20
17
|
*/
|
|
21
18
|
/** A select option as a data-view `select` / `multi-select` holds it. */
|
|
22
19
|
export interface ChipTag {
|
|
@@ -37,8 +34,6 @@ export type ChipValueView = {
|
|
|
37
34
|
kind: 'tags';
|
|
38
35
|
tags: ChipTag[];
|
|
39
36
|
};
|
|
40
|
-
/** The editor a click on a chip opens; `none` for a type the band cannot edit. */
|
|
41
|
-
export type ChipEditorKind = 'toggle' | 'select' | 'multi-select' | 'date' | 'number' | 'text' | 'none';
|
|
42
37
|
/**
|
|
43
38
|
* The number preset's formats (`data-view/…/number/utils/formatter.ts`),
|
|
44
39
|
* restated rather than imported: the preset formats with
|
|
@@ -60,10 +55,3 @@ export declare function chipValueView(property: TitleBandProperty, locale: strin
|
|
|
60
55
|
* mark, not a word, so a host draws its own from `property.value`.
|
|
61
56
|
*/
|
|
62
57
|
export declare function formatPropertyValue(property: TitleBandProperty, locale?: string): string;
|
|
63
|
-
/**
|
|
64
|
-
* A number typed in a chip's editor: blanks dropped, a decimal comma read as
|
|
65
|
-
* a point. `NaN` for anything else, which the band writes as `null`.
|
|
66
|
-
*/
|
|
67
|
-
export declare function parseChipNumber(text: string): number;
|
|
68
|
-
/** The editor a click on this property's chip opens. */
|
|
69
|
-
export declare function chipEditorKind(property: TitleBandProperty): ChipEditorKind;
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
const TEXT_TYPES = new Set([
|
|
2
|
-
'text',
|
|
3
|
-
'rich-text',
|
|
4
|
-
'title',
|
|
5
|
-
'url',
|
|
6
|
-
'link',
|
|
7
|
-
'email',
|
|
8
|
-
'phone',
|
|
9
|
-
]);
|
|
10
1
|
const DATE_TYPES = new Set(['date', 'created-time', 'modified-time']);
|
|
11
2
|
const currency = (code) => ({
|
|
12
3
|
style: 'currency',
|
|
@@ -151,32 +142,3 @@ export function formatPropertyValue(property, locale = 'en-US') {
|
|
|
151
142
|
return '';
|
|
152
143
|
}
|
|
153
144
|
}
|
|
154
|
-
/**
|
|
155
|
-
* A number typed in a chip's editor: blanks dropped, a decimal comma read as
|
|
156
|
-
* a point. `NaN` for anything else, which the band writes as `null`.
|
|
157
|
-
*/
|
|
158
|
-
export function parseChipNumber(text) {
|
|
159
|
-
const compact = text.replace(/\s/g, '');
|
|
160
|
-
if (compact === '')
|
|
161
|
-
return NaN;
|
|
162
|
-
return Number(compact.replace(',', '.'));
|
|
163
|
-
}
|
|
164
|
-
/** The editor a click on this property's chip opens. */
|
|
165
|
-
export function chipEditorKind(property) {
|
|
166
|
-
if (property.readonly)
|
|
167
|
-
return 'none';
|
|
168
|
-
const { type } = property;
|
|
169
|
-
if (type === 'checkbox')
|
|
170
|
-
return 'toggle';
|
|
171
|
-
if (type === 'select')
|
|
172
|
-
return 'select';
|
|
173
|
-
if (type === 'multi-select')
|
|
174
|
-
return 'multi-select';
|
|
175
|
-
if (type === 'date')
|
|
176
|
-
return 'date';
|
|
177
|
-
if (type === 'number' || type === 'progress')
|
|
178
|
-
return 'number';
|
|
179
|
-
if (TEXT_TYPES.has(type))
|
|
180
|
-
return 'text';
|
|
181
|
-
return 'none';
|
|
182
|
-
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BlockStdScope } from '../../std/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* "Show here" (labre ADR-0045 §7): insert a card of page `pageId` into the
|
|
4
|
+
* open document, so a child page the document held without showing becomes
|
|
5
|
+
* shown. The host computes the "Not shown" list; once the card exists, its
|
|
6
|
+
* own reading of the document drops the page from it. Nothing here knows a
|
|
7
|
+
* parent or a child: the card is an ordinary `affine:embed-linked-doc`,
|
|
8
|
+
* exactly what pasting a link to that page would make.
|
|
9
|
+
*
|
|
10
|
+
* - page view: at the end of the last note the page view shows (a new note
|
|
11
|
+
* when there is none);
|
|
12
|
+
* - canvas: centred in the visible part of the canvas, through the CRUD
|
|
13
|
+
* `addBlock`, which stamps the viewer's active layer (ADR 0031 §6), then
|
|
14
|
+
* selected so the reader sees what appeared.
|
|
15
|
+
*
|
|
16
|
+
* One gesture, one undo step (`captureSync`). A read-only document gets
|
|
17
|
+
* nothing. Returns the new card's id, or `null` when nothing was written.
|
|
18
|
+
*/
|
|
19
|
+
export declare function showPageHere(std: BlockStdScope, surface: 'page' | 'canvas', pageId: string): string | null;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { EdgelessCRUDIdentifier } from '../../affine-block-surface/index.js';
|
|
2
|
+
import { EMBED_CARD_HEIGHT, EMBED_CARD_WIDTH, } from '../../affine-shared/consts/index.js';
|
|
3
|
+
import { TelemetryProvider } from '../../affine-shared/services/index.js';
|
|
4
|
+
import { getLastNoteBlock } from '../../affine-shared/utils/index.js';
|
|
5
|
+
import { Bound } from '../../global/gfx/index.js';
|
|
6
|
+
import { GfxControllerIdentifier } from '../../std/gfx/index.js';
|
|
7
|
+
const LINKED_DOC = 'affine:embed-linked-doc';
|
|
8
|
+
/** The canvas card's style, the one "Linked doc" inserts on the canvas. */
|
|
9
|
+
const CANVAS_STYLE = 'vertical';
|
|
10
|
+
/**
|
|
11
|
+
* "Show here" (labre ADR-0045 §7): insert a card of page `pageId` into the
|
|
12
|
+
* open document, so a child page the document held without showing becomes
|
|
13
|
+
* shown. The host computes the "Not shown" list; once the card exists, its
|
|
14
|
+
* own reading of the document drops the page from it. Nothing here knows a
|
|
15
|
+
* parent or a child: the card is an ordinary `affine:embed-linked-doc`,
|
|
16
|
+
* exactly what pasting a link to that page would make.
|
|
17
|
+
*
|
|
18
|
+
* - page view: at the end of the last note the page view shows (a new note
|
|
19
|
+
* when there is none);
|
|
20
|
+
* - canvas: centred in the visible part of the canvas, through the CRUD
|
|
21
|
+
* `addBlock`, which stamps the viewer's active layer (ADR 0031 §6), then
|
|
22
|
+
* selected so the reader sees what appeared.
|
|
23
|
+
*
|
|
24
|
+
* One gesture, one undo step (`captureSync`). A read-only document gets
|
|
25
|
+
* nothing. Returns the new card's id, or `null` when nothing was written.
|
|
26
|
+
*/
|
|
27
|
+
export function showPageHere(std, surface, pageId) {
|
|
28
|
+
const { store } = std;
|
|
29
|
+
if (store.readonly || !store.root || !pageId)
|
|
30
|
+
return null;
|
|
31
|
+
store.captureSync();
|
|
32
|
+
const id = surface === 'canvas'
|
|
33
|
+
? insertOnCanvas(std, pageId)
|
|
34
|
+
: insertInPage(std, pageId);
|
|
35
|
+
if (id) {
|
|
36
|
+
std.getOptional(TelemetryProvider)?.track('BlockCreated', {
|
|
37
|
+
blockType: LINKED_DOC,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return id;
|
|
41
|
+
}
|
|
42
|
+
function insertInPage(std, pageId) {
|
|
43
|
+
const { store } = std;
|
|
44
|
+
const root = store.root;
|
|
45
|
+
if (!root)
|
|
46
|
+
return null;
|
|
47
|
+
const noteId = getLastNoteBlock(store)?.id ?? store.addBlock('affine:note', {}, root.id);
|
|
48
|
+
return store.addBlock(LINKED_DOC, { pageId }, noteId);
|
|
49
|
+
}
|
|
50
|
+
function insertOnCanvas(std, pageId) {
|
|
51
|
+
const gfx = std.get(GfxControllerIdentifier);
|
|
52
|
+
const surface = gfx.surface;
|
|
53
|
+
if (!surface)
|
|
54
|
+
return null;
|
|
55
|
+
const xywh = Bound.fromCenter([gfx.viewport.centerX, gfx.viewport.centerY], EMBED_CARD_WIDTH[CANVAS_STYLE], EMBED_CARD_HEIGHT[CANVAS_STYLE]).serialize();
|
|
56
|
+
const id = std
|
|
57
|
+
.get(EdgelessCRUDIdentifier)
|
|
58
|
+
.addBlock(LINKED_DOC, { pageId, xywh, style: CANVAS_STYLE }, surface);
|
|
59
|
+
gfx.selection.set({ elements: [id], editing: false });
|
|
60
|
+
return id;
|
|
61
|
+
}
|
|
@@ -14,40 +14,50 @@ declare const TitleBand_base: typeof ShadowlessElement & import("../../global/ut
|
|
|
14
14
|
*
|
|
15
15
|
* Fed by `TitleBandProvider` alone (§9d): no provider, nothing at all. The
|
|
16
16
|
* chips are the sheet's visible properties in the host's order, an empty one
|
|
17
|
-
* included (REQ-PR-1)
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
17
|
+
* included (REQ-PR-1). Each value is drawn and edited by the cell the inline
|
|
18
|
+
* table mounts for its data-view type (`<dv-standalone-cell>`, ADR 0035
|
|
19
|
+
* §11 amended 2026-10-13): the checkbox, the tag menu of a select, the date
|
|
20
|
+
* picker, the number, text and link inputs, with the table's own styles. The
|
|
21
|
+
* value the cell commits goes back through `set`, the chip shows pending
|
|
22
|
+
* until the host settles it, and a type with no cell keeps a plain-text
|
|
23
|
+
* reading that opens the properties panel. The band never applies a value, and writes to
|
|
24
|
+
* the document only the card "Show here" inserts. The "+" is drawn when the
|
|
25
|
+
* host passes `add`; the panel button when a `PropertiesPanelProvider` is
|
|
26
|
+
* registered. The "Not shown on this page" row is drawn in both views
|
|
27
|
+
* from the host's `notShown$` (ADR 0035 §9d, amended 2026-10-13): each page
|
|
28
|
+
* opens through the linked-document path, and "Show here" inserts a card of
|
|
29
|
+
* it into this document; the host then drops the page from its list.
|
|
23
30
|
*/
|
|
24
31
|
export declare class TitleBand extends TitleBand_base {
|
|
25
32
|
static styles: import("lit").CSSResult;
|
|
26
33
|
private _sources;
|
|
27
|
-
/** The editor menu open now, put away with the band. */
|
|
28
|
-
private _menu;
|
|
29
|
-
private _pop;
|
|
30
34
|
/** Collapse state when the host does not remember one. */
|
|
31
35
|
private readonly _localCollapsed$;
|
|
32
36
|
/** Property ids whose `set` has not settled yet. */
|
|
33
37
|
private readonly _pending$;
|
|
34
38
|
/** Read inside `render` it subscribes, through `SignalWatcher`. */
|
|
35
39
|
private get _readonly();
|
|
40
|
+
/** The table's own flags, so a number reads as it does in a cell. */
|
|
41
|
+
private readonly _featureFlags$;
|
|
36
42
|
private get _locale();
|
|
37
43
|
private _t;
|
|
38
44
|
private _getSources;
|
|
39
45
|
private _isCollapsed;
|
|
40
46
|
private _setCollapsed;
|
|
41
47
|
private _write;
|
|
42
|
-
|
|
43
|
-
private
|
|
44
|
-
|
|
45
|
-
private
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
/** A value a cell commits: unchanged, nothing is written. */
|
|
49
|
+
private _commit;
|
|
50
|
+
/** Neither the property nor the document can be written, or the type. */
|
|
51
|
+
private _isReadonlyChip;
|
|
52
|
+
/**
|
|
53
|
+
* The cell that draws `prop`, built once per property and type: its value,
|
|
54
|
+
* name and config are read from the sheet, so a new sheet updates the cell
|
|
55
|
+
* in place and an editor open in it stays open.
|
|
56
|
+
*/
|
|
57
|
+
private _cellFor;
|
|
49
58
|
private readonly _openPanel;
|
|
50
|
-
private
|
|
59
|
+
private readonly _onChip;
|
|
60
|
+
private _renderFallback;
|
|
51
61
|
private _renderChip;
|
|
52
62
|
private _renderTools;
|
|
53
63
|
private _renderSheet;
|
|
@@ -56,7 +66,7 @@ export declare class TitleBand extends TitleBand_base {
|
|
|
56
66
|
render(): TemplateResult<1> | typeof nothing;
|
|
57
67
|
accessor std: BlockStdScope | null;
|
|
58
68
|
accessor docId: string;
|
|
59
|
-
/** Where the band is drawn
|
|
69
|
+
/** Where the band is drawn: where "Show here" puts the card. */
|
|
60
70
|
accessor surface: 'page' | 'canvas';
|
|
61
71
|
}
|
|
62
72
|
export {};
|