@gooddata/sdk-ui-metric-component 11.67.0-alpha.2 → 11.67.0-alpha.3

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 (197) hide show
  1. package/NOTICE +943 -2401
  2. package/esm/MaqlEditor/codemirror/CodeEditor.d.ts +52 -0
  3. package/esm/MaqlEditor/codemirror/CodeEditor.d.ts.map +1 -0
  4. package/esm/MaqlEditor/codemirror/CodeEditor.js +170 -0
  5. package/esm/MaqlEditor/codemirror/CodeEditor.styles.d.ts +95 -0
  6. package/esm/MaqlEditor/codemirror/CodeEditor.styles.d.ts.map +1 -0
  7. package/esm/MaqlEditor/codemirror/CodeEditor.styles.js +536 -0
  8. package/esm/MaqlEditor/codemirror/ContextMenu.d.ts +52 -0
  9. package/esm/MaqlEditor/codemirror/ContextMenu.d.ts.map +1 -0
  10. package/esm/MaqlEditor/codemirror/ContextMenu.js +204 -0
  11. package/esm/MaqlEditor/codemirror/baseExtensions.d.ts +22 -0
  12. package/esm/MaqlEditor/codemirror/baseExtensions.d.ts.map +1 -0
  13. package/esm/MaqlEditor/codemirror/baseExtensions.js +95 -0
  14. package/esm/MaqlEditor/codemirror/commands.d.ts +21 -0
  15. package/esm/MaqlEditor/codemirror/commands.d.ts.map +1 -0
  16. package/esm/MaqlEditor/codemirror/commands.js +98 -0
  17. package/esm/MaqlEditor/codemirror/hooks/useAutofocus.d.ts +7 -0
  18. package/esm/MaqlEditor/codemirror/hooks/useAutofocus.d.ts.map +1 -0
  19. package/esm/MaqlEditor/{monaco → codemirror}/hooks/useAutofocus.js +4 -0
  20. package/esm/MaqlEditor/codemirror/lsp.d.ts +28 -0
  21. package/esm/MaqlEditor/codemirror/lsp.d.ts.map +1 -0
  22. package/esm/MaqlEditor/codemirror/lsp.js +70 -0
  23. package/esm/MaqlEditor/codemirror/markdown.d.ts +11 -0
  24. package/esm/MaqlEditor/codemirror/markdown.d.ts.map +1 -0
  25. package/esm/MaqlEditor/codemirror/markdown.js +28 -0
  26. package/esm/MaqlEditor/codemirror/types.d.ts +8 -0
  27. package/esm/MaqlEditor/codemirror/types.d.ts.map +1 -0
  28. package/esm/MaqlEditor/codemirror/types.js +2 -0
  29. package/esm/MaqlEditor/hooks/useCodeTheme.d.ts +15 -2
  30. package/esm/MaqlEditor/hooks/useCodeTheme.d.ts.map +1 -1
  31. package/esm/MaqlEditor/hooks/useCodeTheme.js +36 -43
  32. package/esm/MaqlEditor/hooks/useCopyToClipboard.d.ts +7 -2
  33. package/esm/MaqlEditor/hooks/useCopyToClipboard.d.ts.map +1 -1
  34. package/esm/MaqlEditor/hooks/useCopyToClipboard.js +53 -10
  35. package/esm/MaqlEditor/maql/MaqlEditor.d.ts +25 -9
  36. package/esm/MaqlEditor/maql/MaqlEditor.d.ts.map +1 -1
  37. package/esm/MaqlEditor/maql/MaqlEditor.js +179 -30
  38. package/esm/MaqlEditor/maql/MaqlEditor.styles.d.ts.map +1 -1
  39. package/esm/MaqlEditor/maql/MaqlEditor.styles.js +13 -17
  40. package/esm/MaqlEditor/maql/MaqlEditor.tooltip.d.ts.map +1 -1
  41. package/esm/MaqlEditor/maql/MaqlEditor.tooltip.js +15 -20
  42. package/esm/MaqlEditor/maql/extensions/completion.d.ts +101 -0
  43. package/esm/MaqlEditor/maql/extensions/completion.d.ts.map +1 -0
  44. package/esm/MaqlEditor/maql/extensions/completion.js +420 -0
  45. package/esm/MaqlEditor/maql/extensions/decorations.d.ts +19 -0
  46. package/esm/MaqlEditor/maql/extensions/decorations.d.ts.map +1 -0
  47. package/esm/MaqlEditor/maql/extensions/decorations.js +137 -0
  48. package/esm/MaqlEditor/maql/extensions/formatting.d.ts +22 -0
  49. package/esm/MaqlEditor/maql/extensions/formatting.d.ts.map +1 -0
  50. package/esm/MaqlEditor/maql/extensions/formatting.js +78 -0
  51. package/esm/MaqlEditor/maql/extensions/hover.d.ts +22 -0
  52. package/esm/MaqlEditor/maql/extensions/hover.d.ts.map +1 -0
  53. package/esm/MaqlEditor/maql/extensions/hover.js +98 -0
  54. package/esm/MaqlEditor/maql/extensions/semanticTokens.d.ts +15 -0
  55. package/esm/MaqlEditor/maql/extensions/semanticTokens.d.ts.map +1 -0
  56. package/esm/MaqlEditor/maql/extensions/semanticTokens.js +79 -0
  57. package/esm/MaqlEditor/maql/extensions/validation.d.ts +41 -0
  58. package/esm/MaqlEditor/maql/extensions/validation.d.ts.map +1 -0
  59. package/esm/MaqlEditor/maql/extensions/validation.js +202 -0
  60. package/esm/MaqlEditor/maql/hooks/hover/doHover.d.ts +19 -4
  61. package/esm/MaqlEditor/maql/hooks/hover/doHover.d.ts.map +1 -1
  62. package/esm/MaqlEditor/maql/hooks/hover/doHover.js +71 -61
  63. package/esm/MaqlEditor/maql/maqlLanguage.d.ts +16 -0
  64. package/esm/MaqlEditor/maql/maqlLanguage.d.ts.map +1 -0
  65. package/esm/MaqlEditor/maql/maqlLanguage.js +72 -0
  66. package/esm/MaqlEditor/mock/editor-shim.d.ts +7 -0
  67. package/esm/MaqlEditor/mock/editor-shim.d.ts.map +1 -0
  68. package/esm/MaqlEditor/mock/{monaco-shim.js → editor-shim.js} +27 -1
  69. package/esm/MaqlEditor/sql/SqlEditor.d.ts +15 -7
  70. package/esm/MaqlEditor/sql/SqlEditor.d.ts.map +1 -1
  71. package/esm/MaqlEditor/sql/SqlEditor.js +55 -30
  72. package/esm/MaqlEditor/sql/formatter.d.ts +6 -5
  73. package/esm/MaqlEditor/sql/formatter.d.ts.map +1 -1
  74. package/esm/MaqlEditor/sql/formatter.js +14 -14
  75. package/esm/MaqlEditor/sql/sqlLanguage.d.ts +3 -0
  76. package/esm/MaqlEditor/sql/sqlLanguage.d.ts.map +1 -0
  77. package/esm/MaqlEditor/sql/sqlLanguage.js +19 -0
  78. package/esm/MaqlEditor/statusBar/SuggestionStatusBar.d.ts +5 -2
  79. package/esm/MaqlEditor/statusBar/SuggestionStatusBar.d.ts.map +1 -1
  80. package/esm/MaqlEditor/statusBar/SuggestionStatusBar.js +20 -8
  81. package/esm/MetricComponent/Form/MaqlEditorField/MaqlEditorEditor.d.ts.map +1 -1
  82. package/esm/MetricComponent/Form/MaqlEditorField/MaqlEditorEditor.js +28 -27
  83. package/esm/MetricComponent/Form/MaqlEditorField/suggestionDetailsFunctions.d.ts +0 -1
  84. package/esm/MetricComponent/Form/MaqlEditorField/suggestionDetailsFunctions.d.ts.map +1 -1
  85. package/esm/MetricComponent/Form/MaqlEditorField/suggestionDetailsFunctions.js +4 -29
  86. package/esm/MetricComponent/Form/MaqlResult/MaqlSql.d.ts.map +1 -1
  87. package/esm/MetricComponent/Form/MaqlResult/MaqlSql.js +4 -2
  88. package/esm/MetricComponent/Form/maqlFieldFunctions.d.ts +2 -5
  89. package/esm/MetricComponent/Form/maqlFieldFunctions.d.ts.map +1 -1
  90. package/esm/MetricComponent/Form/maqlFieldFunctions.js +1 -4
  91. package/esm/index.d.ts +3 -3
  92. package/esm/index.d.ts.map +1 -1
  93. package/esm/index.js +1 -1
  94. package/esm/sdk-ui-metric-component.d.ts +50 -39
  95. package/esm/shared/permissions.d.ts.map +1 -1
  96. package/esm/shared/permissions.js +1 -0
  97. package/esm/translations/en-US.json +36 -0
  98. package/package.json +33 -30
  99. package/esm/MaqlEditor/hooks/useAutoformat.d.ts +0 -3
  100. package/esm/MaqlEditor/hooks/useAutoformat.d.ts.map +0 -1
  101. package/esm/MaqlEditor/hooks/useAutoformat.js +0 -15
  102. package/esm/MaqlEditor/hooks/useCleanCallback.d.ts +0 -4
  103. package/esm/MaqlEditor/hooks/useCleanCallback.d.ts.map +0 -1
  104. package/esm/MaqlEditor/hooks/useCleanCallback.js +0 -12
  105. package/esm/MaqlEditor/hooks/useMountCallback.d.ts +0 -13
  106. package/esm/MaqlEditor/hooks/useMountCallback.d.ts.map +0 -1
  107. package/esm/MaqlEditor/hooks/useMountCallback.js +0 -26
  108. package/esm/MaqlEditor/hooks/useUpdateCallback.d.ts +0 -19
  109. package/esm/MaqlEditor/hooks/useUpdateCallback.d.ts.map +0 -1
  110. package/esm/MaqlEditor/hooks/useUpdateCallback.js +0 -63
  111. package/esm/MaqlEditor/hooks/useValueCallbacks.d.ts +0 -6
  112. package/esm/MaqlEditor/hooks/useValueCallbacks.d.ts.map +0 -1
  113. package/esm/MaqlEditor/hooks/useValueCallbacks.js +0 -14
  114. package/esm/MaqlEditor/maql/formatter.d.ts +0 -6
  115. package/esm/MaqlEditor/maql/formatter.d.ts.map +0 -1
  116. package/esm/MaqlEditor/maql/formatter.js +0 -14
  117. package/esm/MaqlEditor/maql/hooks/hover/useHoverEvent.d.ts +0 -4
  118. package/esm/MaqlEditor/maql/hooks/hover/useHoverEvent.d.ts.map +0 -1
  119. package/esm/MaqlEditor/maql/hooks/hover/useHoverEvent.js +0 -32
  120. package/esm/MaqlEditor/maql/hooks/useAutocomplete.d.ts +0 -4
  121. package/esm/MaqlEditor/maql/hooks/useAutocomplete.d.ts.map +0 -1
  122. package/esm/MaqlEditor/maql/hooks/useAutocomplete.js +0 -60
  123. package/esm/MaqlEditor/maql/hooks/useDecoration.d.ts +0 -4
  124. package/esm/MaqlEditor/maql/hooks/useDecoration.d.ts.map +0 -1
  125. package/esm/MaqlEditor/maql/hooks/useDecoration.js +0 -73
  126. package/esm/MaqlEditor/maql/hooks/useDocumentFormatting.d.ts +0 -3
  127. package/esm/MaqlEditor/maql/hooks/useDocumentFormatting.d.ts.map +0 -1
  128. package/esm/MaqlEditor/maql/hooks/useDocumentFormatting.js +0 -29
  129. package/esm/MaqlEditor/maql/hooks/useHover.d.ts +0 -6
  130. package/esm/MaqlEditor/maql/hooks/useHover.d.ts.map +0 -1
  131. package/esm/MaqlEditor/maql/hooks/useHover.js +0 -77
  132. package/esm/MaqlEditor/maql/hooks/useLanguageConfiguration.d.ts +0 -4
  133. package/esm/MaqlEditor/maql/hooks/useLanguageConfiguration.d.ts.map +0 -1
  134. package/esm/MaqlEditor/maql/hooks/useLanguageConfiguration.js +0 -21
  135. package/esm/MaqlEditor/maql/hooks/useMonaco.d.ts +0 -21
  136. package/esm/MaqlEditor/maql/hooks/useMonaco.d.ts.map +0 -1
  137. package/esm/MaqlEditor/maql/hooks/useMonaco.js +0 -75
  138. package/esm/MaqlEditor/maql/hooks/useSemanticHighlight.d.ts +0 -4
  139. package/esm/MaqlEditor/maql/hooks/useSemanticHighlight.d.ts.map +0 -1
  140. package/esm/MaqlEditor/maql/hooks/useSemanticHighlight.js +0 -33
  141. package/esm/MaqlEditor/maql/hooks/useSyntaxHighlight.d.ts +0 -2
  142. package/esm/MaqlEditor/maql/hooks/useSyntaxHighlight.d.ts.map +0 -1
  143. package/esm/MaqlEditor/maql/hooks/useSyntaxHighlight.js +0 -28
  144. package/esm/MaqlEditor/maql/hooks/useValidation.d.ts +0 -4
  145. package/esm/MaqlEditor/maql/hooks/useValidation.d.ts.map +0 -1
  146. package/esm/MaqlEditor/maql/hooks/useValidation.js +0 -56
  147. package/esm/MaqlEditor/maql/monacoConverter.d.ts +0 -80
  148. package/esm/MaqlEditor/maql/monacoConverter.d.ts.map +0 -1
  149. package/esm/MaqlEditor/maql/monacoConverter.js +0 -528
  150. package/esm/MaqlEditor/maql/utils.d.ts +0 -4
  151. package/esm/MaqlEditor/maql/utils.d.ts.map +0 -1
  152. package/esm/MaqlEditor/maql/utils.js +0 -6
  153. package/esm/MaqlEditor/mock/monaco-shim.d.ts +0 -5
  154. package/esm/MaqlEditor/mock/monaco-shim.d.ts.map +0 -1
  155. package/esm/MaqlEditor/monaco/MonacoEditor.d.ts +0 -64
  156. package/esm/MaqlEditor/monaco/MonacoEditor.d.ts.map +0 -1
  157. package/esm/MaqlEditor/monaco/MonacoEditor.js +0 -71
  158. package/esm/MaqlEditor/monaco/MonacoEditor.styles.d.ts +0 -53
  159. package/esm/MaqlEditor/monaco/MonacoEditor.styles.d.ts.map +0 -1
  160. package/esm/MaqlEditor/monaco/MonacoEditor.styles.js +0 -427
  161. package/esm/MaqlEditor/monaco/hooks/useAutofocus.d.ts +0 -3
  162. package/esm/MaqlEditor/monaco/hooks/useAutofocus.d.ts.map +0 -1
  163. package/esm/MaqlEditor/monaco/hooks/useDefaultValue.d.ts +0 -3
  164. package/esm/MaqlEditor/monaco/hooks/useDefaultValue.d.ts.map +0 -1
  165. package/esm/MaqlEditor/monaco/hooks/useDefaultValue.js +0 -14
  166. package/esm/MaqlEditor/monaco/hooks/useEditorInit.d.ts +0 -3
  167. package/esm/MaqlEditor/monaco/hooks/useEditorInit.d.ts.map +0 -1
  168. package/esm/MaqlEditor/monaco/hooks/useEditorInit.js +0 -84
  169. package/esm/MaqlEditor/monaco/hooks/useEditorOptions.d.ts +0 -3
  170. package/esm/MaqlEditor/monaco/hooks/useEditorOptions.d.ts.map +0 -1
  171. package/esm/MaqlEditor/monaco/hooks/useEditorOptions.js +0 -51
  172. package/esm/MaqlEditor/monaco/hooks/useMonaco.d.ts +0 -3
  173. package/esm/MaqlEditor/monaco/hooks/useMonaco.d.ts.map +0 -1
  174. package/esm/MaqlEditor/monaco/hooks/useMonaco.js +0 -24
  175. package/esm/MaqlEditor/monaco/monacoContributions.d.ts +0 -74
  176. package/esm/MaqlEditor/monaco/monacoContributions.d.ts.map +0 -1
  177. package/esm/MaqlEditor/monaco/monacoContributions.js +0 -88
  178. package/esm/MaqlEditor/monaco/monacoWorkers.d.ts +0 -53
  179. package/esm/MaqlEditor/monaco/monacoWorkers.d.ts.map +0 -1
  180. package/esm/MaqlEditor/monaco/monacoWorkers.js +0 -176
  181. package/esm/MaqlEditor/sql/hooks/useDocumentFormatting.d.ts +0 -2
  182. package/esm/MaqlEditor/sql/hooks/useDocumentFormatting.d.ts.map +0 -1
  183. package/esm/MaqlEditor/sql/hooks/useDocumentFormatting.js +0 -26
  184. package/esm/MaqlEditor/sql/hooks/useLanguageConfiguration.d.ts +0 -4
  185. package/esm/MaqlEditor/sql/hooks/useLanguageConfiguration.d.ts.map +0 -1
  186. package/esm/MaqlEditor/sql/hooks/useLanguageConfiguration.js +0 -29
  187. package/esm/MaqlEditor/sql/hooks/useMonaco.d.ts +0 -14
  188. package/esm/MaqlEditor/sql/hooks/useMonaco.d.ts.map +0 -1
  189. package/esm/MaqlEditor/sql/hooks/useMonaco.js +0 -26
  190. package/esm/MaqlEditor/sql/hooks/useSyntaxHighlight.d.ts +0 -2
  191. package/esm/MaqlEditor/sql/hooks/useSyntaxHighlight.d.ts.map +0 -1
  192. package/esm/MaqlEditor/sql/hooks/useSyntaxHighlight.js +0 -796
  193. package/esm/MaqlEditor/sql/utils.d.ts +0 -4
  194. package/esm/MaqlEditor/sql/utils.d.ts.map +0 -1
  195. package/esm/MaqlEditor/sql/utils.js +0 -6
  196. package/worker/monaco-editor-worker.js +0 -33
  197. package/worker/monaco-editor-worker.source.js +0 -1
