@sentry/scraps 0.4.0 → 0.5.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 (285) hide show
  1. package/README.md +6 -5
  2. package/dist/alert/alert.js +0 -3
  3. package/dist/badge/badge.js +1 -2
  4. package/dist/badge/tag.js +0 -2
  5. package/dist/button/index.d.ts +0 -1
  6. package/dist/button/index.js +0 -1
  7. package/dist/clipboard/copyToClipboardButton.d.ts +15 -0
  8. package/dist/clipboard/copyToClipboardButton.js +32 -0
  9. package/dist/clipboard/index.d.ts +1 -0
  10. package/dist/clipboard/index.js +1 -0
  11. package/dist/code/index.d.ts +1 -0
  12. package/dist/code/index.js +1 -0
  13. package/dist/codeBlock/codeBlock.d.ts +68 -0
  14. package/dist/codeBlock/codeBlock.js +242 -0
  15. package/dist/codeBlock/index.d.ts +2 -0
  16. package/dist/codeBlock/index.js +2 -0
  17. package/dist/codeBlock/prism.d.ts +11 -0
  18. package/dist/codeBlock/prism.js +101 -0
  19. package/dist/codeBlock/styles.d.ts +2 -0
  20. package/dist/codeBlock/styles.js +133 -0
  21. package/dist/compactSelect/compactSelect.d.ts +21 -0
  22. package/dist/compactSelect/compactSelect.js +150 -0
  23. package/dist/compactSelect/composite.d.ts +54 -0
  24. package/dist/compactSelect/composite.js +101 -0
  25. package/dist/compactSelect/control.d.ts +112 -0
  26. package/dist/compactSelect/control.js +354 -0
  27. package/dist/compactSelect/fzf.d.ts +8 -0
  28. package/dist/compactSelect/fzf.js +151 -0
  29. package/dist/compactSelect/gridList/index.d.ts +46 -0
  30. package/dist/compactSelect/gridList/index.js +102 -0
  31. package/dist/compactSelect/gridList/option.d.ts +15 -0
  32. package/dist/compactSelect/gridList/option.js +111 -0
  33. package/dist/compactSelect/gridList/section.d.ts +15 -0
  34. package/dist/compactSelect/gridList/section.js +58 -0
  35. package/dist/compactSelect/highlightText.d.ts +6 -0
  36. package/dist/compactSelect/highlightText.js +33 -0
  37. package/dist/compactSelect/index.d.ts +9 -0
  38. package/dist/compactSelect/index.js +8 -0
  39. package/dist/compactSelect/list.d.ts +94 -0
  40. package/dist/compactSelect/list.js +167 -0
  41. package/dist/compactSelect/listBox/index.d.ts +84 -0
  42. package/dist/compactSelect/listBox/index.js +175 -0
  43. package/dist/compactSelect/listBox/option.d.ts +19 -0
  44. package/dist/compactSelect/listBox/option.js +101 -0
  45. package/dist/compactSelect/listBox/section.d.ts +21 -0
  46. package/dist/compactSelect/listBox/section.js +58 -0
  47. package/dist/compactSelect/menuComponents.d.ts +89 -0
  48. package/dist/compactSelect/menuComponents.js +117 -0
  49. package/dist/compactSelect/selectFilterContext.d.ts +2 -0
  50. package/dist/compactSelect/selectFilterContext.js +3 -0
  51. package/dist/compactSelect/styles.d.ts +39 -0
  52. package/dist/compactSelect/styles.js +155 -0
  53. package/dist/compactSelect/types.d.ts +1 -0
  54. package/dist/compactSelect/types.js +0 -0
  55. package/dist/compactSelect/useVirtualizedItems.d.ts +52 -0
  56. package/dist/compactSelect/useVirtualizedItems.js +74 -0
  57. package/dist/compactSelect/utils.d.ts +80 -0
  58. package/dist/compactSelect/utils.js +268 -0
  59. package/dist/confirm/index.d.ts +153 -0
  60. package/dist/confirm/index.js +132 -0
  61. package/dist/descriptionList/descriptionList.js +4 -3
  62. package/dist/disclosure/disclosure.js +2 -2
  63. package/dist/dragHandle/dragHandle.d.ts +3 -1
  64. package/dist/dragHandle/dragHandle.js +8 -5
  65. package/dist/drawer/components.d.ts +46 -0
  66. package/dist/drawer/components.js +265 -0
  67. package/dist/drawer/globalDrawer.d.ts +106 -0
  68. package/dist/drawer/globalDrawer.js +173 -0
  69. package/dist/drawer/index.d.ts +3 -0
  70. package/dist/drawer/index.js +2 -0
  71. package/dist/drawer/useDrawerResizing.d.ts +19 -0
  72. package/dist/drawer/useDrawerResizing.js +111 -0
  73. package/dist/drawer/useDrawerWidth.d.ts +1 -0
  74. package/dist/drawer/useDrawerWidth.js +42 -0
  75. package/dist/dropdownMenu/content.d.ts +1 -0
  76. package/dist/dropdownMenu/content.js +1 -0
  77. package/dist/dropdownMenu/context.d.ts +24 -0
  78. package/dist/dropdownMenu/context.js +3 -0
  79. package/dist/dropdownMenu/dropdownMenu.d.ts +70 -0
  80. package/dist/dropdownMenu/dropdownMenu.js +103 -0
  81. package/dist/dropdownMenu/index.d.ts +2 -0
  82. package/dist/dropdownMenu/index.js +1 -0
  83. package/dist/dropdownMenu/item.d.ts +136 -0
  84. package/dist/dropdownMenu/item.js +182 -0
  85. package/dist/dropdownMenu/list.d.ts +59 -0
  86. package/dist/dropdownMenu/list.js +410 -0
  87. package/dist/dropdownMenu/search.d.ts +16 -0
  88. package/dist/dropdownMenu/search.js +16 -0
  89. package/dist/dropdownMenu/section.d.ts +21 -0
  90. package/dist/dropdownMenu/section.js +40 -0
  91. package/dist/dropdownMenu/separator.d.ts +7 -0
  92. package/dist/dropdownMenu/separator.js +15 -0
  93. package/dist/dropdownMenu/useDropdownMenuKeyboard.d.ts +260 -0
  94. package/dist/dropdownMenu/useDropdownMenuKeyboard.js +55 -0
  95. package/dist/dropdownMenu/useDropdownMenuRowLayout.d.ts +29 -0
  96. package/dist/dropdownMenu/useDropdownMenuRowLayout.js +64 -0
  97. package/dist/dropdownMenu/useSafetyTriangle.d.ts +12 -0
  98. package/dist/dropdownMenu/useSafetyTriangle.js +119 -0
  99. package/dist/dropdownMenu/utils.d.ts +21 -0
  100. package/dist/dropdownMenu/utils.js +57 -0
  101. package/dist/form/FormSearch.d.ts +19 -0
  102. package/dist/form/FormSearch.js +4 -0
  103. package/dist/form/autoSaveForm.d.ts +110 -0
  104. package/dist/form/autoSaveForm.js +100 -0
  105. package/dist/{formPresentation → form}/displayField.js +2 -2
  106. package/dist/form/field/baseField.d.ts +23 -0
  107. package/dist/form/field/baseField.js +116 -0
  108. package/dist/form/field/checkboxField.d.ts +11 -0
  109. package/dist/form/field/checkboxField.js +42 -0
  110. package/dist/form/field/checkboxGroupField.d.ts +16 -0
  111. package/dist/form/field/checkboxGroupField.js +80 -0
  112. package/dist/form/field/compactSelectField.d.ts +19 -0
  113. package/dist/form/field/compactSelectField.js +77 -0
  114. package/dist/{formPresentation → form/field}/fieldIds.js +1 -1
  115. package/dist/form/field/inputField.d.ts +19 -0
  116. package/dist/form/field/inputField.js +31 -0
  117. package/dist/{formPresentation → form/field}/meta.js +6 -6
  118. package/dist/form/field/numberField.d.ts +5 -0
  119. package/dist/form/field/numberField.js +11 -0
  120. package/dist/form/field/passwordField.d.ts +3 -0
  121. package/dist/form/field/passwordField.js +27 -0
  122. package/dist/form/field/radioGroupField.d.ts +16 -0
  123. package/dist/form/field/radioGroupField.js +92 -0
  124. package/dist/form/field/rangeField.d.ts +8 -0
  125. package/dist/form/field/rangeField.js +34 -0
  126. package/dist/form/field/selectAsyncField.d.ts +31 -0
  127. package/dist/form/field/selectAsyncField.js +22 -0
  128. package/dist/form/field/selectField.d.ts +9 -0
  129. package/dist/form/field/selectField.js +72 -0
  130. package/dist/form/field/switchField.d.ts +7 -0
  131. package/dist/form/field/switchField.js +37 -0
  132. package/dist/form/field/textAreaField.d.ts +7 -0
  133. package/dist/form/field/textAreaField.js +25 -0
  134. package/dist/{formPresentation → form}/formContext.js +1 -1
  135. package/dist/form/formErrorContext/index.d.ts +9 -0
  136. package/dist/form/formErrorContext/index.js +7 -0
  137. package/dist/form/index.d.ts +9 -0
  138. package/dist/form/index.js +8 -0
  139. package/dist/{formPresentation → form/layout}/base.d.ts +1 -1
  140. package/dist/{formPresentation → form/layout}/base.js +1 -1
  141. package/dist/form/layout/fieldGroup.d.ts +6 -0
  142. package/dist/form/layout/fieldGroup.js +60 -0
  143. package/dist/{formPresentation/fieldLayout.d.ts → form/layout/index.d.ts} +1 -1
  144. package/dist/{formPresentation/fieldLayout.js → form/layout/index.js} +3 -3
  145. package/dist/{formPresentation → form/layout}/useStackedLayout.js +1 -1
  146. package/dist/form/scrapsForm.d.ts +220 -0
  147. package/dist/form/scrapsForm.js +126 -0
  148. package/dist/hotkey/hotkey.d.ts +9 -8
  149. package/dist/hotkey/hotkey.js +13 -6
  150. package/dist/hotkey/index.d.ts +2 -1
  151. package/dist/hotkey/index.js +2 -1
  152. package/dist/hotkey/keyMappings.d.ts +1 -15
  153. package/dist/hotkey/keyMappings.js +29 -174
  154. package/dist/hotkey/useHotkeys.d.ts +3 -47
  155. package/dist/hotkey/useHotkeys.js +8 -42
  156. package/dist/image/image.js +2 -1
  157. package/dist/info/infoTip.d.ts +1 -1
  158. package/dist/info/infoTip.js +4 -3
  159. package/dist/input/index.d.ts +0 -3
  160. package/dist/input/index.js +0 -2
  161. package/dist/input/input.d.ts +2 -0
  162. package/dist/input/input.js +2 -0
  163. package/dist/input/passwordManagerIgnoreProps.d.ts +11 -0
  164. package/dist/input/passwordManagerIgnoreProps.js +8 -0
  165. package/dist/layout/index.d.ts +2 -2
  166. package/dist/layout/index.js +1 -1
  167. package/dist/link/link.js +4 -3
  168. package/dist/link/linkBehaviorContext.d.ts +2 -0
  169. package/dist/link/linkBehaviorContext.js +17 -10
  170. package/dist/menu/index.d.ts +1 -1
  171. package/dist/menu/index.js +1 -1
  172. package/dist/menu/menu.d.ts +14 -6
  173. package/dist/menu/menu.js +160 -56
  174. package/dist/modal/components.d.ts +19 -0
  175. package/dist/modal/components.js +99 -0
  176. package/dist/modal/errorBoundary.d.ts +2 -0
  177. package/dist/modal/errorBoundary.js +35 -0
  178. package/dist/modal/index.d.ts +33 -0
  179. package/dist/modal/index.js +260 -0
  180. package/dist/modal/portal.d.ts +1 -0
  181. package/dist/modal/portal.js +10 -0
  182. package/dist/modal/state.d.ts +17 -0
  183. package/dist/modal/state.js +41 -0
  184. package/dist/modal/types.d.ts +75 -0
  185. package/dist/modal/types.js +0 -0
  186. package/dist/numberInput/index.d.ts +3 -0
  187. package/dist/numberInput/index.js +2 -0
  188. package/dist/{input → numberInput}/numberDragInput.d.ts +1 -1
  189. package/dist/{input → numberInput}/numberDragInput.js +1 -1
  190. package/dist/{input → numberInput}/numberInput.d.ts +1 -1
  191. package/dist/{input → numberInput}/numberInput.js +1 -1
  192. package/dist/overlayContext.d.ts +29 -0
  193. package/dist/overlayContext.js +7 -0
  194. package/dist/pagination/index.d.ts +1 -0
  195. package/dist/pagination/index.js +1 -0
  196. package/dist/pagination/pagination.d.ts +24 -0
  197. package/dist/pagination/pagination.js +63 -0
  198. package/dist/pictureInPicture/index.d.ts +2 -0
  199. package/dist/pictureInPicture/index.js +2 -0
  200. package/dist/pictureInPicture/pictureInPicture.d.ts +47 -0
  201. package/dist/pictureInPicture/pictureInPicture.js +100 -0
  202. package/dist/pictureInPicture/pictureInPicturePortal.d.ts +16 -0
  203. package/dist/pictureInPicture/pictureInPicturePortal.js +46 -0
  204. package/dist/pictureInPicture/portalContext.d.ts +2 -0
  205. package/dist/pictureInPicture/portalContext.js +3 -0
  206. package/dist/revealOnHover/revealOnHover.js +1 -1
  207. package/dist/segmentedControl/segmentedControl.js +1 -1
  208. package/dist/select/filter.d.ts +4 -0
  209. package/dist/select/filter.js +12 -0
  210. package/dist/select/index.d.ts +3 -0
  211. package/dist/select/index.js +2 -0
  212. package/dist/select/option.d.ts +16 -0
  213. package/dist/select/option.js +81 -0
  214. package/dist/select/reactSelectWrapper.d.ts +8 -0
  215. package/dist/select/reactSelectWrapper.js +25 -0
  216. package/dist/select/select.d.ts +79 -0
  217. package/dist/select/select.js +454 -0
  218. package/dist/select/styles.d.ts +9 -0
  219. package/dist/select/styles.js +27 -0
  220. package/dist/select/types.d.ts +60 -0
  221. package/dist/select/types.js +0 -0
  222. package/dist/select/virtualizedMenuList.d.ts +24 -0
  223. package/dist/select/virtualizedMenuList.js +123 -0
  224. package/dist/slideOverPanel.d.ts +20 -0
  225. package/dist/slideOverPanel.js +141 -0
  226. package/dist/splitPanel/splitPanel.d.ts +3 -1
  227. package/dist/splitPanel/splitPanel.js +2 -1
  228. package/dist/table/table.d.ts +1 -1
  229. package/dist/table/table.js +39 -20
  230. package/dist/table/useColumnResize.d.ts +6 -5
  231. package/dist/table/useColumnResize.js +5 -4
  232. package/dist/tabs/index.d.ts +4 -0
  233. package/dist/tabs/index.js +3 -0
  234. package/dist/tabs/item.d.ts +13 -0
  235. package/dist/tabs/item.js +4 -0
  236. package/dist/tabs/tab.d.ts +22 -0
  237. package/dist/tabs/tab.js +205 -0
  238. package/dist/tabs/tabList.d.ts +18 -0
  239. package/dist/tabs/tabList.js +256 -0
  240. package/dist/tabs/tabPanels.d.ts +14 -0
  241. package/dist/tabs/tabPanels.js +62 -0
  242. package/dist/tabs/tabs.d.ts +38 -0
  243. package/dist/tabs/tabs.js +56 -0
  244. package/dist/tabs/utils.d.ts +3 -0
  245. package/dist/tabs/utils.js +6 -0
  246. package/dist/text/heading.d.ts +1 -1
  247. package/dist/text/heading.js +1 -1
  248. package/dist/text/styles.js +1 -1
  249. package/dist/text/text.d.ts +1 -1
  250. package/dist/text/text.js +1 -1
  251. package/dist/theme/dark.js +9 -9
  252. package/dist/theme/light.js +9 -9
  253. package/dist/tooltip/tooltip.js +2 -5
  254. package/dist/useMedia.d.ts +15 -0
  255. package/dist/useMedia.js +24 -0
  256. package/dist/useOnClickOutside.d.ts +2 -0
  257. package/dist/useOnClickOutside.js +22 -0
  258. package/dist/useOverlay.d.ts +1 -0
  259. package/dist/useOverlay.js +1 -0
  260. package/dist/useVirtualCollection.d.ts +154 -0
  261. package/dist/useVirtualCollection.js +143 -0
  262. package/dist/useVirtualRows.d.ts +26 -0
  263. package/dist/useVirtualRows.js +26 -0
  264. package/dist/virtualCollectionLayout.d.ts +51 -0
  265. package/dist/virtualCollectionLayout.js +49 -0
  266. package/package.json +115 -16
  267. package/dist/formPresentation/index.d.ts +0 -8
  268. package/dist/formPresentation/index.js +0 -8
  269. package/dist/interactionStateLayer/index.d.ts +0 -1
  270. package/dist/interactionStateLayer/index.js +0 -1
  271. package/dist/interactionStateLayer/interactionStateLayer.d.ts +0 -23
  272. package/dist/interactionStateLayer/interactionStateLayer.js +0 -67
  273. package/dist/unreachable.d.ts +0 -1
  274. package/dist/unreachable.js +0 -4
  275. /package/dist/{formPresentation → form}/autoSaveContext.d.ts +0 -0
  276. /package/dist/{formPresentation → form}/autoSaveContext.js +0 -0
  277. /package/dist/{formPresentation → form}/displayField.d.ts +0 -0
  278. /package/dist/{formPresentation → form/field}/fieldIds.d.ts +0 -0
  279. /package/dist/{formPresentation → form/field}/groupContext.d.ts +0 -0
  280. /package/dist/{formPresentation → form/field}/groupContext.js +0 -0
  281. /package/dist/{formPresentation → form/field}/meta.d.ts +0 -0
  282. /package/dist/{formPresentation → form}/formContext.d.ts +0 -0
  283. /package/dist/{formPresentation → form}/icons.d.ts +0 -0
  284. /package/dist/{formPresentation → form}/icons.js +0 -0
  285. /package/dist/{formPresentation → form/layout}/useStackedLayout.d.ts +0 -0
