@opengis/cms 0.0.59 → 0.0.60

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.
@@ -0,0 +1,188 @@
1
+ import { defineAsyncComponent as k, defineComponent as S, inject as q, ref as m, computed as v, onMounted as D, openBlock as p, createElementBlock as h, createVNode as O, createElementVNode as r, createTextVNode as R, toDisplayString as f, unref as A, Fragment as W, renderList as J, normalizeClass as M, createBlock as Y, resolveDynamicComponent as G, createCommentVNode as H } from "vue";
2
+ import { useRoute as K, useRouter as P } from "vue-router";
3
+ import { useI18n as Q } from "vue-i18n";
4
+ import { notify as $ } from "@opengis/core";
5
+ import { _ as X } from "./CollectionsBreadcrumb.vue_vue_type_script_setup_true_lang-BJh-tjam.js";
6
+ const Z = {
7
+ monaco: k(() => import("./vs-builder-monaco-Cw-f19gc.js")),
8
+ edit: k(() => import("./vs-builder-edit-D-q1o8tF.js")),
9
+ preview: k(() => import("./vs-builder-preview-BH4VAM3a.js"))
10
+ }, ee = { class: "mx-auto max-w-[90%]" }, te = { class: "flex items-center justify-between mb-6" }, oe = { class: "mb-2 text-2xl font-semibold text-gray-900" }, ne = { class: "lowercase" }, se = { class: "text-gray-600" }, ie = { class: "flex items-center gap-2" }, ae = { class: "w-full" }, re = { class: "flex items-center w-full h-10 max-w-md grid-cols-3 p-1 mb-6 bg-white border border-gray-200 rounded-md text-muted-foreground" }, le = ["onClick"], ce = {
11
+ key: 0,
12
+ class: "mx-auto bg-white rounded-md py-4 px-2 bg-opacity-50"
13
+ }, ge = /* @__PURE__ */ S({
14
+ __name: "EditCollectionPage",
15
+ setup(ue) {
16
+ const { t: s } = Q(), j = q("cms.fetchContentTypes"), g = m("edit"), n = m({ yaml: "", data: { columns: [], type: "collection" } }), w = m({}), x = m(""), l = K(), b = P(), I = m(!1), _ = m(!0), C = m(""), F = v(() => [
17
+ // {
18
+ // name: "YAML",
19
+ // id: "monaco",
20
+ // },
21
+ {
22
+ name: s("cms.builder.edit"),
23
+ id: "edit"
24
+ },
25
+ {
26
+ name: s("cms.builder.preview"),
27
+ id: "preview"
28
+ }
29
+ ]), c = v(() => {
30
+ if (typeof l.params.collection == "string" && typeof l.params.contentId == "string")
31
+ return l.params.collection;
32
+ const e = l.params.id;
33
+ return e === "edit" ? l.params.collection : e;
34
+ }), y = v(() => typeof l.params.contentId == "string" ? l.params.contentId : null), L = v(() => {
35
+ if (c.value && y.value)
36
+ return `/collections/${c.value}/${y.value}`;
37
+ const e = l.query.from;
38
+ return typeof e == "string" && e.startsWith("/") ? e : null;
39
+ }), N = v(() => {
40
+ if (C.value)
41
+ return C.value;
42
+ const e = l.query.fromLabel;
43
+ return typeof e == "string" && e.trim() ? e.trim() : null;
44
+ }), B = v(() => {
45
+ var t, i, u, a, d, T;
46
+ const e = x.value || c.value, o = [
47
+ {
48
+ label: ((i = (t = n.value) == null ? void 0 : t.data) == null ? void 0 : i.type) == "single" ? s("cms.navigation.singletons") : e,
49
+ route: `collections/${((a = (u = n.value) == null ? void 0 : u.data) == null ? void 0 : a.type) == "single" ? "pages" : c.value}`
50
+ },
51
+ {
52
+ label: (((T = (d = n.value) == null ? void 0 : d.data) == null ? void 0 : T.type) == "single" ? e + " - " : "") + s("cms.collections.edit")
53
+ }
54
+ ].filter((E) => E);
55
+ return L.value && N.value && o.splice(1, 0, {
56
+ label: N.value,
57
+ route: L.value
58
+ }), o;
59
+ }), U = (e) => {
60
+ if (e) {
61
+ if (e.startsWith("/")) {
62
+ b.push(e);
63
+ return;
64
+ }
65
+ b.push(`/${e}`);
66
+ }
67
+ }, V = async () => {
68
+ var e;
69
+ try {
70
+ if (_.value = !0, !c.value)
71
+ return;
72
+ if (y.value) {
73
+ const u = await fetch(
74
+ `/api/cms/${c.value}/${y.value}`
75
+ );
76
+ if (u.ok) {
77
+ const a = await u.json(), d = Array.isArray(a == null ? void 0 : a.rows) ? a.rows[0] : a;
78
+ d != null && d.title && (C.value = d.title);
79
+ }
80
+ }
81
+ const t = await (await fetch(`/api/cms-type/${c.value}`)).json(), i = {
82
+ ...t,
83
+ columns: Array.isArray(t.columns) ? t.columns : (e = Object.entries((t == null ? void 0 : t.columns) || {})) == null ? void 0 : e.map(([u, a]) => ({
84
+ ...a,
85
+ name: u
86
+ }))
87
+ };
88
+ n.value = {
89
+ ...n.value,
90
+ data: i
91
+ }, x.value = i.title || i.name;
92
+ } catch (o) {
93
+ console.error(o);
94
+ } finally {
95
+ _.value = !1, I.value = !0;
96
+ }
97
+ }, z = async () => {
98
+ var e, o;
99
+ try {
100
+ if (await w.value.validate()) {
101
+ $({
102
+ type: "warning",
103
+ title: s("cms.common.actions.warning"),
104
+ message: s("cms.builder.editFieldFailed")
105
+ });
106
+ return;
107
+ }
108
+ const i = c.value;
109
+ if (!i)
110
+ return;
111
+ const u = await fetch(
112
+ `/api/cms-type/${i}`,
113
+ {
114
+ method: "PUT",
115
+ headers: {
116
+ "Content-Type": "application/json"
117
+ },
118
+ body: JSON.stringify(g.value === "monaco" ? (e = n.value) == null ? void 0 : e.yaml : (o = n.value) == null ? void 0 : o.data)
119
+ }
120
+ );
121
+ b.back(), j && j(), $({
122
+ type: "success",
123
+ title: s("cms.common.actions.success"),
124
+ message: s("cms.collections.collectionCreated")
125
+ });
126
+ } catch (t) {
127
+ console.error(t), $({
128
+ type: "error",
129
+ title: s("cms.common.actions.error"),
130
+ message: s("cms.collections.collectionCreationFailed")
131
+ });
132
+ }
133
+ };
134
+ return D(() => {
135
+ V();
136
+ }), (e, o) => (p(), h("div", ee, [
137
+ O(X, {
138
+ items: B.value,
139
+ loading: _.value,
140
+ onNavigate: U
141
+ }, null, 8, ["items", "loading"]),
142
+ r("div", te, [
143
+ r("div", null, [
144
+ r("h1", oe, [
145
+ R(f(e.$t("cms.builder.editCollection")) + ": ", 1),
146
+ r("span", ne, ' "' + f(x.value) + '" ', 1)
147
+ ]),
148
+ r("p", se, f(e.$t("cms.builder.editContentForYourSite")), 1)
149
+ ]),
150
+ r("div", ie, [
151
+ r("a", {
152
+ onClick: o[0] || (o[0] = (t) => A(b).back()),
153
+ class: "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 border bg-background hover:text-accent-foreground h-10 px-4 py-2 border-gray-300 text-gray-700 hover:bg-gray-50"
154
+ }, f(e.$t("cms.common.actions.back")), 1),
155
+ r("button", {
156
+ onClick: z,
157
+ class: "inline-flex items-center justify-center gap-2 whitespace-nowrap text-white rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 text-primary-foreground h-10 px-4 py-2 bg-blue-600 hover:bg-blue-700"
158
+ }, f(e.$t("cms.common.actions.save")), 1)
159
+ ])
160
+ ]),
161
+ r("div", ae, [
162
+ r("div", re, [
163
+ (p(!0), h(W, null, J(F.value, (t) => (p(), h("button", {
164
+ key: t.id,
165
+ onClick: (i) => g.value = t.id,
166
+ class: M([
167
+ "inline-flex flex-1 items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm data-[state=active]:bg-blue-50 data-[state=active]:text-blue-700 data-[state=active]:border-blue-200",
168
+ t.id === g.value ? "bg-blue-50 text-blue-700 border-blue-200" : ""
169
+ ])
170
+ }, f(t.name), 11, le))), 128))
171
+ ])
172
+ ]),
173
+ I.value ? (p(), h("div", ce, [
174
+ (p(), Y(G(A(Z)[g.value]), {
175
+ yaml: n.value.yaml,
176
+ "onUpdate:yaml": o[1] || (o[1] = (t) => n.value.yaml = t),
177
+ data: n.value.data,
178
+ "onUpdate:data": o[2] || (o[2] = (t) => n.value.data = t),
179
+ form: w.value,
180
+ "onUpdate:form": o[3] || (o[3] = (t) => w.value = t)
181
+ }, null, 40, ["yaml", "data", "form"]))
182
+ ])) : H("", !0)
183
+ ]));
184
+ }
185
+ });
186
+ export {
187
+ ge as default
188
+ };
@@ -4,7 +4,7 @@ import { ArrowLeft as Je, HelpCircle as He, Settings as Ke, Save as qe, Loader2
4
4
  import { useI18n as Qe } from "vue-i18n";
5
5
  import { g as We } from "./getField-CpwVE28P.js";
6
6
  import { inputs as x, VForm as ue } from "@opengis/form";
7
- import { notify as F } from "@opengis/core";
7
+ import { notify as P } from "@opengis/core";
8
8
  const Xe = [
9
9
  {
10
10
  key: "title",
@@ -69,13 +69,13 @@ const Xe = [
69
69
  () => import("./CollectionsBreadcrumb-HePNJb-d.js")
70
70
  );
71
71
  x["vs-input-custom-datatable"] = fe, x["vs-input-reference"] = de, x["vs-input-texteditor"] = me, x["vs-input-mediaselect"] = E, x["vs-input-file"] = E, x["vs-input-image"] = E, x["vs-input-richtext-md"] = pe, x["vs-input-integer"] = ve, x["vs-input-relation-link"] = ye;
72
- const { t: c, locale: G } = Qe(), V = Ue(), d = Oe(), Q = le("cms.menu", null) || le("menu", p([])), _ = p([]), D = p({}), W = p({}), I = p({}), N = p(""), M = p(!0), R = Be(), U = R == null ? void 0 : R.appContext, we = (U == null ? void 0 : U.config.globalProperties) || {}, X = Ee(we, "$settings"), P = m(() => {
72
+ const { t: r, locale: G } = Qe(), V = Ue(), d = Oe(), Q = le("cms.menu", null) || le("menu", p([])), _ = p([]), D = p({}), W = p({}), I = p({}), N = p(""), M = p(!0), R = Be(), U = R == null ? void 0 : R.appContext, we = (U == null ? void 0 : U.config.globalProperties) || {}, X = Ee(we, "$settings"), B = m(() => {
73
73
  var e;
74
74
  return ((e = X.value) == null ? void 0 : e.cms) || {};
75
- }), ke = m(() => Array.isArray(P.value.locales) ? P.value.locales : []), O = m(
75
+ }), ke = m(() => Array.isArray(B.value.locales) ? B.value.locales : []), O = m(
76
76
  () => ke.value.filter(Boolean)
77
77
  ), Y = m(
78
- () => P.value.locale || O.value[0] || "uk"
78
+ () => B.value.locale || O.value[0] || "uk"
79
79
  );
80
80
  De(
81
81
  X,
@@ -114,14 +114,14 @@ const Xe = [
114
114
  return Xe.flatMap((t) => {
115
115
  const o = {
116
116
  ...t,
117
- label: c(t.label)
117
+ label: r(t.label)
118
118
  };
119
119
  if (!t.localization || e.length === 0)
120
120
  return [o];
121
121
  const a = e.map((n) => ({
122
122
  ...t,
123
123
  key: `${t.key}:${n}`,
124
- label: `${c(t.label)} (${n})`,
124
+ label: `${r(t.label)} (${n})`,
125
125
  localization: !1
126
126
  }));
127
127
  return [o, ...a];
@@ -129,21 +129,21 @@ const Xe = [
129
129
  }), g = p({}), i = p({
130
130
  title: "",
131
131
  status: "draft"
132
- }), J = p(null), L = p(""), B = m(
132
+ }), J = p(null), L = p(""), F = m(
133
133
  () => {
134
134
  var e;
135
135
  return (((e = i.value) == null ? void 0 : e.type) || J.value) === "single";
136
136
  }
137
137
  ), Te = m(() => {
138
138
  const e = [
139
- { id: "content", name: c("cms.builder.content") },
140
- { id: "seo", name: c("cms.builder.seo") },
141
- { id: "tags", name: c("cms.builder.tags") }
139
+ { id: "content", name: r("cms.builder.content") },
140
+ { id: "seo", name: r("cms.builder.seo") },
141
+ { id: "tags", name: r("cms.builder.tags") }
142
142
  ];
143
- return N.value && e.push({ id: "preview", name: c("cms.builder.preview") }), e;
143
+ return N.value && e.push({ id: "preview", name: r("cms.builder.preview") }), e;
144
144
  }), A = p("content"), ee = m(() => {
145
- var s, r, l, k, f, b, y, T, oe;
146
- const e = ((s = d.params) == null ? void 0 : s.collection) || ((r = d.params) == null ? void 0 : r.id), t = (l = i.value) == null ? void 0 : l.content_type_id, o = t ? (f = (k = Q.value) == null ? void 0 : k.find((K) => K.id === t)) == null ? void 0 : f.title : null;
145
+ var s, c, l, k, f, b, y, T, oe;
146
+ const e = ((s = d.params) == null ? void 0 : s.collection) || ((c = d.params) == null ? void 0 : c.id), t = (l = i.value) == null ? void 0 : l.content_type_id, o = t ? (f = (k = Q.value) == null ? void 0 : k.find((K) => K.id === t)) == null ? void 0 : f.title : null;
147
147
  if (o)
148
148
  return o;
149
149
  if (L.value)
@@ -154,24 +154,24 @@ const Xe = [
154
154
  if (a)
155
155
  return a;
156
156
  const n = (T = d.params) == null ? void 0 : T.id;
157
- return B.value && n && e === n && ((oe = i.value) != null && oe.title) ? i.value.title : e === "pages" ? c("cms.articles.title") : e;
157
+ return F.value && n && e === n && ((oe = i.value) != null && oe.title) ? i.value.title : e === "pages" ? r("cms.articles.title") : e;
158
158
  }), Se = m(() => {
159
159
  var t, o;
160
- const e = B.value ? "cms.builder.editPage" : "cms.builder.editCollection";
161
- return ((t = i.value) == null ? void 0 : t.title) || ((o = d.params) != null && o.id ? c(e) : c("cms.articles.createArticle"));
160
+ const e = F.value ? "cms.builder.editPage" : "cms.builder.editCollection";
161
+ return ((t = i.value) == null ? void 0 : t.title) || ((o = d.params) != null && o.id ? r(e) : r("cms.articles.createArticle"));
162
162
  }), Ve = m(() => {
163
- var s, r, l;
164
- const e = ((s = d.params) == null ? void 0 : s.collection) || ((r = d.params) == null ? void 0 : r.id), t = (l = d.params) == null ? void 0 : l.id, o = Se.value, a = o === ee.value, n = [
163
+ var s, c, l;
164
+ const e = ((s = d.params) == null ? void 0 : s.collection) || ((c = d.params) == null ? void 0 : c.id), t = (l = d.params) == null ? void 0 : l.id, o = Se.value, a = o === ee.value, n = [
165
165
  {
166
- label: ee.value,
166
+ label: F ? r("cms.navigation.singletons") : ee.value,
167
167
  route: `collections/${e}`
168
168
  }
169
169
  ];
170
170
  return t ? n.push({
171
- label: a ? c("cms.collections.edit") : o,
171
+ label: a ? r("cms.collections.edit") : o,
172
172
  route: `collections/${e}/${t}`
173
173
  }) : n.push({
174
- label: c("cms.articles.createArticle"),
174
+ label: r("cms.articles.createArticle"),
175
175
  route: `collections/${e}/create`
176
176
  }), n;
177
177
  }), Ae = (e) => {
@@ -186,9 +186,9 @@ const Xe = [
186
186
  throw new Error("Failed to fetch article");
187
187
  const s = await n.json();
188
188
  if (_.value = (s == null ? void 0 : s.columns) || [], s != null && s.preview_path && (N.value = s == null ? void 0 : s.preview_path), J.value = (s == null ? void 0 : s.type) || null, s.rows) {
189
- let r = s.rows;
190
- Array.isArray(r) || (r = [r]), i.value = r[0];
191
- const l = ((o = r[0]) == null ? void 0 : o.content_type_id) || e;
189
+ let c = s.rows;
190
+ Array.isArray(c) || (c = [c]), i.value = c[0];
191
+ const l = ((o = c[0]) == null ? void 0 : o.content_type_id) || e;
192
192
  if (l) {
193
193
  const k = await fetch(`/api/cms-type/${l}`);
194
194
  if (k.ok) {
@@ -196,7 +196,7 @@ const Xe = [
196
196
  L.value = (f == null ? void 0 : f.title) || (f == null ? void 0 : f.name) || L.value;
197
197
  }
198
198
  }
199
- await ce(), (a = r[0]) != null && a.meta ? g.value = { ...r[0].meta } : g.value = {
199
+ await ce(), (a = c[0]) != null && a.meta ? g.value = { ...c[0].meta } : g.value = {
200
200
  title: "",
201
201
  description: "",
202
202
  keywords: "",
@@ -249,12 +249,12 @@ const Xe = [
249
249
  const e = (t = i.value) == null ? void 0 : t.content_type_id;
250
250
  return e ? `/collections/${e}/edit` : null;
251
251
  }), ze = () => {
252
- var o, a, n;
252
+ var o, a, n, s;
253
253
  if (!H.value)
254
254
  return;
255
255
  const e = ((o = d.params) == null ? void 0 : o.collection) || ((a = d.params) == null ? void 0 : a.id), t = (n = d.params) == null ? void 0 : n.id;
256
256
  if (e && t) {
257
- V.push(`/collections/${e}/${t}/edit`);
257
+ V.push(`/collections/${(s = i.value) == null ? void 0 : s.content_type_id}/edit`);
258
258
  return;
259
259
  }
260
260
  V.push(H.value);
@@ -265,24 +265,24 @@ const Xe = [
265
265
  try {
266
266
  (await fetch(
267
267
  `/api/cms-translate?id=${t}&collection=${e}&to=en&nocache=1`
268
- )).ok ? (F({
269
- title: c("cms.collections.translateContentSuccess"),
270
- message: c("cms.collections.translateContentSuccess"),
268
+ )).ok ? (P({
269
+ title: r("cms.collections.translateContentSuccess"),
270
+ message: r("cms.collections.translateContentSuccess"),
271
271
  type: "success"
272
- }), await te(e, t)) : F({
273
- title: c("cms.collections.translateContentError"),
274
- message: c("cms.collections.translateContentError"),
272
+ }), await te(e, t)) : P({
273
+ title: r("cms.collections.translateContentError"),
274
+ message: r("cms.collections.translateContentError"),
275
275
  type: "error"
276
276
  });
277
277
  } finally {
278
278
  z.value = !1;
279
279
  }
280
280
  }, Fe = async (e) => {
281
- var r, l, k, f;
282
- const t = (r = d.params) == null ? void 0 : r.collection, o = (l = d.params) == null ? void 0 : l.id, a = await D.value.validate();
281
+ var c, l, k, f;
282
+ const t = (c = d.params) == null ? void 0 : c.collection, o = (l = d.params) == null ? void 0 : l.id, a = await D.value.validate();
283
283
  if (a) {
284
- F({
285
- title: c("cms.validation"),
284
+ P({
285
+ title: r("cms.validation"),
286
286
  message: JSON.stringify(a),
287
287
  type: "warning"
288
288
  });
@@ -322,21 +322,21 @@ const Xe = [
322
322
  } catch (y) {
323
323
  console.warn("Could not parse response to get ID:", y);
324
324
  }
325
- F({
326
- title: c("cms.common.success"),
327
- message: c("cms.common.successMessage"),
325
+ P({
326
+ title: r("cms.common.success"),
327
+ message: r("cms.common.successMessage"),
328
328
  type: "success"
329
329
  });
330
330
  } catch (b) {
331
- console.error("Submit error:", b), F({
332
- title: c("cms.common.error"),
331
+ console.error("Submit error:", b), P({
332
+ title: r("cms.common.error"),
333
333
  message: "Помилка збереження",
334
334
  type: "error"
335
335
  });
336
336
  }
337
337
  };
338
338
  return (e, t) => {
339
- var o, a, n, s, r;
339
+ var o, a, n, s, c;
340
340
  return w(), $("div", Ye, [
341
341
  u("div", Ze, [
342
342
  C(v(he), {
@@ -353,7 +353,7 @@ const Xe = [
353
353
  C(v(Je), { class: "w-5 h-5" })
354
354
  ]),
355
355
  u("h1", st, j(e.$t(
356
- B.value ? "cms.builder.editPage" : "cms.builder.editCollection"
356
+ F.value ? "cms.builder.editPage" : "cms.builder.editCollection"
357
357
  )) + ' "' + j(i.value.title) + '" ', 1),
358
358
  u("a", {
359
359
  href: `https://cms.opengis.info/${v(G)}/guides/content/`,
@@ -364,7 +364,7 @@ const Xe = [
364
364
  ], 8, ot)
365
365
  ]),
366
366
  u("div", lt, [
367
- H.value && B.value ? (w(), $("button", {
367
+ H.value && F.value ? (w(), $("button", {
368
368
  key: 0,
369
369
  onClick: ze,
370
370
  type: "button",
@@ -389,7 +389,7 @@ const Xe = [
389
389
  (w(!0), $(Ne, null, Me(Te.value, (l) => (w(), $("button", {
390
390
  key: l.id,
391
391
  onClick: (k) => {
392
- A.value = l.id, console.log("cmsSettings:", P.value.value);
392
+ A.value = l.id, console.log("cmsSettings:", B.value.value);
393
393
  },
394
394
  class: ne([
395
395
  "inline-flex flex-1 items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm data-[state=active]:bg-blue-50 data-[state=active]:text-blue-700 data-[state=active]:border-blue-200",
@@ -476,7 +476,7 @@ const Xe = [
476
476
  ])) : S("", !0),
477
477
  A.value === "preview" ? (w(), $("div", bt, [
478
478
  C(v(be), {
479
- slug: (r = i.value) == null ? void 0 : r.slug,
479
+ slug: (c = i.value) == null ? void 0 : c.slug,
480
480
  preview_path: N.value
481
481
  }, null, 8, ["slug", "preview_path"])
482
482
  ])) : S("", !0)
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { useRoute as $, routeLocationKey as K } from "vue-router";
3
3
  const O = "menu", B = (s, c, a) => {
4
4
  const o = s == null ? void 0 : s.trim(), l = a == null ? void 0 : a.trim();
5
5
  return o ? o === O ? c ? c === "create" ? { type: "createMenu", collection: o } : { type: "editMenu", collection: o, id: c } : { type: "menu", collection: o } : l === "edit" && c ? { type: "editCollection", collection: o, id: c } : c === "edit" ? { type: "editCollection", collection: o } : c ? c === "create" ? { type: "createArticle", collection: o } : { type: "editArticle", collection: o, id: c } : { type: "articles", collection: o } : { type: "collections" };
6
- }, R = u(() => import("./CollectionsPage-DHfPNql6.js")), L = u(() => import("./ArticlesPage-BjYzvTWM.js")), C = u(() => import("./contentForm-Buku-lel.js")), N = u(() => import("./EditCollectionPage-CqYHpEON.js")), W = u(
6
+ }, R = u(() => import("./CollectionsPage-DHfPNql6.js")), L = u(() => import("./ArticlesPage-BjYzvTWM.js")), C = u(() => import("./contentForm-yMn63kza.js")), N = u(() => import("./EditCollectionPage-BycuD920.js")), W = u(
7
7
  () => import("./MenuPage-3W6jZ15H.js")
8
8
  ), j = u(
9
9
  () => import("./MenuItemPage-B7Y9KFyb.js")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/cms",
3
- "version": "0.0.59",
3
+ "version": "0.0.60",
4
4
  "description": "cms",
5
5
  "type": "module",
6
6
  "author": "Softpro",
@@ -41,7 +41,7 @@ export default async function insertContentLocalization({ send = () => { }, tabl
41
41
  const obj = { ...row, ...localization };
42
42
 
43
43
  const entries = Object.entries(obj).filter(([key, value]) => value && schemaKeys.includes(key) && (typeof value === 'string' || (Array.isArray(value) && value?.[0] && typeof value?.[0] === 'object' && Object.keys(value).length)));
44
- // do not old localization overwrite by default
44
+ // do not overwrite old localization by default
45
45
  const filteredEntries = skip && targetLocalization ? entries.filter(([key]) => !Object.keys(targetLocalization).includes(key)) : entries;
46
46
 
47
47
  if (skip && targetLocalization && !filteredEntries.length) {
@@ -5,17 +5,26 @@ const { host = 'https://translate.softpro.ua', key = '' } = config.integrations?
5
5
  const divider = ' <divider> ';
6
6
 
7
7
  // Wrap dot notation keys in quotes
8
- export const arrayToPhrases = (arr, prefix = 'item') => {
8
+ export const arrayToPhrases = (arr, prefix = 'item', mainIdx = null) => {
9
9
  if (!arr || !arr.length) return [];
10
- return arr.flatMap((obj, idx) =>
11
- Object.entries(obj).map(([key, value]) => ({
12
- prefix,
13
- value,
14
- // phrase: `"${prefix}"."${key}".${idx}: ${value}`,
15
- key,
16
- idx
17
- }))
18
- );
10
+
11
+ return arr.flatMap((obj, idx) => {
12
+ const currentMainIdx = mainIdx ?? idx;
13
+
14
+ return Object.entries(obj).flatMap(([key, value]) => {
15
+ if (Array.isArray(value)) {
16
+ return arrayToPhrases(value, `${prefix}.${key}`, currentMainIdx);
17
+ }
18
+
19
+ return [{
20
+ prefix,
21
+ value,
22
+ key,
23
+ mainIdx: currentMainIdx,
24
+ idx,
25
+ }];
26
+ });
27
+ });
19
28
  };
20
29
 
21
30
  export default async function requestTranslation(entries, from = 'uk', to) {
@@ -26,13 +35,13 @@ export default async function requestTranslation(entries, from = 'uk', to) {
26
35
 
27
36
  // Translate each phrase independently
28
37
  const translatedPhrases = await Promise.all(
29
- phrasesWithMeta.map(async ({ key, idx, prefix, value }) => {
38
+ phrasesWithMeta.map(async ({ key, idx, prefix, value, mainIdx }) => {
30
39
  if (!value || typeof value === 'number' || value?.startsWith?.('/files/')) {
31
- return { key, idx, prefix, value, skip: true }; // fallback to original
40
+ return { key, idx, mainIdx, prefix, value, skip: true }; // fallback to original
32
41
  }
33
42
 
34
43
  try {
35
- const parts = value.startsWith('<') && value.endsWith('>')
44
+ const parts = typeof value === 'string' && value.startsWith('<') && value.endsWith('>')
36
45
  ? [...value.matchAll(/(<[^>]+>)([^<]*)(<\/[^>]+>)/g)].map(([, openTag, str, closeTag]) => ({ openTag, str, closeTag }))
37
46
  : [{ str: value }];
38
47
 
@@ -58,19 +67,38 @@ export default async function requestTranslation(entries, from = 'uk', to) {
58
67
 
59
68
  const body = await resp.json();
60
69
  const resultValue = body.translatedText ? parts.map(({ openTag, str, closeTag }, i) => `${openTag || ''}${body.translatedText.split(divider)[i] || str || ''}${closeTag || ''}`).join(' ') : null;
61
- return { key, idx, prefix, value: resultValue || value };
70
+ return { key, idx, mainIdx, prefix, value: resultValue || value };
62
71
  } catch (err) {
63
72
  console.warn('translation request failed', err.toString());
64
- return { key, idx, prefix, value, error: err.toString() }; // fallback
73
+ return { key, idx, mainIdx, prefix, value, error: err.toString() }; // fallback
65
74
  }
66
75
  })
67
76
  );
68
77
 
69
- const result = translatedPhrases.reduce((acc, { key, idx, prefix, value }) => {
70
- if (!acc[`${prefix}:${to}`]) acc[`${prefix}:${to}`] = Array.isArray(entries.find(e => e[0] === prefix)[1]) ? [] : null;
78
+ const result = translatedPhrases.reduce((acc, curr) => {
79
+ const { key, idx, prefix: prefix1, value, mainIdx } = curr;
80
+ const [prefix, subkey] = prefix1.split('.');
71
81
 
72
- if (Array.isArray(entries.find(e => e[0] === prefix)[1])) {
73
- if (!acc[`${prefix}:${to}`][idx]) acc[`${prefix}:${to}`][idx] = {};
82
+ if (!acc[`${prefix}:${to}`]) {
83
+ acc[`${prefix}:${to}`] = Array.isArray(entries.find(e => e[0] === prefix)[1]) ? [] : null;
84
+ }
85
+
86
+ if (subkey && Array.isArray(entries.find(e => e[0] === prefix)[1])) {
87
+ if (!acc[`${prefix}:${to}`][mainIdx]) {
88
+ acc[`${prefix}:${to}`][mainIdx] = {};
89
+ }
90
+ if (!acc[`${prefix}:${to}`][mainIdx][subkey]) {
91
+ acc[`${prefix}:${to}`][mainIdx][subkey] = [];
92
+ }
93
+ if (!acc[`${prefix}:${to}`][mainIdx][subkey]?.[idx]) {
94
+ acc[`${prefix}:${to}`][mainIdx][subkey][idx] = {};
95
+ }
96
+ acc[`${prefix}:${to}`][mainIdx][subkey][idx][key] = value;
97
+ // console.log(prefix, to, idx, subkey, mainIdx, key);
98
+ } else if (Array.isArray(entries.find(e => e[0] === prefix)[1])) {
99
+ if (!acc[`${prefix}:${to}`][idx]) {
100
+ acc[`${prefix}:${to}`][idx] = {};
101
+ }
74
102
  acc[`${prefix}:${to}`][idx][key] = value;
75
103
  } else {
76
104
  acc[`${prefix}:${to}`] = value;
@@ -1,187 +0,0 @@
1
- import { defineAsyncComponent as k, defineComponent as z, inject as E, ref as u, computed as m, onMounted as S, openBlock as v, createElementBlock as h, createVNode as q, createElementVNode as n, createTextVNode as D, toDisplayString as d, unref as T, Fragment as O, renderList as R, normalizeClass as W, createBlock as J, resolveDynamicComponent as M, createCommentVNode as Y } from "vue";
2
- import { useRoute as G, useRouter as H } from "vue-router";
3
- import { useI18n as K } from "vue-i18n";
4
- import { notify as $ } from "@opengis/core";
5
- import { _ as P } from "./CollectionsBreadcrumb.vue_vue_type_script_setup_true_lang-BJh-tjam.js";
6
- const Q = {
7
- monaco: k(() => import("./vs-builder-monaco-Cw-f19gc.js")),
8
- edit: k(() => import("./vs-builder-edit-D-q1o8tF.js")),
9
- preview: k(() => import("./vs-builder-preview-BH4VAM3a.js"))
10
- }, X = { class: "mx-auto max-w-[90%]" }, Z = { class: "flex items-center justify-between mb-6" }, ee = { class: "mb-2 text-2xl font-semibold text-gray-900" }, te = { class: "lowercase" }, oe = { class: "text-gray-600" }, ne = { class: "flex items-center gap-2" }, se = { class: "w-full" }, ie = { class: "flex items-center w-full h-10 max-w-md grid-cols-3 p-1 mb-6 bg-white border border-gray-200 rounded-md text-muted-foreground" }, re = ["onClick"], ae = {
11
- key: 0,
12
- class: "mx-auto bg-white rounded-md py-4 px-2 bg-opacity-50"
13
- }, ve = /* @__PURE__ */ z({
14
- __name: "EditCollectionPage",
15
- setup(le) {
16
- const { t: s } = K(), j = E("cms.fetchContentTypes"), p = u("edit"), r = u({ yaml: "", data: { columns: [], type: "collection" } }), w = u({}), x = u(""), i = G(), b = H(), I = u(!1), _ = u(!0), C = u(""), A = m(() => [
17
- // {
18
- // name: "YAML",
19
- // id: "monaco",
20
- // },
21
- {
22
- name: s("cms.builder.edit"),
23
- id: "edit"
24
- },
25
- {
26
- name: s("cms.builder.preview"),
27
- id: "preview"
28
- }
29
- ]), a = m(() => {
30
- if (typeof i.params.collection == "string" && typeof i.params.contentId == "string")
31
- return i.params.collection;
32
- const e = i.params.id;
33
- return e === "edit" ? i.params.collection : e;
34
- }), g = m(() => typeof i.params.contentId == "string" ? i.params.contentId : null), L = m(() => {
35
- if (a.value && g.value)
36
- return `/collections/${a.value}/${g.value}`;
37
- const e = i.query.from;
38
- return typeof e == "string" && e.startsWith("/") ? e : null;
39
- }), N = m(() => {
40
- if (C.value)
41
- return C.value;
42
- const e = i.query.fromLabel;
43
- return typeof e == "string" && e.trim() ? e.trim() : null;
44
- }), F = m(() => {
45
- const o = [
46
- {
47
- label: x.value || a.value,
48
- route: `collections/${a.value}`
49
- },
50
- {
51
- label: s("cms.collections.edit")
52
- }
53
- ];
54
- return L.value && N.value && o.splice(1, 0, {
55
- label: N.value,
56
- route: L.value
57
- }), o;
58
- }), B = (e) => {
59
- if (e) {
60
- if (e.startsWith("/")) {
61
- b.push(e);
62
- return;
63
- }
64
- b.push(`/${e}`);
65
- }
66
- }, U = async () => {
67
- var e;
68
- try {
69
- if (_.value = !0, !a.value)
70
- return;
71
- if (g.value) {
72
- const f = await fetch(
73
- `/api/cms/${a.value}/${g.value}`
74
- );
75
- if (f.ok) {
76
- const c = await f.json(), y = Array.isArray(c == null ? void 0 : c.rows) ? c.rows[0] : c;
77
- y != null && y.title && (C.value = y.title);
78
- }
79
- }
80
- const t = await (await fetch(`/api/cms-type/${a.value}`)).json(), l = {
81
- ...t,
82
- columns: Array.isArray(t.columns) ? t.columns : (e = Object.entries((t == null ? void 0 : t.columns) || {})) == null ? void 0 : e.map(([f, c]) => ({
83
- ...c,
84
- name: f
85
- }))
86
- };
87
- r.value = {
88
- ...r.value,
89
- data: l
90
- }, x.value = l.title || l.name;
91
- } catch (o) {
92
- console.error(o);
93
- } finally {
94
- _.value = !1, I.value = !0;
95
- }
96
- }, V = async () => {
97
- var e, o;
98
- try {
99
- if (await w.value.validate()) {
100
- $({
101
- type: "warning",
102
- title: s("cms.common.actions.warning"),
103
- message: s("cms.builder.editFieldFailed")
104
- });
105
- return;
106
- }
107
- const l = a.value;
108
- if (!l)
109
- return;
110
- const f = await fetch(
111
- `/api/cms-type/${l}`,
112
- {
113
- method: "PUT",
114
- headers: {
115
- "Content-Type": "application/json"
116
- },
117
- body: JSON.stringify(p.value === "monaco" ? (e = r.value) == null ? void 0 : e.yaml : (o = r.value) == null ? void 0 : o.data)
118
- }
119
- );
120
- b.back(), j && j(), $({
121
- type: "success",
122
- title: s("cms.common.actions.success"),
123
- message: s("cms.collections.collectionCreated")
124
- });
125
- } catch (t) {
126
- console.error(t), $({
127
- type: "error",
128
- title: s("cms.common.actions.error"),
129
- message: s("cms.collections.collectionCreationFailed")
130
- });
131
- }
132
- };
133
- return S(() => {
134
- U();
135
- }), (e, o) => (v(), h("div", X, [
136
- q(P, {
137
- items: F.value,
138
- loading: _.value,
139
- onNavigate: B
140
- }, null, 8, ["items", "loading"]),
141
- n("div", Z, [
142
- n("div", null, [
143
- n("h1", ee, [
144
- D(d(e.$t("cms.builder.editCollection")) + ": ", 1),
145
- n("span", te, ' "' + d(x.value) + '" ', 1)
146
- ]),
147
- n("p", oe, d(e.$t("cms.builder.editContentForYourSite")), 1)
148
- ]),
149
- n("div", ne, [
150
- n("a", {
151
- onClick: o[0] || (o[0] = (t) => T(b).back()),
152
- class: "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 border bg-background hover:text-accent-foreground h-10 px-4 py-2 border-gray-300 text-gray-700 hover:bg-gray-50"
153
- }, d(e.$t("cms.common.actions.back")), 1),
154
- n("button", {
155
- onClick: V,
156
- class: "inline-flex items-center justify-center gap-2 whitespace-nowrap text-white rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 text-primary-foreground h-10 px-4 py-2 bg-blue-600 hover:bg-blue-700"
157
- }, d(e.$t("cms.common.actions.save")), 1)
158
- ])
159
- ]),
160
- n("div", se, [
161
- n("div", ie, [
162
- (v(!0), h(O, null, R(A.value, (t) => (v(), h("button", {
163
- key: t.id,
164
- onClick: (l) => p.value = t.id,
165
- class: W([
166
- "inline-flex flex-1 items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm data-[state=active]:bg-blue-50 data-[state=active]:text-blue-700 data-[state=active]:border-blue-200",
167
- t.id === p.value ? "bg-blue-50 text-blue-700 border-blue-200" : ""
168
- ])
169
- }, d(t.name), 11, re))), 128))
170
- ])
171
- ]),
172
- I.value ? (v(), h("div", ae, [
173
- (v(), J(M(T(Q)[p.value]), {
174
- yaml: r.value.yaml,
175
- "onUpdate:yaml": o[1] || (o[1] = (t) => r.value.yaml = t),
176
- data: r.value.data,
177
- "onUpdate:data": o[2] || (o[2] = (t) => r.value.data = t),
178
- form: w.value,
179
- "onUpdate:form": o[3] || (o[3] = (t) => w.value = t)
180
- }, null, 40, ["yaml", "data", "form"]))
181
- ])) : Y("", !0)
182
- ]));
183
- }
184
- });
185
- export {
186
- ve as default
187
- };
Binary file
package/dist/index.html DELETED
@@ -1,29 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>CMS</title>
7
- <link rel="icon" type="image/png" href="/images/logo.png" />
8
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
9
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">
10
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css">
11
- <link rel="stylesheet" href="/css/style.css">
12
- </head>
13
- <body>
14
- <div id="app">
15
- <div class="container">
16
- <div class="row">
17
- <div class="col-md-12">
18
- <h1 class="text-center">CMS</h1>
19
- </div>
20
- </div>
21
- </div>
22
- </div>
23
- <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
24
- <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
25
- <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
26
- <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
27
- <script src="/js/app.js"></script>
28
- </body>
29
- </html>
package/dist/vite.svg DELETED
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>