1 Commits

Author SHA1 Message Date
Isaac - The456
37e9fa2a0e Add option to wrap text 2025-03-15 11:56:15 +00:00
16 changed files with 1014 additions and 1499 deletions

View File

@@ -1,45 +0,0 @@
name: Deploy to GitHub Pages
on:
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: 'pages'
cancel-in-progress: true
jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'npm'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
env:
#VITE_BYTEBIN_URL: "https://your-bytebin.example.com/"
VITE_USE_QUERY_ROUTING: "true" # required for github pages
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload dist folder
path: './dist'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

42
API.md
View File

@@ -1,42 +0,0 @@
<p align="center">
<img src=".github/banner.svg">
</p>
# API
paste has a simple HTTP API which can be used to read and write pastes programmatically.
> [!IMPORTANT]
> If you are using the official instance of paste (https://pastes.dev), please note the following:
>
> * You must **provide a `User-Agent` header** to uniquely identify your application in all requests. This should include the application name and contact information, e.g. `ExampleApp (github.com/ExampleUser/ExampleApp)` or `MyExampleScript (github.com/ExampleUser)`.
> * You must **only upload content when prompted by a user action**, e.g. a button click or command line input. Automated or scheduled uploads are not allowed.
> * An additional **terms of service** applies. In summary:
> * No Illegal Use *(no illegal, harmful or unlawful content)*
> * No Malicious Content *(no malware, phishing, personal data without consent, etc.)*
> * Content Responsibility *(you are responsible for what you post)*
> * Moderation *(we reserve the right to remove content or block access)*
> * No Liability *(the service is provided "as is" without warranties)*
>
> Otherwise, please enjoy using the service! :)
### Base URL
The base URL for the 'official' paste instance is: `https://api.pastes.dev/`.
If you are self-hosting, use the base URL of your own instance. With the default Docker Compose setup, this will be `http://localhost:8080/data/`.
## Upload: `POST {BASE URL}/post`
To upload content, send an HTTP `POST` request to `{BASE URL}/post`.
* Include the content in the request body.
* Specify the language with the `Content-Type: text/<language>` header
* If using the official instance, please remember to provide a suitable `User-Agent` header as well. (see above for more details)
* The paste "key" is returned in the `Location` header, and in the response body as a JSON object in the format `{"key": "<key>"}`.**
## Read: `GET {BASE URL}/{key}`
To read content, send an HTTP `GET` request to `{BASE URL}/{key}`.
* Replace `{key}` with the id of the paste.
* The content is returned in the response body.
* The `Content-Type` header is `text/<language>`, where language is the id of the language the paste was saved with.

View File

@@ -23,6 +23,18 @@ You can submit content most easily using [curl](https://curl.se/docs/manpage.htm
> echo "Hello world" | curl -T - https://api.pastes.dev/post > echo "Hello world" | curl -T - https://api.pastes.dev/post
``` ```
<details>
<summary>If curl isn't installed on your system, you can also post using <b>netcat</b>.</summary>
```shell
# Pipe in some output from any command
> echo "Hello world" | nc nc.pastes.dev 1337
# Upload the contents of a file
> cat example.txt | nc nc.pastes.dev 1337
```
</details>
<details> <details>
<summary>If you don't want to do so much typing, you can create a shorter <b>alias</b>.</summary> <summary>If you don't want to do so much typing, you can create a shorter <b>alias</b>.</summary>
@@ -44,8 +56,8 @@ You can submit content most easily using [curl](https://curl.se/docs/manpage.htm
``` ```
</details> </details>
##### 3) From Code / Scripts ##### 3) From Code
Please see the [API Documentation](/API.md). :) Send GET/POST/PUT requests to `https://api.pastes.dev/`. More info [below](#pastesdev-api).
___ ___
@@ -54,6 +66,28 @@ The frontend _(this repository)_ is written using the React framework. The backe
The user-interface is based on the [Monaco Editor](https://microsoft.github.io/monaco-editor/), the engine behind the popular Visual Studio Code text editor. It's quite simple; it supports syntax highlighting, automatic indentation, many supported languages, themes, zooming in/out, linking to specific lines or sections, and more! The user-interface is based on the [Monaco Editor](https://microsoft.github.io/monaco-editor/), the engine behind the popular Visual Studio Code text editor. It's quite simple; it supports syntax highlighting, automatic indentation, many supported languages, themes, zooming in/out, linking to specific lines or sections, and more!
### pastes.dev
I host a public instance at https://pastes.dev. Please feel free to use it to share code/configs/whatever!
Please note that the following (very-non-legally worded) [terms of service](https://github.com/lucko/bytebin#public-instances) apply.
If you come across any content which is illegal or infringes on copyright, please [get in touch](https://lucko.me/contact) and let me know so I can remove it.
Uploaded content is retained for 90 days then deleted.
### pastes.dev API
* To **read** content, send a HTTP `GET` request to `https://api.pastes.dev/<key>`.
* Replace `<key>` with the id of the paste.
* The content is returned in the response body.
* The `Content-Type` header is `text/<language>`, where language is the id of the language the paste was saved with.
* To **upload** content, send a HTTP `POST` request to `https://api.pastes.dev/post`.
* Include the content in the request body.
* Specify the language with the `Content-Type: text/<language>` header, and please provide a `User-Agent` header too.
* The paste "key" is returned in the `Location` header, or in the response body as a JSON object in the format `{"key": "<key>"}`.
The API is powered by the [bytebin](https://github.com/lucko/bytebin) service, so more information about how it works can be found there.
___ ___
### Self-hosting ### Self-hosting

View File

@@ -11,35 +11,34 @@
"format": "prettier --write '**/*.ts' '**/*.tsx' '**/*.css'" "format": "prettier --write '**/*.ts' '**/*.tsx' '**/*.css'"
}, },
"dependencies": { "dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1",
"@monaco-editor/react": "^4.6.0",
"@catppuccin/palette": "^1.7.1", "@catppuccin/palette": "^1.7.1",
"@monaco-editor/react": "^4.8.0-rc.3",
"copy-to-clipboard": "^3.3.3", "copy-to-clipboard": "^3.3.3",
"history": "^5.3.0", "history": "^5.3.0",
"monaco-editor": "^0.55.1", "monaco-editor": "^0.52.0",
"monaco-themes": "^0.4.8", "monaco-themes": "^0.4.4",
"pako": "^2.1.0", "pako": "^2.1.0",
"react": "^19.2.4",
"react-device-detect": "^2.2.3", "react-device-detect": "^2.2.3",
"react-dom": "^19.2.4", "styled-components": "^6.1.13",
"styled-components": "^6.3.11",
"whatwg-mimetype": "^3.0.0" "whatwg-mimetype": "^3.0.0"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^10.0.1", "@eslint/js": "^9.17.0",
"@types/node": "^25.3.0", "@types/react": "^18.3.18",
"@types/pako": "^2.0.4", "@types/react-dom": "^18.3.5",
"@types/react": "^19.2.14", "@types/pako": "^2.0.3",
"@types/react-dom": "^19.2.3",
"@types/whatwg-mimetype": "^3.0.2", "@types/whatwg-mimetype": "^3.0.2",
"@vitejs/plugin-react-swc": "^4.2.3", "@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "^10.0.1", "eslint": "^9.17.0",
"eslint-plugin-react-hooks": "^7.0.1", "eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.5.2", "eslint-plugin-react-refresh": "^0.4.16",
"globals": "^17.3.0", "globals": "^15.14.0",
"prettier": "^3.8.1", "typescript": "~5.6.2",
"prettier-plugin-organize-imports": "^4.3.0", "typescript-eslint": "^8.18.2",
"typescript": "~5.9.3", "vite": "^6.0.5",
"typescript-eslint": "^8.56.1", "prettier": "^3.4.2",
"vite": "^7.3.1" "prettier-plugin-organize-imports": "^4.1.0"
} }
} }

View File

@@ -1,10 +1,5 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { ThemeProvider } from 'styled-components';
import About from './components/About.tsx';
import Editor from './components/Editor'; import Editor from './components/Editor';
import usePreference from './hooks/usePreference.ts';
import themes, { Themes } from './style/themes.ts';
import { useQueryRouting } from './util/constants';
import { loadFromBytebin } from './util/storage'; import { loadFromBytebin } from './util/storage';
const INITIAL = Symbol(); const INITIAL = Symbol();
@@ -19,12 +14,6 @@ export default function App() {
const [forcedContent, setForcedContent] = useState<string>(''); const [forcedContent, setForcedContent] = useState<string>('');
const [actualContent, setActualContent] = useState<string>(''); const [actualContent, setActualContent] = useState<string>('');
const [contentType, setContentType] = useState<string>(); const [contentType, setContentType] = useState<string>();
const [theme, setTheme] = usePreference<keyof Themes>(
'theme',
'dark',
pref => !!themes[pref]
);
const [showAbout, setShowAbout] = useState<boolean>(false);
function setContent(content: string) { function setContent(content: string) {
setActualContent(content); setActualContent(content);
@@ -33,7 +22,6 @@ export default function App() {
useEffect(() => { useEffect(() => {
if (pasteId && state === INITIAL) { if (pasteId && state === INITIAL) {
// eslint-disable-next-line react-hooks/set-state-in-effect
setState(LOADING); setState(LOADING);
setContent('Loading...'); setContent('Loading...');
@@ -52,19 +40,13 @@ export default function App() {
}, [pasteId, state]); }, [pasteId, state]);
return ( return (
<ThemeProvider theme={themes[theme]}>
<Editor <Editor
forcedContent={forcedContent} forcedContent={forcedContent}
actualContent={actualContent} actualContent={actualContent}
setActualContent={setActualContent} setActualContent={setActualContent}
contentType={contentType} contentType={contentType}
pasteId={pasteId} pasteId={pasteId}
theme={theme}
setTheme={setTheme}
setShowAbout={setShowAbout}
/> />
{showAbout && <About setVisible={setShowAbout} />}
</ThemeProvider>
); );
} }
@@ -83,10 +65,10 @@ function get404Message(pasteId: string) {
} }
function getPasteIdFromUrl() { function getPasteIdFromUrl() {
if (useQueryRouting) {
return new URLSearchParams(window.location.search).get('id') ?? undefined;
}
const path = window.location.pathname; const path = window.location.pathname;
return /^\/[a-zA-Z0-9]+$/.test(path) ? path.substring(1) : undefined; if (path && /^\/[a-zA-Z0-9]+$/.test(path)) {
return path.substring(1);
} else {
return undefined;
}
} }

View File

@@ -1,202 +0,0 @@
import { useCallback, useState } from 'react';
import styled from 'styled-components';
import Button from './Button.tsx';
const CloseButton = ({
setVisible,
}: {
setVisible: (show: boolean) => void;
}) => {
const close = useCallback(() => {
setVisible(false);
}, [setVisible]);
return (
<div
style={{
position: 'absolute',
top: '5px',
right: '5px',
}}
>
<Button style={{ padding: '5px' }} onClick={close}>
[X]
</Button>
</div>
);
};
export default function About({
setVisible,
}: {
setVisible: (show: boolean) => void;
}) {
const official = window.location.hostname === 'pastes.dev';
const [showTos, setShowTos] = useState<boolean>(false);
if (showTos) {
return <Tos setVisible={setShowTos} />;
}
return (
<AboutPanel>
<CloseButton setVisible={setVisible} />
<BannerContainer>
<Banner>{'{paste}'}</Banner>
</BannerContainer>
<p>
<b>paste is a simple web app for writing & sharing code</b>. It's a
different take on conventional pastebin sites like pastebin.com or
hastebin.
</p>
{official && (
<>
<p>
<b>pastes.dev</b> is the official, publicly accessible paste
instance, and can be used by anyone, subject to the{' '}
<a
href="#"
onClick={e => {
setShowTos(true);
e.preventDefault();
}}
>
Terms of Service
</a>
.
</p>
<p>
To access pastes.dev programmatically, please use the{' '}
<a
href="https://github.com/lucko/paste/blob/master/API.md"
target="_blank"
>
API
</a>
. :)
</p>
<p>
Please{' '}
<b>
<a
href="#"
onClick={e => {
setShowTos(true);
e.preventDefault();
}}
>
report
</a>
</b>{' '}
illegal, malicious, or abusive content so it can be removed.
</p>
</>
)}
<p style={{ textAlign: 'center' }}>
<a href="https://github.com/lucko/paste" target="_blank">
paste
</a>{' '}
is free & open source on GitHub.
<br />
Copyright &copy; 2021-{new Date().getFullYear()}{' '}
<a href="https://github.com/lucko" target="_blank">
lucko
</a>{' '}
& other paste{' '}
<a
href="https://github.com/lucko/paste/graphs/contributors"
target="_blank"
>
contributors
</a>
.
</p>
</AboutPanel>
);
}
const Tos = ({ setVisible }: { setVisible: (show: boolean) => void }) => {
return (
<AboutPanel>
<CloseButton setVisible={setVisible} />
<h1>Terms of Service</h1>
<p>
Welcome to pastes.dev. By using this service, you agree to the following
terms:
</p>
<ol>
<li>
<b>No Illegal Use:</b> You may not use pastes.dev to share, store, or
distribute any content that is illegal, harmful, or violates any laws
or regulations.
</li>
<li>
<b>No Malicious Content:</b> Do not upload or share content intended
to harm others, including but not limited to malware, phishing links,
or personal data without consent.
</li>
<li>
<b>Content Responsibility:</b> You are solely responsible for the
content you post. We do not review content and are not liable for what
users choose to share.
</li>
<li>
<b>Moderation:</b> We reserve the right to remove any content at our
discretion, and to restrict or terminate access to the service for
abuse or violations of these terms.
</li>
<li>
<b>No Liability:</b> This service is provided "as is" with no
warranties. We do not guarantee uptime, data retention, or
availability.
</li>
</ol>
<p>
By using pastes.dev, you accept these terms. If you do not agree, please
do not use the service.
</p>
<h2>Reporting Abuse</h2>
<p>
If you encounter illegal or malicious content, please report it by email
to <span>report-abuse@pastes.dev</span>.
</p>
</AboutPanel>
);
};
const AboutPanel = styled.div`
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 99;
padding: 10px;
max-width: 650px;
max-height: 100vh;
overflow-y: auto;
color: ${props => props.theme.primary};
background-color: ${props => props.theme.secondary};
span {
color: ${props => props.theme.logo};
}
a {
color: ${props => props.theme.logo};
}
`;
const BannerContainer = styled.div`
display: flex;
justify-content: center;
`;
const Banner = styled.div`
background-color: ${props => props.theme.background};
color: ${props => props.theme.logo};
border-radius: 20px;
font-size: 70px;
letter-spacing: -5px;
padding: 10px;
font-weight: bold;
`;

View File

@@ -1,8 +1,9 @@
import { useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import { isMobile } from 'react-device-detect'; import { isMobile } from 'react-device-detect';
import { ThemeProvider } from 'styled-components';
import usePreference from '../hooks/usePreference'; import usePreference from '../hooks/usePreference';
import { Themes } from '../style/themes.ts'; import themes, { Themes } from '../style/themes';
import EditorControls from './EditorControls'; import EditorControls from './EditorControls';
import EditorGlobalStyle from './EditorGlobalStyle'; import EditorGlobalStyle from './EditorGlobalStyle';
import EditorTextArea from './EditorTextArea'; import EditorTextArea from './EditorTextArea';
@@ -13,9 +14,6 @@ export interface EditorProps {
setActualContent: (value: string) => void; setActualContent: (value: string) => void;
contentType?: string; contentType?: string;
pasteId?: string; pasteId?: string;
theme: keyof Themes;
setTheme: (value: keyof Themes) => void;
setShowAbout: (value: boolean) => void;
} }
export type ResetFunction = () => void; export type ResetFunction = () => void;
@@ -26,29 +24,26 @@ export default function Editor({
setActualContent, setActualContent,
contentType, contentType,
pasteId, pasteId,
theme,
setTheme,
setShowAbout,
}: EditorProps) { }: EditorProps) {
const [language, setLanguage] = useState<string>('plain'); const [language, setLanguage] = useState<string>('plain');
const [readOnly, setReadOnly] = useState<boolean>(isMobile && !!pasteId); const [readOnly, setReadOnly] = useState<boolean>(isMobile && !!pasteId);
const resetFunction = useRef<ResetFunction>(null); const resetFunction = useRef<ResetFunction>(null);
const [theme, setTheme] = usePreference<keyof Themes>(
'theme',
'dark',
pref => !!themes[pref]
);
const [fontSize, setFontSize, fontSizeCheck] = usePreference<number>( const [fontSize, setFontSize, fontSizeCheck] = usePreference<number>(
'fontsize', 'fontsize',
16, 16,
pref => pref >= 10 && pref <= 22 pref => pref >= 10 && pref <= 22
); );
const [wordWrap, setWordWrap] = usePreference<boolean>( const [wordWrap, setWordWrap] = usePreference<boolean>('wordwrap-enabled', true, (value) => true)
'wordwrap',
true,
() => true
);
useEffect(() => { useEffect(() => {
if (contentType) { if (contentType) {
// eslint-disable-next-line react-hooks/set-state-in-effect
setLanguage(contentType); setLanguage(contentType);
} }
}, [contentType]); }, [contentType]);
@@ -62,6 +57,7 @@ export default function Editor({
return ( return (
<> <>
<ThemeProvider theme={themes[theme]}>
<EditorGlobalStyle /> <EditorGlobalStyle />
<EditorControls <EditorControls
actualContent={actualContent} actualContent={actualContent}
@@ -75,18 +71,19 @@ export default function Editor({
wordWrap={wordWrap} wordWrap={wordWrap}
setWordWrap={setWordWrap} setWordWrap={setWordWrap}
zoom={zoom} zoom={zoom}
setShowAbout={setShowAbout}
/> />
<EditorTextArea <EditorTextArea
forcedContent={forcedContent} forcedContent={forcedContent}
actualContent={actualContent} actualContent={actualContent}
setActualContent={setActualContent} setActualContent={setActualContent}
theme={themes[theme]}
language={language} language={language}
fontSize={fontSize} fontSize={fontSize}
readOnly={readOnly} readOnly={readOnly}
wordWrap={wordWrap} wordWrap={wordWrap}
resetFunctionRef={resetFunction} resetFunction={resetFunction}
/> />
</ThemeProvider>
</> </>
); );
} }

View File

@@ -4,7 +4,6 @@ import { RefObject, useCallback, useEffect, useState } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import themes, { Themes } from '../style/themes'; import themes, { Themes } from '../style/themes';
import { useQueryRouting } from '../util/constants';
import { languages } from '../util/highlighting'; import { languages } from '../util/highlighting';
import { saveToBytebin } from '../util/storage'; import { saveToBytebin } from '../util/storage';
import Button from './Button'; import Button from './Button';
@@ -20,10 +19,9 @@ export interface EditorControlsProps {
setReadOnly: (value: boolean) => void; setReadOnly: (value: boolean) => void;
theme: keyof Themes; theme: keyof Themes;
setTheme: (value: keyof Themes) => void; setTheme: (value: keyof Themes) => void;
wordWrap: boolean; wordWrap: boolean
setWordWrap: (value: boolean) => void; setWordWrap: (value: boolean) => void;
zoom: (delta: number) => void; zoom: (delta: number) => void;
setShowAbout: (value: boolean) => void;
} }
export default function EditorControls({ export default function EditorControls({
@@ -38,20 +36,14 @@ export default function EditorControls({
wordWrap, wordWrap,
setWordWrap, setWordWrap,
zoom, zoom,
setShowAbout,
}: EditorControlsProps) { }: EditorControlsProps) {
const [saving, setSaving] = useState<boolean>(false); const [saving, setSaving] = useState<boolean>(false);
const [recentlySaved, setRecentlySaved] = useState<boolean>(false); const [recentlySaved, setRecentlySaved] = useState<boolean>(false);
useEffect(() => { useEffect(() => {
// eslint-disable-next-line react-hooks/set-state-in-effect
setRecentlySaved(false); setRecentlySaved(false);
}, [actualContent, language]); }, [actualContent, language]);
const showAbout = useCallback(() => {
setShowAbout(true);
}, [setShowAbout]);
const save = useCallback(() => { const save = useCallback(() => {
if (!actualContent || recentlySaved) { if (!actualContent || recentlySaved) {
return; return;
@@ -61,15 +53,9 @@ export default function EditorControls({
setSaving(false); setSaving(false);
setRecentlySaved(true); setRecentlySaved(true);
if (pasteId) { if (pasteId) {
if (useQueryRouting) {
history.replace({
search: `?id=${pasteId}`,
});
} else {
history.replace({ history.replace({
pathname: pasteId, pathname: pasteId,
}); });
}
copy(window.location.href); copy(window.location.href);
document.title = 'paste | ' + pasteId; document.title = 'paste | ' + pasteId;
} }
@@ -131,16 +117,22 @@ export default function EditorControls({
<Section> <Section>
<Button onClick={() => zoom(1)}>[+ </Button> <Button onClick={() => zoom(1)}>[+ </Button>
<Button onClick={() => zoom(-1)}> -]</Button> <Button onClick={() => zoom(-1)}> -]</Button>
<Button onClick={() => setWordWrap(!wordWrap)}> <Button onClick={() => setWordWrap(!wordWrap)}>[<span className='optional'>wrap:</span>{wordWrap ? "on" : "off"}]</Button>
[wrap:{wordWrap ? 'on' : 'off'}]
</Button>
<MenuButton <MenuButton
label="theme" label="theme"
value={theme} value={theme}
setValue={setTheme} setValue={setTheme}
ids={Object.keys(themes) as (keyof Themes)[]} ids={Object.keys(themes) as (keyof Themes)[]}
/> />
<Button onClick={showAbout}>[about]</Button> <Button
className="optional"
as="a"
href="https://github.com/lucko/paste#readme"
target="_blank"
rel="noreferrer"
>
[about]
</Button>
</Section> </Section>
</Header> </Header>
); );
@@ -157,15 +149,13 @@ const Header = styled.header`
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
user-select: none; user-select: none;
overflow-x: auto;
white-space: nowrap;
`; `;
const Section = styled.div` const Section = styled.div`
display: flex; display: flex;
align-items: center; align-items: center;
@media (max-width: 850px) { @media (max-width: 470px) {
.optional { .optional {
display: none; display: none;
} }

View File

@@ -5,8 +5,15 @@ import Editor, {
OnMount, OnMount,
} from '@monaco-editor/react'; } from '@monaco-editor/react';
import history from 'history/browser'; import history from 'history/browser';
import { RefObject, useCallback, useEffect, useRef, useState } from 'react'; import {
import styled, { useTheme } from 'styled-components'; MutableRefObject,
RefObject,
useCallback,
useEffect,
useRef,
useState,
} from 'react';
import styled from 'styled-components';
import themes, { Theme } from '../style/themes'; import themes, { Theme } from '../style/themes';
import type { editor } from 'monaco-editor'; import type { editor } from 'monaco-editor';
@@ -51,28 +58,29 @@ export interface EditorTextAreaProps {
forcedContent: string; forcedContent: string;
actualContent: string; actualContent: string;
setActualContent: (value: string) => void; setActualContent: (value: string) => void;
theme: Theme;
language: string; language: string;
fontSize: number; fontSize: number;
readOnly: boolean; readOnly: boolean;
wordWrap: boolean; wordWrap: boolean;
resetFunctionRef: RefObject<ResetFunction | null>; resetFunction: MutableRefObject<ResetFunction | null>;
} }
export default function EditorTextArea({ export default function EditorTextArea({
forcedContent, forcedContent,
actualContent, actualContent,
setActualContent, setActualContent,
theme,
language, language,
fontSize, fontSize,
readOnly, readOnly,
wordWrap, wordWrap,
resetFunctionRef, resetFunction,
}: EditorTextAreaProps) { }: EditorTextAreaProps) {
const [editor, setEditor] = useState<editor.IStandaloneCodeEditor>(); const [editor, setEditor] = useState<editor.IStandaloneCodeEditor>();
const [monaco, setMonaco] = useState<Monaco>(); const [monaco, setMonaco] = useState<Monaco>();
const [selected, toggleSelected] = useSelectedLine(); const [selected, toggleSelected] = useSelectedLine();
const editorAreaRef = useRef<HTMLDivElement>(null); const editorAreaRef = useRef<HTMLDivElement>(null);
const theme = useTheme();
useLineNumberMagic( useLineNumberMagic(
editorAreaRef, editorAreaRef,
@@ -122,16 +130,12 @@ export default function EditorTextArea({
setEditor(editor); setEditor(editor);
setMonaco(monaco); setMonaco(monaco);
resetFunctionRef.current = () => { resetFunction.current = () => {
editor.setValue(''); editor.setValue('');
if (!readOnly) {
editor.focus(); editor.focus();
}
}; };
if (!readOnly) {
editor.focus(); editor.focus();
}
}; };
const onChange: OnChange = useCallback( const onChange: OnChange = useCallback(

View File

@@ -1,5 +1,4 @@
import React, { useEffect, useRef, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { createPortal } from 'react-dom';
import styled from 'styled-components'; import styled from 'styled-components';
import Button from './Button'; import Button from './Button';
@@ -17,11 +16,6 @@ export default function MenuButton<T extends string>({
setValue, setValue,
}: MenuButtonProps<T>) { }: MenuButtonProps<T>) {
const [open, setOpen] = useState<boolean>(false); const [open, setOpen] = useState<boolean>(false);
const [menuPosition, setMenuPosition] = useState<{
top: number;
left: number;
}>({ top: 0, left: 0 });
const buttonRef = useRef<HTMLDivElement | null>(null);
// close the menu when a click is made elsewhere // close the menu when a click is made elsewhere
useEffect(() => { useEffect(() => {
@@ -32,16 +26,6 @@ export default function MenuButton<T extends string>({
function toggleOpen(e: React.MouseEvent) { function toggleOpen(e: React.MouseEvent) {
e.stopPropagation(); e.stopPropagation();
if (!buttonRef.current) {
return;
}
if (!open) {
const rect = buttonRef.current.getBoundingClientRect();
setMenuPosition({
top: rect.bottom + window.scrollY,
left: rect.left + window.scrollX,
});
}
setOpen(!open); setOpen(!open);
} }
@@ -79,35 +63,22 @@ export default function MenuButton<T extends string>({
} }
return ( return (
<> <Button onClick={toggleOpen}>
<Button onClick={toggleOpen} ref={buttonRef}>
[<span>{label}: </span> [<span>{label}: </span>
{value}] {value}]{open && <Menu>{items}</Menu>}
</Button> </Button>
{open &&
createPortal(
<Menu style={{ top: menuPosition.top, left: menuPosition.left }}>
{items}
</Menu>,
document.body
)}
</>
); );
} }
const Menu = styled.ul` const Menu = styled.ul`
position: absolute; position: absolute;
top: 2em;
margin: 0; margin: 0;
padding: 0; padding: 0;
list-style: none; list-style: none;
background-color: ${props => props.theme.highlight}; background-color: ${props => props.theme.highlight};
max-height: calc(100vh - 2em); max-height: calc(100vh - 2em);
overflow: auto; overflow: auto;
z-index: 20;
> li {
cursor: pointer;
}
> li.title { > li.title {
text-align: center; text-align: center;
@@ -132,7 +103,6 @@ const Menu = styled.ul`
> li { > li {
padding: 0em 1em 0.05em 1em; padding: 0em 1em 0.05em 1em;
color: ${props => props.theme.primary};
} }
> li:hover { > li:hover {

View File

@@ -1,14 +1,9 @@
import type { editor } from 'monaco-editor'; import type { editor } from 'monaco-editor';
import { CatppuccinFlavor, ColorFormat, flavors } from '@catppuccin/palette'; import { CatppuccinFlavor, ColorFormat, flavors } from '@catppuccin/palette';
// @ts-expect-error Alias import added in vite.config.ts
import dracula from 'monaco-themes/themes/Dracula.json'; import dracula from 'monaco-themes/themes/Dracula.json';
// @ts-expect-error Alias import added in vite.config.ts
import monokai from 'monaco-themes/themes/Monokai.json'; import monokai from 'monaco-themes/themes/Monokai.json';
// @ts-expect-error Alias import added in vite.config.ts
import solarizedDark from 'monaco-themes/themes/Solarized-dark.json'; import solarizedDark from 'monaco-themes/themes/Solarized-dark.json';
// @ts-expect-error Alias import added in vite.config.ts
import solarizedLight from 'monaco-themes/themes/Solarized-light.json'; import solarizedLight from 'monaco-themes/themes/Solarized-light.json';
type Color = `#${string}`; type Color = `#${string}`;
@@ -20,7 +15,6 @@ export interface Theme {
secondary: Color; secondary: Color;
highlight: Color; highlight: Color;
background: Color; background: Color;
logo: Color;
lightOrDark: 'light' | 'dark'; lightOrDark: 'light' | 'dark';
highlightedLine: { highlightedLine: {
color: Color; color: Color;
@@ -49,7 +43,6 @@ const themes: Themes = {
secondary: '#010409', // canvas.inset secondary: '#010409', // canvas.inset
highlight: '#161b22', // canvas.overlay highlight: '#161b22', // canvas.overlay
background: '#0d1117', // canvas.default background: '#0d1117', // canvas.default
logo: '#d2a8ff',
lightOrDark: 'dark', lightOrDark: 'dark',
highlightedLine: { highlightedLine: {
@@ -92,7 +85,6 @@ const themes: Themes = {
secondary: '#022550', secondary: '#022550',
highlight: '#36368c', highlight: '#36368c',
background: '#ffffff', background: '#ffffff',
logo: '#00a2ff',
lightOrDark: 'light', lightOrDark: 'light',
highlightedLine: { highlightedLine: {
@@ -135,7 +127,6 @@ const themes: Themes = {
secondary: '#383a59', secondary: '#383a59',
highlight: '#44475a', highlight: '#44475a',
background: '#282a36', background: '#282a36',
logo: '#BD93F9', // purple
lightOrDark: 'dark', lightOrDark: 'dark',
highlightedLine: { highlightedLine: {
color: '#586e75', color: '#586e75',
@@ -158,7 +149,6 @@ const themes: Themes = {
secondary: '#222218', secondary: '#222218',
highlight: '#49483E', highlight: '#49483E',
background: '#272822', background: '#272822',
logo: '#f92672', // red
lightOrDark: 'dark', lightOrDark: 'dark',
highlightedLine: { highlightedLine: {
color: '#49483E', color: '#49483E',
@@ -181,7 +171,6 @@ const themes: Themes = {
secondary: '#073642', // base02 secondary: '#073642', // base02
highlight: '#002b36', // base03 highlight: '#002b36', // base03
background: '#002B36', // base03 background: '#002B36', // base03
logo: '#dc322f', // red
lightOrDark: 'dark', lightOrDark: 'dark',
highlightedLine: { highlightedLine: {
color: '#93a1a1', // base1 color: '#93a1a1', // base1
@@ -204,7 +193,6 @@ const themes: Themes = {
secondary: '#eee8d5', // base2 secondary: '#eee8d5', // base2
highlight: '#FDF6E3', // base3 highlight: '#FDF6E3', // base3
background: '#FDF6E3', // base3 background: '#FDF6E3', // base3
logo: '#dc322f', // red
lightOrDark: 'light', lightOrDark: 'light',
highlightedLine: { highlightedLine: {
color: '#586e75', // base01 color: '#586e75', // base01
@@ -392,7 +380,6 @@ export function createCatppuccinTheme(flavor: CatppuccinFlavor): Theme {
color: color(flavor.colors.rosewater), color: color(flavor.colors.rosewater),
backgroundColor: color(flavor.colors.surface2), backgroundColor: color(flavor.colors.surface2),
}, },
logo: color(flavor.colors.mauve),
editor: editorTheme, editor: editorTheme,
}; };
} }

View File

@@ -1,5 +1,3 @@
export const bytebinUrl = export const bytebinUrl =
import.meta.env.VITE_BYTEBIN_URL || 'https://api.pastes.dev/'; import.meta.env.VITE_BYTEBIN_URL || 'https://bytebin.lucko.me/';
export const postUrl = bytebinUrl + 'post'; export const postUrl = bytebinUrl + 'post';
export const useQueryRouting =
import.meta.env.VITE_USE_QUERY_ROUTING === 'true';

View File

@@ -31,8 +31,7 @@ export async function loadFromBytebin(id: string): Promise<LoadResult> {
} else { } else {
return { ok: false }; return { ok: false };
} }
} catch (e) { } catch {
console.error(e);
return { ok: false }; return { ok: false };
} }
} }
@@ -60,7 +59,7 @@ export async function saveToBytebin(
return json.key; return json.key;
} }
} catch (e) { } catch (e) {
console.error(e); console.log(e);
} }
return null; return null;
} }

1
src/vite-env.d.ts vendored
View File

@@ -2,7 +2,6 @@
interface ImportMetaEnv { interface ImportMetaEnv {
readonly VITE_BYTEBIN_URL?: string; readonly VITE_BYTEBIN_URL?: string;
readonly VITE_USE_QUERY_ROUTING?: string;
} }
interface ImportMeta { interface ImportMeta {

View File

@@ -1,15 +1,7 @@
import react from '@vitejs/plugin-react-swc'; import react from '@vitejs/plugin-react-swc';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vite'; import { defineConfig } from 'vite';
// https://vite.dev/config/ // https://vite.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [react()],
resolve: {
alias: {
'monaco-themes/themes': fileURLToPath(
new URL('./node_modules/monaco-themes/themes', import.meta.url)
),
},
},
}); });

1889
yarn.lock

File diff suppressed because it is too large Load Diff