@pdfme/ui 5.3.19 → 5.4.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +3834 -3828
- package/dist/index.umd.js +113 -113
- package/package.json +2 -2
- package/src/components/Designer/index.tsx +15 -3
- package/src/components/Preview.tsx +12 -2
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pdfme/ui",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.4.0-dev.2",
|
4
4
|
"sideEffects": false,
|
5
5
|
"author": "hand-dot",
|
6
6
|
"license": "MIT",
|
@@ -68,7 +68,7 @@
|
|
68
68
|
"is-path-inside": "^4.0.0",
|
69
69
|
"jest-canvas-mock": "^2.3.1",
|
70
70
|
"jest-environment-jsdom": "^29.7.0",
|
71
|
-
"postcss": "^8.5.
|
71
|
+
"postcss": "^8.5.4",
|
72
72
|
"process": "^0.11.10",
|
73
73
|
"rollup": "^4.40.2",
|
74
74
|
"vite": "^6.3.5",
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { useRef, useState, useContext, useCallback } from 'react';
|
1
|
+
import React, { useRef, useState, useContext, useCallback, useEffect } from 'react';
|
2
2
|
import {
|
3
3
|
cloneDeep,
|
4
4
|
ZOOM,
|
@@ -70,8 +70,8 @@ const TemplateEditor = ({
|
|
70
70
|
const [activeElements, setActiveElements] = useState<HTMLElement[]>([]);
|
71
71
|
const [schemasList, setSchemasList] = useState<SchemaForUI[][]>([[]] as SchemaForUI[][]);
|
72
72
|
const [pageCursor, setPageCursor] = useState(0);
|
73
|
-
const [zoomLevel, setZoomLevel] = useState(1);
|
74
|
-
const [sidebarOpen, setSidebarOpen] = useState(true);
|
73
|
+
const [zoomLevel, setZoomLevel] = useState(options.zoomLevel ?? 1);
|
74
|
+
const [sidebarOpen, setSidebarOpen] = useState(options.sidebarOpen ?? true);
|
75
75
|
const [prevTemplate, setPrevTemplate] = useState<Template | null>(null);
|
76
76
|
|
77
77
|
const { backgrounds, pageSizes, scale, error, refresh } = useUIPreProcessor({
|
@@ -91,6 +91,18 @@ const TemplateEditor = ({
|
|
91
91
|
setHoveringSchemaId(null);
|
92
92
|
};
|
93
93
|
|
94
|
+
// Update component state only when _options_ changes
|
95
|
+
// Ignore exhaustive useEffect dependency warnings here
|
96
|
+
useEffect(() => {
|
97
|
+
if (typeof options.zoomLevel === 'number' && options.zoomLevel !== zoomLevel) {
|
98
|
+
setZoomLevel(options.zoomLevel);
|
99
|
+
}
|
100
|
+
if (typeof options.sidebarOpen === 'boolean' && options.sidebarOpen !== sidebarOpen) {
|
101
|
+
setSidebarOpen(options.sidebarOpen);
|
102
|
+
}
|
103
|
+
// eslint-disable-next-line
|
104
|
+
}, [options]);
|
105
|
+
|
94
106
|
useScrollPageCursor({
|
95
107
|
ref: canvasRef,
|
96
108
|
pageSizes,
|
@@ -16,7 +16,7 @@ import CtlBar from './CtlBar.js';
|
|
16
16
|
import Paper from './Paper.js';
|
17
17
|
import Renderer from './Renderer.js';
|
18
18
|
import { useUIPreProcessor, useScrollPageCursor } from '../hooks.js';
|
19
|
-
import { FontContext } from '../contexts.js';
|
19
|
+
import { FontContext, OptionsContext } from '../contexts.js';
|
20
20
|
import { template2SchemasList, getPagesScrollTopByIndex, useMaxZoom } from '../helper.js';
|
21
21
|
import { theme } from 'antd';
|
22
22
|
|
@@ -34,6 +34,7 @@ const Preview = ({
|
|
34
34
|
const { token } = theme.useToken();
|
35
35
|
|
36
36
|
const font = useContext(FontContext);
|
37
|
+
const options = useContext(OptionsContext);
|
37
38
|
const maxZoom = useMaxZoom();
|
38
39
|
|
39
40
|
const containerRef = useRef<HTMLDivElement>(null);
|
@@ -41,7 +42,7 @@ const Preview = ({
|
|
41
42
|
|
42
43
|
const [unitCursor, setUnitCursor] = useState(0);
|
43
44
|
const [pageCursor, setPageCursor] = useState(0);
|
44
|
-
const [zoomLevel, setZoomLevel] = useState(1);
|
45
|
+
const [zoomLevel, setZoomLevel] = useState(options.zoomLevel ?? 1);
|
45
46
|
const [schemasList, setSchemasList] = useState<SchemaForUI[][]>([[]] as SchemaForUI[][]);
|
46
47
|
|
47
48
|
const { backgrounds, pageSizes, scale, error, refresh } = useUIPreProcessor({
|
@@ -79,6 +80,15 @@ const Preview = ({
|
|
79
80
|
.catch((err) => console.error(`[@pdfme/ui] `, err));
|
80
81
|
};
|
81
82
|
|
83
|
+
// Update component state only when _options_ changes
|
84
|
+
// Ignore exhaustive useEffect dependency warnings here
|
85
|
+
useEffect(() => {
|
86
|
+
if (typeof options.zoomLevel === 'number' && options.zoomLevel !== zoomLevel) {
|
87
|
+
setZoomLevel(options.zoomLevel);
|
88
|
+
}
|
89
|
+
// eslint-disable-next-line
|
90
|
+
}, [options]);
|
91
|
+
|
82
92
|
useEffect(() => {
|
83
93
|
if (unitCursor > inputs.length - 1) {
|
84
94
|
setUnitCursor(inputs.length - 1);
|