docblocks-react-ui 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +101 -0
- package/README.md +26 -3
- package/dist/{Editor-BZjfHAO5.mjs → Editor-g5aY0giB.mjs} +980 -300
- package/dist/{index-DzYwo6Px.d.mts → index-DPLVe3Mf.d.mts} +38 -1
- package/dist/index.d.mts +85 -73
- package/dist/index.mjs +2 -2
- package/dist/mermaid/index.mjs +1 -1
- package/dist/pdf/index.d.mts +1 -1
- package/dist/styles.css +86 -11
- package/package.json +1 -1
|
@@ -1603,7 +1603,7 @@ function Heart(props) {
|
|
|
1603
1603
|
}
|
|
1604
1604
|
//#endregion
|
|
1605
1605
|
//#region src/shared/ui/icons/Image.tsx
|
|
1606
|
-
function Image(props) {
|
|
1606
|
+
function Image$1(props) {
|
|
1607
1607
|
return /* @__PURE__ */ jsxs("svg", {
|
|
1608
1608
|
xmlns: "http://www.w3.org/2000/svg",
|
|
1609
1609
|
width: 24,
|
|
@@ -3806,10 +3806,6 @@ const INIT_OPTIONS = {
|
|
|
3806
3806
|
access: {
|
|
3807
3807
|
"notPublished": "This document has not been published yet.",
|
|
3808
3808
|
"notPublishedHint": "Readers see the document only after it has been published."
|
|
3809
|
-
},
|
|
3810
|
-
colorPicker: {
|
|
3811
|
-
"aria": "Color picker",
|
|
3812
|
-
"hexAria": "Hex color value"
|
|
3813
3809
|
}
|
|
3814
3810
|
},
|
|
3815
3811
|
database: {
|
|
@@ -3948,7 +3944,8 @@ const INIT_OPTIONS = {
|
|
|
3948
3944
|
"callout": {
|
|
3949
3945
|
"typeAria": "Callout type",
|
|
3950
3946
|
"variant": "{variant} callout",
|
|
3951
|
-
"iconAria": "Callout icon"
|
|
3947
|
+
"iconAria": "Callout icon",
|
|
3948
|
+
"hexAria": "Background hex value"
|
|
3952
3949
|
},
|
|
3953
3950
|
"color": {
|
|
3954
3951
|
"trigger": "Text and background color",
|
|
@@ -4011,6 +4008,22 @@ const INIT_OPTIONS = {
|
|
|
4011
4008
|
"addTagAria": "Add a tag",
|
|
4012
4009
|
"uploadCoverAria": "Upload the cover",
|
|
4013
4010
|
"removeCoverAria": "Remove the cover",
|
|
4011
|
+
"coverPresetsLabel": "Presets",
|
|
4012
|
+
"coverPresetAria": "Use the preset cover {{id}}",
|
|
4013
|
+
"coverMode": "Placement",
|
|
4014
|
+
"coverModeTile": "Tile",
|
|
4015
|
+
"coverModeCenter": "Centering",
|
|
4016
|
+
"coverTint": "Frame tint",
|
|
4017
|
+
"coverTintAria": "Tint the frame's border over the cover's average color",
|
|
4018
|
+
"coverUploadTitle": "Upload cover",
|
|
4019
|
+
"coverUploadHint": "Drag and drop a PNG, JPEG, or WebP image, or click to choose a file",
|
|
4020
|
+
"coverInfoMinHeight": "Minimum height: {min} px",
|
|
4021
|
+
"coverInfoMinWidth": "Minimum width: {min} px",
|
|
4022
|
+
"coverTooShort": "Image height must be at least {min} px",
|
|
4023
|
+
"coverTooNarrow": "Image width must be at least {min} px",
|
|
4024
|
+
"coverUnsupportedType": "Only PNG, JPEG, and WebP images are supported",
|
|
4025
|
+
"coverUploadFailed": "The upload failed",
|
|
4026
|
+
"closeCoverUploadAria": "Close the cover upload",
|
|
4014
4027
|
"addAttribute": "Add attribute",
|
|
4015
4028
|
"addConfirm": "Add",
|
|
4016
4029
|
"keyReserved": "The key cannot be used (a reserved document key)."
|
|
@@ -4073,8 +4086,6 @@ const INIT_OPTIONS = {
|
|
|
4073
4086
|
},
|
|
4074
4087
|
menu: {
|
|
4075
4088
|
"background": "Background",
|
|
4076
|
-
"backgroundSwatch": "Background {color}",
|
|
4077
|
-
"removeBackground": "Remove background",
|
|
4078
4089
|
"insertRight": "Insert right",
|
|
4079
4090
|
"insertLeft": "Insert left",
|
|
4080
4091
|
"insertBelow": "Insert below",
|
|
@@ -4304,10 +4315,6 @@ const INIT_OPTIONS = {
|
|
|
4304
4315
|
access: {
|
|
4305
4316
|
"notPublished": "Документ ещё не опубликован.",
|
|
4306
4317
|
"notPublishedHint": "Читатели увидят документ только после публикации."
|
|
4307
|
-
},
|
|
4308
|
-
colorPicker: {
|
|
4309
|
-
"aria": "Выбор цвета",
|
|
4310
|
-
"hexAria": "Цвет в hex-формате"
|
|
4311
4318
|
}
|
|
4312
4319
|
},
|
|
4313
4320
|
database: {
|
|
@@ -4446,7 +4453,8 @@ const INIT_OPTIONS = {
|
|
|
4446
4453
|
"callout": {
|
|
4447
4454
|
"typeAria": "Тип выноски",
|
|
4448
4455
|
"variant": "Выноска: {variant}",
|
|
4449
|
-
"iconAria": "Иконка выноски"
|
|
4456
|
+
"iconAria": "Иконка выноски",
|
|
4457
|
+
"hexAria": "Цвет фона в hex-формате"
|
|
4450
4458
|
},
|
|
4451
4459
|
"color": {
|
|
4452
4460
|
"trigger": "Цвет текста и фона",
|
|
@@ -4509,6 +4517,22 @@ const INIT_OPTIONS = {
|
|
|
4509
4517
|
"addTagAria": "Добавить тег",
|
|
4510
4518
|
"uploadCoverAria": "Загрузить обложку",
|
|
4511
4519
|
"removeCoverAria": "Удалить обложку",
|
|
4520
|
+
"coverPresetsLabel": "Пресеты",
|
|
4521
|
+
"coverPresetAria": "Выбрать пресет обложки {{id}}",
|
|
4522
|
+
"coverMode": "Размещение",
|
|
4523
|
+
"coverModeTile": "Плитка",
|
|
4524
|
+
"coverModeCenter": "Центрирование",
|
|
4525
|
+
"coverTint": "Окраска рамки",
|
|
4526
|
+
"coverTintAria": "Окрашивать рамку средним цветом обложки",
|
|
4527
|
+
"coverUploadTitle": "Загрузка обложки",
|
|
4528
|
+
"coverUploadHint": "Перетащите сюда изображение PNG, JPEG или WebP или нажмите, чтобы выбрать файл",
|
|
4529
|
+
"coverInfoMinHeight": "Минимальная высота: {min} px",
|
|
4530
|
+
"coverInfoMinWidth": "Минимальная ширина: {min} px",
|
|
4531
|
+
"coverTooShort": "Высота изображения должна быть не меньше {min} px",
|
|
4532
|
+
"coverTooNarrow": "Ширина изображения должна быть не меньше {min} px",
|
|
4533
|
+
"coverUnsupportedType": "Поддерживаются только изображения PNG, JPEG и WebP",
|
|
4534
|
+
"coverUploadFailed": "Загрузка не удалась",
|
|
4535
|
+
"closeCoverUploadAria": "Закрыть загрузку обложки",
|
|
4512
4536
|
"addAttribute": "Добавить атрибут",
|
|
4513
4537
|
"addConfirm": "Добавить",
|
|
4514
4538
|
"keyReserved": "Ключ использовать нельзя (зарезервированный ключ документа)."
|
|
@@ -4571,8 +4595,6 @@ const INIT_OPTIONS = {
|
|
|
4571
4595
|
},
|
|
4572
4596
|
menu: {
|
|
4573
4597
|
"background": "Фон",
|
|
4574
|
-
"backgroundSwatch": "Фон {color}",
|
|
4575
|
-
"removeBackground": "Убрать фон",
|
|
4576
4598
|
"insertRight": "Вставить справа",
|
|
4577
4599
|
"insertLeft": "Вставить слева",
|
|
4578
4600
|
"insertBelow": "Вставить ниже",
|
|
@@ -6490,168 +6512,35 @@ function probeFor(entry) {
|
|
|
6490
6512
|
return el;
|
|
6491
6513
|
}
|
|
6492
6514
|
//#endregion
|
|
6493
|
-
//#region src/shared/ui/
|
|
6515
|
+
//#region src/shared/ui/ColorChip.tsx
|
|
6494
6516
|
/**
|
|
6495
|
-
* The
|
|
6496
|
-
*
|
|
6497
|
-
*
|
|
6498
|
-
*
|
|
6499
|
-
*
|
|
6500
|
-
*
|
|
6501
|
-
*
|
|
6502
|
-
*
|
|
6503
|
-
* own classes merge through `cn` (width, focus background, or padding
|
|
6504
|
-
* overrides win over the size's stand).
|
|
6517
|
+
* The color chip's preview — the trigger's current-color stand, the shared
|
|
6518
|
+
* language over every color trigger (the page's format buttons, the canvas
|
|
6519
|
+
* toolbars, the table's handles). The `fill` mode's square is filled with
|
|
6520
|
+
* the current hex; the `stroke` mode's square is hollow with the current
|
|
6521
|
+
* hex's border (the stroke's preview). The none's stand is the X over the
|
|
6522
|
+
* theme's muted frame. The frame's border reads the canvas chrome's token
|
|
6523
|
+
* over the canvas toolbars and the standard's `--border` elsewhere (the
|
|
6524
|
+
* token's fallback).
|
|
6505
6525
|
*/
|
|
6506
|
-
|
|
6507
|
-
|
|
6508
|
-
|
|
6509
|
-
|
|
6510
|
-
|
|
6511
|
-
|
|
6512
|
-
|
|
6513
|
-
|
|
6514
|
-
|
|
6515
|
-
size: {
|
|
6516
|
-
default: `
|
|
6517
|
-
border-input px-3 py-1 text-base shadow-xs
|
|
6518
|
-
focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/40
|
|
6519
|
-
aria-invalid:border-destructive aria-invalid:ring-destructive/20
|
|
6520
|
-
md:text-sm
|
|
6521
|
-
dark:aria-invalid:ring-destructive/40
|
|
6522
|
-
`,
|
|
6523
|
-
sm: `h-8 border-border px-2 py-0.5 text-sm`
|
|
6526
|
+
function ColorChip({ value, mode = "fill", className }) {
|
|
6527
|
+
const none = value === void 0 || value === null || value === "";
|
|
6528
|
+
const stroke = mode === "stroke" && !none;
|
|
6529
|
+
return /* @__PURE__ */ jsx("span", {
|
|
6530
|
+
"data-slot": "docblocks/color-chip",
|
|
6531
|
+
className: cn("relative size-3 shrink-0 rounded-(--docblocks-radius)", className),
|
|
6532
|
+
style: none ? { border: "1px solid var(--docblocks-formatbar-border-color, var(--border, #888))" } : stroke ? { border: `2px solid ${value}` } : {
|
|
6533
|
+
background: value,
|
|
6534
|
+
border: "1px solid var(--docblocks-formatbar-border-color, var(--border, #888))"
|
|
6524
6535
|
},
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
|
|
6531
|
-
dark:bg-transparent
|
|
6532
|
-
`
|
|
6533
|
-
}
|
|
6534
|
-
},
|
|
6535
|
-
defaultVariants: {
|
|
6536
|
-
size: "default",
|
|
6537
|
-
variant: "default"
|
|
6538
|
-
}
|
|
6539
|
-
});
|
|
6540
|
-
function Input({ className, size, variant, type, ...props }) {
|
|
6541
|
-
return /* @__PURE__ */ jsx("input", {
|
|
6542
|
-
type,
|
|
6543
|
-
"data-slot": "input",
|
|
6544
|
-
className: cn(inputVariants({
|
|
6545
|
-
size,
|
|
6546
|
-
variant,
|
|
6547
|
-
className
|
|
6548
|
-
})),
|
|
6549
|
-
...props
|
|
6550
|
-
});
|
|
6551
|
-
}
|
|
6552
|
-
//#endregion
|
|
6553
|
-
//#region src/shared/ui/ColorPicker.tsx
|
|
6554
|
-
/**
|
|
6555
|
-
* The custom color's picker body (the callout menu's custom swatch opens it
|
|
6556
|
-
* as an inline section): the native `input type="color"` (the live scrub —
|
|
6557
|
-
* no doc write over the scrub) and the hex field (the strict `#rrggbb`).
|
|
6558
|
-
* The doc write stands one `onCommit` per pick (one undo step, one wire
|
|
6559
|
-
* update — the swatch pick's parity): the native dialog's commit (`change`),
|
|
6560
|
-
* the field's valid Enter / blur. An invalid field value resets to the
|
|
6561
|
-
* draft on blur (the picker stands the last valid stand). The close without
|
|
6562
|
-
* an explicit commit (the Esc / the toggle / the menu's dismiss) commits the
|
|
6563
|
-
* last scrubbed value (the picker's unmount commits it); an untouched
|
|
6564
|
-
* picker commits nothing.
|
|
6565
|
-
*/
|
|
6566
|
-
/** The absent value's stand: the native input's neutral default. */
|
|
6567
|
-
const DEFAULT_HEX = "#808080";
|
|
6568
|
-
/** The strict hex field's stand: `#` + six hex digits. */
|
|
6569
|
-
const STRICT_HEX_RE = /^#([0-9a-f]{6})$/i;
|
|
6570
|
-
function ColorPickerInner({ value, onCommit, onClose }) {
|
|
6571
|
-
const { t } = useTranslation("common");
|
|
6572
|
-
const [draft, setDraft] = useState(value ?? DEFAULT_HEX);
|
|
6573
|
-
const [field, setField] = useState(value ?? DEFAULT_HEX);
|
|
6574
|
-
const valueRef = useRef(value);
|
|
6575
|
-
valueRef.current = value;
|
|
6576
|
-
const onCommitRef = useRef(onCommit);
|
|
6577
|
-
onCommitRef.current = onCommit;
|
|
6578
|
-
const onCloseRef = useRef(onClose);
|
|
6579
|
-
onCloseRef.current = onClose;
|
|
6580
|
-
const draftRef = useRef(draft);
|
|
6581
|
-
draftRef.current = draft;
|
|
6582
|
-
const touchedRef = useRef(false);
|
|
6583
|
-
const committedRef = useRef(false);
|
|
6584
|
-
useEffect(() => {
|
|
6585
|
-
return () => {
|
|
6586
|
-
if (!touchedRef.current || committedRef.current) return;
|
|
6587
|
-
const committed = normalizeHex$1(draftRef.current);
|
|
6588
|
-
const current = valueRef.current === null ? null : normalizeHex$1(valueRef.current);
|
|
6589
|
-
if (committed !== null && committed !== current) onCommitRef.current(committed);
|
|
6590
|
-
};
|
|
6591
|
-
}, []);
|
|
6592
|
-
const nativeRef = useRef(null);
|
|
6593
|
-
useEffect(() => {
|
|
6594
|
-
const el = nativeRef.current;
|
|
6595
|
-
if (el === null) return;
|
|
6596
|
-
const onChange = (event) => {
|
|
6597
|
-
committedRef.current = true;
|
|
6598
|
-
const committed = normalizeHex$1(event.target.value);
|
|
6599
|
-
const current = valueRef.current === null ? null : normalizeHex$1(valueRef.current);
|
|
6600
|
-
if (committed !== null && committed !== current) onCommitRef.current(committed);
|
|
6601
|
-
onCloseRef.current();
|
|
6602
|
-
};
|
|
6603
|
-
el.addEventListener("change", onChange);
|
|
6604
|
-
return () => el.removeEventListener("change", onChange);
|
|
6605
|
-
}, []);
|
|
6606
|
-
/** The field's commit gesture (the Enter / the valid blur): write + close. */
|
|
6607
|
-
const commitField = (raw) => {
|
|
6608
|
-
const match = raw.trim().match(STRICT_HEX_RE);
|
|
6609
|
-
if (match === null) return false;
|
|
6610
|
-
committedRef.current = true;
|
|
6611
|
-
const hex = `#${match[1].toLowerCase()}`;
|
|
6612
|
-
setDraft(hex);
|
|
6613
|
-
setField(hex);
|
|
6614
|
-
if (hex !== (valueRef.current === null ? null : normalizeHex$1(valueRef.current))) onCommitRef.current(hex);
|
|
6615
|
-
onCloseRef.current();
|
|
6616
|
-
return true;
|
|
6617
|
-
};
|
|
6618
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
6619
|
-
className: "flex flex-col gap-2",
|
|
6620
|
-
children: [/* @__PURE__ */ jsx("input", {
|
|
6621
|
-
ref: nativeRef,
|
|
6622
|
-
type: "color",
|
|
6623
|
-
value: draft,
|
|
6624
|
-
onInput: (event) => {
|
|
6625
|
-
touchedRef.current = true;
|
|
6626
|
-
setDraft(event.currentTarget.value);
|
|
6627
|
-
},
|
|
6628
|
-
"aria-label": t("colorPicker.aria"),
|
|
6629
|
-
className: "h-8 w-8 cursor-pointer rounded-xs border border-(--border) bg-transparent p-0.5"
|
|
6630
|
-
}), /* @__PURE__ */ jsx(Input, {
|
|
6631
|
-
value: field,
|
|
6632
|
-
size: "sm",
|
|
6633
|
-
"aria-label": t("colorPicker.hexAria"),
|
|
6634
|
-
placeholder: "#rrggbb",
|
|
6635
|
-
className: "font-(family-name:--docblocks-mono-font-family)",
|
|
6636
|
-
onChange: (event) => setField(event.target.value),
|
|
6637
|
-
onKeyDown: (event) => {
|
|
6638
|
-
if (event.key === "Enter") {
|
|
6639
|
-
event.preventDefault();
|
|
6640
|
-
commitField(field);
|
|
6641
|
-
}
|
|
6642
|
-
},
|
|
6643
|
-
onBlur: () => {
|
|
6644
|
-
if (!commitField(field)) setField(draft);
|
|
6645
|
-
}
|
|
6646
|
-
})]
|
|
6536
|
+
"aria-hidden": true,
|
|
6537
|
+
children: none && /* @__PURE__ */ jsx(X, {
|
|
6538
|
+
className: "absolute inset-0 m-auto size-2.5 text-muted-foreground",
|
|
6539
|
+
strokeWidth: 2.5,
|
|
6540
|
+
"aria-hidden": true
|
|
6541
|
+
})
|
|
6647
6542
|
});
|
|
6648
6543
|
}
|
|
6649
|
-
/** The palette's i18n scope: the package's instance stands the provider's
|
|
6650
|
-
* seat over the picker (the primitive stands also outside the editor's
|
|
6651
|
-
* scope — the ColorSwatches' parity). */
|
|
6652
|
-
function ColorPicker(props) {
|
|
6653
|
-
return /* @__PURE__ */ jsx(DocblocksI18nProvider, { children: /* @__PURE__ */ jsx(ColorPickerInner, { ...props }) });
|
|
6654
|
-
}
|
|
6655
6544
|
//#endregion
|
|
6656
6545
|
//#region src/shared/ui/ColorSwatches.tsx
|
|
6657
6546
|
/**
|
|
@@ -7443,6 +7332,66 @@ function DropdownMenuSubContent({ className, ...props }) {
|
|
|
7443
7332
|
});
|
|
7444
7333
|
}
|
|
7445
7334
|
//#endregion
|
|
7335
|
+
//#region src/shared/ui/Input.tsx
|
|
7336
|
+
/**
|
|
7337
|
+
* The text input primitive: the standard field control for the editor's
|
|
7338
|
+
* chrome forms. Two sizes: `default` (the standard h-9 field — the header
|
|
7339
|
+
* and the portaled forms; the `--input` token frame + the focus ring) and
|
|
7340
|
+
* `sm` (the compact h-8 grid-control look the database grid, the filter
|
|
7341
|
+
* builder, and the portaled pickers stand — the `--border` token frame,
|
|
7342
|
+
* no ring). Two looks: `default` (the framed field) and `inline` (the
|
|
7343
|
+
* row's flat field — the in-row editor: no frame / the background / the
|
|
7344
|
+
* shadow over the rest, the focus's border stand only). The call site's
|
|
7345
|
+
* own classes merge through `cn` (width, focus background, or padding
|
|
7346
|
+
* overrides win over the size's stand).
|
|
7347
|
+
*/
|
|
7348
|
+
const inputVariants = cva(`
|
|
7349
|
+
h-9 w-full min-w-0 rounded-md border bg-transparent transition-[color,box-shadow] duration-300 outline-none
|
|
7350
|
+
selection:bg-primary selection:text-primary-foreground
|
|
7351
|
+
file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground
|
|
7352
|
+
placeholder:text-muted-foreground
|
|
7353
|
+
disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50
|
|
7354
|
+
dark:bg-input/30
|
|
7355
|
+
`, {
|
|
7356
|
+
variants: {
|
|
7357
|
+
size: {
|
|
7358
|
+
default: `
|
|
7359
|
+
border-input px-3 py-1 text-base shadow-xs
|
|
7360
|
+
focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/40
|
|
7361
|
+
aria-invalid:border-destructive aria-invalid:ring-destructive/20
|
|
7362
|
+
md:text-sm
|
|
7363
|
+
dark:aria-invalid:ring-destructive/40
|
|
7364
|
+
`,
|
|
7365
|
+
sm: `h-8 border-border px-2 py-0.5 text-sm`
|
|
7366
|
+
},
|
|
7367
|
+
variant: {
|
|
7368
|
+
default: ``,
|
|
7369
|
+
inline: `
|
|
7370
|
+
h-8 border-transparent bg-transparent px-1.5 py-0.5 text-sm shadow-none
|
|
7371
|
+
focus-visible:border-ring focus-visible:ring-0
|
|
7372
|
+
aria-invalid:border-destructive
|
|
7373
|
+
dark:bg-transparent
|
|
7374
|
+
`
|
|
7375
|
+
}
|
|
7376
|
+
},
|
|
7377
|
+
defaultVariants: {
|
|
7378
|
+
size: "default",
|
|
7379
|
+
variant: "default"
|
|
7380
|
+
}
|
|
7381
|
+
});
|
|
7382
|
+
function Input({ className, size, variant, type, ...props }) {
|
|
7383
|
+
return /* @__PURE__ */ jsx("input", {
|
|
7384
|
+
type,
|
|
7385
|
+
"data-slot": "input",
|
|
7386
|
+
className: cn(inputVariants({
|
|
7387
|
+
size,
|
|
7388
|
+
variant,
|
|
7389
|
+
className
|
|
7390
|
+
})),
|
|
7391
|
+
...props
|
|
7392
|
+
});
|
|
7393
|
+
}
|
|
7394
|
+
//#endregion
|
|
7446
7395
|
//#region src/shared/ui/InlineEditInput.tsx
|
|
7447
7396
|
/**
|
|
7448
7397
|
* The inline edit's input (the document meta's inline editors — the
|
|
@@ -20094,6 +20043,7 @@ function FormatToolbar({ rootRef, palette }) {
|
|
|
20094
20043
|
const alignActive = (align) => range.kind === "cross" ? uniformAlignOfRange(doc, range.cross) === align : alignOfBlock(single) === align;
|
|
20095
20044
|
const paletteActive = (value) => range.kind === "cross" ? uniformMarkValueRange(doc, range.cross, target) === value : uniformMarkValue(single, range.from, range.to, target) === value;
|
|
20096
20045
|
const currentMarkValue = range.kind === "cross" ? uniformMarkValueRange(doc, range.cross, target) : uniformMarkValue(single, range.from, range.to, target);
|
|
20046
|
+
const chipValue = currentMarkValue !== null && currentMarkValue !== "mixed" ? currentMarkValue : null;
|
|
20097
20047
|
const listValue = block !== void 0 && block.type === "list-item" ? block.attrs.list : block !== void 0 && block.type === "paragraph" ? "paragraph" : block !== void 0 && block.type === "quote" ? "quote" : "";
|
|
20098
20048
|
const toggleMarkAt = (mark) => () => onToggleMark(mark);
|
|
20099
20049
|
const alignAt = (align) => () => onAlign(align);
|
|
@@ -20190,7 +20140,10 @@ function FormatToolbar({ rootRef, palette }) {
|
|
|
20190
20140
|
title: t("formatToolbar.color.trigger"),
|
|
20191
20141
|
"aria-label": t("formatToolbar.color.trigger"),
|
|
20192
20142
|
className: "data-[state=open]:bg-accent data-[state=open]:text-accent-foreground",
|
|
20193
|
-
children: /* @__PURE__ */
|
|
20143
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
20144
|
+
className: "flex items-center gap-1",
|
|
20145
|
+
children: [/* @__PURE__ */ jsx(Baseline, { className: "size-4" }), /* @__PURE__ */ jsx(ColorChip, { value: chipValue })]
|
|
20146
|
+
})
|
|
20194
20147
|
})
|
|
20195
20148
|
}), /* @__PURE__ */ jsxs(PopoverContent, {
|
|
20196
20149
|
align: "start",
|
|
@@ -20299,29 +20252,27 @@ function calloutIconName(icon, variant) {
|
|
|
20299
20252
|
/**
|
|
20300
20253
|
* The callout's management affordance — the marker-zone icon stands a
|
|
20301
20254
|
* button; its click opens the block's management menu (the type presets /
|
|
20302
|
-
* the background palette over the custom
|
|
20303
|
-
*
|
|
20304
|
-
*
|
|
20305
|
-
*
|
|
20306
|
-
*
|
|
20255
|
+
* the background palette over the custom hex / the icon catalog) beside the
|
|
20256
|
+
* icon. The menu manages the block's attrs, not the selection's marks, so
|
|
20257
|
+
* it stands for an empty callout (no text selection needed). The read-only
|
|
20258
|
+
* stands (view / published) render the icon without a button — no pointer
|
|
20259
|
+
* events, the editing-surface parity.
|
|
20307
20260
|
*
|
|
20308
20261
|
* The menu is a non-modal portaled popover: the content's mousedown guard
|
|
20309
20262
|
* keeps the editor's text selection alive over the open (the format
|
|
20310
|
-
* toolbar's menu parity — the guard yields over the
|
|
20311
|
-
*
|
|
20312
|
-
*
|
|
20313
|
-
*
|
|
20314
|
-
*
|
|
20315
|
-
* dismiss) applies the last scrubbed value (the picker's unmount commits
|
|
20316
|
-
* it; the grid's custom swatch carries a non-preset current value as its
|
|
20317
|
-
* own dot).
|
|
20263
|
+
* toolbar's menu parity — the guard yields over the hex's input, its focus
|
|
20264
|
+
* stands the gesture). The pick's stand closes the menu over the color and
|
|
20265
|
+
* the icon's apply (the type preset stays open). The custom's stand is the
|
|
20266
|
+
* rainbow's swatch (the dot over the non-preset current) + the hex's input
|
|
20267
|
+
* (the shared mechanism — the canvas's palette's parity).
|
|
20318
20268
|
*/
|
|
20319
20269
|
function CalloutBlockMenu({ id, block }) {
|
|
20320
20270
|
const { t } = useTranslation("editor");
|
|
20321
20271
|
const { doc, viewMode } = useEditorContext();
|
|
20322
20272
|
const palette = useFormatPalette();
|
|
20323
20273
|
const [menuOpen, setMenuOpen] = useState(false);
|
|
20324
|
-
const [
|
|
20274
|
+
const [hexDraft, setHexDraft] = useState("");
|
|
20275
|
+
const hexRef = useRef(null);
|
|
20325
20276
|
const variant = block.attrs?.variant ?? "info";
|
|
20326
20277
|
const color = block.attrs?.color ?? null;
|
|
20327
20278
|
const icon = block.attrs?.icon ?? null;
|
|
@@ -20350,6 +20301,16 @@ function CalloutBlockMenu({ id, block }) {
|
|
|
20350
20301
|
if (color === hex) return;
|
|
20351
20302
|
doc.updateBlock(id, { color: hex });
|
|
20352
20303
|
};
|
|
20304
|
+
useEffect(() => {
|
|
20305
|
+
if (!menuOpen) setHexDraft("");
|
|
20306
|
+
}, [menuOpen]);
|
|
20307
|
+
const commitHexDraft = () => {
|
|
20308
|
+
const normalized = normalizeHex$1(hexDraft);
|
|
20309
|
+
if (normalized !== null) {
|
|
20310
|
+
onColorCommit(normalized);
|
|
20311
|
+
setMenuOpen(false);
|
|
20312
|
+
}
|
|
20313
|
+
};
|
|
20353
20314
|
const onIconPick = (name) => {
|
|
20354
20315
|
setMenuOpen(false);
|
|
20355
20316
|
if (icon === name) return;
|
|
@@ -20384,10 +20345,7 @@ function CalloutBlockMenu({ id, block }) {
|
|
|
20384
20345
|
children: /* @__PURE__ */ jsxs(Popover, {
|
|
20385
20346
|
modal: false,
|
|
20386
20347
|
open: menuOpen,
|
|
20387
|
-
onOpenChange:
|
|
20388
|
-
setMenuOpen(next);
|
|
20389
|
-
setPickerOpen(false);
|
|
20390
|
-
},
|
|
20348
|
+
onOpenChange: setMenuOpen,
|
|
20391
20349
|
children: [/* @__PURE__ */ jsx(PopoverTrigger, {
|
|
20392
20350
|
asChild: true,
|
|
20393
20351
|
children: /* @__PURE__ */ jsx(Button, {
|
|
@@ -20451,15 +20409,24 @@ function CalloutBlockMenu({ id, block }) {
|
|
|
20451
20409
|
noneActive: color === null,
|
|
20452
20410
|
onSelectNone: onColorNone,
|
|
20453
20411
|
allowCustom: true,
|
|
20454
|
-
onCustom: () =>
|
|
20455
|
-
}),
|
|
20412
|
+
onCustom: () => hexRef.current?.focus()
|
|
20413
|
+
}), /* @__PURE__ */ jsx(Input, {
|
|
20414
|
+
ref: hexRef,
|
|
20415
|
+
type: "text",
|
|
20416
|
+
size: "sm",
|
|
20456
20417
|
"data-slot": "docblocks/callout-color-picker",
|
|
20457
|
-
|
|
20458
|
-
|
|
20459
|
-
|
|
20460
|
-
|
|
20461
|
-
|
|
20462
|
-
|
|
20418
|
+
"aria-label": t("formatToolbar.callout.hexAria"),
|
|
20419
|
+
className: "mt-2 h-7 font-mono text-xs",
|
|
20420
|
+
placeholder: "#rrggbb",
|
|
20421
|
+
value: hexDraft,
|
|
20422
|
+
onChange: (event) => setHexDraft(event.target.value),
|
|
20423
|
+
onKeyDown: (event) => {
|
|
20424
|
+
if (event.key === "Enter") {
|
|
20425
|
+
event.preventDefault();
|
|
20426
|
+
commitHexDraft();
|
|
20427
|
+
}
|
|
20428
|
+
},
|
|
20429
|
+
onBlur: commitHexDraft
|
|
20463
20430
|
})]
|
|
20464
20431
|
}),
|
|
20465
20432
|
/* @__PURE__ */ jsx("div", {
|
|
@@ -22890,11 +22857,14 @@ function onToolbarBodyMouseDown(event) {
|
|
|
22890
22857
|
/** One color section of the shape toolbar (the fill or the stroke). The
|
|
22891
22858
|
* open state is the toolbar's (the sections are mutually exclusive — the
|
|
22892
22859
|
* non-modal popover does not close on an outside click, so a per-section
|
|
22893
|
-
* state would let both palettes stand open at once).
|
|
22894
|
-
|
|
22860
|
+
* state would let both palettes stand open at once). The custom's stand is
|
|
22861
|
+
* the rainbow's swatch (the dot over the current custom's value) + the hex
|
|
22862
|
+
* input (the shared mechanism — the native dialog's no-stand). */
|
|
22863
|
+
function ColorSection({ target, label, current, mode = "fill", icon, open, onOpenChange, onApply, allowNone = true, slotPrefix = "docblocks/shape" }) {
|
|
22895
22864
|
const { t } = useTranslation("canvas");
|
|
22896
22865
|
const palette = useFormatPalette();
|
|
22897
22866
|
const [draft, setDraft] = useState("");
|
|
22867
|
+
const hexRef = useRef(null);
|
|
22898
22868
|
const none = allowNone && (current === void 0 || current === "none");
|
|
22899
22869
|
const lower = current?.toLowerCase();
|
|
22900
22870
|
useEffect(() => {
|
|
@@ -22935,13 +22905,9 @@ function ColorSection({ target, label, current, chipStyle, icon, open, onOpenCha
|
|
|
22935
22905
|
className: "data-[state=open]:bg-accent data-[state=open]:text-accent-foreground",
|
|
22936
22906
|
children: /* @__PURE__ */ jsxs("span", {
|
|
22937
22907
|
className: "flex items-center gap-1",
|
|
22938
|
-
children: [icon,
|
|
22939
|
-
|
|
22940
|
-
|
|
22941
|
-
...chipStyle,
|
|
22942
|
-
border: "1px solid var(--docblocks-formatbar-border-color, #888)"
|
|
22943
|
-
},
|
|
22944
|
-
"aria-hidden": true
|
|
22908
|
+
children: [icon, /* @__PURE__ */ jsx(ColorChip, {
|
|
22909
|
+
value: current,
|
|
22910
|
+
mode
|
|
22945
22911
|
})]
|
|
22946
22912
|
})
|
|
22947
22913
|
})
|
|
@@ -22961,8 +22927,11 @@ function ColorSection({ target, label, current, chipStyle, icon, open, onOpenCha
|
|
|
22961
22927
|
label: target,
|
|
22962
22928
|
allowNone,
|
|
22963
22929
|
noneActive: none,
|
|
22964
|
-
onSelectNone: allowNone ? selectNone : void 0
|
|
22930
|
+
onSelectNone: allowNone ? selectNone : void 0,
|
|
22931
|
+
allowCustom: true,
|
|
22932
|
+
onCustom: () => hexRef.current?.focus()
|
|
22965
22933
|
}), /* @__PURE__ */ jsx(Input, {
|
|
22934
|
+
ref: hexRef,
|
|
22966
22935
|
size: "sm",
|
|
22967
22936
|
"data-slot": `${slotPrefix}-${target}-hex`,
|
|
22968
22937
|
"aria-label": t("colorHex", { label }),
|
|
@@ -23124,7 +23093,7 @@ function ConnectorToolbar({ id, variant, strokeColor, strokeWidth, strokeStyle,
|
|
|
23124
23093
|
target: "stroke",
|
|
23125
23094
|
label: t("connector.lineColor"),
|
|
23126
23095
|
current: strokeColor,
|
|
23127
|
-
|
|
23096
|
+
mode: "stroke",
|
|
23128
23097
|
icon: /* @__PURE__ */ jsx(Stroke, { className: "size-4" }),
|
|
23129
23098
|
open: openSection === "stroke",
|
|
23130
23099
|
onOpenChange: openStrokeSection,
|
|
@@ -24653,7 +24622,6 @@ function ShapeTextControls({ slotPrefix, sizeListId, fontFamily, textColor, text
|
|
|
24653
24622
|
target: "text",
|
|
24654
24623
|
label: t("text.color"),
|
|
24655
24624
|
current: textColor,
|
|
24656
|
-
chipStyle: { background: textColor ?? "transparent" },
|
|
24657
24625
|
icon: /* @__PURE__ */ jsx(Palette, { className: "size-4" }),
|
|
24658
24626
|
open: textColorOpen,
|
|
24659
24627
|
onOpenChange: onTextColorOpenChange,
|
|
@@ -24916,7 +24884,6 @@ function ShapeToolbar({ id, fill, stroke, strokeWidth, strokeStyle, variant, tex
|
|
|
24916
24884
|
target: "fill",
|
|
24917
24885
|
label: t("shape.fillColor"),
|
|
24918
24886
|
current: fill,
|
|
24919
|
-
chipStyle: { background: fill ?? "transparent" },
|
|
24920
24887
|
icon: /* @__PURE__ */ jsx(Fill, { className: "size-4" }),
|
|
24921
24888
|
open: openSection === "fill",
|
|
24922
24889
|
onOpenChange: openFillSection,
|
|
@@ -24926,7 +24893,7 @@ function ShapeToolbar({ id, fill, stroke, strokeWidth, strokeStyle, variant, tex
|
|
|
24926
24893
|
target: "stroke",
|
|
24927
24894
|
label: t("shape.strokeColor"),
|
|
24928
24895
|
current: stroke,
|
|
24929
|
-
|
|
24896
|
+
mode: "stroke",
|
|
24930
24897
|
icon: /* @__PURE__ */ jsx(Stroke, { className: "size-4" }),
|
|
24931
24898
|
open: openSection === "stroke",
|
|
24932
24899
|
onOpenChange: openStrokeSection,
|
|
@@ -25706,7 +25673,7 @@ function ImageBlock({ id, block }) {
|
|
|
25706
25673
|
className: BLOB_PLACEHOLDER_CLASS,
|
|
25707
25674
|
children: /* @__PURE__ */ jsxs(CardContent, {
|
|
25708
25675
|
className: "flex flex-col items-center gap-2 text-center",
|
|
25709
|
-
children: [file.status === "loading" ? /* @__PURE__ */ jsx(LoaderCircle, { className: "size-6 animate-spin" }) : /* @__PURE__ */ jsx(Image, { className: "size-6" }), t("image.placeholder")]
|
|
25676
|
+
children: [file.status === "loading" ? /* @__PURE__ */ jsx(LoaderCircle, { className: "size-6 animate-spin" }) : /* @__PURE__ */ jsx(Image$1, { className: "size-6" }), t("image.placeholder")]
|
|
25710
25677
|
})
|
|
25711
25678
|
});
|
|
25712
25679
|
if (file.status === "ready-meta") return /* @__PURE__ */ jsx(FileCard, {
|
|
@@ -26665,13 +26632,13 @@ function HandleMenu({ kind, index, visible, left, top, open, onOpenChange, dragg
|
|
|
26665
26632
|
})]
|
|
26666
26633
|
});
|
|
26667
26634
|
}
|
|
26668
|
-
/** The handle's menu items (in the fixed order: the background palette
|
|
26669
|
-
*
|
|
26670
|
-
* items; the edge moves are disabled). The
|
|
26671
|
-
* color is read from the store (a primitive selector: the menu
|
|
26672
|
-
* when the row/column's cells gain or lose the color — a cell
|
|
26673
|
-
* does not touch the table block, so the block's own
|
|
26674
|
-
* fire). */
|
|
26635
|
+
/** The handle's menu items (in the fixed order: the background palette (the
|
|
26636
|
+
* shared's swatches — the none's swatch stands the clear), the insert / move
|
|
26637
|
+
* / duplicate / clear / delete items; the edge moves are disabled). The
|
|
26638
|
+
* background color is read from the store (a primitive selector: the menu
|
|
26639
|
+
* re-renders when the row/column's cells gain or lose the color — a cell
|
|
26640
|
+
* color change does not touch the table block, so the block's own
|
|
26641
|
+
* subscription does not fire). */
|
|
26675
26642
|
function HandleMenuItems({ tableId, kind, index, palette, atStart, atEnd, onAction, onColor }) {
|
|
26676
26643
|
const { t } = useTranslation("table");
|
|
26677
26644
|
const { store } = useEditorContext();
|
|
@@ -26706,35 +26673,21 @@ function HandleMenuItems({ tableId, kind, index, palette, atStart, atEnd, onActi
|
|
|
26706
26673
|
const selectClear = () => onAction("clear");
|
|
26707
26674
|
const selectRemove = () => onAction("remove");
|
|
26708
26675
|
const clearColor = () => onColor(null);
|
|
26709
|
-
const selectSwatch = (swatch) => (event) => {
|
|
26710
|
-
const hex = resolveColorToHex(swatch, event.currentTarget);
|
|
26711
|
-
if (hex !== null) onColor(hex);
|
|
26712
|
-
};
|
|
26713
26676
|
const column = kind === "column";
|
|
26714
26677
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
26715
|
-
/* @__PURE__ */ jsxs(DropdownMenuSub, { children: [/* @__PURE__ */ jsxs(DropdownMenuSubTrigger, { children: [/* @__PURE__ */ jsx("
|
|
26716
|
-
|
|
26717
|
-
|
|
26718
|
-
|
|
26719
|
-
|
|
26720
|
-
|
|
26721
|
-
|
|
26722
|
-
|
|
26723
|
-
|
|
26724
|
-
|
|
26725
|
-
|
|
26726
|
-
|
|
26727
|
-
title: swatch,
|
|
26728
|
-
className: "size-6",
|
|
26729
|
-
style: { background: swatch },
|
|
26730
|
-
onClick: selectSwatch(swatch)
|
|
26731
|
-
}, swatch))
|
|
26678
|
+
/* @__PURE__ */ jsxs(DropdownMenuSub, { children: [/* @__PURE__ */ jsxs(DropdownMenuSubTrigger, { children: [/* @__PURE__ */ jsx(ColorChip, { value: color }), t("menu.background")] }), /* @__PURE__ */ jsx(DropdownMenuSubContent, {
|
|
26679
|
+
"data-slot": "docblocks/table-color-palette",
|
|
26680
|
+
className: "w-auto p-2",
|
|
26681
|
+
children: /* @__PURE__ */ jsx(ColorSwatches, {
|
|
26682
|
+
colors: palette,
|
|
26683
|
+
current: color,
|
|
26684
|
+
onSelect: (hex) => onColor(hex),
|
|
26685
|
+
label: t("menu.background"),
|
|
26686
|
+
allowNone: true,
|
|
26687
|
+
noneActive: color === void 0,
|
|
26688
|
+
onSelectNone: clearColor
|
|
26689
|
+
})
|
|
26732
26690
|
})] }),
|
|
26733
|
-
color !== void 0 && /* @__PURE__ */ jsx(DropdownMenuItem, {
|
|
26734
|
-
"data-slot": "docblocks/table-remove-color",
|
|
26735
|
-
onSelect: clearColor,
|
|
26736
|
-
children: t("menu.removeBackground")
|
|
26737
|
-
}),
|
|
26738
26691
|
/* @__PURE__ */ jsx(DropdownMenuItem, {
|
|
26739
26692
|
onSelect: selectInsertAfter,
|
|
26740
26693
|
children: column ? t("menu.insertRight") : t("menu.insertBelow")
|
|
@@ -27580,6 +27533,7 @@ function TableBlock({ id, block }) {
|
|
|
27580
27533
|
if (kind === "column") doc.setTableColumnColor(id, index, color);
|
|
27581
27534
|
else doc.setTableRowColor(id, rowId, color);
|
|
27582
27535
|
} catch {}
|
|
27536
|
+
setMenu(null);
|
|
27583
27537
|
};
|
|
27584
27538
|
const columnCenters = [];
|
|
27585
27539
|
{
|
|
@@ -30216,7 +30170,7 @@ function publishedStandKey(doc) {
|
|
|
30216
30170
|
* its own. Safe under StrictMode double-mount: the cleanup detaches every
|
|
30217
30171
|
* subscription and destroys the view between the two mounts.
|
|
30218
30172
|
*/
|
|
30219
|
-
function EditorProviderStand({ doc, provider, blockRenderers, blobStore, databaseBridge, syncEmbedResolver, pdfPreview, mentionProvider, mentionInteractions, embedSandbox, rootBlockId, commandPalettePlaceholder, accessLevel, mode, publishedDoc, presence, hiddenAttributes, renderAttribute, attributeTypePicker, docTags, children }) {
|
|
30173
|
+
function EditorProviderStand({ doc, provider, blockRenderers, blobStore, databaseBridge, syncEmbedResolver, pdfPreview, mentionProvider, mentionInteractions, embedSandbox, rootBlockId, commandPalettePlaceholder, accessLevel, mode, publishedDoc, presence, hiddenAttributes, renderAttribute, attributeTypePicker, docTags, coverPresets, children }) {
|
|
30220
30174
|
const rootId = rootBlockId ?? doc.meta.id;
|
|
30221
30175
|
const [store] = useState(() => createEditorStore(doc, rootId));
|
|
30222
30176
|
const docRef = useRef(doc);
|
|
@@ -30372,6 +30326,7 @@ function EditorProviderStand({ doc, provider, blockRenderers, blobStore, databas
|
|
|
30372
30326
|
renderAttribute: renderAttribute ?? parent?.renderAttribute ?? null,
|
|
30373
30327
|
attributeTypePicker: attributeTypePicker ?? parent?.attributeTypePicker ?? null,
|
|
30374
30328
|
docTags: docTags ?? parent?.docTags ?? null,
|
|
30329
|
+
coverPresets: coverPresets ?? parent?.coverPresets ?? null,
|
|
30375
30330
|
embedSandbox: embedSandbox ?? parent?.embedSandbox ?? defaultEmbedSandbox,
|
|
30376
30331
|
rootBlockId: rootId,
|
|
30377
30332
|
ancestorDocIds: parent ? [...parent.ancestorDocIds, parent.doc.meta.id] : [],
|
|
@@ -30402,7 +30357,8 @@ function EditorProviderStand({ doc, provider, blockRenderers, blobStore, databas
|
|
|
30402
30357
|
hiddenAttributes,
|
|
30403
30358
|
renderAttribute,
|
|
30404
30359
|
attributeTypePicker,
|
|
30405
|
-
docTags
|
|
30360
|
+
docTags,
|
|
30361
|
+
coverPresets
|
|
30406
30362
|
]);
|
|
30407
30363
|
const inheritedPublishedStand = parentContext !== null && parentContext.mode === "published";
|
|
30408
30364
|
const rendered = effectiveAccessLevel === "viewer" && parentContext === null ? children : effectiveMode === "published" ? publishedDoc !== void 0 && publishedDoc !== null ? /* @__PURE__ */ jsx(EditorProvider, {
|
|
@@ -30545,10 +30501,10 @@ function AttributeRow({ attributeKey, label, removable, onRemove, removeAria, to
|
|
|
30545
30501
|
return /* @__PURE__ */ jsxs("div", {
|
|
30546
30502
|
"data-slot": "docblocks/attribute-row",
|
|
30547
30503
|
"data-attribute-key": attributeKey,
|
|
30548
|
-
className: "flex
|
|
30504
|
+
className: "flex items-center gap-3",
|
|
30549
30505
|
children: [
|
|
30550
30506
|
/* @__PURE__ */ jsx("span", {
|
|
30551
|
-
className: cn("w-
|
|
30507
|
+
className: cn("w-32 shrink-0 truncate text-sm text-muted-foreground", topAlign && "self-start", labelClassName),
|
|
30552
30508
|
children: label
|
|
30553
30509
|
}),
|
|
30554
30510
|
/* @__PURE__ */ jsx("div", {
|
|
@@ -30569,26 +30525,480 @@ function AttributeRow({ attributeKey, label, removable, onRemove, removeAria, to
|
|
|
30569
30525
|
});
|
|
30570
30526
|
}
|
|
30571
30527
|
//#endregion
|
|
30572
|
-
//#region src/attributes/
|
|
30573
|
-
/** The cover's
|
|
30574
|
-
|
|
30575
|
-
|
|
30576
|
-
|
|
30528
|
+
//#region src/attributes/cover.ts
|
|
30529
|
+
/** The cover's accepted upload's MIME's types (the strict's stand). */
|
|
30530
|
+
const COVER_ACCEPTED_MIME_TYPES = [
|
|
30531
|
+
"image/png",
|
|
30532
|
+
"image/jpeg",
|
|
30533
|
+
"image/webp"
|
|
30534
|
+
];
|
|
30535
|
+
/** The cover's renderable-MIME's predicate. A module-level const keeps the
|
|
30536
|
+
* predicate's identity stable (the resolution's effect's dep — an inline
|
|
30537
|
+
* arrow re-runs the effect on every render). The lenient's `image/*`'s
|
|
30538
|
+
* stand: the legacy's covers may stand a format outside the upload's
|
|
30539
|
+
* strict's gate. */
|
|
30540
|
+
const COVER_RENDERS_BYTES = (mimeType) => mimeType.startsWith("image/");
|
|
30541
|
+
/** The cover mode's ordered options (the tile's stand stands first — the
|
|
30542
|
+
* selector's default's stand). */
|
|
30543
|
+
const COVER_MODE_ORDER = ["tile", "center"];
|
|
30544
|
+
/**
|
|
30545
|
+
* The intrinsic dimensions over a decodable image blob (the
|
|
30546
|
+
* `createImageBitmap` decode probe — the bytes are never rendered).
|
|
30547
|
+
* `null` over an undecodable payload (the fail-open: the consumer's
|
|
30548
|
+
* renderer may accept a format the browser cannot probe).
|
|
30549
|
+
*/
|
|
30550
|
+
async function readImageDimensions(file) {
|
|
30551
|
+
try {
|
|
30552
|
+
const bitmap = await createImageBitmap(file);
|
|
30553
|
+
try {
|
|
30554
|
+
return {
|
|
30555
|
+
width: bitmap.width,
|
|
30556
|
+
height: bitmap.height
|
|
30557
|
+
};
|
|
30558
|
+
} finally {
|
|
30559
|
+
bitmap.close();
|
|
30560
|
+
}
|
|
30561
|
+
} catch {
|
|
30562
|
+
return null;
|
|
30563
|
+
}
|
|
30564
|
+
}
|
|
30565
|
+
/** The frame's tint's CSS variable (the cover's average color's stand
|
|
30566
|
+
* over the card's element — the border's mix's input). */
|
|
30567
|
+
const COVER_TINT_VARIABLE = "--docblocks-cover-tint-color";
|
|
30568
|
+
/** The tint's average's sample's size (the pixel's count per side — the
|
|
30569
|
+
* grid's area's mean over the image's downscale). */
|
|
30570
|
+
const TINT_SAMPLE_PX = 8;
|
|
30571
|
+
/** The image's decode over the `<img>`'s element (the SVG's stand — the
|
|
30572
|
+
* `createImageBitmap`'s rejection's parity: the engine refuses the SVG's
|
|
30573
|
+
* blob over the bitmap's API, while the image's decode accepts it over
|
|
30574
|
+
* the raster's formats' parity). The object URL's lifecycle stands the
|
|
30575
|
+
* decode's completion (the pixels' in-memory's stand over the revoke —
|
|
30576
|
+
* the draw's source is the decoded's image, not the url). */
|
|
30577
|
+
async function decodeToImage(file) {
|
|
30578
|
+
const url = URL.createObjectURL(file);
|
|
30579
|
+
const img = new Image();
|
|
30580
|
+
img.src = url;
|
|
30581
|
+
try {
|
|
30582
|
+
await img.decode();
|
|
30583
|
+
return img;
|
|
30584
|
+
} catch {
|
|
30585
|
+
return null;
|
|
30586
|
+
} finally {
|
|
30587
|
+
URL.revokeObjectURL(url);
|
|
30588
|
+
}
|
|
30589
|
+
}
|
|
30590
|
+
/** The average's color's cache over the blob's identity (the re-resolution's
|
|
30591
|
+
* no re-compute's stand; the store's change's new blob stands a fresh
|
|
30592
|
+
* entry — the weak key's stand keeps the dead blobs' garbage's parity).
|
|
30593
|
+
*/
|
|
30594
|
+
const tintColorCache = /* @__PURE__ */ new WeakMap();
|
|
30595
|
+
/**
|
|
30596
|
+
* The alpha-weighted average color over a decodable image blob (the
|
|
30597
|
+
* frame's tint's / the consumer's glow's data's source): the image stands
|
|
30598
|
+
* downscaled to the sample's grid over a canvas (the `img`'s decode — the
|
|
30599
|
+
* SVG's parity), and the mean stands the premultiplied's accumulation
|
|
30600
|
+
* (the alpha's share per pixel) — the transparent's stand no gray's pull
|
|
30601
|
+
* (the alpha fade's cover stands its solid's hue, not the fade's
|
|
30602
|
+
* average). The `rgb(...)`'s string over the computed's stand; `null`
|
|
30603
|
+
* over an undecodable payload or the canvas's absence (the jsdom's
|
|
30604
|
+
* fail-open's stand — the plain border's parity).
|
|
30605
|
+
*/
|
|
30606
|
+
async function averageColorOfBlob(file) {
|
|
30607
|
+
let cached = tintColorCache.get(file);
|
|
30608
|
+
if (cached === void 0) {
|
|
30609
|
+
cached = (async () => {
|
|
30610
|
+
const img = await decodeToImage(file);
|
|
30611
|
+
if (img === null) return null;
|
|
30612
|
+
try {
|
|
30613
|
+
const canvas = document.createElement("canvas");
|
|
30614
|
+
canvas.width = TINT_SAMPLE_PX;
|
|
30615
|
+
canvas.height = TINT_SAMPLE_PX;
|
|
30616
|
+
const ctx = canvas.getContext("2d");
|
|
30617
|
+
if (ctx === null) return null;
|
|
30618
|
+
ctx.drawImage(img, 0, 0, TINT_SAMPLE_PX, TINT_SAMPLE_PX);
|
|
30619
|
+
const data = ctx.getImageData(0, 0, TINT_SAMPLE_PX, TINT_SAMPLE_PX).data;
|
|
30620
|
+
let r = 0;
|
|
30621
|
+
let g = 0;
|
|
30622
|
+
let b = 0;
|
|
30623
|
+
let alphaSum = 0;
|
|
30624
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
30625
|
+
const alpha = (data[i + 3] ?? 0) / 255;
|
|
30626
|
+
r += (data[i] ?? 0) * alpha;
|
|
30627
|
+
g += (data[i + 1] ?? 0) * alpha;
|
|
30628
|
+
b += (data[i + 2] ?? 0) * alpha;
|
|
30629
|
+
alphaSum += alpha;
|
|
30630
|
+
}
|
|
30631
|
+
if (alphaSum === 0) return null;
|
|
30632
|
+
const mean = (sum) => Math.round(sum / alphaSum);
|
|
30633
|
+
return `rgb(${mean(r)}, ${mean(g)}, ${mean(b)})`;
|
|
30634
|
+
} catch {
|
|
30635
|
+
return null;
|
|
30636
|
+
}
|
|
30637
|
+
})();
|
|
30638
|
+
tintColorCache.set(file, cached);
|
|
30639
|
+
}
|
|
30640
|
+
return cached;
|
|
30641
|
+
}
|
|
30642
|
+
/**
|
|
30643
|
+
* The banner's bottom fade-out's mask (the last pixels' smooth stand into
|
|
30644
|
+
* the page's content) — the mask's stand over both modes (the layer's /
|
|
30645
|
+
* the image's stand share the wrapper's stand). The smooth's stand is the
|
|
30646
|
+
* default's (the soft's bottom's edge).
|
|
30647
|
+
*/
|
|
30648
|
+
function coverFadeMask(mode = "smooth") {
|
|
30649
|
+
const depth = 16;
|
|
30650
|
+
if (mode === "linear") return `linear-gradient(to bottom, #000 calc(100% - ${depth}px), transparent 100%)`;
|
|
30651
|
+
const stop = (t) => `rgba(0, 0, 0, ${(1 - t) ** 2}) calc(100% - ${depth * (1 - t)}px)`;
|
|
30652
|
+
return `linear-gradient(to bottom, #000 calc(100% - ${depth}px), ${stop(.25)}, ${stop(.5)}, ${stop(.75)}, transparent 100%)`;
|
|
30653
|
+
}
|
|
30654
|
+
/** The mode's switch's gate over the stored cover's dimensions (the
|
|
30655
|
+
* toggle's disabled's stand): a mode's option stands disabled only when
|
|
30656
|
+
* its gate is known unmet over the image — the centering's minimum width
|
|
30657
|
+
* over the editor width, the tile's minimum height. The unknown's
|
|
30658
|
+
* dimensions' / the no-layout's width's stand keep the option's enabled
|
|
30659
|
+
* stand (the fail-open's parity over the upload's gate). */
|
|
30660
|
+
function coverModeGating(dimensions, editorWidthPx) {
|
|
30661
|
+
if (dimensions === null) return {
|
|
30662
|
+
tileDisabled: false,
|
|
30663
|
+
centerDisabled: false
|
|
30664
|
+
};
|
|
30665
|
+
return {
|
|
30666
|
+
tileDisabled: dimensions.height < 150,
|
|
30667
|
+
centerDisabled: editorWidthPx > 0 && dimensions.width < editorWidthPx
|
|
30668
|
+
};
|
|
30669
|
+
}
|
|
30670
|
+
/** The cover mode's read over the stored value: the absent's / the
|
|
30671
|
+
* non-center's stand stands the tile (the stored value's vocabulary is
|
|
30672
|
+
* the "center"'s single entry — the tile's stand is the key's absence). */
|
|
30673
|
+
function coverModeOf(value) {
|
|
30674
|
+
return value === "center" ? "center" : "tile";
|
|
30675
|
+
}
|
|
30676
|
+
/**
|
|
30677
|
+
* The cover upload's validation over the mode: the accepted MIME's gate
|
|
30678
|
+
* (the strict's png/jpeg/webp's stand), then the intrinsic dimension's gate —
|
|
30679
|
+
* the tile's minimum height, the centering's minimum width over the
|
|
30680
|
+
* editor's live width (the measured column's box). `editorWidthPx` of
|
|
30681
|
+
* zero or less stands the width check's fail-open (the no-layout's stand).
|
|
30682
|
+
* An undecodable payload stands the fail-open over the dimension's gates.
|
|
30683
|
+
*/
|
|
30684
|
+
async function validateCoverUpload(file, mode, editorWidthPx) {
|
|
30685
|
+
if (!COVER_ACCEPTED_MIME_TYPES.includes(file.type)) return {
|
|
30686
|
+
ok: false,
|
|
30687
|
+
reason: "unsupported"
|
|
30688
|
+
};
|
|
30689
|
+
const dimensions = await readImageDimensions(file);
|
|
30690
|
+
if (dimensions === null) return { ok: true };
|
|
30691
|
+
if (mode === "tile" && dimensions.height < 150) return {
|
|
30692
|
+
ok: false,
|
|
30693
|
+
reason: "tooShort"
|
|
30694
|
+
};
|
|
30695
|
+
if (mode === "center" && editorWidthPx > 0 && dimensions.width < editorWidthPx) return {
|
|
30696
|
+
ok: false,
|
|
30697
|
+
reason: "tooNarrow"
|
|
30698
|
+
};
|
|
30699
|
+
return { ok: true };
|
|
30700
|
+
}
|
|
30701
|
+
/**
|
|
30702
|
+
* The tile mode's background stand: the image's strip stands scaled to the
|
|
30703
|
+
* fixed's strip's height (the width's proportional), centered, and repeated
|
|
30704
|
+
* horizontally (the narrow's strip's copies glue left and right to the
|
|
30705
|
+
* container's edge; the wide's single copy stands the centered's crop).
|
|
30706
|
+
*/
|
|
30707
|
+
function tileBackgroundStyle(url) {
|
|
30708
|
+
return {
|
|
30709
|
+
height: 150,
|
|
30710
|
+
backgroundImage: `url("${url}")`,
|
|
30711
|
+
backgroundSize: `auto 150px`,
|
|
30712
|
+
backgroundPosition: "center",
|
|
30713
|
+
backgroundRepeat: "repeat-x"
|
|
30714
|
+
};
|
|
30715
|
+
}
|
|
30716
|
+
/**
|
|
30717
|
+
* The centering mode's background stand: the image's width stands scaled to
|
|
30718
|
+
* the container's width (the height's proportional), and the wrapper's
|
|
30719
|
+
* height stands the centered's slice over that scaled height (capped at the
|
|
30720
|
+
* maximum's stand — the narrower's scaled height stands its own). The
|
|
30721
|
+
* vertical centering crops the excess top and bottom evenly. The
|
|
30722
|
+
* zero-container's stand (the no-layout's jsdom) stands the maximum's
|
|
30723
|
+
* height's fail-open.
|
|
30724
|
+
*/
|
|
30725
|
+
function centerBackgroundStyle(dimensions, containerWidthPx, url) {
|
|
30726
|
+
const scaledHeight = containerWidthPx > 0 ? dimensions.height * (containerWidthPx / dimensions.width) : 150;
|
|
30727
|
+
return {
|
|
30728
|
+
height: Math.min(150, scaledHeight),
|
|
30729
|
+
backgroundImage: `url("${url}")`,
|
|
30730
|
+
backgroundSize: "100% auto",
|
|
30731
|
+
backgroundPosition: "center",
|
|
30732
|
+
backgroundRepeat: "no-repeat"
|
|
30733
|
+
};
|
|
30734
|
+
}
|
|
30735
|
+
//#endregion
|
|
30736
|
+
//#region src/attributes/CoverUploadModal.tsx
|
|
30737
|
+
/** The cover upload's modal (the portaled dialog over the row's upload
|
|
30738
|
+
* entry): the placement mode's selector (the tile / the centering), the
|
|
30739
|
+
* drop zone (the drag-and-drop's stand + the click's standard picker, the
|
|
30740
|
+
* strict's png/jpeg/webp's accept), the mode's rule's info (the validation's
|
|
30741
|
+
* gate over the upload), and the rejection's hint. The gate stands
|
|
30742
|
+
* pre-upload: a rejected file's bytes never reach the consumer's store;
|
|
30743
|
+
* the commit stands the id + the mode over the caller's write. */
|
|
30744
|
+
/** The editor frame's selector (the editor width's source — the measured
|
|
30745
|
+
* frame's box over the anchor's nearest editor root). */
|
|
30746
|
+
const EDITOR_SELECTOR$1 = "[data-slot=\"docblocks/editor\"]";
|
|
30747
|
+
/** The file picker's accept's list (the strict's gate's declarative's
|
|
30748
|
+
* stand — the MIME's gate over the chosen file enforces the same
|
|
30749
|
+
* vocabulary). */
|
|
30750
|
+
const COVER_ACCEPTED_MIME_TYPES_LIST = COVER_ACCEPTED_MIME_TYPES.join(",");
|
|
30751
|
+
/** The editor width's read over the anchor (the no-page / no-layout's
|
|
30752
|
+
* stand keeps zero — the width gate's fail-open). */
|
|
30753
|
+
function editorWidthOf(anchor) {
|
|
30754
|
+
const editor = anchor?.closest(EDITOR_SELECTOR$1) ?? null;
|
|
30755
|
+
if (editor === null) return 0;
|
|
30756
|
+
return Math.round(editor.getBoundingClientRect().width);
|
|
30757
|
+
}
|
|
30758
|
+
/** A preset grid's cell: the consumer's store's id resolved to the
|
|
30759
|
+
* thumbnail (the bytes' stand — the preset's id is the consumer's store's
|
|
30760
|
+
* id, the same one the banner's resolution stands); the placeholder over
|
|
30761
|
+
* the loading / the missing's stands. A pick commits the id over the
|
|
30762
|
+
* caller's mode (the upload's no stand — the consumer's catalog's curation
|
|
30763
|
+
* is the gate's stand over the presets). */
|
|
30764
|
+
function CoverPresetCell({ fileId, label, busy, onPick }) {
|
|
30765
|
+
const file = useBlobFile(fileId, COVER_RENDERS_BYTES);
|
|
30766
|
+
return /* @__PURE__ */ jsx("button", {
|
|
30767
|
+
type: "button",
|
|
30768
|
+
"data-slot": "docblocks/cover-preset",
|
|
30769
|
+
"data-cover-preset-id": fileId,
|
|
30770
|
+
"aria-label": label,
|
|
30771
|
+
title: label,
|
|
30772
|
+
disabled: busy,
|
|
30773
|
+
onClick: onPick,
|
|
30774
|
+
className: "\n flex h-18 w-full items-center justify-center overflow-hidden rounded-md border border-border bg-muted\n text-muted-foreground\n hover:border-primary\n disabled:opacity-60\n ",
|
|
30775
|
+
children: file.status === "ready" ? /* @__PURE__ */ jsx("img", {
|
|
30776
|
+
src: file.url,
|
|
30777
|
+
alt: "",
|
|
30778
|
+
className: "size-full object-cover"
|
|
30779
|
+
}) : /* @__PURE__ */ jsx(Image$1, { className: "size-4" })
|
|
30780
|
+
});
|
|
30781
|
+
}
|
|
30782
|
+
function CoverUploadModal({ anchorRef, initialMode, onCommit, onClose }) {
|
|
30577
30783
|
const { t } = useTranslation("editor");
|
|
30578
|
-
const { blobStore } = useEditorContext();
|
|
30579
|
-
const
|
|
30784
|
+
const { blobStore, coverPresets } = useEditorContext();
|
|
30785
|
+
const [mode, setMode] = useState(initialMode);
|
|
30786
|
+
const presets = coverPresets?.[mode] ?? [];
|
|
30787
|
+
const hasPresets = (coverPresets?.tile?.length ?? 0) + (coverPresets?.center?.length ?? 0) > 0;
|
|
30788
|
+
const [dragOver, setDragOver] = useState(false);
|
|
30789
|
+
const [busy, setBusy] = useState(false);
|
|
30790
|
+
/** The rejection's hint (the gate's / the upload's failure's stand; the
|
|
30791
|
+
* next attempt's start clears it). */
|
|
30792
|
+
const [error, setError] = useState(null);
|
|
30580
30793
|
const inputRef = useRef(null);
|
|
30581
|
-
const
|
|
30582
|
-
|
|
30583
|
-
|
|
30794
|
+
const overlayRef = useRef(null);
|
|
30795
|
+
const dialogRef = useRef(null);
|
|
30796
|
+
const busyRef = useRef(false);
|
|
30797
|
+
busyRef.current = busy;
|
|
30798
|
+
const closeRef = useRef(onClose);
|
|
30799
|
+
closeRef.current = onClose;
|
|
30800
|
+
const [editorWidth, setEditorWidth] = useState(0);
|
|
30801
|
+
useLayoutEffect(() => {
|
|
30802
|
+
setEditorWidth(editorWidthOf(anchorRef.current));
|
|
30803
|
+
}, [anchorRef]);
|
|
30804
|
+
useLayoutEffect(() => {
|
|
30805
|
+
dialogRef.current?.focus();
|
|
30806
|
+
}, []);
|
|
30807
|
+
useEffect(() => () => {
|
|
30808
|
+
if (anchorRef.current !== null && anchorRef.current.isConnected) anchorRef.current.focus();
|
|
30809
|
+
}, [anchorRef]);
|
|
30810
|
+
useEffect(() => {
|
|
30811
|
+
const onKeyDown = (event) => {
|
|
30812
|
+
if (event.key === "Escape" && !busyRef.current) {
|
|
30813
|
+
event.stopPropagation();
|
|
30814
|
+
closeRef.current();
|
|
30815
|
+
}
|
|
30816
|
+
};
|
|
30817
|
+
document.addEventListener("keydown", onKeyDown, true);
|
|
30818
|
+
return () => document.removeEventListener("keydown", onKeyDown, true);
|
|
30819
|
+
}, []);
|
|
30820
|
+
const onOverlayMouseDown = (event) => {
|
|
30821
|
+
if (event.target === overlayRef.current && !busyRef.current) closeRef.current();
|
|
30822
|
+
};
|
|
30823
|
+
const onOverlayDragOver = (event) => {
|
|
30824
|
+
event.preventDefault();
|
|
30825
|
+
};
|
|
30826
|
+
const onOverlayDrop = (event) => {
|
|
30827
|
+
event.preventDefault();
|
|
30828
|
+
};
|
|
30829
|
+
const handleFile = useCallback(async (file) => {
|
|
30830
|
+
setError(null);
|
|
30831
|
+
const width = editorWidthOf(anchorRef.current);
|
|
30832
|
+
const verdict = await validateCoverUpload(file, mode, width);
|
|
30833
|
+
if (!verdict.ok) {
|
|
30834
|
+
const hint = verdict.reason === "unsupported" ? t("attributes.coverUnsupportedType") : verdict.reason === "tooShort" ? t("attributes.coverTooShort", { min: 150 }) : t("attributes.coverTooNarrow", { min: width });
|
|
30835
|
+
setError(hint);
|
|
30836
|
+
return;
|
|
30837
|
+
}
|
|
30838
|
+
setBusy(true);
|
|
30584
30839
|
try {
|
|
30585
|
-
|
|
30840
|
+
onCommit(await blobStore.upload(file), mode);
|
|
30841
|
+
onClose();
|
|
30842
|
+
} catch {
|
|
30843
|
+
setError(t("attributes.coverUploadFailed"));
|
|
30586
30844
|
} finally {
|
|
30587
|
-
|
|
30845
|
+
setBusy(false);
|
|
30588
30846
|
}
|
|
30847
|
+
}, [
|
|
30848
|
+
anchorRef,
|
|
30849
|
+
blobStore,
|
|
30850
|
+
mode,
|
|
30851
|
+
onClose,
|
|
30852
|
+
onCommit,
|
|
30853
|
+
t
|
|
30854
|
+
]);
|
|
30855
|
+
const onInputChange = (event) => {
|
|
30856
|
+
const file = event.target.files?.[0];
|
|
30857
|
+
event.target.value = "";
|
|
30858
|
+
if (file !== void 0) handleFile(file);
|
|
30859
|
+
};
|
|
30860
|
+
const onDrop = (event) => {
|
|
30861
|
+
event.preventDefault();
|
|
30862
|
+
setDragOver(false);
|
|
30863
|
+
const file = event.dataTransfer.files?.[0];
|
|
30864
|
+
if (file !== void 0) handleFile(file);
|
|
30589
30865
|
};
|
|
30866
|
+
const modeOptions = COVER_MODE_ORDER.map((value) => ({
|
|
30867
|
+
value,
|
|
30868
|
+
label: t(value === "tile" ? "attributes.coverModeTile" : "attributes.coverModeCenter")
|
|
30869
|
+
}));
|
|
30870
|
+
return createPortal(/* @__PURE__ */ jsx("div", {
|
|
30871
|
+
ref: overlayRef,
|
|
30872
|
+
"data-slot": "docblocks/cover-upload",
|
|
30873
|
+
className: "fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",
|
|
30874
|
+
onMouseDown: onOverlayMouseDown,
|
|
30875
|
+
onDragOver: onOverlayDragOver,
|
|
30876
|
+
onDrop: onOverlayDrop,
|
|
30877
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
30878
|
+
ref: dialogRef,
|
|
30879
|
+
role: "dialog",
|
|
30880
|
+
"aria-modal": true,
|
|
30881
|
+
"aria-label": t("attributes.coverUploadTitle"),
|
|
30882
|
+
"data-slot": "docblocks/cover-upload-dialog",
|
|
30883
|
+
tabIndex: -1,
|
|
30884
|
+
className: cn("max-w-full rounded-lg border border-border bg-popover p-4 text-foreground shadow-lg outline-none", hasPresets ? "w-140" : "w-110"),
|
|
30885
|
+
children: [
|
|
30886
|
+
/* @__PURE__ */ jsxs("div", {
|
|
30887
|
+
className: "mb-3 flex items-center justify-between gap-2",
|
|
30888
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
30889
|
+
className: "text-sm font-medium",
|
|
30890
|
+
children: t("attributes.coverUploadTitle")
|
|
30891
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
30892
|
+
type: "button",
|
|
30893
|
+
variant: "ghost",
|
|
30894
|
+
size: "icon",
|
|
30895
|
+
"aria-label": t("attributes.closeCoverUploadAria"),
|
|
30896
|
+
"data-slot": "docblocks/cover-upload-close",
|
|
30897
|
+
className: "size-6 text-muted-foreground hover:bg-muted/50 hover:text-foreground dark:hover:bg-muted/50",
|
|
30898
|
+
onClick: () => {
|
|
30899
|
+
if (!busyRef.current) closeRef.current();
|
|
30900
|
+
},
|
|
30901
|
+
children: /* @__PURE__ */ jsx(X, { className: "size-3.5" })
|
|
30902
|
+
})]
|
|
30903
|
+
}),
|
|
30904
|
+
/* @__PURE__ */ jsx(SegmentSelector, {
|
|
30905
|
+
size: "text",
|
|
30906
|
+
ariaLabel: t("attributes.coverMode"),
|
|
30907
|
+
slot: "docblocks/cover-upload-mode",
|
|
30908
|
+
pillSlot: "docblocks/cover-upload-mode-pill",
|
|
30909
|
+
buttonAttrName: "mode",
|
|
30910
|
+
options: modeOptions,
|
|
30911
|
+
value: mode,
|
|
30912
|
+
onChange: (next) => {
|
|
30913
|
+
setMode(next);
|
|
30914
|
+
setError(null);
|
|
30915
|
+
}
|
|
30916
|
+
}),
|
|
30917
|
+
presets.length > 0 ? /* @__PURE__ */ jsxs("div", {
|
|
30918
|
+
className: "mt-3",
|
|
30919
|
+
"data-slot": "docblocks/cover-preset-grid",
|
|
30920
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
30921
|
+
className: "mb-1.5 block text-xs text-muted-foreground",
|
|
30922
|
+
children: t("attributes.coverPresetsLabel")
|
|
30923
|
+
}), /* @__PURE__ */ jsx(ScrollArea, {
|
|
30924
|
+
className: "max-h-58",
|
|
30925
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
30926
|
+
className: "grid grid-cols-4 gap-2",
|
|
30927
|
+
"data-slot": "docblocks/cover-preset-cells",
|
|
30928
|
+
children: presets.map((fileId) => /* @__PURE__ */ jsx(CoverPresetCell, {
|
|
30929
|
+
fileId,
|
|
30930
|
+
busy,
|
|
30931
|
+
label: t("attributes.coverPresetAria", { id: fileId }),
|
|
30932
|
+
onPick: () => {
|
|
30933
|
+
onCommit(fileId, mode);
|
|
30934
|
+
onClose();
|
|
30935
|
+
}
|
|
30936
|
+
}, fileId))
|
|
30937
|
+
})
|
|
30938
|
+
})]
|
|
30939
|
+
}) : null,
|
|
30940
|
+
/* @__PURE__ */ jsx("input", {
|
|
30941
|
+
ref: inputRef,
|
|
30942
|
+
type: "file",
|
|
30943
|
+
accept: COVER_ACCEPTED_MIME_TYPES_LIST,
|
|
30944
|
+
className: "hidden",
|
|
30945
|
+
"aria-label": t("attributes.coverUploadHint"),
|
|
30946
|
+
"data-slot": "docblocks/cover-upload-input",
|
|
30947
|
+
onChange: onInputChange
|
|
30948
|
+
}),
|
|
30949
|
+
/* @__PURE__ */ jsxs("button", {
|
|
30950
|
+
type: "button",
|
|
30951
|
+
"data-slot": "docblocks/cover-upload-dropzone",
|
|
30952
|
+
"aria-label": t("attributes.coverUploadHint"),
|
|
30953
|
+
disabled: busy,
|
|
30954
|
+
className: cn(`
|
|
30955
|
+
mt-3 flex h-36 w-full flex-col items-center justify-center gap-1.5 rounded-md border border-dashed
|
|
30956
|
+
text-muted-foreground
|
|
30957
|
+
`, "hover:bg-muted/50", dragOver && "border-primary bg-accent/50 text-foreground", busy && "opacity-60"),
|
|
30958
|
+
onClick: () => {
|
|
30959
|
+
if (!busyRef.current) inputRef.current?.click();
|
|
30960
|
+
},
|
|
30961
|
+
onDragOver: (event) => {
|
|
30962
|
+
event.preventDefault();
|
|
30963
|
+
setDragOver(true);
|
|
30964
|
+
},
|
|
30965
|
+
onDragLeave: () => setDragOver(false),
|
|
30966
|
+
onDrop,
|
|
30967
|
+
children: [/* @__PURE__ */ jsx(Image$1, { className: "size-5" }), /* @__PURE__ */ jsx("span", {
|
|
30968
|
+
className: "px-3 text-center text-xs",
|
|
30969
|
+
children: t("attributes.coverUploadHint")
|
|
30970
|
+
})]
|
|
30971
|
+
}),
|
|
30972
|
+
/* @__PURE__ */ jsx("p", {
|
|
30973
|
+
"data-slot": "docblocks/cover-upload-info",
|
|
30974
|
+
className: "mt-2 text-xs text-muted-foreground",
|
|
30975
|
+
children: mode === "tile" ? t("attributes.coverInfoMinHeight", { min: 150 }) : t("attributes.coverInfoMinWidth", { min: editorWidth })
|
|
30976
|
+
}),
|
|
30977
|
+
error !== null ? /* @__PURE__ */ jsx("p", {
|
|
30978
|
+
"data-slot": "docblocks/cover-upload-error",
|
|
30979
|
+
role: "alert",
|
|
30980
|
+
className: "mt-2 text-xs text-destructive",
|
|
30981
|
+
children: error
|
|
30982
|
+
}) : null
|
|
30983
|
+
]
|
|
30984
|
+
})
|
|
30985
|
+
}), document.body);
|
|
30986
|
+
}
|
|
30987
|
+
//#endregion
|
|
30988
|
+
//#region src/attributes/CoverEditor.tsx
|
|
30989
|
+
/** The cover's row's control (the file id's thumbnail / the upload's
|
|
30990
|
+
* entry / the remove; the read-only stand stands the thumbnail
|
|
30991
|
+
* display-only). The upload's entry opens the modal (the mode's
|
|
30992
|
+
* selector + the drop zone + the gate's stands live over it). */
|
|
30993
|
+
function CoverEditor({ fileId, mode, readOnly, onCommit, onClear }) {
|
|
30994
|
+
const { t } = useTranslation("editor");
|
|
30995
|
+
const file = useBlobFile(fileId ?? "", COVER_RENDERS_BYTES);
|
|
30996
|
+
const [open, setOpen] = useState(false);
|
|
30997
|
+
const anchorRef = useRef(null);
|
|
30590
30998
|
return /* @__PURE__ */ jsxs("div", {
|
|
30591
|
-
|
|
30999
|
+
ref: anchorRef,
|
|
31000
|
+
tabIndex: -1,
|
|
31001
|
+
className: "flex min-w-0 items-center gap-2 outline-none",
|
|
30592
31002
|
children: [
|
|
30593
31003
|
fileId !== void 0 && (file.status === "ready" || file.status === "ready-meta") ? /* @__PURE__ */ jsx("span", {
|
|
30594
31004
|
"data-slot": "docblocks/attributes-cover",
|
|
@@ -30603,15 +31013,6 @@ function CoverEditor({ fileId, readOnly, onSet, onClear }) {
|
|
|
30603
31013
|
className: "px-1.5 py-1 text-sm text-muted-foreground",
|
|
30604
31014
|
children: t("attributes.notSet")
|
|
30605
31015
|
}),
|
|
30606
|
-
readOnly ? null : /* @__PURE__ */ jsx("input", {
|
|
30607
|
-
ref: inputRef,
|
|
30608
|
-
type: "file",
|
|
30609
|
-
accept: "image/*",
|
|
30610
|
-
className: "hidden",
|
|
30611
|
-
"aria-label": t("attributes.uploadCoverAria"),
|
|
30612
|
-
"data-slot": "docblocks/attributes-cover-upload",
|
|
30613
|
-
onChange: (event) => void onUpload(event)
|
|
30614
|
-
}),
|
|
30615
31016
|
readOnly ? null : /* @__PURE__ */ jsx(Button, {
|
|
30616
31017
|
type: "button",
|
|
30617
31018
|
variant: "ghost",
|
|
@@ -30619,8 +31020,8 @@ function CoverEditor({ fileId, readOnly, onSet, onClear }) {
|
|
|
30619
31020
|
"aria-label": t("attributes.uploadCoverAria"),
|
|
30620
31021
|
"data-slot": "docblocks/attributes-cover-upload-button",
|
|
30621
31022
|
className: "size-6 text-muted-foreground hover:bg-muted/50 hover:text-foreground dark:hover:bg-muted/50",
|
|
30622
|
-
onClick: () =>
|
|
30623
|
-
children: /* @__PURE__ */ jsx(Image, { className: "size-3.5" })
|
|
31023
|
+
onClick: () => setOpen(true),
|
|
31024
|
+
children: /* @__PURE__ */ jsx(Image$1, { className: "size-3.5" })
|
|
30624
31025
|
}),
|
|
30625
31026
|
fileId !== void 0 && !readOnly ? /* @__PURE__ */ jsx(Button, {
|
|
30626
31027
|
type: "button",
|
|
@@ -30631,11 +31032,89 @@ function CoverEditor({ fileId, readOnly, onSet, onClear }) {
|
|
|
30631
31032
|
className: "size-6 text-muted-foreground hover:bg-muted/50 hover:text-foreground dark:hover:bg-muted/50",
|
|
30632
31033
|
onClick: onClear,
|
|
30633
31034
|
children: /* @__PURE__ */ jsx(X, { className: "size-3.5" })
|
|
31035
|
+
}) : null,
|
|
31036
|
+
open && !readOnly ? /* @__PURE__ */ jsx(CoverUploadModal, {
|
|
31037
|
+
anchorRef,
|
|
31038
|
+
initialMode: mode,
|
|
31039
|
+
onCommit,
|
|
31040
|
+
onClose: () => setOpen(false)
|
|
30634
31041
|
}) : null
|
|
30635
31042
|
]
|
|
30636
31043
|
});
|
|
30637
31044
|
}
|
|
30638
31045
|
//#endregion
|
|
31046
|
+
//#region src/attributes/CoverModeSelector.tsx
|
|
31047
|
+
/** The cover mode's row's selector (the panel's toggle over the stored
|
|
31048
|
+
* cover): the tile / the centering's options stand the switch's gate —
|
|
31049
|
+
* an option stands disabled when its gate is known unmet over the
|
|
31050
|
+
* current image (the centering's minimum width over the editor width,
|
|
31051
|
+
* the tile's minimum height; the unknown's dimensions' fail-open keeps
|
|
31052
|
+
* it enabled). The editor width stands measured over the anchor's
|
|
31053
|
+
* nearest editor frame. */
|
|
31054
|
+
/** The editor frame's selector (the width's measurement's source). */
|
|
31055
|
+
const EDITOR_SELECTOR = "[data-slot=\"docblocks/editor\"]";
|
|
31056
|
+
function CoverModeSelector({ coverId, mode, readOnly, onChange }) {
|
|
31057
|
+
const { t } = useTranslation("editor");
|
|
31058
|
+
const file = useBlobFile(coverId, COVER_RENDERS_BYTES);
|
|
31059
|
+
const blob = file.status === "ready" ? file.blob : null;
|
|
31060
|
+
/** The intrinsic dimensions' probe (the gate's input — the undecodable's
|
|
31061
|
+
* payload keeps the gate's fail-open stand). */
|
|
31062
|
+
const [dimensions, setDimensions] = useState(null);
|
|
31063
|
+
useLayoutEffect(() => {
|
|
31064
|
+
if (blob === null) {
|
|
31065
|
+
setDimensions(null);
|
|
31066
|
+
return;
|
|
31067
|
+
}
|
|
31068
|
+
let alive = true;
|
|
31069
|
+
readImageDimensions(blob).then((next) => {
|
|
31070
|
+
if (alive) setDimensions(next);
|
|
31071
|
+
});
|
|
31072
|
+
return () => {
|
|
31073
|
+
alive = false;
|
|
31074
|
+
};
|
|
31075
|
+
}, [blob]);
|
|
31076
|
+
/** The editor frame's live width (the centering's gate's input): the
|
|
31077
|
+
* anchor's nearest editor frame's box over the mount's measure + the
|
|
31078
|
+
* resize's watch (the jsdom's no-layout's stand keeps the zero's value
|
|
31079
|
+
* — the gate's fail-open). */
|
|
31080
|
+
const zoneRef = useRef(null);
|
|
31081
|
+
const [editorWidth, setEditorWidth] = useState(0);
|
|
31082
|
+
useLayoutEffect(() => {
|
|
31083
|
+
const editor = zoneRef.current?.closest(EDITOR_SELECTOR) ?? null;
|
|
31084
|
+
if (editor === null) return;
|
|
31085
|
+
const measure = () => {
|
|
31086
|
+
setEditorWidth((prev) => prev === editor.clientWidth ? prev : editor.clientWidth);
|
|
31087
|
+
};
|
|
31088
|
+
measure();
|
|
31089
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
31090
|
+
const observer = new ResizeObserver(measure);
|
|
31091
|
+
observer.observe(editor);
|
|
31092
|
+
return () => observer.disconnect();
|
|
31093
|
+
}, []);
|
|
31094
|
+
const gating = coverModeGating(dimensions, editorWidth);
|
|
31095
|
+
const options = COVER_MODE_ORDER.map((value) => ({
|
|
31096
|
+
value,
|
|
31097
|
+
label: t(value === "tile" ? "attributes.coverModeTile" : "attributes.coverModeCenter"),
|
|
31098
|
+
disabled: readOnly || (value === "tile" ? gating.tileDisabled : gating.centerDisabled)
|
|
31099
|
+
}));
|
|
31100
|
+
return /* @__PURE__ */ jsx("div", {
|
|
31101
|
+
ref: zoneRef,
|
|
31102
|
+
children: /* @__PURE__ */ jsx(SegmentSelector, {
|
|
31103
|
+
size: "text",
|
|
31104
|
+
ariaLabel: t("attributes.coverMode"),
|
|
31105
|
+
slot: "docblocks/attributes-cover-mode",
|
|
31106
|
+
pillSlot: "docblocks/attributes-cover-mode-pill",
|
|
31107
|
+
buttonAttrName: "mode",
|
|
31108
|
+
options,
|
|
31109
|
+
value: mode,
|
|
31110
|
+
onChange: (next) => {
|
|
31111
|
+
if (next === mode) return;
|
|
31112
|
+
onChange(next);
|
|
31113
|
+
}
|
|
31114
|
+
})
|
|
31115
|
+
});
|
|
31116
|
+
}
|
|
31117
|
+
//#endregion
|
|
30639
31118
|
//#region src/attributes/presets.ts
|
|
30640
31119
|
/**
|
|
30641
31120
|
* The document-attributes panel's preset catalog: the preset keys are
|
|
@@ -30649,6 +31128,8 @@ const PRESET_KEYS = [
|
|
|
30649
31128
|
"tags",
|
|
30650
31129
|
"createdBy",
|
|
30651
31130
|
"cover",
|
|
31131
|
+
"coverMode",
|
|
31132
|
+
"coverTint",
|
|
30652
31133
|
"status",
|
|
30653
31134
|
"publishedAt"
|
|
30654
31135
|
];
|
|
@@ -31088,7 +31569,7 @@ function DraggableAttributeRow({ attributeKey, onDragStart, onDragEnd, topAlign,
|
|
|
31088
31569
|
rounded-full text-(--docblocks-gutter-color) opacity-0
|
|
31089
31570
|
group-hover:opacity-100
|
|
31090
31571
|
active:cursor-grabbing
|
|
31091
|
-
`, topAlign ? "top-
|
|
31572
|
+
`, topAlign ? "top-1.5" : "top-1/2 -translate-y-1/2"),
|
|
31092
31573
|
children: /* @__PURE__ */ jsx(GripVertical, { className: "size-4" })
|
|
31093
31574
|
}), children]
|
|
31094
31575
|
});
|
|
@@ -31101,7 +31582,7 @@ function TagsZone({ tags, readOnly, onTagAdd, onTagRemove, onTagClick }) {
|
|
|
31101
31582
|
const { t } = useTranslation("editor");
|
|
31102
31583
|
if (tags.length === 0) {
|
|
31103
31584
|
if (readOnly || onTagAdd === void 0) return /* @__PURE__ */ jsx("span", {
|
|
31104
|
-
className: "text-muted-foreground",
|
|
31585
|
+
className: "text-sm text-muted-foreground",
|
|
31105
31586
|
children: t("attributes.notSet")
|
|
31106
31587
|
});
|
|
31107
31588
|
return /* @__PURE__ */ jsxs("button", {
|
|
@@ -31200,6 +31681,7 @@ function AttributesPanel() {
|
|
|
31200
31681
|
const v = attributes[key];
|
|
31201
31682
|
return typeof v === "string" ? v : void 0;
|
|
31202
31683
|
};
|
|
31684
|
+
const coverMode = coverModeOf(value("coverMode"));
|
|
31203
31685
|
const set = (key, v) => {
|
|
31204
31686
|
try {
|
|
31205
31687
|
doc.setAttribute(key, v);
|
|
@@ -31257,7 +31739,7 @@ function AttributesPanel() {
|
|
|
31257
31739
|
return node === null ? defaultZone : node;
|
|
31258
31740
|
};
|
|
31259
31741
|
const notSet = /* @__PURE__ */ jsx("span", {
|
|
31260
|
-
className: "text-muted-foreground",
|
|
31742
|
+
className: "text-sm text-muted-foreground",
|
|
31261
31743
|
children: t("attributes.notSet")
|
|
31262
31744
|
});
|
|
31263
31745
|
const customKeysAll = Object.keys(attributes).filter((key) => !isPresetKey(key));
|
|
@@ -31415,7 +31897,7 @@ function AttributesPanel() {
|
|
|
31415
31897
|
children: [/* @__PURE__ */ jsx(ChevronDown, { className: cn("size-3.5 transition-transform", !open && "-rotate-90") }), t("attributes.title")]
|
|
31416
31898
|
}), open ? /* @__PURE__ */ jsxs("div", {
|
|
31417
31899
|
"data-slot": "docblocks/attributes-body",
|
|
31418
|
-
className: "mt-1 border-t border-muted pt-1.5",
|
|
31900
|
+
className: "mt-1 flex flex-col gap-1 border-t border-muted pt-1.5",
|
|
31419
31901
|
children: [
|
|
31420
31902
|
hidden.has("id") ? null : /* @__PURE__ */ jsx(AttributeRow, {
|
|
31421
31903
|
attributeKey: "id",
|
|
@@ -31460,12 +31942,15 @@ function AttributesPanel() {
|
|
|
31460
31942
|
attributeKey: "tags",
|
|
31461
31943
|
label: t("attributes.tags"),
|
|
31462
31944
|
removable: false,
|
|
31463
|
-
children:
|
|
31464
|
-
|
|
31465
|
-
|
|
31466
|
-
|
|
31467
|
-
|
|
31468
|
-
|
|
31945
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
31946
|
+
className: "flex min-w-0 flex-1 items-center px-1.5 py-1",
|
|
31947
|
+
children: docTags === null ? notSet : /* @__PURE__ */ jsx(TagsZone, {
|
|
31948
|
+
tags: docTags.tags,
|
|
31949
|
+
readOnly: viewMode,
|
|
31950
|
+
onTagAdd: docTags.onTagAdd,
|
|
31951
|
+
onTagRemove: docTags.onTagRemove,
|
|
31952
|
+
onTagClick: docTags.onTagClick
|
|
31953
|
+
})
|
|
31469
31954
|
})
|
|
31470
31955
|
}, "tags"),
|
|
31471
31956
|
hidden.has("createdBy") ? null : /* @__PURE__ */ jsx(AttributeRow, {
|
|
@@ -31485,11 +31970,45 @@ function AttributesPanel() {
|
|
|
31485
31970
|
removeAria: t("attributes.removeAria", { name: t("attributes.cover") }),
|
|
31486
31971
|
children: valueZone("cover", /* @__PURE__ */ jsx(CoverEditor, {
|
|
31487
31972
|
fileId: stringValue("cover"),
|
|
31973
|
+
mode: coverMode,
|
|
31488
31974
|
readOnly: viewMode,
|
|
31489
|
-
|
|
31975
|
+
onCommit: (id, mode) => {
|
|
31976
|
+
set("cover", id);
|
|
31977
|
+
if (mode === "center") set("coverMode", "center");
|
|
31978
|
+
else remove("coverMode");
|
|
31979
|
+
},
|
|
31490
31980
|
onClear: () => remove("cover")
|
|
31491
31981
|
}))
|
|
31492
31982
|
}, "cover"),
|
|
31983
|
+
has("cover") && !hidden.has("coverMode") ? /* @__PURE__ */ jsx(AttributeRow, {
|
|
31984
|
+
attributeKey: "coverMode",
|
|
31985
|
+
label: t("attributes.coverMode"),
|
|
31986
|
+
removable: false,
|
|
31987
|
+
children: valueZone("coverMode", /* @__PURE__ */ jsx(CoverModeSelector, {
|
|
31988
|
+
coverId: stringValue("cover") ?? "",
|
|
31989
|
+
mode: coverMode,
|
|
31990
|
+
readOnly: viewMode,
|
|
31991
|
+
onChange: (next) => {
|
|
31992
|
+
if (next === "center") set("coverMode", "center");
|
|
31993
|
+
else remove("coverMode");
|
|
31994
|
+
}
|
|
31995
|
+
}))
|
|
31996
|
+
}, "coverMode") : null,
|
|
31997
|
+
has("cover") && !hidden.has("coverTint") ? /* @__PURE__ */ jsx(AttributeRow, {
|
|
31998
|
+
attributeKey: "coverTint",
|
|
31999
|
+
label: t("attributes.coverTint"),
|
|
32000
|
+
removable: false,
|
|
32001
|
+
children: valueZone("coverTint", /* @__PURE__ */ jsx(Checkbox, {
|
|
32002
|
+
"data-slot": "docblocks/attributes-cover-tint",
|
|
32003
|
+
"aria-label": t("attributes.coverTintAria"),
|
|
32004
|
+
checked: value("coverTint") !== false,
|
|
32005
|
+
disabled: viewMode,
|
|
32006
|
+
onCheckedChange: (next) => {
|
|
32007
|
+
if (next === true) remove("coverTint");
|
|
32008
|
+
else set("coverTint", false);
|
|
32009
|
+
}
|
|
32010
|
+
}))
|
|
32011
|
+
}, "coverTint") : null,
|
|
31493
32012
|
hidden.has("status") ? null : /* @__PURE__ */ jsx(AttributeRow, {
|
|
31494
32013
|
attributeKey: "status",
|
|
31495
32014
|
label: t("attributes.status"),
|
|
@@ -31502,21 +32021,19 @@ function AttributesPanel() {
|
|
|
31502
32021
|
hidden.has("publishedAt") ? null : /* @__PURE__ */ jsx(AttributeRow, {
|
|
31503
32022
|
attributeKey: "publishedAt",
|
|
31504
32023
|
label: t("attributes.publishedAt"),
|
|
31505
|
-
removable:
|
|
31506
|
-
onRemove: () => remove("publishedAt"),
|
|
31507
|
-
removeAria: t("attributes.removeAria", { name: t("attributes.publishedAt") }),
|
|
32024
|
+
removable: false,
|
|
31508
32025
|
children: (() => {
|
|
31509
32026
|
const raw = stringValue("publishedAt");
|
|
31510
|
-
|
|
31511
|
-
|
|
31512
|
-
|
|
31513
|
-
|
|
31514
|
-
else set("publishedAt", next);
|
|
32027
|
+
return valueZone("publishedAt", /* @__PURE__ */ jsx("span", {
|
|
32028
|
+
"data-slot": "docblocks/attributes-published-at",
|
|
32029
|
+
className: "block truncate px-1.5 py-1 text-sm",
|
|
32030
|
+
children: raw === void 0 || raw === "" ? notSet : displayPublishedDate(raw, locale)
|
|
31515
32031
|
}));
|
|
31516
32032
|
})()
|
|
31517
32033
|
}, "publishedAt"),
|
|
31518
32034
|
viewMode ? /* @__PURE__ */ jsx("div", {
|
|
31519
32035
|
"data-slot": "docblocks/attributes-custom",
|
|
32036
|
+
className: "flex flex-col gap-1",
|
|
31520
32037
|
children: displayCustomKeys.map((key) => renderCustomRow(key))
|
|
31521
32038
|
}) : /* @__PURE__ */ jsx(Reorder.Group, {
|
|
31522
32039
|
as: "div",
|
|
@@ -31524,7 +32041,7 @@ function AttributesPanel() {
|
|
|
31524
32041
|
axis: "y",
|
|
31525
32042
|
values: displayCustomKeys,
|
|
31526
32043
|
onReorder: (next) => setDragOrder(next),
|
|
31527
|
-
className: "flex flex-col",
|
|
32044
|
+
className: "flex flex-col gap-1",
|
|
31528
32045
|
children: displayCustomKeys.map((key) => /* @__PURE__ */ jsx(DraggableAttributeRow, {
|
|
31529
32046
|
attributeKey: key,
|
|
31530
32047
|
topAlign: isListCustom(key),
|
|
@@ -31542,6 +32059,163 @@ function AttributesPanel() {
|
|
|
31542
32059
|
});
|
|
31543
32060
|
}
|
|
31544
32061
|
//#endregion
|
|
32062
|
+
//#region src/attributes/CoverBanner.tsx
|
|
32063
|
+
/** The cover's banner over the editor frame's top edge (the above-the-
|
|
32064
|
+
* page column's stand, the full frame width's bleed): the stored cover's
|
|
32065
|
+
* image rendered over the placement mode — the tile's stand (the strip
|
|
32066
|
+
* scaled to the fixed's 150 px's height, the width's proportional, the
|
|
32067
|
+
* `repeat-x`'s horizontal glue) or the centering's stand (the width
|
|
32068
|
+
* scaled to the frame's width, the centered's 150 px's vertical slice
|
|
32069
|
+
* over the scaled height). The banner is decoration only: the pointer's
|
|
32070
|
+
* transparent stand keeps the page's selection and the cross-drag's
|
|
32071
|
+
* stands untouched. The bottom's last pixels stand the fade-out's smooth
|
|
32072
|
+
* stand into the page's content. */
|
|
32073
|
+
function CoverBanner() {
|
|
32074
|
+
const { store } = useEditorContext();
|
|
32075
|
+
const attributes = useStore(store, (state) => state.meta).attributes;
|
|
32076
|
+
const coverId = typeof attributes?.cover === "string" ? attributes.cover : void 0;
|
|
32077
|
+
if (coverId === void 0) return null;
|
|
32078
|
+
return /* @__PURE__ */ jsx(CoverBannerBody, {
|
|
32079
|
+
coverId,
|
|
32080
|
+
mode: coverModeOf(attributes?.coverMode)
|
|
32081
|
+
});
|
|
32082
|
+
}
|
|
32083
|
+
/** The banner's body (the hooks' stand — the mount only over the cover's
|
|
32084
|
+
* presence, so the resolution's hook never sees the empty's id). */
|
|
32085
|
+
function CoverBannerBody({ coverId, mode }) {
|
|
32086
|
+
const file = useBlobFile(coverId, COVER_RENDERS_BYTES);
|
|
32087
|
+
const blob = file.status === "ready" ? file.blob : null;
|
|
32088
|
+
/** The intrinsic dimensions' probe (the centering's slice's input — the
|
|
32089
|
+
* width's scale over the container; the undecodable's payload stands
|
|
32090
|
+
* the fallback's plain image's stand). The tile's stand needs no probe
|
|
32091
|
+
* (the fixed's strip's height is the layout's constant). */
|
|
32092
|
+
const [dimensions, setDimensions] = useState(null);
|
|
32093
|
+
useLayoutEffect(() => {
|
|
32094
|
+
if (blob === null || mode === "tile") {
|
|
32095
|
+
setDimensions(null);
|
|
32096
|
+
return;
|
|
32097
|
+
}
|
|
32098
|
+
let alive = true;
|
|
32099
|
+
readImageDimensions(blob).then((next) => {
|
|
32100
|
+
if (alive) setDimensions(next);
|
|
32101
|
+
});
|
|
32102
|
+
return () => {
|
|
32103
|
+
alive = false;
|
|
32104
|
+
};
|
|
32105
|
+
}, [blob, mode]);
|
|
32106
|
+
/** The frame's live width (the centering's slice's height's input): the
|
|
32107
|
+
* wrapper's own box (the full frame's width's stand) over the mount's
|
|
32108
|
+
* measure + the resize's watch (the jsdom's no-layout's stand keeps the
|
|
32109
|
+
* zero's value — the maximum's height's fail-open). The effect re-runs
|
|
32110
|
+
* over the ready's stand: the wrapper commits only over the
|
|
32111
|
+
* resolution, so the mount's measure stands over its presence. */
|
|
32112
|
+
const wrapperRef = useRef(null);
|
|
32113
|
+
const [width, setWidth] = useState(0);
|
|
32114
|
+
useLayoutEffect(() => {
|
|
32115
|
+
const el = wrapperRef.current;
|
|
32116
|
+
if (el === null) return;
|
|
32117
|
+
const measure = () => {
|
|
32118
|
+
setWidth((prev) => prev === el.clientWidth ? prev : el.clientWidth);
|
|
32119
|
+
};
|
|
32120
|
+
measure();
|
|
32121
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
32122
|
+
const observer = new ResizeObserver(measure);
|
|
32123
|
+
observer.observe(el);
|
|
32124
|
+
return () => observer.disconnect();
|
|
32125
|
+
}, [file.status === "ready"]);
|
|
32126
|
+
if (file.status !== "ready") return null;
|
|
32127
|
+
return /* @__PURE__ */ jsx("div", {
|
|
32128
|
+
ref: wrapperRef,
|
|
32129
|
+
"data-slot": "docblocks/cover-banner",
|
|
32130
|
+
"data-cover-mode": mode,
|
|
32131
|
+
"aria-hidden": true,
|
|
32132
|
+
className: "pointer-events-none -mt-6 w-full overflow-hidden rounded-t-xl select-none",
|
|
32133
|
+
style: {
|
|
32134
|
+
maskImage: coverFadeMask(),
|
|
32135
|
+
WebkitMaskImage: coverFadeMask()
|
|
32136
|
+
},
|
|
32137
|
+
children: mode === "tile" ? /* @__PURE__ */ jsx("div", {
|
|
32138
|
+
className: "w-full",
|
|
32139
|
+
style: tileBackgroundStyle(file.url)
|
|
32140
|
+
}) : dimensions === null ? /* @__PURE__ */ jsx("div", {
|
|
32141
|
+
className: "flex w-full justify-center",
|
|
32142
|
+
children: /* @__PURE__ */ jsx("img", {
|
|
32143
|
+
src: file.url,
|
|
32144
|
+
alt: "",
|
|
32145
|
+
className: "max-w-full",
|
|
32146
|
+
style: { maxHeight: 150 }
|
|
32147
|
+
})
|
|
32148
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
32149
|
+
className: "w-full",
|
|
32150
|
+
style: centerBackgroundStyle(dimensions, width, file.url)
|
|
32151
|
+
})
|
|
32152
|
+
});
|
|
32153
|
+
}
|
|
32154
|
+
//#endregion
|
|
32155
|
+
//#region src/attributes/cover-tint.tsx
|
|
32156
|
+
/**
|
|
32157
|
+
* The stored cover's average color (the frame's tint's / the consumer's
|
|
32158
|
+
* glow's data's source): the cover's blob resolved over the editor's blob
|
|
32159
|
+
* store, and the alpha-weighted average read from it — the `rgb(...)`'s
|
|
32160
|
+
* string or `null` over the absent's id / the unresolved's / the
|
|
32161
|
+
* undecodable's stand. The blob's identity's cache stands the
|
|
32162
|
+
* re-resolution's no re-compute (the store's change's new blob stands the
|
|
32163
|
+
* fresh entry).
|
|
32164
|
+
*/
|
|
32165
|
+
function useCoverAverageColor() {
|
|
32166
|
+
const { store, blobStore } = useEditorContext();
|
|
32167
|
+
const attributes = useStore(store, (state) => state.meta.attributes);
|
|
32168
|
+
const coverId = typeof attributes?.cover === "string" ? attributes.cover : void 0;
|
|
32169
|
+
const [color, setColor] = useState(null);
|
|
32170
|
+
useEffect(() => {
|
|
32171
|
+
if (coverId === void 0) {
|
|
32172
|
+
setColor(null);
|
|
32173
|
+
return;
|
|
32174
|
+
}
|
|
32175
|
+
let alive = true;
|
|
32176
|
+
const settle = (next) => {
|
|
32177
|
+
if (alive) setColor(next);
|
|
32178
|
+
};
|
|
32179
|
+
const load = async () => {
|
|
32180
|
+
try {
|
|
32181
|
+
const ref = await blobStore.get(coverId);
|
|
32182
|
+
settle(await averageColorOfBlob(ref.blob));
|
|
32183
|
+
} catch {
|
|
32184
|
+
settle(null);
|
|
32185
|
+
}
|
|
32186
|
+
};
|
|
32187
|
+
const unsubscribe = blobStore.subscribe(coverId, () => {
|
|
32188
|
+
load();
|
|
32189
|
+
});
|
|
32190
|
+
load();
|
|
32191
|
+
return () => {
|
|
32192
|
+
alive = false;
|
|
32193
|
+
unsubscribe();
|
|
32194
|
+
};
|
|
32195
|
+
}, [blobStore, coverId]);
|
|
32196
|
+
return color;
|
|
32197
|
+
}
|
|
32198
|
+
/**
|
|
32199
|
+
* The tint's variable's controller (the package's internal's stand): the
|
|
32200
|
+
* average's color stood over the card's element (the border's element) as
|
|
32201
|
+
* the tint's CSS variable — the variable's removal stands over the
|
|
32202
|
+
* absent's color (the plain border's stand). The read-only's parity: the
|
|
32203
|
+
* tint is the derived's visual (the data's read stands over every mode).
|
|
32204
|
+
*/
|
|
32205
|
+
function CoverTintController({ cardRef }) {
|
|
32206
|
+
const color = useCoverAverageColor();
|
|
32207
|
+
useEffect(() => {
|
|
32208
|
+
const el = cardRef.current;
|
|
32209
|
+
if (el === null) return;
|
|
32210
|
+
if (color === null) {
|
|
32211
|
+
el.style.removeProperty(COVER_TINT_VARIABLE);
|
|
32212
|
+
return;
|
|
32213
|
+
}
|
|
32214
|
+
el.style.setProperty(COVER_TINT_VARIABLE, color);
|
|
32215
|
+
}, [cardRef, color]);
|
|
32216
|
+
return null;
|
|
32217
|
+
}
|
|
32218
|
+
//#endregion
|
|
31545
32219
|
//#region src/editing/cross-copy.ts
|
|
31546
32220
|
/** The HTML-escaped run text. */
|
|
31547
32221
|
function escapeHtml(text) {
|
|
@@ -31974,7 +32648,7 @@ function useEditing() {
|
|
|
31974
32648
|
if (inner === null) return;
|
|
31975
32649
|
const position = locatePosition(inner, event.key === "Home" ? 0 : doc.getTextLength(targetId));
|
|
31976
32650
|
applyDomSelection(position.node, position.offset, position.node, position.offset);
|
|
31977
|
-
(position.node instanceof Element ? position.node : position.node.parentElement)?.scrollIntoView({ block: event.key === "Home" ? "start" : "end" });
|
|
32651
|
+
(position.node instanceof Element ? position.node : position.node.parentElement)?.scrollIntoView?.({ block: event.key === "Home" ? "start" : "end" });
|
|
31978
32652
|
return;
|
|
31979
32653
|
}
|
|
31980
32654
|
if (viewMode) return;
|
|
@@ -33063,6 +33737,9 @@ function useMotionDrag({ doc, rootBlockId, store, rootRef, rowKeys, nodesById })
|
|
|
33063
33737
|
function Editor({ view = "page", formatPalette = FORMAT_PALETTE }) {
|
|
33064
33738
|
const { doc, store, rootBlockId, viewMode } = useEditorContext();
|
|
33065
33739
|
const rootChildren = useStore(store, (state) => state.rootChildren);
|
|
33740
|
+
const attributes = useStore(store, (state) => state.meta.attributes);
|
|
33741
|
+
const coverTintEnabled = (typeof attributes?.cover === "string" ? attributes.cover : void 0) !== void 0 && attributes?.coverTint !== false;
|
|
33742
|
+
const cardRef = useRef(null);
|
|
33066
33743
|
const pageRef = useRef(null);
|
|
33067
33744
|
const surfaceMapRef = useRef(null);
|
|
33068
33745
|
if (surfaceMapRef.current === null) surfaceMapRef.current = /* @__PURE__ */ new Map();
|
|
@@ -33131,9 +33808,11 @@ function Editor({ view = "page", formatPalette = FORMAT_PALETTE }) {
|
|
|
33131
33808
|
]),
|
|
33132
33809
|
nodesById
|
|
33133
33810
|
});
|
|
33134
|
-
return /* @__PURE__ */
|
|
33811
|
+
return /* @__PURE__ */ jsxs(Card, {
|
|
33812
|
+
ref: cardRef,
|
|
33813
|
+
"data-cover-tint": coverTintEnabled ? "" : void 0,
|
|
33135
33814
|
className: cn(view === "canvas" && "min-h-0 flex-1"),
|
|
33136
|
-
children: /* @__PURE__ */ jsx(EnumOptionsMotionSlot.Provider, {
|
|
33815
|
+
children: [/* @__PURE__ */ jsx(CoverTintController, { cardRef }), /* @__PURE__ */ jsx(EnumOptionsMotionSlot.Provider, {
|
|
33137
33816
|
value: MotionEnumOptionsEditor,
|
|
33138
33817
|
children: /* @__PURE__ */ jsxs("div", {
|
|
33139
33818
|
ref: rootRef,
|
|
@@ -33148,6 +33827,7 @@ function Editor({ view = "page", formatPalette = FORMAT_PALETTE }) {
|
|
|
33148
33827
|
onPointerDown: onCrossDragPointerDown,
|
|
33149
33828
|
children: [
|
|
33150
33829
|
/* @__PURE__ */ jsx("style", { children: HANDLE_GRAB_STYLE }),
|
|
33830
|
+
view === "canvas" ? null : /* @__PURE__ */ jsx(CoverBanner, {}),
|
|
33151
33831
|
/* @__PURE__ */ jsx(MentionMenuContext.Provider, {
|
|
33152
33832
|
value: mention.api,
|
|
33153
33833
|
children: /* @__PURE__ */ jsx(SlashMenuContext.Provider, {
|
|
@@ -33191,8 +33871,8 @@ function Editor({ view = "page", formatPalette = FORMAT_PALETTE }) {
|
|
|
33191
33871
|
viewMode ? null : format.toolbarNode
|
|
33192
33872
|
]
|
|
33193
33873
|
})
|
|
33194
|
-
})
|
|
33874
|
+
})]
|
|
33195
33875
|
});
|
|
33196
33876
|
}
|
|
33197
33877
|
//#endregion
|
|
33198
|
-
export {
|
|
33878
|
+
export { DropdownMenuSubContent as $, CodeXml as $t, SelectGroup as A, Skeleton as At, Input as B, useBlock as Bt, FilterBuilder as C, isBridgeError as Ct, ScrollArea as D, parseCellValue as Dt, SegmentSelector as E, conditionMatches as Et, SelectSeparator as F, CardFooter as Ft, DropdownMenuItem as G, useSelection as Gt, DropdownMenuCheckboxItem as H, useMeta as Ht, SelectTrigger as I, CardHeader as It, DropdownMenuRadioGroup as J, DocblocksI18nProvider as Jt, DropdownMenuLabel as K, useSelectionView as Kt, SelectValue as L, CardTitle as Lt, SelectLabel as M, CardAction as Mt, SelectScrollDownButton as N, CardContent as Nt, Select as O, TEXT_TYPES as Ot, SelectScrollUpButton as P, CardDescription as Pt, DropdownMenuSub as Q, Eye as Qt, Label as R, Badge as Rt, newMutationContext as S, BridgeError as St, filterIsComplete as T, toBridgeError as Tt, DropdownMenuContent as U, usePresence as Ut, DropdownMenu as V, useDoc as Vt, DropdownMenuGroup as W, usePresenceSharing as Wt, DropdownMenuSeparator as X, renderRuns as Xt, DropdownMenuRadioItem as Y, INLINE_CODE_CLASS as Yt, DropdownMenuShortcut as Z, Pen as Zt, mapFrontmatter as _, BASELINE_CAPABILITIES as _t, DEFAULT_EMBED_SANDBOX as a, PopoverContent as at, useDatabaseTable as b, validateProtocolDescriptor as bt, SHAPE_FONT_OPTIONS as c, PopoverTitle as ct, FORMAT_PALETTE as d, Button as dt, BookOpen as en, DropdownMenuSubTrigger as et, textOf as f, buttonVariants as ft, mdToBlocks as g, AlertTitle as gt, insertNative as h, AlertDescription as ht, useEditorContext as i, PopoverAnchor as it, SelectItem as j, Card as jt, SelectContent as k, columnAnnotation as kt, SHAPE_FONT_STACKS as l, PopoverTrigger as lt, htmlToBlocks as m, Alert as mt, useCoverAverageColor as n, Separator as nt, childrenSlot as o, PopoverDescription as ot, markToggleAction as p, BareSelect as pt, DropdownMenuPortal as q, useText as qt, EditorProvider as r, Popover as rt, CodeHeader as s, PopoverHeader as st, Editor as t, createMemoryBlobStore as tn, DropdownMenuTrigger as tt, TextBlock as u, Checkbox as ut, parseFrontmatter as v, PROTOCOL_VERSION as vt, emptyFilter as w, isBridgeErrorCode as wt, cellValueEqual as x, BRIDGE_ERROR_CODES as xt, GridBody as y, isDatabaseBridge as yt, InlineEditInput as z, badgeVariants as zt };
|