frappe-ui 1.0.0-rc.2 → 1.0.1
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/experimental/TextEditor/TextEditor.vue +7 -0
- package/package.json +7 -5
- package/readme.md +1 -1
- package/src/charts/FunnelChart.vue +6 -5
- package/src/charts/axisChartCommon.ts +100 -33
- package/src/charts/axisChartOptions.ts +14 -37
- package/src/charts/axisFormat.ts +21 -1
- package/src/charts/core/dataLabelFit.ts +88 -0
- package/src/charts/core/useAxisChart.ts +40 -8
- package/src/charts/scatterOptions.ts +1 -6
- package/src/charts/types.ts +6 -6
- package/src/components/Checkbox/Checkbox.vue +8 -4
- package/src/components/Combobox/Combobox.vue +17 -7
- package/src/components/Combobox/ComboboxResults.vue +2 -0
- package/src/components/PageHeader/PageHeaderMobile.vue +2 -2
- package/src/components/Progress/Progress.md +2 -2
- package/src/components/Progress/Progress.vue +4 -5
- package/src/components/SidebarRail/SidebarRail.api.md +1 -1
- package/src/components/SidebarRail/SidebarRail.md +3 -1
- package/src/components/SidebarRail/SidebarRailItem.vue +7 -3
- package/src/components/SidebarRail/types.ts +2 -1
- package/src/molecules/editor/extensions/shared/media-plugin.ts +30 -7
- package/src/molecules/editor/extensions/shared/suggestion-renderer.ts +24 -2
- package/src/molecules/editor/useEditor.ts +8 -0
- package/src/resources/realtime.ts +20 -4
- package/tailwind/plugin.js +7 -13
- package/vitepress/components/SiteActions.vue +1 -1
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
} from 'vue'
|
|
44
44
|
|
|
45
45
|
import { Editor, EditorContent } from '@tiptap/vue-3'
|
|
46
|
+
import type { EditorView } from '@tiptap/pm/view'
|
|
46
47
|
import StarterKit from '@tiptap/starter-kit'
|
|
47
48
|
import { Placeholder } from '@tiptap/extensions'
|
|
48
49
|
import Typography from '@tiptap/extension-typography'
|
|
@@ -126,6 +127,12 @@ const editorProps = computed(() => {
|
|
|
126
127
|
attributes: {
|
|
127
128
|
class: normalizeClass(['prose', props.editorClass]),
|
|
128
129
|
},
|
|
130
|
+
handleDOMEvents: {
|
|
131
|
+
// ProseMirror's dragstart runs even when read-only and overwrites the drag
|
|
132
|
+
// data; claiming the event (without preventDefault) keeps the browser's
|
|
133
|
+
// native payload, such as a link URL.
|
|
134
|
+
dragstart: (view: EditorView) => !view.editable,
|
|
135
|
+
},
|
|
129
136
|
}
|
|
130
137
|
})
|
|
131
138
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frappe-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A set of components and utilities for rapid UI development",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.19.0"
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"scripts": {
|
|
50
50
|
"test": "vitest --run",
|
|
51
51
|
"test:coverage": "vitest --run --coverage",
|
|
52
|
-
"test:cypress": "cypress run --component",
|
|
53
|
-
"test:cypress:coverage": "cross-env COVERAGE=true cypress run --component",
|
|
52
|
+
"test:cypress": "cypress run --component --browser chrome",
|
|
53
|
+
"test:cypress:coverage": "cross-env COVERAGE=true cypress run --component --browser chrome && nyc report",
|
|
54
54
|
"coverage": "yarn test:coverage && yarn test:cypress:coverage && yarn coverage:merge",
|
|
55
55
|
"coverage:merge": "tsx .github/scripts/merge-coverage.ts",
|
|
56
56
|
"type-check": "vue-tsc --noEmit -p tsconfig.app.json && vue-tsc --noEmit -p tsconfig.node.json",
|
|
@@ -66,7 +66,8 @@
|
|
|
66
66
|
"docs:gen:all": "yarn docs:gen --all",
|
|
67
67
|
"docs:check": "tsx docs/scripts/propsgen.ts --check",
|
|
68
68
|
"sync-tokens": "node tailwind/tokens/build.js",
|
|
69
|
-
"sync-token-types": "node tailwind/tokens/build-types.js"
|
|
69
|
+
"sync-token-types": "node tailwind/tokens/build-types.js",
|
|
70
|
+
"version-packages": "changeset version && cd packages/create-frappe-ui && npm version \"$(node -p \"require('../../package.json').version\")\" --no-git-tag-version --allow-same-version"
|
|
70
71
|
},
|
|
71
72
|
"exports": {
|
|
72
73
|
".": {
|
|
@@ -299,6 +300,8 @@
|
|
|
299
300
|
}
|
|
300
301
|
},
|
|
301
302
|
"devDependencies": {
|
|
303
|
+
"@changesets/changelog-github": "^0.7.0",
|
|
304
|
+
"@changesets/cli": "^2.31.1",
|
|
302
305
|
"@codemirror/lang-css": "^6.3.0",
|
|
303
306
|
"@codemirror/lang-html": "^6.4.9",
|
|
304
307
|
"@codemirror/lang-javascript": "^6.2.2",
|
|
@@ -310,7 +313,6 @@
|
|
|
310
313
|
"@codemirror/lang-xml": "^6.1.0",
|
|
311
314
|
"@codemirror/lang-yaml": "^6.1.3",
|
|
312
315
|
"@codemirror/lint": "^6.0.0",
|
|
313
|
-
"@cypress/code-coverage": "^3.13.10",
|
|
314
316
|
"@shikijs/transformers": "^3.15.0",
|
|
315
317
|
"@vitejs/plugin-vue": "^6.0.7",
|
|
316
318
|
"@vitest/coverage-v8": "^3.2.4",
|
package/readme.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
# Frappe UI
|
|
6
6
|
|
|
7
|
-
**
|
|
7
|
+
**The all-in-one toolkit for modern frontends. High-quality components, app recipes and AI-ready docs.**
|
|
8
8
|
|
|
9
9
|
<a href="https://www.npmjs.com/package/frappe-ui"><img alt="npm version" src="https://img.shields.io/npm/v/frappe-ui.svg?style=flat" /></a>
|
|
10
10
|
<a href="https://www.npmjs.com/package/frappe-ui"><img alt="npm downloads" src="https://img.shields.io/npm/dm/frappe-ui.svg?style=flat" /></a>
|
|
@@ -121,10 +121,9 @@
|
|
|
121
121
|
:dir="dir"
|
|
122
122
|
>
|
|
123
123
|
<template #default="slotProps">
|
|
124
|
+
<!-- The value item carries the stage's name, so a header would print
|
|
125
|
+
it twice. -->
|
|
124
126
|
<slot name="tooltip" v-bind="slotProps">
|
|
125
|
-
<div class="mb-2 text-p-sm text-ink-gray-5">
|
|
126
|
-
{{ slotProps.label }}
|
|
127
|
-
</div>
|
|
128
127
|
<div class="flex flex-col gap-1.5 text-p-sm">
|
|
129
128
|
<div
|
|
130
129
|
v-for="item in slotProps.items.filter(
|
|
@@ -170,7 +169,7 @@
|
|
|
170
169
|
|
|
171
170
|
<script setup lang="ts">
|
|
172
171
|
import { computed, reactive, ref } from 'vue'
|
|
173
|
-
import {
|
|
172
|
+
import { formatPercent, formatValue } from './format'
|
|
174
173
|
import { buildFunnelStages, funnelShapes } from './funnelGeometry'
|
|
175
174
|
import { useTooltipDismiss } from './core/useTooltipDismiss'
|
|
176
175
|
import { paletteColors, useChartTokens } from './tokens'
|
|
@@ -290,7 +289,9 @@ function readStage(stage: FunnelStage) {
|
|
|
290
289
|
tooltip.items = [
|
|
291
290
|
{
|
|
292
291
|
name: String(stage.index),
|
|
293
|
-
|
|
292
|
+
// `value` is a row key, often one the caller named when reshaping its
|
|
293
|
+
// rows, so it says nothing to the reader.
|
|
294
|
+
label: stage.label,
|
|
294
295
|
color: colors.value[stage.index],
|
|
295
296
|
value: stage.value,
|
|
296
297
|
formattedValue: formatMeasure(stage.value),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { dayjs } from '#utils/dayjs'
|
|
1
2
|
import {
|
|
2
3
|
estimateTextWidth,
|
|
3
4
|
formatAxisValue,
|
|
@@ -12,6 +13,7 @@ import {
|
|
|
12
13
|
} from './format'
|
|
13
14
|
import { CHART_FONT_FAMILY } from './measureText'
|
|
14
15
|
import { paletteColors, type ChartTokens } from './tokens'
|
|
16
|
+
import type { AxisChartFormatters } from './seriesData'
|
|
15
17
|
import { mergeDeep } from './utils'
|
|
16
18
|
import type {
|
|
17
19
|
AxisChartBaseConfig,
|
|
@@ -29,6 +31,8 @@ export type AxisChartOptionContext = {
|
|
|
29
31
|
hiddenSeries?: string[]
|
|
30
32
|
/** Plot width in pixels, once measured. Unset leaves pixel sizes to echarts. */
|
|
31
33
|
width?: number
|
|
34
|
+
/** What a data label prints in when its series has no `format` of its own. */
|
|
35
|
+
format?: AxisChartFormatters
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
export const AXIS_LABEL_FONT_SIZE = 11
|
|
@@ -338,8 +342,8 @@ export function axisChartBase(
|
|
|
338
342
|
* the grid only reserves room for its own axis labels and names. echarts does
|
|
339
343
|
* that reservation itself: it measures the labels it has already laid out and
|
|
340
344
|
* shrinks the plot until they fit the outer bounds. What it does not cover is
|
|
341
|
-
* data labels, which sit past the end of a mark
|
|
342
|
-
*
|
|
345
|
+
* data labels, which sit past the end of a mark: `useAxisChart` raises the
|
|
346
|
+
* value axis a tick for those once the chart is laid out (see `fitLabels`).
|
|
343
347
|
*
|
|
344
348
|
* A label is measured as the box its rotation gives it, so a tilted category
|
|
345
349
|
* axis (see `categoryLabelFit`) takes its own height out of the plot without the
|
|
@@ -351,21 +355,27 @@ export function axisChartBase(
|
|
|
351
355
|
// plot to keep the labels inside it and never spends the two pixels.
|
|
352
356
|
const EDGE_PAD = 2
|
|
353
357
|
|
|
358
|
+
// How far in from the value axis a line's first and last point sit on a time
|
|
359
|
+
// axis, in pixels: enough to clear the y tick labels and a data label over it.
|
|
360
|
+
const LINE_AXIS_INSET = 32
|
|
361
|
+
|
|
362
|
+
// Echarts' own `splitNumber` for a time axis. It divides the span by this to
|
|
363
|
+
// pick the tick interval, so a padded span has to be given more splits to keep
|
|
364
|
+
// the ticks as dense as the same data unpadded.
|
|
365
|
+
const TIME_AXIS_SPLIT_NUMBER = 6
|
|
366
|
+
|
|
354
367
|
export function buildAxisGrid(opts: {
|
|
355
368
|
horizontal: boolean
|
|
356
|
-
isRTL: boolean
|
|
357
|
-
labelGutter: number
|
|
358
369
|
/** Title on the category axis, which only a horizontal chart draws inline. */
|
|
359
370
|
xAxisTitle?: string
|
|
360
371
|
}) {
|
|
361
|
-
const { horizontal,
|
|
362
|
-
const endGutter = horizontal ? labelGutter : 0
|
|
372
|
+
const { horizontal, xAxisTitle } = opts
|
|
363
373
|
|
|
364
374
|
return {
|
|
365
|
-
top: 8
|
|
375
|
+
top: 8,
|
|
366
376
|
bottom: 0,
|
|
367
|
-
left: EDGE_PAD
|
|
368
|
-
right:
|
|
377
|
+
left: EDGE_PAD,
|
|
378
|
+
right: xAxisTitle && horizontal ? 24 : EDGE_PAD,
|
|
369
379
|
// What `containLabel` did until echarts 6, plus the two things it never did:
|
|
370
380
|
// it reserves on both dimensions, so the label at either end of a horizontal
|
|
371
381
|
// axis stops overhanging the canvas, and `all` covers the axis name as well
|
|
@@ -387,14 +397,18 @@ export function buildXAxis(
|
|
|
387
397
|
categories: any[]
|
|
388
398
|
horizontal: boolean
|
|
389
399
|
isRTL: boolean
|
|
390
|
-
/**
|
|
391
|
-
|
|
400
|
+
/** Whether a time axis is padded at each end, as echarts only does for bars. */
|
|
401
|
+
inset: boolean
|
|
392
402
|
/** Plot width in pixels, when known. Decides how the labels are laid out. */
|
|
393
403
|
width?: number
|
|
394
404
|
},
|
|
395
405
|
) {
|
|
396
|
-
const { categories, horizontal, isRTL,
|
|
406
|
+
const { categories, horizontal, isRTL, width } = opts
|
|
397
407
|
const { type, timeGrain } = resolveXAxis(config, horizontal)
|
|
408
|
+
const inset =
|
|
409
|
+
type === 'time' && opts.inset
|
|
410
|
+
? timeInset(config, categories, width)
|
|
411
|
+
: undefined
|
|
398
412
|
const { rotate, labelWidth } = categoryLabelFit(config, { ...opts, type })
|
|
399
413
|
|
|
400
414
|
const axis = {
|
|
@@ -407,7 +421,10 @@ export function buildXAxis(
|
|
|
407
421
|
// horizontal bar chart is inverted so the first category sits on top.
|
|
408
422
|
inverse: horizontal ? true : isRTL,
|
|
409
423
|
position: horizontal ? (isRTL ? 'right' : 'left') : 'bottom',
|
|
410
|
-
|
|
424
|
+
// A line's points sit in a half slot at each end as a bar does. A pixel pad
|
|
425
|
+
// like the time axis' is out: echarts rounds a category `min` and `max`.
|
|
426
|
+
...(type === 'category' ? { data: categories, boundaryGap: true } : {}),
|
|
427
|
+
...(inset ? inset.extent : {}),
|
|
411
428
|
name: config.xAxis.title ? formatLabel(config.xAxis.title) : undefined,
|
|
412
429
|
nameLocation: 'end',
|
|
413
430
|
nameGap: 8,
|
|
@@ -440,13 +457,55 @@ export function buildXAxis(
|
|
|
440
457
|
// Left out entirely when the labels fit, so a flat axis carries no
|
|
441
458
|
// rotation key at all.
|
|
442
459
|
...(rotate ? { rotate } : {}),
|
|
443
|
-
...xAxisLabelFormat(type, {
|
|
460
|
+
...xAxisLabelFormat(type, {
|
|
461
|
+
tokens,
|
|
462
|
+
timeGrain,
|
|
463
|
+
labelWidth,
|
|
464
|
+
dataRange: inset?.dataRange,
|
|
465
|
+
}),
|
|
444
466
|
},
|
|
445
467
|
}
|
|
446
468
|
|
|
447
469
|
return mergeDeep(axis, config.xAxis.echartOptions)
|
|
448
470
|
}
|
|
449
471
|
|
|
472
|
+
/**
|
|
473
|
+
* A line's end points sit on the plot's edges, under the value axis' ticks. A
|
|
474
|
+
* time axis cannot take a half slot, so it is padded by a fixed distance on
|
|
475
|
+
* each side, whatever the span or the plot is wide. Echarts does this itself,
|
|
476
|
+
* but only for bars it draws. A lone date has no span to pad, and an axis whose
|
|
477
|
+
* caller set either end is theirs to lay out.
|
|
478
|
+
*
|
|
479
|
+
* `dataRange` is what the padding is not: the ticks that land in it say nothing
|
|
480
|
+
* about the series, so they go unlabelled (see `xAxisLabelFormat`).
|
|
481
|
+
*/
|
|
482
|
+
function timeInset(config: AxisChartBaseConfig, values: any[], width?: number) {
|
|
483
|
+
const { min, max } = config.xAxis.echartOptions ?? {}
|
|
484
|
+
if (min !== undefined || max !== undefined) return undefined
|
|
485
|
+
|
|
486
|
+
let first = Infinity
|
|
487
|
+
let last = -Infinity
|
|
488
|
+
for (const value of values) {
|
|
489
|
+
// Read the way echarts reads the points, so the pad is measured from them.
|
|
490
|
+
const time = dayjs(value).valueOf()
|
|
491
|
+
if (time < first) first = time
|
|
492
|
+
if (time > last) last = time
|
|
493
|
+
}
|
|
494
|
+
const plot = width ? plotWidth(config, width) : 0
|
|
495
|
+
if (!(last > first) || plot <= 2 * LINE_AXIS_INSET) return undefined
|
|
496
|
+
|
|
497
|
+
const padded = plot / (plot - 2 * LINE_AXIS_INSET)
|
|
498
|
+
const pad = ((last - first) * (padded - 1)) / 2
|
|
499
|
+
return {
|
|
500
|
+
extent: {
|
|
501
|
+
min: first - pad,
|
|
502
|
+
max: last + pad,
|
|
503
|
+
splitNumber: Math.round(TIME_AXIS_SPLIT_NUMBER * padded),
|
|
504
|
+
},
|
|
505
|
+
dataRange: [first, last] as const,
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
450
509
|
/**
|
|
451
510
|
* How a tick prints, which is most of what the three readings disagree about.
|
|
452
511
|
* A value axis prints the compact tick the value axis on the other side of the
|
|
@@ -455,7 +514,13 @@ export function buildXAxis(
|
|
|
455
514
|
*/
|
|
456
515
|
function xAxisLabelFormat(
|
|
457
516
|
type: ResolvedXAxis['type'],
|
|
458
|
-
opts: {
|
|
517
|
+
opts: {
|
|
518
|
+
tokens: ChartTokens
|
|
519
|
+
timeGrain?: TimeGrain
|
|
520
|
+
labelWidth?: number
|
|
521
|
+
/** A padded time axis labels only the ticks between these two. */
|
|
522
|
+
dataRange?: readonly [number, number]
|
|
523
|
+
},
|
|
459
524
|
) {
|
|
460
525
|
if (type === 'time') {
|
|
461
526
|
return {
|
|
@@ -464,7 +529,10 @@ function xAxisLabelFormat(
|
|
|
464
529
|
// than as another tick. `primary` is echarts' own name for that level's
|
|
465
530
|
// rich style.
|
|
466
531
|
formatter: (value: any, _index: number, extra?: { level: number }) =>
|
|
467
|
-
|
|
532
|
+
opts.dataRange &&
|
|
533
|
+
(value < opts.dataRange[0] || value > opts.dataRange[1])
|
|
534
|
+
? ''
|
|
535
|
+
: formatTimeAxisLabel(value, opts.timeGrain, extra?.level),
|
|
468
536
|
rich: {
|
|
469
537
|
primary: {
|
|
470
538
|
color: opts.tokens.axisTitle,
|
|
@@ -513,7 +581,6 @@ function categoryLabelFit(
|
|
|
513
581
|
categories: any[]
|
|
514
582
|
horizontal: boolean
|
|
515
583
|
isRTL: boolean
|
|
516
|
-
boundaryGap: boolean
|
|
517
584
|
width?: number
|
|
518
585
|
type: ResolvedXAxis['type']
|
|
519
586
|
},
|
|
@@ -550,28 +617,26 @@ function categoryLabelFit(
|
|
|
550
617
|
}
|
|
551
618
|
}
|
|
552
619
|
|
|
620
|
+
/** The room the x axis has: the chart less its edge pad and the value axes. */
|
|
621
|
+
function plotWidth(config: AxisChartBaseConfig, width: number) {
|
|
622
|
+
return width - 2 * EDGE_PAD - valueAxisReserve(config)
|
|
623
|
+
}
|
|
624
|
+
|
|
553
625
|
/**
|
|
554
626
|
* The room one category gets along the axis, or undefined where there is
|
|
555
|
-
* nothing to decide from: a chart that has not been measured, one measured
|
|
556
|
-
* nothing
|
|
557
|
-
* with.
|
|
627
|
+
* nothing to decide from: a chart that has not been measured, or one measured
|
|
628
|
+
* at nothing. Only a column chart asks: a row chart's categories are stacked.
|
|
558
629
|
*/
|
|
559
630
|
function categorySlotWidth(
|
|
560
631
|
config: AxisChartBaseConfig,
|
|
561
|
-
opts: { categories: any[];
|
|
632
|
+
opts: { categories: any[]; width?: number },
|
|
562
633
|
) {
|
|
563
|
-
if (!opts.width) return undefined
|
|
564
|
-
|
|
565
|
-
const plot = opts.width - 2 * EDGE_PAD - valueAxisReserve(config)
|
|
566
|
-
// `boundaryGap` gives every category a slot of its own to sit in the middle
|
|
567
|
-
// of; without it they sit on the dividers, so what has to hold a label is
|
|
568
|
-
// the distance between two ticks.
|
|
569
|
-
const slots = opts.boundaryGap
|
|
570
|
-
? opts.categories.length
|
|
571
|
-
: opts.categories.length - 1
|
|
634
|
+
if (!opts.width || !opts.categories.length) return undefined
|
|
572
635
|
|
|
573
|
-
|
|
574
|
-
|
|
636
|
+
const plot = plotWidth(config, opts.width)
|
|
637
|
+
// A column chart's `boundaryGap` gives every category a slot of its own to
|
|
638
|
+
// sit in the middle of.
|
|
639
|
+
return plot > 0 ? plot / opts.categories.length : undefined
|
|
575
640
|
}
|
|
576
641
|
|
|
577
642
|
/**
|
|
@@ -689,7 +754,9 @@ function categoryLabelWidth(width?: number) {
|
|
|
689
754
|
|
|
690
755
|
function categoryLabel(label: string, labelWidth?: number) {
|
|
691
756
|
if (!labelWidth) return label
|
|
692
|
-
|
|
757
|
+
// zrender truncates against `width - 1`, not `width` (parseText.js), so a
|
|
758
|
+
// label fitted to the full width can still get an end ellipsis of its own.
|
|
759
|
+
return truncateMiddleToWidth(label, labelWidth - 1, AXIS_LABEL_FONT_SIZE)
|
|
693
760
|
}
|
|
694
761
|
|
|
695
762
|
/**
|
|
@@ -18,12 +18,14 @@ import {
|
|
|
18
18
|
MARK_Z,
|
|
19
19
|
type AxisChartOptionContext,
|
|
20
20
|
} from './axisChartCommon'
|
|
21
|
+
import { seriesFormatter } from './axisFormat'
|
|
21
22
|
import { buildReferenceLineSeries } from './referenceLines'
|
|
22
23
|
import { mergeDeep } from './utils'
|
|
23
24
|
import type {
|
|
24
25
|
AxisChartConfig,
|
|
25
26
|
AxisChartSeriesConfig,
|
|
26
27
|
ChartMark,
|
|
28
|
+
ChartValueFormatter,
|
|
27
29
|
ChartYAxisConfig,
|
|
28
30
|
} from './types'
|
|
29
31
|
|
|
@@ -31,10 +33,6 @@ const BAR_MAX_WIDTH = 32
|
|
|
31
33
|
/** Slim bars with an airy gap between categories. */
|
|
32
34
|
const BAR_CATEGORY_GAP = '38%'
|
|
33
35
|
const BAR_RADIUS = 4
|
|
34
|
-
/** Room for a data label sitting past the end of a bar. */
|
|
35
|
-
const BAR_LABEL_GUTTER = 40
|
|
36
|
-
/** Room for a data label sitting above a point. */
|
|
37
|
-
const LINE_LABEL_GUTTER = 24
|
|
38
36
|
|
|
39
37
|
export const DEFAULT_LINE_WIDTH = 2
|
|
40
38
|
/** Big enough to hit with a pointer, small enough not to read as a scatter plot. */
|
|
@@ -73,6 +71,8 @@ type SeriesContext = {
|
|
|
73
71
|
carriesTip: (entry: PlottedSeries, rowIndex: number, value: number) => boolean
|
|
74
72
|
/** Whether this area stacks onto another, i.e. reads as a band. */
|
|
75
73
|
banded: boolean
|
|
74
|
+
/** Prints this series' values: its own format, or its axis'. */
|
|
75
|
+
format?: ChartValueFormatter
|
|
76
76
|
/**
|
|
77
77
|
* This series' share of its stack, row by row, on a normalized chart. Set
|
|
78
78
|
* means the plot draws the share and prints it as a percentage; unset means
|
|
@@ -95,7 +95,7 @@ export type StackShares = Map<string, (number | null)[]>
|
|
|
95
95
|
*/
|
|
96
96
|
export function buildAxisChartOption(
|
|
97
97
|
config: AxisChartConfig,
|
|
98
|
-
{ tokens, hiddenSeries = [], width }: AxisChartOptionContext,
|
|
98
|
+
{ tokens, hiddenSeries = [], width, format = {} }: AxisChartOptionContext,
|
|
99
99
|
): EChartsCoreOption {
|
|
100
100
|
const isRTL = config.dir === 'rtl'
|
|
101
101
|
const horizontal = Boolean(config.horizontal)
|
|
@@ -113,7 +113,7 @@ export function buildAxisChartOption(
|
|
|
113
113
|
(entry) => !hiddenSeries.includes(entry.series.name),
|
|
114
114
|
)
|
|
115
115
|
// Read over *every* series rather than the visible ones: hiding the last bar
|
|
116
|
-
// in the legend should not
|
|
116
|
+
// in the legend should not swap the pointer from a shade to a rule.
|
|
117
117
|
const hasBars = plotted.some((entry) => entry.mark === 'bar')
|
|
118
118
|
const categories = rows.map((row) => row[config.xAxis.key])
|
|
119
119
|
// A point on a value axis carries its own coordinate; on the other two the
|
|
@@ -129,8 +129,8 @@ export function buildAxisChartOption(
|
|
|
129
129
|
categories,
|
|
130
130
|
horizontal,
|
|
131
131
|
isRTL,
|
|
132
|
-
//
|
|
133
|
-
|
|
132
|
+
// Echarts pads a time axis for the bars it draws, so only the visible count.
|
|
133
|
+
inset: !horizontal && !visible.some((entry) => entry.mark === 'bar'),
|
|
134
134
|
width,
|
|
135
135
|
})
|
|
136
136
|
const hasSecondary = hasSecondaryValueAxis(config, horizontal)
|
|
@@ -148,8 +148,6 @@ export function buildAxisChartOption(
|
|
|
148
148
|
...axisChartBase(tokens, hasBars ? 'shadow' : 'line'),
|
|
149
149
|
grid: buildAxisGrid({
|
|
150
150
|
horizontal,
|
|
151
|
-
isRTL,
|
|
152
|
-
labelGutter: dataLabelGutter(plotted),
|
|
153
151
|
xAxisTitle: config.xAxis.title,
|
|
154
152
|
}),
|
|
155
153
|
xAxis: horizontal ? valueAxis : xColumnAxis,
|
|
@@ -163,6 +161,7 @@ export function buildAxisChartOption(
|
|
|
163
161
|
isRTL,
|
|
164
162
|
color: colors[entry.series.name],
|
|
165
163
|
yAxisIndex: valueAxisIndex(entry.series, hasSecondary),
|
|
164
|
+
format: seriesFormatter(entry.series, format, horizontal),
|
|
166
165
|
xValue,
|
|
167
166
|
carriesTip,
|
|
168
167
|
banded: isBanded(entry, plotted),
|
|
@@ -346,19 +345,6 @@ function pinValueAxis(
|
|
|
346
345
|
}
|
|
347
346
|
}
|
|
348
347
|
|
|
349
|
-
/** Chart-wide room for the labels, i.e. whatever the hungriest mark needs. */
|
|
350
|
-
function dataLabelGutter(plotted: PlottedSeries[]) {
|
|
351
|
-
let gutter = 0
|
|
352
|
-
for (const { series, mark, stack } of plotted) {
|
|
353
|
-
if (!series.showDataLabels) continue
|
|
354
|
-
// Stacked labels sit inside the fill, so they need no gutter.
|
|
355
|
-
const needed =
|
|
356
|
-
mark === 'bar' ? (stack ? 0 : BAR_LABEL_GUTTER) : LINE_LABEL_GUTTER
|
|
357
|
-
gutter = Math.max(gutter, needed)
|
|
358
|
-
}
|
|
359
|
-
return gutter
|
|
360
|
-
}
|
|
361
|
-
|
|
362
348
|
function buildSeries(
|
|
363
349
|
entry: PlottedSeries,
|
|
364
350
|
config: AxisChartConfig,
|
|
@@ -477,11 +463,7 @@ function buildBarSeries(entry: PlottedSeries, ctx: SeriesContext) {
|
|
|
477
463
|
: tokens.dataLabel,
|
|
478
464
|
fontSize: DATA_LABEL_FONT_SIZE,
|
|
479
465
|
formatter: (params: any) =>
|
|
480
|
-
plottedLabel(
|
|
481
|
-
horizontal ? params.value?.[0] : params.value?.[1],
|
|
482
|
-
series,
|
|
483
|
-
Boolean(ctx.share),
|
|
484
|
-
),
|
|
466
|
+
plottedLabel(horizontal ? params.value?.[0] : params.value?.[1], ctx),
|
|
485
467
|
},
|
|
486
468
|
labelLayout: { hideOverlap: true },
|
|
487
469
|
}
|
|
@@ -532,8 +514,7 @@ function buildLineSeries(
|
|
|
532
514
|
position: 'top',
|
|
533
515
|
color: tokens.dataLabel,
|
|
534
516
|
fontSize: DATA_LABEL_FONT_SIZE,
|
|
535
|
-
formatter: (params: any) =>
|
|
536
|
-
plottedLabel(params.value?.[1], series, Boolean(ctx.share)),
|
|
517
|
+
formatter: (params: any) => plottedLabel(params.value?.[1], ctx),
|
|
537
518
|
},
|
|
538
519
|
labelLayout: { hideOverlap: true },
|
|
539
520
|
}
|
|
@@ -550,14 +531,10 @@ function buildLineSeries(
|
|
|
550
531
|
* What a data label prints. A normalized series plots a share, so printing it
|
|
551
532
|
* as a number would read as a count of something.
|
|
552
533
|
*/
|
|
553
|
-
function plottedLabel(
|
|
554
|
-
value: any,
|
|
555
|
-
series: AxisChartSeriesConfig,
|
|
556
|
-
normalized: boolean,
|
|
557
|
-
) {
|
|
534
|
+
function plottedLabel(value: any, ctx: SeriesContext) {
|
|
558
535
|
if (value === null || value === undefined || isNaN(value)) return ''
|
|
559
|
-
if (
|
|
560
|
-
return
|
|
536
|
+
if (ctx.share) return formatPercent(value)
|
|
537
|
+
return ctx.format ? ctx.format(value) : formatValue(value, 1, true)
|
|
561
538
|
}
|
|
562
539
|
|
|
563
540
|
/**
|
package/src/charts/axisFormat.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { AxisChartFormatters } from './seriesData'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
AxisChartBaseConfig,
|
|
4
|
+
AxisChartSeriesConfig,
|
|
5
|
+
ChartValueFormatter,
|
|
6
|
+
EchartOptionsOverride,
|
|
7
|
+
} from './types'
|
|
3
8
|
import { mergeDeep } from './utils'
|
|
4
9
|
|
|
5
10
|
/**
|
|
@@ -48,3 +53,18 @@ function withFormatter(
|
|
|
48
53
|
echartOptions,
|
|
49
54
|
)
|
|
50
55
|
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* How a series prints its values. Without its own format, a series reads in the
|
|
59
|
+
* units of the axis it is actually drawn against, so `y2` series never fall back
|
|
60
|
+
* to the primary formatter — except on a horizontal chart, which has no second
|
|
61
|
+
* axis to put them on.
|
|
62
|
+
*/
|
|
63
|
+
export function seriesFormatter(
|
|
64
|
+
series: AxisChartSeriesConfig,
|
|
65
|
+
format: AxisChartFormatters,
|
|
66
|
+
horizontal: boolean,
|
|
67
|
+
): ChartValueFormatter | undefined {
|
|
68
|
+
const secondary = series.axis === 'y2' && !horizontal
|
|
69
|
+
return series.format ?? (secondary ? format.y2 : format.y)
|
|
70
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { ECharts } from 'echarts/core'
|
|
2
|
+
|
|
3
|
+
/** The grid edge the data labels run towards: past the tip of a column or a row. */
|
|
4
|
+
export type DataLabelSide = 'top' | 'right' | 'left'
|
|
5
|
+
|
|
6
|
+
/** echarts' own default distance between a label and its mark. */
|
|
7
|
+
const DEFAULT_LABEL_DISTANCE = 5
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The axis end one tick past the current one, or `null` when echarts has drawn
|
|
11
|
+
* fewer than two ticks to read a step from. Read off the ticks rather than the
|
|
12
|
+
* scale's extent, because the ticks are what the reader sees and what a label
|
|
13
|
+
* has to clear.
|
|
14
|
+
*/
|
|
15
|
+
export function nextAxisMax(chart: ECharts, axis: 'xAxis' | 'yAxis') {
|
|
16
|
+
const ticks = (chart as any)
|
|
17
|
+
.getModel()
|
|
18
|
+
.getComponent(axis, 0)
|
|
19
|
+
?.axis?.scale?.getTicks?.()
|
|
20
|
+
if (!ticks || ticks.length < 2) return null
|
|
21
|
+
const last = ticks[ticks.length - 1].value
|
|
22
|
+
return last + (last - ticks[ticks.length - 2].value)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* How far the furthest data label reaches past `bound`: positive when it
|
|
27
|
+
* overflows, negative when there is room to spare, `null` when nothing is
|
|
28
|
+
* labelled past the end of a mark.
|
|
29
|
+
*
|
|
30
|
+
* echarts contains axis labels in the grid's outer bounds but not data labels,
|
|
31
|
+
* and how far a label reaches depends on the axis ends echarts picks and on the
|
|
32
|
+
* plot's size, so it can only be read off the laid-out chart. `bound` is the
|
|
33
|
+
* grid edge the option set, which is where the axis labels on that side stop.
|
|
34
|
+
*/
|
|
35
|
+
export function dataLabelOverflow(
|
|
36
|
+
chart: ECharts,
|
|
37
|
+
side: DataLabelSide,
|
|
38
|
+
bound: number,
|
|
39
|
+
) {
|
|
40
|
+
const width = chart.getWidth()
|
|
41
|
+
let overflow: number | null = null
|
|
42
|
+
|
|
43
|
+
;(chart as any).getModel().eachSeries((series: any) => {
|
|
44
|
+
if (!series.get(['label', 'show'])) return
|
|
45
|
+
// A label inside the fill never leaves the mark.
|
|
46
|
+
if (series.get(['label', 'position']) === 'inside') return
|
|
47
|
+
const distance = series.get(['label', 'distance']) ?? DEFAULT_LABEL_DISTANCE
|
|
48
|
+
const data = series.getData()
|
|
49
|
+
// A line lays its points out as one flat `[x0, y0, x1, y1, …]` array.
|
|
50
|
+
const points = data.getLayout('points')
|
|
51
|
+
|
|
52
|
+
data.each((index: number) => {
|
|
53
|
+
const el = data.getItemGraphicEl(index)
|
|
54
|
+
// A line point is a symbol group, and its label hangs off the path inside.
|
|
55
|
+
const label = (el?.getSymbolPath?.() ?? el)?.getTextContent?.()
|
|
56
|
+
const tip = markTip(
|
|
57
|
+
points
|
|
58
|
+
? [points[index * 2], points[index * 2 + 1]]
|
|
59
|
+
: data.getItemLayout(index),
|
|
60
|
+
side,
|
|
61
|
+
)
|
|
62
|
+
// A gap in a line is a NaN point, with nothing drawn there to label.
|
|
63
|
+
if (!label || tip === null || Number.isNaN(tip)) return
|
|
64
|
+
const box = label.getBoundingRect()
|
|
65
|
+
|
|
66
|
+
const reach =
|
|
67
|
+
side === 'top'
|
|
68
|
+
? bound - (tip - distance - box.height)
|
|
69
|
+
: side === 'right'
|
|
70
|
+
? tip + distance + box.width - (width - bound)
|
|
71
|
+
: bound - (tip - distance - box.width)
|
|
72
|
+
overflow = Math.max(overflow ?? -Infinity, reach)
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
return overflow
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The pixel a mark ends at on the side its label sits past. */
|
|
80
|
+
function markTip(layout: any, side: DataLabelSide): number | null {
|
|
81
|
+
if (!layout) return null
|
|
82
|
+
// A point is `[x, y]`, a bar its rect.
|
|
83
|
+
if (Array.isArray(layout)) return side === 'top' ? layout[1] : layout[0]
|
|
84
|
+
const { x, y, width, height } = layout
|
|
85
|
+
if (side === 'top') return Math.min(y, y + height)
|
|
86
|
+
if (side === 'right') return Math.max(x, x + width)
|
|
87
|
+
return Math.min(x, x + width)
|
|
88
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { computed, reactive, ref, watch, type Ref } from 'vue'
|
|
2
2
|
import type { EChartsCoreOption } from 'echarts/core'
|
|
3
|
+
import { dataLabelOverflow, nextAxisMax } from './dataLabelFit'
|
|
3
4
|
import { useChart } from './useChart'
|
|
4
5
|
import { usePlotKeyboard } from './usePlotKeyboard'
|
|
5
6
|
import { useTooltipDismiss } from './useTooltipDismiss'
|
|
@@ -11,7 +12,7 @@ import {
|
|
|
11
12
|
resolveXAxis,
|
|
12
13
|
toNumber,
|
|
13
14
|
} from '../axisChartCommon'
|
|
14
|
-
import { applyAxisFormatters } from '../axisFormat'
|
|
15
|
+
import { applyAxisFormatters, seriesFormatter } from '../axisFormat'
|
|
15
16
|
import { pruneHiddenSeries, toggleHiddenSeries } from '../hiddenSeries'
|
|
16
17
|
import { buildTooltipItems } from '../tooltipItems'
|
|
17
18
|
import {
|
|
@@ -136,6 +137,7 @@ export function useAxisChart<C extends AxisChartConfig>(
|
|
|
136
137
|
tokens: tokens.value,
|
|
137
138
|
hiddenSeries: hiddenSeries.value,
|
|
138
139
|
width: plotWidth.value,
|
|
140
|
+
format: format.value,
|
|
139
141
|
},
|
|
140
142
|
),
|
|
141
143
|
error: null as string | null,
|
|
@@ -154,6 +156,9 @@ export function useAxisChart<C extends AxisChartConfig>(
|
|
|
154
156
|
click: (params: any) => {
|
|
155
157
|
select(params.seriesName, rows.value[params.dataIndex])
|
|
156
158
|
},
|
|
159
|
+
// Fires inside the frame that laid the chart out, before it is painted,
|
|
160
|
+
// so raising the axis here never shows a clipped label.
|
|
161
|
+
updated: () => fitLabels(),
|
|
157
162
|
},
|
|
158
163
|
onZrEvents: {
|
|
159
164
|
mousemove: (e: any) => updateTooltip(e.offsetX, e.offsetY, e.event),
|
|
@@ -163,6 +168,39 @@ export function useAxisChart<C extends AxisChartConfig>(
|
|
|
163
168
|
},
|
|
164
169
|
})
|
|
165
170
|
|
|
171
|
+
// The option the value axis was last raised for. A label still clipping
|
|
172
|
+
// after one more step is in a plot too short to fit it, and stepping again
|
|
173
|
+
// would only squash the bars.
|
|
174
|
+
let raisedFor: EChartsCoreOption | undefined
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* A data label at the top of the scale reaches past the plot. The value axis
|
|
178
|
+
* goes up one tick to make room for it, so the plot keeps its place in the
|
|
179
|
+
* card whatever the numbers are. An axis end the caller fixed is theirs.
|
|
180
|
+
*/
|
|
181
|
+
function fitLabels() {
|
|
182
|
+
const instance = chart.value
|
|
183
|
+
const option = built.value.option as any
|
|
184
|
+
if (!instance || !option?.grid || raisedFor === option) return
|
|
185
|
+
const valueAxis = horizontal.value ? 'xAxis' : 'yAxis'
|
|
186
|
+
const primary = [option[valueAxis]].flat()[0]
|
|
187
|
+
if (primary?.max != null) return
|
|
188
|
+
|
|
189
|
+
const side = horizontal.value
|
|
190
|
+
? dir.value === 'rtl'
|
|
191
|
+
? 'left'
|
|
192
|
+
: 'right'
|
|
193
|
+
: 'top'
|
|
194
|
+
if (typeof option.grid[side] !== 'number') return
|
|
195
|
+
const overflow = dataLabelOverflow(instance, side, option.grid[side])
|
|
196
|
+
if (overflow === null || overflow <= 0) return
|
|
197
|
+
|
|
198
|
+
const max = nextAxisMax(instance, valueAxis)
|
|
199
|
+
if (max === null) return
|
|
200
|
+
raisedFor = option
|
|
201
|
+
instance.setOption({ [valueAxis]: [{ max }] })
|
|
202
|
+
}
|
|
203
|
+
|
|
166
204
|
const legendItems = computed<ChartLegendItem[]>(() =>
|
|
167
205
|
config.value.series.map((series) => ({
|
|
168
206
|
name: series.name,
|
|
@@ -172,14 +210,8 @@ export function useAxisChart<C extends AxisChartConfig>(
|
|
|
172
210
|
})),
|
|
173
211
|
)
|
|
174
212
|
|
|
175
|
-
// Without its own format, a series reads in the units of the axis it is
|
|
176
|
-
// actually drawn against, so `y2` series never fall back to the primary
|
|
177
|
-
// formatter — except on a horizontal chart, which has no second axis to put
|
|
178
|
-
// them on.
|
|
179
213
|
function formatSeriesValue(series: AxisChartSeriesConfig, value: number) {
|
|
180
|
-
const
|
|
181
|
-
const formatter =
|
|
182
|
-
series.format ?? (secondary ? format.value.y2 : format.value.y)
|
|
214
|
+
const formatter = seriesFormatter(series, format.value, horizontal.value)
|
|
183
215
|
return formatter ? formatter(value) : formatValue(value)
|
|
184
216
|
}
|
|
185
217
|
|
|
@@ -187,12 +187,7 @@ export function buildScatterOption(
|
|
|
187
187
|
// No `tooltip` key and no TooltipComponent: a point is read on its own
|
|
188
188
|
// rather than through an axis pointer, and the visible tooltip is a Vue
|
|
189
189
|
// component (ChartTooltip).
|
|
190
|
-
grid: buildAxisGrid({
|
|
191
|
-
horizontal: false,
|
|
192
|
-
isRTL,
|
|
193
|
-
// Nothing is printed past the end of a mark: a point is the mark.
|
|
194
|
-
labelGutter: 0,
|
|
195
|
-
}),
|
|
190
|
+
grid: buildAxisGrid({ horizontal: false }),
|
|
196
191
|
// The x axis title is drawn on the axis, the way the category axis carries
|
|
197
192
|
// its own; the y axis title is chrome, drawn above the plot by the
|
|
198
193
|
// component. Same split as every other cartesian chart.
|
package/src/charts/types.ts
CHANGED
|
@@ -88,9 +88,9 @@ export type AxisChartSeriesConfig = {
|
|
|
88
88
|
axis?: 'y' | 'y2'
|
|
89
89
|
/**
|
|
90
90
|
* Prints this series' values in the tooltip and its data labels, for a series
|
|
91
|
-
* whose unit differs from the others on its axis. Without one,
|
|
92
|
-
*
|
|
93
|
-
*
|
|
91
|
+
* whose unit differs from the others on its axis. Without one, both use its
|
|
92
|
+
* axis' `format`. A label on a normalized stack prints the series' share
|
|
93
|
+
* either way.
|
|
94
94
|
*/
|
|
95
95
|
format?: ChartValueFormatter
|
|
96
96
|
showDataLabels?: boolean
|
|
@@ -734,9 +734,9 @@ export type SeriesStyle = {
|
|
|
734
734
|
type?: ChartMark
|
|
735
735
|
/**
|
|
736
736
|
* Prints this series' values in the tooltip and its data labels, for a series
|
|
737
|
-
* whose unit differs from the others on its axis. Without one,
|
|
738
|
-
*
|
|
739
|
-
*
|
|
737
|
+
* whose unit differs from the others on its axis. Without one, both use its
|
|
738
|
+
* axis' `format`. A label on a normalized stack prints the series' share
|
|
739
|
+
* either way.
|
|
740
740
|
*/
|
|
741
741
|
format?: ChartValueFormatter
|
|
742
742
|
/** Prints this series' value beside each of its marks. */
|
|
@@ -208,7 +208,7 @@ const inputClasses = computed(() => {
|
|
|
208
208
|
sizeClasses,
|
|
209
209
|
'cursor-not-allowed bg-surface-base border-outline-gray-3',
|
|
210
210
|
'text-[color:var(--surface-gray-5)]',
|
|
211
|
-
'
|
|
211
|
+
'focus:ring-0 focus:ring-offset-0',
|
|
212
212
|
]
|
|
213
213
|
}
|
|
214
214
|
|
|
@@ -219,15 +219,19 @@ const inputClasses = computed(() => {
|
|
|
219
219
|
'cursor-pointer transition focus:ring-0 focus:ring-offset-0',
|
|
220
220
|
// Unchecked — surface-base fill, outline scale: default 4 / hover 5 / active 6.
|
|
221
221
|
'bg-surface-base border-outline-gray-4',
|
|
222
|
-
// Checked fill (via currentColor): default 10
|
|
222
|
+
// Checked / indeterminate fill (via currentColor): default 10, hover 9,
|
|
223
|
+
// active 8 (non-padded only). The hover and active tokens in the branch
|
|
224
|
+
// below have no `checked:` variant, because `:checked` does not match an
|
|
225
|
+
// indeterminate box. The colour paints a fill only when the box is checked
|
|
226
|
+
// or indeterminate.
|
|
223
227
|
'text-[color:var(--surface-gray-10)]',
|
|
224
228
|
// Non-padded shows the global espresso ring on keyboard focus. forms sets a
|
|
225
229
|
// transparent `:focus` outline that outranks the global `:focus-visible` rule,
|
|
226
230
|
// so re-assert it with the themed `focus-ring` utility. (Padded shows the ring
|
|
227
231
|
// on the row instead, via `[&:has(:focus-visible)]` on the container.)
|
|
228
232
|
padded
|
|
229
|
-
? 'group-hover:border-outline-gray-5
|
|
230
|
-
: 'hover:border-outline-gray-5
|
|
233
|
+
? 'group-hover:border-outline-gray-5 group-hover:text-[color:var(--surface-gray-9)]'
|
|
234
|
+
: 'hover:border-outline-gray-5 active:border-outline-gray-6 hover:text-[color:var(--surface-gray-9)] active:text-[color:var(--surface-gray-8)] focus-visible:focus-ring',
|
|
231
235
|
]
|
|
232
236
|
})
|
|
233
237
|
</script>
|
|
@@ -52,6 +52,7 @@ import type {
|
|
|
52
52
|
NormalizedCustomOption,
|
|
53
53
|
NormalizedGroup,
|
|
54
54
|
NormalizedItem,
|
|
55
|
+
NormalizedSelectableOption,
|
|
55
56
|
} from './utils'
|
|
56
57
|
|
|
57
58
|
defineOptions({
|
|
@@ -306,13 +307,10 @@ const searchSlotProps = computed<ComboboxSearchSlotProps>(() => ({
|
|
|
306
307
|
focus: focusSearch,
|
|
307
308
|
}))
|
|
308
309
|
|
|
309
|
-
function commitSelectableOption(
|
|
310
|
-
|
|
311
|
-
allSelectableOptions.value.find((item) => item.value === value) ?? null
|
|
312
|
-
|
|
313
|
-
model.value = value
|
|
310
|
+
function commitSelectableOption(option: NormalizedSelectableOption) {
|
|
311
|
+
model.value = option.value
|
|
314
312
|
emit('update:selectedOption', option)
|
|
315
|
-
query.value = option
|
|
313
|
+
query.value = option.label
|
|
316
314
|
hasTypedSinceOpen.value = false
|
|
317
315
|
}
|
|
318
316
|
|
|
@@ -330,7 +328,7 @@ function handleRootModelValueChange(
|
|
|
330
328
|
)
|
|
331
329
|
|
|
332
330
|
if (selectableOption) {
|
|
333
|
-
commitSelectableOption(selectableOption
|
|
331
|
+
commitSelectableOption(selectableOption)
|
|
334
332
|
}
|
|
335
333
|
}
|
|
336
334
|
|
|
@@ -362,6 +360,17 @@ function handleCustomItemSelect(item: NormalizedCustomOption, event: Event) {
|
|
|
362
360
|
if (!item.keepOpen) open.value = false
|
|
363
361
|
}
|
|
364
362
|
|
|
363
|
+
// Commit before closing. Reka closes first and sends the value later, and
|
|
364
|
+
// closing resets the query. Options derived from the query can then drop the
|
|
365
|
+
// picked option before the value arrives.
|
|
366
|
+
function handleOptionSelect(item: NormalizedSelectableOption, event: Event) {
|
|
367
|
+
event.preventDefault()
|
|
368
|
+
if (item.disabled || props.disabled) return
|
|
369
|
+
|
|
370
|
+
commitSelectableOption(item)
|
|
371
|
+
open.value = false
|
|
372
|
+
}
|
|
373
|
+
|
|
365
374
|
function handleFocusScopeMountAutoFocus(event: Event) {
|
|
366
375
|
// In input mode the trigger is the search input — keep focus there so the
|
|
367
376
|
// user can keep typing. FocusScope's default would yank focus to the first
|
|
@@ -771,6 +780,7 @@ defineSlots<ComboboxSlots>()
|
|
|
771
780
|
:slot-fns="slotFns"
|
|
772
781
|
:all-selectable-options="allSelectableOptions"
|
|
773
782
|
@select-custom="handleCustomItemSelect"
|
|
783
|
+
@select-option="handleOptionSelect"
|
|
774
784
|
/>
|
|
775
785
|
|
|
776
786
|
<div v-if="$slots.footer" data-slot="footer">
|
|
@@ -52,6 +52,7 @@ const props = withDefaults(
|
|
|
52
52
|
|
|
53
53
|
const emit = defineEmits<{
|
|
54
54
|
selectCustom: [item: NormalizedCustomOption, event: Event]
|
|
55
|
+
selectOption: [item: NormalizedSelectableOption, event: Event]
|
|
55
56
|
}>()
|
|
56
57
|
|
|
57
58
|
const ItemSlotRender = createItemSlotRender('ComboboxItemSlotRender')
|
|
@@ -102,6 +103,7 @@ function getItemTextValue(item: NormalizedItem) {
|
|
|
102
103
|
|
|
103
104
|
function handleSelect(item: NormalizedItem, event: Event) {
|
|
104
105
|
if (isCustomOption(item)) emit('selectCustom', item, event)
|
|
106
|
+
else emit('selectOption', item, event)
|
|
105
107
|
}
|
|
106
108
|
</script>
|
|
107
109
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<div
|
|
10
10
|
v-if="hasPrefixSlot"
|
|
11
11
|
ref="prefixSlotEl"
|
|
12
|
-
class="absolute
|
|
12
|
+
class="absolute start-0 top-1/2 z-[1] flex max-w-[35%] -translate-y-1/2 justify-start"
|
|
13
13
|
>
|
|
14
14
|
<slot name="prefix" />
|
|
15
15
|
</div>
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
<div
|
|
27
27
|
v-if="hasSuffixSlot"
|
|
28
28
|
ref="suffixSlotEl"
|
|
29
|
-
class="absolute
|
|
29
|
+
class="absolute end-0 top-1/2 z-[1] flex max-w-[35%] -translate-y-1/2 justify-end"
|
|
30
30
|
>
|
|
31
31
|
<slot name="suffix" />
|
|
32
32
|
</div>
|
|
@@ -57,7 +57,7 @@ number. Leave `intervals` out for a continuous bar.
|
|
|
57
57
|
## Accessibility
|
|
58
58
|
|
|
59
59
|
The bar has the `progressbar` role, with `aria-valuenow` set to the value
|
|
60
|
-
from 0 to 100.
|
|
61
|
-
|
|
60
|
+
from 0 to 100. `label` is the bar's accessible name. A bar without a label is
|
|
61
|
+
named "Progress".
|
|
62
62
|
|
|
63
63
|
<!-- @include: ./Progress.api.md -->
|
|
@@ -94,12 +94,11 @@ const clampedValue = computed(() =>
|
|
|
94
94
|
const fillOffset = computed(() => clampedValue.value - MAX_VALUE)
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
97
|
+
* The progressbar's accessible name: the visible label, or a generic name.
|
|
98
|
+
* Not reka-ui's default percentage, because `aria-valuenow` already announces
|
|
99
|
+
* the value and a "40%" name would be read twice.
|
|
99
100
|
*/
|
|
100
|
-
const valueLabel = computed(
|
|
101
|
-
() => props.label || `${Math.round(clampedValue.value)}%`,
|
|
102
|
-
)
|
|
101
|
+
const valueLabel = computed(() => props.label || 'Progress')
|
|
103
102
|
|
|
104
103
|
const filledIntervalCount = computed(() =>
|
|
105
104
|
Math.round((clampedValue.value / MAX_VALUE) * (props.intervals ?? 0)),
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
name: 'variant',
|
|
68
|
-
description: 'Visual treatment.\n- `subtle` (default): a filled cell with a left indicator bar when active —\n for image/avatar items like communities or workspaces
|
|
68
|
+
description: 'Visual treatment.\n- `subtle` (default): a filled cell with a left indicator bar when active —\n for image/avatar items like communities or workspaces. The cell paints\n no fill when its default slot holds an `<img>`.\n- `ghost`: transparent until hovered, a raised highlight when active — for\n icon shortcuts like Search or Notifications.',
|
|
69
69
|
required: false,
|
|
70
70
|
type: '"subtle" | "ghost"',
|
|
71
71
|
default: '"subtle"'
|
|
@@ -52,7 +52,9 @@ its items, so moving between items shows each tooltip with no delay.
|
|
|
52
52
|
### Variants
|
|
53
53
|
|
|
54
54
|
- `variant="subtle"` (default) is a filled cell with a bar on its left edge when
|
|
55
|
-
active. Use the default slot for an image, an avatar or initials.
|
|
55
|
+
active. Use the default slot for an image, an avatar or initials. When the
|
|
56
|
+
slot holds an `<img>`, the cell paints no fill, so the image's rounded corners
|
|
57
|
+
show no gray rim. The bar still marks the active item.
|
|
56
58
|
- `variant="ghost"` is transparent until hovered, and raised when active. Pass
|
|
57
59
|
an `icon` for a shortcut such as Search or Notifications.
|
|
58
60
|
|
|
@@ -134,10 +134,14 @@ const cellClasses = computed(() => [
|
|
|
134
134
|
// `subtle` uses the community-tile radius; `ghost` mirrors frappe-ui's icon
|
|
135
135
|
// button (rounded-4 = 8px).
|
|
136
136
|
props.variant === 'subtle' ? 'rounded-[7px]' : 'rounded-4',
|
|
137
|
+
// A `subtle` item paints no fill under an image. Two anti-aliased curves
|
|
138
|
+
// never cover each other exactly, so a fill under a rounded image shows at
|
|
139
|
+
// its corners as a gray rim.
|
|
137
140
|
props.variant === 'subtle'
|
|
138
|
-
?
|
|
139
|
-
|
|
140
|
-
|
|
141
|
+
? [
|
|
142
|
+
resolvedActive.value ? 'bg-surface-gray-4' : 'bg-surface-gray-3',
|
|
143
|
+
'has-[img]:bg-transparent',
|
|
144
|
+
]
|
|
141
145
|
: resolvedActive.value
|
|
142
146
|
? 'text-ink-gray-8 !bg-surface-elevation-3 shadow-sm'
|
|
143
147
|
: 'text-ink-gray-8 bg-transparent hover:bg-surface-gray-3',
|
|
@@ -38,7 +38,8 @@ export interface SidebarRailItemProps {
|
|
|
38
38
|
/**
|
|
39
39
|
* Visual treatment.
|
|
40
40
|
* - `subtle` (default): a filled cell with a left indicator bar when active —
|
|
41
|
-
* for image/avatar items like communities or workspaces.
|
|
41
|
+
* for image/avatar items like communities or workspaces. The cell paints
|
|
42
|
+
* no fill when its default slot holds an `<img>`.
|
|
42
43
|
* - `ghost`: transparent until hovered, a raised highlight when active — for
|
|
43
44
|
* icon shortcuts like Search or Notifications.
|
|
44
45
|
*/
|
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
* conventions §1.6 contract.
|
|
10
10
|
*/
|
|
11
11
|
import { Plugin } from '@tiptap/pm/state'
|
|
12
|
+
import { isHistoryTransaction } from '@tiptap/pm/history'
|
|
12
13
|
import type { Transaction, EditorState } from '@tiptap/pm/state'
|
|
13
14
|
import type { EditorView } from '@tiptap/pm/view'
|
|
14
15
|
import type { Editor } from '@tiptap/core'
|
|
15
16
|
import { dispatchIfAlive } from '#molecules/editor/extensions/shared/node-view'
|
|
17
|
+
import { isRemoteChange } from '#molecules/editor/extensions/shared/collaboration'
|
|
16
18
|
import { resolveUploadOptions } from '#molecules/editor/extensions/shared/media-upload-engine'
|
|
17
19
|
import type {
|
|
18
20
|
MediaUploadConfig,
|
|
@@ -44,6 +46,19 @@ function collectFiles(
|
|
|
44
46
|
return files
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
/** Whether a transaction loads content or undoes/redoes, not a person's edit. */
|
|
50
|
+
function isLoadOrUndo(transaction: Transaction): boolean {
|
|
51
|
+
// A transaction another plugin appends (TrailingNode, ListJoin) carries no
|
|
52
|
+
// meta of its own. ProseMirror tags it with the root transaction that
|
|
53
|
+
// caused it, so ask that one too.
|
|
54
|
+
const root = transaction.getMeta('appendedTransaction') as
|
|
55
|
+
| Transaction
|
|
56
|
+
| undefined
|
|
57
|
+
return [transaction, root].some(
|
|
58
|
+
(tr) => tr && (tr.getMeta('preventUpdate') || isHistoryTransaction(tr)),
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
47
62
|
/**
|
|
48
63
|
* Build the drop + paste + dimension-back-fill plugin for one media node type.
|
|
49
64
|
*
|
|
@@ -79,8 +94,12 @@ export function createMediaPlugin(
|
|
|
79
94
|
},
|
|
80
95
|
|
|
81
96
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
97
|
+
* Back-fill width/height onto every media node that has a `src` but no
|
|
98
|
+
* dimensions and is not loading, after the person's own edit. This heals
|
|
99
|
+
* new and stored media alike. Loaded content, a collaborator's change and
|
|
100
|
+
* undo/redo write nothing, so opening or watching a document never
|
|
101
|
+
* changes it. The write is kept out of undo history, so Ctrl+Z reverts
|
|
102
|
+
* the person's edit.
|
|
84
103
|
*/
|
|
85
104
|
appendTransaction(
|
|
86
105
|
transactions: readonly Transaction[],
|
|
@@ -88,6 +107,8 @@ export function createMediaPlugin(
|
|
|
88
107
|
newState: EditorState,
|
|
89
108
|
): Transaction | null {
|
|
90
109
|
if (!transactions.some((tr) => tr.docChanged)) return null
|
|
110
|
+
if (isRemoteChange(transactions, newState)) return null
|
|
111
|
+
if (transactions.some(isLoadOrUndo)) return null
|
|
91
112
|
|
|
92
113
|
const pending: number[] = []
|
|
93
114
|
newState.doc.descendants((node, pos) => {
|
|
@@ -118,11 +139,13 @@ export function createMediaPlugin(
|
|
|
118
139
|
if (live.attrs.width != null && live.attrs.height != null) return
|
|
119
140
|
dispatchIfAlive(
|
|
120
141
|
view,
|
|
121
|
-
view.state.tr
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
142
|
+
view.state.tr
|
|
143
|
+
.setNodeMarkup(pos, undefined, {
|
|
144
|
+
...live.attrs,
|
|
145
|
+
width: live.attrs.width ?? dims.width,
|
|
146
|
+
height: live.attrs.height ?? dims.height,
|
|
147
|
+
})
|
|
148
|
+
.setMeta('addToHistory', false),
|
|
126
149
|
)
|
|
127
150
|
})
|
|
128
151
|
.catch(() => {
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
} from '@tiptap/suggestion'
|
|
6
6
|
import type { Component } from 'vue'
|
|
7
7
|
import {
|
|
8
|
+
autoUpdate,
|
|
8
9
|
computePosition,
|
|
9
10
|
flip,
|
|
10
11
|
offset,
|
|
@@ -40,6 +41,9 @@ export function createSuggestionRenderer(
|
|
|
40
41
|
let isActive = false
|
|
41
42
|
// Monotonic token; a stale onUpdate from a superseded query bails.
|
|
42
43
|
let renderToken = 0
|
|
44
|
+
// Monotonic token; a stale computePosition settling later bails.
|
|
45
|
+
let positionToken = 0
|
|
46
|
+
let cleanupAutoUpdate: (() => void) | null = null
|
|
43
47
|
|
|
44
48
|
function getListExpose(): SuggestionListExpose | null {
|
|
45
49
|
const ref = renderer?.ref as SuggestionListExpose | null | undefined
|
|
@@ -52,6 +56,7 @@ export function createSuggestionRenderer(
|
|
|
52
56
|
const rect = getReferenceClientRect()
|
|
53
57
|
if (!rect) return
|
|
54
58
|
const reference = { getBoundingClientRect: () => rect }
|
|
59
|
+
const token = ++positionToken
|
|
55
60
|
void computePosition(reference, floatingEl, {
|
|
56
61
|
placement: floatingOptions?.placement ?? 'bottom-start',
|
|
57
62
|
middleware: [
|
|
@@ -60,7 +65,7 @@ export function createSuggestionRenderer(
|
|
|
60
65
|
shift({ padding: 8 }),
|
|
61
66
|
],
|
|
62
67
|
}).then(({ x, y }) => {
|
|
63
|
-
if (!floatingEl) return
|
|
68
|
+
if (!floatingEl || token !== positionToken) return
|
|
64
69
|
Object.assign(floatingEl.style, {
|
|
65
70
|
position: 'absolute',
|
|
66
71
|
left: `${x}px`,
|
|
@@ -93,7 +98,21 @@ export function createSuggestionRenderer(
|
|
|
93
98
|
floatingEl.style.position = 'absolute'
|
|
94
99
|
document.body.appendChild(floatingEl)
|
|
95
100
|
getReferenceClientRect = props.clientRect as () => DOMRect | null
|
|
96
|
-
|
|
101
|
+
|
|
102
|
+
// Positions once, then keeps the popup on the caret through scroll, window
|
|
103
|
+
// resize and its own height changes (`flip()` measures a height that async
|
|
104
|
+
// rows and late fonts change after the fact). autoUpdate reads only
|
|
105
|
+
// `contextElement`, to find the editor's scroll ancestors; `updatePosition`
|
|
106
|
+
// reads the caret rect itself.
|
|
107
|
+
cleanupAutoUpdate = autoUpdate(
|
|
108
|
+
{
|
|
109
|
+
getBoundingClientRect: () =>
|
|
110
|
+
getReferenceClientRect?.() ?? new DOMRect(),
|
|
111
|
+
contextElement: props.editor.view.dom,
|
|
112
|
+
},
|
|
113
|
+
floatingEl,
|
|
114
|
+
updatePosition,
|
|
115
|
+
)
|
|
97
116
|
}
|
|
98
117
|
|
|
99
118
|
return {
|
|
@@ -139,6 +158,9 @@ export function createSuggestionRenderer(
|
|
|
139
158
|
onExit() {
|
|
140
159
|
isActive = false
|
|
141
160
|
renderToken++
|
|
161
|
+
positionToken++
|
|
162
|
+
cleanupAutoUpdate?.()
|
|
163
|
+
cleanupAutoUpdate = null
|
|
142
164
|
floatingEl?.remove()
|
|
143
165
|
renderer?.destroy()
|
|
144
166
|
floatingEl = null
|
|
@@ -100,6 +100,14 @@ export function useEditor(
|
|
|
100
100
|
extensions,
|
|
101
101
|
editable: toValue(options.editable) ?? true,
|
|
102
102
|
autofocus: options.autofocus,
|
|
103
|
+
editorProps: {
|
|
104
|
+
handleDOMEvents: {
|
|
105
|
+
// ProseMirror's dragstart runs even when read-only and overwrites the drag
|
|
106
|
+
// data; claiming the event (without preventDefault) keeps the browser's
|
|
107
|
+
// native payload, such as a link URL.
|
|
108
|
+
dragstart: (view) => !view.editable,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
103
111
|
onUpdate: ({ editor: tiptapEditor }) => {
|
|
104
112
|
if (!isCollaborationMode && options.content && !applyingExternalUpdate) {
|
|
105
113
|
const value = serialize(tiptapEditor)
|
|
@@ -17,9 +17,25 @@ export function onDocUpdate(
|
|
|
17
17
|
})
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
// Doctypes subscribed per socket, so each new Socket subscribes on its own and
|
|
21
|
+
// a closed one can be garbage collected.
|
|
22
|
+
const subscribed = new WeakMap<Socket, Set<string>>()
|
|
23
|
+
|
|
21
24
|
function subscribe(socket: Socket, doctype: string): void {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
const doctypes = subscribed.get(socket) ?? new Set<string>()
|
|
26
|
+
if (!subscribed.has(socket)) {
|
|
27
|
+
subscribed.set(socket, doctypes)
|
|
28
|
+
// Server-side rooms are per-socket and dropped on disconnect. This handler
|
|
29
|
+
// subscribes to every doctype on the first connect and on each reconnect.
|
|
30
|
+
socket.on('connect', () => {
|
|
31
|
+
for (const type of doctypes) {
|
|
32
|
+
socket.emit('doctype_subscribe', type)
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
if (doctypes.has(doctype)) return
|
|
37
|
+
doctypes.add(doctype)
|
|
38
|
+
// socket.io buffers emits while disconnected and flushes them before
|
|
39
|
+
// `connect`, so emit directly only on a connected socket.
|
|
40
|
+
if (socket.connected) socket.emit('doctype_subscribe', doctype)
|
|
25
41
|
}
|
package/tailwind/plugin.js
CHANGED
|
@@ -333,6 +333,13 @@ export default plugin(
|
|
|
333
333
|
'h5 strong': {
|
|
334
334
|
fontWeight: 600,
|
|
335
335
|
},
|
|
336
|
+
// keep a named text color on bold text (typography's `strong` color would override it)
|
|
337
|
+
':where(span[style*="--prose-color-"]) strong': {
|
|
338
|
+
color: 'inherit',
|
|
339
|
+
},
|
|
340
|
+
'strong:where([style*="--prose-color-"])': {
|
|
341
|
+
color: 'inherit',
|
|
342
|
+
},
|
|
336
343
|
'img[data-align=right]': {
|
|
337
344
|
marginLeft: 'auto',
|
|
338
345
|
marginRight: '0',
|
|
@@ -436,19 +443,6 @@ export default plugin(
|
|
|
436
443
|
borderBottom: '1px solid var(--ink-gray-6)',
|
|
437
444
|
},
|
|
438
445
|
|
|
439
|
-
// named text color + bold: the color lives on a `textStyle`
|
|
440
|
-
// span that wraps (or is wrapped by) `<strong>`. Typography's
|
|
441
|
-
// `strong { color: var(--tw-prose-bold) }` otherwise overrides
|
|
442
|
-
// the inherited named color, painting bold text gray. Mirror the
|
|
443
|
-
// base preset's `a strong { color: inherit }` so bold keeps the
|
|
444
|
-
// span's color in both nesting orders.
|
|
445
|
-
':where(span[style*="--prose-color-"]) strong': {
|
|
446
|
-
color: 'inherit',
|
|
447
|
-
},
|
|
448
|
-
'strong:where([style*="--prose-color-"])': {
|
|
449
|
-
color: 'inherit',
|
|
450
|
-
},
|
|
451
|
-
|
|
452
446
|
// inline code: subtle pill — strip Tailwind's added quotes
|
|
453
447
|
'code::before': { content: 'none' },
|
|
454
448
|
'code::after': { content: 'none' },
|