@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,5 +1,6 @@
1
1
  import type { BlockAttrSpec } from "@ecomcx/ecomweb-content";
2
- import { useEffect, useState, type ReactNode } from "react";
2
+ import { AlignCenter, AlignHorizontalSpaceBetween, AlignJustify, AlignLeft, AlignRight, RotateCcw } from "lucide-react";
3
+ import { useEffect, useState, type ComponentType, type ReactNode } from "react";
3
4
  import { useEditor } from "../context";
4
5
  import type { Choice, ChoiceKind } from "../core/host";
5
6
  import type { BlockType } from "../core/registry";
@@ -7,6 +8,7 @@ import { messages } from "../../i18n";
7
8
  import { blockOptions } from "../../shared/block-defs";
8
9
  import { DEFAULT_IMAGE_SIZES, hintOf, hintText, imageSizeLabel, optionLabel, type AttrHint } from "./attr-hints";
9
10
  import { ColorInput } from "./color-field";
11
+ import { IconPicker } from "./icon-picker";
10
12
  import { mediaSrcsets } from "../core/media";
11
13
 
12
14
  export const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
@@ -38,7 +40,7 @@ export function Field({ label, children, group }: { label: string; children: Rea
38
40
  }
39
41
 
40
42
  /** Lựa chọn lấy từ ứng dụng (host.choices); null = ứng dụng không cung cấp → ô gõ tay. */
41
- function useChoices(kind: ChoiceKind | undefined, args: Record<string, string> | undefined): Choice[] | null | undefined {
43
+ export function useChoices(kind: ChoiceKind | undefined, args: Record<string, string> | undefined): Choice[] | null | undefined {
42
44
  const { host, labels } = useEditor();
43
45
  const key = JSON.stringify([kind, args]);
44
46
  const [state, setState] = useState<{ key: string; list: Choice[] | null } | null>(null);
@@ -54,12 +56,17 @@ function useChoices(kind: ChoiceKind | undefined, args: Record<string, string> |
54
56
  return state?.key === key ? state.list : undefined;
55
57
  }
56
58
 
59
+ /** Giá trị căn → biểu tượng (như thanh căn chữ của WP): hàng chọn căn chỉ toàn các giá trị này thì vẽ bằng biểu tượng, chữ nằm ở tooltip / nhãn đọc màn hình. */
60
+ const ALIGN_ICONS: Record<string, ComponentType<{ className?: string }>> = { left: AlignLeft, center: AlignCenter, right: AlignRight, justify: AlignJustify, "space-between": AlignHorizontalSpaceBetween };
57
61
  function SegText({ value, options, onChange, label }: { value: string | undefined; options: Array<[string, string]>; onChange(v: string | undefined): void; label: string }) {
62
+ // Từ 3 lựa chọn trở lên: hai lựa chọn trái / phải thường là vị trí (icon trước / sau chữ), không phải căn
63
+ const icons = options.length > 2 && options.every(([v]) => ALIGN_ICONS[v]);
58
64
  return (
59
- <div role="radiogroup" aria-label={label} className="ecx-seg is-text">
60
- {options.map(([v, text]) => (
61
- <button key={v} type="button" role="radio" aria-checked={value === v} className={cx("ecx-seg-btn", value === v && "is-active")} onClick={() => onChange(value === v ? undefined : v)}>{text}</button>
62
- ))}
65
+ <div role="radiogroup" aria-label={label} className={cx("ecx-seg", !icons && "is-text")}>
66
+ {options.map(([v, text]) => {
67
+ const Icon = icons ? ALIGN_ICONS[v] : undefined;
68
+ return <button key={v} type="button" role="radio" aria-checked={value === v} aria-label={Icon ? text : undefined} title={Icon ? text : undefined} className={cx("ecx-seg-btn", value === v && "is-active")} onClick={() => onChange(value === v ? undefined : v)}>{Icon ? <Icon className="ecx-icon" /> : text}</button>;
69
+ })}
63
70
  </div>
64
71
  );
65
72
  }
@@ -79,6 +86,22 @@ function ChoiceField({ hint, attrs, value, set, label }: { hint: AttrHint; attrs
79
86
  );
80
87
  }
81
88
 
89
+ /** Chọn nhiều mục (danh sách tích): giá trị lưu là các mã cách nhau dấu phẩy. */
90
+ function MultiChoiceField({ hint, attrs, value, set, label }: { hint: AttrHint; attrs: Record<string, unknown>; value: unknown; set(v: unknown): void; label: string }) {
91
+ const { labels } = useEditor();
92
+ const list = useChoices(hint.choice?.kind, hint.choice?.args?.(attrs));
93
+ const picked = new Set(String(value ?? "").split(",").map((x) => x.trim()).filter(Boolean));
94
+ if (list === null) return <input className="ecx-input" aria-label={label} value={String(value ?? "")} onChange={(e) => set(e.target.value || undefined)} />;
95
+ if (list === undefined) return <span className="ecx-muted">{labels.choiceLoading}</span>;
96
+ const toggle = (v: string) => { const next = new Set(picked); if (next.has(v)) next.delete(v); else next.add(v); set(next.size ? [...next].join(",") : undefined); };
97
+ return (
98
+ <div className="ecx-multichoice" role="group" aria-label={label}>
99
+ {list.map((c) => <label key={c.value} className="ecx-check"><input type="checkbox" checked={picked.has(c.value)} onChange={() => toggle(c.value)} /> {c.label}</label>)}
100
+ {!list.length && <span className="ecx-muted">{labels.choiceSelect}</span>}
101
+ </div>
102
+ );
103
+ }
104
+
82
105
  /** Form thuộc tính tự sinh từ mô tả khối + gợi ý hiển thị (attr-hints): không phải viết giao diện cho từng khối. */
83
106
  export function AttrForm({ type, attrs, onChange }: { type: BlockType; attrs: Record<string, any>; onChange(a: Record<string, unknown>): void }) {
84
107
  const { host, labels } = useEditor();
@@ -89,9 +112,26 @@ export function AttrForm({ type, attrs, onChange }: { type: BlockType; attrs: Re
89
112
  .map(([k, s]) => [k, s, hintOf(type.name, k)] as const)
90
113
  .filter(([k, s, h]) => !HIDDEN_ATTRS.has(k) && controlOf(s) !== "hidden" && h.control !== "hidden" && (!h.when || h.when(attrs)));
91
114
  if (!entries.length) return null;
115
+ const resetLabel = String(messages("controls", lang).reset ?? "Reset");
92
116
  return (
93
117
  <div className="ecx-form">
94
118
  {entries.map(([k, spec, hint]) => {
119
+ const node = field(k, spec, hint);
120
+ // Ô đã đổi khác mặc định: nút ↶ về mặc định (như ô của tab Kiểu dáng)
121
+ const v = attrs[k];
122
+ if (v === undefined || v === null || v === "" || JSON.stringify(v) === JSON.stringify(spec.default) || !node) return node;
123
+ const label = hintText(hint, "label", lang) ?? attrLabel(k, spec, lang, translate);
124
+ return (
125
+ <div key={k} className="ecx-field-wrap">
126
+ {node}
127
+ <button type="button" className="ecx-row-reset ecx-field-reset" title={resetLabel} aria-label={`${resetLabel}: ${label}`} onClick={() => onChange({ [k]: undefined })}><RotateCcw className="ecx-icon" /></button>
128
+ </div>
129
+ );
130
+ })}
131
+ </div>
132
+ );
133
+
134
+ function field(k: string, spec: BlockAttrSpec, hint: AttrHint) {
95
135
  const label = hintText(hint, "label", lang) ?? attrLabel(k, spec, lang, translate);
96
136
  const value = attrs[k] ?? spec.default;
97
137
  const set = (v: unknown) => onChange({ [k]: v === "" || v === spec.default ? undefined : v });
@@ -109,7 +149,11 @@ export function AttrForm({ type, attrs, onChange }: { type: BlockType; attrs: Re
109
149
  return <label key={k} className="ecx-check"><input type="checkbox" checked={value === "_blank"} onChange={(e) => set(e.target.checked ? "_blank" : undefined)} /> {labels.openInNewTab}</label>;
110
150
  case "segmented":
111
151
  return <Field key={k} label={label} group><SegText label={label} value={value == null ? undefined : String(value)} options={opts()} onChange={(v) => set(v === undefined ? undefined : parse(v))} />{help}</Field>;
112
- case "select":
152
+ case "select": {
153
+ // Ít lựa chọn, chữ ngắn → dãy nút bấm (một chạm, thấy hết lựa chọn) như bảng của các bộ khối lớn; cấp tiêu đề → H1…H6
154
+ const list = k === "level" ? opts().map(([v]) => [v, `H${v}`] as [string, string]) : opts();
155
+ if (list.length >= 2 && list.length <= 6 && list.every(([, text]) => text.length <= 12))
156
+ return <Field key={k} label={label} group><SegText label={label} value={value == null ? undefined : String(value)} options={list} onChange={(v) => set(v === undefined ? undefined : parse(v))} />{help}</Field>;
113
157
  return (
114
158
  <Field key={k} label={label}>
115
159
  <select className="ecx-input" value={value == null ? "" : String(value)} onChange={(e) => set(parse(e.target.value))}>
@@ -119,6 +163,11 @@ export function AttrForm({ type, attrs, onChange }: { type: BlockType; attrs: Re
119
163
  {help}
120
164
  </Field>
121
165
  );
166
+ }
167
+ case "icon":
168
+ return <Field key={k} label={label}><IconPicker label={label} value={value == null ? undefined : String(value)} allowNone={hint.allowNone} onChange={(v) => set(v)} />{help}</Field>;
169
+ case "multichoice":
170
+ return <Field key={k} label={label}><MultiChoiceField hint={hint} attrs={attrs} value={value} set={set} label={label} />{help}</Field>;
122
171
  case "choice":
123
172
  return <Field key={k} label={label}><ChoiceField hint={hint} attrs={attrs} value={value} set={set} label={label} />{help}</Field>;
124
173
  case "range": {
@@ -151,7 +200,7 @@ export function AttrForm({ type, attrs, onChange }: { type: BlockType; attrs: Re
151
200
  case "textarea":
152
201
  return <Field key={k} label={label}><textarea className="ecx-input" rows={3} value={value == null ? "" : String(value)} onChange={(e) => set(e.target.value)} />{help}</Field>;
153
202
  case "color":
154
- return <Field key={k} label={label} group><ColorInput label={label} value={value == null ? undefined : String(value)} onChange={(v) => set(v)} />{help}</Field>;
203
+ return <div key={k} className="ecx-field"><ColorInput label={label} value={value == null ? undefined : String(value)} onChange={(v) => set(v)} />{help}</div>;
155
204
  case "media":
156
205
  return (
157
206
  <Field key={k} label={label}>
@@ -163,9 +212,7 @@ export function AttrForm({ type, attrs, onChange }: { type: BlockType; attrs: Re
163
212
  </Field>
164
213
  );
165
214
  default:
166
- return <Field key={k} label={label}><input className="ecx-input" type={controlOf(spec) === "url" ? "url" : "text"} value={value == null ? "" : String(value)} onChange={(e) => set(e.target.value)} />{help}</Field>;
215
+ return <Field key={k} label={label}><input className="ecx-input" type={controlOf(spec) === "url" ? "url" : "text"} value={value == null ? "" : String(value)} placeholder={hintText(hint, "placeholder", lang)} onChange={(e) => set(e.target.value)} />{help}</Field>;
167
216
  }
168
- })}
169
- </div>
170
- );
217
+ }
171
218
  }
@@ -14,7 +14,9 @@ export interface AttrHint {
14
14
  label?: true;
15
15
  /** Khoá của hint (do hintOf điền) — dùng tra chữ. */
16
16
  key?: string;
17
- control?: "select" | "segmented" | "range" | "choice" | "newTab" | "suggest" | "code" | "hidden";
17
+ control?: "select" | "segmented" | "range" | "choice" | "multichoice" | "newTab" | "suggest" | "code" | "hidden" | "icon";
18
+ /** control "icon": có lựa chọn "Không có icon". */
19
+ allowNone?: true;
18
20
  options?: Opt[];
19
21
  /** Ô chọn lấy dữ liệu từ ứng dụng (host.choices); tham số tính từ thuộc tính hiện tại. */
20
22
  choice?: { kind: ChoiceKind; args?: (attrs: Record<string, unknown>) => Record<string, string> };
@@ -27,6 +29,8 @@ export interface AttrHint {
27
29
  when?: (attrs: Record<string, unknown>) => boolean;
28
30
  /** Có ghi chú dưới ô (chữ: hints "<khoá>.help"). */
29
31
  help?: true;
32
+ /** Có chữ gợi ý trong ô trống (chữ: hints "<khoá>.placeholder"). */
33
+ placeholder?: true;
30
34
  }
31
35
 
32
36
  const ALIGN: Opt[] = ["left", "center", "right"];
@@ -39,6 +43,81 @@ const levels = (from: number, to: number, zero?: boolean): Opt[] => [
39
43
  const notInherit = (a: Record<string, unknown>) => a.inherit === false;
40
44
 
41
45
  export const ATTR_HINTS: Record<string, AttrHint> = {
46
+ // v3: chọn icon bằng lưới có ô tìm (mọi khối có thuộc tính icon); nút: icon trái / phải, rộng hết khung, nhãn trình đọc màn hình
47
+ "*.icon": { control: "icon" },
48
+ "button.icon": { control: "icon", allowNone: true },
49
+ "tab.icon": { control: "icon", allowNone: true, label: true },
50
+ "tab.subtitle": { label: true },
51
+ "tabs.orientation": { control: "segmented", label: true, options: ["horizontal", "vertical"] },
52
+ "tabs.mobileAccordion": { label: true },
53
+ "tabs.iconPosition": { control: "segmented", label: true, options: ["left", "right", "top"] },
54
+ "tabs.iconOnly": { label: true, help: true },
55
+ "buttons.orientation": { control: "segmented", label: true, options: ["horizontal", "vertical"] },
56
+ "button.iconOnly": { label: true, when: (a) => !!a.icon },
57
+ "button.iconReveal": { label: true, when: (a) => !!a.icon && a.iconOnly !== true },
58
+ "countdown.layout": { control: "segmented", label: true, options: ["block", "inline"] },
59
+ "countdown.divider": { label: true },
60
+ "countdown.pad": { label: true },
61
+ "countdown.postText": { label: true },
62
+ "countdown.showDays": { label: true },
63
+ "countdown.showSeconds": { label: true },
64
+ "countdown.daysLabel": { label: true, when: (a) => a.showDays !== false },
65
+ "countdown.hoursLabel": { label: true },
66
+ "countdown.minutesLabel": { label: true },
67
+ "countdown.secondsLabel": { label: true, when: (a) => a.showSeconds !== false },
68
+ "map.address": { label: true, help: true },
69
+ "map.title": { label: true, help: true },
70
+ "map.zoom": { control: "range", label: true, min: 1, max: 20, step: 1 },
71
+ "map.height": { control: "range", label: true, min: 150, max: 1000, step: 10, unit: "px" },
72
+ "map.mapType": { control: "segmented", label: true, options: ["roadmap", "satellite"] },
73
+ "progressBar.max": { label: true },
74
+ "progressBar.prefix": { label: true, when: (a) => a.showValue !== false },
75
+ "progressBar.suffix": { label: true, help: true, when: (a) => a.showValue !== false },
76
+ "progressBar.textPosition": { control: "segmented", label: true, options: ["above", "inside", "below"] },
77
+ "progressBar.duration": { label: true, help: true, when: (a) => a.animate !== false },
78
+ "progressBar.decimals": { control: "segmented", label: true, options: ["0", "1", "2"], when: (a) => a.showValue !== false },
79
+ "progressBar.animate": { label: true },
80
+ "progressBar.easing": { control: "select", label: true, options: ["ease", "linear", "ease-in", "ease-out", "ease-in-out"], when: (a) => a.animate !== false },
81
+ "progressBar.ariaLabel": { label: true, help: true },
82
+ "iconBox.media": { control: "segmented", label: true, options: ["icon", "image", "number", "none"] },
83
+ "iconBox.src": { label: true, when: (a) => a.media === "image" },
84
+ "iconBox.alt": { when: (a) => a.media === "image" },
85
+ "iconBox.width": { when: (a) => a.media === "image" },
86
+ "iconBox.height": { when: (a) => a.media === "image" },
87
+ "iconBox.verticalAlign": { control: "segmented", label: true, options: ["top", "center", "bottom"], when: (a) => a.media !== "none" && (a.position === "left" || a.position === "right") },
88
+ "iconBox.fullHeight": { label: true, help: true },
89
+ "iconBox.number": { label: true, when: (a) => a.media === "number" },
90
+ "iconBox.iconStyle": { control: "segmented", label: true, options: ["plain", "circle", "square"], when: (a) => a.media !== "none" && a.media !== "image" },
91
+ "iconBox.hover": { control: "segmented", label: true, options: ["none", "grow", "flip"], when: (a) => a.media !== "none" },
92
+ "iconBox.linkMode": { control: "segmented", label: true, options: ["title", "box", "button"] },
93
+ "iconBox.buttonText": { label: true, help: true, when: (a) => a.linkMode === "button" },
94
+ "tableOfContents.minLevel": { control: "select", label: true, options: levels(2, 6) },
95
+ "tableOfContents.showTitle": { label: true, when: (a) => a.collapsible !== true },
96
+ "tableOfContents.collapsible": { label: true },
97
+ "tableOfContents.startCollapsed": { label: true, when: (a) => a.collapsible === true },
98
+ "tableOfContents.listStyle": { control: "segmented", label: true, options: ["numbers", "bullets", "none"] },
99
+ "tableOfContents.columns": { control: "segmented", label: true, options: [1, 2, 3] },
100
+ "tableOfContents.smoothScroll": { label: true },
101
+ "tableOfContents.highlight": { label: true },
102
+ "accordion.columns": { control: "segmented", label: true, options: [1, 2] },
103
+ "accordion.icon": { control: "segmented", label: true, options: ["arrow", "plus", "none"] },
104
+ "accordion.iconSide": { control: "segmented", label: true, options: ["left", "right"] },
105
+ "accordion.titleTag": { control: "segmented", label: true, help: true },
106
+ "accordion.faq": { label: true, help: true },
107
+ "accordion.startOpen": { control: "segmented", label: true, help: true, options: ["none", "first", "all"] },
108
+ "paragraph.icon": { control: "icon", allowNone: true, label: true },
109
+ "paragraph.iconPosition": { control: "segmented", label: true, options: ["left", "right"], when: (a) => !!a.icon },
110
+ "paragraph.iconTitle": { label: true, help: true, when: (a) => !!a.icon },
111
+ "heading.icon": { control: "icon", allowNone: true, label: true },
112
+ "heading.iconPosition": { control: "segmented", label: true, options: ["left", "right"], when: (a) => !!a.icon },
113
+ "heading.iconTitle": { label: true, help: true, when: (a) => !!a.icon },
114
+ "heading.tocTitle": { label: true, help: true },
115
+ "button.iconPosition": { control: "segmented", options: ["left", "right"], when: (a) => !!a.icon },
116
+ "button.text": { placeholder: true },
117
+ "button.href": { placeholder: true },
118
+ "button.width": { control: "segmented", options: ["auto", "full"] },
119
+ "button.ariaLabel": { help: true },
120
+ "tabs.tabsAlign": { control: "segmented", options: ["flex-start", "center", "flex-end", "space-between"] },
42
121
  "*.textAlign": { control: "segmented", options: [...ALIGN, "justify"] },
43
122
  "*.mime": { control: "hidden" },
44
123
  "video.name": { control: "hidden" },
@@ -95,7 +174,8 @@ export const ATTR_HINTS: Record<string, AttrHint> = {
95
174
  "socialLinks.align": { control: "segmented", options: ALIGN },
96
175
  "navigation.location": { control: "choice", choice: { kind: "menuLocation" }, help: true },
97
176
  "navigation.orientation": { control: "segmented", options: ["horizontal", "vertical"] },
98
- "navigation.overlayMenu": { control: "segmented", label: true, options: ["never", "mobile", "always"] },
177
+ "navigation.overlayMenu": { control: "segmented", label: true, options: ["never", "mobile", "tablet", "always"] },
178
+ "gallery.layout": { control: "segmented", label: true, options: ["grid", "masonry"] },
99
179
  "gallery.linkTo": { control: "segmented", label: true, options: ["none", "media"] },
100
180
  "gallery.imageCrop": { label: true },
101
181
  "gallery.lightbox": { label: true },
@@ -103,12 +183,21 @@ export const ATTR_HINTS: Record<string, AttrHint> = {
103
183
  // 1.27: form cơ bản
104
184
  "form.formId": { control: "hidden" },
105
185
  "form.notifyEmail": { help: true },
186
+ "form.notifyCc": { label: true, help: true },
187
+ "form.emailSubject": { label: true, help: true },
188
+ "form.redirect": { label: true, help: true },
189
+ "form.inputSize": { control: "segmented", label: true, options: ["sm", "md", "lg"] },
106
190
  "formField.kind": { control: "select", options: ["text", "email", "tel", "textarea", "select", "radio", "checkbox", "consent", "number", "date"] },
107
191
  "formField.name": { label: true, help: true },
108
192
  "formField.label": { label: true, help: true },
109
- "formField.width": { control: "segmented", options: ["full", "half"] },
193
+ "formField.width": { control: "segmented", options: ["full", "half", "third"] },
194
+ "formField.autocomplete": { control: "select", label: true, help: true, when: (a) => !["checkbox", "consent", "radio", "select"].includes(String(a.kind ?? "text")), options: ["off", "name", "given-name", "family-name", "email", "tel", "organization", "street-address", "address-level1", "address-level2", "postal-code", "country-name", "bday"] },
110
195
  "search.showLabel": { label: true },
111
196
  "search.buttonPosition": { control: "segmented", label: true, options: ["right", "left", "below"] },
197
+ "search.buttonStyle": { control: "segmented", label: true, options: ["text", "icon"] },
198
+ "search.collapse": { control: "segmented", label: true, help: true, options: ["never", "tablet", "mobile"] },
199
+ "search.scopeSelect": { label: true, help: true },
200
+ "search.scopes": { label: true, help: true, when: (a) => a.scopeSelect === true },
112
201
  "postAuthor.showName": { label: true },
113
202
  "postAuthor.showBio": { label: true },
114
203
  "postAuthor.avatarSize": { label: true },
@@ -124,24 +213,38 @@ export const ATTR_HINTS: Record<string, AttrHint> = {
124
213
  "pageList.parentId": { label: true },
125
214
  "archives.showCount": { label: true },
126
215
  "icon.name": { control: "select", options: [...ICON_NAMES] },
127
- "iconBox.icon": { control: "select", options: [...ICON_NAMES] },
128
- "iconBox.position": { control: "segmented", label: true, options: ["top", "left"] },
216
+ "icon.stroke": { control: "range", label: true, min: 0.5, max: 4, step: 0.5 },
217
+ "icon.iconStyle": { control: "segmented", label: true, options: ["plain", "circle", "square"] },
218
+ "icon.linkTarget": { control: "segmented", label: true, options: ["_self", "_blank"], when: (a) => !!a.href },
219
+ "iconBox.icon": { control: "select", options: [...ICON_NAMES], when: (a) => a.media !== "number" && a.media !== "none" && a.media !== "image" },
220
+ "iconBox.position": { control: "segmented", label: true, options: ["top", "left", "right"] },
129
221
  "iconBox.level": { control: "select", options: levels(2, 6) },
130
222
  "imageBox.level": { control: "select", options: levels(2, 6) },
131
223
  "imageBox.src": { label: true },
132
224
  "iconList.icon": { control: "select", options: [...ICON_NAMES] },
133
225
  "iconList.layout": { control: "segmented", options: ["list", "inline"] },
226
+ "iconList.columns": { control: "range", label: true, min: 1, max: 4, step: 1, when: (a) => a.layout !== "inline" },
227
+ "iconList.iconAlign": { control: "segmented", label: true, options: ["top", "center", "bottom"] },
228
+ "iconList.iconStyle": { control: "segmented", label: true, options: ["plain", "circle", "square"] },
229
+ "iconList.stroke": { control: "range", label: true, min: 0.5, max: 4, step: 0.5 },
134
230
  "counter.start": { label: true },
135
231
  "counter.prefix": { label: true },
136
232
  "counter.separator": { control: "select", label: true, options: ["none", ",", ".", "space"] },
137
233
  "counter.duration": { help: true },
234
+ "counter.decimals": { label: true, help: true },
235
+ "counter.titleTag": { control: "select", label: true, options: ["p", "div", "h2", "h3", "h4", "h5", "h6"] },
138
236
  "testimonial.src": { label: true },
139
- "progressBar.value": { control: "range", label: true, min: 0, max: 100, step: 1, unit: "%" },
237
+ "testimonial.variant": { control: "segmented", label: true, options: ["card", "plain", "bubble"] },
238
+ "testimonial.rating": { control: "range", label: true, help: true, min: 0, max: 5, step: 1 },
239
+ "testimonial.quoteMark": { label: true },
240
+ "progressBar.value": { label: true },
140
241
  "languageSwitcher.display": { control: "segmented", options: ["inline", "dropdown"] },
141
242
  "postTerms.taxonomy": { control: "choice", choice: { kind: "taxonomy" } },
142
243
  "query.postType": { control: "choice", choice: { kind: "postType" }, when: notInherit },
143
244
  "query.category": { control: "choice", choice: { kind: "term", args: () => ({ taxonomy: "category" }) }, when: notInherit },
144
245
  "query.tag": { control: "choice", choice: { kind: "term", args: () => ({ taxonomy: "post_tag" }) }, when: notInherit },
246
+ "query.taxonomy": { control: "choice", choice: { kind: "taxonomy" }, label: true, help: true, when: notInherit },
247
+ "query.term": { control: "choice", choice: { kind: "term", args: (a) => ({ taxonomy: String(a.taxonomy ?? "") }) }, label: true, when: (a) => a.inherit === false && !!a.taxonomy },
145
248
  "query.perPage": { when: notInherit },
146
249
  "query.orderBy": { control: "select", options: ["date", "modified", "title", "comment_count", "menu_order", "rand"], when: notInherit },
147
250
  "query.authorId": { label: true, when: notInherit },
@@ -154,12 +257,40 @@ export const ATTR_HINTS: Record<string, AttrHint> = {
154
257
  "orderedList.reversed": { label: true },
155
258
  "blockquote.citation": { label: true },
156
259
  "postDate.displayType": { control: "segmented", label: true, options: ["published", "modified"] },
260
+ "query.source": { control: "segmented", label: true, options: ["latest", "manual", "related"], when: notInherit },
261
+ "query.include": { label: true, help: true, placeholder: true, when: (a) => a.inherit === false && a.source === "manual" },
262
+ "query.terms": { control: "multichoice", choice: { kind: "term", args: (a) => ({ taxonomy: String(a.taxonomy ?? "") }) }, label: true, when: (a) => !!a.taxonomy },
263
+ "query.termMode": { control: "segmented", label: true, options: ["any", "all", "none"], when: (a) => !!a.taxonomy && !!String(a.terms ?? "").trim() },
264
+ "query.metaKey": { label: true, help: true, placeholder: true, when: notInherit },
265
+ "query.metaCompare": { control: "select", label: true, options: ["=", "!=", ">", ">=", "<", "<=", "LIKE", "EXISTS", "NOT EXISTS"], when: (a) => a.inherit === false && !!a.metaKey },
266
+ "query.metaValue": { label: true, when: (a) => a.inherit === false && !!a.metaKey && !["EXISTS", "NOT EXISTS"].includes(String(a.metaCompare ?? "=")) },
267
+ "query.dateRange": { control: "select", label: true, options: ["any", "7", "30", "90", "365"], when: notInherit },
268
+ "query.after": { label: true, placeholder: true, when: notInherit },
269
+ "query.before": { label: true, placeholder: true, when: notInherit },
270
+ "query.parent": { label: true, help: true, when: notInherit },
271
+ "query.offset": { label: true, help: true, when: notInherit },
272
+ "query.excludeCurrent": { label: true, help: true, when: notInherit },
273
+ "query.authorCurrent": { label: true, when: notInherit },
274
+ "query.urlFilters": { label: true, help: true },
275
+ "queryFilter.taxonomy": { control: "choice", choice: { kind: "taxonomy" }, label: true, help: true },
276
+ "queryFilter.termStyle": { control: "segmented", label: true, options: ["none", "links", "chips", "select"], when: (a) => !!a.taxonomy },
277
+ "queryFilter.allLabel": { label: true, placeholder: true },
278
+ "queryFilter.showSearch": { label: true },
279
+ "queryFilter.showSort": { label: true },
280
+ "queryFilter.sortOptions": { label: true, help: true, placeholder: true, when: (a) => a.showSort === true },
281
+ "queryFilter.placeholder": { label: true, when: (a) => a.showSearch === true },
282
+ "queryFilter.submitText": { label: true },
283
+ "queryFilter.action": { label: true, help: true, placeholder: true },
157
284
  "query.paginate": { label: true, help: true, when: notInherit },
158
285
  "query.orderByMeta": { label: true, help: true, when: notInherit },
159
286
  "query.order": { control: "segmented", options: ["desc", "asc"], when: notInherit },
160
287
  "query.inherit": { help: true },
161
- "postTemplate.layout": { control: "segmented", options: ["list", "grid"] },
162
- "postTemplate.columns": { control: "range", min: 1, max: 6, step: 1, when: (a) => a.layout === "grid" },
288
+ "postTemplate.layout": { control: "segmented", options: ["list", "grid", "carousel"] },
289
+ "postTemplate.columns": { control: "range", min: 1, max: 6, step: 1, when: (a) => a.layout === "grid" || a.layout === "carousel" },
290
+ "postTemplate.columnsTablet": { control: "range", min: 1, max: 6, step: 1, label: true, when: (a) => a.layout === "grid" },
291
+ "postTemplate.columnsMobile": { control: "range", min: 1, max: 4, step: 1, label: true, when: (a) => a.layout === "grid" },
292
+ "postTemplate.gap": { label: true, help: true, when: (a) => a.layout === "grid" || a.layout === "carousel" },
293
+ "postTemplate.arrows": { label: true, when: (a) => a.layout === "carousel" },
163
294
  "templatePart.slug": { control: "choice", choice: { kind: "templatePart" } },
164
295
  "templatePart.tagName": { control: "select", options: ["div", "header", "footer", "aside", "section"] },
165
296
  };
@@ -172,7 +303,7 @@ export function hintOf(block: string, attr: string): AttrHint {
172
303
  const text = (v: unknown): string | undefined => (typeof v === "string" ? v : undefined);
173
304
 
174
305
  /** Chữ nhãn / ghi chú của hint theo ngôn ngữ (undefined nếu hint không khai báo). */
175
- export const hintText = (hint: AttrHint, part: "label" | "help", lang: string): string | undefined =>
306
+ export const hintText = (hint: AttrHint, part: "label" | "help" | "placeholder", lang: string): string | undefined =>
176
307
  hint[part] && hint.key ? text(messages("hints", lang)[`${hint.key}.${part}`]) : undefined;
177
308
 
178
309
  /** Nhãn của giá trị chọn: riêng của hint, rồi mẫu "Tiêu đề N", rồi nhãn chung của giá trị, cuối cùng là giá trị thô. */
@@ -4,7 +4,7 @@ import { useEditor } from "../context";
4
4
  import { useMsgs } from "../i18n";
5
5
  import { ColorInput } from "./color-field";
6
6
  import { GradientField } from "./layout-panel";
7
- import { Row, Section, Seg, cx } from "./style-controls";
7
+ import { Row, Section, Seg, StateTabs, cx } from "./style-controls";
8
8
 
9
9
  /** Điểm lấy nét chọn nhanh: lưới 3×3 (trên-trái … dưới-phải). */
10
10
  const POSITIONS = ["0% 0%", "50% 0%", "100% 0%", "0% 50%", "50% 50%", "100% 50%", "0% 100%", "50% 100%", "100% 100%"];
@@ -41,7 +41,14 @@ export function BackgroundControl({ type, attrs, setAttrs, device }: { type: str
41
41
  if (v) r[device] = v; else delete r[device];
42
42
  setBg({ [k]: Object.keys(r).length ? r : undefined });
43
43
  };
44
+ /** Màu riêng của khổ tablet / điện thoại (máy tính dùng style.color.background). */
45
+ const setBgColorAt = (v: string | undefined) => {
46
+ const r: Record<string, string | undefined> = { ...(bg.color ?? {}) };
47
+ if (v) r[device] = v; else delete r[device];
48
+ setBg({ color: Object.keys(r).length ? r : undefined });
49
+ };
44
50
  const setColor = (v: string | undefined) => {
51
+ if (device !== "base") return setBgColorAt(v);
45
52
  const next: BlockStyle = { ...style, color: { ...style.color, background: v } };
46
53
  if (legacy === undefined) return commitStyle(next);
47
54
  // Màu cũ của nhóm kéo theo khoảng đệm + bo góc trong vỏ → giữ nguyên dáng khi chuyển sang style
@@ -69,18 +76,58 @@ export function BackgroundControl({ type, attrs, setAttrs, device }: { type: str
69
76
  commitStyle(next, { ...(legacy ? { background: undefined } : {}), ...(cover ? { src: undefined, mediaId: undefined, overlay: undefined, opacity: undefined, fixed: undefined, focal: undefined } : {}) });
70
77
  };
71
78
 
79
+ const ovKind: "color" | "gradient" | "image" = bg.overlayImage ? "image" : bg.overlayGradient ? "gradient" : "color";
80
+ const [ovTab, setOvTab] = useState<"color" | "gradient" | "image" | null>(null);
81
+ const ovShown = ovTab ?? ovKind;
82
+ const hasOv = !!(overlay || bg.overlayGradient || bg.overlayImage);
83
+ const pickOverlayImage = async () => {
84
+ const [item] = (await host.media?.pick({ kind: "image", multiple: false })) ?? [];
85
+ if (item) setBg({ overlayImage: item.sizes?.large?.url ?? item.url, overlayOpacity: bg.overlayOpacity });
86
+ };
87
+ const BLENDS = ["multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "difference", "exclusion", "hue", "saturation", "color", "luminosity"];
88
+ const overlayFields = (
89
+ <>
90
+ {!cover && (
91
+ <Row label={t.overlayType}>
92
+ <div role="radiogroup" aria-label={t.overlayType} className="ecx-seg is-text">
93
+ {(["color", "gradient", "image"] as const).map((k) => (
94
+ <button key={k} type="button" role="radio" aria-checked={ovShown === k} className={cx("ecx-seg-btn", ovShown === k && "is-active")} onClick={() => setOvTab(k)}>{b.bg[k]}</button>
95
+ ))}
96
+ </div>
97
+ </Row>
98
+ )}
99
+ {(cover || ovShown === "color") && <ColorInput label={t.overlay} value={overlay} onChange={setOverlay} />}
100
+ {!cover && ovShown === "gradient" && <Row label={b.bg.gradient}><GradientField value={bg.overlayGradient} onChange={(g) => setBg({ overlayGradient: g, overlayOpacity: g ? bg.overlayOpacity : undefined })} /></Row>}
101
+ {!cover && ovShown === "image" && (
102
+ <Row label={t.image}>
103
+ <div className="ecx-bg-actions">
104
+ {host.media && <button type="button" className="ecx-btn" onClick={pickOverlayImage}>{bg.overlayImage ? t.replace : t.choose}</button>}
105
+ {bg.overlayImage && <button type="button" className="ecx-btn" onClick={() => setBg({ overlayImage: undefined })}>{t.remove}</button>}
106
+ </div>
107
+ </Row>
108
+ )}
109
+ {!cover && hasOv && (
110
+ <Row label={t.overlayBlend}>
111
+ <select className="ecx-input" aria-label={t.overlayBlend} value={bg.overlayBlend ?? ""} onChange={(e) => setBg({ overlayBlend: e.target.value || undefined })}>
112
+ <option value="">{t.blendNormal}</option>
113
+ {BLENDS.map((x) => <option key={x} value={x}>{(t as Record<string, string>)[`blend_${x.replace(/-/g, "_")}`] ?? x}</option>)}
114
+ </select>
115
+ </Row>
116
+ )}
117
+ {(hasOv || (cover && attrs.src)) && (
118
+ <Row label={`${t.opacity}: ${opacity}%`}>
119
+ <input type="range" min={0} max={100} step={5} value={opacity} aria-label={t.opacity} onChange={(e) => setOpacity(Number(e.target.value))} />
120
+ </Row>
121
+ )}
122
+ </>
123
+ );
72
124
  return (
73
- <Section title={b.bg.title} modified={modified} onReset={reset}>
74
- <div role="tablist" className="ecx-seg is-text ecx-state-tabs">
75
- {(["normal", "hover"] as const).map((s) => (
76
- <button key={s} type="button" role="tab" aria-selected={state === s} className={cx("ecx-seg-btn", state === s && "is-active")} onClick={() => setState(s)}>{b[s]}</button>
77
- ))}
78
- </div>
125
+ <>
126
+ <Section title={b.bg.title} modified={modified} onReset={reset} defaultOpen={type === "group" ? true : undefined}>
127
+ <StateTabs value={state} onChange={setState} />
79
128
  {state === "hover" ? (
80
129
  <>
81
- <Row label={b.bg.hoverColor}>
82
- <ColorInput label={b.bg.hoverColor} value={style.hover?.color?.background} onChange={(v) => commitStyle({ ...style, hover: { ...style.hover, color: { ...style.hover?.color, background: v } } })} />
83
- </Row>
130
+ <ColorInput label={b.bg.hoverColor} value={style.hover?.color?.background} onChange={(v) => commitStyle({ ...style, hover: { ...style.hover, color: { ...style.hover?.color, background: v } } })} />
84
131
  <p className="ecx-muted">{b.bg.hoverNote}</p>
85
132
  </>
86
133
  ) : (
@@ -93,10 +140,11 @@ export function BackgroundControl({ type, attrs, setAttrs, device }: { type: str
93
140
  </div>
94
141
  </Row>
95
142
  {kind === "color" && (
96
- <Row label={b.bg.color}>
97
- <ColorInput label={b.bg.color} value={style.color?.background ?? legacy} onChange={setColor} />
143
+ <>
144
+ <ColorInput label={b.bg.color} value={device === "base" ? style.color?.background ?? legacy : bg.color?.[device]} onChange={setColor} />
145
+ {device !== "base" && !bg.color?.[device] && <p className="ecx-muted">{b.bg.colorInherit}</p>}
98
146
  {legacy && !style.color?.background && <p className="ecx-muted">{b.bg.legacy}</p>}
99
- </Row>
147
+ </>
100
148
  )}
101
149
  {kind === "gradient" && <Row label={b.bg.gradient}><GradientField value={style.gradient} onChange={(g) => commitStyle({ ...style, gradient: g })} /></Row>}
102
150
  {kind === "image" && (
@@ -137,18 +185,14 @@ export function BackgroundControl({ type, attrs, setAttrs, device }: { type: str
137
185
  <label className="ecx-check"><input type="checkbox" checked={cover ? !!attrs.fixed : !!bg.fixed} onChange={(e) => (cover ? setAttrs({ fixed: e.target.checked || undefined }) : setBg({ fixed: e.target.checked || undefined }))} /> {t.fixed}</label>
138
186
  </>
139
187
  )}
140
- <Row label={t.overlay}>
141
- <ColorInput label={t.overlay} value={overlay} onChange={setOverlay} />
142
- </Row>
143
- {(overlay || (cover && attrs.src)) && (
144
- <Row label={`${t.opacity}: ${opacity}%`}>
145
- <input type="range" min={0} max={100} step={5} value={opacity} aria-label={t.opacity} onChange={(e) => setOpacity(Number(e.target.value))} />
146
- </Row>
147
- )}
188
+ {cover && overlayFields}
148
189
  </>
149
190
  )}
150
191
  </>
151
192
  )}
152
193
  </Section>
194
+ {/* Lớp phủ nền: mục riêng (phủ lên màu / chuyển màu / ảnh), như bộ khối lớn */}
195
+ {!cover && <Section title={t.overlayTitle} modified={hasOv} onReset={() => setBg({ overlay: undefined, overlayOpacity: undefined, overlayGradient: undefined, overlayImage: undefined, overlayBlend: undefined })} defaultOpen={hasOv ? true : undefined}>{overlayFields}</Section>}
196
+ </>
153
197
  );
154
198
  }
@@ -66,6 +66,9 @@ export function BindingsPanel({ block, bindable, onChange }: { block: BNode; bin
66
66
  </select>
67
67
  : <input className="ecx-input" aria-label={`${ATTR[attr] ?? attr}: ${argKey}`} placeholder={argKey} value={String(b.args?.[argKey] ?? "")}
68
68
  onChange={(e) => set(attr, { ...b, args: { ...b.args, [argKey]: e.target.value.replace(/[^\w.-]/g, "").slice(0, 200) } })} />)}
69
+ {b && (attr === "content" || attr === "text") && (
70
+ <label className="ecx-check"><input type="checkbox" checked={b.args?.hideIfEmpty === true} onChange={(e) => { const { hideIfEmpty: _drop, ...rest } = b.args ?? {}; set(attr, { ...b, args: e.target.checked ? { ...rest, hideIfEmpty: true } : rest }); }} /> {t.hideIfEmpty}</label>
71
+ )}
69
72
  </div>
70
73
  );
71
74
  })}