mirror of
https://github.com/directus/directus.git
synced 2026-02-08 23:25:55 -05:00
Input code json (#9291)
* remove language selection for input code type JSON * lint as json when type is json Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { ExtensionsOptionsContext } from '@directus/shared/types';
|
||||
import { defineInterface } from '@directus/shared/utils';
|
||||
import CodeMirror from 'codemirror';
|
||||
import 'codemirror/mode/meta';
|
||||
@@ -37,43 +38,57 @@ export default defineInterface({
|
||||
types: ['string', 'json', 'text', 'geometry'],
|
||||
group: 'standard',
|
||||
preview: PreviewSVG,
|
||||
options: [
|
||||
{
|
||||
field: 'language',
|
||||
name: '$t:language',
|
||||
type: 'string',
|
||||
meta: {
|
||||
width: 'half',
|
||||
interface: 'select-dropdown',
|
||||
options: { choices },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'lineNumber',
|
||||
name: '$t:interfaces.input-code.line_number',
|
||||
type: 'boolean',
|
||||
meta: {
|
||||
width: 'half',
|
||||
interface: 'boolean',
|
||||
},
|
||||
schema: {
|
||||
default_value: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'template',
|
||||
name: '$t:template',
|
||||
type: 'text',
|
||||
meta: {
|
||||
width: 'full',
|
||||
interface: 'input-code',
|
||||
options: {
|
||||
placeholder: '$t:interfaces.input-code.placeholder',
|
||||
options: ({ field }: ExtensionsOptionsContext) => {
|
||||
const sharedOptions = [
|
||||
{
|
||||
field: 'lineNumber',
|
||||
name: '$t:interfaces.input-code.line_number',
|
||||
type: 'boolean',
|
||||
meta: {
|
||||
width: 'half',
|
||||
interface: 'boolean',
|
||||
},
|
||||
schema: {
|
||||
default_value: false,
|
||||
},
|
||||
},
|
||||
schema: {
|
||||
default_value: null,
|
||||
{
|
||||
field: 'template',
|
||||
name: '$t:template',
|
||||
type: 'text',
|
||||
meta: {
|
||||
width: 'full',
|
||||
interface: 'input-code',
|
||||
options: {
|
||||
placeholder: '$t:interfaces.input-code.placeholder',
|
||||
},
|
||||
},
|
||||
schema: {
|
||||
default_value: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
const defaultOptions = [
|
||||
{
|
||||
field: 'language',
|
||||
name: '$t:language',
|
||||
type: 'string',
|
||||
meta: {
|
||||
width: 'half',
|
||||
interface: 'select-dropdown',
|
||||
options: { choices },
|
||||
},
|
||||
},
|
||||
...sharedOptions,
|
||||
];
|
||||
|
||||
const jsonOptions = [...sharedOptions];
|
||||
|
||||
if (field?.type === 'json') {
|
||||
return jsonOptions;
|
||||
}
|
||||
|
||||
return defaultOptions;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -135,7 +135,7 @@ export default defineComponent({
|
||||
if (codemirror) {
|
||||
const lang = props.language.toLowerCase();
|
||||
|
||||
if (lang === 'json') {
|
||||
if (props.type === 'json' || lang === 'json') {
|
||||
// @ts-ignore
|
||||
await import('codemirror/mode/javascript/javascript.js');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user