notion-to-jsx 1.2.12 → 1.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -30,13 +30,18 @@ import { memo } from "react";
30
30
 
31
31
  // src/components/Renderer/components/RichText/styles.css.ts
32
32
  import { createRuntimeFn as _7a4682 } from "@vanilla-extract/recipes/createRuntimeFn";
33
+ var emptyRichText = "styles_emptyRichText__fdf3twr";
33
34
  var link = "styles_link__fdf3twq";
34
35
  var richText = _7a4682({ defaultClassName: "styles__fdf3tw0", variantClassNames: { bold: { true: "styles_richText_bold_true__fdf3tw1" }, italic: { true: "styles_richText_italic_true__fdf3tw2" }, strikethrough: { true: "styles_richText_strikethrough_true__fdf3tw3" }, underline: { true: "styles_richText_underline_true__fdf3tw4" }, code: { true: "styles_richText_code_true__fdf3tw5" }, color: { "default": "styles_richText_color_default__fdf3tw6", gray: "styles_richText_color_gray__fdf3tw7", brown: "styles_richText_color_brown__fdf3tw8", orange: "styles_richText_color_orange__fdf3tw9", yellow: "styles_richText_color_yellow__fdf3twa", green: "styles_richText_color_green__fdf3twb", blue: "styles_richText_color_blue__fdf3twc", purple: "styles_richText_color_purple__fdf3twd", pink: "styles_richText_color_pink__fdf3twe", red: "styles_richText_color_red__fdf3twf", gray_background: "styles_richText_color_gray_background__fdf3twg", brown_background: "styles_richText_color_brown_background__fdf3twh", orange_background: "styles_richText_color_orange_background__fdf3twi", yellow_background: "styles_richText_color_yellow_background__fdf3twj", green_background: "styles_richText_color_green_background__fdf3twk", blue_background: "styles_richText_color_blue_background__fdf3twl", purple_background: "styles_richText_color_purple_background__fdf3twm", pink_background: "styles_richText_color_pink_background__fdf3twn", red_background: "styles_richText_color_red_background__fdf3two" } }, defaultVariants: {}, compoundVariants: [[{ strikethrough: true, underline: true }, "styles_richText_compound_0__fdf3twp"]] });
35
36
 
36
37
  // src/components/Renderer/components/RichText/RichTexts.tsx
37
38
  import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
38
39
  var renderLink = (href, content3) => /* @__PURE__ */ jsx2("a", { href, target: "_blank", rel: "noopener noreferrer", className: link, children: content3 });
