@pdfme/ui 5.3.3-dev.3 → 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.
@@ -10,7 +10,7 @@ export declare abstract class BaseUIClass {
10
10
  private readonly setSize;
11
11
  resizeObserver: ResizeObserver;
12
12
  constructor(props: UIProps);
13
- protected getLang(): "en" | "pl" | "zh" | "ja" | "ko" | "ar" | "th" | "it" | "de" | "es" | "fr";
13
+ protected getLang(): "en" | "zh" | "ja" | "ko" | "ar" | "th" | "pl" | "it" | "de" | "es" | "fr";
14
14
  protected getFont(): Record<string, {
15
15
  data: string | ArrayBuffer | Uint8Array;
16
16
  fallback?: boolean | undefined;
@@ -6,4 +6,4 @@ export declare const PAGE_GAP = 10;
6
6
  export declare const LEFT_SIDEBAR_WIDTH = 45;
7
7
  export declare const RIGHT_SIDEBAR_WIDTH = 400;
8
8
  export declare const BACKGROUND_COLOR = "rgb(74, 74, 74)";
9
- export declare const MAX_ZOOM = 2;
9
+ export declare const DEFAULT_MAX_ZOOM = 2;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { Plugins, UIOptions } from '@pdfme/common';
3
- export declare const I18nContext: import("react").Context<(key: "type" | "width" | "height" | "rotate" | "opacity" | "required" | "cancel" | "close" | "set" | "clear" | "field" | "fieldName" | "align" | "edit" | "editable" | "plsInputName" | "fieldMustUniq" | "notUniq" | "noKeyName" | "fieldsList" | "editField" | "errorOccurred" | "errorBulkUpdateFieldName" | "commitBulkUpdateFieldName" | "bulkUpdateFieldName" | "addPageAfter" | "removePage" | "removePageConfirm" | "validation.uniqueName" | "validation.hexColor" | "validation.dateTimeFormat" | "schemas.color" | "schemas.borderWidth" | "schemas.borderColor" | "schemas.backgroundColor" | "schemas.textColor" | "schemas.bgColor" | "schemas.horizontal" | "schemas.vertical" | "schemas.left" | "schemas.center" | "schemas.right" | "schemas.top" | "schemas.middle" | "schemas.bottom" | "schemas.padding" | "schemas.text.fontName" | "schemas.text.size" | "schemas.text.spacing" | "schemas.text.textAlign" | "schemas.text.verticalAlign" | "schemas.text.lineHeight" | "schemas.text.min" | "schemas.text.max" | "schemas.text.fit" | "schemas.text.dynamicFontSize" | "schemas.text.format" | "schemas.mvt.typingInstructions" | "schemas.mvt.sampleField" | "schemas.mvt.variablesSampleData" | "schemas.barcodes.barColor" | "schemas.barcodes.includetext" | "schemas.table.alternateBackgroundColor" | "schemas.table.tableStyle" | "schemas.table.showHead" | "schemas.table.headStyle" | "schemas.table.bodyStyle" | "schemas.table.columnStyle" | "schemas.date.format" | "schemas.date.locale" | "schemas.select.options" | "schemas.select.optionPlaceholder" | "schemas.radioGroup.groupName", dict?: {
3
+ export declare const I18nContext: import("react").Context<(key: "cancel" | "close" | "set" | "clear" | "field" | "fieldName" | "align" | "width" | "opacity" | "height" | "rotate" | "edit" | "required" | "editable" | "plsInputName" | "fieldMustUniq" | "notUniq" | "noKeyName" | "fieldsList" | "editField" | "type" | "errorOccurred" | "errorBulkUpdateFieldName" | "commitBulkUpdateFieldName" | "bulkUpdateFieldName" | "addPageAfter" | "removePage" | "removePageConfirm" | "validation.uniqueName" | "validation.hexColor" | "validation.dateTimeFormat" | "schemas.color" | "schemas.borderWidth" | "schemas.borderColor" | "schemas.backgroundColor" | "schemas.textColor" | "schemas.bgColor" | "schemas.horizontal" | "schemas.vertical" | "schemas.left" | "schemas.center" | "schemas.right" | "schemas.top" | "schemas.middle" | "schemas.bottom" | "schemas.padding" | "schemas.text.fontName" | "schemas.text.size" | "schemas.text.spacing" | "schemas.text.textAlign" | "schemas.text.verticalAlign" | "schemas.text.lineHeight" | "schemas.text.min" | "schemas.text.max" | "schemas.text.fit" | "schemas.text.dynamicFontSize" | "schemas.text.format" | "schemas.mvt.typingInstructions" | "schemas.mvt.sampleField" | "schemas.mvt.variablesSampleData" | "schemas.barcodes.barColor" | "schemas.barcodes.includetext" | "schemas.table.alternateBackgroundColor" | "schemas.table.tableStyle" | "schemas.table.showHead" | "schemas.table.headStyle" | "schemas.table.bodyStyle" | "schemas.table.columnStyle" | "schemas.date.format" | "schemas.date.locale" | "schemas.select.options" | "schemas.select.optionPlaceholder" | "schemas.radioGroup.groupName", dict?: {
4
4
  cancel: string;
5
5
  close: string;
6
6
  set: string;
@@ -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>>;
@@ -72,4 +72,5 @@ export declare const changeSchemas: (args: {
72
72
  };
73
73
  commitSchemas: (newSchemas: SchemaForUI[]) => void;
74
74
  }) => void;
75
+ export declare const getMaxZoom: () => number;
75
76
  export {};
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/ui",
3
- "version": "5.3.3-dev.3",
3
+ "version": "5.3.3-dev.5",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
@@ -5,7 +5,7 @@ import { Plus, Minus, ChevronLeft, ChevronRight, Ellipsis } from 'lucide-react';
5
5
  import type { MenuProps } from 'antd';
6
6
  import { theme, Typography, Button, Dropdown } from 'antd';
7
7
  import { I18nContext } from '../contexts';
8
- import { MAX_ZOOM } from '../constants';
8
+ import { getMaxZoom } from "../helper";
9
9
 
10
10
  const { Text } = Typography;
11
11
 
@@ -18,7 +18,7 @@ type ZoomProps = {
18
18
 
19
19
  const Zoom = ({ zoomLevel, setZoomLevel, style }: ZoomProps) => {
20
20
  const zoomStep = 0.25;
21
- const maxZoom = MAX_ZOOM;
21
+ const maxZoom = getMaxZoom();
22
22
  const minZoom = 0.25;
23
23
 
24
24
  const nextZoomOut = zoomLevel - zoomStep;
@@ -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 = useRef<Map<any, any>>(new Map());
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: _cache.current,
136
+ _cache,
137
137
  });
138
138
  }
139
139
  return () => {
package/src/constants.ts CHANGED
@@ -14,4 +14,4 @@ export const RIGHT_SIDEBAR_WIDTH = 400;
14
14
 
15
15
  export const BACKGROUND_COLOR = 'rgb(74, 74, 74)';
16
16
 
17
- export const MAX_ZOOM = 2;
17
+ export const DEFAULT_MAX_ZOOM = 2;
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/helper.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import hotkeys from 'hotkeys-js';
2
+ import { useContext } from 'react';
2
3
  import {
3
4
  cloneDeep,
4
5
  ZOOM,
@@ -12,7 +13,8 @@ import {
12
13
  Plugins,
13
14
  } from '@pdfme/common';
14
15
  import { pdf2size } from '@pdfme/converter';
15
- import { RULER_HEIGHT } from './constants.js';
16
+ import { DEFAULT_MAX_ZOOM, RULER_HEIGHT } from './constants.js';
17
+ import { OptionsContext } from './contexts';
16
18
 
17
19
  export const uuid = () =>
18
20
  'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
@@ -469,3 +471,9 @@ export const changeSchemas = (args: {
469
471
  }, cloneDeep(schemas));
470
472
  commitSchemas(newSchemas);
471
473
  };
474
+
475
+ export const getMaxZoom = () => {
476
+ const options = useContext(OptionsContext);
477
+
478
+ return options.maxZoom ? (options.maxZoom as number) / 100 : DEFAULT_MAX_ZOOM;
479
+ }
package/src/hooks.ts CHANGED
@@ -19,9 +19,9 @@ import {
19
19
  moveCommandToChangeSchemasArg,
20
20
  arrayBufferToBase64,
21
21
  initShortCuts,
22
- destroyShortCuts,
22
+ destroyShortCuts
23
23
  } from './helper.js';
24
- import { RULER_HEIGHT, MAX_ZOOM } from './constants.js';
24
+ import { RULER_HEIGHT } from './constants.js';
25
25
 
26
26
  export const usePrevious = <T>(value: T) => {
27
27
  const ref = useRef<T | null>(null);
@@ -35,9 +35,9 @@ export const usePrevious = <T>(value: T) => {
35
35
  const getScale = (n: number, paper: number) =>
36
36
  Math.floor((n / paper > 1 ? 1 : n / paper) * 100) / 100;
37
37
 
38
- type UIPreProcessorProps = { template: Template; size: Size; zoomLevel: number };
38
+ type UIPreProcessorProps = { template: Template; size: Size; zoomLevel: number; maxZoom: number };
39
39
 
40
- export const useUIPreProcessor = ({ template, size, zoomLevel }: UIPreProcessorProps) => {
40
+ export const useUIPreProcessor = ({ template, size, zoomLevel, maxZoom }: UIPreProcessorProps) => {
41
41
  const [backgrounds, setBackgrounds] = useState<string[]>([]);
42
42
  const [pageSizes, setPageSizes] = useState<Size[]>([]);
43
43
  const [scale, setScale] = useState(0);
@@ -68,7 +68,7 @@ export const useUIPreProcessor = ({ template, size, zoomLevel }: UIPreProcessorP
68
68
 
69
69
  const [_pages, imgBuffers] = await Promise.all([
70
70
  pdf2size(b64toUint8Array(_basePdf)),
71
- pdf2img(b64toUint8Array(_basePdf), { scale: MAX_ZOOM }),
71
+ pdf2img(b64toUint8Array(_basePdf), { scale: maxZoom }),
72
72
  ]);
73
73
 
74
74
  _pageSizes = _pages;