rimelight-components 2.1.11 → 2.1.12

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/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rimelight-components",
3
- "version": "2.1.11",
3
+ "version": "2.1.12",
4
4
  "docs": "https://rimelight.com/tools/rimelight-components",
5
5
  "configKey": "rimelightComponents",
6
6
  "compatibility": {
package/dist/module.mjs CHANGED
@@ -4,7 +4,7 @@ import { readdirSync } from 'node:fs';
4
4
  import { basename } from 'node:path';
5
5
 
6
6
  const name = "rimelight-components";
7
- const version = "2.1.11";
7
+ const version = "2.1.12";
8
8
  const homepage = "https://rimelight.com/tools/rimelight-components";
9
9
 
10
10
  const defaultOptions = {
@@ -1,6 +1,10 @@
1
- import type { Page } from "../../types/index.js";
1
+ import type { Page, PageSurround } from "../../types/index.js";
2
2
  interface PageEditorProps {
3
3
  isSaving: boolean;
4
+ useSurround?: boolean;
5
+ surround?: PageSurround | null;
6
+ surroundStatus?: 'idle' | 'pending' | 'success' | 'error';
7
+ resolvePage?: (id: string) => Promise<Pick<Page, 'title' | 'icon' | 'slug'>>;
4
8
  }
5
9
  type __VLS_Props = PageEditorProps;
6
10
  type __VLS_ModelProps = {
@@ -1,11 +1,18 @@
1
1
  <script setup>
2
- import { ref, computed, useTemplateRef } from "vue";
3
- import { usePageEditor } from "../../composables";
2
+ import { ref, computed, useTemplateRef, provide } from "vue";
3
+ import { usePageEditor, usePageRegistry } from "../../composables";
4
4
  import { getLocalizedContent } from "../../utils";
5
+ import { useI18n } from "vue-i18n";
6
+ const { getTypeLabelKey } = usePageRegistry();
7
+ const { t, locale } = useI18n();
5
8
  const page = defineModel({ type: null, ...{ required: true } });
6
9
  const { undo, redo, canUndo, canRedo, captureSnapshot } = usePageEditor(page);
7
- const { isSaving } = defineProps({
8
- isSaving: { type: Boolean, required: true }
10
+ const { isSaving, useSurround = false, surroundStatus = "idle", surround = null, resolvePage } = defineProps({
11
+ isSaving: { type: Boolean, required: true },
12
+ useSurround: { type: Boolean, required: false },
13
+ surround: { type: [Object, null], required: false },
14
+ surroundStatus: { type: String, required: false },
15
+ resolvePage: { type: Function, required: false }
9
16
  });
10
17
  const emit = defineEmits(["save"]);
11
18
  const handleSave = () => {
@@ -20,12 +27,43 @@ defineExpose({
20
27
  });
21
28
  const editorRef = useTemplateRef("editor");
22
29
  const showPreview = ref(false);
23
- const editorPanelClass = computed(() => ({
24
- // When the preview is visible, both editor/preview share 1/2 span.
25
- "col-span-1 w-full": showPreview.value,
26
- // When the preview is hidden, the editor uses the full grid space.
27
- "col-span-2 w-full": !showPreview.value
28
- }));
30
+ provide("page-resolver", resolvePage);
31
+ const previousPage = computed(() => surround?.previous);
32
+ const nextPage = computed(() => surround?.next);
33
+ const hasSurround = computed(() => !!(surround?.previous || surround?.next));
34
+ const containerRef = useTemplateRef("split-container");
35
+ const editorWidth = ref(50);
36
+ const isResizing = ref(false);
37
+ const SNAP_THRESHOLD = 1.5;
38
+ const handleMouseMove = (e) => {
39
+ if (!isResizing.value || !containerRef.value) return;
40
+ const containerRect = containerRef.value.getBoundingClientRect();
41
+ let newWidth = (e.clientX - containerRect.left) / containerRect.width * 100;
42
+ newWidth = Math.min(Math.max(newWidth, 20), 80);
43
+ if (Math.abs(newWidth - 50) < SNAP_THRESHOLD) {
44
+ editorWidth.value = 50;
45
+ } else {
46
+ editorWidth.value = newWidth;
47
+ }
48
+ };
49
+ const cursorClass = computed(() => {
50
+ if (isResizing.value) return "cursor-grabbing";
51
+ return "cursor-grab";
52
+ });
53
+ const startResizing = (e) => {
54
+ isResizing.value = true;
55
+ window.addEventListener("mousemove", handleMouseMove);
56
+ window.addEventListener("mouseup", stopResizing);
57
+ document.body.style.cursor = "col-resize";
58
+ document.body.style.userSelect = "none";
59
+ };
60
+ const stopResizing = () => {
61
+ isResizing.value = false;
62
+ window.removeEventListener("mousemove", handleMouseMove);
63
+ window.removeEventListener("mouseup", stopResizing);
64
+ document.body.style.cursor = "";
65
+ document.body.style.userSelect = "";
66
+ };
29
67
  </script>
30
68
 
31
69
  <template>
@@ -72,70 +110,138 @@ const editorPanelClass = computed(() => ({
72
110
  </div>
73
111
  </template>
74
112
  </UHeader>
75
- <UContainer
76
- class="mt-24 grid gap-xl"
77
- :class="showPreview ? 'grid-cols-2 max-w-full' : 'grid-cols-1'"
113
+ <main
114
+ ref="split-container"
115
+ class="flex w-full overflow-hidden"
78
116
  >
79
- <div :class="editorPanelClass" class="grid grid-cols-1 lg:grid-cols-4 gap-8">
80
- <UPageAside class="order-1 lg:order-2 lg:col-span-1">
81
- <RCPagePropertiesEditor v-model="page" />
82
- </UPageAside>
83
- <div class="order-2 lg:order-1 lg:col-span-3">
84
- <UPageHeader
85
- :title="getLocalizedContent(page.title, 'en')"
86
- :description="getLocalizedContent(page.description, 'en') ?? ''"
87
- />
88
- <RCBlockEditor
89
- ref="editor"
90
- v-model="page.blocks"
91
- :class="editorPanelClass"
92
- @mutation="captureSnapshot"
93
- />
94
- <div class="flex flex-col gap-xs text-xs">
95
- <h6>Metadata</h6>
96
- <span>Page ID: {{ page.id }}</span>
97
- <span
98
- >Created At:
99
- <NuxtTime
100
- :datetime="page.created_at ?? ''"
101
- year="numeric"
102
- month="numeric"
103
- day="numeric"
104
- hour="numeric"
105
- minute="numeric"
106
- second="numeric"
107
- time-zone-name="short"
108
- /></span>
109
- <span
110
- >Posted At:
111
- <NuxtTime
112
- :datetime="page.created_at ?? ''"
113
- year="numeric"
114
- month="numeric"
115
- day="numeric"
116
- hour="numeric"
117
- minute="numeric"
118
- second="numeric"
119
- time-zone-name="short"
120
- /></span>
121
- <span
122
- >Updated At:
123
- <NuxtTime
124
- :datetime="page.created_at ?? ''"
125
- year="numeric"
126
- month="numeric"
127
- day="numeric"
128
- hour="numeric"
129
- minute="numeric"
130
- second="numeric"
131
- time-zone-name="short"
132
- /></span>
117
+ <div
118
+ class="h-full overflow-y-auto"
119
+ :style="{ width: showPreview ? `${editorWidth}%` : '100%' }"
120
+ >
121
+ <UContainer class="flex flex-col py-16">
122
+ <div class="grid grid-cols-1 lg:grid-cols-24 gap-xl items-start">
123
+ <RCPageTOC
124
+ :page-blocks="page.blocks"
125
+ :levels="[2, 3, 4]"
126
+ class="hidden lg:flex lg:col-span-4 sticky top-20 self-start"
127
+ >
128
+ <template #bottom> </template>
129
+ </RCPageTOC>
130
+ <RCPagePropertiesEditor v-model="page" class="order-1 lg:order-2 lg:col-span-6" />
131
+ <div class="order-2 lg:order-1 lg:col-span-14 flex flex-col gap-xl">
132
+ <NuxtImg
133
+ v-if="page.banner?.src"
134
+ :src="page.banner?.src"
135
+ :alt="page.banner?.alt"
136
+ class="rounded-xl w-full object-cover"
137
+ />
138
+ <UPageHeader
139
+ :headline="t(getTypeLabelKey(page.type))"
140
+ :description="getLocalizedContent(page.description, 'en') ?? ''"
141
+ :ui="{ root: 'pt-0' }"
142
+ >
143
+ <template #title>
144
+ <div class="flex flex-row gap-sm">
145
+ <NuxtImg
146
+ v-if="page.icon?.src"
147
+ :src="page.icon?.src"
148
+ :alt="page.icon?.alt"
149
+ class="rounded-full w-12 h-12 object-cover"
150
+ />
151
+ <h1>{{ getLocalizedContent(page.title, locale) }}</h1>
152
+ </div>
153
+ </template>
154
+ </UPageHeader>
155
+ <RCBlockEditor
156
+ ref="editor"
157
+ v-model="page.blocks"
158
+ @mutation="captureSnapshot"
159
+ />
160
+ <template v-if="useSurround">
161
+ <div v-if="surroundStatus === 'pending'" class="grid grid-cols-1 gap-md sm:grid-cols-2">
162
+ <USkeleton class="h-48 w-full rounded-xl" />
163
+ <USkeleton class="h-48 w-full rounded-xl" />
164
+ </div>
165
+
166
+ <LazyRCPageSurround
167
+ v-else-if="surroundStatus === 'success' && hasSurround"
168
+ hydrate-on-visible
169
+ :pageType="getTypeLabelKey(page.type)"
170
+ :previousTitle="getLocalizedContent(previousPage?.title, locale)"
171
+ :previousDescription="getLocalizedContent(previousPage?.description, locale)"
172
+ :previousTo="`/${previousPage?.slug}`"
173
+ :nextTitle="getLocalizedContent(nextPage?.title, locale)"
174
+ :nextDescription="getLocalizedContent(nextPage?.description, locale)"
175
+ :nextTo="`/${nextPage?.slug}`"
176
+ />
177
+
178
+ <USeparator />
179
+
180
+ <div class="flex flex-col gap-xs text-xs text-dimmed p-xl">
181
+ <h6>Metadata</h6>
182
+ <span>Page ID: {{ page.id }}</span>
183
+ <span
184
+ >Created At:
185
+ <NuxtTime
186
+ :datetime="page.created_at ?? ''"
187
+ year="numeric"
188
+ month="numeric"
189
+ day="numeric"
190
+ hour="numeric"
191
+ minute="numeric"
192
+ second="numeric"
193
+ time-zone-name="short"
194
+ /></span>
195
+ <span
196
+ >Posted At:
197
+ <NuxtTime
198
+ :datetime="page.created_at ?? ''"
199
+ year="numeric"
200
+ month="numeric"
201
+ day="numeric"
202
+ hour="numeric"
203
+ minute="numeric"
204
+ second="numeric"
205
+ time-zone-name="short"
206
+ /></span>
207
+ <span
208
+ >Updated At:
209
+ <NuxtTime
210
+ :datetime="page.created_at ?? ''"
211
+ year="numeric"
212
+ month="numeric"
213
+ day="numeric"
214
+ hour="numeric"
215
+ minute="numeric"
216
+ second="numeric"
217
+ time-zone-name="short"
218
+ /></span>
219
+ </div>
220
+ </template>
221
+ </div>
133
222
  </div>
134
- </div>
223
+ </UContainer>
135
224
  </div>
136
- <div class="flex flex-row gap-xl">
137
- <USeparator orientation="vertical" />
138
- <RCPageRenderer v-if="showPreview" v-model="page" />
225
+
226
+ <div
227
+ v-if="showPreview"
228
+ :class="cursorClass"
229
+ class="relative flex flex-col items-center justify-center w-6 cursor-col-resize group px-1 py-16"
230
+ @mousedown="startResizing"
231
+ @dblclick="editorWidth = 50"
232
+ >
233
+ <USeparator
234
+ orientation="vertical"
235
+ :ui="{}"
236
+ />
237
+ </div>
238
+
239
+ <div
240
+ v-if="showPreview"
241
+ class="h-full overflow-y-auto"
242
+ :style="{ width: `${100 - editorWidth}%` }"
243
+ >
244
+ <RCPageRenderer v-model="page" />
139
245
  </div>
140
- </UContainer>
246
+ </main>
141
247
  </template>
@@ -1,6 +1,10 @@
1
- import type { Page } from "../../types/index.js";
1
+ import type { Page, PageSurround } from "../../types/index.js";
2
2
  interface PageEditorProps {
3
3
  isSaving: boolean;
4
+ useSurround?: boolean;
5
+ surround?: PageSurround | null;
6
+ surroundStatus?: 'idle' | 'pending' | 'success' | 'error';
7
+ resolvePage?: (id: string) => Promise<Pick<Page, 'title' | 'icon' | 'slug'>>;
4
8
  }
5
9
  type __VLS_Props = PageEditorProps;
6
10
  type __VLS_ModelProps = {
@@ -1,101 +1,183 @@
1
1
  <script setup>
2
+ import { computed } from "vue";
2
3
  import { useI18n } from "vue-i18n";
3
- import { usePageRegistry } from "../../composables";
4
+ import { usePageRegistry, useInfobox } from "../../composables";
4
5
  import { getLocalizedContent } from "../../utils";
6
+ import {} from "@nuxt/ui/components/Tabs.vue";
5
7
  import {} from "../../types";
6
- const { getTypeLabelKey } = usePageRegistry();
7
8
  const page = defineModel({ type: null, ...{ required: true } });
9
+ const { getTypeLabelKey } = usePageRegistry();
10
+ const { isFieldVisible, shouldRenderGroup, getSortedFields, getSortedGroups } = useInfobox(page.value.properties);
8
11
  const { locale, t } = useI18n();
9
- const isFieldVisible = (fieldSchema) => {
10
- if (!fieldSchema.visibleIf) return true;
11
- return fieldSchema.visibleIf(page.value.properties);
12
- };
13
- const getSortedFields = (fields) => {
14
- return Object.entries(fields).sort(([, a], [, b]) => (a.order ?? 0) - (b.order ?? 0));
12
+ const imageTabs = computed(() => {
13
+ if (!page.value.images?.length) return [];
14
+ return page.value.images.map((img, index) => {
15
+ const localizedName = getLocalizedContent(img.name, locale.value);
16
+ return {
17
+ label: localizedName || `${t("label_image")} ${index + 1}`,
18
+ value: `image-${index}`,
19
+ img
20
+ };
21
+ });
22
+ });
23
+ const updateTextArray = (schema, vals) => {
24
+ schema.value = vals.map((str) => ({
25
+ ...schema.value.find((i) => i.en === str),
26
+ // Preserve other locales if they exist
27
+ en: str
28
+ }));
15
29
  };
16
30
  </script>
17
31
 
18
32
  <template>
19
- <UCard
20
- variant="soft"
21
- :ui="{ root: 'divide-none', header: 'bg-elevated text-center', body: 'bg-muted' }"
22
- >
23
- <template #header>
24
- <h3>
25
- {{ getLocalizedContent(page.title, locale) }}
26
- </h3>
27
- <UBadge variant="subtle" size="sm" color="primary" :label="t(getTypeLabelKey(page.type))" />
28
- </template>
33
+ <aside class="flex flex-col gap-md">
34
+ <UCard
35
+ variant="soft"
36
+ :ui="{ root: 'divide-none', header: 'bg-accented text-center', body: 'p-0 sm:p-0 bg-muted' }"
37
+ >
38
+ <template #header>
39
+ <div class="flex flex-col gap-xs items-center">
40
+ <NuxtImg
41
+ v-if="page.icon?.src"
42
+ :src="page.icon?.src"
43
+ :alt="page.icon?.alt"
44
+ class="rounded-full w-12 h-12 object-cover"
45
+ />
29
46
 
30
- <div v-for="(group, groupId) in page.properties" :key="groupId">
31
- <div class="flex items-center gap-3">
32
- <span class="text-[10px] font-bold uppercase tracking-widest text-primary">
33
- {{ group.label[locale] }}
34
- </span>
35
- <div class="h-px flex-1 bg-border/50"></div>
36
- </div>
47
+ <h3>
48
+ {{ getLocalizedContent(page.title, locale) }}
49
+ </h3>
37
50
 
38
- <div class="grid gap-y-4 px-1">
39
- <template v-for="[fieldKey, schema] in getSortedFields(group.fields)" :key="fieldKey">
40
- <UFormField
41
- v-if="isFieldVisible(schema)"
42
- :label="getLocalizedContent(schema.label, locale)"
43
- :name="fieldKey"
44
- >
45
- <UInput
46
- v-if="schema.type === 'text'"
47
- v-model="schema.value[locale]"
48
- variant="subtle"
49
- placeholder="..."
50
- />
51
+ <span class="text-sm">{{ t(getTypeLabelKey(page.type)) }}</span>
51
52
 
52
- <UInput
53
- v-else-if="schema.type === 'number'"
54
- v-model.number="schema.value"
55
- type="number"
56
- variant="subtle"
57
- />
53
+ <div v-if="page.tags?.length" class="flex flex-row flex-wrap gap-xs">
54
+ <UBadge
55
+ v-for="tag in page.tags"
56
+ :key="tag[locale]"
57
+ variant="soft"
58
+ size="xs"
59
+ color="neutral"
60
+ >
61
+ {{ tag[locale] }}
62
+ </UBadge>
63
+ </div>
58
64
 
59
- <USelect
60
- v-else-if="schema.type === 'enum'"
61
- v-model="schema.value"
62
- :items="schema.options || []"
63
- variant="subtle"
64
- />
65
+ <div v-if="page.images?.length" class="w-full">
66
+ <UTabs
67
+ v-if="page.images.length > 1"
68
+ :items="imageTabs"
69
+ default-value="image-0"
70
+ variant="link"
71
+ size="xs"
72
+ color="neutral"
73
+ class="w-full"
74
+ >
75
+ <template #content="{ item }">
76
+ <NuxtImg :src="item.img.src" :alt="item.img.alt" class="w-full object-cover" />
77
+ </template>
78
+ </UTabs>
65
79
 
66
- <UInputMenu
67
- v-else-if="schema.type === 'text-array'"
68
- :model-value="schema.value.map((v) => v[locale])"
69
- @update:model-value="(vals) => schema.value = vals.map((str) => ({ [locale]: str }))"
70
- multiple
71
- creatable
72
- variant="subtle"
73
- placeholder="Add item..."
74
- />
80
+ <div v-else-if="page.images[0]">
81
+ <NuxtImg
82
+ :src="page.images[0].src"
83
+ :alt="page.images[0].alt"
84
+ class="w-full object-cover"
85
+ />
86
+ </div>
87
+ </div>
88
+ </div>
89
+ </template>
75
90
 
76
- <UInput
77
- v-else-if="schema.type === 'page'"
78
- v-model="schema.value"
79
- icon="lucide:link-2"
80
- variant="subtle"
81
- :placeholder="`Select ${schema.allowedPageTypes?.join('/')}`"
82
- />
83
- </UFormField>
84
- </template>
85
- </div>
86
- </div>
91
+ <template #default>
92
+ <template v-for="[groupId, group] in getSortedGroups(page.properties)" :key="groupId">
93
+ <UCollapsible v-if="shouldRenderGroup(group, false)" :default-open="group.defaultOpen">
94
+ <template #default>
95
+ <UButton
96
+ :label="getLocalizedContent(group.label, locale)"
97
+ variant="soft"
98
+ trailing-icon="lucide:chevron-down"
99
+ :ui="{
100
+ trailingIcon: 'group-data-[state=open]:rotate-180 transition-transform duration-200'
101
+ }"
102
+ block
103
+ class="group rounded-none bg-elevated text-default"
104
+ />
105
+ </template>
87
106
 
88
- <USeparator class="my-6" />
107
+ <template #content>
108
+ <dl class="p-sm flex flex-col gap-xs">
109
+ <template v-for="[fieldKey, schema] in getSortedFields(group.fields)" :key="fieldKey">
110
+ <UFormField
111
+ v-if="isFieldVisible(schema, false)"
112
+ :label="getLocalizedContent(schema.label, locale)"
113
+ :name="fieldKey"
114
+ >
115
+ <UInput
116
+ v-if="schema.type === 'text'"
117
+ v-model="schema.value.en"
118
+ variant="subtle"
119
+ placeholder="Type here..."
120
+ class="w-full"
121
+ />
89
122
 
90
- <UFormField label="Global Search Tags">
91
- <UInputMenu
92
- v-model="page.tags"
93
- multiple
94
- creatable
95
- icon="lucide:tag"
96
- variant="subtle"
97
- placeholder="Add tags..."
123
+ <UInput
124
+ v-else-if="schema.type === 'number'"
125
+ v-model.number="schema.value"
126
+ type="number"
127
+ variant="subtle"
128
+ class="w-full"
129
+ />
130
+
131
+ <USelect
132
+ v-else-if="schema.type === 'enum'"
133
+ v-model="schema.value"
134
+ :items="schema.options || []"
135
+ variant="subtle"
136
+ class="w-full"
137
+ />
138
+
139
+ <UInputMenu
140
+ v-else-if="schema.type === 'text-array'"
141
+ :model-value="schema.value.map((v) => v.en)"
142
+ @update:model-value="(vals) => updateTextArray(schema, vals)"
143
+ multiple
144
+ creatable
145
+ variant="subtle"
146
+ placeholder="Add item..."
147
+ class="w-full"
148
+ />
149
+
150
+ <UInput
151
+ v-else-if="schema.type === 'page'"
152
+ v-model="schema.value"
153
+ icon="lucide:link-2"
154
+ variant="subtle"
155
+ :placeholder="`Select ${schema.allowedPageTypes?.join('/')}`"
156
+ class="w-full"
157
+ />
158
+ </UFormField>
159
+ </template>
160
+ </dl>
161
+ </template>
162
+ </UCollapsible>
163
+ </template>
164
+ </template>
165
+ </UCard>
166
+ <div class="flex flex-col gap-xs">
167
+ <h6>Links</h6>
168
+ <UButton
169
+ v-for="(link, index) in page.links"
170
+ :key="index"
171
+ :label="link.label"
172
+ :icon="link.icon"
173
+ :to="link.to"
174
+ :target="link.to ? '_blank' : void 0"
175
+ :external="!!link.to"
176
+ :variant="link.variant || 'link'"
177
+ :color="link.color || 'neutral'"
178
+ size="sm"
179
+ :ui="{ base: 'pl-0' }"
98
180
  />
99
- </UFormField>
100
- </UCard>
181
+ </div>
182
+ </aside>
101
183
  </template>
@@ -1,7 +1,7 @@
1
1
  <script setup>
2
2
  import { computed } from "vue";
3
3
  import { getLocalizedContent } from "../../utils";
4
- import { usePageRegistry } from "../../composables";
4
+ import { usePageRegistry, useInfobox } from "../../composables";
5
5
  import { useToast } from "@nuxt/ui/composables";
6
6
  import {} from "@nuxt/ui/components/Tabs.vue";
7
7
  import { useI18n } from "vue-i18n";
@@ -26,7 +26,7 @@ const hasSurround = computed(() => !!(surround?.previous || surround?.next));
26
26
  <RCPageTOC
27
27
  :page-blocks="page.blocks"
28
28
  :levels="[2, 3, 4]"
29
- class="hidden lg:flex lg:col-span-4 sticky top-32"
29
+ class="hidden lg:flex lg:col-span-4 sticky top-16"
30
30
  >
31
31
  <template #bottom> </template>
32
32
  </RCPageTOC>
@@ -84,7 +84,7 @@ onMounted(() => {
84
84
  </script>
85
85
 
86
86
  <template>
87
- <nav class="flex flex-col gap-sm self-start w-full" aria-label="Table of Contents">
87
+ <nav class="flex flex-col gap-sm w-full" aria-label="Table of Contents">
88
88
  <h5 v-if="title">
89
89
  {{ t(title) }}
90
90
  </h5>
@@ -2,3 +2,4 @@ export * from "./useDateRange.js";
2
2
  export * from "./usePageEditor.js";
3
3
  export * from "./useBlockEditor.js";
4
4
  export * from "./usePageRegistry.js";
5
+ export * from "./useInfobox.js";
@@ -2,3 +2,4 @@ export * from "./useDateRange.js";
2
2
  export * from "./usePageEditor.js";
3
3
  export * from "./useBlockEditor.js";
4
4
  export * from "./usePageRegistry.js";
5
+ export * from "./useInfobox.js";
@@ -2,3 +2,4 @@ export * from "./useDateRange.mjs";
2
2
  export * from "./usePageEditor.mjs";
3
3
  export * from "./useBlockEditor.mjs";
4
4
  export * from "./usePageRegistry.mjs";
5
+ export * from "./useInfobox.mjs";
@@ -0,0 +1,8 @@
1
+ import type { Property, PropertyGroup, BasePageProperties } from '../types/index.js';
2
+ export declare const useInfobox: (properties: BasePageProperties) => {
3
+ isFieldVisible: (schema: Property, isReadOnly: boolean) => boolean;
4
+ shouldRenderGroup: (group: PropertyGroup, isReadOnly: boolean) => boolean;
5
+ getSortedFields: (fields: Record<string, Property>) => [string, Property<any>][];
6
+ getSortedGroups: (props: BasePageProperties) => [string, PropertyGroup][];
7
+ locale: import("vue").WritableComputedRef<string, string>;
8
+ };
@@ -0,0 +1,31 @@
1
+ import { useI18n } from "vue-i18n";
2
+ export const useInfobox = (properties) => {
3
+ const { locale } = useI18n();
4
+ const isFieldVisible = (schema, isReadOnly) => {
5
+ const passesLogic = !schema.visibleIf || schema.visibleIf(properties);
6
+ if (!passesLogic) return false;
7
+ if (isReadOnly) {
8
+ const val = schema.value;
9
+ if (schema.type === "text") return !!val?.[locale.value];
10
+ if (schema.type === "text-array") return Array.isArray(val) && val.length > 0;
11
+ return val !== void 0 && val !== null && val !== "";
12
+ }
13
+ return true;
14
+ };
15
+ const shouldRenderGroup = (group, isReadOnly) => {
16
+ return Object.values(group.fields).some((schema) => isFieldVisible(schema, isReadOnly));
17
+ };
18
+ const getSortedFields = (fields) => {
19
+ return Object.entries(fields).sort(([, a], [, b]) => (a.order ?? 0) - (b.order ?? 0));
20
+ };
21
+ const getSortedGroups = (props) => {
22
+ return Object.entries(props).sort(([, a], [, b]) => (a.order ?? 0) - (b.order ?? 0));
23
+ };
24
+ return {
25
+ isFieldVisible,
26
+ shouldRenderGroup,
27
+ getSortedFields,
28
+ getSortedGroups,
29
+ locale
30
+ };
31
+ };
@@ -0,0 +1,31 @@
1
+ import { useI18n } from "vue-i18n";
2
+ export const useInfobox = (properties) => {
3
+ const { locale } = useI18n();
4
+ const isFieldVisible = (schema, isReadOnly) => {
5
+ const passesLogic = !schema.visibleIf || schema.visibleIf(properties);
6
+ if (!passesLogic) return false;
7
+ if (isReadOnly) {
8
+ const val = schema.value;
9
+ if (schema.type === "text") return !!val?.[locale.value];
10
+ if (schema.type === "text-array") return Array.isArray(val) && val.length > 0;
11
+ return val !== void 0 && val !== null && val !== "";
12
+ }
13
+ return true;
14
+ };
15
+ const shouldRenderGroup = (group, isReadOnly) => {
16
+ return Object.values(group.fields).some((schema) => isFieldVisible(schema, isReadOnly));
17
+ };
18
+ const getSortedFields = (fields) => {
19
+ return Object.entries(fields).sort(([, a], [, b]) => (a.order ?? 0) - (b.order ?? 0));
20
+ };
21
+ const getSortedGroups = (props) => {
22
+ return Object.entries(props).sort(([, a], [, b]) => (a.order ?? 0) - (b.order ?? 0));
23
+ };
24
+ return {
25
+ isFieldVisible,
26
+ shouldRenderGroup,
27
+ getSortedFields,
28
+ getSortedGroups,
29
+ locale
30
+ };
31
+ };
@@ -13,14 +13,12 @@ export function usePageEditor(page, maxHistorySize = 100) {
13
13
  const undo = () => {
14
14
  if (history.value.length === 0) return;
15
15
  future.value = [JSON.stringify(page.value), ...future.value];
16
- const previous = JSON.parse(history.value.pop());
17
- page.value = previous;
16
+ page.value = JSON.parse(history.value.pop());
18
17
  };
19
18
  const redo = () => {
20
19
  if (future.value.length === 0) return;
21
20
  history.value = [...history.value, JSON.stringify(page.value)];
22
- const next = JSON.parse(future.value.shift());
23
- page.value = next;
21
+ page.value = JSON.parse(future.value.shift());
24
22
  };
25
23
  const canUndo = computed(() => history.value.length > 0);
26
24
  const canRedo = computed(() => future.value.length > 0);
@@ -13,14 +13,12 @@ export function usePageEditor(page, maxHistorySize = 100) {
13
13
  const undo = () => {
14
14
  if (history.value.length === 0) return;
15
15
  future.value = [JSON.stringify(page.value), ...future.value];
16
- const previous = JSON.parse(history.value.pop());
17
- page.value = previous;
16
+ page.value = JSON.parse(history.value.pop());
18
17
  };
19
18
  const redo = () => {
20
19
  if (future.value.length === 0) return;
21
20
  history.value = [...history.value, JSON.stringify(page.value)];
22
- const next = JSON.parse(future.value.shift());
23
- page.value = next;
21
+ page.value = JSON.parse(future.value.shift());
24
22
  };
25
23
  const canUndo = computed(() => history.value.length > 0);
26
24
  const canRedo = computed(() => future.value.length > 0);
@@ -32,6 +32,7 @@ export interface PageDefinition {
32
32
  initialBlocks?: () => Block[];
33
33
  }
34
34
  export interface BasePageProperties {
35
+ [key: string]: PropertyGroup | undefined;
35
36
  }
36
37
  /**
37
38
  * Common fields shared by every page regardless of type.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rimelight-components",
3
- "version": "2.1.11",
3
+ "version": "2.1.12",
4
4
  "description": "A component library by Rimelight Entertainment.",
5
5
  "keywords": [
6
6
  "nuxt",