Skip to content

[Experimental] Live AsciiDoc editor #96

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

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2910331
Rough? Gross? Cool?
benjaminleonard Apr 16, 2024
eecdbe0
Pre-demo commit
benjaminleonard Apr 30, 2024
7288132
Merge branch 'tome' into live-asciidoc-notes
benjaminleonard Dec 17, 2024
8fd2114
Switch to monaco
benjaminleonard Dec 17, 2024
cea30e3
Continued cleanup
benjaminleonard Dec 17, 2024
5e49280
Tweaks
benjaminleonard Dec 17, 2024
bf47ae8
Update API to use env vars and general type fixes
benjaminleonard Dec 17, 2024
f8e52a3
More type fixes
benjaminleonard Dec 17, 2024
f895851
Licenses
benjaminleonard Dec 17, 2024
d7788ee
Ignore notes subfolder
benjaminleonard Dec 17, 2024
2a4357e
Test user for preview
benjaminleonard Dec 18, 2024
b5f63d3
Missed an auth check
benjaminleonard Dec 18, 2024
a1585d2
Merge branch 'main' into live-asciidoc-notes
benjaminleonard Jan 15, 2025
0826a92
Updates
benjaminleonard Jan 24, 2025
6fedc26
Merge branch 'main' into live-asciidoc-notes
benjaminleonard Jan 24, 2025
c4c2791
Update app/routes/notes._index.tsx
benjaminleonard Jan 24, 2025
724ba5a
Lint
benjaminleonard Jan 24, 2025
a899da0
Try `noExternal` code mirror basic setup
benjaminleonard Jan 24, 2025
6942ac8
Add `@uiw/codemirror-themes` to `noExternal`
benjaminleonard Jan 24, 2025
adca510
API within Remix instead
benjaminleonard Jan 27, 2025
4994518
Switch to liveblocks
benjaminleonard Jan 31, 2025
541d86b
Remove unused deps
benjaminleonard Jan 31, 2025
01a9b70
Auth tweak
benjaminleonard Jan 31, 2025
4d7f5d6
Last updated / tweaks / use storage / live title update
benjaminleonard Feb 3, 2025
2d0071d
Move server stuff into `notes.server`
benjaminleonard Feb 3, 2025
81ff67f
Tweak errors and URL
benjaminleonard Feb 3, 2025
c667f14
Title input improvements
benjaminleonard Feb 3, 2025
5dcc881
Merge branch 'main' into live-asciidoc-notes
benjaminleonard Feb 3, 2025
7c00686
Licenses
benjaminleonard Feb 3, 2025
585956b
`allowImportingTsExtensions`
benjaminleonard Feb 3, 2025
ccb061f
Use react query for sidebar
benjaminleonard Feb 3, 2025
9837b90
Readd lodash types
benjaminleonard Feb 3, 2025
1be5a8a
Remove upload artifact
benjaminleonard Feb 3, 2025
f185d3c
Rough migration to tiptap instead of codemirror
benjaminleonard Feb 19, 2025
6c190d8
Update package-lock.json
benjaminleonard Feb 19, 2025
c03ef2d
Add window mode (add focus)
benjaminleonard Feb 20, 2025
bf18572
Upgrade DS
benjaminleonard Feb 20, 2025
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
10 changes: 9 additions & 1 deletion app/components/AsciidocBlocks/Document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
import { Content, type DocumentBlock } from '@oxide/react-asciidoc'

