@vc-shell/framework 1.1.54 → 1.1.55

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vc-shell/framework",
3
- "version": "1.1.54",
3
+ "version": "1.1.55",
4
4
  "type": "module",
5
5
  "main": "./dist/framework.js",
6
6
  "types": "./dist/index.d.ts",
@@ -82,9 +82,9 @@
82
82
  "@fullhuman/postcss-purgecss": "^7.0.2",
83
83
  "@laynezh/vite-plugin-lib-assets": "v1.1.0",
84
84
  "@types/dompurify": "^3.0.5",
85
- "@vc-shell/api-client-generator": "^1.1.54",
86
- "@vc-shell/config-generator": "^1.1.54",
87
- "@vc-shell/ts-config": "^1.1.54",
85
+ "@vc-shell/api-client-generator": "^1.1.55",
86
+ "@vc-shell/config-generator": "^1.1.55",
87
+ "@vc-shell/ts-config": "^1.1.55",
88
88
  "@vitejs/plugin-vue": "^5.2.3",
89
89
  "@vue/test-utils": "^2.4.5",
90
90
  "cypress-signalr-mock": "^1.5.0",
@@ -1,3 +1,5 @@
1
1
  export * from "./useMenuExpanded";
2
2
  export * from "./useModificationTracker";
3
3
  export * from "./useTableSort";
