diff --git a/packages/editor-ui/src/composables/useExpressionEditor.ts b/packages/editor-ui/src/composables/useExpressionEditor.ts index 9b52589a7a..0393618dfa 100644 --- a/packages/editor-ui/src/composables/useExpressionEditor.ts +++ b/packages/editor-ui/src/composables/useExpressionEditor.ts @@ -352,6 +352,12 @@ export const useExpressionEditor = ({ * - `This is a {{ [] }} test` displays as `This is a test`. * - `{{ [] }}` displays as `[Array: []]`. * + * - `This is a {{ {} }} test` displays as `This is a [object Object] test`. + * - `{{ {} }}` displays as `[Object: {}]`. + * + * - `This is a {{ [{}] }} test` displays as `This is a [object Object] test`. + * - `{{ [] }}` displays as `[Array: []]`. + * * Some segments display differently based on context: * * Date displays as @@ -366,13 +372,29 @@ export const useExpressionEditor = ({ .map((s) => { if (cachedSegments.length <= 1 || s.kind !== 'resolvable') return s; - if (typeof s.resolved === 'string' && /\[Object: "\d{4}-\d{2}-\d{2}T/.test(s.resolved)) { - const utcDateString = s.resolved.replace(/(\[Object: "|\"\])/g, ''); - s.resolved = new Date(utcDateString).toString(); - } + if (typeof s.resolved === 'string') { + let resolved = s.resolved; - if (typeof s.resolved === 'string' && /\[Array:\s\[.+\]\]/.test(s.resolved)) { - s.resolved = s.resolved.replace(/(\[Array: \[|\])/g, ''); + if (/\[Object: "\d{4}-\d{2}-\d{2}T/.test(resolved)) { + const utcDateString = resolved.replace(/(\[Object: "|\"\])/g, ''); + resolved = new Date(utcDateString).toString(); + } + + if (/\[Object:\s(\{.+\}|\{\})\]/.test(resolved)) { + resolved = resolved.replace(/(\[Object: |\]$)/g, ''); + try { + resolved = String(JSON.parse(resolved)); + } catch (error) {} + } + + if (/\[Array:\s\[.+\]\]/.test(resolved)) { + resolved = resolved.replace(/(\[Array: |\]$)/g, ''); + try { + resolved = String(JSON.parse(resolved)); + } catch (error) {} + } + + s.resolved = resolved; } return s;