Skip to content

Commit ffaa425

Browse files
committed
Add video editor view
1 parent 4e590e9 commit ffaa425

File tree

20 files changed

+461
-131
lines changed

20 files changed

+461
-131
lines changed

.changeset/cruel-zoos-play.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@pulse-editor/shared-utils": patch
3+
"@pulse-editor/react-api": patch
4+
---
5+
6+
Add image and video gen hooks

.changeset/pre.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"beige-pandas-rhyme",
1818
"calm-rivers-march",
1919
"chatty-trains-beam",
20+
"cruel-zoos-play",
2021
"curvy-places-wash",
2122
"dirty-swans-rescue",
2223
"early-pumas-listen",

npm-packages/react-api/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @pulse-editor/react-api
22

3+
## 0.1.1-alpha.18
4+
5+
### Patch Changes
6+
7+
- Add image and video gen hooks
8+
- Updated dependencies
9+
- @pulse-editor/shared-utils@0.1.1-alpha.18
10+
311
## 0.1.1-alpha.17
412

513
### Patch Changes

npm-packages/react-api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pulse-editor/react-api",
3-
"version": "0.1.1-alpha.17",
3+
"version": "0.1.1-alpha.18",
44
"main": "dist/main.js",
55
"files": [
66
"dist"
@@ -38,7 +38,7 @@
3838
"typescript-eslint": "^8.30.1"
3939
},
4040
"peerDependencies": {
41-
"@pulse-editor/shared-utils": "0.1.1-alpha.17",
41+
"@pulse-editor/shared-utils": "0.1.1-alpha.18",
4242
"react": "^19.0.0",
4343
"react-dom": "^19.0.0"
4444
}

npm-packages/react-api/src/hooks/modality/use-image-gen.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export default function useImageGen() {
2525
imagePrompt?: string | ArrayBuffer,
2626
// LLM config is optional, if not provided, the default config will be used.
2727
imageModelConfig?: ImageModelConfig
28-
): Promise<ArrayBuffer> {
28+
): Promise<{
29+
arrayBuffer?: ArrayBuffer;
30+
url?: string;
31+
}> {
2932
if (!imc) {
3033
throw new Error("IMC not initialized.");
3134
}
@@ -41,7 +44,10 @@ export default function useImageGen() {
4144
imageModelConfig,
4245
})
4346
.then((response) => {
44-
return response as ArrayBuffer;
47+
return response as {
48+
arrayBuffer?: ArrayBuffer;
49+
url?: string;
50+
};
4551
});
4652

4753
return result;

npm-packages/react-api/src/hooks/modality/use-video-gen.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ export default function useVideoGen() {
2121
* @returns The generated video in an ArrayBuffer.
2222
*/
2323
async function runVideoGen(
24+
duration: number,
2425
textPrompt?: string,
2526
imagePrompt?: string | ArrayBuffer,
2627
// LLM config is optional, if not provided, the default config will be used.
2728
videoModelConfig?: VideoModelConfig
28-
): Promise<ArrayBuffer> {
29+
): Promise<{
30+
url?: string;
31+
arrayBuffer?: ArrayBuffer;
32+
}> {
2933
if (!imc) {
3034
throw new Error("IMC not initialized.");
3135
}
@@ -36,12 +40,16 @@ export default function useVideoGen() {
3640

3741
const result = await imc
3842
.sendMessage(IMCMessageTypeEnum.UseVideoGen, {
43+
duration,
3944
textPrompt,
4045
imagePrompt,
4146
videoModelConfig,
4247
})
4348
.then((response) => {
44-
return response as ArrayBuffer;
49+
return response as {
50+
url?: string;
51+
arrayBuffer?: ArrayBuffer;
52+
};
4553
});
4654

4755
return result;

npm-packages/react-api/src/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import useTheme from "./hooks/editor/use-theme";
88
import useToolbar from "./hooks/editor/use-toolbar";
99
import useExtCommand from "./hooks/extension/use-ext-command";
1010

11-
import useDiffusion from "./hooks/modality/use-image-gen";
11+
import useImageGen from "./hooks/modality/use-image-gen";
1212
import useLLM from "./hooks/modality/use-llm";
1313
import useOCR from "./hooks/modality/use-ocr";
1414
import useSTT from "./hooks/modality/use-stt";
1515
import useTTS from "./hooks/modality/use-tts";
16+
import useVideoGen from "./hooks/modality/use-video-gen";
1617
import useTerminal from "./hooks/terminal/use-terminal";
1718

1819
export {
@@ -23,7 +24,8 @@ export {
2324
useNotification,
2425
useTheme,
2526
useToolbar,
26-
useDiffusion,
27+
useImageGen,
28+
useVideoGen,
2729
useLLM,
2830
useOCR,
2931
useSTT,

npm-packages/shared-utils/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @pulse-editor/shared-utils
22

3+
## 0.1.1-alpha.18
4+
5+
### Patch Changes
6+
7+
- Add image and video gen hooks
8+
39
## 0.1.1-alpha.17
410

511
### Patch Changes

npm-packages/shared-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pulse-editor/shared-utils",
3-
"version": "0.1.1-alpha.17",
3+
"version": "0.1.1-alpha.18",
44
"main": "dist/main.js",
55
"files": [
66
"dist"

npm-packages/shared-utils/src/imc/inter-module-communication.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class InterModuleCommunication {
2121

2222
private listener: ((event: MessageEvent) => void) | undefined;
2323

24-
constructor() {}
24+
private messageRecords: Map<string, IMCMessage> | undefined;
2525

2626
/**
2727
* Initialize a receiver to receive message.
@@ -46,7 +46,19 @@ export class InterModuleCommunication {
4646
);
4747
this.receiver = receiver;
4848

49+
this.messageRecords = new Map<string, IMCMessage>();
50+
4951
this.listener = (event: MessageEvent<IMCMessage>) => {
52+
const messageId = event.data.id;
53+
54+
if (this.messageRecords?.has(messageId)) {
55+
console.warn(
56+
`Duplicate message received with ID: ${messageId}. Ignoring this message.`
57+
);
58+
return;
59+
}
60+
this.messageRecords?.set(messageId, event.data);
61+
5062
if (!receiver) {
5163
throw new Error(
5264
"Receiver not initialized at module " + this.thisWindowId

0 commit comments

Comments
 (0)