@xleddyl/nuxt-cms 0.1.61 → 0.2.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.
Files changed (115) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/module.mjs +117 -9
  3. package/dist/runtime/app/components/cms/BlocksField.vue +86 -10
  4. package/dist/runtime/app/components/cms/BrandMark.d.vue.ts +6 -0
  5. package/dist/runtime/app/components/cms/BrandMark.vue +19 -0
  6. package/dist/runtime/app/components/cms/BrandMark.vue.d.ts +6 -0
  7. package/dist/runtime/app/components/cms/Checkbox.d.vue.ts +11 -0
  8. package/dist/runtime/app/components/cms/Checkbox.vue +21 -0
  9. package/dist/runtime/app/components/cms/Checkbox.vue.d.ts +11 -0
  10. package/dist/runtime/app/components/cms/EmptyState.vue +4 -2
  11. package/dist/runtime/app/components/cms/EntryDrawer.vue +1 -0
  12. package/dist/runtime/app/components/cms/EntryForm.d.vue.ts +1 -0
  13. package/dist/runtime/app/components/cms/EntryForm.vue +105 -30
  14. package/dist/runtime/app/components/cms/EntryForm.vue.d.ts +1 -0
  15. package/dist/runtime/app/components/cms/FieldInput.vue +20 -5
  16. package/dist/runtime/app/components/cms/FormField.d.vue.ts +5 -3
  17. package/dist/runtime/app/components/cms/FormField.vue +8 -2
  18. package/dist/runtime/app/components/cms/FormField.vue.d.ts +5 -3
  19. package/dist/runtime/app/components/cms/Icon.vue +1 -1
  20. package/dist/runtime/app/components/cms/MediaGallery.vue +24 -10
  21. package/dist/runtime/app/components/cms/MediaUpload.d.vue.ts +1 -0
  22. package/dist/runtime/app/components/cms/MediaUpload.vue +71 -41
  23. package/dist/runtime/app/components/cms/MediaUpload.vue.d.ts +1 -0
  24. package/dist/runtime/app/components/cms/PageHeader.d.vue.ts +5 -3
  25. package/dist/runtime/app/components/cms/PageHeader.vue +16 -6
  26. package/dist/runtime/app/components/cms/PageHeader.vue.d.ts +5 -3
  27. package/dist/runtime/app/components/cms/PasswordInput.d.vue.ts +17 -0
  28. package/dist/runtime/app/components/cms/PasswordInput.vue +77 -0
  29. package/dist/runtime/app/components/cms/PasswordInput.vue.d.ts +17 -0
  30. package/dist/runtime/app/components/cms/SelectMenu.vue +3 -5
  31. package/dist/runtime/app/components/cms/SettingsAccount.d.vue.ts +3 -0
  32. package/dist/runtime/app/components/cms/SettingsAccount.vue +138 -0
  33. package/dist/runtime/app/components/cms/SettingsAccount.vue.d.ts +3 -0
  34. package/dist/runtime/app/components/cms/SettingsColumns.d.vue.ts +16 -0
  35. package/dist/runtime/app/components/cms/SettingsColumns.vue +102 -0
  36. package/dist/runtime/app/components/cms/SettingsColumns.vue.d.ts +16 -0
  37. package/dist/runtime/app/components/cms/SettingsEntry.d.vue.ts +6 -0
  38. package/dist/runtime/app/components/cms/SettingsEntry.vue +133 -0
  39. package/dist/runtime/app/components/cms/SettingsEntry.vue.d.ts +6 -0
  40. package/dist/runtime/app/components/cms/SettingsLayout.d.vue.ts +16 -0
  41. package/dist/runtime/app/components/cms/SettingsLayout.vue +177 -0
  42. package/dist/runtime/app/components/cms/SettingsLayout.vue.d.ts +16 -0
  43. package/dist/runtime/app/components/cms/SettingsModal.d.vue.ts +16 -0
  44. package/dist/runtime/app/components/cms/SettingsModal.vue +179 -0
  45. package/dist/runtime/app/components/cms/SettingsModal.vue.d.ts +16 -0
  46. package/dist/runtime/app/components/cms/SettingsUsers.d.vue.ts +3 -0
  47. package/dist/runtime/app/components/cms/SettingsUsers.vue +270 -0
  48. package/dist/runtime/app/components/cms/SettingsUsers.vue.d.ts +3 -0
  49. package/dist/runtime/app/components/cms/Spinner.vue +2 -2
  50. package/dist/runtime/app/components/cms/Table.d.vue.ts +7 -2
  51. package/dist/runtime/app/components/cms/Table.vue +38 -1
  52. package/dist/runtime/app/components/cms/Table.vue.d.ts +7 -2
  53. package/dist/runtime/app/components/cms/Toaster.vue +1 -1
  54. package/dist/runtime/app/components/cms/WelcomeModal.d.vue.ts +3 -0
  55. package/dist/runtime/app/components/cms/WelcomeModal.vue +69 -0
  56. package/dist/runtime/app/components/cms/WelcomeModal.vue.d.ts +3 -0
  57. package/dist/runtime/app/composables/cms-account.d.ts +11 -0
  58. package/dist/runtime/app/composables/cms-account.js +23 -0
  59. package/dist/runtime/app/composables/cms-media-uploader.d.ts +11 -1
  60. package/dist/runtime/app/composables/cms-media-uploader.js +138 -11
  61. package/dist/runtime/app/composables/cms-settings.d.ts +13 -0
  62. package/dist/runtime/app/composables/cms-settings.js +59 -0
  63. package/dist/runtime/app/composables/cms-theme.d.ts +9 -0
  64. package/dist/runtime/app/composables/cms-theme.js +27 -0
  65. package/dist/runtime/app/layouts/cms-admin.d.vue.ts +2 -2
  66. package/dist/runtime/app/layouts/cms-admin.vue +71 -17
  67. package/dist/runtime/app/layouts/cms-admin.vue.d.ts +2 -2
  68. package/dist/runtime/app/pages/admin-collection.vue +127 -101
  69. package/dist/runtime/app/pages/admin-entry.vue +1 -0
  70. package/dist/runtime/app/pages/admin-login.vue +18 -3
  71. package/dist/runtime/app/pages/admin-media.vue +5 -1
  72. package/dist/runtime/app/utils/ui.d.ts +2 -0
  73. package/dist/runtime/app/utils/ui.js +18 -0
  74. package/dist/runtime/assets/main.css +1 -1
  75. package/dist/runtime/server/api/account-password.put.d.ts +4 -0
  76. package/dist/runtime/server/api/account-password.put.js +38 -0
  77. package/dist/runtime/server/api/account-welcome.post.d.ts +4 -0
  78. package/dist/runtime/server/api/account-welcome.post.js +14 -0
  79. package/dist/runtime/server/api/account.put.d.ts +3 -0
  80. package/dist/runtime/server/api/account.put.js +25 -0
  81. package/dist/runtime/server/api/settings.delete.d.ts +4 -0
  82. package/dist/runtime/server/api/settings.delete.js +12 -0
  83. package/dist/runtime/server/api/settings.get.d.ts +3 -0
  84. package/dist/runtime/server/api/settings.get.js +15 -0
  85. package/dist/runtime/server/api/settings.put.d.ts +3 -0
  86. package/dist/runtime/server/api/settings.put.js +14 -0
  87. package/dist/runtime/server/api/user.delete.d.ts +4 -0
  88. package/dist/runtime/server/api/user.delete.js +12 -0
  89. package/dist/runtime/server/api/user.put.d.ts +3 -0
  90. package/dist/runtime/server/api/user.put.js +27 -0
  91. package/dist/runtime/server/api/users.get.d.ts +3 -0
  92. package/dist/runtime/server/api/users.get.js +11 -0
  93. package/dist/runtime/server/api/users.post.d.ts +3 -0
  94. package/dist/runtime/server/api/users.post.js +32 -0
  95. package/dist/runtime/server/plugins/session-validate.d.ts +2 -0
  96. package/dist/runtime/server/plugins/session-validate.js +13 -0
  97. package/dist/runtime/server/routes/auth/login.post.js +18 -8
  98. package/dist/runtime/server/utils/password.d.ts +3 -0
  99. package/dist/runtime/server/utils/password.js +31 -0
  100. package/dist/runtime/server/utils/require-admin.d.ts +6 -2
  101. package/dist/runtime/server/utils/require-admin.js +33 -28
  102. package/dist/runtime/server/utils/same-origin.d.ts +2 -0
  103. package/dist/runtime/server/utils/same-origin.js +24 -0
  104. package/dist/runtime/server/utils/settings.d.ts +16 -0
  105. package/dist/runtime/server/utils/settings.js +31 -0
  106. package/dist/runtime/server/utils/users.d.ts +15 -0
  107. package/dist/runtime/server/utils/users.js +34 -0
  108. package/dist/runtime/shared/index.d.ts +13 -1
  109. package/dist/runtime/shared/index.js +2 -0
  110. package/dist/runtime/shared/layout.d.ts +34 -0
  111. package/dist/runtime/shared/layout.js +130 -0
  112. package/dist/runtime/shared/users.d.ts +18 -0
  113. package/dist/runtime/shared/users.js +1 -0
  114. package/dist/runtime/shared/validation.js +5 -4
  115. package/package.json +3 -3
