8000 fix(notes): keep typing when a thing's page is first saved, and open only web links by adeelahmad · Pull Request #124 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 9 additions & 4 deletions nextjs-frontend/components/notes/block-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Props = {
};

const LENS_LINK = /^(recording|entity|collection|speaker|page):\d+$/;
const WEB_LINK = /^(https?:|mailto:)/i;

function toBase64(bytes: Uint8Array): string {
let s = "";
Expand Down Expand Up @@ -144,16 +145,19 @@ export default function BlockEditor({ markdown, doc, readOnly, onChange, search,
editor.mode = "page";
host.current.replaceChildren(editor);

// Links to things in Lens open in the app, not as web addresses.
// Links to things in Lens open in the app, not as web addresses. Other links open only as web or mail addresses:
// BlockSuite renders any href it is given, and the Markdown may come from the assistant (`javascript:` and such).
const MouseEvent) => {
const a = (e.composedPath().find((n) => n instanceof HTMLAnchorElement) ?? null) as HTMLAnchorElement | null;
const href = a?.getAttribute("href") ?? "";
if (!LENS_LINK.test(href)) return;
if (!a) return;
const href = (a.getAttribute("href") ?? "").trim();
if (WEB_LINK.test(href)) return;
e.preventDefault();
e.stopPropagation();
latest.current.onOpenLink(href);
if (e.type === "click" && LENS_LINK.test(href)) latest.current.onOpenLink(href);
};
host.current.addEventListener("click", onClick, true);
host.current.addEventListener("auxclick", onClick, true);

let timer: ReturnType<typeof setTimeout> | undefined;
const save = async (flush = false) => {
Expand Down Expand Up @@ -183,6 +187,7 @@ export default function BlockEditor({ markdown, doc, readOnly, onChange, search,
clearTimeout(timer);
changed.dispose();
el.removeEventListener("click", onClick, true);
el.removeEventListener("auxclick", onClick, true);
el.replaceChildren();
collection.dispose();
};
Expand Down
4 changes: 2 additions & 2 deletions nextjs-frontend/components/notes/note-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function NotePage({ id, about }: { id?: number; about?: string }) {
const loadedFor = useRef<string | null>(null);
useEffect(() => {
if (!page) return;
const k = `${page.id ?? "draft"}:${page.about ?? ""}`;
const k = page.about ?? `page:${page.id}`;
if (loadedFor.current === k) return;
loadedFor.current = k;
setTitle(page.title);
Expand Down Expand Up @@ -263,7 +263,7 @@ export function NotePage({ id, about }: { id?: number; about?: string }) {
{saved?.updated_at && <span>Changed {shortDate(saved.updated_at)}</span>}
</div>
<BlockEditor
key={`${page.id ?? "draft"}:${page.about ?? ""}`}
key={page.about ?? `page:${page.id}`}
markdown={page.body ?? ""}
doc={saved?.doc ?? null}
readOnly={!canEdit}
Expand Down
Loading
0