@osimart/create-storefront 1.0.3 → 1.0.7

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.
@@ -238,9 +238,18 @@ export function useContentTree(section, options = {}) {
238
238
  const HEADINGS = ["H1", "H2", "H3", "H4", "H5", "H6"];
239
239
 
240
240
  const plain = (html) => String(html || "").replace(/<(img|video|iframe)\b/gi, "x").replace(/<[^>]*>/g, "").replace(/&nbsp;/g, " ").trim();
241
- // A heading preset renders as <hN>: its richtext paragraphs become lines.
241
+ // A heading preset renders as <hN>, which can't hold blocks: the editor's
242
+ // paragraphs, headings and list items become lines (<br>) inside it.
243
+ // Inline formatting (<b>, <i>, <a>, …) is kept.
242
244
  const inline = (html) =>
243
- String(html).replace(/<\/p>\s*<p[^>]*>/gi, "<br>").replace(/^\s*<p[^>]*>/i, "").replace(/<\/p>\s*$/i, "");
245
+ String(html)
246
+ .replace(/<(p|h[1-6]|li)\b[^>]*>\s*<br\s*\/?>\s*<\/\1>/gi, "<$1></$1>") // a blank line = one <br>
247
+ .replace(/<\/?(ul|ol)\b[^>]*>/gi, "")
248
+ .replace(/<(p|h[1-6]|li|blockquote|div)\b[^>]*>/gi, "")
249
+ .replace(/<\/(p|h[1-6]|li|blockquote|div)>/gi, "<br>")
250
+ .replace(/^(\s*<br\s*\/?>)+/i, "")
251
+ .replace(/(<br\s*\/?>\s*)+$/i, "")
252
+ .trim();
244
253
 
245
254
  /* ------------------------------------------------------------ the tree */
246
255
 
@@ -47,6 +47,7 @@ const API_ROOT = storeApiBase
47
47
  console.log("storedataaaaa", bootstrapData.value);
48
48
  } catch (error) {
49
49
  console.error('[useStoreInit] Failed to fetch bootstrap data:', error);
50
+ throw error;
50
51
  }
51
52
 
52
53
  return bootstrapData.value;
@@ -22,6 +22,13 @@ const FOOTER_APPEARANCE = [
22
22
  "FOOTER_LINK_COLOR", "FOOTER_LINK_HOVER_COLOR",
23
23
  ];
24
24
 
25
+ function unavailable(status, message) {
26
+ const err = new Error(message);
27
+ err.status = status;
28
+ err.code = "STORE_UNAVAILABLE";
29
+ return err;
30
+ }
31
+
25
32
  /** Menus arrive as a map keyed by handle from bootstrap, and as a plain list
26
33
  * from the dashboard's MENUS message. Normalize to the map either way. */
27
34
  function menusAsMap(value) {
@@ -120,8 +127,7 @@ export function useStorefront() {
120
127
 
121
128
  // The bar's own on / off is now "is the section there (and shown)".
122
129
  const bar = chrome.find((s) => s.type === "ANNOUNCEMENT_BAR");
123
- out.ANNOUNCEMENT_ENABLED =
124
- !!bar && (!bar.disabled || !!previewState.value);
130
+ out.ANNOUNCEMENT_ENABLED = !!bar && !bar.disabled;
125
131
  return out;
126
132
  });
127
133
 
@@ -185,7 +191,14 @@ export function useStorefront() {
185
191
  // and derives baseUrl from the store's username in the response. Reuse
186
192
  // that payload instead of firing a second, redundant bootstrap request.
187
193
  if (!bootstrapData.value) await init();
188
- data.value = bootstrapData.value;
194
+ const payload = bootstrapData.value;
195
+
196
+ if (!payload?.store) throw unavailable(404, "No store for this address");
197
+ if (payload.store.is_active === false || payload.store.available === false) {
198
+ throw unavailable(402, "This store is currently unavailable");
199
+ }
200
+
201
+ data.value = payload;
189
202
 
190
203
  const available = data.value?.store?.locales ?? ["en"];
191
204
  if (!available.includes(locale.value)) {
@@ -39,13 +39,13 @@ export default function useLogic() {
39
39
  const { sectionGroups } = useStorefront();
40
40
  const { isPreview } = useBuilderPreview();
41
41
  const headerSections = computed(() => {
42
- const list = (sectionGroups.value?.header ?? []).filter((s) => isPreview.value || !s.disabled);
42
+ const list = (sectionGroups.value?.header ?? []).filter((s) => !s.disabled);
43
43
  if (chrome.value === "bare") return [];
44
44
  return chrome.value === "minimal" ? list.filter((s) => s.type === "HEADER") : list;
45
45
  });
46
46
  const footerSections = computed(() =>
47
47
  chrome.value === "full"
48
- ? (sectionGroups.value?.footer ?? []).filter((s) => isPreview.value || !s.disabled)
48
+ ? (sectionGroups.value?.footer ?? []).filter((s) => !s.disabled)
49
49
  : []
50
50
  );
51
51