@pdfme/ui 6.1.2-dev.31 → 6.1.2-dev.33

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.
@@ -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[];
package/dist/index.js CHANGED
@@ -214183,34 +214183,70 @@ var WidgetRenderer = (props) => {
214183
214183
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref });
214184
214184
  };
214185
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
214186
214215
  //#region src/components/Designer/RightSidebar/DetailView/ButtonGroupWidget.tsx
214187
214216
  var ButtonGroupWidget = (props) => {
214188
- const { activeElements, changeSchemas, schemas, schema } = props;
214217
+ const { activeElements, activeSchema, changeSchemas, schemas, schema } = props;
214189
214218
  const { token } = theme_default.useToken();
214190
214219
  const buttons = Array.isArray(schema?.buttons) ? schema.buttons : [];
214191
- const apply = (btn) => {
214192
- const key = btn.key;
214193
- const type = btn.type;
214220
+ const getSelectedSchemas = () => {
214194
214221
  const ids = activeElements.map((ae) => ae.id);
214195
- changeSchemas(schemas.filter((s) => ids.includes(s.id)).map((s) => {
214196
- const oldValue = Boolean(s[key] ?? false);
214197
- return {
214198
- key,
214199
- value: type === "boolean" ? !oldValue : btn.value,
214200
- schemaId: s.id
214201
- };
214202
- }));
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
+ })));
214203
214240
  };
214204
214241
  const isActive = (btn) => {
214205
214242
  const key = btn.key;
214206
214243
  const type = btn.type;
214207
- let active = false;
214208
- const ids = activeElements.map((ae) => ae.id);
214209
- schemas.filter((s) => ids.includes(s.id)).forEach((s) => {
214244
+ const targetSchemas = getTargetSchemas();
214245
+ if (targetSchemas.length === 0) return false;
214246
+ return targetSchemas.every((s) => {
214210
214247
  const schemaRecord = s;
214211
- active = type === "boolean" ? Boolean(schemaRecord[key] ?? false) : schemaRecord[key] === btn.value;
214248
+ return type === "boolean" ? Boolean(schemaRecord[key] ?? false) : schemaRecord[key] === btn.value;
214212
214249
  });
214213
- return active;
214214
214250
  };
214215
214251
  const replaceCurrentColor = (svgString, color) => color ? svgString.replace(/="currentColor"/g, `="${color}"`) : svgString;
214216
214252
  const svgIcon = (svgString) => {
@@ -214239,6 +214275,7 @@ var ButtonGroupWidget = (props) => {
214239
214275
  //#region src/components/Designer/RightSidebar/DetailView/index.tsx
214240
214276
  var { Text: Text$2 } = Typography;
214241
214277
  var TEXT_OVERFLOW_EXPAND_SCHEMA_TYPES = new Set(["text", "multiVariableText"]);
214278
+ var getElementIds = (elements) => elements.map(({ id }) => id);
214242
214279
  var DetailView = (props) => {
214243
214280
  const { token } = theme_default.useToken();
214244
214281
  const { schemasList, changeSchemas, deselectSchema, activeSchema, pageSize, basePdf } = props;
@@ -214246,6 +214283,19 @@ var DetailView = (props) => {
214246
214283
  const i18n = (0, import_react$9.useContext)(I18nContext);
214247
214284
  const pluginsRegistry = (0, import_react$9.useContext)(PluginsRegistry);
214248
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
+ ]);
214249
214299
  const typedI18n = (0, import_react$9.useCallback)((key) => {
214250
214300
  return typeof i18n === "function" ? i18n(key) : key;
214251
214301
  }, [i18n]);
@@ -214254,6 +214304,7 @@ var DetailView = (props) => {
214254
214304
  AlignWidget: (p) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlignWidget, {
214255
214305
  ...p,
214256
214306
  ...props,
214307
+ changeSchemas: changeSchemasWithSameTypeSelection,
214257
214308
  options
214258
214309
  }),
214259
214310
  Divider: () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Divider$2, { style: {
@@ -214263,6 +214314,7 @@ var DetailView = (props) => {
214263
214314
  ButtonGroup: (p) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ButtonGroupWidget, {
214264
214315
  ...p,
214265
214316
  ...props,
214317
+ changeSchemas: changeSchemasWithSameTypeSelection,
214266
214318
  options
214267
214319
  })
214268
214320
  };
@@ -214272,6 +214324,7 @@ var DetailView = (props) => {
214272
214324
  newWidgets[widgetKey] = (p) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WidgetRenderer, {
214273
214325
  ...p,
214274
214326
  ...props,
214327
+ changeSchemas: changeSchemasWithSameTypeSelection,
214275
214328
  options,
214276
214329
  theme: token,
214277
214330
  i18n: typedI18n,
@@ -214281,6 +214334,7 @@ var DetailView = (props) => {
214281
214334
  }
214282
214335
  return newWidgets;
214283
214336
  }, [
214337
+ changeSchemasWithSameTypeSelection,
214284
214338
  options,
214285
214339
  pluginsRegistry,
214286
214340
  props,
@@ -214384,9 +214438,9 @@ var DetailView = (props) => {
214384
214438
  });
214385
214439
  }
214386
214440
  }
214387
- if (changes.length) form.validateFields().then(() => changeSchemas(changes)).catch((reason) => {
214441
+ if (changes.length) form.validateFields().then(() => changeSchemasWithSameTypeSelection(changes)).catch((reason) => {
214388
214442
  if (reason.errorFields.length) changes = changes.filter((change) => !reason.errorFields.find((field) => field.name.includes(change.key)));
214389
- if (changes.length) changeSchemas(changes);
214443
+ if (changes.length) changeSchemasWithSameTypeSelection(changes);
214390
214444
  });
214391
214445
  }, 100);
214392
214446
  const activePlugin = pluginsRegistry.findByType(activeSchema.type);
@@ -214537,7 +214591,7 @@ var DetailView = (props) => {
214537
214591
  };
214538
214592
  const safeProperties = { ...propPanelSchema.properties };
214539
214593
  if (typeof activePropPanelSchema === "function") {
214540
- const { size, schemas, pageSize, basePdf, changeSchemas, activeElements, deselectSchema, activeSchema } = props;
214594
+ const { size, schemas, pageSize, basePdf, activeElements, deselectSchema, activeSchema } = props;
214541
214595
  const functionResult = activePropPanelSchema({
214542
214596
  size,
214543
214597
  schemas,
@@ -214610,7 +214664,7 @@ var DetailView = (props) => {
214610
214664
  });
214611
214665
  };
214612
214666
  var propsAreUnchanged = (prevProps, nextProps) => {
214613
- return JSON.stringify(prevProps.activeSchema) == JSON.stringify(nextProps.activeSchema);
214667
+ return JSON.stringify(prevProps.activeSchema) === JSON.stringify(nextProps.activeSchema) && JSON.stringify(getElementIds(prevProps.activeElements)) === JSON.stringify(getElementIds(nextProps.activeElements));
214614
214668
  };
214615
214669
  var DetailView_default = import_react$9.memo(DetailView, propsAreUnchanged);
214616
214670
  //#endregion