@emuanalytics/flow-rdf-ui 4.4.0 → 5.0.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.
@@ -5,36 +5,142 @@ const styles = css`
5
5
  ${componentStyles}
6
6
 
7
7
  :host {
8
- /*
9
- * These are actually used by tree item, but we define them here so they can more easily be set and all tree items
10
- * stay consistent.
11
- */
12
- --indent-guide-color: var(--flow-ui-color-neutral-200);
13
- --indent-guide-offset: 0;
14
- --indent-guide-style: solid;
15
- --indent-guide-width: 0;
8
+ --default-width: 15rem;
16
9
  --indent-size: var(--flow-ui-spacing-large);
17
-
18
10
  --selected-background-color: var(--flow-ui-color-neutral-100);
19
11
  --selected-marker-color: var(--flow-ui-color-primary-500);
20
12
 
13
+ /* As tall as its rows; given a height (or max-height), it scrolls them itself */
21
14
  display: block;
22
- isolation: isolate;
15
+ position: relative;
16
+ overflow: auto;
17
+ min-height: 0;
18
+ }
23
19
 
24
- /*
25
- * Tree item indentation uses the "em" unit to increment its width on each level, so setting the font size to zero
26
- * here removes the indentation for all the nodes on the first level.
27
- */
28
- font-size: 0;
20
+ :host([size='small']) {
21
+ --indent-size: var(--flow-ui-spacing-medium);
29
22
  }
30
23
 
31
- .tree--multiple {
32
- --selected-background-color: transparent;
33
- --selected-marker-color: transparent;
24
+ .tree {
25
+ position: relative;
26
+ outline: none;
34
27
  }
35
28
 
36
- .tree--small {
37
- --indent-size: var(--flow-ui-spacing-medium);
29
+ /*
30
+ * The rows are positioned, so they give the tree no width. Where its container sizes to its content, the sizer makes
31
+ * the tree --default-width wide: a percentage max-width doesn't count toward that size, but keeps the sizer inside a
32
+ * narrower container.
33
+ */
34
+ .tree__sizer {
35
+ width: var(--default-width);
36
+ max-width: 100%;
37
+ height: 0;
38
+ }
39
+
40
+ .tree__spacer {
41
+ position: relative;
42
+ }
43
+
44
+ /* The space above and below the rendered rows, watched for coming into view */
45
+ .tree__gap {
46
+ position: absolute;
47
+ left: 0;
48
+ right: 0;
49
+ pointer-events: none;
50
+ }
51
+
52
+ .tree__window {
53
+ position: absolute;
54
+ top: 0;
55
+ left: 0;
56
+ right: 0;
57
+ will-change: transform;
58
+ }
59
+
60
+ .tree__row {
61
+ display: flex;
62
+ align-items: center;
63
+ box-sizing: border-box;
64
+ white-space: nowrap;
65
+ overflow: hidden;
66
+ cursor: pointer;
67
+ user-select: none;
68
+ color: var(--flow-ui-color-neutral-900);
69
+ font-family: var(--flow-ui-font-sans);
70
+ font-size: var(--flow-ui-font-size-medium);
71
+ line-height: var(--flow-ui-line-height-dense);
72
+ border-inline-start: solid 3px transparent;
73
+ }
74
+
75
+ .tree--small .tree__row {
76
+ font-size: var(--flow-ui-font-size-small);
77
+ }
78
+
79
+ .tree--large .tree__row {
80
+ font-size: var(--flow-ui-font-size-large);
81
+ }
82
+
83
+ .tree:focus-visible .tree__row--active {
84
+ outline: var(--flow-ui-focus-ring);
85
+ outline-offset: calc(-1 * var(--flow-ui-focus-ring-width, 3px));
86
+ }
87
+
88
+ .tree__row--selected {
89
+ background-color: var(--selected-background-color);
90
+ border-inline-start-color: var(--selected-marker-color);
91
+ }
92
+
93
+ .tree__row--disabled {
94
+ opacity: 0.5;
95
+ cursor: not-allowed;
96
+ }
97
+
98
+ .tree__expand {
99
+ display: flex;
100
+ align-items: center;
101
+ justify-content: center;
102
+ flex-shrink: 0;
103
+ box-sizing: content-box;
104
+ width: 1rem;
105
+ height: 1rem;
106
+ padding: var(--flow-ui-spacing-x-small);
107
+ color: var(--flow-ui-color-neutral-800);
108
+ }
109
+
110
+ .tree__expand--expanded {
111
+ rotate: 90deg;
112
+ }
113
+
114
+ :host(:dir(rtl)) .tree__expand--expanded {
115
+ rotate: -90deg;
116
+ }
117
+
118
+ .tree__checkbox {
119
+ pointer-events: none;
120
+ margin-inline-end: var(--flow-ui-spacing-x-small);
121
+ }
122
+
123
+ /* A row now showing another node: its checkbox jumps to the new state instead of fading from the old one */
124
+ .tree__checkbox--reused::part(control) {
125
+ transition: none;
126
+ }
127
+
128
+ .tree__icon {
129
+ flex-shrink: 0;
130
+ margin-inline-end: var(--flow-ui-spacing-x-small);
131
+ }
132
+
133
+ .tree__label {
134
+ flex: 1 1 auto;
135
+ overflow: hidden;
136
+ text-overflow: ellipsis;
137
+ }
138
+
139
+ .tree__end {
140
+ display: flex;
141
+ align-items: center;
142
+ flex-shrink: 0;
143
+ margin-inline-start: auto;
38
144
  }
39
145
  `;
