@dovetail-v2/refine 0.2.2-alpha.0 → 0.2.3-alpha.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.
@@ -1,6 +1,7 @@
1
- import { j as jsxRuntimeExports } from "./index-d00a6dbe.js";
1
+ import { j as jsxRuntimeExports } from "./index-49e0db41.js";
2
2
  import * as monaco from "monaco-editor";
3
3
  import { useRef, useEffect } from "react";
4
+ import "dayjs";
4
5
  import "i18next";
5
6
  import "@refinedev/core";
6
7
  import "qs";
@@ -9,9 +10,18 @@ import "@cloudtower/eagle";
9
10
  import "@cloudtower/icons-react";
10
11
  import "lodash-es";
11
12
  import "js-yaml";
13
+ import "usehooks-ts";
12
14
  import "k8s-api-provider";
13
- import "monaco-yaml";
14
- import "react-dom";
15
+ import "@patternfly/react-log-viewer";
16
+ import "@xterm/addon-canvas";
17
+ import "@xterm/addon-fit";
18
+ import "@xterm/addon-search";
19
+ import "@xterm/addon-web-links";
20
+ import "@xterm/addon-webgl";
21
+ import "@xterm/xterm";
22
+ import "copy-to-clipboard";
23
+ import "buffer";
24
+ import "react-hook-form";
15
25
  import "sunflower-antd";
16
26
  import "antd";