4
+ export * from "./useBladeMultilanguage";
5
+ export * from "./useExternalWidgets";
@@ -0,0 +1,75 @@
1
+ import { ref, computed, watchEffect, type Ref } from "vue";
2
+ import { useLanguages } from "../../core/composables";
3
+
4
+ interface LanguageOption {
5
+ value: string;
6
+ label: string | undefined;
7
+ }
8
+
9
+ interface LanguageOptionWithFlag extends LanguageOption {
10
+ flag?: string;
11
+ }
12
+
13
+ interface UseBladeMultilanguageParams {
14
+ localesOptions: Ref<LanguageOption[]>;
15
+ currentLocale: Ref<string>;
16
+ setLocale: (locale: string) => void;
17
+ }
18
+
19
+ interface UseBladeMultilanguageReturn {
20
+ languageOptionsWithFlags: Ref<LanguageOptionWithFlag[]>;
21
+ currentLanguageOption: Ref<LanguageOptionWithFlag | undefined>;
22
+ isLoadingFlags: Ref<boolean>;
23
+ setLocale: (locale: string) => void;
24
+ isMultilanguage: Ref<boolean>;
25
+ }
26
+
27
+ /**
28
+ * Composable for preparing data for the language switcher in blades.
29
+ * @param {UseBladeMultilanguageParams} params - Parameters including languages, current locale, and a function to set it.
30
+ * @returns {UseBladeMultilanguageReturn} - Reactive data and actions for use in DataContext.
31
+ */
32
+ export function useBladeMultilanguage({
33
+ localesOptions,
34
+ currentLocale,
35
+ setLocale,
36
+ }: UseBladeMultilanguageParams): UseBladeMultilanguageReturn {
37
+ const { getFlag } = useLanguages();
38
+
39
+ const languageOptionsWithFlags = ref<LanguageOptionWithFlag[]>([]);
40
+ const isLoadingFlags = ref(false);
41
+
42
+ const isMultilanguage = computed(() => localesOptions.value.length > 1);
43
+
44
+ watchEffect(async () => {
45
+ if (!isMultilanguage.value) {
46
+ languageOptionsWithFlags.value = [];
47
+ return;
48
+ }
49
+
50
+ isLoadingFlags.value = true;
51
+ const options = await Promise.all(
52
+ localesOptions.value.map(async (lang) => ({
53
+ ...lang,
54
+ flag: await getFlag(lang.value ?? ""),
55
+ })),
56
+ );
57
+
58
+ console.log("options", options);
59
+
60
+ languageOptionsWithFlags.value = options;
61
+ isLoadingFlags.value = false;
62
+ });
63
+
64
+ const currentLanguageOption = computed(() => {
65
+ return languageOptionsWithFlags.value.find((lang) => lang.value === currentLocale.value);
66
+ });
67
+
68
+ return {
69
+ languageOptionsWithFlags,
70
+ currentLanguageOption,
71
+ isLoadingFlags,
72
+ setLocale,
73
+ isMultilanguage,
74
+ };
75
+ }
@@ -0,0 +1,111 @@
1
+ import { computed, inject, onMounted, watchEffect, Ref, ComputedRef } from "vue";
2
+ import { WidgetServiceKey, BladeInstance } from "../../injection-keys";
3
+ import { IWidget, IExternalWidgetRegistration } from "../../core/services/widget-service";
4
+
5
+ export interface UseExternalWidgetsOptions {
6
+ bladeType: string;
7
+ bladeData: Ref<Record<string, unknown>> | ComputedRef<Record<string, unknown>>;
8
+ autoRegister?: boolean; // Automatic registration when mounted
9
+ autoUpdateProps?: boolean; // Automatic update of props when data changes
10
+ }
11
+
12
+ export function useExternalWidgets(options: UseExternalWidgetsOptions) {
13
+ const { bladeType, bladeData, autoRegister = true, autoUpdateProps = true } = options;
14
+
15
+ const widgetService = inject(WidgetServiceKey);
16
+ const blade = inject(BladeInstance);
17
+
18
+ const registeredExternalWidgetIds = new Set<string>();
19
+
20
+ const registerExternalWidgets = () => {
21
+ if (!widgetService || !blade?.value.id) {
22
+ console.warn("Widget service or blade ID not available");
23
+ return;
24
+ }
25
+
26
+ const externalWidgets = widgetService.getExternalWidgetsForBlade(bladeType);
27
+
28
+ externalWidgets.forEach((externalWidget) => {
29
+ // Check if the widget is already registered
30
+ if (registeredExternalWidgetIds.has(externalWidget.id)) {
31
+ return;
32
+ }
33
+
34
+ const widget: IWidget = {
35
+ id: externalWidget.id,
36
+ component: externalWidget.component,
37
+ config: externalWidget.config,
38
+ isVisible: externalWidget.isVisible,
39
+ title: externalWidget.title,
40
+ updateFunctionName: externalWidget.updateFunctionName,
41
+ // Initially allow props
42
+ props: widgetService.resolveWidgetProps(
43
+ { id: externalWidget.id, component: externalWidget.component, config: externalWidget.config },
44
+ bladeData.value,
45
+ ),
46
+ };
47
+
48
+ try {
49
+ widgetService.registerWidget(widget, blade.value.id);
50
+ registeredExternalWidgetIds.add(externalWidget.id);
51
+ } catch (error) {
52
+ console.error(`Failed to register external widget '${externalWidget.id}':`, error);
53
+ }
54
+ });
55
+ };
56
+
57
+ // Update widget props when blade data changes
58
+ const updateWidgetProps = () => {
59
+ if (!widgetService || !blade?.value.id) return;
60
+
61
+ const widgets = widgetService.getWidgets(blade.value.id);
62
+
63
+ widgets.forEach((widget) => {
64
+ if (widget.config && registeredExternalWidgetIds.has(widget.id)) {
65
+ try {
66
+ const resolvedProps = widgetService.resolveWidgetProps(widget, bladeData.value);
67
+
68
+ widgetService.updateWidget({
69
+ id: widget.id,
70
+ bladeId: blade.value.id,
71
+ widget: { props: resolvedProps },
72
+ });
73
+ } catch (error) {
74
+ console.error(`Failed to update props for widget '${widget.id}':`, error);
75
+ }
76
+ }
77
+ });
78
+ };
79
+
80
+ // Unregister external widgets when unmounted
81
+ const unregisterExternalWidgets = () => {
82
+ if (!widgetService || !blade?.value.id) return;
83
+
84
+ registeredExternalWidgetIds.forEach((widgetId) => {
85
+ try {
86
+ widgetService.unregisterWidget(widgetId, blade.value.id);
87
+ } catch (error) {
88
+ console.error(`Failed to unregister external widget '${widgetId}':`, error);
89
+ }
90
+ });
91
+
92
+ registeredExternalWidgetIds.clear();
93
+ };
94
+
95
+ // Automatic registration when mounted
96
+ if (autoRegister) {
97
+ onMounted(registerExternalWidgets);
98
+ }
99
+
100
+ // Automatic update of props when blade data changes
101
+ if (autoUpdateProps) {
102
+ watchEffect(updateWidgetProps);
103
+ }
104
+
105
+ return {
106
+ registerExternalWidgets,
107
+ updateWidgetProps,
108
+ unregisterExternalWidgets,
109
+ registeredExternalWidgetIds: computed(() => Array.from(registeredExternalWidgetIds)),
110
+ };
111
+ }
@@ -119,7 +119,7 @@ watch(
119
119
  }
120
120
 
121
121
  &__more {
122
- @apply tw-flex tw-items-center tw-gap-2 tw-px-2 tw-cursor-pointer tw-text-[var(--blade-toolbar-desktop-more-color)] tw-flex-col;
122
+ @apply tw-flex tw-items-center tw-gap-1 tw-px-2 tw-cursor-pointer tw-text-[var(--blade-toolbar-desktop-more-color)] tw-flex-col;
123
123
 
124
124
  &-text {
125
125
  @apply tw-text-xs;