@mapvx/website-component 0.5.1 → 0.6.0

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
@@ -52,29 +52,95 @@ import '@mapvx/website-component/dist/browser/styles.css'
52
52
  ```jsx
53
53
  // In your main App.jsx or index.jsx
54
54
  import '@mapvx/website-component/dist/browser/main.js'
55
- import '@mapvx/website-component/dist/browser/styles.css'
56
55
 
57
56
  function App() {
58
57
  return <mapvx-website api-key="your-api-key-here" />
59
58
  }
60
59
  ```
61
60
 
61
+ ```css
62
+ /* In your main CSS file (e.g., index.css, App.css) */
63
+ @import '@mapvx/website-component/dist/browser/styles.css';
64
+ ```
65
+
62
66
  **Vue:**
63
67
 
64
68
  ```javascript
65
69
  // In your main.js
66
70
  import '@mapvx/website-component/dist/browser/main.js'
67
- import '@mapvx/website-component/dist/browser/styles.css'
71
+ ```
72
+
73
+ ```css
74
+ /* In your main CSS file (e.g., style.css, main.css) */
75
+ @import '@mapvx/website-component/dist/browser/styles.css';
68
76
  ```
69
77
 
70
78
  **Angular:**
71
79
 
80
+ #### Method 1: HTML Script Tags
81
+
82
+ Configure assets in `angular.json` and use script tags in `index.html`:
83
+
84
+ ```json
85
+ {
86
+ "assets": [
87
+ {
88
+ "glob": "**/*",
89
+ "input": "public"
90
+ },
91
+ {
92
+ "glob": "**/*",
93
+ "input": "src/assets",
94
+ "output": "assets"
95
+ },
96
+ {
97
+ "glob": "**/*",
98
+ "input": "node_modules/@mapvx/website-component/dist/browser",
99
+ "output": "website-component"
100
+ }
101
+ ]
102
+ }
103
+ ```
104
+
105
+ Then reference the files in your `index.html`:
106
+
107
+ ```html
108
+ <!-- Web Component Scripts -->
109
+ <script src="website-component/main.js" defer></script>
110
+
111
+ <!-- Web Component Styles -->
112
+ <link rel="stylesheet" href="website-component/styles.css" />
113
+ ```
114
+
115
+ **Why this configuration is needed:**
116
+
117
+ - Angular doesn't serve files from `node_modules` by default in development
118
+ - Without proper asset configuration, you'll get `SyntaxError: Unexpected token '<'` errors
119
+ - This ensures files are served as static assets with proper caching headers
120
+
121
+ #### Method 2: TypeScript Imports
122
+
123
+ Alternatively, you can import the files in your application:
124
+
72
125
  ```typescript
73
- // In your angular.json or import in main.ts
126
+ // In your main.ts - Import the JavaScript
74
127
  import '@mapvx/website-component/dist/browser/main.js'
75
- import '@mapvx/website-component/dist/browser/styles.css'
76
128
  ```
77
129
 
130
+ ```scss
131
+ /* In your styles.scss - Import the styles (Modern Sass) */
132
+ @use '@mapvx/website-component/dist/browser/styles.css';
133
+
134
+ /* Alternative for older Sass versions or CSS files */
135
+ @import '@mapvx/website-component/dist/browser/styles.css';
136
+ ```
137
+
138
+ **Important**: Choose ONE method only:
139
+
140
+ - ✅ **Method 1**: HTML script tags + assets configuration
141
+ - ✅ **Method 2**: TypeScript imports + SCSS imports
142
+ - ❌ **Don't use both**: This can cause duplicate loading and conflicts
143
+
78
144
  ### Helper Package (SSR Support)
79
145
 
80
146
  For Server-Side Rendering (SSR) applications that need to preload initial data on the server:
@@ -180,6 +246,7 @@ The web component accepts the following input properties to customize its behavi
180
246
  | `show-category-filters` | `boolean` | ❌ No | `true` | If `true`, shows category filters |
181
247
  | `show-city-filter` | `boolean` | ❌ No | `true` | If `true`, shows city filter |
182
248
  | `inherit-font-family` | `boolean` | ❌ No | `false` | If `true`, inherits font family from parent |
249
+ | `hide-deals` | `boolean` | ❌ No | `false` | If `true`, hides deals and promotional content |
183
250
 
184
251
  ### Input Usage Examples
185
252
 
@@ -198,6 +265,7 @@ The web component accepts the following input properties to customize its behavi
198
265
  default-to-map="true"
199
266
  show-category-filters="false"
200
267
  show-city-filter="true"
268
+ hide-deals="true"
201
269
  >
202
270
  </mapvx-website>
