@getlupa/vue 0.15.5 → 0.15.6

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.
@@ -12945,6 +12945,17 @@ const renderHtmlTemplate = (template, document2 = {}) => {
12945
12945
  const rendered = mustache.render(template, document2);
12946
12946
  return sanitizeHtml$1(rendered);
12947
12947
  };
12948
+ const getDynamicAttributes = (dynamicAttributes = [], document2 = {}) => {
12949
+ var _a, _b;
12950
+ const parsedAttributes = {};
12951
+ for (const attribute of dynamicAttributes) {
12952
+ if (!((_a = attribute == null ? void 0 : attribute.key) == null ? void 0 : _a.startsWith("data-"))) {
12953
+ continue;
12954
+ }
12955
+ parsedAttributes[attribute == null ? void 0 : attribute.key] = escapeHtml$1(mustache.render((_b = attribute == null ? void 0 : attribute.value) != null ? _b : "", document2));
12956
+ }
12957
+ return parsedAttributes;
12958
+ };
12948
12959
  const getFieldValue = (doc, field = "") => {
12949
12960
  var _a;
12950
12961
  if (typeof field === "number") {
@@ -13630,7 +13641,8 @@ const _sfc_main$1d = /* @__PURE__ */ vue.defineComponent({
13630
13641
  props: {
13631
13642
  item: {},
13632
13643
  options: {},
13633
- inStock: { type: Boolean }
13644
+ inStock: { type: Boolean },
13645
+ dynamicAttributes: {}
13634
13646
  },
13635
13647
  emits: ["productEvent"],
13636
13648
  setup(__props, { emit }) {
@@ -13660,13 +13672,13 @@ const _sfc_main$1d = /* @__PURE__ */ vue.defineComponent({
13660
13672
  return (_ctx, _cache) => {
13661
13673
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$15, [
13662
13674
  vue.createElementVNode("div", _hoisted_2$O, [
13663
- vue.createElementVNode("button", {
13675
+ vue.createElementVNode("button", vue.mergeProps({
13664
13676
  onClick: vue.withModifiers(handleClick, ["stop", "prevent"]),
13665
- class: vue.normalizeClass(loading.value ? "lupa-add-to-cart-loading" : "lupa-add-to-cart"),
13677
+ class: loading.value ? "lupa-add-to-cart-loading" : "lupa-add-to-cart",
13666
13678
  "data-cy": "lupa-add-to-cart",
13667
13679
  type: "button",
13668
13680
  disabled: !inStockValue.value || loading.value
13669
- }, vue.toDisplayString(label.value), 11, _hoisted_3$B)
13681
+ }, _ctx.dynamicAttributes), vue.toDisplayString(label.value), 17, _hoisted_3$B)
13670
13682
  ])
13671
13683
  ]);
13672
13684
  };
@@ -13721,6 +13733,9 @@ const _sfc_main$1c = /* @__PURE__ */ vue.defineComponent(__spreadProps(__spreadV
13721
13733
  }
13722
13734
  return "search-box-product-title";
13723
13735
  });
13736
+ const renderDynamicAttributesOnParentElement = vue.computed(() => {
13737
+ return props.element.type !== DocumentElementType.ADDTOCART;
13738
+ });
13724
13739
  const displayElement = vue.computed(() => {
13725
13740
  const element = props.element;
13726
13741
  const item = props.item;
@@ -13737,20 +13752,24 @@ const _sfc_main$1c = /* @__PURE__ */ vue.defineComponent(__spreadProps(__spreadV
13737
13752
  const enhancementData = (_d = (_c = dynamicDataIdMap.value) == null ? void 0 : _c[(_b = props.item) == null ? void 0 : _b.id]) != null ? _d : {};
13738
13753
  return __spreadValues(__spreadValues({}, props.item), enhancementData);
13739
13754
  });
13755
+ const dynamicAttributes = vue.computed(() => {
13756
+ return getDynamicAttributes(props.element.dynamicAttributes, enhancedItem.value);
13757
+ });
13740
13758
  const isLoadingDynamicData = (id) => {
13741
13759
  return Boolean(props.element.dynamic && id && loading.value && (loadingIds == null ? void 0 : loadingIds.value[id]));
13742
13760
  };
13743
13761
  return (_ctx, _cache) => {
13744
13762
  var _a, _b;
13745
13763
  return !_ctx.$slots.badges ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [
13746
- displayElement.value ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(elementComponent.value), {
13764
+ displayElement.value ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(elementComponent.value), vue.mergeProps({
13747
13765
  key: 0,
13748
13766
  item: enhancedItem.value,
13749
13767
  options: _ctx.element,
13750
13768
  labels: _ctx.labels,
13751
- class: vue.normalizeClass({ "lupa-loading-dynamic-data": isLoadingDynamicData((_a = _ctx.item) == null ? void 0 : _a.id) }),
13752
- inStock: _ctx.isInStock
13753
- }, null, 8, ["item", "options", "labels", "class", "inStock"])) : vue.createCommentVNode("", true)
13769
+ class: { "lupa-loading-dynamic-data": isLoadingDynamicData((_a = _ctx.item) == null ? void 0 : _a.id) },
13770
+ inStock: _ctx.isInStock,
13771
+ "dynamic-attributes": dynamicAttributes.value
13772
+ }, renderDynamicAttributesOnParentElement.value && dynamicAttributes.value), null, 16, ["item", "options", "labels", "class", "inStock", "dynamic-attributes"])) : vue.createCommentVNode("", true)
13754
13773
  ], 64)) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$14, [
13755
13774
  displayElement.value ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(elementComponent.value), {
13756
13775
  key: 0,
@@ -18642,7 +18661,8 @@ const _sfc_main$u = /* @__PURE__ */ vue.defineComponent({
18642
18661
  props: {
18643
18662
  item: {},
18644
18663
  options: {},
18645
- inStock: { type: Boolean }
18664
+ inStock: { type: Boolean },
18665
+ dynamicAttributes: {}
18646
18666
  },
18647
18667
  emits: ["productEvent"],
18648
18668
  setup(__props, { emit }) {
@@ -18677,13 +18697,14 @@ const _sfc_main$u = /* @__PURE__ */ vue.defineComponent({
18677
18697
  return (_ctx, _cache) => {
18678
18698
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$r, [
18679
18699
  vue.createElementVNode("div", _hoisted_2$m, [
18680
- vue.createElementVNode("button", {
18700
+ vue.createElementVNode("button", vue.mergeProps({
18681
18701
  id: id.value,
18682
- class: vue.normalizeClass(loading.value ? "lupa-add-to-cart-loading" : "lupa-add-to-cart"),
18702
+ class: loading.value ? "lupa-add-to-cart-loading" : "lupa-add-to-cart",
18683
18703
  "data-cy": "lupa-add-to-cart",
18684
- disabled: !inStockValue.value || loading.value,
18704
+ disabled: !inStockValue.value || loading.value
18705
+ }, _ctx.dynamicAttributes, {
18685
18706
  onClick: vue.withModifiers(handleClick, ["stop"])
18686
- }, vue.toDisplayString(label.value), 11, _hoisted_3$g)
18707
+ }), vue.toDisplayString(label.value), 17, _hoisted_3$g)
18687
18708
  ])
18688
18709
  ]);
18689
18710
  };
@@ -18879,6 +18900,9 @@ const _sfc_main$q = /* @__PURE__ */ vue.defineComponent(__spreadProps(__spreadVa
18879
18900
  }
18880
18901
  return "searchResultsProductTitle";
18881
18902
  });
18903
+ const renderDynamicAttributesOnParentElement = vue.computed(() => {
18904
+ return props.element.type !== DocumentElementType.ADDTOCART;
18905
+ });
18882
18906
  const enhancedItem = vue.computed(() => {
18883
18907
  var _a, _b, _c, _d;
18884
18908
  if (!((_a = props.item) == null ? void 0 : _a.id)) {
@@ -18895,6 +18919,9 @@ const _sfc_main$q = /* @__PURE__ */ vue.defineComponent(__spreadProps(__spreadVa
18895
18919
  }
18896
18920
  return typeof element.display === "function" ? element.display(item) : processDisplayCondition(element.display, item);
18897
18921
  });
18922
+ const dynamicAttributes = vue.computed(() => {
18923
+ return getDynamicAttributes(props.element.dynamicAttributes, enhancedItem.value);
18924
+ });
18898
18925
  const handleProductEvent = (item) => {
18899
18926
  emit("productEvent", item);
18900
18927
  };
@@ -18903,16 +18930,16 @@ const _sfc_main$q = /* @__PURE__ */ vue.defineComponent(__spreadProps(__spreadVa
18903
18930
  };
18904
18931
  return (_ctx, _cache) => {
18905
18932
  var _a;
18906
- return displayElement.value ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(elementComponent.value), {
18933
+ return displayElement.value ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(elementComponent.value), vue.mergeProps({
18907
18934
  key: 0,
18908
18935
  item: enhancedItem.value,
18909
18936
  options: _ctx.element,
18910
18937
  labels: _ctx.labels,
18911
18938
  inStock: _ctx.inStock,
18912
18939
  link: _ctx.link,
18913
- class: vue.normalizeClass({ "lupa-loading-dynamic-data": isLoadingDynamicData((_a = _ctx.item) == null ? void 0 : _a.id) }),
18914
- onProductEvent: handleProductEvent
18915
- }, null, 40, ["item", "options", "labels", "inStock", "link", "class"])) : vue.createCommentVNode("", true);
18940
+ class: { "lupa-loading-dynamic-data": isLoadingDynamicData((_a = _ctx.item) == null ? void 0 : _a.id) },
18941
+ "dynamic-attributes": dynamicAttributes.value
18942
+ }, renderDynamicAttributesOnParentElement.value && dynamicAttributes.value, { onProductEvent: handleProductEvent }), null, 16, ["item", "options", "labels", "inStock", "link", "class", "dynamic-attributes"])) : vue.createCommentVNode("", true);
18916
18943
  };
18917
18944
  }
18918
18945
  }));
@@ -12943,6 +12943,17 @@ const renderHtmlTemplate = (template, document2 = {}) => {
12943
12943
  const rendered = mustache.render(template, document2);
12944
12944
  return sanitizeHtml$1(rendered);
12945
12945
  };
12946
+ const getDynamicAttributes = (dynamicAttributes = [], document2 = {}) => {
12947
+ var _a, _b;
12948
+ const parsedAttributes = {};
12949
+ for (const attribute of dynamicAttributes) {
12950
+ if (!((_a = attribute == null ? void 0 : attribute.key) == null ? void 0 : _a.startsWith("data-"))) {
12951
+ continue;
12952
+ }
12953
+ parsedAttributes[attribute == null ? void 0 : attribute.key] = escapeHtml$1(mustache.render((_b = attribute == null ? void 0 : attribute.value) != null ? _b : "", document2));
12954
+ }
12955
+ return parsedAttributes;
12956
+ };
12946
12957
  const getFieldValue = (doc, field = "") => {
12947
12958
  var _a;
12948
12959
  if (typeof field === "number") {
@@ -13628,7 +13639,8 @@ const _sfc_main$1d = /* @__PURE__ */ defineComponent({
13628
13639
  props: {
13629
13640
  item: {},
13630
13641
  options: {},
13631
- inStock: { type: Boolean }
13642
+ inStock: { type: Boolean },
13643
+ dynamicAttributes: {}
13632
13644
  },
13633
13645
  emits: ["productEvent"],
13634
13646
  setup(__props, { emit }) {
@@ -13658,13 +13670,13 @@ const _sfc_main$1d = /* @__PURE__ */ defineComponent({
13658
13670
  return (_ctx, _cache) => {
13659
13671
  return openBlock(), createElementBlock("div", _hoisted_1$15, [
13660
13672
  createElementVNode("div", _hoisted_2$O, [
13661
- createElementVNode("button", {
13673
+ createElementVNode("button", mergeProps({
13662
13674
  onClick: withModifiers(handleClick, ["stop", "prevent"]),
13663
- class: normalizeClass(loading.value ? "lupa-add-to-cart-loading" : "lupa-add-to-cart"),
13675
+ class: loading.value ? "lupa-add-to-cart-loading" : "lupa-add-to-cart",
13664
13676
  "data-cy": "lupa-add-to-cart",
13665
13677
  type: "button",
13666
13678
  disabled: !inStockValue.value || loading.value
13667
- }, toDisplayString(label.value), 11, _hoisted_3$B)
13679
+ }, _ctx.dynamicAttributes), toDisplayString(label.value), 17, _hoisted_3$B)
13668
13680
  ])
13669
13681
  ]);
13670
13682
  };
@@ -13719,6 +13731,9 @@ const _sfc_main$1c = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValue
13719
13731
  }
13720
13732
  return "search-box-product-title";
13721
13733
  });
13734
+ const renderDynamicAttributesOnParentElement = computed(() => {
13735
+ return props.element.type !== DocumentElementType.ADDTOCART;
13736
+ });
13722
13737
  const displayElement = computed(() => {
13723
13738
  const element = props.element;
13724
13739
  const item = props.item;
@@ -13735,20 +13750,24 @@ const _sfc_main$1c = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValue
13735
13750
  const enhancementData = (_d = (_c = dynamicDataIdMap.value) == null ? void 0 : _c[(_b = props.item) == null ? void 0 : _b.id]) != null ? _d : {};
13736
13751
  return __spreadValues(__spreadValues({}, props.item), enhancementData);
13737
13752
  });
13753
+ const dynamicAttributes = computed(() => {
13754
+ return getDynamicAttributes(props.element.dynamicAttributes, enhancedItem.value);
13755
+ });
13738
13756
  const isLoadingDynamicData = (id) => {
13739
13757
  return Boolean(props.element.dynamic && id && loading.value && (loadingIds == null ? void 0 : loadingIds.value[id]));
13740
13758
  };
13741
13759
  return (_ctx, _cache) => {
13742
13760
  var _a, _b;
13743
13761
  return !_ctx.$slots.badges ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
13744
- displayElement.value ? (openBlock(), createBlock(resolveDynamicComponent(elementComponent.value), {
13762
+ displayElement.value ? (openBlock(), createBlock(resolveDynamicComponent(elementComponent.value), mergeProps({
13745
13763
  key: 0,
13746
13764
  item: enhancedItem.value,
13747
13765
  options: _ctx.element,
13748
13766
  labels: _ctx.labels,
13749
- class: normalizeClass({ "lupa-loading-dynamic-data": isLoadingDynamicData((_a = _ctx.item) == null ? void 0 : _a.id) }),
13750
- inStock: _ctx.isInStock
13751
- }, null, 8, ["item", "options", "labels", "class", "inStock"])) : createCommentVNode("", true)
13767
+ class: { "lupa-loading-dynamic-data": isLoadingDynamicData((_a = _ctx.item) == null ? void 0 : _a.id) },
13768
+ inStock: _ctx.isInStock,
13769
+ "dynamic-attributes": dynamicAttributes.value
13770
+ }, renderDynamicAttributesOnParentElement.value && dynamicAttributes.value), null, 16, ["item", "options", "labels", "class", "inStock", "dynamic-attributes"])) : createCommentVNode("", true)
13752
13771
  ], 64)) : (openBlock(), createElementBlock("div", _hoisted_1$14, [
13753
13772
  displayElement.value ? (openBlock(), createBlock(resolveDynamicComponent(elementComponent.value), {
13754
13773
  key: 0,
@@ -18640,7 +18659,8 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
18640
18659
  props: {
18641
18660
  item: {},
18642
18661
  options: {},
18643
- inStock: { type: Boolean }
18662
+ inStock: { type: Boolean },
18663
+ dynamicAttributes: {}
18644
18664
  },
18645
18665
  emits: ["productEvent"],
18646
18666
  setup(__props, { emit }) {
@@ -18675,13 +18695,14 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
18675
18695
  return (_ctx, _cache) => {
18676
18696
  return openBlock(), createElementBlock("div", _hoisted_1$r, [
18677
18697
  createElementVNode("div", _hoisted_2$m, [
18678
- createElementVNode("button", {
18698
+ createElementVNode("button", mergeProps({
18679
18699
  id: id.value,
18680
- class: normalizeClass(loading.value ? "lupa-add-to-cart-loading" : "lupa-add-to-cart"),
18700
+ class: loading.value ? "lupa-add-to-cart-loading" : "lupa-add-to-cart",
18681
18701
  "data-cy": "lupa-add-to-cart",
18682
- disabled: !inStockValue.value || loading.value,
18702
+ disabled: !inStockValue.value || loading.value
18703
+ }, _ctx.dynamicAttributes, {
18683
18704
  onClick: withModifiers(handleClick, ["stop"])
18684
- }, toDisplayString(label.value), 11, _hoisted_3$g)
18705
+ }), toDisplayString(label.value), 17, _hoisted_3$g)
18685
18706
  ])
18686
18707
  ]);
18687
18708
  };
@@ -18877,6 +18898,9 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues
18877
18898
  }
18878
18899
  return "searchResultsProductTitle";
18879
18900
  });
18901
+ const renderDynamicAttributesOnParentElement = computed(() => {
18902
+ return props.element.type !== DocumentElementType.ADDTOCART;
18903
+ });
18880
18904
  const enhancedItem = computed(() => {
18881
18905
  var _a, _b, _c, _d;
18882
18906
  if (!((_a = props.item) == null ? void 0 : _a.id)) {
@@ -18893,6 +18917,9 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues
18893
18917
  }
18894
18918
  return typeof element.display === "function" ? element.display(item) : processDisplayCondition(element.display, item);
18895
18919
  });
18920
+ const dynamicAttributes = computed(() => {
18921
+ return getDynamicAttributes(props.element.dynamicAttributes, enhancedItem.value);
18922
+ });
18896
18923
  const handleProductEvent = (item) => {
18897
18924
  emit("productEvent", item);
18898
18925
  };
@@ -18901,16 +18928,16 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues
18901
18928
  };
18902
18929
  return (_ctx, _cache) => {
18903
18930
  var _a;
18904
- return displayElement.value ? (openBlock(), createBlock(resolveDynamicComponent(elementComponent.value), {
18931
+ return displayElement.value ? (openBlock(), createBlock(resolveDynamicComponent(elementComponent.value), mergeProps({
18905
18932
  key: 0,
18906
18933
  item: enhancedItem.value,
18907
18934
  options: _ctx.element,
18908
18935
  labels: _ctx.labels,
18909
18936
  inStock: _ctx.inStock,
18910
18937
  link: _ctx.link,
18911
- class: normalizeClass({ "lupa-loading-dynamic-data": isLoadingDynamicData((_a = _ctx.item) == null ? void 0 : _a.id) }),
18912
- onProductEvent: handleProductEvent
18913
- }, null, 40, ["item", "options", "labels", "inStock", "link", "class"])) : createCommentVNode("", true);
18938
+ class: { "lupa-loading-dynamic-data": isLoadingDynamicData((_a = _ctx.item) == null ? void 0 : _a.id) },
18939
+ "dynamic-attributes": dynamicAttributes.value
18940
+ }, renderDynamicAttributesOnParentElement.value && dynamicAttributes.value, { onProductEvent: handleProductEvent }), null, 16, ["item", "options", "labels", "inStock", "link", "class", "dynamic-attributes"])) : createCommentVNode("", true);
18914
18941
  };
18915
18942
  }
18916
18943
  }));
@@ -14,6 +14,10 @@ declare const _sfc_main: import("vue").DefineComponent<{
14
14
  type: __PropType<boolean>;
15
15
  required: false;
16
16
  };
17
+ dynamicAttributes: {
18
+ type: __PropType<Record<string, unknown>>;
19
+ required: true;
20
+ };
17
21
  }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "productEvent"[], "productEvent", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
18
22
  item: {
19
23
  type: __PropType<Document>;
@@ -27,6 +31,10 @@ declare const _sfc_main: import("vue").DefineComponent<{
27
31
  type: __PropType<boolean>;
28
32
  required: false;
29
33
  };
34
+ dynamicAttributes: {
35
+ type: __PropType<Record<string, unknown>>;
36
+ required: true;
37
+ };
30
38
  }>> & {
31
39
  onProductEvent?: (...args: any[]) => any;
32
40
  }, {}, {}>;
@@ -14,6 +14,10 @@ declare const _sfc_main: import("vue").DefineComponent<{
14
14
  type: __PropType<boolean>;
15
15
  required: true;
16
16
  };
17
+ dynamicAttributes: {
18
+ type: __PropType<Record<string, unknown>>;
19
+ required: true;
20
+ };
17
21
  }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "productEvent"[], "productEvent", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
18
22
  item: {
19
23
  type: __PropType<Document>;
@@ -27,6 +31,10 @@ declare const _sfc_main: import("vue").DefineComponent<{
27
31
  type: __PropType<boolean>;
28
32
  required: true;
29
33
  };
34
+ dynamicAttributes: {
35
+ type: __PropType<Record<string, unknown>>;
36
+ required: true;
37
+ };
30
38
  }>> & {
31
39
  onProductEvent?: (...args: any[]) => any;
32
40
  }, {}, {}>;
@@ -14,6 +14,10 @@ export type DisplayCondition = {
14
14
  condition: 'exists' | 'equals' | 'notEquals' | 'greaterThan' | 'lessThan' | 'greaterThanOrEquals' | 'lessThanOrEquals';
15
15
  fields: (string | number)[];
16
16
  };
17
+ export type DynamicAttribute = {
18
+ key: string;
19
+ value: string;
20
+ };
17
21
  export type DocumentElementBase<T = any> = {
18
22
  type: DocumentElementType;
19
23
  key?: string;
@@ -21,6 +25,7 @@ export type DocumentElementBase<T = any> = {
21
25
  isHtml?: boolean;
22
26
  group?: string;
23
27
  dynamic?: boolean;
28
+ dynamicAttributes?: DynamicAttribute[];
24
29
  };
25
30
  export type ImageDocumentElement<T = any> = DocumentElementBase<T> & {
26
31
  type: DocumentElementType.IMAGE;
@@ -1,3 +1,4 @@
1
- import { DisplayCondition } from '../types/DocumentElement';
1
+ import { DisplayCondition, DynamicAttribute } from '../types/DocumentElement';
2
2
  export declare const renderHtmlTemplate: (template: string, document?: Record<string, unknown>) => string;
3
+ export declare const getDynamicAttributes: (dynamicAttributes?: DynamicAttribute[], document?: Record<string, unknown>) => {};
3
4
  export declare const processDisplayCondition: (displayCondition: DisplayCondition, doc?: Record<string, unknown>) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getlupa/vue",
3
- "version": "0.15.5",
3
+ "version": "0.15.6",
4
4
  "main": "dist/lupaSearch.mjs",
5
5
  "module": "dist/lupaSearch.mjs",
6
6
  "types": "dist/src/index.d.ts",