This commit is contained in:
lnn0q 2025-07-08 16:36:00 +03:00
parent c8f68b7486
commit e5126a4aca
6 changed files with 56 additions and 288 deletions

View file

@ -1,159 +0,0 @@
import { Card, Heading, SystemStyleObject } from '@chakra-ui/react';
import EditorJS, { EditorConfig } from '@editorjs/editorjs';
import Header from '@editorjs/header';
import List from '@editorjs/list';
import Quote from '@editorjs/quote';
import { useEffect, useRef } from 'react';
// @ts-ignore
import Link from '@coolbytes/editorjs-link';
export function Editor({ initialData }: { initialData?: EditorConfig['data'] }) {
const ejInstance = useRef<EditorJS | undefined | null>();
const initEditor = () => {
const editor = new EditorJS({
holder: 'editorjs',
onReady: () => {
ejInstance.current = editor;
},
autofocus: true,
data: initialData,
// onChange: async () => {
// const content = await editor.saver.save();
// },
tools: {
header: Header,
list: List,
link: Link,
quote: Quote
}
});
};
useEffect(() => {
if (ejInstance.current === null) {
initEditor();
}
return () => {
ejInstance?.current?.destroy();
ejInstance.current = null;
};
}, []);
return (
<>
<Card.Root
variant={'subtle'}
width="100%"
maxWidth="840px"
minHeight="sm"
justifyContent="center"
alignItems="center"
>
<Card.Header>
<Heading textAlign="center">Editor</Heading>
</Card.Header>
<Card.Body
width="90%"
css={{
'& *': {
fontSize: 'revert',
fontWeight: 'revert'
},
...editorJsStyles
}}
>
<div className="editorjs" id="editorjs"></div>
</Card.Body>
</Card.Root>
</>
);
}
const editorJsStyles:
| SystemStyleObject
| Omit<Array<SystemStyleObject | undefined>, keyof any[]>
| undefined = {
'& .ce-block--selected .ce-block__content, \
& .ce-inline-toolbar, \
& .codex-editor--narrow .ce-toolbox, \
& .ce-conversion-toolbar, \
& .ce-settings, \
& .ce-settings__button, \
& .ce-toolbar__settings-btn, \
& .cdx-button, \
& .ce-popover': {
background: 'colorPalette.500',
border: 'none'
},
'& .ce-inline-tool, \
& .ce-conversion-toolbar__label, \
& .ce-toolbox__button, \
& .cdx-settings-button, \
& .ce-toolbar__plus': {
color: 'colorPalette.500'
},
'& ::selection': {
background: 'colorPalette.500'
},
'& .cdx-settings-button:hover, \
& .ce-settings__button:hover, \
& .ce-toolbox__button--active, \
& .ce-toolbox__button:hover, \
& .cdx-button:hover, \
& .ce-inline-toolbar__dropdown:hover, \
& .ce-inline-tool:hover, \
& .ce-popover__item:hover, \
& .ce-toolbar__settings-btn:hover': {
background: 'colorPalette.500',
color: 'fg'
},
'& .cdx-notify--error': {
background: 'red !important'
},
'& .cdx-notify__cross::after, & .cdx-notify__cross::before': {
background: 'white'
},
'& .ce-toolbar__plus:hover, \
& .ce-popover__container': {
backgroundColor: 'bg.emphasized',
color: 'colorPalette.500',
border: 'none'
},
'& .ce-popover-item:hover:not(.ce-popover-item--no-hover)': {
backgroundColor: 'colorPalette.500',
color: 'fg'
},
'& .cdx-search-field': {
background: 'bg.muted',
color: 'fg',
border: 'none'
},
'& .ce-popover-item__title, \
& .ce-popover-item__icon': {
color: 'fg'
},
'& .ce-popover-item-separator': {
color: 'bg.muted'
},
'& .ce-toolbar__settings-btn': {
color: 'white'
},
'& .ce-toolbar__settings-btn:hover': {
color: 'black'
}
};

View file

@ -1,6 +1,6 @@
import { Button, Card, Stack, Text, Wrap } from '@chakra-ui/react';
import isHotkey from 'is-hotkey';
import React, { KeyboardEvent, MouseEvent, useCallback, useEffect, useMemo } from 'react';
import React, { KeyboardEvent, MouseEvent, useCallback, useMemo } from 'react';
import { createEditor, Descendant, Editor, Element as SlateElement, Transforms } from 'slate';
import { withHistory } from 'slate-history';
import {

View file

@ -6,7 +6,6 @@ import { useIdentity } from '@app/client/hooks/identity';
import { useToastMutation } from '@app/client/hooks/useToastMutation';
import { useUserOneQuery } from '@app/client/hooks/useUserOneQuery';
import {
Box,
Button,
Card,
Heading,

View file

@ -1,9 +1,9 @@
import { call } from '@app/common';
import { ensureIdentity } from '@app/server/helpers';
import { IdentityContext } from '@app/server/identity';
import { prisma, uuid } from '@app/server/prisma/client';
import { prisma } from '@app/server/prisma/client';
import { MutationUserUpdateArgs, User } from '@generated/types';
import { toUserSchema } from './mappers/userMapper';
import { call } from '@app/common';
export async function UserUpdateResolver(
_: any,
@ -12,7 +12,7 @@ export async function UserUpdateResolver(
): Promise<User> {
ensureIdentity(identity);
if (input.id != identity.id) throw new Error('Operation is not permitted.'); //todo: add admin access
if (input.id !== identity.id) throw new Error('Operation is not permitted.');
if (input.description != null && input.description.length > 700)
throw new Error('Description is too long.');

View file

@ -7,7 +7,7 @@ import 'dotenv/config';
import express from 'express';
import fs from 'fs';
import { GraphQLJSON } from 'graphql-scalars';
import https from 'https';
import http from 'http';
import path from 'path';
import ViteExpress from 'vite-express';
import { toAppConfig } from './config';
@ -18,11 +18,16 @@ import { getIdentityContext, IdentityContext } from './identity';
export const config = toAppConfig();
const __dirname = import.meta.dirname;
const key = fs.readFileSync(path.join(__dirname + '../../../certs/selfsigned.key'));
const cert = fs.readFileSync(path.join(__dirname + '../../../certs/selfsigned.crt'));
// todo - make built-in ssl conditional
// const key = fs.readFileSync(path.join(__dirname + '../../../certs/selfsigned.key'));
// const cert = fs.readFileSync(path.join(__dirname + '../../../certs/selfsigned.crt'));
const app = express();
const server = https.createServer({ key, cert }, app);
// todo - make built-in ssl conditional
// const server = https.createServer({ key, cert }, app);
const server = http.createServer(app);
const typeDefs = fs.readFileSync(path.join(__dirname, 'graphql', 'schema.graphql'), 'utf8');