Skip to content

Commit 8f4a79c

Browse files
authored
Re-enable lineNumbers in chatbot-note.tsx (commontoolsinc#1798)
Also add mentions to `note.tsx`
1 parent 33166e4 commit 8f4a79c

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

packages/patterns/chatbot-note.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,6 @@ const handleCharmLinkClick = handler<
5353
return navigateTo(detail.charm);
5454
});
5555

56-
export const Note = recipe<NoteInput>(
57-
"Note",
58-
({ content, allCharms }) => {
59-
return {
60-
[NAME]: "Note",
61-
[UI]: (
62-
<ct-code-editor
63-
$value={content}
64-
$mentionable={allCharms}
65-
onbacklink-click={handleCharmLinkClick({})}
66-
language="text/markdown"
67-
style="min-height: 400px;"
68-
/>
69-
),
70-
content,
71-
};
72-
},
73-
);
74-
7556
const handleCharmLinkClicked = handler(
7657
(_: any, { charm }: { charm: Cell<MentionableCharm> }) => {
7758
return navigateTo(charm);
@@ -222,6 +203,7 @@ export default recipe<LLMTestInput, LLMTestResult>(
222203
language="text/markdown"
223204
wordWrap
224205
tabIndent
206+
lineNumbers
225207
/>
226208
<details>
227209
<summary>Mentioned Charms</summary>

packages/patterns/default-app.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,12 @@ const spawnChatbotNote = handler<
116116

117117
const spawnNote = handler<
118118
Record<string, never>,
119-
Record<string, never>
119+
{ allCharms: Cell<MentionableCharm[]> }
120120
>((_, state) => {
121121
return navigateTo(Note({
122122
title: "New Note",
123123
content: "",
124+
allCharms: state.allCharms,
124125
}));
125126
});
126127

@@ -161,7 +162,11 @@ export default recipe<CharmsListInput, CharmsListOutput>(
161162
🤖 Chatbot Note
162163
</ct-button>
163164
<ct-button
164-
onClick={spawnNote({})}
165+
onClick={spawnNote({ // slight disagreement between Charm types but they are compatible
166+
allCharms: allCharms as unknown as OpaqueRef<
167+
MentionableCharm[]
168+
>,
169+
})}
165170
>
166171
📄 Note
167172
</ct-button>

packages/patterns/note.tsx

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
/// <cts-enable />
22
import {
33
Cell,
4+
cell,
45
Default,
56
h,
67
handler,
78
NAME,
9+
navigateTo,
810
recipe,
911
toSchema,
1012
UI,
1113
} from "commontools";
1214

15+
export type MentionableCharm = {
16+
[NAME]: string;
17+
content?: string;
18+
mentioned?: MentionableCharm[];
19+
};
20+
1321
type Input = {
1422
title: Default<string, "Untitled Note">;
1523
content: Default<string, "">;
24+
allCharms: Cell<MentionableCharm[]>;
1625
};
1726

18-
type Output = Input;
27+
type Output = {
28+
mentioned: Default<Array<MentionableCharm>, []>;
29+
content: Default<string, "">;
30+
};
1931

2032
const updateTitle = handler<
2133
{ detail: { value: string } },
@@ -35,9 +47,22 @@ const updateContent = handler<
3547
},
3648
);
3749

50+
const handleCharmLinkClick = handler<
51+
{
52+
detail: {
53+
charm: Cell<MentionableCharm>;
54+
};
55+
},
56+
Record<string, never>
57+
>(({ detail }, _) => {
58+
return navigateTo(detail.charm);
59+
});
60+
3861
export default recipe<Input, Output>(
3962
"Note",
40-
({ title, content }) => {
63+
({ title, content, allCharms }) => {
64+
const mentioned = cell<MentionableCharm[]>([]);
65+
4166
return {
4267
[NAME]: title,
4368
[UI]: (
@@ -48,15 +73,22 @@ export default recipe<Input, Output>(
4873
placeholder="Enter title..."
4974
/>
5075
</div>
76+
5177
<ct-code-editor
5278
$value={content}
79+
$mentionable={allCharms}
80+
$mentioned={mentioned}
81+
onbacklink-click={handleCharmLinkClick({})}
5382
language="text/markdown"
54-
style="min-height: 400px;"
83+
wordWrap
84+
tabIndent
85+
lineNumbers
5586
/>
5687
</ct-screen>
5788
),
5889
title,
5990
content,
91+
mentioned,
6092
};
6193
},
6294
);

0 commit comments

Comments
 (0)