@mica-js/editor 0.12.0 → 0.14.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 CHANGED
@@ -35,6 +35,8 @@ await workbench.dispose();
35
35
 
36
36
  宿主直接传入 `FusedDocument`,自行维护项目身份和存储。`getDocument()` / `onDidChangeContent` 提供当前快照;可选的 `saveDocument(snapshot)` 完成后标记对应版本已保存,缺失时 `save()` 明确拒绝。器件 Provider 返回锁定发布版本的 `PackageFiles`,工作台校验文件清单和摘要。
37
37
 
38
+ `deviceStateProvider` 可持久化指定器件的二进制运行状态。`bindings` 按器件 ID 和锁定版本选择启动属性、查询方法与变化事件。启动时优先装载 `read` 返回的映像,缺失时使用电路配置。宿主用文档作用域与状态槽键定位 `read` / `write`,写入确认后运行时才视为已保存。工作台在停止、重启和关闭时等待保存,失败后可重试。预热不访问此存储。
39
+
38
40
  `assetProvider.select({ kind, formats, signal })` 打开宿主资产库 UI,返回 `{ id, name }` 或以 `undefined` 取消;`name` 包含文件扩展名。`read(id, signal)` 返回二进制,编辑器不枚举资产。普通资源仅支持 `asset` / `package`;`program` 另支持 `project`,使用 `programs.projects.select({ ...target, templateIds }, signal)` 选择项目、`resolve(id, target, signal?)` 取得程序产物。项目选择能力可省略,已有引用仍可解析;程序文件集资产使用 ZIP,校验解包后交给模型只读访问。
39
41
 
40
42
  属性字段以单行显示来源图标、引用名称和默认标记,通过同行图标打开来源菜单或内存装载设置浮层;新内容读取校验成功后才提交,取消和失败保留原值。项目选择的请求包含 `templateIds`,按属性的 `templates` 顺序传递,未声明时为空数组;宿主负责模板展示与项目创建,编辑器只保存返回的项目引用。内置资源从当前器件包选择,项目可独立打开。宿主接口合同见 [RFC 0028](../../docs/rfc/0028-workbench-host-resources.md)。
@@ -1 +1 @@
1
- export { y as ASSET_ROOT_DIRECTORY, s as DEFAULT_HTML_VIEW_THEME, b as ENVIRONMENT_BOOTSTRAP_FILE, x as ENVIRONMENT_CONTENT_DOCUMENT_FILE, S as ENVIRONMENT_CONTENT_FILE, C as ENVIRONMENT_DOCUMENT_FILE, w as ENVIRONMENT_WORKER_FILE, L as HTML_VIEW_ACK, R as HTML_VIEW_ASSETS, z as HTML_VIEW_ASSETS_ACK, B as HTML_VIEW_ATTACH, V as HTML_VIEW_ATTACH_ACK, H as HTML_VIEW_CHILD_CONNECT, U as HTML_VIEW_CHILD_HELLO, W as HTML_VIEW_CHILD_PREPARED, G as HTML_VIEW_CONNECT, T as HTML_VIEW_CONTENT_POLICY, E as HTML_VIEW_ENVIRONMENT_POLICY, K as HTML_VIEW_FRAME_PARAM, q as HtmlViewError, N as VIEW_ENV_LABEL, c as applyHtmlViewTheme, t as assertAssetPath, D as assetRootUrl, O as authorBaseUrl, n as createDeviceViewSession, a as createHtmlViewHost, r as createHtmlViewRuntimeSource, k as decodeDocument, J as fusedHtmlAssetService, Y as fusedHtmlContentViewService, X as fusedHtmlHostControlService, Z as fusedHtmlHostService, P as htmlEnvironmentUrl, i as htmlViewDeviceDeclaration, o as htmlViewKey, l as htmlViewThemeCss, u as htmlViewThemeEquals, Q as isHtmlViewError, A as mimeTypeOf, F as newHtmlEnvironmentId, d as normalizeHtmlViewTheme, I as parseHtmlViewBase, j as resolveAssetRequest, M as withHtmlDocumentPreamble } from "./html-HXwZq1my.js";
1
+ export { y as ASSET_ROOT_DIRECTORY, s as DEFAULT_HTML_VIEW_THEME, b as ENVIRONMENT_BOOTSTRAP_FILE, x as ENVIRONMENT_CONTENT_DOCUMENT_FILE, S as ENVIRONMENT_CONTENT_FILE, C as ENVIRONMENT_DOCUMENT_FILE, w as ENVIRONMENT_WORKER_FILE, L as HTML_VIEW_ACK, R as HTML_VIEW_ASSETS, z as HTML_VIEW_ASSETS_ACK, B as HTML_VIEW_ATTACH, V as HTML_VIEW_ATTACH_ACK, H as HTML_VIEW_CHILD_CONNECT, U as HTML_VIEW_CHILD_HELLO, W as HTML_VIEW_CHILD_PREPARED, G as HTML_VIEW_CONNECT, T as HTML_VIEW_CONTENT_POLICY, E as HTML_VIEW_ENVIRONMENT_POLICY, K as HTML_VIEW_FRAME_PARAM, q as HtmlViewError, N as VIEW_ENV_LABEL, c as applyHtmlViewTheme, t as assertAssetPath, D as assetRootUrl, O as authorBaseUrl, n as createDeviceViewSession, a as createHtmlViewHost, r as createHtmlViewRuntimeSource, k as decodeDocument, J as fusedHtmlAssetService, Y as fusedHtmlContentViewService, X as fusedHtmlHostControlService, Z as fusedHtmlHostService, P as htmlEnvironmentUrl, i as htmlViewDeviceDeclaration, o as htmlViewKey, l as htmlViewThemeCss, u as htmlViewThemeEquals, Q as isHtmlViewError, A as mimeTypeOf, F as newHtmlEnvironmentId, d as normalizeHtmlViewTheme, I as parseHtmlViewBase, j as resolveAssetRequest, M as withHtmlDocumentPreamble } from "./html-CyZiE7kS.js";
@@ -138,6 +138,32 @@ export declare type FusedView2DFactory = (context: IFusedView2DContext) => IFuse
138
138
 
