pocket-tutor 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +171 -2
- package/bin/pocket-tutor.js +57 -0
- package/config.example.json +12 -0
- package/docs/CLIP_RULES.md +38 -0
- package/package.json +74 -4
- package/scripts/build-ui.mjs +25 -0
- package/scripts/clip-judge.js +106 -0
- package/scripts/doctor.js +58 -0
- package/scripts/setup-visuals.js +27 -0
- package/scripts/visual_scene.py +279 -0
- package/src/astryx-themes.js +18 -0
- package/src/browser.js +38 -0
- package/src/config.js +84 -0
- package/src/graph.js +114 -0
- package/src/helper.ps1 +67 -0
- package/src/main.js +490 -0
- package/src/model.js +283 -0
- package/src/native.js +50 -0
- package/src/place.js +29 -0
- package/src/preload.js +17 -0
- package/src/privacy.js +40 -0
- package/src/project.js +252 -0
- package/src/search.js +111 -0
- package/src/themes/lens/lens.css +1165 -0
- package/src/themes/lens/lens.css.d.ts +9 -0
- package/src/themes/lens/lens.d.ts +14 -0
- package/src/themes/lens/lens.fonts.css +2 -0
- package/src/themes/lens/lens.js +627 -0
- package/src/themes/lens/lens.variants.d.ts +22 -0
- package/src/themes/lens/lensTheme.doc.mjs +10 -0
- package/src/themes/lens/lensTheme.ts +2 -0
- package/src/ui/app.jsx +268 -0
- package/src/ui/dist/assets/KaTeX_AMS-Regular-CYEKBG2K.woff +0 -0
- package/src/ui/dist/assets/KaTeX_AMS-Regular-JKX5W2C4.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_AMS-Regular-U6PRYMIZ.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Caligraphic-Bold-5QL5CMTE.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Caligraphic-Bold-WZ3QSGD3.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Caligraphic-Bold-ZTS3R3HK.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Caligraphic-Regular-3LKEU76G.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Caligraphic-Regular-A7XRTZ5Q.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Caligraphic-Regular-KX5MEWCF.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Fraktur-Bold-2QVFK6NQ.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Fraktur-Bold-T4SWXBMT.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Fraktur-Bold-WGHVTYOR.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Fraktur-Regular-2PEIFJSJ.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Fraktur-Regular-5U4OPH2X.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Fraktur-Regular-PQMHCIK6.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Main-Bold-2GA4IZIN.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Main-Bold-W5FBVCZM.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Main-Bold-YP5VVQRP.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Main-BoldItalic-4P4C7HJH.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Main-BoldItalic-N4V3DX7S.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Main-BoldItalic-ODMLBJJQ.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Main-Italic-I43T2HSR.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Main-Italic-RELBIK7M.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Main-Italic-SASNQFN2.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Main-Regular-ARRPAO67.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Main-Regular-P5I74A2A.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Main-Regular-W74P5G27.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Math-BoldItalic-6EBV3DK5.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Math-BoldItalic-K4WTGH3J.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Math-BoldItalic-VB447A4D.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Math-Italic-6KGCHLFN.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Math-Italic-KKK3USB2.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Math-Italic-SON4MRCA.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_SansSerif-Bold-RRNVJFFW.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_SansSerif-Bold-STQ6RXC7.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_SansSerif-Bold-X5M5EMOD.woff +0 -0
- package/src/ui/dist/assets/KaTeX_SansSerif-Italic-HMPFTM52.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_SansSerif-Italic-PSN4QKYX.woff +0 -0
- package/src/ui/dist/assets/KaTeX_SansSerif-Italic-WTBAZBGY.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_SansSerif-Regular-2TL3USAE.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_SansSerif-Regular-OQCII6EP.woff +0 -0
- package/src/ui/dist/assets/KaTeX_SansSerif-Regular-XIQ62X4E.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Script-Regular-72OLXYNA.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Script-Regular-A5IFOEBS.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Script-Regular-APUWIHLP.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Size1-Regular-4HRHTS65.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Size1-Regular-5LRUTBFT.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Size1-Regular-7K6AASVL.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Size2-Regular-222HN3GT.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Size2-Regular-K5ZHAIS6.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Size2-Regular-LELKET5D.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Size3-Regular-TLFPAHDE.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Size3-Regular-UFCO6WCA.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Size3-Regular-WQRQ47UD.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Size4-Regular-7PGNVPQK.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Size4-Regular-CDMV7U5C.woff2 +0 -0
- package/src/ui/dist/assets/KaTeX_Size4-Regular-PKMWZHNC.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Typewriter-Regular-3F5K6SQ6.ttf +0 -0
- package/src/ui/dist/assets/KaTeX_Typewriter-Regular-MJMFSK64.woff +0 -0
- package/src/ui/dist/assets/KaTeX_Typewriter-Regular-VBYJ4NRC.woff2 +0 -0
- package/src/ui/dist/assets/figtree-latin-400-normal-PORFSHKN.woff2 +0 -0
- package/src/ui/dist/assets/figtree-latin-500-normal-AHYR5JKA.woff2 +0 -0
- package/src/ui/dist/assets/figtree-latin-600-normal-5C6Z7QEI.woff2 +0 -0
- package/src/ui/dist/assets/figtree-latin-700-normal-M33EANAW.woff2 +0 -0
- package/src/ui/dist/assets/figtree-latin-ext-400-normal-CK4ZBFIX.woff2 +0 -0
- package/src/ui/dist/assets/figtree-latin-ext-500-normal-M4H6A6MQ.woff2 +0 -0
- package/src/ui/dist/assets/figtree-latin-ext-600-normal-KUZFNAIE.woff2 +0 -0
- package/src/ui/dist/assets/figtree-latin-ext-700-normal-U3DQVDYX.woff2 +0 -0
- package/src/ui/dist/popup.css +1 -0
- package/src/ui/dist/popup.js +546 -0
- package/src/ui/popup.html +13 -0
- package/src/ui/state.js +89 -0
- package/src/visual.js +229 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Written by `astryx experimental theme editor show lens` after every build of themes/lens/; do not edit it here. Change the theme with the editor.
|
|
2
|
+
|
|
3
|
+
/** @type {import('@astryxdesign/cli/authoring').ThemeDoc} */
|
|
4
|
+
export default {
|
|
5
|
+
type: 'theme',
|
|
6
|
+
name: "lens",
|
|
7
|
+
displayName: "lens",
|
|
8
|
+
description: "The lens theme, made with the theme editor (themes/lens/).",
|
|
9
|
+
maintained: false,
|
|
10
|
+
};
|
package/src/ui/app.jsx
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// Pocket Tutor's two views, built with Astryx components on the black "lens" theme (themes/lens).
|
|
2
|
+
// The box (default): the explanation only (and, for math, a ManimGL clip). Three buttons: explain in
|
|
3
|
+
// detail, minimize (to a small "0" at the same spot) and close. It sizes itself to its content, always
|
|
4
|
+
// wider than tall: the page measures it, main.js resizes the window (place.js fitBox).
|
|
5
|
+
// The detail window (?view=detail): a big landscape window with the full explanation on the left and,
|
|
6
|
+
// on the right, the clip, the code it found, related ideas and web pages to read more.
|
|
7
|
+
import '@astryxdesign/core/reset.css'
|
|
8
|
+
import '@astryxdesign/core/astryx.css'
|
|
9
|
+
import { useEffect, useLayoutEffect, useReducer, useRef, useState } from 'react'
|
|
10
|
+
import { createRoot } from 'react-dom/client'
|
|
11
|
+
import { Theme } from '@astryxdesign/core/theme'
|
|
12
|
+
import { VStack } from '@astryxdesign/core/VStack'
|
|
13
|
+
import { HStack } from '@astryxdesign/core/HStack'
|
|
14
|
+
import { Text } from '@astryxdesign/core/Text'
|
|
15
|
+
import { Link } from '@astryxdesign/core/Link'
|
|
16
|
+
import { Button } from '@astryxdesign/core/Button'
|
|
17
|
+
import { IconButton } from '@astryxdesign/core/IconButton'
|
|
18
|
+
import { Icon } from '@astryxdesign/core/Icon'
|
|
19
|
+
import { Spinner } from '@astryxdesign/core/Spinner'
|
|
20
|
+
import { Markdown } from '@astryxdesign/core/Markdown'
|
|
21
|
+
import { Code } from '@astryxdesign/core/Code'
|
|
22
|
+
import { CodeBlock } from '@astryxdesign/core/CodeBlock'
|
|
23
|
+
import { Collapsible } from '@astryxdesign/core/Collapsible'
|
|
24
|
+
import { Divider } from '@astryxdesign/core/Divider'
|
|
25
|
+
import { TextInput } from '@astryxdesign/core/TextInput'
|
|
26
|
+
import { themes, defaultThemeSlug, themeModes } from '../astryx-themes'
|
|
27
|
+
import { fresh, reduce, freshDetail, reduceDetail, codeRef, settleMarkdown } from './state.js'
|
|
28
|
+
// Math in the explanation ($L^2 d$, $$…$$) is typeset with KaTeX. Before, the box showed the raw dollar signs
|
|
29
|
+
// (2026-11-24 screenshot). KaTeX's own stylesheet and fonts are its typesetting, not app styling.
|
|
30
|
+
import katex from 'katex'
|
|
31
|
+
import 'katex/dist/katex.min.css'
|
|
32
|
+
|
|
33
|
+
// Astryx has no math component, and KaTeX hands back HTML, so this is the one raw element in the app.
|
|
34
|
+
// trust: false keeps \href, \url and \htmlClass out; a formula KaTeX can't read is shown as code instead.
|
|
35
|
+
function MathTex({ value, display }) {
|
|
36
|
+
let html = null
|
|
37
|
+
try { html = katex.renderToString(String(value), { displayMode: display === 'block', throwOnError: true, trust: false, strict: 'ignore', output: 'htmlAndMathml' }) } catch { /* shown as code below */ }
|
|
38
|
+
if (html == null) return <Code>{value}</Code>
|
|
39
|
+
return <span dangerouslySetInnerHTML={{ __html: html }} />
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const lens = window.lens
|
|
43
|
+
|
|
44
|
+
// the window is frameless: the top row and the dot drag it, buttons don't
|
|
45
|
+
const drag = { WebkitAppRegion: 'drag' }
|
|
46
|
+
const noDrag = { WebkitAppRegion: 'no-drag' }
|
|
47
|
+
|
|
48
|
+
function Answer({ st, text = st.answer, busy = st.busy }) {
|
|
49
|
+
const components = {
|
|
50
|
+
inlineCode: ({ children }) => {
|
|
51
|
+
const ref = codeRef(children, st.snippets)
|
|
52
|
+
if (!ref) return <Code>{children}</Code>
|
|
53
|
+
return <Link onClick={(e) => { e.preventDefault(); lens.openCode(ref.file, ref.line) }} tooltip="Open in VS Code"><Code color="inherit">{children}</Code></Link>
|
|
54
|
+
},
|
|
55
|
+
math: ({ value, display }) => <MathTex value={value} display={display} />,
|
|
56
|
+
}
|
|
57
|
+
return (
|
|
58
|
+
<Markdown isStreaming={busy} components={components} contentWidth="100%"
|
|
59
|
+
onLinkClick={(href, e) => { e.preventDefault(); lens.openUrl(href); return false }}>
|
|
60
|
+
{busy ? settleMarkdown(text) : text}
|
|
61
|
+
</Markdown>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// "I didn't understand": a follow-up question under the explanation. Enter sends it; an empty Enter asks for the
|
|
66
|
+
// same thing again, simpler. The answers stream in as questions and answers under the explanation.
|
|
67
|
+
function FollowUp({ st, view, disabled }) {
|
|
68
|
+
const first = view === 'box' && st.ready
|
|
69
|
+
const [q, setQ] = useState('')
|
|
70
|
+
const send = () => { if (disabled || st.asking || (first && !q.trim())) return; lens.ask(q, view); setQ('') }
|
|
71
|
+
return (
|
|
72
|
+
<HStack gap={1} vAlign="center" paddingInline={3} paddingBlock={1}>
|
|
73
|
+
<TextInput size="sm" label="Ask a follow-up" isLabelHidden width="100%" value={q} onChange={setQ} onEnter={send}
|
|
74
|
+
placeholder={first ? 'Ask anything. It uses the project you are in.' : "Didn't get it? Ask here (Enter alone = explain simpler)"} hasAutoFocus={first} isDisabled={disabled || st.asking} />
|
|
75
|
+
<IconButton size="sm" variant="ghost" label="Ask" icon={<Icon icon="chevronRight" />} isDisabled={disabled || st.asking} onClick={send} />
|
|
76
|
+
</HStack>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function Followups({ st }) {
|
|
81
|
+
return st.qa.map((x, i) => (
|
|
82
|
+
<VStack key={i} gap={1}>
|
|
83
|
+
<Text type="supporting" weight="semibold">{x.q || 'Explain it simpler'}</Text>
|
|
84
|
+
{x.a ? <Answer st={st} text={x.a} busy={st.asking && i === st.qa.length - 1} /> : <Spinner size="sm" />}
|
|
85
|
+
</VStack>
|
|
86
|
+
))
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function Box() {
|
|
90
|
+
const [st, dispatch] = useReducer(reduce, undefined, () => fresh())
|
|
91
|
+
const [mode, setMode] = useState('full')
|
|
92
|
+
const top = useRef(null)
|
|
93
|
+
const content = useRef(null)
|
|
94
|
+
const busy = useRef(false)
|
|
95
|
+
const remeasure = useRef(() => {})
|
|
96
|
+
const bottom = useRef(null)
|
|
97
|
+
busy.current = st.busy || st.asking
|
|
98
|
+
useEffect(() => { if (!st.busy && !st.asking) remeasure.current() }, [st.busy, st.asking])
|
|
99
|
+
|
|
100
|
+
useEffect(() => { lens.onState(dispatch); lens.onMode(setMode) }, [])
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
const onKey = (e) => { if (e.key === 'Escape') lens.close() }
|
|
103
|
+
// any plain web link opens in Chrome, never inside the box
|
|
104
|
+
const onClick = (e) => {
|
|
105
|
+
const a = e.target.closest && e.target.closest('a[href^="http"]')
|
|
106
|
+
if (a) { e.preventDefault(); lens.openUrl(a.href) }
|
|
107
|
+
}
|
|
108
|
+
document.addEventListener('keydown', onKey)
|
|
109
|
+
document.addEventListener('click', onClick, true)
|
|
110
|
+
return () => { document.removeEventListener('keydown', onKey); document.removeEventListener('click', onClick, true) }
|
|
111
|
+
}, [])
|
|
112
|
+
|
|
113
|
+
// tell main.js how tall the box should be: the top row plus the content's natural height
|
|
114
|
+
useLayoutEffect(() => {
|
|
115
|
+
if (mode !== 'full' || !content.current) return
|
|
116
|
+
// send the width it was measured at: main.js drops reports from before its last resize
|
|
117
|
+
// and only once the size has been still for a moment: a passing tall frame (a code block before its
|
|
118
|
+
// highlighting, a clip before it loads) would otherwise widen the box for good
|
|
119
|
+
// While the answer is being written the box keeps the size it opened at (main.js show(), BOX.work):
|
|
120
|
+
// fitting on every streamed chunk made it grow step by step. It fits once the answer is done.
|
|
121
|
+
let timer = 0
|
|
122
|
+
const measure = () => {
|
|
123
|
+
if (busy.current) return
|
|
124
|
+
lens.fit((top.current ? top.current.offsetHeight : 0) + content.current.offsetHeight + (bottom.current ? bottom.current.offsetHeight : 0), window.innerWidth)
|
|
125
|
+
}
|
|
126
|
+
const report = () => { clearTimeout(timer); timer = setTimeout(measure, 120) }
|
|
127
|
+
remeasure.current = report
|
|
128
|
+
measure()
|
|
129
|
+
const ro = new ResizeObserver(report)
|
|
130
|
+
ro.observe(content.current)
|
|
131
|
+
return () => { clearTimeout(timer); ro.disconnect() }
|
|
132
|
+
}, [mode])
|
|
133
|
+
|
|
134
|
+
if (mode === 'min') {
|
|
135
|
+
return (
|
|
136
|
+
<HStack height="100vh" hAlign="center" vAlign="center" style={drag}>
|
|
137
|
+
<HStack style={noDrag}>
|
|
138
|
+
<Button size="sm" variant="ghost" label="0" tooltip="Show the explanation" onClick={() => lens.restore()} />
|
|
139
|
+
</HStack>
|
|
140
|
+
</HStack>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<VStack height="100vh" gap={0}>
|
|
146
|
+
<HStack ref={top} gap={0.5} paddingInline={1} paddingBlockStart={1} hAlign="end" style={drag}>
|
|
147
|
+
<HStack gap={0.5} style={noDrag}>
|
|
148
|
+
<IconButton size="sm" variant="ghost" label="Explain in detail" icon={<Icon icon="externalLink" />}
|
|
149
|
+
isDisabled={!st.answer || st.busy} onClick={() => lens.openDetail()} />
|
|
150
|
+
<IconButton size="sm" variant="ghost" label="Minimize" icon={<Icon icon="chevronDown" />} onClick={() => lens.minimize()} />
|
|
151
|
+
<IconButton size="sm" variant="ghost" label="Close (Esc)" icon={<Icon icon="close" />} onClick={() => lens.close()} />
|
|
152
|
+
</HStack>
|
|
153
|
+
</HStack>
|
|
154
|
+
<VStack isScrollable style={{ flex: 1, minHeight: 0 }}>
|
|
155
|
+
<VStack ref={content} gap={2} paddingInline={3} paddingBlockEnd={3}>
|
|
156
|
+
{(st.status || (st.busy && !st.answer)) && (
|
|
157
|
+
<HStack gap={1} vAlign="center">
|
|
158
|
+
{st.busy && !st.answer && <Spinner size="sm" />}
|
|
159
|
+
<Text type="supporting" color="secondary">{st.status}</Text>
|
|
160
|
+
</HStack>
|
|
161
|
+
)}
|
|
162
|
+
{st.answer && <Answer st={st} />}
|
|
163
|
+
{st.drawing && <Spinner size="sm" />}
|
|
164
|
+
<Followups st={st} />
|
|
165
|
+
{/* fixed width: a 16:9 clip that grew with the box would make widening useless (see fitBox) */}
|
|
166
|
+
{st.video && <video src={st.video} autoPlay loop muted playsInline style={{ width: '24rem', maxWidth: '100%', display: 'block' }} />}
|
|
167
|
+
</VStack>
|
|
168
|
+
</VStack>
|
|
169
|
+
<VStack ref={bottom} gap={0}><FollowUp st={st} view="box" disabled={!(st.ready || (st.answer && !st.busy))} /></VStack>
|
|
170
|
+
</VStack>
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const languageOf = (file) => ({ py: 'python', js: 'javascript', mjs: 'javascript', jsx: 'jsx', ts: 'typescript', tsx: 'tsx', json: 'json',
|
|
175
|
+
md: 'markdown', sh: 'bash', yml: 'yaml', yaml: 'yaml', rs: 'rust', go: 'go', java: 'java', sql: 'sql', css: 'css', html: 'html' })[
|
|
176
|
+
(/\.([a-z0-9]+)$/i.exec(file || '') || [])[1]?.toLowerCase()] || 'plaintext'
|
|
177
|
+
|
|
178
|
+
function Side({ title, children }) {
|
|
179
|
+
return (
|
|
180
|
+
<VStack gap={1}>
|
|
181
|
+
<Text type="label" color="secondary">{title}</Text>
|
|
182
|
+
{children}
|
|
183
|
+
</VStack>
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function Detail() {
|
|
188
|
+
const [st, dispatch] = useReducer(reduceDetail, undefined, () => freshDetail())
|
|
189
|
+
useEffect(() => { lens.onDetail(dispatch) }, [])
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
const onKey = (e) => { if (e.key === 'Escape') lens.closeDetail() }
|
|
192
|
+
const onClick = (e) => {
|
|
193
|
+
const a = e.target.closest && e.target.closest('a[href^="http"]')
|
|
194
|
+
if (a) { e.preventDefault(); lens.openUrl(a.href) }
|
|
195
|
+
}
|
|
196
|
+
document.addEventListener('keydown', onKey)
|
|
197
|
+
document.addEventListener('click', onClick, true)
|
|
198
|
+
return () => { document.removeEventListener('keydown', onKey); document.removeEventListener('click', onClick, true) }
|
|
199
|
+
}, [])
|
|
200
|
+
const hasSide = st.video || st.snippets.length > 0 || st.related.length > 0 || st.web.length > 0
|
|
201
|
+
return (
|
|
202
|
+
<VStack height="100vh" gap={0}>
|
|
203
|
+
<HStack gap={1} padding={2} vAlign="center" style={drag}>
|
|
204
|
+
<HStack style={{ flex: 1, minWidth: 0 }}>
|
|
205
|
+
<Text weight="semibold" size="lg" maxLines={1}>{st.title || 'Pocket Tutor'}</Text>
|
|
206
|
+
</HStack>
|
|
207
|
+
<HStack style={noDrag}>
|
|
208
|
+
<IconButton size="sm" variant="ghost" label="Close (Esc)" icon={<Icon icon="close" />} onClick={() => lens.closeDetail()} />
|
|
209
|
+
</HStack>
|
|
210
|
+
</HStack>
|
|
211
|
+
<Divider />
|
|
212
|
+
<HStack gap={0} style={{ flex: 1, minHeight: 0 }}>
|
|
213
|
+
<VStack isScrollable gap={2} padding={4} style={{ flex: 1, minWidth: 0 }}>
|
|
214
|
+
{st.busy && !st.text && (
|
|
215
|
+
<HStack gap={1} vAlign="center"><Spinner size="sm" /><Text type="supporting" color="secondary">Writing the detailed explanation…</Text></HStack>
|
|
216
|
+
)}
|
|
217
|
+
{st.error && <Text type="supporting" weight="semibold">{st.error}</Text>}
|
|
218
|
+
{st.text && <Answer st={st} text={st.text} busy={st.busy} />}
|
|
219
|
+
<Followups st={st} />
|
|
220
|
+
</VStack>
|
|
221
|
+
{hasSide && <Divider orientation="vertical" />}
|
|
222
|
+
{hasSide && (
|
|
223
|
+
<VStack isScrollable gap={3} padding={3} width="22rem">
|
|
224
|
+
{st.video && <video src={st.video} autoPlay loop muted playsInline style={{ width: '100%', display: 'block' }} />}
|
|
225
|
+
{st.snippets.length > 0 && (
|
|
226
|
+
<Side title="In your code">
|
|
227
|
+
{st.snippets.map((sn) => (
|
|
228
|
+
<Collapsible key={`${sn.file}:${sn.line}`} defaultIsOpen={false} chevronPosition="start" trigger={<Code>{`${sn.file}:${sn.line}`}</Code>}>
|
|
229
|
+
<VStack gap={1} hAlign="start">
|
|
230
|
+
{sn.code && <CodeBlock code={sn.code} language={languageOf(sn.file)} size="sm" width="100%" hasLineNumbers
|
|
231
|
+
startLineNumber={sn.from || 1} highlightLines={[sn.line]} hasLanguageLabel={false} maxHeight="14rem" />}
|
|
232
|
+
<Button size="sm" variant="ghost" label="Open in VS Code" onClick={() => lens.openCode(sn.file, sn.line)} />
|
|
233
|
+
</VStack>
|
|
234
|
+
</Collapsible>
|
|
235
|
+
))}
|
|
236
|
+
</Side>
|
|
237
|
+
)}
|
|
238
|
+
{st.related.length > 0 && (
|
|
239
|
+
<Side title="Related ideas">
|
|
240
|
+
{st.related.map((r) => <Text key={r} type="supporting">{r}</Text>)}
|
|
241
|
+
</Side>
|
|
242
|
+
)}
|
|
243
|
+
{st.web.length > 0 && (
|
|
244
|
+
<Side title="Read more">
|
|
245
|
+
{st.web.map((w) => (
|
|
246
|
+
<VStack key={w.url} gap={0}>
|
|
247
|
+
<Link onClick={(e) => { e.preventDefault(); lens.openUrl(w.url) }} maxLines={2}>{w.title}</Link>
|
|
248
|
+
<Text type="supporting" size="2xs" color="secondary">{w.site}</Text>
|
|
249
|
+
</VStack>
|
|
250
|
+
))}
|
|
251
|
+
</Side>
|
|
252
|
+
)}
|
|
253
|
+
</VStack>
|
|
254
|
+
)}
|
|
255
|
+
</HStack>
|
|
256
|
+
<Divider />
|
|
257
|
+
<FollowUp st={st} view="detail" disabled={!st.text || st.busy} />
|
|
258
|
+
</VStack>
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const view = new URLSearchParams(window.location.search).get('view')
|
|
263
|
+
|
|
264
|
+
createRoot(document.getElementById('root')).render(
|
|
265
|
+
<Theme theme={themes[defaultThemeSlug]} mode={themeModes[defaultThemeSlug] ?? 'dark'}>
|
|
266
|
+
{view === 'detail' ? <Detail /> : <Box />}
|
|
267
|
+
</Theme>,
|
|
268
|
+
)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|