@pdfme/ui 5.3.11-dev.12 → 5.3.11-dev.14

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.
@@ -62,27 +62,28 @@ const SelectableSortableContainer = (
62
62
  // Get schema by ID or use directly
63
63
  const thisSchema =
64
64
  typeof inSchema === 'string' ? schemas.find((schema) => schema.id === inSchema) : inSchema;
65
-
65
+
66
66
  if (!thisSchema) return <></>;
67
-
67
+
68
68
  // Safely extract schema type
69
69
  const schemaType = typeof thisSchema.type === 'string' ? thisSchema.type : '';
70
-
70
+
71
71
  // Find matching plugin with type-safe approach
72
- const pluginEntry = Object.entries(pluginsRegistry).find(
73
- ([, plugin]) => {
74
- if (!plugin || typeof plugin !== 'object') return false;
75
- if (!plugin.propPanel || typeof plugin.propPanel !== 'object') return false;
76
- if (!plugin.propPanel.defaultSchema || typeof plugin.propPanel.defaultSchema !== 'object') return false;
77
-
78
- // Use Record<string, unknown> to safely access properties
79
- const defaultSchema = plugin.propPanel.defaultSchema as Record<string, unknown>;
80
- return 'type' in defaultSchema &&
81
- typeof defaultSchema.type === 'string' &&
82
- defaultSchema.type === schemaType;
83
- }
84
- );
85
-
72
+ const pluginEntry = Object.entries(pluginsRegistry).find(([, plugin]) => {
73
+ if (!plugin || typeof plugin !== 'object') return false;
74
+ if (!plugin.propPanel || typeof plugin.propPanel !== 'object') return false;
75
+ if (!plugin.propPanel.defaultSchema || typeof plugin.propPanel.defaultSchema !== 'object')
76
+ return false;
77
+
78
+ // Use Record<string, unknown> to safely access properties
79
+ const defaultSchema = plugin.propPanel.defaultSchema as Record<string, unknown>;
80
+ return (
81
+ 'type' in defaultSchema &&
82
+ typeof defaultSchema.type === 'string' &&
83
+ defaultSchema.type === schemaType
84
+ );
85
+ });
86
+
86
87
  const [pluginLabel, activePlugin] = pluginEntry || ['', undefined];
87
88
 
88
89
  if (!activePlugin) {
@@ -44,22 +44,23 @@ const SelectableSortableItem = ({
44
44
 
45
45
  // Safely extract schema type
46
46
  const schemaType = typeof schema.type === 'string' ? schema.type : '';
47
-
47
+
48
48
  // Find matching plugin with type-safe approach
49
- const pluginEntry = Object.entries(pluginsRegistry).find(
50
- ([, plugin]) => {
51
- if (!plugin || typeof plugin !== 'object') return false;
52
- if (!plugin.propPanel || typeof plugin.propPanel !== 'object') return false;
53
- if (!plugin.propPanel.defaultSchema || typeof plugin.propPanel.defaultSchema !== 'object') return false;
54
-
55
- // Use Record<string, unknown> to safely access properties
56
- const defaultSchema = plugin.propPanel.defaultSchema as Record<string, unknown>;
57
- return 'type' in defaultSchema &&
58
- typeof defaultSchema.type === 'string' &&
59
- defaultSchema.type === schemaType;
60
- }
61
- );
62
-
49
+ const pluginEntry = Object.entries(pluginsRegistry).find(([, plugin]) => {
50
+ if (!plugin || typeof plugin !== 'object') return false;
51
+ if (!plugin.propPanel || typeof plugin.propPanel !== 'object') return false;
52
+ if (!plugin.propPanel.defaultSchema || typeof plugin.propPanel.defaultSchema !== 'object')
53
+ return false;
54
+
55
+ // Use Record<string, unknown> to safely access properties
56
+ const defaultSchema = plugin.propPanel.defaultSchema as Record<string, unknown>;
57
+ return (
58
+ 'type' in defaultSchema &&
59
+ typeof defaultSchema.type === 'string' &&
60
+ defaultSchema.type === schemaType
61
+ );
62
+ });
63
+
63
64
  const [pluginLabel, thisPlugin] = pluginEntry || ['', undefined];
64
65
 
65
66
  let status: undefined | 'is-warning' | 'is-danger';
@@ -227,7 +227,7 @@ const TemplateEditor = ({
227
227
  onChangeTemplate(newTemplate);
228
228
  await updateTemplate(newTemplate);
229
229
  void refresh(newTemplate);
230
-
230
+
231
231
  // Use setTimeout to update scroll position after render
232
232
  setTimeout(() => {
233
233
  if (canvasRef.current) {
@@ -129,10 +129,10 @@ const Renderer = (props: RendererProps) => {
129
129
 
130
130
  useEffect(() => {
131
131
  if (!plugin?.ui || !ref.current || !schema.type) return;
132
-
132
+
133
133
  ref.current.innerHTML = '';
134
134
  const render = plugin.ui;
135
-
135
+
136
136
  void render({
137
137
  value,
138
138
  schema,
package/src/helper.ts CHANGED
@@ -48,7 +48,6 @@ export const uuid = () =>
48
48
  return v.toString(16);
49
49
  });
50
50
 
51
-
52
51
  const set = <T extends object>(obj: T, path: string | string[], value: unknown) => {
53
52
  path = Array.isArray(path) ? path : path.replace('[', '.').replace(']', '').split('.');
54
53
  let src: Record<string, unknown> = obj as Record<string, unknown>;
@@ -436,7 +435,8 @@ const handlePositionSizeChange = (
436
435
  const padding = isBlankPdf(basePdf) ? basePdf.padding : [0, 0, 0, 0];
437
436
  const [pt, pr, pb, pl] = padding;
438
437
  const { width: pw, height: ph } = pageSize;
439
- const calcBounds = (v: unknown, min: number, max: number) => Math.min(Math.max(Number(v), min), max);
438
+ const calcBounds = (v: unknown, min: number, max: number) =>
439
+ Math.min(Math.max(Number(v), min), max);
440
440
  if (key === 'position.x') {
441
441
  schema.position.x = calcBounds(value, pl, pw - schema.width - pr);
442
442
  } else if (key === 'position.y') {
@@ -464,79 +464,84 @@ const handleTypeChange = (
464
464
  // Apply attributes from new defaultSchema
465
465
  // Find the plugin with matching type
466
466
  const pluginValue = value as string;
467
-
467
+
468
468
  // Define a type-safe approach to find the matching plugin
469
469
  interface PluginSchema {
470
470
  type: string;
471
471
  [key: string]: unknown;
472
472
  }
473
-
473
+
474
474
  interface PluginType {
475
475
  propPanel: {
476
476
  defaultSchema: PluginSchema;
477
477
  };
478
478
  }
479
-
479
+
480
480
  // Initialize plugin as undefined
481
481
  let plugin: PluginType | undefined;
482
-
482
+
483
483
  // Safely iterate through plugins to find one with matching type
484
484
  const pluginEntries = Object.entries(pluginsRegistry);
485
485
  for (let i = 0; i < pluginEntries.length; i++) {
486
486
  const [, pluginObj] = pluginEntries[i];
487
-
487
+
488
488
  // Skip invalid plugins
489
489
  if (!pluginObj || typeof pluginObj !== 'object') continue;
490
-
490
+
491
491
  // Check if propPanel exists and is an object
492
- if (!('propPanel' in pluginObj) ||
493
- !pluginObj.propPanel ||
494
- typeof pluginObj.propPanel !== 'object') continue;
495
-
492
+ if (
493
+ !('propPanel' in pluginObj) ||
494
+ !pluginObj.propPanel ||
495
+ typeof pluginObj.propPanel !== 'object'
496
+ )
497
+ continue;
498
+
496
499
  // Check if defaultSchema exists and is an object
497
500
  const propPanel = pluginObj.propPanel as { defaultSchema?: unknown };
498
- if (!('defaultSchema' in propPanel) ||
499
- !propPanel.defaultSchema ||
500
- typeof propPanel.defaultSchema !== 'object') continue;
501
-
501
+ if (
502
+ !('defaultSchema' in propPanel) ||
503
+ !propPanel.defaultSchema ||
504
+ typeof propPanel.defaultSchema !== 'object'
505
+ )
506
+ continue;
507
+
502
508
  // Safely check if type property exists and matches
503
509
  const defaultSchema = propPanel.defaultSchema as Record<string, unknown>;
504
- if (!('type' in defaultSchema) ||
505
- typeof defaultSchema.type !== 'string') continue;
506
-
510
+ if (!('type' in defaultSchema) || typeof defaultSchema.type !== 'string') continue;
511
+
507
512
  // Check if the type matches
508
513
  const schemaType = defaultSchema.type;
509
514
  if (schemaType === pluginValue) {
510
515
  // Create a type-safe copy of the plugin
511
516
  const safeSchema: PluginSchema = {
512
- type: schemaType
517
+ type: schemaType,
513
518
  };
514
-
519
+
515
520
  // Copy other properties safely
516
- Object.keys(defaultSchema).forEach(key => {
521
+ Object.keys(defaultSchema).forEach((key) => {
517
522
  if (key !== 'type' && Object.prototype.hasOwnProperty.call(defaultSchema, key)) {
518
523
  safeSchema[key] = defaultSchema[key];
519
524
  }
520
525
  });
521
-
526
+
522
527
  // Found matching plugin with proper typing
523
528
  plugin = {
524
529
  propPanel: {
525
- defaultSchema: safeSchema
526
- }
530
+ defaultSchema: safeSchema,
531
+ },
527
532
  };
528
533
  break;
529
534
  }
530
535
  }
531
-
536
+
532
537
  const propPanel = plugin?.propPanel;
533
-
538
+
534
539
  // Apply default schema properties if available
535
540
  if (propPanel?.defaultSchema) {
536
541
  // Create a type-safe copy of the default schema
537
542
  const defaultSchema = propPanel.defaultSchema;
538
543
  const schemaRecord = schema as Record<string, unknown>;
539
-
544
+
540
545
  // Use a type-safe approach to copy properties
541
546
  for (const key of Object.keys(defaultSchema)) {
542
547
  // Only add properties that don't already exist in the schema
@@ -545,7 +550,7 @@ const handleTypeChange = (
545
550
  if (Object.prototype.hasOwnProperty.call(defaultSchema, key)) {
546
551
  // Get the property value safely
547
552
  const propertyValue = defaultSchema[key];
548
-
553
+
549
554
  // Only assign if the value is defined
550
555
  if (propertyValue !== undefined) {
551
556
  schemaRecord[key] = propertyValue;