@salla.sa/twilight 1.0.19 → 1.6.13

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 (115) hide show
  1. package/LICENSE.md +674 -0
  2. package/README.md +214 -4
  3. package/dist/@salla.sa/twilight.min.js +20 -0
  4. package/dist/@salla.sa/twilight.min.js.map +1 -0
  5. package/dist/cjs/index.js +2 -0
  6. package/dist/cjs/index.js.map +1 -0
  7. package/dist/esm/index.js +2 -0
  8. package/dist/esm/index.js.map +1 -0
  9. package/package.json +64 -53
  10. package/types/actions.d.ts +47 -0
  11. package/types/api/auth/index.d.ts +17 -0
  12. package/types/api/auth/request.d.ts +42 -0
  13. package/types/api/auth/response.d.ts +22 -0
  14. package/types/api/cart/index.d.ts +24 -0
  15. package/types/api/cart/request.d.ts +8 -0
  16. package/types/api/cart/response.d.ts +66 -0
  17. package/types/api/comment.d.ts +18 -0
  18. package/types/api/currency.d.ts +17 -0
  19. package/types/api/document.d.ts +3 -0
  20. package/types/api/index.d.ts +110 -0
  21. package/types/api/loyalty.d.ts +226 -0
  22. package/types/api/order.d.ts +15 -0
  23. package/types/api/product/index.d.ts +17 -0
  24. package/types/api/product/request.d.ts +53 -0
  25. package/types/api/product/response.d.ts +103 -0
  26. package/types/api/profile.d.ts +50 -0
  27. package/types/api/rating.d.ts +49 -0
  28. package/types/api/scope.d.ts +42 -0
  29. package/types/api/wishlist.d.ts +7 -0
  30. package/types/common.d.ts +75 -0
  31. package/types/event/auth.d.ts +18 -0
  32. package/types/event/cart.d.ts +30 -0
  33. package/types/event/comment.d.ts +7 -0
  34. package/types/event/currency.d.ts +9 -0
  35. package/types/event/document.d.ts +29 -0
  36. package/types/event/index.d.ts +48 -0
  37. package/types/event/infiniteScroll.d.ts +12 -0
  38. package/types/event/loyalty.d.ts +14 -0
  39. package/types/event/order.d.ts +11 -0
  40. package/types/event/product.d.ts +30 -0
  41. package/types/event/profile.d.ts +13 -0
  42. package/types/event/rating.d.ts +13 -0
  43. package/types/event/scope.d.ts +15 -0
  44. package/types/event/wishlist.d.ts +8 -0
  45. package/types/helpers/app-helpers.d.ts +29 -0
  46. package/types/index.d.ts +36 -0
  47. package/types/lib/config.ts +14 -0
  48. package/types/lib/form.d.ts +8 -0
  49. package/types/lib/lang.d.ts +14 -0
  50. package/types/lib/notify.d.ts +14 -0
  51. package/types/tiwlight-config.d.ts +74 -0
  52. package/watcher.js +62 -20
  53. package/components/README.md +0 -55
  54. package/components/dist/cjs/index-9441fd8e.js +0 -1554
  55. package/components/dist/cjs/index.cjs.js +0 -2
  56. package/components/dist/cjs/loader.cjs.js +0 -21
  57. package/components/dist/cjs/salla-login_2.cjs.entry.js +0 -131
  58. package/components/dist/cjs/twilight-components.cjs.js +0 -19
  59. package/components/dist/collection/collection-manifest.json +0 -13
  60. package/components/dist/collection/components/generate-summary.js +0 -35
  61. package/components/dist/collection/components/salla-login/salla-login.css +0 -104
  62. package/components/dist/collection/components/salla-login/salla-login.js +0 -113
  63. package/components/dist/collection/components/search-modal/search-modal.css +0 -9
  64. package/components/dist/collection/components/search-modal/search-modal.js +0 -161
  65. package/components/dist/collection/index.js +0 -1
  66. package/components/dist/collection/interfaces/colors.js +0 -1
  67. package/components/dist/collection/interfaces/index.js +0 -2
  68. package/components/dist/collection/interfaces/ratio.js +0 -1
  69. package/components/dist/collection/plugins/tailwind-theme/index.js +0 -32
  70. package/components/dist/collection/plugins/tailwind-theme/scripts/generator.js +0 -51
  71. package/components/dist/collection/utils/utils.js +0 -16
  72. package/components/dist/esm/index-63e5409f.js +0 -1527
  73. package/components/dist/esm/index.js +0 -1
  74. package/components/dist/esm/loader.js +0 -17
  75. package/components/dist/esm/polyfills/core-js.js +0 -11
  76. package/components/dist/esm/polyfills/css-shim.js +0 -1
  77. package/components/dist/esm/polyfills/dom.js +0 -79
  78. package/components/dist/esm/polyfills/es5-html-element.js +0 -1
  79. package/components/dist/esm/polyfills/index.js +0 -34
  80. package/components/dist/esm/polyfills/system.js +0 -6
  81. package/components/dist/esm/salla-login_2.entry.js +0 -126
  82. package/components/dist/esm/twilight-components.js +0 -17
  83. package/components/dist/index.cjs.js +0 -1
  84. package/components/dist/index.js +0 -1
  85. package/components/dist/twilight-components/index.esm.js +0 -0
  86. package/components/dist/twilight-components/p-3d53781c.js +0 -1
  87. package/components/dist/twilight-components/p-fccb89fa.entry.js +0 -1
  88. package/components/dist/twilight-components/twilight-components.esm.js +0 -1
  89. package/components/dist/types/components/salla-login/salla-login.d.ts +0 -14
  90. package/components/dist/types/components/search-modal/search-modal.d.ts +0 -26
  91. package/components/dist/types/components.d.ts +0 -76
  92. package/components/dist/types/index.d.ts +0 -6
  93. package/components/dist/types/interfaces/colors.d.ts +0 -1
  94. package/components/dist/types/interfaces/index.d.ts +0 -2
  95. package/components/dist/types/interfaces/ratio.d.ts +0 -1
  96. package/components/dist/types/stencil-public-runtime.d.ts +0 -1563
  97. package/components/dist/types/utils/utils.d.ts +0 -6
  98. package/components/loader/cdn.js +0 -3
  99. package/components/loader/index.cjs.js +0 -3
  100. package/components/loader/index.d.ts +0 -13
  101. package/components/loader/index.es2017.js +0 -3
  102. package/components/loader/index.js +0 -4
  103. package/components/loader/package.json +0 -10
  104. package/components/package.json +0 -70
  105. package/components/src/plugins/tailwind-theme/index.js +0 -32
  106. package/components/src/plugins/tailwind-theme/package.json +0 -27
  107. package/components/src/plugins/tailwind-theme/readme.md +0 -47
  108. package/components/src/plugins/tailwind-theme/safe-list-css.txt +0 -19
  109. package/components/src/plugins/tailwind-theme/utilities.json +0 -1
  110. package/components.js +0 -1
  111. package/dist/twilight.js +0 -2
  112. package/dist/twilight.js.LICENSE.txt +0 -27
  113. package/postInstall.js +0 -2
  114. package/tailwind.js +0 -1
  115. package/tailwind_css_list.js +0 -1
@@ -0,0 +1,7 @@
1
+ import {RequestErrorEventWithData} from "../common";
2
+ import {AddCommentResponse} from "../api/comment";
3
+
4
+ export default interface CommentEvent {
5
+ onAdded: (callback: (response: AddCommentResponse) => void, /*product/page id*/ id:number) => void;
6
+ onAdditionFailed: RequestErrorEventWithData</*product/page id*/number>;
7
+ }
@@ -0,0 +1,9 @@
1
+ import {ChangeCurrencyResponse, ListCurrenciesResponse} from "../api/currency";
2
+ import {RequestErrorEvent} from "../common";
3
+
4
+ export default interface CurrencyEvent {
5
+ onChanged: (callback: (response: ChangeCurrencyResponse, currency: 'SAR' | string) => void) => void;
6
+ onFetched: (callback: (response: ListCurrenciesResponse) => void) => void;
7
+ onFailed: RequestErrorEvent;
8
+ onFailedToFetch: RequestErrorEvent;
9
+ }
@@ -0,0 +1,29 @@
1
+ import {RequestError} from "../common";
2
+
3
+ export interface requestPayload {
4
+ namespace: string | 'cart';
5
+ action: string | 'latest';
6
+ hook: string | 'latest';
7
+ url: string | 'cart/latest';
8
+ payload: {} | { params: {} };
9
+ method: 'get' | 'post' | 'put' | 'delete';
10
+ headers?: {};
11
+ }
12
+
13
+
14
+ export default interface DocumentEvent {
15
+ onClick: (selector: string | ((event) => void), callback?: (event) => void) => void;
16
+ onChange: (selector: string | ((event) => void), callback?: (event) => void) => void;
17
+ onSubmit: (selector: string | ((event) => void), callback?: (event) => void) => void;
18
+ onKeyup: (selector: string | ((event) => void), callback?: (event) => void) => void;
19
+ onLeaving: (event: BeforeUnloadEvent) => boolean; //return false to show alert 'Changes you made may not be saved.'
20
+ onRequest: (payload: requestPayload) => void; //💡handy when there is need to prevent request by throwing an error `throw 'stop the request';`.
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;
29
+ }
@@ -0,0 +1,48 @@
1
+ import AuthEvent from "./auth";
2
+ import CartEvent from "./cart";
3
+ import OrderEvent from "./order";
4
+ import RatingEvent from "./rating";
5
+ import CommentEvent from "./comment";
6
+ import LoyaltyEvent from "./loyalty";
7
+ import ProductEvent from "./product";
8
+ import ProfileEvent from "./profile";
9
+ import CurrencyEvent from "./currency";
10
+ import DocumentEvent from "./document";
11
+ import WishlistEvent from "./wishlist";
12
+ import InfiniteScrollEvent from "./infiniteScroll";
13
+ import ScopeEvents from "./scope";
14
+ import Emitter from "@salla.sa/base/types/event";
15
+
16
+ export type event = (symbol | string);
17
+
18
+ export {
19
+ AuthEvent,
20
+ CartEvent,
21
+ OrderEvent,
22
+ RatingEvent,
23
+ CommentEvent,
24
+ LoyaltyEvent,
25
+ ProductEvent,
26
+ ProfileEvent,
27
+ CurrencyEvent,
28
+ DocumentEvent,
29
+ WishlistEvent,
30
+ InfiniteScrollEvent,
31
+ ScopeEvents,
32
+ }
33
+
34
+ export default interface TwilightEmitter extends Emitter {
35
+ auth: AuthEvent;
36
+ cart: CartEvent;
37
+ order: OrderEvent;
38
+ rating: RatingEvent;
39
+ comment: CommentEvent;
40
+ loyalty: LoyaltyEvent;
41
+ product: ProductEvent;
42
+ profile: ProfileEvent;
43
+ currency: CurrencyEvent;
44
+ document: DocumentEvent;
45
+ wishlist: WishlistEvent;
46
+ scope: ScopeEvents,
47
+ infiniteScroll: InfiniteScrollEvent;
48
+ }
@@ -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,14 @@
1
+ import { RequestErrorEvent, SuccessResponse } from "../common";
2
+ import { LoyaltyApiResponse } from '../api/loyalty'
3
+
4
+ export default interface LoyaltyEvent {
5
+
6
+ onProgramFetched: (callback: (response: LoyaltyApiResponse.program, prod_id: number) => void) => void;
7
+ onProgramNotFetched: RequestErrorEvent;
8
+ // Point
9
+ onExchangeFetched: (callback: (response: LoyaltyApiResponse.point, prod_id: number) => void) => void;
10
+ onExchangeFetchFailed: RequestErrorEvent;
11
+ // Reset Exchange
12
+ onResetSucceeded: (callback: (response: SuccessResponse) => void) => void;
13
+ onResetFailed: RequestErrorEvent
14
+ }
@@ -0,0 +1,11 @@
1
+ import {RequestError, SuccessResponse} from "../common";
2
+ import {CreateCartFromOrderResponse} from "../api/order";
3
+
4
+ export default interface OrderEvent {
5
+ onCanceled: (callback: (response: SuccessResponse, order_id?: number) => void) => void;
6
+ onNotCanceled: (callback: (error: RequestError, order_id?: number) => void) => void;
7
+ onOrderCreated: (callback: (response: CreateCartFromOrderResponse, order_id?: number) => void) => void;
8
+ onOrderCreationFailed: (callback: (error: RequestError, order_id?: number) => void) => void;
9
+ onInvoiceSent: (callback: (response: SuccessResponse, order_id?: number) => void) => void;
10
+ onInvoiceNotSent: (callback: (error: RequestError | 'There is no id!', order_id?: number) => void) => void;
11
+ }
@@ -0,0 +1,30 @@
1
+ import { OfferSummary } from "../api/cart";
2
+ import { ProductResponse } from "../api/product";
3
+ import { RequestError, RequestErrorEvent, RequestErrorEventWithData, SuccessResponse } from "../common";
4
+
5
+ export default interface ProductEvent {
6
+ onPriceUpdated: (callback: (response: ProductResponse.getPrice, product_id: number) => void) => void;
7
+ onPriceUpdateFailed: RequestErrorEventWithData</*product_id*/ number>;
8
+ onAvailabilitySubscribed: (callback: (response: SuccessResponse, product_id: number) => void) => void;
9
+ onAvailabilitySubscribeFailed: RequestErrorEventWithData</*product_id*/ number>;
10
+ onCategoriesFetched: (callback: (response: ProductResponse.categories) => void) => void;
11
+ onCategoriesFailed: RequestError;
12
+ onSearchResults: (callback: (response: ProductResponse.search, query?: string) => void) => void;
13
+ onSearchFailed: RequestErrorEventWithData</*query*/string | undefined>;
14
+
15
+ onOfferExisted: (callback: (offer: OfferSummary) => void) => void;
16
+ onOffersFetched: (callback: (response: ProductResponse.offers) => void) => void;
17
+ onFetchOffersFailed: RequestErrorEvent;
18
+
19
+ onSizeGuideFetched: (callback: (response: ProductResponse.sizeGuides, prod_id: number) => void) => void;
20
+ onSizeGuideFetchFailed: RequestErrorEvent;
21
+
22
+ onGiftFetched: (callback: (response: ProductResponse.giftResponse, product_id: number) => void) => void;
23
+ onGiftFetchFailed: RequestErrorEvent;
24
+
25
+ onAddGiftToCartSucceeded: (callback: (response: ProductResponse.giftToCart, product_id: number) => void) => void;
26
+ onAddGiftToCartFailed: RequestErrorEvent;
27
+
28
+ onGiftImageUploadSucceeded: (callback: (response: ProductResponse.giftImageUpload) => void) => void;
29
+ onGiftImageUploadFailed: RequestErrorEvent;
30
+ }
@@ -0,0 +1,13 @@
1
+ import {ProfileResponse} from "../api/profile";
2
+ import {RequestErrorEvent, SuccessResponse} from "../common";
3
+
4
+ export default interface ProfileEvent {
5
+ onUpdated: (callback: (response: ProfileResponse) => void) => void;
6
+ onVerified: (callback: (response: SuccessResponse) => void) => void;
7
+ onVerificationCodeSent: (callback: (response: ProfileResponse) => void) => void; //should trigger action to fill verify code, then calling salla.profile.verify(...)
8
+
9
+ //errors
10
+ onUpdateFailed: RequestErrorEvent;
11
+ onUnverified: RequestErrorEvent;
12
+ onUpdateContactsFailed: RequestErrorEvent;
13
+ }
@@ -0,0 +1,13 @@
1
+ import {OrderDetailsResponse, RatingStorePayload, RatingProductsPayload, RatingShippingPayload} from "../api/rating";
2
+ import {RequestErrorEventWithData, SuccessResponse} from "../common";
3
+
4
+ export default interface RatingEvent {
5
+ onOrderFetched: (callback: (response: OrderDetailsResponse, order_id: number) => void) => void;
6
+ onOrderNotFetched: RequestErrorEventWithData</*order_id*/number>;
7
+ onStoreRated: (callback: (response: SuccessResponse, data: RatingStorePayload) => void) => void;
8
+ onStoreFailed: RequestErrorEventWithData</*data*/RatingStorePayload>;
9
+ onProductRated: (callback: (response: SuccessResponse, data: RatingProductsPayload) => void) => void;
10
+ onProductFailed: RequestErrorEventWithData</*data*/RatingProductsPayload>;
11
+ onShippingRated: (callback: (response: SuccessResponse, data: RatingShippingPayload) => void) => void;
12
+ onShippingFailed: RequestErrorEventWithData</*data*/RatingShippingPayload>;
13
+ }
@@ -0,0 +1,15 @@
1
+ import { RequestErrorEvent } from "../common";
2
+ import { ScopeApiResponse } from '../api/scope'
3
+
4
+ export default interface ScopeEvents {
5
+ onFetched: (callback: (response: ScopeApiResponse.scopeList) => void) => void;
6
+ onNotFetched: RequestErrorEvent;
7
+
8
+ // POST
9
+ onChangeSucceeded: (callback: (response: ScopeApiResponse.scopeAddition) => void) => void;
10
+ onChangeFailed: RequestErrorEvent;
11
+
12
+ // Availability
13
+ onProductAvailabilityFetched: (callback: (response: ScopeApiResponse.availability, product_id: number) => void) => void;
14
+ onProductAvailabilityNotFetched: RequestErrorEvent;
15
+ }
@@ -0,0 +1,8 @@
1
+ import {RequestErrorEventWithData, SuccessResponse} from "../common";
2
+
3
+ export default interface WishlistEvent {
4
+ onAdded: (callback: (response: SuccessResponse, product_id: number) => void) => void;
5
+ onRemoved: (callback: (response: SuccessResponse, product_id: number) => void) => void;
6
+ onAdditionFailed: RequestErrorEventWithData</*product_id*/number>;
7
+ onRemovingFailed: RequestErrorEventWithData</*product_id*/number>;
8
+ }
@@ -0,0 +1,29 @@
1
+ type ElementOrSelector = string | HTMLElement;
2
+ type EventTypes = 'click' | 'keyup' | 'input' | 'change' | string;
3
+ export default interface AppHelpers {
4
+ toggleClassIf: (selector: string, classes1: string | Array<string>, classes2: string | Array<string>, callback: (element: HTMLElement) => boolean) => AppHelpers;
5
+ toggleElementClassIf: (element: HTMLElement, classes1: string | Array<string>, classes2: string | Array<string>, callback: (element: HTMLElement) => boolean) => AppHelpers;
6
+
7
+ isValidEmail: (email: string) => boolean;
8
+
9
+ element: (selector: ElementOrSelector) => HTMLElement | undefined;
10
+ watchElement: (name: string, selector: ElementOrSelector) => AppHelpers;
11
+ watchElements: (elements: { [key: string]: [value: ElementOrSelector] }) => AppHelpers;
12
+ hideElement: (element: ElementOrSelector) => AppHelpers;
13
+ showElement: (element: ElementOrSelector) => AppHelpers;
14
+ //💡 you can pass one or multi classes: this.removeClass(element, 'class_1', 'class_2', ...)
15
+ removeClass: (element: ElementOrSelector, ...className: string[]) => AppHelpers;
16
+ addClass: (element: ElementOrSelector, ...className: string[]) => AppHelpers;
17
+ //💡instead of: `document.querySelectorAll('.test').forEach(element=>{...})`
18
+ // you can use: `this.all('.test', element=>{...})`
19
+ all: (element: ElementOrSelector, callback: (element: HTMLElement) => void) => AppHelpers;
20
+
21
+ //💡instead of: `document.querySelectorAll('.test').forEach(el => el.addEventListener('keyup', callback));`
22
+ // you can use: `this.on('.test', 'keyup', callback)`
23
+ // or can use: `this.onKeyUp('.test', callback)`
24
+ on: (eventType: EventTypes, element: ElementOrSelector, callback: EventListener, options?: AddEventListenerOptions) => AppHelpers;
25
+ onClick: (element: ElementOrSelector, callback: EventListener) => AppHelpers;
26
+ onKeyUp: (element: ElementOrSelector, callback: EventListener) => AppHelpers;
27
+ onEnter: (element: ElementOrSelector, callback: EventListener) => AppHelpers;
28
+ debounce: (callback: () => unknown) => (...data: any | undefined) => Promise<unknown>
29
+ }
@@ -0,0 +1,36 @@
1
+ import TwilightEmitter from './event';
2
+ import Api, {ApiActionName} from "./api";
3
+ import SallaActions from "./actions";
4
+
5
+ import Config from "./lib/config";
6
+ import AppHelpers from "./helpers/app-helpers";
7
+ import SallaNotify from "./lib/notify";
8
+ import SallaLang from "./lib/lang";
9
+ import SallaForm from "./lib/form";
10
+ import {TwilightConfig} from "./tiwlight-config";
11
+
12
+ export default interface Salla extends SallaActions {
13
+ api: Api;
14
+ event: TwilightEmitter;
15
+
16
+ config: TwilightConfig;
17
+ lang: SallaLang;
18
+
19
+ notify: SallaNotify;
20
+ success: (message: string, data?: any) => void;
21
+ error: (message: string, data?: any) => void;
22
+
23
+ AppHelpers: AppHelpers;
24
+ form: SallaForm;
25
+ isInitiated: boolean; // will be true when firing event `twilight::initiated`
26
+ onReady: (callback: (event: Event) => unknown) => void; // don't relay on it because Salla may not existed yet
27
+ init: (config: TwilightConfig) => void; // an alias for `salla.twilight.init(config)`
28
+ call: (action: ApiActionName | string) => any;
29
+
30
+ onInitiated: (callback) => void;
31
+ }
32
+
33
+ declare global {
34
+ // @ts-ignore
35
+ let salla: Salla, Salla: Salla;
36
+ }
@@ -0,0 +1,14 @@
1
+ import { Language, TwilightConfig } from "../tiwlight-config";
2
+ import { Currency, Price } from "../common";
3
+ import { default as SallaConfig } from "@salla.sa/base/types/config";
4
+
5
+ export default interface Config extends SallaConfig {
6
+ merge: (config: TwilightConfig) => Config;
7
+ isRTL: () => boolean;
8
+ money: (money: number | Price) => string;
9
+ isUser: () => boolean;
10
+ isGuest: () => boolean;
11
+ currency: (code?: string | 'SAR') => Currency;
12
+ currencies: () => Promise<{ SAR: Currency, [iso_code: string]: Currency }>;
13
+ languages: () => Promise<Language[]>;
14
+ }
@@ -0,0 +1,8 @@
1
+ import {ApiActionName} from "../api";
2
+
3
+ export default interface SallaForm {
4
+ submit: (action: ApiActionName|string, eventOrData: Event | Object) => Promise<any>;
5
+ onSubmit: (action: ApiActionName|string, eventOrData: Event | Object) => false;
6
+ onChange: (action: ApiActionName|string, eventOrData: Event | Object) => false;
7
+ getPossibleValue(formData: object|FormData, possibleNames: Array<string>, objectable?: boolean): object | FormData | string | undefined;
8
+ }
@@ -0,0 +1,14 @@
1
+ import Lang from 'lang.js'
2
+
3
+ type Replacements = { [key: string]: string }
4
+
5
+ /**
6
+ * @Example
7
+ * salla.lang.get('pages.cart.free_shipping_alert',{amount:salla.money(100)})
8
+ */
9
+ export default interface SallaLang extends Lang {
10
+ translationsLoaded: boolean;
11
+ onLoaded: (callback: Function) => void;
12
+ get: (key: string, replacements?: Replacements, locale?: string | 'ar') => string;
13
+ set: (key: string, message: string) => SallaLang;
14
+ }
@@ -0,0 +1,14 @@
1
+ export type NotifyType = 'error' | 'success' | 'info' | string;
2
+ export type Notifier = (message: string, type: NotifyType, data?: object | any) => void | unknown;
3
+ export type Logger = (...data: string[]) => void | unknown;
4
+ export default interface SallaNotify {
5
+ fire: (message: string, type: NotifyType, data?: object | any) => Notifier; //default is just `alert(message)
6
+ setNotifier: (callback: Notifier) => void;// handy to override notifier used by salla.notify.fire(salla.success, salla.error, salla.info)
7
+ log: Logger; //default is just `console.log(...data)`
8
+ setLogger: (callback: Logger) => void;// handy to override logger used by salla.log()
9
+ error: (message: string, data?: object | any) => Notifier; //an alias for fire(message, salla.notify.types.error, data)
10
+ success: (message: string, data?: object | any) => Notifier; //an alias for fire(message, salla.notify.types.success, data)
11
+ info: (message: string, data?: object | any) => Notifier; //an alias for fire(message, salla.notify.types.info, data)
12
+ sallaInitiated;
13
+ types: { error: 'error', success: 'success', info: 'info' }; //handy to be overridden, to be passed via salla.error, salla.info, salla.success second argument when calling salla.notify.fire(message, /*{type}*/, data)
14
+ }
@@ -0,0 +1,74 @@
1
+ import {Currency} from "./common";
2
+
3
+ export interface Language {
4
+ name: string;
5
+ code: string;
6
+ url: string;
7
+ is_rtl: boolean;
8
+ country_code: string;
9
+ }
10
+
11
+ type Installment = 'tabby_installment' | 'tamara_installment' | 'spotii_pay';
12
+ type PaymentName = Installment | 'mada' | 'credit_card' | 'paypal' | 'bank' | 'stc_pay' | 'apple_pay' | 'knet';
13
+
14
+ export interface TwilightConfig {
15
+ /**
16
+ * @deprecated
17
+ */
18
+ _token?: string;
19
+
20
+ maintenance?: boolean;
21
+ debug?: boolean;
22
+ events?: { [event_name: string]: any };
23
+ sdk?: {
24
+ notifier_handler_disabled: boolean
25
+ },
26
+ store: {
27
+ url: string;
28
+ id: number;
29
+ logo?: string;
30
+ name?: string;
31
+ api?: string;
32
+ settings?: {
33
+ auth: {
34
+ email_allowed: boolean;
35
+ mobile_allowed: boolean;
36
+ is_email_required: boolean;
37
+ };
38
+ arabic_numbers_enabled: boolean;
39
+ payments: PaymentName[];
40
+ installments: Installment[];
41
+ };
42
+ };
43
+ user?: {
44
+ type?: 'user' | 'guest';
45
+ id?: string | number;
46
+ email?: any;
47
+ mobile?: any;
48
+ language_code?: string;
49
+ currency_code?: string;
50
+ country_code?: string;
51
+ };
52
+ theme?: {
53
+ name?: string;
54
+ mode?: string;
55
+ translations_hash?: string;
56
+ color?: {
57
+ primary: string | '#5cd5c4';
58
+ text: string | '#ffffff';
59
+ is_dark: boolean;
60
+ reverse_primary: string | '#5cd5c4';
61
+ reverse_text: string | '#005544';
62
+ }
63
+ };
64
+ languages?: Language[];
65
+ currencies?: {
66
+ SAR?: Currency;
67
+ [key: string]: Currency;
68
+ };
69
+ page?: {
70
+ title?: string;
71
+ slug?: string;
72
+ id?: number;//available in product.single, customer.orders.single, cart, thank-you, page-single
73
+ };
74
+ }
package/watcher.js CHANGED
@@ -2,6 +2,8 @@ const path = require('path');
2
2
  const glob = require("glob");
