-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
237 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
:root { | ||
--syntax_normal: #1b1e23; | ||
--syntax_comment: #a9b0bc; | ||
--syntax_number: #20a5ba; | ||
--syntax_keyword: #c30771; | ||
--syntax_atom: #10a778; | ||
--syntax_string: #008ec4; | ||
--syntax_error: #ffbedc; | ||
--syntax_unknown_variable: #838383; | ||
--syntax_known_variable: #005f87; | ||
--syntax_matchbracket: #20bbfc; | ||
--syntax_key: #6636b4; | ||
--mono_fonts: 82%/1.5 Menlo, Consolas, monospace; | ||
} | ||
|
||
.Inspector { | ||
display: flex; | ||
background-color: white; | ||
width: 100%; | ||
overflow: auto; | ||
height: 100%; | ||
padding: 1px 1px 0px 1px; | ||
} | ||
|
||
.observablehq--expanded, | ||
.observablehq--collapsed, | ||
.observablehq--function, | ||
.observablehq--import, | ||
.observablehq--string:before, | ||
.observablehq--string:after, | ||
.observablehq--gray { | ||
color: var(--syntax_normal); | ||
} | ||
|
||
.observablehq--collapsed, | ||
.observablehq--inspect a { | ||
cursor: pointer; | ||
} | ||
|
||
.observablehq--field { | ||
text-indent: -1em; | ||
margin-left: 1em; | ||
} | ||
|
||
.observablehq--empty { | ||
color: var(--syntax_comment); | ||
} | ||
|
||
.observablehq--keyword, | ||
.observablehq--blue { | ||
color: #3182bd; | ||
} | ||
|
||
.observablehq--forbidden, | ||
.observablehq--pink { | ||
color: #e377c2; | ||
} | ||
|
||
.observablehq--orange { | ||
color: #e6550d; | ||
} | ||
|
||
.observablehq--null, | ||
.observablehq--undefined, | ||
.observablehq--boolean { | ||
color: var(--syntax_atom); | ||
} | ||
|
||
.observablehq--number, | ||
.observablehq--bigint, | ||
.observablehq--date, | ||
.observablehq--regexp, | ||
.observablehq--symbol, | ||
.observablehq--green { | ||
color: var(--syntax_number); | ||
} | ||
|
||
.observablehq--index, | ||
.observablehq--key { | ||
color: var(--syntax_key); | ||
} | ||
|
||
.observablehq--empty { | ||
font-style: oblique; | ||
} | ||
|
||
.observablehq--string, | ||
.observablehq--purple { | ||
color: var(--syntax_string); | ||
} | ||
|
||
.observablehq--error, | ||
.observablehq--red { | ||
color: #e7040f; | ||
} | ||
|
||
.observablehq--inspect { | ||
font: var(--mono_fonts); | ||
overflow-x: auto; | ||
display: block; | ||
white-space: pre; | ||
} | ||
|
||
.observablehq--error .observablehq--inspect { | ||
word-break: break-all; | ||
white-space: pre-wrap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import React, { useEffect, useRef, useMemo } from 'react' | ||
import { Handle } from 'hypermerge' | ||
|
||
import Automerge from 'automerge' | ||
import * as Observable from '@observablehq/inspector' | ||
import Delta from 'quill-delta' | ||
import ContentTypes from '../../ContentTypes' | ||
import { ContentProps } from '../Content' | ||
import { useDocument, useStaticCallback } from '../../Hooks' | ||
import Badge from '../Badge' | ||
import * as ContentData from '../../ContentData' | ||
// import '@observablehq/inspector/src/style.css' | ||
import './Inspector.css' | ||
|
||
interface InspectorDoc {} | ||
|
||
interface Props extends ContentProps { | ||
uniquelySelected?: boolean | ||
} | ||
|
||
Inspector.minWidth = 6 | ||
Inspector.minHeight = 2 | ||
Inspector.defaultWidth = 12 | ||
Inspector.defaultHeight = 18 | ||
|
||
export default function Inspector(props: Props) { | ||
const [doc, changeDoc] = useDocument<InspectorDoc>(props.hypermergeUrl) | ||
|
||
const [ref] = useInspector({ | ||
doc, | ||
change(fn) { | ||
changeDoc((doc) => fn(doc)) | ||
}, | ||
}) | ||
|
||
return <div className="Inspector" ref={ref} onPaste={stopPropagation} /> | ||
} | ||
|
||
function useInspector({ doc, change }): [React.Ref<HTMLDivElement>, Observable.Inspector | null] { | ||
const ref = useRef<HTMLDivElement>(null) | ||
const inspector = useRef<Observable.Inspector | null>(null) | ||
// const makeChange = useStaticCallback(change) | ||
|
||
useEffect(() => { | ||
if (!ref.current) return () => {} | ||
|
||
const container = ref.current | ||
inspector.current = new Observable.Inspector(container) | ||
inspector.current.pending() | ||
|
||
return () => { | ||
inspector.current = null | ||
} | ||
}, [ref.current]) // eslint-disable-line | ||
|
||
useEffect(() => { | ||
if (!inspector.current) return | ||
|
||
inspector.current.fulfilled(doc) | ||
}, [doc]) | ||
|
||
return [ref, inspector.current] | ||
} | ||
|
||
function stopPropagation(e: React.SyntheticEvent) { | ||
e.stopPropagation() | ||
e.nativeEvent.stopImmediatePropagation() | ||
} | ||
|
||
async function createFrom( | ||
contentData: ContentData.ContentData, | ||
handle: Handle<InspectorDoc>, | ||
callback | ||
) { | ||
handle.change((doc) => {}) | ||
callback() | ||
} | ||
|
||
function create({ text }, handle: Handle<InspectorDoc>, callback) { | ||
handle.change((doc) => {}) | ||
callback() | ||
} | ||
|
||
function InspectorInList(props: ContentProps) { | ||
const [doc] = useDocument<InspectorDoc>(props.hypermergeUrl) | ||
function onDragStart(e: React.DragEvent) { | ||
e.dataTransfer.setData('application/pushpin-url', props.url) | ||
} | ||
|
||
if (!doc) return null | ||
|
||
return ( | ||
<div className="DocLink"> | ||
<span draggable onDragStart={onDragStart}> | ||
<Badge icon="sticky-note" /> | ||
</span> | ||
<div className="DocLink__title">{props.selfId}</div> | ||
</div> | ||
) | ||
} | ||
|
||
const supportsMimeType = (mimeType) => true | ||
|
||
ContentTypes.register({ | ||
type: 'inspect', | ||
name: 'Inspector', | ||
icon: 'cogs', | ||
contexts: { | ||
board: Inspector, | ||
workspace: Inspector, | ||
list: InspectorInList, | ||
}, | ||
create, | ||
createFrom, | ||
supportsMimeType, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters