diff --git a/eslint.config.js b/eslint.config.js index c24d79ac6..2cc424443 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -8,21 +8,21 @@ export default tseslint.config( ...tseslint.configs.recommended, { ignores: [ - "**/build/", - "**/docs/", - "injected/lib", - "Sources/ContentScopeScripts/dist/", - "injected/integration-test/extension/contentScope.js", - "injected/integration-test/test-pages/duckplayer/scripts/dist", - "special-pages/pages/**/public", - "special-pages/playwright-report/", - "special-pages/test-results/", - "special-pages/types/", - "special-pages/messages/", - "playwright-report", - "test-results", - "injected/src/types", - ".idea" + '**/build/', + '**/docs/', + 'injected/lib', + 'Sources/ContentScopeScripts/dist/', + 'injected/integration-test/extension/contentScope.js', + 'injected/integration-test/test-pages/duckplayer/scripts/dist', + 'special-pages/pages/**/public', + 'special-pages/playwright-report/', + 'special-pages/test-results/', + 'special-pages/types/', + 'special-pages/messages/', + 'playwright-report', + 'test-results', + 'injected/src/types', + '.idea', ], }, { diff --git a/special-pages/messages/new-tab/examples/stats.js b/special-pages/messages/new-tab/examples/stats.js index c36648f29..6cccb6a34 100644 --- a/special-pages/messages/new-tab/examples/stats.js +++ b/special-pages/messages/new-tab/examples/stats.js @@ -14,8 +14,8 @@ const privacyStatsData = { * @type {import("../../../types/new-tab").StatsConfig} */ const minimumConfig = { - expansion: "expanded", - animation: { kind: "none" } + expansion: 'expanded', + animation: { kind: 'none' }, } /** diff --git a/special-pages/pages/new-tab/app/components/Components.jsx b/special-pages/pages/new-tab/app/components/Components.jsx index 58ad07ef7..48fe700af 100644 --- a/special-pages/pages/new-tab/app/components/Components.jsx +++ b/special-pages/pages/new-tab/app/components/Components.jsx @@ -1,28 +1,26 @@ -import { Fragment, h } from "preact"; -import styles from "./Components.module.css"; -import { mainExamples, otherExamples } from "./Examples.jsx"; -import { updateNotificationExamples } from "../update-notification/UpdateNotification.examples.js"; -const url = new URL(window.location.href); +import { Fragment, h } from 'preact' +import styles from './Components.module.css' +import { mainExamples, otherExamples } from './Examples.jsx' +import { updateNotificationExamples } from '../update-notification/UpdateNotification.examples.js' +const url = new URL(window.location.href) const list = { ...mainExamples, ...otherExamples, - ...updateNotificationExamples + ...updateNotificationExamples, } -const entries = Object.entries(list); +const entries = Object.entries(list) export function Components() { - const ids = url.searchParams.getAll("id"); - const isolated = url.searchParams.has("isolate"); - const e2e = url.searchParams.has("e2e"); - const entryIds = entries.map(([id]) => id); + const ids = url.searchParams.getAll('id') + const isolated = url.searchParams.has('isolate') + const e2e = url.searchParams.has('e2e') + const entryIds = entries.map(([id]) => id) const validIds = ids.filter((id) => entryIds.includes(id)) - const filtered = validIds.length - ? validIds.map((id) => /** @type {const} */([id, list[id]])) - : entries + const filtered = validIds.length ? validIds.map((id) => /** @type {const} */ ([id, list[id]])) : entries if (isolated) { return diff --git a/special-pages/pages/new-tab/app/components/Layout.js b/special-pages/pages/new-tab/app/components/Layout.js index f3aeecea7..ba6c9a197 100644 --- a/special-pages/pages/new-tab/app/components/Layout.js +++ b/special-pages/pages/new-tab/app/components/Layout.js @@ -1,9 +1,5 @@ import { h } from 'preact' -export function Centered ({ children }) { - return ( -
- {children} -
- ) +export function Centered({ children }) { + return
{children}
} diff --git a/special-pages/pages/new-tab/app/customizer/Customizer.js b/special-pages/pages/new-tab/app/customizer/Customizer.js index f545cd306..05ea5b269 100644 --- a/special-pages/pages/new-tab/app/customizer/Customizer.js +++ b/special-pages/pages/new-tab/app/customizer/Customizer.js @@ -82,11 +82,11 @@ export function useContextMenu() { const items = getItems() /** @type {VisibilityMenuItem[]} */ const simplified = items - .filter(x => x.id !== 'debug') - .map(item => { + .filter((x) => x.id !== 'debug') + .map((item) => { return { id: item.id, - title: item.title + title: item.title, } }) messaging.contextMenu({ visibilityMenuItems: simplified }) diff --git a/special-pages/pages/new-tab/app/entry-points/favorites.js b/special-pages/pages/new-tab/app/entry-points/favorites.js index 7ca6addc6..47223e039 100644 --- a/special-pages/pages/new-tab/app/entry-points/favorites.js +++ b/special-pages/pages/new-tab/app/entry-points/favorites.js @@ -2,10 +2,10 @@ import { h } from 'preact' import { FavoritesCustomized } from '../favorites/Favorites.js' import { Centered } from '../components/Layout.js' -export function factory () { +export function factory() { return ( - + ) } diff --git a/special-pages/pages/new-tab/app/entry-points/privacyStats.js b/special-pages/pages/new-tab/app/entry-points/privacyStats.js index c550f95fd..0c23d61a7 100644 --- a/special-pages/pages/new-tab/app/entry-points/privacyStats.js +++ b/special-pages/pages/new-tab/app/entry-points/privacyStats.js @@ -2,7 +2,7 @@ import { h } from 'preact' import { PrivacyStatsCustomized } from '../privacy-stats/PrivacyStats.js' import { Centered } from '../components/Layout.js' -export function factory () { +export function factory() { return ( diff --git a/special-pages/pages/new-tab/app/entry-points/rmf.js b/special-pages/pages/new-tab/app/entry-points/rmf.js index 49df96912..0843ba558 100644 --- a/special-pages/pages/new-tab/app/entry-points/rmf.js +++ b/special-pages/pages/new-tab/app/entry-points/rmf.js @@ -3,11 +3,11 @@ import { Centered } from '../components/Layout.js' import { RMFConsumer } from '../remote-messaging-framework/RemoteMessagingFramework.js' import { RMFProvider } from '../remote-messaging-framework/RMFProvider.js' -export function factory () { +export function factory() { return ( - + ) diff --git a/special-pages/pages/new-tab/app/entry-points/updateNotification.js b/special-pages/pages/new-tab/app/entry-points/updateNotification.js index 921ca00fa..731144f6a 100644 --- a/special-pages/pages/new-tab/app/entry-points/updateNotification.js +++ b/special-pages/pages/new-tab/app/entry-points/updateNotification.js @@ -2,7 +2,7 @@ import { h } from 'preact' import { UpdateNotificationConsumer } from '../update-notification/UpdateNotification.js' import { UpdateNotificationProvider } from '../update-notification/UpdateNotificationProvider.js' -export function factory () { +export function factory() { return ( diff --git a/special-pages/pages/new-tab/app/favorites/Favorites.js b/special-pages/pages/new-tab/app/favorites/Favorites.js index 96ce87787..0ee915b27 100644 --- a/special-pages/pages/new-tab/app/favorites/Favorites.js +++ b/special-pages/pages/new-tab/app/favorites/Favorites.js @@ -15,6 +15,8 @@ export function FavoritesCustomized() { return null } return ( -

Favourites here... (id: {id})

+

+ Favourites here... (id: {id}) +

) } diff --git a/special-pages/pages/new-tab/app/index.js b/special-pages/pages/new-tab/app/index.js index f9cf6aa6e..d7d22a19f 100644 --- a/special-pages/pages/new-tab/app/index.js +++ b/special-pages/pages/new-tab/app/index.js @@ -11,7 +11,7 @@ import enStrings from '../src/locales/en/newtab.json' import { WidgetConfigProvider } from './widget-list/widget-config.provider.js' import { Settings } from './settings.js' import { Components } from './components/Components.jsx' -import { widgetEntryPoint } from "./widget-list/WidgetList.js"; +import { widgetEntryPoint } from './widget-list/WidgetList.js' /** * @param {import("../src/js").NewTabPage} messaging @@ -67,7 +67,6 @@ export async function init(messaging, baseEnvironment) { document.body.dataset.platformName = settings.platform.name - if (environment.display === 'components') { document.body.dataset.display = 'components' return render( @@ -84,15 +83,15 @@ export async function init(messaging, baseEnvironment) { const entryPoints = await (async () => { try { - const loaders = init.widgets.map(widget => { - return widgetEntryPoint(widget.id).then(mod => [widget.id, mod]); + const loaders = init.widgets.map((widget) => { + return widgetEntryPoint(widget.id).then((mod) => [widget.id, mod]) }) const entryPoints = await Promise.all(loaders) - return Object.fromEntries(entryPoints); + return Object.fromEntries(entryPoints) } catch (e) { - const error = new Error('Error loading widget entry points:' + e.message); + const error = new Error('Error loading widget entry points:' + e.message) didCatch(error) - console.error(error); + console.error(error) return {} } })() @@ -110,7 +109,12 @@ export async function init(messaging, baseEnvironment) { - + diff --git a/special-pages/pages/new-tab/app/remote-messaging-framework/RemoteMessagingFramework.js b/special-pages/pages/new-tab/app/remote-messaging-framework/RemoteMessagingFramework.js index 39f2eb22f..1efca0c72 100644 --- a/special-pages/pages/new-tab/app/remote-messaging-framework/RemoteMessagingFramework.js +++ b/special-pages/pages/new-tab/app/remote-messaging-framework/RemoteMessagingFramework.js @@ -17,7 +17,7 @@ import { Cross } from '../components/Icons.js' export function RemoteMessagingFramework({ message, primaryAction, secondaryAction, dismiss }) { const { id, messageType, titleText, descriptionText } = message return ( -
+
{messageType !== 'small' && message.icon && ( diff --git a/special-pages/pages/new-tab/app/update-notification/UpdateNotification.examples.js b/special-pages/pages/new-tab/app/update-notification/UpdateNotification.examples.js index 892f0cd2f..362a20118 100644 --- a/special-pages/pages/new-tab/app/update-notification/UpdateNotification.examples.js +++ b/special-pages/pages/new-tab/app/update-notification/UpdateNotification.examples.js @@ -5,20 +5,12 @@ import { noop } from '../utils.js' export const updateNotificationExamples = { empty: { factory: () => { - return - } + return + }, }, populated: { factory: () => { - return - } - } + return + }, + }, } diff --git a/special-pages/pages/new-tab/app/update-notification/UpdateNotification.js b/special-pages/pages/new-tab/app/update-notification/UpdateNotification.js index 91f3803bf..d8d64a58c 100644 --- a/special-pages/pages/new-tab/app/update-notification/UpdateNotification.js +++ b/special-pages/pages/new-tab/app/update-notification/UpdateNotification.js @@ -33,7 +33,7 @@ export function UpdateNotification({ notes, dismiss, version }) { ) } -export function WithNotes ({ notes, version }) { +export function WithNotes({ notes, version }) { const id = useId() const ref = useRef(/** @type {HTMLDetailsElement|null} */ (null)) const { t } = useTypedTranslation() @@ -79,13 +79,7 @@ export function UpdateNotificationConsumer() { // `state.data.content` can be empty - meaning there's no message to display! if (state.status === 'ready' && state.data.content) { - return ( - - ) + return } return null } diff --git a/special-pages/pages/new-tab/app/update-notification/update-notification.service.js b/special-pages/pages/new-tab/app/update-notification/update-notification.service.js index 543ccf97f..578923152 100644 --- a/special-pages/pages/new-tab/app/update-notification/update-notification.service.js +++ b/special-pages/pages/new-tab/app/update-notification/update-notification.service.js @@ -44,8 +44,8 @@ export class UpdateNotificationService { */ dismiss() { this.ntp.messaging.notify('updateNotification_dismiss') - - this.dataService.update(_old => { + + this.dataService.update((_old) => { return { content: null } }) } diff --git a/special-pages/pages/new-tab/app/widget-list/WidgetList.js b/special-pages/pages/new-tab/app/widget-list/WidgetList.js index 81883aa25..12541e1e1 100644 --- a/special-pages/pages/new-tab/app/widget-list/WidgetList.js +++ b/special-pages/pages/new-tab/app/widget-list/WidgetList.js @@ -2,20 +2,17 @@ import { Fragment, h } from 'preact' import { WidgetConfigContext, WidgetVisibilityProvider } from './widget-config.provider.js' import { useContext } from 'preact/hooks' import { Stack } from '../../../onboarding/app/components/Stack.js' -import { - Customizer, - CustomizerMenuPositionedFixed -} from '../customizer/Customizer.js' +import { Customizer, CustomizerMenuPositionedFixed } from '../customizer/Customizer.js' /** * @param {string} id * @return {{factory: () => import("preact").ComponentChild}} */ -function placeholderWidget (id) { +function placeholderWidget(id) { return { factory: () => { return

Entry point for {id} was not found. This is a bug.

- } + }, } } @@ -23,9 +20,8 @@ function placeholderWidget (id) { * @param {string} id * @return {Promise<{factory: () => import("preact").ComponentChild}>} */ -export async function widgetEntryPoint (id) { +export async function widgetEntryPoint(id) { try { - const mod = await import(`../entry-points/${id}.js`) if (typeof mod.factory !== 'function') { console.error(`module found for ${id}, but missing 'factory' export`) @@ -36,30 +32,22 @@ export async function widgetEntryPoint (id) { console.error(e) return placeholderWidget(id) } -}; +} -export function WidgetList () { +export function WidgetList() { const { widgets, widgetConfigItems, entryPoints } = useContext(WidgetConfigContext) return ( {widgets.map((widget, index) => { - const matchingConfig = widgetConfigItems.find(item => item.id === widget.id) + const matchingConfig = widgetConfigItems.find((item) => item.id === widget.id) const matchingEntryPoint = entryPoints[widget.id] if (!matchingConfig) { - return ( - - {matchingEntryPoint.factory?.()} - - ) + return {matchingEntryPoint.factory?.()} } return ( - + {matchingEntryPoint.factory?.()} diff --git a/special-pages/pages/new-tab/app/widget-list/widget-config.provider.js b/special-pages/pages/new-tab/app/widget-list/widget-config.provider.js index 08982173a..5b0080755 100644 --- a/special-pages/pages/new-tab/app/widget-list/widget-config.provider.js +++ b/special-pages/pages/new-tab/app/widget-list/widget-config.provider.js @@ -20,8 +20,6 @@ export const WidgetConfigContext = createContext({ /** @type {(id:string) => void} */ - toggle: (_id) => { - toggle: (_id) => {}, }) @@ -56,14 +54,16 @@ export function WidgetConfigProvider(props) { } return ( - + {props.children} ) diff --git a/special-pages/pages/new-tab/src/js/mock-transport.js b/special-pages/pages/new-tab/src/js/mock-transport.js index 72b40089c..e91bac8f2 100644 --- a/special-pages/pages/new-tab/src/js/mock-transport.js +++ b/special-pages/pages/new-tab/src/js/mock-transport.js @@ -80,38 +80,38 @@ export function mockTransport() { /** @type {import('../../../../types/new-tab.js').NewTabMessages['notifications']} */ const msg = /** @type {any} */ (_msg) switch (msg.method) { - case 'widgets_setConfig': { - if (!msg.params) throw new Error('unreachable') - write('widget_config', msg.params) - broadcast('widget_config') - return - } - case 'stats_setConfig': { - if (!msg.params) throw new Error('unreachable') - - const { animation, ...rest } = msg.params - write('stats_config', rest) - broadcast('stats_config') - return - } - case 'rmf_primaryAction': { - console.log('ignoring rmf_primaryAction', msg.params) - clearRmf() - return - } - case 'rmf_secondaryAction': { - console.log('ignoring rmf_secondaryAction', msg.params) - clearRmf() - return - } - case 'rmf_dismiss': { - console.log('ignoring rmf_dismiss', msg.params) - clearRmf() - return - } - default: { - console.warn('unhandled notification', msg) - } + case 'widgets_setConfig': { + if (!msg.params) throw new Error('unreachable') + write('widget_config', msg.params) + broadcast('widget_config') + return + } + case 'stats_setConfig': { + if (!msg.params) throw new Error('unreachable') + + const { animation, ...rest } = msg.params + write('stats_config', rest) + broadcast('stats_config') + return + } + case 'rmf_primaryAction': { + console.log('ignoring rmf_primaryAction', msg.params) + clearRmf() + return + } + case 'rmf_secondaryAction': { + console.log('ignoring rmf_secondaryAction', msg.params) + clearRmf() + return + } + case 'rmf_dismiss': { + console.log('ignoring rmf_dismiss', msg.params) + clearRmf() + return + } + default: { + console.warn('unhandled notification', msg) + } } }, subscribe(_msg, cb) { diff --git a/special-pages/types/new-tab.ts b/special-pages/types/new-tab.ts index 2935ea0cd..a545d92df 100644 --- a/special-pages/types/new-tab.ts +++ b/special-pages/types/new-tab.ts @@ -33,36 +33,36 @@ export type RMFIcon = 'Announce' | 'DDGAnnounce' | 'CriticalUpdate' | 'AppUpdate * Requests, Notifications and Subscriptions from the NewTab feature */ export interface NewTabMessages { - notifications: - | ContextMenuNotification - | FavoritesAddNotification - | FavoritesMoveNotification - | FavoritesOpenNotification - | FavoritesOpenContextMenuNotification - | FavoritesSetConfigNotification - | ReportInitExceptionNotification - | ReportPageExceptionNotification - | RmfDismissNotification - | RmfPrimaryActionNotification - | RmfSecondaryActionNotification - | StatsSetConfigNotification - | UpdateNotificationDismissNotification - | WidgetsSetConfigNotification; - requests: - | FavoritesGetConfigRequest - | FavoritesGetDataRequest - | InitialSetupRequest - | RmfGetDataRequest - | StatsGetConfigRequest - | StatsGetDataRequest; - subscriptions: - | FavoritesOnConfigUpdateSubscription - | FavoritesOnDataUpdateSubscription - | RmfOnDataUpdateSubscription - | StatsOnConfigUpdateSubscription - | StatsOnDataUpdateSubscription - | UpdateNotificationOnDataUpdateSubscription - | WidgetsOnConfigUpdatedSubscription; + notifications: + | ContextMenuNotification + | FavoritesAddNotification + | FavoritesMoveNotification + | FavoritesOpenNotification + | FavoritesOpenContextMenuNotification + | FavoritesSetConfigNotification + | ReportInitExceptionNotification + | ReportPageExceptionNotification + | RmfDismissNotification + | RmfPrimaryActionNotification + | RmfSecondaryActionNotification + | StatsSetConfigNotification + | UpdateNotificationDismissNotification + | WidgetsSetConfigNotification + requests: + | FavoritesGetConfigRequest + | FavoritesGetDataRequest + | InitialSetupRequest + | RmfGetDataRequest + | StatsGetConfigRequest + | StatsGetDataRequest + subscriptions: + | FavoritesOnConfigUpdateSubscription + | FavoritesOnDataUpdateSubscription + | RmfOnDataUpdateSubscription + | StatsOnConfigUpdateSubscription + | StatsOnDataUpdateSubscription + | UpdateNotificationOnDataUpdateSubscription + | WidgetsOnConfigUpdatedSubscription } /** * Generated from @see "../messages/new-tab/contextMenu.notify.json" @@ -85,77 +85,77 @@ export interface VisibilityMenuItem { * Generated from @see "../messages/new-tab/favorites_add.notify.json" */ export interface FavoritesAddNotification { - method: "favorites_add"; + method: 'favorites_add' } /** * Generated from @see "../messages/new-tab/favorites_move.notify.json" */ export interface FavoritesMoveNotification { - method: "favorites_move"; - params: FavoritesMoveAction; + method: 'favorites_move' + params: FavoritesMoveAction } export interface FavoritesMoveAction { - /** - * Entity ID - */ - id: string; - /** - * zero-indexed target - */ - targetIndex: number; + /** + * Entity ID + */ + id: string + /** + * zero-indexed target + */ + targetIndex: number } /** * Generated from @see "../messages/new-tab/favorites_open.notify.json" */ export interface FavoritesOpenNotification { - method: "favorites_open"; - params: FavoritesOpenAction; + method: 'favorites_open' + params: FavoritesOpenAction } export interface FavoritesOpenAction { - /** - * Entity ID - */ - id: string; - target: "same-tab" | "new-tab" | "new-window"; + /** + * Entity ID + */ + id: string + target: 'same-tab' | 'new-tab' | 'new-window' } /** * Generated from @see "../messages/new-tab/favorites_openContextMenu.notify.json" */ export interface FavoritesOpenContextMenuNotification { - method: "favorites_openContextMenu"; - params: FavoritesOpenContextMenuAction; + method: 'favorites_openContextMenu' + params: FavoritesOpenContextMenuAction } export interface FavoritesOpenContextMenuAction { - /** - * Entity ID - */ - id: string; + /** + * Entity ID + */ + id: string } /** * Generated from @see "../messages/new-tab/favorites_setConfig.notify.json" */ export interface FavoritesSetConfigNotification { - method: "favorites_setConfig"; - params: FavoritesConfig; + method: 'favorites_setConfig' + params: FavoritesConfig } export interface FavoritesConfig { - expansion: Expansion; - animation?: Animation; + expansion: Expansion + animation?: Animation } export interface None { - kind: "none"; + kind: 'none' } /** * Use CSS view transitions where available */ export interface ViewTransitions { - kind: "view-transitions"; + kind: 'view-transitions' } /** * Use the auto-animate library to provide default animation styles */ export interface Auto { - kind: "auto-animate"; + kind: 'auto-animate' } /** * Generated from @see "../messages/new-tab/reportInitException.notify.json" @@ -242,28 +242,28 @@ export interface WidgetConfigItem { * Generated from @see "../messages/new-tab/favorites_getConfig.request.json" */ export interface FavoritesGetConfigRequest { - method: "favorites_getConfig"; - result: FavoritesConfig; + method: 'favorites_getConfig' + result: FavoritesConfig } /** * Generated from @see "../messages/new-tab/favorites_getData.request.json" */ export interface FavoritesGetDataRequest { - method: "favorites_getData"; - result: FavoritesData; + method: 'favorites_getData' + result: FavoritesData } export interface FavoritesData { - favorites: Favorite[]; + favorites: Favorite[] } export interface Favorite { - url: string; - id: string; - title: string; - favicon: null | FavoriteFavicon; + url: string + id: string + title: string + favicon: null | FavoriteFavicon } export interface FavoriteFavicon { - src: string; - maxAvailableSize: number; + src: string + maxAvailableSize: number } /** * Generated from @see "../messages/new-tab/initialSetup.request.json" @@ -367,15 +367,15 @@ export interface TrackerCompany { * Generated from @see "../messages/new-tab/favorites_onConfigUpdate.subscribe.json" */ export interface FavoritesOnConfigUpdateSubscription { - subscriptionEvent: "favorites_onConfigUpdate"; - params: FavoritesConfig; + subscriptionEvent: 'favorites_onConfigUpdate' + params: FavoritesConfig } /** * Generated from @see "../messages/new-tab/favorites_onDataUpdate.subscribe.json" */ export interface FavoritesOnDataUpdateSubscription { - subscriptionEvent: "favorites_onDataUpdate"; - params: FavoritesData; + subscriptionEvent: 'favorites_onDataUpdate' + params: FavoritesData } /** * Generated from @see "../messages/new-tab/rmf_onDataUpdate.subscribe.json" diff --git a/typedoc.js b/typedoc.js index 32af97616..7bd649137 100644 --- a/typedoc.js +++ b/typedoc.js @@ -37,7 +37,7 @@ const config = { treatWarningsAsErrors: true, searchInComments: true, modifierTags: [...OptionDefaults.modifierTags, '@implements'], - highlightLanguages: [...OptionDefaults.highlightLanguages, 'mermaid'] + highlightLanguages: [...OptionDefaults.highlightLanguages, 'mermaid'], } export default config