@pdfme/ui 6.1.2-dev.3 → 6.1.2-dev.32
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 +8 -0
- package/dist/components/Designer/RightSidebar/DetailView/schemaChangeHelpers.d.ts +11 -0
- package/dist/components/Designer/index.d.ts +4 -1
- package/dist/designerSelection.d.ts +45 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +238 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/Designer.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { Template, DesignerProps } from '@pdfme/common';
|
|
2
2
|
import { BaseUIClass } from './class.js';
|
|
3
|
+
import { type DesignerSelectSchemasOptions, type DesignerSchemaSelectionTarget, type DesignerSelectedSchema, type DesignerSelection, type DesignerSelectionChangeCallback } from './designerSelection.js';
|
|
3
4
|
declare class Designer extends BaseUIClass {
|
|
4
5
|
private onSaveTemplateCallback?;
|
|
5
6
|
private onChangeTemplateCallback?;
|
|
6
7
|
private onPageChangeCallback?;
|
|
8
|
+
private onChangeSelectionCallback?;
|
|
7
9
|
private pageCursor;
|
|
10
|
+
private selection;
|
|
11
|
+
private selectSchemasHandler;
|
|
8
12
|
constructor(props: DesignerProps);
|
|
9
13
|
saveTemplate(): void;
|
|
10
14
|
updateTemplate(template: Template): void;
|
|
@@ -14,6 +18,10 @@ declare class Designer extends BaseUIClass {
|
|
|
14
18
|
currentPage: number;
|
|
15
19
|
totalPages: number;
|
|
16
20
|
}) => void): void;
|
|
21
|
+
onChangeSelection(cb: DesignerSelectionChangeCallback): void;
|
|
22
|
+
getSelection(): DesignerSelection;
|
|
23
|
+
getSelectedSchemas(): DesignerSelectedSchema[];
|
|
24
|
+
selectSchemas(targets: DesignerSchemaSelectionTarget | DesignerSchemaSelectionTarget[], options?: DesignerSelectSchemasOptions): void;
|
|
17
25
|
getPageCursor(): number;
|
|
18
26
|
getTotalPages(): number;
|
|
19
27
|
protected render(): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ChangeSchemaItem, SchemaForUI } from '@pdfme/common';
|
|
2
|
+
export declare const getSameTypeBulkUpdateSchemas: ({ activeSchema, activeSchemas, }: {
|
|
3
|
+
activeSchema: SchemaForUI;
|
|
4
|
+
activeSchemas: SchemaForUI[];
|
|
5
|
+
}) => SchemaForUI[];
|
|
6
|
+
export declare const isSingleSchemaOnlyChange: (key: string) => boolean;
|
|
7
|
+
export declare const expandSameTypeBulkUpdateChanges: ({ activeSchema, activeSchemas, changes, }: {
|
|
8
|
+
activeSchema: SchemaForUI;
|
|
9
|
+
activeSchemas: SchemaForUI[];
|
|
10
|
+
changes: ChangeSchemaItem[];
|
|
11
|
+
}) => ChangeSchemaItem[];
|
|
@@ -1,9 +1,12 @@
|
|
|
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
|
+
declare const TemplateEditor: ({ template, size, onSaveTemplate, onChangeTemplate, onPageCursorChange, onChangeSelection, onRegisterSchemaSelectionHandler, }: Omit<DesignerProps, "domContainer"> & {
|
|
4
5
|
size: Size;
|
|
5
6
|
onSaveTemplate: (t: Template) => void;
|
|
6
7
|
onChangeTemplate: (t: Template) => void;
|
|
8
|
+
onChangeSelection?: (selection: DesignerSelection) => void;
|
|
9
|
+
onRegisterSchemaSelectionHandler?: (handler: DesignerSelectSchemas | null) => void;
|
|
7
10
|
} & {
|
|
8
11
|
onChangeTemplate: (t: Template) => void;
|
|
9
12
|
onPageCursorChange: (newPageCursor: number, totalPages: number) => void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type Schema, type SchemaForUI } from '@pdfme/common';
|
|
2
|
+
export type DesignerSelectionBounds = {
|
|
3
|
+
height: number;
|
|
4
|
+
width: number;
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
};
|
|
8
|
+
export type DesignerSelectedSchema = {
|
|
9
|
+
name: string;
|
|
10
|
+
pageIndex: number;
|
|
11
|
+
schema: Schema;
|
|
12
|
+
schemaId: string;
|
|
13
|
+
schemaIndex: number;
|
|
14
|
+
type: string;
|
|
15
|
+
};
|
|
16
|
+
export type DesignerSelection = {
|
|
17
|
+
bounds: DesignerSelectionBounds | null;
|
|
18
|
+
pageIndex: number;
|
|
19
|
+
schemas: DesignerSelectedSchema[];
|
|
20
|
+
};
|
|
21
|
+
export type DesignerSelectionChangeCallback = (selection: DesignerSelection) => void;
|
|
22
|
+
export type DesignerSchemaSelectionTarget = string | {
|
|
23
|
+
name?: string;
|
|
24
|
+
pageIndex?: number;
|
|
25
|
+
schemaId?: string;
|
|
26
|
+
schemaIndex?: number;
|
|
27
|
+
};
|
|
28
|
+
export type DesignerSelectSchemasOptions = {
|
|
29
|
+
pageIndex?: number;
|
|
30
|
+
scroll?: boolean;
|
|
31
|
+
};
|
|
32
|
+
export type DesignerSelectSchemas = (targets: DesignerSchemaSelectionTarget | DesignerSchemaSelectionTarget[], options?: DesignerSelectSchemasOptions) => void;
|
|
33
|
+
export declare const EMPTY_DESIGNER_SELECTION: DesignerSelection;
|
|
34
|
+
export declare const createDesignerSelection: ({ activeSchemaIds, pageIndex, schemasList, }: {
|
|
35
|
+
activeSchemaIds: string[];
|
|
36
|
+
pageIndex: number;
|
|
37
|
+
schemasList: SchemaForUI[][];
|
|
38
|
+
}) => DesignerSelection;
|
|
39
|
+
export declare const normalizeDesignerSchemaSelectionTargets: (targets: DesignerSchemaSelectionTarget | DesignerSchemaSelectionTarget[]) => DesignerSchemaSelectionTarget[];
|
|
40
|
+
export declare const getDesignerSelectionPageIndex: (targets: DesignerSchemaSelectionTarget[], fallbackPageIndex: number, options?: DesignerSelectSchemasOptions) => number;
|
|
41
|
+
export declare const getSelectedSchemaIds: ({ pageIndex, schemas, targets, }: {
|
|
42
|
+
pageIndex: number;
|
|
43
|
+
schemas: SchemaForUI[];
|
|
44
|
+
targets: DesignerSchemaSelectionTarget[];
|
|
45
|
+
}) => string[];
|
package/dist/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ 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 { DesignerSchemaSelectionTarget, DesignerSelectSchemas, DesignerSelectSchemasOptions, DesignerSelectedSchema, DesignerSelection, DesignerSelectionBounds, DesignerSelectionChangeCallback, } from './designerSelection.js';
|
package/dist/index.js
CHANGED
|
@@ -45966,7 +45966,7 @@ var UIProps = CommonProps.extend({
|
|
|
45966
45966
|
});
|
|
45967
45967
|
var PreviewProps = UIProps.extend({ inputs: Inputs }).strict();
|
|
45968
45968
|
var DesignerProps = UIProps.extend({}).strict();
|
|
45969
|
-
var cloneDeep$1 = structuredClone;
|
|
45969
|
+
var cloneDeep$1 = (value) => structuredClone(value);
|
|
45970
45970
|
var uniq = (array) => Array.from(new Set(array));
|
|
45971
45971
|
var getFallbackFontName = (font) => {
|
|
45972
45972
|
const initial = "";
|
|
@@ -46665,6 +46665,10 @@ var getDynamicTemplate = async (arg) => {
|
|
|
46665
46665
|
const PARALLEL_LIMIT = 10;
|
|
46666
46666
|
for (let pageIndex = 0; pageIndex < template.schemas.length; pageIndex++) {
|
|
46667
46667
|
const pageSchemas = template.schemas[pageIndex];
|
|
46668
|
+
if (pageSchemas.length === 0) {
|
|
46669
|
+
resultPages.push([]);
|
|
46670
|
+
continue;
|
|
46671
|
+
}
|
|
46668
46672
|
const { items, orderMap } = normalizePageSchemas(pageSchemas, paddingTop);
|
|
46669
46673
|
for (let i = 0; i < items.length; i += PARALLEL_LIMIT) {
|
|
46670
46674
|
const chunk = items.slice(i, i + PARALLEL_LIMIT);
|
|
@@ -46681,7 +46685,6 @@ var getDynamicTemplate = async (arg) => {
|
|
|
46681
46685
|
const processedPages = processDynamicPage(items, orderMap, contentHeight, paddingTop);
|
|
46682
46686
|
resultPages.push(...processedPages);
|
|
46683
46687
|
}
|
|
46684
|
-
removeTrailingEmptyPages(resultPages);
|
|
46685
46688
|
if (resultPages.length === template.schemas.length) {
|
|
46686
46689
|
let unchanged = true;
|
|
46687
46690
|
for (let i = 0; i < resultPages.length && unchanged; i++) {
|
|
@@ -100555,7 +100558,7 @@ var Underline = [["path", { d: "M6 4v6a6 6 0 0 0 12 0V4" }], ["line", {
|
|
|
100555
100558
|
y2: "20"
|
|
100556
100559
|
}]];
|
|
100557
100560
|
//#endregion
|
|
100558
|
-
//#region ../schemas/dist/builtins-
|
|
100561
|
+
//#region ../schemas/dist/builtins-D9sJvrz9.js
|
|
100559
100562
|
var addUriLinkAnnotation = (arg) => {
|
|
100560
100563
|
const { pdfDoc, page, uri, rect, borderWidth = 0 } = arg;
|
|
100561
100564
|
const safeUri = normalizeSafeLinkUri(uri);
|
|
@@ -101738,6 +101741,8 @@ var getRangedPlainTextValue = (arg) => {
|
|
|
101738
101741
|
var buildStyledTextContainer = (arg, fontKitFont, value, resolvedDynamicFontSize) => {
|
|
101739
101742
|
const { schema, rootElement, mode } = arg;
|
|
101740
101743
|
let dynamicFontSize = resolvedDynamicFontSize;
|
|
101744
|
+
const characterSpacing = schema.characterSpacing ?? 0;
|
|
101745
|
+
const editable = isEditable(mode, schema);
|
|
101741
101746
|
if (dynamicFontSize === void 0 && shouldUseDynamicFontSize(schema, arg.basePdf) && value) dynamicFontSize = calculateDynamicFontSize({
|
|
101742
101747
|
textSchema: schema,
|
|
101743
101748
|
fontKitFont,
|
|
@@ -101772,7 +101777,7 @@ var buildStyledTextContainer = (arg, fontKitFont, value, resolvedDynamicFontSize
|
|
|
101772
101777
|
justifyContent: mapVerticalAlignToFlex(verticalAlignment),
|
|
101773
101778
|
width: "100%",
|
|
101774
101779
|
height: "100%",
|
|
101775
|
-
cursor:
|
|
101780
|
+
cursor: editable ? "text" : "default"
|
|
101776
101781
|
};
|
|
101777
101782
|
Object.assign(container.style, containerStyle);
|
|
101778
101783
|
rootElement.innerHTML = "";
|
|
@@ -101784,7 +101789,7 @@ var buildStyledTextContainer = (arg, fontKitFont, value, resolvedDynamicFontSize
|
|
|
101784
101789
|
fontFamily: schema.fontName ? `'${schema.fontName}'` : "inherit",
|
|
101785
101790
|
color: schema.fontColor ? schema.fontColor : DEFAULT_FONT_COLOR,
|
|
101786
101791
|
fontSize: `${dynamicFontSize ?? schema.fontSize ?? 13}pt`,
|
|
101787
|
-
letterSpacing: `${
|
|
101792
|
+
letterSpacing: `${characterSpacing}pt`,
|
|
101788
101793
|
lineHeight: `${schema.lineHeight ?? 1}em`,
|
|
101789
101794
|
textAlign: schema.alignment ?? "left",
|
|
101790
101795
|
whiteSpace: "pre-wrap",
|
|
@@ -101796,6 +101801,7 @@ var buildStyledTextContainer = (arg, fontKitFont, value, resolvedDynamicFontSize
|
|
|
101796
101801
|
paddingTop: `${topAdjustment}px`,
|
|
101797
101802
|
backgroundColor: "transparent",
|
|
101798
101803
|
textDecoration: textDecorations.join(" "),
|
|
101804
|
+
...editable && characterSpacing > 0 ? { width: `calc(100% + ${characterSpacing}pt)` } : {},
|
|
101799
101805
|
...isTopAligned ? { height: "100%" } : {}
|
|
101800
101806
|
};
|
|
101801
101807
|
const textBlock = document.createElement("div");
|
|
@@ -213907,7 +213913,7 @@ withProvider(FormCore, { Html: html });
|
|
|
213907
213913
|
//#region ../../node_modules/form-render/es/index.js
|
|
213908
213914
|
var es_default = withProvider(FormCore, widgets_exports);
|
|
213909
213915
|
//#endregion
|
|
213910
|
-
//#region ../schemas/dist/helper-
|
|
213916
|
+
//#region ../schemas/dist/helper-Doen9Okh.js
|
|
213911
213917
|
var substituteVariables = (text, variablesIn, valueMapper = (value) => value) => {
|
|
213912
213918
|
if (!text) return "";
|
|
213913
213919
|
let substitutedText = text;
|
|
@@ -213936,14 +213942,14 @@ var validateVariables = (value, schema) => {
|
|
|
213936
213942
|
} catch {
|
|
213937
213943
|
throw new SyntaxError(`[@pdfme/generator] invalid JSON string '${value}' for variables in field ${schema.name}`);
|
|
213938
213944
|
}
|
|
213939
|
-
for (const variable of schema.variables) if (!values[variable]) {
|
|
213945
|
+
for (const variable of schema.variables) if (!Object.prototype.hasOwnProperty.call(values, variable) || values[variable] === null || values[variable] === void 0) {
|
|
213940
213946
|
if (schema.required) throw new Error(`[@pdfme/generator] variable ${variable} is missing for field ${schema.name}`);
|
|
213941
213947
|
return false;
|
|
213942
213948
|
}
|
|
213943
213949
|
return true;
|
|
213944
213950
|
};
|
|
213945
213951
|
//#endregion
|
|
213946
|
-
//#region ../schemas/dist/dynamicTemplate-
|
|
213952
|
+
//#region ../schemas/dist/dynamicTemplate-CRjx4Mjc.js
|
|
213947
213953
|
var getDynamicLayoutForMultiVariableText = async (value, args) => {
|
|
213948
213954
|
if (args.schema.type !== "multiVariableText") return { heights: [args.schema.height] };
|
|
213949
213955
|
const schema = args.schema;
|
|
@@ -214177,34 +214183,70 @@ var WidgetRenderer = (props) => {
|
|
|
214177
214183
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref });
|
|
214178
214184
|
};
|
|
214179
214185
|
//#endregion
|
|
214186
|
+
//#region src/components/Designer/RightSidebar/DetailView/schemaChangeHelpers.ts
|
|
214187
|
+
var singleSchemaOnlyChangeKeys = new Set([
|
|
214188
|
+
"id",
|
|
214189
|
+
"name",
|
|
214190
|
+
"type",
|
|
214191
|
+
"content",
|
|
214192
|
+
"position"
|
|
214193
|
+
]);
|
|
214194
|
+
var getSameTypeBulkUpdateSchemas = ({ activeSchema, activeSchemas }) => {
|
|
214195
|
+
if (activeSchemas.length > 1 && activeSchemas.every((schema) => schema.type === activeSchema.type)) return activeSchemas;
|
|
214196
|
+
return [activeSchema];
|
|
214197
|
+
};
|
|
214198
|
+
var isSingleSchemaOnlyChange = (key) => singleSchemaOnlyChangeKeys.has(key) || key.startsWith("position.");
|
|
214199
|
+
var expandSameTypeBulkUpdateChanges = ({ activeSchema, activeSchemas, changes }) => {
|
|
214200
|
+
const targetSchemas = getSameTypeBulkUpdateSchemas({
|
|
214201
|
+
activeSchema,
|
|
214202
|
+
activeSchemas
|
|
214203
|
+
});
|
|
214204
|
+
if (targetSchemas.length <= 1) return changes;
|
|
214205
|
+
if (!changes.every((change) => change.schemaId === activeSchema.id)) return changes;
|
|
214206
|
+
if (changes.some((change) => isSingleSchemaOnlyChange(change.key))) return changes;
|
|
214207
|
+
return changes.flatMap((change) => {
|
|
214208
|
+
return targetSchemas.map((schema) => ({
|
|
214209
|
+
...change,
|
|
214210
|
+
schemaId: schema.id
|
|
214211
|
+
}));
|
|
214212
|
+
});
|
|
214213
|
+
};
|
|
214214
|
+
//#endregion
|
|
214180
214215
|
//#region src/components/Designer/RightSidebar/DetailView/ButtonGroupWidget.tsx
|
|
214181
214216
|
var ButtonGroupWidget = (props) => {
|
|
214182
|
-
const { activeElements, changeSchemas, schemas, schema } = props;
|
|
214217
|
+
const { activeElements, activeSchema, changeSchemas, schemas, schema } = props;
|
|
214183
214218
|
const { token } = theme_default.useToken();
|
|
214184
214219
|
const buttons = Array.isArray(schema?.buttons) ? schema.buttons : [];
|
|
214185
|
-
const
|
|
214186
|
-
const key = btn.key;
|
|
214187
|
-
const type = btn.type;
|
|
214220
|
+
const getSelectedSchemas = () => {
|
|
214188
214221
|
const ids = activeElements.map((ae) => ae.id);
|
|
214189
|
-
|
|
214190
|
-
|
|
214191
|
-
|
|
214192
|
-
|
|
214193
|
-
|
|
214194
|
-
|
|
214195
|
-
|
|
214196
|
-
|
|
214222
|
+
return schemas.filter((s) => ids.includes(s.id));
|
|
214223
|
+
};
|
|
214224
|
+
const getTargetSchemas = () => getSameTypeBulkUpdateSchemas({
|
|
214225
|
+
activeSchema,
|
|
214226
|
+
activeSchemas: getSelectedSchemas()
|
|
214227
|
+
});
|
|
214228
|
+
const getButtonValue = (btn, targetSchemas) => {
|
|
214229
|
+
if (btn.type !== "boolean") return btn.value;
|
|
214230
|
+
return !targetSchemas.every((s) => Boolean(s[btn.key] ?? false));
|
|
214231
|
+
};
|
|
214232
|
+
const apply = (btn) => {
|
|
214233
|
+
const targetSchemas = getTargetSchemas();
|
|
214234
|
+
const value = getButtonValue(btn, targetSchemas);
|
|
214235
|
+
changeSchemas(targetSchemas.map((s) => ({
|
|
214236
|
+
key: btn.key,
|
|
214237
|
+
value,
|
|
214238
|
+
schemaId: s.id
|
|
214239
|
+
})));
|
|
214197
214240
|
};
|
|
214198
214241
|
const isActive = (btn) => {
|
|
214199
214242
|
const key = btn.key;
|
|
214200
214243
|
const type = btn.type;
|
|
214201
|
-
|
|
214202
|
-
|
|
214203
|
-
|
|
214244
|
+
const targetSchemas = getTargetSchemas();
|
|
214245
|
+
if (targetSchemas.length === 0) return false;
|
|
214246
|
+
return targetSchemas.every((s) => {
|
|
214204
214247
|
const schemaRecord = s;
|
|
214205
|
-
|
|
214248
|
+
return type === "boolean" ? Boolean(schemaRecord[key] ?? false) : schemaRecord[key] === btn.value;
|
|
214206
214249
|
});
|
|
214207
|
-
return active;
|
|
214208
214250
|
};
|
|
214209
214251
|
const replaceCurrentColor = (svgString, color) => color ? svgString.replace(/="currentColor"/g, `="${color}"`) : svgString;
|
|
214210
214252
|
const svgIcon = (svgString) => {
|
|
@@ -214233,6 +214275,7 @@ var ButtonGroupWidget = (props) => {
|
|
|
214233
214275
|
//#region src/components/Designer/RightSidebar/DetailView/index.tsx
|
|
214234
214276
|
var { Text: Text$2 } = Typography;
|
|
214235
214277
|
var TEXT_OVERFLOW_EXPAND_SCHEMA_TYPES = new Set(["text", "multiVariableText"]);
|
|
214278
|
+
var getElementIds = (elements) => elements.map(({ id }) => id);
|
|
214236
214279
|
var DetailView = (props) => {
|
|
214237
214280
|
const { token } = theme_default.useToken();
|
|
214238
214281
|
const { schemasList, changeSchemas, deselectSchema, activeSchema, pageSize, basePdf } = props;
|
|
@@ -214240,6 +214283,19 @@ var DetailView = (props) => {
|
|
|
214240
214283
|
const i18n = (0, import_react$9.useContext)(I18nContext);
|
|
214241
214284
|
const pluginsRegistry = (0, import_react$9.useContext)(PluginsRegistry);
|
|
214242
214285
|
const options = (0, import_react$9.useContext)(OptionsContext);
|
|
214286
|
+
const activeSchemas = (0, import_react$9.useMemo)(() => {
|
|
214287
|
+
const ids = new Set(props.activeElements.map((element) => element.id));
|
|
214288
|
+
return props.schemas.filter((schema) => ids.has(schema.id));
|
|
214289
|
+
}, [props.activeElements, props.schemas]);
|
|
214290
|
+
const changeSchemasWithSameTypeSelection = (0, import_react$9.useCallback)((changes) => changeSchemas(expandSameTypeBulkUpdateChanges({
|
|
214291
|
+
activeSchema,
|
|
214292
|
+
activeSchemas,
|
|
214293
|
+
changes
|
|
214294
|
+
})), [
|
|
214295
|
+
activeSchema,
|
|
214296
|
+
activeSchemas,
|
|
214297
|
+
changeSchemas
|
|
214298
|
+
]);
|
|
214243
214299
|
const typedI18n = (0, import_react$9.useCallback)((key) => {
|
|
214244
214300
|
return typeof i18n === "function" ? i18n(key) : key;
|
|
214245
214301
|
}, [i18n]);
|
|
@@ -214248,6 +214304,7 @@ var DetailView = (props) => {
|
|
|
214248
214304
|
AlignWidget: (p) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlignWidget, {
|
|
214249
214305
|
...p,
|
|
214250
214306
|
...props,
|
|
214307
|
+
changeSchemas: changeSchemasWithSameTypeSelection,
|
|
214251
214308
|
options
|
|
214252
214309
|
}),
|
|
214253
214310
|
Divider: () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Divider$2, { style: {
|
|
@@ -214257,6 +214314,7 @@ var DetailView = (props) => {
|
|
|
214257
214314
|
ButtonGroup: (p) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ButtonGroupWidget, {
|
|
214258
214315
|
...p,
|
|
214259
214316
|
...props,
|
|
214317
|
+
changeSchemas: changeSchemasWithSameTypeSelection,
|
|
214260
214318
|
options
|
|
214261
214319
|
})
|
|
214262
214320
|
};
|
|
@@ -214266,6 +214324,7 @@ var DetailView = (props) => {
|
|
|
214266
214324
|
newWidgets[widgetKey] = (p) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WidgetRenderer, {
|
|
214267
214325
|
...p,
|
|
214268
214326
|
...props,
|
|
214327
|
+
changeSchemas: changeSchemasWithSameTypeSelection,
|
|
214269
214328
|
options,
|
|
214270
214329
|
theme: token,
|
|
214271
214330
|
i18n: typedI18n,
|
|
@@ -214275,6 +214334,7 @@ var DetailView = (props) => {
|
|
|
214275
214334
|
}
|
|
214276
214335
|
return newWidgets;
|
|
214277
214336
|
}, [
|
|
214337
|
+
changeSchemasWithSameTypeSelection,
|
|
214278
214338
|
options,
|
|
214279
214339
|
pluginsRegistry,
|
|
214280
214340
|
props,
|
|
@@ -214378,9 +214438,9 @@ var DetailView = (props) => {
|
|
|
214378
214438
|
});
|
|
214379
214439
|
}
|
|
214380
214440
|
}
|
|
214381
|
-
if (changes.length) form.validateFields().then(() =>
|
|
214441
|
+
if (changes.length) form.validateFields().then(() => changeSchemasWithSameTypeSelection(changes)).catch((reason) => {
|
|
214382
214442
|
if (reason.errorFields.length) changes = changes.filter((change) => !reason.errorFields.find((field) => field.name.includes(change.key)));
|
|
214383
|
-
if (changes.length)
|
|
214443
|
+
if (changes.length) changeSchemasWithSameTypeSelection(changes);
|
|
214384
214444
|
});
|
|
214385
214445
|
}, 100);
|
|
214386
214446
|
const activePlugin = pluginsRegistry.findByType(activeSchema.type);
|
|
@@ -214531,7 +214591,7 @@ var DetailView = (props) => {
|
|
|
214531
214591
|
};
|
|
214532
214592
|
const safeProperties = { ...propPanelSchema.properties };
|
|
214533
214593
|
if (typeof activePropPanelSchema === "function") {
|
|
214534
|
-
const { size, schemas, pageSize, basePdf,
|
|
214594
|
+
const { size, schemas, pageSize, basePdf, activeElements, deselectSchema, activeSchema } = props;
|
|
214535
214595
|
const functionResult = activePropPanelSchema({
|
|
214536
214596
|
size,
|
|
214537
214597
|
schemas,
|
|
@@ -214604,7 +214664,7 @@ var DetailView = (props) => {
|
|
|
214604
214664
|
});
|
|
214605
214665
|
};
|
|
214606
214666
|
var propsAreUnchanged = (prevProps, nextProps) => {
|
|
214607
|
-
return JSON.stringify(prevProps.activeSchema)
|
|
214667
|
+
return JSON.stringify(prevProps.activeSchema) === JSON.stringify(nextProps.activeSchema) && JSON.stringify(getElementIds(prevProps.activeElements)) === JSON.stringify(getElementIds(nextProps.activeElements));
|
|
214608
214668
|
};
|
|
214609
214669
|
var DetailView_default = import_react$9.memo(DetailView, propsAreUnchanged);
|
|
214610
214670
|
//#endregion
|
|
@@ -235266,6 +235326,81 @@ var Canvas = (props, ref) => {
|
|
|
235266
235326
|
};
|
|
235267
235327
|
var Canvas_default = (0, import_react$9.forwardRef)(Canvas);
|
|
235268
235328
|
//#endregion
|
|
235329
|
+
//#region src/designerSelection.ts
|
|
235330
|
+
var EMPTY_DESIGNER_SELECTION = {
|
|
235331
|
+
bounds: null,
|
|
235332
|
+
pageIndex: 0,
|
|
235333
|
+
schemas: []
|
|
235334
|
+
};
|
|
235335
|
+
var toPersistedSchema = (schema) => {
|
|
235336
|
+
const cloned = cloneDeep$1(schema);
|
|
235337
|
+
delete cloned.id;
|
|
235338
|
+
return cloned;
|
|
235339
|
+
};
|
|
235340
|
+
var getSelectionBounds = (schemas) => {
|
|
235341
|
+
if (schemas.length === 0) return null;
|
|
235342
|
+
const left = Math.min(...schemas.map(({ schema }) => schema.position.x));
|
|
235343
|
+
const top = Math.min(...schemas.map(({ schema }) => schema.position.y));
|
|
235344
|
+
const right = Math.max(...schemas.map(({ schema }) => schema.position.x + schema.width));
|
|
235345
|
+
return {
|
|
235346
|
+
height: Math.max(...schemas.map(({ schema }) => schema.position.y + schema.height)) - top,
|
|
235347
|
+
width: right - left,
|
|
235348
|
+
x: left,
|
|
235349
|
+
y: top
|
|
235350
|
+
};
|
|
235351
|
+
};
|
|
235352
|
+
var createDesignerSelection = ({ activeSchemaIds, pageIndex, schemasList }) => {
|
|
235353
|
+
const pageSchemas = schemasList[pageIndex] ?? [];
|
|
235354
|
+
const selectedSchemas = activeSchemaIds.flatMap((schemaId) => {
|
|
235355
|
+
const schemaIndex = pageSchemas.findIndex((schema) => schema.id === schemaId);
|
|
235356
|
+
const schema = pageSchemas[schemaIndex];
|
|
235357
|
+
if (schemaIndex === -1 || !schema) return [];
|
|
235358
|
+
return [{
|
|
235359
|
+
name: schema.name,
|
|
235360
|
+
pageIndex,
|
|
235361
|
+
schema: toPersistedSchema(schema),
|
|
235362
|
+
schemaId: schema.id,
|
|
235363
|
+
schemaIndex,
|
|
235364
|
+
type: schema.type
|
|
235365
|
+
}];
|
|
235366
|
+
});
|
|
235367
|
+
return {
|
|
235368
|
+
bounds: getSelectionBounds(selectedSchemas),
|
|
235369
|
+
pageIndex,
|
|
235370
|
+
schemas: selectedSchemas
|
|
235371
|
+
};
|
|
235372
|
+
};
|
|
235373
|
+
var normalizeDesignerSchemaSelectionTargets = (targets) => Array.isArray(targets) ? targets : [targets];
|
|
235374
|
+
var getDesignerSelectionPageIndex = (targets, fallbackPageIndex, options = {}) => {
|
|
235375
|
+
const optionPageIndex = options.pageIndex;
|
|
235376
|
+
if (Number.isInteger(optionPageIndex) && optionPageIndex !== void 0 && optionPageIndex >= 0) return optionPageIndex;
|
|
235377
|
+
const targetPageIndex = targets.find((target) => typeof target === "object" && target !== null)?.pageIndex;
|
|
235378
|
+
return Number.isInteger(targetPageIndex) && targetPageIndex !== void 0 && targetPageIndex >= 0 ? targetPageIndex : fallbackPageIndex;
|
|
235379
|
+
};
|
|
235380
|
+
var getSelectedSchemaIds = ({ pageIndex, schemas, targets }) => {
|
|
235381
|
+
const selectedIds = /* @__PURE__ */ new Set();
|
|
235382
|
+
targets.forEach((target) => {
|
|
235383
|
+
schemas.forEach((schema, schemaIndex) => {
|
|
235384
|
+
if (typeof target === "string") {
|
|
235385
|
+
if (schema.id === target || schema.name === target) selectedIds.add(schema.id);
|
|
235386
|
+
return;
|
|
235387
|
+
}
|
|
235388
|
+
if (Number.isInteger(target.pageIndex) && target.pageIndex !== void 0 && target.pageIndex !== pageIndex) return;
|
|
235389
|
+
if (!(target.schemaId !== void 0 || target.schemaIndex !== void 0 || target.name !== void 0)) return;
|
|
235390
|
+
if (target.schemaId !== void 0 && target.schemaId === schema.id) {
|
|
235391
|
+
selectedIds.add(schema.id);
|
|
235392
|
+
return;
|
|
235393
|
+
}
|
|
235394
|
+
if (target.schemaIndex !== void 0 && target.schemaIndex === schemaIndex) {
|
|
235395
|
+
selectedIds.add(schema.id);
|
|
235396
|
+
return;
|
|
235397
|
+
}
|
|
235398
|
+
if (target.name !== void 0 && target.name === schema.name) selectedIds.add(schema.id);
|
|
235399
|
+
});
|
|
235400
|
+
});
|
|
235401
|
+
return [...selectedIds];
|
|
235402
|
+
};
|
|
235403
|
+
//#endregion
|
|
235269
235404
|
//#region src/components/Spinner.tsx
|
|
235270
235405
|
var Spinner = () => {
|
|
235271
235406
|
const { token } = theme_default.useToken();
|
|
@@ -235541,7 +235676,7 @@ var scaleDragPosAdjustment = (adjustment, scale) => {
|
|
|
235541
235676
|
if (scale < 1) return adjustment * -(1 - scale);
|
|
235542
235677
|
return 0;
|
|
235543
235678
|
};
|
|
235544
|
-
var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPageCursorChange }) => {
|
|
235679
|
+
var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPageCursorChange, onChangeSelection, onRegisterSchemaSelectionHandler }) => {
|
|
235545
235680
|
const past = (0, import_react$9.useRef)([]);
|
|
235546
235681
|
const future = (0, import_react$9.useRef)([]);
|
|
235547
235682
|
const canvasRef = (0, import_react$9.useRef)(null);
|
|
@@ -235564,10 +235699,59 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
|
|
|
235564
235699
|
zoomLevel,
|
|
235565
235700
|
maxZoom
|
|
235566
235701
|
});
|
|
235702
|
+
const getElementsByIds = (ids) => ids.map((id) => document.getElementById(id)).filter((element) => element instanceof HTMLElement);
|
|
235567
235703
|
const onEdit = (targets) => {
|
|
235568
235704
|
setActiveElements(targets.filter((target) => target instanceof HTMLElement));
|
|
235569
235705
|
setHoveringSchemaId(null);
|
|
235570
235706
|
};
|
|
235707
|
+
const selectSchemas = (0, import_react$9.useCallback)((targets, options = {}) => {
|
|
235708
|
+
const normalizedTargets = normalizeDesignerSchemaSelectionTargets(targets);
|
|
235709
|
+
if (normalizedTargets.length === 0) {
|
|
235710
|
+
onEditEnd();
|
|
235711
|
+
return;
|
|
235712
|
+
}
|
|
235713
|
+
const targetPageIndex = getDesignerSelectionPageIndex(normalizedTargets, pageCursor, options);
|
|
235714
|
+
const selectedSchemaIds = getSelectedSchemaIds({
|
|
235715
|
+
pageIndex: targetPageIndex,
|
|
235716
|
+
schemas: schemasList[targetPageIndex] ?? [],
|
|
235717
|
+
targets: normalizedTargets
|
|
235718
|
+
});
|
|
235719
|
+
const editSelectedSchemas = () => onEdit(getElementsByIds(selectedSchemaIds));
|
|
235720
|
+
if (selectedSchemaIds.length === 0) {
|
|
235721
|
+
onEditEnd();
|
|
235722
|
+
return;
|
|
235723
|
+
}
|
|
235724
|
+
if (targetPageIndex !== pageCursor) {
|
|
235725
|
+
setPageCursor(targetPageIndex);
|
|
235726
|
+
onPageCursorChange(targetPageIndex, schemasList.length);
|
|
235727
|
+
if (options.scroll !== false && canvasRef.current) canvasRef.current.scrollTop = getPagesScrollTopByIndex(pageSizes, targetPageIndex, scale);
|
|
235728
|
+
setTimeout(editSelectedSchemas);
|
|
235729
|
+
return;
|
|
235730
|
+
}
|
|
235731
|
+
editSelectedSchemas();
|
|
235732
|
+
}, [
|
|
235733
|
+
pageCursor,
|
|
235734
|
+
pageSizes,
|
|
235735
|
+
scale,
|
|
235736
|
+
schemasList,
|
|
235737
|
+
onPageCursorChange
|
|
235738
|
+
]);
|
|
235739
|
+
(0, import_react$9.useEffect)(() => {
|
|
235740
|
+
onRegisterSchemaSelectionHandler?.(selectSchemas);
|
|
235741
|
+
return () => onRegisterSchemaSelectionHandler?.(null);
|
|
235742
|
+
}, [onRegisterSchemaSelectionHandler, selectSchemas]);
|
|
235743
|
+
(0, import_react$9.useEffect)(() => {
|
|
235744
|
+
onChangeSelection?.(createDesignerSelection({
|
|
235745
|
+
activeSchemaIds: activeElements.map((element) => element.id),
|
|
235746
|
+
pageIndex: pageCursor,
|
|
235747
|
+
schemasList
|
|
235748
|
+
}));
|
|
235749
|
+
}, [
|
|
235750
|
+
activeElements,
|
|
235751
|
+
onChangeSelection,
|
|
235752
|
+
pageCursor,
|
|
235753
|
+
schemasList
|
|
235754
|
+
]);
|
|
235571
235755
|
const onEditEnd = () => {
|
|
235572
235756
|
setActiveElements([]);
|
|
235573
235757
|
setHoveringSchemaId(null);
|
|
@@ -235913,7 +236097,10 @@ var Designer = class extends BaseUIClass {
|
|
|
235913
236097
|
_defineProperty$14(this, "onSaveTemplateCallback", void 0);
|
|
235914
236098
|
_defineProperty$14(this, "onChangeTemplateCallback", void 0);
|
|
235915
236099
|
_defineProperty$14(this, "onPageChangeCallback", void 0);
|
|
236100
|
+
_defineProperty$14(this, "onChangeSelectionCallback", void 0);
|
|
235916
236101
|
_defineProperty$14(this, "pageCursor", 0);
|
|
236102
|
+
_defineProperty$14(this, "selection", EMPTY_DESIGNER_SELECTION);
|
|
236103
|
+
_defineProperty$14(this, "selectSchemasHandler", null);
|
|
235917
236104
|
checkDesignerProps(props);
|
|
235918
236105
|
}
|
|
235919
236106
|
saveTemplate() {
|
|
@@ -235936,6 +236123,20 @@ var Designer = class extends BaseUIClass {
|
|
|
235936
236123
|
onPageChange(cb) {
|
|
235937
236124
|
this.onPageChangeCallback = cb;
|
|
235938
236125
|
}
|
|
236126
|
+
onChangeSelection(cb) {
|
|
236127
|
+
this.onChangeSelectionCallback = cb;
|
|
236128
|
+
}
|
|
236129
|
+
getSelection() {
|
|
236130
|
+
if (!this.domContainer) throw Error(DESTROYED_ERR_MSG);
|
|
236131
|
+
return cloneDeep$1(this.selection);
|
|
236132
|
+
}
|
|
236133
|
+
getSelectedSchemas() {
|
|
236134
|
+
return this.getSelection().schemas;
|
|
236135
|
+
}
|
|
236136
|
+
selectSchemas(targets, options) {
|
|
236137
|
+
if (!this.domContainer) throw Error(DESTROYED_ERR_MSG);
|
|
236138
|
+
this.selectSchemasHandler?.(targets, options);
|
|
236139
|
+
}
|
|
235939
236140
|
getPageCursor() {
|
|
235940
236141
|
return this.pageCursor;
|
|
235941
236142
|
}
|
|
@@ -235969,6 +236170,13 @@ var Designer = class extends BaseUIClass {
|
|
|
235969
236170
|
totalPages
|
|
235970
236171
|
});
|
|
235971
236172
|
},
|
|
236173
|
+
onChangeSelection: (selection) => {
|
|
236174
|
+
this.selection = cloneDeep$1(selection);
|
|
236175
|
+
if (this.onChangeSelectionCallback) this.onChangeSelectionCallback(cloneDeep$1(selection));
|
|
236176
|
+
},
|
|
236177
|
+
onRegisterSchemaSelectionHandler: (handler) => {
|
|
236178
|
+
this.selectSchemasHandler = handler;
|
|
236179
|
+
},
|
|
235972
236180
|
size: this.size
|
|
235973
236181
|
})
|
|
235974
236182
|
}));
|