Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGB committed Feb 23, 2024
2 parents a0d23ab + fb8d119 commit 377b7e6
Show file tree
Hide file tree
Showing 14 changed files with 370 additions and 282 deletions.
22 changes: 11 additions & 11 deletions WorkFlow Test/Workflow of new notes.canvas

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "zettelflow",
"name": "ZettelFlow",
"version": "2.3.0",
"version": "2.3.1",
"minAppVersion": "1.4.11",
"description": "Helps you to create and manage your notes in a Zettelkasten way via Canvas.",
"author": "RafaelGB",
Expand Down
493 changes: 258 additions & 235 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zettelflow",
"version": "2.3.0",
"version": "2.3.1",
"description": "A plugin for Obsidian that allows you to create and manage notes in a ZettelFlow-like way.",
"main": "main.js",
"scripts": {
Expand All @@ -15,25 +15,25 @@
"author": "RafaelGB",
"license": "MIT",
"devDependencies": {
"@types/node": "20.11.19",
"@types/react": "18.2.56",
"@types/node": "20.11.20",
"@types/react": "18.2.58",
"@types/react-dom": "18.2.19",
"@types/uuid": "9.0.8",
"@typescript-eslint/eslint-plugin": "7.0.1",
"@typescript-eslint/parser": "7.0.1",
"@typescript-eslint/eslint-plugin": "7.0.2",
"@typescript-eslint/parser": "7.0.2",
"builtin-modules": "3.3.0",
"codemirror": "6.0.1",
"esbuild": "0.20.0",
"esbuild-sass-plugin": "3.0.0",
"esbuild": "0.20.1",
"esbuild-sass-plugin": "3.1.0",
"eslint": "8.56.0",
"eslint-plugin-react": "7.33.2",
"jest": "29.7.0",
"obsidian": "1.4.11",
"obsidian": "1.5.7-1",
"ts-jest": "29.1.2",
"tslib": "2.6.2",
"typescript": "5.3.3",
"zustand": "4.5.1",
"sass": "1.71.0"
"sass": "1.71.1"
},
"dependencies": {
"@popperjs/core": "2.11.8",
Expand Down
23 changes: 19 additions & 4 deletions src/actions/calendar/CalendarAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { WrappedActionBuilderProps } from "application/components/noteBuilder";
import { calendarSettings } from "./CalendarSettings";
import { t } from "architecture/lang";
import { TypeService } from "architecture/typing";
import moment from "moment";

export class CalendarAction extends CustomZettelAction {
private static ICON = "calendar-days";
Expand All @@ -22,19 +23,33 @@ export class CalendarAction extends CustomZettelAction {

async execute(info: ExecuteInfo) {
const { content, element, context } = info;
const { result, key, zone, staticBehaviour, staticValue } = element;
const {
result,
key,
zone,
staticBehaviour,
staticValue,
enableTime,
format,
} = element;
// If the result is date, apply the daily format
const valueToSave = staticBehaviour ? staticValue : result;

if (TypeService.isString(key) && TypeService.isDate(valueToSave)) {
const defaultFormat = enableTime ? "YYYY-MM-DDTHH:mm:ss" : "YYYY-MM-DD";
const formattedValue = moment(valueToSave).format(
(format as string) || defaultFormat
);
switch (zone) {
case "body":
content.modify(key, valueToSave.toISOString());
content.modify(key, formattedValue);
break;
case "context":
context[key] = valueToSave;
context[key] = formattedValue;
break;
case "frontmatter":
default:
content.addFrontMatter({ [key]: valueToSave });
content.addFrontMatter({ [key]: formattedValue });
}
}
}
Expand Down
21 changes: 19 additions & 2 deletions src/actions/calendar/CalendarSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { ObsidianConfig } from "architecture/plugin";
import { v4 as uuid4 } from "uuid";

export const calendarSettings: ActionSetting = (contentEl, _, action) => {
const { key, label, zone, enableTime, staticBehaviour, staticValue } = action as CalendarElement;
const {
key, label, zone, enableTime, staticBehaviour, staticValue, format
} = action as CalendarElement;

const name = t('step_builder_element_type_calendar_title');
const description = t('step_builder_element_type_calendar_description');
Expand Down Expand Up @@ -47,7 +49,6 @@ export const calendarSettings: ActionSetting = (contentEl, _, action) => {
action.key = value;
});
});

});

new Setting(contentEl)
Expand All @@ -60,6 +61,7 @@ export const calendarSettings: ActionSetting = (contentEl, _, action) => {
action.label = value;
});
});

// Toggle to enable time
const dynamicId = uuid4();
new Setting(contentEl)
Expand All @@ -70,13 +72,28 @@ export const calendarSettings: ActionSetting = (contentEl, _, action) => {
.setValue(enableTime)
.onChange(async (value) => {
action.enableTime = value;
delete action.format;
const input = document.getElementById(dynamicId);
if (input) {
input.setAttribute('type', value ? 'datetime-local' : 'date');
}
});
});

// Format in function of the time is enabled or not
new Setting(contentEl)
.setName(t("step_builder_element_type_calendar_format_title"))
.setDesc(t("step_builder_element_type_calendar_format_description"))
.addText(text => {
const placeholder = enableTime ? 'YYYY-MM-DDTHH:MM' : 'YYYY-MM-DD';
text
.setValue(format || ``)
.setPlaceholder(placeholder)
.onChange(async (value) => {
action.format = value;
});
});

