From c4b3dde110abb8a39a2fc635db38835bb8217c6d Mon Sep 17 00:00:00 2001 From: Ege Korkan Date: Wed, 2 Oct 2024 13:25:04 +0200 Subject: [PATCH] fix: add checks for at type being an array --- packages/web/src/scripts/editor.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/web/src/scripts/editor.js b/packages/web/src/scripts/editor.js index ed53c272..c8e2337e 100644 --- a/packages/web/src/scripts/editor.js +++ b/packages/web/src/scripts/editor.js @@ -288,7 +288,7 @@ export function createIde(ideNumber, exampleValue) { newIde.classList.add("active") //Create the new tab depending if its a TM or TD - if (defaultValue["@type"] === "tm:ThingModel") { + if ( (defaultValue["@type"] === "tm:ThingModel") || (defaultValue["@type"].indexOf("tm:ThingModel") > 0) { createTab(ideNumber, defaultValue["title"], "TM") } else { @@ -340,7 +340,7 @@ async function initEditor(ideNumber, editorValue, editorLanguage) { //Only use the spell checker if file is json if (editorValues[0] === "json") { //Get if thing type and set the respective schema - if (editorValues[2]["@type"] === "tm:ThingModel") { + if ( (editorValues[2]["@type"] === "tm:ThingModel") || (editorValues[2]["@type"].indexOf("tm:ThingModel") > 0) { // Configure JSON language support with schemas and schema associations languages.json.jsonDefaults.setDiagnosticsOptions({ validate: true, @@ -409,7 +409,12 @@ function markTypos(model) { export function getEditorData(editorInstance) { const formatType = editorInstance["_domElement"].dataset.modeId const editorContent = formatType === "json" ? JSON.parse(editorInstance.getValue()) : JSON.parse(convertTDYamlToJson(editorInstance.getValue())) - const thingType = editorContent["@type"] === "tm:ThingModel" ? "tm" : "td" + let thingType = "td" + if ( (editorContent["@type"] === "tm:ThingModel") || (editorContent.indexOf("tm:ThingModel") > 0) { + thingType = "tm" + } else { + thingType = "td" + } return [formatType, thingType, editorContent] } @@ -520,4 +525,4 @@ function updateTabName(docTitle) { tab.children[1].textContent = docTitle } }) -} \ No newline at end of file +}