@willbooster/monaco-react 1.0.3 → 1.0.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/README.md +4 -3
- package/dist/DiffEditor/DiffEditor.cjs +3 -0
- package/dist/DiffEditor/DiffEditor.cjs.map +1 -0
- package/dist/DiffEditor/DiffEditor.d.ts +5 -0
- package/dist/DiffEditor/DiffEditor.d.ts.map +1 -0
- package/dist/DiffEditor/DiffEditor.js +3 -0
- package/dist/DiffEditor/DiffEditor.js.map +1 -0
- package/dist/DiffEditor/index.cjs +2 -0
- package/dist/DiffEditor/index.cjs.map +1 -0
- package/dist/DiffEditor/index.d.ts +5 -0
- package/dist/DiffEditor/index.d.ts.map +1 -0
- package/dist/DiffEditor/index.js +2 -0
- package/dist/DiffEditor/index.js.map +1 -0
- package/dist/DiffEditor/index.spec.d.ts +2 -0
- package/dist/DiffEditor/index.spec.d.ts.map +1 -0
- package/dist/DiffEditor/types.d.ts +101 -0
- package/dist/DiffEditor/types.d.ts.map +1 -0
- package/dist/Editor/Editor.cjs +3 -0
- package/dist/Editor/Editor.cjs.map +1 -0
- package/dist/Editor/Editor.d.ts +5 -0
- package/dist/Editor/Editor.d.ts.map +1 -0
- package/dist/Editor/Editor.js +3 -0
- package/dist/Editor/Editor.js.map +1 -0
- package/dist/Editor/index.cjs +2 -0
- package/dist/Editor/index.cjs.map +1 -0
- package/dist/Editor/index.d.ts +5 -0
- package/dist/Editor/index.d.ts.map +1 -0
- package/dist/Editor/index.js +2 -0
- package/dist/Editor/index.js.map +1 -0
- package/dist/Editor/index.spec.d.ts +2 -0
- package/dist/Editor/index.spec.d.ts.map +1 -0
- package/dist/Editor/types.d.ts +116 -0
- package/dist/Editor/types.d.ts.map +1 -0
- package/dist/Loading/Loading.cjs +2 -0
- package/dist/Loading/Loading.cjs.map +1 -0
- package/dist/Loading/Loading.d.ts +4 -0
- package/dist/Loading/Loading.d.ts.map +1 -0
- package/dist/Loading/Loading.js +2 -0
- package/dist/Loading/Loading.js.map +1 -0
- package/dist/Loading/index.cjs +2 -0
- package/dist/Loading/index.cjs.map +1 -0
- package/dist/Loading/index.d.ts +3 -0
- package/dist/Loading/index.d.ts.map +1 -0
- package/dist/Loading/index.js +2 -0
- package/dist/Loading/index.js.map +1 -0
- package/dist/Loading/index.spec.d.ts +2 -0
- package/dist/Loading/index.spec.d.ts.map +1 -0
- package/dist/Loading/styles.cjs +2 -0
- package/dist/Loading/styles.cjs.map +1 -0
- package/dist/Loading/styles.d.ts +4 -0
- package/dist/Loading/styles.d.ts.map +1 -0
- package/dist/Loading/styles.js +2 -0
- package/dist/Loading/styles.js.map +1 -0
- package/dist/MonacoContainer/MonacoContainer.cjs +2 -0
- package/dist/MonacoContainer/MonacoContainer.cjs.map +1 -0
- package/dist/MonacoContainer/MonacoContainer.d.ts +5 -0
- package/dist/MonacoContainer/MonacoContainer.d.ts.map +1 -0
- package/dist/MonacoContainer/MonacoContainer.js +2 -0
- package/dist/MonacoContainer/MonacoContainer.js.map +1 -0
- package/dist/MonacoContainer/index.cjs +2 -0
- package/dist/MonacoContainer/index.cjs.map +1 -0
- package/dist/MonacoContainer/index.d.ts +4 -0
- package/dist/MonacoContainer/index.d.ts.map +1 -0
- package/dist/MonacoContainer/index.js +2 -0
- package/dist/MonacoContainer/index.js.map +1 -0
- package/dist/MonacoContainer/index.spec.d.ts +2 -0
- package/dist/MonacoContainer/index.spec.d.ts.map +1 -0
- package/dist/MonacoContainer/styles.cjs +2 -0
- package/dist/MonacoContainer/styles.cjs.map +1 -0
- package/dist/MonacoContainer/styles.d.ts +4 -0
- package/dist/MonacoContainer/styles.d.ts.map +1 -0
- package/dist/MonacoContainer/styles.js +2 -0
- package/dist/MonacoContainer/styles.js.map +1 -0
- package/dist/MonacoContainer/types.d.ts +11 -0
- package/dist/MonacoContainer/types.d.ts.map +1 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.cjs +2 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.cjs.map +1 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.js +2 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
- package/dist/hooks/useMonaco/index.cjs +2 -0
- package/dist/hooks/useMonaco/index.cjs.map +1 -0
- package/dist/hooks/useMonaco/index.d.ts +4 -0
- package/dist/hooks/useMonaco/index.d.ts.map +1 -0
- package/dist/hooks/useMonaco/index.js +2 -0
- package/dist/hooks/useMonaco/index.js.map +1 -0
- package/dist/hooks/useMount/index.cjs +2 -0
- package/dist/hooks/useMount/index.cjs.map +1 -0
- package/dist/hooks/useMount/index.d.ts +4 -0
- package/dist/hooks/useMount/index.d.ts.map +1 -0
- package/dist/hooks/useMount/index.js +2 -0
- package/dist/hooks/useMount/index.js.map +1 -0
- package/dist/hooks/usePrevious/index.cjs +2 -0
- package/dist/hooks/usePrevious/index.cjs.map +1 -0
- package/dist/hooks/usePrevious/index.d.ts +3 -0
- package/dist/hooks/usePrevious/index.d.ts.map +1 -0
- package/dist/hooks/usePrevious/index.js +2 -0
- package/dist/hooks/usePrevious/index.js.map +1 -0
- package/dist/hooks/useUpdate/index.cjs +2 -0
- package/dist/hooks/useUpdate/index.cjs.map +1 -0
- package/dist/hooks/useUpdate/index.d.ts +4 -0
- package/dist/hooks/useUpdate/index.d.ts.map +1 -0
- package/dist/hooks/useUpdate/index.js +2 -0
- package/dist/hooks/useUpdate/index.js.map +1 -0
- package/dist/index.cjs +3 -625
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -231
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -588
- package/dist/index.js.map +1 -1
- package/dist/utils/index.cjs +2 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.ts +20 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +9 -14
- package/dist/index.d.cts +0 -231
package/dist/index.cjs
CHANGED
|
@@ -1,625 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
|
|
31
|
-
// src/index.ts
|
|
32
|
-
var index_exports = {};
|
|
33
|
-
__export(index_exports, {
|
|
34
|
-
DiffEditor: () => DiffEditor_default2,
|
|
35
|
-
Editor: () => Editor_default2,
|
|
36
|
-
default: () => index_default,
|
|
37
|
-
loader: () => import_monaco_loader4.default,
|
|
38
|
-
useMonaco: () => useMonaco_default
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(index_exports);
|
|
41
|
-
var import_monaco_loader4 = __toESM(require("@willbooster/monaco-loader"), 1);
|
|
42
|
-
|
|
43
|
-
// src/DiffEditor/index.ts
|
|
44
|
-
var import_react5 = require("react");
|
|
45
|
-
|
|
46
|
-
// src/DiffEditor/DiffEditor.tsx
|
|
47
|
-
var import_react4 = require("react");
|
|
48
|
-
var import_monaco_loader = __toESM(require("@willbooster/monaco-loader"), 1);
|
|
49
|
-
|
|
50
|
-
// src/MonacoContainer/index.ts
|
|
51
|
-
var import_react = require("react");
|
|
52
|
-
|
|
53
|
-
// src/MonacoContainer/styles.ts
|
|
54
|
-
var styles = {
|
|
55
|
-
wrapper: {
|
|
56
|
-
display: "flex",
|
|
57
|
-
position: "relative",
|
|
58
|
-
textAlign: "initial"
|
|
59
|
-
},
|
|
60
|
-
fullWidth: {
|
|
61
|
-
width: "100%"
|
|
62
|
-
},
|
|
63
|
-
hide: {
|
|
64
|
-
display: "none"
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
var styles_default = styles;
|
|
68
|
-
|
|
69
|
-
// src/Loading/styles.ts
|
|
70
|
-
var styles2 = {
|
|
71
|
-
container: {
|
|
72
|
-
display: "flex",
|
|
73
|
-
height: "100%",
|
|
74
|
-
width: "100%",
|
|
75
|
-
justifyContent: "center",
|
|
76
|
-
alignItems: "center"
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
var styles_default2 = styles2;
|
|
80
|
-
|
|
81
|
-
// src/Loading/Loading.tsx
|
|
82
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
83
|
-
function Loading({ children }) {
|
|
84
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: styles_default2.container, children });
|
|
85
|
-
}
|
|
86
|
-
var Loading_default = Loading;
|
|
87
|
-
|
|
88
|
-
// src/Loading/index.ts
|
|
89
|
-
var Loading_default2 = Loading_default;
|
|
90
|
-
|
|
91
|
-
// src/MonacoContainer/MonacoContainer.tsx
|
|
92
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
93
|
-
function MonacoContainer({
|
|
94
|
-
width,
|
|
95
|
-
height,
|
|
96
|
-
isEditorReady,
|
|
97
|
-
loading,
|
|
98
|
-
_ref,
|
|
99
|
-
className,
|
|
100
|
-
wrapperProps
|
|
101
|
-
}) {
|
|
102
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("section", { style: { ...styles_default.wrapper, width, height }, ...wrapperProps, children: [
|
|
103
|
-
!isEditorReady && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Loading_default2, { children: loading }),
|
|
104
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: _ref, style: { ...styles_default.fullWidth, ...!isEditorReady && styles_default.hide }, className })
|
|
105
|
-
] });
|
|
106
|
-
}
|
|
107
|
-
var MonacoContainer_default = MonacoContainer;
|
|
108
|
-
|
|
109
|
-
// src/MonacoContainer/index.ts
|
|
110
|
-
var MonacoContainer_default2 = (0, import_react.memo)(MonacoContainer_default);
|
|
111
|
-
|
|
112
|
-
// src/hooks/useMount/index.ts
|
|
113
|
-
var import_react2 = require("react");
|
|
114
|
-
function useMount(effect) {
|
|
115
|
-
(0, import_react2.useEffect)(effect, []);
|
|
116
|
-
}
|
|
117
|
-
var useMount_default = useMount;
|
|
118
|
-
|
|
119
|
-
// src/hooks/useUpdate/index.ts
|
|
120
|
-
var import_react3 = require("react");
|
|
121
|
-
function useUpdate(effect, deps, applyChanges = true) {
|
|
122
|
-
const isInitialMount = (0, import_react3.useRef)(true);
|
|
123
|
-
(0, import_react3.useEffect)(
|
|
124
|
-
isInitialMount.current || !applyChanges ? () => {
|
|
125
|
-
isInitialMount.current = false;
|
|
126
|
-
} : effect,
|
|
127
|
-
deps
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
var useUpdate_default = useUpdate;
|
|
131
|
-
|
|
132
|
-
// src/utils/index.ts
|
|
133
|
-
function noop() {
|
|
134
|
-
}
|
|
135
|
-
function getOrCreateModel(monaco, value, language, path) {
|
|
136
|
-
return getModel(monaco, path) ?? createModel(monaco, value, language, path);
|
|
137
|
-
}
|
|
138
|
-
function getModel(monaco, path) {
|
|
139
|
-
return monaco.editor.getModel(createModelUri(monaco, path));
|
|
140
|
-
}
|
|
141
|
-
function createModel(monaco, value, language, path) {
|
|
142
|
-
return monaco.editor.createModel(value, language, path ? createModelUri(monaco, path) : void 0);
|
|
143
|
-
}
|
|
144
|
-
function createModelUri(monaco, path) {
|
|
145
|
-
return monaco.Uri.parse(path);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// src/DiffEditor/DiffEditor.tsx
|
|
149
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
150
|
-
function DiffEditor({
|
|
151
|
-
original,
|
|
152
|
-
modified,
|
|
153
|
-
language,
|
|
154
|
-
originalLanguage,
|
|
155
|
-
modifiedLanguage,
|
|
156
|
-
originalModelPath,
|
|
157
|
-
modifiedModelPath,
|
|
158
|
-
keepCurrentOriginalModel = false,
|
|
159
|
-
keepCurrentModifiedModel = false,
|
|
160
|
-
theme = "light",
|
|
161
|
-
loading = "Loading...",
|
|
162
|
-
options = {},
|
|
163
|
-
height = "100%",
|
|
164
|
-
width = "100%",
|
|
165
|
-
className,
|
|
166
|
-
wrapperProps = {},
|
|
167
|
-
beforeMount = noop,
|
|
168
|
-
onMount = noop
|
|
169
|
-
}) {
|
|
170
|
-
const [isEditorReady, setIsEditorReady] = (0, import_react4.useState)(false);
|
|
171
|
-
const [isMonacoMounting, setIsMonacoMounting] = (0, import_react4.useState)(true);
|
|
172
|
-
const editorRef = (0, import_react4.useRef)(null);
|
|
173
|
-
const monacoRef = (0, import_react4.useRef)(null);
|
|
174
|
-
const containerRef = (0, import_react4.useRef)(null);
|
|
175
|
-
const onMountRef = (0, import_react4.useRef)(onMount);
|
|
176
|
-
const beforeMountRef = (0, import_react4.useRef)(beforeMount);
|
|
177
|
-
const preventCreation = (0, import_react4.useRef)(false);
|
|
178
|
-
useMount_default(() => {
|
|
179
|
-
const cancelable = import_monaco_loader.default.init();
|
|
180
|
-
cancelable.then((monaco) => (monacoRef.current = monaco) && setIsMonacoMounting(false)).catch((error) => error?.type !== "cancelation" && console.error("Monaco initialization: error:", error));
|
|
181
|
-
return () => editorRef.current ? disposeEditor() : cancelable.cancel();
|
|
182
|
-
});
|
|
183
|
-
useUpdate_default(
|
|
184
|
-
() => {
|
|
185
|
-
if (editorRef.current && monacoRef.current) {
|
|
186
|
-
const originalEditor = editorRef.current.getOriginalEditor();
|
|
187
|
-
const model = getOrCreateModel(
|
|
188
|
-
monacoRef.current,
|
|
189
|
-
original || "",
|
|
190
|
-
originalLanguage || language || "text",
|
|
191
|
-
originalModelPath || ""
|
|
192
|
-
);
|
|
193
|
-
if (model !== originalEditor.getModel()) {
|
|
194
|
-
originalEditor.setModel(model);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
[originalModelPath],
|
|
199
|
-
isEditorReady
|
|
200
|
-
);
|
|
201
|
-
useUpdate_default(
|
|
202
|
-
() => {
|
|
203
|
-
if (editorRef.current && monacoRef.current) {
|
|
204
|
-
const modifiedEditor = editorRef.current.getModifiedEditor();
|
|
205
|
-
const model = getOrCreateModel(
|
|
206
|
-
monacoRef.current,
|
|
207
|
-
modified || "",
|
|
208
|
-
modifiedLanguage || language || "text",
|
|
209
|
-
modifiedModelPath || ""
|
|
210
|
-
);
|
|
211
|
-
if (model !== modifiedEditor.getModel()) {
|
|
212
|
-
modifiedEditor.setModel(model);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
[modifiedModelPath],
|
|
217
|
-
isEditorReady
|
|
218
|
-
);
|
|
219
|
-
useUpdate_default(
|
|
220
|
-
() => {
|
|
221
|
-
const modifiedEditor = editorRef.current.getModifiedEditor();
|
|
222
|
-
if (modifiedEditor.getOption(monacoRef.current.editor.EditorOption.readOnly)) {
|
|
223
|
-
modifiedEditor.setValue(modified || "");
|
|
224
|
-
} else {
|
|
225
|
-
if (modified !== modifiedEditor.getValue()) {
|
|
226
|
-
modifiedEditor.executeEdits("", [
|
|
227
|
-
{
|
|
228
|
-
range: modifiedEditor.getModel().getFullModelRange(),
|
|
229
|
-
text: modified || "",
|
|
230
|
-
forceMoveMarkers: true
|
|
231
|
-
}
|
|
232
|
-
]);
|
|
233
|
-
modifiedEditor.pushUndoStop();
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
[modified],
|
|
238
|
-
isEditorReady
|
|
239
|
-
);
|
|
240
|
-
useUpdate_default(
|
|
241
|
-
() => {
|
|
242
|
-
editorRef.current?.getModel()?.original.setValue(original || "");
|
|
243
|
-
},
|
|
244
|
-
[original],
|
|
245
|
-
isEditorReady
|
|
246
|
-
);
|
|
247
|
-
useUpdate_default(
|
|
248
|
-
() => {
|
|
249
|
-
const { original: original2, modified: modified2 } = editorRef.current.getModel();
|
|
250
|
-
monacoRef.current.editor.setModelLanguage(original2, originalLanguage || language || "text");
|
|
251
|
-
monacoRef.current.editor.setModelLanguage(modified2, modifiedLanguage || language || "text");
|
|
252
|
-
},
|
|
253
|
-
[language, originalLanguage, modifiedLanguage],
|
|
254
|
-
isEditorReady
|
|
255
|
-
);
|
|
256
|
-
useUpdate_default(
|
|
257
|
-
() => {
|
|
258
|
-
monacoRef.current?.editor.setTheme(theme);
|
|
259
|
-
},
|
|
260
|
-
[theme],
|
|
261
|
-
isEditorReady
|
|
262
|
-
);
|
|
263
|
-
useUpdate_default(
|
|
264
|
-
() => {
|
|
265
|
-
editorRef.current?.updateOptions(options);
|
|
266
|
-
},
|
|
267
|
-
[options],
|
|
268
|
-
isEditorReady
|
|
269
|
-
);
|
|
270
|
-
const setModels = (0, import_react4.useCallback)(() => {
|
|
271
|
-
if (!monacoRef.current) return;
|
|
272
|
-
beforeMountRef.current(monacoRef.current);
|
|
273
|
-
const originalModel = getOrCreateModel(
|
|
274
|
-
monacoRef.current,
|
|
275
|
-
original || "",
|
|
276
|
-
originalLanguage || language || "text",
|
|
277
|
-
originalModelPath || ""
|
|
278
|
-
);
|
|
279
|
-
const modifiedModel = getOrCreateModel(
|
|
280
|
-
monacoRef.current,
|
|
281
|
-
modified || "",
|
|
282
|
-
modifiedLanguage || language || "text",
|
|
283
|
-
modifiedModelPath || ""
|
|
284
|
-
);
|
|
285
|
-
editorRef.current?.setModel({
|
|
286
|
-
original: originalModel,
|
|
287
|
-
modified: modifiedModel
|
|
288
|
-
});
|
|
289
|
-
}, [language, modified, modifiedLanguage, original, originalLanguage, originalModelPath, modifiedModelPath]);
|
|
290
|
-
const createEditor = (0, import_react4.useCallback)(() => {
|
|
291
|
-
if (!preventCreation.current && containerRef.current) {
|
|
292
|
-
editorRef.current = monacoRef.current.editor.createDiffEditor(containerRef.current, {
|
|
293
|
-
automaticLayout: true,
|
|
294
|
-
...options
|
|
295
|
-
});
|
|
296
|
-
setModels();
|
|
297
|
-
monacoRef.current?.editor.setTheme(theme);
|
|
298
|
-
setIsEditorReady(true);
|
|
299
|
-
preventCreation.current = true;
|
|
300
|
-
}
|
|
301
|
-
}, [options, theme, setModels]);
|
|
302
|
-
(0, import_react4.useEffect)(() => {
|
|
303
|
-
if (isEditorReady) {
|
|
304
|
-
onMountRef.current(editorRef.current, monacoRef.current);
|
|
305
|
-
}
|
|
306
|
-
}, [isEditorReady]);
|
|
307
|
-
(0, import_react4.useEffect)(() => {
|
|
308
|
-
if (!isMonacoMounting && !isEditorReady) {
|
|
309
|
-
createEditor();
|
|
310
|
-
}
|
|
311
|
-
}, [isMonacoMounting, isEditorReady, createEditor]);
|
|
312
|
-
function disposeEditor() {
|
|
313
|
-
const editor = editorRef.current;
|
|
314
|
-
const models = editor?.getModel();
|
|
315
|
-
editor?.setModel(null);
|
|
316
|
-
editor?.dispose();
|
|
317
|
-
if (!keepCurrentOriginalModel && !models?.original.isDisposed()) {
|
|
318
|
-
models?.original?.dispose();
|
|
319
|
-
}
|
|
320
|
-
if (!keepCurrentModifiedModel && !models?.modified.isDisposed()) {
|
|
321
|
-
models?.modified?.dispose();
|
|
322
|
-
}
|
|
323
|
-
editorRef.current = null;
|
|
324
|
-
preventCreation.current = false;
|
|
325
|
-
setIsEditorReady(false);
|
|
326
|
-
}
|
|
327
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
328
|
-
MonacoContainer_default2,
|
|
329
|
-
{
|
|
330
|
-
width,
|
|
331
|
-
height,
|
|
332
|
-
isEditorReady,
|
|
333
|
-
loading,
|
|
334
|
-
_ref: containerRef,
|
|
335
|
-
className,
|
|
336
|
-
wrapperProps
|
|
337
|
-
}
|
|
338
|
-
);
|
|
339
|
-
}
|
|
340
|
-
var DiffEditor_default = DiffEditor;
|
|
341
|
-
|
|
342
|
-
// src/DiffEditor/index.ts
|
|
343
|
-
var DiffEditor_default2 = (0, import_react5.memo)(DiffEditor_default);
|
|
344
|
-
|
|
345
|
-
// src/hooks/useMonaco/index.ts
|
|
346
|
-
var import_react6 = require("react");
|
|
347
|
-
var import_monaco_loader2 = __toESM(require("@willbooster/monaco-loader"), 1);
|
|
348
|
-
function useMonaco() {
|
|
349
|
-
const [monaco, setMonaco] = (0, import_react6.useState)(import_monaco_loader2.default.__getMonacoInstance());
|
|
350
|
-
useMount_default(() => {
|
|
351
|
-
let cancelable;
|
|
352
|
-
if (!monaco) {
|
|
353
|
-
cancelable = import_monaco_loader2.default.init();
|
|
354
|
-
void cancelable.then((monaco2) => {
|
|
355
|
-
setMonaco(monaco2);
|
|
356
|
-
return;
|
|
357
|
-
}).catch((error) => {
|
|
358
|
-
if (error?.type !== "cancelation") {
|
|
359
|
-
console.error("Monaco initialization: error:", error);
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
return () => cancelable?.cancel();
|
|
364
|
-
});
|
|
365
|
-
return monaco;
|
|
366
|
-
}
|
|
367
|
-
var useMonaco_default = useMonaco;
|
|
368
|
-
|
|
369
|
-
// src/Editor/index.ts
|
|
370
|
-
var import_react9 = require("react");
|
|
371
|
-
|
|
372
|
-
// src/Editor/Editor.tsx
|
|
373
|
-
var import_react8 = require("react");
|
|
374
|
-
var import_monaco_loader3 = __toESM(require("@willbooster/monaco-loader"), 1);
|
|
375
|
-
|
|
376
|
-
// src/hooks/usePrevious/index.ts
|
|
377
|
-
var import_react7 = require("react");
|
|
378
|
-
function usePrevious(value) {
|
|
379
|
-
const ref = (0, import_react7.useRef)(void 0);
|
|
380
|
-
(0, import_react7.useEffect)(() => {
|
|
381
|
-
ref.current = value;
|
|
382
|
-
}, [value]);
|
|
383
|
-
return ref.current;
|
|
384
|
-
}
|
|
385
|
-
var usePrevious_default = usePrevious;
|
|
386
|
-
|
|
387
|
-
// src/Editor/Editor.tsx
|
|
388
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
389
|
-
var viewStates = /* @__PURE__ */ new Map();
|
|
390
|
-
function Editor({
|
|
391
|
-
defaultValue,
|
|
392
|
-
defaultLanguage,
|
|
393
|
-
defaultPath,
|
|
394
|
-
value,
|
|
395
|
-
language,
|
|
396
|
-
path,
|
|
397
|
-
/* === */
|
|
398
|
-
theme = "light",
|
|
399
|
-
line,
|
|
400
|
-
loading = "Loading...",
|
|
401
|
-
options = {},
|
|
402
|
-
overrideServices = {},
|
|
403
|
-
saveViewState = true,
|
|
404
|
-
keepCurrentModel = false,
|
|
405
|
-
/* === */
|
|
406
|
-
width = "100%",
|
|
407
|
-
height = "100%",
|
|
408
|
-
className,
|
|
409
|
-
wrapperProps = {},
|
|
410
|
-
/* === */
|
|
411
|
-
beforeMount = noop,
|
|
412
|
-
onMount = noop,
|
|
413
|
-
onChange,
|
|
414
|
-
onValidate = noop
|
|
415
|
-
}) {
|
|
416
|
-
const [isEditorReady, setIsEditorReady] = (0, import_react8.useState)(false);
|
|
417
|
-
const [isMonacoMounting, setIsMonacoMounting] = (0, import_react8.useState)(true);
|
|
418
|
-
const monacoRef = (0, import_react8.useRef)(null);
|
|
419
|
-
const editorRef = (0, import_react8.useRef)(null);
|
|
420
|
-
const containerRef = (0, import_react8.useRef)(null);
|
|
421
|
-
const onMountRef = (0, import_react8.useRef)(onMount);
|
|
422
|
-
const beforeMountRef = (0, import_react8.useRef)(beforeMount);
|
|
423
|
-
const subscriptionRef = (0, import_react8.useRef)(void 0);
|
|
424
|
-
const valueRef = (0, import_react8.useRef)(value);
|
|
425
|
-
const previousPath = usePrevious_default(path);
|
|
426
|
-
const preventCreation = (0, import_react8.useRef)(false);
|
|
427
|
-
const preventTriggerChangeEvent = (0, import_react8.useRef)(false);
|
|
428
|
-
useMount_default(() => {
|
|
429
|
-
const cancelable = import_monaco_loader3.default.init();
|
|
430
|
-
cancelable.then((monaco) => (monacoRef.current = monaco) && setIsMonacoMounting(false)).catch((error) => error?.type !== "cancelation" && console.error("Monaco initialization: error:", error));
|
|
431
|
-
return () => editorRef.current ? disposeEditor() : cancelable.cancel();
|
|
432
|
-
});
|
|
433
|
-
useUpdate_default(
|
|
434
|
-
() => {
|
|
435
|
-
const model = getOrCreateModel(
|
|
436
|
-
monacoRef.current,
|
|
437
|
-
defaultValue || value || "",
|
|
438
|
-
defaultLanguage || language || "",
|
|
439
|
-
path || defaultPath || ""
|
|
440
|
-
);
|
|
441
|
-
if (model !== editorRef.current?.getModel()) {
|
|
442
|
-
if (saveViewState) viewStates.set(previousPath, editorRef.current?.saveViewState());
|
|
443
|
-
editorRef.current?.setModel(model);
|
|
444
|
-
if (saveViewState) editorRef.current?.restoreViewState(viewStates.get(path));
|
|
445
|
-
}
|
|
446
|
-
},
|
|
447
|
-
[path],
|
|
448
|
-
isEditorReady
|
|
449
|
-
);
|
|
450
|
-
useUpdate_default(
|
|
451
|
-
() => {
|
|
452
|
-
editorRef.current?.updateOptions(options);
|
|
453
|
-
},
|
|
454
|
-
[options],
|
|
455
|
-
isEditorReady
|
|
456
|
-
);
|
|
457
|
-
useUpdate_default(
|
|
458
|
-
() => {
|
|
459
|
-
if (!editorRef.current || value === void 0) return;
|
|
460
|
-
if (editorRef.current.getOption(monacoRef.current.editor.EditorOption.readOnly)) {
|
|
461
|
-
editorRef.current.setValue(value);
|
|
462
|
-
} else if (value !== editorRef.current.getValue()) {
|
|
463
|
-
preventTriggerChangeEvent.current = true;
|
|
464
|
-
editorRef.current.executeEdits("", [
|
|
465
|
-
{
|
|
466
|
-
range: editorRef.current.getModel().getFullModelRange(),
|
|
467
|
-
text: value,
|
|
468
|
-
forceMoveMarkers: true
|
|
469
|
-
}
|
|
470
|
-
]);
|
|
471
|
-
editorRef.current.pushUndoStop();
|
|
472
|
-
preventTriggerChangeEvent.current = false;
|
|
473
|
-
}
|
|
474
|
-
},
|
|
475
|
-
[value],
|
|
476
|
-
isEditorReady
|
|
477
|
-
);
|
|
478
|
-
useUpdate_default(
|
|
479
|
-
() => {
|
|
480
|
-
const model = editorRef.current?.getModel();
|
|
481
|
-
if (isEditorReady && model && language) {
|
|
482
|
-
monacoRef.current?.editor.setModelLanguage(model, language);
|
|
483
|
-
}
|
|
484
|
-
},
|
|
485
|
-
[language, isEditorReady],
|
|
486
|
-
isEditorReady
|
|
487
|
-
);
|
|
488
|
-
useUpdate_default(
|
|
489
|
-
() => {
|
|
490
|
-
if (line !== void 0) {
|
|
491
|
-
editorRef.current?.revealLine(line);
|
|
492
|
-
}
|
|
493
|
-
},
|
|
494
|
-
[line],
|
|
495
|
-
isEditorReady
|
|
496
|
-
);
|
|
497
|
-
useUpdate_default(
|
|
498
|
-
() => {
|
|
499
|
-
monacoRef.current?.editor.setTheme(theme);
|
|
500
|
-
},
|
|
501
|
-
[theme],
|
|
502
|
-
isEditorReady
|
|
503
|
-
);
|
|
504
|
-
const createEditor = (0, import_react8.useCallback)(() => {
|
|
505
|
-
if (!containerRef.current || !monacoRef.current) return;
|
|
506
|
-
if (!preventCreation.current) {
|
|
507
|
-
beforeMountRef.current(monacoRef.current);
|
|
508
|
-
const autoCreatedModelPath = path || defaultPath;
|
|
509
|
-
const defaultModel = getOrCreateModel(
|
|
510
|
-
monacoRef.current,
|
|
511
|
-
value || defaultValue || "",
|
|
512
|
-
defaultLanguage || language || "",
|
|
513
|
-
autoCreatedModelPath || ""
|
|
514
|
-
);
|
|
515
|
-
const editor = monacoRef.current.editor.create(
|
|
516
|
-
containerRef.current,
|
|
517
|
-
{
|
|
518
|
-
model: defaultModel,
|
|
519
|
-
automaticLayout: true,
|
|
520
|
-
...options
|
|
521
|
-
},
|
|
522
|
-
overrideServices
|
|
523
|
-
);
|
|
524
|
-
editorRef.current = editor;
|
|
525
|
-
saveViewState && editor.restoreViewState(viewStates.get(autoCreatedModelPath));
|
|
526
|
-
monacoRef.current.editor.setTheme(theme);
|
|
527
|
-
if (line !== void 0) {
|
|
528
|
-
editor.revealLine(line);
|
|
529
|
-
}
|
|
530
|
-
setIsEditorReady(true);
|
|
531
|
-
preventCreation.current = true;
|
|
532
|
-
}
|
|
533
|
-
}, [
|
|
534
|
-
defaultValue,
|
|
535
|
-
defaultLanguage,
|
|
536
|
-
defaultPath,
|
|
537
|
-
value,
|
|
538
|
-
language,
|
|
539
|
-
path,
|
|
540
|
-
options,
|
|
541
|
-
overrideServices,
|
|
542
|
-
saveViewState,
|
|
543
|
-
theme,
|
|
544
|
-
line
|
|
545
|
-
]);
|
|
546
|
-
(0, import_react8.useEffect)(() => {
|
|
547
|
-
if (isEditorReady) {
|
|
548
|
-
onMountRef.current(editorRef.current, monacoRef.current);
|
|
549
|
-
}
|
|
550
|
-
}, [isEditorReady]);
|
|
551
|
-
(0, import_react8.useEffect)(() => {
|
|
552
|
-
!isMonacoMounting && !isEditorReady && createEditor();
|
|
553
|
-
}, [isMonacoMounting, isEditorReady, createEditor]);
|
|
554
|
-
valueRef.current = value;
|
|
555
|
-
(0, import_react8.useEffect)(() => {
|
|
556
|
-
if (isEditorReady && onChange) {
|
|
557
|
-
subscriptionRef.current?.dispose();
|
|
558
|
-
subscriptionRef.current = editorRef.current?.onDidChangeModelContent((event) => {
|
|
559
|
-
if (!preventTriggerChangeEvent.current) {
|
|
560
|
-
onChange(editorRef.current.getValue(), event);
|
|
561
|
-
}
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
}, [isEditorReady, onChange]);
|
|
565
|
-
(0, import_react8.useEffect)(() => {
|
|
566
|
-
if (isEditorReady) {
|
|
567
|
-
const changeMarkersListener = monacoRef.current.editor.onDidChangeMarkers((uris) => {
|
|
568
|
-
const editorUri = editorRef.current.getModel()?.uri;
|
|
569
|
-
if (editorUri) {
|
|
570
|
-
const currentEditorHasMarkerChanges = uris.find((uri) => uri.path === editorUri.path);
|
|
571
|
-
if (currentEditorHasMarkerChanges) {
|
|
572
|
-
const markers = monacoRef.current.editor.getModelMarkers({
|
|
573
|
-
resource: editorUri
|
|
574
|
-
});
|
|
575
|
-
onValidate?.(markers);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
});
|
|
579
|
-
return () => {
|
|
580
|
-
changeMarkersListener?.dispose();
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
|
-
return () => {
|
|
584
|
-
};
|
|
585
|
-
}, [isEditorReady, onValidate]);
|
|
586
|
-
function disposeEditor() {
|
|
587
|
-
subscriptionRef.current?.dispose();
|
|
588
|
-
if (keepCurrentModel) {
|
|
589
|
-
saveViewState && viewStates.set(path, editorRef.current.saveViewState());
|
|
590
|
-
} else {
|
|
591
|
-
editorRef.current.getModel()?.dispose();
|
|
592
|
-
}
|
|
593
|
-
editorRef.current.dispose();
|
|
594
|
-
editorRef.current = null;
|
|
595
|
-
preventCreation.current = false;
|
|
596
|
-
setIsEditorReady(false);
|
|
597
|
-
}
|
|
598
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
599
|
-
MonacoContainer_default2,
|
|
600
|
-
{
|
|
601
|
-
width,
|
|
602
|
-
height,
|
|
603
|
-
isEditorReady,
|
|
604
|
-
loading,
|
|
605
|
-
_ref: containerRef,
|
|
606
|
-
className,
|
|
607
|
-
wrapperProps
|
|
608
|
-
}
|
|
609
|
-
);
|
|
610
|
-
}
|
|
611
|
-
var Editor_default = Editor;
|
|
612
|
-
|
|
613
|
-
// src/Editor/index.ts
|
|
614
|
-
var Editor_default2 = (0, import_react9.memo)(Editor_default);
|
|
615
|
-
|
|
616
|
-
// src/index.ts
|
|
617
|
-
var index_default = Editor_default2;
|
|
618
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
619
|
-
0 && (module.exports = {
|
|
620
|
-
DiffEditor,
|
|
621
|
-
Editor,
|
|
622
|
-
loader,
|
|
623
|
-
useMonaco
|
|
624
|
-
});
|
|
625
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@willbooster/monaco-loader"),r=require("./DiffEditor/index.cjs"),o=require("./hooks/useMonaco/index.cjs"),i=require("./Editor/index.cjs");exports.loader=e,exports.DiffEditor=r,exports.useMonaco=o,exports.Editor=i,exports.default=i;
|
|
3
|
+
//# sourceMappingURL=index.cjs.map
|