@pdfme/ui 6.1.13-dev.27 → 6.1.13-dev.35
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/Designer.d.ts +5 -1
- package/dist/class.d.ts +2 -2
- package/dist/components/Designer/index.d.ts +5 -4
- package/dist/contexts.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +88 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/Designer.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Template, DesignerProps } from '@pdfme/common';
|
|
2
2
|
import { BaseUIClass } from './class.js';
|
|
3
3
|
import { type DesignerSelectSchemasOptions, type DesignerSchemaSelectionTarget, type DesignerSelectedSchema, type DesignerSelection, type DesignerSelectionChangeCallback } from './designerSelection.js';
|
|
4
|
+
export type DesignerUpdateTemplateOptions = {
|
|
5
|
+
page?: number;
|
|
6
|
+
};
|
|
4
7
|
declare class Designer extends BaseUIClass {
|
|
5
8
|
private onSaveTemplateCallback?;
|
|
6
9
|
private onChangeTemplateCallback?;
|
|
@@ -9,9 +12,10 @@ declare class Designer extends BaseUIClass {
|
|
|
9
12
|
private pageCursor;
|
|
10
13
|
private selection;
|
|
11
14
|
private selectSchemasHandler;
|
|
15
|
+
private updateTemplatePage?;
|
|
12
16
|
constructor(props: DesignerProps);
|
|
13
17
|
saveTemplate(): void;
|
|
14
|
-
updateTemplate(template: Template): void;
|
|
18
|
+
updateTemplate(template: Template, options?: DesignerUpdateTemplateOptions): void;
|
|
15
19
|
onSaveTemplate(cb: (template: Template) => void): void;
|
|
16
20
|
onChangeTemplate(cb: (template: Template) => void): void;
|
|
17
21
|
onPageChange(cb: (pageInfo: {
|
package/dist/class.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare abstract class BaseUIClass {
|
|
|
14
14
|
constructor(props: UIProps);
|
|
15
15
|
protected getLang(): "ar" | "de" | "en" | "es" | "fr" | "it" | "ja" | "ko" | "pl" | "th" | "tr" | "zh" | "zh-TW";
|
|
16
16
|
protected getFont(): Record<string, {
|
|
17
|
-
data: string | ArrayBuffer |
|
|
17
|
+
data: string | ArrayBuffer | import("@pdfme/common").PdfBytes;
|
|
18
18
|
fallback?: boolean | undefined;
|
|
19
19
|
subset?: boolean | undefined;
|
|
20
20
|
}>;
|
|
@@ -44,7 +44,7 @@ export declare abstract class BaseUIClass {
|
|
|
44
44
|
} | undefined;
|
|
45
45
|
__isSplit?: boolean | undefined;
|
|
46
46
|
}[][];
|
|
47
|
-
basePdf: string | ArrayBuffer |
|
|
47
|
+
basePdf: string | ArrayBuffer | import("@pdfme/common").PdfBytes | {
|
|
48
48
|
width: number;
|
|
49
49
|
height: number;
|
|
50
50
|
padding: [number, number, number, number];
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Template, DesignerProps, Size } from '@pdfme/common';
|
|
3
3
|
import { type DesignerSelectSchemas, type DesignerSelection } from '../../designerSelection.js';
|
|
4
|
-
|
|
4
|
+
type TemplateEditorProps = Omit<DesignerProps, 'domContainer'> & {
|
|
5
5
|
size: Size;
|
|
6
6
|
onSaveTemplate: (t: Template) => void;
|
|
7
7
|
onChangeTemplate: (t: Template) => void;
|
|
8
8
|
onChangeSelection?: (selection: DesignerSelection) => void;
|
|
9
9
|
onRegisterSchemaSelectionHandler?: (handler: DesignerSelectSchemas | null) => void;
|
|
10
|
-
|
|
11
|
-
onChangeTemplate: (t: Template) => void;
|
|
10
|
+
onUpdateTemplatePageApplied?: (page: number) => void;
|
|
12
11
|
onPageCursorChange: (newPageCursor: number, totalPages: number) => void;
|
|
13
|
-
|
|
12
|
+
updateTemplatePage?: number;
|
|
13
|
+
};
|
|
14
|
+
declare const TemplateEditor: ({ template, size, onSaveTemplate, onChangeTemplate, onPageCursorChange, onChangeSelection, onRegisterSchemaSelectionHandler, onUpdateTemplatePageApplied, updateTemplatePage, }: TemplateEditorProps) => React.JSX.Element;
|
|
14
15
|
export default TemplateEditor;
|
package/dist/contexts.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { i18n } from './i18n.js';
|
|
|
2
2
|
import { PluginRegistry, UIOptions } from '@pdfme/common';
|
|
3
3
|
export declare const I18nContext: import("react").Context<typeof i18n>;
|
|
4
4
|
export declare const FontContext: import("react").Context<Record<string, {
|
|
5
|
-
data: string | ArrayBuffer |
|
|
5
|
+
data: string | ArrayBuffer | import("@pdfme/common").PdfBytes;
|
|
6
6
|
fallback?: boolean | undefined;
|
|
7
7
|
subset?: boolean | undefined;
|
|
8
8
|
}>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ import Designer from './Designer.js';
|
|
|
2
2
|
import Form from './Form.js';
|
|
3
3
|
import Viewer from './Viewer.js';
|
|
4
4
|
export { Designer, Viewer, Form };
|
|
5
|
+
export type { DesignerUpdateTemplateOptions } from './Designer.js';
|
|
5
6
|
export type { DesignerSchemaSelectionTarget, DesignerSelectSchemas, DesignerSelectSchemasOptions, DesignerSelectedSchema, DesignerSelection, DesignerSelectionBounds, DesignerSelectionChangeCallback, } from './designerSelection.js';
|
package/dist/index.js
CHANGED
|
@@ -38225,7 +38225,8 @@ var runnersToPage = (page, options) => ({
|
|
|
38225
38225
|
const isBold = style.fontWeight === "bold" || Number(style.fontWeight) >= 700;
|
|
38226
38226
|
const isItalic = style.fontStyle === "italic";
|
|
38227
38227
|
const getFont = (bold, italic, family) => fonts[family + (bold ? "_bold" : "") + (italic ? "_italic" : "")];
|
|
38228
|
-
|
|
38228
|
+
const matchingFontFamily = Object.keys(fonts).find((fontFamily) => fontFamily.startsWith(family));
|
|
38229
|
+
return getFont(isBold, isItalic, family) || getFont(isBold, false, family) || getFont(false, isItalic, family) || getFont(false, false, family) || (matchingFontFamily ? fonts[matchingFontFamily] : void 0);
|
|
38229
38230
|
}
|
|
38230
38231
|
const font = options.fonts && getBestFont(element.svgAttributes, options.fonts);
|
|
38231
38232
|
const textWidth = (font || page.getFont()[0]).widthOfTextAtSize(text, fontSize);
|
|
@@ -38344,6 +38345,33 @@ var parseStyles$1 = (style) => {
|
|
|
38344
38345
|
}
|
|
38345
38346
|
return css;
|
|
38346
38347
|
};
|
|
38348
|
+
var stripImportantSuffix = (value) => {
|
|
38349
|
+
const suffix = "!important";
|
|
38350
|
+
const trimmed = value.trim();
|
|
38351
|
+
return trimmed.toLowerCase().endsWith(suffix) ? trimmed.slice(0, -10).trimEnd() : trimmed;
|
|
38352
|
+
};
|
|
38353
|
+
var splitFontFamilies = (fontFamily) => {
|
|
38354
|
+
const families = [];
|
|
38355
|
+
let current = "";
|
|
38356
|
+
let quote;
|
|
38357
|
+
for (const char of fontFamily) {
|
|
38358
|
+
if ((char === "\"" || char === "'") && (!quote || quote === char)) {
|
|
38359
|
+
quote = quote ? void 0 : char;
|
|
38360
|
+
continue;
|
|
38361
|
+
}
|
|
38362
|
+
if (char === "," && !quote) {
|
|
38363
|
+
if (current.trim()) families.push(current.trim());
|
|
38364
|
+
current = "";
|
|
38365
|
+
continue;
|
|
38366
|
+
}
|
|
38367
|
+
current += char;
|
|
38368
|
+
}
|
|
38369
|
+
if (current.trim()) families.push(current.trim());
|
|
38370
|
+
return families.map(stripImportantSuffix).filter(Boolean);
|
|
38371
|
+
};
|
|
38372
|
+
var normalizeFontFamily = (fontFamily) => {
|
|
38373
|
+
return splitFontFamilies(fontFamily)[0] || fontFamily.trim();
|
|
38374
|
+
};
|
|
38347
38375
|
var parseColor$2 = (color, inherited) => {
|
|
38348
38376
|
if (!color || color.length === 0) return void 0;
|
|
38349
38377
|
if (["none", "transparent"].includes(color)) return void 0;
|
|
@@ -38461,10 +38489,7 @@ var parseAttributes = (element, inherited, matrix) => {
|
|
|
38461
38489
|
newMatrix = combineTransformation(newMatrix, "scale", [1, -1]);
|
|
38462
38490
|
svgAttributes.d = attributes.d;
|
|
38463
38491
|
}
|
|
38464
|
-
if (newInherited.fontFamily)
|
|
38465
|
-
const inner = newInherited.fontFamily.match(/^"(.*?)"|^'(.*?)'/);
|
|
38466
|
-
if (inner) newInherited.fontFamily = inner[1] || inner[2];
|
|
38467
|
-
}
|
|
38492
|
+
if (newInherited.fontFamily) newInherited.fontFamily = normalizeFontFamily(newInherited.fontFamily);
|
|
38468
38493
|
if (newInherited.strokeWidth) svgAttributes.strokeWidth = newInherited.strokeWidth;
|
|
38469
38494
|
return {
|
|
38470
38495
|
inherited: newInherited,
|
|
@@ -86168,7 +86193,7 @@ var Underline = [["path", { d: "M6 4v6a6 6 0 0 0 12 0V4" }], ["line", {
|
|
|
86168
86193
|
y2: "20"
|
|
86169
86194
|
}]];
|
|
86170
86195
|
//#endregion
|
|
86171
|
-
//#region ../schemas/dist/builtins-
|
|
86196
|
+
//#region ../schemas/dist/builtins-D75m2smy.js
|
|
86172
86197
|
var addUriLinkAnnotation = (arg) => {
|
|
86173
86198
|
const { pdfDoc, page, uri, rect, borderWidth = 0 } = arg;
|
|
86174
86199
|
const safeUri = normalizeSafeLinkUri(uri);
|
|
@@ -86465,7 +86490,7 @@ var isTextOverflowExpandSchema = (schema) => schema.type === void 0 || TEXT_OVER
|
|
|
86465
86490
|
var canUseTextOverflowExpand = (schema, basePdf) => !isTextOverflowExpandSchema(schema) || basePdf === void 0 || isBlankPdf(basePdf);
|
|
86466
86491
|
var isTextOverflowExpand = (schema, basePdf) => canUseTextOverflowExpand(schema, basePdf) && schema.overflow === "expand";
|
|
86467
86492
|
var shouldUseDynamicFontSize = (schema, basePdf) => Boolean(schema.dynamicFontSize) && !isTextOverflowExpand(schema, basePdf);
|
|
86468
|
-
var PDF_FONT_CACHE_KEY = "
|
|
86493
|
+
var PDF_FONT_CACHE_KEY = "schemas-pdf-font-cache";
|
|
86469
86494
|
var getPdfFontCache = (_cache) => {
|
|
86470
86495
|
let pdfFontCache = _cache.get(PDF_FONT_CACHE_KEY);
|
|
86471
86496
|
if (!pdfFontCache) {
|
|
@@ -237067,7 +237092,7 @@ var scaleDragPosAdjustment = (adjustment, scale) => {
|
|
|
237067
237092
|
return 0;
|
|
237068
237093
|
};
|
|
237069
237094
|
var MIN_CANVAS_WIDTH = 100;
|
|
237070
|
-
var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPageCursorChange, onChangeSelection, onRegisterSchemaSelectionHandler }) => {
|
|
237095
|
+
var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPageCursorChange, onChangeSelection, onRegisterSchemaSelectionHandler, onUpdateTemplatePageApplied, updateTemplatePage }) => {
|
|
237071
237096
|
const past = (0, import_react$9.useRef)([]);
|
|
237072
237097
|
const future = (0, import_react$9.useRef)([]);
|
|
237073
237098
|
const canvasRef = (0, import_react$9.useRef)(null);
|
|
@@ -237081,6 +237106,7 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
|
|
|
237081
237106
|
const [activeElements, setActiveElements] = (0, import_react$9.useState)([]);
|
|
237082
237107
|
const [schemasList, setSchemasList] = (0, import_react$9.useState)([[]]);
|
|
237083
237108
|
const [pageCursor, setPageCursor] = (0, import_react$9.useState)(0);
|
|
237109
|
+
const [pendingScrollPage, setPendingScrollPage] = (0, import_react$9.useState)(null);
|
|
237084
237110
|
const [sidebarOpen, setSidebarOpen] = (0, import_react$9.useState)(options.sidebarOpen ?? canvasWidth - 400 >= MIN_CANVAS_WIDTH);
|
|
237085
237111
|
const [canvasHeight, setCanvasHeight] = (0, import_react$9.useState)(0);
|
|
237086
237112
|
const [prevTemplate, setPrevTemplate] = (0, import_react$9.useState)(null);
|
|
@@ -237187,6 +237213,26 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
|
|
|
237187
237213
|
onEditEnd();
|
|
237188
237214
|
}
|
|
237189
237215
|
});
|
|
237216
|
+
(0, import_react$9.useLayoutEffect)(() => {
|
|
237217
|
+
if (!pendingScrollPage || !canvasRef.current) return;
|
|
237218
|
+
const { page: pendingPage, queuedPageSizes, requestedPage } = pendingScrollPage;
|
|
237219
|
+
if (!pageSizes[pendingPage] || pageSizes.length !== schemasList.length) return;
|
|
237220
|
+
if (isBlankPdf(template.basePdf)) {
|
|
237221
|
+
const { width, height } = template.basePdf;
|
|
237222
|
+
if (!pageSizes.every((pageSize) => pageSize.width === width && pageSize.height === height)) return;
|
|
237223
|
+
} else if (pageSizes === queuedPageSizes) return;
|
|
237224
|
+
setPendingScrollPage(null);
|
|
237225
|
+
canvasRef.current.scrollTop = getPagesScrollTopByIndex(pageSizes, pendingPage, displayScale);
|
|
237226
|
+
if (requestedPage !== void 0) onUpdateTemplatePageApplied?.(requestedPage);
|
|
237227
|
+
}, [
|
|
237228
|
+
displayScale,
|
|
237229
|
+
pageCursor,
|
|
237230
|
+
pageSizes,
|
|
237231
|
+
pendingScrollPage,
|
|
237232
|
+
schemasList.length,
|
|
237233
|
+
template.basePdf,
|
|
237234
|
+
onUpdateTemplatePageApplied
|
|
237235
|
+
]);
|
|
237190
237236
|
(0, import_react$9.useLayoutEffect)(() => {
|
|
237191
237237
|
const updateHeight = () => {
|
|
237192
237238
|
setCanvasHeight(canvasRef.current ? canvasRef.current.clientHeight : 0);
|
|
@@ -237252,25 +237298,35 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
|
|
|
237252
237298
|
onEdit,
|
|
237253
237299
|
onEditEnd
|
|
237254
237300
|
});
|
|
237255
|
-
const updateTemplate = (0, import_react$9.useCallback)(async (newTemplate,
|
|
237301
|
+
const updateTemplate = (0, import_react$9.useCallback)(async (newTemplate, targetPage) => {
|
|
237256
237302
|
const sl = await template2SchemasList(newTemplate);
|
|
237257
237303
|
setSchemasList(sl);
|
|
237258
237304
|
onEditEnd();
|
|
237259
|
-
if (
|
|
237260
|
-
|
|
237261
|
-
|
|
237262
|
-
|
|
237263
|
-
|
|
237264
|
-
|
|
237265
|
-
|
|
237266
|
-
|
|
237267
|
-
if (clamped !== prev && canvasRef.current) canvasRef.current.scroll({
|
|
237268
|
-
top: getPagesScrollTopByIndex(pageSizes, clamped, displayScale),
|
|
237269
|
-
behavior: "smooth"
|
|
237305
|
+
if (targetPage !== void 0) {
|
|
237306
|
+
const clampedPage = Math.min(Math.max(Number.isFinite(targetPage) ? Math.trunc(targetPage) : 0, 0), sl.length - 1);
|
|
237307
|
+
setPageCursor(clampedPage);
|
|
237308
|
+
onPageCursorChange(clampedPage, sl.length);
|
|
237309
|
+
setPendingScrollPage({
|
|
237310
|
+
page: clampedPage,
|
|
237311
|
+
queuedPageSizes: pageSizes,
|
|
237312
|
+
requestedPage: targetPage
|
|
237270
237313
|
});
|
|
237271
|
-
|
|
237272
|
-
|
|
237273
|
-
|
|
237314
|
+
} else {
|
|
237315
|
+
const clampedPage = Math.min(pageCursor, sl.length - 1);
|
|
237316
|
+
setPageCursor(clampedPage);
|
|
237317
|
+
if (clampedPage !== pageCursor) {
|
|
237318
|
+
onPageCursorChange(clampedPage, sl.length);
|
|
237319
|
+
setPendingScrollPage({
|
|
237320
|
+
page: clampedPage,
|
|
237321
|
+
queuedPageSizes: pageSizes
|
|
237322
|
+
});
|
|
237323
|
+
}
|
|
237324
|
+
}
|
|
237325
|
+
}, [
|
|
237326
|
+
pageCursor,
|
|
237327
|
+
pageSizes,
|
|
237328
|
+
onPageCursorChange
|
|
237329
|
+
]);
|
|
237274
237330
|
const addSchema = (defaultSchema) => {
|
|
237275
237331
|
const [paddingTop, paddingRight, paddingBottom, paddingLeft] = isBlankPdf(template.basePdf) ? template.basePdf.padding : [
|
|
237276
237332
|
0,
|
|
@@ -237317,9 +237373,8 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
|
|
|
237317
237373
|
setPageCursor(newPageCursor);
|
|
237318
237374
|
const newTemplate = schemasList2template(sl, template.basePdf);
|
|
237319
237375
|
onChangeTemplate(newTemplate);
|
|
237320
|
-
await updateTemplate(newTemplate,
|
|
237376
|
+
await updateTemplate(newTemplate, newPageCursor);
|
|
237321
237377
|
refresh(newTemplate);
|
|
237322
|
-
onPageCursorChange(newPageCursor, sl.length);
|
|
237323
237378
|
setTimeout(() => {
|
|
237324
237379
|
if (canvasRef.current) canvasRef.current.scrollTop = getPagesScrollTopByIndex(pageSizes, newPageCursor, displayScale);
|
|
237325
237380
|
}, 0);
|
|
@@ -237338,7 +237393,7 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
|
|
|
237338
237393
|
};
|
|
237339
237394
|
if (prevTemplate !== template) {
|
|
237340
237395
|
setPrevTemplate(template);
|
|
237341
|
-
updateTemplate(template,
|
|
237396
|
+
updateTemplate(template, updateTemplatePage);
|
|
237342
237397
|
}
|
|
237343
237398
|
if (error) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorScreen, {
|
|
237344
237399
|
size,
|
|
@@ -237515,16 +237570,18 @@ var Designer = class extends BaseUIClass {
|
|
|
237515
237570
|
_defineProperty$14(this, "pageCursor", 0);
|
|
237516
237571
|
_defineProperty$14(this, "selection", EMPTY_DESIGNER_SELECTION);
|
|
237517
237572
|
_defineProperty$14(this, "selectSchemasHandler", null);
|
|
237573
|
+
_defineProperty$14(this, "updateTemplatePage", void 0);
|
|
237518
237574
|
checkDesignerProps(props);
|
|
237519
237575
|
}
|
|
237520
237576
|
saveTemplate() {
|
|
237521
237577
|
if (!this.domContainer) throw Error(DESTROYED_ERR_MSG);
|
|
237522
237578
|
if (this.onSaveTemplateCallback) this.onSaveTemplateCallback(this.template);
|
|
237523
237579
|
}
|
|
237524
|
-
updateTemplate(template) {
|
|
237580
|
+
updateTemplate(template, options = {}) {
|
|
237525
237581
|
checkTemplate(template);
|
|
237526
237582
|
if (!this.domContainer) throw Error(DESTROYED_ERR_MSG);
|
|
237527
237583
|
this.template = cloneDeep$1(template);
|
|
237584
|
+
this.updateTemplatePage = options.page;
|
|
237528
237585
|
if (this.onChangeTemplateCallback) this.onChangeTemplateCallback(template);
|
|
237529
237586
|
this.render();
|
|
237530
237587
|
}
|
|
@@ -237591,6 +237648,10 @@ var Designer = class extends BaseUIClass {
|
|
|
237591
237648
|
onRegisterSchemaSelectionHandler: (handler) => {
|
|
237592
237649
|
this.selectSchemasHandler = handler;
|
|
237593
237650
|
},
|
|
237651
|
+
onUpdateTemplatePageApplied: (page) => {
|
|
237652
|
+
if (Object.is(this.updateTemplatePage, page)) this.updateTemplatePage = void 0;
|
|
237653
|
+
},
|
|
237654
|
+
updateTemplatePage: this.updateTemplatePage,
|
|
237594
237655
|
size: this.size
|
|
237595
237656
|
})
|
|
237596
237657
|
}));
|