@salla.sa/twilight 2.0.217 → 2.0.218

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.
Files changed (40) hide show
  1. package/dist/@salla.sa/twilight.min.js +2 -2
  2. package/dist/@salla.sa/twilight.min.js.map +1 -1
  3. package/dist/cjs/main.js +2 -2
  4. package/dist/cjs/main.js.map +1 -1
  5. package/dist/esm/main.js +2 -2
  6. package/dist/esm/main.js.map +1 -1
  7. package/package.json +1 -1
  8. package/types/api/cart.d.ts +4 -6
  9. package/types/api/comment.d.ts +12 -0
  10. package/types/api/currency.d.ts +17 -0
  11. package/types/api/document.d.ts +3 -0
  12. package/types/api/feedback.d.ts +56 -0
  13. package/types/api/gift.js +70 -0
  14. package/types/api/loyalty.js +50 -0
  15. package/types/api/offer.d.ts +43 -0
  16. package/types/api/order.js +94 -0
  17. package/types/api/product.d.ts +29 -0
  18. package/types/api/scope.js +54 -0
  19. package/types/api/search.d.ts +22 -0
  20. package/types/api/twilight.js +39 -0
  21. package/types/api/wishlist.d.ts +7 -0
  22. package/types/common.d.ts +40 -4
  23. package/types/event/comment.d.ts +7 -0
  24. package/types/event/currency.d.ts +9 -0
  25. package/types/event/document.d.ts +21 -0
  26. package/types/event/feedback.d.ts +18 -0
  27. package/types/event/gift.js +33 -0
  28. package/types/event/infiniteScroll.d.ts +12 -0
  29. package/types/event/loyalty.js +28 -0
  30. package/types/event/offer.d.ts +9 -0
  31. package/types/event/product.d.ts +9 -0
  32. package/types/event/profile.d.ts +2 -5
  33. package/types/event/scope.js +14 -0
  34. package/types/event/search.d.ts +7 -0
  35. package/types/event/twilight.js +32 -0
  36. package/types/event/wishlist.d.ts +8 -0
  37. package/types/helpers/app-helpers.d.ts +31 -0
  38. package/types/helpers/salla-helpers.d.ts +1 -1
  39. package/types/index.d.ts +49 -29
  40. package/types/infinite-scroll.d.ts +19 -0
