@paprize/react 0.0.10 → 0.0.11

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.
@@ -215,7 +215,7 @@ function ee({ elements: e, options: t }) {
215
215
  pageHeader: y.current
216
216
  },
217
217
  (l) => {
218
- O(l);
218
+ O(l.pages);
219
219
  }
220
220
  ).catch((l) => V.error(l)), () => {
221
221
  i.removeSection(o);
@@ -1 +1 @@
1
- {"version":3,"file":"paprize-react.js","sources":["../src/components/ReportPreview.tsx","../src/internal/useReportBuilder.ts","../src/components/ReportRoot.tsx","../src/components/PageContent.tsx","../src/components/PageFooter.tsx","../src/components/PageHeader.tsx","../src/components/SectionFooter.tsx","../src/components/SectionHeader.tsx","../src/components/PageOverlay.tsx","../src/internal/parseSectionChildren.ts","../src/internal/SectionIdContext.ts","../src/internal/PageInfoContext.ts","../src/components/Page.tsx","../src/internal/SectionControllerContext.ts","../src/internal/useSectionControllerState.tsx","../src/internal/SectionLayout.tsx","../src/components/Section.tsx","../src/components/PageBreak.tsx","../src/components/Layout.tsx","../src/components/usePageInfo.ts","../src/components/useSectionInfo.ts","../src/internal/eventHelper.ts","../src/components/useReportInfo.ts","../src/components/useSectionSuspension.ts","../src/components/useJsonData.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { previewClassName } from '@paprize/core';\n\nexport function ReportPreview({ children }: { children: ReactNode }) {\n return <div className={previewClassName}>{children}</div>;\n}\n","import type { ReportBuilder } from '@paprize/core';\nimport { createContext, useContext } from 'react';\n\nexport const ReportBuilderContext = createContext<ReportBuilder | null>(null);\n\nexport function useReportBuilder() {\n const context = useContext(ReportBuilderContext);\n if (!context) {\n throw new Error(\n 'ReportRoot is missing. Please wrap your component tree with ReportRoot component.'\n );\n }\n\n return context;\n}\n","import { useEffect, useMemo, type ReactNode } from 'react';\nimport { ReportBuilder } from '@paprize/core';\nimport { ReportBuilderContext } from '../internal/useReportBuilder';\n\nexport interface ReportRootProps {\n children: ReactNode;\n}\n\nexport function ReportRoot({ children }: ReportRootProps) {\n const reportBuilder = useMemo(() => new ReportBuilder(), []);\n\n useEffect(() => {\n reportBuilder.schedulePagination();\n }, [reportBuilder]);\n\n return (\n <ReportBuilderContext value={reportBuilder}>\n {children}\n </ReportBuilderContext>\n );\n}\n","import { useEffect, useRef, type ReactNode } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\n\nexport function PageContent({ children }: { children: ReactNode }) {\n const reportBuilder = useReportBuilder();\n const isFirstCycleCompleted = useRef(false);\n\n useEffect(() => {\n const unsubscribe = reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n () => {\n isFirstCycleCompleted.current = true;\n }\n );\n\n return () => unsubscribe();\n }, [reportBuilder.monitor]);\n\n // If the children change after the first pagination cycle, we need to re-paginate\n // this can happen if the content is dynamic or loaded asynchronously\n // if we don't do this, the new content will be ignored in the pagination\n useEffect(() => {\n if (isFirstCycleCompleted.current) {\n reportBuilder.schedulePagination();\n }\n }, [children, reportBuilder]);\n\n return <>{children}</>;\n}\n","export function PageFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageHeader({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionHeader({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageOverlay({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","import {\n Children,\n isValidElement,\n type FC,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { PageContent } from '../components/PageContent';\nimport { PageFooter } from '../components/PageFooter';\nimport { PageHeader } from '../components/PageHeader';\nimport { SectionFooter } from '../components/SectionFooter';\nimport { SectionHeader } from '../components/SectionHeader';\nimport { PageOverlay } from '../components/PageOverlay';\n\nconst validChildren: FC<{ children: ReactNode }>[] = [\n PageContent,\n PageHeader,\n PageFooter,\n PageOverlay,\n SectionHeader,\n SectionFooter,\n];\n\nexport interface PageElements {\n content: ReactElement;\n header?: ReactElement;\n footer?: ReactElement;\n overlay?: ReactElement;\n sectionHeader?: ReactElement;\n sectionFooter?: ReactElement;\n}\n\nfunction parseSectionChildren(children: ReactNode): PageElements {\n let content: ReactElement | null = null;\n const pageElements: Partial<PageElements> = {};\n\n Children.forEach(children, (child) => {\n if (!isValidElement(child)) {\n throw new Error(\n `Invalid React element found in children: ${child}`,\n {\n cause: { child },\n }\n );\n }\n\n const component = validChildren.find((x) => x === child.type);\n if (!component) {\n throw Error(\n `Component \"${child.type}\" is not valid as a child for Section, Expected one of: ${validChildren\n .map((x) => x.name)\n .join(',')}`\n );\n }\n\n switch (component) {\n case SectionHeader:\n pageElements.sectionHeader = child;\n break;\n\n case SectionFooter:\n pageElements.sectionFooter = child;\n break;\n\n case PageContent:\n content = child;\n break;\n\n case PageHeader:\n pageElements.header = child;\n break;\n\n case PageFooter:\n pageElements.footer = child;\n break;\n\n case PageOverlay:\n pageElements.overlay = child;\n break;\n }\n });\n\n if (!content) {\n throw Error('PageContent component is a required child for Section');\n }\n\n return { ...pageElements, content: content };\n}\n\nexport default parseSectionChildren;\n","import { createContext } from 'react';\n\nexport const SectionIdContext = createContext<string>('');\n","import { createContext } from 'react';\n\nexport const PageInfoContext = createContext<{\n pageIndex: number;\n totalPages: number;\n}>({\n pageIndex: 0,\n totalPages: 0,\n});\n","import { useContext, useMemo, type Ref } from 'react';\nimport { type PageElements } from '../internal/parseSectionChildren';\nimport { PageInfoContext } from '../internal/PageInfoContext';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n pageClassName,\n pageMargin,\n reportStyles,\n type PageSize,\n type PageMargin,\n} from '@paprize/core';\n\nexport interface PageProps {\n elements: PageElements;\n size: PageSize;\n margin?: PageMargin;\n pageIndex: number;\n totalPages: number;\n ref?: Ref<HTMLDivElement>;\n sectionHeaderRef?: Ref<HTMLDivElement>;\n sectionFooterRef?: Ref<HTMLDivElement>;\n pageHeaderRef?: Ref<HTMLDivElement>;\n pageFooterRef?: Ref<HTMLDivElement>;\n contentRef?: Ref<HTMLDivElement>;\n}\n\nexport function Page({\n elements,\n size,\n margin,\n pageIndex,\n totalPages,\n ref,\n sectionHeaderRef,\n sectionFooterRef,\n pageHeaderRef,\n pageFooterRef,\n contentRef,\n}: PageProps) {\n const sectionId = useContext(SectionIdContext);\n const contextValue = useMemo(\n () => ({ pageIndex, totalPages }),\n [pageIndex, totalPages]\n );\n\n return (\n <PageInfoContext value={contextValue}>\n <div\n id={`${sectionId}-${pageIndex}`}\n className={pageClassName}\n ref={ref}\n style={reportStyles.page(size, margin ?? pageMargin.None)}\n >\n {elements.sectionHeader && pageIndex === 0 && (\n <div style={reportStyles.component} ref={sectionHeaderRef}>\n {elements.sectionHeader}\n </div>\n )}\n {elements.header && (\n <div style={reportStyles.component} ref={pageHeaderRef}>\n {elements.header}\n </div>\n )}\n\n <div style={reportStyles.pageContent} ref={contentRef}>\n {elements.content}\n </div>\n\n {elements.overlay && (\n <div style={reportStyles.overlay}>{elements.overlay}</div>\n )}\n\n {(elements.footer || elements.sectionFooter) && (\n <div\n style={{ ...reportStyles.component, marginTop: 'auto' }}\n >\n {elements.footer && (\n <div\n style={reportStyles.component}\n ref={pageFooterRef}\n >\n {elements.footer}\n </div>\n )}\n {elements.sectionFooter &&\n pageIndex === totalPages - 1 && (\n <div\n style={reportStyles.component}\n ref={sectionFooterRef}\n >\n {elements.sectionFooter}\n </div>\n )}\n </div>\n )}\n </div>\n </PageInfoContext>\n );\n}\n","import type { PaginationPlugin } from '@paprize/core';\nimport { createContext } from 'react';\n\nexport interface SectionController {\n addPlugin: (plugin: PaginationPlugin) => void;\n addSuspense: (suspense: Promise<void>) => void;\n}\n\nexport const SectionControllerContext = createContext<SectionController>({\n addPlugin: () => {\n throw new Error('addPlugin must be used within a Section');\n },\n addSuspense: () => {\n throw new Error('addSuspense must be used within a Section');\n },\n});\n","import { useMemo } from 'react';\nimport { type SectionController } from './SectionControllerContext';\nimport type { PaginationPlugin } from '@paprize/core';\n\nexport function useSectionControllerState(plugins?: PaginationPlugin[]) {\n const state = useMemo(\n () => ({\n plugins: plugins ?? ([] as PaginationPlugin[]),\n suspense: [] as Promise<void>[],\n }),\n [plugins]\n );\n\n const sectionController: SectionController = useMemo(\n () => ({\n addPlugin: (plugin: PaginationPlugin) => {\n state.plugins.push(plugin);\n },\n addSuspense: (suspense: Promise<void>) => {\n state.suspense.push(suspense);\n },\n }),\n [state]\n );\n\n return {\n controllerState: state,\n controllerValue: sectionController,\n };\n}\n","import {\n adjustPageSize,\n logger,\n reportStyles,\n type PageContext,\n type SectionOptions,\n} from '@paprize/core';\nimport { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { Page } from '../components/Page';\nimport { useReportBuilder } from './useReportBuilder';\nimport { SectionIdContext } from './SectionIdContext';\nimport type { PageElements } from './parseSectionChildren';\nimport { useSectionControllerState } from './useSectionControllerState';\nimport { SectionControllerContext } from './SectionControllerContext';\n\nexport interface SectionLayoutProps {\n elements: PageElements;\n options: SectionOptions;\n}\n\nexport function SectionLayout({ elements, options }: SectionLayoutProps) {\n const sectionId = useContext(SectionIdContext);\n const { controllerState, controllerValue } = useSectionControllerState(\n options?.plugins\n );\n const reportBuilder = useReportBuilder();\n const pageRef = useRef<HTMLDivElement>(null);\n const sectionHeaderRef = useRef<HTMLDivElement>(null);\n const sectionFooterRef = useRef<HTMLDivElement>(null);\n const pageHeaderRef = useRef<HTMLDivElement>(null);\n const pageFooterRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const realizedSize = useMemo(\n () => adjustPageSize(options.size, options.orientation),\n [options.orientation, options.size]\n );\n const [pageContexts, setPageContexts] = useState<PageContext[] | null>(\n null\n );\n\n useEffect(() => {\n if (!contentRef.current) {\n return;\n }\n\n reportBuilder\n .tryAddSection(\n {\n ...options,\n id: sectionId,\n plugins: controllerState.plugins,\n suspense: controllerState.suspense,\n },\n {\n pageContent: contentRef.current,\n sectionHeader: sectionHeaderRef.current,\n sectionFooter: sectionFooterRef.current,\n pageFooter: pageFooterRef.current,\n pageHeader: pageHeaderRef.current,\n },\n (pages) => {\n setPageContexts(pages);\n }\n )\n .catch((e) => logger.error(e));\n\n return () => {\n reportBuilder.removeSection(sectionId);\n };\n }, [\n controllerState.plugins,\n controllerState.suspense,\n options,\n reportBuilder,\n sectionId,\n ]);\n\n return (\n <SectionControllerContext value={controllerValue}>\n {pageContexts?.map((pageContext) => (\n <Page\n key={pageContext.pageIndex}\n elements={{\n ...elements,\n content: (\n <div\n style={{ display: 'contents' }}\n dangerouslySetInnerHTML={{\n __html: pageContext.pageContentHtml,\n }}\n />\n ),\n }}\n size={realizedSize}\n margin={options.margin}\n pageIndex={pageContext.pageIndex}\n totalPages={pageContext.totalPages}\n />\n ))}\n\n {createPortal(\n <div style={reportStyles.outOfScreen}>\n <Page\n elements={elements}\n size={realizedSize}\n margin={options.margin}\n pageIndex={0}\n totalPages={1}\n ref={pageRef}\n sectionHeaderRef={sectionHeaderRef}\n sectionFooterRef={sectionFooterRef}\n pageHeaderRef={pageHeaderRef}\n pageFooterRef={pageFooterRef}\n contentRef={contentRef}\n />\n </div>,\n document.body\n )}\n </SectionControllerContext>\n );\n}\n","import { useMemo, type ReactNode } from 'react';\nimport parseSectionChildren from '../internal/parseSectionChildren';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n reportStyles,\n sectionClassName,\n type SectionOptions,\n} from '@paprize/core';\nimport { SectionLayout } from '../internal/SectionLayout';\n\n/**\n * Configuration options for a section.\n * @inlineType SectionOptions\n */\nexport interface SectionProps extends Omit<SectionOptions, 'id' | 'suspense'> {\n children: ReactNode;\n /**\n * Unique id of the section within the report. If not set, a random id will be used.\n */\n id?: string;\n}\n\nlet sectionIdCounter = 1;\n\nexport function Section({ children, id, ...options }: SectionProps) {\n const sectionId = useMemo(() => id ?? `__000${sectionIdCounter++}`, [id]);\n const elements = useMemo(() => parseSectionChildren(children), [children]);\n const sectionOptions = useMemo(\n () => ({\n ...options,\n id: sectionId,\n }),\n [options, sectionId]\n );\n\n return (\n <section\n className={sectionClassName}\n id={sectionId}\n style={reportStyles.section(sectionId)}\n >\n <SectionIdContext value={sectionId}>\n <SectionLayout elements={elements} options={sectionOptions} />\n </SectionIdContext>\n </section>\n );\n}\n","import { pageBreakAttributeName } from '@paprize/core';\n\nexport function PageBreak() {\n return <span {...{ [pageBreakAttributeName]: 'true' }} />;\n}\n","import { layoutOptionsToAttributes, type LayoutOptions } from '@paprize/core';\n\nexport interface LayoutProps extends LayoutOptions {\n children: React.ReactNode;\n}\n\nexport function Layout({ children, ...attributes }: LayoutProps) {\n return (\n <div\n style={{ display: 'contents' }}\n {...layoutOptionsToAttributes(attributes)}\n >\n {children}\n </div>\n );\n}\n","import { useContext } from 'react';\nimport { PageInfoContext } from '../internal/PageInfoContext';\nimport type { PageInfo } from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the current page.\n */\nexport const usePageInfo = (): PageInfo => {\n const pageContext = useContext(PageInfoContext);\n\n return {\n pageIndex: pageContext.pageIndex,\n totalPages: pageContext.totalPages,\n };\n};\n","import { useContext, useRef, useSyncExternalStore } from 'react';\nimport type { SectionContext } from '@paprize/core';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport type { SectionInfo } from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the current section.\n */\nexport const useSectionInfo = (): SectionInfo => {\n const sectionId = useContext(SectionIdContext);\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<SectionContext>({\n pages: [],\n isPaginated: false,\n isSuspended: false,\n sectionIndex: -1,\n sectionId: sectionId,\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'sectionCompleted',\n (sc) => {\n if (sc.sectionId !== sectionId) return;\n stateRef.current = sc;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return {\n sectionId: sectionId,\n sectionIndex: state.sectionIndex,\n isSuspended: state.isSuspended,\n isPaginated: state.isPaginated,\n pages: state.pages.map((p) => ({\n pageIndex: p.pageIndex,\n totalPages: p.totalPages,\n })),\n };\n};\n","import type { PaginationCycleCompleted, SectionContext } from '@paprize/core';\n\n/**\n * {@inheritDoc @paprize/core!PageContext}\n */\nexport interface PageInfo {\n /**\n * {@inheritDoc @paprize/core!PageContext.pageIndex}\n */\n pageIndex: number;\n /**\n * {@inheritDoc @paprize/core!PageContext.totalPages}\n */\n totalPages: number;\n}\n\n/**\n * {@inheritDoc @paprize/core!SectionContext}\n */\nexport interface SectionInfo {\n /**\n * {@inheritDoc @paprize/core!SectionContext.sectionId}\n */\n sectionId: string;\n /**\n * {@inheritDoc @paprize/core!SectionContext.sectionIndex}\n */\n sectionIndex: number;\n /**\n * {@inheritDoc @paprize/core!SectionContext.isPaginated}\n */\n isPaginated: boolean;\n /**\n * {@inheritDoc @paprize/core!SectionContext.isSuspended}\n */\n isSuspended: boolean;\n /**\n * {@inheritDoc @paprize/core!SectionContext.pages}\n */\n pages: PageInfo[];\n}\n\n/**\n * {@inheritDoc @paprize/core!PaginationCycleCompleted}\n */\n\nexport interface ReportInfo {\n /**\n * {@inheritDoc @paprize/core!PaginationCycleCompleted.sections}\n */\n sections: SectionInfo[];\n}\n\nexport function pageContextToPageInfo(pc: {\n pageIndex: number;\n totalPages: number;\n}): PageInfo {\n return {\n pageIndex: pc.pageIndex,\n totalPages: pc.totalPages,\n };\n}\n\nexport function sectionContextToSectionInfo(sc: SectionContext): SectionInfo {\n return {\n sectionId: sc.sectionId,\n sectionIndex: sc.sectionIndex,\n isPaginated: sc.isPaginated,\n isSuspended: sc.isSuspended,\n pages: sc.pages.map(pageContextToPageInfo),\n };\n}\n\nexport function paginationCycleToReportInfo(\n rc: PaginationCycleCompleted\n): ReportInfo {\n return {\n sections: rc.sections.map(sectionContextToSectionInfo),\n };\n}\n","import { useRef, useSyncExternalStore } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport type { PaginationCycleCompleted } from '@paprize/core';\nimport {\n paginationCycleToReportInfo,\n type ReportInfo,\n} from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the report.\n */\nexport function useReportInfo(): ReportInfo {\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<PaginationCycleCompleted>({\n sections: [],\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n (pg) => {\n stateRef.current = pg;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return paginationCycleToReportInfo(state);\n}\n","import { useContext, useEffect, useMemo, useRef } from 'react';\nimport { SectionControllerContext } from '../internal/SectionControllerContext';\n\n/**\n * Controls the section suspension.\n * @inline\n */\nexport interface SectionSuspension {\n /**\n * Releases the suspension. The pagination engine will paginate this section immediately.\n */\n release: () => void;\n\n /**\n * Marks the suspension as pending again if it was previously resolved.\n * During the next pagination cycle (for example, if pagination is retriggered\n * by changes to the page content), this section will not be paginated\n * until `release` is called again.\n */\n reset: () => void;\n}\n\n/**\n * Suspends pagination for this section.\n * @param promise The suspension is tied to this promise. Once the promise is resolved,\n * the suspension is released and the pagination engine will paginate this section.\n */\nexport function useSectionSuspension(\n promise: Promise<void> | Promise<unknown>\n): void;\n/**\n * Suspends pagination for this section. You need to call the `release` method\n * of the returned value; otherwise, the pagination engine will never paginate this section.\n */\nexport function useSectionSuspension(): SectionSuspension;\nexport function useSectionSuspension(\n promise?: Promise<void> | Promise<unknown>\n) {\n const resolveFn = useRef<() => void | null>(null);\n const { addSuspense } = useContext(SectionControllerContext);\n\n useEffect(() => {\n if (resolveFn.current) {\n return;\n }\n\n const pr =\n promise ??\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n });\n resolveFn.current ||= () => {};\n\n addSuspense(pr as Promise<void>);\n }, [addSuspense, promise]);\n\n return useMemo(\n () => ({\n reset: () => {\n if (resolveFn.current) return;\n\n addSuspense(\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n })\n );\n },\n release: () => {\n resolveFn.current?.();\n resolveFn.current = null;\n },\n }),\n [addSuspense]\n );\n}\n","import { useSectionSuspension } from './useSectionSuspension';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport { useEffect, useMemo } from 'react';\n\n/**\n * {@inheritDoc @paprize/core!ReportBuilder.getJsonData}\n */\nexport function useJsonData<DataModel>(\n defaultValue?: DataModel\n): DataModel | null {\n const reportBuilder = useReportBuilder();\n const value = useMemo(\n () => ({\n current: null as DataModel | null,\n }),\n []\n );\n\n const promise = useMemo(\n () => reportBuilder.getJsonData(defaultValue),\n [defaultValue, reportBuilder]\n );\n\n useSectionSuspension(promise);\n\n useEffect(() => {\n promise.then((v) => (value.current = v));\n }, [promise, value]);\n\n return value.current ?? defaultValue ?? null;\n}\n"],"names":["ReportPreview","children","jsx","previewClassName","ReportBuilderContext","createContext","useReportBuilder","context","useContext","ReportRoot","reportBuilder","useMemo","ReportBuilder","useEffect","PageContent","isFirstCycleCompleted","useRef","unsubscribe","PageFooter","PageHeader","SectionFooter","SectionHeader","PageOverlay","validChildren","parseSectionChildren","content","pageElements","Children","child","isValidElement","component","x","SectionIdContext","PageInfoContext","Page","elements","size","margin","pageIndex","totalPages","ref","sectionHeaderRef","sectionFooterRef","pageHeaderRef","pageFooterRef","contentRef","sectionId","contextValue","jsxs","pageClassName","reportStyles","pageMargin","SectionControllerContext","useSectionControllerState","plugins","state","sectionController","plugin","suspense","SectionLayout","options","controllerState","controllerValue","pageRef","realizedSize","adjustPageSize","pageContexts","setPageContexts","useState","pages","e","logger","pageContext","createPortal","sectionIdCounter","Section","id","sectionOptions","sectionClassName","PageBreak","pageBreakAttributeName","Layout","attributes","layoutOptionsToAttributes","usePageInfo","useSectionInfo","stateRef","useSyncExternalStore","callback","sc","p","pageContextToPageInfo","pc","sectionContextToSectionInfo","paginationCycleToReportInfo","rc","useReportInfo","pg","useSectionS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AAC,GAElBxF;AAAA,IACH,OAAO;AAAA,MACH,OAAO,MAAM;AACT,QAAIyF,EAAU,WAEdC;AAAA,UACI,IAAI,QAAc,CAACE,MAAY;AAC3B,YAAAH,EAAU,UAAUG;AAAA,UACxB,CAAC;AAAA,QAAA;AAAA,MAET;AAAA,MACA,SAAS,MAAM;AACX,QAAAH,EAAU,UAAA,GACVA,EAAU,UAAU;AAAA,MACxB;AAAA,IAAA;AAAA,IAEJ,CAACC,CAAW;AAAA,EAAA;AAEpB;ACnEO,SAASG,GACZC,GACgB;AAChB,QAAM/F,IAAgBJ,EAAA,GAChBoG,IAAQ/F;AAAA,IACV,OAAO;AAAA,MACH,SAAS;AAAA,IAAA;AAAA,IAEb,CAAA;AAAA,EAAC,GAGCwF,IAAUxF;AAAA,IACZ,MAAMD,EAAc,YAAY+F,CAAY;AAAA,IAC5C,CAACA,GAAc/F,CAAa;AAAA,EAAA;AAGhC,SAAAwF,GAAqBC,CAAO,GAE5BtF,EAAU,MAAM;AACZ,IAAAsF,EAAQ,KAAK,CAACQ,MAAOD,EAAM,UAAUC,CAAE;AAAA,EAC3C,GAAG,CAACR,GAASO,CAAK,CAAC,GAEZA,EAAM,WAAWD,KAAgB;AAC5C;"}
1
+ {"version":3,"file":"paprize-react.js","sources":["../src/components/ReportPreview.tsx","../src/internal/useReportBuilder.ts","../src/components/ReportRoot.tsx","../src/components/PageContent.tsx","../src/components/PageFooter.tsx","../src/components/PageHeader.tsx","../src/components/SectionFooter.tsx","../src/components/SectionHeader.tsx","../src/components/PageOverlay.tsx","../src/internal/parseSectionChildren.ts","../src/internal/SectionIdContext.ts","../src/internal/PageInfoContext.ts","../src/components/Page.tsx","../src/internal/SectionControllerContext.ts","../src/internal/useSectionControllerState.tsx","../src/internal/SectionLayout.tsx","../src/components/Section.tsx","../src/components/PageBreak.tsx","../src/components/Layout.tsx","../src/components/usePageInfo.ts","../src/components/useSectionInfo.ts","../src/internal/eventHelper.ts","../src/components/useReportInfo.ts","../src/components/useSectionSuspension.ts","../src/components/useJsonData.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { previewClassName } from '@paprize/core';\n\nexport function ReportPreview({ children }: { children: ReactNode }) {\n return <div className={previewClassName}>{children}</div>;\n}\n","import type { ReportBuilder } from '@paprize/core';\nimport { createContext, useContext } from 'react';\n\nexport const ReportBuilderContext = createContext<ReportBuilder | null>(null);\n\nexport function useReportBuilder() {\n const context = useContext(ReportBuilderContext);\n if (!context) {\n throw new Error(\n 'ReportRoot is missing. Please wrap your component tree with ReportRoot component.'\n );\n }\n\n return context;\n}\n","import { useEffect, useMemo, type ReactNode } from 'react';\nimport { ReportBuilder } from '@paprize/core';\nimport { ReportBuilderContext } from '../internal/useReportBuilder';\n\nexport interface ReportRootProps {\n children: ReactNode;\n}\n\nexport function ReportRoot({ children }: ReportRootProps) {\n const reportBuilder = useMemo(() => new ReportBuilder(), []);\n\n useEffect(() => {\n reportBuilder.schedulePagination();\n }, [reportBuilder]);\n\n return (\n <ReportBuilderContext value={reportBuilder}>\n {children}\n </ReportBuilderContext>\n );\n}\n","import { useEffect, useRef, type ReactNode } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\n\nexport function PageContent({ children }: { children: ReactNode }) {\n const reportBuilder = useReportBuilder();\n const isFirstCycleCompleted = useRef(false);\n\n useEffect(() => {\n const unsubscribe = reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n () => {\n isFirstCycleCompleted.current = true;\n }\n );\n\n return () => unsubscribe();\n }, [reportBuilder.monitor]);\n\n // If the children change after the first pagination cycle, we need to re-paginate\n // this can happen if the content is dynamic or loaded asynchronously\n // if we don't do this, the new content will be ignored in the pagination\n useEffect(() => {\n if (isFirstCycleCompleted.current) {\n reportBuilder.schedulePagination();\n }\n }, [children, reportBuilder]);\n\n return <>{children}</>;\n}\n","export function PageFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageHeader({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionHeader({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageOverlay({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","import {\n Children,\n isValidElement,\n type FC,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { PageContent } from '../components/PageContent';\nimport { PageFooter } from '../components/PageFooter';\nimport { PageHeader } from '../components/PageHeader';\nimport { SectionFooter } from '../components/SectionFooter';\nimport { SectionHeader } from '../components/SectionHeader';\nimport { PageOverlay } from '../components/PageOverlay';\n\nconst validChildren: FC<{ children: ReactNode }>[] = [\n PageContent,\n PageHeader,\n PageFooter,\n PageOverlay,\n SectionHeader,\n SectionFooter,\n];\n\nexport interface PageElements {\n content: ReactElement;\n header?: ReactElement;\n footer?: ReactElement;\n overlay?: ReactElement;\n sectionHeader?: ReactElement;\n sectionFooter?: ReactElement;\n}\n\nfunction parseSectionChildren(children: ReactNode): PageElements {\n let content: ReactElement | null = null;\n const pageElements: Partial<PageElements> = {};\n\n Children.forEach(children, (child) => {\n if (!isValidElement(child)) {\n throw new Error(\n `Invalid React element found in children: ${child}`,\n {\n cause: { child },\n }\n );\n }\n\n const component = validChildren.find((x) => x === child.type);\n if (!component) {\n throw Error(\n `Component \"${child.type}\" is not valid as a child for Section, Expected one of: ${validChildren\n .map((x) => x.name)\n .join(',')}`\n );\n }\n\n switch (component) {\n case SectionHeader:\n pageElements.sectionHeader = child;\n break;\n\n case SectionFooter:\n pageElements.sectionFooter = child;\n break;\n\n case PageContent:\n content = child;\n break;\n\n case PageHeader:\n pageElements.header = child;\n break;\n\n case PageFooter:\n pageElements.footer = child;\n break;\n\n case PageOverlay:\n pageElements.overlay = child;\n break;\n }\n });\n\n if (!content) {\n throw Error('PageContent component is a required child for Section');\n }\n\n return { ...pageElements, content: content };\n}\n\nexport default parseSectionChildren;\n","import { createContext } from 'react';\n\nexport const SectionIdContext = createContext<string>('');\n","import { createContext } from 'react';\n\nexport const PageInfoContext = createContext<{\n pageIndex: number;\n totalPages: number;\n}>({\n pageIndex: 0,\n totalPages: 0,\n});\n","import { useContext, useMemo, type Ref } from 'react';\nimport { type PageElements } from '../internal/parseSectionChildren';\nimport { PageInfoContext } from '../internal/PageInfoContext';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n pageClassName,\n pageMargin,\n reportStyles,\n type PageSize,\n type PageMargin,\n} from '@paprize/core';\n\nexport interface PageProps {\n elements: PageElements;\n size: PageSize;\n margin?: PageMargin;\n pageIndex: number;\n totalPages: number;\n ref?: Ref<HTMLDivElement>;\n sectionHeaderRef?: Ref<HTMLDivElement>;\n sectionFooterRef?: Ref<HTMLDivElement>;\n pageHeaderRef?: Ref<HTMLDivElement>;\n pageFooterRef?: Ref<HTMLDivElement>;\n contentRef?: Ref<HTMLDivElement>;\n}\n\nexport function Page({\n elements,\n size,\n margin,\n pageIndex,\n totalPages,\n ref,\n sectionHeaderRef,\n sectionFooterRef,\n pageHeaderRef,\n pageFooterRef,\n contentRef,\n}: PageProps) {\n const sectionId = useContext(SectionIdContext);\n const contextValue = useMemo(\n () => ({ pageIndex, totalPages }),\n [pageIndex, totalPages]\n );\n\n return (\n <PageInfoContext value={contextValue}>\n <div\n id={`${sectionId}-${pageIndex}`}\n className={pageClassName}\n ref={ref}\n style={reportStyles.page(size, margin ?? pageMargin.None)}\n >\n {elements.sectionHeader && pageIndex === 0 && (\n <div style={reportStyles.component} ref={sectionHeaderRef}>\n {elements.sectionHeader}\n </div>\n )}\n {elements.header && (\n <div style={reportStyles.component} ref={pageHeaderRef}>\n {elements.header}\n </div>\n )}\n\n <div style={reportStyles.pageContent} ref={contentRef}>\n {elements.content}\n </div>\n\n {elements.overlay && (\n <div style={reportStyles.overlay}>{elements.overlay}</div>\n )}\n\n {(elements.footer || elements.sectionFooter) && (\n <div\n style={{ ...reportStyles.component, marginTop: 'auto' }}\n >\n {elements.footer && (\n <div\n style={reportStyles.component}\n ref={pageFooterRef}\n >\n {elements.footer}\n </div>\n )}\n {elements.sectionFooter &&\n pageIndex === totalPages - 1 && (\n <div\n style={reportStyles.component}\n ref={sectionFooterRef}\n >\n {elements.sectionFooter}\n </div>\n )}\n </div>\n )}\n </div>\n </PageInfoContext>\n );\n}\n","import type { PaginationPlugin } from '@paprize/core';\nimport { createContext } from 'react';\n\nexport interface SectionController {\n addPlugin: (plugin: PaginationPlugin) => void;\n addSuspense: (suspense: Promise<void>) => void;\n}\n\nexport const SectionControllerContext = createContext<SectionController>({\n addPlugin: () => {\n throw new Error('addPlugin must be used within a Section');\n },\n addSuspense: () => {\n throw new Error('addSuspense must be used within a Section');\n },\n});\n","import { useMemo } from 'react';\nimport { type SectionController } from './SectionControllerContext';\nimport type { PaginationPlugin } from '@paprize/core';\n\nexport function useSectionControllerState(plugins?: PaginationPlugin[]) {\n const state = useMemo(\n () => ({\n plugins: plugins ?? ([] as PaginationPlugin[]),\n suspense: [] as Promise<void>[],\n }),\n [plugins]\n );\n\n const sectionController: SectionController = useMemo(\n () => ({\n addPlugin: (plugin: PaginationPlugin) => {\n state.plugins.push(plugin);\n },\n addSuspense: (suspense: Promise<void>) => {\n state.suspense.push(suspense);\n },\n }),\n [state]\n );\n\n return {\n controllerState: state,\n controllerValue: sectionController,\n };\n}\n","import {\n adjustPageSize,\n logger,\n reportStyles,\n type PageContext,\n type SectionOptions,\n} from '@paprize/core';\nimport { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { Page } from '../components/Page';\nimport { useReportBuilder } from './useReportBuilder';\nimport { SectionIdContext } from './SectionIdContext';\nimport type { PageElements } from './parseSectionChildren';\nimport { useSectionControllerState } from './useSectionControllerState';\nimport { SectionControllerContext } from './SectionControllerContext';\n\nexport interface SectionLayoutProps {\n elements: PageElements;\n options: SectionOptions;\n}\n\nexport function SectionLayout({ elements, options }: SectionLayoutProps) {\n const sectionId = useContext(SectionIdContext);\n const { controllerState, controllerValue } = useSectionControllerState(\n options?.plugins\n );\n const reportBuilder = useReportBuilder();\n const pageRef = useRef<HTMLDivElement>(null);\n const sectionHeaderRef = useRef<HTMLDivElement>(null);\n const sectionFooterRef = useRef<HTMLDivElement>(null);\n const pageHeaderRef = useRef<HTMLDivElement>(null);\n const pageFooterRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const realizedSize = useMemo(\n () => adjustPageSize(options.size, options.orientation),\n [options.orientation, options.size]\n );\n const [pageContexts, setPageContexts] = useState<PageContext[] | null>(\n null\n );\n\n useEffect(() => {\n if (!contentRef.current) {\n return;\n }\n\n reportBuilder\n .tryAddSection(\n {\n ...options,\n id: sectionId,\n plugins: controllerState.plugins,\n suspense: controllerState.suspense,\n },\n {\n pageContent: contentRef.current,\n sectionHeader: sectionHeaderRef.current,\n sectionFooter: sectionFooterRef.current,\n pageFooter: pageFooterRef.current,\n pageHeader: pageHeaderRef.current,\n },\n (sectionCtx) => {\n setPageContexts(sectionCtx.pages);\n }\n )\n .catch((e) => logger.error(e));\n\n return () => {\n reportBuilder.removeSection(sectionId);\n };\n }, [\n controllerState.plugins,\n controllerState.suspense,\n options,\n reportBuilder,\n sectionId,\n ]);\n\n return (\n <SectionControllerContext value={controllerValue}>\n {pageContexts?.map((pageContext) => (\n <Page\n key={pageContext.pageIndex}\n elements={{\n ...elements,\n content: (\n <div\n style={{ display: 'contents' }}\n dangerouslySetInnerHTML={{\n __html: pageContext.pageContentHtml,\n }}\n />\n ),\n }}\n size={realizedSize}\n margin={options.margin}\n pageIndex={pageContext.pageIndex}\n totalPages={pageContext.totalPages}\n />\n ))}\n\n {createPortal(\n <div style={reportStyles.outOfScreen}>\n <Page\n elements={elements}\n size={realizedSize}\n margin={options.margin}\n pageIndex={0}\n totalPages={1}\n ref={pageRef}\n sectionHeaderRef={sectionHeaderRef}\n sectionFooterRef={sectionFooterRef}\n pageHeaderRef={pageHeaderRef}\n pageFooterRef={pageFooterRef}\n contentRef={contentRef}\n />\n </div>,\n document.body\n )}\n </SectionControllerContext>\n );\n}\n","import { useMemo, type ReactNode } from 'react';\nimport parseSectionChildren from '../internal/parseSectionChildren';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n reportStyles,\n sectionClassName,\n type SectionOptions,\n} from '@paprize/core';\nimport { SectionLayout } from '../internal/SectionLayout';\n\n/**\n * Configuration options for a section.\n * @inlineType SectionOptions\n */\nexport interface SectionProps extends Omit<SectionOptions, 'id' | 'suspense'> {\n children: ReactNode;\n /**\n * Unique id of the section within the report. If not set, a random id will be used.\n */\n id?: string;\n}\n\nlet sectionIdCounter = 1;\n\nexport function Section({ children, id, ...options }: SectionProps) {\n const sectionId = useMemo(() => id ?? `__000${sectionIdCounter++}`, [id]);\n const elements = useMemo(() => parseSectionChildren(children), [children]);\n const sectionOptions = useMemo(\n () => ({\n ...options,\n id: sectionId,\n }),\n [options, sectionId]\n );\n\n return (\n <section\n className={sectionClassName}\n id={sectionId}\n style={reportStyles.section(sectionId)}\n >\n <SectionIdContext value={sectionId}>\n <SectionLayout elements={elements} options={sectionOptions} />\n </SectionIdContext>\n </section>\n );\n}\n","import { pageBreakAttributeName } from '@paprize/core';\n\nexport function PageBreak() {\n return <span {...{ [pageBreakAttributeName]: 'true' }} />;\n}\n","import { layoutOptionsToAttributes, type LayoutOptions } from '@paprize/core';\n\nexport interface LayoutProps extends LayoutOptions {\n children: React.ReactNode;\n}\n\nexport function Layout({ children, ...attributes }: LayoutProps) {\n return (\n <div\n style={{ display: 'contents' }}\n {...layoutOptionsToAttributes(attributes)}\n >\n {children}\n </div>\n );\n}\n","import { useContext } from 'react';\nimport { PageInfoContext } from '../internal/PageInfoContext';\nimport type { PageInfo } from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the current page.\n */\nexport const usePageInfo = (): PageInfo => {\n const pageContext = useContext(PageInfoContext);\n\n return {\n pageIndex: pageContext.pageIndex,\n totalPages: pageContext.totalPages,\n };\n};\n","import { useContext, useRef, useSyncExternalStore } from 'react';\nimport type { SectionContext } from '@paprize/core';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport type { SectionInfo } from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the current section.\n */\nexport const useSectionInfo = (): SectionInfo => {\n const sectionId = useContext(SectionIdContext);\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<Omit<SectionContext, 'options' | 'components'>>({\n pages: [],\n isPaginated: false,\n isSuspended: false,\n sectionIndex: -1,\n sectionId: sectionId,\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'sectionCompleted',\n (sc) => {\n if (sc.sectionId !== sectionId) return;\n stateRef.current = sc;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return {\n sectionId: sectionId,\n sectionIndex: state.sectionIndex,\n isSuspended: state.isSuspended,\n isPaginated: state.isPaginated,\n pages: state.pages.map((p) => ({\n pageIndex: p.pageIndex,\n totalPages: p.totalPages,\n })),\n };\n};\n","import type { PaginationCycleCompleted, SectionContext } from '@paprize/core';\n\n/**\n * {@inheritDoc @paprize/core!PageContext}\n */\nexport interface PageInfo {\n /**\n * {@inheritDoc @paprize/core!PageContext.pageIndex}\n */\n pageIndex: number;\n /**\n * {@inheritDoc @paprize/core!PageContext.totalPages}\n */\n totalPages: number;\n}\n\n/**\n * {@inheritDoc @paprize/core!SectionContext}\n */\nexport interface SectionInfo {\n /**\n * {@inheritDoc @paprize/core!SectionContext.sectionId}\n */\n sectionId: string;\n /**\n * {@inheritDoc @paprize/core!SectionContext.sectionIndex}\n */\n sectionIndex: number;\n /**\n * {@inheritDoc @paprize/core!SectionContext.isPaginated}\n */\n isPaginated: boolean;\n /**\n * {@inheritDoc @paprize/core!SectionContext.isSuspended}\n */\n isSuspended: boolean;\n /**\n * {@inheritDoc @paprize/core!SectionContext.pages}\n */\n pages: PageInfo[];\n}\n\n/**\n * {@inheritDoc @paprize/core!PaginationCycleCompleted}\n */\n\nexport interface ReportInfo {\n /**\n * {@inheritDoc @paprize/core!PaginationCycleCompleted.sections}\n */\n sections: SectionInfo[];\n}\n\nexport function pageContextToPageInfo(pc: {\n pageIndex: number;\n totalPages: number;\n}): PageInfo {\n return {\n pageIndex: pc.pageIndex,\n totalPages: pc.totalPages,\n };\n}\n\nexport function sectionContextToSectionInfo(sc: SectionContext): SectionInfo {\n return {\n sectionId: sc.sectionId,\n sectionIndex: sc.sectionIndex,\n isPaginated: sc.isPaginated,\n isSuspended: sc.isSuspended,\n pages: sc.pages.map(pageContextToPageInfo),\n };\n}\n\nexport function paginationCycleToReportInfo(\n rc: PaginationCycleCompleted\n): ReportInfo {\n return {\n sections: rc.sections.map(sectionContextToSectionInfo),\n };\n}\n","import { useRef, useSyncExternalStore } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport type { PaginationCycleCompleted } from '@paprize/core';\nimport {\n paginationCycleToReportInfo,\n type ReportInfo,\n} from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the report.\n */\nexport function useReportInfo(): ReportInfo {\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<PaginationCycleCompleted>({\n sections: [],\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n (pg) => {\n stateRef.current = pg;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return paginationCycleToReportInfo(state);\n}\n","import { useContext, useEffect, useMemo, useRef } from 'react';\nimport { SectionControllerContext } from '../internal/SectionControllerContext';\n\n/**\n * Controls the section suspension.\n * @inline\n */\nexport interface SectionSuspension {\n /**\n * Releases the suspension. The pagination engine will paginate this section immediately.\n */\n release: () => void;\n\n /**\n * Marks the suspension as pending again if it was previously resolved.\n * During the next pagination cycle (for example, if pagination is retriggered\n * by changes to the page content), this section will not be paginated\n * until `release` is called again.\n */\n reset: () => void;\n}\n\n/**\n * Suspends pagination for this section.\n * @param promise The suspension is tied to this promise. Once the promise is resolved,\n * the suspension is released and the pagination engine will paginate this section.\n */\nexport function useSectionSuspension(\n promise: Promise<void> | Promise<unknown>\n): void;\n/**\n * Suspends pagination for this section. You need to call the `release` method\n * of the returned value; otherwise, the pagination engine will never paginate this section.\n */\nexport function useSectionSuspension(): SectionSuspension;\nexport function useSectionSuspension(\n promise?: Promise<void> | Promise<unknown>\n) {\n const resolveFn = useRef<() => void | null>(null);\n const { addSuspense } = useContext(SectionControllerContext);\n\n useEffect(() => {\n if (resolveFn.current) {\n return;\n }\n\n const pr =\n promise ??\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n });\n resolveFn.current ||= () => {};\n\n addSuspense(pr as Promise<void>);\n }, [addSuspense, promise]);\n\n return useMemo(\n () => ({\n reset: () => {\n if (resolveFn.current) return;\n\n addSuspense(\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n })\n );\n },\n release: () => {\n resolveFn.current?.();\n resolveFn.current = null;\n },\n }),\n [addSuspense]\n );\n}\n","import { useSectionSuspension } from './useSectionSuspension';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport { useEffect, useMemo } from 'react';\n\n/**\n * {@inheritDoc @paprize/core!ReportBuilder.getJsonData}\n */\nexport function useJsonData<DataModel>(\n defaultValue?: DataModel\n): DataModel | null {\n const reportBuilder = useReportBuilder();\n const value = useMemo(\n () => ({\n current: null as DataModel | null,\n }),\n []\n );\n\n const promise = useMemo(\n () => reportBuilder.getJsonData(defaultValue),\n [defaultValue, reportBuilder]\n );\n\n useSectionSuspension(promise);\n\n useEffect(() => {\n promise.then((v) => (value.current = v));\n }, [promise, value]);\n\n return value.current ?? defaultValue ?? null;\n}\n"],"names":["ReportPreview","children","jsx","previewClassName","ReportBuilderContext","createContext","useReportBuilder","context","useContext","ReportRoot","reportBuilder","useMemo","ReportBuilder","useEffect","PageContent","isFirstCycleCompleted","useRef","unsubscribe","PageFooter","PageHeader","SectionFooter","SectionHeader","PageOverlay","validChildren","parseSectionChildren","content","pageElements","Children","child","isValidElement","component","x","SectionIdContext","PageInfoContext","Page","elements","size","margin","pageIndex","totalPages","ref","sectionHeaderRef","sectionFooterRef","pageHeaderRef","pageFooterRef","contentRef","sectionId","contextValue","jsxs","pageClassName","reportStyles","pageMargin","SectionControllerContext","useSectionControllerState","plugins","state","sectionController","plugin","suspense","SectionLayout","options","controllerState","controllerValue","pageRef","realizedSize","adjustPageSize","pageContexts","setPageContexts","useState","sectionCtx","e","logger","pageContext","createPortal","sectionIdCounter","Section","id","sectionOptions","sectionClassName","PageBreak","pageBreakAttributeName","Layout","attributes","layoutOptionsToAttributes","usePageInfo","useSectionInfo","stateRef","useSyncExternalStore","callback","sc","p","pageContextToPageInfo","pc","sectionContextToSectionInfo","paginationCycleToReportInfo","rc","useReportInfo","pg","useSectionSuspension","promise","resolveFn","addSuspense","pr","resolve","useJsonData","defaultValue","value","v"],"mappings":";;;;AAGO,SAASA,GAAc,EAAE,UAAAC,KAAqC;AACjE,SAAO,gBAAAC,EAAC,OAAA,EAAI,WAAWC,GAAmB,UAAAF,EAAA,CAAS;AACvD;ACFO,MAAMG,IAAuBC,EAAoC,IAAI;AAErE,SAASC,IAAmB;AAC/B,QAAMC,IAAUC,EAAWJ,CAAoB;AAC/C,MAAI,CAACG;AACD,UAAM,IAAI;AAAA,MACN;AAAA,IAAA;AAIR,SAAOA;AACX;ACNO,SAASE,GAAW,EAAE,UAAAR,KAA6B;AACtD,QAAMS,IAAgBC,EAAQ,MAAM,IAAIC,EAAA,GAAiB,CAAA,CAAE;AAE3D,SAAAC,EAAU,MAAM;AACZ,IAAAH,EAAc,mBAAA;AAAA,EAClB,GAAG,CAACA,CAAa,CAAC,GAGd,gBAAAR,EAACE,GAAA,EAAqB,OAAOM,GACxB,UAAAT,EAAA,CACL;AAER;ACjBO,SAASa,EAAY,EAAE,UAAAb,KAAqC;AAC/D,QAAMS,IAAgBJ,EAAA,GAChBS,IAAwBC,EAAO,EAAK;AAE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GAASO,CAAK,CAAC,GAEZA,EAAM,WAAWD,KAAgB;AAC5C;"}
@@ -1,2 +1,2 @@
1
- (function(i,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react/jsx-runtime"),require("@paprize/core"),require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@paprize/core","react","react-dom"],r):(i=typeof globalThis<"u"?globalThis:i||self,r(i["paprize-react"]={},i.jsxRuntime,i.PaprizeCore,i.React,i.ReactDOM))})(this,(function(i,r,a,o,k){"use strict";function T({children:e}){return r.jsx("div",{className:a.previewClassName,children:e})}const x=o.createContext(null);function l(){const e=o.useContext(x);if(!e)throw new Error("ReportRoot is missing. Please wrap your component tree with ReportRoot component.");return e}function N({children:e}){const n=o.useMemo(()=>new a.ReportBuilder,[]);return o.useEffect(()=>{n.schedulePagination()},[n]),r.jsx(x,{value:n,children:e})}function v({children:e}){const n=l(),s=o.useRef(!1);return o.useEffect(()=>{const t=n.monitor.addEventListener("paginationCycleCompleted",()=>{s.current=!0});return()=>t()},[n.monitor]),o.useEffect(()=>{s.current&&n.schedulePagination()},[e,n]),r.jsx(r.Fragment,{children:e})}function I({children:e}){return r.jsx(r.Fragment,{children:e})}function h({children:e}){return r.jsx(r.Fragment,{children:e})}function m({children:e}){return r.jsx(r.Fragment,{children:e})}function w({children:e}){return r.jsx(r.Fragment,{children:e})}function E({children:e}){return r.jsx(r.Fragment,{children:e})}const M=[v,h,I,E,w,m];function L(e){let n=null;const s={};if(o.Children.forEach(e,t=>{if(!o.isValidElement(t))throw new Error(`Invalid React element found in children: ${t}`,{cause:{child:t}});const u=M.find(c=>c===t.type);if(!u)throw Error(`Component "${t.type}" is not valid as a child for Section, Expected one of: ${M.map(c=>c.name).join(",")}`);switch(u){case w:s.sectionHeader=t;break;case m:s.sectionFooter=t;break;case v:n=t;break;case h:s.header=t;break;case I:s.footer=t;break;case E:s.overlay=t;break}}),!n)throw Error("PageContent component is a required child for Section");return{...s,content:n}}const p=o.createContext(""),H=o.createContext({pageIndex:0,totalPages:0});function b({elements:e,size:n,margin:s,pageIndex:t,totalPages:u,ref:c,sectionHeaderRef:F,sectionFooterRef:g,pageHeaderRef:S,pageFooterRef:y,contentRef:P}){const f=o.useContext(p),C=o.useMemo(()=>({pageIndex:t,totalPages:u}),[t,u]);return r.jsx(H,{value:C,children:r.jsxs("div",{id:`${f}-${t}`,className:a.pageClassName,ref:c,style:a.reportStyles.page(n,s??a.pageMargin.None),children:[e.sectionHeader&&t===0&&r.jsx("div",{style:a.reportStyles.component,ref:F,children:e.sectionHeader}),e.header&&r.jsx("div",{style:a.reportStyles.component,ref:S,children:e.header}),r.jsx("div",{style:a.reportStyles.pageContent,ref:P,children:e.content}),e.overlay&&r.jsx("div",{style:a.reportStyles.overlay,children:e.overlay}),(e.footer||e.sectionFooter)&&r.jsxs("div",{style:{...a.reportStyles.component,marginTop:"auto"},children:[e.footer&&r.jsx("div",{style:a.reportStyles.component,ref:y,children:e.footer}),e.sectionFooter&&t===u-1&&r.jsx("div",{style:a.reportStyles.component,ref:g,children:e.sectionFooter})]})]})})}const B=o.createContext({addPlugin:()=>{throw new Error("addPlugin must be used within a Section")},addSuspense:()=>{throw new Error("addSuspense must be used within a Section")}});function O(e){const n=o.useMemo(()=>({plugins:e??[],suspense:[]}),[e]),s=o.useMemo(()=>({addPlugin:t=>{n.plugins.push(t)},addSuspense:t=>{n.suspense.push(t)}}),[n]);return{controllerState:n,controllerValue:s}}function R({elements:e,options:n}){const s=o.useContext(p),{controllerState:t,controllerValue:u}=O(n?.plugins),c=l(),F=o.useRef(null),g=o.useRef(null),S=o.useRef(null),y=o.useRef(null),P=o.useRef(null),f=o.useRef(null),C=o.useMemo(()=>a.adjustPageSize(n.size,n.orientation),[n.orientation,n.size]),[U,W]=o.useState(null);return o.useEffect(()=>{if(f.current)return c.tryAddSection({...n,id:s,plugins:t.plugins,suspense:t.suspense},{pageContent:f.current,sectionHeader:g.current,sectionFooter:S.current,pageFooter:P.current,pageHeader:y.current},d=>{W(d)}).catch(d=>a.logger.error(d)),()=>{c.removeSection(s)}},[t.plugins,t.suspense,n,c,s]),r.jsxs(B,{value:u,children:[U?.map(d=>r.jsx(b,{elements:{...e,content:r.jsx("div",{style:{display:"contents"},dangerouslySetInnerHTML:{__html:d.pageContentHtml}})},size:C,margin:n.margin,pageIndex:d.pageIndex,totalPages:d.totalPages},d.pageIndex)),k.createPortal(r.jsx("div",{style:a.reportStyles.outOfScreen,children:r.jsx(b,{elements:e,size:C,margin:n.margin,pageIndex:0,totalPages:1,ref:F,sectionHeaderRef:g,sectionFooterRef:S,pageHeaderRef:y,pageFooterRef:P,contentRef:f})}),document.body)]})}let $=1;function q({children:e,id:n,...s}){const t=o.useMemo(()=>n??`__000${$++}`,[n]),u=o.useMemo(()=>L(e),[e]),c=o.useMemo(()=>({...s,id:t}),[s,t]);return r.jsx("section",{className:a.sectionClassName,id:t,style:a.reportStyles.section(t),children:r.jsx(p,{value:t,children:r.jsx(R,{elements:u,options:c})})})}function D(){return r.jsx("span",{[a.pageBreakAttributeName]:"true"})}function _({children:e,...n}){return r.jsx("div",{style:{display:"contents"},...a.layoutOptionsToAttributes(n),children:e})}const A=()=>{const e=o.useContext(H);return{pageIndex:e.pageIndex,totalPages:e.totalPages}},J=()=>{const e=o.useContext(p),n=l(),s=o.useRef({pages:[],isPaginated:!1,isSuspended:!1,sectionIndex:-1,sectionId:e}),t=o.useSyncExternalStore(u=>n.monitor.addEventListener("sectionCompleted",c=>{c.sectionId===e&&(s.current=c,u())}),()=>s.current);return{sectionId:e,sectionIndex:t.sectionIndex,isSuspended:t.isSuspended,isPaginated:t.isPaginated,pages:t.pages.map(u=>({pageIndex:u.pageIndex,totalPages:u.totalPages}))}};function j(e){return{pageIndex:e.pageIndex,totalPages:e.totalPages}}function V(e){return{sectionId:e.sectionId,sectionIndex:e.sectionIndex,isPaginated:e.isPaginated,isSuspended:e.isSuspended,pages:e.pages.map(j)}}function G(e){return{sections:e.sections.map(V)}}function K(){const e=l(),n=o.useRef({sections:[]}),s=o.useSyncExternalStore(t=>e.monitor.addEventListener("paginationCycleCompleted",u=>{n.current=u,t()}),()=>n.current);return G(s)}function z(e){const n=o.useRef(null),{addSuspense:s}=o.useContext(B);return o.useEffect(()=>{if(n.current)return;const t=e??new Promise(u=>{n.current=u});n.current||=()=>{},s(t)},[s,e]),o.useMemo(()=>({reset:()=>{n.current||s(new Promise(t=>{n.current=t}))},release:()=>{n.current?.(),n.current=null}}),[s])}function Q(e){const n=l(),s=o.useMemo(()=>({current:null}),[]),t=o.useMemo(()=>n.getJsonData(e),[e,n]);return z(t),o.useEffect(()=>{t.then(u=>s.current=u)},[t,s]),s.current??e??null}i.Layout=_,i.PageBreak=D,i.PageContent=v,i.PageFooter=I,i.PageHeader=h,i.PageOverlay=E,i.ReportPreview=T,i.ReportRoot=N,i.Section=q,i.SectionFooter=m,i.SectionHeader=w,i.useJsonData=Q,i.usePageInfo=A,i.useReportInfo=K,i.useSectionInfo=J,i.useSectionSuspension=z,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(i,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react/jsx-runtime"),require("@paprize/core"),require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@paprize/core","react","react-dom"],r):(i=typeof globalThis<"u"?globalThis:i||self,r(i["paprize-react"]={},i.jsxRuntime,i.PaprizeCore,i.React,i.ReactDOM))})(this,(function(i,r,a,o,k){"use strict";function T({children:e}){return r.jsx("div",{className:a.previewClassName,children:e})}const x=o.createContext(null);function l(){const e=o.useContext(x);if(!e)throw new Error("ReportRoot is missing. Please wrap your component tree with ReportRoot component.");return e}function N({children:e}){const n=o.useMemo(()=>new a.ReportBuilder,[]);return o.useEffect(()=>{n.schedulePagination()},[n]),r.jsx(x,{value:n,children:e})}function v({children:e}){const n=l(),s=o.useRef(!1);return o.useEffect(()=>{const t=n.monitor.addEventListener("paginationCycleCompleted",()=>{s.current=!0});return()=>t()},[n.monitor]),o.useEffect(()=>{s.current&&n.schedulePagination()},[e,n]),r.jsx(r.Fragment,{children:e})}function I({children:e}){return r.jsx(r.Fragment,{children:e})}function h({children:e}){return r.jsx(r.Fragment,{children:e})}function m({children:e}){return r.jsx(r.Fragment,{children:e})}function w({children:e}){return r.jsx(r.Fragment,{children:e})}function E({children:e}){return r.jsx(r.Fragment,{children:e})}const M=[v,h,I,E,w,m];function L(e){let n=null;const s={};if(o.Children.forEach(e,t=>{if(!o.isValidElement(t))throw new Error(`Invalid React element found in children: ${t}`,{cause:{child:t}});const u=M.find(c=>c===t.type);if(!u)throw Error(`Component "${t.type}" is not valid as a child for Section, Expected one of: ${M.map(c=>c.name).join(",")}`);switch(u){case w:s.sectionHeader=t;break;case m:s.sectionFooter=t;break;case v:n=t;break;case h:s.header=t;break;case I:s.footer=t;break;case E:s.overlay=t;break}}),!n)throw Error("PageContent component is a required child for Section");return{...s,content:n}}const p=o.createContext(""),H=o.createContext({pageIndex:0,totalPages:0});function b({elements:e,size:n,margin:s,pageIndex:t,totalPages:u,ref:c,sectionHeaderRef:F,sectionFooterRef:g,pageHeaderRef:S,pageFooterRef:y,contentRef:P}){const f=o.useContext(p),C=o.useMemo(()=>({pageIndex:t,totalPages:u}),[t,u]);return r.jsx(H,{value:C,children:r.jsxs("div",{id:`${f}-${t}`,className:a.pageClassName,ref:c,style:a.reportStyles.page(n,s??a.pageMargin.None),children:[e.sectionHeader&&t===0&&r.jsx("div",{style:a.reportStyles.component,ref:F,children:e.sectionHeader}),e.header&&r.jsx("div",{style:a.reportStyles.component,ref:S,children:e.header}),r.jsx("div",{style:a.reportStyles.pageContent,ref:P,children:e.content}),e.overlay&&r.jsx("div",{style:a.reportStyles.overlay,children:e.overlay}),(e.footer||e.sectionFooter)&&r.jsxs("div",{style:{...a.reportStyles.component,marginTop:"auto"},children:[e.footer&&r.jsx("div",{style:a.reportStyles.component,ref:y,children:e.footer}),e.sectionFooter&&t===u-1&&r.jsx("div",{style:a.reportStyles.component,ref:g,children:e.sectionFooter})]})]})})}const B=o.createContext({addPlugin:()=>{throw new Error("addPlugin must be used within a Section")},addSuspense:()=>{throw new Error("addSuspense must be used within a Section")}});function O(e){const n=o.useMemo(()=>({plugins:e??[],suspense:[]}),[e]),s=o.useMemo(()=>({addPlugin:t=>{n.plugins.push(t)},addSuspense:t=>{n.suspense.push(t)}}),[n]);return{controllerState:n,controllerValue:s}}function R({elements:e,options:n}){const s=o.useContext(p),{controllerState:t,controllerValue:u}=O(n?.plugins),c=l(),F=o.useRef(null),g=o.useRef(null),S=o.useRef(null),y=o.useRef(null),P=o.useRef(null),f=o.useRef(null),C=o.useMemo(()=>a.adjustPageSize(n.size,n.orientation),[n.orientation,n.size]),[U,W]=o.useState(null);return o.useEffect(()=>{if(f.current)return c.tryAddSection({...n,id:s,plugins:t.plugins,suspense:t.suspense},{pageContent:f.current,sectionHeader:g.current,sectionFooter:S.current,pageFooter:P.current,pageHeader:y.current},d=>{W(d.pages)}).catch(d=>a.logger.error(d)),()=>{c.removeSection(s)}},[t.plugins,t.suspense,n,c,s]),r.jsxs(B,{value:u,children:[U?.map(d=>r.jsx(b,{elements:{...e,content:r.jsx("div",{style:{display:"contents"},dangerouslySetInnerHTML:{__html:d.pageContentHtml}})},size:C,margin:n.margin,pageIndex:d.pageIndex,totalPages:d.totalPages},d.pageIndex)),k.createPortal(r.jsx("div",{style:a.reportStyles.outOfScreen,children:r.jsx(b,{elements:e,size:C,margin:n.margin,pageIndex:0,totalPages:1,ref:F,sectionHeaderRef:g,sectionFooterRef:S,pageHeaderRef:y,pageFooterRef:P,contentRef:f})}),document.body)]})}let $=1;function q({children:e,id:n,...s}){const t=o.useMemo(()=>n??`__000${$++}`,[n]),u=o.useMemo(()=>L(e),[e]),c=o.useMemo(()=>({...s,id:t}),[s,t]);return r.jsx("section",{className:a.sectionClassName,id:t,style:a.reportStyles.section(t),children:r.jsx(p,{value:t,children:r.jsx(R,{elements:u,options:c})})})}function D(){return r.jsx("span",{[a.pageBreakAttributeName]:"true"})}function _({children:e,...n}){return r.jsx("div",{style:{display:"contents"},...a.layoutOptionsToAttributes(n),children:e})}const A=()=>{const e=o.useContext(H);return{pageIndex:e.pageIndex,totalPages:e.totalPages}},J=()=>{const e=o.useContext(p),n=l(),s=o.useRef({pages:[],isPaginated:!1,isSuspended:!1,sectionIndex:-1,sectionId:e}),t=o.useSyncExternalStore(u=>n.monitor.addEventListener("sectionCompleted",c=>{c.sectionId===e&&(s.current=c,u())}),()=>s.current);return{sectionId:e,sectionIndex:t.sectionIndex,isSuspended:t.isSuspended,isPaginated:t.isPaginated,pages:t.pages.map(u=>({pageIndex:u.pageIndex,totalPages:u.totalPages}))}};function j(e){return{pageIndex:e.pageIndex,totalPages:e.totalPages}}function V(e){return{sectionId:e.sectionId,sectionIndex:e.sectionIndex,isPaginated:e.isPaginated,isSuspended:e.isSuspended,pages:e.pages.map(j)}}function G(e){return{sections:e.sections.map(V)}}function K(){const e=l(),n=o.useRef({sections:[]}),s=o.useSyncExternalStore(t=>e.monitor.addEventListener("paginationCycleCompleted",u=>{n.current=u,t()}),()=>n.current);return G(s)}function z(e){const n=o.useRef(null),{addSuspense:s}=o.useContext(B);return o.useEffect(()=>{if(n.current)return;const t=e??new Promise(u=>{n.current=u});n.current||=()=>{},s(t)},[s,e]),o.useMemo(()=>({reset:()=>{n.current||s(new Promise(t=>{n.current=t}))},release:()=>{n.current?.(),n.current=null}}),[s])}function Q(e){const n=l(),s=o.useMemo(()=>({current:null}),[]),t=o.useMemo(()=>n.getJsonData(e),[e,n]);return z(t),o.useEffect(()=>{t.then(u=>s.current=u)},[t,s]),s.current??e??null}i.Layout=_,i.PageBreak=D,i.PageContent=v,i.PageFooter=I,i.PageHeader=h,i.PageOverlay=E,i.ReportPreview=T,i.ReportRoot=N,i.Section=q,i.SectionFooter=m,i.SectionHeader=w,i.useJsonData=Q,i.usePageInfo=A,i.useReportInfo=K,i.useSectionInfo=J,i.useSectionSuspension=z,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
2
2
  //# sourceMappingURL=paprize-react.umd.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"paprize-react.umd.cjs","sources":["../src/components/ReportPreview.tsx","../src/internal/useReportBuilder.ts","../src/components/ReportRoot.tsx","../src/components/PageContent.tsx","../src/components/PageFooter.tsx","../src/components/PageHeader.tsx","../src/components/SectionFooter.tsx","../src/components/SectionHeader.tsx","../src/components/PageOverlay.tsx","../src/internal/parseSectionChildren.ts","../src/internal/SectionIdContext.ts","../src/internal/PageInfoContext.ts","../src/components/Page.tsx","../src/internal/SectionControllerContext.ts","../src/internal/useSectionControllerState.tsx","../src/internal/SectionLayout.tsx","../src/components/Section.tsx","../src/components/PageBreak.tsx","../src/components/Layout.tsx","../src/components/usePageInfo.ts","../src/components/useSectionInfo.ts","../src/internal/eventHelper.ts","../src/components/useReportInfo.ts","../src/components/useSectionSuspension.ts","../src/components/useJsonData.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { previewClassName } from '@paprize/core';\n\nexport function ReportPreview({ children }: { children: ReactNode }) {\n return <div className={previewClassName}>{children}</div>;\n}\n","import type { ReportBuilder } from '@paprize/core';\nimport { createContext, useContext } from 'react';\n\nexport const ReportBuilderContext = createContext<ReportBuilder | null>(null);\n\nexport function useReportBuilder() {\n const context = useContext(ReportBuilderContext);\n if (!context) {\n throw new Error(\n 'ReportRoot is missing. Please wrap your component tree with ReportRoot component.'\n );\n }\n\n return context;\n}\n","import { useEffect, useMemo, type ReactNode } from 'react';\nimport { ReportBuilder } from '@paprize/core';\nimport { ReportBuilderContext } from '../internal/useReportBuilder';\n\nexport interface ReportRootProps {\n children: ReactNode;\n}\n\nexport function ReportRoot({ children }: ReportRootProps) {\n const reportBuilder = useMemo(() => new ReportBuilder(), []);\n\n useEffect(() => {\n reportBuilder.schedulePagination();\n }, [reportBuilder]);\n\n return (\n <ReportBuilderContext value={reportBuilder}>\n {children}\n </ReportBuilderContext>\n );\n}\n","import { useEffect, useRef, type ReactNode } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\n\nexport function PageContent({ children }: { children: ReactNode }) {\n const reportBuilder = useReportBuilder();\n const isFirstCycleCompleted = useRef(false);\n\n useEffect(() => {\n const unsubscribe = reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n () => {\n isFirstCycleCompleted.current = true;\n }\n );\n\n return () => unsubscribe();\n }, [reportBuilder.monitor]);\n\n // If the children change after the first pagination cycle, we need to re-paginate\n // this can happen if the content is dynamic or loaded asynchronously\n // if we don't do this, the new content will be ignored in the pagination\n useEffect(() => {\n if (isFirstCycleCompleted.current) {\n reportBuilder.schedulePagination();\n }\n }, [children, reportBuilder]);\n\n return <>{children}</>;\n}\n","export function PageFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageHeader({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionHeader({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageOverlay({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","import {\n Children,\n isValidElement,\n type FC,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { PageContent } from '../components/PageContent';\nimport { PageFooter } from '../components/PageFooter';\nimport { PageHeader } from '../components/PageHeader';\nimport { SectionFooter } from '../components/SectionFooter';\nimport { SectionHeader } from '../components/SectionHeader';\nimport { PageOverlay } from '../components/PageOverlay';\n\nconst validChildren: FC<{ children: ReactNode }>[] = [\n PageContent,\n PageHeader,\n PageFooter,\n PageOverlay,\n SectionHeader,\n SectionFooter,\n];\n\nexport interface PageElements {\n content: ReactElement;\n header?: ReactElement;\n footer?: ReactElement;\n overlay?: ReactElement;\n sectionHeader?: ReactElement;\n sectionFooter?: ReactElement;\n}\n\nfunction parseSectionChildren(children: ReactNode): PageElements {\n let content: ReactElement | null = null;\n const pageElements: Partial<PageElements> = {};\n\n Children.forEach(children, (child) => {\n if (!isValidElement(child)) {\n throw new Error(\n `Invalid React element found in children: ${child}`,\n {\n cause: { child },\n }\n );\n }\n\n const component = validChildren.find((x) => x === child.type);\n if (!component) {\n throw Error(\n `Component \"${child.type}\" is not valid as a child for Section, Expected one of: ${validChildren\n .map((x) => x.name)\n .join(',')}`\n );\n }\n\n switch (component) {\n case SectionHeader:\n pageElements.sectionHeader = child;\n break;\n\n case SectionFooter:\n pageElements.sectionFooter = child;\n break;\n\n case PageContent:\n content = child;\n break;\n\n case PageHeader:\n pageElements.header = child;\n break;\n\n case PageFooter:\n pageElements.footer = child;\n break;\n\n case PageOverlay:\n pageElements.overlay = child;\n break;\n }\n });\n\n if (!content) {\n throw Error('PageContent component is a required child for Section');\n }\n\n return { ...pageElements, content: content };\n}\n\nexport default parseSectionChildren;\n","import { createContext } from 'react';\n\nexport const SectionIdContext = createContext<string>('');\n","import { createContext } from 'react';\n\nexport const PageInfoContext = createContext<{\n pageIndex: number;\n totalPages: number;\n}>({\n pageIndex: 0,\n totalPages: 0,\n});\n","import { useContext, useMemo, type Ref } from 'react';\nimport { type PageElements } from '../internal/parseSectionChildren';\nimport { PageInfoContext } from '../internal/PageInfoContext';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n pageClassName,\n pageMargin,\n reportStyles,\n type PageSize,\n type PageMargin,\n} from '@paprize/core';\n\nexport interface PageProps {\n elements: PageElements;\n size: PageSize;\n margin?: PageMargin;\n pageIndex: number;\n totalPages: number;\n ref?: Ref<HTMLDivElement>;\n sectionHeaderRef?: Ref<HTMLDivElement>;\n sectionFooterRef?: Ref<HTMLDivElement>;\n pageHeaderRef?: Ref<HTMLDivElement>;\n pageFooterRef?: Ref<HTMLDivElement>;\n contentRef?: Ref<HTMLDivElement>;\n}\n\nexport function Page({\n elements,\n size,\n margin,\n pageIndex,\n totalPages,\n ref,\n sectionHeaderRef,\n sectionFooterRef,\n pageHeaderRef,\n pageFooterRef,\n contentRef,\n}: PageProps) {\n const sectionId = useContext(SectionIdContext);\n const contextValue = useMemo(\n () => ({ pageIndex, totalPages }),\n [pageIndex, totalPages]\n );\n\n return (\n <PageInfoContext value={contextValue}>\n <div\n id={`${sectionId}-${pageIndex}`}\n className={pageClassName}\n ref={ref}\n style={reportStyles.page(size, margin ?? pageMargin.None)}\n >\n {elements.sectionHeader && pageIndex === 0 && (\n <div style={reportStyles.component} ref={sectionHeaderRef}>\n {elements.sectionHeader}\n </div>\n )}\n {elements.header && (\n <div style={reportStyles.component} ref={pageHeaderRef}>\n {elements.header}\n </div>\n )}\n\n <div style={reportStyles.pageContent} ref={contentRef}>\n {elements.content}\n </div>\n\n {elements.overlay && (\n <div style={reportStyles.overlay}>{elements.overlay}</div>\n )}\n\n {(elements.footer || elements.sectionFooter) && (\n <div\n style={{ ...reportStyles.component, marginTop: 'auto' }}\n >\n {elements.footer && (\n <div\n style={reportStyles.component}\n ref={pageFooterRef}\n >\n {elements.footer}\n </div>\n )}\n {elements.sectionFooter &&\n pageIndex === totalPages - 1 && (\n <div\n style={reportStyles.component}\n ref={sectionFooterRef}\n >\n {elements.sectionFooter}\n </div>\n )}\n </div>\n )}\n </div>\n </PageInfoContext>\n );\n}\n","import type { PaginationPlugin } from '@paprize/core';\nimport { createContext } from 'react';\n\nexport interface SectionController {\n addPlugin: (plugin: PaginationPlugin) => void;\n addSuspense: (suspense: Promise<void>) => void;\n}\n\nexport const SectionControllerContext = createContext<SectionController>({\n addPlugin: () => {\n throw new Error('addPlugin must be used within a Section');\n },\n addSuspense: () => {\n throw new Error('addSuspense must be used within a Section');\n },\n});\n","import { useMemo } from 'react';\nimport { type SectionController } from './SectionControllerContext';\nimport type { PaginationPlugin } from '@paprize/core';\n\nexport function useSectionControllerState(plugins?: PaginationPlugin[]) {\n const state = useMemo(\n () => ({\n plugins: plugins ?? ([] as PaginationPlugin[]),\n suspense: [] as Promise<void>[],\n }),\n [plugins]\n );\n\n const sectionController: SectionController = useMemo(\n () => ({\n addPlugin: (plugin: PaginationPlugin) => {\n state.plugins.push(plugin);\n },\n addSuspense: (suspense: Promise<void>) => {\n state.suspense.push(suspense);\n },\n }),\n [state]\n );\n\n return {\n controllerState: state,\n controllerValue: sectionController,\n };\n}\n","import {\n adjustPageSize,\n logger,\n reportStyles,\n type PageContext,\n type SectionOptions,\n} from '@paprize/core';\nimport { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { Page } from '../components/Page';\nimport { useReportBuilder } from './useReportBuilder';\nimport { SectionIdContext } from './SectionIdContext';\nimport type { PageElements } from './parseSectionChildren';\nimport { useSectionControllerState } from './useSectionControllerState';\nimport { SectionControllerContext } from './SectionControllerContext';\n\nexport interface SectionLayoutProps {\n elements: PageElements;\n options: SectionOptions;\n}\n\nexport function SectionLayout({ elements, options }: SectionLayoutProps) {\n const sectionId = useContext(SectionIdContext);\n const { controllerState, controllerValue } = useSectionControllerState(\n options?.plugins\n );\n const reportBuilder = useReportBuilder();\n const pageRef = useRef<HTMLDivElement>(null);\n const sectionHeaderRef = useRef<HTMLDivElement>(null);\n const sectionFooterRef = useRef<HTMLDivElement>(null);\n const pageHeaderRef = useRef<HTMLDivElement>(null);\n const pageFooterRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const realizedSize = useMemo(\n () => adjustPageSize(options.size, options.orientation),\n [options.orientation, options.size]\n );\n const [pageContexts, setPageContexts] = useState<PageContext[] | null>(\n null\n );\n\n useEffect(() => {\n if (!contentRef.current) {\n return;\n }\n\n reportBuilder\n .tryAddSection(\n {\n ...options,\n id: sectionId,\n plugins: controllerState.plugins,\n suspense: controllerState.suspense,\n },\n {\n pageContent: contentRef.current,\n sectionHeader: sectionHeaderRef.current,\n sectionFooter: sectionFooterRef.current,\n pageFooter: pageFooterRef.current,\n pageHeader: pageHeaderRef.current,\n },\n (pages) => {\n setPageContexts(pages);\n }\n )\n .catch((e) => logger.error(e));\n\n return () => {\n reportBuilder.removeSection(sectionId);\n };\n }, [\n controllerState.plugins,\n controllerState.suspense,\n options,\n reportBuilder,\n sectionId,\n ]);\n\n return (\n <SectionControllerContext value={controllerValue}>\n {pageContexts?.map((pageContext) => (\n <Page\n key={pageContext.pageIndex}\n elements={{\n ...elements,\n content: (\n <div\n style={{ display: 'contents' }}\n dangerouslySetInnerHTML={{\n __html: pageContext.pageContentHtml,\n }}\n />\n ),\n }}\n size={realizedSize}\n margin={options.margin}\n pageIndex={pageContext.pageIndex}\n totalPages={pageContext.totalPages}\n />\n ))}\n\n {createPortal(\n <div style={reportStyles.outOfScreen}>\n <Page\n elements={elements}\n size={realizedSize}\n margin={options.margin}\n pageIndex={0}\n totalPages={1}\n ref={pageRef}\n sectionHeaderRef={sectionHeaderRef}\n sectionFooterRef={sectionFooterRef}\n pageHeaderRef={pageHeaderRef}\n pageFooterRef={pageFooterRef}\n contentRef={contentRef}\n />\n </div>,\n document.body\n )}\n </SectionControllerContext>\n );\n}\n","import { useMemo, type ReactNode } from 'react';\nimport parseSectionChildren from '../internal/parseSectionChildren';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n reportStyles,\n sectionClassName,\n type SectionOptions,\n} from '@paprize/core';\nimport { SectionLayout } from '../internal/SectionLayout';\n\n/**\n * Configuration options for a section.\n * @inlineType SectionOptions\n */\nexport interface SectionProps extends Omit<SectionOptions, 'id' | 'suspense'> {\n children: ReactNode;\n /**\n * Unique id of the section within the report. If not set, a random id will be used.\n */\n id?: string;\n}\n\nlet sectionIdCounter = 1;\n\nexport function Section({ children, id, ...options }: SectionProps) {\n const sectionId = useMemo(() => id ?? `__000${sectionIdCounter++}`, [id]);\n const elements = useMemo(() => parseSectionChildren(children), [children]);\n const sectionOptions = useMemo(\n () => ({\n ...options,\n id: sectionId,\n }),\n [options, sectionId]\n );\n\n return (\n <section\n className={sectionClassName}\n id={sectionId}\n style={reportStyles.section(sectionId)}\n >\n <SectionIdContext value={sectionId}>\n <SectionLayout elements={elements} options={sectionOptions} />\n </SectionIdContext>\n </section>\n );\n}\n","import { pageBreakAttributeName } from '@paprize/core';\n\nexport function PageBreak() {\n return <span {...{ [pageBreakAttributeName]: 'true' }} />;\n}\n","import { layoutOptionsToAttributes, type LayoutOptions } from '@paprize/core';\n\nexport interface LayoutProps extends LayoutOptions {\n children: React.ReactNode;\n}\n\nexport function Layout({ children, ...attributes }: LayoutProps) {\n return (\n <div\n style={{ display: 'contents' }}\n {...layoutOptionsToAttributes(attributes)}\n >\n {children}\n </div>\n );\n}\n","import { useContext } from 'react';\nimport { PageInfoContext } from '../internal/PageInfoContext';\nimport type { PageInfo } from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the current page.\n */\nexport const usePageInfo = (): PageInfo => {\n const pageContext = useContext(PageInfoContext);\n\n return {\n pageIndex: pageContext.pageIndex,\n totalPages: pageContext.totalPages,\n };\n};\n","import { useContext, useRef, useSyncExternalStore } from 'react';\nimport type { SectionContext } from '@paprize/core';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport type { SectionInfo } from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the current section.\n */\nexport const useSectionInfo = (): SectionInfo => {\n const sectionId = useContext(SectionIdContext);\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<SectionContext>({\n pages: [],\n isPaginated: false,\n isSuspended: false,\n sectionIndex: -1,\n sectionId: sectionId,\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'sectionCompleted',\n (sc) => {\n if (sc.sectionId !== sectionId) return;\n stateRef.current = sc;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return {\n sectionId: sectionId,\n sectionIndex: state.sectionIndex,\n isSuspended: state.isSuspended,\n isPaginated: state.isPaginated,\n pages: state.pages.map((p) => ({\n pageIndex: p.pageIndex,\n totalPages: p.totalPages,\n })),\n };\n};\n","import type { PaginationCycleCompleted, SectionContext } from '@paprize/core';\n\n/**\n * {@inheritDoc @paprize/core!PageContext}\n */\nexport interface PageInfo {\n /**\n * {@inheritDoc @paprize/core!PageContext.pageIndex}\n */\n pageIndex: number;\n /**\n * {@inheritDoc @paprize/core!PageContext.totalPages}\n */\n totalPages: number;\n}\n\n/**\n * {@inheritDoc @paprize/core!SectionContext}\n */\nexport interface SectionInfo {\n /**\n * {@inheritDoc @paprize/core!SectionContext.sectionId}\n */\n sectionId: string;\n /**\n * {@inheritDoc @paprize/core!SectionContext.sectionIndex}\n */\n sectionIndex: number;\n /**\n * {@inheritDoc @paprize/core!SectionContext.isPaginated}\n */\n isPaginated: boolean;\n /**\n * {@inheritDoc @paprize/core!SectionContext.isSuspended}\n */\n isSuspended: boolean;\n /**\n * {@inheritDoc @paprize/core!SectionContext.pages}\n */\n pages: PageInfo[];\n}\n\n/**\n * {@inheritDoc @paprize/core!PaginationCycleCompleted}\n */\n\nexport interface ReportInfo {\n /**\n * {@inheritDoc @paprize/core!PaginationCycleCompleted.sections}\n */\n sections: SectionInfo[];\n}\n\nexport function pageContextToPageInfo(pc: {\n pageIndex: number;\n totalPages: number;\n}): PageInfo {\n return {\n pageIndex: pc.pageIndex,\n totalPages: pc.totalPages,\n };\n}\n\nexport function sectionContextToSectionInfo(sc: SectionContext): SectionInfo {\n return {\n sectionId: sc.sectionId,\n sectionIndex: sc.sectionIndex,\n isPaginated: sc.isPaginated,\n isSuspended: sc.isSuspended,\n pages: sc.pages.map(pageContextToPageInfo),\n };\n}\n\nexport function paginationCycleToReportInfo(\n rc: PaginationCycleCompleted\n): ReportInfo {\n return {\n sections: rc.sections.map(sectionContextToSectionInfo),\n };\n}\n","import { useRef, useSyncExternalStore } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport type { PaginationCycleCompleted } from '@paprize/core';\nimport {\n paginationCycleToReportInfo,\n type ReportInfo,\n} from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the report.\n */\nexport function useReportInfo(): ReportInfo {\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<PaginationCycleCompleted>({\n sections: [],\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n (pg) => {\n stateRef.current = pg;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return paginationCycleToReportInfo(state);\n}\n","import { useContext, useEffect, useMemo, useRef } from 'react';\nimport { SectionControllerContext } from '../internal/SectionControllerContext';\n\n/**\n * Controls the section suspension.\n * @inline\n */\nexport interface SectionSuspension {\n /**\n * Releases the suspension. The pagination engine will paginate this section immediately.\n */\n release: () => void;\n\n /**\n * Marks the suspension as pending again if it was previously resolved.\n * During the next pagination cycle (for example, if pagination is retriggered\n * by changes to the page content), this section will not be paginated\n * until `release` is called again.\n */\n reset: () => void;\n}\n\n/**\n * Suspends pagination for this section.\n * @param promise The suspension is tied to this promise. Once the promise is resolved,\n * the suspension is released and the pagination engine will paginate this section.\n */\nexport function useSectionSuspension(\n promise: Promise<void> | Promise<unknown>\n): void;\n/**\n * Suspends pagination for this section. You need to call the `release` method\n * of the returned value; otherwise, the pagination engine will never paginate this section.\n */\nexport function useSectionSuspension(): SectionSuspension;\nexport function useSectionSuspension(\n promise?: Promise<void> | Promise<unknown>\n) {\n const resolveFn = useRef<() => void | null>(null);\n const { addSuspense } = useContext(SectionControllerContext);\n\n useEffect(() => {\n if (resolveFn.current) {\n return;\n }\n\n const pr =\n promise ??\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n });\n resolveFn.current ||= () => {};\n\n addSuspense(pr as Promise<void>);\n }, [addSuspense, promise]);\n\n return useMemo(\n () => ({\n reset: () => {\n if (resolveFn.current) return;\n\n addSuspense(\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n })\n );\n },\n release: () => {\n resolveFn.current?.();\n resolveFn.current = null;\n },\n }),\n [addSuspense]\n );\n}\n","import { useSectionSuspension } from './useSectionSuspension';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport { useEffect, useMemo } from 'react';\n\n/**\n * {@inheritDoc @paprize/core!ReportBuilder.getJsonData}\n */\nexport function useJsonData<DataModel>(\n defaultValue?: DataModel\n): DataModel | null {\n const reportBuilder = useReportBuilder();\n const value = useMemo(\n () => ({\n current: null as DataModel | null,\n }),\n []\n );\n\n const promise = useMemo(\n () => reportBuilder.getJsonData(defaultValue),\n [defaultValue, reportBuilder]\n );\n\n useSectionSuspension(promise);\n\n useEffect(() => {\n promise.then((v) => (value.current = v));\n }, [promise, value]);\n\n return value.current ?? defaultValue ?? null;\n}\n"],"names":["ReportPreview","children","jsx","previewClassName","ReportBuilderContext","createContext","useReportBuilder","context","useContext","ReportRoot","reportBuilder","useMemo","ReportBuilder","useEffect","PageContent","isFirstCycleCompleted","useRef","unsubscribe","PageFooter","PageHeader","SectionFooter","SectionHeader","PageOverlay","validChildren","parseSectionChildren","content","pageElements","Children","child","isValidElement","component","x","SectionIdContext","PageInfoContext","Page","elements","size","margin","pageIndex","totalPages","ref","sectionHeaderRef","sectionFooterRef","pageHeaderRef","pageFooterRef","contentRef","sectionId","contextValue","jsxs","pageClassName","reportStyles","pageMargin","SectionControllerContext","useSectionControllerState","plugins","state","sectionController","plugin","suspense","SectionLayout","options","controllerState","controllerValue","pageRef","realizedSize","adjustPageSize","pageContexts","setPageContexts","useState","pages","e","logger","pageContext","createPortal","sectionIdCounter","Section","id","sectionOptions","sectionClassName","PageBreak","pageBreakAttributeName","Layout","attributes","layoutOptionsToAttributes","usePageInfo","useSectionInfo","stateRef","useSyncExternalStore","callback","sc","p","pageContextToPageInfo","pc","sectionContextToSectionInfo","paginationCycleToReportInfo","rc","useReportInfo","pg","useSectionSuspension","promise","resolveFn","addSuspense","pr","resolve","useJsonData","defaultValue","value","v"],"mappings":"mbAGO,SAASA,EAAc,CAAE,SAAAC,GAAqC,CACjE,OAAOC,EAAAA,IAAC,MAAA,CAAI,UAAWC,EAAAA,iBAAmB,SAAAF,CAAA,CAAS,CACvD,CCF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,CAEpB,CCnEO,SAASG,EACZC,EACgB,CAChB,MAAM/F,EAAgBJ,EAAA,EAChBoG,EAAQ/F,EAAAA,QACV,KAAO,CACH,QAAS,IAAA,GAEb,CAAA,CAAC,EAGCwF,EAAUxF,EAAAA,QACZ,IAAMD,EAAc,YAAY+F,CAAY,EAC5C,CAACA,EAAc/F,CAAa,CAAA,EAGhC,OAAAwF,EAAqBC,CAAO,EAE5BtF,EAAAA,UAAU,IAAM,CACZsF,EAAQ,KAAMQ,GAAOD,EAAM,QAAUC,CAAE,CAC3C,EAAG,CAACR,EAASO,CAAK,CAAC,EAEZA,EAAM,SAAWD,GAAgB,IAC5C"}
1
+ {"version":3,"file":"paprize-react.umd.cjs","sources":["../src/components/ReportPreview.tsx","../src/internal/useReportBuilder.ts","../src/components/ReportRoot.tsx","../src/components/PageContent.tsx","../src/components/PageFooter.tsx","../src/components/PageHeader.tsx","../src/components/SectionFooter.tsx","../src/components/SectionHeader.tsx","../src/components/PageOverlay.tsx","../src/internal/parseSectionChildren.ts","../src/internal/SectionIdContext.ts","../src/internal/PageInfoContext.ts","../src/components/Page.tsx","../src/internal/SectionControllerContext.ts","../src/internal/useSectionControllerState.tsx","../src/internal/SectionLayout.tsx","../src/components/Section.tsx","../src/components/PageBreak.tsx","../src/components/Layout.tsx","../src/components/usePageInfo.ts","../src/components/useSectionInfo.ts","../src/internal/eventHelper.ts","../src/components/useReportInfo.ts","../src/components/useSectionSuspension.ts","../src/components/useJsonData.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { previewClassName } from '@paprize/core';\n\nexport function ReportPreview({ children }: { children: ReactNode }) {\n return <div className={previewClassName}>{children}</div>;\n}\n","import type { ReportBuilder } from '@paprize/core';\nimport { createContext, useContext } from 'react';\n\nexport const ReportBuilderContext = createContext<ReportBuilder | null>(null);\n\nexport function useReportBuilder() {\n const context = useContext(ReportBuilderContext);\n if (!context) {\n throw new Error(\n 'ReportRoot is missing. Please wrap your component tree with ReportRoot component.'\n );\n }\n\n return context;\n}\n","import { useEffect, useMemo, type ReactNode } from 'react';\nimport { ReportBuilder } from '@paprize/core';\nimport { ReportBuilderContext } from '../internal/useReportBuilder';\n\nexport interface ReportRootProps {\n children: ReactNode;\n}\n\nexport function ReportRoot({ children }: ReportRootProps) {\n const reportBuilder = useMemo(() => new ReportBuilder(), []);\n\n useEffect(() => {\n reportBuilder.schedulePagination();\n }, [reportBuilder]);\n\n return (\n <ReportBuilderContext value={reportBuilder}>\n {children}\n </ReportBuilderContext>\n );\n}\n","import { useEffect, useRef, type ReactNode } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\n\nexport function PageContent({ children }: { children: ReactNode }) {\n const reportBuilder = useReportBuilder();\n const isFirstCycleCompleted = useRef(false);\n\n useEffect(() => {\n const unsubscribe = reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n () => {\n isFirstCycleCompleted.current = true;\n }\n );\n\n return () => unsubscribe();\n }, [reportBuilder.monitor]);\n\n // If the children change after the first pagination cycle, we need to re-paginate\n // this can happen if the content is dynamic or loaded asynchronously\n // if we don't do this, the new content will be ignored in the pagination\n useEffect(() => {\n if (isFirstCycleCompleted.current) {\n reportBuilder.schedulePagination();\n }\n }, [children, reportBuilder]);\n\n return <>{children}</>;\n}\n","export function PageFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageHeader({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionHeader({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageOverlay({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","import {\n Children,\n isValidElement,\n type FC,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { PageContent } from '../components/PageContent';\nimport { PageFooter } from '../components/PageFooter';\nimport { PageHeader } from '../components/PageHeader';\nimport { SectionFooter } from '../components/SectionFooter';\nimport { SectionHeader } from '../components/SectionHeader';\nimport { PageOverlay } from '../components/PageOverlay';\n\nconst validChildren: FC<{ children: ReactNode }>[] = [\n PageContent,\n PageHeader,\n PageFooter,\n PageOverlay,\n SectionHeader,\n SectionFooter,\n];\n\nexport interface PageElements {\n content: ReactElement;\n header?: ReactElement;\n footer?: ReactElement;\n overlay?: ReactElement;\n sectionHeader?: ReactElement;\n sectionFooter?: ReactElement;\n}\n\nfunction parseSectionChildren(children: ReactNode): PageElements {\n let content: ReactElement | null = null;\n const pageElements: Partial<PageElements> = {};\n\n Children.forEach(children, (child) => {\n if (!isValidElement(child)) {\n throw new Error(\n `Invalid React element found in children: ${child}`,\n {\n cause: { child },\n }\n );\n }\n\n const component = validChildren.find((x) => x === child.type);\n if (!component) {\n throw Error(\n `Component \"${child.type}\" is not valid as a child for Section, Expected one of: ${validChildren\n .map((x) => x.name)\n .join(',')}`\n );\n }\n\n switch (component) {\n case SectionHeader:\n pageElements.sectionHeader = child;\n break;\n\n case SectionFooter:\n pageElements.sectionFooter = child;\n break;\n\n case PageContent:\n content = child;\n break;\n\n case PageHeader:\n pageElements.header = child;\n break;\n\n case PageFooter:\n pageElements.footer = child;\n break;\n\n case PageOverlay:\n pageElements.overlay = child;\n break;\n }\n });\n\n if (!content) {\n throw Error('PageContent component is a required child for Section');\n }\n\n return { ...pageElements, content: content };\n}\n\nexport default parseSectionChildren;\n","import { createContext } from 'react';\n\nexport const SectionIdContext = createContext<string>('');\n","import { createContext } from 'react';\n\nexport const PageInfoContext = createContext<{\n pageIndex: number;\n totalPages: number;\n}>({\n pageIndex: 0,\n totalPages: 0,\n});\n","import { useContext, useMemo, type Ref } from 'react';\nimport { type PageElements } from '../internal/parseSectionChildren';\nimport { PageInfoContext } from '../internal/PageInfoContext';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n pageClassName,\n pageMargin,\n reportStyles,\n type PageSize,\n type PageMargin,\n} from '@paprize/core';\n\nexport interface PageProps {\n elements: PageElements;\n size: PageSize;\n margin?: PageMargin;\n pageIndex: number;\n totalPages: number;\n ref?: Ref<HTMLDivElement>;\n sectionHeaderRef?: Ref<HTMLDivElement>;\n sectionFooterRef?: Ref<HTMLDivElement>;\n pageHeaderRef?: Ref<HTMLDivElement>;\n pageFooterRef?: Ref<HTMLDivElement>;\n contentRef?: Ref<HTMLDivElement>;\n}\n\nexport function Page({\n elements,\n size,\n margin,\n pageIndex,\n totalPages,\n ref,\n sectionHeaderRef,\n sectionFooterRef,\n pageHeaderRef,\n pageFooterRef,\n contentRef,\n}: PageProps) {\n const sectionId = useContext(SectionIdContext);\n const contextValue = useMemo(\n () => ({ pageIndex, totalPages }),\n [pageIndex, totalPages]\n );\n\n return (\n <PageInfoContext value={contextValue}>\n <div\n id={`${sectionId}-${pageIndex}`}\n className={pageClassName}\n ref={ref}\n style={reportStyles.page(size, margin ?? pageMargin.None)}\n >\n {elements.sectionHeader && pageIndex === 0 && (\n <div style={reportStyles.component} ref={sectionHeaderRef}>\n {elements.sectionHeader}\n </div>\n )}\n {elements.header && (\n <div style={reportStyles.component} ref={pageHeaderRef}>\n {elements.header}\n </div>\n )}\n\n <div style={reportStyles.pageContent} ref={contentRef}>\n {elements.content}\n </div>\n\n {elements.overlay && (\n <div style={reportStyles.overlay}>{elements.overlay}</div>\n )}\n\n {(elements.footer || elements.sectionFooter) && (\n <div\n style={{ ...reportStyles.component, marginTop: 'auto' }}\n >\n {elements.footer && (\n <div\n style={reportStyles.component}\n ref={pageFooterRef}\n >\n {elements.footer}\n </div>\n )}\n {elements.sectionFooter &&\n pageIndex === totalPages - 1 && (\n <div\n style={reportStyles.component}\n ref={sectionFooterRef}\n >\n {elements.sectionFooter}\n </div>\n )}\n </div>\n )}\n </div>\n </PageInfoContext>\n );\n}\n","import type { PaginationPlugin } from '@paprize/core';\nimport { createContext } from 'react';\n\nexport interface SectionController {\n addPlugin: (plugin: PaginationPlugin) => void;\n addSuspense: (suspense: Promise<void>) => void;\n}\n\nexport const SectionControllerContext = createContext<SectionController>({\n addPlugin: () => {\n throw new Error('addPlugin must be used within a Section');\n },\n addSuspense: () => {\n throw new Error('addSuspense must be used within a Section');\n },\n});\n","import { useMemo } from 'react';\nimport { type SectionController } from './SectionControllerContext';\nimport type { PaginationPlugin } from '@paprize/core';\n\nexport function useSectionControllerState(plugins?: PaginationPlugin[]) {\n const state = useMemo(\n () => ({\n plugins: plugins ?? ([] as PaginationPlugin[]),\n suspense: [] as Promise<void>[],\n }),\n [plugins]\n );\n\n const sectionController: SectionController = useMemo(\n () => ({\n addPlugin: (plugin: PaginationPlugin) => {\n state.plugins.push(plugin);\n },\n addSuspense: (suspense: Promise<void>) => {\n state.suspense.push(suspense);\n },\n }),\n [state]\n );\n\n return {\n controllerState: state,\n controllerValue: sectionController,\n };\n}\n","import {\n adjustPageSize,\n logger,\n reportStyles,\n type PageContext,\n type SectionOptions,\n} from '@paprize/core';\nimport { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { Page } from '../components/Page';\nimport { useReportBuilder } from './useReportBuilder';\nimport { SectionIdContext } from './SectionIdContext';\nimport type { PageElements } from './parseSectionChildren';\nimport { useSectionControllerState } from './useSectionControllerState';\nimport { SectionControllerContext } from './SectionControllerContext';\n\nexport interface SectionLayoutProps {\n elements: PageElements;\n options: SectionOptions;\n}\n\nexport function SectionLayout({ elements, options }: SectionLayoutProps) {\n const sectionId = useContext(SectionIdContext);\n const { controllerState, controllerValue } = useSectionControllerState(\n options?.plugins\n );\n const reportBuilder = useReportBuilder();\n const pageRef = useRef<HTMLDivElement>(null);\n const sectionHeaderRef = useRef<HTMLDivElement>(null);\n const sectionFooterRef = useRef<HTMLDivElement>(null);\n const pageHeaderRef = useRef<HTMLDivElement>(null);\n const pageFooterRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const realizedSize = useMemo(\n () => adjustPageSize(options.size, options.orientation),\n [options.orientation, options.size]\n );\n const [pageContexts, setPageContexts] = useState<PageContext[] | null>(\n null\n );\n\n useEffect(() => {\n if (!contentRef.current) {\n return;\n }\n\n reportBuilder\n .tryAddSection(\n {\n ...options,\n id: sectionId,\n plugins: controllerState.plugins,\n suspense: controllerState.suspense,\n },\n {\n pageContent: contentRef.current,\n sectionHeader: sectionHeaderRef.current,\n sectionFooter: sectionFooterRef.current,\n pageFooter: pageFooterRef.current,\n pageHeader: pageHeaderRef.current,\n },\n (sectionCtx) => {\n setPageContexts(sectionCtx.pages);\n }\n )\n .catch((e) => logger.error(e));\n\n return () => {\n reportBuilder.removeSection(sectionId);\n };\n }, [\n controllerState.plugins,\n controllerState.suspense,\n options,\n reportBuilder,\n sectionId,\n ]);\n\n return (\n <SectionControllerContext value={controllerValue}>\n {pageContexts?.map((pageContext) => (\n <Page\n key={pageContext.pageIndex}\n elements={{\n ...elements,\n content: (\n <div\n style={{ display: 'contents' }}\n dangerouslySetInnerHTML={{\n __html: pageContext.pageContentHtml,\n }}\n />\n ),\n }}\n size={realizedSize}\n margin={options.margin}\n pageIndex={pageContext.pageIndex}\n totalPages={pageContext.totalPages}\n />\n ))}\n\n {createPortal(\n <div style={reportStyles.outOfScreen}>\n <Page\n elements={elements}\n size={realizedSize}\n margin={options.margin}\n pageIndex={0}\n totalPages={1}\n ref={pageRef}\n sectionHeaderRef={sectionHeaderRef}\n sectionFooterRef={sectionFooterRef}\n pageHeaderRef={pageHeaderRef}\n pageFooterRef={pageFooterRef}\n contentRef={contentRef}\n />\n </div>,\n document.body\n )}\n </SectionControllerContext>\n );\n}\n","import { useMemo, type ReactNode } from 'react';\nimport parseSectionChildren from '../internal/parseSectionChildren';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n reportStyles,\n sectionClassName,\n type SectionOptions,\n} from '@paprize/core';\nimport { SectionLayout } from '../internal/SectionLayout';\n\n/**\n * Configuration options for a section.\n * @inlineType SectionOptions\n */\nexport interface SectionProps extends Omit<SectionOptions, 'id' | 'suspense'> {\n children: ReactNode;\n /**\n * Unique id of the section within the report. If not set, a random id will be used.\n */\n id?: string;\n}\n\nlet sectionIdCounter = 1;\n\nexport function Section({ children, id, ...options }: SectionProps) {\n const sectionId = useMemo(() => id ?? `__000${sectionIdCounter++}`, [id]);\n const elements = useMemo(() => parseSectionChildren(children), [children]);\n const sectionOptions = useMemo(\n () => ({\n ...options,\n id: sectionId,\n }),\n [options, sectionId]\n );\n\n return (\n <section\n className={sectionClassName}\n id={sectionId}\n style={reportStyles.section(sectionId)}\n >\n <SectionIdContext value={sectionId}>\n <SectionLayout elements={elements} options={sectionOptions} />\n </SectionIdContext>\n </section>\n );\n}\n","import { pageBreakAttributeName } from '@paprize/core';\n\nexport function PageBreak() {\n return <span {...{ [pageBreakAttributeName]: 'true' }} />;\n}\n","import { layoutOptionsToAttributes, type LayoutOptions } from '@paprize/core';\n\nexport interface LayoutProps extends LayoutOptions {\n children: React.ReactNode;\n}\n\nexport function Layout({ children, ...attributes }: LayoutProps) {\n return (\n <div\n style={{ display: 'contents' }}\n {...layoutOptionsToAttributes(attributes)}\n >\n {children}\n </div>\n );\n}\n","import { useContext } from 'react';\nimport { PageInfoContext } from '../internal/PageInfoContext';\nimport type { PageInfo } from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the current page.\n */\nexport const usePageInfo = (): PageInfo => {\n const pageContext = useContext(PageInfoContext);\n\n return {\n pageIndex: pageContext.pageIndex,\n totalPages: pageContext.totalPages,\n };\n};\n","import { useContext, useRef, useSyncExternalStore } from 'react';\nimport type { SectionContext } from '@paprize/core';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport type { SectionInfo } from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the current section.\n */\nexport const useSectionInfo = (): SectionInfo => {\n const sectionId = useContext(SectionIdContext);\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<Omit<SectionContext, 'options' | 'components'>>({\n pages: [],\n isPaginated: false,\n isSuspended: false,\n sectionIndex: -1,\n sectionId: sectionId,\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'sectionCompleted',\n (sc) => {\n if (sc.sectionId !== sectionId) return;\n stateRef.current = sc;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return {\n sectionId: sectionId,\n sectionIndex: state.sectionIndex,\n isSuspended: state.isSuspended,\n isPaginated: state.isPaginated,\n pages: state.pages.map((p) => ({\n pageIndex: p.pageIndex,\n totalPages: p.totalPages,\n })),\n };\n};\n","import type { PaginationCycleCompleted, SectionContext } from '@paprize/core';\n\n/**\n * {@inheritDoc @paprize/core!PageContext}\n */\nexport interface PageInfo {\n /**\n * {@inheritDoc @paprize/core!PageContext.pageIndex}\n */\n pageIndex: number;\n /**\n * {@inheritDoc @paprize/core!PageContext.totalPages}\n */\n totalPages: number;\n}\n\n/**\n * {@inheritDoc @paprize/core!SectionContext}\n */\nexport interface SectionInfo {\n /**\n * {@inheritDoc @paprize/core!SectionContext.sectionId}\n */\n sectionId: string;\n /**\n * {@inheritDoc @paprize/core!SectionContext.sectionIndex}\n */\n sectionIndex: number;\n /**\n * {@inheritDoc @paprize/core!SectionContext.isPaginated}\n */\n isPaginated: boolean;\n /**\n * {@inheritDoc @paprize/core!SectionContext.isSuspended}\n */\n isSuspended: boolean;\n /**\n * {@inheritDoc @paprize/core!SectionContext.pages}\n */\n pages: PageInfo[];\n}\n\n/**\n * {@inheritDoc @paprize/core!PaginationCycleCompleted}\n */\n\nexport interface ReportInfo {\n /**\n * {@inheritDoc @paprize/core!PaginationCycleCompleted.sections}\n */\n sections: SectionInfo[];\n}\n\nexport function pageContextToPageInfo(pc: {\n pageIndex: number;\n totalPages: number;\n}): PageInfo {\n return {\n pageIndex: pc.pageIndex,\n totalPages: pc.totalPages,\n };\n}\n\nexport function sectionContextToSectionInfo(sc: SectionContext): SectionInfo {\n return {\n sectionId: sc.sectionId,\n sectionIndex: sc.sectionIndex,\n isPaginated: sc.isPaginated,\n isSuspended: sc.isSuspended,\n pages: sc.pages.map(pageContextToPageInfo),\n };\n}\n\nexport function paginationCycleToReportInfo(\n rc: PaginationCycleCompleted\n): ReportInfo {\n return {\n sections: rc.sections.map(sectionContextToSectionInfo),\n };\n}\n","import { useRef, useSyncExternalStore } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport type { PaginationCycleCompleted } from '@paprize/core';\nimport {\n paginationCycleToReportInfo,\n type ReportInfo,\n} from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the report.\n */\nexport function useReportInfo(): ReportInfo {\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<PaginationCycleCompleted>({\n sections: [],\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n (pg) => {\n stateRef.current = pg;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return paginationCycleToReportInfo(state);\n}\n","import { useContext, useEffect, useMemo, useRef } from 'react';\nimport { SectionControllerContext } from '../internal/SectionControllerContext';\n\n/**\n * Controls the section suspension.\n * @inline\n */\nexport interface SectionSuspension {\n /**\n * Releases the suspension. The pagination engine will paginate this section immediately.\n */\n release: () => void;\n\n /**\n * Marks the suspension as pending again if it was previously resolved.\n * During the next pagination cycle (for example, if pagination is retriggered\n * by changes to the page content), this section will not be paginated\n * until `release` is called again.\n */\n reset: () => void;\n}\n\n/**\n * Suspends pagination for this section.\n * @param promise The suspension is tied to this promise. Once the promise is resolved,\n * the suspension is released and the pagination engine will paginate this section.\n */\nexport function useSectionSuspension(\n promise: Promise<void> | Promise<unknown>\n): void;\n/**\n * Suspends pagination for this section. You need to call the `release` method\n * of the returned value; otherwise, the pagination engine will never paginate this section.\n */\nexport function useSectionSuspension(): SectionSuspension;\nexport function useSectionSuspension(\n promise?: Promise<void> | Promise<unknown>\n) {\n const resolveFn = useRef<() => void | null>(null);\n const { addSuspense } = useContext(SectionControllerContext);\n\n useEffect(() => {\n if (resolveFn.current) {\n return;\n }\n\n const pr =\n promise ??\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n });\n resolveFn.current ||= () => {};\n\n addSuspense(pr as Promise<void>);\n }, [addSuspense, promise]);\n\n return useMemo(\n () => ({\n reset: () => {\n if (resolveFn.current) return;\n\n addSuspense(\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n })\n );\n },\n release: () => {\n resolveFn.current?.();\n resolveFn.current = null;\n },\n }),\n [addSuspense]\n );\n}\n","import { useSectionSuspension } from './useSectionSuspension';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport { useEffect, useMemo } from 'react';\n\n/**\n * {@inheritDoc @paprize/core!ReportBuilder.getJsonData}\n */\nexport function useJsonData<DataModel>(\n defaultValue?: DataModel\n): DataModel | null {\n const reportBuilder = useReportBuilder();\n const value = useMemo(\n () => ({\n current: null as DataModel | null,\n }),\n []\n );\n\n const promise = useMemo(\n () => reportBuilder.getJsonData(defaultValue),\n [defaultValue, reportBuilder]\n );\n\n useSectionSuspension(promise);\n\n useEffect(() => {\n promise.then((v) => (value.current = v));\n }, [promise, value]);\n\n return value.current ?? defaultValue ?? null;\n}\n"],"names":["ReportPreview","children","jsx","previewClassName","ReportBuilderContext","createContext","useReportBuilder","context","useContext","ReportRoot","reportBuilder","useMemo","ReportBuilder","useEffect","PageContent","isFirstCycleCompleted","useRef","unsubscribe","PageFooter","PageHeader","SectionFooter","SectionHeader","PageOverlay","validChildren","parseSectionChildren","content","pageElements","Children","child","isValidElement","component","x","SectionIdContext","PageInfoContext","Page","elements","size","margin","pageIndex","totalPages","ref","sectionHeaderRef","sectionFooterRef","pageHeaderRef","pageFooterRef","contentRef","sectionId","contextValue","jsxs","pageClassName","reportStyles","pageMargin","SectionControllerContext","useSectionControllerState","plugins","state","sectionController","plugin","suspense","SectionLayout","options","controllerState","controllerValue","pageRef","realizedSize","adjustPageSize","pageContexts","setPageContexts","useState","sectionCtx","e","logger","pageContext","createPortal","sectionIdCounter","Section","id","sectionOptions","sectionClassName","PageBreak","pageBreakAttributeName","Layout","attributes","layoutOptionsToAttributes","usePageInfo","useSectionInfo","stateRef","useSyncExternalStore","callback","sc","p","pageContextToPageInfo","pc","sectionContextToSectionInfo","paginationCycleToReportInfo","rc","useReportInfo","pg","useSectionSuspension","promise","resolveFn","addSuspense","pr","resolve","useJsonData","defaultValue","value","v"],"mappings":"mbAGO,SAASA,EAAc,CAAE,SAAAC,GAAqC,CACjE,OAAOC,EAAAA,IAAC,MAAA,CAAI,UAAWC,EAAAA,iBAAmB,SAAAF,CAAA,CAAS,CACvD,CCFO,MAAMG,EAAuBC,EAAAA,cAAoC,IAAI,EAErE,SAASC,GAAmB,CAC/B,MAAMC,EAAUC,EAAAA,WAAWJ,CAAoB,EAC/C,GAAI,CAACG,EACD,MAAM,IAAI,MACN,mFAAA,EAIR,OAAOA,CACX,CCNO,SAASE,EAAW,CAAE,SAAAR,GAA6B,CACtD,MAAMS,EAAgBC,EAAAA,QAAQ,IAAM,IAAIC,EAAAA,cAAiB,CAAA,CAAE,EAE3DC,OAAAA,EAAAA,UAAU,IAAM,CACZH,EAAc,mBAAA,CAClB,EAAG,CAACA,CAAa,CAAC,EAGdR,EAAAA,IAACE,EAAA,CAAqB,MAAOM,EACxB,SAAAT,CAAA,CACL,CAER,CCjBO,SAASa,EAAY,CAAE,SAAAb,GAAqC,CAC/D,MAAMS,EAAgBJ,EAAA,EAChBS,EAAwBC,EAAAA,OAAO,EAAK,EAE1CH,OAAAA,EAAAA,UAAU,IAAM,CACZ,MAAMI,EAAcP,EAAc,QAAQ,iBACtC,2BACA,IAAM,CACFK,EAAsB,QAAU,EACpC,CAAA,EAGJ,MAAO,IAAME,EAAA,CACjB,EAAG,CAACP,EAAc,OAAO,CAAC,EAK1BG,EAAAA,UAAU,IAAM,CACRE,EAAsB,SACtBL,EAAc,mBAAA,CAEtB,EAAG,CAACT,EAAUS,CAAa,CAAC,oBAElB,SAAAT,EAAS,CACvB,CC5BO,SAASiB,EAAW,CAA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,IAAI,QAAeI,GAAY,CAC3BH,EAAU,QAAUG,CACxB,CAAC,EACLH,EAAU,UAAY,IAAM,CAAC,EAE7BC,EAAYC,CAAmB,CACnC,EAAG,CAACD,EAAaF,CAAO,CAAC,EAElBxF,EAAAA,QACH,KAAO,CACH,MAAO,IAAM,CACLyF,EAAU,SAEdC,EACI,IAAI,QAAeE,GAAY,CAC3BH,EAAU,QAAUG,CACxB,CAAC,CAAA,CAET,EACA,QAAS,IAAM,CACXH,EAAU,UAAA,EACVA,EAAU,QAAU,IACxB,CAAA,GAEJ,CAACC,CAAW,CAAA,CAEpB,CCnEO,SAASG,EACZC,EACgB,CAChB,MAAM/F,EAAgBJ,EAAA,EAChBoG,EAAQ/F,EAAAA,QACV,KAAO,CACH,QAAS,IAAA,GAEb,CAAA,CAAC,EAGCwF,EAAUxF,EAAAA,QACZ,IAAMD,EAAc,YAAY+F,CAAY,EAC5C,CAACA,EAAc/F,CAAa,CAAA,EAGhC,OAAAwF,EAAqBC,CAAO,EAE5BtF,EAAAA,UAAU,IAAM,CACZsF,EAAQ,KAAMQ,GAAOD,EAAM,QAAUC,CAAE,CAC3C,EAAG,CAACR,EAASO,CAAK,CAAC,EAEZA,EAAM,SAAWD,GAAgB,IAC5C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paprize/react",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "React library for creating professional, print-ready reports",
5
5
  "type": "module",
6
6
  "files": [
@@ -34,7 +34,7 @@
34
34
  "license": "Apache-2.0",
35
35
  "author": "PejmanNikram",
36
36
  "dependencies": {
37
- "@paprize/core": "0.0.10"
37
+ "@paprize/core": "0.0.11"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "react": ">=17.0.0",
@@ -44,11 +44,11 @@
44
44
  "@types/react": "^19.2.0",
45
45
  "@types/react-dom": "^19.2.0",
46
46
  "@vitejs/plugin-react-swc": "^4.1.0",
47
- "react": "^19.2.0",
47
+ "react": "19.2.0",
48
48
  "react-dom": "^19.2.0",
49
- "typescript": "~5.9.3",
49
+ "typescript": "5.9.3",
50
50
  "vite": "^7.1.9",
51
- "@paprize/config": "0.0.1"
51
+ "@paprize/config": "1.0.0"
52
52
  },
53
53
  "scripts": {
54
54
  "dev": "vite",