@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.
Files changed (91) hide show
  1. package/package.json +3 -3
  2. package/src/locales/en/attrs.ts +2 -1
  3. package/src/locales/en/background.ts +5 -0
  4. package/src/locales/en/bindings.ts +5 -1
  5. package/src/locales/en/block-desc.ts +5 -11
  6. package/src/locales/en/block-style.ts +17 -6
  7. package/src/locales/en/block-titles.ts +38 -15
  8. package/src/locales/en/blocks.ts +37 -6
  9. package/src/locales/en/columns.ts +1 -0
  10. package/src/locales/en/controls.ts +1 -1
  11. package/src/locales/en/hints.ts +315 -12
  12. package/src/locales/en/index.ts +3 -1
  13. package/src/locales/en/layout.ts +13 -0
  14. package/src/locales/en/motion.ts +16 -0
  15. package/src/locales/en/palette.ts +8 -0
  16. package/src/locales/en/parts.ts +2 -1
  17. package/src/locales/en/pattern-overrides.ts +14 -0
  18. package/src/locales/en/placeholders.ts +9 -3
  19. package/src/locales/en/v2.ts +2 -0
  20. package/src/locales/vi/attrs.ts +3 -2
  21. package/src/locales/vi/background.ts +5 -0
  22. package/src/locales/vi/bindings.ts +5 -1
  23. package/src/locales/vi/block-desc.ts +8 -14
  24. package/src/locales/vi/block-style.ts +18 -7
  25. package/src/locales/vi/block-titles.ts +48 -25
  26. package/src/locales/vi/blocks.ts +37 -6
  27. package/src/locales/vi/columns.ts +1 -0
  28. package/src/locales/vi/controls.ts +1 -1
  29. package/src/locales/vi/hints.ts +315 -12
  30. package/src/locales/vi/index.ts +3 -1
  31. package/src/locales/vi/layout.ts +13 -0
  32. package/src/locales/vi/motion.ts +16 -0
  33. package/src/locales/vi/palette.ts +8 -0
  34. package/src/locales/vi/parts.ts +2 -1
  35. package/src/locales/vi/pattern-overrides.ts +14 -0
  36. package/src/locales/vi/placeholders.ts +10 -4
  37. package/src/locales/vi/v2.ts +2 -0
  38. package/src/v2/blocks/columns-inspector.tsx +11 -2
  39. package/src/v2/blocks/index.ts +9 -6
  40. package/src/v2/blocks/layout-options.tsx +80 -0
  41. package/src/v2/blocks/layout.tsx +349 -106
  42. package/src/v2/blocks/media.tsx +51 -21
  43. package/src/v2/blocks/resize.tsx +50 -19
  44. package/src/v2/blocks/social-icons.ts +22 -0
  45. package/src/v2/blocks/text.tsx +12 -50
  46. package/src/v2/blocks/theme.tsx +62 -29
  47. package/src/v2/blocks/tools.tsx +24 -2
  48. package/src/v2/blocks/widgets.tsx +84 -28
  49. package/src/v2/canvas/block-list.tsx +36 -5
  50. package/src/v2/canvas/canvas-css.ts +95 -7
  51. package/src/v2/canvas/canvas.tsx +65 -9
  52. package/src/v2/canvas/dnd.ts +7 -0
  53. package/src/v2/canvas/variation-picker.tsx +63 -0
  54. package/src/v2/context.tsx +48 -0
  55. package/src/v2/core/bindings.ts +6 -1
  56. package/src/v2/core/block-presets.ts +10 -0
  57. package/src/v2/core/clipboard.ts +5 -5
  58. package/src/v2/core/host.ts +3 -1
  59. package/src/v2/core/model.ts +6 -6
  60. package/src/v2/core/registry.ts +15 -0
  61. package/src/v2/core/store.ts +9 -9
  62. package/src/v2/core/structure.ts +1 -3
  63. package/src/v2/editor.css +74 -0
  64. package/src/v2/editor.tsx +22 -7
  65. package/src/v2/text/rich-text.tsx +20 -5
  66. package/src/v2/ui/ai-markdown.ts +52 -0
  67. package/src/v2/ui/ai.tsx +81 -14
  68. package/src/v2/ui/attr-form.tsx +45 -7
  69. package/src/v2/ui/attr-hints.ts +151 -19
  70. package/src/v2/ui/background-panel.tsx +22 -0
  71. package/src/v2/ui/bg-video-preview.tsx +7 -0
  72. package/src/v2/ui/bindings.tsx +9 -1
  73. package/src/v2/ui/block-icons.tsx +3 -10
  74. package/src/v2/ui/block-live-preview.tsx +21 -0
  75. package/src/v2/ui/block-style-panel.tsx +3 -1
  76. package/src/v2/ui/command-palette.tsx +125 -0
  77. package/src/v2/ui/icon-picker.tsx +88 -21
  78. package/src/v2/ui/icon-svg.tsx +21 -0
  79. package/src/v2/ui/inserter.tsx +72 -17
  80. package/src/v2/ui/inspector.tsx +12 -6
  81. package/src/v2/ui/layout-panel.tsx +1 -1
  82. package/src/v2/ui/motion-panel.tsx +22 -13
  83. package/src/v2/ui/option-thumbs.tsx +81 -0
  84. package/src/v2/ui/pattern-library.tsx +2 -1
  85. package/src/v2/ui/pattern-overrides.tsx +67 -0
  86. package/src/v2/ui/placeholders.tsx +21 -2
  87. package/src/v2/ui/preset-bar.tsx +5 -5
  88. package/src/v2/ui/style-supports.ts +2 -3
  89. package/src/v2/ui/style-tab.tsx +83 -20
  90. package/src/v2/ui/toolbar.tsx +40 -6
  91. package/src/v2/ui/transform-panel.tsx +77 -0