40
146
 
@@ -1,18 +1,8 @@
1
- import { html } from 'lit';
2
- import { state, property, query } from 'lit/decorators.js';
3
- import { classMap } from 'lit/directives/class-map.js';
4
- import { live } from 'lit/directives/live.js';
5
- import { when } from 'lit/directives/when.js';
6
- import { stopAnimations, animateTo, shimKeyframesHeightAuto } from '../../internal/animate.mjs';
1
+ import { nothing, css } from 'lit';
2
+ import { property } from 'lit/decorators.js';
7
3
  import { boolean } from '../../internal/boolean.mjs';
8
4
  import FlowRdfElement from '../../internal/flow-ui-rdf-element.mjs';
9
5
  import { watch } from '../../internal/watch.mjs';
10
- import { setDefaultAnimation, getAnimation } from '../../utilities/animation-registry.mjs';
11
- import { LocalizeController } from '../../utilities/localize.mjs';
12
- import FlowUiCheckbox from '../checkbox/checkbox.component.mjs';
13
- import FlowUiIcon from '../icon/icon.component.mjs';
14
- import FlowUiProgressRing from '../progress-ring/progress-ring.component.mjs';
15
- import styles from './tree-item.styles.mjs';
16
6
 
17
7
  var __defProp = Object.defineProperty;
18
8
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -25,314 +15,62 @@ var __decorateClass = (decorators, target, key, kind) => {
25
15
  __defProp(target, key, result);
26
16
  return result;
27
17
  };
