@mndw/cli 0.0.0-stage → 0.1.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.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/meta.json +1821 -0
  4. package/dist/mndw.js +3993 -0
  5. package/host-dev/assets/_virtual_sandbox-manifest-DbTeSIus.js +1 -0
  6. package/host-dev/assets/_virtual_sandbox-plugin-Cg-1CvkF.js +1 -0
  7. package/host-dev/assets/index-CADLhduS.js +94 -0
  8. package/host-dev/assets/index-TmL5gfki.css +1 -0
  9. package/host-dev/assets/sandbox-url-D9gV-Yo0.js +1 -0
  10. package/host-dev/assets/sprite-DIkKar2y.svg +189 -0
  11. package/host-dev/assets/ticker-pool.worker-DJA1ERT2.js +1 -0
  12. package/host-dev/index.html +33 -0
  13. package/host-dev/shared/angular-common@21.2.18.js +30 -0
  14. package/host-dev/shared/angular-compiler@21.2.18.js +84 -0
  15. package/host-dev/shared/angular-core@21.2.18.js +122 -0
  16. package/host-dev/shared/angular-platform-browser@21.2.18.js +34 -0
  17. package/host-dev/shared/d3@7.9.0.js +5 -0
  18. package/host-dev/shared/hash-wasm@4.12.0.js +10 -0
  19. package/host-dev/shared/mndw-ui@0.1.1.js +1656 -0
  20. package/host-dev/shared/rci-tools-core@0.6.0.js +15 -0
  21. package/host-dev/shared/rxjs-operators@7.8.2.js +3 -0
  22. package/host-dev/shared/rxjs@7.8.2.js +3 -0
  23. package/host-dev/shared/vue@3.5.39.js +56 -0
  24. package/host-dev/shared/zone@0.15.1.js +11 -0
  25. package/package.json +77 -3
  26. package/templates/angular/src/app.component.ts +57 -0
  27. package/templates/angular/src/index.ts +21 -0
  28. package/templates/angular/src/l10n.test.ts +50 -0
  29. package/templates/angular/src/table.test.ts +59 -0
  30. package/templates/angular/tsconfig.json +18 -0
  31. package/templates/backend/main.sh +7 -0
  32. package/templates/go/backend/cmd/__MNDW_NAME__d/main.go +20 -0
  33. package/templates/go/backend/go.mod +6 -0
  34. package/templates/go/backend/integration_test.go +174 -0
  35. package/templates/go/backend/internal/httpapi/server.go +87 -0
  36. package/templates/go/backend/internal/httpapi/server_test.go +63 -0
  37. package/templates/go/gitignore +6 -0
  38. package/templates/go/i18n/en.json +8 -0
  39. package/templates/go/i18n/ru.json +8 -0
  40. package/templates/go/manifest.json +25 -0
  41. package/templates/go/package.json +20 -0
  42. package/templates/go/src/index.css +31 -0
  43. package/templates/go/src/index.test.ts +59 -0
  44. package/templates/go/src/index.ts +92 -0
  45. package/templates/go/src/l10n.test.ts +66 -0
  46. package/templates/go/src/test-helpers.ts +6 -0
  47. package/templates/svelte/src/App.svelte +102 -0
  48. package/templates/svelte/src/TableNameCell.svelte +10 -0
  49. package/templates/svelte/src/index.ts +14 -0
  50. package/templates/svelte/src/l10n.test.ts +45 -0
  51. package/templates/svelte/src/table.test.ts +53 -0
  52. package/templates/svelte/vitest.config.ts +9 -0
  53. package/templates/vanilla/src/index.css +31 -0
  54. package/templates/vanilla/src/index.ts +65 -0
  55. package/templates/vanilla/src/l10n.test.ts +44 -0
  56. package/templates/vue/src/App.vue +80 -0
  57. package/templates/vue/src/TableNameCell.vue +12 -0
  58. package/templates/vue/src/env.d.ts +6 -0
  59. package/templates/vue/src/index.ts +16 -0
  60. package/templates/vue/src/l10n.test.ts +45 -0
  61. package/templates/vue/src/table.test.ts +53 -0
  62. package/templates/vue/vitest.config.ts +6 -0