139
139
  export declare type FusedViewInputType = 'pointerdown' | 'pointerup' | 'pointermove';
140
140
 
141
+ declare interface IDeviceStateBinding {
142
+ readonly device: string;
143
+ readonly version: string;
144
+ readonly slot: string;
145
+ readonly formatVersion: number;
146
+ readonly byteLength: number;
147
+ readonly property: string;
148
+ readonly method: string;
149
+ readonly event: string;
150
+ }
151
+
152
+ /** The caller scopes these keys to its account/workspace and stable document ID. */
153
+ declare interface IDeviceStateKey {
154
+ readonly instanceId: string;
155
+ readonly device: string;
156
+ readonly slot: string;
157
+ readonly formatVersion: number;
158
+ }
159
+
160
+ declare interface IDeviceStateProvider {
161
+ readonly bindings: readonly IDeviceStateBinding[];
162
+ read(key: IDeviceStateKey, signal: AbortSignal): Promise<Uint8Array | undefined>;
163
+ /** Atomically replace the slot. Resolve only after the write has committed. */
164
+ write(key: IDeviceStateKey, image: Uint8Array, signal: AbortSignal): Promise<void>;
165
+ }
166
+
141
167
  /** Audio handles belong to one instance generation, including while its body is hidden. */
142
168
  export declare interface IFusedAudio extends Omit<WidgetAudioApi, 'onStateChange' | 'createStream'> {
143
169
  readonly onDidChangeState: Event_2<FusedAudioState>;
@@ -189,6 +215,16 @@ export declare interface IFusedConnectionOptions {
189
215
  readonly onDiagnostic?: (diagnostic: RuntimeDiagnostic) => void;
190
216
  }
191
217
 
218
+ /** A configured slot and, if available, its persisted startup bytes. */
219
+ declare interface IFusedDeviceStateImage {
220
+ readonly instanceId: string;
221
+ readonly property: string;
222
+ readonly method: string;
223
+ readonly event: string;
224
+ readonly byteLength: number;
225
+ readonly image?: Uint8Array;
226
+ }
227
+
192
228
  /** 2D presentation surface the editor drives (RFC 0022). */
193
229
  export declare interface IFusedDisplay {
194
230
  /** Mode of the current presentation; `undefined` before the first preparation. */
@@ -382,6 +418,8 @@ export declare interface IFusedLoadRequest {
382
418
  readonly simulationPacing?: FusedSimulationPacing;
383
419
  /** Explicit simulator batch-execution switch; omitted uses the board default. */
384
420
  readonly batchExecution?: boolean;
421
+ readonly deviceState?: readonly IFusedDeviceStateImage[];
422
+ readonly stateGeneration?: number;
385
423
  }
386
424
 
387
425
  /** Model lane served by the simulation guest to the display guest over the direct port. */
@@ -427,6 +465,7 @@ export declare interface IFusedModelEventWire {
427
465
  readonly instanceId: string;
428
466
  readonly event: string;
429
467
  readonly payload: ModelEvent<Value>;
468
+ readonly stateGeneration?: number;
430
469
  }
431
470
 
432
471
  /** Model event lane served by the display guest to the simulation guest. */
@@ -459,10 +498,15 @@ export declare interface IFusedPackageFilesWire {
459
498
  export declare interface IFusedPrepareRequest {
460
499
  readonly document: FusedDocument;
461
500
  readonly mode: FusedDisplayMode;
501
+ readonly deviceState?: readonly IFusedDeviceStateImage[];
462
502
  }
463
503
 
464
504
  export declare interface IFusedPrepareResult {
465
505
  readonly instances: readonly IFusedInstancePresentation[];
506
+ readonly deviceState?: readonly {
507
+ readonly instanceId: string;
508
+ readonly image: Uint8Array;
509
+ }[];
466
510
  }
467
511
 
468
512
  declare interface IFusedProgramFilesSnapshot {
@@ -516,6 +560,7 @@ export declare interface IFusedRuntime {
516
560
  }
517
561
 
518
562
  export declare interface IFusedRuntimeOptions {
563
+ readonly deviceStateProvider?: IDeviceStateProvider;
519
564
  /** Caller-owned browser context; resume it directly within a user gesture for autoplay. */
520
565
  readonly audio?: IFusedAudioOptions;
521
566
  /** Fused `.sch` version 2 document; the simulation guest snapshots it. */
@@ -1,3 +1,3 @@
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-hyeAcSP7.js";
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 { _ 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-_9IqvWDa.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
@@ -121,6 +121,11 @@ export declare interface IAssetInfo {
121
121
  export declare interface IAssetProvider {
122
122
  select(request: IAssetRequest): Promise<IAssetInfo | undefined>;
123
123
  read(assetId: string, signal: AbortSignal): Promise<Uint8Array>;
124
+ /**
125
+ * 写入用户上传的文件并返回可直接绑定的资产。宿主决定命名与替换规则;
126
+ * 未实现时属性面板不提供上传入口。
127
+ */
128
+ upload?(request: IAssetUploadRequest): Promise<IAssetInfo | undefined>;
124
129
  }
125
130
 
126
131
  export declare interface IAssetRequest {
@@ -129,6 +134,24 @@ export declare interface IAssetRequest {
129
134
  readonly signal: AbortSignal;
130
135
  }
131
136
 
137
+ export declare interface IAssetUploadRequest {
138
+ readonly kind: 'image' | 'binary' | 'program';
139
+ readonly formats?: readonly string[];
140
+ /** 目标属性的器件位号;宿主据此命名资产,实例没有位号时为 `undefined`。 */
141
+ readonly designator: string | undefined;
142
+ /** 目标属性的名称,与位号一起构成宿主侧的资产名。 */
143
+ readonly property: string;
144
+ /** 上传文件的原始文件名,含扩展名。 */
145
+ readonly name: string;
146
+ readonly bytes: Uint8Array;
147
+ /**
148
+ * 可以原位替换的资产 UUID:当前绑定,且文档里没有其他属性引用它。
149
+ * 宿主复用它时保留 UUID,用户不会为同一个属性积累历史固件。
150
+ */
151
+ readonly replace: string | undefined;
152
+ readonly signal: AbortSignal;
153
+ }
154
+
132
155
  /**
133
156
  * A parsed condition. Parsing validates once; `evaluate` is pure and reads keys through the
134
157
  * supplied lookup, so callers can evaluate the same condition against several scopes.
@@ -238,6 +261,32 @@ export declare interface IDeviceAdditionContext extends IDocumentAccessContext {
238
261
 
239
262
  export { IDeviceProvider }
240
263
 
264
+ export declare interface IDeviceStateBinding {
265
+ readonly device: string;
266
+ readonly version: string;
267
+ readonly slot: string;
268
+ readonly formatVersion: number;
269
+ readonly byteLength: number;
270
+ readonly property: string;
271
+ readonly method: string;
272
+ readonly event: string;
273
+ }
274
+
275
+ /** The caller scopes these keys to its account/workspace and stable document ID. */
276
+ export declare interface IDeviceStateKey {
277
+ readonly instanceId: string;
278
+ readonly device: string;
279
+ readonly slot: string;
280
+ readonly formatVersion: number;
281
+ }
282
+
283
+ export declare interface IDeviceStateProvider {
284
+ readonly bindings: readonly IDeviceStateBinding[];
285
+ read(key: IDeviceStateKey, signal: AbortSignal): Promise<Uint8Array | undefined>;
286
+ /** Atomically replace the slot. Resolve only after the write has committed. */
287
+ write(key: IDeviceStateKey, image: Uint8Array, signal: AbortSignal): Promise<void>;
288
+ }
289
+
241
290
  export declare interface IDocumentAccess {
242
291
  readonly edit: AccessDecision;
243
292
  readonly run: AccessDecision;
@@ -505,6 +554,7 @@ export declare interface IWorkbenchExtensionContext {
505
554
  }
506
555
 
507
556
  export declare interface IWorkbenchOptions {
557
+ readonly deviceStateProvider?: IDeviceStateProvider;
508
558
  /** Caller-owned browser context, automatically resumed on document-wide user gestures. */
509
559
  readonly audio?: IFusedAudioOptions;
510
560
  readonly container: HTMLElement;