17
27
  const MonacoYamlDiffEditor = (props) => {
@@ -0,0 +1,196 @@
1
+ import { j as jsxRuntimeExports, c as cx_default, Y as YamlEditorStyle } from "./index-49e0db41.js";
2
+ import * as monaco from "monaco-editor";
3
+ import { setDiagnosticsOptions } from "monaco-yaml";
4
+ import { useRef, useEffect } from "react";
5
+ import ReactDOM from "react-dom";
6
+ import "dayjs";
7
+ import "i18next";
8
+ import "@refinedev/core";
9
+ import "qs";
10
+ import "react-router-dom";
11
+ import "@cloudtower/eagle";
12
+ import "@cloudtower/icons-react";
13
+ import "lodash-es";
14
+ import "js-yaml";
15
+ import "usehooks-ts";
16
+ import "k8s-api-provider";
17
+ import "@patternfly/react-log-viewer";
18
+ import "@xterm/addon-canvas";
19
+ import "@xterm/addon-fit";
20
+ import "@xterm/addon-search";
21
+ import "@xterm/addon-web-links";
22
+ import "@xterm/addon-webgl";
23
+ import "@xterm/xterm";
24
+ import "copy-to-clipboard";
25
+ import "buffer";
26
+ import "react-hook-form";
27
+ import "sunflower-antd";
28
+ import "antd";
29
+ const MonacoYamlEditor = (props) => {
30
+ const ref = useRef(null);
31
+ const instanceRef = useRef({
32
+ editor: null
33
+ });
34
+ const {
35
+ defaultValue,
36
+ id,
37
+ height,
38
+ readOnly,
39
+ schemas,
40
+ isScrollOnFocus,
41
+ onChange,
42
+ onValidate,
43
+ getInstance,
44
+ onEditorCreate,
45
+ onBlur
46
+ } = props;
47
+ const uri = id ? monaco.Uri.parse(`${id}.yaml`) : void 0;
48
+ useEffect(() => {
49
+ if (!window._MonacoSchemaMap) {
50
+ window._MonacoSchemaMap = /* @__PURE__ */ new Map();
51
+ }
52
+ window._MonacoSchemaMap.set(id || "", {
53
+ // Id of the first schema
54
+ uri: String(uri),
55
+ // Associate with our model
56
+ fileMatch: [String(uri)],
57
+ schema: {
58
+ oneOf: schemas || [{ type: "object" }]
59
+ }
60
+ });
61
+ const finalSchemas = [...window._MonacoSchemaMap.values()];
62
+ setDiagnosticsOptions({
63
+ enableSchemaRequest: false,
64
+ validate: true,
65
+ format: true,
66
+ isKubernetes: true,
67
+ schemas: finalSchemas
68
+ });
69
+ const model = monaco.editor.createModel(defaultValue, "yaml", uri);
70
+ const editor = monaco.editor.create(ref.current, {
71
+ automaticLayout: true,
72
+ scrollBeyondLastLine: false,
73
+ model,
74
+ scrollbar: {
75
+ handleMouseWheel: !isScrollOnFocus,
76
+ alwaysConsumeMouseWheel: false
77
+ // https://github.com/microsoft/monaco-editor/issues/2007
78
+ },
79
+ tabSize: 2,
80
+ lineNumbersMinChars: 7,
81
+ readOnly,
82
+ autoIndent: {}.VITE_IS_TEST ? "none" : "advanced",
83
+ theme: "vs"
84
+ });
85
+ instanceRef.current.editor = editor;
86
+ getInstance == null ? void 0 : getInstance(editor);
87
+ onEditorCreate == null ? void 0 : onEditorCreate(editor);
88
+ return () => {
89
+ instanceRef.current.editor = null;
90
+ window._MonacoSchemaMap.delete(id || "");
91
+ model.dispose();
92
+ editor.dispose();
93
+ };
94
+ }, [id, schemas, readOnly, isScrollOnFocus, getInstance]);
95
+ useEffect(() => {
96
+ const editor = instanceRef.current.editor;
97
+ if (editor) {
98
+ const stop = editor.onDidChangeModelContent(() => {
99
+ ReactDOM.unstable_batchedUpdates(() => {
100
+ onChange == null ? void 0 : onChange(editor.getValue());
101
+ });
102
+ });
103
+ return () => {
104
+ stop.dispose();
105
+ };
106
+ }
107
+ }, [onChange]);
108
+ useEffect(() => {
109
+ const editor = instanceRef.current.editor;
110
+ if (editor) {
111
+ const stop = monaco.editor.onDidChangeMarkers((uri2) => {
112
+ var _a;
113
+ const model = (_a = instanceRef.current.editor) == null ? void 0 : _a.getModel();
114
+ const currentEditorUri = model == null ? void 0 : model.uri;
115
+ if (model && uri2.toString() === (currentEditorUri == null ? void 0 : currentEditorUri.toString())) {
116
+ const marks = monaco.editor.getModelMarkers({
117
+ owner: "yaml",
118
+ resource: currentEditorUri
119
+ });
120
+ const yamlMarks = marks.filter((m) => m.source === "YAML");
121
+ const schemaMarks = marks.filter((m) => m.source !== "YAML");
122
+ const yamlValid = yamlMarks.length === 0;
123
+ const schemaValid = schemaMarks.length === 0;
124
+ onValidate == null ? void 0 : onValidate(yamlValid, schemaValid);
125
+ if (marks.some((mark) => {
126
+ var _a2;
127
+ return (_a2 = mark.source) == null ? void 0 : _a2.includes("yaml-schema");
128
+ })) {
129
+ monaco.editor.setModelMarkers(
130
+ model,
131
+ "yaml",
132
+ marks.map((mark) => ({ ...mark, source: "", resource: {} }))
133
+ );
134
+ }
135
+ }
136
+ });
137
+ return () => {
138
+ stop.dispose();
139
+ };
140
+ }
141
+ }, [onValidate]);
142
+ useEffect(() => {
143
+ const editor = instanceRef.current.editor;
144
+ if (editor) {
145
+ const stop = editor.onDidBlurEditorWidget(() => {
146
+ ReactDOM.unstable_batchedUpdates(() => {
147
+ onBlur == null ? void 0 : onBlur();
148
+ });
149
+ });
150
+ return () => {
151
+ stop.dispose();
152
+ };
153
+ }
154
+ }, [onBlur]);
155
+ useEffect(() => {
156
+ const editor = instanceRef.current.editor;
157
+ const stops = [];
158
+ if (editor && isScrollOnFocus) {
159
+ stops.push(
160
+ editor.onDidFocusEditorWidget(() => {
161
+ editor.updateOptions({
162
+ scrollbar: {
163
+ handleMouseWheel: true
164
+ }
165
+ });
166
+ })
167
+ );
168
+ stops.push(
169
+ editor.onDidBlurEditorWidget(() => {
170
+ editor.updateOptions({
171
+ scrollbar: {
172
+ handleMouseWheel: false
173
+ }
174
+ });
175
+ })
176
+ );
177
+ }
178
+ return () => {
179
+ stops.forEach((stop) => stop.dispose());
180
+ };
181
+ }, [isScrollOnFocus]);
182
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
183
+ "div",
184
+ {
185
+ ref,
186
+ className: cx_default(YamlEditorStyle, props.className),
187
+ style: {
188
+ width: "100%",
189
+ height: height || "500px"
190
+ }
191
+ }
192
+ );
193
+ };
194
+ export {
195
+ MonacoYamlEditor as default
196
+ };