UNPKG

sccoreui

Version:

ui-sccore

38 lines (37 loc) 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const ExpressionRenderer = ({ inputValue }) => { const parts = []; const regex = /\[\[\{.*?\}\]\]/g; let lastIndex = 0; let match; while ((match = regex.exec(inputValue)) !== null) { const before = inputValue.substring(lastIndex, match.index); if (before.trim()) { parts.push(...before.split(/(\s+)/).filter(Boolean)); } try { const json = JSON.parse(match[0].slice(2, -2)); parts.push(json); // Add parsed object } catch (e) { parts.push(match[0]); // Fallback to raw } lastIndex = regex.lastIndex; } const after = inputValue.substring(lastIndex); if (after.trim()) { parts.push(...after.split(/(\s+)/).filter(Boolean)); } return ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: "flex align-items-center gap-2" }, { children: parts.map((part, index) => { if (typeof part === "object" && part.value) { return ((0, jsx_runtime_1.jsx)("span", Object.assign({ className: "bg-gray-200 px-2 py-1 border-round-sm font-bold" }, { children: part.value }), index)); } else if (typeof part === "string" && part.trim() !== "") { return (0, jsx_runtime_1.jsx)("span", { children: part }, index); } return null; }) }))); }; exports.default = ExpressionRenderer;