@@ -0,0 +1,19 @@
1
+ import type { ReactNode } from 'react';
2
+ interface FormSearchProps {
3
+ children: ReactNode;
4
+ /**
5
+ * Route pattern for settings search (e.g., '/settings/account/details/').
6
+ * This prop is used by the static extraction script to associate
7
+ * form fields with their navigation route. It has no runtime effect.
8
+ */
9
+ route: string;
10
+ }
11
+ /**
12
+ * Wrapper component that marks form fields as searchable in settings search.
13
+ * The `route` prop is extracted at build time by scripts/extractFormFields.ts
14
+ * to generate the form field registry used for search.
15
+ *
16
+ * This component has no runtime behavior - it simply renders its children.
17
+ */
18
+ export declare function FormSearch({ children }: FormSearchProps): ReactNode;
19
+ export {};
@@ -0,0 +1,4 @@
1
+ function FormSearch({ children }) {
2
+ return children;
3
+ }
4
+ export { FormSearch };
@@ -0,0 +1,110 @@
1
+ import type * as React from 'react';
2
+ import type { DeepKeys, DeepValue, FieldApi } from '@tanstack/react-form';
3
+ import { type UseMutationOptions } from '@tanstack/react-query';
4
+ import { type z } from 'zod';
5
+ import { type BoundFieldComponents } from './scrapsForm.js';
6
+ /**
7
+ * Configuration for confirmation dialogs before applying changes.
8
+ * Used for dangerous operations like security settings.
9
+ * Always focuses the Cancel button for safety.
10
+ *
11
+ * @example
12
+ * // Simple string - always show this message
13
+ * confirm="Are you sure you want to save?"
14
+ *
15
+ * @example
16
+ * // Function - return message based on new value, or undefined to skip
17
+ * confirm={(value) => value ? "Enable this feature?" : "Disable this feature?"}
18
+ */
19
+ type ConfirmConfig<TValue = unknown> = React.ReactNode | ((value: TValue) => React.ReactNode | undefined);
20
+ type SchemaInput<TSchema extends z.ZodObject> = z.input<TSchema>;
21
+ type SchemaOutput<TSchema extends z.ZodObject> = z.output<TSchema>;
22
+ /** Form data type coming from the schema input */
23
+ type SchemaFieldName<TSchema extends z.ZodObject> = Extract<DeepKeys<SchemaInput<TSchema>>, string>;
24
+ /** FieldApi’s TData must be DeepValue<TParentData, TName> */
25
+ type SchemaFieldInputValue<TSchema extends z.ZodObject, TFieldName extends SchemaFieldName<TSchema>> = DeepValue<SchemaInput<TSchema>, TFieldName>;
26
+ type AutoSaveFormRenderArg<TSchema extends z.ZodObject, TFieldName extends SchemaFieldName<TSchema>> = FieldApi<SchemaInput<TSchema>, TFieldName, SchemaFieldInputValue<TSchema, TFieldName>, undefined, // TOnMount
27
+ undefined, // TOnChange
28
+ undefined, // TOnChangeAsync
29
+ undefined, // TOnBlur
30
+ undefined, // TOnBlurAsync
31
+ undefined, // TOnSubmit
32
+ undefined, // TOnSubmitAsync
33
+ undefined, // TOnDynamic
34
+ undefined, // TOnDynamicAsync
35
+ undefined, // TFormOnMount
36
+ undefined, // TFormOnChange
37
+ undefined, // TFormOnChangeAsync
38
+ undefined, // TFormOnBlur
39
+ undefined, // TFormOnBlurAsync
40
+ undefined, // TFormOnSubmit
41
+ undefined, // TFormOnSubmitAsync
42
+ undefined, // TFormOnDynamic
43
+ undefined, // TFormOnDynamicAsync
44
+ undefined, // TFormOnServer
45
+ unknown> & {
46
+ [K in keyof BoundFieldComponents]: BoundFieldComponents[K];
47
+ };
48
+ /**
49
+ * A component that provides field props and mutation state via render prop.
50
+ *
51
+ * @example
52
+ * <AutoSaveForm
53
+ * name="lastName"
54
+ * schema={baseUserSchema}
55
+ * initialValue={user.data?.lastName ?? ''}
56
+ * mutationOptions={{
57
+ * mutationFn: async (data) => api.patch('/user', data),
58
+ * }}
59
+ * >
60
+ * {field => (
61
+ * <InputField
62
+ * label="Last Name:"
63
+ * required
64
+ * value={field.state.value}
65
+ * onChange={field.handleChange}
66
+ * />
67
+ * )}
68
+ * </AutoSaveForm>
69
+ */
70
+ interface AutoSaveFormProps<TData, TContext, TSchema extends z.ZodObject, TFieldName extends Extract<keyof SchemaInput<TSchema>, string>> {
71
+ /**
72
+ * Render prop that receives field props and additional props
73
+ */
74
+ children: (field: AutoSaveFormRenderArg<TSchema, TFieldName>) => React.ReactElement | null;
75
+ /**
76
+ * Initial value - must match the schema's type for this field
77
+ */
78
+ initialValue: SchemaInput<TSchema>[TFieldName];
79
+ /**
80
+ * TanStack Query mutation options - mutationFn receives single-field data
81
+ */
82
+ mutationOptions: UseMutationOptions<TData, Error, NoInfer<Record<TFieldName, SchemaOutput<TSchema>[TFieldName]>>, TContext>;
83
+ /**
84
+ * Field name - must be a valid string key in the schema
85
+ */
86
+ name: TFieldName;
87
+ /**
88
+ * Zod schema for validation
89
+ */
90
+ schema: TSchema;
91
+ /**
92
+ * Optional confirmation dialog before saving.
93
+ * Shows a modal and requires user confirmation before applying changes.
94
+ *
95
+ * @example
96
+ * // Simple string - always show this message
97
+ * confirm="Are you sure you want to save this change?"
98
+ *
99
+ * @example
100
+ * // Function - return message based on new value, or undefined to skip
101
+ * confirm={(value) => value ? "Enable this feature?" : "Disable this feature?"}
102
+ *
103
+ * @example
104
+ * // Function with conditional confirmation
105
+ * confirm={(value) => value === 'dangerous' ? "This is irreversible!" : undefined}
106
+ */
107
+ confirm?: ConfirmConfig<SchemaInput<TSchema>[TFieldName]>;
108
+ }
109
+ export declare function AutoSaveForm<TData, TContext, TSchema extends z.ZodObject<z.ZodRawShape>, TFieldName extends Extract<keyof SchemaInput<TSchema>, string>>(props: AutoSaveFormProps<TData, TContext, TSchema, TFieldName>): import("@emotion/react/jsx-runtime").JSX.Element;
110
+ export {};
@@ -0,0 +1,100 @@
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import { useId, useRef } from "react";
3
+ import { useMutation } from "@tanstack/react-query";
4
+ import { openConfirmModal } from "../confirm/index.js";
5
+ import { AutoSaveContextProvider } from "./autoSaveContext.js";
6
+ import { useFormErrorMapper } from "./formErrorContext/index.js";
7
+ import { setFieldErrors, useScrapsForm } from "./scrapsForm.js";
8
+ import { useTranslation } from "../translation/useTranslation.js";
9
+ function AutoSaveForm(props) {
10
+ const { name, schema, initialValue, mutationOptions, confirm, children } = props;
11
+ const { t } = useTranslation();
12
+ const mapFormError = useFormErrorMapper();
13
+ const id = useId();
14
+ const mutation = useMutation(mutationOptions);
15
+ const pendingConfirmRef = useRef(false);
16
+ const resetOnErrorRef = useRef(false);
17
+ const form = useScrapsForm({
18
+ formId: `${name}-${id}-(auto-save)`,
19
+ defaultValues: {
20
+ [name]: initialValue
21
+ },
22
+ validators: {
23
+ onChange: schema.pick({
24
+ [name]: true
25
+ })
26
+ },
27
+ listeners: {
28
+ onBlur: ({ formApi, fieldApi })=>{
29
+ if (!fieldApi.state.meta.isDefaultValue) formApi.handleSubmit();
30
+ }
31
+ },
32
+ onSubmit: ({ value, formApi })=>{
33
+ if ('pending' === mutation.status || pendingConfirmRef.current) return Promise.resolve();
34
+ const onError = (error)=>{
35
+ if (resetOnErrorRef.current) formApi.reset();
36
+ const fallbackMessage = t('Failed to save');
37
+ const mappedError = mapFormError(error, formApi.state.values, fallbackMessage);
38
+ if (mappedError && 'fieldErrors' in mappedError && setFieldErrors(formApi, mappedError.fieldErrors)) return;
39
+ setFieldErrors(formApi, {
40
+ [name]: {
41
+ message: mappedError && 'message' in mappedError ? mappedError.message : fallbackMessage
42
+ }
43
+ });
44
+ };
45
+ const onSuccess = ()=>{
46
+ formApi.reset();
47
+ };
48
+ const parsedValue = schema.pick({
49
+ [name]: true
50
+ }).safeParse(value);
51
+ if (!parsedValue.success) return Promise.resolve();
52
+ const submittedValue = parsedValue.data;
53
+ const fieldValue = value[name];
54
+ const confirmMessage = 'function' == typeof confirm ? confirm(fieldValue) : confirm;
55
+ if (confirmMessage) {
56
+ pendingConfirmRef.current = true;
57
+ return new Promise((resolve)=>{
58
+ openConfirmModal({
59
+ message: confirmMessage,
60
+ isDangerous: true,
61
+ onConfirm: ()=>{
62
+ pendingConfirmRef.current = false;
63
+ mutation.mutateAsync(submittedValue, {
64
+ onError,
65
+ onSuccess
66
+ }).then(()=>{
67
+ resolve();
68
+ }, resolve);
69
+ },
70
+ onClose: ()=>{
71
+ if (pendingConfirmRef.current) {
72
+ form.reset();
73
+ resolve();
74
+ }
75
+ pendingConfirmRef.current = false;
76
+ }
77
+ });
78
+ });
79
+ }
80
+ return mutation.mutateAsync(submittedValue, {
81
+ onError,
82
+ onSuccess
83
+ }).catch(()=>{});
84
+ }
85
+ });
86
+ return /*#__PURE__*/ jsx(form.AppForm, {
87
+ form: form,
88
+ children: /*#__PURE__*/ jsx(AutoSaveContextProvider, {
89
+ value: {
90
+ status: mutation.status,
91
+ resetOnErrorRef
92
+ },
93
+ children: /*#__PURE__*/ jsx(form.AppField, {
94
+ name: name,
95
+ children: (field)=>children(field)
96
+ })
97
+ })
98
+ });
99
+ }
100
+ export { AutoSaveForm };
@@ -3,8 +3,8 @@ import { DescriptionList } from "../descriptionList/index.js";
3
3
  import { InfoText } from "../info/index.js";
