@revenexx/cover 0.2.33 → 0.2.35

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revenexx/cover",
3
- "version": "0.2.33",
3
+ "version": "0.2.35",
4
4
  "description": "Cover \u2014 revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -40,6 +40,11 @@ export interface LiveProductDoc {
40
40
  categories?: string[];
41
41
  category_labels?: string[];
42
42
  attrs?: Record<string, unknown>;
43
+ /**
44
+ * The same attributes in the document's own locale (`attribute:locale.*`),
45
+ * carrying only the keys a tenant actually translated.
46
+ */
47
+ attrs_locale?: Record<string, unknown>;
43
48
  locale: string;
44
49
  updated_at?: number;
45
50
  }
@@ -292,7 +297,7 @@ export async function mapLiveDocToDetail(doc: LiveProductDoc, locale: Locale = "
292
297
  // attribute definitions so the storefront shows the localized LABEL
293
298
  // (never the technical code), select values as their option label, a
294
299
  // unit suffix where declared, and hides internal/media keys (e.g. image).
295
- attributes: await buildSpecRows(doc.attrs ?? {}, locale),
300
+ attributes: await buildSpecRows(doc.attrs ?? {}, doc.attrs_locale ?? {}, locale),
296
301
  prices: [],
297
302
  };
298
303
  }
@@ -737,7 +742,62 @@ export function renderLiveAttributeValue(
737
742
  * localized label, option/unit-aware value, internal keys hidden. Degrades to
738
743
  * prettified keys if the attribute metadata can't be loaded.
739
744
  */
740
- async function buildSpecRows(attrs: Record<string, unknown>, locale: Locale): Promise<{ id: number; name: string; value: string }[]> {
745
+ /**
746
+ * The two attribute buckets, merged for display: a translated value wins where
747
+ * one exists, the common value carries the rest.
748
+ *
749
+ * Tenants translate SOME attributes, not all — `attrs_locale` holds only the
750
+ * keys with a value in this locale, so a key missing there is the normal case
751
+ * and not a gap. An empty string counts as missing too: a half-filled
752
+ * translation should fall back to the value that IS there rather than blank
753
+ * the row out, which is the difference between a German word on an English
754
+ * page and no answer at all.
755
+ */
756
+ /**
757
+ * Attributes the product page renders somewhere of its own, so the
758
+ * specification table must not print them a second time.
759
+ *
760
+ * Both are projected out of the locale bucket into the document's own fields —
761
+ * `attribute:locale.name` and `attribute:locale.description` in the products
762
+ * app's `search.json` — and the page reads them from there: `name` is the
763
+ * heading, `description` is the description block above this table. Since the
764
+ * table renders `attribute:locale.*` wholesale, the same two values arrived
765
+ * again as rows, so a product page carried its own name twice and its whole
766
+ * description twice, the second time inside a table of technical data.
767
+ *
768
+ * Deliberately not `short_description`: nothing else on the page renders it,
769
+ * so hiding it here would not stop a repetition, it would drop a value the
770
+ * catalogue maintains. The rule is "this is already on the page", not "this is
771
+ * prose rather than a measurement".
772
+ *
773
+ * By attribute code rather than by the `hidden` flag, because the flag is a
774
+ * property of the attribute (an internal, a media key) while this is a
775
+ * property of the PAGE: the same attribute is the right thing to show in a
776
+ * listing facet or an export, and only this one table is the place it would be
777
+ * a repetition.
778
+ */
779
+ const PAGE_RENDERS_ITSELF = new Set(["name", "description"]);
780
+
781
+ function mergeLocalizedAttrs(
782
+ common: Record<string, unknown>,
783
+ localized: Record<string, unknown>,
784
+ ): Record<string, unknown> {
785
+ const merged = { ...common };
786
+ for (const [key, value] of Object.entries(localized)) {
787
+ if (value === null || value === undefined || value === "") {
788
+ continue;
789
+ }
790
+ merged[key] = value;
791
+ }
792
+ return merged;
793
+ }
794
+
795
+ async function buildSpecRows(
796
+ common: Record<string, unknown>,
797
+ localized: Record<string, unknown>,
798
+ locale: Locale,
799
+ ): Promise<{ id: number; name: string; value: string }[]> {
800
+ const attrs = mergeLocalizedAttrs(common, localized);
741
801
  let meta: Record<string, LiveAttributeMeta> = {};
742
802
  try {
743
803
  meta = await loadLiveAttributeMeta();
@@ -762,6 +822,7 @@ async function buildSpecRows(attrs: Record<string, unknown>, locale: Locale): Pr
762
822
  // `""` and would otherwise render as a row with no value at all.
763
823
  if (Array.isArray(value) && value.length === 0) return false;
764
824
  if (key === "image" || key === logoAttribute) return false;
825
+ if (PAGE_RENDERS_ITSELF.has(key)) return false;
765
826
  return !meta[key]?.hidden;
766
827
  })
767
828
  .map(([key, value]) => {