From fcc7c8378f4141631fc8a0808b3e2224c1255d74 Mon Sep 17 00:00:00 2001 From: Dominik Haentsch Date: Fri, 27 Oct 2023 10:59:11 +0200 Subject: [PATCH] refactor: allow lenses with typed values in lens registry --- src/lenses/SafeHtmlLens.tsx | 4 ++-- src/lenses/TextLens.tsx | 6 ++---- src/stores/components.ts | 7 ++++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/lenses/SafeHtmlLens.tsx b/src/lenses/SafeHtmlLens.tsx index 200d86a8..abdc0077 100644 --- a/src/lenses/SafeHtmlLens.tsx +++ b/src/lenses/SafeHtmlLens.tsx @@ -3,8 +3,8 @@ import { Lens } from '../types'; import DOMPurify from 'dompurify'; import Html from '../components/ui/Html'; -const SafeHtmlLens: Lens = ({ value }) => { - const safe_html = DOMPurify.sanitize(value as string); +const SafeHtmlLens: Lens = ({ value }) => { + const safe_html = DOMPurify.sanitize(value); return ; }; diff --git a/src/lenses/TextLens.tsx b/src/lenses/TextLens.tsx index 03d800fc..55578887 100644 --- a/src/lenses/TextLens.tsx +++ b/src/lenses/TextLens.tsx @@ -1,12 +1,10 @@ import 'twin.macro'; import { Lens } from '../types'; -const TextLens: Lens = ({ value }) => { - const text = value as string; - +const TextLens: Lens = ({ value }) => { return (
- {text} + {value}
); }; diff --git a/src/stores/components.ts b/src/stores/components.ts index 7bf801ce..d8207674 100644 --- a/src/stores/components.ts +++ b/src/stores/components.ts @@ -6,8 +6,8 @@ import { DataType } from '../datatypes'; import { ALL_LENSES } from '../lenses'; import { ALL_WIDGETS } from '../widgets'; -export function isLensCompatible( - view: Lens, +export function isLensCompatible( + view: Lens, types: DataType[], canEdit: boolean ): boolean { @@ -65,7 +65,8 @@ export function registerWidget(widget: Widget) { } ALL_WIDGETS.forEach(registerWidget); -export function registerLens(lens: Lens) { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function registerLens(lens: Lens) { useComponentsStore.setState((state) => { const lensesByKey = { ...state.lensesByKey, [lens.key]: lens }; return {