From 929edf81d4d03fb7e035ffdebdabfeb8037bb96e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20G=C3=B3mez=20Bermejo?= Date: Wed, 22 Feb 2023 20:12:28 +0100 Subject: [PATCH 1/7] depracate engine --- src/services/EditEngineService.ts | 46 ++++++++++--------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/src/services/EditEngineService.ts b/src/services/EditEngineService.ts index da2cdac8..4ff92b03 100644 --- a/src/services/EditEngineService.ts +++ b/src/services/EditEngineService.ts @@ -1,6 +1,6 @@ import { RowDataType, TableColumn } from "cdm/FolderModel"; import { LocalSettings } from "cdm/SettingsModel"; -import { requireApiVersion, TFile } from "obsidian"; +import { TFile } from "obsidian"; import { LOGGER } from "services/Logger"; import { ParseService } from "services/ParseService"; import { InputType, UpdateRowOptions } from "helpers/Constants"; @@ -10,7 +10,6 @@ import { EditionError, showDBError } from "errors/ErrorTypes"; import obtainRowDatabaseFields from "IO/md/FileToRowDatabaseFields"; import { EditArguments } from "cdm/ServicesModel"; import NoteContentActionBuilder from "patterns/builders/NoteContentActionBuilder"; -import { parseFrontmatterFieldsToString } from "IO/md/RowDatabaseFieldsToFile"; import { hasFrontmatter } from "helpers/VaultManagement"; import { ValueOf } from "typings/base"; import { RowDatabaseFields } from "cdm/DatabaseModel"; @@ -225,42 +224,27 @@ class EditEngine { const { file, columnId, - content, ddbbConfig, - contentHasFrontmatter, rowFields, deletedColumn, newKey } = context; - if (requireApiVersion("1.1.1")) { - await app.fileManager.processFrontMatter(file, (frontmatter) => { - if (newKey) { - frontmatter[newKey] = frontmatter[deletedColumn]; - } else { - frontmatter[columnId] = ParseService.parseLiteral( - rowFields.frontmatter[columnId], - InputType.MARKDOWN, - ddbbConfig - ); - } + await app.fileManager.processFrontMatter(file, (frontmatter) => { + if (newKey) { + frontmatter[newKey] = frontmatter[deletedColumn]; + } else { + frontmatter[columnId] = ParseService.parseLiteral( + rowFields.frontmatter[columnId], + InputType.MARKDOWN, + ddbbConfig + ); + } - if (deletedColumn) { - delete frontmatter[deletedColumn]; - } - }); - } else { - const frontmatterGroupRegex = contentHasFrontmatter ? /^---[\s\S]+?---\n*/g : /(^[\s\S]*$)/g; - const frontmatterFieldsText = parseFrontmatterFieldsToString(rowFields, ddbbConfig, deletedColumn); - const newContent = contentHasFrontmatter ? `${frontmatterFieldsText}\n` : `${frontmatterFieldsText ? frontmatterFieldsText.concat('\n') : frontmatterFieldsText}$1`; - const builder = new NoteContentActionBuilder() - .setContent(content) - .setFile(file) - .addRegExp(frontmatterGroupRegex) - .addRegExpNewValue(newContent) - .build(); - await VaultManagerDB.editNoteContent(builder); - } + if (deletedColumn) { + delete frontmatter[deletedColumn]; + } + }); } /******************************************************************************************* From c5f77ce1a8c4914eb975af244fe37e78d30ff427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20G=C3=B3mez=20Bermejo?= Date: Wed, 22 Feb 2023 20:22:02 +0100 Subject: [PATCH 2/7] code smells --- src/api/obsidian-projects-api.ts | 2 +- src/helpers/Constants.ts | 2 +- src/services/FormulaService.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/obsidian-projects-api.ts b/src/api/obsidian-projects-api.ts index 10f117f4..9bfc1606 100644 --- a/src/api/obsidian-projects-api.ts +++ b/src/api/obsidian-projects-api.ts @@ -15,7 +15,7 @@ import { CustomView } from "views/AbstractView"; const projectsMetadataColumns = ["File", "name", "path"]; class ProjectAPI extends ProjectView { - private ignoreDataAutoReload: boolean = false; + private ignoreDataAutoReload = false; private plugin: DBFolderPlugin; private view: CustomView; diff --git a/src/helpers/Constants.ts b/src/helpers/Constants.ts index a4e25d4a..f87fb922 100644 --- a/src/helpers/Constants.ts +++ b/src/helpers/Constants.ts @@ -447,7 +447,7 @@ export const WRAPPERER_KEY = `_\\*~\``; export const INLINE_REGEX = Object.freeze({ INLINE_WITHOUT_FRONTMATTER: /(^[\s\S]*$)/g, INLINE_WITH_FRONTMATTER: /(^---[\s\S]+?---)+([\s\S]*$)/g, - INLINE_LAST_FIELD: /([\s\S]*)(^[^_*~`a-zA-Z1-9\[\(]*)([\[\(]{0,1})([_*~`]{0,2})([A-Za-z0-9]+)([_*~`]{0,2})([:]{2})([^\]\)\n]+)([\]\)]{0,1})(.*$)(\n{0,1})([\s\S]*)/gm + INLINE_LAST_FIELD: /([\s\S]*)(^[^_*~`a-zA-Z1-9[(]*)([[(]{0,1})([_*~`]{0,2})([A-Za-z0-9]+)([_*~`]{0,2})([:]{2})([^\])\n]+)([\])]{0,1})(.*$)(\n{0,1})([\s\S]*)/gm }); /****************************************************************************** diff --git a/src/services/FormulaService.ts b/src/services/FormulaService.ts index be03f1b4..f48ddc30 100644 --- a/src/services/FormulaService.ts +++ b/src/services/FormulaService.ts @@ -3,7 +3,7 @@ import { DbInfo } from "cdm/TableStateInterface"; import Rollup from "lib/Rollup"; import { Link, Literal } from "obsidian-dataview"; import { LOGGER } from "./Logger"; -; + class FormulaServiceInstance { private static instance: FormulaServiceInstance; From 8e10ba4466864dd2ebab79e594aaa8a5a522c8cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20G=C3=B3mez=20Bermejo?= Date: Wed, 22 Feb 2023 20:46:43 +0100 Subject: [PATCH 3/7] quotes to stings --- src/IO/md/RowDatabaseFieldsToFile.ts | 1 + src/services/parseServiceHelpers/MarkdownParser.ts | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/IO/md/RowDatabaseFieldsToFile.ts b/src/IO/md/RowDatabaseFieldsToFile.ts index e4ad4b37..13b5e17b 100644 --- a/src/IO/md/RowDatabaseFieldsToFile.ts +++ b/src/IO/md/RowDatabaseFieldsToFile.ts @@ -5,6 +5,7 @@ import { Literal } from "obsidian-dataview"; import { DateTime } from "luxon"; import { DataviewService } from "services/DataviewService"; import { ParseService } from "services/ParseService"; + export const parseFrontmatterFieldsToString = (databaseFields: RowDatabaseFields, localSettings: LocalSettings, deletedColumn?: string): string => { const frontmatterFields = databaseFields.frontmatter; let array: string[] = []; diff --git a/src/services/parseServiceHelpers/MarkdownParser.ts b/src/services/parseServiceHelpers/MarkdownParser.ts index 5ab1287b..c309586e 100644 --- a/src/services/parseServiceHelpers/MarkdownParser.ts +++ b/src/services/parseServiceHelpers/MarkdownParser.ts @@ -48,6 +48,9 @@ class MarkdownParser extends TypeParser { auxMarkdown = wrapped.value; } break; + case 'string': + auxMarkdown = this.wrapWithQuotes(wrapped.value); + break; default: auxMarkdown = wrapped.value?.toString().trim(); } @@ -79,7 +82,7 @@ class MarkdownParser extends TypeParser { private wrapWithQuotes(value: string): string { value = value.replaceAll(`\\`, ``); value = value.replaceAll(`"`, `\\"`); - return `"${value}"`; + return `"${value?.toString().trim()}"`; } } From 8dbbab97e1bde641a8ffcd5f278008b98d473d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20G=C3=B3mez=20Bermejo?= Date: Wed, 22 Feb 2023 22:46:43 +0100 Subject: [PATCH 4/7] regresion qoute wrapper --- .../cellTypes/Editor/RelationEditor.tsx | 19 +++++++++++++++---- .../parseServiceHelpers/MarkdownParser.ts | 2 -- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/components/cellTypes/Editor/RelationEditor.tsx b/src/components/cellTypes/Editor/RelationEditor.tsx index 9c9b3065..843652cb 100644 --- a/src/components/cellTypes/Editor/RelationEditor.tsx +++ b/src/components/cellTypes/Editor/RelationEditor.tsx @@ -1,15 +1,15 @@ import { RelationEditorComponentProps, SelectValue } from "cdm/ComponentsModel"; import React, { useEffect } from "react"; import { useState } from "react"; -import Select from "react-select"; import CustomTagsStyles from "components/styles/TagsStyles"; import { c } from "helpers/StylesHelper"; import { obtainInfoFromRelation } from "helpers/RelationHelper"; import { TableColumn } from "cdm/FolderModel"; import { Link } from "obsidian-dataview"; -import { OnChangeValue } from "react-select"; +import { ActionMeta, OnChangeValue } from "react-select"; import { StyleVariables } from "helpers/Constants"; import ClickAwayListener from "@mui/material/ClickAwayListener"; +import CreatableSelect from "react-select/creatable"; const RelationEditor = (props: RelationEditorComponentProps) => { const { defaultCell, persistChange, relationCell } = props; @@ -28,7 +28,18 @@ const RelationEditor = (props: RelationEditorComponentProps) => { const [relationOptions, setRelationOptions] = useState([]); // onChange handler - const handleOnChange = async (newValue: OnChangeValue) => { + const handleOnChange = async ( + newValue: OnChangeValue, + actionMeta: ActionMeta + ) => { + switch (actionMeta.action) { + case "create-option": + console.log(`Created: ${actionMeta.option}`); + break; + default: + // Do nothing + } + const arrayTags = newValue.map((tag) => ({ label: tag.label, value: tag.value, @@ -63,7 +74,7 @@ const RelationEditor = (props: RelationEditorComponentProps) => { return (
-