From 1fca4aa9465f736628ea11f1132e0be6ca96c619 Mon Sep 17 00:00:00 2001 From: VictorS67 <185000048@qq.com> Date: Mon, 24 Jun 2024 14:32:28 -0400 Subject: [PATCH] update electron in studio --- packages/app/.env | 2 +- packages/app/.gitignore | 1 + ...nfig-overrides.js => config-overrides.cjs} | 0 packages/app/electron/electron.ts | 19 +- packages/app/electron/tsconfig.json | 12 +- packages/app/package.json | 25 +- packages/app/public/index.html | 7 +- .../app/src/components/NodeContentBody.tsx | 6 +- .../hooks/useContextMenuNodeGraphHandler.ts | 34 +- packages/app/src/state/graph.ts | 4 +- packages/app/src/state/node.ts | 96 +++-- packages/app/src/types/studio.type.ts | 334 ++++++++++++------ packages/app/tsconfig.json | 12 +- packages/app/webpack.config.cjs | 40 +++ 14 files changed, 426 insertions(+), 166 deletions(-) rename packages/app/{config-overrides.js => config-overrides.cjs} (100%) create mode 100644 packages/app/webpack.config.cjs diff --git a/packages/app/.env b/packages/app/.env index 6b673d44..16ae5fe5 100644 --- a/packages/app/.env +++ b/packages/app/.env @@ -1,2 +1,2 @@ REACT_APP_ENV=local -ELECTRON_START_URL='http://localhost:3000' \ No newline at end of file +ELECTRON_START_URL='http://localhost:8080' \ No newline at end of file diff --git a/packages/app/.gitignore b/packages/app/.gitignore index 5229cc9e..f6ebd83b 100644 --- a/packages/app/.gitignore +++ b/packages/app/.gitignore @@ -10,6 +10,7 @@ # production /build +/dist # misc .DS_Store diff --git a/packages/app/config-overrides.js b/packages/app/config-overrides.cjs similarity index 100% rename from packages/app/config-overrides.js rename to packages/app/config-overrides.cjs diff --git a/packages/app/electron/electron.ts b/packages/app/electron/electron.ts index bebf8b6c..8517e8e1 100644 --- a/packages/app/electron/electron.ts +++ b/packages/app/electron/electron.ts @@ -1,4 +1,4 @@ -import { app, BrowserWindow } from "electron"; +import { app, BrowserWindow, ipcMain } from "electron"; import path from "path"; import url from "url"; @@ -26,7 +26,22 @@ function createWindow() { // ); // } - mainWindow.loadURL(process.env.ELECTRON_START_URL || "http://localhost:3000"); + mainWindow.loadURL(process.env.ELECTRON_START_URL || "http://localhost:8080"); + // mainWindow.loadFile(path.join(__dirname, "public", "index.html")); + + // ipcMain.handle("globalNodeRegistry", async (event, arg) => { + // const encre = await import("@encrejs/core"); + + // return encre.globalNodeRegistry; + // }); + + mainWindow.webContents.on("before-input-event", (_, input) => { + if (input.type === "keyDown" && input.key === "F12") { + mainWindow?.webContents.isDevToolsOpened() + ? mainWindow?.webContents.closeDevTools() + : mainWindow?.webContents.openDevTools({ mode: "left" }); + } + }); mainWindow.on("closed", () => { mainWindow = null; diff --git a/packages/app/electron/tsconfig.json b/packages/app/electron/tsconfig.json index fe4140ee..4671a7ab 100644 --- a/packages/app/electron/tsconfig.json +++ b/packages/app/electron/tsconfig.json @@ -2,12 +2,12 @@ "extends": "../tsconfig.json", "compilerOptions": { "noEmit": false, - "outDir": "../build/electron", + "outDir": "../dist/main", "rootDir": ".", - "module": "commonjs" - // "module": "ESNext", - // "moduleResolution": "node", - // "target": "ESNext" + "target": "ESNEXT", + "module": "ESNext", + "moduleResolution": "Node", + "esModuleInterop": true }, - "include": ["./**/*.ts"] + "include": ["electron.ts"] } diff --git a/packages/app/package.json b/packages/app/package.json index 19469145..8ffc04d7 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -5,9 +5,9 @@ "author": "Encre", "license": "MIT", "private": true, - "type": "commonjs", - "packageManager": "yarn@1.22.21", - "main": "build/electron/electron.js", + "type": "module", + "packageManager": "yarn@1.22.19", + "main": "./main/electron.js", "devDependencies": { "@atlaskit/eslint-plugin-design-system": "^4.11.2", "@babel/plugin-proposal-private-property-in-object": "^7.21.11", @@ -25,7 +25,8 @@ "@typescript-eslint/eslint-plugin": "^6.7.0", "@typescript-eslint/parser": "^6.7.0", "concurrently": "^8.2.1", - "electron": "^26.3.0", + "css-loader": "^7.1.2", + "electron": "^28.0.0", "eslint": "^8.49.0", "eslint-cjs-to-esm": "^2.2.0", "eslint-config-prettier": "^9.0.0", @@ -35,12 +36,16 @@ "eslint-plugin-n": "^16.1.0", "eslint-plugin-prettier": "^5.0.0", "eslint-plugin-promise": "^6.1.1", + "esm": "^3.2.25", "node-polyfill-webpack-plugin": "^4.0.0", "prettier": "^3.0.3", "react-app-rewired": "^2.2.1", "react-scripts": "5.0.1", "recoil-persist": "^5.1.0", - "wait-on": "^7.0.1" + "style-loader": "^4.0.0", + "ts-loader": "^9.5.1", + "wait-on": "^7.0.1", + "webpack-cli": "^5.1.4" }, "dependencies": { "@atlaskit/css-reset": "^6.5.4", @@ -79,6 +84,9 @@ "ws": "^8.14.1", "yaml": "^2.3.2" }, + "imports": { + "@encrejs/core": "./node_modules/@encrejs/core/*.js" + }, "scripts": { "start": "react-app-rewired start", "build": "react-scripts build", @@ -86,6 +94,11 @@ "eject": "react-scripts eject", "lint": "eslint src/**/*.{ts,tsx} --quiet --fix", "lint-fix": "eslint --fix src/**/*.{ts,tsx} src/**/**/*.{ts,tsx}", + "build:react": "webpack --config webpack.config.cjs", + "build:electron": "tsc -p electron/tsconfig.json", + "start:dev": "concurrently \"yarn start:react\" \"wait-on http://localhost:8000 && yarn start:electron\"", + "start:react": "webpack serve --config webpack.config.cjs --mode development", + "start:electron": "electron .", "electron-build": "tsc -p electron/tsconfig.json", "electron-start": "yarn electron-build && electron .", "electron-dev": "concurrently \"yarn start\" \"wait-on http://localhost:3000 && yarn electron-start\"" @@ -108,4 +121,4 @@ "last 1 safari version" ] } -} +} \ No newline at end of file diff --git a/packages/app/public/index.html b/packages/app/public/index.html index 300398bd..4755de6d 100644 --- a/packages/app/public/index.html +++ b/packages/app/public/index.html @@ -2,19 +2,19 @@ - + - + - + + diff --git a/packages/app/src/components/NodeContentBody.tsx b/packages/app/src/components/NodeContentBody.tsx index 20780b31..50638eb7 100644 --- a/packages/app/src/components/NodeContentBody.tsx +++ b/packages/app/src/components/NodeContentBody.tsx @@ -7,7 +7,7 @@ import { useRecoilValue } from 'recoil'; import { useStableCallback } from '../hooks/useStableCallback'; import { useUIContextDescriptors } from '../hooks/useUIContextDescriptors'; -import { nodeInstanceMapState } from '../state/node'; +import { nodeInstanceState } from '../state/node'; import { KnownNodeContentBodyProps, NodeContentBodyProps, @@ -35,7 +35,7 @@ const NodeContentBodyWrapper = styled.div<{ export const NodeContentBody: FC = memo( ({ node }: NodeContentBodyProps) => { - const nodeInstanceMap = useRecoilValue(nodeInstanceMapState); + const nodeInstance = useRecoilValue(nodeInstanceState(node.id)); const { isPending, @@ -44,7 +44,7 @@ export const NodeContentBody: FC = memo( isFetching, } = useQuery({ queryKey: ['nodeBody', node.id], - queryFn: () => nodeInstanceMap[node.id]?.getBody(), + queryFn: () => nodeInstance?.getBody(), }); if (isPending) return <>; diff --git a/packages/app/src/hooks/useContextMenuNodeGraphHandler.ts b/packages/app/src/hooks/useContextMenuNodeGraphHandler.ts index c55970f1..04778caa 100644 --- a/packages/app/src/hooks/useContextMenuNodeGraphHandler.ts +++ b/packages/app/src/hooks/useContextMenuNodeGraphHandler.ts @@ -20,6 +20,7 @@ import { showContextMenuState } from '../state/contextmenu'; import { collapsingNodeIdsState, nodeMapState, + nodeRegistryState, nodesState, pinningNodeIdsState, selectingNodeIdsState, @@ -28,7 +29,7 @@ import { connectionsState } from '../state/nodeconnection'; import { removeWireDataState, selectingWireIdsState } from '../state/wire'; import { ContextMenuConfigContextData } from '../types/contextmenu.type'; import { - globalNodeRegistry, + // globalNodeRegistry, GraphComment, Node, NodeBody, @@ -52,6 +53,7 @@ export function useContextMenuNodeGraphHandler() { const [selectingCommentIds, setSelectingCommentIds] = useRecoilState( selectingCommentIdsState, ); + const nodeRegistry = useRecoilValue(nodeRegistryState); const nodeMap = useRecoilValue(nodeMapState); const [selectingWireIds, setSelectingWireIds] = useRecoilState( selectingWireIdsState, @@ -168,22 +170,22 @@ export function useContextMenuNodeGraphHandler() { position: { x: number; y: number }, registerArgs?: Record, ) => { - const newNode: Node = globalNodeRegistry.createDynamic( - nodeType, - nodeSubType, - registerArgs, - ); - newNode.visualInfo = { - ...newNode.visualInfo, - position: { - ...newNode.visualInfo.position, - ...position, - }, - }; - - changeNodes?.([...nodes, newNode]); + if (nodeRegistry) { + const newNode: Node = nodeRegistry.createDynamic( + nodeType, + nodeSubType, + registerArgs, + ); + newNode.visualInfo = { + ...newNode.visualInfo, + position: { + ...newNode.visualInfo.position, + ...position, + }, + }; - // changeNodes?.([...nodes]); + changeNodes?.([...nodes, newNode]); + } }, ); diff --git a/packages/app/src/state/graph.ts b/packages/app/src/state/graph.ts index fcdcc27d..886aad1b 100644 --- a/packages/app/src/state/graph.ts +++ b/packages/app/src/state/graph.ts @@ -10,7 +10,7 @@ import myMp3 from '../assets/sunflower.mp3'; import myPng from '../assets/timetable.png'; import { NodeGraph } from '../types/graph.type'; import { - globalNodeRegistry, + // globalNodeRegistry, Node, NodeInputPortDef, NodeOutputPortDef, @@ -660,7 +660,7 @@ export const graphState = atom({ // throw new Error("Function not implemented."); // }, // }, - globalNodeRegistry.createDynamic('prompt', 'string'), + // globalNodeRegistry.createDynamic('prompt', 'string'), ], connections: [], comments: [ diff --git a/packages/app/src/state/node.ts b/packages/app/src/state/node.ts index 42b5aa7e..04f34feb 100644 --- a/packages/app/src/state/node.ts +++ b/packages/app/src/state/node.ts @@ -1,13 +1,13 @@ import type { NodeImpl } from '@encrejs/core/build/studio/nodes/base'; -import { mapValues } from 'lodash-es'; -import { DefaultValue, atom, selector, selectorFamily } from 'recoil'; +import { mapValues, keys, map } from "lodash-es"; +import { DefaultValue, atom, selector, selectorFamily } from "recoil"; -import { graphState } from './graph'; -import { connectionMapState } from './nodeconnection'; -import { NodeGraph } from '../types/graph.type'; -import { NodeVisualContentData } from '../types/node.type'; +import { graphState } from "./graph"; +import { connectionMapState } from "./nodeconnection"; +import { NodeGraph } from "../types/graph.type"; +import { NodeVisualContentData } from "../types/node.type"; import { - globalNodeRegistry, + // globalNodeRegistry, RecordId, CommentVisualInfo, GraphComment, @@ -15,7 +15,28 @@ import { NodeConnection, NodeInputPortDef, NodeOutputPortDef, -} from '../types/studio.type'; + NodeRegistration, +} from "../types/studio.type"; + +export const nodeRegistryState = atom({ + key: "nodeRegistryState", + default: selectorFamily({ + key: "nodeRegistryState/default", + get: () => async () => { + // const { ipcRenderer } = window.require('electron'); + // try { + // const globalNodeRegistry = + // await ipcRenderer.invoke('globalNodeRegistry'); + // return globalNodeRegistry; + // } catch (e) { + // console.log(`failed to get globalNodeRegistry: ${e}`); + // return undefined; + // } + + return undefined; + }, + })(undefined), +}); export const nodesState = selector({ key: 'nodes', @@ -45,21 +66,52 @@ export const nodeMapState = selector>({ }, }); +export const nodeInstanceState = selectorFamily< + NodeImpl | undefined, + RecordId +>({ + key: "nodeInstanceState", + get: (nodeId) => async () => { + // const { ipcRenderer } = window.require("electron"); + + // try { + // const globalNodeRegistry = await ipcRenderer.invoke("globalNodeRegistry"); + + // return globalNodeRegistry.createDynamicImpl(nodeId) as NodeImpl; + // } catch (e) { + // return undefined; + // } + + return undefined; + }, +}); + export const nodeInstanceMapState = selector< Record | undefined> >({ - key: 'nodeInstanceMapState', + key: "nodeInstanceMapState", get: ({ get }) => { const nodeMap = get(nodeMapState); - return mapValues(nodeMap, (node) => { - try { - return globalNodeRegistry.createDynamicImpl(node); - // return undefined; - } catch (e) { - return undefined; - } - }); + return mapValues(nodeMap, (node) => undefined); + + // return Object.fromEntries( + // await Promise.all( + // Object.entries(nodeMap).map(async ([k, v]) => { + // try { + // const globalNodeRegistry = + // await ipcRenderer.invoke('globalNodeRegistry'); + + // return [ + // k, + // globalNodeRegistry.createDynamicImpl(v) as NodeImpl, + // ]; + // } catch (e) { + // return [k, undefined]; + // } + // }), + // ), + // ); }, }); @@ -125,16 +177,18 @@ export const nodeIODefState = selector< key: 'nodeIODefState', get: ({ get }) => { const nodeMap = get(nodeMapState); - const nodeInstanceMap = get(nodeInstanceMapState); + // const nodeInstanceMap = get(nodeInstanceMapState); const connectionMap = get(connectionMapState); const getIOFromNode = (node: Node) => { const connections: NodeConnection[] = connectionMap[node.id] ?? []; + const nodeInstance = get(nodeInstanceState(node.id)); + const inputDefs: NodeInputPortDef[] = - nodeInstanceMap[node.id]?.getInputPortDefs(connections, nodeMap) ?? []; + nodeInstance?.getInputPortDefs(connections, nodeMap) ?? []; const outputDefs: NodeOutputPortDef[] = - nodeInstanceMap[node.id]?.getOutputPortDefs(connections, nodeMap) ?? []; + nodeInstance?.getOutputPortDefs(connections, nodeMap) ?? []; return inputDefs && outputDefs ? { @@ -148,7 +202,7 @@ export const nodeIODefState = selector< Object.entries(nodeMap).map(([nodeId, node]) => [ nodeId, getIOFromNode(node), - ]), + ]) ); }, }); diff --git a/packages/app/src/types/studio.type.ts b/packages/app/src/types/studio.type.ts index e0e5f058..ec7b1b95 100644 --- a/packages/app/src/types/studio.type.ts +++ b/packages/app/src/types/studio.type.ts @@ -1,25 +1,29 @@ import type { RecordId as IRecordId, - SerializableNode as INode, - NodeConnection as INodeConnection, - NodeInputPortDef as INodeInputPortDef, - NodeOutputPortDef as INodeOutputPortDef, - NodePortFields as INodePortFields, + // SerializableNode as INode, + // NodeConnection as INodeConnection, + // NodeInputPortDef as INodeInputPortDef, + // NodeOutputPortDef as INodeOutputPortDef, + // NodePortFields as INodePortFields, DataType as IDataType, + ChatMessageData, + NodeRegistration as INodeRegistration, BuiltInNodeTypes as IBuiltInNodeTypes, BuiltInNodeTypePairs as IBuiltInNodeTypePairs, -} from '@encrejs/core'; -import { globalNodeRegistry as coreGlobalNodeRegistry } from '@encrejs/core/studio/registration/nodes'; -// import { extMap as coreExtMap } from '@encrejs/core/studio/ui'; -// import { getRecordId as coreGetRecordId } from '@encrejs/core/utils/nanoid'; +} from "@encrejs/core"; +// import { globalNodeRegistry as coreGlobalNodeRegistry } from '@encrejs/core/studio/registration/nodes'; +import { extMap as coreExtMap } from "@encrejs/core/studio/ui"; +import { getRecordId as coreGetRecordId } from "@encrejs/core/utils/nanoid"; -export const globalNodeRegistry = coreGlobalNodeRegistry; +// export const globalNodeRegistry = coreGlobalNodeRegistry; export type RecordId = IRecordId; -// export function getRecordId() { -// return coreGetRecordId(); -// } +export function getRecordId() { + return coreGetRecordId(); +} + +export type NodeRegistration = INodeRegistration; export type BuiltInNodeTypes = IBuiltInNodeTypes; @@ -37,52 +41,68 @@ export type VisualInfo = { }; content?: { color?: - | 'red' - | 'orange' - | 'gold' - | 'yellow' - | 'palmera' - | 'green' - | 'meadow' - | 'cyan' - | 'blue' - | 'cornflower' - | 'purple' - | 'pink' - | 'razzmatazz' - | 'silver' - | 'dark'; + | "red" + | "orange" + | "gold" + | "yellow" + | "palmera" + | "green" + | "meadow" + | "cyan" + | "blue" + | "cornflower" + | "purple" + | "pink" + | "razzmatazz" + | "silver" + | "dark"; }; }; export type CommentVisualInfo = VisualInfo & { content?: { - horitontal?: 'center' | 'start' | 'end' | 'justify'; - vertical?: 'center' | 'start' | 'end'; + horitontal?: "center" | "start" | "end" | "justify"; + vertical?: "center" | "start" | "end"; color?: - | 'red' - | 'orange' - | 'gold' - | 'yellow' - | 'palmera' - | 'green' - | 'meadow' - | 'cyan' - | 'blue' - | 'cornflower' - | 'purple' - | 'pink' - | 'razzmatazz' - | 'silver' - | 'dark'; + | "red" + | "orange" + | "gold" + | "yellow" + | "palmera" + | "green" + | "meadow" + | "cyan" + | "blue" + | "cornflower" + | "purple" + | "pink" + | "razzmatazz" + | "silver" + | "dark"; }; }; -export type NodeInputPortDef = INodeInputPortDef; +export type NodeInputPortDef = { + nodeId: RecordId; + name: string; + type: DataType | Readonly; + required?: boolean; + data?: ValueOf | Readonly[]>; + default?: unknown; +}; -export type NodeOutputPortDef = INodeOutputPortDef; +export type NodeOutputPortDef = { + nodeId: RecordId; + name: string; + type: DataType | Readonly; + required?: boolean; + data?: ValueOf | Readonly[]>; + default?: unknown; +}; -export type NodePortFields = INodePortFields; +export type NodePortFields = { + [key: string]: DataType | Readonly; +}; export interface BaseComment { id: string; @@ -95,17 +115,17 @@ export interface BaseComment { } export interface PlainTextComment extends BaseComment { - type: 'plain'; + type: "plain"; text: string; } export interface MarkdownComment extends BaseComment { - type: 'markdown'; + type: "markdown"; text: string; } export interface CodeComment extends BaseComment { - type: 'code'; + type: "code"; text: string; language?: string; @@ -114,13 +134,142 @@ export interface CodeComment extends BaseComment { export type GraphComment = PlainTextComment | MarkdownComment | CodeComment; -export interface Node extends INode { +export type NodePortSizes = { + [key: string]: number; +}; + +export interface Node { + id: RecordId; + visualInfo: { + position: { + x: number; + y: number; + zIndex?: number; + }; + size: { + width: number; + height: number; + }; + content?: { + color?: + | "red" + | "orange" + | "gold" + | "yellow" + | "palmera" + | "green" + | "meadow" + | "cyan" + | "blue" + | "cornflower" + | "purple" + | "pink" + | "razzmatazz" + | "silver" + | "dark"; + }; + }; + inputs: NodePortFields | undefined; + outputs: NodePortFields | undefined; + title?: string | undefined; + description?: string | undefined; + outputSizes?: NodePortSizes | undefined; + + type: string; + subType: string; + registerArgs?: Record; + runtime?: number; + memory?: number; + data: any; + tags?: Array; - state?: 'init' | 'pending' | 'success' | 'failed'; + state?: "init" | "pending" | "success" | "failed"; isDebug?: boolean; } -export type NodeConnection = INodeConnection; +export type NodeConnection = { + fromNodeId: RecordId; + fromPortName: string; + toNodeId: RecordId; + toPortName: string; +}; + +export interface Context> { + pageContent: string; + metadata: Metadata; +} + +export type MessageRole = + | "human" + | "assistant" + | "system" + | "function" + | "general"; + +export type ContentLike = + | string + | { + [key: string]: unknown; + }; + +export interface BaseMessage { + content: ContentLike | ContentLike[]; + name?: string; + additionalKwargs?: { + [key: string]: unknown; + }; +} + +export type BaseMessageLike = BaseMessage | [MessageRole, string] | string; + +export type StringData = DataDef<"string", string>; +export type NumberData = DataDef<"number", number>; +export type BooleanData = DataDef<"boolean", boolean>; +export type UnknownData = DataDef<"unknown", unknown>; +export type JSONObjectData = DataDef<"object", Record>; +export type BlobData = DataDef<"blob", Blob>; +export type ContextData = DataDef<"context", Context>; +// export type ChatMessageData = DataDef<'chat-message', BaseMessageLike>; + +export type ScalarData = + | StringData + | NumberData + | BooleanData + | UnknownData + | JSONObjectData + | BlobData + | ContextData + | ChatMessageData; + +export type DataDef = { + type: T; + value: RuntimeType; +}; + +export type ArrayOf = DataDef< + `${T["type"]}[]`, + T["value"][] +>; + +export type ArrayData = { + [P in ScalarData["type"]]: ArrayOf< + Extract< + ScalarData, + { + type: P; + } + > + >; +}[ScalarData["type"]]; + +export type Data = ScalarData | ArrayData; + +export type ValueOf = Extract< + Data, + { + type: T; + } +>; export type DataType = IDataType; @@ -136,22 +285,22 @@ export type NodeBody = string | UIContext | UIContext[] | undefined; export type BaseUIContext = { fontSize?: number; - fontFamily?: 'monospace' | 'sans-serif'; + fontFamily?: "monospace" | "sans-serif"; isReadOnly?: boolean; }; export type PlainUIContext = { - type: 'plain'; + type: "plain"; text: string; }; export type MarkdownUIContext = { - type: 'markdown'; + type: "markdown"; text: string; }; export type CodeUIContext = { - type: 'code'; + type: "code"; text: string; language?: string; @@ -162,20 +311,20 @@ export type CodeUIContext = { }; export type BlobUIContext = { - type: 'blob'; + type: "blob"; blob: Array; size: number; blobType: string; }; export type ContextUIContext = { - type: 'context'; + type: "context"; text: Array; metadata: Array; }; export type MessageUIContext = { - type: 'message'; + type: "message"; content: Array; kwargs: Array; role: string; @@ -184,38 +333,38 @@ export type MessageUIContext = { }; export type ImageUIContext = { - type: 'image'; - mimeType: 'image/png' | 'image/jpeg' | 'image/gif' | 'image/svg+xml'; + type: "image"; + mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/svg+xml"; data: Uint8Array; }; export type AudioUIContext = { - type: 'audio'; - mimeType: 'audio/mp3' | 'audio/wav' | 'audio/ogg'; + type: "audio"; + mimeType: "audio/mp3" | "audio/wav" | "audio/ogg"; data: Uint8Array; }; export type FileUIContext = { - type: 'file'; + type: "file"; mimeType: - | 'text/plain' - | 'text/html' - | 'text/javascript' - | 'text/css' - | 'application/json' - | 'application/pdf' - | 'application/xml'; + | "text/plain" + | "text/html" + | "text/javascript" + | "text/css" + | "application/json" + | "application/pdf" + | "application/xml"; data: Uint8Array; }; export type SerializedRuleMetadata = { left: SerializedRule; right?: SerializedRule; - conjunction: 'and' | 'or'; + conjunction: "and" | "or"; }; export type SerializedRule = { - _type: 'rule'; + _type: "rule"; _ruleType: string; description: string; func: string; @@ -224,28 +373,28 @@ export type SerializedRule = { }; export type SerializedRuleCollection = { - _type: 'rule-collection'; + _type: "rule-collection"; description: string; collection: Record; - conjunction: 'and' | 'or'; + conjunction: "and" | "or"; }; export type IfConditionUI = { - type: 'if'; + type: "if"; description?: string; metadata?: SerializedRuleCollection; source?: string; }; export type ElseIfConditionUI = { - type: 'else-if'; + type: "else-if"; description?: string; metadata?: SerializedRuleCollection; source?: string; }; export type OtherwiseConditionUI = { - type: 'otherwise'; + type: "otherwise"; source?: string; }; @@ -255,7 +404,7 @@ export type ConditionUI = | OtherwiseConditionUI; export type ConditionUIContext = { - type: 'condition'; + type: "condition"; target: string; sources: string[]; conditions: ConditionUI[]; @@ -276,23 +425,8 @@ export type UIContext = BaseUIContext & ); export const extMap: Record< - | ImageUIContext['mimeType'] - | AudioUIContext['mimeType'] - | FileUIContext['mimeType'], + | ImageUIContext["mimeType"] + | AudioUIContext["mimeType"] + | FileUIContext["mimeType"], string -> = { - 'text/plain': 'bin', - 'text/html': 'html', - 'text/javascript': 'js', - 'text/css': 'css', - 'application/json': 'json', - 'application/pdf': 'pdf', - 'application/xml': 'xml', - 'image/png': 'png', - 'image/jpeg': 'jpeg', - 'image/gif': 'gif', - 'image/svg+xml': 'svg', - 'audio/mp3': 'mp3', - 'audio/ogg': 'ogg', - 'audio/wav': 'wav', -}; +> = coreExtMap; diff --git a/packages/app/tsconfig.json b/packages/app/tsconfig.json index 85ee69c4..512e72b2 100644 --- a/packages/app/tsconfig.json +++ b/packages/app/tsconfig.json @@ -13,20 +13,20 @@ "allowJs": true /* Allow javascript files to be compiled. */, "skipLibCheck": true, // "checkJs": true /* Report errors in .js files. */, - "jsx": "react-jsx" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */, + "jsx": "react" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */, // "declaration": true /* Generates corresponding '.d.ts' file. */, // "declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */, // "sourceMap": true /* Generates corresponding '.map' file. */, // "outFile": "./dist/bundle.js", /* Concatenate and emit output to single file. */ - // "outDir": "./build" /* Redirect output structure to the directory. */, + "outDir": "./dist/renderer" /* Redirect output structure to the directory. */, // "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, // "composite": true, /* Enable project compilation */ // "removeComments": true /* Do not emit comments to output. */, - "noEmit": true /* Do not emit outputs. */, + "noEmit": false /* Do not emit outputs. */, // "importHelpers": true, /* Import emit helpers from 'tslib'. */ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ "isolatedModules": true /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */, - // "noEmitOnError": true, + "noEmitOnError": false, /* Strict Type-Checking Options */ "strict": true /* Enable all strict type-checking options. */, @@ -48,7 +48,7 @@ /* Module Resolution Options */ "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, "resolveJsonModule": true, - // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + "baseUrl": "." /* Base directory to resolve non-absolute module names. */, // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ // "typeRoots": [], /* List of folders to include type definitions from. */ @@ -69,6 +69,6 @@ "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */, "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */ }, - "include": ["src"], + "include": ["src/**/*.tsx", "src/**/*.ts"], "exclude": ["node_modules", "build"] } diff --git a/packages/app/webpack.config.cjs b/packages/app/webpack.config.cjs new file mode 100644 index 00000000..a3a09560 --- /dev/null +++ b/packages/app/webpack.config.cjs @@ -0,0 +1,40 @@ +const path = require("path"); +const HtmlWebpackPlugin = require("html-webpack-plugin"); + +module.exports = { + mode: "development", + entry: "./src/index.tsx", + output: { + path: path.resolve(__dirname, "dist", "renderer"), + filename: "bundle.js", + }, + module: { + rules: [ + { + test: /\.tsx?$/, + use: [ + { + loader: "ts-loader", + options: { + configFile: "tsconfig.json", + }, + }, + ], + exclude: /node_modules/, + }, + { + test: /\.css$/, // This rule will apply to any files ending in .css + use: ["style-loader", "css-loader"], // Use these loaders for .css files + }, + ], + }, + plugins: [ + new HtmlWebpackPlugin({ + template: "./public/index.html", // Path to your original index.html + }), + ], + resolve: { + extensions: [".tsx", ".ts", ".js"], + }, + target: "electron-renderer", +};