prototypey.org - atproto lexicon typescript toolkit - mirror https://github.com/tylersayshi/prototypey
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix for playground

Tyler 12b62261 98c0fbc5

+18 -16
+18 -16
packages/site/src/components/Playground.tsx
··· 46 46 useEffect(() => { 47 47 const timeoutId = setTimeout(async () => { 48 48 try { 49 - const cleanedCode = code 50 - .replace(/import\s+{[^}]*}\s+from\s+['"][^'"]+['"]\s*;?\s*/g, "") 51 - .replace(/^type\s+\w+\s*=\s*[^;]+;?\s*$/gm, ""); 49 + const nsMatch = code.match( 50 + /const\s+ns\s*=\s*lx\.namespace\([^]*?\}\s*\);/, 51 + ); 52 + if (!nsMatch) { 53 + throw new Error("No namespace definition found"); 54 + } 52 55 53 - const lastVarMatch = cleanedCode.match(/(?:const|let|var)\s+(\w+)\s*=/); 54 - const lastVarName = lastVarMatch ? lastVarMatch[1] : null; 55 - 56 - const wrappedCode = lastVarName 57 - ? `${cleanedCode}\nreturn ${lastVarName};` 58 - : cleanedCode; 59 - 56 + const cleanedCode = nsMatch[0]; 57 + const wrappedCode = `${cleanedCode}\nreturn ns;`; 60 58 const fn = new Function("lx", wrappedCode); 61 59 const result = fn(lx); 62 60 let typeInfo = "// Hover over .infer in the editor to see the type"; 63 61 64 - if (lastVarName && monaco && tsWorkerRef.current) { 62 + if (monaco && tsWorkerRef.current) { 65 63 try { 66 64 const uri = monaco.Uri.parse("file:///main.ts"); 67 65 const existingModel = monaco.editor.getModel(uri); 68 66 69 67 if (existingModel) { 70 - const inferPosition = code.indexOf(`${lastVarName}.infer`); 68 + const inferPosition = code.indexOf(`ns.infer`); 71 69 if (inferPosition !== -1) { 72 - const offset = 73 - inferPosition + `${lastVarName}.infer`.length - 1; 70 + const offset = inferPosition + `ns.infer`.length - 1; 74 71 75 72 const quickInfo = 76 73 await tsWorkerRef.current.getQuickInfoAtPosition( ··· 183 180 184 181 const DEFAULT_CODE = `import { lx, type Infer } from "prototypey"; 185 182 186 - const profileNamespace = lx.namespace("app.bsky.actor.profile", { 183 + const ns = lx.namespace("app.bsky.actor.profile", { 187 184 main: lx.record({ 188 185 key: "self", 189 186 record: lx.object({ ··· 193 190 }), 194 191 }); 195 192 196 - type ProfileInferred = Infer<typeof profileNamespace>;`; 193 + type ProfileInferred = Infer<typeof ns>; 194 + 195 + const aProfile: ProfileInferred = { 196 + $type: "app.bsky.actor.profile", 197 + displayName: "Benny Harvey" 198 + }`;