@pdfme/ui 5.3.3-dev.4 → 5.3.3-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +19691 -19697
- package/dist/index.umd.js +145 -145
- package/dist/types/contexts.d.ts +1 -0
- package/dist/types/hooks.d.ts +2 -1
- package/package.json +1 -1
- package/src/components/Designer/index.tsx +3 -1
- package/src/components/Preview.tsx +3 -2
- package/src/components/Renderer.tsx +3 -3
- package/src/contexts.ts +2 -0
- package/src/hooks.ts +4 -5
package/dist/types/contexts.d.ts
CHANGED
@@ -82,3 +82,4 @@ export declare const FontContext: import("react").Context<Record<string, {
|
|
82
82
|
}>>;
|
83
83
|
export declare const PluginsRegistry: import("react").Context<Plugins>;
|
84
84
|
export declare const OptionsContext: import("react").Context<UIOptions>;
|
85
|
+
export declare const CacheContext: import("react").Context<Map<any, any>>;
|
package/dist/types/hooks.d.ts
CHANGED
@@ -5,8 +5,9 @@ type UIPreProcessorProps = {
|
|
5
5
|
template: Template;
|
6
6
|
size: Size;
|
7
7
|
zoomLevel: number;
|
8
|
+
maxZoom: number;
|
8
9
|
};
|
9
|
-
export declare const useUIPreProcessor: ({ template, size, zoomLevel }: UIPreProcessorProps) => {
|
10
|
+
export declare const useUIPreProcessor: ({ template, size, zoomLevel, maxZoom }: UIPreProcessorProps) => {
|
10
11
|
backgrounds: string[];
|
11
12
|
pageSizes: {
|
12
13
|
width: number;
|
package/package.json
CHANGED
@@ -24,6 +24,7 @@ import {
|
|
24
24
|
template2SchemasList,
|
25
25
|
getPagesScrollTopByIndex,
|
26
26
|
changeSchemas as _changeSchemas,
|
27
|
+
getMaxZoom,
|
27
28
|
} from '../../helper';
|
28
29
|
import { useUIPreProcessor, useScrollPageCursor, useInitEvents } from '../../hooks';
|
29
30
|
import Root from '../Root';
|
@@ -63,6 +64,7 @@ const TemplateEditor = ({
|
|
63
64
|
const i18n = useContext(I18nContext);
|
64
65
|
const pluginsRegistry = useContext(PluginsRegistry);
|
65
66
|
const options = useContext(OptionsContext);
|
67
|
+
const maxZoom = getMaxZoom();
|
66
68
|
|
67
69
|
const [hoveringSchemaId, setHoveringSchemaId] = useState<string | null>(null);
|
68
70
|
const [activeElements, setActiveElements] = useState<HTMLElement[]>([]);
|
@@ -73,7 +75,7 @@ const TemplateEditor = ({
|
|
73
75
|
const [prevTemplate, setPrevTemplate] = useState<Template | null>(null);
|
74
76
|
|
75
77
|
const { backgrounds, pageSizes, scale, error, refresh } =
|
76
|
-
useUIPreProcessor({ template, size, zoomLevel });
|
78
|
+
useUIPreProcessor({ template, size, zoomLevel, maxZoom });
|
77
79
|
|
78
80
|
const onEdit = (targets: HTMLElement[]) => {
|
79
81
|
setActiveElements(targets);
|
@@ -10,7 +10,7 @@ import Paper from './Paper';
|
|
10
10
|
import Renderer from './Renderer';
|
11
11
|
import { useUIPreProcessor, useScrollPageCursor } from '../hooks';
|
12
12
|
import { FontContext } from '../contexts';
|
13
|
-
import { template2SchemasList, getPagesScrollTopByIndex } from '../helper';
|
13
|
+
import { template2SchemasList, getPagesScrollTopByIndex, getMaxZoom } from '../helper';
|
14
14
|
import { theme } from 'antd';
|
15
15
|
|
16
16
|
const _cache = new Map();
|
@@ -27,6 +27,7 @@ const Preview = ({
|
|
27
27
|
const { token } = theme.useToken();
|
28
28
|
|
29
29
|
const font = useContext(FontContext);
|
30
|
+
const maxZoom = getMaxZoom();
|
30
31
|
|
31
32
|
const containerRef = useRef<HTMLDivElement>(null);
|
32
33
|
const paperRefs = useRef<HTMLDivElement[]>([]);
|
@@ -37,7 +38,7 @@ const Preview = ({
|
|
37
38
|
const [schemasList, setSchemasList] = useState<SchemaForUI[][]>([[]] as SchemaForUI[][]);
|
38
39
|
|
39
40
|
const { backgrounds, pageSizes, scale, error, refresh } =
|
40
|
-
useUIPreProcessor({ template, size, zoomLevel });
|
41
|
+
useUIPreProcessor({ template, size, zoomLevel, maxZoom });
|
41
42
|
|
42
43
|
const isForm = Boolean(onChangeInput);
|
43
44
|
|
@@ -2,7 +2,7 @@ import React, { useEffect, useContext, ReactNode, useRef, useMemo } from 'react'
|
|
2
2
|
import { Dict, Mode, ZOOM, UIRenderProps, SchemaForUI, BasePdf, Schema, Plugin, UIOptions, cloneDeep } from '@pdfme/common';
|
3
3
|
import { theme as antdTheme } from 'antd';
|
4
4
|
import { SELECTABLE_CLASSNAME } from '../constants';
|
5
|
-
import { PluginsRegistry, OptionsContext, I18nContext } from '../contexts';
|
5
|
+
import { PluginsRegistry, OptionsContext, I18nContext, CacheContext } from '../contexts';
|
6
6
|
|
7
7
|
type RendererProps = Omit<
|
8
8
|
UIRenderProps<Schema>,
|
@@ -96,7 +96,7 @@ const Renderer = (props: RendererProps) => {
|
|
96
96
|
|
97
97
|
|
98
98
|
const ref = useRef<HTMLDivElement>(null);
|
99
|
-
const _cache =
|
99
|
+
const _cache = useContext(CacheContext);
|
100
100
|
const plugin = Object.values(pluginsRegistry).find(
|
101
101
|
(plugin) => plugin?.propPanel.defaultSchema.type === schema.type
|
102
102
|
) as Plugin<any>;
|
@@ -133,7 +133,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
|
|
133
133
|
options,
|
134
134
|
theme,
|
135
135
|
i18n,
|
136
|
-
_cache
|
136
|
+
_cache,
|
137
137
|
});
|
138
138
|
}
|
139
139
|
return () => {
|
package/src/contexts.ts
CHANGED
@@ -10,3 +10,5 @@ export const FontContext = createContext(getDefaultFont());
|
|
10
10
|
export const PluginsRegistry = createContext<Plugins>(builtInPlugins);
|
11
11
|
|
12
12
|
export const OptionsContext = createContext<UIOptions>({});
|
13
|
+
|
14
|
+
export const CacheContext = createContext<Map<any, any>>(new Map());
|
package/src/hooks.ts
CHANGED
@@ -19,8 +19,7 @@ import {
|
|
19
19
|
moveCommandToChangeSchemasArg,
|
20
20
|
arrayBufferToBase64,
|
21
21
|
initShortCuts,
|
22
|
-
destroyShortCuts
|
23
|
-
getMaxZoom,
|
22
|
+
destroyShortCuts
|
24
23
|
} from './helper.js';
|
25
24
|
import { RULER_HEIGHT } from './constants.js';
|
26
25
|
|
@@ -36,9 +35,9 @@ export const usePrevious = <T>(value: T) => {
|
|
36
35
|
const getScale = (n: number, paper: number) =>
|
37
36
|
Math.floor((n / paper > 1 ? 1 : n / paper) * 100) / 100;
|
38
37
|
|
39
|
-
type UIPreProcessorProps = { template: Template; size: Size; zoomLevel: number };
|
38
|
+
type UIPreProcessorProps = { template: Template; size: Size; zoomLevel: number; maxZoom: number };
|
40
39
|
|
41
|
-
export const useUIPreProcessor = ({ template, size, zoomLevel }: UIPreProcessorProps) => {
|
40
|
+
export const useUIPreProcessor = ({ template, size, zoomLevel, maxZoom }: UIPreProcessorProps) => {
|
42
41
|
const [backgrounds, setBackgrounds] = useState<string[]>([]);
|
43
42
|
const [pageSizes, setPageSizes] = useState<Size[]>([]);
|
44
43
|
const [scale, setScale] = useState(0);
|
@@ -69,7 +68,7 @@ export const useUIPreProcessor = ({ template, size, zoomLevel }: UIPreProcessorP
|
|
69
68
|
|
70
69
|
const [_pages, imgBuffers] = await Promise.all([
|
71
70
|
pdf2size(b64toUint8Array(_basePdf)),
|
72
|
-
pdf2img(b64toUint8Array(_basePdf), { scale:
|
71
|
+
pdf2img(b64toUint8Array(_basePdf), { scale: maxZoom }),
|
73
72
|
]);
|
74
73
|
|
75
74
|
_pageSizes = _pages;
|