@nubisco/cms-vue 1.2.0 → 1.4.0

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.js CHANGED
@@ -1,336 +1,328 @@
1
- import { Fragment as e, computed as t, createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, defineComponent as o, inject as s, normalizeClass as c, openBlock as l, provide as u, ref as d, renderList as f, renderSlot as p, resolveDynamicComponent as m, toDisplayString as h, unref as g, withCtx as _, withKeys as v, withModifiers as y } from "vue";
2
- //#region src/contract/logic.ts
3
- var b = [
4
- {
5
- id: "featureFlag",
6
- label: "Feature flag",
7
- valueType: "boolean",
8
- params: { flag: {
9
- type: "text",
10
- label: "Flag key",
11
- required: !0
12
- } },
13
- resolveAt: "build"
14
- },
15
- {
16
- id: "environment",
17
- label: "Environment",
18
- valueType: "enum",
19
- enumValues: ["staging", "production"],
20
- resolveAt: "build"
21
- },
22
- {
23
- id: "locale",
24
- label: "Locale",
25
- valueType: "enum",
26
- enumValues: [
27
- "en",
28
- "pt",
29
- "es",
30
- "fr"
31
- ],
32
- resolveAt: "build"
33
- },
34
- {
35
- id: "schedule",
36
- label: "Schedule window",
37
- valueType: "date",
38
- params: {
39
- from: {
40
- type: "date",
41
- label: "From"
42
- },
43
- to: {
44
- type: "date",
45
- label: "To"
46
- }
47
- },
48
- resolveAt: "build"
49
- },
50
- {
51
- id: "auth",
52
- label: "Signed in",
53
- valueType: "boolean",
54
- resolveAt: "request"
55
- },
56
- {
57
- id: "region",
58
- label: "Region",
59
- valueType: "enum",
60
- enumValues: [
61
- "EU",
62
- "NA",
63
- "SA",
64
- "AS",
65
- "AF",
66
- "OC"
67
- ],
68
- resolveAt: "request"
1
+ import { applySerializers as e, compileLinks as t, evaluate as n, isHtml as r, linkAttrs as i, linkTag as a, normalizeImage as o, normalizeLink as s, pickField as c, text as l } from "@nubisco/cms-core";
2
+ import { Fragment as u, computed as d, createBlock as f, createCommentVNode as p, createElementBlock as m, createElementVNode as h, createTextVNode as g, defineComponent as _, getCurrentInstance as v, inject as y, mergeProps as b, normalizeClass as x, openBlock as S, provide as C, ref as w, renderList as T, renderSlot as E, resolveDynamicComponent as D, toDisplayString as O, unref as k, withCtx as A, withKeys as ee, withModifiers as j } from "vue";
3
+ export * from "@nubisco/cms-core";
4
+ //#region src/context.ts
5
+ var M = Symbol("cms-context");
6
+ //#endregion
7
+ //#region src/useField.ts
8
+ function N() {
9
+ let e = y(M, {
10
+ messages: {},
11
+ editing: !1,
12
+ setText: () => {}
13
+ });
14
+ return { t: (t) => l(t, e.messages) };
15
+ }
16
+ //#endregion
17
+ //#region src/client.ts
18
+ var P = Symbol("cms-client");
19
+ function F() {
20
+ return typeof window > "u";
21
+ }
22
+ function te() {
23
+ return typeof window < "u" ? new URLSearchParams(window.location.search) : null;
24
+ }
25
+ function I() {
26
+ let e = te();
27
+ return e?.has("cms-edit") ? {
28
+ active: !0,
29
+ environment: e.get("cms-env")?.trim() || void 0,
30
+ token: e.get("cms-preview-token")?.trim() || void 0
31
+ } : { active: !1 };
32
+ }
33
+ var L = { active: !1 };
34
+ function R(e) {
35
+ if (!e.apiBase) throw Error("createCms: apiBase is required, for example https://cms.example.com");
36
+ if (!e.siteId) throw Error("createCms: siteId is required");
37
+ let t = e.apiBase.replace(/\/$/, ""), n = e.environment || "production", r = e.siteId, i = e.fetch ?? ((e, t) => fetch(e, t)), a = e.preview ?? I;
38
+ function o() {
39
+ try {
40
+ return a() ?? L;
41
+ } catch {
42
+ return L;
43
+ }
69
44
  }
70
- ], x = {
71
- featureFlag: {
72
- label: "Feature flag",
73
- color: "#6e6bd6",
74
- category: "input",
75
- ports: [{
76
- id: "out",
77
- label: "on",
78
- type: "output"
79
- }],
80
- param: "flag"
81
- },
82
- environment: {
83
- label: "Environment",
84
- color: "#b9781e",
85
- category: "input",
86
- ports: [{
87
- id: "out",
88
- label: "is",
89
- type: "output"
90
- }],
91
- param: "environment"
92
- },
93
- auth: {
94
- label: "Signed in",
95
- color: "#2c9560",
96
- category: "input",
97
- ports: [{
98
- id: "out",
99
- label: "yes",
100
- type: "output"
101
- }]
102
- },
103
- region: {
104
- label: "Region",
105
- color: "#3a86c8",
106
- category: "input",
107
- ports: [{
108
- id: "out",
109
- label: "in",
110
- type: "output"
111
- }],
112
- param: "region"
113
- },
114
- and: {
115
- label: "AND",
116
- color: "#5a5a6a",
117
- category: "gate",
118
- ports: [
119
- {
120
- id: "a",
121
- label: "a",
122
- type: "input"
123
- },
124
- {
125
- id: "b",
126
- label: "b",
127
- type: "input"
128
- },
129
- {
130
- id: "out",
131
- label: "out",
132
- type: "output"
133
- }
134
- ]
135
- },
136
- or: {
137
- label: "OR",
138
- color: "#5a5a6a",
139
- category: "gate",
140
- ports: [
141
- {
142
- id: "a",
143
- label: "a",
144
- type: "input"
145
- },
146
- {
147
- id: "b",
148
- label: "b",
149
- type: "input"
150
- },
151
- {
152
- id: "out",
153
- label: "out",
154
- type: "output"
155
- }
156
- ]
157
- },
158
- not: {
159
- label: "NOT",
160
- color: "#5a5a6a",
161
- category: "gate",
162
- ports: [{
163
- id: "in",
164
- label: "in",
165
- type: "input"
166
- }, {
167
- id: "out",
168
- label: "out",
169
- type: "output"
170
- }]
171
- },
172
- visible: {
173
- label: "Visible",
174
- color: "#c0392b",
175
- category: "output",
176
- ports: [{
177
- id: "in",
178
- label: "show",
179
- type: "input"
180
- }]
45
+ function s(e) {
46
+ let i = o(), a = i.active && i.environment || n, s = i.active ? i.token ? `?previewToken=${encodeURIComponent(i.token)}` : "?preview=1" : "";
47
+ return `${t}/api/v1/${r}/${a}/${e.replace(/^\/+/, "")}${s}`;
48
+ }
49
+ async function c(e) {
50
+ let t = o().active || F() ? "no-store" : "default", n = await i(s(e), { cache: t });
51
+ return n.ok ? {
52
+ status: n.status,
53
+ body: await n.json()
54
+ } : {
55
+ status: n.status,
56
+ body: null
57
+ };
181
58
  }
182
- };
183
- function S(e) {
184
- return e.nodes.map((e) => {
185
- let t = x[e.kind], n = e.param ? `${t.label}: ${e.param}` : t.label;
186
- return {
187
- id: e.id,
188
- x: e.x,
189
- y: e.y,
190
- width: 160,
191
- height: 52 + t.ports.length * 8,
192
- paint: {
193
- title: n,
194
- color: t.color,
195
- category: t.category,
196
- ports: t.ports
59
+ async function l(e) {
60
+ try {
61
+ let t = await c(e);
62
+ if (!t) return {
63
+ doc: null,
64
+ error: "CMS delivery unreachable",
65
+ outcome: "unavailable"
66
+ };
67
+ if (t.body === null) {
68
+ let e = t.status === 404 || t.status === 410;
69
+ return {
70
+ doc: null,
71
+ error: `CMS delivery ${t.status}`,
72
+ outcome: e ? "missing" : "unavailable"
73
+ };
197
74
  }
75
+ let n = t.body;
76
+ return {
77
+ doc: n,
78
+ error: null,
79
+ outcome: n?.zones?.main ? "ok" : "missing"
80
+ };
81
+ } catch {
82
+ return {
83
+ doc: null,
84
+ error: "CMS delivery unreachable",
85
+ outcome: "unavailable"
86
+ };
87
+ }
88
+ }
89
+ async function u(t) {
90
+ if (e.partials === !1) return {
91
+ doc: null,
92
+ error: "CMS partials are off"
198
93
  };
199
- });
200
- }
201
- function C(e, t) {
202
- let n = {}, r = (t, n) => e.connections.find((e) => e.toNode === t && e.toPort === n)?.fromNode, i = (e, t) => {
203
- let n = r(e, t);
204
- return n ? a(n) : !1;
205
- };
206
- function a(r) {
207
- if (r in n) return n[r];
208
- n[r] = !1;
209
- let a = e.nodes.find((e) => e.id === r);
210
- if (!a) return !1;
211
- let o = !1;
212
- switch (a.kind) {
213
- case "featureFlag":
214
- o = t.featureFlag?.({ flag: a.param ?? "" }, void 0, void 0) ?? !1;
215
- break;
216
- case "environment":
217
- o = t.environment?.(void 0, "is", a.param ?? "staging") ?? !1;
218
- break;
219
- case "auth":
220
- o = t.auth?.(void 0, void 0, void 0) ?? !1;
221
- break;
222
- case "region":
223
- o = t.region?.(void 0, "in", [a.param ?? ""]) ?? !1;
224
- break;
225
- case "and":
226
- o = i(r, "a") && i(r, "b");
227
- break;
228
- case "or":
229
- o = i(r, "a") || i(r, "b");
230
- break;
231
- case "not":
232
- o = !i(r, "in");
233
- break;
234
- case "visible": o = i(r, "in");
94
+ try {
95
+ let e = await c(`_partials/${encodeURIComponent(t)}`);
96
+ if (!e) return {
97
+ doc: null,
98
+ error: "CMS delivery unreachable"
99
+ };
100
+ if (e.body === null) return {
101
+ doc: null,
102
+ error: `CMS delivery ${e.status}`
103
+ };
104
+ let n = e.body;
105
+ return n?.zones?.main?.blocks?.length ? {
106
+ doc: n,
107
+ error: ""
108
+ } : {
109
+ doc: null,
110
+ error: "CMS partial is empty"
111
+ };
112
+ } catch {
113
+ return {
114
+ doc: null,
115
+ error: "CMS delivery unreachable"
116
+ };
235
117
  }
236
- return n[r] = o, o;
237
118
  }
238
- let o = e.nodes.find((e) => e.kind === "visible"), s = {};
239
- for (let t of e.nodes) s[t.id] = a(t.id);
240
- return {
241
- visible: o ? a(o.id) : !1,
242
- nodeOut: s
119
+ function d(t) {
120
+ return e.navigate ? (e.navigate(t), !0) : e.router ? (e.router.push(t), !0) : !1;
121
+ }
122
+ let f = {
123
+ siteId: r,
124
+ environment: n,
125
+ apiBase: t,
126
+ patchMessageType: e.patchMessageType ?? "nubisco-cms:patch",
127
+ options: e,
128
+ preview: o,
129
+ documentUrl: s,
130
+ navigate: d,
131
+ fetchPage: l,
132
+ fetchPartial: u,
133
+ install(e) {
134
+ e.provide(P, f);
135
+ }
243
136
  };
137
+ return f;
138
+ }
139
+ function z() {
140
+ return y(P, null);
141
+ }
142
+ function ne() {
143
+ let e = z();
144
+ if (!e) throw Error("[cms-vue] No CMS client provided. Call app.use(createCms({ siteId }))");
145
+ return e;
244
146
  }
245
147
  //#endregion
246
- //#region src/evaluate.ts
247
- function w(e, t, n) {
248
- if (!e || e.kind === "always") return !0;
249
- switch (e.kind) {
250
- case "simple": {
251
- let n = t[e.input];
252
- return n ? n(e.params, e.op, e.value) : !1;
148
+ //#region src/usePage.ts
149
+ function re(e, t) {
150
+ let n = t ?? z(), r = w(null), i = w(null), a = w("unavailable"), o = w(!1);
151
+ async function s() {
152
+ if (!n) {
153
+ i.value = "CMS client is not configured", a.value = "unavailable";
154
+ return;
253
155
  }
254
- case "all": return e.of.every((e) => w(e, t, n));
255
- case "any": return e.of.some((e) => w(e, t, n));
256
- case "not": return !w(e.of, t, n);
257
- case "graph": {
258
- let r = n?.[e.graphId];
259
- return !r || C(r, t).visible;
156
+ o.value = !0;
157
+ try {
158
+ let t = await n.fetchPage(e);
159
+ r.value = t.doc, i.value = t.error, a.value = t.outcome;
160
+ } finally {
161
+ o.value = !1;
260
162
  }
261
163
  }
164
+ return {
165
+ doc: r,
166
+ error: i,
167
+ outcome: a,
168
+ loading: o,
169
+ load: s
170
+ };
262
171
  }
263
172
  //#endregion
264
- //#region src/resolve.ts
265
- function T(e) {
266
- return typeof e == "object" && !!e && "$t" in e;
173
+ //#region src/usePartial.ts
174
+ var B = /* @__PURE__ */ new Map();
175
+ function V(e) {
176
+ if (!F()) return B;
177
+ let t = e ?? v()?.appContext.app;
178
+ return t ? t.__cmsPartialStates ??= /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map();
267
179
  }
268
- function E(e) {
269
- return typeof e == "object" && !!e && "src" in e;
180
+ function H(e, t) {
181
+ return e ? `${e.siteId}:${e.environment}:${t}` : `:${t}`;
270
182
  }
271
- function D(e) {
272
- return typeof e == "object" && !!e && "href" in e;
183
+ function U() {
184
+ return {
185
+ doc: w(null),
186
+ messages: w({}),
187
+ error: w(null),
188
+ loading: w(!0),
189
+ started: !1,
190
+ ready: null
191
+ };
273
192
  }
274
- function O(e, t) {
275
- return e == null ? "" : typeof e == "string" ? e : typeof e == "number" || typeof e == "boolean" ? String(e) : T(e) ? t[e.$t] ?? e.$t : "";
193
+ function W(e, t) {
194
+ let n = V(t), r = n.get(e);
195
+ return r || (r = U(), n.set(e, r)), r;
276
196
  }
277
- //#endregion
278
- //#region src/context.ts
279
- var k = Symbol("cms-context");
280
- //#endregion
281
- //#region src/useField.ts
282
- function A() {
283
- let e = s(k, {
284
- messages: {},
285
- editing: !1,
286
- setText: () => {}
197
+ function G(e, t) {
198
+ if (!e || typeof e != "object") return !1;
199
+ let n = e, r = (typeof n.contentType == "string" ? n.contentType : typeof n.content_type == "string" ? n.content_type : "") === "partial" || n.kind === "partial", i = typeof n.key == "string" ? n.key : typeof n.route == "string" && !n.route.startsWith("/") ? n.route : "";
200
+ return !r && !i ? !1 : !t || i === t || r && i === "";
201
+ }
202
+ function K(e) {
203
+ let t = /* @__PURE__ */ new Set(), n = (e) => {
204
+ if (e) try {
205
+ t.add(new URL(e).origin);
206
+ } catch {}
207
+ };
208
+ n(e?.apiBase);
209
+ for (let t of e?.options.consoleOrigins ?? []) n(t);
210
+ return n(typeof document < "u" ? document.referrer : void 0), Array.from(t);
211
+ }
212
+ function q(e, t, n) {
213
+ typeof window > "u" || window.addEventListener("message", (r) => {
214
+ if (!e?.preview().active) return;
215
+ if (window.parent !== window) {
216
+ if (r.source !== window.parent || !K(e).includes(r.origin)) return;
217
+ } else if (r.origin !== window.location.origin) return;
218
+ let i = r.data, a = e?.patchMessageType ?? "nubisco-cms:patch";
219
+ !i || i.type !== a || !i.document?.zones?.main || G(i.document, t) && (i.messages && typeof i.messages == "object" && (n.messages.value = i.messages), n.doc.value = i.document, n.error.value = "", n.loading.value = !1);
220
+ });
221
+ }
222
+ function J(e, t) {
223
+ let n = t ?? z(), r = W(H(n, e));
224
+ return r.started || (r.started = !0, n ? (n.options.livePreview !== !1 && n.preview().active && q(n, e, r), r.ready = n.fetchPartial(e).then((e) => {
225
+ r.doc.value || (r.doc.value = e.doc, r.error.value = e.error, r.loading.value = !1);
226
+ }), r.ready) : (r.error.value = "CMS client is not configured", r.loading.value = !1)), {
227
+ doc: r.doc,
228
+ messages: r.messages,
229
+ error: r.error,
230
+ loading: r.loading,
231
+ whenReady: () => r.ready ?? Promise.resolve()
232
+ };
233
+ }
234
+ function Y() {
235
+ B.clear();
236
+ }
237
+ var X = "cmsPartials";
238
+ function ie(e) {
239
+ let t = {};
240
+ for (let [n, r] of V(e)) r.loading.value || (t[n] = {
241
+ doc: r.doc.value,
242
+ error: r.error.value
287
243
  });
288
- return { t: (t) => O(t, e.messages) };
244
+ return t;
245
+ }
246
+ function ae(e, t) {
247
+ if (!(!e || typeof e != "object") && !t?.preview().active) for (let [t, n] of Object.entries(e)) {
248
+ let e = n;
249
+ if (!e || typeof e != "object") continue;
250
+ let r = W(t);
251
+ r.started || (r.started = !0, r.doc.value = e.doc ?? null, r.error.value = typeof e.error == "string" ? e.error : e.doc ? "" : "CMS partial unavailable", r.loading.value = !1, r.ready = Promise.resolve());
252
+ }
253
+ }
254
+ //#endregion
255
+ //#region src/props.ts
256
+ function Z() {
257
+ return {
258
+ block: {
259
+ type: Object,
260
+ required: !0
261
+ },
262
+ index: {
263
+ type: Number,
264
+ required: !1,
265
+ default: 0
266
+ },
267
+ blocks: {
268
+ type: Array,
269
+ required: !1,
270
+ default: () => []
271
+ },
272
+ context: {
273
+ type: null,
274
+ required: !1,
275
+ default: void 0
276
+ }
277
+ };
278
+ }
279
+ function oe() {
280
+ return Z();
289
281
  }
290
282
  //#endregion
291
283
  //#region src/CmsText.vue?vue&type=script&setup=true&lang.ts
292
- var j = [
284
+ var se = [
293
285
  "data-cms-block",
294
286
  "data-cms-field",
295
287
  "onKeydown"
296
- ], M = { key: 1 }, N = /*@__PURE__*/ o({
288
+ ], ce = { key: 1 }, le = /*@__PURE__*/ _({
297
289
  __name: "CmsText",
298
290
  props: {
299
291
  block: {},
300
292
  field: {}
301
293
  },
302
294
  setup(e) {
303
- let n = e, r = s(k, {
295
+ let t = e, n = y(M, {
304
296
  messages: {},
305
297
  editing: !1,
306
298
  setText: () => {}
307
- }), a = t(() => n.block.fields[n.field]), o = t(() => O(a.value, r.messages)), c = d(null);
308
- function u() {
309
- let e = c.value?.innerText.trim() ?? "";
310
- e !== o.value && r.setText(n.block, n.field, a.value, e), c.value?.blur();
299
+ }), r = d(() => t.block.fields[t.field]), i = d(() => l(r.value, n.messages)), a = w(null);
300
+ function o() {
301
+ let e = a.value?.innerText.trim() ?? "";
302
+ e !== i.value && n.setText(t.block, t.field, r.value, e), a.value?.blur();
311
303
  }
312
- return (t, n) => g(r).editing ? (l(), i("span", {
304
+ return (t, r) => k(n).editing ? (S(), m("span", {
313
305
  key: 0,
314
306
  ref_key: "el",
315
- ref: c,
307
+ ref: a,
316
308
  class: "cms-text cms-text--editing",
317
309
  "data-cms-block": e.block.id,
318
310
  "data-cms-field": e.field,
319
311
  contenteditable: "plaintext-only",
320
312
  role: "textbox",
321
313
  tabindex: "0",
322
- onBlur: u,
323
- onKeydown: v(y(u, ["prevent"]), ["enter"])
324
- }, h(o.value), 41, j)) : (l(), i("span", M, h(o.value), 1));
314
+ onBlur: o,
315
+ onKeydown: ee(j(o, ["prevent"]), ["enter"])
316
+ }, O(i.value), 41, se)) : (S(), m("span", ce, O(i.value), 1));
325
317
  }
326
- }), P = (e, t) => {
318
+ }), Q = (e, t) => {
327
319
  let n = e.__vccOpts || e;
328
320
  for (let [e, r] of t) n[e] = r;
329
321
  return n;
330
- }, F = /*#__PURE__*/ P(N, [["__scopeId", "data-v-57962fd1"]]), I = { class: "bf__type" }, L = {
322
+ }, ue = /*#__PURE__*/ Q(le, [["__scopeId", "data-v-67fffd3d"]]), de = { class: "bf__type" }, fe = {
331
323
  key: 0,
332
324
  class: "bf__badge"
333
- }, R = ["disabled"], z = ["disabled"], B = { class: "bf__body" }, V = /*#__PURE__*/ P(/* @__PURE__ */ o({
325
+ }, pe = ["disabled"], $ = ["disabled"], me = { class: "bf__body" }, he = /*#__PURE__*/ Q(/* @__PURE__ */ _({
334
326
  __name: "BlockFrame",
335
327
  props: {
336
328
  label: {},
@@ -345,43 +337,43 @@ var j = [
345
337
  "select"
346
338
  ],
347
339
  setup(e) {
348
- return (t, n) => (l(), i("div", { class: c(["bf", {
340
+ return (t, n) => (S(), m("div", { class: x(["bf", {
349
341
  "bf--dim": e.hidden,
350
342
  "bf--selected": e.selected
351
- }]) }, [a("div", {
343
+ }]) }, [h("div", {
352
344
  class: "bf__bar",
353
345
  onClick: n[2] ||= (e) => t.$emit("select")
354
346
  }, [
355
- n[3] ||= a("span", {
347
+ n[3] ||= h("span", {
356
348
  class: "bf__grip",
357
349
  "aria-hidden": "true"
358
350
  }, "⠿", -1),
359
- a("span", I, h(e.label), 1),
360
- e.hidden ? (l(), i("span", L, "hidden by condition")) : r("", !0),
361
- n[4] ||= a("span", { class: "bf__spacer" }, null, -1),
362
- a("button", {
351
+ h("span", de, O(e.label), 1),
352
+ e.hidden ? (S(), m("span", fe, "hidden by condition")) : p("", !0),
353
+ n[4] ||= h("span", { class: "bf__spacer" }, null, -1),
354
+ h("button", {
363
355
  class: "bf__btn",
364
356
  type: "button",
365
357
  disabled: e.isFirst,
366
358
  title: "Move up",
367
- onClick: n[0] ||= y((e) => t.$emit("up"), ["stop"])
368
- }, " ↑ ", 8, R),
369
- a("button", {
359
+ onClick: n[0] ||= j((e) => t.$emit("up"), ["stop"])
360
+ }, " ↑ ", 8, pe),
361
+ h("button", {
370
362
  class: "bf__btn",
371
363
  type: "button",
372
364
  disabled: e.isLast,
373
365
  title: "Move down",
374
- onClick: n[1] ||= y((e) => t.$emit("down"), ["stop"])
375
- }, " ↓ ", 8, z)
376
- ]), a("div", B, [p(t.$slots, "default", {}, void 0, !0)])], 2));
366
+ onClick: n[1] ||= j((e) => t.$emit("down"), ["stop"])
367
+ }, " ↓ ", 8, $)
368
+ ]), h("div", me, [E(t.$slots, "default", {}, void 0, !0)])], 2));
377
369
  }
378
- }), [["__scopeId", "data-v-22d52899"]]), H = { class: "cms-zone" }, U = {
370
+ }), [["__scopeId", "data-v-22d52899"]]), ge = { class: "cms-zone" }, _e = {
379
371
  key: 1,
380
372
  class: "cms-zone__missing"
381
- }, W = {
373
+ }, ve = {
382
374
  key: 1,
383
375
  class: "cms-zone__missing"
384
- }, G = /*#__PURE__*/ P(/* @__PURE__ */ o({
376
+ }, ye = /*#__PURE__*/ Q(/* @__PURE__ */ _({
385
377
  __name: "CmsZone",
386
378
  props: {
387
379
  zone: {},
@@ -391,48 +383,57 @@ var j = [
391
383
  editing: { type: Boolean },
392
384
  selectedId: {},
393
385
  graphs: {},
386
+ provideBlockProps: { type: Boolean },
387
+ context: {},
394
388
  setText: { type: Function }
395
389
  },
396
390
  emits: ["select"],
397
- setup(r, { emit: a }) {
398
- let o = r, s = a;
399
- u(k, {
391
+ setup(e, { emit: t }) {
392
+ let r = e, i = t;
393
+ C(M, {
400
394
  get messages() {
401
- return o.messages;
395
+ return r.messages;
402
396
  },
403
397
  get editing() {
404
- return o.editing ?? !1;
398
+ return r.editing ?? !1;
405
399
  },
406
- setText: (e, t, n, r) => o.setText?.(e, t, n, r)
400
+ setText: (e, t, n, i) => r.setText?.(e, t, n, i)
407
401
  });
408
- function c(e) {
409
- return w(e.when, o.env, o.graphs);
402
+ function a(e) {
403
+ return n(e.when, r.env, r.graphs);
410
404
  }
411
- let d = t(() => o.zone.blocks.filter(c));
412
- function p(e) {
405
+ let o = d(() => r.zone.blocks.filter(a));
406
+ function s(e) {
407
+ if (r.provideBlockProps) return {
408
+ index: e,
409
+ blocks: r.zone.blocks,
410
+ context: r.context
411
+ };
412
+ }
413
+ function c(e) {
413
414
  return e.type + (e.variation ? ` · ${e.variation}` : "");
414
415
  }
415
- function g(e, t) {
416
- let n = o.zone.blocks;
416
+ function l(e, t) {
417
+ let n = r.zone.blocks;
417
418
  if (t < 0 || t >= n.length) return;
418
- let [r] = n.splice(e, 1);
419
- n.splice(t, 0, r);
419
+ let [i] = n.splice(e, 1);
420
+ n.splice(t, 0, i);
420
421
  }
421
- return (t, a) => (l(), i("div", H, [r.editing ? (l(!0), i(e, { key: 0 }, f(r.zone.blocks, (e, t) => (l(), n(V, {
422
- key: e.id,
423
- label: p(e),
424
- hidden: !c(e),
425
- "is-first": t === 0,
426
- "is-last": t === r.zone.blocks.length - 1,
427
- selected: e.id === r.selectedId,
428
- onUp: (e) => g(t, t - 1),
429
- onDown: (e) => g(t, t + 1),
430
- onSelect: (t) => s("select", e.id)
422
+ return (t, n) => (S(), m("div", ge, [e.editing ? (S(!0), m(u, { key: 0 }, T(e.zone.blocks, (t, n) => (S(), f(he, {
423
+ key: t.id,
424
+ label: c(t),
425
+ hidden: !a(t),
426
+ "is-first": n === 0,
427
+ "is-last": n === e.zone.blocks.length - 1,
428
+ selected: t.id === e.selectedId,
429
+ onUp: (e) => l(n, n - 1),
430
+ onDown: (e) => l(n, n + 1),
431
+ onSelect: (e) => i("select", t.id)
431
432
  }, {
432
- default: _(() => [r.registry[e.type] ? (l(), n(m(r.registry[e.type]), {
433
+ default: A(() => [e.registry[t.type] ? (S(), f(D(e.registry[t.type]), b({
433
434
  key: 0,
434
- block: e
435
- }, null, 8, ["block"])) : (l(), i("div", U, "Unknown block type: " + h(e.type), 1))]),
435
+ block: t
436
+ }, { ref_for: !0 }, s(n)), null, 16, ["block"])) : (S(), m("div", _e, "Unknown block type: " + O(t.type), 1))]),
436
437
  _: 2
437
438
  }, 1032, [
438
439
  "label",
@@ -443,11 +444,169 @@ var j = [
443
444
  "onUp",
444
445
  "onDown",
445
446
  "onSelect"
446
- ]))), 128)) : (l(!0), i(e, { key: 1 }, f(d.value, (t) => (l(), i(e, { key: t.id }, [r.registry[t.type] ? (l(), n(m(r.registry[t.type]), {
447
+ ]))), 128)) : (S(!0), m(u, { key: 1 }, T(o.value, (t, n) => (S(), m(u, { key: t.id }, [e.registry[t.type] ? (S(), f(D(e.registry[t.type]), b({
447
448
  key: 0,
448
449
  block: t
449
- }, null, 8, ["block"])) : (l(), i("div", W, "Unknown block type: " + h(t.type), 1))], 64))), 128))]));
450
+ }, { ref_for: !0 }, s(n)), null, 16, ["block"])) : (S(), m("div", ve, "Unknown block type: " + O(t.type), 1))], 64))), 128))]));
451
+ }
452
+ }), [["__scopeId", "data-v-6a544d0b"]]), be = /* @__PURE__ */ _({
453
+ __name: "CmsRichText",
454
+ props: {
455
+ block: {},
456
+ field: {},
457
+ value: {},
458
+ serializers: {},
459
+ as: { default: "div" },
460
+ plainAs: { default: "p" },
461
+ transform: {}
462
+ },
463
+ setup(n, { expose: i }) {
464
+ let a = n, o = y(M, {
465
+ messages: {},
466
+ editing: !1,
467
+ setText: () => {}
468
+ }), s = z(), u = d(() => a.block?.fields);
469
+ function m(e) {
470
+ return e === void 0 ? [] : typeof e == "string" ? [e] : e;
471
+ }
472
+ let h = d(() => {
473
+ if (!a.block) return;
474
+ let e = u.value;
475
+ return m(a.field).find((t) => e && e[t] !== void 0 && e[t] !== null);
476
+ }), _ = d(() => a.block?.id), v = d(() => a.value === void 0 ? c(u.value, m(a.field)) : a.value), b = d(() => l(v.value, o.messages)), x = d(() => r(b.value)), C = d(() => x.value ? "" : b.value), w = d(() => {
477
+ let n = e(t(b.value), a.serializers);
478
+ return a.transform && (n = a.transform(n)), n;
479
+ });
480
+ function T(e) {
481
+ if (!s || e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
482
+ let t = e.target?.closest?.("a");
483
+ if (!t || t.hasAttribute("download")) return;
484
+ let n = t.getAttribute("target");
485
+ if (n && n !== "_self") return;
486
+ let r = t.getAttribute("href") ?? "";
487
+ !r.startsWith("/") || r.startsWith("//") || s.navigate(r) && e.preventDefault();
488
+ }
489
+ return i({
490
+ html: w,
491
+ plain: C
492
+ }), (e, t) => x.value ? (S(), f(D(n.as), {
493
+ key: 0,
494
+ class: "cms-richtext-body",
495
+ "data-cms-block": _.value,
496
+ "data-cms-field": h.value,
497
+ "data-cms-field-kind": "richtext",
498
+ onClick: T,
499
+ innerHTML: w.value
500
+ }, null, 8, [
501
+ "data-cms-block",
502
+ "data-cms-field",
503
+ "innerHTML"
504
+ ])) : C.value ? (S(), f(D(n.plainAs), {
505
+ key: 1,
506
+ class: "cms-richtext-body",
507
+ "data-cms-block": _.value,
508
+ "data-cms-field": h.value,
509
+ "data-cms-field-kind": "richtext"
510
+ }, {
511
+ default: A(() => [g(O(C.value), 1)]),
512
+ _: 1
513
+ }, 8, ["data-cms-block", "data-cms-field"])) : p("", !0);
514
+ }
515
+ }), xe = /*#__PURE__*/ Q(/* @__PURE__ */ _({
516
+ __name: "CmsLink",
517
+ props: {
518
+ block: {},
519
+ field: {},
520
+ value: {},
521
+ fallback: {},
522
+ label: {},
523
+ labelField: {}
524
+ },
525
+ setup(e, { expose: t }) {
526
+ let n = e, r = y(M, {
527
+ messages: {},
528
+ editing: !1,
529
+ setText: () => {}
530
+ }), o = z(), u = d(() => n.block?.fields);
531
+ function p(e) {
532
+ return e === void 0 ? [] : typeof e == "string" ? [e] : e;
533
+ }
534
+ let m = d(() => {
535
+ if (!n.block) return;
536
+ let e = u.value;
537
+ return p(n.field).find((t) => e && e[t] !== void 0 && e[t] !== null);
538
+ }), h = d(() => n.block?.id), _ = d(() => n.value === void 0 ? c(u.value, p(n.field)) : n.value), v = d(() => s(_.value, n.fallback ?? "")), x = d(() => a(v.value)), C = d(() => i(v.value)), w = d(() => {
539
+ if (n.label !== void 0) return l(n.label, r.messages);
540
+ let e = c(u.value, p(n.labelField));
541
+ return e === void 0 ? "" : l(e, r.messages);
542
+ });
543
+ t({ link: v });
544
+ function T(e) {
545
+ let t = v.value;
546
+ !t.ok || !t.internal || !t.href || t.newTab || e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || o && o.navigate(t.href) && e.preventDefault();
547
+ }
548
+ return (e, t) => (S(), f(D(x.value), b(C.value, {
549
+ class: ["cms-link", v.value.ok && v.value.href ? "" : "cms-link--inert"],
550
+ "data-cms-block": h.value,
551
+ "data-cms-field": m.value,
552
+ "data-cms-link-status": v.value.status,
553
+ onClick: T
554
+ }), {
555
+ default: A(() => [E(e.$slots, "default", { link: v.value }, () => [g(O(w.value), 1)], !0)]),
556
+ _: 3
557
+ }, 16, [
558
+ "class",
559
+ "data-cms-block",
560
+ "data-cms-field",
561
+ "data-cms-link-status"
562
+ ]));
563
+ }
564
+ }), [["__scopeId", "data-v-87a57473"]]), Se = [
565
+ "src",
566
+ "alt",
567
+ "width",
568
+ "height",
569
+ "data-cms-block",
570
+ "data-cms-field"
571
+ ], Ce = /* @__PURE__ */ _({
572
+ __name: "CmsImage",
573
+ props: {
574
+ block: {},
575
+ field: {},
576
+ value: {},
577
+ fallback: {},
578
+ alt: {}
579
+ },
580
+ setup(e, { expose: t }) {
581
+ let n = e, r = y(M, {
582
+ messages: {},
583
+ editing: !1,
584
+ setText: () => {}
585
+ }), i = d(() => n.block?.fields);
586
+ function a(e) {
587
+ return e === void 0 ? [] : typeof e == "string" ? [e] : e;
588
+ }
589
+ let s = d(() => {
590
+ if (!n.block) return;
591
+ let e = i.value;
592
+ return a(n.field).find((t) => e && e[t] !== void 0 && e[t] !== null);
593
+ }), l = d(() => n.block?.id), u = d(() => n.value === void 0 ? c(i.value, a(n.field)) : n.value), f = d(() => {
594
+ let e = o(u.value, r.messages, n.fallback ?? "");
595
+ return n.alt === void 0 ? e : {
596
+ ...e,
597
+ alt: n.alt
598
+ };
599
+ });
600
+ return t({ image: f }), (e, t) => f.value.src ? (S(), m("img", {
601
+ key: 0,
602
+ src: f.value.src,
603
+ alt: f.value.alt,
604
+ width: f.value.width,
605
+ height: f.value.height,
606
+ "data-cms-block": l.value,
607
+ "data-cms-field": s.value
608
+ }, null, 8, Se)) : p("", !0);
450
609
  }
451
- }), [["__scopeId", "data-v-b1bd4d10"]]);
610
+ });
452
611
  //#endregion
453
- export { k as CMS_CONTEXT, b as CORE_LOGIC_INPUTS, F as CmsText, G as CmsZone, x as NODE_SPECS, w as evaluate, C as evaluateGraph, E as isImage, D as isLink, T as isTRef, O as text, S as toCards, A as useField };
612
+ export { P as CMS_CLIENT, M as CMS_CONTEXT, X as CMS_PARTIAL_STATE_KEY, Ce as CmsImage, xe as CmsLink, be as CmsRichText, ue as CmsText, ye as CmsZone, R as createCms, oe as defineBlock, Z as getBlockComponentProps, ae as hydrateCmsPartials, G as isPartialDocument, F as isServerRender, I as readPreviewFromLocation, Y as resetCmsPartials, ie as snapshotCmsPartials, z as useCms, ne as useCmsOrThrow, re as useCmsPage, J as useCmsPartial, N as useField };