frappe-ui 1.0.0 → 1.0.2

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.
Files changed (34) hide show
  1. package/experimental/TextEditor/TextEditor.vue +7 -0
  2. package/package.json +6 -4
  3. package/src/charts/axisChartCommon.ts +97 -33
  4. package/src/charts/axisChartOptions.ts +3 -22
  5. package/src/charts/core/dataLabelFit.ts +88 -0
  6. package/src/charts/core/useAxisChart.ts +37 -0
  7. package/src/charts/scatterOptions.ts +1 -6
  8. package/src/components/Checkbox/Checkbox.vue +8 -4
  9. package/src/components/Combobox/Combobox.vue +20 -7
  10. package/src/components/Combobox/ComboboxResults.vue +2 -0
  11. package/src/components/Dialog/Dialog.vue +8 -1
  12. package/src/components/MobileNav/MobileNav.vue +4 -3
  13. package/src/components/MobileShell/MobileShell.md +4 -1
  14. package/src/components/MultiSelect/MultiSelect.vue +2 -0
  15. package/src/components/PageHeader/PageHeaderMobile.vue +2 -2
  16. package/src/components/Progress/Progress.md +2 -2
  17. package/src/components/Progress/Progress.vue +4 -5
  18. package/src/components/SidebarRail/SidebarRail.api.md +1 -1
  19. package/src/components/SidebarRail/SidebarRail.md +3 -1
  20. package/src/components/SidebarRail/SidebarRailItem.vue +7 -3
  21. package/src/components/SidebarRail/types.ts +2 -1
  22. package/src/components/shared/selection/useFilteredGroups.ts +39 -5
  23. package/src/molecules/editor/extensions/mention/mention-extension.ts +2 -2
  24. package/src/molecules/editor/extensions/shared/media-plugin.ts +30 -7
  25. package/src/molecules/editor/extensions/shared/suggestion-helpers.ts +9 -0
  26. package/src/molecules/editor/extensions/shared/suggestion-renderer.ts +30 -2
  27. package/src/molecules/editor/useEditor.ts +8 -0
  28. package/src/resources/realtime.ts +20 -4
  29. package/src/style.css +12 -0
  30. package/src/utils/rankMatch.ts +18 -0
  31. package/tailwind/plugin.js +7 -13
  32. package/vite/benchFiles.js +36 -0
  33. package/vite/index.js +4 -0
  34. package/vite/utils.js +57 -7
@@ -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.0",
3
+ "version": "1.0.2",
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 && nyc report",
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,7 @@
299
300
  }
300
301
  },
