@pdfme/ui 5.2.14 → 5.2.16-dev.1

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.
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { UIRenderProps, SchemaForUI, BasePdf, Schema } from '@pdfme/common';
2
+ import { Mode, UIRenderProps, SchemaForUI, BasePdf, Schema, Plugin, UIOptions } from '@pdfme/common';
3
3
  type RendererProps = Omit<UIRenderProps<Schema>, 'schema' | 'rootElement' | 'options' | 'theme' | 'i18n' | 'pdfJs' | '_cache'> & {
4
4
  basePdf: BasePdf;
5
5
  schema: SchemaForUI;
@@ -9,5 +9,14 @@ type RendererProps = Omit<UIRenderProps<Schema>, 'schema' | 'rootElement' | 'opt
9
9
  scale: number;
10
10
  selectable?: boolean;
11
11
  };
12
+ type ReRenderCheckProps = {
13
+ plugin: Plugin<any>;
14
+ value: string;
15
+ mode: Mode;
16
+ scale: number;
17
+ schema: SchemaForUI;
18
+ options: UIOptions;
19
+ };
20
+ export declare const useRerenderDependencies: (arg: ReRenderCheckProps) => (string | number)[];
12
21
  declare const Renderer: (props: RendererProps) => React.JSX.Element;
13
22
  export default Renderer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/ui",
3
- "version": "5.2.14",
3
+ "version": "5.2.16-dev.1",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
@@ -1,5 +1,5 @@
1
- import React, { useEffect, useMemo, useContext, ReactNode, useRef } from 'react';
2
- import { Dict, Mode, ZOOM, UIRenderProps, SchemaForUI, BasePdf, Schema, Plugin, UIOptions } from '@pdfme/common';
1
+ import React, { useEffect, useContext, ReactNode, useRef, useMemo } from 'react';
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
5
  import { PluginsRegistry, OptionsContext, I18nContext } from '../contexts';
@@ -27,18 +27,26 @@ type ReRenderCheckProps = {
27
27
  options: UIOptions,
28
28
  }
29
29
 
30
- const useRerenderDependencies = ({ plugin, value, mode, scale, schema, options }: ReRenderCheckProps) => {
31
- const dependencies = useMemo(() => {
30
+ export const useRerenderDependencies = (arg: ReRenderCheckProps) => {
31
+ const { plugin, value, mode, scale, schema, options } = arg;
32
+ const _options = cloneDeep(options);
33
+ if (_options.font) {
34
+ Object.values(_options.font).forEach((fontObj) => {
35
+ (fontObj as { data: string }).data = '...';
36
+ });
37
+ }
38
+ const optionStr = JSON.stringify(_options);
39
+
40
+ return useMemo(() => {
32
41
  if (plugin.uninterruptedEditMode && mode === 'designer') {
33
42
  return [mode];
34
43
  } else {
35
- return [value, mode, scale, JSON.stringify(schema), JSON.stringify(options)];
44
+ return [value, mode, scale, JSON.stringify(schema), optionStr];
36
45
  }
37
- }, [value, mode, scale, schema, options]);
38
-
39
- return dependencies;
46
+ }, [plugin.uninterruptedEditMode, value, mode, scale, schema, optionStr]);
40
47
  };
41
48
 
49
+
42
50
  const Wrapper = ({
43
51
  children,
44
52
  outline,
@@ -79,13 +87,14 @@ const Wrapper = ({
79
87
  );
80
88
 
81
89
  const Renderer = (props: RendererProps) => {
90
+ const { schema, basePdf, value, mode, onChange, stopEditing, tabIndex, placeholder, scale } =
91
+ props;
92
+
82
93
  const pluginsRegistry = useContext(PluginsRegistry);
83
94
  const options = useContext(OptionsContext);
84
95
  const i18n = useContext(I18nContext) as (key: keyof Dict | string) => string;
85
96
  const { token: theme } = antdTheme.useToken();
86
97
 
87
- const { schema, basePdf, value, mode, onChange, stopEditing, tabIndex, placeholder, scale } =
88
- props;
89
98
 
90
99
  const ref = useRef<HTMLDivElement>(null);
91
100
  const _cache = useRef<Map<any, any>>(new Map());
@@ -93,14 +102,14 @@ const Renderer = (props: RendererProps) => {
93
102
  (plugin) => plugin?.propPanel.defaultSchema.type === schema.type
94
103
  ) as Plugin<any>;
95
104
 
105
+ const reRenderDependencies = useRerenderDependencies({ plugin, value, mode, scale, schema, options });
106
+
96
107
  if (!plugin || !plugin.ui) {
97
108
  console.error(`[@pdfme/ui] Renderer for type ${schema.type} not found.
98
109
  Check this document: https://pdfme.com/docs/custom-schemas`);
99
110
  return <></>;
100
111
  }
101
112
 
102
- const reRenderDependencies = useRerenderDependencies({ plugin, value, mode, scale, schema, options });
103
-
104
113
  useEffect(() => {
105
114
  if (ref.current && schema.type) {
106
115
  ref.current.innerHTML = '';