@unlayer/react-elements 0.1.6 → 0.1.8

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.cjs CHANGED
@@ -234,15 +234,13 @@ function mapSemanticProps(props, defaultValues, componentType) {
234
234
  delete userProps.html;
235
235
  delete result.html;
236
236
  }
237
- const href = userProps.href;
238
- if (href !== void 0) {
239
- if (typeof href === "string") {
240
- userProps.href = {
237
+ for (const key of ["href", "action"]) {
238
+ const v = userProps[key];
239
+ if (typeof v === "string") {
240
+ userProps[key] = {
241
241
  name: "web",
242
- values: { href, target: "_blank" }
242
+ values: { href: v, target: "_blank" }
243
243
  };
244
- } else {
245
- userProps.href = href;
246
244
  }
247
245
  }
248
246
  const nestedGroups = analyzeNestedStructure(defaultValues);
@@ -281,6 +279,46 @@ function mapSemanticProps(props, defaultValues, componentType) {
281
279
  }
282
280
  return final;
283
281
  }
282
+ function normalizeLinkValue(value) {
283
+ if (value == null) return void 0;
284
+ if (typeof value === "string") {
285
+ return { url: value, target: "_blank" };
286
+ }
287
+ if (typeof value !== "object") return void 0;
288
+ const v = value;
289
+ if ("url" in v) return v;
290
+ if ("name" in v && v.values && typeof v.values === "object") {
291
+ const inner = v.values;
292
+ return {
293
+ url: inner.href ?? "",
294
+ target: inner.target ?? "_blank",
295
+ ...v.attrs ?? {}
296
+ };
297
+ }
298
+ return void 0;
299
+ }
300
+ function normalizeValuesForExporter(values, componentName) {
301
+ if (values == null || typeof values !== "object") return values;
302
+ const out = { ...values };
303
+ for (const key of ["href", "action"]) {
304
+ if (out[key] !== void 0) {
305
+ const normalized = normalizeLinkValue(out[key]);
306
+ if (normalized !== void 0) out[key] = normalized;
307
+ }
308
+ }
309
+ if (componentName === "Menu" && out.menu && Array.isArray(out.menu.items)) {
310
+ out.menu = {
311
+ ...out.menu,
312
+ items: out.menu.items.map((item) => {
313
+ if (!item || item.link === void 0) return item;
314
+ const normalized = normalizeLinkValue(item.link);
315
+ if (normalized === void 0) return item;
316
+ return { ...item, link: normalized };
317
+ })
318
+ };
319
+ }
320
+ return out;
321
+ }
284
322
  var HTML_ENTITIES = {
285
323
  "&": "&",
286
324
  "&lt;": "<",
@@ -470,10 +508,14 @@ function createItemComponent(config) {
470
508
  contentWidth: 600,
471
509
  ...bodyValues
472
510
  };
511
+ const valuesForExporter = normalizeValuesForExporter(
512
+ valuesWithMeta,
513
+ config.name
514
+ );
473
515
  const exporter = config.exporters[mode] || config.exporters.web;
474
516
  return renderComponent({
475
517
  type: config.name,
476
- values: valuesWithMeta,
518
+ values: valuesForExporter,
477
519
  className,
478
520
  style,
479
521
  args: [index, colIndex, cells, safeBodyValues, rowValues],