@ecomcx/ecomweb-editor 1.25.1 → 1.25.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecomcx/ecomweb-editor",
3
- "version": "1.25.1",
3
+ "version": "1.25.2",
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": {
@@ -139,4 +139,49 @@ export const hints = {
139
139
  "imageSize.medium": "Medium",
140
140
  "imageSize.large": "Large",
141
141
  "imageSize.full": "Full size",
142
+ "gallery.linkTo.label": "Link images",
143
+ "gallery.linkTo.opt.none": "None",
144
+ "gallery.linkTo.opt.media": "Open full image",
145
+ "gallery.imageCrop.label": "Crop images to fit",
146
+ "gallery.lightbox.label": "Enlarge on click",
147
+ "countdown.expiredText.label": "Text when expired",
148
+ "navigation.overlayMenu.label": "Collapse into menu button",
149
+ "navigation.overlayMenu.opt.never": "Never",
150
+ "navigation.overlayMenu.opt.mobile": "Mobile",
151
+ "navigation.overlayMenu.opt.always": "Always",
152
+ "search.showLabel.label": "Show label",
153
+ "search.buttonPosition.label": "Button position",
154
+ "search.buttonPosition.opt.right": "Right",
155
+ "search.buttonPosition.opt.left": "Left",
156
+ "search.buttonPosition.opt.below": "Below",
157
+ "languageSwitcher.display.opt.inline": "Inline",
158
+ "languageSwitcher.display.opt.dropdown": "Dropdown",
159
+ "postAuthor.showName.label": "Show name",
160
+ "postAuthor.showBio.label": "Show bio",
161
+ "postAuthor.avatarSize.label": "Avatar size",
162
+ "comments.avatarSize.label": "Avatar size",
163
+ "comments.showDate.label": "Show date",
164
+ "comments.order.opt.asc": "Oldest first",
165
+ "comments.order.opt.desc": "Newest first",
166
+ "termList.showCount.label": "Show post count",
167
+ "termList.hideEmpty.label": "Hide empty",
168
+ "termList.hierarchical.label": "Show hierarchy",
169
+ "termList.display.opt.list": "List",
170
+ "termList.display.opt.cloud": "Tag cloud",
171
+ "loginout.loginText.label": "“Log in” text",
172
+ "loginout.logoutText.label": "“Log out” text",
173
+ "pageList.parentId.label": "Only children of (page ID)",
174
+ "archives.showCount.label": "Show post count",
175
+ "icon.name.opt.check": "Check",
176
+ "icon.name.opt.x": "X",
177
+ "icon.name.opt.star": "Star",
178
+ "icon.name.opt.heart": "Heart",
179
+ "icon.name.opt.arrowRight": "Arrow right",
180
+ "icon.name.opt.phone": "Phone",
181
+ "icon.name.opt.mail": "Mail",
182
+ "icon.name.opt.mapPin": "Map pin",
183
+ "icon.name.opt.clock": "Clock",
184
+ "icon.name.opt.info": "Info",
185
+ "icon.name.opt.alert": "Alert",
186
+ "icon.name.opt.externalLink": "External link",
142
187
  };
