Skip to content

Commit bb68997

Browse files
committed
chore: remove extra code from core
1 parent f186bed commit bb68997

2 files changed

Lines changed: 67 additions & 69 deletions

File tree

src/livecodes/UI/templates.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const createTemplatesContainer = (
2828
}
2929
});
3030
});
31+
setupTemplatesSearch(templatesContainer);
3132
return templatesContainer;
3233
};
3334

@@ -53,23 +54,23 @@ export const noUserTemplates = () => `
5354
<div class="description alert">${window.deps.translateString('templates.noUserTemplates.heading', 'You have no saved templates.')}</div>
5455
<div class="description help">
5556
${window.deps.translateString(
56-
'templates.noUserTemplates.desc',
57-
'You can save a project as a template from <wbr />(App&nbsp;menu&nbsp;&gt;&nbsp;Save&nbsp;as&nbsp;&gt; Template).',
58-
{
59-
isHTML: true,
60-
},
61-
)}
57+
'templates.noUserTemplates.desc',
58+
'You can save a project as a template from <wbr />(App&nbsp;menu&nbsp;&gt;&nbsp;Save&nbsp;as&nbsp;&gt; Template).',
59+
{
60+
isHTML: true,
61+
},
62+
)}
6263
</div>
6364
</div>
6465
`;
6566

