@tmlmobilidade/ui 20250725.48.15 → 20250725.125.38

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 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  import { j as jsxRuntimeExports } from '../../../../_virtual/jsx-runtime.js';
2
3
  import { useMeContext } from '../../../contexts/Me.context.js';
3
4
 
@@ -6,14 +7,14 @@ function HasPermission({ action, children, resource_key, scope, value }) {
6
7
  //
7
8
  //
8
9
  // A. Setup variables
9
- const { actions } = useMeContext();
10
+ const meContext = useMeContext();
10
11
  //
11
12
  // B. Render components
12
13
  if (!resource_key && !value) {
13
14
  console.log('hasPermission', scope, action);
14
- return actions.hasPermission(scope, action) ? jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children }) : null;
15
+ return meContext.actions.hasPermission(scope, action) ? jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children }) : null;
15
16
  }
16
- if (actions.hasPermissionResource({ action, resource_key: resource_key ?? '', scope, value: value ?? '' })) {
17
+ if (meContext.actions.hasPermissionResource({ action, resource_key: resource_key ?? '', scope, value: value ?? '' })) {
17
18
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
18
19
  }
19
20
  return null;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/components/authentication/HasPermission/index.tsx"],"sourcesContent":[null],"names":["_jsx","_Fragment"],"mappings":";;;;AA0BA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAEM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAU,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAoC,CAAA,CAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQ,CAAA,CAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAY,CAAA,CAAE,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAE,CAAA,CAAA,CAAA,CAAA,CAAK,EAA8B,CAAA,CAAA;;;;AAM5I,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAY,CAAA,CAAE;;;AAKhC,CAAA,CAAA,CAAA,CAAA,IAAI,CAAC,CA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K,CAAA,CAAE,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAE,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAI,CAAA,CAAE,CAAA,CAAE,CAAC,CAAA,CAAE;QACrH,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAOA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA,CAAAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQ,CAAA,CAAA,CAAI;IACvB;AAEA,CAAA,CAAA,CAAA,CAAA,OAAO,CAAA,CAAA,CAAA,CAAI;;AAGZ;;"}
@@ -0,0 +1,20 @@
1
+ 'use client';
2
+ import { useMeContext } from '../../../contexts/Me.context.js';
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":";;;AAOA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAEM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAU,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAe,CAAC,CAAA,CAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQ,EAAqB,CAAA,CAAA;;;;AAM9D,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAY,CAAA,CAAE;;;AAKhC,CAAA,CAAA,CAAA,CAAA,IAAI,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAC,CAAA,CAAA,CAAA,CAAI,CAAC,IAAI,CAAA,CAAE;AACzB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,OAAO,CAAA,CAAA,CAAA,CAAI;IACZ;AAEA,CAAA,CAAA,CAAA,CAAA,OAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQ;;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. Define actions
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
- // C. Render components
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.48.15",
4
+ "version": "20250725.125.38",
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;;;;"}