Skip to content

Commit

Permalink
Fix bugs with package management, fix pasting from Chrome, add <detai…
Browse files Browse the repository at this point in the history
…ls> and <summary> editing
  • Loading branch information
salmenf committed Oct 19, 2023
1 parent 15a9de1 commit 9978158
Show file tree
Hide file tree
Showing 27 changed files with 515 additions and 542 deletions.
2 changes: 1 addition & 1 deletion @webwriter/app-desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webwriter/app-desktop",
"version": "0.8.2",
"version": "0.8.3",
"description": "Windows/Mac/Linux version of WebWriter",
"private": true,
"author": "Frederic Salmen <frederic@fsalmen.de>",
Expand Down
2 changes: 1 addition & 1 deletion @webwriter/app-desktop/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion @webwriter/app-desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "webwriter"
version = "0.8.2"
version = "0.8.3"
description = "Windows/Mac/Linux version of WebWriter"
authors = ["Frederic Salmen <frederic@fsalmen.de>"]
license = "UNLICENSED"
Expand Down
2 changes: 2 additions & 0 deletions @webwriter/core/localization/generated/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,5 +413,7 @@
'spaceKey': `Leertaste`,
'tabKey': `⭾ Tab`,
'upKey': `↑ Hoch`,
's3b3ea038c5d3bb06': `Division`,
'se6cdad455e2d8c02': `Insert a division`,
};

