hasting-swatchcart-module 1.0.4 → 1.0.6

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 (2) hide show
  1. package/README.md +39 -60
  2. package/package.json +101 -101
package/README.md CHANGED
@@ -41,16 +41,26 @@ import { SwatchModule } from 'hasting-swatchcart-module';
41
41
 
42
42
  const handleToggleSidebar = () => {
43
43
  // handleToggleSidebar
44
- }
44
+ };
45
45
 
46
46
  const handleSendData = (selectedData) => {
47
47
  // handleSendData
48
- }
48
+ };
49
49
 
50
+ // UI (attributes from outside) - single product
51
+ // mountSwatchModule(rootElement, {
52
+ // isOpen: true,
53
+ // uiDataType: 'UI',
54
+ // data: mockData, // or your data
55
+ // onToggleSidebar: handleToggleSidebar,
56
+ // onSendData: handleSendData,
57
+ // });
58
+
59
+ // Fetch product data - single product
50
60
  mountSwatchModule(rootElement, {
51
61
  isOpen: true,
52
- uiDataType: 'UI' or 'DATA_INPUT' or 'DATA_ALL_PRODUCT',
53
- data: data,
62
+ uiDataType: 'FETCH_DATA_PRODUCT',
63
+ assetId: '67119b1c-36ba-42c1-bcd1-2d21cf44df55',
54
64
  onToggleSidebar: handleToggleSidebar,
55
65
  onSendData: handleSendData,
56
66
  });
@@ -95,13 +105,13 @@ export interface IAttributeAsset {
95
105
  }
96
106
  ```
97
107
 
98
- | Prop | Type | Required | Description |
99
- | --------------- | ------------------------------------------ | -------- | -------------------------------------------------------------------------------------- |
100
- | isOpen | boolean | Yes | Controls visibility of the module (module state). true → module is visible. |
101
- | uiDataType | 'UI' or 'DATA_INPUT' or 'DATA_ALL_PRODUCT' | Yes | Defines type data mode. Rendered data depends on this parameter |
102
- | data | IAttributeAsset[] | Yes | Array of attributes data. Passed to the module to render swatch cards. |
103
- | onToggleSidebar | void | Yes | This method uses for open/close this module. |
104
- | onSendData | () => selected materials array from a cart | Yes | Callback that returns selected materials from the cart back to the parent Application. |
108
+ | Prop | Type | Required | Description |
109
+ | --------------- | -------------------------------------------------------------------------------------- | -------- | -------------------------------------------------------------------------------------- |
110
+ | isOpen | boolean | Yes | Controls visibility of the module (module state). true → module is visible. |
111
+ | uiDataType | 'UI' or 'DATA_INPUT' or 'DATA_ALL_PRODUCT' or 'FETCH_DATA_PRODUCT' or 'FETCH_DATA_ALL' | Yes | Defines type data mode. Rendered data depends on this parameter |
112
+ | data | IAttributeAsset[] | Yes | Array of attributes data. Passed to the module to render swatch cards. |
113
+ | onToggleSidebar | void | Yes | This method uses for open/close this module. |
114
+ | onSendData | () => selected materials array from a cart | Yes | Callback that returns selected materials from the cart back to the parent Application. |
105
115
 
106
116
  ## Development
107
117
 
@@ -153,7 +163,8 @@ npm run build:cdn
153
163
  ```html
154
164
  <link rel="stylesheet" href="../dist/cdn/main.css" />
155
165
  <script type="module">
156
- import { mountSwatchModule } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
166
+ // Test locally
167
+ import { mountSwatchModule } from '../dist/cdn/main.js';
157
168
 
158
169
  const rootElement = document.getElementById('root');
159
170
  const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
@@ -180,16 +191,22 @@ npm run build:cdn
180
191
  3. **Test with CDN** - Use the published CDN version:
181
192
 
