MCPcopy Index your code
hub / github.com/tinyplex/tinybase / addStackblitz

Function addStackblitz

site/js/common/common.ts:109–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

107 });
108
109export const addStackblitz = () => {
110 const iframe = queryElement(getArticle(), ':scope iframe');
111 const iframeParent = iframe?.parentElement;
112 if (iframe == null || iframeParent == null) {
113 return;
114 }
115 const form = iframeParent.insertBefore(
116 createElement('form', null, {
117 action: 'https://stackblitz.com/run',
118 method: 'post',
119 target: '_blank',
120 }),
121 iframe,
122 ) as HTMLFormElement;
123 iframeParent.insertBefore(
124 createElement('a', null, {id: 'sbEdit'}, 'Open this demo in StackBlitz'),
125 iframe,
126 ).onclick = () => {
127 if (form.childNodes.length == 0) {
128 fetch('stackblitz.json')
129 .then((response) => response.json())
130 .then((project: ExecutableProject) => {
131 addHiddenInput(form, '[title]', project.title);
132 addHiddenInput(form, '[description]', project.description);
133 addHiddenInput(form, '[template]', project.template);
134 Object.entries(project.files).forEach(([filePath, contents]) =>
135 addHiddenInput(form, `[files][${filePath}]`, contents),
136 );
137 if (project.settings != null) {
138 addHiddenInput(
139 form,
140 '[settings]',
141 JSON.stringify(project.settings),
142 );
143 }
144 if (project.dependencies != null) {
145 addHiddenInput(
146 form,
147 '[dependencies]',
148 JSON.stringify(project.dependencies),
149 );
150 }
151 const action = new URL(form.action);
152 Object.entries(project.options ?? {}).forEach(([option, value]) =>
153 action.searchParams.set(option, value),
154 );
155 form.action = action.toString();
156 form.submit();
157 });
158 } else {
159 form.submit();
160 }
161 };
162};
163
164const updateNav = (
165 {

Callers 2

app.tsFile · 0.90
goFunction · 0.85

Calls 4

queryElementFunction · 0.85
getArticleFunction · 0.85
createElementFunction · 0.85
addHiddenInputFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…