@johnoscott/isometric-engine 0.9.0 → 0.10.1
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/EDITOR-GUIDE.md +43 -5
- package/README.md +1 -1
- package/assets/app.css +7 -3
- package/assets/marks.css +5 -1
- package/iso-editor.js +176 -176
- package/js/iso-editor/splice.js +3 -1
- package/js/iso-editor/ui/canvas.js +210 -12
- package/js/iso-editor/ui/setup.js +6 -2
- package/package.json +10 -1
- package/src/iso-editor/adapter.ts +19 -0
- package/src/iso-editor/index.ts +2 -2
- package/src/iso-editor/splice.ts +8 -3
- package/src/iso-editor/ui/app.css +2 -2
- package/src/iso-editor/ui/canvas.ts +173 -17
- package/src/iso-editor/ui/marks.css +5 -1
- package/src/iso-editor/ui/setup.ts +12 -3
- package/src/iso-objects/route.ts +1 -1
- package/types/iso-editor/adapter.d.ts +33 -0
- package/types/iso-editor/index.d.ts +2 -2
- package/types/iso-editor/ui/canvas.d.ts +36 -8
- package/types/iso-editor/ui/setup.d.ts +9 -0
- package/types/iso-objects/route.d.ts +1 -1
package/EDITOR-GUIDE.md
CHANGED
|
@@ -33,6 +33,9 @@ All of this comes from `@johnoscott/isometric-engine/editor`, namespace `editor`
|
|
|
33
33
|
- **The canvas**: your drawing in 3D, with selection, a marquee, pan and zoom, and pins (a dragged object is pinned in
|
|
34
34
|
the file). It also has a **2D view** that you opt into: the same drawing laid out flat, with a 3D | 2D switch.
|
|
35
35
|
- **The outline (tree)**, **properties** (from your JSON Schema), **problems**, **palette**, **menus** and **keys**.
|
|
36
|
+
- **Optional, when you say how** (0.10.0): palette **presets** (a box, a tray, a database… each starting as itself),
|
|
37
|
+
**connecting** two objects by dragging from one to the other, and **grouping** the selection into a new container.
|
|
38
|
+
Each writes the file as your adapter says, as one undo step.
|
|
36
39
|
- **`editor.mountEditor(element, options, setup)`**, which puts it all on a page, where `setup = editor.setupFor(adapter,
|
|
37
40
|
view)`.
|
|
38
41
|
|
|
@@ -196,14 +199,45 @@ export const boxesView = (theme: string): editor.DomainView<Boxes, editor.Canvas
|
|
|
196
199
|
});
|
|
197
200
|
```
|
|
198
201
|
|
|
199
|
-
|
|
202
|
+
### Presets, connecting and grouping (0.10.0)
|
|
200
203
|
|
|
201
|
-
|
|
202
|
-
user `~/.npmrc` (never in a repo):
|
|
204
|
+
Three optional pieces. Give one and the editor offers it; leave it out and nothing changes.
|
|
203
205
|
|
|
206
|
+
- **Palette presets**, on the view: `palette: [{ kind, label, icon?, value?, name? }]`. Each entry adds an object of
|
|
207
|
+
`kind` starting as a copy of `value` (default: the kind's `template()`), named from `name` (default: the kind's
|
|
208
|
+
singular). Without it, the palette has one entry per kind.
|
|
209
|
+
- **Connect**, on the adapter: `connect(from, to, data)` returns where a connection goes and what it is, `{ at, value }`
|
|
210
|
+
to add to a list (or with `name`, to a map under a fresh name), or `undefined` when those two don't connect. The
|
|
211
|
+
canvas then shows a handle on the one selected object: drag it to another (Esc cancels), or use **Connect to…** in
|
|
212
|
+
its menu and click the other.
|
|
213
|
+
- **Drop into** (0.10.1), on the adapter: `dropInto(target, value, kind, data)` returns the new thing's value inside
|
|
214
|
+
`target` (and words for it), or `undefined` when `target` doesn't hold it. A palette drop asks what is under it,
|
|
215
|
+
innermost first, and the first that holds it takes it; with none, the drop is pinned where it lands.
|
|
216
|
+
- **Group**, on the adapter: `group(members, data)` returns the new container (`at`, the base of its `name`, its
|
|
217
|
+
`value`) and `members(name)`, what changes in each member once it has a name. **Group** in the menu, or ⌘G, writes
|
|
218
|
+
it all as one step; members' pins are dropped, so the layout places them in their new container.
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
// boxes/1's: a link between two boxes (not twice), and the selection into a new zone in what they were all in
|
|
222
|
+
type Data = { boxes: Record<string, { in?: string }>; links?: { from: string; to: string }[] };
|
|
223
|
+
connect: (from, to, data) =>
|
|
224
|
+
(data as Data).links?.some(l => l.from === from.name && l.to === to.name) ? undefined
|
|
225
|
+
: { at: ['links'], value: { from: from.name, to: to.name } },
|
|
226
|
+
group: (members, data) => {
|
|
227
|
+
const ins = new Set(members.map(m => (data as Data).boxes[m.name]?.in));
|
|
228
|
+
return {
|
|
229
|
+
at: ['boxes'], name: 'group', value: { kind: 'zone', label: 'Group', ...(ins.size === 1 && [...ins][0] ? { in: [...ins][0] } : {}) },
|
|
230
|
+
members: name => members.map(m => ({ path: ['boxes', m.name, 'in'], value: name })),
|
|
231
|
+
};
|
|
232
|
+
},
|
|
233
|
+
// and on the view
|
|
234
|
+
palette: [
|
|
235
|
+
{ kind: 'boxes', label: 'Box', name: 'box', value: { size: [2, 2, 1] } },
|
|
236
|
+
{ kind: 'boxes', label: 'Tray', icon: 'layers', name: 'tray', value: { kind: 'tray', label: 'Tray' } },
|
|
237
|
+
],
|
|
204
238
|
```
|
|
205
|
-
|
|
206
|
-
|
|
239
|
+
|
|
240
|
+
## 3. A page
|
|
207
241
|
|
|
208
242
|
```
|
|
209
243
|
npm i @johnoscott/isometric-engine
|
|
@@ -271,6 +305,10 @@ Its `index.html` gives the editor a sized element: `<div id="app" style="height:
|
|
|
271
305
|
| a text pane beside the tree and canvas | your own pane on the `TextPane` interface (`editor.PaneOpts`), given as `setupFor`'s third argument, and Monaco in your bundle. The package ships none (Monaco is large); without one, the tree, canvas and properties make a complete editor |
|
|
272
306
|
| the 2D view | `view.flat` with `load: async () => editor.flatCanvas`, and `viewer.flatCss(styles)` in your canvas CSS |
|
|
273
307
|
| isodiag/1 YAML drawings | `/systems`: `systems.compile(yaml, theme)` (see the README) |
|
|
308
|
+
| palette presets (0.10.0) | `view.palette` |
|
|
309
|
+
| connecting by drag, Connect to… (0.10.0) | `adapter.connect` |
|
|
310
|
+
| Group, ⌘G (0.10.0) | `adapter.group` |
|
|
311
|
+
| a palette drop that lands inside a container (0.10.1) | `adapter.dropInto` |
|
|
274
312
|
|
|
275
313
|
## 5. Testing your adapter
|
|
276
314
|
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @johnoscott/isometric-engine 0.
|
|
1
|
+
# @johnoscott/isometric-engine 0.10.1
|
|
2
2
|
|
|
3
3
|
A generic isometric diagram engine: `@johnoscott/isometric-engine/render` (L0 core, L1 objects, L2 viewer)
|
|
4
4
|
and `@johnoscott/isometric-engine/editor` (the same, and L3 editor). Each exports one namespace per layer:
|
package/assets/app.css
CHANGED
|
@@ -217,8 +217,8 @@ body { position: relative; height: 100%; min-height: 0; font: var(--fw-regular)
|
|
|
217
217
|
}
|
|
218
218
|
/* E11: the palette, on the canvas: click to add, or drag onto the canvas */
|
|
219
219
|
@layer views {
|
|
220
|
-
.palette { position: absolute; left: var(--sp-3); top: var(--sp-3); display: flex; flex-direction: column; gap: 2px; padding: var(--sp-0); background: var(--surface); border: var(--bw) solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-1, none); z-index: 2; }
|
|
221
|
-
.pal-item { display: flex; align-items: center; gap: var(--sp-2); height: var(--ctl-sm); padding: 0 var(--sp-2); border: 0; border-radius: var(--r-sm); background: none; color: var(--ink-2); font: inherit; font-size: var(--fs-sm); cursor: grab; text-align: left; touch-action: none; user-select: none; }
|
|
220
|
+
.palette { position: absolute; left: var(--sp-3); top: var(--sp-3); display: flex; flex-direction: column; gap: 2px; padding: var(--sp-0); max-height: calc(100% - 2 * var(--sp-3) - 56px); overflow-y: auto; overscroll-behavior: contain; background: var(--surface); border: var(--bw) solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-1, none); z-index: 2; }
|
|
221
|
+
.pal-item { display: flex; flex-shrink: 0; align-items: center; gap: var(--sp-2); height: var(--ctl-sm); padding: 0 var(--sp-2); border: 0; border-radius: var(--r-sm); background: none; color: var(--ink-2); font: inherit; font-size: var(--fs-sm); cursor: grab; text-align: left; touch-action: none; user-select: none; }
|
|
222
222
|
.pal-item:hover { background: var(--state-hover); color: var(--ink); }
|
|
223
223
|
.pal-item:active { cursor: grabbing; }
|
|
224
224
|
.pal-item .icon { width: 14px; height: 14px; }
|
|
@@ -230,7 +230,7 @@ body.read-only .palette { display: none; }
|
|
|
230
230
|
|
|
231
231
|
/* The canvas's own marks over the drawing (0.7.4), for the plain words (setup.ts: the root .iso-canvas, the pan key's
|
|
232
232
|
class .pan-key): selection, hover, marquee, the drag's grid, drop target and edges,
|
|
233
|
-
problem badges, and the canvas's cursors. On the skin's tokens: --iso-sel* default to --accent, --iso-bad and
|
|
233
|
+
problem badges, the connect handle and line (0.10.0), and the canvas's cursors. On the skin's tokens: --iso-sel* default to --accent, --iso-bad and
|
|
234
234
|
--iso-warn to --bad and --warn; a host may set any of them on .iso-canvas. The package's assets/app.css carries
|
|
235
235
|
this file after the layout, and it ships alone as assets/marks.css. (A domain with its own words styles its own.)
|
|
236
236
|
Without any of it the marks are still harmless: the overlay's own attributes give no fill and take no pointer. */
|
|
@@ -257,6 +257,10 @@ body.read-only .palette { display: none; }
|
|
|
257
257
|
.iso-canvas .overlay .drop { fill: var(--iso-sel-fill); stroke: var(--iso-sel); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
|
|
258
258
|
.iso-canvas .overlay .drop.bad { fill: color-mix(in srgb, var(--iso-bad) 18%, transparent); stroke: var(--iso-bad); }
|
|
259
259
|
.iso-canvas .overlay .edge { fill: none; stroke: var(--iso-sel); stroke-width: 4; stroke-linecap: round; vector-effect: non-scaling-stroke; }
|
|
260
|
+
.iso-canvas .overlay .connect-handle { fill: var(--surface, #fff); stroke: var(--iso-sel); stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: all; cursor: crosshair; }
|
|
261
|
+
.iso-canvas .overlay .connect-handle:hover { fill: var(--iso-sel); }
|
|
262
|
+
.iso-canvas .overlay .connect-line { stroke: var(--iso-sel); stroke-width: 2; stroke-dasharray: 5 4; stroke-linecap: round; vector-effect: non-scaling-stroke; }
|
|
263
|
+
.iso-canvas .overlay .connect-line.ok { stroke-dasharray: none; }
|
|
260
264
|
.iso-canvas .overlay .badge circle { fill: var(--iso-bad); stroke: none; }
|
|
261
265
|
.iso-canvas .overlay .badge.warn circle { fill: var(--iso-warn); }
|
|
262
266
|
.iso-canvas .overlay .badge text { fill: #fff; stroke: none; font-family: system-ui, sans-serif; font-weight: 600; text-anchor: middle; dominant-baseline: central; }
|
package/assets/marks.css
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* The canvas's own marks over the drawing (0.7.4), for the plain words (setup.ts: the root .iso-canvas, the pan key's
|
|
2
2
|
class .pan-key): selection, hover, marquee, the drag's grid, drop target and edges,
|
|
3
|
-
problem badges, and the canvas's cursors. On the skin's tokens: --iso-sel* default to --accent, --iso-bad and
|
|
3
|
+
problem badges, the connect handle and line (0.10.0), and the canvas's cursors. On the skin's tokens: --iso-sel* default to --accent, --iso-bad and
|
|
4
4
|
--iso-warn to --bad and --warn; a host may set any of them on .iso-canvas. The package's assets/app.css carries
|
|
5
5
|
this file after the layout, and it ships alone as assets/marks.css. (A domain with its own words styles its own.)
|
|
6
6
|
Without any of it the marks are still harmless: the overlay's own attributes give no fill and take no pointer. */
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
.iso-canvas .overlay .drop { fill: var(--iso-sel-fill); stroke: var(--iso-sel); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
|
|
28
28
|
.iso-canvas .overlay .drop.bad { fill: color-mix(in srgb, var(--iso-bad) 18%, transparent); stroke: var(--iso-bad); }
|
|
29
29
|
.iso-canvas .overlay .edge { fill: none; stroke: var(--iso-sel); stroke-width: 4; stroke-linecap: round; vector-effect: non-scaling-stroke; }
|
|
30
|
+
.iso-canvas .overlay .connect-handle { fill: var(--surface, #fff); stroke: var(--iso-sel); stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: all; cursor: crosshair; }
|
|
31
|
+
.iso-canvas .overlay .connect-handle:hover { fill: var(--iso-sel); }
|
|
32
|
+
.iso-canvas .overlay .connect-line { stroke: var(--iso-sel); stroke-width: 2; stroke-dasharray: 5 4; stroke-linecap: round; vector-effect: non-scaling-stroke; }
|
|
33
|
+
.iso-canvas .overlay .connect-line.ok { stroke-dasharray: none; }
|
|
30
34
|
.iso-canvas .overlay .badge circle { fill: var(--iso-bad); stroke: none; }
|
|
31
35
|
.iso-canvas .overlay .badge.warn circle { fill: var(--iso-warn); }
|
|
32
36
|
.iso-canvas .overlay .badge text { fill: #fff; stroke: none; font-family: system-ui, sans-serif; font-weight: 600; text-anchor: middle; dominant-baseline: central; }
|