@@ -0,0 +1,52 @@
1
+ import { type Ref } from "react";
2
+ import { type Extension } from "@codemirror/state";
3
+ import { EditorView } from "@codemirror/view";
4
+ import { type IMaqlCodeTheme } from "../hooks/useCodeTheme.js";
5
+ import { type IMaqlEditorIcons } from "./CodeEditor.styles.js";
6
+ import { type IContextMenuItem } from "./ContextMenu.js";
7
+ export interface ICodeEditorProps {
8
+ inline?: boolean;
9
+ readonly?: boolean;
10
+ autofocus?: boolean;
11
+ lineNumbers?: boolean;
12
+ className?: string;
13
+ defaultValue?: string;
14
+ icons?: IMaqlEditorIcons;
15
+ codeTheme?: IMaqlCodeTheme;
16
+ /**
17
+ * The accessible name of the editor, read to screen-reader users in place of the code.
18
+ */
19
+ ariaLabel?: string;
20
+ /**
21
+ * Language and behaviour of the editor. A new array reconfigures the running editor.
22
+ */
23
+ extensions?: Extension;
24
+ /**
25
+ * The actions of the context menu. Without them, the browser's own menu opens.
26
+ */
27
+ contextMenu?: IContextMenuItem[];
28
+ /**
29
+ * Called once, when the editor is created.
30
+ */
31
+ onEditorMount?: (editor: EditorView) => void;
32
+ /**
33
+ * Called when the editor is created and whenever the callback itself changes.
34
+ */
35
+ onEditorUpdate?: (editor: EditorView) => void;
36
+ ref?: Ref<EditorView | null>;
37
+ }
38
+ export declare const MainClass = "maql-editor";
39
+ export declare const MainClassContent = "maql-editor-content";
40
+ /**
41
+ * The property of the content element (`.cm-content`) that holds the editor view, for tests and
42
+ * tooling that run in the page without the library: `EditorView.findFromDOM` is not available there.
43
+ *
44
+ * @internal
45
+ */
46
+ export declare const EDITOR_VIEW_PROPERTY = "maqlEditorView";
47
+ /**
48
+ * A CodeMirror editor in the frame, theme and lifecycle every editor of this package shares. The
49
+ * language and the behaviour come in through `extensions`.
50
+ */
51
+ export declare const CodeEditor: import("react").ForwardRefExoticComponent<Omit<ICodeEditorProps, "ref"> & import("react").RefAttributes<EditorView | null>>;
52
+ //# sourceMappingURL=CodeEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../src/MaqlEditor/codemirror/CodeEditor.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,GAAG,EAA6E,MAAM,OAAO,CAAC;AAE5G,OAAO,EAA4B,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAI/D,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACjF,OAAO,EAAe,KAAK,gBAAgB,EAAsB,MAAM,kBAAkB,CAAC;AAG1F,MAAM,WAAW,gBAAgB;IAC7B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACjC;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IAC7C;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IAC9C,GAAG,CAAC,EAAE,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;CAChC;AAoBD,eAAO,MAAM,SAAS,gBAAgB,CAAC;AACvC,eAAO,MAAM,gBAAgB,wBAAwB,CAAC;AAEtD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AA4BrD;;;GAGG;AACH,eAAO,MAAM,UAAU,6HAqIrB,CAAC"}
@@ -0,0 +1,170 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // (C) 2021-2026 GoodData Corporation
3
+ import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react";
4
+ import { Compartment, EditorState } from "@codemirror/state";
5
+ import { EditorView } from "@codemirror/view";
6
+ import classNames from "classnames";
7
+ import { makeStyles } from "../theme/styles.js";
8
+ import { baseExtensions, lineNumbersExtension, readOnlyExtension } from "./baseExtensions.js";
9
+ import { CodeEditorStyles } from "./CodeEditor.styles.js";
10
+ import { ContextMenu } from "./ContextMenu.js";
11
+ import { useAutofocus } from "./hooks/useAutofocus.js";
12
+ const useStyles = makeStyles()(() => ({
13
+ editor: {
14
+ display: "flex",
15
+ position: "relative",
16
+ textAlign: "initial",
17
+ width: "100%",
18
+ height: "100%",
19
+ },
20
+ inline: {
21
+ height: "auto",
22
+ },
23
+ content: {
24
+ width: "100%",
25
+ minWidth: 0,
26
+ height: "100%",
27
+ },
28
+ }));
29
+ export const MainClass = "maql-editor";
30
+ export const MainClassContent = "maql-editor-content";
31
+ /**
32
+ * The property of the content element (`.cm-content`) that holds the editor view, for tests and
33
+ * tooling that run in the page without the library: `EditorView.findFromDOM` is not available there.
34
+ *
35
+ * @internal
36
+ */
37
+ export const EDITOR_VIEW_PROPERTY = "maqlEditorView";
38
+ function attachView(content, view) {
39
+ content[EDITOR_VIEW_PROPERTY] = view;
40
+ }
41
+ function ariaLabelExtension(label) {
42
+ return label ? EditorView.contentAttributes.of({ "aria-label": label }) : [];
43
+ }
44
+ function stopHandledKeys(event) {
45
+ if (event.defaultPrevented) {
46
+ event.stopPropagation();
47
+ }
48
+ }
49
+ /**
50
+ * Where the menu opens: under the pointer, or under the cursor when the keyboard asked for it
51
+ * (the Menu key and Shift+F10 come without a pointer position).
52
+ */
53
+ function menuPosition(view, event) {
54
+ if (event.clientX > 0 || event.clientY > 0) {
55
+ return { x: event.clientX, y: event.clientY };
56
+ }
57
+ const cursor = view.coordsAtPos(view.state.selection.main.head);
58
+ return cursor ? { x: cursor.left, y: cursor.bottom } : { x: 0, y: 0 };
59
+ }
60
+ /**
61
+ * A CodeMirror editor in the frame, theme and lifecycle every editor of this package shares. The
62
+ * language and the behaviour come in through `extensions`.
63
+ */
64
+ export const CodeEditor = forwardRef(function CodeEditor({ inline = false, readonly = false, autofocus = false, lineNumbers = !inline, className = "", defaultValue = "", icons, codeTheme, ariaLabel, extensions, contextMenu, onEditorMount, onEditorUpdate, }, ref) {
65
+ const [element, setElement] = useState(null);
66
+ const [uniqueId] = useState(() => `${MainClassContent}-${Math.random().toString(36).slice(2)}`);
67
+ const [editor, setEditor] = useState(null);
68
+ const [menu, setMenu] = useState(null);
69
+ const closeMenu = useCallback(() => setMenu(null), []);
70
+ const menuItems = useRef(contextMenu);
71
+ menuItems.current = contextMenu;
72
+ const compartments = useRef({
73
+ extensions: new Compartment(),
74
+ lineNumbers: new Compartment(),
75
+ readOnly: new Compartment(),
76
+ ariaLabel: new Compartment(),
77
+ }).current;
78
+ const { classes } = useStyles();
79
+ // The props the one-time creation reads, without making it depend on them.
80
+ const initial = useRef({ defaultValue, extensions, lineNumbers, readonly, ariaLabel });
81
+ initial.current = { defaultValue, extensions, lineNumbers, readonly, ariaLabel };
82
+ useEffect(() => {
83
+ if (!element) {
84
+ return undefined;
85
+ }
86
+ const view = new EditorView({
87
+ state: EditorState.create({
88
+ doc: initial.current.defaultValue,
89
+ extensions: [
90
+ baseExtensions(),
91
+ compartments.lineNumbers.of(lineNumbersExtension(initial.current.lineNumbers)),
92
+ compartments.readOnly.of(readOnlyExtension(initial.current.readonly)),
93
+ compartments.ariaLabel.of(ariaLabelExtension(initial.current.ariaLabel)),
94
+ compartments.extensions.of(initial.current.extensions ?? []),
95
+ ],
96
+ }),
97
+ parent: element,
98
+ });
99
+ // CodeMirror prevents the default of the keys it handles but lets them bubble, and the
100
+ // dialog around the editor moves the focus on Tab and closes on Escape, which closes the
101
+ // find panel here. Monaco stopped the keys it handled. The panel sits beside the content,
102
+ // so the whole editor is listened to.
103
+ view.dom.addEventListener("keydown", stopHandledKeys);
104
+ // The browser's menu is stopped before anything else sees the event, anywhere in the
105
+ // editor (the gutter and the panels included), the way Monaco's menu covered it.
106
+ const openMenu = (event) => {
107
+ if (menuItems.current?.length) {
108
+ event.preventDefault();
109
+ event.stopPropagation();
110
+ setMenu(menuPosition(view, event));
111
+ }
112
+ };
113
+ view.dom.addEventListener("contextmenu", openMenu, true);
114
+ attachView(view.contentDOM, view);
115
+ setEditor(view);
116
+ return () => {
117
+ view.dom.removeEventListener("keydown", stopHandledKeys);
118
+ view.dom.removeEventListener("contextmenu", openMenu, true);
119
+ attachView(view.contentDOM, null);
120
+ view.destroy();
121
+ setEditor(null);
122
+ setMenu(null);
123
+ };
124
+ }, [element, compartments]);
125
+ useEffect(() => {
126
+ editor?.dispatch({ effects: compartments.extensions.reconfigure(extensions ?? []) });
127
+ }, [editor, extensions, compartments]);
128
+ useEffect(() => {
129
+ editor?.dispatch({ effects: compartments.ariaLabel.reconfigure(ariaLabelExtension(ariaLabel)) });
130
+ }, [editor, ariaLabel, compartments]);
131
+ useEffect(() => {
132
+ editor?.dispatch({
133
+ effects: compartments.lineNumbers.reconfigure(lineNumbersExtension(lineNumbers)),
134
+ });
135
+ }, [editor, lineNumbers, compartments]);
136
+ useEffect(() => {
137
+ editor?.dispatch({ effects: compartments.readOnly.reconfigure(readOnlyExtension(readonly)) });
138
+ }, [editor, readonly, compartments]);
139
+ useDefaultValue(editor, defaultValue);
140
+ const mountCallback = useRef(onEditorMount);
141
+ mountCallback.current = onEditorMount;
142
+ useEffect(() => {
143
+ if (editor) {
144
+ mountCallback.current?.(editor);
145
+ }
146
+ }, [editor]);
147
+ useEffect(() => {
148
+ if (editor) {
149
+ onEditorUpdate?.(editor);
150
+ }
151
+ }, [editor, onEditorUpdate]);
152
+ useImperativeHandle(ref, () => editor, [editor]);
153
+ useAutofocus(element, editor, autofocus);
154
+ return (_jsxs("section", { id: uniqueId, className: classNames(classes.editor, MainClassContent, inline && classes.inline), children: [_jsx(CodeEditorStyles, { id: uniqueId, icons: icons, codeTheme: codeTheme, inline: inline }), _jsx("div", { ref: setElement, className: classNames(classes.content, MainClass, className) }), menu && editor && contextMenu ? (_jsx(ContextMenu, { editor: editor, items: contextMenu, position: menu, onClose: closeMenu })) : null] }));
155
+ });
156
+ /**
157
+ * Replaces the content when the parent hands in a different value. The parent's own edits come
158
+ * back as the same value, so they do not replace anything.
159
+ */
160
+ function useDefaultValue(editor, defaultValue) {
161
+ useEffect(() => {
162
+ if (!editor) {
163
+ return;
164
+ }
165
+ const current = editor.state.doc.toString();
166
+ if (defaultValue !== current) {
167
+ editor.dispatch({ changes: { from: 0, to: current.length, insert: defaultValue } });
168
+ }
169
+ }, [defaultValue, editor]);
170
+ }
@@ -0,0 +1,95 @@
1
+ import { type IMaqlCodeTheme } from "../hooks/useCodeTheme.js";
2
+ /**
3
+ * @internal
4
+ */
5
+ export interface IMaqlEditorIcon {
6
+ base64: string;
7
+ width?: number;
8
+ height?: number;
9
+ }
10
+ /**
11
+ * @internal
12
+ */
13
+ export interface IMaqlEditorIcons {
14
+ fact?: IMaqlEditorIcon;
15
+ metric?: IMaqlEditorIcon;
16
+ dataset?: IMaqlEditorIcon;
17
+ label?: IMaqlEditorIcon;
18
+ attribute?: IMaqlEditorIcon;
19
+ keyword?: IMaqlEditorIcon;
20
+ function?: IMaqlEditorIcon;
21
+ operator?: IMaqlEditorIcon;
22
+ snippet?: IMaqlEditorIcon;
23
+ value?: IMaqlEditorIcon;
24
+ detail?: IMaqlEditorIcon;
25
+ next?: IMaqlEditorIcon;
26
+ prev?: IMaqlEditorIcon;
27
+ close?: IMaqlEditorIcon;
28
+ }
29
+ export declare const DecoratorHovered = "hovered-decorator";
30
+ export declare const DecoratorClassName = "decorator";
31
+ export declare const DecoratorItemClassName = "decorator-item";
32
+ type Decorators = {
33
+ [key: string]: {
34
+ decoratorItem: Array<string>;
35
+ decorator: Array<string>;
36
+ };
37
+ };
38
+ export declare const DecoratorFact = "fact";
39
+ export declare const DecoratorAttribute = "attribute";
40
+ export declare const DecoratorDateAttribute = "dateAttribute";
41
+ export declare const DecoratorComputedAttribute = "computedAttribute";
42
+ export declare const DecoratorLabel = "label";
43
+ export declare const DecoratorDateLabel = "dateLabel";
44
+ export declare const DecoratorMetric = "metric";
45
+ export declare const DecoratorDataset = "dataset";
46
+ export declare const DecoratorParameter = "parameter";
47
+ export declare const Decorators: Decorators;
48
+ /**
49
+ * Class prefix of the syntax tokens, see maqlLanguage.
50
+ */
51
+ export declare const TOKEN_CLASS_PREFIX = "maql-token-";
52
+ /**
53
+ * Class prefix of the semantic tokens the language service reports, see semanticTokens.
54
+ */
55
+ export declare const SEMANTIC_TOKEN_CLASS_PREFIX = "maql-semantic-";
56
+ /**
57
+ * Class of the completion tooltip, so its styles do not leak into other CodeMirror editors.
58
+ */
59
+ export declare const SUGGEST_CLASS = "maql-suggest";
60
+ /**
61
+ * Class of the widget that shows the diagnostic the user navigated to.
62
+ */
63
+ export declare const DIAGNOSTIC_WIDGET_CLASS = "maql-diagnostic-widget";
64
+ /**
65
+ * Class of the hover tooltip with the language service's markdown.
66
+ */
67
+ export declare const HOVER_CLASS = "maql-hover";
68
+ /**
69
+ * Class of the rendered completion documentation.
70
+ */
71
+ export declare const DOCS_CLASS = "docs";
72
+ /**
73
+ * Class of the documentation pane of a suggestion: the item detail, a close button, the docs.
74
+ */
75
+ export declare const DOCS_PANE_CLASS = "maql-docs";
76
+ /**
77
+ * Class of the `?` button on the selected suggestion that shows and hides the documentation.
78
+ */
79
+ export declare const DOCS_TOGGLE_CLASS = "maql-docs-toggle";
80
+ /**
81
+ * Class on the editor while the documentation of the suggestions is shown.
82
+ */
83
+ export declare const DOCS_OPEN_CLASS = "maql-docs-open";
84
+ /**
85
+ * Class of the type of a suggested object, shown after its label.
86
+ */
87
+ export declare const TYPE_LABEL_CLASS = "maql-suggest-type";
88
+ export declare function CodeEditorStyles({ id, icons, codeTheme, inline, }: {
89
+ id: string;
90
+ icons?: IMaqlEditorIcons;
91
+ codeTheme?: IMaqlCodeTheme;
92
+ inline: boolean;
93
+ }): import("react/jsx-runtime").JSX.Element;
94
+ export {};
95
+ //# sourceMappingURL=CodeEditor.styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeEditor.styles.d.ts","sourceRoot":"","sources":["../../../src/MaqlEditor/codemirror/CodeEditor.styles.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAO/D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,KAAK,CAAC,EAAE,eAAe,CAAC;CAC3B;AAED,eAAO,MAAM,gBAAgB,sBAAsB,CAAC;AACpD,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAC9C,eAAO,MAAM,sBAAsB,mBAAmB,CAAC;AAEvD,KAAK,UAAU,GAAG;IACd,CAAC,GAAG,EAAE,MAAM,GAAG;QACX,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAC7B,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;KAC5B,CAAC;CACL,CAAC;AACF,eAAO,MAAM,aAAa,SAAS,CAAC;AACpC,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAC9C,eAAO,MAAM,sBAAsB,kBAAkB,CAAC;AACtD,eAAO,MAAM,0BAA0B,sBAAsB,CAAC;AAC9D,eAAO,MAAM,cAAc,UAAU,CAAC;AACtC,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAC9C,eAAO,MAAM,eAAe,WAAW,CAAC;AACxC,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAC1C,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAC9C,eAAO,MAAM,UAAU,EAAE,UAyCxB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAChD;;GAEG;AACH,eAAO,MAAM,2BAA2B,mBAAmB,CAAC;AAC5D;;GAEG;AACH,eAAO,MAAM,aAAa,iBAAiB,CAAC;AAC5C;;GAEG;AACH,eAAO,MAAM,uBAAuB,2BAA2B,CAAC;AAChE;;GAEG;AACH,eAAO,MAAM,WAAW,eAAe,CAAC;AACxC;;GAEG;AACH,eAAO,MAAM,UAAU,SAAS,CAAC;AACjC;;GAEG;AACH,eAAO,MAAM,eAAe,cAAc,CAAC;AAC3C;;GAEG;AACH,eAAO,MAAM,iBAAiB,qBAAqB,CAAC;AACpD;;GAEG;AACH,eAAO,MAAM,eAAe,mBAAmB,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,gBAAgB,sBAAsB,CAAC;AAyCpD,wBAAgB,gBAAgB,CAAC,EAC7B,EAAE,EACF,KAAK,EACL,SAAS,EACT,MAAM,GACT,EAAE;IACC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;CACnB,2CAIA"}