@muraldevkit/ui-toolkit 4.75.0 → 4.76.1-dev-aD33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/cjs/components/file-upload/MrlFileUpload/MrlFileUpload.js +404 -0
  2. package/dist/cjs/components/file-upload/MrlFileUpload/MrlFileUpload.js.map +1 -0
  3. package/dist/cjs/components/file-upload/MrlFileUpload/MrlFileUpload.module.scss.js +8 -0
  4. package/dist/cjs/components/file-upload/MrlFileUpload/MrlFileUpload.module.scss.js.map +1 -0
  5. package/dist/cjs/components/file-upload/constants.js +48 -0
  6. package/dist/cjs/components/file-upload/constants.js.map +1 -0
  7. package/dist/cjs/components/file-upload/helpers.js +67 -0
  8. package/dist/cjs/components/file-upload/helpers.js.map +1 -0
  9. package/dist/cjs/components/grid/MrlCol/MrlCol.js +58 -55
  10. package/dist/cjs/components/grid/MrlCol/MrlCol.js.map +1 -1
  11. package/dist/cjs/components/grid/MrlGrid/MrlGrid.js +4 -6
  12. package/dist/cjs/components/grid/MrlGrid/MrlGrid.js.map +1 -1
  13. package/dist/cjs/components/grid/MrlRow/MrlRow.js +10 -8
  14. package/dist/cjs/components/grid/MrlRow/MrlRow.js.map +1 -1
  15. package/dist/cjs/components/grid/constants.js +47 -9
  16. package/dist/cjs/components/grid/constants.js.map +1 -1
  17. package/dist/cjs/index.js +37 -31
  18. package/dist/cjs/index.js.map +1 -1
  19. package/dist/cjs/version.js +1 -1
  20. package/dist/cjs/version.js.map +1 -1
  21. package/dist/components/file-upload/MrlFileUpload/MrlFileUpload.d.ts +154 -0
  22. package/dist/components/file-upload/MrlFileUpload/index.d.ts +1 -0
  23. package/dist/components/file-upload/constants.d.ts +35 -0
  24. package/dist/components/file-upload/helpers.d.ts +35 -0
  25. package/dist/components/file-upload/index.d.ts +2 -0
  26. package/dist/components/grid/MrlCol/MrlCol.d.ts +4 -6
  27. package/dist/components/grid/MrlCol/index.d.ts +1 -1
  28. package/dist/components/grid/MrlGrid/MrlGrid.d.ts +5 -5
  29. package/dist/components/grid/MrlGrid/index.d.ts +1 -1
  30. package/dist/components/grid/MrlRow/MrlRow.d.ts +7 -7
  31. package/dist/components/grid/MrlRow/index.d.ts +1 -1
  32. package/dist/components/grid/constants.d.ts +52 -12
  33. package/dist/components/grid/index.d.ts +1 -0
  34. package/dist/components/index.d.ts +1 -0
  35. package/dist/esm/components/file-upload/MrlFileUpload/MrlFileUpload.js +379 -0
  36. package/dist/esm/components/file-upload/MrlFileUpload/MrlFileUpload.js.map +1 -0
  37. package/dist/esm/components/file-upload/MrlFileUpload/MrlFileUpload.module.scss.js +4 -0
  38. package/dist/esm/components/file-upload/MrlFileUpload/MrlFileUpload.module.scss.js.map +1 -0
  39. package/dist/esm/components/file-upload/constants.js +44 -0
  40. package/dist/esm/components/file-upload/constants.js.map +1 -0
  41. package/dist/esm/components/file-upload/helpers.js +62 -0
  42. package/dist/esm/components/file-upload/helpers.js.map +1 -0
  43. package/dist/esm/components/grid/MrlCol/MrlCol.js +59 -56
  44. package/dist/esm/components/grid/MrlCol/MrlCol.js.map +1 -1
  45. package/dist/esm/components/grid/MrlGrid/MrlGrid.js +4 -6
  46. package/dist/esm/components/grid/MrlGrid/MrlGrid.js.map +1 -1
  47. package/dist/esm/components/grid/MrlRow/MrlRow.js +10 -8
  48. package/dist/esm/components/grid/MrlRow/MrlRow.js.map +1 -1
  49. package/dist/esm/components/grid/constants.js +46 -9
  50. package/dist/esm/components/grid/constants.js.map +1 -1
  51. package/dist/esm/index.js +2 -0
  52. package/dist/esm/index.js.map +1 -1
  53. package/dist/esm/version.js +1 -1
  54. package/dist/esm/version.js.map +1 -1
  55. package/dist/styles/MrlFileUpload/module.scss +136 -0
  56. package/dist/styles/MrlSidebar/module.scss +2 -2
  57. package/dist/styles/file-upload/variables.scss +13 -0
  58. package/dist/styles/grid/global.scss +97 -2
  59. package/dist/styles.css +2 -7
  60. package/dist/types/components/file-upload/MrlFileUpload/MrlFileUpload.d.ts +154 -0
  61. package/dist/types/components/file-upload/MrlFileUpload/index.d.ts +1 -0
  62. package/dist/types/components/file-upload/constants.d.ts +35 -0
  63. package/dist/types/components/file-upload/helpers.d.ts +35 -0
  64. package/dist/types/components/file-upload/index.d.ts +2 -0
  65. package/dist/types/components/grid/MrlCol/MrlCol.d.ts +4 -6
  66. package/dist/types/components/grid/MrlCol/index.d.ts +1 -1
  67. package/dist/types/components/grid/MrlGrid/MrlGrid.d.ts +5 -5
  68. package/dist/types/components/grid/MrlGrid/index.d.ts +1 -1
  69. package/dist/types/components/grid/MrlRow/MrlRow.d.ts +7 -7
  70. package/dist/types/components/grid/MrlRow/index.d.ts +1 -1
  71. package/dist/types/components/grid/constants.d.ts +52 -12
  72. package/dist/types/components/grid/index.d.ts +1 -0
  73. package/dist/types/components/index.d.ts +1 -0
  74. package/package.json +1 -1
  75. package/dist/styles/grid/variables.scss +0 -26
