@kosdev-code/kos-ddk-cli 0.1.0-dev.57 → 0.1.0-dev.63
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/README.md +14 -1
- package/agent-plugin/kos-ddk-tools/.claude-plugin/plugin.json +1 -1
- package/agent-plugin/kos-ddk-tools/plugin.json +1 -1
- package/agent-plugin/kos-ddk-tools/reference/reference.json +6 -1
- package/agent-plugin/kos-ddk-tools/servers/kos-ddk.mjs +406 -393
- package/agent-plugin/kos-ddk-tools/skills/ddk-content-component/SKILL.md +10 -2
- package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.stories.tsx__template__ +30 -5
- package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.tsx__template__ +56 -5
- package/guides/storybook.md +5 -1
- package/package.json +2 -2
- package/reference/reference.json +6 -1
- package/src/codegen/contribution.mjs +16 -4
- package/src/codegen/descriptor.mjs +28 -0
- package/src/codegen/project.mjs +8 -2
- package/src/generators/contributions.mjs +13 -0
- package/src/mcp/tools.mjs +8 -1
- package/templates/utility/__nameDashCase__.stories.tsx__template__ +30 -5
- package/templates/utility/__nameDashCase__.tsx__template__ +56 -5
|
@@ -34,10 +34,18 @@ look of whichever theme the DDK app applies.
|
|
|
34
34
|
`useComponentConfigurationContext`, which switches it to compact mode), and the
|
|
35
35
|
tokens it reads. Pass props; never guess them.
|
|
36
36
|
|
|
37
|
-
4. **
|
|
37
|
+
4. **A utility renders in a modal.** `useUtilityModal({ onComplete, layout, onBack })`
|
|
38
|
+
from `@kosdev-code/kos-ddk-components` gives the `Modal` and `Header` props for the
|
|
39
|
+
standard or compact mode the DDK runs in, and `close()`, which runs `onComplete`
|
|
40
|
+
once the modal has closed. Keep the generated `Modal` / `Header` / `Content` /
|
|
41
|
+
`Footer` and spread its props; do not switch on `componentModeOverride` yourself.
|
|
42
|
+
`layout: "fullscreen"` covers the display (a screen test); in compact mode render
|
|
43
|
+
a Back button in the `Footer` when `showFooterBack` is true.
|
|
44
|
+
|
|
45
|
+
5. **Text** through the typography components (`Heading`, `Subheading`, `BodyMedium`,
|
|
38
46
|
`LabelSmall` and the rest) rather than styled text of your own.
|
|
39
47
|
|
|
40
|
-
|
|
48
|
+
6. **Check it** in Storybook (the `ddk-storybook` skill), in both render modes.
|
|
41
49
|
|
|
42
50
|
## Rules
|
|
43
51
|
|
package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.stories.tsx__template__
CHANGED
|
@@ -3,12 +3,19 @@
|
|
|
3
3
|
* Simulator is running in order to retrieve model data, unless the story mocks
|
|
4
4
|
* it with parameters.kosMock (ddk://guide/storybook).
|
|
5
5
|
*/
|
|
6
|
+
import { Button } from "@kosdev-code/kos-ddk-components";
|
|
6
7
|
import { UtilityStoryContainer } from "@kosdev-code/kos-ddk-story-containers";
|
|
7
8
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
9
|
+
import type { ComponentProps } from "react";
|
|
10
|
+
import { useArgs } from "storybook/preview-api";
|
|
11
|
+
import { fn } from "storybook/test";
|
|
8
12
|
import { <%= namePascalCase %> } from "./<%= nameDashCase %>";
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
/** `open` shows the utility; it turns off when the utility closes. */
|
|
15
|
+
type StoryArgs = ComponentProps<typeof <%= namePascalCase %>> & { open: boolean };
|
|
16
|
+
|
|
17
|
+
const meta: Meta<StoryArgs> = {
|
|
18
|
+
args: { onComplete: fn(), open: true },
|
|
12
19
|
component: <%= namePascalCase %>,
|
|
13
20
|
decorators: [
|
|
14
21
|
(Story, context) => (
|
|
@@ -23,10 +30,28 @@ const meta: Meta<typeof <%= namePascalCase %>> = {
|
|
|
23
30
|
|
|
24
31
|
export default meta;
|
|
25
32
|
|
|
26
|
-
type Story = StoryObj<
|
|
33
|
+
type Story = StoryObj<StoryArgs>;
|
|
27
34
|
|
|
28
35
|
export const Default: Story = {
|
|
29
36
|
// parameters: { kosMock: { setups: ["<setup module>"] } },
|
|
30
|
-
render: (
|
|
37
|
+
render: function Render({ open, onComplete, ...props }) {
|
|
38
|
+
const [, updateArgs] = useArgs<StoryArgs>();
|
|
39
|
+
return (
|
|
40
|
+
<>
|
|
41
|
+
{/* Behind the modal: reopens the utility after it closes. */}
|
|
42
|
+
<Button onPointerDown={() => updateArgs({ open: true })}>
|
|
43
|
+
Open <%= namePascalCase %>
|
|
44
|
+
</Button>
|
|
45
|
+
{open && (
|
|
46
|
+
<<%= namePascalCase %>
|
|
47
|
+
{...props}
|
|
48
|
+
onComplete={() => {
|
|
49
|
+
onComplete();
|
|
50
|
+
updateArgs({ open: false });
|
|
51
|
+
}}
|
|
52
|
+
/>
|
|
53
|
+
)}
|
|
54
|
+
</>
|
|
55
|
+
);
|
|
56
|
+
},
|
|
31
57
|
};
|
|
32
|
-
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import styled from '@emotion/styled';
|
|
2
2
|
import {
|
|
3
|
+
<% if (layout !== "fullscreen") { -%>
|
|
3
4
|
Button,
|
|
5
|
+
Content,
|
|
4
6
|
Footer,
|
|
7
|
+
<% } -%>
|
|
8
|
+
Header,
|
|
9
|
+
Modal,
|
|
10
|
+
useUtilityModal,
|
|
5
11
|
type Experience,
|
|
6
12
|
} from '@kosdev-code/kos-ddk-components';
|
|
7
13
|
import {
|
|
@@ -13,24 +19,69 @@ import {
|
|
|
13
19
|
const log = KosLog.createLogger({name: "<%= nameDashCase %>"})
|
|
14
20
|
log.debug("<%= nameDashCase %> component loaded");
|
|
15
21
|
|
|
16
|
-
const <%= namePascalCase %>Container = styled.
|
|
22
|
+
const <%= namePascalCase %>Container = styled.section`
|
|
17
23
|
align-items: center;
|
|
18
24
|
display: flex;
|
|
19
25
|
flex-direction: column;
|
|
26
|
+
gap: 32px;
|
|
27
|
+
height: 100%;
|
|
28
|
+
justify-content: center;
|
|
20
29
|
width: 100%;
|
|
21
30
|
`;
|
|
22
31
|
|
|
32
|
+
<% if (layout === "fullscreen") { -%>
|
|
33
|
+
/** A fullscreen utility: it covers the display and closes from its header. */
|
|
23
34
|
export const <%= namePascalCase %>: Experience = kosComponent(({ onComplete }) => {
|
|
24
35
|
const { t } = useKosTranslation('<%= appProject %>');
|
|
36
|
+
const { modalProps, headerProps } = useUtilityModal({
|
|
37
|
+
onComplete,
|
|
38
|
+
layout: "fullscreen",
|
|
39
|
+
closeButtonLabel: t('close'),
|
|
40
|
+
});
|
|
25
41
|
return (
|
|
26
|
-
|
|
27
|
-
|
|
42
|
+
<Modal {...modalProps}>
|
|
43
|
+
<Header
|
|
44
|
+
{...headerProps}
|
|
45
|
+
title={t('<%= appProject %>.<%= nameCamelCase %>.utility.title')}
|
|
46
|
+
/>
|
|
47
|
+
<<%= namePascalCase %>Container>
|
|
48
|
+
Hello from <%= namePascalCase %> Utility
|
|
49
|
+
</<%= namePascalCase %>Container>
|
|
50
|
+
</Modal>
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
<% } else { -%>
|
|
54
|
+
/**
|
|
55
|
+
* A utility in a modal. useUtilityModal fits the modal to the DDK's standard or
|
|
56
|
+
* compact mode; pass onBack (and showBack) for a utility with steps.
|
|
57
|
+
*/
|
|
58
|
+
export const <%= namePascalCase %>: Experience = kosComponent(({ onComplete }) => {
|
|
59
|
+
const { t } = useKosTranslation('<%= appProject %>');
|
|
60
|
+
const { modalProps, headerProps, close } = useUtilityModal({
|
|
61
|
+
onComplete,
|
|
62
|
+
closeButtonLabel: t('close'),
|
|
63
|
+
backButtonLabel: t('back'),
|
|
64
|
+
});
|
|
65
|
+
return (
|
|
66
|
+
<Modal {...modalProps}>
|
|
67
|
+
<Header
|
|
68
|
+
{...headerProps}
|
|
69
|
+
title={t('<%= appProject %>.<%= nameCamelCase %>.utility.title')}
|
|
70
|
+
/>
|
|
71
|
+
<Content align="center">
|
|
72
|
+
<<%= namePascalCase %>Container>
|
|
73
|
+
Hello from <%= namePascalCase %> Utility
|
|
74
|
+
</<%= namePascalCase %>Container>
|
|
75
|
+
</Content>
|
|
28
76
|
<Footer>
|
|
29
|
-
<Button
|
|
77
|
+
<Button mode="primary" onPointerDown={close}>
|
|
78
|
+
{t('done')}
|
|
79
|
+
</Button>
|
|
30
80
|
</Footer>
|
|
31
|
-
|
|
81
|
+
</Modal>
|
|
32
82
|
);
|
|
33
83
|
});
|
|
84
|
+
<% } -%>
|
|
34
85
|
|
|
35
86
|
<%= namePascalCase %>.displayName = "<%= namePascalCase %>"
|
|
36
87
|
|
package/guides/storybook.md
CHANGED
|
@@ -79,7 +79,7 @@ Each story renders the component inside the container for its extension point, f
|
|
|
79
79
|
|
|
80
80
|
| Command | Container | Gives the component |
|
|
81
81
|
| -------------------- | ----------------------------------------------------------------- | ----------------------------------------------------- |
|
|
82
|
-
| `ddk:utility` | `UtilityStoryContainer` | the utility
|
|
82
|
+
| `ddk:utility` | `UtilityStoryContainer` | nothing: the utility opens its own `Modal` |
|
|
83
83
|
| `ddk:setup` | `SetupStepStoryContainer` | the setup step frame |
|
|
84
84
|
| `ddk:nav` | `NavStoryContainer` | the navigation view frame |
|
|
85
85
|
| `ddk:cui` | `CUIStoryContainer` | the CUI frame |
|
|
@@ -92,6 +92,10 @@ Each story renders the component inside the container for its extension point, f
|
|
|
92
92
|
When the simulator has no matching model, holder or trouble, the container says so in place
|
|
93
93
|
of the story.
|
|
94
94
|
|
|
95
|
+
A utility story has an `open` control. Closing the utility turns it off and logs
|
|
96
|
+
`onComplete` in the Actions panel; the **Open** button behind the modal, or the
|
|
97
|
+
control, opens it again.
|
|
98
|
+
|
|
95
99
|
## Standard and compact modes
|
|
96
100
|
|
|
97
101
|
The **Render Mode** toolbar switches between `standard` and `compact`. It changes the DDK
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosdev-code/kos-ddk-cli",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.63",
|
|
4
4
|
"description": "DDK commands for kosui: plugin projects and DDK extension-point contributions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"kosui": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"kos": {
|
|
29
29
|
"build": {
|
|
30
|
-
"gitHash": "
|
|
30
|
+
"gitHash": "bc5245dbcb317a31a44c3441ff772db881239b65"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
package/reference/reference.json
CHANGED
|
@@ -18947,6 +18947,11 @@
|
|
|
18947
18947
|
"package": "@kosdev-code/kos-ddk-components",
|
|
18948
18948
|
"file": "src/hooks/router/useNavigate.tsx"
|
|
18949
18949
|
},
|
|
18950
|
+
{
|
|
18951
|
+
"name": "useUtilityModal",
|
|
18952
|
+
"package": "@kosdev-code/kos-ddk-components",
|
|
18953
|
+
"file": "src/components/modal/utility-modal/use-utility-modal.tsx"
|
|
18954
|
+
},
|
|
18950
18955
|
{
|
|
18951
18956
|
"name": "useViewExperience",
|
|
18952
18957
|
"package": "@kosdev-code/kos-ddk-components",
|
|
@@ -19235,7 +19240,7 @@
|
|
|
19235
19240
|
"name": "ddk-guide-storybook",
|
|
19236
19241
|
"title": "Developing DDK contributions in Storybook",
|
|
19237
19242
|
"description": "Running a plugin's Storybook against a simulator or with KosMock story mocks, where model data comes from, the story container per contribution command, render modes and overrides.",
|
|
19238
|
-
"body": "# Developing DDK contributions in Storybook\n\nEvery `ddk:*` contribution command writes a story next to the component, so a contribution\ncan be developed in isolation before the plugin is loaded into a running DDK. Stories render\nagainst live models from a running simulator.\n\n## Run it\n\n```sh\nnpx nx run <plugin>:storybook\n```\n\nStorybook serves on port 4400. The plugin's `serve` target is the module federation dev\nserver used by `kosui ddk:dev`; Storybook has its own `storybook` target.\n\n## Where model data comes from\n\nThe preview (`.storybook/preview.tsx`) wraps every story in the providers the DDK hosts use:\nKosCore, translations (`app/system`, `app/kosdev.ddk`), `AssemblyProvider`,\n`ApplicationProvider` and `ApplicationComponentConfigurationProvider`. KosCore connects to the\nfirst of:\n\n1. the `?host=` query parameter on the Storybook URL;\n2. `KOS_HOST` and `KOS_PORT` in the plugin's `.env` (the generated `.env` sets\n `KOS_PORT=8081`, the simulator's default);\n3. the page's own origin.\n\nTranslations come from the same device: the DDK's namespaces (`app/system`,\n`app/kosdev.ddk`) from its files, and the plugin's own namespace from the plugin's\n`src/assets/locales`, since the device lists it only once the KAB is installed. Each\ncontribution command adds its title key, and the keys its component calls, to\n`src/assets/locales/en/<plugin>.json`.\n\nStart the simulator before Storybook. A story shows what the simulator has: a dashboard card\nneeds an active model at its `dashboardKey`, a trouble action needs an active trouble of its\n`troubleType`.\n\n## Mocking what the simulator lacks\n\nA story can bring its own data with KosMock, the SDK's transport-level mocks\n(`kos://guide/mocking`), instead of waiting for the simulator to reach a state: an active\ntrouble, setup mode, a descriptor entry. It names the mocks as `parameters.kosMock`, and\nthe preview's outermost decorator reloads the page into those boot switches\n(`ensureKosMockBoot`):\n\n```tsx\nexport const ActiveTrouble: Story = {\n parameters: { kosMock: { setups: [\"daily-cleaning-trouble\"] } },\n};\n```\n\n`kosMock` takes `setups` (setup modules in `fixtures/setups/`), `fixture` (a recorded\nfixture), `mode` and `fixtureServer`:\n\n- `mode: \"on\"` (the default) mocks only the named endpoints over the running simulator.\n- `mode: \"standalone\"` boots with no device at all; every endpoint the story reads must\n be mocked.\n\nServe the fixtures beside Storybook:\n\n```sh\nkosui fixtures serve\n```\n\nA story without `kosMock` reloads without switches, so mocks never carry over between\nstories. Every generated story has a commented `kosMock` line to start from.\n\n## Story containers\n\nEach story renders the component inside the container for its extension point, from\n`@kosdev-code/kos-ddk-story-containers`:\n\n| Command | Container | Gives the component |\n| -------------------- | ----------------------------------------------------------------- | ----------------------------------------------------- |\n| `ddk:utility` | `UtilityStoryContainer` | the utility
|
|
19243
|
+
"body": "# Developing DDK contributions in Storybook\n\nEvery `ddk:*` contribution command writes a story next to the component, so a contribution\ncan be developed in isolation before the plugin is loaded into a running DDK. Stories render\nagainst live models from a running simulator.\n\n## Run it\n\n```sh\nnpx nx run <plugin>:storybook\n```\n\nStorybook serves on port 4400. The plugin's `serve` target is the module federation dev\nserver used by `kosui ddk:dev`; Storybook has its own `storybook` target.\n\n## Where model data comes from\n\nThe preview (`.storybook/preview.tsx`) wraps every story in the providers the DDK hosts use:\nKosCore, translations (`app/system`, `app/kosdev.ddk`), `AssemblyProvider`,\n`ApplicationProvider` and `ApplicationComponentConfigurationProvider`. KosCore connects to the\nfirst of:\n\n1. the `?host=` query parameter on the Storybook URL;\n2. `KOS_HOST` and `KOS_PORT` in the plugin's `.env` (the generated `.env` sets\n `KOS_PORT=8081`, the simulator's default);\n3. the page's own origin.\n\nTranslations come from the same device: the DDK's namespaces (`app/system`,\n`app/kosdev.ddk`) from its files, and the plugin's own namespace from the plugin's\n`src/assets/locales`, since the device lists it only once the KAB is installed. Each\ncontribution command adds its title key, and the keys its component calls, to\n`src/assets/locales/en/<plugin>.json`.\n\nStart the simulator before Storybook. A story shows what the simulator has: a dashboard card\nneeds an active model at its `dashboardKey`, a trouble action needs an active trouble of its\n`troubleType`.\n\n## Mocking what the simulator lacks\n\nA story can bring its own data with KosMock, the SDK's transport-level mocks\n(`kos://guide/mocking`), instead of waiting for the simulator to reach a state: an active\ntrouble, setup mode, a descriptor entry. It names the mocks as `parameters.kosMock`, and\nthe preview's outermost decorator reloads the page into those boot switches\n(`ensureKosMockBoot`):\n\n```tsx\nexport const ActiveTrouble: Story = {\n parameters: { kosMock: { setups: [\"daily-cleaning-trouble\"] } },\n};\n```\n\n`kosMock` takes `setups` (setup modules in `fixtures/setups/`), `fixture` (a recorded\nfixture), `mode` and `fixtureServer`:\n\n- `mode: \"on\"` (the default) mocks only the named endpoints over the running simulator.\n- `mode: \"standalone\"` boots with no device at all; every endpoint the story reads must\n be mocked.\n\nServe the fixtures beside Storybook:\n\n```sh\nkosui fixtures serve\n```\n\nA story without `kosMock` reloads without switches, so mocks never carry over between\nstories. Every generated story has a commented `kosMock` line to start from.\n\n## Story containers\n\nEach story renders the component inside the container for its extension point, from\n`@kosdev-code/kos-ddk-story-containers`:\n\n| Command | Container | Gives the component |\n| -------------------- | ----------------------------------------------------------------- | ----------------------------------------------------- |\n| `ddk:utility` | `UtilityStoryContainer` | nothing: the utility opens its own `Modal` |\n| `ddk:setup` | `SetupStepStoryContainer` | the setup step frame |\n| `ddk:nav` | `NavStoryContainer` | the navigation view frame |\n| `ddk:cui` | `CUIStoryContainer` | the CUI frame |\n| `ddk:dashboard-card` | `DashboardSummaryStoryContainer`, `DashboardDetailStoryContainer` | `dashboardKey`, `assembly`, `cardModel`, `onComplete` |\n| `ddk:pump-detail` | `PumpDetailStoryContainer` | the first `holder` with the `dashboardKey` |\n| `ddk:pump-card` | `PumpSummaryStoryContainer`, `PumpDetailStoryContainer` | the first `holder` with the `dashboardKey` |\n| `ddk:macro-summary` | `MacroSummaryStoryContainer` | the first `holder` with the `dashboardKey` |\n| `ddk:trouble-action` | `TroubleActionStoryContainer` | the active `trouble` of the `troubleType` |\n\nWhen the simulator has no matching model, holder or trouble, the container says so in place\nof the story.\n\nA utility story has an `open` control. Closing the utility turns it off and logs\n`onComplete` in the Actions panel; the **Open** button behind the modal, or the\ncontrol, opens it again.\n\n## Standard and compact modes\n\nThe **Render Mode** toolbar switches between `standard` and `compact`. It changes the DDK\nstyles and the component mode; in `compact`, modals render full screen.\n\n## Overrides\n\nA story renders the override on its own, so an override of a standard contribution can be\ndeveloped here first. To see it replace the standard contribution, load the plugin into a\nrunning DDK with `kosui ddk:dev` (see the package README)."
|
|
19239
19244
|
},
|
|
19240
19245
|
{
|
|
19241
19246
|
"uri": "ddk://guide/descriptor-project",
|
|
@@ -39,8 +39,9 @@ export const CONTRIBUTION_TYPES = {
|
|
|
39
39
|
overridable: "utilDescriptor",
|
|
40
40
|
listedIn: "kondra.ncui.utilities",
|
|
41
41
|
descriptorType: "utility",
|
|
42
|
+
layouts: ["maximized", "fullscreen"],
|
|
42
43
|
description:
|
|
43
|
-
"Create a utility; --descriptor is its kondra.ncui.utilities entry (default: from the name)",
|
|
44
|
+
"Create a utility in a modal; --layout maximized (default) or fullscreen; --descriptor is its kondra.ncui.utilities entry (default: from the name)",
|
|
44
45
|
},
|
|
45
46
|
nav: {
|
|
46
47
|
pluginType: "ddk.nav",
|
|
@@ -59,7 +60,7 @@ export const CONTRIBUTION_TYPES = {
|
|
|
59
60
|
export const TEMPLATE_KEYS = {
|
|
60
61
|
"ddk.cui": { proceed: "Proceed" },
|
|
61
62
|
"ddk.setup": { proceed: "Proceed" },
|
|
62
|
-
"ddk.utility": {
|
|
63
|
+
"ddk.utility": { back: "Back", close: "Close", done: "Done" },
|
|
63
64
|
"ddk.dashboardDetail": { close: "Close" },
|
|
64
65
|
"ddk.troubleAction": { resolve: "Resolve" },
|
|
65
66
|
};
|
|
@@ -126,9 +127,10 @@ const rankField = (rank) => (rank === undefined ? {} : { rank });
|
|
|
126
127
|
|
|
127
128
|
/**
|
|
128
129
|
* @param {{type: keyof CONTRIBUTION_TYPES, name: string, project: string,
|
|
129
|
-
* descriptor?: string, override?: string, rank?: number|string
|
|
130
|
+
* descriptor?: string, override?: string, rank?: number|string,
|
|
131
|
+
* layout?: string}} options
|
|
130
132
|
* `override` and `rank` apply to the rankable types (setup, utility, nav); `descriptor`
|
|
131
|
-
* to those and to cui, which requires it.
|
|
133
|
+
* to those and to cui, which requires it; `layout` to a utility's modal.
|
|
132
134
|
*/
|
|
133
135
|
export function generateDdkContribution(
|
|
134
136
|
codegenFs,
|
|
@@ -142,6 +144,7 @@ export function generateDdkContribution(
|
|
|
142
144
|
descriptorProject,
|
|
143
145
|
roles,
|
|
144
146
|
column,
|
|
147
|
+
layout,
|
|
145
148
|
}
|
|
146
149
|
) {
|
|
147
150
|
const spec = CONTRIBUTION_TYPES[type];
|
|
@@ -159,6 +162,14 @@ export function generateDdkContribution(
|
|
|
159
162
|
);
|
|
160
163
|
}
|
|
161
164
|
if (spec.required) requireOption(descriptor, `descriptor (${spec.required})`);
|
|
165
|
+
if (layout && !spec.layouts) {
|
|
166
|
+
throw new Error(`${type} contributions have no layout; --layout does not apply`);
|
|
167
|
+
}
|
|
168
|
+
if (layout && !spec.layouts.includes(layout)) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
`Unknown layout "${layout}". Choose from ${spec.layouts.join(", ")}.`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
162
173
|
const resolved = spec.overridable
|
|
163
174
|
? resolveOverride(type, {
|
|
164
175
|
override,
|
|
@@ -192,6 +203,7 @@ export function generateDdkContribution(
|
|
|
192
203
|
project,
|
|
193
204
|
...(slot ? { descriptor: slot } : {}),
|
|
194
205
|
...rankField(resolved.rank),
|
|
206
|
+
...(spec.layouts ? { layout: layout || spec.layouts[0] } : {}),
|
|
195
207
|
});
|
|
196
208
|
const listed = spec.descriptorType
|
|
197
209
|
? descriptorNotes(codegenFs, spec, {
|
|
@@ -43,6 +43,32 @@ function descriptorProject(codegenFs, name) {
|
|
|
43
43
|
return project;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* The KosMock setup module that serves a descriptor project without deploying it:
|
|
48
|
+
* `fixtures/setups/<name>.mjs`, relative to the workspace root, for
|
|
49
|
+
* `kosui fixtures serve`. Regenerated whenever the descriptor project changes.
|
|
50
|
+
*/
|
|
51
|
+
export function descriptorMockSetup(kosJson) {
|
|
52
|
+
const { name, kondra } = kosJson;
|
|
53
|
+
return {
|
|
54
|
+
path: path.join("fixtures", "setups", `${name}.mjs`),
|
|
55
|
+
content: `// Generated from the descriptor project ${name}; regenerated whenever a ddk
|
|
56
|
+
// command lists an entry there, so put other mocking in a setup of its own.
|
|
57
|
+
// Serves ${name} as the installed NCUI descriptor without deploying it: run
|
|
58
|
+
// \`kosui fixtures serve\` and open the DDK app with
|
|
59
|
+
// ?kosMock=on&kosFixtureServer&kosSetup=${name}
|
|
60
|
+
const descriptor = ${JSON.stringify({ kondra }, null, 2)};
|
|
61
|
+
|
|
62
|
+
export default (kosMock) => {
|
|
63
|
+
if (!kosMock.ddk) {
|
|
64
|
+
throw new Error("kosMock.ddk is missing: it needs a DDK and kos-ui-sdk that provide it");
|
|
65
|
+
}
|
|
66
|
+
return kosMock.ddk.useDescriptor(descriptor);
|
|
67
|
+
};
|
|
68
|
+
`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
46
72
|
const parseRoles = (roles) =>
|
|
47
73
|
(Array.isArray(roles) ? roles : String(roles ?? "").split(","))
|
|
48
74
|
.map((role) => role.trim())
|
|
@@ -117,6 +143,8 @@ export function addDescriptorEntry(
|
|
|
117
143
|
}
|
|
118
144
|
|
|
119
145
|
codegenFs.write(kosJsonPath, JSON.stringify(kosJson, null, 2) + "\n");
|
|
146
|
+
const setup = descriptorMockSetup(kosJson);
|
|
147
|
+
codegenFs.write(setup.path, setup.content);
|
|
120
148
|
return note;
|
|
121
149
|
}
|
|
122
150
|
|
package/src/codegen/project.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import fs from "node:fs";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { findProjectByName } from "@kosdev-code/kos-codegen-core";
|
|
7
7
|
import { TEMPLATES_DIR } from "../handlers.mjs";
|
|
8
|
-
import { DESCRIPTOR_KAB_TYPE } from "./descriptor.mjs";
|
|
8
|
+
import { DESCRIPTOR_KAB_TYPE, descriptorMockSetup } from "./descriptor.mjs";
|
|
9
9
|
import { buildNcuiDescriptor } from "./ncui-descriptor.mjs";
|
|
10
10
|
|
|
11
11
|
export const DDK_VERSION = "~3.1.0";
|
|
@@ -87,12 +87,16 @@ function overlayTheme(_workspaceRoot, projectRoot) {
|
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
function overlayDescriptor(
|
|
90
|
+
function overlayDescriptor(workspaceRoot, projectRoot, { ncui } = {}) {
|
|
91
91
|
const kosJsonPath = path.join(projectRoot, ".kos.json");
|
|
92
92
|
const kosJson = readJson(kosJsonPath);
|
|
93
93
|
kosJson.type = DESCRIPTOR_KAB_TYPE;
|
|
94
94
|
kosJson.kondra = buildNcuiDescriptor(ncui);
|
|
95
95
|
writeJson(kosJsonPath, kosJson);
|
|
96
|
+
const setup = descriptorMockSetup(kosJson);
|
|
97
|
+
const setupPath = path.join(workspaceRoot, setup.path);
|
|
98
|
+
fs.mkdirSync(path.dirname(setupPath), { recursive: true });
|
|
99
|
+
fs.writeFileSync(setupPath, setup.content);
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
const PROJECT_KINDS = {
|
|
@@ -223,6 +227,8 @@ export function createDdkProject(
|
|
|
223
227
|
`.kos.json: type ${DESCRIPTOR_KAB_TYPE}, kondra.ncui for the ${
|
|
224
228
|
ncui.layout ?? "standard"
|
|
225
229
|
} layout`,
|
|
230
|
+
descriptorMockSetup({ name }).path +
|
|
231
|
+
": KosMock setup serving the descriptor",
|
|
226
232
|
]
|
|
227
233
|
: templateFiles(kind),
|
|
228
234
|
};
|
|
@@ -33,6 +33,7 @@ export const metadata = Object.entries(CONTRIBUTION_TYPES).map(
|
|
|
33
33
|
...baseArguments,
|
|
34
34
|
...(spec.overridable ? rankArguments : {}),
|
|
35
35
|
...(spec.descriptorType === "utility" ? { column: "column" } : {}),
|
|
36
|
+
...(spec.layouts ? { layout: "layout" } : {}),
|
|
36
37
|
...(spec.required ? { descriptor: "descriptor" } : {}),
|
|
37
38
|
},
|
|
38
39
|
})
|
|
@@ -55,6 +56,7 @@ export async function register(plop, { host }) {
|
|
|
55
56
|
descriptorProject: answers.descriptorProject || undefined,
|
|
56
57
|
roles: answers.roles || undefined,
|
|
57
58
|
column: answers.column || undefined,
|
|
59
|
+
layout: answers.layout || undefined,
|
|
58
60
|
});
|
|
59
61
|
return host.reportCodegen(
|
|
60
62
|
codegenFs,
|
|
@@ -86,6 +88,17 @@ export async function register(plop, { host }) {
|
|
|
86
88
|
message: "Which plugin project should the component be created in?",
|
|
87
89
|
choices: pluginProjects,
|
|
88
90
|
},
|
|
91
|
+
...(spec.layouts
|
|
92
|
+
? [
|
|
93
|
+
{
|
|
94
|
+
type: "list",
|
|
95
|
+
name: "layout",
|
|
96
|
+
message: "Modal layout?",
|
|
97
|
+
choices: spec.layouts,
|
|
98
|
+
default: spec.layouts[0],
|
|
99
|
+
},
|
|
100
|
+
]
|
|
101
|
+
: []),
|
|
89
102
|
...(spec.required
|
|
90
103
|
? [
|
|
91
104
|
{
|
package/src/mcp/tools.mjs
CHANGED
|
@@ -107,6 +107,7 @@ function contributionTool(
|
|
|
107
107
|
descriptorProject: args.descriptorProject,
|
|
108
108
|
roles: args.roles,
|
|
109
109
|
column: args.column,
|
|
110
|
+
layout: args.layout,
|
|
110
111
|
})
|
|
111
112
|
),
|
|
112
113
|
};
|
|
@@ -223,13 +224,19 @@ export const ddkTools = [
|
|
|
223
224
|
contributionTool(
|
|
224
225
|
"add_utility",
|
|
225
226
|
"utility",
|
|
226
|
-
"Add a utility (utilities contribution) with its component, story and i18n title.",
|
|
227
|
+
"Add a utility (utilities contribution) with its component, story and i18n title. The component renders in a modal through useUtilityModal.",
|
|
227
228
|
slot("utilDescriptor", "kondra.ncui.utilities", {
|
|
228
229
|
column: {
|
|
229
230
|
type: "integer",
|
|
230
231
|
description:
|
|
231
232
|
"With descriptorProject: utilities column, 1-based. Default: the last.",
|
|
232
233
|
},
|
|
234
|
+
layout: {
|
|
235
|
+
type: "string",
|
|
236
|
+
enum: ["maximized", "fullscreen"],
|
|
237
|
+
description:
|
|
238
|
+
"The utility's modal: maximized (default, a modal over the shell) or fullscreen (covers the display).",
|
|
239
|
+
},
|
|
233
240
|
})
|
|
234
241
|
),
|
|
235
242
|
contributionTool(
|
|
@@ -3,12 +3,19 @@
|
|
|
3
3
|
* Simulator is running in order to retrieve model data, unless the story mocks
|
|
4
4
|
* it with parameters.kosMock (ddk://guide/storybook).
|
|
5
5
|
*/
|
|
6
|
+
import { Button } from "@kosdev-code/kos-ddk-components";
|
|
6
7
|
import { UtilityStoryContainer } from "@kosdev-code/kos-ddk-story-containers";
|
|
7
8
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
9
|
+
import type { ComponentProps } from "react";
|
|
10
|
+
import { useArgs } from "storybook/preview-api";
|
|
11
|
+
import { fn } from "storybook/test";
|
|
8
12
|
import { <%= namePascalCase %> } from "./<%= nameDashCase %>";
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
/** `open` shows the utility; it turns off when the utility closes. */
|
|
15
|
+
type StoryArgs = ComponentProps<typeof <%= namePascalCase %>> & { open: boolean };
|
|
16
|
+
|
|
17
|
+
const meta: Meta<StoryArgs> = {
|
|
18
|
+
args: { onComplete: fn(), open: true },
|
|
12
19
|
component: <%= namePascalCase %>,
|
|
13
20
|
decorators: [
|
|
14
21
|
(Story, context) => (
|
|
@@ -23,10 +30,28 @@ const meta: Meta<typeof <%= namePascalCase %>> = {
|
|
|
23
30
|
|
|
24
31
|
export default meta;
|
|
25
32
|
|
|
26
|
-
type Story = StoryObj<
|
|
33
|
+
type Story = StoryObj<StoryArgs>;
|
|
27
34
|
|
|
28
35
|
export const Default: Story = {
|
|
29
36
|
// parameters: { kosMock: { setups: ["<setup module>"] } },
|
|
30
|
-
render: (
|
|
37
|
+
render: function Render({ open, onComplete, ...props }) {
|
|
38
|
+
const [, updateArgs] = useArgs<StoryArgs>();
|
|
39
|
+
return (
|
|
40
|
+
<>
|
|
41
|
+
{/* Behind the modal: reopens the utility after it closes. */}
|
|
42
|
+
<Button onPointerDown={() => updateArgs({ open: true })}>
|
|
43
|
+
Open <%= namePascalCase %>
|
|
44
|
+
</Button>
|
|
45
|
+
{open && (
|
|
46
|
+
<<%= namePascalCase %>
|
|
47
|
+
{...props}
|
|
48
|
+
onComplete={() => {
|
|
49
|
+
onComplete();
|
|
50
|
+
updateArgs({ open: false });
|
|
51
|
+
}}
|
|
52
|
+
/>
|
|
53
|
+
)}
|
|
54
|
+
</>
|
|
55
|
+
);
|
|
56
|
+
},
|
|
31
57
|
};
|
|
32
|
-
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import styled from '@emotion/styled';
|
|
2
2
|
import {
|
|
3
|
+
<% if (layout !== "fullscreen") { -%>
|
|
3
4
|
Button,
|
|
5
|
+
Content,
|
|
4
6
|
Footer,
|
|
7
|
+
<% } -%>
|
|
8
|
+
Header,
|
|
9
|
+
Modal,
|
|
10
|
+
useUtilityModal,
|
|
5
11
|
type Experience,
|
|
6
12
|
} from '@kosdev-code/kos-ddk-components';
|
|
7
13
|
import {
|
|
@@ -13,24 +19,69 @@ import {
|
|
|
13
19
|
const log = KosLog.createLogger({name: "<%= nameDashCase %>"})
|
|
14
20
|
log.debug("<%= nameDashCase %> component loaded");
|
|
15
21
|
|
|
16
|
-
const <%= namePascalCase %>Container = styled.
|
|
22
|
+
const <%= namePascalCase %>Container = styled.section`
|
|
17
23
|
align-items: center;
|
|
18
24
|
display: flex;
|
|
19
25
|
flex-direction: column;
|
|
26
|
+
gap: 32px;
|
|
27
|
+
height: 100%;
|
|
28
|
+
justify-content: center;
|
|
20
29
|
width: 100%;
|
|
21
30
|
`;
|
|
22
31
|
|
|
32
|
+
<% if (layout === "fullscreen") { -%>
|
|
33
|
+
/** A fullscreen utility: it covers the display and closes from its header. */
|
|
23
34
|
export const <%= namePascalCase %>: Experience = kosComponent(({ onComplete }) => {
|
|
24
35
|
const { t } = useKosTranslation('<%= appProject %>');
|
|
36
|
+
const { modalProps, headerProps } = useUtilityModal({
|
|
37
|
+
onComplete,
|
|
38
|
+
layout: "fullscreen",
|
|
39
|
+
closeButtonLabel: t('close'),
|
|
40
|
+
});
|
|
25
41
|
return (
|
|
26
|
-
|
|
27
|
-
|
|
42
|
+
<Modal {...modalProps}>
|
|
43
|
+
<Header
|
|
44
|
+
{...headerProps}
|
|
45
|
+
title={t('<%= appProject %>.<%= nameCamelCase %>.utility.title')}
|
|
46
|
+
/>
|
|
47
|
+
<<%= namePascalCase %>Container>
|
|
48
|
+
Hello from <%= namePascalCase %> Utility
|
|
49
|
+
</<%= namePascalCase %>Container>
|
|
50
|
+
</Modal>
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
<% } else { -%>
|
|
54
|
+
/**
|
|
55
|
+
* A utility in a modal. useUtilityModal fits the modal to the DDK's standard or
|
|
56
|
+
* compact mode; pass onBack (and showBack) for a utility with steps.
|
|
57
|
+
*/
|
|
58
|
+
export const <%= namePascalCase %>: Experience = kosComponent(({ onComplete }) => {
|
|
59
|
+
const { t } = useKosTranslation('<%= appProject %>');
|
|
60
|
+
const { modalProps, headerProps, close } = useUtilityModal({
|
|
61
|
+
onComplete,
|
|
62
|
+
closeButtonLabel: t('close'),
|
|
63
|
+
backButtonLabel: t('back'),
|
|
64
|
+
});
|
|
65
|
+
return (
|
|
66
|
+
<Modal {...modalProps}>
|
|
67
|
+
<Header
|
|
68
|
+
{...headerProps}
|
|
69
|
+
title={t('<%= appProject %>.<%= nameCamelCase %>.utility.title')}
|
|
70
|
+
/>
|
|
71
|
+
<Content align="center">
|
|
72
|
+
<<%= namePascalCase %>Container>
|
|
73
|
+
Hello from <%= namePascalCase %> Utility
|
|
74
|
+
</<%= namePascalCase %>Container>
|
|
75
|
+
</Content>
|
|
28
76
|
<Footer>
|
|
29
|
-
<Button
|
|
77
|
+
<Button mode="primary" onPointerDown={close}>
|
|
78
|
+
{t('done')}
|
|
79
|
+
</Button>
|
|
30
80
|
</Footer>
|
|
31
|
-
|
|
81
|
+
</Modal>
|
|
32
82
|
);
|
|
33
83
|
});
|
|
84
|
+
<% } -%>
|
|
34
85
|
|
|
35
86
|
<%= namePascalCase %>.displayName = "<%= namePascalCase %>"
|
|
36
87
|
|