@object-ui/fields 17.3.0 → 17.6.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 (265) hide show
  1. package/CHANGELOG.md +1655 -0
  2. package/README.md +1 -12
  3. package/dist/FieldEditWidget.d.ts +23 -3
  4. package/dist/currency.d.ts +46 -0
  5. package/dist/field-type-alias.d.ts +35 -1
  6. package/dist/index.cjs +4 -4
  7. package/dist/index.css +651 -0
  8. package/dist/index.d.ts +474 -85
  9. package/dist/index.js +5418 -5023
  10. package/dist/widgets/AddressField.d.ts +4 -12
  11. package/dist/widgets/AutoNumberField.d.ts +1 -1
  12. package/dist/widgets/AvatarField.d.ts +1 -1
  13. package/dist/widgets/BooleanField.d.ts +1 -1
  14. package/dist/widgets/CapabilityMultiSelectField.d.ts +1 -1
  15. package/dist/widgets/CheckboxesField.d.ts +1 -1
  16. package/dist/widgets/CodeField.d.ts +1 -1
  17. package/dist/widgets/ColorField.d.ts +1 -1
  18. package/dist/widgets/CurrencyField.d.ts +1 -1
  19. package/dist/widgets/DateField.d.ts +1 -1
  20. package/dist/widgets/DateTimeField.d.ts +1 -1
  21. package/dist/widgets/EmailField.d.ts +1 -1
  22. package/dist/widgets/FileField.d.ts +18 -2
  23. package/dist/widgets/FilterConditionField.d.ts +28 -1
  24. package/dist/widgets/FormulaField.d.ts +1 -1
  25. package/dist/widgets/FullscreenFieldEditor.d.ts +49 -152
  26. package/dist/widgets/GeolocationField.d.ts +1 -1
  27. package/dist/widgets/GridField.d.ts +68 -6
  28. package/dist/widgets/ImageField.d.ts +1 -1
  29. package/dist/widgets/LocationField.d.ts +1 -1
  30. package/dist/widgets/LookupField.d.ts +1 -1
  31. package/dist/widgets/MasterDetailField.d.ts +1 -1
  32. package/dist/widgets/MultiSelectField.d.ts +1 -1
  33. package/dist/widgets/NumberField.d.ts +1 -1
  34. package/dist/widgets/ObjectField.d.ts +1 -1
  35. package/dist/widgets/ObjectRefField.d.ts +1 -1
  36. package/dist/widgets/OptionsEmptyState.d.ts +21 -1
  37. package/dist/widgets/PasswordField.d.ts +1 -1
  38. package/dist/widgets/PercentField.d.ts +1 -1
  39. package/dist/widgets/PhoneField.d.ts +1 -1
  40. package/dist/widgets/QRCodeField.d.ts +1 -1
  41. package/dist/widgets/RadioField.d.ts +1 -1
  42. package/dist/widgets/RatingField.d.ts +1 -1
  43. package/dist/widgets/RecipientPickerField.d.ts +1 -1
  44. package/dist/widgets/RecordPickerDialog.d.ts +34 -10
  45. package/dist/widgets/RichTextField.d.ts +37 -1
  46. package/dist/widgets/SelectField.d.ts +26 -6
  47. package/dist/widgets/SignatureField.d.ts +32 -2
  48. package/dist/widgets/SliderField.d.ts +37 -2
  49. package/dist/widgets/SummaryField.d.ts +1 -1
  50. package/dist/widgets/TagsField.d.ts +1 -1
  51. package/dist/widgets/TextAreaField.d.ts +6 -2
  52. package/dist/widgets/TextField.d.ts +1 -1
  53. package/dist/widgets/TimeField.d.ts +1 -1
  54. package/dist/widgets/UrlField.d.ts +1 -1
  55. package/dist/widgets/UserField.d.ts +1 -1
  56. package/dist/widgets/VectorField.d.ts +1 -1
  57. package/dist/widgets/_cell-renderer-bridge.d.ts +1 -1
  58. package/dist/widgets/address-format.d.ts +88 -0
  59. package/dist/widgets/file-size-guard.d.ts +41 -0
  60. package/dist/widgets/lookupColumnDisplay.d.ts +93 -0
  61. package/dist/widgets/nativeDateValue.d.ts +37 -0
  62. package/dist/widgets/richTextDisplay.d.ts +80 -0
  63. package/dist/widgets/toDomProps.d.ts +30 -10
  64. package/dist/widgets/toHostGroupProps.d.ts +189 -0
  65. package/dist/widgets/types.d.ts +8 -3
  66. package/dist/widgets/useRecordQuery.d.ts +7 -1
  67. package/package.json +17 -14
  68. package/dist/FieldEditWidget.test.d.ts +0 -8
  69. package/dist/__tests__/DateCellRenderer.test.d.ts +0 -0
  70. package/dist/__tests__/NumberCellRenderer.test.d.ts +0 -0
  71. package/dist/__tests__/cell-truncation.test.d.ts +0 -0
  72. package/dist/__tests__/field-carrier-sdui.test.d.ts +0 -0
  73. package/dist/__tests__/lookupCellDisplayField.test.d.ts +0 -0
  74. package/dist/__tests__/lookupCellDisplayName.test.d.ts +0 -0
  75. package/dist/__tests__/lookupCellReferenceKey.test.d.ts +0 -0
  76. package/dist/__tests__/registry-collision.test.d.ts +0 -0
  77. package/dist/__tests__/resolveFieldCurrency.test.d.ts +0 -1
  78. package/dist/__tests__/spec-symbol-batch7.test.d.ts +0 -8
  79. package/dist/__tests__/validation-feedback.test.d.ts +0 -0
  80. package/dist/__tests__/widget-aria-invalid-e2e.test.d.ts +0 -0
  81. package/dist/__tests__/widget-aria-invalid-registry-e2e.test.d.ts +0 -0
  82. package/dist/__tests__/widget-dom-leak-e2e.test.d.ts +0 -0
  83. package/dist/__tests__/widget-props-contract.test.d.ts +0 -8
  84. package/dist/coerce-safe-value.test.d.ts +0 -1
  85. package/dist/complex-widgets.test.d.ts +0 -1
  86. package/dist/datetime-widgets.test.d.ts +0 -1
  87. package/dist/field-type-coverage.test.d.ts +0 -1
  88. package/dist/standard-widgets.test.d.ts +0 -0
  89. package/dist/widgets/AddressField.uniqueIds.test.d.ts +0 -0
  90. package/dist/widgets/CapabilityMultiSelectField.test.d.ts +0 -0
  91. package/dist/widgets/CharacterCount.d.ts +0 -56
  92. package/dist/widgets/CheckboxesField.cascade.test.d.ts +0 -0
  93. package/dist/widgets/GeolocationField.uniqueIds.test.d.ts +0 -0
  94. package/dist/widgets/GridField.test.d.ts +0 -1
  95. package/dist/widgets/ImageLightbox.test.d.ts +0 -1
  96. package/dist/widgets/LookupField.dependsOn.test.d.ts +0 -8
  97. package/dist/widgets/LookupField.gateHintLabel.test.d.ts +0 -8
  98. package/dist/widgets/LookupField.hydration.test.d.ts +0 -1
  99. package/dist/widgets/LookupField.idField.test.d.ts +0 -1
  100. package/dist/widgets/MultiSelectField.cascade.test.d.ts +0 -0
  101. package/dist/widgets/OptionsEmptyState.no-provider.test.d.ts +0 -0
  102. package/dist/widgets/OptionsEmptyState.test.d.ts +0 -0
  103. package/dist/widgets/PeoplePicker.test.d.ts +0 -8
  104. package/dist/widgets/PeoplePickerComponents.test.d.ts +0 -8
  105. package/dist/widgets/RadioField.cascade.test.d.ts +0 -0
  106. package/dist/widgets/RecipientPickerField.test.d.ts +0 -0
  107. package/dist/widgets/RecordPickerDialog.filterOptions.test.d.ts +0 -8
  108. package/dist/widgets/RecordPickerDialog.selectLabel.test.d.ts +0 -8
  109. package/dist/widgets/SelectField.cascade.test.d.ts +0 -0
  110. package/dist/widgets/TagsField.placeholder.no-provider.test.d.ts +0 -0
  111. package/dist/widgets/TagsField.placeholder.test.d.ts +0 -0
  112. package/dist/widgets/UserFieldPicker.test.d.ts +0 -8
  113. package/dist/widgets/__tests__/FilterConditionField.matchAll.test.d.ts +0 -8
  114. package/dist/widgets/__tests__/FilterConditionField.operators.test.d.ts +0 -8
  115. package/dist/widgets/__tests__/FullscreenFieldEditor.i18n.test.d.ts +0 -0
  116. package/dist/widgets/__tests__/FullscreenFieldEditor.no-provider.test.d.ts +0 -0
  117. package/dist/widgets/__tests__/RichTextField.fullscreenDisabled.test.d.ts +0 -0
  118. package/dist/widgets/__tests__/RichTextField.mobileFullscreen.test.d.ts +0 -0
  119. package/dist/widgets/__tests__/TextAreaField.characterCount.announcements.test.d.ts +0 -0
  120. package/dist/widgets/__tests__/TextAreaField.characterCount.i18n.test.d.ts +0 -0
  121. package/dist/widgets/__tests__/TextAreaField.characterCount.no-provider.test.d.ts +0 -0
  122. package/dist/widgets/__tests__/TextAreaField.fullscreenCharacterCount.i18n.test.d.ts +0 -0
  123. package/dist/widgets/__tests__/TextAreaField.fullscreenCharacterCount.test.d.ts +0 -0
  124. package/dist/widgets/__tests__/TextAreaField.fullscreenDisabled.test.d.ts +0 -0
  125. package/dist/widgets/__tests__/TextAreaField.mobileFullscreen.test.d.ts +0 -0
  126. package/dist/widgets/deriveLookupColumns.test.d.ts +0 -1
  127. package/dist/widgets/file-value.test.d.ts +0 -1
  128. package/dist/widgets/personDisplay.test.d.ts +0 -8
  129. package/dist/widgets/recentLookups.test.d.ts +0 -1
  130. package/dist/widgets/useRecordQuery.test.d.ts +0 -8
  131. package/dist/widgets/useUploadingSignal.test.d.ts +0 -1
  132. package/src/FieldEditWidget.test.ts +0 -133
  133. package/src/FieldEditWidget.tsx +0 -191
  134. package/src/__tests__/DateCellRenderer.test.tsx +0 -73
  135. package/src/__tests__/NumberCellRenderer.test.tsx +0 -60
  136. package/src/__tests__/cell-truncation.test.tsx +0 -96
  137. package/src/__tests__/field-carrier-sdui.test.tsx +0 -169
  138. package/src/__tests__/lookupCellDisplayField.test.tsx +0 -107
  139. package/src/__tests__/lookupCellDisplayName.test.tsx +0 -119
  140. package/src/__tests__/lookupCellReferenceKey.test.tsx +0 -57
  141. package/src/__tests__/registry-collision.test.ts +0 -91
  142. package/src/__tests__/resolveFieldCurrency.test.ts +0 -20
  143. package/src/__tests__/spec-symbol-batch7.test.ts +0 -126
  144. package/src/__tests__/validation-feedback.test.tsx +0 -361
  145. package/src/__tests__/widget-aria-invalid-e2e.test.tsx +0 -265
  146. package/src/__tests__/widget-aria-invalid-registry-e2e.test.tsx +0 -338
  147. package/src/__tests__/widget-dom-leak-e2e.test.tsx +0 -598
  148. package/src/__tests__/widget-props-contract.test.tsx +0 -142
  149. package/src/coerce-safe-value.test.ts +0 -34
  150. package/src/complex-widgets.test.tsx +0 -908
  151. package/src/currency.ts +0 -14
  152. package/src/datetime-widgets.test.tsx +0 -93
  153. package/src/field-type-alias.ts +0 -100
  154. package/src/field-type-coverage.test.ts +0 -67
  155. package/src/index.tsx +0 -2503
  156. package/src/standard-widgets.test.tsx +0 -357
  157. package/src/widgets/AddressField.tsx +0 -132
  158. package/src/widgets/AddressField.uniqueIds.test.tsx +0 -92
  159. package/src/widgets/AutoNumberField.tsx +0 -18
  160. package/src/widgets/AvatarField.tsx +0 -117
  161. package/src/widgets/BooleanField.tsx +0 -52
  162. package/src/widgets/CapabilityMultiSelectField.test.tsx +0 -168
  163. package/src/widgets/CapabilityMultiSelectField.tsx +0 -229
  164. package/src/widgets/CharacterCount.tsx +0 -263
  165. package/src/widgets/CheckboxesField.cascade.test.tsx +0 -143
  166. package/src/widgets/CheckboxesField.tsx +0 -136
  167. package/src/widgets/CodeField.tsx +0 -41
  168. package/src/widgets/ColorField.tsx +0 -53
  169. package/src/widgets/CurrencyField.tsx +0 -95
  170. package/src/widgets/DateField.tsx +0 -31
  171. package/src/widgets/DateTimeField.tsx +0 -37
  172. package/src/widgets/EmailField.tsx +0 -37
  173. package/src/widgets/FileField.tsx +0 -494
  174. package/src/widgets/FilterConditionField.tsx +0 -454
  175. package/src/widgets/FormulaField.tsx +0 -33
  176. package/src/widgets/FullscreenFieldEditor.tsx +0 -271
  177. package/src/widgets/GeolocationField.tsx +0 -167
  178. package/src/widgets/GeolocationField.uniqueIds.test.tsx +0 -88
  179. package/src/widgets/GridField.test.tsx +0 -406
  180. package/src/widgets/GridField.tsx +0 -966
  181. package/src/widgets/ImageCropperDialog.tsx +0 -245
  182. package/src/widgets/ImageField.tsx +0 -255
  183. package/src/widgets/ImageLightbox.test.tsx +0 -52
  184. package/src/widgets/ImageLightbox.tsx +0 -108
  185. package/src/widgets/LocationField.tsx +0 -57
  186. package/src/widgets/LookupField.dependsOn.test.tsx +0 -233
  187. package/src/widgets/LookupField.gateHintLabel.test.tsx +0 -135
  188. package/src/widgets/LookupField.hydration.test.tsx +0 -136
  189. package/src/widgets/LookupField.idField.test.tsx +0 -61
  190. package/src/widgets/LookupField.tsx +0 -1291
  191. package/src/widgets/MarkdownContent.tsx +0 -19
  192. package/src/widgets/MasterDetailField.tsx +0 -131
  193. package/src/widgets/MultiSelectField.cascade.test.tsx +0 -143
  194. package/src/widgets/MultiSelectField.tsx +0 -142
  195. package/src/widgets/NumberField.tsx +0 -49
  196. package/src/widgets/ObjectField.tsx +0 -94
  197. package/src/widgets/ObjectRefField.tsx +0 -121
  198. package/src/widgets/OptionsEmptyState.no-provider.test.tsx +0 -88
  199. package/src/widgets/OptionsEmptyState.test.tsx +0 -169
  200. package/src/widgets/OptionsEmptyState.tsx +0 -83
  201. package/src/widgets/PasswordField.tsx +0 -49
  202. package/src/widgets/PeoplePicker.test.tsx +0 -360
  203. package/src/widgets/PeoplePicker.tsx +0 -579
  204. package/src/widgets/PeoplePickerComponents.test.tsx +0 -104
  205. package/src/widgets/PercentField.tsx +0 -95
  206. package/src/widgets/PersonRow.tsx +0 -117
  207. package/src/widgets/PhoneField.tsx +0 -37
  208. package/src/widgets/QRCodeField.tsx +0 -103
  209. package/src/widgets/RadioField.cascade.test.tsx +0 -141
  210. package/src/widgets/RadioField.tsx +0 -111
  211. package/src/widgets/RatingField.tsx +0 -81
  212. package/src/widgets/RecipientPickerField.test.tsx +0 -157
  213. package/src/widgets/RecipientPickerField.tsx +0 -188
  214. package/src/widgets/RecordPickerDialog.filterOptions.test.tsx +0 -611
  215. package/src/widgets/RecordPickerDialog.selectLabel.test.tsx +0 -112
  216. package/src/widgets/RecordPickerDialog.tsx +0 -1316
  217. package/src/widgets/RichTextField.tsx +0 -176
  218. package/src/widgets/SelectField.cascade.test.tsx +0 -138
  219. package/src/widgets/SelectField.tsx +0 -162
  220. package/src/widgets/SelectionTray.tsx +0 -110
  221. package/src/widgets/SignatureField.tsx +0 -140
  222. package/src/widgets/SliderField.tsx +0 -39
  223. package/src/widgets/SummaryField.tsx +0 -31
  224. package/src/widgets/TagsField.placeholder.no-provider.test.tsx +0 -68
  225. package/src/widgets/TagsField.placeholder.test.tsx +0 -95
  226. package/src/widgets/TagsField.tsx +0 -88
  227. package/src/widgets/TextAreaField.tsx +0 -213
  228. package/src/widgets/TextField.tsx +0 -45
  229. package/src/widgets/TimeField.tsx +0 -31
  230. package/src/widgets/UrlField.tsx +0 -46
  231. package/src/widgets/UserField.tsx +0 -58
  232. package/src/widgets/UserFieldPicker.test.tsx +0 -78
  233. package/src/widgets/VectorField.tsx +0 -29
  234. package/src/widgets/__tests__/FilterConditionField.matchAll.test.ts +0 -66
  235. package/src/widgets/__tests__/FilterConditionField.operators.test.ts +0 -142
  236. package/src/widgets/__tests__/FullscreenFieldEditor.i18n.test.tsx +0 -248
  237. package/src/widgets/__tests__/FullscreenFieldEditor.no-provider.test.tsx +0 -116
  238. package/src/widgets/__tests__/RichTextField.fullscreenDisabled.test.tsx +0 -244
  239. package/src/widgets/__tests__/RichTextField.mobileFullscreen.test.tsx +0 -195
  240. package/src/widgets/__tests__/TextAreaField.characterCount.announcements.test.tsx +0 -417
  241. package/src/widgets/__tests__/TextAreaField.characterCount.i18n.test.tsx +0 -287
  242. package/src/widgets/__tests__/TextAreaField.characterCount.no-provider.test.tsx +0 -160
  243. package/src/widgets/__tests__/TextAreaField.fullscreenCharacterCount.i18n.test.tsx +0 -161
  244. package/src/widgets/__tests__/TextAreaField.fullscreenCharacterCount.test.tsx +0 -346
  245. package/src/widgets/__tests__/TextAreaField.fullscreenDisabled.test.tsx +0 -246
  246. package/src/widgets/__tests__/TextAreaField.mobileFullscreen.test.tsx +0 -175
  247. package/src/widgets/_cell-renderer-bridge.ts +0 -19
  248. package/src/widgets/deriveLookupColumns.test.ts +0 -112
  249. package/src/widgets/deriveLookupColumns.ts +0 -108
  250. package/src/widgets/file-value.test.ts +0 -230
  251. package/src/widgets/file-value.ts +0 -246
  252. package/src/widgets/openNativePicker.ts +0 -18
  253. package/src/widgets/personDisplay.test.ts +0 -113
  254. package/src/widgets/personDisplay.ts +0 -92
  255. package/src/widgets/recentLookups.test.ts +0 -45
  256. package/src/widgets/recentLookups.ts +0 -47
  257. package/src/widgets/toDomProps.ts +0 -175
  258. package/src/widgets/types.ts +0 -242
  259. package/src/widgets/useCascadingOptions.ts +0 -46
  260. package/src/widgets/useFieldTranslation.ts +0 -150
  261. package/src/widgets/useRecordQuery.test.ts +0 -174
  262. package/src/widgets/useRecordQuery.ts +0 -264
  263. package/src/widgets/useUploadingSignal.test.tsx +0 -62
  264. package/src/widgets/useUploadingSignal.ts +0 -20
  265. package/src/withFieldCarrier.tsx +0 -75
@@ -1,271 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- import React, { useState } from 'react';
10
- import {
11
- cn,
12
- Dialog,
13
- DialogContent,
14
- DialogDescription,
15
- DialogHeader,
16
- DialogTitle,
17
- DialogFooter,
18
- Button,
19
- } from '@object-ui/components';
20
- import { Maximize2, Check, X } from 'lucide-react';
21
- import { useFieldTranslation } from './useFieldTranslation';
22
-
23
- /**
24
- * The fullscreen-edit affordance shared by every long-text widget: the "expand"
25
- * button plus the full-height dialog it opens.
26
- *
27
- * ## Why this is shared rather than copied
28
- *
29
- * `ObjectFormSchema.mobile.fullscreenLongText` is ONE form-level promise, and
30
- * `ObjectForm` projects it onto EVERY long-text field as `mobile_fullscreen`
31
- * (`field:textarea` → `TextAreaField`, `field:markdown` / `field:html` →
32
- * `RichTextField`). A user who turns the setting on gets one behaviour, so the
33
- * behaviour has one implementation. objectui#3301 is what the other
34
- * arrangement costs: the flag reached `RichTextField` for as long as the
35
- * feature has existed and that widget simply never read it, so half the
36
- * documented promise ("textarea/rich-text get an expand button") silently did
37
- * nothing. A second hand-written copy of the state machine is the same failure
38
- * with an extra step — it drifts, and nothing reports the drift.
39
- *
40
- * What is genuinely per-widget is the EDITOR, so that is the only thing
41
- * injected: `children` renders it against the draft. Everything a user can
42
- * observe about the *interaction* — when the affordance appears, that the
43
- * dialog seeds from the committed value, that typing stays local until "Done",
44
- * that "Cancel" discards — lives here, once.
45
- *
46
- * ## Draft semantics (unchanged from the original `TextAreaField` behaviour)
47
- *
48
- * The dialog edits a LOCAL draft seeded from `value` at open time and commits
49
- * once, on "Done". It deliberately does not stream every keystroke to the host:
50
- * these widgets sit in a react-hook-form field, and per-keystroke `onChange`
51
- * during a modal edit would mark the form dirty (and fire validation) for an
52
- * edit the user may still cancel. "Cancel" therefore needs no undo — nothing
53
- * was written.
54
- *
55
- * ## `disabled` (objectui#3402)
56
- *
57
- * The dialog is a SECOND editing surface for the same value, so a field that is
58
- * not interactive has to be not interactive here too. It was not: hosts landed
59
- * `disabled` on their inline control only, this component never declared the
60
- * prop at all, and a disabled long-text field therefore sat correctly greyed out
61
- * next to a live expand button — click it, type anything, press "Done", and the
62
- * edit went into form state through `onCommit`. Measured on `origin/main`
63
- * before the fix: inline `disabled=true`, toggle `disabled=false`, dialog input
64
- * `disabled=false`, `onChange` called with "EDITED WHILE DISABLED".
65
- *
66
- * The gate is shaped like the built-in path's (`FullscreenTextarea` in
67
- * `components/src/renderers/form/form.tsx`, objectui#3400/PR #3401), because
68
- * one form-level setting must keep producing one behaviour on both paths:
69
- *
70
- * - the toggle STAYS but is `disabled` — `disabled` means "not interactive,
71
- * muted", not "shown plainly", which is `readonly`'s job (and `readonly`
72
- * never reaches this component at all — see below);
73
- * - `openFullscreen` refuses independently of the attribute, since a
74
- * programmatic dispatch and a lost `pointer-events` rule both get past it;
75
- * - the dialog locks on its OWN — `disabled` is not merely a static flag, it is
76
- * also the form's `isSubmitting`, which flips to true while the dialog may
77
- * already be open. At that moment the toggle is no longer the gate. So the
78
- * editor is told (third `children` argument) and "Done" is disabled;
79
- * - and `onCommit` is gated, because that is the single point where a value can
80
- * leave this component for host state. Nothing native guards it: it is a
81
- * click handler on a different control reading React state.
82
- *
83
- * "Cancel" and `Esc` stay live in every state — a dialog that goes disabled
84
- * mid-edit must still be closable, or a submit in flight traps the user in it.
85
- *
86
- * ## Why there is no `readonly` prop
87
- *
88
- * Both hosts early-return a read-only DISPLAY before they compute the affordance
89
- * (`TextAreaField.tsx`, `RichTextField.tsx`), so this component is never
90
- * rendered for a read-only field and a `readonly` prop here would be declared
91
- * with no producer — the shape this package keeps deleting (objectui#3232/#3233).
92
- * A future host that renders an editor for read-only fields must add the prop
93
- * AND the producer together; do not add it "for symmetry" beforehand.
94
- *
95
- * ## `testIdPrefix`
96
- *
97
- * Each host passes its own (`textarea`, `richtext`), yielding the same
98
- * convention with a per-widget namespace: `<prefix>-fullscreen-toggle` /
99
- * `-dialog` / `-save`. One form can contain both a textarea and a markdown
100
- * field, so a single shared id would make a test unable to say which widget it
101
- * had found. The editor's own test id belongs to `children` for the same
102
- * reason.
103
- *
104
- * ## Copy (objectui#3404)
105
- *
106
- * Every string here goes through `useFieldTranslation()` and consumes the
107
- * EXISTING `form.fullscreen.*` / `common.cancel` keys — the same ones the
108
- * built-in branch consumes since objectui#3272. Nothing was missing from the
109
- * ten locale packs; this path simply never read them, so a zh session opened a
110
- * dialog reading `Cancel` / `Done` while a long-text field rendered by the
111
- * built-in branch **in the same form** read 「取消 / 完成」.
112
- *
113
- * Sharing the keys rather than minting `fields.fullscreen.*` twins is the
114
- * point: one form-level setting (`mobile.fullscreenLongText`) projects onto
115
- * both render paths, so two copies of this copy could only drift.
116
- *
117
- * `useFieldTranslation` (not bare `useObjectTranslation`) because this widget
118
- * is rendered without an `I18nProvider` by standalone/embedded hosts and by
119
- * every bare-render test in this package. Measured before the change: with no
120
- * provider mounted `useObjectTranslation().t('common.cancel')` returns
121
- * `"common.cancel"` — the raw key — and the `{{label}}` interpolation collapses
122
- * entirely. The safe hook's English defaults are byte-identical to the literals
123
- * they replaced, so the provider-less rendering is unchanged.
124
- *
125
- * Focus management, `Esc`, the overlay and the close button are Radix's, via
126
- * the repo's `Dialog` (`@object-ui/components`) — deliberately not re-answered
127
- * here.
128
- */
129
- export interface FullscreenFieldEditorProps {
130
- /**
131
- * The committed value. Seeds the draft each time the dialog opens — read at
132
- * open time, not held, so a value that changes underneath while the dialog is
133
- * closed is picked up on the next open.
134
- */
135
- value: string;
136
- /** Called once with the draft when the user confirms. */
137
- onCommit: (next: string) => void;
138
- /** Field label — the dialog title and part of the toggle's accessible name. */
139
- label?: string;
140
- /** Namespace for this widget's fullscreen test ids. See above. */
141
- testIdPrefix: string;
142
- /**
143
- * The host field is not interactive (objectui#3402). Disables the toggle, the
144
- * "Done" button and the write-back, and is handed to `children` so the host's
145
- * own editor renders disabled too. See the `disabled` section above for why
146
- * each of those is a separate line rather than belt-and-braces.
147
- *
148
- * **Producer**: the widget's `disabled` prop, which the form renderer computes
149
- * as `disabled || fieldDisabled || isSubmitting || optionGroupGated` and
150
- * forwards to registered widgets (`stripRegisteredFieldProps` does not strip
151
- * it).
152
- */
153
- disabled?: boolean;
154
- /**
155
- * The editor itself, rendered inside the dialog body against the draft. The
156
- * host passes the SAME editor it renders inline, so "fullscreen" is a size
157
- * change rather than a second, poorer editing surface.
158
- *
159
- * The third argument is this component's `disabled`, and the host is expected
160
- * to put it on the control it renders: only the host knows which element its
161
- * editor's disabled state belongs on. Ignoring it is not a write-back hole —
162
- * `onCommit` is gated here regardless — but it does leave a control that looks
163
- * editable while the field is not, so both in-repo hosts apply it and their
164
- * tests pin it.
165
- */
166
- children: (
167
- draft: string,
168
- setDraft: (next: string) => void,
169
- disabled: boolean,
170
- ) => React.ReactNode;
171
- /** Optional footer status for the draft (e.g. a character counter). */
172
- footer?: (draft: string) => React.ReactNode;
173
- /**
174
- * Extra classes for the toggle button. It is absolutely positioned by
175
- * default and expects a `relative` ancestor; a host whose layout has a
176
- * better home for it can re-place it here.
177
- */
178
- toggleClassName?: string;
179
- }
180
-
181
- export function FullscreenFieldEditor({
182
- value,
183
- onCommit,
184
- label,
185
- testIdPrefix,
186
- disabled = false,
187
- children,
188
- footer,
189
- toggleClassName,
190
- }: FullscreenFieldEditorProps) {
191
- const { t } = useFieldTranslation();
192
- const [open, setOpen] = useState(false);
193
- const [draft, setDraft] = useState(value ?? '');
194
-
195
- const openFullscreen = () => {
196
- if (disabled) return;
197
- setDraft(value ?? '');
198
- setOpen(true);
199
- };
200
- const cancelFullscreen = () => setOpen(false);
201
- const commitFullscreen = () => {
202
- // THE gate: the one point where a value leaves this component for host
203
- // state. `disabled` can flip to true while this dialog is open (it carries
204
- // the form's `isSubmitting`), so this is checked here and not only on the
205
- // way in. Closing is unconditional — see "Cancel and Esc stay live" above.
206
- if (!disabled) onCommit(draft);
207
- setOpen(false);
208
- };
209
-
210
- return (
211
- <>
212
- <button
213
- type="button"
214
- onClick={openFullscreen}
215
- disabled={disabled}
216
- className={cn(
217
- 'absolute top-1.5 right-1.5 inline-flex items-center justify-center size-7 rounded-md bg-background/80 text-muted-foreground hover:text-foreground hover:bg-background border shadow-sm transition-colors',
218
- 'disabled:opacity-50 disabled:pointer-events-none',
219
- toggleClassName,
220
- )}
221
- aria-label={t('form.fullscreen.toggle', {
222
- label: label ?? t('form.fullscreen.textFallback'),
223
- })}
224
- data-testid={`${testIdPrefix}-fullscreen-toggle`}
225
- >
226
- <Maximize2 className="size-3.5" />
227
- </button>
228
-
229
- <Dialog open={open} onOpenChange={setOpen}>
230
- <DialogContent
231
- className="sm:max-w-3xl h-[100dvh] sm:h-[80vh] max-h-[100dvh] sm:max-h-[80vh] flex flex-col p-0 gap-0"
232
- data-testid={`${testIdPrefix}-fullscreen-dialog`}
233
- >
234
- <DialogHeader className="p-4 border-b">
235
- <DialogTitle className="text-base">{label ?? t('form.fullscreen.title')}</DialogTitle>
236
- {/*
237
- Parity with the built-in branch (`form.tsx`), which has carried
238
- this sr-only line since #3272. Without it Radix reports no
239
- `descriptionPresent` and omits `aria-describedby` altogether, so
240
- the registered path's dialog had no accessible description while
241
- the identical built-in one did — and `form.fullscreen.description`
242
- was a key with no consumer here. (The missing-Description console
243
- warning older Radix versions emitted is NOT why: @radix-ui/react-dialog
244
- 1.1.23 contains no `console.*` call at all, verified before adding this.)
245
- */}
246
- <DialogDescription className="sr-only">
247
- {t('form.fullscreen.description')}
248
- </DialogDescription>
249
- </DialogHeader>
250
- <div className="flex-1 min-h-0 p-4">{children(draft, setDraft, disabled)}</div>
251
- <DialogFooter className="p-3 border-t flex-row justify-between sm:justify-end gap-2">
252
- {footer?.(draft)}
253
- <div className="flex gap-2 ml-auto">
254
- <Button type="button" variant="ghost" onClick={cancelFullscreen}>
255
- <X className="size-4 mr-1" /> {t('common.cancel')}
256
- </Button>
257
- <Button
258
- type="button"
259
- onClick={commitFullscreen}
260
- disabled={disabled}
261
- data-testid={`${testIdPrefix}-fullscreen-save`}
262
- >
263
- <Check className="size-4 mr-1" /> {t('form.fullscreen.done')}
264
- </Button>
265
- </div>
266
- </DialogFooter>
267
- </DialogContent>
268
- </Dialog>
269
- </>
270
- );
271
- }
@@ -1,167 +0,0 @@
1
- import React, { useId } from 'react';
2
- import { Input, Button, Label, EmptyValue } from '@object-ui/components';
3
- import { MapPin, Crosshair } from 'lucide-react';
4
- import { FieldWidgetComponentProps } from './types';
5
- import { toDomProps } from './toDomProps';
6
-
7
- /**
8
- * Geolocation data structure
9
- */
10
- export interface GeolocationValue {
11
- latitude?: number;
12
- longitude?: number;
13
- accuracy?: number;
14
- }
15
-
16
- /**
17
- * Geolocation field widget - provides a location picker with coordinates
18
- * Supports manual entry and browser geolocation API
19
- */
20
- export function GeolocationField({ value, onChange, field, readonly, error, ...props }: FieldWidgetComponentProps<GeolocationValue>) {
21
- const [isLoading, setIsLoading] = React.useState(false);
22
- const location = value || {};
23
- // DOM pass-through (objectui#3318): the whitelist spread goes onto the FIRST
24
- // sub-input (latitude); the composite's validation state goes onto BOTH
25
- // focusable sub-inputs via `aria-invalid={!!error}`.
26
- const domProps = toDomProps(props);
27
- // Sub-input ids (objectui#3343): `useId()` prefix + sub-field name — the
28
- // `groupId` paradigm of RadioField / CheckboxesField. Hardcoded literals
29
- // ("latitude" / "longitude") collide as soon as a form renders two
30
- // geolocation fields, and every label's htmlFor then resolves to the
31
- // FIRST match.
32
- const groupId = useId();
33
- const subId = (name: keyof GeolocationValue) => `${groupId}-${name}`;
34
-
35
- const handleFieldChange = (fieldName: keyof GeolocationValue, fieldValue: string) => {
36
- onChange({
37
- ...location,
38
- [fieldName]: fieldValue ? Number(fieldValue) : undefined,
39
- });
40
- };
41
-
42
- const getCurrentLocation = () => {
43
- if (!navigator.geolocation) {
44
- console.error('Geolocation is not supported by this browser');
45
- return;
46
- }
47
-
48
- setIsLoading(true);
49
- navigator.geolocation.getCurrentPosition(
50
- (position) => {
51
- onChange({
52
- latitude: position.coords.latitude,
53
- longitude: position.coords.longitude,
54
- accuracy: position.coords.accuracy,
55
- });
56
- setIsLoading(false);
57
- },
58
- (error) => {
59
- console.error('Error getting location:', error.message);
60
- setIsLoading(false);
61
- },
62
- {
63
- enableHighAccuracy: true,
64
- timeout: 5000,
65
- maximumAge: 0,
66
- }
67
- );
68
- };
69
-
70
- const formatLocation = (loc: GeolocationValue): string => {
71
- if (!loc.latitude || !loc.longitude) return '';
72
- return `${loc.latitude.toFixed(6)}, ${loc.longitude.toFixed(6)}`;
73
- };
74
-
75
- const openInMaps = () => {
76
- if (!location.latitude || !location.longitude) return;
77
- const url = `https://www.google.com/maps?q=${location.latitude},${location.longitude}`;
78
- window.open(url, '_blank');
79
- };
80
-
81
- if (readonly) {
82
- const formatted = formatLocation(location);
83
- return (
84
- <div className="flex items-center gap-2">
85
- <MapPin className="w-4 h-4 text-muted-foreground" />
86
- {formatted ? <span className="text-sm">{formatted}</span> : <EmptyValue />}
87
- {location.latitude && location.longitude && (
88
- <Button
89
- type="button"
90
- variant="link"
91
- size="sm"
92
- onClick={openInMaps}
93
- className="p-0 h-auto"
94
- >
95
- View on map
96
- </Button>
97
- )}
98
- </div>
99
- );
100
- }
101
-
102
- return (
103
- <div className="space-y-3">
104
- <div className="flex items-center gap-2">
105
- <Button
106
- type="button"
107
- variant="outline"
108
- size="sm"
109
- onClick={getCurrentLocation}
110
- disabled={readonly || isLoading}
111
- >
112
- <Crosshair className="w-4 h-4 mr-2" />
113
- {isLoading ? 'Getting location...' : 'Use Current Location'}
114
- </Button>
115
- {location.latitude && location.longitude && (
116
- <Button
117
- type="button"
118
- variant="link"
119
- size="sm"
120
- onClick={openInMaps}
121
- >
122
- <MapPin className="w-4 h-4 mr-2" />
123
- View on map
124
- </Button>
125
- )}
126
- </div>
127
-
128
- <div className="grid grid-cols-2 gap-3">
129
- <div>
130
- <Label htmlFor={subId('latitude')} className="text-xs">Latitude</Label>
131
- <Input
132
- {...domProps}
133
- id={subId('latitude')}
134
- type="number"
135
- value={location.latitude ?? ''}
136
- onChange={(e) => handleFieldChange('latitude', e.target.value)}
137
- placeholder="37.7749"
138
- disabled={readonly || props.disabled}
139
- step="any"
140
- className={props.className}
141
- aria-invalid={!!error}
142
- />
143
- </div>
144
-
145
- <div>
146
- <Label htmlFor={subId('longitude')} className="text-xs">Longitude</Label>
147
- <Input
148
- id={subId('longitude')}
149
- type="number"
150
- value={location.longitude ?? ''}
151
- onChange={(e) => handleFieldChange('longitude', e.target.value)}
152
- placeholder="-122.4194"
153
- disabled={readonly || props.disabled}
154
- step="any"
155
- aria-invalid={!!error}
156
- />
157
- </div>
158
- </div>
159
-
160
- {location.accuracy && (
161
- <p className="text-xs text-muted-foreground">
162
- Accuracy: ±{location.accuracy.toFixed(0)}m
163
- </p>
164
- )}
165
- </div>
166
- );
167
- }
@@ -1,88 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- /**
10
- * Unique sub-input ids for the composite `geolocation` widget
11
- * (objectui#3343).
12
- *
13
- * The widget used to hardcode literal ids ("latitude" / "longitude") on its
14
- * sub-inputs. Two geolocation fields in one form — e.g. origin + destination
15
- * — then produced duplicate DOM ids, and every `Label htmlFor` resolved to
16
- * the FIRST match in the document: each sub-label of the second field
17
- * clicked/announced the first field's input.
18
- *
19
- * The fix follows the `groupId` paradigm of RadioField / CheckboxesField:
20
- * a `useId()` prefix + the sub-field name. These tests pin it by rendering
21
- * TWO instances in one form:
22
- *
23
- * 1. every `[id]` in the document is globally unique (red again if anyone
24
- * reverts to hardcoded literals — both instances would emit
25
- * id="latitude");
26
- * 2. each sub-label of the SECOND instance resolves — via the exact
27
- * mechanism browsers use for label activation, `for` → getElementById —
28
- * to an input inside its OWN instance, and focusing it lands there.
29
- */
30
- import { describe, it, expect, vi } from 'vitest';
31
- import React from 'react';
32
- import { render, within } from '@testing-library/react';
33
- import '@testing-library/jest-dom';
34
- import { GeolocationField } from './GeolocationField';
35
-
36
- const field = { name: 'location', type: 'geolocation' } as any;
37
-
38
- const SUB_LABELS = ['Latitude', 'Longitude'];
39
-
40
- function renderTwoInOneForm() {
41
- return render(
42
- <form>
43
- <div data-testid="geo-a">
44
- <GeolocationField value={{}} onChange={vi.fn()} field={field} />
45
- </div>
46
- <div data-testid="geo-b">
47
- <GeolocationField value={{}} onChange={vi.fn()} field={field} />
48
- </div>
49
- </form>,
50
- );
51
- }
52
-
53
- describe('GeolocationField — unique sub-input ids (objectui#3343)', () => {
54
- it('two geolocation fields in one form produce globally unique DOM ids', () => {
55
- const { baseElement } = renderTwoInOneForm();
56
- const ids = Array.from(baseElement.querySelectorAll('[id]')).map((el) => el.id);
57
- // 2 sub-inputs per instance — both instances must actually render ids.
58
- expect(ids.length).toBeGreaterThanOrEqual(4);
59
- const duplicates = ids.filter((id, i) => ids.indexOf(id) !== i);
60
- expect(duplicates).toEqual([]);
61
- });
62
-
63
- it("each sub-label of the SECOND field focuses that field's own input", () => {
64
- const { getByTestId } = renderTwoInOneForm();
65
- const first = getByTestId('geo-a');
66
- const second = getByTestId('geo-b');
67
-
68
- for (const text of SUB_LABELS) {
69
- const label = within(second).getByText(text);
70
- const forId = label.getAttribute('for');
71
- expect(forId, `label "${text}" must carry htmlFor`).toBeTruthy();
72
-
73
- // Exactly what the browser does on label click / SR announcement:
74
- // resolve `for` against the document.
75
- const control = document.getElementById(forId!);
76
- expect(control, `htmlFor of "${text}" must resolve`).not.toBeNull();
77
- expect(control!.tagName).toBe('INPUT');
78
- expect(
79
- second.contains(control),
80
- `"${text}" must resolve into its OWN field, not the first one`,
81
- ).toBe(true);
82
- expect(first.contains(control)).toBe(false);
83
-
84
- (control as HTMLInputElement).focus();
85
- expect(control).toHaveFocus();
86
- }
87
- });
88
- });