@haklex/rich-renderer-linkcard 0.0.1
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/LICENSE +28 -0
- package/README.md +67 -0
- package/dist/LinkCardEditDecorator.d.ts +10 -0
- package/dist/LinkCardEditDecorator.d.ts.map +1 -0
- package/dist/LinkCardEditNode.d.ts +10 -0
- package/dist/LinkCardEditNode.d.ts.map +1 -0
- package/dist/LinkCardRenderer.d.ts +12 -0
- package/dist/LinkCardRenderer.d.ts.map +1 -0
- package/dist/LinkCardSkeleton.d.ts +5 -0
- package/dist/LinkCardSkeleton.d.ts.map +1 -0
- package/dist/hooks/useCardFetcher.d.ts +19 -0
- package/dist/hooks/useCardFetcher.d.ts.map +1 -0
- package/dist/hooks/useUrlMatcher.d.ts +7 -0
- package/dist/hooks/useUrlMatcher.d.ts.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +1432 -0
- package/dist/plugins/academic/arxiv.d.ts +3 -0
- package/dist/plugins/academic/arxiv.d.ts.map +1 -0
- package/dist/plugins/academic/index.d.ts +2 -0
- package/dist/plugins/academic/index.d.ts.map +1 -0
- package/dist/plugins/code/index.d.ts +2 -0
- package/dist/plugins/code/index.d.ts.map +1 -0
- package/dist/plugins/code/leetcode.d.ts +3 -0
- package/dist/plugins/code/leetcode.d.ts.map +1 -0
- package/dist/plugins/github/commit.d.ts +3 -0
- package/dist/plugins/github/commit.d.ts.map +1 -0
- package/dist/plugins/github/discussion.d.ts +3 -0
- package/dist/plugins/github/discussion.d.ts.map +1 -0
- package/dist/plugins/github/index.d.ts +6 -0
- package/dist/plugins/github/index.d.ts.map +1 -0
- package/dist/plugins/github/issue.d.ts +3 -0
- package/dist/plugins/github/issue.d.ts.map +1 -0
- package/dist/plugins/github/pr.d.ts +3 -0
- package/dist/plugins/github/pr.d.ts.map +1 -0
- package/dist/plugins/github/repo.d.ts +3 -0
- package/dist/plugins/github/repo.d.ts.map +1 -0
- package/dist/plugins/index.d.ts +13 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/media/bangumi.d.ts +3 -0
- package/dist/plugins/media/bangumi.d.ts.map +1 -0
- package/dist/plugins/media/index.d.ts +5 -0
- package/dist/plugins/media/index.d.ts.map +1 -0
- package/dist/plugins/media/netease-music.d.ts +3 -0
- package/dist/plugins/media/netease-music.d.ts.map +1 -0
- package/dist/plugins/media/qq-music.d.ts +3 -0
- package/dist/plugins/media/qq-music.d.ts.map +1 -0
- package/dist/plugins/media/tmdb.d.ts +3 -0
- package/dist/plugins/media/tmdb.d.ts.map +1 -0
- package/dist/plugins/self/index.d.ts +3 -0
- package/dist/plugins/self/index.d.ts.map +1 -0
- package/dist/plugins/self/mx-space.d.ts +8 -0
- package/dist/plugins/self/mx-space.d.ts.map +1 -0
- package/dist/rich-renderer-linkcard.css +331 -0
- package/dist/styles.css.d.ts +2 -0
- package/dist/styles.css.d.ts.map +1 -0
- package/dist/types.d.ts +88 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Innei
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
Additional Terms and Conditions
|
|
25
|
+
|
|
26
|
+
----------------
|
|
27
|
+
|
|
28
|
+
Use of this software is governed by the terms of MIT and, in addition, by the terms and conditions described in the additional file (ADDITIONAL_TERMS.md). By using this software, you agree to abide by these additional terms and conditions.
|
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @haklex/rich-renderer-linkcard
|
|
2
|
+
|
|
3
|
+
链接卡片渲染器,支持多平台元数据获取。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @haklex/rich-renderer-linkcard @haklex/rich-editor
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 导出
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// 渲染器
|
|
15
|
+
export { LinkCardRenderer } from './LinkCardRenderer'
|
|
16
|
+
export { LinkCardEditNode, linkCardEditNodes } from './LinkCardEditNode'
|
|
17
|
+
export { LinkCardSkeleton } from './LinkCardSkeleton'
|
|
18
|
+
|
|
19
|
+
// Hooks
|
|
20
|
+
export { useUrlMatcher } from './hooks/useUrlMatcher'
|
|
21
|
+
|
|
22
|
+
// 插件
|
|
23
|
+
export { plugins, pluginMap, getPluginByName } from './plugins'
|
|
24
|
+
export {
|
|
25
|
+
githubRepoPlugin, githubPrPlugin, githubIssuePlugin,
|
|
26
|
+
githubCommitPlugin, githubDiscussionPlugin,
|
|
27
|
+
arxivPlugin, tmdbPlugin, bangumiPlugin,
|
|
28
|
+
leetcodePlugin, mxSpacePlugin, createMxSpacePlugin,
|
|
29
|
+
neteaseMusicPlugin, qqMusicPlugin
|
|
30
|
+
} from './plugins'
|
|
31
|
+
|
|
32
|
+
// 工具
|
|
33
|
+
export {
|
|
34
|
+
fetchGitHubApi, fetchJsonWithContext,
|
|
35
|
+
camelcaseKeys, generateColor, LanguageToColorMap
|
|
36
|
+
} from './utils'
|
|
37
|
+
|
|
38
|
+
// 类型
|
|
39
|
+
export type {
|
|
40
|
+
LinkCardData, LinkCardPlugin, LinkCardTypeClass,
|
|
41
|
+
LinkCardApiAdapter, LinkCardFetchContext,
|
|
42
|
+
PluginRegistry, UrlMatchResult, UrlMatchInfo,
|
|
43
|
+
EnhancedLinkCardProps, MxSpacePluginConfig
|
|
44
|
+
} from './types'
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 内置插件
|
|
48
|
+
|
|
49
|
+
- GitHub: repo, pr, issue, commit, discussion
|
|
50
|
+
- 学术: arxiv, leetcode
|
|
51
|
+
- 媒体: tmdb, bangumi, netease-music, qq-music
|
|
52
|
+
- 自定义: mx-space
|
|
53
|
+
|
|
54
|
+
## 使用
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { LinkCardRenderer } from '@haklex/rich-renderer-linkcard'
|
|
58
|
+
import type { RendererConfig } from '@haklex/rich-editor'
|
|
59
|
+
|
|
60
|
+
const config: RendererConfig = {
|
|
61
|
+
LinkCard: LinkCardRenderer,
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LinkCardNodePayload } from '@haklex/rich-editor';
|
|
2
|
+
import { ReactElement } from 'react';
|
|
3
|
+
interface LinkCardEditDecoratorProps {
|
|
4
|
+
nodeKey: string;
|
|
5
|
+
payload: LinkCardNodePayload;
|
|
6
|
+
children: ReactElement;
|
|
7
|
+
}
|
|
8
|
+
export declare function LinkCardEditDecorator({ nodeKey, payload, children, }: LinkCardEditDecoratorProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=LinkCardEditDecorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkCardEditDecorator.d.ts","sourceRoot":"","sources":["../src/LinkCardEditDecorator.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAK/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAGzC,UAAU,0BAA0B;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,mBAAmB,CAAA;IAC5B,QAAQ,EAAE,YAAY,CAAA;CACvB;AAED,wBAAgB,qBAAqB,CAAC,EACpC,OAAO,EACP,OAAO,EACP,QAAQ,GACT,EAAE,0BAA0B,2CAoH5B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LinkCardNode, SerializedLinkCardNode } from '@haklex/rich-editor';
|
|
2
|
+
import { EditorConfig, Klass, LexicalEditor, LexicalNode } from 'lexical';
|
|
3
|
+
import { ReactElement } from 'react';
|
|
4
|
+
export declare class LinkCardEditNode extends LinkCardNode {
|
|
5
|
+
static clone(node: LinkCardEditNode): LinkCardEditNode;
|
|
6
|
+
static importJSON(serializedNode: SerializedLinkCardNode): LinkCardEditNode;
|
|
7
|
+
decorate(_editor: LexicalEditor, _config: EditorConfig): ReactElement;
|
|
8
|
+
}
|
|
9
|
+
export declare const linkCardEditNodes: Array<Klass<LexicalNode>>;
|
|
10
|
+
//# sourceMappingURL=LinkCardEditNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkCardEditNode.d.ts","sourceRoot":"","sources":["../src/LinkCardEditNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EAEZ,KAAK,sBAAsB,EAC5B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAKzC,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB;IAatD,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,sBAAsB,GAAG,gBAAgB;IAU3E,QAAQ,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,GAAG,YAAY;CAmBtE;AAED,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAsB,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LinkCardRendererProps } from '@haklex/rich-editor';
|
|
2
|
+
import { ComponentType } from 'react';
|
|
3
|
+
import { LinkCardFetchContext, PluginRegistry } from './types';
|
|
4
|
+
export interface EnhancedLinkCardProps extends LinkCardRendererProps {
|
|
5
|
+
source?: string;
|
|
6
|
+
id?: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
plugins?: PluginRegistry;
|
|
9
|
+
fetchContext?: LinkCardFetchContext;
|
|
10
|
+
}
|
|
11
|
+
export declare const LinkCardRenderer: ComponentType<EnhancedLinkCardProps>;
|
|
12
|
+
//# sourceMappingURL=LinkCardRenderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkCardRenderer.d.ts","sourceRoot":"","sources":["../src/LinkCardRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAEhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAO1C,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAEnE,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;IAClE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,YAAY,CAAC,EAAE,oBAAoB,CAAA;CACpC;AAgBD,eAAO,MAAM,gBAAgB,EAAE,aAAa,CAAC,qBAAqB,CAqJjE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkCardSkeleton.d.ts","sourceRoot":"","sources":["../src/LinkCardSkeleton.tsx"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,CAAC,EAC/B,MAAM,EACN,SAAS,GACV,EAAE;IACD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,2CAsBA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LinkCardData, LinkCardFetchContext, LinkCardPlugin } from '../types';
|
|
2
|
+
export interface UseCardFetcherOptions {
|
|
3
|
+
source?: string;
|
|
4
|
+
plugin?: LinkCardPlugin;
|
|
5
|
+
id: string;
|
|
6
|
+
fallbackUrl?: string;
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
context?: LinkCardFetchContext;
|
|
9
|
+
}
|
|
10
|
+
export interface UseCardFetcherResult {
|
|
11
|
+
loading: boolean;
|
|
12
|
+
isError: boolean;
|
|
13
|
+
cardInfo: LinkCardData | undefined;
|
|
14
|
+
fullUrl: string;
|
|
15
|
+
isValid: boolean;
|
|
16
|
+
ref: (node?: Element | null) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare function useCardFetcher(options: UseCardFetcherOptions): UseCardFetcherResult;
|
|
19
|
+
//# sourceMappingURL=useCardFetcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCardFetcher.d.ts","sourceRoot":"","sources":["../../src/hooks/useCardFetcher.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACf,MAAM,UAAU,CAAA;AAEjB,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,CAAC,EAAE,oBAAoB,CAAA;CAC/B;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAA;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,CAAA;CACrC;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,qBAAqB,GAC7B,oBAAoB,CAiDtB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LinkCardPlugin, PluginRegistry, UrlMatchResult } from '../types';
|
|
2
|
+
export interface UrlMatchInfo {
|
|
3
|
+
plugin: LinkCardPlugin;
|
|
4
|
+
match: UrlMatchResult;
|
|
5
|
+
}
|
|
6
|
+
export declare function useUrlMatcher(url: string | undefined, pluginRegistry?: PluginRegistry): UrlMatchInfo | null;
|
|
7
|
+
//# sourceMappingURL=useUrlMatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUrlMatcher.d.ts","sourceRoot":"","sources":["../../src/hooks/useUrlMatcher.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9E,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,cAAc,CAAA;IACtB,KAAK,EAAE,cAAc,CAAA;CACtB;AAED,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,cAAc,GAAE,cAA+B,GAC9C,YAAY,GAAG,IAAI,CAcrB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type { UrlMatchInfo } from './hooks/useUrlMatcher';
|
|
2
|
+
export { useUrlMatcher } from './hooks/useUrlMatcher';
|
|
3
|
+
export { LinkCardEditDecorator } from './LinkCardEditDecorator';
|
|
4
|
+
export { LinkCardEditNode, linkCardEditNodes } from './LinkCardEditNode';
|
|
5
|
+
export type { EnhancedLinkCardProps } from './LinkCardRenderer';
|
|
6
|
+
export { LinkCardRenderer } from './LinkCardRenderer';
|
|
7
|
+
export { LinkCardSkeleton } from './LinkCardSkeleton';
|
|
8
|
+
export { getPluginByName, pluginMap, plugins } from './plugins';
|
|
9
|
+
export { arxivPlugin, bangumiPlugin, githubCommitPlugin, githubDiscussionPlugin, githubIssuePlugin, githubPrPlugin, githubRepoPlugin, leetcodePlugin, mxSpacePlugin, neteaseMusicPlugin, qqMusicPlugin, tmdbPlugin, } from './plugins';
|
|
10
|
+
export { createMxSpacePlugin } from './plugins';
|
|
11
|
+
export type { MxSpacePluginConfig } from './plugins/self';
|
|
12
|
+
export type { LinkCardApiAdapter, LinkCardData, LinkCardFetchContext, LinkCardPlugin, LinkCardTypeClass, PluginRegistry, UrlMatchResult, } from './types';
|
|
13
|
+
export { camelcaseKeys, fetchGitHubApi, fetchJsonWithContext, generateColor, LanguageToColorMap, } from './utils';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACxE,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC/D,OAAO,EACL,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,UAAU,GACX,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAC/C,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACzD,YAAY,EACV,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,cAAc,GACf,MAAM,SAAS,CAAA;AAChB,OAAO,EACL,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,kBAAkB,GACnB,MAAM,SAAS,CAAA"}
|