@ecomcx/ecomweb-editor 1.28.0 → 1.29.1
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 +3 -3
- package/src/locales/en/attrs.ts +10 -0
- package/src/locales/en/block-desc.ts +6 -0
- package/src/locales/en/block-titles.ts +6 -0
- package/src/locales/en/blocks.ts +18 -0
- package/src/locales/en/controls.ts +2 -0
- package/src/locales/en/hints.ts +39 -0
- package/src/locales/vi/attrs.ts +10 -0
- package/src/locales/vi/block-desc.ts +6 -0
- package/src/locales/vi/block-titles.ts +6 -0
- package/src/locales/vi/blocks.ts +18 -0
- package/src/locales/vi/controls.ts +2 -0
- package/src/locales/vi/hints.ts +39 -0
- package/src/shared/panel-store.ts +2 -0
- package/src/v2/blocks/index.ts +2 -1
- package/src/v2/blocks/theme.tsx +3 -1
- package/src/v2/blocks/widgets.tsx +65 -0
- package/src/v2/ui/attr-hints.ts +16 -1
- package/src/v2/ui/background-panel.tsx +5 -0
- package/src/v2/ui/inspector.tsx +23 -3
- package/src/v2/ui/unit-controls.tsx +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecomcx/ecomweb-editor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.29.1",
|
|
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.
|
|
32
|
+
"@ecomcx/ecomweb-content": "^1.23.1",
|
|
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.
|
|
48
|
+
"@ecomcx/ecomweb-content": "^1.23.1",
|
|
49
49
|
"@playwright/test": "1.53.0",
|
|
50
50
|
"@types/react": "19.2.2",
|
|
51
51
|
"@types/react-dom": "19.2.2",
|
package/src/locales/en/attrs.ts
CHANGED
|
@@ -76,4 +76,14 @@ export const attrs = {
|
|
|
76
76
|
submitText: "Submit button text",
|
|
77
77
|
successMessage: "Thank-you message",
|
|
78
78
|
notifyEmail: "Notification email",
|
|
79
|
+
icon: "Icon",
|
|
80
|
+
quote: "Quote",
|
|
81
|
+
name: "Name",
|
|
82
|
+
role: "Role",
|
|
83
|
+
label: "Label",
|
|
84
|
+
value: "Value",
|
|
85
|
+
end: "End number",
|
|
86
|
+
suffix: "Suffix",
|
|
87
|
+
duration: "Duration (ms)",
|
|
88
|
+
showValue: "Show percentage",
|
|
79
89
|
};
|
|
@@ -81,4 +81,10 @@ export const blockDesc = {
|
|
|
81
81
|
tableRow: "One table row.",
|
|
82
82
|
tableHeader: "Table header cell.",
|
|
83
83
|
tableCell: "One table cell.",
|
|
84
|
+
iconBox: "Icon + title + description (feature / service card), optional link; icon on top or to the left.",
|
|
85
|
+
imageBox: "Image + title + description (service / product / location card), optional link.",
|
|
86
|
+
iconList: "List with an icon at the start of each line (benefits, checklist, contact details), vertical or inline; each item can link.",
|
|
87
|
+
counter: "Highlighted number (e.g. 1,200+ customers) that counts up when scrolled into view; prefix / suffix and label.",
|
|
88
|
+
testimonial: "Customer testimonial: quote, name, role and avatar.",
|
|
89
|
+
progressBar: "Labelled progress bar with a percentage (skills, goals) that fills when scrolled into view.",
|
|
84
90
|
};
|
|
@@ -54,4 +54,10 @@ export const blockTitles = {
|
|
|
54
54
|
queryEmpty: "No results",
|
|
55
55
|
form: "Form",
|
|
56
56
|
formField: "Form field",
|
|
57
|
+
iconBox: "Icon Box",
|
|
58
|
+
imageBox: "Image Box",
|
|
59
|
+
iconList: "Icon List",
|
|
60
|
+
counter: "Counter",
|
|
61
|
+
testimonial: "Testimonial",
|
|
62
|
+
progressBar: "Progress Bar",
|
|
57
63
|
};
|
package/src/locales/en/blocks.ts
CHANGED
|
@@ -58,4 +58,22 @@ export const blocks = {
|
|
|
58
58
|
fieldName: "Full name",
|
|
59
59
|
option1: "Option 1",
|
|
60
60
|
option2: "Option 2",
|
|
61
|
+
widgetEmpty: "Add items in the settings panel",
|
|
62
|
+
iconListItems: "Items (one per line, add a link: text | /path)",
|
|
63
|
+
widget_title: "Title",
|
|
64
|
+
widget_text: "Short description",
|
|
65
|
+
widget_quote: "What a customer says about you",
|
|
66
|
+
widget_name: "Customer name",
|
|
67
|
+
widget_role: "Role / company",
|
|
68
|
+
widget_label: "Label",
|
|
69
|
+
sampleTitle: "Feature title",
|
|
70
|
+
sampleText: "A short line on the benefit for the customer.",
|
|
71
|
+
sampleItem1: "First benefit",
|
|
72
|
+
sampleItem2: "Second benefit",
|
|
73
|
+
sampleItem3: "Third benefit",
|
|
74
|
+
sampleCounter: "Happy customers",
|
|
75
|
+
sampleQuote: "Caring service and on-time delivery. I will be back!",
|
|
76
|
+
sampleName: "Customer name",
|
|
77
|
+
sampleRole: "Role, company",
|
|
78
|
+
sampleSkill: "Skill",
|
|
61
79
|
};
|
|
@@ -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
|
};
|
package/src/locales/en/hints.ts
CHANGED
|
@@ -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",
|
|
@@ -201,4 +202,42 @@ export const hints = {
|
|
|
201
202
|
"formField.kind.opt.consent": "Consent",
|
|
202
203
|
"formField.kind.opt.number": "Number",
|
|
203
204
|
"formField.kind.opt.date": "Date",
|
|
205
|
+
"iconBox.icon.opt.check": "Check",
|
|
206
|
+
"iconBox.icon.opt.x": "X",
|
|
207
|
+
"iconBox.icon.opt.star": "Star",
|
|
208
|
+
"iconBox.icon.opt.heart": "Heart",
|
|
209
|
+
"iconBox.icon.opt.arrowRight": "Arrow right",
|
|
210
|
+
"iconBox.icon.opt.phone": "Phone",
|
|
211
|
+
"iconBox.icon.opt.mail": "Mail",
|
|
212
|
+
"iconBox.icon.opt.mapPin": "Map pin",
|
|
213
|
+
"iconBox.icon.opt.clock": "Clock",
|
|
214
|
+
"iconBox.icon.opt.info": "Info",
|
|
215
|
+
"iconBox.icon.opt.alert": "Alert",
|
|
216
|
+
"iconBox.icon.opt.externalLink": "External link",
|
|
217
|
+
"iconList.icon.opt.check": "Check",
|
|
218
|
+
"iconList.icon.opt.x": "X",
|
|
219
|
+
"iconList.icon.opt.star": "Star",
|
|
220
|
+
"iconList.icon.opt.heart": "Heart",
|
|
221
|
+
"iconList.icon.opt.arrowRight": "Arrow right",
|
|
222
|
+
"iconList.icon.opt.phone": "Phone",
|
|
223
|
+
"iconList.icon.opt.mail": "Mail",
|
|
224
|
+
"iconList.icon.opt.mapPin": "Map pin",
|
|
225
|
+
"iconList.icon.opt.clock": "Clock",
|
|
226
|
+
"iconList.icon.opt.info": "Info",
|
|
227
|
+
"iconList.icon.opt.alert": "Alert",
|
|
228
|
+
"iconList.icon.opt.externalLink": "External link",
|
|
229
|
+
"iconBox.position.label": "Icon position",
|
|
230
|
+
"iconBox.position.opt.top": "Top",
|
|
231
|
+
"iconBox.position.opt.left": "Left",
|
|
232
|
+
"imageBox.src.label": "Image",
|
|
233
|
+
"testimonial.src.label": "Avatar",
|
|
234
|
+
"counter.start.label": "Count from",
|
|
235
|
+
"counter.prefix.label": "Prefix (e.g. ~, $)",
|
|
236
|
+
"counter.separator.label": "Thousands separator",
|
|
237
|
+
"counter.separator.opt.none": "None",
|
|
238
|
+
"counter.separator.opt.space": "Space",
|
|
239
|
+
"counter.duration.help": "0 = show the final number at once. Visitors who prefer reduced motion always see the final number.",
|
|
240
|
+
"iconList.layout.opt.list": "Vertical",
|
|
241
|
+
"iconList.layout.opt.inline": "Inline",
|
|
242
|
+
"progressBar.value.label": "Percent",
|
|
204
243
|
};
|
package/src/locales/vi/attrs.ts
CHANGED
|
@@ -76,4 +76,14 @@ export const attrs = {
|
|
|
76
76
|
submitText: "Chữ trên nút gửi",
|
|
77
77
|
successMessage: "Lời cảm ơn sau khi gửi",
|
|
78
78
|
notifyEmail: "Email nhận thông báo",
|
|
79
|
+
icon: "Icon",
|
|
80
|
+
quote: "Lời chứng thực",
|
|
81
|
+
name: "Tên",
|
|
82
|
+
role: "Chức danh",
|
|
83
|
+
label: "Nhãn",
|
|
84
|
+
value: "Giá trị",
|
|
85
|
+
end: "Số cuối",
|
|
86
|
+
suffix: "Hậu tố",
|
|
87
|
+
duration: "Thời gian chạy (ms)",
|
|
88
|
+
showValue: "Hiện phần trăm",
|
|
79
89
|
};
|
|
@@ -81,4 +81,10 @@ export const blockDesc = {
|
|
|
81
81
|
tableRow: "Một hàng của bảng.",
|
|
82
82
|
tableHeader: "Ô tiêu đề của bảng.",
|
|
83
83
|
tableCell: "Một ô của bảng.",
|
|
84
|
+
iconBox: "Icon + tiêu đề + mô tả (thẻ tính năng / dịch vụ), có thể gắn liên kết; icon nằm trên hoặc bên trái.",
|
|
85
|
+
imageBox: "Ảnh + tiêu đề + mô tả (thẻ dịch vụ / sản phẩm / chi nhánh), có thể gắn liên kết.",
|
|
86
|
+
iconList: "Danh sách có icon ở đầu mỗi dòng (lợi ích, checklist, thông tin liên hệ), dọc hoặc hàng ngang; mỗi mục có thể có liên kết.",
|
|
87
|
+
counter: "Con số nổi bật (vd 1.200+ khách hàng) đếm lên khi cuộn tới; có tiền tố / hậu tố và nhãn.",
|
|
88
|
+
testimonial: "Lời chứng thực của khách hàng: câu trích, tên, chức danh và ảnh đại diện.",
|
|
89
|
+
progressBar: "Thanh tiến độ có nhãn và phần trăm (kỹ năng, mục tiêu), chạy lên khi cuộn tới.",
|
|
84
90
|
};
|
|
@@ -54,4 +54,10 @@ export const blockTitles = {
|
|
|
54
54
|
queryEmpty: "Khi không có bài",
|
|
55
55
|
form: "Form",
|
|
56
56
|
formField: "Ô nhập",
|
|
57
|
+
iconBox: "Hộp icon",
|
|
58
|
+
imageBox: "Hộp ảnh",
|
|
59
|
+
iconList: "Danh sách icon",
|
|
60
|
+
counter: "Bộ đếm số",
|
|
61
|
+
testimonial: "Lời chứng thực",
|
|
62
|
+
progressBar: "Thanh tiến độ",
|
|
57
63
|
};
|
package/src/locales/vi/blocks.ts
CHANGED
|
@@ -58,4 +58,22 @@ export const blocks = {
|
|
|
58
58
|
fieldName: "Họ và tên",
|
|
59
59
|
option1: "Lựa chọn 1",
|
|
60
60
|
option2: "Lựa chọn 2",
|
|
61
|
+
widgetEmpty: "Thêm mục ở bảng cài đặt bên phải",
|
|
62
|
+
iconListItems: "Các mục (mỗi dòng một mục, thêm liên kết: chữ | /duong-dan)",
|
|
63
|
+
widget_title: "Tiêu đề",
|
|
64
|
+
widget_text: "Mô tả ngắn",
|
|
65
|
+
widget_quote: "Lời khách hàng nói về bạn",
|
|
66
|
+
widget_name: "Tên khách hàng",
|
|
67
|
+
widget_role: "Chức danh / công ty",
|
|
68
|
+
widget_label: "Nhãn",
|
|
69
|
+
sampleTitle: "Tiêu đề tính năng",
|
|
70
|
+
sampleText: "Mô tả ngắn về lợi ích cho khách hàng.",
|
|
71
|
+
sampleItem1: "Lợi ích thứ nhất",
|
|
72
|
+
sampleItem2: "Lợi ích thứ hai",
|
|
73
|
+
sampleItem3: "Lợi ích thứ ba",
|
|
74
|
+
sampleCounter: "Khách hàng hài lòng",
|
|
75
|
+
sampleQuote: "Dịch vụ tận tâm, giao hàng đúng hẹn. Tôi sẽ quay lại!",
|
|
76
|
+
sampleName: "Tên khách hàng",
|
|
77
|
+
sampleRole: "Chức danh, công ty",
|
|
78
|
+
sampleSkill: "Kỹ năng",
|
|
61
79
|
};
|
|
@@ -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
|
};
|
package/src/locales/vi/hints.ts
CHANGED
|
@@ -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",
|
|
@@ -201,4 +202,42 @@ export const hints = {
|
|
|
201
202
|
"formField.kind.opt.consent": "Đồng ý (điều khoản)",
|
|
202
203
|
"formField.kind.opt.number": "Số",
|
|
203
204
|
"formField.kind.opt.date": "Ngày",
|
|
205
|
+
"iconBox.icon.opt.check": "Dấu tích",
|
|
206
|
+
"iconBox.icon.opt.x": "Dấu X",
|
|
207
|
+
"iconBox.icon.opt.star": "Ngôi sao",
|
|
208
|
+
"iconBox.icon.opt.heart": "Trái tim",
|
|
209
|
+
"iconBox.icon.opt.arrowRight": "Mũi tên phải",
|
|
210
|
+
"iconBox.icon.opt.phone": "Điện thoại",
|
|
211
|
+
"iconBox.icon.opt.mail": "Thư",
|
|
212
|
+
"iconBox.icon.opt.mapPin": "Ghim bản đồ",
|
|
213
|
+
"iconBox.icon.opt.clock": "Đồng hồ",
|
|
214
|
+
"iconBox.icon.opt.info": "Thông tin",
|
|
215
|
+
"iconBox.icon.opt.alert": "Cảnh báo",
|
|
216
|
+
"iconBox.icon.opt.externalLink": "Liên kết ngoài",
|
|
217
|
+
"iconList.icon.opt.check": "Dấu tích",
|
|
218
|
+
"iconList.icon.opt.x": "Dấu X",
|
|
219
|
+
"iconList.icon.opt.star": "Ngôi sao",
|
|
220
|
+
"iconList.icon.opt.heart": "Trái tim",
|
|
221
|
+
"iconList.icon.opt.arrowRight": "Mũi tên phải",
|
|
222
|
+
"iconList.icon.opt.phone": "Điện thoại",
|
|
223
|
+
"iconList.icon.opt.mail": "Thư",
|
|
224
|
+
"iconList.icon.opt.mapPin": "Ghim bản đồ",
|
|
225
|
+
"iconList.icon.opt.clock": "Đồng hồ",
|
|
226
|
+
"iconList.icon.opt.info": "Thông tin",
|
|
227
|
+
"iconList.icon.opt.alert": "Cảnh báo",
|
|
228
|
+
"iconList.icon.opt.externalLink": "Liên kết ngoài",
|
|
229
|
+
"iconBox.position.label": "Vị trí icon",
|
|
230
|
+
"iconBox.position.opt.top": "Trên",
|
|
231
|
+
"iconBox.position.opt.left": "Bên trái",
|
|
232
|
+
"imageBox.src.label": "Ảnh",
|
|
233
|
+
"testimonial.src.label": "Ảnh đại diện",
|
|
234
|
+
"counter.start.label": "Đếm từ",
|
|
235
|
+
"counter.prefix.label": "Tiền tố (vd ~, $)",
|
|
236
|
+
"counter.separator.label": "Dấu nhóm nghìn",
|
|
237
|
+
"counter.separator.opt.none": "Không",
|
|
238
|
+
"counter.separator.opt.space": "Khoảng trắng",
|
|
239
|
+
"counter.duration.help": "0 = hiện ngay số cuối. Người dùng chọn giảm chuyển động luôn thấy số cuối.",
|
|
240
|
+
"iconList.layout.opt.list": "Dọc",
|
|
241
|
+
"iconList.layout.opt.inline": "Hàng ngang",
|
|
242
|
+
"progressBar.value.label": "Phần trăm",
|
|
204
243
|
};
|
|
@@ -26,6 +26,8 @@ export interface BlockPanel {
|
|
|
26
26
|
/**
|
|
27
27
|
* Thuộc tính thêm vào khối (kể cả khối lõi), vd { lazy: { default: true } } — cần khai báo để trình soạn lưu được.
|
|
28
28
|
* Bắt buộc có `blocks` khi khai báo thuộc tính. Website đọc được qua filter "post.blocks" hoặc renderer của plugin.
|
|
29
|
+
* Có `type` → ô tự vẽ: number/color/length/enum (sinh CSS), boolean/string/url/textarea/datetime (chỉ ô, editor 1.29).
|
|
30
|
+
* `label` và nhãn `options: [{ value, label }]` nhận "%khoá%" (admin dịch theo slug plugin, CMS ≥ 1.30).
|
|
29
31
|
*/
|
|
30
32
|
attributes?: Record<string, { default?: unknown; label?: string } | (ControlSpec & { label?: string })>;
|
|
31
33
|
/** Giao diện riêng; bỏ trống = trình soạn tự vẽ ô cho các thuộc tính có `type`. */
|
package/src/v2/blocks/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { mediaBlocks } from "./media";
|
|
|
6
6
|
import { textBlocks } from "./text";
|
|
7
7
|
import { themeBlocks } from "./theme";
|
|
8
8
|
import { formBlocks } from "./form";
|
|
9
|
+
import { widgetBlocks } from "./widgets";
|
|
9
10
|
import { blockDescription } from "../ui/block-descriptions";
|
|
10
11
|
|
|
11
12
|
/** Tên khối theo ngôn ngữ giao diện (khối có nhãn trong bộ chữ). */
|
|
@@ -18,7 +19,7 @@ const TITLE_KEYS: Partial<Record<string, keyof V2Labels>> = {
|
|
|
18
19
|
|
|
19
20
|
export function coreBlockTypes(labels: V2Labels): BlockType[] {
|
|
20
21
|
const names = messages("blockTitles", labels.lang);
|
|
21
|
-
return [...textBlocks(), ...layoutBlocks(), ...mediaBlocks(), ...formBlocks(labels.lang), ...themeBlocks()].map((t) => {
|
|
22
|
+
return [...textBlocks(), ...layoutBlocks(), ...mediaBlocks(), ...formBlocks(labels.lang), ...widgetBlocks(labels.lang), ...themeBlocks()].map((t) => {
|
|
22
23
|
const key = TITLE_KEYS[t.name];
|
|
23
24
|
const str = (v: unknown) => (typeof v === "string" ? v : undefined);
|
|
24
25
|
const title = key ? String(labels[key]) : str(names[t.name]) ?? t.title;
|
package/src/v2/blocks/theme.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Star, AlignLeft, ArrowLeftRight, CalendarDays, ChevronsRight, Heading1, Copyright, FileText, Globe2, Image as ImageIcon, LayoutTemplate, ListOrdered, Menu, MessageSquare, PanelTop, Repeat2, Rows3, Search, SquareDashed, Tag, Type, User } from "lucide-react";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useState, type CSSProperties, type ReactNode } from "react";
|
|
3
|
+
import { ICON_PATHS } from "@ecomcx/ecomweb-content";
|
|
3
4
|
import { Block, DocBlocks, InnerBlocks, NestedDoc } from "../canvas/block-list";
|
|
4
5
|
import { DocScopeProvider, LoopPostContext, useDocScope, useDynamicData, useEditor, useEditorState } from "../context";
|
|
5
6
|
import type { DynamicPost, QueryArgs } from "../core/host";
|
|
@@ -153,7 +154,8 @@ function LoginOutEdit({ block, blockProps }: BlockEditProps) {
|
|
|
153
154
|
}
|
|
154
155
|
function IconEdit({ block, blockProps }: BlockEditProps) {
|
|
155
156
|
const size = Math.min(128, Math.max(12, Number(block.attrs.size) || 24));
|
|
156
|
-
|
|
157
|
+
const path = ICON_PATHS[String(block.attrs.name ?? "star")] ?? ICON_PATHS.star;
|
|
158
|
+
return <div {...merge(blockProps, "ecx-icon-block", align(block.attrs))}><svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden><path d={path} /></svg></div>;
|
|
157
159
|
}
|
|
158
160
|
function FootnotesEdit({ block, blockProps }: BlockEditProps) {
|
|
159
161
|
return <aside {...merge(blockProps, "ecx-footnotes")}>{block.attrs.title ? <p className="ecx-footnotes-title">{String(block.attrs.title)}</p> : null}<ol><li>Chú thích 1</li><li>Chú thích 2</li></ol></aside>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CORE_NODES, ICON_NAMES, widgetMarkup, type WidgetEl } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { BarChart3, Hash, Image as ImageIcon, ListChecks, Quote, Star } from "lucide-react";
|
|
3
|
+
import { createElement, type CSSProperties, type ReactNode } from "react";
|
|
4
|
+
import { makeBlock } from "../core/model";
|
|
5
|
+
import type { BlockEditProps, BlockType } from "../core/registry";
|
|
6
|
+
import { useMsgs } from "../i18n";
|
|
7
|
+
import { messages } from "../../i18n";
|
|
8
|
+
import { RichText } from "../text/rich-text";
|
|
9
|
+
import { Field } from "../ui/attr-form";
|
|
10
|
+
import { MediaPick } from "./layout";
|
|
11
|
+
|
|
12
|
+
const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Widget lõi trên khung soạn: cùng cây markup với website (@ecomcx/ecomweb-content widgetMarkup) → vẽ y hệt.
|
|
16
|
+
* Ô chữ (`field`) gõ trực tiếp trên khối, chỗ ảnh trống (`slot`) là ô chọn ảnh; số / thanh tiến độ hiện giá trị cuối (không chạy hiệu ứng).
|
|
17
|
+
*/
|
|
18
|
+
function WidgetEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
19
|
+
const t = useMsgs("blocks") as Record<string, string>;
|
|
20
|
+
const tree = widgetMarkup(block.type, block.attrs, true);
|
|
21
|
+
if (!tree || (block.type === "iconList" && !tree.children?.length)) return <div {...blockProps} className={cx(blockProps.className, "ecx-placeholder-block")}>{t.widgetEmpty}</div>;
|
|
22
|
+
const draw = (el: WidgetEl | string, key: number, root?: boolean): ReactNode => {
|
|
23
|
+
if (typeof el === "string") return el;
|
|
24
|
+
if (el.field) {
|
|
25
|
+
const f = el.field;
|
|
26
|
+
return <RichText key={key} blockId={block.id} field={f} tagName="span" value={String(block.attrs[f] ?? "")} onChange={(v) => setAttrs({ [f]: v })} placeholder={t[`widget_${f}`]} placeholderAlways editable={editable} />;
|
|
27
|
+
}
|
|
28
|
+
const kids = el.slot === "media" ? [<MediaPick key="pick" blockId={block.id} />] : (el.children ?? []).map((c, i) => draw(c, i));
|
|
29
|
+
const props: Record<string, unknown> = { key, ...el.props, className: el.className, style: el.style as CSSProperties };
|
|
30
|
+
if (el.tag === "a") props.onClick = (e: Event) => e.preventDefault();
|
|
31
|
+
if (el.tag === "img") props.draggable = false;
|
|
32
|
+
if (root) Object.assign(props, blockProps, { className: cx(blockProps.className, el.className), style: { ...(blockProps.style ?? {}), ...el.style } });
|
|
33
|
+
return createElement(el.tag, props, ...kids);
|
|
34
|
+
};
|
|
35
|
+
return <>{draw(tree, 0, true)}</>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Danh sách mục của Icon List: mỗi dòng một mục, "chữ | đường dẫn" (đường dẫn tuỳ chọn); dòng trống giữ khi đang gõ, website bỏ qua. Icon riêng từng mục: chỉ qua dữ liệu (AI / mẫu). */
|
|
39
|
+
function IconListInspector({ attrs, setAttrs }: BlockEditProps) {
|
|
40
|
+
const t = useMsgs("blocks") as Record<string, string>;
|
|
41
|
+
const items: Array<{ text: string; href?: string; icon?: string }> = Array.isArray(attrs.items) ? attrs.items : [];
|
|
42
|
+
const value = items.map((it) => (it.href ? `${it.text} | ${it.href}` : it.text)).join("\n");
|
|
43
|
+
const parse = (s: string) => s.split("\n").slice(0, 50).map((line, i) => {
|
|
44
|
+
const [text, href] = line.split("|").map((x) => x.trim());
|
|
45
|
+
return { ...(items[i]?.icon ? { icon: items[i].icon } : {}), text: text ?? "", ...(href ? { href } : {}) };
|
|
46
|
+
});
|
|
47
|
+
return <Field label={t.iconListItems}><textarea className="ecx-input" rows={6} value={value} data-icon-list-items onChange={(e) => setAttrs({ items: parse(e.target.value) })} /></Field>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const spec = (name: string) => CORE_NODES[name]?.attrs;
|
|
51
|
+
const ICON_SELECT = { type: "string" as const, enum: ICON_NAMES };
|
|
52
|
+
|
|
53
|
+
/** Khối widget của lõi; `lang` = ngôn ngữ của trình soạn (chữ mẫu khi chèn). */
|
|
54
|
+
export function widgetBlocks(lang?: string): BlockType[] {
|
|
55
|
+
const m = messages("blocks", lang) as Record<string, string>;
|
|
56
|
+
const base = { kind: "atom" as const, category: "widgets", edit: WidgetEdit, supports: { style: true, anchor: true, className: true } };
|
|
57
|
+
return [
|
|
58
|
+
{ ...base, name: "iconBox", title: "Icon Box", icon: Star, keywords: "icon box hop bieu tuong tinh nang dich vu feature", attributes: { ...spec("iconBox"), icon: { ...ICON_SELECT, default: "star" } }, create: () => makeBlock("iconBox", { icon: "star", title: m.sampleTitle, text: m.sampleText }), summary: (a) => a.title },
|
|
59
|
+
{ ...base, name: "imageBox", title: "Image Box", icon: ImageIcon, keywords: "image box hop anh the card dich vu", attributes: { ...spec("imageBox"), src: { type: "url", control: "media" } }, create: () => makeBlock("imageBox", { title: m.sampleTitle, text: m.sampleText }), summary: (a) => a.title },
|
|
60
|
+
{ ...base, name: "iconList", title: "Icon List", icon: ListChecks, keywords: "icon list danh sach bieu tuong loi ich checklist", inspector: IconListInspector, attributes: { ...spec("iconList"), icon: { ...ICON_SELECT, default: "check" } }, create: () => makeBlock("iconList", { items: [m.sampleItem1, m.sampleItem2, m.sampleItem3].map((text) => ({ text })) }) },
|
|
61
|
+
{ ...base, name: "counter", title: "Counter", icon: Hash, keywords: "counter dem so con so thong ke number", attributes: spec("counter"), create: () => makeBlock("counter", { end: 100, suffix: "+", title: m.sampleCounter, textAlign: "center" }), summary: (a) => a.title },
|
|
62
|
+
{ ...base, name: "testimonial", title: "Testimonial", icon: Quote, keywords: "testimonial loi chung thuc danh gia khach hang review", attributes: { ...spec("testimonial"), src: { type: "url", control: "media" } }, create: () => makeBlock("testimonial", { quote: m.sampleQuote, name: m.sampleName, role: m.sampleRole }), summary: (a) => a.name },
|
|
63
|
+
{ ...base, name: "progressBar", title: "Progress Bar", icon: BarChart3, keywords: "progress bar thanh tien do ky nang phan tram", attributes: spec("progressBar"), create: () => makeBlock("progressBar", { label: m.sampleSkill, value: 80 }), summary: (a) => a.label },
|
|
64
|
+
];
|
|
65
|
+
}
|
package/src/v2/ui/attr-hints.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ICON_NAMES } from "@ecomcx/ecomweb-content";
|
|
1
2
|
import { format, messages } from "../../i18n";
|
|
2
3
|
import type { ChoiceKind } from "../core/host";
|
|
3
4
|
|
|
@@ -118,7 +119,20 @@ export const ATTR_HINTS: Record<string, AttrHint> = {
|
|
|
118
119
|
"loginout.logoutText": { label: true },
|
|
119
120
|
"pageList.parentId": { label: true },
|
|
120
121
|
"archives.showCount": { label: true },
|
|
121
|
-
"icon.name": { control: "select", options: [
|
|
122
|
+
"icon.name": { control: "select", options: [...ICON_NAMES] },
|
|
123
|
+
"iconBox.icon": { control: "select", options: [...ICON_NAMES] },
|
|
124
|
+
"iconBox.position": { control: "segmented", label: true, options: ["top", "left"] },
|
|
125
|
+
"iconBox.level": { control: "select", options: levels(2, 6) },
|
|
126
|
+
"imageBox.level": { control: "select", options: levels(2, 6) },
|
|
127
|
+
"imageBox.src": { label: true },
|
|
128
|
+
"iconList.icon": { control: "select", options: [...ICON_NAMES] },
|
|
129
|
+
"iconList.layout": { control: "segmented", options: ["list", "inline"] },
|
|
130
|
+
"counter.start": { label: true },
|
|
131
|
+
"counter.prefix": { label: true },
|
|
132
|
+
"counter.separator": { control: "select", label: true, options: ["none", ",", ".", "space"] },
|
|
133
|
+
"counter.duration": { help: true },
|
|
134
|
+
"testimonial.src": { label: true },
|
|
135
|
+
"progressBar.value": { control: "range", label: true, min: 0, max: 100, step: 1, unit: "%" },
|
|
122
136
|
"languageSwitcher.display": { control: "segmented", options: ["inline", "dropdown"] },
|
|
123
137
|
"postTerms.taxonomy": { control: "choice", choice: { kind: "taxonomy" } },
|
|
124
138
|
"query.postType": { control: "choice", choice: { kind: "postType" }, when: notInherit },
|
|
@@ -131,6 +145,7 @@ export const ATTR_HINTS: Record<string, AttrHint> = {
|
|
|
131
145
|
"query.exclude": { label: true, when: notInherit },
|
|
132
146
|
"query.sticky": { control: "select", options: ["any", "only", "exclude"], when: notInherit },
|
|
133
147
|
"image.href": { label: true },
|
|
148
|
+
"image.lightbox": { label: true },
|
|
134
149
|
"image.linkTarget": { control: "segmented", label: true, options: ["_self", "_blank"] },
|
|
135
150
|
"orderedList.reversed": { label: true },
|
|
136
151
|
"blockquote.citation": { label: true },
|
|
@@ -15,6 +15,10 @@ const POSITIONS = ["0% 0%", "50% 0%", "100% 0%", "0% 50%", "50% 50%", "100% 50%"
|
|
|
15
15
|
export function BackgroundPanel({ style: raw, onChange, device }: { style: unknown; onChange(style: BlockStyle | null): void; device: Device }) {
|
|
16
16
|
const { host } = useEditor();
|
|
17
17
|
const t = useMsgs("background");
|
|
18
|
+
// Ả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/…"
|
|
19
|
+
const sameOriginPath = (v: string) => {
|
|
20
|
+
try { const u = new URL(v, location.href); return u.origin === location.origin ? u.pathname + u.search : v; } catch { return v; }
|
|
21
|
+
};
|
|
18
22
|
const style: BlockStyle = normalizeStyle(raw) ?? {};
|
|
19
23
|
const bg: BlockBackground = style.background ?? {};
|
|
20
24
|
const [url, setUrl] = useState("");
|
|
@@ -24,6 +28,7 @@ export function BackgroundPanel({ style: raw, onChange, device }: { style: unkno
|
|
|
24
28
|
/** Giá trị theo khổ đang chọn (ảnh, cách phủ, điểm lấy nét). */
|
|
25
29
|
const setAt = (k: "image" | "size" | "position", v: string | undefined) => {
|
|
26
30
|
const r: Record<string, string | undefined> = { ...(bg[k] ?? {}) };
|
|
31
|
+
if (v && k === "image") v = sameOriginPath(v);
|
|
27
32
|
if (v) r[device] = v; else delete r[device];
|
|
28
33
|
set({ [k]: Object.keys(r).length ? r : undefined });
|
|
29
34
|
};
|
package/src/v2/ui/inspector.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Device } from "@ecomcx/ecomweb-content";
|
|
2
|
-
import { CORE_BLOCK_STYLES } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { CORE_BLOCK_STYLES, controlValue, optionValue } from "@ecomcx/ecomweb-content";
|
|
3
3
|
import { Blocks } from "lucide-react";
|
|
4
4
|
import { useState, useSyncExternalStore } from "react";
|
|
5
5
|
import { blockPanelsFor, onBlockPanelsChange, type BlockPanel } from "../../shared/panel-store";
|
|
@@ -34,7 +34,7 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
|
|
|
34
34
|
const setAttrs = (a: Record<string, unknown>) => store.setAttrs(ids, a);
|
|
35
35
|
const Custom = same && nodes.length === 1 ? type?.inspector : undefined;
|
|
36
36
|
const bindable = type?.bindable ?? CORE_BINDABLE[first.type];
|
|
37
|
-
const variants = [...(CORE_BLOCK_STYLES[first.type] ?? []).map((name) => ({ name, label: name })), ...(blockStyles?.[first.type] ?? [])];
|
|
37
|
+
const variants = [...(CORE_BLOCK_STYLES[first.type] ?? []).map((name) => ({ name, label: (t.blockStyle as Record<string, string>)[name] ?? name })), ...(blockStyles?.[first.type] ?? [])];
|
|
38
38
|
return (
|
|
39
39
|
<div className="ecx-inspector">
|
|
40
40
|
<div className="ecx-block-card">
|
|
@@ -92,6 +92,12 @@ function PluginPanels({ type, attrs, setAttrs, tab = "block" }: { type: string;
|
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
/** Giá trị ISO → ô datetime-local (giờ của máy người soạn); lưu lại bằng toISOString (UTC). */
|
|
96
|
+
const toLocal = (iso: unknown) => {
|
|
97
|
+
const d = typeof iso === "string" ? new Date(iso) : null;
|
|
98
|
+
return !d || Number.isNaN(d.getTime()) ? "" : new Date(d.getTime() - d.getTimezoneOffset() * 60_000).toISOString().slice(0, 16);
|
|
99
|
+
};
|
|
100
|
+
|
|
95
101
|
/** Ô tự vẽ cho thuộc tính khai `type` của panel không có component riêng. */
|
|
96
102
|
function ControlFields({ panel, attrs, setAttrs }: { panel: BlockPanel; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void }) {
|
|
97
103
|
const { host } = useEditor();
|
|
@@ -109,10 +115,24 @@ function ControlFields({ panel, attrs, setAttrs }: { panel: BlockPanel; attrs: R
|
|
|
109
115
|
<Field key={name} label={label}>
|
|
110
116
|
<select className="ecx-input" value={v ?? ""} onChange={(e) => set(e.target.value)}>
|
|
111
117
|
<option value="">—</option>
|
|
112
|
-
{spec.options?.map((o) => <option key={
|
|
118
|
+
{spec.options?.map((o) => { const val = optionValue(o); return <option key={val} value={val}>{(typeof o === "object" && tr(o.label)) || val}</option>; })}
|
|
113
119
|
</select>
|
|
114
120
|
</Field>
|
|
115
121
|
);
|
|
122
|
+
// Kiểu chỉ có ô (content 1.23): giá trị không hợp lệ (controlValue) được báo, vẫn giữ để người soạn sửa
|
|
123
|
+
const invalid = v !== undefined && v !== "" && controlValue(spec, v) === undefined;
|
|
124
|
+
if (spec.type === "boolean") return (
|
|
125
|
+
<label key={name} className="ecx-check"><input type="checkbox" checked={v === true} onChange={(e) => set(e.target.checked || undefined)} /> {label}</label>
|
|
126
|
+
);
|
|
127
|
+
if (spec.type === "string" || spec.type === "url" || spec.type === "textarea" || spec.type === "datetime") return (
|
|
128
|
+
<Field key={name} label={label}>
|
|
129
|
+
{spec.type === "textarea"
|
|
130
|
+
? <textarea className="ecx-input" rows={4} maxLength={spec.maxLength ?? 5000} value={typeof v === "string" ? v : ""} aria-invalid={invalid || undefined} onChange={(e) => set(e.target.value)} />
|
|
131
|
+
: spec.type === "datetime"
|
|
132
|
+
? <input className="ecx-input" type="datetime-local" value={toLocal(v)} aria-invalid={invalid || undefined} onChange={(e) => set(e.target.value ? new Date(e.target.value).toISOString() : undefined)} />
|
|
133
|
+
: <input className="ecx-input" type={spec.type === "url" ? "url" : "text"} maxLength={spec.type === "string" ? spec.maxLength ?? 200 : 2048} value={typeof v === "string" ? v : ""} aria-invalid={invalid || undefined} onChange={(e) => set(e.target.value)} />}
|
|
134
|
+
</Field>
|
|
135
|
+
);
|
|
116
136
|
return (
|
|
117
137
|
<Field key={name} label={label}>
|
|
118
138
|
<input className="ecx-input" type="number" min={spec.min} max={spec.max} value={v ?? ""} onChange={(e) => set(e.target.value === "" ? undefined : Number(e.target.value))} />
|
|
@@ -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) => {
|
|
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>
|