@hamak/ui-shell-impl 0.5.9 → 0.7.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.
@@ -4,4 +4,11 @@
4
4
  * @deprecated This package is deprecated. Please migrate to @hamak/ui-shell
5
5
  */
6
6
  console.warn('[@hamak/ui-shell-impl] This package is deprecated. Please migrate to @hamak/ui-shell');
7
+ // Re-export everything from the consolidated package for back-compat.
7
8
  export * from '@hamak/ui-shell';
9
+ // Own implementations of the shell plugin factory and the plugin-style DOM sink.
10
+ // These explicit named re-exports take precedence over the wildcard above, so a
11
+ // consumer of this (deprecated) package always gets the style-mounting factory
12
+ // even if its installed @hamak/ui-shell predates the #15 Styles extension point.
13
+ export { createShellPlugin, getShellFromContext } from './plugin/index.js';
14
+ export { mountStyleRegistry } from './styles/index.js';
@@ -14,9 +14,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
14
14
  import { SHELL_TOKEN, THEME_MANAGER_TOKEN, FEATURE_MANAGER_TOKEN, LAYOUT_MANAGER_TOKEN, ShellCommands, ShellEvents, } from '@hamak/ui-shell-api';
15
15
  import { DefaultShell } from '../core/DefaultShell.js';
16
16
  import { DefaultLayoutManager } from '../core/DefaultLayoutManager.js';
