From e57f471b7e6a783f25d9b54855ad69d7202b1b35 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Sat, 2 Sep 2023 08:36:42 +0200 Subject: [PATCH] chore: fix TypeScript issues --- .../navigationBar/NavigationBarItem.svelte | 6 ++- .../NavigationBarPathEditor.svelte | 8 ++-- .../components/modals/CopyPasteModal.svelte | 3 +- src/lib/components/modals/Header.svelte | 3 +- .../components/modals/JSONEditorModal.svelte | 3 +- .../components/modals/JSONRepairModal.svelte | 3 +- src/lib/components/modals/ModalRef.svelte | 3 +- src/lib/components/modals/SortModal.svelte | 3 +- .../components/modals/TransformModal.svelte | 12 +++--- .../modals/TransformModalHeader.svelte | 12 +++--- .../modals/popup/AbsolutePopup.svelte | 4 +- .../components/modals/transformModalState.ts | 11 ++++- .../modes/tablemode/TableMode.svelte | 7 ++- .../components/modes/textmode/TextMode.svelte | 43 +++++++++++-------- .../components/modes/treemode/TreeMode.svelte | 7 ++- .../modes/treemode/ValidationErrorIcon.svelte | 4 +- .../value/components/ColorPicker.svelte | 6 +-- .../value/components/TimestampTag.svelte | 3 +- src/lib/types.ts | 9 ++++ 19 files changed, 96 insertions(+), 54 deletions(-) diff --git a/src/lib/components/controls/navigationBar/NavigationBarItem.svelte b/src/lib/components/controls/navigationBar/NavigationBarItem.svelte index 34e43311..7c292833 100644 --- a/src/lib/components/controls/navigationBar/NavigationBarItem.svelte +++ b/src/lib/components/controls/navigationBar/NavigationBarItem.svelte @@ -6,8 +6,10 @@ import NavigationBarDropdown from '../../../components/controls/navigationBar/NavigationBarDropdown.svelte' import { getContext } from 'svelte' import type { JSONPath } from 'immutable-json-patch' + import type { AbsolutePopupContext } from '$lib/types' - const { openAbsolutePopup, closeAbsolutePopup } = getContext('absolute-popup') + const { openAbsolutePopup, closeAbsolutePopup } = + getContext('absolute-popup') export let path: JSONPath export let index: number @@ -21,7 +23,7 @@ $: itemPath = path.slice(0, index) $: selectedItem = path[index] - function handleSelectItem(item) { + function handleSelectItem(item: string) { closeAbsolutePopup(popupId) onSelect(itemPath.concat(item)) } diff --git a/src/lib/components/controls/navigationBar/NavigationBarPathEditor.svelte b/src/lib/components/controls/navigationBar/NavigationBarPathEditor.svelte index e8e0d058..b7e7cd45 100644 --- a/src/lib/components/controls/navigationBar/NavigationBarPathEditor.svelte +++ b/src/lib/components/controls/navigationBar/NavigationBarPathEditor.svelte @@ -6,9 +6,9 @@ import Icon from 'svelte-awesome' import { keyComboFromEvent } from '$lib/utils/keyBindings.js' import { tooltip } from '../../controls/tooltip/tooltip.js' - import type { JSONPathParser, OnError } from '$lib/types.js' + import type { AbsolutePopupContext, JSONPathParser, OnError } from '$lib/types.js' - const absolutePopupContext = getContext('absolute-popup') + const absolutePopupContext = getContext('absolute-popup') export let path: JSONPath export let pathParser: JSONPathParser @@ -17,13 +17,13 @@ export let onError: OnError export let pathExists: (path: JSONPath) => boolean - let inputRef + let inputRef: HTMLInputElement let inputPath: string let validationActive = false $: inputPath = pathParser.stringify(path) $: inputValidationError = validationActive ? parseAndValidate(inputPath).error : undefined - let copiedTimer = undefined + let copiedTimer: number | undefined = undefined let copied = false const copiedDelay = 1000 // ms diff --git a/src/lib/components/modals/CopyPasteModal.svelte b/src/lib/components/modals/CopyPasteModal.svelte index f89075ca..fa75d9d3 100644 --- a/src/lib/components/modals/CopyPasteModal.svelte +++ b/src/lib/components/modals/CopyPasteModal.svelte @@ -4,8 +4,9 @@ import { getContext } from 'svelte' import { IS_MAC } from '../../utils/navigatorUtils.js' import Header from './Header.svelte' + import type { Context } from 'svelte-simple-modal' - const { close } = getContext('simple-modal') + const { close } = getContext('simple-modal') const ctrl = IS_MAC ? '⌘' : 'Ctrl' diff --git a/src/lib/components/modals/Header.svelte b/src/lib/components/modals/Header.svelte index 54503e3c..4cf32bd9 100644 --- a/src/lib/components/modals/Header.svelte +++ b/src/lib/components/modals/Header.svelte @@ -4,11 +4,12 @@ import { getContext } from 'svelte' import Icon from 'svelte-awesome' import { faTimes } from '@fortawesome/free-solid-svg-icons' + import type { Context } from 'svelte-simple-modal' export let title = 'Modal' export let onClose: (() => void) | undefined = undefined - const { close } = getContext('simple-modal') + const { close } = getContext('simple-modal')
diff --git a/src/lib/components/modals/JSONEditorModal.svelte b/src/lib/components/modals/JSONEditorModal.svelte index 1c6a88b3..24a3612c 100644 --- a/src/lib/components/modals/JSONEditorModal.svelte +++ b/src/lib/components/modals/JSONEditorModal.svelte @@ -31,6 +31,7 @@ import memoizeOne from 'memoize-one' import { onEscape } from '$lib/actions/onEscape.js' import { getFocusPath } from '$lib/logic/selection.js' + import type { Context } from 'svelte-simple-modal' const debug = createDebug('jsoneditor:JSONEditorModal') @@ -60,7 +61,7 @@ export let onSortModal: OnSortModal export let onTransformModal: OnTransformModal - const { close } = getContext('simple-modal') + const { close } = getContext('simple-modal') interface ModalState { mode: Mode diff --git a/src/lib/components/modals/JSONRepairModal.svelte b/src/lib/components/modals/JSONRepairModal.svelte index d44189c2..17602f7f 100644 --- a/src/lib/components/modals/JSONRepairModal.svelte +++ b/src/lib/components/modals/JSONRepairModal.svelte @@ -4,13 +4,14 @@ import { getContext } from 'svelte' import JSONRepairComponent from './repair/JSONRepairComponent.svelte' import { onEscape } from '$lib/actions/onEscape.js' + import type { Context } from 'svelte-simple-modal' export let text export let onParse export let onRepair export let onApply - const { close } = getContext('simple-modal') + const { close } = getContext('simple-modal') function handleApply(repairedText) { close() diff --git a/src/lib/components/modals/ModalRef.svelte b/src/lib/components/modals/ModalRef.svelte index fbd233ae..866302b5 100644 --- a/src/lib/components/modals/ModalRef.svelte +++ b/src/lib/components/modals/ModalRef.svelte @@ -12,8 +12,9 @@ // // import { getContext } from 'svelte' + import type { Context } from 'svelte-simple-modal' - const context = getContext('simple-modal') + const context = getContext('simple-modal') export const open = context.open export const close = context.close diff --git a/src/lib/components/modals/SortModal.svelte b/src/lib/components/modals/SortModal.svelte index 9d4b1fe3..6830ffc2 100644 --- a/src/lib/components/modals/SortModal.svelte +++ b/src/lib/components/modals/SortModal.svelte @@ -14,6 +14,7 @@ import { createDebug } from '$lib/utils/debug.js' import type { OnSort } from '$lib/types.js' import { onEscape } from '$lib/actions/onEscape.js' + import type { Context } from 'svelte-simple-modal' const debug = createDebug('jsoneditor:SortModal') @@ -22,7 +23,7 @@ export let rootPath: JSONPath export let onSort: OnSort - const { close } = getContext('simple-modal') + const { close } = getContext('simple-modal') const stateId = `${id}:${compileJSONPointer(rootPath)}` const selectedJson = getIn(json, rootPath) diff --git a/src/lib/components/modals/TransformModal.svelte b/src/lib/components/modals/TransformModal.svelte index 2df75a71..214a7afc 100644 --- a/src/lib/components/modals/TransformModal.svelte +++ b/src/lib/components/modals/TransformModal.svelte @@ -24,9 +24,11 @@ OnClassName, OnPatch, OnRenderValue, - QueryLanguage + QueryLanguage, + QueryLanguageOptions } from '$lib/types.js' import { onEscape } from '$lib/actions/onEscape.js' + import type { Context } from 'svelte-simple-modal' const debug = createDebug('jsoneditor:TransformModal') @@ -54,7 +56,7 @@ $: selectedJson = getIn(json, rootPath) $: selectedContent = { json: selectedJson } - const { close } = getContext('simple-modal') + const { close } = getContext('simple-modal') const stateId = `${id}:${compileJSONPointer(rootPath)}` @@ -78,7 +80,7 @@ return queryLanguages.find((item) => item.id === queryLanguageId) || queryLanguages[0] } - function updateQueryByWizard(newQueryOptions) { + function updateQueryByWizard(newQueryOptions: QueryLanguageOptions) { queryOptions = newQueryOptions query = getSelectedQueryLanguage(queryLanguageId).createQuery(json, newQueryOptions) isManual = false @@ -107,7 +109,7 @@ previewError = undefined } catch (err) { previewContent = { text: '' } - previewError = err.toString() + previewError = String(err) } } @@ -153,7 +155,7 @@ // button when creating a preview was successful console.error(err) previewContent = { text: '' } - previewError = err.toString() + previewError = String(err) } } diff --git a/src/lib/components/modals/TransformModalHeader.svelte b/src/lib/components/modals/TransformModalHeader.svelte index 9a6ab7bb..4f881546 100644 --- a/src/lib/components/modals/TransformModalHeader.svelte +++ b/src/lib/components/modals/TransformModalHeader.svelte @@ -5,7 +5,8 @@ import Icon from 'svelte-awesome' import { faCog, faTimes } from '@fortawesome/free-solid-svg-icons' import SelectQueryLanguage from '../controls/selectQueryLanguage/SelectQueryLanguage.svelte' - import type { OnChangeQueryLanguage, QueryLanguage } from '$lib/types.js' + import type { AbsolutePopupContext, OnChangeQueryLanguage, QueryLanguage } from '$lib/types.js' + import type { Context } from 'svelte-simple-modal' export let queryLanguages: QueryLanguage[] export let queryLanguageId: string @@ -14,14 +15,15 @@ let refConfigButton: HTMLButtonElement | undefined let popupId: number | undefined - const { close } = getContext('simple-modal') - const { openAbsolutePopup, closeAbsolutePopup } = getContext('absolute-popup') + const { close } = getContext('simple-modal') + const { openAbsolutePopup, closeAbsolutePopup } = + getContext('absolute-popup') function openConfig() { const props = { queryLanguages, queryLanguageId, - onChangeQueryLanguage: (selectedQueryLanguage) => { + onChangeQueryLanguage: (selectedQueryLanguage: QueryLanguage) => { closeAbsolutePopup(popupId) onChangeQueryLanguage(selectedQueryLanguage) } @@ -50,7 +52,7 @@ {/if} -
diff --git a/src/lib/components/modals/popup/AbsolutePopup.svelte b/src/lib/components/modals/popup/AbsolutePopup.svelte index bd6d3952..7746c55e 100644 --- a/src/lib/components/modals/popup/AbsolutePopup.svelte +++ b/src/lib/components/modals/popup/AbsolutePopup.svelte @@ -3,7 +3,7 @@ {#each popups as popup} diff --git a/src/lib/components/modals/transformModalState.ts b/src/lib/components/modals/transformModalState.ts index 598dcd61..8e7686cf 100644 --- a/src/lib/components/modals/transformModalState.ts +++ b/src/lib/components/modals/transformModalState.ts @@ -1 +1,10 @@ -export const transformModalState: Record = {} +import type { QueryLanguageOptions } from '$lib/types.js' + +export interface ModalState { + queryLanguageId: string + queryOptions: QueryLanguageOptions + query: string + isManual: boolean +} + +export const transformModalState: Record = {} diff --git a/src/lib/components/modes/tablemode/TableMode.svelte b/src/lib/components/modes/tablemode/TableMode.svelte index f51b46a1..201edd41 100644 --- a/src/lib/components/modes/tablemode/TableMode.svelte +++ b/src/lib/components/modes/tablemode/TableMode.svelte @@ -2,6 +2,7 @@