@ecomcx/ecomweb-editor 1.31.0 → 1.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/package.json +3 -3
  2. package/src/locales/en/attrs.ts +10 -0
  3. package/src/locales/en/background.ts +17 -0
  4. package/src/locales/en/bindings.ts +1 -1
  5. package/src/locales/en/block-desc.ts +2 -0
  6. package/src/locales/en/block-style.ts +7 -4
  7. package/src/locales/en/block-titles.ts +2 -0
  8. package/src/locales/en/blocks.ts +12 -3
  9. package/src/locales/en/columns.ts +12 -0
  10. package/src/locales/en/controls.ts +21 -0
  11. package/src/locales/en/hints.ts +289 -1
  12. package/src/locales/en/index.ts +5 -2
  13. package/src/locales/en/layout.ts +32 -0
  14. package/src/locales/en/legacy.ts +1 -1
  15. package/src/locales/en/library.ts +38 -0
  16. package/src/locales/en/parts.ts +12 -0
  17. package/src/locales/en/placeholders.ts +12 -1
  18. package/src/locales/en/presets.ts +6 -0
  19. package/src/locales/en/v2.ts +21 -0
  20. package/src/locales/vi/attrs.ts +10 -0
  21. package/src/locales/vi/background.ts +17 -0
  22. package/src/locales/vi/bindings.ts +1 -1
  23. package/src/locales/vi/block-desc.ts +2 -0
  24. package/src/locales/vi/block-style.ts +7 -4
  25. package/src/locales/vi/block-titles.ts +2 -0
  26. package/src/locales/vi/blocks.ts +12 -3
  27. package/src/locales/vi/columns.ts +12 -0
  28. package/src/locales/vi/controls.ts +21 -0
  29. package/src/locales/vi/hints.ts +290 -2
  30. package/src/locales/vi/index.ts +5 -2
  31. package/src/locales/vi/layout.ts +32 -0
  32. package/src/locales/vi/legacy.ts +1 -1
  33. package/src/locales/vi/library.ts +38 -0
  34. package/src/locales/vi/parts.ts +12 -0
  35. package/src/locales/vi/placeholders.ts +12 -1
  36. package/src/locales/vi/presets.ts +6 -0
  37. package/src/locales/vi/v2.ts +21 -0
  38. package/src/shared/panel-store.ts +3 -3
  39. package/src/shared/patterns.ts +3 -52
  40. package/src/shared/style-panel.tsx +2 -2
  41. package/src/shared/types.ts +2 -0
  42. package/src/v2/blocks/columns-inspector.tsx +210 -0
  43. package/src/v2/blocks/form.tsx +4 -4
  44. package/src/v2/blocks/index.ts +10 -4
  45. package/src/v2/blocks/inline-style.ts +1 -1
  46. package/src/v2/blocks/layout.tsx +211 -44
  47. package/src/v2/blocks/media.tsx +22 -13
  48. package/src/v2/blocks/resize.tsx +172 -4
  49. package/src/v2/blocks/text.tsx +14 -7
  50. package/src/v2/blocks/theme.tsx +63 -19
  51. package/src/v2/blocks/tools.tsx +50 -5
  52. package/src/v2/blocks/widgets.tsx +44 -16
  53. package/src/v2/canvas/block-list.tsx +23 -3
  54. package/src/v2/canvas/canvas-css.ts +70 -4
  55. package/src/v2/canvas/canvas.tsx +22 -5
  56. package/src/v2/canvas/dnd.ts +34 -3
  57. package/src/v2/canvas/move-animation.ts +94 -0
  58. package/src/v2/canvas/spacing-viz.ts +51 -0
  59. package/src/v2/core/block-presets.ts +68 -0
  60. package/src/v2/core/host.ts +6 -1
  61. package/src/v2/core/structure.ts +2 -1
  62. package/src/v2/editor.css +238 -9
  63. package/src/v2/editor.tsx +8 -2
  64. package/src/v2/ui/attr-form.tsx +59 -12
  65. package/src/v2/ui/attr-hints.ts +140 -9
  66. package/src/v2/ui/background-panel.tsx +65 -21
  67. package/src/v2/ui/bindings.tsx +3 -0
  68. package/src/v2/ui/block-icons.tsx +152 -0
  69. package/src/v2/ui/block-menu.ts +22 -0
  70. package/src/v2/ui/block-style-panel.tsx +14 -3
  71. package/src/v2/ui/color-field.tsx +74 -9
  72. package/src/v2/ui/divider-panel.tsx +58 -0
  73. package/src/v2/ui/group-width.tsx +38 -0
  74. package/src/v2/ui/icon-picker.tsx +51 -0
  75. package/src/v2/ui/inserter.tsx +61 -12
  76. package/src/v2/ui/inspector.tsx +48 -16
  77. package/src/v2/ui/layout-panel.tsx +5 -47
  78. package/src/v2/ui/list-view.tsx +81 -7
  79. package/src/v2/ui/motion-panel.tsx +2 -1
  80. package/src/v2/ui/parts-panel.tsx +164 -0
  81. package/src/v2/ui/pattern-library.tsx +228 -0
  82. package/src/v2/ui/preset-bar.tsx +83 -0
  83. package/src/v2/ui/style-controls.tsx +65 -15
  84. package/src/v2/ui/style-supports.ts +1 -1
  85. package/src/v2/ui/style-tab.tsx +127 -41
  86. package/src/v2/ui/toolbar.tsx +52 -13
  87. package/src/v2/ui/unit-controls.tsx +88 -39
  88. package/src/locales/en/patterns.ts +0 -50
  89. package/src/locales/vi/patterns.ts +0 -50
  90. package/src/shared/patterns-kit.ts +0 -7
  91. package/src/shared/patterns-library.ts +0 -172
