@shopware-ag/storefront-types 0.2.0 → 0.2.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.
@@ -27,7 +27,8 @@ interface DomAccessHelper {
27
27
  /**
28
28
  * Returns the selected elements of a defined parent node
29
29
  */
30
- querySelectorAll(element: HTMLElement, selector: string, strict?: boolean): HTMLElement[]
30
+ querySelectorAll(element: HTMLElement, selector: string, strict: true): NodeList
31
+ querySelectorAll(element: HTMLElement, selector: string, strict?: false): NodeList | false
31
32
  }
32
33
 
33
34
  declare module 'src/helper/dom-access.helper' {
@@ -3,22 +3,22 @@ declare module 'src/helper/emitter.helper' {
3
3
  detail?: object;
4
4
  cancelable?: boolean;
5
5
  }
6
-
6
+
7
7
  interface NativeEventEmitterSubscribeOpts {
8
8
  once?: boolean;
9
9
  scope?: Function;
10
10
  }
11
-
12
- class NativeEventEmitter {
11
+
12
+ class NativeEventEmitter<El extends HTMLElement = HTMLElement> {
13
13
  private _listeners;
14
14
  private _el;
15
- constructor(el: HTMLElement);
15
+ constructor(el: El);
16
16
  publish(eventName: string, detail?: NativeEventEmitterPublish, cancelable?: boolean): CustomEvent;
17
17
  subscribe(eventName: string, callback: Function, opts?: NativeEventEmitterSubscribeOpts): boolean;
18
18
  unsubscribe(eventName: String): boolean;
19
19
  reset(): boolean;
20
- get el(): HTMLElement;
21
- set el(value: HTMLElement);
20
+ get el(): El;
21
+ set el(value: El);
22
22
  get listeners(): any[];
23
23
  set listeners(value: any[]);
24
24
  }
@@ -1,5 +1,5 @@
1
1
  interface CookieStorageHelper {
2
- setItem(key: string, value: string, expireationDays: number): void
2
+ setItem(key: string, value: string, expirationDays: number): void
3
3
 
4
4
  getItem(key: string): any
5
5
 
@@ -1,5 +1,5 @@
1
- declare module 'src/utility/modal-extension/psuedo-modal.util' {
2
- class PsuedoModalUtil {
1
+ declare module 'src/utility/modal-extension/pseudo-modal.util' {
2
+ class PseudoModalUtil {
3
3
  open(callback: Function): void
4
4
  close(): void
5
5
  getModal(): HTMLElement
@@ -7,5 +7,5 @@ declare module 'src/utility/modal-extension/psuedo-modal.util' {
7
7
  updateContent(content: string, callback: () => void): void
8
8
  }
9
9
 
10
- export = PsuedoModalUtil;
10
+ export = PseudoModalUtil;
11
11
  }
package/global.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  declare global {
2
2
  interface Window {
3
3
  PluginManager: import('./plugin-system/plugin-manager').default,
4
- PluginBaseClass: import('./plugin-system/plugin').default,
4
+ PluginBaseClass: typeof import('./plugin-system/plugin').default,
5
5
  router: {
6
6
  'frontend.cart.offcanvas': string,
7
7
  'frontend.cookie.offcanvas': string,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware-ag/storefront-types",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Provides Shopware Storefront Typescript types",
5
5
  "types": "index.d.ts",
6
6
  "scripts": {
@@ -3,16 +3,16 @@ interface NativeEventEmitterSubscribeOpts {
3
3
  scope?: Function;
4
4
  }
5
5
 
6
- export default class NativeEventEmitter {
6
+ export default class NativeEventEmitter<El extends HTMLElement = HTMLElement> {
7
7
  private _listeners;
8
8
  private _el;
9
- constructor(el: HTMLElement);
9
+ constructor(el: El);
10
10
  publish(eventName: string, detail?: object, cancelable?: boolean): CustomEvent;
11
11
  subscribe(eventName: string, callback: Function, opts?: NativeEventEmitterSubscribeOpts): boolean;
12
12
  unsubscribe(eventName: String): boolean;
13
13
  reset(): boolean;
14
- get el(): HTMLElement;
15
- set el(value: HTMLElement);
14
+ get el(): El;
15
+ set el(value: El);
16
16
  get listeners(): any[];
17
17
  set listeners(value: any[]);
18
18
  }
@@ -1,10 +1,10 @@
1
1
  import NativeEventEmitter from "./native-event-emitter";
2
2
 
3
- export default interface PluginBaseClass<Options extends object = Record<string, unknown>> {
4
- new(el: HTMLElement, options?: Partial<Options>, pluginName?: false | string): PluginBaseClass<Options>;
3
+ export default class PluginBaseClass<Options extends object = Record<string, unknown>, El extends HTMLElement = HTMLElement> {
4
+ constructor(el: El, options?: Partial<Options>, pluginName?: false | string);
5
5
 
6
- el: HTMLElement;
7
- $emitter: NativeEventEmitter;
6
+ el: El;
7
+ $emitter: NativeEventEmitter<El>;
8
8
  _pluginName: String;
9
9
  initialOptions: Options;
10
10
  options: Options;
@@ -0,0 +1,38 @@
1
+ // Test case for using window.PluginBaseClass as shown in the issue
2
+ /// <reference path="../global.d.ts" />
3
+
4
+ const { PluginBaseClass } = window;
5
+
6
+ interface MyPluginOptions {
7
+ option1: string;
8
+ option2: number | null;
9
+ }
10
+
11
+ class MyPlugin extends PluginBaseClass<MyPluginOptions> {
12
+ static options: MyPluginOptions = {
13
+ option1: 'default value',
14
+ option2: null,
15
+ };
16
+
17
+ init(): void {
18
+ // Test that instance properties are accessible
19
+ console.log(this.el);
20
+ console.log(this.options);
21
+ console.log(this.$emitter);
22
+
23
+ // Test that options are properly typed
24
+ const opt1: string = this.options.option1;
25
+ const opt2: number | null = this.options.option2;
26
+ }
27
+ }
28
+
29
+ // Test: Can instantiate using the class from window
30
+ const element = document.createElement('div');
31
+ const plugin = new MyPlugin(element, { option1: 'custom' });
32
+
33
+ // Test: Instance properties should be typed correctly
34
+ const opt1: string = plugin.options.option1;
35
+ const opt2: number | null = plugin.options.option2;
36
+
37
+ // @ts-expect-error - Should error when accessing non-existent property
38
+ plugin.options.nonExistent;
@@ -0,0 +1,39 @@
1
+ // Test case for extending PluginBaseClass as shown in the issue
2
+ import PluginBaseClass from '../plugin-system/plugin';
3
+
4
+ interface MyPluginOptions {
5
+ option1: string;
6
+ option2: number | null;
7
+ }
8
+
9
+ class MyPlugin extends PluginBaseClass<MyPluginOptions> {
10
+ static options: MyPluginOptions = {
11
+ option1: 'default value',
12
+ option2: null,
13
+ };
14
+
15
+ init(): void {
16
+ // Test that instance properties are accessible
17
+ console.log(this.el);
18
+ console.log(this.options);
19
+ console.log(this.$emitter);
20
+
21
+ // Test that options are properly typed
22
+ const opt1: string = this.options.option1;
23
+ const opt2: number | null = this.options.option2;
24
+ }
25
+ }
26
+
27
+ // Test: Should be able to instantiate via constructor
28
+ const element = document.createElement('div');
29
+ const plugin = new MyPlugin(element, { option1: 'test' });
30
+
31
+ // Test: Instance properties should be accessible
32
+ const el: HTMLElement = plugin.el;
33
+ const opt1: string = plugin.options.option1;
34
+
35
+ // @ts-expect-error - Should error when accessing non-existent property
36
+ plugin.options.nonExistent;
37
+
38
+ // @ts-expect-error - Should error when assigning wrong type
39
+ const wrongType: number = plugin.options.option1;
@@ -31,7 +31,7 @@ const defaultOpt: unknown = defaultPlugin.options['anyKey'];
31
31
  const defaultInitOpt: unknown = defaultPlugin.initialOptions['anyKey'];
32
32
 
33
33
  // Test: Constructor options parameter should accept Partial<Options>
34
- declare const PluginClass: PluginBaseClass<MyPluginOptions>;
34
+ declare const PluginClass: new (el: HTMLElement, options?: Partial<MyPluginOptions>, pluginName?: false | string) => PluginBaseClass<MyPluginOptions>;
35
35
  declare const element: HTMLElement;
36
36
  const instance = new PluginClass(element, { option1: 'partial' });
37
37
  const instanceNoOpts = new PluginClass(element);