@kubex/zinc 1.0.110 → 1.0.112
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/custom-elements.json +105 -74
- package/dist/vscode.html-custom-data.json +12 -11
- package/dist/web-types.json +28 -23
- package/dist/zn.d.ts +25 -0
- package/dist/zn.min.js +285 -283
- package/package.json +1 -1
- package/src/components/button/button.scss +2 -0
- package/src/components/inline-edit/inline-edit.component.ts +14 -6
- package/src/components/select/select.component.ts +3 -28
- package/src/internal/conditional.ts +88 -0
package/package.json
CHANGED
|
@@ -139,6 +139,7 @@
|
|
|
139
139
|
|
|
140
140
|
&:hover:not([disabled]), &:active:not([disabled]) {
|
|
141
141
|
background-color: rgb(var(--btn-color));
|
|
142
|
+
color: white;
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
&.button--secondary {
|
|
@@ -146,6 +147,7 @@
|
|
|
146
147
|
|
|
147
148
|
&:hover:not([disabled]), &:active:not([disabled]) {
|
|
148
149
|
background-color: var(--zn-color-neutral-100);
|
|
150
|
+
color: rgb(var(--btn-color));
|
|
149
151
|
}
|
|
150
152
|
}
|
|
151
153
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { classMap } from "lit/directives/class-map.js";
|
|
2
|
+
import { ConditionalController } from "../../internal/conditional";
|
|
2
3
|
import { type CSSResultGroup, html, type HTMLTemplateResult, type PropertyValues, unsafeCSS } from 'lit';
|
|
3
4
|
import { defaultValue } from "../../internal/default-value";
|
|
4
5
|
import { FormControlController } from "../../internal/form";
|
|
@@ -47,6 +48,7 @@ export default class ZnInlineEdit extends ZincElement implements ZincFormControl
|
|
|
47
48
|
},
|
|
48
49
|
});
|
|
49
50
|
private readonly hasSlotController = new HasSlotController(this, 'help-text', '[default]');
|
|
51
|
+
private readonly conditionalController = new ConditionalController(this);
|
|
50
52
|
|
|
51
53
|
@property() value: string | string[] = '';
|
|
52
54
|
|
|
@@ -56,6 +58,8 @@ export default class ZnInlineEdit extends ZincElement implements ZincFormControl
|
|
|
56
58
|
|
|
57
59
|
@property({ attribute: 'edit-text' }) editText: string;
|
|
58
60
|
|
|
61
|
+
@property() conditional = '';
|
|
62
|
+
|
|
59
63
|
@property({ type: Boolean }) disabled: boolean
|
|
60
64
|
|
|
61
65
|
@property({ type: Boolean }) inline: boolean
|
|
@@ -171,6 +175,7 @@ export default class ZnInlineEdit extends ZincElement implements ZincFormControl
|
|
|
171
175
|
async firstUpdated() {
|
|
172
176
|
await this.updateComplete;
|
|
173
177
|
this.input.addEventListener('onclick', this.handleEditClick);
|
|
178
|
+
this.conditionalController.setup();
|
|
174
179
|
}
|
|
175
180
|
|
|
176
181
|
protected willUpdate(changedProperties: PropertyValues) {
|
|
@@ -195,6 +200,7 @@ export default class ZnInlineEdit extends ZincElement implements ZincFormControl
|
|
|
195
200
|
if (this.input instanceof ZnSelect && !this.isEditing) {
|
|
196
201
|
await this.input.hide();
|
|
197
202
|
}
|
|
203
|
+
this.conditionalController.check();
|
|
198
204
|
}
|
|
199
205
|
|
|
200
206
|
mouseEventHandler = (e: MouseEvent) => {
|
|
@@ -468,16 +474,18 @@ export default class ZnInlineEdit extends ZincElement implements ZincFormControl
|
|
|
468
474
|
protected _getDataSelectInput(): HTMLTemplateResult {
|
|
469
475
|
return html`
|
|
470
476
|
<zn-data-select class="ai__input"
|
|
471
|
-
|
|
472
|
-
|
|
477
|
+
clearable=${ifDefined(this.isEditing ? this.clearable : undefined)}
|
|
478
|
+
dir="${this.dir}"
|
|
473
479
|
icon-position="${ifDefined(this.iconPosition)}"
|
|
474
|
-
|
|
480
|
+
multiple=${ifDefined(this.multiple)}
|
|
481
|
+
name="${this.name}"
|
|
475
482
|
provider="${this.selectProvider}"
|
|
476
|
-
clearable=${ifDefined(this.isEditing ? this.clearable : undefined)}
|
|
477
483
|
required=${ifDefined(this.required)}
|
|
478
|
-
|
|
484
|
+
size="${this.size}"
|
|
485
|
+
value="${this.value}"
|
|
486
|
+
@zn-blur="${this.handleBlur}"
|
|
479
487
|
@zn-input="${this.handleInput}"
|
|
480
|
-
|
|
488
|
+
>
|
|
481
489
|
</zn-data-select>`;
|
|
482
490
|
}
|
|
483
491
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {animateTo, stopAnimations} from '../../internal/animate.js';
|
|
2
2
|
import {classMap} from "lit/directives/class-map.js";
|
|
3
|
-
import {
|
|
3
|
+
import {ConditionalController} from "../../internal/conditional";
|
|
4
4
|
import {FormControlController} from "../../internal/form";
|
|
5
5
|
import {getAnimation, setDefaultAnimation} from "../../utilities/animation-registry";
|
|
6
6
|
import {HasSlotController} from "../../internal/slot";
|
|
@@ -89,6 +89,7 @@ export default class ZnSelect extends ZincElement implements ZincFormControl {
|
|
|
89
89
|
protected readonly formControlController = new FormControlController(this, {
|
|
90
90
|
assumeInteractionOn: ['zn-blur', 'zn-input']
|
|
91
91
|
});
|
|
92
|
+
private readonly conditionalController = new ConditionalController(this);
|
|
92
93
|
private readonly hasSlotController = new HasSlotController(this, 'help-text', 'label');
|
|
93
94
|
private readonly localize = new LocalizeController(this);
|
|
94
95
|
private typeToSelectString = '';
|
|
@@ -1131,33 +1132,7 @@ export default class ZnSelect extends ZincElement implements ZincFormControl {
|
|
|
1131
1132
|
|
|
1132
1133
|
}
|
|
1133
1134
|
|
|
1134
|
-
|
|
1135
|
-
const ids = this.conditional.split(',').map(id => id.trim());
|
|
1136
|
-
const conditionals: ZnSelect[] = [];
|
|
1137
|
-
|
|
1138
|
-
ids.forEach(id => {
|
|
1139
|
-
const elements = deepQuerySelectorAll(`#${id}`, document.documentElement, '') as ZnSelect[];
|
|
1140
|
-
conditionals.push(...elements);
|
|
1141
|
-
});
|
|
1142
|
-
|
|
1143
|
-
const initiallyDisabled = this.disabled;
|
|
1144
|
-
const checkConditionals = () => {
|
|
1145
|
-
const shouldDisable = conditionals.some(select => {
|
|
1146
|
-
let linkedValues = Array.isArray(select.value) ? select.value : [select.value];
|
|
1147
|
-
linkedValues = linkedValues.filter(v => v !== '');
|
|
1148
|
-
return linkedValues.length > 0;
|
|
1149
|
-
});
|
|
1150
|
-
this.disabled = initiallyDisabled || shouldDisable;
|
|
1151
|
-
};
|
|
1152
|
-
|
|
1153
|
-
conditionals.forEach(select => {
|
|
1154
|
-
select.addEventListener('zn-change', checkConditionals);
|
|
1155
|
-
select.addEventListener('zn-input', checkConditionals);
|
|
1156
|
-
});
|
|
1157
|
-
|
|
1158
|
-
// trigger the check once to initialize
|
|
1159
|
-
checkConditionals();
|
|
1160
|
-
}
|
|
1135
|
+
this.conditionalController.setup();
|
|
1161
1136
|
|
|
1162
1137
|
if (this.dataUri && !this.searchOnly) {
|
|
1163
1138
|
this.fetchOptions().then();
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {deepQuerySelectorAll} from '../utilities/query';
|
|
2
|
+
import type {ReactiveController, ReactiveControllerHost} from 'lit';
|
|
3
|
+
|
|
4
|
+
export interface ConditionalHost {
|
|
5
|
+
conditional: string;
|
|
6
|
+
disabled: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** A reactive controller that disables the host when linked selects have a value. */
|
|
10
|
+
export class ConditionalController implements ReactiveController {
|
|
11
|
+
host: ReactiveControllerHost & Element & ConditionalHost;
|
|
12
|
+
private conditionals: (Element & { value: string | string[] })[] = [];
|
|
13
|
+
private initiallyDisabled = false;
|
|
14
|
+
private readonly handleChange = () => this.checkConditionals();
|
|
15
|
+
|
|
16
|
+
constructor(host: ReactiveControllerHost & Element & ConditionalHost) {
|
|
17
|
+
(this.host = host).addController(this);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Call from the host's `firstUpdated()` to parse IDs, find elements, attach listeners, and run the initial check. */
|
|
21
|
+
setup() {
|
|
22
|
+
if (this.host.conditional === '') {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const ids = this.host.conditional.split(',').map(id => id.trim());
|
|
27
|
+
|
|
28
|
+
ids.forEach(id => {
|
|
29
|
+
const byId = deepQuerySelectorAll(`#${id}`, document.documentElement, '') as (Element & {
|
|
30
|
+
value: string | string[];
|
|
31
|
+
})[];
|
|
32
|
+
const byName = deepQuerySelectorAll(`[name="${id}"]`, document.documentElement, '') as (Element & {
|
|
33
|
+
value: string | string[];
|
|
34
|
+
})[];
|
|
35
|
+
|
|
36
|
+
// de-duplicate in case the same element matches both id and name
|
|
37
|
+
const seen = new Set<Element>();
|
|
38
|
+
[...byId, ...byName].forEach(el => {
|
|
39
|
+
if (!seen.has(el)) {
|
|
40
|
+
seen.add(el);
|
|
41
|
+
this.conditionals.push(el);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
this.initiallyDisabled = this.host.disabled;
|
|
47
|
+
|
|
48
|
+
if (ids.length === 0) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.conditionals.forEach(select => {
|
|
53
|
+
select.addEventListener('zn-change', this.handleChange);
|
|
54
|
+
select.addEventListener('zn-input', this.handleChange);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// trigger the check once to initialize
|
|
58
|
+
this.checkConditionals();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
hostConnected() {
|
|
62
|
+
// No-op; setup is deferred to setup() which the host calls from firstUpdated()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
hostDisconnected() {
|
|
66
|
+
this.conditionals.forEach(select => {
|
|
67
|
+
select.removeEventListener('zn-change', this.handleChange);
|
|
68
|
+
// select.removeEventListener('zn-input', this.handleChange);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
this.conditionals = [];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Re-evaluate the conditional state. Call from the host when needed. */
|
|
75
|
+
check() {
|
|
76
|
+
this.checkConditionals();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private checkConditionals() {
|
|
80
|
+
const shouldDisable = this.conditionals.some(select => {
|
|
81
|
+
let linkedValues = Array.isArray(select.value) ? select.value : [select.value];
|
|
82
|
+
linkedValues = linkedValues.filter(v => (v !== '' && v !== "0"));
|
|
83
|
+
return linkedValues.length > 0;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
this.host.disabled = this.initiallyDisabled || shouldDisable;
|
|
87
|
+
}
|
|
88
|
+
}
|