diff --git a/package.json b/package.json index 0ada08f7..af79b992 100644 --- a/package.json +++ b/package.json @@ -251,6 +251,16 @@ "outputType": { "type": "string", "description": "The type of output for the editor panel. Can be used to change it to 'markdown' for example" + }, + "type": { + "type": "string", + "default": "article", + "enum": [ + "article", + "mediaFolder", + "mediaFile" + ], + "description": "The type for which the script will be used." } }, "additionalProperties": false, diff --git a/src/commands/Dashboard.ts b/src/commands/Dashboard.ts index 148b596f..13950633 100644 --- a/src/commands/Dashboard.ts +++ b/src/commands/Dashboard.ts @@ -1,10 +1,10 @@ -import { SETTINGS_CONTENT_STATIC_FOLDER, SETTING_DATE_FIELD, SETTING_SEO_DESCRIPTION_FIELD, SETTINGS_DASHBOARD_OPENONSTART, SETTINGS_DASHBOARD_MEDIA_SNIPPET, SETTING_TAXONOMY_CONTENT_TYPES, DefaultFields, HOME_PAGE_NAVIGATION_ID, ExtensionState, COMMAND_NAME, SETTINGS_FRAMEWORK_ID, SETTINGS_CONTENT_DRAFT_FIELD, SETTINGS_CONTENT_SORTING, CONTEXT } from '../constants'; +import { SETTINGS_CONTENT_STATIC_FOLDER, SETTING_DATE_FIELD, SETTING_SEO_DESCRIPTION_FIELD, SETTINGS_DASHBOARD_OPENONSTART, SETTINGS_DASHBOARD_MEDIA_SNIPPET, SETTING_TAXONOMY_CONTENT_TYPES, DefaultFields, HOME_PAGE_NAVIGATION_ID, ExtensionState, COMMAND_NAME, SETTINGS_FRAMEWORK_ID, SETTINGS_CONTENT_DRAFT_FIELD, SETTINGS_CONTENT_SORTING, CONTEXT, SETTING_CUSTOM_SCRIPTS } from '../constants'; import { ArticleHelper } from './../helpers/ArticleHelper'; import { basename, dirname, extname, join, parse } from "path"; import { existsSync, readdirSync, statSync, unlinkSync, writeFileSync } from "fs"; import { commands, Uri, ViewColumn, Webview, WebviewPanel, window, workspace, env, Position } from "vscode"; import { Settings as SettingsHelper } from '../helpers'; -import { DraftField, Framework, SortingSetting, SortOrder, SortType, TaxonomyType } from '../models'; +import { CustomScript as ICustomScript, DraftField, Framework, ScriptType, SortingSetting, SortOrder, SortType, TaxonomyType } from '../models'; import { Folders } from './Folders'; import { DashboardCommand } from '../dashboardWebView/DashboardCommand'; import { DashboardMessage } from '../dashboardWebView/DashboardMessage'; @@ -28,6 +28,7 @@ import { ContentType } from '../helpers/ContentType'; import { SortingOption } from '../dashboardWebView/models'; import { Sorting } from '../helpers/Sorting'; import imageSize from 'image-size'; +import { CustomScript } from '../helpers/CustomScript'; export class Dashboard { private static webview: WebviewPanel | null = null; @@ -203,6 +204,9 @@ export class Dashboard { case DashboardMessage.setFramework: Dashboard.setFramework(msg?.data); break; + case DashboardMessage.runCustomScript: + CustomScript.run(msg?.data?.script, msg?.data?.path); + break; case DashboardMessage.setState: if (msg?.data?.key && msg?.data?.value) { Extension.getInstance().setState(msg?.data?.key, msg?.data?.value, "workspace"); @@ -300,6 +304,7 @@ export class Dashboard { contentFolders: Folders.get(), crntFramework: SettingsHelper.get(SETTINGS_FRAMEWORK_ID), framework: (!isInitialized && wsFolder) ? FrameworkDetector.get(wsFolder.fsPath) : null, + scripts: (SettingsHelper.get(SETTING_CUSTOM_SCRIPTS) || []).filter(s => s.type && s.type !== ScriptType.Article), dashboardState: { contents: { sorting: await ext.getState(ExtensionState.Dashboard.Contents.Sorting, "workspace") diff --git a/src/dashboardWebView/DashboardMessage.ts b/src/dashboardWebView/DashboardMessage.ts index 46ecabcd..23dc81de 100644 --- a/src/dashboardWebView/DashboardMessage.ts +++ b/src/dashboardWebView/DashboardMessage.ts @@ -20,4 +20,5 @@ export enum DashboardMessage { createMediaFolder = 'createMediaFolder', setFramework = 'setFramework', setState = 'setState', + runCustomScript = 'runCustomScript', } \ No newline at end of file diff --git a/src/dashboardWebView/components/Media/Item.tsx b/src/dashboardWebView/components/Media/Item.tsx index de4e8350..b0993aad 100644 --- a/src/dashboardWebView/components/Media/Item.tsx +++ b/src/dashboardWebView/components/Media/Item.tsx @@ -1,11 +1,13 @@ import { Messenger } from '@estruyf/vscode/dist/client'; -import { ClipboardCopyIcon, CodeIcon, PencilIcon, PhotographIcon, PlusCircleIcon, TrashIcon } from '@heroicons/react/outline'; +import { ClipboardCopyIcon, CodeIcon, PencilIcon, PhotographIcon, PlayIcon, PlusCircleIcon, TrashIcon } from '@heroicons/react/outline'; import { basename, dirname } from 'path'; import * as React from 'react'; import { useEffect } from 'react'; import { useRecoilState, useRecoilValue } from 'recoil'; import { CompressIcon } from '../../../components/icons/CompressIcon'; +import { CustomScript } from '../../../helpers/CustomScript'; import { parseWinPath } from '../../../helpers/parseWinPath'; +import { ScriptType } from '../../../models'; import { MediaInfo } from '../../../models/MediaPaths'; import { DashboardMessage } from '../../DashboardMessage'; import { LightboxAtom, PageSelector, SelectedMediaFolderSelector, SettingsSelector, ViewDataSelector } from '../../state'; @@ -62,6 +64,11 @@ export const Item: React.FunctionComponent = ({media}: React.PropsWi Messenger.send(DashboardMessage.copyToClipboard, parseWinPath(relPath) || ""); }; + const runCustomScript = (script: CustomScript) => { + const relPath = getRelPath(); + Messenger.send(DashboardMessage.runCustomScript, {script, path: relPath}); + }; + const insertToArticle = () => { const relPath = getRelPath(); Messenger.send(DashboardMessage.insertPreviewImage, { @@ -225,6 +232,19 @@ export const Item: React.FunctionComponent = ({media}: React.PropsWi Copy media path + + { + (settings?.scripts || []).filter(script => script.type === ScriptType.MediaFile).map(script => ( + + )) + } +