@ecomcx/ecomweb-editor 1.32.0 → 1.34.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/attrs.ts +2 -1
- package/src/locales/en/background.ts +5 -0
- package/src/locales/en/bindings.ts +5 -1
- package/src/locales/en/block-desc.ts +5 -11
- package/src/locales/en/block-style.ts +17 -6
- package/src/locales/en/block-titles.ts +38 -15
- package/src/locales/en/blocks.ts +37 -6
- package/src/locales/en/columns.ts +1 -0
- package/src/locales/en/controls.ts +1 -1
- package/src/locales/en/hints.ts +315 -12
- package/src/locales/en/index.ts +3 -1
- package/src/locales/en/layout.ts +13 -0
- package/src/locales/en/motion.ts +16 -0
- package/src/locales/en/palette.ts +8 -0
- package/src/locales/en/parts.ts +2 -1
- package/src/locales/en/pattern-overrides.ts +14 -0
- package/src/locales/en/placeholders.ts +9 -3
- package/src/locales/en/v2.ts +2 -0
- package/src/locales/vi/attrs.ts +3 -2
- package/src/locales/vi/background.ts +5 -0
- package/src/locales/vi/bindings.ts +5 -1
- package/src/locales/vi/block-desc.ts +8 -14
- package/src/locales/vi/block-style.ts +18 -7
- package/src/locales/vi/block-titles.ts +48 -25
- package/src/locales/vi/blocks.ts +37 -6
- package/src/locales/vi/columns.ts +1 -0
- package/src/locales/vi/controls.ts +1 -1
- package/src/locales/vi/hints.ts +315 -12
- package/src/locales/vi/index.ts +3 -1
- package/src/locales/vi/layout.ts +13 -0
- package/src/locales/vi/motion.ts +16 -0
- package/src/locales/vi/palette.ts +8 -0
- package/src/locales/vi/parts.ts +2 -1
- package/src/locales/vi/pattern-overrides.ts +14 -0
- package/src/locales/vi/placeholders.ts +10 -4
- package/src/locales/vi/v2.ts +2 -0
- package/src/v2/blocks/columns-inspector.tsx +11 -2
- package/src/v2/blocks/index.ts +9 -6
- package/src/v2/blocks/layout-options.tsx +80 -0
- package/src/v2/blocks/layout.tsx +349 -106
- package/src/v2/blocks/media.tsx +51 -21
- package/src/v2/blocks/resize.tsx +50 -19
- package/src/v2/blocks/social-icons.ts +22 -0
- package/src/v2/blocks/text.tsx +12 -50
- package/src/v2/blocks/theme.tsx +62 -29
- package/src/v2/blocks/tools.tsx +24 -2
- package/src/v2/blocks/widgets.tsx +84 -28
- package/src/v2/canvas/block-list.tsx +36 -5
- package/src/v2/canvas/canvas-css.ts +95 -7
- package/src/v2/canvas/canvas.tsx +65 -9
- package/src/v2/canvas/dnd.ts +7 -0
- package/src/v2/canvas/variation-picker.tsx +63 -0
- package/src/v2/context.tsx +48 -0
- package/src/v2/core/bindings.ts +6 -1
- package/src/v2/core/block-presets.ts +10 -0
- package/src/v2/core/clipboard.ts +5 -5
- package/src/v2/core/host.ts +3 -1
- package/src/v2/core/model.ts +6 -6
- package/src/v2/core/registry.ts +15 -0
- package/src/v2/core/store.ts +9 -9
- package/src/v2/core/structure.ts +1 -3
- package/src/v2/editor.css +74 -0
- package/src/v2/editor.tsx +22 -7
- package/src/v2/text/rich-text.tsx +20 -5
- package/src/v2/ui/ai-markdown.ts +52 -0
- package/src/v2/ui/ai.tsx +81 -14
- package/src/v2/ui/attr-form.tsx +45 -7
- package/src/v2/ui/attr-hints.ts +151 -19
- package/src/v2/ui/background-panel.tsx +22 -0
- package/src/v2/ui/bg-video-preview.tsx +7 -0
- package/src/v2/ui/bindings.tsx +9 -1
- package/src/v2/ui/block-icons.tsx +3 -10
- package/src/v2/ui/block-live-preview.tsx +21 -0
- package/src/v2/ui/block-style-panel.tsx +3 -1
- package/src/v2/ui/command-palette.tsx +125 -0
- package/src/v2/ui/icon-picker.tsx +88 -21
- package/src/v2/ui/icon-svg.tsx +21 -0
- package/src/v2/ui/inserter.tsx +72 -17
- package/src/v2/ui/inspector.tsx +12 -6
- package/src/v2/ui/layout-panel.tsx +1 -1
- package/src/v2/ui/motion-panel.tsx +22 -13
- package/src/v2/ui/option-thumbs.tsx +81 -0
- package/src/v2/ui/pattern-library.tsx +2 -1
- package/src/v2/ui/pattern-overrides.tsx +67 -0
- package/src/v2/ui/placeholders.tsx +21 -2
- package/src/v2/ui/preset-bar.tsx +5 -5
- package/src/v2/ui/style-supports.ts +2 -3
- package/src/v2/ui/style-tab.tsx +83 -20
- package/src/v2/ui/toolbar.tsx +40 -6
- package/src/v2/ui/transform-panel.tsx +77 -0
package/src/v2/blocks/theme.tsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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";
|
|
1
|
+
import { ListFilter, 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 {
|
|
3
|
+
import { SEARCH_ICON_PATH, resolveIcon, spacingValue } from "@ecomcx/ecomweb-content";
|
|
4
|
+
import { IconSvg } from "../ui/icon-svg";
|
|
5
|
+
import { useChoices } from "../ui/attr-form";
|
|
4
6
|
import { Block, DocBlocks, InnerBlocks, NestedDoc } from "../canvas/block-list";
|
|
5
7
|
import { DocScopeProvider, LoopPostContext, useDocScope, useDynamicData, useEditor, useEditorState } from "../context";
|
|
6
8
|
import type { DynamicPost, QueryArgs } from "../core/host";
|
|
@@ -73,7 +75,8 @@ function NavigationEdit({ block, blockProps, selected }: BlockEditProps) {
|
|
|
73
75
|
const { labels } = useEditor();
|
|
74
76
|
const location = String(block.attrs.location ?? "primary");
|
|
75
77
|
const items = d.menus?.[location];
|
|
76
|
-
const
|
|
78
|
+
const overlay = ["never", "mobile", "tablet", "always"].includes(String(block.attrs.overlayMenu)) ? String(block.attrs.overlayMenu) : block.attrs.mobile === false ? "never" : "mobile";
|
|
79
|
+
const mobile = overlay !== "never";
|
|
77
80
|
const t = useMsgs("blocks");
|
|
78
81
|
const tp = useMsgs("placeholders");
|
|
79
82
|
const { host } = useEditor();
|
|
@@ -94,9 +97,9 @@ function NavigationEdit({ block, blockProps, selected }: BlockEditProps) {
|
|
|
94
97
|
}
|
|
95
98
|
const menu = <nav className="ecx-navigation-menu" aria-label={location}><ul>{items.map((it, i) => <li key={i}><a href={it.url} onClick={(e) => e.preventDefault()}>{it.title}</a></li>)}</ul></nav>;
|
|
96
99
|
return (
|
|
97
|
-
<div {...merge(blockProps, cx("ecx-navigation", `ecx-navigation-${block.attrs.orientation ?? "horizontal"}`, mobile && "has-mobile"))}>
|
|
98
|
-
<div className="ecx-navigation-items">{menu}</div>
|
|
99
|
-
{mobile && <
|
|
100
|
+
<div {...merge(blockProps, cx("ecx-navigation", `ecx-navigation-${block.attrs.orientation ?? "horizontal"}`, mobile && "has-mobile", overlay === "tablet" && "bp-tablet", overlay === "always" && "overlay-always"))}>
|
|
101
|
+
{overlay !== "always" && <div className="ecx-navigation-items">{menu}</div>}
|
|
102
|
+
{mobile && <div className="ecx-nav-drawer"><button type="button" className="ecx-nav-burger" tabIndex={-1} aria-label={t.menu}><svg viewBox="0 0 24 24" width={24} height={24} fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" aria-hidden="true" focusable="false"><path d="M4 7h16M4 12h16M4 17h16" /></svg></button></div>}
|
|
100
103
|
<EditMenuButton location={location} selected={selected} />
|
|
101
104
|
</div>
|
|
102
105
|
);
|
|
@@ -109,15 +112,30 @@ function SearchEdit({ block, blockProps }: BlockEditProps) {
|
|
|
109
112
|
const button = block.attrs.buttonStyle === "icon"
|
|
110
113
|
? <button type="button" tabIndex={-1} aria-label={label} title={label}><svg viewBox="0 0 24 24" width={18} height={18} fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" focusable="false"><path d={SEARCH_ICON_PATH} /></svg></button>
|
|
111
114
|
: <button type="button" tabIndex={-1}>{label}</button>;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
<form role="search" onSubmit={(e) => e.preventDefault()} style={pos === "below" ? { display: "flex", flexDirection: "column", gap: 8 } : undefined}
|
|
115
|
+
const collapse = block.attrs.collapse === "tablet" || block.attrs.collapse === "mobile" ? String(block.attrs.collapse) : undefined;
|
|
116
|
+
const form = (
|
|
117
|
+
<form role="search" data-ecx-inert="" onSubmit={(e) => e.preventDefault()} style={pos === "below" ? { display: "flex", flexDirection: "column", gap: 8 } : undefined}
|
|
115
118
|
className={`search-form${pos !== "right" ? ` search-button-${pos}` : ""}`}>
|
|
116
119
|
{block.attrs.showLabel === true && <label className="search-label">{t.searchLabel}</label>}
|
|
117
120
|
{pos === "left" && button}
|
|
118
121
|
<input type="search" placeholder={String(block.attrs.placeholder || t.searchPlaceholder)} aria-label={t.searchLabel} readOnly tabIndex={-1} />
|
|
122
|
+
{block.attrs.scopeSelect === true && (
|
|
123
|
+
<select className="search-scope" aria-label={t.searchScope} tabIndex={-1} onMouseDown={(e) => e.preventDefault()}>
|
|
124
|
+
<option>{t.searchAll}</option>
|
|
125
|
+
{String(block.attrs.scopes ?? "").split(",").map((x) => x.trim()).filter(Boolean).map((x) => { const [v, ...r] = x.split(":"); return <option key={x}>{r.join(":").trim() || v}</option>; })}
|
|
126
|
+
</select>
|
|
127
|
+
)}
|
|
119
128
|
{pos !== "left" && button}
|
|
120
129
|
</form>
|
|
130
|
+
);
|
|
131
|
+
return (
|
|
132
|
+
<div {...merge(blockProps, "ecx-search")}>
|
|
133
|
+
{collapse ? (
|
|
134
|
+
<div className={`ecx-search-collapse collapse-${collapse}`}>
|
|
135
|
+
<button type="button" className="ecx-search-toggle" tabIndex={-1} aria-label={label}><svg viewBox="0 0 24 24" width={20} height={20} fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" focusable="false"><path d={SEARCH_ICON_PATH} /></svg></button>
|
|
136
|
+
<div className="ecx-search-panel">{form}</div>
|
|
137
|
+
</div>
|
|
138
|
+
) : form}
|
|
121
139
|
</div>
|
|
122
140
|
);
|
|
123
141
|
}
|
|
@@ -195,18 +213,10 @@ function LoginOutEdit({ block, blockProps }: BlockEditProps) {
|
|
|
195
213
|
}
|
|
196
214
|
function IconEdit({ block, blockProps }: BlockEditProps) {
|
|
197
215
|
const size = Math.min(128, Math.max(12, Number(block.attrs.size) || 24));
|
|
198
|
-
const path = ICON_PATHS[String(block.attrs.name ?? "star")] ?? ICON_PATHS.star;
|
|
199
216
|
const stroke = Math.min(4, Math.max(0.5, Number(block.attrs.stroke) || 2));
|
|
200
217
|
const shape = block.attrs.iconStyle === "circle" || block.attrs.iconStyle === "square" ? block.attrs.iconStyle : undefined;
|
|
201
|
-
return <div {...merge(blockProps, "ecx-icon-block", align(block.attrs))}><span className={`ecx-icon-shape${shape ? ` is-${shape}` : ""}`} style={shape ? {
|
|
202
|
-
}
|
|
203
|
-
function FootnotesEdit({ block, blockProps }: BlockEditProps) {
|
|
204
|
-
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>;
|
|
205
|
-
}
|
|
206
|
-
function PageBreakEdit({ blockProps }: BlockEditProps) {
|
|
207
|
-
return <div {...merge(blockProps, "ecx-page-break")} style={{ ...(blockProps.style ?? {}), borderTop: "2px dashed currentColor", opacity: 0.5, textAlign: "center", fontSize: 12 }}>Ngắt trang</div>;
|
|
208
|
-
}
|
|
209
|
-
function PageListEdit({ blockProps }: BlockEditProps) {
|
|
218
|
+
return <div {...merge(blockProps, "ecx-icon-block", align(block.attrs))}><span className={`ecx-icon-shape${shape ? ` is-${shape}` : ""}`} data-ecx-tip={typeof block.attrs.tooltip === "string" && block.attrs.tooltip.trim() ? block.attrs.tooltip.trim().slice(0, 120) : undefined} style={shape ? ({ "--ecx-icon-pad-auto": `${Math.round(size * 0.4)}px` } as CSSProperties) : undefined}><IconSvg name={resolveIcon(block.attrs.name) ? block.attrs.name : "star"} size={size} stroke={stroke} /></span></div>;
|
|
219
|
+
}function PageListEdit({ blockProps }: BlockEditProps) {
|
|
210
220
|
return <nav {...merge(blockProps, "ecx-page-list")}><ul><li>Trang A<ul><li>Trang con</li></ul></li><li>Trang B</li></ul></nav>;
|
|
211
221
|
}
|
|
212
222
|
function ArchivesEdit({ block, blockProps }: BlockEditProps) {
|
|
@@ -338,6 +348,7 @@ export function queryArgs(a: Record<string, unknown>): QueryArgs {
|
|
|
338
348
|
inherit: a.inherit !== false, postType: typeof a.postType === "string" && a.postType ? a.postType : "post",
|
|
339
349
|
perPage: Math.min(100, Math.max(1, Number(a.perPage) || 10)),
|
|
340
350
|
category: typeof a.category === "string" && a.category ? a.category : undefined, tag: typeof a.tag === "string" && a.tag ? a.tag : undefined,
|
|
351
|
+
taxonomy: typeof a.taxonomy === "string" && a.taxonomy && (a.term || a.terms) ? a.taxonomy : undefined, term: typeof a.term === "string" && a.term ? a.term : typeof a.terms === "string" && a.terms ? a.terms.split(",")[0].trim() : undefined,
|
|
341
352
|
orderBy: typeof a.orderBy === "string" ? a.orderBy : "date", order: a.order === "asc" ? "asc" : "desc",
|
|
342
353
|
};
|
|
343
354
|
}
|
|
@@ -374,14 +385,17 @@ function PostTemplateEdit({ block, blockProps, editable, labels }: BlockEditProp
|
|
|
374
385
|
const q = queryArgs(queryAttrs);
|
|
375
386
|
const posts = useQueryPosts(q);
|
|
376
387
|
const [active, setActive] = useState(0);
|
|
377
|
-
const grid = block.attrs.layout === "grid";
|
|
388
|
+
const grid = block.attrs.layout === "grid" || block.attrs.layout === "carousel";
|
|
389
|
+
const carousel = block.attrs.layout === "carousel";
|
|
390
|
+
const responsive = block.attrs.layout === "grid" && (Number(block.attrs.columnsTablet) > 0 || Number(block.attrs.columnsMobile) > 0);
|
|
378
391
|
const cols = Math.min(6, Math.max(1, Number(block.attrs.columns) || 3));
|
|
379
|
-
const
|
|
392
|
+
const gap = spacingValue(block.attrs.gap) ?? "1.5rem";
|
|
393
|
+
const count = posts ? Math.max(1, Math.min(posts.length, q.perPage, carousel ? cols : 6)) : 3;
|
|
380
394
|
const current = Math.min(active, count - 1);
|
|
381
395
|
const t = useMsgs("blocks");
|
|
382
396
|
const tp = useMsgs("placeholders");
|
|
383
397
|
return (
|
|
384
|
-
<ul {...(merge(blockProps, cx("ecx-post-template", grid && "is-grid"), grid ? { display: "grid", gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))`, gap
|
|
398
|
+
<ul {...(merge(blockProps, cx("ecx-post-template", grid && "is-grid", responsive && "is-responsive"), responsive ? { "--per": cols, "--per-tablet": Number(block.attrs.columnsTablet) || Math.min(cols, 3), "--per-mobile": Number(block.attrs.columnsMobile) || Math.min(cols, 2), "--gap": gap } as CSSProperties : grid ? { display: "grid", gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))`, gap } : undefined) as object)} data-ecx-posts={posts ? posts.length : ""}>
|
|
385
399
|
{posts && !posts.length && <li className="ecx-post ecx-post-none ecx-ph-theme is-missing" data-ecx-placeholder="no-posts"><Missing>{tp.noPosts}</Missing> <span className="ecx-placeholder-hint">{tp.noPostsHint}</span> <AdminButton target="newPost" args={{ postType: q.postType }}>+ {tp.writeFirst}</AdminButton></li>}
|
|
386
400
|
{Array.from({ length: count }, (_, i) => {
|
|
387
401
|
const post = posts?.[i] ?? null;
|
|
@@ -409,6 +423,26 @@ function PaginationEdit({ block, blockProps }: BlockEditProps) {
|
|
|
409
423
|
const single = posts !== undefined && posts.length < perPage;
|
|
410
424
|
return <nav {...(merge(blockProps, cx("ecx-pagination", single && "is-single")) as object)} style={single ? { opacity: 0.45 } : undefined}>{single ? "‹ 1 ›" : "‹ 1 2 3 ›"}</nav>;
|
|
411
425
|
}
|
|
426
|
+
/** Thanh lọc: cùng markup với website (QueryFilterBar) — mục phân loại thật lấy từ ứng dụng, không có thì mục mẫu. */
|
|
427
|
+
function QueryFilterEdit({ block, blockProps }: BlockEditProps) {
|
|
428
|
+
const t = useMsgs("blocks");
|
|
429
|
+
const a = block.attrs;
|
|
430
|
+
const style = ["none", "links", "chips", "select", "checks"].includes(String(a.termStyle)) ? String(a.termStyle) : "links";
|
|
431
|
+
const choices = useChoices("term", { taxonomy: String(a.taxonomy ?? "") });
|
|
432
|
+
const names = (a.taxonomy ? choices : null)?.map((c) => c.label).slice(0, 8) ?? ["Danh mục 1", "Danh mục 2", "Danh mục 3"];
|
|
433
|
+
return (
|
|
434
|
+
<div {...merge(blockProps, "ecx-query-filter")}>
|
|
435
|
+
{style === "select" && <select tabIndex={-1} aria-label={String(a.taxonomy ?? "")}><option>{String(a.allLabel || t.filterAll)}</option></select>}
|
|
436
|
+
{(style === "links" || style === "chips" || style === "checks") && <nav className="ecx-filter-terms"><a className="is-active">{String(a.allLabel || t.filterAll)}</a>{names.map((n) => <a key={n}>{n}</a>)}</nav>}
|
|
437
|
+
{a.showSearch === true && <input type="search" readOnly tabIndex={-1} placeholder={String(a.placeholder || t.filterSearch)} />}
|
|
438
|
+
{a.showSort === true && <select tabIndex={-1} aria-label={t.filterSort}><option>{t.filterNewest}</option></select>}
|
|
439
|
+
{a.showRange === true && <span className="ecx-filter-range"><input type="number" readOnly tabIndex={-1} placeholder="Từ" /> – <input type="number" readOnly tabIndex={-1} placeholder="Đến" /></span>}
|
|
440
|
+
{a.showYear === true && <select tabIndex={-1} aria-label={t.filterYear}><option>{t.filterYear}</option></select>}
|
|
441
|
+
{a.showReset === true && <a className="ecx-filter-reset">{t.filterReset}</a>}
|
|
442
|
+
{style === "none" && !a.showSearch && !a.showSort && !a.showYear && !a.showReset && <span className="ecx-muted">{t.filterEmpty}</span>}
|
|
443
|
+
</div>
|
|
444
|
+
);
|
|
445
|
+
}
|
|
412
446
|
function QueryEmptyEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
413
447
|
const { posts } = useParentQueryPosts(block);
|
|
414
448
|
// Danh sách đang có bài → khối "không có bài" không hiện trên website: thu gọn thành nhãn mờ (vẫn chọn / sửa được khi bấm vào)
|
|
@@ -458,8 +492,8 @@ export function themeBlocks(): BlockType[] {
|
|
|
458
492
|
{ name: "siteTitle", title: "Tên website", icon: Type, category: theme, keywords: "ten website site title", kind: "atom", edit: SiteTitleEdit, attributes: { level: { type: "integer", default: 0, min: 0, max: 6 }, link: { type: "boolean", default: true }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
459
493
|
{ name: "siteLogo", title: "Logo", icon: ImageIcon, category: theme, keywords: "logo", kind: "atom", edit: SiteLogoEdit, attributes: { width: { type: "number", default: 120 }, link: { type: "boolean", default: true } }, supports: { style: true, className: true } },
|
|
460
494
|
{ name: "siteTagline", title: "Khẩu hiệu", icon: Type, category: theme, keywords: "khau hieu tagline mo ta", kind: "atom", edit: SiteTaglineEdit, attributes: { textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
461
|
-
{ name: "navigation", title: "Menu", icon: Menu, category: theme, keywords: "menu dieu huong navigation", kind: "atom", edit: NavigationEdit, attributes: { location: { type: "string", default: "primary" }, orientation: { type: "string", enum: ["horizontal", "vertical"], default: "horizontal" }, mobile: { type: "boolean", default: true }, overlayMenu: { type: "string", enum: ["never", "mobile", "always"], default: "mobile" } }, supports: { style: true, className: true }, summary: (a) => a.location },
|
|
462
|
-
{ name: "search", title: "Tìm kiếm", icon: Search, category: theme, keywords: "tim kiem search", kind: "atom", edit: SearchEdit, attributes: { placeholder: { type: "string" }, buttonText: { type: "string" }, postType: { type: "string" }, showLabel: { type: "boolean", default: false }, buttonPosition: { type: "string", enum: ["right", "left", "below"], default: "right" }, buttonStyle: { type: "string", enum: ["text", "icon"], default: "text" } }, supports: { style: true, className: true } },
|
|
495
|
+
{ name: "navigation", title: "Menu", icon: Menu, category: theme, keywords: "menu dieu huong navigation", kind: "atom", edit: NavigationEdit, attributes: { location: { type: "string", default: "primary" }, orientation: { type: "string", enum: ["horizontal", "vertical"], default: "horizontal" }, mobile: { type: "boolean", default: true }, overlayMenu: { type: "string", enum: ["never", "mobile", "tablet", "always"], default: "mobile" } }, supports: { style: true, className: true }, summary: (a) => a.location },
|
|
496
|
+
{ name: "search", title: "Tìm kiếm", icon: Search, category: theme, keywords: "tim kiem search", kind: "atom", edit: SearchEdit, attributes: { placeholder: { type: "string" }, buttonText: { type: "string" }, postType: { type: "string" }, showLabel: { type: "boolean", default: false }, buttonPosition: { type: "string", enum: ["right", "left", "below"], default: "right" }, buttonStyle: { type: "string", enum: ["text", "icon"], default: "text" }, scopeSelect: { type: "boolean", default: false }, scopes: { type: "string" }, collapse: { type: "string", enum: ["never", "tablet", "mobile"], default: "never" } }, supports: { style: true, className: true } },
|
|
463
497
|
{ name: "languageSwitcher", title: "Chọn ngôn ngữ", icon: Globe2, category: theme, keywords: "ngon ngu language", kind: "atom", edit: LanguageEdit, attributes: { display: { type: "string", enum: ["inline", "dropdown"], default: "inline" } }, supports: { style: true, className: true } },
|
|
464
498
|
{ name: "copyright", title: "Bản quyền", icon: Copyright, category: theme, keywords: "ban quyen copyright", kind: "atom", edit: CopyrightEdit, attributes: { text: { type: "string" }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
465
499
|
{ name: "postTitle", title: "Tiêu đề bài", icon: Type, category: theme, keywords: "tieu de bai post title", kind: "atom", edit: PostTitleEdit, attributes: { level: { type: "integer", default: 1, min: 1, max: 6 }, link: { type: "boolean", default: false }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
@@ -476,9 +510,7 @@ export function themeBlocks(): BlockType[] {
|
|
|
476
510
|
{ name: "queryTotal", title: "Tổng số bài", icon: ListOrdered, category: theme, keywords: "tong so bai total", kind: "atom", edit: QueryTotalEdit, attributes: { textAlign: TEXT_ALIGN }, supports: { style: true, className: true }, structure: { parents: ["query"] } },
|
|
477
511
|
{ name: "termList", title: "Danh sách chuyên mục / thẻ", icon: Tag, category: theme, keywords: "danh sach chuyen muc the category tag cloud term list", kind: "atom", edit: TermListEdit, attributes: { taxonomy: { type: "string", default: "category" }, display: { type: "string", enum: ["list", "cloud"], default: "list" }, showCount: { type: "boolean", default: false }, hierarchical: { type: "boolean", default: false }, hideEmpty: { type: "boolean", default: true } }, supports: { style: true, className: true }, summary: (a) => a.taxonomy },
|
|
478
512
|
{ name: "loginout", title: "Đăng nhập / Đăng xuất", icon: User, category: theme, keywords: "dang nhap dang xuat login logout", kind: "atom", edit: LoginOutEdit, attributes: { loginText: { type: "string" }, logoutText: { type: "string" }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
479
|
-
{ name: "icon", title: "Icon", icon: Star, category: theme, keywords: "icon bieu tuong", kind: "atom", edit: IconEdit, attributes: {
|
|
480
|
-
{ name: "footnotes", title: "Chú thích cuối bài", icon: ListOrdered, category: theme, keywords: "chu thich cuoi bai footnotes", kind: "atom", edit: FootnotesEdit, attributes: { title: { type: "string" } }, supports: { style: true, className: true } },
|
|
481
|
-
{ name: "pageBreak", title: "Ngắt trang", icon: PanelTop, category: theme, keywords: "ngat trang page break nextpage", kind: "atom", edit: PageBreakEdit, supports: { className: true } },
|
|
513
|
+
{ name: "icon", title: "Icon", icon: Star, category: theme, keywords: "icon bieu tuong", kind: "atom", edit: IconEdit, attributes: { tooltip: { type: "string" }, name: { type: "string", default: "star" }, size: { type: "integer", default: 24, min: 12, max: 128 }, label: { type: "string" }, textAlign: TEXT_ALIGN, stroke: { type: "number", default: 2, min: 0.5, max: 4 }, iconStyle: { type: "string", enum: ["plain", "circle", "square"], default: "plain" }, href: { type: "url" }, linkTarget: { type: "string", enum: ["_self", "_blank"] } }, supports: { style: true, className: true }, summary: (a) => a.name },
|
|
482
514
|
{ name: "pageList", title: "Danh sách trang", icon: ListOrdered, category: theme, keywords: "danh sach trang page list sitemap", kind: "atom", edit: PageListEdit, attributes: { parentId: { type: "integer", min: 1 }, depth: { type: "integer", default: 2, min: 1, max: 3 } }, supports: { style: true, className: true } },
|
|
483
515
|
{ name: "archives", title: "Lưu trữ theo tháng", icon: CalendarDays, category: theme, keywords: "luu tru thang archives", kind: "atom", edit: ArchivesEdit, attributes: { showCount: { type: "boolean", default: true }, limit: { type: "integer", default: 12, min: 1, max: 60 } }, supports: { style: true, className: true } },
|
|
484
516
|
{ name: "queryTitle", title: "Tiêu đề trang lưu trữ", icon: Heading1, category: theme, keywords: "tieu de luu tru chuyen muc archive query title h1", kind: "atom", edit: QueryTitleEdit, attributes: { level: { type: "integer", default: 1, min: 1, max: 6 }, prefix: { type: "boolean", default: false }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
@@ -487,13 +519,14 @@ export function themeBlocks(): BlockType[] {
|
|
|
487
519
|
{ name: "postNavigation", title: "Bài trước / bài sau", icon: ArrowLeftRight, category: theme, keywords: "bai truoc bai sau dieu huong post navigation", kind: "atom", edit: PostNavigationEdit, attributes: { showTitle: { type: "boolean", default: true } }, supports: { style: true, className: true } },
|
|
488
520
|
{
|
|
489
521
|
name: "query", title: "Danh sách bài", icon: Rows3, category: theme, keywords: "danh sach bai query loop tin tuc", kind: "container", edit: QueryEdit,
|
|
490
|
-
attributes: { inherit: { type: "boolean", default: true }, postType: { type: "string", default: "post" }, perPage: { type: "integer", default: 10, min: 1, max: 100 }, category: { type: "string" }, tag: { type: "string" }, orderBy: { type: "string", enum: ["date", "title", "modified", "menu_order", "comment_count", "rand"], default: "date" }, order: { type: "string", enum: ["desc", "asc"], default: "desc" }, authorId: { type: "integer", min: 1 }, search: { type: "string" }, exclude: { type: "string" }, sticky: { type: "string", enum: ["any", "only", "exclude"], default: "any" }, orderByMeta: { type: "string" }, paginate: { type: "boolean", default: false } },
|
|
522
|
+
attributes: { inherit: { type: "boolean", default: true }, postType: { type: "string", default: "post" }, perPage: { type: "integer", default: 10, min: 1, max: 100 }, category: { type: "string" }, tag: { type: "string" }, taxonomy: { type: "string" }, term: { type: "string" }, terms: { type: "string" }, termMode: { type: "string", enum: ["any", "all", "none"], default: "any" }, source: { type: "string", enum: ["latest", "manual", "related"], default: "latest" }, include: { type: "string" }, metaKey: { type: "string" }, metaCompare: { type: "string", enum: ["=", "!=", ">", ">=", "<", "<=", "LIKE", "EXISTS", "NOT EXISTS"], default: "=" }, metaValue: { type: "string" }, dateRange: { type: "string", enum: ["any", "7", "30", "90", "365"], default: "any" }, after: { type: "string" }, before: { type: "string" }, parent: { type: "integer", min: 1 }, offset: { type: "integer", min: 0, max: 1000 }, excludeCurrent: { type: "boolean", default: true }, authorCurrent: { type: "boolean", default: false }, urlFilters: { type: "boolean", default: false }, orderBy: { type: "string", enum: ["date", "title", "modified", "menu_order", "comment_count", "rand"], default: "date" }, order: { type: "string", enum: ["desc", "asc"], default: "desc" }, authorId: { type: "integer", min: 1 }, search: { type: "string" }, exclude: { type: "string" }, sticky: { type: "string", enum: ["any", "only", "exclude"], default: "any" }, orderByMeta: { type: "string" }, paginate: { type: "boolean", default: false } },
|
|
491
523
|
// Mới chèn: chưa có khuôn → hỏi kiểu hiển thị trước (Danh sách / Lưới / Thẻ có ảnh)
|
|
492
524
|
create: () => makeBlock("query", { inherit: true }, []),
|
|
493
525
|
supports: { style: true, className: true },
|
|
494
526
|
},
|
|
495
|
-
{ name: "postTemplate", title: "Khuôn mỗi bài", icon: LayoutTemplate, kind: "container", edit: PostTemplateEdit, hidden: true, attributes: { layout: { type: "string", enum: ["list", "grid"], default: "list" }, columns: { type: "integer", default: 3, min: 1, max: 6 } }, structure: { parents: ["query"] } },
|
|
527
|
+
{ name: "postTemplate", title: "Khuôn mỗi bài", icon: LayoutTemplate, kind: "container", edit: PostTemplateEdit, hidden: true, attributes: { layout: { type: "string", enum: ["list", "grid", "carousel"], default: "list" }, columns: { type: "integer", default: 3, min: 1, max: 6 }, columnsTablet: { type: "integer", min: 1, max: 6 }, columnsMobile: { type: "integer", min: 1, max: 4 }, gap: { type: "string" }, arrows: { type: "boolean", default: true } }, structure: { parents: ["query"] } },
|
|
496
528
|
{ name: "pagination", title: "Phân trang", icon: ListOrdered, kind: "atom", edit: PaginationEdit, attributes: { type: { type: "string", enum: ["numbers", "prevNext", "both"], default: "both" }, midSize: { type: "integer", default: 2, min: 0, max: 5 } }, hidden: true, structure: { parents: ["query"] } },
|
|
529
|
+
{ name: "queryFilter", title: "Thanh lọc", icon: ListFilter, category: theme, keywords: "loc bo loc thanh loc filter danh muc sap xep tim", kind: "atom", edit: QueryFilterEdit, attributes: { taxonomy: { type: "string" }, termStyle: { type: "string", enum: ["none", "links", "chips", "select", "checks"], default: "links" }, showRange: { type: "boolean", default: false }, rangeParam: { type: "string" }, rangeLabel: { type: "string" }, rangeMax: { type: "number" }, allLabel: { type: "string" }, showSearch: { type: "boolean", default: false }, showSort: { type: "boolean", default: false }, showYear: { type: "boolean", default: false }, showReset: { type: "boolean", default: false }, sortOptions: { type: "string" }, placeholder: { type: "string" }, submitText: { type: "string" }, action: { type: "string" } }, supports: { style: true, className: true, align: true } },
|
|
497
530
|
{ name: "queryEmpty", title: "Khi không có bài", icon: SquareDashed, kind: "container", edit: QueryEmptyEdit, hidden: true, structure: { parents: ["query"] } },
|
|
498
531
|
{ name: "templatePart", title: "Phần dùng chung", icon: PanelTop, category: theme, keywords: "phan dung chung template part header footer", kind: "atom", edit: TemplatePartEdit, attributes: { slug: { type: "string" }, tagName: { type: "string", enum: ["div", "header", "footer", "aside", "section"], default: "div" } }, summary: (a) => a.slug },
|
|
499
532
|
{ name: "syncedPattern", title: "Mẫu đồng bộ", icon: Repeat2, category: "widgets", keywords: "mau dong bo synced pattern reusable", kind: "atom", edit: SyncedPatternEdit, attributes: { ref: { type: "integer" } }, hidden: true },
|
package/src/v2/blocks/tools.tsx
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { AlignCenter, AlignCenterHorizontal, AlignEndHorizontal, AlignHorizontalSpaceBetween, AlignLeft, AlignRight, AlignStartHorizontal, Link2, StretchHorizontal, Columns2, Minus, Plus, Table2, ArrowUpToLine, ArrowDownToLine, ArrowLeftToLine, ArrowRightToLine, Trash2, Heading, TableCellsMerge, TableCellsSplit } from "lucide-react";
|
|
1
|
+
import { Star, AlignCenter, AlignCenterHorizontal, AlignEndHorizontal, AlignHorizontalSpaceBetween, AlignLeft, AlignRight, AlignStartHorizontal, Link2, StretchHorizontal, Columns2, Minus, Plus, Table2, ArrowUpToLine, ArrowDownToLine, ArrowLeftToLine, ArrowRightToLine, Trash2, Heading, TableCellsMerge, TableCellsSplit } from "lucide-react";
|
|
2
2
|
import { useEditor } from "../context";
|
|
3
3
|
import { makeBlock, type BNode } from "../core/model";
|
|
4
4
|
import { addColumn, addRow, canMerge, canSplit, deleteColumn, deleteRow, hasHeaderRow, mergeCells, splitCell, tableContext, toggleHeaderRow } from "../core/tables";
|
|
5
5
|
import { Dropdown, MenuItem, ToolButton } from "../ui/toolbar";
|
|
6
6
|
import { useState } from "react";
|
|
7
7
|
import { useMsgs } from "../i18n";
|
|
8
|
-
import { isSafeUrl } from "@ecomcx/ecomweb-content";
|
|
8
|
+
import { isSafeUrl, resolveIcon } from "@ecomcx/ecomweb-content";
|
|
9
|
+
import { IconSvg } from "../ui/icon-svg";
|
|
9
10
|
import type { BlockEditProps } from "../core/registry";
|
|
11
|
+
import { IconGrid } from "../ui/icon-picker";
|
|
10
12
|
|
|
11
13
|
/** Công cụ bảng khi đang gõ trong ô (hoặc chọn cả bảng). */
|
|
12
14
|
export function TableTools({ ancestor, currentId }: { ancestor: BNode; currentId: string }) {
|
|
@@ -98,6 +100,26 @@ export function ButtonsTools({ ancestor }: { ancestor: BNode; currentId: string
|
|
|
98
100
|
);
|
|
99
101
|
}
|
|
100
102
|
|
|
103
|
+
/** Chọn icon ngay trên thanh công cụ (icon là thuộc tính chính của Icon Box / Icon List / Nút): bấm nút mở lưới icon có ô tìm. */
|
|
104
|
+
export function IconTool({ value, onChange, allowNone }: { value?: string; onChange(v: string | undefined): void; allowNone?: boolean }) {
|
|
105
|
+
const t = useMsgs("controls");
|
|
106
|
+
const has = !!value && !!resolveIcon(value);
|
|
107
|
+
return (
|
|
108
|
+
<Dropdown label={t.chooseIcon} trigger={has ? <IconSvg className="ecx-icon" name={value} size={20} /> : <Star className="ecx-icon" />}>
|
|
109
|
+
{(close) => <IconGrid className="ecx-tool-icon-pop" value={value} label={t.chooseIcon} allowNone={allowNone} onPick={(v) => { onChange(v); close(); }} />}
|
|
110
|
+
</Dropdown>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function ButtonIconTool({ block, setAttrs }: BlockEditProps) {
|
|
115
|
+
return <IconTool value={block.attrs.icon as string | undefined} onChange={(v) => setAttrs({ icon: v })} allowNone />;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Thanh của nút: icon + liên kết. */
|
|
119
|
+
export function ButtonTools(p: BlockEditProps) {
|
|
120
|
+
return <><ButtonIconTool {...p} /><ButtonLinkTool {...p} /></>;
|
|
121
|
+
}
|
|
122
|
+
|
|
101
123
|
/** Liên kết của nút ngay trên thanh: ô địa chỉ + mở tab mới (cùng thuộc tính href / target với bảng bên phải). */
|
|
102
124
|
export function ButtonLinkTool({ block, setAttrs }: BlockEditProps) {
|
|
103
125
|
const { labels } = useEditor();
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import { CORE_NODES,
|
|
1
|
+
import { CORE_NODES, colorCss, iconListClass, resolveIcon, widgetMarkup, type WidgetEl } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { IconPicker } from "../ui/icon-picker";
|
|
3
|
+
import { ColorInput } from "../ui/color-field";
|
|
4
|
+
import { IconSvg } from "../ui/icon-svg";
|
|
2
5
|
import { BarChart3, Hash, Image as ImageIcon, ListChecks, MapPin, Quote, Star } from "lucide-react";
|
|
3
|
-
import { createElement, type CSSProperties, type ReactNode } from "react";
|
|
6
|
+
import { createElement, useEffect, useRef, useSyncExternalStore, type CSSProperties, type ReactNode } from "react";
|
|
7
|
+
import { useEditor } from "../context";
|
|
4
8
|
import { makeBlock } from "../core/model";
|
|
5
9
|
import type { BlockEditProps, BlockType } from "../core/registry";
|
|
6
10
|
import { useMsgs } from "../i18n";
|
|
7
11
|
import { messages } from "../../i18n";
|
|
8
12
|
import { RichText } from "../text/rich-text";
|
|
9
13
|
import { Section } from "../ui/style-controls";
|
|
14
|
+
import { IconTool } from "./tools";
|
|
10
15
|
import { MediaPick } from "./layout";
|
|
11
16
|
import { useActiveWithin } from "./resize";
|
|
12
17
|
import { AddItemButton, TextPlaceholder } from "../ui/placeholders";
|
|
18
|
+
import { iconBoxLayouts, iconListLayouts, progressLayouts, testimonialLayouts } from "./layout-options";
|
|
13
19
|
|
|
14
20
|
const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
|
|
15
21
|
|
|
@@ -56,51 +62,97 @@ function WidgetEdit(props: BlockEditProps) {
|
|
|
56
62
|
/** Icon List trên khung soạn: mỗi dòng gõ ngay trên khối (dòng trống website bỏ qua) + "+ Thêm dòng". */
|
|
57
63
|
function IconListEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
58
64
|
const tp = useMsgs("placeholders");
|
|
59
|
-
const
|
|
65
|
+
const { ui } = useEditor();
|
|
66
|
+
const activeIdx = useSyncExternalStore(ui.subscribe, () => ui.activeItem.get(block.id) ?? 0);
|
|
67
|
+
const items: Array<{ text: string; href?: string; icon?: string; tip?: string; color?: string; iconBg?: string; textColor?: string }> = Array.isArray(block.attrs.items) ? block.attrs.items : [];
|
|
60
68
|
const list = items.length || !editable ? items : [{ text: "" }];
|
|
61
69
|
const save = (next: typeof items) => setAttrs({ items: next });
|
|
62
70
|
const stroke = Math.min(4, Math.max(0.5, Number(block.attrs.stroke) || 2));
|
|
63
|
-
const icon = (name?: string) => name === "none" ? null : <
|
|
71
|
+
const icon = (name?: string, it?: { color?: string; iconBg?: string }) => name === "none" ? null : <IconSvg className="ecx-widget-icon" style={{ ...(colorCss(it?.color) ? { color: colorCss(it?.color) } : {}), ...(colorCss(it?.iconBg) ? { background: colorCss(it?.iconBg) } : {}) }} name={resolveIcon(name) ? name : resolveIcon(block.attrs.icon) ? block.attrs.icon : "check"} stroke={stroke} />;
|
|
72
|
+
const ul = useRef<HTMLUListElement | null>(null);
|
|
73
|
+
const focusAt = useRef<number | null>(null);
|
|
74
|
+
// Sau khi thêm / xoá mục, đưa con trỏ vào đúng mục (Enter → mục mới, Backspace → mục trước)
|
|
75
|
+
useEffect(() => { if (focusAt.current != null) { ul.current?.querySelectorAll<HTMLInputElement>("li input")[focusAt.current]?.focus(); focusAt.current = null; } });
|
|
76
|
+
/** Enter: thêm mục ngay dưới; Backspace ở mục trống: xoá mục, về mục trước. */
|
|
77
|
+
const key = (i: number) => (e: { key: string; shiftKey: boolean; preventDefault(): void; currentTarget: HTMLInputElement | HTMLTextAreaElement }) => {
|
|
78
|
+
if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); focusAt.current = i + 1; save([...list.slice(0, i + 1), { text: "" }, ...list.slice(i + 1)]); }
|
|
79
|
+
else if (e.key === "Backspace" && e.currentTarget.value === "" && list.length > 1) { e.preventDefault(); focusAt.current = Math.max(0, i - 1); save(list.filter((_, k) => k !== i)); }
|
|
80
|
+
};
|
|
64
81
|
return (
|
|
65
|
-
<ul {...blockProps} className={cx(blockProps.className, iconListClass(block.attrs))}>
|
|
82
|
+
<ul {...blockProps} ref={(el) => { ul.current = el; const r = (blockProps as { ref?: unknown }).ref; if (typeof r === "function") (r as (n: HTMLUListElement | null) => void)(el); else if (r && typeof r === "object") (r as { current: unknown }).current = el; }} className={cx(blockProps.className, iconListClass(block.attrs))}>
|
|
66
83
|
{list.map((it, i) => (
|
|
67
|
-
<li key={i}>{icon(it.icon)}{editable
|
|
68
|
-
? <TextPlaceholder value={it.text} placeholder={i === 0 ? tp.iconListItem : `${tp.addRow}…`} label={`${tp.addRow} ${i + 1}`} onChange={(v) => save(list.map((x, k) => (k === i ? { ...x, text: v } : x)))}
|
|
69
|
-
: <span>{it.text}</span>}</li>
|
|
84
|
+
<li key={i} className={editable && i === activeIdx ? "is-item-active" : undefined} data-ecx-tip={it.tip?.trim() ? it.tip.trim().slice(0, 120) : undefined} onFocusCapture={() => ui.setActiveItem(block.id, i)}>{icon(it.icon, it)}{editable
|
|
85
|
+
? <span style={colorCss(it.textColor) ? { color: colorCss(it.textColor) } : undefined}><TextPlaceholder value={it.text} placeholder={i === 0 ? tp.iconListItem : `${tp.addRow}…`} label={`${tp.addRow} ${i + 1}`} onKeyDown={key(i)} onChange={(v) => save(list.map((x, k) => (k === i ? { ...x, text: v } : x)))} /></span>
|
|
86
|
+
: <span style={colorCss(it.textColor) ? { color: colorCss(it.textColor) } : undefined}>{it.text}</span>}</li>
|
|
70
87
|
))}
|
|
71
|
-
{editable && <li className="ecx-ph-list-add"><AddItemButton label={tp.addRow} onClick={() => save([...list, { text: "" }])} /></li>}
|
|
88
|
+
{editable && <li className="ecx-ph-list-add"><AddItemButton label={tp.addRow} onClick={() => { focusAt.current = list.length; save([...list, { text: "" }]); }} /></li>}
|
|
72
89
|
</ul>
|
|
73
90
|
);
|
|
74
91
|
}
|
|
75
92
|
|
|
76
93
|
/** Các mục của Icon List: mỗi mục một hàng — chữ, icon riêng (theo danh sách / tên icon / không icon), liên kết; thêm / xoá mục. Dòng trống website bỏ qua. */
|
|
77
|
-
|
|
94
|
+
/** Icon ngay trên thanh: Icon Box (khi đầu hộp là icon) — chọn một lần, thấy ngay trên khối. */
|
|
95
|
+
function IconBoxTool({ block, setAttrs }: BlockEditProps) {
|
|
96
|
+
const media = block.attrs.media;
|
|
97
|
+
if (media && media !== "icon") return null;
|
|
98
|
+
return <IconTool value={block.attrs.icon as string | undefined} onChange={(v) => setAttrs({ icon: v ?? "star" })} />;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Icon List: có mục đang chọn thì đổi icon của mục đó; chưa chọn mục nào thì đổi icon chung của danh sách. */
|
|
102
|
+
function IconListTool({ block, attrs, setAttrs }: BlockEditProps) {
|
|
103
|
+
const { ui } = useEditor();
|
|
104
|
+
useSyncExternalStore(ui.subscribe, ui.getTick);
|
|
105
|
+
const items: Array<{ text: string; href?: string; icon?: string; tip?: string; color?: string; iconBg?: string; textColor?: string }> = Array.isArray(attrs.items) ? attrs.items : [];
|
|
106
|
+
const sel = ui.activeItem.get(block.id);
|
|
107
|
+
const item = sel != null ? items[sel] : undefined;
|
|
108
|
+
if (!item) return <IconTool value={attrs.icon as string | undefined} onChange={(v) => setAttrs({ icon: v ?? "check" })} />;
|
|
109
|
+
return <IconTool value={item.icon && item.icon !== "none" ? item.icon : (attrs.icon as string | undefined)} allowNone
|
|
110
|
+
onChange={(v) => setAttrs({ items: items.map((x, k) => { if (k !== sel) return x; const n = { ...x }; if (v) n.icon = v; else n.icon = "none"; return n; }) })} />;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function IconListInspector({ block, attrs, setAttrs }: BlockEditProps) {
|
|
78
114
|
const t = useMsgs("blocks") as Record<string, string>;
|
|
79
115
|
const h = useMsgs("hints") as Record<string, string>;
|
|
80
|
-
const
|
|
116
|
+
const { ui } = useEditor();
|
|
117
|
+
useSyncExternalStore(ui.subscribe, ui.getTick);
|
|
118
|
+
const items: Array<{ text: string; href?: string; icon?: string; tip?: string; color?: string; iconBg?: string; textColor?: string }> = Array.isArray(attrs.items) ? attrs.items : [];
|
|
119
|
+
const sel = Math.min(Math.max(ui.activeItem.get(block.id) ?? 0, 0), Math.max(0, items.length - 1));
|
|
81
120
|
const patch = (i: number, p: Record<string, string | undefined>) => setAttrs({ items: items.map((x, k) => {
|
|
82
121
|
if (k !== i) return x;
|
|
83
122
|
const next: Record<string, unknown> = { ...x, ...p };
|
|
84
123
|
for (const key of Object.keys(next)) if (next[key] === undefined || (key !== "text" && next[key] === "")) delete next[key];
|
|
85
124
|
return next;
|
|
86
125
|
}) });
|
|
126
|
+
const pick = (i: number) => ui.setActiveItem(block.id, i);
|
|
127
|
+
const move = (i: number, d: number) => { const j = i + d; if (j < 0 || j >= items.length) return; const next = items.slice(); [next[i], next[j]] = [next[j], next[i]]; setAttrs({ items: next }); pick(j); };
|
|
87
128
|
return (
|
|
88
129
|
<Section title={t.iconListItems} defaultOpen>
|
|
89
130
|
{items.map((it, i) => (
|
|
90
|
-
<div key={i} className="ecx-item-row" data-icon-list-item>
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
<
|
|
94
|
-
|
|
95
|
-
<
|
|
96
|
-
{
|
|
97
|
-
|
|
98
|
-
<input className="ecx-input" type="url" inputMode="url" aria-label={`${t.iconListLink} ${i + 1}`} placeholder={t.iconListLink} value={it.href ?? ""} onChange={(e) => patch(i, { href: e.target.value || undefined })} />
|
|
131
|
+
<div key={i} className={cx("ecx-item-row", i === sel && "is-active")} data-icon-list-item data-active={i === sel ? "" : undefined} onFocusCapture={() => pick(i)} onMouseDown={() => pick(i)}>
|
|
132
|
+
<div className="ecx-item-row-head">
|
|
133
|
+
<span className="ecx-item-n" aria-hidden="true">{i + 1}</span>
|
|
134
|
+
<input className="ecx-input" aria-label={`${t.iconListText} ${i + 1}`} placeholder={t.iconListText} value={it.text ?? ""} onChange={(e) => patch(i, { text: e.target.value })} />
|
|
135
|
+
{i === sel && <>
|
|
136
|
+
<button type="button" className="ecx-tool" aria-label={`${t.iconListUp} ${i + 1}`} title={t.iconListUp} disabled={i === 0} onClick={() => move(i, -1)}>↑</button>
|
|
137
|
+
<button type="button" className="ecx-tool" aria-label={`${t.iconListDown} ${i + 1}`} title={t.iconListDown} disabled={i === items.length - 1} onClick={() => move(i, 1)}>↓</button>
|
|
138
|
+
</>}
|
|
99
139
|
<button type="button" className="ecx-tool" aria-label={`${t.iconListRemove} ${i + 1}`} title={t.iconListRemove} onClick={() => setAttrs({ items: items.filter((_, k) => k !== i) })}>×</button>
|
|
100
140
|
</div>
|
|
141
|
+
{i === sel && (
|
|
142
|
+
<div className="ecx-item-row-sub">
|
|
143
|
+
<IconPicker label={`${t.iconListIcon} ${i + 1}`} value={it.icon} defaultLabel={t.iconListIconDefault} noneValue="none" onChange={(v) => patch(i, { icon: v })} />
|
|
144
|
+
<input className="ecx-input" type="url" inputMode="url" aria-label={`${t.iconListLink} ${i + 1}`} placeholder={t.iconListLink} value={it.href ?? ""} onChange={(e) => patch(i, { href: e.target.value || undefined })} />
|
|
145
|
+
<input className="ecx-input" aria-label={`${t.iconListTip} ${i + 1}`} placeholder={t.iconListTip} maxLength={120} value={it.tip ?? ""} onChange={(e) => patch(i, { tip: e.target.value || undefined })} />
|
|
146
|
+
<div className="ecx-item-colors">
|
|
147
|
+
<ColorInput label={`${t.iconListColor} ${i + 1}`} value={it.color} onChange={(v) => patch(i, { color: v })} />
|
|
148
|
+
<ColorInput label={`${t.iconListBg} ${i + 1}`} value={it.iconBg} onChange={(v) => patch(i, { iconBg: v })} />
|
|
149
|
+
<ColorInput label={`${t.iconListTextColor} ${i + 1}`} value={it.textColor} onChange={(v) => patch(i, { textColor: v })} />
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
)}
|
|
101
153
|
</div>
|
|
102
154
|
))}
|
|
103
|
-
{items.length < 50 && <button type="button" className="ecx-btn" onClick={() => setAttrs({ items: [...items, { text: "" }] })}>+ {t.iconListAdd}</button>}
|
|
155
|
+
{items.length < 50 && <button type="button" className="ecx-btn" onClick={() => { setAttrs({ items: [...items, { text: "" }] }); pick(items.length); }}>+ {t.iconListAdd}</button>}
|
|
104
156
|
</Section>
|
|
105
157
|
);
|
|
106
158
|
}
|
|
@@ -111,20 +163,24 @@ const ICON_BOX_ORDER = ["media", "icon", "number", "src", "alt", "width", "heigh
|
|
|
111
163
|
function ordered<T>(attrs: Record<string, T>, order: string[]): Record<string, T> {
|
|
112
164
|
return Object.fromEntries([...order.filter((k) => k in attrs), ...Object.keys(attrs).filter((k) => !order.includes(k))].map((k) => [k, attrs[k]]));
|
|
113
165
|
}
|
|
114
|
-
const
|
|
166
|
+
const OVERLAY_ORDER = ["media", "src", "alt", "title", "subtitle", "level", "href", "linkTarget", "ratio", "hAlign", "vAlign", "subtitleMode", "imageEffect", "overlayColor", "overlayOpacity", "restOpacity", "frame", "frameInset", "divider"];
|
|
167
|
+
const ICON_SELECT = { type: "string" as const };
|
|
115
168
|
|
|
116
169
|
/** Khối widget của lõi; `lang` = ngôn ngữ của trình soạn (chữ mẫu khi chèn). */
|
|
117
170
|
export function widgetBlocks(lang?: string): BlockType[] {
|
|
118
171
|
const m = messages("blocks", lang) as Record<string, string>;
|
|
119
172
|
const base = { kind: "atom" as const, category: "widgets", edit: WidgetEdit, supports: { style: true, anchor: true, className: true } };
|
|
120
173
|
return [
|
|
121
|
-
{ ...base, name: "iconBox", title: "Icon Box", icon: Star, keywords: "icon box hop bieu tuong tinh nang dich vu feature", attributes: ordered({ ...spec("iconBox"), icon: { ...ICON_SELECT, default: "star" }, src: { type: "url", control: "media" } }, ICON_BOX_ORDER), create: () => makeBlock("iconBox", { icon: "star", title:
|
|
174
|
+
{ ...base, name: "iconBox", toolbar: IconBoxTool, layouts: iconBoxLayouts(m), layoutsOnInsert: false, layoutOwns: ["position"], title: "Icon Box", icon: Star, keywords: "icon box hop bieu tuong tinh nang dich vu feature", attributes: ordered({ ...spec("iconBox"), icon: { ...ICON_SELECT, default: "star" }, src: { type: "url", control: "media" } }, ICON_BOX_ORDER), create: () => makeBlock("iconBox", { icon: "star", title: m.sampleBoxTitle, text: m.sampleBoxText }), summary: (a) => a.title },
|
|
122
175
|
// Hộp ảnh đã gộp vào Hộp icon (media = ảnh): ẩn khỏi trình chèn, nội dung cũ vẫn sửa được
|
|
123
176
|
{ ...base, hidden: true, 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: "", text: "" }), summary: (a) => a.title },
|
|
124
|
-
|
|
125
|
-
{ ...base, name: "
|
|
126
|
-
|
|
127
|
-
{ ...base, name: "
|
|
128
|
-
{ ...base, name: "
|
|
177
|
+
// Ảnh phủ chữ: ảnh + lớp màu + khung viền + chữ hiện khi rê chuột (thẻ chuyên mục, bộ sưu tập, dự án)
|
|
178
|
+
{ ...base, name: "imageOverlay", title: "Image Overlay", icon: ImageIcon, keywords: "anh phu chu image overlay hover the chuyen muc bo suu tap du an banner", attributes: ordered({ ...spec("imageOverlay"), src: { type: "url", control: "media" }, overlayColor: { type: "string", control: "color" } }, OVERLAY_ORDER),
|
|
179
|
+
create: () => makeBlock("imageOverlay", { title: m.sampleOverlayTitle, subtitle: m.sampleOverlaySubtitle, overlayColor: "primary", overlayOpacity: 65, imageEffect: "zoom", ratio: "4/3" }), summary: (a) => a.title },
|
|
180
|
+
{ ...base, name: "iconList", toolbar: IconListTool, layouts: iconListLayouts(m), layoutOwns: ["layout"], 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.sampleList1, m.sampleList2, m.sampleList3, m.sampleList4].map((text) => ({ text })) }) },
|
|
181
|
+
{ ...base, name: "counter", title: "Counter", icon: Hash, keywords: "counter dem so con so thong ke number", attributes: spec("counter"), create: () => makeBlock("counter", { end: 1200, suffix: "+", title: m.sampleCounterTitle, textAlign: "center" }), summary: (a) => a.title },
|
|
182
|
+
{ ...base, name: "testimonial", layouts: testimonialLayouts(m), layoutOwns: ["variant"], title: "Testimonial", icon: Quote, keywords: "testimonial loi chung thuc danh gia khach hang review", attributes: ordered({ ...spec("testimonial"), src: { type: "url", control: "media" } }, ["variant", "quoteMark", "rating", "quote", "name", "role", "src", "alt", "textAlign"]), create: () => makeBlock("testimonial", { quote: m.sampleQuote, name: m.sampleName, role: m.sampleRole, rating: 5 }), summary: (a) => a.name },
|
|
183
|
+
{ ...base, name: "map", title: "Map", icon: MapPin, keywords: "map ban do dia chi google maps vi tri", attributes: ordered(spec("map") ?? {}, ["address", "title", "zoom", "height", "mapType"]), create: () => makeBlock("map", { address: m.sampleAddress }), summary: (a) => a.address },
|
|
184
|
+
{ ...base, name: "progressBar", layouts: progressLayouts(m), layoutsOnInsert: false, layoutOwns: ["textPosition"], 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 },
|
|
129
185
|
];
|
|
130
186
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { controlsCss, normalizeStyle, styleClass, widthClass } from "@ecomcx/ecomweb-content";
|
|
2
2
|
import { blockControls } from "../../shared/panel-store";
|
|
3
|
-
import { Component, memo, useCallback, useContext, useEffect, useMemo, useRef, type ErrorInfo, type MouseEvent, type PointerEvent, type ReactElement, type ReactNode } from "react";
|
|
3
|
+
import { Component, memo, useCallback, useContext, useEffect, useMemo, useRef, useSyncExternalStore, type ErrorInfo, type MouseEvent, type PointerEvent, type ReactElement, type ReactNode } from "react";
|
|
4
4
|
import { DocScopeProvider, LoopPostContext, useDocScope, useEditor, useEditorState } from "../context";
|
|
5
5
|
import { ServerBlock } from "./server-block";
|
|
6
|
+
import { VariationChooser } from "./variation-picker";
|
|
6
7
|
import { startDrag } from "./dnd";
|
|
7
8
|
import { docIdOf, type NestedDocRef } from "../core/host";
|
|
8
9
|
import { blocksFromDoc, makeBlock, type BNode } from "../core/model";
|
|
@@ -22,6 +23,9 @@ export function sectionOf(store: ReturnType<typeof useEditor>["store"], el: HTML
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
/** Props gắn vào phần tử gốc của khối: chọn, viền, kiểu dáng, neo. */
|
|
26
|
+
/** Khối chứa mà con phủ kín: có nhãn rê chuột để bấm chọn chính khối chứa (xem canvas-css). */
|
|
27
|
+
const LABELED = new Set(["query", "postTemplate", "queryEmpty", "templatePart", "tabs", "tab", "accordion", "details", "popup", "testimonials", "carousel", "columns", "column", "buttons", "form", "mediaText", "cover"]);
|
|
28
|
+
|
|
25
29
|
export function useBlockProps(block: BNode, state: { selected: boolean; editing: boolean; mode: EditingMode }): BlockProps {
|
|
26
30
|
const ctx = useEditor();
|
|
27
31
|
const { store, registry, ui } = ctx;
|
|
@@ -44,7 +48,8 @@ export function useBlockProps(block: BNode, state: { selected: boolean; editing:
|
|
|
44
48
|
if (store.modeOf(block.id) === "disabled") return;
|
|
45
49
|
const rich = target.closest<HTMLElement>("[data-ecx-rich]");
|
|
46
50
|
if (rich && rich.isContentEditable && !e.shiftKey) return; // bấm vào chữ: ProseMirror đặt con trỏ, focus báo đang gõ
|
|
47
|
-
|
|
51
|
+
// Ô nhập / nút thật của khối đặt chỗ tự xử lý; riêng vùng đánh dấu data-ecx-inert (bản xem trước không bấm được, vd khối Tìm kiếm) thì bấm vào là chọn khối
|
|
52
|
+
if (target.closest("input, textarea, select, button, [contenteditable=true]") && !target.closest("[data-ecx-inert]") && !e.shiftKey) return;
|
|
48
53
|
// Bấm vào phần đệm của ô bảng: con trỏ vào chữ trong ô (như bấm vào ô của Word / WordPress), không chọn cả ô
|
|
49
54
|
if ((block.type === "tableCell" || block.type === "tableHeader") && !e.shiftKey && !e.metaKey && !e.ctrlKey) {
|
|
50
55
|
const text = block.content?.find((b) => b.inline);
|
|
@@ -70,7 +75,7 @@ export function useBlockProps(block: BNode, state: { selected: boolean; editing:
|
|
|
70
75
|
if (t.closest("[data-ecx-block]")?.getAttribute("data-ecx-block") !== block.id) return;
|
|
71
76
|
// Chỉ xét trong khối (cả khung soạn là contenteditable)
|
|
72
77
|
const hit = t.closest("[data-ecx-rich], input, textarea, select, button, a, [contenteditable=true], .ecx-pad-handles, .ecx-col-handles, .ecx-image-handle");
|
|
73
|
-
if (hit && e.currentTarget.contains(hit)) return;
|
|
78
|
+
if (hit && e.currentTarget.contains(hit) && !hit.closest("[data-ecx-inert]")) return;
|
|
74
79
|
const ids = store.getState().selection.ids;
|
|
75
80
|
startDrag(ctx, e, ids.includes(block.id) ? ids : [block.id]);
|
|
76
81
|
}, [block.id, ctx, store, ui]);
|
|
@@ -78,6 +83,7 @@ export function useBlockProps(block: BNode, state: { selected: boolean; editing:
|
|
|
78
83
|
ref: null,
|
|
79
84
|
"data-ecx-block": block.id,
|
|
80
85
|
"data-type": block.type,
|
|
86
|
+
...(LABELED.has(block.type) ? { "data-ecx-label": type?.title ?? block.type } : {}),
|
|
81
87
|
tabIndex: type?.kind === "text" ? undefined : -1,
|
|
82
88
|
id: typeof a.anchor === "string" ? a.anchor : undefined,
|
|
83
89
|
className: cx(
|
|
@@ -115,10 +121,14 @@ export const Block = memo(function Block({ node }: { node: BNode }) {
|
|
|
115
121
|
const type = registry.get(node.type);
|
|
116
122
|
const blockProps = useBlockProps(node, { selected, editing, mode: scope.mode });
|
|
117
123
|
const setAttrs = useCallback((attrs: Record<string, unknown>) => store.setAttrs([node.id], attrs), [node.id, store]);
|
|
124
|
+
const { ui } = useEditor();
|
|
125
|
+
const picking = useSyncExternalStore(ui.subscribe, () => ui.pickIds.has(node.id));
|
|
126
|
+
// (Hook phải gọi trước mọi return sớm — ô chọn bố cục trả về sớm khi đang chờ chọn.) Khối trong vòng lặp bài (query › postTemplate) giữ giao diện của trình soạn: website chỉ biết bài của trang, không biết bài của vòng lặp
|
|
127
|
+
const loop = useContext(LoopPostContext);
|
|
118
128
|
const Edit = type?.edit ?? FallbackEdit;
|
|
119
129
|
const props: BlockEditProps = { block: node, attrs: node.attrs, setAttrs, blockProps, selected: selected || editing, editable: scope.mode !== "disabled", labels };
|
|
120
|
-
|
|
121
|
-
|
|
130
|
+
if (picking && type?.layouts?.length && scope.mode !== "disabled")
|
|
131
|
+
return <BlockBoundary id={node.id} type={node.type}><VariationChooser type={type} attrs={node.attrs} blockProps={blockProps as unknown as Record<string, unknown>} onPick={(v) => { setAttrs(v.attrs); ui.resolvePick(node.id); }} onSkip={() => ui.resolvePick(node.id, true)} /></BlockBoundary>;
|
|
122
132
|
// editWhenSelected: đang chọn → ô giữ chỗ của trình soạn; vẫn đi qua ServerBlock để ô nhập không bị dựng lại (mất focus) khi chọn / bỏ chọn
|
|
123
133
|
if (type?.serverRender && host.renderBlock && !loop)
|
|
124
134
|
return <BlockBoundary id={node.id} type={node.type}><ServerBlock node={node} blockProps={blockProps} fallback={<Edit {...props} />} live={!(type.editWhenSelected && (selected || editing) && scope.mode !== "disabled")} /></BlockBoundary>;
|
|
@@ -163,15 +173,36 @@ export function InnerBlocks({ parent, appender = "auto" }: { parent: BNode; appe
|
|
|
163
173
|
const kids = parent.content ?? [];
|
|
164
174
|
const { store } = useEditor();
|
|
165
175
|
const showAppender = appender === "auto" && scope.mode === "default" && !kids.length && store.canInsertInto(parent.id);
|
|
176
|
+
// Khối chứa đã có nội dung (Cột, Nhóm, Tab, Hộp lưu ý): nút "+" nhỏ ngay dưới khối cuối, hiện khi rê chuột / chọn — để thấy chỗ thêm tiếp và chỗ thả (như dòng "gõ / để chọn khối" của WordPress)
|
|
177
|
+
const showTail = appender === "auto" && scope.mode === "default" && kids.length > 0 && TAIL_PARENTS.has(parent.type) && !isFlowLayout(parent) && store.canInsertInto(parent.id);
|
|
166
178
|
const elements = useBlockElements(kids);
|
|
167
179
|
return (
|
|
168
180
|
<>
|
|
169
181
|
{elements}
|
|
170
182
|
{showAppender && <Appender docId={scope.docId} parentId={parent.id} index={0} />}
|
|
183
|
+
{showTail && <TailAppender docId={scope.docId} parentId={parent.id} index={kids.length} />}
|
|
171
184
|
</>
|
|
172
185
|
);
|
|
173
186
|
}
|
|
174
187
|
|
|
188
|
+
const TAIL_PARENTS = new Set(["column", "group", "tab"]);
|
|
189
|
+
/** Nhóm dạng hàng ngang / lưới: thêm một ô vào hàng sẽ làm lệch bố cục → không có nút + cuối (dùng thanh công cụ / bảng chèn). */
|
|
190
|
+
const isFlowLayout = (b: BNode) => { const t = (b.attrs.style as { layout?: { type?: string } } | undefined)?.layout?.type; return t === "flex" || t === "grid"; };
|
|
191
|
+
|
|
192
|
+
/** Nút "+" nhỏ cuối khối chứa đã có nội dung: ẩn khi không rê chuột / chọn. */
|
|
193
|
+
function TailAppender({ docId, parentId, index }: { docId: string; parentId: string; index: number }) {
|
|
194
|
+
const { ui, labels } = useEditor();
|
|
195
|
+
return (
|
|
196
|
+
<button type="button" className="ecx-tail-appender" title={labels.addBlock} aria-label={labels.addBlock} contentEditable={false} data-ecx-ui="" tabIndex={-1}
|
|
197
|
+
onMouseDown={(e) => { e.preventDefault(); e.stopPropagation(); }}
|
|
198
|
+
onClick={(e) => {
|
|
199
|
+
const r = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
200
|
+
const f = ui.canvasFrame?.getBoundingClientRect();
|
|
201
|
+
ui.openInserter({ mode: "appender", docId, parentId, index, rect: { left: (f?.left ?? 0) + r.left, top: (f?.top ?? 0) + r.top, bottom: (f?.top ?? 0) + r.bottom } });
|
|
202
|
+
}} data-ecx-placeholder="add"><span aria-hidden="true">+</span></button>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
175
206
|
/** Nút "+" chèn khối vào khối chứa trống. */
|
|
176
207
|
export function Appender({ docId, parentId, index }: { docId: string; parentId: string | null; index: number }) {
|
|
177
208
|
const { ui, labels } = useEditor();
|