203
271
  ```
@@ -216,19 +284,64 @@ npm install @mapvx/website-component-helpers
216
284
 
217
285
  #### Next.js (App Router)
218
286
 
287
+ **1. Install dependencies:**
288
+
289
+ ```bash
290
+ npm install @mapvx/website-component @mapvx/website-component-helpers
291
+ ```
292
+
293
+ **2. Copy the bundle script to your `package.json`:**
294
+
295
+ ```json
296
+ {
297
+ "scripts": {
298
+ "copy-bundle": "node copy-bundle.mjs"
299
+ }
300
+ }
301
+ ```
302
+
303
+ **3. Create `copy-bundle.mjs` in your project root:**
304
+
305
+ ```javascript
306
+ #!/usr/bin/env node
307
+
308
+ import { existsSync, mkdirSync, copyFileSync } from 'fs'
309
+ import { join } from 'path'
310
+
311
+ const sourcePath = 'node_modules/@mapvx/website-component/dist/browser/main.js'
312
+ const targetDir = 'public/mapvx-website'
313
+ const targetPath = join(targetDir, 'bundle.js')
314
+
315
+ if (!existsSync(sourcePath)) {
316
+ console.error(`❌ Source file not found: ${sourcePath}`)
317
+ process.exit(1)
318
+ }
319
+
320
+ if (!existsSync(targetDir)) {
321
+ mkdirSync(targetDir, { recursive: true })
322
+ }
323
+
324
+ copyFileSync(sourcePath, targetPath)
325
+ console.log(`✅ Bundle copied successfully!`)
326
+ ```
327
+
328
+ **4. Create your page component:**
329
+
219
330
  ```typescript
220
331
  // app/page.tsx
221
332
  import { prepareInitialData } from '@mapvx/website-component-helpers';
333
+ import '@mapvx/website-component/dist/browser/styles.css';
334
+ import Script from 'next/script';
222
335
 
223
336
  export default async function HomePage() {
224
- // Execute on the server
225
- const initialData = await prepareInitialData(process.env.MAPVX_API_KEY!);
337
+ const initialData = await prepareInitialData(process.env.NEXT_PUBLIC_MAPVX_API_KEY || '');
226
338
 
227
339
  return (
228
340
  <div>
229
- <h1>My App</h1>
341
+ <Script src='/mapvx-website/bundle.js' />
230
342
  <mapvx-website
231
- api-key={process.env.MAPVX_API_KEY}
343
+ api-key={process.env.NEXT_PUBLIC_MAPVX_API_KEY}
344
+ institution-id={process.env.NEXT_PUBLIC_MAPVX_INSTITUTION_ID}
232
345
  initial-data={initialData}
233
346
  default-to-map="true"
234
347
  />
@@ -237,36 +350,18 @@ export default async function HomePage() {
237
350
  }
238
351
  ```
239
352
 
240
- #### Next.js (Pages Router)
353
+ **5. Set environment variables in `.env.local`:**
241
354
 
242
- ```typescript
243
- // pages/index.tsx
244
- import { GetServerSideProps } from 'next';
245
- import { prepareInitialData } from '@mapvx/website-component-helpers';
246
-
247
- export const getServerSideProps: GetServerSideProps = async () => {
248
- // Execute on the server
249
- const initialData = await prepareInitialData(process.env.MAPVX_API_KEY!);
355
+ ```bash
356
+ NEXT_PUBLIC_MAPVX_API_KEY=your-api-key-here
357
+ NEXT_PUBLIC_MAPVX_INSTITUTION_ID=your-institution-id
358
+ ```
250
359
 
251
- return {
252
- props: {
253
- initialData,
254
- },
255
- };
256
- };
360
+ **6. Run the copy script before building:**
257
361
 
258
- export default function HomePage({ initialData }: { initialData: string }) {
259
- return (
260
- <div>
261
- <h1>My App</h1>
262
- <mapvx-website
263
- api-key={process.env.MAPVX_API_KEY}
264
- initial-data={initialData}
265
- default-to-map="true"
266
- />
267
- </div>
268
- );
269
- }
362
+ ```bash
363
+ npm run copy-bundle
364
+ npm run build
270
365
  ```
271
366
 
272
367
  #### Nuxt.js
@@ -433,6 +528,36 @@ function App() {
433
528
  - The web component will automatically pick up these custom colors
434
529
  - Use valid CSS color values (hex, rgb, hsl, etc.)
435
530
 
531
+ ## 🔧 Troubleshooting
532
+
533
+ ### Common Issues
534
+
535
+ #### `SyntaxError: Unexpected token '<'` in Angular
536
+
537
+ **Problem**: Angular returns HTML instead of JavaScript files from `node_modules`.
538
+
539
+ **Solution**: Configure assets in `angular.json` as shown in the Angular Configuration section above.
540
+
541
+ #### Slow Loading (>10 seconds)
542
+
543
+ **Problem**: Large bundle size or incorrect asset serving.
544
+
545
+ **Solutions**:
546
+
547
+ - Use the recommended Angular assets configuration
548
+ - Ensure files are served as static assets, not through routing
549
+ - Check network tab in DevTools for 404 errors
550
+
551
+ #### Web Component Not Loading
552
+
553
+ **Problem**: Scripts not loading or component not registering.
554
+
555
+ **Solutions**:
556
+
557
+ - Verify file paths are correct
558
+ - Check browser console for errors
559
+ - Ensure `defer` attribute is used for script tags
560
+
436
561
  ## 🏠 Homepage
437
562
 
438
563
  Visit [MapVX](https://mapvx.com) for more information.