typo3-typescript-sources 14.3.5 → 14.3.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/.last-synced-tag +1 -1
- package/README-TYPO3.md +1 -1
- package/README.md +1 -1
- package/backend/element/contextual-record-edit-trigger.ts +9 -1
- package/backend/form-engine/element/extra/select-box-filter.ts +8 -5
- package/backend/form-engine/element/select-tree.ts +16 -2
- package/backend/form-engine/element/slug-element.ts +13 -5
- package/backend/form-engine/field-control/add-record.ts +27 -1
- package/backend/form-engine.ts +80 -1
- package/backend/layout-module/sticky-language-header.ts +186 -0
- package/backend/live-search/element/result/item/item.ts +2 -0
- package/backend/live-search/element/result/result-detail-container.ts +14 -1
- package/backend/localization/localization-wizard.ts +3 -0
- package/backend/localization/steps/handler-selection-step.ts +12 -17
- package/backend/localization/steps/mode-step.ts +9 -14
- package/backend/localization/steps/source-language-step.ts +8 -13
- package/backend/localization/steps/target-language-step.ts +12 -17
- package/backend/modal.ts +124 -1
- package/backend/module-docheader.ts +58 -0
- package/backend/page-wizard/steps/position-step.ts +5 -0
- package/backend/tests/form-engine/element/extra/select-box-filter-test.ts +215 -0
- package/backend/tests/form-engine/element/select-tree-test.ts +121 -0
- package/backend/tree/page-position-select.ts +25 -0
- package/backend/wizard/finisher/event-finisher.ts +62 -0
- package/backend/wizard/steps/finisher-step.ts +2 -2
- package/backend/wizard/wizard.ts +110 -7
- package/core/ajax/ajax-request.ts +18 -0
- package/core/tests/ajax/ajax-request-test.ts +1 -1
- package/core/tests/utility/text-normalizer-test.ts +138 -0
- package/core/utility/text-normalizer.ts +98 -0
- package/dashboard/dashboard-wizard.ts +86 -0
- package/dashboard/dashboard.ts +28 -76
- package/dashboard/wizard/finisher/dashboard-wizard-submission-service.ts +43 -0
- package/dashboard/wizard/steps/preset-step.ts +164 -0
- package/dashboard/wizard/steps/title-step.ts +90 -0
- package/form/backend/form-editor/core.ts +22 -9
- package/form/backend/form-editor/inspector-component.ts +61 -38
- package/form/backend/form-editor/stage-component.ts +2 -2
- package/form/backend/form-editor/view-model.ts +1 -1
- package/form/backend/form-wizard/form-wizard.ts +1 -0
- package/form/backend/form-wizard/steps/settings-step.ts +6 -13
- package/package.json +2 -2
- package/workspaces/backend.ts +7 -2
- package/workspaces/renderable/comment-view.ts +4 -2
- package/workspaces/renderable/record-table.ts +41 -4
- package/workspaces/workspaces.ts +65 -12
|
@@ -56,6 +56,21 @@ export class InsertPositionChangeEvent extends CustomEvent<{pageUid: number, pos
|
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
|
|
60
|
+
export class InsertPositionConfirmEvent extends CustomEvent<{pageUid: number, position: Position}> {
|
|
61
|
+
static readonly eventName = 'typo3:page-position-select-tree:insert-position-confirm';
|
|
62
|
+
constructor(pageUid: number, position: Position) {
|
|
63
|
+
super(InsertPositionConfirmEvent.eventName, {
|
|
64
|
+
detail: {
|
|
65
|
+
pageUid: pageUid,
|
|
66
|
+
position: position,
|
|
67
|
+
},
|
|
68
|
+
bubbles: true,
|
|
69
|
+
composed: true
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
59
74
|
@customElement('typo3-backend-component-page-position-select-tree')
|
|
60
75
|
export class PagePositionSelectTree extends PageTree {
|
|
61
76
|
|
|
@@ -140,6 +155,16 @@ export class PagePositionSelect extends LitElement {
|
|
|
140
155
|
|
|
141
156
|
private async handleNodeSelected(event: CustomEvent): Promise<void> {
|
|
142
157
|
const selectedNode: TreeNodeInterface = event.detail.node;
|
|
158
|
+
|
|
159
|
+
// Re-selecting the active node confirms it and advances the wizard.
|
|
160
|
+
if (this.isActivePagePositionNode(selectedNode)) {
|
|
161
|
+
this.dispatchEvent(new InsertPositionConfirmEvent(
|
|
162
|
+
this.activePageId,
|
|
163
|
+
this.insertPosition
|
|
164
|
+
));
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
143
168
|
const [pageUid, insertPosition] = selectedNode.identifier.split('-');
|
|
144
169
|
this.insertPosition = (insertPosition ?? 'inside') as Position;
|
|
145
170
|
this.activePageId = Number(pageUid);
|
|
@@ -0,0 +1,62 @@
|
|
|
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 { html, type TemplateResult } from 'lit';
|
|
15
|
+
import type { FinisherInterface } from '@typo3/backend/wizard/finisher/finisher-interface';
|
|
16
|
+
import type { FinisherConfig } from '@typo3/backend/wizard/finisher/finisher-config';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Event finisher - dispatches the event supplied via `config.data.event` when
|
|
20
|
+
* the wizard finishes.
|
|
21
|
+
*
|
|
22
|
+
* The wizard runs in the top window while backend modules live in content
|
|
23
|
+
* frames, so the event is broadcast to the top document and every child frame,
|
|
24
|
+
* where the module that opened the wizard (e.g. the dashboard) can listen for
|
|
25
|
+
* it on its own document and update in place instead of reloading.
|
|
26
|
+
*/
|
|
27
|
+
export default class EventFinisher implements FinisherInterface {
|
|
28
|
+
private config!: FinisherConfig;
|
|
29
|
+
|
|
30
|
+
public setConfig(config: FinisherConfig): void {
|
|
31
|
+
this.config = config;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async render(): Promise<TemplateResult> {
|
|
35
|
+
return html`
|
|
36
|
+
<typo3-backend-alert
|
|
37
|
+
severity="0"
|
|
38
|
+
heading="${this.config.labels.successTitle}"
|
|
39
|
+
message="${this.config.labels.successDescription}"
|
|
40
|
+
show-icon
|
|
41
|
+
></typo3-backend-alert>
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async execute(): Promise<void> {
|
|
46
|
+
const event = this.config.data.event;
|
|
47
|
+
|
|
48
|
+
if (!(event instanceof Event)) {
|
|
49
|
+
console.warn('Event finisher called without an event to dispatch');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
document.dispatchEvent(event);
|
|
54
|
+
for (let i = 0; i < window.frames.length; i++) {
|
|
55
|
+
try {
|
|
56
|
+
window.frames[i].document.dispatchEvent(event);
|
|
57
|
+
} catch {
|
|
58
|
+
// Cross-origin frame, skip
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -33,9 +33,9 @@ export class FinisherStep implements WizardStepInterface {
|
|
|
33
33
|
readonly autoAdvance = false;
|
|
34
34
|
|
|
35
35
|
public resetButtonTitle: string = null;
|
|
36
|
+
public hasError = false;
|
|
36
37
|
|
|
37
38
|
private finisherInstance: FinisherInterface | null = null;
|
|
38
|
-
private hasError = false;
|
|
39
39
|
private readonly task: Task<[SubmissionServiceInterface], FinisherResult>;
|
|
40
40
|
|
|
41
41
|
constructor(private readonly wizard: Wizard, private readonly finisher: SubmissionServiceInterface) {
|
|
@@ -55,7 +55,7 @@ export class FinisherStep implements WizardStepInterface {
|
|
|
55
55
|
public isComplete(): boolean {
|
|
56
56
|
// Finisher step is complete when the task has finished (success or error)
|
|
57
57
|
// This allows the user to close the wizard even when there's an error
|
|
58
|
-
return this.task.status === TaskStatus.COMPLETE;
|
|
58
|
+
return this.task.status === TaskStatus.COMPLETE || this.task.status === TaskStatus.ERROR;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
public async beforeAdvance(): Promise<void> {
|
package/backend/wizard/wizard.ts
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
import { html, LitElement, nothing, type PropertyValues, type TemplateResult } from 'lit';
|
|
15
15
|
import { customElement, property, state } from 'lit/decorators.js';
|
|
16
16
|
import { classMap } from 'lit/directives/class-map.js';
|
|
17
|
+
import { createRef, ref, type Ref } from 'lit/directives/ref.js';
|
|
18
|
+
import { KeyTypesEnum } from '@typo3/backend/enum/key-types';
|
|
17
19
|
import Modal from '@typo3/backend/modal';
|
|
18
20
|
import '@typo3/backend/element/alert-element';
|
|
19
21
|
import '@typo3/backend/element/icon-element';
|
|
@@ -41,6 +43,7 @@ type DataStoreKey = keyof DataStore;
|
|
|
41
43
|
export class Wizard extends LitElement {
|
|
42
44
|
@property({ type: Array, attribute: false }) steps: WizardStepInterface[] = [];
|
|
43
45
|
@property({ type: String, attribute: 'confirm-button-label' }) confirmButtonLabel: string;
|
|
46
|
+
@property({ type: Boolean, attribute: 'skip-summary' }) skipSummary: boolean = false;
|
|
44
47
|
@property({ type: Object, attribute: false }) submissionService: SubmissionServiceInterface;
|
|
45
48
|
|
|
46
49
|
@state() protected currentStepIndex: number = 0;
|
|
@@ -49,6 +52,8 @@ export class Wizard extends LitElement {
|
|
|
49
52
|
@state() protected allSteps: WizardStepInterface[] = [];
|
|
50
53
|
|
|
51
54
|
private progressTracker: ProgressTrackerElement | null = null;
|
|
55
|
+
private readonly primaryButtonRef: Ref<HTMLButtonElement> = createRef();
|
|
56
|
+
private focusPendingStep: WizardStepInterface | null = null;
|
|
52
57
|
|
|
53
58
|
override connectedCallback(): void {
|
|
54
59
|
super.connectedCallback();
|
|
@@ -144,7 +149,7 @@ export class Wizard extends LitElement {
|
|
|
144
149
|
return html`
|
|
145
150
|
<div class="wizard">
|
|
146
151
|
<div class="wizard-progress">${this.renderProgressTracker()}</div>
|
|
147
|
-
<div class="wizard-content" aria-live="polite">${this.currentStep?.render()}</div>
|
|
152
|
+
<div class="wizard-content" aria-live="polite" @keydown=${this.handleContentKeydown}>${this.currentStep?.render()}</div>
|
|
148
153
|
<div class="wizard-actions">${this.renderWizardButtons()}</div>
|
|
149
154
|
</div>
|
|
150
155
|
`;
|
|
@@ -177,7 +182,7 @@ export class Wizard extends LitElement {
|
|
|
177
182
|
) {
|
|
178
183
|
this.allSteps = [
|
|
179
184
|
...this.steps,
|
|
180
|
-
new ConfirmStep(this),
|
|
185
|
+
...(this.skipSummary ? [] : [new ConfirmStep(this)]),
|
|
181
186
|
new FinisherStep(this, this.submissionService),
|
|
182
187
|
];
|
|
183
188
|
|
|
@@ -188,11 +193,85 @@ export class Wizard extends LitElement {
|
|
|
188
193
|
}
|
|
189
194
|
|
|
190
195
|
if (this.currentStep && _changedProperties.has('currentStep')) {
|
|
196
|
+
// Optional per-step readiness hook (e.g. reinitialising FormEngine).
|
|
191
197
|
if (this.hasAfterRender(this.currentStep)) {
|
|
192
198
|
await this.currentStep.afterRender();
|
|
193
199
|
this.requestUpdate();
|
|
194
200
|
}
|
|
201
|
+
this.focusPendingStep = this.currentStep;
|
|
195
202
|
}
|
|
203
|
+
|
|
204
|
+
await this.moveFocusIntoStep();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Move focus into the current step's content once present. Async steps (e.g.
|
|
209
|
+
* @lit/task) re-render the wizard when their data settles, so retry on every
|
|
210
|
+
* update until a focus target is found — no per-step focus wiring required.
|
|
211
|
+
*/
|
|
212
|
+
private async moveFocusIntoStep(): Promise<void> {
|
|
213
|
+
const step = this.focusPendingStep;
|
|
214
|
+
if (!step || step !== this.currentStep) {
|
|
215
|
+
this.focusPendingStep = null; // no request, or navigated on since
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
await this.updateComplete;
|
|
219
|
+
if (step === this.currentStep && this.focusStepContent()) {
|
|
220
|
+
this.focusPendingStep = null;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Focus the selected radio, otherwise the first form control. Returns whether
|
|
226
|
+
* focus settled on the step's own content; the primary-button fall back
|
|
227
|
+
* returns `false` so async content can still claim focus once it renders.
|
|
228
|
+
*/
|
|
229
|
+
private focusStepContent(): boolean {
|
|
230
|
+
const content = this.renderRoot.querySelector('.wizard-content');
|
|
231
|
+
if (content) {
|
|
232
|
+
// Don't steal focus if the step already has a focus.
|
|
233
|
+
if (content.contains(this.ownerDocument.activeElement)) {
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const target = this.findFocusTarget(content);
|
|
238
|
+
if (target) {
|
|
239
|
+
// autofocus makes an opening modal <dialog> pick this over the close
|
|
240
|
+
// button; focus() covers later step transitions.
|
|
241
|
+
target.setAttribute('autofocus', '');
|
|
242
|
+
target.focus();
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// No focusable content (yet): fall back to the primary button, but not if
|
|
248
|
+
// focus already rests on an action button (don't steal it on re-renders).
|
|
249
|
+
const actions = this.renderRoot.querySelector('.wizard-actions');
|
|
250
|
+
if (!actions?.contains(this.ownerDocument.activeElement)) {
|
|
251
|
+
this.primaryButtonRef.value?.focus();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Explicit autofocus wins, then the selected radio, then the first control
|
|
259
|
+
* that is enabled and visible. Shadow roots are not pierced — custom
|
|
260
|
+
* elements take part by declaring autofocus or tabindex="0" on their host.
|
|
261
|
+
*/
|
|
262
|
+
private findFocusTarget(content: Element): HTMLElement | null {
|
|
263
|
+
const firstOperable = (selector: string): HTMLElement | null => {
|
|
264
|
+
for (const element of content.querySelectorAll<HTMLElement>(selector)) {
|
|
265
|
+
if (!element.matches(':disabled') && element.checkVisibility()) {
|
|
266
|
+
return element;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return null;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
return firstOperable('[autofocus]')
|
|
273
|
+
?? firstOperable('input[type="radio"]:checked')
|
|
274
|
+
?? firstOperable('input:not([type="hidden"]):not([type="radio"]):not([readonly]), select, button, textarea:not([readonly]), [contenteditable]:not([contenteditable="false"]), [tabindex]:not([tabindex="-1"])');
|
|
196
275
|
}
|
|
197
276
|
|
|
198
277
|
private hasAfterRender(step: WizardStepInterface): step is WizardStepInterface & WizardStepAfterRenderInterface {
|
|
@@ -211,6 +290,23 @@ export class Wizard extends LitElement {
|
|
|
211
290
|
this.tryAutoAdvance();
|
|
212
291
|
};
|
|
213
292
|
|
|
293
|
+
/**
|
|
294
|
+
* Enter inside a bare input advances the wizard, emulating a form submit.
|
|
295
|
+
* Controls with their own Enter behaviour are left alone: inputs inside a
|
|
296
|
+
* <form>, search inputs, checkboxes and non-input controls.
|
|
297
|
+
*/
|
|
298
|
+
private readonly handleContentKeydown = (event: KeyboardEvent): void => {
|
|
299
|
+
if (event.key !== KeyTypesEnum.ENTER) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const target = event.target;
|
|
303
|
+
if (!(target instanceof HTMLInputElement) || target.form || target.type === 'search' || target.type === 'checkbox') {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
event.preventDefault();
|
|
307
|
+
void this.handleNext();
|
|
308
|
+
};
|
|
309
|
+
|
|
214
310
|
private renderWizardButtons(): TemplateResult {
|
|
215
311
|
return html`
|
|
216
312
|
${this.renderPreviousButton()}
|
|
@@ -236,13 +332,20 @@ export class Wizard extends LitElement {
|
|
|
236
332
|
private renderNextButtons(): TemplateResult {
|
|
237
333
|
const isComplete = this.currentStep?.isComplete();
|
|
238
334
|
let buttonLabel: string;
|
|
335
|
+
let buttonIcon: string = 'actions-arrow-end-alt';
|
|
239
336
|
let resetButtonHtml: TemplateResult | typeof nothing = nothing;
|
|
240
337
|
|
|
241
338
|
if (this.currentStep?.key === 'finisher') {
|
|
242
|
-
buttonLabel = wizardLabels.get('wizard.buttons.finish');
|
|
243
|
-
|
|
244
339
|
const finisherStep: FinisherStep = this.currentStep as FinisherStep;
|
|
245
|
-
if (finisherStep
|
|
340
|
+
if (finisherStep.hasError) {
|
|
341
|
+
// On failure the primary action only closes the wizard
|
|
342
|
+
buttonLabel = wizardLabels.get('wizard.buttons.close');
|
|
343
|
+
buttonIcon = 'actions-close';
|
|
344
|
+
} else {
|
|
345
|
+
buttonLabel = wizardLabels.get('wizard.buttons.finish');
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (!finisherStep.hasError && finisherStep?.resetButtonTitle) {
|
|
246
349
|
resetButtonHtml = html`
|
|
247
350
|
<button type="button" class="${classMap({ 'btn': true, 'btn-secondary': true })}"
|
|
248
351
|
@click="${this.handleRestart}"
|
|
@@ -261,11 +364,11 @@ export class Wizard extends LitElement {
|
|
|
261
364
|
return html`
|
|
262
365
|
<div>
|
|
263
366
|
${resetButtonHtml}
|
|
264
|
-
<button type="button" class="${classMap({ 'btn': true, 'btn-primary': true, 'disabled': !isComplete })}"
|
|
367
|
+
<button type="button" ${ref(this.primaryButtonRef)} class="${classMap({ 'btn': true, 'btn-primary': true, 'disabled': !isComplete })}"
|
|
265
368
|
@click="${this.handleNext}"
|
|
266
369
|
>
|
|
267
370
|
${buttonLabel}
|
|
268
|
-
<typo3-backend-icon identifier="
|
|
371
|
+
<typo3-backend-icon identifier="${buttonIcon}" bidi size="small"></typo3-backend-icon>
|
|
269
372
|
</button>
|
|
270
373
|
</div>
|
|
271
374
|
`;
|
|
@@ -117,6 +117,24 @@ class AjaxRequest {
|
|
|
117
117
|
return new AjaxResponse(response);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Executes a (by default uncached) PATCH request
|
|
122
|
+
*
|
|
123
|
+
* @param {string | FormData | GenericKeyValue} data
|
|
124
|
+
* @param {RequestInit} init
|
|
125
|
+
* @return {Promise<Response>}
|
|
126
|
+
*/
|
|
127
|
+
public async patch(data: string | FormData | GenericKeyValue, init: RequestInit = {}): Promise<AjaxResponse> {
|
|
128
|
+
const localDefaultOptions: RequestInit = {
|
|
129
|
+
body: typeof data === 'string' || data instanceof FormData ? data : InputTransformer.byHeader(data, init?.headers),
|
|
130
|
+
cache: 'no-cache',
|
|
131
|
+
method: 'PATCH',
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const response = await this.send({ ...localDefaultOptions, ...init });
|
|
135
|
+
return new AjaxResponse(response);
|
|
136
|
+
}
|
|
137
|
+
|
|
120
138
|
/**
|
|
121
139
|
* Executes a regular DELETE request
|
|
122
140
|
*
|
|
@@ -50,7 +50,7 @@ describe('@typo3/core/ajax/ajax-request', (): void => {
|
|
|
50
50
|
expect(fetchStub).calledWithMatch(new Request('https://example.com/', { method: 'POST', body: '' }));
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
for (const requestMethod of ['POST', 'PUT', 'DELETE']) {
|
|
53
|
+
for (const requestMethod of ['POST', 'PUT', 'PATCH', 'DELETE']) {
|
|
54
54
|
describe(`send a ${requestMethod} request`, (): void => {
|
|
55
55
|
function* requestDataProvider(): any {
|
|
56
56
|
yield [
|
|
@@ -0,0 +1,138 @@
|
|
|
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 TextNormalizer from '@typo3/core/utility/text-normalizer.js';
|
|
15
|
+
import { expect } from '@open-wc/testing';
|
|
16
|
+
import type { } from 'mocha';
|
|
17
|
+
|
|
18
|
+
describe('@typo3/core/utility/text-normalizer', () => {
|
|
19
|
+
describe('foldCaseAndDiacritics', () => {
|
|
20
|
+
it('returns an empty string unchanged', (): void => {
|
|
21
|
+
expect(TextNormalizer.foldCaseAndDiacritics('')).to.equal('');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('lowercases the value', (): void => {
|
|
25
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Cremeschnitte')).to.equal('cremeschnitte');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('removes Latin diacritics', (): void => {
|
|
29
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Crème brûlée')).to.equal('creme brulee');
|
|
30
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Müller')).to.equal('muller');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('removes Greek and Cyrillic diacritics', (): void => {
|
|
34
|
+
expect(TextNormalizer.foldCaseAndDiacritics('ΆΘΗΝΑ')).to.equal('αθηνα');
|
|
35
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Ёлка')).to.equal('елка');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('removes every Vietnamese tone mark', (): void => {
|
|
39
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Tiếng Việt')).to.equal('tieng viet');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('folds a value that is already decomposed to the same result', (): void => {
|
|
43
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Crème'.normalize('NFD'))).to.equal(TextNormalizer.foldCaseAndDiacritics('Crème'.normalize('NFC')));
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// A locale aware mapping folds this to a dotless "ı" on a Turkish browser.
|
|
47
|
+
it('folds the capital i to a plain lowercase i', (): void => {
|
|
48
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Import')).to.equal('import');
|
|
49
|
+
expect(TextNormalizer.foldCaseAndDiacritics('İstanbul')).to.equal('istanbul');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('spells out the Latin letters that do not decompose', (): void => {
|
|
53
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Straße')).to.equal('strasse');
|
|
54
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Ærø')).to.equal('aero');
|
|
55
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Łódź')).to.equal('lodz');
|
|
56
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Þórður')).to.equal('thordur');
|
|
57
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Đà Nẵng')).to.equal('da nang');
|
|
58
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Ħamrun')).to.equal('hamrun');
|
|
59
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Cœur')).to.equal('coeur');
|
|
60
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Kız')).to.equal('kiz');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('folds an alphabet consistently rather than half of it', (): void => {
|
|
64
|
+
// Danish: "å" decomposes and "æ"/"ø" do not, so without the expansions one
|
|
65
|
+
// half of the alphabet would fold and the other half would not.
|
|
66
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Åse')).to.equal('ase');
|
|
67
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Æble')).to.equal('aeble');
|
|
68
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Øst')).to.equal('ost');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('leaves the language dependent transcriptions alone', (): void => {
|
|
72
|
+
// "ü" decomposes to "u", so the German transcription to "ue" is not applied
|
|
73
|
+
// on top of it -- a value cannot fold to both.
|
|
74
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Müller')).to.equal('muller');
|
|
75
|
+
expect(TextNormalizer.foldCaseAndDiacritics('Müller')).to.not.equal('mueller');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('removes the Hebrew points', (): void => {
|
|
79
|
+
expect(TextNormalizer.foldCaseAndDiacritics('\u05e9\u05c1\u05b8\u05dc\u05d5\u05b9\u05dd'))
|
|
80
|
+
.to.equal(TextNormalizer.foldCaseAndDiacritics('\u05e9\u05dc\u05d5\u05dd'));
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('removes the Arabic harakat', (): void => {
|
|
84
|
+
expect(TextNormalizer.foldCaseAndDiacritics('\u0645\u064e\u062f\u0652\u0631\u064e\u0633\u064e\u0629'))
|
|
85
|
+
.to.equal(TextNormalizer.foldCaseAndDiacritics('\u0645\u062f\u0631\u0633\u0629'));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('folds the Arabic alef variants onto the plain alef', (): void => {
|
|
89
|
+
expect(TextNormalizer.foldCaseAndDiacritics('\u0623\u062d\u0645\u062f'))
|
|
90
|
+
.to.equal(TextNormalizer.foldCaseAndDiacritics('\u0627\u062d\u0645\u062f'));
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('keeps the marks a script writes obligatorily', (): void => {
|
|
94
|
+
// Thai vowel signs, Devanagari matras and the Japanese dakuten separate
|
|
95
|
+
// words rather than accent them, so folding must leave them alone.
|
|
96
|
+
const distinct = (values: string[]): number =>
|
|
97
|
+
new Set(values.map((value: string): string => TextNormalizer.foldCaseAndDiacritics(value))).size;
|
|
98
|
+
expect(distinct(['\u0e01\u0e34', '\u0e01\u0e35', '\u0e01\u0e38'])).to.equal(3);
|
|
99
|
+
expect(distinct(['\u0915\u093f', '\u0915\u0941', '\u0915\u0947'])).to.equal(3);
|
|
100
|
+
expect(distinct(['\u304b', '\u304c', '\u3071', '\u3070'])).to.equal(4);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('leaves Chinese untouched and unifies the compatibility ideographs', (): void => {
|
|
104
|
+
expect(TextNormalizer.foldCaseAndDiacritics('\u4e2d\u6587')).to.equal('\u4e2d\u6587');
|
|
105
|
+
expect(TextNormalizer.foldCaseAndDiacritics('\uf900')).to.equal('\u8c48');
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('normalizeInvisibleCharacters', () => {
|
|
110
|
+
it('returns an empty string unchanged', (): void => {
|
|
111
|
+
expect(TextNormalizer.normalizeInvisibleCharacters('')).to.equal('');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('drops a soft hyphen', (): void => {
|
|
115
|
+
expect(TextNormalizer.normalizeInvisibleCharacters('Do\u00adnau')).to.equal('Donau');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('drops the zero width characters', (): void => {
|
|
119
|
+
expect(TextNormalizer.normalizeInvisibleCharacters('a\u200bb\u200cc\u200dd\u2060e\ufeff')).to.equal('abcde');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('turns a no-break space into a plain space', (): void => {
|
|
123
|
+
expect(TextNormalizer.normalizeInvisibleCharacters('Cr\u00e8me\u00a0br\u00fbl\u00e9e')).to.equal('Cr\u00e8me br\u00fbl\u00e9e');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('turns the other space variants into a plain space', (): void => {
|
|
127
|
+
expect(TextNormalizer.normalizeInvisibleCharacters('a\u2009b\u202fc\u3000d')).to.equal('a b c d');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('leaves an ordinary label untouched', (): void => {
|
|
131
|
+
expect(TextNormalizer.normalizeInvisibleCharacters('Cremeschnitte')).to.equal('Cremeschnitte');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('leaves casing and diacritics to the other function', (): void => {
|
|
135
|
+
expect(TextNormalizer.normalizeInvisibleCharacters('Cr\u00e8me Br\u00fbl\u00e9e')).to.equal('Cr\u00e8me Br\u00fbl\u00e9e');
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
/**
|
|
15
|
+
* Module: @typo3/core/utility/text-normalizer
|
|
16
|
+
*
|
|
17
|
+
* Intl.Collator is deliberately not used: it compares whole strings rather than
|
|
18
|
+
* searching inside one, its result depends on the locale it is given, and at
|
|
19
|
+
* sensitivity "base" it merges the Japanese for "school" and for "cuckoo".
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
class TextNormalizer {
|
|
24
|
+
// The marks a script writes optionally, one constant per script so that each
|
|
25
|
+
// range can be read and checked against Unicode on its own. The marks Thai,
|
|
26
|
+
// Devanagari, Khmer, Lao and Japanese write obligatorily are deliberately
|
|
27
|
+
// absent: there a mark separates one word from another rather than accenting
|
|
28
|
+
// it, so removing it would fold the Japanese for "school" and for "cuckoo"
|
|
29
|
+
// into one value and leave a Thai filter narrowing nothing.
|
|
30
|
+
|
|
31
|
+
/** Combining diacritical marks, written by Latin, Greek and Cyrillic. */
|
|
32
|
+
private static readonly latinGreekCyrillicMarks = /[\u0300-\u036f]/g;
|
|
33
|
+
|
|
34
|
+
/** Hebrew points and cantillation. The gaps are punctuation, not marks. */
|
|
35
|
+
private static readonly hebrewPoints = /[\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7]/g;
|
|
36
|
+
|
|
37
|
+
/** Arabic harakat, hamza and madda, plus the superscript alef. */
|
|
38
|
+
private static readonly arabicHarakat = /[\u064b-\u065f\u0670]/g;
|
|
39
|
+
|
|
40
|
+
// Latin letters Unicode does not decompose, so stripping marks never reaches
|
|
41
|
+
// them. Without these an alphabet folds inconsistently: Danish "å" becomes "a"
|
|
42
|
+
// because it decomposes, while "æ" and "ø" would stay as they are.
|
|
43
|
+
//
|
|
44
|
+
// Only letters whose ASCII spelling is conventional rather than a matter of
|
|
45
|
+
// language are in here. The transcriptions that are a matter of language --
|
|
46
|
+
// German "ü" to "ue" rather than to "u" -- are not, because the decomposition
|
|
47
|
+
// already settles those.
|
|
48
|
+
|
|
49
|
+
/** Their conventional ASCII spelling, applied after the marks are stripped. */
|
|
50
|
+
private static readonly latinExpansions = new Map([
|
|
51
|
+
['ß', 'ss'], ['æ', 'ae'], ['œ', 'oe'], ['þ', 'th'],
|
|
52
|
+
['ø', 'o'], ['đ', 'd'], ['ð', 'd'], ['ł', 'l'],
|
|
53
|
+
['ħ', 'h'], ['ı', 'i'], ['ĸ', 'k'], ['ŋ', 'n'],
|
|
54
|
+
['ŧ', 't'],
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
/** Built from the map above so the letters are listed in one place only. */
|
|
58
|
+
private static readonly latinExpansionPattern =
|
|
59
|
+
new RegExp('[' + [...TextNormalizer.latinExpansions.keys()].join('') + ']', 'g');
|
|
60
|
+
|
|
61
|
+
/** Characters that take no width, so a reader cannot tell they are there. */
|
|
62
|
+
private static readonly zeroWidthCharacters = /[\u00ad\u200b-\u200d\u2060\ufeff]/g;
|
|
63
|
+
|
|
64
|
+
/** The space separators, all compared as a plain U+0020. */
|
|
65
|
+
private static readonly spaceVariants = /[\u00a0\u1680\u2000-\u200a\u202f\u205f\u3000]/g;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Lowercase, strip the optional marks and spell out the Latin letters that do
|
|
69
|
+
* not decompose, so that a filter matches "Crème" when "creme" is typed,
|
|
70
|
+
* "Straße" when "strasse" is typed, and an Arabic label carrying its harakat
|
|
71
|
+
* when it is typed without them.
|
|
72
|
+
*
|
|
73
|
+
* toLocaleLowerCase() is avoided: it follows the browser UI locale, where "I"
|
|
74
|
+
* folds to a dotless "ı".
|
|
75
|
+
*/
|
|
76
|
+
public static foldCaseAndDiacritics(value: string): string {
|
|
77
|
+
return value
|
|
78
|
+
.toLowerCase()
|
|
79
|
+
.normalize('NFD')
|
|
80
|
+
.replace(TextNormalizer.latinGreekCyrillicMarks, '')
|
|
81
|
+
.replace(TextNormalizer.hebrewPoints, '')
|
|
82
|
+
.replace(TextNormalizer.arabicHarakat, '')
|
|
83
|
+
.replace(TextNormalizer.latinExpansionPattern, (letter: string): string => TextNormalizer.latinExpansions.get(letter));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Drop the characters a reader cannot see and unify the space variants, so
|
|
88
|
+
* that a label carrying a soft hyphen or a no-break space still matches what
|
|
89
|
+
* is typed. Both arrive in labels by pasting.
|
|
90
|
+
*/
|
|
91
|
+
public static normalizeInvisibleCharacters(value: string): string {
|
|
92
|
+
return value
|
|
93
|
+
.replace(TextNormalizer.zeroWidthCharacters, '')
|
|
94
|
+
.replace(TextNormalizer.spaceVariants, ' ');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default TextNormalizer;
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
import { customElement, query, state } from 'lit/decorators.js';
|
|
14
|
+
import { html, LitElement, type PropertyValues, type TemplateResult } from 'lit';
|
|
15
|
+
import type { SubmissionServiceInterface } from '@typo3/backend/wizard/finisher/submission-service-interface';
|
|
16
|
+
import type { WizardStepInterface } from '@typo3/backend/wizard/steps/wizard-step-interface';
|
|
17
|
+
import type { DataStore, Wizard } from '@typo3/backend/wizard/wizard';
|
|
18
|
+
import { AutoAdvanceEvent } from '@typo3/backend/wizard/events/auto-advance-event';
|
|
19
|
+
import PresetStep from '@typo3/dashboard/wizard/steps/preset-step';
|
|
20
|
+
import TitleStep from '@typo3/dashboard/wizard/steps/title-step';
|
|
21
|
+
import { DashboardWizardSubmissionService } from '@typo3/dashboard/wizard/finisher/dashboard-wizard-submission-service';
|
|
22
|
+
|
|
23
|
+
export interface DashboardWizardDataStore extends DataStore {
|
|
24
|
+
preset?: string;
|
|
25
|
+
title?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type DashboardWizardDataStoreKey = keyof DashboardWizardDataStore;
|
|
29
|
+
|
|
30
|
+
export interface DashboardWizardContext {
|
|
31
|
+
wizard: Wizard;
|
|
32
|
+
getStoreData: <T extends DashboardWizardDataStoreKey>(key: T) => NoInfer<DashboardWizardDataStore[T]>;
|
|
33
|
+
setStoreData: <T extends DashboardWizardDataStoreKey>(key: T, value: NoInfer<DashboardWizardDataStore[T]>) => void;
|
|
34
|
+
clearStoreData: <T extends DashboardWizardDataStoreKey>(key: T) => void;
|
|
35
|
+
getDataStore: () => Readonly<DashboardWizardDataStore>;
|
|
36
|
+
dispatchAutoAdvance: () => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@customElement('typo3-dashboard-wizard')
|
|
40
|
+
export class DashboardWizard extends LitElement {
|
|
41
|
+
@state() steps: WizardStepInterface[] = [];
|
|
42
|
+
@state() submissionService: SubmissionServiceInterface;
|
|
43
|
+
|
|
44
|
+
@query('typo3-backend-wizard') wizard!: Wizard;
|
|
45
|
+
|
|
46
|
+
private context: DashboardWizardContext;
|
|
47
|
+
|
|
48
|
+
protected override firstUpdated(_changedProperties: PropertyValues): void {
|
|
49
|
+
super.firstUpdated(_changedProperties);
|
|
50
|
+
|
|
51
|
+
this.context = {
|
|
52
|
+
wizard: this.wizard,
|
|
53
|
+
getStoreData: this.wizard.getStoreData.bind(this.wizard),
|
|
54
|
+
setStoreData: this.wizard.setStoreData.bind(this.wizard),
|
|
55
|
+
clearStoreData: this.wizard.clearStoreData.bind(this.wizard),
|
|
56
|
+
getDataStore: this.wizard.getDataStore.bind(this.wizard),
|
|
57
|
+
dispatchAutoAdvance: () => this.wizard.dispatchEvent(new AutoAdvanceEvent())
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
this.steps = [
|
|
61
|
+
new PresetStep(this.context),
|
|
62
|
+
new TitleStep(this.context),
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
this.submissionService = new DashboardWizardSubmissionService(this.context);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
protected override createRenderRoot(): HTMLElement | DocumentFragment {
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
protected override render(): TemplateResult {
|
|
73
|
+
return html`
|
|
74
|
+
<typo3-backend-wizard .steps="${this.steps}"
|
|
75
|
+
.submissionService="${this.submissionService}"
|
|
76
|
+
skip-summary
|
|
77
|
+
></typo3-backend-wizard>
|
|
78
|
+
`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
declare global {
|
|
83
|
+
interface HTMLElementTagNameMap {
|
|
84
|
+
'typo3-dashboard-wizard': DashboardWizard;
|
|
85
|
+
}
|
|
86
|
+
}
|