@ecomcx/ecomweb-editor 1.29.0 → 1.30.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecomcx/ecomweb-editor",
3
- "version": "1.29.0",
3
+ "version": "1.30.0",
4
4
  "description": "Trình soạn nội dung dạng khối của CMS — dùng độc lập trong mọi dự án React (1.x: TipTap; ./v2: cây khối, khung soạn iframe, sửa header/footer tại chỗ).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  "*.css"
30
30
  ],
31
31
  "peerDependencies": {
32
- "@ecomcx/ecomweb-content": "^1.23.0",
32
+ "@ecomcx/ecomweb-content": "^1.24.0",
33
33
  "react": ">=18",
34
34
  "react-dom": ">=18"
35
35
  },
@@ -45,7 +45,7 @@
45
45
  "prosemirror-view": "1.42.7"
46
46
  },
47
47
  "devDependencies": {
48
- "@ecomcx/ecomweb-content": "^1.23.0",
48
+ "@ecomcx/ecomweb-content": "^1.24.0",
49
49
  "@playwright/test": "1.53.0",
50
50
  "@types/react": "19.2.2",
51
51
  "@types/react-dom": "19.2.2",
@@ -2,7 +2,7 @@
2
2
  export const blockDesc = {
3
3
  paragraph: "Start with the basic building block of all narrative.",
4
4
  heading: "Introduce sections and organise content for readers and search engines.",
5
- bulletList: "A bulleted list.",
5
+ bulletList: "A bulleted list — marker type (✓, →…), marker colour, spacing and dividers in Style.",
6
6
  orderedList: "A numbered list.",
7
7
  taskList: "A checklist.",
8
8
  blockquote: "Give quoted text visual emphasis.",
@@ -13,14 +13,14 @@ export const blockDesc = {
13
13
  table: "Rows and columns of data; cells can be merged.",
14
14
  image: "An image with caption and alt text; drag to resize.",
15
15
  gallery: "Several images in a grid.",
16
- cover: "A large image or colour with text on top — a page hero.",
16
+ cover: "A covering image (or colour / gradient) with an overlay and text on top — a page hero; image, focal point and overlay in Background.",
17
17
  mediaText: "Media and text side by side for a richer layout.",
18
18
  video: "An uploaded or linked video.",
19
19
  audio: "An audio player.",
20
20
  file: "A downloadable file (PDF…), optionally embedded.",
21
21
  youtube: "Embed a YouTube video.",
22
22
  embed: "Embed content from a URL.",
23
- group: "Gather blocks in a container to style them together: background colour, gradient or background image (Styles), spacing, row / stack / grid layout.",
23
+ group: "Gather blocks in a container: Background (colour, gradient, image + overlay) right in Settings, spacing, row / stack / grid layout.",
24
24
  columns: "Display content in columns; drag to resize.",
25
25
  buttons: "Prompt visitors to take action with buttons.",
26
26
  spacer: "Add white space between blocks.",
@@ -53,9 +53,9 @@ export const blockDesc = {
53
53
  form: "Basic contact / sign-up form: submissions are kept in the admin and emailed. Advanced forms: plugins.",
54
54
  formField: "One field of a form: text, email, phone, message, choice, consent…",
55
55
  column: "One column inside Columns; set its width, can have its own background or background image.",
56
- button: "A linked button (primary / secondary / outline) inside Buttons.",
56
+ button: "A linked button (primary / secondary / outline) inside Buttons; Normal / Hover colours, size and radius in Style.",
57
57
  accordion: "Collapsible items (FAQ) — each item is a Details block.",
58
- tabs: "Content split into tabs; click a tab name to switch.",
58
+ tabs: "Content split into tabs; click a tab name to switch; normal / active title colours in Style.",
59
59
  tab: "One tab inside Tabs: its title and content.",
60
60
  carousel: "Sliding slides (images, cards, testimonials); choose how many show at once.",
61
61
  shortcode: "Insert a plugin feature by its shortcode.",
@@ -0,0 +1,55 @@
1
+ import type { vi } from "../vi";
2
+
3
+ export const blockStyle: (typeof vi)["blockStyle"] = {
4
+ tabContent: "Content",
5
+ tabStyle: "Style",
6
+ tabAdvanced: "Advanced",
7
+ normal: "Normal",
8
+ hover: "Hover",
9
+ active: "Active",
10
+ section: {
11
+ text: "Text", list: "List", button: "Button", image: "Image", table: "Table", tabs: "Tabs", accordion: "Accordion", columns: "Columns",
12
+ separator: "Separator", icon: "Icon", content: "Title & text", number: "Number", box: "Box", bar: "Bar",
13
+ },
14
+ attr: {
15
+ textShadow: "Text shadow",
16
+ listMarker: "Marker type", listMarkerColor: "Marker color", listGap: "Space between", listDivider: "Divider",
17
+ buttonColor: "Text color", buttonBg: "Background color", buttonHoverColor: "Text color", buttonHoverBg: "Background color", buttonSize: "Size", buttonRadius: "Border radius", buttonWeight: "Font weight", buttonShadow: "Box shadow",
18
+ imageWidth: "Width", imageHeight: "Height", imageFit: "Object fit", imageRadius: "Border radius", imageBorderWidth: "Border width", imageBorderColor: "Border color", imageShadow: "Box shadow",
19
+ imageOpacity: "Opacity", imageFilter: "CSS filter", imageHoverEffect: "Hover animation", imageHoverOpacity: "Opacity", imageHoverFilter: "CSS filter",
20
+ tableBorderColor: "Cell border color", tableBorderWidth: "Cell border width", tableHeaderBg: "Header background", tableHeaderColor: "Header text", tableStripe: "Striped rows", tableCellPadding: "Cell padding", tableAlign: "Cell alignment",
21
+ tabsTitleColor: "Title color", tabsTitleBg: "Title background", tabsActiveColor: "Title color", tabsActiveBg: "Title background", tabsAccent: "Underline", tabsBorderColor: "Divider color", tabsGap: "Space between titles", tabsContentPadding: "Content padding",
22
+ accTitleColor: "Title color", accTitleBg: "Title background", accActiveColor: "Title color", accBorderColor: "Border color", accGap: "Space between", accPadding: "Padding",
23
+ columnsGap: "Columns gap", columnsDirection: "Direction",
24
+ hrStyle: "Style", hrWeight: "Weight", hrColor: "Color", hrWidth: "Width", hrAlign: "Alignment",
25
+ iconBoxIconColor: "Icon color", iconBoxIconSize: "Icon size", iconBoxTitleColor: "Title color", iconBoxTextColor: "Description color",
26
+ imageBoxRadius: "Image radius", imageBoxTitleColor: "Title color", imageBoxTextColor: "Description color",
27
+ iconListGap: "Space between", iconListDivider: "Divider", iconListIconColor: "Icon color", iconListIconSize: "Icon size", iconListTextColor: "Text color",
28
+ counterNumberColor: "Number color", counterNumberSize: "Number size", counterTitleColor: "Title color",
29
+ testimonialBg: "Background color", testimonialBorderColor: "Border color", testimonialQuoteColor: "Quote color", testimonialNameColor: "Name color", testimonialRoleColor: "Role color",
30
+ progressBarColor: "Bar color", progressTrackColor: "Track color", progressHeight: "Bar height", progressTitleColor: "Title color",
31
+ },
32
+ opt: {
33
+ sm: "Small", md: "Medium", lg: "Large", xl: "Extra large", xs: "Extra small",
34
+ disc: "• Disc", circle: "○ Circle", square: "■ Square", decimal: "1. Number", "decimal-leading-zero": "01. Zero-padded", "lower-alpha": "a. Lowercase", "upper-alpha": "A. Uppercase",
35
+ "lower-roman": "i. Roman", "upper-roman": "I. Roman", check: "✓ Check", arrow: "→ Arrow", dash: "– Dash", none: "None",
36
+ cover: "Cover", contain: "Contain",
37
+ grayscale: "Grayscale", sepia: "Sepia", blur: "Blur", bright: "Brighter", dim: "Darker", saturate: "Saturate",
38
+ zoom: "Zoom", lift: "Lift", tilt: "Tilt",
39
+ start: "Start", center: "Center", end: "End",
40
+ row: "Row", "row-reverse": "Row, reversed", column: "Stacked", "column-reverse": "Stacked, reversed",
41
+ solid: "Solid", dashed: "Dashed", dotted: "Dotted", double: "Double",
42
+ "400": "Regular", "500": "Medium", "600": "Semi-bold", "700": "Bold", "800": "Extra bold",
43
+ },
44
+ bg: {
45
+ title: "Background",
46
+ type: "Background type",
47
+ color: "Color",
48
+ gradient: "Gradient",
49
+ image: "Image",
50
+ hoverColor: "Background color on hover",
51
+ hoverNote: "Hover only changes the background color; image / gradient stay.",
52
+ legacy: "Old group background color — pick another color to move it to the new style.",
53
+ },
54
+ tabTitle: "Tab {n}",
55
+ };
@@ -19,4 +19,6 @@ export const controls = {
19
19
  sideLeft: "left",
20
20
  styles: "Styles",
21
21
  advanced: "Advanced",
22
+ /** Tên biến thể kiểu khối của lõi (CORE_BLOCK_STYLES). */
23
+ blockStyle: { stripes: "Stripes", rounded: "Rounded", circle: "Circle", plain: "Plain", dots: "Dots", wide: "Wide", pill: "Pill", card: "Card" },
22
24
  };
@@ -144,6 +144,7 @@ export const hints = {
144
144
  "gallery.linkTo.opt.media": "Open full image",
145
145
  "gallery.imageCrop.label": "Crop images to fit",
146
146
  "gallery.lightbox.label": "Enlarge on click",
147
+ "image.lightbox.label": "Enlarge on click",
147
148
  "countdown.expiredText.label": "Text when expired",
148
149
  "navigation.overlayMenu.label": "Collapse into menu button",
149
150
  "navigation.overlayMenu.opt.never": "Never",
@@ -13,9 +13,10 @@ import { legacyBasic } from "./legacy-basic";
13
13
  import { legacyDynamic } from "./legacy-dynamic";
14
14
  import { motion } from "./motion";
15
15
  import { background } from "./background";
16
+ import { blockStyle } from "./block-style";
16
17
  import { patternLib } from "./pattern-lib";
17
18
  import { patterns } from "./patterns";
18
19
  import { shortcuts } from "./shortcuts";
19
20
 
20
21
  /** Tiếng Anh: đủ khoá như vi/ (thiếu khoá là lỗi biên dịch) và là ngôn ngữ dự phòng của mọi ngôn ngữ khác. */
21
- export const en: typeof vi = { v2, legacy, attrs, background, bindings, blockDesc, blockTitles, blocks, controls, hints, layout, legacyBasic, legacyDynamic, motion, patternLib, patterns, shortcuts };
22
+ export const en: typeof vi = { v2, legacy, attrs, background, bindings, blockStyle, blockDesc, blockTitles, blocks, controls, hints, layout, legacyBasic, legacyDynamic, motion, patternLib, patterns, shortcuts };
@@ -2,7 +2,7 @@
2
2
  export const blockDesc = {
3
3
  paragraph: "Đoạn chữ thường — nền tảng của mọi nội dung.",
4
4
  heading: "Tiêu đề mục (H2–H6), giúp người đọc và Google hiểu cấu trúc trang.",
5
- bulletList: "Danh sách gạch đầu dòng.",
5
+ bulletList: "Danh sách gạch đầu dòng — kiểu dấu (✓, →…), màu dấu, khoảng cách và đường kẻ giữa mục ở Kiểu dáng.",
6
6
  orderedList: "Danh sách đánh số theo thứ tự.",
7
7
  taskList: "Danh sách việc có ô đánh dấu.",
8
8
  blockquote: "Trích dẫn lời của ai đó.",
@@ -13,14 +13,14 @@ export const blockDesc = {
13
13
  table: "Bảng dữ liệu hàng / cột, gộp ô được.",
14
14
  image: "Ảnh có chú thích, alt cho SEO, đổi cỡ bằng tay kéo.",
15
15
  gallery: "Nhiều ảnh xếp lưới.",
16
- cover: "Ảnh hoặc màu nền lớn với chữ đè lên — phần mở đầu trang.",
16
+ cover: "Ảnh phủ kín (hoặc màu / chuyển màu) với lớp phủ và chữ đè lên — phần mở đầu trang; ảnh, điểm lấy nét, lớp phủ ở mục Nền.",
17
17
  mediaText: "Ảnh và chữ đặt cạnh nhau để bố cục hấp dẫn hơn.",
18
18
  video: "Video tải lên hoặc từ địa chỉ.",
19
19
  audio: "Tệp âm thanh có trình phát.",
20
20
  file: "Liên kết tải tệp (PDF…), có thể xem ngay trên trang.",
21
21
  youtube: "Nhúng video YouTube.",
22
22
  embed: "Nhúng nội dung từ địa chỉ (Facebook, TikTok, bản đồ…).",
23
- group: "Gom nhiều khối vào một khung để tô nền (màu, chuyển màu, ảnh nền trong Kiểu dáng), căn lề, bố cục hàng / cột / lưới.",
23
+ group: "Gom nhiều khối vào một khung: Nền (màu, chuyển màu, ảnh + lớp phủ) ngay ở Cài đặt, căn lề, bố cục hàng / cột / lưới.",
24
24
  columns: "Chia nội dung thành nhiều cột, kéo để đổi độ rộng.",
25
25
  buttons: "Một hoặc nhiều nút kêu gọi hành động.",
26
26
  spacer: "Khoảng trống giữa các khối.",
@@ -53,9 +53,9 @@ export const blockDesc = {
53
53
  form: "Form liên hệ / đăng ký cơ bản: bài gửi lưu trong admin và báo qua email. Form nâng cao: plugin.",
54
54
  formField: "Một ô của form: chữ, email, điện thoại, nội dung, chọn, đồng ý…",
55
55
  column: "Một cột trong khối Cột; chỉnh độ rộng, có thể tô nền / ảnh nền riêng.",
56
- button: "Một nút bấm có liên kết (chính / phụ / viền) — nằm trong khối Nút.",
56
+ button: "Một nút bấm có liên kết (chính / phụ / viền) — nằm trong khối Nút; màu Thường / Rê chuột, cỡ, bo góc ở Kiểu dáng.",
57
57
  accordion: "Nhiều mục gập / mở (câu hỏi thường gặp) — mỗi mục là khối Nội dung ẩn.",
58
- tabs: "Nội dung chia thẻ, bấm tên thẻ để chuyển.",
58
+ tabs: "Nội dung chia thẻ, bấm tên thẻ để chuyển; màu tiêu đề thường / đang mở ở Kiểu dáng.",
59
59
  tab: "Một thẻ trong khối Thẻ: tên thẻ và nội dung bên trong.",
60
60
  carousel: "Trình chiếu nhiều trang trượt (ảnh, thẻ, lời chứng thực), chọn số trang hiện cùng lúc.",
61
61
  shortcode: "Chèn tính năng của plugin bằng mã ngắn.",
@@ -0,0 +1,58 @@
1
+ /** Ô Kiểu dáng riêng của khối lõi (@ecomcx/ecomweb-content core-controls) + ô Nền thống nhất. Khoá = tên thuộc tính / mục / giá trị. */
2
+ export const blockStyle = {
3
+ tabContent: "Nội dung",
4
+ tabStyle: "Kiểu dáng",
5
+ tabAdvanced: "Nâng cao",
6
+ normal: "Thường",
7
+ hover: "Rê chuột",
8
+ active: "Đang mở",
9
+ /** Mục của tab Kiểu dáng. */
10
+ section: {
11
+ text: "Chữ", list: "Danh sách", button: "Nút", image: "Ảnh", table: "Bảng", tabs: "Tabs", accordion: "Accordion", columns: "Cột",
12
+ separator: "Đường kẻ", icon: "Icon", content: "Tiêu đề & chữ", number: "Con số", box: "Khung", bar: "Thanh",
13
+ },
14
+ /** Tên ô (thuộc tính). */
15
+ attr: {
16
+ textShadow: "Bóng chữ",
17
+ listMarker: "Kiểu dấu đầu dòng", listMarkerColor: "Màu dấu", listGap: "Khoảng giữa các mục", listDivider: "Đường kẻ giữa các mục",
18
+ buttonColor: "Màu chữ", buttonBg: "Màu nền", buttonHoverColor: "Màu chữ", buttonHoverBg: "Màu nền", buttonSize: "Cỡ nút", buttonRadius: "Bo góc", buttonWeight: "Độ đậm chữ", buttonShadow: "Đổ bóng",
19
+ imageWidth: "Chiều rộng", imageHeight: "Chiều cao", imageFit: "Cách phủ", imageRadius: "Bo góc", imageBorderWidth: "Độ dày viền", imageBorderColor: "Màu viền", imageShadow: "Đổ bóng",
20
+ imageOpacity: "Độ trong", imageFilter: "Bộ lọc màu", imageHoverEffect: "Hiệu ứng", imageHoverOpacity: "Độ trong", imageHoverFilter: "Bộ lọc màu",
21
+ tableBorderColor: "Màu viền ô", tableBorderWidth: "Độ dày viền ô", tableHeaderBg: "Nền hàng tiêu đề", tableHeaderColor: "Chữ hàng tiêu đề", tableStripe: "Màu hàng xen kẽ", tableCellPadding: "Khoảng đệm ô", tableAlign: "Căn chữ trong ô",
22
+ tabsTitleColor: "Màu tiêu đề", tabsTitleBg: "Nền tiêu đề", tabsActiveColor: "Màu tiêu đề", tabsActiveBg: "Nền tiêu đề", tabsAccent: "Gạch chân", tabsBorderColor: "Màu đường kẻ", tabsGap: "Khoảng giữa tiêu đề", tabsContentPadding: "Khoảng đệm nội dung",
23
+ accTitleColor: "Màu tiêu đề", accTitleBg: "Nền tiêu đề", accActiveColor: "Màu tiêu đề", accBorderColor: "Màu viền", accGap: "Khoảng giữa các mục", accPadding: "Khoảng đệm",
24
+ columnsGap: "Khoảng giữa các cột", columnsDirection: "Hướng xếp",
25
+ hrStyle: "Kiểu", hrWeight: "Độ dày", hrColor: "Màu", hrWidth: "Chiều rộng", hrAlign: "Căn",
26
+ iconBoxIconColor: "Màu icon", iconBoxIconSize: "Cỡ icon", iconBoxTitleColor: "Màu tiêu đề", iconBoxTextColor: "Màu mô tả",
27
+ imageBoxRadius: "Bo góc ảnh", imageBoxTitleColor: "Màu tiêu đề", imageBoxTextColor: "Màu mô tả",
28
+ iconListGap: "Khoảng giữa các mục", iconListDivider: "Đường kẻ giữa các mục", iconListIconColor: "Màu icon", iconListIconSize: "Cỡ icon", iconListTextColor: "Màu chữ",
29
+ counterNumberColor: "Màu số", counterNumberSize: "Cỡ số", counterTitleColor: "Màu tiêu đề",
30
+ testimonialBg: "Màu nền", testimonialBorderColor: "Màu viền", testimonialQuoteColor: "Màu lời chứng thực", testimonialNameColor: "Màu tên", testimonialRoleColor: "Màu chức danh",
31
+ progressBarColor: "Màu thanh", progressTrackColor: "Màu rãnh", progressHeight: "Độ cao thanh", progressTitleColor: "Màu tiêu đề",
32
+ },
33
+ /** Nhãn giá trị của ô chọn. */
34
+ opt: {
35
+ sm: "Nhỏ", md: "Vừa", lg: "Lớn", xl: "Rất lớn", xs: "Rất nhỏ",
36
+ disc: "• Chấm tròn", circle: "○ Vòng tròn", square: "■ Vuông", decimal: "1. Số", "decimal-leading-zero": "01. Số có 0", "lower-alpha": "a. Chữ thường", "upper-alpha": "A. Chữ hoa",
37
+ "lower-roman": "i. La Mã thường", "upper-roman": "I. La Mã hoa", check: "✓ Dấu tích", arrow: "→ Mũi tên", dash: "– Gạch ngang", none: "Không",
38
+ cover: "Phủ kín", contain: "Vừa khung",
39
+ grayscale: "Đen trắng", sepia: "Màu cũ", blur: "Làm mờ", bright: "Sáng hơn", dim: "Tối hơn", saturate: "Rực hơn",
40
+ zoom: "Phóng to", lift: "Nhấc lên", tilt: "Nghiêng",
41
+ start: "Đầu", center: "Giữa", end: "Cuối",
42
+ row: "Ngang", "row-reverse": "Ngang, đảo thứ tự", column: "Xếp dọc", "column-reverse": "Xếp dọc, đảo thứ tự",
43
+ solid: "Liền", dashed: "Gạch", dotted: "Chấm", double: "Đôi",
44
+ "400": "Thường", "500": "Vừa", "600": "Hơi đậm", "700": "Đậm", "800": "Rất đậm",
45
+ },
46
+ /** Ô Nền thống nhất (như nhóm Background của Elementor). */
47
+ bg: {
48
+ title: "Nền",
49
+ type: "Loại nền",
50
+ color: "Màu",
51
+ gradient: "Chuyển màu",
52
+ image: "Ảnh",
53
+ hoverColor: "Màu nền khi rê chuột",
54
+ hoverNote: "Rê chuột chỉ đổi màu nền; ảnh / chuyển màu giữ nguyên.",
55
+ legacy: "Màu nền cũ của nhóm — chọn màu khác để chuyển sang kiểu dáng mới.",
56
+ },
57
+ tabTitle: "Tab {n}",
58
+ };
@@ -19,4 +19,6 @@ export const controls = {
19
19
  sideLeft: "trái",
20
20
  styles: "Kiểu dáng",
21
21
  advanced: "Nâng cao",
22
+ /** Tên biến thể kiểu khối của lõi (CORE_BLOCK_STYLES). */
23
+ blockStyle: { stripes: "Kẻ sọc", rounded: "Bo góc", circle: "Tròn", plain: "Đơn giản", dots: "Chấm", wide: "Rộng", pill: "Viên thuốc", card: "Thẻ" },
22
24
  };
@@ -144,6 +144,7 @@ export const hints = {
144
144
  "gallery.linkTo.opt.media": "Mở ảnh gốc",
145
145
  "gallery.imageCrop.label": "Cắt ảnh cho đều khung",
146
146
  "gallery.lightbox.label": "Phóng to khi bấm",
147
+ "image.lightbox.label": "Phóng to khi bấm",
147
148
  "countdown.expiredText.label": "Chữ khi hết giờ",
148
149
  "navigation.overlayMenu.label": "Thu gọn thành nút menu",
149
150
  "navigation.overlayMenu.opt.never": "Không",
@@ -18,8 +18,9 @@ import { legacyBasic } from "./legacy-basic";
18
18
  import { legacyDynamic } from "./legacy-dynamic";
19
19
  import { motion } from "./motion";
20
20
  import { background } from "./background";
21
+ import { blockStyle } from "./block-style";
21
22
  import { patternLib } from "./pattern-lib";
22
23
  import { patterns } from "./patterns";
23
24
  import { shortcuts } from "./shortcuts";
24
25
 
25
- export const vi = { v2, legacy, attrs, background, bindings, blockDesc, blockTitles, blocks, controls, hints, layout, legacyBasic, legacyDynamic, motion, patternLib, patterns, shortcuts };
26
+ export const vi = { v2, legacy, attrs, background, bindings, blockStyle, blockDesc, blockTitles, blocks, controls, hints, layout, legacyBasic, legacyDynamic, motion, patternLib, patterns, shortcuts };
@@ -1,6 +1,6 @@
1
1
  /** Kho panel plugin (registerBlockPanel) — đăng ký ở đây, trình soạn đọc. */
2
2
  import type { ComponentType } from "react";
3
- import { defineBlockControls, type BlockControls, type ControlSpec } from "@ecomcx/ecomweb-content";
3
+ import { CORE_CONTROLS, defineBlockControls, type BlockControls, type ControlSpec } from "@ecomcx/ecomweb-content";
4
4
 
5
5
  /** Props của panel plugin trong tab "Khối". */
6
6
  export interface BlockPanelProps {
@@ -40,12 +40,13 @@ const listeners = new Set<() => void>();
40
40
  let snapshot: BlockPanel[] = [];
41
41
  const changed = () => {
42
42
  snapshot = [...panels.values()].sort((a, b) => (a.order ?? 10) - (b.order ?? 10));
43
- controls = snapshot.flatMap((p) => { const t = typed(p); return Object.keys(t).length ? [{ id: p.id, blocks: p.blocks ?? "*", attributes: t }] : []; });
43
+ controls = [...CORE_CONTROLS, ...snapshot.flatMap((p) => { const t = typed(p); return Object.keys(t).length ? [{ id: p.id, blocks: p.blocks ?? "*", attributes: t }] : []; })];
44
44
  listeners.forEach((l) => l());
45
45
  };
46
46
  /** Thuộc tính có `type` + `css` → ô điều khiển khai CSS (kiểm khai báo ngay lúc đăng ký: sai → ném lỗi). */
47
47
  const typed = (p: BlockPanel) => Object.fromEntries(Object.entries(p.attributes ?? {}).filter(([, s]) => "type" in s && s.type)) as Record<string, ControlSpec>;
48
- let controls: BlockControls[] = [];
48
+ // Ô Kiểu dáng của khối lõi (1.24) luôn có, ô của plugin thêm sau
49
+ let controls: BlockControls[] = [...CORE_CONTROLS];
49
50
  export function registerBlockPanel(panel: BlockPanel) {
50
51
  const t = typed(panel);
51
52
  if (Object.keys(t).length) defineBlockControls({ id: panel.id, blocks: panel.blocks ?? "*", attributes: t });
@@ -55,7 +56,7 @@ export function unregisterBlockPanel(id: string) { const had = panels.delete(id)
55
56
 
56
57
  /** Panel áp dụng cho một loại khối. */
57
58
  export const blockPanelsFor = (type: string, tab: "block" | "style" = "block") => snapshot.filter((p) => (p.blocks === undefined || p.blocks === "*" || p.blocks.includes(type)) && (p.tab ?? "block") === tab);
58
- /** Ô điều khiển khai CSS của mọi panel (đầu vào của controlsCss — cùng hàm website dùng). */
59
+ /** Ô điều khiển khai CSS: của khối lõi + của mọi panel (đầu vào của controlsCss — cùng hàm website dùng). */
59
60
  export const blockControls = () => controls;
60
61
  export const blockPanels = () => snapshot;
61
62
  export function onBlockPanelsChange(l: () => void) { listeners.add(l); return () => { listeners.delete(l); }; }
@@ -1,3 +1,4 @@
1
+ import { CORE_NODES, coreControlsFor, type AttrSpec, type BlockAttrSpec } from "@ecomcx/ecomweb-content";
1
2
  import { messages } from "../../i18n";
2
3
  import type { V2Labels } from "../labels";
3
4
  import type { BlockType, BlockTypeRegistry } from "../core/registry";
@@ -17,6 +18,23 @@ const TITLE_KEYS: Partial<Record<string, keyof V2Labels>> = {
17
18
  pullquote: "pullquote", cover: "cover", customHtml: "html", embed: "embed",
18
19
  };
19
20
 
21
+ /**
22
+ * Ô Kiểu dáng lõi (core-controls) khai thêm vào thuộc tính của khối, ẩn khỏi form Cài đặt (sửa ở tab Kiểu dáng) — để danh mục khối
23
+ * gửi cho AI (aiCatalog) biết tên / giá trị hợp lệ. Khối chưa khai `attributes` giữ mô tả của CORE_NODES (cũng ẩn) như trước.
24
+ */
25
+ function withStyleAttrs(t: BlockType): BlockType["attributes"] {
26
+ const ctl = Object.entries(coreControlsFor(t.name));
27
+ if (!ctl.length) return t.attributes;
28
+ const hidden = (s: AttrSpec): BlockAttrSpec => ({ ...s, control: "hidden" });
29
+ const base = t.attributes ?? Object.fromEntries(Object.entries(CORE_NODES[t.name]?.attrs ?? {}).map(([k, s]) => [k, hidden(s)]));
30
+ return {
31
+ ...base,
32
+ ...Object.fromEntries(ctl.map(([k, s]) => [k, hidden(s.type === "number"
33
+ ? { type: "number", min: s.min, max: s.max }
34
+ : { type: "string", ...(s.type === "enum" ? { enum: s.options?.map((o) => (typeof o === "string" ? o : o.value)) } : {}) })])),
35
+ };
36
+ }
37
+
20
38
  export function coreBlockTypes(labels: V2Labels): BlockType[] {
21
39
  const names = messages("blockTitles", labels.lang);
22
40
  return [...textBlocks(), ...layoutBlocks(), ...mediaBlocks(), ...formBlocks(labels.lang), ...widgetBlocks(labels.lang), ...themeBlocks()].map((t) => {
@@ -25,7 +43,7 @@ export function coreBlockTypes(labels: V2Labels): BlockType[] {
25
43
  const title = key ? String(labels[key]) : str(names[t.name]) ?? t.title;
26
44
  // Biến thể đứng riêng (Hàng ngang / Xếp dọc / Lưới) theo ngôn ngữ
27
45
  const variations = t.variations?.map((v) => { const vt = str(names[`${t.name}/${v.name}`]); return vt ? { ...v, title: vt } : v; });
28
- return { ...t, title, variations, description: t.description ?? blockDescription(t.name, labels.lang) };
46
+ return { ...t, title, variations, description: t.description ?? blockDescription(t.name, labels.lang), attributes: withStyleAttrs(t) };
29
47
  });
30
48
  }
31
49
 
@@ -1,6 +1,6 @@
1
1
  import { blockShell, buttonWrapShell, colorCss, coverParts, spacingValue } from "@ecomcx/ecomweb-content";
2
2
  import { ChevronsUpDown, Columns2, Columns3, Columns4, Info, LayoutPanelLeft, Minus, MousePointerClick, PanelTop, RectangleHorizontal, Square, Table2, Image as ImageIcon } from "lucide-react";
3
- import type { CSSProperties } from "react";
3
+ import { useEffect, useSyncExternalStore, type CSSProperties } from "react";
4
4
  import { InnerBlocks } from "../canvas/block-list";
5
5
  import { withoutOverridden } from "./inline-style";
6
6
  import { makeBlock } from "../core/model";
@@ -139,14 +139,43 @@ function AccordionEdit({ block, blockProps }: BlockEditProps) {
139
139
  return <div {...(merge(blockProps, "ecx-accordion") as object)}><InnerBlocks parent={block} /></div>;
140
140
  }
141
141
 
142
- function TabsEdit({ block, blockProps }: BlockEditProps) {
143
- return <div {...(merge(blockProps, "ecx-tabs") as object)}><InnerBlocks parent={block} /></div>;
142
+ /** Thẻ đang mở của từng khối tabs trên khung soạn (không lưu vào nội dung — website luôn mở thẻ đầu). */
143
+ const openTabs = new Map<string, number>();
144
+ const tabListeners = new Set<() => void>();
145
+ const setOpenTab = (id: string, i: number) => { openTabs.set(id, i); tabListeners.forEach((l) => l()); };
146
+ const useOpenTab = (id: string) => useSyncExternalStore((l) => { tabListeners.add(l); return () => { tabListeners.delete(l); }; }, () => openTabs.get(id) ?? 0);
147
+
148
+ /** Tabs như website (TabsClient): thanh tiêu đề (vai trò tablist / tab) + một thẻ hiện; tiêu đề gõ ngay trên thanh, trống = "Tab N". */
149
+ function TabsEdit({ block, blockProps, editable }: BlockEditProps) {
150
+ const { store } = useEditor();
151
+ const t = useMsgs("blockStyle");
152
+ const active = useOpenTab(block.id);
153
+ const tabs = (block.content ?? []).filter((c) => c.type === "tab");
154
+ return (
155
+ <div {...(merge(blockProps, "ecx-tabs") as object)}>
156
+ <div role="tablist" className="ecx-tabs-list">
157
+ {tabs.map((tab, i) => (
158
+ <div key={tab.id} role="tab" aria-selected={i === active} tabIndex={-1} className={cx("ecx-tab-button", i === active && "is-active")} onMouseDown={() => setOpenTab(block.id, i)}>
159
+ <RichText blockId={tab.id} field="title" tagName="span" value={String(tab.attrs.title ?? "")} onChange={(v) => store.setAttrs([tab.id], { title: v })} placeholder={t.tabTitle.replace("{n}", String(i + 1))} placeholderAlways editable={editable} />
160
+ </div>
161
+ ))}
162
+ </div>
163
+ <InnerBlocks parent={block} />
164
+ </div>
165
+ );
144
166
  }
145
167
 
146
- function TabEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
168
+ function TabEdit({ block, blockProps }: BlockEditProps) {
169
+ const { store } = useEditor();
170
+ const loc = store.locate(block.id);
171
+ const parentId = loc?.parent?.id ?? "";
172
+ const index = (loc?.parent?.content ?? []).filter((c) => c.type === "tab").findIndex((c) => c.id === block.id);
173
+ const open = useOpenTab(parentId) === index;
174
+ const within = useActiveWithin(block.id);
175
+ // Chọn khối nằm trong thẻ đang ẩn (danh sách khối, tìm kiếm…) → mở thẻ đó
176
+ useEffect(() => { if (within && !open && parentId) setOpenTab(parentId, index); }, [within, open, parentId, index]);
147
177
  return (
148
- <div {...(merge(blockProps, "ecx-tab", { borderLeft: "3px solid rgba(127,127,127,.4)", paddingLeft: 12, marginBlock: 8 }) as object)}>
149
- <RichText blockId={block.id} field="title" tagName="strong" value={String(block.attrs.title ?? "")} onChange={(v) => setAttrs({ title: v })} placeholder="Tab…" placeholderAlways editable={editable} />
178
+ <div {...(merge(blockProps, "ecx-tab ecx-tab-panel", open ? undefined : { display: "none" }) as object)} role="tabpanel">
150
179
  <InnerBlocks parent={block} />
151
180
  </div>
152
181
  );
@@ -180,7 +209,8 @@ function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
180
209
  const drop = useFileDrop("image", select);
181
210
  const t = useMsgs("blocks"); // hook phải gọi trước mọi return sớm: chọn ảnh/màu làm đổi nhánh render
182
211
  // Chưa có ảnh lẫn màu: chỗ chọn ảnh nền hoặc màu nền (không để khối trắng trơn vô hình)
183
- if (!src && !a.overlay) {
212
+ const st = normalizeStyle(a.style);
213
+ if (!src && !a.overlay && !st?.color?.background && !st?.gradient && !st?.background?.image) {
184
214
  return (
185
215
  <div {...merge(blockProps, cx("ecx-media-placeholder ecx-cover-placeholder", drop.over && "is-drop-target"))} {...drop.props}>
186
216
  <span className="ecx-placeholder-title"><ImageIcon className="ecx-icon" />{t.cover}</span>
@@ -194,11 +224,11 @@ function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
194
224
  </div>
195
225
  );
196
226
  }
197
- const { overlay, opacity, fixed } = coverParts(a);
227
+ const { overlay, fixed, imgStyle, overlayStyle } = coverParts(a);
198
228
  return (
199
229
  <div {...shellProps(blockProps, "cover", a)}>
200
- {src && !fixed && <img className="ecx-cover-img" src={src} alt={String(a.alt ?? "")} draggable={false} />}
201
- {overlay && <span className="ecx-cover-overlay" aria-hidden="true" style={{ background: overlay, opacity }} />}
230
+ {src && !fixed && <img className="ecx-cover-img" src={src} alt={String(a.alt ?? "")} draggable={false} style={imgStyle as CSSProperties} />}
231
+ {overlay && <span className="ecx-cover-overlay" aria-hidden="true" style={overlayStyle as CSSProperties} />}
202
232
  <div className="ecx-cover-inner"><InnerBlocks parent={block} /></div>
203
233
  </div>
204
234
  );
@@ -270,8 +300,8 @@ export function layoutBlocks(): BlockType[] {
270
300
  variations: [
271
301
  { name: "50-50", title: "50 / 50", icon: Columns2, create: () => columns(1, 1) },
272
302
  { name: "33-33-33", title: "33 / 33 / 33", icon: Columns3, create: () => columns(1, 1, 1) },
273
- { name: "30-70", title: "30 / 70", icon: LayoutPanelLeft, create: () => columns(30, 70) },
274
- { name: "70-30", title: "70 / 30", icon: LayoutPanelLeft, create: () => columns(70, 30) },
303
+ { name: "33-66", title: "33 / 66", icon: LayoutPanelLeft, create: () => columns(33, 67) },
304
+ { name: "66-33", title: "66 / 33", icon: LayoutPanelLeft, create: () => columns(67, 33) },
275
305
  { name: "25x4", title: "25 / 25 / 25 / 25", icon: Columns4, create: () => columns(1, 1, 1, 1) },
276
306
  ],
277
307
  supports: { style: true, anchor: true, className: true },
@@ -311,7 +341,7 @@ export function layoutBlocks(): BlockType[] {
311
341
  },
312
342
  {
313
343
  name: "tabs", title: "Tabs", icon: PanelTop, category: "text", keywords: "tabs the tab chuyen doi noi dung", kind: "container", edit: TabsEdit,
314
- create: () => makeBlock("tabs", {}, [makeBlock("tab", { title: "" }, [makeBlock("paragraph")]), makeBlock("tab", { title: "" }, [makeBlock("paragraph")])]), supports: { style: true, anchor: true, className: true },
344
+ create: () => makeBlock("tabs", {}, [makeBlock("tab", { title: "Tab 1" }, [makeBlock("paragraph")]), makeBlock("tab", { title: "Tab 2" }, [makeBlock("paragraph")])]), supports: { style: true, anchor: true, className: true },
315
345
  },
316
346
  {
317
347
  name: "tab", title: "Tab", icon: PanelTop, category: "text", keywords: "tab", kind: "container", edit: TabEdit, hidden: true, structure: { parents: ["tabs"] },
@@ -165,6 +165,13 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
165
165
  .ecx-media-actions form .ecx-input { flex: 1; }
166
166
  .ecx-media-error { color: #b42318; font: 12px var(--ecx-ui-font); margin: 6px 0 0; }
167
167
  .ecx-cover-placeholder { min-height: 220px; }
168
+ /* Bảng: ô trống vẫn thấy lưới + có chỗ bấm dù theme bỏ viền bảng (chỉ trong trình soạn — outline không đổi bố cục) */
169
+ .ecx-canvas-root .ecx-table table { width: 100%; border-collapse: collapse; }
170
+ .ecx-canvas-root .ecx-table :is(td, th) { min-width: 3em; height: 2.5em; outline: 1px dashed color-mix(in srgb, currentColor 22%, transparent); outline-offset: -1px; }
171
+ /* Tabs: thanh tiêu đề luôn thấy và bấm được (thẻ đang ẩn: display none inline) */
172
+ .ecx-canvas-root .ecx-tabs-list { display: flex; flex-wrap: wrap; min-height: 2.5em; }
173
+ .ecx-canvas-root .ecx-tab-button { cursor: pointer; }
174
+ .ecx-canvas-root .ecx-tab-button [data-ecx-rich] { display: inline-block; min-width: 3em; }
168
175
  .ecx-btn-ghost { background: none; border-color: transparent; }
169
176
  /* tay nắm cột / nút thêm cột định vị theo khối cột (website không cần); nút nằm trong khối cột, góc dưới phải: không tràn khung canvas (thanh cuộn ngang) và không bị thanh công cụ nổi (ở trên khối đang chọn) che */
170
177
  .ecx-canvas-root .ecx-columns { position: relative; }
@@ -59,7 +59,11 @@ export const ATTR_HINTS: Record<string, AttrHint> = {
59
59
  "youtube.src": { label: true },
60
60
  "youtube.start": { label: true },
61
61
  "image.src": { label: true },
62
- "cover.src": { label: true },
62
+ "cover.src": { label: true, control: "hidden" }, // ảnh, lớp phủ, cố định: ô Nền (background-panel.tsx)
63
+ "cover.overlay": { control: "hidden" },
64
+ "cover.fixed": { control: "hidden" },
65
+ "group.background": { control: "hidden" }, // màu nền cũ của nhóm: ô Nền (chuyển sang style.color.background khi sửa)
66
+ "group.textColor": { when: (a) => !!a.textColor }, // màu chữ cũ: chỉ hiện khi có giá trị — màu chữ mới ở tab Kiểu dáng
63
67
  "pullquote.citation": { label: true },
64
68
  "audio.name": { control: "hidden" },
65
69
  "heading.level": { control: "select", options: levels(1, 6), help: true },
@@ -74,7 +78,7 @@ export const ATTR_HINTS: Record<string, AttrHint> = {
74
78
  "columns.verticalAlign": { control: "segmented", options: V_ALIGN },
75
79
  "mediaText.verticalAlign": { control: "segmented", options: V_ALIGN },
76
80
  "cover.contentAlign": { control: "segmented", options: V_ALIGN },
77
- "cover.opacity": { control: "range", min: 0, max: 100, step: 5, unit: "%" },
81
+ "cover.opacity": { control: "hidden" },
78
82
  "mediaText.position": { control: "segmented", options: ["left", "right"] },
79
83
  "mediaText.width": { control: "range", min: 15, max: 85, step: 5, unit: "%" },
80
84
  "buttons.align": { control: "segmented", options: [...ALIGN, "space-between"] },
@@ -145,6 +149,7 @@ export const ATTR_HINTS: Record<string, AttrHint> = {
145
149
  "query.exclude": { label: true, when: notInherit },
146
150
  "query.sticky": { control: "select", options: ["any", "only", "exclude"], when: notInherit },
147
151
  "image.href": { label: true },
152
+ "image.lightbox": { label: true },
148
153
  "image.linkTarget": { control: "segmented", label: true, options: ["_self", "_blank"] },
149
154
  "orderedList.reversed": { label: true },
150
155
  "blockquote.citation": { label: true },
@@ -3,81 +3,152 @@ import { useState } from "react";
3
3
  import { useEditor } from "../context";
4
4
  import { useMsgs } from "../i18n";
5
5
  import { ColorInput } from "./color-field";
6
+ import { GradientField } from "./layout-panel";
6
7
  import { Row, Section, Seg, cx } from "./style-controls";
7
8
 
8
9
  /** Điểm lấy nét chọn nhanh: lưới 3×3 (trên-trái … dưới-phải). */
9
10
  const POSITIONS = ["0% 0%", "50% 0%", "100% 0%", "0% 50%", "50% 50%", "100% 50%", "0% 100%", "50% 100%", "100% 100%"];
11
+ type Kind = "color" | "gradient" | "image";
10
12
 
11
13
  /**
12
- * Mục "Ảnh nền" của tab Kiểu dáng (attrs.style.background, @ecomcx/ecomweb-content 1.22): ảnh từ thư viện media (hoặc dán URL),
13
- * ảnh / cách phủ / điểm lấy nét riêng theo khổ màn hình đang chọn, lặp, cố định khi cuộn, lớp phủ màu + độ mờ.
14
+ * Ô Nền thống nhất (như nhóm Background của Elementor): thẻ Thường / Rê chuột, loại Màu | Chuyển màu | Ảnh.
15
+ * Không có kho riêng — ghi vào trường sẵn có: style.color.background, style.gradient, style.background (ảnh theo khổ, cách phủ,
16
+ * điểm lấy nét, lặp, cố định, lớp phủ), style.hover.color.background. Khối bìa: ảnh / lớp phủ / cố định là attrs của khối
17
+ * (src, overlay, opacity, fixed, focal) — ảnh bìa là <img> phủ kín, chữ nằm trên. Nhóm có màu nền cũ (attrs.background) được
18
+ * hiện và chuyển sang style khi sửa.
14
19
  */
15
- export function BackgroundPanel({ style: raw, onChange, device }: { style: unknown; onChange(style: BlockStyle | null): void; device: Device }) {
20
+ export function BackgroundControl({ type, attrs, setAttrs, device }: { type: string; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void; device: Device }) {
16
21
  const { host } = useEditor();
17
22
  const t = useMsgs("background");
18
- const style: BlockStyle = normalizeStyle(raw) ?? {};
23
+ const b = useMsgs("blockStyle");
24
+ const cover = type === "cover";
25
+ const style: BlockStyle = normalizeStyle(attrs.style) ?? {};
19
26
  const bg: BlockBackground = style.background ?? {};
27
+ const legacy = type === "group" && typeof attrs.background === "string" ? attrs.background : undefined;
28
+ const hasImage = cover ? !!attrs.src : !!bg.image;
29
+ const [kind, setKind] = useState<Kind>(hasImage ? "image" : style.gradient ? "gradient" : "color");
30
+ const [state, setState] = useState<"normal" | "hover">("normal");
20
31
  const [url, setUrl] = useState("");
21
32
 
22
- const commit = (next: Record<string, unknown> | undefined) => onChange(normalizeStyle({ ...style, background: next }) ?? null);
23
- const set = (patch: Record<string, unknown>) => commit({ ...bg, ...patch });
33
+ const commitStyle = (next: BlockStyle, extra: Record<string, unknown> = {}) => setAttrs({ ...extra, style: normalizeStyle(next) ?? undefined });
34
+ const setBg = (patch: Record<string, unknown>) => commitStyle({ ...style, background: { ...bg, ...patch } as BlockBackground });
35
+ // Ảnh nền chỉ nhận đường dẫn tương đối hoặc https → URL media cùng website (site http) đổi thành "/uploads/…"
36
+ const sameOriginPath = (v: string) => { try { const u = new URL(v, location.href); return u.origin === location.origin ? u.pathname + u.search : v; } catch { return v; } };
24
37
  /** Giá trị theo khổ đang chọn (ảnh, cách phủ, điểm lấy nét). */
25
38
  const setAt = (k: "image" | "size" | "position", v: string | undefined) => {
26
39
  const r: Record<string, string | undefined> = { ...(bg[k] ?? {}) };
40
+ if (v && k === "image") v = sameOriginPath(v);
27
41
  if (v) r[device] = v; else delete r[device];
28
- set({ [k]: Object.keys(r).length ? r : undefined });
42
+ setBg({ [k]: Object.keys(r).length ? r : undefined });
29
43
  };
30
- const image = bg.image?.[device];
31
- const inherited = device === "mobile" ? bg.image?.tablet ?? bg.image?.base : device === "tablet" ? bg.image?.base : undefined;
44
+ const setColor = (v: string | undefined) => {
45
+ const next: BlockStyle = { ...style, color: { ...style.color, background: v } };
46
+ if (legacy === undefined) return commitStyle(next);
47
+ // 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
48
+ if (!next.radius && attrs.align !== "full") next.radius = "12px";
49
+ commitStyle(next, { background: undefined, ...(attrs.padding ? {} : { padding: "medium" }) });
50
+ };
51
+
52
+ const image = cover ? (attrs.src as string | undefined) : bg.image?.[device];
53
+ const inherited = cover ? undefined : device === "mobile" ? bg.image?.tablet ?? bg.image?.base : device === "tablet" ? bg.image?.base : undefined;
54
+ const focal = cover ? (typeof attrs.focal === "string" ? attrs.focal : undefined) : bg.position?.[device];
55
+ const setImage = (src: string | undefined, item?: { alt?: string; id?: unknown }) => cover
56
+ ? setAttrs({ src: src ? sameOriginPath(src) : undefined, ...(item ? { alt: item.alt || undefined, mediaId: item.id } : src ? {} : { mediaId: undefined }) })
57
+ : setAt("image", src);
32
58
  const pick = async () => {
33
59
  const [item] = (await host.media?.pick({ kind: "image", multiple: false })) ?? [];
34
- if (item) setAt("image", item.sizes?.large?.url ?? item.url);
60
+ if (item) setImage(item.sizes?.large?.url ?? item.url, item);
61
+ };
62
+ const overlay = cover ? attrs.overlay : bg.overlay;
63
+ const opacity = cover ? Number(attrs.opacity ?? 50) : bg.overlayOpacity ?? 50;
64
+ const setOverlay = (v: string | undefined) => cover ? setAttrs({ overlay: v }) : setBg({ overlay: v, overlayOpacity: v ? bg.overlayOpacity : undefined });
65
+ const setOpacity = (n: number) => cover ? setAttrs({ opacity: n === 50 ? undefined : n }) : setBg({ overlayOpacity: n === 50 ? undefined : n });
66
+ const modified = !!(style.color?.background || style.gradient || style.background || style.hover?.color?.background || legacy || (cover && (attrs.src || attrs.overlay)));
67
+ const reset = () => {
68
+ const next: BlockStyle = { ...style, gradient: undefined, background: undefined, color: { ...style.color, background: undefined }, hover: style.hover && { ...style.hover, color: { ...style.hover.color, background: undefined } } };
69
+ commitStyle(next, { ...(legacy ? { background: undefined } : {}), ...(cover ? { src: undefined, mediaId: undefined, overlay: undefined, opacity: undefined, fixed: undefined, focal: undefined } : {}) });
35
70
  };
36
71
 
37
72
  return (
38
- <Section title={t.title} modified={!!style.background} onReset={() => commit(undefined)} defaultOpen={!!style.background}>
39
- <Row label={t.image} device={device}>
40
- <div className="ecx-bg-image">
41
- {(image ?? inherited) && <img src={image ?? inherited} alt="" className={cx("ecx-bg-thumb", !image && "is-inherited")} style={{ objectPosition: bg.position?.[device] ?? bg.position?.base ?? "50% 50%" }} />}
42
- <div className="ecx-bg-actions">
43
- {host.media && <button type="button" className="ecx-btn" onClick={pick}>{image ? t.replace : t.choose}</button>}
44
- {image && <button type="button" className="ecx-btn" onClick={() => setAt("image", undefined)}>{t.remove}</button>}
45
- </div>
46
- {!host.media && (
47
- <input className="ecx-input" value={url} placeholder="https://…" aria-label={t.url}
48
- onChange={(e) => setUrl(e.target.value)} onBlur={() => { setAt("image", url.trim() || undefined); setUrl(""); }} />
49
- )}
50
- {inherited && !image && <p className="ecx-muted">{t.inherited}</p>}
51
- </div>
52
- </Row>
53
- {bg.image && (
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>
79
+ {state === "hover" ? (
54
80
  <>
55
- <Row label={t.size} device={device}>
56
- <Seg label={t.size} value={bg.size?.[device]} onChange={(v) => setAt("size", v)}
57
- options={[["cover", t.cover, t.cover_help], ["contain", t.contain, t.contain_help], ["auto", t.auto, t.auto_help]]} />
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 } } })} />
58
83
  </Row>
59
- <Row label={t.focal} device={device}>
60
- <div role="radiogroup" aria-label={t.focal} className="ecx-bg-focal">
61
- {POSITIONS.map((p) => (
62
- <button key={p} type="button" role="radio" aria-checked={(bg.position?.[device] ?? (device === "base" ? "50% 50%" : undefined)) === p} title={p} aria-label={p}
63
- className={cx("ecx-bg-focal-dot", (bg.position?.[device] ?? (device === "base" ? "50% 50%" : undefined)) === p && "is-active")}
64
- onClick={() => setAt("position", p === "50% 50%" && device === "base" ? undefined : p)} />
84
+ <p className="ecx-muted">{b.bg.hoverNote}</p>
85
+ </>
86
+ ) : (
87
+ <>
88
+ <Row label={b.bg.type}>
89
+ <div role="radiogroup" aria-label={b.bg.type} className="ecx-seg is-text">
90
+ {(["color", "gradient", "image"] as const).map((k) => (
91
+ <button key={k} type="button" role="radio" aria-checked={kind === k} className={cx("ecx-seg-btn", kind === k && "is-active")} onClick={() => setKind(k)}>{b.bg[k]}</button>
65
92
  ))}
66
93
  </div>
67
94
  </Row>
68
- <label className="ecx-check"><input type="checkbox" checked={!!bg.repeat} onChange={(e) => set({ repeat: e.target.checked || undefined })} /> {t.repeat}</label>
69
- <label className="ecx-check"><input type="checkbox" checked={!!bg.fixed} onChange={(e) => set({ fixed: e.target.checked || undefined })} /> {t.fixed}</label>
95
+ {kind === "color" && (
96
+ <Row label={b.bg.color}>
97
+ <ColorInput label={b.bg.color} value={style.color?.background ?? legacy} onChange={setColor} />
98
+ {legacy && !style.color?.background && <p className="ecx-muted">{b.bg.legacy}</p>}
99
+ </Row>
100
+ )}
101
+ {kind === "gradient" && <Row label={b.bg.gradient}><GradientField value={style.gradient} onChange={(g) => commitStyle({ ...style, gradient: g })} /></Row>}
102
+ {kind === "image" && (
103
+ <>
104
+ <Row label={t.image} device={cover ? undefined : device}>
105
+ <div className="ecx-bg-image">
106
+ {(image ?? inherited) && <img src={image ?? inherited} alt="" className={cx("ecx-bg-thumb", !image && "is-inherited")} style={{ objectPosition: focal ?? bg.position?.base ?? "50% 50%" }} />}
107
+ <div className="ecx-bg-actions">
108
+ {host.media && <button type="button" className="ecx-btn" onClick={pick}>{image ? t.replace : t.choose}</button>}
109
+ {image && <button type="button" className="ecx-btn" onClick={() => setImage(undefined)}>{t.remove}</button>}
110
+ </div>
111
+ {!host.media && (
112
+ <input className="ecx-input" value={url} placeholder="https://…" aria-label={t.url}
113
+ onChange={(e) => setUrl(e.target.value)} onBlur={() => { setImage(url.trim() || undefined); setUrl(""); }} />
114
+ )}
115
+ {inherited && !image && <p className="ecx-muted">{t.inherited}</p>}
116
+ </div>
117
+ </Row>
118
+ {hasImage && (
119
+ <>
120
+ {!cover && (
121
+ <Row label={t.size} device={device}>
122
+ <Seg label={t.size} value={bg.size?.[device]} onChange={(v) => setAt("size", v)}
123
+ options={[["cover", t.cover, t.cover_help], ["contain", t.contain, t.contain_help], ["auto", t.auto, t.auto_help]]} />
124
+ </Row>
125
+ )}
126
+ <Row label={t.focal} device={cover ? undefined : device}>
127
+ <div role="radiogroup" aria-label={t.focal} className="ecx-bg-focal">
128
+ {POSITIONS.map((p) => {
129
+ const on = (focal ?? (cover || device === "base" ? "50% 50%" : undefined)) === p;
130
+ const v = p === "50% 50%" && (cover || device === "base") ? undefined : p;
131
+ return <button key={p} type="button" role="radio" aria-checked={on} title={p} aria-label={p} className={cx("ecx-bg-focal-dot", on && "is-active")}
132
+ onClick={() => (cover ? setAttrs({ focal: v }) : setAt("position", v))} />;
133
+ })}
134
+ </div>
135
+ </Row>
136
+ {!cover && <label className="ecx-check"><input type="checkbox" checked={!!bg.repeat} onChange={(e) => setBg({ repeat: e.target.checked || undefined })} /> {t.repeat}</label>}
137
+ <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
+ </>
139
+ )}
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
+ )}
148
+ </>
149
+ )}
70
150
  </>
71
151
  )}
72
- <Row label={t.overlay}>
73
- <ColorInput label={t.overlay} value={bg.overlay} onChange={(v) => set({ overlay: v, overlayOpacity: v ? bg.overlayOpacity : undefined })} />
74
- </Row>
75
- {bg.overlay && (
76
- <Row label={`${t.opacity}: ${bg.overlayOpacity ?? 50}%`}>
77
- <input type="range" min={0} max={100} step={5} value={bg.overlayOpacity ?? 50} aria-label={t.opacity}
78
- onChange={(e) => set({ overlayOpacity: Number(e.target.value) === 50 ? undefined : Number(e.target.value) })} />
79
- </Row>
80
- )}
81
152
  </Section>
82
153
  );
83
154
  }
@@ -0,0 +1,78 @@
1
+ import { coreControlsFor, optionValue, type ControlSpec, type Device } from "@ecomcx/ecomweb-content";
2
+ import { useState } from "react";
3
+ import { useMsgs } from "../i18n";
4
+ import { ColorInput } from "./color-field";
5
+ import { Row, Section, cx } from "./style-controls";
6
+ import { UnitInput } from "./unit-controls";
7
+
8
+ type State = "normal" | "hover" | "active";
9
+
10
+ /**
11
+ * Mục Kiểu dáng riêng của khối lõi (như tab Style của từng widget Elementor: Danh sách › khoảng cách, đường kẻ; Icon › màu, cỡ…).
12
+ * Ô khai ở @ecomcx/ecomweb-content core-controls → website và khung soạn sinh cùng CSS (controlsCss). Ô `responsive` sửa theo khổ
13
+ * đang chọn ở đầu tab; ô có `state` nằm trong thẻ Rê chuột / Đang mở của mục.
14
+ */
15
+ export function BlockStyleSections({ type, attrs, setAttrs, device }: { type: string; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void; device: Device }) {
16
+ const t = useMsgs("blockStyle");
17
+ const sections = new Map<string, Array<[string, ControlSpec]>>();
18
+ for (const [name, spec] of Object.entries(coreControlsFor(type))) {
19
+ const k = spec.section ?? "text";
20
+ sections.set(k, [...(sections.get(k) ?? []), [name, spec]]);
21
+ }
22
+ if (!sections.size) return null;
23
+ return <>{[...sections].map(([key, list]) => <ControlSection key={key} title={(t.section as Record<string, string>)[key] ?? key} list={list} attrs={attrs} setAttrs={setAttrs} device={device} />)}</>;
24
+ }
25
+
26
+ function ControlSection({ title, list, attrs, setAttrs, device }: { title: string; list: Array<[string, ControlSpec]>; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void; device: Device }) {
27
+ const t = useMsgs("blockStyle");
28
+ const states = [...new Set(list.map(([, s]) => s.state ?? "normal"))] as State[];
29
+ const [state, setState] = useState<State>("normal");
30
+ const modified = list.some(([k]) => attrs[k] !== undefined);
31
+ const shown = list.filter(([, s]) => (s.state ?? "normal") === state);
32
+ return (
33
+ <Section title={title} modified={modified} onReset={() => setAttrs(Object.fromEntries(list.map(([k]) => [k, undefined])))}>
34
+ {states.length > 1 && (
35
+ <div role="tablist" className="ecx-seg is-text ecx-state-tabs">
36
+ {(["normal", "hover", "active"] as const).filter((s) => states.includes(s)).map((s) => (
37
+ <button key={s} type="button" role="tab" aria-selected={state === s} className={cx("ecx-seg-btn", state === s && "is-active")} onClick={() => setState(s)}>{t[s]}</button>
38
+ ))}
39
+ </div>
40
+ )}
41
+ {shown.map(([name, spec]) => <ControlField key={name} name={name} spec={spec} value={attrs[name]} device={device} onChange={(v) => setAttrs({ [name]: v })} />)}
42
+ </Section>
43
+ );
44
+ }
45
+
46
+ /** Một ô: giá trị theo khổ (`responsive`) lưu `{ base, tablet, mobile }`, khổ chưa đặt hiện giá trị kế thừa làm gợi ý. */
47
+ function ControlField({ name, spec, value, device, onChange }: { name: string; spec: ControlSpec; value: unknown; device: Device; onChange(v: unknown): void }) {
48
+ const t = useMsgs("blockStyle");
49
+ const label = (t.attr as Record<string, string>)[name] ?? name;
50
+ const map = spec.responsive ? (value && typeof value === "object" ? value as Record<string, unknown> : value === undefined ? {} : { base: value }) : null;
51
+ const v = map ? map[device] : value;
52
+ const inherited = map && device !== "base" && v === undefined ? (device === "mobile" ? map.tablet ?? map.base : map.base) : undefined;
53
+ const set = (x: unknown) => {
54
+ if (!map) return onChange(x === "" ? undefined : x);
55
+ const next = { ...map };
56
+ if (x === undefined || x === "") delete next[device]; else next[device] = x;
57
+ const keys = Object.keys(next);
58
+ onChange(!keys.length ? undefined : keys.length === 1 && keys[0] === "base" ? next.base : next);
59
+ };
60
+ const dev = spec.responsive ? device : undefined;
61
+ if (spec.type === "color") return <Row label={label} device={dev}><ColorInput label={label} value={typeof v === "string" ? v : undefined} onChange={set} /></Row>;
62
+ if (spec.type === "length") return <Row label={label} device={dev}><UnitInput label={label} value={typeof v === "string" ? v : undefined} placeholder={typeof inherited === "string" ? inherited : undefined} units={["px", "rem", "em", "%"]} onChange={set} /></Row>;
63
+ if (spec.type === "number") return (
64
+ <Row label={`${label}${typeof v === "number" ? `: ${v}` : ""}`} device={dev}>
65
+ <input type="range" className="ecx-range" min={spec.min} max={spec.max} step={spec.step ?? 1} value={typeof v === "number" ? v : spec.max ?? 1} aria-label={label}
66
+ onChange={(e) => set(Number(e.target.value) === spec.max ? undefined : Number(e.target.value))} />
67
+ </Row>
68
+ );
69
+ const opts = t.opt as Record<string, string>;
70
+ return (
71
+ <Row label={label} device={dev}>
72
+ <select className="ecx-input" aria-label={label} value={typeof v === "string" ? v : ""} onChange={(e) => set(e.target.value || undefined)}>
73
+ <option value="">{typeof inherited === "string" ? `↳ ${opts[inherited] ?? inherited}` : "—"}</option>
74
+ {spec.options?.map((o) => { const x = optionValue(o); return <option key={x} value={x}>{opts[x] ?? x}</option>; })}
75
+ </select>
76
+ </Row>
77
+ );
78
+ }
@@ -8,18 +8,27 @@ import type { BNode } from "../core/model";
8
8
  import { AttrForm, Field, attrName, cx } from "./attr-form";
9
9
  import { BindingsPanel, CORE_BINDABLE } from "./bindings";
10
10
  import { StyleTab } from "./style-tab";
11
+ import { BackgroundControl } from "./background-panel";
12
+ import { BlockStyleSections } from "./block-style-panel";
13
+ import { styleGroups } from "./style-supports";
11
14
  import { ColorInput } from "./color-field";
12
15
  import { UnitInput } from "./unit-controls";
13
16
  import { useMsgs } from "../i18n";
14
17
 
15
- /** Bảng cài đặt của khối đang chọn: thẻ khối, tab Cài đặt (form + phần riêng của khối), tab Kiểu dáng. */
18
+ /** Khối "khung" (như Container / Section của Elementor): ô Nền đặt ngay tab Cài đặt — chỗ người dùng tìm đầu tiên. */
19
+ const BG_IN_SETTINGS = new Set(["group", "column", "cover"]);
20
+
21
+ /**
22
+ * Bảng cài đặt của khối đang chọn (như Elementor): thẻ khối, tab Cài đặt (nội dung: form + phần riêng của khối), tab Kiểu dáng
23
+ * (mục riêng của khối từ core-controls + ô Nền + chữ / màu) và tab Nâng cao (khoảng cách, viền, hiệu ứng, chuyển động, ẩn hiện, neo / class).
24
+ */
16
25
  export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<{ name: string; label: string }>> }) {
17
26
  const { store, registry, labels, ui } = useEditor();
18
27
  useUiTick();
19
28
  const t = useMsgs("controls");
20
29
  const sel = useEditorState((s) => s.selection);
21
30
  useEditorState((s) => s.revision);
22
- const [tab, setTab] = useState<"settings" | "style">("settings");
31
+ const [tab, setTab] = useState<"settings" | "style" | "advanced">("settings");
23
32
  // Khổ dùng chung với khung soạn: chọn "Điện thoại" ở đây thì khung soạn cũng thu về khổ điện thoại
24
33
  const device: Device = ui.device === "desktop" ? "base" : ui.device;
25
34
  const setDevice = (d: Device) => ui.setDevice(d === "base" ? "desktop" : d);
@@ -32,9 +41,11 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
32
41
  const Icon = type?.icon ?? Blocks;
33
42
  const disabled = store.modeOf(first.id) === "disabled";
34
43
  const setAttrs = (a: Record<string, unknown>) => store.setAttrs(ids, a);
35
- const Custom = same && nodes.length === 1 ? type?.inspector : undefined;
44
+ const single = same && nodes.length === 1;
45
+ const Custom = single ? type?.inspector : undefined;
46
+ const styled = type?.supports?.style !== false && !store.isContentOnly(first.id);
36
47
  const bindable = type?.bindable ?? CORE_BINDABLE[first.type];
37
- const variants = [...(CORE_BLOCK_STYLES[first.type] ?? []).map((name) => ({ name, label: name })), ...(blockStyles?.[first.type] ?? [])];
48
+ const variants = [...(CORE_BLOCK_STYLES[first.type] ?? []).map((name) => ({ name, label: (t.blockStyle as Record<string, string>)[name] ?? name })), ...(blockStyles?.[first.type] ?? [])];
38
49
  return (
39
50
  <div className="ecx-inspector">
40
51
  <div className="ecx-block-card">
@@ -45,28 +56,37 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
45
56
  <>
46
57
  <div className="ecx-tabs" role="tablist">
47
58
  <button type="button" role="tab" aria-selected={tab === "settings"} className={cx(tab === "settings" && "is-active")} onClick={() => setTab("settings")}>{labels.settings}</button>
48
- {type?.supports?.style !== false && !store.isContentOnly(first.id) && <button type="button" role="tab" aria-selected={tab === "style"} className={cx(tab === "style" && "is-active")} onClick={() => setTab("style")}>{t.styles}</button>}
59
+ {styled && <button type="button" role="tab" aria-selected={tab === "style"} className={cx(tab === "style" && "is-active")} onClick={() => setTab("style")}>{t.styles}</button>}
60
+ {(styled || nodes.length === 1) && <button type="button" role="tab" aria-selected={tab === "advanced"} className={cx(tab === "advanced" && "is-active")} onClick={() => setTab("advanced")}>{t.advanced}</button>}
49
61
  </div>
50
- {tab === "settings" ? (
62
+ {tab === "settings" || (tab === "style" && !styled) ? (
51
63
  <div className="ecx-panel">
52
64
  {same && type && <AttrForm type={type} attrs={first.attrs} onChange={setAttrs} />}
65
+ {styled && single && BG_IN_SETTINGS.has(first.type) && <BackgroundControl key={first.id} type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />}
53
66
  {Custom && <Custom block={first} attrs={first.attrs} setAttrs={setAttrs} blockProps={null as never} selected editable labels={labels} />}
54
67
  {same && nodes.length === 1 && <PluginPanels type={first.type} attrs={first.attrs} setAttrs={setAttrs} />}
55
68
  {nodes.length === 1 && bindable?.length && <BindingsPanel block={first} bindable={bindable} onChange={(b) => setAttrs({ bindings: b })} />}
69
+ </div>
70
+ ) : tab === "style" ? (
71
+ <div className="ecx-panel">
72
+ <StyleTab type={first.type} style={first.attrs.style} onChange={(st) => setAttrs({ style: st ?? undefined })} device={device} onDeviceChange={setDevice} part="style"
73
+ variants={variants.length ? variants : undefined} variant={(first.attrs.blockStyle as string) ?? null} onVariantChange={(v) => setAttrs({ blockStyle: v ?? undefined })}
74
+ lead={single && <>
75
+ <BlockStyleSections type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />
76
+ {!BG_IN_SETTINGS.has(first.type) && (styleGroups(first.type, type).has("background") || !!(first.attrs.style as { background?: unknown } | undefined)?.background) && <BackgroundControl key={first.id} type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />}
77
+ </>} />
78
+ {single && <PluginPanels type={first.type} attrs={first.attrs} setAttrs={setAttrs} tab="style" />}
79
+ </div>
80
+ ) : (
81
+ <div className="ecx-panel">
82
+ {styled && <StyleTab type={first.type} style={first.attrs.style} onChange={(st) => setAttrs({ style: st ?? undefined })} device={device} onDeviceChange={setDevice} part="advanced" />}
56
83
  {nodes.length === 1 && (
57
- <details className="ecx-advanced">
58
- <summary>{t.advanced}</summary>
84
+ <div className="ecx-form">
59
85
  <Field label={attrName("anchor", labels.lang) ?? "anchor"}><input className="ecx-input" value={String(first.attrs.anchor ?? "")} onChange={(e) => setAttrs({ anchor: e.target.value.replace(/[^\w-]/g, "") || undefined })} /></Field>
60
86
  <Field label={attrName("className", labels.lang) ?? "className"}><input className="ecx-input" value={String(first.attrs.className ?? "")} onChange={(e) => setAttrs({ className: e.target.value || undefined })} /></Field>
61
- </details>
87
+ </div>
62
88
  )}
63
89
  </div>
64
- ) : (
65
- <div className="ecx-panel">
66
- <StyleTab type={first.type} style={first.attrs.style} onChange={(st) => setAttrs({ style: st ?? undefined })} device={device} onDeviceChange={setDevice}
67
- variants={variants.length ? variants : undefined} variant={(first.attrs.blockStyle as string) ?? null} onVariantChange={(v) => setAttrs({ blockStyle: v ?? undefined })} />
68
- {same && nodes.length === 1 && <PluginPanels type={first.type} attrs={first.attrs} setAttrs={setAttrs} tab="style" />}
69
- </div>
70
90
  )}
71
91
  </>
72
92
  )}
@@ -21,7 +21,40 @@ export function layoutFor(kind: Kind, prev?: BlockLayout): BlockLayout | undefin
21
21
  return { type: "flex", direction: { base: kind === "stack" ? "column" : "row" }, ...(prev?.justify ? { justify: prev.justify } : {}), ...(prev?.align ? { align: prev.align } : {}) };
22
22
  }
23
23
 
24
- export function LayoutEffectsPanel({ type, style: raw, onChange, device, effects = true, hover = true }: { type: string; style: unknown; onChange(style: BlockStyle | null): void; device: Device; effects?: boolean; hover?: boolean }) {
24
+ /** Nền chuyển màu: preset của theme hoặc hai màu + góc (dùng ở mục Hiệu ứng và ô Nền). */
25
+ export function GradientField({ value, onChange }: { value?: string; onChange(g: string | undefined): void }) {
26
+ const { host } = useEditor();
27
+ const t = useMsgs("layout");
28
+ const gradPresets = Object.keys(host.presets?.gradients ?? {});
29
+ const g = value && !gradPresets.includes(value) ? /^linear-gradient\((\d{1,3})deg, (#[0-9a-f]{3,8}) 0%, (#[0-9a-f]{3,8}) 100%\)$/i.exec(value) : null;
30
+ const [angle, setAngle] = useState(g ? Number(g[1]) : 135);
31
+ const [c1, setC1] = useState(g?.[2] ?? "#1a597b");
32
+ const [c2, setC2] = useState(g?.[3] ?? "#f26251");
33
+ const applyCustom = (a = angle, x = c1, y = c2) => onChange(normalizeGradient(`linear-gradient(${a}deg, ${x} 0%, ${y} 100%)`));
34
+ return (
35
+ <>
36
+ <div className="ecx-chip-row">
37
+ <button type="button" className={cx("ecx-chip", !value && "is-active")} onClick={() => onChange(undefined)}>{t.none}</button>
38
+ {gradPresets.map((name) => (
39
+ <button key={name} type="button" className={cx("ecx-chip ecx-chip-swatch", value === name && "is-active")} title={name} aria-label={name}
40
+ style={{ background: host.presets!.gradients![name] }} onClick={() => onChange(name)} />
41
+ ))}
42
+ <button type="button" className={cx("ecx-chip ecx-chip-swatch", g && "is-active")} title={t.custom}
43
+ style={{ background: `linear-gradient(${angle}deg, ${c1}, ${c2})` }} onClick={() => applyCustom()} />
44
+ </div>
45
+ {g && (
46
+ <div className="ecx-gradient-edit">
47
+ <label>{t.from} <input type="color" value={c1} onChange={(e) => { setC1(e.target.value); applyCustom(angle, e.target.value, c2); }} /></label>
48
+ <label>{t.to} <input type="color" value={c2} onChange={(e) => { setC2(e.target.value); applyCustom(angle, c1, e.target.value); }} /></label>
49
+ <label>{t.angle} <input type="range" min={0} max={360} step={15} value={angle} onChange={(e) => { setAngle(Number(e.target.value)); applyCustom(Number(e.target.value)); }} aria-label={t.angle} /> {angle}°</label>
50
+ </div>
51
+ )}
52
+ </>
53
+ );
54
+ }
55
+
56
+ /** `gradient` = false khi khối đã có ô Nền (chuyển màu sửa ở đó, không lặp lại ở Hiệu ứng). */
57
+ export function LayoutEffectsPanel({ type, style: raw, onChange, device, effects = true, hover = true, gradient = true }: { type: string; style: unknown; onChange(style: BlockStyle | null): void; device: Device; effects?: boolean; hover?: boolean; gradient?: boolean }) {
25
58
  const { labels, host } = useEditor();
26
59
  const t = useMsgs("layout");
27
60
  const style: BlockStyle = normalizeStyle(raw) ?? {};
@@ -40,13 +73,6 @@ export function LayoutEffectsPanel({ type, style: raw, onChange, device, effects
40
73
  return Object.keys(next).length ? next : undefined;
41
74
  };
42
75
 
43
- // Nền chuyển màu: preset của theme hoặc hai màu + góc
44
- const gradPresets = Object.keys(host.presets?.gradients ?? {});
45
- const g = style.gradient && !gradPresets.includes(style.gradient) ? /^linear-gradient\((\d{1,3})deg, (#[0-9a-f]{3,8}) 0%, (#[0-9a-f]{3,8}) 100%\)$/i.exec(style.gradient) : null;
46
- const [angle, setAngle] = useState(g ? Number(g[1]) : 135);
47
- const [c1, setC1] = useState(g?.[2] ?? "#1a597b");
48
- const [c2, setC2] = useState(g?.[3] ?? "#f26251");
49
- const applyCustom = (a = angle, x = c1, y = c2) => set({ gradient: normalizeGradient(`linear-gradient(${a}deg, ${x} 0%, ${y} 100%)`) });
50
76
  const shadows = ["sm", "md", "lg", "xl", ...Object.keys(host.presets?.shadows ?? {}).filter((s) => !["sm", "md", "lg", "xl"].includes(s))];
51
77
 
52
78
  return (
@@ -93,24 +119,7 @@ export function LayoutEffectsPanel({ type, style: raw, onChange, device, effects
93
119
  )}
94
120
 
95
121
  {effects && <Section title={t.effects} defaultOpen={!!(style.gradient || style.shadow || style.aspectRatio || style.position)}>
96
- <Row label={t.gradient}>
97
- <div className="ecx-chip-row">
98
- <button type="button" className={cx("ecx-chip", !style.gradient && "is-active")} onClick={() => set({ gradient: undefined })}>{t.none}</button>
99
- {gradPresets.map((name) => (
100
- <button key={name} type="button" className={cx("ecx-chip ecx-chip-swatch", style.gradient === name && "is-active")} title={name} aria-label={name}
101
- style={{ background: host.presets!.gradients![name] }} onClick={() => set({ gradient: name })} />
102
- ))}
103
- <button type="button" className={cx("ecx-chip ecx-chip-swatch", g && "is-active")} title={t.custom}
104
- style={{ background: `linear-gradient(${angle}deg, ${c1}, ${c2})` }} onClick={() => applyCustom()} />
105
- </div>
106
- {g && (
107
- <div className="ecx-gradient-edit">
108
- <label>{t.from} <input type="color" value={c1} onChange={(e) => { setC1(e.target.value); applyCustom(angle, e.target.value, c2); }} /></label>
109
- <label>{t.to} <input type="color" value={c2} onChange={(e) => { setC2(e.target.value); applyCustom(angle, c1, e.target.value); }} /></label>
110
- <label>{t.angle} <input type="range" min={0} max={360} step={15} value={angle} onChange={(e) => { setAngle(Number(e.target.value)); applyCustom(Number(e.target.value)); }} aria-label={t.angle} /> {angle}°</label>
111
- </div>
112
- )}
113
- </Row>
122
+ {gradient && <Row label={t.gradient}><GradientField value={style.gradient} onChange={(g) => set({ gradient: g })} /></Row>}
114
123
  <Row label={t.shadow}>
115
124
  <select className="ecx-input" aria-label={t.shadow} value={style.shadow ?? ""} onChange={(e) => set({ shadow: e.target.value || undefined })}>
116
125
  <option value="">—</option><option value="none">{t.none}</option>
@@ -15,6 +15,8 @@ const CORE: Record<string, StyleGroup[]> = {
15
15
  image: MEDIA, gallery: MEDIA, video: MEDIA, youtube: MEDIA, embed: MEDIA, featuredImage: MEDIA, siteLogo: MEDIA, avatar: MEDIA,
16
16
  icon: ["color", "spacing", "motion", "visibility"],
17
17
  socialLinks: ["color", "spacing", "motion", "visibility"],
18
+ // Màu nút (Thường / Rê chuột) ở mục Nút riêng (core-controls) — không lặp nhóm Màu chung (dữ liệu cũ có màu vẫn hiện để sửa)
19
+ button: NO_BACKGROUND.filter((g) => g !== "color"),
18
20
  };
19
21
 
20
22
  /**
@@ -3,7 +3,6 @@ import { AlignCenter, AlignJustify, AlignLeft, AlignRight, Monitor, Smartphone,
3
3
  import { useEffect, useState, type ReactNode } from "react";
4
4
  import { labelsLegacy, type EditorLabels } from "../../shared/labels";
5
5
  import { useEditor } from "../context";
6
- import { BackgroundPanel } from "./background-panel";
7
6
  import { ColorInput } from "./color-field";
8
7
  import { LayoutEffectsPanel } from "./layout-panel";
9
8
  import { MotionPanel } from "./motion-panel";
@@ -41,9 +40,15 @@ function ValueInput({ value, onCommit, check, placeholder, label, inherited }: {
41
40
  onChange={(e) => setText(e.target.value)} onBlur={commit} onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); commit(); } }} />;
42
41
  }
43
42
 
44
- export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, variants, variant, onVariantChange }: {
43
+ /**
44
+ * `part`: "style" = biến thể, chữ, màu (tab Kiểu dáng); "advanced" = khoảng cách, viền, bố cục / hiệu ứng, hover, chuyển động, ẩn hiện
45
+ * (tab Nâng cao — lớp chung của mọi khối như Advanced của Elementor); bỏ trống = tất cả. Ô Nền vẽ ở BackgroundControl.
46
+ */
47
+ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, variants, variant, onVariantChange, part, lead }: {
45
48
  type: string; style: unknown; onChange(style: BlockStyle | null): void; device: Device; onDeviceChange(d: Device): void;
46
- variants?: Array<{ name: string; label: string }>; variant?: string | null; onVariantChange?(v: string | null): void;
49
+ variants?: Array<{ name: string; label: string }>; variant?: string | null; onVariantChange?(v: string | null): void; part?: "style" | "advanced";
50
+ /** Mục vẽ sau Chữ / Màu (mục riêng của khối, ô Nền). */
51
+ lead?: ReactNode;
47
52
  }) {
48
53
  const { host, labels, registry } = useEditor();
49
54
  const t = labelsLegacy(labels.lang);
@@ -90,7 +95,8 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
90
95
  );
91
96
  // Nhóm khối hỗ trợ; nhóm đã có giá trị vẫn hiện để sửa / xoá (dữ liệu cũ, khối dán từ nơi khác)
92
97
  const groups = styleGroups(type, registry.get(type));
93
- const show = (g: StyleGroup, keys: string[]) => groups.has(g) || keys.some((k) => style[k] !== undefined);
98
+ const inPart = (g: StyleGroup) => !part || (part === "style") === ["typography", "color"].includes(g);
99
+ const show = (g: StyleGroup, keys: string[]) => inPart(g) && (groups.has(g) || keys.some((k) => style[k] !== undefined));
94
100
  const appearance = `${style.fontWeight ?? ""}${style.fontStyle === "italic" ? "i" : ""}`;
95
101
 
96
102
  return (
@@ -101,7 +107,7 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
101
107
  options={[["base", Monitor, t.device_base], ["tablet", Tablet, t.device_tablet], ["mobile", Smartphone, t.device_mobile]]} />
102
108
  </div>
103
109
 
104
- {variants && variants.length > 0 && (
110
+ {part !== "advanced" && variants && variants.length > 0 && (
105
111
  <div className="ecx-style-row">
106
112
  <span className="ecx-field-label">{t.blockVariant}</span>
107
113
  <div role="radiogroup" aria-label={t.blockVariant} className="ecx-seg is-text">
@@ -146,10 +152,11 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
146
152
 
147
153
  {show("color", ["color"]) && <Section title={t.style_color} modified={has(["color"])} onReset={() => reset(["color"])}>
148
154
  {row("text", t.style_text, <ColorInput label={t.style_text} value={style.color?.text} onChange={(v) => setGroup("color", "text", v)} />)}
149
- {row("background", t.style_background, <ColorInput label={t.style_background} value={style.color?.background} onChange={(v) => setGroup("color", "background", v)} />)}
155
+ {/* Khối có ô Nền: màu nền sửa ở đó (một chỗ) */}
156
+ {(!groups.has("background") || part === undefined) && row("background", t.style_background, <ColorInput label={t.style_background} value={style.color?.background} onChange={(v) => setGroup("color", "background", v)} />)}
150
157
  </Section>}
151
158
 
152
- {show("background", ["background"]) && <BackgroundPanel style={raw} onChange={onChange} device={device} />}
159
+ {lead}
153
160
 
154
161
  {show("spacing", SPACING) && <Section title={t.style_spacing} modified={has(SPACING)} onReset={() => reset(SPACING)} moreOpen={has(["gap", "width", "maxWidth", "minHeight"])}
155
162
  more={<>{(["gap", "width", "maxWidth", "minHeight"] as const).map((k) =>
@@ -166,8 +173,8 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
166
173
  {row("radius", t.style_radius, <UnitInput label={t.style_radius} value={typeof style.radius === "string" ? style.radius : undefined} max={60} units={["px", "%", "em", "rem"]} onChange={(v) => set("radius", v)} />)}
167
174
  </Section>}
168
175
 
169
- <LayoutEffectsPanel type={type} style={raw} onChange={onChange} device={device}
170
- effects={show("effects", ["gradient", "shadow", "aspectRatio", "position"])} hover={show("hover", ["hover"])} />
176
+ {part !== "style" && <LayoutEffectsPanel type={type} style={raw} onChange={onChange} device={device}
177
+ effects={show("effects", ["gradient", "shadow", "aspectRatio", "position"])} hover={show("hover", ["hover"])} gradient={!groups.has("background")} />}
171
178
 
172
179
  {show("motion", ["motion"]) && <MotionPanel type={type} style={raw} onChange={onChange} />}
173
180
 
@@ -99,7 +99,8 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
99
99
  useLayoutEffect(() => {
100
100
  // Trong bảng: thanh công cụ neo theo cả bảng (như WordPress) — neo theo ô thì thanh đè lên hàng phía trên
101
101
  const loc0 = ids[0] ? store.locate(ids[0]) : null;
102
- const table = loc0 ? [...loc0.ancestors].reverse().find((a) => store.block(a)?.type === "table") : undefined;
102
+ // Tab: neo theo cả khối Tabs — neo theo nội dung tab thì thanh đè lên thanh tiêu đề tab
103
+ const table = loc0 ? [...loc0.ancestors].reverse().find((a) => ["table", "tabs"].includes(store.block(a)?.type ?? "")) : undefined;
103
104
  const r = table ? ui.blockRect(table) : unionRect(ids.map((id) => ui.blockRect(id)));
104
105
  setRect((prev) => (prev && r && prev.x === r.x && prev.y === r.y && prev.width === r.width && prev.height === r.height ? prev : r));
105
106
  });
@@ -15,6 +15,12 @@ const parse = (v: unknown): { n: string; unit: string } | null => {
15
15
  const m = typeof v === "string" ? /^(-?\d*\.?\d+)(px|rem|em|%|vw|vh)?$/.exec(v.trim()) : typeof v === "number" ? [String(v), String(v), "px"] : null;
16
16
  return m ? { n: m[1], unit: m[2] ?? "px" } : null;
17
17
  };
18
+ /** Đổi đơn vị giữ nguyên cỡ thật: px ↔ rem / em theo 16px (22px → 1.375rem). %, vw, vh phụ thuộc khung chứa → giữ số. */
19
+ export const convertUnit = (n: string, from: string, to: string): string => {
20
+ const px = (u: string) => (u === "px" ? 1 : u === "rem" || u === "em" ? 16 : 0);
21
+ if (n === "" || !px(from) || !px(to) || !Number.isFinite(Number(n))) return n;
22
+ return String(Math.round((Number(n) * px(from)) / px(to) * 1000) / 1000);
23
+ };
18
24
 
19
25
  export function UnitInput({ value, onChange, label, max = 100, units = UNITS, slider = true, placeholder }: { value?: string; onChange(v: string | undefined): void; label: string; max?: number; units?: string[]; slider?: boolean; placeholder?: string }) {
20
26
  const t = useMsgs("controls");
@@ -29,7 +35,7 @@ export function UnitInput({ value, onChange, label, max = 100, units = UNITS, sl
29
35
  <div className="ecx-unit-input">
30
36
  <input type="number" inputMode="decimal" aria-label={label} value={n} placeholder={p ? undefined : value ?? placeholder ?? ""} step={unit === "px" || unit === "%" ? 1 : 0.1}
31
37
  onChange={(e) => { setN(e.target.value); emit(e.target.value, unit); }} />
32
- <select aria-label={`${label}: ${t.unit}`} value={unit} onChange={(e) => { setUnit(e.target.value); if (n !== "") emit(n, e.target.value); }}>
38
+ <select aria-label={`${label}: ${t.unit}`} value={unit} onChange={(e) => { const u = e.target.value, m = convertUnit(n, unit, u); setUnit(u); setN(m); if (m !== "") emit(m, u); }}>
33
39
  {units.map((u) => <option key={u} value={u}>{u}</option>)}
34
40
  </select>
35
41
  </div>