@gravitee/graphene-core 2.56.0 → 2.57.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,260 @@
1
+ import { n as e, r as t, t as n } from "./Skeleton-DYPFDpYt.js";
2
+ import * as r from "react";
3
+ import { jsx as i } from "react/jsx-runtime";
4
+ import { Editor as a, loader as o } from "@monaco-editor/react";
5
+ //#region src/composed/CodeEditor/setupCodeEditor.ts
6
+ var s = !1;
7
+ function c({ baseUrl: e, monaco: t } = {}) {
8
+ if (!s) {
9
+ if (t !== void 0) {
10
+ o.config({ monaco: t }), s = !0;
11
+ return;
12
+ }
13
+ e !== void 0 && (o.config({ paths: { vs: e.replace(/\/+$/, "") } }), s = !0);
14
+ }
15
+ }
16
+ async function l() {
17
+ if (s) return;
18
+ let e = await import("monaco-editor");
19
+ s ||= (o.config({ monaco: e }), !0);
20
+ }
21
+ function u() {
22
+ return s;
23
+ }
24
+ //#endregion
25
+ //#region src/composed/CodeEditor/theme/buildTheme.ts
26
+ var d = "graphene";
27
+ function f(e) {
28
+ let t = {}, n = [], r = document.createElement("div");
29
+ document.body.appendChild(r);
30
+ let i = getComputedStyle(r), a = document.createElement("canvas");
31
+ a.width = 1, a.height = 1;
32
+ let o = a.getContext("2d");
33
+ for (let a of e) {
34
+ if (!o) {
35
+ t[a] = "#000000";
36
+ continue;
37
+ }
38
+ r.style.backgroundColor = `var(${a})`;
39
+ let e = i.backgroundColor;
40
+ (e === "" || e === "rgba(0, 0, 0, 0)") && n.push(a), o.clearRect(0, 0, 1, 1), o.fillStyle = e, o.fillRect(0, 0, 1, 1);
41
+ let [s, c, l] = o.getImageData(0, 0, 1, 1).data;
42
+ t[a] = "#" + [
43
+ s,
44
+ c,
45
+ l
46
+ ].map((e) => e.toString(16).padStart(2, "0")).join("");
47
+ }
48
+ return document.body.removeChild(r), t;
49
+ }
50
+ function p() {
51
+ let e = document.documentElement.classList.contains("dark"), t = f([
52
+ "--background",
53
+ "--foreground",
54
+ "--border",
55
+ "--muted",
56
+ "--muted-foreground",
57
+ "--primary",
58
+ "--code-editor-string",
59
+ "--code-editor-keyword",
60
+ "--code-editor-number",
61
+ "--code-editor-type",
62
+ "--code-editor-special"
63
+ ]), n = t["--background"], r = t["--foreground"], i = t["--border"], a = t["--muted"], o = t["--muted-foreground"], s = t["--primary"], c = t["--code-editor-string"], l = t["--code-editor-keyword"], u = t["--code-editor-number"], d = t["--code-editor-type"], p = t["--code-editor-special"], m = (e) => e.slice(1);
64
+ return {
65
+ base: e ? "vs-dark" : "vs",
66
+ inherit: !0,
67
+ rules: [
68
+ {
69
+ token: "string",
70
+ foreground: m(c)
71
+ },
72
+ {
73
+ token: "string.key.json",
74
+ foreground: m(d)
75
+ },
76
+ {
77
+ token: "keyword",
78
+ foreground: m(l)
79
+ },
80
+ {
81
+ token: "keyword.json",
82
+ foreground: m(p)
83
+ },
84
+ {
85
+ token: "number",
86
+ foreground: m(u)
87
+ },
88
+ {
89
+ token: "type",
90
+ foreground: m(d)
91
+ },
92
+ {
93
+ token: "tag",
94
+ foreground: m(l)
95
+ },
96
+ {
97
+ token: "attribute.name",
98
+ foreground: m(d)
99
+ },
100
+ {
101
+ token: "attribute.value",
102
+ foreground: m(c)
103
+ },
104
+ {
105
+ token: "comment",
106
+ foreground: m(o),
107
+ fontStyle: "italic"
108
+ },
109
+ {
110
+ token: "comment.line",
111
+ foreground: m(o),
112
+ fontStyle: "italic"
113
+ },
114
+ {
115
+ token: "comment.block",
116
+ foreground: m(o),
117
+ fontStyle: "italic"
118
+ },
119
+ {
120
+ token: "identifier",
121
+ foreground: m(r)
122
+ },
123
+ {
124
+ token: "variable",
125
+ foreground: m(r)
126
+ },
127
+ {
128
+ token: "delimiter",
129
+ foreground: m(r)
130
+ }
131
+ ],
132
+ colors: {
133
+ "editor.background": n,
134
+ "editor.foreground": r,
135
+ "editor.lineHighlightBackground": r + "08",
136
+ "editor.lineHighlightBorder": "#00000000",
137
+ "editor.selectionBackground": s + "4d",
138
+ "editor.inactiveSelectionBackground": s + "26",
139
+ "editorCursor.foreground": s,
140
+ "editorLineNumber.foreground": o,
141
+ "editorLineNumber.activeForeground": r,
142
+ "editorGutter.background": n,
143
+ "editorIndentGuide.background1": i,
144
+ "editorIndentGuide.activeBackground1": o,
145
+ "editorWidget.background": a,
146
+ "editorWidget.foreground": r,
147
+ "editorWidget.border": i,
148
+ "editorWidget.resizeBorder": i,
149
+ "widget.shadow": r + "1a",
150
+ "input.background": n,
151
+ "input.border": i,
152
+ "input.foreground": r,
153
+ "input.placeholderForeground": o,
154
+ "inputOption.activeBorder": s,
155
+ "inputOption.activeBackground": s + "26",
156
+ "inputOption.activeForeground": s,
157
+ "button.background": s,
158
+ "button.foreground": "#ffffff",
159
+ "editorSuggestWidget.background": n,
160
+ "editorSuggestWidget.border": i,
161
+ "editorSuggestWidget.selectedBackground": s + "26",
162
+ "scrollbarSlider.background": i + "80",
163
+ "scrollbarSlider.hoverBackground": i,
164
+ "scrollbarSlider.activeBackground": o + "80"
165
+ }
166
+ };
167
+ }
168
+ //#endregion
169
+ //#region src/composed/CodeEditor/CodeEditor.tsx
170
+ function m(e) {
171
+ e.editor.defineTheme(d, p()), e.editor.setTheme(d);
172
+ }
173
+ var h = (e) => {
174
+ m(e);
175
+ };
176
+ function g() {
177
+ let [e, t] = r.useState(typeof document < "u" && document.documentElement.classList.contains("dark"));
178
+ return r.useEffect(() => {
179
+ let e = new MutationObserver(() => {
180
+ t(document.documentElement.classList.contains("dark"));
181
+ });
182
+ return e.observe(document.documentElement, {
183
+ attributes: !0,
184
+ attributeFilter: ["class"]
185
+ }), () => e.disconnect();
186
+ }, []), e;
187
+ }
188
+ function _({ value: o, defaultValue: s, onChange: c, language: f = "plaintext", readOnly: p = !1, disabled: _ = !1, height: v, className: y, options: b, onMount: x }) {
189
+ let [S, C] = r.useState(() => u() ? { status: "ready" } : { status: "loading" });
190
+ r.useEffect(() => {
191
+ if (S.status !== "loading") return;
192
+ let e = !1;
193
+ return l().then(() => {
194
+ e || C({ status: "ready" });
195
+ }, (t) => {
196
+ if (e) return;
197
+ let n = t instanceof Error ? t.message : "Unknown error";
198
+ console.error("[CodeEditor] Failed to configure Monaco loader:", t), C({
199
+ status: "error",
200
+ message: n
201
+ });
202
+ }), () => {
203
+ e = !0;
204
+ };
205
+ }, [S.status]);
206
+ let w = g(), T = r.useRef(null), E = r.useRef(null);
207
+ r.useEffect(() => {
208
+ T.current && m(T.current);
209
+ }, [w]);
210
+ let D = r.useCallback((e, t) => {
211
+ T.current = t, E.current = e, x?.(e, t);
212
+ }, [x]), O = typeof v == "number" ? `${v}px` : v ?? "300px", k = /* @__PURE__ */ i(n, { className: "size-full" });
213
+ return /* @__PURE__ */ i("div", {
214
+ "data-slot": "code-editor",
215
+ "data-disabled": _ ? "" : void 0,
216
+ "data-readonly": p && !_ ? "" : void 0,
217
+ className: t("overflow-hidden rounded-lg border border-input bg-background", "data-disabled:pointer-events-none data-disabled:opacity-50", "data-readonly:bg-muted/30", y),
218
+ style: { height: O },
219
+ children: S.status === "error" ? /* @__PURE__ */ i(e, {
220
+ value: o ?? "",
221
+ onChange: (e) => c?.(e.target.value),
222
+ readOnly: p || _,
223
+ spellCheck: !1,
224
+ className: "size-full resize-none rounded-none border-0 p-3 font-mono text-xs focus-visible:ring-0"
225
+ }) : S.status === "ready" ? /* @__PURE__ */ i(a, {
226
+ height: "100%",
227
+ language: f,
228
+ value: o,
229
+ defaultValue: s,
230
+ theme: d,
231
+ onChange: c,
232
+ onMount: D,
233
+ beforeMount: h,
234
+ loading: k,
235
+ options: {
236
+ readOnly: p || _,
237
+ minimap: { enabled: !1 },
238
+ scrollBeyondLastLine: !1,
239
+ automaticLayout: !0,
240
+ fontFamily: "ui-monospace, Menlo, Consolas, \"Cascadia Code\", \"Liberation Mono\", monospace",
241
+ fontSize: 13,
242
+ lineHeight: 20,
243
+ padding: {
244
+ top: 8,
245
+ bottom: 8
246
+ },
247
+ glyphMargin: !1,
248
+ renderLineHighlight: "line",
249
+ scrollbar: {
250
+ verticalScrollbarSize: 6,
251
+ horizontalScrollbarSize: 6
252
+ },
253
+ overviewRulerLanes: 0,
254
+ ...b
255
+ }
256
+ }) : k
257
+ });
258
+ }
259
+ //#endregion
260
+ export { c as n, _ as t };
@@ -0,0 +1,52 @@
1
+ import { f as e, h as t, i as n, o as r, p as i, r as a, s as o, t as s, u as c } from "./SchemaBanner-lrLehIB4.js";
2
+ import { t as l } from "./CodeEditor-izUXIn0I.js";
3
+ import { useEffect as u, useRef as d, useState as f } from "react";
4
+ import { jsx as p, jsxs as m } from "react/jsx-runtime";
5
+ //#region src/composed/JsonSchemaForm/fields/code-editor/CodeEditorField.tsx
6
+ var h = 250;
7
+ function g(e) {
8
+ if (typeof e != "string" || e.trim() === "") return !1;
9
+ try {
10
+ return JSON.parse(e), !0;
11
+ } catch {
12
+ return !1;
13
+ }
14
+ }
15
+ function _({ node: _, name: v }) {
16
+ let { control: y, basePath: b, disabled: x } = r(), { schema: S } = _, C = v ? b ? `${b}.${v}` : v : b, { field: w, fieldState: T } = o({
17
+ control: y,
18
+ name: C
19
+ }), E = a(S, v), D = T.invalid, O = typeof w.value == "string" ? w.value : "", [k] = f(() => O), A = S.gioConfig?.monacoEditorConfig?.language ?? (g(k) ? "json" : "plaintext"), j = d(w.onBlur);
20
+ u(() => {
21
+ j.current = w.onBlur;
22
+ });
23
+ let M = d(null);
24
+ return u(() => () => {
25
+ M.current?.dispose(), M.current = null;
26
+ }, []), /* @__PURE__ */ m(c, {
27
+ "data-invalid": D,
28
+ children: [
29
+ /* @__PURE__ */ p(t, {
30
+ htmlFor: C,
31
+ required: S.isRequired,
32
+ children: E
33
+ }),
34
+ S.gioConfig?.banner && /* @__PURE__ */ p(s, { banner: S.gioConfig.banner }),
35
+ /* @__PURE__ */ p(l, {
36
+ value: O,
37
+ language: A,
38
+ height: S.gioConfig?.monacoEditorConfig?.height ?? h,
39
+ onChange: (e) => w.onChange(e ?? ""),
40
+ readOnly: S.readOnly === !0,
41
+ disabled: x,
42
+ onMount: (e) => {
43
+ M.current?.dispose(), M.current = e.onDidBlurEditorText(() => j.current());
44
+ }
45
+ }),
46
+ S.description && /* @__PURE__ */ p(e, { children: S.description }),
47
+ /* @__PURE__ */ p(i, { errors: n(T.error) })
48
+ ]
49
+ });
50
+ }
51
+ //#endregion
52
+ export { _ as CodeEditorField };