control
This commit is contained in:
parent
30037995f5
commit
19027ae643
|
@ -341,7 +341,7 @@ export function buildMenuItems(schema: Schema) {
|
||||||
)
|
)
|
||||||
r.listMenu = [r.wrapBulletList as MenuItem, r.wrapOrderedList as MenuItem]
|
r.listMenu = [r.wrapBulletList as MenuItem, r.wrapOrderedList as MenuItem]
|
||||||
r.inlineMenu = [r.toggleStrong as MenuItem, r.toggleEm as MenuItem, r.toggleMark as MenuItem]
|
r.inlineMenu = [r.toggleStrong as MenuItem, r.toggleEm as MenuItem, r.toggleMark as MenuItem]
|
||||||
r.fullMenu = [...r.inlineMenu, tMenu as MenuItem, ...r.listMenu]
|
r.fullMenu = [...r.inlineMenu, tMenu as MenuItem, ...r.listMenu].filter(Boolean)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ export class SelectionTooltip {
|
||||||
this.tooltip = document.createElement('div')
|
this.tooltip = document.createElement('div')
|
||||||
this.tooltip.className = 'tooltip'
|
this.tooltip.className = 'tooltip'
|
||||||
view.dom.parentNode.appendChild(this.tooltip)
|
view.dom.parentNode.appendChild(this.tooltip)
|
||||||
|
console.debug('[prosemirror] selection view', view)
|
||||||
|
console.debug('[prosemirror] selection menu', buildMenuItems(schema).fullMenu)
|
||||||
const { dom } = renderGrouped(view, buildMenuItems(schema).fullMenu as any)
|
const { dom } = renderGrouped(view, buildMenuItems(schema).fullMenu as any)
|
||||||
this.tooltip.appendChild(dom)
|
this.tooltip.appendChild(dom)
|
||||||
this.update(view, null)
|
this.update(view, null)
|
||||||
|
|
|
@ -15,7 +15,6 @@ import { useStore } from '@nanostores/solid'
|
||||||
import { createMemo } from 'solid-js'
|
import { createMemo } from 'solid-js'
|
||||||
|
|
||||||
const isText = (x) => x && x.doc && x.selection
|
const isText = (x) => x && x.doc && x.selection
|
||||||
const isState = (x) => typeof x.lastModified !== 'string' && Array.isArray(x.drafts)
|
|
||||||
const isDraft = (x): boolean => x && (x.text || x.path)
|
const isDraft = (x): boolean => x && (x.text || x.path)
|
||||||
const mod = 'Ctrl'
|
const mod = 'Ctrl'
|
||||||
|
|
||||||
|
@ -133,7 +132,7 @@ export const createCtrl = (initial): [Store<State>, { [key: string]: any }] => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchData = async (): Promise<State> => {
|
const readStoredState = async (): Promise<State> => {
|
||||||
const state: State = unwrap(store)
|
const state: State = unwrap(store)
|
||||||
const room = window.location.pathname?.slice(1).trim()
|
const room = window.location.pathname?.slice(1).trim()
|
||||||
const args = { room, draft: room }
|
const args = { room, draft: room }
|
||||||
|
@ -168,7 +167,13 @@ export const createCtrl = (initial): [Store<State>, { [key: string]: any }] => {
|
||||||
config: undefined
|
config: undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
const newst = {
|
for (const draft of parsed.drafts || []) {
|
||||||
|
if (!isDraft(draft)) {
|
||||||
|
throw new ServiceError('invalid_draft', draft)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
...parsed,
|
...parsed,
|
||||||
text,
|
text,
|
||||||
extensions,
|
extensions,
|
||||||
|
@ -176,18 +181,6 @@ export const createCtrl = (initial): [Store<State>, { [key: string]: any }] => {
|
||||||
args,
|
args,
|
||||||
lastModified: new Date(parsed.lastModified)
|
lastModified: new Date(parsed.lastModified)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const draft of parsed.drafts) {
|
|
||||||
if (!isDraft(draft)) {
|
|
||||||
throw new ServiceError('invalid_draft', draft)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isState(newst)) {
|
|
||||||
throw new ServiceError('invalid_state', newst)
|
|
||||||
}
|
|
||||||
|
|
||||||
return newst
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getTheme = (state: State) => ({ theme: state.config.theme })
|
const getTheme = (state: State) => ({ theme: state.config.theme })
|
||||||
|
@ -197,7 +190,6 @@ export const createCtrl = (initial): [Store<State>, { [key: string]: any }] => {
|
||||||
...newState(),
|
...newState(),
|
||||||
loading: 'initialized',
|
loading: 'initialized',
|
||||||
drafts: [],
|
drafts: [],
|
||||||
fullscreen: store.fullscreen,
|
|
||||||
lastModified: new Date(),
|
lastModified: new Date(),
|
||||||
error: undefined,
|
error: undefined,
|
||||||
text: undefined
|
text: undefined
|
||||||
|
@ -216,37 +208,37 @@ export const createCtrl = (initial): [Store<State>, { [key: string]: any }] => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
let data = await fetchData()
|
let state = await readStoredState()
|
||||||
try {
|
try {
|
||||||
if (data.args.room) {
|
if (state.args.room) {
|
||||||
data = await doStartCollab(data)
|
state = await doStartCollab(state)
|
||||||
} else if (data.args.text) {
|
} else if (state.args.text) {
|
||||||
data = await doOpenDraft(data, {
|
state = await doOpenDraft(state, {
|
||||||
text: { ...JSON.parse(data.args.text) },
|
text: { ...JSON.parse(state.args.text) },
|
||||||
lastModified: new Date()
|
lastModified: new Date()
|
||||||
})
|
})
|
||||||
} else if (data.args.draft) {
|
} else if (state.args.draft) {
|
||||||
const draft = await loadDraft(data.config, data.args.draft)
|
const draft = await loadDraft(state.config, state.args.draft)
|
||||||
data = await doOpenDraft(data, draft)
|
state = await doOpenDraft(state, draft)
|
||||||
} else if (data.path) {
|
} else if (state.path) {
|
||||||
const draft = await loadDraft(data.config, data.path)
|
const draft = await loadDraft(state.config, state.path)
|
||||||
data = await doOpenDraft(data, draft)
|
state = await doOpenDraft(state, draft)
|
||||||
} else if (!data.text) {
|
} else if (!state.text) {
|
||||||
const text = createEmptyText()
|
const text = createEmptyText()
|
||||||
const extensions = createExtensions({
|
const extensions = createExtensions({
|
||||||
config: data.config ?? store.config,
|
config: state.config ?? store.config,
|
||||||
markdown: data.markdown ?? store.markdown,
|
markdown: state.markdown ?? store.markdown,
|
||||||
keymap: keymap
|
keymap: keymap
|
||||||
})
|
})
|
||||||
data = { ...data, text, extensions }
|
state = { ...state, text, extensions }
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
data = { ...data, error: error.errorObject }
|
state = { ...state, error: error.errorObject }
|
||||||
}
|
}
|
||||||
|
|
||||||
setState({
|
setState({
|
||||||
...data,
|
...state,
|
||||||
config: { ...data.config, ...getTheme(data) },
|
config: { ...state.config, ...getTheme(state) },
|
||||||
loading: 'initialized'
|
loading: 'initialized'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,10 @@
|
||||||
min-width: 50%;
|
min-width: 50%;
|
||||||
min-height: fit-content;
|
min-height: fit-content;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
border: 1px dotted rgb(0 0 0 / 80%);
|
border: 1px dashed rgb(0 0 0 / 80%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ProseMirror {
|
||||||
a {
|
a {
|
||||||
color: rgb(0 100 200);
|
color: rgb(0 100 200);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
@ -62,7 +63,6 @@ button:focus {
|
||||||
border-color: #666;
|
border-color: #666;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ProseMirror {
|
|
||||||
color: var(--foreground);
|
color: var(--foreground);
|
||||||
background-color: var(--background);
|
background-color: var(--background);
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { initRouter } from '../stores/router'
|
||||||
|
|
||||||
const slug = Astro.params.slug?.toString()
|
const slug = Astro.params.slug?.toString()
|
||||||
if (slug.endsWith('.map')) {
|
if (slug.endsWith('.map')) {
|
||||||
return
|
return Astro.redirect('/404')
|
||||||
}
|
}
|
||||||
|
|
||||||
const article = await apiClient.getArticle({ slug })
|
const article = await apiClient.getArticle({ slug })
|
||||||
|
|
Loading…
Reference in New Issue
Block a user