hasting-swatchcart-module 1.0.36 → 1.0.37

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 CHANGED
@@ -1,454 +1,454 @@
1
- # hasting-swatchcart-module
2
-
3
- This module was created for implementation into clients applications
4
- There are two ways of using this module: `NPM` or `CDN`
5
-
6
- ## Installation
7
-
8
- ### NPM
9
-
10
- ```bash
11
- npm i hasting-swatchcart-module
12
- ```
13
-
14
- ### NPM usage
15
-
16
- ### UI (attributes from outside )
17
-
18
- ### For example
19
-
20
- ```js
21
- const handleOpenSidebar = () => {
22
- // open/close a module
23
- };
24
- ```
25
-
26
- ```js
27
- const handleSetData = (data) => {
28
- // Callback that returns selected materials from the cart back to the parent Application.
29
- };
30
- ```
31
-
32
- ```js
33
- import { SwatchModule, EDataInputType } from 'hasting-swatchcart-module';
34
-
35
- <SwatchModule
36
- isOpen={isOpenModule}
37
- uiDataType={EDataInputType.UI}
38
- data={data}
39
- onToggleSidebar={handleOpenSidebar}
40
- onSendData={handleSetData}
41
- />;
42
- ```
43
-
44
- ### Fetch product
45
-
46
- ```js
47
- import { SwatchModule, EDataInputType } from 'hasting-swatchcart-module';
48
-
49
- <SwatchModule
50
- isOpen={isOpenModule}
51
- uiDataType={EDataInputType.FETCH_DATA_PRODUCT}
52
- assetId={'asset_id'}
53
- onToggleSidebar={handleOpenSidebar}
54
- onSendData={handleSetData}
55
- />;
56
- ```
57
-
58
- ### Fetch product all
59
-
60
- ```js
61
- import { SwatchModule, EDataInputType } from 'hasting-swatchcart-module';
62
-
63
- <SwatchModule
64
- isOpen={isOpenModule}
65
- uiDataType={EDataInputType.FETCH_DATA_ALL}
66
- onToggleSidebar={handleOpenSidebar}
67
- onSendData={handleSetData}
68
- />;
69
- ```
70
-
71
- ### CDN (no installation required) usage and installation
72
-
73
- ```html
74
- <link
75
- rel="stylesheet"
76
- href="https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.css"
77
- />
78
- <body>
79
- <div id="root"></div>
80
-
81
- <script type="module">
82
- import {
83
- mountSwatchModule,
84
- EDataInputType,
85
- } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
86
-
87
- // local MOCK JSON data or your real data
88
- const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
89
- const mockData = await fetch(jsonUrl).then((r) => r.json());
90
-
91
- const rootElement = document.getElementById('root');
92
-
93
- const handleToggleSidebar = () => {
94
- console.log('handleToggleSidebar');
95
- };
96
-
97
- const handleSendData = (selectedData) => {
98
- console.log('handleSendData', selectedData);
99
- };
100
-
101
- // UI (attributes from outside) - single product
102
- mountSwatchModule(rootElement, {
103
- isOpen: true,
104
- uiDataType: EDataInputType.UI,
105
- data: mockData, // or your data
106
- onToggleSidebar: handleToggleSidebar,
107
- onSendData: handleSendData,
108
- });
109
-
110
- // Fetch product data - single product
111
- mountSwatchModule(rootElement, {
112
- isOpen: true,
113
- uiDataType: EDataInputType.FETCH_DATA_PRODUCT,
114
- assetId: 'assetId',
115
- onToggleSidebar: handleToggleSidebar,
116
- onSendData: handleSendData,
117
- });
118
-
119
- // Fetch product all data - multi product
120
- mountSwatchModule(rootElement, {
121
- isOpen: true,
122
- uiDataType: EDataInputType.FETCH_DATA_ALL,
123
- onToggleSidebar: handleToggleSidebar,
124
- onSendData: handleSendData,
125
- });
126
- </script>
127
- </body>
128
- ```
129
-
130
- ## Props
131
-
132
- ```ts
133
- export interface IAttributeAsset {
134
- assetType: string;
135
- blacklist: unknown[];
136
- defaultValue: { assetId: string; type: string }[];
137
- disabledValues: unknown[];
138
- enabled: boolean;
139
- global: {
140
- defaultValue: { assetId: string; type: string };
141
- id: string;
142
- metadata: unknown[];
143
- name: string;
144
- type: string;
145
- };
146
- hiddenValues: unknown[];
147
- id: string;
148
- label: string;
149
- metadata: {
150
- [key: string]: string;
151
- };
152
- name: string;
153
- type: string;
154
- value: {
155
- assetId: string;
156
- configuration: unknown;
157
- metadata: { [key: string]: string };
158
- name: string;
159
- tags: string[];
160
- type: string;
161
- };
162
- values: IAttributeAssetValues[];
163
- visible: boolean;
164
- }
165
- ```
166
-
167
- ### UI (attributes from outside )
168
-
169
- | Prop | Type | Required | Description |
170
- | --------------- | ------------------------------------------------------ | -------- | -------------------------------------------------------------------------------------- |
171
- | isOpen | boolean | Yes | Controls visibility of the module (module state). true → module is visible. |
172
- | uiDataType | 'UI' | Yes | Defines type data mode. Rendered data depends on this parameter |
173
- | data | IAttributeAsset[] | Yes | Array of attributes data. Passed to the module to render swatch cards. |
174
- | onToggleSidebar | void | Yes | This method uses for open/close this module. |
175
- | onSendData | (data) => data is selected materials array from a cart | Yes | Callback that returns selected materials from the cart back to the parent Application. |
176
-
177
- ### Fetch product
178
-
179
- | Prop | Type | Required | Description |
180
- | --------------- | ------------------------------------------------------ | -------- | -------------------------------------------------------------------------------------- |
181
- | isOpen | boolean | Yes | Controls visibility of the module (module state). true → module is visible. |
182
- | uiDataType | 'FETCH_DATA_PRODUCT' | Yes | Defines type data mode. Rendered data depends on this parameter |
183
- | assetId | string | Yes | Defined an object for getting it`s attributes |
184
- | onToggleSidebar | void | Yes | This method uses for open/close this module. |
185
- | onSendData | (data) => data is selected materials array from a cart | Yes | Callback that returns selected materials from the cart back to the parent Application. |
186
-
187
- ### Fetch all product
188
-
189
- | Prop | Type | Required | Description |
190
- | --------------- | ------------------------------------------------------ | -------- | -------------------------------------------------------------------------------------- |
191
- | isOpen | boolean | Yes | Controls visibility of the module (module state). true → module is visible. |
192
- | uiDataType | 'FETCH_DATA_ALL' | Yes | Defines type data mode. Rendered data depends on this parameter |
193
- | onToggleSidebar | void | Yes | This method uses for open/close this module. |
194
- | onSendData | (data) => data is selected materials array from a cart | Yes | Callback that returns selected materials from the cart back to the parent Application. |
195
-
196
- ## Development
197
-
198
- ```bash
199
- git clone https://github.com/Elementals-technical/hasting-swatchcart-module.git
200
- cd hasting-swatchcart-module
201
- npm install
202
- npm run dev
203
- ```
204
-
205
- ### General Information
206
-
207
- This project gives a module which can be implemented in two ways `NPM`, `CDN`.
208
-
209
- **_IMPORTANT_** before pushing code to the git repo, husky runs this scripts for checking `error/warnings`. If your scripts din't finish, check the console for more information
210
-
211
- ```bash
212
- npm run build:all
213
- npx lint-staged
214
- ```
215
-
216
- ### Stack
217
-
218
- - react
219
- - RTK
220
- - css/tailwind
221
- - vite
222
- - husky
223
- - lint
224
- - FSD as architecture base
225
-
226
- ### Testing CDN Usage Locally
227
-
228
- 1. **Build**
229
- If a `dist` folder `doesn't exist`, use this command for making it.
230
-
231
- ```bash
232
- npm run build:all
233
- ```
234
-
235
- If a `dist` folder `exist`, use this command for making it.
236
-
237
- ```bash
238
- npm run build:cdn
239
- ```
240
-
241
- 2. **Test with local files** - Create an HTML file and use local paths:
242
-
243
- ```html
244
- <link rel="stylesheet" href="../dist/cdn/main.css" />
245
- <script type="module">
246
- // Test locally
247
- import { mountSwatchModule, EDataInputType } from '../dist/cdn/main.js';
248
-
249
- const rootElement = document.getElementById('root');
250
- const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
251
- const mockData = await fetch(jsonUrl).then((r) => r.json());
252
-
253
- const handleToggleSidebar = () => {
254
- console.log('handleToggleSidebar is working');
255
- };
256
-
257
- const handleSendData = (selectedData) => {
258
- console.log('handleSendData is working', selectedData);
259
- };
260
-
261
- // Chose one of these possible options
262
-
263
- // UI (attributes from outside) - single product
264
- mountSwatchModule(rootElement, {
265
- isOpen: true,
266
- uiDataType: EDataInputType.UI,
267
- data: mockData, // or your data
268
- onToggleSidebar: handleToggleSidebar,
269
- onSendData: handleSendData,
270
- });
271
-
272
- // Fetch product data - single product
273
- mountSwatchModule(rootElement, {
274
- isOpen: true,
275
- uiDataType: EDataInputType.FETCH_DATA_PRODUCT,
276
- assetId: 'assetId',
277
- onToggleSidebar: handleToggleSidebar,
278
- onSendData: handleSendData,
279
- });
280
-
281
- // Fetch product all data - multi product
282
- mountSwatchModule(rootElement, {
283
- isOpen: true,
284
- uiDataType: EDataInputType.FETCH_DATA_ALL,
285
- onToggleSidebar: handleToggleSidebar,
286
- onSendData: handleSendData,
287
- });
288
- </script>
289
- ```
290
-
291
- 3. **Test with CDN** - Use the published CDN version:
292
-
293
- ```html
294
- <!-- Test real CDN -->
295
- <link
296
- rel="stylesheet"
297
- href="https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.css"
298
- />
299
-
300
- <div id="root"></div>
301
- <script type="module">
302
- // Test real CDN
303
- import { mountSwatchModule } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
304
-
305
- // local JSON data
306
- const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
307
- const mockData = await fetch(jsonUrl).then((r) => r.json());
308
-
309
- const rootElement = document.getElementById('root'); <script type="module">
310
- // Test locally
311
- // import { mountSwatchModule } from '../dist/cdn/main.js';
312
-
313
- // Test real CDN
314
- import { mountSwatchModule } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
315
-
316
- // local JSON data
317
- const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
318
- const mockData = await fetch(jsonUrl).then((r) => r.json());
319
-
320
- const rootElement = document.getElementById('root');
321
-
322
- const handleToggleSidebar = () => {
323
- console.log('handleToggleSidebar');
324
- };
325
-
326
- const handleSendData = (selectedData) => {
327
- console.log('handleSendData', selectedData);
328
- };
329
-
330
- // Chose one of these possible options
331
-
332
- // UI (attributes from outside) - single product
333
- mountSwatchModule(rootElement, {
334
- isOpen: true,
335
- uiDataType: EDataInputType.UI,
336
- data: mockData, // or your data
337
- onToggleSidebar: handleToggleSidebar,
338
- onSendData: handleSendData,
339
- });
340
-
341
- // Fetch product data - single product
342
- mountSwatchModule(rootElement, {
343
- isOpen: true,
344
- uiDataType: EDataInputType.FETCH_DATA_PRODUCT,
345
- assetId: 'assetId',
346
- onToggleSidebar: handleToggleSidebar,
347
- onSendData: handleSendData,
348
- });
349
-
350
- // Fetch product all data - multi product
351
- mountSwatchModule(rootElement, {
352
- isOpen: true,
353
- uiDataType: EDataInputType.FETCH_DATA_ALL,
354
- onToggleSidebar: handleToggleSidebar,
355
- onSendData: handleSendData,
356
- });
357
- </script>
358
- ```
359
-
360
- ### Testing Module Usage Locally
361
-
362
- 1. **Build**
363
-
364
- ```bash
365
- npm run build:lib
366
- ```
367
-
368
- 2. **Run Locally**
369
-
370
- After finishing `build` in the `src/App.ts`, import builded file from the builded folder
371
-
372
- ```js
373
- import { SwatchModule } from '../../dist/main'; // build module
374
- ```
375
-
376
- 3. **Use module**
377
-
378
- ### UI (attributes from outside )
379
-
380
- ```js
381
- <SwatchModule
382
- isOpen={isOpenModule}
383
- uiDataType={'UI'}
384
- data={data}
385
- onToggleSidebar={handleOpenSidebar}
386
- onSendData={handleSetData}
387
- />
388
- ```
389
-
390
- ### Fetch product
391
-
392
- ```js
393
- <SwatchModule
394
- isOpen={isOpenModule}
395
- uiDataType={'FETCH_DATA_PRODUCT'}
396
- assetId={'asset_id'}
397
- onToggleSidebar={handleOpenSidebar}
398
- onSendData={handleSetData}
399
- />
400
- ```
401
-
402
- ### Fetch product all
403
-
404
- ```js
405
- <SwatchModule
406
- isOpen={isOpenModule}
407
- uiDataType={'FETCH_DATA_PRODUCT_All'}
408
- onToggleSidebar={handleOpenSidebar}
409
- onSendData={handleSetData}
410
- />
411
- ```
412
-
413
- ## Branching
414
-
415
- We have one main branch `main`. This branch connected to DO and our web version of our module.
416
-
417
- ## Publishing
418
-
419
- In our app we have two envs that we need to published
420
-
421
- - web
422
- - module
423
-
424
- ### Publishing web
425
-
426
- ```bach
427
- npm run build
428
- ```
429
-
430
- Then push your changes to the `develop` branch then push to the `main`
431
-
432
- ### Publishing module
433
-
434
- Before Publishing you need to start
435
-
436
- ```bach
437
- npm run build:all
438
- ```
439
-
440
- Then
441
-
442
- Update module version
443
-
444
- `"version": "*.*.*"`
445
-
446
- Then
447
-
448
- ```bach
449
- npm publish
450
- ```
451
-
452
- You can publish module changes from any branch you want
453
-
454
- \*\* Don't forget to add your changes to the `main` branch
1
+ # hasting-swatchcart-module
2
+
3
+ This module was created for implementation into clients applications
4
+ There are two ways of using this module: `NPM` or `CDN`
5
+
6
+ ## Installation
7
+
8
+ ### NPM
9
+
10
+ ```bash
11
+ npm i hasting-swatchcart-module
12
+ ```
13
+
14
+ ### NPM usage
15
+
16
+ ### UI (attributes from outside )
17
+
18
+ ### For example
19
+
20
+ ```js
21
+ const handleOpenSidebar = () => {
22
+ // open/close a module
23
+ };
24
+ ```
25
+
26
+ ```js
27
+ const handleSetData = (data) => {
28
+ // Callback that returns selected materials from the cart back to the parent Application.
29
+ };
30
+ ```
31
+
32
+ ```js
33
+ import { SwatchModule, EDataInputType } from 'hasting-swatchcart-module';
34
+
35
+ <SwatchModule
36
+ isOpen={isOpenModule}
37
+ uiDataType={EDataInputType.UI}
38
+ data={data}
39
+ onToggleSidebar={handleOpenSidebar}
40
+ onSendData={handleSetData}
41
+ />;
42
+ ```
43
+
44
+ ### Fetch product
45
+
46
+ ```js
47
+ import { SwatchModule, EDataInputType } from 'hasting-swatchcart-module';
48
+
49
+ <SwatchModule
50
+ isOpen={isOpenModule}
51
+ uiDataType={EDataInputType.FETCH_DATA_PRODUCT}
52
+ assetId={'asset_id'}
53
+ onToggleSidebar={handleOpenSidebar}
54
+ onSendData={handleSetData}
55
+ />;
56
+ ```
57
+
58
+ ### Fetch product all
59
+
60
+ ```js
61
+ import { SwatchModule, EDataInputType } from 'hasting-swatchcart-module';
62
+
63
+ <SwatchModule
64
+ isOpen={isOpenModule}
65
+ uiDataType={EDataInputType.FETCH_DATA_ALL}
66
+ onToggleSidebar={handleOpenSidebar}
67
+ onSendData={handleSetData}
68
+ />;
69
+ ```
70
+
71
+ ### CDN (no installation required) usage and installation
72
+
73
+ ```html
74
+ <link
75
+ rel="stylesheet"
76
+ href="https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.css"
77
+ />
78
+ <body>
79
+ <div id="root"></div>
80
+
81
+ <script type="module">
82
+ import {
83
+ mountSwatchModule,
84
+ EDataInputType,
85
+ } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
86
+
87
+ // local MOCK JSON data or your real data
88
+ const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
89
+ const mockData = await fetch(jsonUrl).then((r) => r.json());
90
+
91
+ const rootElement = document.getElementById('root');
92
+
93
+ const handleToggleSidebar = () => {
94
+ console.log('handleToggleSidebar');
95
+ };
96
+
97
+ const handleSendData = (selectedData) => {
98
+ console.log('handleSendData', selectedData);
99
+ };
100
+
101
+ // UI (attributes from outside) - single product
102
+ mountSwatchModule(rootElement, {
103
+ isOpen: true,
104
+ uiDataType: EDataInputType.UI,
105
+ data: mockData, // or your data
106
+ onToggleSidebar: handleToggleSidebar,
107
+ onSendData: handleSendData,
108
+ });
109
+
110
+ // Fetch product data - single product
111
+ mountSwatchModule(rootElement, {
112
+ isOpen: true,
113
+ uiDataType: EDataInputType.FETCH_DATA_PRODUCT,
114
+ assetId: 'assetId',
115
+ onToggleSidebar: handleToggleSidebar,
116
+ onSendData: handleSendData,
117
+ });
118
+
119
+ // Fetch product all data - multi product
120
+ mountSwatchModule(rootElement, {
121
+ isOpen: true,
122
+ uiDataType: EDataInputType.FETCH_DATA_ALL,
123
+ onToggleSidebar: handleToggleSidebar,
124
+ onSendData: handleSendData,
125
+ });
126
+ </script>
127
+ </body>
128
+ ```
129
+
130
+ ## Props
131
+
132
+ ```ts
133
+ export interface IAttributeAsset {
134
+ assetType: string;
135
+ blacklist: unknown[];
136
+ defaultValue: { assetId: string; type: string }[];
137
+ disabledValues: unknown[];
138
+ enabled: boolean;
139
+ global: {
140
+ defaultValue: { assetId: string; type: string };
141
+ id: string;
142
+ metadata: unknown[];
143
+ name: string;
144
+ type: string;
145
+ };
146
+ hiddenValues: unknown[];
147
+ id: string;
148
+ label: string;
149
+ metadata: {
150
+ [key: string]: string;
151
+ };
152
+ name: string;
153
+ type: string;
154
+ value: {
155
+ assetId: string;
156
+ configuration: unknown;
157
+ metadata: { [key: string]: string };
158
+ name: string;
159
+ tags: string[];
160
+ type: string;
161
+ };
162
+ values: IAttributeAssetValues[];
163
+ visible: boolean;
164
+ }
165
+ ```
166
+
167
+ ### UI (attributes from outside )
168
+
169
+ | Prop | Type | Required | Description |
170
+ | --------------- | ------------------------------------------------------ | -------- | -------------------------------------------------------------------------------------- |
171
+ | isOpen | boolean | Yes | Controls visibility of the module (module state). true → module is visible. |
172
+ | uiDataType | 'UI' | Yes | Defines type data mode. Rendered data depends on this parameter |
173
+ | data | IAttributeAsset[] | Yes | Array of attributes data. Passed to the module to render swatch cards. |
174
+ | onToggleSidebar | void | Yes | This method uses for open/close this module. |
175
+ | onSendData | (data) => data is selected materials array from a cart | Yes | Callback that returns selected materials from the cart back to the parent Application. |
176
+
177
+ ### Fetch product
178
+
179
+ | Prop | Type | Required | Description |
180
+ | --------------- | ------------------------------------------------------ | -------- | -------------------------------------------------------------------------------------- |
181
+ | isOpen | boolean | Yes | Controls visibility of the module (module state). true → module is visible. |
182
+ | uiDataType | 'FETCH_DATA_PRODUCT' | Yes | Defines type data mode. Rendered data depends on this parameter |
183
+ | assetId | string | Yes | Defined an object for getting it`s attributes |
184
+ | onToggleSidebar | void | Yes | This method uses for open/close this module. |
185
+ | onSendData | (data) => data is selected materials array from a cart | Yes | Callback that returns selected materials from the cart back to the parent Application. |
186
+
187
+ ### Fetch all product
188
+
189
+ | Prop | Type | Required | Description |
190
+ | --------------- | ------------------------------------------------------ | -------- | -------------------------------------------------------------------------------------- |
191
+ | isOpen | boolean | Yes | Controls visibility of the module (module state). true → module is visible. |
192
+ | uiDataType | 'FETCH_DATA_ALL' | Yes | Defines type data mode. Rendered data depends on this parameter |
193
+ | onToggleSidebar | void | Yes | This method uses for open/close this module. |
194
+ | onSendData | (data) => data is selected materials array from a cart | Yes | Callback that returns selected materials from the cart back to the parent Application. |
195
+
196
+ ## Development
197
+
198
+ ```bash
199
+ git clone https://github.com/Elementals-technical/hasting-swatchcart-module.git
200
+ cd hasting-swatchcart-module
201
+ npm install
202
+ npm run dev
203
+ ```
204
+
205
+ ### General Information
206
+
207
+ This project gives a module which can be implemented in two ways `NPM`, `CDN`.
208
+
209
+ **_IMPORTANT_** before pushing code to the git repo, husky runs this scripts for checking `error/warnings`. If your scripts din't finish, check the console for more information
210
+
211
+ ```bash
212
+ npm run build:all
213
+ npx lint-staged
214
+ ```
215
+
216
+ ### Stack
217
+
218
+ - react
219
+ - RTK
220
+ - css/tailwind
221
+ - vite
222
+ - husky
223
+ - lint
224
+ - FSD as architecture base
225
+
226
+ ### Testing CDN Usage Locally
227
+
228
+ 1. **Build**
229
+ If a `dist` folder `doesn't exist`, use this command for making it.
230
+
231
+ ```bash
232
+ npm run build:all
233
+ ```
234
+
235
+ If a `dist` folder `exist`, use this command for making it.
236
+
237
+ ```bash
238
+ npm run build:cdn
239
+ ```
240
+
241
+ 2. **Test with local files** - Create an HTML file and use local paths:
242
+
243
+ ```html
244
+ <link rel="stylesheet" href="../dist/cdn/main.css" />
245
+ <script type="module">
246
+ // Test locally
247
+ import { mountSwatchModule, EDataInputType } from '../dist/cdn/main.js';
248
+
249
+ const rootElement = document.getElementById('root');
250
+ const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
251
+ const mockData = await fetch(jsonUrl).then((r) => r.json());
252
+
253
+ const handleToggleSidebar = () => {
254
+ console.log('handleToggleSidebar is working');
255
+ };
256
+
257
+ const handleSendData = (selectedData) => {
258
+ console.log('handleSendData is working', selectedData);
259
+ };
260
+
261
+ // Chose one of these possible options
262
+
263
+ // UI (attributes from outside) - single product
264
+ mountSwatchModule(rootElement, {
265
+ isOpen: true,
266
+ uiDataType: EDataInputType.UI,
267
+ data: mockData, // or your data
268
+ onToggleSidebar: handleToggleSidebar,
269
+ onSendData: handleSendData,
270
+ });
271
+
272
+ // Fetch product data - single product
273
+ mountSwatchModule(rootElement, {
274
+ isOpen: true,
275
+ uiDataType: EDataInputType.FETCH_DATA_PRODUCT,
276
+ assetId: 'assetId',
277
+ onToggleSidebar: handleToggleSidebar,
278
+ onSendData: handleSendData,
279
+ });
280
+
281
+ // Fetch product all data - multi product
282
+ mountSwatchModule(rootElement, {
283
+ isOpen: true,
284
+ uiDataType: EDataInputType.FETCH_DATA_ALL,
285
+ onToggleSidebar: handleToggleSidebar,
286
+ onSendData: handleSendData,
287
+ });
288
+ </script>
289
+ ```
290
+
291
+ 3. **Test with CDN** - Use the published CDN version:
292
+
293
+ ```html
294
+ <!-- Test real CDN -->
295
+ <link
296
+ rel="stylesheet"
297
+ href="https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.css"
298
+ />
299
+
300
+ <div id="root"></div>
301
+ <script type="module">
302
+ // Test real CDN
303
+ import { mountSwatchModule } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
304
+
305
+ // local JSON data
306
+ const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
307
+ const mockData = await fetch(jsonUrl).then((r) => r.json());
308
+
309
+ const rootElement = document.getElementById('root'); <script type="module">
310
+ // Test locally
311
+ // import { mountSwatchModule } from '../dist/cdn/main.js';
312
+
313
+ // Test real CDN
314
+ import { mountSwatchModule } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
315
+
316
+ // local JSON data
317
+ const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
318
+ const mockData = await fetch(jsonUrl).then((r) => r.json());
319
+
320
+ const rootElement = document.getElementById('root');
321
+
322
+ const handleToggleSidebar = () => {
323
+ console.log('handleToggleSidebar');
324
+ };
325
+
326
+ const handleSendData = (selectedData) => {
327
+ console.log('handleSendData', selectedData);
328
+ };
329
+
330
+ // Chose one of these possible options
331
+
332
+ // UI (attributes from outside) - single product
333
+ mountSwatchModule(rootElement, {
334
+ isOpen: true,
335
+ uiDataType: EDataInputType.UI,
336
+ data: mockData, // or your data
337
+ onToggleSidebar: handleToggleSidebar,
338
+ onSendData: handleSendData,
339
+ });
340
+
341
+ // Fetch product data - single product
342
+ mountSwatchModule(rootElement, {
343
+ isOpen: true,
344
+ uiDataType: EDataInputType.FETCH_DATA_PRODUCT,
345
+ assetId: 'assetId',
346
+ onToggleSidebar: handleToggleSidebar,
347
+ onSendData: handleSendData,
348
+ });
349
+
350
+ // Fetch product all data - multi product
351
+ mountSwatchModule(rootElement, {
352
+ isOpen: true,
353
+ uiDataType: EDataInputType.FETCH_DATA_ALL,
354
+ onToggleSidebar: handleToggleSidebar,
355
+ onSendData: handleSendData,
356
+ });
357
+ </script>
358
+ ```
359
+
360
+ ### Testing Module Usage Locally
361
+
362
+ 1. **Build**
363
+
364
+ ```bash
365
+ npm run build:lib
366
+ ```
367
+
368
+ 2. **Run Locally**
369
+
370
+ After finishing `build` in the `src/App.ts`, import builded file from the builded folder
371
+
372
+ ```js
373
+ import { SwatchModule } from '../../dist/main'; // build module
374
+ ```
375
+
376
+ 3. **Use module**
377
+
378
+ ### UI (attributes from outside )
379
+
380
+ ```js
381
+ <SwatchModule
382
+ isOpen={isOpenModule}
383
+ uiDataType={'UI'}
384
+ data={data}
385
+ onToggleSidebar={handleOpenSidebar}
386
+ onSendData={handleSetData}
387
+ />
388
+ ```
389
+
390
+ ### Fetch product
391
+
392
+ ```js
393
+ <SwatchModule
394
+ isOpen={isOpenModule}
395
+ uiDataType={'FETCH_DATA_PRODUCT'}
396
+ assetId={'asset_id'}
397
+ onToggleSidebar={handleOpenSidebar}
398
+ onSendData={handleSetData}
399
+ />
400
+ ```
401
+
402
+ ### Fetch product all
403
+
404
+ ```js
405
+ <SwatchModule
406
+ isOpen={isOpenModule}
407
+ uiDataType={'FETCH_DATA_PRODUCT_All'}
408
+ onToggleSidebar={handleOpenSidebar}
409
+ onSendData={handleSetData}
410
+ />
411
+ ```
412
+
413
+ ## Branching
414
+
415
+ We have one main branch `main`. This branch connected to DO and our web version of our module.
416
+
417
+ ## Publishing
418
+
419
+ In our app we have two envs that we need to published
420
+
421
+ - web
422
+ - module
423
+
424
+ ### Publishing web
425
+
426
+ ```bach
427
+ npm run build
428
+ ```
429
+
430
+ Then push your changes to the `develop` branch then push to the `main`
431
+
432
+ ### Publishing module
433
+
434
+ Before Publishing you need to start
435
+
436
+ ```bach
437
+ npm run build:all
438
+ ```
439
+
440
+ Then
441
+
442
+ Update module version
443
+
444
+ `"version": "*.*.*"`
445
+
446
+ Then
447
+
448
+ ```bach
449
+ npm publish
450
+ ```
451
+
452
+ You can publish module changes from any branch you want
453
+
454
+ \*\* Don't forget to add your changes to the `main` branch