@formicoidea/labre-core 0.58.0 → 0.60.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/architecture/code.c4 +175 -144
- package/architecture/domain.c4 +15 -9
- package/architecture/likec4.config.json +3 -3
- package/dist/_pkgs/affine-block-attachment/edgeless-clipboard-config.d.ts +3 -2
- package/dist/_pkgs/affine-block-attachment/edgeless-clipboard-config.js +18 -13
- package/dist/_pkgs/affine-block-callout/adapters/markdown.js +4 -1
- package/dist/_pkgs/affine-block-code/adapters/html.js +1 -1
- package/dist/_pkgs/affine-block-code/adapters/markdown/preprocessor.js +13 -1
- package/dist/_pkgs/affine-block-code/adapters/notion-html.js +1 -1
- package/dist/_pkgs/affine-block-code/code-block.d.ts +17 -2
- package/dist/_pkgs/affine-block-code/code-block.js +28 -23
- package/dist/_pkgs/affine-block-code/code-toolbar/components/lang-button.js +17 -4
- package/dist/_pkgs/affine-block-code/code-toolbar/components/preview-button.js +1 -1
- package/dist/_pkgs/affine-block-data-view/data-source.js +12 -5
- package/dist/_pkgs/affine-block-edgeless-text/edgeless-clipboard-config.d.ts +3 -2
- package/dist/_pkgs/affine-block-edgeless-text/edgeless-clipboard-config.js +8 -5
- package/dist/_pkgs/affine-block-image/asset-picker.d.ts +23 -2
- package/dist/_pkgs/affine-block-image/asset-picker.js +52 -12
- package/dist/_pkgs/affine-block-image/configs/replace-action.d.ts +8 -5
- package/dist/_pkgs/affine-block-image/configs/replace-action.js +8 -8
- package/dist/_pkgs/affine-block-image/configs/toolbar.js +2 -1
- package/dist/_pkgs/affine-block-image/crop/crop-controller.d.ts +15 -0
- package/dist/_pkgs/affine-block-image/crop/crop-controller.js +40 -2
- package/dist/_pkgs/affine-block-image/crop/crop-math.d.ts +22 -0
- package/dist/_pkgs/affine-block-image/crop/crop-math.js +55 -2
- package/dist/_pkgs/affine-block-image/crop/crop-overlay.d.ts +17 -3
- package/dist/_pkgs/affine-block-image/crop/crop-overlay.js +64 -6
- package/dist/_pkgs/affine-block-image/edgeless-clipboard-config.d.ts +3 -2
- package/dist/_pkgs/affine-block-image/edgeless-clipboard-config.js +20 -14
- package/dist/_pkgs/affine-block-image/image-block.js +1 -0
- package/dist/_pkgs/affine-block-image/image-edgeless-block.js +3 -0
- package/dist/_pkgs/affine-block-image/index.d.ts +2 -0
- package/dist/_pkgs/affine-block-image/index.js +2 -0
- package/dist/_pkgs/affine-block-image/replace/commands.d.ts +68 -0
- package/dist/_pkgs/affine-block-image/replace/commands.js +200 -0
- package/dist/_pkgs/affine-block-image/replace/replace-model.d.ts +44 -0
- package/dist/_pkgs/affine-block-image/replace/replace-model.js +168 -0
- package/dist/_pkgs/affine-block-image/replace/toolbar.d.ts +21 -0
- package/dist/_pkgs/affine-block-image/replace/toolbar.js +159 -0
- package/dist/_pkgs/affine-block-image/translations.d.ts +15 -2
- package/dist/_pkgs/affine-block-image/translations.js +35 -2
- package/dist/_pkgs/affine-block-image/utils.d.ts +7 -0
- package/dist/_pkgs/affine-block-image/utils.js +13 -0
- package/dist/_pkgs/affine-block-image/view.js +7 -0
- package/dist/_pkgs/affine-block-note/components/edgeless-page-block-title.d.ts +14 -5
- package/dist/_pkgs/affine-block-note/components/edgeless-page-block-title.js +18 -11
- package/dist/_pkgs/affine-block-note/config.d.ts +9 -2
- package/dist/_pkgs/affine-block-note/edgeless-clipboard-config.d.ts +3 -2
- package/dist/_pkgs/affine-block-note/edgeless-clipboard-config.js +8 -5
- package/dist/_pkgs/affine-block-paragraph/adapters/markdown.js +11 -0
- package/dist/_pkgs/affine-block-root/commands/invisible-characters-commands.d.ts +17 -0
- package/dist/_pkgs/affine-block-root/commands/invisible-characters-commands.js +123 -0
- package/dist/_pkgs/affine-block-root/edgeless/clipboard/command.js +82 -65
- package/dist/_pkgs/affine-block-root/edgeless/edgeless-keyboard.js +2 -0
- package/dist/_pkgs/affine-block-root/index.d.ts +1 -0
- package/dist/_pkgs/affine-block-root/index.js +1 -0
- package/dist/_pkgs/affine-block-root/translations.d.ts +6 -0
- package/dist/_pkgs/affine-block-root/translations.js +10 -0
- package/dist/_pkgs/affine-block-root/view.js +6 -1
- package/dist/_pkgs/affine-block-surface/commands/index.d.ts +1 -1
- package/dist/_pkgs/affine-block-surface/commands/index.js +1 -1
- package/dist/_pkgs/affine-block-surface/commands/reassociate-connectors.d.ts +9 -0
- package/dist/_pkgs/affine-block-surface/commands/reassociate-connectors.js +21 -12
- package/dist/_pkgs/affine-block-surface/extensions/clipboard-config.d.ts +33 -0
- package/dist/_pkgs/affine-block-surface/extensions/clipboard-config.js +53 -0
- package/dist/_pkgs/affine-block-surface/extensions/index.d.ts +1 -0
- package/dist/_pkgs/affine-block-surface/extensions/index.js +1 -0
- package/dist/_pkgs/affine-block-surface/extensions/legend-label.d.ts +11 -0
- package/dist/_pkgs/affine-block-surface/extensions/legend-label.js +16 -0
- package/dist/_pkgs/affine-block-surface/extensions/legend.d.ts +1 -11
- package/dist/_pkgs/affine-block-surface/extensions/legend.js +2 -11
- package/dist/_pkgs/affine-block-surface/extensions/reading-toolbar.js +12 -12
- package/dist/_pkgs/affine-block-surface/extensions/toolbox.d.ts +62 -0
- package/dist/_pkgs/affine-block-surface/extensions/toolbox.js +1 -0
- package/dist/_pkgs/affine-block-surface/framework-background/background-view.js +2 -1
- package/dist/_pkgs/affine-block-surface/framework-background/band-widths.d.ts +104 -0
- package/dist/_pkgs/affine-block-surface/framework-background/band-widths.js +156 -0
- package/dist/_pkgs/affine-block-surface/framework-background/def.d.ts +87 -4
- package/dist/_pkgs/affine-block-surface/framework-background/def.js +26 -7
- package/dist/_pkgs/affine-block-surface/framework-background/ellipsis.d.ts +58 -0
- package/dist/_pkgs/affine-block-surface/framework-background/ellipsis.js +110 -0
- package/dist/_pkgs/affine-block-surface/framework-background/index.d.ts +3 -0
- package/dist/_pkgs/affine-block-surface/framework-background/index.js +3 -0
- package/dist/_pkgs/affine-block-surface/framework-background/labels.d.ts +12 -2
- package/dist/_pkgs/affine-block-surface/framework-background/labels.js +29 -5
- package/dist/_pkgs/affine-block-surface/framework-background/measure-text.d.ts +14 -0
- package/dist/_pkgs/affine-block-surface/framework-background/measure-text.js +31 -0
- package/dist/_pkgs/affine-block-surface/framework-background/renderer.d.ts +14 -1
- package/dist/_pkgs/affine-block-surface/framework-background/renderer.js +84 -31
- package/dist/_pkgs/affine-block-surface/interchange-headless.d.ts +2 -0
- package/dist/_pkgs/affine-block-surface/interchange-headless.js +2 -0
- package/dist/_pkgs/affine-block-table/adapters/html.js +26 -14
- package/dist/_pkgs/affine-block-table/adapters/utils.d.ts +1 -0
- package/dist/_pkgs/affine-block-table/adapters/utils.js +23 -5
- package/dist/_pkgs/affine-block-table/header-menu.d.ts +13 -0
- package/dist/_pkgs/affine-block-table/header-menu.js +25 -0
- package/dist/_pkgs/affine-block-table/selection-controller.d.ts +15 -0
- package/dist/_pkgs/affine-block-table/selection-controller.js +62 -0
- package/dist/_pkgs/affine-block-table/table-cell-css.d.ts +7 -0
- package/dist/_pkgs/affine-block-table/table-cell-css.js +10 -0
- package/dist/_pkgs/affine-block-table/table-cell.d.ts +8 -0
- package/dist/_pkgs/affine-block-table/table-cell.js +35 -3
- package/dist/_pkgs/affine-block-table/table-data-manager.d.ts +14 -0
- package/dist/_pkgs/affine-block-table/table-data-manager.js +44 -3
- package/dist/_pkgs/affine-block-table/translations.d.ts +14 -0
- package/dist/_pkgs/affine-block-table/translations.js +22 -0
- package/dist/_pkgs/affine-components/highlight-dropdown-menu/highlight-duotone-icon.js +8 -8
- package/dist/_pkgs/affine-components/highlight-dropdown-menu/text-duotone-icon.js +11 -11
- package/dist/_pkgs/affine-gfx-mindmap/toolbar/mindmap-tool-button.d.ts +2 -2
- package/dist/_pkgs/affine-gfx-template/builtin/other.d.ts +4 -0
- package/dist/_pkgs/affine-gfx-template/builtin/other.js +1 -1
- package/dist/_pkgs/affine-gfx-template/builtin/slides/build.d.ts +81 -0
- package/dist/_pkgs/affine-gfx-template/builtin/slides/build.js +276 -0
- package/dist/_pkgs/affine-gfx-template/builtin/slides/consts.d.ts +126 -0
- package/dist/_pkgs/affine-gfx-template/builtin/slides/consts.js +101 -0
- package/dist/_pkgs/affine-gfx-template/builtin/slides/index.d.ts +8 -0
- package/dist/_pkgs/affine-gfx-template/builtin/slides/index.js +27 -0
- package/dist/_pkgs/affine-gfx-template/builtin/slides/masks.d.ts +83 -0
- package/dist/_pkgs/affine-gfx-template/builtin/slides/masks.js +674 -0
- package/dist/_pkgs/affine-gfx-template/contribute.js +12 -17
- package/dist/_pkgs/affine-gfx-template/make-snapshot.d.ts +14 -2
- package/dist/_pkgs/affine-gfx-template/make-snapshot.js +6 -2
- package/dist/_pkgs/affine-gfx-template/services/template-middlewares.d.ts +12 -0
- package/dist/_pkgs/affine-gfx-template/services/template-middlewares.js +48 -0
- package/dist/_pkgs/affine-gfx-template/services/template.js +2 -1
- package/dist/_pkgs/affine-gfx-template/toolbar/builtin-templates.d.ts +15 -1
- package/dist/_pkgs/affine-gfx-template/toolbar/builtin-templates.js +33 -37
- package/dist/_pkgs/affine-gfx-template/toolbar/template-type.d.ts +6 -0
- package/dist/_pkgs/affine-gfx-template/translations.d.ts +94 -0
- package/dist/_pkgs/affine-gfx-template/translations.js +441 -2
- package/dist/_pkgs/affine-model/blocks/table/table-model.d.ts +4 -0
- package/dist/_pkgs/affine-model/blocks/table/table-model.js +4 -0
- package/dist/_pkgs/affine-model/elements/bpmn/node.d.ts +46 -3
- package/dist/_pkgs/affine-model/elements/bpmn/node.js +47 -4
- package/dist/_pkgs/affine-model/elements/bpmn/pool.d.ts +20 -0
- package/dist/_pkgs/affine-model/elements/bpmn/pool.js +33 -4
- package/dist/_pkgs/affine-model/elements/c4/board.d.ts +0 -22
- package/dist/_pkgs/affine-model/elements/c4/board.js +1 -22
- package/dist/_pkgs/affine-model/elements/c4/consts.d.ts +29 -0
- package/dist/_pkgs/affine-model/elements/c4/consts.js +29 -0
- package/dist/_pkgs/affine-model/elements/c4/index.d.ts +1 -0
- package/dist/_pkgs/affine-model/elements/c4/index.js +1 -0
- package/dist/_pkgs/affine-model/headless.d.ts +1 -0
- package/dist/_pkgs/affine-model/headless.js +1 -0
- package/dist/_pkgs/affine-shared/services/edit-props-store.d.ts +3 -16
- package/dist/_pkgs/affine-shared/services/edit-props-store.js +16 -16
- package/dist/_pkgs/affine-shared/services/editor-setting-service.d.ts +3 -0
- package/dist/_pkgs/affine-shared/services/editor-setting-service.js +4 -0
- package/dist/_pkgs/affine-shared/services/index.d.ts +1 -0
- package/dist/_pkgs/affine-shared/services/index.js +1 -0
- package/dist/_pkgs/affine-shared/services/invisible-characters.d.ts +33 -0
- package/dist/_pkgs/affine-shared/services/invisible-characters.js +63 -0
- package/dist/_pkgs/affine-shared/services/link-preview-service/link-preview-cache.d.ts +0 -9
- package/dist/_pkgs/affine-shared/services/link-preview-service/link-preview-cache.js +3 -9
- package/dist/_pkgs/affine-shared/services/telemetry-service/lifecycle.d.ts +26 -0
- package/dist/_pkgs/affine-shared/services/telemetry-service/telemetry-service.d.ts +4 -3
- package/dist/_pkgs/affine-shared/services/telemetry-service/types.d.ts +11 -0
- package/dist/_pkgs/affine-shared/utils/index.d.ts +1 -0
- package/dist/_pkgs/affine-shared/utils/index.js +1 -0
- package/dist/_pkgs/affine-shared/utils/invisible-characters.d.ts +42 -0
- package/dist/_pkgs/affine-shared/utils/invisible-characters.js +81 -0
- package/dist/_pkgs/affine-widget-edgeless-zoom-toolbar/index.js +26 -26
- package/dist/_pkgs/affine-widget-edgeless-zoom-toolbar/zoom-toolbar.js +13 -2
- package/dist/_pkgs/affine-widget-keyboard-toolbar/icons.js +98 -98
- package/dist/_pkgs/affine-widget-page-dragging-area/index.js +10 -10
- package/dist/_pkgs/affine-widget-viewport-overlay/index.js +13 -13
- package/dist/_pkgs/data-view/core/utils/menu-title.js +17 -17
- package/dist/_pkgs/data-view/view-presets/table/pc/header/column-header.js +6 -0
- package/dist/_pkgs/data-view/view-presets/table/pc/table-view-ui-logic.js +5 -2
- package/dist/_pkgs/std/clipboard/clipboard.d.ts +15 -1
- package/dist/_pkgs/std/clipboard/clipboard.js +18 -0
- package/dist/_pkgs/std/inline/components/embed-gap.js +1 -1
- package/dist/_pkgs/std/inline/components/v-line.js +1 -1
- package/dist/_pkgs/std/inline/components/v-text.d.ts +15 -2
- package/dist/_pkgs/std/inline/components/v-text.js +147 -15
- package/dist/_pkgs/std/inline/consts.d.ts +5 -0
- package/dist/_pkgs/std/inline/consts.js +5 -0
- package/dist/_pkgs/std/inline/utils/index.d.ts +1 -0
- package/dist/_pkgs/std/inline/utils/index.js +1 -0
- package/dist/_pkgs/std/inline/utils/invisible-characters.d.ts +57 -0
- package/dist/_pkgs/std/inline/utils/invisible-characters.js +162 -0
- package/dist/_pkgs/std/inline/utils/point-conversion.js +3 -3
- package/dist/_pkgs/std/inline/utils/text.d.ts +8 -0
- package/dist/_pkgs/std/inline/utils/text.js +11 -2
- package/dist/_pkgs/store/model/store/crud.d.ts +28 -0
- package/dist/_pkgs/store/model/store/crud.js +97 -30
- package/dist/_pkgs/store/model/store/query.js +3 -2
- package/dist/_pkgs/store/model/store/store.d.ts +21 -0
- package/dist/_pkgs/store/model/store/store.js +88 -21
- package/dist/_pkgs/store/transformer/transformer.d.ts +46 -0
- package/dist/_pkgs/store/transformer/transformer.js +72 -0
- package/dist/commands.js +6 -1
- package/dist/translations.js +2 -0
- package/package.json +3 -4
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { estimateBackgroundText } from './band-widths.js';
|
|
2
|
+
/** `undefined` until first asked; `null` where there is no canvas to ask. */
|
|
3
|
+
let offscreen;
|
|
4
|
+
/**
|
|
5
|
+
* Measure background text with no painting context at hand — a hit test runs on
|
|
6
|
+
* a pointer event, not inside a paint — for `backgroundBandWidths`.
|
|
7
|
+
*
|
|
8
|
+
* A module-level offscreen 2D context where a document exists, so a hit box is
|
|
9
|
+
* measured with the same metrics the canvas paints with, and a band a long name
|
|
10
|
+
* widened is aimed at where it is drawn; the estimate where there is no
|
|
11
|
+
* document, or where the DOM is a test double that cannot measure.
|
|
12
|
+
*
|
|
13
|
+
* In a file of its own, out of the `./interchange` graph: `band-widths.ts` is
|
|
14
|
+
* reachable from that headless entry and must not touch the DOM
|
|
15
|
+
* (`interchange-headless.unit.spec.ts` in `affine/all`).
|
|
16
|
+
*/
|
|
17
|
+
export function measureBackgroundText(text, font) {
|
|
18
|
+
if (offscreen === undefined) {
|
|
19
|
+
offscreen =
|
|
20
|
+
typeof document === 'undefined'
|
|
21
|
+
? null
|
|
22
|
+
: (document.createElement('canvas').getContext?.('2d') ?? null);
|
|
23
|
+
}
|
|
24
|
+
if (offscreen) {
|
|
25
|
+
offscreen.font = font;
|
|
26
|
+
const width = offscreen.measureText(text)?.width;
|
|
27
|
+
if (typeof width === 'number' && Number.isFinite(width))
|
|
28
|
+
return width;
|
|
29
|
+
}
|
|
30
|
+
return estimateBackgroundText(text, font);
|
|
31
|
+
}
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import type { GfxPrimitiveElementModel } from '../../std/gfx/index.js';
|
|
2
2
|
import type { ElementRenderer } from '../renderer/elements/index.js';
|
|
3
3
|
import type { FrameworkBackgroundDef } from './def.js';
|
|
4
|
+
import { type BackgroundBandLayout } from './band-widths.js';
|
|
5
|
+
/** What a framework may ask of the renderer beyond the declaration. */
|
|
6
|
+
export interface FrameworkBackgroundRendererOptions<T> {
|
|
7
|
+
/**
|
|
8
|
+
* Called on every paint with the band widths that paint measured
|
|
9
|
+
* (`backgroundBandWidths`), before anything is drawn. Named consumer: the
|
|
10
|
+
* BPMN pool, which caches them on its model (`paintedBands`, a `@local()`
|
|
11
|
+
* field, never stored) so that picking — which asks the headless model —
|
|
12
|
+
* selects by the bands as painted. A consumer that writes must write only
|
|
13
|
+
* when the widths changed: a local write repaints.
|
|
14
|
+
*/
|
|
15
|
+
onBands?: (model: T, layout: BackgroundBandLayout) => void;
|
|
16
|
+
}
|
|
4
17
|
/**
|
|
5
18
|
* Build the canvas renderer of one declaration. Pure: the same declaration
|
|
6
19
|
* always paints the same picture for the same model and size.
|
|
7
20
|
*/
|
|
8
|
-
export declare function createFrameworkBackgroundRenderer<T extends GfxPrimitiveElementModel>(def: FrameworkBackgroundDef): ElementRenderer<T>;
|
|
21
|
+
export declare function createFrameworkBackgroundRenderer<T extends GfxPrimitiveElementModel>(def: FrameworkBackgroundDef, options?: FrameworkBackgroundRendererOptions<T>): ElementRenderer<T>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { TranslationProvider } from '../../affine-shared/services/index.js';
|
|
2
2
|
import { notationColor, } from '../renderer/notation-tint.js';
|
|
3
3
|
import { backgroundColor, backgroundInstanceZoneBand, backgroundInstanceZones, backgroundPlot, backgroundPoint, BROKEN_BACKGROUND_COLOR, DEFAULT_BACKGROUND_SURFACE, warnBrokenBackgroundColor, } from './def.js';
|
|
4
|
+
import { backgroundBandWidths, backgroundFont, backgroundTextRoom, backgroundWrapLineHeight, DEFAULT_BACKGROUND_FONT_FAMILY, } from './band-widths.js';
|
|
5
|
+
import { BACKGROUND_TEXT_FIT_PADDING, ellipsizeToWidth } from './ellipsis.js';
|
|
4
6
|
import { backgroundInVariant, backgroundLabelText, backgroundTexts, backgroundVisible, } from './labels.js';
|
|
5
7
|
/**
|
|
6
8
|
* The framework-background PRIMITIVE (PF2.1): one renderer, driven entirely by
|
|
@@ -79,13 +81,6 @@ function rgba(hex, alpha) {
|
|
|
79
81
|
const b = parseInt(hex.slice(5, 7), 16);
|
|
80
82
|
return `rgba(${r},${g},${b},${alpha})`;
|
|
81
83
|
}
|
|
82
|
-
function fontOf(style, fallbackFamily) {
|
|
83
|
-
const italic = style.italic ? 'italic ' : '';
|
|
84
|
-
const weight = style.weight ? `${style.weight} ` : '';
|
|
85
|
-
return `${italic}${weight}${style.size}px ${style.family ?? fallbackFamily}`;
|
|
86
|
-
}
|
|
87
|
-
/** The family a declaration that names none falls back to. */
|
|
88
|
-
const DEFAULT_FONT_FAMILY = 'Inter, sans-serif';
|
|
89
84
|
/**
|
|
90
85
|
* Where an instance zone's name sits in its band when the declaration states no
|
|
91
86
|
* offset: 8 model units in from the leading edge, 18 down from the top of the
|
|
@@ -103,9 +98,9 @@ const DEFAULT_INSTANCE_ZONE_LABEL_DY = 18;
|
|
|
103
98
|
* Build the canvas renderer of one declaration. Pure: the same declaration
|
|
104
99
|
* always paints the same picture for the same model and size.
|
|
105
100
|
*/
|
|
106
|
-
export function createFrameworkBackgroundRenderer(def) {
|
|
101
|
+
export function createFrameworkBackgroundRenderer(def, options = {}) {
|
|
107
102
|
const palette = def.chrome?.palette;
|
|
108
|
-
const family = def.chrome?.fontFamily ??
|
|
103
|
+
const family = def.chrome?.fontFamily ?? DEFAULT_BACKGROUND_FONT_FAMILY;
|
|
109
104
|
const surface = def.chrome?.surface ?? DEFAULT_BACKGROUND_SURFACE;
|
|
110
105
|
const declared = (c) => backgroundColor(c, palette);
|
|
111
106
|
const texts = backgroundTexts(def);
|
|
@@ -140,7 +135,16 @@ export function createFrameworkBackgroundRenderer(def) {
|
|
|
140
135
|
.translateSelf(cx, cy)
|
|
141
136
|
.rotateSelf(model.rotate)
|
|
142
137
|
.translateSelf(-cx, -cy));
|
|
143
|
-
|
|
138
|
+
// The bands as thick as their wrapped labels need, measured on this very
|
|
139
|
+
// context so the band holds exactly the lines painted in it. Every piece of
|
|
140
|
+
// chrome below paints from this plot; a declaration that wraps nothing gets
|
|
141
|
+
// its declared margin back without a measurement.
|
|
142
|
+
const layout = backgroundBandWidths(def, props, w, h, (text, font) => {
|
|
143
|
+
ctx.font = font;
|
|
144
|
+
return ctx.measureText(text).width;
|
|
145
|
+
}, translation);
|
|
146
|
+
options.onBands?.(model, layout);
|
|
147
|
+
const plot = backgroundPlot(def, w, h, layout.margin);
|
|
144
148
|
const { x0, y0, x1, y1 } = plot;
|
|
145
149
|
const pw = plot.width;
|
|
146
150
|
const ph = plot.height;
|
|
@@ -150,26 +154,60 @@ export function createFrameworkBackgroundRenderer(def) {
|
|
|
150
154
|
ctx.lineTo(bx, by);
|
|
151
155
|
ctx.stroke();
|
|
152
156
|
};
|
|
153
|
-
const drawText = (words, ax, ay, style, align, vertical
|
|
157
|
+
const drawText = (words, ax, ay, style, align, vertical,
|
|
158
|
+
/**
|
|
159
|
+
* The length the words may take, in model units; absent draws them
|
|
160
|
+
* whole. Measured AFTER the font is set, so the cut is in the font the
|
|
161
|
+
* words are drawn in.
|
|
162
|
+
*/
|
|
163
|
+
room,
|
|
164
|
+
/**
|
|
165
|
+
* The lines a wrapped label was broken into by `backgroundBandWidths`,
|
|
166
|
+
* drawn instead of `words`: stacked ACROSS the text's direction and
|
|
167
|
+
* centred on the anchor, one line height apart. Taken from the resolver
|
|
168
|
+
* rather than wrapped again here, so the band and its lines are one
|
|
169
|
+
* measurement.
|
|
170
|
+
*/
|
|
171
|
+
wrapped) => {
|
|
154
172
|
if (!words)
|
|
155
173
|
return;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
174
|
+
const font = backgroundFont(style, family);
|
|
175
|
+
let shown;
|
|
176
|
+
if (wrapped)
|
|
177
|
+
shown = wrapped;
|
|
178
|
+
else if (room === undefined)
|
|
179
|
+
shown = [words];
|
|
180
|
+
else {
|
|
181
|
+
ctx.font = font;
|
|
182
|
+
shown = [ellipsizeToWidth(ctx, words, room)];
|
|
183
|
+
}
|
|
184
|
+
const lineHeight = backgroundWrapLineHeight(style);
|
|
185
|
+
shown.forEach((text, i) => {
|
|
186
|
+
if (!text)
|
|
187
|
+
return;
|
|
188
|
+
// Zero for a single line, which is drawn exactly where it always was.
|
|
189
|
+
const across = (i - (shown.length - 1) / 2) * lineHeight;
|
|
190
|
+
if (vertical) {
|
|
191
|
+
// Rotated -90°, the next line is to the RIGHT of the one before:
|
|
192
|
+
// the glyphs' tops point left, so a reader turning their head reads
|
|
193
|
+
// the lines left to right.
|
|
194
|
+
ctx.save();
|
|
195
|
+
ctx.translate(ax + across, ay);
|
|
196
|
+
ctx.rotate(-Math.PI / 2);
|
|
197
|
+
ctx.font = font;
|
|
198
|
+
ctx.fillStyle = color(style.color);
|
|
199
|
+
ctx.textAlign = align ?? 'center';
|
|
200
|
+
ctx.textBaseline = style.baseline ?? 'alphabetic';
|
|
201
|
+
ctx.fillText(text, 0, 0);
|
|
202
|
+
ctx.restore();
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
ctx.font = font;
|
|
161
206
|
ctx.fillStyle = color(style.color);
|
|
162
|
-
ctx.textAlign = align ?? '
|
|
207
|
+
ctx.textAlign = align ?? 'left';
|
|
163
208
|
ctx.textBaseline = style.baseline ?? 'alphabetic';
|
|
164
|
-
ctx.fillText(
|
|
165
|
-
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
ctx.font = fontOf(style, family);
|
|
169
|
-
ctx.fillStyle = color(style.color);
|
|
170
|
-
ctx.textAlign = align ?? 'left';
|
|
171
|
-
ctx.textBaseline = style.baseline ?? 'alphabetic';
|
|
172
|
-
ctx.fillText(words, ax, ay);
|
|
209
|
+
ctx.fillText(text, ax, ay + across);
|
|
210
|
+
});
|
|
173
211
|
};
|
|
174
212
|
// ── 1. The card, and the bands that dress it ────────────────────────
|
|
175
213
|
const border = surface.border;
|
|
@@ -330,8 +368,18 @@ export function createFrameworkBackgroundRenderer(def) {
|
|
|
330
368
|
continue;
|
|
331
369
|
if (!visible(text.visibleProp))
|
|
332
370
|
continue;
|
|
333
|
-
const [
|
|
334
|
-
|
|
371
|
+
const [px, py] = backgroundPoint(text.anchor, plot);
|
|
372
|
+
// A wrapped band label keeps its place relative to the middle of its
|
|
373
|
+
// band, however much the band grew (`BackgroundWrappedLabel.shift`).
|
|
374
|
+
const wrap = layout.labels.get(text);
|
|
375
|
+
const tx = px + (wrap?.shift[0] ?? 0);
|
|
376
|
+
const ty = py + (wrap?.shift[1] ?? 0);
|
|
377
|
+
const vertical = text.vertical === true;
|
|
378
|
+
drawText(backgroundLabelText(text, props, translation), tx, ty, text.style, text.align, vertical,
|
|
379
|
+
// `'wrap'` on a text with no band to grow is cut like `'ellipsis'`.
|
|
380
|
+
text.fit !== undefined
|
|
381
|
+
? backgroundTextRoom(tx, ty, text.align, vertical, w, h)
|
|
382
|
+
: undefined, wrap?.lines);
|
|
335
383
|
}
|
|
336
384
|
// The instance's own zone names, after the declared texts — the same order
|
|
337
385
|
// the audit reports them in, and the same reason: what the framework says
|
|
@@ -350,6 +398,7 @@ export function createFrameworkBackgroundRenderer(def) {
|
|
|
350
398
|
const dx = zoneLabel.dx ?? DEFAULT_INSTANCE_ZONE_LABEL_DX;
|
|
351
399
|
const dy = zoneLabel.dy ?? DEFAULT_INSTANCE_ZONE_LABEL_DY;
|
|
352
400
|
const stackY = instanceZonesDef?.stack === 'y';
|
|
401
|
+
const fitZone = zoneLabel.fit !== undefined;
|
|
353
402
|
for (const zone of instanceZones) {
|
|
354
403
|
// The strip is drawn for EVERY zone, named or not: it is the lane's
|
|
355
404
|
// title band, and a lane whose name has been cleared still has one —
|
|
@@ -357,7 +406,7 @@ export function createFrameworkBackgroundRenderer(def) {
|
|
|
357
406
|
// a lane that silently loses its structure. The NAME is what is
|
|
358
407
|
// conditional, exactly as under the corner placement.
|
|
359
408
|
const strip = labelBand
|
|
360
|
-
? backgroundInstanceZoneBand(def, zone, plot)
|
|
409
|
+
? backgroundInstanceZoneBand(def, zone, plot, layout.zoneBandWidth)
|
|
361
410
|
: null;
|
|
362
411
|
if (strip && labelBand?.divider) {
|
|
363
412
|
const divider = labelBand.divider;
|
|
@@ -386,10 +435,14 @@ export function createFrameworkBackgroundRenderer(def) {
|
|
|
386
435
|
// strip, and a baseline anchor there would push the words against the
|
|
387
436
|
// divider.
|
|
388
437
|
const style = { ...zoneLabel.style, baseline: 'middle' };
|
|
389
|
-
drawText(zone.name, strip.x + strip.w / 2, strip.y + strip.h / 2, style, 'center', stackY
|
|
438
|
+
drawText(zone.name, strip.x + strip.w / 2, strip.y + strip.h / 2, style, 'center', stackY, fitZone
|
|
439
|
+
? (stackY ? strip.h : strip.w) - 2 * BACKGROUND_TEXT_FIT_PADDING
|
|
440
|
+
: undefined, layout.zoneLines.get(zone.id));
|
|
390
441
|
continue;
|
|
391
442
|
}
|
|
392
|
-
drawText(zone.name, x0 + zone.rect.x * pw + dx, y0 + zone.rect.y * ph + dy, zoneLabel.style, 'left', false
|
|
443
|
+
drawText(zone.name, x0 + zone.rect.x * pw + dx, y0 + zone.rect.y * ph + dy, zoneLabel.style, 'left', false, fitZone
|
|
444
|
+
? zone.rect.w * pw - dx - BACKGROUND_TEXT_FIT_PADDING
|
|
445
|
+
: undefined);
|
|
393
446
|
}
|
|
394
447
|
}
|
|
395
448
|
};
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
*/
|
|
19
19
|
export * from './extensions/export-svg/marker-version.js';
|
|
20
20
|
export * from './extensions/interchange.js';
|
|
21
|
+
export * from './extensions/toolbox.js';
|
|
22
|
+
export * from './extensions/legend-label.js';
|
|
21
23
|
export * from './extensions/legend-role.js';
|
|
22
24
|
export * from './extensions/svg-sanitize.js';
|
|
23
25
|
export * from './extensions/svg-sketch.js';
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
*/
|
|
19
19
|
export * from './extensions/export-svg/marker-version.js';
|
|
20
20
|
export * from './extensions/interchange.js';
|
|
21
|
+
export * from './extensions/toolbox.js';
|
|
22
|
+
export * from './extensions/legend-label.js';
|
|
21
23
|
export * from './extensions/legend-role.js';
|
|
22
24
|
export * from './extensions/svg-sanitize.js';
|
|
23
25
|
export * from './extensions/svg-sketch.js';
|
|
@@ -42,12 +42,12 @@ export const tableBlockHtmlAdapterMatcher = {
|
|
|
42
42
|
fromBlockSnapshot: {
|
|
43
43
|
enter: (o, context) => {
|
|
44
44
|
const { walkerContext } = context;
|
|
45
|
-
const { columns, rows, cells } = o.node
|
|
45
|
+
const { columns, rows, cells, headerRow, headerColumn } = o.node
|
|
46
46
|
.props;
|
|
47
47
|
const table = processTable(columns, rows, cells);
|
|
48
|
-
const createAstTableCell = (children) => ({
|
|
48
|
+
const createAstTableCell = (children, header) => ({
|
|
49
49
|
type: 'element',
|
|
50
|
-
tagName: 'td',
|
|
50
|
+
tagName: header ? 'th' : 'td',
|
|
51
51
|
properties: Object.create(null),
|
|
52
52
|
children: [
|
|
53
53
|
{
|
|
@@ -67,18 +67,30 @@ export const tableBlockHtmlAdapterMatcher = {
|
|
|
67
67
|
children: cells,
|
|
68
68
|
});
|
|
69
69
|
const { deltaConverter } = context;
|
|
70
|
-
|
|
70
|
+
// ADR 0043: the header row goes in a `thead`, header cells are `th`.
|
|
71
|
+
const hasHeaderRow = headerRow === true && table.rows.length > 0;
|
|
72
|
+
const hasHeaderColumn = headerColumn === true;
|
|
73
|
+
const astRows = table.rows.map((v, rowIndex) => {
|
|
74
|
+
return createAstTableRow(v.cells.map((cell, columnIndex) => {
|
|
75
|
+
return createAstTableCell(typeof cell.value === 'string'
|
|
76
|
+
? [{ type: 'text', value: cell.value }]
|
|
77
|
+
: deltaConverter.deltaToAST(cell.value.delta), (hasHeaderRow && rowIndex === 0) ||
|
|
78
|
+
(hasHeaderColumn && columnIndex === 0));
|
|
79
|
+
}));
|
|
80
|
+
});
|
|
81
|
+
const section = (tagName, children) => ({
|
|
71
82
|
type: 'element',
|
|
72
|
-
tagName
|
|
83
|
+
tagName,
|
|
73
84
|
properties: Object.create(null),
|
|
74
|
-
children
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
children,
|
|
86
|
+
});
|
|
87
|
+
const tableChildren = hasHeaderRow
|
|
88
|
+
? [section('thead', astRows.slice(0, 1))]
|
|
89
|
+
: [];
|
|
90
|
+
const bodyRows = hasHeaderRow ? astRows.slice(1) : astRows;
|
|
91
|
+
if (!hasHeaderRow || bodyRows.length > 0) {
|
|
92
|
+
tableChildren.push(section('tbody', bodyRows));
|
|
93
|
+
}
|
|
82
94
|
walkerContext
|
|
83
95
|
.openNode({
|
|
84
96
|
type: 'element',
|
|
@@ -87,7 +99,7 @@ export const tableBlockHtmlAdapterMatcher = {
|
|
|
87
99
|
border: true,
|
|
88
100
|
style: 'border-collapse: collapse;border-spacing: 0;',
|
|
89
101
|
},
|
|
90
|
-
children:
|
|
102
|
+
children: tableChildren,
|
|
91
103
|
})
|
|
92
104
|
.closeNode();
|
|
93
105
|
walkerContext.skipAllChildren();
|
|
@@ -28,6 +28,7 @@ export declare const createTableProps: (deltasLists: RichTextType[][]) => {
|
|
|
28
28
|
};
|
|
29
29
|
export declare const parseTableFromHtml: (element: Element, astToDelta: (ast: HtmlAST) => RichTextType) => TableBlockPropsSerialized;
|
|
30
30
|
export declare const parseTableFromMarkdown: (node: MarkdownTable, astToDelta: (ast: MarkdownAST) => RichTextType) => {
|
|
31
|
+
headerRow: true;
|
|
31
32
|
columns: {
|
|
32
33
|
[k: string]: TableColumn;
|
|
33
34
|
};
|
|
@@ -115,11 +115,23 @@ export const createTableProps = (deltasLists) => {
|
|
|
115
115
|
cells,
|
|
116
116
|
};
|
|
117
117
|
};
|
|
118
|
+
/**
|
|
119
|
+
* A row's cells in order, `td` and `th` alike: a body row may open on a `th`
|
|
120
|
+
* (a header column, which the HTML export writes since ADR 0043), and keeping
|
|
121
|
+
* only `td` dropped that cell.
|
|
122
|
+
*/
|
|
123
|
+
const rowCells = (tr) => tr.children.filter((child) => HastUtils.isElement(child) &&
|
|
124
|
+
(child.tagName === 'td' || child.tagName === 'th'));
|
|
118
125
|
export const parseTableFromHtml = (element, astToDelta) => {
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
const
|
|
126
|
+
const heads = getAllTag(element, 'thead');
|
|
127
|
+
const headerRows = heads.flatMap(node => getAllTag(node, 'tr').map(rowCells));
|
|
128
|
+
const bodyRows = getAllTag(element, 'tbody').flatMap(node => getAllTag(node, 'tr').map(rowCells));
|
|
129
|
+
const footerRows = getAllTag(element, 'tfoot').flatMap(node => getAllTag(node, 'tr').map(rowCells));
|
|
122
130
|
const allRows = [...headerRows, ...bodyRows, ...footerRows];
|
|
131
|
+
// ADR 0043: a `thead` is a header row; a body whose every row opens on a
|
|
132
|
+
// `th` is a header column. `true` or absent, never `false`.
|
|
133
|
+
const headerRow = heads.length > 0;
|
|
134
|
+
const headerColumn = bodyRows.length > 0 && bodyRows.every(cells => cells[0]?.tagName === 'th');
|
|
123
135
|
const rowTextLists = [];
|
|
124
136
|
allRows.forEach(cells => {
|
|
125
137
|
const row = [];
|
|
@@ -128,7 +140,11 @@ export const parseTableFromHtml = (element, astToDelta) => {
|
|
|
128
140
|
});
|
|
129
141
|
rowTextLists.push(row);
|
|
130
142
|
});
|
|
131
|
-
return
|
|
143
|
+
return {
|
|
144
|
+
...createTableProps(rowTextLists),
|
|
145
|
+
...(headerRow ? { headerRow: true } : {}),
|
|
146
|
+
...(headerColumn ? { headerColumn: true } : {}),
|
|
147
|
+
};
|
|
132
148
|
};
|
|
133
149
|
/**
|
|
134
150
|
* A cell holds rich text, and no inline matcher turns an `image` into a delta:
|
|
@@ -162,5 +178,7 @@ export const parseTableFromMarkdown = (node, astToDelta) => {
|
|
|
162
178
|
});
|
|
163
179
|
rowTextLists.push(rowText);
|
|
164
180
|
});
|
|
165
|
-
|
|
181
|
+
// GFM has no table without a header row: the first row always was one
|
|
182
|
+
// (ADR 0043).
|
|
183
|
+
return { ...createTableProps(rowTextLists), headerRow: true };
|
|
166
184
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BlockStdScope } from '../std/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The "Header row" / "Header column" item of the first row's / first
|
|
4
|
+
* column's menu (ADR 0043): a plain action with the menu's check mark, the
|
|
5
|
+
* toggle-switch row of `menu.toggleSwitch` hands its click the value it was
|
|
6
|
+
* built with.
|
|
7
|
+
*
|
|
8
|
+
* Kept out of `table-cell.ts` on purpose: the literal guard treats every
|
|
9
|
+
* literal of a file that calls `translateKey` as covered when it equals some
|
|
10
|
+
* fallback, and the cell menus' older labels ("Copy", "Delete"…) are still
|
|
11
|
+
* untranslated literals its baseline must keep seeing.
|
|
12
|
+
*/
|
|
13
|
+
export declare function headerToggleMenuItem(std: BlockStdScope | undefined, kind: 'row' | 'column', on: boolean, toggle: (on: boolean) => void): (menu: import("../affine-components/context-menu/menu.js").Menu) => import("lit-html").TemplateResult<1> | undefined;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { menu } from '../affine-components/context-menu/index.js';
|
|
2
|
+
import { translateKey } from '../affine-shared/services/index.js';
|
|
3
|
+
import { HeaderColumnIcon, HeaderRowIcon } from '@blocksuite/icons/lit';
|
|
4
|
+
import { TABLE_HEADER_COLUMN, TABLE_HEADER_ROW } from './translations.js';
|
|
5
|
+
/**
|
|
6
|
+
* The "Header row" / "Header column" item of the first row's / first
|
|
7
|
+
* column's menu (ADR 0043): a plain action with the menu's check mark, the
|
|
8
|
+
* toggle-switch row of `menu.toggleSwitch` hands its click the value it was
|
|
9
|
+
* built with.
|
|
10
|
+
*
|
|
11
|
+
* Kept out of `table-cell.ts` on purpose: the literal guard treats every
|
|
12
|
+
* literal of a file that calls `translateKey` as covered when it equals some
|
|
13
|
+
* fallback, and the cell menus' older labels ("Copy", "Delete"…) are still
|
|
14
|
+
* untranslated literals its baseline must keep seeing.
|
|
15
|
+
*/
|
|
16
|
+
export function headerToggleMenuItem(std, kind, on, toggle) {
|
|
17
|
+
const wording = kind === 'row' ? TABLE_HEADER_ROW : TABLE_HEADER_COLUMN;
|
|
18
|
+
return menu.action({
|
|
19
|
+
name: std ? translateKey(std, ...wording) : wording[1],
|
|
20
|
+
prefix: kind === 'row' ? HeaderRowIcon() : HeaderColumnIcon(),
|
|
21
|
+
isSelected: on,
|
|
22
|
+
testId: `table-header-${kind}-toggle`,
|
|
23
|
+
select: () => toggle(!on),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -2,6 +2,13 @@ import type { UIEventStateContext } from '../std/index.js';
|
|
|
2
2
|
import type { ReactiveController } from 'lit';
|
|
3
3
|
import { type TableAreaSelection, TableSelectionData } from './selection-schema.js';
|
|
4
4
|
import type { TableBlockComponent } from './table-block.js';
|
|
5
|
+
/**
|
|
6
|
+
* The width that makes a column end where the table's scroll box ends: what
|
|
7
|
+
* the box offers minus what the other columns already take, never below
|
|
8
|
+
* `ColumnMinWidth`. `undefined` when nothing is left to give, so the caller
|
|
9
|
+
* writes nothing.
|
|
10
|
+
*/
|
|
11
|
+
export declare function remainingColumnWidth(available: number, otherColumnsWidth: number): number | undefined;
|
|
5
12
|
export declare class SelectionController implements ReactiveController {
|
|
6
13
|
readonly host: TableBlockComponent;
|
|
7
14
|
constructor(host: TableBlockComponent);
|
|
@@ -16,6 +23,14 @@ export declare class SelectionController implements ReactiveController {
|
|
|
16
23
|
private get clipboard();
|
|
17
24
|
private get scale();
|
|
18
25
|
widthAdjust(dragHandle: HTMLElement, event: MouseEvent): void;
|
|
26
|
+
/**
|
|
27
|
+
* Double-click on a column's resize handle: the column takes the room left
|
|
28
|
+
* between the table and the right edge of its scroll box. Measured in the
|
|
29
|
+
* table's own unscaled pixels (`clientWidth` ignores the edgeless zoom, the
|
|
30
|
+
* cells' rects do not, hence `getScale()`); the container's own padding and
|
|
31
|
+
* the virtual padding around the table are not room a column can take.
|
|
32
|
+
*/
|
|
33
|
+
fitColumnToRemainingSpace(columnId: string): void;
|
|
19
34
|
dragListener(): void;
|
|
20
35
|
startColumnDrag(x: number, columnDragHandle: HTMLElement): {
|
|
21
36
|
onMove: (x: number) => void;
|
|
@@ -3,9 +3,23 @@ import { IS_MOBILE } from '../global/env/index.js';
|
|
|
3
3
|
import { computed } from '@preact/signals-core';
|
|
4
4
|
import { ColumnMinWidth, DefaultColumnWidth } from './consts.js';
|
|
5
5
|
import { TableSelection, TableSelectionData, } from './selection-schema.js';
|
|
6
|
+
import { tableContainer } from './table-block-css.js';
|
|
6
7
|
import { createColumnDragPreview, createRowDragPreview, TableCellComponentName, } from './table-cell.js';
|
|
7
8
|
import { cleanSelection, isTableDragHandle } from './utils.js';
|
|
8
9
|
const TEXT = 'text/plain';
|
|
10
|
+
/**
|
|
11
|
+
* The width that makes a column end where the table's scroll box ends: what
|
|
12
|
+
* the box offers minus what the other columns already take, never below
|
|
13
|
+
* `ColumnMinWidth`. `undefined` when nothing is left to give, so the caller
|
|
14
|
+
* writes nothing.
|
|
15
|
+
*/
|
|
16
|
+
export function remainingColumnWidth(available, otherColumnsWidth) {
|
|
17
|
+
const remainder = Math.floor(available - otherColumnsWidth);
|
|
18
|
+
if (!Number.isFinite(remainder) || remainder <= 0)
|
|
19
|
+
return;
|
|
20
|
+
return Math.max(ColumnMinWidth, remainder);
|
|
21
|
+
}
|
|
22
|
+
const px = (value) => parseFloat(value) || 0;
|
|
9
23
|
export class SelectionController {
|
|
10
24
|
constructor(host) {
|
|
11
25
|
this.host = host;
|
|
@@ -221,10 +235,58 @@ export class SelectionController {
|
|
|
221
235
|
window.addEventListener('mousemove', onMove);
|
|
222
236
|
window.addEventListener('mouseup', onUp);
|
|
223
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Double-click on a column's resize handle: the column takes the room left
|
|
240
|
+
* between the table and the right edge of its scroll box. Measured in the
|
|
241
|
+
* table's own unscaled pixels (`clientWidth` ignores the edgeless zoom, the
|
|
242
|
+
* cells' rects do not, hence `getScale()`); the container's own padding and
|
|
243
|
+
* the virtual padding around the table are not room a column can take.
|
|
244
|
+
*/
|
|
245
|
+
fitColumnToRemainingSpace(columnId) {
|
|
246
|
+
if (this.dataManager.readonly$.peek())
|
|
247
|
+
return;
|
|
248
|
+
const container = this.host.querySelector(`.${tableContainer}`);
|
|
249
|
+
const firstRow = this.host.querySelector('tr');
|
|
250
|
+
if (!container || !firstRow)
|
|
251
|
+
return;
|
|
252
|
+
const containerStyle = getComputedStyle(container);
|
|
253
|
+
const inner = container.firstElementChild;
|
|
254
|
+
const innerStyle = inner instanceof HTMLElement ? getComputedStyle(inner) : undefined;
|
|
255
|
+
const available = container.clientWidth -
|
|
256
|
+
px(containerStyle.paddingLeft) -
|
|
257
|
+
px(containerStyle.paddingRight) -
|
|
258
|
+
px(innerStyle?.paddingLeft ?? '') -
|
|
259
|
+
px(innerStyle?.paddingRight ?? '');
|
|
260
|
+
const scale = this.scale;
|
|
261
|
+
let others = 0;
|
|
262
|
+
firstRow
|
|
263
|
+
.querySelectorAll('td[data-column-id]')
|
|
264
|
+
.forEach(cell => {
|
|
265
|
+
if (cell.dataset['columnId'] === columnId)
|
|
266
|
+
return;
|
|
267
|
+
others += cell.getBoundingClientRect().width / scale;
|
|
268
|
+
});
|
|
269
|
+
const width = remainingColumnWidth(available, others);
|
|
270
|
+
if (width === undefined)
|
|
271
|
+
return;
|
|
272
|
+
this.dataManager.setColumnWidth(columnId, width);
|
|
273
|
+
}
|
|
224
274
|
dragListener() {
|
|
225
275
|
if (IS_MOBILE || this.dataManager.readonly$.value) {
|
|
226
276
|
return;
|
|
227
277
|
}
|
|
278
|
+
this.host.disposables.addFromEvent(this.host, 'dblclick', event => {
|
|
279
|
+
const target = event.target;
|
|
280
|
+
if (!(target instanceof HTMLElement))
|
|
281
|
+
return;
|
|
282
|
+
const handle = target.closest('[data-width-adjust-column-id]');
|
|
283
|
+
const columnId = handle?.dataset['widthAdjustColumnId'];
|
|
284
|
+
if (!columnId)
|
|
285
|
+
return;
|
|
286
|
+
event.preventDefault();
|
|
287
|
+
event.stopPropagation();
|
|
288
|
+
this.fitColumnToRemainingSpace(columnId);
|
|
289
|
+
});
|
|
228
290
|
// Keep the pointer sequence inside the table too: in edgeless the canvas
|
|
229
291
|
// listens for `pointerdown` and would start dragging the block.
|
|
230
292
|
this.host.disposables.addFromEvent(this.host, 'pointerdown', event => {
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export declare const cellContainerStyle: string;
|
|
2
|
+
/**
|
|
3
|
+
* A header cell (ADR 0043). Only a class, so an explicit row or column
|
|
4
|
+
* background — written inline by `tdStyle` — still wins over the tint. Not
|
|
5
|
+
* `table.headerBackground.default`: that token is the page colour in both
|
|
6
|
+
* themes, so the tint would not show.
|
|
7
|
+
*/
|
|
8
|
+
export declare const headerCellStyle: string;
|
|
2
9
|
export declare const columnOptionsCellStyle: string;
|
|
3
10
|
export declare const columnOptionsStyle: string;
|
|
4
11
|
export declare const rowOptionsCellStyle: string;
|
|
@@ -10,6 +10,16 @@ export const cellContainerStyle = css({
|
|
|
10
10
|
textAlign: 'start',
|
|
11
11
|
verticalAlign: 'top',
|
|
12
12
|
});
|
|
13
|
+
/**
|
|
14
|
+
* A header cell (ADR 0043). Only a class, so an explicit row or column
|
|
15
|
+
* background — written inline by `tdStyle` — still wins over the tint. Not
|
|
16
|
+
* `table.headerBackground.default`: that token is the page colour in both
|
|
17
|
+
* themes, so the tint would not show.
|
|
18
|
+
*/
|
|
19
|
+
export const headerCellStyle = css({
|
|
20
|
+
fontWeight: 600,
|
|
21
|
+
backgroundColor: cssVarV2.layer.background.secondary,
|
|
22
|
+
});
|
|
13
23
|
export const columnOptionsCellStyle = css({
|
|
14
24
|
position: 'absolute',
|
|
15
25
|
height: '0',
|
|
@@ -23,6 +23,13 @@ export declare class TableCell extends TableCell_base {
|
|
|
23
23
|
get hoverRowIndex$(): import("@preact/signals-core").Signal<number | undefined>;
|
|
24
24
|
get inlineManager(): import("../std/inline/index.js").InlineManager<import("../affine-shared/types/index.js").AffineTextAttributes> | undefined;
|
|
25
25
|
get topContenteditableElement(): import("../std/index.js").BlockComponent<import("../store/index.js").BlockModel<object>, import("../std/index.js").BlockService, string> | null | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* The header toggle sits in the first row's / first column's menu only: the
|
|
28
|
+
* header is positional (ADR 0043), so no other row could be the one it
|
|
29
|
+
* marks.
|
|
30
|
+
*/
|
|
31
|
+
private headerToggle;
|
|
32
|
+
private get isHeader();
|
|
26
33
|
openColumnOptions(target: PopupTarget, column: TableColumn, columnIndex: number): void;
|
|
27
34
|
openRowOptions(target: PopupTarget, row: TableRow, rowIndex: number): void;
|
|
28
35
|
createColorPickerMenu(currentColor: string | undefined, select: (color?: string) => void): (menu: import("../affine-components/context-menu/menu.js").Menu) => import("lit-html").TemplateResult<1> | undefined;
|
|
@@ -43,6 +50,7 @@ export declare class TableCell extends TableCell_base {
|
|
|
43
50
|
private readonly _handleKeyDown;
|
|
44
51
|
connectedCallback(): void;
|
|
45
52
|
firstUpdated(): void;
|
|
53
|
+
private tdClass;
|
|
46
54
|
render(): import("lit-html").TemplateResult<1>;
|
|
47
55
|
}
|
|
48
56
|
export declare const createColumnDragPreview: (cells: TableCell[]) => HTMLDivElement;
|