From 5662fa0d09b70ca9d4e620a89aa22dfbebf4c11f Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Mon, 13 Mar 2023 20:59:27 +0100 Subject: [PATCH] fix compile --- .../src/lib/components/WhitelistIp.svelte | 4 +-- .../InlineScriptEditor.svelte | 4 +-- .../settingsPanel/ComponentPanel.svelte | 5 ++-- .../inputEditor/EvalInputEditor.svelte | 4 +-- frontend/src/lib/components/apps/utils.ts | 29 ++++++++++--------- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/frontend/src/lib/components/WhitelistIp.svelte b/frontend/src/lib/components/WhitelistIp.svelte index 6ccc384354..75480caf21 100644 --- a/frontend/src/lib/components/WhitelistIp.svelte +++ b/frontend/src/lib/components/WhitelistIp.svelte @@ -9,9 +9,7 @@ ...new Set( workers .filter((worker) => { - const date = new Date().getTime() - 300 * 60 - const ping_at = new Date(worker.ping_at).getTime() - return worker.ip != 'unretrievable IP' && ping_at > date + return worker.ip != 'unretrievable IP' && worker.last_ping && worker.last_ping < 300 }) .map((worker) => worker.ip) ) diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditor.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditor.svelte index 9c63d0f6ce..b6a7400828 100644 --- a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditor.svelte +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditor.svelte @@ -27,7 +27,7 @@ export let fields: Record = {} export let syncFields: boolean = false - const { runnableComponents, stateId, worldStore } = + const { runnableComponents, stateId, worldStore, state } = getContext('AppViewerContext') let editor: Editor @@ -82,7 +82,7 @@ $: extraLib = inlineScript.language == 'frontend' && worldStore - ? buildExtraLib($worldStore?.outputsById ?? {}, id, false) + ? buildExtraLib($worldStore?.outputsById ?? {}, id, false, $state, true) : undefined diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte index d381e4db7f..9dec3027e9 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte @@ -40,7 +40,8 @@ selectedComponent, worldStore, focusedGrid, - stateId + stateId, + state } = getContext('AppViewerContext') const { history } = getContext('AppEditorContext') @@ -70,7 +71,7 @@ $: extraLib = component?.componentInput?.type === 'template' && $worldStore - ? buildExtraLib($worldStore?.outputsById ?? {}, component?.id, false) + ? buildExtraLib($worldStore?.outputsById ?? {}, component?.id, false, $state, false) : undefined function keydown(event: KeyboardEvent) { diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/inputEditor/EvalInputEditor.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/inputEditor/EvalInputEditor.svelte index ef18dfd038..f9697e20ae 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/inputEditor/EvalInputEditor.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/inputEditor/EvalInputEditor.svelte @@ -10,13 +10,13 @@ export let id: string export let hasRows: boolean = false - const { onchange, worldStore } = getContext('AppViewerContext') + const { onchange, worldStore, state } = getContext('AppViewerContext') $: componentInput && onchange?.() $: extraLib = componentInput?.expr && $worldStore - ? buildExtraLib($worldStore?.outputsById ?? {}, id, hasRows) + ? buildExtraLib($worldStore?.outputsById ?? {}, id, hasRows, $state, false) : undefined diff --git a/frontend/src/lib/components/apps/utils.ts b/frontend/src/lib/components/apps/utils.ts index 702a172432..ef28c4021a 100644 --- a/frontend/src/lib/components/apps/utils.ts +++ b/frontend/src/lib/components/apps/utils.ts @@ -162,21 +162,24 @@ export function toStatic( export function buildExtraLib( components: Record>>, idToExclude: string, - hasRows: boolean + hasRows: boolean, + state: Record, + goto: boolean ): string { - return ( - Object.entries(components) - .filter(([k, v]) => k != idToExclude) - .map(([k, v]) => [k, Object.fromEntries(Object.entries(v).map(([k, v]) => [k, v.peak()]))]) - .map( - ([k, v]) => ` - -declare const ${k} = ${JSON.stringify(v)}; - + const cs = Object.entries(components) + .filter(([k, v]) => k != idToExclude) + .map(([k, v]) => [k, Object.fromEntries(Object.entries(v).map(([k, v]) => [k, v.peak()]))]) + .map( + ([k, v]) => `declare const ${k}: ${JSON.stringify(v)}; +` + ) + .join('\n') + + return `${cs} +${hasRows ? 'declare const row: Record;' : ''} +${goto ? 'declare const goto: async (path: string) => void)' : ''} +declare const state: ${JSON.stringify(state)}; ` - ) - .join('\n') + (hasRows ? 'declare const row: Record;' : '') - ) } export function getAllScriptNames(app: App): string[] {