// Toggle to enable static behaviour
new Setting(contentEl)
.setName(t("step_builder_element_type_static_toggle_title"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ interface OptionsProviderProps {
}

const OptionsProvider: FC<OptionsProviderProps> = ({ action, children }) => {
const { options = [], defaultOption } = action;
const { options, defaultOption } = action;
const [defaultOptionState, setDefaultOptionState] = useState(defaultOption);
const [optionsState, setOptionsState] = useState(options);
const [optionsState, setOptionsState] = useState(options || []);

const swapOptions = (origin: number, dropped: number) => {
const newOptionsState = [...optionsState];
Expand Down Expand Up @@ -75,6 +75,9 @@ const OptionsProvider: FC<OptionsProviderProps> = ({ action, children }) => {

setOptionsState(newOptionsState);
// On disk
if (!action.options) {
action.options = [];
}
action.options.unshift([newKey, newLabel]);
};

Expand Down
31 changes: 17 additions & 14 deletions src/application/components/noteBuilder/callbacks/CallbackUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,25 @@ export async function manageElement(
})
.catch((error: ZettelError) => {
log.error(error);
switch (error.getType()) {
case ZettelError.WARNING_TYPE: {
new Notice(`Error building note: ${error.message}`);
manageWarningError(actions, error);
}
case ZettelError.FATAL_TYPE: {
new Notice(`Fatal error: ${error.message}`);
manageFatalError(actions, error);
break;
}
default: {
new Notice(`Not controlled error: ${error.message}`);
modal.close();
if (error! instanceof ZettelError) {
switch (error.getType()) {
case ZettelError.WARNING_TYPE: {
new Notice(`Warning error: ${error.message}`);
manageWarningError(actions, error);
}
case ZettelError.FATAL_TYPE: {
new Notice(`Fatal error: ${error.message}`);
manageFatalError(actions, error);
break;
}
default: {
new Notice(`Not controlled error: ${error.message}`);
modal.close();
}
}
} else {
new Notice(`Not controlled error: ${error}`);
}
actions.setInvalidTitle(true);
});
}
}
Expand Down
20 changes: 16 additions & 4 deletions src/application/notes/NoteBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,22 @@ export class NoteBuilder {
}

public async build(modal: SelectorMenuModal) {
if (modal.isEditor()) {
return await this.buildEditor(modal);
} else {
return await this.buildNewNote();
try {
if (modal.isEditor()) {
return await this.buildEditor(modal);
} else {
return await this.buildNewNote();
}
} catch (error) {
this.content.reset();
if (!modal.isEditor()) {
const potentialFile = await FileService.getFile(this.note.getFinalPath(), false);
// Check if the file was created and delete it
if (potentialFile) {
await FileService.deleteFile(potentialFile);
}
}
throw error;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/application/notes/model/ContentDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,10 @@ export class ContentDTO {
this.frontmatter = { ...this.frontmatter, ...frontmatter };
}
}

public reset() {
this.content = "";
this.frontmatter = {};
this.tags = [];
}
}
2 changes: 2 additions & 0 deletions src/architecture/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export default {
step_builder_element_type_calendar_label_description: 'The label will be the title of your calendar',
step_builder_element_type_calendar_toggle_time_title: 'Enable time',
step_builder_element_type_calendar_toggle_time_description: 'Enable or disable time in the calendar',
step_builder_element_type_calendar_format_title: 'Format of calendar',
step_builder_element_type_calendar_format_description: 'Choose the format of the calendar',
step_builder_element_type_selector_title: 'Element type selector',
step_builder_element_type_selector_description: 'Add options to your step that will be displayed in the menu of the action.',
step_builder_element_type_selector_label_title: 'Label of selector',
Expand Down
2 changes: 2 additions & 0 deletions src/architecture/lang/locale/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export default {
step_builder_element_type_calendar_label_description: 'La etiqueta será el título de tu calendario',
step_builder_element_type_calendar_toggle_time_title: 'Activar la opción de hora',
step_builder_element_type_calendar_toggle_time_description: 'Activa o desactiva la hora para tu calendario',
step_builder_element_type_calendar_format_title: 'Formato del calendario',
step_builder_element_type_calendar_format_description: 'Elige el formato para el calendario',
step_builder_element_type_selector_title: 'Acción de selector',
step_builder_element_type_selector_description: 'Añade opciones a tu paso que se mostrarán en el menú de la acción.',
step_builder_element_type_selector_label_title: 'Etiqueta del selector',
Expand Down
4 changes: 4 additions & 0 deletions src/architecture/plugin/services/FileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class FileService {
await ObsidianApi.workspace().openLinkText(path, "");
}

public static async deleteFile(file: TFile): Promise<void> {
await ObsidianApi.vault().delete(file);
}

public static async getFile(file_str: string, restrict = true): Promise<TFile | null> {
file_str = normalizePath(file_str);

Expand Down
1 change: 1 addition & 0 deletions src/zettelkasten/typing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type NumberElement = {

export type CalendarElement = {
enableTime: boolean,
format: string,
} & AditionBaseElement;

export type SelectorElement = {
Expand Down

0 comments on commit 377b7e6

Please sign in to comment.