@ -17,9 +17,9 @@ There are no tests in this project. To preview components locally, open `index.h
This library wraps [Leaflet.js](https://leafletjs.com/) as native Web Components (Custom Elements). Each HTML element maps 1:1 to a Leaflet object.
This library wraps [Leaflet.js](https://leafletjs.com/) as native Web Components (Custom Elements). Each HTML element maps 1:1 to a Leaflet object.
### `withProps` mixin: `src/core/with-props.ts`
### `WithProps` mixin: `src/core/with-props.ts`
The `withProps(Base, PROPS)` mixin factory replaces the old `LeafletElement` base class. Each component defines a `PROPS` table (a const record mapping kebab-case attribute names to `PropDef` descriptors), then extends `withProps(HTMLElement, PROPS)`. The mixin handles:
The `WithProps(Base, PROPS)` mixin factory replaces the old `LeafletElement` base class. Each component defines a `PROPS` table (a const record mapping kebab-case attribute names to `PropDef` descriptors), then extends `WithProps(HTMLElement, PROPS)`. The mixin handles:
- `observedAttributes` getter derived from the PROPS table keys.
- `observedAttributes` getter derived from the PROPS table keys.
- `definePropAccessors` — property getters/setters on the prototype that sync attributes.
- `definePropAccessors` — property getters/setters on the prototype that sync attributes.
@ -33,10 +33,10 @@ The `withProps(Base, PROPS)` mixin factory replaces the old `LeafletElement` bas
### Child component pattern
### Child component pattern
All non-map components extend `withProps(HTMLElement, PROPS)`. To add a new component:
All non-map components extend `WithProps(HTMLElement, PROPS)`. To add a new component:
1. Define a `PROPS = {...}` const table mapping kebab-case attributes to `PropDef` entries.
1. Define a `PROPS = {...}` const table mapping kebab-case attributes to `PropDef` entries.
3. Override `updateLeafletObject(name, val)` only if the default setter-based update won't work (common for coordinate pairs).
3. Override `updateLeafletObject(name, val)` only if the default setter-based update won't work (common for coordinate pairs).
4. Call `customElements.define('leaflet-foo', LeafletFoo)` at the bottom.
4. Call `customElements.define('leaflet-foo', LeafletFoo)` at the bottom.
5. Export from `src/index.ts`.
5. Export from `src/index.ts`.
@ -47,7 +47,7 @@ For components that accept children (layers, popups, tooltips), use the `registe
- **`leaflet-polygon`** uses `<leaflet-line>` children for vertices. The polygon collects lat/lng from child `leaflet-line` elements rather than having them as direct attributes.
- **`leaflet-polygon`** uses `<leaflet-line>` children for vertices. The polygon collects lat/lng from child `leaflet-line` elements rather than having them as direct attributes.
- **`leaflet-popup`** / **`leaflet-tooltip`**: content comes from `innerHTML`, not attributes. `leaflet-popup` watches for DOM mutations to keep Leaflet in sync.
- **`leaflet-popup`** / **`leaflet-tooltip`**: content comes from `innerHTML`, not attributes. `leaflet-popup` watches for DOM mutations to keep Leaflet in sync.
- **`leaflet-layer-group`** / **`leaflet-feature-group`**: passthrough containers extending `HTMLElement` directly (not via `withProps`). Children register themselves into them via the standard bubble mechanism.
- **`leaflet-layer-group`** / **`leaflet-feature-group`**: passthrough containers extending `HTMLElement` directly (not via `WithProps`). Children register themselves into them via the standard bubble mechanism.