mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-24 22:58:08 +00:00
Restratified i-ext. Adds v2 conversions for 6 core extensions: - dynamicPrompts.v2.ts - imageCrop.v2.ts - previewAny.v2.ts - noteNode.v2.ts - rerouteNode.v2.ts - slotDefaults.v2.ts And registers the first 3 in src/extensions/core/index.ts. Note: noteNode.v2, rerouteNode.v2, slotDefaults.v2 are NOT yet registered in index.ts (pre-existing issue from original i-ext branch). Filed as a follow-up TODO. Original (pre-restratify) branch tip backed up at refs/backup/restratify-20260511/ext-api-i-ext.
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
/**
|
|
* PreviewAny — rewritten with the v2 extension API.
|
|
*
|
|
* Compare with previewAny.ts (v1) which uses beforeRegisterNodeDef +
|
|
* prototype patching + manual callback chaining.
|
|
*
|
|
* v1: 90 lines, prototype.onNodeCreated override, prototype.onExecuted override
|
|
* v2: 35 lines, no prototype access, no manual chaining
|
|
*/
|
|
|
|
import { defineNodeExtension } from '@/extension-api'
|
|
|
|
defineNodeExtension({
|
|
name: 'Comfy.PreviewAny.V2',
|
|
nodeTypes: ['PreviewAny'],
|
|
|
|
nodeCreated(node) {
|
|
const markdown = node.addWidget('MARKDOWN', 'preview_markdown', '', {
|
|
hidden: true,
|
|
readonly: true,
|
|
serialize: false,
|
|
label: 'Preview'
|
|
})
|
|
|
|
const plaintext = node.addWidget('STRING', 'preview_text', '', {
|
|
multiline: true,
|
|
readonly: true,
|
|
serialize: false,
|
|
label: 'Preview'
|
|
})
|
|
|
|
const toggle = node.addWidget('BOOLEAN', 'previewMode', false, {
|
|
labelOn: 'Markdown',
|
|
labelOff: 'Plaintext'
|
|
})
|
|
|
|
toggle.on('valueChange', (e) => {
|
|
markdown.setHidden(!e.newValue)
|
|
plaintext.setHidden(e.newValue as boolean)
|
|
})
|
|
|
|
node.on('executed', (e) => {
|
|
const text = (e.output['text'] as string | string[]) ?? ''
|
|
const content = Array.isArray(text) ? text.join('\n\n') : text
|
|
markdown.setValue(content)
|
|
plaintext.setValue(content)
|
|
})
|
|
}
|
|
})
|