@odigos/ui-kit 0.0.17 → 0.0.18

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.
@@ -1,211 +0,0 @@
1
- import { c as create } from './react-CjImwkhV.js';
2
- import { g as getEntityId, i as isTimeElapsed } from './index-BQs4sULy.js';
3
- import { E as EntityTypes } from './index-BVVVevuY.js';
4
-
5
- const useDrawerStore = create((set) => ({
6
- drawerType: null,
7
- drawerEntityId: null,
8
- setDrawerType: (value) => set({ drawerType: value }),
9
- setDrawerEntityId: (value) => set({ drawerEntityId: value }),
10
- }));
11
-
12
- const useEntityStore = create((set) => ({
13
- namespacesLoading: false,
14
- namespaces: [],
15
- sourcesLoading: false,
16
- sources: [],
17
- destinationsLoading: false,
18
- destinations: [],
19
- actionsLoading: false,
20
- actions: [],
21
- instrumentationRulesLoading: false,
22
- instrumentationRules: [],
23
- setEntitiesLoading: (entityType, bool) => {
24
- const KEY = entityType === EntityTypes.Namespace
25
- ? 'namespacesLoading'
26
- : entityType === EntityTypes.Source
27
- ? 'sourcesLoading'
28
- : entityType === EntityTypes.Destination
29
- ? 'destinationsLoading'
30
- : entityType === EntityTypes.Action
31
- ? 'actionsLoading'
32
- : entityType === EntityTypes.InstrumentationRule
33
- ? 'instrumentationRulesLoading'
34
- : 'NONE';
35
- if (KEY === 'NONE')
36
- return;
37
- set({ [KEY]: bool });
38
- },
39
- setEntities: (entityType, payload) => {
40
- const KEY = entityType === EntityTypes.Namespace
41
- ? 'namespaces'
42
- : entityType === EntityTypes.Source
43
- ? 'sources'
44
- : entityType === EntityTypes.Destination
45
- ? 'destinations'
46
- : entityType === EntityTypes.Action
47
- ? 'actions'
48
- : entityType === EntityTypes.InstrumentationRule
49
- ? 'instrumentationRules'
50
- : 'NONE';
51
- if (KEY === 'NONE')
52
- return;
53
- set({ [KEY]: payload });
54
- },
55
- addEntities: (entityType, entities) => {
56
- const KEY = entityType === EntityTypes.Namespace
57
- ? 'namespaces'
58
- : entityType === EntityTypes.Source
59
- ? 'sources'
60
- : entityType === EntityTypes.Destination
61
- ? 'destinations'
62
- : entityType === EntityTypes.Action
63
- ? 'actions'
64
- : entityType === EntityTypes.InstrumentationRule
65
- ? 'instrumentationRules'
66
- : 'NONE';
67
- if (KEY === 'NONE')
68
- return;
69
- set((state) => {
70
- const prev = [...state[KEY]];
71
- entities.forEach((newItem) => {
72
- const foundIdx = prev.findIndex((oldItem) => JSON.stringify(getEntityId(oldItem)) === JSON.stringify(getEntityId(newItem)));
73
- if (foundIdx !== -1) {
74
- prev[foundIdx] = { ...prev[foundIdx], ...newItem };
75
- }
76
- else {
77
- prev.push(newItem);
78
- }
79
- });
80
- return { [KEY]: prev };
81
- });
82
- },
83
- removeEntities: (entityType, entityIds) => {
84
- const KEY = entityType === EntityTypes.Namespace
85
- ? 'namespaces'
86
- : entityType === EntityTypes.Source
87
- ? 'sources'
88
- : entityType === EntityTypes.Destination
89
- ? 'destinations'
90
- : entityType === EntityTypes.Action
91
- ? 'actions'
92
- : entityType === EntityTypes.InstrumentationRule
93
- ? 'instrumentationRules'
94
- : 'NONE';
95
- if (KEY === 'NONE')
96
- return;
97
- set((state) => {
98
- const prev = [...state[KEY]];
99
- entityIds.forEach((id) => {
100
- const foundIdx = prev.findIndex((entity) => entityType === EntityTypes.Source ? JSON.stringify(getEntityId(entity)) === JSON.stringify(getEntityId(id)) : getEntityId(entity) === id);
101
- if (foundIdx !== -1) {
102
- prev.splice(foundIdx, 1);
103
- }
104
- });
105
- return { [KEY]: prev };
106
- });
107
- },
108
- resetEntityStore: () => {
109
- set({
110
- namespacesLoading: false,
111
- namespaces: [],
112
- sourcesLoading: false,
113
- sources: [],
114
- destinationsLoading: false,
115
- destinations: [],
116
- actionsLoading: false,
117
- actions: [],
118
- instrumentationRulesLoading: false,
119
- instrumentationRules: [],
120
- });
121
- },
122
- }));
123
-
124
- const useModalStore = create((set) => ({
125
- currentModal: '',
126
- setCurrentModal: (str) => set({ currentModal: str }),
127
- }));
128
-
129
- const useNotificationStore = create((set, get) => ({
130
- notifications: [],
131
- addNotification: (notif) => {
132
- const date = new Date();
133
- const id = `${date.getTime().toString()}${!!notif.target ? `#${notif.target}` : ''}`;
134
- // This is to prevent duplicate notifications within a 10 second time-frame.
135
- // This is useful for notifications that are triggered multiple times in a short period, like failed API queries...
136
- const foundThisNotif = !!get().notifications.find((n) => n.type === notif.type && n.title === notif.title && n.message === notif.message && !isTimeElapsed(n.time, 3000)); // 3 seconds
137
- if (!foundThisNotif) {
138
- set((state) => ({
139
- notifications: [
140
- {
141
- ...notif,
142
- id,
143
- time: date.toISOString(),
144
- dismissed: false,
145
- seen: false,
146
- },
147
- ...state.notifications,
148
- ],
149
- }));
150
- }
151
- },
152
- markAsDismissed: (id) => {
153
- set((state) => {
154
- const foundIdx = state.notifications.findIndex((notif) => notif.id === id);
155
- if (foundIdx !== -1) {
156
- state.notifications[foundIdx].dismissed = true;
157
- }
158
- return {
159
- notifications: state.notifications,
160
- };
161
- });
162
- },
163
- markAsSeen: (id) => {
164
- set((state) => {
165
- const foundIdx = state.notifications.findIndex((notif) => notif.id === id);
166
- if (foundIdx !== -1) {
167
- state.notifications[foundIdx].seen = true;
168
- }
169
- return {
170
- notifications: state.notifications,
171
- };
172
- });
173
- },
174
- removeNotification: (id) => {
175
- set((state) => {
176
- const foundIdx = state.notifications.findIndex((notif) => notif.id === id);
177
- if (foundIdx !== -1) {
178
- state.notifications.splice(foundIdx, 1);
179
- }
180
- return {
181
- notifications: state.notifications,
182
- };
183
- });
184
- },
185
- removeNotifications: (target) => {
186
- if (!target)
187
- return;
188
- set((state) => {
189
- const filtered = state.notifications.filter((notif) => notif.id.split('#')[1] !== target);
190
- return {
191
- notifications: filtered,
192
- };
193
- });
194
- },
195
- }));
196
-
197
- const useSetupStore = create((set) => ({
198
- availableSources: {},
199
- configuredSources: {},
200
- configuredFutureApps: {},
201
- configuredDestinations: [],
202
- setAvailableSources: (payload) => set({ availableSources: payload }),
203
- setConfiguredSources: (payload) => set({ configuredSources: payload }),
204
- setConfiguredFutureApps: (payload) => set({ configuredFutureApps: payload }),
205
- setConfiguredDestinations: (payload) => set({ configuredDestinations: payload }),
206
- addConfiguredDestination: (payload) => set((state) => ({ configuredDestinations: [...state.configuredDestinations, payload] })),
207
- removeConfiguredDestination: (payload) => set((state) => ({ configuredDestinations: state.configuredDestinations.filter(({ stored }) => stored.type !== payload.type) })),
208
- resetState: () => set(() => ({ availableSources: {}, configuredSources: {}, configuredFutureApps: {}, configuredDestinations: [] })),
209
- }));
210
-
211
- export { useEntityStore as a, useModalStore as b, useNotificationStore as c, useSetupStore as d, useDrawerStore as u };
@@ -1,128 +0,0 @@
1
- import React, { useRef, useState, useEffect, useCallback } from 'react';
2
- import styled from 'styled-components';
3
-
4
- const useContainerSize = () => {
5
- const ref = useRef(null);
6
- const [width, setWidth] = useState(0);
7
- const [height, setHeight] = useState(0);
8
- useEffect(() => {
9
- const resize = () => {
10
- if (ref.current) {
11
- const { width, height } = ref.current.getBoundingClientRect();
12
- setWidth(width);
13
- setHeight(height);
14
- }
15
- };
16
- resize();
17
- window.addEventListener('resize', resize);
18
- return () => window.removeEventListener('resize', resize);
19
- }, []);
20
- return {
21
- containerRef: ref,
22
- containerWidth: width,
23
- containerHeight: height,
24
- };
25
- };
26
-
27
- const useCopy = () => {
28
- const [isCopied, setIsCopied] = useState(false);
29
- const [copiedIndex, setCopiedIndex] = useState(-1);
30
- const clickCopy = async (str, idx) => {
31
- if (!isCopied) {
32
- setIsCopied(true);
33
- if (idx !== undefined)
34
- setCopiedIndex(idx);
35
- if (navigator?.clipboard && navigator.clipboard.writeText) {
36
- try {
37
- await navigator.clipboard.writeText(str);
38
- }
39
- catch (err) {
40
- console.error('Clipboard write failed:', err);
41
- }
42
- }
43
- else {
44
- // Fallback: Create a temporary textarea
45
- const textArea = document.createElement('textarea');
46
- textArea.value = str;
47
- document.body.appendChild(textArea);
48
- textArea.select();
49
- try {
50
- document.execCommand('copy');
51
- }
52
- catch (err) {
53
- console.error('execCommand copy failed:', err);
54
- }
55
- document.body.removeChild(textArea);
56
- }
57
- setTimeout(() => {
58
- setIsCopied(false);
59
- setCopiedIndex(-1);
60
- }, 1000);
61
- }
62
- };
63
- return { isCopied, copiedIndex, clickCopy };
64
- };
65
-
66
- const useKeyDown = ({ active, key, withAltKey, withCtrlKey, withShiftKey, withMetaKey }, callback) => {
67
- useEffect(() => {
68
- const handleKeyDown = (e) => {
69
- if (active &&
70
- key === e.key &&
71
- (!withAltKey || (withAltKey && e.altKey)) &&
72
- (!withCtrlKey || (withCtrlKey && e.ctrlKey)) &&
73
- (!withShiftKey || (withShiftKey && e.shiftKey)) &&
74
- (!withMetaKey || (withMetaKey && e.metaKey))) {
75
- e.preventDefault();
76
- e.stopPropagation();
77
- callback(e);
78
- }
79
- };
80
- window.addEventListener('keydown', handleKeyDown);
81
- return () => {
82
- window.removeEventListener('keydown', handleKeyDown);
83
- };
84
- }, [key, active, withAltKey, withCtrlKey, withShiftKey, withMetaKey, callback]);
85
- return null;
86
- };
87
-
88
- const useOnClickOutside = (ref, handler) => {
89
- useEffect(() => {
90
- const listener = (event) => {
91
- // Do nothing if clicking ref's element or descendent elements
92
- if (!ref.current || ref.current.contains(event.target)) {
93
- return;
94
- }
95
- handler();
96
- };
97
- document.addEventListener('mousedown', listener);
98
- document.addEventListener('touchstart', listener);
99
- return () => {
100
- document.removeEventListener('mousedown', listener);
101
- document.removeEventListener('touchstart', listener);
102
- };
103
- }, [ref, handler]);
104
- };
105
-
106
- const useTransition = ({ container, animateIn, animateOut, duration = 300 }) => {
107
- const Animated = styled(container) `
108
- animation-name: ${({ $isEntering, $isLeaving }) => ($isEntering ? animateIn : $isLeaving ? animateOut : 'none')};
109
- animation-duration: ${duration}ms;
110
- animation-fill-mode: forwards;
111
- `;
112
- // !! Do not deprecate this "useCallback" hook, it is necessary for the transition to work properly
113
- const Transition = useCallback(({ children, enter, ...props }) => {
114
- const [mounted, setMounted] = useState(false);
115
- useEffect(() => {
116
- const t = setTimeout(() => setMounted(enter), duration + 50); // +50ms to ensure the animation is finished
117
- return () => clearTimeout(t);
118
- }, [enter, duration]);
119
- if (!enter && !mounted)
120
- return null;
121
- return (React.createElement(Animated, { "$isEntering": enter, "$isLeaving": !enter && mounted, ...props }, children));
122
- },
123
- // !! Do not add dependencies here, it will cause re-renders which we want to avoid
124
- []);
125
- return Transition;
126
- };
127
-
128
- export { useCopy as a, useKeyDown as b, useOnClickOutside as c, useTransition as d, useContainerSize as u };