notionic 0.8.3 → 0.9.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 +6 -0
- package/README.md +19 -0
- package/dist/fetch.d.ts +8 -1
- package/dist/fetch.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +13 -6
- package/dist/markdown.d.ts +1 -1
- package/dist/{types-DOxr5KpT.d.ts → types-Bn9yupWe.d.ts} +12 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# notionic
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#43](https://github.com/nublson/notionic/pull/43) [`31d8a75`](https://github.com/nublson/notionic/commit/31d8a75aecd9164cb532950f6663f60aaed93b78) Thanks [@nublson](https://github.com/nublson)! - Add a `link` key to `components` for links inside text, such as adding a favicon to external links. Its component gets `link`, `children` and `context`; the default is `NotionLink`. `LinkProps` is exported. `notionic/fetch` exports `fetchBookmarkPreview(url)`, to preview any link the way bookmarks are.
|
|
8
|
+
|
|
3
9
|
## 0.8.3
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -86,6 +86,8 @@ To also get the page's title, icon, cover and properties, use `fetchPage(notion,
|
|
|
86
86
|
|
|
87
87
|
For bookmarks, embeds and link previews, `fetchBlocks` also fetches the linked page and reads its title, description, image and favicon, so the block renders as a card like a Notion bookmark. A page that's slow (over 5 seconds), unreachable or untitled renders as a one-line card with the URL, and private network addresses are never fetched. Pass `bookmarkPreviews: false` to make no requests outside Notion.
|
|
88
88
|
|
|
89
|
+
To preview any other link the same way, use `fetchBookmarkPreview(url)` from `notionic/fetch`. It returns the page's `title`, `description`, `image`, `favicon` and `siteName`, or `null`, under the same rules. It doesn't cache either.
|
|
90
|
+
|
|
89
91
|
You can also pass blocks you fetched yourself: `NotionRenderer` takes the API's block objects with nested blocks attached as `children` (the `NotionBlock` type).
|
|
90
92
|
|
|
91
93
|
## Options
|
|
@@ -126,6 +128,23 @@ function Callout({ block, context, children }: BlockProps<"callout">) {
|
|
|
126
128
|
|
|
127
129
|
Equations inside text have their own key, `inline_equation`, whose component gets the equation's LaTeX as `expression`.
|
|
128
130
|
|
|
131
|
+
Links inside text have their own key too, `link`. Its component gets the resolved `link` (`href`, and `external` for other sites), the formatted text as `children`, and `context`. Wrap `NotionLink` to keep notionic's styling and new-tab behavior:
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
import { NotionLink, type LinkProps } from "notionic";
|
|
135
|
+
|
|
136
|
+
function Link({ link, children }: LinkProps) {
|
|
137
|
+
return (
|
|
138
|
+
<NotionLink link={link}>
|
|
139
|
+
{link.external ? <Favicon href={link.href} /> : null}
|
|
140
|
+
{children}
|
|
141
|
+
</NotionLink>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
<NotionRenderer blocks={blocks} components={{ link: Link }} />;
|
|
146
|
+
```
|
|
147
|
+
|
|
129
148
|
### Interactive demos
|
|
130
149
|
|
|
131
150
|
Put your own React components in a page, like the demos in a design engineering blog. Each demo is a component in your project, so it can use anything you install (Motion, Sonner, charts, 3D). In Notion, an embed of a URL ending in `/demos/<name>` marks where it goes, and its caption goes below it.
|
package/dist/fetch.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as ListBlockChildrenResponse, E as PartialPageObjectResponse, S as ListBlockChildrenParameters, T as PageObjectResponse, d as NotionBlock, i as BookmarkPreview, p as NotionPage, w as IdRequest } from "./types-Bn9yupWe.js";
|
|
2
2
|
//#region ../../node_modules/.pnpm/@notionhq+client@5.27.1/node_modules/@notionhq/client/build/src/api-endpoints/pages.d.ts
|
|
3
3
|
type GetPagePathParameters = {
|
|
4
4
|
page_id: IdRequest;
|
|
@@ -9,6 +9,13 @@ type GetPageQueryParameters = {
|
|
|
9
9
|
type GetPageParameters = GetPagePathParameters & GetPageQueryParameters;
|
|
10
10
|
type GetPageResponse = PartialPageObjectResponse | PageObjectResponse;
|
|
11
11
|
//#endregion
|
|
12
|
+
//#region src/bookmark-preview.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* The preview card data for a bookmarked page, read from its HTML, or null
|
|
15
|
+
* when the page can't be fetched, isn't HTML, or has no title.
|
|
16
|
+
*/
|
|
17
|
+
export declare function fetchBookmarkPreview(url: string): Promise<BookmarkPreview | null>;
|
|
18
|
+
//#endregion
|
|
12
19
|
//#region src/fetch.d.ts
|
|
13
20
|
/**
|
|
14
21
|
* The part of the Notion client notionic uses. A `Client` from
|
package/dist/fetch.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { T as PageObjectResponse, _ as RichText, a as DemoFrameProps, b as HostedFile, c as InlineEquationProps, d as NotionBlock, f as NotionBlockType, g as ResolvedLink, h as RenderContext, i as BookmarkPreview, l as LinkProps, m as PageIcon, n as BlockOf, o as DemoProps, p as NotionPage, r as BlockProps, s as Demos, t as BlockComponents, u as LinkedPage, v as PageHeading, x as resolveFileUrl, y as collectHeadings } from "./types-Bn9yupWe.js";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
3
|
//#region src/renderer.d.ts
|
|
4
4
|
export declare const defaultComponents: BlockComponents;
|
|
@@ -109,4 +109,4 @@ export declare function DemoFrame({ caption, context, children }: DemoFrameProps
|
|
|
109
109
|
/** A Notion code language as people write it: "typescript" is "TypeScript". */
|
|
110
110
|
export declare function languageName(language: string): string;
|
|
111
111
|
//#endregion
|
|
112
|
-
export { type BlockComponents, type BlockOf, type BlockProps, type BookmarkPreview, type DemoFrameProps, type DemoProps, type Demos, type HostedFile, type InlineEquationProps, type LinkedPage, type NotionBlock, type NotionBlockType, type NotionPage, type NotionRendererProps, type RichText as NotionRichText, type PageHeading, type PageIcon, type RenderContext, type ResolvedLink, RichText$1 as RichText, collectHeadings, resolveFileUrl };
|
|
112
|
+
export { type BlockComponents, type BlockOf, type BlockProps, type BookmarkPreview, type DemoFrameProps, type DemoProps, type Demos, type HostedFile, type InlineEquationProps, type LinkProps, type LinkedPage, type NotionBlock, type NotionBlockType, type NotionPage, type NotionRendererProps, type RichText as NotionRichText, type PageHeading, type PageIcon, type RenderContext, type ResolvedLink, RichText$1 as RichText, collectHeadings, resolveFileUrl };
|
package/dist/index.js
CHANGED
|
@@ -102,10 +102,14 @@ function RichTextItem({ item, context }) {
|
|
|
102
102
|
children: node
|
|
103
103
|
});
|
|
104
104
|
const link = resolveLink(item.href, context);
|
|
105
|
-
if (link)
|
|
106
|
-
link
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
if (link) {
|
|
106
|
+
const Link = context.components.link ?? NotionLink;
|
|
107
|
+
node = /* @__PURE__ */ jsx(Link, {
|
|
108
|
+
link,
|
|
109
|
+
context,
|
|
110
|
+
children: node
|
|
111
|
+
});
|
|
112
|
+
}
|
|
109
113
|
return node;
|
|
110
114
|
}
|
|
111
115
|
/** A Notion rich text array: annotations, colors, links and mentions. */
|
|
@@ -460,8 +464,10 @@ function Caption({ caption, context }) {
|
|
|
460
464
|
function UrlLine({ url, label, context }) {
|
|
461
465
|
const link = resolveLink(url, context);
|
|
462
466
|
if (!link) return null;
|
|
463
|
-
|
|
467
|
+
const Link = context.components.link ?? NotionLink;
|
|
468
|
+
return /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(Link, {
|
|
464
469
|
link,
|
|
470
|
+
context,
|
|
465
471
|
children: label || url
|
|
466
472
|
}) });
|
|
467
473
|
}
|
|
@@ -1154,7 +1160,8 @@ const defaultComponents = {
|
|
|
1154
1160
|
link_to_page: LinkToPage,
|
|
1155
1161
|
table_of_contents: TableOfContents,
|
|
1156
1162
|
tab: Tab,
|
|
1157
|
-
inline_equation: InlineEquation
|
|
1163
|
+
inline_equation: InlineEquation,
|
|
1164
|
+
link: NotionLink
|
|
1158
1165
|
};
|
|
1159
1166
|
const LIST_KINDS = {
|
|
1160
1167
|
bulleted_list_item: "bulleted",
|
package/dist/markdown.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as NotionBlock, h as RenderContext } from "./types-Bn9yupWe.js";
|
|
2
2
|
//#region src/markdown.d.ts
|
|
3
3
|
export type MarkdownOptions = {
|
|
4
4
|
/** Where links to Notion pages point, as in `NotionRenderer`. Defaults to notion.so. */
|
|
@@ -1292,14 +1292,23 @@ type InlineEquationProps = {
|
|
|
1292
1292
|
expression: string;
|
|
1293
1293
|
context: RenderContext;
|
|
1294
1294
|
};
|
|
1295
|
+
/** Props of the component that renders a link inside text. */
|
|
1296
|
+
type LinkProps = {
|
|
1297
|
+
/** Where the link goes, and whether it opens in a new tab. */
|
|
1298
|
+
link: ResolvedLink;
|
|
1299
|
+
/** The linked text, already formatted. */
|
|
1300
|
+
children: ReactNode;
|
|
1301
|
+
context: RenderContext;
|
|
1302
|
+
};
|
|
1295
1303
|
/**
|
|
1296
1304
|
* Replacements for the built-in components: one per block type, plus
|
|
1297
|
-
* `inline_equation` for equations inside text
|
|
1298
|
-
* around demos.
|
|
1305
|
+
* `inline_equation` for equations inside text, `link` for links inside text,
|
|
1306
|
+
* and `demo` for the frame around demos.
|
|
1299
1307
|
*/
|
|
1300
1308
|
type BlockComponents = { [T in NotionBlockType]?: ComponentType<BlockProps<T>>; } & {
|
|
1301
1309
|
inline_equation?: ComponentType<InlineEquationProps>;
|
|
1310
|
+
link?: ComponentType<LinkProps>;
|
|
1302
1311
|
demo?: ComponentType<DemoFrameProps>;
|
|
1303
1312
|
};
|
|
1304
1313
|
//#endregion
|
|
1305
|
-
export {
|
|
1314
|
+
export { ListBlockChildrenResponse as C, PartialPageObjectResponse as E, ListBlockChildrenParameters as S, PageObjectResponse as T, RichText as _, DemoFrameProps as a, HostedFile as b, InlineEquationProps as c, NotionBlock as d, NotionBlockType as f, ResolvedLink as g, RenderContext as h, BookmarkPreview as i, LinkProps as l, PageIcon as m, BlockOf as n, DemoProps as o, NotionPage as p, BlockProps as r, Demos as s, BlockComponents as t, LinkedPage as u, PageHeading as v, IdRequest as w, resolveFileUrl as x, collectHeadings as y };
|
package/package.json
CHANGED