@gooddata/sdk-ui-kit 10.27.0-alpha.43 → 10.27.0-alpha.45
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/esm/measureNumberFormat/customFormatDialog/FormatInput.d.ts +8 -0
- package/esm/measureNumberFormat/customFormatDialog/FormatInput.d.ts.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/FormatInput.js +94 -32
- package/esm/measureNumberFormat/customFormatDialog/FormatInput.js.map +1 -1
- package/esm/sdk-ui-kit.d.ts +3 -2
- package/esm/syntaxHighlightingInput/SyntaxHighlightingInput.d.ts +3 -5
- package/esm/syntaxHighlightingInput/SyntaxHighlightingInput.d.ts.map +1 -1
- package/esm/syntaxHighlightingInput/SyntaxHighlightingInput.js +81 -58
- package/esm/syntaxHighlightingInput/SyntaxHighlightingInput.js.map +1 -1
- package/package.json +14 -11
- package/src/@ui/UiMenu/UiMenu.scss +5 -14
- package/styles/css/main.css +24 -550
- package/styles/css/main.css.map +1 -1
- package/styles/css/syntaxHighlightingInput.css +19 -537
- package/styles/css/syntaxHighlightingInput.css.map +1 -1
- package/styles/scss/syntaxHighlightingInput.scss +10 -43
@@ -1,7 +1,15 @@
|
|
1
1
|
import React from "react";
|
2
2
|
import { WrappedComponentProps } from "react-intl";
|
3
3
|
import { ISeparators } from "@gooddata/sdk-ui";
|
4
|
+
import { StreamLanguage } from "@codemirror/language";
|
4
5
|
import { IFormatTemplate } from "../typings.js";
|
6
|
+
type LanguageState = {
|
7
|
+
isInColor: boolean;
|
8
|
+
isInCustomColor: boolean;
|
9
|
+
isInCondition: boolean;
|
10
|
+
isInArithmeticExpression: boolean;
|
11
|
+
};
|
12
|
+
export declare const formattingLanguage: StreamLanguage<LanguageState>;
|
5
13
|
interface IFormatInputOwnProps {
|
6
14
|
format: string;
|
7
15
|
onFormatChange: (format: string) => void;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"FormatInput.d.ts","sourceRoot":"","sources":["../../../src/measureNumberFormat/customFormatDialog/FormatInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAc,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
1
|
+
{"version":3,"file":"FormatInput.d.ts","sourceRoot":"","sources":["../../../src/measureNumberFormat/customFormatDialog/FormatInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAc,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,KAAK,aAAa,GAAG;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;IACvB,wBAAwB,EAAE,OAAO,CAAC;CACrC,CAAC;AAEF,eAAO,MAAM,kBAAkB,+BAwG7B,CAAC;AAIH,UAAU,oBAAoB;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,SAAS,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;CAC9C;AAED,KAAK,iBAAiB,GAAG,oBAAoB,GAAG,qBAAqB,CAAC;AAgCtE,QAAA,MAAM,mBAAmB;;CAA0B,CAAC;AAEpD,eAAe,mBAAmB,CAAC"}
|
@@ -1,39 +1,101 @@
|
|
1
|
-
// (C) 2020-
|
1
|
+
// (C) 2020-2025 GoodData Corporation
|
2
2
|
import React from "react";
|
3
3
|
import { injectIntl } from "react-intl";
|
4
|
+
import { StreamLanguage } from "@codemirror/language";
|
4
5
|
import { FormatTemplatesDropdown } from "./formatTemplatesDropdown/FormatTemplatesDropdown.js";
|
5
6
|
import { SyntaxHighlightingInput } from "../../syntaxHighlightingInput/SyntaxHighlightingInput.js";
|
6
|
-
const
|
7
|
-
|
8
|
-
{
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
14
|
-
{
|
15
|
-
// disabling for legibility
|
16
|
-
// eslint-disable-next-line regexp/prefer-character-class
|
17
|
-
regex: /(<|>|=|>=|<=)(-?)(\d*(\.|,)?\d+|Null)/i,
|
18
|
-
token: ["variable-5", "variable-5", "variable-5"],
|
19
|
-
},
|
20
|
-
{ regex: /\/\/.*/, token: "comment" },
|
21
|
-
{ regex: /\/(?:[^\\]|\\.)*?\//, token: "variable-3" },
|
22
|
-
{ regex: /\/\*/, token: "comment", next: "comment" },
|
23
|
-
{ regex: /[{[(]/, indent: true, token: "variable-brackets" },
|
24
|
-
{ regex: /[}\])]/, dedent: true, token: "variable-brackets" },
|
25
|
-
{ regex: /[a-z$][\w$]*/, token: "variable" },
|
26
|
-
{ regex: /<</, token: "meta", mode: { spec: "xml", end: />>/ } },
|
27
|
-
],
|
28
|
-
comment: [
|
29
|
-
{ regex: /.*?\*\//, token: "comment", next: "start" },
|
30
|
-
{ regex: /.*/, token: "comment" },
|
31
|
-
],
|
32
|
-
meta: {
|
33
|
-
dontIndentStates: ["comment"],
|
34
|
-
lineComment: "//",
|
7
|
+
export const formattingLanguage = StreamLanguage.define({
|
8
|
+
startState() {
|
9
|
+
return {
|
10
|
+
isInColor: false,
|
11
|
+
isInCustomColor: false,
|
12
|
+
isInCondition: false,
|
13
|
+
isInArithmeticExpression: false,
|
14
|
+
};
|
35
15
|
},
|
36
|
-
|
16
|
+
token(stream, state) {
|
17
|
+
// Arithmetic expressions
|
18
|
+
if (state.isInArithmeticExpression ||
|
19
|
+
stream.match(/^\{\{\{(?:\d+(?:\.\d+)?)?\|(?:\d+\.?)?\|[^}]+\}\}\}/, false)) {
|
20
|
+
if (stream.match("{{{")) {
|
21
|
+
state.isInArithmeticExpression = true;
|
22
|
+
return "bracket";
|
23
|
+
}
|
24
|
+
if (stream.match("}}}")) {
|
25
|
+
state.isInArithmeticExpression = false;
|
26
|
+
return "bracket";
|
27
|
+
}
|
28
|
+
if (stream.match(/^(?:\d+(?:\.\d+)?)?\|(?:\d+\.?)?\|/)) {
|
29
|
+
return "variableName";
|
30
|
+
}
|
31
|
+
// For the last section, fall through, as arithmetic expression can contain other tokens
|
32
|
+
}
|
33
|
+
// Colors
|
34
|
+
if (state.isInColor ||
|
35
|
+
stream.match(/^\[(?:black|blue|cyan|green|magenta|red|white|yellow|none)\]/i, false)) {
|
36
|
+
if (stream.match("[")) {
|
37
|
+
state.isInColor = true;
|
38
|
+
return "bracket";
|
39
|
+
}
|
40
|
+
if (stream.match(/^[^\]]+/)) {
|
41
|
+
return "keyword";
|
42
|
+
}
|
43
|
+
if (stream.match("]")) {
|
44
|
+
state.isInColor = false;
|
45
|
+
return "bracket";
|
46
|
+
}
|
47
|
+
}
|
48
|
+
// Custom colors
|
49
|
+
if (state.isInCustomColor ||
|
50
|
+
stream.match(/^\[(?:backgroundColor|color)=#?(?:[a-f0-9]{6}|[a-f0-9]{3})\]/i, false)) {
|
51
|
+
if (stream.match("[")) {
|
52
|
+
state.isInCustomColor = true;
|
53
|
+
return "bracket";
|
54
|
+
}
|
55
|
+
if (stream.match("]")) {
|
56
|
+
state.isInCustomColor = false;
|
57
|
+
return "bracket";
|
58
|
+
}
|
59
|
+
if (stream.match(/^(?:backgroundColor|color)/i)) {
|
60
|
+
return "variableName.special";
|
61
|
+
}
|
62
|
+
if (stream.match(/=/)) {
|
63
|
+
return "bracket";
|
64
|
+
}
|
65
|
+
if (stream.match(/^#?(?:[a-f0-9]{6}|[a-f0-9]{3})/i)) {
|
66
|
+
return "keyword";
|
67
|
+
}
|
68
|
+
}
|
69
|
+
// Condition separator
|
70
|
+
if (stream.match(";")) {
|
71
|
+
return "bracket";
|
72
|
+
}
|
73
|
+
// Explicit conditions
|
74
|
+
if (state.isInCondition || stream.match(/^\[(?:>=|<=|[<>=])-?(?:\d+(?:[.,]\d+)?|Null)\]/i, false)) {
|
75
|
+
if (stream.match("[")) {
|
76
|
+
state.isInCondition = true;
|
77
|
+
return "bracket";
|
78
|
+
}
|
79
|
+
if (stream.match("]")) {
|
80
|
+
state.isInCondition = false;
|
81
|
+
return "bracket";
|
82
|
+
}
|
83
|
+
stream.eat(/^[^\]]/);
|
84
|
+
return "variableName.standard";
|
85
|
+
}
|
86
|
+
// Escaping special characters
|
87
|
+
if (stream.match(/^\\[0#?,.\\[\];]/)) {
|
88
|
+
return "variableName";
|
89
|
+
}
|
90
|
+
// Number formatting
|
91
|
+
if (stream.match(/^[0#?,]+(?:\.[0#?,]*)?/)) {
|
92
|
+
return "string";
|
93
|
+
}
|
94
|
+
stream.next(); // Move the stream forward
|
95
|
+
return "variableName";
|
96
|
+
},
|
97
|
+
});
|
98
|
+
const codeMirrorExtensions = [formattingLanguage];
|
37
99
|
class FormatInput extends React.PureComponent {
|
38
100
|
render() {
|
39
101
|
const { format, onFormatChange, separators, templates, intl } = this.props;
|
@@ -41,7 +103,7 @@ class FormatInput extends React.PureComponent {
|
|
41
103
|
React.createElement("div", { className: "gd-measure-custom-format-dialog-section-title" },
|
42
104
|
React.createElement("span", null, intl.formatMessage({ id: "measureNumberCustomFormatDialog.definition" })),
|
43
105
|
templates ? (React.createElement(FormatTemplatesDropdown, { onChange: onFormatChange, separators: separators, templates: templates })) : null),
|
44
|
-
React.createElement(SyntaxHighlightingInput, { value: format,
|
106
|
+
React.createElement(SyntaxHighlightingInput, { value: format, extensions: codeMirrorExtensions, onChange: this.handleInputChange, className: "s-custom-format-input" })));
|
45
107
|
}
|
46
108
|
handleInputChange = (value) => {
|
47
109
|
this.props.onFormatChange(value);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"FormatInput.js","sourceRoot":"","sources":["../../../src/measureNumberFormat/customFormatDialog/FormatInput.tsx"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAyB,MAAM,YAAY,CAAC;
|
1
|
+
{"version":3,"file":"FormatInput.js","sourceRoot":"","sources":["../../../src/measureNumberFormat/customFormatDialog/FormatInput.tsx"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAyB,MAAM,YAAY,CAAC;AAE/D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sDAAsD,CAAC;AAC/F,OAAO,EAAE,uBAAuB,EAAE,MAAM,0DAA0D,CAAC;AAUnG,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC,MAAM,CAAgB;IACnE,UAAU;QACN,OAAO;YACH,SAAS,EAAE,KAAK;YAChB,eAAe,EAAE,KAAK;YACtB,aAAa,EAAE,KAAK;YACpB,wBAAwB,EAAE,KAAK;SAClC,CAAC;IACN,CAAC;IAED,KAAK,CAAC,MAAM,EAAE,KAAK;QACf,yBAAyB;QACzB,IACI,KAAK,CAAC,wBAAwB;YAC9B,MAAM,CAAC,KAAK,CAAC,qDAAqD,EAAE,KAAK,CAAC,EAC5E,CAAC;YACC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACtB,KAAK,CAAC,wBAAwB,GAAG,IAAI,CAAC;gBACtC,OAAO,SAAS,CAAC;YACrB,CAAC;YACD,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACtB,KAAK,CAAC,wBAAwB,GAAG,KAAK,CAAC;gBACvC,OAAO,SAAS,CAAC;YACrB,CAAC;YACD,IAAI,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,EAAE,CAAC;gBACrD,OAAO,cAAc,CAAC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CAAO,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,4CAA4C,EAAE,CAAC,CAAQ;gBACtF,SAAS,CAAC,CAAC,CAAC,CACT,oBAAC,uBAAuB,IACpB,QAAQ,EAAE,cAAc,EACxB,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,GACtB,CACL,CAAC,CAAC,CAAC,IAAI,CACN;YACN,oBAAC,uBAAuB,IACpB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,oBAAoB,EAChC,QAAQ,EAAE,IAAI,CAAC,iBAAiB,EAChC,SAAS,EAAE,uBAAuB,GACpC,CACA,CACT,CAAC;IACN,CAAC;IAEO,iBAAiB,GAAG,CAAC,KAAa,EAAE,EAAE;QAC1C,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC,CAAC;CACL;AAED,MAAM,mBAAmB,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;AAEpD,eAAe,mBAAmB,CAAC"}
|
package/esm/sdk-ui-kit.d.ts
CHANGED
@@ -16,6 +16,7 @@ import { ColorFormats } from 'tinycolor2';
|
|
16
16
|
import { Component } from 'react';
|
17
17
|
import { CSSProperties } from 'react';
|
18
18
|
import { DebouncedFunc } from 'lodash';
|
19
|
+
import { Extension } from '@codemirror/state';
|
19
20
|
import { GoodDataSdkError } from '@gooddata/sdk-ui';
|
20
21
|
import { IAccessControlAware } from '@gooddata/sdk-model';
|
21
22
|
import { IAccessGrantee } from '@gooddata/sdk-model';
|
@@ -4296,8 +4297,8 @@ export declare interface ISyntaxHighlightingInputProps {
|
|
4296
4297
|
value: string;
|
4297
4298
|
onChange: (value: string) => void;
|
4298
4299
|
onCursor?: (from: number, to: number) => void;
|
4299
|
-
|
4300
|
-
|
4300
|
+
placeholder?: string;
|
4301
|
+
extensions?: Extension[];
|
4301
4302
|
className?: string;
|
4302
4303
|
}
|
4303
4304
|
|
@@ -1,7 +1,5 @@
|
|
1
1
|
import React from "react";
|
2
|
-
import "codemirror/
|
3
|
-
import "codemirror/addon/edit/matchbrackets.js";
|
4
|
-
import "codemirror/addon/display/placeholder.js";
|
2
|
+
import { Extension } from "@codemirror/state";
|
5
3
|
/**
|
6
4
|
* @internal
|
7
5
|
*/
|
@@ -9,8 +7,8 @@ export interface ISyntaxHighlightingInputProps {
|
|
9
7
|
value: string;
|
10
8
|
onChange: (value: string) => void;
|
11
9
|
onCursor?: (from: number, to: number) => void;
|
12
|
-
|
13
|
-
|
10
|
+
placeholder?: string;
|
11
|
+
extensions?: Extension[];
|
14
12
|
className?: string;
|
15
13
|
}
|
16
14
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SyntaxHighlightingInput.d.ts","sourceRoot":"","sources":["../../src/syntaxHighlightingInput/SyntaxHighlightingInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAA4B,MAAM,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"SyntaxHighlightingInput.d.ts","sourceRoot":"","sources":["../../src/syntaxHighlightingInput/SyntaxHighlightingInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAGjD,OAAO,EAAe,SAAS,EAAgC,MAAM,mBAAmB,CAAC;AAmBzF;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,EAAE,CAAC,6BAA6B,CAkF3E,CAAC"}
|
@@ -1,70 +1,93 @@
|
|
1
|
-
// (C) 2020-
|
1
|
+
// (C) 2020-2025 GoodData Corporation
|
2
2
|
import React, { useRef, useEffect } from "react";
|
3
3
|
import cx from "classnames";
|
4
|
-
import
|
5
|
-
|
6
|
-
import "codemirror/
|
7
|
-
|
8
|
-
import "codemirror/
|
9
|
-
//
|
10
|
-
|
11
|
-
|
12
|
-
const
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
22
|
-
return lineIndex < cursorLineIndex ? line.length + CODE_MIRROR_EOL.length : cursorLineCharacterIndex;
|
23
|
-
};
|
24
|
-
return text
|
25
|
-
.split(CODE_MIRROR_EOL)
|
26
|
-
.map(getLineLengthToCursor)
|
27
|
-
.reduce((sum, lineLength) => sum + lineLength, 0);
|
28
|
-
};
|
4
|
+
import { EditorView, keymap, placeholder } from "@codemirror/view";
|
5
|
+
import { EditorState, Transaction, EditorSelection } from "@codemirror/state";
|
6
|
+
import { bracketMatching, syntaxHighlighting, HighlightStyle } from "@codemirror/language";
|
7
|
+
import { tags as t } from "@lezer/highlight";
|
8
|
+
import { defaultKeymap, historyKeymap } from "@codemirror/commands";
|
9
|
+
// Disable autofocus
|
10
|
+
const disableAutofocus = EditorView.contentAttributes.of({ autofocus: "false" });
|
11
|
+
// Custom syntax highlighting
|
12
|
+
const customHighlightStyle = HighlightStyle.define([
|
13
|
+
{ tag: t.punctuation, color: "#94a1ad" },
|
14
|
+
{ tag: t.bracket, color: "#94a1ad" },
|
15
|
+
{ tag: t.variableName, color: "#464e56" },
|
16
|
+
{ tag: t.string, color: "#a11" },
|
17
|
+
{ tag: t.special(t.variableName), color: "#13b1e2", fontWeight: "bold" },
|
18
|
+
{ tag: t.standard(t.variableName), color: "#00c18e", fontWeight: "bold" },
|
19
|
+
{ tag: t.keyword, color: "#ab55a3", fontWeight: "bold" },
|
20
|
+
]);
|
29
21
|
/**
|
30
22
|
* @internal
|
31
23
|
*/
|
32
24
|
export const SyntaxHighlightingInput = (props) => {
|
33
|
-
const { value, onChange, onCursor,
|
34
|
-
const
|
35
|
-
const
|
36
|
-
|
37
|
-
if (onCursor) {
|
38
|
-
const from = editor.getCursor("from");
|
39
|
-
const to = editor.getCursor("to");
|
40
|
-
const currentValue = editor.getValue();
|
41
|
-
onCursor(findCursorIndexAcrossMultipleLines(currentValue, from.line, from.ch), findCursorIndexAcrossMultipleLines(currentValue, to.line, to.ch));
|
42
|
-
}
|
43
|
-
};
|
44
|
-
const handleOnChange = () => {
|
45
|
-
onChange(view.current.getValue());
|
46
|
-
};
|
25
|
+
const { value, onChange, onCursor, placeholder: placeholderText, className, extensions = [] } = props;
|
26
|
+
const editorRef = useRef(null);
|
27
|
+
const viewRef = useRef();
|
28
|
+
// Create the editor only once
|
47
29
|
useEffect(() => {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
30
|
+
if (!editorRef.current) {
|
31
|
+
return undefined;
|
32
|
+
}
|
33
|
+
// Create an extension for handling changes
|
34
|
+
const changeHandler = EditorView.updateListener.of((update) => {
|
35
|
+
if (update.docChanged) {
|
36
|
+
onChange(update.state.doc.toString());
|
37
|
+
}
|
38
|
+
if (onCursor && update.selectionSet) {
|
39
|
+
const range = update.state.selection.main;
|
40
|
+
onCursor(range.from, range.to);
|
41
|
+
}
|
42
|
+
});
|
43
|
+
const view = new EditorView({
|
44
|
+
state: EditorState.create({
|
45
|
+
doc: value,
|
46
|
+
extensions: [
|
47
|
+
bracketMatching(),
|
48
|
+
keymap.of([...defaultKeymap, ...historyKeymap]),
|
49
|
+
syntaxHighlighting(customHighlightStyle),
|
50
|
+
EditorView.lineWrapping,
|
51
|
+
disableAutofocus,
|
52
|
+
changeHandler,
|
53
|
+
placeholderText ? placeholder(placeholderText) : [],
|
54
|
+
...extensions,
|
55
|
+
],
|
56
|
+
}),
|
57
|
+
parent: editorRef.current,
|
54
58
|
});
|
55
|
-
|
56
|
-
view.
|
57
|
-
|
58
|
-
|
59
|
-
view.current.off("cursorActivity", reportCursorPosition);
|
60
|
-
};
|
61
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
62
|
-
}, []);
|
59
|
+
viewRef.current = view;
|
60
|
+
return () => view.destroy();
|
61
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
62
|
+
// Handle external value changes
|
63
63
|
useEffect(() => {
|
64
|
-
const
|
65
|
-
view
|
66
|
-
|
64
|
+
const view = viewRef.current;
|
65
|
+
if (!view)
|
66
|
+
return;
|
67
|
+
const currentValue = view.state.doc.toString();
|
68
|
+
if (currentValue !== value) {
|
69
|
+
const selection = view.state.selection;
|
70
|
+
const hasFocus = view.hasFocus;
|
71
|
+
const newLength = value.length;
|
72
|
+
// Adjust selection to stay within bounds of new content
|
73
|
+
const adjustedSelection = EditorSelection.create(selection.ranges.map((range) => {
|
74
|
+
const from = Math.min(range.from, newLength);
|
75
|
+
const to = Math.min(range.to, newLength);
|
76
|
+
return EditorSelection.range(from, to);
|
77
|
+
}), selection.mainIndex);
|
78
|
+
view.dispatch({
|
79
|
+
changes: { from: 0, to: currentValue.length, insert: value },
|
80
|
+
selection: adjustedSelection,
|
81
|
+
annotations: [
|
82
|
+
// Mark this as a remote change to avoid triggering the change handler
|
83
|
+
Transaction.remote.of(true),
|
84
|
+
],
|
85
|
+
});
|
86
|
+
if (hasFocus) {
|
87
|
+
view.focus();
|
88
|
+
}
|
89
|
+
}
|
67
90
|
}, [value]);
|
68
|
-
return React.createElement("div", { className: cx(className, "gd-input-syntax-highlighting-input"), ref:
|
91
|
+
return React.createElement("div", { className: cx(className, "gd-input-syntax-highlighting-input"), ref: editorRef });
|
69
92
|
};
|
70
93
|
//# sourceMappingURL=SyntaxHighlightingInput.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SyntaxHighlightingInput.js","sourceRoot":"","sources":["../../src/syntaxHighlightingInput/SyntaxHighlightingInput.tsx"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO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GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;gBAC7C,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;gBACzC,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC3C,CAAC,CAAC,EACF,SAAS,CAAC,SAAS,CACtB,CAAC;YAEF,IAAI,CAAC,QAAQ,CAAC;gBACV,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;gBAC5D,SAAS,EAAE,iBAAiB;gBAC5B,WAAW,EAAE;oBACT,sEAAsE;oBACtE,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;iBAC9B;aACJ,CAAC,CAAC;YAEH,IAAI,QAAQ,EAAE,CAAC;gBACX,IAAI,CAAC,KAAK,EAAE,CAAC;YACjB,CAAC;QACL,CAAC;IACL,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,6BAAK,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,oCAAoC,CAAC,EAAE,GAAG,EAAE,SAAS,GAAI,CAAC;AACnG,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gooddata/sdk-ui-kit",
|
3
|
-
"version": "10.27.0-alpha.
|
3
|
+
"version": "10.27.0-alpha.45",
|
4
4
|
"description": "GoodData SDK - UI Building Components",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -41,7 +41,6 @@
|
|
41
41
|
"@gooddata/number-formatter": "^1.0.6",
|
42
42
|
"@tanstack/react-virtual": "^3.11.1",
|
43
43
|
"classnames": "^2.3.1",
|
44
|
-
"codemirror": "^5.54.0",
|
45
44
|
"copy-to-clipboard": "^3.3.1",
|
46
45
|
"cron-parser": "^5.1.1",
|
47
46
|
"date-fns": "^2.22.1",
|
@@ -70,11 +69,16 @@
|
|
70
69
|
"tslib": "^2.5.0",
|
71
70
|
"uuid": "^8.3.2",
|
72
71
|
"unified": "^11.0.5",
|
73
|
-
"@
|
74
|
-
"@
|
75
|
-
"@
|
76
|
-
"@
|
77
|
-
"@
|
72
|
+
"@codemirror/language": "~6.11.0",
|
73
|
+
"@codemirror/state": "~6.5.2",
|
74
|
+
"@codemirror/view": "~6.36.4",
|
75
|
+
"@lezer/highlight": "~1.2.1",
|
76
|
+
"@codemirror/commands": "~6.8.1",
|
77
|
+
"@gooddata/sdk-backend-spi": "10.27.0-alpha.45",
|
78
|
+
"@gooddata/sdk-model": "10.27.0-alpha.45",
|
79
|
+
"@gooddata/sdk-ui": "10.27.0-alpha.45",
|
80
|
+
"@gooddata/sdk-ui-theme-provider": "10.27.0-alpha.45",
|
81
|
+
"@gooddata/util": "10.27.0-alpha.45"
|
78
82
|
},
|
79
83
|
"peerDependencies": {
|
80
84
|
"react": "^16.10.0 || ^17.0.0 || ^18.0.0",
|
@@ -88,7 +92,6 @@
|
|
88
92
|
"@testing-library/dom": "~9.2.0",
|
89
93
|
"@testing-library/react": "^14.0.0",
|
90
94
|
"@testing-library/user-event": "^14.4.2",
|
91
|
-
"@types/codemirror": "^5.60.7",
|
92
95
|
"@types/debounce-promise": "^3.1.4",
|
93
96
|
"@types/kefir": "^3.8.5",
|
94
97
|
"@types/lodash": "^4.14.202",
|
@@ -133,8 +136,8 @@
|
|
133
136
|
"typescript": "5.3.3",
|
134
137
|
"vitest": "3.0.8",
|
135
138
|
"vitest-dom": "0.1.1",
|
136
|
-
"@gooddata/reference-workspace": "10.27.0-alpha.
|
137
|
-
"@gooddata/sdk-backend-mockingbird": "10.27.0-alpha.
|
139
|
+
"@gooddata/reference-workspace": "10.27.0-alpha.45",
|
140
|
+
"@gooddata/sdk-backend-mockingbird": "10.27.0-alpha.45"
|
138
141
|
},
|
139
142
|
"scripts": {
|
140
143
|
"clean": "rm -rf ci dist esm coverage styles/css *.log tsconfig.tsbuildinfo",
|
@@ -158,6 +161,6 @@
|
|
158
161
|
"validate-locales": "cd ../sdk-ui && npm run validate-locales",
|
159
162
|
"validate-locales-ci": "cd ../sdk-ui && npm run validate-locales-ci",
|
160
163
|
"validate-theming": "npm run scss && node scripts/validateCss.js",
|
161
|
-
"scss": "sass --load-path=node_modules --load-path=node_modules/fixed-data-table-2/dist
|
164
|
+
"scss": "sass --load-path=node_modules --load-path=node_modules/fixed-data-table-2/dist styles/scss:styles/css"
|
162
165
|
}
|
163
166
|
}
|
@@ -86,6 +86,11 @@
|
|
86
86
|
margin: 0;
|
87
87
|
padding: 0;
|
88
88
|
outline: none;
|
89
|
+
|
90
|
+
// Focus ring when not controlling by mouse
|
91
|
+
#{$root}:not(#{$root}--controlType-mouse) &:focus-visible #{$root}__item-wrapper--isFocused {
|
92
|
+
@include mixins.focus-ring;
|
93
|
+
}
|
89
94
|
}
|
90
95
|
|
91
96
|
&__item {
|
@@ -104,20 +109,6 @@
|
|
104
109
|
color: variables.$is-focused-color;
|
105
110
|
}
|
106
111
|
|
107
|
-
// Controlled by keyboard and has focus, not disabled
|
108
|
-
#{$root}--controlType-keyboard #{$root}__items:focus &--isFocused:not(&--isDisabled) {
|
109
|
-
background-color: variables.$is-focused-background;
|
110
|
-
color: variables.$is-focused-color;
|
111
|
-
|
112
|
-
@include mixins.focus-ring;
|
113
|
-
}
|
114
|
-
// Controlled by keyboard and has focus, disabled
|
115
|
-
#{$root}--controlType-keyboard #{$root}__items:focus &--isFocused#{&}--isDisabled {
|
116
|
-
background-color: variables.$is-focused-background;
|
117
|
-
|
118
|
-
@include mixins.focus-ring;
|
119
|
-
}
|
120
|
-
|
121
112
|
&--isDisabled {
|
122
113
|
color: variables.$gd-color-disabled;
|
123
114
|
cursor: not-allowed;
|