@histoire/plugin-kit 0.0.0-stage → 1.0.0-beta.2

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.
Files changed (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +182 -2
  3. package/dist/builtins.d.ts +13 -0
  4. package/dist/builtins.d.ts.map +1 -0
  5. package/dist/builtins.js +7 -0
  6. package/dist/define.d.ts +19 -0
  7. package/dist/define.d.ts.map +1 -0
  8. package/dist/define.js +43 -0
  9. package/dist/errors.d.ts +11 -0
  10. package/dist/errors.d.ts.map +1 -0
  11. package/dist/errors.js +14 -0
  12. package/dist/frame.d.ts +6 -0
  13. package/dist/frame.d.ts.map +1 -0
  14. package/dist/frame.js +3 -0
  15. package/dist/host/actions.d.ts +37 -0
  16. package/dist/host/actions.d.ts.map +1 -0
  17. package/dist/host/actions.js +47 -0
  18. package/dist/host/create-host.d.ts +9 -0
  19. package/dist/host/create-host.d.ts.map +1 -0
  20. package/dist/host/create-host.js +194 -0
  21. package/dist/host/diagnostics.d.ts +14 -0
  22. package/dist/host/diagnostics.d.ts.map +1 -0
  23. package/dist/host/diagnostics.js +26 -0
  24. package/dist/host/frames.d.ts +43 -0
  25. package/dist/host/frames.d.ts.map +1 -0
  26. package/dist/host/frames.js +63 -0
  27. package/dist/host/generation.d.ts +24 -0
  28. package/dist/host/generation.d.ts.map +1 -0
  29. package/dist/host/generation.js +38 -0
  30. package/dist/host/install.d.ts +43 -0
  31. package/dist/host/install.d.ts.map +1 -0
  32. package/dist/host/install.js +168 -0
  33. package/dist/host/manifest.d.ts +23 -0
  34. package/dist/host/manifest.d.ts.map +1 -0
  35. package/dist/host/manifest.js +37 -0
  36. package/dist/host/mount.d.ts +15 -0
  37. package/dist/host/mount.d.ts.map +1 -0
  38. package/dist/host/mount.js +57 -0
  39. package/dist/host/ordering.d.ts +20 -0
  40. package/dist/host/ordering.d.ts.map +1 -0
  41. package/dist/host/ordering.js +12 -0
  42. package/dist/host/plugin-api.d.ts +33 -0
  43. package/dist/host/plugin-api.d.ts.map +1 -0
  44. package/dist/host/plugin-api.js +113 -0
  45. package/dist/host/preferences.d.ts +57 -0
  46. package/dist/host/preferences.d.ts.map +1 -0
  47. package/dist/host/preferences.js +137 -0
  48. package/dist/host/registry.d.ts +43 -0
  49. package/dist/host/registry.d.ts.map +1 -0
  50. package/dist/host/registry.js +123 -0
  51. package/dist/host/resources.d.ts +20 -0
  52. package/dist/host/resources.d.ts.map +1 -0
  53. package/dist/host/resources.js +45 -0
  54. package/dist/ids.d.ts +32 -0
  55. package/dist/ids.d.ts.map +1 -0
  56. package/dist/ids.js +51 -0
  57. package/dist/index.d.ts +27 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.js +16 -0
  60. package/dist/react/index.d.ts +19 -0
  61. package/dist/react/index.d.ts.map +1 -0
  62. package/dist/react/index.js +25 -0
  63. package/dist/render/keys.d.ts +7 -0
  64. package/dist/render/keys.d.ts.map +1 -0
  65. package/dist/render/keys.js +15 -0
  66. package/dist/render/mount-manager.d.ts +36 -0
  67. package/dist/render/mount-manager.d.ts.map +1 -0
  68. package/dist/render/mount-manager.js +128 -0
  69. package/dist/render/view-binding.d.ts +19 -0
  70. package/dist/render/view-binding.d.ts.map +1 -0
  71. package/dist/render/view-binding.js +7 -0
  72. package/dist/render/workbench-components.d.ts +39 -0
  73. package/dist/render/workbench-components.d.ts.map +1 -0
  74. package/dist/render/workbench-components.js +76 -0
  75. package/dist/session/context.d.ts +66 -0
  76. package/dist/session/context.d.ts.map +1 -0
  77. package/dist/session/context.js +173 -0
  78. package/dist/session/frames.d.ts +46 -0
  79. package/dist/session/frames.d.ts.map +1 -0
  80. package/dist/session/frames.js +68 -0
  81. package/dist/shortcuts.d.ts +94 -0
  82. package/dist/shortcuts.d.ts.map +1 -0
  83. package/dist/shortcuts.js +157 -0
  84. package/dist/styles.d.ts +3 -0
  85. package/dist/styles.d.ts.map +1 -0
  86. package/dist/styles.js +25 -0
  87. package/dist/svelte4/index.d.ts +27 -0
  88. package/dist/svelte4/index.d.ts.map +1 -0
  89. package/dist/svelte4/index.js +16 -0
  90. package/dist/svelte5/index.d.ts +21 -0
  91. package/dist/svelte5/index.d.ts.map +1 -0
  92. package/dist/svelte5/index.js +40 -0
  93. package/dist/types/actions.d.ts +12 -0
  94. package/dist/types/actions.d.ts.map +1 -0
  95. package/dist/types/actions.js +1 -0
  96. package/dist/types/base.d.ts +12 -0
  97. package/dist/types/base.d.ts.map +1 -0
  98. package/dist/types/base.js +1 -0
  99. package/dist/types/canvas.d.ts +150 -0
  100. package/dist/types/canvas.d.ts.map +1 -0
  101. package/dist/types/canvas.js +1 -0
  102. package/dist/types/channel.d.ts +28 -0
  103. package/dist/types/channel.d.ts.map +1 -0
  104. package/dist/types/channel.js +1 -0
  105. package/dist/types/commands.d.ts +35 -0
  106. package/dist/types/commands.d.ts.map +1 -0
  107. package/dist/types/commands.js +1 -0
  108. package/dist/types/common.d.ts +7 -0
  109. package/dist/types/common.d.ts.map +1 -0
  110. package/dist/types/common.js +1 -0
  111. package/dist/types/context.d.ts +72 -0
  112. package/dist/types/context.d.ts.map +1 -0
  113. package/dist/types/context.js +1 -0
  114. package/dist/types/contribution.d.ts +56 -0
  115. package/dist/types/contribution.d.ts.map +1 -0
  116. package/dist/types/contribution.js +1 -0
  117. package/dist/types/frame.d.ts +41 -0
  118. package/dist/types/frame.d.ts.map +1 -0
  119. package/dist/types/frame.js +1 -0
  120. package/dist/types/host.d.ts +123 -0
  121. package/dist/types/host.d.ts.map +1 -0
  122. package/dist/types/host.js +1 -0
  123. package/dist/types/index.d.ts +19 -0
  124. package/dist/types/index.d.ts.map +1 -0
  125. package/dist/types/index.js +1 -0
  126. package/dist/types/inspector.d.ts +38 -0
  127. package/dist/types/inspector.d.ts.map +1 -0
  128. package/dist/types/inspector.js +1 -0
  129. package/dist/types/menus.d.ts +71 -0
  130. package/dist/types/menus.d.ts.map +1 -0
  131. package/dist/types/menus.js +1 -0
  132. package/dist/types/plugin.d.ts +133 -0
  133. package/dist/types/plugin.d.ts.map +1 -0
  134. package/dist/types/plugin.js +1 -0
  135. package/dist/types/preferences.d.ts +31 -0
  136. package/dist/types/preferences.d.ts.map +1 -0
  137. package/dist/types/preferences.js +1 -0
  138. package/dist/types/services.d.ts +175 -0
  139. package/dist/types/services.d.ts.map +1 -0
  140. package/dist/types/services.js +1 -0
  141. package/dist/types/shell.d.ts +47 -0
  142. package/dist/types/shell.d.ts.map +1 -0
  143. package/dist/types/shell.js +1 -0
  144. package/dist/types/toolbar.d.ts +59 -0
  145. package/dist/types/toolbar.d.ts.map +1 -0
  146. package/dist/types/toolbar.js +1 -0
  147. package/dist/types/view.d.ts +82 -0
  148. package/dist/types/view.d.ts.map +1 -0
  149. package/dist/types/view.js +1 -0
  150. package/dist/vue/components.d.ts +122 -0
  151. package/dist/vue/components.d.ts.map +1 -0
  152. package/dist/vue/components.js +112 -0
  153. package/dist/vue/index.d.ts +21 -0
  154. package/dist/vue/index.d.ts.map +1 -0
  155. package/dist/vue/index.js +47 -0
  156. package/dist/vue/mount.d.ts +9 -0
  157. package/dist/vue/mount.d.ts.map +1 -0
  158. package/dist/vue/mount.js +32 -0
  159. package/dist/vue/panel-action.d.ts +60 -0
  160. package/dist/vue/panel-action.d.ts.map +1 -0
  161. package/dist/vue/panel-action.js +28 -0
  162. package/package.json +92 -3
@@ -0,0 +1,14 @@
1
+ import type { PluginDiagnostic } from '../types/host.js';
2
+ /** Append-only diagnostics log of one host. Failures are recorded, never retried. */
3
+ export interface DiagnosticsLog {
4
+ /** Records a diagnostic unless the same error object was already recorded for the plugin. */
5
+ record: (diagnostic: PluginDiagnostic) => void;
6
+ /** Frozen snapshot; identity changes only when a diagnostic is added. */
7
+ list: () => ReadonlyArray<PluginDiagnostic>;
8
+ }
9
+ /**
10
+ * Creates a diagnostics log.
11
+ * @param onChange Called after each new diagnostic.
12
+ */
13
+ export declare function createDiagnosticsLog(onChange: () => void): DiagnosticsLog;
14
+ //# sourceMappingURL=diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/host/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAExD,qFAAqF;AACrF,MAAM,WAAW,cAAc;IAC7B,6FAA6F;IAC7F,MAAM,EAAE,CAAC,UAAU,EAAE,gBAAgB,KAAK,IAAI,CAAA;IAC9C,yEAAyE;IACzE,IAAI,EAAE,MAAM,aAAa,CAAC,gBAAgB,CAAC,CAAA;CAC5C;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,cAAc,CAsBzE"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Creates a diagnostics log.
3
+ * @param onChange Called after each new diagnostic.
4
+ */
5
+ export function createDiagnosticsLog(onChange) {
6
+ let snapshot = Object.freeze([]);
7
+ /**
8
+ * Whether `diagnostic` repeats an error already attributed to the same plugin, e.g. a
9
+ * rejected registration rethrown out of `setup`.
10
+ * @param diagnostic Candidate entry.
11
+ */
12
+ function isRepeat(diagnostic) {
13
+ const { error, pluginId } = diagnostic;
14
+ return typeof error === 'object' && error !== null
15
+ && snapshot.some(entry => entry.pluginId === pluginId && entry.error === error);
16
+ }
17
+ return {
18
+ record(diagnostic) {
19
+ if (isRepeat(diagnostic))
20
+ return;
21
+ snapshot = Object.freeze([...snapshot, Object.freeze({ ...diagnostic })]);
22
+ onChange();
23
+ },
24
+ list: () => snapshot,
25
+ };
26
+ }
@@ -0,0 +1,43 @@
1
+ import type { PluginChannel } from '../types/channel.js';
2
+ import type { Disposer } from '../types/common.js';
3
+ import type { FrameRef, WorkbenchContext } from '../types/context.js';
4
+ import type { PluginFrameRef, PluginFrameWindow, WorkbenchPluginApi } from '../types/plugin.js';
5
+ /**
6
+ * Key under which a host exposes its {@link PluginFrameService} on the root context it passes to
7
+ * `createExtensionHost`. `Symbol.for` lets separately bundled hosts share it without an import.
8
+ */
9
+ export declare const PLUGIN_FRAMES_SERVICE: unique symbol;
10
+ /** Host-level frame messaging, shared by every plugin of one extension host. */
11
+ export interface PluginFrameService {
12
+ /** Frames where `pluginId`'s frame module is attached. */
13
+ list: (pluginId: string) => ReadonlyArray<PluginFrameRef>;
14
+ /**
15
+ * Channel bound to the exact actor of `frame` (its `actorId` when given).
16
+ * @param signal Plugin lifetime; aborting it releases the channel's listeners.
17
+ */
18
+ open: (pluginId: string, frame: FrameRef, signal: AbortSignal) => PluginChannel;
19
+ /** Resolve a window only while this plugin's exact actor remains attached. */
20
+ window?: (pluginId: string, frame: PluginFrameRef) => PluginFrameWindow | undefined;
21
+ /** Observes frame-side failures attributed to `pluginId`. */
22
+ onError: (pluginId: string, listener: (error: Error) => void) => Disposer;
23
+ /** Observes actor attach and detach of any plugin; `api.frames.subscribe` narrows it. */
24
+ subscribe: (listener: () => void) => Disposer;
25
+ }
26
+ /**
27
+ * `api.frames` of one plugin. Channels and failure subscriptions belong to the plugin and are
28
+ * released with it; hosts without frame messaging report the service unavailable.
29
+ * @param options Plugin identity, root context and ownership hooks.
30
+ * @param options.id Plugin id.
31
+ * @param options.context Root context, possibly carrying the frame service.
32
+ * @param options.signal Plugin scope signal.
33
+ * @param options.reportError Records a diagnostic attributed to the plugin.
34
+ * @param options.track Ties a resource to the plugin lifetime.
35
+ */
36
+ export declare function createPluginFrames(options: {
37
+ id: string;
38
+ context: WorkbenchContext;
39
+ signal: AbortSignal;
40
+ reportError: (error: unknown) => void;
41
+ track: (release: () => void) => Disposer;
42
+ }): WorkbenchPluginApi['frames'];
43
+ //# sourceMappingURL=frames.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frames.d.ts","sourceRoot":"","sources":["../../src/host/frames.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAE/F;;;GAGG;AACH,eAAO,MAAM,qBAAqB,eAA4C,CAAA;AAE9E,gFAAgF;AAChF,MAAM,WAAW,kBAAkB;IACjC,0DAA0D;IAC1D,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,aAAa,CAAC,cAAc,CAAC,CAAA;IACzD;;;OAGG;IACH,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,KAAK,aAAa,CAAA;IAC/E,8EAA8E;IAC9E,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,KAAK,iBAAiB,GAAG,SAAS,CAAA;IACnF,6DAA6D;IAC7D,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,KAAK,QAAQ,CAAA;IACzE,yFAAyF;IACzF,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,QAAQ,CAAA;CAC9C;AAeD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,WAAW,CAAC;IAAC,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,IAAI,KAAK,QAAQ,CAAA;CAAE,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CA+BzN"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Key under which a host exposes its {@link PluginFrameService} on the root context it passes to
3
+ * `createExtensionHost`. `Symbol.for` lets separately bundled hosts share it without an import.
4
+ */
5
+ export const PLUGIN_FRAMES_SERVICE = Symbol.for('@histoire/plugin-kit/frames');
6
+ /** Coded failure without a runtime protocol dependency. */
7
+ function failure(code, message) {
8
+ return Object.assign(new Error(`[histoire plugin] ${message}`), { code });
9
+ }
10
+ /**
11
+ * Identity of a frame list: changes only when an actor of the plugin attaches or detaches.
12
+ * @param frames Frames listed for one plugin.
13
+ */
14
+ function listKey(frames) {
15
+ return JSON.stringify(frames.map(frame => [frame.key, frame.actorId]));
16
+ }
17
+ /**
18
+ * `api.frames` of one plugin. Channels and failure subscriptions belong to the plugin and are
19
+ * released with it; hosts without frame messaging report the service unavailable.
20
+ * @param options Plugin identity, root context and ownership hooks.
21
+ * @param options.id Plugin id.
22
+ * @param options.context Root context, possibly carrying the frame service.
23
+ * @param options.signal Plugin scope signal.
24
+ * @param options.reportError Records a diagnostic attributed to the plugin.
25
+ * @param options.track Ties a resource to the plugin lifetime.
26
+ */
27
+ export function createPluginFrames(options) {
28
+ const service = Reflect.get(options.context, PLUGIN_FRAMES_SERVICE);
29
+ if (service && !options.signal.aborted)
30
+ options.track(service.onError(options.id, options.reportError));
31
+ const list = () => service && !options.signal.aborted ? service.list(options.id) : [];
32
+ return {
33
+ list,
34
+ window(frame) {
35
+ return options.signal.aborted ? undefined : service?.window?.(options.id, frame);
36
+ },
37
+ subscribe(listener) {
38
+ if (!service || options.signal.aborted)
39
+ return () => { };
40
+ // Host notifications cover every plugin's actors: forward only changes of this plugin's list.
41
+ let last = listKey(list());
42
+ return options.track(service.subscribe(() => {
43
+ const next = listKey(list());
44
+ if (next === last)
45
+ return;
46
+ last = next;
47
+ try {
48
+ listener();
49
+ }
50
+ catch (error) {
51
+ options.reportError(error);
52
+ }
53
+ }));
54
+ },
55
+ open(frame) {
56
+ if (!service)
57
+ throw failure('CAPABILITY_UNAVAILABLE', 'frame channels are unavailable in this host');
58
+ if (options.signal.aborted)
59
+ throw failure('RUNTIME_CHANGED', `plugin "${options.id}" was disposed`);
60
+ return service.open(options.id, frame, options.signal);
61
+ },
62
+ };
63
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Generation tokens. Each scope (host, plugin, selection, frame, action) owns one
3
+ * `AbortController`. Operations capture the scope when they start and drop their result
4
+ * when `active` turned false meanwhile, so a stale generation can never register,
5
+ * update or publish into the current one.
6
+ */
7
+ /** One generation of an owner; retired once, never reactivated. */
8
+ export interface Scope {
9
+ /** Aborted when this scope or any parent retires. */
10
+ readonly signal: AbortSignal;
11
+ /** `false` once retired; captured operations check it before applying results. */
12
+ readonly active: boolean;
13
+ /** Retires this scope and every child; idempotent. */
14
+ retire: () => void;
15
+ /** Creates a child scope retired together with this one. */
16
+ child: () => Scope;
17
+ }
18
+ /**
19
+ * Creates a scope that retires when any parent signal aborts.
20
+ * Parent listeners are removed on retirement so long-lived parents do not accumulate them.
21
+ * @param parents Parent signals; `undefined` entries are ignored.
22
+ */
23
+ export declare function createScope(...parents: ReadonlyArray<AbortSignal | undefined>): Scope;
24
+ //# sourceMappingURL=generation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generation.d.ts","sourceRoot":"","sources":["../../src/host/generation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,mEAAmE;AACnE,MAAM,WAAW,KAAK;IACpB,qDAAqD;IACrD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;IAC5B,kFAAkF;IAClF,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB,sDAAsD;IACtD,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB,4DAA4D;IAC5D,KAAK,EAAE,MAAM,KAAK,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,OAAO,EAAE,aAAa,CAAC,WAAW,GAAG,SAAS,CAAC,GAAG,KAAK,CA0BrF"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Generation tokens. Each scope (host, plugin, selection, frame, action) owns one
3
+ * `AbortController`. Operations capture the scope when they start and drop their result
4
+ * when `active` turned false meanwhile, so a stale generation can never register,
5
+ * update or publish into the current one.
6
+ */
7
+ /**
8
+ * Creates a scope that retires when any parent signal aborts.
9
+ * Parent listeners are removed on retirement so long-lived parents do not accumulate them.
10
+ * @param parents Parent signals; `undefined` entries are ignored.
11
+ */
12
+ export function createScope(...parents) {
13
+ const controller = new AbortController();
14
+ const linked = parents.filter((signal) => signal !== undefined);
15
+ /** Aborts once and detaches from parents. */
16
+ function retire() {
17
+ if (controller.signal.aborted)
18
+ return;
19
+ for (const parent of linked)
20
+ parent.removeEventListener('abort', retire);
21
+ controller.abort();
22
+ }
23
+ if (linked.some(parent => parent.aborted)) {
24
+ controller.abort();
25
+ }
26
+ else {
27
+ for (const parent of linked)
28
+ parent.addEventListener('abort', retire, { once: true });
29
+ }
30
+ return {
31
+ signal: controller.signal,
32
+ get active() {
33
+ return !controller.signal.aborted;
34
+ },
35
+ retire,
36
+ child: () => createScope(controller.signal),
37
+ };
38
+ }
@@ -0,0 +1,43 @@
1
+ import type { HistoireJsonValue } from '@histoire/protocol';
2
+ import type { WorkbenchContext } from '../types/context.js';
3
+ import type { WorkbenchPluginDefinition } from '../types/plugin.js';
4
+ import type { DiagnosticsLog } from './diagnostics.js';
5
+ import type { Scope } from './generation.js';
6
+ import type { PreferenceStore } from './preferences.js';
7
+ import type { Registry } from './registry.js';
8
+ /** Host state shared by every installed plugin. */
9
+ export interface HostInternals {
10
+ /** Contribution registry. */
11
+ registry: Registry;
12
+ /** Diagnostics log. */
13
+ diagnostics: DiagnosticsLog;
14
+ /** Host scope; plugin scopes are its children. */
15
+ scope: Scope;
16
+ /** Root context. */
17
+ context: WorkbenchContext;
18
+ /** Preference backend. */
19
+ preferences: PreferenceStore;
20
+ /** Project namespace of preference keys. */
21
+ storageNamespace: string | undefined;
22
+ /** Next host-wide registration sequence number. */
23
+ nextSequence: () => number;
24
+ /** Notifies host subscribers (`api.invalidate`). */
25
+ notify: () => void;
26
+ }
27
+ /** One plugin installed into a host. */
28
+ export interface InstalledPlugin {
29
+ /** Settles once setup committed, failed or the plugin was disposed. */
30
+ readonly settled: Promise<void>;
31
+ /** Retires the plugin and releases everything it owns, exactly once. */
32
+ dispose: () => void;
33
+ }
34
+ /**
35
+ * Installs one validated plugin: runs `setup` against a provisional batch, commits the
36
+ * batch atomically on success and rolls everything back on failure.
37
+ * @param definition Validated definition.
38
+ * @param options Browser-visible options.
39
+ * @param configIndex Position in config, used for ordering.
40
+ * @param host Shared host state.
41
+ */
42
+ export declare function installPlugin(definition: WorkbenchPluginDefinition, options: HistoireJsonValue | undefined, configIndex: number, host: HostInternals): InstalledPlugin;
43
+ //# sourceMappingURL=install.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/host/install.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAE3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAiB,MAAM,eAAe,CAAA;AAQ5D,mDAAmD;AACnD,MAAM,WAAW,aAAa;IAC5B,6BAA6B;IAC7B,QAAQ,EAAE,QAAQ,CAAA;IAClB,uBAAuB;IACvB,WAAW,EAAE,cAAc,CAAA;IAC3B,kDAAkD;IAClD,KAAK,EAAE,KAAK,CAAA;IACZ,oBAAoB;IACpB,OAAO,EAAE,gBAAgB,CAAA;IACzB,0BAA0B;IAC1B,WAAW,EAAE,eAAe,CAAA;IAC5B,4CAA4C;IAC5C,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC,mDAAmD;IACnD,YAAY,EAAE,MAAM,MAAM,CAAA;IAC1B,oDAAoD;IACpD,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB;AAED,wCAAwC;AACxC,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/B,wEAAwE;IACxE,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAUD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,yBAAyB,EAAE,OAAO,EAAE,iBAAiB,GAAG,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,eAAe,CA6ItK"}
@@ -0,0 +1,168 @@
1
+ import { PluginDefinitionError } from '../errors.js';
2
+ import { qualifyId } from '../ids.js';
3
+ import { createPluginApi } from './plugin-api.js';
4
+ import { createPluginPreferences } from './preferences.js';
5
+ import { assertKnownKind, qualifyContribution } from './registry.js';
6
+ import { createResourceSet, NOOP } from './resources.js';
7
+ /**
8
+ * Resolves when `signal` aborts, so a hanging setup cannot hold `ready` after disposal.
9
+ * @param signal Plugin scope signal.
10
+ */
11
+ function whenAborted(signal) {
12
+ return new Promise(resolve => signal.aborted ? resolve() : signal.addEventListener('abort', () => resolve(), { once: true }));
13
+ }
14
+ /**
15
+ * Installs one validated plugin: runs `setup` against a provisional batch, commits the
16
+ * batch atomically on success and rolls everything back on failure.
17
+ * @param definition Validated definition.
18
+ * @param options Browser-visible options.
19
+ * @param configIndex Position in config, used for ordering.
20
+ * @param host Shared host state.
21
+ */
22
+ export function installPlugin(definition, options, configIndex, host) {
23
+ const pluginId = definition.id;
24
+ // Plugin generation: retired on failure, plugin disposal or host disposal.
25
+ const scope = host.scope.child();
26
+ const resources = createResourceSet(error => host.diagnostics.record({ pluginId, phase: 'dispose', error }));
27
+ /** Registrations made while setup is pending; `null` once committed or rolled back. */
28
+ let pending = [];
29
+ /** Qualified ids owned by this plugin, pending or committed, for duplicate checks. */
30
+ const owned = new Set();
31
+ /** Qualified ids exposed in the registry. */
32
+ const committed = new Set();
33
+ let tornDown = false;
34
+ /**
35
+ * Validates and builds a registry entry; records and rethrows rejections.
36
+ * @param contribution Untrusted contribution.
37
+ */
38
+ function createEntry(contribution) {
39
+ try {
40
+ assertKnownKind(contribution, pluginId);
41
+ const id = qualifyId(pluginId, contribution.id);
42
+ // Duplicates reject before anything is exposed and never replace the first entry.
43
+ if (owned.has(id))
44
+ throw new PluginDefinitionError(`duplicate contribution id "${id}"`, pluginId);
45
+ const order = typeof contribution.order === 'number' && Number.isFinite(contribution.order) ? contribution.order : 0;
46
+ return {
47
+ contribution: qualifyContribution(contribution, pluginId, id),
48
+ rank: { builtin: false, order, configIndex, sequence: host.nextSequence() },
49
+ owner: scope.signal,
50
+ };
51
+ }
52
+ catch (error) {
53
+ host.diagnostics.record({ pluginId, phase: 'register', error });
54
+ throw error;
55
+ }
56
+ }
57
+ /**
58
+ * Owned registration: provisional while setup is pending, direct afterwards.
59
+ * Stale generations get a no-op disposer and never reach the registry.
60
+ * @param contribution Contribution from the plugin.
61
+ */
62
+ function contribute(contribution) {
63
+ if (!scope.active)
64
+ return NOOP;
65
+ const entry = createEntry(contribution);
66
+ const id = entry.contribution.id;
67
+ owned.add(id);
68
+ if (pending) {
69
+ pending.push(entry);
70
+ }
71
+ else {
72
+ committed.add(id);
73
+ host.registry.commit([entry]);
74
+ }
75
+ let released = false;
76
+ return () => {
77
+ // `released` keeps a stale disposer from removing a re-registered id; `owned` is
78
+ // cleared on teardown, which turns late disposers into no-ops.
79
+ if (released)
80
+ return;
81
+ released = true;
82
+ if (!owned.delete(id))
83
+ return;
84
+ if (pending)
85
+ pending = pending.filter(candidate => candidate !== entry);
86
+ else if (committed.delete(id))
87
+ host.registry.remove([id]);
88
+ };
89
+ }
90
+ /** Retires the generation and releases resources, then exposed entries; runs once. */
91
+ function teardown() {
92
+ if (tornDown)
93
+ return;
94
+ tornDown = true;
95
+ scope.retire();
96
+ pending = null;
97
+ resources.close();
98
+ const exposed = [...committed];
99
+ committed.clear();
100
+ owned.clear();
101
+ host.registry.remove(exposed);
102
+ }
103
+ /**
104
+ * Rolls back a failed setup.
105
+ * @param error Setup error.
106
+ */
107
+ function fail(error) {
108
+ host.diagnostics.record({ pluginId, phase: 'setup', error });
109
+ teardown();
110
+ }
111
+ /**
112
+ * Commits the provisional batch. A disposer returned after retirement runs immediately.
113
+ * @param result Setup return value.
114
+ */
115
+ function commit(result) {
116
+ if (typeof result === 'function')
117
+ resources.add(result);
118
+ if (!scope.active || !pending)
119
+ return;
120
+ const batch = pending;
121
+ pending = null;
122
+ for (const entry of batch)
123
+ committed.add(entry.contribution.id);
124
+ host.registry.commit(batch);
125
+ }
126
+ const api = createPluginApi({
127
+ id: pluginId,
128
+ options,
129
+ context: host.context,
130
+ signal: scope.signal,
131
+ contribute,
132
+ track: release => resources.add(release),
133
+ reportError: (error) => {
134
+ if (scope.active)
135
+ host.diagnostics.record({ pluginId, phase: 'report', error });
136
+ },
137
+ invalidate: () => {
138
+ if (scope.active)
139
+ host.notify();
140
+ },
141
+ preferences: createPluginPreferences({
142
+ store: host.preferences,
143
+ pluginId,
144
+ namespace: host.storageNamespace,
145
+ isActive: () => scope.active,
146
+ track: release => resources.add(release),
147
+ onError: error => host.diagnostics.record({ pluginId, phase: 'callback', error }),
148
+ }),
149
+ });
150
+ /** Runs setup; synchronous throws and rejections both roll back. */
151
+ function start() {
152
+ let result;
153
+ try {
154
+ result = definition.setup(api);
155
+ }
156
+ catch (error) {
157
+ fail(error);
158
+ return Promise.resolve();
159
+ }
160
+ const completion = Promise.resolve(result).then(commit, (error) => {
161
+ // Rejections of a retired generation are discarded.
162
+ if (scope.active)
163
+ fail(error);
164
+ });
165
+ return Promise.race([completion, whenAborted(scope.signal)]);
166
+ }
167
+ return { settled: start(), dispose: teardown };
168
+ }
@@ -0,0 +1,23 @@
1
+ import type { HistoireJsonValue } from '@histoire/protocol';
2
+ import type { ExtensionHostPlugin } from '../types/host.js';
3
+ /** One configured `workbench.client` entry, as `virtual:$histoire-workbench-plugins` exports it. */
4
+ export interface WorkbenchPluginManifestEntry {
5
+ /** Plugin id from the Node descriptor. */
6
+ id: string;
7
+ /** Extension contract version from the Node descriptor. */
8
+ apiVersion: number;
9
+ /** Validated browser-visible JSON options. */
10
+ options: HistoireJsonValue | undefined;
11
+ /** Imports the entry module; its default export is the plugin definition. */
12
+ load: () => Promise<{
13
+ default: unknown;
14
+ }>;
15
+ }
16
+ /**
17
+ * Converts a book's own plugin manifest into host plugins, keeping config order. Only documents
18
+ * served by the book (standalone, source-origin explorer) use it; remote hosts import plugins
19
+ * explicitly and never evaluate a book's modules.
20
+ * @param entries Manifest entries.
21
+ */
22
+ export declare function lazyWorkbenchPlugins(entries: readonly WorkbenchPluginManifestEntry[]): ExtensionHostPlugin[];
23
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/host/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAK3D,oGAAoG;AACpG,MAAM,WAAW,4BAA4B;IAC3C,0CAA0C;IAC1C,EAAE,EAAE,MAAM,CAAA;IACV,2DAA2D;IAC3D,UAAU,EAAE,MAAM,CAAA;IAClB,8CAA8C;IAC9C,OAAO,EAAE,iBAAiB,GAAG,SAAS,CAAA;IACtC,6EAA6E;IAC7E,IAAI,EAAE,MAAM,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;CAC1C;AA4BD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,SAAS,4BAA4B,EAAE,GAAG,mBAAmB,EAAE,CAE5G"}
@@ -0,0 +1,37 @@
1
+ import { defineWorkbenchPlugin } from '../define.js';
2
+ import { PluginDefinitionError } from '../errors.js';
3
+ /**
4
+ * Wraps one lazy manifest entry in a definition the host can install immediately. The module
5
+ * import runs inside `setup`, so the host never waits for plugin code before the workbench
6
+ * paints; a failed import or an invalid export becomes an attributed setup diagnostic and
7
+ * never affects sibling plugins.
8
+ * @param entry Manifest entry.
9
+ */
10
+ function lazyPlugin(entry) {
11
+ const definition = {
12
+ id: entry.id,
13
+ // Unsupported versions are rejected by the host before anything loads.
14
+ apiVersion: entry.apiVersion,
15
+ async setup(api) {
16
+ const loaded = (await entry.load()).default;
17
+ // Disposed while importing: never run setup for a retired host.
18
+ if (api.signal.aborted)
19
+ return;
20
+ defineWorkbenchPlugin(loaded);
21
+ if (loaded.id !== entry.id) {
22
+ throw new PluginDefinitionError(`client entry exports plugin "${loaded.id}"; expected "${entry.id}"`, entry.id);
23
+ }
24
+ return loaded.setup(api);
25
+ },
26
+ };
27
+ return { definition, options: entry.options };
28
+ }
29
+ /**
30
+ * Converts a book's own plugin manifest into host plugins, keeping config order. Only documents
31
+ * served by the book (standalone, source-origin explorer) use it; remote hosts import plugins
32
+ * explicitly and never evaluate a book's modules.
33
+ * @param entries Manifest entries.
34
+ */
35
+ export function lazyWorkbenchPlugins(entries) {
36
+ return entries.map(lazyPlugin);
37
+ }
@@ -0,0 +1,15 @@
1
+ import type { MountedView, PluginDiagnostic, ViewMountOptions } from '../types/host.js';
2
+ import type { RegistryEntry } from './registry.js';
3
+ /**
4
+ * Mounts the DOM view of one committed contribution under its owner's generation.
5
+ * Failures are recorded as diagnostics attributed to the contribution, then passed to
6
+ * `options.onError` for mount and update so the caller shows a local error state.
7
+ * @param entry Registry entry, or `undefined` when the id is unknown.
8
+ * @param contributionId Qualified id, for errors.
9
+ * @param container Caller container.
10
+ * @param context Initial context snapshot.
11
+ * @param options Overlay root and failure listener.
12
+ * @param record Diagnostics sink of the host.
13
+ */
14
+ export declare function mountContribution(entry: RegistryEntry | undefined, contributionId: string, container: HTMLElement, context: unknown, options: ViewMountOptions, record: (diagnostic: PluginDiagnostic) => void): MountedView;
15
+ //# sourceMappingURL=mount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/host/mount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAEvF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AA0BlD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,aAAa,GAAG,SAAS,EAChC,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,WAAW,EACtB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,CAAC,UAAU,EAAE,gBAAgB,KAAK,IAAI,GAC7C,WAAW,CAqBb"}
@@ -0,0 +1,57 @@
1
+ import { createMountManager } from '../render/mount-manager.js';
2
+ /**
3
+ * Mounted view that failed before mounting; `ready` rejects with the reason.
4
+ * @param error Rejection reason.
5
+ */
6
+ function failedView(error) {
7
+ const ready = Promise.reject(error);
8
+ ready.catch(() => { });
9
+ return { ready, update: () => { }, dispose: async () => { } };
10
+ }
11
+ /**
12
+ * Creates the element a view uses for popovers when the caller owns none; it lives in the
13
+ * container's document body for the view's lifetime.
14
+ * @param container View container.
15
+ * @param contributionId Owning contribution, exposed for debugging.
16
+ */
17
+ function createOverlayRoot(container, contributionId) {
18
+ const element = container.ownerDocument.createElement('div');
19
+ element.setAttribute('data-histoire-overlay-root', contributionId);
20
+ container.ownerDocument.body.append(element);
21
+ return element;
22
+ }
23
+ /**
24
+ * Mounts the DOM view of one committed contribution under its owner's generation.
25
+ * Failures are recorded as diagnostics attributed to the contribution, then passed to
26
+ * `options.onError` for mount and update so the caller shows a local error state.
27
+ * @param entry Registry entry, or `undefined` when the id is unknown.
28
+ * @param contributionId Qualified id, for errors.
29
+ * @param container Caller container.
30
+ * @param context Initial context snapshot.
31
+ * @param options Overlay root and failure listener.
32
+ * @param record Diagnostics sink of the host.
33
+ */
34
+ export function mountContribution(entry, contributionId, container, context, options, record) {
35
+ const view = entry?.contribution;
36
+ if (!entry || !view)
37
+ return failedView(new Error(`[histoire] no contribution "${contributionId}"`));
38
+ if (typeof view.mount !== 'function') {
39
+ return failedView(new Error(`[histoire] contribution "${contributionId}" has no DOM mount; ${view.component ? 'component views render through the workbench Vue outlet' : 'it is not a view'}`));
40
+ }
41
+ const pluginId = entry.contribution.pluginId;
42
+ const overlayRoot = options.overlayRoot ?? createOverlayRoot(container, contributionId);
43
+ return createMountManager({
44
+ mount: view.mount,
45
+ container,
46
+ context,
47
+ overlayRoot,
48
+ signal: entry.owner,
49
+ report(error, phase) {
50
+ record({ pluginId, contributionId, phase, error });
51
+ if (phase === 'mount' || phase === 'update')
52
+ options.onError?.(error, phase);
53
+ },
54
+ onDispose: options.overlayRoot ? undefined : () => overlayRoot.remove(),
55
+ renderState: options.renderState,
56
+ });
57
+ }
@@ -0,0 +1,20 @@
1
+ /** Sort key of one registered contribution. */
2
+ export interface ContributionRank {
3
+ /** Built-ins always precede plugin entries. */
4
+ readonly builtin: boolean;
5
+ /** Contribution `order`; `0` when omitted. */
6
+ readonly order: number;
7
+ /** Plugin position in config; `-1` for built-ins. */
8
+ readonly configIndex: number;
9
+ /** Host-wide registration sequence number. */
10
+ readonly sequence: number;
11
+ }
12
+ /**
13
+ * Orders contributions: built-ins first (by their own `order`, then registration order),
14
+ * then plugin entries by `order`, config order and registration order.
15
+ * Commit time never matters, so a slow plugin keeps its config position.
16
+ * @param a First rank.
17
+ * @param b Second rank.
18
+ */
19
+ export declare function compareRanks(a: ContributionRank, b: ContributionRank): number;
20
+ //# sourceMappingURL=ordering.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ordering.d.ts","sourceRoot":"","sources":["../../src/host/ordering.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,MAAM,WAAW,gBAAgB;IAC/B,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,8CAA8C;IAC9C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,qDAAqD;IACrD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,8CAA8C;IAC9C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAG7E"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Orders contributions: built-ins first (by their own `order`, then registration order),
3
+ * then plugin entries by `order`, config order and registration order.
4
+ * Commit time never matters, so a slow plugin keeps its config position.
5
+ * @param a First rank.
6
+ * @param b Second rank.
7
+ */
8
+ export function compareRanks(a, b) {
9
+ if (a.builtin !== b.builtin)
10
+ return a.builtin ? -1 : 1;
11
+ return a.order - b.order || a.configIndex - b.configIndex || a.sequence - b.sequence;
12
+ }