@upsoftware_tech/svarium 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1154 -171
- package/dist/src/pages/Init.vue +21 -0
- package/dist/src/pages/Svarium.vue +189 -0
- package/dist/svarium.css +1 -1
- package/dist/svarium.es.js +27860 -21927
- package/dist/svarium.umd.js +6 -7
- package/package.json +3 -3
- package/src/pages/Init.vue +21 -0
- package/src/pages/Svarium.vue +189 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { h, resolveComponent } from 'vue';
|
|
3
|
+
|
|
4
|
+
const props = defineProps({
|
|
5
|
+
tree: Object,
|
|
6
|
+
meta: Object
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
function renderNode(node) {
|
|
10
|
+
const component = resolveComponent(node.type);
|
|
11
|
+
|
|
12
|
+
return h(component, node.props || {}, () => node.children?.map(renderNode));
|
|
13
|
+
}
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<pre>{{ meta }}</pre>
|
|
18
|
+
<hr />
|
|
19
|
+
<pre>{{ tree }}</pre>
|
|
20
|
+
<component :is="renderNode(tree)" />
|
|
21
|
+
</template>
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<pre class="hidden">{{ tree }}</pre>
|
|
3
|
+
<main class="flex bg-slate-100 dark:bg-slate-950 h-screen">
|
|
4
|
+
<template v-if="Array.isArray(tree)">
|
|
5
|
+
<component
|
|
6
|
+
:is="renderNode(node)"
|
|
7
|
+
:key="index"
|
|
8
|
+
v-for="(node, index) in tree"
|
|
9
|
+
/>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<template v-else>
|
|
13
|
+
<component :is="renderNode(tree)" />
|
|
14
|
+
</template>
|
|
15
|
+
</main>
|
|
16
|
+
<Toaster position="bottom-center" />
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script setup lang="ts">
|
|
20
|
+
import { usePage } from '@inertiajs/vue3';
|
|
21
|
+
import { computed, h, isRef, ref, resolveComponent, watch } from 'vue';
|
|
22
|
+
import { Toaster } from 'vue-sonner';
|
|
23
|
+
import { toast } from 'vue-sonner';
|
|
24
|
+
import { normalizeNodeProps } from '../lib/appearance';
|
|
25
|
+
import 'vue-sonner/style.css';
|
|
26
|
+
|
|
27
|
+
const props = defineProps<{
|
|
28
|
+
tree: any;
|
|
29
|
+
meta?: any;
|
|
30
|
+
modelValue?: any;
|
|
31
|
+
}>();
|
|
32
|
+
|
|
33
|
+
const emit = defineEmits<{
|
|
34
|
+
(e: 'update:modelValue', value: any): void;
|
|
35
|
+
}>();
|
|
36
|
+
|
|
37
|
+
function resolveModelValue(modelContext: any): any {
|
|
38
|
+
if (modelContext && typeof modelContext === 'object' && 'value' in modelContext) {
|
|
39
|
+
return modelContext.value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (isRef(modelContext)) {
|
|
43
|
+
return modelContext.value;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (modelContext !== undefined) {
|
|
47
|
+
return modelContext;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return props.modelValue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function updateModelValue(modelContext: any, value: any): void {
|
|
54
|
+
if (modelContext && typeof modelContext === 'object' && typeof modelContext.update === 'function') {
|
|
55
|
+
modelContext.update(value);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (isRef(modelContext)) {
|
|
60
|
+
modelContext.value = value;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
emit('update:modelValue', value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function renderNode(node: any, modelContext?: any) {
|
|
68
|
+
if (!node || typeof node !== 'object') {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const componentName = node.component ?? node.type;
|
|
73
|
+
|
|
74
|
+
if (!componentName) {
|
|
75
|
+
console.error('Missing component type', node);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const component = resolveComponent(componentName);
|
|
80
|
+
const slots: Record<string, (...args: any[]) => any> = {};
|
|
81
|
+
|
|
82
|
+
if (Array.isArray(node.children) && node.children.length) {
|
|
83
|
+
slots.default = () => node.children.map((child: any) => renderNode(child, modelContext));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (node.slots && !Array.isArray(node.slots)) {
|
|
87
|
+
for (const [name, content] of Object.entries(node.slots)) {
|
|
88
|
+
if (!Array.isArray(content)) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
slots[name] = (slotProps: any = {}) => {
|
|
93
|
+
const hasSlotModel =
|
|
94
|
+
Object.prototype.hasOwnProperty.call(slotProps, 'modelValue') ||
|
|
95
|
+
Object.prototype.hasOwnProperty.call(slotProps, 'tab');
|
|
96
|
+
|
|
97
|
+
const slotModelContext =
|
|
98
|
+
hasSlotModel || typeof slotProps?.updateModelValue === 'function'
|
|
99
|
+
? {
|
|
100
|
+
value: slotProps?.modelValue ?? slotProps?.tab ?? resolveModelValue(modelContext),
|
|
101
|
+
update: slotProps?.updateModelValue,
|
|
102
|
+
}
|
|
103
|
+
: (slotProps?.model ?? modelContext);
|
|
104
|
+
|
|
105
|
+
return content.map((child: any) => renderNode(child, slotModelContext));
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return h(
|
|
111
|
+
component,
|
|
112
|
+
{
|
|
113
|
+
...normalizeNodeProps(node.props ?? {}),
|
|
114
|
+
modelValue: resolveModelValue(modelContext),
|
|
115
|
+
'onUpdate:modelValue': (value: any) => {
|
|
116
|
+
updateModelValue(modelContext, value);
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
slots,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
type FlashMessages = {
|
|
124
|
+
success?: string;
|
|
125
|
+
error?: string;
|
|
126
|
+
warning?: string;
|
|
127
|
+
info?: string;
|
|
128
|
+
message?: string;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const page = usePage();
|
|
132
|
+
const lastFlashFingerprint = ref('');
|
|
133
|
+
|
|
134
|
+
const flash = computed<FlashMessages>(() => {
|
|
135
|
+
const currentPage = page as unknown as { flash?: unknown; props?: { flash?: unknown } };
|
|
136
|
+
const value = currentPage.flash ?? currentPage.props?.flash;
|
|
137
|
+
|
|
138
|
+
if (!value || typeof value !== 'object') {
|
|
139
|
+
return {};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return value as FlashMessages;
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
watch(
|
|
146
|
+
flash,
|
|
147
|
+
(value) => {
|
|
148
|
+
const fingerprint = ['success', 'error', 'warning', 'info', 'message']
|
|
149
|
+
.map((key) => {
|
|
150
|
+
const flashKey = key as keyof FlashMessages;
|
|
151
|
+
const item = value[flashKey];
|
|
152
|
+
return `${key}:${typeof item === 'string' ? item : ''}`;
|
|
153
|
+
})
|
|
154
|
+
.join('|');
|
|
155
|
+
|
|
156
|
+
if (fingerprint === 'success:|error:|warning:|info:|message:') {
|
|
157
|
+
lastFlashFingerprint.value = '';
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (fingerprint === lastFlashFingerprint.value) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
lastFlashFingerprint.value = fingerprint;
|
|
166
|
+
|
|
167
|
+
if (value.error) {
|
|
168
|
+
toast.error(value.error);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (value.warning) {
|
|
172
|
+
toast.warning(value.warning);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (value.success) {
|
|
176
|
+
toast.success(value.success);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (value.info) {
|
|
180
|
+
toast.info(value.info);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (value.message) {
|
|
184
|
+
toast(value.message);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
{ immediate: true },
|
|
188
|
+
);
|
|
189
|
+
</script>
|