From 4b129c4f2f581d6fa9b9ff7a96a4969f92838f86 Mon Sep 17 00:00:00 2001 From: Jeri Peier Date: Wed, 20 Nov 2024 13:14:18 +0100 Subject: [PATCH] fix: cleanup deprecated core functionality (#3219) BREAKING CHANGE: Several deprecated core functionality has been removed. - dom.js `getDocumentWritingMode()` removed - dom.js `getLocalName()` removed - eventing.js `formElementHandlerAspect()` removed - eventing.js `HandlerRepository`, `HandlerAspectParams` and `HandlerAspect` removed - mixins.js `SbbFocusableDisabledActionMixin` removed - observers.js completely removed (containing `NodeIntersectionObserver`, `AgnosticIntersectionObserver`, `NodeMutationObserver`, `AgnosticMutationObserver`, `NodeResizeObserver` and `AgnosticResizeObserver`) --- src/elements/core/dom.ts | 2 - .../core/dom/get-document-writing-mode.ts | 7 --- src/elements/core/dom/ssr.ts | 29 ------------ src/elements/core/eventing.ts | 1 - .../core/eventing/form-element-handlers.ts | 11 ----- .../core/eventing/handler-repository.ts | 45 ------------------- src/elements/core/mixins/disabled-mixin.ts | 30 ------------- src/elements/core/observers.ts | 3 -- .../core/observers/intersection-observer.ts | 31 ------------- .../core/observers/mutation-observer.ts | 23 ---------- .../core/observers/resize-observer.ts | 23 ---------- 11 files changed, 205 deletions(-) delete mode 100644 src/elements/core/dom/get-document-writing-mode.ts delete mode 100644 src/elements/core/dom/ssr.ts delete mode 100644 src/elements/core/eventing/handler-repository.ts delete mode 100644 src/elements/core/observers.ts delete mode 100644 src/elements/core/observers/intersection-observer.ts delete mode 100644 src/elements/core/observers/mutation-observer.ts delete mode 100644 src/elements/core/observers/resize-observer.ts diff --git a/src/elements/core/dom.ts b/src/elements/core/dom.ts index 5920d373a4..52975d08b3 100644 --- a/src/elements/core/dom.ts +++ b/src/elements/core/dom.ts @@ -1,9 +1,7 @@ export * from './dom/breakpoint.js'; export * from './dom/find-referenced-element.js'; -export * from './dom/get-document-writing-mode.js'; export * from './dom/host-context.js'; export * from './dom/input-element.js'; export * from './dom/set-or-remove-attribute.js'; export * from './dom/platform.js'; export * from './dom/scroll.js'; -export * from './dom/ssr.js'; diff --git a/src/elements/core/dom/get-document-writing-mode.ts b/src/elements/core/dom/get-document-writing-mode.ts deleted file mode 100644 index 32e04634aa..0000000000 --- a/src/elements/core/dom/get-document-writing-mode.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { isServer } from 'lit'; - -/** - * @deprecated use :dir() selector instead - */ -export const getDocumentWritingMode = (): string => - (!isServer && document.documentElement.getAttribute('dir')) || 'ltr'; diff --git a/src/elements/core/dom/ssr.ts b/src/elements/core/dom/ssr.ts deleted file mode 100644 index b7aa96e9e3..0000000000 --- a/src/elements/core/dom/ssr.ts +++ /dev/null @@ -1,29 +0,0 @@ -import type { LitElement } from 'lit'; - -const localNameCache = new Map(); - -/** - * In SSR the local/tag name is not available on the class instance, but it is available - * in the shim customElements registry. - * - * https://github.com/lit/lit/blob/main/packages/labs/ssr-dom-shim/src.ts (See CustomElementRegistryShim) - * - * Can be removed once https://github.com/lit/lit/pull/4553 is merged/released. - * - * @deprecated Will be removed with next major version - */ -export function getLocalName(element: LitElement): string { - if (localNameCache.has(element.constructor)) { - return localNameCache.get(element.constructor)!; - } - - const definitions = // eslint-disable-next-line @typescript-eslint/naming-convention - (customElements as unknown as { __definitions: Map }).__definitions; - for (const [key, value] of definitions) { - if (value.ctor === element.constructor) { - localNameCache.set(element.constructor, key); - return key; - } - } - throw new Error(`Given element ${element.constructor.name} has not been registered yet.`); -} diff --git a/src/elements/core/eventing.ts b/src/elements/core/eventing.ts index 3afa9c472a..cff041920a 100644 --- a/src/elements/core/eventing.ts +++ b/src/elements/core/eventing.ts @@ -3,6 +3,5 @@ export * from './eventing/event-emitter.js'; export * from './eventing/event-target.js'; export * from './eventing/form-element-handlers.js'; export * from './eventing/forward-event.js'; -export * from './eventing/handler-repository.js'; export * from './eventing/is-event-prevented.js'; export * from './eventing/throttle.js'; diff --git a/src/elements/core/eventing/form-element-handlers.ts b/src/elements/core/eventing/form-element-handlers.ts index 20545463c8..b3a5c85f2c 100644 --- a/src/elements/core/eventing/form-element-handlers.ts +++ b/src/elements/core/eventing/form-element-handlers.ts @@ -1,5 +1,3 @@ -import type { HandlerAspect } from './handler-repository.js'; - /** * Prevents scrolling from pressing Space * @param event The origin event. @@ -9,12 +7,3 @@ export function preventScrollOnSpacebarPress(event: KeyboardEvent): void { event.preventDefault(); } } - -/** - * Handler to prevent scrolling on space bar click. - * - * @deprecated TODO: remove once radio button became form element - */ -export const formElementHandlerAspect: HandlerAspect = ({ host, signal }) => { - host.addEventListener('keydown', preventScrollOnSpacebarPress, { signal }); -}; diff --git a/src/elements/core/eventing/handler-repository.ts b/src/elements/core/eventing/handler-repository.ts deleted file mode 100644 index 05a5ea5a5e..0000000000 --- a/src/elements/core/eventing/handler-repository.ts +++ /dev/null @@ -1,45 +0,0 @@ -/** - * @deprecated - * TODO: remove once radio button became form element - */ -export interface HandlerAspectParams { - host: HTMLElement; - signal: AbortSignal; -} - -/** - * @deprecated - * TODO: remove once radio button became form element - */ -export interface HandlerAspect { - (params: HandlerAspectParams): void; -} - -/** - * @deprecated - * TODO: remove once radio button became form element - */ -export class HandlerRepository { - private _aspects: HandlerAspect[]; - private _controller?: AbortController; - - public constructor( - private readonly _host: HTMLElement, - ...aspects: HandlerAspect[] - ) { - this._aspects = aspects; - } - - public connect(): void { - this._controller?.abort(); - this._controller = new AbortController(); - const params: HandlerAspectParams = { host: this._host, signal: this._controller.signal }; - for (const aspect of this._aspects) { - aspect(params); - } - } - - public disconnect(): void { - this._controller?.abort(); - } -} diff --git a/src/elements/core/mixins/disabled-mixin.ts b/src/elements/core/mixins/disabled-mixin.ts index e6803edb63..045fe5c492 100644 --- a/src/elements/core/mixins/disabled-mixin.ts +++ b/src/elements/core/mixins/disabled-mixin.ts @@ -97,33 +97,3 @@ export const SbbDisabledTabIndexActionMixin = < > & T; }; - -/** - * Extends `SbbDisabledMixin` with the `aria-disabled` attribute. - * For a11y purposes, keeps the element focusable even when disabled. - * @deprecated Will be removed with next major version - */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export const SbbFocusableDisabledActionMixin = >( - superClass: T, -): AbstractConstructor & T => { - abstract class SbbFocusableDisabledAction - extends SbbDisabledMixin(superClass) - implements SbbDisabledMixinType - { - protected override willUpdate(changedProperties: PropertyValues): void { - super.willUpdate(changedProperties); - - if (!changedProperties.has('disabled')) { - return; - } - - if (this.disabled) { - this.setAttribute('aria-disabled', 'true'); - } else { - this.removeAttribute('aria-disabled'); - } - } - } - return SbbFocusableDisabledAction as AbstractConstructor & T; -}; diff --git a/src/elements/core/observers.ts b/src/elements/core/observers.ts deleted file mode 100644 index 1c1b0d8ee2..0000000000 --- a/src/elements/core/observers.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './observers/intersection-observer.js'; -export * from './observers/mutation-observer.js'; -export * from './observers/resize-observer.js'; diff --git a/src/elements/core/observers/intersection-observer.ts b/src/elements/core/observers/intersection-observer.ts deleted file mode 100644 index 8494fb700d..0000000000 --- a/src/elements/core/observers/intersection-observer.ts +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @deprecated use lit observers, will be removed with next major version - */ -export class NodeIntersectionObserver implements IntersectionObserver { - public root!: Element | Document | null; - public rootMargin!: string; - public thresholds!: number[]; - - public disconnect(): void { - // noop - } - - public observe(): void { - // noop - } - - public takeRecords(): any { - // noop - } - - public unobserve(): void { - // noop - } -} - -/** - * @deprecated use lit observers, will be removed with next major version - */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export const AgnosticIntersectionObserver = - typeof IntersectionObserver === 'undefined' ? NodeIntersectionObserver : IntersectionObserver; diff --git a/src/elements/core/observers/mutation-observer.ts b/src/elements/core/observers/mutation-observer.ts deleted file mode 100644 index e09862fd42..0000000000 --- a/src/elements/core/observers/mutation-observer.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * @deprecated use lit observers, will be removed with next major version - */ -export class NodeMutationObserver implements MutationObserver { - public disconnect(): void { - // Noop - } - - public observe(_target: Node, _options?: MutationObserverInit): void { - // Noop - } - - public takeRecords(): MutationRecord[] { - return []; - } -} - -/** - * @deprecated use lit observers, will be removed with next major version - */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export const AgnosticMutationObserver: typeof MutationObserver = - typeof MutationObserver === 'undefined' ? NodeMutationObserver : MutationObserver; diff --git a/src/elements/core/observers/resize-observer.ts b/src/elements/core/observers/resize-observer.ts deleted file mode 100644 index c11f4ba04e..0000000000 --- a/src/elements/core/observers/resize-observer.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * @deprecated use lit observers, will be removed with next major version - */ -export class NodeResizeObserver implements ResizeObserver { - public disconnect(): any { - // noop - } - - public observe(): any { - // noop - } - - public unobserve(): any { - // noop - } -} - -/** - * @deprecated use lit observers, will be removed with next major version - */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export const AgnosticResizeObserver = - typeof ResizeObserver === 'undefined' ? NodeResizeObserver : ResizeObserver;