@@ -0,0 +1,77 @@
1
+ <template>
2
+ <CmsInput
3
+ v-model="model"
4
+ :type="visible ? 'text' : 'password'"
5
+ icon="key"
6
+ class="cms-password-input"
7
+ :autocomplete="autocomplete ?? 'new-password'"
8
+ :placeholder="placeholder"
9
+ >
10
+ <template #trailing>
11
+ <span class="cms-password-actions">
12
+ <button
13
+ type="button"
14
+ class="cms-password-action"
15
+ :title="visible ? 'Hide password' : 'Show password'"
16
+ :aria-label="visible ? 'Hide password' : 'Show password'"
17
+ @click="visible = !visible"
18
+ >
19
+ <CmsIcon :name="visible ? 'eye-slash' : 'eye'" class="size-4" />
20
+ </button>
21
+ <button
22
+ v-if="generate"
23
+ type="button"
24
+ class="cms-password-action"
25
+ title="Generate a password"
26
+ aria-label="Generate a password"
27
+ @click="regenerate"
28
+ >
29
+ <CmsIcon name="sparkles" class="size-4" />
30
+ </button>
31
+ <button
32
+ v-if="copy"
33
+ type="button"
34
+ class="cms-password-action"
35
+ :class="{ 'is-done': copied }"
36
+ :title="copied ? 'Copied' : 'Copy password'"
37
+ :aria-label="copied ? 'Copied' : 'Copy password'"
38
+ :disabled="!model"
39
+ @click="copyPassword"
40
+ >
41
+ <CmsIcon
42
+ :name="copied ? 'clipboard-document-check' : 'clipboard-document'"
43
+ class="size-4"
44
+ />
45
+ </button>
46
+ </span>
47
+ </template>
48
+ </CmsInput>
49
+ </template>
50
+
51
+ <script setup>
52
+ import { ref } from "#imports";
53
+ import { generatePassword } from "../../composables/cms-account";
54
+ defineProps({
55
+ generate: { type: Boolean, required: false },
56
+ copy: { type: Boolean, required: false },
57
+ placeholder: { type: String, required: false },
58
+ autocomplete: { type: String, required: false }
59
+ });
60
+ const model = defineModel({ type: String, ...{ required: true } });
61
+ const visible = ref(false);
62
+ const copied = ref(false);
63
+ let copiedTimer;
64
+ function regenerate() {
65
+ model.value = generatePassword();
66
+ visible.value = true;
67
+ }
68
+ async function copyPassword() {
69
+ if (!model.value) return;
70
+ await navigator.clipboard.writeText(model.value);
71
+ copied.value = true;
72
+ clearTimeout(copiedTimer);
73
+ copiedTimer = setTimeout(() => {
74
+ copied.value = false;
75
+ }, 1600);
76
+ }
77
+ </script>
@@ -0,0 +1,17 @@
1
+ type __VLS_Props = {
2
+ generate?: boolean;
3
+ copy?: boolean;
4
+ placeholder?: string;
5
+ autocomplete?: string;
6
+ };
7
+ type __VLS_ModelProps = {
8
+ modelValue: string;
9
+ };
10
+ type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
11
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
12
+ "update:modelValue": (value: string) => any;
13
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
14
+ "onUpdate:modelValue"?: ((value: string) => any) | undefined;
15
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
16
+ declare const _default: typeof __VLS_export;
17
+ export default _default;
@@ -25,11 +25,9 @@
25
25
  @input="onInput"
