frappe-ui 1.0.0 → 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.
@@ -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.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 && 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,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",
@@ -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>
@@ -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(value: ComboboxOptionValue) {
310
- const option =
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?.label ?? String(value)
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.value)
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 left-0 top-1/2 z-[1] flex max-w-[35%] -translate-y-1/2 justify-start"
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 right-0 top-1/2 z-[1] flex max-w-[35%] -translate-y-1/2 justify-end"
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. Screen readers read `label` as the value text, or the
61
- percentage when there is no label.
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
- * A bare percentage (reka-ui's default) says how far along the bar is but not
98
- * what it measures, so prefer the visible label when there is one.
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.\n- `ghost`: transparent until hovered, a raised highlight when active — for\n icon shortcuts like Search or Notifications.',
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
- ? resolvedActive.value
139
- ? 'bg-surface-gray-4'
140
- : 'bg-surface-gray-3'
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
- * After any doc-changing transaction, back-fill width/height onto freshly
83
- * inserted nodes that have a `src` but no dimensions and are not loading.
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.setNodeMarkup(pos, undefined, {
122
- ...live.attrs,
123
- width: live.attrs.width ?? dims.width,
124
- height: live.attrs.height ?? dims.height,
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
- updatePosition()
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
- let subscribed: Record<string, boolean> = {}
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
- if (subscribed[doctype]) return
23
- socket.emit('doctype_subscribe', doctype)
24
- subscribed[doctype] = true
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
  }
@@ -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' },