mirror of
https://github.com/kou029w/quot.git
synced 2025-01-31 14:28:06 +00:00
Compare commits
No commits in common. "b725b250d332ff1649e49a927dde33e73ea04fbe" and "23e6bf327bc2c79fca62e79b38920016f299ee9a" have entirely different histories.
b725b250d3
...
23e6bf327b
7 changed files with 33 additions and 109 deletions
|
@ -12,7 +12,7 @@ async function views(fastify: FastifyInstance) {
|
|||
},
|
||||
{
|
||||
bundle: true,
|
||||
minify: process.env.NODE_ENV !== "development",
|
||||
minify: true,
|
||||
entryPoints: [entryPoint],
|
||||
define: {
|
||||
"import.meta.env.QUOT_API_ENDPOINT": JSON.stringify(
|
||||
|
|
34
app/package-lock.json
generated
34
app/package-lock.json
generated
|
@ -11,8 +11,7 @@
|
|||
"@exampledev/new.css": "^1.1.3",
|
||||
"@fastify/http-proxy": "^8.2.2",
|
||||
"@lexical/history": "^0.4.1",
|
||||
"@lexical/link": "^0.4.1",
|
||||
"@lexical/rich-text": "^0.4.1",
|
||||
"@lexical/plain-text": "^0.4.1",
|
||||
"@tsconfig/node18-strictest-esm": "^1.0.1",
|
||||
"esbuild": "^0.15.7",
|
||||
"esbuild-register": "^3.3.3",
|
||||
|
@ -139,17 +138,6 @@
|
|||
"lexical": "0.4.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/link": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/link/-/link-0.4.1.tgz",
|
||||
"integrity": "sha512-566lQymmuBe3Y7UDyaaTs+VDlElbu1WhnjT9lVDk0BXag7MA8tv/f60XptWnTK1pv/Dobm/CyLmyLae55OuflQ==",
|
||||
"dependencies": {
|
||||
"@lexical/utils": "0.4.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"lexical": "0.4.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/list": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/list/-/list-0.4.1.tgz",
|
||||
|
@ -161,10 +149,10 @@
|
|||
"lexical": "0.4.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/rich-text": {
|
||||
"node_modules/@lexical/plain-text": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/rich-text/-/rich-text-0.4.1.tgz",
|
||||
"integrity": "sha512-EI4ul3y1hqMp0VS/4D8aOyR41ysz1KaYgkm6PyrRXEMyK8uKmVubJP83RkOU2fWkTVtdrMjM6aeT1qX849LetA==",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/plain-text/-/plain-text-0.4.1.tgz",
|
||||
"integrity": "sha512-cNFLXhOfR0coUFGA6aPGcHr6a+Y9ZrkETMM78+XV9J8iVsKij4/katFhsqACQDna4vSfXuqjTitCRtiFaDevDg==",
|
||||
"peerDependencies": {
|
||||
"@lexical/clipboard": "0.4.1",
|
||||
"@lexical/selection": "0.4.1",
|
||||
|
@ -1211,14 +1199,6 @@
|
|||
"@lexical/selection": "0.4.1"
|
||||
}
|
||||
},
|
||||
"@lexical/link": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/link/-/link-0.4.1.tgz",
|
||||
"integrity": "sha512-566lQymmuBe3Y7UDyaaTs+VDlElbu1WhnjT9lVDk0BXag7MA8tv/f60XptWnTK1pv/Dobm/CyLmyLae55OuflQ==",
|
||||
"requires": {
|
||||
"@lexical/utils": "0.4.1"
|
||||
}
|
||||
},
|
||||
"@lexical/list": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/list/-/list-0.4.1.tgz",
|
||||
|
@ -1227,10 +1207,10 @@
|
|||
"@lexical/utils": "0.4.1"
|
||||
}
|
||||
},
|
||||
"@lexical/rich-text": {
|
||||
"@lexical/plain-text": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/rich-text/-/rich-text-0.4.1.tgz",
|
||||
"integrity": "sha512-EI4ul3y1hqMp0VS/4D8aOyR41ysz1KaYgkm6PyrRXEMyK8uKmVubJP83RkOU2fWkTVtdrMjM6aeT1qX849LetA==",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/plain-text/-/plain-text-0.4.1.tgz",
|
||||
"integrity": "sha512-cNFLXhOfR0coUFGA6aPGcHr6a+Y9ZrkETMM78+XV9J8iVsKij4/katFhsqACQDna4vSfXuqjTitCRtiFaDevDg==",
|
||||
"requires": {}
|
||||
},
|
||||
"@lexical/selection": {
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
"@exampledev/new.css": "^1.1.3",
|
||||
"@fastify/http-proxy": "^8.2.2",
|
||||
"@lexical/history": "^0.4.1",
|
||||
"@lexical/link": "^0.4.1",
|
||||
"@lexical/rich-text": "^0.4.1",
|
||||
"@lexical/plain-text": "^0.4.1",
|
||||
"@tsconfig/node18-strictest-esm": "^1.0.1",
|
||||
"esbuild": "^0.15.7",
|
||||
"esbuild-register": "^3.3.3",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"extends": "@tsconfig/node18-strictest-esm/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"lib": ["esnext", "dom", "dom.iterable"],
|
||||
"lib": ["dom", "dom.iterable"],
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "solid-js/h",
|
||||
"noPropertyAccessFromIndexSignature": false
|
||||
|
|
|
@ -23,7 +23,8 @@ header h1 {
|
|||
margin: 0;
|
||||
}
|
||||
|
||||
header h1 > :is(a, a:hover) {
|
||||
header h1 > a,
|
||||
header h1 > a:hover {
|
||||
color: var(--nc-ac-1);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,12 +8,3 @@
|
|||
border-top-color: var(--nc-bg-3);
|
||||
box-shadow: 0 1px var(--nc-bg-3);
|
||||
}
|
||||
|
||||
.editor :is(h1, h2, h3, h4, h5, h6) {
|
||||
padding: unset;
|
||||
font-size: unset;
|
||||
}
|
||||
|
||||
.editor p {
|
||||
margin: unset;
|
||||
}
|
||||
|
|
|
@ -1,23 +1,17 @@
|
|||
import {
|
||||
$createLineBreakNode,
|
||||
$createParagraphNode,
|
||||
$createTextNode,
|
||||
$getRoot,
|
||||
$isElementNode,
|
||||
createEditor,
|
||||
} from "lexical";
|
||||
import { registerHistory, createEmptyHistoryState } from "@lexical/history";
|
||||
import {
|
||||
$createHeadingNode,
|
||||
HeadingNode,
|
||||
registerRichText,
|
||||
} from "@lexical/rich-text";
|
||||
import { $createAutoLinkNode, AutoLinkNode } from "@lexical/link";
|
||||
import { registerPlainText } from "@lexical/plain-text";
|
||||
import { onCleanup, onMount } from "solid-js";
|
||||
import type Pages from "../../protocol/pages";
|
||||
import "./editor.css";
|
||||
|
||||
const urlMatcher = /https?:\/\/[^\s]+/;
|
||||
const editor = createEditor({ nodes: [HeadingNode, AutoLinkNode] });
|
||||
const editor = createEditor();
|
||||
|
||||
function ref(el: HTMLElement) {
|
||||
editor.setRootElement(el);
|
||||
|
@ -31,66 +25,25 @@ export default (props: {
|
|||
}) => {
|
||||
const initialEditorState = () => {
|
||||
const root = $getRoot();
|
||||
const [title, ...lines] = props.text.split("\n");
|
||||
const titleNode = $createHeadingNode("h2");
|
||||
titleNode.append($createTextNode(title));
|
||||
root.append(titleNode);
|
||||
for (const line of lines) {
|
||||
const lineNode = $createParagraphNode();
|
||||
const indent = line.match(/^\s*/)?.[0]?.length ?? 0;
|
||||
lineNode.setIndent(indent);
|
||||
let text = line.slice(indent);
|
||||
let match: RegExpMatchArray | null = null;
|
||||
while ((match = text.match(urlMatcher))) {
|
||||
const offset = text.slice(0, match.index!);
|
||||
const input = match[0]!;
|
||||
const link = $createAutoLinkNode(input);
|
||||
link.append($createTextNode(match[0]));
|
||||
lineNode.append($createTextNode(offset), link);
|
||||
text = text.slice(offset.length + input.length);
|
||||
}
|
||||
lineNode.append($createTextNode(text));
|
||||
root.append(lineNode);
|
||||
}
|
||||
if (root.getFirstChild()) return;
|
||||
const paragraphNode = $createParagraphNode();
|
||||
const text = props.text
|
||||
.split("\n")
|
||||
.flatMap((line) => [$createTextNode(line), $createLineBreakNode()])
|
||||
.slice(0, -1);
|
||||
paragraphNode.append(...text);
|
||||
root.append(paragraphNode);
|
||||
};
|
||||
onCleanup(registerRichText(editor, initialEditorState));
|
||||
onCleanup(registerPlainText(editor, initialEditorState));
|
||||
onCleanup(registerHistory(editor, createEmptyHistoryState(), 333));
|
||||
onCleanup(
|
||||
editor.registerUpdateListener(() =>
|
||||
editor.update(() => {
|
||||
const root = $getRoot();
|
||||
const defaultTitle = new Date()
|
||||
.toLocaleDateString(navigator.language, {
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
})
|
||||
.replaceAll("/", "-");
|
||||
const [titleNode, ...lineNodes] = root.getChildren();
|
||||
const title =
|
||||
titleNode?.getTextContent().trim() ||
|
||||
(lineNodes.length === 0 ? "" : defaultTitle);
|
||||
const lines = lineNodes.map((line) => {
|
||||
const indent = $isElementNode(line) ? line.getIndent() : 0;
|
||||
return `${" ".repeat(indent)}${line.getTextContent()}`;
|
||||
});
|
||||
const text = [title, ...lines].join("\n");
|
||||
props.onUpdatePage({ id: props.id, title, text });
|
||||
onMount(() => {
|
||||
onCleanup(
|
||||
editor.registerTextContentListener((text) => {
|
||||
const [title] = text.split("\n");
|
||||
props.onUpdatePage({ id: props.id, title: title ?? "", text });
|
||||
})
|
||||
)
|
||||
);
|
||||
onMount(() => editor.focus());
|
||||
return (
|
||||
<article
|
||||
ref={ref}
|
||||
onclick={(e) => {
|
||||
const el = e.target.parentElement;
|
||||
if (el instanceof HTMLAnchorElement) {
|
||||
window.open(el.href, "_blank", "noreferrer");
|
||||
}
|
||||
}}
|
||||
class="editor"
|
||||
contenteditable
|
||||
/>
|
||||
);
|
||||
);
|
||||
editor.focus();
|
||||
});
|
||||
return <article ref={ref} class="editor" contenteditable />;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue