Skip to content

[WEB-64] [EDITOR] Code Blocks :D #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
24a8bdb
Created code block button
Apr 12, 2023
57d9c1c
added codeblock to index
Apr 12, 2023
9211f93
added 'code' as a valid type
Apr 12, 2023
cf3af79
Stubbed CodeBlock component
Apr 13, 2023
ba6b99e
added basic code content block w/o syntax highlighting
Apr 15, 2023
96fdead
added types needed for syntax highlighting
Apr 18, 2023
f441418
integrated code types required with existing implementation
Apr 20, 2023
9b5d3fb
added code from Slate sample implementation
Apr 20, 2023
b945362
fixed mergeMaps - compiling (yay) but getting runtime errors sads
Apr 20, 2023
1727ab0
Added stylesheet - still running into range errors :(
Apr 20, 2023
1517470
changed element wrapper to only ever return codeline type
May 9, 2023
9dd9032
YOOO SYNTAX HIGHLIGHTINGS WORKING NOWWWW
May 9, 2023
d1a7009
added functionality to change language of block - still have to selec…
May 9, 2023
14393d5
added functionality to change language of block w/o having to selectt…
May 9, 2023
d857d71
right aligned the language selection dropdown
May 9, 2023
942910d
added code to make the language selected in dropdown element persiste…
May 9, 2023
e5094e7
disabled spellcheck in editor
May 9, 2023
ef8ff14
added support for more languages
May 9, 2023
0094824
tabbing support
May 9, 2023
8013f83
moved prism theme to its own file and deleted deprecated style sheet
May 9, 2023
9ea1421
removed debugging console logs and improved comments
May 9, 2023
7747a71
changed code-block prop to be simply 'code' and fixed bg colour of co…
May 9, 2023
aa0d166
fixed bg color of codecontentblock
May 9, 2023
8c0e875
changed default language to Python
May 12, 2023
96e1034
removed unused imports
Jun 4, 2023
59e4e3f
removed unnecessary package json files
Jun 4, 2023
cddb97e
removed more unused imports + possible fix for default lang fix
Jun 4, 2023
bb9553c
fixed issue where default language would not persist when left unsele…
Jun 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
464 changes: 305 additions & 159 deletions frontend/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"@types/draft-js": "0.11.9",
"@types/jest": "26.0.24",
"@types/node": "12.20.55",
"@types/prismjs": "^1.26.0",
"@types/react": "17.0.44",
"@types/react-dom": "17.0.17",
"@types/react-redux": "7.1.24",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import styled from "styled-components";

export type buttonProps = {
background?: string;
};
export const StyledButton = styled.div<buttonProps>`
width: 175px;
height: 45px;
margin: 5px;
background: ${(props) => props.background};

display: flex;
justify-content: center;
align-items: center;
border-radius: 10px;
user-select: none;

&:hover {
background: #efeef3;
color: black;
transform: scale(1.04);
}
&:active {
background: #c8d1fa;
transform: scale(0.96);
}

cursor: pointer;
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';

import CreateCodeBlock from './CreateCodeBlock';

import { AiFillEdit } from "react-icons/ai";

export default {
title: 'CSE-UIKIT/CreateCodeBlockButton',
component: CreateCodeBlock,

argTypes: {
backgroundColor: { control: 'color' },
},
} as ComponentMeta<typeof CreateCodeBlock>;

const Template: ComponentStory<typeof CreateCodeBlock> = (args) =>
(
<div
style={{
margin: "30px"
}}
>
Insert Button
<CreateCodeBlock {...args}></CreateCodeBlock>
</div>
)

export const Primary = Template.bind({});
Primary.args = {
background: "#90c2e7",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { MouseEventHandler } from "react";
import { StyledButton, buttonProps } from "./CreateCodeBlock-Styled";
import { AiOutlineCode } from "react-icons/ai";

type Props = {
onClick?: MouseEventHandler<HTMLDivElement>;
} & buttonProps;

export default function CreateCodeBlock({ onClick, ...styleProps }: Props) {
return (
<StyledButton
data-anchor="CreateCodeBlockButton"
onClick={onClick}
{...styleProps}
>
<AiOutlineCode />
Insert Code Block
</StyledButton>
);
}
3 changes: 3 additions & 0 deletions frontend/src/cse-ui-kit/CreateCodeBlock_button /index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import CreateCodeBlock from './CreateCodeBlock';

export default CreateCodeBlock;
28 changes: 28 additions & 0 deletions frontend/src/cse-ui-kit/codeblock/codecontentblock-Styled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
import styled from "styled-components";

export type StyledProps = {
focused?: boolean;
}

export const StyledCodeContent = styled.div<StyledProps>`
width: 100%;
max-width: 600px;
background: #f7f7f7;
color: #000000;
box-shadow: ${(props) => props.focused && '0px 2px 3px rgba(0, 0, 0, 0.25);'}
padding: 30px 20px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
border-radius: 5px;
margin: 5px;
padding: 5px;
font-family: monospace;
`;

export const StyledCodeContentDots = styled.div`
height: 100;
cursor: pointer;
`;
38 changes: 38 additions & 0 deletions frontend/src/cse-ui-kit/codeblock/codecontentblock-wrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable */
import React from 'react';
import { StyledCodeContent, StyledCodeContentDots, StyledProps } from './codecontentblock-Styled';
import { ReactComponent as Dots } from '../../assets/moveable-content-dots.svg';
import { Box } from "@mui/material";

type Props = {
children?: React.ReactElement | any;
onClick?: (...args: any) => void;
} & StyledProps;

export default function MoveableContentBlock({ children, onClick, ...styleProps }: Props) {
const { focused } = styleProps;
return (
<StyledCodeContent
onClick={onClick}
{...styleProps}
data-anchor="ContentBlockWrapper"
>
<div
style={{
width: "90%",
wordWrap: "break-word"
}}
>
{children}
</div>
<StyledCodeContentDots>
{ (focused == true) &&
<Dots
height="18px"
width="18px"
/>
}
</StyledCodeContentDots>
</StyledCodeContent>
);
}
25 changes: 25 additions & 0 deletions frontend/src/cse-ui-kit/codeblock/codecontentblock.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';

import MoveableCodeContentContentBlock from './codecontentblock-wrapper';

export default {
title: 'CSE-UIKIT/CodeContentContentBlock',
component: MoveableCodeContentContentBlock,
} as ComponentMeta<typeof MoveableCodeContentContentBlock>;

const Template: ComponentStory<typeof MoveableCodeContentContentBlock> = (args) =>
(
<div
style={{
margin: "30px"
}}
>
Moveable Content Block
<MoveableCodeContentContentBlock {...args}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</MoveableCodeContentContentBlock>
</div>
)

export const Primary = Template.bind({});
4 changes: 3 additions & 1 deletion frontend/src/packages/editor/componentFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from "react";
import { BlockData, UpdateCallback, CMSBlockProps } from "./types";
import EditorBlock from "./components/EditorBlock";
import { OperationManager, slateToCmsOperation } from "./operationManager";
import CodeBlock from "./components/CodeBlock";

// TODO: not now because I want to get this over and done with but the idea of attaching the operation path to the id irks me
// because logically the operation paths aren't actually coupled to the id, it is just a coincidence, ideally the source of the operation path index
Expand All @@ -15,7 +16,8 @@ type callbackHandler = (id: number, update: BlockData) => void;
// registration of all block constructors
const constructors: Record<string, (props: CMSBlockProps) => JSX.Element> = {
"paragraph": (props) => <EditorBlock {...props} />,
"heading": (props) => <HeadingBlock {...props} />
"heading": (props) => <HeadingBlock {...props} />,
"code" : (props) => <CodeBlock {...props} />
}

/**
Expand Down
Loading