@mica-js/editor 0.5.0 → 0.6.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 +3 -3
- package/dist/fused-html.d.ts +5 -2
- package/dist/fused-runtime.d.ts +6 -2
- package/dist/fused-runtime.js +1 -1
- package/dist/fused.d.ts +9 -0
- package/dist/fused.js +146 -26
- package/dist/fused.js.map +1 -1
- package/dist/{runtime-CXYJzbbj.js → runtime-CE38_qhr.js} +3 -4
- package/dist/runtime-CE38_qhr.js.map +1 -0
- package/dist/style.css +3 -2
- package/package.json +1 -1
- package/dist/runtime-CXYJzbbj.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## 融合工作台
|
|
6
6
|
|
|
7
|
-
`@mica-js/editor/fused` 提供 React 19 工作台,直接编辑融合 `.sch` v2 文档。器件底图、逐引脚接线与动态覆盖共用实例坐标;主线程处理文档和交互,模型与 `view2d.js` 分别运行在现有 `SandboxWorker`
|
|
7
|
+
`@mica-js/editor/fused` 提供 React 19 工作台,直接编辑融合 `.sch` v2 文档。器件底图、逐引脚接线与动态覆盖共用实例坐标;主线程处理文档和交互,模型与 `view2d.js` 分别运行在现有 `SandboxWorker` 中。进入「运行」自动启动,切回「编辑」释放运行会话,下次运行从初态开始。暂停与继续只作为宿主 API 提供,工具条不显示相应控件:`workbench.executeCommand('simulation.pause')` 在仿真端确认后停止推进,保留模型、视图和订阅,实例音频随之暂停;`workbench.executeCommand('simulation.resume')` 在同一会话上继续。两个命令都串行于模式切换,编辑模式下拒绝,已处于目标状态时不重复操作。`getState().simulationStatus` 与 `onDidChangeState` 报告运行会话的实际状态,编辑模式下为 `undefined`。
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
10
|
import { createWorkbench } from '@mica-js/editor/fused';
|
|
@@ -55,9 +55,9 @@ await workbench.dispose();
|
|
|
55
55
|
|
|
56
56
|
信息容器固定在活动栏首位。当前模式只有属性视图时,容器头部合并为“属性”及其操作,内容始终展开,保留收起整个侧栏的操作;包含器件视图时,头部显示“信息”,各视图保留自己的标题并支持折叠。最后一个展开的视图填满剩余高度,其后的折叠标题随之推到底部,保持视图顺序;空间不足时在容器内滚动。已打开的浮动视图隐藏头部入口,关闭后重新显示入口。折叠、停靠和浮动均不改变可用视图的计数;属性视图固定在首位。
|
|
57
57
|
|
|
58
|
-
电源、接地端子和网络标签的符号、文字与默认偏移使用场景单位,已放置内容与幽灵预览均随画布缩放。导线预览、提交和器件移动使用共用的正交路由;端子、网标与器件放置一次后返回选择工具,Esc
|
|
58
|
+
电源、接地端子和网络标签的符号、文字与默认偏移使用场景单位,已放置内容与幽灵预览均随画布缩放。导线预览、提交和器件移动使用共用的正交路由;端子、网标与器件放置一次后返回选择工具,Esc 取消放置且不写入文档。新建电源符号默认使用 `VCC` 网名与 `3.3 V` 电压,幽灵预览显示同一默认值;接地符号固定 `0 V` 且不保存网名。点击端子符号或网名只选择对象,点击其接线锚点才进入画线状态。拖动独立网标时连接端与名称一起移动,附着导线的折点随节点重排;命名引脚或共享节点的网标只移动名称,连接端留在原处。属性面板对选中的电压参考显示类型与连接端,并可直接修改角度、电压与网名,接地符号固定 `0 V` 且不提供电压和网名编辑;普通网标可直接修改网名;导线与连接节点显示只读身份。
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
工作台界面使用简体中文。工具条固定在画布左上角,模式切换位于最左侧,选中背景以胶囊滑动,并尊重系统的减少动态效果设置。宿主按钮与内置按钮共用实际宽度测量:依次使用图标与文字、仅图标、部分按钮进入“更多工具”的方式收纳;下拉菜单始终显示完整文字。编辑模式下双击器件、电源或接地符号及其网名、普通网标会选中该对象并展开属性侧栏;窄屏侧栏从顶部覆盖画布,通过向右箭头收起。
|
|
61
61
|
|
|
62
62
|
融合工作台默认使用中性暗色,以黑、白、灰区分背景、面板、操作与接线。`theme` 接受 `'dark'`、`'light'`、`'system'`,或 `{ appearance, colors }`;只有显式选择 `system` 才跟随系统主题。`colors` 按语义 Token 覆盖基础色板,覆盖值不会因系统明暗切换而丢失。
|
|
63
63
|
|
package/dist/fused-html.d.ts
CHANGED
|
@@ -445,8 +445,11 @@ declare interface IFusedRuntime {
|
|
|
445
445
|
prepareDisplay(input: IFusedDisplayPrepareInput): Promise<readonly IFusedInstancePresentation[]>;
|
|
446
446
|
/** Restarts continuous fixed-step advancement after pause; requires a run session. */
|
|
447
447
|
resume(): Promise<void>;
|
|
448
|
-
/**
|
|
449
|
-
|
|
448
|
+
/**
|
|
449
|
+
* Stops advancement after the simulation guest acknowledged it, keeping models, listeners and
|
|
450
|
+
* presentation state. Resolves without a session outside run mode.
|
|
451
|
+
*/
|
|
452
|
+
pause(): Promise<void>;
|
|
450
453
|
/** Advances exactly one fixed step; requires a paused run session. */
|
|
451
454
|
step(): Promise<void>;
|
|
452
455
|
/** Rebuilds models and presentation of the run session from the same captured bytes, then advances. */
|
package/dist/fused-runtime.d.ts
CHANGED
|
@@ -491,8 +491,11 @@ export declare interface IFusedRuntime {
|
|
|
491
491
|
prepareDisplay(input: IFusedDisplayPrepareInput): Promise<readonly IFusedInstancePresentation[]>;
|
|
492
492
|
/** Restarts continuous fixed-step advancement after pause; requires a run session. */
|
|
493
493
|
resume(): Promise<void>;
|
|
494
|
-
/**
|
|
495
|
-
|
|
494
|
+
/**
|
|
495
|
+
* Stops advancement after the simulation guest acknowledged it, keeping models, listeners and
|
|
496
|
+
* presentation state. Resolves without a session outside run mode.
|
|
497
|
+
*/
|
|
498
|
+
pause(): Promise<void>;
|
|
496
499
|
/** Advances exactly one fixed step; requires a paused run session. */
|
|
497
500
|
step(): Promise<void>;
|
|
498
501
|
/** Rebuilds models and presentation of the run session from the same captured bytes, then advances. */
|
|
@@ -559,6 +562,7 @@ export declare interface IFusedSimulationService {
|
|
|
559
562
|
load(request: IFusedLoadRequest): Promise<IFusedSessionState>;
|
|
560
563
|
step(): Promise<IFusedSessionState>;
|
|
561
564
|
resume(): Promise<void>;
|
|
565
|
+
/** Stops advancement synchronously; the RPC result acknowledges the paused state. */
|
|
562
566
|
pause(): void;
|
|
563
567
|
reset(): Promise<void>;
|
|
564
568
|
/** Releases the models and keeps the captured package bytes for the next load. */
|
package/dist/fused-runtime.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { c as toWireFailure, i as isFusedBridgeError, n as FusedBridgeError, o as mapWireFailure, r as fromWireFailure, t as FUSED_WIRE_FAILURE } from "./wire-BDHL5Aj9.js";
|
|
2
|
-
import { _ as fusedModelSinkService, a as createFusedRuntime, c as createModelEventRouter, d as createHostPackageGateway, f as packageLockKey, g as fusedModelChannelService, h as fusedHostResourceService, i as startFusedSimulationGuest, l as createFusedDisplay, m as fusedHostPackageService, n as startFusedDisplayGuest, o as createHostModelRouter, p as fusedDisplayService, r as createViewSession, s as channelKey, t as loadFusedWorkerFactories, u as connectFusedWorkbench, v as fusedSimulationService } from "./runtime-
|
|
2
|
+
import { _ as fusedModelSinkService, a as createFusedRuntime, c as createModelEventRouter, d as createHostPackageGateway, f as packageLockKey, g as fusedModelChannelService, h as fusedHostResourceService, i as startFusedSimulationGuest, l as createFusedDisplay, m as fusedHostPackageService, n as startFusedDisplayGuest, o as createHostModelRouter, p as fusedDisplayService, r as createViewSession, s as channelKey, t as loadFusedWorkerFactories, u as connectFusedWorkbench, v as fusedSimulationService } from "./runtime-CE38_qhr.js";
|
|
3
3
|
export { FUSED_WIRE_FAILURE, FusedBridgeError, channelKey, connectFusedWorkbench, createFusedDisplay, createFusedRuntime, createHostModelRouter, createHostPackageGateway, createModelEventRouter, createViewSession, fromWireFailure, fusedDisplayService, fusedHostPackageService, fusedHostResourceService, fusedModelChannelService, fusedModelSinkService, fusedSimulationService, isFusedBridgeError, loadFusedWorkerFactories, mapWireFailure, packageLockKey, startFusedDisplayGuest, startFusedSimulationGuest, toWireFailure };
|
package/dist/fused.d.ts
CHANGED
|
@@ -92,6 +92,9 @@ export { FusedAudioState }
|
|
|
92
92
|
|
|
93
93
|
export { FusedDocument }
|
|
94
94
|
|
|
95
|
+
/** Session status the host mirrors; `idle` means no models are mounted (edit mode). */
|
|
96
|
+
declare type FusedSessionStatus = 'idle' | 'paused' | 'running' | 'faulted' | 'disposed';
|
|
97
|
+
|
|
95
98
|
export declare interface IAssetInfo {
|
|
96
99
|
readonly id: string;
|
|
97
100
|
/** File name including its extension; used to identify program formats. */
|
|
@@ -299,6 +302,10 @@ export declare interface IWorkbenchCommandMap {
|
|
|
299
302
|
'workbench.setMode': IWorkbenchCommand<{
|
|
300
303
|
readonly mode: WorkbenchMode;
|
|
301
304
|
}>;
|
|
305
|
+
/** Host-only pause of the mounted run session; no-op when already paused. */
|
|
306
|
+
'simulation.pause': IWorkbenchCommand;
|
|
307
|
+
/** Host-only resume of the mounted run session; no-op when already running. */
|
|
308
|
+
'simulation.resume': IWorkbenchCommand;
|
|
302
309
|
'canvas.fit': IWorkbenchCommand;
|
|
303
310
|
'canvas.zoom': IWorkbenchCommand<{
|
|
304
311
|
readonly factor: number;
|
|
@@ -442,6 +449,8 @@ export declare interface IWorkbenchOptions {
|
|
|
442
449
|
|
|
443
450
|
export declare interface IWorkbenchState {
|
|
444
451
|
readonly mode: WorkbenchMode;
|
|
452
|
+
/** Status of the mounted run session; undefined when no run session is mounted (edit mode). */
|
|
453
|
+
readonly simulationStatus: FusedSessionStatus | undefined;
|
|
445
454
|
readonly busy: boolean;
|
|
446
455
|
readonly dirty: boolean;
|
|
447
456
|
readonly readOnly: boolean;
|
package/dist/fused.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { c as planPolylineSegmentDrag, n as orthogonalWaypoints, t as extendWirePath } from "./wire-JZIiIOI0.js";
|
|
2
2
|
import { Q as isHtmlViewError, _ as resolveTheme, a as createHtmlViewHost, f as WORKBENCH_DARK_COLORS, g as readCanvasTheme, h as normalizeTheme, m as WORKBENCH_THEME_CSS_VARIABLES, p as WORKBENCH_LIGHT_COLORS, v as themeStyle } from "./html-HXwZq1my.js";
|
|
3
|
-
import { a as createFusedRuntime } from "./runtime-
|
|
3
|
+
import { a as createFusedRuntime } from "./runtime-CE38_qhr.js";
|
|
4
4
|
import { DisposableStore, Emitter } from "@mica-js/core/lifecycle";
|
|
5
5
|
import { projectOnSegment } from "@mica-js/document/schematic";
|
|
6
6
|
import { timePs } from "@mica-js/core";
|
|
@@ -1110,6 +1110,8 @@ function addLabel(document, target, name, options = {}, createId) {
|
|
|
1110
1110
|
labelId
|
|
1111
1111
|
};
|
|
1112
1112
|
}
|
|
1113
|
+
/** Ideal voltage of a power symbol placed from the editor toolbar. */
|
|
1114
|
+
var DEFAULT_POWER_VOLTAGE = 3.3;
|
|
1113
1115
|
/** Attaches an ideal voltage reference, optionally with the built-in power or ground symbol. */
|
|
1114
1116
|
function addReference(document, target, voltage, symbol, options = {}, createId) {
|
|
1115
1117
|
requireEndpoint(document, target, "target");
|
|
@@ -1135,6 +1137,16 @@ function addReference(document, target, voltage, symbol, options = {}, createId)
|
|
|
1135
1137
|
referenceId
|
|
1136
1138
|
};
|
|
1137
1139
|
}
|
|
1140
|
+
/**
|
|
1141
|
+
* Adds the reference a toolbar-placed power or ground symbol creates. A power symbol starts on an
|
|
1142
|
+
* explicit `VCC` net at 3.3 V; a ground symbol stays at 0 V and owns no net name.
|
|
1143
|
+
*/
|
|
1144
|
+
function addPlacedReference(document, target, symbol, rotation, createId) {
|
|
1145
|
+
return addReference(document, target, symbol === "ground" ? 0 : DEFAULT_POWER_VOLTAGE, symbol, symbol === "power" ? {
|
|
1146
|
+
rotation,
|
|
1147
|
+
label: { name: "VCC" }
|
|
1148
|
+
} : { rotation }, createId);
|
|
1149
|
+
}
|
|
1138
1150
|
/** Stores the per-instance sidebar and HTML view layout; `undefined` restores the defaults. */
|
|
1139
1151
|
function setViewLayout(document, instanceId, layout) {
|
|
1140
1152
|
const instance = requireInstance(document, instanceId);
|
|
@@ -1674,6 +1686,27 @@ function pickAnnotation(document, devices, point, tolerance) {
|
|
|
1674
1686
|
};
|
|
1675
1687
|
}
|
|
1676
1688
|
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Object a double click configures: text (an embedded net name or designator) wins over an
|
|
1691
|
+
* annotation symbol, which wins over a device body, matching the click-selection order.
|
|
1692
|
+
*/
|
|
1693
|
+
function pickDoubleClickTarget(document, devices, point, scale) {
|
|
1694
|
+
const text = pickText(document, devices, point, scale);
|
|
1695
|
+
if (text !== void 0) return text.kind === "designator" ? {
|
|
1696
|
+
kind: "instance",
|
|
1697
|
+
id: text.id
|
|
1698
|
+
} : {
|
|
1699
|
+
kind: text.kind,
|
|
1700
|
+
id: text.id
|
|
1701
|
+
};
|
|
1702
|
+
const annotation = pickAnnotation(document, devices, point, 3 / scale);
|
|
1703
|
+
if (annotation !== void 0) return annotation;
|
|
1704
|
+
const instance = pickInstance(document, devices, point);
|
|
1705
|
+
return instance === void 0 ? void 0 : {
|
|
1706
|
+
kind: "instance",
|
|
1707
|
+
id: instance.id
|
|
1708
|
+
};
|
|
1709
|
+
}
|
|
1677
1710
|
function containsExpanded(bounds, point, tolerance) {
|
|
1678
1711
|
return contains({
|
|
1679
1712
|
x: bounds.x - tolerance,
|
|
@@ -3176,6 +3209,72 @@ function resolveViewLayout(saved, manifest, availableHeight) {
|
|
|
3176
3209
|
};
|
|
3177
3210
|
}
|
|
3178
3211
|
//#endregion
|
|
3212
|
+
//#region src/fused/simulation.ts
|
|
3213
|
+
/**
|
|
3214
|
+
* Creates the host control of one workbench run session.
|
|
3215
|
+
*
|
|
3216
|
+
* Only status transitions reach `onDidChangeStatus`; simulated time changes are ignored, so a host
|
|
3217
|
+
* is never asked to update once per simulated tick.
|
|
3218
|
+
*/
|
|
3219
|
+
function createSimulationControl(onDidChangeStatus) {
|
|
3220
|
+
let runtime;
|
|
3221
|
+
let subscription;
|
|
3222
|
+
let status;
|
|
3223
|
+
let closed = false;
|
|
3224
|
+
function publish(next) {
|
|
3225
|
+
if (next === status) return;
|
|
3226
|
+
status = next;
|
|
3227
|
+
if (!closed) onDidChangeStatus(next);
|
|
3228
|
+
}
|
|
3229
|
+
function detach() {
|
|
3230
|
+
subscription?.dispose();
|
|
3231
|
+
subscription = void 0;
|
|
3232
|
+
runtime = void 0;
|
|
3233
|
+
publish(void 0);
|
|
3234
|
+
}
|
|
3235
|
+
function requireSession(operation) {
|
|
3236
|
+
if (closed) throw new Error(`simulation.${operation} requires an active workbench`);
|
|
3237
|
+
if (runtime === void 0) throw new Error(`simulation.${operation} requires a run session`);
|
|
3238
|
+
return runtime;
|
|
3239
|
+
}
|
|
3240
|
+
return {
|
|
3241
|
+
get status() {
|
|
3242
|
+
return status;
|
|
3243
|
+
},
|
|
3244
|
+
attach(next) {
|
|
3245
|
+
if (closed) throw new Error("The simulation control is disposed");
|
|
3246
|
+
detach();
|
|
3247
|
+
runtime = next;
|
|
3248
|
+
subscription = next.onDidChangeState((state) => {
|
|
3249
|
+
if (runtime !== next) return;
|
|
3250
|
+
publish(state.status);
|
|
3251
|
+
});
|
|
3252
|
+
publish(next.getState().status);
|
|
3253
|
+
},
|
|
3254
|
+
detach,
|
|
3255
|
+
async pause() {
|
|
3256
|
+
const active = requireSession("pause");
|
|
3257
|
+
if (status === "paused") return;
|
|
3258
|
+
await active.pause();
|
|
3259
|
+
if (runtime === active && !closed) publish(active.getState().status);
|
|
3260
|
+
},
|
|
3261
|
+
async resume() {
|
|
3262
|
+
const active = requireSession("resume");
|
|
3263
|
+
if (status === "running") return;
|
|
3264
|
+
await active.resume();
|
|
3265
|
+
if (runtime === active && !closed) publish(active.getState().status);
|
|
3266
|
+
},
|
|
3267
|
+
dispose() {
|
|
3268
|
+
if (closed) return;
|
|
3269
|
+
closed = true;
|
|
3270
|
+
subscription?.dispose();
|
|
3271
|
+
subscription = void 0;
|
|
3272
|
+
runtime = void 0;
|
|
3273
|
+
status = void 0;
|
|
3274
|
+
}
|
|
3275
|
+
};
|
|
3276
|
+
}
|
|
3277
|
+
//#endregion
|
|
3179
3278
|
//#region src/fused/parts/activity-bar-part.tsx
|
|
3180
3279
|
function Icon({ name }) {
|
|
3181
3280
|
return /* @__PURE__ */ jsx("span", {
|
|
@@ -3377,8 +3476,9 @@ function drawCanvas(canvas, width, height, state) {
|
|
|
3377
3476
|
node: "__annotation__"
|
|
3378
3477
|
},
|
|
3379
3478
|
symbol: state.annotation.kind,
|
|
3380
|
-
voltage: state.annotation.kind === "ground" ? 0 :
|
|
3381
|
-
rotation: state.annotation.rotation
|
|
3479
|
+
voltage: state.annotation.kind === "ground" ? 0 : DEFAULT_POWER_VOLTAGE,
|
|
3480
|
+
rotation: state.annotation.rotation,
|
|
3481
|
+
...state.annotation.kind === "power" ? { label: { name: "VCC" } } : {}
|
|
3382
3482
|
}]
|
|
3383
3483
|
};
|
|
3384
3484
|
context.strokeStyle = ink;
|
|
@@ -4025,16 +4125,14 @@ function CanvasPart(props) {
|
|
|
4025
4125
|
},
|
|
4026
4126
|
onDoubleClick: (event) => {
|
|
4027
4127
|
if (props.state.mode !== "edit" || props.state.busy || props.placement !== void 0) return;
|
|
4128
|
+
const point = toScene(local(event), viewport);
|
|
4028
4129
|
if (props.state.tool === "wire") {
|
|
4029
|
-
if (connection !== void 0) useEndpoint(snappedAnchor(
|
|
4130
|
+
if (connection !== void 0) useEndpoint(snappedAnchor(point, event.altKey));
|
|
4030
4131
|
return;
|
|
4031
4132
|
}
|
|
4032
|
-
const
|
|
4033
|
-
if (
|
|
4034
|
-
props.onSelection([
|
|
4035
|
-
kind: "instance",
|
|
4036
|
-
id: instance.id
|
|
4037
|
-
}]);
|
|
4133
|
+
const target = pickDoubleClickTarget(props.document, props.devices, point, viewport.scale);
|
|
4134
|
+
if (target === void 0) return;
|
|
4135
|
+
props.onSelection([target]);
|
|
4038
4136
|
props.onOpenProperties();
|
|
4039
4137
|
},
|
|
4040
4138
|
onPointerMove: (event) => {
|
|
@@ -4459,18 +4557,21 @@ function ToolbarPart(props) {
|
|
|
4459
4557
|
"data-compact": layout.compact,
|
|
4460
4558
|
children: visible.map(itemButton)
|
|
4461
4559
|
}),
|
|
4462
|
-
overflow.length > 0 && /* @__PURE__ */ jsxs(
|
|
4463
|
-
className: "mica-wb-more
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4560
|
+
overflow.length > 0 && /* @__PURE__ */ jsxs("span", {
|
|
4561
|
+
className: "mica-wb-more",
|
|
4562
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
4563
|
+
className: "mica-wb-more-button",
|
|
4564
|
+
"aria-label": "更多工具",
|
|
4565
|
+
title: "更多工具",
|
|
4566
|
+
"aria-expanded": more,
|
|
4567
|
+
onClick: () => setMore(!more),
|
|
4568
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "ellipsis" })
|
|
4569
|
+
}), more && /* @__PURE__ */ jsx("div", {
|
|
4570
|
+
className: "mica-wb-more-menu",
|
|
4571
|
+
"aria-label": "其他工具",
|
|
4572
|
+
children: overflow.map(itemButton)
|
|
4573
|
+
})]
|
|
4574
|
+
})
|
|
4474
4575
|
] })
|
|
4475
4576
|
]
|
|
4476
4577
|
});
|
|
@@ -6222,6 +6323,9 @@ async function createWorkbench(options) {
|
|
|
6222
6323
|
let presentation = Promise.resolve();
|
|
6223
6324
|
let presentationSignature = "";
|
|
6224
6325
|
let version = 0;
|
|
6326
|
+
const simulation = disposables.add(createSimulationControl(() => {
|
|
6327
|
+
if (mode === "run") update();
|
|
6328
|
+
}));
|
|
6225
6329
|
const images = /* @__PURE__ */ new Map();
|
|
6226
6330
|
const imageLocks = /* @__PURE__ */ new Map();
|
|
6227
6331
|
const overlays = /* @__PURE__ */ new Map();
|
|
@@ -6240,6 +6344,7 @@ async function createWorkbench(options) {
|
|
|
6240
6344
|
const value = documentSession.getState();
|
|
6241
6345
|
return Object.freeze({
|
|
6242
6346
|
mode,
|
|
6347
|
+
simulationStatus: mode === "run" ? simulation.status : void 0,
|
|
6243
6348
|
busy,
|
|
6244
6349
|
dirty: value.dirty,
|
|
6245
6350
|
readOnly: value.readOnly,
|
|
@@ -6326,6 +6431,7 @@ async function createWorkbench(options) {
|
|
|
6326
6431
|
async function releaseRuntime() {
|
|
6327
6432
|
htmlViews?.closeAll();
|
|
6328
6433
|
runtimeGeneration++;
|
|
6434
|
+
simulation.detach();
|
|
6329
6435
|
const previous = runtime;
|
|
6330
6436
|
runtimeDocument = void 0;
|
|
6331
6437
|
runtime = void 0;
|
|
@@ -6429,10 +6535,22 @@ async function createWorkbench(options) {
|
|
|
6429
6535
|
update();
|
|
6430
6536
|
}).catch(error);
|
|
6431
6537
|
}
|
|
6538
|
+
function enqueue(operation) {
|
|
6539
|
+
const task = transition.then(operation);
|
|
6540
|
+
transition = task.then(() => void 0, () => void 0);
|
|
6541
|
+
return task;
|
|
6542
|
+
}
|
|
6543
|
+
function controlSimulation(operation) {
|
|
6544
|
+
return enqueue(async () => {
|
|
6545
|
+
assertReady();
|
|
6546
|
+
if (mode !== "run") throw new Error(`simulation.${operation} requires Run mode`);
|
|
6547
|
+
await simulation[operation]();
|
|
6548
|
+
});
|
|
6549
|
+
}
|
|
6432
6550
|
async function setMode(next) {
|
|
6433
6551
|
assertReady();
|
|
6434
6552
|
if (next !== "edit" && next !== "run") throw new Error(`Invalid workbench mode: ${String(next)}`);
|
|
6435
|
-
|
|
6553
|
+
return enqueue(async () => {
|
|
6436
6554
|
assertReady();
|
|
6437
6555
|
if (next === mode) return;
|
|
6438
6556
|
busy = true;
|
|
@@ -6445,6 +6563,8 @@ async function createWorkbench(options) {
|
|
|
6445
6563
|
await documentSession.setRunning(true);
|
|
6446
6564
|
await releaseRuntime();
|
|
6447
6565
|
runtime = await createRuntime("run");
|
|
6566
|
+
if (runtime === void 0) throw new Error("Run mode requires a mounted runtime");
|
|
6567
|
+
simulation.attach(runtime);
|
|
6448
6568
|
await documentSession.refreshAccess();
|
|
6449
6569
|
const permission = documentSession.getAccess().run;
|
|
6450
6570
|
if (!permission.allowed) throw new Error(permission.message);
|
|
@@ -6481,8 +6601,6 @@ async function createWorkbench(options) {
|
|
|
6481
6601
|
if (mode === "edit") refreshPresentation();
|
|
6482
6602
|
}
|
|
6483
6603
|
});
|
|
6484
|
-
transition = task.then(() => void 0, () => void 0);
|
|
6485
|
-
return task;
|
|
6486
6604
|
}
|
|
6487
6605
|
function assertEditable() {
|
|
6488
6606
|
assertReady();
|
|
@@ -6587,6 +6705,8 @@ async function createWorkbench(options) {
|
|
|
6587
6705
|
update();
|
|
6588
6706
|
},
|
|
6589
6707
|
"workbench.setMode": ({ mode }) => setMode(mode),
|
|
6708
|
+
"simulation.pause": () => controlSimulation("pause"),
|
|
6709
|
+
"simulation.resume": () => controlSimulation("resume"),
|
|
6590
6710
|
"canvas.fit": async () => {
|
|
6591
6711
|
canvas?.fit();
|
|
6592
6712
|
},
|
|
@@ -6950,7 +7070,7 @@ async function createWorkbench(options) {
|
|
|
6950
7070
|
if (activeTool === "label" && name === "") throw new Error("网标名称不能为空");
|
|
6951
7071
|
await documentSession.transact((current) => {
|
|
6952
7072
|
const anchor = materializeAnchor(routeDocumentWires(current, documentSession.getDevices().getLoadedDevices()), target, documentSession.getDevices().getLoadedDevices(), () => crypto.randomUUID());
|
|
6953
|
-
return activeTool === "label" ? addLabel(anchor.document, anchor.endpoint, name, {}, () => crypto.randomUUID()).document :
|
|
7073
|
+
return activeTool === "label" ? addLabel(anchor.document, anchor.endpoint, name, {}, () => crypto.randomUUID()).document : addPlacedReference(anchor.document, anchor.endpoint, activeTool, rotation, () => crypto.randomUUID()).document;
|
|
6954
7074
|
});
|
|
6955
7075
|
if (tool === activeTool) {
|
|
6956
7076
|
tool = "select";
|