@@ -0,0 +1,59 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import {describe, expect, it, vi} from 'vitest';
4
+
5
+ import {createInstance} from './index.js';
6
+ import {makeStubContext} from './test-helpers.js';
7
+
8
+ describe('generated frontend', () => {
9
+ it('fetches \'hello\' and renders the typed message', async () => {
10
+ const fetch = vi.fn().mockResolvedValue(new Response(JSON.stringify({message: 'hello', plugin: 'p'})));
11
+ const container = document.createElement('div');
12
+ const instance = createInstance(container, makeStubContext({backend: {fetch}}));
13
+
14
+ await vi.waitFor(() => {
15
+ expect(fetch).toHaveBeenCalledWith('hello');
16
+ expect(container.querySelector('[data-testid="l10n-result"]')?.textContent).toBe('l10n.result: hello');
17
+ });
18
+
19
+ instance.unmount();
20
+ });
21
+
22
+ it('requests hello again when the button is clicked', async () => {
23
+ const fetch = vi.fn().mockResolvedValue(new Response(JSON.stringify({message: 'hello', plugin: 'p'})));
24
+ const container = document.createElement('div');
25
+ const instance = createInstance(container, makeStubContext({backend: {fetch}}));
26
+
27
+ await vi.waitFor(() => {
28
+ expect(fetch).toHaveBeenCalledTimes(1);
29
+ });
30
+
31
+ (container.querySelector('button') as HTMLButtonElement).click();
32
+
33
+ await vi.waitFor(() => {
34
+ expect(fetch).toHaveBeenCalledTimes(2);
35
+ });
36
+
37
+ instance.unmount();
38
+ });
39
+
40
+ it('renders a localized error when the backend request fails', async () => {
41
+ const fetch = vi.fn().mockRejectedValue(new Error('unavailable'));
42
+ const container = document.createElement('div');
43
+ const instance = createInstance(container, makeStubContext({backend: {fetch}}));
44
+
45
+ await vi.waitFor(() => {
46
+ expect(container.querySelector('[data-testid="l10n-result"]')?.textContent).toBe('l10n.error');
47
+ });
48
+
49
+ instance.unmount();
50
+ });
51
+
52
+ it('renders the fallback when backend is undefined without throwing', () => {
53
+ const container = document.createElement('div');
54
+ const instance = createInstance(container, makeStubContext({backend: undefined}));
55
+
56
+ expect(container.querySelector('[data-testid="l10n-result"]')?.textContent).toBe('l10n.result');
57
+ instance.unmount();
58
+ });
59
+ });
@@ -0,0 +1,92 @@
1
+ import type {PluginContext, PluginInstance} from '@mndw/sdk';
2
+ import {bindLocale} from '@mndw/sdk/bind-locale';
3
+
4
+ import './index.css';
5
+
6
+ export function createInstance(container: HTMLElement, ctx: PluginContext): PluginInstance {
7
+ container.innerHTML = `
8
+ <div class="mndw-__MNDW_NAME__">
9
+ <h3 class="mndw-__MNDW_NAME____title" data-testid="l10n-probe" data-plugin-label="__MNDW_LABEL__"></h3>
10
+ <p class="mndw-__MNDW_NAME____device">Device: <span class="mndw-__MNDW_NAME____device-name"></span></p>
11
+ <button class="mndw-__MNDW_NAME____count" type="button"></button>
12
+ <p class="mndw-__MNDW_NAME____result" data-testid="l10n-result"></p>
13
+ </div>
14
+ `;
15
+
16
+ const title = container.querySelector('.mndw-__MNDW_NAME____title');
17
+ const device = container.querySelector('.mndw-__MNDW_NAME____device-name');
18
+ const button = container.querySelector('.mndw-__MNDW_NAME____count');
19
+ const result = container.querySelector('.mndw-__MNDW_NAME____result');
20
+ let mounted = true;
21
+ let backendMessage: string | undefined;
22
+ let backendError = false;
23
+
24
+ const render = (): void => {
25
+ if (title !== null) {
26
+ title.textContent = ctx.i18n.t('l10n.probe');
27
+ }
28
+
29
+ if (device !== null) {
30
+ device.textContent = ctx.deviceInfo.deviceName;
31
+ }
32
+
33
+ if (button !== null) {
34
+ button.textContent = ctx.i18n.t('l10n.button');
35
+ }
36
+
37
+ if (result === null) {
38
+ return;
39
+ }
40
+
41
+ if (backendError) {
42
+ result.textContent = ctx.i18n.t('l10n.error');
43
+ } else if (backendMessage !== undefined) {
44
+ result.textContent = `${ctx.i18n.t('l10n.result')}: ${backendMessage}`;
45
+ } else {
46
+ result.textContent = ctx.i18n.t('l10n.result');
47
+ }
48
+ };
49
+
50
+ const load = async (): Promise<void> => {
51
+ if (ctx.backend === undefined) {
52
+ render();
53
+ return;
54
+ }
55
+
56
+ try {
57
+ const response = await ctx.backend.fetch('hello');
58
+ const data = await response.json() as {message: string; plugin: string};
59
+ backendMessage = data.message;
60
+ backendError = false;
61
+ } catch {
62
+ backendMessage = undefined;
63
+ backendError = true;
64
+ }
65
+
66
+ if (mounted) {
67
+ render();
68
+ }
69
+ };
70
+
71
+ const onClick = (): void => {
72
+ void load();
73
+ };
74
+
75
+ button?.addEventListener('click', onClick);
76
+ const teardown = bindLocale(ctx.i18n, render);
77
+ const themeSubscription = ctx.theme$.subscribe((theme) => {
78
+ container.dataset.theme = theme;
79
+ });
80
+ void load();
81
+
82
+ return {
83
+ unmount() {
84
+ mounted = false;
85
+ teardown();
86
+ themeSubscription.unsubscribe();
87
+ button?.removeEventListener('click', onClick);
88
+ container.innerHTML = '';
89
+ delete container.dataset.theme;
90
+ },
91
+ };
92
+ }
@@ -0,0 +1,66 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import type {BackendClient, PluginContext} from '@mndw/sdk';
4
+ import {createTestI18n, createTestPluginContext} from '@mndw/sdk/testing';
5
+ import {describe, expect, it, vi} from 'vitest';
6
+
7
+ import {createInstance} from './index.js';
8
+
9
+ const contextFor = (
10
+ i18n: ReturnType<typeof createTestI18n>,
11
+ backend?: Partial<BackendClient>,
12
+ ): PluginContext => createTestPluginContext({i18n, backend: backend as BackendClient | undefined}).context;
13
+
14
+ describe('generated Go locale reactivity', () => {
15
+ it('updates probe, control, and result without remounting', () => {
16
+ const en = {l10n: {probe: 'English probe', button: 'Run English', result: 'English result'}};
17
+ const ru = {l10n: {probe: 'Русский probe', button: 'Запустить', result: 'Русский result'}};
18
+ const i18n = createTestI18n(en, 'en');
19
+ const root = document.createElement('div');
20
+ const instance = createInstance(root, contextFor(i18n));
21
+ const probe = root.querySelector('[data-testid="l10n-probe"]');
22
+ const button = root.querySelector('button');
23
+ const result = root.querySelector('[data-testid="l10n-result"]');
24
+
25
+ expect(probe?.textContent).toBe(en.l10n.probe);
26
+ i18n.setLocale('ru', ru);
27
+
28
+ expect(root.querySelector('[data-testid="l10n-probe"]')).toBe(probe);
29
+ expect(probe?.textContent).toBe(ru.l10n.probe);
30
+ expect(button?.textContent).toBe(ru.l10n.button);
31
+ expect(result?.textContent).toBe(ru.l10n.result);
32
+ instance.unmount();
33
+ });
34
+
35
+ it('updates data-theme when the host theme changes', () => {
36
+ const fixture = createTestPluginContext();
37
+ const root = document.createElement('div');
38
+ const instance = createInstance(root, fixture.context);
39
+
40
+ expect(root.dataset.theme).toBe('light');
41
+ fixture.setTheme('dark');
42
+ expect(root.dataset.theme).toBe('dark');
43
+
44
+ instance.unmount();
45
+ fixture.unmount();
46
+ });
47
+
48
+ it('updates the localized result label after a backend response', async () => {
49
+ const en = {l10n: {probe: 'English probe', button: 'Run English', result: 'English result'}};
50
+ const ru = {l10n: {probe: 'Русский probe', button: 'Запустить', result: 'Русский result'}};
51
+ const i18n = createTestI18n(en, 'en');
52
+ const fetch = vi.fn().mockResolvedValue(new Response(JSON.stringify({message: 'hello', plugin: 'p'})));
53
+ const root = document.createElement('div');
54
+ const instance = createInstance(root, contextFor(i18n, {fetch}));
55
+ const result = root.querySelector('[data-testid="l10n-result"]');
56
+
57
+ await vi.waitFor(() => {
58
+ expect(result?.textContent).toBe('English result: hello');
59
+ });
60
+
61
+ i18n.setLocale('ru', ru);
62
+
63
+ expect(result?.textContent).toBe('Русский result: hello');
64
+ instance.unmount();
65
+ });
66
+ });
@@ -0,0 +1,6 @@
1
+ import type {BackendClient, PluginContext} from '@mndw/sdk';
2
+ import {createTestPluginContext} from '@mndw/sdk/testing';
3
+
4
+ export function makeStubContext(overrides: {backend?: Partial<BackendClient>}): PluginContext {
5
+ return createTestPluginContext({backend: overrides.backend as BackendClient | undefined}).context;
6
+ }
@@ -0,0 +1,102 @@
1
+ <script lang="ts">
2
+ import type {PluginContext} from '@mndw/sdk';
3
+ import {type MndwTableProps, column} from '@mndw/ui';
4
+ import {createTranslator} from '@mndw/sdk/svelte';
5
+ import {svelteCell} from '@mndw/ui-svelte';
6
+ import TableNameCell from './TableNameCell.svelte';
7
+
8
+ interface TableRow {
9
+ id: string;
10
+ name: string;
11
+ }
12
+
13
+ let {ctx}: {ctx: PluginContext} = $props();
14
+ const translator = $derived(createTranslator(ctx.i18n));
15
+ const theme$ = $derived(ctx.theme$);
16
+ const rows = $derived<TableRow[]>([
17
+ {id: 'first', name: $translator.t('table.first')},
18
+ {id: 'second', name: $translator.t('table.second')},
19
+ ]);
20
+ const columns = $derived([
21
+ column<TableRow>()({
22
+ id: 'name',
23
+ label: $translator.t('table.column'),
24
+ accessor: (row) => row.name,
25
+ renderer: svelteCell<TableRow, string>()(TableNameCell),
26
+ }),
27
+ ]);
28
+ let table: (HTMLElement & MndwTableProps<TableRow>) | undefined = $state();
29
+
30
+ $effect(() => {
31
+ if (table === undefined) {
32
+ return;
33
+ }
34
+
35
+ Object.assign(table, {
36
+ columns,
37
+ rows,
38
+ rowKey: 'id',
39
+ caption: $translator.t('table.caption'),
40
+ columnMenu: false,
41
+ });
42
+ });
43
+
44
+ let count = $state(0);
45
+ </script>
46
+
47
+ <div
48
+ class="wrap"
49
+ data-theme={$theme$}
50
+ >
51
+ <h3
52
+ class="title"
53
+ data-testid="l10n-probe"
54
+ data-plugin-label="__MNDW_LABEL__"
55
+ >
56
+ {$translator.t('l10n.probe')}
57
+ </h3>
58
+ <p class="device">Device: {ctx.deviceInfo.deviceName}</p>
59
+ <button
60
+ class="count"
61
+ type="button"
62
+ onclick={() => count++}
63
+ >
64
+ {$translator.t('l10n.button')} {count}
65
+ </button>
66
+ <p class="result">{$translator.t('l10n.result')}</p>
67
+ <mndw-table bind:this={table}></mndw-table>
68
+ </div>
69
+
70
+ <style>
71
+ .wrap {
72
+ padding: var(--mndw-space-4);
73
+ font-family: var(--mndw-font-sans);
74
+ color: var(--mndw-text);
75
+ background: var(--mndw-surface);
76
+ }
77
+
78
+ .title {
79
+ margin: 0 0 var(--mndw-space-2);
80
+ font-size: var(--mndw-text-lg);
81
+ font-weight: var(--mndw-weight-semibold);
82
+ }
83
+
84
+ .device {
85
+ margin: 0 0 var(--mndw-space-3);
86
+ color: var(--mndw-text-muted);
87
+ }
88
+
89
+ .count {
90
+ padding: var(--mndw-space-2) var(--mndw-space-3);
91
+ font: inherit;
92
+ color: var(--mndw-accent-contrast);
93
+ background: var(--mndw-accent);
94
+ border: none;
95
+ border-radius: var(--mndw-radius-md);
96
+ cursor: pointer;
97
+ }
98
+
99
+ .count:hover {
100
+ background: var(--mndw-accent-hover);
101
+ }
102
+ </style>
@@ -0,0 +1,10 @@
1
+ <script lang="ts">
2
+ interface TableRow {
3
+ id: string;
4
+ name: string;
5
+ }
6
+
7
+ let {value}: {row: TableRow; value: string; colId: string} = $props();
8
+ </script>
9
+
10
+ <span data-testid="table-name-cell">{value}</span>
@@ -0,0 +1,14 @@
1
+ import {mount, unmount} from 'svelte';
2
+ import type {PluginContext, PluginInstance} from '@mndw/sdk';
3
+
4
+ import App from './App.svelte';
5
+
6
+ export function createInstance(container: HTMLElement, ctx: PluginContext): PluginInstance {
7
+ const app = mount(App, {target: container, props: {ctx}});
8
+
9
+ return {
10
+ unmount() {
11
+ void unmount(app);
12
+ },
13
+ };
14
+ }
@@ -0,0 +1,45 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import {flushSync, mount, unmount} from 'svelte';
4
+ import type {PluginContext} from '@mndw/sdk';
5
+ import {createTestI18n, createTestPluginContext} from '@mndw/sdk/testing';
6
+ import {describe, expect, it} from 'vitest';
7
+ import App from './App.svelte';
8
+
9
+ const contextFor = (i18n: ReturnType<typeof createTestI18n>): PluginContext => createTestPluginContext({i18n}).context;
10
+
11
+ describe('generated Svelte locale reactivity', () => {
12
+ it('updates the same probe node without remounting', () => {
13
+ const en = {l10n: {probe: 'English probe', button: 'Run English', result: 'English result'}};
14
+ const ru = {l10n: {probe: 'Русский probe', button: 'Запустить', result: 'Русский результат'}};
15
+ const i18n = createTestI18n(en, 'en');
16
+ const root = document.createElement('div');
17
+ const component = mount(App, {target: root, props: {ctx: contextFor(i18n)}});
18
+ flushSync();
19
+ const probe = root.querySelector('[data-testid="l10n-probe"]');
20
+
21
+ expect(en.l10n.probe).not.toBe(ru.l10n.probe);
22
+ expect(probe?.textContent).toBe(en.l10n.probe);
23
+ i18n.setLocale('ru', ru);
24
+ flushSync();
25
+
26
+ expect(root.querySelector('[data-testid="l10n-probe"]')).toBe(probe);
27
+ expect(probe?.textContent).toBe(ru.l10n.probe);
28
+ unmount(component);
29
+ });
30
+
31
+ it('updates data-theme when the host theme changes', () => {
32
+ const fixture = createTestPluginContext();
33
+ const root = document.createElement('div');
34
+ const component = mount(App, {target: root, props: {ctx: fixture.context}});
35
+ flushSync();
36
+
37
+ expect(root.querySelector('.wrap')?.getAttribute('data-theme')).toBe('light');
38
+ fixture.setTheme('dark');
39
+ flushSync();
40
+ expect(root.querySelector('.wrap')?.getAttribute('data-theme')).toBe('dark');
41
+
42
+ unmount(component);
43
+ fixture.unmount();
44
+ });
45
+ });
@@ -0,0 +1,53 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import {flushSync} from 'svelte';
4
+ import {defineMndwUi} from '@mndw/ui';
5
+ import {createTestI18n, createTestPluginContext} from '@mndw/sdk/testing';
6
+ import {afterEach, describe, expect, it} from 'vitest';
7
+ import {createInstance} from './index.js';
8
+
9
+ type TableElement = HTMLElement & {updateComplete: Promise<unknown>};
10
+
11
+ const catalog = {
12
+ table: {
13
+ caption: 'Example records',
14
+ column: 'Name',
15
+ first: 'Alpha',
16
+ second: 'Beta',
17
+ },
18
+ };
19
+
20
+ defineMndwUi();
21
+
22
+ afterEach(() => {
23
+ document.body.innerHTML = '';
24
+ });
25
+
26
+ describe('generated Svelte table', () => {
27
+ it('renders localized rows through svelteCell', async () => {
28
+ const fixture = createTestPluginContext({i18n: createTestI18n(catalog)});
29
+ const container = document.createElement('div');
30
+ document.body.append(container);
31
+ const instance = createInstance(container, fixture.context);
32
+ flushSync();
33
+
34
+ const table = container.querySelector('mndw-table') as TableElement | null;
35
+
36
+ if (table === null) {
37
+ throw new Error('expected generated mndw-table');
38
+ }
39
+
40
+ await table.updateComplete;
41
+ expect(table.shadowRoot?.querySelectorAll('[part="row"]')).toHaveLength(2);
42
+ expect(table.shadowRoot?.querySelector('[part="caption"]')?.textContent).toBe(catalog.table.caption);
43
+ expect(table.shadowRoot?.querySelector('[part="header-cell"]')?.textContent).toContain(catalog.table.column);
44
+ expect(Array.from(table.querySelectorAll('[data-testid="table-name-cell"]')).map((cell) => cell.textContent))
45
+ .toEqual([
46
+ catalog.table.first,
47
+ catalog.table.second,
48
+ ]);
49
+
50
+ instance.unmount();
51
+ fixture.unmount();
52
+ });
53
+ });
@@ -0,0 +1,9 @@
1
+ import {svelte} from '@sveltejs/vite-plugin-svelte';
2
+ import {defineConfig} from 'vitest/config';
3
+
4
+ export default defineConfig({
5
+ plugins: [svelte({hot: false})],
6
+ resolve: {
7
+ conditions: ['browser'],
8
+ },
9
+ });
@@ -0,0 +1,31 @@
1
+ .mndw-__MNDW_NAME__ {
2
+ padding: var(--mndw-space-4);
3
+ background: var(--mndw-surface);
4
+ color: var(--mndw-text);
5
+ font-family: var(--mndw-font-sans);
6
+ }
7
+
8
+ .mndw-__MNDW_NAME____title {
9
+ margin: 0 0 var(--mndw-space-2);
10
+ font-weight: var(--mndw-weight-semibold);
11
+ font-size: var(--mndw-text-lg);
12
+ }
13
+
14
+ .mndw-__MNDW_NAME____device {
15
+ margin: 0 0 var(--mndw-space-3);
16
+ color: var(--mndw-text-muted);
17
+ }
18
+
19
+ .mndw-__MNDW_NAME____count {
20
+ padding: var(--mndw-space-2) var(--mndw-space-3);
21
+ border: none;
22
+ border-radius: var(--mndw-radius-md);
23
+ background: var(--mndw-accent);
24
+ color: var(--mndw-accent-contrast);
25
+ font: inherit;
26
+ cursor: pointer;
27
+ }
28
+
29
+ .mndw-__MNDW_NAME____count:hover {
30
+ background: var(--mndw-accent-hover);
31
+ }
@@ -0,0 +1,65 @@
1
+ import type {PluginContext, PluginInstance} from '@mndw/sdk';
2
+ import {bindLocale} from '@mndw/sdk/bind-locale';
3
+
4
+ import './index.css';
5
+
6
+ export function createInstance(container: HTMLElement, ctx: PluginContext): PluginInstance {
7
+ container.innerHTML = `
8
+ <div class="mndw-__MNDW_NAME__">
9
+ <h3 class="mndw-__MNDW_NAME____title" data-testid="l10n-probe" data-plugin-label="__MNDW_LABEL__"></h3>
10
+ <p class="mndw-__MNDW_NAME____device">Device: <span class="mndw-__MNDW_NAME____device-name"></span></p>
11
+ <button class="mndw-__MNDW_NAME____count" type="button"></button>
12
+ <p class="mndw-__MNDW_NAME____result" data-testid="l10n-result"></p>
13
+ </div>
14
+ `;
15
+
16
+ const title = container.querySelector('.mndw-__MNDW_NAME____title');
17
+ const deviceEl = container.querySelector('.mndw-__MNDW_NAME____device-name');
18
+ const button = container.querySelector('.mndw-__MNDW_NAME____count');
19
+ const result = container.querySelector('.mndw-__MNDW_NAME____result');
20
+
21
+ let count = 0;
22
+
23
+ const render = (): void => {
24
+ if (title !== null) {
25
+ title.textContent = ctx.i18n.t('l10n.probe');
26
+ }
27
+
28
+ if (deviceEl !== null) {
29
+ deviceEl.textContent = ctx.deviceInfo.deviceName;
30
+ }
31
+
32
+ if (button !== null) {
33
+ button.textContent = ctx.i18n.t('l10n.button');
34
+ }
35
+
36
+ if (result !== null) {
37
+ result.textContent = ctx.i18n.t('l10n.result');
38
+ }
39
+ };
40
+
41
+ const onClick = (): void => {
42
+ count++;
43
+
44
+ if (result !== null) {
45
+ result.textContent = `${ctx.i18n.t('l10n.result')} ${count}`;
46
+ }
47
+ };
48
+
49
+ button?.addEventListener('click', onClick);
50
+ const teardown = bindLocale(ctx.i18n, render);
51
+ const themeSubscription = ctx.theme$.subscribe((theme) => {
52
+ container.dataset.theme = theme;
53
+ });
54
+
55
+ return {
56
+ unmount() {
57
+ teardown();
58
+ themeSubscription.unsubscribe();
59
+ button?.removeEventListener('click', onClick);
60
+
61
+ container.innerHTML = '';
62
+ delete container.dataset.theme;
63
+ },
64
+ };
65
+ }
@@ -0,0 +1,44 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import type {PluginContext} from '@mndw/sdk';
4
+ import {createTestI18n, createTestPluginContext} from '@mndw/sdk/testing';
5
+ import {describe, expect, it} from 'vitest';
6
+ import {createInstance} from './index.js';
7
+
8
+ const contextFor = (i18n: ReturnType<typeof createTestI18n>): PluginContext => createTestPluginContext({i18n}).context;
9
+
10
+ describe('generated vanilla locale reactivity', () => {
11
+ it('updates probe, control, and result without remounting', () => {
12
+ const en = {l10n: {probe: 'English probe', button: 'Run English', result: 'English result'}};
13
+ const ru = {l10n: {probe: 'Русский probe', button: 'Запустить', result: 'Русский результат'}};
14
+ const i18n = createTestI18n(en, 'en');
15
+ const root = document.createElement('div');
16
+ const instance = createInstance(root, contextFor(i18n));
17
+ const probe = root.querySelector('[data-testid="l10n-probe"]');
18
+ const button = root.querySelector('button');
19
+ const result = root.querySelector('[data-testid="l10n-result"]');
20
+
21
+ expect(en.l10n.probe).not.toBe(ru.l10n.probe);
22
+ expect(probe?.textContent).toBe(en.l10n.probe);
23
+ i18n.setLocale('ru', ru);
24
+
25
+ expect(root.querySelector('[data-testid="l10n-probe"]')).toBe(probe);
26
+ expect(probe?.textContent).toBe(ru.l10n.probe);
27
+ expect(button?.textContent).toBe(ru.l10n.button);
28
+ expect(result?.textContent).toBe(ru.l10n.result);
29
+ instance.unmount();
30
+ });
31
+
32
+ it('updates data-theme when the host theme changes', () => {
33
+ const fixture = createTestPluginContext();
34
+ const root = document.createElement('div');
35
+ const instance = createInstance(root, fixture.context);
36
+
37
+ expect(root.dataset.theme).toBe('light');
38
+ fixture.setTheme('dark');
39
+ expect(root.dataset.theme).toBe('dark');
40
+
41
+ instance.unmount();
42
+ fixture.unmount();
43
+ });
44
+ });
@@ -0,0 +1,80 @@
1
+ <script setup lang="ts">
2
+ import {computed, ref, watchEffect} from 'vue';
3
+ import type {PluginContext} from '@mndw/sdk';
4
+ import {column, type MndwTableProps} from '@mndw/ui';
5
+ import {useTheme, useTranslator} from '@mndw/sdk/vue';
6
+ import {vueCell} from '@mndw/ui-vue';
7
+ import TableNameCell from './TableNameCell.vue';
8
+
9
+ interface TableRow {
10
+ id: string;
11
+ name: string;
12
+ }
13
+
14
+ const {ctx} = defineProps<{ctx: PluginContext}>();
15
+ const translator = useTranslator(ctx.i18n);
16
+ const theme = useTheme(ctx);
17
+ const rows = computed<TableRow[]>(() => [
18
+ {id: 'first', name: translator.t('table.first')},
19
+ {id: 'second', name: translator.t('table.second')},
20
+ ]);
21
+ const columns = computed(() => [
22
+ column<TableRow>()({
23
+ id: 'name',
24
+ label: translator.t('table.column'),
25
+ accessor: (row) => row.name,
26
+ renderer: vueCell<TableRow, string>()(TableNameCell),
27
+ }),
28
+ ]);
29
+ const table = ref<(HTMLElement & MndwTableProps<TableRow>) | null>(null);
30
+
31
+ watchEffect(() => {
32
+ if (table.value === null) {
33
+ return;
34
+ }
35
+
36
+ Object.assign(table.value, {
37
+ columns: columns.value,
38
+ rows: rows.value,
39
+ rowKey: 'id',
40
+ caption: translator.t('table.caption'),
41
+ columnMenu: false,
42
+ });
43
+ });
44
+ </script>
45
+
46
+ <template>
47
+ <div class="wrap" :data-theme="theme">
48
+ <h3 class="title" data-testid="l10n-probe" data-plugin-label="__MNDW_LABEL__">{{ translator.t('l10n.probe') }}</h3>
49
+ <p class="device">Device: {{ ctx.deviceInfo.deviceName }}</p>
50
+ <p class="result">{{ translator.t('l10n.result') }}</p>
51
+ <mndw-table
52
+ ref="table"
53
+ :columns.prop="columns"
54
+ :rows.prop="rows"
55
+ :rowKey.prop="'id'"
56
+ :caption.prop="translator.t('table.caption')"
57
+ :columnMenu.prop="false"
58
+ />
59
+ </div>
60
+ </template>
61
+
62
+ <style scoped>
63
+ .wrap {
64
+ padding: var(--mndw-space-4);
65
+ font-family: var(--mndw-font-sans);
66
+ color: var(--mndw-text);
67
+ background: var(--mndw-surface);
68
+ }
69
+
70
+ .title {
71
+ margin: 0 0 var(--mndw-space-2);
72
+ font-size: var(--mndw-text-lg);
73
+ font-weight: var(--mndw-weight-semibold);
74
+ }
75
+
76
+ .device {
77
+ margin: 0;
78
+ color: var(--mndw-text-muted);
79
+ }
80
+ </style>