frappe-ui 1.0.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/experimental/Calendar/CalendarEventRow.vue +0 -4
  2. package/experimental/Calendar/calendarUtils.ts +33 -21
  3. package/experimental/CommandPalette/CommandPaletteItem.vue +9 -1
  4. package/experimental/MultiEmailInput/MultiEmailInput.vue +64 -12
  5. package/experimental/MultiEmailInput/types.ts +12 -3
  6. package/experimental/SpriteIcons/IconPicker.vue +2 -1
  7. package/experimental/Stepper/StepIndicator.vue +129 -0
  8. package/experimental/Stepper/Stepper.api.md +117 -0
  9. package/experimental/Stepper/Stepper.md +95 -0
  10. package/experimental/Stepper/Stepper.vue +82 -0
  11. package/experimental/Stepper/StepperHorizontal.vue +93 -0
  12. package/experimental/Stepper/StepperVertical.vue +291 -0
  13. package/experimental/Stepper/index.ts +11 -0
  14. package/experimental/Stepper/resolve.ts +87 -0
  15. package/experimental/Stepper/types.ts +89 -0
  16. package/experimental.ts +2 -21
  17. package/package.json +1 -3
  18. package/src/charts/CalendarHeatmapChart.vue +353 -0
  19. package/src/charts/DonutChart.vue +34 -58
  20. package/src/charts/HeatmapChart.vue +26 -64
  21. package/src/charts/NumberCard.vue +62 -7
  22. package/src/charts/PercentageBarChart.vue +243 -0
  23. package/src/charts/SankeyChart.vue +14 -11
  24. package/src/charts/ScatterChart.vue +24 -20
  25. package/src/charts/axisChartCommon.ts +182 -18
  26. package/src/charts/axisFormat.ts +8 -3
  27. package/src/charts/calendarHeatmapOptions.ts +604 -0
  28. package/src/charts/colorMath.ts +26 -0
  29. package/src/charts/components/ChartContainer.vue +63 -53
  30. package/src/charts/components/ChartLegend.vue +216 -24
  31. package/src/charts/components/ChartScale.vue +85 -0
  32. package/src/charts/core/dataLabelFit.ts +45 -6
  33. package/src/charts/core/useAxisChart.ts +36 -19
  34. package/src/charts/core/useChart.ts +6 -1
  35. package/src/charts/core/usePlotKeyboard.ts +13 -2
  36. package/src/charts/docs/BarChart.md +11 -3
  37. package/src/charts/docs/CalendarHeatmapChart.api.md +165 -0
  38. package/src/charts/docs/CalendarHeatmapChart.md +33 -0
  39. package/src/charts/docs/ChartContainer.api.md +6 -0
  40. package/src/charts/docs/ChartLegend.api.md +1 -1
  41. package/src/charts/docs/ChartLegend.md +25 -3
  42. package/src/charts/docs/DonutChart.api.md +12 -0
  43. package/src/charts/docs/DonutChart.md +17 -0
  44. package/src/charts/docs/HeatmapChart.api.md +1 -1
  45. package/src/charts/docs/LineChart.md +5 -3
  46. package/src/charts/docs/NumberCard.api.md +6 -0
  47. package/src/charts/docs/NumberCard.md +6 -0
  48. package/src/charts/docs/Overview.md +13 -6
  49. package/src/charts/docs/PercentageBarChart.api.md +148 -0
  50. package/src/charts/docs/PercentageBarChart.md +42 -0
  51. package/src/charts/docs/ScatterChart.md +2 -3
  52. package/src/charts/donutChartOptions.ts +22 -130
  53. package/src/charts/format.ts +4 -1
  54. package/src/charts/heatmapOptions.ts +17 -12
  55. package/src/charts/hiddenSeries.ts +8 -3
  56. package/src/charts/index.ts +12 -0
  57. package/src/charts/legendOverflow.ts +40 -0
  58. package/src/charts/numberCardFormat.ts +19 -13
  59. package/src/charts/referenceLines.ts +2 -1
  60. package/src/charts/scatterOptions.ts +16 -3
  61. package/src/charts/seriesData.ts +8 -3
  62. package/src/charts/slices.ts +228 -0
  63. package/src/charts/tokens.ts +99 -0
  64. package/src/charts/types.ts +318 -9
  65. package/src/components/Avatar/Avatar.md +27 -2
  66. package/src/components/Avatar/Avatar.vue +29 -12
  67. package/src/components/Breadcrumbs/Breadcrumbs.vue +2 -1
  68. package/src/components/Combobox/Combobox.vue +9 -2
  69. package/src/components/Combobox/ComboboxResults.vue +6 -1
  70. package/src/components/Combobox/utils.ts +2 -1
  71. package/src/components/DatePicker/DatePicker.md +7 -0
  72. package/src/components/DatePicker/DatePicker.vue +6 -0
  73. package/src/components/DatePicker/DateTimePicker.vue +6 -0
  74. package/src/components/DatePicker/composables.ts +18 -1
  75. package/src/components/DatePicker/utils.ts +53 -0
  76. package/src/components/Dialog/Dialog.md +3 -1
  77. package/src/components/Duration/Duration.api.md +16 -3
  78. package/src/components/Duration/Duration.md +21 -0
  79. package/src/components/Duration/Duration.vue +29 -8
  80. package/src/components/Duration/duration.ts +105 -44
  81. package/src/components/Duration/index.ts +1 -0
  82. package/src/components/Duration/types.ts +30 -1
  83. package/src/components/HoverCard/HoverCard.vue +21 -5
  84. package/src/components/Menu/utils.ts +3 -2
  85. package/src/components/MobileNav/MobileNavItem.vue +3 -22
  86. package/src/components/MultiSelect/MultiSelect.api.md +5 -0
  87. package/src/components/MultiSelect/MultiSelect.vue +34 -0
  88. package/src/components/MultiSelect/MultiSelectResults.vue +3 -4
  89. package/src/components/MultiSelect/types.ts +6 -0
  90. package/src/components/Select/Select.vue +4 -4
  91. package/src/components/Select/utils.ts +1 -0
  92. package/src/components/SettingsDialog/SettingsDialog.api.md +7 -2
  93. package/src/components/SettingsDialog/SettingsDialog.md +2 -1
  94. package/src/components/SettingsDialog/SettingsRow.vue +12 -2
  95. package/src/components/Sidebar/SidebarItem.vue +3 -33
  96. package/src/components/SidebarRail/SidebarRailItem.vue +4 -17
  97. package/src/components/Switch/Switch.vue +3 -3
  98. package/src/components/Tooltip/Tooltip.vue +8 -0
  99. package/src/components/shared/deferredTrigger.ts +174 -0
  100. package/src/components/shared/navLink.ts +45 -0
  101. package/src/components/shared/selection/utils.ts +8 -1
  102. package/src/data-fetching/useCall/useCall.ts +25 -26
  103. package/src/data-fetching/useFrappeFetch.ts +48 -2
  104. package/src/data-fetching/useList/useList.ts +11 -3
  105. package/src/data-fetching/utils.ts +15 -1
  106. package/src/molecules/editor/components/MediaNodeView.vue +10 -1
  107. package/src/molecules/editor/components/MediaResizeGuide.vue +71 -0
  108. package/src/molecules/editor/components/media-node-view-utils.ts +7 -0
  109. package/src/molecules/editor/composables/useNodeViewResize.ts +142 -10
  110. package/src/molecules/editor/extensions/attachment/attachment-engine.ts +1 -1
  111. package/src/molecules/editor/extensions/content-paste/paste-html-utils.ts +16 -6
  112. package/src/molecules/editor/extensions/iframe/IframeNodeView.vue +29 -10
  113. package/src/molecules/editor/extensions/iframe/iframe-allowlist.ts +35 -16
  114. package/src/molecules/editor/extensions/iframe/iframe-embed-utils.ts +1 -1
  115. package/src/molecules/editor/extensions/iframe/iframe-extension.ts +30 -30
  116. package/src/molecules/editor/extensions/link/LinkEditorPopup.vue +1 -1
  117. package/src/molecules/editor/extensions/link/link-paste-plugin.ts +1 -1
  118. package/src/molecules/editor/extensions/shared/media-upload-engine.ts +1 -1
  119. package/src/molecules/editor/useEditor.ts +12 -6
  120. package/src/molecules/list/ListRow.vue +8 -1
  121. package/src/utils/dialog.ts +57 -16
  122. package/src/{molecules/editor/extensions/shared → utils}/url-safety.ts +28 -16
  123. package/tailwind/content.js +1 -1
  124. package/tailwind/plugin.js +22 -0
  125. package/vite/README.md +5 -3
  126. package/vite/codeLanguages.js +41 -17
  127. package/vite/doctypeInterfaceGenerator.js +52 -39
  128. package/vitepress/index.node.ts +0 -2
  129. package/experimental/TextEditor/TextEditor.api.md +0 -161
  130. package/experimental/TextEditor/TextEditor.vue +0 -298
  131. package/experimental/TextEditor/classIcon.ts +0 -21
  132. package/experimental/TextEditor/commands.js +0 -344
  133. package/experimental/TextEditor/components/CodeBlockComponent.vue +0 -103
  134. package/experimental/TextEditor/components/FontColor.vue +0 -153
  135. package/experimental/TextEditor/components/ImageViewerModal.vue +0 -463
  136. package/experimental/TextEditor/components/InsertImage.vue +0 -54
  137. package/experimental/TextEditor/components/InsertLink.vue +0 -13
  138. package/experimental/TextEditor/components/InsertVideo.vue +0 -14
  139. package/experimental/TextEditor/components/LinkPopup.vue +0 -99
  140. package/experimental/TextEditor/components/MediaNodeView.vue +0 -398
  141. package/experimental/TextEditor/components/MentionList.vue +0 -95
  142. package/experimental/TextEditor/components/TextEditorBubbleMenu.vue +0 -78
  143. package/experimental/TextEditor/components/TextEditorFixedMenu.vue +0 -78
  144. package/experimental/TextEditor/components/TextEditorFloatingMenu.vue +0 -61
  145. package/experimental/TextEditor/components/TextEditorMenu.vue +0 -218
  146. package/experimental/TextEditor/components/index.js +0 -0
  147. package/experimental/TextEditor/extensions/code-block.ts +0 -119
  148. package/experimental/TextEditor/extensions/color/color-extension.ts +0 -140
  149. package/experimental/TextEditor/extensions/color/color-styles.css +0 -25
  150. package/experimental/TextEditor/extensions/color/index.ts +0 -2
  151. package/experimental/TextEditor/extensions/content-paste-extension.ts +0 -160
  152. package/experimental/TextEditor/extensions/copy-styles.ts +0 -160
  153. package/experimental/TextEditor/extensions/emoji/EmojiList.vue +0 -55
  154. package/experimental/TextEditor/extensions/emoji/emoji-extension.ts +0 -55
  155. package/experimental/TextEditor/extensions/emoji/emojis.json +0 -7422
  156. package/experimental/TextEditor/extensions/heading/heading.ts +0 -20
  157. package/experimental/TextEditor/extensions/highlight/highlight-extension.ts +0 -241
  158. package/experimental/TextEditor/extensions/highlight/highlight-styles.css +0 -31
  159. package/experimental/TextEditor/extensions/highlight/index.ts +0 -2
  160. package/experimental/TextEditor/extensions/iframe/IframeNodeView.vue +0 -308
  161. package/experimental/TextEditor/extensions/iframe/InsertIframe.vue +0 -209
  162. package/experimental/TextEditor/extensions/iframe/iframe-extension.ts +0 -404
  163. package/experimental/TextEditor/extensions/iframe/index.ts +0 -11
  164. package/experimental/TextEditor/extensions/iframe/utils.ts +0 -283
  165. package/experimental/TextEditor/extensions/image/image-extension.ts +0 -661
  166. package/experimental/TextEditor/extensions/image/index.ts +0 -5
  167. package/experimental/TextEditor/extensions/image-group/ImageGroupNodeView.vue +0 -182
  168. package/experimental/TextEditor/extensions/image-group/ImageGroupUploadDialog.vue +0 -740
  169. package/experimental/TextEditor/extensions/image-group/image-group-extension.ts +0 -187
  170. package/experimental/TextEditor/extensions/image-viewer-extension.ts +0 -162
  171. package/experimental/TextEditor/extensions/link/index.ts +0 -1
  172. package/experimental/TextEditor/extensions/link/link-extension.ts +0 -323
  173. package/experimental/TextEditor/extensions/link/linkPasteHandler.ts +0 -51
  174. package/experimental/TextEditor/extensions/mention/index.ts +0 -1
  175. package/experimental/TextEditor/extensions/mention/mention-extension.ts +0 -204
  176. package/experimental/TextEditor/extensions/mention/style.css +0 -11
  177. package/experimental/TextEditor/extensions/shared/color-utils.ts +0 -236
  178. package/experimental/TextEditor/extensions/slash-commands/SlashCommandsList.vue +0 -59
  179. package/experimental/TextEditor/extensions/slash-commands/slash-commands-extension.ts +0 -184
  180. package/experimental/TextEditor/extensions/suggestion/SuggestionList.vue +0 -130
  181. package/experimental/TextEditor/extensions/suggestion/createSuggestionExtension.ts +0 -151
  182. package/experimental/TextEditor/extensions/suggestion/index.ts +0 -5
  183. package/experimental/TextEditor/extensions/tag/index.ts +0 -1
  184. package/experimental/TextEditor/extensions/tag/tag-extension.ts +0 -170
  185. package/experimental/TextEditor/extensions/toc-node/TocNodeView.vue +0 -439
  186. package/experimental/TextEditor/extensions/toc-node/index.ts +0 -3
  187. package/experimental/TextEditor/extensions/toc-node/toc-node-extension.ts +0 -167
  188. package/experimental/TextEditor/extensions/video-extension.ts +0 -653
  189. package/experimental/TextEditor/hljs-github.css +0 -197
  190. package/experimental/TextEditor/index.ts +0 -21
  191. package/experimental/TextEditor/style.css +0 -190
  192. package/experimental/TextEditor/types.ts +0 -72
  193. package/experimental/TextEditor/utils.js +0 -11
  194. package/src/utils/url-validation.ts +0 -39