@@ -0,0 +1,33 @@
1
+ import baseEvent from './baseEvent';
2
+
3
+ class GiftEvents extends baseEvent {
4
+ constructor(parent) {
5
+ super(parent);
6
+ this.namespace = 'gift';
7
+ /**
8
+ * 💡 Notice that you can override any event by creating method, if we have 'this.events={...,codeSent:code-sent,...}',
9
+ * it can be override by creating method like:
10
+ * codeSent(response){
11
+ * //your costume code
12
+ * ....
13
+ * //then call dispatch to emit other listeners
14
+ * return this.dispatch('codeSent', ...arguments);
15
+ * }
16
+ * 💡 namespace 'gift::' will be added dynamically,
17
+ * so last result will be something like: 'gift::item-added'
18
+ * all events will be initiated to have three functions, for ex: event "buyingSucceeded" wil be:
19
+ * 🔸 name: gift::buying-succeeded
20
+ * 🔸 fire: salla.gift.event.buyingSucceeded(...data)
21
+ * 🔸 listen: salla.gift.event.onBuyingSucceeded((...data) => salla.log(data))
22
+ * 🔸 fireWithName: salla.event.emit('gift::buying-succeeded',...data)
23
+ */
24
+ this.events = {
25
+ buyingSucceeded:'buying.succeeded',
26
+ buyingFailed:'buying.failed',
27
+ }
28
+
29
+ this.after_init();
30
+ }
31
+ }
32
+
33
+ export default GiftEvents
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @see https://infinite-scroll.com/events.html
3
+ */
4
+ export default interface InfiniteScrollEvent {
5
+ onScrollThreshold: (callback: (event: Event) => void) => void;
6
+ onRequest: (callback: (event: Event, path: string, fetchPromise: Promise<any>) => void) => void;
7
+ onLoad: (callback: (event: Event, body: Body, path: string, response: Response) => void) => void;
8
+ onAppend: (callback: (event: Event, body: Body, path: string, items: NodeList, response: Response) => void) => void;
9
+ onError: (callback: (event: Event, error: Error, path: string, response: Response) => void) => void;
10
+ onLast: (callback: (event: Event, body: Body, path: string) => void) => void;
11
+ onHistory: (callback: (event: Event, title: string, path: string) => void) => void;
12
+ }
@@ -0,0 +1,28 @@
1
+ import baseEvent from './baseEvent';
2
+
3
+ class LoyaltyEvents extends baseEvent {
4
+ constructor(parent) {
5
+ super(parent);
6
+ this.namespace = 'loyalty';
7
+ /**
8
+ * 💡 Notice that you can override any event by creating method, if we have 'this.events={...,codeSent:code-sent,...}',
9
+ * it can be override by creating method like:
10
+ * codeSent(response){
11
+ * //your costume code
12
+ * ....
13
+ * //then call dispatch to emit other listeners
14
+ * return this.dispatch('codeSent', ...arguments);
15
+ * }
16
+ * 💡 namespace 'loyalty::' will be added dynamically,
17
+ * so last result will be something like: 'loyalty::item-added'
18
+ */
19
+ this.events = {
20
+ exchangeSucceeded:'exchange.succeeded',
21
+ exchangeFailed:'exchange.failed',
22
+ }
23
+
24
+ this.after_init();
25
+ }
26
+ }
27
+
28
+ export default LoyaltyEvents
@@ -0,0 +1,9 @@
1
+ import {OfferDetailsResponse} from "../api/offer";
2
+ import {RequestErrorEvent} from "../common";
3
+ import {OfferSummary} from "../api/cart";
4
+
5
+ export default interface OfferEvent {
6
+ onExisted: (callback: (offer: OfferSummary) => void) => void;
7
+ ondDetailsFetched: (callback: (response: OfferDetailsResponse) => void) => void;
8
+ onFetchDetailsFailed: RequestErrorEvent;
9
+ }
@@ -0,0 +1,9 @@
1
+ import {GetPriceResponse} from "../api/product";
2
+ import {RequestErrorEventWithData, TwilightResponse} from "../common";
3
+
4
+ export default interface ProductEvent {
5
+ onPriceUpdated: (callback: (response: GetPriceResponse, product_id: number) => void) => void;
6
+ onPriceUpdateFailed: RequestErrorEventWithData</*product_id*/ number>;
7
+ onAvailabilitySubscribed: (callback: (response: TwilightResponse, product_id: number) => void) => void;
8
+ onAvailabilitySubscribeFailed: RequestErrorEventWithData</*product_id*/ number>;
9
+ }
@@ -1,10 +1,7 @@
1
1
  import {UpdateProfileResponse} from "../api/profile";
2
- import {Nullable, RequestError} from "../common";
2
+ import { RequestErrorEvent} from "../common";
3
3
 
4
4
  export default interface ProfileEvent {
5
- updated: (response: UpdateProfileResponse) => void; //fire the event
6
- updateFailed: (RequestError) => void;//fire the event
7
-
8
5
  onUpdated: (callback: (response: UpdateProfileResponse) => void) => void;
9
- onUpdateFailed: (callback: (error: RequestError) => void) => void;
6
+ onUpdateFailed: RequestErrorEvent;
10
7
  }
