diff --git a/.gitignore b/.gitignore index ece2d46..33f510e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ node_modules .env .DS_Store undefined -.vscode \ No newline at end of file +.vscode +data.json diff --git a/package.json b/package.json index b197fb9..ef61587 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "make.md", "main": "main.js", "scripts": { - "dev": "nnode esbuild.config.mjs", + "dev": "node esbuild.config.mjs", "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", "preview": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs preview", "demo": "&& node esbuild.config.mjs demo", diff --git a/src/core/react/components/Explorer/PropertiesView.tsx b/src/core/react/components/Explorer/PropertiesView.tsx index ac9c1eb..46bfbfb 100644 --- a/src/core/react/components/Explorer/PropertiesView.tsx +++ b/src/core/react/components/Explorer/PropertiesView.tsx @@ -86,7 +86,8 @@ export const PropertiesView = (props: { ]).filter((f) => !columns.some((g) => g.name == f)); const cols: SpaceTableColumn[] = fmKeys.map( (f) => - tableData?.cols?.find((g) => g.name == f) ?? { + tableData?.cols?.find((g) => g.name == f) ?? + columns.find((g) => g.name == f) ?? { table: "", name: f, schemaId: "", @@ -96,7 +97,8 @@ export const PropertiesView = (props: { if (properties) { newCols.push(...cols); fmKeys.forEach((c) => { - newValues[c] = parseProperty(c, properties[c]); + const colType = cols.find((col) => col.name == c)?.type; + newValues[c] = parseProperty(c, properties[c], colType); }); } @@ -128,20 +130,34 @@ export const PropertiesView = (props: { } }; + const pathChanged = (payload: { path: string }) => { + if (payload.path == pathState?.path) { + refreshData(); + } + }; + useEffect(() => { refreshData(); props.superstate.eventsDispatcher.addListener( "contextStateUpdated", mdbChanged ); + props.superstate.eventsDispatcher.addListener( + "pathStateUpdated", + pathChanged + ); return () => { props.superstate.eventsDispatcher.removeListener( "contextStateUpdated", mdbChanged ); + props.superstate.eventsDispatcher.removeListener( + "pathStateUpdated", + pathChanged + ); }; - }, [props.spaces, tableData]); + }, [props.spaces, tableData, pathState]); const savePropertyValue = (value: string, f: SpaceTableColumn) => { if (saveProperty) { const property = tableData?.cols?.find((g) => g.name == f.name); diff --git a/src/core/react/components/SpaceView/Contexts/DataTypeView/OptionCell.tsx b/src/core/react/components/SpaceView/Contexts/DataTypeView/OptionCell.tsx index a244844..d718950 100644 --- a/src/core/react/components/SpaceView/Contexts/DataTypeView/OptionCell.tsx +++ b/src/core/react/components/SpaceView/Contexts/DataTypeView/OptionCell.tsx @@ -66,11 +66,11 @@ export const OptionCell = ( .map((t, index) => ({ ...t, color: editable - ? schemeColors + ? t.color?.length > 0 + ? t.color // Use individual option color if set + : schemeColors ? schemeColors[index % schemeColors.length]?.value || "var(--mk-color-none)" - : t.color?.length > 0 - ? t.color : undefined : undefined, removeable: editable ? editMode >= CellEditMode.EditModeView : false, @@ -155,7 +155,7 @@ export const OptionCell = ( } else { props.saveOptions( serializeOptionValue(newOptions, parsedValue), - serializeMultiDisplayString(newValues) + newValues[0] ?? "" ); } }; @@ -168,7 +168,7 @@ export const OptionCell = ( } else { props.saveOptions( serializeOptionValue(options, parsedValue), - serializeMultiDisplayString(value) + value[0] ?? "" ); } }; diff --git a/src/core/react/components/UI/Menus/contexts/PropertyValue.tsx b/src/core/react/components/UI/Menus/contexts/PropertyValue.tsx index 77bc6d9..ee98931 100644 --- a/src/core/react/components/UI/Menus/contexts/PropertyValue.tsx +++ b/src/core/react/components/UI/Menus/contexts/PropertyValue.tsx @@ -444,10 +444,11 @@ export const PropertyValueComponent = (props: { const options = parseOptions(parsedValue.options ?? []); const saveOptionsHandler = (newOptions: SelectOption[], colorScheme?: string) => { - saveParsedValue("options", newOptions); + const updated: Record = { ...parsedValue, options: newOptions }; if (colorScheme !== undefined) { - saveParsedValue("colorScheme", colorScheme); + updated.colorScheme = colorScheme; } + props.saveValue(JSON.stringify(updated)); }; props.superstate.ui.openModal( diff --git a/src/core/react/components/UI/Modals/EditOptionsModal.tsx b/src/core/react/components/UI/Modals/EditOptionsModal.tsx index ef3e72f..a1e78ea 100644 --- a/src/core/react/components/UI/Modals/EditOptionsModal.tsx +++ b/src/core/react/components/UI/Modals/EditOptionsModal.tsx @@ -78,13 +78,17 @@ const SortableOptionItem: React.FC = ({ e.preventDefault(); // Always show color picker menu regardless of color scheme - showColorPickerMenu( + const menu = showColorPickerMenu( superstate, (e.target as HTMLElement).getBoundingClientRect(), windowFromDocument(e.view.document), option.color || "var(--mk-color-none)", (color: string) => { onEdit({ ...option, color }); + // Auto-close menu after color selection + if (menu) { + menu.hide(); + } } ); }; diff --git a/src/core/utils/contexts/linkContextRow.ts b/src/core/utils/contexts/linkContextRow.ts index edd8a6a..1119d1a 100644 --- a/src/core/utils/contexts/linkContextRow.ts +++ b/src/core/utils/contexts/linkContextRow.ts @@ -91,7 +91,10 @@ const resolvedPath = resolvePath(_row[PathPropertyName], path?.path, (spacePath) const frontmatter = (paths.get(resolvedPath)?.metadata?.property ?? {}); - const filteredFrontmatter = Object.keys(frontmatter).filter(f => fields.some(g => g.name == f) && f != PathPropertyName).reduce((p, c) => ({ ...p, [c]: parseProperty(c, frontmatter[c]) }), {}) + const filteredFrontmatter = Object.keys(frontmatter).filter(f => fields.some(g => g.name == f) && f != PathPropertyName).reduce((p, c) => { + const fieldType = fields.find(f => f.name == c)?.type; + return { ...p, [c]: parseProperty(c, frontmatter[c], fieldType) }; + }, {}) const tagData : Record = {}; const tagField = fields.find(f => f.name?.toLowerCase() == 'tags'); diff --git a/src/utils/parsers.ts b/src/utils/parsers.ts index 67fa122..55e76c8 100644 --- a/src/utils/parsers.ts +++ b/src/utils/parsers.ts @@ -105,10 +105,16 @@ export const parseMultiString = (str: string): string[] => ensureString(str).sta break; case "text": case "tag": - case "option": case "image": return value; break; + case "option": + // Handle case where option value is an array (from frontmatter) + if (Array.isArray(value)) { + return value[0] ?? ""; + } + return value; + break; } return ""; }; diff --git a/src/utils/properties.ts b/src/utils/properties.ts index 252ee38..20a4085 100644 --- a/src/utils/properties.ts +++ b/src/utils/properties.ts @@ -146,6 +146,11 @@ export const parseMDBStringValue = (type: string, value: string, frontmatter?: b ); } else if (type.includes("link") || type.includes("context")) { return frontmatter ? `[[${value}]]` : value; + } else if (type == "option" && frontmatter) { + // Parse option values when saving to frontmatter + // If it's a JSON array string, parse it to get the single value + const parsed = parseMultiString(value); + return parsed.length === 1 ? parsed[0] : (parsed.length > 1 ? parsed : value); } return value; }; diff --git a/tsconfig.json b/tsconfig.json index c96f121..5d54678 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "inlineSources": true, "isolatedModules": true, "module": "ESNext", - "target": "es6", + "target": "es2020", "allowJs": true, "alwaysStrict": true, "noImplicitAny": true,