@salla.sa/twilight 2.0.254 → 2.0.256

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salla.sa/twilight",
3
- "version": "2.0.254",
3
+ "version": "2.0.256",
4
4
  "description": "Salla Theme Toolkit, Webcomponents, Events, Requests, Utils",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -47,7 +47,7 @@ export interface CartSummary {
47
47
  id: number;
48
48
  user_id: number | string;
49
49
  store_id: number;
50
- real_shipping_cost: number;
50
+ real_shipping_cost?: number;
51
51
  free_shipping_bar?: {
52
52
  minimum_amount: number;
53
53
  has_free_shipping: boolean;
@@ -1,4 +1,4 @@
1
- import { RequestError} from "../common";
1
+ import {RequestError} from "../common";
2
2
 
3
3
  export interface requestPayload {
4
4
  namespace: string | 'cart';
@@ -10,6 +10,7 @@ export interface requestPayload {
10
10
  headers?: {};
11
11
  }
12
12
 
13
+
13
14
  export default interface DocumentEvent {
14
15
  onClick: (selector: string | ((event) => void), callback?: (event) => void) => void;
15
16
  onChange: (selector: string | ((event) => void), callback?: (event) => void) => void;
@@ -18,4 +19,11 @@ export default interface DocumentEvent {
18
19
  onLeaving: (event: BeforeUnloadEvent) => boolean; //return false to show alert 'Changes you made may not be saved.'
19
20
  onRequest: (payload: requestPayload) => void; //💡handy when there is need to prevent request by throwing an error `throw 'stop the request';`.
20
21
  onRequestFailed: (payload: requestPayload, error?: RequestError) => void;
22
+ /**
23
+ * Helper method to fake firing event on element, for
24
+ * @example someInput.addEventListener("change",()=>{...});
25
+ * we want to fire this event programmatically, we can do that by:
26
+ * @example salla.document.event.fireEvent(someInput, 'change', {'bubbles': true})
27
+ */
28
+ fireEvent: (element: HTMLElement, eventName: 'click' | 'change' | string, payload: undefined | Object) => void;
21
29
  }
@@ -16,6 +16,98 @@ import WishlistEvent from "./wishlist";
16
16
  import InfiniteScrollEvent from "./infiniteScroll";
17
17
  import {EventEmitter2} from "eventemitter2";
18
18
 
19
+ export type event = (symbol | string);
20
+ export type EventName = string
21
+ | 'auth::login'
22
+ | 'auth::logout'
23
+ | 'auth::code.sent'
24
+ | 'auth::code.not-sent'
25
+ | 'auth::code.re-sent'
26
+ | 'auth::code.not.re-sent'
27
+ | 'auth::verified'
28
+ | 'auth::verification.failed'
29
+ | 'auth::logged.in'
30
+ | 'auth::registered'
31
+ | 'auth::registration.failed'
32
+ | 'auth::logged.out'
33
+ | 'auth::failed.logout'
34
+ | 'auth::token.fetched'
35
+ | 'auth::refresh.failed'
36
+ | 'cart::latest.fetched'
37
+ | 'cart::latest.failed'
38
+ | 'cart::updated'
39
+ | 'cart::item.updated'
40
+ | 'cart::item.updated.failed'
41
+ | 'cart::item.added'
42
+ | 'cart::item.added.failed'
43
+ | 'cart::item.deleted'
44
+ | 'cart::item.deleted.failed'
45
+ | 'cart::submitted'
46
+ | 'cart::submit.failed'
47
+ | 'cart::image.deleted'
48
+ | 'cart::image.not.deleted'
49
+ | 'cart::details.fetched'
50
+ | 'cart::details.not.fetched'
51
+ | 'cart::success.reset'
52
+ | 'cart::coupon.added'
53
+ | 'cart::coupon.deleted'
54
+ | 'cart::coupon.addition.failed'
55
+ | 'cart::coupon.deletion.failed'
56
+ | 'gift::buying.succeeded'
57
+ | 'gift::buying.failed'
58
+ | 'loyalty::exchange.succeeded'
59
+ | 'loyalty::exchange.failed'
60
+ | 'order::canceled'
61
+ | 'order::not.canceled'
62
+ | 'order::re.ordered'
63
+ | 'order::re.order.failed'
64
+ | 'order::invoice.sent'
65
+ | 'order::invoice.not.sent'
66
+ | 'offer::existed'
67
+ | 'offer::increase'
68
+ | 'offer::increase.failed'
69
+ | 'offer::fetch.details.failed'
70
+ | 'offer::details.fetched'
71
+ | 'rating::order.not.fetched'
72
+ | 'rating::order.fetched'
73
+ | 'rating::store.rated'
74
+ | 'rating::store.failed'
75
+ | 'rating::products.rated'
76
+ | 'rating::products.failed'
77
+ | 'rating::shipping.rated'
78
+ | 'rating::shipping.failed'
79
+ | 'search::finished'
80
+ | 'search::failed'
81
+ | 'product::price.updated'
82
+ | 'product::price.updated.failed'
83
+ | 'product::availability.subscribed'
84
+ | 'product::availability.subscribe.failed'
85
+ | 'profile::updated'
86
+ | 'profile::update.failed'
87
+ | 'profile::mobile.updated'
88
+ | 'profile::update.mobile.failed'
89
+ | 'profile::email.updated'
90
+ | 'profile::update.email.failed'
91
+ | 'profile::verified'
92
+ | 'profile::unverified'
93
+ | 'comment::added'
94
+ | 'comment::addition.failed'
95
+ | 'currency::changed'
96
+ | 'currency::failed'
97
+ | 'currency::fetched'
98
+ | 'currency::failed.to.fetch'
99
+ | 'document::click'
100
+ | 'document::change'
101
+ | 'document::submit'
102
+ | 'document::keyup'
103
+ | 'document::leaving'
104
+ | 'document::request'
105
+ | 'document::request.failed'
106
+ | 'twilight::initiated'
107
+ | 'wishlist::added'
108
+ | 'wishlist::removed'
109
+ | 'wishlist::addition.failed'
110
+ | 'wishlist::removing.failed';
19
111
  export {
20
112
  AuthEvent,
21
113
  CartEvent,
@@ -53,5 +145,9 @@ export default interface SallaEvent extends EventEmitter2 {
53
145
  wishlist: WishlistEvent;
54
146
  infiniteScroll: InfiniteScrollEvent;
55
147
  dispatchEvents: (events: { [event_name: string]: any }) => void;
56
- dispatch: (event_name: string, ...data: undefined | any) => void;
148
+ dispatch: (event_name: EventName, ...data: undefined | any) => void;
149
+
150
+ on(event: EventName, listener: (...values: any[]) => void, options?: boolean | Object): this;
151
+
152
+ once(event: EventName, listener: (...values: any[]) => void, options?: boolean | Object): this;
57
153
  }
package/types/index.d.ts CHANGED
@@ -31,7 +31,7 @@ export default interface Salla extends SallaActions {
31
31
  form: SallaForm;
32
32
  money: (money: number | Price) => string;
33
33
  url: UrlHelper;
34
-
34
+ isInitiated: boolean; // will be true when firing event `twilight::initiated`
35
35
  onReady: (callback: (event: Event) => unknown) => void; //don't relay on it because Salla may not existed yet
36
36
  init: (config: SallaConfig) => void; // an alias for `salla.twilight.init(config)`
37
37
  call: (action: ApiActionName | string) => any;
@@ -1,5 +1,5 @@
1
1
  import {Language, TwilightConfig} from "../tiwlight-config";
2
- import {Currency, Nullable, Price} from "../common";
2
+ import {Currency, Price} from "../common";
3
3
 
4
4
  export type ConfigKey =
5
5
  '_token'
@@ -44,7 +44,7 @@ export default interface SallaConfig {
44
44
  isUser: () => boolean;
45
45
  isGuest: () => boolean;
46
46
  languageCode: () => string | 'ar';
47
- currency: (code: Nullable<string | 'SAR'>) => Currency;
47
+ currency: (code?: string | 'SAR') => Currency;
48
48
  currencies: () => Promise<{ SAR: Currency, [code: string]: Currency }>;
49
49
  languages: () => Promise<{ ar: Language, [code: string]: Language }>;
50
50
  }