@verbb/formie-browser 1.0.17-next.8.g031176b155cf → 4.0.7
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.
- package/CHANGELOG.md +7 -0
- package/dist/chunks/{api-BR2Gqy37.js → api-DlW6054X.js} +3 -1
- package/dist/chunks/{bpoint-GvYfyPjD.js → bpoint-BKRpTj1e.js} +1 -1
- package/dist/chunks/{eway-BZuTBAUW.js → eway-9ZTEmiod.js} +1 -1
- package/dist/chunks/{file-upload-vEUr_EuP.js → file-upload-Bhxg5QZe.js} +2 -0
- package/dist/chunks/{go-cardless-DWZeB0Bq.js → go-cardless-BN096eDZ.js} +1 -1
- package/dist/chunks/{mollie-8OMXIYa8.js → mollie-DCBzpCmt.js} +1 -1
- package/dist/chunks/{moneris-qYHJ9EFy.js → moneris-CeryRRRJ.js} +1 -1
- package/dist/chunks/{opayo-DlWPEnla.js → opayo-D5cbEqJy.js} +1 -1
- package/dist/chunks/{paddle-CArfWih0.js → paddle-CDiiBCJ8.js} +1 -1
- package/dist/chunks/{paypal-BcaMCMGY.js → paypal-CA-kRKlJ.js} +1 -1
- package/dist/chunks/{payway-vxC7_bfR.js → payway-K9eUUMvk.js} +1 -1
- package/dist/chunks/{square-Dyz0p_GU.js → square-Bn6y1M0R.js} +1 -1
- package/dist/chunks/{stripe-Bfd_jp_k.js → stripe-CmzSSdMg.js} +1 -1
- package/dist/chunks/{upload-manager-CkmsPJRl.js → upload-manager-cGKWwGhu.js} +196 -192
- package/dist/css/formie-base.css +26 -26
- package/dist/css/theme-base/_primitives.css +9 -8
- package/dist/index.js +430 -422
- package/dist/js/core/create-formie-client.d.ts.map +1 -1
- package/dist/js/core/submit-result-state.d.ts.map +1 -1
- package/dist/js/core/validation-focus.d.ts +1 -0
- package/dist/js/core/validation-focus.d.ts.map +1 -1
- package/dist/js/modules/fields/file-upload.d.ts.map +1 -1
- package/dist/js/modules/fields/upload-manager.d.ts.map +1 -1
- package/package.json +4 -6
- package/src/css/formie-base.css +26 -26
- package/src/css/theme-base/_primitives.css +9 -8
- package/src/js/core/create-formie-client.ts +5 -0
- package/src/js/core/submit-result-state.ts +5 -0
- package/src/js/core/validation-focus.ts +40 -15
- package/src/js/modules/fields/file-upload.ts +7 -0
- package/src/js/modules/fields/upload-manager.ts +27 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-formie-client.d.ts","sourceRoot":"","sources":["../../../src/js/core/create-formie-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,YAAY,EAGf,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-formie-client.d.ts","sourceRoot":"","sources":["../../../src/js/core/create-formie-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,YAAY,EAGf,MAAM,mBAAmB,CAAC;AAk4B3B,wBAAgB,kBAAkB,IAAI,YAAY,CA+uBjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"submit-result-state.d.ts","sourceRoot":"","sources":["../../../src/js/core/submit-result-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAyH1D,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAqB/E;AA4GD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,eAAe,EAAE,SAAS,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,IAAI,CA0B5F;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAwB9D;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAkE9E;
|
|
1
|
+
{"version":3,"file":"submit-result-state.d.ts","sourceRoot":"","sources":["../../../src/js/core/submit-result-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAyH1D,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAqB/E;AA4GD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,eAAe,EAAE,SAAS,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,IAAI,CA0B5F;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAwB9D;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAkE9E;AA0LD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CA4GhH"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare function enhanceServerRenderedFieldErrors(form: HTMLFormElement): void;
|
|
2
2
|
export declare function hasServerRenderedValidationErrors(form: HTMLFormElement): boolean;
|
|
3
|
+
export declare function restoreLostValidationFocus(form: HTMLFormElement): void;
|
|
3
4
|
export declare function focusFirstValidationError(form: HTMLFormElement): boolean;
|
|
4
5
|
//# sourceMappingURL=validation-focus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation-focus.d.ts","sourceRoot":"","sources":["../../../src/js/core/validation-focus.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validation-focus.d.ts","sourceRoot":"","sources":["../../../src/js/core/validation-focus.ts"],"names":[],"mappings":"AA6DA,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CA4C5E;AAED,wBAAgB,iCAAiC,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAEhF;AAID,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAMtE;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAkCxE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-upload.d.ts","sourceRoot":"","sources":["../../../../src/js/modules/fields/file-upload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"file-upload.d.ts","sourceRoot":"","sources":["../../../../src/js/modules/fields/file-upload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAosBlE,eAAO,MAAM,gBAAgB,EAAE,uBAiE9B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-manager.d.ts","sourceRoot":"","sources":["../../../../src/js/modules/fields/upload-manager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"upload-manager.d.ts","sourceRoot":"","sources":["../../../../src/js/modules/fields/upload-manager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAm2ClE,eAAO,MAAM,mBAAmB,EAAE,uBAqFjC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verbb/formie-browser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -84,8 +84,7 @@
|
|
|
84
84
|
"./vite-dev": "./vite-dev.mjs"
|
|
85
85
|
},
|
|
86
86
|
"publishConfig": {
|
|
87
|
-
"access": "public"
|
|
88
|
-
"tag": "next"
|
|
87
|
+
"access": "public"
|
|
89
88
|
},
|
|
90
89
|
"scripts": {
|
|
91
90
|
"prebuild": "node ../../scripts/generate-browser-theme-state.mjs",
|
|
@@ -102,7 +101,7 @@
|
|
|
102
101
|
"@placekit/autocomplete-js": "^2.2.1",
|
|
103
102
|
"@uppy/core": "^5.2.0",
|
|
104
103
|
"@uppy/xhr-upload": "^5.2.0",
|
|
105
|
-
"@verbb/formie-core": "
|
|
104
|
+
"@verbb/formie-core": "4.0.7",
|
|
106
105
|
"expression-language": "^2.5.4",
|
|
107
106
|
"flatpickr": "^4.6.13",
|
|
108
107
|
"friendly-challenge": "^0.9.19",
|
|
@@ -111,6 +110,5 @@
|
|
|
111
110
|
"pell": "^1.0.6",
|
|
112
111
|
"signature_pad": "^5.1.3",
|
|
113
112
|
"tom-select": "^2.6.1"
|
|
114
|
-
}
|
|
115
|
-
"gitHead": "031176b155cf0bea732a19467f045adcc4f0ffec"
|
|
113
|
+
}
|
|
116
114
|
}
|
package/src/css/formie-base.css
CHANGED
|
@@ -2,53 +2,53 @@
|
|
|
2
2
|
|
|
3
3
|
@layer formie-base {
|
|
4
4
|
|
|
5
|
-
.formie-form,
|
|
6
|
-
.formie-form fieldset,
|
|
7
|
-
.formie-form legend,
|
|
8
|
-
.formie-form h1,
|
|
9
|
-
.formie-form h2,
|
|
10
|
-
.formie-form h3,
|
|
11
|
-
.formie-form h4,
|
|
12
|
-
.formie-form h5,
|
|
13
|
-
.formie-form h6,
|
|
14
|
-
.formie-form p,
|
|
15
|
-
.formie-form ul,
|
|
16
|
-
.formie-form ol,
|
|
17
|
-
.formie-form menu,
|
|
18
|
-
.formie-form dl,
|
|
19
|
-
.formie-form dd,
|
|
20
|
-
.formie-form blockquote,
|
|
21
|
-
.formie-form figure {
|
|
5
|
+
:where(.formie-form),
|
|
6
|
+
:where(.formie-form) fieldset,
|
|
7
|
+
:where(.formie-form) legend,
|
|
8
|
+
:where(.formie-form) h1,
|
|
9
|
+
:where(.formie-form) h2,
|
|
10
|
+
:where(.formie-form) h3,
|
|
11
|
+
:where(.formie-form) h4,
|
|
12
|
+
:where(.formie-form) h5,
|
|
13
|
+
:where(.formie-form) h6,
|
|
14
|
+
:where(.formie-form) p,
|
|
15
|
+
:where(.formie-form) ul,
|
|
16
|
+
:where(.formie-form) ol,
|
|
17
|
+
:where(.formie-form) menu,
|
|
18
|
+
:where(.formie-form) dl,
|
|
19
|
+
:where(.formie-form) dd,
|
|
20
|
+
:where(.formie-form) blockquote,
|
|
21
|
+
:where(.formie-form) figure {
|
|
22
22
|
margin: 0;
|
|
23
23
|
padding: 0;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
.formie-form,
|
|
27
|
-
.formie-form *,
|
|
28
|
-
.formie-form *::before,
|
|
29
|
-
.formie-form *::after {
|
|
26
|
+
:where(.formie-form),
|
|
27
|
+
:where(.formie-form) *,
|
|
28
|
+
:where(.formie-form) *::before,
|
|
29
|
+
:where(.formie-form) *::after {
|
|
30
30
|
box-sizing: border-box;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
.formie-page-container,
|
|
34
34
|
.formie-field-layout,
|
|
35
|
-
.formie-form fieldset,
|
|
36
|
-
.formie-form legend {
|
|
35
|
+
:where(.formie-form) fieldset,
|
|
36
|
+
:where(.formie-form) legend {
|
|
37
37
|
border: 0;
|
|
38
38
|
min-inline-size: 0;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/* Fix for Firefox display issue in fieldset */
|
|
42
|
-
body:not(:-moz-handler-blocked) .formie-form fieldset {
|
|
42
|
+
body:not(:-moz-handler-blocked) :where(.formie-form) fieldset {
|
|
43
43
|
display: table-cell;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
.formie-form legend {
|
|
46
|
+
:where(.formie-form) legend {
|
|
47
47
|
/* legend should be `display: contents` to work with grid */
|
|
48
48
|
display: contents;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
.formie-form legend * {
|
|
51
|
+
:where(.formie-form) legend * {
|
|
52
52
|
/* legend should be `display: contents` to work with grid */
|
|
53
53
|
display: contents;
|
|
54
54
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
@layer formie-theme-base {
|
|
2
|
-
.
|
|
3
|
-
.formie-form
|
|
4
|
-
.formie-form
|
|
5
|
-
.formie-form
|
|
6
|
-
.formie-form
|
|
7
|
-
.formie-form
|
|
2
|
+
/* Keep resets weaker than control classes when compiled without layers. */
|
|
3
|
+
:where(.formie-form) button,
|
|
4
|
+
:where(.formie-form) input,
|
|
5
|
+
:where(.formie-form) select,
|
|
6
|
+
:where(.formie-form) optgroup,
|
|
7
|
+
:where(.formie-form) textarea,
|
|
8
|
+
:where(.formie-form) ::file-selector-button {
|
|
8
9
|
margin: 0;
|
|
9
10
|
font: inherit;
|
|
10
11
|
font-feature-settings: inherit;
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
opacity: 1;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
.formie-form a,
|
|
21
|
+
:where(.formie-form) a,
|
|
21
22
|
.formie-link,
|
|
22
23
|
.formie-address-location {
|
|
23
24
|
color: var(--formie-color-primary);
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
transition: color 150ms ease;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
.formie-form a:hover,
|
|
30
|
+
:where(.formie-form) a:hover,
|
|
30
31
|
.formie-link:hover,
|
|
31
32
|
.formie-address-location:hover {
|
|
32
33
|
color: var(--formie-color-primary-hover);
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
enhanceServerRenderedFieldErrors,
|
|
21
21
|
focusFirstValidationError,
|
|
22
22
|
hasServerRenderedValidationErrors,
|
|
23
|
+
restoreLostValidationFocus,
|
|
23
24
|
} from '#core/validation-focus';
|
|
24
25
|
import { clearSubmitFeedback, executeAjaxSubmitFlow, shouldKeepSubmitLoading } from '#core/submit-flow';
|
|
25
26
|
import { applySubmitResultUi, renderFieldErrors, renderFormErrors } from '#core/submit-result-ui';
|
|
@@ -1327,6 +1328,10 @@ export function createFormieClient(): FormieClient {
|
|
|
1327
1328
|
unbindEventContext,
|
|
1328
1329
|
});
|
|
1329
1330
|
|
|
1331
|
+
if (form instanceof HTMLFormElement && normalizedOptions.mode === 'server-rendered' && hasServerRenderedValidationErrors(form)) {
|
|
1332
|
+
restoreLostValidationFocus(form);
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1330
1335
|
dispatchFormieDomEvent(target, 'formie:mount:after', {
|
|
1331
1336
|
id,
|
|
1332
1337
|
mode: normalizedOptions.mode as FormMode,
|
|
@@ -470,6 +470,11 @@ function resetSubmissionState(form: HTMLFormElement, options: ResetSubmissionSta
|
|
|
470
470
|
}
|
|
471
471
|
});
|
|
472
472
|
form.querySelectorAll('[data-formie-summary-blocks]').forEach((element) => element.replaceChildren());
|
|
473
|
+
// Upload modules on hidden pages are also unmounted. Clear their retained
|
|
474
|
+
// inputs and presentation before showing a page can hydrate the old files.
|
|
475
|
+
form.querySelectorAll('[data-formie-file-upload-entry]').forEach((element) => element.remove());
|
|
476
|
+
form.querySelectorAll('[data-formie-file-summary], [data-formie-upload-manager-list]').forEach((element) => element.replaceChildren());
|
|
477
|
+
form.querySelectorAll<HTMLInputElement>('[data-formie-upload-manager-status]').forEach((input) => { input.value = ''; });
|
|
473
478
|
if (!options.preserveHiddenState) {
|
|
474
479
|
setFormHiddenState(form, false);
|
|
475
480
|
}
|
|
@@ -26,22 +26,31 @@ function getVisibleControl(control: HTMLElement): HTMLElement {
|
|
|
26
26
|
return control;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
function findFocusableControl(nodes: Element[]): HTMLElement | null {
|
|
30
|
+
for (const node of nodes) {
|
|
31
|
+
const control = getVisibleControl(node as HTMLElement);
|
|
32
|
+
|
|
33
|
+
// Checkboxes and Agree put a hidden input first, and a searchable dropdown hides its
|
|
34
|
+
// select behind a search input. Focusing either does nothing, so keep looking.
|
|
35
|
+
if (!(control instanceof HTMLInputElement && control.type === 'hidden') && control.getClientRects().length > 0) {
|
|
36
|
+
return control;
|
|
37
|
+
}
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getFieldFocusTarget(field: HTMLElement): HTMLElement | null {
|
|
44
|
+
const invalidControls = Array.from(field.querySelectorAll('[aria-invalid="true"]')).filter((node) => {
|
|
41
45
|
return !isValidationSkipped(node);
|
|
42
|
-
})
|
|
46
|
+
});
|
|
43
47
|
|
|
44
|
-
|
|
48
|
+
// Fall back to any usable control. This includes a searchable dropdown's search input, which
|
|
49
|
+
// is skipped by validation because it holds no value, but is what a visitor actually uses.
|
|
50
|
+
return findFocusableControl(invalidControls)
|
|
51
|
+
|| findFocusableControl(Array.from(field.querySelectorAll(
|
|
52
|
+
'input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled])',
|
|
53
|
+
)));
|
|
45
54
|
}
|
|
46
55
|
|
|
47
56
|
function getFormLevelErrorTarget(form: HTMLFormElement): HTMLElement | null {
|
|
@@ -53,10 +62,16 @@ function getFormLevelErrorTarget(form: HTMLFormElement): HTMLElement | null {
|
|
|
53
62
|
export function enhanceServerRenderedFieldErrors(form: HTMLFormElement): void {
|
|
54
63
|
form.querySelectorAll('[data-formie-field-handle]').forEach((fieldNode) => {
|
|
55
64
|
const field = fieldNode as HTMLElement;
|
|
56
|
-
const
|
|
57
|
-
|
|
65
|
+
const messages = Array.from(field.querySelectorAll('[data-formie-field-error]'));
|
|
66
|
+
|
|
67
|
+
// A Group or Repeater contains the fields inside it, and an error on one of those is
|
|
68
|
+
// not an error on its siblings. Only act on a field for the messages it owns.
|
|
69
|
+
const hasOwnMessage = messages.some((message) => {
|
|
70
|
+
return message.closest('[data-formie-field-handle]') === field;
|
|
71
|
+
});
|
|
72
|
+
const hasOwnFlag = field.getAttribute('data-formie-field-has-error') === 'true' && messages.length === 0;
|
|
58
73
|
|
|
59
|
-
if (!
|
|
74
|
+
if (!hasOwnMessage && !hasOwnFlag) {
|
|
60
75
|
return;
|
|
61
76
|
}
|
|
62
77
|
|
|
@@ -94,6 +109,16 @@ export function hasServerRenderedValidationErrors(form: HTMLFormElement): boolea
|
|
|
94
109
|
return !!getFirstErroredField(form) || !!getFormLevelErrorTarget(form);
|
|
95
110
|
}
|
|
96
111
|
|
|
112
|
+
// Browser modules can replace a control after focus lands on it, or only create the visible one once
|
|
113
|
+
// they mount. Leave focus alone if the visitor has already moved it somewhere usable.
|
|
114
|
+
export function restoreLostValidationFocus(form: HTMLFormElement): void {
|
|
115
|
+
const active = document.activeElement;
|
|
116
|
+
|
|
117
|
+
if (!active || active === document.body || active.getClientRects().length === 0) {
|
|
118
|
+
focusFirstValidationError(form);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
97
122
|
export function focusFirstValidationError(form: HTMLFormElement): boolean {
|
|
98
123
|
const field = getFirstErroredField(form);
|
|
99
124
|
|
|
@@ -634,6 +634,13 @@ function bindFileUploadInput(field: HTMLElement, input: HTMLInputElement, form:
|
|
|
634
634
|
return;
|
|
635
635
|
}
|
|
636
636
|
|
|
637
|
+
// Hidden pages keep their file references while this request runs.
|
|
638
|
+
// A completed form clears them, so its late response must stay empty.
|
|
639
|
+
const currentAssets = readUploadedAssetsFromHiddenInputs(field, input);
|
|
640
|
+
if (currentAssets.length !== uploadedAssets.length || currentAssets.some((asset, index) => asset.assetId !== uploadedAssets[index].assetId)) {
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
|
|
637
644
|
state.uploadedAssets = hydratedAssets;
|
|
638
645
|
renderSummary(state);
|
|
639
646
|
dispatchFieldEvent(field, MODULE_ID, 'uploaded-assets-sync', {
|
|
@@ -918,6 +918,8 @@ function bindUploadManagerField(field: HTMLElement, form: HTMLFormElement | null
|
|
|
918
918
|
uppy,
|
|
919
919
|
files: [],
|
|
920
920
|
};
|
|
921
|
+
const listeners = new AbortController();
|
|
922
|
+
let hydrationToken = 0;
|
|
921
923
|
|
|
922
924
|
const remainingUploadCapacity = (): number | null => {
|
|
923
925
|
if (!maxFiles) {
|
|
@@ -1019,7 +1021,9 @@ function bindUploadManagerField(field: HTMLElement, form: HTMLFormElement | null
|
|
|
1019
1021
|
uppy.removeFile(managedFile.uppyFileId);
|
|
1020
1022
|
}
|
|
1021
1023
|
|
|
1022
|
-
|
|
1024
|
+
// Only staged files have a deletion capability. Already-attached files
|
|
1025
|
+
// are removed from the form's selection without deleting the saved asset.
|
|
1026
|
+
if (managedFile.assetId && managedFile.deleteToken) {
|
|
1023
1027
|
const body = new FormData();
|
|
1024
1028
|
const context = getUploadContext(resolvedForm, field, dropzone);
|
|
1025
1029
|
|
|
@@ -1029,9 +1033,7 @@ function bindUploadManagerField(field: HTMLElement, form: HTMLFormElement | null
|
|
|
1029
1033
|
|
|
1030
1034
|
body.append('assetId', String(managedFile.assetId));
|
|
1031
1035
|
|
|
1032
|
-
|
|
1033
|
-
body.append('uploadToken', managedFile.deleteToken || '');
|
|
1034
|
-
}
|
|
1036
|
+
body.append('uploadToken', managedFile.deleteToken);
|
|
1035
1037
|
|
|
1036
1038
|
try {
|
|
1037
1039
|
await requestJson<DeleteResponse>(deleteEndpoint, {
|
|
@@ -1081,6 +1083,7 @@ function bindUploadManagerField(field: HTMLElement, form: HTMLFormElement | null
|
|
|
1081
1083
|
};
|
|
1082
1084
|
|
|
1083
1085
|
const hydrateExistingAssets = async() => {
|
|
1086
|
+
const token = ++hydrationToken;
|
|
1084
1087
|
const assetIds = readAssetIdsFromDom(field, assetInputName);
|
|
1085
1088
|
|
|
1086
1089
|
if (!assetIds.length) {
|
|
@@ -1096,6 +1099,12 @@ function bindUploadManagerField(field: HTMLElement, form: HTMLFormElement | null
|
|
|
1096
1099
|
body: buildHydrateFormData(resolvedForm, field, assetIds, uploadTokens),
|
|
1097
1100
|
});
|
|
1098
1101
|
|
|
1102
|
+
// A response from an earlier page mount must not repopulate a reset
|
|
1103
|
+
// form or overwrite the current upload manager's selection.
|
|
1104
|
+
if (token !== hydrationToken) {
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1099
1108
|
const assets = response.assets || [];
|
|
1100
1109
|
const assetsById = new Map(assets.map((asset) => {
|
|
1101
1110
|
return [toPositiveInt(asset.assetId), asset] as const;
|
|
@@ -1263,7 +1272,7 @@ function bindUploadManagerField(field: HTMLElement, form: HTMLFormElement | null
|
|
|
1263
1272
|
event.preventDefault();
|
|
1264
1273
|
event.stopPropagation();
|
|
1265
1274
|
openBrowseDialog();
|
|
1266
|
-
});
|
|
1275
|
+
}, { signal: listeners.signal });
|
|
1267
1276
|
|
|
1268
1277
|
dropzone.addEventListener('click', (event) => {
|
|
1269
1278
|
if (event.target instanceof Element && event.target.closest(BROWSE_BUTTON_SELECTOR)) {
|
|
@@ -1271,14 +1280,14 @@ function bindUploadManagerField(field: HTMLElement, form: HTMLFormElement | null
|
|
|
1271
1280
|
}
|
|
1272
1281
|
|
|
1273
1282
|
openBrowseDialog();
|
|
1274
|
-
});
|
|
1283
|
+
}, { signal: listeners.signal });
|
|
1275
1284
|
|
|
1276
1285
|
dropzone.addEventListener('keydown', (event) => {
|
|
1277
1286
|
if (event.key === 'Enter' || event.key === ' ') {
|
|
1278
1287
|
event.preventDefault();
|
|
1279
1288
|
openBrowseDialog();
|
|
1280
1289
|
}
|
|
1281
|
-
});
|
|
1290
|
+
}, { signal: listeners.signal });
|
|
1282
1291
|
|
|
1283
1292
|
browseInput.addEventListener('change', () => {
|
|
1284
1293
|
if (!browseInput.files?.length) {
|
|
@@ -1302,14 +1311,14 @@ function bindUploadManagerField(field: HTMLElement, form: HTMLFormElement | null
|
|
|
1302
1311
|
uppy.info(error.message, 'error', 3000);
|
|
1303
1312
|
}
|
|
1304
1313
|
}
|
|
1305
|
-
});
|
|
1314
|
+
}, { signal: listeners.signal });
|
|
1306
1315
|
|
|
1307
1316
|
['dragenter', 'dragover'].forEach((eventName) => {
|
|
1308
1317
|
dropzone.addEventListener(eventName, (event) => {
|
|
1309
1318
|
event.preventDefault();
|
|
1310
1319
|
event.stopPropagation();
|
|
1311
1320
|
setDropzoneActive(true);
|
|
1312
|
-
});
|
|
1321
|
+
}, { signal: listeners.signal });
|
|
1313
1322
|
});
|
|
1314
1323
|
|
|
1315
1324
|
['dragleave', 'drop'].forEach((eventName) => {
|
|
@@ -1317,7 +1326,7 @@ function bindUploadManagerField(field: HTMLElement, form: HTMLFormElement | null
|
|
|
1317
1326
|
event.preventDefault();
|
|
1318
1327
|
event.stopPropagation();
|
|
1319
1328
|
setDropzoneActive(false);
|
|
1320
|
-
});
|
|
1329
|
+
}, { signal: listeners.signal });
|
|
1321
1330
|
});
|
|
1322
1331
|
|
|
1323
1332
|
dropzone.addEventListener('drop', (event) => {
|
|
@@ -1343,16 +1352,17 @@ function bindUploadManagerField(field: HTMLElement, form: HTMLFormElement | null
|
|
|
1343
1352
|
uppy.info(error.message, 'error', 3000);
|
|
1344
1353
|
}
|
|
1345
1354
|
}
|
|
1346
|
-
});
|
|
1355
|
+
}, { signal: listeners.signal });
|
|
1347
1356
|
|
|
1348
1357
|
const resetHandler = () => {
|
|
1358
|
+
hydrationToken += 1;
|
|
1349
1359
|
clearSelectionError();
|
|
1350
1360
|
state.files.forEach((managedFile) => {
|
|
1351
1361
|
managedFile.listItem.remove();
|
|
1352
1362
|
});
|
|
1353
1363
|
state.files = [];
|
|
1354
1364
|
uppy.cancelAll();
|
|
1355
|
-
|
|
1365
|
+
syncUploadedAssetsEvent(state);
|
|
1356
1366
|
};
|
|
1357
1367
|
|
|
1358
1368
|
resolvedForm?.addEventListener(FORM_RESET_EVENT, resetHandler);
|
|
@@ -1360,9 +1370,14 @@ function bindUploadManagerField(field: HTMLElement, form: HTMLFormElement | null
|
|
|
1360
1370
|
void hydrateExistingAssets();
|
|
1361
1371
|
|
|
1362
1372
|
return () => {
|
|
1373
|
+
hydrationToken += 1;
|
|
1374
|
+
listeners.abort();
|
|
1363
1375
|
resolvedForm?.removeEventListener(FORM_RESET_EVENT, resetHandler);
|
|
1364
1376
|
uppy.destroy();
|
|
1365
1377
|
selectionError.remove();
|
|
1378
|
+
// Keep the submitted references for Back navigation, but let the next
|
|
1379
|
+
// mount render fresh rows and attach exactly one set of controls.
|
|
1380
|
+
state.files.forEach((managedFile) => { managedFile.listItem.remove(); });
|
|
1366
1381
|
state.files = [];
|
|
1367
1382
|
};
|
|
1368
1383
|
}
|