@@ -119,7 +119,14 @@ export const triggerBaseClassesFocusWithin =
119
119
  'relative inline-flex items-center gap-2 text-left text-ink-gray-7 outline-none transition-[background-color,border-color,box-shadow] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] focus-within:focus-ring data-[state=open]:focus-ring'
120
120
 
121
121
  export const itemClasses =
122
- 'select-none rounded-4 border-0 text-base text-ink-gray-9 transition-colors duration-100 ease-out data-[disabled]:text-ink-gray-4 data-[highlighted]:bg-surface-alpha-gray-2 data-[state=checked]:bg-surface-gray-3 data-[highlighted]:data-[state=checked]:bg-surface-gray-4'
122
+ 'select-none rounded-4 border-0 text-base text-ink-gray-9 transition-colors duration-100 ease-out data-[disabled]:text-ink-gray-4 data-[highlighted]:bg-surface-alpha-gray-2'
123
+
124
+ /**
125
+ * Fill for the picked row of a single-pick list. A multi-pick list leaves it
126
+ * off: its checkbox already shows the state, and most of its rows are checked.
127
+ */
128
+ export const checkedItemClasses =
129
+ 'data-[state=checked]:bg-surface-gray-3 data-[highlighted]:data-[state=checked]:bg-surface-gray-4'
123
130
 
