@mica-js/editor 0.16.0 → 0.16.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/dist/fused.js +21 -10
- package/dist/fused.js.map +1 -1
- package/package.json +1 -1
package/dist/fused.js
CHANGED
|
@@ -884,7 +884,7 @@ function addInstance(document, device, placement, createId) {
|
|
|
884
884
|
* Removes instances, wires, nodes, labels and references as one change.
|
|
885
885
|
*
|
|
886
886
|
* Removing an instance also removes its labels, references and attached wires; removing a node
|
|
887
|
-
* removes what hangs on it
|
|
887
|
+
* removes what hangs on it. Nodes of removed wires and references are pruned when unused.
|
|
888
888
|
*/
|
|
889
889
|
function removeTargets(document, targets) {
|
|
890
890
|
const instances = new Map(document.instances.map((instance) => [instance.id, instance]));
|
|
@@ -897,7 +897,7 @@ function removeTargets(document, targets) {
|
|
|
897
897
|
const removedWires = /* @__PURE__ */ new Set();
|
|
898
898
|
const removedLabels = /* @__PURE__ */ new Set();
|
|
899
899
|
const removedReferences = /* @__PURE__ */ new Set();
|
|
900
|
-
const
|
|
900
|
+
const pruneCandidates = /* @__PURE__ */ new Set();
|
|
901
901
|
for (const target of targets) switch (target.kind) {
|
|
902
902
|
case "instance":
|
|
903
903
|
removedInstances.add(requireEntry(instances, target).id);
|
|
@@ -914,22 +914,36 @@ function removeTargets(document, targets) {
|
|
|
914
914
|
case "reference": {
|
|
915
915
|
const reference = requireEntry(references, target);
|
|
916
916
|
removedReferences.add(reference.id);
|
|
917
|
-
if (reference.target.kind === "node")
|
|
917
|
+
if (reference.target.kind === "node") pruneCandidates.add(reference.target.node);
|
|
918
918
|
break;
|
|
919
919
|
}
|
|
920
920
|
default: throw new FusedSessionError("edit/invalid-request", `Unknown target kind ${JSON.stringify(target.kind)}.`);
|
|
921
921
|
}
|
|
922
922
|
const endpointRemoved = (endpoint) => endpoint.kind === "pin" ? removedInstances.has(endpoint.instance) : removedNodes.has(endpoint.node);
|
|
923
|
-
for (const wire of document.wires)
|
|
923
|
+
for (const wire of document.wires) {
|
|
924
|
+
if (endpointRemoved(wire.from) || endpointRemoved(wire.to)) removedWires.add(wire.id);
|
|
925
|
+
if (removedWires.has(wire.id)) {
|
|
926
|
+
if (wire.from.kind === "node") pruneCandidates.add(wire.from.node);
|
|
927
|
+
if (wire.to.kind === "node") pruneCandidates.add(wire.to.node);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
924
930
|
for (const label of document.labels) if (endpointRemoved(label.target)) removedLabels.add(label.id);
|
|
925
931
|
for (const reference of document.references) if (endpointRemoved(reference.target)) removedReferences.add(reference.id);
|
|
926
932
|
if (removedInstances.size === 0 && removedNodes.size === 0 && removedWires.size === 0 && removedLabels.size === 0 && removedReferences.size === 0) return document;
|
|
927
933
|
const keptWires = document.wires.filter((wire) => !removedWires.has(wire.id));
|
|
928
934
|
const keptLabels = document.labels.filter((label) => !removedLabels.has(label.id));
|
|
929
935
|
const keptReferences = document.references.filter((reference) => !removedReferences.has(reference.id));
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
936
|
+
if (pruneCandidates.size > 0) {
|
|
937
|
+
const keepAnchor = (endpoint) => {
|
|
938
|
+
if (endpoint.kind === "node") pruneCandidates.delete(endpoint.node);
|
|
939
|
+
};
|
|
940
|
+
for (const wire of keptWires) {
|
|
941
|
+
keepAnchor(wire.from);
|
|
942
|
+
keepAnchor(wire.to);
|
|
943
|
+
}
|
|
944
|
+
for (const label of keptLabels) keepAnchor(label.target);
|
|
945
|
+
for (const reference of keptReferences) keepAnchor(reference.target);
|
|
946
|
+
for (const nodeId of pruneCandidates) removedNodes.add(nodeId);
|
|
933
947
|
}
|
|
934
948
|
return {
|
|
935
949
|
...document,
|
|
@@ -1274,9 +1288,6 @@ function requireEntry(entries, target) {
|
|
|
1274
1288
|
if (entry === void 0) throw new FusedSessionError("edit/unknown-target", `Unknown ${target.kind} ${JSON.stringify(target.id)}.`);
|
|
1275
1289
|
return entry;
|
|
1276
1290
|
}
|
|
1277
|
-
function touchesNode(wire, nodeId) {
|
|
1278
|
-
return wire.from.kind === "node" && wire.from.node === nodeId || wire.to.kind === "node" && wire.to.node === nodeId;
|
|
1279
|
-
}
|
|
1280
1291
|
function sameEndpoint(a, b) {
|
|
1281
1292
|
if (a.kind === "pin" && b.kind === "pin") return a.instance === b.instance && a.pin === b.pin;
|
|
1282
1293
|
if (a.kind === "node" && b.kind === "node") return a.node === b.node;
|