@enyxs/wikex-components 0.11.19 → 0.11.21
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/dist/index.d.mts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +160 -96
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +161 -97
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/README.md +0 -146
package/dist/index.d.mts
CHANGED
|
@@ -84,6 +84,7 @@ type CmsTextMark = {
|
|
|
84
84
|
start: number;
|
|
85
85
|
end: number;
|
|
86
86
|
bold?: boolean;
|
|
87
|
+
italic?: boolean;
|
|
87
88
|
underline?: boolean;
|
|
88
89
|
href?: string;
|
|
89
90
|
newTab?: boolean;
|
|
@@ -95,10 +96,11 @@ type CmsRichText = {
|
|
|
95
96
|
declare function safeCmsTextHref(value: string): string | undefined;
|
|
96
97
|
declare function parseCmsRichText(value: unknown): CmsRichText | undefined;
|
|
97
98
|
declare function rebaseCmsRichText(value: unknown, text: string): CmsRichText;
|
|
98
|
-
declare function patchCmsRichText(value: unknown, text: string, start: number, end: number, patch: Partial<Pick<CmsTextMark, 'bold' | 'underline' | 'href'>>): CmsRichText;
|
|
99
|
+
declare function patchCmsRichText(value: unknown, text: string, start: number, end: number, patch: Partial<Pick<CmsTextMark, 'bold' | 'italic' | 'underline' | 'href'>>): CmsRichText;
|
|
99
100
|
declare function renderCmsRichText(children: ReactNode, value: unknown, allowLinks?: boolean): ReactNode;
|
|
100
101
|
|
|
101
102
|
declare const CMS_TEXT_FONTS: {
|
|
103
|
+
readonly 'Inter, sans-serif': "Inter";
|
|
102
104
|
readonly 'Arial, sans-serif': "Arial";
|
|
103
105
|
readonly 'Georgia, serif': "Georgia";
|
|
104
106
|
readonly '"Times New Roman", serif': "Times New Roman";
|
|
@@ -110,6 +112,9 @@ type CmsTextLayout = {
|
|
|
110
112
|
height?: number;
|
|
111
113
|
fontFamily?: string;
|
|
112
114
|
fontSize?: number;
|
|
115
|
+
lineHeight?: number;
|
|
116
|
+
textAlign?: "left" | "center" | "right";
|
|
117
|
+
listType?: "ul" | "ol";
|
|
113
118
|
richText?: CmsRichText;
|
|
114
119
|
blockType?: "p" | "h1" | "h2" | "h3" | "ul" | "ol";
|
|
115
120
|
};
|
|
@@ -127,11 +132,14 @@ type CmsTextToolbarProps = {
|
|
|
127
132
|
inlineControls?: ReactNode;
|
|
128
133
|
structureControls?: ReactNode;
|
|
129
134
|
computedFontSize?: number;
|
|
130
|
-
|
|
135
|
+
computedLineHeight?: number;
|
|
136
|
+
computedFontFamily?: string;
|
|
137
|
+
computedTextAlign?: string;
|
|
138
|
+
onLayoutChange: (change: Pick<CmsTextLayout, "fontFamily" | "fontSize" | "lineHeight" | "textAlign">) => void;
|
|
131
139
|
onColorChange: (color: string) => void;
|
|
132
140
|
onReset: () => void;
|
|
133
141
|
};
|
|
134
|
-
declare function CmsTextToolbar({ layout, color, colorPicker, inlineControls, structureControls, computedFontSize, onLayoutChange, onColorChange, onReset }: CmsTextToolbarProps): react.JSX.Element;
|
|
142
|
+
declare function CmsTextToolbar({ layout, color, colorPicker, inlineControls, structureControls, computedFontSize, computedLineHeight, computedFontFamily, computedTextAlign, onLayoutChange, onColorChange, onReset }: CmsTextToolbarProps): react.JSX.Element;
|
|
135
143
|
|
|
136
144
|
declare const CMS_ELEMENTS_FIELD = "__cmsElements";
|
|
137
145
|
type CmsElementState = {
|
package/dist/index.d.ts
CHANGED
|
@@ -84,6 +84,7 @@ type CmsTextMark = {
|
|
|
84
84
|
start: number;
|
|
85
85
|
end: number;
|
|
86
86
|
bold?: boolean;
|
|
87
|
+
italic?: boolean;
|
|
87
88
|
underline?: boolean;
|
|
88
89
|
href?: string;
|
|
89
90
|
newTab?: boolean;
|
|
@@ -95,10 +96,11 @@ type CmsRichText = {
|
|
|
95
96
|
declare function safeCmsTextHref(value: string): string | undefined;
|
|
96
97
|
declare function parseCmsRichText(value: unknown): CmsRichText | undefined;
|
|
97
98
|
declare function rebaseCmsRichText(value: unknown, text: string): CmsRichText;
|
|
98
|
-
declare function patchCmsRichText(value: unknown, text: string, start: number, end: number, patch: Partial<Pick<CmsTextMark, 'bold' | 'underline' | 'href'>>): CmsRichText;
|
|
99
|
+
declare function patchCmsRichText(value: unknown, text: string, start: number, end: number, patch: Partial<Pick<CmsTextMark, 'bold' | 'italic' | 'underline' | 'href'>>): CmsRichText;
|
|
99
100
|
declare function renderCmsRichText(children: ReactNode, value: unknown, allowLinks?: boolean): ReactNode;
|
|
100
101
|
|
|
101
102
|
declare const CMS_TEXT_FONTS: {
|
|
103
|
+
readonly 'Inter, sans-serif': "Inter";
|
|
102
104
|
readonly 'Arial, sans-serif': "Arial";
|
|
103
105
|
readonly 'Georgia, serif': "Georgia";
|
|
104
106
|
readonly '"Times New Roman", serif': "Times New Roman";
|
|
@@ -110,6 +112,9 @@ type CmsTextLayout = {
|
|
|
110
112
|
height?: number;
|
|
111
113
|
fontFamily?: string;
|
|
112
114
|
fontSize?: number;
|
|
115
|
+
lineHeight?: number;
|
|
116
|
+
textAlign?: "left" | "center" | "right";
|
|
117
|
+
listType?: "ul" | "ol";
|
|
113
118
|
richText?: CmsRichText;
|
|
114
119
|
blockType?: "p" | "h1" | "h2" | "h3" | "ul" | "ol";
|
|
115
120
|
};
|
|
@@ -127,11 +132,14 @@ type CmsTextToolbarProps = {
|
|
|
127
132
|
inlineControls?: ReactNode;
|
|
128
133
|
structureControls?: ReactNode;
|
|
129
134
|
computedFontSize?: number;
|
|
130
|
-
|
|
135
|
+
computedLineHeight?: number;
|
|
136
|
+
computedFontFamily?: string;
|
|
137
|
+
computedTextAlign?: string;
|
|
138
|
+
onLayoutChange: (change: Pick<CmsTextLayout, "fontFamily" | "fontSize" | "lineHeight" | "textAlign">) => void;
|
|
131
139
|
onColorChange: (color: string) => void;
|
|
132
140
|
onReset: () => void;
|
|
133
141
|
};
|
|
134
|
-
declare function CmsTextToolbar({ layout, color, colorPicker, inlineControls, structureControls, computedFontSize, onLayoutChange, onColorChange, onReset }: CmsTextToolbarProps): react.JSX.Element;
|
|
142
|
+
declare function CmsTextToolbar({ layout, color, colorPicker, inlineControls, structureControls, computedFontSize, computedLineHeight, computedFontFamily, computedTextAlign, onLayoutChange, onColorChange, onReset }: CmsTextToolbarProps): react.JSX.Element;
|
|
135
143
|
|
|
136
144
|
declare const CMS_ELEMENTS_FIELD = "__cmsElements";
|
|
137
145
|
type CmsElementState = {
|
package/dist/index.js
CHANGED
|
@@ -274,8 +274,7 @@ function CmsAddedElements({ field }) {
|
|
|
274
274
|
value: context.content[item.field] ?? "",
|
|
275
275
|
component: "p",
|
|
276
276
|
sx: {
|
|
277
|
-
font: "inherit"
|
|
278
|
-
my: 1
|
|
277
|
+
font: "inherit"
|
|
279
278
|
},
|
|
280
279
|
editable: context.editable,
|
|
281
280
|
onChange: context.onChange
|
|
@@ -290,9 +289,9 @@ function CmsTextList({ field, type, children }) {
|
|
|
290
289
|
});
|
|
291
290
|
}
|
|
292
291
|
var NativeList = import_styled_components2.default.ul.withConfig({
|
|
293
|
-
componentId: "sc-
|
|
292
|
+
componentId: "sc-4154c689-0"
|
|
294
293
|
})([
|
|
295
|
-
|
|
294
|
+
`> li{display:list-item !important;padding-left:0 !important;}> li::before{content:none !important;}`
|
|
296
295
|
]);
|
|
297
296
|
function CmsTemplateList({ cmsAs, cmsId, children }) {
|
|
298
297
|
const context = (0, import_react.useContext)(ElementContext);
|
|
@@ -319,7 +318,8 @@ function CmsTemplateList({ cmsAs, cmsId, children }) {
|
|
|
319
318
|
const text = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EditableText, {
|
|
320
319
|
component: "span",
|
|
321
320
|
sx: {
|
|
322
|
-
font: "inherit"
|
|
321
|
+
font: "inherit",
|
|
322
|
+
display: "block"
|
|
323
323
|
},
|
|
324
324
|
field: added.field,
|
|
325
325
|
value: context?.content[added.field] ?? "M\u1EE5c m\u1EDBi",
|
|
@@ -336,7 +336,8 @@ function CmsTemplateList({ cmsAs, cmsId, children }) {
|
|
|
336
336
|
if (!items.length) return null;
|
|
337
337
|
return /* @__PURE__ */ (0, import_react.createElement)(stored?.type || stored?.marker ? NativeList : cmsAs, {
|
|
338
338
|
...stored?.type || stored?.marker ? {
|
|
339
|
-
as:
|
|
339
|
+
as: cmsAs,
|
|
340
|
+
forwardedAs: stored?.type ?? (stored?.marker === "decimal" || stored?.marker === "lower-alpha" || stored?.marker === "lower-roman" ? "ol" : "ul"),
|
|
340
341
|
style: {
|
|
341
342
|
listStyleType: stored?.marker ?? (stored?.type === "ol" ? "decimal" : "disc")
|
|
342
343
|
}
|
|
@@ -382,9 +383,10 @@ function parseCmsRichText(value4) {
|
|
|
382
383
|
if (!mark || !Number.isInteger(mark.start) || !Number.isInteger(mark.end) || mark.start < 0 || mark.end <= mark.start || mark.end > raw.text.length) continue;
|
|
383
384
|
const next = { start: mark.start, end: mark.end };
|
|
384
385
|
if (typeof mark.bold === "boolean") next.bold = mark.bold;
|
|
386
|
+
if (typeof mark.italic === "boolean") next.italic = mark.italic;
|
|
385
387
|
if (typeof mark.underline === "boolean") next.underline = mark.underline;
|
|
386
388
|
if (typeof mark.href === "string") next.href = safeCmsTextHref(mark.href);
|
|
387
|
-
if (next.bold !== void 0 || next.underline !== void 0 || next.href) marks.push(next);
|
|
389
|
+
if (next.bold !== void 0 || next.italic !== void 0 || next.underline !== void 0 || next.href) marks.push(next);
|
|
388
390
|
}
|
|
389
391
|
return { text: raw.text, marks };
|
|
390
392
|
}
|
|
@@ -420,10 +422,10 @@ function patchCmsRichText(value4, text, start, end, patch) {
|
|
|
420
422
|
const style = {};
|
|
421
423
|
rich.marks.filter((m) => m.start <= a && m.end >= b).forEach((m) => Object.assign(style, m));
|
|
422
424
|
if (a >= start && b <= end) Object.assign(style, patch);
|
|
423
|
-
const next = { start: a, end: b, bold: style.bold, underline: style.underline, newTab: style.newTab, href: style.href ? safeCmsTextHref(style.href) : void 0 };
|
|
424
|
-
if (next.bold === void 0 && next.underline === void 0 && !next.href) continue;
|
|
425
|
+
const next = { start: a, end: b, bold: style.bold, italic: style.italic, underline: style.underline, newTab: style.newTab, href: style.href ? safeCmsTextHref(style.href) : void 0 };
|
|
426
|
+
if (next.bold === void 0 && next.italic === void 0 && next.underline === void 0 && !next.href) continue;
|
|
425
427
|
const previous = marks[marks.length - 1];
|
|
426
|
-
if (previous && previous.end === a && previous.bold === next.bold && previous.underline === next.underline && previous.href === next.href && previous.newTab === next.newTab) previous.end = b;
|
|
428
|
+
if (previous && previous.end === a && previous.bold === next.bold && previous.italic === next.italic && previous.underline === next.underline && previous.href === next.href && previous.newTab === next.newTab) previous.end = b;
|
|
427
429
|
else marks.push(next);
|
|
428
430
|
}
|
|
429
431
|
return { text, marks };
|
|
@@ -447,9 +449,10 @@ function renderCmsRichText(children, value4, allowLinks = true) {
|
|
|
447
449
|
const end = points[index + 1];
|
|
448
450
|
const mark = Object.assign({}, ...rich.marks.filter((m) => m.start <= start && m.end >= end));
|
|
449
451
|
const part = text.slice(start - base, end - base);
|
|
450
|
-
if (mark.bold === void 0 && mark.underline === void 0 && !mark.href) return part;
|
|
452
|
+
if (mark.bold === void 0 && mark.italic === void 0 && mark.underline === void 0 && !mark.href) return part;
|
|
451
453
|
const style = {
|
|
452
454
|
...mark.bold !== void 0 ? { fontWeight: mark.bold ? 700 : 400 } : {},
|
|
455
|
+
...mark.italic !== void 0 ? { fontStyle: mark.italic ? "italic" : "normal" } : {},
|
|
453
456
|
...mark.underline !== void 0 ? { textDecorationLine: mark.underline ? "underline" : "none" } : {}
|
|
454
457
|
};
|
|
455
458
|
return mark.href && links ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { href: mark.href, target: mark.newTab ? "_blank" : void 0, rel: mark.newTab ? "noopener noreferrer" : void 0, style: { color: "inherit", textDecoration: "underline", ...style }, children: part }, start) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style, children: part }, start);
|
|
@@ -469,6 +472,7 @@ function renderCmsRichText(children, value4, allowLinks = true) {
|
|
|
469
472
|
|
|
470
473
|
// src/shared/text-layout.ts
|
|
471
474
|
var CMS_TEXT_FONTS = {
|
|
475
|
+
"Inter, sans-serif": "Inter",
|
|
472
476
|
"Arial, sans-serif": "Arial",
|
|
473
477
|
"Georgia, serif": "Georgia",
|
|
474
478
|
'"Times New Roman", serif': "Times New Roman",
|
|
@@ -487,6 +491,9 @@ function parseCmsTextLayout(value4) {
|
|
|
487
491
|
if (typeof parsed.fontFamily === "string" && Object.prototype.hasOwnProperty.call(CMS_TEXT_FONTS, parsed.fontFamily)) layout.fontFamily = parsed.fontFamily;
|
|
488
492
|
if (typeof parsed.fontSize === "number" && Number.isFinite(parsed.fontSize) && parsed.fontSize >= 8 && parsed.fontSize <= 300) layout.fontSize = parsed.fontSize;
|
|
489
493
|
if (["p", "h1", "h2", "h3", "ul", "ol"].includes(parsed.blockType)) layout.blockType = parsed.blockType;
|
|
494
|
+
if (typeof parsed.lineHeight === "number" && Number.isFinite(parsed.lineHeight) && parsed.lineHeight >= 0.5 && parsed.lineHeight <= 5) layout.lineHeight = parsed.lineHeight;
|
|
495
|
+
if (["left", "center", "right"].includes(parsed.textAlign)) layout.textAlign = parsed.textAlign;
|
|
496
|
+
if (["ul", "ol"].includes(parsed.listType)) layout.listType = parsed.listType;
|
|
490
497
|
const richText = parseCmsRichText(parsed.richText);
|
|
491
498
|
if (richText) layout.richText = richText;
|
|
492
499
|
return layout;
|
|
@@ -495,11 +502,13 @@ function parseCmsTextLayout(value4) {
|
|
|
495
502
|
}
|
|
496
503
|
}
|
|
497
504
|
function cmsTextLayoutStyle(value4, templateBlock = false) {
|
|
498
|
-
const { width, height, fontFamily, fontSize, blockType } = parseCmsTextLayout(value4);
|
|
505
|
+
const { width, height, fontFamily, fontSize, blockType, lineHeight, textAlign } = parseCmsTextLayout(value4);
|
|
499
506
|
return {
|
|
500
|
-
...blockType && !templateBlock ? { fontSize: blockType === "h1" ? "2rem" : blockType === "h2" ? "1.5rem" : blockType === "h3" ? "1.25rem" : "1rem", fontWeight: blockType.startsWith("h") ? 700 : 400, lineHeight: 1.5 } : {},
|
|
507
|
+
...blockType && blockType !== "ul" && blockType !== "ol" && !templateBlock ? { fontSize: blockType === "h1" ? "2rem" : blockType === "h2" ? "1.5rem" : blockType === "h3" ? "1.25rem" : "1rem", fontWeight: blockType.startsWith("h") ? 700 : 400, lineHeight: 1.5 } : {},
|
|
501
508
|
...fontFamily ? { fontFamily } : {},
|
|
502
|
-
...fontSize ? { fontSize: `${fontSize}px
|
|
509
|
+
...fontSize ? { fontSize: `${fontSize}px` } : {},
|
|
510
|
+
...lineHeight ? { lineHeight } : {},
|
|
511
|
+
...textAlign ? { textAlign, justifyContent: textAlign === "center" ? "center" : textAlign === "right" ? "flex-end" : "flex-start" } : {},
|
|
503
512
|
whiteSpace: "pre-wrap",
|
|
504
513
|
overflowWrap: "anywhere",
|
|
505
514
|
...width !== void 0 || height !== void 0 ? {
|
|
@@ -513,8 +522,8 @@ function cmsTextLayoutStyle(value4, templateBlock = false) {
|
|
|
513
522
|
function applyCmsTextLayout(element, value4) {
|
|
514
523
|
const styles = cmsTextLayoutStyle(value4);
|
|
515
524
|
const view = element.ownerDocument.defaultView;
|
|
516
|
-
if ((styles.width || styles.minHeight) && view?.getComputedStyle(element).display === "inline") {
|
|
517
|
-
styles.display = "inline-block";
|
|
525
|
+
if ((styles.textAlign || styles.width || styles.minHeight) && view?.getComputedStyle(element).display === "inline") {
|
|
526
|
+
styles.display = styles.textAlign ? "block" : "inline-block";
|
|
518
527
|
}
|
|
519
528
|
const previous = Object.keys(styles).map((key) => {
|
|
520
529
|
const property = key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
@@ -589,10 +598,12 @@ function EditableText({
|
|
|
589
598
|
}) {
|
|
590
599
|
const colorContext = (0, import_react4.useContext)(getTextColorContext());
|
|
591
600
|
const hidden = useCmsElementHidden(field);
|
|
592
|
-
const
|
|
601
|
+
const metadata = parseCmsTextLayout(colorContext?.content[`${field}TextLayout`]);
|
|
602
|
+
const legacyList = metadata.blockType === "ul" || metadata.blockType === "ol" ? metadata.blockType : void 0;
|
|
603
|
+
const listType = metadata.listType ?? legacyList;
|
|
604
|
+
const block = legacyList ? void 0 : metadata.blockType;
|
|
593
605
|
const templateBlock = useCmsTextBlock(block);
|
|
594
606
|
if (hidden) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CmsAddedElements, { field });
|
|
595
|
-
const isList = block === "ul" || block === "ol";
|
|
596
607
|
const colorValue = colorContext?.content[`${field}Color`];
|
|
597
608
|
const color = validTextColor(colorValue) ? colorValue : void 0;
|
|
598
609
|
const selected = editable && colorContext?.selectedTextField === field;
|
|
@@ -601,7 +612,7 @@ function EditableText({
|
|
|
601
612
|
"data-cms-text-field": field,
|
|
602
613
|
"data-cms-text-rendered": "true",
|
|
603
614
|
contentEditable: editable ? "plaintext-only" : false,
|
|
604
|
-
style: cmsTextLayoutStyle(colorContext?.content[`${field}TextLayout`], Boolean(templateBlock)),
|
|
615
|
+
style: { ...cmsTextLayoutStyle(colorContext?.content[`${field}TextLayout`], Boolean(templateBlock)), ...metadata.textAlign && !templateBlock ? { display: "block" } : {} },
|
|
605
616
|
suppressContentEditableWarning: true,
|
|
606
617
|
onBlur: (event) => onChange?.(field, readCmsEditableText(event.currentTarget)),
|
|
607
618
|
onClick: (event) => {
|
|
@@ -624,15 +635,16 @@ function EditableText({
|
|
|
624
635
|
"&:focus": { boxShadow: "0 0 0 2px #00A76F" }
|
|
625
636
|
}
|
|
626
637
|
},
|
|
638
|
+
...listType ? [{ font: "inherit", display: "block" }] : [],
|
|
627
639
|
...!templateBlock ? Array.isArray(sx) ? sx : sx ? [sx] : [] : [],
|
|
628
640
|
...color ? [{ color }] : [],
|
|
629
641
|
...selected ? [{ outline: "2px solid #00A76F", outlineOffset: 2 }] : []
|
|
630
642
|
],
|
|
631
643
|
children: renderCmsRichText(value4, parseCmsTextLayout(colorContext?.content[`${field}TextLayout`]).richText, component !== "a" && component !== "button")
|
|
632
644
|
};
|
|
633
|
-
const rendered = templateBlock ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_Box.default, { component: templateBlock, ...textProps }, String(value4 ?? "")) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_Typography.default, { component:
|
|
645
|
+
const rendered = templateBlock ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_Box.default, { component: templateBlock, ...textProps }, String(value4 ?? "")) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_Typography.default, { component: block ?? (listType ? "span" : component) ?? "div", variant, ...textProps }, String(value4 ?? ""));
|
|
634
646
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
635
|
-
|
|
647
|
+
listType ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CmsTextList, { field, type: listType, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { children: rendered }) }) : rendered,
|
|
636
648
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CmsAddedElements, { field })
|
|
637
649
|
] });
|
|
638
650
|
}
|
|
@@ -3595,16 +3607,20 @@ function ExactText({ cmsAs, children, style, cmsDefaultRichText, cmsField, ...pr
|
|
|
3595
3607
|
const entry = explicitField ? { field: explicitField, layout: content?.[`${explicitField}TextLayout`], color: typeof content?.[`${explicitField}Color`] === "string" ? String(content[`${explicitField}Color`]) : void 0 } : entries.get(normalize(plainText(children)));
|
|
3596
3608
|
if (explicitField && content?.[explicitField] !== void 0) children = String(content[explicitField]);
|
|
3597
3609
|
const hidden = useCmsElementHidden(entry?.field);
|
|
3598
|
-
const
|
|
3610
|
+
const metadata = parseCmsTextLayout(entry?.layout);
|
|
3611
|
+
const legacyList = metadata.blockType === "ul" || metadata.blockType === "ol" ? metadata.blockType : void 0;
|
|
3612
|
+
const listType = metadata.listType ?? legacyList;
|
|
3613
|
+
const block = legacyList ? void 0 : metadata.blockType;
|
|
3614
|
+
const listItem = cmsAs === "li" && Boolean(block);
|
|
3599
3615
|
const templateBlock = useCmsTextBlock(block);
|
|
3600
3616
|
if (hidden) return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CmsAddedElements, { field: entry?.field });
|
|
3601
|
-
const
|
|
3602
|
-
const host = block ? isList ? "li" : block : cmsAs;
|
|
3617
|
+
const host = block ?? (listType ? "span" : cmsAs);
|
|
3603
3618
|
const layout = entry ? cmsTextLayoutStyle(entry.layout, Boolean(templateBlock)) : void 0;
|
|
3604
3619
|
const sized = layout?.width || layout?.minHeight;
|
|
3605
3620
|
const rendered = (0, import_react9.createElement)(templateBlock ?? (typeof cmsAs === "string" ? host : cmsAs), {
|
|
3606
3621
|
...block && !templateBlock && typeof cmsAs !== "string" ? { as: host } : {},
|
|
3607
3622
|
...props,
|
|
3623
|
+
...listItem ? { "data-cms-list-item": void 0 } : {},
|
|
3608
3624
|
// Replace the edited host when plain text changes; browser-created text nodes
|
|
3609
3625
|
// must not be reconciled against the previous annotation tree.
|
|
3610
3626
|
key: plainText(children),
|
|
@@ -3613,11 +3629,11 @@ function ExactText({ cmsAs, children, style, cmsDefaultRichText, cmsField, ...pr
|
|
|
3613
3629
|
"data-cms-text-rendered": "true",
|
|
3614
3630
|
"data-cms-text-default-rich": cmsDefaultRichText ? JSON.stringify(cmsDefaultRichText) : void 0,
|
|
3615
3631
|
"data-cms-text-sized": sized ? "true" : void 0,
|
|
3616
|
-
style: { ...style, ...layout, ...entry.color ? { color: entry.color } : {} }
|
|
3632
|
+
style: { ...style, ...layout, ...metadata.textAlign && host === "span" ? { display: "block" } : {}, ...entry.color ? { color: entry.color } : {} }
|
|
3617
3633
|
} : { style }
|
|
3618
3634
|
}, entry ? renderCmsRichText(children, parseCmsTextLayout(entry.layout).richText ?? cmsDefaultRichText, cmsAs !== "a" && cmsAs !== "button" && !props.href) : children);
|
|
3619
3635
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
3620
|
-
|
|
3636
|
+
listType && entry ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CmsTextList, { field: entry.field, type: listType, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("li", { children: rendered }) }) : listItem ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("li", { "data-cms-list-item": props["data-cms-list-item"], children: rendered }) : rendered,
|
|
3621
3637
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CmsAddedElements, { field: entry?.field })
|
|
3622
3638
|
] });
|
|
3623
3639
|
}
|
|
@@ -16579,10 +16595,28 @@ var wikexCommodityRoutes = wikexCommodityPageTemplates.map(({ route, slug, key }
|
|
|
16579
16595
|
var import_react36 = require("react");
|
|
16580
16596
|
var import_material = require("@mui/material");
|
|
16581
16597
|
var import_jsx_runtime56 = require("react/jsx-runtime");
|
|
16582
|
-
function CmsTextToolbar({ layout, color, colorPicker, inlineControls, structureControls, computedFontSize, onLayoutChange, onColorChange, onReset }) {
|
|
16598
|
+
function CmsTextToolbar({ layout, color, colorPicker, inlineControls, structureControls, computedFontSize, computedLineHeight, computedFontFamily, computedTextAlign, onLayoutChange, onColorChange, onReset }) {
|
|
16583
16599
|
const toolbarRef = (0, import_react36.useRef)(null);
|
|
16584
16600
|
const [hex, setHex] = (0, import_react36.useState)(color);
|
|
16585
16601
|
const displayedSize = String(computedFontSize ?? layout.fontSize ?? 16);
|
|
16602
|
+
const displayedLineHeight = String(layout.lineHeight ?? computedLineHeight ?? 1.5);
|
|
16603
|
+
const dirtyLineHeight = (0, import_react36.useRef)(false);
|
|
16604
|
+
const [lineHeight, setLineHeight] = (0, import_react36.useState)(displayedLineHeight);
|
|
16605
|
+
(0, import_react36.useEffect)(() => {
|
|
16606
|
+
dirtyLineHeight.current = false;
|
|
16607
|
+
setLineHeight(displayedLineHeight);
|
|
16608
|
+
}, [displayedLineHeight]);
|
|
16609
|
+
const commitLineHeight = () => {
|
|
16610
|
+
if (!dirtyLineHeight.current) return;
|
|
16611
|
+
dirtyLineHeight.current = false;
|
|
16612
|
+
if (!lineHeight.trim()) {
|
|
16613
|
+
onLayoutChange({ lineHeight: void 0 });
|
|
16614
|
+
return;
|
|
16615
|
+
}
|
|
16616
|
+
const value4 = Number(lineHeight);
|
|
16617
|
+
if (Number.isFinite(value4) && value4 >= 0.5 && value4 <= 5) onLayoutChange({ lineHeight: value4 });
|
|
16618
|
+
else setLineHeight(displayedLineHeight);
|
|
16619
|
+
};
|
|
16586
16620
|
const dirtySize = (0, import_react36.useRef)(false);
|
|
16587
16621
|
const [size, setSize] = (0, import_react36.useState)(displayedSize);
|
|
16588
16622
|
(0, import_react36.useEffect)(() => setHex(color), [color]);
|
|
@@ -16605,6 +16639,13 @@ function CmsTextToolbar({ layout, color, colorPicker, inlineControls, structureC
|
|
|
16605
16639
|
if (Number.isFinite(value4) && value4 >= 8 && value4 <= 300) onLayoutChange({ fontSize: value4 });
|
|
16606
16640
|
else setSize(displayedSize);
|
|
16607
16641
|
};
|
|
16642
|
+
const fontName = (computedFontFamily ?? layout.fontFamily ?? "Arial").split(",")[0].trim().replace(/^["']|["']$/g, "");
|
|
16643
|
+
const matchedFont = Object.entries(CMS_TEXT_FONTS).find(([family]) => family.split(",")[0].replace(/^["']|["']$/g, "").toLowerCase() === fontName.toLowerCase());
|
|
16644
|
+
const fontLabel = matchedFont?.[1] ?? fontName;
|
|
16645
|
+
const selectedFont = layout.fontFamily ?? matchedFont?.[0] ?? "";
|
|
16646
|
+
const tooltipProps = { slotProps: { popper: { sx: { zIndex: 1800 } } } };
|
|
16647
|
+
const inputSx = { width: 52, flexShrink: 0, "& .MuiInputBase-root": { height: 32 }, "& input": { py: 0.5, px: 0.75, fontSize: 12 } };
|
|
16648
|
+
const groupSx = { display: "flex", alignItems: "center", gap: 0.5 };
|
|
16608
16649
|
return /* @__PURE__ */ (0, import_jsx_runtime56.jsxs)(
|
|
16609
16650
|
import_material.Box,
|
|
16610
16651
|
{
|
|
@@ -16612,80 +16653,103 @@ function CmsTextToolbar({ layout, color, colorPicker, inlineControls, structureC
|
|
|
16612
16653
|
role: "toolbar",
|
|
16613
16654
|
"aria-label": "\u0110\u1ECBnh d\u1EA1ng ch\u1EEF",
|
|
16614
16655
|
"data-cms-text-toolbar": true,
|
|
16615
|
-
sx: { display: "flex",
|
|
16656
|
+
sx: { display: "flex", flexDirection: "column", gap: 0.5, p: 0.75, border: "1px solid", borderColor: "divider", borderRadius: 1, bgcolor: "background.paper", boxShadow: 8, color: "text.primary", maxWidth: "100%" },
|
|
16616
16657
|
children: [
|
|
16617
|
-
|
|
16618
|
-
|
|
16619
|
-
|
|
16620
|
-
|
|
16621
|
-
|
|
16622
|
-
|
|
16623
|
-
|
|
16624
|
-
|
|
16625
|
-
|
|
16626
|
-
|
|
16627
|
-
|
|
16628
|
-
|
|
16629
|
-
|
|
16630
|
-
|
|
16631
|
-
|
|
16632
|
-
|
|
16633
|
-
|
|
16634
|
-
|
|
16635
|
-
|
|
16636
|
-
|
|
16637
|
-
|
|
16638
|
-
|
|
16639
|
-
|
|
16640
|
-
|
|
16641
|
-
|
|
16642
|
-
|
|
16643
|
-
|
|
16644
|
-
|
|
16645
|
-
|
|
16646
|
-
|
|
16647
|
-
|
|
16648
|
-
|
|
16649
|
-
|
|
16650
|
-
|
|
16658
|
+
/* @__PURE__ */ (0, import_jsx_runtime56.jsxs)(import_material.Box, { sx: { ...groupSx, flexWrap: "wrap", pb: 0.5, borderBottom: "1px solid", borderColor: "divider" }, children: [
|
|
16659
|
+
/* @__PURE__ */ (0, import_jsx_runtime56.jsxs)(
|
|
16660
|
+
import_material.Select,
|
|
16661
|
+
{
|
|
16662
|
+
size: "small",
|
|
16663
|
+
displayEmpty: true,
|
|
16664
|
+
value: selectedFont,
|
|
16665
|
+
inputProps: { "aria-label": "Font ch\u1EEF" },
|
|
16666
|
+
renderValue: (value4) => value4 ? CMS_TEXT_FONTS[value4] : fontLabel,
|
|
16667
|
+
MenuProps: { disableScrollLock: true, container: () => toolbarRef.current?.ownerDocument.body ?? null, sx: { zIndex: 1600 }, slotProps: { paper: { sx: { maxHeight: 320 } } } },
|
|
16668
|
+
sx: { width: 128, height: 30, fontSize: 12, "& .MuiSelect-select": { py: 0.5, pl: 1, pr: "24px !important" }, "& .MuiSelect-icon": { right: 3 } },
|
|
16669
|
+
onChange: (event) => onLayoutChange({ fontFamily: event.target.value || void 0 }),
|
|
16670
|
+
children: [
|
|
16671
|
+
!selectedFont && /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_material.MenuItem, { value: "", sx: { fontSize: 12 }, children: fontLabel }),
|
|
16672
|
+
Object.entries(CMS_TEXT_FONTS).map(([value4, label]) => /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_material.MenuItem, { value: value4, sx: { fontFamily: value4, fontSize: 13 }, children: label }, value4))
|
|
16673
|
+
]
|
|
16674
|
+
}
|
|
16675
|
+
),
|
|
16676
|
+
structureControls
|
|
16677
|
+
] }),
|
|
16678
|
+
/* @__PURE__ */ (0, import_jsx_runtime56.jsxs)(import_material.Box, { sx: { ...groupSx, flexWrap: "wrap" }, children: [
|
|
16679
|
+
/* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_material.Tooltip, { title: "C\u1EE1 ch\u1EEF (px)", ...tooltipProps, children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
|
|
16680
|
+
import_material.TextField,
|
|
16681
|
+
{
|
|
16682
|
+
size: "small",
|
|
16683
|
+
type: "number",
|
|
16684
|
+
value: size,
|
|
16685
|
+
slotProps: { htmlInput: { "aria-label": "C\u1EE1 ch\u1EEF (px)", min: 8, max: 300, step: 1 } },
|
|
16686
|
+
sx: inputSx,
|
|
16687
|
+
onChange: (event) => {
|
|
16688
|
+
dirtySize.current = true;
|
|
16689
|
+
setSize(event.target.value);
|
|
16690
|
+
},
|
|
16691
|
+
onBlur: commitSize,
|
|
16692
|
+
onKeyDown: (event) => {
|
|
16693
|
+
if (event.key === "Enter") {
|
|
16694
|
+
event.preventDefault();
|
|
16695
|
+
commitSize();
|
|
16696
|
+
}
|
|
16651
16697
|
}
|
|
16652
16698
|
}
|
|
16653
|
-
}
|
|
16654
|
-
|
|
16655
|
-
|
|
16656
|
-
|
|
16657
|
-
|
|
16658
|
-
|
|
16659
|
-
|
|
16660
|
-
|
|
16661
|
-
|
|
16662
|
-
|
|
16663
|
-
|
|
16664
|
-
|
|
16665
|
-
|
|
16666
|
-
|
|
16667
|
-
|
|
16668
|
-
|
|
16669
|
-
|
|
16670
|
-
|
|
16699
|
+
) }),
|
|
16700
|
+
/* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_material.Tooltip, { title: "Chi\u1EC1u cao d\xF2ng (l\u1EA7n c\u1EE1 ch\u1EEF)", ...tooltipProps, children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
|
|
16701
|
+
import_material.TextField,
|
|
16702
|
+
{
|
|
16703
|
+
size: "small",
|
|
16704
|
+
type: "number",
|
|
16705
|
+
value: lineHeight,
|
|
16706
|
+
slotProps: { input: { startAdornment: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_material.InputAdornment, { position: "start", sx: { mr: 0 }, children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_material.SvgIcon, { sx: { fontSize: 17 }, children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)("path", { d: "M3 4 0 7h2v10H0l3 3 3-3H4V7h2L3 4zm5 2h16v2H8zm0 5h16v2H8zm0 5h16v2H8z" }) }) }) }, htmlInput: { "aria-label": "Chi\u1EC1u cao d\xF2ng", min: 0.5, max: 5, step: 0.1 } },
|
|
16707
|
+
sx: { ...inputSx, width: 78, "& .MuiInputBase-root": { height: 32, pl: 0.75 } },
|
|
16708
|
+
onChange: (event) => {
|
|
16709
|
+
dirtyLineHeight.current = true;
|
|
16710
|
+
setLineHeight(event.target.value);
|
|
16711
|
+
},
|
|
16712
|
+
onBlur: commitLineHeight,
|
|
16713
|
+
onKeyDown: (event) => {
|
|
16714
|
+
if (event.key === "Enter") {
|
|
16715
|
+
event.preventDefault();
|
|
16716
|
+
commitLineHeight();
|
|
16717
|
+
}
|
|
16671
16718
|
}
|
|
16672
16719
|
}
|
|
16673
|
-
}
|
|
16674
|
-
|
|
16675
|
-
|
|
16676
|
-
|
|
16677
|
-
|
|
16678
|
-
|
|
16679
|
-
|
|
16680
|
-
|
|
16681
|
-
|
|
16682
|
-
|
|
16683
|
-
|
|
16684
|
-
|
|
16685
|
-
|
|
16686
|
-
|
|
16687
|
-
|
|
16688
|
-
|
|
16720
|
+
) }),
|
|
16721
|
+
/* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_material.Box, { sx: groupSx, children: inlineControls }),
|
|
16722
|
+
/* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_material.Box, { sx: { ...groupSx, borderLeft: "1px solid", borderColor: "divider", pl: 1, ml: 0.5 }, children: [["left", "C\u0103n tr\xE1i"], ["center", "C\u0103n gi\u1EEFa"], ["right", "C\u0103n ph\u1EA3i"]].map(([align, label]) => /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_material.Tooltip, { title: label, ...tooltipProps, children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
|
|
16723
|
+
import_material.ToggleButton,
|
|
16724
|
+
{
|
|
16725
|
+
value: align,
|
|
16726
|
+
selected: (layout.textAlign ?? computedTextAlign ?? "left") === align,
|
|
16727
|
+
"aria-label": label,
|
|
16728
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
16729
|
+
onClick: () => onLayoutChange({ textAlign: align }),
|
|
16730
|
+
sx: { width: 30, minWidth: 30, height: 30, p: 0.5, border: 0 },
|
|
16731
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_material.SvgIcon, { sx: { fontSize: 19 }, children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)("path", { d: align === "left" ? "M3 4h18v2H3zm0 5h12v2H3zm0 5h18v2H3zm0 5h12v2H3z" : align === "right" ? "M3 4h18v2H3zm6 5h12v2H9zm-6 5h18v2H3zm6 5h12v2H9z" : "M3 4h18v2H3zm3 5h12v2H6zm-3 5h18v2H3zm3 5h12v2H6z" }) })
|
|
16732
|
+
}
|
|
16733
|
+
) }, align)) }),
|
|
16734
|
+
colorPicker || /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
|
|
16735
|
+
import_material.TextField,
|
|
16736
|
+
{
|
|
16737
|
+
size: "small",
|
|
16738
|
+
value: hex,
|
|
16739
|
+
slotProps: { htmlInput: { "aria-label": "M\xE3 m\xE0u ch\u1EEF", maxLength: 7, spellCheck: false } },
|
|
16740
|
+
sx: { ...inputSx, width: 76 },
|
|
16741
|
+
onChange: (event) => setHex(event.target.value),
|
|
16742
|
+
onBlur: commitColor,
|
|
16743
|
+
onKeyDown: (event) => {
|
|
16744
|
+
if (event.key === "Enter") {
|
|
16745
|
+
event.preventDefault();
|
|
16746
|
+
commitColor();
|
|
16747
|
+
}
|
|
16748
|
+
}
|
|
16749
|
+
}
|
|
16750
|
+
),
|
|
16751
|
+
/* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_material.Tooltip, { title: "\u0110\u1EB7t l\u1EA1i \u0111\u1ECBnh d\u1EA1ng ch\u1EEF", ...tooltipProps, children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_material.IconButton, { size: "small", "aria-label": "\u0110\u1EB7t l\u1EA1i \u0111\u1ECBnh d\u1EA1ng ch\u1EEF", onClick: onReset, sx: { width: 30, height: 30, ml: "auto" }, children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_material.SvgIcon, { sx: { fontSize: 19 }, children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)("path", { d: "m18 4 3 3-9 9-3-3 9-9zM8 14l3 3-3 3H4l-3-3 4-4 3 1zm4 6h10v2H10z" }) }) }) })
|
|
16752
|
+
] })
|
|
16689
16753
|
]
|
|
16690
16754
|
}
|
|
16691
16755
|
);
|