refactored function name
reverted binding logic
This commit is contained in:
parent
3b729bc470
commit
44e657fe12
|
|
@ -17,7 +17,7 @@ import ErrorTooltip from "components/editorComponents/ErrorTooltip";
|
||||||
import HelperTooltip from "components/editorComponents/HelperTooltip";
|
import HelperTooltip from "components/editorComponents/HelperTooltip";
|
||||||
import { WrappedFieldInputProps, WrappedFieldMetaProps } from "redux-form";
|
import { WrappedFieldInputProps, WrappedFieldMetaProps } from "redux-form";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { parseDynamicString } from "utils/DynamicBindingUtils";
|
import { getDynamicStringSegments } from "utils/DynamicBindingUtils";
|
||||||
import { DataTree } from "entities/DataTree/dataTreeFactory";
|
import { DataTree } from "entities/DataTree/dataTreeFactory";
|
||||||
import { Theme } from "constants/DefaultTheme";
|
import { Theme } from "constants/DefaultTheme";
|
||||||
import AnalyticsUtil from "utils/AnalyticsUtil";
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
||||||
|
|
@ -324,6 +324,7 @@ class DynamicAutocompleteInput extends Component<Props, State> {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.editor.on("change", _.debounce(this.handleChange, 300));
|
this.editor.on("change", _.debounce(this.handleChange, 300));
|
||||||
|
this.editor.on("change", this.handleAutocompleteVisibility);
|
||||||
this.editor.on("keyup", this.handleAutocompleteHide);
|
this.editor.on("keyup", this.handleAutocompleteHide);
|
||||||
this.editor.on("focus", this.handleEditorFocus);
|
this.editor.on("focus", this.handleEditorFocus);
|
||||||
this.editor.on("blur", this.handleEditorBlur);
|
this.editor.on("blur", this.handleEditorBlur);
|
||||||
|
|
@ -409,7 +410,6 @@ class DynamicAutocompleteInput extends Component<Props, State> {
|
||||||
globalScope: this.props.dynamicData,
|
globalScope: this.props.dynamicData,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.editor.on("cursorActivity", this.handleAutocompleteVisibility);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleEditorFocus = () => {
|
handleEditorFocus = () => {
|
||||||
|
|
@ -447,20 +447,30 @@ class DynamicAutocompleteInput extends Component<Props, State> {
|
||||||
let cursorBetweenBinding = false;
|
let cursorBetweenBinding = false;
|
||||||
const cursor = this.editor.getCursor();
|
const cursor = this.editor.getCursor();
|
||||||
const value = this.editor.getValue();
|
const value = this.editor.getValue();
|
||||||
|
let cursorIndex = cursor.ch;
|
||||||
|
if (cursor.line > 0) {
|
||||||
|
for (let lineIndex = 0; lineIndex < cursor.line; lineIndex++) {
|
||||||
|
const line = this.editor.getLine(lineIndex);
|
||||||
|
// Add line length + 1 for new line character
|
||||||
|
cursorIndex = cursorIndex + line.length + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const stringSegments = getDynamicStringSegments(value);
|
||||||
|
// count of chars processed
|
||||||
let cumulativeCharCount = 0;
|
let cumulativeCharCount = 0;
|
||||||
parseDynamicString(value).forEach(segment => {
|
stringSegments.forEach((segment: string) => {
|
||||||
const start = cumulativeCharCount;
|
const start = cumulativeCharCount;
|
||||||
const dynamicStart = segment.indexOf("{{");
|
const dynamicStart = segment.indexOf("{{");
|
||||||
const dynamicDoesStart = dynamicStart > -1;
|
const dynamicDoesStart = dynamicStart > -1;
|
||||||
const dynamicEnd = segment.indexOf("}}");
|
const dynamicEnd = segment.indexOf("}}");
|
||||||
const dynamicDoesEnd = dynamicEnd > -1;
|
const dynamicDoesEnd = dynamicEnd > -1;
|
||||||
const dynamicStartIndex = dynamicStart + start + 1;
|
const dynamicStartIndex = dynamicStart + start + 2;
|
||||||
const dynamicEndIndex = dynamicEnd + start + 1;
|
const dynamicEndIndex = dynamicEnd + start;
|
||||||
if (
|
if (
|
||||||
dynamicDoesStart &&
|
dynamicDoesStart &&
|
||||||
cursor.ch > dynamicStartIndex &&
|
cursorIndex >= dynamicStartIndex &&
|
||||||
((dynamicDoesEnd && cursor.ch < dynamicEndIndex) ||
|
((dynamicDoesEnd && cursorIndex <= dynamicEndIndex) ||
|
||||||
(!dynamicDoesEnd && cursor.ch > dynamicStartIndex))
|
(!dynamicDoesEnd && cursorIndex >= dynamicStartIndex))
|
||||||
) {
|
) {
|
||||||
cursorBetweenBinding = true;
|
cursorBetweenBinding = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,15 +31,15 @@ export const isDynamicValue = (value: string): boolean =>
|
||||||
DATA_BIND_REGEX.test(value);
|
DATA_BIND_REGEX.test(value);
|
||||||
|
|
||||||
//{{}}{{}}}
|
//{{}}{{}}}
|
||||||
export function parseDynamicString(dynamicString: string): string[] {
|
export function getDynamicStringSegments(dynamicString: string): string[] {
|
||||||
let parsedDynamicValues = [];
|
let stringSegments = [];
|
||||||
const indexOfDoubleParanStart = dynamicString.indexOf("{{");
|
const indexOfDoubleParanStart = dynamicString.indexOf("{{");
|
||||||
if (indexOfDoubleParanStart === -1) {
|
if (indexOfDoubleParanStart === -1) {
|
||||||
return [dynamicString];
|
return [dynamicString];
|
||||||
}
|
}
|
||||||
//{{}}{{}}}
|
//{{}}{{}}}
|
||||||
const firstString = dynamicString.substring(0, indexOfDoubleParanStart);
|
const firstString = dynamicString.substring(0, indexOfDoubleParanStart);
|
||||||
firstString && parsedDynamicValues.push(firstString);
|
firstString && stringSegments.push(firstString);
|
||||||
let rest = dynamicString.substring(
|
let rest = dynamicString.substring(
|
||||||
indexOfDoubleParanStart,
|
indexOfDoubleParanStart,
|
||||||
dynamicString.length,
|
dynamicString.length,
|
||||||
|
|
@ -55,11 +55,11 @@ export function parseDynamicString(dynamicString: string): string[] {
|
||||||
} else if (char === "}") {
|
} else if (char === "}") {
|
||||||
sum--;
|
sum--;
|
||||||
if (prevChar === "}" && sum === 0) {
|
if (prevChar === "}" && sum === 0) {
|
||||||
parsedDynamicValues.push(rest.substring(0, i + 1));
|
stringSegments.push(rest.substring(0, i + 1));
|
||||||
rest = rest.substring(i + 1, rest.length);
|
rest = rest.substring(i + 1, rest.length);
|
||||||
if (rest) {
|
if (rest) {
|
||||||
parsedDynamicValues = parsedDynamicValues.concat(
|
stringSegments = stringSegments.concat(
|
||||||
parseDynamicString(rest),
|
getDynamicStringSegments(rest),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +69,7 @@ export function parseDynamicString(dynamicString: string): string[] {
|
||||||
if (sum !== 0 && dynamicString !== "") {
|
if (sum !== 0 && dynamicString !== "") {
|
||||||
return [dynamicString];
|
return [dynamicString];
|
||||||
}
|
}
|
||||||
return parsedDynamicValues;
|
return stringSegments;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getAllPaths = (
|
const getAllPaths = (
|
||||||
|
|
@ -95,24 +95,24 @@ const getAllPaths = (
|
||||||
|
|
||||||
export const getDynamicBindings = (
|
export const getDynamicBindings = (
|
||||||
dynamicString: string,
|
dynamicString: string,
|
||||||
): { mustaches: string[]; jsSnippets: string[] } => {
|
): { stringSegments: string[]; jsSnippets: string[] } => {
|
||||||
// Protect against bad string parse
|
// Protect against bad string parse
|
||||||
if (!dynamicString || !_.isString(dynamicString)) {
|
if (!dynamicString || !_.isString(dynamicString)) {
|
||||||
return { mustaches: [], jsSnippets: [] };
|
return { stringSegments: [], jsSnippets: [] };
|
||||||
}
|
}
|
||||||
const sanitisedString = dynamicString.trim();
|
const sanitisedString = dynamicString.trim();
|
||||||
// Get the {{binding}} bound values
|
// Get the {{binding}} bound values
|
||||||
const bindings = parseDynamicString(sanitisedString);
|
const stringSegments = getDynamicStringSegments(sanitisedString);
|
||||||
// Get the "binding" path values
|
// Get the "binding" path values
|
||||||
const paths = bindings.map(binding => {
|
const paths = stringSegments.map(segment => {
|
||||||
const length = binding.length;
|
const length = segment.length;
|
||||||
const matches = isDynamicValue(binding);
|
const matches = isDynamicValue(segment);
|
||||||
if (matches) {
|
if (matches) {
|
||||||
return binding.substring(2, length - 2);
|
return segment.substring(2, length - 2);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
});
|
});
|
||||||
return { mustaches: bindings, jsSnippets: paths };
|
return { stringSegments: stringSegments, jsSnippets: paths };
|
||||||
};
|
};
|
||||||
|
|
||||||
// Paths are expected to have "{name}.{path}" signature
|
// Paths are expected to have "{name}.{path}" signature
|
||||||
|
|
@ -162,8 +162,10 @@ export const getDynamicValue = (
|
||||||
includeTriggers = false,
|
includeTriggers = false,
|
||||||
): JSExecutorResult => {
|
): JSExecutorResult => {
|
||||||
// Get the {{binding}} bound values
|
// Get the {{binding}} bound values
|
||||||
const { mustaches, jsSnippets } = getDynamicBindings(dynamicBinding);
|
const { stringSegments: stringSegments, jsSnippets } = getDynamicBindings(
|
||||||
if (mustaches.length) {
|
dynamicBinding,
|
||||||
|
);
|
||||||
|
if (stringSegments.length) {
|
||||||
// Get the Data Tree value of those "binding "paths
|
// Get the Data Tree value of those "binding "paths
|
||||||
const values = jsSnippets.map((jsSnippet, index) => {
|
const values = jsSnippets.map((jsSnippet, index) => {
|
||||||
if (jsSnippet) {
|
if (jsSnippet) {
|
||||||
|
|
@ -174,16 +176,16 @@ export const getDynamicValue = (
|
||||||
return { result: result.result };
|
return { result: result.result };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return { result: mustaches[index], triggers: [] };
|
return { result: stringSegments[index], triggers: [] };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// if it is just one binding, no need to create template string
|
// if it is just one binding, no need to create template string
|
||||||
if (mustaches.length === 1) return values[0];
|
if (stringSegments.length === 1) return values[0];
|
||||||
// else return a string template with bindings
|
// else return a string template with bindings
|
||||||
const templateString = createDynamicValueString(
|
const templateString = createDynamicValueString(
|
||||||
dynamicBinding,
|
dynamicBinding,
|
||||||
mustaches,
|
stringSegments,
|
||||||
values.map(v => v.result),
|
values.map(v => v.result),
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -137,8 +137,11 @@ class TernServer {
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
return a.text.toLowerCase().localeCompare(b.text.toLowerCase());
|
return a.text.toLowerCase().localeCompare(b.text.toLowerCase());
|
||||||
});
|
});
|
||||||
const otherCompletions = completions.filter(c => c.origin !== "dataTree");
|
const docCompletetions = completions.filter(c => c.origin === "[doc]");
|
||||||
return [...dataTreeCompletions, ...otherCompletions];
|
const otherCompletions = completions.filter(
|
||||||
|
c => c.origin !== "dataTree" && c.origin !== "[doc]",
|
||||||
|
);
|
||||||
|
return [...docCompletetions, ...dataTreeCompletions, ...otherCompletions];
|
||||||
}
|
}
|
||||||
|
|
||||||
typeToIcon(type: string) {
|
typeToIcon(type: string) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user