@@ -139,4 +139,49 @@ export const hints = {
139
139
  "imageSize.medium": "Vừa",
140
140
  "imageSize.large": "Lớn",
141
141
  "imageSize.full": "Gốc",
142
+ "gallery.linkTo.label": "Liên kết ảnh",
143
+ "gallery.linkTo.opt.none": "Không",
144
+ "gallery.linkTo.opt.media": "Mở ảnh gốc",
145
+ "gallery.imageCrop.label": "Cắt ảnh cho đều khung",
146
+ "gallery.lightbox.label": "Phóng to khi bấm",
147
+ "countdown.expiredText.label": "Chữ khi hết giờ",
148
+ "navigation.overlayMenu.label": "Thu gọn thành nút menu",
149
+ "navigation.overlayMenu.opt.never": "Không",
150
+ "navigation.overlayMenu.opt.mobile": "Điện thoại",
151
+ "navigation.overlayMenu.opt.always": "Luôn luôn",
152
+ "search.showLabel.label": "Hiện nhãn",
153
+ "search.buttonPosition.label": "Vị trí nút",
154
+ "search.buttonPosition.opt.right": "Phải",
155
+ "search.buttonPosition.opt.left": "Trái",
156
+ "search.buttonPosition.opt.below": "Bên dưới",
157
+ "languageSwitcher.display.opt.inline": "Dàn hàng",
158
+ "languageSwitcher.display.opt.dropdown": "Danh sách xổ xuống",
159
+ "postAuthor.showName.label": "Hiện tên",
160
+ "postAuthor.showBio.label": "Hiện giới thiệu",
161
+ "postAuthor.avatarSize.label": "Cỡ ảnh đại diện",
162
+ "comments.avatarSize.label": "Cỡ ảnh đại diện",
163
+ "comments.showDate.label": "Hiện ngày",
164
+ "comments.order.opt.asc": "Cũ trước",
165
+ "comments.order.opt.desc": "Mới trước",
166
+ "termList.showCount.label": "Hiện số bài",
167
+ "termList.hideEmpty.label": "Ẩn mục trống",
168
+ "termList.hierarchical.label": "Hiện theo cấp",
169
+ "termList.display.opt.list": "Danh sách",
170
+ "termList.display.opt.cloud": "Đám mây thẻ",
171
+ "loginout.loginText.label": "Chữ “Đăng nhập”",
172
+ "loginout.logoutText.label": "Chữ “Đăng xuất”",
173
+ "pageList.parentId.label": "Chỉ trang con của (mã trang)",
174
+ "archives.showCount.label": "Hiện số bài",
175
+ "icon.name.opt.check": "Dấu tick",
176
+ "icon.name.opt.x": "Dấu X",
177
+ "icon.name.opt.star": "Ngôi sao",
178
+ "icon.name.opt.heart": "Trái tim",
179
+ "icon.name.opt.arrowRight": "Mũi tên phải",
180
+ "icon.name.opt.phone": "Điện thoại",
181
+ "icon.name.opt.mail": "Thư",
182
+ "icon.name.opt.mapPin": "Ghim bản đồ",
183
+ "icon.name.opt.clock": "Đồng hồ",
184
+ "icon.name.opt.info": "Thông tin",
185
+ "icon.name.opt.alert": "Cảnh báo",
186
+ "icon.name.opt.externalLink": "Liên kết ngoài",
142
187
  };
