@mndw/cli 0.1.5 → 0.2.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/dist/meta.json +83 -27
- package/dist/mndw.js +391 -101
- package/host-dev/assets/index-BqQCCILo.css +1 -0
- package/host-dev/assets/index-DFVRx7na.js +94 -0
- package/host-dev/assets/sandbox-url-D8HO7UBF.js +1 -0
- package/host-dev/index.html +3 -3
- package/host-dev/shared/mndw-ui@0.2.0.js +1805 -0
- package/package.json +18 -14
- package/templates/angular/i18n/en.json +4 -9
- package/templates/angular/i18n/ru.json +4 -9
- package/templates/angular/src/app.component.ts +39 -39
- package/templates/angular/src/index.ts +14 -1
- package/templates/angular/src/l10n.test.ts +50 -17
- package/templates/go/i18n/en.json +1 -1
- package/templates/go/i18n/ru.json +1 -1
- package/templates/go/src/index.css +4 -20
- package/templates/go/src/index.test.ts +12 -24
- package/templates/go/src/index.ts +18 -15
- package/templates/go/src/l10n.test.ts +37 -23
- package/templates/svelte/i18n/en.json +4 -9
- package/templates/svelte/i18n/ru.json +4 -9
- package/templates/svelte/src/App.svelte +46 -72
- package/templates/svelte/src/index.ts +7 -0
- package/templates/svelte/src/l10n.test.ts +64 -17
- package/templates/svelte/svelte.config.js +7 -0
- package/templates/svelte/vitest.config.ts +2 -1
- package/templates/vanilla/i18n/en.json +4 -3
- package/templates/vanilla/i18n/ru.json +4 -3
- package/templates/vanilla/src/index.css +4 -20
- package/templates/vanilla/src/index.ts +47 -17
- package/templates/vanilla/src/l10n.test.ts +50 -17
- package/templates/vue/i18n/en.json +4 -9
- package/templates/vue/i18n/ru.json +4 -9
- package/templates/vue/src/App.vue +36 -54
- package/templates/vue/src/index.ts +7 -0
- package/templates/vue/src/l10n.test.ts +50 -17
- package/host-dev/assets/index-CJ80zEWN.js +0 -94
- package/host-dev/assets/index-DNxACGUr.css +0 -1
- package/host-dev/assets/sandbox-url-Dk7HpxDp.js +0 -1
- package/host-dev/shared/mndw-ui@0.1.5.js +0 -1782
- package/templates/angular/src/table.test.ts +0 -59
- package/templates/svelte/src/TableNameCell.svelte +0 -10
- package/templates/svelte/src/table.test.ts +0 -53
- package/templates/vue/src/TableNameCell.vue +0 -12
- package/templates/vue/src/table.test.ts +0 -53
|
@@ -1,80 +1,62 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import {ref} from 'vue';
|
|
3
3
|
import type {PluginContext} from '@mndw/sdk';
|
|
4
|
-
import {
|
|
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
|
-
}
|
|
4
|
+
import {useTranslator} from '@mndw/sdk/vue';
|
|
13
5
|
|
|
14
6
|
const {ctx} = defineProps<{ctx: PluginContext}>();
|
|
15
7
|
const translator = useTranslator(ctx.i18n);
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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);
|
|
8
|
+
const backendMessage = ref<string | undefined>();
|
|
9
|
+
const backendError = ref(false);
|
|
10
|
+
|
|
11
|
+
const load = async (): Promise<void> => {
|
|
12
|
+
if (ctx.backend === undefined) {
|
|
13
|
+
backendError.value = true;
|
|
30
14
|
|
|
31
|
-
watchEffect(() => {
|
|
32
|
-
if (table.value === null) {
|
|
33
15
|
return;
|
|
34
16
|
}
|
|
35
17
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
18
|
+
try {
|
|
19
|
+
const response = await ctx.backend.call<{message: string}>('hello', {as: 'json'});
|
|
20
|
+
backendMessage.value = response.message;
|
|
21
|
+
backendError.value = false;
|
|
22
|
+
} catch {
|
|
23
|
+
backendMessage.value = undefined;
|
|
24
|
+
backendError.value = true;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
44
27
|
</script>
|
|
45
28
|
|
|
46
29
|
<template>
|
|
47
|
-
<
|
|
48
|
-
<
|
|
30
|
+
<section class="__MNDW_NAME__" :aria-labelledby="ctx.kind === 'page' ? 'plugin-title' : undefined">
|
|
31
|
+
<h2 v-if="ctx.kind === 'page'" id="plugin-title">{{ translator.t('l10n.title') }}</h2>
|
|
49
32
|
<p class="device">Device: {{ ctx.deviceInfo.deviceName }}</p>
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
33
|
+
<mndw-button variant="primary" type="button" @click="void load()">
|
|
34
|
+
{{ translator.t('l10n.button') }}
|
|
35
|
+
</mndw-button>
|
|
36
|
+
<p class="result" :role="backendError ? 'alert' : 'status'" aria-live="polite">
|
|
37
|
+
<template v-if="backendError">{{ translator.t('l10n.error') }}</template>
|
|
38
|
+
<template v-else-if="backendMessage !== undefined">
|
|
39
|
+
{{ translator.t('l10n.result') }}: {{ backendMessage }}
|
|
40
|
+
</template>
|
|
41
|
+
<template v-else>{{ translator.t('l10n.result') }}</template>
|
|
42
|
+
</p>
|
|
43
|
+
</section>
|
|
60
44
|
</template>
|
|
61
45
|
|
|
62
46
|
<style scoped>
|
|
63
|
-
.
|
|
47
|
+
.__MNDW_NAME__ {
|
|
64
48
|
padding: var(--mndw-space-4);
|
|
65
49
|
font-family: var(--mndw-font-sans);
|
|
66
50
|
color: var(--mndw-text);
|
|
67
51
|
background: var(--mndw-surface);
|
|
68
52
|
}
|
|
69
53
|
|
|
70
|
-
.
|
|
71
|
-
margin: 0 0 var(--mndw-space-
|
|
72
|
-
|
|
73
|
-
font-weight: var(--mndw-weight-semibold);
|
|
54
|
+
.__MNDW_NAME__ .device {
|
|
55
|
+
margin: 0 0 var(--mndw-space-3);
|
|
56
|
+
color: var(--mndw-text-muted);
|
|
74
57
|
}
|
|
75
58
|
|
|
76
|
-
.
|
|
77
|
-
margin: 0;
|
|
78
|
-
color: var(--mndw-text-muted);
|
|
59
|
+
.__MNDW_NAME__ .result {
|
|
60
|
+
margin-block: var(--mndw-space-3) 0;
|
|
79
61
|
}
|
|
80
62
|
</style>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {PluginContext, PluginInstance} from '@mndw/sdk';
|
|
2
2
|
import {createApp} from 'vue';
|
|
3
|
+
import {bindLocale} from '@mndw/sdk/bind-locale';
|
|
3
4
|
|
|
4
5
|
import App from './App.vue';
|
|
5
6
|
|
|
@@ -7,9 +8,15 @@ export function createInstance(container: HTMLElement, ctx: PluginContext): Plug
|
|
|
7
8
|
const app = createApp(App, {ctx});
|
|
8
9
|
|
|
9
10
|
app.mount(container);
|
|
11
|
+
const unsubscribeLocale = bindLocale(ctx.i18n, () => {
|
|
12
|
+
if (ctx.kind === 'widget') {
|
|
13
|
+
ctx.setTileTitle?.(ctx.i18n.t('l10n.title'));
|
|
14
|
+
}
|
|
15
|
+
});
|
|
10
16
|
|
|
11
17
|
return {
|
|
12
18
|
unmount() {
|
|
19
|
+
unsubscribeLocale();
|
|
13
20
|
app.unmount();
|
|
14
21
|
},
|
|
15
22
|
};
|
|
@@ -1,43 +1,76 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
2
|
|
|
3
3
|
import {createApp, nextTick} from 'vue';
|
|
4
|
-
import type {PluginContext} from '@mndw/sdk';
|
|
4
|
+
import type {BackendClient, PluginContext} from '@mndw/sdk';
|
|
5
5
|
import {createTestI18n, createTestPluginContext} from '@mndw/sdk/testing';
|
|
6
|
-
import {describe, expect, it} from 'vitest';
|
|
6
|
+
import {describe, expect, it, vi} from 'vitest';
|
|
7
7
|
import App from './App.vue';
|
|
8
|
+
import {createInstance} from './index.js';
|
|
8
9
|
|
|
9
|
-
const contextFor = (i18n: ReturnType<typeof createTestI18n>): PluginContext =>
|
|
10
|
+
const contextFor = (i18n: ReturnType<typeof createTestI18n>): PluginContext =>
|
|
11
|
+
createTestPluginContext({i18n, kind: 'page'}).context;
|
|
10
12
|
|
|
11
13
|
describe('generated Vue locale reactivity', () => {
|
|
12
|
-
it('updates
|
|
13
|
-
const en = {l10n: {
|
|
14
|
-
const ru = {l10n: {
|
|
14
|
+
it('updates visible result without remounting', async () => {
|
|
15
|
+
const en = {l10n: {title: 'Plugin title', button: 'Run English', result: 'English result', error: 'Error'}};
|
|
16
|
+
const ru = {l10n: {title: 'Заголовок', button: 'Запустить', result: 'Русский результат', error: 'Ошибка'}};
|
|
15
17
|
const i18n = createTestI18n(en, 'en');
|
|
16
18
|
const root = document.createElement('div');
|
|
17
19
|
const app = createApp(App, {ctx: contextFor(i18n)});
|
|
18
20
|
app.mount(root);
|
|
19
|
-
const
|
|
21
|
+
const title = root.querySelector('h2');
|
|
22
|
+
const button = root.querySelector('mndw-button');
|
|
23
|
+
const result = root.querySelector('.result');
|
|
20
24
|
|
|
21
|
-
expect(
|
|
22
|
-
expect(
|
|
25
|
+
expect(title?.textContent).toBe(en.l10n.title);
|
|
26
|
+
expect(root.firstElementChild?.getAttribute('aria-labelledby')).toBe(title?.id);
|
|
27
|
+
expect(button?.textContent).toContain(en.l10n.button);
|
|
28
|
+
expect(result?.textContent).toBe(en.l10n.result);
|
|
23
29
|
i18n.setLocale('ru', ru);
|
|
24
30
|
await nextTick();
|
|
25
31
|
|
|
26
|
-
expect(
|
|
27
|
-
expect(
|
|
32
|
+
expect(title?.textContent).toBe(ru.l10n.title);
|
|
33
|
+
expect(button?.textContent).toContain(ru.l10n.button);
|
|
34
|
+
expect(result?.textContent).toBe(ru.l10n.result);
|
|
28
35
|
app.unmount();
|
|
29
36
|
});
|
|
30
37
|
|
|
31
|
-
it('
|
|
32
|
-
const
|
|
38
|
+
it('sets a translated host title for widgets without drawing an internal heading', () => {
|
|
39
|
+
const en = {l10n: {title: 'Plugin title', button: 'Run', result: 'Result', error: 'Error'}};
|
|
40
|
+
const ru = {l10n: {title: 'Заголовок', button: 'Запустить', result: 'Результат', error: 'Ошибка'}};
|
|
41
|
+
const i18n = createTestI18n(en, 'en');
|
|
42
|
+
const setTileTitle = vi.fn();
|
|
43
|
+
const fixture = createTestPluginContext({i18n});
|
|
44
|
+
const context = Object.assign(Object.create(fixture.context), {setTileTitle}) as PluginContext;
|
|
45
|
+
const root = document.createElement('div');
|
|
46
|
+
const instance = createInstance(root, context);
|
|
47
|
+
|
|
48
|
+
expect(setTileTitle).toHaveBeenLastCalledWith(en.l10n.title);
|
|
49
|
+
expect(root.querySelector('h2')).toBeNull();
|
|
50
|
+
expect(root.firstElementChild?.hasAttribute('aria-labelledby')).toBe(false);
|
|
51
|
+
i18n.setLocale('ru', ru);
|
|
52
|
+
|
|
53
|
+
expect(setTileTitle).toHaveBeenLastCalledWith(ru.l10n.title);
|
|
54
|
+
instance.unmount();
|
|
55
|
+
fixture.unmount();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('calls the backend when the shared button is clicked', async () => {
|
|
59
|
+
const call = vi.fn().mockResolvedValue({message: 'hello'});
|
|
60
|
+
const i18n = createTestI18n({
|
|
61
|
+
l10n: {title: 'Plugin title', button: 'Run', result: 'Backend response', error: 'Unavailable'},
|
|
62
|
+
});
|
|
63
|
+
const fixture = createTestPluginContext({i18n, backend: {call} as unknown as BackendClient});
|
|
33
64
|
const root = document.createElement('div');
|
|
34
65
|
const app = createApp(App, {ctx: fixture.context});
|
|
35
66
|
app.mount(root);
|
|
36
67
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
await
|
|
40
|
-
|
|
68
|
+
root.querySelector('mndw-button')?.dispatchEvent(new MouseEvent('click', {bubbles: true}));
|
|
69
|
+
|
|
70
|
+
await vi.waitFor(() => {
|
|
71
|
+
expect(call).toHaveBeenCalledWith('hello', {as: 'json'});
|
|
72
|
+
expect(root.querySelector('.result')?.textContent).toBe('Backend response: hello');
|
|
73
|
+
});
|
|
41
74
|
|
|
42
75
|
app.unmount();
|
|
43
76
|
fixture.unmount();
|