Skip to content

Instantly share code, notes, and snippets.

@uptonking
uptonking / node-view.js
Created June 16, 2021 15:47 — forked from marijnh/node-view.js
Demo of a ProseMirror editor that uses a nested code editor
const {EditorState, Selection} = require("prosemirror-state")
const {MenuBarEditorView} = require("prosemirror-menu")
const {DOMParser, DOMSerializer, Schema} = require("prosemirror-model")
const {schema: baseSchema} = require("prosemirror-schema-basic")
const {exampleSetup} = require("prosemirror-example-setup")
const {keymap} = require("prosemirror-keymap")
const CodeMirror = require("codemirror")
require("codemirror/mode/javascript/javascript")
let view, menuView, schema = new Schema({
@uptonking
uptonking / Editor.tsx
Created June 16, 2021 16:10 — forked from TeemuKoivisto/Editor.tsx
Updated ProseMirror + React example with TypeScript and styled-components from @esmevane using NodeViews
import * as React from 'react'
import ReactDOM from 'react-dom'
import { EditorState } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
import { Node, Schema } from 'prosemirror-model'
import applyDevTools from 'prosemirror-dev-tools'
import styled from 'styled-components'
// Here we have the (too simple) React component which
// we'll be rendering content into.
@uptonking
uptonking / mutableSource.tsx
Created August 19, 2021 07:35 — forked from Aslemammad/mutableSource.tsx
Consistent version of useMutableSource.
// Consistent version of `useMutableSource`, Inspired by https://github.com/pmndrs/valtio/blob/master/src/useMutableSource.ts
import { useEffect, useRef, useState } from 'react';
const TARGET = Symbol('target');
const GET_VERSION = Symbol('getVersion');
export type Source<TargetType extends any, VersionType extends any> = {
[TARGET]: TargetType;
[GET_VERSION]: (target: TargetType) => VersionType;
};
@uptonking
uptonking / markdown-cheatsheet.md
Created September 9, 2021 15:27 — forked from jonschlinkert/markdown-cheatsheet.md
A better markdown cheatsheet.
Skype
Min: 6
Max: 32
Can contain: a-z A-Z 0-9 . , _ -
Other: Must start with a letter
Twitter
Min: 1
Max: 15
Can contain: a-z A-Z 0-9 _
@uptonking
uptonking / Table.tsx
Created January 3, 2022 15:06 — forked from tannerlinsley/Table.tsx
A quick snippet of an early ReactTable v8 table that renders!
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import { createTable } from 'react-table'
type Row = {
firstName: string
lastName: string
@uptonking
uptonking / README.md
Last active October 25, 2022 11:47 — forked from jed/LICENSE.txt
generate random UUIDs

UUID

Returns a random v4 UUID of the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx, where each x is replaced with a random hexadecimal digit from 0 to f, and y is replaced with a random hexadecimal digit from 8 to b.

There's also @LeverOne's approach using iteration, which is one byte shorter.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE

@uptonking
uptonking / y-pouchdb.ts
Created December 2, 2022 11:02 — forked from samwillis/y-pouchdb.ts
(Alpha) PouchDB integration for Yjs
import * as Y from 'yjs'
import * as mutex from 'lib0/mutex.js'
import { Observable } from 'lib0/observable.js'
import PouchDB from 'pouchdb';
// This is the name of the top level Y.Map that is used to construct the main pouchDB
// JSON document.
const topDataYMapName = 'data';
@uptonking
uptonking / proposal.jsx
Created January 2, 2023 11:11 — forked from jamesmfriedman/proposal.jsx
MDC Foundation Proposal
/**
* Current Adapter Example
* This is a simple adapter, some are extremely complex...
* It is not immediately obvious why some code lives in the adapter and some in the foundation
* The Select alone is over 700 lines of component logic...
**/
MDCCheckboxFoundation({
addClass: (className) => this.root_.classList.add(className),
removeClass: (className) => this.root_.classList.remove(className),
setNativeControlAttr: (attr, value) => this.nativeCb_.setAttribute(attr, value),
@uptonking
uptonking / MarkdownField.ts
Created January 24, 2023 23:31 — forked from oranoran/MarkdownField.ts
Payload CMS - alternative rich text editor using rich-markdown-editor
import React, { useCallback, FunctionComponent } from 'react'
import { useField } from 'payload/components/forms'
import { Field } from 'payload/types'
import Editor from 'rich-markdown-editor'
// Make sure to never re-render the editor, since it tracks the value on its own.
const MemorizedEditor = React.memo(Editor, (prev, next) => prev.id === next.id)
type FieldWithPath = Field & { path?: string }