Merge branch 'dev' into issue/666

This commit is contained in:
Elio Struyf
2024-02-13 09:13:50 +01:00
68 changed files with 1200 additions and 339 deletions
@@ -260,6 +260,7 @@ export const Item: React.FunctionComponent<IItemProps> = ({
ref={formRef}
snippetKey={snippetKey}
snippet={snippet}
filePath={viewData?.data?.filePath}
fieldInfo={viewData?.data?.snippetInfo?.fields}
selection={viewData?.data?.selection} />
</FormDialog>
@@ -1,8 +1,7 @@
import { Messenger } from '@estruyf/vscode/dist/client';
import { Messenger, messageHandler } from '@estruyf/vscode/dist/client';
import * as React from 'react';
import { useCallback, useEffect, useImperativeHandle, useMemo, useState } from 'react';
import { useRecoilValue } from 'recoil';
import { processKnownPlaceholders } from '../../../helpers/PlaceholderHelper';
import { SnippetParser } from '../../../helpers/SnippetParser';
import { Snippet, SnippetField, SnippetInfoField, SnippetSpecialPlaceholders } from '../../../models';
import { DashboardMessage } from '../../DashboardMessage';
@@ -14,6 +13,7 @@ export interface ISnippetFormProps {
snippetKey?: string;
snippet: Snippet;
selection: string | undefined;
filePath?: string;
fieldInfo?: SnippetInfoField[];
mediaData?: any;
onInsert?: (mediaData: any) => void;
@@ -24,7 +24,7 @@ export interface SnippetFormHandle {
}
const SnippetForm: React.ForwardRefRenderFunction<SnippetFormHandle, ISnippetFormProps> = (
{ snippetKey, snippet, selection, fieldInfo, mediaData, onInsert },
{ snippetKey, snippet, selection, filePath, fieldInfo, mediaData, onInsert },
ref
) => {
const viewData = useRecoilValue(ViewDataSelector);
@@ -41,20 +41,19 @@ const SnippetForm: React.ForwardRefRenderFunction<SnippetFormHandle, ISnippetFor
);
const insertPlaceholderValues = useCallback(
(value: SnippetSpecialPlaceholders) => {
async (value: SnippetSpecialPlaceholders) => {
if (value === 'FM_SELECTED_TEXT') {
return selection || '';
}
value = processKnownPlaceholders(
value = await messageHandler.request<string>(DashboardMessage.updateSnippetPlaceholders, {
value,
viewData?.data?.fileTitle || '',
settings?.date.format || ''
);
filePath
});
return value;
},
[selection]
[selection, filePath]
);
const insertValueFromMedia = useCallback(
@@ -128,7 +127,7 @@ ${snippetBody}
}
}));
useEffect(() => {
const processFields = useCallback(async () => {
// Get all placeholder variables from the snippet
const body = typeof snippet.body === 'string' ? snippet.body : snippet.body.join(`\n`);
@@ -147,7 +146,7 @@ ${snippetBody}
if (idx > -1) {
allFields.push({
...field,
value: insertPlaceholderValues(field.default || '')
value: await insertPlaceholderValues(field.default || '')
});
}
}
@@ -167,6 +166,10 @@ ${snippetBody}
}
setFields(allFields);
}, [snippet, insertPlaceholderValues, insertValueFromMedia]);
useEffect(() => {
processFields();
}, [snippet]);
return (