typo3-typescript-sources 14.1.0 → 14.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/.last-synced-tag +1 -1
  2. package/README.md +1 -1
  3. package/backend/Contrib/bootstrap.ts +39 -0
  4. package/backend/action-button/deferred-action.ts +0 -2
  5. package/backend/action-button/immediate-action.ts +0 -2
  6. package/backend/action-dispatcher.ts +0 -2
  7. package/backend/bookmark/bookmark-manager.ts +1234 -0
  8. package/backend/bookmark/bookmark-store.ts +701 -0
  9. package/backend/bookmark/element/bookmark-button-element.ts +144 -0
  10. package/backend/bookmark/toolbar/bookmark-menu-element.ts +139 -0
  11. package/backend/clear-cache.ts +12 -4
  12. package/backend/clipboard-panel.ts +4 -4
  13. package/backend/code-editor/element/code-mirror-element.ts +6 -1
  14. package/backend/color-picker.ts +7 -5
  15. package/backend/color-scheme-switch.ts +1 -1
  16. package/backend/column-selector-button.ts +4 -4
  17. package/backend/context-menu-actions.ts +63 -9
  18. package/backend/context-menu.ts +3 -3
  19. package/backend/contextual-record-edit.ts +212 -0
  20. package/backend/copy-to-clipboard.ts +32 -13
  21. package/backend/date-time-picker.ts +7 -5
  22. package/backend/drag-tooltip.ts +1 -1
  23. package/backend/drag-uploader.ts +58 -43
  24. package/backend/dropdown.ts +317 -0
  25. package/backend/element/alert-element.ts +5 -5
  26. package/backend/element/breadcrumb.ts +162 -38
  27. package/backend/element/combobox-element.ts +3 -2
  28. package/backend/element/contextual-record-edit-trigger.ts +117 -0
  29. package/backend/element/datetime-element.ts +282 -0
  30. package/backend/element/dispatch-modal-button.ts +1 -1
  31. package/backend/element/draggable-resizable-element.ts +1 -1
  32. package/backend/element/editable-page-title.ts +8 -6
  33. package/backend/element/icon-element.ts +2 -2
  34. package/backend/element/link-browser-download-element.ts +86 -0
  35. package/backend/element/pagination.ts +4 -4
  36. package/backend/element/progress-bar-element.ts +6 -2
  37. package/backend/element/progress-tracker-element.ts +4 -4
  38. package/backend/element/pseudo-button.ts +1 -1
  39. package/backend/element/qrcode-element.ts +54 -7
  40. package/{redirects → backend}/element/qrcode-modal-button.ts +20 -14
  41. package/backend/element/sidebar-toggle-element.ts +1 -1
  42. package/backend/element/spinner-element.ts +1 -1
  43. package/backend/element-browser.ts +62 -6
  44. package/backend/event/form-engine-link-browser-set-link-event.ts +34 -0
  45. package/backend/form/submit-interceptor.ts +7 -5
  46. package/backend/form-engine/container/flex-form-container-container.ts +42 -32
  47. package/backend/form-engine/container/flex-form-section-container.ts +8 -28
  48. package/backend/form-engine/container/inline-control-container.ts +304 -293
  49. package/backend/form-engine/element/extra/char-counter.ts +3 -3
  50. package/backend/form-engine/element/online-media-form-element.ts +2 -2
  51. package/backend/form-engine/element/select-tree-toolbar.ts +6 -6
  52. package/backend/form-engine/element/select-tree.ts +1 -1
  53. package/backend/form-engine/element/suggest/result-container.ts +3 -3
  54. package/backend/form-engine/element/suggest/result-item.ts +1 -1
  55. package/backend/form-engine/element/table-wizard-element.ts +23 -22
  56. package/backend/form-engine/field-control/link-popup.ts +22 -3
  57. package/backend/form-engine/field-control/password-generator.ts +9 -3
  58. package/backend/form-engine-link-browser-adapter.ts +15 -86
  59. package/backend/form-engine-review.ts +9 -4
  60. package/backend/form-engine-validation.ts +13 -6
  61. package/backend/form-engine.ts +170 -113
  62. package/backend/grid-editor.ts +32 -29
  63. package/backend/hotkeys/events.ts +47 -0
  64. package/backend/hotkeys/hotkey-storage.ts +3 -18
  65. package/backend/hotkeys/hotkey-struct.ts +58 -0
  66. package/backend/hotkeys/negotiator.ts +53 -0
  67. package/backend/hotkeys.ts +27 -46
  68. package/backend/image-manipulation.ts +82 -2
  69. package/backend/input/clearable.ts +4 -3
  70. package/backend/layout-module/paste.ts +7 -6
  71. package/backend/link-browser.ts +1 -0
  72. package/backend/live-search/element/backend-search.ts +1 -1
  73. package/backend/live-search/element/hint.ts +1 -1
  74. package/backend/live-search/element/provider/default-result-item.ts +3 -3
  75. package/backend/live-search/element/provider/page-provider-result-item.ts +3 -3
  76. package/backend/live-search/element/result/item/action/action-container.ts +1 -1
  77. package/backend/live-search/element/result/item/action/action.ts +2 -2
  78. package/backend/live-search/element/result/item/item-container.ts +3 -3
  79. package/backend/live-search/element/result/item/item.ts +2 -1
  80. package/backend/live-search/element/result/result-container.ts +5 -5
  81. package/backend/live-search/element/result/result-detail-container.ts +1 -1
  82. package/backend/live-search/element/result/result-pagination.ts +2 -2
  83. package/backend/live-search/element/search-option-item.ts +2 -2
  84. package/backend/live-search/live-search-shortcut.ts +1 -14
  85. package/backend/{toolbar → live-search}/live-search.ts +10 -22
  86. package/backend/live-search/result-types/default-result-type.ts +6 -1
  87. package/backend/live-search/result-types/page-result-type.ts +2 -2
  88. package/backend/live-search/toolbar/live-search-toolbar-item.ts +24 -0
  89. package/backend/localization/finisher/localization-submission-service.ts +33 -0
  90. package/backend/localization/label-provider.ts +187 -0
  91. package/backend/localization/localization-button.ts +3 -3
  92. package/backend/localization/localization-wizard.ts +70 -351
  93. package/backend/localization/steps/content-record-selection-step.ts +35 -42
  94. package/backend/localization/steps/handler-selection-step.ts +27 -31
  95. package/backend/localization/steps/mode-step.ts +26 -30
  96. package/backend/localization/steps/source-language-step.ts +28 -30
  97. package/backend/localization/steps/target-language-step.ts +34 -35
  98. package/backend/login-refresh.ts +15 -14
  99. package/backend/modal.ts +81 -18
  100. package/backend/module/iframe.ts +5 -5
  101. package/backend/module/router.ts +1 -1
  102. package/backend/multi-record-selection-delete-action.ts +4 -2
  103. package/backend/multi-step-wizard.ts +7 -6
  104. package/backend/new-content-element-wizard-button.ts +1 -1
  105. package/backend/new-record-wizard.ts +14 -17
  106. package/backend/notification.ts +5 -5
  107. package/backend/online-media.ts +2 -1
  108. package/backend/page-wizard/finisher/page-wizard-submission-service.ts +42 -0
  109. package/backend/page-wizard/helper/wizard-helper.ts +34 -0
  110. package/backend/page-wizard/new-page-wizard-button.ts +32 -0
  111. package/backend/page-wizard/page-wizard-configuration.ts +20 -0
  112. package/backend/page-wizard/page-wizard.ts +114 -0
  113. package/backend/page-wizard/steps/doktype-step.ts +239 -0
  114. package/backend/page-wizard/steps/form-engine-step.ts +165 -0
  115. package/backend/page-wizard/steps/position-step.ts +158 -0
  116. package/backend/pagetsconfig/pagetsconfig-includes.ts +1 -1
  117. package/backend/record-download-button.ts +4 -4
  118. package/backend/security/element/csp-reports.ts +30 -30
  119. package/backend/security/element/sudo-mode.ts +1 -1
  120. package/backend/settings/editor/editable-setting.ts +7 -6
  121. package/backend/settings/editor.ts +9 -8
  122. package/backend/settings/type/base.ts +1 -1
  123. package/backend/settings/type/bool.ts +1 -1
  124. package/backend/settings/type/color.ts +1 -1
  125. package/backend/settings/type/int.ts +2 -2
  126. package/backend/settings/type/number.ts +2 -2
  127. package/backend/settings/type/page.ts +9 -5
  128. package/backend/settings/type/string.ts +2 -2
  129. package/backend/settings/type/stringlist.ts +1 -1
  130. package/backend/settings/type/url.ts +1 -1
  131. package/backend/sortable-table.ts +3 -2
  132. package/backend/switch-user.ts +1 -1
  133. package/backend/tab.ts +424 -0
  134. package/backend/tabs.ts +2 -59
  135. package/backend/tests/localization/label-provider-test.ts +72 -0
  136. package/backend/toolbar/clear-cache-menu.ts +12 -9
  137. package/backend/toolbar/system-information-menu.ts +6 -16
  138. package/backend/tree/file-storage-browser.ts +1 -1
  139. package/backend/tree/file-storage-tree-container.ts +14 -11
  140. package/backend/tree/page-browser.ts +13 -12
  141. package/backend/tree/page-position-select.ts +293 -0
  142. package/backend/tree/page-tree-element.ts +233 -83
  143. package/backend/tree/page-tree.ts +20 -0
  144. package/backend/tree/tree-module-state.ts +1 -1
  145. package/backend/tree/tree-node-toggle.ts +1 -1
  146. package/backend/tree/tree-toolbar.ts +43 -38
  147. package/backend/tree/tree.ts +69 -23
  148. package/backend/type/date-configuration.ts +31 -0
  149. package/backend/user-settings-manager.ts +34 -18
  150. package/backend/utility/collapse-state-search.ts +2 -1
  151. package/backend/viewport/content-container.ts +1 -1
  152. package/backend/viewport/content-navigation-toggle.ts +14 -4
  153. package/backend/viewport/content-navigation.ts +6 -6
  154. package/backend/viewport/loader.ts +6 -4
  155. package/backend/wizard/events/auto-advance-event.ts +21 -0
  156. package/backend/wizard/events/before-next-step-event.ts +24 -0
  157. package/backend/wizard/events/step-summary-event.ts +26 -0
  158. package/backend/wizard/finisher/finisher-config.ts +19 -0
  159. package/backend/{localization/localization-finisher.ts → wizard/finisher/finisher-interface.ts} +2 -11
  160. package/backend/wizard/finisher/finisher-result.ts +26 -0
  161. package/backend/{localization → wizard}/finisher/noop-finisher.ts +3 -2
  162. package/backend/{localization → wizard}/finisher/redirect-finisher.ts +3 -2
  163. package/backend/{localization → wizard}/finisher/reload-finisher.ts +4 -3
  164. package/backend/wizard/finisher/submission-service-interface.ts +17 -0
  165. package/backend/wizard/helper/dynamic-steps-loader.ts +60 -0
  166. package/backend/wizard/move-content-element.ts +14 -8
  167. package/backend/wizard/move-page.ts +7 -5
  168. package/backend/wizard/steps/confirm-step.ts +63 -0
  169. package/backend/{localization → wizard}/steps/finisher-step.ts +37 -61
  170. package/backend/wizard/steps/summary-item-interface.ts +19 -0
  171. package/backend/wizard/steps/wizard-step-after-render-interface.ts +16 -0
  172. package/backend/wizard/steps/wizard-step-interface.ts +26 -0
  173. package/backend/wizard/steps/wizard-step-summary-interface.ts +18 -0
  174. package/backend/wizard/steps/wizard-step-value-interface.ts +20 -0
  175. package/backend/wizard/wizard.ts +399 -0
  176. package/belog/backend-log.ts +8 -2
  177. package/core/authentication/mfa-provider/totp.ts +1 -1
  178. package/core/directive/markdown.ts +2 -2
  179. package/core/lit-helper.ts +2 -2
  180. package/core/utility/debug-exception-handler-service.ts +188 -0
  181. package/dashboard/dashboard.ts +51 -49
  182. package/dashboard/widget/bookmarks-widget-element.ts +140 -0
  183. package/extensionmanager/dependency-check.ts +179 -0
  184. package/extensionmanager/distribution-image.ts +1 -1
  185. package/extensionmanager/extension-toggle-button.ts +201 -0
  186. package/extensionmanager/main.ts +55 -69
  187. package/extensionmanager/repository.ts +22 -16
  188. package/extensionmanager/update.ts +4 -3
  189. package/filelist/context-menu-actions.ts +14 -13
  190. package/filelist/file-delete.ts +3 -2
  191. package/filelist/file-list-rename-handler.ts +6 -5
  192. package/filelist/file-list-replace-handler.ts +17 -14
  193. package/filelist/file-list-transfer-handler.ts +8 -11
  194. package/filelist/file-list.ts +38 -12
  195. package/filelist/rename-file.ts +9 -6
  196. package/form/backend/form-editor/component/date-editor.ts +265 -0
  197. package/form/backend/form-editor/component/form-element-selector.ts +74 -0
  198. package/form/backend/form-editor/component/form-element-stage-item-toolbar.ts +112 -0
  199. package/form/backend/form-editor/component/form-element-stage-item.ts +188 -0
  200. package/form/backend/form-editor/component/page-stage-item.ts +53 -0
  201. package/form/backend/form-editor/component/property-grid-editor.ts +54 -23
  202. package/form/backend/form-editor/core.ts +119 -105
  203. package/form/backend/form-editor/helper.ts +17 -10
  204. package/form/backend/form-editor/inspector-component.ts +689 -703
  205. package/form/backend/form-editor/mediator.ts +54 -43
  206. package/form/backend/form-editor/modals-component.ts +59 -61
  207. package/form/backend/form-editor/stage-component.ts +635 -328
  208. package/form/backend/form-editor/tree-component-adapter.ts +651 -0
  209. package/form/backend/form-editor/utility/string-utility.ts +33 -0
  210. package/form/backend/form-editor/view-model.ts +240 -229
  211. package/form/backend/form-editor-tree-container.ts +105 -0
  212. package/form/backend/form-editor-tree-events.ts +138 -0
  213. package/form/backend/form-editor-tree.ts +784 -0
  214. package/form/backend/form-editor.ts +26 -42
  215. package/form/backend/form-manager/view-model.ts +155 -674
  216. package/form/backend/form-manager.ts +26 -9
  217. package/form/backend/form-wizard/finisher/create-form-submission-service.ts +59 -0
  218. package/form/backend/form-wizard/finisher/duplicate-form-submission-service.ts +58 -0
  219. package/form/backend/form-wizard/form-wizard.ts +135 -0
  220. package/form/backend/form-wizard/steps/mode-step.ts +140 -0
  221. package/form/backend/form-wizard/steps/settings-step.ts +248 -0
  222. package/form/backend/form-wizard/steps/storage-step.ts +128 -0
  223. package/form/frontend/date-picker.ts +2 -0
  224. package/install/module/settings/extension-configuration.ts +0 -8
  225. package/install/module/settings/local-configuration.ts +0 -8
  226. package/install/renderable/flash-message.ts +1 -1
  227. package/install/renderable/info-box.ts +1 -1
  228. package/install/renderable/language-packs.ts +3 -3
  229. package/install/renderable/offset-group.ts +1 -1
  230. package/install/renderable/wrap-group.ts +1 -1
  231. package/install/router.ts +1 -1
  232. package/lowlevel/query-generator.ts +1 -1
  233. package/opendocs/open-document-store.ts +195 -0
  234. package/opendocs/toolbar/open-document-menu-element.ts +127 -0
  235. package/opendocs/widget/recent-documents-widget-element.ts +130 -0
  236. package/package.json +2 -2
  237. package/recycler/recycler.ts +55 -56
  238. package/redirects/event-handler.ts +15 -7
  239. package/redirects/short-url-generator.ts +145 -0
  240. package/rte-ckeditor/ckeditor5.ts +3 -3
  241. package/rte-ckeditor/plugin/typo3-link.ts +24 -4
  242. package/scheduler/new-scheduler-task-wizard-button.ts +1 -1
  243. package/scheduler/scheduler-add-group.ts +6 -6
  244. package/scheduler/setup-check-button.ts +1 -1
  245. package/styleguide/element/theme-switcher-element.ts +10 -9
  246. package/sys-note/element/delete-button.ts +1 -1
  247. package/tstemplate/template-analyzer.ts +1 -1
  248. package/workspaces/backend.ts +27 -25
  249. package/workspaces/element/workspace-selector-element.ts +186 -0
  250. package/workspaces/element/workspace-top-indicator-element.ts +159 -0
  251. package/workspaces/preview.ts +5 -4
  252. package/workspaces/renderable/comment-view.ts +3 -3
  253. package/workspaces/renderable/diff-view.ts +3 -3
  254. package/workspaces/renderable/history-view.ts +3 -3
  255. package/workspaces/renderable/record-information.ts +8 -12
  256. package/workspaces/renderable/record-table.ts +56 -32
  257. package/workspaces/renderable/send-to-stage-form.ts +14 -8
  258. package/workspaces/workspace-state.ts +251 -0
  259. package/workspaces/workspaces.ts +4 -5
  260. package/backend/form-engine/container/files-control-container.ts +0 -716
  261. package/backend/form-engine/container/site-language-container.ts +0 -616
  262. package/backend/key-bindings.ts +0 -42
  263. package/backend/localization/steps/confirm-step.ts +0 -61
  264. package/backend/toolbar/shortcut-menu.ts +0 -254
  265. package/form/backend/form-editor/tree-component.ts +0 -550
  266. package/opendocs/toolbar/opendocs-menu.ts +0 -117
  267. package/workspaces/toolbar/workspaces-menu.ts +0 -192