124
131
  /**
125
132
  * Case-insensitive substring match against an option's label and value.
@@ -4,7 +4,7 @@ import {
4
4
  currentDispatchSeq,
5
5
  FrappeResponseError,
6
6
  getDispatchStamp,
7
- getRequestDispatchSeq,
7
+ trackNewestRequest,
8
8
  useFrappeFetch,
9
9
  } from '../useFrappeFetch'
10
10
  import { LOCAL_WRITE, type WriteStamp } from '../writeGate'
@@ -90,24 +90,18 @@ export function useCall<TResponse, TParams extends BasicParams = undefined>(
90
90
 
91
91
  type FrappeResponse<T> = { data: T }
92
92
 
93
- // The dispatch number of the newest request this call has sent, whoever
94
- // sent it: this call's `execute`, or `useFetch`'s parameter watcher under
95
- // `refetch: true`. `submit` compares it with the number it read before it
96
- // waited. The number itself is minted in `useFrappeFetch`, at the top of
97
- // `execute`; counting here instead would be a tick late, because
93
+ // `submit` compares the newest request's number with the number it read
94
+ // before it waited. The number itself is minted in `useFrappeFetch`, at the
95
+ // top of `execute`; counting here instead would be a tick late, because
98
96
  // `createFetch` chains a per-call `beforeFetch` after the factory's, and a
99
97
  // submit in the same tick would have taken its reading by then.
100
- let lastDispatch = 0
98
+ // `error` is destructured below, after `fetchOptions` is built.
99
+ const requests = trackNewestRequest(() => error.value)
101
100
 
102
101
  const fetchOptions: UseFetchOptions = {
103
102
  immediate,
104
103
  refetch,
105
- beforeFetch({ options }) {
106
- const seq = getRequestDispatchSeq(options)
107
- if (seq !== undefined && seq > lastDispatch) {
108
- lastDispatch = seq
109
- }
110
- },
104
+ beforeFetch: requests.beforeFetch,
111
105
  // `data` is read back out as `data.value?.data` below (the raw fetch
112
106
  // response is `{ data: TResponse }`), so the seed value has to be
113
107
  // wrapped the same way — an unwrapped `initialData` would read as
@@ -161,7 +155,7 @@ export function useCall<TResponse, TParams extends BasicParams = undefined>(
161
155
  }
162
156
  return ctx
163
157
  },
164
- onFetchError(ctx) {
158
+ onFetchError: requests.onFetchError((ctx) => {
165
159
  if (onError) {
166
160
  try {
167
161
  onError(ctx.error)
@@ -170,7 +164,7 @@ export function useCall<TResponse, TParams extends BasicParams = undefined>(
170
164
  }
171
165
  }
172
166
  return ctx
173
- },
167
+ }),
174
168
  }
175
169
 
176
170
  let result
@@ -214,13 +208,6 @@ export function useCall<TResponse, TParams extends BasicParams = undefined>(
214
208
  }
215
209
 
216
210
  onFetchResponse(() => {
217
- // This response succeeded, so the call is not in error. `execute` clears
218
- // `error` when it starts, but a request this one superseded rejects with
219
- // its abort *after* that, and nothing put the ref back. Two overlapping
220
- // submits ended with the newer one rejecting on the older one's abort.
221
- // `data` is already overwritten by whichever response settled last; the
222
- // error half has to follow the same rule.
223
- error.value = null
224
211
  resolve()
225
212
  promise.value = makePromise()
226
213
  })
@@ -274,19 +261,31 @@ export function useCall<TResponse, TParams extends BasicParams = undefined>(
274
261
  const sentBefore = currentDispatchSeq()
275
262
  await nextTick()
276
263
  await whenSettled()
277
- if (lastDispatch > sentBefore) {
264
+ if (requests.newest() > sentBefore) {
278
265
  if (error.value) throw error.value
279
266
  return data.value?.data ?? null
280
267
  }
281
268
  // Nothing went out with these params. Fall through and send it here,
282
269
  // the same way a submit without `refetch` does.
283
270
  }
284
- const response = await execute()
285
271
  // Actions reject, reads resolve. `submit()` writes, so a caller that
286
272
  // does not handle failure must not run its success path (DAT-Q1).
287
273
  // `execute`/`fetch`/`reload` keep resolving; read `error` after them.
288
- if (error.value) throw error.value
289
- return response
274
+ // `_execute(true)` rethrows this request's own failure. That includes the
275
+ // abort of a request a newer one replaced: the abort stays out of
276
+ // `error`, but this submit did not land, so it rejects with the abort.
277
+ // Any other failure rejects with `error.value`, not the raw error:
278
+ // the factory's `onFetchError` in `useFrappeFetch` turns a server failure
279
+ // into a `FrappeResponseError` and stores that in `error`, while
280
+ // `_execute(true)` rethrows the raw error.
281
+ const sending = _execute(true)
282
+ const seq = currentDispatchSeq()
283
+ try {
284
+ await sending
285
+ } catch (e) {
286
+ throw requests.newest() > seq ? e : error.value
287
+ }
288
+ return data.value?.data ?? null
290
289
  }
291
290
 
292
291
  const reset = () => {
@@ -1,4 +1,8 @@
1
- import { createFetch } from '@vueuse/core'
1
+ import {
2
+ createFetch,
3
+ type BeforeFetchContext,
4
+ type UseFetchOptions,
5
+ } from '@vueuse/core'
2
6
  import { docStore } from './docStore'
3
7
  import { listStore } from './useList/listStore'
4
8
  import { LOCAL_WRITE, writeGate, type DispatchStamp } from './writeGate'
@@ -64,10 +68,52 @@ export function currentDispatchSeq(): number {
64
68
  * `options` object per `execute` and every hook in the chain is handed that
65
69
  * same object, so it names the request.
66
70
  */
