@redvars/peacock 3.11.0 → 3.13.0
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/dist/cb-divider.js +7 -6
- package/dist/cb-divider.js.map +1 -1
- package/dist/cb-group-base-D9gv7SDY.js +114 -0
- package/dist/cb-group-base-D9gv7SDY.js.map +1 -0
- package/dist/cb-group-base-DsX_2aFl.js +325 -0
- package/dist/cb-group-base-DsX_2aFl.js.map +1 -0
- package/dist/cb-group.js +96 -0
- package/dist/cb-group.js.map +1 -0
- package/dist/cb-rule.js +212 -0
- package/dist/cb-rule.js.map +1 -0
- package/dist/condition-builder.js +90 -35
- package/dist/condition-builder.js.map +1 -1
- package/dist/custom-elements-jsdocs.json +176 -96
- package/dist/custom-elements.json +1348 -151
- package/dist/field.js +6 -5
- package/dist/field.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/loader.js +40 -22
- package/dist/loader.js.map +1 -1
- package/dist/src/LoaderUtils.d.ts +10 -2
- package/dist/src/condition-builder/cb-divider.d.ts +3 -1
- package/dist/src/condition-builder/cb-drag.d.ts +10 -0
- package/dist/src/condition-builder/cb-group-base.d.ts +59 -0
- package/dist/src/condition-builder/cb-group.d.ts +34 -0
- package/dist/src/condition-builder/cb-rule.d.ts +32 -0
- package/dist/src/condition-builder/cb-types.d.ts +13 -0
- package/dist/src/condition-builder/condition-builder.d.ts +35 -14
- package/dist/src/condition-builder/index.d.ts +3 -3
- package/dist/src/index.d.ts +2 -1
- package/dist/test/condition-builder.test.d.ts +1 -0
- package/dist/test/loader.test.d.ts +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/readme.md +2 -2
- package/src/LoaderUtils.ts +41 -13
- package/src/condition-builder/cb-divider.scss +4 -5
- package/src/condition-builder/cb-divider.ts +3 -1
- package/src/condition-builder/cb-drag.ts +35 -0
- package/src/condition-builder/cb-group-base.scss +97 -0
- package/src/condition-builder/cb-group-base.ts +335 -0
- package/src/condition-builder/cb-group.scss +21 -0
- package/src/condition-builder/cb-group.ts +72 -0
- package/src/condition-builder/cb-rule.scss +90 -0
- package/src/condition-builder/cb-rule.ts +129 -0
- package/src/condition-builder/cb-types.ts +16 -0
- package/src/condition-builder/condition-builder.scss +12 -9
- package/src/condition-builder/condition-builder.ts +77 -17
- package/src/condition-builder/index.ts +7 -3
- package/src/field/field.scss +11 -6
- package/src/index.ts +7 -3
- package/src/loader.ts +6 -13
- package/dist/cb-compound-expression.js +0 -133
- package/dist/cb-compound-expression.js.map +0 -1
- package/dist/cb-expression.js +0 -78
- package/dist/cb-expression.js.map +0 -1
- package/dist/cb-predicate.js +0 -141
- package/dist/cb-predicate.js.map +0 -1
- package/dist/src/condition-builder/cb-compound-expression.d.ts +0 -30
- package/dist/src/condition-builder/cb-expression.d.ts +0 -30
- package/dist/src/condition-builder/cb-predicate.d.ts +0 -29
- package/src/condition-builder/cb-compound-expression.scss +0 -41
- package/src/condition-builder/cb-compound-expression.ts +0 -79
- package/src/condition-builder/cb-expression.scss +0 -13
- package/src/condition-builder/cb-expression.ts +0 -48
- package/src/condition-builder/cb-predicate.scss +0 -35
- package/src/condition-builder/cb-predicate.ts +0 -101
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
import IndividualComponent from '@/IndividualComponent.js';
|
|
3
|
+
import { CbGroupBase } from './cb-group-base.js';
|
|
4
|
+
import baseStyles from './cb-group-base.scss';
|
|
5
|
+
import styles from './cb-group.scss';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @label CB Group
|
|
9
|
+
* @tag wc-cb-group
|
|
10
|
+
* @rawTag cb-group
|
|
11
|
+
* @summary A bordered, nested group of rules in a condition builder, joined by its own And/Or operator.
|
|
12
|
+
* @overview
|
|
13
|
+
* <p>A bracket on the left joins the group's rules, with a pill to switch between And and Or. Rules can be dragged into, out of and within the group.</p>
|
|
14
|
+
* @tags condition-builder
|
|
15
|
+
*
|
|
16
|
+
* @fires {CustomEvent<{operator: 'and' | 'or'}>} operator-change - Dispatched when the user picks a different operator.
|
|
17
|
+
* @fires {CustomEvent<{rule: CbRule, from: HTMLElement | null, to: HTMLElement, index: number}>} rule-move - Dispatched before a rule is moved into this group. Cancelable: unless prevented, the group moves the rule.
|
|
18
|
+
* @fires {CustomEvent<{group: HTMLElement}>} add-rule - Dispatched when the default "Add condition" link is clicked.
|
|
19
|
+
*
|
|
20
|
+
* @slot - Rules (`wc-cb-rule`) and nested groups.
|
|
21
|
+
* @slot actions - Replaces the default "Add condition" link.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```html
|
|
25
|
+
* <wc-cb-group operator="or">
|
|
26
|
+
* <wc-cb-rule>
|
|
27
|
+
* <wc-input placeholder="Value"></wc-input>
|
|
28
|
+
* </wc-cb-rule>
|
|
29
|
+
* <wc-cb-rule>
|
|
30
|
+
* <wc-input placeholder="Value"></wc-input>
|
|
31
|
+
* </wc-cb-rule>
|
|
32
|
+
* </wc-cb-group>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
@IndividualComponent
|
|
36
|
+
export class CbGroup extends CbGroupBase {
|
|
37
|
+
// ── Static ────────────────────────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
static styles = [baseStyles, styles];
|
|
40
|
+
|
|
41
|
+
// ── Private methods ───────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
private _onAddRuleClick() {
|
|
44
|
+
this.dispatchEvent(
|
|
45
|
+
new CustomEvent<{ group: HTMLElement }>('add-rule', {
|
|
46
|
+
detail: { group: this },
|
|
47
|
+
bubbles: true,
|
|
48
|
+
composed: true,
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ── Render helpers ────────────────────────────────────────────────────────
|
|
54
|
+
|
|
55
|
+
protected override renderFooter() {
|
|
56
|
+
return html`
|
|
57
|
+
<div class="footer">
|
|
58
|
+
<slot name="actions">
|
|
59
|
+
<wc-button
|
|
60
|
+
class="add-condition"
|
|
61
|
+
variant="text"
|
|
62
|
+
size="xs"
|
|
63
|
+
@click=${this._onAddRuleClick}
|
|
64
|
+
>
|
|
65
|
+
<wc-icon slot="icon" name="add"></wc-icon>
|
|
66
|
+
Add condition
|
|
67
|
+
</wc-button>
|
|
68
|
+
</slot>
|
|
69
|
+
</div>
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
@use '../../scss/mixin';
|
|
2
|
+
|
|
3
|
+
@include mixin.base-styles;
|
|
4
|
+
|
|
5
|
+
:host {
|
|
6
|
+
display: block;
|
|
7
|
+
container-type: inline-size;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
:host([dragging]) {
|
|
11
|
+
opacity: 0.4;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.rule {
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: stretch;
|
|
17
|
+
border: 1px solid var(--color-outline-variant);
|
|
18
|
+
border-radius: var(--shape-corner-medium);
|
|
19
|
+
background: var(--color-surface);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.handle {
|
|
23
|
+
position: relative;
|
|
24
|
+
display: flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
justify-content: center;
|
|
27
|
+
flex: none;
|
|
28
|
+
width: 2rem;
|
|
29
|
+
border-inline-end: 1px solid var(--color-outline-variant);
|
|
30
|
+
color: var(--color-on-surface-variant);
|
|
31
|
+
cursor: grab;
|
|
32
|
+
outline: none;
|
|
33
|
+
|
|
34
|
+
&:active {
|
|
35
|
+
cursor: grabbing;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
wc-icon {
|
|
39
|
+
--icon-size: 1.25rem;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
wc-focus-ring {
|
|
43
|
+
--focus-ring-container-shape-start-start: var(--shape-corner-medium);
|
|
44
|
+
--focus-ring-container-shape-end-start: var(--shape-corner-medium);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.content {
|
|
49
|
+
display: flex;
|
|
50
|
+
flex-wrap: wrap;
|
|
51
|
+
align-items: center;
|
|
52
|
+
flex: 1;
|
|
53
|
+
min-width: 0;
|
|
54
|
+
gap: var(--spacing-100) var(--spacing-150);
|
|
55
|
+
padding: var(--spacing-100) var(--spacing-150);
|
|
56
|
+
// Compact the slotted fields (wc-select, wc-input…), which read it from wc-field.
|
|
57
|
+
--field-height: var(--cb-rule-field-height, 2.5rem);
|
|
58
|
+
|
|
59
|
+
::slotted(*) {
|
|
60
|
+
flex: 1 1 8rem;
|
|
61
|
+
min-width: 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
::slotted(:last-child) {
|
|
65
|
+
flex-grow: 1.5;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.remove {
|
|
70
|
+
display: flex;
|
|
71
|
+
align-items: center;
|
|
72
|
+
flex: none;
|
|
73
|
+
padding-inline: var(--spacing-050);
|
|
74
|
+
border-inline-start: 1px solid var(--color-outline-variant);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Narrow rows: give the controls the room.
|
|
78
|
+
@container (max-width: 22rem) {
|
|
79
|
+
.handle {
|
|
80
|
+
width: 1.5rem;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.content {
|
|
84
|
+
padding: var(--spacing-100);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.remove {
|
|
88
|
+
padding-inline: 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { html, LitElement } from 'lit';
|
|
2
|
+
import { query } from 'lit/decorators.js';
|
|
3
|
+
import IndividualComponent from '@/IndividualComponent.js';
|
|
4
|
+
import { claimDropTarget, getActiveRule, setActiveRule } from './cb-drag.js';
|
|
5
|
+
import { CbGroupBase } from './cb-group-base.js';
|
|
6
|
+
import type { CbRuleRemoveDetail } from './cb-types.js';
|
|
7
|
+
import styles from './cb-rule.scss';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @label CB Rule
|
|
11
|
+
* @tag wc-cb-rule
|
|
12
|
+
* @rawTag cb-rule
|
|
13
|
+
* @summary One condition row in a condition builder: a drag handle, the slotted field, operator and value controls, and a remove button.
|
|
14
|
+
* @overview
|
|
15
|
+
* <p>Drag the handle to reorder the rule, or to move it into another group. With the handle focused, ArrowUp and ArrowDown move the rule within its group.</p>
|
|
16
|
+
* @tags condition-builder
|
|
17
|
+
*
|
|
18
|
+
* @cssprop --cb-rule-field-height - Height of the slotted fields (wc-select, wc-input…). Defaults to `2.5rem`.
|
|
19
|
+
*
|
|
20
|
+
* @fires {CustomEvent<{rule: CbRule, group: HTMLElement | null}>} rule-remove - Dispatched when the remove button is clicked. Cancelable: unless prevented, the rule removes itself.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```html
|
|
24
|
+
* <wc-cb-rule>
|
|
25
|
+
* <wc-select placeholder="Field"></wc-select>
|
|
26
|
+
* <wc-select placeholder="Operator"></wc-select>
|
|
27
|
+
* <wc-input placeholder="Value"></wc-input>
|
|
28
|
+
* </wc-cb-rule>
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
@IndividualComponent
|
|
32
|
+
export class CbRule extends LitElement {
|
|
33
|
+
// ── Static ────────────────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
static styles = [styles];
|
|
36
|
+
|
|
37
|
+
// ── Queries ───────────────────────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
@query('.handle')
|
|
40
|
+
private readonly _handleEl?: HTMLElement;
|
|
41
|
+
|
|
42
|
+
// ── Private methods ───────────────────────────────────────────────────────
|
|
43
|
+
|
|
44
|
+
private _onDragStart(event: DragEvent) {
|
|
45
|
+
const { dataTransfer } = event;
|
|
46
|
+
if (dataTransfer) {
|
|
47
|
+
dataTransfer.effectAllowed = 'move';
|
|
48
|
+
// Firefox only starts a drag that carries data.
|
|
49
|
+
dataTransfer.setData('text/plain', '');
|
|
50
|
+
const rect = this.getBoundingClientRect();
|
|
51
|
+
dataTransfer.setDragImage(
|
|
52
|
+
this,
|
|
53
|
+
event.clientX - rect.left,
|
|
54
|
+
event.clientY - rect.top,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
setActiveRule(this);
|
|
58
|
+
// Dim the row after the browser has captured the drag image.
|
|
59
|
+
requestAnimationFrame(() =>
|
|
60
|
+
this.toggleAttribute('dragging', getActiveRule() === this),
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private _onDragEnd() {
|
|
65
|
+
setActiveRule(null);
|
|
66
|
+
claimDropTarget(null);
|
|
67
|
+
this.toggleAttribute('dragging', false);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private _onHandleKeyDown(event: KeyboardEvent) {
|
|
71
|
+
const offsets: Record<string, number> = { ArrowUp: -1, ArrowDown: 1 };
|
|
72
|
+
const offset = offsets[event.key];
|
|
73
|
+
const group = this.parentElement;
|
|
74
|
+
if (!offset || !(group instanceof CbGroupBase)) return;
|
|
75
|
+
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
const index = group.items.indexOf(this) + offset;
|
|
78
|
+
if (index >= 0 && group.moveRule(this, index)) {
|
|
79
|
+
this._handleEl?.focus();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private _onRemoveClick() {
|
|
84
|
+
const event = new CustomEvent<CbRuleRemoveDetail>('rule-remove', {
|
|
85
|
+
detail: { rule: this, group: this.parentElement },
|
|
86
|
+
bubbles: true,
|
|
87
|
+
composed: true,
|
|
88
|
+
cancelable: true,
|
|
89
|
+
});
|
|
90
|
+
if (this.dispatchEvent(event)) this.remove();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ── Render ────────────────────────────────────────────────────────────────
|
|
94
|
+
|
|
95
|
+
render() {
|
|
96
|
+
return html`
|
|
97
|
+
<div class="rule">
|
|
98
|
+
<div
|
|
99
|
+
class="handle"
|
|
100
|
+
role="button"
|
|
101
|
+
tabindex="0"
|
|
102
|
+
draggable="true"
|
|
103
|
+
aria-label="Reorder condition"
|
|
104
|
+
title="Drag to reorder"
|
|
105
|
+
@dragstart=${this._onDragStart}
|
|
106
|
+
@dragend=${this._onDragEnd}
|
|
107
|
+
@keydown=${this._onHandleKeyDown}
|
|
108
|
+
>
|
|
109
|
+
<wc-focus-ring></wc-focus-ring>
|
|
110
|
+
<wc-icon name="drag_indicator" aria-hidden="true"></wc-icon>
|
|
111
|
+
</div>
|
|
112
|
+
<div class="content">
|
|
113
|
+
<slot></slot>
|
|
114
|
+
</div>
|
|
115
|
+
<div class="remove">
|
|
116
|
+
<wc-icon-button
|
|
117
|
+
variant="text"
|
|
118
|
+
color="on-surface"
|
|
119
|
+
size="sm"
|
|
120
|
+
aria-label="Remove condition"
|
|
121
|
+
@click=${this._onRemoveClick}
|
|
122
|
+
>
|
|
123
|
+
<wc-icon name="delete"></wc-icon>
|
|
124
|
+
</wc-icon-button>
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CbGroupBase } from './cb-group-base.js';
|
|
2
|
+
import type { CbRule } from './cb-rule.js';
|
|
3
|
+
|
|
4
|
+
export type CbOperator = 'and' | 'or';
|
|
5
|
+
|
|
6
|
+
export interface CbRuleMoveDetail {
|
|
7
|
+
rule: CbRule;
|
|
8
|
+
from: HTMLElement | null;
|
|
9
|
+
to: CbGroupBase;
|
|
10
|
+
index: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface CbRuleRemoveDetail {
|
|
14
|
+
rule: CbRule;
|
|
15
|
+
group: HTMLElement | null;
|
|
16
|
+
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
:
|
|
6
|
-
|
|
1
|
+
.footer {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-wrap: wrap;
|
|
4
|
+
align-items: center;
|
|
5
|
+
justify-content: space-between;
|
|
6
|
+
gap: var(--spacing-100);
|
|
7
|
+
padding-top: var(--spacing-200);
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
.
|
|
10
|
+
.actions,
|
|
11
|
+
.actions-end {
|
|
10
12
|
display: flex;
|
|
11
|
-
flex-
|
|
12
|
-
|
|
13
|
+
flex-wrap: wrap;
|
|
14
|
+
align-items: center;
|
|
15
|
+
gap: var(--spacing-100);
|
|
13
16
|
}
|
|
@@ -1,37 +1,97 @@
|
|
|
1
|
-
import { html
|
|
1
|
+
import { html } from 'lit';
|
|
2
2
|
import IndividualComponent from '@/IndividualComponent.js';
|
|
3
|
+
import { CbGroupBase } from './cb-group-base.js';
|
|
4
|
+
import baseStyles from './cb-group-base.scss';
|
|
3
5
|
import styles from './condition-builder.scss';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* @label Condition Builder
|
|
7
9
|
* @tag wc-condition-builder
|
|
8
10
|
* @rawTag condition-builder
|
|
9
|
-
* @summary A
|
|
11
|
+
* @summary A query builder for composing filter conditions from rules and nested groups joined by And/Or.
|
|
12
|
+
* @overview
|
|
13
|
+
* <p>The condition builder is the root group of a query. It holds rules (<code>wc-cb-rule</code>) and bordered nested groups (<code>wc-cb-group</code>), each joined by a bracket with an And/Or pill.</p>
|
|
14
|
+
* <ul>
|
|
15
|
+
* <li>Click the pill to switch a group between And and Or.</li>
|
|
16
|
+
* <li>Drag a rule by its handle to reorder it or move it between groups.</li>
|
|
17
|
+
* <li>Removing, moving and switching are built in; adding rules and groups is up to you, since only you know what a new rule contains. Listen for <code>add-rule</code> and <code>add-group</code>.</li>
|
|
18
|
+
* </ul>
|
|
10
19
|
* @tags condition-builder
|
|
11
20
|
*
|
|
21
|
+
* @fires {CustomEvent<{operator: 'and' | 'or'}>} operator-change - Dispatched when the user picks a different operator, on this or a nested group.
|
|
22
|
+
* @fires {CustomEvent<{rule: CbRule, from: HTMLElement | null, to: HTMLElement, index: number}>} rule-move - Dispatched before a rule is moved. Cancelable: unless prevented, the target group moves the rule.
|
|
23
|
+
* @fires {CustomEvent<{rule: CbRule, group: HTMLElement | null}>} rule-remove - Dispatched when a rule's remove button is clicked. Cancelable: unless prevented, the rule removes itself.
|
|
24
|
+
* @fires {CustomEvent<{group: HTMLElement}>} add-rule - Dispatched when "Add rule" (or a nested group's "Add condition") is clicked.
|
|
25
|
+
* @fires {CustomEvent<{group: HTMLElement}>} add-group - Dispatched when "Add inner group" is clicked.
|
|
26
|
+
*
|
|
27
|
+
* @slot - Rules (`wc-cb-rule`) and groups (`wc-cb-group`).
|
|
28
|
+
* @slot actions - Replaces the default "Add rule" and "Add inner group" buttons.
|
|
29
|
+
* @slot actions-end - Actions aligned to the end of the footer, such as a "Run query" button.
|
|
30
|
+
*
|
|
12
31
|
* @example
|
|
13
32
|
* ```html
|
|
14
|
-
* <wc-condition-builder>
|
|
15
|
-
* <wc-cb-
|
|
16
|
-
* <wc-
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
33
|
+
* <wc-condition-builder operator="and">
|
|
34
|
+
* <wc-cb-rule>
|
|
35
|
+
* <wc-input placeholder="Value"></wc-input>
|
|
36
|
+
* </wc-cb-rule>
|
|
37
|
+
* <wc-cb-group operator="or">
|
|
38
|
+
* <wc-cb-rule>
|
|
39
|
+
* <wc-input placeholder="Value"></wc-input>
|
|
40
|
+
* </wc-cb-rule>
|
|
41
|
+
* <wc-cb-rule>
|
|
42
|
+
* <wc-input placeholder="Value"></wc-input>
|
|
43
|
+
* </wc-cb-rule>
|
|
44
|
+
* </wc-cb-group>
|
|
45
|
+
* <wc-button slot="actions-end">Run query</wc-button>
|
|
24
46
|
* </wc-condition-builder>
|
|
25
47
|
* ```
|
|
26
48
|
*/
|
|
27
49
|
@IndividualComponent
|
|
28
|
-
export class ConditionBuilder extends
|
|
29
|
-
|
|
50
|
+
export class ConditionBuilder extends CbGroupBase {
|
|
51
|
+
// ── Static ────────────────────────────────────────────────────────────────
|
|
52
|
+
|
|
53
|
+
static styles = [baseStyles, styles];
|
|
54
|
+
|
|
55
|
+
// ── Private methods ───────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
private _dispatchAdd(type: 'add-rule' | 'add-group') {
|
|
58
|
+
this.dispatchEvent(
|
|
59
|
+
new CustomEvent<{ group: HTMLElement }>(type, {
|
|
60
|
+
detail: { group: this },
|
|
61
|
+
bubbles: true,
|
|
62
|
+
composed: true,
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ── Render helpers ────────────────────────────────────────────────────────
|
|
30
68
|
|
|
31
|
-
|
|
69
|
+
protected override renderFooter() {
|
|
32
70
|
return html`
|
|
33
|
-
<div class="
|
|
34
|
-
<
|
|
71
|
+
<div class="footer">
|
|
72
|
+
<div class="actions">
|
|
73
|
+
<slot name="actions">
|
|
74
|
+
<wc-button
|
|
75
|
+
variant="outlined"
|
|
76
|
+
size="sm"
|
|
77
|
+
@click=${() => this._dispatchAdd('add-rule')}
|
|
78
|
+
>
|
|
79
|
+
<wc-icon slot="icon" name="add_circle"></wc-icon>
|
|
80
|
+
Add rule
|
|
81
|
+
</wc-button>
|
|
82
|
+
<wc-button
|
|
83
|
+
variant="text"
|
|
84
|
+
size="sm"
|
|
85
|
+
@click=${() => this._dispatchAdd('add-group')}
|
|
86
|
+
>
|
|
87
|
+
<wc-icon slot="icon" name="create_new_folder"></wc-icon>
|
|
88
|
+
Add inner group
|
|
89
|
+
</wc-button>
|
|
90
|
+
</slot>
|
|
91
|
+
</div>
|
|
92
|
+
<div class="actions-end">
|
|
93
|
+
<slot name="actions-end"></slot>
|
|
94
|
+
</div>
|
|
35
95
|
</div>
|
|
36
96
|
`;
|
|
37
97
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export { ConditionBuilder } from './condition-builder.js';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export { CbExpression } from './cb-expression.js';
|
|
2
|
+
export { CbGroup } from './cb-group.js';
|
|
3
|
+
export { CbRule } from './cb-rule.js';
|
|
5
4
|
export { CbDivider } from './cb-divider.js';
|
|
5
|
+
export type {
|
|
6
|
+
CbOperator,
|
|
7
|
+
CbRuleMoveDetail,
|
|
8
|
+
CbRuleRemoveDetail,
|
|
9
|
+
} from './cb-types.js';
|
package/src/field/field.scss
CHANGED
|
@@ -95,12 +95,15 @@
|
|
|
95
95
|
display: flex;
|
|
96
96
|
align-items: center;
|
|
97
97
|
flex: 1;
|
|
98
|
+
// Let a narrow field shrink below its content, so the value truncates.
|
|
99
|
+
min-width: 0;
|
|
98
100
|
min-height: var(--field-height, 3.5rem);
|
|
99
101
|
padding-block: var(--field-padding-block);
|
|
100
102
|
z-index: 1;
|
|
101
103
|
|
|
102
104
|
.input-wrapper {
|
|
103
105
|
flex: 1;
|
|
106
|
+
min-width: 0;
|
|
104
107
|
padding-inline: var(--spacing-200);
|
|
105
108
|
position: relative;
|
|
106
109
|
|
|
@@ -232,13 +235,15 @@
|
|
|
232
235
|
cursor: not-allowed;
|
|
233
236
|
}
|
|
234
237
|
|
|
235
|
-
|
|
238
|
+
// A value to read, not a control switched off: the text, label and helper stay at full
|
|
239
|
+
// contrast, in a faint box with a lighter outline (full again on focus).
|
|
240
|
+
&.readonly:not(.disabled) {
|
|
236
241
|
cursor: initial;
|
|
237
|
-
--
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
+
--_container-color: color-mix(in srgb, var(--color-on-surface) 4%, transparent);
|
|
243
|
+
|
|
244
|
+
&:not(.focused) {
|
|
245
|
+
--_outline-opacity: 0.38;
|
|
246
|
+
}
|
|
242
247
|
}
|
|
243
248
|
|
|
244
249
|
&.show-skeleton {
|
package/src/index.ts
CHANGED
|
@@ -96,8 +96,12 @@ export { Flow } from './flow/index.js';
|
|
|
96
96
|
export type { FlowNode, FlowEdge, FlowStrokeVariant } from './flow/index.js';
|
|
97
97
|
export {
|
|
98
98
|
ConditionBuilder,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
CbExpression,
|
|
99
|
+
CbGroup,
|
|
100
|
+
CbRule,
|
|
102
101
|
CbDivider,
|
|
103
102
|
} from './condition-builder/index.js';
|
|
103
|
+
export type {
|
|
104
|
+
CbOperator,
|
|
105
|
+
CbRuleMoveDetail,
|
|
106
|
+
CbRuleRemoveDetail,
|
|
107
|
+
} from './condition-builder/index.js';
|
package/src/loader.ts
CHANGED
|
@@ -432,21 +432,14 @@ const loaderConfig: LoaderConfig = {
|
|
|
432
432
|
},
|
|
433
433
|
'wc-condition-builder': {
|
|
434
434
|
importPath: `${distDirectory}/condition-builder.js`,
|
|
435
|
-
dependencies: [
|
|
436
|
-
'wc-cb-predicate',
|
|
437
|
-
'wc-cb-compound-expression',
|
|
438
|
-
'wc-cb-expression',
|
|
439
|
-
'wc-cb-divider',
|
|
440
|
-
],
|
|
435
|
+
dependencies: ['wc-cb-group', 'wc-cb-rule', 'wc-cb-divider'],
|
|
441
436
|
},
|
|
442
|
-
'wc-cb-
|
|
443
|
-
importPath: `${distDirectory}/cb-
|
|
437
|
+
'wc-cb-group': {
|
|
438
|
+
importPath: `${distDirectory}/cb-group.js`,
|
|
439
|
+
dependencies: ['wc-cb-divider'],
|
|
444
440
|
},
|
|
445
|
-
'wc-cb-
|
|
446
|
-
importPath: `${distDirectory}/cb-
|
|
447
|
-
},
|
|
448
|
-
'wc-cb-expression': {
|
|
449
|
-
importPath: `${distDirectory}/cb-expression.js`,
|
|
441
|
+
'wc-cb-rule': {
|
|
442
|
+
importPath: `${distDirectory}/cb-rule.js`,
|
|
450
443
|
},
|
|
451
444
|
'wc-cb-divider': {
|
|
452
445
|
importPath: `${distDirectory}/cb-divider.js`,
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { i, _ as __decorate, I as IndividualComponent, a as i$1, A, b } from './IndividualComponent-Bdwyrvd6.js';
|
|
2
|
-
import { n } from './property-B49QQ8pS.js';
|
|
3
|
-
|
|
4
|
-
var css_248z = i`* {
|
|
5
|
-
box-sizing: border-box;
|
|
6
|
-
-webkit-tap-highlight-color: transparent;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.screen-reader-only {
|
|
10
|
-
display: none !important;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
[hidden] {
|
|
14
|
-
display: none !important;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
:host {
|
|
18
|
-
display: block;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.compound-expression {
|
|
22
|
-
display: flex;
|
|
23
|
-
padding-top: var(--spacing-200);
|
|
24
|
-
}
|
|
25
|
-
.compound-expression .field-name-container {
|
|
26
|
-
display: flex;
|
|
27
|
-
flex-direction: column;
|
|
28
|
-
padding-top: var(--spacing-100);
|
|
29
|
-
padding-right: var(--spacing-200);
|
|
30
|
-
}
|
|
31
|
-
.compound-expression .field-name-container .field-label {
|
|
32
|
-
font-family: var(--typography-label-medium-font-family);
|
|
33
|
-
font-size: var(--typography-label-medium-font-size);
|
|
34
|
-
font-weight: var(--typography-label-medium-font-weight);
|
|
35
|
-
line-height: var(--typography-label-medium-line-height);
|
|
36
|
-
letter-spacing: var(--typography-label-medium-letter-spacing);
|
|
37
|
-
color: var(--color-on-surface-variant);
|
|
38
|
-
text-align: center;
|
|
39
|
-
}
|
|
40
|
-
.compound-expression .field-name-container .field-compound-type {
|
|
41
|
-
flex: 1;
|
|
42
|
-
padding-bottom: var(--spacing-250);
|
|
43
|
-
}
|
|
44
|
-
.compound-expression .conditions {
|
|
45
|
-
flex: 1;
|
|
46
|
-
display: flex;
|
|
47
|
-
flex-direction: column;
|
|
48
|
-
gap: 1rem;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.slot-end {
|
|
52
|
-
display: block;
|
|
53
|
-
}`;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @label CB Compound Expression
|
|
57
|
-
* @tag wc-cb-compound-expression
|
|
58
|
-
* @rawTag cb-compound-expression
|
|
59
|
-
* @summary A compound expression group in a condition builder that displays a field label, an optional condition operator divider, and slots for child expressions.
|
|
60
|
-
* @tags condition-builder
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```html
|
|
64
|
-
* <wc-cb-compound-expression field-label="Age" condition-operator="or">
|
|
65
|
-
* <wc-cb-expression>
|
|
66
|
-
* <wc-input placeholder="Enter value"></wc-input>
|
|
67
|
-
* </wc-cb-expression>
|
|
68
|
-
* </wc-cb-compound-expression>
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
let CbCompoundExpression = class CbCompoundExpression extends i$1 {
|
|
72
|
-
constructor() {
|
|
73
|
-
super(...arguments);
|
|
74
|
-
/** The field name for the compound expression. */
|
|
75
|
-
this.fieldName = '';
|
|
76
|
-
/** The display label for the field. */
|
|
77
|
-
this.fieldLabel = '';
|
|
78
|
-
}
|
|
79
|
-
updated() {
|
|
80
|
-
this.__adjustSlotEndPadding();
|
|
81
|
-
}
|
|
82
|
-
__adjustSlotEndPadding() {
|
|
83
|
-
const slotEnd = this.renderRoot.querySelector('.slot-end');
|
|
84
|
-
const fieldNameContainer = this.renderRoot.querySelector('.field-name-container');
|
|
85
|
-
if (slotEnd && fieldNameContainer) {
|
|
86
|
-
slotEnd.style.paddingInlineStart =
|
|
87
|
-
fieldNameContainer.getBoundingClientRect().width + 'px';
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
__renderOperatorDivider() {
|
|
91
|
-
if (!this.conditionOperator)
|
|
92
|
-
return A;
|
|
93
|
-
return b `
|
|
94
|
-
<wc-cb-divider connect-end>
|
|
95
|
-
<wc-tag color="yellow" size="sm">${this.conditionOperator}</wc-tag>
|
|
96
|
-
</wc-cb-divider>
|
|
97
|
-
`;
|
|
98
|
-
}
|
|
99
|
-
render() {
|
|
100
|
-
return b `
|
|
101
|
-
<div class="compound-expression" field-name=${this.fieldName}>
|
|
102
|
-
<div class="field-name-container">
|
|
103
|
-
<span class="field-label">${this.fieldLabel}</span>
|
|
104
|
-
<div class="field-compound-type">
|
|
105
|
-
${this.__renderOperatorDivider()}
|
|
106
|
-
</div>
|
|
107
|
-
</div>
|
|
108
|
-
<div class="conditions">
|
|
109
|
-
<slot></slot>
|
|
110
|
-
</div>
|
|
111
|
-
</div>
|
|
112
|
-
<div class="slot-end">
|
|
113
|
-
<slot name="end"></slot>
|
|
114
|
-
</div>
|
|
115
|
-
`;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
CbCompoundExpression.styles = [css_248z];
|
|
119
|
-
__decorate([
|
|
120
|
-
n({ type: String, attribute: 'condition-operator', reflect: true })
|
|
121
|
-
], CbCompoundExpression.prototype, "conditionOperator", void 0);
|
|
122
|
-
__decorate([
|
|
123
|
-
n({ type: String, attribute: 'field-name' })
|
|
124
|
-
], CbCompoundExpression.prototype, "fieldName", void 0);
|
|
125
|
-
__decorate([
|
|
126
|
-
n({ type: String, attribute: 'field-label' })
|
|
127
|
-
], CbCompoundExpression.prototype, "fieldLabel", void 0);
|
|
128
|
-
CbCompoundExpression = __decorate([
|
|
129
|
-
IndividualComponent
|
|
130
|
-
], CbCompoundExpression);
|
|
131
|
-
|
|
132
|
-
export { CbCompoundExpression };
|
|
133
|
-
//# sourceMappingURL=cb-compound-expression.js.map
|