@@ -81,8 +81,8 @@ function FileEdit({ block, blockProps }: BlockEditProps) {
81
81
  function YoutubeEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
82
82
  const m = String(block.attrs.src ?? "").match(/(?:v=|youtu\.be\/|embed\/)([\w-]{11})/);
83
83
  const [draft, setDraft] = useState("");
84
+ const t = useMsgs("blocks"); // hook phải gọi trước mọi return sớm (đổi số hook khi dán link → React #300)
84
85
  if (!m) {
85
- const t = useMsgs("blocks");
86
86
  return (
87
87
  <div {...blockProps} className={cx(blockProps.className, "ecx-media-placeholder")}>
88
88
  <span className="ecx-placeholder-title"><Play className="ecx-icon" />YouTube</span>
@@ -111,7 +111,10 @@ function PostAuthorEdit({ blockProps }: BlockEditProps) {
111
111
  }
112
112
  function PostTermsEdit({ block, blockProps }: BlockEditProps) {
113
113
  const d = useDynamic();
114
- return <p {...merge(blockProps, "ecx-post-terms")}>{(d.post?.terms?.length ? d.post.terms : block.attrs.taxonomy === "post_tag" ? ["Thẻ A", "Thẻ B"] : ["Chuyên mục A", "Chuyên mục B"]).join(String(block.attrs.separator ?? ", "))}</p>;
114
+ const names = d.post?.terms?.length ? d.post.terms : block.attrs.taxonomy === "post_tag" ? ["Thẻ A", "Thẻ B"] : ["Chuyên mục A", "Chuyên mục B"];
115
+ const sep = String(block.attrs.separator ?? ", ");
116
+ // website dựng mỗi mục là <a rel="tag"> (TermLinks) → canvas cũng là liên kết để ăn đúng kiểu liên kết của theme
117
+ return <p {...merge(blockProps, "ecx-post-terms")}>{names.map((n, i) => <span key={i}>{i > 0 && sep}<a href="#" rel="tag" onClick={(e) => e.preventDefault()}>{n}</a></span>)}</p>;
115
118
  }
116
119
  function ReadMoreEdit({ block, blockProps }: BlockEditProps) {
117
120
  return <p {...merge(blockProps, "ecx-read-more", align(block.attrs))}><a href="#" onClick={(e) => e.preventDefault()}>{String(block.attrs.text || "Đọc tiếp")}</a></p>;
@@ -41,6 +41,7 @@ pre [data-ecx-rich], pre[data-ecx-rich] { white-space: pre-wrap; }
41
41
  /* min(100%, …) = 0 trong khung co theo nội dung (nút) → dùng độ dài chữ gợi ý, chặn tràn bằng max-width */
42
42
  [data-ecx-rich][data-empty][data-placeholder] { min-width: calc(var(--ecx-ph, 0) * .6em); max-width: 100%; }
43
43
  span[data-ecx-rich][data-empty][data-placeholder] { display: inline-block; vertical-align: top; }
44
+ [data-ecx-rich][data-empty][data-placeholder] { min-width: 0; } /* ô lưới/flex trống không bị chữ gợi ý (nowrap) đẩy rộng hơn khung */
44
45
  [data-ecx-rich][data-empty][data-placeholder]::before { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
45
46
  .ProseMirror-hideselection *::selection { background: transparent; }
46
47
  .ProseMirror-selectednode { outline: 2px solid var(--ecx-ui); }
@@ -140,9 +141,9 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
140
141
  .ecx-media-error { color: #b42318; font: 12px var(--ecx-ui-font); margin: 6px 0 0; }
141
142
  .ecx-cover-placeholder { min-height: 220px; }
142
143
  .ecx-btn-ghost { background: none; border-color: transparent; }
143
- /* tay nắm cột / nút thêm cột định vị theo khối cột (website không cần) */
144
+ /* tay nắm cột / nút thêm cột định vị theo khối cột (website không cần); nút nằm trong khối cột, góc dưới phải: không tràn khung canvas (thanh cuộn ngang) và không bị thanh công cụ nổi (ở trên khối đang chọn) che */
144
145
  .ecx-canvas-root .ecx-columns { position: relative; }
145
- .ecx-add-column { position: absolute; right: -14px; top: 50%; transform: translateY(-50%); z-index: 7; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px; background: #0f1e29; color: #fff; font: 600 18px/1 var(--ecx-ui-font); cursor: pointer; box-shadow: 0 2px 6px rgb(0 0 0 / .2); }
146
+ .ecx-add-column { position: absolute; right: 4px; bottom: 4px; z-index: 7; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px; background: #0f1e29; color: #fff; font: 600 18px/1 var(--ecx-ui-font); cursor: pointer; box-shadow: 0 2px 6px rgb(0 0 0 / .2); }
146
147
  .ecx-add-column:hover { background: var(--ecx-ui); }
147
148
  .is-zoomed-out .ecx-add-column { display: none; }
148
149
  `;
@@ -1,7 +1,7 @@
1
1
  import type { RichNode } from "@ecomcx/ecomweb-content";
2
2
  import { cloneBlock, inlineLength, joinInline, kindOf, makeBlock, splitInline, type BNode } from "./model";
3
3
  import { findBlock, flatten, insertBlocks, mapBlock, moveBlocks, removeBlocks, setAttrs, sibling, topLevelOrdered, type Location } from "./ops";
4
- import { canContain, fixTree } from "./structure";
4
+ import { canContain, leavesItem, fixTree } from "./structure";
5
5
 
6
6
  /**
7
7
  * Store của trình soạn: nhiều tài liệu cùng lúc (bài/template đang mở + header, footer, mẫu đồng bộ lồng bên trong),
@@ -470,7 +470,7 @@ export class EditorStore {
470
470
  const loc = this.locate(afterId);
471
471
  if (!loc) return;
472
472
  const target = loc.block;
473
- if (opts.replaceEmpty !== false && target.type === "paragraph" && !inlineLength(target.inline) && canContain(loc.parent?.type ?? null, nodes[0].type) && this.canRemove(afterId)) {
473
+ if (opts.replaceEmpty !== false && target.type === "paragraph" && !inlineLength(target.inline) && canContain(loc.parent?.type ?? null, nodes[0].type) && !leavesItem(loc.parent?.type, nodes[0].type) && this.canRemove(afterId)) {
474
474
  const focusId = opts.focus !== false ? firstText(nodes[0]) : null;
475
475
  this.commit(loc.docId, mapBlock(this.state.docs[loc.docId].blocks, afterId, () => nodes), {
476
476
  select: focusId ? { ids: [], editing: focusId } : { ids: nodes.map((n) => n.id), editing: null },
@@ -480,7 +480,7 @@ export class EditorStore {
480
480
  }
481
481
  // Khối không đặt được ở cấp này (vd chèn nhóm sau một listItem): leo lên tới cấp đặt được
482
482
  let at: Location & { docId: string } = loc;
483
- while (at.parent && !canContain(at.parent.type, nodes[0].type)) {
483
+ while (at.parent && (!canContain(at.parent.type, nodes[0].type) || leavesItem(at.parent.type, nodes[0].type))) {
484
484
  const up = this.locate(at.parent.id);
485
485
  if (!up) break;
486
486
  at = up;
@@ -38,6 +38,9 @@ const RULES: Record<string, StructureRule> = {
38
38
  tableHeader: { parents: ["tableRow"], required: p },
39
39
  };
40
40
 
41
+ /** Mục danh sách / việc chỉ nhận chữ và danh sách lồng: khối lớn (bảng, ảnh, nhóm…) chèn mới thì phải ra ngoài danh sách. */
42
+ export const leavesItem = (parentType: string | null | undefined, child: string) => (parentType === "listItem" || parentType === "taskItem") && !/^(paragraph|bulletList|orderedList|taskList)$/.test(child);
43
+
41
44
  const extra = new Map<string, StructureRule>();
42
45
  export function setStructureRule(type: string, rule: StructureRule | null) {
43
46
  if (rule) extra.set(type, rule);
@@ -90,9 +90,29 @@ export const ATTR_HINTS: Record<string, AttrHint> = {
90
90
  "socialLinks.align": { control: "segmented", options: ALIGN },
91
91
  "navigation.location": { control: "choice", choice: { kind: "menuLocation" }, help: true },
92
92
  "navigation.orientation": { control: "segmented", options: ["horizontal", "vertical"] },
93
- "navigation.overlayMenu": { control: "segmented", options: ["never", "mobile", "always"] },
93
+ "navigation.overlayMenu": { control: "segmented", label: true, options: ["never", "mobile", "always"] },
94
+ "gallery.linkTo": { control: "segmented", label: true, options: ["none", "media"] },
95
+ "gallery.imageCrop": { label: true },
96
+ "gallery.lightbox": { label: true },
97
+ "countdown.expiredText": { label: true },
98
+ "search.showLabel": { label: true },
99
+ "search.buttonPosition": { control: "segmented", label: true, options: ["right", "left", "below"] },
100
+ "postAuthor.showName": { label: true },
101
+ "postAuthor.showBio": { label: true },
102
+ "postAuthor.avatarSize": { label: true },
103
+ "comments.avatarSize": { label: true },
104
+ "comments.showDate": { label: true },
105
+ "comments.order": { control: "segmented", options: ["asc", "desc"] },
106
+ "termList.display": { control: "segmented", options: ["list", "cloud"] },
107
+ "termList.showCount": { label: true },
108
+ "termList.hideEmpty": { label: true },
109
+ "termList.hierarchical": { label: true },
110
+ "loginout.loginText": { label: true },
111
+ "loginout.logoutText": { label: true },
112
+ "pageList.parentId": { label: true },
113
+ "archives.showCount": { label: true },
114
+ "icon.name": { control: "select", options: ["check", "x", "star", "heart", "arrowRight", "phone", "mail", "mapPin", "clock", "info", "alert", "externalLink"] },
94
115
  "languageSwitcher.display": { control: "segmented", options: ["inline", "dropdown"] },
95
- "gallery.linkTo": { control: "segmented", options: ["none", "media"] },
96
116
  "postTerms.taxonomy": { control: "choice", choice: { kind: "taxonomy" } },
97
117
  "query.postType": { control: "choice", choice: { kind: "postType" }, when: notInherit },
98
118
  "query.category": { control: "choice", choice: { kind: "term", args: () => ({ taxonomy: "category" }) }, when: notInherit },
@@ -1,3 +1,4 @@
1
+ import { leavesItem } from "../core/structure";
1
2
  import { blockDescription } from "./block-descriptions";
2
3
  import { Blocks } from "lucide-react";
3
4
  import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ComponentType } from "react";
@@ -70,7 +71,12 @@ export function applyInsert(ctx: ReturnType<typeof useEditor>, req: InserterRequ
70
71
  if (req.mode === "slash" && req.blockId) {
71
72
  const b = store.block(req.blockId);
72
73
  // Đoạn chỉ còn "/từ khoá" → thay cả đoạn bằng khối mới
73
- if (b && inlineLength(b.inline) <= (req.query?.length ?? 0) + 1) store.replace(req.blockId, [node], focusOpts(node));
74
+ const parentType = store.locate(req.blockId)?.parent?.type;
75
+ if (b && leavesItem(parentType, node.type)) {
76
+ // trong mục danh sách: khối mới ra sau danh sách, bỏ đoạn "/từ khoá" (mục còn lại tự có đoạn trống)
77
+ store.insertAfter(req.blockId, [node], { replaceEmpty: false });
78
+ store.remove([req.blockId], { focusNeighbor: false });
79
+ } else if (b && inlineLength(b.inline) <= (req.query?.length ?? 0) + 1) store.replace(req.blockId, [node], focusOpts(node));
74
80
  else store.insertAfter(req.blockId, [node]);
75
81
  } else store.insert(req.docId, req.parentId, req.index, [node]);
76
82
  ui.openInserter(null);
@@ -194,7 +200,13 @@ const CATEGORY_ORDER = ["text", "media", "design", "widgets", "theme", "embed"];
194
200
  export function InserterPanel({ onInserted }: { onInserted?(): void }) {
195
201
  const ctx = useEditor();
196
202
  const { store, labels } = ctx;
197
- const options = useInsertOptions();
203
+ useUiTick();
204
+ const all = useInsertOptions();
205
+ // Khối có luật vị trí (vd "Tổng số bài" chỉ trong Query): ẩn khi từ chỗ đang chọn đi lên tới gốc không có cấp nào nhận
206
+ const cur = store.currentIds[store.currentIds.length - 1];
207
+ const loc = cur ? store.locate(cur) : null;
208
+ const chain = loc ? [null, ...loc.ancestors.map((id) => store.block(id)?.type ?? null)] : [null];
209
+ const options = all.filter((o) => chain.some((t) => canContain(t, o.type)));
198
210
  const [query, setQuery] = useState("");
199
211
  const [tab, setTab] = useState<"blocks" | "patterns">("blocks");
200
212
  const [hover, setHover] = useState<{ o: InsertOption; rect: DOMRect; y: number } | null>(null);