typo3-typescript-sources 14.3.9 → 14.3.11

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 (198) hide show
  1. package/.last-synced-tag +1 -1
  2. package/README.md +1 -1
  3. package/adminpanel/admin-panel.ts +2 -2
  4. package/backend/bookmark/bookmark-manager.ts +4 -3
  5. package/backend/bookmark/bookmark-store.ts +8 -12
  6. package/backend/clipboard-panel.ts +22 -10
  7. package/backend/code-editor/language/typoscript.ts +1 -1
  8. package/backend/column-selector-button.ts +2 -2
  9. package/backend/context-menu-actions.ts +36 -16
  10. package/backend/context-menu.ts +35 -3
  11. package/backend/contextual-record-edit.ts +115 -33
  12. package/backend/date-time-picker.ts +3 -2
  13. package/backend/drag-uploader.ts +51 -21
  14. package/backend/element/breadcrumb.ts +6 -6
  15. package/backend/element/combobox-element.ts +2 -2
  16. package/backend/element/contextual-record-edit-trigger.ts +100 -65
  17. package/backend/element/datetime-element.ts +2 -1
  18. package/backend/element/editable-page-title.ts +2 -1
  19. package/backend/element/pseudo-button.ts +29 -5
  20. package/backend/element/qrcode-modal-button.ts +2 -2
  21. package/backend/element/sidebar-toggle-element.ts +1 -15
  22. package/backend/element-browser.ts +4 -3
  23. package/backend/enum/viewport/scaffold-identifier.ts +1 -1
  24. package/backend/event/event-dispatcher.ts +4 -2
  25. package/backend/form-engine/container/flex-form-container-container.ts +1 -1
  26. package/backend/form-engine/container/flex-form-section-container.ts +3 -3
  27. package/backend/form-engine/container/inline-control-container.ts +29 -29
  28. package/backend/form-engine/element/abstract-sortable-select-items.ts +1 -1
  29. package/backend/form-engine/element/category-element.ts +5 -5
  30. package/backend/form-engine/element/extra/char-counter.ts +1 -1
  31. package/backend/form-engine/element/group-element.ts +1 -1
  32. package/backend/form-engine/element/select-tree-element.ts +4 -4
  33. package/backend/form-engine/element/select-tree.ts +1 -1
  34. package/backend/form-engine/element/slug-element.ts +9 -7
  35. package/backend/form-engine/element/suggest/result-container.ts +1 -1
  36. package/backend/form-engine/element/suggest/result-item.ts +1 -1
  37. package/backend/form-engine/element/table-permission-element.ts +4 -4
  38. package/backend/form-engine/field-control/add-record.ts +1 -1
  39. package/backend/form-engine/field-control/edit-popup.ts +2 -2
  40. package/backend/form-engine/field-control/insert-clipboard.ts +1 -1
  41. package/backend/form-engine/field-control/link-popup.ts +1 -1
  42. package/backend/form-engine/field-control/list-module.ts +1 -1
  43. package/backend/form-engine/field-control/password-generator.ts +4 -4
  44. package/backend/form-engine/field-control/reset-selection.ts +2 -2
  45. package/backend/form-engine/field-wizard/localization-state-selector.ts +2 -2
  46. package/backend/form-engine/field-wizard/value-picker.ts +1 -1
  47. package/backend/form-engine/field-wizard/value-slider.ts +2 -2
  48. package/backend/form-engine-review.ts +1 -1
  49. package/backend/form-engine-suggest.ts +2 -2
  50. package/backend/form-engine-validation.ts +55 -10
  51. package/backend/form-engine.ts +16 -14
  52. package/backend/global-event-handler.ts +1 -1
  53. package/backend/grid-editor.ts +83 -8
  54. package/backend/hotkeys.ts +2 -1
  55. package/backend/image-manipulation.ts +4 -3
  56. package/backend/info-window.ts +4 -3
  57. package/backend/layout-module/drag-drop.ts +17 -16
  58. package/backend/layout-module/page-layout.ts +7 -2
  59. package/backend/layout-module/paste.ts +3 -3
  60. package/backend/layout-module/toggle-hidden-element.ts +1 -1
  61. package/backend/live-search/live-search-configurator.ts +4 -3
  62. package/backend/live-search/live-search-shortcut.ts +2 -1
  63. package/backend/live-search/live-search.ts +10 -9
  64. package/backend/live-search/result-types/default-result-type.ts +2 -1
  65. package/backend/localization/finisher/localization-submission-service.ts +1 -0
  66. package/backend/localization/label-provider.ts +2 -1
  67. package/backend/localization/localization-button.ts +3 -0
  68. package/backend/localization/localization-wizard.ts +3 -0
  69. package/backend/localization/steps/source-language-step.ts +1 -0
  70. package/backend/login/capslock-warning.ts +84 -0
  71. package/backend/login-refresh.ts +6 -26
  72. package/backend/login.ts +6 -4
  73. package/backend/mail-link-handler.ts +2 -2
  74. package/backend/modal.ts +36 -18
  75. package/backend/module-menu.ts +21 -11
  76. package/backend/module.ts +1 -1
  77. package/backend/multi-record-selection-edit-action.ts +3 -2
  78. package/backend/multi-record-selection.ts +3 -3
  79. package/backend/multi-step-wizard.ts +2 -2
  80. package/backend/new-record-wizard.ts +3 -2
  81. package/backend/notification.ts +4 -20
  82. package/backend/page-wizard/steps/form-engine-step.ts +2 -2
  83. package/backend/popover.ts +1 -1
  84. package/backend/recordlist.ts +13 -11
  85. package/backend/security/element/csp-reports.ts +2 -2
  86. package/backend/security/element/sudo-mode.ts +6 -7
  87. package/backend/settings/editor.ts +9 -9
  88. package/backend/settings/type/page.ts +5 -4
  89. package/backend/severity.ts +2 -22
  90. package/backend/sortable-table.ts +3 -3
  91. package/backend/storage/module-state-storage.ts +3 -1
  92. package/backend/storage/persistent.ts +15 -3
  93. package/backend/switch-user.ts +3 -2
  94. package/backend/tab.ts +3 -3
  95. package/backend/telephone-link-handler.ts +1 -1
  96. package/backend/tests/drag-uploader-test.ts +287 -0
  97. package/backend/tests/element/pseudo-button-test.ts +95 -0
  98. package/backend/tests/form-engine/element/select-tree-test.ts +1 -1
  99. package/backend/tests/form-engine-validation-test.ts +75 -0
  100. package/backend/tests/grid-editor-test.ts +29 -0
  101. package/backend/tests/login/capslock-warning-test.ts +78 -0
  102. package/backend/tests/modal-test.ts +73 -0
  103. package/backend/tests/notification-test.ts +16 -16
  104. package/backend/tests/tree/tree-test.ts +68 -0
  105. package/backend/tests/utility/drag-drop-utility-test.ts +82 -0
  106. package/backend/toolbar/system-information-menu.ts +2 -2
  107. package/backend/tree/file-storage-browser.ts +7 -5
  108. package/backend/tree/file-storage-tree-container.ts +8 -6
  109. package/backend/tree/page-browser.ts +4 -3
  110. package/backend/tree/page-position-select.ts +4 -3
  111. package/backend/tree/page-tree-element.ts +8 -6
  112. package/backend/tree/tree-module-state.ts +12 -0
  113. package/backend/tree/tree-toolbar.ts +1 -1
  114. package/backend/tree/tree.ts +26 -18
  115. package/backend/url-link-handler.ts +1 -1
  116. package/backend/user-pass-login.ts +0 -103
  117. package/backend/user-settings-manager.ts +2 -1
  118. package/backend/utility/collapse-state-search.ts +2 -2
  119. package/backend/utility/drag-drop-utility.ts +7 -10
  120. package/backend/utility/top-level-module-import.ts +3 -1
  121. package/backend/viewport/content-container.ts +3 -2
  122. package/backend/viewport/content-navigation-toggle.ts +5 -12
  123. package/backend/viewport/content-navigation.ts +3 -3
  124. package/backend/viewport/navigation-container.ts +2 -2
  125. package/backend/viewport.ts +5 -4
  126. package/backend/window-manager.ts +5 -4
  127. package/backend/wizard/finisher/noop-finisher.ts +3 -2
  128. package/backend/wizard/finisher/redirect-finisher.ts +4 -3
  129. package/backend/wizard/finisher/reload-finisher.ts +3 -2
  130. package/backend/wizard/move-content-element.ts +7 -7
  131. package/backend/wizard/move-page.ts +5 -4
  132. package/backend/wizard/steps/finisher-step.ts +1 -1
  133. package/belog/backend-log.ts +2 -2
  134. package/beuser/permissions.ts +4 -4
  135. package/core/java-script-item-handler.ts +12 -2
  136. package/core/java-script-item-processor.ts +55 -7
  137. package/core/lit-helper.ts +5 -2
  138. package/core/tests/java-script-item-processor-test.ts +83 -0
  139. package/core/tests/utility/top-window-test.ts +121 -0
  140. package/core/utility/top-window.ts +99 -0
  141. package/dashboard/dashboard.ts +3 -7
  142. package/extensionmanager/dependency-check.ts +2 -1
  143. package/extensionmanager/extension-toggle-button.ts +2 -1
  144. package/extensionmanager/main.ts +1 -1
  145. package/extensionmanager/repository.ts +2 -1
  146. package/extensionmanager/update.ts +1 -1
  147. package/extensionmanager/upload-form.ts +1 -1
  148. package/filelist/browse-files.ts +2 -2
  149. package/filelist/browse-folders.ts +1 -1
  150. package/filelist/context-menu-actions.ts +20 -19
  151. package/filelist/file-delete.ts +4 -3
  152. package/filelist/file-list-actions.ts +1 -1
  153. package/filelist/file-list-dragdrop.ts +7 -6
  154. package/filelist/file-list-rename-handler.ts +2 -1
  155. package/filelist/file-list-replace-handler.ts +2 -1
  156. package/filelist/file-list-transfer-handler.ts +5 -4
  157. package/filelist/file-list.ts +12 -11
  158. package/filelist/linkbrowser-file-handler.ts +1 -1
  159. package/filelist/rename-file.ts +3 -3
  160. package/filelist/resource-creation.ts +1 -1
  161. package/form/backend/form-editor/core.ts +1 -1
  162. package/form/backend/form-editor/inspector-component.ts +4 -4
  163. package/form/backend/form-editor/stage-component.ts +10 -11
  164. package/form/backend/form-editor/view-model.ts +1 -1
  165. package/impexp/context-menu-actions.ts +5 -3
  166. package/info/translation-status.ts +2 -2
  167. package/install/installer.ts +8 -7
  168. package/install/module/abstract-interactable-module.ts +2 -2
  169. package/install/module/environment/folder-structure.ts +1 -1
  170. package/install/module/maintenance/clear-tables.ts +1 -1
  171. package/install/module/maintenance/clear-typo3temp-files.ts +1 -1
  172. package/install/module/maintenance/database-analyzer.ts +2 -2
  173. package/install/module/maintenance/language-packs.ts +2 -1
  174. package/install/module/settings/extension-configuration.ts +3 -4
  175. package/install/module/settings/local-configuration.ts +8 -8
  176. package/install/module/upgrade/upgrade-docs.ts +1 -1
  177. package/install/module/upgrade/upgrade-wizards.ts +8 -8
  178. package/install/renderable/flash-message.ts +2 -2
  179. package/install/renderable/info-box.ts +2 -2
  180. package/install/router.ts +3 -3
  181. package/lowlevel/query-generator.ts +4 -4
  182. package/opendocs/open-document-store.ts +5 -4
  183. package/package.json +2 -2
  184. package/recycler/recycler.ts +19 -18
  185. package/redirects/event-handler.ts +66 -20
  186. package/redirects/short-url-generator.ts +2 -2
  187. package/redirects/tests/event-handler-test.ts +121 -0
  188. package/rte-ckeditor/ckeditor5.ts +2 -2
  189. package/rte-ckeditor/tests/ckeditor5-test.ts +1 -1
  190. package/scheduler/form-engine/element/timing-options-element.ts +2 -2
  191. package/scheduler/scheduler-add-group.ts +5 -4
  192. package/scheduler/scheduler-sortable-groups.ts +2 -2
  193. package/scheduler/scheduler.ts +1 -1
  194. package/styleguide/find-icons.ts +1 -1
  195. package/viewpage/main.ts +7 -7
  196. package/workspaces/backend.ts +33 -31
  197. package/workspaces/preview.ts +11 -10
  198. package/workspaces/workspace-state.ts +6 -5
