@shopware-ag/storefront-types 0.1.0

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.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Types for Shopware Storefront
2
+
3
+ This package provides types for window bound classes in Shopware 6 Storefront:
4
+
5
+ - `window.PluginManager`
6
+ - `window.PluginBaseClass`
7
+ - `window.router`
8
+
9
+ Install this package with NPM:
10
+
11
+ ```bash
12
+ npm install @shopware-ag/storefront-types --save-dev
13
+ ```
14
+
15
+ To hav the types active, you need to create a `tsconfig.json` (`src/Resources/app/storefront/tsconfig.json`) with following content:
16
+
17
+ ```json
18
+ {
19
+ "compilerOptions": {
20
+ "types": ["@shopware-ag/storefront-types"]
21
+ }
22
+ }
23
+ ```
package/bun.lockb ADDED
Binary file
@@ -0,0 +1,8 @@
1
+ interface DateHelper {
2
+ format(val: string|Date, options: Intl.DateTimeFormatOptions): string
3
+ }
4
+
5
+ declare module 'src/helper/date.helper' {
6
+ const helper: DateHelper;
7
+ export = helper;
8
+ }
@@ -0,0 +1,8 @@
1
+ interface DebouncerHelper {
2
+ debounce(callback: Function, delay: number, immediate: boolean): Function
3
+ }
4
+
5
+ declare module 'src/helper/debouncer.helper' {
6
+ const helper: DebouncerHelper;
7
+ export = helper;
8
+ }
@@ -0,0 +1,23 @@
1
+ interface DeviceDetectionHelper {
2
+ isTouchDevice(): boolean
3
+ isIOSDevice(): boolean
4
+ isNativeWindowsBrowser(): boolean
5
+ isIPhoneDevice(): boolean
6
+ isIPadDevice(): boolean
7
+ isIEBrowser(): boolean
8
+ isEdgeBrowser(): boolean
9
+ getList(): {
10
+ 'is-touch': boolean,
11
+ 'is-ios': boolean,
12
+ 'is-native-windows': boolean,
13
+ 'is-iphone': boolean,
14
+ 'is-ipad': boolean,
15
+ 'is-ie': boolean,
16
+ 'is-edge': boolean
17
+ }
18
+ }
19
+
20
+ declare module 'src/helper/device-detection.helper' {
21
+ const helper: DeviceDetectionHelper;
22
+ export = helper;
23
+ }
@@ -0,0 +1,36 @@
1
+ interface DomAccessHelper {
2
+ /**
3
+ * Returns whether or not the element is an HTML node
4
+ */
5
+ isNode(element: any): boolean
6
+
7
+ /**
8
+ * Returns if the given element has the requested attribute/property
9
+ */
10
+ hasAttribute(element: HTMLElement, attribute: string): boolean
11
+
12
+ /**
13
+ * Returns the value of a given element's attribute/property
14
+ */
15
+ getAttribute(element: HTMLElement, attribute: string, strict?: boolean): string | undefined
16
+
17
+ /**
18
+ * Returns the value of a given elements dataset entry
19
+ */
20
+ getDataAttribute(element: HTMLElement, attribute: string, strict?: boolean): string | undefined
21
+
22
+ /**
23
+ * Returns the selected element of a defined parent node
24
+ */
25
+ querySelector(element: HTMLElement, selector: string, strict?: boolean): HTMLElement | null
26
+
27
+ /**
28
+ * Returns the selected elements of a defined parent node
29
+ */
30
+ querySelectorAll(element: HTMLElement, selector: string, strict?: boolean): HTMLElement[]
31
+ }
32
+
33
+ declare module 'src/helper/dom-access.helper' {
34
+ const helper: DomAccessHelper;
35
+ export = helper;
36
+ }
@@ -0,0 +1,10 @@
1
+ interface ElementReplaceHelper {
2
+ replaceFromMarkup(markup: HTMLElement|string, selectors: string[]|string, strict: boolean): void
3
+
4
+ replaceElement(src: NodeList|HTMLElement|string, target: NodeList|HTMLElement|string, strict: boolean): boolean
5
+ }
6
+
7
+ declare module 'src/helper/element-replace.helper' {
8
+ const helper: ElementReplaceHelper;
9
+ export = helper;
10
+ }
@@ -0,0 +1,27 @@
1
+ declare module 'src/helper/emitter.helper' {
2
+ interface NativeEventEmitterPublish {
3
+ detail?: object;
4
+ cancelable?: boolean;
5
+ }
6
+
7
+ interface NativeEventEmitterSubscribeOpts {
8
+ once?: boolean;
9
+ scope?: Function;
10
+ }
11
+
12
+ class NativeEventEmitter {
13
+ private _listeners;
14
+ private _el;
15
+ constructor(el: HTMLElement);
16
+ publish(eventName: string, detail?: NativeEventEmitterPublish, cancelable?: boolean): CustomEvent;
17
+ subscribe(eventName: string, callback: Function, opts?: NativeEventEmitterSubscribeOpts): boolean;
18
+ unsubscribe(eventName: String): boolean;
19
+ reset(): boolean;
20
+ get el(): HTMLElement;
21
+ set el(value: HTMLElement);
22
+ get listeners(): any[];
23
+ set listeners(value: any[]);
24
+ }
25
+
26
+ export = NativeEventEmitter;
27
+ }
@@ -0,0 +1,9 @@
1
+ interface FeatureHelper {
2
+ init(flagConfig: object): void;
3
+ isActive(flag: string): boolean;
4
+ }
5
+
6
+ declare module 'src/helper/feature.helper' {
7
+ const helper: FeatureHelper;
8
+ export = helper;
9
+ }
@@ -0,0 +1,8 @@
1
+ interface IteratorHelper {
2
+ iterate(source: any, callback: (value: any, index: number, array: any) => void): void
3
+ }
4
+
5
+ declare module 'src/helper/iterator.helper' {
6
+ const helper: IteratorHelper;
7
+ export = helper;
8
+ }
@@ -0,0 +1,38 @@
1
+ interface CookieStorageHelper {
2
+ setItem(key: string, value: string, expireationDays: number): void
3
+
4
+ getItem(key: string): any
5
+
6
+ removeItem(key: string): boolean
7
+
8
+ key(index: number): string | null
9
+
10
+ clear(): void
11
+ }
12
+
13
+ interface MemoryStorageHelper {
14
+ setItem(key: string, value: string): void
15
+
16
+ getItem(key: string): any
17
+
18
+ removeItem(key: string): boolean
19
+
20
+ key(index: number): string | null
21
+
22
+ clear(): void
23
+ }
24
+
25
+ declare module 'src/helper/storage/storage.helper' {
26
+ const helper: Storage;
27
+ export = helper;
28
+ }
29
+
30
+ declare module 'src/helper/storage/cookie-storage.helper' {
31
+ const helper: CookieStorageHelper;
32
+ export = helper;
33
+ }
34
+
35
+ declare module 'src/helper/storage/memory-storage.helper' {
36
+ const helper: MemoryStorageHelper;
37
+ export = helper;
38
+ }
@@ -0,0 +1,34 @@
1
+ interface StringHelper {
2
+ /**
3
+ * Upper case first letter of string
4
+ */
5
+ ucFirst(str: string): string
6
+
7
+ /**
8
+ * Lower case first letter of string
9
+ */
10
+ lcFirst(str: string): string
11
+
12
+ /**
13
+ * Convert string to dash case
14
+ */
15
+ toDashCase(str: string): string
16
+
17
+ /**
18
+ * Convert string to low camel case
19
+ */
20
+ toLowerCamelCase(str: string): string
21
+
22
+
23
+ /**
24
+ * Convert string to upper camel case
25
+ */
26
+ toUpperCamelCase(str: string): string
27
+
28
+ parsePrimitive(value: string): any
29
+ }
30
+
31
+ declare module 'src/helper/string.helper' {
32
+ const helper: StringHelper;
33
+ export = helper;
34
+ }
@@ -0,0 +1,14 @@
1
+ interface ViewportDetectionHelper {
2
+ isXS(): boolean
3
+ isSM(): boolean
4
+ isMD(): boolean
5
+ isLG(): boolean
6
+ isXL(): boolean
7
+ isXXL(): boolean
8
+ getCurrentViewport(): 'XS' | 'SM' | 'MD' | 'LG' | 'XL' | 'XXL'
9
+ }
10
+
11
+ declare module 'src/helper/viewport-detection.helper' {
12
+ const helper: ViewportDetectionHelper;
13
+ export = helper;
14
+ }
@@ -0,0 +1,24 @@
1
+ /// <reference path="plugin-system/plugin.class.d.ts" />
2
+ /// <reference path="plugin-system/plugin.manager.d.ts" />
3
+
4
+ /// <reference path="helper/date.helper.d.ts" />
5
+ /// <reference path="helper/debouncer.helper.d.ts" />
6
+ /// <reference path="helper/device-detection.helper.d.ts" />
7
+ /// <reference path="helper/dom-access.helper.d.ts" />
8
+ /// <reference path="helper/element-replace.helper.d.ts" />
9
+ /// <reference path="helper/emitter.helper.d.ts" />
10
+ /// <reference path="helper/feature.helper.d.ts" />
11
+ /// <reference path="helper/iterator.helper.d.ts" />
12
+ /// <reference path="helper/storage.helper.d.ts" />
13
+ /// <reference path="helper/string.helper.d.ts" />
14
+ /// <reference path="helper/viewport-detection.helper.d.ts" />
15
+
16
+ /// <reference path="service/http-client.service.d.ts" />
17
+ /// <reference path="service/app-client.service.d.ts" />
18
+
19
+ /// <reference path="utility/backdrop.util.d.ts" />
20
+ /// <reference path="utility/bootstrap.util.d.ts" />
21
+ /// <reference path="utility/form-serialize.util.d.ts" />
22
+ /// <reference path="utility/history.util.d.ts" />
23
+ /// <reference path="utility/loading-indicator.d.ts" />
24
+ /// <reference path="utility/pseudo-modal.d.ts" />
@@ -0,0 +1,4 @@
1
+ declare module 'src/plugin-system/plugin.class' {
2
+ const Plugin: import('../../plugin-system/plugin').default;
3
+ export = Plugin;
4
+ }
@@ -0,0 +1,4 @@
1
+ declare module 'src/plugin-system/plugin.manager' {
2
+ const PluginManager: import('../../plugin-system/plugin-manager').default;
3
+ export = PluginManager;
4
+ }
@@ -0,0 +1,13 @@
1
+ declare module 'src/service/app-client.service' {
2
+ class AppClient {
3
+ constructor();
4
+
5
+ get(url: RequestInfo, options?: RequestInit): Promise<Response>;
6
+ post(url: RequestInfo, options?: RequestInit): Promise<Response>;
7
+ patch(url: RequestInfo, options?: RequestInit): Promise<Response>;
8
+ delete(url: RequestInfo, options?: RequestInit): Promise<Response>;
9
+ reset(): void;
10
+ }
11
+
12
+ export = AppClient;
13
+ }
@@ -0,0 +1,17 @@
1
+ declare module 'src/service/http-client.service' {
2
+ class HttpClient {
3
+ constructor();
4
+
5
+ get(url: string, callback: (content: any, response: XMLHttpRequest) => void, contentType?: string): void;
6
+ post(url: string, data: object|null, callback: (content: any, response: XMLHttpRequest) => void, contentType?: string): void;
7
+ patch(url: string, data: object|null, callback: (content: any, response: XMLHttpRequest) => void, contentType?: string): void;
8
+ delete(url: string, data: object|null, callback: (content: any, response: XMLHttpRequest) => void, contentType?: string): void;
9
+
10
+ /**
11
+ * Abort running Request
12
+ */
13
+ abort(): void;
14
+ }
15
+
16
+ export = HttpClient;
17
+ }
@@ -0,0 +1,11 @@
1
+ interface BackDropUtil {
2
+ SELECTOR_CLASS: string
3
+
4
+ create(callback: Function|null): void
5
+ remove(delay: number): void
6
+ }
7
+
8
+ declare module 'src/utility/backdrop/backdrop.util' {
9
+ const helper: BackDropUtil;
10
+ export = helper;
11
+ }
@@ -0,0 +1,10 @@
1
+ interface BootstrapUtil {
2
+ initTooltip(): bootstrap.Tooltip
3
+ initPopover(): bootstrap.Popover
4
+ initBootstrapPlugins(): void
5
+ }
6
+
7
+ declare module 'src/utility/bootstrap/bootstrap.util' {
8
+ const helper: BootstrapUtil;
9
+ export = helper;
10
+ }
@@ -0,0 +1,9 @@
1
+ interface FormSerializeUtil {
2
+ serialize(form: HTMLFormElement, strict?: boolean): FormData
3
+ serializeJson(form: HTMLFormElement, strict?: boolean): object
4
+ }
5
+
6
+ declare module 'src/utility/form/form-serialize.util' {
7
+ const helper: FormSerializeUtil;
8
+ export = helper;
9
+ }
@@ -0,0 +1,15 @@
1
+ interface HistoryUtil {
2
+ getLocation(): string
3
+ listen(callback: Function): any
4
+ unlisten(callback: Function): void
5
+ push(pathName: string, search: any, state: any): void
6
+ replace(pathName: string, search: any, state: any): void
7
+ pushParams(params: any, state: any): void
8
+ replaceParams(params: any, state: any): void
9
+ getSearch(): string
10
+ }
11
+
12
+ declare module 'src/utility/history/history.util' {
13
+ const helper: HistoryUtil;
14
+ export = helper;
15
+ }
@@ -0,0 +1,32 @@
1
+ interface LoadingIndicatorUtil {
2
+ SELECTOR_CLASS: string
3
+
4
+ create(): void
5
+ remove(): void
6
+ exists(): boolean
7
+ getTemplate(): string
8
+ }
9
+
10
+ interface ElementLoadingIndicatorUtil extends LoadingIndicatorUtil {
11
+ appendLoader(element: HTMLElement): void
12
+ }
13
+
14
+ declare module 'src/utility/loading-indicator/loading-indicator.util' {
15
+ const helper: LoadingIndicatorUtil;
16
+ export = helper;
17
+ }
18
+
19
+ declare module 'src/utility/loading-indicator/button-loading-indicator.util' {
20
+ const helper: LoadingIndicatorUtil;
21
+ export = helper;
22
+ }
23
+
24
+ declare module 'src/utility/loading-indicator/element-indicator.util' {
25
+ const helper: ElementLoadingIndicatorUtil;
26
+ export = helper;
27
+ }
28
+
29
+ declare module 'src/utility/loading-indicator/page-loading-indicator.util' {
30
+ const helper: LoadingIndicatorUtil;
31
+ export = helper;
32
+ }
@@ -0,0 +1,11 @@
1
+ declare module 'src/utility/modal-extension/psuedo-modal.util' {
2
+ class PsuedoModalUtil {
3
+ open(callback: Function): void
4
+ close(): void
5
+ getModal(): HTMLElement
6
+ updatePosition(): void
7
+ updateContent(content: string, callback: () => void): void
8
+ }
9
+
10
+ export = PsuedoModalUtil;
11
+ }
package/global.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ declare global {
2
+ interface Window {
3
+ PluginManager: import('./plugin-system/plugin-manager').default,
4
+ PluginBaseClass: import('./plugin-system/plugin').default,
5
+ router: {
6
+ 'frontend.cart.offcanvas': string,
7
+ 'frontend.cookie.offcanvas': string,
8
+ 'frontend.checkout.finish.page': string,
9
+ 'frontend.checkout.info': string,
10
+ 'frontend.menu.offcanvas': string,
11
+ 'frontend.cms.page': string,
12
+ 'frontend.cms.navigation.page': string,
13
+ 'frontend.account.addressbook': string,
14
+ 'frontend.country.country-data': string,
15
+ 'frontend.app-system.generate-token': string,
16
+ }
17
+ bootstrap: typeof import('bootstrap')
18
+ }
19
+
20
+ interface Document {
21
+ $emitter: import('./plugin-system/native-event-emitter').default,
22
+ }
23
+ }
24
+
25
+ export {}
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ /// <reference path="declare/index.d.ts" />
2
+ /// <reference path="global.d.ts" />
package/module.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ declare module 'src/plugin-system/plugin.manager' {
2
+ const PluginManager: import('./plugin-system/plugin-manager').default;
3
+ export = PluginManager;
4
+ }
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@shopware-ag/storefront-types",
3
+ "version": "0.1.0",
4
+ "description": "Provides Shopware Storefront Typescript types",
5
+ "types": "index.d.ts",
6
+ "dependencies": {
7
+ "@types/bootstrap": "^5.2.0"
8
+ },
9
+ "devDependencies": {
10
+ "typescript": "*"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/shopware/storefront-types.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/shopware/storefront-types/issues"
18
+ },
19
+ "author": "shopware AG",
20
+ "license": "MIT"
21
+ }
@@ -0,0 +1,18 @@
1
+ interface NativeEventEmitterSubscribeOpts {
2
+ once?: boolean;
3
+ scope?: Function;
4
+ }
5
+
6
+ export default class NativeEventEmitter {
7
+ private _listeners;
8
+ private _el;
9
+ constructor(el: HTMLElement);
10
+ publish(eventName: string, detail?: object, cancelable?: boolean): CustomEvent;
11
+ subscribe(eventName: string, callback: Function, opts?: NativeEventEmitterSubscribeOpts): boolean;
12
+ unsubscribe(eventName: String): boolean;
13
+ reset(): boolean;
14
+ get el(): HTMLElement;
15
+ set el(value: HTMLElement);
16
+ get listeners(): any[];
17
+ set listeners(value: any[]);
18
+ }
@@ -0,0 +1,55 @@
1
+ export default interface PluginManager {
2
+ /**
3
+ * Registers a plugin to the plugin manager.
4
+ */
5
+ register(pluginName: String, pluginClass: Object, selector: String | NodeList | HTMLElement, options?: Object): void
6
+
7
+ /**
8
+ * Removes a plugin from the plugin manager
9
+ */
10
+ deregister(pluginName: String): void
11
+
12
+ /**
13
+ * Extends an already existing plugin with a new class or function.
14
+ * If both names are equal, the plugin will be overridden.
15
+ */
16
+ extend(fromName: String, newName: string, pluginClass: Object, selector: String | NodeList | HTMLElement, options?: Object): boolean
17
+
18
+ /**
19
+ * Returns a list of all registered plugins.
20
+ */
21
+ getPluginList(): string[]
22
+
23
+ /**
24
+ * Returns the definition of a plugin.
25
+ */
26
+ getPlugin(pluginName: String, strict: boolean): Map<String, String>
27
+
28
+ /**
29
+ * Returns all registered plugin instances for the passed plugin name.
30
+ */
31
+ getPluginInstances(pluginName: String): Array<Object>
32
+
33
+
34
+ /**
35
+ * Returns the plugin instance from the passed element selected by plugin Name.
36
+ */
37
+ getPluginInstanceFromElement(el: HTMLElement, pluginName: String): Array<Object>
38
+
39
+
40
+ /**
41
+ * Returns all plugin instances from the passed element.
42
+ */
43
+ getPluginInstancesFromElement(el: HTMLElement): Map<String, Object>
44
+
45
+
46
+ /**
47
+ * Initializes all plugins which are currently registered.
48
+ */
49
+ initializePlugins(): void
50
+
51
+ /**
52
+ * Initializes a single plugin.
53
+ */
54
+ initializePlugin(pluginName: String, selector: String|NodeList|HTMLElement, options: object): void;
55
+ }
@@ -0,0 +1,19 @@
1
+ import NativeEventEmitter from "./native-event-emitter";
2
+
3
+ export default interface PluginBaseClass {
4
+ new(el: HTMLElement, options?: any, pluginName?: false | string): PluginBaseClass;
5
+
6
+ el: HTMLElement;
7
+ $emitter: NativeEventEmitter;
8
+ _pluginName: String;
9
+ initialOptions: object;
10
+ options: object;
11
+ _initialized: boolean;
12
+ init(): void;
13
+ _update(): void;
14
+ update(): void;
15
+ _registerInstance(): void;
16
+ _getPluginName(pluginName: false | string): String;
17
+ _mergeOptions(options: any): object;
18
+ parseJsonOrFail(dashedPluginName: string): any | string;
19
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "lib": [
5
+ "es6",
6
+ "DOM"
7
+ ],
8
+ "noImplicitAny": true,
9
+ "noImplicitThis": true,
10
+ "strictNullChecks": true,
11
+ "strictFunctionTypes": true,
12
+ "types": ["."],
13
+ "noEmit": true,
14
+ "forceConsistentCasingInFileNames": true
15
+ },
16
+ "files": [
17
+ "index.d.ts"
18
+ ]
19
+ }