Path: blob/master/src/packages/frontend/editors/slate/elements/details/index.tsx
1702 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { CSSProperties } from "react";6import { load } from "cheerio";78import { register, SlateElement } from "../register";9import { dict } from "@cocalc/util/misc";1011export const STYLE = {12cursor: "pointer",13background: "#f6f6f6",14color: "black",15padding: "0.5rem 1rem",16borderRadius: "5px",17} as CSSProperties;1819export interface Details extends SlateElement {20type: "details";21isInline?: boolean;22open?: boolean;23summary: string;24}2526register({27slateType: "details",2829StaticElement: ({ attributes, children, element }) => {30const node = element as Details;31return (32<details {...{ ...attributes, ...{ open: node.open } }} style={STYLE}>33{node.summary && (34<summary style={{ cursor: "pointer", display: "list-item" }}>35{node.summary}36</summary>37)}38{children}39</details>40);41},4243toSlate: ({ children, state, token }) => {44const attrs = dict(state.attrs as any);45const $ = load("");46const x = $(token.content);47const summary = x.find("summary").text().trim();48return {49type: "details",50children,51isInline: token.type == "html_inline",52open: attrs.open,53summary,54};55},56});575859