tfy-web-components 0.0.18 → 0.0.20

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.
Files changed (140) hide show
  1. package/README.md +80 -0
  2. package/dist/..d.ts +46 -0
  3. package/dist/Accordion.d.ts +8 -9
  4. package/dist/Alert.d.ts +73 -0
  5. package/dist/AudioPlayer.d.ts +10 -0
  6. package/dist/Avatar.d.ts +19 -0
  7. package/dist/Badge.d.ts +2 -1
  8. package/dist/Button.d.ts +2 -2
  9. package/dist/CopyField.d.ts +3 -2
  10. package/dist/CustomDrawer.d.ts +8 -1
  11. package/dist/DropdownMenu.d.ts +25 -0
  12. package/dist/IconButton.d.ts +4 -2
  13. package/dist/ImagesPreview.d.ts +12 -0
  14. package/dist/Input-CnGhA18d.js +74283 -0
  15. package/dist/Input-CnGhA18d.js.map +1 -0
  16. package/dist/Markdown.d.ts +103 -0
  17. package/dist/Modal.d.ts +12 -0
  18. package/dist/MonacoEditorCore-xfpJ6z-E.js +113 -0
  19. package/dist/MonacoEditorCore-xfpJ6z-E.js.map +1 -0
  20. package/dist/OpenUiFenceBlock-CsVY6kwA.js +20 -0
  21. package/dist/OpenUiFenceBlock-CsVY6kwA.js.map +1 -0
  22. package/dist/OutlinedRadio.d.ts +9 -0
  23. package/dist/RootFontSizeContext-7vgn7Y_k.js +22 -0
  24. package/dist/RootFontSizeContext-7vgn7Y_k.js.map +1 -0
  25. package/dist/SimpleCodeEditor.d.ts +63 -0
  26. package/dist/Skeleton.d.ts +7 -0
  27. package/dist/ThumbsFeedback.d.ts +18 -0
  28. package/dist/ToggleButton.d.ts +42 -0
  29. package/dist/Tooltip.d.ts +9 -5
  30. package/dist/UserMessage.d.ts +15 -0
  31. package/dist/UserMessageEdit.d.ts +16 -0
  32. package/dist/_commonjsHelpers-DWwsNxpa.js +9 -0
  33. package/dist/_commonjsHelpers-DWwsNxpa.js.map +1 -0
  34. package/dist/agent-chat.d.ts +222 -0
  35. package/dist/classNames-Dy-RXSjS.js +9 -0
  36. package/dist/{classNames-CC5emYUV.js.map → classNames-Dy-RXSjS.js.map} +1 -1
  37. package/dist/components/atoms/Accordion.d.ts +5 -6
  38. package/dist/components/atoms/Accordion.es.js +9 -7
  39. package/dist/components/atoms/Accordion.es.js.map +1 -1
  40. package/dist/components/atoms/AudioPlayer.d.ts +6 -0
  41. package/dist/components/atoms/AudioPlayer.es.js +1424 -0
  42. package/dist/components/atoms/AudioPlayer.es.js.map +1 -0
  43. package/dist/components/atoms/Avatar.d.ts +10 -0
  44. package/dist/components/atoms/Avatar.es.js +62 -0
  45. package/dist/components/atoms/Avatar.es.js.map +1 -0
  46. package/dist/components/atoms/Badge.d.ts +2 -1
  47. package/dist/components/atoms/Badge.es.js +9 -1
  48. package/dist/components/atoms/Badge.es.js.map +1 -1
  49. package/dist/components/atoms/Button.d.ts +2 -5
  50. package/dist/components/atoms/Button.es.js +2 -2
  51. package/dist/components/atoms/Button.es.js.map +1 -1
  52. package/dist/components/atoms/IconButton.d.ts +4 -2
  53. package/dist/components/atoms/IconButton.es.js +23 -7
  54. package/dist/components/atoms/IconButton.es.js.map +1 -1
  55. package/dist/components/atoms/IconProvider.es.js +28 -2
  56. package/dist/components/atoms/IconProvider.es.js.map +1 -1
  57. package/dist/components/atoms/Modal.d.ts +8 -0
  58. package/dist/components/atoms/Modal.es.js +19 -0
  59. package/dist/components/atoms/Modal.es.js.map +1 -0
  60. package/dist/components/atoms/OutlinedRadio.d.ts +5 -0
  61. package/dist/components/atoms/OutlinedRadio.es.js +29 -0
  62. package/dist/components/atoms/OutlinedRadio.es.js.map +1 -0
  63. package/dist/components/atoms/Skeleton.d.ts +4 -0
  64. package/dist/components/atoms/Skeleton.es.js +9 -0
  65. package/dist/components/atoms/Skeleton.es.js.map +1 -0
  66. package/dist/components/atoms/Spinner.es.js +1 -1
  67. package/dist/components/atoms/Switch.es.js +1 -18
  68. package/dist/components/atoms/Switch.es.js.map +1 -1
  69. package/dist/components/atoms/TabButton.es.js +1 -1
  70. package/dist/components/atoms/TabPanel.es.js +1 -1
  71. package/dist/components/atoms/Tooltip.d.ts +8 -5
  72. package/dist/components/atoms/Tooltip.es.js +1 -1
  73. package/dist/components/atoms/Tooltip.es.js.map +1 -1
  74. package/dist/components/molecules/Alert.d.ts +26 -0
  75. package/dist/components/molecules/Alert.es.js +135 -0
  76. package/dist/components/molecules/Alert.es.js.map +1 -0
  77. package/dist/components/molecules/CopyField.d.ts +1 -0
  78. package/dist/components/molecules/CopyField.es.js +12 -74192
  79. package/dist/components/molecules/CopyField.es.js.map +1 -1
  80. package/dist/components/molecules/CustomDrawer.d.ts +8 -1
  81. package/dist/components/molecules/CustomDrawer.es.js +118 -48
  82. package/dist/components/molecules/CustomDrawer.es.js.map +1 -1
  83. package/dist/components/molecules/Dialog.es.js +2570 -1519
  84. package/dist/components/molecules/Dialog.es.js.map +1 -1
  85. package/dist/components/molecules/DropdownMenu.d.ts +18 -0
  86. package/dist/components/molecules/DropdownMenu.es.js +104 -0
  87. package/dist/components/molecules/DropdownMenu.es.js.map +1 -0
  88. package/dist/components/molecules/ImagesPreview.d.ts +8 -0
  89. package/dist/components/molecules/ImagesPreview.es.js +186 -0
  90. package/dist/components/molecules/ImagesPreview.es.js.map +1 -0
  91. package/dist/components/molecules/Input.es.js +2 -2
  92. package/dist/components/molecules/Markdown.d.ts +1 -0
  93. package/dist/components/molecules/Markdown.es.js +345 -0
  94. package/dist/components/molecules/Markdown.es.js.map +1 -0
  95. package/dist/components/molecules/Notify.es.js +6 -1023
  96. package/dist/components/molecules/Notify.es.js.map +1 -1
  97. package/dist/components/molecules/SimpleCodeEditor.d.ts +56 -0
  98. package/dist/components/molecules/SimpleCodeEditor.es.js +784 -0
  99. package/dist/components/molecules/SimpleCodeEditor.es.js.map +1 -0
  100. package/dist/components/molecules/ThumbsFeedback.d.ts +13 -0
  101. package/dist/components/molecules/ThumbsFeedback.es.js +98 -0
  102. package/dist/components/molecules/ThumbsFeedback.es.js.map +1 -0
  103. package/dist/components/molecules/ToggleButton.d.ts +37 -0
  104. package/dist/components/molecules/ToggleButton.es.js +72 -0
  105. package/dist/components/molecules/ToggleButton.es.js.map +1 -0
  106. package/dist/components/molecules/agent-chat/UserMessage.d.ts +11 -0
  107. package/dist/components/molecules/agent-chat/UserMessage.es.js +40 -0
  108. package/dist/components/molecules/agent-chat/UserMessage.es.js.map +1 -0
  109. package/dist/components/molecules/agent-chat/UserMessageEdit.d.ts +12 -0
  110. package/dist/components/molecules/agent-chat/UserMessageEdit.es.js +33 -0
  111. package/dist/components/molecules/agent-chat/UserMessageEdit.es.js.map +1 -0
  112. package/dist/components/molecules/agent-chat.d.ts +1 -0
  113. package/dist/components/molecules/agent-chat.es.js +935 -0
  114. package/dist/components/molecules/agent-chat.es.js.map +1 -0
  115. package/dist/components/theme/index.d.ts +1 -0
  116. package/dist/components/theme/index.es.js +3 -1
  117. package/dist/components/theme/index.es.js.map +1 -1
  118. package/dist/components/theme/theme.d.ts +1 -0
  119. package/dist/components/theme/theme.es.js +12 -1
  120. package/dist/components/theme/theme.es.js.map +1 -1
  121. package/dist/components/theme/useTheme.d.ts +7 -0
  122. package/dist/components/theme/useTheme.es.js +35 -20
  123. package/dist/components/theme/useTheme.es.js.map +1 -1
  124. package/dist/components/theme/utils.es.js +1 -1
  125. package/dist/index.es.js +12 -4
  126. package/dist/index.es.js.map +1 -1
  127. package/dist/{isTypedArray-CoDTnA8U.js → isTypedArray-CLAk7Q1f.js} +30 -30
  128. package/dist/isTypedArray-CLAk7Q1f.js.map +1 -0
  129. package/dist/style.css +1 -1
  130. package/dist/tailwindPreset.d.ts +140 -0
  131. package/dist/tailwindPreset.es.js +100 -0
  132. package/dist/tailwindPreset.es.js.map +1 -0
  133. package/dist/theme.css +163 -0
  134. package/dist/theme.d.ts +2 -0
  135. package/dist/useTheme.d.ts +7 -0
  136. package/package.json +49 -3
  137. package/dist/_commonjsHelpers-CcAunmGO.js +0 -34
  138. package/dist/_commonjsHelpers-CcAunmGO.js.map +0 -1
  139. package/dist/classNames-CC5emYUV.js +0 -9
  140. package/dist/isTypedArray-CoDTnA8U.js.map +0 -1