28
- const _FlowUiTreeItem = class _FlowUiTreeItem extends FlowRdfElement {
18
+ class FlowUiTreeItem extends FlowRdfElement {
29
19
  constructor() {
30
20
  super(...arguments);
31
- this.localize = new LocalizeController(this);
32
- this.indeterminate = false;
33
- this.isLeaf = false;
34
- this.loading = false;
35
- this.selectable = false;
36
21
  this.value = "";
37
22
  this.expanded = false;
38
23
  this.selected = false;
39
24
  this.disabled = false;
40
25
  this.lazy = false;
41
- this.size = "medium";
42
- this.hidden = false;
43
26
  }
44
- /** @internal */
45
- static isTreeItem(node) {
46
- return node instanceof Element && node.getAttribute("role") === "treeitem";
47
- }
48
- connectedCallback() {
49
- super.connectedCallback();
50
- this.expanded = boolean(this.expanded, true);
51
- this.selected = boolean(this.selected, true);
52
- this.disabled = boolean(this.disabled, true);
53
- this.lazy = boolean(this.lazy, true);
54
- this.hidden = boolean(this.hidden, true);
55
- this.setAttribute("role", "treeitem");
56
- this.setAttribute("tabindex", "-1");
57
- if (this.isNestedItem()) {
58
- this.slot = "children";
27
+ willUpdate(changed) {
28
+ for (const name of ["expanded", "selected", "disabled", "lazy"]) {
29
+ if (changed.has(name) && typeof this[name] !== "boolean")
30
+ this[name] = boolean(this[name], true);
59
31
  }
60
32
  }
61
- firstUpdated() {
62
- this.childrenContainer.hidden = !this.expanded;
63
- this.childrenContainer.style.height = this.expanded ? "auto" : "0";
64
- this.isLeaf = !this.lazy && this.getChildrenItems().length === 0;
65
- this.handleExpandedChange();
66
- }
67
33
  handleValueChange() {
68
- if (typeof this.value !== "string") {
69
- this.value = String(this.value);
70
- }
34
+ if (typeof this.value !== "string")
35
+ this.value = String(this.value ?? "");
71
36
  if (this.value.includes(" ")) {
72
- console.error(`Option values cannot include a space. All spaces have been replaced with underscores.`, this);
37
+ console.error("Tree item values cannot include a space. All spaces have been replaced with underscores.", this);
73
38
  this.value = this.value.replace(/ /g, "_");
74
39
  }
75
40
  }
76
- async animateCollapse() {
77
- this.emit("flow-ui-collapse");
78
- await stopAnimations(this.childrenContainer);
79
- const { keyframes, options } = getAnimation(this, "tree-item.collapse", { dir: this.localize.dir() });
80
- await animateTo(
81
- this.childrenContainer,
82
- shimKeyframesHeightAuto(keyframes, this.childrenContainer.scrollHeight),
83
- options
84
- );
85
- this.childrenContainer.hidden = true;
86
- this.emit("flow-ui-after-collapse");
87
- }
88
- // Checks whether the item is nested into an item
89
- isNestedItem() {
90
- const parent = this.parentElement;
91
- return !!parent && _FlowUiTreeItem.isTreeItem(parent);
92
- }
93
- handleChildrenSlotChange() {
94
- this.loading = false;
95
- this.isLeaf = !this.lazy && this.getChildrenItems().length === 0;
96
- }
97
- willUpdate(changedProperties) {
98
- if (changedProperties.has("selected") && !changedProperties.has("indeterminate")) {
99
- this.indeterminate = false;
100
- }
101
- }
102
- async animateExpand() {
103
- this.emit("flow-ui-expand");
104
- await stopAnimations(this.childrenContainer);
105
- this.childrenContainer.hidden = false;
106
- const { keyframes, options } = getAnimation(this, "tree-item.expand", { dir: this.localize.dir() });
107
- await animateTo(
108
- this.childrenContainer,
109
- shimKeyframesHeightAuto(keyframes, this.childrenContainer.scrollHeight),
110
- options
111
- );
112
- this.childrenContainer.style.height = "auto";
113
- this.emit("flow-ui-after-expand");
114
- }
115
- handleLoadingChange() {
116
- this.setAttribute("aria-busy", this.loading ? "true" : "false");
117
- if (!this.loading) {
118
- this.animateExpand();
119
- }
120
- }
121
- handleDisabledChange() {
122
- this.setAttribute("aria-disabled", this.disabled ? "true" : "false");
123
- }
124
- handleSelectedChange() {
125
- this.setAttribute("aria-selected", this.selected ? "true" : "false");
126
- }
127
- handleExpandedChange() {
128
- if (!this.isLeaf) {
129
- this.setAttribute("aria-expanded", this.expanded ? "true" : "false");
130
- } else {
131
- this.removeAttribute("aria-expanded");
132
- }
133
- }
134
- handleExpandAnimation() {
135
- if (this.expanded) {
136
- if (this.lazy) {
137
- this.loading = true;
138
- this.emit("flow-ui-lazy-load");
139
- } else {
140
- this.animateExpand();
141
- }
142
- } else {
143
- this.animateCollapse();
144
- }
145
- }
146
- handleLazyChange() {
147
- this.emit("flow-ui-lazy-change");
148
- }
149
- /** Gets all the nested tree items in this node. */
150
- getChildrenItems({ includeDisabled = true } = {}) {
151
- return this.childrenSlot ? [...this.childrenSlot.assignedElements({ flatten: true })].filter(
152
- (item) => _FlowUiTreeItem.isTreeItem(item) && (includeDisabled || !item.disabled)
153
- ) : [];
154
- }
155
41
  render() {
156
- const isRtl = this.localize.dir() === "rtl";
157
- const showExpandButton = !this.loading && (!this.isLeaf || this.lazy);
158
- return html`
159
- <div
160
- part="base"
161
- class="${classMap({
162
- "tree-item": true,
163
- "tree-item--expanded": this.expanded,
164
- "tree-item--selected": this.selected,
165
- "tree-item--disabled": this.disabled,
166
- "tree-item--hidden": this.hidden,
167
- "tree-item--small": this.size === "small",
168
- "tree-item--medium": this.size === "medium",
169
- "tree-item--large": this.size === "large",
170
- "tree-item--leaf": this.isLeaf,
171
- "tree-item--has-expand-button": showExpandButton,
172
- "tree-item--rtl": this.localize.dir() === "rtl"
173
- })}"
174
- >
175
- <div
176
- class="tree-item__item"
177
- part="
178
- item
179
- ${this.disabled ? "item--disabled" : ""}
180
- ${this.expanded ? "item--expanded" : ""}
181
- ${this.indeterminate ? "item--indeterminate" : ""}
182
- ${this.selected ? "item--selected" : ""}
183
- "
184
- >
185
- <div class="tree-item__indentation" part="indentation"></div>
186
-
187
- <div
188
- part="expand-button"
189
- class=${classMap({
190
- "tree-item__expand-button": true,
191
- "tree-item__expand-button--visible": showExpandButton
192
- })}
193
- aria-hidden="true"
194
- >
195
- ${when(
196
- this.loading,
197
- () => html`
198
- <flow-ui-progress-ring
199
- size=${this.size === "large" ? "medium" : this.size}
200
- indeterminate
201
- ></flow-ui-progress-ring>
202
- `
203
- )}
204
- <slot class="tree-item__expand-icon-slot" name="expand-icon">
205
- <flow-ui-icon library="system" name=${isRtl ? "chevron-left" : "chevron-right"}></flow-ui-icon>
206
- </slot>
207
- <slot class="tree-item__expand-icon-slot" name="collapse-icon">
208
- <flow-ui-icon library="system" name=${isRtl ? "chevron-left" : "chevron-right"}></flow-ui-icon>
209
- </slot>
210
- </div>
211
-
212
- ${when(
213
- this.selectable,
214
- () => html`
215
- <flow-ui-checkbox
216
- part="checkbox"
217
- exportparts="
218
- base:checkbox__base,
219
- control:checkbox__control,
220
- control--checked:checkbox__control--checked,
221
- control--indeterminate:checkbox__control--indeterminate,
222
- checked-icon:checkbox__checked-icon,
223
- indeterminate-icon:checkbox__indeterminate-icon,
224
- label:checkbox__label
225
- "
226
- class="tree-item__checkbox"
227
- ?disabled="${this.disabled}"
228
- ?checked="${live(this.selected)}"
229
- ?indeterminate="${this.indeterminate}"
230
- tabindex="-1"
231
- size="${this.size}"
232
- ></flow-ui-checkbox>
233
- `
234
- )}
235
-
236
- <slot class="tree-item__label" part="label"></slot>
237
- </div>
238
-
239
- <slot
240
- name="children"
241
- class="tree-item__children"
242
- part="children"
243
- role="group"
244
- @slotchange="${this.handleChildrenSlotChange}"
245
- ></slot>
246
- </div>
247
- `;
42
+ return nothing;
248
43
  }
249
- };
250
- _FlowUiTreeItem.tagName = "flow-ui-tree-item";
251
- _FlowUiTreeItem.styles = styles;
252
- _FlowUiTreeItem.dependencies = [FlowUiCheckbox, FlowUiIcon, FlowUiProgressRing];
253
- __decorateClass([
254
- state()
255
- ], _FlowUiTreeItem.prototype, "indeterminate", 2);
256
- __decorateClass([
257
- state()
258
- ], _FlowUiTreeItem.prototype, "isLeaf", 2);
259
- __decorateClass([
260
- state()
261
- ], _FlowUiTreeItem.prototype, "loading", 2);
262
- __decorateClass([
263
- state()
264
- ], _FlowUiTreeItem.prototype, "selectable", 2);
44
+ }
45
+ FlowUiTreeItem.tagName = "flow-ui-tree-item";
46
+ FlowUiTreeItem.styles = css`
47
+ :host {
48
+ display: none;
49
+ }
50
+ `;
265
51
  __decorateClass([
266
52
  property({ reflect: true })
267
- ], _FlowUiTreeItem.prototype, "value", 2);
53
+ ], FlowUiTreeItem.prototype, "value", 2);
268
54
  __decorateClass([
269
55
  property({ type: Boolean, reflect: true })
270
- ], _FlowUiTreeItem.prototype, "expanded", 2);
56
+ ], FlowUiTreeItem.prototype, "expanded", 2);
271
57
  __decorateClass([
272
58
  property({ type: Boolean, reflect: true })
273
- ], _FlowUiTreeItem.prototype, "selected", 2);
59
+ ], FlowUiTreeItem.prototype, "selected", 2);
274
60
  __decorateClass([
275
61
  property({ type: Boolean, reflect: true })
276
- ], _FlowUiTreeItem.prototype, "disabled", 2);
62
+ ], FlowUiTreeItem.prototype, "disabled", 2);
277
63
  __decorateClass([
278
64
  property({ type: Boolean, reflect: true })
279
- ], _FlowUiTreeItem.prototype, "lazy", 2);
65
+ ], FlowUiTreeItem.prototype, "lazy", 2);
280
66
  __decorateClass([
281
67
  property({ reflect: true })
282
- ], _FlowUiTreeItem.prototype, "size", 2);
283
- __decorateClass([
284
- property({ type: Boolean, reflect: true })
285
- ], _FlowUiTreeItem.prototype, "hidden", 2);
68
+ ], FlowUiTreeItem.prototype, "icon", 2);
286
69
  __decorateClass([
287
- query("slot:not([name])")
288
- ], _FlowUiTreeItem.prototype, "defaultSlot", 2);
289
- __decorateClass([
290
- query("slot[name=children]")
291
- ], _FlowUiTreeItem.prototype, "childrenSlot", 2);
292
- __decorateClass([
293
- query(".tree-item__item")
294
- ], _FlowUiTreeItem.prototype, "itemElement", 2);
295
- __decorateClass([
296
- query(".tree-item__children")
297
- ], _FlowUiTreeItem.prototype, "childrenContainer", 2);
298
- __decorateClass([
299
- query(".tree-item__expand-button slot")
300
- ], _FlowUiTreeItem.prototype, "expandButtonSlot", 2);
70
+ property({ attribute: "icon-library", reflect: true })
71
+ ], FlowUiTreeItem.prototype, "iconLibrary", 2);
301
72
  __decorateClass([
302
73
  watch("value")
303
- ], _FlowUiTreeItem.prototype, "handleValueChange", 1);
304
- __decorateClass([
305
- watch("loading", { waitUntilFirstUpdate: true })
306
- ], _FlowUiTreeItem.prototype, "handleLoadingChange", 1);
307
- __decorateClass([
308
- watch("disabled")
309
- ], _FlowUiTreeItem.prototype, "handleDisabledChange", 1);
310
- __decorateClass([
311
- watch("selected")
312
- ], _FlowUiTreeItem.prototype, "handleSelectedChange", 1);
313
- __decorateClass([
314
- watch("expanded", { waitUntilFirstUpdate: true })
315
- ], _FlowUiTreeItem.prototype, "handleExpandedChange", 1);
316
- __decorateClass([
317
- watch("expanded", { waitUntilFirstUpdate: true })
318
- ], _FlowUiTreeItem.prototype, "handleExpandAnimation", 1);
319
- __decorateClass([
320
- watch("lazy", { waitUntilFirstUpdate: true })
321
- ], _FlowUiTreeItem.prototype, "handleLazyChange", 1);
322
- let FlowUiTreeItem = _FlowUiTreeItem;
323
- setDefaultAnimation("tree-item.expand", {
324
- keyframes: [
325
- { height: "0", opacity: "0", overflow: "hidden" },
326
- { height: "auto", opacity: "1", overflow: "hidden" }
327
- ],
328
- options: { duration: 250, easing: "cubic-bezier(0.4, 0.0, 0.2, 1)" }
329
- });
330
- setDefaultAnimation("tree-item.collapse", {
331
- keyframes: [
332
- { height: "auto", opacity: "1", overflow: "hidden" },
333
- { height: "0", opacity: "0", overflow: "hidden" }
334
- ],
335
- options: { duration: 200, easing: "cubic-bezier(0.4, 0.0, 0.2, 1)" }
336
- });
74
+ ], FlowUiTreeItem.prototype, "handleValueChange", 1);
337
75
 
338
76
  export { FlowUiTreeItem as default };