SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.
JavaScript a2aagentic-aiai-agentsdevtoolsmcp-clientn8n-alternativeno-codeopen-sourceorchestrationsmythosvisual-builder
Refactor textarea handling and template variable button generation
Muhammad Hamza Khane5e4570ef6bc
diff --git a/packages/app/src/builder-ui/ui/form/fields.ts b/packages/app/src/builder-ui/ui/form/fields.tsindex 9edd325e..13d6ad98 100644--- a/packages/app/src/builder-ui/ui/form/fields.ts+++ b/packages/app/src/builder-ui/ui/form/fields.ts@@ -354,20 +354,6 @@ function applyTextareaStyles(textarea: HTMLTextAreaElement, isCodeEditor: booleafont-size: 14px;outline: none;`;- } else {- // Full styling for regular textarea- textarea.style.cssText = `- width: 100%;- min-height: 300px;- padding: 16px;- border: 1px solid #d1d5db;- border-radius: 6px;- font-size: 14px;- font-family: inherit;- resize: vertical;- outline: none;- transition: border-color 0.15s ease-in-out;- `;}}@@ -453,9 +439,14 @@ async function handleExpandTextarea(const { twModalDialog, setCodeEditor } = await getModalImports(!!code);const hasCodeEditor = !!code;- // Get current component for template variables- const currentComponent = (window as any).Component?.curComponentSettings || null;-+ // Get component UID for template variables - try multiple approaches++ // First, try to get it from the original textarea's data attribute (if it was stored)+ const compUid = originalTextarea.getAttribute('data-component-uid');++ // Create a mock component object with the UID for handleTemplateVars+ const currentComponent = compUid ? { _uid: compUid } : null;+// Create modal content containerconst modalContainer = document.createElement('div');modalContainer.classList.add('h-full', 'flex', 'flex-col', 'form-group');@@ -464,20 +455,11 @@ async function handleExpandTextarea(const modalTextarea = document.createElement('textarea') as TextAreaWithEditor;modalTextarea.value = originalTextarea.value;modalTextarea.classList.add('form-control', 'flex-1', 'resize-none');+ modalTextarea.id = 'expanded-textarea';// Apply styles based on editor typeapplyTextareaStyles(modalTextarea, hasCodeEditor);- // Add focus handlers for regular textarea (not needed for code editor)- if (!hasCodeEditor) {- modalTextarea.addEventListener('focus', () => {- modalTextarea.style.borderColor = '#3b82f6';- });- modalTextarea.addEventListener('blur', () => {- modalTextarea.style.borderColor = '#d1d5db';- });- }-// Create template variable buttons containerconst templateVarsContainer = document.createElement('div');templateVarsContainer.classList.add('template-var-buttons', 'mt-2');@@ -506,6 +488,10 @@ async function handleExpandTextarea(if (modalTextareaInDialog) {syncTextareaValues(modalTextareaInDialog, originalTextarea, hasCodeEditor);}++ // Clean up any template variable wrappers within the modal+ const templateVarWrappers = dialogElm.querySelectorAll('.template-var-buttons');+ templateVarWrappers.forEach((wrapper) => wrapper.remove());},},],@@ -547,10 +533,17 @@ async function handleExpandTextarea(// Set up template variable functionality if the textarea has template vars attributeconst hasTemplateVars = modalTextareaInDialog.getAttribute('data-template-vars') === 'true';const hasAgentVars = modalTextareaInDialog.getAttribute('data-agent-vars') === 'true';-+if (hasTemplateVars || hasAgentVars) {- // Just use the existing handleTemplateVars function directly on the modal container- handleTemplateVars(dialogElm, currentComponent);+ // Clean up any existing template variable wrappers in the modal first+ const existingWrappers = dialogElm.querySelectorAll('.template-var-buttons');+ existingWrappers.forEach((wrapper) => wrapper.remove());++ // Find the form group within the modal and set up template vars on that specific container+ const modalFormGroup = modalTextareaInDialog.closest('.form-group') as HTMLElement;+ if (modalFormGroup) {+ handleTemplateVars(modalFormGroup, currentComponent);+ }}},});@@ -600,6 +593,14 @@ export const createTextArea = (entry: {});}+ // Store component UID in textarea data attribute for template variables+ const currentComponent = (window as any).Component?.curComponentSettings || null;+ const compUid =+ currentComponent?._uid || document.querySelector('.component.active')?.getAttribute('id') || '';+ if (compUid) {+ textarea.setAttribute('data-component-uid', compUid);+ }+// If expandable is true, wrap textarea with container and add expand buttonif (expandable) {const container = document.createElement('div');diff --git a/packages/app/src/builder-ui/ui/form/misc.ts b/packages/app/src/builder-ui/ui/form/misc.tsindex 489f357b..899df469 100644--- a/packages/app/src/builder-ui/ui/form/misc.ts+++ b/packages/app/src/builder-ui/ui/form/misc.ts@@ -150,8 +150,11 @@ const TEMPLATE_VAR_BTNS_WRAPPER_CLASS = 'template-var-buttons';export function generateTemplateVarBtns(variables: Map<string, { var: string; type?: string }>,compUid = '',+ parentContainer?: HTMLElement,): HTMLElement | null {- let wrapper = document.querySelector(`.${TEMPLATE_VAR_BTNS_WRAPPER_CLASS}`) as HTMLDivElement;+ // Look for existing wrapper within the specific parent container, not globally+ const searchScope = parentContainer || document;+ let wrapper = searchScope.querySelector(`.${TEMPLATE_VAR_BTNS_WRAPPER_CLASS}.tvb-${compUid}`) as HTMLDivElement;if (!wrapper) {wrapper = document.createElement('div');@@ -321,11 +324,11 @@ export function handleTemplateVars(targetElm, component = null) {}// #endregion- const buttonsContainer = generateTemplateVarBtns(variables, compUid) as HTMLDivElement;+ const focusedElmParent = clickedElm.closest('.form-group') as HTMLElement;+ const buttonsContainer = generateTemplateVarBtns(variables, compUid, focusedElmParent) as HTMLDivElement;if (!buttonsContainer) return;- const focusedElmParent = clickedElm.closest('.form-group');focusedElmParent.appendChild(buttonsContainer);} else if (clickedElm.getAttribute('data-agent-vars') === 'true' &&@@ -345,11 +348,11 @@ export function handleTemplateVars(targetElm, component = null) {{ var: string; type: string }>;- const buttonsContainer = generateTemplateVarBtns(variables, compUid) as HTMLDivElement;+ const focusedElmParent = clickedElm.closest('.form-group') as HTMLElement;+ const buttonsContainer = generateTemplateVarBtns(variables, compUid, focusedElmParent) as HTMLDivElement;if (!buttonsContainer) return;- const focusedElmParent = clickedElm.closest('.form-group');focusedElmParent.appendChild(buttonsContainer);} else {// * Remove template variable buttons