diff --git a/packages/nc-gui-v2/components/cell/Json.vue b/packages/nc-gui-v2/components/cell/Json.vue new file mode 100644 index 0000000000..b4fb09e740 --- /dev/null +++ b/packages/nc-gui-v2/components/cell/Json.vue @@ -0,0 +1,101 @@ + + + + + diff --git a/packages/nc-gui-v2/components/cell/JsonEditableCell.vue b/packages/nc-gui-v2/components/cell/JsonEditableCell.vue deleted file mode 100644 index f92bd346ca..0000000000 --- a/packages/nc-gui-v2/components/cell/JsonEditableCell.vue +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - - diff --git a/packages/nc-gui-v2/components/monaco/Editor.vue b/packages/nc-gui-v2/components/monaco/Editor.vue index 371b466590..a833718c64 100644 --- a/packages/nc-gui-v2/components/monaco/Editor.vue +++ b/packages/nc-gui-v2/components/monaco/Editor.vue @@ -7,14 +7,22 @@ import { onMounted } from '#imports' import { deepCompare } from '~/utils' interface Props { - modelValue: string - lang?: string - validate?: boolean + modelValue: any + hideMinimap?: boolean } -const { modelValue, lang = 'json', validate = true } = defineProps() +interface Emits { + (event: 'update:modelValue', model: any): void + (event: 'validationError', error: any): void + (event: 'valueChanged'): void +} + +const props = defineProps() +const emits = defineEmits() + +const { hideMinimap } = props -const emit = defineEmits(['update:modelValue']) +let vModel = $(useVModel(props, 'modelValue', emits)) const isValid = ref(true) @@ -48,14 +56,13 @@ defineExpose({ }) onMounted(() => { - if (root.value && lang) { - const model = monaco.editor.createModel(JSON.stringify(modelValue, null, 2), lang) - if (lang === 'json') { - // configure the JSON language support with schemas and schema associations - monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ - validate: validate as boolean, - }) - } + if (root.value) { + const model = monaco.editor.createModel(JSON.stringify(vModel, null, 2), 'json') + + // configure the JSON language support with schemas and schema associations + monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ + validate: true, + }) editor = monaco.editor.create(root.value, { model, @@ -68,22 +75,20 @@ onMounted(() => { }, tabSize: 2, automaticLayout: true, + minimap: { + enabled: !hideMinimap, + }, }) editor.onDidChangeModelContent(async (e) => { try { isValid.value = true - - const value = editor?.getValue() - if (typeof modelValue === 'object') { - if (!value || !deepCompare(modelValue, JSON.parse(value))) { - emit('update:modelValue', JSON.stringify(modelValue, null, 2)) - } - } else { - if (value !== modelValue) emit('update:modelValue', value) - } + const obj = JSON.parse(editor.getValue()) + emits('valueChanged') + if (!deepCompare(vModel, obj)) vModel = obj } catch (e) { isValid.value = false + emits('validationError', e) console.log(e) } }) @@ -91,17 +96,18 @@ onMounted(() => { }) watch( - () => modelValue, + () => vModel, (v) => { - if (editor && v) { - const value = editor?.getValue() - if (typeof v === 'object') { - if (!value || !deepCompare(v, JSON.parse(value))) { - editor.setValue(JSON.stringify(v, null, 2)) - } - } else { - if (value !== v) editor.setValue(v) + if (!editor || !v) { + return + } + + try { + if (!deepCompare(v, JSON.parse(editor?.getValue() as string))) { + editor.setValue(JSON.stringify(v, null, 2)) } + } catch (e) { + editor.setValue(JSON.stringify(v, null, 2)) } }, ) diff --git a/packages/nc-gui-v2/components/smartsheet/Cell.vue b/packages/nc-gui-v2/components/smartsheet/Cell.vue index 42d7b28f35..9f7793761a 100644 --- a/packages/nc-gui-v2/components/smartsheet/Cell.vue +++ b/packages/nc-gui-v2/components/smartsheet/Cell.vue @@ -130,6 +130,7 @@ const syncAndNavigate = (dir: NavigateDir) => { + diff --git a/packages/nc-gui-v2/components/smartsheet/Grid.vue b/packages/nc-gui-v2/components/smartsheet/Grid.vue index 542e0b8bd9..6a060b1d17 100644 --- a/packages/nc-gui-v2/components/smartsheet/Grid.vue +++ b/packages/nc-gui-v2/components/smartsheet/Grid.vue @@ -420,7 +420,6 @@ const onNavigate = (dir: NavigateDir) => { td { text-overflow: ellipsis; - white-space: nowrap; } td.active::after, diff --git a/packages/nc-gui-v2/package-lock.json b/packages/nc-gui-v2/package-lock.json index eab7b55eac..0588364b3a 100644 --- a/packages/nc-gui-v2/package-lock.json +++ b/packages/nc-gui-v2/package-lock.json @@ -28,6 +28,7 @@ }, "devDependencies": { "@antfu/eslint-config": "^0.25.2", + "@iconify-json/cil": "^1.1.2", "@iconify-json/clarity": "^1.1.4", "@iconify-json/eva": "^1.1.2", "@iconify-json/ic": "^1.1.7", @@ -990,6 +991,15 @@ "dev": true, "peer": true }, + "node_modules/@iconify-json/cil": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@iconify-json/cil/-/cil-1.1.2.tgz", + "integrity": "sha512-fu9x1f+A2H5qGWnApU1aw0EREAKqg5EP2Z6cWHV11XchlKgzY+jWQCalctkV+Jsef2M2m3C2DX/ukgyhMclIcw==", + "dev": true, + "dependencies": { + "@iconify/types": "*" + } + }, "node_modules/@iconify-json/clarity": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/@iconify-json/clarity/-/clarity-1.1.4.tgz", @@ -15502,6 +15512,15 @@ "dev": true, "peer": true }, + "@iconify-json/cil": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@iconify-json/cil/-/cil-1.1.2.tgz", + "integrity": "sha512-fu9x1f+A2H5qGWnApU1aw0EREAKqg5EP2Z6cWHV11XchlKgzY+jWQCalctkV+Jsef2M2m3C2DX/ukgyhMclIcw==", + "dev": true, + "requires": { + "@iconify/types": "*" + } + }, "@iconify-json/clarity": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/@iconify-json/clarity/-/clarity-1.1.4.tgz", diff --git a/packages/nc-gui-v2/package.json b/packages/nc-gui-v2/package.json index a03599eec8..5fa76f2658 100644 --- a/packages/nc-gui-v2/package.json +++ b/packages/nc-gui-v2/package.json @@ -34,6 +34,7 @@ }, "devDependencies": { "@antfu/eslint-config": "^0.25.2", + "@iconify-json/cil": "^1.1.2", "@iconify-json/clarity": "^1.1.4", "@iconify-json/eva": "^1.1.2", "@iconify-json/ic": "^1.1.7",