@reactloom/code-editor 0.0.0-stage → 1.0.1
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/README.md +39 -2
- package/dist/LICENSE +21 -0
- package/dist/_internal/primitives/visually-hidden.js +29 -0
- package/dist/_internal/primitives/visually-hidden.js.map +1 -0
- package/dist/_internal/utils/cx.js +10 -0
- package/dist/_internal/utils/cx.js.map +1 -0
- package/dist/_internal/utils/data-attr.js +8 -0
- package/dist/_internal/utils/data-attr.js.map +1 -0
- package/dist/code-editor.d.ts +53 -0
- package/dist/code-editor.d.ts.map +1 -0
- package/dist/code-editor.js +344 -0
- package/dist/code-editor.js.map +1 -0
- package/dist/code-editor.module.js +15 -0
- package/dist/code-editor.module.js.map +1 -0
- package/dist/diff-viewer.d.ts +14 -0
- package/dist/diff-viewer.d.ts.map +1 -0
- package/dist/diff-viewer.js +181 -0
- package/dist/diff-viewer.js.map +1 -0
- package/dist/diff-viewer.module.js +34 -0
- package/dist/diff-viewer.module.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/styles.css +3 -0
- package/package.json +103 -3
package/README.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @reactloom/code-editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Accessible code fields for ReactLoom on CodeMirror 6: `CodeEditor`, a labelled source editor
|
|
4
|
+
themed with ReactLoom tokens, and `DiffViewer`, a side-by-side or unified diff.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pnpm add @reactloom/code-editor @reactloom/ui @reactloom/theme
|
|
8
|
+
# plus the CodeMirror languages you need, for example:
|
|
9
|
+
pnpm add @codemirror/lang-json
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import '@reactloom/code-editor/styles.css';
|
|
14
|
+
import { CodeEditor } from '@reactloom/code-editor';
|
|
15
|
+
import { json } from '@codemirror/lang-json';
|
|
16
|
+
|
|
17
|
+
<CodeEditor
|
|
18
|
+
label="Webhook retry policy (JSON)"
|
|
19
|
+
description="Applied to every outgoing webhook."
|
|
20
|
+
value={value}
|
|
21
|
+
onValueChange={setValue}
|
|
22
|
+
extensions={[json()]}
|
|
23
|
+
error={error}
|
|
24
|
+
name="policy"
|
|
25
|
+
/>;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- **Keyboard-safe:** Tab moves focus out of the editor by default, so keyboard users never get
|
|
29
|
+
trapped. Set `tabIndents` to indent instead; Escape then Tab still leaves.
|
|
30
|
+
- **Forms:** `name` submits the value with a hidden input; `error` and `description` are announced
|
|
31
|
+
like any ReactLoom field.
|
|
32
|
+
- **Server rendering:** the first paint is plain, readable code; CodeMirror takes over in the
|
|
33
|
+
browser.
|
|
34
|
+
- **Diffs:** `<DiffViewer title="config.ts" original={before} modified={after} />`.
|
|
35
|
+
|
|
36
|
+
No languages are bundled, so the package stays small: pass any CodeMirror extension in
|
|
37
|
+
`extensions`.
|
|
38
|
+
|
|
39
|
+
Documentation and live examples: <https://www.reactloom.dev/components/code-editor> ·
|
|
40
|
+
<https://www.reactloom.dev/components/diff-viewer>
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ReactLoom UI contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// ../primitives/src/visually-hidden.tsx
|
|
4
|
+
var hidden = {
|
|
5
|
+
position: "absolute",
|
|
6
|
+
width: 1,
|
|
7
|
+
height: 1,
|
|
8
|
+
padding: 0,
|
|
9
|
+
margin: -1,
|
|
10
|
+
overflow: "hidden",
|
|
11
|
+
clip: "rect(0 0 0 0)",
|
|
12
|
+
clipPath: "inset(50%)",
|
|
13
|
+
whiteSpace: "nowrap",
|
|
14
|
+
border: 0
|
|
15
|
+
};
|
|
16
|
+
/** Content available to assistive technology but not rendered visually. */
|
|
17
|
+
var VisuallyHidden = /*#__PURE__*/ forwardRef(function VisuallyHidden({ style, ...props }, ref) {
|
|
18
|
+
return /* @__PURE__ */ jsx("span", {
|
|
19
|
+
ref,
|
|
20
|
+
...props,
|
|
21
|
+
style: {
|
|
22
|
+
...hidden,
|
|
23
|
+
...style
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
export { VisuallyHidden };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=visually-hidden.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visually-hidden.js","names":[],"sources":["../../../../primitives/src/visually-hidden.tsx"],"sourcesContent":["import { forwardRef, type CSSProperties, type HTMLAttributes } from 'react';\n\nconst hidden: CSSProperties = {\n position: 'absolute',\n width: 1,\n height: 1,\n padding: 0,\n margin: -1,\n overflow: 'hidden',\n clip: 'rect(0 0 0 0)',\n clipPath: 'inset(50%)',\n whiteSpace: 'nowrap',\n border: 0,\n};\n\nexport type VisuallyHiddenProps = HTMLAttributes<HTMLSpanElement>;\n\n/** Content available to assistive technology but not rendered visually. */\nexport const VisuallyHidden = /*#__PURE__*/ forwardRef<HTMLSpanElement, VisuallyHiddenProps>(function VisuallyHidden(\n { style, ...props },\n ref,\n) {\n return <span ref={ref} {...props} style={{ ...hidden, ...style }} />;\n});\n"],"mappings":";;;AAEA,IAAM,SAAwB;CAC5B,UAAU;CACV,OAAO;CACP,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,UAAU;CACV,MAAM;CACN,UAAU;CACV,YAAY;CACZ,QAAQ;AACV;;AAKA,IAAa,iBAA+B,yBAAiD,SAAS,eACpG,EAAE,OAAO,GAAG,SACZ,KACA;CACA,OAAO,oBAAC,QAAD;EAAW;EAAK,GAAI;EAAO,OAAO;GAAE,GAAG;GAAQ,GAAG;EAAM;CAAI,CAAA;AACrE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// ../utils/src/cx.ts
|
|
2
|
+
/** Joins truthy class names with a single space. */
|
|
3
|
+
function cx(...values) {
|
|
4
|
+
let out = "";
|
|
5
|
+
for (const v of values) if (v) out = out ? `${out} ${v}` : v;
|
|
6
|
+
return out || void 0;
|
|
7
|
+
}
|
|
8
|
+
export { cx };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=cx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cx.js","names":[],"sources":["../../../../utils/src/cx.ts"],"sourcesContent":["type ClassValue = string | false | null | undefined;\n\n/** Joins truthy class names with a single space. */\nexport function cx(...values: ClassValue[]): string | undefined {\n let out = '';\n for (const v of values) if (v) out = out ? `${out} ${v}` : v;\n return out || undefined;\n}\n"],"mappings":";;AAGA,SAAgB,GAAG,GAAG,QAA0C;CAC9D,IAAI,MAAM;CACV,KAAK,MAAM,KAAK,QAAQ,IAAI,GAAG,MAAM,MAAM,GAAG,IAAI,GAAG,MAAM;CAC3D,OAAO,OAAO,KAAA;AAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-attr.js","names":[],"sources":["../../../../utils/src/data-attr.ts"],"sourcesContent":["/** `true` → `\"\"` (attribute present), falsy → `undefined` (attribute absent). */\nexport function dataAttr(condition: boolean | undefined): '' | undefined {\n return condition ? '' : undefined;\n}\n"],"mappings":";;AACA,SAAgB,SAAS,WAAgD;CACvE,OAAO,YAAY,KAAK,KAAA;AAC1B"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type Extension } from '@codemirror/state';
|
|
3
|
+
export interface CodeEditorMessages {
|
|
4
|
+
/** Visually hidden instructions, used when `tabIndents` is on. */
|
|
5
|
+
tabHint: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CodeEditorProps {
|
|
8
|
+
/** Visible label; it names the editable area. */
|
|
9
|
+
label: ReactNode;
|
|
10
|
+
hideLabel?: boolean;
|
|
11
|
+
description?: ReactNode;
|
|
12
|
+
error?: ReactNode;
|
|
13
|
+
invalid?: boolean;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
readOnly?: boolean;
|
|
17
|
+
value?: string;
|
|
18
|
+
defaultValue?: string;
|
|
19
|
+
onValueChange?: (value: string) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Language support and other CodeMirror extensions, e.g. `[markdown()]` from
|
|
22
|
+
* `@codemirror/lang-markdown` or `[javascript({ typescript: true })]`. Install the ones you use;
|
|
23
|
+
* the package ships none so it stays small.
|
|
24
|
+
*/
|
|
25
|
+
extensions?: readonly Extension[];
|
|
26
|
+
placeholder?: string;
|
|
27
|
+
/** Show line numbers. @default true */
|
|
28
|
+
lineNumbers?: boolean;
|
|
29
|
+
/** Wrap long lines instead of scrolling horizontally. @default false */
|
|
30
|
+
wrap?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Tab inserts indentation instead of moving focus. Off by default so keyboard users can leave
|
|
33
|
+
* the field; when on, Escape then Tab leaves it (announced in a hint).
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
tabIndents?: boolean;
|
|
37
|
+
/** Submits the text in a hidden input with this name. */
|
|
38
|
+
name?: string;
|
|
39
|
+
/** Minimum height (CSS length or px). @default 160 */
|
|
40
|
+
minHeight?: number | string;
|
|
41
|
+
/** Scroll inside beyond this height (CSS length or px). */
|
|
42
|
+
maxHeight?: number | string;
|
|
43
|
+
messages?: Partial<CodeEditorMessages>;
|
|
44
|
+
className?: string;
|
|
45
|
+
id?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A labelled field for code and Markdown source on CodeMirror 6. Tab is not captured unless
|
|
49
|
+
* `tabIndents` is on, the text is a plain string, and the server renders it as read-only text in
|
|
50
|
+
* the same box so the page does not shift when the editor loads.
|
|
51
|
+
*/
|
|
52
|
+
export declare const CodeEditor: import("react").ForwardRefExoticComponent<CodeEditorProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
53
|
+
//# sourceMappingURL=code-editor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-editor.d.ts","sourceRoot":"","sources":["../src/code-editor.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAkD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAMvF,OAAO,EAA4B,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAe7E,MAAM,WAAW,kBAAkB;IACjC,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAC;CACjB;AAMD,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uCAAuC;IACvC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,wEAAwE;IACxE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAoCD;;;;GAIG;AACH,eAAO,MAAM,UAAU,4GAmKrB,CAAC"}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { VisuallyHidden } from "./_internal/primitives/visually-hidden.js";
|
|
3
|
+
import { cx } from "./_internal/utils/cx.js";
|
|
4
|
+
import { dataAttr } from "./_internal/utils/data-attr.js";
|
|
5
|
+
import code_editor_module_default from "./code-editor.module.js";
|
|
6
|
+
import { forwardRef, useEffect, useId, useRef, useState } from "react";
|
|
7
|
+
import { closeBrackets, closeBracketsKeymap } from "@codemirror/autocomplete";
|
|
8
|
+
import { defaultKeymap, history, historyKeymap, indentWithTab } from "@codemirror/commands";
|
|
9
|
+
import { HighlightStyle, bracketMatching, indentOnInput, syntaxHighlighting } from "@codemirror/language";
|
|
10
|
+
import { tags } from "@lezer/highlight";
|
|
11
|
+
import { highlightSelectionMatches, searchKeymap } from "@codemirror/search";
|
|
12
|
+
import { Compartment, EditorState } from "@codemirror/state";
|
|
13
|
+
import { EditorView, drawSelection, highlightActiveLine, highlightActiveLineGutter, keymap, lineNumbers, placeholder } from "@codemirror/view";
|
|
14
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
import { FormDescription, FormError, FormLabel } from "@reactloom/ui";
|
|
16
|
+
// src/code-editor.tsx
|
|
17
|
+
var defaultMessages = { tabHint: "Tab indents. Press Escape, then Tab, to leave the editor." };
|
|
18
|
+
var size = (v) => typeof v === "number" ? `${v}px` : v;
|
|
19
|
+
/** ReactLoom tokens for CodeMirror's chrome (syntax colours come from your highlight style). */
|
|
20
|
+
/**
|
|
21
|
+
* Syntax colours from the theme's text tokens, which are contrast-checked on surfaces in every
|
|
22
|
+
* theme (CodeMirror's default style is fixed light-theme colours and fails in dark themes).
|
|
23
|
+
*/
|
|
24
|
+
var reactloomHighlight = /*#__PURE__*/ HighlightStyle.define([
|
|
25
|
+
{
|
|
26
|
+
tag: [
|
|
27
|
+
tags.keyword,
|
|
28
|
+
tags.operatorKeyword,
|
|
29
|
+
tags.modifier,
|
|
30
|
+
tags.controlKeyword,
|
|
31
|
+
tags.moduleKeyword
|
|
32
|
+
],
|
|
33
|
+
color: "var(--pl-color-accent-fg)"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
tag: [
|
|
37
|
+
tags.string,
|
|
38
|
+
tags.special(tags.string),
|
|
39
|
+
tags.regexp,
|
|
40
|
+
tags.inserted
|
|
41
|
+
],
|
|
42
|
+
color: "var(--pl-color-success-fg)"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
tag: [
|
|
46
|
+
tags.number,
|
|
47
|
+
tags.bool,
|
|
48
|
+
tags.null,
|
|
49
|
+
tags.atom,
|
|
50
|
+
tags.unit
|
|
51
|
+
],
|
|
52
|
+
color: "var(--pl-color-warning-fg)"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
tag: [
|
|
56
|
+
tags.function(tags.variableName),
|
|
57
|
+
tags.function(tags.propertyName),
|
|
58
|
+
tags.definition(tags.function(tags.variableName)),
|
|
59
|
+
tags.macroName
|
|
60
|
+
],
|
|
61
|
+
color: "var(--pl-color-info-fg)"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
tag: [
|
|
65
|
+
tags.typeName,
|
|
66
|
+
tags.className,
|
|
67
|
+
tags.namespace,
|
|
68
|
+
tags.tagName,
|
|
69
|
+
tags.deleted,
|
|
70
|
+
tags.invalid
|
|
71
|
+
],
|
|
72
|
+
color: "var(--pl-color-danger-fg)"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
tag: [
|
|
76
|
+
tags.attributeName,
|
|
77
|
+
tags.propertyName,
|
|
78
|
+
tags.labelName
|
|
79
|
+
],
|
|
80
|
+
color: "var(--pl-color-info-fg)"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
tag: [
|
|
84
|
+
tags.comment,
|
|
85
|
+
tags.lineComment,
|
|
86
|
+
tags.blockComment,
|
|
87
|
+
tags.docComment,
|
|
88
|
+
tags.meta
|
|
89
|
+
],
|
|
90
|
+
color: "var(--pl-color-fg-muted)",
|
|
91
|
+
fontStyle: "italic"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
tag: tags.heading,
|
|
95
|
+
fontWeight: "bold",
|
|
96
|
+
color: "var(--pl-color-accent-fg)"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
tag: tags.strong,
|
|
100
|
+
fontWeight: "bold"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
tag: tags.emphasis,
|
|
104
|
+
fontStyle: "italic"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
tag: tags.strikethrough,
|
|
108
|
+
textDecoration: "line-through"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
tag: tags.link,
|
|
112
|
+
color: "var(--pl-color-accent-fg)",
|
|
113
|
+
textDecoration: "underline"
|
|
114
|
+
}
|
|
115
|
+
]);
|
|
116
|
+
var reactloomTheme = /*#__PURE__*/ EditorView.theme({
|
|
117
|
+
"&": {
|
|
118
|
+
color: "var(--pl-color-fg-default)",
|
|
119
|
+
backgroundColor: "transparent",
|
|
120
|
+
fontSize: "var(--pl-font-size-sm)"
|
|
121
|
+
},
|
|
122
|
+
".cm-content": {
|
|
123
|
+
fontFamily: "var(--pl-font-family-mono)",
|
|
124
|
+
padding: "var(--pl-space-2) 0",
|
|
125
|
+
caretColor: "var(--pl-color-fg-default)"
|
|
126
|
+
},
|
|
127
|
+
".cm-gutters": {
|
|
128
|
+
backgroundColor: "var(--pl-color-bg-subtle)",
|
|
129
|
+
color: "var(--pl-color-fg-subtle)",
|
|
130
|
+
borderInlineEnd: "1px solid var(--pl-color-border-default)"
|
|
131
|
+
},
|
|
132
|
+
".cm-activeLine": { backgroundColor: "color-mix(in srgb, var(--pl-color-accent-subtle) 45%, transparent)" },
|
|
133
|
+
".cm-activeLineGutter": {
|
|
134
|
+
backgroundColor: "var(--pl-color-bg-muted)",
|
|
135
|
+
color: "var(--pl-color-fg-default)"
|
|
136
|
+
},
|
|
137
|
+
"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection": { backgroundColor: "var(--pl-color-accent-subtle)" },
|
|
138
|
+
".cm-cursor": { borderInlineStartColor: "var(--pl-color-fg-default)" },
|
|
139
|
+
".cm-placeholder": { color: "var(--pl-color-fg-subtle)" },
|
|
140
|
+
".cm-panels": {
|
|
141
|
+
backgroundColor: "var(--pl-color-bg-subtle)",
|
|
142
|
+
color: "var(--pl-color-fg-default)"
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
/**
|
|
146
|
+
* A labelled field for code and Markdown source on CodeMirror 6. Tab is not captured unless
|
|
147
|
+
* `tabIndents` is on, the text is a plain string, and the server renders it as read-only text in
|
|
148
|
+
* the same box so the page does not shift when the editor loads.
|
|
149
|
+
*/
|
|
150
|
+
var CodeEditor = /*#__PURE__*/ forwardRef(function CodeEditor(props, ref) {
|
|
151
|
+
const { label, hideLabel, description, error, invalid, required, disabled = false, readOnly = false, extensions = [], placeholder: placeholder$1, lineNumbers: lineNumbers$1 = true, wrap = false, tabIndents = false, name, minHeight = 160, maxHeight, className } = props;
|
|
152
|
+
const messages = {
|
|
153
|
+
...defaultMessages,
|
|
154
|
+
...props.messages
|
|
155
|
+
};
|
|
156
|
+
const uid = useId();
|
|
157
|
+
const id = props.id ?? `${uid}-code`;
|
|
158
|
+
const labelId = `${id}-label`;
|
|
159
|
+
const descriptionId = description ? `${id}-description` : void 0;
|
|
160
|
+
const errorId = error ? `${id}-error` : void 0;
|
|
161
|
+
const hintId = `${id}-hint`;
|
|
162
|
+
const isInvalid = Boolean(invalid || error);
|
|
163
|
+
const [inner, setInner] = useState(props.defaultValue ?? "");
|
|
164
|
+
const controlled = props.value !== void 0;
|
|
165
|
+
const text = controlled ? props.value ?? "" : inner;
|
|
166
|
+
const hostRef = useRef(null);
|
|
167
|
+
const viewRef = useRef(null);
|
|
168
|
+
const [mounted, setMounted] = useState(false);
|
|
169
|
+
const onValueChange = useRef(props.onValueChange);
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
onValueChange.current = props.onValueChange;
|
|
172
|
+
});
|
|
173
|
+
const controlledRef = useRef(controlled);
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
controlledRef.current = controlled;
|
|
176
|
+
});
|
|
177
|
+
const compartments = useRef({
|
|
178
|
+
access: new Compartment(),
|
|
179
|
+
options: new Compartment(),
|
|
180
|
+
user: new Compartment()
|
|
181
|
+
});
|
|
182
|
+
const accessExtension = () => [
|
|
183
|
+
EditorState.readOnly.of(readOnly || disabled),
|
|
184
|
+
EditorView.editable.of(!readOnly && !disabled),
|
|
185
|
+
EditorView.contentAttributes.of({
|
|
186
|
+
id,
|
|
187
|
+
"aria-labelledby": labelId,
|
|
188
|
+
"aria-describedby": [
|
|
189
|
+
descriptionId,
|
|
190
|
+
errorId,
|
|
191
|
+
tabIndents ? hintId : void 0
|
|
192
|
+
].filter(Boolean).join(" "),
|
|
193
|
+
"aria-invalid": isInvalid ? "true" : "false",
|
|
194
|
+
...required ? { "aria-required": "true" } : {},
|
|
195
|
+
...readOnly ? { "aria-readonly": "true" } : {},
|
|
196
|
+
...disabled ? { "aria-disabled": "true" } : {},
|
|
197
|
+
...placeholder$1 ? { "aria-placeholder": placeholder$1 } : {}
|
|
198
|
+
})
|
|
199
|
+
];
|
|
200
|
+
const optionsExtension = () => [
|
|
201
|
+
lineNumbers$1 ? [lineNumbers(), highlightActiveLineGutter()] : [],
|
|
202
|
+
wrap ? EditorView.lineWrapping : [],
|
|
203
|
+
tabIndents ? keymap.of([indentWithTab]) : [],
|
|
204
|
+
placeholder$1 ? placeholder(placeholder$1) : []
|
|
205
|
+
];
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
const host = hostRef.current;
|
|
208
|
+
if (!host) return;
|
|
209
|
+
const { access, options, user } = compartments.current;
|
|
210
|
+
const view = new EditorView({
|
|
211
|
+
parent: host,
|
|
212
|
+
state: EditorState.create({
|
|
213
|
+
doc: text,
|
|
214
|
+
extensions: [
|
|
215
|
+
history(),
|
|
216
|
+
drawSelection(),
|
|
217
|
+
indentOnInput(),
|
|
218
|
+
syntaxHighlighting(reactloomHighlight, { fallback: true }),
|
|
219
|
+
bracketMatching(),
|
|
220
|
+
closeBrackets(),
|
|
221
|
+
highlightActiveLine(),
|
|
222
|
+
highlightSelectionMatches(),
|
|
223
|
+
keymap.of([
|
|
224
|
+
...closeBracketsKeymap,
|
|
225
|
+
...defaultKeymap,
|
|
226
|
+
...searchKeymap,
|
|
227
|
+
...historyKeymap
|
|
228
|
+
]),
|
|
229
|
+
reactloomTheme,
|
|
230
|
+
access.of(accessExtension()),
|
|
231
|
+
options.of(optionsExtension()),
|
|
232
|
+
user.of([...extensions]),
|
|
233
|
+
EditorView.updateListener.of((update) => {
|
|
234
|
+
if (!update.docChanged) return;
|
|
235
|
+
const next = update.state.doc.toString();
|
|
236
|
+
if (!controlledRef.current) setInner(next);
|
|
237
|
+
onValueChange.current?.(next);
|
|
238
|
+
})
|
|
239
|
+
]
|
|
240
|
+
})
|
|
241
|
+
});
|
|
242
|
+
viewRef.current = view;
|
|
243
|
+
setMounted(true);
|
|
244
|
+
return () => {
|
|
245
|
+
view.destroy();
|
|
246
|
+
viewRef.current = null;
|
|
247
|
+
};
|
|
248
|
+
}, []);
|
|
249
|
+
useEffect(() => {
|
|
250
|
+
viewRef.current?.dispatch({ effects: compartments.current.access.reconfigure(accessExtension()) });
|
|
251
|
+
}, [
|
|
252
|
+
readOnly,
|
|
253
|
+
disabled,
|
|
254
|
+
isInvalid,
|
|
255
|
+
required,
|
|
256
|
+
placeholder$1,
|
|
257
|
+
descriptionId,
|
|
258
|
+
errorId,
|
|
259
|
+
tabIndents,
|
|
260
|
+
id
|
|
261
|
+
]);
|
|
262
|
+
useEffect(() => {
|
|
263
|
+
viewRef.current?.dispatch({ effects: compartments.current.options.reconfigure(optionsExtension()) });
|
|
264
|
+
}, [
|
|
265
|
+
lineNumbers$1,
|
|
266
|
+
wrap,
|
|
267
|
+
tabIndents,
|
|
268
|
+
placeholder$1
|
|
269
|
+
]);
|
|
270
|
+
useEffect(() => {
|
|
271
|
+
viewRef.current?.dispatch({ effects: compartments.current.user.reconfigure([...extensions]) });
|
|
272
|
+
}, [extensions]);
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
const view = viewRef.current;
|
|
275
|
+
if (!view || !controlled) return;
|
|
276
|
+
const current = view.state.doc.toString();
|
|
277
|
+
if (current !== text) view.dispatch({ changes: {
|
|
278
|
+
from: 0,
|
|
279
|
+
to: current.length,
|
|
280
|
+
insert: text
|
|
281
|
+
} });
|
|
282
|
+
}, [controlled, text]);
|
|
283
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
284
|
+
ref,
|
|
285
|
+
className: cx(code_editor_module_default.root, className),
|
|
286
|
+
"data-disabled": dataAttr(disabled),
|
|
287
|
+
"data-readonly": dataAttr(readOnly),
|
|
288
|
+
"data-invalid": dataAttr(isInvalid),
|
|
289
|
+
style: {
|
|
290
|
+
"--_min-h": size(minHeight),
|
|
291
|
+
"--_max-h": size(maxHeight)
|
|
292
|
+
},
|
|
293
|
+
children: [
|
|
294
|
+
hideLabel ? /* @__PURE__ */ jsx(VisuallyHidden, {
|
|
295
|
+
id: labelId,
|
|
296
|
+
children: label
|
|
297
|
+
}) : /* @__PURE__ */ jsx(FormLabel, {
|
|
298
|
+
id: labelId,
|
|
299
|
+
required,
|
|
300
|
+
disabled,
|
|
301
|
+
onClick: () => viewRef.current?.focus(),
|
|
302
|
+
children: label
|
|
303
|
+
}),
|
|
304
|
+
description && /* @__PURE__ */ jsx(FormDescription, {
|
|
305
|
+
id: descriptionId,
|
|
306
|
+
children: description
|
|
307
|
+
}),
|
|
308
|
+
/* @__PURE__ */ jsxs("div", {
|
|
309
|
+
className: code_editor_module_default.frame,
|
|
310
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
311
|
+
ref: hostRef,
|
|
312
|
+
className: code_editor_module_default.host
|
|
313
|
+
}), !mounted && /* @__PURE__ */ jsx("div", {
|
|
314
|
+
className: code_editor_module_default.static,
|
|
315
|
+
role: "textbox",
|
|
316
|
+
"aria-multiline": "true",
|
|
317
|
+
"aria-readonly": "true",
|
|
318
|
+
"aria-labelledby": labelId,
|
|
319
|
+
"data-static": "",
|
|
320
|
+
children: /* @__PURE__ */ jsx("pre", {
|
|
321
|
+
className: code_editor_module_default.staticText,
|
|
322
|
+
children: text
|
|
323
|
+
})
|
|
324
|
+
})]
|
|
325
|
+
}),
|
|
326
|
+
tabIndents && /* @__PURE__ */ jsx(VisuallyHidden, {
|
|
327
|
+
id: hintId,
|
|
328
|
+
children: messages.tabHint
|
|
329
|
+
}),
|
|
330
|
+
error && /* @__PURE__ */ jsx(FormError, {
|
|
331
|
+
id: errorId,
|
|
332
|
+
children: error
|
|
333
|
+
}),
|
|
334
|
+
name && /* @__PURE__ */ jsx("input", {
|
|
335
|
+
type: "hidden",
|
|
336
|
+
name,
|
|
337
|
+
value: text
|
|
338
|
+
})
|
|
339
|
+
]
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
export { CodeEditor };
|
|
343
|
+
|
|
344
|
+
//# sourceMappingURL=code-editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-editor.js","names":["t","placeholder","lineNumbers","lineNumberGutter","placeholderExtension","styles"],"sources":["../src/code-editor.tsx"],"sourcesContent":["'use client';\n\nimport { forwardRef, useEffect, useId, useRef, useState, type ReactNode } from 'react';\nimport { closeBrackets, closeBracketsKeymap } from '@codemirror/autocomplete';\nimport { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands';\nimport { bracketMatching, HighlightStyle, indentOnInput, syntaxHighlighting } from '@codemirror/language';\nimport { tags as t } from '@lezer/highlight';\nimport { highlightSelectionMatches, searchKeymap } from '@codemirror/search';\nimport { Compartment, EditorState, type Extension } from '@codemirror/state';\nimport {\n drawSelection,\n EditorView,\n highlightActiveLine,\n highlightActiveLineGutter,\n keymap,\n lineNumbers as lineNumberGutter,\n placeholder as placeholderExtension,\n} from '@codemirror/view';\nimport { VisuallyHidden } from '@reactloom/primitives';\nimport { FormDescription, FormError, FormLabel } from '@reactloom/ui';\nimport { cx, dataAttr } from '@reactloom/utils';\nimport styles from './code-editor.module.css';\n\nexport interface CodeEditorMessages {\n /** Visually hidden instructions, used when `tabIndents` is on. */\n tabHint: string;\n}\n\nconst defaultMessages: CodeEditorMessages = {\n tabHint: 'Tab indents. Press Escape, then Tab, to leave the editor.',\n};\n\nexport interface CodeEditorProps {\n /** Visible label; it names the editable area. */\n label: ReactNode;\n hideLabel?: boolean;\n description?: ReactNode;\n error?: ReactNode;\n invalid?: boolean;\n required?: boolean;\n disabled?: boolean;\n readOnly?: boolean;\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n /**\n * Language support and other CodeMirror extensions, e.g. `[markdown()]` from\n * `@codemirror/lang-markdown` or `[javascript({ typescript: true })]`. Install the ones you use;\n * the package ships none so it stays small.\n */\n extensions?: readonly Extension[];\n placeholder?: string;\n /** Show line numbers. @default true */\n lineNumbers?: boolean;\n /** Wrap long lines instead of scrolling horizontally. @default false */\n wrap?: boolean;\n /**\n * Tab inserts indentation instead of moving focus. Off by default so keyboard users can leave\n * the field; when on, Escape then Tab leaves it (announced in a hint).\n * @default false\n */\n tabIndents?: boolean;\n /** Submits the text in a hidden input with this name. */\n name?: string;\n /** Minimum height (CSS length or px). @default 160 */\n minHeight?: number | string;\n /** Scroll inside beyond this height (CSS length or px). */\n maxHeight?: number | string;\n messages?: Partial<CodeEditorMessages>;\n className?: string;\n id?: string;\n}\n\nconst size = (v: number | string | undefined) => (typeof v === 'number' ? `${v}px` : v);\n\n/** ReactLoom tokens for CodeMirror's chrome (syntax colours come from your highlight style). */\n/**\n * Syntax colours from the theme's text tokens, which are contrast-checked on surfaces in every\n * theme (CodeMirror's default style is fixed light-theme colours and fails in dark themes).\n */\nconst reactloomHighlight = /*#__PURE__*/ HighlightStyle.define([\n { tag: [t.keyword, t.operatorKeyword, t.modifier, t.controlKeyword, t.moduleKeyword], color: 'var(--pl-color-accent-fg)' },\n { tag: [t.string, t.special(t.string), t.regexp, t.inserted], color: 'var(--pl-color-success-fg)' },\n { tag: [t.number, t.bool, t.null, t.atom, t.unit], color: 'var(--pl-color-warning-fg)' },\n { tag: [t.function(t.variableName), t.function(t.propertyName), t.definition(t.function(t.variableName)), t.macroName], color: 'var(--pl-color-info-fg)' },\n { tag: [t.typeName, t.className, t.namespace, t.tagName, t.deleted, t.invalid], color: 'var(--pl-color-danger-fg)' },\n { tag: [t.attributeName, t.propertyName, t.labelName], color: 'var(--pl-color-info-fg)' },\n { tag: [t.comment, t.lineComment, t.blockComment, t.docComment, t.meta], color: 'var(--pl-color-fg-muted)', fontStyle: 'italic' },\n { tag: t.heading, fontWeight: 'bold', color: 'var(--pl-color-accent-fg)' },\n { tag: t.strong, fontWeight: 'bold' },\n { tag: t.emphasis, fontStyle: 'italic' },\n { tag: t.strikethrough, textDecoration: 'line-through' },\n { tag: t.link, color: 'var(--pl-color-accent-fg)', textDecoration: 'underline' },\n]);\n\nconst reactloomTheme = /*#__PURE__*/ EditorView.theme({\n '&': { color: 'var(--pl-color-fg-default)', backgroundColor: 'transparent', fontSize: 'var(--pl-font-size-sm)' },\n '.cm-content': { fontFamily: 'var(--pl-font-family-mono)', padding: 'var(--pl-space-2) 0', caretColor: 'var(--pl-color-fg-default)' },\n '.cm-gutters': { backgroundColor: 'var(--pl-color-bg-subtle)', color: 'var(--pl-color-fg-subtle)', borderInlineEnd: '1px solid var(--pl-color-border-default)' },\n '.cm-activeLine': { backgroundColor: 'color-mix(in srgb, var(--pl-color-accent-subtle) 45%, transparent)' },\n '.cm-activeLineGutter': { backgroundColor: 'var(--pl-color-bg-muted)', color: 'var(--pl-color-fg-default)' },\n '&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection': { backgroundColor: 'var(--pl-color-accent-subtle)' },\n '.cm-cursor': { borderInlineStartColor: 'var(--pl-color-fg-default)' },\n '.cm-placeholder': { color: 'var(--pl-color-fg-subtle)' },\n '.cm-panels': { backgroundColor: 'var(--pl-color-bg-subtle)', color: 'var(--pl-color-fg-default)' },\n});\n\n/**\n * A labelled field for code and Markdown source on CodeMirror 6. Tab is not captured unless\n * `tabIndents` is on, the text is a plain string, and the server renders it as read-only text in\n * the same box so the page does not shift when the editor loads.\n */\nexport const CodeEditor = /*#__PURE__*/ forwardRef<HTMLDivElement, CodeEditorProps>(function CodeEditor(props, ref) {\n const {\n label,\n hideLabel,\n description,\n error,\n invalid,\n required,\n disabled = false,\n readOnly = false,\n extensions = [],\n placeholder,\n lineNumbers = true,\n wrap = false,\n tabIndents = false,\n name,\n minHeight = 160,\n maxHeight,\n className,\n } = props;\n const messages = { ...defaultMessages, ...props.messages };\n const uid = useId();\n const id = props.id ?? `${uid}-code`;\n const labelId = `${id}-label`;\n const descriptionId = description ? `${id}-description` : undefined;\n const errorId = error ? `${id}-error` : undefined;\n const hintId = `${id}-hint`;\n const isInvalid = Boolean(invalid || error);\n\n const [inner, setInner] = useState(props.defaultValue ?? '');\n const controlled = props.value !== undefined;\n const text = controlled ? (props.value ?? '') : inner;\n\n const hostRef = useRef<HTMLDivElement>(null);\n const viewRef = useRef<EditorView | null>(null);\n const [mounted, setMounted] = useState(false);\n const onValueChange = useRef(props.onValueChange);\n useEffect(() => {\n onValueChange.current = props.onValueChange;\n });\n const controlledRef = useRef(controlled);\n useEffect(() => {\n controlledRef.current = controlled;\n });\n\n // Reconfigurable parts.\n const compartments = useRef({ access: new Compartment(), options: new Compartment(), user: new Compartment() });\n const accessExtension = () =>\n [\n EditorState.readOnly.of(readOnly || disabled),\n EditorView.editable.of(!readOnly && !disabled),\n EditorView.contentAttributes.of({\n id,\n 'aria-labelledby': labelId,\n 'aria-describedby': [descriptionId, errorId, tabIndents ? hintId : undefined].filter(Boolean).join(' '),\n 'aria-invalid': isInvalid ? 'true' : 'false',\n ...(required ? { 'aria-required': 'true' } : {}),\n ...(readOnly ? { 'aria-readonly': 'true' } : {}),\n ...(disabled ? { 'aria-disabled': 'true' } : {}),\n ...(placeholder ? { 'aria-placeholder': placeholder } : {}),\n }),\n ] as Extension;\n const optionsExtension = () =>\n [\n lineNumbers ? [lineNumberGutter(), highlightActiveLineGutter()] : [],\n wrap ? EditorView.lineWrapping : [],\n tabIndents ? keymap.of([indentWithTab]) : [],\n placeholder ? placeholderExtension(placeholder) : [],\n ] as Extension;\n\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n const { access, options, user } = compartments.current;\n const view = new EditorView({\n parent: host,\n state: EditorState.create({\n doc: text,\n extensions: [\n history(),\n drawSelection(),\n indentOnInput(),\n syntaxHighlighting(reactloomHighlight, { fallback: true }),\n bracketMatching(),\n closeBrackets(),\n highlightActiveLine(),\n highlightSelectionMatches(),\n keymap.of([...closeBracketsKeymap, ...defaultKeymap, ...searchKeymap, ...historyKeymap]),\n reactloomTheme,\n access.of(accessExtension()),\n options.of(optionsExtension()),\n user.of([...extensions]),\n EditorView.updateListener.of((update) => {\n if (!update.docChanged) return;\n const next = update.state.doc.toString();\n if (!controlledRef.current) setInner(next);\n onValueChange.current?.(next);\n }),\n ],\n }),\n });\n viewRef.current = view;\n // The editor exists only in the browser; until now the server's text was shown.\n setMounted(true);\n return () => {\n view.destroy();\n viewRef.current = null;\n };\n // Created once; later changes are applied through compartments below.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n viewRef.current?.dispatch({ effects: compartments.current.access.reconfigure(accessExtension()) });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [readOnly, disabled, isInvalid, required, placeholder, descriptionId, errorId, tabIndents, id]);\n useEffect(() => {\n viewRef.current?.dispatch({ effects: compartments.current.options.reconfigure(optionsExtension()) });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [lineNumbers, wrap, tabIndents, placeholder]);\n useEffect(() => {\n viewRef.current?.dispatch({ effects: compartments.current.user.reconfigure([...extensions]) });\n }, [extensions]);\n\n // Outside changes to a controlled value (e.g. a reset) replace the document.\n useEffect(() => {\n const view = viewRef.current;\n if (!view || !controlled) return;\n const current = view.state.doc.toString();\n if (current !== text) view.dispatch({ changes: { from: 0, to: current.length, insert: text } });\n }, [controlled, text]);\n\n return (\n <div\n ref={ref}\n className={cx(styles.root, className)}\n data-disabled={dataAttr(disabled)}\n data-readonly={dataAttr(readOnly)}\n data-invalid={dataAttr(isInvalid)}\n style={{ '--_min-h': size(minHeight), '--_max-h': size(maxHeight) } as React.CSSProperties}\n >\n {hideLabel ? (\n <VisuallyHidden id={labelId}>{label}</VisuallyHidden>\n ) : (\n <FormLabel id={labelId} required={required} disabled={disabled} onClick={() => viewRef.current?.focus()}>\n {label}\n </FormLabel>\n )}\n {description && <FormDescription id={descriptionId}>{description}</FormDescription>}\n <div className={styles.frame}>\n <div ref={hostRef} className={styles.host} />\n {!mounted && (\n // Server and first client render: the text, same box, readable before JavaScript.\n <div className={styles.static} role=\"textbox\" aria-multiline=\"true\" aria-readonly=\"true\" aria-labelledby={labelId} data-static=\"\">\n <pre className={styles.staticText}>{text}</pre>\n </div>\n )}\n </div>\n {tabIndents && <VisuallyHidden id={hintId}>{messages.tabHint}</VisuallyHidden>}\n {error && <FormError id={errorId}>{error}</FormError>}\n {name && <input type=\"hidden\" name={name} value={text} />}\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;AA4BA,IAAM,kBAAsC,EAC1C,SAAS,4DACX;AA2CA,IAAM,QAAQ,MAAoC,OAAO,MAAM,WAAW,GAAG,EAAE,MAAM;;;;;;AAOrF,IAAM,qBAAmC,6BAAe,OAAO;CAC7D;EAAE,KAAK;GAACA,KAAE;GAASA,KAAE;GAAiBA,KAAE;GAAUA,KAAE;GAAgBA,KAAE;EAAa;EAAG,OAAO;CAA4B;CACzH;EAAE,KAAK;GAACA,KAAE;GAAQA,KAAE,QAAQA,KAAE,MAAM;GAAGA,KAAE;GAAQA,KAAE;EAAQ;EAAG,OAAO;CAA6B;CAClG;EAAE,KAAK;GAACA,KAAE;GAAQA,KAAE;GAAMA,KAAE;GAAMA,KAAE;GAAMA,KAAE;EAAI;EAAG,OAAO;CAA6B;CACvF;EAAE,KAAK;GAACA,KAAE,SAASA,KAAE,YAAY;GAAGA,KAAE,SAAS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AEZ,eAAe,oBAAC,iBAAD;IAAiB,IAAI;IAAgB,UAAA;GAA6B,CAAA;GAClF,qBAAC,OAAD;IAAK,WAAWA,2BAAO;IAAvB,UAAA,CACE,oBAAC,OAAD;KAAK,KAAK;KAAS,WAAWA,2BAAO;IAAO,CAAA,GAC3C,CAAC,WAEA,oBAAC,OAAD;KAAK,WAAWA,2BAAO;KAAQ,MAAK;KAAU,kBAAe;KAAO,iBAAc;KAAO,mBAAiB;KAAS,eAAY;KAC7H,UAAA,oBAAC,OAAD;MAAK,WAAWA,2BAAO;MAAa,UAAA;KAAU,CAAA;IAC3C,CAAA,CAEJ;;GACJ,cAAc,oBAAC,gBAAD;IAAgB,IAAI;IAAS,UAAA,SAAS;GAAwB,CAAA;GAC5E,SAAS,oBAAC,WAAD;IAAW,IAAI;IAAU,UAAA;GAAiB,CAAA;GACnD,QAAQ,oBAAC,SAAD;IAAO,MAAK;IAAe;IAAM,OAAO;GAAO,CAAA;EACrD;;AAET,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/code-editor.module.css
|
|
2
|
+
var root = "pl-code-editor-root-RntA1G";
|
|
3
|
+
var frame = "pl-code-editor-frame-RntA1G";
|
|
4
|
+
var host = "pl-code-editor-host-RntA1G";
|
|
5
|
+
var staticText = "pl-code-editor-staticText-RntA1G";
|
|
6
|
+
var code_editor_module_default = {
|
|
7
|
+
root,
|
|
8
|
+
frame,
|
|
9
|
+
host,
|
|
10
|
+
"static": "pl-code-editor-static-RntA1G",
|
|
11
|
+
staticText
|
|
12
|
+
};
|
|
13
|
+
export { code_editor_module_default as default, frame, host, root, staticText };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=code-editor.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-editor.module.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface DiffViewerProps {
|
|
2
|
+
original: string;
|
|
3
|
+
modified: string;
|
|
4
|
+
/** File or comparison title. */
|
|
5
|
+
title?: string;
|
|
6
|
+
/** Display mode. @default 'unified' */
|
|
7
|
+
mode?: 'unified' | 'split';
|
|
8
|
+
/** Accessible label for the diff region. */
|
|
9
|
+
label?: string;
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Line-by-line code and text diff viewer with unified and split modes. */
|
|
13
|
+
export declare function DiffViewer({ original, modified, title, mode: initialMode, label, className, }: DiffViewerProps): import("react").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=diff-viewer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-viewer.d.ts","sourceRoot":"","sources":["../src/diff-viewer.tsx"],"names":[],"mappings":"AAMA,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IAC3B,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAiDD,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,EACzB,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,IAAI,EAAE,WAAuB,EAC7B,KAAmB,EACnB,SAAS,GACV,EAAE,eAAe,+BAoEjB"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx } from "./_internal/utils/cx.js";
|
|
3
|
+
import diff_viewer_module_default from "./diff-viewer.module.js";
|
|
4
|
+
import { useMemo, useState } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/diff-viewer.tsx
|
|
7
|
+
function computeDiff(original, modified) {
|
|
8
|
+
const a = original.split("\n");
|
|
9
|
+
const b = modified.split("\n");
|
|
10
|
+
const m = a.length;
|
|
11
|
+
const n = b.length;
|
|
12
|
+
const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
13
|
+
for (let i = m - 1; i >= 0; i--) {
|
|
14
|
+
const row = dp[i] ?? [];
|
|
15
|
+
const nextRow = dp[i + 1] ?? [];
|
|
16
|
+
for (let j = n - 1; j >= 0; j--) row[j] = a[i] === b[j] ? 1 + (nextRow[j + 1] ?? 0) : Math.max(nextRow[j] ?? 0, row[j + 1] ?? 0);
|
|
17
|
+
}
|
|
18
|
+
const out = [];
|
|
19
|
+
let i = 0;
|
|
20
|
+
let j = 0;
|
|
21
|
+
let oldNum = 1;
|
|
22
|
+
let newNum = 1;
|
|
23
|
+
while (i < m && j < n) {
|
|
24
|
+
const lineA = a[i] ?? "";
|
|
25
|
+
const lineB = b[j] ?? "";
|
|
26
|
+
const down = dp[i + 1]?.[j] ?? 0;
|
|
27
|
+
const right = dp[i]?.[j + 1] ?? 0;
|
|
28
|
+
if (lineA === lineB) {
|
|
29
|
+
out.push({
|
|
30
|
+
type: "same",
|
|
31
|
+
text: lineA,
|
|
32
|
+
oldNum: oldNum++,
|
|
33
|
+
newNum: newNum++
|
|
34
|
+
});
|
|
35
|
+
i++;
|
|
36
|
+
j++;
|
|
37
|
+
} else if (down >= right) {
|
|
38
|
+
out.push({
|
|
39
|
+
type: "remove",
|
|
40
|
+
text: lineA,
|
|
41
|
+
oldNum: oldNum++,
|
|
42
|
+
newNum: null
|
|
43
|
+
});
|
|
44
|
+
i++;
|
|
45
|
+
} else {
|
|
46
|
+
out.push({
|
|
47
|
+
type: "add",
|
|
48
|
+
text: lineB,
|
|
49
|
+
oldNum: null,
|
|
50
|
+
newNum: newNum++
|
|
51
|
+
});
|
|
52
|
+
j++;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
while (i < m) out.push({
|
|
56
|
+
type: "remove",
|
|
57
|
+
text: a[i++] ?? "",
|
|
58
|
+
oldNum: oldNum++,
|
|
59
|
+
newNum: null
|
|
60
|
+
});
|
|
61
|
+
while (j < n) out.push({
|
|
62
|
+
type: "add",
|
|
63
|
+
text: b[j++] ?? "",
|
|
64
|
+
oldNum: null,
|
|
65
|
+
newNum: newNum++
|
|
66
|
+
});
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
/** Line-by-line code and text diff viewer with unified and split modes. */
|
|
70
|
+
function DiffViewer({ original, modified, title, mode: initialMode = "unified", label = "Code diff", className }) {
|
|
71
|
+
const [mode, setMode] = useState(initialMode);
|
|
72
|
+
const lines = useMemo(() => computeDiff(original, modified), [original, modified]);
|
|
73
|
+
const stats = useMemo(() => {
|
|
74
|
+
let added = 0;
|
|
75
|
+
let removed = 0;
|
|
76
|
+
for (const l of lines) if (l.type === "add") added++;
|
|
77
|
+
else if (l.type === "remove") removed++;
|
|
78
|
+
return {
|
|
79
|
+
added,
|
|
80
|
+
removed
|
|
81
|
+
};
|
|
82
|
+
}, [lines]);
|
|
83
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
84
|
+
className: cx(diff_viewer_module_default.root, className),
|
|
85
|
+
"aria-label": label,
|
|
86
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
87
|
+
className: diff_viewer_module_default.header,
|
|
88
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
89
|
+
className: diff_viewer_module_default.meta,
|
|
90
|
+
children: [title && /* @__PURE__ */ jsx("span", {
|
|
91
|
+
className: diff_viewer_module_default.title,
|
|
92
|
+
children: title
|
|
93
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
94
|
+
className: diff_viewer_module_default.stats,
|
|
95
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
96
|
+
className: diff_viewer_module_default.statAdd,
|
|
97
|
+
children: ["+", stats.added]
|
|
98
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
99
|
+
className: diff_viewer_module_default.statRemove,
|
|
100
|
+
children: ["−", stats.removed]
|
|
101
|
+
})]
|
|
102
|
+
})]
|
|
103
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
104
|
+
className: diff_viewer_module_default.modeGroup,
|
|
105
|
+
role: "group",
|
|
106
|
+
"aria-label": "Diff layout",
|
|
107
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
108
|
+
type: "button",
|
|
109
|
+
className: diff_viewer_module_default.modeBtn,
|
|
110
|
+
"aria-pressed": mode === "unified",
|
|
111
|
+
onClick: () => setMode("unified"),
|
|
112
|
+
children: "Unified"
|
|
113
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
114
|
+
type: "button",
|
|
115
|
+
className: diff_viewer_module_default.modeBtn,
|
|
116
|
+
"aria-pressed": mode === "split",
|
|
117
|
+
onClick: () => setMode("split"),
|
|
118
|
+
children: "Split"
|
|
119
|
+
})]
|
|
120
|
+
})]
|
|
121
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
122
|
+
className: diff_viewer_module_default.body,
|
|
123
|
+
children: mode === "unified" ? /* @__PURE__ */ jsx("table", {
|
|
124
|
+
className: diff_viewer_module_default.table,
|
|
125
|
+
children: /* @__PURE__ */ jsx("tbody", { children: lines.map((line, idx) => /* @__PURE__ */ jsxs("tr", {
|
|
126
|
+
"data-diff": line.type,
|
|
127
|
+
className: diff_viewer_module_default.row,
|
|
128
|
+
children: [
|
|
129
|
+
/* @__PURE__ */ jsx("td", {
|
|
130
|
+
className: diff_viewer_module_default.num,
|
|
131
|
+
children: line.oldNum ?? ""
|
|
132
|
+
}),
|
|
133
|
+
/* @__PURE__ */ jsx("td", {
|
|
134
|
+
className: diff_viewer_module_default.num,
|
|
135
|
+
children: line.newNum ?? ""
|
|
136
|
+
}),
|
|
137
|
+
/* @__PURE__ */ jsx("td", {
|
|
138
|
+
className: diff_viewer_module_default.sign,
|
|
139
|
+
"aria-hidden": "true",
|
|
140
|
+
children: line.type === "add" ? "+" : line.type === "remove" ? "−" : " "
|
|
141
|
+
}),
|
|
142
|
+
/* @__PURE__ */ jsx("td", {
|
|
143
|
+
className: diff_viewer_module_default.code,
|
|
144
|
+
children: /* @__PURE__ */ jsx("code", { children: line.text || " " })
|
|
145
|
+
})
|
|
146
|
+
]
|
|
147
|
+
}, idx)) })
|
|
148
|
+
}) : /* @__PURE__ */ jsx("table", {
|
|
149
|
+
className: diff_viewer_module_default.table,
|
|
150
|
+
children: /* @__PURE__ */ jsx("tbody", { children: lines.map((line, idx) => /* @__PURE__ */ jsxs("tr", {
|
|
151
|
+
className: diff_viewer_module_default.row,
|
|
152
|
+
children: [
|
|
153
|
+
/* @__PURE__ */ jsx("td", {
|
|
154
|
+
className: diff_viewer_module_default.num,
|
|
155
|
+
"data-diff": line.type === "remove" ? "remove" : void 0,
|
|
156
|
+
children: line.oldNum ?? ""
|
|
157
|
+
}),
|
|
158
|
+
/* @__PURE__ */ jsx("td", {
|
|
159
|
+
className: diff_viewer_module_default.code,
|
|
160
|
+
"data-diff": line.type === "remove" ? "remove" : void 0,
|
|
161
|
+
children: /* @__PURE__ */ jsx("code", { children: line.type === "add" ? "" : line.text || " " })
|
|
162
|
+
}),
|
|
163
|
+
/* @__PURE__ */ jsx("td", {
|
|
164
|
+
className: diff_viewer_module_default.num,
|
|
165
|
+
"data-diff": line.type === "add" ? "add" : void 0,
|
|
166
|
+
children: line.newNum ?? ""
|
|
167
|
+
}),
|
|
168
|
+
/* @__PURE__ */ jsx("td", {
|
|
169
|
+
className: diff_viewer_module_default.code,
|
|
170
|
+
"data-diff": line.type === "add" ? "add" : void 0,
|
|
171
|
+
children: /* @__PURE__ */ jsx("code", { children: line.type === "remove" ? "" : line.text || " " })
|
|
172
|
+
})
|
|
173
|
+
]
|
|
174
|
+
}, idx)) })
|
|
175
|
+
})
|
|
176
|
+
})]
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
export { DiffViewer };
|
|
180
|
+
|
|
181
|
+
//# sourceMappingURL=diff-viewer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-viewer.js","names":["styles"],"sources":["../src/diff-viewer.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo, useState } from 'react';\nimport { cx } from '@reactloom/utils';\nimport styles from './diff-viewer.module.css';\n\nexport interface DiffViewerProps {\n original: string;\n modified: string;\n /** File or comparison title. */\n title?: string;\n /** Display mode. @default 'unified' */\n mode?: 'unified' | 'split';\n /** Accessible label for the diff region. */\n label?: string;\n className?: string;\n}\n\ninterface DiffLine {\n type: 'same' | 'add' | 'remove';\n text: string;\n oldNum: number | null;\n newNum: number | null;\n}\n\nfunction computeDiff(original: string, modified: string): DiffLine[] {\n const a = original.split('\\n');\n const b = modified.split('\\n');\n const m = a.length;\n const n = b.length;\n const dp: number[][] = Array.from({ length: m + 1 }, () => new Array<number>(n + 1).fill(0));\n for (let i = m - 1; i >= 0; i--) {\n const row = dp[i] ?? [];\n const nextRow = dp[i + 1] ?? [];\n for (let j = n - 1; j >= 0; j--) {\n row[j] = a[i] === b[j] ? 1 + (nextRow[j + 1] ?? 0) : Math.max(nextRow[j] ?? 0, row[j + 1] ?? 0);\n }\n }\n const out: DiffLine[] = [];\n let i = 0;\n let j = 0;\n let oldNum = 1;\n let newNum = 1;\n while (i < m && j < n) {\n const lineA = a[i] ?? '';\n const lineB = b[j] ?? '';\n const down = dp[i + 1]?.[j] ?? 0;\n const right = dp[i]?.[j + 1] ?? 0;\n if (lineA === lineB) {\n out.push({ type: 'same', text: lineA, oldNum: oldNum++, newNum: newNum++ });\n i++;\n j++;\n } else if (down >= right) {\n out.push({ type: 'remove', text: lineA, oldNum: oldNum++, newNum: null });\n i++;\n } else {\n out.push({ type: 'add', text: lineB, oldNum: null, newNum: newNum++ });\n j++;\n }\n }\n while (i < m) out.push({ type: 'remove', text: a[i++] ?? '', oldNum: oldNum++, newNum: null });\n while (j < n) out.push({ type: 'add', text: b[j++] ?? '', oldNum: null, newNum: newNum++ });\n return out;\n}\n\n/** Line-by-line code and text diff viewer with unified and split modes. */\nexport function DiffViewer({\n original,\n modified,\n title,\n mode: initialMode = 'unified',\n label = 'Code diff',\n className,\n}: DiffViewerProps) {\n const [mode, setMode] = useState<'unified' | 'split'>(initialMode);\n const lines = useMemo(() => computeDiff(original, modified), [original, modified]);\n const stats = useMemo(() => {\n let added = 0;\n let removed = 0;\n for (const l of lines) {\n if (l.type === 'add') added++;\n else if (l.type === 'remove') removed++;\n }\n return { added, removed };\n }, [lines]);\n\n return (\n <section className={cx(styles.root, className)} aria-label={label}>\n <div className={styles.header}>\n <div className={styles.meta}>\n {title && <span className={styles.title}>{title}</span>}\n <span className={styles.stats}>\n <span className={styles.statAdd}>+{stats.added}</span>\n <span className={styles.statRemove}>−{stats.removed}</span>\n </span>\n </div>\n <div className={styles.modeGroup} role=\"group\" aria-label=\"Diff layout\">\n <button type=\"button\" className={styles.modeBtn} aria-pressed={mode === 'unified'} onClick={() => setMode('unified')}>\n Unified\n </button>\n <button type=\"button\" className={styles.modeBtn} aria-pressed={mode === 'split'} onClick={() => setMode('split')}>\n Split\n </button>\n </div>\n </div>\n\n <div className={styles.body}>\n {mode === 'unified' ? (\n <table className={styles.table}>\n <tbody>\n {lines.map((line, idx) => (\n <tr key={idx} data-diff={line.type} className={styles.row}>\n <td className={styles.num}>{line.oldNum ?? ''}</td>\n <td className={styles.num}>{line.newNum ?? ''}</td>\n <td className={styles.sign} aria-hidden=\"true\">{line.type === 'add' ? '+' : line.type === 'remove' ? '−' : ' '}</td>\n <td className={styles.code}><code>{line.text || ' '}</code></td>\n </tr>\n ))}\n </tbody>\n </table>\n ) : (\n <table className={styles.table}>\n <tbody>\n {lines.map((line, idx) => (\n <tr key={idx} className={styles.row}>\n <td className={styles.num} data-diff={line.type === 'remove' ? 'remove' : undefined}>{line.oldNum ?? ''}</td>\n <td className={styles.code} data-diff={line.type === 'remove' ? 'remove' : undefined}>\n <code>{line.type === 'add' ? '' : line.text || ' '}</code>\n </td>\n <td className={styles.num} data-diff={line.type === 'add' ? 'add' : undefined}>{line.newNum ?? ''}</td>\n <td className={styles.code} data-diff={line.type === 'add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E,oBAAC,MAAD;OAAI,WAAWA,2BAAO;OAAK,aAAW,KAAK,SAAS,WAAW,WAAW,KAAA;OAAY,UAAA,KAAK,UAAU;MAAO,CAAA;MAC5G,oBAAC,MAAD;OAAI,WAAWA,2BAAO;OAAM,aAAW,KAAK,SAAS,WAAW,WAAW,KAAA;OACzE,UAAA,oBAAC,QAAD,EAAA,UAAO,KAAK,SAAS,QAAQ,KAAK,KAAK,QAAQ,IAAU,CAAA;MACvD,CAAA;MACJ,oBAAC,MAAD;OAAI,WAAWA,2BAAO;OAAK,aAAW,KAAK,SAAS,QAAQ,QAAQ,KAAA;OAAY,UAAA,KAAK,UAAU;MAAO,CAAA;MACtG,oBAAC,MAAD;OAAI,WAAWA,2BAAO;OAAM,aAAW,KAAK,SAAS,QAAQ,QAAQ,KAAA;OACnE,UAAA,oBAAC,QAAD,EAAA,UAAO,KAAK,SAAS,WAAW,KAAK,KAAK,QAAQ,IAAU,CAAA;MAC1D,CAAA;KACF;IATK,GAAA,GASL,CACL,EACI,CAAA;GACF,CAAA;EAEN,CAAA,CACE;;AAEb"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/diff-viewer.module.css
|
|
2
|
+
var root = "pl-diff-viewer-root-mV5yZ3";
|
|
3
|
+
var header = "pl-diff-viewer-header-mV5yZ3";
|
|
4
|
+
var meta = "pl-diff-viewer-meta-mV5yZ3";
|
|
5
|
+
var title = "pl-diff-viewer-title-mV5yZ3";
|
|
6
|
+
var stats = "pl-diff-viewer-stats-mV5yZ3";
|
|
7
|
+
var statAdd = "pl-diff-viewer-statAdd-mV5yZ3";
|
|
8
|
+
var statRemove = "pl-diff-viewer-statRemove-mV5yZ3";
|
|
9
|
+
var modeGroup = "pl-diff-viewer-modeGroup-mV5yZ3";
|
|
10
|
+
var modeBtn = "pl-diff-viewer-modeBtn-mV5yZ3";
|
|
11
|
+
var body = "pl-diff-viewer-body-mV5yZ3";
|
|
12
|
+
var table = "pl-diff-viewer-table-mV5yZ3";
|
|
13
|
+
var num = "pl-diff-viewer-num-mV5yZ3";
|
|
14
|
+
var sign = "pl-diff-viewer-sign-mV5yZ3";
|
|
15
|
+
var code = "pl-diff-viewer-code-mV5yZ3";
|
|
16
|
+
var diff_viewer_module_default = {
|
|
17
|
+
root,
|
|
18
|
+
header,
|
|
19
|
+
meta,
|
|
20
|
+
title,
|
|
21
|
+
stats,
|
|
22
|
+
statAdd,
|
|
23
|
+
statRemove,
|
|
24
|
+
modeGroup,
|
|
25
|
+
modeBtn,
|
|
26
|
+
body,
|
|
27
|
+
table,
|
|
28
|
+
num,
|
|
29
|
+
sign,
|
|
30
|
+
code
|
|
31
|
+
};
|
|
32
|
+
export { body, code, diff_viewer_module_default as default, header, meta, modeBtn, modeGroup, num, root, sign, statAdd, statRemove, stats, table, title };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=diff-viewer.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-viewer.module.js","names":[],"sources":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
package/dist/styles.css
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
@layer pl.theme, pl.components;
|
|
2
|
+
.pl-code-editor-root-RntA1G{gap:var(--pl-space-2);flex-direction:column;min-inline-size:0;display:flex}.pl-code-editor-frame-RntA1G{min-block-size:var(--_min-h);max-block-size:var(--_max-h,none);border:var(--pl-control-border-width,1px) solid var(--pl-color-border-input);border-radius:var(--pl-radius-md);background:var(--pl-color-bg-surface);flex-direction:column;display:flex;position:relative;overflow:hidden}.pl-code-editor-frame-RntA1G:focus-within{border-color:var(--pl-color-border-focus);outline:var(--pl-focus-ring-width) solid var(--pl-focus-ring-color);outline-offset:calc(-1 * var(--pl-control-border-width,1px))}.pl-code-editor-root-RntA1G[data-invalid] .pl-code-editor-frame-RntA1G{border-color:var(--pl-color-danger-border)}.pl-code-editor-root-RntA1G:is([data-disabled],[data-readonly]) .pl-code-editor-frame-RntA1G{background:var(--pl-color-bg-subtle)}.pl-code-editor-root-RntA1G[data-disabled] .pl-code-editor-frame-RntA1G{color:var(--pl-color-fg-disabled)}.pl-code-editor-host-RntA1G{flex:1;min-block-size:0;display:flex}.pl-code-editor-host-RntA1G>.cm-editor{min-block-size:var(--_min-h);max-block-size:var(--_max-h,none);flex:1}.pl-code-editor-host-RntA1G>.cm-editor.cm-focused{outline:none}.pl-code-editor-host-RntA1G .cm-scroller{overflow:auto}.pl-code-editor-static-RntA1G{padding:var(--pl-space-2) var(--pl-space-3);min-block-size:var(--_min-h);font-family:var(--pl-font-family-mono);font-size:var(--pl-font-size-sm);flex:1;margin:0;line-height:1.4;overflow:auto}.pl-code-editor-staticText-RntA1G{font:inherit;white-space:pre;margin:0}@layer pl.components{.pl-diff-viewer-root-mV5yZ3{border:var(--pl-border-width-hairline) solid var(--pl-color-border-default);border-radius:var(--pl-radius-md);background:var(--pl-color-bg-surface);color:var(--pl-color-fg-default);overflow:hidden}.pl-diff-viewer-header-mV5yZ3{justify-content:space-between;align-items:center;gap:var(--pl-space-2);padding:var(--pl-space-2) var(--pl-space-3);border-block-end:var(--pl-border-width-hairline) solid var(--pl-color-border-default);background:var(--pl-color-bg-subtle);display:flex}.pl-diff-viewer-meta-mV5yZ3{align-items:center;gap:var(--pl-space-3);display:inline-flex}.pl-diff-viewer-title-mV5yZ3{font-family:var(--pl-font-family-mono);font-size:var(--pl-font-size-xs);font-weight:var(--pl-font-weight-semibold)}.pl-diff-viewer-stats-mV5yZ3{gap:var(--pl-space-2);font-family:var(--pl-font-family-mono);font-size:var(--pl-font-size-xs);font-weight:var(--pl-font-weight-semibold);display:inline-flex}.pl-diff-viewer-statAdd-mV5yZ3{color:var(--pl-color-success-fg)}.pl-diff-viewer-statRemove-mV5yZ3{color:var(--pl-color-danger-fg)}.pl-diff-viewer-modeGroup-mV5yZ3{gap:var(--pl-space-1);display:inline-flex}.pl-diff-viewer-modeBtn-mV5yZ3{appearance:none;padding:var(--pl-space-1) var(--pl-space-2);border:var(--pl-border-width-hairline) solid var(--pl-color-border-default);border-radius:var(--pl-radius-sm);background:var(--pl-color-bg-surface);color:var(--pl-color-fg-muted);font:inherit;font-size:var(--pl-font-size-xs);cursor:pointer}.pl-diff-viewer-modeBtn-mV5yZ3[aria-pressed=true]{border-color:var(--pl-color-accent-solid);background:var(--pl-color-accent-subtle);color:var(--pl-color-accent-fg);font-weight:var(--pl-font-weight-semibold)}.pl-diff-viewer-modeBtn-mV5yZ3:focus-visible{outline:var(--pl-focus-ring-width) solid var(--pl-focus-ring-color);outline-offset:1px}.pl-diff-viewer-body-mV5yZ3{overflow-x:auto}.pl-diff-viewer-table-mV5yZ3{border-collapse:collapse;width:100%;font-family:var(--pl-font-family-mono);font-size:var(--pl-font-size-xs);line-height:1.55}.pl-diff-viewer-num-mV5yZ3{inline-size:2.5rem;padding:0 var(--pl-space-2);color:var(--pl-color-fg-muted);text-align:end;-webkit-user-select:none;user-select:none;vertical-align:top}.pl-diff-viewer-sign-mV5yZ3{text-align:center;-webkit-user-select:none;user-select:none;inline-size:1.25rem}.pl-diff-viewer-code-mV5yZ3{padding:0 var(--pl-space-2);white-space:pre}[data-diff=add]{background:color-mix(in srgb, var(--pl-color-success-subtle) 65%, transparent)}[data-diff=remove]{background:color-mix(in srgb, var(--pl-color-danger-subtle) 65%, transparent)}}
|
|
3
|
+
/*$vite$:1*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,106 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactloom/code-editor",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Accessible React code editor and diff viewer for ReactLoom on CodeMirror 6: labelled field, ReactLoom theme tokens, Tab not captured by default and server-rendered first paint.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"reactloom",
|
|
8
|
+
"accessible",
|
|
9
|
+
"a11y",
|
|
10
|
+
"wcag",
|
|
11
|
+
"typescript",
|
|
12
|
+
"code-editor",
|
|
13
|
+
"codemirror",
|
|
14
|
+
"diff-viewer",
|
|
15
|
+
"syntax-highlighting",
|
|
16
|
+
"markdown",
|
|
17
|
+
"editor"
|
|
18
|
+
],
|
|
19
|
+
"homepage": "https://www.reactloom.dev/components/code-editor",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://www.reactloom.dev/docs/feedback"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"sideEffects": [
|
|
26
|
+
"**/*.css"
|
|
27
|
+
],
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"@reactloom/source": "./src/index.ts",
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./styles.css": "./dist/styles.css",
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"main": "./dist/index.js",
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@codemirror/autocomplete": "^6.18.0",
|
|
45
|
+
"@codemirror/commands": "^6.8.0",
|
|
46
|
+
"@codemirror/language": "^6.11.0",
|
|
47
|
+
"@lezer/highlight": "^1.2.5",
|
|
48
|
+
"@codemirror/search": "^6.5.0",
|
|
49
|
+
"@codemirror/state": "^6.5.0",
|
|
50
|
+
"@codemirror/view": "^6.38.0"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@reactloom/theme": "^1.0.0",
|
|
54
|
+
"@reactloom/ui": "^1.0.0",
|
|
55
|
+
"react": "^18.2.0 || ^19.0.0",
|
|
56
|
+
"react-dom": "^18.2.0 || ^19.0.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@codemirror/lang-markdown": "^6.5.2",
|
|
60
|
+
"@size-limit/preset-small-lib": "^14.3.0",
|
|
61
|
+
"@storybook/react-vite": "^10.6.8",
|
|
62
|
+
"@testing-library/dom": "^10.4.2",
|
|
63
|
+
"@testing-library/react": "^16.3.3",
|
|
64
|
+
"@testing-library/user-event": "^14.6.12",
|
|
65
|
+
"@types/node": "^22.19.0",
|
|
66
|
+
"@types/react": "^19.3.0",
|
|
67
|
+
"@types/react-dom": "^19.3.0",
|
|
68
|
+
"@vitejs/plugin-react": "^6.3.0",
|
|
69
|
+
"eslint": "^10.15.0",
|
|
70
|
+
"react": "^19.3.1",
|
|
71
|
+
"react-dom": "^19.3.1",
|
|
72
|
+
"size-limit": "^14.3.0",
|
|
73
|
+
"storybook": "^10.6.8",
|
|
74
|
+
"typescript": "~6.0.3",
|
|
75
|
+
"vite": "^8.3.8",
|
|
76
|
+
"vitest": "^5.1.1",
|
|
77
|
+
"@reactloom/eslint-config": "0.0.0",
|
|
78
|
+
"@reactloom/tsconfig": "0.0.0",
|
|
79
|
+
"@reactloom/hooks": "0.0.0",
|
|
80
|
+
"@reactloom/ui": "1.0.1",
|
|
81
|
+
"@reactloom/primitives": "0.0.0",
|
|
82
|
+
"@reactloom/theme": "1.0.1",
|
|
83
|
+
"@reactloom/utils": "0.0.0",
|
|
84
|
+
"@reactloom/testing": "0.0.0"
|
|
85
|
+
},
|
|
86
|
+
"publishConfig": {
|
|
87
|
+
"access": "public"
|
|
88
|
+
},
|
|
89
|
+
"funding": [
|
|
90
|
+
{
|
|
91
|
+
"type": "github",
|
|
92
|
+
"url": "https://github.com/sponsors/Bindhani1995"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"type": "ko_fi",
|
|
96
|
+
"url": "https://ko-fi.com/bindhani1995"
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
"scripts": {
|
|
100
|
+
"build": "vite build && tsc -p tsconfig.build.json",
|
|
101
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
102
|
+
"test": "vitest run",
|
|
103
|
+
"lint": "eslint src",
|
|
104
|
+
"size": "size-limit"
|
|
105
|
+
}
|
|
6
106
|
}
|