All Projects → TeemuKoivisto → prosemirror-dev-toolkit

TeemuKoivisto / prosemirror-dev-toolkit

Licence: MIT license
Injectable developer tools for ProseMirror rich-text editors implemented in Svelte and TypeScript.

Programming Languages

typescript
32286 projects
Svelte
593 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects
SCSS
7915 projects
shell
77523 projects

Projects that are alternatives of or similar to prosemirror-dev-toolkit

Portal
A clojure tool to navigate through your data.
Stars: ✭ 239 (+443.18%)
Mutual labels:  inspector, devtools
devtools-highlighter
DevTools extension that finds and highlights elements in the page
Stars: ✭ 29 (-34.09%)
Mutual labels:  inspector, devtools
svelte-toy
A toy for svelte data stores
Stars: ✭ 73 (+65.91%)
Mutual labels:  devtools, svelte
Rawkit
🦊 Immediately Open Chrome DevTools when debugging Node.js apps
Stars: ✭ 306 (+595.45%)
Mutual labels:  inspector, devtools
React Inspect Props
React properties inspector with the power of Redux DevTools
Stars: ✭ 31 (-29.55%)
Mutual labels:  inspector, devtools
Ply
CSS inspection aided by visual regression pruning
Stars: ✭ 370 (+740.91%)
Mutual labels:  inspector, devtools
InAppDevTools
Android library with a collection of tools for debugging, inspecting and reporting from within your own app
Stars: ✭ 26 (-40.91%)
Mutual labels:  inspector, devtools
Nim
Streamline Your Node.js Debugging Workflow with Chromium (Chrome, Edge, More) DevTools.
Stars: ✭ 168 (+281.82%)
Mutual labels:  inspector, devtools
mdebug
基于React开发的新一代web调试工具,支持React组件调试,类似于Chrome Devtools。A Lightweight, Easy To Extend Web Debugging Tool Build With React
Stars: ✭ 237 (+438.64%)
Mutual labels:  inspector, devtools
svelte-datagrid
Svelte data grid spreadsheet best best features and performance from excel
Stars: ✭ 48 (+9.09%)
Mutual labels:  svelte
hagura-sveltekit
A minimal markdown blog template built using SvelteKit
Stars: ✭ 51 (+15.91%)
Mutual labels:  svelte
svelte-leaflet
Svelte component for leaflet.
Stars: ✭ 37 (-15.91%)
Mutual labels:  svelte
sveltekit-blog-template
A SvelteKit blog template
Stars: ✭ 79 (+79.55%)
Mutual labels:  svelte
editor
An interactive scientific editor built with ProseMirror, React and Redux - by Curvenote.
Stars: ✭ 157 (+256.82%)
Mutual labels:  prosemirror
curl2ab
Convert cURL command line to ab (apache bench)
Stars: ✭ 22 (-50%)
Mutual labels:  svelte
hitboxtracker
🔨 Dev-tool that demonstrates on client-side true position of the hitboxes calculated by server
Stars: ✭ 34 (-22.73%)
Mutual labels:  devtools
fastify-vite
This plugin lets you load a Vite client application and set it up for Server-Side Rendering (SSR) with Fastify.
Stars: ✭ 497 (+1029.55%)
Mutual labels:  svelte
ed
Text editing with media widgets
Stars: ✭ 56 (+27.27%)
Mutual labels:  prosemirror
svelte-typescript-setups
Examples and tests of different bundler setups for Svelte with Typescript and PostCSS (Tailwind)
Stars: ✭ 50 (+13.64%)
Mutual labels:  svelte
ctx-core
A composable monorepo web-service/front-end toolkit
Stars: ✭ 25 (-43.18%)
Mutual labels:  svelte

prosemirror-dev-toolkit version package minified size package size

This is a rewrite of prosemirror-dev-tools which I'm a big fan of, yet have felt could use some improvements. Since it didn't seem that actively maintained anymore and also because I wanted to remove the hard dependency to React, use TypeScript and make the whole thing smaller, I took it to my own hands to rewrite it in Svelte.

Unlike React, Svelte compiles directly to JS without having to bundle a runtime which should make the library smaller to use in projects that don't use React. I also pruned some of the extra dependencies by using out-of-the-box Svelte features and have experimented making the library injectable as a stand-alone script.

Demo

npm i prosemirror-dev-toolkit

And use it eg:

import { applyDevTools } from 'prosemirror-dev-toolkit'

import { EditorState } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
import { schema } from 'prosemirror-schema-basic'
import { exampleSetup } from 'prosemirror-example-setup'

const view = new EditorView(document.querySelector('#editor') as HTMLElement, {
  state: EditorState.create({
    doc: schema.nodes.doc.createAndFill(),
    plugins: exampleSetup({ schema })
  })
})
applyDevTools(view)

Code sandbox

API

type ButtonPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
interface DevToolsOpts {
  devToolsExpanded?: boolean
  buttonPosition?: ButtonPosition
}
declare function applyDevTools(view: EditorView, opts?: DevToolsOpts): void
declare function removeDevTools(): void
declare global {
  interface Window {
    applyDevTools: typeof applyDevTools
    editorView?: EditorView
    _node?: { node: PMNode; pos: number }
    _doc?: {
      [key: string]: any
    }
    _trs?: Transaction[]
    _plugin?: [Plugin | undefined, unknown]
  }
}
export { applyDevTools, removeDevTools, ButtonPosition, DevToolsOpts }

I am adding properties to the global Window interface which may or may not that convenient. From my perspective I don't have to ts-ignore those assignments but if you use those properties in your repos you'll have to obey the types or receive rather weird errors (that may take a moment to figure out).

Features

As was in the old tools, prosemirror-dev-toolkit consists of 6 tabs which interact with the PM editor in various ways. Basically what happens is dev-toolkit injects itself into the DOM, visible as the rounded button in the bottom right corner, and then sets the dispatchTransaction prop of the EditorView to be able to track transactions.

In addition it can persist snapshots and hydrate them which I enhanced by adding export/import from JSON as well as ensuring the functionality doesn't break with Yjs. In the old dev-tools there was a node picker to inspect PM nodes that I have not had time to remake.

For quick live editor instance debugging I have added a script to inject the dev-toolkit directly from CDN: inject.js Not 100% bulletproof but works in most cases. Improvements welcome. Might use it to turn this into a Chrome extension.

State

State tab

Shows the current toJSON'd state.doc as well as the selection, augmented by a few additional properties, active marks and a simple summary of the document. These tree views were implemented in the original with react-json-tree library which although ported to Svelte (svelte-json-tree) felt a little complex and difficult to customize. Instead, I wrote a simple recursive component and then rolled it out as a separate Svelte library: https://github.com/TeemuKoivisto/svelte-tree-view

History

History tab

History tab shows the last dispatched transaction with a diff of the changed content, diff of the changed selection, toDOM'd document slice between the selection start and end and the actual transaction at the bottom.

Copying the old diffing logic was perhaps the most annoying feature to implement as it required me to wrap my head around the jsondiffpatch's delta format and figure out how to rewrite it in Svelte. Somewhat interesting topic, certainly, but quite tedious. I changed the original colors to a perhaps more distinct palette and added the transaction to the history entry as well. I've found it quite useful.

I added some new features to the trees such as 'log' and 'copy' buttons which log the node to window (eg into _node variable) or add it to your clipboard.

You can hydrate the doc from a transaction by double-clicking it. I have thought of adding import/export of transaction history to allow replaying them but haven't had time for it.

Plugins

Plugins tab

Shows the current plugins and their states. This is mostly the same as in the old tools but I added some convenience buttons to for example log the plugin to a _plugin object that you can manipulate from the console. Handy for inspecting the plugin editor props which are not visible from the plugin state.

As a side-note, I'm sure I have not covered all possible object types in svelte-tree-view beyond the common Objects/Arrays/Maps/Sets. Make an issue or PR if something's weird.

Schema

Schema tab

Shows the current schema's nodes and marks. Same as in the old tools but I added circular node detection to make the recursion a little lighter. Not strictly needed as all the nodes are uncollapsed and can't be auto-expanded but hey, it's there.

Structure

Structure tab

A bit more complicated tab it shows the document in a neat block view with a side panel to inspect the node contents. Auto-expands the content whenever it's within reasonable size (less than 50 children). You can double click nodes to scroll into them. Thought about allowing selecting and deleting nodes directly from the DocView.

Snapshots

Snapshots tab

Shows the stored snapshots (toJSON'd topNode eg "doc") in localStorage. The changes I've made are switching to date strings instead of unix timestamps for default names. Then, you can double-click the snapshot to edit its name. 'Show' button replaces the current doc with the snapshot doc, allowing you to revert it with 'Hide'. 'Restore' does a one-way replacement of the doc with the snapshot. And well I say one-way but since I don't erase the actual PM history you can Ctrl-z your way out of it.

'Export' toJSONs and downloads the snapshot. You have to now double-click 'Delete' to prevent occasional misclicks. There's also a new 'Import snapshot' button above the main panel to replace the doc with exported snapshot.

How to run locally

You need pnpm installed globally.

  1. pnpm
  2. pnpm start

Should open a React app at http://localhost:3300/prosemirror-dev-toolkit/

Tests

To run the end-to-end tests you must launch the site (pnpm site) and then run pnpm --filter prosemirror-dev-tolkit test:e2e. NOTE: the snapshots might locally fail. They should work in CI however and hopefully they'll be fixed when I next time migrate Cypress and its libraries.

Contributing

Contributions and issues are more than welcome! This project uses changesets https://github.com/changesets/changesets to generate changelogs but in short, when you commit from terminal the changeset prompt is opened in which you should write your functionality using conventional commits https://www.conventionalcommits.org/en/v1.0.0/ to create a changeset (which is for something that changes the library for the downstream users).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].