@yext/visual-editor 2.0.0-beta.3 → 2.0.0-beta.5

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.
@@ -1,4 +1,4 @@
1
- import c from "node:path";
1
+ import l from "node:path";
2
2
  import f from "fs-extra";
3
3
  import { Project as J, Node as I, SyntaxKind as T } from "ts-morph";
4
4
  import { fileURLToPath as Nt, pathToFileURL as Dt } from "node:url";
@@ -356,8 +356,8 @@ const SectionLibraryLayout: Template<TemplateRenderProps> = (props) => {
356
356
  };
357
357
 
358
358
  export default SectionLibraryLayout;
359
- `, vt = /^[A-Za-z0-9_-]{1,64}$/, W = 1024, Mt = (t) => {
360
- const e = c.join(t, "src", "library", "library.json"), n = c.relative(t, e), o = [], r = (p, m) => {
359
+ `, vt = /^[a-z][a-z0-9-]{0,61}[a-z0-9](?![\s\S])/, W = 1024, Mt = (t) => {
360
+ const e = l.join(t, "src", "library", "library.json"), n = l.relative(t, e), o = [], r = (p, m) => {
361
361
  o.push({ category: "api", filePath: n, message: m, rule: p });
362
362
  };
363
363
  if (!f.existsSync(e))
@@ -385,11 +385,15 @@ export default SectionLibraryLayout;
385
385
  "field/description/length",
386
386
  `description must be at most ${W} characters.`
387
387
  ) : s.set("description", d);
