Merge commit '8c700b1e080a29a02375664e856bc6e5b757c7c3' into feature/negodata
This commit is contained in:
commit
9ac8fe6363
26 files changed
+530
-62
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { DataTable } from '@/components/ui/data-table';
|
||||
import { renderEmphasis } from '@/lib/emphasis';
|
||||
import type { NegotiationCard } from '../types';
|
||||
|
||||
type CardTableProps = {
|
||||
@@ -67,7 +68,8 @@ export function CardTable({ data, onEdit, footer }: CardTableProps) {
|
||||
mobileBlock: true, // 긴 미리보기 블록 → 모바일 카드뷰에서 라벨 아래 풀폭
|
||||
cell: (card) => (
|
||||
<div className="max-w-[22rem] truncate bg-muted/20 px-2 py-1 rounded border border-border/30 text-[11px] leading-snug">
|
||||
{card.scriptPreview}
|
||||
{/* 마커(**굵게**·{{색}})를 스타일로 렌더 — 표 미리보기에 원시 마커가 보이지 않게 */}
|
||||
{renderEmphasis(card.scriptPreview)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export { CardScriptEditor } from './CardScriptEditor';
|
||||
// deserialize() 는 항상 새 배열을 반환 → Slate initialValue 로 안전. 공용 mutable 상수는 export 하지 않는다.
|
||||
export { deserialize, serializeToText } from './slate';
|
||||
export { deserialize, serializeToText, serializeToMarker } from './slate';
|
||||
export { CARD_VARIABLES } from './variables';
|
||||
@@ -96,6 +96,38 @@ function serializeNode(node: Descendant): string {
|
||||
return node.text;
|
||||
}
|
||||
|
||||
// ── 직렬화: Slate 값 → 마커 문자열(script) ──────────────────
|
||||
// bold/underline/color 마크를 경량 마커로 인코딩해 저장한다(edit_script=Slate 원본은 재편집용).
|
||||
// agent 는 이 문자열을 불투명 텍스트로 전달하고, 각 프론트 emphasis.tsx 가 마커를 렌더한다.
|
||||
// 고정 팔레트(검정/빨강/파랑) → 시맨틱 토큰. 검정(#151515)은 기본이라 마커 없음.
|
||||
const COLOR_TO_TOKEN: Record<string, string> = {
|
||||
'#ED2024': '강조', // 빨강
|
||||
'#4880EF': '안내', // 파랑
|
||||
};
|
||||
|
||||
export function serializeToMarker(nodes: Descendant[]): string {
|
||||
return nodes.map(serializeMarkerNode).join('\n');
|
||||
}
|
||||
|
||||
function serializeMarkerNode(node: Descendant): string {
|
||||
if (SlateElement.isElement(node)) {
|
||||
if (node.type === 'variable') return applyMarks(`{${node.name}}`, node.children[0]);
|
||||
return node.children.map(serializeMarkerNode).join('');
|
||||
}
|
||||
return applyMarks(node.text, node);
|
||||
}
|
||||
|
||||
// 텍스트/변수 리프의 마크를 마커로 감싼다. 중첩 순서: 색(바깥) → 굵게 → 밑줄(안). 빈 문자열은 그대로.
|
||||
function applyMarks(text: string, leaf?: CustomText): string {
|
||||
if (!text || !leaf) return text;
|
||||
let s = text;
|
||||
if (leaf.underline) s = `__${s}__`;
|
||||
if (leaf.bold) s = `**${s}**`;
|
||||
const token = leaf.color ? COLOR_TO_TOKEN[leaf.color] : undefined;
|
||||
if (token) s = `{{${token}|${s}}}`;
|
||||
return s;
|
||||
}
|
||||
|
||||
// ── 역직렬화: edit_script(JSON) 또는 평문(script) → Slate 값 ──
|
||||
// 저장된 edit_script 가 있으면 그대로, 없으면(레거시 평문 카드) {name} 토큰을 변수 노드로 복원.
|
||||
// Slate 는 initialValue 를 레퍼런스로 직접 변경하므로 항상 새 배열을 돌려준다
|
||||
|
||||
@@ -12,7 +12,7 @@ import type { ResCard } from '@/api/generated/model/resCard';
|
||||
import type { NegotiationCard } from '@/types';
|
||||
import type { BulkFailure } from '@/lib/excel';
|
||||
import { mapCardData, toCardStatusCode } from '../types';
|
||||
import { serializeToText } from '../editor';
|
||||
import { serializeToMarker } from '../editor';
|
||||
|
||||
// 카드 폼이 넘기는 입력값(편집/생성 공통).
|
||||
// 스크립트는 Slate JSON(editorScript)을 정본으로 받고, 평문 script 는 저장 시 직렬화로 파생한다.
|
||||
@@ -43,8 +43,8 @@ function toReq(input: CardInput): ReqCreateCard {
|
||||
usage_type: input.usageType,
|
||||
name: input.title,
|
||||
number: input.code,
|
||||
script: serializeToText(input.editorScript), // 평문 미리보기({변수} 토큰 포함)
|
||||
edit_script: input.editorScript, // Slate JSON 원본
|
||||
script: serializeToMarker(input.editorScript), // 마커 문자열(굵게·색 인코딩 + {변수} 토큰)
|
||||
edit_script: input.editorScript, // Slate JSON 원본(재편집 전용)
|
||||
status: toCardStatusCode(input.status),
|
||||
condition: input.isWildcard ? input.triggerCondition : undefined,
|
||||
memo: input.isWildcard ? input.memo : undefined,
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Typography } from '@/components/ui/typography';
|
||||
import { StatusPill, sessionStatusTone } from './StatusPill';
|
||||
import { type Product, type Partner, sessionStatusLabel } from '../../types';
|
||||
import { maskPrices } from '@/lib/utils';
|
||||
import { renderEmphasis } from '@/lib/emphasis';
|
||||
|
||||
export function ChatTab({
|
||||
serverSessions,
|
||||
@@ -158,7 +159,7 @@ function BotBubble({
|
||||
)}
|
||||
{m.script && (
|
||||
<Typography as="p" variant="small" className="text-xs whitespace-pre-line leading-relaxed text-inherit">
|
||||
{maskPrices(m.script)}
|
||||
{renderEmphasis(maskPrices(m.script))}
|
||||
</Typography>
|
||||
)}
|
||||
<UsedCardBox
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import { Fragment, type ReactNode } from 'react';
|
||||
|
||||
/**
|
||||
* 봇 스크립트 경량 마크업(마크다운 서브셋) 렌더러 — 공급사 프론트(frontend emphasis.tsx)와 동일 규칙.
|
||||
*
|
||||
* agent 스크립트는 의미(텍스트)만 소유하고 표현(굵기·밑줄·색)은 각 프론트가 결정한다.
|
||||
* 지원 문법(중첩 가능): **굵게** __밑줄__ {{강조|빨강}} {{안내|파랑}} (검정은 기본, 마커 없음).
|
||||
* 색 토큰명은 시맨틱이며 실제 색값은 이 프론트의 디자인 토큰(tokens.css)이 결정 — 다크모드 안전.
|
||||
* innerHTML 없이 React 노드로 분해(XSS 안전). 짝이 안 맞는 마커는 평문으로 출력.
|
||||
*/
|
||||
|
||||
// 시맨틱 색 토큰 → 이 프론트의 Tailwind 색 클래스(tokens.css --color-destructive/--color-info).
|
||||
const COLOR_CLASS: Record<string, string> = {
|
||||
강조: 'text-destructive',
|
||||
안내: 'text-info',
|
||||
};
|
||||
|
||||
export function renderEmphasis(text: string): ReactNode {
|
||||
if (!text || !/\*\*|__|\{\{/.test(text)) return text;
|
||||
return <Fragment>{parseInline(text, 'e')}</Fragment>;
|
||||
}
|
||||
|
||||
function parseInline(text: string, keyPrefix: string): ReactNode[] {
|
||||
const nodes: ReactNode[] = [];
|
||||
let pos = 0;
|
||||
let seq = 0;
|
||||
while (pos < text.length) {
|
||||
const hit = nextMarker(text, pos);
|
||||
if (!hit) {
|
||||
nodes.push(text.slice(pos));
|
||||
break;
|
||||
}
|
||||
if (hit.start > pos) nodes.push(text.slice(pos, hit.start));
|
||||
const key = `${keyPrefix}-${seq++}`;
|
||||
const inner = parseInline(hit.inner, key);
|
||||
nodes.push(wrap(hit.kind, hit.token, inner, key));
|
||||
pos = hit.end;
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
type Hit = { kind: 'bold' | 'underline' | 'color'; start: number; end: number; inner: string; token?: string };
|
||||
|
||||
function nextMarker(text: string, pos: number): Hit | null {
|
||||
let best: Hit | null = null;
|
||||
const consider = (h: Hit | null) => {
|
||||
if (h && (!best || h.start < best.start)) best = h;
|
||||
};
|
||||
consider(matchDelim(text, pos, '**', 'bold'));
|
||||
consider(matchDelim(text, pos, '__', 'underline'));
|
||||
consider(matchColor(text, pos));
|
||||
return best;
|
||||
}
|
||||
|
||||
function matchDelim(text: string, pos: number, delim: '**' | '__', kind: 'bold' | 'underline'): Hit | null {
|
||||
const open = text.indexOf(delim, pos);
|
||||
if (open < 0) return null;
|
||||
const close = text.indexOf(delim, open + delim.length);
|
||||
if (close < 0) return null;
|
||||
return { kind, start: open, end: close + delim.length, inner: text.slice(open + delim.length, close) };
|
||||
}
|
||||
|
||||
function matchColor(text: string, pos: number): Hit | null {
|
||||
const open = text.indexOf('{{', pos);
|
||||
if (open < 0) return null;
|
||||
const bar = text.indexOf('|', open + 2);
|
||||
if (bar < 0) return null;
|
||||
const close = text.indexOf('}}', bar + 1);
|
||||
if (close < 0) return null;
|
||||
const token = text.slice(open + 2, bar).trim();
|
||||
if (!(token in COLOR_CLASS)) return null;
|
||||
return { kind: 'color', start: open, end: close + 2, inner: text.slice(bar + 1, close), token };
|
||||
}
|
||||
|
||||
function wrap(kind: Hit['kind'], token: string | undefined, inner: ReactNode[], key: string): ReactNode {
|
||||
if (kind === 'bold') return <strong key={key} className="font-semibold">{inner}</strong>;
|
||||
if (kind === 'underline') return <u key={key}>{inner}</u>;
|
||||
return <span key={key} className={token ? COLOR_CLASS[token] : undefined}>{inner}</span>;
|
||||
}
|
||||
@@ -31,6 +31,7 @@
|
||||
--color-destructive-foreground: var(--destructive-foreground);
|
||||
--color-success: var(--success);
|
||||
--color-warning: var(--warning);
|
||||
--color-info: var(--info);
|
||||
--color-ring: var(--ring);
|
||||
|
||||
--font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
|
||||
@@ -55,6 +56,7 @@
|
||||
--destructive-foreground: #fafafa;
|
||||
--success: #10b981;
|
||||
--warning: #f59e0b;
|
||||
--info: #4880ef;
|
||||
--ring: #a1a1a1;
|
||||
--popover: #ffffff;
|
||||
--popover-foreground: #0a0a0a;
|
||||
@@ -94,6 +96,7 @@
|
||||
--destructive-foreground: #fafafa;
|
||||
--success: #10b981;
|
||||
--warning: #f59e0b;
|
||||
--info: #6ea8ff;
|
||||
--ring: #737373;
|
||||
--popover: #171717;
|
||||
--popover-foreground: #fafafa;
|
||||
|
||||
Reference in new issue
Block a user