17
+ import { mountStyleRegistry } from '../styles/index.js';
17
18
  export function createShellPlugin(config) {
18
19
  let shell;
19
20
  let layoutManager;
21
+ let unmountStyles;
20
22
  return {
21
23
  initialize(ctx) {
22
24
  shell = new DefaultShell(config);
@@ -68,11 +70,15 @@ export function createShellPlugin(config) {
68
70
  activate(ctx) {
69
71
  return __awaiter(this, void 0, void 0, function* () {
70
72
  yield shell.initialize();
73
+ // Mount plugin-contributed stylesheets into the document. Single well-known
74
+ // mount point for the whole host; SSR-safe (no-op without a document).
75
+ unmountStyles = mountStyleRegistry(ctx.styles);
71
76
  const shellContext = shell.getContext();
72
77
  ctx.hooks.emit('shell:activated', { context: shellContext });
73
78
  });
74
79
  },
75
80
  deactivate() {
81
+ unmountStyles === null || unmountStyles === void 0 ? void 0 : unmountStyles();
76
82
  shell.destroy();
77
83
  layoutManager.destroy();
78
84
  },
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Style Sink
3
+ *
4
+ * Mounts plugin-contributed stylesheets (from the microkernel StyleRegistry)
5
+ * into the document as keyed <style> elements. The registry is pure data; this
6
+ * is the DOM side, kept here so microkernel-impl stays DOM-free and node-safe.
7
+ */
8
+ /**
9
+ * Subscribe a StyleRegistry to a document, keeping a `<style data-plugin-style="<id>">`
10
+ * element in `<head>` in sync with every contribution. Updates mutate the element in
11
+ * place; removed contributions unmount their element.
12
+ *
13
+ * SSR / node-safe: a no-op (returns an empty disposer) when there is no document.
14
+ *
15
+ * @returns an unmount function that removes all mounted styles and stops reacting.
16
+ */
17
+ export function mountStyleRegistry(registry, doc = (typeof document === 'undefined' ? undefined : document)) {
18
+ if (!doc || !doc.head)
19
+ return () => { };
20
+ const els = new Map();
21
+ const unsubscribe = registry.subscribe((styles) => {
22
+ const seen = new Set();
23
+ for (const { id, css } of styles) {
24
+ seen.add(id);
25
+ let el = els.get(id);
26
+ if (!el) {
27
+ el = doc.createElement('style');
28
+ el.setAttribute('data-plugin-style', id);
29
+ doc.head.appendChild(el);
30
+ els.set(id, el);
31
+ }
32
+ if (el.textContent !== css)
33
+ el.textContent = css;
34
+ }
35
+ // Remove styles whose contribution disappeared (dispose/unregister).
36
+ for (const [id, el] of els) {
37
+ if (!seen.has(id)) {
38
+ el.remove();
39
+ els.delete(id);
40
+ }
41
+ }
42
+ });
43
+ return () => {
44
+ unsubscribe();
45
+ for (const el of els.values())
46
+ el.remove();
47
+ els.clear();
48
+ };
49
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Styles
3
+ * Plugin-contributed stylesheet mounting (StyleRegistry → DOM).
4
+ */
5
+ export * from './StyleSink.js';
package/dist/index.d.ts CHANGED
@@ -4,4 +4,6 @@
4
4
  * @deprecated This package is deprecated. Please migrate to @hamak/ui-shell
5
5
  */
6
6
  export * from '@hamak/ui-shell';
7
+ export { createShellPlugin, getShellFromContext } from './plugin/index.js';
8
+ export { mountStyleRegistry } from './styles/index.js';
7
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,cAAc,iBAAiB,CAAC;AAMhC,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -4,4 +4,11 @@
4
4
  * @deprecated This package is deprecated. Please migrate to @hamak/ui-shell
5
5
  */
6
6
  console.warn('[@hamak/ui-shell-impl] This package is deprecated. Please migrate to @hamak/ui-shell');
7
+ // Re-export everything from the consolidated package for back-compat.
7
8
  export * from '@hamak/ui-shell';
9
+ // Own implementations of the shell plugin factory and the plugin-style DOM sink.
10
+ // These explicit named re-exports take precedence over the wildcard above, so a
11
+ // consumer of this (deprecated) package always gets the style-mounting factory
12
+ // even if its installed @hamak/ui-shell predates the #15 Styles extension point.
13
+ export { createShellPlugin, getShellFromContext } from './plugin/index.js';
14
+ export { mountStyleRegistry } from './styles/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"ShellPluginFactory.d.ts","sourceRoot":"","sources":["../../src/plugin/ShellPluginFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AASvD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,YAAY,CAyEpE;AAGD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,eAAe,GAAG,YAAY,CAEtE"}
1
+ {"version":3,"file":"ShellPluginFactory.d.ts","sourceRoot":"","sources":["../../src/plugin/ShellPluginFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AASvD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpD,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,YAAY,CA8EpE;AAGD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,eAAe,GAAG,YAAY,CAEtE"}
@@ -5,9 +5,11 @@
5
5
  import { SHELL_TOKEN, THEME_MANAGER_TOKEN, FEATURE_MANAGER_TOKEN, LAYOUT_MANAGER_TOKEN, ShellCommands, ShellEvents, } from '@hamak/ui-shell-api';
6
6
  import { DefaultShell } from '../core/DefaultShell.js';
7
7
  import { DefaultLayoutManager } from '../core/DefaultLayoutManager.js';
8
+ import { mountStyleRegistry } from '../styles/index.js';
8
9
  export function createShellPlugin(config) {
9
10
  let shell;
10
11
  let layoutManager;
12
+ let unmountStyles;
11
13
  return {
12
14
  initialize(ctx) {
13
15
  shell = new DefaultShell(config);
@@ -58,10 +60,14 @@ export function createShellPlugin(config) {
58
60
  },
59
61
  async activate(ctx) {
60
62
  await shell.initialize();
63
+ // Mount plugin-contributed stylesheets into the document. Single well-known
64
+ // mount point for the whole host; SSR-safe (no-op without a document).
65
+ unmountStyles = mountStyleRegistry(ctx.styles);
61
66
  const shellContext = shell.getContext();
62
67
  ctx.hooks.emit('shell:activated', { context: shellContext });
63
68
  },
64
69
  deactivate() {
70
+ unmountStyles?.();
65
71
  shell.destroy();
66
72
  layoutManager.destroy();
67
73
  },
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Style Sink
3
+ *
4
+ * Mounts plugin-contributed stylesheets (from the microkernel StyleRegistry)
5
+ * into the document as keyed <style> elements. The registry is pure data; this
6
+ * is the DOM side, kept here so microkernel-impl stays DOM-free and node-safe.
7
+ */
8
+ import type { StyleRegistry } from '@hamak/microkernel-api';
9
+ /**
10
+ * Subscribe a StyleRegistry to a document, keeping a `<style data-plugin-style="<id>">`
11
+ * element in `<head>` in sync with every contribution. Updates mutate the element in
12
+ * place; removed contributions unmount their element.
13
+ *
14
+ * SSR / node-safe: a no-op (returns an empty disposer) when there is no document.
15
+ *
16
+ * @returns an unmount function that removes all mounted styles and stops reacting.
17
+ */
18
+ export declare function mountStyleRegistry(registry: StyleRegistry, doc?: Document): () => void;
19
+ //# sourceMappingURL=StyleSink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StyleSink.d.ts","sourceRoot":"","sources":["../../src/styles/StyleSink.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,aAAa,EACvB,GAAG,GAAE,QAA+E,GACnF,MAAM,IAAI,CAgCZ"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Style Sink
3
+ *
4
+ * Mounts plugin-contributed stylesheets (from the microkernel StyleRegistry)
5
+ * into the document as keyed <style> elements. The registry is pure data; this
6
+ * is the DOM side, kept here so microkernel-impl stays DOM-free and node-safe.
7
+ */
8
+ /**
9
+ * Subscribe a StyleRegistry to a document, keeping a `<style data-plugin-style="<id>">`
10
+ * element in `<head>` in sync with every contribution. Updates mutate the element in
11
+ * place; removed contributions unmount their element.
12
+ *
13
+ * SSR / node-safe: a no-op (returns an empty disposer) when there is no document.
14
+ *
15
+ * @returns an unmount function that removes all mounted styles and stops reacting.
16
+ */
17
+ export function mountStyleRegistry(registry, doc = (typeof document === 'undefined' ? undefined : document)) {
18
+ if (!doc || !doc.head)
19
+ return () => { };
20
+ const els = new Map();
21
+ const unsubscribe = registry.subscribe((styles) => {
22
+ const seen = new Set();
23
+ for (const { id, css } of styles) {
24
+ seen.add(id);
25
+ let el = els.get(id);
26
+ if (!el) {
27
+ el = doc.createElement('style');
28
+ el.setAttribute('data-plugin-style', id);
29
+ doc.head.appendChild(el);
30
+ els.set(id, el);
31
+ }
32
+ if (el.textContent !== css)
33
+ el.textContent = css;
34
+ }
35
+ // Remove styles whose contribution disappeared (dispose/unregister).
36
+ for (const [id, el] of els) {
37
+ if (!seen.has(id)) {
38
+ el.remove();
39
+ els.delete(id);
40
+ }
41
+ }
42
+ });
43
+ return () => {
44
+ unsubscribe();
45
+ for (const el of els.values())
46
+ el.remove();
47
+ els.clear();
48
+ };
49
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Styles
3
+ * Plugin-contributed stylesheet mounting (StyleRegistry → DOM).
4
+ */
5
+ export * from './StyleSink.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/styles/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,aAAa,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Styles
3
+ * Plugin-contributed stylesheet mounting (StyleRegistry → DOM).
4
+ */
5
+ export * from './StyleSink.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hamak/ui-shell-impl",
3
- "version": "0.5.9",
3
+ "version": "0.7.1",
4
4
  "description": "[DEPRECATED] Use @hamak/ui-shell instead",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",