@sanity/code-input 7.2.3 → 7.2.5
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/CodeMirrorProxy.js +446 -0
- package/dist/CodeMirrorProxy.js.map +1 -0
- package/dist/CodeModeContext.js +5 -0
- package/dist/CodeModeContext.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +665 -8
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
- package/dist/_chunks-es/CodeMirrorProxy.js +0 -511
- package/dist/_chunks-es/CodeMirrorProxy.js.map +0 -1
- package/dist/_chunks-es/index.js +0 -589
- package/dist/_chunks-es/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,665 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
|
|
1
|
+
import { t as CodeInputConfigContext } from "./CodeModeContext.js";
|
|
2
|
+
import { CodeBlockIcon } from "@sanity/icons/CodeBlock";
|
|
3
|
+
import { MemberField, definePlugin, defineType, set, setIfMissing, unset } from "sanity";
|
|
4
|
+
import { c } from "react/compiler-runtime";
|
|
5
|
+
import { Box, Button, Card, Flex, Label, Layer, Portal, Select, Stack, Text, Tooltip } from "@sanity/ui";
|
|
6
|
+
import { Suspense, lazy, startTransition, useEffect, useRef, useState } from "react";
|
|
7
|
+
import { CollapseIcon } from "@sanity/icons/Collapse";
|
|
8
|
+
import { ExpandIcon } from "@sanity/icons/Expand";
|
|
9
|
+
import { css, styled } from "styled-components";
|
|
10
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
/** @internal */
|
|
12
|
+
function focusRingBorderStyle(border) {
|
|
13
|
+
return `inset 0 0 0 ${border.width}px ${border.color}`;
|
|
14
|
+
}
|
|
15
|
+
/** @internal */
|
|
16
|
+
function focusRingStyle(opts) {
|
|
17
|
+
let { base, border, focusRing } = opts, focusRingOutsetWidth = focusRing.offset + focusRing.width, focusRingInsetWidth = 0 - focusRing.offset, bgColor = base ? base.bg : "var(--card-bg-color)";
|
|
18
|
+
return [
|
|
19
|
+
focusRingInsetWidth > 0 && `inset 0 0 0 ${focusRingInsetWidth}px var(--card-focus-ring-color)`,
|
|
20
|
+
border && focusRingBorderStyle(border),
|
|
21
|
+
focusRingInsetWidth < 0 && `0 0 0 ${0 - focusRingInsetWidth}px ${bgColor}`,
|
|
22
|
+
focusRingOutsetWidth > 0 && `0 0 0 ${focusRingOutsetWidth}px var(--card-focus-ring-color)`
|
|
23
|
+
].filter(Boolean).join(",");
|
|
24
|
+
}
|
|
25
|
+
const TOOLTIP_DELAY = { open: 400 }, DOCUMENT_PANE_SELECTOR = "[data-testid=\"document-pane\"]", DOCUMENT_PANEL_SCROLLER_SELECTOR = "[data-testid=\"document-panel-scroller\"]", SELECTED_PANE_SCROLLER_SELECTOR = `${DOCUMENT_PANE_SELECTOR}[data-pane-selected="true"] ${DOCUMENT_PANEL_SCROLLER_SELECTOR}`;
|
|
26
|
+
function getScrollParent(node) {
|
|
27
|
+
let current = node?.parentElement ?? null;
|
|
28
|
+
for (; current;) {
|
|
29
|
+
let { overflowY } = window.getComputedStyle(current);
|
|
30
|
+
if (overflowY === "auto" || overflowY === "scroll" || overflowY === "overlay") return current;
|
|
31
|
+
current = current.parentElement;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
function getDocumentPaneElement(node) {
|
|
36
|
+
if (!node) return null;
|
|
37
|
+
let ownPane = node.closest(DOCUMENT_PANE_SELECTOR);
|
|
38
|
+
if (ownPane instanceof HTMLElement) {
|
|
39
|
+
let scroller = ownPane.querySelector(DOCUMENT_PANEL_SCROLLER_SELECTOR);
|
|
40
|
+
return scroller instanceof HTMLElement ? scroller : ownPane;
|
|
41
|
+
}
|
|
42
|
+
let selectedScroller = document.querySelector(SELECTED_PANE_SCROLLER_SELECTOR);
|
|
43
|
+
if (selectedScroller instanceof HTMLElement) return selectedScroller;
|
|
44
|
+
let scroller = document.querySelector(DOCUMENT_PANEL_SCROLLER_SELECTOR);
|
|
45
|
+
return scroller instanceof HTMLElement ? scroller : getScrollParent(node);
|
|
46
|
+
}
|
|
47
|
+
const FullscreenRoot = styled.div.withConfig({
|
|
48
|
+
displayName: "FullscreenRoot",
|
|
49
|
+
componentId: "sc-ozhpzk-0"
|
|
50
|
+
})`position:relative;`, FullscreenOverlay = /* @__PURE__ */ styled.div.withConfig({
|
|
51
|
+
displayName: "FullscreenOverlay",
|
|
52
|
+
componentId: "sc-ozhpzk-1"
|
|
53
|
+
})(({ theme }) => {
|
|
54
|
+
let { input } = theme.sanity, borderColor = theme.sanity.color.input.default.enabled.border;
|
|
55
|
+
return css`box-sizing:border-box;overflow:hidden;border-top:${input.border.width}px solid ${borderColor};border-bottom:${input.border.width}px solid ${borderColor};`;
|
|
56
|
+
}), ToggleButtonBox = styled(Box).withConfig({
|
|
57
|
+
displayName: "ToggleButtonBox",
|
|
58
|
+
componentId: "sc-ozhpzk-2"
|
|
59
|
+
})`position:absolute;top:0;right:0;z-index:2;`, EditorContainer = /* @__PURE__ */ styled(Card).withConfig({
|
|
60
|
+
displayName: "EditorContainer",
|
|
61
|
+
componentId: "sc-ozhpzk-3"
|
|
62
|
+
})(({ theme, $fullscreen }) => {
|
|
63
|
+
let { focusRing, input } = theme.sanity, base = theme.sanity.color.base, border = {
|
|
64
|
+
color: theme.sanity.color.input.default.enabled.border,
|
|
65
|
+
width: input.border.width
|
|
66
|
+
};
|
|
67
|
+
return css`--input-box-shadow:${focusRingBorderStyle(border)};box-shadow:var(--input-box-shadow);height:${250}px;min-height:80px;overflow-y:auto;position:relative;resize:vertical;z-index:0;& > .cm-theme{height:100%;}&:focus-within{--input-box-shadow:${focusRingStyle({
|
|
68
|
+
base,
|
|
69
|
+
border,
|
|
70
|
+
focusRing
|
|
71
|
+
})};}${$fullscreen && css`height:100%;border-radius:0;resize:none;background-color:${base.bg};box-shadow:none;`}`;
|
|
72
|
+
});
|
|
73
|
+
/** Wraps the editor with an "Expand editor" toggle that fills the document pane. */
|
|
74
|
+
function FullscreenEditor(t0) {
|
|
75
|
+
let $ = c(25), { enabled, children } = t0, [isFullscreen, setIsFullscreen] = useState(!1), rootRef = useRef(null), overlayRef = useRef(null), [overlayElement, setOverlayElement] = useState(null), t1;
|
|
76
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = (node) => {
|
|
77
|
+
overlayRef.current = node, setOverlayElement(node);
|
|
78
|
+
}, $[0] = t1) : t1 = $[0];
|
|
79
|
+
let setOverlayRef = t1, [paneRect, setPaneRect] = useState(null), [placeholderHeight, setPlaceholderHeight] = useState(250), showFullscreen = isFullscreen && paneRect !== null, t2;
|
|
80
|
+
$[1] === Symbol.for("react.memo_cache_sentinel") ? (t2 = () => {
|
|
81
|
+
setPaneRect(null), setIsFullscreen(!1);
|
|
82
|
+
}, $[1] = t2) : t2 = $[1];
|
|
83
|
+
let collapse = t2, t3;
|
|
84
|
+
$[2] === isFullscreen ? t3 = $[3] : (t3 = () => {
|
|
85
|
+
if (isFullscreen) {
|
|
86
|
+
collapse();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
setPlaceholderHeight(rootRef.current?.offsetHeight ?? 250), setIsFullscreen(!0);
|
|
90
|
+
}, $[2] = isFullscreen, $[3] = t3);
|
|
91
|
+
let handleToggle = t3, t4;
|
|
92
|
+
$[4] === Symbol.for("react.memo_cache_sentinel") ? (t4 = (event) => {
|
|
93
|
+
event.key === "Escape" && (event.preventDefault(), event.stopPropagation(), event.nativeEvent.stopImmediatePropagation(), collapse());
|
|
94
|
+
}, $[4] = t4) : t4 = $[4];
|
|
95
|
+
let handleKeyDown = t4, t5, t6;
|
|
96
|
+
$[5] === isFullscreen ? (t5 = $[6], t6 = $[7]) : (t5 = () => {
|
|
97
|
+
if (!isFullscreen) return;
|
|
98
|
+
let paneElement = getDocumentPaneElement(rootRef.current), update = () => {
|
|
99
|
+
let { top, left, width, height } = paneElement ? paneElement.getBoundingClientRect() : {
|
|
100
|
+
top: 0,
|
|
101
|
+
left: 0,
|
|
102
|
+
width: window.innerWidth,
|
|
103
|
+
height: window.innerHeight
|
|
104
|
+
};
|
|
105
|
+
setPaneRect((prev) => prev && prev.top === top && prev.left === left && prev.width === width && prev.height === height ? prev : {
|
|
106
|
+
top,
|
|
107
|
+
left,
|
|
108
|
+
width,
|
|
109
|
+
height
|
|
110
|
+
});
|
|
111
|
+
}, raf = requestAnimationFrame(update), resizeObserver;
|
|
112
|
+
return paneElement && (resizeObserver = new ResizeObserver(update), resizeObserver.observe(paneElement)), window.addEventListener("resize", update), window.addEventListener("scroll", update, !0), () => {
|
|
113
|
+
cancelAnimationFrame(raf), resizeObserver?.disconnect(), window.removeEventListener("resize", update), window.removeEventListener("scroll", update, !0);
|
|
114
|
+
};
|
|
115
|
+
}, t6 = [isFullscreen], $[5] = isFullscreen, $[6] = t5, $[7] = t6), useEffect(t5, t6);
|
|
116
|
+
let t7, t8;
|
|
117
|
+
$[8] === showFullscreen ? (t7 = $[9], t8 = $[10]) : (t7 = () => {
|
|
118
|
+
if (!showFullscreen) return;
|
|
119
|
+
let raf_0 = requestAnimationFrame(() => {
|
|
120
|
+
let overlay = overlayRef.current;
|
|
121
|
+
overlay && (overlay.querySelector(".cm-content") ?? overlay).focus();
|
|
122
|
+
});
|
|
123
|
+
return () => cancelAnimationFrame(raf_0);
|
|
124
|
+
}, t8 = [showFullscreen], $[8] = showFullscreen, $[9] = t7, $[10] = t8), useEffect(t7, t8);
|
|
125
|
+
let t9;
|
|
126
|
+
$[11] !== enabled || $[12] !== handleToggle || $[13] !== overlayElement || $[14] !== showFullscreen ? (t9 = enabled && /* @__PURE__ */ jsx(ToggleButtonBox, {
|
|
127
|
+
padding: 1,
|
|
128
|
+
children: /* @__PURE__ */ jsx(Tooltip, {
|
|
129
|
+
animate: !0,
|
|
130
|
+
arrow: !1,
|
|
131
|
+
boundaryElement: overlayElement,
|
|
132
|
+
content: /* @__PURE__ */ jsx(Text, {
|
|
133
|
+
size: 1,
|
|
134
|
+
children: showFullscreen ? "Collapse editor" : "Expand editor"
|
|
135
|
+
}),
|
|
136
|
+
delay: TOOLTIP_DELAY,
|
|
137
|
+
placement: "bottom",
|
|
138
|
+
portal: !0,
|
|
139
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
140
|
+
"aria-label": showFullscreen ? "Collapse editor" : "Expand editor",
|
|
141
|
+
icon: showFullscreen ? CollapseIcon : ExpandIcon,
|
|
142
|
+
mode: "ghost",
|
|
143
|
+
onClick: handleToggle,
|
|
144
|
+
padding: 2
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
}), $[11] = enabled, $[12] = handleToggle, $[13] = overlayElement, $[14] = showFullscreen, $[15] = t9) : t9 = $[15];
|
|
148
|
+
let toggleButton = t9, t10;
|
|
149
|
+
$[16] !== paneRect || $[17] !== showFullscreen ? (t10 = showFullscreen && paneRect ? {
|
|
150
|
+
position: "fixed",
|
|
151
|
+
top: paneRect.top,
|
|
152
|
+
left: paneRect.left,
|
|
153
|
+
width: paneRect.width,
|
|
154
|
+
height: paneRect.height
|
|
155
|
+
} : void 0, $[16] = paneRect, $[17] = showFullscreen, $[18] = t10) : t10 = $[18];
|
|
156
|
+
let fullscreenStyle = t10, t11;
|
|
157
|
+
return $[19] !== children || $[20] !== fullscreenStyle || $[21] !== placeholderHeight || $[22] !== showFullscreen || $[23] !== toggleButton ? (t11 = /* @__PURE__ */ jsx(FullscreenRoot, {
|
|
158
|
+
ref: rootRef,
|
|
159
|
+
children: showFullscreen ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
160
|
+
"aria-hidden": !0,
|
|
161
|
+
style: { height: placeholderHeight }
|
|
162
|
+
}), /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(Layer, { children: /* @__PURE__ */ jsxs(FullscreenOverlay, {
|
|
163
|
+
onKeyDown: handleKeyDown,
|
|
164
|
+
ref: setOverlayRef,
|
|
165
|
+
style: fullscreenStyle,
|
|
166
|
+
tabIndex: -1,
|
|
167
|
+
children: [toggleButton, children({ isFullscreen: showFullscreen })]
|
|
168
|
+
}) }) })] }) : /* @__PURE__ */ jsxs(Fragment, { children: [toggleButton, children({ isFullscreen: showFullscreen })] })
|
|
169
|
+
}), $[19] = children, $[20] = fullscreenStyle, $[21] = placeholderHeight, $[22] = showFullscreen, $[23] = toggleButton, $[24] = t11) : t11 = $[24], t11;
|
|
170
|
+
}
|
|
171
|
+
const CodeMirrorProxy = lazy(() => import("./CodeMirrorProxy.js"));
|
|
172
|
+
function useMounted() {
|
|
173
|
+
let $ = c(2), [mounted, setMounted] = useState(!1), t0, t1;
|
|
174
|
+
return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = () => {
|
|
175
|
+
requestAnimationFrame(() => startTransition(() => setMounted(!0)));
|
|
176
|
+
}, t1 = [], $[0] = t0, $[1] = t1) : (t0 = $[0], t1 = $[1]), useEffect(t0, t1), mounted;
|
|
177
|
+
}
|
|
178
|
+
const SUPPORTED_LANGUAGES = [
|
|
179
|
+
{
|
|
180
|
+
title: "Batch file",
|
|
181
|
+
value: "batchfile"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
title: "C#",
|
|
185
|
+
value: "csharp"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
title: "CSS",
|
|
189
|
+
value: "css"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
title: "Go",
|
|
193
|
+
value: "golang"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
title: "GROQ",
|
|
197
|
+
value: "groq"
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
title: "HTML",
|
|
201
|
+
value: "html"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
title: "Java",
|
|
205
|
+
value: "java"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
title: "JavaScript",
|
|
209
|
+
value: "javascript"
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
title: "JSON",
|
|
213
|
+
value: "json"
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
title: "JSX",
|
|
217
|
+
value: "jsx"
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
title: "Markdown",
|
|
221
|
+
value: "markdown"
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
title: "MySQL",
|
|
225
|
+
value: "mysql"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
title: "PHP",
|
|
229
|
+
value: "php"
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
title: "Plain text",
|
|
233
|
+
value: "text"
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
title: "Python",
|
|
237
|
+
value: "python"
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
title: "Ruby",
|
|
241
|
+
value: "ruby"
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
title: "SASS",
|
|
245
|
+
value: "sass"
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
title: "SCSS",
|
|
249
|
+
value: "scss"
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
title: "sh",
|
|
253
|
+
value: "sh"
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
title: "SQL",
|
|
257
|
+
value: "sql"
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
title: "TSX",
|
|
261
|
+
value: "tsx"
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
title: "TypeScript",
|
|
265
|
+
value: "typescript"
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
title: "XML",
|
|
269
|
+
value: "xml"
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
title: "YAML",
|
|
273
|
+
value: "yaml"
|
|
274
|
+
}
|
|
275
|
+
], LANGUAGE_ALIASES = { js: "javascript" }, PATH_CODE = ["code"], defaultLanguageMode = "text";
|
|
276
|
+
function useLanguageMode(schemaType, value) {
|
|
277
|
+
let $ = c(12), languages = useLanguageAlternatives(schemaType), fixedLanguage = schemaType.options?.language, language = value?.language ?? fixedLanguage ?? defaultLanguageMode, t0;
|
|
278
|
+
if ($[0] !== language || $[1] !== languages) {
|
|
279
|
+
let t1;
|
|
280
|
+
$[3] === language ? t1 = $[4] : (t1 = (entry) => entry.value === language, $[3] = language, $[4] = t1), t0 = languages.find(t1), $[0] = language, $[1] = languages, $[2] = t0;
|
|
281
|
+
} else t0 = $[2];
|
|
282
|
+
let configured = t0, t1;
|
|
283
|
+
$[5] !== configured?.mode || $[6] !== language ? (t1 = configured?.mode ?? resolveAliasedLanguage(language) ?? defaultLanguageMode, $[5] = configured?.mode, $[6] = language, $[7] = t1) : t1 = $[7];
|
|
284
|
+
let languageMode = t1, t2;
|
|
285
|
+
return $[8] !== language || $[9] !== languageMode || $[10] !== languages ? (t2 = {
|
|
286
|
+
language,
|
|
287
|
+
languageMode,
|
|
288
|
+
languages
|
|
289
|
+
}, $[8] = language, $[9] = languageMode, $[10] = languages, $[11] = t2) : t2 = $[11], t2;
|
|
290
|
+
}
|
|
291
|
+
function resolveAliasedLanguage(lang) {
|
|
292
|
+
return (lang && LANGUAGE_ALIASES[lang]) ?? lang;
|
|
293
|
+
}
|
|
294
|
+
function useLanguageAlternatives(type) {
|
|
295
|
+
let $ = c(2), t0;
|
|
296
|
+
bb0: {
|
|
297
|
+
let languageAlternatives = type.options?.languageAlternatives;
|
|
298
|
+
if (!languageAlternatives) {
|
|
299
|
+
t0 = SUPPORTED_LANGUAGES;
|
|
300
|
+
break bb0;
|
|
301
|
+
}
|
|
302
|
+
if (!Array.isArray(languageAlternatives)) throw Error(`'options.languageAlternatives' should be an array, got ${typeof languageAlternatives}`);
|
|
303
|
+
let t1;
|
|
304
|
+
$[0] === languageAlternatives ? t1 = $[1] : (t1 = languageAlternatives.reduce(_temp$1, []), $[0] = languageAlternatives, $[1] = t1), t0 = t1;
|
|
305
|
+
}
|
|
306
|
+
return t0;
|
|
307
|
+
}
|
|
308
|
+
function _temp$1(acc, t0) {
|
|
309
|
+
let { title, value: val, mode } = t0, alias = LANGUAGE_ALIASES[val];
|
|
310
|
+
return alias ? (console.warn("'options.languageAlternatives' lists a language with value \"%s\", which is an alias of \"%s\" - please replace the value to read \"%s\"", val, alias, alias), acc.concat({
|
|
311
|
+
title,
|
|
312
|
+
value: alias,
|
|
313
|
+
mode
|
|
314
|
+
})) : acc.concat({
|
|
315
|
+
title,
|
|
316
|
+
value: val,
|
|
317
|
+
mode
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
/** @internal */
|
|
321
|
+
function LanguageInput(props) {
|
|
322
|
+
let $ = c(9), { language, languages, onChange, elementProps } = props, t0;
|
|
323
|
+
$[0] === onChange ? t0 = $[1] : (t0 = (e) => {
|
|
324
|
+
let newValue = e.currentTarget.value;
|
|
325
|
+
onChange(newValue ? set(newValue) : unset());
|
|
326
|
+
}, $[0] = onChange, $[1] = t0);
|
|
327
|
+
let handleChange = t0, t1;
|
|
328
|
+
$[2] === languages ? t1 = $[3] : (t1 = languages.map(_temp), $[2] = languages, $[3] = t1);
|
|
329
|
+
let t2;
|
|
330
|
+
return $[4] !== elementProps || $[5] !== handleChange || $[6] !== language || $[7] !== t1 ? (t2 = /* @__PURE__ */ jsx(Select, {
|
|
331
|
+
...elementProps,
|
|
332
|
+
value: language,
|
|
333
|
+
onChange: handleChange,
|
|
334
|
+
children: t1
|
|
335
|
+
}), $[4] = elementProps, $[5] = handleChange, $[6] = language, $[7] = t1, $[8] = t2) : t2 = $[8], t2;
|
|
336
|
+
}
|
|
337
|
+
function _temp(lang) {
|
|
338
|
+
return /* @__PURE__ */ jsx("option", {
|
|
339
|
+
value: lang.value,
|
|
340
|
+
children: lang.title
|
|
341
|
+
}, lang.value);
|
|
342
|
+
}
|
|
343
|
+
function LanguageField(props) {
|
|
344
|
+
let $ = c(9), { member, languages, language, renderItem, renderField, renderPreview } = props, t0;
|
|
345
|
+
$[0] !== language || $[1] !== languages ? (t0 = (t1) => {
|
|
346
|
+
let { elementProps, onChange } = t1;
|
|
347
|
+
return /* @__PURE__ */ jsx(LanguageInput, {
|
|
348
|
+
onChange,
|
|
349
|
+
elementProps,
|
|
350
|
+
language,
|
|
351
|
+
languages
|
|
352
|
+
});
|
|
353
|
+
}, $[0] = language, $[1] = languages, $[2] = t0) : t0 = $[2];
|
|
354
|
+
let renderInput = t0, t1;
|
|
355
|
+
return $[3] !== member || $[4] !== renderField || $[5] !== renderInput || $[6] !== renderItem || $[7] !== renderPreview ? (t1 = /* @__PURE__ */ jsx(MemberField, {
|
|
356
|
+
member,
|
|
357
|
+
renderItem,
|
|
358
|
+
renderField,
|
|
359
|
+
renderInput,
|
|
360
|
+
renderPreview
|
|
361
|
+
}), $[3] = member, $[4] = renderField, $[5] = renderInput, $[6] = renderItem, $[7] = renderPreview, $[8] = t1) : t1 = $[8], t1;
|
|
362
|
+
}
|
|
363
|
+
/** @internal */
|
|
364
|
+
function useFieldMember(members, fieldName) {
|
|
365
|
+
let $ = c(5), t0;
|
|
366
|
+
if ($[0] !== fieldName || $[1] !== members) {
|
|
367
|
+
let t1;
|
|
368
|
+
$[3] === fieldName ? t1 = $[4] : (t1 = (member) => member.kind === "field" && member.name === fieldName, $[3] = fieldName, $[4] = t1), t0 = members.find(t1), $[0] = fieldName, $[1] = members, $[2] = t0;
|
|
369
|
+
} else t0 = $[2];
|
|
370
|
+
return t0;
|
|
371
|
+
}
|
|
372
|
+
/** @public */
|
|
373
|
+
function CodeInput(props) {
|
|
374
|
+
let $ = c(43), { members, elementProps, onChange, readOnly, renderField, renderInput, renderItem, renderPreview, schemaType: type, value, onPathFocus } = props, languageFieldMember = useFieldMember(members, "language"), filenameMember = useFieldMember(members, "filename"), codeFieldMember = useFieldMember(members, "code"), t0;
|
|
375
|
+
$[0] === onPathFocus ? t0 = $[1] : (t0 = () => {
|
|
376
|
+
onPathFocus(PATH_CODE);
|
|
377
|
+
}, $[0] = onPathFocus, $[1] = t0);
|
|
378
|
+
let handleCodeFocus = t0, t1;
|
|
379
|
+
$[2] === onChange ? t1 = $[3] : (t1 = (lines) => onChange(set(lines, ["highlightedLines"])), $[2] = onChange, $[3] = t1);
|
|
380
|
+
let onHighlightChange = t1, t2;
|
|
381
|
+
$[4] !== onChange || $[5] !== type.name || $[6] !== type.options?.language ? (t2 = (code) => {
|
|
382
|
+
let fixedLanguage = type.options?.language;
|
|
383
|
+
onChange([setIfMissing({
|
|
384
|
+
_type: type.name,
|
|
385
|
+
language: fixedLanguage
|
|
386
|
+
}), code ? set(code, PATH_CODE) : unset(PATH_CODE)]);
|
|
387
|
+
}, $[4] = onChange, $[5] = type.name, $[6] = type.options?.language, $[7] = t2) : t2 = $[7];
|
|
388
|
+
let handleCodeChange = t2, { languages, language, languageMode } = useLanguageMode(props.schemaType, props.value), mounted = useMounted(), fullscreenEnabled = !type.options?.disableFullscreen, t3;
|
|
389
|
+
$[8] !== elementProps.onBlur || $[9] !== fullscreenEnabled || $[10] !== handleCodeChange || $[11] !== handleCodeFocus || $[12] !== languageMode || $[13] !== mounted || $[14] !== onHighlightChange || $[15] !== readOnly || $[16] !== value?.highlightedLines ? (t3 = (inputProps) => /* @__PURE__ */ jsx(FullscreenEditor, {
|
|
390
|
+
enabled: fullscreenEnabled,
|
|
391
|
+
children: (t4) => {
|
|
392
|
+
let { isFullscreen } = t4;
|
|
393
|
+
return /* @__PURE__ */ jsx(EditorContainer, {
|
|
394
|
+
$fullscreen: isFullscreen,
|
|
395
|
+
border: !isFullscreen,
|
|
396
|
+
overflow: "hidden",
|
|
397
|
+
radius: 1,
|
|
398
|
+
sizing: "border",
|
|
399
|
+
readOnly,
|
|
400
|
+
children: mounted && /* @__PURE__ */ jsx(Suspense, {
|
|
401
|
+
fallback: /* @__PURE__ */ jsx(Box, {
|
|
402
|
+
padding: 3,
|
|
403
|
+
children: /* @__PURE__ */ jsx(Text, { children: "Loading code editor..." })
|
|
404
|
+
}),
|
|
405
|
+
children: /* @__PURE__ */ jsx(CodeMirrorProxy, {
|
|
406
|
+
languageMode,
|
|
407
|
+
onChange: handleCodeChange,
|
|
408
|
+
value: inputProps.value,
|
|
409
|
+
highlightLines: value?.highlightedLines,
|
|
410
|
+
onHighlightChange,
|
|
411
|
+
readOnly,
|
|
412
|
+
onFocus: handleCodeFocus,
|
|
413
|
+
onBlur: elementProps.onBlur
|
|
414
|
+
})
|
|
415
|
+
})
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}), $[8] = elementProps.onBlur, $[9] = fullscreenEnabled, $[10] = handleCodeChange, $[11] = handleCodeFocus, $[12] = languageMode, $[13] = mounted, $[14] = onHighlightChange, $[15] = readOnly, $[16] = value?.highlightedLines, $[17] = t3) : t3 = $[17], value?.highlightedLines;
|
|
419
|
+
let renderCodeInput = t3, t4;
|
|
420
|
+
$[18] !== language || $[19] !== languageFieldMember || $[20] !== languages || $[21] !== renderField || $[22] !== renderInput || $[23] !== renderItem || $[24] !== renderPreview ? (t4 = languageFieldMember && /* @__PURE__ */ jsx(LanguageField, {
|
|
421
|
+
member: languageFieldMember,
|
|
422
|
+
language,
|
|
423
|
+
languages,
|
|
424
|
+
renderField,
|
|
425
|
+
renderItem,
|
|
426
|
+
renderInput,
|
|
427
|
+
renderPreview
|
|
428
|
+
}), $[18] = language, $[19] = languageFieldMember, $[20] = languages, $[21] = renderField, $[22] = renderInput, $[23] = renderItem, $[24] = renderPreview, $[25] = t4) : t4 = $[25];
|
|
429
|
+
let t5;
|
|
430
|
+
$[26] !== filenameMember || $[27] !== renderField || $[28] !== renderInput || $[29] !== renderItem || $[30] !== renderPreview || $[31] !== type.options?.withFilename ? (t5 = type.options?.withFilename && filenameMember && /* @__PURE__ */ jsx(MemberField, {
|
|
431
|
+
member: filenameMember,
|
|
432
|
+
renderItem,
|
|
433
|
+
renderField,
|
|
434
|
+
renderInput,
|
|
435
|
+
renderPreview
|
|
436
|
+
}), $[26] = filenameMember, $[27] = renderField, $[28] = renderInput, $[29] = renderItem, $[30] = renderPreview, $[31] = type.options?.withFilename, $[32] = t5) : t5 = $[32];
|
|
437
|
+
let t6;
|
|
438
|
+
$[33] !== codeFieldMember || $[34] !== renderCodeInput || $[35] !== renderField || $[36] !== renderItem || $[37] !== renderPreview ? (t6 = codeFieldMember && /* @__PURE__ */ jsx(MemberField, {
|
|
439
|
+
member: codeFieldMember,
|
|
440
|
+
renderInput: renderCodeInput,
|
|
441
|
+
renderItem,
|
|
442
|
+
renderField,
|
|
443
|
+
renderPreview
|
|
444
|
+
}), $[33] = codeFieldMember, $[34] = renderCodeInput, $[35] = renderField, $[36] = renderItem, $[37] = renderPreview, $[38] = t6) : t6 = $[38];
|
|
445
|
+
let t7;
|
|
446
|
+
return $[39] !== t4 || $[40] !== t5 || $[41] !== t6 ? (t7 = /* @__PURE__ */ jsxs(Stack, {
|
|
447
|
+
gap: 4,
|
|
448
|
+
children: [
|
|
449
|
+
t4,
|
|
450
|
+
t5,
|
|
451
|
+
t6
|
|
452
|
+
]
|
|
453
|
+
}), $[39] = t4, $[40] = t5, $[41] = t6, $[42] = t7) : t7 = $[42], t7;
|
|
454
|
+
}
|
|
455
|
+
function getMedia(language) {
|
|
456
|
+
if (language === "jsx") return /* @__PURE__ */ jsx("svg", {
|
|
457
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
458
|
+
viewBox: "0 0 128 128",
|
|
459
|
+
children: /* @__PURE__ */ jsxs("g", {
|
|
460
|
+
fill: "#61DAFB",
|
|
461
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
462
|
+
cx: "64",
|
|
463
|
+
cy: "64",
|
|
464
|
+
r: "11.4"
|
|
465
|
+
}), /* @__PURE__ */ jsx("path", { d: "M107.3 45.2c-2.2-.8-4.5-1.6-6.9-2.3.6-2.4 1.1-4.8 1.5-7.1 2.1-13.2-.2-22.5-6.6-26.1-1.9-1.1-4-1.6-6.4-1.6-7 0-15.9 5.2-24.9 13.9-9-8.7-17.9-13.9-24.9-13.9-2.4 0-4.5.5-6.4 1.6-6.4 3.7-8.7 13-6.6 26.1.4 2.3.9 4.7 1.5 7.1-2.4.7-4.7 1.4-6.9 2.3C8.2 50 1.4 56.6 1.4 64s6.9 14 19.3 18.8c2.2.8 4.5 1.6 6.9 2.3-.6 2.4-1.1 4.8-1.5 7.1-2.1 13.2.2 22.5 6.6 26.1 1.9 1.1 4 1.6 6.4 1.6 7.1 0 16-5.2 24.9-13.9 9 8.7 17.9 13.9 24.9 13.9 2.4 0 4.5-.5 6.4-1.6 6.4-3.7 8.7-13 6.6-26.1-.4-2.3-.9-4.7-1.5-7.1 2.4-.7 4.7-1.4 6.9-2.3 12.5-4.8 19.3-11.4 19.3-18.8s-6.8-14-19.3-18.8zM92.5 14.7c4.1 2.4 5.5 9.8 3.8 20.3-.3 2.1-.8 4.3-1.4 6.6-5.2-1.2-10.7-2-16.5-2.5-3.4-4.8-6.9-9.1-10.4-13 7.4-7.3 14.9-12.3 21-12.3 1.3 0 2.5.3 3.5.9zM81.3 74c-1.8 3.2-3.9 6.4-6.1 9.6-3.7.3-7.4.4-11.2.4-3.9 0-7.6-.1-11.2-.4-2.2-3.2-4.2-6.4-6-9.6-1.9-3.3-3.7-6.7-5.3-10 1.6-3.3 3.4-6.7 5.3-10 1.8-3.2 3.9-6.4 6.1-9.6 3.7-.3 7.4-.4 11.2-.4 3.9 0 7.6.1 11.2.4 2.2 3.2 4.2 6.4 6 9.6 1.9 3.3 3.7 6.7 5.3 10-1.7 3.3-3.4 6.6-5.3 10zm8.3-3.3c1.5 3.5 2.7 6.9 3.8 10.3-3.4.8-7 1.4-10.8 1.9 1.2-1.9 2.5-3.9 3.6-6 1.2-2.1 2.3-4.2 3.4-6.2zM64 97.8c-2.4-2.6-4.7-5.4-6.9-8.3 2.3.1 4.6.2 6.9.2 2.3 0 4.6-.1 6.9-.2-2.2 2.9-4.5 5.7-6.9 8.3zm-18.6-15c-3.8-.5-7.4-1.1-10.8-1.9 1.1-3.3 2.3-6.8 3.8-10.3 1.1 2 2.2 4.1 3.4 6.1 1.2 2.2 2.4 4.1 3.6 6.1zm-7-25.5c-1.5-3.5-2.7-6.9-3.8-10.3 3.4-.8 7-1.4 10.8-1.9-1.2 1.9-2.5 3.9-3.6 6-1.2 2.1-2.3 4.2-3.4 6.2zM64 30.2c2.4 2.6 4.7 5.4 6.9 8.3-2.3-.1-4.6-.2-6.9-.2-2.3 0-4.6.1-6.9.2 2.2-2.9 4.5-5.7 6.9-8.3zm22.2 21l-3.6-6c3.8.5 7.4 1.1 10.8 1.9-1.1 3.3-2.3 6.8-3.8 10.3-1.1-2.1-2.2-4.2-3.4-6.2zM31.7 35c-1.7-10.5-.3-17.9 3.8-20.3 1-.6 2.2-.9 3.5-.9 6 0 13.5 4.9 21 12.3-3.5 3.8-7 8.2-10.4 13-5.8.5-11.3 1.4-16.5 2.5-.6-2.3-1-4.5-1.4-6.6zM7 64c0-4.7 5.7-9.7 15.7-13.4 2-.8 4.2-1.5 6.4-2.1 1.6 5 3.6 10.3 6 15.6-2.4 5.3-4.5 10.5-6 15.5C15.3 75.6 7 69.6 7 64zm28.5 49.3c-4.1-2.4-5.5-9.8-3.8-20.3.3-2.1.8-4.3 1.4-6.6 5.2 1.2 10.7 2 16.5 2.5 3.4 4.8 6.9 9.1 10.4 13-7.4 7.3-14.9 12.3-21 12.3-1.3 0-2.5-.3-3.5-.9zM96.3 93c1.7 10.5.3 17.9-3.8 20.3-1 .6-2.2.9-3.5.9-6 0-13.5-4.9-21-12.3 3.5-3.8 7-8.2 10.4-13 5.8-.5 11.3-1.4 16.5-2.5.6 2.3 1 4.5 1.4 6.6zm9-15.6c-2 .8-4.2 1.5-6.4 2.1-1.6-5-3.6-10.3-6-15.6 2.4-5.3 4.5-10.5 6-15.5 13.8 4 22.1 10 22.1 15.6 0 4.7-5.8 9.7-15.7 13.4z" })]
|
|
466
|
+
})
|
|
467
|
+
});
|
|
468
|
+
if (language === "javascript") return /* @__PURE__ */ jsxs("svg", {
|
|
469
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
470
|
+
viewBox: "0 0 128 128",
|
|
471
|
+
children: [/* @__PURE__ */ jsx("path", {
|
|
472
|
+
fill: "#F0DB4F",
|
|
473
|
+
d: "M1.408 1.408h125.184v125.185H1.408z"
|
|
474
|
+
}), /* @__PURE__ */ jsx("path", {
|
|
475
|
+
fill: "#323330",
|
|
476
|
+
d: "M116.347 96.736c-.917-5.711-4.641-10.508-15.672-14.981-3.832-1.761-8.104-3.022-9.377-5.926-.452-1.69-.512-2.642-.226-3.665.821-3.32 4.784-4.355 7.925-3.403 2.023.678 3.938 2.237 5.093 4.724 5.402-3.498 5.391-3.475 9.163-5.879-1.381-2.141-2.118-3.129-3.022-4.045-3.249-3.629-7.676-5.498-14.756-5.355l-3.688.477c-3.534.893-6.902 2.748-8.877 5.235-5.926 6.724-4.236 18.492 2.975 23.335 7.104 5.332 17.54 6.545 18.873 11.531 1.297 6.104-4.486 8.08-10.234 7.378-4.236-.881-6.592-3.034-9.139-6.949-4.688 2.713-4.688 2.713-9.508 5.485 1.143 2.499 2.344 3.63 4.26 5.795 9.068 9.198 31.76 8.746 35.83-5.176.165-.478 1.261-3.666.38-8.581zM69.462 58.943H57.753l-.048 30.272c0 6.438.333 12.34-.714 14.149-1.713 3.558-6.152 3.117-8.175 2.427-2.059-1.012-3.106-2.451-4.319-4.485-.333-.584-.583-1.036-.667-1.071l-9.52 5.83c1.583 3.249 3.915 6.069 6.902 7.901 4.462 2.678 10.459 3.499 16.731 2.059 4.082-1.189 7.604-3.652 9.448-7.401 2.666-4.915 2.094-10.864 2.07-17.444.06-10.735.001-21.468.001-32.237z"
|
|
477
|
+
})]
|
|
478
|
+
});
|
|
479
|
+
if (language === "php") return /* @__PURE__ */ jsx("svg", {
|
|
480
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
481
|
+
viewBox: "0 0 800 400",
|
|
482
|
+
children: /* @__PURE__ */ jsx("g", {
|
|
483
|
+
transform: "translate(-44.632 -141.55)",
|
|
484
|
+
children: /* @__PURE__ */ jsxs("g", {
|
|
485
|
+
transform: "matrix(8.3528 0 0 8.3119 -727.13 -3759.5)",
|
|
486
|
+
children: [
|
|
487
|
+
/* @__PURE__ */ jsx("path", { d: "m99.974 479.48h14.204c4.1693 0.0354 7.1903 1.2367 9.063 3.604 1.8726 2.3674 2.491 5.6004 1.855 9.699-0.24737 1.8727-0.79504 3.71-1.643 5.512-0.8127 1.802-1.9434 3.4273-3.392 4.876-1.7667 1.8373-3.657 3.0033-5.671 3.498-2.014 0.49467-4.0987 0.742-6.254 0.742h-6.36l-2.014 10.07h-7.367l7.579-38.001m6.201 6.042-3.18 15.9c0.21198 0.0353 0.42398 0.053 0.636 0.053h0.742c3.392 0.0353 6.2186-0.30033 8.48-1.007 2.2613-0.74199 3.7806-3.3213 4.558-7.738 0.63597-3.71-0.00003-5.8476-1.908-6.413-1.8727-0.56531-4.2224-0.83031-7.049-0.795-0.42402 0.0353-0.83035 0.053-1.219 0.053-0.35335 0.00002-0.72435 0.00002-1.113 0l0.053-0.053" }),
|
|
488
|
+
/* @__PURE__ */ jsx("path", { d: "m133.49 469.36h7.314l-2.067 10.123h6.572c3.604 0.0707 6.2893 0.81269 8.056 2.226 1.802 1.4134 2.332 4.0987 1.59 8.056l-3.551 17.649h-7.42l3.392-16.854c0.35328-1.7666 0.2473-3.021-0.318-3.763-0.56536-0.74198-1.7844-1.113-3.657-1.113l-5.883-0.053-4.346 21.783h-7.314l7.632-38.054" }),
|
|
489
|
+
/* @__PURE__ */ jsx("path", { d: "m162.81 479.48h14.204c4.1693 0.0354 7.1903 1.2367 9.063 3.604 1.8726 2.3674 2.491 5.6004 1.855 9.699-0.24737 1.8727-0.79503 3.71-1.643 5.512-0.8127 1.802-1.9434 3.4273-3.392 4.876-1.7667 1.8373-3.657 3.0033-5.671 3.498-2.014 0.49467-4.0987 0.742-6.254 0.742h-6.36l-2.014 10.07h-7.367l7.579-38.001m6.201 6.042-3.18 15.9c0.21199 0.0353 0.42399 0.053 0.636 0.053h0.742c3.392 0.0353 6.2186-0.30033 8.48-1.007 2.2613-0.74199 3.7806-3.3213 4.558-7.738 0.63597-3.71-0.00003-5.8476-1.908-6.413-1.8727-0.56531-4.2224-0.83031-7.049-0.795-0.42402 0.0353-0.83035 0.053-1.219 0.053-0.35335 0.00002-0.72435 0.00002-1.113 0l0.053-0.053" })
|
|
490
|
+
]
|
|
491
|
+
})
|
|
492
|
+
})
|
|
493
|
+
});
|
|
494
|
+
if (language === "json") return /* @__PURE__ */ jsxs("svg", {
|
|
495
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
496
|
+
xmlnsXlink: "http://www.w3.org/1999/xlink",
|
|
497
|
+
viewBox: "0 0 160 160",
|
|
498
|
+
children: [
|
|
499
|
+
/* @__PURE__ */ jsxs("defs", { children: [
|
|
500
|
+
/* @__PURE__ */ jsxs("linearGradient", {
|
|
501
|
+
id: "a",
|
|
502
|
+
children: [/* @__PURE__ */ jsx("stop", { offset: "0" }), /* @__PURE__ */ jsx("stop", {
|
|
503
|
+
offset: "1",
|
|
504
|
+
stopColor: "#fff"
|
|
505
|
+
})]
|
|
506
|
+
}),
|
|
507
|
+
/* @__PURE__ */ jsx("linearGradient", {
|
|
508
|
+
x1: "-553.27",
|
|
509
|
+
y1: "525.908",
|
|
510
|
+
x2: "-666.116",
|
|
511
|
+
y2: "413.045",
|
|
512
|
+
id: "c",
|
|
513
|
+
xlinkHref: "#a",
|
|
514
|
+
gradientUnits: "userSpaceOnUse",
|
|
515
|
+
gradientTransform: "matrix(.99884 0 0 .9987 689.008 -388.844)"
|
|
516
|
+
}),
|
|
517
|
+
/* @__PURE__ */ jsx("linearGradient", {
|
|
518
|
+
x1: "-666.117",
|
|
519
|
+
y1: "413.045",
|
|
520
|
+
x2: "-553.27",
|
|
521
|
+
y2: "525.908",
|
|
522
|
+
id: "b",
|
|
523
|
+
xlinkHref: "#a",
|
|
524
|
+
gradientUnits: "userSpaceOnUse",
|
|
525
|
+
gradientTransform: "matrix(.99884 0 0 .9987 689.008 -388.844)"
|
|
526
|
+
})
|
|
527
|
+
] }),
|
|
528
|
+
/* @__PURE__ */ jsx("path", {
|
|
529
|
+
d: "M79.865 119.1c35.397 48.255 70.04-13.469 69.988-50.587-.06-43.886-44.54-68.414-70.017-68.414C38.943.1 0 33.895 0 80.135 0 131.531 44.64 160 79.836 160c-7.965-1.147-34.507-6.834-34.863-67.967-.24-41.346 13.487-57.865 34.805-50.599.477.177 23.514 9.265 23.514 38.95 0 29.56-23.427 38.716-23.427 38.716z",
|
|
530
|
+
style: { marker: "none" },
|
|
531
|
+
color: "#000",
|
|
532
|
+
fill: "url(#b)",
|
|
533
|
+
fillRule: "evenodd",
|
|
534
|
+
overflow: "visible"
|
|
535
|
+
}),
|
|
536
|
+
/* @__PURE__ */ jsx("path", {
|
|
537
|
+
d: "M79.823 41.4C56.433 33.34 27.78 52.618 27.78 91.23c0 63.048 46.72 68.77 52.384 68.77C121.057 160 160 126.204 160 79.964 160 28.568 115.36.1 80.164.1c9.749-1.35 52.541 10.55 52.541 69.037 0 38.141-31.953 58.905-52.735 50.033-.478-.177-23.514-9.264-23.514-38.95 0-29.56 23.367-38.818 23.367-38.818z",
|
|
538
|
+
style: { marker: "none" },
|
|
539
|
+
color: "#000",
|
|
540
|
+
fill: "url(#c)",
|
|
541
|
+
fillRule: "evenodd",
|
|
542
|
+
overflow: "visible"
|
|
543
|
+
})
|
|
544
|
+
]
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
const PreviewContainer = styled(Box).withConfig({
|
|
548
|
+
displayName: "PreviewContainer",
|
|
549
|
+
componentId: "sc-o2s7d4-0"
|
|
550
|
+
})`position:relative;`;
|
|
551
|
+
/**
|
|
552
|
+
* @public
|
|
553
|
+
*/
|
|
554
|
+
function PreviewCode(props) {
|
|
555
|
+
let $ = c(10), { selection, schemaType: type } = props, { languageMode } = useLanguageMode(type, props.selection), mounted = useMounted(), t0;
|
|
556
|
+
$[0] === selection ? t0 = $[1] : (t0 = selection?.filename || selection?.language ? /* @__PURE__ */ jsx(Card, {
|
|
557
|
+
paddingBottom: 4,
|
|
558
|
+
marginBottom: selection.code ? 4 : 0,
|
|
559
|
+
borderBottom: !!selection.code,
|
|
560
|
+
children: /* @__PURE__ */ jsxs(Flex, {
|
|
561
|
+
align: "center",
|
|
562
|
+
justify: "flex-end",
|
|
563
|
+
children: [selection?.filename ? /* @__PURE__ */ jsx(Box, {
|
|
564
|
+
flex: 1,
|
|
565
|
+
children: /* @__PURE__ */ jsx(Text, { children: /* @__PURE__ */ jsx("code", { children: selection.filename }) })
|
|
566
|
+
}) : null, selection?.language ? /* @__PURE__ */ jsx(Label, {
|
|
567
|
+
muted: !0,
|
|
568
|
+
children: selection.language
|
|
569
|
+
}) : null]
|
|
570
|
+
})
|
|
571
|
+
}) : null, $[0] = selection, $[1] = t0);
|
|
572
|
+
let t1;
|
|
573
|
+
$[2] !== languageMode || $[3] !== mounted || $[4] !== selection?.code || $[5] !== selection?.highlightedLines ? (t1 = mounted && /* @__PURE__ */ jsx(Suspense, {
|
|
574
|
+
fallback: /* @__PURE__ */ jsx(Card, {
|
|
575
|
+
padding: 2,
|
|
576
|
+
children: "Loading code preview..."
|
|
577
|
+
}),
|
|
578
|
+
children: /* @__PURE__ */ jsx(CodeMirrorProxy, {
|
|
579
|
+
readOnly: !0,
|
|
580
|
+
editable: !1,
|
|
581
|
+
value: selection?.code || "",
|
|
582
|
+
highlightLines: selection?.highlightedLines || [],
|
|
583
|
+
basicSetup: {
|
|
584
|
+
lineNumbers: !1,
|
|
585
|
+
foldGutter: !1,
|
|
586
|
+
highlightSelectionMatches: !1,
|
|
587
|
+
highlightActiveLineGutter: !1,
|
|
588
|
+
highlightActiveLine: !1
|
|
589
|
+
},
|
|
590
|
+
languageMode
|
|
591
|
+
})
|
|
592
|
+
}), $[2] = languageMode, $[3] = mounted, $[4] = selection?.code, $[5] = selection?.highlightedLines, $[6] = t1) : t1 = $[6];
|
|
593
|
+
let t2;
|
|
594
|
+
return $[7] !== t0 || $[8] !== t1 ? (t2 = /* @__PURE__ */ jsx(PreviewContainer, { children: /* @__PURE__ */ jsxs(Card, {
|
|
595
|
+
padding: 4,
|
|
596
|
+
children: [t0, t1]
|
|
597
|
+
}) }), $[7] = t0, $[8] = t1, $[9] = t2) : t2 = $[9], t2;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* @public
|
|
601
|
+
*/
|
|
602
|
+
const codeTypeName = "code", codeSchema = defineType({
|
|
603
|
+
name: "code",
|
|
604
|
+
type: "object",
|
|
605
|
+
title: "Code",
|
|
606
|
+
components: {
|
|
607
|
+
input: CodeInput,
|
|
608
|
+
preview: PreviewCode
|
|
609
|
+
},
|
|
610
|
+
icon: CodeBlockIcon,
|
|
611
|
+
fields: [
|
|
612
|
+
{
|
|
613
|
+
name: "language",
|
|
614
|
+
title: "Language",
|
|
615
|
+
type: "string"
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
name: "filename",
|
|
619
|
+
title: "Filename",
|
|
620
|
+
type: "string"
|
|
621
|
+
},
|
|
622
|
+
{
|
|
623
|
+
title: "Code",
|
|
624
|
+
name: "code",
|
|
625
|
+
type: "text"
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
title: "Highlighted lines",
|
|
629
|
+
name: "highlightedLines",
|
|
630
|
+
type: "array",
|
|
631
|
+
of: [{
|
|
632
|
+
type: "number",
|
|
633
|
+
title: "Highlighted line"
|
|
634
|
+
}]
|
|
635
|
+
}
|
|
636
|
+
],
|
|
637
|
+
preview: {
|
|
638
|
+
select: {
|
|
639
|
+
language: "language",
|
|
640
|
+
code: "code",
|
|
641
|
+
filename: "filename",
|
|
642
|
+
highlightedLines: "highlightedLines"
|
|
643
|
+
},
|
|
644
|
+
prepare: (value) => ({
|
|
645
|
+
title: value.filename || (value.language || "unknown").toUpperCase(),
|
|
646
|
+
media: getMedia(value?.language),
|
|
647
|
+
selection: value
|
|
648
|
+
})
|
|
649
|
+
}
|
|
650
|
+
}), codeInput = definePlugin((config) => {
|
|
651
|
+
let codeModes = config && config.codeModes, basePlugin = {
|
|
652
|
+
name: "@sanity/code-input",
|
|
653
|
+
schema: { types: [codeSchema] }
|
|
654
|
+
};
|
|
655
|
+
return codeModes ? {
|
|
656
|
+
...basePlugin,
|
|
657
|
+
form: { components: { input: (props) => props.id === "root" ? /* @__PURE__ */ jsx(CodeInputConfigContext.Provider, {
|
|
658
|
+
value: config,
|
|
659
|
+
children: props.renderDefault(props)
|
|
660
|
+
}) : props.renderDefault(props) } }
|
|
661
|
+
} : basePlugin;
|
|
662
|
+
});
|
|
663
|
+
export { PreviewCode, codeInput, codeSchema, codeTypeName };
|
|
664
|
+
|
|
665
|
+
//# sourceMappingURL=index.js.map
|