@mdxeditor/editor 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CodeBlockEditor-7e15d01c.cjs +1 -0
- package/dist/CodeBlockEditor-85a8b6b0.js +79 -0
- package/dist/FrontmatterEditor-a8263f5d.js +119 -0
- package/dist/FrontmatterEditor-bd112c96.cjs +1 -0
- package/dist/JsxEditor-4511b188.js +110 -0
- package/dist/JsxEditor-85e636d6.cjs +1 -0
- package/dist/SandpackEditor-04d3c3ce.cjs +1 -0
- package/dist/SandpackEditor-0a3bfaf0.js +99 -0
- package/dist/TableEditor-0aedb943.js +428 -0
- package/dist/TableEditor-d0c5800f.cjs +1 -0
- package/dist/index-11db5fbf.js +3884 -0
- package/dist/index-731c8e58.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +66 -4540
- package/dist/style.css +132 -130
- package/dist/useCodeMirrorRef-89746e60.js +84 -0
- package/dist/useCodeMirrorRef-cba12130.cjs +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@codesandbox/sandpack-react"),r=require("react"),i=require("./index-731c8e58.cjs"),a=require("./useCodeMirrorRef-cba12130.cjs");require("@lexical/react/LexicalComposer"),require("@lexical/react/LexicalContentEditable"),require("@lexical/react/LexicalErrorBoundary"),require("@lexical/react/LexicalHorizontalRulePlugin"),require("@lexical/react/LexicalLinkPlugin"),require("@lexical/react/LexicalListPlugin"),require("@lexical/react/LexicalRichTextPlugin"),require("@lexical/react/LexicalTabIndentationPlugin"),require("classnames"),require("lexical"),require("@lexical/code"),require("@lexical/link"),require("@lexical/list"),require("@lexical/react/LexicalHorizontalRuleNode"),require("@lexical/rich-text"),require("mdast-util-directive"),require("mdast-util-from-markdown"),require("mdast-util-frontmatter"),require("mdast-util-gfm-table"),require("mdast-util-mdx"),require("micromark-extension-directive"),require("micromark-extension-frontmatter"),require("micromark-extension-gfm-table"),require("micromark-extension-mdxjs"),require("@lexical/utils"),require("@lexical/react/LexicalComposerContext"),require("@lexical/selection"),require("@lexical/react/LexicalHistoryPlugin"),require("mdast-util-to-markdown"),require("@radix-ui/react-popover"),require("@radix-ui/react-tooltip"),require("downshift"),require("@lexical/markdown"),require("@lexical/react/LexicalMarkdownShortcutPlugin"),require("@codemirror/lang-markdown"),require("react-diff-view"),require("unidiff"),require("@radix-ui/react-toolbar"),require("@radix-ui/react-select"),require("@radix-ui/react-dialog");exports.CodeBlockEditor=({nodeKey:t,code:l,language:c,onChange:u,focusEmitter:o})=>{const[n]=i.useEmitterValues("activeEditor"),d=a.useCodeMirrorRef(t,"codeblock",c),s=i.usePublisher("activeEditorType");r.useEffect((()=>{o.subscribe((()=>{var e,r;null==(r=null==(e=null==d?void 0:d.current)?void 0:e.getCodemirror())||r.focus(),s({type:"codeblock",nodeKey:t})}))}),[o,d,s,t]);const x=r.useCallback((e=>{null==n||n.update((()=>{u(e)}))}),[u,n]);return r.createElement("div",{className:i.styles.sandpackWrapper},r.createElement(e.SandpackProvider,null,r.createElement(e.CodeEditor,{showLineNumbers:!0,initMode:"immediate",key:c,filePath:`file.${c||"txt"}`,code:l,onCodeUpdate:x,ref:d})))};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { SandpackProvider, CodeEditor } from "@codesandbox/sandpack-react";
|
|
2
|
+
import React__default from "react";
|
|
3
|
+
import { u as useEmitterValues, a as usePublisher, s as styles } from "./index-11db5fbf.js";
|
|
4
|
+
import { u as useCodeMirrorRef } from "./useCodeMirrorRef-89746e60.js";
|
|
5
|
+
import "@lexical/react/LexicalComposer";
|
|
6
|
+
import "@lexical/react/LexicalContentEditable";
|
|
7
|
+
import "@lexical/react/LexicalErrorBoundary";
|
|
8
|
+
import "@lexical/react/LexicalHorizontalRulePlugin";
|
|
9
|
+
import "@lexical/react/LexicalLinkPlugin";
|
|
10
|
+
import "@lexical/react/LexicalListPlugin";
|
|
11
|
+
import "@lexical/react/LexicalRichTextPlugin";
|
|
12
|
+
import "@lexical/react/LexicalTabIndentationPlugin";
|
|
13
|
+
import "classnames";
|
|
14
|
+
import "lexical";
|
|
15
|
+
import "@lexical/code";
|
|
16
|
+
import "@lexical/link";
|
|
17
|
+
import "@lexical/list";
|
|
18
|
+
import "@lexical/react/LexicalHorizontalRuleNode";
|
|
19
|
+
import "@lexical/rich-text";
|
|
20
|
+
import "mdast-util-directive";
|
|
21
|
+
import "mdast-util-from-markdown";
|
|
22
|
+
import "mdast-util-frontmatter";
|
|
23
|
+
import "mdast-util-gfm-table";
|
|
24
|
+
import "mdast-util-mdx";
|
|
25
|
+
import "micromark-extension-directive";
|
|
26
|
+
import "micromark-extension-frontmatter";
|
|
27
|
+
import "micromark-extension-gfm-table";
|
|
28
|
+
import "micromark-extension-mdxjs";
|
|
29
|
+
import "@lexical/utils";
|
|
30
|
+
import "@lexical/react/LexicalComposerContext";
|
|
31
|
+
import "@lexical/selection";
|
|
32
|
+
import "@lexical/react/LexicalHistoryPlugin";
|
|
33
|
+
import "mdast-util-to-markdown";
|
|
34
|
+
import "@radix-ui/react-popover";
|
|
35
|
+
import "@radix-ui/react-tooltip";
|
|
36
|
+
import "downshift";
|
|
37
|
+
import "@lexical/markdown";
|
|
38
|
+
import "@lexical/react/LexicalMarkdownShortcutPlugin";
|
|
39
|
+
import "@codemirror/lang-markdown";
|
|
40
|
+
import "react-diff-view";
|
|
41
|
+
import "unidiff";
|
|
42
|
+
import "@radix-ui/react-toolbar";
|
|
43
|
+
import "@radix-ui/react-select";
|
|
44
|
+
import "@radix-ui/react-dialog";
|
|
45
|
+
const CodeBlockEditor = ({ nodeKey, code, language, onChange, focusEmitter }) => {
|
|
46
|
+
const [activeEditor] = useEmitterValues("activeEditor");
|
|
47
|
+
const codeMirrorRef = useCodeMirrorRef(nodeKey, "codeblock", language);
|
|
48
|
+
const setActiveEditorType = usePublisher("activeEditorType");
|
|
49
|
+
React__default.useEffect(() => {
|
|
50
|
+
focusEmitter.subscribe(() => {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
(_b = (_a = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a.getCodemirror()) == null ? void 0 : _b.focus();
|
|
53
|
+
setActiveEditorType({ type: "codeblock", nodeKey });
|
|
54
|
+
});
|
|
55
|
+
}, [focusEmitter, codeMirrorRef, setActiveEditorType, nodeKey]);
|
|
56
|
+
const wrappedOnChange = React__default.useCallback(
|
|
57
|
+
(code2) => {
|
|
58
|
+
activeEditor == null ? void 0 : activeEditor.update(() => {
|
|
59
|
+
onChange(code2);
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
[onChange, activeEditor]
|
|
63
|
+
);
|
|
64
|
+
return /* @__PURE__ */ React__default.createElement("div", { className: styles.sandpackWrapper }, /* @__PURE__ */ React__default.createElement(SandpackProvider, null, /* @__PURE__ */ React__default.createElement(
|
|
65
|
+
CodeEditor,
|
|
66
|
+
{
|
|
67
|
+
showLineNumbers: true,
|
|
68
|
+
initMode: "immediate",
|
|
69
|
+
key: language,
|
|
70
|
+
filePath: `file.${language || "txt"}`,
|
|
71
|
+
code,
|
|
72
|
+
onCodeUpdate: wrappedOnChange,
|
|
73
|
+
ref: codeMirrorRef
|
|
74
|
+
}
|
|
75
|
+
)));
|
|
76
|
+
};
|
|
77
|
+
export {
|
|
78
|
+
CodeBlockEditor
|
|
79
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import YamlParser from "js-yaml";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import React__default from "react";
|
|
4
|
+
import { useForm, useFieldArray } from "react-hook-form";
|
|
5
|
+
import classNames from "classnames";
|
|
6
|
+
import { s as styles } from "./index-11db5fbf.js";
|
|
7
|
+
import "@lexical/react/LexicalComposer";
|
|
8
|
+
import "@lexical/react/LexicalContentEditable";
|
|
9
|
+
import "@lexical/react/LexicalErrorBoundary";
|
|
10
|
+
import "@lexical/react/LexicalHorizontalRulePlugin";
|
|
11
|
+
import "@lexical/react/LexicalLinkPlugin";
|
|
12
|
+
import "@lexical/react/LexicalListPlugin";
|
|
13
|
+
import "@lexical/react/LexicalRichTextPlugin";
|
|
14
|
+
import "@lexical/react/LexicalTabIndentationPlugin";
|
|
15
|
+
import "lexical";
|
|
16
|
+
import "@lexical/code";
|
|
17
|
+
import "@lexical/link";
|
|
18
|
+
import "@lexical/list";
|
|
19
|
+
import "@lexical/react/LexicalHorizontalRuleNode";
|
|
20
|
+
import "@lexical/rich-text";
|
|
21
|
+
import "mdast-util-directive";
|
|
22
|
+
import "mdast-util-from-markdown";
|
|
23
|
+
import "mdast-util-frontmatter";
|
|
24
|
+
import "mdast-util-gfm-table";
|
|
25
|
+
import "mdast-util-mdx";
|
|
26
|
+
import "micromark-extension-directive";
|
|
27
|
+
import "micromark-extension-frontmatter";
|
|
28
|
+
import "micromark-extension-gfm-table";
|
|
29
|
+
import "micromark-extension-mdxjs";
|
|
30
|
+
import "@lexical/utils";
|
|
31
|
+
import "@lexical/react/LexicalComposerContext";
|
|
32
|
+
import "@lexical/selection";
|
|
33
|
+
import "@lexical/react/LexicalHistoryPlugin";
|
|
34
|
+
import "mdast-util-to-markdown";
|
|
35
|
+
import "@radix-ui/react-popover";
|
|
36
|
+
import "@radix-ui/react-tooltip";
|
|
37
|
+
import "downshift";
|
|
38
|
+
import "@lexical/markdown";
|
|
39
|
+
import "@lexical/react/LexicalMarkdownShortcutPlugin";
|
|
40
|
+
import "@codemirror/lang-markdown";
|
|
41
|
+
import "@codesandbox/sandpack-react";
|
|
42
|
+
import "react-diff-view";
|
|
43
|
+
import "unidiff";
|
|
44
|
+
import "@radix-ui/react-toolbar";
|
|
45
|
+
import "@radix-ui/react-select";
|
|
46
|
+
import "@radix-ui/react-dialog";
|
|
47
|
+
const SvgArrowRight = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
48
|
+
maskType: "alpha"
|
|
49
|
+
} }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M10 17V7l5 5-5 5Z" })));
|
|
50
|
+
const ArrowRight = SvgArrowRight;
|
|
51
|
+
const SvgArrowDropDown = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
52
|
+
maskType: "alpha"
|
|
53
|
+
} }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "m12 15-5-5h10l-5 5Z" })));
|
|
54
|
+
const ArrowDown = SvgArrowDropDown;
|
|
55
|
+
const SvgDelete = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
56
|
+
maskType: "alpha"
|
|
57
|
+
} }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M5 17V6.5H4V5h4V4h4v1h4v1.5h-1V17H5Zm1.5-1.5h7v-9h-7v9ZM8 14h1.5V8H8v6Zm2.5 0H12V8h-1.5v6Z" })));
|
|
58
|
+
const DeleteIcon = SvgDelete;
|
|
59
|
+
const FrontmatterEditor = ({ yaml, onChange }) => {
|
|
60
|
+
const [expanded, setExpanded] = React__default.useState(true);
|
|
61
|
+
const yamlConfig = React__default.useMemo(() => {
|
|
62
|
+
if (!yaml) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
return Object.entries(YamlParser.load(yaml)).map(([key, value]) => ({ key, value }));
|
|
66
|
+
}, [yaml]);
|
|
67
|
+
const { register, control, watch } = useForm({
|
|
68
|
+
defaultValues: {
|
|
69
|
+
yamlConfig
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const { fields, append, remove } = useFieldArray({
|
|
73
|
+
control,
|
|
74
|
+
name: "yamlConfig"
|
|
75
|
+
});
|
|
76
|
+
React__default.useEffect(() => {
|
|
77
|
+
const subscription = watch(({ yamlConfig: yamlConfig2 }) => {
|
|
78
|
+
const yaml2 = yamlConfig2.reduce((acc, { key, value }) => {
|
|
79
|
+
if (key && value) {
|
|
80
|
+
acc[key] = value;
|
|
81
|
+
}
|
|
82
|
+
return acc;
|
|
83
|
+
}, {});
|
|
84
|
+
onChange(YamlParser.dump(yaml2).trim());
|
|
85
|
+
});
|
|
86
|
+
return () => subscription.unsubscribe();
|
|
87
|
+
}, [watch, onChange]);
|
|
88
|
+
return /* @__PURE__ */ React__default.createElement("div", { className: styles.frontmatterWrapper, "data-expanded": expanded, "data-editor-type": "frontmatter" }, /* @__PURE__ */ React__default.createElement(
|
|
89
|
+
"button",
|
|
90
|
+
{
|
|
91
|
+
className: styles.frontmatterToggleButton,
|
|
92
|
+
onClick: (e) => {
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
setExpanded((v) => !v);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
expanded ? /* @__PURE__ */ React__default.createElement(ArrowDown, null) : /* @__PURE__ */ React__default.createElement(ArrowRight, null),
|
|
98
|
+
"Document frontmatter"
|
|
99
|
+
), expanded && /* @__PURE__ */ React__default.createElement("form", null, /* @__PURE__ */ React__default.createElement("table", { className: styles.frontmatterEditorTable }, /* @__PURE__ */ React__default.createElement("colgroup", null, /* @__PURE__ */ React__default.createElement("col", null), /* @__PURE__ */ React__default.createElement("col", null), /* @__PURE__ */ React__default.createElement("col", null)), /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null, "Key"), /* @__PURE__ */ React__default.createElement("th", null, "Value"), /* @__PURE__ */ React__default.createElement("th", null))), /* @__PURE__ */ React__default.createElement("tbody", null, fields.map((item, index) => {
|
|
100
|
+
return /* @__PURE__ */ React__default.createElement("tr", { key: item.id }, /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(TableInput, { ...register(`yamlConfig.${index}.key`, { required: true }), autofocusIfEmpty: true })), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(TableInput, { ...register(`yamlConfig.${index}.value`, { required: true }) })), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement("button", { type: "button", onClick: () => remove(index), className: styles.iconButton }, /* @__PURE__ */ React__default.createElement(DeleteIcon, null))));
|
|
101
|
+
})), /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(
|
|
102
|
+
"button",
|
|
103
|
+
{
|
|
104
|
+
className: styles.primaryButton,
|
|
105
|
+
type: "button",
|
|
106
|
+
onClick: () => {
|
|
107
|
+
append({ key: "", value: "" });
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"Add new key"
|
|
111
|
+
)))))));
|
|
112
|
+
};
|
|
113
|
+
const TableInput = React__default.forwardRef(({ className, autofocusIfEmpty, ...props }, ref) => {
|
|
114
|
+
props.autoFocus = Boolean(!props.value && autofocusIfEmpty);
|
|
115
|
+
return /* @__PURE__ */ React__default.createElement("input", { className: classNames(styles.frontmatterInput, className), ...props, ref });
|
|
116
|
+
});
|
|
117
|
+
export {
|
|
118
|
+
FrontmatterEditor
|
|
119
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("js-yaml"),t=require("react"),r=require("react-hook-form"),l=require("classnames"),a=require("./index-731c8e58.cjs");function i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const l=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,l.get?l:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}require("@lexical/react/LexicalComposer"),require("@lexical/react/LexicalContentEditable"),require("@lexical/react/LexicalErrorBoundary"),require("@lexical/react/LexicalHorizontalRulePlugin"),require("@lexical/react/LexicalLinkPlugin"),require("@lexical/react/LexicalListPlugin"),require("@lexical/react/LexicalRichTextPlugin"),require("@lexical/react/LexicalTabIndentationPlugin"),require("lexical"),require("@lexical/code"),require("@lexical/link"),require("@lexical/list"),require("@lexical/react/LexicalHorizontalRuleNode"),require("@lexical/rich-text"),require("mdast-util-directive"),require("mdast-util-from-markdown"),require("mdast-util-frontmatter"),require("mdast-util-gfm-table"),require("mdast-util-mdx"),require("micromark-extension-directive"),require("micromark-extension-frontmatter"),require("micromark-extension-gfm-table"),require("micromark-extension-mdxjs"),require("@lexical/utils"),require("@lexical/react/LexicalComposerContext"),require("@lexical/selection"),require("@lexical/react/LexicalHistoryPlugin"),require("mdast-util-to-markdown"),require("@radix-ui/react-popover"),require("@radix-ui/react-tooltip"),require("downshift"),require("@lexical/markdown"),require("@lexical/react/LexicalMarkdownShortcutPlugin"),require("@codemirror/lang-markdown"),require("@codesandbox/sandpack-react"),require("react-diff-view"),require("unidiff"),require("@radix-ui/react-toolbar"),require("@radix-ui/react-select"),require("@radix-ui/react-dialog");const n=i(t),c=e=>n.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:24,height:24,fill:"currentColor",viewBox:"0 0 24 24",...e},n.createElement("mask",{id:"a",width:24,height:24,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},n.createElement("path",{d:"M0 0h24v24H0z"})),n.createElement("g",{mask:"url(#a)"},n.createElement("path",{d:"M10 17V7l5 5-5 5Z"}))),u=e=>n.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:24,height:24,fill:"currentColor",viewBox:"0 0 24 24",...e},n.createElement("mask",{id:"a",width:24,height:24,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},n.createElement("path",{d:"M0 0h24v24H0z"})),n.createElement("g",{mask:"url(#a)"},n.createElement("path",{d:"m12 15-5-5h10l-5 5Z"}))),o=e=>n.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:20,height:20,fill:"currentColor",viewBox:"0 0 20 20",...e},n.createElement("mask",{id:"a",width:20,height:20,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},n.createElement("path",{d:"M0 0h20v20H0z"})),n.createElement("g",{mask:"url(#a)"},n.createElement("path",{d:"M5 17V6.5H4V5h4V4h4v1h4v1.5h-1V17H5Zm1.5-1.5h7v-9h-7v9ZM8 14h1.5V8H8v6Zm2.5 0H12V8h-1.5v6Z"}))),m=t.forwardRef((({className:e,autofocusIfEmpty:r,...i},n)=>(i.autoFocus=Boolean(!i.value&&r),t.createElement("input",{className:l(a.styles.frontmatterInput,e),...i,ref:n}))));exports.FrontmatterEditor=({yaml:l,onChange:i})=>{const[n,s]=t.useState(!0),d=t.useMemo((()=>l?Object.entries(e.load(l)).map((([e,t])=>({key:e,value:t}))):[]),[l]),{register:x,control:h,watch:E}=r.useForm({defaultValues:{yamlConfig:d}}),{fields:f,append:p,remove:q}=r.useFieldArray({control:h,name:"yamlConfig"});return t.useEffect((()=>{const t=E((({yamlConfig:t})=>{const r=t.reduce(((e,{key:t,value:r})=>(t&&r&&(e[t]=r),e)),{});i(e.dump(r).trim())}));return()=>t.unsubscribe()}),[E,i]),t.createElement("div",{className:a.styles.frontmatterWrapper,"data-expanded":n,"data-editor-type":"frontmatter"},t.createElement("button",{className:a.styles.frontmatterToggleButton,onClick:e=>{e.preventDefault(),s((e=>!e))}},n?t.createElement(u,null):t.createElement(c,null),"Document frontmatter"),n&&t.createElement("form",null,t.createElement("table",{className:a.styles.frontmatterEditorTable},t.createElement("colgroup",null,t.createElement("col",null),t.createElement("col",null),t.createElement("col",null)),t.createElement("thead",null,t.createElement("tr",null,t.createElement("th",null,"Key"),t.createElement("th",null,"Value"),t.createElement("th",null))),t.createElement("tbody",null,f.map(((e,r)=>t.createElement("tr",{key:e.id},t.createElement("td",null,t.createElement(m,{...x(`yamlConfig.${r}.key`,{required:!0}),autofocusIfEmpty:!0})),t.createElement("td",null,t.createElement(m,{...x(`yamlConfig.${r}.value`,{required:!0})})),t.createElement("td",null,t.createElement("button",{type:"button",onClick:()=>q(r),className:a.styles.iconButton},t.createElement(o,null))))))),t.createElement("tfoot",null,t.createElement("tr",null,t.createElement("td",null,t.createElement("button",{className:a.styles.primaryButton,type:"button",onClick:()=>{p({key:"",value:""})}},"Add new key")))))))};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React__default from "react";
|
|
3
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
4
|
+
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
5
|
+
import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
|
|
6
|
+
import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
|
|
7
|
+
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
8
|
+
import * as RadixPopover from "@radix-ui/react-popover";
|
|
9
|
+
import { useForm } from "react-hook-form";
|
|
10
|
+
import { u as useEmitterValues } from "./index-11db5fbf.js";
|
|
11
|
+
import "@lexical/react/LexicalComposer";
|
|
12
|
+
import "@lexical/react/LexicalHorizontalRulePlugin";
|
|
13
|
+
import "@lexical/react/LexicalLinkPlugin";
|
|
14
|
+
import "@lexical/react/LexicalListPlugin";
|
|
15
|
+
import "@lexical/react/LexicalTabIndentationPlugin";
|
|
16
|
+
import "classnames";
|
|
17
|
+
import "lexical";
|
|
18
|
+
import "@lexical/code";
|
|
19
|
+
import "@lexical/link";
|
|
20
|
+
import "@lexical/list";
|
|
21
|
+
import "@lexical/react/LexicalHorizontalRuleNode";
|
|
22
|
+
import "@lexical/rich-text";
|
|
23
|
+
import "mdast-util-directive";
|
|
24
|
+
import "mdast-util-from-markdown";
|
|
25
|
+
import "mdast-util-frontmatter";
|
|
26
|
+
import "mdast-util-gfm-table";
|
|
27
|
+
import "mdast-util-mdx";
|
|
28
|
+
import "micromark-extension-directive";
|
|
29
|
+
import "micromark-extension-frontmatter";
|
|
30
|
+
import "micromark-extension-gfm-table";
|
|
31
|
+
import "micromark-extension-mdxjs";
|
|
32
|
+
import "@lexical/utils";
|
|
33
|
+
import "@lexical/selection";
|
|
34
|
+
import "@lexical/react/LexicalHistoryPlugin";
|
|
35
|
+
import "mdast-util-to-markdown";
|
|
36
|
+
import "@radix-ui/react-tooltip";
|
|
37
|
+
import "downshift";
|
|
38
|
+
import "@lexical/markdown";
|
|
39
|
+
import "@lexical/react/LexicalMarkdownShortcutPlugin";
|
|
40
|
+
import "@codemirror/lang-markdown";
|
|
41
|
+
import "@codesandbox/sandpack-react";
|
|
42
|
+
import "react-diff-view";
|
|
43
|
+
import "unidiff";
|
|
44
|
+
import "@radix-ui/react-toolbar";
|
|
45
|
+
import "@radix-ui/react-select";
|
|
46
|
+
import "@radix-ui/react-dialog";
|
|
47
|
+
const SvgSettings = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
48
|
+
maskType: "alpha"
|
|
49
|
+
} }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "m9.25 22-.4-3.2a3.79 3.79 0 0 1-.613-.3 8.266 8.266 0 0 1-.562-.375L4.7 19.375l-2.75-4.75 2.575-1.95a2.387 2.387 0 0 1-.025-.338v-.675c0-.108.008-.22.025-.337L1.95 9.375l2.75-4.75 2.975 1.25c.183-.133.375-.258.575-.375.2-.117.4-.217.6-.3l.4-3.2h5.5l.4 3.2c.217.083.42.183.612.3.192.117.38.242.563.375l2.975-1.25 2.75 4.75-2.575 1.95c.017.117.025.23.025.338v.675c0 .108-.017.22-.05.337l2.575 1.95-2.75 4.75-2.95-1.25a6.842 6.842 0 0 1-.575.375c-.2.117-.4.217-.6.3l-.4 3.2h-5.5Zm2.8-6.5c.967 0 1.792-.342 2.475-1.025A3.372 3.372 0 0 0 15.55 12c0-.967-.342-1.792-1.025-2.475A3.373 3.373 0 0 0 12.05 8.5c-.983 0-1.813.342-2.488 1.025A3.393 3.393 0 0 0 8.55 12c0 .967.337 1.792 1.012 2.475.676.683 1.505 1.025 2.488 1.025Zm0-2c-.417 0-.77-.146-1.063-.438A1.446 1.446 0 0 1 10.55 12c0-.417.146-.77.438-1.063a1.446 1.446 0 0 1 1.062-.437c.417 0 .77.146 1.063.438.291.291.437.645.437 1.062 0 .417-.146.77-.438 1.063a1.447 1.447 0 0 1-1.062.437ZM11 20h1.975l.35-2.65a5.61 5.61 0 0 0 1.438-.588c.441-.258.845-.57 1.212-.937l2.475 1.025.975-1.7-2.15-1.625c.083-.233.142-.48.175-.738a6.153 6.153 0 0 0 0-1.575 3.535 3.535 0 0 0-.175-.737l2.15-1.625-.975-1.7-2.475 1.05a5.556 5.556 0 0 0-1.213-.962 5.607 5.607 0 0 0-1.437-.588L13 4h-1.975l-.35 2.65c-.517.133-.996.33-1.438.587a6.015 6.015 0 0 0-1.212.938L5.55 7.15l-.975 1.7 2.15 1.6c-.083.25-.142.5-.175.75a6.122 6.122 0 0 0 0 1.575c.033.25.092.5.175.75l-2.15 1.625.975 1.7 2.475-1.05c.367.383.77.704 1.212.962.442.259.921.455 1.438.588L11 20Z" })));
|
|
50
|
+
const SettingsIcon = SvgSettings;
|
|
51
|
+
const PopoverContent = React__default.forwardRef(
|
|
52
|
+
(props, ref) => {
|
|
53
|
+
return /* @__PURE__ */ React__default.createElement(RadixPopover.Content, { ...props, className: "", ref });
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
const PopoverTrigger = React__default.forwardRef(
|
|
57
|
+
(props, ref) => {
|
|
58
|
+
return /* @__PURE__ */ React__default.createElement(RadixPopover.Trigger, { ...props, className: "", ref });
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
function JsxEditor({ kind, attributes, componentName, editor, onSubmit, theme }) {
|
|
62
|
+
if (kind === "flow") {
|
|
63
|
+
return /* @__PURE__ */ React__default.createElement("div", null, /* @__PURE__ */ React__default.createElement("div", null, componentName), /* @__PURE__ */ React__default.createElement(LexicalNestedComposer, { initialEditor: editor, initialTheme: theme }, /* @__PURE__ */ React__default.createElement(RichTextPlugin, { contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, null), placeholder: /* @__PURE__ */ React__default.createElement("div", null, "Type here.."), ErrorBoundary: LexicalErrorBoundary })));
|
|
64
|
+
}
|
|
65
|
+
return /* @__PURE__ */ React__default.createElement("span", null, /* @__PURE__ */ React__default.createElement("span", null, /* @__PURE__ */ React__default.createElement(InlineJsxComponent, { attributes, componentName, onSubmit })), /* @__PURE__ */ React__default.createElement("span", null, componentName, /* @__PURE__ */ React__default.createElement(LexicalNestedComposer, { initialEditor: editor, initialTheme: theme }, /* @__PURE__ */ React__default.createElement(
|
|
66
|
+
RichTextPlugin,
|
|
67
|
+
{
|
|
68
|
+
contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, { style: { padding: 5, border: "1px solid red" } }),
|
|
69
|
+
placeholder: /* @__PURE__ */ React__default.createElement("div", null, "Type here.."),
|
|
70
|
+
ErrorBoundary: LexicalErrorBoundary
|
|
71
|
+
}
|
|
72
|
+
))));
|
|
73
|
+
}
|
|
74
|
+
const InlineJsxComponent = ({ attributes, componentName, onSubmit }) => {
|
|
75
|
+
const [open, setOpen] = React__default.useState(false);
|
|
76
|
+
const decoratedOnSubmit = React__default.useCallback(
|
|
77
|
+
(values) => {
|
|
78
|
+
onSubmit(values);
|
|
79
|
+
setOpen(false);
|
|
80
|
+
},
|
|
81
|
+
[onSubmit]
|
|
82
|
+
);
|
|
83
|
+
return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, { open, onOpenChange: (v) => setOpen(v) }, /* @__PURE__ */ React__default.createElement(PopoverTrigger, null, /* @__PURE__ */ React__default.createElement(SettingsIcon, null)), /* @__PURE__ */ React__default.createElement(RadixPopover.Portal, null, /* @__PURE__ */ React__default.createElement(PopoverContent, null, /* @__PURE__ */ React__default.createElement(JsxPropertyPanel, { attributes, componentName, onSubmit: decoratedOnSubmit }))));
|
|
84
|
+
};
|
|
85
|
+
const JsxPropertyPanel = ({ attributes, componentName, onSubmit }) => {
|
|
86
|
+
const [jsxComponentDescriptors] = useEmitterValues("jsxComponentDescriptors");
|
|
87
|
+
const descriptor = jsxComponentDescriptors.find((descriptor2) => descriptor2.name === componentName);
|
|
88
|
+
const [editor] = useLexicalComposerContext();
|
|
89
|
+
const { register, handleSubmit } = useForm({
|
|
90
|
+
defaultValues: attributes.reduce((acc, attribute) => {
|
|
91
|
+
acc[attribute.name] = attribute.value;
|
|
92
|
+
return acc;
|
|
93
|
+
}, {})
|
|
94
|
+
});
|
|
95
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
96
|
+
"form",
|
|
97
|
+
{
|
|
98
|
+
onSubmit: handleSubmit((data) => {
|
|
99
|
+
editor.update(() => {
|
|
100
|
+
onSubmit(data);
|
|
101
|
+
});
|
|
102
|
+
})
|
|
103
|
+
},
|
|
104
|
+
/* @__PURE__ */ React__default.createElement("table", null, /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null, "Attribute"), /* @__PURE__ */ React__default.createElement("th", null, "Value"))), /* @__PURE__ */ React__default.createElement("tbody", null, descriptor.props.map((propDescriptor) => /* @__PURE__ */ React__default.createElement("tr", { key: propDescriptor.name }, /* @__PURE__ */ React__default.createElement("td", null, " ", propDescriptor.name, " "), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement("input", { ...register(propDescriptor.name) })))))),
|
|
105
|
+
/* @__PURE__ */ React__default.createElement("button", { type: "submit" }, "Submit")
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
export {
|
|
109
|
+
JsxEditor
|
|
110
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),t=require("@lexical/react/LexicalComposerContext"),r=require("@lexical/react/LexicalContentEditable"),l=require("@lexical/react/LexicalErrorBoundary"),a=require("@lexical/react/LexicalNestedComposer"),i=require("@lexical/react/LexicalRichTextPlugin"),n=require("@radix-ui/react-popover"),c=require("react-hook-form"),u=require("./index-731c8e58.cjs");function o(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const l=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,l.get?l:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}require("@lexical/react/LexicalComposer"),require("@lexical/react/LexicalHorizontalRulePlugin"),require("@lexical/react/LexicalLinkPlugin"),require("@lexical/react/LexicalListPlugin"),require("@lexical/react/LexicalTabIndentationPlugin"),require("classnames"),require("lexical"),require("@lexical/code"),require("@lexical/link"),require("@lexical/list"),require("@lexical/react/LexicalHorizontalRuleNode"),require("@lexical/rich-text"),require("mdast-util-directive"),require("mdast-util-from-markdown"),require("mdast-util-frontmatter"),require("mdast-util-gfm-table"),require("mdast-util-mdx"),require("micromark-extension-directive"),require("micromark-extension-frontmatter"),require("micromark-extension-gfm-table"),require("micromark-extension-mdxjs"),require("@lexical/utils"),require("@lexical/selection"),require("@lexical/react/LexicalHistoryPlugin"),require("mdast-util-to-markdown"),require("@radix-ui/react-tooltip"),require("downshift"),require("@lexical/markdown"),require("@lexical/react/LexicalMarkdownShortcutPlugin"),require("@codemirror/lang-markdown"),require("@codesandbox/sandpack-react"),require("react-diff-view"),require("unidiff"),require("@radix-ui/react-toolbar"),require("@radix-ui/react-select"),require("@radix-ui/react-dialog");const m=o(e),s=o(n),d=e=>m.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:24,height:24,fill:"currentColor",viewBox:"0 0 24 24",...e},m.createElement("mask",{id:"a",width:24,height:24,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},m.createElement("path",{d:"M0 0h24v24H0z"})),m.createElement("g",{mask:"url(#a)"},m.createElement("path",{d:"m9.25 22-.4-3.2a3.79 3.79 0 0 1-.613-.3 8.266 8.266 0 0 1-.562-.375L4.7 19.375l-2.75-4.75 2.575-1.95a2.387 2.387 0 0 1-.025-.338v-.675c0-.108.008-.22.025-.337L1.95 9.375l2.75-4.75 2.975 1.25c.183-.133.375-.258.575-.375.2-.117.4-.217.6-.3l.4-3.2h5.5l.4 3.2c.217.083.42.183.612.3.192.117.38.242.563.375l2.975-1.25 2.75 4.75-2.575 1.95c.017.117.025.23.025.338v.675c0 .108-.017.22-.05.337l2.575 1.95-2.75 4.75-2.95-1.25a6.842 6.842 0 0 1-.575.375c-.2.117-.4.217-.6.3l-.4 3.2h-5.5Zm2.8-6.5c.967 0 1.792-.342 2.475-1.025A3.372 3.372 0 0 0 15.55 12c0-.967-.342-1.792-1.025-2.475A3.373 3.373 0 0 0 12.05 8.5c-.983 0-1.813.342-2.488 1.025A3.393 3.393 0 0 0 8.55 12c0 .967.337 1.792 1.012 2.475.676.683 1.505 1.025 2.488 1.025Zm0-2c-.417 0-.77-.146-1.063-.438A1.446 1.446 0 0 1 10.55 12c0-.417.146-.77.438-1.063a1.446 1.446 0 0 1 1.062-.437c.417 0 .77.146 1.063.438.291.291.437.645.437 1.062 0 .417-.146.77-.438 1.063a1.447 1.447 0 0 1-1.062.437ZM11 20h1.975l.35-2.65a5.61 5.61 0 0 0 1.438-.588c.441-.258.845-.57 1.212-.937l2.475 1.025.975-1.7-2.15-1.625c.083-.233.142-.48.175-.738a6.153 6.153 0 0 0 0-1.575 3.535 3.535 0 0 0-.175-.737l2.15-1.625-.975-1.7-2.475 1.05a5.556 5.556 0 0 0-1.213-.962 5.607 5.607 0 0 0-1.437-.588L13 4h-1.975l-.35 2.65c-.517.133-.996.33-1.438.587a6.015 6.015 0 0 0-1.212.938L5.55 7.15l-.975 1.7 2.15 1.6c-.083.25-.142.5-.175.75a6.122 6.122 0 0 0 0 1.575c.033.25.092.5.175.75l-2.15 1.625.975 1.7 2.475-1.05c.367.383.77.704 1.212.962.442.259.921.455 1.438.588L11 20Z"}))),x=e.forwardRef(((t,r)=>e.createElement(s.Content,{...t,className:"",ref:r}))),E=e.forwardRef(((t,r)=>e.createElement(s.Trigger,{...t,className:"",ref:r})));const p=({attributes:t,componentName:r,onSubmit:l})=>{const[a,i]=e.useState(!1),n=e.useCallback((e=>{l(e),i(!1)}),[l]);return e.createElement(s.Root,{open:a,onOpenChange:e=>i(e)},e.createElement(E,null,e.createElement(d,null)),e.createElement(s.Portal,null,e.createElement(x,null,e.createElement(q,{attributes:t,componentName:r,onSubmit:n}))))},q=({attributes:r,componentName:l,onSubmit:a})=>{const[i]=u.useEmitterValues("jsxComponentDescriptors"),n=i.find((e=>e.name===l)),[o]=t.useLexicalComposerContext(),{register:m,handleSubmit:s}=c.useForm({defaultValues:r.reduce(((e,t)=>(e[t.name]=t.value,e)),{})});return e.createElement("form",{onSubmit:s((e=>{o.update((()=>{a(e)}))}))},e.createElement("table",null,e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Attribute"),e.createElement("th",null,"Value"))),e.createElement("tbody",null,n.props.map((t=>e.createElement("tr",{key:t.name},e.createElement("td",null," ",t.name," "),e.createElement("td",null,e.createElement("input",{...m(t.name)}))))))),e.createElement("button",{type:"submit"},"Submit"))};exports.JsxEditor=function({kind:t,attributes:n,componentName:c,editor:u,onSubmit:o,theme:m}){return"flow"===t?e.createElement("div",null,e.createElement("div",null,c),e.createElement(a.LexicalNestedComposer,{initialEditor:u,initialTheme:m},e.createElement(i.RichTextPlugin,{contentEditable:e.createElement(r.ContentEditable,null),placeholder:e.createElement("div",null,"Type here.."),ErrorBoundary:l}))):e.createElement("span",null,e.createElement("span",null,e.createElement(p,{attributes:n,componentName:c,onSubmit:o})),e.createElement("span",null,c,e.createElement(a.LexicalNestedComposer,{initialEditor:u,initialTheme:m},e.createElement(i.RichTextPlugin,{contentEditable:e.createElement(r.ContentEditable,{style:{padding:5,border:"1px solid red"}}),placeholder:e.createElement("div",null,"Type here.."),ErrorBoundary:l}))))};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@codesandbox/sandpack-react"),r=require("@lexical/react/LexicalComposerContext"),i=require("react"),a=require("./index-731c8e58.cjs"),t=require("./useCodeMirrorRef-cba12130.cjs");require("@lexical/react/LexicalComposer"),require("@lexical/react/LexicalContentEditable"),require("@lexical/react/LexicalErrorBoundary"),require("@lexical/react/LexicalHorizontalRulePlugin"),require("@lexical/react/LexicalLinkPlugin"),require("@lexical/react/LexicalListPlugin"),require("@lexical/react/LexicalRichTextPlugin"),require("@lexical/react/LexicalTabIndentationPlugin"),require("classnames"),require("lexical"),require("@lexical/code"),require("@lexical/link"),require("@lexical/list"),require("@lexical/react/LexicalHorizontalRuleNode"),require("@lexical/rich-text"),require("mdast-util-directive"),require("mdast-util-from-markdown"),require("mdast-util-frontmatter"),require("mdast-util-gfm-table"),require("mdast-util-mdx"),require("micromark-extension-directive"),require("micromark-extension-frontmatter"),require("micromark-extension-gfm-table"),require("micromark-extension-mdxjs"),require("@lexical/utils"),require("@lexical/selection"),require("@lexical/react/LexicalHistoryPlugin"),require("mdast-util-to-markdown"),require("@radix-ui/react-popover"),require("@radix-ui/react-tooltip"),require("downshift"),require("@lexical/markdown"),require("@lexical/react/LexicalMarkdownShortcutPlugin"),require("@codemirror/lang-markdown"),require("react-diff-view"),require("unidiff"),require("@radix-ui/react-toolbar"),require("@radix-ui/react-select"),require("@radix-ui/react-dialog");const l=({onChange:r,snippetFileName:i})=>{const{sandpack:a}=e.useSandpack();return r(a.files[i].code),null};exports.SandpackEditor=({nodeKey:c,code:n,meta:u,onChange:o,focusEmitter:s})=>{const[d]=r.useLexicalComposerContext(),[m]=a.useEmitterValues("sandpackConfig"),x=t.useCodeMirrorRef(c,"sandpack","jsx"),q=a.usePublisher("activeEditorType");i.useEffect((()=>{s.subscribe((()=>{var e,r;null==(r=null==(e=null==x?void 0:x.current)?void 0:e.getCodemirror())||r.focus(),q({type:"sandpack",nodeKey:c})}))}),[s,x,q,c]);const p=i.useCallback((e=>{d.update((()=>{o(e)}))}),[o,d]),f=function(e,r){return r.presets.find((r=>r.meta===e))||r.presets.find((e=>e.name===r.defaultPreset))}(u,m);if(!f)throw new Error(`No sandpack preset found for meta: ${u}`);return i.createElement(e.SandpackProvider,{template:f.sandpackTemplate,theme:f.sandpackTheme,files:{[f.snippetFileName]:n,...Object.entries(f.files||{}).reduce(((e,[r,i])=>({...e,[r]:{code:i,readOnly:!0}})),{})},customSetup:{dependencies:f.dependencies}},i.createElement(e.SandpackLayout,null,i.createElement(e.SandpackCodeEditor,{showLineNumbers:!0,showInlineErrors:!0,ref:x}),i.createElement(e.SandpackPreview,null)),i.createElement(l,{onChange:p,snippetFileName:f.snippetFileName}))};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { SandpackProvider, SandpackLayout, SandpackCodeEditor, SandpackPreview, useSandpack } from "@codesandbox/sandpack-react";
|
|
2
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
3
|
+
import React__default from "react";
|
|
4
|
+
import { u as useEmitterValues, a as usePublisher } from "./index-11db5fbf.js";
|
|
5
|
+
import { u as useCodeMirrorRef } from "./useCodeMirrorRef-89746e60.js";
|
|
6
|
+
import "@lexical/react/LexicalComposer";
|
|
7
|
+
import "@lexical/react/LexicalContentEditable";
|
|
8
|
+
import "@lexical/react/LexicalErrorBoundary";
|
|
9
|
+
import "@lexical/react/LexicalHorizontalRulePlugin";
|
|
10
|
+
import "@lexical/react/LexicalLinkPlugin";
|
|
11
|
+
import "@lexical/react/LexicalListPlugin";
|
|
12
|
+
import "@lexical/react/LexicalRichTextPlugin";
|
|
13
|
+
import "@lexical/react/LexicalTabIndentationPlugin";
|
|
14
|
+
import "classnames";
|
|
15
|
+
import "lexical";
|
|
16
|
+
import "@lexical/code";
|
|
17
|
+
import "@lexical/link";
|
|
18
|
+
import "@lexical/list";
|
|
19
|
+
import "@lexical/react/LexicalHorizontalRuleNode";
|
|
20
|
+
import "@lexical/rich-text";
|
|
21
|
+
import "mdast-util-directive";
|
|
22
|
+
import "mdast-util-from-markdown";
|
|
23
|
+
import "mdast-util-frontmatter";
|
|
24
|
+
import "mdast-util-gfm-table";
|
|
25
|
+
import "mdast-util-mdx";
|
|
26
|
+
import "micromark-extension-directive";
|
|
27
|
+
import "micromark-extension-frontmatter";
|
|
28
|
+
import "micromark-extension-gfm-table";
|
|
29
|
+
import "micromark-extension-mdxjs";
|
|
30
|
+
import "@lexical/utils";
|
|
31
|
+
import "@lexical/selection";
|
|
32
|
+
import "@lexical/react/LexicalHistoryPlugin";
|
|
33
|
+
import "mdast-util-to-markdown";
|
|
34
|
+
import "@radix-ui/react-popover";
|
|
35
|
+
import "@radix-ui/react-tooltip";
|
|
36
|
+
import "downshift";
|
|
37
|
+
import "@lexical/markdown";
|
|
38
|
+
import "@lexical/react/LexicalMarkdownShortcutPlugin";
|
|
39
|
+
import "@codemirror/lang-markdown";
|
|
40
|
+
import "react-diff-view";
|
|
41
|
+
import "unidiff";
|
|
42
|
+
import "@radix-ui/react-toolbar";
|
|
43
|
+
import "@radix-ui/react-select";
|
|
44
|
+
import "@radix-ui/react-dialog";
|
|
45
|
+
const CodeUpdateEmitter = ({ onChange, snippetFileName }) => {
|
|
46
|
+
const { sandpack } = useSandpack();
|
|
47
|
+
onChange(sandpack.files[snippetFileName].code);
|
|
48
|
+
return null;
|
|
49
|
+
};
|
|
50
|
+
function getPresetOrDefault(meta, config) {
|
|
51
|
+
return config.presets.find((preset) => preset.meta === meta) || config.presets.find((preset) => preset.name === config.defaultPreset);
|
|
52
|
+
}
|
|
53
|
+
const SandpackEditor = ({ nodeKey, code, meta, onChange, focusEmitter }) => {
|
|
54
|
+
const [editor] = useLexicalComposerContext();
|
|
55
|
+
const [config] = useEmitterValues("sandpackConfig");
|
|
56
|
+
const codeMirrorRef = useCodeMirrorRef(nodeKey, "sandpack", "jsx");
|
|
57
|
+
const setActiveEditorType = usePublisher("activeEditorType");
|
|
58
|
+
React__default.useEffect(() => {
|
|
59
|
+
focusEmitter.subscribe(() => {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
(_b = (_a = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a.getCodemirror()) == null ? void 0 : _b.focus();
|
|
62
|
+
setActiveEditorType({ type: "sandpack", nodeKey });
|
|
63
|
+
});
|
|
64
|
+
}, [focusEmitter, codeMirrorRef, setActiveEditorType, nodeKey]);
|
|
65
|
+
const wrappedOnChange = React__default.useCallback(
|
|
66
|
+
(code2) => {
|
|
67
|
+
editor.update(() => {
|
|
68
|
+
onChange(code2);
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
[onChange, editor]
|
|
72
|
+
);
|
|
73
|
+
const preset = getPresetOrDefault(meta, config);
|
|
74
|
+
if (!preset) {
|
|
75
|
+
throw new Error(`No sandpack preset found for meta: ${meta}`);
|
|
76
|
+
}
|
|
77
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
78
|
+
SandpackProvider,
|
|
79
|
+
{
|
|
80
|
+
template: preset.sandpackTemplate,
|
|
81
|
+
theme: preset.sandpackTheme,
|
|
82
|
+
files: {
|
|
83
|
+
[preset.snippetFileName]: code,
|
|
84
|
+
...Object.entries(preset.files || {}).reduce(
|
|
85
|
+
(acc, [filePath, fileContents]) => ({ ...acc, ...{ [filePath]: { code: fileContents, readOnly: true } } }),
|
|
86
|
+
{}
|
|
87
|
+
)
|
|
88
|
+
},
|
|
89
|
+
customSetup: {
|
|
90
|
+
dependencies: preset.dependencies
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
/* @__PURE__ */ React__default.createElement(SandpackLayout, null, /* @__PURE__ */ React__default.createElement(SandpackCodeEditor, { showLineNumbers: true, showInlineErrors: true, ref: codeMirrorRef }), /* @__PURE__ */ React__default.createElement(SandpackPreview, null)),
|
|
94
|
+
/* @__PURE__ */ React__default.createElement(CodeUpdateEmitter, { onChange: wrappedOnChange, snippetFileName: preset.snippetFileName })
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
export {
|
|
98
|
+
SandpackEditor
|
|
99
|
+
};
|