14 changes: 11 additions & 3 deletions @webwriter/core/model/environment/tauri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,19 @@ export async function search(text: string, params?: {size?: number, from?: numbe
export async function pm(command: string, commandArgs: string[] = [], json=true, cwd?: string) {
const cmdArgs = [command, ...(json ? ["--json"]: []), ...commandArgs]
const opts = cwd? {cwd}: {}
console.info(`[TAURI] ${cwd? cwd: await appDir()}> bin/yarn ${[...cmdArgs, "--mutex file"].join(" ")}`)
const output = await Command.sidecar("bin/yarn", [...cmdArgs, "--mutex file"], opts).execute()
if(output.stderr) {
const err = output.stderr.split("\n").map((e: any) => JSON.parse(e))
const errors = err.filter((e: any) => e.type === "error")
const warnings = err.filter((e: any) => e.type === "warning")
const err = output.stderr.split("\n").map((e: any) => {
try {
console.error(JSON.parse(e))
}
catch(err) {
console.error(e)
}
})
const errors = err.filter((e: any) => e?.type === "error")
const warnings = err.filter((e: any) => e?.type === "warning")
warnings.forEach((w: any) => console.warn(w.data))
if(err?.some((e: any) => e?.type === "error")) {
throw err
Expand Down
2 changes: 1 addition & 1 deletion @webwriter/core/model/schemas/packageschema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ const PackageObjectSchema = z.object({
imports: z.record(z.string().startsWith("#"), z.record(z.string())).optional(),
editingConfig: EditingConfig.optional(),
installed: z.boolean().optional().default(false),
outdated: z.boolean().optional().default(false),
latest: SemVer.schema.optional(),
imported: z.boolean().optional().default(false),
watching: z.boolean().optional().default(false),
reloadCount: z.number().optional().default(0),
Expand Down
42 changes: 30 additions & 12 deletions @webwriter/core/model/schemas/resourceschema/editingstyles.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ html::-webkit-scrollbar-button:vertical:single-button:increment:disabled {
border-color: var(--sl-color-gray-400) transparent transparent transparent;
}

* {
outline: none;
}

a:not([href]) {
text-decoration: underline;
color: #0000EE;
Expand Down Expand Up @@ -145,25 +149,43 @@ figure.ProseMirror-selectednode::before {
-webkit-user-select: none !important;
}

.ww-widget[editable]::after {
.ProseMirror > :not(.ProseMirror-widget) {
position: relative;
}

.ProseMirror > :not(.ProseMirror-widget)::after {
content: "";
position: absolute;
right: -14px;
right: -18px;
top: 0;
width: 6px;
border-right: 6px solid transparent;
background: none;
height: 100%;
border-radius: 4px;
cursor: pointer;
width: 20px;
}

.ww-widget[editable]:hover::after {
background: var(--sl-color-primary-300);
.ProseMirror *:not([data-ww-inline]):hover {
outline: 1px dotted var(--sl-color-gray-400);
outline-offset: 2px;
}
/*
.ProseMirror > *:hover::after {
border-color: var(--sl-color-gray-100);
}
.ww-widget[editable][data-ww-selected]::after {
background: var(--sl-color-primary-400);
.ProseMirror > *:is([data-ww-selected], :has([data-ww-selected]))::after {
border-color: var(--sl-color-gray-200);
}
.ProseMirror > *:is([data-ww-selected]:hover, :has([data-ww-selected]:hover))::after {
border-color: var(--sl-color-gray-300);
}
.ww-widget[editable][data-ww-deleting]::after {
border-color: var(--sl-color-danger-400);
}*/

.ww-widget[editable][data-ww-deleting]::before {
content: "";
position: absolute;
Expand All @@ -177,10 +199,6 @@ figure.ProseMirror-selectednode::before {
height: 100%;
}

.ww-widget[editable][data-ww-deleting]::after {
background: var(--sl-color-danger-400);
}

.ww-widget#ww_preview {
position: relative;
display: block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export function toAttributes(node: Node | Attrs, extraAttrs?: Attrs) {
const attrSpec: (k: string) => AttributeSpec & {private?: boolean} | undefined = (k: string) => complex? (node.type?.spec?.attrs ?? {})[k]: {}
for (const [k, v] of Object.entries(attrs)) {
const spec = attrSpec(k)
if(k !== "data" && v !== undefined && (spec?.default !== v) && !spec?.private) {
if(k !== "data" && v && (spec?.default !== v) && !spec?.private) {
outputAttrs[k] = Array.isArray(v)? v.join(" "): v
}
if(k === "data") {
Expand Down
9 changes: 7 additions & 2 deletions @webwriter/core/model/schemas/resourceschema/plugins/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,18 @@ export const basePlugin = () => ({
content: "text | phrasing*",
whitespace: "pre"
}),
div: HTMLElementSpec({
tag: "div",
group: "flow palpable",
content: "flow*"
}),
pre: HTMLElementSpec({
tag: "pre",
group: "flow palpable",
content: "text | phrasing*",
whitespace: "pre"
}),
unknownElement: {
/*unknownElement: {
attrs: {
tagName: {},
otherAttrs: {default: {}}
Expand All @@ -133,7 +138,7 @@ export const basePlugin = () => ({
"data-ww-editing": CustomElementName.safeParse(node.attrs.tagName).success? "unknowncustom": "unknownbuiltin",
"data-ww-tagname": node.attrs.tagName
}]
},
},*/
},
topNode: "explorable",
keymap: baseKeymap,
Expand Down
111 changes: 91 additions & 20 deletions @webwriter/core/model/schemas/resourceschema/plugins/modal.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,96 @@
import { TextSelection, Command, EditorState, NodeSelection, AllSelection } from "prosemirror-state";
import { SchemaPlugin } from ".";
import { range } from "../../../../utility";
import { HTMLElementSpec } from "../htmlelementspec";
import {Node, ResolvedPos, NodeType, Attrs, NodeRange, Fragment} from "prosemirror-model"
import {canSplit, liftTarget} from "prosemirror-transform"

export const modalPlugin = () => ({
dialog: HTMLElementSpec({
tag: "dialog",
group: "flow sectioningroot",
content: "flow*",
attrs: {
open: {default: undefined}
}
}),
details: HTMLElementSpec({
tag: "details",
group: "flow sectioningroot interactive palpable",
content: `summary flow*`,
attrs: {
open: {default: undefined}
export function getNodePath($pos: ResolvedPos, excludeRoot=true) {
return range($pos.depth + 1).map(k => $pos.node(k)).slice(excludeRoot? 1: 0)
}

export function getPosPath($pos: ResolvedPos, excludeRoot=true) {
return range($pos.depth + 1).map(k => $pos.before(k + 1)).slice(excludeRoot? 1: 0)
}

export function findAncestor($pos: ResolvedPos, predicate: (value: [number, Node], index: number, array: [number, Node][]) => boolean) {
const nodePath = getNodePath($pos)
const posPath = getPosPath($pos)
return posPath.map((pos, i) => [pos, nodePath[i]] as [number, Node]).find(predicate) ?? []
}

export function ancestorOfType($pos: ResolvedPos, type: string) {
return findAncestor($pos, ([_, node]) => node?.type.name === type)
}

function selectDetailsContent(split=false): Command {
return (state, dispatch, view) => {
const {selection, doc} = state
const pType = state.schema.nodes["p"]!
const [detailsPos, details] = ancestorOfType(selection.$from, "details")
const [summaryPos, summary] = ancestorOfType(selection.$from, "summary")
const nodePath = getNodePath(selection.$from)
if(details && summary && split) {

let tr = state.tr.setNodeAttribute(detailsPos! - 1, "open", true)
tr = tr.deleteSelection()
tr = tr.split(tr.selection.from, undefined, [{type: pType}])
dispatch && dispatch(tr)
return true
}
}),
summary: HTMLElementSpec({
tag: "summary",
content: "heading"
})
return false
}
}

export const modalPlugin = () => ({
nodes: {
dialog: HTMLElementSpec({
tag: "dialog",
group: "flow sectioningroot",
content: "flow*",
attrs: {
open: {default: undefined}
}
}),
details: HTMLElementSpec({
tag: "details",
group: "flow sectioningroot interactive palpable",
content: `summary flow*`,
attrs: {
open: {default: undefined}
}
}),
summary: HTMLElementSpec({
tag: "summary",
content: "phrasing*" // simplified until phrase editing is fixed
})
},
keymap: {
"Enter": selectDetailsContent(true),
"ArrowDown": selectDetailsContent(),
"Backspace": (state, dispatch, view) => {
const {selection, doc} = state
const [summaryPos, summary] = ancestorOfType(selection.$from, "summary")
if(summary && selection.from === summaryPos) {

}
/*
console.log(getNodePath(selection.$from), getPosPath(selection.$from))
const [detailsPos, details] = ancestorOfType(selection.$from, "details")
const [summaryPos, summary] = detailsPos? [
detailsPos + 1,
details?.child(0).type.name === "summary"? details?.child(0): undefined
]: []
const open = details?.attrs.open
console.log(details, summaryPos, selection.from)
if(details && summaryPos !== undefined && selection.from === summaryPos) {
console.log("backspace handled")
let tr = state.tr.setSelection(TextSelection.create(doc, selection.from - 2))
dispatch && dispatch(tr)
return true
}*/
return false
},
}
} as SchemaPlugin)
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ export function toggleOrUpdateMark(mark: string, attrs: any = {}) {

export const phrasingPlugin = () => ({
nodes: {
text: {
group: "phrasing",
inline: true
},
br: HTMLElementSpec({
tag: "br",
group: "phrasing",
Expand All @@ -58,6 +54,10 @@ export const phrasingPlugin = () => ({
group: "phrasing",
inline: true
}),
text: {
group: "phrasing",
inline: true
},
_phrase: HTMLElementSpec({
tag: "span",
content: "text? | phrasing*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ export function packageWidgetNodeSpec(pkg: Package): NodeSpec {
const mediaTypes = getMediaTypesOfContent(pkg.editingConfig?.content)
const mediaNodeNames = mediaTypes
.map(t => t.slice(1).replaceAll("/", "__").replaceAll("-", "_"))
const maybeMediaParseRules = mediaTypes.length > 0? [

]: []

const maybeMediaParseRules = mediaTypes.length > 0? []: []
return {
group: "flow widget",
widget: true,
Expand All @@ -83,6 +80,7 @@ export function packageWidgetNodeSpec(pkg: Package): NodeSpec {
...styleAttrs
},
parseDOM : [{tag: unscopePackageName(pkg.name), getAttrs: (dom: HTMLElement ) => {
console.log(dom)
return {
id: dom.getAttribute("id"),
editable: dom.getAttribute("editable") ?? false,
Expand Down
9 changes: 9 additions & 0 deletions @webwriter/core/model/schemas/resourceschema/themes/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,13 @@ blockquote {
padding: 0.4rem 0.8rem;
border-left: 10px solid #ccc;
color: var(--text-light);
}

details {
border-left: 2px solid black;
padding-left: 1ch;
}

details p {
margin: 0;
}
Loading

0 comments on commit 9978158

Please sign in to comment.