Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schemaVersion": 1,
"name": "ai-node-canvas",
"displayName": "节点画布",
"version": "1.22.10",
"version": "1.22.11",
"description": "无限画布节点编排:把 MiniMax 模型生成的文本、图片、视频串成工作流,连线即数据流,上游产物可直接被下游引用。",
"author": "antianqi",
"icon": "icon.png",
Expand Down
10 changes: 8 additions & 2 deletions plugins/antianqi/ai-node-canvas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ English | [简体中文](README.zh-CN.md)
An infinite-canvas node graph for MiniMax Code, modelled on the canvas of
`work.batvid.com`.

Author: [antianqi](https://github.com/antianqi) · Version: `1.22.10`
Author: [antianqi](https://github.com/antianqi) · Version: `1.22.11`

![The canvas with the 图片复刻 template on it: a reference picture goes in, the prompt is read back out of that picture, and a new picture is made from the prompt](docs/preview.png)

Expand Down Expand Up @@ -709,6 +709,11 @@ Agent to open "节点画布" — or open it from the plugin list.
5. Drag the circle on the right edge of a node onto another node to connect
them.

**Immersive mode**: `F11` or `Ctrl+Shift+F` folds the toolbar away and lets
the canvas take the whole surface, with one `Exit immersive (Esc)` chip in the
corner. When the Host hands the window to the page the mode is a real
fullscreen; when it refuses, the page mode still works.

### Keyboard

| Keys | Action |
Expand All @@ -718,7 +723,8 @@ Agent to open "节点画布" — or open it from the plugin list.
| `Delete` / `Backspace` | Delete the selection |
| `Shift`+drag | Marquee select |
| `Shift`+click | Toggle one node in the selection |
| `Escape` | Close mention menu → panel → menu → deselect |
| `F11` / `Ctrl+Shift+F` | Immersive mode: the toolbar folds away, the canvas takes the surface |
| `Escape` | Close mention menu → panel → menu → leave immersive → deselect |

## Tested environment

Expand Down
9 changes: 7 additions & 2 deletions plugins/antianqi/ai-node-canvas/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MiniMax Code 里的无限画布节点图。每个节点是一次模型运行,每条连线是一条数据通路——
把文本节点连到图片节点,上游文本会自动注入下游提示词。

作者:[antianqi](https://github.com/antianqi) · 版本:`1.22.10`
作者:[antianqi](https://github.com/antianqi) · 版本:`1.22.11`

![画布:铺了「图片复刻」模板——参考图进去,提示词从这张图里反推出来,再照着它重新生成一张](docs/preview.png)

Expand Down Expand Up @@ -434,6 +434,10 @@ provider 有**几种不同的请求**把素材变成视频,不是同一个请
5. 点「生成」,上游产物自动流进下游提示词,结果落到出图的那张卡上。
6. Agent 需要工具权限时,在节点上回应审批卡。

**沉浸模式**:`F11` 或 `Ctrl+Shift+F` 让工具栏收起、画布铺满整个窗口,右上角
只留一个「退出沉浸(Esc)」。宿主允许把窗口交给页面时,它就是真的全屏;宿主
不允许时,页面内的沉浸照常工作。

### 快捷键

| 按键 | 作用 |
Expand All @@ -443,7 +447,8 @@ provider 有**几种不同的请求**把素材变成视频,不是同一个请
| `Delete` / `Backspace` | 删除选中 |
| `Shift`+拖拽 | 框选 |
| `Shift`+点击 | 增减单个节点选择 |
| `Escape` | 依次关闭:引用菜单 → 面板 → 菜单 → 节点面板 → 取消选择 |
| `F11` / `Ctrl+Shift+F` | 沉浸模式:工具栏收起,画布铺满 |
| `Escape` | 依次关闭:引用菜单 → 面板 → 菜单 → 节点面板 → 退出沉浸 → 取消选择 |

## Test 环境

Expand Down
67 changes: 67 additions & 0 deletions plugins/antianqi/ai-node-canvas/miniapp/client/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { wirePlayhead } from './clip-playhead.mjs';
import { frameStops, paintFilmstrip, paintWaveform, redrawStrips } from './strip.mjs';
import { isBusyRefusal, panelClosed, panelIsShown, panelTasks, runIsGone, taskIsExpired, theRunThatIsGoing, theRunToWaitFor, waitForTheRun, withDeadline } from './run-watch.mjs';
import { panelTitleRow } from './task-panel.mjs';
import { immersiveAction } from './immersive.mjs';
import { applyAction, applyModel, canvasTitleAfterTemplate, inheritedTextFor, legacyProductNodes, lineKind, linesDroppedByMode, materializeResults, outputForRun, pendingAncestors as pendingAncestorsIn, planIncoming, planPort, promptTemplateFor, readTemplateFile, runSpecFor, syncMentions, templateFile, templateFromCanvas } from './actions.mjs';

(() => {
Expand Down Expand Up @@ -129,6 +130,8 @@ import { applyAction, applyModel, canvasTitleAfterTemplate, inheritedTextFor, le
tool: null, // { nodeId, tool, params }
picker: null, // the node picker that opens on an empty drop
suppressClick: false,
// The immersive mode: the chrome goes away and the canvas takes the surface.
immersive: false,
};

const dom = {};
Expand Down Expand Up @@ -4441,6 +4444,12 @@ import { applyAction, applyModel, canvasTitleAfterTemplate, inheritedTextFor, le
dom.deleteButton.disabled = !state.canvas.id;
dom.gridButton.textContent = state.canvas.backgroundMode === 'dots' ? '网格:圆点' : '网格:线条';
dom.themeButton.textContent = `主题:${THEME_LABEL[state.theme] ?? THEME_LABEL.system}`;
// The button says which way the mode goes, so the user never has to
// remember whether it is on.
dom.immersiveButton.textContent = state.immersive ? '退出沉浸' : '沉浸';
dom.immersiveButton.title = state.immersive
? '退出沉浸模式(Esc)'
: '沉浸模式:工具栏收起,画布铺满(F11 / Ctrl+Shift+F)';
updateHistoryBtns();
}

Expand Down Expand Up @@ -6594,6 +6603,15 @@ import { applyAction, applyModel, canvasTitleAfterTemplate, inheritedTextFor, le
});

window.addEventListener('keydown', (event) => {
// The immersive mode is a mode and not an overlay, so its key works
// whatever else is open. One rule reads the key; the page does what
// the rule means.
const immersive = immersiveAction(event, state);
if (immersive === 'toggle') {
event.preventDefault();
setImmersive(!state.immersive);
return;
}
if (event.key === 'Escape') {
// The question the page asks is closed by Escape, like any other.
if (dom.confirmDialog && !dom.confirmDialog.hidden) {
Expand Down Expand Up @@ -6630,6 +6648,11 @@ import { applyAction, applyModel, canvasTitleAfterTemplate, inheritedTextFor, le
render();
return;
}
// Nothing else was open: what is left to close is the mode itself.
if (immersive === 'exit') {
setImmersive(false);
return;
}
selectNode(null, false);
return;
}
Expand Down Expand Up @@ -6670,6 +6693,12 @@ import { applyAction, applyModel, canvasTitleAfterTemplate, inheritedTextFor, le
}
});

// The user may leave the fullscreen with the key the browser takes, and
// the mode has to follow it out.
document.addEventListener('fullscreenchange', () => {
if (!document.fullscreenElement && state.immersive) setImmersive(false);
});

// A native drag would swallow the pointermove stream the canvas relies on.
// The blocker lives on the document so it also covers media that is
// rendered outside the viewport subtree.
Expand Down Expand Up @@ -7282,6 +7311,41 @@ import { applyAction, applyModel, canvasTitleAfterTemplate, inheritedTextFor, le
});
});
}
dom.immersiveButton.addEventListener('click', () => setImmersive(!state.immersive));
// The way out stands on the canvas: in the mode the toolbar is gone, so
// the button that leaves it cannot live there.
dom.immersiveExit.addEventListener('click', () => setImmersive(false));
}

// ---------------------------------------------------------------- immersive

/**
* The immersive mode: the chrome goes out of the way and the canvas takes
* the whole surface.
*
* The host may hand the window to the page as well, so the mode asks for
* the real fullscreen — and keeps the page mode whether the host says yes
* or no. A refusal is not an error the user has to read.
*/
function setImmersive(on) {
if (state.immersive === on) return;
state.immersive = on;
dom.app.classList.toggle('nxc-app--immersive', on);
dom.immersiveExit.hidden = !on;
// The surface grew or shrank, so the canvas has to be told again where
// there is room for it.
applyViewport();
renderToolbar();
void syncFullscreen(on);
}

async function syncFullscreen(on) {
try {
if (on) await document.documentElement.requestFullscreen?.();
else await document.exitFullscreen?.();
} catch {
// The host says no. The canvas is still immersive without it.
}
}

// ---------------------------------------------------------------- bootstrap
Expand Down Expand Up @@ -7325,6 +7389,9 @@ import { applyAction, applyModel, canvasTitleAfterTemplate, inheritedTextFor, le
dom.gridButton = $('btn-grid');
dom.themeButton = $('btn-theme');
dom.popoutButton = $('btn-popout');
dom.immersiveButton = $('btn-immersive');
dom.immersiveExit = $('immersive-exit');
dom.app = $('nxc-app');

bindInteractions();
bindToolbar();
Expand Down
32 changes: 32 additions & 0 deletions plugins/antianqi/ai-node-canvas/miniapp/client/immersive.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// The immersive mode: the chrome gets out of the way and the canvas takes
// the whole surface.
//
// One rule, one reader: the keyboard says what a key means, and the page
// does what that meaning is. If the page read the keys itself, the key on
// the keyboard and the key in the README would drift apart.

/**
* What a key means for the immersive mode.
*
* `toggle` asks for the mode or leaves it, `exit` leaves it, and an empty
* answer means the key is none of this mode's business.
*
* The mode is a mode and not an overlay, so its own key works whatever else
* is open. Escape is the other way round: it closes whatever is open first,
* and only then does it leave the mode.
*
* @param {{ key?: string, ctrlKey?: boolean, metaKey?: boolean, shiftKey?: boolean }} event
* @param {{ immersive?: boolean }} state
* @returns {'toggle' | 'exit' | ''}
*/
export function immersiveAction(event, state = {}) {
if (!event) return '';
const key = event.key ?? '';
if (key === 'F11') return 'toggle';
// The host may take F11 for itself, so the same verb has a second key.
if ((event.ctrlKey || event.metaKey) && event.shiftKey && (key === 'f' || key === 'F')) {
return 'toggle';
}
if (key === 'Escape' && state.immersive) return 'exit';
return '';
}
7 changes: 6 additions & 1 deletion plugins/antianqi/ai-node-canvas/miniapp/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="stylesheet" href="/styles.css" />
</head>
<body>
<div class="nxc-app"> <header class="nxc-toolbar">
<div id="nxc-app" class="nxc-app"> <header class="nxc-toolbar">
<div class="nxc-toolbar__group">
<h1 class="nxc-brand"><i class="nxc-brand__dot"></i>节点画布</h1>
<button id="canvas-select" class="nxc-select nxc-select--canvas" type="button" title="切换画布"></button>
Expand All @@ -32,6 +32,7 @@ <h1 class="nxc-brand"><i class="nxc-brand__dot"></i>节点画布</h1>
<button id="btn-theme" class="nxc-btn" type="button" title="切换配色主题">主题:跟随系统</button>
<button id="btn-reset" class="nxc-btn" type="button">重置视图</button>
<button id="btn-popout" class="nxc-btn" type="button" hidden>独立窗口</button>
<button id="btn-immersive" class="nxc-btn" type="button" title="沉浸模式:工具栏收起,画布铺满(F11 / Ctrl+Shift+F)">沉浸</button>
<button id="btn-add" class="nxc-btn nxc-btn--primary" type="button">添加节点</button>
</div>
</header>
Expand All @@ -52,6 +53,10 @@ <h1 class="nxc-brand"><i class="nxc-brand__dot"></i>节点画布</h1>
</div>
</main>

<!-- The way out of the immersive mode stands on the canvas: the mode
hides the toolbar, so the button that leaves it cannot live there. -->
<button id="immersive-exit" class="nxc-btn nxc-immersive-exit" type="button" hidden>退出沉浸(Esc)</button>

<div id="context-menu" class="nxc-menu" hidden></div>
<div id="add-menu" class="nxc-menu nxc-palette" hidden></div>
<div id="mention-menu" class="nxc-menu nxc-mention-menu" hidden></div>
Expand Down
31 changes: 31 additions & 0 deletions plugins/antianqi/ai-node-canvas/miniapp/client/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2997,3 +2997,34 @@ input {
color: var(--brand);
font-size: 13px;
}

/* ---------------- immersive ---------------- */

/* The immersive mode: the chrome goes out of the way and the canvas takes
the whole surface. What the mode hides is a list, and the list lives here:
one class says the mode is on, and the stylesheet says what that means. */
.nxc-app--immersive .nxc-toolbar {
display: none;
}

.nxc-immersive-exit {
position: fixed;
top: 10px;
right: 12px;
z-index: 40;
min-height: 26px;
padding: 3px 10px;
font-size: 12px;
border-radius: 999px;
opacity: 0.35;
transition: opacity var(--mcode-duration-fast) var(--mcode-ease);
}

.nxc-immersive-exit:hover,
.nxc-immersive-exit:focus-visible {
opacity: 1;
}

.nxc-immersive-exit[hidden] {
display: none;
}
1 change: 1 addition & 0 deletions plugins/antianqi/ai-node-canvas/miniapp/node/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const CLIENT_FILES = new Map([
['/strip.mjs', { file: 'strip.mjs', type: 'text/javascript; charset=utf-8' }],
['/clip-place.mjs', { file: 'clip-place.mjs', type: 'text/javascript; charset=utf-8' }],
['/clip-playhead.mjs', { file: 'clip-playhead.mjs', type: 'text/javascript; charset=utf-8' }],
['/immersive.mjs', { file: 'immersive.mjs', type: 'text/javascript; charset=utf-8' }],
['/styles.css', { file: 'styles.css', type: 'text/css; charset=utf-8' }],
]);

Expand Down
2 changes: 1 addition & 1 deletion plugins/antianqi/ai-node-canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ai-node-canvas",
"version": "1.22.10",
"version": "1.22.11",
"private": true,
"description": "Node-graph canvas MiniApp for MiniMax Code: wire MiniMax model runs into a visual workflow.",
"mcode": {
Expand Down
18 changes: 18 additions & 0 deletions plugins/antianqi/ai-node-canvas/tests/smoke.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { createActionQueue, OWNER_TTL_MS } from '../miniapp/node/action-queue.mj
import { decodeHostConnectorValue } from '../miniapp/node/host-connector-value.mjs';
import { findMediaTool, RETIRED_TOOLS, TOOL_ACCEPTS, TOOL_PRODUCES, delogoRect } from '../miniapp/node/media-tools.mjs';
import { cropRectAfterDrag, fanOutParams, nodeHasProduct, NODE_GAP, toolPrompt } from '../miniapp/client/tools.mjs';
import { immersiveAction } from '../miniapp/client/immersive.mjs';
import { providerFailure } from '../miniapp/node/connector-runner.mjs';
import { scanFiles } from './scan-undefined.mjs';

Expand Down Expand Up @@ -12079,6 +12080,23 @@ test('an audio the provider would refuse is converted before it goes up', async
assert.deepEqual(leftovers.filter((name) => name.endsWith('.mp3')), [], 'the converted copy was left behind');
});

test('the immersive mode reads its keys in one place', () => {
// F11 is the key the README tells the user to press.
assert.equal(immersiveAction({ key: 'F11' }), 'toggle');
// The host may take F11 for itself, so the same verb has a second key.
assert.equal(immersiveAction({ key: 'f', ctrlKey: true, shiftKey: true }), 'toggle');
assert.equal(immersiveAction({ key: 'F', metaKey: true, shiftKey: true }), 'toggle');
// A find is not this mode's key, and neither is a bare letter.
assert.equal(immersiveAction({ key: 'f', ctrlKey: true }), '');
assert.equal(immersiveAction({ key: 'f' }), '');
// Escape leaves the mode, but only when it is on: otherwise it keeps
// closing whatever else is open.
assert.equal(immersiveAction({ key: 'Escape' }, { immersive: true }), 'exit');
assert.equal(immersiveAction({ key: 'Escape' }, { immersive: false }), '');
// No key at all is no meaning at all.
assert.equal(immersiveAction(null), '');
});

test('the first and last frame request declares one ending only', async (t) => {
// The provider takes ONE ending. When last_frame_image stands beside
// input_image, input_image has to be declared the first frame — declaring
Expand Down