@harborclient/sdk 0.6.16 → 0.7.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.
@@ -1,4 +1,5 @@
1
1
  import type * as React from 'react';
2
+ import type { Disposable, PluginContext, ThemeContribution } from '../types';
2
3
 
3
4
  /**
4
5
  * Installs the HarborClient renderer React instance for plugin JSX and hooks.
@@ -18,3 +19,20 @@ export function installReact(react: typeof React): void;
18
19
  export function createPluginComponent<P extends Record<string, unknown>>(
19
20
  factory: (react: typeof React) => React.ComponentType<P>
20
21
  ): React.ComponentType<P>;
22
+
23
+ /**
24
+ * Registers a custom appearance theme and tracks its disposable for cleanup.
25
+ *
26
+ * @param hc - Renderer plugin context.
27
+ * @param theme - Theme definition; `theme.id` must match `contributes.themes`.
28
+ * @returns Disposable that unregisters the theme.
29
+ */
30
+ export function registerTheme(hc: PluginContext, theme: ThemeContribution): Disposable;
31
+
32
+ /**
33
+ * Identity helper that applies `ThemeContribution` typing to a theme literal.
34
+ *
35
+ * @param theme - Theme definition.
36
+ * @returns The same theme, typed.
37
+ */
38
+ export function defineTheme(theme: ThemeContribution): ThemeContribution;
@@ -41,3 +41,26 @@ export function createPluginComponent(factory) {
41
41
 
42
42
  return PluginComponent;
43
43
  }
44
+
45
+ /**
46
+ * Registers a custom appearance theme and tracks its disposable for cleanup.
47
+ *
48
+ * @param {import('../types').PluginContext} hc - Renderer plugin context.
49
+ * @param {import('../types').ThemeContribution} theme - Theme definition; `theme.id` must match `contributes.themes`.
50
+ * @returns {import('../types').Disposable} Disposable that unregisters the theme.
51
+ */
52
+ export function registerTheme(hc, theme) {
53
+ const disposable = hc.themes.register(theme);
54
+ hc.subscriptions.push(disposable);
55
+ return disposable;
56
+ }
57
+
58
+ /**
59
+ * Identity helper that applies `ThemeContribution` typing to a theme literal.
60
+ *
61
+ * @param {import('../types').ThemeContribution} theme - Theme definition.
62
+ * @returns {import('../types').ThemeContribution} The same theme, typed.
63
+ */
64
+ export function defineTheme(theme) {
65
+ return theme;
66
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/runtime/index.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,41 @@
1
+ import { describe, expect, it, jest } from '@jest/globals';
2
+ import { defineTheme, registerTheme } from './index.js';
3
+ /**
4
+ * Builds a minimal plugin context mock for registerTheme tests.
5
+ */
6
+ function createMockPluginContext() {
7
+ const disposable = { dispose: jest.fn() };
8
+ const registerMock = jest.fn(() => disposable);
9
+ const subscriptions = [];
10
+ return {
11
+ subscriptions,
12
+ themes: { register: registerMock },
13
+ registerMock
14
+ };
15
+ }
16
+ describe('registerTheme', () => {
17
+ it('registers the theme, pushes the disposable onto subscriptions, and returns it', () => {
18
+ const hc = createMockPluginContext();
19
+ const theme = {
20
+ id: 'solarized',
21
+ title: 'Solarized Dark',
22
+ type: 'dark',
23
+ colors: { surface: '#002b36' }
24
+ };
25
+ const disposable = registerTheme(hc, theme);
26
+ expect(hc.registerMock).toHaveBeenCalledWith(theme);
27
+ expect(hc.subscriptions).toHaveLength(1);
28
+ expect(hc.subscriptions[0]).toBe(disposable);
29
+ });
30
+ });
31
+ describe('defineTheme', () => {
32
+ it('returns the theme argument unchanged', () => {
33
+ const theme = {
34
+ id: 'nord',
35
+ title: 'Nord',
36
+ type: 'dark',
37
+ stylesheet: 'dist/theme.css'
38
+ };
39
+ expect(defineTheme(theme)).toBe(theme);
40
+ });
41
+ });
@@ -0,0 +1,53 @@
1
+ import { describe, expect, it, jest } from '@jest/globals';
2
+ import type { PluginContext, ThemeContribution } from '../types';
3
+ import { defineTheme, registerTheme } from './index.js';
4
+
5
+ /**
6
+ * Builds a minimal plugin context mock for registerTheme tests.
7
+ */
8
+ function createMockPluginContext(): PluginContext & {
9
+ registerMock: jest.MockedFunction<PluginContext['themes']['register']>;
10
+ } {
11
+ const disposable = { dispose: jest.fn() };
12
+ const registerMock = jest.fn(() => disposable);
13
+ const subscriptions: PluginContext['subscriptions'] = [];
14
+
15
+ return {
16
+ subscriptions,
17
+ themes: { register: registerMock },
18
+ registerMock
19
+ } as unknown as PluginContext & {
20
+ registerMock: jest.MockedFunction<PluginContext['themes']['register']>;
21
+ };
22
+ }
23
+
24
+ describe('registerTheme', () => {
25
+ it('registers the theme, pushes the disposable onto subscriptions, and returns it', () => {
26
+ const hc = createMockPluginContext();
27
+ const theme: ThemeContribution = {
28
+ id: 'solarized',
29
+ title: 'Solarized Dark',
30
+ type: 'dark',
31
+ colors: { surface: '#002b36' }
32
+ };
33
+
34
+ const disposable = registerTheme(hc, theme);
35
+
36
+ expect(hc.registerMock).toHaveBeenCalledWith(theme);
37
+ expect(hc.subscriptions).toHaveLength(1);
38
+ expect(hc.subscriptions[0]).toBe(disposable);
39
+ });
40
+ });
41
+
42
+ describe('defineTheme', () => {
43
+ it('returns the theme argument unchanged', () => {
44
+ const theme: ThemeContribution = {
45
+ id: 'nord',
46
+ title: 'Nord',
47
+ type: 'dark',
48
+ stylesheet: 'dist/theme.css'
49
+ };
50
+
51
+ expect(defineTheme(theme)).toBe(theme);
52
+ });
53
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harborclient/sdk",
3
- "version": "0.6.16",
3
+ "version": "0.7.0",
4
4
  "description": "TypeScript SDK for HarborClient plugin development.",
5
5
  "keywords": [
6
6
  "harborclient",