182
193
  ```html
183
- <!-- Test locally -->
184
- <link rel="stylesheet" href="../dist/cdn/main.css" />
185
- <!-- Test real CDN -->
186
- <!-- <link
187
- rel="stylesheet"
188
- href="https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.css"
189
- /> -->
194
+ <!-- Test real CDN -->
195
+ <link
196
+ rel="stylesheet"
197
+ href="https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.css"
198
+ />
190
199
 
191
200
  <div id="root"></div>
192
- <script type="module">
201
+ <script type="module">
202
+ // Test real CDN
203
+ import { mountSwatchModule } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
204
+
205
+ // local JSON data
206
+ const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
207
+ const mockData = await fetch(jsonUrl).then((r) => r.json());
208
+
209
+ const rootElement = document.getElementById('root'); <script type="module">
193
210
  // Test locally
194
211
  import { mountSwatchModule } from '../dist/cdn/main.js';
195
212
 
@@ -200,45 +217,7 @@ npm run build:cdn
200
217
  const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
201
218
  const mockData = await fetch(jsonUrl).then((r) => r.json());
202
219
 
203
- const rootElement = document.getElementById('root'); <script type="module">
204
- // Test locally
205
- import { mountSwatchModule } from '../dist/cdn/main.js';
206
-
207
- // Test real CDN
208
- // import { mountSwatchModule } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
209
-
210
- // local JSON data
211
- const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
212
- const mockData = await fetch(jsonUrl).then((r) => r.json());
213
-
214
- const rootElement = document.getElementById('root');
215
-
216
- const handleToggleSidebar = () => {
217
- console.log('handleToggleSidebar');
218
- };
219
-
220
- const handleSendData = (selectedData) => {
221
- console.log('handleSendData', selectedData);
222
- };
223
-
224
- // UI (attributes from outside) - single product
225
- // mountSwatchModule(rootElement, {
226
- // isOpen: true,
227
- // uiDataType: 'UI',
228
- // data: mockData, // or your data
229
- // onToggleSidebar: handleToggleSidebar,
230
- // onSendData: handleSendData,
231
- // });
232
-
233
- // Fetch product data - single product
234
- mountSwatchModule(rootElement, {
235
- isOpen: true,
236
- uiDataType: 'FETCH_DATA_PRODUCT',
237
- assetId: '67119b1c-36ba-42c1-bcd1-2d21cf44df55',
238
- onToggleSidebar: handleToggleSidebar,
239
- onSendData: handleSendData,
240
- });
241
- </script>
220
+ const rootElement = document.getElementById('root');
242
221
 
243
222
  const handleToggleSidebar = () => {
244
223
  console.log('handleToggleSidebar');
@@ -265,7 +244,7 @@ npm run build:cdn
265
244
  onToggleSidebar: handleToggleSidebar,
266
245
  onSendData: handleSendData,
267
246
  });
268
- </script>
247
+ </script>
269
248
  ```
270
249
 
271
250
  ### Testing Module Usage Locally