67
- export function getRequestDispatchSeq(options: object): number | undefined {
71
+ function getRequestDispatchSeq(options: object): number | undefined {
68
72
  return requestSeqs.get(options)
69
73
  }
70
74
 
75
+ /**
76
+ * Tracks the newest request one `useFetch` instance has sent, whoever sent
77
+ * it: the instance's `execute`, or `useFetch`'s parameter watcher under
78
+ * `refetch: true`. `useFetch` aborts the request in flight when it sends a
79
+ * new one, so a request older than the newest was replaced. Its abort is not
80
+ * an error of the instance.
81
+ *
82
+ * Pass `beforeFetch` as the per-call `beforeFetch`. `createFetch` chains it
83
+ * after the factory's, which has already numbered the request.
84
+ *
85
+ * Wrap the per-call `onFetchError` in `onFetchError`. This is the one place a
86
+ * replaced request's abort is handled: it stops here and leaves the
87
+ * instance's `error` as it is (read through `getError`). Every other failure
88
+ * goes on to the wrapped handler.
89
+ */
90
+ export function trackNewestRequest(getError: () => unknown) {
91
+ let newest = 0
92
+ return {
93
+ beforeFetch({ options }: BeforeFetchContext) {
94
+ const seq = getRequestDispatchSeq(options)
95
+ if (seq !== undefined && seq > newest) {
96
+ newest = seq
97
+ }
98
+ },
99
+ /** The dispatch number of the newest request sent so far. */
100
+ newest: () => newest,
101
+ onFetchError(handler: FetchErrorHook): FetchErrorHook {
102
+ return (ctx) => {
103
+ const seq = getRequestDispatchSeq(ctx.context.options)
104
+ if (seq !== undefined && seq < newest) {
105
+ // `useFetch` writes whatever is returned here into `error`, so
106
+ // hand back the error the newer request left there.
107
+ return { ...ctx, error: getError() }
108
+ }
109
+ return handler(ctx)
110
+ }
111
+ },
112
+ }
113
+ }
114
+
115
+ type FetchErrorHook = NonNullable<UseFetchOptions['onFetchError']>
116
+
71
117
  /**
72
118
  * The stamp put on a Response by the wrapped fetch below. The single source
73
119
  * for both halves of the write-gate rule: the dispatch version and whether
@@ -13,7 +13,11 @@ import {
13
13
  OnFetchErrorContext,
14
14
  UseFetchOptions,
15
15
  } from '@vueuse/core'
16
- import { FrappeResponseError, useFrappeFetch } from '../useFrappeFetch'
16
+ import {
17
+ FrappeResponseError,
18
+ trackNewestRequest,
19
+ useFrappeFetch,
20
+ } from '../useFrappeFetch'
17
21
  import { useAction } from '../useAction'
18
22
  import { parseFilters, makeGetParams, normalizeCacheKey } from '../utils'
19
23
  import { UseListOptions, UseListResponse } from './types'
@@ -114,9 +118,13 @@ export function useList<T extends { name: string }>(
114
118
  return transform ? applyTransform(structuredClone(rows), transform) : rows
115
119
  }
116
120
 
121
+ // `error` is destructured below, after `fetchOptions` is built.
122
+ const requests = trackNewestRequest(() => error.value)
123
+
117
124
  const fetchOptions: UseFetchOptions = {
118
125
  immediate,
119
126
  refetch,
127
+ beforeFetch: requests.beforeFetch,
120
128
  initialData: initialData || null,
121
129
  afterFetch: handleAfterFetch<T>({
122
130
  ...options,
@@ -129,7 +137,7 @@ export function useList<T extends { name: string }>(
129
137
  _limit,
130
138
  hasNextPage,
131
139
  }),
132
- onFetchError: handleFetchError<T>(options),
140
+ onFetchError: requests.onFetchError(handleFetchError<T>(options)),
133
141
  }
134
142
 
135
143
  const {
@@ -412,5 +420,5 @@ function handleFetchError<T>({ onError }: UseListOptions<T>) {
412
420
  }
413
421
  }
414
422
  return ctx
415
- } as UseFetchOptions['onFetchError']
423
+ }
416
424
  }
@@ -6,12 +6,26 @@ export function makeGetParams(params: Record<string, any>) {
6
6
  for (let key in params) {
7
7
  let value = params[key]
8
8
  if (value != null && !isEmptyObject(value)) {
9
- url.append(key, value)
9
+ // A query string holds only strings, and `append` would turn an object
10
+ // into `[object Object]` and an array into `a,b`. Frappe reads a
11
+ // structured GET arg (`filters`, `fields`) as JSON, so send a plain
12
+ // object or an array as JSON. Anything else, such as a Date, goes as is.
13
+ url.append(
14
+ key,
15
+ isPlainObjectOrArray(value) ? JSON.stringify(value) : value,
16
+ )
10
17
  }
11
18
  }
12
19
  return url.toString()
13
20
  }
14
21
 
22
+ function isPlainObjectOrArray(value: unknown) {
23
+ if (Array.isArray(value)) return true
24
+ if (typeof value !== 'object' || value === null) return false
25
+ const proto = Object.getPrototypeOf(value)
26
+ return proto === Object.prototype || proto === null
27
+ }
28
+
15
29
  export function isEmptyObject(obj: any) {
16
30
  return Object.keys(obj).length === 0 && obj.constructor === Object
17
31
  }
@@ -17,6 +17,7 @@ import {
17
17
  import { safeGetPos } from '#molecules/editor/extensions/shared/node-view'
18
18
  import MediaToolbar from './MediaToolbar.vue'
19
19
  import MediaResizeHandle from './MediaResizeHandle.vue'
20
+ import MediaResizeGuide from './MediaResizeGuide.vue'
20
21
  import VideoControls from './VideoControls.vue'
21
22
  import UploadProgressIndicator from './UploadProgressIndicator.vue'
22
23
  import {
@@ -158,10 +159,11 @@ watch(nodeKey, () => {
158
159
  isFreshInsert.value = Boolean(props.node.attrs.uploadId)
159
160
  })
160
161
 
161
- const { isResizing, startResize } = useNodeViewResize(editor, {
162
+ const { isResizing, guide, startResize } = useNodeViewResize(editor, {
162
163
  mediaEl: () => mediaRef.value,
163
164
  containerEl: () => containerRef.value,
164
165
  getAspectRatio: () => mediaIntrinsicAspect(),
166
+ getNaturalWidth: () => mediaNaturalWidth(),
165
167
  getPos: () => props.getPos(),
166
168
  onCommit: ({ width, height }) => props.updateAttributes({ width, height }),
167
169
  })
@@ -185,6 +187,12 @@ function mediaIntrinsicAspect(): number {
185
187
  return heightOverWidth(width, height)
186
188
  }
187
189
 
190
+ function mediaNaturalWidth(): number {
191
+ const el = mediaRef.value
192
+ if (!el) return 0
193
+ return el instanceof HTMLVideoElement ? el.videoWidth : el.naturalWidth
194
+ }
195
+
188
196
  function selectMedia() {
189
197
  selectMediaCmd(editor, () => props.getPos())
190
198
  }
@@ -403,6 +411,7 @@ function setVideoOptions(options: {
403
411
  @resize-start="startResizeFromHandle"
404
412
  @resize-keydown="onResizeKeydown"
405
413
  />
414
+ <MediaResizeGuide :guide="() => guide" />
406
415
 
407
416
  <!-- Upload error over the staged preview: same overlay pattern as the
408
417
  gallery grid cell, kept inside the media box. -->
@@ -0,0 +1,71 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Live feedback for a media resize drag. A pill names the width — the snap it
4
+ * holds ("50%", "Original size") or the free width in px. While a snap holds, a
5
+ * line runs through the dragged edge from the top of the editor to the bottom,
6
+ * so it shows what the media lines up with.
7
+ */
8
+ import { computed, ref, useTemplateRef, watch } from 'vue'
9
+ import { usePortalTarget } from '#composables/usePortalTarget'
10
+ import type { ResizeGuide } from '#molecules/editor/composables/useNodeViewResize'
11
+ import { MEDIA_CORNER_GRIP_INSET } from './media-node-view-utils'
12
+
13
+ const props = defineProps<{
14
+ /**
15
+ * A getter, so only this overlay re-renders on every pointer move. If the
16
+ * node view read the guide itself, each re-render would rewrite its
17
+ * container's bound width over the drag's inline width.
18
+ */
19
+ guide: () => ResizeGuide | null
20
+ }>()
21
+
22
+ const current = computed(() => props.guide())
23
+ const label = computed(() => {
24
+ const guide = current.value
25
+ if (!guide) return null
26
+ return guide.snap?.label ?? `${Math.round(guide.width)}px`
27
+ })
28
+
29
+ // Measured after each render that changes the text: the media clips its
30
+ // overflow, so a pill too wide for a small image would read "riginal siz" or
31
+ // sit on the grip.
32
+ // Hidden with `invisible` rather than `v-if` so it keeps a width to measure.
33
+ const labelEl = useTemplateRef<HTMLElement>('labelEl')
34
+ const labelWidth = ref(0)
35
+ watch(
36
+ [labelEl, label],
37
+ () => {
38
+ if (labelEl.value) labelWidth.value = labelEl.value.offsetWidth
39
+ },
40
+ { flush: 'post' },
41
+ )
42
+ const labelFits = computed(
43
+ () =>
44
+ !!current.value &&
45
+ labelWidth.value <= current.value.width - MEDIA_CORNER_GRIP_INSET * 2,
46
+ )
47
+
48
+ const portalTarget = usePortalTarget()
49
+ </script>
50
+
51
+ <template>
52
+ <template v-if="current">
53
+ <Teleport v-if="current.snap" :to="portalTarget ?? 'body'">
54
+ <div
55
+ class="pointer-events-none fixed z-50 w-px -translate-x-1/2 bg-surface-gray-7"
56
+ :style="{
57
+ left: `${current.snap.line.x}px`,
58
+ top: `${current.snap.line.top}px`,
59
+ height: `${current.snap.line.height}px`,
60
+ }"
61
+ />
62
+ </Teleport>
63
+ <div
64
+ ref="labelEl"
65
+ class="pointer-events-none absolute bottom-2.5 left-1/2 z-30 -translate-x-1/2 whitespace-nowrap rounded-4 bg-black-overlay-600 px-1.5 py-0.5 text-xs tabular-nums text-white"
66
+ :class="{ invisible: !labelFits }"
67
+ >
68
+ {{ label }}
69
+ </div>
70
+ </template>
71
+ </template>
@@ -20,6 +20,13 @@ export type MediaAlign = 'left' | 'center' | 'right'
20
20
  export const MEDIA_CHROME_BUTTON =