40
+ var EmptyRichText = () => /* @__PURE__ */ jsx2("div", { className: emptyRichText });
39
41
  var RichTexts = ({ richTexts }) => {
42
+ if (richTexts.length === 0) {
43
+ return /* @__PURE__ */ jsx2(EmptyRichText, {});
44
+ }
40
45
  return /* @__PURE__ */ jsx2(Fragment, { children: richTexts.map((text, index) => {
41
46
  const { bold, italic, strikethrough, underline, code, color } = text.annotations;
42
47
  let content3;
@@ -100,7 +105,7 @@ var RichTexts = ({ richTexts }) => {
100
105
  var RichTexts_default = RichTexts;
101
106
 
102
107
  // src/components/Renderer/components/Image/Image.tsx
103
- import { useState } from "react";
108
+ import { useState, useRef, useEffect } from "react";
104
109
 
105
110
  // src/components/Renderer/components/Image/styles.css.ts
106
111
  import { createRuntimeFn as _7a4683 } from "@vanilla-extract/recipes/createRuntimeFn";
@@ -166,12 +171,23 @@ var Image = ({
166
171
  isColumn = false
167
172
  }) => {
168
173
  const [isLoaded, setIsLoaded] = useState(false);
174
+ const imgRef = useRef(null);
175
+ useEffect(() => {
176
+ const img = imgRef.current;
177
+ if (img && img.complete && img.naturalHeight !== 0) {
178
+ setIsLoaded(true);
179
+ }
180
+ }, [src]);
181
+ const handleLoad = () => {
182
+ setIsLoaded(true);
183
+ };
169
184
  return /* @__PURE__ */ jsxs("div", { className: imageContainer, children: [
170
185
  /* @__PURE__ */ jsxs("div", { className: imageWrapper, style: getImageStyles(format, isColumn), children: [
171
186
  /* @__PURE__ */ jsx4("div", { className: skeletonWrapper({ isLoaded }), children: /* @__PURE__ */ jsx4(Skeleton_default, { variant: "image", isLoading: !isLoaded }) }),
172
187
  /* @__PURE__ */ jsx4(
173
188
  "img",
174
189
  {
190
+ ref: imgRef,
175
191
  className: imageStyle({
176
192
  loaded: isLoaded,
177
193
  hasAspectRatio: !!format?.block_aspect_ratio
@@ -179,7 +195,7 @@ var Image = ({
179
195
  src,
180
196
  alt,
181
197
  loading: "lazy",
182
- onLoad: () => setIsLoaded(true),
198
+ onLoad: handleLoad,
183
199
  width: format?.block_width,
184
200
  height: format?.block_height,
185
201
  style: getImageTagStyle(format)
@@ -253,7 +269,7 @@ var Bookmark = ({ url, metadata }) => {
253
269
  var Bookmark_default = Bookmark;
254
270
 
255
271
  // src/components/Renderer/components/LinkPreview/LinkPreview.tsx
256
- import { useState as useState2, useEffect } from "react";
272
+ import { useState as useState2, useEffect as useEffect2 } from "react";
257
273
 
258
274
  // src/components/Renderer/components/LinkPreview/styles.css.ts
259
275
  var content2 = "styles_content__o1p3m12";
@@ -393,7 +409,7 @@ var LinkPreview = ({ url }) => {
393
409
  const [linkType, setLinkType] = useState2(
394
410
  "unknown"
395
411
  );
396
- useEffect(() => {
412
+ useEffect2(() => {
397
413
  const loadLinkData = async () => {
398
414
  setLoading(true);
399
415
  const type = getLinkType(url);
@@ -479,54 +495,71 @@ var MemoizedLinkPreview = memo(
479
495
  }
480
496
  );
481
497
 
482
- // src/components/Renderer/components/List/ListBlocksRenderer.tsx
498
+ // src/components/Renderer/components/List/ListItemGroup.tsx
483
499
  import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
484
- var RecursiveListItem = ({ block }) => {
485
- const blockType = block.type;
500
+ var RecursiveListItem = ({ block, renderBlock }) => {
486
501
  let content3;
487
- if (blockType === "bulleted_list_item") {
502
+ if (block.type === "bulleted_list_item") {
488
503
  content3 = block.bulleted_list_item;
489
504
  } else {
490
505
  content3 = block.numbered_list_item;
491
506
  }
492
507
  const richTexts = content3.rich_text;
493
- const filteredChildren = block.children?.filter(
494
- (child) => child.type === blockType
495
- );
508
+ const renderedChildren = [];
509
+ const children = block.children ?? [];
510
+ if (children.length > 0) {
511
+ let i = 0;
512
+ while (i < children.length) {
513
+ const currentChild = children[i];
514
+ if (!currentChild) {
515
+ i++;
516
+ continue;
517
+ }
518
+ if (currentChild.type === "bulleted_list_item" || currentChild.type === "numbered_list_item") {
519
+ const groupType = currentChild.type;
520
+ const currentGroup = [currentChild];
521
+ let j = i + 1;
522
+ while (j < children.length) {
523
+ const nextChildInGroup = children[j];
524
+ if (!nextChildInGroup) {
525
+ break;
526
+ }
527
+ if (nextChildInGroup.type === groupType) {
528
+ currentGroup.push(
529
+ nextChildInGroup
530
+ );
531
+ j++;
532
+ } else {
533
+ break;
534
+ }
535
+ }
536
+ renderedChildren.push(
537
+ /* @__PURE__ */ jsx7(
538
+ ListGroup,
539
+ {
540
+ blocks: currentGroup,
541
+ type: groupType,
542
+ renderBlock
543
+ },
544
+ `${currentChild.id}-group`
545
+ )
546
+ );
547
+ i = j;
548
+ } else {
549
+ renderedChildren.push(
550
+ /* @__PURE__ */ jsx7("div", { children: renderBlock(currentChild, block.id) }, currentChild.id)
551
+ );
552
+ i++;
553
+ }
554
+ }
555
+ }
496
556
  return /* @__PURE__ */ jsxs4(ListItem, { children: [
497
557
  /* @__PURE__ */ jsx7(MemoizedRichText, { richTexts }),
498
- filteredChildren && filteredChildren.length > 0 && /* @__PURE__ */ jsx7(RecursiveListGroup, { blocks: filteredChildren, type: blockType })
558
+ renderedChildren.length > 0 && renderedChildren
499
559
  ] });
500
560
  };
501
- var RecursiveListGroup = ({ blocks, type }) => {
502
- if (!blocks || blocks.length === 0) return null;
503
- return /* @__PURE__ */ jsx7(
504
- List,
505
- {
506
- as: type === "numbered_list_item" ? "ol" : "ul",
507
- type,
508
- role: "list",
509
- "aria-label": type,
510
- children: blocks.map((block) => /* @__PURE__ */ jsx7(RecursiveListItem, { block }, block.id))
511
- }
512
- );
513
- };
514
- var ListBlocksRenderer = ({
515
- blocks,
516
- startIndex,
517
- type
518
- }) => {
519
- let consecutiveItems = 0;
520
- for (let i = startIndex; i < blocks.length; i++) {
521
- const block = blocks[i];
522
- if (!block) break;
523
- if (block.type === type) {
524
- consecutiveItems++;
525
- } else {
526
- break;
527
- }
528
- }
529
- const listItems = blocks.slice(startIndex, startIndex + consecutiveItems);
561
+ var ListGroup = ({ blocks, type, renderBlock }) => {
562
+ if (blocks.length === 0) return null;
530
563
  return /* @__PURE__ */ jsx7(
531
564
  List,
532
565
  {
@@ -534,11 +567,17 @@ var ListBlocksRenderer = ({
534
567
  type,
535
568
  role: "list",
536
569
  "aria-label": type,
537
- children: listItems.map((block) => /* @__PURE__ */ jsx7(RecursiveListItem, { block }, block.id))
570
+ children: blocks.map((block) => /* @__PURE__ */ jsx7(
571
+ RecursiveListItem,
572
+ {
573
+ block,
574
+ renderBlock
575
+ },
576
+ block.id
577
+ ))
538
578
  }
539
579
  );
540
580
  };
541
- var ListBlocksRenderer_default = ListBlocksRenderer;
542
581
 
543
582
  // src/components/Renderer/components/Code/CodeBlock.tsx
544
583
  import { useMemo } from "react";
@@ -577,7 +616,7 @@ var CodeBlock = ({ code, language, caption: caption2 }) => {
577
616
  }, [code, language]);
578
617
  return /* @__PURE__ */ jsxs5(Fragment2, { children: [
579
618
  /* @__PURE__ */ jsx8("pre", { className: `${codeBlock} language-${language}`, children: /* @__PURE__ */ jsx8("code", { className: `language-${language}`, children: tokens.map((token, i) => renderToken(token, i)) }) }),
580
- caption2 && /* @__PURE__ */ jsx8("figcaption", { children: /* @__PURE__ */ jsx8(MemoizedRichText, { richTexts: caption2 }) })
619
+ caption2 && caption2.length > 0 && /* @__PURE__ */ jsx8("figcaption", { children: /* @__PURE__ */ jsx8(MemoizedRichText, { richTexts: caption2 }) })
581
620
  ] });
582
621
  };
583
622
  var CodeBlock_default = CodeBlock;
@@ -888,7 +927,7 @@ var Title = ({ title: title3 }) => {
888
927
  var Title_default = Title;
889
928
 
890
929
  // src/components/Cover/index.tsx
891
- import { useState as useState4 } from "react";
930
+ import { useState as useState4, useRef as useRef2, useEffect as useEffect3 } from "react";
892
931
 
893
932
  // src/components/Cover/styles.css.ts
894
933
  import { createRuntimeFn as _7a4684 } from "@vanilla-extract/recipes/createRuntimeFn";
@@ -900,15 +939,26 @@ var skeletonWrapper2 = _7a4684({ defaultClassName: "styles_skeletonWrapper__p0cp
900
939
  import { jsx as jsx19, jsxs as jsxs9 } from "react/jsx-runtime";
901
940
  var Cover = ({ src, alt }) => {
902
941
  const [isLoaded, setIsLoaded] = useState4(false);
942
+ const imgRef = useRef2(null);
943
+ useEffect3(() => {
944
+ const img = imgRef.current;
945
+ if (img && img.complete && img.naturalHeight !== 0) {
946
+ setIsLoaded(true);
947
+ }
948
+ }, [src]);
949
+ const handleLoad = () => {
950
+ setIsLoaded(true);
951
+ };
903
952
  return /* @__PURE__ */ jsxs9("div", { className: coverContainer, children: [
904
953
  /* @__PURE__ */ jsx19("div", { className: skeletonWrapper2({ isLoaded }), children: /* @__PURE__ */ jsx19(Skeleton_default, { variant: "image", isLoading: !isLoaded }) }),
905
954
  /* @__PURE__ */ jsx19(
906
955
  "img",
907
956
  {
957
+ ref: imgRef,
908
958
  src,
909
959
  alt,
910
960
  className: imageStyle2({ isLoaded }),
911
- onLoad: () => setIsLoaded(true),
961
+ onLoad: handleLoad,
912
962
  loading: "lazy"
913
963
  }
914
964
  )
@@ -935,20 +985,26 @@ var Renderer = memo2(({ blocks, isDarkMode = false, title: title3, cover }) => {
935
985
  const handleListItem = (listType) => {
936
986
  const listItemType = `${listType}_list_item`;
937
987
  if (block.type === listItemType && (i === 0 || blocks[i - 1]?.type !== listItemType)) {
988
+ const listItems = [];
989
+ let j = i;
990
+ while (j < blocks.length && blocks[j] && blocks[j]?.type === listItemType) {
991
+ listItems.push(
992
+ blocks[j]
993
+ );
994
+ j++;
995
+ }
938
996
  result.push(
939
997
  /* @__PURE__ */ jsx20(
940
- ListBlocksRenderer_default,
998
+ ListGroup,
941
999
  {
942
- blocks,
943
- startIndex: i,
944
- type: listItemType
1000
+ blocks: listItems,
1001
+ type: listItemType,
1002
+ renderBlock: (childBlock) => /* @__PURE__ */ jsx20(BlockRenderer_default, { block: childBlock })
945
1003
  },
946
1004
  block.id
947
1005
  )
948
1006
  );
949
- while (i + 1 < blocks.length && blocks[i + 1] && blocks[i + 1]?.type === listItemType) {
950
- i++;
951
- }
1007
+ i = j - 1;
952
1008
  return true;
953
1009
  }
954
1010
  return false;