388
- const l = s.get("id");
389
- return l && !vt.test(l) && r(
390
- "field/id/safe",
391
- "id must be at most 64 characters and may contain only letters, numbers, underscores, and hyphens."
392
- ), o.length > 0 ? { issues: o } : {
388
+ const c = s.get("id");
389
+ if (c) {
390
+ const p = c.startsWith("yext_") ? c.slice(5) : c;
391
+ (c.length > 63 || !vt.test(p)) && r(
392
+ "field/id/safe",
393
+ "id must be 2–63 characters, contain only lowercase letters, numbers, and hyphens, start with a lowercase letter, and end with a letter or number."
394
+ );
395
+ }
396
+ return o.length > 0 ? { issues: o } : {
393
397
  issues: o,
394
398
  metadata: {
395
399
  schemaVersion: 1,
@@ -417,8 +421,8 @@ export default SectionLibraryLayout;
417
421
  r[i] = a;
418
422
  continue;
419
423
  }
420
- const l = q(s), p = q(a);
421
- if (l && p) {
424
+ const c = q(s), p = q(a);
425
+ if (c && p) {
422
426
  r[i] = k(
423
427
  s,
424
428
  a,
@@ -427,9 +431,9 @@ export default SectionLibraryLayout;
427
431
  );
428
432
  continue;
429
433
  }
430
- l !== p && n?.({
434
+ c !== p && n?.({
431
435
  path: d,
432
- builtInType: l ? "object" : "string",
436
+ builtInType: c ? "object" : "string",
433
437
  repoType: p ? "object" : "string"
434
438
  }), r[i] = a;
435
439
  }
@@ -437,11 +441,11 @@ export default SectionLibraryLayout;
437
441
  }, q = (t) => typeof t == "object", D = "stream.config.ts", yt = "/__yext_visual_editor/local-editor", mt = "local-editor-data-", Ft = "src/templates/local-editor-data.tsx", Bt = "/** THIS FILE IS AUTOGENERATED AND SHOULD NOT BE EDITED */", Y = (t) => {
438
442
  const e = t.trim().replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "").toLowerCase();
439
443
  return `${mt}${e || "layout"}`;
440
- }, Gt = (t) => c.join(
444
+ }, Gt = (t) => l.join(
441
445
  "src",
442
446
  "templates",
443
447
  `${Y(t)}.tsx`
444
- ), K = (t, e) => c.isAbsolute(e) ? e : c.join(t, e), Ht = (t) => {
448
+ ), K = (t, e) => l.isAbsolute(e) ? e : l.join(t, e), Ht = (t) => {
445
449
  const e = K(
446
450
  t,
447
451
  D
@@ -518,7 +522,7 @@ export default config;
518
522
  }, d = s("id");
519
523
  if (!d || !b.test(d))
520
524
  throw new Error(`${t} config must define a valid id`);
521
- const l = a.getProperty("pageSetTypes"), p = l ? l.asKind(T.PropertyAssignment)?.getInitializer()?.asKind(T.ArrayLiteralExpression)?.getElements().map((u) => {
525
+ const c = a.getProperty("pageSetTypes"), p = c ? c.asKind(T.PropertyAssignment)?.getInitializer()?.asKind(T.ArrayLiteralExpression)?.getElements().map((u) => {
522
526
  const E = u.asKind(T.StringLiteral)?.getLiteralValue(), _ = pt.find(
523
527
  (L) => L === E
524
528
  );
@@ -528,7 +532,7 @@ export default config;
528
532
  );
529
533
  return _;
530
534
  }) : void 0;
531
- if (l && !p)
535
+ if (c && !p)
532
536
  throw new Error(
533
537
  `${t} config.pageSetTypes must be an array of page set types`
534
538
  );
@@ -583,8 +587,8 @@ export default config;
583
587
  `${t} sharedComponentMetadata must be an array literal`
584
588
  );
585
589
  return {
586
- components: d.map((l, p) => {
587
- const m = l.asKind(T.ObjectLiteralExpression);
590
+ components: d.map((c, p) => {
591
+ const m = c.asKind(T.ObjectLiteralExpression);
588
592
  if (!m)
589
593
  throw new Error(
590
594
  `${t} sharedComponentMetadata[${p}] must be an object literal`
@@ -664,25 +668,25 @@ const Wt = (t) => {
664
668
  e.forget();
665
669
  }
666
670
  }, ft = (t, e) => {
667
- const n = c.dirname(Nt(import.meta.url));
671
+ const n = l.dirname(Nt(import.meta.url));
668
672
  let o;
669
673
  if (n.endsWith(
670
- c.join("src", "internal", "sectionLibraryValidation")
674
+ l.join("src", "internal", "sectionLibraryValidation")
671
675
  ))
672
- o = c.resolve(
676
+ o = l.resolve(
673
677
  n,
674
678
  "..",
675
679
  "..",
676
680
  "..",
677
681
  "locales"
678
682
  );
679
- else if (c.basename(c.dirname(n)) === "dist")
680
- o = c.resolve(n, "..", "locales");
683
+ else if (l.basename(l.dirname(n)) === "dist")
684
+ o = l.resolve(n, "..", "locales");
681
685
  else
682
686
  throw new Error(
683
687
  `Cannot determine the built-in translation location from ${n}`
684
688
  );
685
- const r = c.join(
689
+ const r = l.join(
686
690
  o,
687
691
  t,
688
692
  e,
@@ -702,15 +706,15 @@ const Wt = (t) => {
702
706
  "local-editor"
703
707
  // generated Local Editor template ID
704
708
  ]), b = /^[A-Za-z0-9_-]+$/, Zt = (t) => {
705
- const e = c.join(t, "src", "library"), n = [], o = (u, E, _, L) => {
709
+ const e = l.join(t, "src", "library"), n = [], o = (u, E, _, L) => {
706
710
  n.push({
707
711
  category: "structure",
708
712
  ...L ? { severity: L } : {},
709
- filePath: c.relative(t, u) || ".",
713
+ filePath: l.relative(t, u) || ".",
710
714
  message: pe(_, t),
711
715
  rule: E
712
716
  });
713
- }, r = re(t, e, o), i = c.join(
717
+ }, r = re(t, e, o), i = l.join(
714
718
  e,
715
719
  "migrations",
716
720
  "registry.ts"
@@ -729,21 +733,21 @@ const Wt = (t) => {
729
733
  t,
730
734
  e,
731
735
  o
732
- ), d = c.join(
736
+ ), d = l.join(
733
737
  e,
734
738
  "shared",
735
739
  "componentRegistry.ts"
736
740
  );
737
- let l;
741
+ let c;
738
742
  try {
739
- l = Kt(d);
743
+ c = Kt(d);
740
744
  } catch (u) {
741
745
  o(d, "shared/invalid", C(u));
742
746
  }
743
- const p = l?.components ?? [], m = l?.rootPageSetTypes ?? [], g = ae(e, o), y = g.map(
747
+ const p = c?.components ?? [], m = c?.rootPageSetTypes ?? [], g = ae(e, o), y = g.map(
744
748
  ({ defaultLayoutPath: u, ...E }) => E
745
749
  );
746
- !l && !f.existsSync(d) && g.some((u) => u.metadata.pageSetType !== "ENTITY") && o(
750
+ !c && !f.existsSync(d) && g.some((u) => u.metadata.pageSetType !== "ENTITY") && o(
747
751
  d,
748
752
  "shared/missing",
749
753
  "A shared component registry is required for DIRECTORY and LOCATOR layouts."
@@ -782,12 +786,12 @@ const Wt = (t) => {
782
786
  const o = {
783
787
  platform: {},
784
788
  page: {}
785
- }, r = c.join(e, "i18n");
789
+ }, r = l.join(e, "i18n");
786
790
  if (!f.existsSync(r))
787
791
  return o;
788
792
  const i = f.readdirSync(r, { withFileTypes: !0 }).filter((a) => a.name !== ".gitkeep").sort((a, s) => a.name.localeCompare(s.name));
789
793
  for (const a of i) {
790
- const s = a.name, d = c.join(r, s);
794
+ const s = a.name, d = l.join(r, s);
791
795
  if (!a.isDirectory() || !te.includes(
792
796
  s
793
797
  )) {
@@ -809,8 +813,8 @@ const Wt = (t) => {
809
813
  return o;
810
814
  }, oe = (t, e, n, o, r) => {
811
815
  for (const i of f.readdirSync(e, { withFileTypes: !0 }).filter((a) => a.name !== ".gitkeep").sort((a, s) => a.name.localeCompare(s.name))) {
812
- const a = c.join(e, i.name), s = c.basename(i.name, c.extname(i.name));
813
- if (!i.isFile() || c.extname(i.name) !== ".json" || !ee(s)) {
816
+ const a = l.join(e, i.name), s = l.basename(i.name, l.extname(i.name));
817
+ if (!i.isFile() || l.extname(i.name) !== ".json" || !ee(s)) {
814
818
  r(
815
819
  a,
816
820
  "i18n/locale",
@@ -837,9 +841,9 @@ const Wt = (t) => {
837
841
  );
838
842
  continue;
839
843
  }
840
- o[n][s] = c.relative(t, a).split(c.sep).join("/");
841
- const l = ft(n, s);
842
- l && k(l, d, (p) => {
844
+ o[n][s] = l.relative(t, a).split(l.sep).join("/");
845
+ const c = ft(n, s);
846
+ c && k(c, d, (p) => {
843
847
  r(
844
848
  a,
845
849
  "i18n/shape-collision",
@@ -851,12 +855,12 @@ const Wt = (t) => {
851
855
  }, gt = (t) => !t || typeof t != "object" || Array.isArray(t) ? !1 : Object.values(t).every(
852
856
  (e) => typeof e == "string" || gt(e)
853
857
  ), re = (t, e, n) => {
854
- const o = c.join(e, "sections");
858
+ const o = l.join(e, "sections");
855
859
  if (!f.existsSync(o))
856
860
  return [];
857
861
  const r = [];
858
862
  for (const i of f.readdirSync(o, { withFileTypes: !0 }).filter((a) => a.name !== ".gitkeep").sort((a, s) => a.name.localeCompare(s.name))) {
859
- const a = c.join(o, i.name);
863
+ const a = l.join(o, i.name);
860
864
  if (i.isDirectory()) {
861
865
  n(
862
866
  a,
@@ -865,7 +869,7 @@ const Wt = (t) => {
865
869
  );
866
870
  continue;
867
871
  }
868
- const s = c.extname(i.name);
872
+ const s = l.extname(i.name);
869
873
  if (!i.isFile() || ![".tsx", ".jsx"].includes(s)) {
870
874
  n(
871
875
  a,
@@ -874,7 +878,7 @@ const Wt = (t) => {
874
878
  );
875
879
  continue;
876
880
  }
877
- const d = c.basename(i.name, s);
881
+ const d = l.basename(i.name, s);
878
882
  if (!b.test(d)) {
879
883
  n(
880
884
  a,
@@ -884,14 +888,14 @@ const Wt = (t) => {
884
888
  continue;
885
889
  }
886
890
  try {
887
- const l = {
891
+ const c = {
888
892
  ...Jt(a, d),
889
893
  componentName: d,
890
- sourcePath: c.relative(t, a)
894
+ sourcePath: l.relative(t, a)
891
895
  };
892
- b.test(l.id) ? r.push(l) : n(a, "sections/id", "config must define a valid id");
893
- } catch (l) {
894
- const p = C(l), m = p.includes("config must define a valid id");
896
+ b.test(c.id) ? r.push(c) : n(a, "sections/id", "config must define a valid id");
897
+ } catch (c) {
898
+ const p = C(c), m = p.includes("config must define a valid id");
895
899
  n(
896
900
  a,
897
901
  m ? "sections/id" : "sections/frontmatter",
@@ -901,12 +905,12 @@ const Wt = (t) => {
901
905
  }
902
906
  return r;
903
907
  }, ae = (t, e) => {
904
- const n = c.join(t, "layouts");
908
+ const n = l.join(t, "layouts");
905
909
  if (!f.existsSync(n))
906
910
  return e(n, "layouts/missing", "Missing layouts directory."), [];
907
911
  const o = f.readdirSync(n, { withFileTypes: !0 }).filter((i) => i.isDirectory()).sort((i, a) => i.name.localeCompare(a.name)), r = o.flatMap((i) => {
908
912
  const a = se(
909
- c.join(n, i.name),
913
+ l.join(n, i.name),
910
914
  e
911
915
  );
912
916
  return a ? [a] : [];
@@ -914,26 +918,26 @@ const Wt = (t) => {
914
918
  if (r.length === o.length) {
915
919
  const i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map();
916
920
  for (const d of r) {
917
- const l = d.metadata.id;
918
- if (i.has(l) ? e(
921
+ const c = d.metadata.id;
922
+ if (i.has(c) ? e(
919
923
  n,
920
924
  "layouts/duplicate-id",
921
- `Layout ID is not unique: ${l}`
922
- ) : i.add(l), d.metadata.pageSetType !== "ENTITY" && d.metadata.pageSetType !== "DIRECTORY")
925
+ `Layout ID is not unique: ${c}`
926
+ ) : i.add(c), d.metadata.pageSetType !== "ENTITY" && d.metadata.pageSetType !== "DIRECTORY")
923
927
  continue;
924
- const p = Y(l), m = a.get(p);
925
- m && m !== l ? e(
928
+ const p = Y(c), m = a.get(p);
929
+ m && m !== c ? e(
926
930
  n,
927
931
  "layouts/local-editor-template-collision",
928
- `Layout IDs ${m} and ${l} generate the same Local Editor id: ${p}`
929
- ) : a.set(p, l);
932
+ `Layout IDs ${m} and ${c} generate the same Local Editor id: ${p}`
933
+ ) : a.set(p, c);
930
934
  }
931
935
  const s = /* @__PURE__ */ new Map();
932
936
  for (const d of r) {
933
- const l = d.metadata.pageSetType;
937
+ const c = d.metadata.pageSetType;
934
938
  s.set(
935
- l,
936
- (s.get(l) ?? 0) + 1
939
+ c,
940
+ (s.get(c) ?? 0) + 1
937
941
  );
938
942
  }
939
943
  (s.get("ENTITY") ?? 0) === 0 && e(
@@ -952,7 +956,7 @@ const Wt = (t) => {
952
956
  DIRECTORY: 1,
953
957
  LOCATOR: 2
954
958
  }, ie = (t, e) => Q[t.metadata.pageSetType] - Q[e.metadata.pageSetType] || t.metadata.id.localeCompare(e.metadata.id), se = (t, e) => {
955
- const n = c.join(t, "metadata.json"), o = c.join(t, "defaultLayout.json"), r = tt(
959
+ const n = l.join(t, "metadata.json"), o = l.join(t, "defaultLayout.json"), r = tt(
956
960
  n,
957
961
  "layout metadata",
958
962
  e
@@ -971,7 +975,7 @@ const Wt = (t) => {
971
975
  "vertical",
972
976
  jt,
973
977
  n
974
- ), l = et(
978
+ ), c = et(
975
979
  r,
976
980
  "purpose",
977
981
  Yt,
@@ -985,7 +989,7 @@ const Wt = (t) => {
985
989
  "displayName"
986
990
  ),
987
991
  ...d === void 0 ? {} : { vertical: d },
988
- ...l === void 0 ? {} : { purpose: l },
992
+ ...c === void 0 ? {} : { purpose: c },
989
993
  pageSetType: a
990
994
  };
991
995
  } else if (a === "DIRECTORY" || a === "LOCATOR")
@@ -1017,11 +1021,11 @@ const Wt = (t) => {
1017
1021
  ["Component", e]
1018
1022
  ])
1019
1023
  for (const s of a) {
1020
- const d = i === "Section" && "sourcePath" in s ? c.join(
1024
+ const d = i === "Section" && "sourcePath" in s ? l.join(
1021
1025
  n,
1022
1026
  "sections",
1023
- s.sourcePath.split(c.sep).at(-1) ?? ""
1024
- ) : c.join(n, "shared", "componentRegistry.ts");
1027
+ s.sourcePath.split(l.sep).at(-1) ?? ""
1028
+ ) : l.join(n, "shared", "componentRegistry.ts");
1025
1029
  b.test(s.id) || o(
1026
1030
  d,
1027
1031
  "components/id",
@@ -1106,7 +1110,7 @@ const Wt = (t) => {
1106
1110
  );
1107
1111
  return r;
1108
1112
  }
1109
- }, C = (t) => t instanceof Error ? t.message : String(t), pe = (t, e) => t.split(`${e}${c.sep}`).join(""), nt = ["api", "structure", "code"], ye = (t) => [...t].sort((e, n) => nt.indexOf(e.category) - nt.indexOf(n.category) || ot(e.filePath, n.filePath) || (e.line ?? 0) - (n.line ?? 0) || (e.column ?? 0) - (n.column ?? 0) || ot(e.rule, n.rule)), ot = (t, e) => t === e ? 0 : t < e ? -1 : 1, me = (t) => {
1113
+ }, C = (t) => t instanceof Error ? t.message : String(t), pe = (t, e) => t.split(`${e}${l.sep}`).join(""), nt = ["api", "structure", "code"], ye = (t) => [...t].sort((e, n) => nt.indexOf(e.category) - nt.indexOf(n.category) || ot(e.filePath, n.filePath) || (e.line ?? 0) - (n.line ?? 0) || (e.column ?? 0) - (n.column ?? 0) || ot(e.rule, n.rule)), ot = (t, e) => t === e ? 0 : t < e ? -1 : 1, me = (t) => {
1110
1114
  const e = t.line ? `:${t.line}${t.column ? `:${t.column}` : ""}` : "";
1111
1115
  return `${t.filePath}${e}: ${t.message}`;
1112
1116
  };
@@ -1151,7 +1155,7 @@ const fe = [
1151
1155
  throw new Error(
1152
1156
  "Section Library builds require SECTION_LIBRARY_REVISION_ID"
1153
1157
  );
1154
- if (!f.existsSync(c.join(t, "src", "library", "library.json")))
1158
+ if (!f.existsSync(l.join(t, "src", "library", "library.json")))
1155
1159
  return { generatedFiles: [], layouts: [] };
1156
1160
  const n = Mt(t), o = Zt(t), r = ye([
1157
1161
  ...n.issues,
@@ -1167,11 +1171,11 @@ const fe = [
1167
1171
  throw new Error(
1168
1172
  "Section Library metadata and structure validation did not run."
1169
1173
  );
1170
- const a = n.metadata, s = o.structure, d = Ce(t), l = c.join(t, "src", "library", ".generated"), p = Te(
1174
+ const a = n.metadata, s = o.structure, d = Ce(t), c = l.join(t, "src", "library", ".generated"), p = Te(
1171
1175
  t,
1172
- l,
1176
+ c,
1173
1177
  s.translationResources
1174
- ), m = c.join(l, "i18n.ts"), g = [...p.generatedFiles];
1178
+ ), m = l.join(c, "i18n.ts"), g = [...p.generatedFiles];
1175
1179
  return A(
1176
1180
  m,
1177
1181
  Ee(
@@ -1180,8 +1184,8 @@ const fe = [
1180
1184
  )
1181
1185
  ) && g.push(m), g.push(
1182
1186
  ...s.layouts.flatMap((y) => {
1183
- const u = c.join(
1184
- l,
1187
+ const u = l.join(
1188
+ c,
1185
1189
  `libraryConfig-${y.metadata.id}.tsx`
1186
1190
  );
1187
1191
  return A(
@@ -1197,7 +1201,7 @@ const fe = [
1197
1201
  })
1198
1202
  ), g.push(
1199
1203
  ...s.layouts.flatMap((y) => {
1200
- const u = c.join(
1204
+ const u = l.join(
1201
1205
  t,
1202
1206
  "src",
1203
1207
  "templates",
@@ -1210,7 +1214,7 @@ const fe = [
1210
1214
  })
1211
1215
  ), g.push(
1212
1216
  ...s.layouts.flatMap((y) => {
1213
- const u = c.join(
1217
+ const u = l.join(
1214
1218
  t,
1215
1219
  "src",
1216
1220
  "templates",
@@ -1247,7 +1251,7 @@ const fe = [
1247
1251
  };
1248
1252
  }, Ee = (t, e) => {
1249
1253
  const n = (o) => Object.entries(o).sort(([r], [i]) => r.localeCompare(i)).map(([r, i]) => {
1250
- const a = c.relative(c.dirname(t), i).split(c.sep).join("/"), s = a.startsWith(".") ? a : `./${a}`;
1254
+ const a = l.relative(l.dirname(t), i).split(l.sep).join("/"), s = a.startsWith(".") ? a : `./${a}`;
1251
1255
  return ` ${JSON.stringify(r)}: () => import(${JSON.stringify(s)}).then(({ default: translations }) => translations),`;
1252
1256
  }).join(`
1253
1257
  `);
@@ -1281,9 +1285,9 @@ const fe = [
1281
1285
  throw new Error(
1282
1286
  `Could not find built-in ${a} translations for ${i}.`
1283
1287
  );
1284
- const l = n[a][i], p = l ? JSON.parse(
1285
- f.readFileSync(c.join(t, l), "utf8")
1286
- ) : void 0, m = p ? k(d, p) : d, g = c.join(
1288
+ const c = n[a][i], p = c ? JSON.parse(
1289
+ f.readFileSync(l.join(t, c), "utf8")
1290
+ ) : void 0, m = p ? k(d, p) : d, g = l.join(
1287
1291
  e,
1288
1292
  "i18n",
1289
1293
  s,
@@ -1311,9 +1315,9 @@ const fe = [
1311
1315
  const e = /* @__PURE__ */ new Set();
1312
1316
  for (const n of t) {
1313
1317
  f.removeSync(n);
1314
- let o = c.dirname(n);
1315
- for (e.add(o); o.includes(`${c.sep}.generated${c.sep}`) && c.basename(o) !== ".generated"; )
1316
- o = c.dirname(o), e.add(o);
1318
+ let o = l.dirname(n);
1319
+ for (e.add(o); o.includes(`${l.sep}.generated${l.sep}`) && l.basename(o) !== ".generated"; )
1320
+ o = l.dirname(o), e.add(o);
1317
1321
  n.endsWith(".tsx") && f.removeSync(n.replace(/\.tsx$/, ".client.tsx"));
1318
1322
  }
1319
1323
  for (const n of [...e].sort(
@@ -1321,7 +1325,7 @@ const fe = [
1321
1325
  ))
1322
1326
  f.existsSync(n) && f.readdirSync(n).length === 0 && f.removeSync(n);
1323
1327
  }, _e = (t, e) => {
1324
- const n = c.join(t, ".template-manifest.json"), o = JSON.stringify(
1328
+ const n = l.join(t, ".template-manifest.json"), o = JSON.stringify(
1325
1329
  {
1326
1330
  templates: e.map((r) => ({
1327
1331
  name: r.metadata.id,
@@ -1336,21 +1340,21 @@ const fe = [
1336
1340
  );
1337
1341
  (!f.existsSync(n) || f.readFileSync(n, "utf8") !== o) && f.writeFileSync(n, o);
1338
1342
  }, Ie = (t, e, n, o, r) => {
1339
- const i = e.metadata.id, a = c.join(
1343
+ const i = e.metadata.id, a = l.join(
1340
1344
  t,
1341
1345
  "src",
1342
1346
  "library",
1343
1347
  ".generated",
1344
1348
  `libraryConfig-${i}.tsx`
1345
1349
  ), s = n.filter((g) => g.pageSetTypes.includes(e.metadata.pageSetType)), d = s.map((g, y) => {
1346
- const u = c.relative(
1347
- c.dirname(a),
1348
- c.join(t, g.sourcePath)
1349
- ).replace(/\.(tsx|jsx)$/, "").split(c.sep).join("/"), E = u.startsWith(".") ? u : `./${u}`;
1350
+ const u = l.relative(
1351
+ l.dirname(a),
1352
+ l.join(t, g.sourcePath)
1353
+ ).replace(/\.(tsx|jsx)$/, "").split(l.sep).join("/"), E = u.startsWith(".") ? u : `./${u}`;
1350
1354
  return `import { ${g.componentName} as Section${y}, config as sectionConfig${y} } from ${JSON.stringify(E)};`;
1351
- }), l = s.map((g, y) => ` { id: ${JSON.stringify(g.id)}, component: Section${y}, config: sectionConfig${y} },`), p = Le(s), m = o.some((g) => g.pageSetTypes.includes(e.metadata.pageSetType)) || r.includes(e.metadata.pageSetType);
1355
+ }), c = s.map((g, y) => ` { id: ${JSON.stringify(g.id)}, component: Section${y}, config: sectionConfig${y} },`), p = Le(s), m = o.some((g) => g.pageSetTypes.includes(e.metadata.pageSetType)) || r.includes(e.metadata.pageSetType);
1352
1356
  return xt.replace("/* SECTION_LIBRARY_GENERATED_FILE */", O).replace("/* SECTION_LIBRARY_IMPORTS */", d.join(`
1353
- `)).replace("/* SECTION_LIBRARY_ENTRIES */", l.join(`
1357
+ `)).replace("/* SECTION_LIBRARY_ENTRIES */", c.join(`
1354
1358
  `)).replace("/* SECTION_LIBRARY_CATEGORIES */", p).replace(
1355
1359
  "/* SECTION_LIBRARY_SHARED_COMPONENT_REGISTRY */",
1356
1360
  m ? 'import { sharedComponentConfigs, sharedComponentMetadata, sharedRootAllowedComponentIds, sharedRootConfigs } from "../shared/componentRegistry";' : `const sharedComponentMetadata: { id: string; pageSetTypes: string[] }[] = [];
@@ -1400,7 +1404,7 @@ const sharedRootConfigs: Partial<Record<string, NonNullable<Config["root"]>>> =
1400
1404
  o
1401
1405
  ).replace("/* SECTION_LIBRARY_COMPONENT_REGISTRY */", r).replace('"__SECTION_LIBRARY_EDITOR_PATH__"', JSON.stringify(e)).replace('"__SECTION_LIBRARY_EDITOR_NAME__"', JSON.stringify(n));
1402
1406
  }, Ce = (t) => {
1403
- const e = c.join(
1407
+ const e = l.join(
1404
1408
  t,
1405
1409
  "src",
1406
1410
  "library",
@@ -1410,7 +1414,7 @@ const sharedRootConfigs: Partial<Record<string, NonNullable<Config["root"]>>> =
1410
1414
  return f.existsSync(e) ? `import { migrationRegistry as repoMigrationRegistry } from "../library/migrations/registry";
1411
1415
  const sectionLibraryMigrationRegistry: MigrationRegistry = repoMigrationRegistry;` : "const sectionLibraryMigrationRegistry: MigrationRegistry = [];";
1412
1416
  }, A = (t, e) => {
1413
- if (f.ensureDirSync(c.dirname(t)), f.existsSync(t)) {
1417
+ if (f.ensureDirSync(l.dirname(t)), f.existsSync(t)) {
1414
1418
  const n = f.readFileSync(t, "utf8");
1415
1419
  if (!n.startsWith(O))
1416
1420
  return !1;
@@ -1595,7 +1599,7 @@ export default LocalEditorData;
1595
1599
  return JSON.parse(f.readFileSync(t, "utf8"));
1596
1600
  } catch (n) {
1597
1601
  throw new Error(
1598
- `Failed to parse ${e} at ${c.relative(process.cwd(), t)}: ${j(n)}`
1602
+ `Failed to parse ${e} at ${l.relative(process.cwd(), t)}: ${j(n)}`
1599
1603
  );
1600
1604
  }
1601
1605
  }, j = (t) => t instanceof Error ? t.message : String(t), be = (t, e) => {
@@ -1605,7 +1609,7 @@ export default LocalEditorData;
1605
1609
  localEditorDataTemplateSource: e
1606
1610
  }) => ({
1607
1611
  cleanupGeneratedLocalEditorArtifacts: (i = process.cwd()) => {
1608
- const a = c.join(
1612
+ const a = l.join(
1609
1613
  i,
1610
1614
  "src",
1611
1615
  "templates",
@@ -1615,37 +1619,37 @@ export default LocalEditorData;
1615
1619
  },
1616
1620
  syncLocalEditorDataTemplates: (i, a = process.cwd()) => {
1617
1621
  const s = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Map();
1618
- for (const l of i) {
1619
- if (l.metadata.pageSetType !== "ENTITY" && l.metadata.pageSetType !== "DIRECTORY")
1622
+ for (const c of i) {
1623
+ if (c.metadata.pageSetType !== "ENTITY" && c.metadata.pageSetType !== "DIRECTORY")
1620
1624
  continue;
1621
- const p = c.join(
1625
+ const p = l.join(
1622
1626
  a,
1623
- Gt(l.metadata.id)
1627
+ Gt(c.metadata.id)
1624
1628
  ), m = d.get(p);
1625
1629
  m ? console.warn(
1626
- `Local Editor layouts "${m}" and "${l.metadata.id}" generate the same data template at ${c.relative(a, p)}. The later layout will overwrite the earlier layout's template.`
1627
- ) : d.set(p, l.metadata.id);
1628
- const g = c.relative(
1629
- c.dirname(p),
1630
+ `Local Editor layouts "${m}" and "${c.metadata.id}" generate the same data template at ${l.relative(a, p)}. The later layout will overwrite the earlier layout's template.`
1631
+ ) : d.set(p, c.metadata.id);
1632
+ const g = l.relative(
1633
+ l.dirname(p),
1630
1634
  K(
1631
1635
  a,
1632
1636
  D
1633
1637
  )
1634
- ).split(c.sep).join("/");
1638
+ ).split(l.sep).join("/");
1635
1639
  rt(
1636
1640
  p,
1637
1641
  Vt(
1638
1642
  e,
1639
1643
  g.startsWith(".") ? g : `./${g}`,
1640
- l.metadata.id,
1641
- l.metadata.pageSetType
1644
+ c.metadata.id,
1645
+ c.metadata.pageSetType
1642
1646
  )
1643
1647
  ), s.add(p);
1644
1648
  }
1645
1649
  at(a, s);
1646
1650
  },
1647
1651
  syncLocalEditorTemplate: (i, a = process.cwd()) => {
1648
- const s = c.join(
1652
+ const s = l.join(
1649
1653
  a,
1650
1654
  "src",
1651
1655
  "templates",
@@ -1661,42 +1665,42 @@ export default LocalEditorData;
1661
1665
  Pe(a)
1662
1666
  ).replace(
1663
1667
  "/* LOCAL_EDITOR_CONFIG_IMPORTS */",
1664
- i.map((d, l) => `import { sectionLibraryConfig as LayoutConfig${l} } from ${JSON.stringify(`../library/.generated/libraryConfig-${d.metadata.id}`)};`).join(`
1668
+ i.map((d, c) => `import { sectionLibraryConfig as LayoutConfig${c} } from ${JSON.stringify(`../library/.generated/libraryConfig-${d.metadata.id}`)};`).join(`
1665
1669
  `)
1666
1670
  ).replace(
1667
1671
  "/* LOCAL_EDITOR_COMPONENT_REGISTRY */",
1668
- i.map((d, l) => ` ${JSON.stringify(d.metadata.id)}: LayoutConfig${l},`).join(`
1672
+ i.map((d, c) => ` ${JSON.stringify(d.metadata.id)}: LayoutConfig${c},`).join(`
1669
1673
  `)
1670
1674
  )
1671
1675
  );
1672
1676
  }
1673
1677
  }), Pe = (t) => f.existsSync(
1674
- c.join(t, "src", "library", "migrations", "registry.ts")
1678
+ l.join(t, "src", "library", "migrations", "registry.ts")
1675
1679
  ) ? `import { migrationRegistry as repoMigrationRegistry } from "../library/migrations/registry";
1676
1680
  const sectionLibraryMigrationRegistry: MigrationRegistry = repoMigrationRegistry;` : "const sectionLibraryMigrationRegistry: MigrationRegistry = [];", rt = (t, e) => {
1677
- if (f.ensureDirSync(c.dirname(t)), f.existsSync(t) && !v(t))
1681
+ if (f.ensureDirSync(l.dirname(t)), f.existsSync(t) && !v(t))
1678
1682
  throw new Error(
1679
1683
  `Refusing to overwrite hand-authored local editor template at ${t}`
1680
1684
  );
1681
1685
  be(t, e);
1682
1686
  }, at = (t, e) => {
1683
- const n = c.join(t, "src", "templates");
1687
+ const n = l.join(t, "src", "templates");
1684
1688
  if (!f.existsSync(n))
1685
1689
  return;
1686
1690
  for (const r of f.readdirSync(n, {
1687
1691
  withFileTypes: !0
1688
1692
  })) {
1689
- const i = c.join(n, r.name);
1690
- !r.isFile() || !r.name.startsWith(mt) || c.extname(r.name) !== ".tsx" || e?.has(i) || !v(i) || f.removeSync(i);
1693
+ const i = l.join(n, r.name);
1694
+ !r.isFile() || !r.name.startsWith(mt) || l.extname(r.name) !== ".tsx" || e?.has(i) || !v(i) || f.removeSync(i);
1691
1695
  }
1692
- const o = c.join(
1696
+ const o = l.join(
1693
1697
  t,
1694
1698
  Ft
1695
1699
  );
1696
1700
  !e?.has(o) && v(o) && f.removeSync(o);
1697
1701
  }, xe = (t) => {
1698
- const e = c.join(t, "public", "y-fonts");
1699
- return f.existsSync(e) ? f.readdirSync(e, { withFileTypes: !0 }).filter((n) => n.isFile() && c.extname(n.name) === ".css").map((n) => `/y-fonts/${n.name}`).sort((n, o) => n.localeCompare(o)) : [];
1702
+ const e = l.join(t, "public", "y-fonts");
1703
+ return f.existsSync(e) ? f.readdirSync(e, { withFileTypes: !0 }).filter((n) => n.isFile() && l.extname(n.name) === ".css").map((n) => `/y-fonts/${n.name}`).sort((n, o) => n.localeCompare(o)) : [];
1700
1704
  };
1701
1705
  let B;
1702
1706
  const Tt = async (t, e, n) => {
@@ -1706,7 +1710,7 @@ const Tt = async (t, e, n) => {
1706
1710
  );
1707
1711
  if (!f.existsSync(o))
1708
1712
  return n.push(
1709
- `Missing local editor config at ${c.relative(process.cwd(), o)}.`
1713
+ `Missing local editor config at ${l.relative(process.cwd(), o)}.`
1710
1714
  ), G(e, {});
1711
1715
  try {
1712
1716
  return G(
@@ -1717,9 +1721,9 @@ const Tt = async (t, e, n) => {
1717
1721
  return n.push(j(r)), G(e, {});
1718
1722
  }
1719
1723
  }, we = async (t) => {
1720
- if (c.extname(t) === ".json")
1724
+ if (l.extname(t) === ".json")
1721
1725
  throw new Error(
1722
- `Unsupported local editor config at ${c.relative(process.cwd(), t)}: use ${D}.`
1726
+ `Unsupported local editor config at ${l.relative(process.cwd(), t)}: use ${D}.`
1723
1727
  );
1724
1728
  if (B?.filePath === t)
1725
1729
  return B.config;
@@ -1733,7 +1737,7 @@ const Tt = async (t, e, n) => {
1733
1737
  n = n.default;
1734
1738
  if (!n || typeof n != "object")
1735
1739
  throw new Error(
1736
- `Failed to parse local editor stream config at ${c.relative(process.cwd(), t)}: expected a default-exported object.`
1740
+ `Failed to parse local editor stream config at ${l.relative(process.cwd(), t)}: expected a default-exported object.`
1737
1741
  );
1738
1742
  const o = n;
1739
1743
  return B = {
@@ -1742,18 +1746,18 @@ const Tt = async (t, e, n) => {
1742
1746
  }, o;
1743
1747
  }, G = (t, e) => {
1744
1748
  const n = t.flatMap((o) => {
1745
- const r = o.metadata.id, i = o.metadata.pageSetType, a = e.pageSetTypes?.[i], s = e.layouts?.[r], d = s?.stream ?? a?.stream, l = i === "ENTITY" || i === "DIRECTORY" && d ? "stream" : "fixture";
1746
- return l === "stream" && !d ? [] : [
1749
+ const r = o.metadata.id, i = o.metadata.pageSetType, a = e.pageSetTypes?.[i], s = e.layouts?.[r], d = s?.stream ?? a?.stream, c = i === "ENTITY" || i === "DIRECTORY" && d ? "stream" : "fixture";
1750
+ return c === "stream" && !d ? [] : [
1747
1751
  {
1748
1752
  layoutId: r,
1749
1753
  dataTemplateName: Y(r),
1750
1754
  pageSetType: i,
1751
- dataSource: l,
1755
+ dataSource: c,
1752
1756
  defaults: {
1753
1757
  entityId: s?.defaults?.entityId ?? a?.defaults?.entityId,
1754
1758
  locale: s?.defaults?.locale ?? a?.defaults?.locale ?? e.defaults?.locale
1755
1759
  },
1756
- stream: l === "stream" ? d : void 0,
1760
+ stream: c === "stream" ? d : void 0,
1757
1761
  defaultLayoutData: o.defaultLayout
1758
1762
  }
1759
1763
  ];
@@ -1991,7 +1995,7 @@ const Tt = async (t, e, n) => {
1991
1995
  a(o, "dm_addressRegionDisplayName"),
1992
1996
  [h("Locations Directory", "index.html")],
1993
1997
  { dm_addressCountryDisplayName: "United States" }
1994
- ), l = w(
1998
+ ), c = w(
1995
1999
  String(o.id),
1996
2000
  "VA",
1997
2001
  "us/va",
@@ -2021,7 +2025,7 @@ const Tt = async (t, e, n) => {
2021
2025
  dm_addressRegionDisplayName: "Virginia"
2022
2026
  }
2023
2027
  );
2024
- return [s, d, l, p].map(
2028
+ return [s, d, c, p].map(
2025
2029
  (m) => ({ layoutId: t, document: m })
2026
2030
  );
2027
2031
  }, Ue = (t) => ({
@@ -2073,7 +2077,7 @@ const Tt = async (t, e, n) => {
2073
2077
  t,
2074
2078
  e,
2075
2079
  i
2076
- ), s = n ?? a.defaults.layoutId ?? a.layouts[0], d = s ? a.entitiesByLayout[s] ?? [] : [], l = s ? a.layoutDefaults[s] : void 0, p = o ?? l?.entityId ?? a.defaults.entityId ?? d[0]?.entityId, m = d.find((S) => S.entityId === p), g = r ?? l?.locale ?? a.defaults.locale ?? m?.locales[0], y = a.documents.find((S) => S.layoutId === s && S.entityId === p && S.locale === g);
2080
+ ), s = n ?? a.defaults.layoutId ?? a.layouts[0], d = s ? a.entitiesByLayout[s] ?? [] : [], c = s ? a.layoutDefaults[s] : void 0, p = o ?? c?.entityId ?? a.defaults.entityId ?? d[0]?.entityId, m = d.find((S) => S.entityId === p), g = r ?? c?.locale ?? a.defaults.locale ?? m?.locales[0], y = a.documents.find((S) => S.layoutId === s && S.entityId === p && S.locale === g);
2077
2081
  if (!y)
2078
2082
  return {
2079
2083
  document: null,
@@ -2162,7 +2166,7 @@ const Tt = async (t, e, n) => {
2162
2166
  return t;
2163
2167
  }
2164
2168
  }, Ct = async (t, e, n = 4) => {
2165
- const o = [], r = c.join(t, "localData");
2169
+ const o = [], r = l.join(t, "localData");
2166
2170
  e.length === 0 && o.push("Missing src/library/library.json.");
2167
2171
  const i = await Tt(
2168
2172
  t,
@@ -2173,7 +2177,7 @@ const Tt = async (t, e, n) => {
2173
2177
  a,
2174
2178
  o,
2175
2179
  n
2176
- ), l = qe(s, d), p = Object.fromEntries(
2180
+ ), c = qe(s, d), p = Object.fromEntries(
2177
2181
  a.map((y) => [
2178
2182
  y.layoutId,
2179
2183
  {
@@ -2204,7 +2208,7 @@ const Tt = async (t, e, n) => {
2204
2208
  dataSourceByLayout: Object.fromEntries(
2205
2209
  a.map((y) => [y.layoutId, y.dataSource])
2206
2210
  ),
2207
- entitiesByLayout: l,
2211
+ entitiesByLayout: c,
2208
2212
  documents: d
2209
2213
  };
2210
2214
  }, Ot = (t) => {
@@ -2214,24 +2218,24 @@ const Tt = async (t, e, n) => {
2214
2218
  const r = He(
2215
2219
  e,
2216
2220
  o
2217
- ).map(({ layoutId: l, document: p }) => ({
2218
- layoutId: l,
2221
+ ).map(({ layoutId: c, document: p }) => ({
2222
+ layoutId: c,
2219
2223
  entityId: H(p, "fixture.json"),
2220
2224
  displayName: typeof p.name == "string" && p.name.length > 0 ? p.name : H(p, "fixture.json"),
2221
2225
  locale: dt(p, "fixture.json"),
2222
2226
  fileName: "built-in fixture",
2223
2227
  document: p
2224
- })), i = e.filter((l) => l.dataSource === "stream");
2228
+ })), i = e.filter((c) => c.dataSource === "stream");
2225
2229
  if (i.length === 0)
2226
2230
  return r;
2227
2231
  if (!f.existsSync(t))
2228
2232
  return n.push(
2229
- `Missing localData snapshots at ${c.relative(process.cwd(), t)}. Run your existing Pages local data generation flow first.`
2233
+ `Missing localData snapshots at ${l.relative(process.cwd(), t)}. Run your existing Pages local data generation flow first.`
2230
2234
  ), r;
2231
- const a = c.join(t, "mapping.json");
2235
+ const a = l.join(t, "mapping.json");
2232
2236
  if (!f.existsSync(a))
2233
2237
  return n.push(
2234
- `Missing local editor snapshot mapping at ${c.relative(process.cwd(), a)}. Run yext pages generate-test-data to populate local editor snapshots.`
2238
+ `Missing local editor snapshot mapping at ${l.relative(process.cwd(), a)}. Run yext pages generate-test-data to populate local editor snapshots.`
2235
2239
  ), r;
2236
2240
  let s;
2237
2241
  try {
@@ -2239,25 +2243,25 @@ const Tt = async (t, e, n) => {
2239
2243
  a,
2240
2244
  "local data mapping"
2241
2245
  );
2242
- } catch (l) {
2243
- return n.push(j(l)), r;
2246
+ } catch (c) {
2247
+ return n.push(j(c)), r;
2244
2248
  }
2245
2249
  const d = [...r];
2246
- for (const l of i) {
2250
+ for (const c of i) {
2247
2251
  const p = new Set(
2248
- s[l.dataTemplateName] ?? []
2252
+ s[c.dataTemplateName] ?? []
2249
2253
  );
2250
2254
  if (p.size === 0) {
2251
2255
  n.push(
2252
- `Missing local editor snapshot mapping for layout "${l.layoutId}" in ${c.relative(process.cwd(), a)}. Expected generated mapping key "${l.dataTemplateName}". Run yext pages generate-test-data after enabling localEditor.`
2256
+ `Missing local editor snapshot mapping for layout "${c.layoutId}" in ${l.relative(process.cwd(), a)}. Expected generated mapping key "${c.dataTemplateName}". Run yext pages generate-test-data after enabling localEditor.`
2253
2257
  );
2254
2258
  continue;
2255
2259
  }
2256
2260
  Array.from(p).sort((m, g) => m.localeCompare(g)).forEach((m) => {
2257
- const g = c.join(t, m);
2261
+ const g = l.join(t, m);
2258
2262
  if (!f.existsSync(g)) {
2259
2263
  n.push(
2260
- `Snapshot file ${c.join("localData", m)} is referenced but missing.`
2264
+ `Snapshot file ${l.join("localData", m)} is referenced but missing.`
2261
2265
  );
2262
2266
  return;
2263
2267
  }
@@ -2267,7 +2271,7 @@ const Tt = async (t, e, n) => {
2267
2271
  `local editor snapshot ${m}`
2268
2272
  ), u = dt(y, m), E = H(y, m);
2269
2273
  d.push({
2270
- layoutId: l.layoutId,
2274
+ layoutId: c.layoutId,
2271
2275
  entityId: E,
2272
2276
  displayName: typeof y.name == "string" && y.name.length > 0 ? y.name : E,
2273
2277
  locale: u,
@@ -2345,7 +2349,7 @@ const Tt = async (t, e, n) => {
2345
2349
  process.env.SECTION_LIBRARY_REVISION_ID
2346
2350
  );
2347
2351
  o = g.generatedFiles, r = g.manifestSource, i = g.layouts, a = g.manifestSource !== void 0;
2348
- }, l = async () => {
2352
+ }, c = async () => {
2349
2353
  Ht(process.cwd()), await Tt(process.cwd(), i, []), s.syncLocalEditorDataTemplates(i), s.syncLocalEditorTemplate(i);
2350
2354
  }, p = () => {
2351
2355
  Se(o), o = [];
@@ -2359,10 +2363,10 @@ const Tt = async (t, e, n) => {
2359
2363
  })), {
2360
2364
  name: "vite-plugin-yext-visual-editor",
2361
2365
  async config(g, { command: y }) {
2362
- e = y === "build", y === "serve" && t.localEditor?.enabled && (d(), a ? await l() : s.cleanupGeneratedLocalEditorArtifacts(), n = !0);
2366
+ e = y === "build", y === "serve" && t.localEditor?.enabled && (d(), a ? await c() : s.cleanupGeneratedLocalEditorArtifacts(), n = !0);
2363
2367
  },
2364
2368
  async buildStart() {
2365
- n || d(), !e && t.localEditor?.enabled && !n && a ? await l() : n || s.cleanupGeneratedLocalEditorArtifacts();
2369
+ n || d(), !e && t.localEditor?.enabled && !n && a ? await c() : n || s.cleanupGeneratedLocalEditorArtifacts();
2366
2370
  },
2367
2371
  generateBundle() {
2368
2372
  r && this.emitFile({