@mzebley/mark-down-react 1.2.1 → 1.2.2

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/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@mzebley/mark-down-react",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "mark↓ React Adapter",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.mjs",
8
8
  "types": "dist/index.d.ts",
9
+ "files": ["dist"],
9
10
  "publishConfig": {
10
11
  "access": "public"
11
12
  },
@@ -13,7 +14,7 @@
13
14
  "build": "tsup src/index.ts --dts --format esm,cjs"
14
15
  },
15
16
  "dependencies": {
16
- "@mzebley/mark-down": "^1.2.1",
17
+ "@mzebley/mark-down": "^1.2.2",
17
18
  "dompurify": "^3.0.5"
18
19
  },
19
20
  "peerDependencies": {
package/src/context.tsx DELETED
@@ -1,32 +0,0 @@
1
- import { createContext, ReactNode, useContext, useMemo } from "react";
2
- import { SnippetClient, type SnippetClientOptions } from "@mzebley/mark-down";
3
-
4
- const SnippetClientContext = createContext<SnippetClient | null>(null);
5
-
6
- export interface SnippetProviderProps {
7
- client?: SnippetClient;
8
- options?: SnippetClientOptions;
9
- children: ReactNode;
10
- }
11
-
12
- export function SnippetProvider({ client, options, children }: SnippetProviderProps) {
13
- const value = useMemo(() => {
14
- if (client) {
15
- return client;
16
- }
17
- if (options) {
18
- return new SnippetClient(options);
19
- }
20
- throw new Error("SnippetProvider requires either a client or options");
21
- }, [client, options]);
22
-
23
- return <SnippetClientContext.Provider value={value}>{children}</SnippetClientContext.Provider>;
24
- }
25
-
26
- export function useSnippetClient(): SnippetClient {
27
- const client = useContext(SnippetClientContext);
28
- if (!client) {
29
- throw new Error("useSnippetClient must be used within a SnippetProvider");
30
- }
31
- return client;
32
- }
package/src/hooks.ts DELETED
@@ -1,43 +0,0 @@
1
- import { useEffect, useState } from "react";
2
- import type { Snippet } from "@mzebley/mark-down";
3
- import { useSnippetClient } from "./context";
4
-
5
- export interface UseSnippetResult {
6
- snippet?: Snippet;
7
- loading: boolean;
8
- error?: Error;
9
- }
10
-
11
- export function useSnippet(slug?: string | null): UseSnippetResult {
12
- const client = useSnippetClient();
13
- const [result, setResult] = useState<UseSnippetResult>(() => ({
14
- loading: Boolean(slug)
15
- }));
16
-
17
- useEffect(() => {
18
- if (!slug) {
19
- setResult({ loading: false });
20
- return;
21
- }
22
-
23
- let cancelled = false;
24
- setResult((prev) => ({ ...prev, loading: true, error: undefined }));
25
-
26
- client
27
- .get(slug)
28
- .then((snippet) => {
29
- if (cancelled) return;
30
- setResult({ snippet, loading: false });
31
- })
32
- .catch((error: Error) => {
33
- if (cancelled) return;
34
- setResult({ loading: false, error });
35
- });
36
-
37
- return () => {
38
- cancelled = true;
39
- };
40
- }, [client, slug]);
41
-
42
- return result;
43
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./context";
2
- export * from "./hooks";
3
- export * from "./snippet-view";
@@ -1,41 +0,0 @@
1
- import { ReactNode, useEffect, useMemo } from "react";
2
- import DOMPurify from "dompurify";
3
- import type { Snippet } from "@mzebley/mark-down";
4
- import { useSnippet } from "./hooks";
5
-
6
- export interface SnippetViewProps {
7
- slug: string;
8
- className?: string;
9
- loadingFallback?: ReactNode;
10
- errorFallback?: ReactNode;
11
- onLoaded?: (snippet?: Snippet) => void;
12
- }
13
-
14
- export function SnippetView({
15
- slug,
16
- className,
17
- loadingFallback = "Loading…",
18
- errorFallback = "Unable to load snippet",
19
- onLoaded
20
- }: SnippetViewProps) {
21
- const state = useSnippet(slug);
22
- const safeHtml = useMemo(() => (state.snippet ? DOMPurify.sanitize(state.snippet.html) : undefined), [state.snippet]);
23
-
24
- useEffect(() => {
25
- onLoaded?.(state.snippet);
26
- }, [state.snippet, onLoaded]);
27
-
28
- if (state.loading) {
29
- return <div className={className}>{loadingFallback}</div>;
30
- }
31
-
32
- if (state.error) {
33
- return <div className={className}>{errorFallback}</div>;
34
- }
35
-
36
- if (!state.snippet) {
37
- return <div className={className}>Snippet not found</div>;
38
- }
39
-
40
- return <div className={className} dangerouslySetInnerHTML={{ __html: safeHtml ?? "" }} />;
41
- }
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "jsx": "react-jsx",
5
- "outDir": "dist"
6
- },
7
- "include": ["src/**/*"]
8
- }