docblocks-react-ui 0.10.1 → 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 +64 -0
- package/README.md +26 -3
- package/dist/{Editor-DKO25suc.mjs → Editor-g5aY0giB.mjs} +790 -33
- 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 +84 -0
- 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,
|
|
@@ -4008,6 +4008,22 @@ const INIT_OPTIONS = {
|
|
|
4008
4008
|
"addTagAria": "Add a tag",
|
|
4009
4009
|
"uploadCoverAria": "Upload the cover",
|
|
4010
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",
|
|
4011
4027
|
"addAttribute": "Add attribute",
|
|
4012
4028
|
"addConfirm": "Add",
|
|
4013
4029
|
"keyReserved": "The key cannot be used (a reserved document key)."
|
|
@@ -4501,6 +4517,22 @@ const INIT_OPTIONS = {
|
|
|
4501
4517
|
"addTagAria": "Добавить тег",
|
|
4502
4518
|
"uploadCoverAria": "Загрузить обложку",
|
|
4503
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": "Закрыть загрузку обложки",
|
|
4504
4536
|
"addAttribute": "Добавить атрибут",
|
|
4505
4537
|
"addConfirm": "Добавить",
|
|
4506
4538
|
"keyReserved": "Ключ использовать нельзя (зарезервированный ключ документа)."
|
|
@@ -25641,7 +25673,7 @@ function ImageBlock({ id, block }) {
|
|
|
25641
25673
|
className: BLOB_PLACEHOLDER_CLASS,
|
|
25642
25674
|
children: /* @__PURE__ */ jsxs(CardContent, {
|
|
25643
25675
|
className: "flex flex-col items-center gap-2 text-center",
|
|
25644
|
-
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")]
|
|
25645
25677
|
})
|
|
25646
25678
|
});
|
|
25647
25679
|
if (file.status === "ready-meta") return /* @__PURE__ */ jsx(FileCard, {
|
|
@@ -30138,7 +30170,7 @@ function publishedStandKey(doc) {
|
|
|
30138
30170
|
* its own. Safe under StrictMode double-mount: the cleanup detaches every
|
|
30139
30171
|
* subscription and destroys the view between the two mounts.
|
|
30140
30172
|
*/
|
|
30141
|
-
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 }) {
|
|
30142
30174
|
const rootId = rootBlockId ?? doc.meta.id;
|
|
30143
30175
|
const [store] = useState(() => createEditorStore(doc, rootId));
|
|
30144
30176
|
const docRef = useRef(doc);
|
|
@@ -30294,6 +30326,7 @@ function EditorProviderStand({ doc, provider, blockRenderers, blobStore, databas
|
|
|
30294
30326
|
renderAttribute: renderAttribute ?? parent?.renderAttribute ?? null,
|
|
30295
30327
|
attributeTypePicker: attributeTypePicker ?? parent?.attributeTypePicker ?? null,
|
|
30296
30328
|
docTags: docTags ?? parent?.docTags ?? null,
|
|
30329
|
+
coverPresets: coverPresets ?? parent?.coverPresets ?? null,
|
|
30297
30330
|
embedSandbox: embedSandbox ?? parent?.embedSandbox ?? defaultEmbedSandbox,
|
|
30298
30331
|
rootBlockId: rootId,
|
|
30299
30332
|
ancestorDocIds: parent ? [...parent.ancestorDocIds, parent.doc.meta.id] : [],
|
|
@@ -30324,7 +30357,8 @@ function EditorProviderStand({ doc, provider, blockRenderers, blobStore, databas
|
|
|
30324
30357
|
hiddenAttributes,
|
|
30325
30358
|
renderAttribute,
|
|
30326
30359
|
attributeTypePicker,
|
|
30327
|
-
docTags
|
|
30360
|
+
docTags,
|
|
30361
|
+
coverPresets
|
|
30328
30362
|
]);
|
|
30329
30363
|
const inheritedPublishedStand = parentContext !== null && parentContext.mode === "published";
|
|
30330
30364
|
const rendered = effectiveAccessLevel === "viewer" && parentContext === null ? children : effectiveMode === "published" ? publishedDoc !== void 0 && publishedDoc !== null ? /* @__PURE__ */ jsx(EditorProvider, {
|
|
@@ -30491,26 +30525,480 @@ function AttributeRow({ attributeKey, label, removable, onRemove, removeAria, to
|
|
|
30491
30525
|
});
|
|
30492
30526
|
}
|
|
30493
30527
|
//#endregion
|
|
30494
|
-
//#region src/attributes/
|
|
30495
|
-
/** The cover's
|
|
30496
|
-
|
|
30497
|
-
|
|
30498
|
-
|
|
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 }) {
|
|
30499
30783
|
const { t } = useTranslation("editor");
|
|
30500
|
-
const { blobStore } = useEditorContext();
|
|
30501
|
-
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);
|
|
30502
30793
|
const inputRef = useRef(null);
|
|
30503
|
-
const
|
|
30504
|
-
|
|
30505
|
-
|
|
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);
|
|
30506
30839
|
try {
|
|
30507
|
-
|
|
30840
|
+
onCommit(await blobStore.upload(file), mode);
|
|
30841
|
+
onClose();
|
|
30842
|
+
} catch {
|
|
30843
|
+
setError(t("attributes.coverUploadFailed"));
|
|
30508
30844
|
} finally {
|
|
30509
|
-
|
|
30845
|
+
setBusy(false);
|
|
30510
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);
|
|
30511
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);
|
|
30512
30998
|
return /* @__PURE__ */ jsxs("div", {
|
|
30513
|
-
|
|
30999
|
+
ref: anchorRef,
|
|
31000
|
+
tabIndex: -1,
|
|
31001
|
+
className: "flex min-w-0 items-center gap-2 outline-none",
|
|
30514
31002
|
children: [
|
|
30515
31003
|
fileId !== void 0 && (file.status === "ready" || file.status === "ready-meta") ? /* @__PURE__ */ jsx("span", {
|
|
30516
31004
|
"data-slot": "docblocks/attributes-cover",
|
|
@@ -30525,15 +31013,6 @@ function CoverEditor({ fileId, readOnly, onSet, onClear }) {
|
|
|
30525
31013
|
className: "px-1.5 py-1 text-sm text-muted-foreground",
|
|
30526
31014
|
children: t("attributes.notSet")
|
|
30527
31015
|
}),
|
|
30528
|
-
readOnly ? null : /* @__PURE__ */ jsx("input", {
|
|
30529
|
-
ref: inputRef,
|
|
30530
|
-
type: "file",
|
|
30531
|
-
accept: "image/*",
|
|
30532
|
-
className: "hidden",
|
|
30533
|
-
"aria-label": t("attributes.uploadCoverAria"),
|
|
30534
|
-
"data-slot": "docblocks/attributes-cover-upload",
|
|
30535
|
-
onChange: (event) => void onUpload(event)
|
|
30536
|
-
}),
|
|
30537
31016
|
readOnly ? null : /* @__PURE__ */ jsx(Button, {
|
|
30538
31017
|
type: "button",
|
|
30539
31018
|
variant: "ghost",
|
|
@@ -30541,8 +31020,8 @@ function CoverEditor({ fileId, readOnly, onSet, onClear }) {
|
|
|
30541
31020
|
"aria-label": t("attributes.uploadCoverAria"),
|
|
30542
31021
|
"data-slot": "docblocks/attributes-cover-upload-button",
|
|
30543
31022
|
className: "size-6 text-muted-foreground hover:bg-muted/50 hover:text-foreground dark:hover:bg-muted/50",
|
|
30544
|
-
onClick: () =>
|
|
30545
|
-
children: /* @__PURE__ */ jsx(Image, { className: "size-3.5" })
|
|
31023
|
+
onClick: () => setOpen(true),
|
|
31024
|
+
children: /* @__PURE__ */ jsx(Image$1, { className: "size-3.5" })
|
|
30546
31025
|
}),
|
|
30547
31026
|
fileId !== void 0 && !readOnly ? /* @__PURE__ */ jsx(Button, {
|
|
30548
31027
|
type: "button",
|
|
@@ -30553,11 +31032,89 @@ function CoverEditor({ fileId, readOnly, onSet, onClear }) {
|
|
|
30553
31032
|
className: "size-6 text-muted-foreground hover:bg-muted/50 hover:text-foreground dark:hover:bg-muted/50",
|
|
30554
31033
|
onClick: onClear,
|
|
30555
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)
|
|
30556
31041
|
}) : null
|
|
30557
31042
|
]
|
|
30558
31043
|
});
|
|
30559
31044
|
}
|
|
30560
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
|
|
30561
31118
|
//#region src/attributes/presets.ts
|
|
30562
31119
|
/**
|
|
30563
31120
|
* The document-attributes panel's preset catalog: the preset keys are
|
|
@@ -30571,6 +31128,8 @@ const PRESET_KEYS = [
|
|
|
30571
31128
|
"tags",
|
|
30572
31129
|
"createdBy",
|
|
30573
31130
|
"cover",
|
|
31131
|
+
"coverMode",
|
|
31132
|
+
"coverTint",
|
|
30574
31133
|
"status",
|
|
30575
31134
|
"publishedAt"
|
|
30576
31135
|
];
|
|
@@ -31122,6 +31681,7 @@ function AttributesPanel() {
|
|
|
31122
31681
|
const v = attributes[key];
|
|
31123
31682
|
return typeof v === "string" ? v : void 0;
|
|
31124
31683
|
};
|
|
31684
|
+
const coverMode = coverModeOf(value("coverMode"));
|
|
31125
31685
|
const set = (key, v) => {
|
|
31126
31686
|
try {
|
|
31127
31687
|
doc.setAttribute(key, v);
|
|
@@ -31410,11 +31970,45 @@ function AttributesPanel() {
|
|
|
31410
31970
|
removeAria: t("attributes.removeAria", { name: t("attributes.cover") }),
|
|
31411
31971
|
children: valueZone("cover", /* @__PURE__ */ jsx(CoverEditor, {
|
|
31412
31972
|
fileId: stringValue("cover"),
|
|
31973
|
+
mode: coverMode,
|
|
31413
31974
|
readOnly: viewMode,
|
|
31414
|
-
|
|
31975
|
+
onCommit: (id, mode) => {
|
|
31976
|
+
set("cover", id);
|
|
31977
|
+
if (mode === "center") set("coverMode", "center");
|
|
31978
|
+
else remove("coverMode");
|
|
31979
|
+
},
|
|
31415
31980
|
onClear: () => remove("cover")
|
|
31416
31981
|
}))
|
|
31417
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,
|
|
31418
32012
|
hidden.has("status") ? null : /* @__PURE__ */ jsx(AttributeRow, {
|
|
31419
32013
|
attributeKey: "status",
|
|
31420
32014
|
label: t("attributes.status"),
|
|
@@ -31465,6 +32059,163 @@ function AttributesPanel() {
|
|
|
31465
32059
|
});
|
|
31466
32060
|
}
|
|
31467
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
|
|
31468
32219
|
//#region src/editing/cross-copy.ts
|
|
31469
32220
|
/** The HTML-escaped run text. */
|
|
31470
32221
|
function escapeHtml(text) {
|
|
@@ -32986,6 +33737,9 @@ function useMotionDrag({ doc, rootBlockId, store, rootRef, rowKeys, nodesById })
|
|
|
32986
33737
|
function Editor({ view = "page", formatPalette = FORMAT_PALETTE }) {
|
|
32987
33738
|
const { doc, store, rootBlockId, viewMode } = useEditorContext();
|
|
32988
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);
|
|
32989
33743
|
const pageRef = useRef(null);
|
|
32990
33744
|
const surfaceMapRef = useRef(null);
|
|
32991
33745
|
if (surfaceMapRef.current === null) surfaceMapRef.current = /* @__PURE__ */ new Map();
|
|
@@ -33054,9 +33808,11 @@ function Editor({ view = "page", formatPalette = FORMAT_PALETTE }) {
|
|
|
33054
33808
|
]),
|
|
33055
33809
|
nodesById
|
|
33056
33810
|
});
|
|
33057
|
-
return /* @__PURE__ */
|
|
33811
|
+
return /* @__PURE__ */ jsxs(Card, {
|
|
33812
|
+
ref: cardRef,
|
|
33813
|
+
"data-cover-tint": coverTintEnabled ? "" : void 0,
|
|
33058
33814
|
className: cn(view === "canvas" && "min-h-0 flex-1"),
|
|
33059
|
-
children: /* @__PURE__ */ jsx(EnumOptionsMotionSlot.Provider, {
|
|
33815
|
+
children: [/* @__PURE__ */ jsx(CoverTintController, { cardRef }), /* @__PURE__ */ jsx(EnumOptionsMotionSlot.Provider, {
|
|
33060
33816
|
value: MotionEnumOptionsEditor,
|
|
33061
33817
|
children: /* @__PURE__ */ jsxs("div", {
|
|
33062
33818
|
ref: rootRef,
|
|
@@ -33071,6 +33827,7 @@ function Editor({ view = "page", formatPalette = FORMAT_PALETTE }) {
|
|
|
33071
33827
|
onPointerDown: onCrossDragPointerDown,
|
|
33072
33828
|
children: [
|
|
33073
33829
|
/* @__PURE__ */ jsx("style", { children: HANDLE_GRAB_STYLE }),
|
|
33830
|
+
view === "canvas" ? null : /* @__PURE__ */ jsx(CoverBanner, {}),
|
|
33074
33831
|
/* @__PURE__ */ jsx(MentionMenuContext.Provider, {
|
|
33075
33832
|
value: mention.api,
|
|
33076
33833
|
children: /* @__PURE__ */ jsx(SlashMenuContext.Provider, {
|
|
@@ -33114,8 +33871,8 @@ function Editor({ view = "page", formatPalette = FORMAT_PALETTE }) {
|
|
|
33114
33871
|
viewMode ? null : format.toolbarNode
|
|
33115
33872
|
]
|
|
33116
33873
|
})
|
|
33117
|
-
})
|
|
33874
|
+
})]
|
|
33118
33875
|
});
|
|
33119
33876
|
}
|
|
33120
33877
|
//#endregion
|
|
33121
|
-
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 };
|