@dust-tt/sparkle 0.2.448 → 0.2.449-rc-samuel
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/cjs/index.js +1 -1
- package/dist/esm/components/AppCommandPalette.d.ts +11 -0
- package/dist/esm/components/AppCommandPalette.d.ts.map +1 -0
- package/dist/esm/components/AppCommandPalette.js +44 -0
- package/dist/esm/components/AppCommandPalette.js.map +1 -0
- package/dist/esm/components/CommandPalette.d.ts +3 -0
- package/dist/esm/components/CommandPalette.d.ts.map +1 -0
- package/dist/esm/components/CommandPalette.js +61 -0
- package/dist/esm/components/CommandPalette.js.map +1 -0
- package/dist/esm/components/Input.d.ts +1 -0
- package/dist/esm/components/Input.d.ts.map +1 -1
- package/dist/esm/components/Input.js +2 -2
- package/dist/esm/components/Input.js.map +1 -1
- package/dist/esm/components/Notification.d.ts +2 -2
- package/dist/esm/components/Notification.d.ts.map +1 -1
- package/dist/esm/components/Notification.js +25 -3
- package/dist/esm/components/Notification.js.map +1 -1
- package/dist/esm/components/Resizable.d.ts +1 -1
- package/dist/esm/components/SamsCommandPalette.d.ts +81 -0
- package/dist/esm/components/SamsCommandPalette.d.ts.map +1 -0
- package/dist/esm/components/SamsCommandPalette.js +56 -0
- package/dist/esm/components/SamsCommandPalette.js.map +1 -0
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/components/markdown/List.d.ts.map +1 -1
- package/dist/esm/components/markdown/List.js +3 -7
- package/dist/esm/components/markdown/List.js.map +1 -1
- package/dist/esm/contexts/CommandPaletteContext.d.ts +28 -0
- package/dist/esm/contexts/CommandPaletteContext.d.ts.map +1 -0
- package/dist/esm/contexts/CommandPaletteContext.js +83 -0
- package/dist/esm/contexts/CommandPaletteContext.js.map +1 -0
- package/dist/esm/hooks/useCommandPalette.d.ts +27 -0
- package/dist/esm/hooks/useCommandPalette.d.ts.map +1 -0
- package/dist/esm/hooks/useCommandPalette.js +62 -0
- package/dist/esm/hooks/useCommandPalette.js.map +1 -0
- package/dist/esm/stories/Notification.stories.js +8 -1
- package/dist/esm/stories/Notification.stories.js.map +1 -1
- package/dist/esm/stories/SamsCommandPalette.stories.d.ts +25 -0
- package/dist/esm/stories/SamsCommandPalette.stories.d.ts.map +1 -0
- package/dist/esm/stories/SamsCommandPalette.stories.js +100 -0
- package/dist/esm/stories/SamsCommandPalette.stories.js.map +1 -0
- package/dist/sparkle.css +136 -0
- package/package.json +2 -1
- package/src/components/AppCommandPalette.tsx +58 -0
- package/src/components/CommandPalette.tsx +112 -0
- package/src/components/Input.tsx +8 -1
- package/src/components/Notification.tsx +38 -19
- package/src/components/SamsCommandPalette.tsx +166 -0
- package/src/components/index.ts +1 -0
- package/src/components/markdown/List.tsx +3 -7
- package/src/contexts/CommandPaletteContext.tsx +135 -0
- package/src/hooks/useCommandPalette.tsx +87 -0
- package/src/stories/Notification.stories.tsx +10 -0
- package/src/stories/SamsCommandPalette.stories.tsx +133 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { Meta } from "@storybook/react";
|
|
2
|
+
import React, { useState } from "react";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
CodeBlock,
|
|
6
|
+
Icon,
|
|
7
|
+
Label,
|
|
8
|
+
RadioGroup,
|
|
9
|
+
RadioGroupItem,
|
|
10
|
+
} from "@sparkle/components";
|
|
11
|
+
import { SamsCommand } from "@sparkle/components/SamsCommandPalette";
|
|
12
|
+
import { useCommandPalette } from "@sparkle/hooks/useCommandPalette";
|
|
13
|
+
import { FolderIcon } from "@sparkle/icons";
|
|
14
|
+
|
|
15
|
+
import { AppCommandPalette } from "../components/AppCommandPalette";
|
|
16
|
+
import { Command } from "../contexts/CommandPaletteContext";
|
|
17
|
+
|
|
18
|
+
const meta = {
|
|
19
|
+
title: "Primitives/Sam's CommandPalette",
|
|
20
|
+
component: SamsCommand,
|
|
21
|
+
} satisfies Meta<typeof SamsCommand>;
|
|
22
|
+
|
|
23
|
+
export default meta;
|
|
24
|
+
|
|
25
|
+
export function SimpleExample() {
|
|
26
|
+
return (
|
|
27
|
+
<AppCommandPalette>
|
|
28
|
+
<Label>
|
|
29
|
+
Press <CodeBlock inline>⌘ K</CodeBlock> to open the command palette
|
|
30
|
+
</Label>
|
|
31
|
+
<SamsCommand />
|
|
32
|
+
</AppCommandPalette>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Example with entity-specific commands
|
|
37
|
+
export function EntitySpecificCommands() {
|
|
38
|
+
return (
|
|
39
|
+
<AppCommandPalette>
|
|
40
|
+
<EntitySelector />
|
|
41
|
+
</AppCommandPalette>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Predefined entity commands - moved outside component to avoid recreation
|
|
46
|
+
const entity1Commands: Command[] = [
|
|
47
|
+
{
|
|
48
|
+
id: "entity1.actionA",
|
|
49
|
+
label: "Action A",
|
|
50
|
+
category: "Entity 1",
|
|
51
|
+
entityType: "entity1",
|
|
52
|
+
action: () => {
|
|
53
|
+
window.alert("Executing Action A for Entity 1");
|
|
54
|
+
},
|
|
55
|
+
priority: 0,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: "entity1.actionB",
|
|
59
|
+
label: "Action B",
|
|
60
|
+
category: "Entity 1",
|
|
61
|
+
entityType: "entity1",
|
|
62
|
+
action: () => {
|
|
63
|
+
window.alert("Executing Action B for Entity 1");
|
|
64
|
+
},
|
|
65
|
+
priority: 1,
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
const entity2Commands: Command[] = [
|
|
70
|
+
{
|
|
71
|
+
id: "entity2.actionC.warning",
|
|
72
|
+
label: "Action C",
|
|
73
|
+
category: "Entity 2",
|
|
74
|
+
entityType: "entity2",
|
|
75
|
+
action: () => {
|
|
76
|
+
window.alert("Executing Action C for Entity 2");
|
|
77
|
+
},
|
|
78
|
+
priority: 0,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "entity2.actionD",
|
|
82
|
+
label: "Action D",
|
|
83
|
+
icon: <Icon visual={FolderIcon} />,
|
|
84
|
+
category: "Entity 2",
|
|
85
|
+
entityType: "entity2",
|
|
86
|
+
action: () => {
|
|
87
|
+
window.alert("Executing Action D for Entity 2");
|
|
88
|
+
},
|
|
89
|
+
priority: 1,
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
// Component to demonstrate entity selection and entity-specific commands
|
|
93
|
+
function EntitySelector() {
|
|
94
|
+
const { registerCommands, unregisterCommandsByEntityType } =
|
|
95
|
+
useCommandPalette();
|
|
96
|
+
const [currentEntity, setCurrentEntity] = useState<"entity1" | "entity2">();
|
|
97
|
+
|
|
98
|
+
// Default to entity 1 commands
|
|
99
|
+
|
|
100
|
+
function handleEntityChange(newEntity: "entity1" | "entity2") {
|
|
101
|
+
setCurrentEntity((previous) => {
|
|
102
|
+
if (previous) {
|
|
103
|
+
unregisterCommandsByEntityType(previous);
|
|
104
|
+
}
|
|
105
|
+
registerCommands(
|
|
106
|
+
newEntity === "entity1" ? entity1Commands : entity2Commands
|
|
107
|
+
);
|
|
108
|
+
return newEntity;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<div className="s-flex s-flex-col s-gap-4">
|
|
114
|
+
<div className="s-flex s-flex-col s-gap-2">
|
|
115
|
+
<Label>Current Entity</Label>
|
|
116
|
+
<div className="s-flex s-gap-4">
|
|
117
|
+
<RadioGroup value={currentEntity} onValueChange={handleEntityChange}>
|
|
118
|
+
<RadioGroupItem value="entity1" label="Entity 1" />
|
|
119
|
+
<RadioGroupItem value="entity2" label="Entity 2" />
|
|
120
|
+
</RadioGroup>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
<div className="s-flex s-flex-col s-gap-2">
|
|
125
|
+
<Label>Command Palette</Label>
|
|
126
|
+
<p className="s-text-sm s-text-muted-foreground">
|
|
127
|
+
Press <CodeBlock inline>⌘ K</CodeBlock> to open the command palette.
|
|
128
|
+
The commands change based on the selected entity.
|
|
129
|
+
</p>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
}
|