@orbat-mapper/tactical-draw 0.16.0 → 0.17.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/dist/index.d.mts +11 -0
- package/dist/index.mjs +198 -159
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1111,6 +1111,17 @@ interface GraphicEditSession<G extends Graphic = Graphic> {
|
|
|
1111
1111
|
onChange(listener: (event: GraphicEditChangeEvent<G>) => void): () => void;
|
|
1112
1112
|
onCommit(handler: (snapshot: GraphicSnapshot<G>) => void): () => void;
|
|
1113
1113
|
onSettled(handler: (reason: SettleReason) => void): () => void;
|
|
1114
|
+
/**
|
|
1115
|
+
* Present on point-symbol sessions: the continuous stream of a drag, for a
|
|
1116
|
+
* host that follows the symbol while it moves (a range ring, a viewshed).
|
|
1117
|
+
* `start` fires on the first move of a gesture, `move` on each one after,
|
|
1118
|
+
* and `end` exactly once per started gesture, before that gesture's
|
|
1119
|
+
* [[onChange]], or when the session settles mid-gesture. `points` holds the
|
|
1120
|
+
* one live position; `pointIndex` is `null`. A body, location or pin drag
|
|
1121
|
+
* moves it; a rotate or scale streams it unchanged. Returns an unsubscribe
|
|
1122
|
+
* function; registering after the session has settled returns a no-op.
|
|
1123
|
+
*/
|
|
1124
|
+
onTransientChange?(listener: (event: TransientChangeEvent) => void): () => void;
|
|
1114
1125
|
}
|
|
1115
1126
|
//#endregion
|
|
1116
1127
|
//#region src/tactical-draw/transform-session.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1085,6 +1085,37 @@ function createCommitEmitter(listenerErrorsMessage) {
|
|
|
1085
1085
|
}
|
|
1086
1086
|
};
|
|
1087
1087
|
}
|
|
1088
|
+
/**
|
|
1089
|
+
* A session's `onTransientChange` stream, with the latch its contract needs:
|
|
1090
|
+
* `start` opens a gesture's stream and no-ops while one is open, `end` closes
|
|
1091
|
+
* it and no-ops when none is, so `end` fires exactly once per started
|
|
1092
|
+
* gesture. `move` always passes through. `points` is copied per emission, so
|
|
1093
|
+
* a listener can't observe (or corrupt) the live working points.
|
|
1094
|
+
*/
|
|
1095
|
+
function createTransientStream(listenerErrorsMessage) {
|
|
1096
|
+
const emitter = createCommitEmitter(listenerErrorsMessage);
|
|
1097
|
+
let active = false;
|
|
1098
|
+
return {
|
|
1099
|
+
get active() {
|
|
1100
|
+
return active;
|
|
1101
|
+
},
|
|
1102
|
+
emit(phase, points, pointIndex) {
|
|
1103
|
+
if (phase === "start") {
|
|
1104
|
+
if (active) return;
|
|
1105
|
+
active = true;
|
|
1106
|
+
} else if (phase === "end") {
|
|
1107
|
+
if (!active) return;
|
|
1108
|
+
active = false;
|
|
1109
|
+
}
|
|
1110
|
+
emitter.emit({
|
|
1111
|
+
phase,
|
|
1112
|
+
points: points.map((p) => [...p]),
|
|
1113
|
+
pointIndex
|
|
1114
|
+
});
|
|
1115
|
+
},
|
|
1116
|
+
register: emitter.register
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1088
1119
|
//#endregion
|
|
1089
1120
|
//#region src/pin-presentation.ts
|
|
1090
1121
|
/** Nested settings, merged key by key rather than replaced by a patch. */
|
|
@@ -2281,6 +2312,80 @@ function createDeferredSnapResolver(getOptions) {
|
|
|
2281
2312
|
return deferred(request, signal);
|
|
2282
2313
|
};
|
|
2283
2314
|
}
|
|
2315
|
+
/** Internal controller seam: the deferred snaps of the drags of one edit. */
|
|
2316
|
+
function createDeferredDragSnap(provider, isSettled) {
|
|
2317
|
+
/** The drag's moves, numbered, and the newest whose answer landed. */
|
|
2318
|
+
let moves = 0;
|
|
2319
|
+
let landedMove = 0;
|
|
2320
|
+
/** Aborted once the drag is over or the edit settles. */
|
|
2321
|
+
let abort = null;
|
|
2322
|
+
/** The newest move's answer, and the pixel it was asked at, for a release
|
|
2323
|
+
* there to reuse; `settled` holds the answer once it has arrived. */
|
|
2324
|
+
let last = null;
|
|
2325
|
+
let releasing = false;
|
|
2326
|
+
/** Asks the host under the drag's signal, or null when it has no say. A
|
|
2327
|
+
* rejected answer counts as finding nothing. */
|
|
2328
|
+
function ask(request) {
|
|
2329
|
+
if (!request || !provider) return null;
|
|
2330
|
+
const { signal } = abort ??= new AbortController();
|
|
2331
|
+
const answer = provider(request, signal);
|
|
2332
|
+
return answer && {
|
|
2333
|
+
answer: answer.catch(() => null),
|
|
2334
|
+
signal
|
|
2335
|
+
};
|
|
2336
|
+
}
|
|
2337
|
+
function end() {
|
|
2338
|
+
abort?.abort();
|
|
2339
|
+
abort = null;
|
|
2340
|
+
last = null;
|
|
2341
|
+
}
|
|
2342
|
+
return {
|
|
2343
|
+
get releasing() {
|
|
2344
|
+
return releasing;
|
|
2345
|
+
},
|
|
2346
|
+
move(pixel, request, land) {
|
|
2347
|
+
const move = ++moves;
|
|
2348
|
+
const asked = ask(request);
|
|
2349
|
+
if (!asked) {
|
|
2350
|
+
landedMove = move;
|
|
2351
|
+
last = null;
|
|
2352
|
+
land(null);
|
|
2353
|
+
return;
|
|
2354
|
+
}
|
|
2355
|
+
const { answer, signal } = asked;
|
|
2356
|
+
const entry = {
|
|
2357
|
+
pixel: [...pixel],
|
|
2358
|
+
answer
|
|
2359
|
+
};
|
|
2360
|
+
last = entry;
|
|
2361
|
+
answer.then((position) => {
|
|
2362
|
+
entry.settled = { position };
|
|
2363
|
+
if (isSettled() || signal.aborted || move < landedMove) return;
|
|
2364
|
+
landedMove = move;
|
|
2365
|
+
land(position);
|
|
2366
|
+
});
|
|
2367
|
+
},
|
|
2368
|
+
release(pixel, request) {
|
|
2369
|
+
if (last && last.pixel[0] === pixel[0] && last.pixel[1] === pixel[1]) return last.settled ? last.settled.position : last.answer;
|
|
2370
|
+
return ask(request)?.answer ?? null;
|
|
2371
|
+
},
|
|
2372
|
+
finish(released, finish) {
|
|
2373
|
+
if (!(released instanceof Promise)) {
|
|
2374
|
+
end();
|
|
2375
|
+
finish(released);
|
|
2376
|
+
return;
|
|
2377
|
+
}
|
|
2378
|
+
releasing = true;
|
|
2379
|
+
released.then((value) => {
|
|
2380
|
+
releasing = false;
|
|
2381
|
+
if (isSettled()) return;
|
|
2382
|
+
end();
|
|
2383
|
+
finish(value);
|
|
2384
|
+
});
|
|
2385
|
+
},
|
|
2386
|
+
end
|
|
2387
|
+
};
|
|
2388
|
+
}
|
|
2284
2389
|
/** Resolve a draw-interaction map event through `snap`, falling back to the event coordinate. */
|
|
2285
2390
|
function snappedDrawPosition(snap, event) {
|
|
2286
2391
|
return snap?.({
|
|
@@ -4493,35 +4598,7 @@ function runEdit(opts) {
|
|
|
4493
4598
|
});
|
|
4494
4599
|
const commitEmitter = createCommitEmitter("EditSession.onCommit listener errors");
|
|
4495
4600
|
const settleEmitter = createSettleEmitter("EditSession.onSettled listener errors");
|
|
4496
|
-
const
|
|
4497
|
-
/**
|
|
4498
|
-
* Latch for the "start"/"end" pairing `emitTransient` enforces: `start`
|
|
4499
|
-
* no-ops (and doesn't re-latch) while a gesture is already open; `end`
|
|
4500
|
-
* no-ops when there is no open gesture. `move` always passes through — the
|
|
4501
|
-
* latch only guards against a duplicate/missing bookend, per the
|
|
4502
|
-
* `onTransientChange` contract (`end` fires exactly once per started
|
|
4503
|
-
* gesture).
|
|
4504
|
-
*/
|
|
4505
|
-
let transientGestureActive = false;
|
|
4506
|
-
/**
|
|
4507
|
-
* Emit one tick of the `EditSession.onTransientChange` stream. `points` is
|
|
4508
|
-
* defensively copied so a listener can't observe (or corrupt) the live
|
|
4509
|
-
* working-point array.
|
|
4510
|
-
*/
|
|
4511
|
-
function emitTransient(phase, points, pointIndex) {
|
|
4512
|
-
if (phase === "start") {
|
|
4513
|
-
if (transientGestureActive) return;
|
|
4514
|
-
transientGestureActive = true;
|
|
4515
|
-
} else if (phase === "end") {
|
|
4516
|
-
if (!transientGestureActive) return;
|
|
4517
|
-
transientGestureActive = false;
|
|
4518
|
-
}
|
|
4519
|
-
transientEmitter.emit({
|
|
4520
|
-
phase,
|
|
4521
|
-
points: points.map((p) => [...p]),
|
|
4522
|
-
pointIndex
|
|
4523
|
-
});
|
|
4524
|
-
}
|
|
4601
|
+
const transient = createTransientStream("EditSession.onTransientChange listener errors");
|
|
4525
4602
|
/**
|
|
4526
4603
|
* The transform box's rotation, in radians, session-scoped (ADR-0017 decision
|
|
4527
4604
|
* #2): starts at `0` (axis-aligned) and accumulates every committed rotate
|
|
@@ -5228,7 +5305,7 @@ function runEdit(opts) {
|
|
|
5228
5305
|
},
|
|
5229
5306
|
onTransientChange(listener) {
|
|
5230
5307
|
if (ctx.settled) return () => {};
|
|
5231
|
-
return
|
|
5308
|
+
return transient.register(listener);
|
|
5232
5309
|
}
|
|
5233
5310
|
};
|
|
5234
5311
|
let activeDrag = null;
|
|
@@ -5294,27 +5371,7 @@ function runEdit(opts) {
|
|
|
5294
5371
|
target: targetAt(snapped)
|
|
5295
5372
|
};
|
|
5296
5373
|
}
|
|
5297
|
-
|
|
5298
|
-
let deferredMoves = 0;
|
|
5299
|
-
let landedMove = 0;
|
|
5300
|
-
/** Aborted once the drag is over or the edit settles. */
|
|
5301
|
-
let deferredAbort = null;
|
|
5302
|
-
/** The newest move's answer, and the pixel it was asked at, for a release
|
|
5303
|
-
* there to reuse; `settled` holds the answer once it has arrived. */
|
|
5304
|
-
let lastDeferred = null;
|
|
5305
|
-
/**
|
|
5306
|
-
* Asks `sources.deferred` where `target` lands, under the drag's signal, or
|
|
5307
|
-
* null when the host has no say. A rejected answer counts as finding nothing.
|
|
5308
|
-
*/
|
|
5309
|
-
function askDeferred(target) {
|
|
5310
|
-
if (!target || !deferredSnap) return null;
|
|
5311
|
-
const { signal } = deferredAbort ??= new AbortController();
|
|
5312
|
-
const answer = deferredSnap(target.request, signal);
|
|
5313
|
-
return answer && {
|
|
5314
|
-
answer: answer.catch(() => null),
|
|
5315
|
-
signal
|
|
5316
|
-
};
|
|
5317
|
-
}
|
|
5374
|
+
const deferred = createDeferredDragSnap(deferredSnap, () => ctx.settled);
|
|
5318
5375
|
/** The drag pixel an answer for `target` puts a drag at `pixel` at:
|
|
5319
5376
|
* `pixel` itself when the host found nothing. */
|
|
5320
5377
|
function landedDragPixel(pixel, target, position) {
|
|
@@ -5326,65 +5383,16 @@ function runEdit(opts) {
|
|
|
5326
5383
|
* say in `target`, otherwise when its answer lands.
|
|
5327
5384
|
*/
|
|
5328
5385
|
function moveDeferred(pixel, target, paint) {
|
|
5329
|
-
|
|
5330
|
-
const asked = askDeferred(target);
|
|
5331
|
-
if (!asked) {
|
|
5332
|
-
landedMove = move;
|
|
5333
|
-
lastDeferred = null;
|
|
5334
|
-
paint(pixel);
|
|
5335
|
-
return;
|
|
5336
|
-
}
|
|
5337
|
-
const { answer, signal } = asked;
|
|
5338
|
-
const last = {
|
|
5339
|
-
pixel,
|
|
5340
|
-
answer
|
|
5341
|
-
};
|
|
5342
|
-
lastDeferred = last;
|
|
5343
|
-
answer.then((position) => {
|
|
5344
|
-
last.settled = { position };
|
|
5345
|
-
if (ctx.settled || signal.aborted || move < landedMove) return;
|
|
5346
|
-
landedMove = move;
|
|
5347
|
-
paint(landedDragPixel(pixel, target, position));
|
|
5348
|
-
});
|
|
5386
|
+
deferred.move(pixel, target?.request ?? null, (position) => paint(target ? landedDragPixel(pixel, target, position) : pixel));
|
|
5349
5387
|
}
|
|
5350
5388
|
/**
|
|
5351
|
-
* What a release at `pixel` waits for:
|
|
5352
|
-
*
|
|
5353
|
-
* a promise of one while it is on its way.
|
|
5389
|
+
* What a release at `pixel` waits for: a drag pixel when it is known now,
|
|
5390
|
+
* a promise of one while the host's answer is on its way.
|
|
5354
5391
|
*/
|
|
5355
5392
|
function releaseDeferred(pixel, target) {
|
|
5356
5393
|
if (!target) return pixel;
|
|
5357
|
-
const
|
|
5358
|
-
|
|
5359
|
-
if (last.settled) return landedDragPixel(pixel, target, last.settled.position);
|
|
5360
|
-
return last.answer.then((position) => landedDragPixel(pixel, target, position));
|
|
5361
|
-
}
|
|
5362
|
-
const asked = askDeferred(target);
|
|
5363
|
-
if (!asked) return pixel;
|
|
5364
|
-
return asked.answer.then((position) => landedDragPixel(pixel, target, position));
|
|
5365
|
-
}
|
|
5366
|
-
/** Done with the drag's deferred snaps: aborts any still on their way. */
|
|
5367
|
-
function endDeferred() {
|
|
5368
|
-
deferredAbort?.abort();
|
|
5369
|
-
deferredAbort = null;
|
|
5370
|
-
lastDeferred = null;
|
|
5371
|
-
}
|
|
5372
|
-
/**
|
|
5373
|
-
* Finishes a released drag at the pixel `released` gives, at once or once
|
|
5374
|
-
* its answer arrives; the drag stays in flight meanwhile, so no other
|
|
5375
|
-
* gesture starts. An edit settled in between drops it.
|
|
5376
|
-
*/
|
|
5377
|
-
function finishRelease(released, finish) {
|
|
5378
|
-
if (!(released instanceof Promise)) {
|
|
5379
|
-
endDeferred();
|
|
5380
|
-
finish(released);
|
|
5381
|
-
return;
|
|
5382
|
-
}
|
|
5383
|
-
released.then((pixel) => {
|
|
5384
|
-
if (ctx.settled) return;
|
|
5385
|
-
endDeferred();
|
|
5386
|
-
finish(pixel);
|
|
5387
|
-
});
|
|
5394
|
+
const released = deferred.release(pixel, target.request);
|
|
5395
|
+
return released instanceof Promise ? released.then((position) => landedDragPixel(pixel, target, position)) : landedDragPixel(pixel, target, released);
|
|
5388
5396
|
}
|
|
5389
5397
|
/**
|
|
5390
5398
|
* A live transform-box gesture (corner scale, box rotate, or body
|
|
@@ -5486,7 +5494,7 @@ function runEdit(opts) {
|
|
|
5486
5494
|
preDragOptions: workingOptions,
|
|
5487
5495
|
preDragNonGeometryDirty: nonGeometryDirty
|
|
5488
5496
|
};
|
|
5489
|
-
|
|
5497
|
+
transient.emit("start", workingPoints, null);
|
|
5490
5498
|
dragInFlight = true;
|
|
5491
5499
|
driver.setDragPanEnabled(false);
|
|
5492
5500
|
return;
|
|
@@ -5505,7 +5513,7 @@ function runEdit(opts) {
|
|
|
5505
5513
|
preDragOptions: workingOptions,
|
|
5506
5514
|
controlPointIndex: hit.kind === "geometry" ? null : hit.kind === "midpoint" ? hit.index + 1 : hit.index
|
|
5507
5515
|
};
|
|
5508
|
-
|
|
5516
|
+
transient.emit("start", fsm.kind === "midpoint" ? initialPoints : preDragPoints, activeDrag.controlPointIndex);
|
|
5509
5517
|
if (fsm.kind === "midpoint") {
|
|
5510
5518
|
followVertexChange({
|
|
5511
5519
|
type: "insert",
|
|
@@ -5548,7 +5556,7 @@ function runEdit(opts) {
|
|
|
5548
5556
|
},
|
|
5549
5557
|
preDragOptions
|
|
5550
5558
|
};
|
|
5551
|
-
|
|
5559
|
+
transient.emit("start", preDragPoints, null);
|
|
5552
5560
|
dragInFlight = true;
|
|
5553
5561
|
driver.setDragPanEnabled(false);
|
|
5554
5562
|
}
|
|
@@ -5567,7 +5575,7 @@ function runEdit(opts) {
|
|
|
5567
5575
|
renderWorkingGraphic();
|
|
5568
5576
|
renderHandlesLayer();
|
|
5569
5577
|
recomputeDirty();
|
|
5570
|
-
|
|
5578
|
+
transient.emit("move", snapshot.points, activeDrag.controlPointIndex);
|
|
5571
5579
|
}
|
|
5572
5580
|
function paintOptionDragSnapshot(pixel) {
|
|
5573
5581
|
if (!activeOptionDrag) return;
|
|
@@ -5578,7 +5586,7 @@ function runEdit(opts) {
|
|
|
5578
5586
|
renderWorkingGraphic();
|
|
5579
5587
|
renderHandlesLayer();
|
|
5580
5588
|
recomputeDirty();
|
|
5581
|
-
|
|
5589
|
+
transient.emit("move", workingPoints, null);
|
|
5582
5590
|
}
|
|
5583
5591
|
/**
|
|
5584
5592
|
* Fold a box gesture's delta (the box `to` relative to `from`, given the
|
|
@@ -5628,7 +5636,7 @@ function runEdit(opts) {
|
|
|
5628
5636
|
renderWorkingGraphic();
|
|
5629
5637
|
renderHandlesLayer();
|
|
5630
5638
|
recomputeDirty();
|
|
5631
|
-
|
|
5639
|
+
transient.emit("move", activeBoxDrag.preDragPoints, null);
|
|
5632
5640
|
return;
|
|
5633
5641
|
}
|
|
5634
5642
|
workingPoints.splice(0, workingPoints.length, ...snapshot.points);
|
|
@@ -5636,7 +5644,7 @@ function runEdit(opts) {
|
|
|
5636
5644
|
renderWorkingGraphic();
|
|
5637
5645
|
renderHandlesLayer();
|
|
5638
5646
|
recomputeDirty();
|
|
5639
|
-
|
|
5647
|
+
transient.emit("move", snapshot.points, null);
|
|
5640
5648
|
}
|
|
5641
5649
|
const onDriverMove = (pixel, info) => {
|
|
5642
5650
|
if (ctx.settled) return;
|
|
@@ -5680,7 +5688,7 @@ function runEdit(opts) {
|
|
|
5680
5688
|
activeOptionDrag = null;
|
|
5681
5689
|
driver.setDragPanEnabled(true);
|
|
5682
5690
|
const nextOptions = optionsForOptionHandle(driver.fromPixel(pixel), drag);
|
|
5683
|
-
|
|
5691
|
+
transient.emit("end", workingPoints, null);
|
|
5684
5692
|
replaceWorkingOptions(drag.preDragOptions);
|
|
5685
5693
|
nonGeometryDirty = drag.preDragNonGeometryDirty;
|
|
5686
5694
|
dragInFlight = false;
|
|
@@ -5695,7 +5703,7 @@ function runEdit(opts) {
|
|
|
5695
5703
|
}
|
|
5696
5704
|
if (activeDrag) {
|
|
5697
5705
|
if (ctx.settled) {
|
|
5698
|
-
|
|
5706
|
+
transient.emit("end", workingPoints, activeDrag.controlPointIndex);
|
|
5699
5707
|
activeDrag = null;
|
|
5700
5708
|
dragInFlight = false;
|
|
5701
5709
|
driver.setDragPanEnabled(true);
|
|
@@ -5705,9 +5713,9 @@ function runEdit(opts) {
|
|
|
5705
5713
|
activeDrag = null;
|
|
5706
5714
|
driver.setDragPanEnabled(true);
|
|
5707
5715
|
const snapped = snapDrag(pixel, (at) => reshapeTarget(at, info, controlPointIndex));
|
|
5708
|
-
|
|
5716
|
+
deferred.finish(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
|
|
5709
5717
|
const next = fsm.end(finalPixel, { constrainAngles: info?.shiftKey });
|
|
5710
|
-
|
|
5718
|
+
transient.emit("end", next, controlPointIndex);
|
|
5711
5719
|
replaceWorkingPoints(preDragPoints);
|
|
5712
5720
|
commitGesture(next, preDragOptions);
|
|
5713
5721
|
});
|
|
@@ -5715,7 +5723,7 @@ function runEdit(opts) {
|
|
|
5715
5723
|
}
|
|
5716
5724
|
if (activeBoxDrag) {
|
|
5717
5725
|
if (ctx.settled) {
|
|
5718
|
-
|
|
5726
|
+
transient.emit("end", workingPoints, null);
|
|
5719
5727
|
activeBoxDrag = null;
|
|
5720
5728
|
dragInFlight = false;
|
|
5721
5729
|
driver.setDragPanEnabled(true);
|
|
@@ -5725,10 +5733,10 @@ function runEdit(opts) {
|
|
|
5725
5733
|
activeBoxDrag = null;
|
|
5726
5734
|
driver.setDragPanEnabled(true);
|
|
5727
5735
|
if (fsm.kind === "body" && withinClickSlop(pixel, downPixel)) {
|
|
5728
|
-
|
|
5736
|
+
deferred.end();
|
|
5729
5737
|
replaceWorkingPoints(preDragPoints);
|
|
5730
5738
|
workingAmplifierPlacements = preDragAmplifierPlacements;
|
|
5731
|
-
|
|
5739
|
+
transient.emit("end", preDragPoints, null);
|
|
5732
5740
|
renderWorkingGraphic();
|
|
5733
5741
|
renderHandlesLayer();
|
|
5734
5742
|
recomputeDirty();
|
|
@@ -5742,7 +5750,7 @@ function runEdit(opts) {
|
|
|
5742
5750
|
downPixel
|
|
5743
5751
|
};
|
|
5744
5752
|
const snapped = snapDrag(pixel, (at) => translateTarget(at, info, drag));
|
|
5745
|
-
|
|
5753
|
+
deferred.finish(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
|
|
5746
5754
|
const finalSnapshot = fsm.move(finalPixel, { constrainRotation: info?.shiftKey });
|
|
5747
5755
|
replaceWorkingPoints(preDragPoints);
|
|
5748
5756
|
workingAmplifierPlacements = preDragAmplifierPlacements;
|
|
@@ -5754,7 +5762,7 @@ function runEdit(opts) {
|
|
|
5754
5762
|
nonGeometryDirty = true;
|
|
5755
5763
|
}
|
|
5756
5764
|
const committedPoints = optionFold && holdsAnchorOnFold ? preDragPoints : finalSnapshot.points;
|
|
5757
|
-
|
|
5765
|
+
transient.emit("end", committedPoints, null);
|
|
5758
5766
|
commitGesture(committedPoints, preDragOptions, transformAmplifierPlacements(preDragAmplifierPlacements, preDragBox, finalSnapshot.box, driver), preDragBox.angle);
|
|
5759
5767
|
});
|
|
5760
5768
|
return;
|
|
@@ -5769,7 +5777,7 @@ function runEdit(opts) {
|
|
|
5769
5777
|
handlesLayer,
|
|
5770
5778
|
closeOnClickAway,
|
|
5771
5779
|
onBeforeTeardown: (settlement) => {
|
|
5772
|
-
|
|
5780
|
+
deferred.end();
|
|
5773
5781
|
settleToGraphics(settlement.status === "committed" ? settlement.value.graphic : void 0);
|
|
5774
5782
|
},
|
|
5775
5783
|
onViewChange: rescaleOnViewChange,
|
|
@@ -5786,7 +5794,7 @@ function runEdit(opts) {
|
|
|
5786
5794
|
emitSettle: (settlement) => settleFromInteraction(settlement, commitEmitter, settleEmitter),
|
|
5787
5795
|
extraTeardown: () => {
|
|
5788
5796
|
if (activeDrag !== null || activeOptionDrag !== null || activeBoxDrag !== null || labels.dragging) {
|
|
5789
|
-
|
|
5797
|
+
transient.emit("end", workingPoints, activeDrag?.controlPointIndex ?? null);
|
|
5790
5798
|
driver.setDragPanEnabled(true);
|
|
5791
5799
|
activeDrag = null;
|
|
5792
5800
|
activeOptionDrag = null;
|
|
@@ -7322,7 +7330,7 @@ function symbolBox(adapter, symbol, rendered, padding = 0) {
|
|
|
7322
7330
|
};
|
|
7323
7331
|
}
|
|
7324
7332
|
function runPointSymbolEdit(opts) {
|
|
7325
|
-
const { adapter, capability, symbol, graphicsLayer, previewLayer, handlesLayer, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, settleToGraphics, publishWorkingGraphic, wasOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap } = opts;
|
|
7333
|
+
const { adapter, capability, symbol, graphicsLayer, previewLayer, handlesLayer, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, settleToGraphics, publishWorkingGraphic, wasOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap, deferredSnap } = opts;
|
|
7326
7334
|
let modes = normalisePointModes(opts.modes ?? (symbol.offset ? ["transform", "offset"] : ["transform"]));
|
|
7327
7335
|
let usesGraphicStack = wasOnGraphicsLayer;
|
|
7328
7336
|
let pinEditing = !!opts.renderPin && opts.modes === void 0;
|
|
@@ -7343,6 +7351,9 @@ function runPointSymbolEdit(opts) {
|
|
|
7343
7351
|
});
|
|
7344
7352
|
const commitEmitter = createCommitEmitter("GraphicEditSession.onCommit listener errors");
|
|
7345
7353
|
const settleEmitter = createSettleEmitter("GraphicEditSession.onSettled listener errors");
|
|
7354
|
+
const transient = createTransientStream("GraphicEditSession.onTransientChange listener errors");
|
|
7355
|
+
/** Emit one tick of the `onTransientChange` stream, at `position`. */
|
|
7356
|
+
const emitTransient = (phase, position) => transient.emit(phase, [position], null);
|
|
7346
7357
|
const captureHistory = () => ({ working: clonePointSymbol(working) });
|
|
7347
7358
|
const cloneHistory = (value) => ({ working: clonePointSymbol(value.working) });
|
|
7348
7359
|
const snapshot = () => ({
|
|
@@ -7530,16 +7541,22 @@ function runPointSymbolEdit(opts) {
|
|
|
7530
7541
|
},
|
|
7531
7542
|
onSettled(listener) {
|
|
7532
7543
|
return settleEmitter.register(listener);
|
|
7544
|
+
},
|
|
7545
|
+
onTransientChange(listener) {
|
|
7546
|
+
if (ctx.settled) return () => {};
|
|
7547
|
+
return transient.register(listener);
|
|
7533
7548
|
}
|
|
7534
7549
|
};
|
|
7535
|
-
const
|
|
7550
|
+
const translateRequest = (position, fallbackPixel, info) => ({
|
|
7536
7551
|
coordinate: position,
|
|
7537
7552
|
pixel: driver.toPixel(position) ?? fallbackPixel,
|
|
7538
7553
|
interaction: "translate",
|
|
7539
7554
|
graphicId: symbol.id,
|
|
7540
7555
|
originalEvent: info?.native
|
|
7541
|
-
})
|
|
7556
|
+
});
|
|
7557
|
+
const snapTranslate = (position, fallbackPixel, info) => snap?.(translateRequest(position, fallbackPixel, info))?.coordinate ?? position;
|
|
7542
7558
|
const onDown = (pixel, info) => {
|
|
7559
|
+
if (deferred.releasing) return;
|
|
7543
7560
|
if (pinEditing && opts.canRenderPin?.() && !ctx.settled) {
|
|
7544
7561
|
const footprint = adapter.getPinFootprint?.(working.id);
|
|
7545
7562
|
if (footprint && adapter.pickPin?.(working.id, pixel, info?.hitTolerance ?? 12)) {
|
|
@@ -7585,16 +7602,24 @@ function runPointSymbolEdit(opts) {
|
|
|
7585
7602
|
};
|
|
7586
7603
|
driver.setDragPanEnabled(false);
|
|
7587
7604
|
};
|
|
7588
|
-
|
|
7605
|
+
/** Where a translate or pin drag at `pixel` moves the symbol's position,
|
|
7606
|
+
* snapped at once; null for any other drag. */
|
|
7607
|
+
const translatedPosition = (pixel, info) => {
|
|
7589
7608
|
if (pinDrag) {
|
|
7590
7609
|
const attachment = [pinDrag.attachment[0] + pixel[0] - pinDrag.down[0], pinDrag.attachment[1] + pixel[1] - pinDrag.down[1]];
|
|
7591
7610
|
const position = adapter.movePinFromPixel?.(working.id, attachment);
|
|
7592
|
-
|
|
7593
|
-
return {
|
|
7594
|
-
...clonePointSymbol(pinDrag.start),
|
|
7595
|
-
position: snapTranslate(position, attachment, info)
|
|
7596
|
-
};
|
|
7611
|
+
return position ? snapTranslate(position, attachment, info) : null;
|
|
7597
7612
|
}
|
|
7613
|
+
if (!drag || !(drag.kind === "location" || drag.kind === "body" && !drag.offsetMode)) return null;
|
|
7614
|
+
return snapTranslate(driver.fromPixel([drag.anchor[0] + pixel[0] - drag.down[0], drag.anchor[1] + pixel[1] - drag.down[1]]), pixel, info);
|
|
7615
|
+
};
|
|
7616
|
+
/** The symbol as the drag at `pixel` leaves it; `position`, where a
|
|
7617
|
+
* translate or pin drag put it, when already known. */
|
|
7618
|
+
const transformed = (pixel, info, position = translatedPosition(pixel, info)) => {
|
|
7619
|
+
if (pinDrag) return position && {
|
|
7620
|
+
...clonePointSymbol(pinDrag.start),
|
|
7621
|
+
position
|
|
7622
|
+
};
|
|
7598
7623
|
if (!drag) return null;
|
|
7599
7624
|
let next = clonePointSymbol(drag.start);
|
|
7600
7625
|
const intrinsic = drag.render;
|
|
@@ -7619,7 +7644,7 @@ function runPointSymbolEdit(opts) {
|
|
|
7619
7644
|
return next;
|
|
7620
7645
|
}
|
|
7621
7646
|
if (drag.kind === "body" || drag.kind === "location") {
|
|
7622
|
-
|
|
7647
|
+
if (!position) return null;
|
|
7623
7648
|
if (drag.kind === "location") return movePointSymbolLocation(next, intrinsic, adapter, position);
|
|
7624
7649
|
next.position = position;
|
|
7625
7650
|
if (next.offset?.placement.mode === "ground") {
|
|
@@ -7636,37 +7661,48 @@ function runPointSymbolEdit(opts) {
|
|
|
7636
7661
|
if (drag.kind === "rotate" || drag.kind === "scale") next = preserveDisplayPlacement(next, capability.render(next), adapter, drag.layout);
|
|
7637
7662
|
return next;
|
|
7638
7663
|
};
|
|
7639
|
-
const
|
|
7640
|
-
|
|
7641
|
-
if (!next) return;
|
|
7664
|
+
const deferred = createDeferredDragSnap(deferredSnap, () => ctx.settled);
|
|
7665
|
+
const paint = (next) => {
|
|
7642
7666
|
working = next;
|
|
7643
7667
|
render();
|
|
7668
|
+
emitTransient(transient.active ? "move" : "start", working.position);
|
|
7669
|
+
};
|
|
7670
|
+
const onMove = (pixel, info) => {
|
|
7671
|
+
if (deferred.releasing) return;
|
|
7672
|
+
const position = translatedPosition(pixel, info);
|
|
7673
|
+
const next = position ? null : transformed(pixel, info, null);
|
|
7674
|
+
if (!position && !next) return;
|
|
7675
|
+
const request = position && translateRequest(position, pixel, info);
|
|
7676
|
+
deferred.move(pixel, request, (landed) => {
|
|
7677
|
+
const moved = next ?? transformed(pixel, void 0, landed ?? position);
|
|
7678
|
+
if (moved) paint(moved);
|
|
7679
|
+
});
|
|
7644
7680
|
};
|
|
7645
7681
|
const onUp = (pixel, info) => {
|
|
7646
|
-
|
|
7647
|
-
|
|
7648
|
-
pinDrag = null;
|
|
7649
|
-
driver.setDragPanEnabled(true);
|
|
7650
|
-
shell.suppressNextClickAway();
|
|
7651
|
-
working = clonePointSymbol(start);
|
|
7652
|
-
if (next && !withinClickSlop(pixel, down)) apply(next, "gesture", "Move unit");
|
|
7653
|
-
else render();
|
|
7654
|
-
return;
|
|
7655
|
-
}
|
|
7656
|
-
if (!drag) return;
|
|
7657
|
-
const currentDrag = drag;
|
|
7658
|
-
const next = transformed(pixel, info);
|
|
7659
|
-
drag = null;
|
|
7682
|
+
const gesture = pinDrag ?? drag;
|
|
7683
|
+
if (deferred.releasing || !gesture) return;
|
|
7660
7684
|
shell.suppressNextClickAway();
|
|
7685
|
+
const position = withinClickSlop(pixel, gesture.down) ? null : translatedPosition(pixel, info);
|
|
7686
|
+
const landed = position && deferred.release(pixel, translateRequest(position, pixel, info));
|
|
7687
|
+
deferred.finish(landed, (at) => finishRelease(pixel, info, at ?? position));
|
|
7688
|
+
};
|
|
7689
|
+
/** Ends a released drag at `pixel`, where a translate or pin drag put the
|
|
7690
|
+
* symbol's `position` when it moved. */
|
|
7691
|
+
function finishRelease(pixel, info, position) {
|
|
7692
|
+
const pin = pinDrag;
|
|
7693
|
+
const gesture = pin ?? drag;
|
|
7694
|
+
if (!gesture) return;
|
|
7695
|
+
const { start, down } = gesture;
|
|
7696
|
+
const next = (!!pin || drag.kind === "body") && withinClickSlop(pixel, down) ? null : transformed(pixel, info, position ?? void 0);
|
|
7697
|
+
const label = pin ? "Move unit" : `${drag.kind[0].toUpperCase()}${drag.kind.slice(1)}`;
|
|
7698
|
+
pinDrag = null;
|
|
7699
|
+
drag = null;
|
|
7661
7700
|
driver.setDragPanEnabled(true);
|
|
7662
|
-
working = clonePointSymbol(
|
|
7663
|
-
|
|
7664
|
-
if (
|
|
7665
|
-
|
|
7666
|
-
|
|
7667
|
-
}
|
|
7668
|
-
apply(next, "gesture", `${currentDrag.kind[0].toUpperCase()}${currentDrag.kind.slice(1)}`);
|
|
7669
|
-
};
|
|
7701
|
+
working = clonePointSymbol(start);
|
|
7702
|
+
emitTransient("end", (next ?? start).position);
|
|
7703
|
+
if (next) apply(next, "gesture", label);
|
|
7704
|
+
else render();
|
|
7705
|
+
}
|
|
7670
7706
|
const handle = runEditInteraction({
|
|
7671
7707
|
adapter,
|
|
7672
7708
|
signal,
|
|
@@ -7679,6 +7715,8 @@ function runPointSymbolEdit(opts) {
|
|
|
7679
7715
|
if (!pinEditing || !opts.canRenderPin?.()) render();
|
|
7680
7716
|
},
|
|
7681
7717
|
onBeforeTeardown: (settlement) => {
|
|
7718
|
+
deferred.end();
|
|
7719
|
+
emitTransient("end", settlement.status === "committed" ? settlement.value.graphic.position : symbol.position);
|
|
7682
7720
|
settleToGraphics(settlement.status === "committed" ? settlement.value.graphic : void 0);
|
|
7683
7721
|
},
|
|
7684
7722
|
onDown,
|
|
@@ -9430,7 +9468,8 @@ var TacticalDraw = class {
|
|
|
9430
9468
|
wasOnGraphicsLayer,
|
|
9431
9469
|
onSettled,
|
|
9432
9470
|
onClickAwayGraphicsPick: (event) => this.dispatchHostPick(this.graphicsLayer, event),
|
|
9433
|
-
snap: this.resolveSnap
|
|
9471
|
+
snap: this.resolveSnap,
|
|
9472
|
+
deferredSnap: this.resolveDeferredSnap
|
|
9434
9473
|
}), (handle) => {
|
|
9435
9474
|
handle.syncHostMembership(this.lastRenderedMeasures.some((graphic) => graphic.id === handle.measureId && isPointSymbol(graphic)));
|
|
9436
9475
|
this.activeEdit = handle;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orbat-mapper/tactical-draw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Engine-agnostic draw/edit core for tactical control measures (MIL-STD-2525 / APP-6). The MapAdapter ABI and bring-your-own-engine entry point for the tactical-draw package family.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Orbat Mapper",
|