notion-to-jsx 1.2.11 → 1.2.13

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;
@@ -122,7 +127,8 @@ var Skeleton = ({
122
127
  variant = "rect",
123
128
  width,
124
129
  height,
125
- className
130
+ className,
131
+ isLoading = true
126
132
  }) => {
127
133
  const getVariantClass = () => {
128
134
  switch (variant) {
@@ -135,6 +141,9 @@ var Skeleton = ({
135
141
  return rect;
136
142
  }
137
143
  };
144
+ if (!isLoading) {
145
+ return null;
146
+ }
138
147
  return /* @__PURE__ */ jsx3(
139
148
  "div",
140
149
  {
@@ -164,7 +173,7 @@ var Image = ({
164
173
  const [isLoaded, setIsLoaded] = useState(false);
165
174
  return /* @__PURE__ */ jsxs("div", { className: imageContainer, children: [
166
175
  /* @__PURE__ */ jsxs("div", { className: imageWrapper, style: getImageStyles(format, isColumn), children: [
167
- /* @__PURE__ */ jsx4("div", { className: skeletonWrapper({ isLoaded }), children: /* @__PURE__ */ jsx4(Skeleton_default, { variant: "image" }) }),
176
+ /* @__PURE__ */ jsx4("div", { className: skeletonWrapper({ isLoaded }), children: /* @__PURE__ */ jsx4(Skeleton_default, { variant: "image", isLoading: !isLoaded }) }),
168
177
  /* @__PURE__ */ jsx4(
169
178
  "img",
170
179
  {
@@ -475,27 +484,71 @@ var MemoizedLinkPreview = memo(
475
484
  }
476
485
  );
477
486
 
478
- // src/components/Renderer/components/List/ListBlocksRenderer.tsx
487
+ // src/components/Renderer/components/List/ListItemGroup.tsx
479
488
  import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
480
- var RecursiveListItem = ({ block }) => {
481
- const blockType = block.type;
489
+ var RecursiveListItem = ({ block, renderBlock }) => {
482
490
  let content3;
483
- if (blockType === "bulleted_list_item") {
491
+ if (block.type === "bulleted_list_item") {
484
492
  content3 = block.bulleted_list_item;
485
493
  } else {
486
494
  content3 = block.numbered_list_item;
487
495
  }
488
496
  const richTexts = content3.rich_text;
489
- const filteredChildren = block.children?.filter(
490
- (child) => child.type === blockType
491
- );
497
+ const renderedChildren = [];
498
+ const children = block.children ?? [];
499
+ if (children.length > 0) {
500
+ let i = 0;
501
+ while (i < children.length) {
502
+ const currentChild = children[i];
503
+ if (!currentChild) {
504
+ i++;
505
+ continue;
506
+ }
507
+ if (currentChild.type === "bulleted_list_item" || currentChild.type === "numbered_list_item") {
508
+ const groupType = currentChild.type;
509
+ const currentGroup = [currentChild];
510
+ let j = i + 1;
511
+ while (j < children.length) {
512
+ const nextChildInGroup = children[j];
513
+ if (!nextChildInGroup) {
514
+ break;
515
+ }
516
+ if (nextChildInGroup.type === groupType) {
517
+ currentGroup.push(
518
+ nextChildInGroup
519
+ );
520
+ j++;
521
+ } else {
522
+ break;
523
+ }
524
+ }
525
+ renderedChildren.push(
526
+ /* @__PURE__ */ jsx7(
527
+ ListGroup,
528
+ {
529
+ blocks: currentGroup,
530
+ type: groupType,
531
+ renderBlock
532
+ },
533
+ `${currentChild.id}-group`
534
+ )
535
+ );
536
+ i = j;
537
+ } else {
538
+ renderedChildren.push(
539
+ /* @__PURE__ */ jsx7("div", { children: renderBlock(currentChild, block.id) }, currentChild.id)
540
+ );
541
+ i++;
542
+ }
543
+ }
544
+ }
492
545
  return /* @__PURE__ */ jsxs4(ListItem, { children: [
493
546
  /* @__PURE__ */ jsx7(MemoizedRichText, { richTexts }),
494
- filteredChildren && filteredChildren.length > 0 && /* @__PURE__ */ jsx7(RecursiveListGroup, { blocks: filteredChildren, type: blockType })
547
+ renderedChildren.length > 0 && renderedChildren
495
548
  ] });
496
549
  };
497
- var RecursiveListGroup = ({ blocks, type }) => {
498
- if (!blocks || blocks.length === 0) return null;
550
+ var ListGroup = ({ blocks, type, renderBlock }) => {
551
+ if (blocks.length === 0) return null;
499
552
  return /* @__PURE__ */ jsx7(
500
553
  List,
501
554
  {
@@ -503,38 +556,17 @@ var RecursiveListGroup = ({ blocks, type }) => {
503
556
  type,
504
557
  role: "list",
505
558
  "aria-label": type,
506
- children: blocks.map((block) => /* @__PURE__ */ jsx7(RecursiveListItem, { block }, block.id))
507
- }
508
- );
509
- };
510
- var ListBlocksRenderer = ({
511
- blocks,
512
- startIndex,
513
- type
514
- }) => {
515
- let consecutiveItems = 0;
516
- for (let i = startIndex; i < blocks.length; i++) {
517
- const block = blocks[i];
518
- if (!block) break;
519
- if (block.type === type) {
520
- consecutiveItems++;
521
- } else {
522
- break;
523
- }
524
- }
525
- const listItems = blocks.slice(startIndex, startIndex + consecutiveItems);
526
- return /* @__PURE__ */ jsx7(
527
- List,
528
- {
529
- as: type === "numbered_list_item" ? "ol" : "ul",
530
- type,
531
- role: "list",
532
- "aria-label": type,
533
- children: listItems.map((block) => /* @__PURE__ */ jsx7(RecursiveListItem, { block }, block.id))
559
+ children: blocks.map((block) => /* @__PURE__ */ jsx7(
560
+ RecursiveListItem,
561
+ {
562
+ block,
563
+ renderBlock
564
+ },
565
+ block.id
566
+ ))
534
567
  }
535
568
  );
536
569
  };
537
- var ListBlocksRenderer_default = ListBlocksRenderer;
538
570
 
539
571
  // src/components/Renderer/components/Code/CodeBlock.tsx
540
572
  import { useMemo } from "react";
@@ -573,7 +605,7 @@ var CodeBlock = ({ code, language, caption: caption2 }) => {
573
605
  }, [code, language]);
574
606
  return /* @__PURE__ */ jsxs5(Fragment2, { children: [
575
607
  /* @__PURE__ */ jsx8("pre", { className: `${codeBlock} language-${language}`, children: /* @__PURE__ */ jsx8("code", { className: `language-${language}`, children: tokens.map((token, i) => renderToken(token, i)) }) }),
576
- caption2 && /* @__PURE__ */ jsx8("figcaption", { children: /* @__PURE__ */ jsx8(MemoizedRichText, { richTexts: caption2 }) })
608
+ caption2 && caption2.length > 0 && /* @__PURE__ */ jsx8("figcaption", { children: /* @__PURE__ */ jsx8(MemoizedRichText, { richTexts: caption2 }) })
577
609
  ] });
578
610
  };
579
611
  var CodeBlock_default = CodeBlock;
@@ -897,7 +929,7 @@ import { jsx as jsx19, jsxs as jsxs9 } from "react/jsx-runtime";
897
929
  var Cover = ({ src, alt }) => {
898
930
  const [isLoaded, setIsLoaded] = useState4(false);
899
931
  return /* @__PURE__ */ jsxs9("div", { className: coverContainer, children: [
900
- /* @__PURE__ */ jsx19("div", { className: skeletonWrapper2({ isLoaded }), children: /* @__PURE__ */ jsx19(Skeleton_default, { variant: "image" }) }),
932
+ /* @__PURE__ */ jsx19("div", { className: skeletonWrapper2({ isLoaded }), children: /* @__PURE__ */ jsx19(Skeleton_default, { variant: "image", isLoading: !isLoaded }) }),
901
933
  /* @__PURE__ */ jsx19(
902
934
  "img",
903
935
  {
@@ -931,20 +963,26 @@ var Renderer = memo2(({ blocks, isDarkMode = false, title: title3, cover }) => {
931
963
  const handleListItem = (listType) => {
932
964
  const listItemType = `${listType}_list_item`;
933
965
  if (block.type === listItemType && (i === 0 || blocks[i - 1]?.type !== listItemType)) {
966
+ const listItems = [];
967
+ let j = i;
968
+ while (j < blocks.length && blocks[j] && blocks[j]?.type === listItemType) {
969
+ listItems.push(
970
+ blocks[j]
971
+ );
972
+ j++;
973
+ }
934
974
  result.push(
935
975
  /* @__PURE__ */ jsx20(
936
- ListBlocksRenderer_default,
976
+ ListGroup,
937
977
  {
938
- blocks,
939
- startIndex: i,
940
- type: listItemType
978
+ blocks: listItems,
979
+ type: listItemType,
980
+ renderBlock: (childBlock) => /* @__PURE__ */ jsx20(BlockRenderer_default, { block: childBlock })
941
981
  },
942
982
  block.id
943
983
  )
944
984
  );
945
- while (i + 1 < blocks.length && blocks[i + 1] && blocks[i + 1]?.type === listItemType) {
946
- i++;
947
- }
985
+ i = j - 1;
948
986
  return true;
949
987
  }
950
988
  return false;