@rsltda/components 1.0.11
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 +73 -0
- package/custom-elements.json +54 -0
- package/dist/components/rs-hello.d.ts +4 -0
- package/dist/components/rs-map.d.ts +97 -0
- package/dist/index.d.ts +8 -0
- package/dist/rs-components.es.js +1145 -0
- package/dist/rs-components.es.js.map +1 -0
- package/dist/rs-components.iife.js +411 -0
- package/dist/rs-components.iife.js.map +1 -0
- package/dist/utils/define.d.ts +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @rsltda/components
|
|
2
|
+
|
|
3
|
+
Libreria de Web Components construida con Vite + TypeScript. El paquete expone principalmente el custom element `<rs-map>`, pensado para desplegar mapas de Google con puntos filtrables y panel lateral. El objetivo del `npm publish` es distribuir solo el bundle compilado (`dist/`) para poder reutilizar el componente via npm o CDN (jsDelivr) sin exponer el codigo fuente.
|
|
4
|
+
|
|
5
|
+
## Instalacion
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @rsltda/components
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Al instalar, el paquete ya incluye los bundles `rs-components.es.js` (ESM) y `rs-components.iife.js`, mas las declaraciones TypeScript generadas en `dist/index.d.ts`.
|
|
12
|
+
|
|
13
|
+
El paquete tambien publica `custom-elements.json`, lo que permite a herramientas compatibles ofrecer autocompletado y documentacion de atributos para `<rs-map>`.
|
|
14
|
+
|
|
15
|
+
## Uso rapido
|
|
16
|
+
|
|
17
|
+
### 1. Registrar el componente
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import "@rsltda/components/dist/rs-components.es.js";
|
|
21
|
+
// El bundle llama a safeDefine internamente, por lo que <rs-map> queda disponible en customElements.
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 2. Insertar en el DOM
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<rs-map
|
|
28
|
+
marca="ktm"
|
|
29
|
+
tipo="1"
|
|
30
|
+
height="600px"
|
|
31
|
+
google-maps-key="TU_KEY"
|
|
32
|
+
points-api-url="https://you.api.com/PuntosMapas"
|
|
33
|
+
cache-days="30"
|
|
34
|
+
marker-icon-base="https://you.cdn.com/marker/"
|
|
35
|
+
></rs-map>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Todos los valores sensibles se inyectan mediante atributos, de modo que el bundle publicado se mantiene agnostico de tus credenciales.
|
|
39
|
+
|
|
40
|
+
### 3. Consumo via jsDelivr
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@rsltda/components/dist/rs-components.es.js"></script>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Tras cargar el script anterior, puedes usar `<rs-map>` en cualquier sitio estatico sin necesidad de build tooling.
|
|
47
|
+
|
|
48
|
+
## Publicacion en npm
|
|
49
|
+
|
|
50
|
+
Este repositorio solo publica la carpeta `dist/` gracias a la combinacion de `files` en `package.json` y `.npmignore`. Antes de `npm publish`, ejecuta `npm run prepublishOnly`, lo cual dispara `vite build` y luego `tsc -p tsconfig.build.json` para asegurar que los bundles y los `.d.ts` esten actualizados.
|
|
51
|
+
|
|
52
|
+
## Atributos principales de `<rs-map>`
|
|
53
|
+
|
|
54
|
+
| Atributo | Descripcion |
|
|
55
|
+
| ------------------ | ---------------------------------------------------------------------------- |
|
|
56
|
+
| `marca` | String que determina filtros y colores (`ktm`, etc.). |
|
|
57
|
+
| `tipo` | `0`/`1` o `sucursal`/`distribuidor`. |
|
|
58
|
+
| `height` | Altura CSS del componente (`520px` por defecto). |
|
|
59
|
+
| `google-maps-key` | API key de Google Maps utilizada para cargar el script JS. |
|
|
60
|
+
| `points-api-url` | Endpoint que devuelve los puntos. Se le agregan query params `marca` y `tipo`. Por defecto usa `https://ap2.rs-shop.cl/web/PuntosMapas`. |
|
|
61
|
+
| `cache-days` | Dias que el componente considera vigente el cache local; por defecto `30`. |
|
|
62
|
+
| `marker-icon-base` | URL base para los iconos de los marcadores; se concatena con `<marca>.png`. Por defecto usa `https://cdn.rsltda.cl/logos/marker/`. |
|
|
63
|
+
| `marker-icon-default` | Icono a usar cuando no se definio `marker-icon-base`; si tampoco se provee, se usara el marcador estandar de Google. |
|
|
64
|
+
|
|
65
|
+
El componente es auto contenido: inyecta su propio Shadow DOM, maneja estados `loading/ready/error`, agrupa puntos por zona y sincroniza la lista lateral con el mapa.
|
|
66
|
+
|
|
67
|
+
## Estructura relevante
|
|
68
|
+
|
|
69
|
+
- `src/components/rs-map.ts`: componente completo con la logica de Google Maps, fetch y UI.
|
|
70
|
+
- `src/utils/define.ts`: helper `safeDefine` para evitar redefinir custom elements.
|
|
71
|
+
- `src/index.ts`: entry principal que registra `RsMap` y reexporta la clase.
|
|
72
|
+
|
|
73
|
+
Durante el build, Vite empaqueta `src/index.ts` siguiendo la configuracion de `vite.config.ts`, mientras que `tsconfig.build.json` genera las declaraciones de tipos en el mismo `dist/`. De esta forma, el paquete final listo para npm contiene unicamente artefactos compilados e ideales para distribuir de forma segura.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/webcomponents/custom-elements-manifest/main/schema.json",
|
|
3
|
+
"schemaVersion": "2.1.0",
|
|
4
|
+
"readme": "README.md",
|
|
5
|
+
"modules": [
|
|
6
|
+
{
|
|
7
|
+
"kind": "javascript-module",
|
|
8
|
+
"path": "src/components/rs-map.ts",
|
|
9
|
+
"declarations": [
|
|
10
|
+
{
|
|
11
|
+
"kind": "class",
|
|
12
|
+
"name": "RsMap",
|
|
13
|
+
"tagName": "rs-map",
|
|
14
|
+
"customElement": true,
|
|
15
|
+
"description": "Web component para mostrar un mapa de Google con puntos filtrados por marca y tipo, con cache local e interfaz lateral.",
|
|
16
|
+
"attributes": [
|
|
17
|
+
{
|
|
18
|
+
"name": "marca",
|
|
19
|
+
"description": "Marca usada para filtrar puntos y resolver color/icono del componente."
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"name": "tipo",
|
|
23
|
+
"description": "Tipo de punto: 0/1 o sucursal/distribuidor."
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "height",
|
|
27
|
+
"description": "Altura CSS del componente. Por defecto 520px."
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": "google-maps-key",
|
|
31
|
+
"description": "API key usada para cargar Google Maps JS."
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"name": "points-api-url",
|
|
35
|
+
"description": "Endpoint base de puntos. Por defecto usa https://ap2.rs-shop.cl/web/PuntosMapas."
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "cache-days",
|
|
39
|
+
"description": "Tiempo de vigencia del cache local en dias. Por defecto 30."
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "marker-icon-base",
|
|
43
|
+
"description": "URL base para iconos por marca. Por defecto usa https://cdn.rsltda.cl/logos/marker/ y concatena <marca>.png."
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "marker-icon-default",
|
|
47
|
+
"description": "Icono de respaldo cuando no se quiere usar la base por marca."
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export declare class RsMap extends HTMLElement {
|
|
2
|
+
static tag: string;
|
|
3
|
+
private static googleMapsLoaderPromise;
|
|
4
|
+
private static pointsCacheDbPromise;
|
|
5
|
+
private root;
|
|
6
|
+
private mapEl;
|
|
7
|
+
private map;
|
|
8
|
+
private markers;
|
|
9
|
+
private marca;
|
|
10
|
+
private marcaKey;
|
|
11
|
+
private tipo;
|
|
12
|
+
private tipoCode;
|
|
13
|
+
private pointsController?;
|
|
14
|
+
private points;
|
|
15
|
+
private pointsByZone;
|
|
16
|
+
private initialViewApplied;
|
|
17
|
+
private zonesContainer;
|
|
18
|
+
private componentMessageEl;
|
|
19
|
+
private mapLayoutEl;
|
|
20
|
+
private zoneButtons;
|
|
21
|
+
private nearestButton;
|
|
22
|
+
private panelTitleEl;
|
|
23
|
+
private activeZone;
|
|
24
|
+
private mapHeight;
|
|
25
|
+
private googleMapsApiKey;
|
|
26
|
+
private pointsApiUrl;
|
|
27
|
+
private markerIconBaseUrl;
|
|
28
|
+
private defaultMarkerIconUrl;
|
|
29
|
+
private pointsCacheTtlMs;
|
|
30
|
+
private static fontAwesomeAttached;
|
|
31
|
+
private panAnimationFrame;
|
|
32
|
+
private highlightTimeout;
|
|
33
|
+
private isSyncingInitialAttributes;
|
|
34
|
+
private refreshQueued;
|
|
35
|
+
static get observedAttributes(): string[];
|
|
36
|
+
constructor();
|
|
37
|
+
connectedCallback(): void;
|
|
38
|
+
disconnectedCallback(): void;
|
|
39
|
+
attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
|
|
40
|
+
private loadGoogleMaps;
|
|
41
|
+
private initMap;
|
|
42
|
+
private getInitialCenter;
|
|
43
|
+
private getFirstValidPoint;
|
|
44
|
+
private syncAttributesToState;
|
|
45
|
+
private setMapHeight;
|
|
46
|
+
private setGoogleMapsKey;
|
|
47
|
+
private setPointsApiUrl;
|
|
48
|
+
private setCacheDays;
|
|
49
|
+
private setMarkerIconBase;
|
|
50
|
+
private setDefaultMarkerIcon;
|
|
51
|
+
private setMarca;
|
|
52
|
+
private setTipo;
|
|
53
|
+
private queueRefreshPoints;
|
|
54
|
+
get marcaFilter(): string;
|
|
55
|
+
get tipoFilter(): string;
|
|
56
|
+
private updatePanelTitle;
|
|
57
|
+
private getTipoLabel;
|
|
58
|
+
private applyBrandColor;
|
|
59
|
+
private normalizeTipo;
|
|
60
|
+
private refreshPoints;
|
|
61
|
+
private applyPointsPayload;
|
|
62
|
+
private getPointsCacheKey;
|
|
63
|
+
private readPointsCache;
|
|
64
|
+
private writePointsCache;
|
|
65
|
+
private readPointsCacheFromIndexedDb;
|
|
66
|
+
private writePointsCacheToIndexedDb;
|
|
67
|
+
private static openPointsCacheDb;
|
|
68
|
+
private transformPoints;
|
|
69
|
+
private renderPoints;
|
|
70
|
+
private groupPoints;
|
|
71
|
+
private createPointCard;
|
|
72
|
+
private getZoneForPoint;
|
|
73
|
+
private normalizeRegionName;
|
|
74
|
+
private normalizeBrandKey;
|
|
75
|
+
private getMarkerIcon;
|
|
76
|
+
private updateMarkers;
|
|
77
|
+
private handleZoneButtonClick;
|
|
78
|
+
private setActiveZone;
|
|
79
|
+
private scrollToZoneSection;
|
|
80
|
+
private updateZoneButtons;
|
|
81
|
+
private updateZoneButtonCounts;
|
|
82
|
+
private updateZoneVisibility;
|
|
83
|
+
private handleNearestClick;
|
|
84
|
+
private findNearestPoint;
|
|
85
|
+
private haversine;
|
|
86
|
+
private scrollToPointCard;
|
|
87
|
+
private highlightPointCard;
|
|
88
|
+
private setComponentState;
|
|
89
|
+
private centerMapOnPoint;
|
|
90
|
+
private focusPointWithZoom;
|
|
91
|
+
private wait;
|
|
92
|
+
private animateZoomTo;
|
|
93
|
+
private animateMapPan;
|
|
94
|
+
private static ensureFontAwesome;
|
|
95
|
+
private createIconElement;
|
|
96
|
+
private getWhatsappLink;
|
|
97
|
+
}
|