@lnco-ai/ui 1.0.0
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/CHANGELOG.md +1323 -0
- package/LICENSE +661 -0
- package/README.md +60 -0
- package/dist/Authorization/PreventGuestWrapper.d.ts +19 -0
- package/dist/Authorization/PreventGuestWrapper.js +15 -0
- package/dist/Authorization/RedirectionContent.d.ts +9 -0
- package/dist/Authorization/RedirectionContent.js +24 -0
- package/dist/Authorization/SignedInWrapper.d.ts +10 -0
- package/dist/Authorization/SignedInWrapper.js +21 -0
- package/dist/Avatar/Avatar.d.ts +24 -0
- package/dist/Avatar/Avatar.js +22 -0
- package/dist/Avatar/stringToColor.d.ts +12 -0
- package/dist/Avatar/stringToColor.js +31 -0
- package/dist/Avatar/stringToColor.test.d.ts +1 -0
- package/dist/Avatar/stringToColor.test.js +8 -0
- package/dist/Card/Card.d.ts +39 -0
- package/dist/Card/Card.js +76 -0
- package/dist/Card/CardHeader.d.ts +12 -0
- package/dist/Card/CardHeader.js +8 -0
- package/dist/Card/CardThumbnail.d.ts +10 -0
- package/dist/Card/CardThumbnail.js +14 -0
- package/dist/Card/FolderCard.d.ts +14 -0
- package/dist/Card/FolderCard.js +44 -0
- package/dist/Card/LinkCard.d.ts +11 -0
- package/dist/Card/LinkCard.js +41 -0
- package/dist/Card/components/CardThumbnail.d.ts +8 -0
- package/dist/Card/components/CardThumbnail.js +15 -0
- package/dist/Card/constants.d.ts +1 -0
- package/dist/Card/constants.js +1 -0
- package/dist/Collapse/Collapse.d.ts +10 -0
- package/dist/Collapse/Collapse.js +48 -0
- package/dist/Collapse/withCollapse.d.ts +7 -0
- package/dist/Collapse/withCollapse.js +8 -0
- package/dist/CookiesBanner/CookiesBanner.d.ts +10 -0
- package/dist/CookiesBanner/CookiesBanner.js +60 -0
- package/dist/CreativeCommons/CreativeCommons.d.ts +14 -0
- package/dist/CreativeCommons/CreativeCommons.js +75 -0
- package/dist/CreativeCommons/icons/By.d.ts +3 -0
- package/dist/CreativeCommons/icons/By.js +3 -0
- package/dist/CreativeCommons/icons/CCIconsProps.d.ts +3 -0
- package/dist/CreativeCommons/icons/CCIconsProps.js +1 -0
- package/dist/CreativeCommons/icons/Cc.d.ts +3 -0
- package/dist/CreativeCommons/icons/Cc.js +3 -0
- package/dist/CreativeCommons/icons/Cc0.d.ts +3 -0
- package/dist/CreativeCommons/icons/Cc0.js +3 -0
- package/dist/CreativeCommons/icons/Nc.d.ts +3 -0
- package/dist/CreativeCommons/icons/Nc.js +3 -0
- package/dist/CreativeCommons/icons/Nd.d.ts +3 -0
- package/dist/CreativeCommons/icons/Nd.js +3 -0
- package/dist/CreativeCommons/icons/Sa.d.ts +3 -0
- package/dist/CreativeCommons/icons/Sa.js +3 -0
- package/dist/CustomInitialLoader/CustomInitialLoader.d.ts +5 -0
- package/dist/CustomInitialLoader/CustomInitialLoader.js +25 -0
- package/dist/DrawerHeader/DrawerHeader.d.ts +7 -0
- package/dist/DrawerHeader/DrawerHeader.js +16 -0
- package/dist/GraaspLogo/EpflLogo.d.ts +5 -0
- package/dist/GraaspLogo/EpflLogo.js +3 -0
- package/dist/GraaspLogo/GraaspLogo.d.ts +8 -0
- package/dist/GraaspLogo/GraaspLogo.js +5 -0
- package/dist/Header/Header.d.ts +21 -0
- package/dist/Header/Header.js +33 -0
- package/dist/HeaderUserInformation/HeaderUserInformation.d.ts +22 -0
- package/dist/HeaderUserInformation/HeaderUserInformation.js +23 -0
- package/dist/ItemBadges/ItemBadges.d.ts +17 -0
- package/dist/ItemBadges/ItemBadges.js +10 -0
- package/dist/ItemFlag/ItemFlagButton.d.ts +9 -0
- package/dist/ItemFlag/ItemFlagButton.js +11 -0
- package/dist/ItemFlag/ItemFlagDialog.d.ts +14 -0
- package/dist/ItemFlag/ItemFlagDialog.js +25 -0
- package/dist/Loader/Loader.d.ts +7 -0
- package/dist/Loader/Loader.js +4 -0
- package/dist/Main/LogoHeader.d.ts +2 -0
- package/dist/Main/LogoHeader.js +5 -0
- package/dist/Main/Main.d.ts +59 -0
- package/dist/Main/Main.js +82 -0
- package/dist/MainMenu/MainMenu.d.ts +10 -0
- package/dist/MainMenu/MainMenu.js +6 -0
- package/dist/MainMenu/MenuItem/MenuItem.d.ts +16 -0
- package/dist/MainMenu/MenuItem/MenuItem.js +16 -0
- package/dist/MainMenu/hooks.d.ts +10 -0
- package/dist/MainMenu/hooks.js +21 -0
- package/dist/Navigation/CurrentItemNavigation.d.ts +15 -0
- package/dist/Navigation/CurrentItemNavigation.js +12 -0
- package/dist/Navigation/ExtraItemsMenu.d.ts +10 -0
- package/dist/Navigation/ExtraItemsMenu.js +24 -0
- package/dist/Navigation/ExtraItemsNavigation.d.ts +11 -0
- package/dist/Navigation/ExtraItemsNavigation.js +11 -0
- package/dist/Navigation/HomeMenu.d.ts +17 -0
- package/dist/Navigation/HomeMenu.js +28 -0
- package/dist/Navigation/ItemMenu.d.ts +16 -0
- package/dist/Navigation/ItemMenu.js +32 -0
- package/dist/Navigation/Navigation.d.ts +26 -0
- package/dist/Navigation/Navigation.js +15 -0
- package/dist/Navigation/ParentsNavigation.d.ts +10 -0
- package/dist/Navigation/ParentsNavigation.js +8 -0
- package/dist/Navigation/common/CenterAlignWrapper.d.ts +3 -0
- package/dist/Navigation/common/CenterAlignWrapper.js +7 -0
- package/dist/Navigation/common/NavigationLink.d.ts +8 -0
- package/dist/Navigation/common/NavigationLink.js +7 -0
- package/dist/Navigation/common/constants.d.ts +1 -0
- package/dist/Navigation/common/constants.js +1 -0
- package/dist/PlatformSwitch/PlatformSwitch.d.ts +57 -0
- package/dist/PlatformSwitch/PlatformSwitch.js +66 -0
- package/dist/PlatformSwitch/hooks.d.ts +30 -0
- package/dist/PlatformSwitch/hooks.js +49 -0
- package/dist/SearchInput/SearchInput.d.ts +20 -0
- package/dist/SearchInput/SearchInput.js +14 -0
- package/dist/Select/Select.d.ts +24 -0
- package/dist/Select/Select.js +7 -0
- package/dist/Sidebar/Sidebar.d.ts +11 -0
- package/dist/Sidebar/Sidebar.js +25 -0
- package/dist/StyledComponents/StyledBaseComponents.d.ts +11 -0
- package/dist/StyledComponents/StyledBaseComponents.js +11 -0
- package/dist/TextDisplay/TextDisplay.d.ts +5 -0
- package/dist/TextDisplay/TextDisplay.js +24 -0
- package/dist/TextDisplay/fixtures.d.ts +3 -0
- package/dist/TextDisplay/fixtures.js +84 -0
- package/dist/TextDisplay/withFlavor.d.ts +8 -0
- package/dist/TextDisplay/withFlavor.js +25 -0
- package/dist/TextEditor/TextEditor.d.ts +16 -0
- package/dist/TextEditor/TextEditor.js +74 -0
- package/dist/ThemeContext/LanguageSelect.d.ts +15 -0
- package/dist/ThemeContext/LanguageSelect.js +19 -0
- package/dist/ThemeContext/ThemeContext.d.ts +22 -0
- package/dist/ThemeContext/ThemeContext.js +31 -0
- package/dist/Thumbnail/Thumbnail.d.ts +28 -0
- package/dist/Thumbnail/Thumbnail.js +27 -0
- package/dist/Tree/Breadcrumbs.d.ts +14 -0
- package/dist/Tree/Breadcrumbs.js +30 -0
- package/dist/Tree/RowMenu.d.ts +12 -0
- package/dist/Tree/RowMenu.js +37 -0
- package/dist/Tree/RowMenus.d.ts +18 -0
- package/dist/Tree/RowMenus.js +7 -0
- package/dist/Tree/types.d.ts +6 -0
- package/dist/Tree/types.js +1 -0
- package/dist/UserSwitch/UserSwitch.d.ts +17 -0
- package/dist/UserSwitch/UserSwitch.js +46 -0
- package/dist/UserSwitch/UserSwitchWrapper.d.ts +37 -0
- package/dist/UserSwitch/UserSwitchWrapper.js +74 -0
- package/dist/appComponents/ErrorFallback.d.ts +57 -0
- package/dist/appComponents/ErrorFallback.js +72 -0
- package/dist/appComponents/QuestionLabel.d.ts +9 -0
- package/dist/appComponents/QuestionLabel.js +4 -0
- package/dist/appComponents/index.d.ts +6 -0
- package/dist/appComponents/index.js +5 -0
- package/dist/appComponents/statusChips/RequiredChip.d.ts +3 -0
- package/dist/appComponents/statusChips/RequiredChip.js +5 -0
- package/dist/appComponents/statusChips/SavedChip.d.ts +3 -0
- package/dist/appComponents/statusChips/SavedChip.js +5 -0
- package/dist/appComponents/statusChips/SubmittedChip.d.ts +3 -0
- package/dist/appComponents/statusChips/SubmittedChip.js +5 -0
- package/dist/appComponents/statusChips/types.d.ts +5 -0
- package/dist/appComponents/statusChips/types.js +1 -0
- package/dist/appComponents/types.d.ts +8 -0
- package/dist/appComponents/types.js +1 -0
- package/dist/apps.d.ts +1 -0
- package/dist/apps.js +1 -0
- package/dist/buttons/BookmarkButton/BookmarkButton.d.ts +24 -0
- package/dist/buttons/BookmarkButton/BookmarkButton.js +24 -0
- package/dist/buttons/Button/Button.d.ts +37 -0
- package/dist/buttons/Button/Button.js +4 -0
- package/dist/buttons/ChatboxButton/ChatboxButton.d.ts +15 -0
- package/dist/buttons/ChatboxButton/ChatboxButton.js +21 -0
- package/dist/buttons/CopyButton/CopyButton.d.ts +13 -0
- package/dist/buttons/CopyButton/CopyButton.js +14 -0
- package/dist/buttons/DeleteButton/DeleteButton.d.ts +12 -0
- package/dist/buttons/DeleteButton/DeleteButton.js +17 -0
- package/dist/buttons/DownloadButton/DownloadButton.d.ts +30 -0
- package/dist/buttons/DownloadButton/DownloadButton.js +20 -0
- package/dist/buttons/EditButton/EditButton.d.ts +13 -0
- package/dist/buttons/EditButton/EditButton.js +17 -0
- package/dist/buttons/LikeButton/LikeButton.d.ts +28 -0
- package/dist/buttons/LikeButton/LikeButton.js +10 -0
- package/dist/buttons/MenuItemButton.d.ts +11 -0
- package/dist/buttons/MenuItemButton.js +12 -0
- package/dist/buttons/MoveButton/MoveButton.d.ts +13 -0
- package/dist/buttons/MoveButton/MoveButton.js +19 -0
- package/dist/buttons/PinButton/PinButton.d.ts +15 -0
- package/dist/buttons/PinButton/PinButton.js +21 -0
- package/dist/buttons/SaveButton/SaveButton.d.ts +24 -0
- package/dist/buttons/SaveButton/SaveButton.js +4 -0
- package/dist/buttons/ShareButton/ShareButton.d.ts +14 -0
- package/dist/buttons/ShareButton/ShareButton.js +17 -0
- package/dist/buttons/hooks.d.ts +5 -0
- package/dist/buttons/hooks.js +14 -0
- package/dist/buttons/index.d.ts +12 -0
- package/dist/buttons/index.js +12 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.js +12 -0
- package/dist/draggable/DraggableElement.d.ts +11 -0
- package/dist/draggable/DraggableElement.js +42 -0
- package/dist/draggable/DraggingWrapper.d.ts +23 -0
- package/dist/draggable/DraggingWrapper.js +20 -0
- package/dist/draggable/InBetween.d.ts +10 -0
- package/dist/draggable/InBetween.js +34 -0
- package/dist/draggable/types.d.ts +10 -0
- package/dist/draggable/types.js +1 -0
- package/dist/enums/errors.d.ts +3 -0
- package/dist/enums/errors.js +3 -0
- package/dist/hooks/useFullscreen.d.ts +5 -0
- package/dist/hooks/useFullscreen.js +37 -0
- package/dist/hooks/useMobileView.d.ts +4 -0
- package/dist/hooks/useMobileView.js +6 -0
- package/dist/icons/AnalyticsIcon.d.ts +15 -0
- package/dist/icons/AnalyticsIcon.js +7 -0
- package/dist/icons/BuildIcon.d.ts +15 -0
- package/dist/icons/BuildIcon.js +7 -0
- package/dist/icons/EtherpadIcon.d.ts +7 -0
- package/dist/icons/EtherpadIcon.js +7 -0
- package/dist/icons/H5PIcon.d.ts +6 -0
- package/dist/icons/H5PIcon.js +6 -0
- package/dist/icons/ItemIcon.d.ts +23 -0
- package/dist/icons/ItemIcon.js +75 -0
- package/dist/icons/LibraryIcon.d.ts +16 -0
- package/dist/icons/LibraryIcon.js +7 -0
- package/dist/icons/PlayIcon.d.ts +15 -0
- package/dist/icons/PlayIcon.js +7 -0
- package/dist/icons/ResizingIcon.d.ts +2 -0
- package/dist/icons/ResizingIcon.js +21 -0
- package/dist/icons/StyledSVGComponents.d.ts +35 -0
- package/dist/icons/StyledSVGComponents.js +53 -0
- package/dist/icons/index.d.ts +6 -0
- package/dist/icons/index.js +6 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +60 -0
- package/dist/itemLogin/ForbiddenContent.d.ts +20 -0
- package/dist/itemLogin/ForbiddenContent.js +4 -0
- package/dist/itemLogin/ForbiddenText.d.ts +8 -0
- package/dist/itemLogin/ForbiddenText.js +6 -0
- package/dist/itemLogin/ItemLoginScreen.d.ts +26 -0
- package/dist/itemLogin/ItemLoginScreen.js +72 -0
- package/dist/itemLogin/ItemLoginWrapper.d.ts +23 -0
- package/dist/itemLogin/ItemLoginWrapper.js +43 -0
- package/dist/itemLogin/constants.d.ts +1 -0
- package/dist/itemLogin/constants.js +1 -0
- package/dist/items/AppItem.d.ts +60 -0
- package/dist/items/AppItem.js +69 -0
- package/dist/items/DocumentItem.d.ts +19 -0
- package/dist/items/DocumentItem.js +25 -0
- package/dist/items/DownloadButtonFileItem.d.ts +9 -0
- package/dist/items/DownloadButtonFileItem.js +10 -0
- package/dist/items/EtherpadItem.d.ts +26 -0
- package/dist/items/EtherpadItem.js +15 -0
- package/dist/items/FileAudio.d.ts +9 -0
- package/dist/items/FileAudio.js +10 -0
- package/dist/items/FileImage.d.ts +7 -0
- package/dist/items/FileImage.js +10 -0
- package/dist/items/FileItem.d.ts +25 -0
- package/dist/items/FileItem.js +81 -0
- package/dist/items/FilePdf.d.ts +14 -0
- package/dist/items/FilePdf.js +29 -0
- package/dist/items/FileVideo.d.ts +8 -0
- package/dist/items/FileVideo.js +9 -0
- package/dist/items/H5PItem.d.ts +20 -0
- package/dist/items/H5PItem.js +80 -0
- package/dist/items/ItemSkeleton/ItemSkeleton.d.ts +12 -0
- package/dist/items/ItemSkeleton/ItemSkeleton.js +35 -0
- package/dist/items/LinkItem.d.ts +43 -0
- package/dist/items/LinkItem.js +97 -0
- package/dist/items/SizingWrapper.d.ts +6 -0
- package/dist/items/SizingWrapper.js +23 -0
- package/dist/items/appItemHooks.d.ts +27 -0
- package/dist/items/appItemHooks.js +124 -0
- package/dist/items/constants.d.ts +1 -0
- package/dist/items/constants.js +1 -0
- package/dist/items/iframeStyles.d.ts +4 -0
- package/dist/items/iframeStyles.js +5 -0
- package/dist/items/index.d.ts +5 -0
- package/dist/items/index.js +5 -0
- package/dist/items/withCaption.d.ts +19 -0
- package/dist/items/withCaption.js +58 -0
- package/dist/items/withResizing.d.ts +9 -0
- package/dist/items/withResizing.js +42 -0
- package/dist/text-editor.d.ts +2 -0
- package/dist/text-editor.js +2 -0
- package/dist/theme.d.ts +108 -0
- package/dist/theme.js +214 -0
- package/dist/types.d.ts +43 -0
- package/dist/types.js +32 -0
- package/dist/upload/FileDropper/FileDropper.d.ts +50 -0
- package/dist/upload/FileDropper/FileDropper.js +43 -0
- package/dist/upload/UploadFileButton/UploadFileButton.d.ts +35 -0
- package/dist/upload/UploadFileButton/UploadFileButton.js +17 -0
- package/dist/utils/fixtures.d.ts +3 -0
- package/dist/utils/fixtures.js +7 -0
- package/dist/utils/storybook.d.ts +5 -0
- package/dist/utils/storybook.js +5 -0
- package/package.json +172 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box, SpeedDial, SpeedDialAction, Tooltip, useMediaQuery, useTheme, } from '@mui/material';
|
|
3
|
+
import { AnalyticsIcon, BuildIcon, PlayIcon } from '../icons/index.js';
|
|
4
|
+
import { PRIMARY_COLOR, SECONDARY_COLOR } from '../theme.js';
|
|
5
|
+
import { Platform } from './hooks.js';
|
|
6
|
+
/** Mapping from platform to their icons */
|
|
7
|
+
const PlatformIcons = {
|
|
8
|
+
[Platform.Builder]: BuildIcon,
|
|
9
|
+
[Platform.Player]: PlayIcon,
|
|
10
|
+
[Platform.Analytics]: AnalyticsIcon,
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* PlatformSwitch allows the user to change between the platforms
|
|
14
|
+
*/
|
|
15
|
+
export const PlatformSwitch = ({ id, spacing = 0.5, size = 32, color = SECONDARY_COLOR, accentColor = PRIMARY_COLOR, disabledColor = '#CCC', sx, selected, platformsProps, CustomMobileIcon, }) => {
|
|
16
|
+
const theme = useTheme();
|
|
17
|
+
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
|
|
18
|
+
/** Helper inner component: generates buttons from icons while capturing parent props */
|
|
19
|
+
const PlatformButton = ({ platform, sx = {}, }) => {
|
|
20
|
+
const isSelectedPlatform = platform === selected;
|
|
21
|
+
const platformProps = platformsProps?.[platform];
|
|
22
|
+
const Icon = PlatformIcons[platform];
|
|
23
|
+
const tooltip = platformProps?.tooltip;
|
|
24
|
+
const sxProps = { ...sx, ...(platformProps?.sx ?? {}) };
|
|
25
|
+
return (_jsx(Tooltip, { title: platformProps?.disabled ? undefined : tooltip, placement: platformProps?.placement, children: _jsx("a", { id: platformProps?.id, style: {
|
|
26
|
+
display: 'flex',
|
|
27
|
+
cursor: platformProps?.disabled ? 'default' : 'pointer',
|
|
28
|
+
}, "data-testid": platform, href: (!platformProps?.disabled && platformProps?.href) || '#', "aria-disabled": platformProps?.disabled, "data-umami-event": `header-navigation-switch-${platform}`, children: _jsx(Icon, { disabledColor: disabledColor, disabled: platformProps?.disabled, selected: isSelectedPlatform, secondaryColor: accentColor, primaryColor: color, primaryOpacity: 1, size: size, sx: sxProps, disableHover: false }) }) }));
|
|
29
|
+
};
|
|
30
|
+
const buttons = Object.values(Platform).map((platform, index, platforms) => (_jsx(PlatformButton, {
|
|
31
|
+
// the last icon does not need margin at the end
|
|
32
|
+
sx: { mr: index === platforms.length - 1 ? 0 : spacing }, platform: platform }, platform)));
|
|
33
|
+
if (isMobile) {
|
|
34
|
+
const selectedPlatform = selected || Platform.Builder;
|
|
35
|
+
const SelectedIcon = CustomMobileIcon ?? PlatformIcons[selectedPlatform];
|
|
36
|
+
const platformProps = platformsProps?.[selectedPlatform];
|
|
37
|
+
const sxProps = { ...sx, ...(platformProps?.sx ?? {}) };
|
|
38
|
+
return (_jsx(Box, { sx: { position: 'relative', height: '40px' }, children: _jsx(SpeedDial, { FabProps: {
|
|
39
|
+
size: 'small',
|
|
40
|
+
sx: {
|
|
41
|
+
border: '2px solid white',
|
|
42
|
+
},
|
|
43
|
+
}, icon: _jsx(SelectedIcon, { selected: true, secondaryColor: accentColor, primaryColor: color, primaryOpacity: 1, size: size, sx: sxProps }), role: 'navigation', direction: 'down', ariaLabel: 'platform switch dial', children: Object.values(Platform).map((platform, index) => {
|
|
44
|
+
const Icon = PlatformIcons[platform];
|
|
45
|
+
const isSelectedPlatform = platform === selected;
|
|
46
|
+
const platformProps = platformsProps?.[platform];
|
|
47
|
+
const sxProps = { ...sx, ...(platformProps?.sx ?? {}) };
|
|
48
|
+
return (_jsx(SpeedDialAction, { icon: _jsx(Icon, { disabledColor: disabledColor, disabled: platformProps?.disabled, selected: isSelectedPlatform, secondaryColor: accentColor, primaryColor: color, primaryOpacity: 1, size: size, sx: sxProps }), tooltipTitle: platformProps?.tooltip, onClick: () => {
|
|
49
|
+
if (!platformProps?.disabled && platformProps?.href) {
|
|
50
|
+
location.assign(platformProps?.href);
|
|
51
|
+
}
|
|
52
|
+
} }, index));
|
|
53
|
+
}) }) }));
|
|
54
|
+
}
|
|
55
|
+
return (_jsx(Box, { component: 'nav', id: id, sx: {
|
|
56
|
+
p: spacing,
|
|
57
|
+
border: 1,
|
|
58
|
+
borderColor: color,
|
|
59
|
+
borderRadius: `${size}px`,
|
|
60
|
+
width: 'fit-content',
|
|
61
|
+
display: 'flex',
|
|
62
|
+
// props sx must be spread last to override existing styles
|
|
63
|
+
...sx,
|
|
64
|
+
}, children: buttons }));
|
|
65
|
+
};
|
|
66
|
+
export default PlatformSwitch;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Enumeration of available platforms */
|
|
2
|
+
export declare enum Platform {
|
|
3
|
+
Builder = "builder",
|
|
4
|
+
Player = "player",
|
|
5
|
+
Analytics = "analytics"
|
|
6
|
+
}
|
|
7
|
+
/** Maps each Platform to a URL generator function */
|
|
8
|
+
export type HostsMapper = Partial<Record<Platform, (itemId?: string) => string | undefined>>;
|
|
9
|
+
/**
|
|
10
|
+
* Generates a default hosts mapper given a record of platform to hostname
|
|
11
|
+
* Only the origin part of the given hostname will be used!
|
|
12
|
+
*
|
|
13
|
+
* The default mapping is:
|
|
14
|
+
* BUILDER_HOST/items/<itemId>
|
|
15
|
+
* PLAYER_HOST/<itemId>
|
|
16
|
+
* LIBRARY_HOST/<itemId>
|
|
17
|
+
* ANALYTICS_HOST/items/<itemId>
|
|
18
|
+
*
|
|
19
|
+
* For any advanced usage, create your own {@see HostsMapper}
|
|
20
|
+
*/
|
|
21
|
+
export declare function defaultHostsMapper(hostsUrls: Partial<Record<Platform, string>>): HostsMapper;
|
|
22
|
+
/**
|
|
23
|
+
* Hook to create a platform navigator function
|
|
24
|
+
* @param hostsMapper {@see HostsMapper}
|
|
25
|
+
* @param itemId Optional ID of the item context which will be opened in the target platform
|
|
26
|
+
* @returns A mouse events factory that will generate left and middle click actions, to be applied to a given platform
|
|
27
|
+
*/
|
|
28
|
+
export declare function usePlatformNavigation(hostsMapper: HostsMapper, itemId?: string): (platform: Platform) => {
|
|
29
|
+
href: string;
|
|
30
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Enumeration of available platforms */
|
|
2
|
+
export var Platform;
|
|
3
|
+
(function (Platform) {
|
|
4
|
+
Platform["Builder"] = "builder";
|
|
5
|
+
Platform["Player"] = "player";
|
|
6
|
+
Platform["Analytics"] = "analytics";
|
|
7
|
+
})(Platform || (Platform = {}));
|
|
8
|
+
/**
|
|
9
|
+
* Generates a default hosts mapper given a record of platform to hostname
|
|
10
|
+
* Only the origin part of the given hostname will be used!
|
|
11
|
+
*
|
|
12
|
+
* The default mapping is:
|
|
13
|
+
* BUILDER_HOST/items/<itemId>
|
|
14
|
+
* PLAYER_HOST/<itemId>
|
|
15
|
+
* LIBRARY_HOST/<itemId>
|
|
16
|
+
* ANALYTICS_HOST/items/<itemId>
|
|
17
|
+
*
|
|
18
|
+
* For any advanced usage, create your own {@see HostsMapper}
|
|
19
|
+
*/
|
|
20
|
+
export function defaultHostsMapper(hostsUrls) {
|
|
21
|
+
const urlBuilders = {
|
|
22
|
+
[Platform.Builder]: (origin, itemId) => `${origin}/items/${itemId}`,
|
|
23
|
+
[Platform.Player]: (origin, itemId) => `${origin}/${itemId}`,
|
|
24
|
+
[Platform.Analytics]: (origin, itemId) => `${origin}/items/${itemId}`,
|
|
25
|
+
};
|
|
26
|
+
return Object.fromEntries(Object.entries(hostsUrls).map(([platform, url]) => {
|
|
27
|
+
const origin = new URL(url).origin;
|
|
28
|
+
return [
|
|
29
|
+
platform,
|
|
30
|
+
// if passed itemId is undefined, redirect to home page of platform
|
|
31
|
+
(itemId) => itemId ? urlBuilders[platform](origin, itemId) : origin,
|
|
32
|
+
];
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Hook to create a platform navigator function
|
|
37
|
+
* @param hostsMapper {@see HostsMapper}
|
|
38
|
+
* @param itemId Optional ID of the item context which will be opened in the target platform
|
|
39
|
+
* @returns A mouse events factory that will generate left and middle click actions, to be applied to a given platform
|
|
40
|
+
*/
|
|
41
|
+
export function usePlatformNavigation(hostsMapper, itemId) {
|
|
42
|
+
return (platform) => {
|
|
43
|
+
const url = hostsMapper[platform]?.(itemId);
|
|
44
|
+
const href = url ?? '#';
|
|
45
|
+
return {
|
|
46
|
+
href,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type TextFieldProps } from '@mui/material';
|
|
2
|
+
import { ChangeEvent } from 'react';
|
|
3
|
+
export type Props = {
|
|
4
|
+
ariaLabel?: string;
|
|
5
|
+
inputBaseId?: string;
|
|
6
|
+
onChange?: (event: ChangeEvent<{
|
|
7
|
+
value: string;
|
|
8
|
+
}>) => void;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
value?: string;
|
|
11
|
+
width?: string | number;
|
|
12
|
+
margin?: TextFieldProps['margin'];
|
|
13
|
+
size?: TextFieldProps['size'];
|
|
14
|
+
/**
|
|
15
|
+
* Name of the event to send to Umami for tracking user actions
|
|
16
|
+
*/
|
|
17
|
+
dataUmamiEvent?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare const SearchInput: ({ ariaLabel, inputBaseId, onChange, placeholder, value, width, margin, size, dataUmamiEvent, }: Props) => JSX.Element;
|
|
20
|
+
export default SearchInput;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { SearchIcon } from 'lucide-react';
|
|
3
|
+
import { InputAdornment, TextField } from '@mui/material';
|
|
4
|
+
// todo: create minified version for small screens
|
|
5
|
+
export const SearchInput = ({ ariaLabel = 'search', inputBaseId, onChange, placeholder = 'Search…', value = '', width, margin, size, dataUmamiEvent, }) => {
|
|
6
|
+
return (_jsx(TextField, { InputProps: {
|
|
7
|
+
endAdornment: (_jsx(InputAdornment, { position: 'end', children: _jsx(SearchIcon, { "aria-label": 'search' }) })),
|
|
8
|
+
}, margin: margin, id: inputBaseId, onChange: onChange, value: value, sx: { flex: 1, width: width ?? '100%', backgroundColor: 'white' }, placeholder: placeholder, size: size, inputProps: {
|
|
9
|
+
'aria-label': ariaLabel,
|
|
10
|
+
// Umami data props
|
|
11
|
+
'data-umami-event': dataUmamiEvent,
|
|
12
|
+
} }));
|
|
13
|
+
};
|
|
14
|
+
export default SearchInput;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SelectProps as MuiSelectProps, SxProps } from '@mui/material';
|
|
2
|
+
type Props<T> = {
|
|
3
|
+
buildOptionId?: (v: T) => string;
|
|
4
|
+
className?: string;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
color?: MuiSelectProps['color'];
|
|
7
|
+
defaultValue?: T;
|
|
8
|
+
value?: T | undefined;
|
|
9
|
+
displayEmpty?: MuiSelectProps['displayEmpty'];
|
|
10
|
+
id?: string;
|
|
11
|
+
label?: string;
|
|
12
|
+
labelId?: MuiSelectProps['labelId'];
|
|
13
|
+
onChange?: MuiSelectProps<T>['onChange'];
|
|
14
|
+
sx?: SxProps;
|
|
15
|
+
values: {
|
|
16
|
+
value: T;
|
|
17
|
+
text: string;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
}[];
|
|
20
|
+
variant?: MuiSelectProps['variant'];
|
|
21
|
+
size?: MuiSelectProps['size'];
|
|
22
|
+
};
|
|
23
|
+
declare const Select: <T extends string | number>({ buildOptionId, className, color, disabled, defaultValue, displayEmpty, id, label, labelId, onChange, sx, values, variant, size, value, }: Props<T>) => JSX.Element;
|
|
24
|
+
export default Select;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { FormControl, InputLabel, MenuItem, Select as MuiSelect, } from '@mui/material';
|
|
3
|
+
const Select = ({ buildOptionId, className, color, disabled = false, defaultValue, displayEmpty, id, label, labelId, onChange, sx, values, variant, size, value, }) => {
|
|
4
|
+
const showLabel = Boolean(labelId ?? label);
|
|
5
|
+
return (_jsxs(FormControl, { sx: { mt: label ? 1 : 0, height: 'fit-content' }, size: size, "data-testid": 'select-test-id', disabled: disabled || values.every(({ disabled }) => disabled), children: [showLabel && _jsx(InputLabel, { id: labelId, children: label }), _jsx(MuiSelect, { labelId: labelId, label: label, defaultValue: defaultValue, onChange: onChange, renderValue: (v) => values.find(({ value }) => value === v)?.text ?? label, displayEmpty: displayEmpty, className: className, color: color, variant: variant, id: id, value: value, sx: sx, children: values.map(({ value, text, disabled }) => (_jsx(MenuItem, { id: buildOptionId?.(value), value: value, disabled: Boolean(disabled), children: text }, value))) })] }));
|
|
6
|
+
};
|
|
7
|
+
export default Select;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SxProps } from '@mui/material';
|
|
2
|
+
import React, { ReactNode } from 'react';
|
|
3
|
+
export type SidebarProps = {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
drawerHeaderContent?: React.ReactElement;
|
|
6
|
+
handleDrawerClose?: () => void;
|
|
7
|
+
isSidebarOpen?: boolean;
|
|
8
|
+
sx?: SxProps;
|
|
9
|
+
};
|
|
10
|
+
export declare const Sidebar: ({ children, drawerHeaderContent, handleDrawerClose, isSidebarOpen, sx, }: SidebarProps) => JSX.Element;
|
|
11
|
+
export default Sidebar;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Drawer, styled } from '@mui/material';
|
|
3
|
+
import DrawerHeader from '../DrawerHeader/DrawerHeader.js';
|
|
4
|
+
import { DRAWER_WIDTH } from '../constants.js';
|
|
5
|
+
const StyledDrawer = styled(Drawer)(({ theme, open }) => ({
|
|
6
|
+
transition: theme.transitions.create(['width'], {
|
|
7
|
+
easing: theme.transitions.easing.sharp,
|
|
8
|
+
duration: theme.transitions.duration.leavingScreen,
|
|
9
|
+
}),
|
|
10
|
+
...(open && {
|
|
11
|
+
transition: theme.transitions.create(['width'], {
|
|
12
|
+
easing: theme.transitions.easing.easeOut,
|
|
13
|
+
duration: theme.transitions.duration.enteringScreen,
|
|
14
|
+
}),
|
|
15
|
+
}),
|
|
16
|
+
position: 'sticky',
|
|
17
|
+
flexShrink: 0,
|
|
18
|
+
'.MuiDrawer-paper': {
|
|
19
|
+
width: DRAWER_WIDTH,
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
export const Sidebar = ({ children, drawerHeaderContent, handleDrawerClose, isSidebarOpen = false, sx, }) => {
|
|
23
|
+
return (_jsx(StyledDrawer, { sx: sx, variant: 'persistent', anchor: 'left', open: isSidebarOpen, children: _jsxs(_Fragment, { children: [_jsx(DrawerHeader, { handleDrawerClose: handleDrawerClose, children: drawerHeaderContent }), children] }) }));
|
|
24
|
+
};
|
|
25
|
+
export default Sidebar;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SxProps } from '@mui/material';
|
|
2
|
+
import { DetailedHTMLProps, HTMLAttributes, ImgHTMLAttributes } from 'react';
|
|
3
|
+
type ImageProps = {
|
|
4
|
+
sx?: SxProps;
|
|
5
|
+
} & DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>;
|
|
6
|
+
declare const StyledImage: (props: ImageProps) => JSX.Element;
|
|
7
|
+
type DivProps = {
|
|
8
|
+
sx?: SxProps;
|
|
9
|
+
} & DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
|
10
|
+
declare const StyledDiv: (props: DivProps) => JSX.Element;
|
|
11
|
+
export { StyledImage, StyledDiv };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { styled } from '@mui/material';
|
|
3
|
+
const StyledImage = (props) => {
|
|
4
|
+
const StyledImage = styled('img')({});
|
|
5
|
+
return _jsx(StyledImage, { ...props });
|
|
6
|
+
};
|
|
7
|
+
const StyledDiv = (props) => {
|
|
8
|
+
const StyledDiv = styled('div')({});
|
|
9
|
+
return _jsx(StyledDiv, { ...props });
|
|
10
|
+
};
|
|
11
|
+
export { StyledImage, StyledDiv };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Interweave } from 'interweave';
|
|
3
|
+
import { styled } from '@mui/material';
|
|
4
|
+
const StyledDiv = styled('div')(({ theme }) => ({
|
|
5
|
+
'& .ql-editor': {
|
|
6
|
+
padding: '0px',
|
|
7
|
+
// apply paragraph margin bottom only to elements that are not last children
|
|
8
|
+
'& p:not(:last-child)': {
|
|
9
|
+
marginBlockEnd: theme.spacing(2),
|
|
10
|
+
},
|
|
11
|
+
'& td, th': {
|
|
12
|
+
border: '1px solid #ddd',
|
|
13
|
+
textAlign: 'left',
|
|
14
|
+
padding: '8px',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
}));
|
|
18
|
+
const TextDisplay = ({ id, content, }) => {
|
|
19
|
+
if (content) {
|
|
20
|
+
return (_jsx(StyledDiv, { className: 'quill', id: id, children: _jsx("div", { className: 'ql-snow ql-disabled', children: _jsx("div", { className: 'ql-editor', children: _jsx(Interweave, { content: content, noWrap: true }) }) }) }));
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
};
|
|
24
|
+
export default TextDisplay;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const HTML_CONTENT = "<p class=\"ql-align-center\">I am centered</p><p>I am left aligned</p><p class=\"ql-align-right\">I am right aligned</p><p class=\"ql-align-right\"><span class=\"ql-emojiblot\" data-name=\"smiling_imp\">\uFEFF<span contenteditable=\"false\"><span class=\"ap ap-smiling_imp\">\uD83D\uDE08</span></span>\uFEFF</span></p><p class=\"ql-align-right\">I <span style=\"background-color: rgb(204, 224, 245);\">have</span> a <span style=\"background-color: rgb(194, 133, 255);\">background</span></p><p class=\"ql-align-center\"><a href=\"https://www.google.com\" rel=\"noopener noreferrer\" target=\"_blank\">Test link</a></p><p><s>Hey !</s></p><p><strong class=\"ql-font-serif\"><s>Wow</s></strong></p><p><br></p><pre class=\"ql-syntax\" spellcheck=\"false\">Some code too !\n</pre>";
|
|
2
|
+
export declare const HTML_TABLE = "\n<h2>HTML Table</h2>\n<table>\n <tr>\n <th>Company</th>\n <th>Contact</th>\n <th>Country</th>\n </tr>\n <tr>\n <td>Alfreds Futterkiste</td>\n <td>Maria Anders</td>\n <td>Germany</td>\n </tr>\n <tr>\n <td>Centro comercial Moctezuma</td>\n <td>Francisco Chang</td>\n <td>Mexico</td>\n </tr>\n <tr>\n <td>Ernst Handel</td>\n <td>Roland Mendel</td>\n <td>Austria</td>\n </tr>\n <tr>\n <td>Island Trading</td>\n <td>Helen Bennett</td>\n <td>UK</td>\n </tr>\n <tr>\n <td>Laughing Bacchus Winecellars</td>\n <td>Yoshi Tannamuri</td>\n <td>Canada</td>\n </tr>\n <tr>\n <td>Magazzini Alimentari Riuniti</td>\n <td>Giovanni Rovelli</td>\n <td>Italy</td>\n </tr>\n</table>\n ";
|
|
3
|
+
export declare const STYLED_HTML_TABLE = "\n<h2 style=\"background-color: #5050d2; color: white; border-radius: 4px; padding: 8px\">HTML Table in Graasp !</h2>\n\n<table style=\"font-family: arial, sans-serif;\nborder-collapse: collapse;\nwidth: 100%;\">\n <tr>\n <th>Company</th>\n <th>Contact</th>\n <th>Country</th>\n </tr>\n <tr>\n <td>Alfreds Futterkiste</td>\n <td>Maria Anders</td>\n <td>Germany</td>\n </tr>\n <tr>\n <td>Centro comercial Moctezuma</td>\n <td>Francisco Chang</td>\n <td>Mexico</td>\n </tr>\n <tr>\n <td>Ernst Handel</td>\n <td>Roland Mendel</td>\n <td>Austria</td>\n </tr>\n <tr>\n <td>Island Trading</td>\n <td>Helen Bennett</td>\n <td>UK</td>\n </tr>\n <tr>\n <td>Laughing Bacchus Winecellars</td>\n <td>Yoshi Tannamuri</td>\n <td>Canada</td>\n </tr>\n <tr>\n <td>Magazzini Alimentari Riuniti</td>\n <td>Giovanni Rovelli</td>\n <td>Italy</td>\n </tr>\n</table>\n ";
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export const HTML_CONTENT = '<p class="ql-align-center">I am centered</p><p>I am left aligned</p><p class="ql-align-right">I am right aligned</p><p class="ql-align-right"><span class="ql-emojiblot" data-name="smiling_imp"><span contenteditable="false"><span class="ap ap-smiling_imp">😈</span></span></span></p><p class="ql-align-right">I <span style="background-color: rgb(204, 224, 245);">have</span> a <span style="background-color: rgb(194, 133, 255);">background</span></p><p class="ql-align-center"><a href="https://www.google.com" rel="noopener noreferrer" target="_blank">Test link</a></p><p><s>Hey !</s></p><p><strong class="ql-font-serif"><s>Wow</s></strong></p><p><br></p><pre class="ql-syntax" spellcheck="false">Some code too !\n</pre>';
|
|
2
|
+
export const HTML_TABLE = `
|
|
3
|
+
<h2>HTML Table</h2>
|
|
4
|
+
<table>
|
|
5
|
+
<tr>
|
|
6
|
+
<th>Company</th>
|
|
7
|
+
<th>Contact</th>
|
|
8
|
+
<th>Country</th>
|
|
9
|
+
</tr>
|
|
10
|
+
<tr>
|
|
11
|
+
<td>Alfreds Futterkiste</td>
|
|
12
|
+
<td>Maria Anders</td>
|
|
13
|
+
<td>Germany</td>
|
|
14
|
+
</tr>
|
|
15
|
+
<tr>
|
|
16
|
+
<td>Centro comercial Moctezuma</td>
|
|
17
|
+
<td>Francisco Chang</td>
|
|
18
|
+
<td>Mexico</td>
|
|
19
|
+
</tr>
|
|
20
|
+
<tr>
|
|
21
|
+
<td>Ernst Handel</td>
|
|
22
|
+
<td>Roland Mendel</td>
|
|
23
|
+
<td>Austria</td>
|
|
24
|
+
</tr>
|
|
25
|
+
<tr>
|
|
26
|
+
<td>Island Trading</td>
|
|
27
|
+
<td>Helen Bennett</td>
|
|
28
|
+
<td>UK</td>
|
|
29
|
+
</tr>
|
|
30
|
+
<tr>
|
|
31
|
+
<td>Laughing Bacchus Winecellars</td>
|
|
32
|
+
<td>Yoshi Tannamuri</td>
|
|
33
|
+
<td>Canada</td>
|
|
34
|
+
</tr>
|
|
35
|
+
<tr>
|
|
36
|
+
<td>Magazzini Alimentari Riuniti</td>
|
|
37
|
+
<td>Giovanni Rovelli</td>
|
|
38
|
+
<td>Italy</td>
|
|
39
|
+
</tr>
|
|
40
|
+
</table>
|
|
41
|
+
`;
|
|
42
|
+
export const STYLED_HTML_TABLE = `
|
|
43
|
+
<h2 style="background-color: #5050d2; color: white; border-radius: 4px; padding: 8px">HTML Table in Graasp !</h2>
|
|
44
|
+
|
|
45
|
+
<table style="font-family: arial, sans-serif;
|
|
46
|
+
border-collapse: collapse;
|
|
47
|
+
width: 100%;">
|
|
48
|
+
<tr>
|
|
49
|
+
<th>Company</th>
|
|
50
|
+
<th>Contact</th>
|
|
51
|
+
<th>Country</th>
|
|
52
|
+
</tr>
|
|
53
|
+
<tr>
|
|
54
|
+
<td>Alfreds Futterkiste</td>
|
|
55
|
+
<td>Maria Anders</td>
|
|
56
|
+
<td>Germany</td>
|
|
57
|
+
</tr>
|
|
58
|
+
<tr>
|
|
59
|
+
<td>Centro comercial Moctezuma</td>
|
|
60
|
+
<td>Francisco Chang</td>
|
|
61
|
+
<td>Mexico</td>
|
|
62
|
+
</tr>
|
|
63
|
+
<tr>
|
|
64
|
+
<td>Ernst Handel</td>
|
|
65
|
+
<td>Roland Mendel</td>
|
|
66
|
+
<td>Austria</td>
|
|
67
|
+
</tr>
|
|
68
|
+
<tr>
|
|
69
|
+
<td>Island Trading</td>
|
|
70
|
+
<td>Helen Bennett</td>
|
|
71
|
+
<td>UK</td>
|
|
72
|
+
</tr>
|
|
73
|
+
<tr>
|
|
74
|
+
<td>Laughing Bacchus Winecellars</td>
|
|
75
|
+
<td>Yoshi Tannamuri</td>
|
|
76
|
+
<td>Canada</td>
|
|
77
|
+
</tr>
|
|
78
|
+
<tr>
|
|
79
|
+
<td>Magazzini Alimentari Riuniti</td>
|
|
80
|
+
<td>Giovanni Rovelli</td>
|
|
81
|
+
<td>Italy</td>
|
|
82
|
+
</tr>
|
|
83
|
+
</table>
|
|
84
|
+
`;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DocumentItemExtraFlavor } from '@lnco-ai/sdk';
|
|
2
|
+
type WithFlavorProps = {
|
|
3
|
+
content: JSX.Element | string;
|
|
4
|
+
title?: string;
|
|
5
|
+
flavor?: `${DocumentItemExtraFlavor}` | DocumentItemExtraFlavor;
|
|
6
|
+
};
|
|
7
|
+
export declare const withFlavor: ({ content, title, flavor, }: WithFlavorProps) => JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Alert, AlertTitle, Typography } from '@mui/material';
|
|
3
|
+
import { DocumentItemExtraFlavor } from '@lnco-ai/sdk';
|
|
4
|
+
const Title = ({ title, isAlert = false, }) => {
|
|
5
|
+
if (!title) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
if (isAlert) {
|
|
9
|
+
return (_jsx(AlertTitle, { sx: { fontWeight: 700, fontSize: '1.1rem' }, children: title }));
|
|
10
|
+
}
|
|
11
|
+
return _jsx(Typography, { variant: 'h5', children: title });
|
|
12
|
+
};
|
|
13
|
+
export const withFlavor = ({ content, title, flavor = DocumentItemExtraFlavor.None, }) => {
|
|
14
|
+
if (flavor === DocumentItemExtraFlavor.None) {
|
|
15
|
+
// need to wrap in a fragment because content can be a string which is not a JSX.Element
|
|
16
|
+
return (_jsxs(_Fragment, { children: [_jsx(Title, { title: title }), content] }));
|
|
17
|
+
}
|
|
18
|
+
return (_jsxs(Alert, { severity: flavor, sx: {
|
|
19
|
+
alignItems: 'flex-start',
|
|
20
|
+
'& .MuiAlert-message': {
|
|
21
|
+
// this allows the content of the text to expand over all available space
|
|
22
|
+
flexGrow: 1,
|
|
23
|
+
},
|
|
24
|
+
}, children: [_jsx(Title, { title: title, isAlert: true }), content] }));
|
|
25
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type TextEditorProps = {
|
|
2
|
+
cancelButtonId?: string;
|
|
3
|
+
cancelButtonText?: string;
|
|
4
|
+
id?: string;
|
|
5
|
+
onCancel?: (text: string) => void;
|
|
6
|
+
onChange?: (text: string) => void;
|
|
7
|
+
onSave?: (text: string) => void;
|
|
8
|
+
placeholderText?: string;
|
|
9
|
+
saveButtonId?: string;
|
|
10
|
+
saveButtonText?: string;
|
|
11
|
+
savedButtonText?: string;
|
|
12
|
+
showActions?: boolean;
|
|
13
|
+
value?: string;
|
|
14
|
+
};
|
|
15
|
+
declare const TextEditor: ({ cancelButtonId, cancelButtonText, id, onCancel, onChange, onSave, placeholderText, saveButtonId, saveButtonText, savedButtonText, showActions, value: initialValue, }: TextEditorProps) => JSX.Element | null;
|
|
16
|
+
export default TextEditor;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// formula dependencies
|
|
3
|
+
import katex from 'katex';
|
|
4
|
+
import { Stack, styled } from '@mui/material';
|
|
5
|
+
import { useEffect, useRef, useState } from 'react';
|
|
6
|
+
import ReactQuill from 'react-quill';
|
|
7
|
+
import Button from '../buttons/Button/Button.js';
|
|
8
|
+
import SaveButton from '../buttons/SaveButton/SaveButton.js';
|
|
9
|
+
window.katex = katex;
|
|
10
|
+
const TEXT_EDITOR_TOOLBAR = [
|
|
11
|
+
[{ header: [1, 2, 3, 4, 5, 6, false] }],
|
|
12
|
+
[{ font: [] }],
|
|
13
|
+
['bold', 'italic', 'underline', 'strike'],
|
|
14
|
+
[{ color: [] }], // default colors depending on theme
|
|
15
|
+
[{ background: [] }], // default colors depending on theme
|
|
16
|
+
[{ align: [] }],
|
|
17
|
+
[{ list: 'ordered' }, { list: 'bullet' }, 'code-block', 'link', 'formula'],
|
|
18
|
+
];
|
|
19
|
+
const TEXT_EDITOR_MIN_HEIGHT = 200;
|
|
20
|
+
const TEXT_EDITOR_MAX_HEIGHT = 400;
|
|
21
|
+
const Div = styled('div')(({ theme }) => ({
|
|
22
|
+
width: '100%',
|
|
23
|
+
'.ql-tooltip': {
|
|
24
|
+
zIndex: theme.zIndex.tooltip,
|
|
25
|
+
},
|
|
26
|
+
'& .ql-editor': {
|
|
27
|
+
// adapt height if read only
|
|
28
|
+
minHeight: TEXT_EDITOR_MIN_HEIGHT,
|
|
29
|
+
// necessary styles to avoid window scrolling top on paste
|
|
30
|
+
// set a max height only on edition
|
|
31
|
+
maxHeight: TEXT_EDITOR_MAX_HEIGHT,
|
|
32
|
+
overflow: 'auto',
|
|
33
|
+
'& p': {
|
|
34
|
+
paddingBottom: 3,
|
|
35
|
+
paddingTop: 3,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
'& .ql-container': {
|
|
39
|
+
// use font size from mui theme
|
|
40
|
+
fontSize: 'unset',
|
|
41
|
+
},
|
|
42
|
+
}));
|
|
43
|
+
const TextEditor = ({ cancelButtonId, cancelButtonText = 'Cancel', id, onCancel, onChange, onSave, placeholderText = 'Write something…', saveButtonId, saveButtonText, savedButtonText, showActions = true, value: initialValue = '', }) => {
|
|
44
|
+
// keep current content
|
|
45
|
+
const [content, setContent] = useState(initialValue ?? '');
|
|
46
|
+
const editorRef = useRef(null);
|
|
47
|
+
const onTextChange = (text) => {
|
|
48
|
+
// keep track of the current content
|
|
49
|
+
setContent(text);
|
|
50
|
+
onChange?.(text);
|
|
51
|
+
};
|
|
52
|
+
const onCancelClick = () => {
|
|
53
|
+
onCancel?.(content);
|
|
54
|
+
setContent(initialValue);
|
|
55
|
+
};
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
// update the content with initialValue only when initialValue changes
|
|
58
|
+
setContent(initialValue);
|
|
59
|
+
}, [initialValue]);
|
|
60
|
+
// this hack is necessary because the "placeholder" prop does not update
|
|
61
|
+
// see: https://github.com/zenoamaro/react-quill/issues/340
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (editorRef.current) {
|
|
64
|
+
editorRef.current.getEditor().root.dataset.placeholder = placeholderText;
|
|
65
|
+
}
|
|
66
|
+
}, [placeholderText]);
|
|
67
|
+
return (_jsxs(Stack, { direction: 'column', spacing: 1, alignItems: 'flex-end', children: [_jsx(Div, { children: _jsx(ReactQuill, { ref: editorRef, id: id, placeholder: placeholderText, theme: 'snow', value: content, onChange: onTextChange, modules: {
|
|
68
|
+
toolbar: TEXT_EDITOR_TOOLBAR,
|
|
69
|
+
clipboard: {
|
|
70
|
+
matchVisual: false,
|
|
71
|
+
},
|
|
72
|
+
} }) }), showActions && (_jsxs(Stack, { spacing: 1, direction: 'row', children: [_jsx(Button, { variant: 'text', id: cancelButtonId, onClick: onCancelClick, children: cancelButtonText }), _jsx(SaveButton, { id: saveButtonId, onClick: () => onSave?.(content), text: saveButtonText, savedText: savedButtonText, hasChanges: content !== initialValue })] }))] }));
|
|
73
|
+
};
|
|
74
|
+
export default TextEditor;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Direction, SelectProps as MuiSelectProps, SxProps } from '@mui/material';
|
|
2
|
+
import { Dispatch } from 'react';
|
|
3
|
+
import { I18nInstance } from '../types.js';
|
|
4
|
+
declare const LanguageSelect: ({ i18n, setDirection, languageSelectSx, langs, label, size, variant, }: {
|
|
5
|
+
i18n: I18nInstance;
|
|
6
|
+
setDirection?: Dispatch<Direction>;
|
|
7
|
+
languageSelectSx?: SxProps;
|
|
8
|
+
langs: {
|
|
9
|
+
[key: string]: string;
|
|
10
|
+
};
|
|
11
|
+
label?: string;
|
|
12
|
+
variant?: MuiSelectProps["variant"];
|
|
13
|
+
size?: MuiSelectProps["size"];
|
|
14
|
+
}) => JSX.Element;
|
|
15
|
+
export default LanguageSelect;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import Select from '../Select/Select.js';
|
|
4
|
+
const LanguageSelect = ({ i18n, setDirection, languageSelectSx, langs, label, size, variant, }) => {
|
|
5
|
+
// init local lang, it does not update if we use i18n language directly
|
|
6
|
+
const [lang, setLang] = useState(i18n.language);
|
|
7
|
+
const handleLangSelect = (event) => {
|
|
8
|
+
const d = i18n.dir(event.target.value);
|
|
9
|
+
// this should be guarded for ssr rendering
|
|
10
|
+
if (document) {
|
|
11
|
+
document.dir = d;
|
|
12
|
+
}
|
|
13
|
+
setDirection?.(d);
|
|
14
|
+
i18n.changeLanguage(event.target.value);
|
|
15
|
+
setLang(event.target.value);
|
|
16
|
+
};
|
|
17
|
+
return (_jsx(Select, { size: size, label: label, variant: variant, labelId: label ? 'language-select-label' : undefined, defaultValue: lang, sx: { minWidth: 80, ...languageSelectSx }, onChange: handleLangSelect, buildOptionId: (value) => `language-${value}`, values: Object.entries(langs).map(([k, l]) => ({ value: k, text: l })) }));
|
|
18
|
+
};
|
|
19
|
+
export default LanguageSelect;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Direction, SelectProps as MuiSelectProps, SxProps } from '@mui/material';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { I18nInstance } from '../types.js';
|
|
4
|
+
type Props = {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
i18n: I18nInstance;
|
|
7
|
+
langs: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
10
|
+
languageSelectSx: SxProps;
|
|
11
|
+
languageSelectLabel?: string;
|
|
12
|
+
languageSelectVariant?: MuiSelectProps['variant'];
|
|
13
|
+
languageSelectSize?: MuiSelectProps['size'];
|
|
14
|
+
defaultDirection?: Direction;
|
|
15
|
+
};
|
|
16
|
+
type Context = {
|
|
17
|
+
languageSelect: JSX.Element;
|
|
18
|
+
direction: Direction;
|
|
19
|
+
};
|
|
20
|
+
declare const ThemeProvider: ({ children, i18n, langs, languageSelectSx, languageSelectLabel, languageSelectVariant, languageSelectSize, defaultDirection, }: Props) => JSX.Element;
|
|
21
|
+
declare const useTheme: () => Context;
|
|
22
|
+
export { ThemeProvider, useTheme };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import createCache from '@emotion/cache';
|
|
3
|
+
import { CacheProvider } from '@emotion/react';
|
|
4
|
+
import { prefixer } from 'stylis';
|
|
5
|
+
import { ThemeProvider as MuiThemeProvider, } from '@mui/material';
|
|
6
|
+
import { createContext, useContext, useEffect, useMemo, useState, } from 'react';
|
|
7
|
+
import rtlPlugin from '@graasp/stylis-plugin-rtl';
|
|
8
|
+
import { buildTheme } from '../theme.js';
|
|
9
|
+
import LanguageSelect from './LanguageSelect.js';
|
|
10
|
+
const ThemeContext = createContext({
|
|
11
|
+
languageSelect: _jsx(_Fragment, {}),
|
|
12
|
+
direction: 'ltr',
|
|
13
|
+
});
|
|
14
|
+
const getCacheForDirection = (direction) => createCache({
|
|
15
|
+
key: `mui-dir-${direction}`,
|
|
16
|
+
stylisPlugins: [prefixer, ...(direction === 'rtl' ? [rtlPlugin] : [])],
|
|
17
|
+
});
|
|
18
|
+
const ThemeProvider = ({ children, i18n, langs, languageSelectSx, languageSelectLabel, languageSelectVariant = 'outlined', languageSelectSize = 'small', defaultDirection = 'ltr', }) => {
|
|
19
|
+
const [direction, setDirection] = useState(defaultDirection);
|
|
20
|
+
const languageSelect = (_jsx(LanguageSelect, { languageSelectSx: languageSelectSx, i18n: i18n, setDirection: setDirection, langs: langs, variant: languageSelectVariant, label: languageSelectLabel, size: languageSelectSize }));
|
|
21
|
+
const value = useMemo(() => ({ direction, languageSelect }), [direction, languageSelect]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
document.documentElement.setAttribute('dir', direction);
|
|
24
|
+
}, [direction]);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
setDirection(defaultDirection);
|
|
27
|
+
}, [defaultDirection]);
|
|
28
|
+
return (_jsx(ThemeContext.Provider, { value: value, children: _jsx(MuiThemeProvider, { theme: { ...buildTheme(direction), direction }, children: _jsx(CacheProvider, { value: getCacheForDirection(direction), children: children }) }) }));
|
|
29
|
+
};
|
|
30
|
+
const useTheme = () => useContext(ThemeContext);
|
|
31
|
+
export { ThemeProvider, useTheme };
|