@@ -0,0 +1,14 @@
1
+ import baseEvent from './baseEvent';
2
+
3
+ class ScopeEvents extends baseEvent {
4
+ constructor(parent) {
5
+ super(parent);
6
+ this.namespace = 'scope';
7
+ this.events = {
8
+ }
9
+
10
+ this.after_init();
11
+ }
12
+ }
13
+
14
+ export default ScopeEvents
@@ -0,0 +1,7 @@
1
+ import {Nullable, RequestErrorEventWithData} from "../common";
2
+ import {SearchResponse} from "../api/search";
3
+
4
+ export default interface SearchEvent {
5
+ onFinished: (callback: (response: SearchResponse, query: Nullable<string>) => void) => void;
6
+ onFailed: RequestErrorEventWithData</*query*/Nullable<string>>;
7
+ }
@@ -0,0 +1,32 @@
1
+ import baseEvent from './baseEvent';
2
+
3
+ class TwilightEvents extends baseEvent {
4
+ constructor(parent) {
5
+ super(parent);
6
+ this.namespace = 'twilight';
7
+ /**
8
+ * 💡 Notice that you can override any event by creating method, if we have 'this.events={...,twilight:initiated,...}',
9
+ * it can be override by creating method like:
10
+ * initiated(reponse){
11
+ * //your costum code
12
+ * ....
13
+ * //then call dispatch to emit other listeners
14
+ * return this.dispatch('initiated', ...arguments);
15
+ * }
16
+ * 💡 namespace "twilight::" will be added dynamically,
17
+ * all events will be initiated to have three functions, for ex: event "initiated" wil be:
18
+ * 🔸 name: twilight::initiated
19
+ * 🔸 fire: salla.twilight.event.initiated(...data)
20
+ * 🔸 listen: salla.twilight.event.onInitiated((...data) => salla.log(data))
21
+ * 🔸 fireWithName: salla.event.emit('twilight::initiated',...data)
22
+ * 🔸 listenWithName: salla.event.on('twilight::initiated',(...data)=>salla.log(data))
23
+ */
24
+ this.events = {
25
+ initiated: "initiated",
26
+ }
27
+
28
+ this.after_init();
29
+ }
30
+ }
31
+
32
+ export default TwilightEvents
@@ -0,0 +1,8 @@
1
+ import {RequestErrorEventWithData, TwilightResponse} from "../common";
2
+
3
+ export default interface WishlistEvent {
4
+ onAdded: (callback: (response: TwilightResponse, product_id: number) => void) => void;
5
+ onRemoved: (callback: (response: TwilightResponse, product_id: number) => void) => void;
6
+ onAdditionFailed: RequestErrorEventWithData</*product_id*/number>;
7
+ onRemovingFailed: RequestErrorEventWithData</*product_id*/number>;
8
+ }
@@ -0,0 +1,31 @@
1
+ import {Nullable} from "../common";
2
+
3
+ type ElementOrSelector = string | HTMLElement;
4
+ type EventTypes = 'click' | 'keyup' | 'input' | 'change' | string;
5
+ export default interface AppHelpers {
6
+ toggleClassIf: (selector: string, classes1: string | Array<string>, classes2: string | Array<string>, callback: (element: HTMLElement) => boolean) => AppHelpers;
7
+ toggleElementClassIf: (element: HTMLElement, classes1: string | Array<string>, classes2: string | Array<string>, callback: (element: HTMLElement) => boolean) => AppHelpers;
8
+
9
+ isValidEmail: (email: string) => boolean;
10
+
11
+ element: (selector: ElementOrSelector) => Nullable<HTMLElement>;
12
+ watchElement: (name: string, selector: ElementOrSelector) => AppHelpers;
13
+ watchElements: (elements: { [key: string]: [value: ElementOrSelector] }) => AppHelpers;
14
+ hideElement: (element: ElementOrSelector) => AppHelpers;
15
+ showElement: (element: ElementOrSelector) => AppHelpers;
16
+ //💡 you can pass one or multi classes: this.removeClass(element, 'class_1', 'class_2', ...)
17
+ removeClass: (element: ElementOrSelector, ...className: string[]) => AppHelpers;
18
+ addClass: (element: ElementOrSelector, ...className: string[]) => AppHelpers;
19
+ //💡instead of: `document.querySelectorAll('.test').forEach(element=>{...})`
20
+ // you can use: `this.all('.test', element=>{...})`
21
+ all: (element: ElementOrSelector, callback: (element: HTMLElement) => void) => AppHelpers;
22
+
23
+ //💡instead of: `document.querySelectorAll('.test').forEach(el => el.addEventListener('keyup', callback));`
24
+ // you can use: `this.on('.test', 'keyup', callback)`
25
+ // or can use: `this.onKeyUp('.test', callback)`
26
+ on: (eventType: EventTypes, element: ElementOrSelector, callback: EventListener, options?: AddEventListenerOptions) => AppHelpers;
27
+ onClick: (element: ElementOrSelector, callback: EventListener) => AppHelpers;
28
+ onKeyUp: (element: ElementOrSelector, callback: EventListener) => AppHelpers;
29
+ onEnter: (element: ElementOrSelector, callback: EventListener) => AppHelpers;
30
+ debounce: (callback: () => unknown) => (...data: Nullable<any>) => Promise<unknown>
31
+ }
@@ -4,7 +4,7 @@ export interface SallaHelpers {
4
4
  //Numbers helpers
5
5
  digitsOnly: (num: string | number) => number,
6
6
  inputDigitsOnly: (input: string | HTMLInputElement) => number,
7
- number: () => number,
7
+ number: (num: number) => number | string,
8
8
  money: (num: number | Price) => string,
9
9
 
10
10
  //Nested objects helpers
package/types/index.d.ts CHANGED
@@ -12,6 +12,25 @@ import OrderApi from "./api/order";
12
12
  import OrderEvent from "./event/order";
13
13
  import ProfileApi from "./api/profile";
14
14
  import ProfileEvent from "./event/profile";
15
+ import AppHelpers from "./helpers/app-helpers";
16
+ import CommentApi from "./api/comment";
17
+ import CommentEvent from "./event/comment";
18
+ import CurrencyApi from "./api/currency";
19
+ import CurrencyEvent from "./event/currency";
20
+ import DocumentApi from "./api/document";
21
+ import DocumentEvent from "./event/document";
22
+ import FeedbackEvent from "./event/feedback";
23
+ import FeedbackApi from "./api/feedback";
24
+ import OfferApi from "./api/offer";
25
+ import OfferEvent from "./event/offer";
26
+ import WishlistApi from "./api/wishlist";
27
+ import WishlistEvent from "./event/wishlist";
28
+ import SearchApi from "./api/search";
29
+ import SearchEvent from "./event/search";
30
+ import ProductEvent from "./event/product";
31
+ import ProductApi from "./api/product";
32
+ import InfiniteScrollEvent from "./event/infiniteScroll";
33
+ import InfiniteScroll from "./infinite-scroll";
15
34
 
16
35
  export * from "./all";
17
36
 
@@ -22,26 +41,26 @@ export default interface Salla {
22
41
  auth: AuthApi;
23
42
  gift: any;
24
43
  order: OrderApi;
25
- offer: any;
26
- search: any;
44
+ offer: OfferApi;
45
+ search: SearchApi;
27
46
  coupon: CouponApi;
28
- comment: any;
47
+ comment: CommentApi;
29
48
  loyalty: any;
30
- product: any;
49
+ product: ProductApi;
31
50
  profile: ProfileApi;
32
- currency: any;
33
- document: any;
34
- feedback: any;
51
+ currency: CurrencyApi;
52
+ document: DocumentApi;
53
+ feedback: FeedbackApi;
35
54
  twilight: any;
36
- wishlist: any;
55
+ wishlist: WishlistApi;
37
56
  getHeaders: () => {
38
- "Accept": string | 'application/json, text/plain, */*',
57
+ Accept: string | 'application/json, text/plain, */*',
39
58
  "X-Requested-With": 'XMLHttpRequest',
40
59
  "S-SOURCE": 'twilight',
41
60
  "Store-Identifier"?: number,
42
- "currency"?: string | 'SAR',
61
+ currency?: string | 'SAR',
43
62
  "accept-language"?: string | 'ar',
44
- "Authorization"?: string
63
+ Authorization?: string
45
64
  }
46
65
  };
47
66
  event: {
@@ -49,21 +68,21 @@ export default interface Salla {
49
68
  cart: CartEvent,
50
69
  gift: any;
51
70
  order: OrderEvent;
52
- offer: any;
53
- search: any;
71
+ offer: OfferEvent;
72
+ search: SearchEvent;
54
73
  coupon: CouponEvent;
55
- comment: any;
74
+ comment: CommentEvent;
56
75
  loyalty: any;
57
- product: any;
76
+ product: ProductEvent;
58
77
  profile: ProfileEvent;
59
- currency: any;
60
- document: any;
61
- feedback: any;
78
+ currency: CurrencyEvent;
79
+ document: DocumentEvent;
80
+ feedback: FeedbackEvent;
62
81
  twilight: any;
63
- wishlist: any;
82
+ wishlist: WishlistEvent;
83
+ infiniteScroll: InfiniteScrollEvent
64
84
 
65
85
  };
66
- infiniteScroll: any;
67
86
  helpers: SallaHelpers;
68
87
  config: SallaConfig;
69
88
  storage: any;
@@ -74,25 +93,26 @@ export default interface Salla {
74
93
  auth: AuthApi & { api: AuthApi, event: AuthEvent };
75
94
  gift: { api: any, event: any };
76
95
  order: OrderApi & { api: OrderApi, event: OrderEvent };
77
- offer: { api: any, event: any };
78
- search: { api: any, event: any };
96
+ offer: OfferApi & { api: OfferApi, event: OfferEvent };
97
+ search: SearchApi & { api: SearchApi, event: SearchEvent };
79
98
  coupon: CouponApi & { api: CouponApi, event: CouponEvent };
80
- comment: { api: any, event: any };
99
+ comment: CommentApi & { api: CommentApi, event: CommentEvent };
81
100
  loyalty: { api: any, event: any };
82
- product: { api: any, event: any };
101
+ product: ProductApi & { api: ProductApi, event: ProductEvent };
83
102
  profile: ProfileApi & { api: ProfileApi, event: ProfileEvent };
84
- currency: { api: any, event: any };
85
- document: { api: any, event: any };
86
- feedback: { api: any, event: any };
103
+ currency: CurrencyApi & { api: CurrencyApi, event: CurrencyEvent };
104
+ document: DocumentApi & { api: DocumentApi, event: DocumentEvent };
105
+ feedback: FeedbackApi & { api: FeedbackApi, event: FeedbackEvent };
87
106
  twilight: { api: any, event: any };
88
- wishlist: { api: any, event: any };
107
+ wishlist: WishlistApi & { api: WishlistApi, event: WishlistEvent };
108
+ infiniteScroll: InfiniteScroll & { api: null, event: InfiniteScrollEvent };
89
109
 
90
110
  log: (message: string | any) => void;
91
111
  success: (message: string) => void;
92
112
  error: (message: string) => void;
93
113
  lang: any;
94
114
  onReady: any; //don't relay on it because Salla may not existed yet
95
- AppHelpers: any;
115
+ AppHelpers: AppHelpers;
96
116
  money: (money: number | Price) => string;
97
117
  }
98
118
 
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @see https://infinite-scroll.com/options.html
3
+ */
4
+ export interface InfiniteScrollOptions {
5
+ path: '.infinite-scroll-btn' | string;
6
+ history: 'push' | false;
7
+ status: ".infinite-scroll-status" | string;
8
+ append: ".list-block" | string;
9
+ button: ".infinite-scroll-btn" | string;
10
+ next_page: string;
11
+ }
12
+
13
+ /**
14
+ * @see https://infinite-scroll.com/api.html
15
+ */
16
+ export default interface InfiniteScroll {
17
+ //💡 when there is no need to pass options, but there is need to change append selector, just pass it as string as second argument
18
+ initiate: (selector: string | HTMLElement, append?: string | InfiniteScrollOptions, customOptions?: InfiniteScrollOptions) => Object;
19
+ }