301
302
  "devDependencies": {
303
+ "@changesets/cli": "^2.31.1",
302
304
  "@codemirror/lang-css": "^6.3.0",
303
305
  "@codemirror/lang-html": "^6.4.9",
304
306
  "@codemirror/lang-javascript": "^6.2.2",
@@ -1,3 +1,4 @@
1
+ import { dayjs } from '#utils/dayjs'
1
2
  import {
2
3
  estimateTextWidth,
3
4
  formatAxisValue,
@@ -341,8 +342,8 @@ export function axisChartBase(
341
342
  * the grid only reserves room for its own axis labels and names. echarts does
342
343
  * that reservation itself: it measures the labels it has already laid out and
343
344
  * shrinks the plot until they fit the outer bounds. What it does not cover is
344
- * data labels, which sit past the end of a mark and would otherwise be clipped
345
- * by the plot edge — hence `labelGutter`.
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`).
346
347
  *
347
348
  * A label is measured as the box its rotation gives it, so a tilted category
348
349
  * axis (see `categoryLabelFit`) takes its own height out of the plot without the
@@ -354,21 +355,27 @@ export function axisChartBase(
354
355
  // plot to keep the labels inside it and never spends the two pixels.
355
356
  const EDGE_PAD = 2
356
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
+
357
367
  export function buildAxisGrid(opts: {
358
368
  horizontal: boolean
359
- isRTL: boolean
360
- labelGutter: number
361
369
  /** Title on the category axis, which only a horizontal chart draws inline. */
362
370
  xAxisTitle?: string
363
371
  }) {
364
- const { horizontal, isRTL, labelGutter, xAxisTitle } = opts
365
- const endGutter = horizontal ? labelGutter : 0
372
+ const { horizontal, xAxisTitle } = opts
366
373
 
367
374
  return {
368
- top: 8 + (horizontal ? 0 : labelGutter),
375
+ top: 8,
369
376
  bottom: 0,
370
- left: EDGE_PAD + (isRTL ? endGutter : 0),
371
- right: (xAxisTitle && horizontal ? 24 : EDGE_PAD) + (isRTL ? 0 : endGutter),
377
+ left: EDGE_PAD,
378
+ right: xAxisTitle && horizontal ? 24 : EDGE_PAD,
372
379
  // What `containLabel` did until echarts 6, plus the two things it never did:
373
380
  // it reserves on both dimensions, so the label at either end of a horizontal
374
381
  // axis stops overhanging the canvas, and `all` covers the axis name as well
@@ -390,14 +397,18 @@ export function buildXAxis(
390
397
  categories: any[]
391
398
  horizontal: boolean
392
399
  isRTL: boolean
393
- /** Bars need a half-slot inset at each end; a line runs edge to edge. */
394
- boundaryGap: boolean
400
+ /** Whether a time axis is padded at each end, as echarts only does for bars. */
401
+ inset: boolean
395
402
  /** Plot width in pixels, when known. Decides how the labels are laid out. */
396
403
  width?: number
397
404
  },
398
405
  ) {
399
- const { categories, horizontal, isRTL, boundaryGap } = opts
406
+ const { categories, horizontal, isRTL, width } = opts
400
407
  const { type, timeGrain } = resolveXAxis(config, horizontal)
408
+ const inset =
409
+ type === 'time' && opts.inset
410
+ ? timeInset(config, categories, width)
411
+ : undefined
401
412
  const { rotate, labelWidth } = categoryLabelFit(config, { ...opts, type })
402
413
 
403
414
  const axis = {
@@ -410,7 +421,10 @@ export function buildXAxis(
410
421
  // horizontal bar chart is inverted so the first category sits on top.
411
422
  inverse: horizontal ? true : isRTL,
412
423
  position: horizontal ? (isRTL ? 'right' : 'left') : 'bottom',
413
- ...(type === 'category' ? { data: categories, boundaryGap } : {}),
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 : {}),
414
428
  name: config.xAxis.title ? formatLabel(config.xAxis.title) : undefined,
415
429
  nameLocation: 'end',
416
430
  nameGap: 8,
@@ -443,13 +457,55 @@ export function buildXAxis(
443
457
  // Left out entirely when the labels fit, so a flat axis carries no
444
458
  // rotation key at all.
445
459
  ...(rotate ? { rotate } : {}),
446
- ...xAxisLabelFormat(type, { tokens, timeGrain, labelWidth }),
460
+ ...xAxisLabelFormat(type, {
461
+ tokens,
462
+ timeGrain,
463
+ labelWidth,
464
+ dataRange: inset?.dataRange,
465
+ }),
447
466
  },
448
467
  }
449
468
 
450
469
  return mergeDeep(axis, config.xAxis.echartOptions)
451
470
  }
452
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
+
453
509
  /**
454
510
  * How a tick prints, which is most of what the three readings disagree about.
455
511
  * A value axis prints the compact tick the value axis on the other side of the
@@ -458,7 +514,13 @@ export function buildXAxis(
458
514
  */
459
515
  function xAxisLabelFormat(
460
516
  type: ResolvedXAxis['type'],
461
- opts: { tokens: ChartTokens; timeGrain?: TimeGrain; labelWidth?: number },
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
+ },
462
524
  ) {
463
525
  if (type === 'time') {
464
526
  return {
@@ -467,7 +529,10 @@ function xAxisLabelFormat(
467
529
  // than as another tick. `primary` is echarts' own name for that level's
468
530
  // rich style.
469
531
  formatter: (value: any, _index: number, extra?: { level: number }) =>
470
- formatTimeAxisLabel(value, opts.timeGrain, extra?.level),
532
+ opts.dataRange &&
533
+ (value < opts.dataRange[0] || value > opts.dataRange[1])
534
+ ? ''
535
+ : formatTimeAxisLabel(value, opts.timeGrain, extra?.level),
471
536
  rich: {
472
537
  primary: {
473
538
  color: opts.tokens.axisTitle,
@@ -516,7 +581,6 @@ function categoryLabelFit(
516
581
  categories: any[]
517
582
  horizontal: boolean
518
583
  isRTL: boolean
519
- boundaryGap: boolean
520
584
  width?: number
521
585
  type: ResolvedXAxis['type']
522
586
  },
@@ -553,28 +617,26 @@ function categoryLabelFit(
553
617
  }
554
618
  }
555
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
+
556
625
  /**
557
626
  * The room one category gets along the axis, or undefined where there is
558
- * nothing to decide from: a chart that has not been measured, one measured at
559
- * nothing, or a line with a single point, which has no neighbour to collide
560
- * 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.
561
629
  */
562
630
  function categorySlotWidth(
563
631
  config: AxisChartBaseConfig,
564
- opts: { categories: any[]; boundaryGap: boolean; width?: number },
632
+ opts: { categories: any[]; width?: number },
565
633
  ) {
566
- if (!opts.width) return undefined
567
-
568
- const plot = opts.width - 2 * EDGE_PAD - valueAxisReserve(config)
569
- // `boundaryGap` gives every category a slot of its own to sit in the middle
570
- // of; without it they sit on the dividers, so what has to hold a label is
571
- // the distance between two ticks.
572
- const slots = opts.boundaryGap
573
- ? opts.categories.length
574
- : opts.categories.length - 1
634
+ if (!opts.width || !opts.categories.length) return undefined
575
635
 
576
- if (plot <= 0 || slots < 1) return undefined
577
- return plot / slots
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
578
640
  }
579
641
 
580
642
  /**
@@ -692,7 +754,9 @@ function categoryLabelWidth(width?: number) {
692
754
 
693
755
  function categoryLabel(label: string, labelWidth?: number) {
694
756
  if (!labelWidth) return label
695
- return truncateMiddleToWidth(label, labelWidth, AXIS_LABEL_FONT_SIZE)
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)
696
760
  }
697
761
 
698
762
  /**
@@ -33,10 +33,6 @@ const BAR_MAX_WIDTH = 32
33
33
  /** Slim bars with an airy gap between categories. */
34
34
  const BAR_CATEGORY_GAP = '38%'
35
35
  const BAR_RADIUS = 4
36
- /** Room for a data label sitting past the end of a bar. */
37
- const BAR_LABEL_GUTTER = 40
38
- /** Room for a data label sitting above a point. */
39
- const LINE_LABEL_GUTTER = 24
40
36
 
41
37
  export const DEFAULT_LINE_WIDTH = 2
42
38
  /** Big enough to hit with a pointer, small enough not to read as a scatter plot. */
@@ -117,7 +113,7 @@ export function buildAxisChartOption(
117
113
  (entry) => !hiddenSeries.includes(entry.series.name),
118
114
  )
119
115
  // Read over *every* series rather than the visible ones: hiding the last bar
120
- // in the legend should not re-space the category axis under the plot.
116
+ // in the legend should not swap the pointer from a shade to a rule.
121
117
  const hasBars = plotted.some((entry) => entry.mark === 'bar')
122
118
  const categories = rows.map((row) => row[config.xAxis.key])
123
119
  // A point on a value axis carries its own coordinate; on the other two the
@@ -133,8 +129,8 @@ export function buildAxisChartOption(
133
129
  categories,
134
130
  horizontal,
135
131
  isRTL,
136
- // Bars need a half-slot inset at each end to sit in; a line runs edge to edge.
137
- boundaryGap: hasBars,
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'),
138
134
  width,
139
135
  })
140
136
  const hasSecondary = hasSecondaryValueAxis(config, horizontal)
@@ -152,8 +148,6 @@ export function buildAxisChartOption(
152
148
  ...axisChartBase(tokens, hasBars ? 'shadow' : 'line'),
153
149
  grid: buildAxisGrid({
154
150
  horizontal,
155
- isRTL,
156
- labelGutter: dataLabelGutter(plotted),
157
151
  xAxisTitle: config.xAxis.title,
158
152
  }),
159
153
  xAxis: horizontal ? valueAxis : xColumnAxis,
@@ -351,19 +345,6 @@ function pinValueAxis(
351
345
  }
352
346
  }
353
347
 
354
- /** Chart-wide room for the labels, i.e. whatever the hungriest mark needs. */
355
- function dataLabelGutter(plotted: PlottedSeries[]) {
356
- let gutter = 0
357
- for (const { series, mark, stack } of plotted) {
358
- if (!series.showDataLabels) continue
359
- // Stacked labels sit inside the fill, so they need no gutter.
360
- const needed =
361
- mark === 'bar' ? (stack ? 0 : BAR_LABEL_GUTTER) : LINE_LABEL_GUTTER
362
- gutter = Math.max(gutter, needed)
363
- }
364
- return gutter
365
- }
366
-
367
348
  function buildSeries(
368
349
  entry: PlottedSeries,
369
350
  config: AxisChartConfig,
@@ -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'
@@ -155,6 +156,9 @@ export function useAxisChart<C extends AxisChartConfig>(
155
156
  click: (params: any) => {
156
157
  select(params.seriesName, rows.value[params.dataIndex])
157
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(),
158
162
  },
159
163
  onZrEvents: {
160
164
  mousemove: (e: any) => updateTooltip(e.offsetX, e.offsetY, e.event),
@@ -164,6 +168,39 @@ export function useAxisChart<C extends AxisChartConfig>(
164
168
  },
165
169
  })
166
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
+
167
204
  const legendItems = computed<ChartLegendItem[]>(() =>
168
205
  config.value.series.map((series) => ({
169
206
  name: series.name,
@@ -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.
@@ -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
- 'hover:shadow-none focus:ring-0 focus:ring-offset-0',
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 / hover 9 / active 8.
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 checked:group-hover:text-[color:var(--surface-gray-9)]'
230
- : 'hover:border-outline-gray-5 hover:shadow-sm active:border-outline-gray-6 focus-visible:focus-ring checked:hover:text-[color:var(--surface-gray-9)] checked:active:text-[color:var(--surface-gray-8)]',
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>
@@ -17,6 +17,7 @@ import { useReactiveSlots } from '../../composables/useReactiveSlots'
17
17
  import { usePortalTarget } from '../../composables/usePortalTarget'
18
18
  import { useEmptyValueMapping } from '../shared/selection/useEmptyValueMapping'
19
19
  import { useFilteredGroups } from '../shared/selection/useFilteredGroups'
20
+ import { rankMatch } from '../../utils/rankMatch'
20
21
  import { useIsModelBound } from '../shared/selection/useIsModelBound'
21
22
  import {
22
23
  InputDescription,
@@ -52,6 +53,7 @@ import type {
52
53
  NormalizedCustomOption,
53
54
  NormalizedGroup,
54
55
  NormalizedItem,
56
+ NormalizedSelectableOption,
55
57
  } from './utils'
56
58
 
57
59
  defineOptions({
@@ -233,6 +235,8 @@ const filteredGroups = useFilteredGroups<NormalizedItem, NormalizedGroup>({
233
235
  item.type === 'custom'
234
236
  ? matchesCustomOption(item, q)
235
237
  : matchesSelectableOption(item, q),
238
+ // custom action rows keep their place; options rank by how well they match
239
+ rank: (item, q) => (item.type === 'custom' ? null : rankMatch(item.label, q)),
236
240
  // `alwaysMatch` carries consumer-declared visibility: a custom row's
237
241
  // `condition` is authoritative and runs even before the user types, so it
238
242
  // is deliberately unaffected by `filterable`.
@@ -306,13 +310,10 @@ const searchSlotProps = computed<ComboboxSearchSlotProps>(() => ({
306
310
  focus: focusSearch,
307
311
  }))
308
312
 
309
- function commitSelectableOption(value: ComboboxOptionValue) {
310
- const option =
311
- allSelectableOptions.value.find((item) => item.value === value) ?? null
312
-
313
- model.value = value
313
+ function commitSelectableOption(option: NormalizedSelectableOption) {
314
+ model.value = option.value
314
315
  emit('update:selectedOption', option)
315
- query.value = option?.label ?? String(value)
316
+ query.value = option.label
316
317
  hasTypedSinceOpen.value = false
317
318
  }
318
319
 
@@ -330,7 +331,7 @@ function handleRootModelValueChange(
330
331
  )
331
332
 
332
333
  if (selectableOption) {
333
- commitSelectableOption(selectableOption.value)
334
+ commitSelectableOption(selectableOption)
334
335
  }
335
336
  }
336
337
 
@@ -362,6 +363,17 @@ function handleCustomItemSelect(item: NormalizedCustomOption, event: Event) {
362
363
  if (!item.keepOpen) open.value = false
363
364
  }
364
365
 
366
+ // Commit before closing. Reka closes first and sends the value later, and
367
+ // closing resets the query. Options derived from the query can then drop the
368
+ // picked option before the value arrives.
369
+ function handleOptionSelect(item: NormalizedSelectableOption, event: Event) {
370
+ event.preventDefault()
371
+ if (item.disabled || props.disabled) return
372
+
373
+ commitSelectableOption(item)
374
+ open.value = false
375
+ }
376
+
365
377
  function handleFocusScopeMountAutoFocus(event: Event) {
366
378
  // In input mode the trigger is the search input — keep focus there so the
367
379
  // user can keep typing. FocusScope's default would yank focus to the first
@@ -771,6 +783,7 @@ defineSlots<ComboboxSlots>()
771
783
  :slot-fns="slotFns"
772
784
  :all-selectable-options="allSelectableOptions"
773
785
  @select-custom="handleCustomItemSelect"
786
+ @select-option="handleOptionSelect"
774
787
  />
775
788
 
776
789
  <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
 
@@ -40,7 +40,7 @@
40
40
  "
41
41
  @interact-outside="
42
42
  (e: Event) => {
43
- if (!isDismissible) e.preventDefault()
43
+ if (!isDismissible || isEditorFloating(e)) e.preventDefault()
44
44
  }
45
45
  "
46
46
  >
@@ -208,6 +208,13 @@ const slots = useReactiveSlots<DialogSlots>()
208
208
 
209
209
  const isDismissible = computed(() => props.dismissible !== false)
210
210
 
211
+ // the editor's suggestion menus (@mention, /, #, :) live on <body>; picking from one isn't leaving the dialog
212
+ function isEditorFloating(e: Event) {
213
+ return (
214
+ e.target instanceof Element && !!e.target.closest('[data-editor-floating]')
215
+ )
216
+ }
217
+
211
218
  const sizeClass = computed(() => {
212
219
  const map: Record<string, string> = {
213
220
  xs: 'max-w-xs',