21
21
  'flex size-7 items-center justify-center rounded-4 bg-black-overlay-300 text-white transition-colors hover:bg-black-overlay-400 active:bg-black-overlay-500 data-[state=open]:bg-black-overlay-500'
22
22
 
23
+ /**
24
+ * Room a label centred along the media's bottom edge leaves on each side for
25
+ * the corner resize grip: its `right-2.5` inset (`MediaResizeHandle.vue`) plus
26
+ * the `size-7` above (38px), and a 4px gap so the two never touch.
27
+ */
28
+ export const MEDIA_CORNER_GRIP_INSET = 42
29
+
23
30
  /**
24
31
  * The selection ring around a media, embed, or gallery node.
25
32
  *
@@ -12,18 +12,31 @@
12
12
  * `mousemove` / `mouseup` listeners on `window` plus the matching body cursor.
13
13
  * - `mousemove` applies temporary inline `width`/`height` to the element for
14
14
  * live visual feedback, clamping width between `minWidth` and the editor's
15
- * content width (minus `maxWidthPadding`).
15
+ * width (minus `maxWidthPadding`).
16
16
  * - `mouseup` reads the final rendered size, clears the temporary inline styles,
17
17
  * and commits via `onCommit` — guarded by `safeGetPos` so a stale node view
18
18
  * never writes back into the document.
19
19
  *
20
20
  * Window listeners are removed on stop AND on `onUnmounted`, fixing the leak
21
21
  * where a drag interrupted by unmount left handlers attached to `window`.
22
+ *
23
+ * The drag snaps to a few widths when it comes within `SNAP_DISTANCE` of one:
24
+ * fractions of the editor's content width, the media's own natural width, and the width
25
+ * of any other media in the document, so images in a post can line up. Holding
26
+ * Alt resizes freely. `guide` describes the live drag for the node view to draw.
22
27
  */
