@djangocfg/ui-tools 2.1.382 → 2.1.383
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/DictationField-U25MEYAL.mjs +4 -0
- package/dist/{DictationField-2ZLQWLYV.mjs.map → DictationField-U25MEYAL.mjs.map} +1 -1
- package/dist/DictationField-XWR5VOID.cjs +13 -0
- package/dist/{DictationField-IPPJ54CU.cjs.map → DictationField-XWR5VOID.cjs.map} +1 -1
- package/dist/{chunk-KMSBGNVC.cjs → chunk-4PFW7MIJ.cjs} +4 -2
- package/dist/chunk-4PFW7MIJ.cjs.map +1 -0
- package/dist/{chunk-4LXG3NBV.mjs → chunk-C2YN6WEO.mjs} +3 -3
- package/dist/chunk-C2YN6WEO.mjs.map +1 -0
- package/dist/index.cjs +139 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +68 -1
- package/dist/index.d.ts +68 -1
- package/dist/index.mjs +141 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -13
- package/src/tools/Chat/index.ts +15 -0
- package/dist/DictationField-2ZLQWLYV.mjs +0 -4
- package/dist/DictationField-IPPJ54CU.cjs +0 -13
- package/dist/chunk-4LXG3NBV.mjs.map +0 -1
- package/dist/chunk-KMSBGNVC.cjs.map +0 -1
- package/src/components/markdown/MarkdownMessage/MarkdownMessage.story.tsx +0 -771
- package/src/stories/index.ts +0 -63
- package/src/tools/AudioPlayer/AudioPlayer.story.tsx +0 -481
- package/src/tools/Chat/stories/01-basic.story.tsx +0 -64
- package/src/tools/Chat/stories/02-bubbles.story.tsx +0 -21
- package/src/tools/Chat/stories/03-tool-calls.story.tsx +0 -59
- package/src/tools/Chat/stories/04-personas.story.tsx +0 -78
- package/src/tools/Chat/stories/05-launcher.story.tsx +0 -321
- package/src/tools/Chat/stories/06-header.story.tsx +0 -147
- package/src/tools/Chat/stories/07-audio-actions.story.tsx +0 -112
- package/src/tools/Chat/stories/shared/Frame.tsx +0 -21
- package/src/tools/Chat/stories/shared/index.ts +0 -5
- package/src/tools/Chat/stories/shared/messages.ts +0 -39
- package/src/tools/Chat/stories/shared/personas.ts +0 -13
- package/src/tools/Chat/stories/shared/seeds.ts +0 -92
- package/src/tools/Chat/stories/shared/transports.ts +0 -36
- package/src/tools/CodeEditor/CodeEditor.story.tsx +0 -202
- package/src/tools/CronScheduler/CronScheduler.story.tsx +0 -300
- package/src/tools/Gallery/Gallery.story.tsx +0 -237
- package/src/tools/ImageViewer/ImageViewer.story.tsx +0 -85
- package/src/tools/JsonForm/JsonForm.story.tsx +0 -350
- package/src/tools/JsonTree/JsonTree.story.tsx +0 -141
- package/src/tools/LottiePlayer/LottiePlayer.story.tsx +0 -95
- package/src/tools/Map/Map.story.tsx +0 -458
- package/src/tools/MarkdownEditor/MarkdownEditor.story.tsx +0 -225
- package/src/tools/Mermaid/Mermaid.story.tsx +0 -251
- package/src/tools/OpenapiViewer/OpenapiViewer.story.tsx +0 -230
- package/src/tools/PrettyCode/PrettyCode.story.tsx +0 -304
- package/src/tools/SpeechRecognition/stories/01-basic.story.tsx +0 -32
- package/src/tools/SpeechRecognition/stories/02-dictation-field.story.tsx +0 -32
- package/src/tools/SpeechRecognition/stories/03-push-to-talk.story.tsx +0 -27
- package/src/tools/SpeechRecognition/stories/04-mic-meter.story.tsx +0 -35
- package/src/tools/SpeechRecognition/stories/05-custom-engine-http.story.tsx +0 -40
- package/src/tools/SpeechRecognition/stories/06-custom-engine-ws.story.tsx +0 -48
- package/src/tools/SpeechRecognition/stories/07-language-device.story.tsx +0 -57
- package/src/tools/SpeechRecognition/stories/08-errors-permissions.story.tsx +0 -25
- package/src/tools/SpeechRecognition/stories/09-chat-voice.story.tsx +0 -90
- package/src/tools/SpeechRecognition/stories/shared.tsx +0 -123
- package/src/tools/Tour/Tour.story.tsx +0 -279
- package/src/tools/Tree/Tree.story.tsx +0 -620
- package/src/tools/Uploader/Uploader.story.tsx +0 -415
- package/src/tools/VideoPlayer/VideoPlayer.story.tsx +0 -87
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { ChatMessage } from '../../types';
|
|
2
|
-
|
|
3
|
-
/** Compact transcript that exercises every bubble state for visual review. */
|
|
4
|
-
export const BUBBLE_GALLERY: ChatMessage[] = [
|
|
5
|
-
{
|
|
6
|
-
id: 'u-1',
|
|
7
|
-
role: 'user',
|
|
8
|
-
content: 'How do I add a new persona?',
|
|
9
|
-
createdAt: Date.now() - 5 * 60_000,
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
id: 'a-1',
|
|
13
|
-
role: 'assistant',
|
|
14
|
-
content:
|
|
15
|
-
'Set `config.assistant = { name, avatarUrl }`. You can also override per message via `message.sender`.\n\nMore info: [docs](https://example.com/docs/personas).',
|
|
16
|
-
createdAt: Date.now() - 4 * 60_000,
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
id: 'u-2',
|
|
20
|
-
role: 'user',
|
|
21
|
-
content: 'And errors? What if the turn fails?',
|
|
22
|
-
createdAt: Date.now() - 3 * 60_000,
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
id: 'a-err',
|
|
26
|
-
role: 'assistant',
|
|
27
|
-
content: 'Network blew up — try again in a moment.',
|
|
28
|
-
isError: true,
|
|
29
|
-
createdAt: Date.now() - 2 * 60_000,
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
id: 'a-streaming',
|
|
33
|
-
role: 'assistant',
|
|
34
|
-
content: 'Live reply tokens arrive here',
|
|
35
|
-
isStreaming: true,
|
|
36
|
-
createdAt: Date.now() - 60_000,
|
|
37
|
-
toolActivity: 'Searching knowledge base…',
|
|
38
|
-
},
|
|
39
|
-
];
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ChatAssistantContext, ChatUserContext } from '../../types';
|
|
2
|
-
|
|
3
|
-
export const USER_ANNA: ChatUserContext = {
|
|
4
|
-
name: 'Anna',
|
|
5
|
-
email: 'anna@example.com',
|
|
6
|
-
avatarUrl: 'https://i.pravatar.cc/64?img=5',
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const ASSISTANT_AURA: ChatAssistantContext = {
|
|
10
|
-
name: 'Aura',
|
|
11
|
-
avatarUrl: 'https://i.pravatar.cc/64?img=11',
|
|
12
|
-
model: 'gpt-4o',
|
|
13
|
-
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type { ChatMessage, ChatToolCall } from '../../types';
|
|
2
|
-
|
|
3
|
-
const now = Date.now();
|
|
4
|
-
|
|
5
|
-
/** Two-turn transcript exercising markdown + plain reply. Used in Basic stories. */
|
|
6
|
-
export const SEED_BASIC: ChatMessage[] = [
|
|
7
|
-
{
|
|
8
|
-
id: 'seed-u-1',
|
|
9
|
-
role: 'user',
|
|
10
|
-
content: 'Give me a markdown sample with a list and a code snippet.',
|
|
11
|
-
createdAt: now - 4 * 60_000,
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
id: 'seed-a-1',
|
|
15
|
-
role: 'assistant',
|
|
16
|
-
content:
|
|
17
|
-
'**Sure!** Here is a list:\n\n- alpha\n- beta\n- gamma\n\nAnd a snippet:\n\n```ts\nconst answer = 42;\n```',
|
|
18
|
-
createdAt: now - 3 * 60_000,
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
id: 'seed-u-2',
|
|
22
|
-
role: 'user',
|
|
23
|
-
content: 'How does streaming work?',
|
|
24
|
-
createdAt: now - 2 * 60_000,
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
id: 'seed-a-2',
|
|
28
|
-
role: 'assistant',
|
|
29
|
-
content:
|
|
30
|
-
'Each token arrives separately over SSE. The UI sticks to the bottom while the stream is in flight and shows a streaming indicator until `message_end` fires.',
|
|
31
|
-
createdAt: now - 60_000,
|
|
32
|
-
},
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
/** A completed tool-call so the panel is visible without sending anything. */
|
|
36
|
-
const SEED_TOOL_CALL: ChatToolCall = {
|
|
37
|
-
id: 'tc-seed-1',
|
|
38
|
-
name: 'search_docs',
|
|
39
|
-
input: { query: 'streaming protocol' },
|
|
40
|
-
output: { hits: 3, top: 'streaming.md' },
|
|
41
|
-
status: 'success',
|
|
42
|
-
startedAt: now - 90_000,
|
|
43
|
-
endedAt: now - 89_000,
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const SEED_TOOL_CALLS: ChatMessage[] = [
|
|
47
|
-
{
|
|
48
|
-
id: 'seed-u-tool',
|
|
49
|
-
role: 'user',
|
|
50
|
-
content: 'Find docs about streaming.',
|
|
51
|
-
createdAt: now - 2 * 60_000,
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
id: 'seed-a-tool',
|
|
55
|
-
role: 'assistant',
|
|
56
|
-
content: 'Let me check the docs for you.\n\nFound 3 relevant chunks. Here is a summary…',
|
|
57
|
-
createdAt: now - 60_000,
|
|
58
|
-
toolCalls: [SEED_TOOL_CALL],
|
|
59
|
-
},
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
/** Tool-call with a richer JSON payload — drives the JsonTree dispatcher story. */
|
|
63
|
-
const SEED_JSON_TOOL_CALL: ChatToolCall = {
|
|
64
|
-
id: 'tc-seed-json',
|
|
65
|
-
name: 'fetch_user',
|
|
66
|
-
input: { id: 'usr_42', fields: ['email', 'roles', 'metadata'] },
|
|
67
|
-
output: {
|
|
68
|
-
id: 'usr_42',
|
|
69
|
-
email: 'mark@example.com',
|
|
70
|
-
roles: ['admin', 'editor'],
|
|
71
|
-
metadata: { plan: 'pro', seats: 5, trial: false },
|
|
72
|
-
},
|
|
73
|
-
status: 'success',
|
|
74
|
-
startedAt: now - 90_000,
|
|
75
|
-
endedAt: now - 89_000,
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export const SEED_JSON_PAYLOAD: ChatMessage[] = [
|
|
79
|
-
{
|
|
80
|
-
id: 'seed-u-json',
|
|
81
|
-
role: 'user',
|
|
82
|
-
content: 'Fetch user 42.',
|
|
83
|
-
createdAt: now - 2 * 60_000,
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
id: 'seed-a-json',
|
|
87
|
-
role: 'assistant',
|
|
88
|
-
content: 'Open the tool panel to inspect the payload.',
|
|
89
|
-
createdAt: now - 60_000,
|
|
90
|
-
toolCalls: [SEED_JSON_TOOL_CALL],
|
|
91
|
-
},
|
|
92
|
-
];
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { createMockTransport } from '../../core/transport/mock';
|
|
2
|
-
import type { ChatMessage, ChatStreamEvent } from '../../types';
|
|
3
|
-
|
|
4
|
-
/** Scripted-replies transport. Pass `seed` to pre-populate the bubble area. */
|
|
5
|
-
export function makeBasicTransport(seed: ChatMessage[] = []) {
|
|
6
|
-
return createMockTransport({
|
|
7
|
-
initialMessages: seed,
|
|
8
|
-
replies: [
|
|
9
|
-
'Hello! I am a mock assistant. Ask me anything — I will reply with scripted text.',
|
|
10
|
-
'**Sure!** Here is a list:\n\n- alpha\n- beta\n- gamma\n\nAnd a snippet:\n\n```ts\nconst answer = 42;\n```',
|
|
11
|
-
'Streaming chunked text works too. Each token arrives separately and the UI sticks to the bottom while the stream is in flight.',
|
|
12
|
-
],
|
|
13
|
-
latencyMs: 35,
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Transport with an inline tool_call + result on send. Seedable. */
|
|
18
|
-
export function makeToolCallsTransport(seed: ChatMessage[] = []) {
|
|
19
|
-
const toolTurn: ChatStreamEvent[] = [
|
|
20
|
-
{ type: 'chunk', delta: 'Let me check the docs for you.\n\n' },
|
|
21
|
-
{
|
|
22
|
-
type: 'tool_call_start',
|
|
23
|
-
toolId: 'search-live',
|
|
24
|
-
name: 'search_docs',
|
|
25
|
-
input: { query: 'streaming protocol' },
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
type: 'tool_call_end',
|
|
29
|
-
toolId: 'search-live',
|
|
30
|
-
status: 'success',
|
|
31
|
-
output: { hits: 3, top: 'streaming.md' },
|
|
32
|
-
},
|
|
33
|
-
{ type: 'chunk', delta: 'Found 3 relevant chunks. Here is a summary…' },
|
|
34
|
-
];
|
|
35
|
-
return createMockTransport({ initialMessages: seed, replies: [toolTurn], latencyMs: 25 });
|
|
36
|
-
}
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import { defineStory, useSelect, useBoolean } from '@djangocfg/playground';
|
|
2
|
-
import { Editor, DiffEditor } from './components';
|
|
3
|
-
|
|
4
|
-
export default defineStory({
|
|
5
|
-
title: 'Tools/Code Editor',
|
|
6
|
-
component: Editor,
|
|
7
|
-
description: 'Monaco-based code editor with syntax highlighting, diff view, and full IDE features.',
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const SAMPLE_CODE = {
|
|
11
|
-
typescript: `import { useState, useCallback, useMemo } from 'react';
|
|
12
|
-
|
|
13
|
-
interface User {
|
|
14
|
-
id: string;
|
|
15
|
-
name: string;
|
|
16
|
-
email: string;
|
|
17
|
-
role: 'admin' | 'user' | 'viewer';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function useUsers() {
|
|
21
|
-
const [users, setUsers] = useState<User[]>([]);
|
|
22
|
-
|
|
23
|
-
const addUser = useCallback((user: Omit<User, 'id'>) => {
|
|
24
|
-
setUsers(prev => [...prev, { ...user, id: crypto.randomUUID() }]);
|
|
25
|
-
}, []);
|
|
26
|
-
|
|
27
|
-
const admins = useMemo(
|
|
28
|
-
() => users.filter(u => u.role === 'admin'),
|
|
29
|
-
[users],
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
return { users, admins, addUser };
|
|
33
|
-
}`,
|
|
34
|
-
|
|
35
|
-
python: `from __future__ import annotations
|
|
36
|
-
|
|
37
|
-
from dataclasses import dataclass
|
|
38
|
-
from datetime import datetime
|
|
39
|
-
from typing import AsyncIterator
|
|
40
|
-
|
|
41
|
-
import httpx
|
|
42
|
-
from pydantic import BaseModel, Field
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
class User(BaseModel):
|
|
46
|
-
id: str
|
|
47
|
-
name: str
|
|
48
|
-
email: str
|
|
49
|
-
role: str = "user"
|
|
50
|
-
created_at: datetime = Field(default_factory=datetime.utcnow)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
@dataclass
|
|
54
|
-
class UserService:
|
|
55
|
-
base_url: str
|
|
56
|
-
client: httpx.AsyncClient | None = None
|
|
57
|
-
|
|
58
|
-
async def list_users(self, page: int = 1) -> list[User]:
|
|
59
|
-
async with httpx.AsyncClient(base_url=self.base_url) as client:
|
|
60
|
-
response = await client.get("/users", params={"page": page})
|
|
61
|
-
response.raise_for_status()
|
|
62
|
-
return [User(**u) for u in response.json()["data"]]`,
|
|
63
|
-
|
|
64
|
-
json: `{
|
|
65
|
-
"name": "@djangocfg/ui-tools",
|
|
66
|
-
"version": "2.1.0",
|
|
67
|
-
"description": "Heavy React tools with lazy loading",
|
|
68
|
-
"dependencies": {
|
|
69
|
-
"monaco-editor": "^0.55.1",
|
|
70
|
-
"react": "^19.1.0"
|
|
71
|
-
},
|
|
72
|
-
"exports": {
|
|
73
|
-
".": "./src/index.ts",
|
|
74
|
-
"./code-editor": "./src/tools/CodeEditor/index.ts"
|
|
75
|
-
}
|
|
76
|
-
}`,
|
|
77
|
-
|
|
78
|
-
css: `/* Design tokens */
|
|
79
|
-
:root {
|
|
80
|
-
--radius: 0.5rem;
|
|
81
|
-
--shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
.editor-container {
|
|
85
|
-
position: relative;
|
|
86
|
-
border-radius: var(--radius);
|
|
87
|
-
border: 1px solid hsl(var(--border));
|
|
88
|
-
overflow: hidden;
|
|
89
|
-
|
|
90
|
-
&:focus-within {
|
|
91
|
-
outline: 2px solid hsl(var(--ring));
|
|
92
|
-
outline-offset: 2px;
|
|
93
|
-
}
|
|
94
|
-
}`,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const DIFF_ORIGINAL = `function greet(name: string) {
|
|
98
|
-
console.log("Hello, " + name);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
greet("World");`;
|
|
102
|
-
|
|
103
|
-
const DIFF_MODIFIED = `function greet(name: string, greeting = "Hello") {
|
|
104
|
-
console.log(\`\${greeting}, \${name}!\`);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function farewell(name: string) {
|
|
108
|
-
console.log(\`Goodbye, \${name}!\`);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
greet("World");
|
|
112
|
-
farewell("World");`;
|
|
113
|
-
|
|
114
|
-
export const Interactive = () => {
|
|
115
|
-
const [language] = useSelect('language', {
|
|
116
|
-
options: ['typescript', 'python', 'json', 'css'] as const,
|
|
117
|
-
defaultValue: 'typescript',
|
|
118
|
-
label: 'Language',
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
const [readOnly] = useBoolean('readOnly', {
|
|
122
|
-
defaultValue: false,
|
|
123
|
-
label: 'Read Only',
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
const [minimap] = useBoolean('minimap', {
|
|
127
|
-
defaultValue: false,
|
|
128
|
-
label: 'Minimap',
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const [autoHeight] = useBoolean('autoHeight', {
|
|
132
|
-
defaultValue: false,
|
|
133
|
-
label: 'Auto Height',
|
|
134
|
-
description: 'Resize editor to fit content',
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
return autoHeight ? (
|
|
138
|
-
<Editor
|
|
139
|
-
value={SAMPLE_CODE[language]}
|
|
140
|
-
language={language}
|
|
141
|
-
autoHeight
|
|
142
|
-
minHeight={100}
|
|
143
|
-
maxHeight={500}
|
|
144
|
-
options={{ readOnly, minimap, fontSize: 14 }}
|
|
145
|
-
/>
|
|
146
|
-
) : (
|
|
147
|
-
<div style={{ height: 400 }}>
|
|
148
|
-
<Editor
|
|
149
|
-
value={SAMPLE_CODE[language]}
|
|
150
|
-
language={language}
|
|
151
|
-
options={{ readOnly, minimap, fontSize: 14 }}
|
|
152
|
-
/>
|
|
153
|
-
</div>
|
|
154
|
-
);
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export const TypeScript = () => (
|
|
158
|
-
<div style={{ height: 350 }}>
|
|
159
|
-
<Editor value={SAMPLE_CODE.typescript} language="typescript" />
|
|
160
|
-
</div>
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
export const Python = () => (
|
|
164
|
-
<div style={{ height: 350 }}>
|
|
165
|
-
<Editor value={SAMPLE_CODE.python} language="python" />
|
|
166
|
-
</div>
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
export const ReadOnly = () => (
|
|
170
|
-
<div style={{ height: 300 }}>
|
|
171
|
-
<Editor
|
|
172
|
-
value={SAMPLE_CODE.json}
|
|
173
|
-
language="json"
|
|
174
|
-
options={{ readOnly: true, lineNumbers: 'on' }}
|
|
175
|
-
/>
|
|
176
|
-
</div>
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
export const AutoHeight = () => (
|
|
180
|
-
<div className="flex flex-col gap-4 max-w-3xl">
|
|
181
|
-
<p className="text-sm text-muted-foreground">
|
|
182
|
-
Editor grows with content (min 100px, max 400px). Try typing new lines.
|
|
183
|
-
</p>
|
|
184
|
-
<Editor
|
|
185
|
-
value={`const x = 1;\nconst y = 2;\nconst z = x + y;`}
|
|
186
|
-
language="typescript"
|
|
187
|
-
autoHeight
|
|
188
|
-
minHeight={100}
|
|
189
|
-
maxHeight={400}
|
|
190
|
-
/>
|
|
191
|
-
</div>
|
|
192
|
-
);
|
|
193
|
-
|
|
194
|
-
export const DiffView = () => (
|
|
195
|
-
<div style={{ height: 400 }}>
|
|
196
|
-
<DiffEditor
|
|
197
|
-
original={DIFF_ORIGINAL}
|
|
198
|
-
modified={DIFF_MODIFIED}
|
|
199
|
-
language="typescript"
|
|
200
|
-
/>
|
|
201
|
-
</div>
|
|
202
|
-
);
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
import { defineStory, useBoolean, useSelect } from '@djangocfg/playground';
|
|
3
|
-
import {
|
|
4
|
-
Dialog,
|
|
5
|
-
DialogContent,
|
|
6
|
-
DialogDescription,
|
|
7
|
-
DialogHeader,
|
|
8
|
-
DialogTitle,
|
|
9
|
-
DialogTrigger,
|
|
10
|
-
} from '@djangocfg/ui-core/components';
|
|
11
|
-
import { CronScheduler } from './index';
|
|
12
|
-
|
|
13
|
-
export default defineStory({
|
|
14
|
-
title: 'Tools/Cron Scheduler',
|
|
15
|
-
component: CronScheduler,
|
|
16
|
-
description: 'Compact cron expression builder with Apple HIG-style UI.',
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export const Interactive = () => {
|
|
20
|
-
const [cron, setCron] = useState('0 9 * * 1-5');
|
|
21
|
-
|
|
22
|
-
const [defaultType] = useSelect('defaultType', {
|
|
23
|
-
options: ['daily', 'weekly', 'monthly', 'custom'] as const,
|
|
24
|
-
defaultValue: 'weekly',
|
|
25
|
-
label: 'Default Type',
|
|
26
|
-
description: 'Initial schedule type',
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const [showPreview] = useBoolean('showPreview', {
|
|
30
|
-
defaultValue: true,
|
|
31
|
-
label: 'Show Preview',
|
|
32
|
-
description: 'Show human-readable preview',
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const [showCronExpression] = useBoolean('showCronExpression', {
|
|
36
|
-
defaultValue: true,
|
|
37
|
-
label: 'Show Cron Expression',
|
|
38
|
-
description: 'Show raw cron expression in preview',
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const [allowCopy] = useBoolean('allowCopy', {
|
|
42
|
-
defaultValue: true,
|
|
43
|
-
label: 'Allow Copy',
|
|
44
|
-
description: 'Enable copy to clipboard',
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const [timeFormat] = useSelect('timeFormat', {
|
|
48
|
-
options: ['24h', '12h'] as const,
|
|
49
|
-
defaultValue: '24h',
|
|
50
|
-
label: 'Time Format',
|
|
51
|
-
description: 'Time display format',
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const [disabled] = useBoolean('disabled', {
|
|
55
|
-
defaultValue: false,
|
|
56
|
-
label: 'Disabled',
|
|
57
|
-
description: 'Disable all interactions',
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<div className="w-[400px]">
|
|
62
|
-
<CronScheduler
|
|
63
|
-
value={cron}
|
|
64
|
-
onChange={setCron}
|
|
65
|
-
defaultType={defaultType}
|
|
66
|
-
showPreview={showPreview}
|
|
67
|
-
showCronExpression={showCronExpression}
|
|
68
|
-
allowCopy={allowCopy}
|
|
69
|
-
timeFormat={timeFormat}
|
|
70
|
-
disabled={disabled}
|
|
71
|
-
/>
|
|
72
|
-
</div>
|
|
73
|
-
);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export const Daily = () => {
|
|
77
|
-
const [cron, setCron] = useState('0 9 * * *');
|
|
78
|
-
|
|
79
|
-
return (
|
|
80
|
-
<div className="w-[400px]">
|
|
81
|
-
<CronScheduler
|
|
82
|
-
value={cron}
|
|
83
|
-
onChange={setCron}
|
|
84
|
-
defaultType="daily"
|
|
85
|
-
showPreview
|
|
86
|
-
/>
|
|
87
|
-
</div>
|
|
88
|
-
);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export const Weekly = () => {
|
|
92
|
-
const [cron, setCron] = useState('30 14 * * 1,3,5');
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
<div className="w-[400px]">
|
|
96
|
-
<CronScheduler
|
|
97
|
-
value={cron}
|
|
98
|
-
onChange={setCron}
|
|
99
|
-
defaultType="weekly"
|
|
100
|
-
showPreview
|
|
101
|
-
/>
|
|
102
|
-
</div>
|
|
103
|
-
);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export const Monthly = () => {
|
|
107
|
-
const [cron, setCron] = useState('0 9 1,15 * *');
|
|
108
|
-
|
|
109
|
-
return (
|
|
110
|
-
<div className="w-[400px]">
|
|
111
|
-
<CronScheduler
|
|
112
|
-
value={cron}
|
|
113
|
-
onChange={setCron}
|
|
114
|
-
defaultType="monthly"
|
|
115
|
-
showPreview
|
|
116
|
-
/>
|
|
117
|
-
</div>
|
|
118
|
-
);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export const Custom = () => {
|
|
122
|
-
const [cron, setCron] = useState('*/15 9-17 * * 1-5');
|
|
123
|
-
|
|
124
|
-
return (
|
|
125
|
-
<div className="w-[400px]">
|
|
126
|
-
<CronScheduler
|
|
127
|
-
value={cron}
|
|
128
|
-
onChange={setCron}
|
|
129
|
-
defaultType="custom"
|
|
130
|
-
showPreview
|
|
131
|
-
showCronExpression
|
|
132
|
-
/>
|
|
133
|
-
</div>
|
|
134
|
-
);
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export const WithCronExpression = () => {
|
|
138
|
-
const [cron, setCron] = useState('0 9 * * 1-5');
|
|
139
|
-
|
|
140
|
-
return (
|
|
141
|
-
<div className="w-[400px]">
|
|
142
|
-
<CronScheduler
|
|
143
|
-
value={cron}
|
|
144
|
-
onChange={setCron}
|
|
145
|
-
showPreview
|
|
146
|
-
showCronExpression
|
|
147
|
-
allowCopy
|
|
148
|
-
/>
|
|
149
|
-
</div>
|
|
150
|
-
);
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
export const TwelveHourFormat = () => {
|
|
154
|
-
const [cron, setCron] = useState('0 14 * * *');
|
|
155
|
-
|
|
156
|
-
return (
|
|
157
|
-
<div className="w-[400px]">
|
|
158
|
-
<CronScheduler
|
|
159
|
-
value={cron}
|
|
160
|
-
onChange={setCron}
|
|
161
|
-
showPreview
|
|
162
|
-
timeFormat="12h"
|
|
163
|
-
/>
|
|
164
|
-
</div>
|
|
165
|
-
);
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export const Disabled = () => (
|
|
169
|
-
<div className="w-[400px]">
|
|
170
|
-
<CronScheduler
|
|
171
|
-
value="0 9 * * 1-5"
|
|
172
|
-
showPreview
|
|
173
|
-
disabled
|
|
174
|
-
/>
|
|
175
|
-
</div>
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
export const Compact = () => {
|
|
179
|
-
const [cron, setCron] = useState('0 9 * * 1-5');
|
|
180
|
-
|
|
181
|
-
return (
|
|
182
|
-
<div className="w-[400px]">
|
|
183
|
-
<CronScheduler
|
|
184
|
-
value={cron}
|
|
185
|
-
onChange={setCron}
|
|
186
|
-
defaultType="weekly"
|
|
187
|
-
showPreview={false}
|
|
188
|
-
/>
|
|
189
|
-
</div>
|
|
190
|
-
);
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
export const Controlled = () => {
|
|
194
|
-
const [cron, setCron] = useState('0 9 * * *');
|
|
195
|
-
|
|
196
|
-
const presets = [
|
|
197
|
-
{ label: 'Every day at 9am', value: '0 9 * * *' },
|
|
198
|
-
{ label: 'Weekdays at 6pm', value: '0 18 * * 1-5' },
|
|
199
|
-
{ label: 'Every Monday', value: '0 0 * * 1' },
|
|
200
|
-
{ label: '1st of month', value: '0 0 1 * *' },
|
|
201
|
-
];
|
|
202
|
-
|
|
203
|
-
return (
|
|
204
|
-
<div className="w-[400px] space-y-4">
|
|
205
|
-
<div className="flex flex-wrap gap-2">
|
|
206
|
-
{presets.map(({ label, value }) => (
|
|
207
|
-
<button
|
|
208
|
-
key={value}
|
|
209
|
-
onClick={() => setCron(value)}
|
|
210
|
-
className={`px-2 py-1 text-xs rounded-md transition-colors ${
|
|
211
|
-
cron === value
|
|
212
|
-
? 'bg-primary text-primary-foreground'
|
|
213
|
-
: 'bg-muted hover:bg-muted/80'
|
|
214
|
-
}`}
|
|
215
|
-
>
|
|
216
|
-
{label}
|
|
217
|
-
</button>
|
|
218
|
-
))}
|
|
219
|
-
</div>
|
|
220
|
-
<CronScheduler
|
|
221
|
-
value={cron}
|
|
222
|
-
onChange={setCron}
|
|
223
|
-
showPreview
|
|
224
|
-
allowCopy
|
|
225
|
-
/>
|
|
226
|
-
</div>
|
|
227
|
-
);
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
export const InDialog = () => {
|
|
231
|
-
const [cron, setCron] = useState('0 9 * * 1-5');
|
|
232
|
-
const [open, setOpen] = useState(false);
|
|
233
|
-
|
|
234
|
-
return (
|
|
235
|
-
<div className="p-4">
|
|
236
|
-
<Dialog open={open} onOpenChange={setOpen}>
|
|
237
|
-
<DialogTrigger asChild>
|
|
238
|
-
<button className="px-4 py-2 bg-primary text-primary-foreground rounded-md">
|
|
239
|
-
Open Schedule Dialog
|
|
240
|
-
</button>
|
|
241
|
-
</DialogTrigger>
|
|
242
|
-
<DialogContent className="max-w-2xl">
|
|
243
|
-
<DialogHeader>
|
|
244
|
-
<DialogTitle>Create Schedule</DialogTitle>
|
|
245
|
-
<DialogDescription>
|
|
246
|
-
Configure a cron schedule for automated execution
|
|
247
|
-
</DialogDescription>
|
|
248
|
-
</DialogHeader>
|
|
249
|
-
<div className="py-4">
|
|
250
|
-
<CronScheduler
|
|
251
|
-
value={cron}
|
|
252
|
-
onChange={setCron}
|
|
253
|
-
showPreview
|
|
254
|
-
showCronExpression
|
|
255
|
-
allowCopy
|
|
256
|
-
/>
|
|
257
|
-
</div>
|
|
258
|
-
</DialogContent>
|
|
259
|
-
</Dialog>
|
|
260
|
-
<div className="mt-4 text-sm text-muted-foreground">
|
|
261
|
-
Current cron: <code className="bg-muted px-1 rounded">{cron}</code>
|
|
262
|
-
</div>
|
|
263
|
-
</div>
|
|
264
|
-
);
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
export const InDialogMonthly = () => {
|
|
268
|
-
const [cron, setCron] = useState('0 9 1,15 * *');
|
|
269
|
-
const [open, setOpen] = useState(false);
|
|
270
|
-
|
|
271
|
-
return (
|
|
272
|
-
<div className="p-4">
|
|
273
|
-
<Dialog open={open} onOpenChange={setOpen}>
|
|
274
|
-
<DialogTrigger asChild>
|
|
275
|
-
<button className="px-4 py-2 bg-primary text-primary-foreground rounded-md">
|
|
276
|
-
Open Monthly Schedule
|
|
277
|
-
</button>
|
|
278
|
-
</DialogTrigger>
|
|
279
|
-
<DialogContent className="max-w-2xl">
|
|
280
|
-
<DialogHeader>
|
|
281
|
-
<DialogTitle>Monthly Schedule</DialogTitle>
|
|
282
|
-
<DialogDescription>
|
|
283
|
-
Test monthly calendar grid inside dialog
|
|
284
|
-
</DialogDescription>
|
|
285
|
-
</DialogHeader>
|
|
286
|
-
<div className="py-4">
|
|
287
|
-
<CronScheduler
|
|
288
|
-
value={cron}
|
|
289
|
-
onChange={setCron}
|
|
290
|
-
defaultType="monthly"
|
|
291
|
-
showPreview
|
|
292
|
-
showCronExpression
|
|
293
|
-
allowCopy
|
|
294
|
-
/>
|
|
295
|
-
</div>
|
|
296
|
-
</DialogContent>
|
|
297
|
-
</Dialog>
|
|
298
|
-
</div>
|
|
299
|
-
);
|
|
300
|
-
};
|