@pdfme/ui 5.3.11-dev.9 → 5.3.12-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.
- package/dist/index.es.js +8359 -8310
- package/dist/index.umd.js +114 -114
- package/dist/types/src/contexts.d.ts +1 -1
- package/package.json +3 -3
- package/src/components/AppContextProvider.tsx +8 -2
- package/src/components/Designer/Canvas/Moveable.tsx +8 -4
- package/src/components/Designer/Canvas/Selecto.tsx +4 -1
- package/src/components/Designer/Canvas/index.tsx +50 -18
- package/src/components/Designer/PluginIcon.tsx +10 -9
- package/src/components/Designer/RightSidebar/DetailView/AlignWidget.tsx +77 -66
- package/src/components/Designer/RightSidebar/DetailView/ButtonGroupWidget.tsx +5 -6
- package/src/components/Designer/RightSidebar/DetailView/index.tsx +147 -68
- package/src/components/Designer/RightSidebar/ListView/Item.tsx +89 -91
- package/src/components/Designer/RightSidebar/ListView/SelectableSortableContainer.tsx +18 -17
- package/src/components/Designer/RightSidebar/ListView/SelectableSortableItem.tsx +16 -15
- package/src/components/Designer/index.tsx +1 -1
- package/src/components/Preview.tsx +1 -1
- package/src/components/Renderer.tsx +2 -2
- package/src/contexts.ts +1 -1
- package/src/helper.ts +34 -29
@@ -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/contexts.ts
CHANGED
@@ -11,4 +11,4 @@ export const PluginsRegistry = createContext<Plugins>(builtInPlugins);
|
|
11
11
|
|
12
12
|
export const OptionsContext = createContext<UIOptions>({});
|
13
13
|
|
14
|
-
export const CacheContext = createContext<Map<
|
14
|
+
export const CacheContext = createContext<Map<string | number, unknown>>(new Map());
|
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) =>
|
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 (
|
493
|
-
|
494
|
-
|
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 (
|
499
|
-
|
500
|
-
|
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
|
-
|
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;
|