From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../migration/content/migration-wizard.mjs | 146 +++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 browser/components/migration/content/migration-wizard.mjs (limited to 'browser/components/migration/content/migration-wizard.mjs') diff --git a/browser/components/migration/content/migration-wizard.mjs b/browser/components/migration/content/migration-wizard.mjs new file mode 100644 index 0000000000..74a80af277 --- /dev/null +++ b/browser/components/migration/content/migration-wizard.mjs @@ -0,0 +1,146 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// eslint-disable-next-line import/no-unassigned-import +import "chrome://global/content/elements/moz-button-group.mjs"; +import { MigrationWizardConstants } from "chrome://browser/content/migration/migration-wizard-constants.mjs"; + +/** + * This component contains the UI that steps users through migrating their + * data from other browsers to this one. This component only contains very + * basic logic and structure for the UI, and most of the state management + * occurs in the MigrationWizardChild JSWindowActor. + */ +export class MigrationWizard extends HTMLElement { + static #template = null; + + #deck = null; + #browserProfileSelector = null; + + static get markup() { + return ` + + `; + } + + static get fragment() { + if (!MigrationWizard.#template) { + let parser = new DOMParser(); + let doc = parser.parseFromString(MigrationWizard.markup, "text/html"); + MigrationWizard.#template = document.importNode( + doc.querySelector("template"), + true + ); + } + let fragment = MigrationWizard.#template.content.cloneNode(true); + if (window.IS_STORYBOOK) { + // If we're using Storybook, load the CSS from the static local file + // system rather than chrome:// to take advantage of auto-reloading. + fragment.querySelector("link[rel=stylesheet]").href = + "./migration/migration-wizard.css"; + } + return fragment; + } + + constructor() { + super(); + const shadow = this.attachShadow({ mode: "closed" }); + + if (window.MozXULElement) { + window.MozXULElement.insertFTLIfNeeded( + "locales-preview/migrationWizard.ftl" + ); + } + document.l10n.connectRoot(shadow); + + shadow.appendChild(MigrationWizard.fragment); + + this.#deck = shadow.querySelector("#wizard-deck"); + this.#browserProfileSelector = shadow.querySelector( + "#browser-profile-selector" + ); + } + + connectedCallback() { + this.dispatchEvent( + new CustomEvent("MigrationWizard:Init", { bubbles: true }) + ); + } + + /** + * This is the main entrypoint for updating the state and appearance of + * the wizard. + * + * @param {object} state The state to be represented by the component. + * @param {string} state.page The page of the wizard to display. This should + * be one of the MigrationWizardConstants.PAGES constants. + */ + setState(state) { + if (state.page == MigrationWizardConstants.PAGES.SELECTION) { + this.#onShowingSelection(state); + } + + this.#deck.setAttribute("selected-view", `page-${state.page}`); + } + + /** + * Called when showing the browser/profile selection page of the wizard. + * + * @param {object} state + * The state object passed into setState. The following properties are + * used: + * @param {string[]} state.migrators An array of source browser names that + * can be migrated from. + */ + #onShowingSelection(state) { + this.#browserProfileSelector.textContent = ""; + + for (let migratorKey of state.migrators) { + let opt = document.createElement("option"); + opt.value = migratorKey; + opt.textContent = migratorKey; + this.#browserProfileSelector.appendChild(opt); + } + } +} + +if (globalThis.customElements) { + customElements.define("migration-wizard", MigrationWizard); +} -- cgit v1.2.3