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