66-
export const setupTemplatesSearch = () => {
67-
const input = document.getElementById('templates-search-input') as HTMLInputElement | null;
67+
export const setupTemplatesSearch = (container: HTMLElement) => {
68+
const input = container.querySelector('#templates-search-input') as HTMLInputElement | null;
6869
if (!input) return;
6970

7071
const filterTemplates = (query: string) => {
71-
const mainItems = document.querySelectorAll('#templates-starter li');
72-
const userItems = document.querySelectorAll('#templates-user li');
72+
const mainItems = container.querySelectorAll('#templates-starter li');
73+
const userItems = container.querySelectorAll('#templates-user li');
7374
const items = Array.from(mainItems).concat(Array.from(userItems));
7475
items.forEach((item) => {
7576
const text = item.textContent?.toLowerCase() || '';

src/livecodes/core.ts

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
getResultElement,
1313
loadingMessage,
1414
noUserTemplates,
15-
setupTemplatesSearch,
1615
} from './UI';
1716
import type {
1817
BroadcastData,
@@ -250,18 +249,18 @@ const loadStyles = () =>
250249
isHeadless
251250
? Promise.resolve()
252251
: Promise.all(
253-
[
254-
snackbarUrl,
255-
...(isLite
256-
? []
257-
: [
258-
lunaObjViewerStylesUrl,
259-
lunaDataGridStylesUrl,
260-
lunaDomViewerStylesUrl,
261-
lunaConsoleStylesUrl,
262-
]),
263-
].map((url) => loadStylesheet(url, undefined, '#app-styles')),
264-
);
252+
[
253+
snackbarUrl,
254+
...(isLite
255+
? []
256+
: [
257+
lunaObjViewerStylesUrl,
258+
lunaDataGridStylesUrl,
259+
lunaDomViewerStylesUrl,
260+
lunaConsoleStylesUrl,
261+
]),
262+
].map((url) => loadStylesheet(url, undefined, '#app-styles')),
263+
);
265264

266265
let lastRun = { time: 0, result: '' };
267266
const createIframe = (container: HTMLElement, result = '', service = sandboxService) =>
@@ -353,12 +352,11 @@ const createIframe = (container: HTMLElement, result = '', service = sandboxServ
353352

354353
iframe.remove(); // avoid changing browser history
355354
const { markup, style, script } = getConfig();
356-
const query = `?markup=${markup.language}&style=${style.language}&script=${
357-
script.language
358-
}&isEmbed=${isEmbed}&isLoggedIn=${Boolean(authService?.isLoggedIn())}&appCDN=${getAppCDN()}`;
355+
const query = `?markup=${markup.language}&style=${style.language}&script=${script.language
356+
}&isEmbed=${isEmbed}&isLoggedIn=${Boolean(authService?.isLoggedIn())}&appCDN=${getAppCDN()}`;
359357
const scrollPosition =
360358
params.scrollPosition === false ||
361-
(iframeScrollPosition.x === 0 && iframeScrollPosition.y === 0)
359+
(iframeScrollPosition.x === 0 && iframeScrollPosition.y === 0)
362360
? ''
363361
: `#livecodes-scroll-position:${iframeScrollPosition.x},${iframeScrollPosition.y}`;
364362
iframe.src = service.getResultUrl() + query + scrollPosition;
@@ -505,7 +503,7 @@ const createEditors = async (config: Config) => {
505503
language: languageIsEnabled(config.markup.language, config)
506504
? config.markup.language
507505
: (config.languages?.find((lang) => getLanguageEditorId(lang) === 'markup') as Language) ||
508-
'html',
506+
'html',
509507
value: languageIsEnabled(config.markup.language, config) ? config.markup.content || '' : '',
510508
};
511509
const styleOptions: EditorOptions = {
@@ -515,7 +513,7 @@ const createEditors = async (config: Config) => {
515513
language: languageIsEnabled(config.style.language, config)
516514
? config.style.language
517515
: (config.languages?.find((lang) => getLanguageEditorId(lang) === 'style') as Language) ||
518-
'css',
516+
'css',
519517
value: languageIsEnabled(config.style.language, config) ? config.style.content || '' : '',
520518
};
521519
const scriptOptions: EditorOptions = {
@@ -525,7 +523,7 @@ const createEditors = async (config: Config) => {
525523
language: languageIsEnabled(config.script.language, config)
526524
? config.script.language
527525
: (config.languages?.find((lang) => getLanguageEditorId(lang) === 'script') as Language) ||
528-
'javascript',
526+
'javascript',
529527
value: languageIsEnabled(config.script.language, config) ? config.script.content || '' : '',
530528
};
531529

@@ -982,12 +980,12 @@ const getResultPage = async ({
982980
blockly:
983981
scriptLanguage === 'blockly'
984982
? ((await customEditors.blockly?.getContent({
985-
baseUrl,
986-
editors,
987-
config: getConfig(),
988-
html: compiledMarkup,
989-
eventsManager,
990-
})) as BlocklyContent)
983+
baseUrl,
984+
editors,
985+
config: getConfig(),
986+
html: compiledMarkup,
987+
eventsManager,
988+
})) as BlocklyContent)
991989
: {},
992990
});
993991
const compiledScript = scriptCompileResult.code;
@@ -1328,28 +1326,28 @@ const share = async (
13281326
const config = getConfig();
13291327
const content = contentOnly
13301328
? {
1331-
...getContentConfig(config),
1332-
markup: {
1333-
...config.markup,
1334-
title: undefined,
1335-
hideTitle: undefined,
1336-
},
1337-
style: {
1338-
...config.style,
1339-
title: undefined,
1340-
hideTitle: undefined,
1341-
},
1342-
script: {
1343-
...config.script,
1344-
title: undefined,
1345-
hideTitle: undefined,
1346-
},
1347-
tools: {
1348-
...config.tools,
1349-
enabled: defaultConfig.tools.enabled,
1350-
status: config.tools.status === 'none' ? defaultConfig.tools.status : config.tools.status,
1351-
},
1352-
}
1329+
...getContentConfig(config),
1330+
markup: {
1331+
...config.markup,
1332+
title: undefined,
1333+
hideTitle: undefined,
1334+
},
1335+
style: {
1336+
...config.style,
1337+
title: undefined,
1338+
hideTitle: undefined,
1339+
},
1340+
script: {
1341+
...config.script,
1342+
title: undefined,
1343+
hideTitle: undefined,
1344+
},
1345+
tools: {
1346+
...config.tools,
1347+
enabled: defaultConfig.tools.enabled,
1348+
status: config.tools.status === 'none' ? defaultConfig.tools.status : config.tools.status,
1349+
},
1350+
}
13531351
: config;
13541352

13551353
const currentUrl = (location.origin + location.pathname).split('/').slice(0, -1).join('/') + '/';
@@ -1631,7 +1629,7 @@ const setSavedStatus = async () => {
16311629
!!(
16321630
savedConfig &&
16331631
JSON.stringify(getContentConfig(savedConfig)) ===
1634-
JSON.stringify(getContentConfig(getConfig()))
1632+
JSON.stringify(getContentConfig(getConfig()))
16351633
);
16361634

16371635
const projectTitle = UI.getProjectTitleElement();
@@ -1813,12 +1811,12 @@ const login = async () =>
18131811
const displayName = user.displayName || user.username;
18141812
const loginSuccessMessage = displayName
18151813
? window.deps.translateString(
1816-
'core.login.successWithName',
1817-
'Logged in as: {{name}}',
1818-
{
1819-
name: displayName,
1820-
},
1821-
)
1814+
'core.login.successWithName',
1815+
'Logged in as: {{name}}',
1816+
{
1817+
name: displayName,
1818+
},
1819+
)
18221820
: window.deps.translateString('core.login.success', 'Logged in successfully');
18231821
notifications.success(loginSuccessMessage);
18241822
displayLoggedIn(user);
@@ -2591,9 +2589,9 @@ const handleKeyboardShortcutsScreen = () => {
25912589
<tr>
25922590
<td>${item.title}</td>
25932591
<td>${item.hotkey
2594-
?.split('+')
2595-
.map((key) => `<kbd>${capitalize(key)}</kbd>`)
2596-
.join(' ')}</td>
2592+
?.split('+')
2593+
.map((key) => `<kbd>${capitalize(key)}</kbd>`)
2594+
.join(' ')}</td>
25972595
</tr>
25982596
`,
25992597
)
@@ -3277,7 +3275,6 @@ const handleNew = () => {
32773275
false,
32783276
);
32793277
});
3280-
setupTemplatesSearch();
32813278
})
32823279
.catch(() => {
32833280
loadingText?.remove();

0 commit comments

Comments
 (0)