From 80fe2162d21517e1acfb7b665676c3ad75f6efb4 Mon Sep 17 00:00:00 2001 From: Todd Schiller Date: Fri, 21 Jun 2024 08:06:46 -0400 Subject: [PATCH] Rename context menu and tour starter bricks --- src/activation/useActivateRecipe.test.ts | 2 +- .../contextMenus/initContextMenus.test.ts | 4 +- .../contextMenus/preloadContextMenus.ts | 4 +- src/components/BrickIcon.tsx | 2 +- src/contentScript/lifecycle.ts | 2 +- .../draft/updateDraftModComponent.ts | 2 +- src/pageEditor/starterBricks/contextMenu.ts | 4 +- .../starterBricks/formStateTypes.ts | 4 +- src/pageEditor/starterBricks/tour.ts | 4 +- ...est.ts => contextMenuStarterBrick.test.ts} | 26 +++--- ...textMenu.ts => contextMenuStarterBrick.ts} | 87 ++++++++++--------- .../{types.ts => contextMenuTypes.ts} | 0 src/starterBricks/factory.ts | 4 +- src/starterBricks/tour/tourController.test.ts | 20 ++--- ...nsion.test.ts => tourStarterBrick.test.ts} | 4 +- .../{tourExtension.ts => tourStarterBrick.ts} | 77 ++++++++-------- .../tour/{types.ts => tourTypes.ts} | 0 src/tsconfig.strictNullChecks.json | 10 +-- 18 files changed, 129 insertions(+), 127 deletions(-) rename src/starterBricks/contextMenu/{contextMenu.test.ts => contextMenuStarterBrick.test.ts} (84%) rename src/starterBricks/contextMenu/{contextMenu.ts => contextMenuStarterBrick.ts} (85%) rename src/starterBricks/contextMenu/{types.ts => contextMenuTypes.ts} (100%) rename src/starterBricks/tour/{tourExtension.test.ts => tourStarterBrick.test.ts} (97%) rename src/starterBricks/tour/{tourExtension.ts => tourStarterBrick.ts} (79%) rename src/starterBricks/tour/{types.ts => tourTypes.ts} (100%) diff --git a/src/activation/useActivateRecipe.test.ts b/src/activation/useActivateRecipe.test.ts index 7c4209b3ad..45369cc92b 100644 --- a/src/activation/useActivateRecipe.test.ts +++ b/src/activation/useActivateRecipe.test.ts @@ -20,7 +20,7 @@ import { renderHook } from "@/pageEditor/testHelpers"; import useActivateRecipe from "./useActivateRecipe"; import { validateRegistryId } from "@/types/helpers"; import { type StarterBrickDefinitionLike } from "@/starterBricks/types"; -import { type ContextMenuDefinition } from "@/starterBricks/contextMenu/types"; +import { type ContextMenuDefinition } from "@/starterBricks/contextMenu/contextMenuTypes"; import { uninstallRecipe } from "@/store/uninstallUtils"; import { type ModDefinition } from "@/types/modDefinitionTypes"; import extensionsSlice from "@/store/extensionsSlice"; diff --git a/src/background/contextMenus/initContextMenus.test.ts b/src/background/contextMenus/initContextMenus.test.ts index 52fa07e870..36dfd3012a 100644 --- a/src/background/contextMenus/initContextMenus.test.ts +++ b/src/background/contextMenus/initContextMenus.test.ts @@ -16,7 +16,7 @@ */ import extensionPointRegistry from "@/starterBricks/registry"; -import { fromJS } from "@/starterBricks/contextMenu/contextMenu"; +import { fromJS } from "@/starterBricks/contextMenu/contextMenuStarterBrick"; import * as backgroundApi from "@/background/messenger/api"; import { type StarterBrickDefinitionLike } from "@/starterBricks/types"; import { type ModComponentBase } from "@/types/modComponentTypes"; @@ -28,7 +28,7 @@ import { getPlatform } from "@/platform/platformContext"; import { type ContextMenuDefinition, type ContextMenuConfig, -} from "@/starterBricks/contextMenu/types"; +} from "@/starterBricks/contextMenu/contextMenuTypes"; import { ensureContextMenu } from "@/background/contextMenus/ensureContextMenu"; import { preloadContextMenus } from "@/background/contextMenus/preloadContextMenus"; diff --git a/src/background/contextMenus/preloadContextMenus.ts b/src/background/contextMenus/preloadContextMenus.ts index 41e563950d..d46209289f 100644 --- a/src/background/contextMenus/preloadContextMenus.ts +++ b/src/background/contextMenus/preloadContextMenus.ts @@ -17,8 +17,8 @@ import { ContextError } from "@/errors/genericErrors"; import { resolveExtensionInnerDefinitions } from "@/registry/internal"; -import { ContextMenuStarterBrickABC } from "@/starterBricks/contextMenu/contextMenu"; -import { type ContextMenuConfig } from "@/starterBricks/contextMenu/types"; +import { ContextMenuStarterBrickABC } from "@/starterBricks/contextMenu/contextMenuStarterBrick"; +import { type ContextMenuConfig } from "@/starterBricks/contextMenu/contextMenuTypes"; import { selectEventData } from "@/telemetry/deployments"; import { type ModComponentBase, diff --git a/src/components/BrickIcon.tsx b/src/components/BrickIcon.tsx index 85d19f519d..b7c59940bf 100644 --- a/src/components/BrickIcon.tsx +++ b/src/components/BrickIcon.tsx @@ -31,7 +31,7 @@ import { } from "@fortawesome/free-solid-svg-icons"; import { TriggerStarterBrickABC } from "@/starterBricks/trigger/triggerStarterBrick"; import { MenuItemStarterBrickABC } from "@/starterBricks/menuItem/menuItemStarterBrick"; -import { ContextMenuStarterBrickABC } from "@/starterBricks/contextMenu/contextMenu"; +import { ContextMenuStarterBrickABC } from "@/starterBricks/contextMenu/contextMenuStarterBrick"; import { PanelStarterBrickABC } from "@/starterBricks/panel/panelStarterBrick"; import { SidebarStarterBrickABC } from "@/starterBricks/sidebar/sidebarStarterBrick"; import getType from "@/runtime/getType"; diff --git a/src/contentScript/lifecycle.ts b/src/contentScript/lifecycle.ts index 207684c3f4..d553704ec3 100644 --- a/src/contentScript/lifecycle.ts +++ b/src/contentScript/lifecycle.ts @@ -46,7 +46,7 @@ import { } from "@/utils/promiseUtils"; import { $safeFind } from "@/utils/domUtils"; import { onContextInvalidated } from "webext-events"; -import { ContextMenuStarterBrickABC } from "@/starterBricks/contextMenu/contextMenu"; +import { ContextMenuStarterBrickABC } from "@/starterBricks/contextMenu/contextMenuStarterBrick"; import { ReusableAbortController } from "abort-utils"; import { isLoadedInIframe } from "@/utils/iframeUtils"; import { notifyNavigationComplete } from "@/contentScript/sidebarController"; diff --git a/src/contentScript/pageEditor/draft/updateDraftModComponent.ts b/src/contentScript/pageEditor/draft/updateDraftModComponent.ts index baa3f4fe04..2966207a5e 100644 --- a/src/contentScript/pageEditor/draft/updateDraftModComponent.ts +++ b/src/contentScript/pageEditor/draft/updateDraftModComponent.ts @@ -28,7 +28,7 @@ import { activateExtensionPanel, showSidebar, } from "@/contentScript/sidebarController"; -import { type TourDefinition } from "@/starterBricks/tour/types"; +import { type TourDefinition } from "@/starterBricks/tour/tourTypes"; import { isLoadedInIframe } from "@/utils/iframeUtils"; export async function updateDraftModComponent({ diff --git a/src/pageEditor/starterBricks/contextMenu.ts b/src/pageEditor/starterBricks/contextMenu.ts index 0216ccb0c7..b4e44d1f21 100644 --- a/src/pageEditor/starterBricks/contextMenu.ts +++ b/src/pageEditor/starterBricks/contextMenu.ts @@ -31,7 +31,7 @@ import { selectStarterBrickAvailability, } from "@/pageEditor/starterBricks/base"; import { type StarterBrickDefinitionLike } from "@/starterBricks/types"; -import { ContextMenuStarterBrickABC } from "@/starterBricks/contextMenu/contextMenu"; +import { ContextMenuStarterBrickABC } from "@/starterBricks/contextMenu/contextMenuStarterBrick"; import { faBars } from "@fortawesome/free-solid-svg-icons"; import { type ModComponentFormStateAdapter } from "@/pageEditor/starterBricks/modComponentFormStateAdapter"; import ContextMenuConfiguration from "@/pageEditor/tabs/contextMenu/ContextMenuConfiguration"; @@ -42,7 +42,7 @@ import { type SingleLayerReaderConfig } from "@/pageEditor/baseFormStateTypes"; import { type ContextMenuDefinition, type ContextMenuConfig, -} from "@/starterBricks/contextMenu/types"; +} from "@/starterBricks/contextMenu/contextMenuTypes"; import { assertNotNullish } from "@/utils/nullishUtils"; function fromNativeElement( diff --git a/src/pageEditor/starterBricks/formStateTypes.ts b/src/pageEditor/starterBricks/formStateTypes.ts index 420f5ab558..46a30eb134 100644 --- a/src/pageEditor/starterBricks/formStateTypes.ts +++ b/src/pageEditor/starterBricks/formStateTypes.ts @@ -20,7 +20,7 @@ import { type ContextMenuConfig, type ContextMenuTargetMode, type MenuDefaultOptions as ContextMenuDefaultOptions, -} from "@/starterBricks/contextMenu/types"; +} from "@/starterBricks/contextMenu/contextMenuTypes"; import { type MenuItemStarterBrickConfig, type MenuPosition, @@ -52,7 +52,7 @@ import { type QuickBarProviderConfig, type QuickBarProviderDefaultOptions, } from "@/starterBricks/quickBarProvider/quickBarProviderTypes"; -import { type TourDefinition } from "@/starterBricks/tour/types"; +import { type TourDefinition } from "@/starterBricks/tour/tourTypes"; import { type BaseExtensionPointState, type BaseExtensionState, diff --git a/src/pageEditor/starterBricks/tour.ts b/src/pageEditor/starterBricks/tour.ts index 08c47a3903..9a1a4d9d5e 100644 --- a/src/pageEditor/starterBricks/tour.ts +++ b/src/pageEditor/starterBricks/tour.ts @@ -37,13 +37,13 @@ import { faMapSigns } from "@fortawesome/free-solid-svg-icons"; import { type ModComponentFormStateAdapter } from "@/pageEditor/starterBricks/modComponentFormStateAdapter"; import type { DraftModComponent } from "@/contentScript/pageEditor/types"; import { type TourFormState } from "./formStateTypes"; -import { TourStarterBrickABC } from "@/starterBricks/tour/tourExtension"; +import { TourStarterBrickABC } from "@/starterBricks/tour/tourStarterBrick"; import TourConfiguration from "@/pageEditor/tabs/tour/TourConfiguration"; import { type ModComponentBase } from "@/types/modComponentTypes"; import { type TourDefinition, type TourConfig, -} from "@/starterBricks/tour/types"; +} from "@/starterBricks/tour/tourTypes"; import { assertNotNullish } from "@/utils/nullishUtils"; function fromNativeElement( diff --git a/src/starterBricks/contextMenu/contextMenu.test.ts b/src/starterBricks/contextMenu/contextMenuStarterBrick.test.ts similarity index 84% rename from src/starterBricks/contextMenu/contextMenu.test.ts rename to src/starterBricks/contextMenu/contextMenuStarterBrick.test.ts index b9a25b4baa..df28c745bd 100644 --- a/src/starterBricks/contextMenu/contextMenu.test.ts +++ b/src/starterBricks/contextMenu/contextMenuStarterBrick.test.ts @@ -22,7 +22,7 @@ import { type Metadata } from "@/types/registryTypes"; import { type BrickPipeline } from "@/bricks/types"; import { RootReader } from "@/starterBricks/starterBrickTestUtils"; import blockRegistry from "@/bricks/registry"; -import { fromJS } from "@/starterBricks/contextMenu/contextMenu"; +import { fromJS } from "@/starterBricks/contextMenu/contextMenuStarterBrick"; import { type ResolvedModComponent } from "@/types/modComponentTypes"; import { uuidSequence } from "@/testUtils/factories/stringFactories"; import { RunReason } from "@/types/runtimeTypes"; @@ -34,14 +34,14 @@ import { getPlatform } from "@/platform/platformContext"; import { type ContextMenuDefinition, type ContextMenuConfig, -} from "@/starterBricks/contextMenu/types"; +} from "@/starterBricks/contextMenu/contextMenuTypes"; const uninstallContextMenuMock = jest.mocked(uninstallContextMenu); const ensureContextMenuMock = jest.mocked(ensureContextMenu); const rootReader = new RootReader(); -const extensionPointFactory = (definitionOverrides: UnknownObject = {}) => +const starterBrickFactory = (definitionOverrides: UnknownObject = {}) => define>({ apiVersion: "v3", kind: "extensionPoint", @@ -62,7 +62,7 @@ const extensionPointFactory = (definitionOverrides: UnknownObject = {}) => }), }); -const extensionFactory = define>({ +const modComponentFactory = define>({ apiVersion: "v3", _resolvedModComponentBrand: undefined as never, id: uuidSequence, @@ -86,10 +86,10 @@ beforeEach(() => { jest.resetAllMocks(); }); -describe("contextMenu", () => { +describe("contextMenuStarterBrick", () => { it("should add extension once", async () => { - const starterBrick = fromJS(getPlatform(), extensionPointFactory()()); - const modComponent = extensionFactory(); + const starterBrick = fromJS(getPlatform(), starterBrickFactory()()); + const modComponent = modComponentFactory(); starterBrick.registerModComponent(modComponent); starterBrick.registerModComponent(modComponent); @@ -98,21 +98,21 @@ describe("contextMenu", () => { }); it("should include context menu props in schema", async () => { - const starterBrick = fromJS(getPlatform(), extensionPointFactory()()); + const starterBrick = fromJS(getPlatform(), starterBrickFactory()()); const reader = await starterBrick.defaultReader(); expect(reader.outputSchema.properties).toHaveProperty("selectionText"); }); it("should include context menu props in preview", async () => { - const starterBrick = fromJS(getPlatform(), extensionPointFactory()()); + const starterBrick = fromJS(getPlatform(), starterBrickFactory()()); const reader = await starterBrick.previewReader(); const value = await reader.read(document); expect(value).toHaveProperty("selectionText"); }); it("should register context menu on run", async () => { - const starterBrick = fromJS(getPlatform(), extensionPointFactory()()); - const modComponent = extensionFactory(); + const starterBrick = fromJS(getPlatform(), starterBrickFactory()()); + const modComponent = modComponentFactory(); starterBrick.registerModComponent(modComponent); @@ -131,8 +131,8 @@ describe("contextMenu", () => { }); it("should remove from UI from all tabs on sync", async () => { - const starterBrick = fromJS(getPlatform(), extensionPointFactory()()); - const modComponent = extensionFactory(); + const starterBrick = fromJS(getPlatform(), starterBrickFactory()()); + const modComponent = modComponentFactory(); starterBrick.registerModComponent(modComponent); await starterBrick.install(); diff --git a/src/starterBricks/contextMenu/contextMenu.ts b/src/starterBricks/contextMenu/contextMenuStarterBrick.ts similarity index 85% rename from src/starterBricks/contextMenu/contextMenu.ts rename to src/starterBricks/contextMenu/contextMenuStarterBrick.ts index 860088d74c..c7224dd865 100644 --- a/src/starterBricks/contextMenu/contextMenu.ts +++ b/src/starterBricks/contextMenu/contextMenuStarterBrick.ts @@ -70,7 +70,7 @@ import { type ContextMenuTargetMode, type ContextMenuConfig, type ContextMenuDefinition, -} from "@/starterBricks/contextMenu/types"; +} from "@/starterBricks/contextMenu/contextMenuTypes"; import { assertNotNullish } from "@/utils/nullishUtils"; const DEFAULT_MENU_ITEM_TITLE = "Untitled menu item"; @@ -79,7 +79,7 @@ const groupRegistrationErrorNotification = (platform: PlatformProtocol) => batchedFunction( (errors: unknown[][]): void => { // `batchedFunction` will throttle the calls and coalesce all the errors into a - // single notification, even if they come from different extensions + // single notification, even if they come from different mod components // https://github.com/pixiebrix/pixiebrix-extension/issues/7353 platform.toasts.showNotification({ type: "error", @@ -164,37 +164,37 @@ export abstract class ContextMenuStarterBrickABC extends StarterBrickABC, + modComponent: ResolvedModComponent, ): Promise { - return collectAllBricks(extension.config.action); + return collectAllBricks(modComponent.config.action); } override uninstall({ global = false }: { global?: boolean }): void { // NOTE: don't uninstall the mouse/click handler because other context menus need it - const extensions = this.modComponents.splice(0); + const modComponents = this.modComponents.splice(0); if (global) { - for (const extension of extensions) { - void getPlatform().contextMenus.unregister(extension.id); - getPlatform().textSelectionMenu.unregister(extension.id); + for (const modComponent of modComponents) { + void getPlatform().contextMenus.unregister(modComponent.id); + getPlatform().textSelectionMenu.unregister(modComponent.id); } } } /** - * Remove the context menu items for the given extensions from all tabs/contexts. + * Remove the context menu items for the given mod components from all tabs/contexts. * @see uninstallContextMenu * @see preloadContextMenus */ - clearModComponentInterfaceAndEvents(extensionIds: UUID[]): void { + clearModComponentInterfaceAndEvents(modComponentIds: UUID[]): void { // Context menus are registered with Chrome by document pattern via the background page. Therefore, it's impossible // to clear the UI menu item from a single tab. Calling `uninstallContextMenu` removes the tab from all menus. // Uninstalling context menus is the least-bad approach because it prevents duplicate menu item titles due to - // re-activating a context menu (during re-activation, mod components get new extensionIds.) + // re-activating a context menu (during re-activation, mod components get new modComponentIds.) - for (const extensionId of extensionIds) { - void getPlatform().contextMenus.unregister(extensionId); - getPlatform().textSelectionMenu.unregister(extensionId); + for (const modComponentId of modComponentIds) { + void getPlatform().contextMenus.unregister(modComponentId); + getPlatform().textSelectionMenu.unregister(modComponentId); } } @@ -215,7 +215,7 @@ export abstract class ContextMenuStarterBrickABC extends StarterBrickABC { - await this.registerExtensions(); + await this.registerModComponents(); } override async defaultReader(): Promise { @@ -233,15 +233,15 @@ export abstract class ContextMenuStarterBrickABC extends StarterBrickABC, "id" | "config" | "_deployment" >, handler: (clickData: Menus.OnClickData) => Promise, ): Promise { - const { title = DEFAULT_MENU_ITEM_TITLE } = extension.config; + const { title = DEFAULT_MENU_ITEM_TITLE } = modComponent.config; - if (!isDeploymentActive(extension)) { + if (!isDeploymentActive(modComponent)) { return; } @@ -250,7 +250,7 @@ export abstract class ContextMenuStarterBrickABC extends StarterBrickABC { + private async registerModComponents(): Promise { console.debug( "Registering", this.modComponents.length, "contextMenu starter bricks", ); - const promises = this.modComponents.map(async (extension) => { + const promises = this.modComponents.map(async (modComponent) => { try { - await this.registerExtension(extension); + await this.registerModComponentItem(modComponent); } catch (error) { reportError(error, { context: { - deploymentId: extension._deployment?.id, - extensionPointId: extension.extensionPointId, - extensionId: extension.id, + deploymentId: modComponent._deployment?.id, + extensionPointId: modComponent.extensionPointId, + extensionId: modComponent.id, }, }); throw error; @@ -321,17 +321,17 @@ export abstract class ContextMenuStarterBrickABC extends StarterBrickABC, + private async registerModComponentItem( + modComponent: ResolvedModComponent, ): Promise { const { action: actionConfig, onSuccess = {}, title = DEFAULT_MENU_ITEM_TITLE, - } = extension.config; + } = modComponent.config; - const extensionLogger = this.logger.childLogger( - selectModComponentContext(extension), + const modComponentLogger = this.logger.childLogger( + selectModComponentContext(modComponent), ); const handler = async ( @@ -340,13 +340,14 @@ export abstract class ContextMenuStarterBrickABC extends StarterBrickABC, ): Promise => { - reportEvent(Events.HANDLE_CONTEXT_MENU, selectEventData(extension)); + reportEvent(Events.HANDLE_CONTEXT_MENU, selectEventData(modComponent)); try { const reader = await this.getBaseReader(); - const serviceContext = await makeIntegrationsContextFromDependencies( - extension.integrationDependencies, - ); + const integrationsContext = + await makeIntegrationsContextFromDependencies( + modComponent.integrationDependencies, + ); const targetElement = clickedElement ?? guessSelectedElement() ?? document; @@ -362,13 +363,13 @@ export abstract class ContextMenuStarterBrickABC extends StarterBrickABC { test("ad-hoc tour", () => { const nonce = uuidv4(); - const extensionId = uuidv4(); + const modComponentId = uuidv4(); const abortController = new AbortController(); markTourStart( nonce, - { id: extensionId, label: "Ad-hoc", _recipe: undefined }, - { abortController, context: { extensionId } }, + { id: modComponentId, label: "Ad-hoc", _recipe: undefined }, + { abortController, context: { extensionId: modComponentId } }, ); expect(isTourInProgress()).toBe(true); - markTourEnd(nonce, { context: { extensionId } }); + markTourEnd(nonce, { context: { extensionId: modComponentId } }); expect(isTourInProgress()).toBe(false); }); test("cancel all tours", () => { const nonce = uuidv4(); - const extensionId = uuidv4(); + const modComponentId = uuidv4(); const abortController = new AbortController(); markTourStart( nonce, - { id: extensionId, label: "Ad-hoc", _recipe: undefined }, - { abortController, context: { extensionId } }, + { id: modComponentId, label: "Ad-hoc", _recipe: undefined }, + { abortController, context: { extensionId: modComponentId } }, ); expect(isTourInProgress()).toBe(true); @@ -65,12 +65,12 @@ describe("tourController", () => { }); test("register and run sub-tour", async () => { - const blueprintId = validateRegistryId("test/tour"); + const modId = validateRegistryId("test/tour"); const tourPromise = pDefer(); await registerTour({ - blueprintId, + blueprintId: modId, extension: { id: uuidv4(), label: "Test Tour", @@ -88,7 +88,7 @@ describe("tourController", () => { const { promise: subTourPromise, nonce } = await runSubTour({ tour: "Test Tour", - blueprintId, + blueprintId: modId, }); expect(getCurrentTour()?.nonce).toBe(nonce); diff --git a/src/starterBricks/tour/tourExtension.test.ts b/src/starterBricks/tour/tourStarterBrick.test.ts similarity index 97% rename from src/starterBricks/tour/tourExtension.test.ts rename to src/starterBricks/tour/tourStarterBrick.test.ts index 8efcc406ef..a8842c1b5a 100644 --- a/src/starterBricks/tour/tourExtension.test.ts +++ b/src/starterBricks/tour/tourStarterBrick.test.ts @@ -20,7 +20,7 @@ import { type StarterBrickDefinitionLike } from "@/starterBricks/types"; import { validateRegistryId } from "@/types/helpers"; import { type Metadata } from "@/types/registryTypes"; import { type BrickPipeline } from "@/bricks/types"; -import { fromJS } from "@/starterBricks/tour/tourExtension"; +import { fromJS } from "@/starterBricks/tour/tourStarterBrick"; import { RootReader, tick } from "@/starterBricks/starterBrickTestUtils"; import blockRegistry from "@/bricks/registry"; import { isTourInProgress } from "@/starterBricks/tour/tourController"; @@ -43,7 +43,7 @@ import { getPlatform } from "@/platform/platformContext"; import { type TourDefinition, type TourConfig, -} from "@/starterBricks/tour/types"; +} from "@/starterBricks/tour/tourTypes"; const rootReader = new RootReader(); diff --git a/src/starterBricks/tour/tourExtension.ts b/src/starterBricks/tour/tourStarterBrick.ts similarity index 79% rename from src/starterBricks/tour/tourExtension.ts rename to src/starterBricks/tour/tourStarterBrick.ts index 70676b52e1..94923d1377 100644 --- a/src/starterBricks/tour/tourExtension.ts +++ b/src/starterBricks/tour/tourStarterBrick.ts @@ -63,7 +63,7 @@ import { propertiesToSchema } from "@/utils/schemaUtils"; import { type TourConfig, type TourDefinition, -} from "@/starterBricks/tour/types"; +} from "@/starterBricks/tour/tourTypes"; import { type Nullishable, assertNotNullish } from "@/utils/nullishUtils"; export abstract class TourStarterBrickABC extends StarterBrickABC { @@ -73,7 +73,7 @@ export abstract class TourStarterBrickABC extends StarterBrickABC { readonly capabilities: PlatformCapability[] = CONTENT_SCRIPT_CAPABILITIES; - readonly extensionTours = new Map(); + readonly modComponentTours = new Map(); /** * Allow the user to manually run the tour, e.g., via the Quick Bar. @@ -99,13 +99,13 @@ export abstract class TourStarterBrickABC extends StarterBrickABC { return false; } - clearModComponentInterfaceAndEvents(extensionIds: UUID[]): void { - console.debug("tourExtension:removeExtensions"); + clearModComponentInterfaceAndEvents(modComponentIds: UUID[]): void { + console.debug("tourStarterBrick:clearModComponentInterfaceAndEvents"); unregisterTours(this.modComponents.map((x) => x.id)); } override uninstall(): void { - console.debug("tourExtension:uninstall", { + console.debug("tourStarterBrick:uninstall", { id: this.id, }); unregisterTours(this.modComponents.map((x) => x.id)); @@ -121,35 +121,35 @@ export abstract class TourStarterBrickABC extends StarterBrickABC { ); async getBricks( - extension: ResolvedModComponent, + modComponent: ResolvedModComponent, ): Promise { - return collectAllBricks(extension.config.tour); + return collectAllBricks(modComponent.config.tour); } - private async runExtensionTour( - extension: ResolvedModComponent, + private async runModComponentTour( + modComponent: ResolvedModComponent, abortController: AbortController, ): Promise { const reader = await this.defaultReader(); - const { tour: tourConfig } = extension.config; + const { tour: tourConfig } = modComponent.config; const ctxt = await reader.read(document); - const extensionLogger = this.logger.childLogger( - selectModComponentContext(extension), + const modComponentLogger = this.logger.childLogger( + selectModComponentContext(modComponent), ); const initialValues: InitialValues = { input: ctxt, root: document, serviceContext: await makeIntegrationsContextFromDependencies( - extension.integrationDependencies, + modComponent.integrationDependencies, ), - optionsArgs: extension.optionsArgs, + optionsArgs: modComponent.optionsArgs, }; await reduceExtensionPipeline(tourConfig, initialValues, { - logger: extensionLogger, - ...apiVersionOptions(extension.apiVersion), + logger: modComponentLogger, + ...apiVersionOptions(modComponent.apiVersion), abortSignal: abortController.signal, }); } @@ -158,25 +158,25 @@ export abstract class TourStarterBrickABC extends StarterBrickABC { * Register a tour with the tour controller. */ private async registerTour( - extension: ResolvedModComponent, + modComponent: ResolvedModComponent, ): Promise { assertNotNullish( - extension._recipe?.id, + modComponent._recipe?.id, "Blueprint ID is required to register tour", ); const tour = await registerTour({ - blueprintId: extension._recipe.id, - extension, + blueprintId: modComponent._recipe.id, + extension: modComponent, allowUserRun: this.allowUserRun, run: () => { const abortController = new AbortController(); - const promise = this.runExtensionTour(extension, abortController); + const promise = this.runModComponentTour(modComponent, abortController); return { promise, abortController }; }, }); - this.extensionTours.set(extension.id, tour); + this.modComponentTours.set(modComponent.id, tour); } /** @@ -192,22 +192,22 @@ export abstract class TourStarterBrickABC extends StarterBrickABC { async decideAutoRunTour(): Promise< Nullishable> > { - const extensionIds = new Set(this.modComponents.map((x) => x.id)); + const modComponentIds = new Set(this.modComponents.map((x) => x.id)); const runs = await getAll(); - // Try to group by extensionId, otherwise fall back to blueprintId+label + // Try to group by mod component id, otherwise fall back to mod id + label const matching = groupBy(runs, (tour) => { - if (extensionIds.has(tour.extensionId)) { + if (modComponentIds.has(tour.extensionId)) { return tour.extensionId; } - for (const extension of this.modComponents) { + for (const modComponent of this.modComponents) { if ( - extension._recipe?.id === tour.packageId && - extension.label === tour.tourName + modComponent._recipe?.id === tour.packageId && + modComponent.label === tour.tourName ) { - return extension.id; + return modComponent.id; } } @@ -252,9 +252,10 @@ export abstract class TourStarterBrickABC extends StarterBrickABC { // tours re-running on Page Editor close/open or "Reactivate All" unless they have a matching autoRunSchedule if (reason === RunReason.PAGE_EDITOR) { cancelAllTours(); - const extensionPool = extensionIds ?? this.modComponents.map((x) => x.id); + const modComponentPool = + extensionIds ?? this.modComponents.map((x) => x.id); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion -- this.modComponents.length > 0 - this.extensionTours.get(extensionPool[0]!)?.run(); + this.modComponentTours.get(modComponentPool[0]!)?.run(); return; } @@ -264,22 +265,22 @@ export abstract class TourStarterBrickABC extends StarterBrickABC { } if (this.autoRunSchedule === "never") { - // Don't auto-run tours from this extension point. They must be run via the tourController run method + // Don't auto-run tours from this starter brick. They must be run via the tourController run method return; } - // Have to re-check isTourInProgress to avoid race condition with other instances of this extension point + // Have to re-check isTourInProgress to avoid race condition with other instances of this starter brick // returning from decideAutoRunTour - const extension = await this.decideAutoRunTour(); - if (extension && !isTourInProgress()) { - const registeredTour = this.extensionTours.get(extension.id); + const modComponent = await this.decideAutoRunTour(); + if (modComponent && !isTourInProgress()) { + const registeredTour = this.modComponentTours.get(modComponent.id); assertNotNullish(registeredTour, "Tour not registered"); registeredTour.run(); } } } -class RemoteTourExtensionPoint extends TourStarterBrickABC { +class RemoteTourStarterBrick extends TourStarterBrickABC { private readonly _definition: TourDefinition; public readonly permissions: Permissions.Permissions; @@ -336,5 +337,5 @@ export function fromJS( throw new Error(`Expected type=tour, got ${type}`); } - return new RemoteTourExtensionPoint(platform, config); + return new RemoteTourStarterBrick(platform, config); } diff --git a/src/starterBricks/tour/types.ts b/src/starterBricks/tour/tourTypes.ts similarity index 100% rename from src/starterBricks/tour/types.ts rename to src/starterBricks/tour/tourTypes.ts diff --git a/src/tsconfig.strictNullChecks.json b/src/tsconfig.strictNullChecks.json index f9c822a9b6..b27b6939f1 100644 --- a/src/tsconfig.strictNullChecks.json +++ b/src/tsconfig.strictNullChecks.json @@ -1337,10 +1337,10 @@ "./sidebar/store.ts", "./sidebar/testHelpers.ts", "./sidebar/useHideEmptySidebar.ts", - "./starterBricks/contextMenu/contextMenu.test.ts", - "./starterBricks/contextMenu/contextMenu.ts", + "./starterBricks/contextMenu/contextMenuStarterBrick.test.ts", + "./starterBricks/contextMenu/contextMenuStarterBrick.ts", "./starterBricks/contextMenu/contextMenuReader.ts", - "./starterBricks/contextMenu/types.ts", + "./starterBricks/contextMenu/contextMenuTypes.ts", "./starterBricks/dom.tsx", "./starterBricks/factory.ts", "./starterBricks/helpers.test.ts", @@ -1368,8 +1368,8 @@ "./starterBricks/tour/tourActionIcon.tsx", "./starterBricks/tour/tourController.test.ts", "./starterBricks/tour/tourController.ts", - "./starterBricks/tour/tourExtension.ts", - "./starterBricks/tour/types.ts", + "./starterBricks/tour/tourStarterBrick.ts", + "./starterBricks/tour/tourTypes.ts", "./starterBricks/trigger/triggerEventReaders.ts", "./starterBricks/trigger/triggerStarterBrick.test.ts", "./starterBricks/trigger/triggerStarterBrick.ts",