@@ -81,6 +81,19 @@ span[data-ecx-rich][data-empty][data-placeholder] { display: inline-block; verti
81
81
  .ecx-appender:hover { opacity: 1; border-color: var(--ecx-ui); color: var(--ecx-ui); }
82
82
 
83
83
  .ecx-placeholder-block, .ecx-media-placeholder { display: flex; flex-direction: column; gap: .5rem; padding: 1rem; border: 1px dashed color-mix(in srgb, currentColor 30%, transparent); border-radius: 6px; font: 14px/1.4 var(--ecx-ui-font); }
84
+ .ecx-variation-chooser { display: flex; flex-direction: column; gap: 12px; padding: 16px; border: 1px dashed color-mix(in srgb, currentColor 30%, transparent); border-radius: 8px; font: 14px/1.4 var(--ecx-ui-font); }
85
+ .ecx-variation-title { font-weight: 600; text-transform: uppercase; letter-spacing: .04em; font-size: 12px; text-align: center; }
86
+ .ecx-variation-chooser .ecx-variations { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; max-width: 640px; width: 100%; margin: 0 auto; }
87
+ .ecx-variation-chooser .ecx-variation { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 8px 8px; border: 1px solid color-mix(in srgb, currentColor 22%, transparent); border-radius: 8px; background: transparent; color: inherit; font: 12px/1.25 var(--ecx-ui-font); cursor: pointer; }
88
+ .ecx-variation-chooser .ecx-variation:hover, .ecx-variation-chooser .ecx-variation:focus-visible { border-color: var(--ecx-ui); outline: none; box-shadow: 0 0 0 1px var(--ecx-ui); }
89
+ .ecx-variation-chooser .ecx-vthumb { width: 100%; height: auto; }
90
+ .ecx-variation-chooser .ecx-vthumb rect { fill: color-mix(in srgb, currentColor 18%, transparent); }
91
+ .ecx-variation-chooser .ecx-vthumb rect.is-box, .ecx-variation-chooser .ecx-vthumb polygon.is-box { fill: transparent; stroke: color-mix(in srgb, currentColor 32%, transparent); stroke-width: 1.2; }
92
+ .ecx-variation-chooser .ecx-vthumb .is-accent { fill: var(--ecx-ui); stroke: none; }
93
+ .ecx-variation-chooser .ecx-vthumb rect.is-box.is-accent { fill: transparent; stroke: var(--ecx-ui); }
94
+ .ecx-variation-chooser .ecx-vthumb path.is-line { fill: none; stroke: var(--ecx-ui); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
95
+ .ecx-variation-skip { align-self: center; border: 0; background: none; color: inherit; opacity: .7; text-decoration: underline; font: 13px var(--ecx-ui-font); cursor: pointer; }
96
+ .ecx-variation-skip:hover { opacity: 1; }
84
97
  .ecx-placeholder-block.is-unknown { border-color: #d97706; background: rgba(217, 119, 6, .05); }
85
98
  .ecx-placeholder-title { display: inline-flex; align-items: center; gap: .4rem; font-weight: 600; }
86
99
  .ecx-placeholder-summary { opacity: .65; font-size: 12px; }
@@ -137,13 +150,15 @@ body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select:
137
150
  .ecx-doc-title .ecx-doc-title-input, .ecx-doc-title .ecx-doc-title-input:focus { border: 0; border-radius: 0; outline: none; box-shadow: none; padding: 0; background: transparent; min-height: 0; }
138
151
  .ecx-col-handles { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
139
152
  /* Dải kéo đệm trên / dưới của khối bố cục đang chọn */
140
- .ecx-block.is-selected:has(> .ecx-pad-handles) { position: relative; }
153
+ :where(.ecx-block.is-selected:has(> .ecx-pad-handles)) { position: relative; }
141
154
  /* Khối bố cục đang chọn: chỗ trống nắm được để kéo đổi chỗ; khối con / chữ giữ con trỏ thường */
142
155
  .ecx-block[data-ecx-grab] { cursor: grab; }
143
156
  .ecx-block[data-ecx-grab] .ecx-block, .ecx-block[data-ecx-grab] [data-ecx-rich] { cursor: auto; }
144
157
  .ecx-pad-handles { position: absolute; inset: 0; max-width: none; margin: 0; pointer-events: none; z-index: 7; }
145
- .ecx-block.is-selected:has(> .ecx-cw-handles) { position: relative; }
158
+ :where(.ecx-block.is-selected:has(> .ecx-cw-handles)) { position: relative; }
146
159
  .ecx-cw-handles { position: absolute; inset: 0; max-width: none; margin: 0; pointer-events: none; z-index: 8; }
160
+ .ecx-cw-guide { position: absolute; top: 0; bottom: 0; border-left: 1px dashed var(--ecx-ui); border-right: 1px dashed var(--ecx-ui); background: color-mix(in srgb, var(--ecx-ui) 6%, transparent); pointer-events: none; opacity: .7; }
161
+ .ecx-cw-guide.is-dragging { background: color-mix(in srgb, var(--ecx-ui) 14%, transparent); opacity: 1; }
147
162
  .ecx-cw-handle { position: absolute; top: 50%; width: 10px; height: 44px; margin: -22px 0 0 4px; border-radius: 6px; background: var(--ecx-ui); box-shadow: 0 0 0 2px #fff; cursor: ew-resize; pointer-events: auto; opacity: .55; touch-action: none; }
148
163
  .ecx-cw-handle.is-left { margin-left: -14px; }
149
164
  .ecx-cw-handle:hover, .ecx-cw-handle.is-dragging { opacity: 1; }
@@ -163,6 +178,10 @@ body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select:
163
178
  .ecx-pad-zone.is-top::after { top: calc(50% - 2px); }
164
179
  .ecx-pad-zone.is-bottom::after { bottom: calc(50% - 2px); }
165
180
  .ecx-pad-zone:hover::after, .ecx-pad-zone.is-dragging::after { opacity: 1; }
181
+ /* Hai cạnh trái / phải: dải đứng, kéo ngang */
182
+ .ecx-pad-zone.is-left, .ecx-pad-zone.is-right { top: 0; bottom: 0; left: auto; right: auto; cursor: ew-resize; }
183
+ .ecx-pad-zone.is-left { left: 0; } .ecx-pad-zone.is-right { right: 0; }
184
+ .ecx-pad-zone.is-left::after, .ecx-pad-zone.is-right::after { top: 50%; left: 50%; width: 4px; height: 36px; margin: -18px 0 0 -2px; }
166
185
  .ecx-col-handle { position: absolute; width: 12px; margin-left: -6px; cursor: col-resize; pointer-events: auto; touch-action: none; }
167
186
  .ecx-col-handle.is-dragging::before, .ecx-col-handle.is-dragging::after { position: absolute; top: 8px; padding: 1px 6px; border-radius: 4px; background: var(--ecx-ui); color: #fff; font: 600 11px/1.5 system-ui, sans-serif; white-space: nowrap; pointer-events: none; }
168
187
  .ecx-col-handle.is-dragging::before { content: attr(data-left); right: 14px; }
@@ -196,7 +215,12 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
196
215
 
197
216
  /* Chỉ trong trình soạn: khối "vô hình" trên website vẫn thấy được để chọn / sửa */
198
217
  .ecx-spacer { background: repeating-linear-gradient(-45deg, transparent 0 6px, color-mix(in srgb, var(--ecx-ui) 8%, transparent) 6px 7px); }
199
- .ecx-block.ecx-column:not(.is-selected):not(.is-editing) { outline: 1px dashed color-mix(in srgb, currentColor 16%, transparent); outline-offset: -1px; min-height: 48px; }
218
+ .ecx-block.ecx-column:not(.is-selected):not(.is-editing) { outline: 1px dashed color-mix(in srgb, currentColor 16%, transparent); outline-offset: -1px; min-height: 96px; }
219
+ /* Nút + cuối khối chứa (Cột, Nhóm, Tab, Hộp lưu ý): hiện khi rê chuột vào khối trong cùng / khi đang chọn hoặc gõ trong khối */
220
+ .ecx-tail-appender { display: none; align-items: center; justify-content: center; width: 100%; height: 26px; margin: 6px 0 0; padding: 0; border: 1px dashed color-mix(in srgb, var(--ecx-ui) 55%, transparent); border-radius: 6px; background: transparent; color: var(--ecx-ui); font: 600 16px/1 var(--ecx-ui-font); cursor: pointer; opacity: 0; pointer-events: none; transition: opacity .12s ease; }
221
+ .ecx-tail-appender:hover { background: color-mix(in srgb, var(--ecx-ui) 8%, transparent); border-style: solid; }
222
+ .ecx-block:hover:not(:has(.ecx-block:hover > .ecx-tail-appender)) > .ecx-tail-appender, .ecx-block.is-selected > .ecx-tail-appender, .ecx-block:has(> * > .is-editing, > .is-editing, > .is-selected) > .ecx-tail-appender { display: flex; opacity: 1; pointer-events: auto; }
223
+ .is-zoomed-out .ecx-tail-appender, [data-ecx-preview] .ecx-tail-appender { display: none !important; }
200
224
  .ecx-block.ecx-column:not(.is-selected):hover { outline-color: color-mix(in srgb, var(--ecx-ui) 55%, transparent); }
201
225
  .ecx-media-placeholder.is-drop-target { outline: 2px dashed var(--ecx-ui); background: color-mix(in srgb, var(--ecx-ui) 6%, transparent); }
202
226
  .ecx-placeholder-hint { margin: 4px 0 10px; font: 13px/1.5 var(--ecx-ui-font); opacity: .75; }
@@ -276,6 +300,62 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
276
300
  .ecx-add-item { display: inline-flex; align-items: center; gap: 4px; margin: 6px 0 0; padding: 6px 10px; border: 1px dashed color-mix(in srgb, currentColor 40%, transparent); border-radius: 6px; background: transparent; color: inherit; font: 600 13px/1.2 var(--ecx-ui-font); cursor: pointer; opacity: .85; }
277
301
  .ecx-add-item:hover, .ecx-add-item:focus-visible { opacity: 1; border-color: var(--ecx-ui); color: var(--ecx-ui); }
278
302
  .ecx-tabs-list .ecx-add-item { margin: 0 0 0 8px; align-self: center; }
303
+ /* Thanh chuyển slide của carousel (chỉ trên khung soạn) */
304
+ .ecx-carousel-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 6px 0 0; font: 600 12px/1 var(--ecx-ui-font); user-select: none; }
305
+ .ecx-carousel-nav:empty { display: none; }
306
+ .ecx-carousel-nav .ecx-add-item { margin: 0 0 0 8px; }
307
+ .ecx-carousel-nav button { display: inline-flex; align-items: center; justify-content: center; min-width: 28px; height: 28px; padding: 0 6px; border: 1px solid #c9d0d7; border-radius: 6px; background: #fff; color: #1f2d38; font: inherit; cursor: pointer; }
308
+ .ecx-carousel-nav button[aria-current="true"] { border-color: var(--ecx-ui); background: var(--ecx-ui); color: #fff; }
309
+ .ecx-carousel-nav button:disabled { opacity: .4; cursor: default; }
310
+ .ecx-carousel-nav .ecx-icon { width: 16px; height: 16px; }
311
+ [data-ecx-preview] .ecx-add-item, [data-ecx-preview] .ecx-carousel-nav, [data-ecx-preview] .ecx-countdown-setup, [data-ecx-preview] .ph-list-add { display: none !important; }
312
+ .ecx-icon-list > li.is-item-active { outline: 2px solid var(--ecx-ui); outline-offset: 2px; border-radius: 4px; }
313
+ .ecx-countdown-setup { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; padding: 8px 10px; border: 1px dashed color-mix(in srgb, currentColor 25%, transparent); border-radius: 8px; font: 12px/1.3 var(--ecx-ui-font); }
314
+ .ecx-countdown-setup .ecx-ph-row { display: flex; align-items: center; gap: 8px; margin: 0; }
315
+ .ecx-countdown-setup .ecx-input { height: 30px; }
316
+ .ecx-carousel-nav .ecx-carousel-del { margin-left: 4px; color: #b42318; }
317
+ .ecx-carousel-nav .ecx-carousel-count { margin-left: auto; opacity: .6; font-weight: 500; }
318
+ .ecx-carousel-nav { min-width: 0; padding-top: 4px; }
319
+ /* Mỗi slide hiện thành một khung riêng trên khung soạn (website không vẽ khung này). Slide nào cũng nằm thật trong track cuộn ngang */
320
+ .ecx-carousel { margin-top: 0; margin-bottom: 0; } /* chỉ trên / dưới: lề trái / phải tự động giữ Slider nằm giữa cột như website */
321
+ .ecx-carousel-track { scroll-snap-type: none; } /* khung soạn: không bám mép — bám mép giằng co với con trỏ khi gõ và với lệnh cuộn tới slide */
322
+ .ecx-carousel-track > [data-ecx-block][data-type="group"] { min-height: 140px; padding: 20px; border: 1px dashed color-mix(in srgb, currentColor 28%, transparent); border-radius: 8px; box-sizing: border-box; }
323
+ /* Popup khi soạn: nút mở ở trên, nội dung popup luôn mở trong khung nét đứt có nhãn */
324
+ .ecx-popup-frame { position: relative; margin-top: 10px; padding: 26px 16px 12px; border: 1px dashed color-mix(in srgb, currentColor 32%, transparent); border-radius: 10px; }
325
+ .ecx-popup-frame-label { position: absolute; top: 6px; left: 12px; font: 600 11px/1 system-ui, sans-serif; letter-spacing: .02em; text-transform: uppercase; opacity: .55; user-select: none; }
326
+ .ecx-countdown-setup [role="radio"] { font: 500 13px/1 system-ui, sans-serif; padding: 8px 12px; border-radius: 6px; border: 1px solid color-mix(in srgb, currentColor 25%, transparent); background: transparent; color: inherit; cursor: pointer; }
327
+ .ecx-countdown-setup [role="radio"][aria-checked="true"] { background: var(--ecx-color-primary, #1a597b); border-color: transparent; color: white; }
328
+ .ecx-countdown-setup .ecx-ph-inline-field { display: inline-flex; align-items: center; gap: 8px; margin-right: 12px; }
329
+ /* Tiêu đề có chữ gõ: khung soạn hiện từ đầu tiên (website gõ lần lượt các từ) — vẽ bằng ::after, không chen vào ô sửa chữ */
330
+ [data-ecx-typed]::after { content: " " attr(data-ecx-typed); color: var(--ecx-typed-color, inherit); border-right: .08em solid currentColor; padding-right: .04em; }
331
+ .ecx-popup-trigger-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
332
+ .ecx-popup-preview-btn { font: 500 12px/1 system-ui, sans-serif; padding: 6px 10px; border-radius: 6px; border: 1px solid color-mix(in srgb, currentColor 28%, transparent); background: transparent; color: inherit; cursor: pointer; opacity: .75; }
333
+ .ecx-popup-preview-btn:hover { opacity: 1; }
334
+ .ecx-popup-preview-close { position: sticky; float: right; top: 0; margin: -1.25rem -1.25rem 0 0; width: 28px; height: 28px; border: 0; border-radius: 999px; background: #111827; color: white; font: 400 18px/1 system-ui; cursor: pointer; }
335
+ /* Xem thử: khung nội dung thành hộp thoại giữa màn hình với nền tối như trên website (vẫn sửa được các khối bên trong) */
336
+ .ecx-popup.is-previewing .ecx-popup-frame { --_w: 40rem; position: fixed; z-index: 60; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(var(--_w), calc(100% - 2rem)); max-height: 80vh; overflow: auto; box-sizing: border-box; padding: 2rem; border: 0; border-radius: 12px; background: var(--ecx-color-background, white); box-shadow: 0 0 0 100vmax rgb(0 0 0 / var(--ecx-popup-dim, .6)), 0 24px 64px rgb(0 0 0 / .3); }
337
+ .ecx-popup.is-previewing.is-size-sm .ecx-popup-frame { --_w: 28rem; }
338
+ .ecx-popup.is-previewing.is-size-lg .ecx-popup-frame { --_w: 56rem; }
339
+ .ecx-popup.is-previewing.is-size-xl .ecx-popup-frame { --_w: 72rem; }
340
+ .ecx-popup.is-previewing .ecx-popup-frame-label { display: none; }
341
+ .ecx-popup.is-previewing .ecx-popup-preview-btn { display: none; }
342
+
343
+ /* Image Overlay chưa có ảnh: ô chọn ảnh ở trên, chữ nằm dưới (không phủ lên ô chọn ảnh) và dùng màu chữ của trang để đọc được */
344
+ .ecx-image-overlay:not(:has(img)) { aspect-ratio: auto; background: none; color: inherit; overflow: visible; border-radius: 0; }
345
+ .ecx-image-overlay:not(:has(img)) .ecx-image-overlay-media { position: static; }
346
+ .ecx-image-overlay:not(:has(img)) .ecx-image-overlay-tint { display: none; }
347
+ .ecx-image-overlay:not(:has(img)) .ecx-image-overlay-body { position: static; padding: 10px 4px 0; align-items: center; text-align: center; }
348
+ .ecx-image-overlay:not(:has(img)) .ecx-image-overlay-body::before { display: none; }
349
+
350
+ /* Ảnh phủ chữ khi soạn: chữ luôn hiện rõ và gõ được (website chỉ hiện khi rê); khối rỗng vẫn có khung cao để thấy */
351
+ [data-ecx-block][data-type="imageOverlay"] { min-height: 160px; }
352
+ [data-ecx-block][data-type="imageOverlay"] .ecx-image-overlay-body { pointer-events: auto; }
353
+ [data-ecx-block][data-type="imageOverlay"] :is(.ecx-image-overlay-title, .ecx-image-overlay-subtitle, .ecx-image-overlay-divider) { opacity: 1; transform: none; }
354
+ [data-ecx-block][data-type="imageOverlay"] .ecx-image-overlay-tint { opacity: max(var(--ecx-ov-rest, 0), .25); }
355
+ [data-ecx-block][data-type="imageOverlay"]:is(:hover, :focus-within) .ecx-image-overlay-tint { opacity: var(--ecx-ov-hover, .6); }
356
+ /* Slider có chiều cao riêng (tỉ lệ / tối thiểu): slide là nền đầy khung nên bỏ viền nét đứt và mức 140px dành cho thẻ trơn */
357
+ .ecx-carousel[data-height="min"] > .ecx-carousel-track > [data-ecx-block][data-type="group"] { min-height: var(--ecx-min-h, 24rem); border-style: none; border-radius: 0; }
358
+ .ecx-carousel[data-height="ratio"] > .ecx-carousel-track > [data-ecx-block][data-type="group"] { min-height: 0; aspect-ratio: var(--ecx-ratio, 16/9); border-style: none; border-radius: 0; }
279
359
  .ecx-social .ecx-add-item, .ecx-social-add .ecx-add-item { margin: 0; }
280
360
  .ecx-ph-list-add { list-style: none; }
281
361
  .ecx-ph-list-add .ecx-add-item { margin-top: 2px; }
@@ -304,10 +384,18 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
304
384
  .ecx-ph-table .ecx-ph-field { flex: 0 1 110px; }
305
385
  /* Khoảng trống: sọc mờ + kích thước; đường kẻ: vùng bấm cao ≥ 40px (không đổi bố cục) */
306
386
  .ecx-spacer[data-ecx-size] { display: flex; align-items: center; justify-content: center; min-height: 24px; }
307
- .ecx-spacer[data-ecx-size]::before { content: attr(data-ecx-size); padding: 2px 8px; border-radius: 4px; background: rgb(255 255 255 / .85); color: #33414d; font: 12px/1.4 var(--ecx-ui-font); opacity: 0; transition: opacity .15s; pointer-events: none; }
308
- .ecx-spacer[data-ecx-size]:hover::before, .ecx-spacer.is-selected[data-ecx-size]::before { opacity: 1; }
309
- .ecx-rating[data-ecx-placeholder] { display: flex; align-items: center; gap: 2px; min-height: 40px; }
310
- .ecx-rating[data-ecx-placeholder] .ecx-placeholder-hint { margin: 0 0 0 8px; }
387
+ .ecx-spacer[data-ecx-size]::after { position: relative; z-index: 1; content: attr(data-ecx-size); padding: 2px 8px; border-radius: 4px; background: rgb(255 255 255 / .85); color: #33414d; font: 12px/1.4 var(--ecx-ui-font); opacity: 0; transition: opacity .15s; pointer-events: none; }
388
+ .ecx-spacer[data-ecx-size]:hover::after, .ecx-spacer.is-selected[data-ecx-size]::after { opacity: 1; }
311
389
  hr.ecx-block { position: relative; overflow: visible; }
312
390
  hr.ecx-block::before { content: ""; position: absolute; left: 0; right: 0; top: -20px; bottom: -20px; }
313
391
  `;
392
+
393
+ export const CONTAINER_LABEL_CSS = `
394
+ /* Khối chứa mà con phủ kín (Danh sách bài, Khuôn mỗi bài, Phần mẫu, Tabs…): rê chuột hiện nhãn ở góc trên trái, bấm nhãn = chọn khối chứa */
395
+ .ecx-canvas-root :where([data-ecx-label]:hover) { position: relative; }
396
+ .ecx-canvas-root [data-ecx-label]:hover:not(:has([data-ecx-label]:hover))::before {
397
+ content: attr(data-ecx-label); position: absolute; top: 0; left: 0; z-index: 30; padding: 2px 8px; border-radius: 0 0 6px 0; background: var(--ecx-ui, #1a597b); color: #fff;
398
+ font: 600 11px/18px var(--ecx-ui-font, system-ui); letter-spacing: .02em; cursor: pointer; pointer-events: auto; white-space: nowrap; }
399
+ /* Cột / Nhóm (con không phủ kín, chữ nằm sát góc trên trái): nhãn đặt NGAY TRÊN mép khối — không che chữ, không chặn bấm vào chữ */
400
+ .ecx-canvas-root [data-ecx-label]:is([data-type="column"], [data-type="group"], [data-type="buttons"]):hover:not(:has([data-ecx-label]:hover))::before { transform: translateY(-100%); border-radius: 6px 6px 0 0; }
401
+ `;
@@ -7,7 +7,7 @@ import { DocBlocks } from "./block-list";
7
7
  import { BLOCKS_MIME, blocksFromClipboard, serializeBlocks } from "../core/clipboard";
8
8
  import { DocScopeProvider, useEditor, useEditorState, useUiTick } from "../context";
9
9
  import { usePrefs } from "../prefs";
10
- import { CANVAS_CSS } from "./canvas-css";
10
+ import { CANVAS_CSS, CONTAINER_LABEL_CSS } from "./canvas-css";
11
11
  import { applyDocumentAttrs } from "./document-attrs";
12
12
  import { wrapperNodes } from "./wrapper-props";
13
13
  import { makeBlock, type BNode } from "../core/model";
@@ -29,6 +29,8 @@ export interface CanvasProps {
29
29
  /** Vẽ thêm quanh nội dung (vd tiêu đề bài phía trên). */
30
30
  before?: ReactNode;
31
31
  after?: ReactNode;
32
+ /** Khung chỉ xem (xem trước khối / thư viện mẫu): không mang dấu nhận diện khung soạn chính (`data-ecx-canvas`). */
33
+ preview?: boolean;
32
34
  }
33
35
 
34
36
  const SRC_DOC = `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"></head><body class="ecx-canvas-body"></body></html>`;
@@ -41,7 +43,7 @@ export const DESKTOP_MIN_WIDTH = 1025;
41
43
  /** Thu nhỏ dưới tỉ lệ này thì chữ quá nhỏ để đọc / gõ (máy thật là điện thoại, tablet dọc): vẽ đúng bề rộng khung, không thu. */
42
44
  export const MIN_FIT = 0.6;
43
45
 
44
- export function Canvas({ device: deviceProp, className, contentClassName = "ecx-content", before, after }: CanvasProps) {
46
+ export function Canvas({ device: deviceProp, className, contentClassName = "ecx-content", before, after, preview }: CanvasProps) {
45
47
  const { ui, labels } = useEditor();
46
48
  const frameRef = useRef<HTMLIFrameElement>(null);
47
49
  const [doc, setDoc] = useState<Document | null>(null);
@@ -61,9 +63,10 @@ export function Canvas({ device: deviceProp, className, contentClassName = "ecx-
61
63
  if (!f || !d) return;
62
64
  ui.canvasFrame = f;
63
65
  ui.canvasDoc = d;
66
+ if (preview) d.documentElement.setAttribute("data-ecx-preview", "");
64
67
  setDoc(d);
65
68
  ui.bump();
66
- }, [ui]);
69
+ }, [ui, preview]);
67
70
 
68
71
  // srcDoc có thể đã nạp xong trước khi React gắn onLoad
69
72
  useLayoutEffect(() => {
@@ -86,7 +89,7 @@ export function Canvas({ device: deviceProp, className, contentClassName = "ecx-
86
89
  return (
87
90
  <div ref={wrapRef} className={["ecx-canvas-wrap", `is-${device}`, zoom !== 1 && "is-zoomed-out", className].filter(Boolean).join(" ")}>
88
91
  <iframe ref={frameRef} className="ecx-canvas-frame" title={labels.canvas} srcDoc={SRC_DOC} onLoad={onLoad}
89
- style={style} data-ecx-canvas="" />
92
+ style={style} {...(preview ? { "data-ecx-preview": "" } : { "data-ecx-canvas": "" })} />
90
93
  {doc && createPortal(<CanvasWrapper><CanvasRoot doc={doc} contentClassName={contentClassName} before={before} after={after} /></CanvasWrapper>, doc.body)}
91
94
  </div>
92
95
  );
@@ -113,6 +116,7 @@ function CanvasRoot({ doc, contentClassName, before, after }: { doc: Document; c
113
116
  const title = useEditorState(useCallback((s) => s.docs[activeId]?.title, [activeId]));
114
117
  useCanvasDocument(doc);
115
118
  useCanvasStyles(doc);
119
+ useHoverPreview(doc);
116
120
  useCanvasKeys(doc);
117
121
  useCanvasEvents(doc);
118
122
  useMoveAnimation(doc);
@@ -152,6 +156,50 @@ function useCanvasDocument(doc: Document) {
152
156
  }
153
157
 
154
158
  /** CSS trong iframe: nền của trình soạn, CSS website (host), preset theme, kiểu dáng các khối. */
159
+ /**
160
+ * Xem trước trạng thái rê chuột của một khối: lấy mọi quy tắc :hover có nhắc class riêng của khối (ecx-s-… / ecx-c-…), sao thành quy tắc thường
161
+ * (`:hover` → `:not(#ecx-hv)` để thắng quy tắc nền về độ ưu tiên). Quy tắc của theme / khối khác không bị đụng.
162
+ */
163
+ function useHoverPreview(doc: Document) {
164
+ const { ui, store } = useEditor();
165
+ const tick = useUiTick();
166
+ const selected = useEditorState((s) => s.selection.ids.join(",") + "|" + (s.selection.editing ?? ""));
167
+ // Chọn khối khác (hoặc bỏ chọn) → tự tắt xem trước
168
+ useLayoutEffect(() => { if (ui.previewHoverId && !store.currentIds.includes(ui.previewHoverId)) ui.setPreviewHover(null); }, [selected, ui, store]);
169
+ useLayoutEffect(() => {
170
+ doc.getElementById("ecx-hover-preview")?.remove();
171
+ const id = ui.previewHoverId;
172
+ if (!id) return;
173
+ const el = doc.querySelector<HTMLElement>(`[data-ecx-block="${CSS.escape(id)}"]`);
174
+ if (!el) return;
175
+ const classes = [...el.classList].filter((c) => /^ecx-(s|c)-/.test(c));
176
+ if (!classes.length) return;
177
+ const mine = (sel: string) => classes.some((c) => sel.includes(`.${c}`));
178
+ const out: string[] = [];
179
+ const walk = (rules: CSSRuleList, wrap: string[]) => {
180
+ for (const r of Array.from(rules)) {
181
+ // Quy tắc thuộc cửa sổ của iframe: `instanceof` với lớp của cửa sổ chính luôn sai → nhận biết bằng thuộc tính
182
+ if ("selectorText" in r) {
183
+ const r2 = r as CSSStyleRule;
184
+ if (!r2.selectorText.includes(":hover") || !mine(r2.selectorText)) continue;
185
+ const sel = r2.selectorText.split(",").filter((s) => s.includes(":hover") && mine(s)).map((s) => s.replace(/:hover/g, ":not(#ecx-hv)")).join(",");
186
+ if (sel) out.push(wrap.reduce((css, w) => `${w}{${css}}`, `${sel}{${r2.style.cssText}}`));
187
+ } else if ("cssRules" in r) {
188
+ const g = r as CSSGroupingRule & { conditionText?: string };
189
+ walk(g.cssRules, g.conditionText !== undefined && !("supportText" in r) && !("name" in r) ? [...wrap, `@media ${g.conditionText}`] : wrap);
190
+ }
191
+ }
192
+ };
193
+ for (const sheet of Array.from(doc.styleSheets)) { try { walk(sheet.cssRules, []); } catch { /* CSS từ nguồn khác: không đọc được, bỏ qua */ } }
194
+ if (!out.length) return;
195
+ const st = doc.createElement("style");
196
+ st.id = "ecx-hover-preview";
197
+ st.textContent = out.join("\n");
198
+ doc.head.appendChild(st);
199
+ return () => st.remove();
200
+ }, [doc, ui, tick, ui.previewHoverId]);
201
+ }
202
+
155
203
  function useCanvasStyles(doc: Document) {
156
204
  const { host, store } = useEditor();
157
205
  const head = doc.head;
@@ -160,7 +208,7 @@ function useCanvasStyles(doc: Document) {
160
208
  const add = (el: HTMLElement) => { head.appendChild(el); nodes.push(el); };
161
209
  const base = doc.createElement("style");
162
210
  base.dataset.ecx = "canvas";
163
- base.textContent = CANVAS_CSS;
211
+ base.textContent = CANVAS_CSS + CONTAINER_LABEL_CSS;
164
212
  add(base);
165
213
  for (const s of host.canvasStyles ?? []) {
166
214
  if (typeof s === "string") {
@@ -256,14 +304,22 @@ function useCanvasEvents(doc: Document) {
256
304
  if (ae?.isContentEditable) doc.querySelector<HTMLElement>(".ecx-canvas-root")?.focus({ preventScroll: true });
257
305
  });
258
306
  // Chuột phải / Shift+F10 / phím Menu trên khối → menu của khối (BlockContextMenu); Shift + chuột phải giữ menu của trình duyệt (chính tả, dán…)
307
+ // Chuột phải làm ô chữ bên dưới nhận tiêu điểm → vùng chọn nhiều khối (vd các ô bảng bôi đen) bị thu về một khối: nhớ lại lúc nhấn
308
+ let selAtDown: ReturnType<typeof store.getState>["selection"] | null = null;
309
+ const rememberSel = (e: MouseEvent) => { if (e.button === 2) selAtDown = store.getState().selection; };
310
+ doc.addEventListener("mousedown", rememberSel, true);
259
311
  const menu = (e: MouseEvent) => {
260
312
  const el = (e.target as Element | null)?.closest?.<HTMLElement>("[data-ecx-block]");
261
313
  const id = el?.dataset.ecxBlock;
262
314
  if (!id || !ui.canvasFrame || (e.shiftKey && e.button === 2) || store.modeOf(id) === "disabled") return;
263
315
  e.preventDefault();
264
- const sel = store.getState().selection;
265
- const ids = sel.ids.includes(id) ? sel.ids : sel.editing === id ? [id] : null;
316
+ const sel = selAtDown && selAtDown.ids.length > 1 ? selAtDown : store.getState().selection;
317
+ selAtDown = null;
318
+ // Chuột phải bên trong khối đang chọn (vd đoạn chữ trong ô bảng đang bôi đen) → giữ nguyên vùng chọn, không thu về một khối
319
+ const inSel = sel.ids.includes(id) || (sel.ids.length > 1 && (store.locate(id)?.ancestors ?? []).some((a) => sel.ids.includes(a)));
320
+ const ids = inSel ? sel.ids : sel.editing === id ? [id] : null;
266
321
  if (!ids) store.select([id], { editing: null });
322
+ else if (ids.length > 1) store.select(ids, { editing: null });
267
323
  const f = ui.canvasFrame.getBoundingClientRect();
268
324
  const scale = f.width / (ui.canvasFrame.offsetWidth || f.width) || 1;
269
325
  // Mở bằng bàn phím: không có toạ độ chuột → neo dưới góc trái của khối
@@ -274,7 +330,7 @@ function useCanvasEvents(doc: Document) {
274
330
  return () => {
275
331
  win.removeEventListener("scroll", bump); win.removeEventListener("resize", bump); ro.disconnect(); cancelAnimationFrame(raf); unsub();
276
332
  doc.removeEventListener("mousemove", moved); document.removeEventListener("mousemove", moved);
277
- doc.removeEventListener("contextmenu", menu);
333
+ doc.removeEventListener("contextmenu", menu); doc.removeEventListener("mousedown", rememberSel, true);
278
334
  };
279
335
  }, [doc, ui, store]);
280
336
  }
@@ -448,7 +504,7 @@ function useCanvasKeys(doc: Document) {
448
504
  }
449
505
 
450
506
  /** Khối không chọn riêng bằng phím mũi tên (đi thẳng vào chữ bên trong). */
451
- const HIDDEN_NAV = new Set(["listItem", "taskItem", "tableRow"]);
507
+ const HIDDEN_NAV = new Set(["listItem", "tableRow"]);
452
508
 
453
509
  /** Thôi thu nhỏ: phần đang chọn cuộn vào giữa màn hình. */
454
510
  export function zoomIn(store: { getState(): { selection: { ids: string[] } } }, ui: { setZoomOut(v: boolean): void; blockEl(id: string): HTMLElement | null }) {
@@ -169,6 +169,13 @@ function findTarget(ctx: EditorContextValue, x: number, y: number, src: Source):
169
169
 
170
170
  let el = doc.elementFromPoint(ix, iy) as HTMLElement | null;
171
171
  let blockEl = el?.closest<HTMLElement>("[data-ecx-block]") ?? null;
172
+ // Phần dùng chung (header / footer) có lớp phủ cùng cỡ nằm trên khối con: lấy khối SÂU nhất (theo DOM) dưới con trỏ
173
+ const domDepth = (b: HTMLElement) => { let n = 0; for (let p = b.parentElement; p; p = p.parentElement) if (p.hasAttribute("data-ecx-block")) n++; return n; };
174
+ let depth = blockEl ? domDepth(blockEl) : -1;
175
+ for (const e of doc.elementsFromPoint(ix, iy)) {
176
+ const b = (e as HTMLElement).closest<HTMLElement>("[data-ecx-block]");
177
+ if (b && domDepth(b) > depth) { blockEl = b; depth = domDepth(b); }
178
+ }
172
179
  // Không thả vào chính khối đang kéo / con của nó
173
180
  while (blockEl && src.ids.some((id) => blockEl!.dataset.ecxBlock === id || isInside(store, blockEl!.dataset.ecxBlock!, id))) {
174
181
  blockEl = blockEl.parentElement?.closest<HTMLElement>("[data-ecx-block]") ?? null;
@@ -0,0 +1,63 @@
1
+ import { useEffect, useRef, type KeyboardEvent, type ReactNode } from "react";
2
+ import type { BlockType, BlockLayout } from "../core/registry";
3
+ import { useMsgs } from "../i18n";
4
+
5
+ const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
6
+
7
+ /** Bản vẽ thu nhỏ của bố cục: nền xám nhạt cho chữ / khung, màu nhấn của trình soạn cho phần đang nổi bật. */
8
+ export function Thumb({ children }: { children: ReactNode }) {
9
+ return <svg className="ecx-vthumb" viewBox="0 0 96 64" aria-hidden="true" focusable="false">{children}</svg>;
10
+ }
11
+ export const bar = (x: number, y: number, w: number, h = 4, accent = false) => <rect key={`${x},${y},${w}`} x={x} y={y} width={w} height={h} rx={1.5} className={accent ? "is-accent" : undefined} />;
12
+ export const box = (x: number, y: number, w: number, h: number, accent = false) => <rect key={`b${x},${y},${w},${h}`} x={x} y={y} width={w} height={h} rx={3} className={cx("is-box", accent && "is-accent")} />;
13
+
14
+ /** Giá trị đang dùng (hoặc mặc định của thuộc tính) có khớp hết thuộc tính của bố cục không. */
15
+ export function variationMatches(type: BlockType | undefined, attrs: Record<string, unknown>, v: BlockLayout): boolean {
16
+ return Object.entries(v.attrs).every(([k, want]) => (attrs[k] ?? type?.attributes?.[k]?.default) === want);
17
+ }
18
+
19
+ /** Lưới thẻ bố cục: bấm một thẻ → áp thuộc tính của bố cục lên khối. Dùng cả ở bảng phải (đổi sau) lẫn ô chọn lúc vừa chèn. */
20
+ export function VariationGrid({ type, attrs, onPick, className }: { type?: BlockType; attrs: Record<string, unknown>; onPick(v: BlockLayout): void; className?: string }) {
21
+ const vs = type?.layouts ?? [];
22
+ if (!vs.length) return null;
23
+ /** Mũi tên di chuyển giữa các thẻ (như nhóm nút chọn chuẩn): thẻ đang được tick giữ tabindex 0, các thẻ còn lại -1. */
24
+ const arrows = (e: KeyboardEvent<HTMLDivElement>) => {
25
+ const keys = ["ArrowRight", "ArrowDown", "ArrowLeft", "ArrowUp", "Home", "End"];
26
+ if (!keys.includes(e.key)) return;
27
+ const btns = [...e.currentTarget.querySelectorAll<HTMLButtonElement>("button[role=radio]")];
28
+ const i = btns.indexOf(e.target as HTMLButtonElement);
29
+ if (i < 0) return;
30
+ e.preventDefault();
31
+ const next = e.key === "Home" ? 0 : e.key === "End" ? btns.length - 1 : (i + (e.key === "ArrowRight" || e.key === "ArrowDown" ? 1 : -1) + btns.length) % btns.length;
32
+ btns[next]?.focus();
33
+ };
34
+ const onIdx = vs.findIndex((v) => variationMatches(type, attrs, v));
35
+ return (
36
+ <div className={cx("ecx-variations", className)} role="radiogroup" onKeyDown={arrows}>
37
+ {vs.map((v, i) => {
38
+ const on = variationMatches(type, attrs, v);
39
+ return (
40
+ <button key={v.id} type="button" role="radio" aria-checked={on} tabIndex={i === Math.max(0, onIdx) ? 0 : -1} className={cx("ecx-variation", on && "is-active")} onMouseDown={(e) => e.preventDefault()} onClick={() => onPick(v)}>
41
+ {v.thumb}<span>{v.label}</span>
42
+ </button>
43
+ );
44
+ })}
45
+ </div>
46
+ );
47
+ }
48
+
49
+ /** Ô chọn bố cục đứng thế chỗ khối ngay sau khi chèn (như Kadence): chọn một thẻ hoặc "Bỏ qua" để dùng bố cục mặc định. */
50
+ export function VariationChooser({ type, attrs, onPick, onSkip, blockProps }: { type: BlockType; attrs: Record<string, unknown>; onPick(v: BlockLayout): void; onSkip(): void; blockProps: Record<string, unknown> }) {
51
+ const t = useMsgs("blocks") as Record<string, string>;
52
+ const box = useRef<HTMLDivElement | null>(null);
53
+ // Bàn phím: thẻ đầu nhận focus ngay khi ô chọn hiện (Enter / Space chọn, Esc bỏ qua)
54
+ useEffect(() => { box.current?.querySelector<HTMLButtonElement>("button[role=radio]")?.focus({ preventScroll: true }); }, []);
55
+ const ref = (el: HTMLDivElement | null) => { box.current = el; const r = (blockProps as { ref?: unknown }).ref; if (typeof r === "function") (r as (n: HTMLDivElement | null) => void)(el); else if (r && typeof r === "object") (r as { current: unknown }).current = el; };
56
+ return (
57
+ <div {...blockProps} ref={ref} onKeyDown={(e) => { if (e.key === "Escape") { e.preventDefault(); onSkip(); } }} className={cx((blockProps as { className?: string }).className, "ecx-variation-chooser")} contentEditable={false}>
58
+ <strong className="ecx-variation-title">{t.chooseLayout}</strong>
59
+ <VariationGrid type={type} attrs={attrs} onPick={onPick} />
60
+ <button type="button" className="ecx-variation-skip" onMouseDown={(e) => e.preventDefault()} onClick={onSkip}>{t.skipLayout}</button>
61
+ </div>
62
+ );
63
+ }
@@ -32,6 +32,9 @@ export class EditorUi {
32
32
  typing = false;
33
33
  /** Thu nhỏ: cả trang trong tầm nhìn, chỉ chọn / sắp xếp các phần (khối cấp cao nhất). */
34
34
  zoomOut = false;
35
+ /** Khối đang "xem trước khi rê chuột": khung soạn vẽ mọi quy tắc :hover của khối đó như đang rê (Kiểu dáng › Xem trước khi rê chuột). */
36
+ previewHoverId: string | null = null;
37
+ setPreviewHover(id: string | null) { if (this.previewHoverId !== id) { this.previewHoverId = id; this.bump(); } }
35
38
  /** Khổ màn hình đang soạn: khung soạn vẽ theo bề rộng này, tab Kiểu dáng sửa giá trị của khổ này (dùng chung, đổi một nơi thì nơi kia theo). */
36
39
  device: "desktop" | "tablet" | "mobile" = "desktop";
37
40
  setDevice(d: "desktop" | "tablet" | "mobile") { if (this.device !== d) { this.device = d; this.bump(); } }
@@ -66,6 +69,51 @@ export class EditorUi {
66
69
  return new DOMRect(f.left + r.left * scale, f.top + r.top * scale, r.width * scale, r.height * scale);
67
70
  }
68
71
  openInserter(req: InserterRequest | null) { this.inserter = req; this.bump(); }
72
+ /** Vẽ nội dung bằng khung soạn chỉ xem (tầng editor gán; ui không import editor): xem trước thật ở bảng chèn và thư viện mẫu. */
73
+ renderPreview: ((value: { version: number; blocks: unknown[] }) => ReactNode) | null = null;
74
+ /** Mục con đang chọn trong khối dạng danh sách (Icon List, Mạng xã hội…): khung soạn tô mục, bảng phải hiện cài đặt riêng của mục. */
75
+ activeItem = new Map<string, number>();
76
+ setActiveItem(blockId: string, i: number) { if (this.activeItem.get(blockId) !== i) { this.activeItem.set(blockId, i); this.bump(); } }
77
+ /** Khối vừa chèn còn chữ mẫu chưa sửa: bấm vào ô chữ lần đầu thì chọn hết để gõ là thay (không chèn thêm vào chữ mẫu). Bỏ cờ khi khối có thay đổi đầu tiên. */
78
+ fresh = new Set<string>();
79
+ /**
80
+ * Khối vừa chèn từ bảng chèn + vùng chọn "tự đến" sau đó (con trỏ vào ô chữ đầu của khối). Lần chèn kế tiếp, nếu người dùng chưa bấm chỗ khác,
81
+ * đặt khối mới NGAY SAU khối vừa chèn cùng cấp — thay vì lồng vào trong khối vừa chèn (vì con trỏ đang nằm sâu trong nó).
82
+ */
83
+ insertAnchor: { id: string; sel: string } | null = null;
84
+ /** Cầu nối tới vùng chọn hiện tại của store (EditorProvider gắn vào). */
85
+ currentIds: () => readonly string[] = () => [];
86
+ private anchorTimer: ReturnType<typeof setTimeout> | null = null;
87
+ markInsertAnchor(id: string, delay = 500) {
88
+ this.insertAnchor = null;
89
+ if (this.anchorTimer) clearTimeout(this.anchorTimer); // chèn nhanh nhiều khối: chỉ lần chèn cuối được đặt mốc
90
+ this.anchorTimer = setTimeout(() => { this.anchorTimer = null; this.insertAnchor = { id, sel: this.currentIds().join(",") }; }, delay);
91
+ }
92
+ /** Khối vừa chèn đang chờ chọn bố cục (không lưu vào nội dung). */
93
+ pickIds = new Set<string>();
94
+ requestPick(id: string) { this.pickIds.add(id); this.bump(); }
95
+ // Chọn / bỏ qua bố cục xong khối vẫn được chọn (bảng phải hiện lưới bố cục vừa chọn) — không đẩy con trỏ vào chữ
96
+ // `focus`: "Bỏ qua" = dùng bố cục mặc định và gõ luôn → con trỏ vào ô chữ đầu; chọn một thẻ thì giữ khối được chọn để bảng phải hiện thẻ đó
97
+ resolvePick(id: string, focus = false) { if (this.pickIds.delete(id)) { this.bump(); if (focus) { this.focusFirstField(id); this.markInsertAnchor(id, 450); } } }
98
+ /**
99
+ * Khối widget vừa chèn (Icon Box, Đếm số, Đánh giá…) có ô gõ ngay trên khối (ô chữ, không phải khối chữ) nên không tự nhận con trỏ như Đoạn văn:
100
+ * gõ ngay sau khi chèn không vào đâu. Đưa con trỏ vào ô chữ đầu tiên của khối (chữ mẫu đã chọn sẵn nên gõ là thay). Khối đang chờ chọn bố cục thì để ô chọn giữ focus.
101
+ */
102
+ focusFirstField(id: string) {
103
+ let tries = 0;
104
+ const attempt = () => {
105
+ if (this.pickIds.has(id)) return;
106
+ const el = this.blockEl(id);
107
+ if (!el) { if (++tries < 8) setTimeout(attempt, 40); return; }
108
+ const doc = el.ownerDocument, active = doc.activeElement as HTMLElement | null;
109
+ if (active && active !== doc.body && el.contains(active) && !active.closest(".ecx-variation-chooser")) return;
110
+ const field = el.querySelector<HTMLElement>('input[data-ecx-placeholder="text"], textarea[data-ecx-placeholder="text"], [contenteditable="true"]');
111
+ if (field && !field.closest("[data-ecx-inert]")) { field.focus({ preventScroll: true }); return; }
112
+ // Khối không có ô gõ (Ảnh, Khoảng trống, Cột…): đưa focus về khung soạn — nếu để ở nút của bảng chèn thì ⌘Z, Delete, mũi tên không tới trình soạn
113
+ (doc.querySelector<HTMLElement>(".ecx-canvas-root"))?.focus({ preventScroll: true });
114
+ };
115
+ setTimeout(attempt, 60);
116
+ }
69
117
  /** Thông báo cho trình đọc màn hình (vùng aria-live). */
70
118
  announcement = "";
71
119
  announce(text: string) { this.announcement = ""; this.bump(); setTimeout(() => { this.announcement = text; this.bump(); }, 30); }
@@ -1,3 +1,4 @@
1
+ import { CORE_BINDABLE as CONTENT_BINDABLE } from "@ecomcx/ecomweb-content";
1
2
  import { msgs } from "../../i18n";
2
3
  import type { DynamicData } from "./host";
3
4
  import type { BNode } from "./model";
@@ -24,7 +25,7 @@ export interface EditorBindingSource {
24
25
  export interface Binding { source: string; args?: Record<string, string | number | boolean> }
25
26
 
26
27
  /** Thuộc tính gắn được của khối lõi; khối plugin khai báo bằng BlockType.bindable. */
27
- export const CORE_BINDABLE: Record<string, string[]> = { paragraph: ["content"], heading: ["content"], image: ["src", "alt", "caption"], button: ["text", "href"] };
28
+ export const CORE_BINDABLE: Record<string, readonly string[]> = CONTENT_BINDABLE;
28
29
 
29
30
  const sources = new Map<string, EditorBindingSource>();
30
31
  const listeners = new Set<() => void>();
@@ -44,12 +45,16 @@ export function registerCoreBindingSources(lang: string) {
44
45
  fields: [
45
46
  { value: "title", label: t.fTitle }, { value: "excerpt", label: t.fExcerpt }, { value: "date", label: t.fDate },
46
47
  { value: "author", label: t.fAuthor }, { value: "link", label: t.fLink }, { value: "featuredImage", label: t.fFeaturedImage },
48
+ { value: "featuredImageAlt", label: t.fFeaturedImageAlt }, { value: "category", label: t.fCategory }, { value: "modified", label: t.fModified },
49
+ { value: "comments", label: t.fComments }, { value: "authorAvatar", label: t.fAuthorAvatar }, { value: "authorBio", label: t.fAuthorBio }, { value: "slug", label: t.fSlug }, { value: "id", label: "ID" },
47
50
  ],
48
51
  preview: (args, { dynamic }) => {
49
52
  const p = dynamic?.post;
50
53
  switch (args.field) {
51
54
  case "title": return p?.title; case "excerpt": return p?.excerpt; case "date": return p?.date; case "author": return p?.author;
52
55
  case "featuredImage": return p?.image ?? undefined; case "link": return "/…";
56
+ case "category": return p?.category; case "comments": return p?.comments === undefined ? undefined : String(p.comments);
57
+ case "modified": return p?.date; case "slug": return "slug-bai-viet"; case "id": return "123";
53
58
  default: return undefined;
54
59
  }
55
60
  },
@@ -50,6 +50,16 @@ export function withDefaults(node: BNode, map: BlockPresetMap | null): BNode {
50
50
  return { ...node, attrs };
51
51
  }
52
52
 
53
+ /**
54
+ * Kho kiểu đặt sẵn mặc định khi ứng dụng chủ không cung cấp `host.blockPresets`: lưu trong trình duyệt (mỗi máy một bộ),
55
+ * để "Kiểu / Đặt làm mặc định" luôn dùng được. Ứng dụng có máy chủ nên cung cấp kho riêng để theo cả website.
56
+ */
57
+ const LOCAL_KEY = "ecx-block-presets";
58
+ export const localBlockPresets = {
59
+ async load(): Promise<Record<string, unknown>> { try { return JSON.parse(localStorage.getItem(LOCAL_KEY) ?? "{}") ?? {}; } catch { return {}; } },
60
+ async save(map: Record<string, unknown>): Promise<Record<string, unknown>> { try { localStorage.setItem(LOCAL_KEY, JSON.stringify(map)); } catch { /* trình duyệt chặn bộ nhớ: giữ trong phiên */ } return map; },
61
+ };
62
+
53
63
  // Kho trong bộ nhớ (một lần nạp mỗi phiên soạn); UI đăng ký nghe thay đổi
54
64
  let current: BlockPresetMap | null = null;
55
65
  let loading: Promise<void> | null = null;
@@ -104,7 +104,7 @@ function blockOf(e: HTMLElement): RichNode | RichNode[] | null {
104
104
  const code = (e.textContent ?? "").replace(/\n$/, "");
105
105
  return { type: "codeBlock", ...(code ? { content: [{ type: "text", text: code }] } : {}) };
106
106
  }
107
- case "HR": return { type: "horizontalRule" };
107
+ case "HR": return { type: "spacer", attrs: { height: "md", line: true } };
108
108
  case "IMG": {
109
109
  const src = e.getAttribute("src") ?? "";
110
110
  return src && isSafeUrl(src) ? { type: "image", attrs: { src, alt: e.getAttribute("alt") ?? undefined } } : null;
@@ -205,12 +205,12 @@ export function richToHtml(nodes: RichNode[]): string {
205
205
  switch (n.type) {
206
206
  case "paragraph": return `<p>${inl(n.content)}</p>`;
207
207
  case "heading": return `<h${Number(n.attrs?.level) || 2}>${inl(n.content)}</h${Number(n.attrs?.level) || 2}>`;
208
- case "bulletList": case "taskList": return `<ul>${kids()}</ul>`;
208
+ case "bulletList": return `<ul>${kids()}</ul>`;
209
209
  case "orderedList": return `<ol>${kids()}</ol>`;
210
- case "listItem": case "taskItem": return `<li>${kids()}</li>`;
210
+ case "listItem": return `<li>${kids()}</li>`;
211
211
  case "blockquote": return `<blockquote>${kids()}</blockquote>`;
212
- case "codeBlock": case "preformatted": return `<pre>${esc((n.content ?? []).map((c) => c.text ?? "").join(""))}</pre>`;
213
- case "horizontalRule": return "<hr>";
212
+ case "codeBlock": return `<pre>${esc((n.content ?? []).map((c) => c.text ?? "").join(""))}</pre>`;
213
+ case "spacer": return n.attrs?.line === true ? "<hr>" : "";
214
214
  case "image": return typeof n.attrs?.src === "string" && isSafeUrl(n.attrs.src) ? `<img src="${esc(n.attrs.src)}" alt="${esc(String(n.attrs.alt ?? ""))}">` : "";
215
215
  case "table": return `<table>${kids()}</table>`;
216
216
  case "tableRow": return `<tr>${kids()}</tr>`;
@@ -43,6 +43,8 @@ export interface EditorHost {
43
43
  renderBlock?(node: { type: string; attrs?: Record<string, unknown>; content?: unknown[] }): Promise<string | null>;
44
44
  /** Nơi đang soạn: "template" = template / phần dùng chung của theme (chèn được khối riêng của theme); mặc định = nội dung bài. */
45
45
  scope?: "template" | "content";
46
+ /** Chỉ cho thử nghiệm / playground: hiện cả khối cũ đã gộp (người dùng thật không bao giờ thấy). */
47
+ showAllBlocks?: boolean;
46
48
  /** Preset của theme (biến --ecx-*). */
47
49
  presets?: StylePresets;
48
50
  /**
@@ -102,7 +104,7 @@ export interface DocumentHost {
102
104
  export type DynamicPost = { title?: string; date?: string; author?: string; excerpt?: string; image?: string | null; terms?: string[]; /** Chuyên mục đầu tiên (breadcrumb như website); không có = bài/trang không thuộc chuyên mục nào. */ category?: string; comments?: number; link?: string; /** Nội dung đã lưu của bài (ContentDoc) — khối "Nội dung bài" trong template vẽ nội dung thật thay vì khung giữ chỗ. */ content?: unknown };
103
105
 
104
106
  /** Thiết lập của khối "Danh sách bài" (attrs của query). */
105
- export interface QueryArgs { inherit: boolean; postType: string; perPage: number; category?: string; tag?: string; orderBy: string; order: "asc" | "desc" }
107
+ export interface QueryArgs { inherit: boolean; postType: string; perPage: number; category?: string; tag?: string; taxonomy?: string; term?: string; orderBy: string; order: "asc" | "desc" }
106
108
 
107
109
  export type ChoiceKind = "menuLocation" | "postType" | "taxonomy" | "term" | "templatePart" | "imageSize";
108
110
  export interface Choice { value: string; label: string }
@@ -28,14 +28,14 @@ export const newId = () => `b${prefix}${(++seq).toString(36)}`;
28
28
 
29
29
  /** Các loại khối của lõi theo cách chứa nội dung. Khối lạ (plugin) suy từ nội dung. */
30
30
  const CORE_KINDS: Record<string, BlockKind> = {
31
- paragraph: "text", heading: "text", codeBlock: "text", preformatted: "text",
32
- bulletList: "container", orderedList: "container", listItem: "container", taskList: "container", taskItem: "container",
33
- blockquote: "container", columns: "container", column: "container", group: "container", callout: "container",
34
- buttons: "container", cover: "container", mediaText: "container", pullquote: "text", details: "container", accordion: "container", tabs: "container", tab: "container", carousel: "container",
31
+ paragraph: "text", heading: "text", codeBlock: "text",
32
+ bulletList: "container", orderedList: "container", listItem: "container",
33
+ blockquote: "container", columns: "container", column: "container", group: "container",
34
+ buttons: "container", cover: "container", details: "container", testimonials: "container", popup: "container", accordion: "container", tabs: "container", tab: "container", carousel: "container",
35
35
  table: "container", tableRow: "container", tableCell: "container", tableHeader: "container",
36
36
  query: "container", postTemplate: "container", queryEmpty: "container", stack: "container",
37
- horizontalRule: "atom", image: "atom", gallery: "atom", video: "atom", audio: "atom", file: "atom", youtube: "atom",
38
- button: "atom", embed: "atom", spacer: "atom", customHtml: "atom", socialLinks: "atom", tableOfContents: "atom", countdown: "atom", rating: "atom", shortcode: "atom",
37
+ image: "atom", gallery: "atom", video: "atom", audio: "atom", file: "atom",
38
+ button: "atom", embed: "atom", spacer: "atom", customHtml: "atom", socialLinks: "atom", tableOfContents: "atom", countdown: "atom", shortcode: "atom",
39
39
  };
40
40
  const kindOverrides = new Map<string, BlockKind>();
41
41
  export function setBlockKind(type: string, kind: BlockKind) { kindOverrides.set(type, kind); }
@@ -37,6 +37,8 @@ export interface BlockVariation {
37
37
  create?(): BNode;
38
38
  /** Hiện trong thư viện khối bằng tên riêng (vd "Hàng ngang") thay vì "tên khối + tên biến thể". */
39
39
  standalone?: boolean;
40
+ /** Ô cũ đã gộp vào khối cha (ô chọn bố cục / kiểu): ẩn khỏi bảng chèn, chỉ hiện khi host.showAllBlocks. */
41
+ legacy?: boolean;
40
42
  /** Biến thể đang áp dụng cho khối này (hiện tên/biểu tượng đúng biến thể). */
41
43
  isActive?(attrs: Record<string, any>): boolean;
42
44
  }
@@ -59,7 +61,11 @@ export interface BlockType {
59
61
  category?: BlockCategory;
60
62
  /** Từ khoá tìm (không dấu). */
61
63
  keywords?: string;
64
+ /** Tên khác (vd tên tiếng Việt cũ) — tìm bằng tên này vẫn ra khối ở hạng như tên chính. */
65
+ aliases?: string[];
62
66
  kind: BlockKind;
67
+ /** Tên hiện ở bảng bên phải / đường dẫn theo thuộc tính (vd Nhóm rộng hết trang có khung nội dung là "Section"); undefined → dùng `title`. */
68
+ titleOf?(attrs: Record<string, unknown>): string | undefined;
63
69
  /** Thuộc tính gắn dữ liệu được (attrs.bindings) — khối lõi: CORE_BINDABLE. */
64
70
  bindable?: string[];
65
71
  attributes?: Record<string, BlockAttrSpec>;
@@ -102,8 +108,17 @@ export interface BlockType {
102
108
  supports?: { style?: boolean | string[]; anchor?: boolean; className?: boolean; blockStyle?: boolean; align?: boolean };
103
109
  /** Tóm tắt một dòng (cây khối, khung chung). */
104
110
  summary?(attrs: Record<string, any>): string | undefined;
111
+ /** Bố cục chọn sẵn (thẻ có hình thu nhỏ): hiện ngay sau khi chèn từ bảng chèn và ở đầu bảng phải. */
112
+ layouts?: BlockLayout[];
113
+ /** false = chỉ hiện lưới bố cục ở bảng phải, không bật ô chọn ngay sau khi chèn (khối nhỏ, bố cục đổi nhẹ). Mặc định: bật. */
114
+ layoutsOnInsert?: boolean;
115
+ /** Thuộc tính chỉ chỉnh bằng thẻ bố cục (mọi giá trị đều có thẻ): ẩn ô chọn trùng ở dưới để một việc chỉ có một chỗ chỉnh. */
116
+ layoutOwns?: string[];
105
117
  }
106
118
 
119
+ /** Một bố cục chọn sẵn của khối: áp `attrs` lên khối; `thumb` là bản vẽ thu nhỏ (xem ui/variation-picker). */
120
+ export interface BlockLayout { id: string; label: string; attrs: Record<string, unknown>; thumb: ReactNode }
121
+
107
122
  export class BlockTypeRegistry {
108
123
  private types = new Map<string, BlockType>();
109
124
  private listeners = new Set<() => void>();