Skip to content

Commit

Permalink
feat(editor): Autocomplete info box: improve structure and add exampl…
Browse files Browse the repository at this point in the history
…es (#9019)

Co-authored-by: Giulio Andreini <andreini@netseven.it>
  • Loading branch information
elsmr and gandreini committed May 10, 2024
1 parent 4ed5850 commit c92c870
Show file tree
Hide file tree
Showing 30 changed files with 1,597 additions and 458 deletions.
1 change: 1 addition & 0 deletions cypress/e2e/14-mapping.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ describe('Data mapping', () => {
ndv.actions.mapToParameter('value');

ndv.getters.inlineExpressionEditorInput().should('have.text', '{{ $json.input[0].count }}');
ndv.getters.inlineExpressionEditorInput().type('{esc}');
ndv.getters.parameterExpressionPreview('value').should('include.text', '0');

ndv.getters.inputTbodyCell(1, 0).realHover();
Expand Down
6 changes: 4 additions & 2 deletions packages/design-system/src/css/_primitives.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

--prim-gray-820: hsl(var(--prim-gray-h), 1%, 18%);
--prim-gray-800: hsl(var(--prim-gray-h), 1%, 20%);
--prim-gray-780: hsl(var(--prim-gray-h), 1%, 22%);
--prim-gray-740: hsl(var(--prim-gray-h), 2%, 26%);
--prim-gray-670: hsl(var(--prim-gray-h), 2%, 33%);
--prim-gray-540: hsl(var(--prim-gray-h), 4%, 46%);
Expand All @@ -20,8 +21,9 @@
--prim-gray-70: hsl(var(--prim-gray-h), 32%, 93%);
--prim-gray-70-alpha-01: hsla(var(--prim-gray-h), 32%, 93%, 0.1);
--prim-gray-40: hsl(var(--prim-gray-h), 40%, 96%);
--prim-gray-30: hsl(var(--prim-gray-h), 40%, 97%);
--prim-gray-10: hsl(var(--prim-gray-h), 47%, 99%);
--prim-gray-30: hsl(var(--prim-gray-h), 43%, 97%);
--prim-gray-25: hsl(var(--prim-gray-h), 50%, 97.5%);
--prim-gray-10: hsl(var(--prim-gray-h), 50%, 99%);
--prim-gray-0-alpha-075: hsla(var(--prim-gray-h), 50%, 100%, 0.75);
--prim-gray-0-alpha-025: hsla(var(--prim-gray-h), 50%, 100%, 0.25);
--prim-gray-0: hsl(var(--prim-gray-h), 50%, 100%);
Expand Down
4 changes: 3 additions & 1 deletion packages/design-system/src/css/_tokens.dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
--color-sticky-background-7: var(--prim-gray-740);
--color-sticky-border-7: var(--prim-gray-670);

// Expressions and autocomplete
// Expressions, autocomplete, infobox
--color-valid-resolvable-foreground: var(--prim-color-alt-a-tint-300);
--color-valid-resolvable-background: var(--prim-color-alt-a-alpha-025);
--color-invalid-resolvable-foreground: var(--prim-color-alt-c-tint-250);
Expand All @@ -83,6 +83,8 @@
--color-expression-syntax-example: var(--prim-gray-670);
--color-autocomplete-item-selected: var(--prim-color-secondary-tint-200);
--color-autocomplete-section-header-border: var(--prim-gray-540);
--color-infobox-background: var(--prim-gray-780);
--color-infobox-examples-border-color: var(--prim-gray-670);

// Code
--color-code-tags-string: var(--prim-color-alt-f-tint-150);
Expand Down
5 changes: 4 additions & 1 deletion packages/design-system/src/css/_tokens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
--color-background-dark: var(--prim-gray-820);
--color-background-medium: var(--prim-gray-120);
--color-background-base: var(--prim-gray-40);
--color-background-light-base: var(--prim-gray-25);
--color-background-light: var(--prim-gray-10);
--color-background-xlight: var(--prim-gray-0);

Expand Down Expand Up @@ -105,7 +106,7 @@
--color-sticky-background-7: var(--prim-gray-10);
--color-sticky-border-7: var(--prim-gray-120);

// Expressions and autocomplete
// Expressions, autocomplete, infobox
--color-valid-resolvable-foreground: var(--prim-color-alt-a);
--color-valid-resolvable-background: var(--prim-color-alt-a-tint-500);
--color-invalid-resolvable-foreground: var(--prim-color-alt-c);
Expand All @@ -116,6 +117,8 @@
--color-expression-syntax-example: var(--prim-gray-40);
--color-autocomplete-item-selected: var(--color-secondary);
--color-autocomplete-section-header-border: var(--color-foreground-light);
--color-infobox-background: var(--color-background-light-base);
--color-infobox-examples-border-color: var(--color-foreground-light);

// Code
--color-code-tags-string: var(--prim-color-alt-f);
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/CodeNodeEditor/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const BASE_STYLING = {
fontFamily: "Menlo, Consolas, 'DejaVu Sans Mono', monospace !important",
maxHeight: '400px',
tooltip: {
maxWidth: '300px',
maxWidth: '250px',
lineHeight: '1.3em',
},
diagnosticButton: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ watchDebounced(
<style lang="scss" module>
.tip {
display: flex;
align-items: flex-start;
align-items: center;
gap: var(--spacing-4xs);
line-height: var(--font-line-height-regular);
color: var(--color-text-base);
Expand Down
25 changes: 24 additions & 1 deletion packages/editor-ui/src/composables/useExpressionEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type Ref,
toValue,
watch,
onMounted,
} from 'vue';

import { ensureSyntaxTree } from '@codemirror/language';
Expand All @@ -24,7 +25,7 @@ import {
getResolvableState,
isEmptyExpression,
} from '@/utils/expressions';
import { completionStatus } from '@codemirror/autocomplete';
import { closeCompletion, completionStatus } from '@codemirror/autocomplete';
import {
Compartment,
EditorState,
Expand Down Expand Up @@ -158,6 +159,19 @@ export const useExpressionEditor = ({
debouncedUpdateSegments();
}

function blur() {
if (editor.value) {
editor.value.contentDOM.blur();
closeCompletion(editor.value);
}
}

function blurOnClickOutside(event: MouseEvent) {
if (event.target && !editor.value?.dom.contains(event.target as Node)) {
blur();
}
}

watch(editorRef, () => {
const parent = toValue(editorRef);

Expand All @@ -176,6 +190,10 @@ export const useExpressionEditor = ({
EditorView.focusChangeEffect.of((_, newHasFocus) => {
hasFocus.value = newHasFocus;
selection.value = state.selection.ranges[0];
if (!newHasFocus) {
autocompleteStatus.value = null;
debouncedUpdateSegments();
}
return null;
}),
EditorView.contentAttributes.of({ 'data-gramm': 'false' }), // disable grammarly
Expand Down Expand Up @@ -231,7 +249,12 @@ export const useExpressionEditor = ({
});
});

onMounted(() => {
document.addEventListener('click', blurOnClickOutside);
});

onBeforeUnmount(() => {
document.removeEventListener('click', blurOnClickOutside);
editor.value?.destroy();
});

Expand Down

0 comments on commit c92c870

Please sign in to comment.