@pulse-editor/react-api 0.1.1-beta.78 → 0.1.1-beta.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/editor/use-action-effect.d.ts +1 -1
- package/dist/main.js +28 -12
- package/dist/main.js.map +1 -1
- package/package.json +2 -2
|
@@ -17,7 +17,7 @@ import { DependencyList } from "react";
|
|
|
17
17
|
export default function useActionEffect(params: {
|
|
18
18
|
actionName: string;
|
|
19
19
|
beforeAction?: (args: any) => Promise<any>;
|
|
20
|
-
afterAction?: (args: any
|
|
20
|
+
afterAction?: (args: any) => Promise<any>;
|
|
21
21
|
}, deps: DependencyList, isExtReady?: boolean): {
|
|
22
22
|
isReady: boolean;
|
|
23
23
|
runAppAction: ((args: any) => Promise<any>) | undefined;
|
package/dist/main.js
CHANGED
|
@@ -5651,9 +5651,21 @@ function useActionEffect(params, deps, isExtReady = true) {
|
|
|
5651
5651
|
// Queue to hold commands until extension is ready
|
|
5652
5652
|
const commandQueue = useRef([]);
|
|
5653
5653
|
const isCommandExecuting = useRef(false);
|
|
5654
|
+
const [remoteOrigin, setRemoteOrigin] = useState(undefined);
|
|
5654
5655
|
const [beforeAction, setBeforeAction] = useState(params.beforeAction);
|
|
5655
5656
|
const [afterAction, setAfterAction] = useState(params.afterAction);
|
|
5656
|
-
const [
|
|
5657
|
+
const [actionHandler, setActionHandler] = useState(undefined);
|
|
5658
|
+
useEffect(() => {
|
|
5659
|
+
async function fetchRemoteOrigin() {
|
|
5660
|
+
const origin = await imc?.sendMessage(IMCMessageTypeEnum.EditorGetAppOrigin, {
|
|
5661
|
+
actionName: params.actionName,
|
|
5662
|
+
});
|
|
5663
|
+
setRemoteOrigin(origin);
|
|
5664
|
+
}
|
|
5665
|
+
if (isReady) {
|
|
5666
|
+
fetchRemoteOrigin();
|
|
5667
|
+
}
|
|
5668
|
+
}, [isReady]);
|
|
5657
5669
|
// Flush queued commands when isExtReady becomes true
|
|
5658
5670
|
useEffect(() => {
|
|
5659
5671
|
async function runQueuedCommands() {
|
|
@@ -5690,14 +5702,18 @@ function useActionEffect(params, deps, isExtReady = true) {
|
|
|
5690
5702
|
};
|
|
5691
5703
|
}
|
|
5692
5704
|
async function updateAction() {
|
|
5705
|
+
if (!remoteOrigin) {
|
|
5706
|
+
console.error("Remote origin is not set yet");
|
|
5707
|
+
throw new Error("Remote origin is not set yet");
|
|
5708
|
+
}
|
|
5693
5709
|
// Register or update action.
|
|
5694
5710
|
// This will only pass signature info to the editor.
|
|
5695
5711
|
// The actual handler is stored in this hook,
|
|
5696
5712
|
// so the execution happens inside the extension app.
|
|
5697
5713
|
const { appId, version, actionInfo } = await getActionInfo(params.actionName);
|
|
5698
5714
|
// Setup handler
|
|
5699
|
-
const func = await loadAppAction(actionInfo.name, appId,
|
|
5700
|
-
|
|
5715
|
+
const func = await loadAppAction(actionInfo.name, appId, remoteOrigin, version);
|
|
5716
|
+
setActionHandler(() => func);
|
|
5701
5717
|
await imc?.sendMessage(IMCMessageTypeEnum.EditorRegisterAction, {
|
|
5702
5718
|
name: actionInfo.name,
|
|
5703
5719
|
description: actionInfo.description,
|
|
@@ -5705,17 +5721,18 @@ function useActionEffect(params, deps, isExtReady = true) {
|
|
|
5705
5721
|
returns: actionInfo.returns,
|
|
5706
5722
|
});
|
|
5707
5723
|
// Update receiver
|
|
5708
|
-
imc?.updateReceiverHandlerMap(getReceiverHandlerMap());
|
|
5724
|
+
imc?.updateReceiverHandlerMap(getReceiverHandlerMap(func));
|
|
5709
5725
|
}
|
|
5710
|
-
if (isExtReady) {
|
|
5726
|
+
if (isExtReady && remoteOrigin) {
|
|
5711
5727
|
updateAction();
|
|
5712
5728
|
}
|
|
5713
|
-
}, [params.actionName, imc, isExtReady]);
|
|
5729
|
+
}, [params.actionName, imc, isExtReady, remoteOrigin, beforeAction, afterAction]);
|
|
5714
5730
|
useEffect(() => {
|
|
5715
5731
|
setBeforeAction(() => params.beforeAction ?? (async () => { }));
|
|
5716
5732
|
setAfterAction(() => params.afterAction ?? (async () => { }));
|
|
5717
5733
|
}, [...deps]);
|
|
5718
|
-
async function executeAction(args) {
|
|
5734
|
+
async function executeAction(args, actionHandlerFunc) {
|
|
5735
|
+
const handler = actionHandlerFunc ?? actionHandler;
|
|
5719
5736
|
if (!handler) {
|
|
5720
5737
|
throw new Error("Action handler is not set");
|
|
5721
5738
|
}
|
|
@@ -5724,11 +5741,11 @@ function useActionEffect(params, deps, isExtReady = true) {
|
|
|
5724
5741
|
}
|
|
5725
5742
|
let res = await handler(args);
|
|
5726
5743
|
if (afterAction) {
|
|
5727
|
-
res = await afterAction(
|
|
5744
|
+
res = await afterAction(res);
|
|
5728
5745
|
}
|
|
5729
5746
|
return res;
|
|
5730
5747
|
}
|
|
5731
|
-
function getReceiverHandlerMap() {
|
|
5748
|
+
function getReceiverHandlerMap(actionHandlerFunc) {
|
|
5732
5749
|
const receiverHandlerMap = new Map([
|
|
5733
5750
|
[
|
|
5734
5751
|
IMCMessageTypeEnum.EditorRunAppAction,
|
|
@@ -5773,7 +5790,7 @@ function useActionEffect(params, deps, isExtReady = true) {
|
|
|
5773
5790
|
} */
|
|
5774
5791
|
// If extension is ready, execute immediately
|
|
5775
5792
|
if (isExtReady) {
|
|
5776
|
-
const result = await executeAction(args);
|
|
5793
|
+
const result = await executeAction(args, actionHandlerFunc);
|
|
5777
5794
|
return result;
|
|
5778
5795
|
}
|
|
5779
5796
|
// Otherwise, queue the command and return when executed
|
|
@@ -5797,7 +5814,6 @@ function useActionEffect(params, deps, isExtReady = true) {
|
|
|
5797
5814
|
},
|
|
5798
5815
|
],
|
|
5799
5816
|
});
|
|
5800
|
-
console.log("Loaded remote from", `${remoteOrigin}/${appId}/${version}/client/remoteEntry.js`);
|
|
5801
5817
|
const loadedFunc =
|
|
5802
5818
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5803
5819
|
(await instance.loadRemote(`${appId}_client/skill/${func}`)).default;
|
|
@@ -5805,7 +5821,7 @@ function useActionEffect(params, deps, isExtReady = true) {
|
|
|
5805
5821
|
}
|
|
5806
5822
|
return {
|
|
5807
5823
|
isReady,
|
|
5808
|
-
runAppAction:
|
|
5824
|
+
runAppAction: actionHandler,
|
|
5809
5825
|
};
|
|
5810
5826
|
}
|
|
5811
5827
|
|