3
3
  const color = {normal: "\x1b[0m", red: "\x1b[31m", green: "\x1b[32m", yellow: "\x1b[33m", cyan: "\x1b[36m",}
4
4
  const {execSync} = require("child_process");
5
+ const fs = require("fs");
6
+ const WebSocketClient = require('websocket').client;
5
7
  //const webpack = require("webpack");
6
8
  /**
7
9
  * @callback HookCallback
@@ -48,10 +50,26 @@ const {execSync} = require("child_process");
48
50
  * @property {boolean} isWin
49
51
  */
50
52
  class WatcherPlugin {
51
- constructor(sallaCli = 'salla') {
52
- this.sallaCli = sallaCli;
53
+ constructor(params = {}) {
54
+ try{
55
+ if(!params.theme_id){
56
+ // this is another way to get params from cli
57
+ let cachePath = path.join(process.cwd(), "/node_modules/.salla-cli");
58
+ if(fs.existsSync(cachePath)) params = JSON.parse(fs.readFileSync(cachePath, 'utf8'));
59
+ }
60
+ }catch(err){}
61
+
62
+ let {wsport = 8001, sallaCli = "salla", theme_id, upload_url, store_id, draft_id} = params;
63
+
64
+ this.sallaCli = sallaCli;
65
+ this.theme_id = theme_id;
66
+ this.upload_url = upload_url;
67
+ this.store_id = store_id;
68
+ this.draft_id = draft_id;
69
+ this.wsport = wsport;
70
+ this.files = {};
53
71
  }
54
-
72
+
55
73
  /**
56
74
  * @param {Compiler} compiler
57
75
  */
@@ -65,9 +83,19 @@ class WatcherPlugin {
65
83
 
66
84
  console.log(color.green, '✓ Listening to webpack watch.', color.normal);
67
85
  this.addFilesToWatcher(compiler);
86
+ this.connectToWsServer();
68
87
  this.watchingChangedFiles(compiler);
88
+ this.afterCompile(compiler);
89
+ }
90
+
91
+ /**
92
+ * @param {Compiler} compiler
93
+ */
94
+ afterCompile(compiler) {
95
+ compiler.hooks.afterCompile.tap('SallaAfterCompilePlugin', (compilation) => {
96
+ this.connection.sendUTF(JSON.stringify({ msg: "reload" }));
97
+ });
69
98
  }
70
-
71
99
  /**
72
100
  * @param {Compiler} compiler
73
101
  */
@@ -76,8 +104,10 @@ class WatcherPlugin {
76
104
  let files = this.isWebpack5
77
105
  ? Array.from(compiler_.modifiedFiles || [])
78
106
  : Object.keys(compiler_.watchFileSystem.watcher.mtimes);
79
- files.filter(file => file.toLowerCase().endsWith('.twig'))
80
- .forEach(file => execSync(`${this.sallaCli} theme sync -f "${file}" -t ${this.draftId}`, {stdio: 'inherit'}));
107
+
108
+ files.map((file) => {
109
+ if (file.toLowerCase().endsWith(".twig")) this.addToQ(file);
110
+ });
81
111
  }
82
112
  );
83
113
  }
