@mica-js/editor 0.4.0 → 0.5.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/README.md +1 -1
- package/dist/fused.d.ts +20 -0
- package/dist/fused.js +403 -7
- package/dist/fused.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ await workbench.dispose();
|
|
|
55
55
|
|
|
56
56
|
信息容器固定在活动栏首位。当前模式只有属性视图时,容器头部合并为“属性”及其操作,内容始终展开,保留收起整个侧栏的操作;包含器件视图时,头部显示“信息”,各视图保留自己的标题并支持折叠。最后一个展开的视图填满剩余高度,其后的折叠标题随之推到底部,保持视图顺序;空间不足时在容器内滚动。已打开的浮动视图隐藏头部入口,关闭后重新显示入口。折叠、停靠和浮动均不改变可用视图的计数;属性视图固定在首位。
|
|
57
57
|
|
|
58
|
-
电源、接地端子和网络标签的符号、文字与默认偏移使用场景单位,已放置内容与幽灵预览均随画布缩放。导线预览、提交和器件移动使用共用的正交路由;端子、网标与器件放置一次后返回选择工具,Esc
|
|
58
|
+
电源、接地端子和网络标签的符号、文字与默认偏移使用场景单位,已放置内容与幽灵预览均随画布缩放。导线预览、提交和器件移动使用共用的正交路由;端子、网标与器件放置一次后返回选择工具,Esc 取消放置且不写入文档。点击端子符号或网名只选择对象,点击其接线锚点才进入画线状态。拖动独立网标时连接端与名称一起移动,附着导线的折点随节点重排;命名引脚或共享节点的网标只移动名称,连接端留在原处。属性面板对选中的电压参考显示类型与连接端,并可直接修改角度、电压与网名,接地符号固定 `0 V` 且不提供电压和网名编辑;普通网标可直接修改网名;导线与连接节点显示只读身份。
|
|
59
59
|
|
|
60
60
|
工作台界面使用简体中文。工具条固定在画布左上角,模式切换位于最左侧,选中背景以胶囊滑动,并尊重系统的减少动态效果设置。宿主按钮与内置按钮共用实际宽度测量:依次使用图标与文字、仅图标、部分按钮进入“更多工具”的方式收纳;下拉菜单始终显示完整文字。编辑模式下双击器件会选中器件并展开属性侧栏;窄屏侧栏从顶部覆盖画布,通过向右箭头收起。
|
|
61
61
|
|
package/dist/fused.d.ts
CHANGED
|
@@ -342,6 +342,26 @@ export declare interface IWorkbenchCommandMap {
|
|
|
342
342
|
readonly referenceId: string;
|
|
343
343
|
readonly position: Point2D;
|
|
344
344
|
}>;
|
|
345
|
+
'label.move': IWorkbenchCommand<{
|
|
346
|
+
readonly labelId: string;
|
|
347
|
+
readonly position: Point2D;
|
|
348
|
+
}>;
|
|
349
|
+
'label.setName': IWorkbenchCommand<{
|
|
350
|
+
readonly labelId: string;
|
|
351
|
+
readonly name: string;
|
|
352
|
+
}>;
|
|
353
|
+
'reference.setVoltage': IWorkbenchCommand<{
|
|
354
|
+
readonly referenceId: string;
|
|
355
|
+
readonly voltage: number;
|
|
356
|
+
}>;
|
|
357
|
+
'reference.setName': IWorkbenchCommand<{
|
|
358
|
+
readonly referenceId: string;
|
|
359
|
+
readonly name: string | undefined;
|
|
360
|
+
}>;
|
|
361
|
+
'reference.setRotation': IWorkbenchCommand<{
|
|
362
|
+
readonly referenceId: string;
|
|
363
|
+
readonly rotation: number;
|
|
364
|
+
}>;
|
|
345
365
|
'wire.moveSegment': IWorkbenchCommand<{
|
|
346
366
|
readonly wireId: string;
|
|
347
367
|
readonly segment: number;
|
package/dist/fused.js
CHANGED
|
@@ -799,6 +799,58 @@ function setTextOffset(document, target, offset) {
|
|
|
799
799
|
} : value)
|
|
800
800
|
};
|
|
801
801
|
}
|
|
802
|
+
/** Renames the net one label declares; the anchor and display offset stay as they are. */
|
|
803
|
+
function setLabelName(document, labelId, name) {
|
|
804
|
+
const label = document.labels.find((value) => value.id === labelId);
|
|
805
|
+
if (label === void 0) throw new FusedSessionError("edit/unknown-target", `Unknown label ${JSON.stringify(labelId)}.`);
|
|
806
|
+
const next = requireNetName(name);
|
|
807
|
+
if (next === label.name) return document;
|
|
808
|
+
return {
|
|
809
|
+
...document,
|
|
810
|
+
labels: document.labels.map((value) => value.id === labelId ? {
|
|
811
|
+
...value,
|
|
812
|
+
name: next
|
|
813
|
+
} : value)
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
/** Sets the ideal voltage of one reference; a ground symbol stays at 0 V. */
|
|
817
|
+
function setReferenceVoltage(document, referenceId, voltage) {
|
|
818
|
+
const reference = requireReference(document, referenceId);
|
|
819
|
+
const next = requireFinite$1(voltage, "voltage");
|
|
820
|
+
if (reference.symbol === "ground" && next !== 0) throw new FusedSessionError("edit/invalid-request", "A ground symbol keeps 0 V.");
|
|
821
|
+
if (next === reference.voltage) return document;
|
|
822
|
+
return {
|
|
823
|
+
...document,
|
|
824
|
+
references: document.references.map((value) => value.id === referenceId ? {
|
|
825
|
+
...value,
|
|
826
|
+
voltage: next
|
|
827
|
+
} : value)
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
/** Renames or removes the net name a power symbol owns. */
|
|
831
|
+
function setReferenceLabelName(document, referenceId, name) {
|
|
832
|
+
const reference = requireReference(document, referenceId);
|
|
833
|
+
if (reference.symbol === void 0) throw new FusedSessionError("edit/invalid-request", "Only a reference symbol owns a net name.");
|
|
834
|
+
if (reference.symbol === "ground") throw new FusedSessionError("edit/invalid-request", "A ground symbol is always GND.");
|
|
835
|
+
const label = name === void 0 ? void 0 : {
|
|
836
|
+
name: requireNetName(name),
|
|
837
|
+
...reference.label?.offset === void 0 ? {} : { offset: reference.label.offset }
|
|
838
|
+
};
|
|
839
|
+
if (label?.name === reference.label?.name) return document;
|
|
840
|
+
const { id, target, voltage, symbol, rotation } = reference;
|
|
841
|
+
const next = {
|
|
842
|
+
id,
|
|
843
|
+
target,
|
|
844
|
+
voltage,
|
|
845
|
+
...symbol === void 0 ? {} : { symbol },
|
|
846
|
+
...rotation === void 0 ? {} : { rotation },
|
|
847
|
+
...label === void 0 ? {} : { label }
|
|
848
|
+
};
|
|
849
|
+
return {
|
|
850
|
+
...document,
|
|
851
|
+
references: document.references.map((value) => value.id === referenceId ? next : value)
|
|
852
|
+
};
|
|
853
|
+
}
|
|
802
854
|
/**
|
|
803
855
|
* Adds one placed instance and locks the release it needs.
|
|
804
856
|
*
|
|
@@ -925,8 +977,20 @@ function rotateInstances(document, instanceIds, degrees) {
|
|
|
925
977
|
}
|
|
926
978
|
}));
|
|
927
979
|
}
|
|
928
|
-
/**
|
|
929
|
-
function
|
|
980
|
+
/** Sets the clockwise rotation of one reference symbol around its anchor. */
|
|
981
|
+
function setReferenceRotation(document, referenceId, rotation) {
|
|
982
|
+
const reference = requireReference(document, referenceId);
|
|
983
|
+
const next = normalizeDegrees(requireFinite$1(rotation, "rotation"));
|
|
984
|
+
if (next === (reference.rotation ?? 0)) return document;
|
|
985
|
+
return {
|
|
986
|
+
...document,
|
|
987
|
+
references: document.references.map((value) => value.id === referenceId ? {
|
|
988
|
+
...value,
|
|
989
|
+
rotation: next
|
|
990
|
+
} : value)
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
/** Rotates selected devices and reference symbols around their own electrical anchors. */ function rotateTargets(document, targets, degrees) {
|
|
930
994
|
const delta = requireFinite$1(degrees, "degrees");
|
|
931
995
|
const rotated = rotateInstances(document, targets.filter((value) => value.kind === "instance").map((value) => value.id), delta);
|
|
932
996
|
const ids = new Set(targets.filter((value) => value.kind === "reference").map((value) => value.id));
|
|
@@ -1183,6 +1247,16 @@ function requireInstance(document, instanceId) {
|
|
|
1183
1247
|
if (instance === void 0) throw new FusedSessionError("edit/unknown-target", `Unknown instance ${JSON.stringify(instanceId)}.`);
|
|
1184
1248
|
return instance;
|
|
1185
1249
|
}
|
|
1250
|
+
function requireReference(document, referenceId) {
|
|
1251
|
+
const reference = document.references.find((value) => value.id === referenceId);
|
|
1252
|
+
if (reference === void 0) throw new FusedSessionError("edit/unknown-target", `Unknown reference ${JSON.stringify(referenceId)}.`);
|
|
1253
|
+
return reference;
|
|
1254
|
+
}
|
|
1255
|
+
function requireNetName(name) {
|
|
1256
|
+
const trimmed = typeof name === "string" ? name.trim() : "";
|
|
1257
|
+
if (trimmed.length === 0) throw new FusedSessionError("edit/invalid-request", "A net name must be a non-empty string.");
|
|
1258
|
+
return trimmed;
|
|
1259
|
+
}
|
|
1186
1260
|
function requireEntry(entries, target) {
|
|
1187
1261
|
const entry = entries.get(target.id);
|
|
1188
1262
|
if (entry === void 0) throw new FusedSessionError("edit/unknown-target", `Unknown ${target.kind} ${JSON.stringify(target.id)}.`);
|
|
@@ -1854,6 +1928,36 @@ function moveReference(document, devices, referenceId, position, createId) {
|
|
|
1854
1928
|
return addWire(moved, reference.target, endpoint, routeWireBends(moved, devices, reference.target, endpoint, []), createId).document;
|
|
1855
1929
|
}
|
|
1856
1930
|
/**
|
|
1931
|
+
* The free node a standalone net label owns, when dragging the label should carry its anchor.
|
|
1932
|
+
*
|
|
1933
|
+
* A label dropped on empty canvas owns the node it created: nothing else names that node, it is
|
|
1934
|
+
* not a branch and at most one wire hangs on it. A label naming a pin, a junction or a shared node
|
|
1935
|
+
* only owns its text, so its name may sit anywhere without dragging the connection with it.
|
|
1936
|
+
*/
|
|
1937
|
+
function labelAnchorNode(document, labelId) {
|
|
1938
|
+
const target = document.labels.find((value) => value.id === labelId)?.target;
|
|
1939
|
+
if (target?.kind !== "node") return void 0;
|
|
1940
|
+
const node = document.nodes.find((value) => value.id === target.node);
|
|
1941
|
+
if (node === void 0 || node.kind === "junction") return void 0;
|
|
1942
|
+
return document.labels.some((value) => value.id !== labelId && value.target.kind === "node" && value.target.node === node.id) || document.references.some((value) => value.target.kind === "node" && value.target.node === node.id) || document.wires.filter((value) => value.from.kind === "node" && value.from.node === node.id || value.to.kind === "node" && value.to.node === node.id).length > 1 ? void 0 : node.id;
|
|
1943
|
+
}
|
|
1944
|
+
/** Moves a standalone net label as one object: the connection point and the name travel together. */
|
|
1945
|
+
function moveLabel(document, devices, labelId, position) {
|
|
1946
|
+
const nodeId = labelAnchorNode(document, labelId);
|
|
1947
|
+
if (nodeId === void 0 || !Number.isFinite(position.x) || !Number.isFinite(position.y)) throw new FusedSessionError("edit/invalid-request", "Invalid net label drag");
|
|
1948
|
+
const node = document.nodes.find((value) => value.id === nodeId);
|
|
1949
|
+
if (node === void 0) throw new FusedSessionError("edit/invalid-request", "Unknown net label anchor");
|
|
1950
|
+
if (node.x === position.x && node.y === position.y) return document;
|
|
1951
|
+
return routeDocumentWires({
|
|
1952
|
+
...document,
|
|
1953
|
+
nodes: document.nodes.map((value) => value.id === nodeId ? {
|
|
1954
|
+
...value,
|
|
1955
|
+
x: position.x,
|
|
1956
|
+
y: position.y
|
|
1957
|
+
} : value)
|
|
1958
|
+
}, devices, document);
|
|
1959
|
+
}
|
|
1960
|
+
/**
|
|
1857
1961
|
* Bends for a new wire from `from` to `to` through the requested waypoints.
|
|
1858
1962
|
*
|
|
1859
1963
|
* The waypoints stay in the order the caller picked them; only the legs between them are
|
|
@@ -3136,6 +3240,7 @@ function drawCanvas(canvas, width, height, state) {
|
|
|
3136
3240
|
let previewId = 0;
|
|
3137
3241
|
document = moveReference(document, state.devices, state.referenceDrag.referenceId, state.referenceDrag.position, () => `__reference_drag_${previewId++}__`);
|
|
3138
3242
|
}
|
|
3243
|
+
if (state.labelDrag !== void 0 && labelAnchorNode(document, state.labelDrag.labelId) !== void 0) document = moveLabel(document, state.devices, state.labelDrag.labelId, state.labelDrag.position);
|
|
3139
3244
|
const stroke = (points) => {
|
|
3140
3245
|
context.beginPath();
|
|
3141
3246
|
points.forEach((point, index) => {
|
|
@@ -3371,6 +3476,7 @@ function CanvasPart(props) {
|
|
|
3371
3476
|
const [wireDrag, setWireDrag] = useState();
|
|
3372
3477
|
const [textDrag, setTextDrag] = useState();
|
|
3373
3478
|
const [referenceDrag, setReferenceDrag] = useState();
|
|
3479
|
+
const [labelDrag, setLabelDrag] = useState();
|
|
3374
3480
|
const [candidates, setCandidates] = useState([]);
|
|
3375
3481
|
const gesture = useRef(void 0);
|
|
3376
3482
|
const business = useRef(void 0);
|
|
@@ -3428,6 +3534,7 @@ function CanvasPart(props) {
|
|
|
3428
3534
|
setWireDrag(void 0);
|
|
3429
3535
|
setTextDrag(void 0);
|
|
3430
3536
|
setReferenceDrag(void 0);
|
|
3537
|
+
setLabelDrag(void 0);
|
|
3431
3538
|
if (active !== void 0) current.current.onInput(active.instanceId, {
|
|
3432
3539
|
type: "pointerup",
|
|
3433
3540
|
position: active.position,
|
|
@@ -3503,6 +3610,7 @@ function CanvasPart(props) {
|
|
|
3503
3610
|
...wireDrag === void 0 ? {} : { wireDrag },
|
|
3504
3611
|
...textDrag === void 0 ? {} : { textDrag },
|
|
3505
3612
|
...referenceDrag === void 0 ? {} : { referenceDrag },
|
|
3613
|
+
...labelDrag === void 0 ? {} : { labelDrag },
|
|
3506
3614
|
...!hovered || props.placement === void 0 ? {} : { ghost: {
|
|
3507
3615
|
device: props.placement.id,
|
|
3508
3616
|
position: pointer,
|
|
@@ -3547,7 +3655,8 @@ function CanvasPart(props) {
|
|
|
3547
3655
|
drag,
|
|
3548
3656
|
wireDrag,
|
|
3549
3657
|
textDrag,
|
|
3550
|
-
referenceDrag
|
|
3658
|
+
referenceDrag,
|
|
3659
|
+
labelDrag
|
|
3551
3660
|
]);
|
|
3552
3661
|
function local(event) {
|
|
3553
3662
|
const rect = event.currentTarget.getBoundingClientRect();
|
|
@@ -3640,6 +3749,11 @@ function CanvasPart(props) {
|
|
|
3640
3749
|
props.onCancel();
|
|
3641
3750
|
});
|
|
3642
3751
|
}
|
|
3752
|
+
/** Wire starts only on the electrical anchor, not on the rest of the terminal symbol. */
|
|
3753
|
+
function atAnchor(endpoint, point) {
|
|
3754
|
+
const anchor = anchorPoint(endpoint);
|
|
3755
|
+
return Math.hypot(anchor.x - point.x, anchor.y - point.y) <= 7 / viewport.scale;
|
|
3756
|
+
}
|
|
3643
3757
|
function startWire(endpoint) {
|
|
3644
3758
|
if (props.state.readOnly || props.state.mode !== "edit") return;
|
|
3645
3759
|
if ("kind" in endpoint && hasWireConnection(props.document, endpoint)) return;
|
|
@@ -3813,7 +3927,20 @@ function CanvasPart(props) {
|
|
|
3813
3927
|
};
|
|
3814
3928
|
props.onSelection(event.shiftKey ? [...props.selection.filter((value) => value.id !== target.id), target] : [target]);
|
|
3815
3929
|
if (!props.state.readOnly) {
|
|
3816
|
-
|
|
3930
|
+
const anchor = text.kind === "label" ? labelAnchorNode(props.document, text.id) : void 0;
|
|
3931
|
+
const node = props.document.nodes.find((value) => value.id === anchor);
|
|
3932
|
+
if (anchor !== void 0 && node !== void 0) gesture.current = {
|
|
3933
|
+
kind: "label",
|
|
3934
|
+
pointerId: event.pointerId,
|
|
3935
|
+
start: point,
|
|
3936
|
+
original: {
|
|
3937
|
+
x: node.x,
|
|
3938
|
+
y: node.y
|
|
3939
|
+
},
|
|
3940
|
+
labelId: text.id,
|
|
3941
|
+
moved: false
|
|
3942
|
+
};
|
|
3943
|
+
else gesture.current = {
|
|
3817
3944
|
kind: "text",
|
|
3818
3945
|
pointerId: event.pointerId,
|
|
3819
3946
|
start: point,
|
|
@@ -3950,6 +4077,15 @@ function CanvasPart(props) {
|
|
|
3950
4077
|
target: active.target,
|
|
3951
4078
|
offset: textDragOffset(props.document, props.devices, active.target, delta)
|
|
3952
4079
|
});
|
|
4080
|
+
} else if (active?.kind === "label") {
|
|
4081
|
+
if (Math.hypot(point.x - active.start.x, point.y - active.start.y) * viewport.scale >= 3) active.moved = true;
|
|
4082
|
+
if (active.moved) setLabelDrag({
|
|
4083
|
+
labelId: active.labelId,
|
|
4084
|
+
position: snap({
|
|
4085
|
+
x: active.original.x + point.x - active.start.x,
|
|
4086
|
+
y: active.original.y + point.y - active.start.y
|
|
4087
|
+
}, event.altKey)
|
|
4088
|
+
});
|
|
3953
4089
|
} else if (active?.kind === "reference") {
|
|
3954
4090
|
if (Math.hypot(point.x - active.start.x, point.y - active.start.y) * viewport.scale >= 3) active.moved = true;
|
|
3955
4091
|
if (active.moved) setReferenceDrag({
|
|
@@ -3991,7 +4127,16 @@ function CanvasPart(props) {
|
|
|
3991
4127
|
if (delta.x !== 0 || delta.y !== 0) commit(() => props.onMoveText(active.target, textDragOffset(props.document, props.devices, active.target, delta)));
|
|
3992
4128
|
else if (active.target.kind === "reference") {
|
|
3993
4129
|
const reference = props.document.references.find((value) => value.id === active.target.id);
|
|
3994
|
-
if (reference !== void 0) startWire(reference.target);
|
|
4130
|
+
if (reference !== void 0 && atAnchor(reference.target, active.start)) startWire(reference.target);
|
|
4131
|
+
}
|
|
4132
|
+
} else if (active?.kind === "label") {
|
|
4133
|
+
if (active.moved) {
|
|
4134
|
+
const point = toScene(local(event), viewport);
|
|
4135
|
+
const position = snap({
|
|
4136
|
+
x: active.original.x + point.x - active.start.x,
|
|
4137
|
+
y: active.original.y + point.y - active.start.y
|
|
4138
|
+
}, event.altKey);
|
|
4139
|
+
if (position.x !== active.original.x || position.y !== active.original.y) commit(() => props.onMoveLabel(active.labelId, position));
|
|
3995
4140
|
}
|
|
3996
4141
|
} else if (active?.kind === "reference") {
|
|
3997
4142
|
if (active.moved) {
|
|
@@ -4003,7 +4148,7 @@ function CanvasPart(props) {
|
|
|
4003
4148
|
if (position.x !== active.original.x || position.y !== active.original.y) commit(() => props.onMoveReference(active.referenceId, position));
|
|
4004
4149
|
} else {
|
|
4005
4150
|
const reference = props.document.references.find((value) => value.id === active.referenceId);
|
|
4006
|
-
if (reference !== void 0) startWire(reference.target);
|
|
4151
|
+
if (reference !== void 0 && atAnchor(reference.target, active.start)) startWire(reference.target);
|
|
4007
4152
|
}
|
|
4008
4153
|
}
|
|
4009
4154
|
gesture.current = void 0;
|
|
@@ -4011,6 +4156,7 @@ function CanvasPart(props) {
|
|
|
4011
4156
|
setWireDrag(void 0);
|
|
4012
4157
|
setTextDrag(void 0);
|
|
4013
4158
|
setReferenceDrag(void 0);
|
|
4159
|
+
setLabelDrag(void 0);
|
|
4014
4160
|
if (event.currentTarget.hasPointerCapture(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId);
|
|
4015
4161
|
},
|
|
4016
4162
|
onPointerEnter: () => setHovered(true),
|
|
@@ -4901,6 +5047,161 @@ function PropertyField(props) {
|
|
|
4901
5047
|
})]
|
|
4902
5048
|
});
|
|
4903
5049
|
}
|
|
5050
|
+
/** Text or number cell that commits on blur and Enter, restoring `Escape`. */
|
|
5051
|
+
function CommitInput(props) {
|
|
5052
|
+
const [draft, setDraft] = useState(props.value);
|
|
5053
|
+
useEffect(() => setDraft(props.value), [props.value]);
|
|
5054
|
+
const commit = () => {
|
|
5055
|
+
if (props.disabled || draft === props.value) return;
|
|
5056
|
+
props.commit(draft);
|
|
5057
|
+
};
|
|
5058
|
+
return /* @__PURE__ */ jsx("input", {
|
|
5059
|
+
"aria-label": props.label,
|
|
5060
|
+
type: props.numeric ? "number" : "text",
|
|
5061
|
+
value: draft,
|
|
5062
|
+
placeholder: props.placeholder,
|
|
5063
|
+
disabled: props.disabled,
|
|
5064
|
+
onChange: (event) => setDraft(event.target.value),
|
|
5065
|
+
onBlur: commit,
|
|
5066
|
+
onKeyDown: (event) => {
|
|
5067
|
+
if (event.key === "Enter") {
|
|
5068
|
+
event.preventDefault();
|
|
5069
|
+
commit();
|
|
5070
|
+
} else if (event.key === "Escape") {
|
|
5071
|
+
event.preventDefault();
|
|
5072
|
+
setDraft(props.value);
|
|
5073
|
+
}
|
|
5074
|
+
}
|
|
5075
|
+
});
|
|
5076
|
+
}
|
|
5077
|
+
function AnnotationField(props) {
|
|
5078
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
5079
|
+
className: "mica-wb-property",
|
|
5080
|
+
children: [/* @__PURE__ */ jsx("label", { children: props.label }), /* @__PURE__ */ jsx("div", {
|
|
5081
|
+
className: "mica-wb-property-control",
|
|
5082
|
+
children: props.children
|
|
5083
|
+
})]
|
|
5084
|
+
});
|
|
5085
|
+
}
|
|
5086
|
+
var REFERENCE_TITLES = {
|
|
5087
|
+
power: "电源端",
|
|
5088
|
+
ground: "接地端",
|
|
5089
|
+
constraint: "电压参考"
|
|
5090
|
+
};
|
|
5091
|
+
function AnnotationFields(props) {
|
|
5092
|
+
const annotation = props.annotation;
|
|
5093
|
+
if (annotation.kind === "node") return /* @__PURE__ */ jsxs("dl", {
|
|
5094
|
+
className: "mica-wb-identity",
|
|
5095
|
+
children: [
|
|
5096
|
+
/* @__PURE__ */ jsx("dt", { children: "对象" }),
|
|
5097
|
+
/* @__PURE__ */ jsx("dd", { children: "连接节点" }),
|
|
5098
|
+
/* @__PURE__ */ jsx("dt", { children: "类型" }),
|
|
5099
|
+
/* @__PURE__ */ jsx("dd", { children: annotation.node.kind === "junction" ? "分支点" : "自由端点" }),
|
|
5100
|
+
/* @__PURE__ */ jsx("dt", { children: "坐标" }),
|
|
5101
|
+
/* @__PURE__ */ jsx("dd", { children: `${String(annotation.node.x)}, ${String(annotation.node.y)} mm` })
|
|
5102
|
+
]
|
|
5103
|
+
});
|
|
5104
|
+
if (annotation.kind === "wire") return /* @__PURE__ */ jsxs("dl", {
|
|
5105
|
+
className: "mica-wb-identity",
|
|
5106
|
+
children: [
|
|
5107
|
+
/* @__PURE__ */ jsx("dt", { children: "对象" }),
|
|
5108
|
+
/* @__PURE__ */ jsx("dd", { children: "导线" }),
|
|
5109
|
+
/* @__PURE__ */ jsx("dt", { children: "起点" }),
|
|
5110
|
+
/* @__PURE__ */ jsx("dd", { children: annotation.from }),
|
|
5111
|
+
/* @__PURE__ */ jsx("dt", { children: "终点" }),
|
|
5112
|
+
/* @__PURE__ */ jsx("dd", { children: annotation.to }),
|
|
5113
|
+
/* @__PURE__ */ jsx("dt", { children: "折点" }),
|
|
5114
|
+
/* @__PURE__ */ jsx("dd", { children: String(annotation.wire.bends.length) })
|
|
5115
|
+
]
|
|
5116
|
+
});
|
|
5117
|
+
if (annotation.kind === "label") return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("dl", {
|
|
5118
|
+
className: "mica-wb-identity",
|
|
5119
|
+
children: [
|
|
5120
|
+
/* @__PURE__ */ jsx("dt", { children: "对象" }),
|
|
5121
|
+
/* @__PURE__ */ jsx("dd", { children: "网标" }),
|
|
5122
|
+
/* @__PURE__ */ jsx("dt", { children: "连接端" }),
|
|
5123
|
+
/* @__PURE__ */ jsx("dd", { children: annotation.endpoint })
|
|
5124
|
+
]
|
|
5125
|
+
}), /* @__PURE__ */ jsx(AnnotationField, {
|
|
5126
|
+
label: "网名",
|
|
5127
|
+
children: /* @__PURE__ */ jsx(CommitInput, {
|
|
5128
|
+
label: "网名",
|
|
5129
|
+
numeric: false,
|
|
5130
|
+
value: annotation.label.name,
|
|
5131
|
+
disabled: props.disabled,
|
|
5132
|
+
commit: (draft) => {
|
|
5133
|
+
const name = draft.trim();
|
|
5134
|
+
if (name.length === 0) {
|
|
5135
|
+
props.onError(/* @__PURE__ */ new Error("网名不能为空"));
|
|
5136
|
+
return;
|
|
5137
|
+
}
|
|
5138
|
+
props.onRenameLabel(annotation.label.id, name);
|
|
5139
|
+
}
|
|
5140
|
+
})
|
|
5141
|
+
})] });
|
|
5142
|
+
const reference = annotation.reference;
|
|
5143
|
+
const ground = reference.symbol === "ground";
|
|
5144
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
5145
|
+
/* @__PURE__ */ jsxs("dl", {
|
|
5146
|
+
className: "mica-wb-identity",
|
|
5147
|
+
children: [
|
|
5148
|
+
/* @__PURE__ */ jsx("dt", { children: "对象" }),
|
|
5149
|
+
/* @__PURE__ */ jsx("dd", { children: REFERENCE_TITLES[reference.symbol ?? "constraint"] }),
|
|
5150
|
+
/* @__PURE__ */ jsx("dt", { children: "连接端" }),
|
|
5151
|
+
/* @__PURE__ */ jsx("dd", { children: annotation.endpoint }),
|
|
5152
|
+
ground ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", { children: "电压" }), /* @__PURE__ */ jsx("dd", { children: "0 V" })] }) : void 0
|
|
5153
|
+
]
|
|
5154
|
+
}),
|
|
5155
|
+
reference.symbol === void 0 ? void 0 : /* @__PURE__ */ jsx(AnnotationField, {
|
|
5156
|
+
label: "角度(°)",
|
|
5157
|
+
children: /* @__PURE__ */ jsx(CommitInput, {
|
|
5158
|
+
label: "角度",
|
|
5159
|
+
numeric: true,
|
|
5160
|
+
value: String(reference.rotation ?? 0),
|
|
5161
|
+
disabled: props.disabled,
|
|
5162
|
+
commit: (draft) => {
|
|
5163
|
+
const rotation = Number(draft);
|
|
5164
|
+
if (draft.trim() === "" || !Number.isFinite(rotation)) {
|
|
5165
|
+
props.onError(/* @__PURE__ */ new Error("角度需要有效数值"));
|
|
5166
|
+
return;
|
|
5167
|
+
}
|
|
5168
|
+
props.onSetRotation(reference.id, rotation);
|
|
5169
|
+
}
|
|
5170
|
+
})
|
|
5171
|
+
}),
|
|
5172
|
+
ground ? void 0 : /* @__PURE__ */ jsx(AnnotationField, {
|
|
5173
|
+
label: "电压(V)",
|
|
5174
|
+
children: /* @__PURE__ */ jsx(CommitInput, {
|
|
5175
|
+
label: "电压",
|
|
5176
|
+
numeric: true,
|
|
5177
|
+
value: String(reference.voltage),
|
|
5178
|
+
disabled: props.disabled,
|
|
5179
|
+
commit: (draft) => {
|
|
5180
|
+
const voltage = Number(draft);
|
|
5181
|
+
if (draft.trim() === "" || !Number.isFinite(voltage)) {
|
|
5182
|
+
props.onError(/* @__PURE__ */ new Error("电压需要有效数值"));
|
|
5183
|
+
return;
|
|
5184
|
+
}
|
|
5185
|
+
props.onSetVoltage(reference.id, voltage);
|
|
5186
|
+
}
|
|
5187
|
+
})
|
|
5188
|
+
}),
|
|
5189
|
+
reference.symbol === "power" ? /* @__PURE__ */ jsx(AnnotationField, {
|
|
5190
|
+
label: "网名",
|
|
5191
|
+
children: /* @__PURE__ */ jsx(CommitInput, {
|
|
5192
|
+
label: "网名",
|
|
5193
|
+
numeric: false,
|
|
5194
|
+
value: reference.label?.name ?? "",
|
|
5195
|
+
placeholder: "未命名",
|
|
5196
|
+
disabled: props.disabled,
|
|
5197
|
+
commit: (draft) => {
|
|
5198
|
+
const name = draft.trim();
|
|
5199
|
+
props.onSetReferenceName(reference.id, name.length === 0 ? void 0 : name);
|
|
5200
|
+
}
|
|
5201
|
+
})
|
|
5202
|
+
}) : void 0
|
|
5203
|
+
] });
|
|
5204
|
+
}
|
|
4904
5205
|
function InspectorView(props) {
|
|
4905
5206
|
const header = /* @__PURE__ */ jsxs("summary", {
|
|
4906
5207
|
className: "mica-wb-panel-title",
|
|
@@ -4927,9 +5228,21 @@ function InspectorView(props) {
|
|
|
4927
5228
|
children: /* @__PURE__ */ jsxs("details", {
|
|
4928
5229
|
open: props.hideHeader || !props.collapsed,
|
|
4929
5230
|
onToggle: toggled,
|
|
4930
|
-
children: [header, /* @__PURE__ */ jsx("p", {
|
|
5231
|
+
children: [header, props.annotation === void 0 ? /* @__PURE__ */ jsx("p", {
|
|
4931
5232
|
className: "mica-wb-empty",
|
|
4932
5233
|
children: props.selectionCount > 1 ? `已选择 ${props.selectionCount} 个对象` : "选择器件以查看其属性"
|
|
5234
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
5235
|
+
className: "mica-wb-property-fields",
|
|
5236
|
+
style: { height: props.fill ? void 0 : props.height },
|
|
5237
|
+
children: /* @__PURE__ */ jsx(AnnotationFields, {
|
|
5238
|
+
annotation: props.annotation,
|
|
5239
|
+
disabled: props.disabled,
|
|
5240
|
+
onRenameLabel: props.onRenameLabel,
|
|
5241
|
+
onSetVoltage: props.onSetVoltage,
|
|
5242
|
+
onSetReferenceName: props.onSetReferenceName,
|
|
5243
|
+
onSetRotation: props.onSetRotation,
|
|
5244
|
+
onError: props.onError
|
|
5245
|
+
})
|
|
4933
5246
|
})]
|
|
4934
5247
|
})
|
|
4935
5248
|
});
|
|
@@ -5412,6 +5725,46 @@ function WorkbenchPart({ ui }) {
|
|
|
5412
5725
|
const active = ui.contributions.containers.find((container) => container.id === state.activeContainer && ui.contributions.visible(container));
|
|
5413
5726
|
const single = selection.length === 1 && selection[0]?.kind === "instance" ? document.instances.find((instance) => instance.id === selection[0]?.id) : void 0;
|
|
5414
5727
|
const manifest = single === void 0 ? void 0 : ui.devices.get(single.device)?.manifest;
|
|
5728
|
+
const describeEndpoint = (endpoint) => {
|
|
5729
|
+
if (endpoint.kind === "node") return "连接节点";
|
|
5730
|
+
const instance = document.instances.find((value) => value.id === endpoint.instance);
|
|
5731
|
+
const label = instance === void 0 ? void 0 : ui.devices.get(instance.device)?.manifest.pins?.[endpoint.pin]?.label ?? endpoint.pin;
|
|
5732
|
+
return `${instance?.designator ?? endpoint.instance} · ${label ?? endpoint.pin}`;
|
|
5733
|
+
};
|
|
5734
|
+
const annotation = (() => {
|
|
5735
|
+
const target = selection.length === 1 ? selection[0] : void 0;
|
|
5736
|
+
if (target === void 0 || target.kind === "instance") return void 0;
|
|
5737
|
+
if (target.kind === "reference") {
|
|
5738
|
+
const reference = document.references.find((value) => value.id === target.id);
|
|
5739
|
+
return reference === void 0 ? void 0 : {
|
|
5740
|
+
kind: "reference",
|
|
5741
|
+
reference,
|
|
5742
|
+
endpoint: describeEndpoint(reference.target)
|
|
5743
|
+
};
|
|
5744
|
+
}
|
|
5745
|
+
if (target.kind === "label") {
|
|
5746
|
+
const label = document.labels.find((value) => value.id === target.id);
|
|
5747
|
+
return label === void 0 ? void 0 : {
|
|
5748
|
+
kind: "label",
|
|
5749
|
+
label,
|
|
5750
|
+
endpoint: describeEndpoint(label.target)
|
|
5751
|
+
};
|
|
5752
|
+
}
|
|
5753
|
+
if (target.kind === "wire") {
|
|
5754
|
+
const wire = document.wires.find((value) => value.id === target.id);
|
|
5755
|
+
return wire === void 0 ? void 0 : {
|
|
5756
|
+
kind: "wire",
|
|
5757
|
+
wire,
|
|
5758
|
+
from: describeEndpoint(wire.from),
|
|
5759
|
+
to: describeEndpoint(wire.to)
|
|
5760
|
+
};
|
|
5761
|
+
}
|
|
5762
|
+
const node = document.nodes.find((value) => value.id === target.id);
|
|
5763
|
+
return node === void 0 ? void 0 : {
|
|
5764
|
+
kind: "node",
|
|
5765
|
+
node
|
|
5766
|
+
};
|
|
5767
|
+
})();
|
|
5415
5768
|
const layout = single === void 0 || manifest === void 0 ? void 0 : ui.viewLayout(single.id);
|
|
5416
5769
|
const run = (task) => {
|
|
5417
5770
|
task.catch(ui.error);
|
|
@@ -5579,6 +5932,12 @@ function WorkbenchPart({ ui }) {
|
|
|
5579
5932
|
position
|
|
5580
5933
|
});
|
|
5581
5934
|
},
|
|
5935
|
+
onMoveLabel: async (labelId, position) => {
|
|
5936
|
+
await ui.workbench.executeCommand("label.move", {
|
|
5937
|
+
labelId,
|
|
5938
|
+
position
|
|
5939
|
+
});
|
|
5940
|
+
},
|
|
5582
5941
|
onStartWire: async () => {
|
|
5583
5942
|
await ui.workbench.executeCommand("canvas.setTool", { tool: "wire" });
|
|
5584
5943
|
},
|
|
@@ -5660,6 +6019,23 @@ function WorkbenchPart({ ui }) {
|
|
|
5660
6019
|
fill: state.mode !== "run" || !layout?.views.some((view) => view.location === "sidebar" && !view.collapsed && manifest?.view?.[view.viewId] !== void 0),
|
|
5661
6020
|
instance: single,
|
|
5662
6021
|
manifest: single === void 0 ? void 0 : ui.devices.get(single.device)?.manifest,
|
|
6022
|
+
annotation,
|
|
6023
|
+
onRenameLabel: (labelId, name) => run(ui.workbench.executeCommand("label.setName", {
|
|
6024
|
+
labelId,
|
|
6025
|
+
name
|
|
6026
|
+
})),
|
|
6027
|
+
onSetVoltage: (referenceId, voltage) => run(ui.workbench.executeCommand("reference.setVoltage", {
|
|
6028
|
+
referenceId,
|
|
6029
|
+
voltage
|
|
6030
|
+
})),
|
|
6031
|
+
onSetReferenceName: (referenceId, name) => run(ui.workbench.executeCommand("reference.setName", {
|
|
6032
|
+
referenceId,
|
|
6033
|
+
name
|
|
6034
|
+
})),
|
|
6035
|
+
onSetRotation: (referenceId, rotation) => run(ui.workbench.executeCommand("reference.setRotation", {
|
|
6036
|
+
referenceId,
|
|
6037
|
+
rotation
|
|
6038
|
+
})),
|
|
5663
6039
|
selectionCount: selection.length,
|
|
5664
6040
|
disabled: state.readOnly || state.mode !== "edit" || state.busy,
|
|
5665
6041
|
assets: ui.options.assetProvider,
|
|
@@ -6291,6 +6667,26 @@ async function createWorkbench(options) {
|
|
|
6291
6667
|
assertEditable();
|
|
6292
6668
|
await documentSession.transact((current) => moveReference(current, documentSession.getDevices().getLoadedDevices(), referenceId, position, () => crypto.randomUUID()));
|
|
6293
6669
|
},
|
|
6670
|
+
"label.move": async ({ labelId, position }) => {
|
|
6671
|
+
assertEditable();
|
|
6672
|
+
await documentSession.transact((current) => moveLabel(current, documentSession.getDevices().getLoadedDevices(), labelId, position));
|
|
6673
|
+
},
|
|
6674
|
+
"label.setName": async ({ labelId, name }) => {
|
|
6675
|
+
assertEditable();
|
|
6676
|
+
await documentSession.transact((current) => setLabelName(current, labelId, name));
|
|
6677
|
+
},
|
|
6678
|
+
"reference.setVoltage": async ({ referenceId, voltage }) => {
|
|
6679
|
+
assertEditable();
|
|
6680
|
+
await documentSession.transact((current) => setReferenceVoltage(current, referenceId, voltage));
|
|
6681
|
+
},
|
|
6682
|
+
"reference.setName": async ({ referenceId, name }) => {
|
|
6683
|
+
assertEditable();
|
|
6684
|
+
await documentSession.transact((current) => setReferenceLabelName(current, referenceId, name));
|
|
6685
|
+
},
|
|
6686
|
+
"reference.setRotation": async ({ referenceId, rotation }) => {
|
|
6687
|
+
assertEditable();
|
|
6688
|
+
await documentSession.transact((current) => setReferenceRotation(current, referenceId, rotation));
|
|
6689
|
+
},
|
|
6294
6690
|
"wire.add": ({ from, to, bends }) => {
|
|
6295
6691
|
assertEditable();
|
|
6296
6692
|
return documentSession.addWire(from, to, bends);
|