From 2ad6f69a1e4fff60c324c6962123d13ff8ca05cf Mon Sep 17 00:00:00 2001 From: Ivan S Glazunov Date: Sat, 21 Sep 2024 18:24:59 +0300 Subject: [PATCH] 0.0.115 --- imports/editor.tsx | 20 +++++++++++++++++++- imports/go.tsx | 5 +++-- package.json | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/imports/editor.tsx b/imports/editor.tsx index d0a8dbc..519bba3 100644 --- a/imports/editor.tsx +++ b/imports/editor.tsx @@ -80,6 +80,14 @@ export const Editor = React.memo(function Editor({ const [v, setV] = useState(value); const { colorMode } = useColorMode(); const [lang, setLang] = useState(langs.tsx()); + const { data: [ObjectedValue] } = deep.useQuery(linkId ? { + type_id: deep.idLocal('@deep-foundation/core', 'Value'), + to_id: deep.idLocal('@deep-foundation/core', 'Object'), + from: { + typed: { id: linkId }, + }, + } : {}, { skip: !linkId }); + const isObject = !!ObjectedValue; const _refEditor = useRef(); const eref = refEditor || _refEditor @@ -91,7 +99,17 @@ export const Editor = React.memo(function Editor({ const { data: [link] } = useLoad({ id: linkId }); const update = useCallback(async () => { - if (linkId && v?.length > 0) await deep.value(linkId, v); + if (linkId && v?.length > 0) { + let _v = v; + if (isObject) { + try { + _v = JSON.parse(v); + await deep.value(linkId, _v); + } catch(e) { + console.log('go.Editor JSON.parse value', e); + } + } else await deep.value(linkId, _v); + } onSave && onSave(v) }, [link, v]); diff --git a/imports/go.tsx b/imports/go.tsx index f7e2cdd..d09e182 100644 --- a/imports/go.tsx +++ b/imports/go.tsx @@ -642,10 +642,10 @@ export const noScrollBar = ((s) => ({ const componentTemplate = ({ children } = { children: null }) => `({ deep, data, require, Go }) => { const React = require('react'); + const c = require('@chakra-ui/react'); const dc = '@deep-foundation/core'; const dpl = '@deep-foundation/perception-links'; - const c = require('@chakra-ui/react'); return ({ go, @@ -847,7 +847,7 @@ const Input = React.memo(({ ...props }: { path: [DeepClientStartItem | QueryLink, ...DeepClientPathItem[]], - insert: any; + insert?: any; title?: any; type?: 'string' | 'number'; @@ -890,6 +890,7 @@ const Input = React.memo(({ setSaving(true); if (!link && !insertedRef.current) { insertedRef.current = true; + if (!insert) return; const { data: [inserted] } = await deep.insert({ containerId, name, [type]: type === 'number' ? +v : v, diff --git a/package.json b/package.json index ea8b0b1..a1a2e65 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@deep-foundation/perception-imports", - "version": "0.0.114", + "version": "0.0.115", "license": "Unlicense", "type": "module", "main": "import.js",