package/package.json CHANGED
@@ -1,101 +1,101 @@
1
- {
2
- "name": "hasting-swatchcart-module",
3
- "version": "1.0.4",
4
- "type": "module",
5
- "files": [
6
- "dist"
7
- ],
8
- "main": "dist/main.cjs",
9
- "module": "dist/main.js",
10
- "types": "dist/main.d.ts",
11
- "style": "dist/assets/index.css",
12
- "exports": {
13
- ".": {
14
- "types": "./dist/main.d.ts",
15
- "require": "./dist/main.cjs",
16
- "import": "./dist/main.js",
17
- "default": "./dist/main.js"
18
- }
19
- },
20
- "sideEffects": [
21
- "**/*.css"
22
- ],
23
- "peerDependencies": {
24
- "@reduxjs/toolkit": ">=2",
25
- "react": ">=18",
26
- "react-dom": ">=18",
27
- "react-redux": ">=9"
28
- },
29
- "scripts": {
30
- "dev": "vite -c vite.app.config.ts",
31
- "build": "tsc -b && vite build",
32
- "build:site": "vite build -c vite.app.config.ts",
33
- "build:lib": "tsc --p ./tsconfig-build.json && vite build -c vite.lib.config.ts",
34
- "build:cdn": "tsc --p ./tsconfig-build.json && vite build -c vite.cdn.config.ts",
35
- "build:all": "npm run build:lib && npm run build:cdn",
36
- "lint": "eslint .",
37
- "preview": "vite preview -c vite.app.config.ts",
38
- "format": "prettier --write .",
39
- "format:check": "prettier --check .",
40
- "prepare": "husky",
41
- "start": "vite preview -c vite.app.config.ts --host 0.0.0.0 --port ${PORT:-8080}"
42
- },
43
- "dependencies": {
44
- "@radix-ui/react-accordion": "^1.2.11",
45
- "@radix-ui/react-checkbox": "^1.3.2",
46
- "@radix-ui/react-dialog": "^1.1.14",
47
- "@radix-ui/react-label": "^2.1.7",
48
- "@radix-ui/react-popover": "^1.1.14",
49
- "@radix-ui/react-slider": "^1.3.6",
50
- "@radix-ui/react-slot": "^1.2.3",
51
- "@radix-ui/react-tooltip": "^1.2.7",
52
- "@reduxjs/toolkit": ">=2",
53
- "@tailwindcss/postcss": "^4.1.16",
54
- "@tailwindcss/vite": "^4.1.14",
55
- "@tanstack/react-virtual": "^3.13.12",
56
- "autoprefixer": "^10.4.21",
57
- "clsx": "^2.1.1",
58
- "lucide-react": "^0.487.0",
59
- "react": ">=18",
60
- "react-dom": ">=18",
61
- "react-markdown": "^10.1.0",
62
- "react-redux": ">=9",
63
- "rehype-raw": "^7.0.0",
64
- "tailwind-merge": "^3.3.0",
65
- "terser": "^5.44.0"
66
- },
67
- "devDependencies": {
68
- "@eslint/js": "^9.36.0",
69
- "@types/node": "^24.7.2",
70
- "@types/react": "^19.1.16",
71
- "@types/react-dom": "^19.1.9",
72
- "@vitejs/plugin-react": "^5.0.4",
73
- "eslint": "^9.36.0",
74
- "eslint-config-prettier": "^10.1.8",
75
- "eslint-plugin-react-hooks": "^5.2.0",
76
- "eslint-plugin-react-refresh": "^0.4.22",
77
- "glob": "^11.0.3",
78
- "globals": "^16.4.0",
79
- "husky": "^9.1.7",
80
- "lint-staged": "^16.2.3",
81
- "prettier": "^3.6.2",
82
- "sass": "^1.93.2",
83
- "sass-embedded": "^1.93.2",
84
- "tailwindcss": "^4.1.14",
85
- "tw-animate-css": "^1.3.0",
86
- "typescript": "~5.9.3",
87
- "typescript-eslint": "^8.45.0",
88
- "vite": "^7.1.7",
89
- "vite-plugin-dts": "^4.5.4",
90
- "vite-plugin-lib-inject-css": "^2.2.2"
91
- },
92
- "lint-staged": {
93
- "*.{js,jsx,ts,tsx}": [
94
- "eslint --fix",
95
- "prettier --write"
96
- ],
97
- "*.{json,css,md}": [
98
- "prettier --write"
99
- ]
100
- }
101
- }
1
+ {
2
+ "name": "hasting-swatchcart-module",
3
+ "version": "1.0.6",
4
+ "type": "module",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "dist/main.cjs",
9
+ "module": "dist/main.js",
10
+ "types": "dist/main.d.ts",
11
+ "style": "dist/assets/index.css",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/main.d.ts",
15
+ "require": "./dist/main.cjs",
16
+ "import": "./dist/main.js",
17
+ "default": "./dist/main.js"
18
+ }
19
+ },
20
+ "sideEffects": [
21
+ "**/*.css"
22
+ ],
23
+ "peerDependencies": {
24
+ "@reduxjs/toolkit": ">=2",
25
+ "react": ">=18",
26
+ "react-dom": ">=18",
27
+ "react-redux": ">=9"
28
+ },
29
+ "scripts": {
30
+ "dev": "vite -c vite.app.config.ts",
31
+ "build": "tsc -b && vite build",
32
+ "build:site": "vite build -c vite.app.config.ts",
33
+ "build:lib": "tsc --p ./tsconfig-build.json && vite build -c vite.lib.config.ts",
34
+ "build:cdn": "tsc --p ./tsconfig-build.json && vite build -c vite.cdn.config.ts",
35
+ "build:all": "npm run build:lib && npm run build:cdn",
36
+ "lint": "eslint .",
37
+ "preview": "vite preview -c vite.app.config.ts",
38
+ "format": "prettier --write .",
39
+ "format:check": "prettier --check .",
40
+ "prepare": "husky",
41
+ "start": "vite preview -c vite.app.config.ts --host 0.0.0.0 --port ${PORT:-8080}"
42
+ },
43
+ "dependencies": {
44
+ "@radix-ui/react-accordion": "^1.2.11",
45
+ "@radix-ui/react-checkbox": "^1.3.2",
46
+ "@radix-ui/react-dialog": "^1.1.14",
47
+ "@radix-ui/react-label": "^2.1.7",
48
+ "@radix-ui/react-popover": "^1.1.14",
49
+ "@radix-ui/react-slider": "^1.3.6",
50
+ "@radix-ui/react-slot": "^1.2.3",
51
+ "@radix-ui/react-tooltip": "^1.2.7",
52
+ "@reduxjs/toolkit": ">=2",
53
+ "@tailwindcss/postcss": "^4.1.16",
54
+ "@tailwindcss/vite": "^4.1.14",
55
+ "@tanstack/react-virtual": "^3.13.12",
56
+ "autoprefixer": "^10.4.21",
57
+ "clsx": "^2.1.1",
58
+ "lucide-react": "^0.487.0",
59
+ "react": ">=18",
60
+ "react-dom": ">=18",
61
+ "react-markdown": "^10.1.0",
62
+ "react-redux": ">=9",
63
+ "rehype-raw": "^7.0.0",
64
+ "tailwind-merge": "^3.3.0",
65
+ "terser": "^5.44.0"
66
+ },
67
+ "devDependencies": {
68
+ "@eslint/js": "^9.36.0",
69
+ "@types/node": "^24.7.2",
70
+ "@types/react": "^19.1.16",
71
+ "@types/react-dom": "^19.1.9",
72
+ "@vitejs/plugin-react": "^5.0.4",
73
+ "eslint": "^9.36.0",
74
+ "eslint-config-prettier": "^10.1.8",
75
+ "eslint-plugin-react-hooks": "^5.2.0",
76
+ "eslint-plugin-react-refresh": "^0.4.22",
77
+ "glob": "^11.0.3",
78
+ "globals": "^16.4.0",
79
+ "husky": "^9.1.7",
80
+ "lint-staged": "^16.2.3",
81
+ "prettier": "^3.6.2",
82
+ "sass": "^1.93.2",
83
+ "sass-embedded": "^1.93.2",
84
+ "tailwindcss": "^4.1.14",
85
+ "tw-animate-css": "^1.3.0",
86
+ "typescript": "~5.9.3",
87
+ "typescript-eslint": "^8.45.0",
88
+ "vite": "^7.1.7",
89
+ "vite-plugin-dts": "^4.5.4",
90
+ "vite-plugin-lib-inject-css": "^2.2.2"
91
+ },
92
+ "lint-staged": {
93
+ "*.{js,jsx,ts,tsx}": [
94
+ "eslint --fix",
95
+ "prettier --write"
96
+ ],
97
+ "*.{json,css,md}": [
98
+ "prettier --write"
99
+ ]
100
+ }
101
+ }