@mica-js/editor 0.8.2 → 0.8.3

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 CHANGED
@@ -4428,6 +4428,7 @@ function SidebarPart(props) {
4428
4428
  //#region src/fused/parts/toolbar-part.tsx
4429
4429
  function ToolbarPart(props) {
4430
4430
  const [more, setMore] = useState(false);
4431
+ const [controlling, setControlling] = useState(false);
4431
4432
  const toolbar = useRef(null);
4432
4433
  const modeGroup = useRef(null);
4433
4434
  const measurements = useRef(null);
@@ -4482,6 +4483,14 @@ function ToolbarPart(props) {
4482
4483
  }, [items]);
4483
4484
  const visible = items.slice(0, layout.count);
4484
4485
  const overflow = items.slice(layout.count);
4486
+ const runMode = props.state.mode === "run";
4487
+ const paused = props.state.simulationStatus === "paused";
4488
+ const canControl = !runMode || paused || props.state.simulationStatus === "running";
4489
+ const control = (action) => {
4490
+ setMore(false);
4491
+ setControlling(true);
4492
+ action().catch(props.onError).finally(() => setControlling(false));
4493
+ };
4485
4494
  const execute = (item) => {
4486
4495
  setMore(false);
4487
4496
  if (!props.registry.enabled(item)) return;
@@ -4530,22 +4539,22 @@ function ToolbarPart(props) {
4530
4539
  })
4531
4540
  ]
4532
4541
  }),
4533
- /* @__PURE__ */ jsx("div", {
4542
+ /* @__PURE__ */ jsxs("div", {
4534
4543
  ref: modeGroup,
4535
4544
  className: "mica-wb-mode",
4536
4545
  role: "group",
4537
- "aria-label": "工作台模式",
4538
- "data-mode": props.state.mode,
4539
- children: ["edit", "run"].map((mode) => /* @__PURE__ */ jsxs("button", {
4540
- "aria-pressed": props.state.mode === mode,
4541
- disabled: props.state.busy,
4542
- className: props.state.mode === mode ? "is-active" : "",
4543
- onClick: () => {
4544
- setMore(false);
4545
- props.context.workbench.setMode(mode).catch(props.onError);
4546
- },
4547
- children: [/* @__PURE__ */ jsx(Icon, { name: mode === "edit" ? "edit" : "play" }), mode === "edit" ? "编辑" : "运行"]
4548
- }, mode))
4546
+ "aria-label": "仿真控制",
4547
+ children: [/* @__PURE__ */ jsxs("button", {
4548
+ className: "is-primary",
4549
+ disabled: props.state.busy || controlling || !canControl,
4550
+ onClick: () => control(() => !runMode ? props.context.workbench.setMode("run") : props.context.workbench.executeCommand(paused ? "simulation.resume" : "simulation.pause")),
4551
+ children: [/* @__PURE__ */ jsx(Icon, { name: runMode && !paused ? "debug-pause" : "play" }), runMode ? paused ? "继续" : "暂停" : "运行"]
4552
+ }), runMode && /* @__PURE__ */ jsxs("button", {
4553
+ disabled: props.state.busy || controlling,
4554
+ title: "结束仿真并返回编辑",
4555
+ onClick: () => control(() => props.context.workbench.setMode("edit")),
4556
+ children: [/* @__PURE__ */ jsx(Icon, { name: "debug-restart" }), "复位"]
4557
+ })]
4549
4558
  }),
4550
4559
  items.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
4551
4560
  /* @__PURE__ */ jsx("span", {