@ecomcx/ecomweb-editor 1.30.0 → 1.31.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 +3 -3
- package/src/locales/en/index.ts +2 -1
- package/src/locales/en/placeholders.ts +96 -0
- package/src/locales/vi/index.ts +2 -1
- package/src/locales/vi/placeholders.ts +95 -0
- package/src/v2/blocks/compat.tsx +91 -5
- package/src/v2/blocks/form.tsx +3 -0
- package/src/v2/blocks/layout.tsx +143 -52
- package/src/v2/blocks/media.tsx +72 -71
- package/src/v2/blocks/text.tsx +48 -17
- package/src/v2/blocks/theme.tsx +73 -12
- package/src/v2/blocks/widgets.tsx +48 -11
- package/src/v2/canvas/block-list.tsx +4 -4
- package/src/v2/canvas/canvas-css.ts +88 -6
- package/src/v2/canvas/server-block.tsx +7 -4
- package/src/v2/core/host.ts +9 -0
- package/src/v2/core/registry.ts +3 -1
- package/src/v2/core/structure.ts +2 -1
- package/src/v2/editor.css +6 -2
- package/src/v2/index.ts +3 -0
- package/src/v2/ui/ai.tsx +9 -5
- package/src/v2/ui/attr-form.tsx +2 -2
- package/src/v2/{blocks → ui}/media-actions.tsx +4 -3
- package/src/v2/ui/placeholders.tsx +205 -0
- package/src/v2/ui/toolbar.tsx +7 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecomcx/ecomweb-editor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.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.
|
|
32
|
+
"@ecomcx/ecomweb-content": "^1.25.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.
|
|
48
|
+
"@ecomcx/ecomweb-content": "^1.25.0",
|
|
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/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { blockStyle } from "./block-style";
|
|
|
17
17
|
import { patternLib } from "./pattern-lib";
|
|
18
18
|
import { patterns } from "./patterns";
|
|
19
19
|
import { shortcuts } from "./shortcuts";
|
|
20
|
+
import { placeholders } from "./placeholders";
|
|
20
21
|
|
|
21
22
|
/** 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. */
|
|
22
|
-
export const en: typeof vi = { v2, legacy, attrs, background, bindings, blockStyle, blockDesc, blockTitles, blocks, controls, hints, layout, legacyBasic, legacyDynamic, motion, patternLib, patterns, shortcuts };
|
|
23
|
+
export const en: typeof vi = { v2, legacy, attrs, background, bindings, blockStyle, blockDesc, blockTitles, blocks, controls, hints, layout, legacyBasic, legacyDynamic, motion, patternLib, patterns, placeholders, shortcuts };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { placeholders as vi } from "../vi/placeholders";
|
|
2
|
+
|
|
3
|
+
export const placeholders: typeof vi = {
|
|
4
|
+
drop: { image: "Drop an image here", gallery: "Drop several images at once", video: "Drop a video here", audio: "Drop an audio file here", file: "Drop a file here" },
|
|
5
|
+
dropSub: "or choose one of the options below",
|
|
6
|
+
dropCover: "Drop a background image here",
|
|
7
|
+
dropNow: "Drop to upload",
|
|
8
|
+
addBlock: "Add block",
|
|
9
|
+
link: "URL",
|
|
10
|
+
linkInvalid: "Invalid URL",
|
|
11
|
+
embedUnsupported: "This site can't be embedded yet — use YouTube, Vimeo, Google Maps, TikTok, Spotify…",
|
|
12
|
+
embedHint: "YouTube, Vimeo, Google Maps, TikTok, Spotify…",
|
|
13
|
+
pasteToEmbed: "Paste a link to embed",
|
|
14
|
+
embed: "Embed",
|
|
15
|
+
choose: "Choose…",
|
|
16
|
+
missing: "Missing: {fields}",
|
|
17
|
+
paragraph: "Write something, or type / to choose a block",
|
|
18
|
+
listItem: "List item…",
|
|
19
|
+
taskItem: "To-do…",
|
|
20
|
+
heading: "Heading…",
|
|
21
|
+
quote: "Add a quote…",
|
|
22
|
+
citation: "Add a source…",
|
|
23
|
+
speaker: "Add the speaker's name…",
|
|
24
|
+
caption: "Add a caption…",
|
|
25
|
+
detailsSummary: "Title when collapsed…",
|
|
26
|
+
calloutTitle: "Title (optional)…",
|
|
27
|
+
code: "// Paste or type code…",
|
|
28
|
+
preformatted: "Text that keeps its spacing…",
|
|
29
|
+
buttonText: "Add button text…",
|
|
30
|
+
tabTitle: "Tab name…",
|
|
31
|
+
addTab: "Add tab",
|
|
32
|
+
addItem: "Add item",
|
|
33
|
+
addSlide: "Add slide",
|
|
34
|
+
addImage: "Add image",
|
|
35
|
+
addRow: "Add row",
|
|
36
|
+
addField: "Add field",
|
|
37
|
+
language: "Language",
|
|
38
|
+
languageAuto: "Auto-detect",
|
|
39
|
+
startAt: "Start at",
|
|
40
|
+
chooseLayout: "Choose a layout",
|
|
41
|
+
layoutStack: "Stack",
|
|
42
|
+
layoutRow: "Row",
|
|
43
|
+
layoutGrid: "Grid",
|
|
44
|
+
createTable: "Create table",
|
|
45
|
+
columns: "Columns",
|
|
46
|
+
rows: "Rows",
|
|
47
|
+
create: "Create",
|
|
48
|
+
queryChoose: "Choose a display",
|
|
49
|
+
queryList: "List",
|
|
50
|
+
queryGrid: "3-column grid",
|
|
51
|
+
queryCards: "Cards with image",
|
|
52
|
+
shortcodeName: "Shortcode name",
|
|
53
|
+
htmlCode: "Code",
|
|
54
|
+
htmlPreview: "Preview",
|
|
55
|
+
htmlPlaceholder: "<!-- Paste HTML… -->",
|
|
56
|
+
countdownTarget: "Count down to",
|
|
57
|
+
counterHint: "Use real numbers only.",
|
|
58
|
+
counterEnd: "Number",
|
|
59
|
+
rateHint: "Click a star to rate",
|
|
60
|
+
rateStar: "{n} stars",
|
|
61
|
+
tocHint: "Lists the H2–H{n} headings of the post. No headings → the table of contents is empty on the website.",
|
|
62
|
+
socialAdd: "Add Facebook, Zalo, YouTube…",
|
|
63
|
+
socialNetwork: "Network",
|
|
64
|
+
spacer: "Spacer {size} · drag the bottom edge to resize",
|
|
65
|
+
separator: "Separator",
|
|
66
|
+
galleryAdd: "Add images to the gallery",
|
|
67
|
+
boxMedia: "Drop an image or choose an icon",
|
|
68
|
+
boxImage: "Image",
|
|
69
|
+
boxIcon: "Icon",
|
|
70
|
+
boxTitle: "Title…",
|
|
71
|
+
boxText: "Short description…",
|
|
72
|
+
testimonialQuote: "What did the customer say…",
|
|
73
|
+
testimonialName: "Customer name…",
|
|
74
|
+
testimonialRole: "Job title…",
|
|
75
|
+
skill: "Skill name…",
|
|
76
|
+
counterTitle: "Describe the number…",
|
|
77
|
+
iconListItem: "First benefit…",
|
|
78
|
+
realData: "Live data",
|
|
79
|
+
sampleData: "Sample data",
|
|
80
|
+
noData: "No data yet",
|
|
81
|
+
noLogo: "No logo yet",
|
|
82
|
+
dropLogo: "Drop your logo here",
|
|
83
|
+
logoAll: "The logo changes for the whole website.",
|
|
84
|
+
menuEmpty: "No menu in the “{location}” location",
|
|
85
|
+
createMenu: "Create menu",
|
|
86
|
+
pickMenu: "Choose an existing menu",
|
|
87
|
+
noFeatured: "The preview post has no image",
|
|
88
|
+
noFeaturedHint: "The website hides this block for posts without an image.",
|
|
89
|
+
postContentHint: "Each post's content appears here",
|
|
90
|
+
noPosts: "No matching posts",
|
|
91
|
+
noPostsHint: "Visitors will see “No posts yet” (edit it in the “No results” block).",
|
|
92
|
+
writeFirst: "Write the first post",
|
|
93
|
+
serverEmpty: "The website draws nothing for this block on the sample page",
|
|
94
|
+
otherSettings: "Display style and other options: sidebar › Block.",
|
|
95
|
+
openSettings: "Open settings",
|
|
96
|
+
};
|
package/src/locales/vi/index.ts
CHANGED
|
@@ -22,5 +22,6 @@ import { blockStyle } from "./block-style";
|
|
|
22
22
|
import { patternLib } from "./pattern-lib";
|
|
23
23
|
import { patterns } from "./patterns";
|
|
24
24
|
import { shortcuts } from "./shortcuts";
|
|
25
|
+
import { placeholders } from "./placeholders";
|
|
25
26
|
|
|
26
|
-
export const vi = { v2, legacy, attrs, background, bindings, blockStyle, blockDesc, blockTitles, blocks, controls, hints, layout, legacyBasic, legacyDynamic, motion, patternLib, patterns, shortcuts };
|
|
27
|
+
export const vi = { v2, legacy, attrs, background, bindings, blockStyle, blockDesc, blockTitles, blocks, controls, hints, layout, legacyBasic, legacyDynamic, motion, patternLib, patterns, placeholders, shortcuts };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/** Ô giữ chỗ trong khối (chỉ có trong trình soạn — website không vẽ gì khi ô trống). */
|
|
2
|
+
export const placeholders = {
|
|
3
|
+
drop: { image: "Kéo thả ảnh vào đây", gallery: "Kéo thả nhiều ảnh cùng lúc", video: "Kéo thả video vào đây", audio: "Kéo thả tệp âm thanh vào đây", file: "Kéo thả tệp vào đây" } as Record<string, string>,
|
|
4
|
+
dropSub: "hoặc chọn một cách bên dưới",
|
|
5
|
+
dropCover: "Kéo thả ảnh nền vào đây",
|
|
6
|
+
dropNow: "Thả để tải lên",
|
|
7
|
+
addBlock: "Thêm khối",
|
|
8
|
+
link: "Đường dẫn",
|
|
9
|
+
linkInvalid: "Đường dẫn không hợp lệ",
|
|
10
|
+
embedUnsupported: "Chưa hỗ trợ nhúng trang này — dùng YouTube, Vimeo, Google Maps, TikTok, Spotify…",
|
|
11
|
+
embedHint: "YouTube, Vimeo, Google Maps, TikTok, Spotify…",
|
|
12
|
+
pasteToEmbed: "Dán đường dẫn để nhúng",
|
|
13
|
+
embed: "Nhúng",
|
|
14
|
+
choose: "Chọn…",
|
|
15
|
+
missing: "Còn thiếu: {fields}",
|
|
16
|
+
paragraph: "Viết nội dung, hoặc gõ / để chọn khối",
|
|
17
|
+
listItem: "Mục danh sách…",
|
|
18
|
+
taskItem: "Việc cần làm…",
|
|
19
|
+
heading: "Tiêu đề…",
|
|
20
|
+
quote: "Nhập câu trích dẫn…",
|
|
21
|
+
citation: "Thêm nguồn…",
|
|
22
|
+
speaker: "Thêm tên người nói…",
|
|
23
|
+
caption: "Thêm chú thích…",
|
|
24
|
+
detailsSummary: "Tiêu đề khi thu gọn…",
|
|
25
|
+
calloutTitle: "Tiêu đề (không bắt buộc)…",
|
|
26
|
+
code: "// Dán hoặc gõ mã…",
|
|
27
|
+
preformatted: "Văn bản giữ nguyên khoảng trắng…",
|
|
28
|
+
buttonText: "Nhập chữ trên nút…",
|
|
29
|
+
tabTitle: "Tên tab…",
|
|
30
|
+
addTab: "Thêm tab",
|
|
31
|
+
addItem: "Thêm mục",
|
|
32
|
+
addSlide: "Thêm slide",
|
|
33
|
+
addImage: "Thêm ảnh",
|
|
34
|
+
addRow: "Thêm dòng",
|
|
35
|
+
addField: "Thêm ô",
|
|
36
|
+
language: "Ngôn ngữ",
|
|
37
|
+
languageAuto: "Tự nhận",
|
|
38
|
+
startAt: "Bắt đầu từ",
|
|
39
|
+
chooseLayout: "Chọn kiểu bố cục",
|
|
40
|
+
layoutStack: "Xếp dọc",
|
|
41
|
+
layoutRow: "Hàng ngang",
|
|
42
|
+
layoutGrid: "Lưới",
|
|
43
|
+
createTable: "Tạo bảng",
|
|
44
|
+
columns: "Số cột",
|
|
45
|
+
rows: "Số hàng",
|
|
46
|
+
create: "Tạo",
|
|
47
|
+
queryChoose: "Chọn kiểu hiển thị",
|
|
48
|
+
queryList: "Danh sách",
|
|
49
|
+
queryGrid: "Lưới 3 cột",
|
|
50
|
+
queryCards: "Thẻ có ảnh",
|
|
51
|
+
shortcodeName: "Tên shortcode",
|
|
52
|
+
htmlCode: "Mã",
|
|
53
|
+
htmlPreview: "Xem trước",
|
|
54
|
+
htmlPlaceholder: "<!-- Dán mã HTML… -->",
|
|
55
|
+
countdownTarget: "Đếm tới",
|
|
56
|
+
counterHint: "Chỉ dùng số thật.",
|
|
57
|
+
counterEnd: "Số",
|
|
58
|
+
rateHint: "Bấm vào sao để chấm",
|
|
59
|
+
rateStar: "{n} sao",
|
|
60
|
+
tocHint: "Tự lấy các tiêu đề H2–H{n} trong bài. Bài chưa có tiêu đề → mục lục trống trên website.",
|
|
61
|
+
socialAdd: "Thêm Facebook, Zalo, YouTube…",
|
|
62
|
+
socialNetwork: "Mạng",
|
|
63
|
+
spacer: "Khoảng trống {size} · kéo cạnh dưới để đổi",
|
|
64
|
+
separator: "Đường kẻ",
|
|
65
|
+
galleryAdd: "Thêm ảnh vào gallery",
|
|
66
|
+
boxMedia: "Thả ảnh hoặc chọn icon",
|
|
67
|
+
boxImage: "Ảnh",
|
|
68
|
+
boxIcon: "Icon",
|
|
69
|
+
boxTitle: "Tiêu đề…",
|
|
70
|
+
boxText: "Mô tả ngắn…",
|
|
71
|
+
testimonialQuote: "Nhập lời khách hàng nói…",
|
|
72
|
+
testimonialName: "Tên khách…",
|
|
73
|
+
testimonialRole: "Chức danh…",
|
|
74
|
+
skill: "Tên kỹ năng…",
|
|
75
|
+
counterTitle: "Mô tả con số…",
|
|
76
|
+
iconListItem: "Lợi ích thứ nhất…",
|
|
77
|
+
realData: "Dữ liệu thật",
|
|
78
|
+
sampleData: "Dữ liệu mẫu",
|
|
79
|
+
noData: "Chưa có dữ liệu",
|
|
80
|
+
noLogo: "Chưa có logo",
|
|
81
|
+
dropLogo: "Thả logo vào đây",
|
|
82
|
+
logoAll: "Chọn xong là đổi logo cho cả website.",
|
|
83
|
+
menuEmpty: "Vị trí “{location}” chưa có menu",
|
|
84
|
+
createMenu: "Tạo menu",
|
|
85
|
+
pickMenu: "Chọn menu có sẵn",
|
|
86
|
+
noFeatured: "Bài xem thử chưa có ảnh",
|
|
87
|
+
noFeaturedHint: "Website sẽ ẩn khối này với bài không có ảnh.",
|
|
88
|
+
postContentHint: "Nội dung của từng bài hiện ở đây",
|
|
89
|
+
noPosts: "Chưa có bài phù hợp",
|
|
90
|
+
noPostsHint: "Khách sẽ thấy: “Chưa có bài viết” (sửa chữ ở khối “Khi không có bài”).",
|
|
91
|
+
writeFirst: "Viết bài đầu tiên",
|
|
92
|
+
serverEmpty: "Website chưa vẽ gì cho khối này ở trang mẫu",
|
|
93
|
+
otherSettings: "Kiểu hiển thị và thuộc tính khác: thanh bên › Khối.",
|
|
94
|
+
openSettings: "Mở cài đặt",
|
|
95
|
+
};
|
package/src/v2/blocks/compat.tsx
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { blockDefaults } from "@ecomcx/ecomweb-content";
|
|
2
|
-
import { Blocks } from "lucide-react";
|
|
3
|
-
import type
|
|
1
|
+
import { blockDefaults, isSafeUrl, type BlockAttrSpec, type BlockDefinition } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { Blocks, X } from "lucide-react";
|
|
3
|
+
import { useId, type ComponentType, type ReactNode } from "react";
|
|
4
|
+
import { useEditor } from "../context";
|
|
5
|
+
import { useMsgs } from "../i18n";
|
|
6
|
+
import { attrLabel, controlOf } from "../ui/attr-form";
|
|
7
|
+
import { MediaPlaceholder, MissingNote, TextPlaceholder } from "../ui/placeholders";
|
|
4
8
|
import { blockOptions, onBlockDefinitionsChange, registeredBlocks, type BlockEditProps as V1EditProps } from "../../shared/block-defs";
|
|
5
9
|
import { InnerBlocks } from "../canvas/block-list";
|
|
6
10
|
import { fromRich, makeBlock } from "../core/model";
|
|
@@ -19,6 +23,85 @@ function wrapV1Edit(Edit: ComponentType<V1EditProps>): ComponentType<BlockEditPr
|
|
|
19
23
|
};
|
|
20
24
|
}
|
|
21
25
|
|
|
26
|
+
/** Loại ô core tự vẽ trong khối plugin; select / checkbox / color là tuỳ chọn → ở thanh bên. */
|
|
27
|
+
const INLINE_CONTROLS = new Set(["media", "text", "textarea", "url", "number"]);
|
|
28
|
+
const TECH_ATTRS = new Set(["_v", "style", "className", "anchor", "blockStyle", "mediaId", "id", "lock", "templateLock", "bindings", "metadata"]);
|
|
29
|
+
const empty = (v: unknown) => v == null || v === "" || (Array.isArray(v) && !v.length);
|
|
30
|
+
|
|
31
|
+
/** Ô của khối plugin theo `placeholder.fields` (mặc định: mọi thuộc tính media / text / textarea / url / number). */
|
|
32
|
+
export function placeholderFields(def: Pick<BlockDefinition, "attributes"> & { placeholder?: { fields?: string[]; required?: string[] } }): { fields: string[]; required: string[] } {
|
|
33
|
+
const attrs = def.attributes ?? {};
|
|
34
|
+
const auto = Object.keys(attrs).filter((k) => !TECH_ATTRS.has(k) && INLINE_CONTROLS.has(controlOf(attrs[k])));
|
|
35
|
+
const fields = (def.placeholder?.fields ?? auto).filter((k) => attrs[k]);
|
|
36
|
+
return { fields, required: (def.placeholder?.required ?? []).filter((k) => attrs[k]) };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Một ô giữ chỗ tự sinh (có <label> cho trình đọc màn hình). */
|
|
40
|
+
function AutoField({ name, spec, label, value, required, set }: { name: string; spec: BlockAttrSpec; label: string; value: unknown; required: boolean; set(v: unknown): void }) {
|
|
41
|
+
const id = useId();
|
|
42
|
+
const tp = useMsgs("placeholders");
|
|
43
|
+
const control = controlOf(spec);
|
|
44
|
+
const head = <span className="ecx-ph-label">{label}{required && <span className="ecx-ph-req" aria-hidden> *</span>}</span>;
|
|
45
|
+
if (control === "media") {
|
|
46
|
+
const url = typeof value === "string" && isSafeUrl(value) ? value : "";
|
|
47
|
+
return (
|
|
48
|
+
<div className="ecx-ph-field is-media" role="group" aria-label={label} data-field={name}>
|
|
49
|
+
{head}
|
|
50
|
+
{url ? (
|
|
51
|
+
<span className="ecx-ph-thumb" contentEditable={false}>
|
|
52
|
+
<img src={url} alt="" draggable={false} />
|
|
53
|
+
<button type="button" className="ecx-tool" aria-label={`${label}: ×`} onMouseDown={(e) => e.stopPropagation()} onClick={() => set(undefined)}><X className="ecx-icon ecx-icon-sm" /></button>
|
|
54
|
+
</span>
|
|
55
|
+
) : <MediaPlaceholder kind="image" compact title={tp.drop.image} onSelect={(items) => set(items[0].url)} onUrl={(u) => set(u)} />}
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
const num = control === "number";
|
|
60
|
+
const bad = control === "url" && typeof value === "string" && value !== "" && !isSafeUrl(value);
|
|
61
|
+
return (
|
|
62
|
+
<label className="ecx-ph-field" htmlFor={id} data-field={name} contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
|
|
63
|
+
{head}
|
|
64
|
+
{control === "text" || control === "textarea"
|
|
65
|
+
? <TextPlaceholder id={id} value={String(value ?? "")} onChange={(v) => set(v)} placeholder={`${label}…`} multiline={control === "textarea"} required={required} label={label} className="ecx-input" />
|
|
66
|
+
: <input id={id} className="ecx-input" type={num ? "number" : "url"} inputMode={num ? "decimal" : "url"} min={spec.min} max={spec.max} placeholder={num ? "0" : "https://…"} required={required}
|
|
67
|
+
value={value == null ? "" : String(value)} aria-invalid={bad || undefined} onChange={(e) => set(e.target.value === "" ? undefined : num ? Number(e.target.value) : e.target.value.trim())} />}
|
|
68
|
+
{bad && <span className="ecx-media-error" role="alert">{tp.linkInvalid}</span>}
|
|
69
|
+
</label>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Khối plugin không có giao diện riêng: core tự vẽ ô giữ chỗ từ `attributes` (ô thả media, ô gõ, ô link, ô số; khối chứa → "+ Thêm khối").
|
|
75
|
+
* Đang chọn / website chưa vẽ được → các ô này; bấm ra ngoài và website vẽ được → bản website vẽ (ServerBlock).
|
|
76
|
+
*/
|
|
77
|
+
function autoEdit(def: BlockDefinition, translate: (s: string) => string, Icon: ComponentType<{ className?: string }>): ComponentType<BlockEditProps> {
|
|
78
|
+
const { fields, required } = placeholderFields(def as never);
|
|
79
|
+
return function AutoPlaceholderEdit({ block, blockProps, setAttrs, editable, labels }: BlockEditProps) {
|
|
80
|
+
const { store } = useEditor();
|
|
81
|
+
const tp = useMsgs("placeholders");
|
|
82
|
+
const label = (k: string) => attrLabel(k, def.attributes[k], labels.lang, translate);
|
|
83
|
+
const missing = required.filter((k) => empty(block.attrs[k]));
|
|
84
|
+
const others = Object.keys(def.attributes).some((k) => !TECH_ATTRS.has(k) && !fields.includes(k) && controlOf(def.attributes[k]) !== "hidden");
|
|
85
|
+
let body: ReactNode = null;
|
|
86
|
+
if (editable && fields.length) body = (
|
|
87
|
+
// Gõ vào ô của khối → chọn khối (thanh công cụ + bảng cài đặt đúng khối)
|
|
88
|
+
<div className="ecx-ph-fields" onFocusCapture={() => { if (!store.getState().selection.ids.includes(block.id)) store.select([block.id], { editing: null }); }}>
|
|
89
|
+
{fields.map((k) => <AutoField key={k} name={k} spec={def.attributes[k]} label={label(k)} value={block.attrs[k]} required={required.includes(k)} set={(v) => setAttrs({ [k]: v })} />)}
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
return (
|
|
93
|
+
<div {...blockProps} className={cx(blockProps.className, "ecx-placeholder-block ecx-ph-auto", missing.length && "is-missing")} data-ecx-placeholder="auto">
|
|
94
|
+
<span className="ecx-placeholder-title"><Icon className="ecx-icon" />{translate(def.title)}</span>
|
|
95
|
+
{body}
|
|
96
|
+
{block.inline && <RichText blockId={block.id} value={block.inline} tagName="div" placeholder={`${translate(def.title)}…`} placeholderAlways editable={editable} />}
|
|
97
|
+
{editable && <MissingNote fields={missing.map(label)} />}
|
|
98
|
+
{editable && others && <span className="ecx-placeholder-summary">{tp.otherSettings}</span>}
|
|
99
|
+
{block.content && <InnerBlocks parent={block} />}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
22
105
|
/**
|
|
23
106
|
* Khối plugin đăng ký bằng registerBlock(defineBlock(...)) → khối v2 (form cài đặt tự sinh, xem trước của plugin nếu có).
|
|
24
107
|
* Plugin cài sau khi mở trình soạn vẫn hiện (theo dõi thay đổi). Trả về hàm huỷ theo dõi.
|
|
@@ -38,9 +121,12 @@ export function syncPluginBlocks(registry: BlockTypeRegistry): () => void {
|
|
|
38
121
|
icon: o.icon ?? Blocks,
|
|
39
122
|
templateOnly: o.templateOnly,
|
|
40
123
|
...(o.styleGroups ? { supports: { style: o.styleGroups.length ? o.styleGroups : false } } : {}),
|
|
41
|
-
|
|
42
|
-
|
|
124
|
+
// Không có xem trước riêng: core tự sinh ô giữ chỗ từ thuộc tính (plugin cũ không sửa gì vẫn có)
|
|
125
|
+
edit: o.edit ? wrapV1Edit(o.edit) : autoEdit(def, t, o.icon ?? Blocks),
|
|
126
|
+
// Không có xem trước riêng và không chứa khối con → website vẽ bằng renderer của theme/plugin (viết khối một lần);
|
|
127
|
+
// đang chọn khối → ô giữ chỗ để nhập ngay trên khối
|
|
43
128
|
serverRender: !o.edit && def.content !== "blocks",
|
|
129
|
+
editWhenSelected: !o.edit,
|
|
44
130
|
create: (attrs) => {
|
|
45
131
|
// blockDefaults kèm "_v" = phiên bản khối: thiếu nó website coi dữ liệu mới là bản 1 rồi chạy migrate lên dữ liệu đã ở bản mới
|
|
46
132
|
const defaults = blockDefaults(def);
|
package/src/v2/blocks/form.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import { messages } from "../../i18n";
|
|
|
9
9
|
import { RichText } from "../text/rich-text";
|
|
10
10
|
import { Field } from "../ui/attr-form";
|
|
11
11
|
import { useEditor } from "../context";
|
|
12
|
+
import { AddBlockButton } from "../ui/placeholders";
|
|
12
13
|
|
|
13
14
|
const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
|
|
14
15
|
const merge = (bp: BlockEditProps["blockProps"], className: string, style?: CSSProperties) => ({ ...bp, className: cx(bp.className, className), style: { ...(bp.style ?? {}), ...style } });
|
|
@@ -26,12 +27,14 @@ export function fieldNameFrom(label: string, taken: string[] = []): string {
|
|
|
26
27
|
|
|
27
28
|
function FormEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
28
29
|
const t = useMsgs("blocks");
|
|
30
|
+
const tp = useMsgs("placeholders");
|
|
29
31
|
const a = block.attrs;
|
|
30
32
|
// Mẫu (pattern) chèn vào chưa có mã: tạo một lần để máy chủ nhận ra form này
|
|
31
33
|
useEffect(() => { if (editable && !a.formId) setAttrs({ formId: newFormId() }); }, [editable, a.formId, setAttrs]);
|
|
32
34
|
return (
|
|
33
35
|
<div {...merge(blockProps, "ecx-form-blocks")} data-form-id={String(a.formId ?? "")}>
|
|
34
36
|
<InnerBlocks parent={block} />
|
|
37
|
+
{editable && <AddBlockButton parentId={block.id} label={tp.addField} className="is-inline" />}
|
|
35
38
|
<div className="ecx-form-actions">
|
|
36
39
|
<span className={blockShell("button", { variant: "primary" })?.className} style={blockShell("button", { variant: "primary" })?.style as CSSProperties} role="presentation">
|
|
37
40
|
<RichText blockId={block.id} field="submitText" tagName="span" value={String(a.submitText ?? "")} onChange={(v) => setAttrs({ submitText: v })} placeholder={t.formSubmit} placeholderAlways editable={editable} />
|