@tmlmobilidade/ui 20250725.32.7 → 20250725.123.30
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 +19 -17
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/src/components/{common → authentication}/HasPermission/index.js +3 -3
- package/dist/src/components/authentication/HasPermission/index.js.map +1 -0
- package/dist/src/components/authentication/IsAuthenticated/index.js +20 -0
- package/dist/src/components/authentication/IsAuthenticated/index.js.map +1 -0
- package/dist/src/components/upload/FileUpload/index.js +1 -1
- package/dist/src/contexts/Me.context.js +2 -2
- package/package.json +1 -1
- package/dist/src/components/common/HasPermission/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,24 @@ export { zod4Resolver, zodResolver } from 'mantine-form-zod-resolver';
|
|
|
16
16
|
|
|
17
17
|
declare function AppProvider({ children }: PropsWithChildren): react_jsx_runtime.JSX.Element;
|
|
18
18
|
|
|
19
|
+
interface HasPermissionProps {
|
|
20
|
+
action: string;
|
|
21
|
+
children: React.ReactNode;
|
|
22
|
+
scope: string;
|
|
23
|
+
}
|
|
24
|
+
interface ResourceKeyAndValue<T> {
|
|
25
|
+
resource_key: keyof T;
|
|
26
|
+
value: string;
|
|
27
|
+
}
|
|
28
|
+
interface NoResourceKeyOrValue {
|
|
29
|
+
resource_key?: never;
|
|
30
|
+
value?: never;
|
|
31
|
+
}
|
|
32
|
+
type HasPermissionFinalProps<T> = HasPermissionProps & (NoResourceKeyOrValue | ResourceKeyAndValue<T>);
|
|
33
|
+
declare function HasPermission<T extends Record<string, unknown>>({ action, children, resource_key, scope, value }: HasPermissionFinalProps<T>): react_jsx_runtime.JSX.Element | null;
|
|
34
|
+
|
|
35
|
+
declare function IsAuthenticated({ children }: PropsWithChildren): React$1.ReactNode;
|
|
36
|
+
|
|
19
37
|
interface BackButtonProps {
|
|
20
38
|
onClick?: () => void;
|
|
21
39
|
type?: 'back' | 'close';
|
|
@@ -225,22 +243,6 @@ declare namespace Checkbox {
|
|
|
225
243
|
var Group: (props: CheckboxGroupProps$1) => react_jsx_runtime.JSX.Element;
|
|
226
244
|
}
|
|
227
245
|
|
|
228
|
-
interface HasPermissionProps {
|
|
229
|
-
action: string;
|
|
230
|
-
children: React.ReactNode;
|
|
231
|
-
scope: string;
|
|
232
|
-
}
|
|
233
|
-
interface ResourceKeyAndValue<T> {
|
|
234
|
-
resource_key: keyof T;
|
|
235
|
-
value: string;
|
|
236
|
-
}
|
|
237
|
-
interface NoResourceKeyOrValue {
|
|
238
|
-
resource_key?: never;
|
|
239
|
-
value?: never;
|
|
240
|
-
}
|
|
241
|
-
type HasPermissionFinalProps<T> = HasPermissionProps & (NoResourceKeyOrValue | ResourceKeyAndValue<T>);
|
|
242
|
-
declare function HasPermission<T extends Record<string, unknown>>({ action, children, resource_key, scope, value }: HasPermissionFinalProps<T>): react_jsx_runtime.JSX.Element | null;
|
|
243
|
-
|
|
244
246
|
type PopoverProps = PopoverProps$1;
|
|
245
247
|
type PopoverTargetProps = PopoverTargetProps$1;
|
|
246
248
|
type PopoverDropdownProps = PopoverDropdownProps$1;
|
|
@@ -908,5 +910,5 @@ declare const getBaseGeoJsonFeatureLineString: () => GeoJSON.Feature<GeoJSON.Lin
|
|
|
908
910
|
*/
|
|
909
911
|
declare const getBaseGeoJsonFeatureCollection: () => GeoJSON.FeatureCollection<GeoJSON.LineString | GeoJSON.Point, GeoJSON.GeoJsonProperties>;
|
|
910
912
|
|
|
911
|
-
export { AVAILABLE_THEMES, AlertCard, AlertMessage, AppProvider, AppWrapper, BackButton, Badge, Button, CMIcon, CMLogo, Checkbox, Collapsible, ComboboxComponent as Combobox, ComponentWrapper, DataTable, DatePicker, DateTimePicker, DeleteButton, Description, Divider, ErrorDisplay, FileButton, FileUpload, FilterMenu, FilterMenuTarget, FiltersBar, Grid, HasPermission, Indicator, Label, Loader, LoadingOverlay, LockButton, MapOptionsContextProvider, MapView, MapViewStyleActiveStops, MapViewStyleActiveStopsInteractiveLayerId, MapViewStyleActiveStopsPrimaryLayerId, MapViewStylePath, MapViewStylePathInteractiveLayerId, MapViewStylePathPrimaryLayerId, MapViewStyleStops, MapViewStyleStopsInteractiveLayerId, MapViewStyleStopsPrimaryLayerId, MapViewStyleVehicles, MapViewStyleVehiclesInteractiveLayerId, MapViewStyleVehiclesPrimaryLayerId, MeContextProvider, Menu, MultiSelect, NoDataLabel, NumberInput, Pane, PanesManager, PasswordInput, Popover, SearchInput, Section, SegmentedControl, Sidebar, SidebarContextProvider, SidebarItem, SidebarSubItem, Slider, Spacer, Surface, Switch, TMLogo, TMLogoDark, TMLogoLight, Tag, TagGroup, Text, TextInput, Textarea, ThemeContextProvider, ThemeDark, ThemeLight, ThemeSwitcher, Themer, Tooltip, ValueDisplay, accessorSearch, centerMap, getBaseGeoJsonFeatureCollection, getBaseGeoJsonFeatureLineString, moveMap, plainSearch, sidebarApps, useIsActiveDomain, useIsActivePage, useMapOptionsContext, useMeContext, useScreenSize, useSearch, useSidebarContext, useThemeContext, useToast };
|
|
913
|
+
export { AVAILABLE_THEMES, AlertCard, AlertMessage, AppProvider, AppWrapper, BackButton, Badge, Button, CMIcon, CMLogo, Checkbox, Collapsible, ComboboxComponent as Combobox, ComponentWrapper, DataTable, DatePicker, DateTimePicker, DeleteButton, Description, Divider, ErrorDisplay, FileButton, FileUpload, FilterMenu, FilterMenuTarget, FiltersBar, Grid, HasPermission, Indicator, IsAuthenticated, Label, Loader, LoadingOverlay, LockButton, MapOptionsContextProvider, MapView, MapViewStyleActiveStops, MapViewStyleActiveStopsInteractiveLayerId, MapViewStyleActiveStopsPrimaryLayerId, MapViewStylePath, MapViewStylePathInteractiveLayerId, MapViewStylePathPrimaryLayerId, MapViewStyleStops, MapViewStyleStopsInteractiveLayerId, MapViewStyleStopsPrimaryLayerId, MapViewStyleVehicles, MapViewStyleVehiclesInteractiveLayerId, MapViewStyleVehiclesPrimaryLayerId, MeContextProvider, Menu, MultiSelect, NoDataLabel, NumberInput, Pane, PanesManager, PasswordInput, Popover, SearchInput, Section, SegmentedControl, Sidebar, SidebarContextProvider, SidebarItem, SidebarSubItem, Slider, Spacer, Surface, Switch, TMLogo, TMLogoDark, TMLogoLight, Tag, TagGroup, Text, TextInput, Textarea, ThemeContextProvider, ThemeDark, ThemeLight, ThemeSwitcher, Themer, Tooltip, ValueDisplay, accessorSearch, centerMap, getBaseGeoJsonFeatureCollection, getBaseGeoJsonFeatureLineString, moveMap, plainSearch, sidebarApps, useIsActiveDomain, useIsActivePage, useMapOptionsContext, useMeContext, useScreenSize, useSearch, useSidebarContext, useThemeContext, useToast };
|
|
912
914
|
export type { ButtonProps, CheckboxGroupProps, CheckboxProps, DataItem$1 as DataItem, DataTableColumn, DataTableProps, FileButtonProps, LabelProps, LoaderProps, MapStyle, NoDataLabelProps, NumberInputProps, PopoverDropdownProps, PopoverProps, PopoverTargetProps, SearchInputProps, SidebarItemProps, SidebarSubItemProps, SurfaceProps, TagGroupProps, TagProps, TextInputProps, TextProps, TextareaProps, ThemeType, ToastPromiseParams, ToastProps };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { AppProvider } from './src/components/AppProvider/index.js';
|
|
2
|
+
export { HasPermission } from './src/components/authentication/HasPermission/index.js';
|
|
3
|
+
export { IsAuthenticated } from './src/components/authentication/IsAuthenticated/index.js';
|
|
2
4
|
export { BackButton } from './src/components/buttons/BackButton/index.js';
|
|
3
5
|
export { Button } from './src/components/buttons/Button/index.js';
|
|
4
6
|
export { DeleteButton } from './src/components/buttons/DeleteButton/index.js';
|
|
@@ -15,7 +17,6 @@ export { default as SegmentedControl } from './src/components/common/SegmentedCo
|
|
|
15
17
|
export { default as Tooltip } from './src/components/common/Tooltip/index.js';
|
|
16
18
|
export { CMIcon, CMLogo, TMLogo, TMLogoDark, TMLogoLight } from './src/components/common/AppLogos/index.js';
|
|
17
19
|
export { Checkbox } from './src/components/common/Checkbox/index.js';
|
|
18
|
-
export { HasPermission } from './src/components/common/HasPermission/index.js';
|
|
19
20
|
export { Popover } from './src/components/common/Popover/index.js';
|
|
20
21
|
export { Slider } from './src/components/common/Slider/index.js';
|
|
21
22
|
export { Switch } from './src/components/common/Switch/index.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -6,14 +6,14 @@ function HasPermission({ action, children, resource_key, scope, value }) {
|
|
|
6
6
|
//
|
|
7
7
|
//
|
|
8
8
|
// A. Setup variables
|
|
9
|
-
const
|
|
9
|
+
const meContext = useMeContext();
|
|
10
10
|
//
|
|
11
11
|
// B. Render components
|
|
12
12
|
if (!resource_key && !value) {
|
|
13
13
|
console.log('hasPermission', scope, action);
|
|
14
|
-
return actions.hasPermission(scope, action) ? jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children }) : null;
|
|
14
|
+
return meContext.actions.hasPermission(scope, action) ? jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children }) : null;
|
|
15
15
|
}
|
|
16
|
-
if (actions.hasPermissionResource({ action, resource_key: resource_key ?? '', scope, value: value ?? '' })) {
|
|
16
|
+
if (meContext.actions.hasPermissionResource({ action, resource_key: resource_key ?? '', scope, value: value ?? '' })) {
|
|
17
17
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
18
18
|
}
|
|
19
19
|
return null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/components/authentication/HasPermission/index.tsx"],"sourcesContent":[null],"names":["_jsx","_Fragment"],"mappings":";;;AAwBA;AAEM,SAAU,aAAa,CAAoC,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,EAA8B,EAAA;;;;AAM5I,IAAA,MAAM,SAAS,GAAG,YAAY,EAAE;;;AAKhC,IAAA,IAAI,CAAC,YAAY,IAAI,CAAC,KAAK,EAAE;QAC5B,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,KAAK,EAAE,MAAM,CAAC;QAC3C,OAAO,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,GAAGA,8DAAG,QAAQ,EAAA,CAAI,GAAG,IAAI;IAC/E;IAEA,IAAI,SAAS,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,EAAE,CAAC,EAAE;QACrH,OAAOA,qBAAA,CAAAC,0BAAA,EAAA,EAAA,QAAA,EAAG,QAAQ,EAAA,CAAI;IACvB;AAEA,IAAA,OAAO,IAAI;;AAGZ;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useMeContext } from '../../../contexts/Me.context.js';
|
|
2
|
+
|
|
3
|
+
/* * */
|
|
4
|
+
/* * */
|
|
5
|
+
function IsAuthenticated({ children }) {
|
|
6
|
+
//
|
|
7
|
+
//
|
|
8
|
+
// A. Setup variables
|
|
9
|
+
const meContext = useMeContext();
|
|
10
|
+
//
|
|
11
|
+
// B. Render components
|
|
12
|
+
if (!meContext.data.user) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return children;
|
|
16
|
+
//
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { IsAuthenticated };
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/components/authentication/IsAuthenticated/index.tsx"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;AAKA;AAEM,SAAU,eAAe,CAAC,EAAE,QAAQ,EAAqB,EAAA;;;;AAM9D,IAAA,MAAM,SAAS,GAAG,YAAY,EAAE;;;AAKhC,IAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE;AACzB,QAAA,OAAO,IAAI;IACZ;AAEA,IAAA,OAAO,QAAQ;;AAGhB;;;;"}
|
|
@@ -12,10 +12,10 @@ import { Label } from '../../display/Label/index.js';
|
|
|
12
12
|
import { Section } from '../../layout/Section/index.js';
|
|
13
13
|
import '../../../contexts/Theme.context.js';
|
|
14
14
|
import '../../common/Checkbox/index.js';
|
|
15
|
-
import '../../../contexts/Me.context.js';
|
|
16
15
|
import '../../common/Popover/index.js';
|
|
17
16
|
import '@tmlmobilidade/lib';
|
|
18
17
|
import '../../sidebar/Sidebar/index.js';
|
|
18
|
+
import '../../../contexts/Me.context.js';
|
|
19
19
|
import { FileButton } from '../FileButton/index.js';
|
|
20
20
|
import '@tmlmobilidade/utils';
|
|
21
21
|
import '@mantine/hooks';
|
|
@@ -23,7 +23,7 @@ const MeContextProvider = ({ children }) => {
|
|
|
23
23
|
// A. Fetch data
|
|
24
24
|
const { data, error, isLoading } = useSWR(`${getAppConfig('auth', 'api_url')}/users/me`, swrFetcher);
|
|
25
25
|
//
|
|
26
|
-
// B.
|
|
26
|
+
// B. Handle actions
|
|
27
27
|
function hasPermission$1(scope, action) {
|
|
28
28
|
if (!data || !data.permissions)
|
|
29
29
|
return false;
|
|
@@ -65,7 +65,7 @@ const MeContextProvider = ({ children }) => {
|
|
|
65
65
|
},
|
|
66
66
|
}), [data, isLoading, error]);
|
|
67
67
|
//
|
|
68
|
-
//
|
|
68
|
+
// D. Render components
|
|
69
69
|
return (jsxRuntimeExports.jsx(MeContext.Provider, { value: contextValue, children: children }));
|
|
70
70
|
//
|
|
71
71
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmlmobilidade/ui",
|
|
3
3
|
"description": "UI components for Transportes Metropolitanos de Lisboa (TML) web applications.",
|
|
4
|
-
"version": "20250725.
|
|
4
|
+
"version": "20250725.123.30",
|
|
5
5
|
"author": "João de Vasconcelos & Jusi Monteiro",
|
|
6
6
|
"license": "AGPL-3.0-or-later",
|
|
7
7
|
"publishConfig": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../src/components/common/HasPermission/index.tsx"],"sourcesContent":[null],"names":["_jsx","_Fragment"],"mappings":";;;AAwBA;AAEM,SAAU,aAAa,CAAoC,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,EAA8B,EAAA;;;;AAM5I,IAAA,MAAM,EAAE,OAAO,EAAE,GAAG,YAAY,EAAE;;;AAKlC,IAAA,IAAI,CAAC,YAAY,IAAI,CAAC,KAAK,EAAE;QAC5B,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,KAAK,EAAE,MAAM,CAAC;AAC3C,QAAA,OAAO,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,GAAGA,8DAAG,QAAQ,EAAA,CAAI,GAAG,IAAI;IACrE;IAEA,IAAI,OAAO,CAAC,qBAAqB,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,EAAE,CAAC,EAAE;QAC3G,OAAOA,qBAAA,CAAAC,0BAAA,EAAA,EAAA,QAAA,EAAG,QAAQ,EAAA,CAAI;IACvB;AAEA,IAAA,OAAO,IAAI;;AAGZ;;;;"}
|