@uniformdev/context-ui 20.3.1-alpha.7 → 20.4.1-alpha.3

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.esm.js CHANGED
@@ -289,39 +289,23 @@ var contextCriteriaMenuOperators = [
289
289
  {
290
290
  name: "has the weakest score",
291
291
  value: "-"
292
- }
293
- ];
294
- var enrichmentCriteriaMenuOperators = [
295
- ...contextCriteriaMenuOperators,
292
+ },
296
293
  {
297
294
  name: "has strongest category score",
298
295
  value: "^"
299
296
  }
300
297
  ];
301
- var quirkCriteriaMenuOperators = [
302
- {
303
- name: "=",
304
- description: "equals",
305
- value: "="
306
- },
307
- {
308
- name: "\u2260",
309
- description: "not equal",
310
- value: "!="
311
- }
312
- ];
313
- function CriteriaOperatorMenu({ onChange, value, rhsType, ...props }) {
298
+ function CriteriaOperatorMenu({ onChange, value, ...props }) {
314
299
  var _a, _b;
315
- const operators = rhsType === "QUIRK" ? quirkCriteriaMenuOperators : rhsType === "ENR" ? enrichmentCriteriaMenuOperators : contextCriteriaMenuOperators;
316
300
  return /* @__PURE__ */ jsx6(
317
301
  InputComboBox,
318
302
  {
319
303
  ...props,
320
304
  value: {
321
- label: (_b = (_a = operators.find((e) => e.value === value)) == null ? void 0 : _a.name) != null ? _b : value,
305
+ label: (_b = (_a = contextCriteriaMenuOperators.find((e) => e.value === value)) == null ? void 0 : _a.name) != null ? _b : value,
322
306
  value
323
307
  },
324
- options: operators.map((option) => ({
308
+ options: contextCriteriaMenuOperators.map((option) => ({
325
309
  label: option.description ? `${option.name}:${option.description}` : option.name,
326
310
  value: option.value
327
311
  })),
@@ -559,23 +543,18 @@ import { useState as useState5 } from "react";
559
543
  import { Icon } from "@uniformdev/design-system";
560
544
 
561
545
  // src/components/DimensionMenu/utils.ts
562
- import { useMemo } from "react";
563
546
  function dimensionToMenuOption(dimension) {
564
- if ("dim" in dimension) {
565
- return {
566
- label: dimension.displayName,
567
- value: dimension.dim,
568
- original: dimension
569
- };
570
- }
571
- const quirk = dimension;
572
547
  return {
573
- label: `Quirk:${quirk.name}`,
574
- value: quirk.id,
575
- original: quirk
548
+ label: dimension.displayName,
549
+ value: dimension.dim,
550
+ isDisabled: false
576
551
  };
577
552
  }
578
- function dimensionIcon(type) {
553
+ function dimensionIcon(displayName) {
554
+ if (!displayName) {
555
+ return "unavailable";
556
+ }
557
+ const [type] = displayName.split(":");
579
558
  switch (type.toLowerCase()) {
580
559
  case "signal":
581
560
  return "data";
@@ -587,42 +566,25 @@ function dimensionIcon(type) {
587
566
  return "user-list";
588
567
  }
589
568
  }
590
- function useGroupedDimensions(dimensions, quirks) {
591
- return useMemo(() => {
592
- const result = [];
593
- let lastType = "";
594
- for (const dim of dimensions) {
595
- const { type } = dimensionDisplayName(dim.displayName);
596
- if (lastType !== type) {
597
- result.push({ label: type != null ? type : "", options: [] });
598
- lastType = type != null ? type : "";
599
- }
600
- result[result.length - 1].options.push(dimensionToMenuOption(dim));
601
- }
602
- if (quirks == null ? void 0 : quirks.length) {
603
- result.push({
604
- label: "Quirks",
605
- options: quirks.map(dimensionToMenuOption)
606
- });
569
+ function groupDimensions(dimensions) {
570
+ const result = [];
571
+ let lastType = "";
572
+ for (const dim of dimensions) {
573
+ const [type] = dim.displayName.split(":");
574
+ if (lastType !== type) {
575
+ result.push({ label: type, options: [] });
576
+ lastType = type;
607
577
  }
608
- return result;
609
- }, [dimensions, quirks]);
610
- }
611
- function dimensionDisplayName(displayName) {
612
- if (!displayName) {
613
- return {};
578
+ result[result.length - 1].options.push(dimensionToMenuOption(dim));
614
579
  }
615
- const colonIndex = displayName.indexOf(":");
616
- const type = colonIndex >= 0 ? displayName.substring(0, colonIndex) : void 0;
617
- const name = colonIndex >= 0 ? displayName.substring(colonIndex + 1) : displayName;
618
- return { type, name };
580
+ return result;
619
581
  }
620
582
 
621
583
  // src/components/DimensionMenu/DimensionGroupHeading.tsx
622
584
  import { jsx as jsx8, jsxs as jsxs3 } from "@emotion/react/jsx-runtime";
623
585
  var DimensionGroupHeading = (props) => {
586
+ var _a;
624
587
  const { data, getStyles, className } = props;
625
- const { type } = dimensionDisplayName(data.label);
626
588
  return /* @__PURE__ */ jsx8(
627
589
  "div",
628
590
  {
@@ -637,7 +599,7 @@ var DimensionGroupHeading = (props) => {
637
599
  {
638
600
  css: { color: "var(--gray-500)", display: "flex", alignItems: "center", gap: "var(--spacing-xs)" },
639
601
  children: [
640
- type ? /* @__PURE__ */ jsx8(Icon, { icon: dimensionIcon(type), iconColor: "currentColor", size: 16 }) : null,
602
+ /* @__PURE__ */ jsx8(Icon, { icon: dimensionIcon((_a = data.label) != null ? _a : ""), iconColor: "currentColor", size: 16 }),
641
603
  /* @__PURE__ */ jsx8("span", { children: data.label })
642
604
  ]
643
605
  }
@@ -668,8 +630,9 @@ function DimensionMenuErrorMessage({ message }) {
668
630
  // src/components/DimensionMenu/DimensionOption.tsx
669
631
  import { jsx as jsx10 } from "@emotion/react/jsx-runtime";
670
632
  var DimensionOption = (props) => {
633
+ var _a, _b;
671
634
  const { data, getStyles, cx, isDisabled, isFocused, isSelected, className, innerRef, innerProps } = props;
672
- const { name } = dimensionDisplayName(data.label);
635
+ const [, value] = (_b = (_a = data.label) == null ? void 0 : _a.split(":")) != null ? _b : [];
673
636
  return /* @__PURE__ */ jsx10(
674
637
  "div",
675
638
  {
@@ -686,7 +649,7 @@ var DimensionOption = (props) => {
686
649
  ref: innerRef,
687
650
  "aria-disabled": isDisabled,
688
651
  ...innerProps,
689
- children: /* @__PURE__ */ jsx10("div", { css: { color: "var(--gray-700)" }, children: name != null ? name : data.label })
652
+ children: /* @__PURE__ */ jsx10("div", { css: { color: "var(--gray-700)" }, children: value != null ? value : data.label })
690
653
  }
691
654
  );
692
655
  };
@@ -695,7 +658,7 @@ var DimensionOption = (props) => {
695
658
  import { Icon as Icon2 } from "@uniformdev/design-system";
696
659
  import { jsx as jsx11, jsxs as jsxs4 } from "@emotion/react/jsx-runtime";
697
660
  function DimensionValue({ displayName }) {
698
- const { type, name } = dimensionDisplayName(displayName);
661
+ const [type, name] = displayName.split(":");
699
662
  return /* @__PURE__ */ jsxs4(
700
663
  "div",
701
664
  {
@@ -704,7 +667,7 @@ function DimensionValue({ displayName }) {
704
667
  overflow: "hidden"
705
668
  },
706
669
  children: [
707
- type ? /* @__PURE__ */ jsxs4(
670
+ name ? /* @__PURE__ */ jsxs4(
708
671
  "small",
709
672
  {
710
673
  css: { color: "var(--gray-500)", display: "flex", alignItems: "center", gap: "var(--spacing-xs)" },
@@ -742,7 +705,6 @@ function CriteriaMatchMenu({
742
705
  );
743
706
  const rDim = criteriaMatch.rDim;
744
707
  const targetDim = criteriaMatch.rDim ? dimensions.dimIndex[criteriaMatch.rDim] : void 0;
745
- const groupedDimensions = useGroupedDimensions(dimensions.dimensions, void 0);
746
708
  return /* @__PURE__ */ jsxs5(Fragment3, { children: [
747
709
  /* @__PURE__ */ jsx13(
748
710
  InputComboBox3,
@@ -761,7 +723,7 @@ function CriteriaMatchMenu({
761
723
  value: "",
762
724
  isDisabled: true
763
725
  },
764
- ...groupedDimensions
726
+ ...groupDimensions(dimensions.dimensions)
765
727
  ],
766
728
  styles: {
767
729
  ...props.styles,
@@ -840,23 +802,14 @@ function isInt(value) {
840
802
  // src/components/DimensionMenu/DimensionMenu.tsx
841
803
  import { InputComboBox as InputComboBox4 } from "@uniformdev/design-system";
842
804
  import { Fragment as Fragment4, jsx as jsx14, jsxs as jsxs6 } from "@emotion/react/jsx-runtime";
843
- function DimensionMenu({
844
- onChange,
845
- value,
846
- dimensions,
847
- errorMessage,
848
- quirks,
849
- ...props
850
- }) {
851
- const groupedDimensions = useGroupedDimensions(dimensions, quirks);
852
- const valueAsMenuOption = value ? dimensionToMenuOption(value) : void 0;
805
+ function DimensionMenu({ onChange, value, dimensions, errorMessage, ...props }) {
853
806
  return /* @__PURE__ */ jsxs6(Fragment4, { children: [
854
807
  /* @__PURE__ */ jsx14(
855
808
  InputComboBox4,
856
809
  {
857
810
  ...props,
858
- value: valueAsMenuOption,
859
- options: groupedDimensions,
811
+ value: value ? dimensionToMenuOption(value) : void 0,
812
+ options: groupDimensions(dimensions),
860
813
  styles: {
861
814
  ...props.styles,
862
815
  valueContainer: (provided, state) => {
@@ -869,8 +822,8 @@ function DimensionMenu({
869
822
  }
870
823
  },
871
824
  onChange: (e) => {
872
- if (e == null ? void 0 : e.original) {
873
- onChange(e.original);
825
+ if (e) {
826
+ onChange(dimensions.find((d) => d.dim === e.value));
874
827
  }
875
828
  },
876
829
  components: {
@@ -939,7 +892,7 @@ import {
939
892
  LoadingIndicator as LoadingIndicator3
940
893
  } from "@uniformdev/design-system";
941
894
  import { produce } from "immer";
942
- import { useMemo as useMemo2, useState as useState6 } from "react";
895
+ import { useMemo, useState as useState6 } from "react";
943
896
  import { Fragment as Fragment5, jsx as jsx16, jsxs as jsxs8 } from "@emotion/react/jsx-runtime";
944
897
  var addEnrichmentLink = css5`
945
898
  flex: 2;
@@ -960,10 +913,10 @@ var EnrichmentTag = ({
960
913
  displayTitle = true
961
914
  }) => {
962
915
  const { loading, result: dimensions, error } = useDimensions(contextConfig);
963
- const allEnrichments = useMemo2(() => {
916
+ const allEnrichments = useMemo(() => {
964
917
  if (dimensions) return dimensions.dimensions.filter((dimension) => dimension.category === "ENR");
965
918
  }, [dimensions]);
966
- const remainingEnrichments = useMemo2(() => {
919
+ const remainingEnrichments = useMemo(() => {
967
920
  if (!value) return allEnrichments;
968
921
  if (allEnrichments)
969
922
  return allEnrichments.filter(
@@ -1309,15 +1262,7 @@ function opHasRhs(op) {
1309
1262
  // src/components/PersonalizationCriteria/PersonalizationCriteriaStatic.tsx
1310
1263
  import { css as css7 } from "@emotion/react";
1311
1264
  import { CgCloseO as CgCloseO2 } from "@react-icons/all-files/cg/CgCloseO";
1312
- import {
1313
- AddListButton as AddListButton3,
1314
- Callout as Callout3,
1315
- Icon as Icon5,
1316
- Input as Input2,
1317
- InputInlineSelect,
1318
- InputSelect as InputSelect2,
1319
- Paragraph
1320
- } from "@uniformdev/design-system";
1265
+ import { AddListButton as AddListButton3, Callout as Callout3, Icon as Icon5, InputInlineSelect, Paragraph } from "@uniformdev/design-system";
1321
1266
  import { produce as produce2 } from "immer";
1322
1267
 
1323
1268
  // src/components/PersonalizationCriteria/PersonalizationCriteriaStatic.styles.ts
@@ -1353,8 +1298,7 @@ var criteriaItem = css6`
1353
1298
  `;
1354
1299
  var criteriaItemInner = css6`
1355
1300
  display: flex;
1356
- row-gap: var(--spacing-base);
1357
- column-gap: var(--spacing-xs);
1301
+ gap: var(--spacing-base);
1358
1302
  flex-grow: 1;
1359
1303
  flex-wrap: wrap;
1360
1304
  margin-right: var(--spacing-base);
@@ -1372,7 +1316,6 @@ var criteriaOperandWrapper = css6`
1372
1316
  `;
1373
1317
  var criteriaOperatorWrapper = css6`
1374
1318
  flex: 1;
1375
- flex-wrap: nowrap;
1376
1319
  min-width: 80px;
1377
1320
  `;
1378
1321
  var expand = css6`
@@ -1386,7 +1329,6 @@ var PersonalizationCriteriaStatic = ({
1386
1329
  value,
1387
1330
  setValue,
1388
1331
  dimensions,
1389
- quirks,
1390
1332
  onMenuOpen,
1391
1333
  onMenuClose,
1392
1334
  onAddCriteria,
@@ -1442,137 +1384,94 @@ var PersonalizationCriteriaStatic = ({
1442
1384
  (components == null ? void 0 : components.CustomVariantName) ? /* @__PURE__ */ jsx17(components.CustomVariantName, {}) : null,
1443
1385
  (components == null ? void 0 : components.ControlPercentage) ? /* @__PURE__ */ jsx17(components.ControlPercentage, {}) : null,
1444
1386
  !currentValue.crit.length ? /* @__PURE__ */ jsx17(Callout3, { title: "Default variant", type: "info", css: { marginBlock: "var(--spacing-base)" }, children: /* @__PURE__ */ jsx17(Paragraph, { children: 'This personalized variant has no match criteria and will be shown to any visitor that does not match any preceding variants. Ensure that default variants come last in the variant list. Personalize this variant by clicking "Add Criteria" to get started.' }) }) : /* @__PURE__ */ jsx17("div", { children: currentValue.crit.map((currentCriteria, index) => {
1445
- var _a2, _b, _c, _d, _e, _f, _g, _h;
1387
+ var _a2, _b, _c, _d;
1446
1388
  const critHasLhs = ((_a2 = currentCriteria.l) == null ? void 0 : _a2.length) > 0;
1447
1389
  const critHasRhs = opHasRhs(currentCriteria.op);
1448
- const currentDimension = dimensions.dimIndex[currentCriteria.l];
1449
- const currentQuirk = quirks == null ? void 0 : quirks.find((q) => q.id === currentCriteria.l);
1450
1390
  return /* @__PURE__ */ jsxs9("div", { css: criteriaItem, "data-testid": "criteria-container", children: [
1451
- /* @__PURE__ */ jsxs9("div", { css: criteriaItemInner, className: "criteriaItemInner", children: [
1452
- /* @__PURE__ */ jsx17(
1453
- "div",
1454
- {
1455
- css: [criteriaWrapper, criteriaOperandWrapper],
1456
- className: "criteria-wrapper",
1457
- "data-testid": "select-criteria",
1458
- children: /* @__PURE__ */ jsx17(
1459
- DimensionMenu,
1391
+ /* @__PURE__ */ jsxs9(
1392
+ "div",
1393
+ {
1394
+ css: css7`
1395
+ ${criteriaItemInner}/* grid-template-columns: minmax(0, 1fr) ${critHasRhs ? "minmax(0, 79px) minmax(0, 1fr)" : "minmax(0, 1fr)"} */
1396
+ `,
1397
+ className: "criteriaItemInner",
1398
+ children: [
1399
+ /* @__PURE__ */ jsx17(
1400
+ "div",
1460
1401
  {
1461
- errorMessage: (_b = errors.lhs) == null ? void 0 : _b[index],
1462
- css: expand,
1463
- styles: { control: (base) => ({ ...base, height: "100%" }) },
1464
- dimensions: dimensions.dimensions,
1465
- quirks,
1466
- onChange: (selection) => {
1467
- if ("dim" in selection) {
1468
- const newCriteria = {
1469
- ...currentCriteria,
1470
- l: selection.dim,
1471
- t: void 0,
1472
- op: ">",
1473
- r: 0
1474
- };
1475
- update(newCriteria, index);
1476
- } else {
1477
- update({ ...currentCriteria, l: selection.id, t: "q", op: "=", r: "" }, index);
1402
+ css: [criteriaWrapper, criteriaOperandWrapper],
1403
+ className: "criteria-wrapper",
1404
+ "data-testid": "select-criteria",
1405
+ children: /* @__PURE__ */ jsx17(
1406
+ DimensionMenu,
1407
+ {
1408
+ errorMessage: (_b = errors.lhs) == null ? void 0 : _b[index],
1409
+ css: expand,
1410
+ styles: { control: (base) => ({ ...base, height: "100%" }) },
1411
+ dimensions: dimensions.dimensions,
1412
+ onChange: (dim) => {
1413
+ update({ ...currentCriteria, l: dim.dim }, index);
1414
+ },
1415
+ value: dimensions.dimIndex[currentCriteria.l],
1416
+ onMenuOpen,
1417
+ onMenuClose
1478
1418
  }
1479
- },
1480
- value: currentDimension != null ? currentDimension : currentQuirk,
1481
- onMenuOpen,
1482
- onMenuClose
1419
+ )
1483
1420
  }
1484
- )
1485
- }
1486
- ),
1487
- /* @__PURE__ */ jsx17(
1488
- "div",
1489
- {
1490
- css: [criteriaWrapper, criteriaOperatorWrapper],
1491
- className: "criteria-wrapper",
1492
- "data-testid": "select-operator",
1493
- children: /* @__PURE__ */ jsx17(
1494
- CriteriaOperatorMenu,
1421
+ ),
1422
+ /* @__PURE__ */ jsx17(
1423
+ "div",
1495
1424
  {
1496
- name: `op-${index}`,
1497
- css: expand,
1498
- styles: { control: (base) => ({ ...base, height: "100%" }) },
1499
- value: currentCriteria.op,
1500
- rhsType: currentQuirk ? "QUIRK" : currentDimension == null ? void 0 : currentDimension.category,
1501
- onChange: (op) => {
1502
- if (op === "+" || op === "-") {
1503
- update({ ...currentCriteria, op, r: void 0, rDim: void 0 }, index);
1504
- } else {
1505
- update({ ...currentCriteria, op }, index);
1425
+ css: [criteriaWrapper, criteriaOperatorWrapper],
1426
+ className: "criteria-wrapper",
1427
+ "data-testid": "select-operator",
1428
+ children: /* @__PURE__ */ jsx17(
1429
+ CriteriaOperatorMenu,
1430
+ {
1431
+ name: `op-${index}`,
1432
+ css: expand,
1433
+ styles: { control: (base) => ({ ...base, height: "100%" }) },
1434
+ value: currentCriteria.op,
1435
+ onChange: (op) => {
1436
+ if (op === "+" || op === "-") {
1437
+ update({ ...currentCriteria, op, r: void 0, rDim: void 0 }, index);
1438
+ } else {
1439
+ update({ ...currentCriteria, op }, index);
1440
+ }
1441
+ },
1442
+ onMenuOpen,
1443
+ onMenuClose
1506
1444
  }
1507
- },
1508
- onMenuOpen,
1509
- onMenuClose
1445
+ )
1510
1446
  }
1511
- )
1512
- }
1513
- ),
1514
- critHasRhs ? /* @__PURE__ */ jsx17(
1515
- "div",
1516
- {
1517
- css: [criteriaWrapper, criteriaOperandWrapper],
1518
- className: "criteria-wrapper",
1519
- "data-testid": "select-match-criteria",
1520
- children: currentQuirk ? /* @__PURE__ */ jsx17(
1447
+ ),
1448
+ critHasRhs ? /* @__PURE__ */ jsx17(
1521
1449
  "div",
1522
1450
  {
1523
- css: css7`
1524
- width: 100%;
1525
- // InputSelect wrapper is unstylable so need a descendant selector
1526
- // to full-width it
1527
- & > * {
1528
- width: 100%;
1529
- }
1530
- `,
1531
- children: currentQuirk.options ? /* @__PURE__ */ jsx17(
1532
- InputSelect2,
1533
- {
1534
- label: "quirk match value",
1535
- showLabel: false,
1536
- value: (_c = currentCriteria.r) != null ? _c : "",
1537
- errorMessage: (_d = errors.rhs) == null ? void 0 : _d[index],
1538
- onChange: (e) => update({ ...currentCriteria, r: e.currentTarget.value }, index),
1539
- options: [
1540
- { label: "Select\u2026", value: "" },
1541
- ...currentQuirk.options.map((o) => ({ label: o.name, value: o.value }))
1542
- ]
1543
- }
1544
- ) : /* @__PURE__ */ jsx17(
1545
- Input2,
1451
+ css: [criteriaWrapper, criteriaOperandWrapper],
1452
+ className: "criteria-wrapper",
1453
+ "data-testid": "select-match-criteria",
1454
+ children: /* @__PURE__ */ jsx17(
1455
+ CriteriaMatchMenu,
1546
1456
  {
1547
- type: "text",
1548
- label: "quirk match value",
1549
- showLabel: false,
1550
- value: (_e = currentCriteria.r) != null ? _e : "",
1551
- errorMessage: (_f = errors.rhs) == null ? void 0 : _f[index],
1552
- onChange: (e) => update({ ...currentCriteria, r: e.currentTarget.value }, index),
1553
- placeholder: "Enter a value"
1457
+ errorMessage: (_c = errors.rhs) == null ? void 0 : _c[index],
1458
+ css: expand,
1459
+ styles: { control: (base) => ({ ...base, height: "100%" }) },
1460
+ criteriaMatch: currentCriteria,
1461
+ onChange: (match) => {
1462
+ update(match, index);
1463
+ },
1464
+ isDisabled: !critHasLhs,
1465
+ dimensions,
1466
+ onMenuOpen,
1467
+ onMenuClose
1554
1468
  }
1555
1469
  )
1556
1470
  }
1557
- ) : /* @__PURE__ */ jsx17(
1558
- CriteriaMatchMenu,
1559
- {
1560
- errorMessage: (_g = errors.rhs) == null ? void 0 : _g[index],
1561
- css: expand,
1562
- styles: { control: (base) => ({ ...base, height: "100%" }) },
1563
- criteriaMatch: currentCriteria,
1564
- onChange: (match) => {
1565
- update(match, index);
1566
- },
1567
- isDisabled: !critHasLhs,
1568
- dimensions,
1569
- onMenuOpen,
1570
- onMenuClose
1571
- }
1572
- )
1573
- }
1574
- ) : null
1575
- ] }),
1471
+ ) : null
1472
+ ]
1473
+ }
1474
+ ),
1576
1475
  /* @__PURE__ */ jsx17(
1577
1476
  "button",
1578
1477
  {
@@ -1598,7 +1497,7 @@ var PersonalizationCriteriaStatic = ({
1598
1497
  {
1599
1498
  "data-testid": "dropdown-button-combine",
1600
1499
  disabled: index > 1,
1601
- value: (_h = currentValue.op) != null ? _h : "&",
1500
+ value: (_d = currentValue.op) != null ? _d : "&",
1602
1501
  options: [
1603
1502
  { label: "AND", value: "&" },
1604
1503
  { label: "OR", value: "|" }
@@ -1830,7 +1729,6 @@ export {
1830
1729
  addEnrichmentLink,
1831
1730
  contextCriteriaMenuOperators,
1832
1731
  convertErrorsToObj,
1833
- enrichmentCriteriaMenuOperators,
1834
1732
  isEnrichmentTagData,
1835
1733
  isPersonalizationCriteriaData,
1836
1734
  opHasRhs,