@softwarity/geojson-editor 1.0.24 → 1.0.25
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 +168 -32
- package/dist/geojson-editor.js +2 -2
- package/package.json +9 -3
- package/src/constants.ts +0 -3
- package/src/geojson-editor.css +48 -43
- package/src/geojson-editor.ts +73 -83
- package/src/types.ts +0 -30
- package/themes/github.css +43 -0
- package/themes/monokai.css +43 -0
- package/themes/solarized.css +44 -0
- package/themes/vscode.css +43 -0
- package/types/types.d.ts +0 -28
package/README.md
CHANGED
|
@@ -71,7 +71,7 @@ A feature-rich, framework-agnostic **Web Component** for editing GeoJSON feature
|
|
|
71
71
|
- **Feature Visibility Toggle** - Hide/show individual Features via eye icon in gutter; hidden features are grayed out and excluded from `change` events (useful for temporary filtering without deleting data)
|
|
72
72
|
- **Color Picker** - Built-in color swatch for hex color properties (`#rrggbb`) displayed inline next to the value; click to open native color picker
|
|
73
73
|
- **Boolean Checkbox** - Inline checkbox for boolean properties displayed next to the value; toggle to switch between `true`/`false` and emit changes (e.g., `marker: true` to show vertices)
|
|
74
|
-
- **Dark/Light Color Schemes** - Automatic color scheme
|
|
74
|
+
- **Dark/Light Color Schemes** - Automatic color scheme based on system preference via CSS `light-dark()` function
|
|
75
75
|
- **Auto-format** - Automatic JSON formatting in real-time (always enabled)
|
|
76
76
|
- **Readonly Mode** - Visual indicator with diagonal stripes when editing is disabled
|
|
77
77
|
- **Block Editing in Collapsed Areas** - Prevents accidental edits in collapsed sections
|
|
@@ -82,6 +82,7 @@ A feature-rich, framework-agnostic **Web Component** for editing GeoJSON feature
|
|
|
82
82
|
- **Save to File** - Ctrl+S to download GeoJSON as `.geojson` file; programmatic `save(filename)` method available
|
|
83
83
|
- **Open from File** - Ctrl+O to open a `.geojson` or `.json` file from the client filesystem; programmatic `open()` method available
|
|
84
84
|
- **Error Navigation** - Visual error indicators in gutter with navigation buttons (◀ ▶) to jump between errors; error count displayed in suffix area
|
|
85
|
+
- **Current Feature Event** - `current-feature` event emitted when cursor enters/leaves a feature or editor gains/loses focus; useful for synchronizing with maps
|
|
85
86
|
|
|
86
87
|
## Installation
|
|
87
88
|
|
|
@@ -127,21 +128,18 @@ This package includes TypeScript type definitions out of the box. No additional
|
|
|
127
128
|
|
|
128
129
|
```typescript
|
|
129
130
|
import '@softwarity/geojson-editor';
|
|
130
|
-
import type { SetOptions,
|
|
131
|
+
import type { SetOptions, CursorPosition, GeometryType } from '@softwarity/geojson-editor';
|
|
131
132
|
|
|
132
133
|
// Type-safe editor access
|
|
133
134
|
const editor = document.querySelector('geojson-editor') as GeoJsonEditor;
|
|
134
135
|
|
|
135
136
|
// Full autocompletion and type checking
|
|
136
137
|
editor.set(features, { collapsed: ['coordinates'] });
|
|
137
|
-
editor.setTheme({ dark: { bgColor: '#1a1a1a' } });
|
|
138
138
|
```
|
|
139
139
|
|
|
140
140
|
**Exported types:**
|
|
141
141
|
- `GeoJsonEditor` - The Web Component class
|
|
142
142
|
- `SetOptions` - Options for `set()`, `add()`, `insertAt()`, `open()`
|
|
143
|
-
- `ThemeConfig` - Theme color configuration
|
|
144
|
-
- `ThemeSettings` - Dark/light color scheme settings
|
|
145
143
|
- `CursorPosition` - Cursor position `{ line, column }`
|
|
146
144
|
- `GeometryType` - GeoJSON geometry types union
|
|
147
145
|
|
|
@@ -164,10 +162,16 @@ editor.setTheme({ dark: { bgColor: '#1a1a1a' } });
|
|
|
164
162
|
|
|
165
163
|
Users edit features directly (comma-separated), and the component automatically wraps them in a `{"type": "FeatureCollection", "features": [...]}` structure for validation and events.
|
|
166
164
|
|
|
167
|
-
### With Theme
|
|
165
|
+
### With Theme Control
|
|
166
|
+
|
|
167
|
+
The component automatically adapts to system color scheme. Override with CSS:
|
|
168
168
|
|
|
169
169
|
```html
|
|
170
|
-
|
|
170
|
+
<!-- Force dark mode -->
|
|
171
|
+
<geojson-editor style="color-scheme: dark;"></geojson-editor>
|
|
172
|
+
|
|
173
|
+
<!-- Force light mode -->
|
|
174
|
+
<geojson-editor style="color-scheme: light;"></geojson-editor>
|
|
171
175
|
```
|
|
172
176
|
|
|
173
177
|
### Listen to Changes
|
|
@@ -194,20 +198,141 @@ editor.addEventListener('error', (e) => {
|
|
|
194
198
|
| `value` | `string` | `""` | Initial editor content (features array content) |
|
|
195
199
|
| `placeholder` | `string` | `""` | Placeholder text |
|
|
196
200
|
| `readonly` | `boolean` | `false` | Make editor read-only |
|
|
197
|
-
| `dark-selector` | `string` | `".dark"` | CSS selector for dark color scheme detection |
|
|
198
201
|
|
|
199
202
|
**Note:** `coordinates` nodes are automatically collapsed when content is loaded to improve readability. Use Enter to expand and Shift+Enter to collapse nodes, or click the gutter toggle. Use Tab/Shift+Tab to navigate between attributes.
|
|
200
203
|
|
|
201
|
-
###
|
|
204
|
+
### Themes
|
|
205
|
+
|
|
206
|
+
The component uses CSS `light-dark()` function for automatic dark/light mode switching based on the system's `color-scheme` preference.
|
|
207
|
+
|
|
208
|
+
#### Pre-built Themes
|
|
209
|
+
|
|
210
|
+
Ready-to-use theme CSS files are available:
|
|
211
|
+
|
|
212
|
+
| Theme | Description | CDN Link |
|
|
213
|
+
|-------|-------------|----------|
|
|
214
|
+
| **Default (IntelliJ)** | Built-in, no extra CSS needed | - |
|
|
215
|
+
| **VS Code** | Visual Studio Code inspired colors | [vscode.css](https://unpkg.com/@softwarity/geojson-editor/themes/vscode.css) |
|
|
216
|
+
| **GitHub** | GitHub's code styling | [github.css](https://unpkg.com/@softwarity/geojson-editor/themes/github.css) |
|
|
217
|
+
| **Monokai** | Classic dark Monokai palette | [monokai.css](https://unpkg.com/@softwarity/geojson-editor/themes/monokai.css) |
|
|
218
|
+
| **Solarized** | Ethan Schoonover's precision colors | [solarized.css](https://unpkg.com/@softwarity/geojson-editor/themes/solarized.css) |
|
|
219
|
+
|
|
220
|
+
**Using via CDN:**
|
|
221
|
+
```html
|
|
222
|
+
<!-- Include theme CSS before the component -->
|
|
223
|
+
<link rel="stylesheet" href="https://unpkg.com/@softwarity/geojson-editor/themes/monokai.css">
|
|
224
|
+
|
|
225
|
+
<!-- Then use the component -->
|
|
226
|
+
<script type="module" src="https://unpkg.com/@softwarity/geojson-editor"></script>
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Using via npm:**
|
|
230
|
+
```javascript
|
|
231
|
+
// Import theme CSS in your build
|
|
232
|
+
import '@softwarity/geojson-editor/themes/github.css';
|
|
233
|
+
import '@softwarity/geojson-editor';
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
#### Custom Themes
|
|
237
|
+
|
|
238
|
+
Create your own theme by overriding CSS custom properties on `:root` with the `light-dark()` function:
|
|
239
|
+
|
|
240
|
+
```css
|
|
241
|
+
:root {
|
|
242
|
+
/* Editor background and text */
|
|
243
|
+
--geojson-editor-bg-color: light-dark(#ffffff, #1e1e1e);
|
|
244
|
+
--geojson-editor-text-color: light-dark(#000000, #d4d4d4);
|
|
245
|
+
--geojson-editor-caret-color: light-dark(#000000, #aeafad);
|
|
246
|
+
|
|
247
|
+
/* Gutter (line numbers area) */
|
|
248
|
+
--geojson-editor-gutter-bg: light-dark(#f3f3f3, #1e1e1e);
|
|
249
|
+
--geojson-editor-gutter-border: light-dark(#e0e0e0, #333333);
|
|
250
|
+
--geojson-editor-gutter-text: light-dark(#237893, #858585);
|
|
251
|
+
|
|
252
|
+
/* JSON syntax highlighting */
|
|
253
|
+
--geojson-editor-json-key: light-dark(#0451a5, #9cdcfe);
|
|
254
|
+
--geojson-editor-json-string: light-dark(#a31515, #ce9178);
|
|
255
|
+
--geojson-editor-json-number: light-dark(#098658, #b5cea8);
|
|
256
|
+
--geojson-editor-json-boolean: light-dark(#0000ff, #569cd6);
|
|
257
|
+
--geojson-editor-json-punct: light-dark(#000000, #d4d4d4);
|
|
258
|
+
--geojson-editor-json-error: light-dark(#cd3131, #f44747);
|
|
259
|
+
|
|
260
|
+
/* GeoJSON-specific */
|
|
261
|
+
--geojson-editor-geojson-key: light-dark(#800000, #9cdcfe);
|
|
262
|
+
--geojson-editor-geojson-type: light-dark(#008000, #4ec9b0);
|
|
263
|
+
--geojson-editor-geojson-type-invalid: light-dark(#cd3131, #f44747);
|
|
264
|
+
|
|
265
|
+
/* Controls (checkboxes, color swatches) */
|
|
266
|
+
--geojson-editor-control-color: light-dark(#0000ff, #569cd6);
|
|
267
|
+
--geojson-editor-control-bg: light-dark(#f3f3f3, #3c3c3c);
|
|
268
|
+
--geojson-editor-control-border: light-dark(#c0c0c0, #6b6b6b);
|
|
269
|
+
|
|
270
|
+
/* Selection and errors */
|
|
271
|
+
--geojson-editor-selection-color: light-dark(rgba(173, 214, 255, 0.5), rgba(38, 79, 120, 0.5));
|
|
272
|
+
--geojson-editor-error-color: light-dark(#cd3131, #f44747);
|
|
273
|
+
}
|
|
274
|
+
```
|
|
202
275
|
|
|
203
|
-
|
|
276
|
+
#### Forcing Light or Dark Mode
|
|
204
277
|
|
|
205
|
-
|
|
278
|
+
```css
|
|
279
|
+
/* Force dark mode on specific editor */
|
|
280
|
+
geojson-editor.dark-editor {
|
|
281
|
+
color-scheme: dark;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/* Force light mode */
|
|
285
|
+
geojson-editor.light-editor {
|
|
286
|
+
color-scheme: light;
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
#### Integration with CSS Frameworks
|
|
206
291
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
292
|
+
The editor inherits `color-scheme` from parent elements. To integrate with frameworks that use class-based dark mode:
|
|
293
|
+
|
|
294
|
+
**Tailwind CSS** (uses `html.dark`):
|
|
295
|
+
```css
|
|
296
|
+
html.dark { color-scheme: dark; }
|
|
297
|
+
html:not(.dark) { color-scheme: light; }
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
**Bootstrap 5** (uses `[data-bs-theme]`):
|
|
301
|
+
```css
|
|
302
|
+
[data-bs-theme="dark"] { color-scheme: dark; }
|
|
303
|
+
[data-bs-theme="light"] { color-scheme: light; }
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
**DaisyUI / Other** (any class-based theme):
|
|
307
|
+
```css
|
|
308
|
+
.dark-theme { color-scheme: dark; }
|
|
309
|
+
.light-theme { color-scheme: light; }
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
#### CSS Custom Properties Reference
|
|
313
|
+
|
|
314
|
+
| Variable | Description |
|
|
315
|
+
|----------|-------------|
|
|
316
|
+
| `--geojson-editor-bg-color` | Editor background |
|
|
317
|
+
| `--geojson-editor-text-color` | Default text color |
|
|
318
|
+
| `--geojson-editor-caret-color` | Cursor color |
|
|
319
|
+
| `--geojson-editor-gutter-bg` | Line numbers background |
|
|
320
|
+
| `--geojson-editor-gutter-border` | Gutter border color |
|
|
321
|
+
| `--geojson-editor-gutter-text` | Line numbers color |
|
|
322
|
+
| `--geojson-editor-json-key` | JSON property keys |
|
|
323
|
+
| `--geojson-editor-json-string` | String values |
|
|
324
|
+
| `--geojson-editor-json-number` | Number values |
|
|
325
|
+
| `--geojson-editor-json-boolean` | Boolean/null values |
|
|
326
|
+
| `--geojson-editor-json-punct` | Punctuation (brackets, colons) |
|
|
327
|
+
| `--geojson-editor-json-error` | Invalid JSON highlighting |
|
|
328
|
+
| `--geojson-editor-geojson-key` | GeoJSON keywords (type, geometry, etc.) |
|
|
329
|
+
| `--geojson-editor-geojson-type` | Valid geometry types (Point, Polygon, etc.) |
|
|
330
|
+
| `--geojson-editor-geojson-type-invalid` | Invalid geometry types |
|
|
331
|
+
| `--geojson-editor-control-color` | Inline controls accent color |
|
|
332
|
+
| `--geojson-editor-control-bg` | Inline controls background |
|
|
333
|
+
| `--geojson-editor-control-border` | Inline controls border |
|
|
334
|
+
| `--geojson-editor-selection-color` | Text selection background |
|
|
335
|
+
| `--geojson-editor-error-color` | Error indicators |
|
|
211
336
|
|
|
212
337
|
## API Methods
|
|
213
338
|
|
|
@@ -310,22 +435,6 @@ const features = editor.getAll();
|
|
|
310
435
|
editor.emit();
|
|
311
436
|
```
|
|
312
437
|
|
|
313
|
-
### Theme API
|
|
314
|
-
|
|
315
|
-
```javascript
|
|
316
|
-
// Get current theme
|
|
317
|
-
const themes = editor.getTheme();
|
|
318
|
-
|
|
319
|
-
// Set custom theme (partial update)
|
|
320
|
-
editor.setTheme({
|
|
321
|
-
dark: { background: '#000', textColor: '#fff' },
|
|
322
|
-
light: { background: '#fff', textColor: '#000' }
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
// Reset to defaults
|
|
326
|
-
editor.resetTheme();
|
|
327
|
-
```
|
|
328
|
-
|
|
329
438
|
### Undo/Redo API
|
|
330
439
|
|
|
331
440
|
Full undo/redo support with action grouping:
|
|
@@ -522,9 +631,36 @@ editor.addEventListener('error', (e) => {
|
|
|
522
631
|
- Invalid types (e.g., `"LinearRing"`)
|
|
523
632
|
- Unknown types (any `type` value not in the GeoJSON specification)
|
|
524
633
|
|
|
634
|
+
### `current-feature`
|
|
635
|
+
|
|
636
|
+
Fired when the current feature changes. Useful for synchronizing the editor with a map display.
|
|
637
|
+
|
|
638
|
+
**Triggers:**
|
|
639
|
+
- Editor gains focus → emits current feature at cursor
|
|
640
|
+
- Cursor moves to a different feature → emits new feature
|
|
641
|
+
- Cursor moves outside any feature → emits `null`
|
|
642
|
+
- Editor loses focus → emits `null`
|
|
643
|
+
|
|
644
|
+
```javascript
|
|
645
|
+
editor.addEventListener('current-feature', (e) => {
|
|
646
|
+
const feature = e.detail; // Feature object or null
|
|
647
|
+
if (feature) {
|
|
648
|
+
// Highlight this feature on your map
|
|
649
|
+
highlightLayer.setData(feature);
|
|
650
|
+
} else {
|
|
651
|
+
// No current feature
|
|
652
|
+
highlightLayer.setData({ type: 'FeatureCollection', features: [] });
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
**Event detail:** The Feature object at the cursor position, or `null` if no feature is current.
|
|
658
|
+
|
|
659
|
+
**Note:** The event is only fired when the feature changes, not on every cursor movement within the same feature. This prevents excessive event firing during normal editing.
|
|
660
|
+
|
|
525
661
|
## Styling
|
|
526
662
|
|
|
527
|
-
The component uses Shadow DOM with CSS variables for theming.
|
|
663
|
+
The component uses Shadow DOM with CSS variables for theming. Customize colors via CSS custom properties (see [Theme Control](#theme-control)).
|
|
528
664
|
|
|
529
665
|
## Browser Support
|
|
530
666
|
|