pankosmia-rcl 0.0.1 → 0.0.2

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,9 +1,9 @@
1
1
  {
2
2
  "name": "pankosmia-rcl",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "private": false,
5
5
  "homepage": "/clients/core-client-rcl",
6
- "main": "build/pankosmia-rcl.es.js",
6
+ "main": "src/rcl",
7
7
  "dependencies": {
8
8
  "@emotion/react": "^11.13.3",
9
9
  "@emotion/styled": "^11.13.0",
package/src/App.jsx ADDED
@@ -0,0 +1,38 @@
1
+ import { useEffect, useState, useCallback } from 'react';
2
+ import { Box } from "@mui/material";
3
+ import { InternetSwitchDemo } from './componentDemos';
4
+ import DialogExampleDemo from './componentDemos/DialogExampleDemo';
5
+ import Demos from './demoHelpers/Demos';
6
+ import Demo from './demoHelpers/Demo';
7
+ import DrawerDemo from './componentDemos/DrawerDemo';
8
+
9
+ function App() {
10
+ const [maxWindowHeight, setMaxWindowHeight] = useState(window.innerHeight - 64);
11
+ const handleWindowResize = useCallback(event => {
12
+ setMaxWindowHeight(window.innerHeight - 64);
13
+ }, []);
14
+
15
+ useEffect(() => {
16
+ window.addEventListener('resize', handleWindowResize);
17
+ return () => {
18
+ window.removeEventListener('resize', handleWindowResize);
19
+ };
20
+ }, [handleWindowResize]);
21
+
22
+ return <Box sx={{ maxHeight: maxWindowHeight }}>
23
+ <Demos>
24
+ <Demo title="InternetSwitch">
25
+ <InternetSwitchDemo />
26
+ </Demo>
27
+ <Demo title="Dialog">
28
+ <DialogExampleDemo />
29
+ </Demo>
30
+ <Demo title="Drawer">
31
+ <DrawerDemo />
32
+ </Demo>
33
+ </Demos>
34
+ </Box>
35
+
36
+ }
37
+
38
+ export default App;
@@ -0,0 +1,16 @@
1
+ import { useState } from "react";
2
+ import PanDialog from "../rcl/PanDialog";
3
+ import { Button } from "@mui/material";
4
+
5
+ export default function DialogExampleDemo() {
6
+ const [openDialog, setOpenDialog] = useState(null);
7
+ const contentOpenDialog = Boolean(openDialog)
8
+
9
+ return <>
10
+ <Button onClick={(event) => {
11
+ setOpenDialog(event.target)
12
+ }}> open dialog </Button>
13
+ <PanDialog open={contentOpenDialog} closeFn={() => setOpenDialog(false)} >test</PanDialog>
14
+ </>
15
+
16
+ }
@@ -0,0 +1,72 @@
1
+ import DrawerComponent from '../rcl/DrawerComponent';
2
+ import {useContext, useState, useEffect, useRef} from "react";
3
+ import {debugContext, getJson} from "pithekos-lib";
4
+
5
+
6
+ function DrawerDemo() {
7
+
8
+ const {debugRef} = useContext(debugContext);
9
+ const [drawerIsOpen, setDrawerIsOpen] = useState(false);
10
+ const [menuItems, setMenuItems] = useState([]);
11
+ const [showAdvanced, setShowAdvanced] = useState(true);
12
+ const [drawerWidth, setDrawerWidth] = useState('auto');
13
+ const [widthLocked, setWidthLocked] = useState(false);
14
+ const measurementRef = useRef(null);
15
+
16
+ useEffect(() => {
17
+ let timeoutId;
18
+ if (drawerIsOpen && !widthLocked) {
19
+ timeoutId = setTimeout(() => {
20
+ if (measurementRef.current) {
21
+ const width = measurementRef.current.clientWidth;
22
+
23
+ if (width > 0) {
24
+ setDrawerWidth(`${width}px`);
25
+ setWidthLocked(true);
26
+ }
27
+ }
28
+ }, 50);
29
+ return () => clearTimeout(timeoutId);
30
+ }
31
+ }, [drawerIsOpen, widthLocked]);
32
+
33
+ useEffect(
34
+ () => {
35
+ const doFetch = async () => {
36
+ const fetched = await getJson("/list-clients", debugRef.current);
37
+ if (fetched.ok) {
38
+ setMenuItems(
39
+ fetched.json.filter(
40
+ i => !i.exclude_from_menu && (debugRef.current || !i.requires.debug)
41
+ )
42
+ );
43
+ }
44
+ };
45
+ doFetch().then();
46
+ },
47
+ [debugRef.current]
48
+ );
49
+
50
+ const toggleDebug = (ev) => {
51
+ getJson(`/debug/${debugRef.current ? "disable" : "enable"}`)
52
+ .then(
53
+ () => {
54
+ ev.stopPropagation();
55
+ ev.preventDefault();
56
+ }
57
+ );
58
+ };
59
+
60
+ return <DrawerComponent
61
+ drawerIsOpen={drawerIsOpen}
62
+ setDrawerIsOpen={setDrawerIsOpen}
63
+ menuItems={menuItems}
64
+ toggleDebug={toggleDebug}
65
+ showAdvanced={showAdvanced}
66
+ setShowAdvanced={setShowAdvanced}
67
+ drawerWidth={drawerWidth}
68
+ measurementRef={measurementRef}
69
+ />
70
+ }
71
+
72
+ export default DrawerDemo;
@@ -0,0 +1,34 @@
1
+ import InternetSwitch from '../rcl/InternetSwitch';
2
+ import {useContext, useState} from "react";
3
+ import {debugContext, netContext, postEmptyJson} from "pithekos-lib";
4
+
5
+ function InternetSwitchDemo() {
6
+
7
+ const [internetDialogOpen, setInternetDialogOpen] = useState(false);
8
+ const {enabledRef} = useContext(netContext);
9
+ const {debugRef} = useContext(debugContext);
10
+
11
+ const disableInternet = () => {
12
+ postEmptyJson('/net/disable', debugRef.current)
13
+ };
14
+
15
+ const enableInternet = () => {
16
+ postEmptyJson('/net/enable', debugRef.current)
17
+ };
18
+ const handleInternetToggleClick = () => {
19
+ if (!enabledRef.current) {
20
+ setInternetDialogOpen(true);
21
+ } else {
22
+ disableInternet();
23
+ }
24
+ };
25
+
26
+ return <InternetSwitch
27
+ enableInternet={enableInternet}
28
+ handleInternetToggleClick={handleInternetToggleClick}
29
+ internetDialogOpen={internetDialogOpen}
30
+ setInternetDialogOpen={setInternetDialogOpen}
31
+ />
32
+ }
33
+
34
+ export default InternetSwitchDemo;
@@ -0,0 +1,3 @@
1
+ import InternetSwitchDemo from "./InternetSwitchDemo";
2
+
3
+ export {InternetSwitchDemo};
@@ -0,0 +1,10 @@
1
+ import { Grid2 } from "@mui/material";
2
+
3
+ export default function Demo({children,title}) {
4
+
5
+ return <Grid2 size={12} item sx={{ p: 2 }}>
6
+ <h1>{title}</h1>
7
+ {children}
8
+ </Grid2>
9
+ }
10
+
@@ -0,0 +1,9 @@
1
+ import { Grid2 } from "@mui/material";
2
+
3
+ export default function Demos({children}) {
4
+
5
+ return <Grid2 container spacing={2}>
6
+ {children}
7
+ </Grid2>
8
+ }
9
+
package/src/index.css ADDED
@@ -0,0 +1,15 @@
1
+ body {
2
+ margin: 0;
3
+ padding: 0;
4
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
5
+ 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
6
+ sans-serif;
7
+ -webkit-font-smoothing: antialiased;
8
+ -moz-osx-font-smoothing: grayscale;
9
+ overflow: hidden;
10
+ }
11
+
12
+ code {
13
+ font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
14
+ monospace;
15
+ }
package/src/index.jsx ADDED
@@ -0,0 +1,15 @@
1
+ import {createRoot} from "react-dom/client";
2
+ import {SpSpa} from "pithekos-lib";
3
+ import App from "./App";
4
+ import './index.css';
5
+
6
+ createRoot(document.getElementById("root"))
7
+ .render(
8
+ <SpSpa
9
+ requireNet={false}
10
+ titleKey="pages:core-client-rcl:title"
11
+ currentId="core-client-rcl"
12
+ >
13
+ <App/>
14
+ </SpSpa>
15
+ );
@@ -0,0 +1,15 @@
1
+ {
2
+ "short_name": "React App",
3
+ "name": "Create React App Sample",
4
+ "icons": [
5
+ {
6
+ "src": "favicon.ico",
7
+ "sizes": "64x64 32x32 24x24 16x16",
8
+ "type": "image/x-icon"
9
+ }
10
+ ],
11
+ "start_url": ".",
12
+ "display": "standalone",
13
+ "theme_color": "#000000",
14
+ "background_color": "#ffffff"
15
+ }
@@ -0,0 +1,128 @@
1
+ import React, {useContext} from 'react';
2
+ import {
3
+ Box,
4
+ Drawer,
5
+ Stack,
6
+ IconButton,
7
+ List,
8
+ ListItem,
9
+ ListItemButton, ListItemText,
10
+ Switch,
11
+ Collapse
12
+ } from "@mui/material";
13
+ import MenuIcon from "@mui/icons-material/Menu";
14
+ import ExpandLess from '@mui/icons-material/ExpandLess';
15
+ import ExpandMore from '@mui/icons-material/ExpandMore';
16
+
17
+ import {i18nContext, netContext, debugContext, doI18n} from "pithekos-lib";
18
+
19
+
20
+ export default function DrawerComponent({drawerIsOpen, setDrawerIsOpen, menuItems, toggleDebug, showAdvanced, setShowAdvanced, drawerWidth, measurementRef }) {
21
+
22
+ const {i18nRef} = useContext(i18nContext);
23
+ const {enabledRef} = useContext(netContext);
24
+ const {debugRef} = useContext(debugContext);
25
+
26
+ return (
27
+ <Box sx={{m: 0, mr: 2}}>
28
+ <IconButton onClick={e => setDrawerIsOpen(true)}>
29
+ <MenuIcon />
30
+ </IconButton>
31
+ <Drawer
32
+ open={drawerIsOpen}
33
+ onClose={() => setDrawerIsOpen(false)}
34
+ slotProps={{ paper: { sx: { width: drawerWidth, overflow: 'hidden' } } }}
35
+ >
36
+ <Box sx={{width: "100%", minHeight: '98vh', m: 0, p: 0}} role="presentation">
37
+ <List sx={{ height: '100%', width: '100%' }}>
38
+ <Stack
39
+ direction="column"
40
+ spacing={0}
41
+ sx={{
42
+ height: '100%',
43
+ width: '100%',
44
+ justifyContent: "space-between",
45
+ alignItems: "flex-start",
46
+ }}
47
+ >
48
+ <Box sx={{width: '100%'}}>
49
+ {
50
+ menuItems
51
+ .map(
52
+ (mi, n) => /* mi.id === currentId ?
53
+ <ListItem key={n} disablePadding onClick={() => setDrawerIsOpen(false)}>
54
+ <ListItemButton selected={true} >
55
+ <ListItemText
56
+ primary={doI18n(`pages:${mi.id}:title`, i18nRef.current)}/>
57
+ </ListItemButton>
58
+ </ListItem> : */
59
+ <ListItem key={n} disablePadding>
60
+ <ListItemButton
61
+ disabled={mi.requires.net && !enabledRef.current}
62
+ onClick={() => {
63
+ window.location.href = mi.url
64
+ }}
65
+ >
66
+ <ListItemText
67
+ primary={doI18n(`pages:${mi.id}:title`, i18nRef.current)}/>
68
+ </ListItemButton>
69
+ </ListItem>
70
+ )
71
+ }
72
+ </Box>
73
+ <Box>
74
+ <ListItem disablePadding >
75
+ <ListItemButton
76
+ /* selected={currentId.includes("settings")} */
77
+ onClick={ () => { window.location.href = "/clients/settings" }}
78
+ >
79
+ <ListItemText primary={doI18n("pages:core-settings:title", i18nRef.current)}/>
80
+ </ListItemButton>
81
+ </ListItem>
82
+ <ListItem sx={{width: drawerWidth}} disablePadding>
83
+ <ListItemButton onClick={() => setShowAdvanced(a => !a)}>
84
+ <ListItemText primary={doI18n(`components:header:advanced`, i18nRef.current)} />
85
+ {showAdvanced ? <ExpandLess /> : <ExpandMore />}
86
+ </ListItemButton>
87
+ </ListItem>
88
+ <Collapse in={showAdvanced} timeout="auto" unmountOnExit>
89
+ <List component="div" disablePadding>
90
+ <ListItemButton onClick={toggleDebug} sx={{ pl:4 }}>
91
+ <ListItemText primary={doI18n(`components:header:experimental_mode`, i18nRef.current)} />
92
+ <Switch
93
+ edge="end"
94
+ onChange={toggleDebug}
95
+ checked={debugRef.current}
96
+ />
97
+ </ListItemButton>
98
+ </List>
99
+ </Collapse>
100
+ <Box
101
+ ref={measurementRef}
102
+ sx={{
103
+ visibility: 'hidden',
104
+ position: 'absolute',
105
+ whiteSpace: 'nowrap',
106
+ top: 0,
107
+ left: 0,
108
+ }}
109
+ >
110
+ <List component="div" disablePadding>
111
+ <ListItemButton onClick={toggleDebug} sx={{ pl:4 }}>
112
+ <ListItemText primary={doI18n(`components:header:experimental_mode`, i18nRef.current)} />
113
+ <Switch
114
+ edge="end"
115
+ onChange={toggleDebug}
116
+ checked={debugRef.current}
117
+ />
118
+ </ListItemButton>
119
+ </List>
120
+ </Box>
121
+ </Box>
122
+ </Stack>
123
+ </List>
124
+ </Box>
125
+ </Drawer>
126
+ </Box>
127
+ )
128
+ }
@@ -0,0 +1,63 @@
1
+ import React, {useContext} from 'react';
2
+ import {
3
+ Box, Button,
4
+ Chip,
5
+ Dialog,
6
+ DialogActions,
7
+ DialogContent,
8
+ DialogContentText,
9
+ DialogTitle,
10
+ Typography
11
+ } from "@mui/material";
12
+ import AirplanemodeInactiveOutlinedIcon from '@mui/icons-material/AirplanemodeInactiveOutlined';
13
+ import AirplanemodeActiveOutlinedIcon from '@mui/icons-material/AirplanemodeActiveOutlined';
14
+ import {i18nContext, netContext, doI18n} from "pithekos-lib";
15
+
16
+
17
+ export default function InternetSwitch({enableInternet, handleInternetToggleClick, internetDialogOpen, setInternetDialogOpen}) {
18
+
19
+ const {i18nRef} = useContext(i18nContext);
20
+ const {enabledRef} = useContext(netContext);
21
+
22
+ const handleClose = () => {
23
+ setInternetDialogOpen(false);
24
+ };
25
+
26
+ return (
27
+ <Box>
28
+ <Chip
29
+ icon={enabledRef.current ? <AirplanemodeInactiveOutlinedIcon /> : <AirplanemodeActiveOutlinedIcon />}
30
+ label={doI18n("components:header:offline_mode", i18nRef.current)}
31
+ onClick={handleInternetToggleClick}
32
+ color={enabledRef.current ? "appbar-chip-inactive" : "secondary"}
33
+ variant="Filled"
34
+ />
35
+ <Dialog
36
+ open={internetDialogOpen}
37
+ onClose={handleClose}
38
+ slotProps={{
39
+ paper: {
40
+ component: 'form',
41
+
42
+ },
43
+ }}
44
+ >
45
+ <DialogTitle><b>{doI18n("components:header:internet_question_label", i18nRef.current)}</b></DialogTitle>
46
+ <DialogContent>
47
+ <DialogContentText>
48
+ <Typography>
49
+ {doI18n("components:header:internet_question", i18nRef.current)}tra la la
50
+ </Typography>
51
+ </DialogContentText>
52
+ </DialogContent>
53
+ <DialogActions>
54
+ <Button onClick={handleClose}>{doI18n("components:header:cancel", i18nRef.current)}</Button>
55
+ <Button onClick={() => {
56
+ enableInternet();
57
+ handleClose();
58
+ }}>{doI18n("components:header:accept", i18nRef.current)}</Button>
59
+ </DialogActions>
60
+ </Dialog>
61
+ </Box>
62
+ )
63
+ }
@@ -0,0 +1,31 @@
1
+ import { AppBar, Dialog, Toolbar, Typography } from "@mui/material";
2
+ import { i18nContext, doI18n } from "pithekos-lib";
3
+ import { useContext } from "react";
4
+ import PanDialogActions from "./PanDialogActions";
5
+ import PanDialogContent from "./PanDialogContent";
6
+
7
+ export default function PanDialog({ open, closeFn,children,createButtonDisabled=false }) {
8
+ const { i18nRef } = useContext(i18nContext);
9
+ return <Dialog
10
+ open={open}
11
+ onClose={closeFn}
12
+ slotProps={{
13
+ paper: {
14
+ component: 'form',
15
+ },
16
+ }}
17
+ >
18
+ <AppBar color='secondary' sx={{ position: 'relative', borderTopLeftRadius: 4, borderTopRightRadius: 4 }}>
19
+ <Toolbar>
20
+ <Typography variant="h6" component="div">
21
+ {doI18n("pages:content:restore_content", i18nRef.current)}
22
+ </Typography>
23
+
24
+ </Toolbar>
25
+ </AppBar>
26
+ <PanDialogContent>
27
+ {children}
28
+ </PanDialogContent>
29
+ <PanDialogActions closeFn={closeFn} createButtonDisabled={createButtonDisabled} />
30
+ </Dialog>;
31
+ }
@@ -0,0 +1,11 @@
1
+ import { DialogActions } from "@mui/material";
2
+ import PanDialogButton from "./PanDialogButton";
3
+
4
+ export default function PanDialogActions ({closeFn,createButtonDisabled}) {
5
+ return <>
6
+ <DialogActions>
7
+ <PanDialogButton closeFn={closeFn} createButtonDisabled={createButtonDisabled}/>
8
+ </DialogActions>
9
+ </>
10
+
11
+ }
@@ -0,0 +1,20 @@
1
+ import { Button } from "@mui/material";
2
+ import { i18nContext, doI18n } from "pithekos-lib";
3
+ import { useContext } from "react";
4
+
5
+ export default function PanDialogButton ({closeFn,createButtonDisabled}) {
6
+ const { i18nRef } = useContext(i18nContext);
7
+ return <>
8
+ <Button onClick={closeFn}>
9
+ {doI18n("pages:content:cancel", i18nRef.current)}
10
+ </Button>
11
+ <Button
12
+ variant='contained'
13
+ color="primary"
14
+ onClick={() => {
15
+ closeFn();
16
+ }}
17
+ disabled={createButtonDisabled}
18
+ >{doI18n("pages:content:accept", i18nRef.current)}</Button>
19
+ </>
20
+ }
@@ -0,0 +1,13 @@
1
+ import { DialogContent, DialogContentText, Typography } from "@mui/material";
2
+ import { i18nContext, doI18n } from "pithekos-lib";
3
+ import { useContext } from "react";
4
+ export default function PanDialogContent({children}) {
5
+ const { i18nRef } = useContext(i18nContext);
6
+ return <>
7
+ <DialogContent>
8
+ <DialogContentText>
9
+ {children}
10
+ </DialogContentText>
11
+ </DialogContent>
12
+ </>
13
+ }
@@ -0,0 +1,16 @@
1
+ import { AppBar, Dialog, Toolbar, Typography } from "@mui/material";
2
+ import { i18nContext, doI18n } from "pithekos-lib";
3
+ import { useContext } from "react";
4
+ import PanDialogActions from "./PanDialogActions";
5
+ import PanDialogContent from "./PanDialogContent";
6
+ import PanDialog from "./PanDialog";
7
+
8
+ export default function PanDialogDefault({ open, closeFn,children,createButtonDisabled=false }) {
9
+
10
+ return <PanDialog>
11
+ <PanDialogContent>
12
+ {children}
13
+ </PanDialogContent>
14
+ <PanDialogActions closeFn={closeFn} createButtonDisabled={createButtonDisabled} />
15
+ </PanDialog>;
16
+ }
@@ -0,0 +1,11 @@
1
+ import InternetSwitch from './InternetSwitch';
2
+ import PanDialog from './PanDialog';
3
+ import DrawerComponent from "./DrawerComponent";
4
+
5
+ const exports = {
6
+ InternetSwitch,
7
+ PanDialog,
8
+ DrawerComponent
9
+ };
10
+
11
+ export default exports;