// add styles for main
// max-w-full flex-shrink overflow-hidden 800:overflow-visible 800:pr-10 1200:w-[calc(100%-var(--toc-width))] 1200:pr-16 print:p-0
const CustomDocument = ({ document }: { document: DocumentBlock }) => (
<div
id="content"
Expand All @@ -16,4 +18,10 @@ const CustomDocument = ({ document }: { document: DocumentBlock }) => (
</div>
)

export { CustomDocument }
const MinimalDocument = ({ document }: { document: DocumentBlock }) => (
<div id="content" className="asciidoc-body max-w-[1040px]">
<Content blocks={document.blocks} />
</div>
)

export { CustomDocument, MinimalDocument }
30 changes: 15 additions & 15 deletions app/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ export const dropdownInnerStyles = `focus:outline-0 focus:bg-hover px-3 py-2 pr-

export const DropdownItem = ({
children,
classNames,
className,
onSelect,
}: {
children: ReactNode | string
classNames?: string
className?: string
onSelect?: () => void
}) => (
<Dropdown.Item
onSelect={onSelect}
className={cn(
dropdownOuterStyles,
classNames,
className,
dropdownInnerStyles,
!onSelect && 'cursor-default',
)}
Expand All @@ -42,12 +42,12 @@ export const DropdownItem = ({

export const DropdownSubTrigger = ({
children,
classNames,
className,
}: {
children: JSX.Element | string
classNames?: string
className?: string
}) => (
<Dropdown.SubTrigger className={cn(dropdownOuterStyles, classNames, dropdownInnerStyles)}>
<Dropdown.SubTrigger className={cn(dropdownOuterStyles, className, dropdownInnerStyles)}>
{children}
<Icon
name="carat-down"
Expand All @@ -59,13 +59,13 @@ export const DropdownSubTrigger = ({

export const DropdownLink = ({
children,
classNames,
className,
internal = false,
to,
disabled = false,
}: {
children: React.ReactNode
classNames?: string
className?: string
internal?: boolean
to: string
disabled?: boolean
Expand All @@ -76,7 +76,7 @@ export const DropdownLink = ({
className={cn(
'block ',
dropdownOuterStyles,
classNames,
className,
disabled && 'pointer-events-none',
)}
>
Expand All @@ -88,18 +88,18 @@ export const DropdownLink = ({

export const DropdownMenu = ({
children,
classNames,
className,
align = 'end',
}: {
children: React.ReactNode
classNames?: string
className?: string
align?: 'end' | 'start' | 'center' | undefined
}) => (
<Dropdown.Portal>
<Dropdown.Content
className={cn(
'menu overlay-shadow z-30 mt-2 min-w-[12rem] rounded border bg-raise border-secondary [&>*:last-child]:border-b-0',
classNames,
className,
)}
align={align}
>
Expand All @@ -110,16 +110,16 @@ export const DropdownMenu = ({

export const DropdownSubMenu = ({
children,
classNames,
className,
}: {
children: JSX.Element[]
classNames?: string
className?: string
}) => (
<Dropdown.Portal>
<Dropdown.SubContent
className={cn(
'menu overlay-shadow z-10 ml-2 max-h-[30vh] min-w-[12rem] overflow-y-auto rounded border bg-raise border-secondary [&>*:last-child]:border-b-0',
classNames,
className,
)}
>
{children}
Expand Down
15 changes: 13 additions & 2 deletions app/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { buttonStyle } from '@oxide/design-system'
import * as Dropdown from '@radix-ui/react-dropdown-menu'
import { Link, useFetcher } from '@remix-run/react'
import { useCallback, useState } from 'react'
import { useHotkeys } from 'react-hotkeys-hook'

import Icon from '~/components/Icon'
import NewRfdButton from '~/components/NewRfdButton'
import { useKey } from '~/hooks/use-key'
import { useRootLoaderData } from '~/root'
import type { RfdItem, RfdListItem } from '~/services/rfd.server'
import { userIsInternal } from '~/utils/rfdApi'

import { DropdownItem, DropdownMenu } from './Dropdown'
import { PublicBanner } from './PublicBanner'
Expand Down Expand Up @@ -53,7 +54,9 @@ export default function Header({ currentRfd }: { currentRfd?: RfdItem }) {
return false // Returning false prevents default behaviour in Firefox
}, [open])

useKey('mod+k', toggleSearchMenu)
useHotkeys('mod+k', toggleSearchMenu)

const isInternal = userIsInternal(user)

return (
<div className="sticky top-0 z-20">
Expand All @@ -79,6 +82,14 @@ export default function Header({ currentRfd }: { currentRfd?: RfdItem }) {
<Icon name="search" size={16} />
</button>
<Search open={open} onClose={() => setOpen(false)} />
{user && isInternal && (
<Link
to="/notes"
className="flex h-8 w-8 items-center justify-center rounded border text-tertiary bg-secondary border-secondary elevation-1 hover:bg-hover"
>
<Icon name="edit" size={16} />
</Link>
)}
<NewRfdButton />

{user ? (
Expand Down
6 changes: 3 additions & 3 deletions app/components/SelectRfdCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { Link, useNavigate } from '@remix-run/react'
import cn from 'classnames'
import fuzzysort from 'fuzzysort'
import { useCallback, useEffect, useRef, useState } from 'react'
import { useHotkeys } from 'react-hotkeys-hook'

import Icon from '~/components/Icon'
import { useKey } from '~/hooks/use-key'
import { useSteppedScroll } from '~/hooks/use-stepped-scroll'
import type { RfdItem, RfdListItem } from '~/services/rfd.server'
import { classed } from '~/utils/classed'
Expand All @@ -33,7 +33,7 @@ const SelectRfdCombobox = ({
// memoized to avoid render churn in useKey
const toggleCombobox = useCallback(() => setOpen(!open), [setOpen, open])

useKey('mod+/', toggleCombobox)
useHotkeys('mod+/', toggleCombobox)

const handleDismiss = () => setOpen(false)

Expand Down Expand Up @@ -220,7 +220,7 @@ const ComboboxItem = ({
}) => {
const [shouldPrefetch, setShouldPrefetch] = useState(false)

const timer = useRef<NodeJS.Timeout | null>(null)
const timer = useRef<ReturnType<typeof setTimeout> | null>(null)

function clear() {
if (timer.current) clearTimeout(timer.current)
Expand Down
2 changes: 1 addition & 1 deletion app/components/home/FilterDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const DropdownFilterItem = ({
}) => (
<DropdownItem
onSelect={onSelect}
classNames={selected ? 'bg-accent-secondary text-accent' : ''}
className={selected ? 'text-accent bg-accent-secondary' : ''}
>
{selected && <Outline />}
<div className="flex items-center justify-between">
Expand Down
79 changes: 79 additions & 0 deletions app/components/note/Editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright Oxide Computer Company
*/
import { EditorView } from '@codemirror/view'
import { createTheme, type CreateThemeOptions } from '@uiw/codemirror-themes'
import CodeMirror from '@uiw/react-codemirror'

const themeSettings: CreateThemeOptions['settings'] = {
background: 'var(--surface-raise)',
foreground: 'var(--content-default)',
caret: 'var(--base-neutral-800)',
selection: 'rgba(255, 255, 255, 0.1)',
selectionMatch: 'rgba(255, 255, 255, 0.2)',
gutterBackground: 'var(--base-neutral-200)',
gutterForeground: 'var(--base-neutral-600)',
gutterBorder: 'transparent',
lineHighlight: 'rgba(255, 255, 255, 0.1)',
}

export const theme = (options?: Partial<CreateThemeOptions>) => {
const { theme = 'dark' } = options || {}
return createTheme({
theme: theme,
settings: {
...themeSettings,
},
styles: [],
})
}

const EditorWrapper = ({
body,
onChange,
}: {
body: string
onChange: (string: string | undefined) => void
}) => {
return (
<CodeMirror
value={body}
onChange={onChange}
extensions={[
EditorView.theme({
'&': {
fontSize: '13px',
fontFamily: 'GT America Mono',
},
'.cm-line': {
paddingLeft: '12px',
},
'.cm-content': {
paddingTop: '8px',
paddingBottom: '8px',
},
}),
EditorView.lineWrapping,
]}
theme={theme()}
basicSetup={{
lineNumbers: true,
highlightActiveLine: true,
foldGutter: false,
dropCursor: true,
allowMultipleSelections: true,
indentOnInput: true,
bracketMatching: true,
closeBrackets: true,
autocompletion: false,
}}
className="h-full"
/>
)
}

export default EditorWrapper
Loading
Loading