@@ -0,0 +1,404 @@
1
+ 'use strict';
2
+
3
+ var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
4
+ var React = require('react');
5
+ var classnames = require('classnames');
6
+ var dsIcons = require('@muraldevkit/ds-icons');
7
+ var MrlButton = require('../../button/MrlButton/MrlButton.js');
8
+ var MrlInlineMessage = require('../../notification/MrlInlineMessage/MrlInlineMessage.js');
9
+ var MrlLiveRegion = require('../../live-region/MrlLiveRegion/MrlLiveRegion.js');
10
+ var MrlProgressBar = require('../../loader/MrlProgressBar/MrlProgressBar.js');
11
+ var MrlSvg = require('../../svg/MrlSvg/MrlSvg.js');
12
+ var MrlText = require('../../text/MrlText/MrlText.js');
13
+ var constants = require('../constants.js');
14
+ var helpers = require('../helpers.js');
15
+ var MrlFileUpload_module = require('./MrlFileUpload.module.scss.js');
16
+ var useMrlAnalytics = require('../../../hooks/useMrlAnalytics/useMrlAnalytics.js');
17
+
18
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
19
+
20
+ function _interopNamespace(e) {
21
+ if (e && e.__esModule) return e;
22
+ var n = Object.create(null);
23
+ if (e) {
24
+ Object.keys(e).forEach(function (k) {
25
+ if (k !== 'default') {
26
+ var d = Object.getOwnPropertyDescriptor(e, k);
27
+ Object.defineProperty(n, k, d.get ? d : {
28
+ enumerable: true,
29
+ get: function () { return e[k]; }
30
+ });
31
+ }
32
+ });
33
+ }
34
+ n.default = e;
35
+ return Object.freeze(n);
36
+ }
37
+
38
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
39
+ var classnames__default = /*#__PURE__*/_interopDefault(classnames);
40
+
41
+ var _excluded = ["accept", "className", "errorMessage", "eventId", "fileName", "heading", "helperText", "label", "maxSizeBytes", "onCancel", "onError", "onFilesSelected", "onRemove", "percent", "showHelperText", "showInlineAlert", "state", "validate", "data-qa"];
42
+
43
+ /**
44
+ * The resting half of the state contract: anything but a reported failure.
45
+ */
46
+
47
+ /**
48
+ * The failure half: reporting an error means saying what went wrong.
49
+ */
50
+
51
+ /**
52
+ * The zone's state and, when it reports a failure, the message that explains it.
53
+ *
54
+ * The two are a union rather than two independent props so that `state="error"`
55
+ * without an `errorMessage` does not compile. An errored zone with no text is
56
+ * signalled by border colour alone, which reaches neither assistive technology
57
+ * nor anyone who cannot distinguish the error hue. A consumer holding the state
58
+ * in a variable typed as the whole union has to narrow it before rendering —
59
+ * that is the point, not an accident.
60
+ */
61
+
62
+ /**
63
+ * A drag-and-drop file upload zone with a keyboard-accessible browse button.
64
+ *
65
+ * The component owns presentation, drag tracking and local validation
66
+ * (`accept`, `maxSizeBytes`); the consumer owns the upload itself and drives
67
+ * `state` and `percent`. Drag and drop is pointer-only by nature, so the
68
+ * button inside the zone is the equivalent path for everyone else and is the
69
+ * affordance exposed to the accessibility tree.
70
+ *
71
+ * @param props - The component props.
72
+ * @returns The MrlFileUpload component.
73
+ */
74
+ function MrlFileUpload(props) {
75
+ var _ref, _ref2;
76
+ var _props$accept = props.accept,
77
+ accept = _props$accept === void 0 ? constants.fileUploadDefaults.accept : _props$accept,
78
+ className = props.className,
79
+ errorMessage = props.errorMessage,
80
+ eventId = props.eventId,
81
+ fileName = props.fileName,
82
+ _props$heading = props.heading,
83
+ heading = _props$heading === void 0 ? constants.fileUploadDefaults.heading : _props$heading,
84
+ helperText = props.helperText,
85
+ label = props.label,
86
+ maxSizeBytes = props.maxSizeBytes,
87
+ onCancel = props.onCancel,
88
+ onError = props.onError,
89
+ onFilesSelected = props.onFilesSelected,
90
+ onRemove = props.onRemove,
91
+ _props$percent = props.percent,
92
+ percent = _props$percent === void 0 ? 0 : _props$percent,
93
+ _props$showHelperText = props.showHelperText,
94
+ showHelperText = _props$showHelperText === void 0 ? constants.fileUploadDefaults.showHelperText : _props$showHelperText,
95
+ _props$showInlineAler = props.showInlineAlert,
96
+ showInlineAlert = _props$showInlineAler === void 0 ? constants.fileUploadDefaults.showInlineAlert : _props$showInlineAler,
97
+ _props$state = props.state,
98
+ state = _props$state === void 0 ? constants.fileUploadDefaults.state : _props$state,
99
+ validate = props.validate,
100
+ dataQa = props['data-qa'],
101
+ rest = _rollupPluginBabelHelpers.objectWithoutProperties(props, _excluded);
102
+ var _React$useState = React__namespace.useState(false),
103
+ _React$useState2 = _rollupPluginBabelHelpers.slicedToArray(_React$useState, 2),
104
+ isDragging = _React$useState2[0],
105
+ setIsDragging = _React$useState2[1];
106
+ var _React$useState3 = React__namespace.useState(null),
107
+ _React$useState4 = _rollupPluginBabelHelpers.slicedToArray(_React$useState3, 2),
108
+ validationError = _React$useState4[0],
109
+ setValidationError = _React$useState4[1];
110
+ var _React$useState5 = React__namespace.useState(null),
111
+ _React$useState6 = _rollupPluginBabelHelpers.slicedToArray(_React$useState5, 2),
112
+ selectedName = _React$useState6[0],
113
+ setSelectedName = _React$useState6[1];
114
+ var inputRef = React__namespace.useRef(null);
115
+ // The action button of whichever view is showing — Browse, Cancel or Remove.
116
+ var actionRef = React__namespace.useRef(null);
117
+ // Armed when an interaction puts focus on that button, so the next view swap
118
+ // can hand it back rather than dropping it.
119
+ var shouldRestoreFocus = React__namespace.useRef(false);
120
+ // dragenter/dragleave fire for descendants too; counting keeps the state stable.
121
+ var dragDepth = React__namespace.useRef(0);
122
+ var reactId = React__namespace.useId();
123
+ var labelId = "".concat(reactId, "-label");
124
+ var messageId = "".concat(reactId, "-message");
125
+ var trackInteraction = useMrlAnalytics.useMrlTrackInteraction('MrlFileUpload', eventId);
126
+ var isDisabled = state === 'disabled';
127
+ // A failed local validation outranks the consumer's state: no upload started.
128
+ // A disabled zone outranks both — it cannot have accepted a file.
129
+ var effectiveState = isDisabled ? 'disabled' : validationError ? 'error' : state;
130
+ var displayName = (_ref = fileName !== null && fileName !== void 0 ? fileName : selectedName) !== null && _ref !== void 0 ? _ref : '';
131
+ var displayError = (_ref2 = validationError !== null && validationError !== void 0 ? validationError : errorMessage) !== null && _ref2 !== void 0 ? _ref2 : null;
132
+ // An errored zone always carries text. The types forbid reporting 'error'
133
+ // without a message, but a JavaScript consumer can still reach it, and colour
134
+ // alone reaches neither assistive technology nor anyone who cannot see the hue.
135
+ var resolvedError = effectiveState === 'error' ? displayError !== null && displayError !== void 0 ? displayError : constants.DEFAULT_ERROR_MESSAGE : displayError;
136
+ // Derived rather than defaulted, so the copy cannot contradict what validation
137
+ // enforces — and so the size limit is stated before it rejects anyone.
138
+ var resolvedHelperText = helperText !== null && helperText !== void 0 ? helperText : helpers.describeConstraints(accept, maxSizeBytes);
139
+ var isBusy = effectiveState === 'uploading';
140
+
141
+ /**
142
+ * Validates a file — against `accept` and `maxSizeBytes`, then against the
143
+ * consumer's own `validate` — and hands it over, or reports why it was
144
+ * rejected. Emits exactly one analytics event per selection.
145
+ *
146
+ * @param file - the file the user chose or dropped
147
+ * @param source - how the file arrived, for analytics only
148
+ */
149
+ var acceptFile = React__namespace.useCallback((file, source) => {
150
+ if (!file) return;
151
+ var rejection = null;
152
+ if (!helpers.isAccepted(file, accept)) {
153
+ // The rule that rejected the file is the only reliable source for what
154
+ // would be accepted; a hand-written list drifts away from `accept`.
155
+ var types = helpers.formatAcceptList(accept);
156
+ rejection = types ? "File type is not valid. Accepted types: ".concat(types) : 'File type is not valid';
157
+ } else if (maxSizeBytes !== undefined && file.size > maxSizeBytes) {
158
+ rejection = "File is larger than ".concat(helpers.formatBytes(maxSizeBytes));
159
+ } else {
160
+ var _validate;
161
+ // The consumer's rules run last, so a file that fails the component's
162
+ // own checks never reaches them.
163
+ rejection = (_validate = validate === null || validate === void 0 ? void 0 : validate(file)) !== null && _validate !== void 0 ? _validate : null;
164
+ }
165
+
166
+ // The file's name, size and type are consumer data and are never emitted.
167
+ trackInteraction({
168
+ action: 'select',
169
+ metadata: {
170
+ outcome: rejection ? 'rejected' : 'accepted',
171
+ source
172
+ }
173
+ });
174
+ if (rejection) {
175
+ setSelectedName(file.name);
176
+ setValidationError(rejection);
177
+ onError === null || onError === void 0 ? void 0 : onError(rejection, file);
178
+ return;
179
+ }
180
+ setSelectedName(file.name);
181
+ setValidationError(null);
182
+ // A browse selection leaves focus on the Browse button, which the consumer
183
+ // is about to unmount by moving to 'uploading'. A drop does not: it is
184
+ // pointer-only, and focus was never in the zone to begin with.
185
+ if (source === 'browse') shouldRestoreFocus.current = true;
186
+ onFilesSelected === null || onFilesSelected === void 0 ? void 0 : onFilesSelected(file);
187
+ }, [accept, maxSizeBytes, onError, onFilesSelected, trackInteraction, validate]);
188
+
189
+ /**
190
+ * Returns the zone to its resting state and clears the native input so the
191
+ * same file can be chosen again.
192
+ */
193
+ var reset = React__namespace.useCallback(() => {
194
+ dragDepth.current = 0;
195
+ setIsDragging(false);
196
+ setSelectedName(null);
197
+ setValidationError(null);
198
+ if (inputRef.current) inputRef.current.value = '';
199
+ }, []);
200
+ var handleBrowse = React__namespace.useCallback(() => {
201
+ var _inputRef$current;
202
+ if (isDisabled) return;
203
+ (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.click();
204
+ }, [isDisabled]);
205
+ var handleCancel = React__namespace.useCallback(() => {
206
+ if (isDisabled) return;
207
+ shouldRestoreFocus.current = true;
208
+ trackInteraction({
209
+ action: 'click',
210
+ metadata: {
211
+ control: 'cancel'
212
+ }
213
+ });
214
+ reset();
215
+ onCancel === null || onCancel === void 0 ? void 0 : onCancel();
216
+ }, [isDisabled, onCancel, reset, trackInteraction]);
217
+ var handleRemove = React__namespace.useCallback(() => {
218
+ if (isDisabled) return;
219
+ shouldRestoreFocus.current = true;
220
+ trackInteraction({
221
+ action: 'clear',
222
+ metadata: {
223
+ control: 'remove'
224
+ }
225
+ });
226
+ reset();
227
+ onRemove === null || onRemove === void 0 ? void 0 : onRemove();
228
+ }, [isDisabled, onRemove, reset, trackInteraction]);
229
+ var handleDragEnter = React__namespace.useCallback(event => {
230
+ if (isDisabled || isBusy) return;
231
+ event.preventDefault();
232
+ dragDepth.current += 1;
233
+ setIsDragging(true);
234
+ }, [isDisabled, isBusy]);
235
+ var handleDragOver = React__namespace.useCallback(event => {
236
+ if (isDisabled || isBusy) return;
237
+ // Required, or the browser treats the drop as navigation and opens the file.
238
+ event.preventDefault();
239
+ event.dataTransfer.dropEffect = 'copy';
240
+ }, [isDisabled, isBusy]);
241
+ var handleDragLeave = React__namespace.useCallback(event => {
242
+ if (isDisabled || isBusy) return;
243
+ event.preventDefault();
244
+ dragDepth.current = Math.max(0, dragDepth.current - 1);
245
+ // Leaving without dropping restores the previous view rather than resetting,
246
+ // so a completed or errored zone is not cleared by a passing cursor.
247
+ if (dragDepth.current === 0) setIsDragging(false);
248
+ }, [isDisabled, isBusy]);
249
+ var handleDrop = React__namespace.useCallback(event => {
250
+ var _event$dataTransfer$f;
251
+ if (isDisabled || isBusy) return;
252
+ event.preventDefault();
253
+ dragDepth.current = 0;
254
+ setIsDragging(false);
255
+ acceptFile((_event$dataTransfer$f = event.dataTransfer.files) === null || _event$dataTransfer$f === void 0 ? void 0 : _event$dataTransfer$f[0], 'drop');
256
+ }, [acceptFile, isDisabled, isBusy]);
257
+ var handleInputChange = React__namespace.useCallback(event => {
258
+ var _event$target$files;
259
+ var file = (_event$target$files = event.target.files) === null || _event$target$files === void 0 ? void 0 : _event$target$files[0];
260
+ // Cleared before validating: the native control fires `change` only when
261
+ // the selection changes, so re-picking a corrected file would be silent.
262
+ event.target.value = '';
263
+ acceptFile(file, 'browse');
264
+ }, [acceptFile]);
265
+ var view = isDragging ? 'dragging' : effectiveState;
266
+
267
+ /*
268
+ * Each view renders its action button at a different position inside the zone,
269
+ * so React unmounts one and mounts another rather than reusing it, and the
270
+ * browser drops focus to the body — sending a keyboard user back to the top of
271
+ * the page mid-task. Hand focus to the button that replaced it, but only when
272
+ * it was genuinely lost: never take it from someone who has tabbed away.
273
+ */
274
+ React__namespace.useLayoutEffect(() => {
275
+ if (!shouldRestoreFocus.current) return;
276
+ var focusWasLost = !document.activeElement || document.activeElement === document.body;
277
+ shouldRestoreFocus.current = false;
278
+ if (focusWasLost) {
279
+ var _actionRef$current;
280
+ (_actionRef$current = actionRef.current) === null || _actionRef$current === void 0 ? void 0 : _actionRef$current.focus();
281
+ // Focus is inside the zone again, so keep the chain armed for the next
282
+ // swap — an upload the consumer completes on its own included.
283
+ shouldRestoreFocus.current = true;
284
+ }
285
+ }, [view]);
286
+
287
+ /* eslint-disable sort-keys */
288
+ var zoneClasses = classnames__default.default({
289
+ [MrlFileUpload_module.default['MrlFileUpload-zone']]: true,
290
+ 'MrlFileUpload-zone': true,
291
+ [MrlFileUpload_module.default["MrlFileUpload-zone--".concat(view)]]: view !== 'idle'
292
+ });
293
+ /* eslint-enable sort-keys */
294
+
295
+ var inlineKind = resolvedError ? 'error' : 'helper';
296
+ var inlineMessage = resolvedError !== null && resolvedError !== void 0 ? resolvedError : showInlineAlert ? resolvedHelperText : null;
297
+ var announcement = () => {
298
+ if (effectiveState === 'uploading') {
299
+ // Quantised to 10% steps. A live region queues announcements rather than
300
+ // replacing them, so narrating every tick buries 'upload successful'
301
+ // behind a backlog that is usually discarded before it is spoken.
302
+ var step = Math.floor(Math.round(percent) / 10) * 10;
303
+ return "Uploading ".concat(displayName, ", ").concat(step, "%");
304
+ }
305
+ if (effectiveState === 'complete') return "Upload of ".concat(displayName, " successful");
306
+ if (effectiveState === 'error' && resolvedError) {
307
+ // Prefixed with the file name so two failures for the same reason are two
308
+ // different strings: a live region re-set to the same text stays silent.
309
+ return displayName ? "".concat(displayName, ": ").concat(resolvedError) : resolvedError;
310
+ }
311
+ return '';
312
+ };
313
+ var restingContent = /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement("div", {
314
+ className: classnames__default.default(MrlFileUpload_module.default['MrlFileUpload-content'], 'MrlFileUpload-content')
315
+ }, /*#__PURE__*/React__namespace.createElement("p", {
316
+ className: classnames__default.default(MrlFileUpload_module.default['MrlFileUpload-heading'], 'MrlFileUpload-heading')
317
+ }, heading), showHelperText && resolvedHelperText && /*#__PURE__*/React__namespace.createElement(MrlText.MrlText, {
318
+ size: "small"
319
+ }, resolvedHelperText)), /*#__PURE__*/React__namespace.createElement(MrlButton.MrlButton, {
320
+ "aria-describedby": inlineMessage ? messageId : undefined,
321
+ kind: "secondary",
322
+ ref: actionRef,
323
+ size: "small",
324
+ state: isDisabled ? 'disabled' : 'default',
325
+ text: "Browse files",
326
+ onClick: handleBrowse
327
+ }));
328
+ return /*#__PURE__*/React__namespace.createElement("div", _rollupPluginBabelHelpers.extends({}, rest, {
329
+ "data-qa": dataQa,
330
+ className: classnames__default.default(MrlFileUpload_module.default['MrlFileUpload'], 'MrlFileUpload', className)
331
+ }), label && /*#__PURE__*/React__namespace.createElement("span", {
332
+ className: classnames__default.default(MrlFileUpload_module.default['MrlFileUpload-label'], 'MrlFileUpload-label'),
333
+ id: labelId
334
+ }, label), /*#__PURE__*/React__namespace.createElement("div", {
335
+ "aria-describedby": inlineMessage ? messageId : undefined,
336
+ "aria-disabled": isDisabled || undefined,
337
+ "aria-label": label ? undefined : heading,
338
+ "aria-labelledby": label ? labelId : undefined,
339
+ className: zoneClasses,
340
+ role: "group",
341
+ onDragEnter: handleDragEnter,
342
+ onDragLeave: handleDragLeave,
343
+ onDragOver: handleDragOver,
344
+ onDrop: handleDrop
345
+ }, (view === 'idle' || view === 'error' || view === 'disabled') && restingContent, view === 'dragging' && /*#__PURE__*/React__namespace.createElement("div", {
346
+ className: classnames__default.default(MrlFileUpload_module.default['MrlFileUpload-preloader'])
347
+ }, /*#__PURE__*/React__namespace.createElement(MrlSvg.MrlSvg, {
348
+ className: classnames__default.default(MrlFileUpload_module.default['MrlFileUpload-icon'], MrlFileUpload_module.default['MrlFileUpload-icon--accent']),
349
+ size: "auto",
350
+ svg: dsIcons.importIcon
351
+ }), /*#__PURE__*/React__namespace.createElement("p", {
352
+ className: classnames__default.default(MrlFileUpload_module.default['MrlFileUpload-heading'], MrlFileUpload_module.default['MrlFileUpload-heading--accent'])
353
+ }, "Drop your files")), view === 'uploading' && /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement("div", {
354
+ className: classnames__default.default(MrlFileUpload_module.default['MrlFileUpload-preloader'])
355
+ }, /*#__PURE__*/React__namespace.createElement("div", {
356
+ className: classnames__default.default(MrlFileUpload_module.default['MrlFileUpload-progress'])
357
+ }, /*#__PURE__*/React__namespace.createElement(MrlProgressBar.MrlProgressBar, {
358
+ name: "Uploading ".concat(displayName || 'file'),
359
+ percent: Math.round(percent)
360
+ })), /*#__PURE__*/React__namespace.createElement("p", {
361
+ className: classnames__default.default(MrlFileUpload_module.default['MrlFileUpload-heading'], MrlFileUpload_module.default['MrlFileUpload-heading--strong'])
362
+ }, "Uploading ", displayName)), /*#__PURE__*/React__namespace.createElement(MrlButton.MrlButton, {
363
+ "aria-describedby": inlineMessage ? messageId : undefined,
364
+ kind: "secondary",
365
+ ref: actionRef,
366
+ size: "small",
367
+ text: "Cancel",
368
+ onClick: handleCancel
369
+ })), view === 'complete' && /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement("div", {
370
+ className: classnames__default.default(MrlFileUpload_module.default['MrlFileUpload-preloader'])
371
+ }, /*#__PURE__*/React__namespace.createElement(MrlSvg.MrlSvg, {
372
+ className: classnames__default.default(MrlFileUpload_module.default['MrlFileUpload-icon'], MrlFileUpload_module.default['MrlFileUpload-icon--success']),
373
+ size: "auto",
374
+ svg: dsIcons.check
375
+ }), /*#__PURE__*/React__namespace.createElement("p", {
376
+ className: classnames__default.default(MrlFileUpload_module.default['MrlFileUpload-heading'], MrlFileUpload_module.default['MrlFileUpload-heading--strong'])
377
+ }, "Upload of ", displayName, " successful!")), /*#__PURE__*/React__namespace.createElement(MrlButton.MrlButton, {
378
+ "aria-describedby": inlineMessage ? messageId : undefined,
379
+ kind: "secondary",
380
+ ref: actionRef,
381
+ size: "small",
382
+ text: "Remove",
383
+ onClick: handleRemove
384
+ }))), inlineMessage && /*#__PURE__*/React__namespace.createElement(MrlInlineMessage.MrlInlineMessage, {
385
+ id: messageId,
386
+ kind: inlineKind,
387
+ message: inlineMessage
388
+ }), /*#__PURE__*/React__namespace.createElement("input", {
389
+ accept: accept || undefined,
390
+ "aria-hidden": "true",
391
+ className: classnames__default.default(MrlFileUpload_module.default['MrlFileUpload-input']),
392
+ disabled: isDisabled,
393
+ ref: inputRef,
394
+ tabIndex: -1,
395
+ type: "file",
396
+ onChange: handleInputChange
397
+ }), /*#__PURE__*/React__namespace.createElement(MrlLiveRegion.MrlLiveRegion, {
398
+ ariaLive: "polite",
399
+ srContent: announcement()
400
+ }));
401
+ }
402
+
403
+ exports.MrlFileUpload = MrlFileUpload;
404
+ //# sourceMappingURL=MrlFileUpload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MrlFileUpload.js","sources":["../../../../../src/components/file-upload/MrlFileUpload/MrlFileUpload.tsx"],"sourcesContent":["import * as React from 'react';\nimport classnames from 'classnames';\nimport { check, importIcon } from '@muraldevkit/ds-icons';\nimport { MrlButton } from '../../button/MrlButton/MrlButton';\nimport { MrlInlineMessage } from '../../notification/MrlInlineMessage/MrlInlineMessage';\nimport { MrlLiveRegion } from '../../live-region/MrlLiveRegion/MrlLiveRegion';\nimport { MrlProgressBar } from '../../loader/MrlProgressBar/MrlProgressBar';\nimport { MrlSvg } from '../../svg/MrlSvg/MrlSvg';\nimport { MrlText } from '../../text/MrlText/MrlText';\nimport { ProgressRange } from '../../loader/constants';\nimport { DataQa } from '../../../utils/dataQa';\nimport { useMrlTrackInteraction } from '../../../hooks/useMrlAnalytics';\nimport { DEFAULT_ERROR_MESSAGE, fileUploadDefaults, MrlFileUploadState } from '../constants';\nimport { describeConstraints, formatAcceptList, formatBytes, isAccepted } from '../helpers';\nimport styles from './MrlFileUpload.module.scss';\n\n/**\n * The resting half of the state contract: anything but a reported failure.\n */\ntype MrlFileUploadRestingProps = {\n\t/**\n\t * Message for a failure the consumer is not currently reporting — kept across\n\t * a retry, for instance. Rendered only in the error state.\n\t */\n\terrorMessage?: string;\n\t/**\n\t * The visual state of the zone, owned by the consumer. The component tracks\n\t * drag state and local validation itself, but never starts, advances or\n\t * completes an upload — pass 'uploading' with a `percent`, then 'complete'.\n\t * Reporting 'error' requires an `errorMessage`, so it lives in the other half\n\t * of this union.\n\t *\n\t * 'disabled' blocks all interaction: drag, drop and click handlers return\n\t * early rather than relying on `pointer-events` alone. Because it is a value\n\t * of this union rather than a separate flag, it replaces the lifecycle state\n\t * rather than composing with it — a zone cannot be disabled *and* report\n\t * progress at the same time.\n\t */\n\tstate?: Exclude<MrlFileUploadState, 'error'>;\n};\n\n/**\n * The failure half: reporting an error means saying what went wrong.\n */\ntype MrlFileUploadErrorProps = {\n\t/**\n\t * Why the upload failed. Required alongside `state=\"error\"`: the failure has\n\t * to reach people who cannot see the border colour.\n\t *\n\t * A retry that fails with the identical message is announced only once — a\n\t * live region re-set to the text it already holds says nothing, and the\n\t * component cannot tell a retry from a re-render. Pass through a non-error\n\t * state between attempts (back to 'idle', or 'uploading' while the retry is\n\t * in flight) so the second failure is a genuine change.\n\t */\n\terrorMessage: string;\n\t/**\n\t * Reports a failed upload. A local validation failure supplies its own\n\t * message and takes precedence over `errorMessage`.\n\t */\n\tstate: 'error';\n};\n\n/**\n * The zone's state and, when it reports a failure, the message that explains it.\n *\n * The two are a union rather than two independent props so that `state=\"error\"`\n * without an `errorMessage` does not compile. An errored zone with no text is\n * signalled by border colour alone, which reaches neither assistive technology\n * nor anyone who cannot distinguish the error hue. A consumer holding the state\n * in a variable typed as the whole union has to narrow it before rendering —\n * that is the point, not an accident.\n */\nexport type MrlFileUploadStateProps = MrlFileUploadRestingProps | MrlFileUploadErrorProps;\n\nexport type MrlFileUploadProps = {\n\t/**\n\t * Accepted file types, in the same format as the native `accept` attribute\n\t * (e.g. '.gif,.jpg,.jpeg,.png' or 'image/*'). Also enforced on drop, which\n\t * the native attribute does not cover.\n\t */\n\taccept?: string;\n\t/**\n\t * Name of the file being uploaded, shown in the progress and completed copy\n\t * and announced to assistive technology. Falls back to the name of the file\n\t * the user last selected.\n\t */\n\tfileName?: string;\n\t/**\n\t * Headline inside the drop zone.\n\t */\n\theading?: string;\n\t/**\n\t * Supporting line describing what is accepted.\n\t */\n\thelperText?: string;\n\t/**\n\t * Field label rendered above the drop zone, and the zone's accessible name.\n\t */\n\tlabel?: string;\n\t/**\n\t * Maximum accepted file size in bytes. Omit for no limit.\n\t */\n\tmaxSizeBytes?: number;\n\t/**\n\t * Fired when the user cancels an upload in progress. The consumer owns the\n\t * abort — the component only returns itself to its resting state.\n\t */\n\tonCancel?: () => void;\n\t/**\n\t * Fired when a file fails local validation, with the message shown to the\n\t * user. Transport failures are reported by the consumer through\n\t * `state=\"error\"` instead.\n\t */\n\tonError?: (message: string, file: File) => void;\n\t/**\n\t * Fired when a file passes validation and is ready to upload. The consumer\n\t * performs the upload and drives `state` and `percent` from its result.\n\t */\n\tonFilesSelected?: (file: File) => void;\n\t/**\n\t * Fired when the user removes a completed upload.\n\t */\n\tonRemove?: () => void;\n\t/**\n\t * Upload progress, 0–100. Only read while `state` is 'uploading'.\n\t */\n\tpercent?: ProgressRange;\n\t/**\n\t * Shows `helperText` inside the drop zone.\n\t */\n\tshowHelperText?: boolean;\n\t/**\n\t * Repeats `helperText` as an inline message below the drop zone. Off by\n\t * default — with `showHelperText` on, enabling both prints the same sentence\n\t * twice. A validation or upload error always renders below the zone\n\t * regardless of this flag.\n\t */\n\tshowInlineAlert?: boolean;\n\t/**\n\t * Additional validation, run after the built-in `accept` and `maxSizeBytes`\n\t * checks and only if those pass. Return a message to reject the file — it is\n\t * shown and reported exactly like a built-in failure — or `null` to accept it.\n\t */\n\tvalidate?: (file: File) => string | null;\n\t/**\n\t * Enables interaction tracking for this upload control. Provide a stable,\n\t * non-PII id (e.g. 'workspace-logo-upload'). When omitted, the component\n\t * emits no analytics.\n\t *\n\t * Note: file names, sizes and types are never emitted — only the fact of a\n\t * selection and whether it was accepted.\n\t */\n\teventId?: string;\n} & MrlFileUploadStateProps &\n\tOmit<React.ComponentPropsWithoutRef<'div'>, 'onError'> &\n\tDataQa;\n\n/**\n * A drag-and-drop file upload zone with a keyboard-accessible browse button.\n *\n * The component owns presentation, drag tracking and local validation\n * (`accept`, `maxSizeBytes`); the consumer owns the upload itself and drives\n * `state` and `percent`. Drag and drop is pointer-only by nature, so the\n * button inside the zone is the equivalent path for everyone else and is the\n * affordance exposed to the accessibility tree.\n *\n * @param props - The component props.\n * @returns The MrlFileUpload component.\n */\nexport function MrlFileUpload(props: MrlFileUploadProps): React.ReactElement {\n\tconst {\n\t\taccept = fileUploadDefaults.accept,\n\t\tclassName,\n\t\terrorMessage,\n\t\teventId,\n\t\tfileName,\n\t\theading = fileUploadDefaults.heading,\n\t\thelperText,\n\t\tlabel,\n\t\tmaxSizeBytes,\n\t\tonCancel,\n\t\tonError,\n\t\tonFilesSelected,\n\t\tonRemove,\n\t\tpercent = 0,\n\t\tshowHelperText = fileUploadDefaults.showHelperText,\n\t\tshowInlineAlert = fileUploadDefaults.showInlineAlert,\n\t\tstate = fileUploadDefaults.state,\n\t\tvalidate,\n\t\t['data-qa']: dataQa,\n\t\t...rest\n\t} = props;\n\n\tconst [isDragging, setIsDragging] = React.useState(false);\n\tconst [validationError, setValidationError] = React.useState<string | null>(null);\n\tconst [selectedName, setSelectedName] = React.useState<string | null>(null);\n\n\tconst inputRef = React.useRef<HTMLInputElement>(null);\n\t// The action button of whichever view is showing — Browse, Cancel or Remove.\n\tconst actionRef = React.useRef<HTMLButtonElement>(null);\n\t// Armed when an interaction puts focus on that button, so the next view swap\n\t// can hand it back rather than dropping it.\n\tconst shouldRestoreFocus = React.useRef(false);\n\t// dragenter/dragleave fire for descendants too; counting keeps the state stable.\n\tconst dragDepth = React.useRef(0);\n\n\tconst reactId = React.useId();\n\tconst labelId = `${reactId}-label`;\n\tconst messageId = `${reactId}-message`;\n\n\tconst trackInteraction = useMrlTrackInteraction('MrlFileUpload', eventId);\n\n\tconst isDisabled = state === 'disabled';\n\t// A failed local validation outranks the consumer's state: no upload started.\n\t// A disabled zone outranks both — it cannot have accepted a file.\n\tconst effectiveState: MrlFileUploadState = isDisabled\n\t\t? 'disabled'\n\t\t: validationError\n\t\t\t? 'error'\n\t\t\t: state;\n\tconst displayName = fileName ?? selectedName ?? '';\n\tconst displayError = validationError ?? errorMessage ?? null;\n\t// An errored zone always carries text. The types forbid reporting 'error'\n\t// without a message, but a JavaScript consumer can still reach it, and colour\n\t// alone reaches neither assistive technology nor anyone who cannot see the hue.\n\tconst resolvedError =\n\t\teffectiveState === 'error' ? (displayError ?? DEFAULT_ERROR_MESSAGE) : displayError;\n\t// Derived rather than defaulted, so the copy cannot contradict what validation\n\t// enforces — and so the size limit is stated before it rejects anyone.\n\tconst resolvedHelperText = helperText ?? describeConstraints(accept, maxSizeBytes);\n\tconst isBusy = effectiveState === 'uploading';\n\n\t/**\n\t * Validates a file — against `accept` and `maxSizeBytes`, then against the\n\t * consumer's own `validate` — and hands it over, or reports why it was\n\t * rejected. Emits exactly one analytics event per selection.\n\t *\n\t * @param file - the file the user chose or dropped\n\t * @param source - how the file arrived, for analytics only\n\t */\n\tconst acceptFile = React.useCallback(\n\t\t(file: File | undefined, source: 'browse' | 'drop') => {\n\t\t\tif (!file) return;\n\n\t\t\tlet rejection: string | null = null;\n\n\t\t\tif (!isAccepted(file, accept)) {\n\t\t\t\t// The rule that rejected the file is the only reliable source for what\n\t\t\t\t// would be accepted; a hand-written list drifts away from `accept`.\n\t\t\t\tconst types = formatAcceptList(accept);\n\t\t\t\trejection = types\n\t\t\t\t\t? `File type is not valid. Accepted types: ${types}`\n\t\t\t\t\t: 'File type is not valid';\n\t\t\t} else if (maxSizeBytes !== undefined && file.size > maxSizeBytes) {\n\t\t\t\trejection = `File is larger than ${formatBytes(maxSizeBytes)}`;\n\t\t\t} else {\n\t\t\t\t// The consumer's rules run last, so a file that fails the component's\n\t\t\t\t// own checks never reaches them.\n\t\t\t\trejection = validate?.(file) ?? null;\n\t\t\t}\n\n\t\t\t// The file's name, size and type are consumer data and are never emitted.\n\t\t\ttrackInteraction({\n\t\t\t\taction: 'select',\n\t\t\t\tmetadata: { outcome: rejection ? 'rejected' : 'accepted', source }\n\t\t\t});\n\n\t\t\tif (rejection) {\n\t\t\t\tsetSelectedName(file.name);\n\t\t\t\tsetValidationError(rejection);\n\t\t\t\tonError?.(rejection, file);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetSelectedName(file.name);\n\t\t\tsetValidationError(null);\n\t\t\t// A browse selection leaves focus on the Browse button, which the consumer\n\t\t\t// is about to unmount by moving to 'uploading'. A drop does not: it is\n\t\t\t// pointer-only, and focus was never in the zone to begin with.\n\t\t\tif (source === 'browse') shouldRestoreFocus.current = true;\n\t\t\tonFilesSelected?.(file);\n\t\t},\n\t\t[accept, maxSizeBytes, onError, onFilesSelected, trackInteraction, validate]\n\t);\n\n\t/**\n\t * Returns the zone to its resting state and clears the native input so the\n\t * same file can be chosen again.\n\t */\n\tconst reset = React.useCallback(() => {\n\t\tdragDepth.current = 0;\n\t\tsetIsDragging(false);\n\t\tsetSelectedName(null);\n\t\tsetValidationError(null);\n\t\tif (inputRef.current) inputRef.current.value = '';\n\t}, []);\n\n\tconst handleBrowse = React.useCallback(() => {\n\t\tif (isDisabled) return;\n\t\tinputRef.current?.click();\n\t}, [isDisabled]);\n\n\tconst handleCancel = React.useCallback(() => {\n\t\tif (isDisabled) return;\n\t\tshouldRestoreFocus.current = true;\n\t\ttrackInteraction({ action: 'click', metadata: { control: 'cancel' } });\n\t\treset();\n\t\tonCancel?.();\n\t}, [isDisabled, onCancel, reset, trackInteraction]);\n\n\tconst handleRemove = React.useCallback(() => {\n\t\tif (isDisabled) return;\n\t\tshouldRestoreFocus.current = true;\n\t\ttrackInteraction({ action: 'clear', metadata: { control: 'remove' } });\n\t\treset();\n\t\tonRemove?.();\n\t}, [isDisabled, onRemove, reset, trackInteraction]);\n\n\tconst handleDragEnter = React.useCallback(\n\t\t(event: React.DragEvent<HTMLDivElement>) => {\n\t\t\tif (isDisabled || isBusy) return;\n\t\t\tevent.preventDefault();\n\t\t\tdragDepth.current += 1;\n\t\t\tsetIsDragging(true);\n\t\t},\n\t\t[isDisabled, isBusy]\n\t);\n\n\tconst handleDragOver = React.useCallback(\n\t\t(event: React.DragEvent<HTMLDivElement>) => {\n\t\t\tif (isDisabled || isBusy) return;\n\t\t\t// Required, or the browser treats the drop as navigation and opens the file.\n\t\t\tevent.preventDefault();\n\t\t\tevent.dataTransfer.dropEffect = 'copy';\n\t\t},\n\t\t[isDisabled, isBusy]\n\t);\n\n\tconst handleDragLeave = React.useCallback(\n\t\t(event: React.DragEvent<HTMLDivElement>) => {\n\t\t\tif (isDisabled || isBusy) return;\n\t\t\tevent.preventDefault();\n\t\t\tdragDepth.current = Math.max(0, dragDepth.current - 1);\n\t\t\t// Leaving without dropping restores the previous view rather than resetting,\n\t\t\t// so a completed or errored zone is not cleared by a passing cursor.\n\t\t\tif (dragDepth.current === 0) setIsDragging(false);\n\t\t},\n\t\t[isDisabled, isBusy]\n\t);\n\n\tconst handleDrop = React.useCallback(\n\t\t(event: React.DragEvent<HTMLDivElement>) => {\n\t\t\tif (isDisabled || isBusy) return;\n\t\t\tevent.preventDefault();\n\t\t\tdragDepth.current = 0;\n\t\t\tsetIsDragging(false);\n\t\t\tacceptFile(event.dataTransfer.files?.[0], 'drop');\n\t\t},\n\t\t[acceptFile, isDisabled, isBusy]\n\t);\n\n\tconst handleInputChange = React.useCallback(\n\t\t(event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\tconst file = event.target.files?.[0];\n\t\t\t// Cleared before validating: the native control fires `change` only when\n\t\t\t// the selection changes, so re-picking a corrected file would be silent.\n\t\t\tevent.target.value = '';\n\t\t\tacceptFile(file, 'browse');\n\t\t},\n\t\t[acceptFile]\n\t);\n\n\tconst view = isDragging ? 'dragging' : effectiveState;\n\n\t/*\n\t * Each view renders its action button at a different position inside the zone,\n\t * so React unmounts one and mounts another rather than reusing it, and the\n\t * browser drops focus to the body — sending a keyboard user back to the top of\n\t * the page mid-task. Hand focus to the button that replaced it, but only when\n\t * it was genuinely lost: never take it from someone who has tabbed away.\n\t */\n\tReact.useLayoutEffect(() => {\n\t\tif (!shouldRestoreFocus.current) return;\n\n\t\tconst focusWasLost = !document.activeElement || document.activeElement === document.body;\n\t\tshouldRestoreFocus.current = false;\n\n\t\tif (focusWasLost) {\n\t\t\tactionRef.current?.focus();\n\t\t\t// Focus is inside the zone again, so keep the chain armed for the next\n\t\t\t// swap — an upload the consumer completes on its own included.\n\t\t\tshouldRestoreFocus.current = true;\n\t\t}\n\t}, [view]);\n\n\t/* eslint-disable sort-keys */\n\tconst zoneClasses = classnames({\n\t\t[styles['MrlFileUpload-zone']]: true,\n\t\t'MrlFileUpload-zone': true,\n\t\t[styles[`MrlFileUpload-zone--${view}`]]: view !== 'idle'\n\t});\n\t/* eslint-enable sort-keys */\n\n\tconst inlineKind = resolvedError ? 'error' : 'helper';\n\tconst inlineMessage = resolvedError ?? (showInlineAlert ? resolvedHelperText : null);\n\n\tconst announcement = () => {\n\t\tif (effectiveState === 'uploading') {\n\t\t\t// Quantised to 10% steps. A live region queues announcements rather than\n\t\t\t// replacing them, so narrating every tick buries 'upload successful'\n\t\t\t// behind a backlog that is usually discarded before it is spoken.\n\t\t\tconst step = Math.floor(Math.round(percent) / 10) * 10;\n\t\t\treturn `Uploading ${displayName}, ${step}%`;\n\t\t}\n\t\tif (effectiveState === 'complete') return `Upload of ${displayName} successful`;\n\t\tif (effectiveState === 'error' && resolvedError) {\n\t\t\t// Prefixed with the file name so two failures for the same reason are two\n\t\t\t// different strings: a live region re-set to the same text stays silent.\n\t\t\treturn displayName ? `${displayName}: ${resolvedError}` : resolvedError;\n\t\t}\n\t\treturn '';\n\t};\n\n\tconst restingContent = (\n\t\t<>\n\t\t\t<div className={classnames(styles['MrlFileUpload-content'], 'MrlFileUpload-content')}>\n\t\t\t\t<p className={classnames(styles['MrlFileUpload-heading'], 'MrlFileUpload-heading')}>\n\t\t\t\t\t{heading}\n\t\t\t\t</p>\n\t\t\t\t{showHelperText && resolvedHelperText && (\n\t\t\t\t\t<MrlText size=\"small\">{resolvedHelperText}</MrlText>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t\t<MrlButton\n\t\t\t\taria-describedby={inlineMessage ? messageId : undefined}\n\t\t\t\tkind=\"secondary\"\n\t\t\t\tref={actionRef}\n\t\t\t\tsize=\"small\"\n\t\t\t\tstate={isDisabled ? 'disabled' : 'default'}\n\t\t\t\ttext=\"Browse files\"\n\t\t\t\tonClick={handleBrowse}\n\t\t\t/>\n\t\t</>\n\t);\n\n\treturn (\n\t\t<div\n\t\t\t{...rest}\n\t\t\tdata-qa={dataQa}\n\t\t\tclassName={classnames(styles['MrlFileUpload'], 'MrlFileUpload', className)}\n\t\t>\n\t\t\t{label && (\n\t\t\t\t<span\n\t\t\t\t\tclassName={classnames(styles['MrlFileUpload-label'], 'MrlFileUpload-label')}\n\t\t\t\t\tid={labelId}\n\t\t\t\t>\n\t\t\t\t\t{label}\n\t\t\t\t</span>\n\t\t\t)}\n\n\t\t\t<div\n\t\t\t\taria-describedby={inlineMessage ? messageId : undefined}\n\t\t\t\taria-disabled={isDisabled || undefined}\n\t\t\t\taria-label={label ? undefined : heading}\n\t\t\t\taria-labelledby={label ? labelId : undefined}\n\t\t\t\tclassName={zoneClasses}\n\t\t\t\trole=\"group\"\n\t\t\t\tonDragEnter={handleDragEnter}\n\t\t\t\tonDragLeave={handleDragLeave}\n\t\t\t\tonDragOver={handleDragOver}\n\t\t\t\tonDrop={handleDrop}\n\t\t\t>\n\t\t\t\t{(view === 'idle' || view === 'error' || view === 'disabled') && restingContent}\n\n\t\t\t\t{view === 'dragging' && (\n\t\t\t\t\t<div className={classnames(styles['MrlFileUpload-preloader'])}>\n\t\t\t\t\t\t<MrlSvg\n\t\t\t\t\t\t\tclassName={classnames(\n\t\t\t\t\t\t\t\tstyles['MrlFileUpload-icon'],\n\t\t\t\t\t\t\t\tstyles['MrlFileUpload-icon--accent']\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\tsize=\"auto\"\n\t\t\t\t\t\t\tsvg={importIcon}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<p\n\t\t\t\t\t\t\tclassName={classnames(\n\t\t\t\t\t\t\t\tstyles['MrlFileUpload-heading'],\n\t\t\t\t\t\t\t\tstyles['MrlFileUpload-heading--accent']\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\tDrop your files\n\t\t\t\t\t\t</p>\n\t\t\t\t\t</div>\n\t\t\t\t)}\n\n\t\t\t\t{view === 'uploading' && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<div className={classnames(styles['MrlFileUpload-preloader'])}>\n\t\t\t\t\t\t\t<div className={classnames(styles['MrlFileUpload-progress'])}>\n\t\t\t\t\t\t\t\t<MrlProgressBar\n\t\t\t\t\t\t\t\t\tname={`Uploading ${displayName || 'file'}`}\n\t\t\t\t\t\t\t\t\tpercent={Math.round(percent) as ProgressRange}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\tclassName={classnames(\n\t\t\t\t\t\t\t\t\tstyles['MrlFileUpload-heading'],\n\t\t\t\t\t\t\t\t\tstyles['MrlFileUpload-heading--strong']\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tUploading {displayName}\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<MrlButton\n\t\t\t\t\t\t\taria-describedby={inlineMessage ? messageId : undefined}\n\t\t\t\t\t\t\tkind=\"secondary\"\n\t\t\t\t\t\t\tref={actionRef}\n\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\ttext=\"Cancel\"\n\t\t\t\t\t\t\tonClick={handleCancel}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t)}\n\n\t\t\t\t{view === 'complete' && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<div className={classnames(styles['MrlFileUpload-preloader'])}>\n\t\t\t\t\t\t\t<MrlSvg\n\t\t\t\t\t\t\t\tclassName={classnames(\n\t\t\t\t\t\t\t\t\tstyles['MrlFileUpload-icon'],\n\t\t\t\t\t\t\t\t\tstyles['MrlFileUpload-icon--success']\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\tsize=\"auto\"\n\t\t\t\t\t\t\t\tsvg={check}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\tclassName={classnames(\n\t\t\t\t\t\t\t\t\tstyles['MrlFileUpload-heading'],\n\t\t\t\t\t\t\t\t\tstyles['MrlFileUpload-heading--strong']\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tUpload of {displayName} successful!\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<MrlButton\n\t\t\t\t\t\t\taria-describedby={inlineMessage ? messageId : undefined}\n\t\t\t\t\t\t\tkind=\"secondary\"\n\t\t\t\t\t\t\tref={actionRef}\n\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\ttext=\"Remove\"\n\t\t\t\t\t\t\tonClick={handleRemove}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t)}\n\t\t\t</div>\n\n\t\t\t{inlineMessage && (\n\t\t\t\t<MrlInlineMessage id={messageId} kind={inlineKind} message={inlineMessage} />\n\t\t\t)}\n\n\t\t\t{/*\n\t\t\t * The real control, opened by the \"Browse files\" button. It is removed from\n\t\t\t * the tab order and the accessibility tree deliberately: the button is the\n\t\t\t * accessible affordance, and a focusable invisible input would be a keyboard\n\t\t\t * trap with no visible focus ring. Do not make it focusable.\n\t\t\t */}\n\t\t\t<input\n\t\t\t\taccept={accept || undefined}\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tclassName={classnames(styles['MrlFileUpload-input'])}\n\t\t\t\tdisabled={isDisabled}\n\t\t\t\tref={inputRef}\n\t\t\t\ttabIndex={-1}\n\t\t\t\ttype=\"file\"\n\t\t\t\tonChange={handleInputChange}\n\t\t\t/>\n\n\t\t\t<MrlLiveRegion ariaLive=\"polite\" srContent={announcement()} />\n\t\t</div>\n\t);\n}\n"],"names":["MrlFileUpload","props","_ref","_ref2","_props$accept","accept","fileUploadDefaults","className","errorMessage","eventId","fileName","_props$heading","heading","helperText","label","maxSizeBytes","onCancel","onError","onFilesSelected","onRemove","_props$percent","percent","_props$showHelperText","showHelperText","_props$showInlineAler","showInlineAlert","_props$state","state","validate","dataQa","rest","_objectWithoutProperties","_excluded","_React$useState","React","useState","_React$useState2","_slicedToArray","isDragging","setIsDragging","_React$useState3","_React$useState4","validationError","setValidationError","_React$useState5","_React$useState6","selectedName","setSelectedName","inputRef","useRef","actionRef","shouldRestoreFocus","dragDepth","reactId","useId","labelId","concat","messageId","trackInteraction","useMrlTrackInteraction","isDisabled","effectiveState","displayName","displayError","resolvedError","DEFAULT_ERROR_MESSAGE","resolvedHelperText","describeConstraints","isBusy","acceptFile","useCallback","file","source","rejection","isAccepted","types","formatAcceptList","undefined","size","formatBytes","_validate","action","metadata","outcome","name","current","reset","value","handleBrowse","_inputRef$current","click","handleCancel","control","handleRemove","handleDragEnter","event","preventDefault","handleDragOver","dataTransfer","dropEffect","handleDragLeave","Math","max","handleDrop","_event$dataTransfer$f","files","handleInputChange","_event$target$files","target","view","useLayoutEffect","focusWasLost","document","activeElement","body","_actionRef$current","focus","zoneClasses","classnames","styles","inlineKind","inlineMessage","announcement","step","floor","round","restingContent","createElement","Fragment","MrlText","MrlButton","kind","ref","text","onClick","_extends","id","role","onDragEnter","onDragLeave","onDragOver","onDrop","MrlSvg","svg","importIcon","MrlProgressBar","check","MrlInlineMessage","message","disabled","tabIndex","type","onChange","MrlLiveRegion","ariaLive","srContent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA;AACA;AACA;;AAuBA;AACA;AACA;;AAoBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAsFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,aAAaA,CAACC,KAAyB,EAAsB;EAAA,IAAAC,IAAA,EAAAC,KAAA;AAC5E,EAAA,IAAAC,aAAA,GAqBIH,KAAK,CApBRI,MAAM;AAANA,IAAAA,MAAM,GAAAD,aAAA,KAAA,MAAA,GAAGE,4BAAkB,CAACD,MAAM,GAAAD,aAAA;IAClCG,SAAS,GAmBNN,KAAK,CAnBRM,SAAS;IACTC,YAAY,GAkBTP,KAAK,CAlBRO,YAAY;IACZC,OAAO,GAiBJR,KAAK,CAjBRQ,OAAO;IACPC,QAAQ,GAgBLT,KAAK,CAhBRS,QAAQ;IAAAC,cAAA,GAgBLV,KAAK,CAfRW,OAAO;AAAPA,IAAAA,OAAO,GAAAD,cAAA,KAAA,MA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AE,EAAE/E,SAAU;AAAC0E,IAAAA,IAAI,EAAEX,UAAW;AAAC4B,IAAAA,OAAO,EAAE3B;AAAc,GAAE,CAC5E,eAQDvF,gBAAA,CAAA6F,aAAA,CAAA,OAAA,EAAA;IACC1H,MAAM,EAAEA,MAAM,IAAIwE,SAAU;AAC5B,IAAA,aAAA,EAAY,MAAM;AAClBtE,IAAAA,SAAS,EAAE+G,2BAAU,CAACC,4BAAM,CAAC,qBAAqB,CAAC,CAAE;AACrD8B,IAAAA,QAAQ,EAAEzF,UAAW;AACrBwE,IAAAA,GAAG,EAAEpF,QAAS;IACdsG,QAAQ,EAAE,EAAG;AACbC,IAAAA,IAAI,EAAC,MAAM;AACXC,IAAAA,QAAQ,EAAE9C;AAAkB,GAC5B,CAAC,eAEFxE,gBAAA,CAAA6F,aAAA,CAAC0B,2BAAa,EAAA;AAACC,IAAAA,QAAQ,EAAC,QAAQ;IAACC,SAAS,EAAEjC,YAAY;AAAG,GAAE,CACzD,CAAC;AAER;;;;"}
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var styles = {"MrlFileUpload":"MrlFileUpload--q42Jc","MrlFileUpload-label":"MrlFileUpload-label--fuqMG","MrlFileUpload-zone":"MrlFileUpload-zone--pB0EK","MrlFileUpload-zone--dragging":"MrlFileUpload-zone--dragging--aZBH2","MrlFileUpload-zone--uploading":"MrlFileUpload-zone--uploading--f0aUR","MrlFileUpload-zone--complete":"MrlFileUpload-zone--complete--HeuVL","MrlFileUpload-zone--error":"MrlFileUpload-zone--error--f5DIT","MrlFileUpload-zone--disabled":"MrlFileUpload-zone--disabled--UgSP5","MrlFileUpload-content":"MrlFileUpload-content--vybKc","MrlFileUpload-preloader":"MrlFileUpload-preloader--Aib44","MrlFileUpload-heading":"MrlFileUpload-heading--J4xnq","MrlFileUpload-heading--accent":"MrlFileUpload-heading--accent--UCQja","MrlFileUpload-heading--strong":"MrlFileUpload-heading--strong--FRgxv","MrlFileUpload-icon":"MrlFileUpload-icon--ZLxPa","MrlFileUpload-icon--accent":"MrlFileUpload-icon--accent--bav01","MrlFileUpload-icon--success":"MrlFileUpload-icon--success--G_dKs","MrlFileUpload-progress":"MrlFileUpload-progress--a6AlX","MrlFileUpload-input":"MrlFileUpload-input--GCD8R"};
6
+
7
+ exports.default = styles;
8
+ //# sourceMappingURL=MrlFileUpload.module.scss.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MrlFileUpload.module.scss.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * File upload component constants
5
+ * ------------------------------------------------------------------
6
+ */
7
+
8
+ var allowedFileUploadValues = {
9
+ states: ['idle', 'uploading', 'complete', 'error', 'disabled']
10
+ };
11
+
12
+ /**
13
+ * The visual state of the drop zone, owned by the consumer.
14
+ *
15
+ * `dragging` is deliberately absent — a drag is transient pointer state the
16
+ * component tracks internally, not a state a consumer can meaningfully set.
17
+ */
18
+
19
+ /**
20
+ * Default values for props on the MrlFileUpload component;
21
+ * shared between the component and Storybook.
22
+ *
23
+ * `helperText` is absent on purpose: with no value from the consumer it is
24
+ * derived from the constraints actually enforced, so the copy cannot drift from
25
+ * what `accept` and `maxSizeBytes` reject.
26
+ */
27
+ var fileUploadDefaults = {
28
+ accept: '.gif,.jpg,.jpeg,.png',
29
+ heading: 'Drop files here to upload',
30
+ showHelperText: true,
31
+ showInlineAlert: false,
32
+ state: 'idle'
33
+ };
34
+
35
+ /**
36
+ * Shown when a consumer reports `state="error"` without an `errorMessage`.
37
+ *
38
+ * The types make that combination impossible, but a JavaScript consumer can
39
+ * still reach it — and an errored zone with no text is signalled by border
40
+ * colour alone, which reaches neither assistive technology nor anyone who
41
+ * cannot distinguish the error hue.
42
+ */
43
+ var DEFAULT_ERROR_MESSAGE = 'Upload failed';
44
+
45
+ exports.DEFAULT_ERROR_MESSAGE = DEFAULT_ERROR_MESSAGE;
46
+ exports.allowedFileUploadValues = allowedFileUploadValues;
47
+ exports.fileUploadDefaults = fileUploadDefaults;
48
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sources":["../../../../src/components/file-upload/constants.ts"],"sourcesContent":["/*\n * File upload component constants\n * ------------------------------------------------------------------\n */\n\nexport const allowedFileUploadValues = {\n\tstates: ['idle', 'uploading', 'complete', 'error', 'disabled'] as const\n};\n\n/**\n * The visual state of the drop zone, owned by the consumer.\n *\n * `dragging` is deliberately absent — a drag is transient pointer state the\n * component tracks internally, not a state a consumer can meaningfully set.\n */\nexport type MrlFileUploadState = (typeof allowedFileUploadValues.states)[number];\n\nexport interface FileUploadDefaults {\n\taccept: string;\n\theading: string;\n\tshowHelperText: boolean;\n\tshowInlineAlert: boolean;\n\tstate: MrlFileUploadState;\n}\n\n/**\n * Default values for props on the MrlFileUpload component;\n * shared between the component and Storybook.\n *\n * `helperText` is absent on purpose: with no value from the consumer it is\n * derived from the constraints actually enforced, so the copy cannot drift from\n * what `accept` and `maxSizeBytes` reject.\n */\nexport const fileUploadDefaults: FileUploadDefaults = {\n\taccept: '.gif,.jpg,.jpeg,.png',\n\theading: 'Drop files here to upload',\n\tshowHelperText: true,\n\tshowInlineAlert: false,\n\tstate: 'idle'\n};\n\n/**\n * Shown when a consumer reports `state=\"error\"` without an `errorMessage`.\n *\n * The types make that combination impossible, but a JavaScript consumer can\n * still reach it — and an errored zone with no text is signalled by border\n * colour alone, which reaches neither assistive technology nor anyone who\n * cannot distinguish the error hue.\n */\nexport const DEFAULT_ERROR_MESSAGE = 'Upload failed';\n"],"names":["allowedFileUploadValues","states","fileUploadDefaults","accept","heading","showHelperText","showInlineAlert","state","DEFAULT_ERROR_MESSAGE"],"mappings":";;AAAA;AACA;AACA;AACA;;AAEO,IAAMA,uBAAuB,GAAG;EACtCC,MAAM,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU;AAC9D;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMC,kBAAsC,GAAG;AACrDC,EAAAA,MAAM,EAAE,sBAAsB;AAC9BC,EAAAA,OAAO,EAAE,2BAA2B;AACpCC,EAAAA,cAAc,EAAE,IAAI;AACpBC,EAAAA,eAAe,EAAE,KAAK;AACtBC,EAAAA,KAAK,EAAE;AACR;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMC,qBAAqB,GAAG;;;;;;"}
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Matches a file against an `accept` string (extensions and/or MIME types).
5
+ *
6
+ * The native `accept` attribute only filters the file picker; a dropped file
7
+ * bypasses it entirely, so the same rules have to be applied in code.
8
+ *
9
+ * @param file - the file to test
10
+ * @param accept - native `accept` syntax, e.g. '.png,image/*'
11
+ * @returns whether the file matches the accept rules
12
+ */
13
+ function isAccepted(file, accept) {
14
+ var rules = accept.split(',').map(rule => rule.trim().toLowerCase()).filter(Boolean);
15
+ if (rules.length === 0) return true;
16
+ var name = file.name.toLowerCase();
17
+ var type = file.type.toLowerCase();
18
+ return rules.some(rule => {
19
+ if (rule.startsWith('.')) return name.endsWith(rule);
20
+ if (rule.endsWith('/*')) return type.startsWith(rule.slice(0, -1));
21
+ return type === rule;
22
+ });
23
+ }
24
+
25
+ /**
26
+ * Formats a byte count for display in a validation message.
27
+ *
28
+ * @param bytes - the size in bytes
29
+ * @returns a short human-readable size, e.g. '2.5 MB'
30
+ */
31
+ function formatBytes(bytes) {
32
+ if (bytes < 1024) return "".concat(bytes, " B");
33
+ if (bytes < 1024 * 1024) return "".concat(Math.round(bytes / 1024), " KB");
34
+ return "".concat(Math.round(bytes / (1024 * 1024) * 10) / 10, " MB");
35
+ }
36
+
37
+ /**
38
+ * Lists the file types an `accept` string permits, for display.
39
+ *
40
+ * @param accept - native `accept` syntax, e.g. '.png,image/*'
41
+ * @returns a comma-separated list, or an empty string if nothing is restricted
42
+ */
43
+ function formatAcceptList(accept) {
44
+ return accept.split(',').map(rule => rule.trim()).filter(Boolean).join(', ');
45
+ }
46
+
47
+ /**
48
+ * Describes the constraints the component actually enforces, for use as helper
49
+ * text. Deriving the sentence from `accept` and `maxSizeBytes` is what keeps it
50
+ * from contradicting what validation rejects.
51
+ *
52
+ * @param accept - native `accept` syntax, e.g. '.png,image/*'
53
+ * @param maxSizeBytes - the size limit in bytes, if there is one
54
+ * @returns a sentence describing what may be uploaded, or an empty string
55
+ */
56
+ function describeConstraints(accept, maxSizeBytes) {
57
+ var types = formatAcceptList(accept);
58
+ var limit = maxSizeBytes !== undefined ? "up to ".concat(formatBytes(maxSizeBytes)) : '';
59
+ if (!types) return limit ? "Accepts any file ".concat(limit) : '';
60
+ return limit ? "Accepts ".concat(types, " ").concat(limit) : "Accepts ".concat(types);
61
+ }
62
+
63
+ exports.describeConstraints = describeConstraints;
64
+ exports.formatAcceptList = formatAcceptList;
65
+ exports.formatBytes = formatBytes;
66
+ exports.isAccepted = isAccepted;
67
+ //# sourceMappingURL=helpers.js.map