notion-to-jsx 1.2.2 → 1.2.4

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
@@ -116,62 +116,71 @@ var styledImage = _7a4683({ defaultClassName: "styles_styledImage__2f3ncf6", var
116
116
  // src/components/Renderer/components/Image/Image.tsx
117
117
  import { jsx as jsx3, jsxs } from "react/jsx-runtime";
118
118
  var MAX_WIDTH = 720;
119
+ var getImageStyles = (format, isColumn = false) => {
120
+ const getWidthStyle = () => {
121
+ if (!isColumn && format?.block_aspect_ratio && format.block_aspect_ratio < 1) {
122
+ return `${format.block_aspect_ratio * 100}%`;
123
+ }
124
+ if (format?.block_width) {
125
+ return format.block_width > MAX_WIDTH ? "100%" : `${format.block_width}px`;
126
+ }
127
+ return "100%";
128
+ };
129
+ const getAspectRatioStyle = () => {
130
+ return format?.block_aspect_ratio ? `${format.block_aspect_ratio}` : "auto";
131
+ };
132
+ return {
133
+ width: getWidthStyle(),
134
+ aspectRatio: getAspectRatioStyle()
135
+ };
136
+ };
137
+ var getImageTagStyle = (format) => {
138
+ return format?.block_aspect_ratio ? { aspectRatio: `${format.block_aspect_ratio}` } : void 0;
139
+ };
119
140
  var Image = ({
120
141
  src,
121
142
  alt,
122
143
  caption: imageCaption,
123
- priority = false,
124
- format
144
+ format,
145
+ isColumn = false
125
146
  }) => {
126
147
  const [isLoaded, setIsLoaded] = useState(false);
127
148
  useEffect(() => {
128
149
  setIsLoaded(false);
129
150
  }, [src]);
130
- return /* @__PURE__ */ jsxs("figure", { className: imageContainer, children: [
151
+ return /* @__PURE__ */ jsxs("div", { className: imageContainer, children: [
131
152
  /* @__PURE__ */ jsxs(
132
153
  "div",
133
154
  {
134
155
  className: imageWrapper({
135
156
  hasWidth: !!format?.block_width
136
157
  }),
137
- style: {
138
- width: format?.block_aspect_ratio && format.block_aspect_ratio < 1 ? `${format.block_aspect_ratio * 100}%` : format?.block_width ? format.block_width > MAX_WIDTH ? "100%" : `${format.block_width}px` : "100%"
139
- },
158
+ style: getImageStyles(format, isColumn),
140
159
  children: [
141
- !isLoaded && /* @__PURE__ */ jsx3(
142
- "div",
160
+ !isLoaded && /* @__PURE__ */ jsx3("div", { className: placeholder, style: getImageStyles(format, isColumn), children: /* @__PURE__ */ jsx3(
161
+ "svg",
143
162
  {
144
- className: placeholder,
145
- style: {
146
- width: format?.block_aspect_ratio && format.block_aspect_ratio < 1 ? `${format.block_aspect_ratio * 100}%` : format?.block_width ? format.block_width > MAX_WIDTH ? "100%" : `${format.block_width}px` : "100%",
147
- aspectRatio: format?.block_aspect_ratio ? `${format.block_aspect_ratio}` : "auto"
148
- },
149
- children: /* @__PURE__ */ jsx3(
150
- "svg",
151
- {
152
- width: "38",
153
- height: "38",
154
- viewBox: "0 0 38 38",
155
- xmlns: "http://www.w3.org/2000/svg",
156
- stroke: "#888",
157
- children: /* @__PURE__ */ jsx3("g", { fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ jsxs("g", { transform: "translate(1 1)", strokeWidth: "2", children: [
158
- /* @__PURE__ */ jsx3("circle", { strokeOpacity: ".5", cx: "18", cy: "18", r: "18" }),
159
- /* @__PURE__ */ jsx3("path", { d: "M36 18c0-9.94-8.06-18-18-18", children: /* @__PURE__ */ jsx3(
160
- "animateTransform",
161
- {
162
- attributeName: "transform",
163
- type: "rotate",
164
- from: "0 18 18",
165
- to: "360 18 18",
166
- dur: "1s",
167
- repeatCount: "indefinite"
168
- }
169
- ) })
170
- ] }) })
171
- }
172
- )
163
+ width: "38",
164
+ height: "38",
165
+ viewBox: "0 0 38 38",
166
+ xmlns: "http://www.w3.org/2000/svg",
167
+ stroke: "#888",
168
+ children: /* @__PURE__ */ jsx3("g", { fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ jsxs("g", { transform: "translate(1 1)", strokeWidth: "2", children: [
169
+ /* @__PURE__ */ jsx3("circle", { strokeOpacity: ".5", cx: "18", cy: "18", r: "18" }),
170
+ /* @__PURE__ */ jsx3("path", { d: "M36 18c0-9.94-8.06-18-18-18", children: /* @__PURE__ */ jsx3(
171
+ "animateTransform",
172
+ {
173
+ attributeName: "transform",
174
+ type: "rotate",
175
+ from: "0 18 18",
176
+ to: "360 18 18",
177
+ dur: "1s",
178
+ repeatCount: "indefinite"
179
+ }
180
+ ) })
181
+ ] }) })
173
182
  }
174
- ),
183
+ ) }),
175
184
  /* @__PURE__ */ jsx3(
176
185
  "img",
177
186
  {
@@ -181,11 +190,11 @@ var Image = ({
181
190
  }),
182
191
  src,
183
192
  alt,
184
- loading: priority ? "eager" : "lazy",
193
+ loading: "lazy",
185
194
  onLoad: () => setIsLoaded(true),
186
195
  width: format?.block_width,
187
196
  height: format?.block_height,
188
- style: format?.block_aspect_ratio ? { aspectRatio: `${format.block_aspect_ratio}` } : void 0
197
+ style: getImageTagStyle(format)
189
198
  }
190
199
  )
191
200
  ]
@@ -600,17 +609,35 @@ var codeBlock = "styles_codeBlock__1qn42yc0";
600
609
 
601
610
  // src/components/Renderer/components/Code/CodeBlock.tsx
602
611
  import Prism from "prismjs";
612
+ import "prismjs/components/prism-typescript";
613
+ import "prismjs/components/prism-jsx";
614
+ import "prismjs/components/prism-tsx";
603
615
  import { Fragment as Fragment2, jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
604
616
  if (typeof window !== "undefined") {
605
617
  window.Prism = Prism;
606
618
  }
619
+ var renderToken = (token, i) => {
620
+ if (typeof token === "string") {
621
+ return /* @__PURE__ */ jsx7("span", { children: token }, i);
622
+ }
623
+ const content3 = token.content;
624
+ let tokenContent;
625
+ if (Array.isArray(content3)) {
626
+ tokenContent = content3.map((subToken, j) => renderToken(subToken, j));
627
+ } else if (typeof content3 === "object" && content3 !== null) {
628
+ tokenContent = renderToken(content3, 0);
629
+ } else {
630
+ tokenContent = content3;
631
+ }
632
+ return /* @__PURE__ */ jsx7("span", { className: `token ${token.type}`, children: tokenContent }, i);
633
+ };
607
634
  var CodeBlock = ({ code, language, caption: caption2 }) => {
608
- const highlightedCode = useMemo(() => {
635
+ const tokens = useMemo(() => {
609
636
  const prismLanguage = Prism.languages[language] || Prism.languages.plaintext;
610
- return Prism.highlight(code, prismLanguage, language);
637
+ return Prism.tokenize(code, prismLanguage);
611
638
  }, [code, language]);
612
639
  return /* @__PURE__ */ jsxs5(Fragment2, { children: [
613
- /* @__PURE__ */ jsx7("pre", { className: codeBlock, children: /* @__PURE__ */ jsx7("code", { dangerouslySetInnerHTML: { __html: highlightedCode } }) }),
640
+ /* @__PURE__ */ jsx7("pre", { className: `${codeBlock} language-${language}`, children: /* @__PURE__ */ jsx7("code", { className: `language-${language}`, children: tokens.map((token, i) => renderToken(token, i)) }) }),
614
641
  caption2 && /* @__PURE__ */ jsx7("figcaption", { children: /* @__PURE__ */ jsx7(MemoizedRichText, { richTexts: caption2 }) })
615
642
  ] });
616
643
  };
@@ -666,7 +693,8 @@ var Column = ({ block, onFocus }) => {
666
693
  {
667
694
  block: childBlock,
668
695
  onFocus,
669
- index
696
+ index,
697
+ isColumn: true
670
698
  },
671
699
  childBlock.id
672
700
  )) });
@@ -823,7 +851,12 @@ var Toggle_default = Toggle;
823
851
 
824
852
  // src/components/Renderer/components/Block/BlockRenderer.tsx
825
853
  import { jsx as jsx15 } from "react/jsx-runtime";
826
- var BlockRenderer = ({ block, onFocus, index }) => {
854
+ var BlockRenderer = ({
855
+ block,
856
+ onFocus,
857
+ index,
858
+ isColumn = false
859
+ }) => {
827
860
  if (!block) return null;
828
861
  const blockProps = {
829
862
  tabIndex: 0,
@@ -856,7 +889,8 @@ var BlockRenderer = ({ block, onFocus, index }) => {
856
889
  src: block.image.file?.url || block.image.external?.url,
857
890
  alt: block.image.caption?.[0]?.plain_text || "",
858
891
  caption: block.image.caption,
859
- format: block.image.format
892
+ format: block.image.format,
893
+ isColumn
860
894
  }
861
895
  ) });
862
896
  case "bookmark":