@khairold/xml-render 0.1.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.
Files changed (58) hide show
  1. package/README.md +372 -0
  2. package/dist/index.d.ts +33 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +41 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/parser.d.ts +129 -0
  7. package/dist/parser.d.ts.map +1 -0
  8. package/dist/parser.js +321 -0
  9. package/dist/parser.js.map +1 -0
  10. package/dist/react/ErrorBoundary.d.ts +56 -0
  11. package/dist/react/ErrorBoundary.d.ts.map +1 -0
  12. package/dist/react/ErrorBoundary.js +69 -0
  13. package/dist/react/ErrorBoundary.js.map +1 -0
  14. package/dist/react/XmlRender.d.ts +62 -0
  15. package/dist/react/XmlRender.d.ts.map +1 -0
  16. package/dist/react/XmlRender.js +90 -0
  17. package/dist/react/XmlRender.js.map +1 -0
  18. package/dist/react/catalog.d.ts +99 -0
  19. package/dist/react/catalog.d.ts.map +1 -0
  20. package/dist/react/catalog.js +55 -0
  21. package/dist/react/catalog.js.map +1 -0
  22. package/dist/react/context.d.ts +66 -0
  23. package/dist/react/context.d.ts.map +1 -0
  24. package/dist/react/context.js +63 -0
  25. package/dist/react/context.js.map +1 -0
  26. package/dist/react/index.d.ts +35 -0
  27. package/dist/react/index.d.ts.map +1 -0
  28. package/dist/react/index.js +41 -0
  29. package/dist/react/index.js.map +1 -0
  30. package/dist/react-native/ErrorBoundary.d.ts +60 -0
  31. package/dist/react-native/ErrorBoundary.d.ts.map +1 -0
  32. package/dist/react-native/ErrorBoundary.js +84 -0
  33. package/dist/react-native/ErrorBoundary.js.map +1 -0
  34. package/dist/react-native/XmlRender.d.ts +62 -0
  35. package/dist/react-native/XmlRender.d.ts.map +1 -0
  36. package/dist/react-native/XmlRender.js +91 -0
  37. package/dist/react-native/XmlRender.js.map +1 -0
  38. package/dist/react-native/catalog.d.ts +100 -0
  39. package/dist/react-native/catalog.d.ts.map +1 -0
  40. package/dist/react-native/catalog.js +56 -0
  41. package/dist/react-native/catalog.js.map +1 -0
  42. package/dist/react-native/context.d.ts +66 -0
  43. package/dist/react-native/context.d.ts.map +1 -0
  44. package/dist/react-native/context.js +63 -0
  45. package/dist/react-native/context.js.map +1 -0
  46. package/dist/react-native/index.d.ts +35 -0
  47. package/dist/react-native/index.d.ts.map +1 -0
  48. package/dist/react-native/index.js +41 -0
  49. package/dist/react-native/index.js.map +1 -0
  50. package/dist/registry.d.ts +99 -0
  51. package/dist/registry.d.ts.map +1 -0
  52. package/dist/registry.js +93 -0
  53. package/dist/registry.js.map +1 -0
  54. package/dist/types.d.ts +436 -0
  55. package/dist/types.d.ts.map +1 -0
  56. package/dist/types.js +28 -0
  57. package/dist/types.js.map +1 -0
  58. package/package.json +60 -0
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Component Catalog for React XML Renderer
3
+ *
4
+ * Creates a type-safe mapping from segment types to React components.
5
+ * The catalog ensures that each registered tag type has a corresponding
6
+ * renderer component with properly typed props.
7
+ */
8
+ import type { ComponentType } from "react";
9
+ import type { TagDefinitions, Registry } from "../registry";
10
+ import type { ParsedSegment } from "../parser";
11
+ /**
12
+ * Props passed to segment renderer components
13
+ */
14
+ export interface SegmentProps<TDefs extends TagDefinitions, TType extends keyof TDefs | "text"> {
15
+ /** The segment being rendered */
16
+ segment: ParsedSegment<TDefs, TType>;
17
+ /** Index of this segment in the segments array */
18
+ index: number;
19
+ }
20
+ /**
21
+ * Props for the text segment renderer
22
+ */
23
+ export interface TextSegmentProps<TDefs extends TagDefinitions> {
24
+ segment: ParsedSegment<TDefs, "text">;
25
+ index: number;
26
+ }
27
+ /**
28
+ * A component that renders a specific segment type
29
+ */
30
+ export type SegmentRenderer<TDefs extends TagDefinitions, TType extends keyof TDefs> = ComponentType<SegmentProps<TDefs, TType>>;
31
+ /**
32
+ * A component that renders text segments
33
+ */
34
+ export type TextRenderer<TDefs extends TagDefinitions> = ComponentType<TextSegmentProps<TDefs>>;
35
+ /**
36
+ * Component definitions for the catalog - maps tag names to renderers
37
+ */
38
+ export type CatalogComponents<TDefs extends TagDefinitions> = {
39
+ [K in keyof TDefs]: SegmentRenderer<TDefs, K>;
40
+ };
41
+ /**
42
+ * The catalog interface returned by createCatalog
43
+ */
44
+ export interface Catalog<TDefs extends TagDefinitions> {
45
+ /** Get the renderer component for a specific segment type */
46
+ getRenderer<K extends keyof TDefs>(type: K): SegmentRenderer<TDefs, K> | undefined;
47
+ /** Get the text segment renderer */
48
+ getTextRenderer(): TextRenderer<TDefs> | undefined;
49
+ /** Check if a renderer exists for a segment type */
50
+ hasRenderer(type: keyof TDefs | "text"): boolean;
51
+ /** The registry this catalog is based on */
52
+ readonly registry: Registry<TDefs>;
53
+ /** All registered component renderers */
54
+ readonly components: Readonly<Partial<CatalogComponents<TDefs>>>;
55
+ }
56
+ /**
57
+ * Options for creating a catalog
58
+ */
59
+ export interface CatalogOptions<TDefs extends TagDefinitions> {
60
+ /** Component renderers for each tag type */
61
+ components: Partial<CatalogComponents<TDefs>>;
62
+ /** Optional text segment renderer (default renders plain text in a span) */
63
+ textRenderer?: TextRenderer<TDefs>;
64
+ }
65
+ /**
66
+ * Create a component catalog for rendering XML segments.
67
+ *
68
+ * The catalog maps registered tag types to React components that render them.
69
+ * TypeScript ensures that component props match the tag's attribute schema.
70
+ *
71
+ * @example
72
+ * ```tsx
73
+ * import { createCatalog } from '@aura/xml-render/react';
74
+ * import { registry } from './xml-registry';
75
+ *
76
+ * const catalog = createCatalog(registry, {
77
+ * components: {
78
+ * callout: ({ segment }) => (
79
+ * <div className={`callout callout-${segment.attributes?.type}`}>
80
+ * {segment.content}
81
+ * </div>
82
+ * ),
83
+ * chart: ({ segment }) => (
84
+ * <ChartComponent
85
+ * type={segment.attributes?.type}
86
+ * data={segment.content}
87
+ * />
88
+ * ),
89
+ * },
90
+ * textRenderer: ({ segment }) => <span>{segment.content}</span>,
91
+ * });
92
+ * ```
93
+ *
94
+ * @param registry - The tag registry defining valid segment types
95
+ * @param options - Component renderers and optional text renderer
96
+ * @returns A catalog instance for use with XmlRenderProvider
97
+ */
98
+ export declare function createCatalog<TDefs extends TagDefinitions>(registry: Registry<TDefs>, options: CatalogOptions<TDefs>): Catalog<TDefs>;
99
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/react/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EACV,cAAc,EACd,QAAQ,EAET,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,YAAY,CAC3B,KAAK,SAAS,cAAc,EAC5B,KAAK,SAAS,MAAM,KAAK,GAAG,MAAM;IAElC,iCAAiC;IACjC,OAAO,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACrC,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,KAAK,SAAS,cAAc;IAC5D,OAAO,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACtC,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,CACzB,KAAK,SAAS,cAAc,EAC5B,KAAK,SAAS,MAAM,KAAK,IACvB,aAAa,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,KAAK,SAAS,cAAc,IAAI,aAAa,CACpE,gBAAgB,CAAC,KAAK,CAAC,CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,KAAK,SAAS,cAAc,IAAI;KAC3D,CAAC,IAAI,MAAM,KAAK,GAAG,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC;CAC9C,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,OAAO,CAAC,KAAK,SAAS,cAAc;IACnD,6DAA6D;IAC7D,WAAW,CAAC,CAAC,SAAS,MAAM,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;IAEnF,oCAAoC;IACpC,eAAe,IAAI,YAAY,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;IAEnD,oDAAoD;IACpD,WAAW,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;IAEjD,4CAA4C;IAC5C,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEnC,yCAAyC;IACzC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;CAClE;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,KAAK,SAAS,cAAc;IAC1D,4CAA4C;IAC5C,UAAU,EAAE,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9C,4EAA4E;IAC5E,YAAY,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,aAAa,CAAC,KAAK,SAAS,cAAc,EACxD,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,EACzB,OAAO,EAAE,cAAc,CAAC,KAAK,CAAC,GAC7B,OAAO,CAAC,KAAK,CAAC,CA4BhB"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Create a component catalog for rendering XML segments.
3
+ *
4
+ * The catalog maps registered tag types to React components that render them.
5
+ * TypeScript ensures that component props match the tag's attribute schema.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { createCatalog } from '@aura/xml-render/react';
10
+ * import { registry } from './xml-registry';
11
+ *
12
+ * const catalog = createCatalog(registry, {
13
+ * components: {
14
+ * callout: ({ segment }) => (
15
+ * <div className={`callout callout-${segment.attributes?.type}`}>
16
+ * {segment.content}
17
+ * </div>
18
+ * ),
19
+ * chart: ({ segment }) => (
20
+ * <ChartComponent
21
+ * type={segment.attributes?.type}
22
+ * data={segment.content}
23
+ * />
24
+ * ),
25
+ * },
26
+ * textRenderer: ({ segment }) => <span>{segment.content}</span>,
27
+ * });
28
+ * ```
29
+ *
30
+ * @param registry - The tag registry defining valid segment types
31
+ * @param options - Component renderers and optional text renderer
32
+ * @returns A catalog instance for use with XmlRenderProvider
33
+ */
34
+ export function createCatalog(registry, options) {
35
+ const { components, textRenderer } = options;
36
+ const frozenComponents = Object.freeze({ ...components });
37
+ const catalog = {
38
+ registry,
39
+ components: frozenComponents,
40
+ getRenderer(type) {
41
+ return frozenComponents[type];
42
+ },
43
+ getTextRenderer() {
44
+ return textRenderer;
45
+ },
46
+ hasRenderer(type) {
47
+ if (type === "text") {
48
+ return textRenderer !== undefined;
49
+ }
50
+ return type in frozenComponents;
51
+ },
52
+ };
53
+ return Object.freeze(catalog);
54
+ }
55
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/react/catalog.ts"],"names":[],"mappings":"AAwFA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,aAAa,CAC3B,QAAyB,EACzB,OAA8B;IAE9B,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAE7C,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,UAAU,EAAE,CAEvD,CAAC;IAEF,MAAM,OAAO,GAAmB;QAC9B,QAAQ;QACR,UAAU,EAAE,gBAAgB;QAE5B,WAAW,CAAwB,IAAO;YACxC,OAAO,gBAAgB,CAAC,IAAI,CAA0C,CAAC;QACzE,CAAC;QAED,eAAe;YACb,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,WAAW,CAAC,IAA0B;YACpC,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBACpB,OAAO,YAAY,KAAK,SAAS,CAAC;YACpC,CAAC;YACD,OAAO,IAAI,IAAI,gBAAgB,CAAC;QAClC,CAAC;KACF,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * React Context for XML Render
3
+ *
4
+ * Provides the component catalog to the render tree via React Context.
5
+ * This allows XmlRender components to access the catalog without prop drilling.
6
+ */
7
+ import React, { type ReactNode } from "react";
8
+ import type { TagDefinitions } from "../registry";
9
+ import type { Catalog } from "./catalog";
10
+ /**
11
+ * Context value type containing the catalog
12
+ */
13
+ interface XmlRenderContextValue<TDefs extends TagDefinitions> {
14
+ catalog: Catalog<TDefs>;
15
+ }
16
+ /**
17
+ * Props for XmlRenderProvider
18
+ */
19
+ export interface XmlRenderProviderProps<TDefs extends TagDefinitions> {
20
+ /** The component catalog to provide to the tree */
21
+ catalog: Catalog<TDefs>;
22
+ /** Child components that can use XmlRender */
23
+ children: ReactNode;
24
+ }
25
+ /**
26
+ * Provider component that makes the catalog available to XmlRender components.
27
+ *
28
+ * Wrap your application or component tree with this provider to enable
29
+ * XML segment rendering.
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * import { XmlRenderProvider } from '@aura/xml-render/react';
34
+ * import { catalog } from './xml-catalog';
35
+ *
36
+ * function App() {
37
+ * return (
38
+ * <XmlRenderProvider catalog={catalog}>
39
+ * <MyContent />
40
+ * </XmlRenderProvider>
41
+ * );
42
+ * }
43
+ * ```
44
+ */
45
+ export declare function XmlRenderProvider<TDefs extends TagDefinitions>({ catalog, children, }: XmlRenderProviderProps<TDefs>): React.ReactElement;
46
+ /**
47
+ * Hook to access the XML render catalog from context.
48
+ *
49
+ * Must be used within an XmlRenderProvider.
50
+ *
51
+ * @throws Error if used outside of XmlRenderProvider
52
+ * @returns The current catalog from context
53
+ *
54
+ * @example
55
+ * ```tsx
56
+ * import { useXmlRenderContext } from '@aura/xml-render/react';
57
+ *
58
+ * function CustomRenderer() {
59
+ * const { catalog } = useXmlRenderContext();
60
+ * // Use catalog to look up renderers...
61
+ * }
62
+ * ```
63
+ */
64
+ export declare function useXmlRenderContext<TDefs extends TagDefinitions = TagDefinitions>(): XmlRenderContextValue<TDefs>;
65
+ export {};
66
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/react/context.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;GAEG;AACH,UAAU,qBAAqB,CAAC,KAAK,SAAS,cAAc;IAC1D,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;CACzB;AAeD;;GAEG;AACH,MAAM,WAAW,sBAAsB,CAAC,KAAK,SAAS,cAAc;IAClE,mDAAmD;IACnD,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACxB,8CAA8C;IAC9C,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,SAAS,cAAc,EAAE,EAC9D,OAAO,EACP,QAAQ,GACT,EAAE,sBAAsB,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,YAAY,CAQpD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,SAAS,cAAc,GAAG,cAAc,KAC1C,qBAAqB,CAAC,KAAK,CAAC,CAWhC"}
@@ -0,0 +1,63 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * React Context for XML Render
4
+ *
5
+ * Provides the component catalog to the render tree via React Context.
6
+ * This allows XmlRender components to access the catalog without prop drilling.
7
+ */
8
+ import { createContext, useContext } from "react";
9
+ /**
10
+ * Internal context - stores catalog as unknown, typed at provider/consumer level
11
+ */
12
+ const XmlRenderContext = createContext(null);
13
+ /**
14
+ * Provider component that makes the catalog available to XmlRender components.
15
+ *
16
+ * Wrap your application or component tree with this provider to enable
17
+ * XML segment rendering.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * import { XmlRenderProvider } from '@aura/xml-render/react';
22
+ * import { catalog } from './xml-catalog';
23
+ *
24
+ * function App() {
25
+ * return (
26
+ * <XmlRenderProvider catalog={catalog}>
27
+ * <MyContent />
28
+ * </XmlRenderProvider>
29
+ * );
30
+ * }
31
+ * ```
32
+ */
33
+ export function XmlRenderProvider({ catalog, children, }) {
34
+ const value = { catalog };
35
+ return (_jsx(XmlRenderContext.Provider, { value: value, children: children }));
36
+ }
37
+ /**
38
+ * Hook to access the XML render catalog from context.
39
+ *
40
+ * Must be used within an XmlRenderProvider.
41
+ *
42
+ * @throws Error if used outside of XmlRenderProvider
43
+ * @returns The current catalog from context
44
+ *
45
+ * @example
46
+ * ```tsx
47
+ * import { useXmlRenderContext } from '@aura/xml-render/react';
48
+ *
49
+ * function CustomRenderer() {
50
+ * const { catalog } = useXmlRenderContext();
51
+ * // Use catalog to look up renderers...
52
+ * }
53
+ * ```
54
+ */
55
+ export function useXmlRenderContext() {
56
+ const context = useContext(XmlRenderContext);
57
+ if (!context) {
58
+ throw new Error("useXmlRenderContext must be used within an XmlRenderProvider");
59
+ }
60
+ // Cast the internal unknown catalog back to the typed version
61
+ return { catalog: context.catalog };
62
+ }
63
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/react/context.tsx"],"names":[],"mappings":";AAAA;;;;;GAKG;AACH,OAAc,EAAE,aAAa,EAAE,UAAU,EAAkB,MAAM,OAAO,CAAC;AAmBzE;;GAEG;AACH,MAAM,gBAAgB,GAAG,aAAa,CAA8B,IAAI,CAAC,CAAC;AAY1E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,iBAAiB,CAA+B,EAC9D,OAAO,EACP,QAAQ,GACsB;IAC9B,MAAM,KAAK,GAAyB,EAAE,OAAO,EAAE,CAAC;IAEhD,OAAO,CACL,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACpC,QAAQ,GACiB,CAC7B,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,mBAAmB;IAGjC,MAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAE7C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAC;IACJ,CAAC;IAED,8DAA8D;IAC9D,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAyB,EAAE,CAAC;AACxD,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @aura/xml-render/react - React Renderer
3
+ *
4
+ * React components for rendering parsed XML segments.
5
+ * Use this entry point for web applications.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { XmlRenderProvider, XmlRender, createCatalog } from '@aura/xml-render/react';
10
+ * import { createParser, createRegistry } from '@aura/xml-render';
11
+ *
12
+ * // Create catalog with your component renderers
13
+ * const catalog = createCatalog(registry, {
14
+ * components: {
15
+ * callout: ({ segment }) => <Callout type={segment.attributes?.type}>{segment.content}</Callout>,
16
+ * },
17
+ * });
18
+ *
19
+ * // Render segments
20
+ * <XmlRenderProvider catalog={catalog}>
21
+ * <XmlRender segments={parser.parse(text)} />
22
+ * </XmlRenderProvider>
23
+ * ```
24
+ *
25
+ * @packageDocumentation
26
+ */
27
+ export { createCatalog } from "./catalog";
28
+ export { XmlRenderProvider, useXmlRenderContext } from "./context";
29
+ export { XmlRender } from "./XmlRender";
30
+ export { ErrorBoundary } from "./ErrorBoundary";
31
+ export type { Catalog, CatalogOptions, CatalogComponents, SegmentProps, SegmentRenderer, TextRenderer, TextSegmentProps, } from "./catalog";
32
+ export type { XmlRenderProviderProps } from "./context";
33
+ export type { XmlRenderProps } from "./XmlRender";
34
+ export type { ErrorBoundaryProps } from "./ErrorBoundary";
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAOH,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAO1C,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAGnE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAOhD,YAAY,EACV,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,gBAAgB,GACjB,MAAM,WAAW,CAAC;AAGnB,YAAY,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAGxD,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @aura/xml-render/react - React Renderer
3
+ *
4
+ * React components for rendering parsed XML segments.
5
+ * Use this entry point for web applications.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { XmlRenderProvider, XmlRender, createCatalog } from '@aura/xml-render/react';
10
+ * import { createParser, createRegistry } from '@aura/xml-render';
11
+ *
12
+ * // Create catalog with your component renderers
13
+ * const catalog = createCatalog(registry, {
14
+ * components: {
15
+ * callout: ({ segment }) => <Callout type={segment.attributes?.type}>{segment.content}</Callout>,
16
+ * },
17
+ * });
18
+ *
19
+ * // Render segments
20
+ * <XmlRenderProvider catalog={catalog}>
21
+ * <XmlRender segments={parser.parse(text)} />
22
+ * </XmlRenderProvider>
23
+ * ```
24
+ *
25
+ * @packageDocumentation
26
+ */
27
+ // ============================================================================
28
+ // Core Functions
29
+ // ============================================================================
30
+ // Catalog - Create component mappings
31
+ export { createCatalog } from "./catalog";
32
+ // ============================================================================
33
+ // Components
34
+ // ============================================================================
35
+ // Provider and consumer hook
36
+ export { XmlRenderProvider, useXmlRenderContext } from "./context";
37
+ // Main render component
38
+ export { XmlRender } from "./XmlRender";
39
+ // Error boundary for safe rendering
40
+ export { ErrorBoundary } from "./ErrorBoundary";
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E,sCAAsC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E,6BAA6B;AAC7B,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEnE,wBAAwB;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,oCAAoC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * ErrorBoundary Component for React Native
3
+ *
4
+ * Catches render errors in segment components and displays a fallback UI.
5
+ * Prevents a single segment error from crashing the entire content area.
6
+ */
7
+ import { Component, type ReactNode, type ErrorInfo } from "react";
8
+ /**
9
+ * Props for the ErrorBoundary component
10
+ */
11
+ export interface ErrorBoundaryProps {
12
+ /** The child components to render */
13
+ children: ReactNode;
14
+ /** The segment type being rendered (for error messages) */
15
+ segmentType: string;
16
+ /** Optional custom fallback renderer */
17
+ fallback?: (error: Error, segmentType: string) => ReactNode;
18
+ }
19
+ /**
20
+ * State for the ErrorBoundary component
21
+ */
22
+ interface ErrorBoundaryState {
23
+ hasError: boolean;
24
+ error: Error | null;
25
+ }
26
+ /**
27
+ * Error boundary component that catches render errors in child components.
28
+ *
29
+ * In development mode, displays a visible error message with segment type and error details.
30
+ * In production mode, renders a minimal hidden fallback to avoid disrupting the UI.
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * <ErrorBoundary segmentType="chart">
35
+ * <ChartComponent data={data} />
36
+ * </ErrorBoundary>
37
+ * ```
38
+ *
39
+ * @example With custom fallback
40
+ * ```tsx
41
+ * <ErrorBoundary
42
+ * segmentType="table"
43
+ * fallback={(error, type) => (
44
+ * <View>
45
+ * <Text>Failed to render {type}: {error.message}</Text>
46
+ * </View>
47
+ * )}
48
+ * >
49
+ * <TableComponent data={data} />
50
+ * </ErrorBoundary>
51
+ * ```
52
+ */
53
+ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
54
+ constructor(props: ErrorBoundaryProps);
55
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState;
56
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
57
+ render(): ReactNode;
58
+ }
59
+ export {};
60
+ //# sourceMappingURL=ErrorBoundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorBoundary.d.ts","sourceRoot":"","sources":["../../src/react-native/ErrorBoundary.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAc,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAGzE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,qCAAqC;IACrC,QAAQ,EAAE,SAAS,CAAC;IACpB,2DAA2D;IAC3D,WAAW,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,KAAK,SAAS,CAAC;CAC7D;AAED;;GAEG;AACH,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,aAAc,SAAQ,SAAS,CAC1C,kBAAkB,EAClB,kBAAkB,CACnB;gBACa,KAAK,EAAE,kBAAkB;IAKrC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,kBAAkB;IAIjE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI;IAS3D,MAAM,IAAI,SAAS;CAwBpB"}
@@ -0,0 +1,84 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * ErrorBoundary Component for React Native
4
+ *
5
+ * Catches render errors in segment components and displays a fallback UI.
6
+ * Prevents a single segment error from crashing the entire content area.
7
+ */
8
+ import { Component } from "react";
9
+ import { View, Text, StyleSheet } from "react-native";
10
+ /**
11
+ * Error boundary component that catches render errors in child components.
12
+ *
13
+ * In development mode, displays a visible error message with segment type and error details.
14
+ * In production mode, renders a minimal hidden fallback to avoid disrupting the UI.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * <ErrorBoundary segmentType="chart">
19
+ * <ChartComponent data={data} />
20
+ * </ErrorBoundary>
21
+ * ```
22
+ *
23
+ * @example With custom fallback
24
+ * ```tsx
25
+ * <ErrorBoundary
26
+ * segmentType="table"
27
+ * fallback={(error, type) => (
28
+ * <View>
29
+ * <Text>Failed to render {type}: {error.message}</Text>
30
+ * </View>
31
+ * )}
32
+ * >
33
+ * <TableComponent data={data} />
34
+ * </ErrorBoundary>
35
+ * ```
36
+ */
37
+ export class ErrorBoundary extends Component {
38
+ constructor(props) {
39
+ super(props);
40
+ this.state = { hasError: false, error: null };
41
+ }
42
+ static getDerivedStateFromError(error) {
43
+ return { hasError: true, error };
44
+ }
45
+ componentDidCatch(error, errorInfo) {
46
+ // Log the error for debugging
47
+ console.error(`XmlRender ErrorBoundary: Failed to render segment type "${this.props.segmentType}"`, error, errorInfo.componentStack);
48
+ }
49
+ render() {
50
+ if (this.state.hasError && this.state.error) {
51
+ // Use custom fallback if provided
52
+ if (this.props.fallback) {
53
+ return this.props.fallback(this.state.error, this.props.segmentType);
54
+ }
55
+ // Development: show detailed error info
56
+ if (process.env.NODE_ENV === "development") {
57
+ return (_jsx(View, { style: styles.errorContainer, children: _jsxs(Text, { style: styles.errorText, children: ["Error in [", this.props.segmentType, "]: ", this.state.error.message] }) }));
58
+ }
59
+ // Production: minimal hidden fallback
60
+ return _jsx(View, { style: styles.hidden });
61
+ }
62
+ return this.props.children;
63
+ }
64
+ }
65
+ const styles = StyleSheet.create({
66
+ errorContainer: {
67
+ padding: 8,
68
+ backgroundColor: "#fee2e2",
69
+ borderWidth: 1,
70
+ borderColor: "#ef4444",
71
+ borderRadius: 4,
72
+ },
73
+ errorText: {
74
+ color: "#991b1b",
75
+ fontSize: 12,
76
+ fontFamily: "monospace",
77
+ },
78
+ hidden: {
79
+ width: 0,
80
+ height: 0,
81
+ overflow: "hidden",
82
+ },
83
+ });
84
+ //# sourceMappingURL=ErrorBoundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorBoundary.js","sourceRoot":"","sources":["../../src/react-native/ErrorBoundary.tsx"],"names":[],"mappings":";AAAA;;;;;GAKG;AACH,OAAc,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAsBtD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,aAAc,SAAQ,SAGlC;IACC,YAAY,KAAyB;QACnC,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,KAAK,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAChD,CAAC;IAED,MAAM,CAAC,wBAAwB,CAAC,KAAY;QAC1C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACnC,CAAC;IAED,iBAAiB,CAAC,KAAY,EAAE,SAAoB;QAClD,8BAA8B;QAC9B,OAAO,CAAC,KAAK,CACX,2DAA2D,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,EACpF,KAAK,EACL,SAAS,CAAC,cAAc,CACzB,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YAC5C,kCAAkC;YAClC,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;gBACxB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YACvE,CAAC;YAED,wCAAwC;YACxC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;gBAC3C,OAAO,CACL,KAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,cAAc,YAChC,MAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,SAAS,2BAChB,IAAI,CAAC,KAAK,CAAC,WAAW,SAAK,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,IACzD,GACF,CACR,CAAC;YACJ,CAAC;YAED,sCAAsC;YACtC,OAAO,KAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,GAAI,CAAC;QACxC,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,cAAc,EAAE;QACd,OAAO,EAAE,CAAC;QACV,eAAe,EAAE,SAAS;QAC1B,WAAW,EAAE,CAAC;QACd,WAAW,EAAE,SAAS;QACtB,YAAY,EAAE,CAAC;KAChB;IACD,SAAS,EAAE;QACT,KAAK,EAAE,SAAS;QAChB,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,WAAW;KACxB;IACD,MAAM,EAAE;QACN,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;QACT,QAAQ,EAAE,QAAQ;KACnB;CACF,CAAC,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * XmlRender Component for React Native
3
+ *
4
+ * Renders an array of parsed segments using the component catalog.
5
+ * Each segment is rendered by its corresponding component from the catalog.
6
+ */
7
+ import { type ReactElement, type ReactNode } from "react";
8
+ import type { TagDefinitions } from "../registry";
9
+ import type { Segments, ParsedSegment } from "../parser";
10
+ import type { Catalog } from "./catalog";
11
+ /**
12
+ * Props for the XmlRender component
13
+ */
14
+ export interface XmlRenderProps<TDefs extends TagDefinitions> {
15
+ /** Array of parsed segments to render */
16
+ segments: Segments<TDefs>;
17
+ /** Optional fallback renderer for unknown segment types */
18
+ fallback?: (segment: ParsedSegment<TDefs>, index: number) => ReactNode;
19
+ /** Optional catalog override (uses context catalog if not provided) */
20
+ catalog?: Catalog<TDefs>;
21
+ /** Optional custom error fallback renderer */
22
+ errorFallback?: (error: Error, segmentType: string) => ReactNode;
23
+ }
24
+ /**
25
+ * Renders an array of parsed XML segments using the component catalog.
26
+ *
27
+ * Each segment is matched to its corresponding renderer component from the catalog.
28
+ * Text segments use the catalog's text renderer or a default Text component renderer.
29
+ * Unknown segment types use the fallback prop or render content as plain text.
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * import { XmlRender, XmlRenderProvider } from '@aura/xml-render/react-native';
34
+ * import { createParser } from '@aura/xml-render';
35
+ * import { registry, catalog } from './xml-config';
36
+ *
37
+ * function RichContent({ text }: { text: string }) {
38
+ * const parser = createParser(registry);
39
+ * const segments = parser.parse(text);
40
+ *
41
+ * return (
42
+ * <XmlRenderProvider catalog={catalog}>
43
+ * <XmlRender segments={segments} />
44
+ * </XmlRenderProvider>
45
+ * );
46
+ * }
47
+ * ```
48
+ *
49
+ * @example With custom fallback
50
+ * ```tsx
51
+ * <XmlRender
52
+ * segments={segments}
53
+ * fallback={(segment, index) => (
54
+ * <View style={styles.unknownSegment}>
55
+ * <Text>Unknown: {segment.type} - {segment.content}</Text>
56
+ * </View>
57
+ * )}
58
+ * />
59
+ * ```
60
+ */
61
+ export declare function XmlRender<TDefs extends TagDefinitions>({ segments, fallback, catalog: catalogProp, errorFallback, }: XmlRenderProps<TDefs>): ReactElement;
62
+ //# sourceMappingURL=XmlRender.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XmlRender.d.ts","sourceRoot":"","sources":["../../src/react-native/XmlRender.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAc,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAEzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,KAAK,SAAS,cAAc;IAC1D,yCAAyC;IACzC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1B,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC;IACvE,uEAAuE;IACvE,OAAO,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACzB,8CAA8C;IAC9C,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,KAAK,SAAS,CAAC;CAClE;AAqED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,SAAS,CAAC,KAAK,SAAS,cAAc,EAAE,EACtD,QAAQ,EACR,QAAQ,EACR,OAAO,EAAE,WAAW,EACpB,aAAa,GACd,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,YAAY,CAwBtC"}