@@ -0,0 +1,784 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { jsxs, jsx } from "react/jsx-runtime";
5
+ import { useRef, useEffect, useMemo, lazy, useState, useContext, useCallback, Suspense } from "react";
6
+ import { createPortal } from "react-dom";
7
+ import { Button } from "../atoms/Button.es.js";
8
+ import Spinner from "../atoms/Spinner.es.js";
9
+ import { darkPalette, lightPalette } from "../theme/colors.es.js";
10
+ import { colors } from "../theme/theme.es.js";
11
+ import { useTheme } from "../theme/useTheme.es.js";
12
+ import { c as classNames } from "../../classNames-Dy-RXSjS.js";
13
+ import { t as toDataTestId } from "../../Notification-BT4CZ69U.js";
14
+ import { C as CopyField } from "../../Input-CnGhA18d.js";
15
+ import { CustomDrawerContext } from "./CustomDrawer.es.js";
16
+ import Dialog from "./Dialog.es.js";
17
+ import notify from "./Notify.es.js";
18
+ import { u as useRootFontSize } from "../../RootFontSizeContext-7vgn7Y_k.js";
19
+ function useDebouncedCallback(func, wait, options) {
20
+ var _this = this;
21
+ var lastCallTime = useRef(null);
22
+ var lastInvokeTime = useRef(0);
23
+ var timerId = useRef(null);
24
+ var lastArgs = useRef([]);
25
+ var lastThis = useRef();
26
+ var result = useRef();
27
+ var funcRef = useRef(func);
28
+ var mounted = useRef(true);
29
+ funcRef.current = func;
30
+ var useRAF = !wait && wait !== 0 && typeof window !== "undefined";
31
+ if (typeof func !== "function") {
32
+ throw new TypeError("Expected a function");
33
+ }
34
+ wait = +wait || 0;
35
+ options = options || {};
36
+ var leading = !!options.leading;
37
+ var trailing = "trailing" in options ? !!options.trailing : true;
38
+ var maxing = "maxWait" in options;
39
+ var maxWait = maxing ? Math.max(+options.maxWait || 0, wait) : null;
40
+ useEffect(function() {
41
+ mounted.current = true;
42
+ return function() {
43
+ mounted.current = false;
44
+ };
45
+ }, []);
46
+ var debounced = useMemo(function() {
47
+ var invokeFunc = function(time) {
48
+ var args = lastArgs.current;
49
+ var thisArg = lastThis.current;
50
+ lastArgs.current = lastThis.current = null;
51
+ lastInvokeTime.current = time;
52
+ return result.current = funcRef.current.apply(thisArg, args);
53
+ };
54
+ var startTimer = function(pendingFunc, wait2) {
55
+ if (useRAF)
56
+ cancelAnimationFrame(timerId.current);
57
+ timerId.current = useRAF ? requestAnimationFrame(pendingFunc) : setTimeout(pendingFunc, wait2);
58
+ };
59
+ var shouldInvoke = function(time) {
60
+ if (!mounted.current)
61
+ return false;
62
+ var timeSinceLastCall = time - lastCallTime.current;
63
+ var timeSinceLastInvoke = time - lastInvokeTime.current;
64
+ return !lastCallTime.current || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
65
+ };
66
+ var trailingEdge = function(time) {
67
+ timerId.current = null;
68
+ if (trailing && lastArgs.current) {
69
+ return invokeFunc(time);
70
+ }
71
+ lastArgs.current = lastThis.current = null;
72
+ return result.current;
73
+ };
74
+ var timerExpired = function() {
75
+ var time = Date.now();
76
+ if (shouldInvoke(time)) {
77
+ return trailingEdge(time);
78
+ }
79
+ if (!mounted.current) {
80
+ return;
81
+ }
82
+ var timeSinceLastCall = time - lastCallTime.current;
83
+ var timeSinceLastInvoke = time - lastInvokeTime.current;
84
+ var timeWaiting = wait - timeSinceLastCall;
85
+ var remainingWait = maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
86
+ startTimer(timerExpired, remainingWait);
87
+ };
88
+ var func2 = function() {
89
+ var args = [];
90
+ for (var _i = 0; _i < arguments.length; _i++) {
91
+ args[_i] = arguments[_i];
92
+ }
93
+ var time = Date.now();
94
+ var isInvoking = shouldInvoke(time);
95
+ lastArgs.current = args;
96
+ lastThis.current = _this;
97
+ lastCallTime.current = time;
98
+ if (isInvoking) {
99
+ if (!timerId.current && mounted.current) {
100
+ lastInvokeTime.current = lastCallTime.current;
101
+ startTimer(timerExpired, wait);
102
+ return leading ? invokeFunc(lastCallTime.current) : result.current;
103
+ }
104
+ if (maxing) {
105
+ startTimer(timerExpired, wait);
106
+ return invokeFunc(lastCallTime.current);
107
+ }
108
+ }
109
+ if (!timerId.current) {
110
+ startTimer(timerExpired, wait);
111
+ }
112
+ return result.current;
113
+ };
114
+ func2.cancel = function() {
115
+ if (timerId.current) {
116
+ useRAF ? cancelAnimationFrame(timerId.current) : clearTimeout(timerId.current);
117
+ }
118
+ lastInvokeTime.current = 0;
119
+ lastArgs.current = lastCallTime.current = lastThis.current = timerId.current = null;
120
+ };
121
+ func2.isPending = function() {
122
+ return !!timerId.current;
123
+ };
124
+ func2.flush = function() {
125
+ return !timerId.current ? result.current : trailingEdge(Date.now());
126
+ };
127
+ return func2;
128
+ }, [leading, maxing, wait, maxWait, trailing, useRAF]);
129
+ return debounced;
130
+ }
131
+ function useThrottledCallback(func, wait, _a) {
132
+ var _b = {}, _c = _b.leading, leading = _c === void 0 ? true : _c, _d = _b.trailing, trailing = _d === void 0 ? true : _d;
133
+ return useDebouncedCallback(func, wait, {
134
+ maxWait: wait,
135
+ leading,
136
+ trailing
137
+ });
138
+ }
139
+ const importEditor = () => import("../../MonacoEditorCore-xfpJ6z-E.js");
140
+ const Editor = lazy(importEditor);
141
+ let markdownHeadingFoldingProviderDisposable = null;
142
+ function ensureMarkdownHeadingFoldingProvider(monaco) {
143
+ if (markdownHeadingFoldingProviderDisposable) {
144
+ return;
145
+ }
146
+ markdownHeadingFoldingProviderDisposable = monaco.languages.registerFoldingRangeProvider("markdown", {
147
+ provideFoldingRanges: (model) => {
148
+ const ranges = [];
149
+ const lines = model.getLinesContent();
150
+ const stack = [];
151
+ for (let i = 0; i < lines.length; i++) {
152
+ const match = lines[i].match(/^(#+)\s+/);
153
+ if (match) {
154
+ const level = match[1].length;
155
+ while (stack.length && stack[stack.length - 1].level >= level) {
156
+ const last = stack.pop();
157
+ if (last) {
158
+ ranges.push({
159
+ start: last.line,
160
+ end: i
161
+ });
162
+ }
163
+ }
164
+ stack.push({ level, line: i + 1 });
165
+ }
166
+ }
167
+ while (stack.length) {
168
+ const last = stack.pop();
169
+ if (last) {
170
+ ranges.push({
171
+ start: last.line,
172
+ end: lines.length
173
+ });
174
+ }
175
+ }
176
+ return ranges;
177
+ }
178
+ });
179
+ }
180
+ function SimpleCodeEditor({
181
+ defaultValue,
182
+ value,
183
+ language,
184
+ readOnly,
185
+ className,
186
+ expandDataTestId,
187
+ height,
188
+ maxHeight,
189
+ enableCopy,
190
+ enableDownload,
191
+ downloadName = "file.txt",
192
+ hideLineNumbers,
193
+ isFoldingEnabled,
194
+ enableExpand,
195
+ fullHeight = false,
196
+ autoLayout,
197
+ fontSize,
198
+ tabSize = 2,
199
+ showToolsOnHover,
200
+ onChange = () => {
201
+ },
202
+ alwaysConsumeMouseWheel = false,
203
+ enableWordWrap = false,
204
+ initialLinesCount,
205
+ placeholder = "",
206
+ placeholderClassName = "text-gray-400",
207
+ autoFocus = false,
208
+ onlyCopyIcon = false,
209
+ openAsFullscreen = false,
210
+ dataTestPrefix,
211
+ renderIndentGuides = true,
212
+ enableLineCopy = false,
213
+ onMinimise,
214
+ disableEditorResize = false,
215
+ codeToCopy,
216
+ extraButtons = null,
217
+ onValidate,
218
+ showExpandOverlay = false,
219
+ softMaxHeight = null,
220
+ darkModeBgColor,
221
+ showExpandOnlyInFullscreen = false,
222
+ hideHorizontalScrollbar = false,
223
+ onPaste,
224
+ enableLineNumbersForText = false,
225
+ enableLineHighlight = false,
226
+ onEditorReady,
227
+ isPrivate = false
228
+ }) {
229
+ const isPlainTextEditor = language === "text";
230
+ const shouldWordWrap = enableWordWrap || isPlainTextEditor;
231
+ const { rootFontSize } = useRootFontSize();
232
+ const APPLIED_LINE_HEIGHT = isPlainTextEditor ? rootFontSize * 1.25 : rootFontSize * 1.125;
233
+ const [codeValue, setCodeValue] = useState(defaultValue);
234
+ const [internalCodeValue, setInternalCodeValue] = useState(value ?? defaultValue ?? "");
235
+ const linesView = useRef(null);
236
+ const editorRef = useRef(null);
237
+ const placeholderRef = useRef(null);
238
+ const wrapperView = useRef(null);
239
+ const [copyWidgetContainer, setCopyWidgetContainer] = useState(null);
240
+ const [copyWidgetLine, setCopyWidgetLine] = useState(null);
241
+ const isMouseOverWidget = useRef(false);
242
+ const hideTimeout = useRef(null);
243
+ const [copiedLine, setCopiedLine] = useState(null);
244
+ const checkTimeoutRef = useRef(null);
245
+ const { updateDrawerContext } = useContext(CustomDrawerContext);
246
+ const MIN_HEIGHT = height ?? (initialLinesCount ? initialLinesCount * APPLIED_LINE_HEIGHT + rootFontSize : rootFontSize * 7.5);
247
+ const SOFT_MAX_HEIGHT = softMaxHeight ?? rootFontSize * 18.75;
248
+ const [editorHeight, setEditorHeight] = useState(MIN_HEIGHT);
249
+ const [fullscreen, setFullscreen] = useState(openAsFullscreen);
250
+ const [marginWidth, setMarginWidth] = useState("");
251
+ const { isDark } = useTheme();
252
+ useEffect(() => {
253
+ setFullscreen(openAsFullscreen);
254
+ }, [openAsFullscreen]);
255
+ const updateAutoLayout = useCallback(() => {
256
+ if (autoLayout && editorRef.current) {
257
+ requestAnimationFrame(() => {
258
+ return setEditorHeight(
259
+ editorRef.current.getContentHeight() + 1.5 * rootFontSize - (hideHorizontalScrollbar ? rootFontSize * 0.5 : 0)
260
+ );
261
+ });
262
+ }
263
+ }, [autoLayout, rootFontSize]);
264
+ const throttledUpdateLayout = useThrottledCallback(updateAutoLayout, 100);
265
+ useEffect(() => {
266
+ setCodeValue(defaultValue);
267
+ if (value === void 0) {
268
+ setInternalCodeValue(defaultValue ?? "");
269
+ }
270
+ }, [defaultValue, value]);
271
+ useEffect(() => {
272
+ throttledUpdateLayout();
273
+ }, [codeValue, internalCodeValue]);
274
+ useEffect(() => {
275
+ window.addEventListener("resize", throttledUpdateLayout);
276
+ return () => window.removeEventListener("resize", throttledUpdateLayout);
277
+ }, [throttledUpdateLayout]);
278
+ const editorBackgroundColor = "#00000000";
279
+ const lineHighlightBackgroundColor = isDark ? darkPalette.gray[150] : lightPalette.gray[250];
280
+ function handleBeforeMount(monaco) {
281
+ monaco.editor.defineTheme("inputTheme", {
282
+ base: isDark ? "vs-dark" : "vs",
283
+ inherit: true,
284
+ rules: [{ background: editorBackgroundColor }],
285
+ colors: {
286
+ "editor.background": editorBackgroundColor,
287
+ "editor.lineHighlightBackground": lineHighlightBackgroundColor,
288
+ focusBorder: "#00000000"
289
+ }
290
+ });
291
+ ensureMarkdownHeadingFoldingProvider(monaco);
292
+ }
293
+ async function handleEditorMount(editor, monaco) {
294
+ class CopyLineWidget {
295
+ constructor() {
296
+ __publicField(this, "id");
297
+ __publicField(this, "domNode");
298
+ __publicField(this, "lineNumber", null);
299
+ this.id = "copy.line.widget";
300
+ this.domNode = document.createElement("div");
301
+ this.domNode.style.position = "absolute";
302
+ this.domNode.style.zIndex = "10";
303
+ this.domNode.style.display = "none";
304
+ setCopyWidgetContainer(this.domNode);
305
+ }
306
+ getId() {
307
+ return this.id;
308
+ }
309
+ getDomNode() {
310
+ return this.domNode;
311
+ }
312
+ getPosition() {
313
+ if (!this.lineNumber) return null;
314
+ const model = editor.getModel();
315
+ const lastColumn = model.getLineMaxColumn(this.lineNumber);
316
+ return {
317
+ position: { lineNumber: this.lineNumber, column: lastColumn },
318
+ preference: [monaco.editor.ContentWidgetPositionPreference.EXACT]
319
+ };
320
+ }
321
+ showAtLine(lineNumber) {
322
+ if (this.lineNumber === lineNumber) return;
323
+ this.lineNumber = lineNumber;
324
+ setCopyWidgetLine(lineNumber);
325
+ const model = editor.getModel();
326
+ const lineContent = model.getLineContent(lineNumber).trim();
327
+ if (lineContent === "}," || lineContent === "],") {
328
+ this.domNode.style.display = "none";
329
+ } else {
330
+ this.domNode.style.display = "block";
331
+ }
332
+ editor.layoutContentWidget(this);
333
+ }
334
+ hide() {
335
+ this.lineNumber = null;
336
+ setCopyWidgetLine(null);
337
+ this.domNode.style.display = "none";
338
+ editor.layoutContentWidget(this);
339
+ }
340
+ }
341
+ if (enableLineCopy) {
342
+ const copyWidget = new CopyLineWidget();
343
+ editor.addContentWidget(copyWidget);
344
+ editor.onMouseMove((e) => {
345
+ var _a, _b;
346
+ const lineNumber = (_b = (_a = e.target) == null ? void 0 : _a.position) == null ? void 0 : _b.lineNumber;
347
+ if (lineNumber) {
348
+ if (hideTimeout.current) {
349
+ clearTimeout(hideTimeout.current);
350
+ hideTimeout.current = null;
351
+ }
352
+ copyWidget.showAtLine(lineNumber);
353
+ } else {
354
+ hideTimeout.current = setTimeout(() => {
355
+ if (!isMouseOverWidget.current) {
356
+ copyWidget.hide();
357
+ }
358
+ }, 200);
359
+ }
360
+ });
361
+ editor.onMouseLeave(() => {
362
+ hideTimeout.current = setTimeout(() => {
363
+ if (!isMouseOverWidget.current) {
364
+ copyWidget.hide();
365
+ }
366
+ }, 200);
367
+ });
368
+ }
369
+ if (onPaste) {
370
+ editor.onDidPaste(() => {
371
+ onPaste(editor.getModel().getValue());
372
+ });
373
+ }
374
+ const options = {
375
+ hover: true,
376
+ completion: true,
377
+ validate: true,
378
+ format: true
379
+ };
380
+ const json = monaco.languages.json;
381
+ if (json && json.jsonDefaults) {
382
+ json.jsonDefaults.setDiagnosticsOptions(options);
383
+ }
384
+ const yaml = monaco.languages.yaml;
385
+ if (yaml && yaml.jsonDefaults) {
386
+ yaml.yamlDefaults.setDiagnosticsOptions(options);
387
+ }
388
+ editor.getModel().updateOptions({ tabSize });
389
+ linesView.current = document.getElementsByClassName("view-lines monaco-mouse-cursor-text")[0];
390
+ requestAnimationFrame(() => {
391
+ var _a, _b, _c;
392
+ setMarginWidth(((_c = (_b = (_a = wrapperView.current) == null ? void 0 : _a.querySelector(".margin")) == null ? void 0 : _b.style) == null ? void 0 : _c.width) ?? 0);
393
+ });
394
+ editorRef.current = editor;
395
+ onEditorReady == null ? void 0 : onEditorReady(editor);
396
+ throttledUpdateLayout();
397
+ }
398
+ useEffect(() => {
399
+ if (value !== void 0) {
400
+ setInternalCodeValue(value);
401
+ }
402
+ }, [value]);
403
+ function handleResize(param) {
404
+ var _a;
405
+ if (param.height && !param.maxHeight) {
406
+ setEditorHeight(param.height);
407
+ return;
408
+ }
409
+ const content = param.content || codeValue;
410
+ const absoluteEditorHeight = (((_a = content == null ? void 0 : content.split("\n")) == null ? void 0 : _a.length) ?? 0) * APPLIED_LINE_HEIGHT + rootFontSize;
411
+ if (param.maxHeight) {
412
+ setEditorHeight(
413
+ absoluteEditorHeight > param.maxHeight * rootFontSize ? param.maxHeight * rootFontSize : absoluteEditorHeight
414
+ );
415
+ return;
416
+ }
417
+ if (enableExpand && linesView.current) {
418
+ if (typeof MIN_HEIGHT === "number" && absoluteEditorHeight > MIN_HEIGHT) {
419
+ setEditorHeight(absoluteEditorHeight > SOFT_MAX_HEIGHT ? SOFT_MAX_HEIGHT : absoluteEditorHeight);
420
+ } else {
421
+ setEditorHeight(MIN_HEIGHT);
422
+ }
423
+ }
424
+ }
425
+ useEffect(() => {
426
+ if (editorRef.current && autoFocus) {
427
+ editorRef.current.focus();
428
+ }
429
+ }, [autoFocus]);
430
+ useEffect(() => {
431
+ setEditorHeight(MIN_HEIGHT);
432
+ handleResize({ height, maxHeight });
433
+ }, [height, maxHeight]);
434
+ useEffect(() => {
435
+ updateDrawerContext == null ? void 0 : updateDrawerContext(
436
+ {
437
+ isPreventEscape: fullscreen,
438
+ onEscape: () => {
439
+ setFullscreen(false);
440
+ }
441
+ },
442
+ !fullscreen
443
+ );
444
+ }, [fullscreen]);
445
+ const handleDownloadFile = () => {
446
+ const element = document.createElement("a");
447
+ const file = new Blob([codeValue || ""], {
448
+ type: "text/plain;charset=utf-8"
449
+ });
450
+ element.href = URL.createObjectURL(file);
451
+ element.download = downloadName;
452
+ document.body.appendChild(element);
453
+ element.click();
454
+ document.body.removeChild(element);
455
+ };
456
+ const handleCopyLine = async () => {
457
+ var _a, _b, _c, _d, _e;
458
+ if (copyWidgetLine && editorRef.current) {
459
+ const model = editorRef.current.getModel();
460
+ const lineContent = model.getLineContent(copyWidgetLine);
461
+ const trimmed = lineContent.trim();
462
+ if (trimmed.endsWith("{") || trimmed.endsWith("[")) {
463
+ const isObject = trimmed.endsWith("{");
464
+ const openChar = isObject ? "{" : "[";
465
+ const closeChar = isObject ? "}" : "]";
466
+ const totalLines = model.getLineCount();
467
+ let openCount = 0;
468
+ let collectedLines = [];
469
+ let foundStart = false;
470
+ for (let i = copyWidgetLine; i <= totalLines; i++) {
471
+ const content = model.getLineContent(i);
472
+ if (!foundStart) {
473
+ if (content.trim().endsWith(openChar)) {
474
+ foundStart = true;
475
+ }
476
+ }
477
+ if (foundStart) {
478
+ collectedLines.push(content);
479
+ for (const char of content) {
480
+ if (char === openChar) openCount++;
481
+ if (char === closeChar) openCount--;
482
+ }
483
+ if (openCount === 0) {
484
+ break;
485
+ }
486
+ }
487
+ }
488
+ collectedLines = [
489
+ (collectedLines == null ? void 0 : collectedLines.includes(":")) ? (_b = (_a = collectedLines[0].split(":")) == null ? void 0 : _a[1]) == null ? void 0 : _b.trim() : collectedLines[0],
490
+ ...collectedLines.slice(1, collectedLines.length - 1),
491
+ (_c = collectedLines[collectedLines.length - 1].split(",")[0]) == null ? void 0 : _c.trim()
492
+ ];
493
+ try {
494
+ await navigator.clipboard.writeText(collectedLines.join("\n"));
495
+ } catch (err) {
496
+ notify("error", "Failed to copy to clipboard");
497
+ }
498
+ } else {
499
+ const cleanedLine = lineContent == null ? void 0 : lineContent.replace(/,$/, "");
500
+ const copiedValue = (_e = (_d = cleanedLine == null ? void 0 : cleanedLine.split(": ", 2)) == null ? void 0 : _d[1]) == null ? void 0 : _e.trim();
501
+ try {
502
+ navigator.clipboard.writeText(copiedValue ?? lineContent);
503
+ } catch (err) {
504
+ notify("error", "Failed to copy to clipboard");
505
+ }
506
+ }
507
+ setCopiedLine(copyWidgetLine);
508
+ if (checkTimeoutRef.current) {
509
+ clearTimeout(checkTimeoutRef.current);
510
+ }
511
+ checkTimeoutRef.current = setTimeout(() => {
512
+ setCopiedLine(null);
513
+ }, 2e3);
514
+ }
515
+ };
516
+ const view = /* @__PURE__ */ jsxs(
517
+ "div",
518
+ {
519
+ ref: wrapperView,
520
+ ...isPrivate ? { "data-private": true } : {},
521
+ className: classNames(
522
+ fullscreen ? "h-full w-full bg-white p-4 pb-0" : "w-full relative",
523
+ "rounded overflow-hidden border border-blue-500 py-2 bg-blue-45 dark:border-gray-250",
524
+ !darkModeBgColor && "dark:bg-gray-200",
525
+ isPlainTextEditor && "px-3",
526
+ showToolsOnHover && "group",
527
+ className
528
+ ),
529
+ style: fullscreen ? void 0 : autoLayout ? {
530
+ height: editorHeight,
531
+ ...isDark && darkModeBgColor && { backgroundColor: darkModeBgColor }
532
+ } : enableExpand ? {
533
+ resize: disableEditorResize ? "none" : "vertical",
534
+ minHeight: MIN_HEIGHT,
535
+ maxHeight: "auto",
536
+ height: editorHeight,
537
+ backgroundColor: isDark ? darkModeBgColor || colors.gray[250] : void 0
538
+ } : fullHeight ? {
539
+ height: "100%",
540
+ ...isDark && darkModeBgColor && { backgroundColor: darkModeBgColor }
541
+ } : {
542
+ minHeight: MIN_HEIGHT,
543
+ maxHeight: "auto",
544
+ height: editorHeight,
545
+ ...isDark && darkModeBgColor && { backgroundColor: darkModeBgColor }
546
+ },
547
+ children: [
548
+ /* @__PURE__ */ jsx(
549
+ Suspense,
550
+ {
551
+ fallback: /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center w-full rounded", style: { minHeight: MIN_HEIGHT }, children: /* @__PURE__ */ jsx(Spinner, { small: true }) }),
552
+ children: /* @__PURE__ */ jsx(
553
+ Editor,
554
+ {
555
+ defaultLanguage: language ?? "json",
556
+ defaultValue: codeValue,
557
+ value,
558
+ onChange: (e) => {
559
+ onChange(e);
560
+ setCodeValue(e);
561
+ setInternalCodeValue(e ?? "");
562
+ handleResize({ content: e });
563
+ },
564
+ onMount: handleEditorMount,
565
+ beforeMount: handleBeforeMount,
566
+ theme: "inputTheme",
567
+ options: {
568
+ readOnly,
569
+ stickyScroll: { enabled: false },
570
+ minimap: { enabled: false },
571
+ // Render suggestion/hover/parameter-hint widgets in a fixed-position
572
+ // layer so they escape `overflow-hidden` ancestors instead of being
573
+ // clipped behind the surrounding card when the editor area scrolls.
574
+ fixedOverflowWidgets: true,
575
+ quickSuggestions: !isPlainTextEditor,
576
+ scrollbar: {
577
+ useShadows: false,
578
+ verticalScrollbarSize: rootFontSize * 0.5,
579
+ horizontalScrollbarSize: hideHorizontalScrollbar ? 0 : rootFontSize * 0.5,
580
+ alwaysConsumeMouseWheel,
581
+ ...autoLayout ? {
582
+ vertical: "hidden"
583
+ } : {}
584
+ },
585
+ revealHorizontalRightPadding: rootFontSize * 1.875,
586
+ wordBreak: isPlainTextEditor ? "normal" : "keepAll",
587
+ lineHeight: isPlainTextEditor ? rootFontSize * 1.25 : rootFontSize * 1.125,
588
+ scrollBeyondLastLine: false,
589
+ automaticLayout: true,
590
+ fontSize: fontSize ?? (isPlainTextEditor ? rootFontSize * 0.875 : fullscreen ? rootFontSize : rootFontSize * 0.75),
591
+ renderLineHighlight: enableLineHighlight ? "line" : "none",
592
+ ...hideLineNumbers || isPlainTextEditor ? {
593
+ lineNumbers: "off",
594
+ glyphMargin: false,
595
+ folding: false,
596
+ lineDecorationsWidth: 0,
597
+ lineNumbersMinChars: 0
598
+ } : {},
599
+ ...enableLineNumbersForText && {
600
+ lineNumbers: "on",
601
+ lineNumbersMinChars: 1,
602
+ lineDecorationsWidth: 8,
603
+ glyphMargin: false,
604
+ folding: false
605
+ },
606
+ ...isFoldingEnabled ? {
607
+ folding: true,
608
+ showFoldingControls: "always",
609
+ glyphMargin: false,
610
+ lineDecorationsWidth: 16
611
+ } : {},
612
+ wordWrap: shouldWordWrap ? "on" : "off",
613
+ wrappingStrategy: shouldWordWrap ? "advanced" : "simple",
614
+ overviewRulerLanes: autoLayout ? 0 : void 0,
615
+ fontFamily: "Jetbrains Mono",
616
+ fontWeight: "500",
617
+ renderWhitespace: "none",
618
+ guides: {
619
+ indentation: renderIndentGuides,
620
+ highlightActiveIndentation: renderIndentGuides
621
+ }
622
+ },
623
+ ...onValidate && { onValidate }
624
+ },
625
+ `isDark-${isDark}`
626
+ )
627
+ }
628
+ ),
629
+ /* @__PURE__ */ jsxs("div", { className: "absolute flex flex-row top-1 right-2 z-10", children: [
630
+ (enableCopy || enableDownload || showToolsOnHover || extraButtons) && /* @__PURE__ */ jsxs("div", { className: `flex flex-row gap-1 ${showToolsOnHover ? "hidden group-hover:block" : ""}`, children: [
631
+ extraButtons,
632
+ (enableCopy || showToolsOnHover) && /* @__PURE__ */ jsx(
633
+ CopyField,
634
+ {
635
+ rawValue: codeToCopy || codeValue,
636
+ initialText: onlyCopyIcon ? "" : "Copy",
637
+ btnClass: classNames("text-xs", {
638
+ " !w-8": onlyCopyIcon
639
+ }),
640
+ dataTestPrefix: toDataTestId("code-copy", dataTestPrefix)
641
+ }
642
+ ),
643
+ enableDownload && /* @__PURE__ */ jsx(
644
+ Button.Secondary,
645
+ {
646
+ size: "small",
647
+ text: "Download",
648
+ icon: "download",
649
+ dataTestId: toDataTestId("download", dataTestPrefix),
650
+ onClick: handleDownloadFile
651
+ }
652
+ )
653
+ ] }),
654
+ showExpandOnlyInFullscreen && fullscreen ? /* @__PURE__ */ jsx(
655
+ Button.Secondary,
656
+ {
657
+ size: "small",
658
+ text: "Minimise",
659
+ icon: "compress-alt",
660
+ onClick: () => {
661
+ if (fullscreen && onMinimise) {
662
+ onMinimise();
663
+ }
664
+ setFullscreen(!fullscreen);
665
+ }
666
+ }
667
+ ) : (enableExpand || showToolsOnHover) && (!showExpandOverlay || fullscreen) && /* @__PURE__ */ jsx(
668
+ Button.Secondary,
669
+ {
670
+ size: "small",
671
+ text: fullscreen ? "Minimise" : "",
672
+ icon: fullscreen ? "compress-alt" : "expand-alt",
673
+ dataTestId: expandDataTestId,
674
+ onClick: () => {
675
+ if (fullscreen && onMinimise) {
676
+ onMinimise();
677
+ }
678
+ setFullscreen(!fullscreen);
679
+ }
680
+ }
681
+ )
682
+ ] }),
683
+ ["", void 0].includes(internalCodeValue) && editorRef.current && /* @__PURE__ */ jsx(
684
+ "div",
685
+ {
686
+ className: classNames(
687
+ "absolute top-2 font-jetbrains font-light whitespace-pre-wrap pointer-events-none",
688
+ placeholderClassName,
689
+ isPlainTextEditor ? "leading-5" : "leading-[1.125rem]"
690
+ ),
691
+ style: {
692
+ fontSize: fontSize ? fontSize * rootFontSize / 16 : fullscreen ? rootFontSize : rootFontSize * 0.75,
693
+ marginLeft: marginWidth
694
+ },
695
+ ref: placeholderRef,
696
+ dangerouslySetInnerHTML: {
697
+ __html: placeholder
698
+ }
699
+ }
700
+ ),
701
+ copyWidgetContainer && enableLineCopy && createPortal(
702
+ /* @__PURE__ */ jsx(
703
+ "div",
704
+ {
705
+ className: "relative -top-1",
706
+ onMouseEnter: () => {
707
+ isMouseOverWidget.current = true;
708
+ if (hideTimeout.current) {
709
+ clearTimeout(hideTimeout.current);
710
+ hideTimeout.current = null;
711
+ }
712
+ },
713
+ onMouseLeave: () => {
714
+ isMouseOverWidget.current = false;
715
+ hideTimeout.current = setTimeout(() => {
716
+ if (!isMouseOverWidget.current) {
717
+ if (copyWidgetLine && copyWidgetContainer) {
718
+ copyWidgetContainer.style.display = "none";
719
+ setCopyWidgetLine(null);
720
+ }
721
+ }
722
+ }, 200);
723
+ },
724
+ children: /* @__PURE__ */ jsx(
725
+ Button.Ghost,
726
+ {
727
+ size: "small",
728
+ icon: copiedLine && copiedLine === copyWidgetLine ? "check" : "copy",
729
+ iconClasses: "text-gray-600",
730
+ onClick: handleCopyLine
731
+ },
732
+ copyWidgetLine ?? ""
733
+ )
734
+ }
735
+ ),
736
+ copyWidgetContainer
737
+ ),
738
+ showExpandOverlay && !fullscreen && /* @__PURE__ */ jsx(
739
+ "div",
740
+ {
741
+ className: "absolute inset-0 h-full bg-white/80 w-full flex items-center justify-center cursor-pointer",
742
+ onClick: () => {
743
+ setFullscreen(true);
744
+ },
745
+ children: /* @__PURE__ */ jsx(Button.Secondary, { text: "Click to Expand", size: "small" })
746
+ }
747
+ )
748
+ ]
749
+ }
750
+ );
751
+ if (fullscreen) {
752
+ return /* @__PURE__ */ jsx(Dialog, { fullScreen: true, open: fullscreen, setOpen: () => {
753
+ }, content: view });
754
+ }
755
+ return view;
756
+ }
757
+ const usePreloadEditor = () => {
758
+ useEffect(() => {
759
+ let timeout;
760
+ if ("requestIdleCallback" in window) {
761
+ timeout = window.requestIdleCallback(() => {
762
+ importEditor();
763
+ });
764
+ } else {
765
+ timeout = setTimeout(() => {
766
+ importEditor();
767
+ }, 1);
768
+ }
769
+ return () => {
770
+ if ("requestIdleCallback" in window) {
771
+ window.cancelIdleCallback(timeout);
772
+ } else {
773
+ clearTimeout(timeout);
774
+ }
775
+ };
776
+ }, []);
777
+ return null;
778
+ };
779
+ export {
780
+ SimpleCodeEditor as default,
781
+ importEditor,
782
+ usePreloadEditor
783
+ };
784
+ //# sourceMappingURL=SimpleCodeEditor.es.js.map