4
4
  import { Container, Stack } from "../layout/index.js";
5
5
  import { Text } from "../text/index.js";
6
- import { BaseLayout, LayoutLabel } from "./base.js";
7
- import { useStackedLayout } from "./useStackedLayout.js";
6
+ import { BaseLayout, LayoutLabel } from "./layout/base.js";
7
+ import { useStackedLayout } from "./layout/useStackedLayout.js";
8
8
  function RowDisplay(props) {
9
9
  const stacked = useStackedLayout();
10
10
  return /*#__PURE__*/ jsx(DisplayLayout, {
@@ -0,0 +1,23 @@
1
+ import type * as React from 'react';
2
+ import { type Ref } from 'react';
3
+ export type BaseFieldProps<T extends HTMLElement> = {
4
+ disabled?: boolean | string;
5
+ ref?: Ref<T>;
6
+ };
7
+ type FieldChildrenProps<T extends HTMLElement> = {
8
+ 'aria-describedby': string;
9
+ 'aria-invalid': boolean;
10
+ disabled: boolean;
11
+ id: string;
12
+ name: string;
13
+ onBlur: () => void;
14
+ ref: Ref<T>;
15
+ };
16
+ export declare const useAutoSaveIndicator: () => import("@emotion/react/jsx-runtime").JSX.Element | null;
17
+ type FieldState = {
18
+ indicator: React.ReactNode;
19
+ };
20
+ export declare function BaseField<T extends HTMLElement>({ children, disabled, ref: refProp, }: BaseFieldProps<T> & {
21
+ children: (props: FieldChildrenProps<T>, state: FieldState) => React.ReactNode;
22
+ }): import("@emotion/react/jsx-runtime").JSX.Element;
23
+ export {};
@@ -0,0 +1,116 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { mergeRefs } from "@react-aria/utils";
4
+ import { useAutoSaveContext } from "../autoSaveContext.js";
5
+ import { useFieldId, useHintTextId } from "./fieldIds.js";
6
+ import { FieldMeta } from "./meta.js";
7
+ import { useFieldContext } from "../formContext.js";
8
+ import { Checkmark, Spinner } from "../icons.js";
9
+ import { Flex } from "../../layout/index.js";
10
+ import { useOverlayContext } from "../../overlayContext.js";
11
+ const useAutoSaveIndicator = ()=>{
12
+ const field = useFieldContext();
13
+ const status = useAutoSaveContext()?.status;
14
+ if ('pending' === status) return /*#__PURE__*/ jsx(Spinner, {
15
+ role: "status",
16
+ "aria-label": `Saving ${field.name}`,
17
+ "aria-live": "polite"
18
+ });
19
+ if ('success' === status) return /*#__PURE__*/ jsx(Checkmark, {
20
+ variant: "success",
21
+ size: "sm"
22
+ });
23
+ return null;
24
+ };
25
+ function useScrollToHash(fieldName, ref) {
26
+ const locationHash = useOverlayContext().location?.hash ?? '';
27
+ useEffect(()=>{
28
+ let hash;
29
+ try {
30
+ hash = decodeURIComponent(locationHash.slice(1));
31
+ } catch {
32
+ return;
33
+ }
34
+ if (hash !== fieldName) return;
35
+ ref.current?.scrollIntoView({
36
+ block: 'center',
37
+ behavior: 'smooth'
38
+ });
39
+ ref.current?.focus({
40
+ focusVisible: true
41
+ });
42
+ animateRowHighlight(fieldName, ref.current);
43
+ }, [
44
+ fieldName,
45
+ ref,
46
+ locationHash
47
+ ]);
48
+ }
49
+ function useFocusRestore(ref) {
50
+ const autoSaveContext = useAutoSaveContext();
51
+ const focusRestoreTargetRef = useRef(null);
52
+ const isDisabledByAutoSave = autoSaveContext?.status === 'pending';
53
+ useEffect(()=>{
54
+ const el = ref.current;
55
+ if (!el) return;
56
+ function onBlur(event) {
57
+ const target = event.target;
58
+ if (target instanceof HTMLElement && target.hasAttribute('disabled')) focusRestoreTargetRef.current = target;
59
+ }
60
+ el.addEventListener('blur', onBlur, true);
61
+ return ()=>el.removeEventListener('blur', onBlur, true);
62
+ }, [
63
+ ref
64
+ ]);
65
+ useEffect(()=>{
66
+ if (!isDisabledByAutoSave && focusRestoreTargetRef.current) {
67
+ const target = focusRestoreTargetRef.current;
68
+ focusRestoreTargetRef.current = null;
69
+ if (target.isConnected && document.activeElement === document.body) target.focus();
70
+ }
71
+ }, [
72
+ isDisabledByAutoSave
73
+ ]);
74
+ }
75
+ function BaseField({ children, disabled, ref: refProp }) {
76
+ const autoSaveContext = useAutoSaveContext();
77
+ const indicator = useAutoSaveIndicator();
78
+ const field = useFieldContext();
79
+ const ref = useRef(null);
80
+ const fieldId = useFieldId();
81
+ const hintTextId = useHintTextId();
82
+ useScrollToHash(field.name, ref);
83
+ useFocusRestore(ref);
84
+ return /*#__PURE__*/ jsxs(Flex, {
85
+ gap: "sm",
86
+ align: "center",
87
+ children: [
88
+ children({
89
+ ref: mergeRefs(ref, refProp),
90
+ disabled: !!disabled || autoSaveContext?.status === 'pending',
91
+ 'aria-invalid': !field.state.meta.isValid,
92
+ 'aria-describedby': hintTextId,
93
+ onBlur: field.handleBlur,
94
+ name: field.name,
95
+ id: fieldId
96
+ }, {
97
+ indicator
98
+ }),
99
+ /*#__PURE__*/ jsx(FieldMeta.Status, {
100
+ disabled: disabled
101
+ })
102
+ ]
103
+ });
104
+ }
105
+ function animateRowHighlight(fieldName, node) {
106
+ if (!node) return;
107
+ const selector = `#${CSS.escape(fieldName)}`;
108
+ const fieldRow = node.closest(selector) ?? node.querySelector(selector);
109
+ if (fieldRow) {
110
+ fieldRow.dataset.highlight = '';
111
+ fieldRow.addEventListener('animationend', ()=>delete fieldRow.dataset.highlight, {
112
+ once: true
113
+ });
114
+ }
115
+ }
116
+ export { BaseField, useAutoSaveIndicator };
@@ -0,0 +1,11 @@
1
+ import type * as React from 'react';
2
+ import { type CheckboxProps } from '../../checkbox/index.js';
3
+ import { type BaseFieldProps } from './baseField.js';
4
+ type Props = BaseFieldProps<HTMLInputElement> & Omit<CheckboxProps, 'checked' | 'onChange' | 'onBlur' | 'disabled' | 'id' | 'ref'> & {
5
+ checked: boolean;
6
+ label: React.ReactNode;
7
+ onChange: (checked: boolean) => void;
8
+ hintText?: React.ReactNode;
9
+ };
10
+ export declare function CheckboxField({ checked, disabled, hintText, label, onChange, ref, ...props }: Props): import("@emotion/react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,42 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import { Checkbox } from "../../checkbox/index.js";
3
+ import { FieldMeta } from "./meta.js";
4
+ import { Container, Flex, Grid } from "../../layout/index.js";
5
+ import { BaseField } from "./baseField.js";
6
+ function CheckboxField({ checked, disabled, hintText, label, onChange, ref, ...props }) {
7
+ return /*#__PURE__*/ jsx(BaseField, {
8
+ disabled: disabled,
9
+ ref: ref,
10
+ children: (fieldProps, { indicator })=>/*#__PURE__*/ jsxs(Grid, {
11
+ columns: "max-content minmax(0, 1fr)",
12
+ gap: "xs sm",
13
+ align: "center",
14
+ flexGrow: 1,
15
+ children: [
16
+ /*#__PURE__*/ jsx(Checkbox, {
17
+ ...fieldProps,
18
+ ...props,
19
+ checked: checked,
20
+ onChange: (event)=>onChange(event.target.checked)
21
+ }),
22
+ /*#__PURE__*/ jsxs(Flex, {
23
+ align: "center",
24
+ gap: "sm",
25
+ children: [
26
+ /*#__PURE__*/ jsx(FieldMeta.Label, {
27
+ children: label
28
+ }),
29
+ indicator
30
+ ]
31
+ }),
32
+ hintText && /*#__PURE__*/ jsx(Container, {
33
+ column: 2,
34
+ children: /*#__PURE__*/ jsx(FieldMeta.HintText, {
35
+ children: hintText
36
+ })
37
+ })
38
+ ]
39
+ })
40
+ });
41
+ }
42
+ export { CheckboxField };
@@ -0,0 +1,16 @@
1
+ import type * as React from 'react';
2
+ import { type BaseFieldProps } from './baseField.js';
3
+ export interface CheckboxGroupProps<T extends string> extends BaseFieldProps<HTMLDivElement> {
4
+ children: (components: {
5
+ Item: (props: CheckboxGroupItemProps<NoInfer<T>>) => React.JSX.Element;
6
+ }) => React.ReactNode;
7
+ onChange: (value: Array<NoInfer<T>>) => void;
8
+ value: T[];
9
+ }
10
+ interface CheckboxGroupItemProps<T extends string> {
11
+ children: React.ReactNode;
12
+ value: T;
13
+ disabled?: boolean;
14
+ }
15
+ export declare const CheckboxGroupField: <T extends string>(props: CheckboxGroupProps<T>) => React.JSX.Element;
16
+ export {};
@@ -0,0 +1,80 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import { useId } from "react";
3
+ import { Checkbox } from "../../checkbox/index.js";
4
+ import { useAutoSaveContext } from "../autoSaveContext.js";
5
+ import { useLabelId } from "./fieldIds.js";
6
+ import { GroupProvider, useGroupItemContext } from "./groupContext.js";
7
+ import { useFieldContext } from "../formContext.js";
8
+ import { Flex, Stack } from "../../layout/index.js";
9
+ import { Text } from "../../text/index.js";
10
+ import { BaseField } from "./baseField.js";
11
+ function CheckboxGroup({ children, value, onChange, disabled, ref }) {
12
+ const field = useFieldContext();
13
+ const labelId = useLabelId();
14
+ const autoSaveContext = useAutoSaveContext();
15
+ return /*#__PURE__*/ jsx(BaseField, {
16
+ disabled: disabled,
17
+ ref: ref,
18
+ children: ({ disabled: isDisabled, name, ...baseProps }, { indicator })=>/*#__PURE__*/ jsxs(GroupProvider, {
19
+ value: {
20
+ 'aria-describedby': baseProps['aria-describedby'],
21
+ 'aria-invalid': baseProps['aria-invalid'],
22
+ disabled: isDisabled,
23
+ name,
24
+ isChecked: (itemValue)=>value.includes(itemValue),
25
+ onChange: (itemValue, checked)=>{
26
+ onChange(checked ? [
27
+ ...value,
28
+ itemValue
29
+ ] : value.filter((item)=>item !== itemValue));
30
+ if (autoSaveContext) {
31
+ autoSaveContext.resetOnErrorRef.current = true;
32
+ field.handleBlur();
33
+ }
34
+ }
35
+ },
36
+ children: [
37
+ /*#__PURE__*/ jsx(Stack, {
38
+ ...baseProps,
39
+ role: "group",
40
+ "aria-labelledby": labelId,
41
+ "aria-disabled": isDisabled,
42
+ flexGrow: 1,
43
+ tabIndex: -1,
44
+ onFocus: (event)=>{
45
+ if (event.target === event.currentTarget) event.currentTarget.querySelector('input[type="checkbox"]:enabled')?.focus();
46
+ },
47
+ children: children(checkboxGroupComponents)
48
+ }),
49
+ indicator
50
+ ]
51
+ })
52
+ });
53
+ }
54
+ function CheckboxGroupItem({ children, value: itemValue, disabled }) {
55
+ const { checked, onChange, disabled: groupDisabled, ...fieldProps } = useGroupItemContext(itemValue);
56
+ const id = useId();
57
+ return /*#__PURE__*/ jsxs(Flex, {
58
+ as: "label",
59
+ gap: "sm",
60
+ align: "center",
61
+ children: [
62
+ /*#__PURE__*/ jsx(Checkbox, {
63
+ ...fieldProps,
64
+ id: id,
65
+ value: itemValue,
66
+ checked: checked,
67
+ disabled: groupDisabled || disabled,
68
+ onChange: (event)=>onChange(itemValue, event.target.checked)
69
+ }),
70
+ /*#__PURE__*/ jsx(Text, {
71
+ children: children
72
+ })
73
+ ]
74
+ });
75
+ }
76
+ const checkboxGroupComponents = {
77
+ Item: CheckboxGroupItem
78
+ };
79
+ const CheckboxGroupField = CheckboxGroup;
80
+ export { CheckboxGroupField };
@@ -0,0 +1,19 @@
1
+ import { type MultipleSelectProps, type SelectKey, type SingleSelectProps } from '../../compactSelect/index.js';
2
+ import { type BaseFieldProps } from './baseField.js';
3
+ type FieldOverrides = 'value' | 'onChange' | 'disabled' | 'onBlur' | 'id';
4
+ type CompactSelectFieldProps<TValue extends SelectKey> = BaseFieldProps<HTMLButtonElement> & ((Omit<MultipleSelectProps<TValue>, FieldOverrides> & {
5
+ onChange: (value: TValue[]) => void;
6
+ value: TValue[];
7
+ }) | (Omit<Extract<SingleSelectProps<TValue>, {
8
+ clearable: true;
9
+ }>, FieldOverrides> & {
10
+ onChange: (value: TValue | null) => void;
11
+ value: TValue | null;
12
+ }) | (Omit<Extract<SingleSelectProps<TValue>, {
13
+ clearable?: false;
14
+ }>, FieldOverrides> & {
15
+ onChange: (value: TValue) => void;
16
+ value: TValue | null;
17
+ }));
18
+ export declare function CompactSelectField<TValue extends SelectKey>({ disabled, ref, trigger, ...props }: CompactSelectFieldProps<TValue>): import("@emotion/react/jsx-runtime").JSX.Element;
19
+ export {};
@@ -0,0 +1,77 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import { Fragment } from "react";
3
+ import { mergeProps, mergeRefs } from "@react-aria/utils";
4
+ import { CompactSelect } from "../../compactSelect/index.js";
5
+ import { useAutoSaveContext } from "../autoSaveContext.js";
6
+ import { useFieldContext } from "../formContext.js";
7
+ import { Container } from "../../layout/index.js";
8
+ import { OverlayTrigger } from "../../overlayTrigger.js";
9
+ import { BaseField } from "./baseField.js";
10
+ function CompactSelectField({ disabled, ref, trigger, ...props }) {
11
+ const autoSaveContext = useAutoSaveContext();
12
+ const field = useFieldContext();
13
+ const selectProps = props.multiple ? {
14
+ ...props,
15
+ onChange: (options)=>{
16
+ props.onChange(options.map((option)=>option.value));
17
+ }
18
+ } : props.clearable ? {
19
+ ...props,
20
+ value: props.value ?? void 0,
21
+ onChange: (option)=>{
22
+ props.onChange(option?.value ?? null);
23
+ if (autoSaveContext) field.handleBlur();
24
+ }
25
+ } : {
26
+ ...props,
27
+ value: props.value ?? void 0,
28
+ onChange: (option)=>{
29
+ props.onChange(option.value);
30
+ if (autoSaveContext) field.handleBlur();
31
+ }
32
+ };
33
+ return /*#__PURE__*/ jsx(BaseField, {
34
+ disabled: disabled ?? 0 === props.options.length,
35
+ ref: ref,
36
+ children: (fieldProps, { indicator })=>/*#__PURE__*/ jsxs(Fragment, {
37
+ children: [
38
+ /*#__PURE__*/ jsx(Container, {
39
+ flex: 1,
40
+ minWidth: 0,
41
+ children: /*#__PURE__*/ jsx(CompactSelect, {
42
+ ...selectProps,
43
+ style: {
44
+ width: '100%',
45
+ ...props.style
46
+ },
47
+ triggerId: fieldProps.id,
48
+ disabled: fieldProps.disabled,
49
+ onClose: ()=>{
50
+ props.onClose?.();
51
+ if (!autoSaveContext || props.multiple) field.handleBlur();
52
+ },
53
+ trigger: (triggerProps, isOpen)=>{
54
+ const mergedProps = mergeProps({
55
+ style: {
56
+ width: '100%'
57
+ }
58
+ }, triggerProps, {
59
+ ...fieldProps,
60
+ onBlur: ()=>{
61
+ if (!isOpen) fieldProps.onBlur();
62
+ }
63
+ }, {
64
+ ref: mergeRefs(triggerProps.ref, fieldProps.ref)
65
+ });
66
+ return trigger ? trigger(mergedProps, isOpen) : /*#__PURE__*/ jsx(OverlayTrigger.Button, {
67
+ ...mergedProps
68
+ });
69
+ }
70
+ })
71
+ }),
72
+ indicator
73
+ ]
74
+ })
75
+ });
76
+ }
77
+ export { CompactSelectField };
@@ -1,4 +1,4 @@
1
- import { useFieldContext } from "./formContext.js";
1
+ import { useFieldContext } from "../formContext.js";
2
2
  const useFieldId = ()=>{
3
3
  const field = useFieldContext();
4
4
  return field.form.formId + field.name;
@@ -0,0 +1,19 @@
1
+ import type * as React from 'react';
2
+ import { type InputProps } from '../../input/index.js';
3
+ import { type BaseFieldProps } from './baseField.js';
4
+ interface SharedInputFieldProps extends BaseFieldProps<HTMLInputElement>, Omit<InputProps, 'value' | 'onChange' | 'onBlur' | 'disabled' | 'id' | 'type' | 'readOnly'> {
5
+ value: string;
6
+ disabled?: boolean | string;
7
+ leadingItems?: React.ReactNode;
8
+ trailingItems?: React.ReactNode;
9
+ type?: 'button' | 'checkbox' | 'color' | 'date' | 'datetime-local' | 'email' | 'file' | 'hidden' | 'image' | 'month' | 'number' | 'password' | 'radio' | 'range' | 'reset' | 'search' | 'submit' | 'tel' | 'text' | 'time' | 'url' | 'week';
10
+ }
11
+ export type InputFieldProps = SharedInputFieldProps & ({
12
+ readOnly: true;
13
+ onChange?: (value: string) => void;
14
+ } | {
15
+ onChange: (value: string) => void;
16
+ readOnly?: boolean;
17
+ });
18
+ export declare function InputField({ onChange, disabled, leadingItems, trailingItems, ref, ...props }: InputFieldProps): import("@emotion/react/jsx-runtime").JSX.Element;
19
+ export {};