@@ -0,0 +1,701 @@
1
+ /*
2
+ * This file is part of the TYPO3 CMS project.
3
+ *
4
+ * It is free software; you can redistribute it and/or modify it under
5
+ * the terms of the GNU General Public License, either version 2
6
+ * of the License, or any later version.
7
+ *
8
+ * For the full copyright and license information, please read the
9
+ * LICENSE.txt file that was distributed with this source code.
10
+ *
11
+ * The TYPO3 project - inspiring people to share!
12
+ */
13
+
14
+ import AjaxRequest from '@typo3/core/ajax/ajax-request';
15
+ import type { AjaxResponse } from '@typo3/core/ajax/ajax-response';
16
+ import labels from '~labels/core.bookmarks';
17
+ import listLabels from '~labels/core.mod_web_list';
18
+ import Modal from '../modal';
19
+ import Notification from '../notification';
20
+ import { SeverityEnum } from '../enum/severity';
21
+ import { BroadcastMessage, type BroadcastEvent } from '@typo3/backend/broadcast-message';
22
+ import BroadcastService from '@typo3/backend/broadcast-service';
23
+
24
+ export const BookmarkStoreChangedEvent = 'typo3:bookmark-store:changed';
25
+
26
+ /**
27
+ * Number for system/global groups,
28
+ * UUID string for user-created groups.
29
+ */
30
+ export type BookmarkGroupId = number | string;
31
+
32
+ export enum BookmarkGroupType {
33
+ SYSTEM = 'system',
34
+ GLOBAL = 'global',
35
+ USER = 'user',
36
+ }
37
+
38
+ export interface Bookmark {
39
+ id: number;
40
+ route: string;
41
+ arguments: string;
42
+ title: string;
43
+ groupId: BookmarkGroupId;
44
+ iconIdentifier: string;
45
+ iconOverlayIdentifier: string;
46
+ module: string;
47
+ href: string;
48
+ editable: boolean;
49
+ accessible: boolean;
50
+ }
51
+
52
+ /**
53
+ * Bookmark group with type information.
54
+ *
55
+ * Group types:
56
+ * - system: Special reserved groups (e.g., Uncategorized with ID 0)
57
+ * - global: Negative ID groups, admin-only for adding, visible to all users
58
+ * - tsconfig: Groups defined via UserTSconfig (includes default bookmark groups)
59
+ * - user: User-created groups with UUID identifiers
60
+ */
61
+ export interface BookmarkGroup {
62
+ id: BookmarkGroupId;
63
+ label: string;
64
+ type: BookmarkGroupType;
65
+ priority: number;
66
+ sorting: number;
67
+ editable: boolean;
68
+ selectable: boolean;
69
+ }
70
+
71
+ interface BookmarkListResponse {
72
+ success: boolean;
73
+ bookmarks: Bookmark[];
74
+ groups: BookmarkGroup[];
75
+ }
76
+
77
+ interface BookmarkOperationResponse {
78
+ success: boolean;
79
+ error?: string;
80
+ bookmark?: Bookmark;
81
+ }
82
+
83
+ interface BookmarkDeleteResponse {
84
+ success: boolean;
85
+ error?: string;
86
+ }
87
+
88
+ interface BookmarkGroupCreateResponse {
89
+ success: boolean;
90
+ group?: BookmarkGroup;
91
+ error?: string;
92
+ }
93
+
94
+ interface BookmarkGroupOperationResponse {
95
+ success: boolean;
96
+ groups?: BookmarkGroup[];
97
+ error?: string;
98
+ }
99
+
100
+ export interface BookmarkStoreData {
101
+ bookmarks: Bookmark[];
102
+ groups: BookmarkGroup[];
103
+ }
104
+
105
+ /**
106
+ * Central state management for bookmarks with cached data, CRUD operations,
107
+ * cross-tab synchronization, and event-driven updates.
108
+ *
109
+ * Single source of truth: bookmarks Map (maintains insertion order) for server-defined ordering.
110
+ */
111
+ class BookmarkStore {
112
+ private readonly bookmarks: Map<number, Bookmark> = new Map();
113
+ private groups: BookmarkGroup[] = [];
114
+ private isLoaded: boolean = false;
115
+ private loadPromise: Promise<void> | null = null;
116
+
117
+ constructor() {
118
+ document.addEventListener('typo3:bookmark:broadcast', (event) => this.handleBroadcast(event as BroadcastEvent<BookmarkStoreData>));
119
+ }
120
+
121
+ /**
122
+ * Generates a composite key for bookmark lookup by route and arguments.
123
+ */
124
+ public getBookmarkKey(route: string, args: string): string {
125
+ return `${route}::${args}`;
126
+ }
127
+
128
+ public async isBookmarked(key: string): Promise<boolean> {
129
+ return (await this.getBookmark(key)) !== null;
130
+ }
131
+
132
+ public async getBookmark(key: string): Promise<Bookmark | null> {
133
+ await this.ready();
134
+ for (const bookmark of this.bookmarks.values()) {
135
+ if (this.getBookmarkKey(bookmark.route, bookmark.arguments) === key) {
136
+ return bookmark;
137
+ }
138
+ }
139
+ return null;
140
+ }
141
+
142
+ public async getBookmarks(): Promise<Bookmark[]> {
143
+ await this.ready();
144
+ return [...this.bookmarks.values()];
145
+ }
146
+
147
+ public async getGroups(): Promise<BookmarkGroup[]> {
148
+ await this.ready();
149
+ return [...this.groups];
150
+ }
151
+
152
+ /**
153
+ * Returns bookmarks grouped by groupId, sorted by group priority.
154
+ * Order: user → tsconfig → global → system.
155
+ * Within each priority level, groups are sorted by their position in the groups array (server-defined order).
156
+ * Optional filter by groupId and limit the total number of bookmarks.
157
+ */
158
+ public async getGroupedBookmarks(options?: { groupId?: BookmarkGroupId; limit?: number; accessibleOnly?: boolean }): Promise<Map<BookmarkGroupId, Bookmark[]>> {
159
+ let bookmarks = await this.getBookmarks();
160
+
161
+ if (options?.accessibleOnly) {
162
+ bookmarks = bookmarks.filter((b: Bookmark) => b.accessible);
163
+ }
164
+ if (options?.groupId !== undefined) {
165
+ bookmarks = bookmarks.filter((b: Bookmark) => b.groupId === options.groupId);
166
+ }
167
+ if (options?.limit !== undefined && options.limit > 0 && bookmarks.length > options.limit) {
168
+ bookmarks = bookmarks.slice(0, options.limit);
169
+ }
170
+
171
+ const grouped = new Map<BookmarkGroupId, Bookmark[]>();
172
+
173
+ // Build maps for sorting by priority and sorting
174
+ const groupPriorityMap = new Map<BookmarkGroupId, number>();
175
+ const groupSortingMap = new Map<BookmarkGroupId, number>();
176
+ this.groups.forEach((group) => {
177
+ groupPriorityMap.set(group.id, group.priority);
178
+ groupSortingMap.set(group.id, group.sorting);
179
+ });
180
+
181
+ const groupIds = [...new Set(bookmarks.map((b: Bookmark) => b.groupId))];
182
+ const sortedBookmarkGroupIds = groupIds.sort((a: BookmarkGroupId, b: BookmarkGroupId) => {
183
+ // First sort by priority (lower values first)
184
+ const priorityA = groupPriorityMap.get(a) ?? Number.MAX_SAFE_INTEGER;
185
+ const priorityB = groupPriorityMap.get(b) ?? Number.MAX_SAFE_INTEGER;
186
+ const priorityDiff = priorityA - priorityB;
187
+ if (priorityDiff !== 0) {
188
+ return priorityDiff;
189
+ }
190
+
191
+ // Within same priority, sort by sorting value
192
+ const sortingA = groupSortingMap.get(a) ?? Number.MAX_SAFE_INTEGER;
193
+ const sortingB = groupSortingMap.get(b) ?? Number.MAX_SAFE_INTEGER;
194
+ return sortingA - sortingB;
195
+ });
196
+
197
+ for (const groupId of sortedBookmarkGroupIds) {
198
+ const groupBookmarks = bookmarks.filter((b: Bookmark) => b.groupId === groupId);
199
+ if (groupBookmarks.length > 0) {
200
+ grouped.set(groupId, groupBookmarks);
201
+ }
202
+ }
203
+
204
+ return grouped;
205
+ }
206
+
207
+ /**
208
+ * Hydrates the store with server-rendered data, avoiding an initial AJAX request.
209
+ * Should be called once during page initialization.
210
+ */
211
+ public initialize(bookmarks: Bookmark[], groups: BookmarkGroup[]): void {
212
+ if (this.isLoaded) {
213
+ return;
214
+ }
215
+ this.load({ bookmarks, groups });
216
+ }
217
+
218
+ /**
219
+ * Creates bookmark on server and updates local cache.
220
+ */
221
+ public async create(
222
+ routeIdentifier: string,
223
+ args: string,
224
+ displayName?: string
225
+ ): Promise<BookmarkOperationResponse> {
226
+ try {
227
+ const response: AjaxResponse = await new AjaxRequest(
228
+ TYPO3.settings.ajaxUrls.bookmark_create
229
+ ).post({
230
+ routeIdentifier,
231
+ arguments: args,
232
+ displayName: displayName || '',
233
+ });
234
+
235
+ const data: BookmarkOperationResponse = await response.resolve();
236
+
237
+ if (data.success && data.bookmark) {
238
+ this.bookmarks.set(data.bookmark.id, data.bookmark);
239
+ this.notifyChanged();
240
+ }
241
+
242
+ return data;
243
+ } catch (error) {
244
+ console.error('Failed to create bookmark:', error);
245
+ return {
246
+ success: false,
247
+ error: labels.get('error.createFailed.message'),
248
+ };
249
+ }
250
+ }
251
+
252
+ /**
253
+ * Updates bookmark title and group on server and synchronizes local cache.
254
+ */
255
+ public async update(
256
+ id: number,
257
+ title: string,
258
+ groupId: BookmarkGroupId
259
+ ): Promise<BookmarkOperationResponse> {
260
+ try {
261
+ const response: AjaxResponse = await new AjaxRequest(
262
+ TYPO3.settings.ajaxUrls.bookmark_update
263
+ ).post({
264
+ bookmarkId: id,
265
+ bookmarkTitle: title,
266
+ bookmarkGroup: groupId,
267
+ });
268
+
269
+ const data: BookmarkOperationResponse = await response.resolve();
270
+
271
+ if (data.success && data.bookmark) {
272
+ this.bookmarks.set(data.bookmark.id, data.bookmark);
273
+ this.notifyChanged();
274
+ }
275
+
276
+ return data;
277
+ } catch (error) {
278
+ console.error('Failed to update bookmark:', error);
279
+ return {
280
+ success: false,
281
+ error: labels.get('error.updateFailed.message'),
282
+ };
283
+ }
284
+ }
285
+
286
+ /**
287
+ * Shows confirmation dialog and deletes bookmark if confirmed.
288
+ */
289
+ public requestDelete(id: number): void {
290
+ const bookmark = this.bookmarks.get(id);
291
+ if (!bookmark) {
292
+ return;
293
+ }
294
+
295
+ const confirmModal = Modal.confirm(
296
+ labels.get('delete'),
297
+ labels.get('confirmDelete.title'),
298
+ SeverityEnum.warning,
299
+ [
300
+ {
301
+ text: listLabels.get('button.cancel'),
302
+ btnClass: 'btn-default',
303
+ name: 'cancel',
304
+ trigger: () => confirmModal.hideModal(),
305
+ },
306
+ {
307
+ text: listLabels.get('button.delete'),
308
+ btnClass: 'btn-danger',
309
+ name: 'delete',
310
+ trigger: async () => {
311
+ confirmModal.hideModal();
312
+ const result = await this.delete(id);
313
+ if (result.success) {
314
+ Notification.success(
315
+ labels.get('success.deleted.title'),
316
+ labels.get('success.deleted.message')
317
+ );
318
+ } else {
319
+ Notification.error(
320
+ labels.get('error.deleteFailed.title'),
321
+ result.error || labels.get('error.deleteFailed.message')
322
+ );
323
+ }
324
+ },
325
+ },
326
+ ]
327
+ );
328
+ }
329
+
330
+ /**
331
+ * Deletes a bookmark from the server and local cache.
332
+ */
333
+ public async delete(id: number): Promise<BookmarkDeleteResponse> {
334
+ try {
335
+ const response: AjaxResponse = await new AjaxRequest(
336
+ TYPO3.settings.ajaxUrls.bookmark_delete
337
+ ).post({ bookmarkId: id });
338
+
339
+ const data: BookmarkDeleteResponse = await response.resolve();
340
+
341
+ if (data.success) {
342
+ this.bookmarks.delete(id);
343
+ this.notifyChanged();
344
+ }
345
+
346
+ return data;
347
+ } catch (error) {
348
+ console.error('Failed to delete bookmark:', error);
349
+ return {
350
+ success: false,
351
+ error: labels.get('error.deleteFailed.message')
352
+ };
353
+ }
354
+ }
355
+
356
+ /**
357
+ * Persists new bookmark order and updates local cache with server response.
358
+ */
359
+ public async reorder(ids: number[]): Promise<boolean> {
360
+ try {
361
+ const response: AjaxResponse = await new AjaxRequest(
362
+ TYPO3.settings.ajaxUrls.bookmark_reorder
363
+ ).post({
364
+ bookmarkIds: ids,
365
+ });
366
+
367
+ const data = await response.resolve();
368
+
369
+ if (data.success && data.bookmarks) {
370
+ this.bookmarks.clear();
371
+ for (const bookmark of data.bookmarks) {
372
+ this.bookmarks.set(bookmark.id, bookmark);
373
+ }
374
+ this.notifyChanged();
375
+ return true;
376
+ }
377
+
378
+ return false;
379
+ } catch (error) {
380
+ console.error('Failed to reorder bookmarks:', error);
381
+ return false;
382
+ }
383
+ }
384
+
385
+ /**
386
+ * Deletes multiple bookmarks in a single request.
387
+ */
388
+ public async deleteMultiple(ids: number[]): Promise<boolean> {
389
+ try {
390
+ const response: AjaxResponse = await new AjaxRequest(
391
+ TYPO3.settings.ajaxUrls.bookmark_delete_multiple
392
+ ).post({
393
+ bookmarkIds: ids,
394
+ });
395
+
396
+ const data = await response.resolve();
397
+
398
+ if (data.success) {
399
+ for (const id of ids) {
400
+ this.bookmarks.delete(id);
401
+ }
402
+ this.notifyChanged();
403
+ return true;
404
+ }
405
+
406
+ return false;
407
+ } catch (error) {
408
+ console.error('Failed to delete multiple bookmarks:', error);
409
+ return false;
410
+ }
411
+ }
412
+
413
+ /**
414
+ * Moves multiple bookmarks to a target group in a single request.
415
+ */
416
+ public async move(ids: number[], groupId: BookmarkGroupId): Promise<boolean> {
417
+ try {
418
+ const response: AjaxResponse = await new AjaxRequest(
419
+ TYPO3.settings.ajaxUrls.bookmark_move
420
+ ).post({
421
+ bookmarkIds: ids,
422
+ groupId,
423
+ });
424
+
425
+ const data = await response.resolve();
426
+
427
+ if (data.success) {
428
+ for (const id of ids) {
429
+ const bookmark = this.bookmarks.get(id);
430
+ if (bookmark) {
431
+ this.bookmarks.set(id, { ...bookmark, groupId });
432
+ }
433
+ }
434
+ this.notifyChanged();
435
+ return true;
436
+ }
437
+
438
+ return false;
439
+ } catch (error) {
440
+ console.error('Failed to move bookmarks:', error);
441
+ return false;
442
+ }
443
+ }
444
+
445
+ /**
446
+ * Clears cache and re-fetches all data from server.
447
+ */
448
+ public async refresh(): Promise<void> {
449
+ this.isLoaded = false;
450
+ this.loadPromise = null;
451
+ await this.fetchAll();
452
+ }
453
+
454
+ /**
455
+ * Creates a user-defined bookmark group.
456
+ */
457
+ public async createGroup(label: string): Promise<BookmarkGroupCreateResponse> {
458
+ try {
459
+ const response: AjaxResponse = await new AjaxRequest(TYPO3.settings.ajaxUrls.bookmark_group_create).post({
460
+ label,
461
+ });
462
+
463
+ const data: BookmarkGroupCreateResponse = await response.resolve();
464
+
465
+ if (data.success && data.group) {
466
+ this.groups.push(data.group);
467
+ this.notifyChanged();
468
+ }
469
+
470
+ return data;
471
+ } catch (error) {
472
+ console.error('Failed to create group:', error);
473
+ return {
474
+ success: false,
475
+ error: labels.get('error.groupCreateFailed.message')
476
+ };
477
+ }
478
+ }
479
+
480
+ /**
481
+ * Renames a user-created group. System groups cannot be modified.
482
+ */
483
+ public async updateGroup(uuid: string, label: string): Promise<BookmarkGroupOperationResponse> {
484
+ try {
485
+ const response: AjaxResponse = await new AjaxRequest(TYPO3.settings.ajaxUrls.bookmark_group_update).post({
486
+ uuid,
487
+ label,
488
+ });
489
+ const data: BookmarkGroupOperationResponse = await response.resolve();
490
+
491
+ if (data.success && data.groups) {
492
+ this.groups = data.groups;
493
+ this.notifyChanged();
494
+ }
495
+
496
+ return data;
497
+ } catch (error) {
498
+ console.error('Failed to update group:', error);
499
+ return {
500
+ success: false,
501
+ error: labels.get('error.groupUpdateFailed.message')
502
+ };
503
+ }
504
+ }
505
+
506
+ /**
507
+ * Deletes a user-created group. Contained bookmarks move to the default group.
508
+ */
509
+ public async deleteGroup(uuid: string): Promise<BookmarkGroupOperationResponse> {
510
+ try {
511
+ const response: AjaxResponse = await new AjaxRequest(TYPO3.settings.ajaxUrls.bookmark_group_delete).post({
512
+ uuid,
513
+ });
514
+
515
+ const data: BookmarkGroupOperationResponse = await response.resolve();
516
+
517
+ if (data.success && data.groups) {
518
+ this.groups = data.groups;
519
+ await this.refresh();
520
+ this.notifyChanged();
521
+ }
522
+
523
+ return data;
524
+ } catch (error) {
525
+ console.error('Failed to delete group:', error);
526
+ return {
527
+ success: false,
528
+ error: labels.get('error.groupDeleteFailed.message')
529
+ };
530
+ }
531
+ }
532
+
533
+ /**
534
+ * Reorders user-created groups.
535
+ */
536
+ public async reorderGroups(uuids: string[]): Promise<BookmarkGroupOperationResponse> {
537
+ try {
538
+ const response: AjaxResponse = await new AjaxRequest(TYPO3.settings.ajaxUrls.bookmark_group_reorder).post({
539
+ uuids,
540
+ });
541
+
542
+ const data: BookmarkGroupOperationResponse = await response.resolve();
543
+
544
+ if (data.success && data.groups) {
545
+ this.groups = data.groups;
546
+ this.notifyChanged();
547
+ }
548
+
549
+ return data;
550
+ } catch (error) {
551
+ console.error('Failed to reorder groups:', error);
552
+ return {
553
+ success: false,
554
+ error: labels.get('error.groupReorderFailed.message')
555
+ };
556
+ }
557
+ }
558
+
559
+ /**
560
+ * Navigates to a bookmark using the module router, with fallback to direct navigation.
561
+ */
562
+ public navigate(bookmark: Bookmark): void {
563
+ const router = document.querySelector('typo3-backend-module-router');
564
+ if (router === null) {
565
+ throw new Error('Router not available.');
566
+ }
567
+
568
+ router.setAttribute('endpoint', bookmark.href);
569
+ router.setAttribute('module', bookmark.module);
570
+ }
571
+
572
+ /**
573
+ * Resolves when the store has been initialized or fetched.
574
+ */
575
+ private async ready(): Promise<void> {
576
+ if (this.isLoaded) {
577
+ return;
578
+ }
579
+ await this.fetchAll();
580
+ }
581
+
582
+ /**
583
+ * Fetches bookmarks from server if not already loaded.
584
+ * Returns immediately if store was already initialized.
585
+ * Deduplicates concurrent requests.
586
+ */
587
+ private async fetchAll(): Promise<Bookmark[]> {
588
+ if (this.isLoaded) {
589
+ return [...this.bookmarks.values()];
590
+ }
591
+
592
+ if (!this.loadPromise) {
593
+ this.loadPromise = this.doFetch();
594
+ }
595
+ await this.loadPromise;
596
+
597
+ return [...this.bookmarks.values()];
598
+ }
599
+
600
+ /**
601
+ * Sorts groups by priority (lower first) then by sorting value.
602
+ */
603
+ private sortGroups(groups: BookmarkGroup[]): BookmarkGroup[] {
604
+ return groups.sort((a, b) => {
605
+ const priorityDiff = a.priority - b.priority;
606
+ if (priorityDiff !== 0) {
607
+ return priorityDiff;
608
+ }
609
+ return a.sorting - b.sorting;
610
+ });
611
+ }
612
+
613
+ /**
614
+ * Synchronizes local cache with data from another tab's broadcast.
615
+ */
616
+ private handleBroadcast(event: BroadcastEvent<BookmarkStoreData>): void {
617
+ this.load(event.detail.payload);
618
+ this.notifyChanged(false);
619
+ }
620
+
621
+ /**
622
+ * Replaces store contents with provided data.
623
+ */
624
+ private load(data: BookmarkStoreData): void {
625
+ this.bookmarks.clear();
626
+ for (const bookmark of data.bookmarks) {
627
+ this.bookmarks.set(bookmark.id, bookmark);
628
+ }
629
+ this.groups = this.sortGroups(data.groups);
630
+ this.isLoaded = true;
631
+ }
632
+
633
+ /**
634
+ * Dispatches change event to all frames and optionally broadcasts to other tabs.
635
+ * @param broadcast - Whether to broadcast changes to other tabs (default: true)
636
+ */
637
+ private notifyChanged(broadcast: boolean = true): void {
638
+ const event = new CustomEvent(BookmarkStoreChangedEvent);
639
+ document.dispatchEvent(event);
640
+ for (let i = 0; i < window.frames.length; i++) {
641
+ try {
642
+ window.frames[i].document.dispatchEvent(event);
643
+ } catch {
644
+ // Cross-origin frame, skip
645
+ }
646
+ }
647
+
648
+ if (broadcast) {
649
+ BroadcastService.post(new BroadcastMessage('bookmark', 'broadcast', {
650
+ bookmarks: [...this.bookmarks.values()],
651
+ groups: [...this.groups],
652
+ }));
653
+ }
654
+ }
655
+
656
+ /**
657
+ * Fetches bookmark data from server and rebuilds local cache.
658
+ */
659
+ private async doFetch(): Promise<void> {
660
+ try {
661
+ const url = TYPO3.settings.ajaxUrls.bookmark_list;
662
+ if (!url) {
663
+ console.warn('BookmarkStore: bookmark_list URL not available yet');
664
+ return;
665
+ }
666
+
667
+ const response: AjaxResponse = await new AjaxRequest(url).get({ cache: 'no-cache' });
668
+ const data: BookmarkListResponse = await response.resolve();
669
+
670
+ if (data.success) {
671
+ this.load(data);
672
+ this.notifyChanged(false);
673
+ }
674
+ } catch (error) {
675
+ console.error('Failed to fetch bookmarks:', error);
676
+ throw error;
677
+ }
678
+ }
679
+
680
+ }
681
+
682
+ /**
683
+ * Returns singleton instance from top frame, creating it if needed.
684
+ */
685
+ function getOrCreateInstance(): BookmarkStore {
686
+ try {
687
+ if (top?.TYPO3?.BookmarkStore) {
688
+ return top.TYPO3.BookmarkStore;
689
+ }
690
+ const instance = new BookmarkStore();
691
+ if (top?.TYPO3) {
692
+ top.TYPO3.BookmarkStore = instance;
693
+ }
694
+ return instance;
695
+ } catch {
696
+ // Cross-origin access denied, create local instance
697
+ return new BookmarkStore();
698
+ }
699
+ }
700
+
701
+ export default getOrCreateInstance();