-
-
Notifications
You must be signed in to change notification settings - Fork 202
Add support for Ripple (WIP) #865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 2 commits
cc813f0
bb8c04f
f0c18a7
16eeddb
085b3a3
cd0045b
b7a457c
1dd4f75
3324ef9
a6c6cce
4a8b37d
2c88177
6d65af0
813cbdd
db6a670
24df424
f3702a7
28387b9
20f8def
20a473d
ffffb1a
dfe0702
abd3e58
dbfe2e1
e62a259
28592cd
ffbdbfc
f9c3b47
ce7fea3
e2d6cea
0c0b60e
05d6552
b2cf421
b324074
224bdac
bea5b56
ec6838b
fc56a41
00683e9
a8ee0a9
6d5f6d3
765861f
0c1e45f
bba104d
7881b06
0887ab8
defbe25
d420059
56805b0
6848574
eb71c13
a57b44a
264033e
b10c3c3
544dea0
971330a
35d6186
6885b11
0d1a869
b0ecd9b
3126c4f
ddb54e9
0bed5bb
16d57df
fafc9a2
2b71b23
75b7334
b91d192
a0df890
39b67f4
3b4c76d
efdea7e
2234dc2
a7f817f
4894b33
0413d21
6b00d82
5a0d428
d530d30
fee8369
d8ba8a5
35de26b
8bf2be9
2404bed
7eb2056
dca57b7
4513aa7
7a6fe48
1ff714e
550c7cc
902a78a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './lang-ripple'; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,31 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { LanguageSpecs } from '../../models'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { rippleUrl } from '../../vendors'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { parserPlugins } from '../prettier'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const ripple: LanguageSpecs = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'ripple', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: 'Ripple', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| info: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'babel-ts', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pluginUrls: [parserPlugins.babel, parserPlugins.html], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| compiler: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| factory: async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO: convert to UMD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { compile } = await import(rippleUrl); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return async (code) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!code.trim()) return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { js, css } = await compile(code, './src/App.ripple'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const cssCode = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| css === '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : `\n\nconst styles = document.createElement('style');\nstyles.innerHTML = ${JSON.stringify(css)};\ndocument.head.appendChild(styles);\n`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return `${js.code}${cssCode}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| factory: async () => { | |
| // TODO: convert to UMD | |
| const { compile } = await import(rippleUrl); | |
| return async (code) => { | |
| if (!code.trim()) return ''; | |
| const { js, css } = await compile(code, './src/App.ripple'); | |
| const cssCode = | |
| css === '' | |
| ? '' | |
| : `\n\nconst styles = document.createElement('style');\nstyles.innerHTML = ${JSON.stringify(css)};\ndocument.head.appendChild(styles);\n`; | |
| return `${js.code}${cssCode}`; | |
| }; | |
| }, | |
| factory: async () => { | |
| // TODO: convert to UMD | |
| const { compile } = await import(rippleUrl); | |
| return async (code) => { | |
| if (!code.trim()) return "export default () => null;"; | |
| try { | |
| const { js, css } = await compile(code, './src/App.ripple'); | |
| const cssCode = | |
| css === '' | |
| ? '' | |
| : `\n\n(function(){const id='lc-ripple-style';let s=document.getElementById(id);if(!s){s=document.createElement('style');s.id=id;document.head.appendChild(s);}s.textContent=${JSON.stringify(css)};})();`; | |
| return `${js.code}${cssCode}`; | |
| } catch (err) { | |
| console.error('[ripple] compile error:', err); | |
| throw err; | |
| } | |
| }; | |
| }, | |
| imports: { ripple: rippleModuleUrl }, |
🤖 Prompt for AI Agents
In src/livecodes/languages/ripple/lang-ripple.ts around lines 14 to 26, the
factory currently imports the ripple compiler directly but doesn't expose a
pinned runtime mapping, doesn't guard against missing imports, and doesn't
surface compile errors to the sandbox; update the language descriptor to include
an imports property mapping the runtime key (e.g., "ripple") to the pinned
rippleModuleUrl, add a guard around the dynamic import so you return a clear
error if the module cannot be loaded, and wrap the compile invocation in
try/catch so any compile errors are caught and returned as a readable error
string from the sandbox rather than throwing.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,9 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| export const rippleRuntime = ` | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { mount } from 'ripple'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import App from "./script"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| (() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| mount(App, { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| target: document.querySelector("#livecodes-app") || document.body.appendChild(document.createElement('div')), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| })(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| `; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainMake runtime resilient to non-default exports from compiled script. If the Ripple compiler doesn’t emit a default export, -export const rippleRuntime = `
-import { mount } from 'ripple';
-import App from "./script";
-(() => {
- mount(App, {
- target: document.querySelector("#livecodes-app") || document.body.appendChild(document.createElement('div')),
- });
-})();
-`;
+export const rippleRuntime = `
+import { mount } from 'ripple';
+import * as AppModule from "./script";
+(() => {
+ const App = AppModule.default || AppModule.App || AppModule;
+ const target =
+ document.querySelector("#livecodes-app") ||
+ (() => { const el = document.createElement('div'); el.id = 'livecodes-app'; return document.body.appendChild(el); })();
+ mount(App, { target });
+})();
+`;🏁 Script executed: #!/bin/bash
# List all files under the Ripple language integration directory
fd src/livecodes/languages/ripple -t f
# Locate any compiler or codegen files in that directory
fd compile src/livecodes/languages/ripple -t f
# Search for default export patterns in the ripple language code
rg -n "export default" src/livecodes/languages/ripple
# Search for named export patterns (const/function/class) in the same directory
rg -n "export (const|function|class) " src/livecodes/languages/rippleLength of output: 812 🏁 Script executed: #!/bin/bash
sed -n '1,200p' src/livecodes/languages/ripple/ripple-runtime.tsLength of output: 308 🏁 Script executed: #!/bin/bash
# Preview the first 200 lines of the Ripple language spec to see how compiled script is generated
sed -n '1,200p' src/livecodes/languages/ripple/lang-ripple.tsLength of output: 1003 Use namespace import with export fallbacks and assign File: src/livecodes/languages/ripple/ripple-runtime.ts -export const rippleRuntime = `
-import { mount } from 'ripple';
-import App from "./script";
-(() => {
- mount(App, {
- target: document.querySelector("#livecodes-app") || document.body.appendChild(document.createElement('div')),
- });
-})();
-`;
+export const rippleRuntime = `
+import { mount } from 'ripple';
+import * as AppModule from "./script";
+(() => {
+ const App = AppModule.default || AppModule.App || AppModule;
+ const target =
+ document.querySelector("#livecodes-app") ||
+ (() => {
+ const el = document.createElement('div');
+ el.id = 'livecodes-app';
+ return document.body.appendChild(el);
+ })();
+ mount(App, { target });
+})();
+`;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import { | |
| import { cssPresets, getLanguageCompiler, getLanguageExtension } from '../languages'; | ||
| import { reactRuntime } from '../languages/jsx/react-runtime'; | ||
| import { reactNativeRuntime } from '../languages/react-native/react-native-runtime'; | ||
| import { rippleRuntime } from '../languages/ripple/ripple-runtime'; | ||
| import { solidRuntime } from '../languages/solid/solid-runtime'; | ||
| import { hasCustomJsxRuntime } from '../languages/typescript'; | ||
| import type { Cache, CompileInfo, Config, EditorId, Language } from '../models'; | ||
|
|
@@ -210,6 +211,7 @@ export const createResultPage = async ({ | |
| 'react-native-tsx': reactNativeRuntime, | ||
| solid: solidRuntime, | ||
| 'solid.tsx': solidRuntime, | ||
| ripple: rippleRuntime, | ||
| }; | ||
|
Comment on lines
+221
to
222
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainEnsure Ripple runtime dependency is version-pinned in import map
🏁 Script executed: #!/bin/bash
# Locate the result-page.ts file
FILE=$(fd result-page.ts)
echo "Found file: $FILE"
# Show lines around the snippet (200–240)
sed -n '200,240p' "$FILE"
# Search for any compiler.imports usage across TypeScript files
rg -n "compiler\.imports" -g '*.ts'
# Search for import map or importMap references
rg -n "importMap" -g '*.ts'
rg -n "import map" -g '*.ts'Length of output: 5400 🏁 Script executed: #!/bin/bash
# Find ripple compiler file under languages directory
fd -g "*ripple*" -t f src/livecodes/languagesLength of output: 142 🏁 Script executed: #!/bin/bash
# Show Ripple language compiler implementation
sed -n '1,200p' src/livecodes/languages/ripple/lang-ripple.tsLength of output: 1003 Add pinned Ripple runtime import in ripple language spec imports: { ripple: rippleUrl },so that 🤖 Prompt for AI Agents |
||
| const jsxRuntime = jsxRuntimes[code.script.language] || ''; | ||
| const reactImport = | ||
|
|
@@ -439,7 +441,7 @@ export const createResultPage = async ({ | |
| } | ||
| } | ||
|
|
||
| // React JSX runtime | ||
| // JSX runtime | ||
| if (shouldInsertJsxRuntime) { | ||
| const jsxRuntimeScript = dom.createElement('script'); | ||
| jsxRuntimeScript.type = 'module'; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -389,6 +389,8 @@ export const resetCssUrl = /* @__PURE__ */ getUrl('[email protected]/reset.css'); | |
|
|
||
| export const riotBaseUrl = /* @__PURE__ */ getUrl('[email protected]/'); | ||
|
|
||
| export const rippleUrl = /* @__PURE__ */ getModuleUrl('[email protected]/compiler'); | ||
|
||
|
|
||
| export const rubyWasmBaseUrl = /* @__PURE__ */ getUrl('@ruby/[email protected]/dist/'); | ||
|
|
||
| export const rubyWasmScriptUrl = /* @__PURE__ */ getUrl( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid empty module when editor content is blank.
Returning
''yields a module with no exports; the runtime import then fails. Emit a tiny no-op component instead.📝 Committable suggestion
🤖 Prompt for AI Agents