23
- import { ref, onUnmounted, type Ref } from 'vue'
28
+ import { computed, ref, onUnmounted, type Ref } from 'vue'
24
29
  import type { Editor } from '@tiptap/core'
25
30
  import { safeGetPos } from '#molecules/editor/extensions/shared/node-view'
26
31
 
32
+ const SNAP_DISTANCE = 8
33
+
34
+ const MATCHED_NODE_LABELS: Record<string, string> = {
35
+ image: 'Same as image',
36
+ video: 'Same as video',
37
+ iframe: 'Same as embed',
38
+ }
39
+
27
40
  export interface ResizeArgs {
28
41
  /** The element being resized (image / video / iframe). May be null pre-mount. */
29
42
  mediaEl: () => HTMLElement | null
@@ -58,6 +71,8 @@ export interface ResizeArgs {
58
71
  * re-writes a style property when its bound VALUE changes).
59
72
  */
60
73
  mediaSizing?: 'attribute' | 'style'
74
+ /** The media's own width in px (e.g. `naturalWidth`), offered as a snap. */
75
+ getNaturalWidth?: () => number
61
76
  /** Minimum width in px. Default 50 (matches the image node view). */
62
77
  minWidth?: number
63
78
  /** Reserved px subtracted from the editor width as the max. Default 0. */
@@ -67,14 +82,35 @@ export interface ResizeArgs {
67
82
  /** Which handle started the drag; each one has its own delta math. */
68
83
  export type ResizeEdge = 'left' | 'right' | 'corner'
69
84
 
85
+ /** A width the drag snaps to, and the name shown while it holds. */
86
+ export interface SnapTarget {
87
+ width: number
88
+ label: string
89
+ }
90
+
91
+ /** A vertical line through the dragged edge spanning the editor, in viewport px. */
92
+ export interface SnapLine {
93
+ x: number
94
+ top: number
95
+ height: number
96
+ }
97
+
98
+ /** The live drag: its width, and the snap it holds (if any) with its line. */
99
+ export interface ResizeGuide {
100
+ width: number
101
+ snap: (SnapTarget & { line: SnapLine }) | null
102
+ }
103
+
70
104
  export function useNodeViewResize(
71
105
  editor: Editor,
72
106
  args: ResizeArgs,
73
107
  ): {
74
- isResizing: Ref<boolean>
108
+ isResizing: Readonly<Ref<boolean>>
109
+ guide: Ref<ResizeGuide | null>
75
110
  startResize: (event: PointerEvent | MouseEvent, edge?: ResizeEdge) => void
76
111
  } {
77
- const isResizing = ref(false)
112
+ const guide = ref<ResizeGuide | null>(null)
113
+ const isResizing = computed(() => guide.value !== null)
78
114
  const minWidth = args.minWidth ?? 50
79
115
  const maxWidthPadding = args.maxWidthPadding ?? 0
80
116
 
@@ -83,6 +119,8 @@ export function useNodeViewResize(
83
119
  let startWidth = 0
84
120
  let aspectRatio = 1
85
121
  let dragFrom: ResizeEdge = 'corner'
122
+ let snapTargets: SnapTarget[] = []
123
+ let lastPointerEvent: PointerEvent | null = null
86
124
 
87
125
  function startResize(
88
126
  event: PointerEvent | MouseEvent,
@@ -92,7 +130,6 @@ export function useNodeViewResize(
92
130
  const el = args.mediaEl()
93
131
  if (!el) return
94
132
 
95
- isResizing.value = true
96
133
  startDragX = event.clientX
97
134
  startDragY = event.clientY
98
135
  startWidth = el.offsetWidth
@@ -105,10 +142,16 @@ export function useNodeViewResize(
105
142
  const renderedAspect = el.offsetWidth ? el.offsetHeight / el.offsetWidth : 0
106
143
  aspectRatio = renderedAspect || args.getAspectRatio() || 1
107
144
  dragFrom = edge
145
+ snapTargets = getSnapTargets()
146
+ guide.value = { width: startWidth, snap: null }
108
147
 
109
148
  window.addEventListener('pointermove', handleResize)
110
149
  window.addEventListener('pointerup', stopResize)
111
150
  window.addEventListener('pointercancel', stopResize)
151
+ // Capture catches scrolling containers too, which a fixed snap line has to
152
+ // follow even while the pointer is held still.
153
+ window.addEventListener('scroll', refreshGuide, true)
154
+ window.addEventListener('resize', refreshSnapTargets)
112
155
  document.body.style.cursor = edge === 'corner' ? 'nwse-resize' : 'ew-resize'
113
156
  }
114
157
 
@@ -116,8 +159,8 @@ export function useNodeViewResize(
116
159
  if (!isResizing.value) return
117
160
  const el = args.mediaEl()
118
161
  if (!el) return
162
+ lastPointerEvent = event
119
163
 
120
- const editorWidth = editor.view.dom.clientWidth
121
164
  const deltaX = event.clientX - startDragX
122
165
  const deltaY = event.clientY - startDragY
123
166
  // A corner can only travel along the line (1, aspectRatio) — the ratio is
@@ -141,10 +184,12 @@ export function useNodeViewResize(
141
184
  dragFrom === 'corner'
142
185
  ? (deltaX + deltaY * aspectRatio) / (1 + aspectRatio * aspectRatio)
143
186
  : deltaX * (dragFrom === 'left' ? -1 : 1)
144
- const newWidth = Math.max(
187
+ const freeWidth = Math.max(
145
188
  minWidth,
146
- Math.min(startWidth + deltaWidth, editorWidth - maxWidthPadding),
189
+ Math.min(startWidth + deltaWidth, getMaxDragWidth()),
147
190
  )
191
+ const snap = event.altKey ? null : findSnap(freeWidth)
192
+ const newWidth = snap?.width ?? freeWidth
148
193
  const newHeight = newWidth * aspectRatio
149
194
 
150
195
  el.style.width = `${newWidth}px`
@@ -153,11 +198,36 @@ export function useNodeViewResize(
153
198
  // Grow the clipping wrapper in lockstep so the live drag isn't clipped.
154
199
  const container = args.containerEl?.()
155
200
  if (container) container.style.width = `${newWidth}px`
201
+
202
+ guide.value = {
203
+ width: newWidth,
204
+ snap: snap ? { ...snap, line: getSnapLine(el) } : null,
205
+ }
206
+ }
207
+
208
+ function refreshGuide(): void {
209
+ if (lastPointerEvent) handleResize(lastPointerEvent)
210
+ }
211
+
212
+ function refreshSnapTargets(): void {
213
+ snapTargets = getSnapTargets()
214
+ refreshGuide()
215
+ }
216
+
217
+ function getSnapLine(el: HTMLElement): SnapLine {
218
+ const media = el.getBoundingClientRect()
219
+ const bounds = editor.view.dom.getBoundingClientRect()
220
+ return {
221
+ x: dragFrom === 'left' ? media.left : media.right,
222
+ top: bounds.top,
223
+ height: bounds.height,
224
+ }
156
225
  }
157
226
 
158
227
  function stopResize(): void {
159
228
  if (!isResizing.value) return
160
- isResizing.value = false
229
+ guide.value = null
230
+ lastPointerEvent = null
161
231
  removeWindowListeners()
162
232
  document.body.style.cursor = ''
163
233
 
@@ -199,6 +269,66 @@ export function useNodeViewResize(
199
269
  }
200
270
  }
201
271
 
272
+ // The drag clamp keeps the editor's padding box, as it did before snapping.
273
+ function getMaxDragWidth(): number {
274
+ return editor.view.dom.clientWidth - maxWidthPadding
275
+ }
276
+
277
+ // The base for "Full width" and its fractions: the widest the media can
278
+ // show. Media renders no wider than the content box, so a snap past it would
279
+ // save a width the media never showed. `maxWidthPadding` is a fixed stand-in
280
+ // for the editor padding, so the two never add up: the tighter limit wins.
281
+ function getFullWidth(): number {
282
+ const dom = editor.view.dom
283
+ const style = getComputedStyle(dom)
284
+ const padding =
285
+ parseFloat(style.paddingLeft) + parseFloat(style.paddingRight)
286
+ return Math.min(dom.clientWidth - padding, getMaxDragWidth())
287
+ }
288
+
289
+ function getSnapTargets(): SnapTarget[] {
290
+ const maxWidth = getFullWidth()
291
+ const targets: SnapTarget[] = [
292
+ { width: maxWidth, label: 'Full width' },
293
+ { width: Math.round(maxWidth * 0.75), label: '75%' },
294
+ { width: Math.round(maxWidth * 0.5), label: '50%' },
295
+ { width: Math.round(maxWidth * 0.25), label: '25%' },
296
+ ]
297
+ const naturalWidth = args.getNaturalWidth?.()
298
+ if (naturalWidth)
299
+ targets.push({ width: naturalWidth, label: 'Original size' })
300
+
301
+ const ownPos = safeGetPos(args.getPos)
302
+ editor.state.doc.descendants((node, pos) => {
303
+ const label = MATCHED_NODE_LABELS[node.type.name]
304
+ if (!label || pos === ownPos) return
305
+ const width = Number(node.attrs.width) || getRenderedWidth(pos)
306
+ if (width) targets.push({ width, label })
307
+ })
308
+ return targets.filter((t) => t.width >= minWidth && t.width <= maxWidth)
309
+ }
310
+
311
+ // Media without a stored width (a fresh image, an embed at its default size)
312
+ // still shows at some width, which is just as useful to line up with.
313
+ function getRenderedWidth(pos: number): number {
314
+ const dom = editor.view.nodeDOM(pos)
315
+ if (!(dom instanceof HTMLElement)) return 0
316
+ return (
317
+ dom.querySelector<HTMLElement>('img, video, iframe')?.offsetWidth ?? 0
318
+ )
319
+ }
320
+
321
+ function findSnap(width: number): SnapTarget | null {
322
+ let closest: SnapTarget | null = null
323
+ for (const target of snapTargets) {
324
+ const distance = Math.abs(target.width - width)
325
+ if (distance > SNAP_DISTANCE) continue
326
+ if (!closest || distance < Math.abs(closest.width - width))
327
+ closest = target
328
+ }
329
+ return closest
330
+ }
331
+
202
332
  function onCommitGuarded(width: number, height: number): void {
203
333
  args.onCommit({ width, height })
204
334
  }
@@ -207,6 +337,8 @@ export function useNodeViewResize(
207
337
  window.removeEventListener('pointermove', handleResize)
208
338
  window.removeEventListener('pointerup', stopResize)
209
339
  window.removeEventListener('pointercancel', stopResize)
340
+ window.removeEventListener('scroll', refreshGuide, true)
341
+ window.removeEventListener('resize', refreshSnapTargets)
210
342
  }
211
343
 
212
344
  onUnmounted(() => {
@@ -214,5 +346,5 @@ export function useNodeViewResize(
214
346
  if (isResizing.value) document.body.style.cursor = ''
215
347
  })
216
348
 
217
- return { isResizing, startResize }
349
+ return { isResizing, guide, startResize }
218
350
  }
@@ -17,7 +17,7 @@
17
17
  */
18
18
  import type { Editor } from '@tiptap/core'
19
19
  import { fileSizeLimitMessage } from '#utils/fileSize'
20
- import { isSafeUrl } from '#molecules/editor/extensions/shared/url-safety'
20
+ import { isSafeUrl } from '#utils/url-safety'
21
21
  import { findNodeByUploadId } from '#molecules/editor/extensions/shared/node-view'
22
22
  import {
23
23
  applyUploadError,