@@ -12,11 +12,15 @@
12
12
  */
13
13
 
14
14
  import FormEngine from '@typo3/backend/form-engine';
15
- import Modal from '@typo3/backend/modal';
15
+ import type { Consumable } from '@typo3/backend/event/consumable';
16
+ import type TriggerRequest from '@typo3/backend/event/trigger-request';
17
+ import Modal, { type ModalElement } from '@typo3/backend/modal';
16
18
  import Severity from '@typo3/backend/severity';
17
19
  import DocumentService from '@typo3/core/document-service';
20
+ import { topDocument, topWindow } from '@typo3/core/utility/top-window';
18
21
  import '@typo3/backend/element/icon-element';
19
22
  import labels from '~labels/backend.alt_doc';
23
+ import coreCommonLabels from '~labels/core.common';
20
24
 
21
25
  type ContextualRecordEditOptions = {
22
26
  justSaved?: boolean;
@@ -37,6 +41,8 @@ class ContextualRecordEdit {
37
41
  private closeButton: HTMLButtonElement | null = null;
38
42
  private fullscreenButton: HTMLAnchorElement | null = null;
39
43
  private readonly options: ContextualRecordEditOptions;
44
+ // "<table>:<uid>" of the edited record
45
+ private readonly record: string = ContextualRecordEdit.resolveRecord();
40
46
 
41
47
  constructor(options: ContextualRecordEditOptions = {}) {
42
48
  this.options = options;
@@ -47,11 +53,22 @@ class ContextualRecordEdit {
47
53
  });
48
54
  }
49
55
 
56
+ private static resolveRecord(): string {
57
+ for (const key of new URL(window.location.href).searchParams.keys()) {
58
+ const match = key.match(/^edit\[([^\]]+)]\[(\d+)]$/);
59
+ if (match !== null) {
60
+ return match[1] + ':' + match[2];
61
+ }
62
+ }
63
+ return '';
64
+ }
65
+
50
66
  private initialize(): void {
51
67
  this.initializeCloseButton();
52
68
  this.initializeFullscreenButton();
53
69
  this.initializeEscapeKey();
54
70
  this.initializeParentMessages();
71
+ this.initializeNavigationGuard();
55
72
  this.handlePostSaveState();
56
73
  if (!this.options.justSaved) {
57
74
  this.focusFirstElement();
@@ -73,42 +90,101 @@ class ContextualRecordEdit {
73
90
  }
74
91
  this.fullscreenButton.addEventListener('click', (e: Event): void => {
75
92
  e.preventDefault();
76
- const navigate = (): void => {
77
- // Clear FormEngine's dirty tracking so it doesn't show its own confirmation after ours
78
- document.querySelectorAll('.has-change').forEach((el) => el.classList.remove('has-change'));
79
- // Navigate the content frame directly (same-origin access) — using
80
- // postMessage for this failed silently in Firefox.
81
- top?.TYPO3?.Backend?.ContentContainer?.setUrl(this.fullscreenButton.href);
82
- // Tell the parent to close the modal
83
- window.parent.postMessage(
84
- { actionName: 'typo3:editform:navigate' },
85
- window.location.origin
86
- );
87
- };
88
- if (FormEngine.hasChange()) {
89
- Modal.confirm(
90
- labels.get('label.confirm.close_without_save.title'),
91
- labels.get('label.confirm.close_without_save.content'),
92
- Severity.warning,
93
- [
94
- {
95
- text: labels.get('buttons.confirm.close_without_save.no'),
96
- btnClass: 'btn-default',
97
- trigger: (_e, modal): void => { modal.hideModal(); },
98
- },
99
- {
100
- text: labels.get('buttons.confirm.close_without_save.yes'),
101
- btnClass: 'btn-warning',
102
- trigger: (_e, modal): void => { modal.hideModal(); navigate(); },
103
- },
104
- ]
105
- );
106
- } else {
107
- navigate();
93
+ // Navigate the content frame directly (same-origin access), using
94
+ // postMessage for this failed silently in Firefox. The navigation
95
+ // guard asks to discard unsaved changes and closes the sheet.
96
+ FormEngine.ready().then((): void => {
97
+ topWindow.TYPO3?.Backend?.ContentContainer?.setUrl(this.fullscreenButton.href);
98
+ });
99
+ });
100
+ }
101
+
102
+ /**
103
+ * Navigating the content frame while the sheet is open (e.g. via a context
104
+ * menu action) would load the target behind the sheet. The sheet therefore
105
+ * replaces FormEngine as navigation guard and closes itself instead.
106
+ */
107
+ private initializeNavigationGuard(): void {
108
+ const consumerScope = topWindow.TYPO3?.Backend?.consumerScope;
109
+ if (!consumerScope) {
110
+ return;
111
+ }
112
+ const navigationGuard: Consumable = {
113
+ consume: (interactionRequest: TriggerRequest): Promise<void> | null => {
114
+ if (!interactionRequest.concernsTypes(['typo3.setUrl'])) {
115
+ return null;
116
+ }
117
+ // Stays pending if the user keeps editing, which cancels the navigation
118
+ return new Promise<void>((resolve): void => {
119
+ if (interactionRequest.concernsTypes(['typo3.recordCommit'])) {
120
+ // A record commit returns to the current module, so the sheet stays
121
+ // open and is reloaded once the commit is done to show its result.
122
+ this.confirmDiscardChanges((): void => {
123
+ topDocument.addEventListener('typo3-module-loaded', () => this.reload(), { once: true });
124
+ resolve();
125
+ });
126
+ return;
127
+ }
128
+ this.confirmDiscardChanges((): void => {
129
+ resolve();
130
+ window.parent.postMessage(
131
+ { actionName: 'typo3:editform:navigate' },
132
+ window.location.origin
133
+ );
134
+ });
135
+ });
136
+ },
137
+ };
138
+ let pageHidden = false;
139
+ window.addEventListener('pagehide', (): void => {
140
+ pageHidden = true;
141
+ consumerScope.detach(navigationGuard);
142
+ }, { once: true });
143
+ FormEngine.ready().then((): void => {
144
+ if (pageHidden) {
145
+ return;
108
146
  }
147
+ consumerScope.detach(FormEngine);
148
+ consumerScope.attach(navigationGuard);
109
149
  });
110
150
  }
111
151
 
152
+ private reload(): void {
153
+ const url = new URL(window.location.href);
154
+ url.searchParams.delete('justSaved');
155
+ window.location.replace(url.toString());
156
+ }
157
+
158
+ private confirmDiscardChanges(onDiscard: () => void, onSave: (() => void) | null = null): void {
159
+ if (!FormEngine.hasChange()) {
160
+ onDiscard();
161
+ return;
162
+ }
163
+ Modal.confirm(
164
+ labels.get('label.confirm.close_without_save.title'),
165
+ labels.get('label.confirm.close_without_save.content'),
166
+ Severity.warning,
167
+ [
168
+ {
169
+ text: labels.get('buttons.confirm.close_without_save.no'),
170
+ btnClass: 'btn-default',
171
+ trigger: (_e, modal): void => { modal.hideModal(); },
172
+ },
173
+ {
174
+ text: labels.get('buttons.confirm.close_without_save.yes'),
175
+ btnClass: 'btn-default',
176
+ trigger: (_e, modal): void => { modal.hideModal(); onDiscard(); },
177
+ },
178
+ ...(onSave !== null && document.querySelector('.has-error') === null ? [{
179
+ text: coreCommonLabels.get('save'),
180
+ btnClass: 'btn-primary',
181
+ active: true,
182
+ trigger: (_e: Event, modal: ModalElement): void => { modal.hideModal(); onSave(); },
183
+ }] : []),
184
+ ]
185
+ );
186
+ }
187
+
112
188
  private initializeEscapeKey(): void {
113
189
  document.addEventListener('keydown', (e: KeyboardEvent): void => {
114
190
  if (e.key === 'Escape') {
@@ -126,6 +202,11 @@ class ContextualRecordEdit {
126
202
  if (event.data?.actionName === 'typo3:editform:requestclose') {
127
203
  this.requestClose();
128
204
  }
205
+ if (event.data?.actionName === 'typo3:editform:reload') {
206
+ // Saving the stale form of the record that was just saved elsewhere would revert that change
207
+ const canSave = event.data.savedRecord !== this.record;
208
+ this.confirmDiscardChanges((): void => this.reload(), canSave ? (): void => FormEngine.saveDocument() : null);
209
+ }
129
210
  });
130
211
  }
131
212
 
@@ -138,6 +219,7 @@ class ContextualRecordEdit {
138
219
  {
139
220
  actionName: 'typo3:editform:saved',
140
221
  recordTitle: this.options.savedRecordTitle ?? '',
222
+ record: this.record,
141
223
  },
142
224
  window.location.origin
143
225
  );
@@ -21,6 +21,7 @@ import type { PostValidationEvent } from '@typo3/backend/form-engine-validation'
21
21
  import type { DateConfiguration } from '@typo3/backend/type/date-configuration';
22
22
  import '@typo3/backend/input/clearable';
23
23
  import coreLabels from '~labels/core.core';
24
+ import { openerTopWindow, topWindow } from '@typo3/core/utility/top-window';
24
25
 
25
26
  const ISO8601_LOCALTIME = 'ISO8601_LOCALTIME';
26
27
 
@@ -33,7 +34,7 @@ interface FlatpickrInputElement extends HTMLInputElement {
33
34
  * contains all logic for the date time picker used in FormEngine, EXT:belog and EXT:scheduler
34
35
  */
35
36
  class DateTimePicker {
36
- private readonly format: DateConfiguration = (typeof opener?.top?.TYPO3 !== 'undefined' ? opener.top : top).TYPO3.settings.DateConfiguration;
37
+ private readonly format: DateConfiguration = (openerTopWindow() ?? topWindow).TYPO3.settings.DateConfiguration;
37
38
 
38
39
  /**
39
40
  * initialize date fields to add a datepicker to each field
@@ -144,7 +145,7 @@ class DateTimePicker {
144
145
  */
145
146
  private getScrollEvent(): ThrottleEvent {
146
147
  return new ThrottleEvent('scroll', (): void => {
147
- const activeFlatpickrElement = document.querySelector('.flatpickr-input.active') as FlatpickrInputElement;
148
+ const activeFlatpickrElement = document.querySelector<FlatpickrInputElement>('.flatpickr-input.active');
148
149
  if (activeFlatpickrElement === null) {
149
150
  return;
150
151
  }
@@ -27,6 +27,7 @@ import { KeyTypesEnum } from '@typo3/backend/enum/key-types';
27
27
  import '@typo3/backend/element/progress-bar-element';
28
28
  import type { ProgressBarElement } from '@typo3/backend/element/progress-bar-element';
29
29
  import { topLevelModuleImport } from '@typo3/backend/utility/top-level-module-import';
30
+ import { topWindow } from '@typo3/core/utility/top-window';
30
31
  import { FormatUtility } from '@typo3/backend/utility/format-utility';
31
32
  import coreLabels from '~labels/core.core';
32
33
  import commonLabels from '~labels/core.common';
@@ -111,6 +112,7 @@ export default class DragUploader {
111
112
  private readonly browserCapabilities: { fileReader: boolean; DnD: boolean; Progress: boolean };
112
113
  private readonly dropZoneInsertBefore: boolean;
113
114
  private queueLength: number;
115
+ private hasSucceededUpload: boolean = false;
114
116
  private readonly defaultAction: Action;
115
117
  private manuallyTriggered: boolean;
116
118
 
@@ -138,7 +140,7 @@ export default class DragUploader {
138
140
  this.dropZoneInsertBefore = false;
139
141
  dropZoneEscapedTarget.after(this.dropzone);
140
142
  }
141
- this.fileInput = <HTMLInputElement>document.createElement('input');
143
+ this.fileInput = document.createElement('input');
142
144
  this.fileInput.setAttribute('type', 'file');
143
145
  this.fileInput.setAttribute('multiple', 'multiple');
144
146
  this.fileInput.setAttribute('name', 'files[]');
@@ -370,22 +372,25 @@ export default class DragUploader {
370
372
  /**
371
373
  * @param {FileList} files
372
374
  */
373
- public processFiles(files: FileList): void {
375
+ public async processFiles(files: FileList | File[]): Promise<void> {
376
+ const candidates = Array.from(files);
377
+ // The files of the picker are gone once it is reset
378
+ this.fileInput.value = '';
379
+ const errors = await Promise.all(candidates.map((file: File): Promise<string | null> => this.validateFile(file)));
374
380
  const validFiles: File[] = [];
375
- for (const file of Array.from(files)) {
376
- const error = this.validateFile(file);
377
- if (error === null) {
381
+ candidates.forEach((file: File, index: number): void => {
382
+ if (errors[index] === null) {
378
383
  validFiles.push(file);
379
384
  } else {
380
- Notification.error(coreLabels.get('file_upload.notUploaded.title'), error);
385
+ Notification.error(coreLabels.get('file_upload.notUploaded.title'), errors[index]);
381
386
  }
382
- }
383
- this.fileInput.value = '';
387
+ });
384
388
  if (validFiles.length === 0) {
385
389
  return;
386
390
  }
387
391
 
388
392
  this.queueLength = validFiles.length;
393
+ this.hasSucceededUpload = false;
389
394
 
390
395
  if (this.fileList.parentElement.hasAttribute('hidden')) {
391
396
  // Show the filelist (table)
@@ -463,9 +468,12 @@ export default class DragUploader {
463
468
  /**
464
469
  * Decrements the queue and renders a flash message if queue is empty
465
470
  */
466
- public decrementQueueLength(messages?: FlashMessage[]): void {
471
+ public decrementQueueLength(messages?: FlashMessage[], uploadSucceeded: boolean = false): void {
467
472
  if (this.queueLength > 0) {
468
473
  this.queueLength--;
474
+ if (uploadSucceeded) {
475
+ this.hasSucceededUpload = true;
476
+ }
469
477
  if (this.queueLength === 0) {
470
478
  document.dispatchEvent(new CustomEvent(uploadFinishedEventName));
471
479
 
@@ -476,7 +484,7 @@ export default class DragUploader {
476
484
  }
477
485
  }
478
486
 
479
- if (this.reloadUrl) {
487
+ if (this.reloadUrl && this.hasSucceededUpload) {
480
488
  // After 5 seconds (when flash messages have disappeared), provide the user the option to reload the module
481
489
  setTimeout(() => {
482
490
  Notification.info(
@@ -490,7 +498,7 @@ export default class DragUploader {
490
498
  {
491
499
  label: coreLabels.get('file_upload.reload.filelist.actions.reload'),
492
500
  action: new ImmediateAction((): void => {
493
- top.list_frame.document.location.href = this.reloadUrl;
501
+ topWindow.list_frame.document.location.href = this.reloadUrl;
494
502
  })
495
503
  }
496
504
  ]
@@ -599,7 +607,7 @@ export default class DragUploader {
599
607
  new RegularEvent('change', (event: Event, target: HTMLSelectElement) => {
600
608
  if (target.value !== '') {
601
609
  // mass action was selected, apply action to every file
602
- for (const select of modal.querySelectorAll('.t3js-actions') as NodeListOf<HTMLSelectElement>) {
610
+ for (const select of modal.querySelectorAll<HTMLSelectElement>('.t3js-actions')) {
603
611
  const index = parseInt(select.dataset.override, 10);
604
612
  select.value = target.value;
605
613
  select.disabled = true;
@@ -619,7 +627,6 @@ export default class DragUploader {
619
627
  modal.addEventListener('button.clicked', (e: Event): void => {
620
628
  const button = e.target as HTMLButtonElement;
621
629
  if (button.name === 'cancel') {
622
- this.askForOverride = [];
623
630
  Modal.dismiss();
624
631
  } else if (button.name === 'continue') {
625
632
  for (const fileInfo of this.askForOverride) {
@@ -628,7 +635,10 @@ export default class DragUploader {
628
635
  this.irreObjectUid,
629
636
  fileInfo.original,
630
637
  );
631
- } else if (fileInfo.action !== Action.SKIP) {
638
+ this.decrementQueueLength();
639
+ } else if (fileInfo.action === Action.SKIP) {
640
+ this.decrementQueueLength();
641
+ } else {
632
642
  new FileQueueItem(this, fileInfo.uploaded, fileInfo.action, this.fileList.dataset.mode === Mode.BROWSE ? Mode.BROWSE : Mode.MANAGE);
633
643
  }
634
644
  }
@@ -638,16 +648,23 @@ export default class DragUploader {
638
648
  });
639
649
 
640
650
  modal.addEventListener('typo3-modal-hidden', () => {
651
+ // None of the files left, e.g. after cancelling the modal, is uploaded
652
+ for (let i = 0; i < this.askForOverride.length; i++) {
653
+ this.decrementQueueLength();
654
+ }
641
655
  this.askForOverride = [];
642
-
643
- document.dispatchEvent(new CustomEvent(uploadFinishedEventName));
644
656
  });
645
657
  }
646
658
 
647
659
  /**
648
660
  * @returns the reason why the file cannot be uploaded, null if it can be uploaded
649
661
  */
650
- private validateFile(file: File): string | null {
662
+ private async validateFile(file: File): Promise<string | null> {
663
+ if (!await this.isReadable(file)) {
664
+ return coreLabels.get('file_upload.notUploaded.unreadable', {
665
+ '0': file.name,
666
+ });
667
+ }
651
668
  const extension = file.name.split('.').pop().toLowerCase();
652
669
  if (this.maxFileSize > 0 && file.size > this.maxFileSize) {
653
670
  return coreLabels.get('file_upload.maxFileSizeExceeded', {
@@ -674,6 +691,19 @@ export default class DragUploader {
674
691
  }
675
692
  return null;
676
693
  }
694
+
695
+ /**
696
+ * A folder, e.g. one dropped from the desktop, is handed over as a file, but reading it fails
697
+ */
698
+ private async isReadable(file: File): Promise<boolean> {
699
+ try {
700
+ // Slicing an empty file reads nothing, so it is read as a whole
701
+ await (file.size === 0 ? file : file.slice(0, 1)).arrayBuffer();
702
+ return true;
703
+ } catch {
704
+ return false;
705
+ }
706
+ }
677
707
  }
678
708
 
679
709
  class FileQueueItem {
@@ -802,7 +832,7 @@ class FileQueueItem {
802
832
  });
803
833
  this.updateMessage(errorText);
804
834
  try {
805
- const jsonResponse = JSON.parse(response.responseText) as any;
835
+ const jsonResponse = JSON.parse(response.responseText);
806
836
  const messages = jsonResponse.messages as FlashMessage[];
807
837
  if (messages && messages.length) {
808
838
  for (const flashMessage of messages) {
@@ -833,7 +863,7 @@ class FileQueueItem {
833
863
  */
834
864
  public uploadSuccess(data: { upload?: UploadedFile[], messages?: FlashMessage[] }): void {
835
865
  if (data.upload) {
836
- this.dragUploader.decrementQueueLength(data.messages);
866
+ this.dragUploader.decrementQueueLength(data.messages, true);
837
867
  this.row.setAttribute('data-type', 'file');
838
868
  this.row.setAttribute('data-file-uid', String(data.upload[0].uid));
839
869
  this.fileName.textContent = data.upload[0].name;
@@ -845,7 +875,7 @@ class FileQueueItem {
845
875
 
846
876
  // Enable checkbox, if available
847
877
  if (this.selector) {
848
- const checkbox: HTMLInputElement = <HTMLInputElement>this.selector.querySelector('input');
878
+ const checkbox = this.selector.querySelector('input');
849
879
  if (checkbox) {
850
880
  checkbox.removeAttribute('disabled');
851
881
  checkbox.setAttribute('name', 'CBC[_FILE|' + Md5.hash(combinedIdentifier) + ']');
@@ -895,7 +925,7 @@ class FileQueueItem {
895
925
  */
896
926
  public showFileInfo(fileInfo: UploadedFile): void {
897
927
  this.removeProgress();
898
- if ((document.querySelector('#filelist-searchterm') as HTMLInputElement)?.value) {
928
+ if ((document.querySelector<HTMLInputElement>('#filelist-searchterm'))?.value) {
899
929
  // When search is active, the PATH column is always present so we add it
900
930
  const pathColumn = document.createElement('td');
901
931
  pathColumn.textContent = fileInfo.path;
@@ -177,8 +177,8 @@ export class Breadcrumb extends LitElement
177
177
  {
178
178
  if (this.dropdownButtonWidth === null) {
179
179
  const toggleTemplate = html`<div class="breadcrumb-item dropdown">${this.renderDropdownToggle()}</div>`;
180
- render(toggleTemplate, this.measurementContainer!);
181
- const toggleElement = this.measurementContainer!.querySelector('div');
180
+ render(toggleTemplate, this.measurementContainer);
181
+ const toggleElement = this.measurementContainer.querySelector('div');
182
182
  this.dropdownButtonWidth = toggleElement?.offsetWidth ?? 0;
183
183
  render(nothing, this.measurementContainer);
184
184
  }
@@ -187,8 +187,8 @@ export class Breadcrumb extends LitElement
187
187
  private measureEllipsis(): void
188
188
  {
189
189
  if (this.ellipsisWidth === null) {
190
- render(this.renderEllipsis(), this.measurementContainer!);
191
- const ellipsisElement = this.measurementContainer!.querySelector('div');
190
+ render(this.renderEllipsis(), this.measurementContainer);
191
+ const ellipsisElement = this.measurementContainer.querySelector('div');
192
192
  this.ellipsisWidth = ellipsisElement?.offsetWidth ?? 0;
193
193
  render(nothing, this.measurementContainer);
194
194
  }
@@ -211,8 +211,8 @@ export class Breadcrumb extends LitElement
211
211
  ${this.renderBreadcrumbElement(node)}
212
212
  </div>
213
213
  `;
214
- render(template, this.measurementContainer!);
215
- const element = this.measurementContainer!.querySelector('div');
214
+ render(template, this.measurementContainer);
215
+ const element = this.measurementContainer.querySelector('div');
216
216
  const width = element?.offsetWidth ?? 0;
217
217
  render(nothing, this.measurementContainer);
218
218
 
@@ -293,7 +293,7 @@ export class ComboboxElement extends LitElement {
293
293
  }
294
294
 
295
295
  private positionDropdown(): void {
296
- const listbox = this.shadowRoot?.querySelector('.listbox') as HTMLElement;
296
+ const listbox = this.shadowRoot?.querySelector<HTMLElement>('.listbox');
297
297
  if (!listbox) {
298
298
  return;
299
299
  }
@@ -466,7 +466,7 @@ export class ComboboxElement extends LitElement {
466
466
 
467
467
 
468
468
  private getInput(): HTMLInputElement | null {
469
- const slot = this.shadowRoot?.querySelector('slot:not([name])') as HTMLSlotElement;
469
+ const slot = this.shadowRoot?.querySelector<HTMLSlotElement>('slot:not([name])');
470
470
  if (!slot) {
471
471
  return null;
472
472
  }
@@ -16,7 +16,9 @@ import { PseudoButtonLitElement } from '@typo3/backend/element/pseudo-button';
16
16
  import Modal, { Types, Sizes, Positions, type ModalElement } from '@typo3/backend/modal';
17
17
  import Notification from '@typo3/backend/notification';
18
18
  import Persistent from '@typo3/backend/storage/persistent';
19
+ import { topLevelModuleImport } from '@typo3/backend/utility/top-level-module-import';
19
20
  import labels from '~labels/backend.alt_doc';
21
+ import { topWindow, topDocument } from '@typo3/core/utility/top-window';
20
22
 
21
23
  /**
22
24
  * Module: @typo3/backend/element/contextual-record-edit-trigger
@@ -41,6 +43,96 @@ import labels from '~labels/backend.alt_doc';
41
43
  * Edit record
42
44
  * </typo3-backend-contextual-record-edit-trigger>
43
45
  */
46
+ /**
47
+ * Whether a contextual record edit sheet is currently open in the backend.
48
+ */
49
+ export const isContextualRecordEditOpen = (): boolean => {
50
+ return topDocument.querySelector('typo3-backend-modal[data-contextual-record-edit]') !== null;
51
+ };
52
+
53
+ /**
54
+ * Opens the contextual record edit route in a sheet. Sheets may be nested,
55
+ * each one only reacts to messages of its own iframe.
56
+ */
57
+ export const openContextualRecordEdit = (url: string, context: string = '', focusTarget: HTMLElement | null = null): ModalElement => {
58
+ const modal = Modal.advanced({
59
+ type: Types.iframe,
60
+ title: '',
61
+ content: url,
62
+ size: Sizes.expand,
63
+ position: Positions.sheet,
64
+ hideHeader: true,
65
+ resizeIdentifier: `contextualEdit${context ? `.${context}` : ''}`,
66
+ });
67
+ modal.setAttribute('data-contextual-record-edit', '');
68
+ setupMessageHandling(modal, focusTarget);
69
+ return modal;
70
+ };
71
+
72
+ const setupMessageHandling = (modal: ModalElement, focusTarget: HTMLElement | null): void => {
73
+ const messageTarget = topWindow;
74
+ let savedRecordTitle = '';
75
+ let savedRecord = '';
76
+ let hasSaved = false;
77
+ let closeConfirmed = false;
78
+ const messageHandler = (event: MessageEvent): void => {
79
+ if (event.origin !== window.location.origin) {
80
+ return;
81
+ }
82
+ if (event.source === null || event.source !== modal.querySelector('iframe')?.contentWindow) {
83
+ return;
84
+ }
85
+ if (event.data?.actionName === 'typo3:editform:saved') {
86
+ hasSaved = true;
87
+ savedRecordTitle = event.data.recordTitle ?? '';
88
+ savedRecord = event.data.record ?? '';
89
+ }
90
+ if (event.data?.actionName === 'typo3:editform:closed') {
91
+ closeConfirmed = true;
92
+ modal.hideModal();
93
+ }
94
+ if (event.data?.actionName === 'typo3:editform:navigate') {
95
+ closeConfirmed = true;
96
+ modal.hideModal();
97
+ }
98
+ };
99
+ messageTarget.addEventListener('message', messageHandler);
100
+
101
+ modal.addEventListener('typo3-modal-hide', (e: Event): void => {
102
+ if (closeConfirmed) {
103
+ return;
104
+ }
105
+ e.preventDefault();
106
+ const iframe = modal.querySelector('iframe');
107
+ iframe?.contentWindow?.postMessage(
108
+ { actionName: 'typo3:editform:requestclose' },
109
+ window.location.origin
110
+ );
111
+ });
112
+
113
+ modal.addEventListener('typo3-modal-hidden', (): void => {
114
+ messageTarget.removeEventListener('message', messageHandler);
115
+ if (hasSaved) {
116
+ // A sheet below may show the saved record, e.g. as a relation
117
+ const sheets = topDocument.querySelectorAll<ModalElement>('typo3-backend-modal[data-contextual-record-edit]');
118
+ sheets.item(sheets.length - 1)?.querySelector('iframe')?.contentWindow?.postMessage(
119
+ { actionName: 'typo3:editform:reload', savedRecord },
120
+ window.location.origin
121
+ );
122
+ topDocument.dispatchEvent(new CustomEvent('typo3:pagetree:refresh'));
123
+ if (topWindow.TYPO3?.Backend?.ContentContainer) {
124
+ topWindow.TYPO3.Backend.ContentContainer.refresh();
125
+ }
126
+ Notification.success(
127
+ labels.get('notification.record_updated.title'),
128
+ savedRecordTitle !== '' ? labels.get('notification.record_updated.message', [savedRecordTitle]) : undefined,
129
+ );
130
+ } else {
131
+ focusTarget?.focus();
132
+ }
133
+ });
134
+ };
135
+
44
136
  @customElement('typo3-backend-contextual-record-edit-trigger')
45
137
  export class ContextualRecordEditTriggerElement extends PseudoButtonLitElement {
46
138
  @property({ type: String }) url: string;
@@ -49,74 +141,17 @@ export class ContextualRecordEditTriggerElement extends PseudoButtonLitElement {
49
141
 
50
142
  protected override async buttonActivated(): Promise<void> {
51
143
  if (Persistent.isset('contextualRecordEdit') && Persistent.get('contextualRecordEdit') == 0) {
52
- if (top?.TYPO3?.Backend?.ContentContainer) {
53
- top.TYPO3.Backend.ContentContainer.setUrl(this.editUrl);
144
+ if (topWindow.TYPO3?.Backend?.ContentContainer) {
145
+ topWindow.TYPO3.Backend.ContentContainer.setUrl(this.editUrl);
54
146
  }
55
147
  return;
56
148
  }
57
- const modal = Modal.advanced({
58
- type: Types.iframe,
59
- title: '',
60
- content: this.url,
61
- size: Sizes.expand,
62
- position: Positions.sheet,
63
- hideHeader: true,
64
- resizeIdentifier: `contextualEdit${this.context ? `.${this.context}` : ''}`,
65
- });
66
- this.setupMessageHandling(modal);
67
- }
68
-
69
- private setupMessageHandling(modal: ModalElement): void {
70
- const messageTarget = top;
71
- let savedRecordTitle = '';
72
- let hasSaved = false;
73
- let closeConfirmed = false;
74
- const messageHandler = (event: MessageEvent): void => {
75
- if (event.origin !== window.location.origin) {
76
- return;
77
- }
78
- if (event.data?.actionName === 'typo3:editform:saved') {
79
- hasSaved = true;
80
- savedRecordTitle = event.data.recordTitle ?? '';
81
- }
82
- if (event.data?.actionName === 'typo3:editform:closed') {
83
- closeConfirmed = true;
84
- modal.hideModal();
85
- }
86
- if (event.data?.actionName === 'typo3:editform:navigate') {
87
- closeConfirmed = true;
88
- modal.hideModal();
89
- }
90
- };
91
- messageTarget.addEventListener('message', messageHandler);
92
-
93
- modal.addEventListener('typo3-modal-hide', (e: Event): void => {
94
- if (closeConfirmed) {
95
- return;
96
- }
97
- e.preventDefault();
98
- const iframe = modal.querySelector('iframe') as HTMLIFrameElement | null;
99
- iframe?.contentWindow?.postMessage(
100
- { actionName: 'typo3:editform:requestclose' },
101
- window.location.origin
102
- );
103
- });
104
-
105
- modal.addEventListener('typo3-modal-hidden', () => {
106
- messageTarget.removeEventListener('message', messageHandler);
107
- if (hasSaved) {
108
- top.document.dispatchEvent(new CustomEvent('typo3:pagetree:refresh'));
109
- if (top.TYPO3?.Backend?.ContentContainer) {
110
- top.TYPO3.Backend.ContentContainer.refresh();
111
- }
112
- Notification.success(
113
- labels.get('notification.record_updated.title'),
114
- savedRecordTitle !== '' ? labels.get('notification.record_updated.message', [savedRecordTitle]) : undefined,
115
- );
116
- } else {
117
- this.focus();
118
- }
119
- });
149
+ // The sheet's handlers must live in the top window, since the content
150
+ // frame this trigger is rendered in may be reloaded while the sheet is open.
151
+ const { openContextualRecordEdit: open } = topWindow === window
152
+ ? { openContextualRecordEdit }
153
+ : await topLevelModuleImport('@typo3/backend/element/contextual-record-edit-trigger.js');
154
+ open(this.url, this.context, this);
120
155
  }
121
156
  }
122
157