@mica-js/editor 0.15.1 → 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-runtime.d.ts +7 -0
- package/dist/fused-runtime.js +1 -1
- package/dist/fused.d.ts +2 -0
- package/dist/fused.js +46 -13
- package/dist/fused.js.map +1 -1
- package/dist/{runtime-DuxZ_yVl.js → runtime-DuYOb1Tc.js} +77 -24
- package/dist/runtime-DuYOb1Tc.js.map +1 -0
- package/dist/workers-CazFr0iO.js +34 -0
- package/dist/{workers-BpHcfNEu.js.map → workers-CazFr0iO.js.map} +1 -1
- package/package.json +5 -5
- package/dist/runtime-DuxZ_yVl.js.map +0 -1
- package/dist/workers-BpHcfNEu.js +0 -34
package/dist/fused-runtime.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DeviceLock } from '@mica-js/document/fused';
|
|
2
2
|
import { DeviceRegistry } from '@mica-js/document/fused';
|
|
3
|
+
import { DiskWriter } from '@mica-js/sdk/fused';
|
|
3
4
|
import { Event as Event_2 } from '@mica-js/core/lifecycle';
|
|
4
5
|
import { WidgetAudioState as FusedAudioState } from '@mica-js/widget/audio-guest';
|
|
5
6
|
import { FusedDocument } from '@mica-js/document/fused';
|
|
@@ -228,6 +229,7 @@ export declare interface IFusedConnectionOptions {
|
|
|
228
229
|
/** Element that hosts the two hidden sandbox iframes. */
|
|
229
230
|
readonly container?: HTMLElement;
|
|
230
231
|
readonly resolveResource?: ResourceResolver;
|
|
232
|
+
readonly writeDisk?: DiskWriter;
|
|
231
233
|
readonly programs?: ProgramSources;
|
|
232
234
|
readonly onDiagnostic?: (diagnostic: RuntimeDiagnostic, source: FusedLogSource) => void;
|
|
233
235
|
readonly observability?: IFusedObservabilityOptions;
|
|
@@ -397,6 +399,7 @@ export declare interface IFusedHostPackageService {
|
|
|
397
399
|
/** Host resources the simulation guest reaches during preparation (RFC 0020 / RFC 0026). */
|
|
398
400
|
export declare interface IFusedHostResourceService {
|
|
399
401
|
readResource(request: ResourceRequest): Promise<Uint8Array>;
|
|
402
|
+
writeDisk(assetId: string, bytes: Uint8Array): Promise<void>;
|
|
400
403
|
resolveProgramProject(projectId: string, target: ProgramTarget): Promise<ProgramArtifact>;
|
|
401
404
|
}
|
|
402
405
|
|
|
@@ -434,6 +437,8 @@ export declare interface IFusedInvalidateEvent {
|
|
|
434
437
|
/** Request that creates the models of one run session. */
|
|
435
438
|
export declare interface IFusedLoadRequest {
|
|
436
439
|
readonly observation?: IFusedObservation;
|
|
440
|
+
readonly preparationId?: number;
|
|
441
|
+
readonly writableDisks?: boolean;
|
|
437
442
|
readonly document: FusedDocument;
|
|
438
443
|
/** Fixed positive step of every advance, in picoseconds. */
|
|
439
444
|
readonly step: TimePs;
|
|
@@ -542,6 +547,7 @@ export declare interface IFusedPackageFilesWire {
|
|
|
542
547
|
/** Preparation request of the simulation guest: verify packages and describe the scene. */
|
|
543
548
|
export declare interface IFusedPrepareRequest {
|
|
544
549
|
readonly observation?: IFusedObservation;
|
|
550
|
+
readonly preparationId?: number;
|
|
545
551
|
readonly document: FusedDocument;
|
|
546
552
|
readonly mode: FusedDisplayMode;
|
|
547
553
|
readonly deviceState?: readonly IFusedDeviceStateImage[];
|
|
@@ -626,6 +632,7 @@ export declare interface IFusedRuntimeOptions {
|
|
|
626
632
|
readonly mode?: FusedDisplayMode;
|
|
627
633
|
/** Explicit resolver of `file` and `store` property resources (RFC 0020). */
|
|
628
634
|
readonly resolveResource?: ResourceResolver;
|
|
635
|
+
readonly writeDisk?: DiskWriter;
|
|
629
636
|
/** Firmware project service of the editor (RFC 0026). */
|
|
630
637
|
readonly programs?: ProgramSources;
|
|
631
638
|
/** Receives every freshly rendered overlay, already keyed by instance. */
|
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-Di4FVpnu.js";
|
|
2
|
-
import { S as fusedSimulationService, _ as fusedDisplayService, a as createFusedRuntime, b as fusedModelChannelService, c as createModelEventRouter, g as packageLockKey, h as createHostPackageGateway, i as startFusedSimulationGuest, l as createFusedDisplay, n as startFusedDisplayGuest, o as createHostModelRouter, r as createViewSession, s as channelKey, t as loadFusedWorkerFactories, u as connectFusedWorkbench, v as fusedHostPackageService, x as fusedModelSinkService, y as fusedHostResourceService } from "./runtime-
|
|
2
|
+
import { S as fusedSimulationService, _ as fusedDisplayService, a as createFusedRuntime, b as fusedModelChannelService, c as createModelEventRouter, g as packageLockKey, h as createHostPackageGateway, i as startFusedSimulationGuest, l as createFusedDisplay, n as startFusedDisplayGuest, o as createHostModelRouter, r as createViewSession, s as channelKey, t as loadFusedWorkerFactories, u as connectFusedWorkbench, v as fusedHostPackageService, x as fusedModelSinkService, y as fusedHostResourceService } from "./runtime-DuYOb1Tc.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
|
@@ -131,6 +131,8 @@ export declare interface IAssetInfo {
|
|
|
131
131
|
export declare interface IAssetProvider {
|
|
132
132
|
select(request: IAssetRequest): Promise<IAssetInfo | undefined>;
|
|
133
133
|
read(assetId: string, signal: AbortSignal): Promise<Uint8Array>;
|
|
134
|
+
/** Returns a writable handle for the same project asset that `read` resolves. */
|
|
135
|
+
getFileHandle?(assetId: string): Promise<Pick<FileSystemFileHandle, 'createWritable'>>;
|
|
134
136
|
/**
|
|
135
137
|
* 写入用户上传的文件并返回可直接绑定的资产。宿主决定命名与替换规则;
|
|
136
138
|
* 未实现时属性面板不提供上传入口。
|
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 { Z 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-B0pN-5Mx.js";
|
|
3
|
-
import { a as createFusedRuntime, d as loggedStartupFailures, f as summarizeStartup, m as writeWorkbenchConsole, p as writeFusedLog } from "./runtime-
|
|
3
|
+
import { a as createFusedRuntime, d as loggedStartupFailures, f as summarizeStartup, m as writeWorkbenchConsole, p as writeFusedLog } from "./runtime-DuYOb1Tc.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";
|
|
@@ -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;
|
|
@@ -3379,6 +3390,22 @@ function createSimulationControl(onDidChangeStatus) {
|
|
|
3379
3390
|
};
|
|
3380
3391
|
}
|
|
3381
3392
|
//#endregion
|
|
3393
|
+
//#region src/fused/providers/disk.ts
|
|
3394
|
+
function createAssetDiskWriter(provider) {
|
|
3395
|
+
const getFileHandle = provider?.getFileHandle?.bind(provider);
|
|
3396
|
+
if (getFileHandle === void 0) return void 0;
|
|
3397
|
+
return async (assetId, bytes) => {
|
|
3398
|
+
const stream = await (await getFileHandle(assetId)).createWritable({ keepExistingData: false });
|
|
3399
|
+
try {
|
|
3400
|
+
await stream.write(bytes.slice());
|
|
3401
|
+
await stream.close();
|
|
3402
|
+
} catch (cause) {
|
|
3403
|
+
await stream.abort(cause).catch(() => void 0);
|
|
3404
|
+
throw cause;
|
|
3405
|
+
}
|
|
3406
|
+
};
|
|
3407
|
+
}
|
|
3408
|
+
//#endregion
|
|
3382
3409
|
//#region src/fused/parts/activity-bar-part.tsx
|
|
3383
3410
|
function Icon({ name }) {
|
|
3384
3411
|
return /* @__PURE__ */ jsx("span", {
|
|
@@ -4762,6 +4789,7 @@ function assetRequestAccept(descriptor, memory) {
|
|
|
4762
4789
|
}
|
|
4763
4790
|
/** 上传前按属性声明的格式快速拒绝,避免为不支持的文件打开写入流程。 */
|
|
4764
4791
|
function resourceAcceptsFile(descriptor, memory, name) {
|
|
4792
|
+
if (descriptor.type === "disk") return name.trim().length > 0;
|
|
4765
4793
|
const extension = name.split(".").at(-1)?.toLowerCase() ?? "";
|
|
4766
4794
|
if (extension === "" || extension === name.toLowerCase()) return false;
|
|
4767
4795
|
const formats = assetRequestFormats(descriptor, memory) ?? (descriptor.type === "image" ? IMAGE_EXTENSIONS : void 0);
|
|
@@ -5148,7 +5176,7 @@ function ResourceField(props) {
|
|
|
5148
5176
|
}),
|
|
5149
5177
|
children: "从项目选择…"
|
|
5150
5178
|
}),
|
|
5151
|
-
/* @__PURE__ */ jsx("button", {
|
|
5179
|
+
descriptor.type !== "disk" && /* @__PURE__ */ jsx("button", {
|
|
5152
5180
|
onClick: () => {
|
|
5153
5181
|
setMenu(false);
|
|
5154
5182
|
setPackagePicker(true);
|
|
@@ -5171,7 +5199,7 @@ function ResourceField(props) {
|
|
|
5171
5199
|
})
|
|
5172
5200
|
]
|
|
5173
5201
|
}),
|
|
5174
|
-
packagePicker && /* @__PURE__ */ jsxs("div", {
|
|
5202
|
+
descriptor.type !== "disk" && packagePicker && /* @__PURE__ */ jsxs("div", {
|
|
5175
5203
|
className: "mica-wb-resource-control",
|
|
5176
5204
|
children: [
|
|
5177
5205
|
/* @__PURE__ */ jsxs("select", {
|
|
@@ -5312,6 +5340,7 @@ function PropertyField(props) {
|
|
|
5312
5340
|
"program",
|
|
5313
5341
|
"image",
|
|
5314
5342
|
"binary",
|
|
5343
|
+
"disk",
|
|
5315
5344
|
"firmware"
|
|
5316
5345
|
].includes(descriptor.type)) return /* @__PURE__ */ jsx(ResourceField, {
|
|
5317
5346
|
name: props.name,
|
|
@@ -5378,6 +5407,7 @@ function PropertyField(props) {
|
|
|
5378
5407
|
"program",
|
|
5379
5408
|
"image",
|
|
5380
5409
|
"binary",
|
|
5410
|
+
"disk",
|
|
5381
5411
|
"firmware"
|
|
5382
5412
|
].includes(descriptor.type) && /* @__PURE__ */ jsx("button", {
|
|
5383
5413
|
title: "恢复默认值",
|
|
@@ -6913,6 +6943,7 @@ async function createWorkbench(options) {
|
|
|
6913
6943
|
const manifest = devices.get(instance.device)?.manifest;
|
|
6914
6944
|
return manifest?.view2d?.entry !== void 0 || Object.values(manifest?.properties ?? {}).some((property) => property.type === "program");
|
|
6915
6945
|
})) return void 0;
|
|
6946
|
+
const writeDisk = createAssetDiskWriter(options.assetProvider);
|
|
6916
6947
|
const result = await createFusedRuntime({
|
|
6917
6948
|
observability,
|
|
6918
6949
|
...requestedAt === void 0 ? {} : { requestedAt },
|
|
@@ -6930,6 +6961,7 @@ async function createWorkbench(options) {
|
|
|
6930
6961
|
if (request.reference.mode !== "asset" || options.assetProvider === void 0) throw new Error("No asset provider is configured");
|
|
6931
6962
|
return options.assetProvider.read(request.reference.assetId, abort.signal);
|
|
6932
6963
|
},
|
|
6964
|
+
...writeDisk === void 0 ? {} : { writeDisk },
|
|
6933
6965
|
onDiagnostic: (diagnostic) => {
|
|
6934
6966
|
if (generation !== runtimeGeneration) return;
|
|
6935
6967
|
report({
|
|
@@ -7594,6 +7626,7 @@ async function createWorkbench(options) {
|
|
|
7594
7626
|
if (descriptor === void 0 || ![
|
|
7595
7627
|
"image",
|
|
7596
7628
|
"binary",
|
|
7629
|
+
"disk",
|
|
7597
7630
|
"firmware",
|
|
7598
7631
|
"program"
|
|
7599
7632
|
].includes(descriptor.type)) throw new Error("Unknown resource property");
|