@@ -93,7 +123,7 @@ class WatcherPlugin {
93
123
  }
94
124
 
95
125
  getEntry() {
96
- let viewsPath = path.join(process.cwd(), "views");
126
+ let viewsPath = path.join(process.cwd(), "src/views");
97
127
  return this.isWin && this.isWebpack5
98
128
  ? viewsPath
99
129
  : glob.sync(path.join(viewsPath, "**/*.twig"), {absolute: true});
@@ -104,19 +134,31 @@ class WatcherPlugin {
104
134
  * @return {boolean}
105
135
  */
106
136
  canWatch(options) {
107
- if (options.mode !== 'development' || !options.watch) {
108
- console.log(color.green, `✓ Skipping Watching Theme files in production.`, color.normal);
109
- return false;
110
- }
111
- //if theme id not existed go out
112
- try {
113
- this.draftId = require(path.resolve(process.cwd(), 'theme.json')).draft_id
114
- return !!this.draftId;
115
- } catch (e) {
116
- let command = color.cyan + this.sallaCli + ' theme watch' + color.red
117
- console.log(color.red, `X Theme files won't sync! if you want to sync them, run: ${command}`, color.normal);
118
- return false;
119
- }
137
+ if (!options.watch) return false;
138
+ return !!this.theme_id;
139
+ }
140
+ connectToWsServer(){
141
+ // connect to live reload server
142
+ let client = new WebSocketClient();
143
+ client.on('connectFailed', (error)=> {
144
+ console.error('[x] Oops! Hot reload is currently not working. Check the error message for details: ',error.toString());
145
+ });
146
+
147
+ client.on('connect', (connection)=> {
148
+ this.connection = connection;
149
+ console.log(color.green, `✓ Performing hot reload on port ws://localhost:${this.wsport}`, color.normal);
150
+ });
151
+ client.connect(`ws://localhost:${this.wsport}`, 'echo-protocol');
152
+ }
153
+ addToQ(file) {
154
+ if (this.files[file]) clearTimeout(this.files[file]);
155
+ this.files[file] = setTimeout(() => {
156
+ execSync(
157
+ `${this.sallaCli} theme sync -f "${file}" -id ${this.theme_id} -store_id ${this.store_id} -draft_id ${this.draft_id} -upload_url ${this.upload_url}`,
158
+ { stdio: "inherit" }
159
+ );
160
+ delete this.files[file];
161
+ }, 700);
120
162
  }
121
163
  }
122
164
 
@@ -1,55 +0,0 @@
1
- # Twilight Components
2
-
3
- Salla web components for building web applications.
4
-
5
- ## Components
6
-
7
- - [ ] [blocks](#)
8
- - [*] [salla-search-modal](src/components/search-modal/readme.md)
9
- - [ ] [salla-login](src/components/search-modal/readme.md)
10
-
11
- ## Install
12
-
13
- ### npm
14
-
15
- ```
16
- npm install @salla.sa/twilight-components
17
- ```
18
-
19
- ### yarn
20
-
21
- ```
22
- yarn add @salla.sa/twilight-components
23
- ```
24
-
25
- ## Usage
26
-
27
- ```
28
- # npm link
29
- npm install @salla.sa/twilight-components
30
- npm install @salla.sa/twilight-tailwind-theme
31
- // or npm install {full-path-of-folder}
32
-
33
- // inclued dev
34
- require('@salla.sa/twilight-components/dist/twilight-components/twilight-components.esm')
35
- // include prod
36
- require('@salla.sa/twilight-components')
37
- ```
38
-
39
-
40
- ## Publish
41
-
42
- ### @salla.sa/twilight-components
43
-
44
- ```
45
- npm version patch
46
- npm publish --access private
47
- ```
48
-
49
- ### @salla.sa/plugins
50
-
51
- todo :: finx the publish scripts
52
-
53
- ```
54
- node publish.js
55
- ```