Skip to content

Commit b9fb751

Browse files
committed
enhance(style-rules): add self-or-* targets
1 parent a029287 commit b9fb751

4 files changed

Lines changed: 52 additions & 14 deletions

File tree

src/lang/style-rules-lang.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ import {
1010
export const styleRulesLang = {
1111
targets: {
1212
self: 'Of card',
13-
'direct-parent': 'Of immediate parent',
13+
'self-or-direct-parent': 'Of card or direct parent',
14+
'self-or-any-parent': 'Of card or any parent',
15+
'self-or-direct-children': 'Of card or direct child',
16+
'self-or-any-children': 'Of card or any child',
17+
'direct-parent': 'Of direct parent',
1418
'any-parent': 'Of any parent',
15-
'direct-children': 'Of immediate child',
19+
'direct-children': 'Of direct child',
1620
'any-children': 'Of any child',
1721
} satisfies Record<StyleRuleTarget, string>,
1822
operators: {

src/stores/settings/types/style-rules-types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export type ComparisonOperator = StringOperator | NumericOperator;
2727

2828
export type StyleRuleTarget =
2929
| 'self'
30+
| 'self-or-any-parent'
31+
| 'self-or-direct-parent'
32+
| 'self-or-direct-children'
33+
| 'self-or-any-children'
3034
| 'direct-parent'
3135
| 'any-parent'
3236
| 'direct-children'

src/stores/view/subscriptions/effects/style-rules/helpers/resolvers/target-node-resolver.ts

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ import {
1010
STRUCTURE_ONLY,
1111
} from 'src/stores/view/helpers/get-document-event-type';
1212

13-
const defaultCache = () => ({
14-
self: {},
15-
'direct-parent': {},
16-
'any-parent': {},
17-
'direct-children': {},
18-
'any-children': {},
19-
});
13+
const defaultCache = () =>
14+
({
15+
self: {},
16+
'direct-parent': {},
17+
'any-parent': {},
18+
'direct-children': {},
19+
'any-children': {},
20+
'self-or-any-parent': {},
21+
'self-or-direct-parent': {},
22+
'self-or-any-children': {},
23+
'self-or-direct-children': {},
24+
}) satisfies Cache;
2025

2126
type Cache = {
2227
[scope in StyleRuleTarget]: {
@@ -63,22 +68,43 @@ export class TargetNodeResolver {
6368
break;
6469
}
6570

66-
case 'any-parent':
71+
case 'self-or-direct-parent': {
72+
const group = findGroupByNodeId(this.columns, nodeId);
73+
result = group ? [group.parentId, nodeId] : [nodeId];
74+
break;
75+
}
76+
77+
case 'any-parent': {
6778
result = traverseUp(this.columns, nodeId);
6879
break;
80+
}
81+
82+
case 'self-or-any-parent': {
83+
result = [...traverseUp(this.columns, nodeId), nodeId];
84+
break;
85+
}
6986

7087
case 'direct-children': {
7188
const childGroup = findChildGroup(this.columns, nodeId);
72-
result = childGroup?.nodes ?? [];
89+
result = childGroup ? childGroup.nodes : [];
7390
break;
7491
}
7592

76-
case 'any-children':
93+
case 'self-or-direct-children': {
94+
const childGroup = findChildGroup(this.columns, nodeId);
95+
result = childGroup ? [nodeId, ...childGroup.nodes] : [nodeId];
96+
break;
97+
}
98+
99+
case 'any-children': {
77100
result = getAllChildren(this.columns, nodeId);
78101
break;
102+
}
79103

80-
default:
81-
result = [];
104+
case 'self-or-any-children': {
105+
result = [nodeId, ...getAllChildren(this.columns, nodeId)];
106+
break;
107+
}
82108
}
83109

84110
this.cacheResult(nodeId, scope, result);

src/view/components/container/style-rules/helpers/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import {
99

1010
export const targets: StyleRuleTarget[] = [
1111
'self',
12+
'self-or-direct-parent',
13+
'self-or-any-parent',
14+
'self-or-direct-children',
15+
'self-or-any-children',
1216
'direct-parent',
1317
'any-parent',
1418
'direct-children',

0 commit comments

Comments
 (0)