26
26
  @focus="onFocus"
27
27
  />
28
- <CmsIcon
29
- v-if="loading"
30
- name="arrow-path"
31
- class="cms-selectmenu-affix ml-auto size-4 animate-spin"
32
- />
28
+ <span v-if="loading" class="cms-selectmenu-affix ml-auto flex">
29
+ <CmsIcon name="arrow-path" class="size-4 animate-spin" />
30
+ </span>
33
31
  <button
34
32
  v-else
35
33
  type="button"
@@ -0,0 +1,3 @@
1
+ declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
3
+ export default _default;
@@ -0,0 +1,138 @@
1
+ <template>
2
+ <div class="cms-settings-entry">
3
+ <div class="cms-settings-entry-header">
4
+ <div class="cms-settings-heading">
5
+ <h2 class="cms-title cms-title-sm">Account</h2>
6
+ <p class="cms-settings-hint">Your profile and your password.</p>
7
+ </div>
8
+ </div>
9
+
10
+ <div class="cms-account-card">
11
+ <span class="cms-avatar is-lg">{{ initial }}</span>
12
+ <div class="cms-account-text">
13
+ <span class="cms-account-name">{{ displayName }}</span>
14
+ <span class="cms-account-email">{{ email }}</span>
15
+ </div>
16
+ <span class="cms-badge is-muted">{{ isSuperAdmin ? "Super admin" : "Admin" }}</span>
17
+ </div>
18
+
19
+ <CmsAlert v-if="isSuperAdmin" color="neutral" title="Environment account">
20
+ This account signs in with the credentials of the environment variables
21
+ (NUXT_CMS_ADMIN_EMAIL and NUXT_CMS_ADMIN_PASSWORD). Change them there. Only this account
22
+ can manage users.
23
+ </CmsAlert>
24
+
25
+ <template v-else>
26
+ <div class="cms-settings-group">
27
+ <div class="cms-settings-heading">
28
+ <p class="cms-settings-label">Profile</p>
29
+ <p class="cms-settings-hint">The name shows in the sidebar.</p>
30
+ </div>
31
+ <CmsForm :state="profile" @submit="saveProfile">
32
+ <div class="cms-form-row" style="--cms-row-cols: 2">
33
+ <CmsFormField label="Name" name="name">
34
+ <CmsInput v-model="profile.name" placeholder="Your name" autocomplete="name" />
35
+ </CmsFormField>
36
+ <CmsFormField label="Email" name="email">
37
+ <CmsInput :model-value="email" disabled />
38
+ </CmsFormField>
39
+ </div>
40
+ <div class="cms-actions is-end">
41
+ <CmsButton
42
+ type="submit"
43
+ label="Save profile"
44
+ size="sm"
45
+ :loading="savingProfile"
46
+ :disabled="profile.name === (user?.name ?? '')"
47
+ />
48
+ </div>
49
+ </CmsForm>
50
+ </div>
51
+
52
+ <div class="cms-settings-group">
53
+ <div class="cms-settings-heading">
54
+ <p class="cms-settings-label">Password</p>
55
+ <p class="cms-settings-hint">
56
+ At least {{ MIN_PASSWORD_LENGTH }} characters. Use the sparkle button to generate
57
+ one.
58
+ </p>
59
+ </div>
60
+ <CmsForm :state="password" @submit="savePassword">
61
+ <CmsAlert v-if="passwordError" color="error" :title="passwordError" />
62
+ <CmsFormField label="Current password" name="current">
63
+ <CmsPasswordInput
64
+ v-model="password.current"
65
+ autocomplete="current-password"
66
+ placeholder="••••••••"
67
+ />
68
+ </CmsFormField>
69
+ <CmsFormField label="New password" name="next">
70
+ <CmsPasswordInput v-model="password.next" generate copy />
71
+ </CmsFormField>
72
+ <div class="cms-actions is-end">
73
+ <CmsButton
74
+ type="submit"
75
+ label="Change password"
76
+ size="sm"
77
+ :loading="savingPassword"
78
+ :disabled="!password.current || password.next.length < MIN_PASSWORD_LENGTH"
79
+ />
80
+ </div>
81
+ </CmsForm>
82
+ </div>
83
+ </template>
84
+ </div>
85
+ </template>
86
+
87
+ <script setup>
88
+ import { MIN_PASSWORD_LENGTH } from "#nuxt-cms";
89
+ import { ref, watch } from "#imports";
90
+ import { useCmsAccount } from "../../composables/cms-account";
91
+ import { useCmsToast } from "../../composables/cms-toast";
92
+ import { cmsApi } from "../../utils/api";
93
+ import { errorMessage } from "../../utils/ui";
94
+ const { user, email, isSuperAdmin, displayName, initial, refresh } = useCmsAccount();
95
+ const toast = useCmsToast();
96
+ const profile = ref({ name: user.value?.name ?? "" });
97
+ watch(
98
+ () => user.value?.name,
99
+ (name) => {
100
+ profile.value.name = name ?? "";
101
+ }
102
+ );
103
+ const savingProfile = ref(false);
104
+ async function saveProfile() {
105
+ savingProfile.value = true;
106
+ try {
107
+ await cmsApi("/api/cms/account", {
108
+ method: "PUT",
109
+ body: { name: profile.value.name || null }
110
+ });
111
+ await refresh();
112
+ toast.add({ title: "Profile saved", color: "success" });
113
+ } catch (error) {
114
+ toast.add({ title: "Profile not saved", description: errorMessage(error), color: "error" });
115
+ } finally {
116
+ savingProfile.value = false;
117
+ }
118
+ }
119
+ const password = ref({ current: "", next: "" });
120
+ const passwordError = ref(null);
121
+ const savingPassword = ref(false);
122
+ async function savePassword() {
123
+ savingPassword.value = true;
124
+ passwordError.value = null;
125
+ try {
126
+ await cmsApi("/api/cms/account/password", {
127
+ method: "PUT",
128
+ body: { currentPassword: password.value.current, newPassword: password.value.next }
129
+ });
130
+ password.value = { current: "", next: "" };
131
+ toast.add({ title: "Password changed", color: "success" });
132
+ } catch (error) {
133
+ passwordError.value = errorMessage(error) ?? "Password not changed.";
134
+ } finally {
135
+ savingPassword.value = false;
136
+ }
137
+ }
138
+ </script>
@@ -0,0 +1,3 @@
1
+ declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
3
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import type { FieldConfig } from '#nuxt-cms';
2
+ type __VLS_Props = {
3
+ fields: Record<string, FieldConfig>;
4
+ extra: string[];
5
+ };
6
+ type __VLS_ModelProps = {
7
+ modelValue: string[];
8
+ };
9
+ type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
10
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
11
+ "update:modelValue": (value: string[]) => any;
12
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
13
+ "onUpdate:modelValue"?: ((value: string[]) => any) | undefined;
14
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
15
+ declare const _default: typeof __VLS_export;
16
+ export default _default;
@@ -0,0 +1,102 @@
1
+ <template>
2
+ <div class="cms-settings-columns">
3
+ <p class="cms-settings-hint">
4
+ Choose the columns of the table. Drag the visible columns to change their order.
5
+ </p>
6
+ <ul class="cms-settings-list">
7
+ <li
8
+ v-for="(key, index) in model"
9
+ :key="key"
10
+ class="cms-settings-item is-draggable"
11
+ :class="{
12
+ 'is-dragging': dragging === key,
13
+ 'is-drop-before': dropIndex === index && dragging !== key
14
+ }"
15
+ draggable="true"
16
+ @dragstart="onDragStart($event, key)"
17
+ @dragover.prevent="dropIndex = index"
18
+ @drop.prevent="onDrop(index)"
19
+ @dragend="onDragEnd"
20
+ >
21
+ <CmsIcon name="bars-2" class="cms-settings-grip size-4" />
22
+ <CmsIcon :name="iconOf(key)" class="cms-settings-item-icon size-4" />
23
+ <span class="cms-settings-item-label">{{ labelOf(key) }}</span>
24
+ <CmsSwitch
25
+ :model-value="true"
26
+ :aria-label="`Hide ${labelOf(key)}`"
27
+ :disabled="model.length === 1"
28
+ @update:model-value="hide(key)"
29
+ />
30
+ </li>
31
+ <li
32
+ v-if="dragging"
33
+ class="cms-settings-drop-end"
34
+ :class="{ 'is-over': dropIndex === model.length }"
35
+ @dragover.prevent="dropIndex = model.length"
36
+ @drop.prevent="onDrop(model.length)"
37
+ />
38
+ </ul>
39
+
40
+ <template v-if="hidden.length">
41
+ <p class="cms-settings-subtitle">Hidden</p>
42
+ <ul class="cms-settings-list">
43
+ <li v-for="key in hidden" :key="key" class="cms-settings-item is-muted">
44
+ <CmsIcon :name="iconOf(key)" class="cms-settings-item-icon size-4" />
45
+ <span class="cms-settings-item-label">{{ labelOf(key) }}</span>
46
+ <CmsSwitch
47
+ :model-value="false"
48
+ :aria-label="`Show ${labelOf(key)}`"
49
+ @update:model-value="show(key)"
50
+ />
51
+ </li>
52
+ </ul>
53
+ </template>
54
+ </div>
55
+ </template>
56
+
57
+ <script setup>
58
+ import { computed, ref } from "#imports";
59
+ import { fieldIcon } from "../../utils/ui";
60
+ const props = defineProps({
61
+ fields: { type: Object, required: true },
62
+ extra: { type: Array, required: true }
63
+ });
64
+ const model = defineModel({ type: Array, ...{ required: true } });
65
+ const available = computed(() => [...Object.keys(props.fields), ...props.extra]);
66
+ const hidden = computed(() => available.value.filter((key) => !model.value.includes(key)));
67
+ function labelOf(key) {
68
+ return props.fields[key]?.label ?? (key === "status" ? "Status" : key);
69
+ }
70
+ function iconOf(key) {
71
+ const field = props.fields[key];
72
+ return field ? fieldIcon(field) : "check-circle";
73
+ }
74
+ function hide(key) {
75
+ if (model.value.length === 1) return;
76
+ model.value = model.value.filter((k) => k !== key);
77
+ }
78
+ function show(key) {
79
+ model.value = [...model.value, key];
80
+ }
81
+ const dragging = ref(null);
82
+ const dropIndex = ref(null);
83
+ function onDragStart(event, key) {
84
+ dragging.value = key;
85
+ event.dataTransfer?.setData("text/plain", key);
86
+ if (event.dataTransfer) event.dataTransfer.effectAllowed = "move";
87
+ }
88
+ function onDrop(index) {
89
+ const key = dragging.value;
90
+ if (key) {
91
+ const next = model.value.filter((k) => k !== key);
92
+ const from = model.value.indexOf(key);
93
+ next.splice(from < index ? index - 1 : index, 0, key);
94
+ model.value = next;
95
+ }
96
+ onDragEnd();
97
+ }
98
+ function onDragEnd() {
99
+ dragging.value = null;
100
+ dropIndex.value = null;
101
+ }
102
+ </script>
@@ -0,0 +1,16 @@
1
+ import type { FieldConfig } from '#nuxt-cms';
2
+ type __VLS_Props = {
3
+ fields: Record<string, FieldConfig>;
4
+ extra: string[];
5
+ };
6
+ type __VLS_ModelProps = {
7
+ modelValue: string[];
8
+ };
9
+ type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
10
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
11
+ "update:modelValue": (value: string[]) => any;
12
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
13
+ "onUpdate:modelValue"?: ((value: string[]) => any) | undefined;
14
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
15
+ declare const _default: typeof __VLS_export;
16
+ export default _default;
@@ -0,0 +1,6 @@
1
+ type __VLS_Props = {
2
+ name: string;
3
+ };
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
5
+ declare const _default: typeof __VLS_export;
6
+ export default _default;
@@ -0,0 +1,133 @@
1
+ <template>
2
+ <div class="cms-settings-entry">
3
+ <div class="cms-settings-entry-header">
4
+ <div class="cms-settings-heading">
5
+ <h2 class="cms-title cms-title-sm">{{ entry.label }}</h2>
6
+ <p class="cms-settings-hint">{{ KIND_LABELS[entry.kind] }}</p>
7
+ </div>
8
+ <span class="cms-settings-status" :class="`is-${status}`" aria-live="polite">
9
+ {{ STATUS_LABELS[status] }}
10
+ </span>
11
+ </div>
12
+
13
+ <div v-if="parts.length > 1" class="cms-tabs" role="tablist">
14
+ <button
15
+ v-for="part in parts"
16
+ :key="part.id"
17
+ type="button"
18
+ role="tab"
19
+ class="cms-tab"
20
+ :class="{ 'is-active': activePart === part.id }"
21
+ :aria-selected="activePart === part.id"
22
+ @click="activePart = part.id"
23
+ >
24
+ {{ part.label }}
25
+ </button>
26
+ </div>
27
+
28
+ <CmsSettingsColumns
29
+ v-if="activePart === 'columns'"
30
+ :model-value="columns"
31
+ :fields="entry.fields"
32
+ :extra="listExtraColumns(name)"
33
+ @update:model-value="saveColumns"
34
+ />
35
+ <CmsSettingsLayout
36
+ v-else
37
+ :model-value="layout"
38
+ :fields="fields"
39
+ :tabs="entry.tabs"
40
+ @update:model-value="saveLayout"
41
+ />
42
+
43
+ <div class="cms-settings-footer">
44
+ <CmsButton
45
+ label="Reset to default"
46
+ icon="arrow-uturn-left"
47
+ variant="ghost"
48
+ color="neutral"
49
+ size="sm"
50
+ :disabled="!isCustom"
51
+ @click="resetPart"
52
+ />
53
+ </div>
54
+ </div>
55
+ </template>
56
+
57
+ <script setup>
58
+ import { computed, ref, watch } from "#imports";
59
+ import cmsConfig from "#cms-config";
60
+ import {
61
+ entryFields,
62
+ entryFormLayout,
63
+ entryListColumns,
64
+ listExtraColumns,
65
+ useCmsSettings
66
+ } from "../../composables/cms-settings";
67
+ import { useCmsToast } from "../../composables/cms-toast";
68
+ import { errorMessage } from "../../utils/ui";
69
+ const KIND_LABELS = {
70
+ collection: "Collection",
71
+ single: "Single",
72
+ page: "Pages"
73
+ };
74
+ const STATUS_LABELS = {
75
+ idle: "Changes save automatically",
76
+ saving: "Saving\u2026",
77
+ saved: "Saved",
78
+ error: "Not saved"
79
+ };
80
+ const props = defineProps({
81
+ name: { type: String, required: true }
82
+ });
83
+ const { settings, save, reset } = useCmsSettings();
84
+ const toast = useCmsToast();
85
+ const entry = computed(() => cmsConfig[props.name]);
86
+ const fields = computed(() => entryFields(props.name));
87
+ const parts = computed(() => [
88
+ ...entry.value.kind === "collection" ? [{ id: "columns", label: "Table columns" }] : [],
89
+ { id: "layout", label: "Form layout" }
90
+ ]);
91
+ const activePart = ref(parts.value[0].id);
92
+ watch(
93
+ () => props.name,
94
+ () => {
95
+ activePart.value = parts.value[0].id;
96
+ status.value = "idle";
97
+ }
98
+ );
99
+ const columns = computed(() => entryListColumns(props.name, settings.value));
100
+ const layout = computed(() => entryFormLayout(props.name, settings.value, fields.value));
101
+ const isCustom = computed(() => {
102
+ const saved = settings.value[props.name];
103
+ return activePart.value === "columns" ? !!saved?.columns : !!saved?.layout;
104
+ });
105
+ const status = ref("idle");
106
+ async function persist(next) {
107
+ status.value = "saving";
108
+ try {
109
+ if (!next.columns && !next.layout) await reset(props.name);
110
+ else await save(props.name, next);
111
+ status.value = "saved";
112
+ } catch (error) {
113
+ status.value = "error";
114
+ toast.add({ title: "Settings not saved", description: errorMessage(error), color: "error" });
115
+ }
116
+ }
117
+ function current() {
118
+ const saved = settings.value[props.name] ?? {};
119
+ return { columns: saved.columns, layout: saved.layout };
120
+ }
121
+ function saveColumns(value) {
122
+ void persist({ ...current(), columns: value });
123
+ }
124
+ function saveLayout(value) {
125
+ void persist({ ...current(), layout: value });
126
+ }
127
+ function resetPart() {
128
+ const next = current();
129
+ if (activePart.value === "columns") next.columns = void 0;
130
+ else next.layout = void 0;
131
+ void persist(next);
132
+ }
133
+ </script>
@@ -0,0 +1,6 @@
1
+ type __VLS_Props = {
2
+ name: string;
3
+ };
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
5
+ declare const _default: typeof __VLS_export;
6
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import type { CmsFormLayout, CmsTab, FieldConfig } from '#nuxt-cms';
2
+ type __VLS_Props = {
3
+ fields: Record<string, FieldConfig>;
4
+ tabs?: CmsTab[];
5
+ };
6
+ type __VLS_ModelProps = {
7
+ modelValue: CmsFormLayout;
8
+ };
9
+ type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
10
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
11
+ "update:modelValue": (value: CmsFormLayout) => any;
12
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
13
+ "onUpdate:modelValue"?: ((value: CmsFormLayout) => any) | undefined;
14
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
15
+ declare const _default: typeof __VLS_export;
16
+ export default _default;