@@ -1,8 +1,10 @@
1
1
  import { normalizeStyle } from "@ecomcx/ecomweb-content";
2
- import { Link2, Link2Off, SlidersHorizontal } from "lucide-react";
3
- import { useEffect, useState } from "react";
2
+ import { Link2, Link2Off } from "lucide-react";
3
+ import { useEffect, useRef, useState } from "react";
4
4
  import { useEditor } from "../context";
5
- import { cx } from "./style-controls";
5
+ import { Row, cx } from "./style-controls";
6
+ import type { Device } from "@ecomcx/ecomweb-content";
7
+ import { hideSpacingViz, showSpacingViz, type Side, type SpacingKind } from "../canvas/spacing-viz";
6
8
  import { useMsgs } from "../i18n";
7
9
 
8
10
  /**
@@ -45,41 +47,72 @@ export function UnitInput({ value, onChange, label, max = 100, units = UNITS, sl
45
47
  );
46
48
  }
47
49
 
48
- /** Thanh kéo theo bậc preset + nút sang giá trị tuỳ chỉnh. */
49
- function StepSlider({ value, steps, onChange, label, sideIcon }: { value?: string; steps: string[]; onChange(v: string | undefined): void; label: string; sideIcon?: string }) {
50
+ /**
51
+ * Một giá trị cho cả 4 (cạnh viền / góc bo), hoặc tách từng cái: xích bật = một ô, tắt = 4 ô nhỏ.
52
+ * Giá trị: chuỗi (cả 4) hoặc `{ [khoá]: chuỗi }`; 4 ô bằng nhau thì gộp lại thành chuỗi.
53
+ */
54
+ export function FourInput({ label, value, keys, keyLabels, units, max, onChange, onReset, corners }: {
55
+ /** Góc bo (nhãn "từng góc") thay cho cạnh. */
56
+ corners?: boolean; label: string; value?: string | Partial<Record<string, string>>; keys: readonly string[]; keyLabels: Record<string, string>;
57
+ units?: string[]; max?: number; onChange(v: string | Record<string, string> | undefined): void; onReset?(): void;
58
+ }) {
50
59
  const t = useMsgs("controls");
51
- const isPreset = value === undefined || steps.includes(value);
52
- const [custom, setCustom] = useState(!isPreset);
53
- useEffect(() => { if (!isPreset) setCustom(true); }, [isPreset]);
54
- const idx = value === undefined ? -1 : steps.indexOf(value);
60
+ const [linked, setLinked] = useState(typeof value !== "object" || !value);
61
+ const each = (typeof value === "object" && value ? value : value ? Object.fromEntries(keys.map((k) => [k, value])) : {}) as Record<string, string>;
62
+ const setOne = (k: string, v: string | undefined) => {
63
+ const next = { ...each }; if (v === undefined) delete next[k]; else next[k] = v;
64
+ const vals = keys.map((x) => next[x]);
65
+ onChange(!Object.keys(next).length ? undefined : vals.every((x) => x !== undefined && x === vals[0]) ? vals[0] : next);
66
+ };
55
67
  return (
56
- <div className="ecx-step-row">
57
- {sideIcon && <span className={cx("ecx-side-icon", sideIcon)} aria-hidden="true" />}
58
- {custom
59
- ? <UnitInput label={label} value={isPreset ? undefined : value} onChange={onChange} max={120} />
60
- : (
61
- <div className="ecx-steps">
62
- <input type="range" aria-label={label} min={-1} max={steps.length - 1} step={1} value={idx} aria-valuetext={idx < 0 ? "—" : steps[idx]}
63
- onChange={(e) => { const i = Number(e.target.value); onChange(i < 0 ? undefined : steps[i]); }} />
64
- <span className="ecx-step-value">{idx < 0 ? "—" : steps[idx].toUpperCase()}</span>
65
- </div>
66
- )}
67
- <button type="button" className={cx("ecx-tool", custom && "is-active")} aria-pressed={custom} title={custom ? (t.usePresets) : (t.customValue)} aria-label={`${label}: ${custom ? (t.usePresets2) : (t.customValue2)}`}
68
- onClick={() => { setCustom(!custom); if (custom && !isPreset) onChange(undefined); }}><SlidersHorizontal className="ecx-icon ecx-icon-sm" /></button>
69
- </div>
68
+ <Row label={label} onReset={onReset}
69
+ extra={<button type="button" className={cx("ecx-link-toggle", linked && "is-on")} aria-pressed={!linked} title={linked ? (corners ? t.unlinkCorners : t.unlinkSides) : (corners ? t.linkCorners : t.linkSides)} aria-label={`${label}: ${corners ? t.unlinkCorners : t.unlinkSides}`}
70
+ onClick={() => { if (!linked && typeof value === "object") onChange(each[keys[0]]); setLinked(!linked); }}>{linked ? <Link2 className="ecx-icon" /> : <Link2Off className="ecx-icon" />}</button>}>
71
+ {linked
72
+ ? <UnitInput label={label} value={typeof value === "string" ? value : undefined} placeholder={typeof value === "object" ? "—" : undefined} units={units} max={max} onChange={onChange} />
73
+ : <div className="ecx-four">{keys.map((k) => (
74
+ <label key={k} className="ecx-four-cell"><small>{keyLabels[k]}</small>
75
+ <UnitInput label={`${label} ${keyLabels[k]}`} value={each[k]} units={units} max={max} slider={false} onChange={(v) => setOne(k, v)} /></label>
76
+ ))}</div>}
77
+ </Row>
70
78
  );
71
79
  }
72
80
 
73
81
  type Box = string | Record<string, string> | undefined;
74
82
  const sidesOf = (v: Box): Record<string, string> => (typeof v === "object" && v ? v : v ? { top: v, right: v, bottom: v, left: v } : {});
83
+ const SIDES: Side[] = ["top", "right", "bottom", "left"];
75
84
 
76
- /** Lề trong / ngoài: liên kết (một giá trị) hoặc dọc + ngang. */
77
- export function SpacingControl({ label, value, onChange, steps, inherited, labels }: {
85
+ /**
86
+ * Đệm / lề bốn cạnh: 4 ô Trên · Phải · Dưới · Trái (vạch đậm ở đúng cạnh, hiện tên bậc hoặc số), xích = 4 cạnh như nhau.
87
+ * Rê chuột lên ô → khối đang chọn được tô vùng đệm (bên trong) / lề (bên ngoài) trên khung soạn. Bấm ô → bảng chọn bậc + giá trị tuỳ chỉnh.
88
+ */
89
+ export function SpacingControl({ label, value, onChange, steps, inherited, labels, kind = "padding", device, onReset, vizTarget }: {
78
90
  label: string; value: Box; onChange(v: Box): void; steps: string[]; inherited?: string; labels: { vertical: string; horizontal: string; link: string; unlink: string; top: string; right: string; bottom: string; left: string };
91
+ kind?: SpacingKind; device?: Device; onReset?(): void;
92
+ /** Phần tử được tô (mặc định: khối đang chọn) — vd một phần của khối. */
93
+ vizTarget?(): HTMLElement | null;
79
94
  }) {
95
+ const { store, ui } = useEditor();
96
+ const t = useMsgs("controls");
80
97
  const sides = sidesOf(value);
81
98
  const [linked, setLinked] = useState(typeof value !== "object" || value === null || (sides.top === sides.bottom && sides.left === sides.right && sides.top === sides.left));
99
+ const [open, setOpen] = useState<Side | null>(null);
100
+ const hover = useRef<Side | null>(null);
101
+ const ref = useRef<HTMLDivElement>(null);
82
102
  const ok = (v: string) => !!normalizeStyle({ padding: v });
103
+ const blockEl = () => { if (vizTarget) return vizTarget(); const s = store.getState().selection; const id = s.ids[0] ?? s.editing; return id ? ui.blockEl(id) : null; };
104
+ const names = () => Object.fromEntries(SIDES.map((s) => [s, sides[s] && steps.includes(sides[s]) ? sides[s].toUpperCase() : undefined])) as Partial<Record<Side, string>>;
105
+ const viz = (side: Side | null) => { if (!side) { hideSpacingViz(ui.canvasDoc); return; } showSpacingViz(blockEl(), kind, linked ? SIDES : [side], names()); };
106
+ // Giá trị đổi khi đang rê / đang mở bảng chọn: vẽ lại lớp tô sau khi khối nhận CSS mới
107
+ useEffect(() => { const s = open ?? hover.current; if (!s) return; const r = requestAnimationFrame(() => viz(s)); return () => cancelAnimationFrame(r); });
108
+ useEffect(() => () => hideSpacingViz(ui.canvasDoc), [ui]);
109
+ useEffect(() => {
110
+ if (!open) return;
111
+ const out = (e: MouseEvent) => { if (!ref.current?.contains(e.target as Node)) { setOpen(null); viz(hover.current); } };
112
+ const esc = (e: KeyboardEvent) => { if (e.key === "Escape") { e.stopPropagation(); setOpen(null); viz(null); } };
113
+ document.addEventListener("mousedown", out, true); document.addEventListener("keydown", esc, true);
114
+ return () => { document.removeEventListener("mousedown", out, true); document.removeEventListener("keydown", esc, true); };
115
+ });
83
116
  const set = (keys: string[], v: string | undefined) => {
84
117
  if (v !== undefined && !ok(v)) return;
85
118
  const next = { ...sides };
@@ -87,22 +120,38 @@ export function SpacingControl({ label, value, onChange, steps, inherited, label
87
120
  const vals = Object.values(next);
88
121
  onChange(!vals.length ? undefined : vals.length === 4 && vals.every((x) => x === vals[0]) ? vals[0] : next);
89
122
  };
123
+ const target = (side: Side) => (linked ? SIDES : [side]);
124
+ const shown = (v?: string) => (v === undefined ? "–" : steps.includes(v) ? (v === "0" ? "0" : v.toUpperCase()) : v);
125
+ const cur = open ? sides[open] : undefined;
90
126
  return (
91
- <div className="ecx-spacing">
92
- <div className="ecx-spacing-head">
93
- <span className="ecx-field-label">{label}{inherited && <em className="ecx-inherit">{inherited}</em>}</span>
94
- <button type="button" className="ecx-tool" aria-pressed={linked} title={linked ? labels.unlink : labels.link} aria-label={`${label}: ${linked ? labels.unlink : labels.link}`} onClick={() => setLinked(!linked)}>
95
- {linked ? <Link2 className="ecx-icon ecx-icon-sm" /> : <Link2Off className="ecx-icon ecx-icon-sm" />}
96
- </button>
97
- </div>
98
- {linked
99
- ? <StepSlider label={label} steps={steps} value={typeof value === "string" ? value : sides.top} onChange={(v) => set(["top", "right", "bottom", "left"], v)} sideIcon="is-all" />
100
- : <>
101
- {/* Bỏ liên kết: bốn cạnh riêng (đặt lệch được, vd chỉ padding-bottom) */}
102
- {(["top", "right", "bottom", "left"] as const).map((side) => (
103
- <StepSlider key={side} label={`${label} ${labels[side]}`} steps={steps} value={sides[side]} onChange={(v) => set([side], v)} sideIcon={`is-${side}`} />
127
+ <div className="ecx-box4" ref={ref} onMouseLeave={() => { hover.current = null; if (!open) viz(null); }}>
128
+ <Row label={<>{label}{inherited && <em className="ecx-inherit">{inherited}</em>}</>} device={device} onReset={onReset}
129
+ extra={<button type="button" className={cx("ecx-link-toggle", linked && "is-on")} aria-pressed={linked} title={linked ? labels.unlink : labels.link} aria-label={`${label}: ${linked ? labels.unlink : labels.link}`}
130
+ onClick={() => setLinked(!linked)}>{linked ? <Link2 className="ecx-icon" /> : <Link2Off className="ecx-icon" />}</button>}>
131
+ <div className="ecx-box4-grid">
132
+ {SIDES.map((side) => (
133
+ <button key={side} type="button" className={cx("ecx-box4-cell", `is-${side}`, sides[side] !== undefined && "is-set", open && target(open).includes(side) && "is-open")}
134
+ aria-label={`${label} ${labels[side]}: ${shown(sides[side])}`} aria-haspopup="dialog" aria-expanded={open === side}
135
+ onMouseEnter={() => { hover.current = side; viz(side); }} onFocus={() => viz(side)} onBlur={() => { if (!open) viz(null); }}
136
+ onClick={() => setOpen(open === side ? null : side)}>
137
+ <small>{labels[side]}</small><b>{shown(sides[side])}</b>
138
+ </button>
139
+ ))}
140
+ </div>
141
+ </Row>
142
+ {open && (
143
+ // key: đổi cạnh thì ô số mới, không giữ số đã gõ của cạnh trước
144
+ <div key={open} className="ecx-box4-pop" role="dialog" aria-label={`${label} ${linked ? "" : labels[open]}`}>
145
+ <div className="ecx-pop-title">{label}{linked ? "" : ` · ${labels[open]}`}</div>
146
+ <div className="ecx-box4-steps" role="radiogroup" aria-label={label}>
147
+ {steps.map((st) => (
148
+ <button key={st} type="button" role="radio" aria-checked={cur === st} className={cx("ecx-chip", cur === st && "is-active")} onClick={() => set(target(open), st)}>{st === "0" ? "0" : st.toUpperCase()}</button>
104
149
  ))}
105
- </>}
150
+ </div>
151
+ <UnitInput label={`${label}: ${t.customValue}`} value={cur && !steps.includes(cur) ? cur : undefined} max={160} onChange={(v) => set(target(open), v)} />
152
+ <div className="ecx-pop-foot"><button type="button" className="ecx-link-btn" onClick={() => set(target(open), undefined)}>{t.reset}</button><button type="button" className="ecx-link-btn" onClick={() => { setOpen(null); viz(null); }}>OK</button></div>
153
+ </div>
154
+ )}
106
155
  </div>
107
156
  );
108
157
  }
@@ -1,50 +0,0 @@
1
- /** Text of the 8 basic patterns (names, descriptions, placeholder content). */
2
- export const patterns = {
3
- hero: "Hero cover",
4
- heroD: "Big heading over a background image + 2 buttons",
5
- heroTitle: "A headline that stands out",
6
- heroText: "One short sentence about what you offer your customers.",
7
- start: "Get started",
8
- learn: "Learn more",
9
- features: "Three features",
10
- featuresD: "Heading + 3 feature columns",
11
- featuresTitle: "Why choose us",
12
- f1: "Fast",
13
- f2: "Secure",
14
- f3: "Easy",
15
- fText: "A short description of this benefit.",
16
- cta: "Call to action",
17
- ctaD: "Highlighted box with a button",
18
- ctaTitle: "Ready to start?",
19
- ctaText: "Sign up today for a special offer.",
20
- ctaBtn: "Contact us",
21
- pricing: "Pricing — 3 plans",
22
- pricingD: "3 plan cards with a feature list",
23
- basic: "Basic",
24
- pro: "Pro",
25
- biz: "Business",
26
- perMonth: "/month",
27
- choose: "Choose plan",
28
- item: "Feature",
29
- faq: "FAQ",
30
- faqD: "Heading + collapsible questions",
31
- q: "Question",
32
- a: "A short answer.",
33
- testimonial: "Testimonial",
34
- testimonialD: "Pullquote with a name",
35
- quote: "Great service, I will recommend it to my friends.",
36
- who: "Jane Doe, CEO",
37
- intro: "Media + intro",
38
- introD: "Image on one side, text and button on the other",
39
- introTitle: "About us",
40
- introText: "A short introduction to the company, its mission and values.",
41
- contact: "Contact",
42
- contactD: "Heading, short intro and a contact form",
43
- contactTitle: "Get in touch",
44
- contactText: "Address · Phone · Email",
45
- send: "Send",
46
- thanks: "Thank you! We will get back to you soon.",
47
- name: "Full name",
48
- email: "Email",
49
- message: "Message",
50
- };
@@ -1,50 +0,0 @@
1
- /** Chữ của 8 mẫu cơ bản (tên, mô tả, nội dung giữ chỗ). */
2
- export const patterns = {
3
- hero: "Ảnh bìa giới thiệu",
4
- heroD: "Tiêu đề lớn trên ảnh nền + 2 nút",
5
- heroTitle: "Tiêu đề thật ấn tượng",
6
- heroText: "Một câu ngắn nói rõ bạn mang lại điều gì cho khách hàng.",
7
- start: "Bắt đầu ngay",
8
- learn: "Tìm hiểu thêm",
9
- features: "Ba tính năng",
10
- featuresD: "Tiêu đề + 3 cột tính năng",
11
- featuresTitle: "Vì sao chọn chúng tôi",
12
- f1: "Nhanh",
13
- f2: "An toàn",
14
- f3: "Dễ dùng",
15
- fText: "Mô tả ngắn về lợi ích này.",
16
- cta: "Kêu gọi hành động",
17
- ctaD: "Khung nổi bật với nút",
18
- ctaTitle: "Sẵn sàng bắt đầu?",
19
- ctaText: "Đăng ký hôm nay để nhận ưu đãi.",
20
- ctaBtn: "Liên hệ ngay",
21
- pricing: "Bảng giá 3 gói",
22
- pricingD: "3 gói dạng thẻ, có danh sách quyền lợi",
23
- basic: "Cơ bản",
24
- pro: "Chuyên nghiệp",
25
- biz: "Doanh nghiệp",
26
- perMonth: "/tháng",
27
- choose: "Chọn gói",
28
- item: "Quyền lợi",
29
- faq: "Câu hỏi thường gặp",
30
- faqD: "Tiêu đề + các câu hỏi thu gọn",
31
- q: "Câu hỏi",
32
- a: "Câu trả lời ngắn gọn.",
33
- testimonial: "Cảm nhận khách hàng",
34
- testimonialD: "Trích dẫn nổi bật kèm tên",
35
- quote: "Dịch vụ tuyệt vời, tôi sẽ giới thiệu cho bạn bè.",
36
- who: "Nguyễn Văn A, Giám đốc",
37
- intro: "Ảnh + giới thiệu",
38
- introD: "Ảnh một bên, chữ và nút bên kia",
39
- introTitle: "Về chúng tôi",
40
- introText: "Giới thiệu ngắn về công ty, sứ mệnh và giá trị.",
41
- contact: "Liên hệ",
42
- contactD: "Tiêu đề, giới thiệu ngắn và form liên hệ",
43
- contactTitle: "Liên hệ với chúng tôi",
44
- contactText: "Địa chỉ · Số điện thoại · Email",
45
- send: "Gửi",
46
- thanks: "Cảm ơn bạn! Chúng tôi sẽ liên hệ lại sớm.",
47
- name: "Họ và tên",
48
- email: "Email",
49
- message: "Nội dung",
50
- };
@@ -1,7 +0,0 @@
1
- /** Hàm dựng khối dùng chung cho mẫu của lõi (patterns.ts, patterns-library.ts). */
2
- export const text = (s: string, marks?: Array<{ type: string }>) => (marks ? { type: "text", text: s, marks } : { type: "text", text: s });
3
- export const p = (s: string, attrs?: Record<string, unknown>) => ({ type: "paragraph", ...(attrs ? { attrs } : {}), content: [text(s)] });
4
- export const h = (level: number, s: string, attrs: Record<string, unknown> = {}) => ({ type: "heading", attrs: { level, ...attrs }, content: [text(s)] });
5
- export const btn = (s: string, variant = "primary") => ({ type: "button", attrs: { text: s, href: "#", variant } });
6
- export const buttons = (align: string, ...list: object[]) => ({ type: "buttons", attrs: { align }, content: list });
7
-
@@ -1,172 +0,0 @@
1
- import { msgs } from "../i18n";
2
- import type { Pattern } from "./patterns";
3
- import { btn, buttons, h, p, text } from "./patterns-kit";
4
-
5
- /**
6
- * Thư viện mẫu section của lõi (ngoài 8 mẫu cơ bản trong patterns.ts): hero, tính năng, số liệu, quy trình, bảng giá, cảm nhận,
7
- * hỏi đáp, kêu gọi, đội ngũ, đối tác, liên hệ, nội dung, chân trang. Chỉ dùng khối và kiểu dáng của @ecomcx/ecomweb-content nên
8
- * mọi theme hiển thị được; người soạn chèn một cú bấm rồi chỉ sửa chữ. Hiệu ứng chuyển động (1.16) có sẵn ở các mẫu hợp lý.
9
- */
10
- type L = Record<string, string>;
11
-
12
- // ---------------------------------------------------------------------------
13
- // Khối dựng sẵn dùng lại
14
- // ---------------------------------------------------------------------------
15
- type Node = Record<string, unknown>;
16
- const GRADIENT = "linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)";
17
- const WHITE_BTN = (s: string) => ({ type: "button", attrs: { text: s, href: "#", variant: "primary", style: { color: { background: "#ffffff", text: "#1e3a8a" } } } });
18
- const GHOST_BTN = (s: string) => ({ type: "button", attrs: { text: s, href: "#", variant: "outline", style: { color: { text: "#ffffff" }, border: { color: "#ffffff" } } } });
19
- const center = { textAlign: { base: "center" } };
20
- const section = (content: Node[], style: Record<string, unknown> = {}): Node => ({ type: "group", attrs: { style: { padding: { base: "2xl", mobile: "xl" }, ...style } }, content });
21
- const grid = (cols: number, content: Node[], style: Record<string, unknown> = {}): Node => ({ type: "group", attrs: { style: { layout: { type: "grid", columns: { base: cols, tablet: Math.min(cols, 2), mobile: 1 } }, gap: "lg", ...style } }, content });
22
- const card = (content: Node[], style: Record<string, unknown> = {}): Node => ({ type: "group", attrs: { blockStyle: "card", style: { motion: { hover: "lift" }, ...style } }, content });
23
- const eyebrow = (s: string, c = false): Node => p(s, { style: { textTransform: "uppercase", letterSpacing: "0.1em", fontSize: { base: "sm" }, fontWeight: "700", color: { text: "primary" }, ...(c ? center : {}) } });
24
- const muted = (s: string, extra: Record<string, unknown> = {}): Node => p(s, { style: { color: { text: "muted" }, ...extra } });
25
- const big = (s: string): Node => ({ type: "heading", attrs: { level: 2, style: { fontSize: { base: "3xl" }, ...center } }, content: [text(s)] });
26
- const link = (s: string, href = "#") => text(s, [{ type: "link", attrs: { href } } as never]);
27
- const li = (s: string): Node => ({ type: "listItem", content: [p(s)] });
28
- const img = (alt: string): Node => ({ type: "image", attrs: { src: "", alt } });
29
- const slideUp = (extra: Record<string, unknown> = {}) => ({ motion: { in: "slide-up", stagger: true }, ...extra });
30
- const table = (rows: string[][]): Node => ({ type: "table", content: rows.map((r, i) => ({ type: "tableRow", content: r.map((c) => ({ type: i === 0 ? "tableHeader" : "tableCell", content: [p(c)] })) })) });
31
-
32
- function library(t: L): Pattern[] {
33
- const feat = (title: string): Node => card([h(3, title), muted(t.fText)], { padding: { base: "lg" } });
34
- const stat = (n: string, l: string): Node => ({ type: "group", attrs: { style: center }, content: [h(2, n, { style: { fontSize: { base: "4xl" }, color: { text: "primary" } } }), muted(l, center)] });
35
- const step = (n: number, title: string): Node => card([h(2, String(n), { style: { color: { text: "primary" } } }), h(3, title), muted(t.sText)], { padding: { base: "lg" } });
36
- const plan = (name: string, price: string, highlight: boolean): Node => card([
37
- ...(highlight ? [eyebrow(t.popular)] : []), h(3, name), h(2, price, { style: { fontSize: { base: "3xl" } } }),
38
- { type: "bulletList", content: [1, 2, 3, 4].map((n) => li(`${t.item} ${n}`)) },
39
- buttons("left", btn(t.choose, highlight ? "primary" : "outline")),
40
- ], { padding: { base: "lg" }, ...(highlight ? { shadow: "lg", border: { width: "2px", style: "solid", color: "primary" } } : {}) });
41
- const quoteCard = (q: string, who: string): Node => card([{ type: "blockquote", attrs: { citation: who }, content: [p(q)] }], { padding: { base: "lg" } });
42
- const member = (): Node => card([img(t.member), h(3, t.member), muted(t.role), p(t.bio)], { padding: { base: "lg" }, textAlign: { base: "center" } });
43
- const info = (label: string, value: string): Node => card([h(3, label), p(value)], { padding: { base: "lg" } });
44
- const links = (title: string, items: string[]): Node => ({ type: "column", content: [h(4, title), { type: "bulletList", content: items.map((s) => ({ type: "listItem", content: [{ type: "paragraph", content: [link(s)] }] })) }] });
45
- // Form cơ bản của lõi (khối form): formId để trống — trình soạn tạo mã khi mẫu được chèn
46
- const fld = (kind: string, name: string, label: string, extra: Record<string, unknown> = {}): Node => ({ type: "formField", attrs: { kind, name, label, ...extra } });
47
- const contactForm = (topics = false): Node => ({ type: "form", attrs: { submitText: t.fSend, successMessage: t.fThanks }, content: [
48
- fld("text", "name", t.fName, { required: true, width: "half" }), fld("tel", "phone", t.fPhone, { required: true, width: "half" }),
49
- fld("email", "email", t.fEmail),
50
- ...(topics ? [fld("select", "topic", t.fTopic, { options: [t.topic1, t.topic2, t.topic3] })] : []),
51
- fld("textarea", "message", t.fMessage, { required: true, placeholder: t.fMessageP }),
52
- fld("consent", "consent", t.fConsent, { required: true }),
53
- ] });
54
- const infoRow = (icon: string, label: string, value: string): Node => ({ type: "group", attrs: { style: { layout: { type: "flex", direction: { base: "row" }, align: { base: "start" }, wrap: false }, gap: "md" } }, content: [
55
- { type: "icon", attrs: { name: icon, size: 22, style: { color: { text: "primary" } } } },
56
- { type: "group", content: [p(label, { style: { fontWeight: "600", margin: { base: "0" } } }), muted(value, { margin: { base: "0" } })] }] });
57
- const m = (id: string, category: string, keywords: string, content: Node[]): Pattern => ({ name: `core/${id}`, category, title: t[id.replace(/-/g, "_")], description: t[`${id.replace(/-/g, "_")}D`], keywords, content });
58
-
59
- return [
60
- // ---------------- hero ----------------
61
- m("hero-split", "hero", "hero banner anh chu split", [
62
- section([{ type: "mediaText", attrs: { position: "right", width: 45, verticalAlign: "center" }, content: [
63
- eyebrow(t.eyebrow), h(1, t.title), p(t.sub), buttons("left", btn(t.start), btn(t.demo, "outline"))] }], { motion: { in: "fade" } })]),
64
- m("hero-gradient", "hero", "hero gradient nen chuyen mau gradient", [
65
- section([h(1, t.title, { style: { ...center, color: { text: "#ffffff" } } }), p(t.sub, { style: { ...center, color: { text: "#ffffff" } } }), buttons("center", WHITE_BTN(t.start), GHOST_BTN(t.learn))],
66
- { gradient: GRADIENT, padding: { base: "3xl", mobile: "2xl" }, radius: "16px", motion: { in: "slide-up" } })]),
67
- m("hero-minimal", "hero", "hero toi gian minimal", [
68
- section([eyebrow(t.eyebrow), h(1, t.title, { style: { fontSize: { base: "4xl", mobile: "3xl" } } }), muted(t.sub, { fontSize: { base: "lg" } }), buttons("left", btn(t.start), btn(t.learn, "outline"))],
69
- { padding: { base: "3xl", mobile: "2xl" }, maxWidth: { base: "720px" }, motion: { in: "fade" } })]),
70
- m("hero-bottom", "hero", "hero anh bia cover chu duoi", [
71
- { type: "cover", attrs: { overlay: "#000000", opacity: 45, minHeight: "75vh", contentAlign: "bottom" }, content: [
72
- h(1, t.title), p(t.sub), buttons("left", btn(t.start))] }]),
73
- m("hero-badge", "hero", "hero nhan badge moi", [
74
- section([p(`● ${t.badge}`, { style: { ...center, fontWeight: "700", color: { text: "primary" } } }), h(1, t.title, { style: center }), muted(t.sub, center), buttons("center", btn(t.start), btn(t.learn, "outline"))],
75
- { padding: { base: "3xl", mobile: "2xl" }, motion: { in: "slide-up" } })]),
76
-
77
- // ---------------- features ----------------
78
- m("feat-grid6", "features", "tinh nang luoi features grid 6", [
79
- section([eyebrow(t.eyebrow, true), big(t.title), { type: "spacer", attrs: { height: "md" } }, grid(3, [t.f1, t.f2, t.f3, t.f4, t.f5, t.f6].map(feat), slideUp())])]),
80
- m("feat-cards4", "features", "the noi hover card 4", [
81
- section([big(t.title), { type: "spacer", attrs: { height: "md" } }, grid(4, [t.f1, t.f2, t.f3, t.f4].map(feat), slideUp())])]),
82
- m("feat-list", "features", "tinh nang danh sach list diem manh", [
83
- section([{ type: "columns", content: [
84
- { type: "column", content: [eyebrow(t.eyebrow), h(2, t.title), muted(t.sub)] },
85
- { type: "column", content: [{ type: "bulletList", content: [t.f1, t.f2, t.f3, t.f4, t.f5].map((s) => li(`${s} — ${t.fText}`)) }] }] }])]),
86
- m("feat-alt", "features", "tinh nang xen ke anh alternating", [
87
- section([
88
- { type: "mediaText", attrs: { position: "left", width: 45, verticalAlign: "center" }, content: [h(2, t.f1), p(t.fText), buttons("left", btn(t.more, "outline"))] },
89
- { type: "spacer", attrs: { height: "xl" } },
90
- { type: "mediaText", attrs: { position: "right", width: 45, verticalAlign: "center" }, content: [h(2, t.f2), p(t.fText), buttons("left", btn(t.more, "outline"))] }])]),
91
-
92
- // ---------------- stats / steps ----------------
93
- m("stats4", "stats", "so lieu con so stats numbers", [
94
- section([grid(4, [stat(t.n1, t.l1), stat(t.n2, t.l2), stat(t.n3, t.l3), stat(t.n4, t.l4)], { motion: { in: "zoom-in", stagger: true } })])]),
95
- m("stats-band", "stats", "dai so lieu stats band", [
96
- section([grid(3, [stat(t.n1, t.l1), stat(t.n2, t.l2), stat(t.n3, t.l3)], { motion: { in: "fade", stagger: true } })], { color: { background: "surface" }, radius: "16px" })]),
97
- m("steps3", "steps", "quy trinh buoc process steps", [
98
- section([big(t.title), { type: "spacer", attrs: { height: "md" } }, grid(3, [step(1, t.s1), step(2, t.s2), step(3, t.s3)], slideUp())])]),
99
- m("steps-v", "steps", "quy trinh doc timeline vertical", [
100
- section([h(2, t.title), { type: "orderedList", content: [t.s1, t.s2, t.s3, t.s4].map((s) => ({ type: "listItem", content: [{ type: "paragraph", content: [text(s, [{ type: "bold" }])] }, p(t.sText)] })) }], { maxWidth: { base: "720px" } })]),
101
-
102
- // ---------------- pricing ----------------
103
- m("price2", "pricing", "bang gia 2 goi pricing", [
104
- section([big(t.title), { type: "spacer", attrs: { height: "md" } }, grid(2, [plan(t.plan1, "199k", false), plan(t.plan2, `499k${t.perMonth}`, true)], { maxWidth: { base: "860px" }, margin: { base: { left: "auto", right: "auto" } } })])]),
105
- m("price-table", "pricing", "bang so sanh goi comparison table", [
106
- section([h(2, t.title, center), table([[t.feature, t.plan1, t.plan2, t.plan3], [`${t.item} 1`, t.yes, t.yes, t.yes], [`${t.item} 2`, t.no, t.yes, t.yes], [`${t.item} 3`, t.no, t.no, t.yes]])])]),
107
-
108
- // ---------------- testimonials ----------------
109
- m("test3", "testimonials", "cam nhan khach hang testimonials 3", [
110
- section([big(t.title), { type: "spacer", attrs: { height: "md" } }, grid(3, [quoteCard(t.quote1, t.who1), quoteCard(t.quote2, t.who2), quoteCard(t.quote3, t.who3)], slideUp())])]),
111
- m("test-big", "testimonials", "cam nhan lon trich dan quote big", [
112
- section([{ type: "pullquote", attrs: { citation: t.who1, style: { fontSize: { base: "xl" } } }, content: [text(t.bigQuote)] }], { padding: { base: "2xl" }, motion: { in: "fade" } })]),
113
-
114
- // ---------------- faq ----------------
115
- m("faq2", "faq", "hoi dap 2 cot faq", [
116
- section([{ type: "columns", content: [
117
- { type: "column", content: [eyebrow(t.eyebrow), h(2, t.title), muted(t.sub)] },
118
- { type: "column", content: [t.q1, t.q2, t.q3].map((q) => ({ type: "details", attrs: { summary: q }, content: [p(t.a)] })) }] }])]),
119
- m("faq5", "faq", "hoi dap thuong gap faq 5", [
120
- section([h(2, t.title, center), ...[t.q1, t.q2, t.q3, t.q4, t.q5].map((q) => ({ type: "details", attrs: { summary: q }, content: [p(t.a)] }))], { maxWidth: { base: "760px" } })]),
121
-
122
- // ---------------- cta ----------------
123
- m("cta-band", "cta", "keu goi nen mau cta band gradient", [
124
- section([h(2, t.title, { style: { ...center, color: { text: "#ffffff" } } }), p(t.sub, { style: { ...center, color: { text: "#ffffff" } } }), buttons("center", WHITE_BTN(t.start))],
125
- { gradient: GRADIENT, radius: "16px", padding: { base: "2xl", mobile: "xl" }, motion: { in: "zoom-in" } })]),
126
- m("cta-split", "cta", "keu goi chia doi cta split", [
127
- section([{ type: "columns", attrs: { verticalAlign: "center" }, content: [
128
- { type: "column", attrs: { width: 65 }, content: [h(2, t.title), muted(t.sub)] },
129
- { type: "column", attrs: { width: 35 }, content: [buttons("right", btn(t.start))] }] }], { color: { background: "surface" }, radius: "16px" })]),
130
- m("cta-contact", "cta", "goi dien zalo lien he nhanh cta", [
131
- section([h(2, t.title, center), muted(t.sub, center), buttons("center", btn(t.call), btn(t.chat, "outline"))], { motion: { in: "slide-up" } })]),
132
-
133
- // ---------------- team / logos ----------------
134
- m("team4", "team", "doi ngu thanh vien team 4", [
135
- section([big(t.title), { type: "spacer", attrs: { height: "md" } }, grid(4, [member(), member(), member(), member()], slideUp())])]),
136
- m("team-intro", "team", "gioi thieu doi ngu anh nhom team intro", [
137
- section([{ type: "mediaText", attrs: { position: "left", width: 50, verticalAlign: "center" }, content: [eyebrow(t.eyebrow), h(2, t.title), p(t.sub), buttons("left", btn(t.more, "outline"))] }])]),
138
- m("logos", "logos", "doi tac logo khach hang logos", [
139
- section([muted(t.trusted, { ...center, textTransform: "uppercase", letterSpacing: "0.08em", fontSize: { base: "sm" } }), grid(5, [1, 2, 3, 4, 5].map(() => img(t.logo)), { motion: { in: "fade", stagger: true } })])]),
140
-
141
- // ---------------- contact ----------------
142
- m("contact-form", "contact", "lien he form gui tin nhan contact form", [
143
- section([{ type: "columns", attrs: { verticalAlign: "top" }, content: [
144
- { type: "column", attrs: { width: 40 }, content: [eyebrow(t.l_contact), h(2, t.contactTitle), muted(t.contactSub, { fontSize: { base: "lg" } }), { type: "spacer", attrs: { height: "sm" } },
145
- { type: "group", attrs: { style: { layout: { type: "flex", direction: { base: "column" } }, gap: "lg" } }, content: [
146
- infoRow("phone", t.phone, t.phoneV), infoRow("mail", t.email, t.emailV), infoRow("mapPin", t.address, t.addressV), infoRow("clock", t.hours, t.hoursV)] }] },
147
- { type: "column", attrs: { width: 60 }, content: [card([contactForm(true)], { padding: { base: "xl", mobile: "lg" }, shadow: "md", motion: undefined })] }] }],
148
- { motion: { in: "fade" } })]),
149
- m("contact-split", "contact", "lien he chia doi contact split", [
150
- section([{ type: "columns", content: [
151
- { type: "column", content: [h(2, t.contactTitle), muted(t.contactSub), p(`${t.address}: ${t.addressV}`), p(`${t.phone}: ${t.phoneV}`), p(`${t.email}: ${t.emailV}`),
152
- { type: "socialLinks", attrs: { links: [{ service: "facebook", url: "https://facebook.com" }, { service: "zalo", url: "https://zalo.me" }, { service: "email", url: "mailto:hello@example.com" }] } }] },
153
- { type: "column", content: [contactForm()] }] }])]),
154
- m("contact-cards", "contact", "the lien he dia chi dien thoai email contact cards", [
155
- section([h(2, t.contactTitle, center), muted(t.contactSub, center), { type: "spacer", attrs: { height: "md" } }, grid(3, [info(t.address, t.addressV), info(t.phone, t.phoneV), info(t.email, t.emailV)], slideUp())])]),
156
-
157
- // ---------------- text ----------------
158
- m("text-cols", "text", "hai cot chu text columns", [
159
- section([h(2, t.title), { type: "columns", content: [{ type: "column", content: [h(3, t.twoColA), p(t.body), p(t.body)] }, { type: "column", content: [h(3, t.twoColB), p(t.body), p(t.body)] }] }])]),
160
- m("text-note", "text", "ghi chu luu y callout note", [
161
- section([{ type: "callout", attrs: { tone: "info", title: t.note }, content: [p(t.noteText)] }, p(t.body)], { maxWidth: { base: "760px" } })]),
162
-
163
- // ---------------- footer ----------------
164
- m("footer-simple", "footer", "chan trang gon footer", [
165
- section([p(t.copyright, { style: { ...center, color: { text: "muted" }, fontSize: { base: "sm" } } }), { type: "socialLinks", attrs: { align: "center", links: [{ service: "facebook", url: "https://facebook.com" }, { service: "youtube", url: "https://youtube.com" }, { service: "zalo", url: "https://zalo.me" }] } }], { padding: { base: "xl" } })]),
166
- m("footer-cols", "footer", "chan trang 3 cot footer links", [
167
- section([{ type: "columns", content: [links(t.footerAbout, [t.l_about, t.l_news, t.l_jobs]), links(t.footerHelp, [t.l_faq, t.l_guide, t.l_contact]), links(t.footerLegal, [t.l_terms, t.l_privacy, t.l_refund])] },
168
- p(t.copyright, { style: { color: { text: "muted" }, fontSize: { base: "sm" } } })], { padding: { base: "xl" } })]),
169
- ];
170
- }
171
-
172
- export const libraryPatterns = (locale: string): Pattern[] => library(msgs("patternLib", locale));