passbolt-styleguide 5.17.0 → 5.17.2
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/RELEASE_NOTES.md +4 -2
- package/build/css/help.min.css +2 -2
- package/build/css/public.min.css +2 -2
- package/build/css/themes/default/api_authentication.min.css +2 -2
- package/build/css/themes/default/api_cloud.min.css +2 -2
- package/build/css/themes/default/api_main.min.css +2 -2
- package/build/css/themes/default/api_reports.min.css +2 -2
- package/build/css/themes/default/api_webinstaller.min.css +2 -2
- package/build/css/themes/default/ext_app.min.css +2 -2
- package/build/css/themes/default/ext_authentication.min.css +2 -2
- package/build/css/themes/default/ext_external.min.css +2 -2
- package/build/css/themes/default/ext_in_form_cta.min.css +2 -2
- package/build/css/themes/default/ext_in_form_menu.min.css +2 -2
- package/build/css/themes/default/ext_quickaccess.min.css +2 -2
- package/build/css/themes/midgar/api_authentication.min.css +2 -2
- package/build/css/themes/midgar/api_main.min.css +2 -2
- package/build/css/themes/midgar/api_reports.min.css +2 -2
- package/build/css/themes/midgar/ext_app.min.css +2 -2
- package/build/css/themes/midgar/ext_authentication.min.css +2 -2
- package/build/css/themes/midgar/ext_in_form_cta.min.css +2 -2
- package/build/css/themes/midgar/ext_in_form_menu.min.css +2 -2
- package/build/css/themes/midgar/ext_quickaccess.min.css +2 -2
- package/build/css/themes/solarized_dark/api_authentication.min.css +2 -2
- package/build/css/themes/solarized_dark/api_main.min.css +2 -2
- package/build/css/themes/solarized_dark/api_reports.min.css +2 -2
- package/build/css/themes/solarized_dark/ext_app.min.css +2 -2
- package/build/css/themes/solarized_dark/ext_authentication.min.css +2 -2
- package/build/css/themes/solarized_dark/ext_in_form_cta.min.css +2 -2
- package/build/css/themes/solarized_dark/ext_in_form_menu.min.css +2 -2
- package/build/css/themes/solarized_dark/ext_quickaccess.min.css +2 -2
- package/build/css/themes/solarized_light/api_authentication.min.css +2 -2
- package/build/css/themes/solarized_light/api_main.min.css +2 -2
- package/build/css/themes/solarized_light/api_reports.min.css +2 -2
- package/build/css/themes/solarized_light/ext_app.min.css +2 -2
- package/build/css/themes/solarized_light/ext_authentication.min.css +2 -2
- package/build/css/themes/solarized_light/ext_in_form_cta.min.css +2 -2
- package/build/css/themes/solarized_light/ext_in_form_menu.min.css +2 -2
- package/build/css/themes/solarized_light/ext_quickaccess.min.css +2 -2
- package/build/js/dist/api-app.js +1 -1
- package/build/locales/cs-CZ/common.json +158 -96
- package/build/locales/de-DE/common.json +146 -90
- package/build/locales/es-ES/common.json +148 -92
- package/build/locales/fr-FR/common.json +148 -92
- package/build/locales/it-IT/common.json +149 -93
- package/build/locales/ja-JP/common.json +145 -92
- package/build/locales/ko-KR/common.json +67 -14
- package/build/locales/lt-LT/common.json +163 -101
- package/build/locales/nl-NL/common.json +151 -95
- package/build/locales/pl-PL/common.json +155 -93
- package/build/locales/pt-BR/common.json +150 -94
- package/build/locales/ro-RO/common.json +147 -88
- package/build/locales/ru-RU/common.json +158 -96
- package/build/locales/sl-SI/common.json +158 -96
- package/build/locales/sv-SE/common.json +151 -95
- package/build/locales/uk-UA/common.json +166 -104
- package/package.json +1 -1
- package/src/locales/cs-CZ/common.json +158 -96
- package/src/locales/de-DE/common.json +146 -90
- package/src/locales/es-ES/common.json +148 -92
- package/src/locales/fr-FR/common.json +148 -92
- package/src/locales/it-IT/common.json +149 -93
- package/src/locales/ja-JP/common.json +145 -92
- package/src/locales/ko-KR/common.json +67 -14
- package/src/locales/lt-LT/common.json +163 -101
- package/src/locales/nl-NL/common.json +151 -95
- package/src/locales/pl-PL/common.json +155 -93
- package/src/locales/pt-BR/common.json +150 -94
- package/src/locales/ro-RO/common.json +147 -88
- package/src/locales/ru-RU/common.json +158 -96
- package/src/locales/sl-SI/common.json +158 -96
- package/src/locales/sv-SE/common.json +151 -95
- package/src/locales/uk-UA/common.json +166 -104
- package/src/react-extension/components/Administration/DisplayAdministrationWorkspaceActions/DisplayAdministrationMfaActions/DisplayAdministrationMfaActions.js +14 -6
- package/src/react-quickaccess/components/ResourceCreatePage/ResourceCreatePage.js +14 -4
- package/src/react-quickaccess/components/ResourceCreatePage/ResourceCreatePage.test.js +26 -2
- package/src/react-quickaccess/contexts/ExtQuickAccessContext.js +0 -14
- package/src/react-web-integration/lib/InForm/InFormManager.js +14 -4
- package/src/react-web-integration/lib/InForm/InformManager.test.js +53 -6
- package/src/react-web-integration/services/DomExtraction/FieldAggregatorService.js +23 -1
- package/src/react-web-integration/services/DomExtraction/FieldAggregatorService.test.js +37 -0
- package/src/react-web-integration/services/ShadowDom/ShadowDomFocusHealerService.js +2 -2
- package/src/react-web-integration/services/ShadowDom/ShadowDomFocusHealerService.test.js +18 -6
- package/src/react-web-integration/services/ShadowDom/ShadowMutationObserverService.js +5 -3
- package/src/react-web-integration/services/ShadowDom/ShadowMutationObserverService.test.js +12 -1
|
@@ -78,15 +78,23 @@ class DisplayAdministrationMfaActions extends React.Component {
|
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
80
|
* Handle save operation error.
|
|
81
|
-
* @param {object}
|
|
81
|
+
* @param {object} e The returned error
|
|
82
82
|
*/
|
|
83
|
-
async handleSaveError(
|
|
83
|
+
async handleSaveError(e) {
|
|
84
84
|
// It can happen when the user has closed the passphrase entry dialog by instance.
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
console.error(error);
|
|
88
|
-
await this.handleError(error);
|
|
85
|
+
if (e.name === "UserAbortsOperationError") {
|
|
86
|
+
return;
|
|
89
87
|
}
|
|
88
|
+
|
|
89
|
+
let error = e;
|
|
90
|
+
// Handles specific webauthn error messages
|
|
91
|
+
if (error?.data?.body?.webauthn) {
|
|
92
|
+
const errorMessage = Object.values(error.data.body.webauthn).join(". ");
|
|
93
|
+
error = new Error(errorMessage);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
console.error(error);
|
|
97
|
+
await this.handleError(error);
|
|
90
98
|
}
|
|
91
99
|
|
|
92
100
|
/**
|
|
@@ -45,6 +45,18 @@ import CloseSVG from "../../../img/svg/close.svg";
|
|
|
45
45
|
import DiceSVG from "../../../img/svg/dice.svg";
|
|
46
46
|
import SettingsSVG from "../../../img/svg/settings.svg";
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Tab names that should not be used to prefill the resource name.
|
|
50
|
+
* @type {Array<string>}
|
|
51
|
+
*/
|
|
52
|
+
const IGNORE_NAMES = ["newtab"];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Tab URIs that should not be used to prefill the resource uri (browsers new tab pages).
|
|
56
|
+
* @type {Array<string>}
|
|
57
|
+
*/
|
|
58
|
+
const IGNORE_URIS = ["chrome://newtab/", "about:newtab", "edge://newtab/"];
|
|
59
|
+
|
|
48
60
|
class ResourceCreatePage extends React.Component {
|
|
49
61
|
/**
|
|
50
62
|
* @constructor
|
|
@@ -205,8 +217,6 @@ class ResourceCreatePage extends React.Component {
|
|
|
205
217
|
let uri = "";
|
|
206
218
|
let username = "";
|
|
207
219
|
let password = "";
|
|
208
|
-
const ignoreNames = ["newtab"];
|
|
209
|
-
const ignoreUris = ["chrome://newtab/", "about:newtab"];
|
|
210
220
|
|
|
211
221
|
try {
|
|
212
222
|
const tabInfo = await this.props.context.port.request(
|
|
@@ -214,11 +224,11 @@ class ResourceCreatePage extends React.Component {
|
|
|
214
224
|
this.props.context.openerTabId,
|
|
215
225
|
);
|
|
216
226
|
|
|
217
|
-
if (!
|
|
227
|
+
if (!IGNORE_NAMES.includes(tabInfo["name"])) {
|
|
218
228
|
name = tabInfo["name"].substring(0, 255);
|
|
219
229
|
}
|
|
220
230
|
|
|
221
|
-
if (
|
|
231
|
+
if (tabInfo["uris"].length > 0 && !IGNORE_URIS.includes(tabInfo["uris"][0])) {
|
|
222
232
|
uri = tabInfo["uris"][0];
|
|
223
233
|
}
|
|
224
234
|
|
|
@@ -77,28 +77,52 @@ describe("ResourceCreatePage", () => {
|
|
|
77
77
|
const expectedData = {
|
|
78
78
|
name: "newtab",
|
|
79
79
|
uris: ["chrome://newtab/"],
|
|
80
|
+
secret_clear: "AAAAAAAAAAAAAAAAAA",
|
|
80
81
|
};
|
|
81
82
|
|
|
82
83
|
const props = defaultProps();
|
|
83
84
|
props.context.port.addRequestListener("passbolt.quickaccess.prepare-resource", async () => expectedData);
|
|
84
85
|
const page = new ResourceCreatePagePage(props);
|
|
85
|
-
|
|
86
|
+
// Wait until the username input value is found (This will ensure the state has been updated with the tab info)
|
|
87
|
+
await screen.findByDisplayValue(props.context.userSettings.username);
|
|
86
88
|
|
|
87
89
|
// Assert the form.
|
|
88
90
|
expect(page.name.value).toStrictEqual("");
|
|
89
91
|
expect(page.uri.value).toStrictEqual("");
|
|
90
92
|
});
|
|
91
93
|
|
|
94
|
+
it("should not initialize with edge new tab metadata", async () => {
|
|
95
|
+
expect.assertions(2);
|
|
96
|
+
|
|
97
|
+
const expectedData = {
|
|
98
|
+
name: "New tab",
|
|
99
|
+
uris: ["edge://newtab/"],
|
|
100
|
+
secret_clear: "AAAAAAAAAAAAAAAAAA",
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const props = defaultProps();
|
|
104
|
+
props.context.port.addRequestListener("passbolt.quickaccess.prepare-resource", async () => expectedData);
|
|
105
|
+
const page = new ResourceCreatePagePage(props);
|
|
106
|
+
// Wait until the username input value is found (This will ensure the state has been updated with the tab info)
|
|
107
|
+
await screen.findByDisplayValue(props.context.userSettings.username);
|
|
108
|
+
|
|
109
|
+
// Assert the form.
|
|
110
|
+
expect(page.name.value).toStrictEqual("New tab");
|
|
111
|
+
expect(page.uri.value).toStrictEqual("");
|
|
112
|
+
});
|
|
113
|
+
|
|
92
114
|
it("should not initialize with firefox new tab metadata", async () => {
|
|
93
115
|
const expectedData = {
|
|
94
116
|
name: "",
|
|
95
117
|
uris: ["about:newtab"],
|
|
118
|
+
secret_clear: "AAAAAAAAAAAAAAAAAA",
|
|
96
119
|
};
|
|
97
120
|
|
|
98
121
|
const props = defaultProps();
|
|
99
122
|
props.context.port.addRequestListener("passbolt.quickaccess.prepare-resource", async () => expectedData);
|
|
100
123
|
const page = new ResourceCreatePagePage(props);
|
|
101
|
-
|
|
124
|
+
// Wait until the username input value is found (This will ensure the state has been updated with the tab info)
|
|
125
|
+
await screen.findByDisplayValue(props.context.userSettings.username);
|
|
102
126
|
|
|
103
127
|
// Assert the form.
|
|
104
128
|
expect(page.name.value).toStrictEqual("");
|
|
@@ -55,7 +55,6 @@ export class ExtQuickAccessContextProvider extends React.Component {
|
|
|
55
55
|
*/
|
|
56
56
|
async initialize() {
|
|
57
57
|
try {
|
|
58
|
-
await this.checkPluginIsConfigured();
|
|
59
58
|
await this.props.activeSessionLocalStorageContext.updateLocalStorage();
|
|
60
59
|
await this.getUserSettings();
|
|
61
60
|
await this.getLocale();
|
|
@@ -198,19 +197,6 @@ export class ExtQuickAccessContextProvider extends React.Component {
|
|
|
198
197
|
this.setState({ shouldCloseAtWindowBlur });
|
|
199
198
|
}
|
|
200
199
|
|
|
201
|
-
/**
|
|
202
|
-
* Check if plugin is configured
|
|
203
|
-
* - not configured will redirect to getting started passbolt page and close quickaccess
|
|
204
|
-
* @return {Promise<void>}
|
|
205
|
-
*/
|
|
206
|
-
async checkPluginIsConfigured() {
|
|
207
|
-
const isConfigured = await this.state.port.request("passbolt.addon.is-configured");
|
|
208
|
-
if (!isConfigured) {
|
|
209
|
-
await this.props.state.request("passbolt.tabs.open-website-getting-started-page");
|
|
210
|
-
await this.closeWindow();
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
200
|
/**
|
|
215
201
|
* Update search
|
|
216
202
|
* @param search
|
|
@@ -326,7 +326,8 @@ class InFormManager {
|
|
|
326
326
|
* If a field was previously found, we reuse the same InformUsernameField, otherwise we create one.
|
|
327
327
|
* Else we clean and reset callToActionFields.
|
|
328
328
|
*/
|
|
329
|
-
const { fields } = PageClassificationService.classifyPage();
|
|
329
|
+
const { fields: classifiedFields } = PageClassificationService.classifyPage();
|
|
330
|
+
const fields = classifiedFields.filter(({ element }) => !element.disabled);
|
|
330
331
|
const newUsernameFields = fields.filter((field) => IDENTIFIER_ROLES.includes(field.role));
|
|
331
332
|
const newPasswordFields = fields.filter((field) => PASSWORD_ROLES.includes(field.role));
|
|
332
333
|
const newOTPFields = fields.filter((field) => field.role === FieldRole.TOTP);
|
|
@@ -563,15 +564,17 @@ class InFormManager {
|
|
|
563
564
|
* @param {Document|ShadowRoot|Element} root The observed node.
|
|
564
565
|
* @param {MutationRecord[]} mutations The list of mutations.
|
|
565
566
|
* @param {boolean} shadowRootsChanged Whether the mutation includes a change in the shadowRoots.
|
|
567
|
+
* @param {object} [options]
|
|
568
|
+
* @param {boolean} [options.fromFocus=false] Whether the notification comes from the user focusing a field.
|
|
566
569
|
*/
|
|
567
|
-
onShadowMutation(root, mutations, shadowRootsChanged) {
|
|
570
|
+
onShadowMutation(root, mutations, shadowRootsChanged, { fromFocus = false } = {}) {
|
|
568
571
|
// Never scan our own CTA shadow root
|
|
569
572
|
if (root === this.shadowRoot) {
|
|
570
573
|
return;
|
|
571
574
|
}
|
|
572
575
|
|
|
573
|
-
//
|
|
574
|
-
if (
|
|
576
|
+
// The user focused a field: re-scan right away so it gets its call-to-action on first focus
|
|
577
|
+
if (fromFocus) {
|
|
575
578
|
this.findAndSetAuthenticationFields();
|
|
576
579
|
this.handleInformCallToActionClickEvent();
|
|
577
580
|
this._pendingFieldScan = true;
|
|
@@ -579,6 +582,13 @@ class InFormManager {
|
|
|
579
582
|
return;
|
|
580
583
|
}
|
|
581
584
|
|
|
585
|
+
// A new shadow root appeared: wait for the page to settle, a component-heavy page adds hundreds at once
|
|
586
|
+
if (shadowRootsChanged) {
|
|
587
|
+
this._pendingFieldScan = true;
|
|
588
|
+
this.updateAuthenticationFieldsDebounce?.();
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
|
|
582
592
|
// Does this batch actually touch a credential-relevant node or attribute?
|
|
583
593
|
const affectsFields =
|
|
584
594
|
this._mutationsAffectAuthenticationFields(mutations) || this._attributeMutationAffectsField(mutations);
|
|
@@ -2229,27 +2229,52 @@ describe("InformManager", () => {
|
|
|
2229
2229
|
expect(InFormManager._pendingFieldScan).toBe(true);
|
|
2230
2230
|
});
|
|
2231
2231
|
|
|
2232
|
-
it("should re-scan synchronously and schedule a debounced follow-up when
|
|
2233
|
-
// The focus healer
|
|
2234
|
-
//
|
|
2235
|
-
//
|
|
2236
|
-
expect.assertions(
|
|
2232
|
+
it("should re-scan synchronously and schedule a debounced follow-up when the user focuses a field", async () => {
|
|
2233
|
+
// The focus healer notifies with fromFocus when a field is focused. The re-scan must be synchronous
|
|
2234
|
+
// (so the call-to-action is attached within the same focus turn) AND also scheduled once more
|
|
2235
|
+
// (debounced) to catch a web component that hydrates just after an autofocus.
|
|
2236
|
+
expect.assertions(3);
|
|
2237
2237
|
|
|
2238
2238
|
document.body.innerHTML = domElementLoginWithNameAttributeUsername;
|
|
2239
2239
|
await act(async () => new InformManagerPage());
|
|
2240
2240
|
InFormManager.updateAuthenticationFieldsDebounce = jest.fn();
|
|
2241
|
+
InFormManager._pendingFieldScan = false;
|
|
2241
2242
|
const findSpy = jest.spyOn(InFormManager, "findAndSetAuthenticationFields").mockImplementation();
|
|
2242
2243
|
|
|
2243
|
-
InFormManager.onShadowMutation(document, [], true);
|
|
2244
|
+
InFormManager.onShadowMutation(document, [], true, { fromFocus: true });
|
|
2244
2245
|
|
|
2245
2246
|
expect(InFormManager.findAndSetAuthenticationFields).toHaveBeenCalledTimes(1);
|
|
2246
2247
|
expect(InFormManager.updateAuthenticationFieldsDebounce).toHaveBeenCalledTimes(1);
|
|
2248
|
+
expect(InFormManager._pendingFieldScan).toBe(true);
|
|
2247
2249
|
|
|
2248
2250
|
// The suite clears (not restores) mocks between tests, so restore the persistent no-op now to avoid
|
|
2249
2251
|
// leaking it into the tests below.
|
|
2250
2252
|
findSpy.mockRestore();
|
|
2251
2253
|
});
|
|
2252
2254
|
|
|
2255
|
+
it("should only schedule a debounced re-scan when a mutation adds shadow roots", async () => {
|
|
2256
|
+
// A component-heavy page (e.g. Reddit) adds hundreds of shadow roots per render: each observer batch
|
|
2257
|
+
// must not trigger a synchronous full-page scan, only arm the gate and schedule a single debounced one.
|
|
2258
|
+
expect.assertions(3);
|
|
2259
|
+
|
|
2260
|
+
document.body.innerHTML = domElementLoginWithNameAttributeUsername;
|
|
2261
|
+
await act(async () => new InformManagerPage());
|
|
2262
|
+
InFormManager.updateAuthenticationFieldsDebounce = jest.fn();
|
|
2263
|
+
InFormManager._pendingFieldScan = false;
|
|
2264
|
+
const findSpy = jest.spyOn(InFormManager, "findAndSetAuthenticationFields").mockImplementation();
|
|
2265
|
+
const otherShadowRoot = document.createElement("div").attachShadow({ mode: "open" });
|
|
2266
|
+
|
|
2267
|
+
for (let i = 0; i < 200; i++) {
|
|
2268
|
+
InFormManager.onShadowMutation(otherShadowRoot, [], true);
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
expect(InFormManager.findAndSetAuthenticationFields).not.toHaveBeenCalled();
|
|
2272
|
+
expect(InFormManager.updateAuthenticationFieldsDebounce).toHaveBeenCalledTimes(200);
|
|
2273
|
+
expect(InFormManager._pendingFieldScan).toBe(true);
|
|
2274
|
+
|
|
2275
|
+
findSpy.mockRestore();
|
|
2276
|
+
});
|
|
2277
|
+
|
|
2253
2278
|
it("should NOT queue an expensive field scan for a non-relevant document mutation (only the host check)", async () => {
|
|
2254
2279
|
expect.assertions(2);
|
|
2255
2280
|
|
|
@@ -2321,6 +2346,28 @@ describe("InformManager", () => {
|
|
|
2321
2346
|
|
|
2322
2347
|
expect(InFormManager.callToActionFields).toHaveLength(1);
|
|
2323
2348
|
});
|
|
2349
|
+
|
|
2350
|
+
it("should not attach a call-to-action to a disabled field until it is enabled", async () => {
|
|
2351
|
+
expect.assertions(3);
|
|
2352
|
+
|
|
2353
|
+
// Second step of a multi-step login: the identifier is recalled in a disabled field above the password.
|
|
2354
|
+
document.body.innerHTML = `<form>
|
|
2355
|
+
<input type='email' id='email' name='email' disabled value='admin@passbolt.com'/>
|
|
2356
|
+
<input type='password' id='password' name='password'/>
|
|
2357
|
+
</form>`;
|
|
2358
|
+
await act(async () => new InformManagerPage());
|
|
2359
|
+
const ctaElements = () => InFormManager.callToActionFields.map(({ field }) => field);
|
|
2360
|
+
expect(ctaElements()).not.toContain(document.getElementById("email"));
|
|
2361
|
+
expect(ctaElements()).toContain(document.getElementById("password"));
|
|
2362
|
+
|
|
2363
|
+
// The site enables the field: the next scan attaches its call-to-action.
|
|
2364
|
+
await act(async () => {
|
|
2365
|
+
document.getElementById("email").disabled = false;
|
|
2366
|
+
});
|
|
2367
|
+
InFormManager.findAndSetAuthenticationFields();
|
|
2368
|
+
|
|
2369
|
+
expect(ctaElements()).toContain(document.getElementById("email"));
|
|
2370
|
+
});
|
|
2324
2371
|
});
|
|
2325
2372
|
|
|
2326
2373
|
describe("Focus healer integration", () => {
|
|
@@ -36,11 +36,33 @@ class FieldAggregatorService {
|
|
|
36
36
|
* @returns {Element[]} The visible fillable fields.
|
|
37
37
|
*/
|
|
38
38
|
static gatherCandidates(containerElement) {
|
|
39
|
-
|
|
39
|
+
const elements = new Set(ShadowDomQueryService.querySelectorAllDeep(containerElement, TEXT_FIELDS));
|
|
40
|
+
FieldAggregatorService.gatherSlottedFields(containerElement).forEach((element) => elements.add(element));
|
|
41
|
+
|
|
42
|
+
return [...elements].filter(
|
|
40
43
|
(element) => ShadowDomQueryService.isElement(element) && ElementVisibilityService.isElementViewable(element),
|
|
41
44
|
);
|
|
42
45
|
}
|
|
43
46
|
|
|
47
|
+
/**
|
|
48
|
+
* TEXT_FIELDS assigned to the slots of a container. A web component may render the light DOM fields of its host
|
|
49
|
+
* through slots of its shadow root: they are displayed inside the container but are not its descendants.
|
|
50
|
+
* @param {Element} containerElement The container to scan.
|
|
51
|
+
* @returns {Element[]} The slotted fields.
|
|
52
|
+
*/
|
|
53
|
+
static gatherSlottedFields(containerElement) {
|
|
54
|
+
const slots = ShadowDomQueryService.querySelectorAllDeep(containerElement, "slot");
|
|
55
|
+
|
|
56
|
+
return slots.flatMap((slot) =>
|
|
57
|
+
slot
|
|
58
|
+
.assignedElements({ flatten: true })
|
|
59
|
+
.flatMap((assigned) => [
|
|
60
|
+
...(assigned.matches(TEXT_FIELDS) ? [assigned] : []),
|
|
61
|
+
...ShadowDomQueryService.querySelectorAllDeep(assigned, TEXT_FIELDS),
|
|
62
|
+
]),
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
44
66
|
/**
|
|
45
67
|
* Populate `fields[]` of every container record with `{ fieldElement, deepestFormContainer }`
|
|
46
68
|
* (replacing whatever seed/skeleton fields it carried), then purge containers left with no field.
|
|
@@ -45,6 +45,43 @@ describe("FieldAggregatorService", () => {
|
|
|
45
45
|
expect(result[0].fields.map((field) => field.fieldElement.id)).toContain("reg-phone");
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
+
it("should populate the fields slotted into a container living in a web component shadow root", () => {
|
|
49
|
+
expect.assertions(2);
|
|
50
|
+
|
|
51
|
+
jest.spyOn(ElementVisibilityService, "isElementViewable").mockReturnValue(true);
|
|
52
|
+
// The landal.de shape: the host's light DOM inputs are rendered through named slots of its shadow root.
|
|
53
|
+
document.body.innerHTML = `<login-panel-component>
|
|
54
|
+
<input slot="username" type="email" id="username"/>
|
|
55
|
+
<input slot="password" type="password" id="current-password"/>
|
|
56
|
+
</login-panel-component>`;
|
|
57
|
+
const host = document.querySelector("login-panel-component");
|
|
58
|
+
const shadowRoot = host.attachShadow({ mode: "open" });
|
|
59
|
+
shadowRoot.innerHTML = '<div id="panel"><slot name="username"></slot><slot name="password"></slot></div>';
|
|
60
|
+
const container = shadowRoot.getElementById("panel");
|
|
61
|
+
|
|
62
|
+
const result = FieldAggregatorService.aggregateFields([
|
|
63
|
+
{ containerElement: container, fields: [], isPseudoForm: true },
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
expect(result).toHaveLength(1);
|
|
67
|
+
expect(result[0].fields.map((field) => field.fieldElement.id)).toEqual(["username", "current-password"]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should not duplicate a field found both as a descendant and through a slot", () => {
|
|
71
|
+
expect.assertions(1);
|
|
72
|
+
|
|
73
|
+
jest.spyOn(ElementVisibilityService, "isElementViewable").mockReturnValue(true);
|
|
74
|
+
document.body.innerHTML = '<login-panel-component><input slot="username" id="username"/></login-panel-component>';
|
|
75
|
+
const host = document.querySelector("login-panel-component");
|
|
76
|
+
host.attachShadow({ mode: "open" }).innerHTML = '<slot name="username"></slot>';
|
|
77
|
+
|
|
78
|
+
const result = FieldAggregatorService.aggregateFields([
|
|
79
|
+
{ containerElement: host, fields: [], isPseudoForm: true },
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
expect(result[0].fields).toHaveLength(1);
|
|
83
|
+
});
|
|
84
|
+
|
|
48
85
|
it("should keep only visible fields", () => {
|
|
49
86
|
expect.assertions(2);
|
|
50
87
|
|
|
@@ -43,7 +43,7 @@ const focusHandler = (event) => {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
if (invalidated) {
|
|
46
|
-
ShadowMutationObserverService.notifyShadowMutationSubscribers(document, [], true);
|
|
46
|
+
ShadowMutationObserverService.notifyShadowMutationSubscribers(document, [], true, { fromFocus: true });
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -55,7 +55,7 @@ const focusHandler = (event) => {
|
|
|
55
55
|
!ShadowDomFocusHealerService._healAttempted.has(target)
|
|
56
56
|
) {
|
|
57
57
|
ShadowDomFocusHealerService._healAttempted.add(target);
|
|
58
|
-
ShadowMutationObserverService.notifyShadowMutationSubscribers(document, [], true);
|
|
58
|
+
ShadowMutationObserverService.notifyShadowMutationSubscribers(document, [], true, { fromFocus: true });
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
|
|
@@ -158,7 +158,9 @@ describe("ShadowDomFocusHealerService", () => {
|
|
|
158
158
|
focusHandler({ composedPath: () => [input, document.body, document] });
|
|
159
159
|
|
|
160
160
|
expect(ShadowRootCacheService.invalidate).not.toHaveBeenCalled();
|
|
161
|
-
expect(ShadowMutationObserverService.notifyShadowMutationSubscribers).toHaveBeenCalledWith(document, [], true
|
|
161
|
+
expect(ShadowMutationObserverService.notifyShadowMutationSubscribers).toHaveBeenCalledWith(document, [], true, {
|
|
162
|
+
fromFocus: true,
|
|
163
|
+
});
|
|
162
164
|
});
|
|
163
165
|
|
|
164
166
|
it("should not trigger a rescan when the focused light-DOM input is already tracked", () => {
|
|
@@ -202,7 +204,9 @@ describe("ShadowDomFocusHealerService", () => {
|
|
|
202
204
|
|
|
203
205
|
expect(ShadowRootCacheService.invalidate).toHaveBeenCalledTimes(1);
|
|
204
206
|
expect(ShadowRootCacheService.invalidate).toHaveBeenCalledWith(document);
|
|
205
|
-
expect(ShadowMutationObserverService.notifyShadowMutationSubscribers).toHaveBeenCalledWith(document, [], true
|
|
207
|
+
expect(ShadowMutationObserverService.notifyShadowMutationSubscribers).toHaveBeenCalledWith(document, [], true, {
|
|
208
|
+
fromFocus: true,
|
|
209
|
+
});
|
|
206
210
|
});
|
|
207
211
|
|
|
208
212
|
it("should invalidate the parent scope when the shadow root in the path is not an instance of ShadowRoot (cross-realm/isolated world)", () => {
|
|
@@ -220,7 +224,9 @@ describe("ShadowDomFocusHealerService", () => {
|
|
|
220
224
|
focusHandler({ composedPath: () => [input, crossRealmShadowRoot, host, document.body, document] });
|
|
221
225
|
|
|
222
226
|
expect(ShadowRootCacheService.invalidate).toHaveBeenCalledWith(document);
|
|
223
|
-
expect(ShadowMutationObserverService.notifyShadowMutationSubscribers).toHaveBeenCalledWith(document, [], true
|
|
227
|
+
expect(ShadowMutationObserverService.notifyShadowMutationSubscribers).toHaveBeenCalledWith(document, [], true, {
|
|
228
|
+
fromFocus: true,
|
|
229
|
+
});
|
|
224
230
|
});
|
|
225
231
|
|
|
226
232
|
it("should invalidate the parent scopes of late-attached nested roots", () => {
|
|
@@ -243,7 +249,9 @@ describe("ShadowDomFocusHealerService", () => {
|
|
|
243
249
|
expect(ShadowRootCacheService.invalidate).toHaveBeenCalledWith(outerRoot);
|
|
244
250
|
expect(ShadowRootCacheService.invalidate).toHaveBeenCalledWith(document);
|
|
245
251
|
expect(ShadowMutationObserverService.notifyShadowMutationSubscribers).toHaveBeenCalledTimes(1);
|
|
246
|
-
expect(ShadowMutationObserverService.notifyShadowMutationSubscribers).toHaveBeenCalledWith(document, [], true
|
|
252
|
+
expect(ShadowMutationObserverService.notifyShadowMutationSubscribers).toHaveBeenCalledWith(document, [], true, {
|
|
253
|
+
fromFocus: true,
|
|
254
|
+
});
|
|
247
255
|
});
|
|
248
256
|
|
|
249
257
|
it("should not invalidate when the focused field is inside a known shadow root", () => {
|
|
@@ -280,7 +288,9 @@ describe("ShadowDomFocusHealerService", () => {
|
|
|
280
288
|
focusHandler({ composedPath: () => [input, shadowRoot, host, document.body, document] });
|
|
281
289
|
|
|
282
290
|
expect(ShadowRootCacheService.invalidate).toHaveBeenCalledWith(document);
|
|
283
|
-
expect(ShadowMutationObserverService.notifyShadowMutationSubscribers).toHaveBeenCalledWith(document, [], true
|
|
291
|
+
expect(ShadowMutationObserverService.notifyShadowMutationSubscribers).toHaveBeenCalledWith(document, [], true, {
|
|
292
|
+
fromFocus: true,
|
|
293
|
+
});
|
|
284
294
|
});
|
|
285
295
|
|
|
286
296
|
it("should invalidate only the scope of the unknown root when its parent root is already known", () => {
|
|
@@ -306,7 +316,9 @@ describe("ShadowDomFocusHealerService", () => {
|
|
|
306
316
|
|
|
307
317
|
expect(ShadowRootCacheService.invalidate).toHaveBeenCalledTimes(1);
|
|
308
318
|
expect(ShadowRootCacheService.invalidate).toHaveBeenCalledWith(outerRoot);
|
|
309
|
-
expect(ShadowMutationObserverService.notifyShadowMutationSubscribers).toHaveBeenCalledWith(document, [], true
|
|
319
|
+
expect(ShadowMutationObserverService.notifyShadowMutationSubscribers).toHaveBeenCalledWith(document, [], true, {
|
|
320
|
+
fromFocus: true,
|
|
321
|
+
});
|
|
310
322
|
});
|
|
311
323
|
});
|
|
312
324
|
});
|
|
@@ -103,7 +103,7 @@ class ShadowMutationObserverService {
|
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
105
|
* Register a subscriber to the shadow root mutations
|
|
106
|
-
* @param {(root: Document|ShadowRoot|Element, mutations: MutationRecord[], shadowRootsChanged: boolean) => void} callback
|
|
106
|
+
* @param {(root: Document|ShadowRoot|Element, mutations: MutationRecord[], shadowRootsChanged: boolean, options: {fromFocus?: boolean}) => void} callback
|
|
107
107
|
* @return {() => void} unsubscribe closure — must be called in the consumer's teardown.
|
|
108
108
|
*/
|
|
109
109
|
static subscribeToShadowMutations(callback) {
|
|
@@ -116,11 +116,13 @@ class ShadowMutationObserverService {
|
|
|
116
116
|
* @param {Document|ShadowRoot|Element} root
|
|
117
117
|
* @param {MutationRecord[]} mutations
|
|
118
118
|
* @param {boolean} shadowRootsChanged
|
|
119
|
+
* @param {object} [options]
|
|
120
|
+
* @param {boolean} [options.fromFocus=false] Whether the notification comes from the user focusing a field.
|
|
119
121
|
*/
|
|
120
|
-
static notifyShadowMutationSubscribers(root, mutations, shadowRootsChanged) {
|
|
122
|
+
static notifyShadowMutationSubscribers(root, mutations, shadowRootsChanged, options = {}) {
|
|
121
123
|
for (const callback of ShadowMutationObserverService._shadowMutationSubscribers) {
|
|
122
124
|
try {
|
|
123
|
-
callback(root, mutations, shadowRootsChanged);
|
|
125
|
+
callback(root, mutations, shadowRootsChanged, options);
|
|
124
126
|
} catch (error) {
|
|
125
127
|
console.warn("ShadowMutationObserverService shadow-mutation subscriber threw", error);
|
|
126
128
|
}
|
|
@@ -221,7 +221,18 @@ describe("ShadowMutationObserverService", () => {
|
|
|
221
221
|
|
|
222
222
|
ShadowMutationObserverService.notifyShadowMutationSubscribers(root, mutations, true);
|
|
223
223
|
|
|
224
|
-
expect(callback).toHaveBeenCalledWith(root, mutations, true);
|
|
224
|
+
expect(callback).toHaveBeenCalledWith(root, mutations, true, {});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("should forward the notification options to the subscribers", () => {
|
|
228
|
+
expect.assertions(1);
|
|
229
|
+
|
|
230
|
+
const callback = jest.fn();
|
|
231
|
+
ShadowMutationObserverService._shadowMutationSubscribers.add(callback);
|
|
232
|
+
|
|
233
|
+
ShadowMutationObserverService.notifyShadowMutationSubscribers(document, [], true, { fromFocus: true });
|
|
234
|
+
|
|
235
|
+
expect(callback).toHaveBeenCalledWith(document, [], true, { fromFocus: true });
|
|
225
236
|
});
|
|
226
237
|
|
|
227
238
|
it("should isolate a throwing subscriber so the others still run", () => {
|