1- import { App } from ' obsidian' ;
1+ import { App , Component } from " obsidian" ;
22import JsEnginePlugin from '../main' ;
33import { ExecutionArgument , ExecutionContext } from '../ArgumentManager' ;
44import { MessageType , MessageWrapper } from '../messages/MessageManager' ;
55import { API } from '../api/API' ;
66import { InstanceId , InstanceType } from '../api/InstanceId' ;
7+ import { Obj } from "tern" ;
78
89const AsyncFunction = async function ( ) : Promise < void > { } . constructor ;
910
11+ export interface JsExecutionParams {
12+ app : App ;
13+ plugin : JsEnginePlugin ;
14+ code : string ;
15+ component : Component ;
16+ container ?: HTMLElement | undefined ;
17+ context ?: ExecutionContext | undefined ;
18+ contextOverrides ?: Record < string , unknown > | undefined ;
19+ }
20+
1021export class JsExecution {
1122 readonly app : App ;
1223 readonly plugin : JsEnginePlugin ;
1324
1425 uuid : string ;
1526 code : string ;
1627 args : ExecutionArgument [ ] ;
17- context : ExecutionContext | undefined ;
28+ context : ExecutionContext & Record < string , unknown > ;
1829 apiInstance : API ;
1930 messages : MessageWrapper [ ] ;
2031
@@ -27,12 +38,12 @@ export class JsExecution {
2738 functionBuildTime : number | undefined ;
2839 functionRunTime : number | undefined ;
2940
30- constructor ( app : App , plugin : JsEnginePlugin , code : string , args : ExecutionArgument [ ] , context ?: ExecutionContext ) {
31- this . app = app ;
32- this . plugin = plugin ;
41+ constructor ( params : JsExecutionParams ) {
42+ this . app = params . app ;
43+ this . plugin = params . plugin ;
3344
34- this . code = code ;
35- this . context = context ;
45+ this . code = params . code ;
46+ this . context = Object . assign ( { } , params . context , params . contextOverrides ) ;
3647
3748 this . uuid = self . crypto . randomUUID ( ) ;
3849 this . apiInstance = new API ( this . app , this . plugin , new InstanceId ( InstanceType . JS_EXECUTION , this . uuid ) ) ;
@@ -53,7 +64,14 @@ export class JsExecution {
5364 key : 'context' ,
5465 value : this . context ,
5566 } ,
56- ...args ,
67+ {
68+ key : 'component' ,
69+ value : params . component ,
70+ } ,
71+ {
72+ key : 'container' ,
73+ value : params . container ,
74+ } ,
5775 ] ;
5876 }
5977
0 commit comments