ianstormtaylor / slate

A completely customizable framework for building rich text editors. (Currently in beta.)
http://slatejs.org
MIT License
29.59k stars 3.23k forks source link

Unable to create custom hyperscript shorthands? (slate-hyperscript@0.100.0) #5599

Open beorn opened 7 months ago

beorn commented 7 months ago

Using I don't seem to be able to create any custom elements (or HyperscriptShorthands). The documentation is "sparse" :) and the way I think it's supposed to work, the types seem broken:

import { createHyperscript } from "slate-hyperscript"

const h = createHyperscript({
  elements: {
    p: { type: "paragraph" },
    item: { type: "item" },
    text: {}
  }
})

h(
  "editor",
  {},
  h("cursor"),
  h("item", {}, h("p", {}, "p1")),
)

This results in the attached TS2345 error from TS for the h("item") and h("p") tags.

Screenshot 2024-02-01 at 16 44 53
dylans commented 7 months ago

I think the tests have perhaps the best examples for using slate-hyperscript, e.g. https://github.com/ianstormtaylor/slate/blob/main/packages/slate/test/operations/set_node/remove-undefined.tsx