Skip to content

Commit f63563a

Browse files
authored
feat: FormulaInputField expert mode enhancements (baserow#4866)
1 parent 3042c08 commit f63563a

28 files changed

Lines changed: 3372 additions & 1143 deletions

web-frontend/modules/core/assets/scss/components/formula_input_field.scss

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
// Atomic comma style
5252
.formula-input-field__comma,
5353
.formula-input-field__parenthesis {
54-
color: $palette-cyan-800;
54+
color: $palette-cyan-900;
5555
font-weight: 500;
5656
background-color: $palette-cyan-50;
5757
padding: 0 8px;
@@ -65,7 +65,7 @@
6565

6666
// Group parenthesis style
6767
.formula-input-field__group-parenthesis {
68-
color: $palette-purple-800;
68+
color: $palette-purple-900;
6969
font-weight: 500;
7070
background-color: $palette-purple-50;
7171
padding: 0 8px;
@@ -82,56 +82,40 @@
8282
padding-left: 0;
8383
}
8484

85-
// Add margin-right when a function component is followed by another function component
86-
.function-formula-component:has(+ .function-formula-component) {
87-
margin-right: 4px;
88-
}
89-
90-
// Add margin-right when a function component is followed by a group parenthesis
91-
.function-formula-component:has(+ .formula-input-field__group-parenthesis) {
92-
margin-right: 4px;
93-
}
94-
95-
// Add margin-right when a parenthesis is followed by another parenthesis
96-
.formula-input-field__parenthesis:has(+ .formula-input-field__parenthesis) {
97-
margin-right: 4px;
98-
}
99-
100-
// Add margin-right when a parenthesis is followed by a comma
101-
.formula-input-field__parenthesis:has(+ .formula-input-field__comma) {
102-
margin-right: 4px;
103-
}
104-
105-
// Add margin-right when a comma is followed by a function component
106-
.formula-input-field__comma:has(+ .function-formula-component) {
107-
margin-right: 4px;
85+
// Spacing between adjacent formula atoms (closing parens, commas, group parens)
86+
.formula-input-field__parenthesis,
87+
.formula-input-field__comma,
88+
.formula-input-field__group-parenthesis {
89+
&:has(
90+
+ :is(
91+
.function-formula-component,
92+
.formula-input-field__parenthesis,
93+
.formula-input-field__comma,
94+
.formula-input-field__group-parenthesis
95+
)
96+
) {
97+
margin-right: 4px;
98+
}
10899
}
109100

110-
// Add margin-right when a comma is followed by a parenthesis
111-
.formula-input-field__comma:has(+ .formula-input-field__parenthesis) {
101+
// Spacing after function components (but not before their own closing paren)
102+
.function-formula-component:has(
103+
+ :is(.function-formula-component, .formula-input-field__group-parenthesis)
104+
) {
112105
margin-right: 4px;
113106
}
114107

115-
// Add margin-left when a comma is preceded by a function component
108+
// Spacing before commas preceded by function components
116109
.function-formula-component + .formula-input-field__comma {
117110
margin-left: 4px;
118111
}
119112

120-
// Add margin-right when a comma is followed by another comma
121-
.formula-input-field__comma:has(+ .formula-input-field__comma) {
122-
margin-right: 4px;
123-
}
124-
125-
// Add margin-right when a group parenthesis is followed by another group parenthesis
126-
.formula-input-field__group-parenthesis:has(
127-
+ .formula-input-field__group-parenthesis
128-
) {
129-
margin-right: 4px;
130-
}
131-
132-
// Add margin-right when a group parenthesis is followed by a function/operator/comma
133-
.formula-input-field__group-parenthesis:has(+ .function-formula-component),
134-
.formula-input-field__group-parenthesis:has(+ .formula-input-field__comma) {
113+
// Spacing between closing parens and operators, and between operators and functions
114+
:is(
115+
.formula-input-field__parenthesis[data-formula-closing-paren='true'],
116+
.formula-input-field__group-parenthesis[data-group-closing-paren='true']
117+
):has(+ .operator-formula-component),
118+
.operator-formula-component:has(+ .function-formula-component) {
135119
margin-right: 4px;
136120
}
137121

@@ -145,3 +129,18 @@
145129
.formula-input-field__view-full-error {
146130
margin-left: 5px;
147131
}
132+
133+
// Paren match highlight on hover (disabled for no-arg functions)
134+
.formula-input-field__paren-highlight:not([data-no-args='true']) {
135+
&.formula-input-field__parenthesis {
136+
box-shadow: inset 0 0 0 1.5px $palette-cyan-800;
137+
}
138+
139+
&.formula-input-field__group-parenthesis {
140+
box-shadow: inset 0 0 0 1.5px $palette-purple-800;
141+
}
142+
143+
&.function-formula-component .function-formula-component__name {
144+
box-shadow: inset 0 0 0 1.5px $palette-cyan-800;
145+
}
146+
}

web-frontend/modules/core/assets/scss/components/function_formula_component.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
height: 24px;
33
display: inline-block;
44
vertical-align: top;
5+
user-select: none;
6+
caret-color: transparent;
57
}
68

79
.function-formula-component__name {
8-
color: $palette-cyan-800;
10+
color: $palette-cyan-900;
911
font-weight: 500;
1012
background-color: $palette-cyan-50;
1113
padding: 0 8px;
@@ -21,7 +23,7 @@
2123
}
2224

2325
.function-formula-component__parenthesis {
24-
color: $palette-cyan-800;
26+
color: $palette-cyan-900;
2527
font-weight: 500;
2628
background-color: $palette-cyan-50;
2729
padding: 0 8px;

web-frontend/modules/core/assets/scss/components/operator_formula_component.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
display: inline-block;
33
vertical-align: top;
44
white-space: normal;
5-
user-select: none;
65
cursor: default;
6+
user-select: none;
7+
caret-color: transparent;
78
}
89

910
.operator-formula-component__symbol {
10-
color: $palette-green-800;
11+
color: $palette-green-900;
1112
font-weight: 500;
1213
background-color: $palette-green-50;
1314
padding: 0 8px;

web-frontend/modules/core/components/formula/FormulaInputErrorContext.vue

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,43 @@ export default {
2424
type: Object,
2525
required: true,
2626
},
27+
visible: {
28+
type: Boolean,
29+
required: true,
30+
},
31+
target: {
32+
type: Object,
33+
default: null,
34+
validator: (value) => value == null || value instanceof HTMLElement,
35+
},
36+
},
37+
watch: {
38+
visible: {
39+
handler(isVisible) {
40+
if (isVisible) {
41+
this.show(this.target)
42+
} else {
43+
this.hide()
44+
}
45+
},
46+
},
2747
},
2848
methods: {
2949
show(
30-
targetElement,
31-
verticalPosition = 'bottom',
50+
targetElement = null,
51+
verticalPosition = 'top',
3252
horizontalPosition = 'left',
33-
verticalOffset = 0,
34-
horizontalOffset = 0,
35-
width = null
53+
verticalOffset = 10,
54+
horizontalOffset = 0
3655
) {
37-
// Ensure that the context's width is dynamically set
38-
// to the targetElement's width, as it can be variable.
39-
if (width !== null) {
40-
this.$refs.context.$el.style.width = `${width}px`
56+
const el = targetElement ?? this.target
57+
if (!el || !this.$refs.context) {
58+
return
4159
}
60+
const { width } = el.getBoundingClientRect()
61+
this.$refs.context.$el.style.width = `${width}px`
4262
return this.$refs.context.show(
43-
targetElement,
63+
el,
4464
verticalPosition,
4565
horizontalPosition,
4666
verticalOffset,
@@ -49,7 +69,6 @@ export default {
4969
},
5070
hide() {
5171
this.$refs.context.hide()
52-
this.hideTooltip()
5372
},
5473
},
5574
}

0 commit comments

Comments
 (0)