@ni/ok-components 1.13.0 → 1.14.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/all-components-bundle.js +776 -460
- package/dist/all-components-bundle.js.map +1 -1
- package/dist/all-components-bundle.min.js +2760 -2671
- package/dist/all-components-bundle.min.js.map +1 -1
- package/dist/custom-elements.json +190 -0
- package/dist/custom-elements.md +23 -0
- package/dist/esm/fv/all-fv.d.ts +1 -0
- package/dist/esm/fv/all-fv.js +1 -0
- package/dist/esm/fv/all-fv.js.map +1 -1
- package/dist/esm/fv/toolbar/index.d.ts +36 -0
- package/dist/esm/fv/toolbar/index.js +253 -0
- package/dist/esm/fv/toolbar/index.js.map +1 -0
- package/dist/esm/fv/toolbar/styles.d.ts +1 -0
- package/dist/esm/fv/toolbar/styles.js +39 -0
- package/dist/esm/fv/toolbar/styles.js.map +1 -0
- package/dist/esm/fv/toolbar/template.d.ts +4 -0
- package/dist/esm/fv/toolbar/template.js +40 -0
- package/dist/esm/fv/toolbar/template.js.map +1 -0
- package/package.json +1 -1
|
@@ -3758,6 +3758,196 @@
|
|
|
3758
3758
|
}
|
|
3759
3759
|
]
|
|
3760
3760
|
},
|
|
3761
|
+
{
|
|
3762
|
+
"kind": "javascript-module",
|
|
3763
|
+
"path": "src/fv/toolbar/index.ts",
|
|
3764
|
+
"declarations": [
|
|
3765
|
+
{
|
|
3766
|
+
"kind": "class",
|
|
3767
|
+
"description": "A Nimble toolbar that automatically collapses declaratively configured actions.",
|
|
3768
|
+
"name": "FvToolbar",
|
|
3769
|
+
"members": [
|
|
3770
|
+
{
|
|
3771
|
+
"kind": "field",
|
|
3772
|
+
"name": "overflowLabel",
|
|
3773
|
+
"type": {
|
|
3774
|
+
"text": "string"
|
|
3775
|
+
},
|
|
3776
|
+
"privacy": "public",
|
|
3777
|
+
"default": "'More actions'"
|
|
3778
|
+
},
|
|
3779
|
+
{
|
|
3780
|
+
"kind": "field",
|
|
3781
|
+
"name": "items",
|
|
3782
|
+
"privacy": "private",
|
|
3783
|
+
"readonly": true,
|
|
3784
|
+
"default": "new Map<Button, ResponsiveItem>()"
|
|
3785
|
+
},
|
|
3786
|
+
{
|
|
3787
|
+
"kind": "field",
|
|
3788
|
+
"name": "resizeObserver",
|
|
3789
|
+
"privacy": "private",
|
|
3790
|
+
"readonly": true,
|
|
3791
|
+
"default": "new ResizeObserver(() => this.scheduleLayout())"
|
|
3792
|
+
},
|
|
3793
|
+
{
|
|
3794
|
+
"kind": "field",
|
|
3795
|
+
"name": "mutationObserver",
|
|
3796
|
+
"privacy": "private",
|
|
3797
|
+
"readonly": true,
|
|
3798
|
+
"default": "new MutationObserver(records => { for (const record of records) { const item = record.target instanceof Button ? this.items.get(record.target) : undefined; if (item && record.attributeName === 'hidden') { item.hidden = item.button.hidden; } if (item && record.attributeName === 'content-hidden') { item.contentHidden = item.button.contentHidden; } } this.scheduleLayout(); })"
|
|
3799
|
+
},
|
|
3800
|
+
{
|
|
3801
|
+
"kind": "field",
|
|
3802
|
+
"name": "observedChildren",
|
|
3803
|
+
"privacy": "private",
|
|
3804
|
+
"readonly": true,
|
|
3805
|
+
"default": "new Set<Element>()"
|
|
3806
|
+
},
|
|
3807
|
+
{
|
|
3808
|
+
"kind": "field",
|
|
3809
|
+
"name": "frame",
|
|
3810
|
+
"type": {
|
|
3811
|
+
"text": "number"
|
|
3812
|
+
},
|
|
3813
|
+
"privacy": "private",
|
|
3814
|
+
"default": "0"
|
|
3815
|
+
},
|
|
3816
|
+
{
|
|
3817
|
+
"kind": "field",
|
|
3818
|
+
"name": "allSlottedItems",
|
|
3819
|
+
"type": {
|
|
3820
|
+
"text": "(HTMLElement | Node)[]"
|
|
3821
|
+
},
|
|
3822
|
+
"privacy": "protected",
|
|
3823
|
+
"readonly": true
|
|
3824
|
+
},
|
|
3825
|
+
{
|
|
3826
|
+
"kind": "method",
|
|
3827
|
+
"name": "observeMutations",
|
|
3828
|
+
"privacy": "private",
|
|
3829
|
+
"return": {
|
|
3830
|
+
"type": {
|
|
3831
|
+
"text": "void"
|
|
3832
|
+
}
|
|
3833
|
+
}
|
|
3834
|
+
},
|
|
3835
|
+
{
|
|
3836
|
+
"kind": "field",
|
|
3837
|
+
"name": "scheduleLayout",
|
|
3838
|
+
"privacy": "private",
|
|
3839
|
+
"readonly": true
|
|
3840
|
+
},
|
|
3841
|
+
{
|
|
3842
|
+
"kind": "method",
|
|
3843
|
+
"name": "restoreItem",
|
|
3844
|
+
"privacy": "private",
|
|
3845
|
+
"return": {
|
|
3846
|
+
"type": {
|
|
3847
|
+
"text": "void"
|
|
3848
|
+
}
|
|
3849
|
+
},
|
|
3850
|
+
"parameters": [
|
|
3851
|
+
{
|
|
3852
|
+
"name": "item",
|
|
3853
|
+
"type": {
|
|
3854
|
+
"text": "ResponsiveItem"
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3857
|
+
]
|
|
3858
|
+
},
|
|
3859
|
+
{
|
|
3860
|
+
"kind": "method",
|
|
3861
|
+
"name": "syncItems",
|
|
3862
|
+
"privacy": "private",
|
|
3863
|
+
"return": {
|
|
3864
|
+
"type": {
|
|
3865
|
+
"text": "ResponsiveItem[]"
|
|
3866
|
+
}
|
|
3867
|
+
}
|
|
3868
|
+
},
|
|
3869
|
+
{
|
|
3870
|
+
"kind": "method",
|
|
3871
|
+
"name": "updateLayout",
|
|
3872
|
+
"privacy": "private",
|
|
3873
|
+
"return": {
|
|
3874
|
+
"type": {
|
|
3875
|
+
"text": "void"
|
|
3876
|
+
}
|
|
3877
|
+
}
|
|
3878
|
+
},
|
|
3879
|
+
{
|
|
3880
|
+
"kind": "method",
|
|
3881
|
+
"name": "showOverflow",
|
|
3882
|
+
"privacy": "private",
|
|
3883
|
+
"return": {
|
|
3884
|
+
"type": {
|
|
3885
|
+
"text": "void"
|
|
3886
|
+
}
|
|
3887
|
+
},
|
|
3888
|
+
"parameters": [
|
|
3889
|
+
{
|
|
3890
|
+
"name": "show",
|
|
3891
|
+
"type": {
|
|
3892
|
+
"text": "boolean"
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
]
|
|
3896
|
+
},
|
|
3897
|
+
{
|
|
3898
|
+
"kind": "method",
|
|
3899
|
+
"name": "fits",
|
|
3900
|
+
"privacy": "private",
|
|
3901
|
+
"return": {
|
|
3902
|
+
"type": {
|
|
3903
|
+
"text": "boolean"
|
|
3904
|
+
}
|
|
3905
|
+
}
|
|
3906
|
+
}
|
|
3907
|
+
],
|
|
3908
|
+
"attributes": [
|
|
3909
|
+
{
|
|
3910
|
+
"name": "overflow-label",
|
|
3911
|
+
"type": {
|
|
3912
|
+
"text": "string"
|
|
3913
|
+
},
|
|
3914
|
+
"default": "'More actions'",
|
|
3915
|
+
"fieldName": "overflowLabel"
|
|
3916
|
+
}
|
|
3917
|
+
],
|
|
3918
|
+
"superclass": {
|
|
3919
|
+
"name": "Toolbar",
|
|
3920
|
+
"package": "@ni/nimble-components/dist/esm/toolbar"
|
|
3921
|
+
}
|
|
3922
|
+
},
|
|
3923
|
+
{
|
|
3924
|
+
"kind": "variable",
|
|
3925
|
+
"name": "fvToolbarTag",
|
|
3926
|
+
"type": {
|
|
3927
|
+
"text": "string"
|
|
3928
|
+
},
|
|
3929
|
+
"default": "'ok-fv-toolbar'"
|
|
3930
|
+
}
|
|
3931
|
+
],
|
|
3932
|
+
"exports": [
|
|
3933
|
+
{
|
|
3934
|
+
"kind": "js",
|
|
3935
|
+
"name": "FvToolbar",
|
|
3936
|
+
"declaration": {
|
|
3937
|
+
"name": "FvToolbar",
|
|
3938
|
+
"module": "src/fv/toolbar/index.ts"
|
|
3939
|
+
}
|
|
3940
|
+
},
|
|
3941
|
+
{
|
|
3942
|
+
"kind": "js",
|
|
3943
|
+
"name": "fvToolbarTag",
|
|
3944
|
+
"declaration": {
|
|
3945
|
+
"name": "fvToolbarTag",
|
|
3946
|
+
"module": "src/fv/toolbar/index.ts"
|
|
3947
|
+
}
|
|
3948
|
+
}
|
|
3949
|
+
]
|
|
3950
|
+
},
|
|
3761
3951
|
{
|
|
3762
3952
|
"kind": "javascript-module",
|
|
3763
3953
|
"path": "src/ts/icon-dynamic/index.ts",
|
package/dist/custom-elements.md
CHANGED
|
@@ -608,6 +608,29 @@
|
|
|
608
608
|
|
|
609
609
|
<hr/>
|
|
610
610
|
|
|
611
|
+
## class: `FvToolbar`
|
|
612
|
+
|
|
613
|
+
### Superclass
|
|
614
|
+
|
|
615
|
+
| Name | Module | Package |
|
|
616
|
+
| --------- | ------ | -------------------------------------- |
|
|
617
|
+
| `Toolbar` | | @ni/nimble-components/dist/esm/toolbar |
|
|
618
|
+
|
|
619
|
+
### Fields
|
|
620
|
+
|
|
621
|
+
| Name | Privacy | Type | Default | Description | Inherited From |
|
|
622
|
+
| ----------------- | --------- | ------------------------- | ---------------- | ----------- | -------------- |
|
|
623
|
+
| `overflowLabel` | public | `string` | `'More actions'` | | |
|
|
624
|
+
| `allSlottedItems` | protected | `(HTMLElement \| Node)[]` | | | |
|
|
625
|
+
|
|
626
|
+
### Attributes
|
|
627
|
+
|
|
628
|
+
| Name | Field | Inherited From |
|
|
629
|
+
| ---------------- | ------------- | -------------- |
|
|
630
|
+
| `overflow-label` | overflowLabel | |
|
|
631
|
+
|
|
632
|
+
<hr/>
|
|
633
|
+
|
|
611
634
|
## class: `TsIconDynamic`
|
|
612
635
|
|
|
613
636
|
### Superclass
|
package/dist/esm/fv/all-fv.d.ts
CHANGED
package/dist/esm/fv/all-fv.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"all-fv.js","sourceRoot":"","sources":["../../../src/fv/all-fv.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,QAAQ,CAAC;AAChB,OAAO,mBAAmB,CAAC;AAC3B,OAAO,iBAAiB,CAAC;AACzB,OAAO,gBAAgB,CAAC;AACxB,OAAO,mBAAmB,CAAC;AAC3B,OAAO,cAAc,CAAC;AACtB,OAAO,2BAA2B,CAAC;AACnC,OAAO,sBAAsB,CAAC;AAC9B,OAAO,gBAAgB,CAAC;AACxB,OAAO,uBAAuB,CAAC;AAC/B,OAAO,iBAAiB,CAAC;AACzB,OAAO,iBAAiB,CAAC;AACzB,OAAO,sBAAsB,CAAC;AAC9B,OAAO,gBAAgB,CAAC;AACxB,OAAO,YAAY,CAAC;AACpB,OAAO,gBAAgB,CAAC","sourcesContent":["import './accordion-item';\nimport './card';\nimport './bulk-edit-field';\nimport './chip-selector';\nimport './context-help';\nimport './edit-commit-bar';\nimport './filter-bar';\nimport './master-detail-list-item';\nimport './master-detail-list';\nimport './split-button';\nimport './split-button-anchor';\nimport './sticky-header';\nimport './summary-panel';\nimport './summary-panel-tile';\nimport './search-input';\nimport './splitter';\nimport './split-layout';\n"]}
|
|
1
|
+
{"version":3,"file":"all-fv.js","sourceRoot":"","sources":["../../../src/fv/all-fv.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,QAAQ,CAAC;AAChB,OAAO,mBAAmB,CAAC;AAC3B,OAAO,iBAAiB,CAAC;AACzB,OAAO,gBAAgB,CAAC;AACxB,OAAO,mBAAmB,CAAC;AAC3B,OAAO,cAAc,CAAC;AACtB,OAAO,2BAA2B,CAAC;AACnC,OAAO,sBAAsB,CAAC;AAC9B,OAAO,gBAAgB,CAAC;AACxB,OAAO,uBAAuB,CAAC;AAC/B,OAAO,iBAAiB,CAAC;AACzB,OAAO,iBAAiB,CAAC;AACzB,OAAO,sBAAsB,CAAC;AAC9B,OAAO,gBAAgB,CAAC;AACxB,OAAO,YAAY,CAAC;AACpB,OAAO,gBAAgB,CAAC;AACxB,OAAO,WAAW,CAAC","sourcesContent":["import './accordion-item';\nimport './card';\nimport './bulk-edit-field';\nimport './chip-selector';\nimport './context-help';\nimport './edit-commit-bar';\nimport './filter-bar';\nimport './master-detail-list-item';\nimport './master-detail-list';\nimport './split-button';\nimport './split-button-anchor';\nimport './sticky-header';\nimport './summary-panel';\nimport './summary-panel-tile';\nimport './search-input';\nimport './splitter';\nimport './split-layout';\nimport './toolbar';\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Toolbar } from '@ni/nimble-components/dist/esm/toolbar';
|
|
2
|
+
import type { MenuButton } from '@ni/nimble-components/dist/esm/menu-button';
|
|
3
|
+
import type { Menu } from '@ni/nimble-components/dist/esm/menu';
|
|
4
|
+
declare global {
|
|
5
|
+
interface HTMLElementTagNameMap {
|
|
6
|
+
'ok-fv-toolbar': FvToolbar;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A Nimble toolbar that automatically collapses declaratively configured actions.
|
|
11
|
+
*/
|
|
12
|
+
export declare class FvToolbar extends Toolbar {
|
|
13
|
+
overflowLabel: string;
|
|
14
|
+
/** @internal */
|
|
15
|
+
hasOverflow: boolean;
|
|
16
|
+
/** @internal */
|
|
17
|
+
overflowButton: MenuButton;
|
|
18
|
+
/** @internal */
|
|
19
|
+
overflowMenu: Menu;
|
|
20
|
+
private readonly items;
|
|
21
|
+
private readonly resizeObserver;
|
|
22
|
+
private readonly mutationObserver;
|
|
23
|
+
private readonly observedChildren;
|
|
24
|
+
private frame;
|
|
25
|
+
connectedCallback(): void;
|
|
26
|
+
disconnectedCallback(): void;
|
|
27
|
+
protected get allSlottedItems(): (HTMLElement | Node)[];
|
|
28
|
+
private observeMutations;
|
|
29
|
+
private readonly scheduleLayout;
|
|
30
|
+
private restoreItem;
|
|
31
|
+
private syncItems;
|
|
32
|
+
private updateLayout;
|
|
33
|
+
private showOverflow;
|
|
34
|
+
private fits;
|
|
35
|
+
}
|
|
36
|
+
export declare const fvToolbarTag = "ok-fv-toolbar";
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { attr, observable } from '@ni/fast-element';
|
|
3
|
+
import { DesignSystem } from '@ni/fast-foundation';
|
|
4
|
+
import { Toolbar } from '@ni/nimble-components/dist/esm/toolbar';
|
|
5
|
+
import { Button } from '@ni/nimble-components/dist/esm/button';
|
|
6
|
+
import { MenuItem, menuItemTag } from '@ni/nimble-components/dist/esm/menu-item';
|
|
7
|
+
import { styles } from './styles';
|
|
8
|
+
import { template } from './template';
|
|
9
|
+
/**
|
|
10
|
+
* A Nimble toolbar that automatically collapses declaratively configured actions.
|
|
11
|
+
*/
|
|
12
|
+
export class FvToolbar extends Toolbar {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.overflowLabel = 'More actions';
|
|
16
|
+
/** @internal */
|
|
17
|
+
this.hasOverflow = false;
|
|
18
|
+
this.items = new Map();
|
|
19
|
+
this.resizeObserver = new ResizeObserver(() => this.scheduleLayout());
|
|
20
|
+
this.mutationObserver = new MutationObserver(records => {
|
|
21
|
+
for (const record of records) {
|
|
22
|
+
const item = record.target instanceof Button ? this.items.get(record.target) : undefined;
|
|
23
|
+
if (item && record.attributeName === 'hidden') {
|
|
24
|
+
item.hidden = item.button.hidden;
|
|
25
|
+
}
|
|
26
|
+
if (item && record.attributeName === 'content-hidden') {
|
|
27
|
+
item.contentHidden = item.button.contentHidden;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
this.scheduleLayout();
|
|
31
|
+
});
|
|
32
|
+
this.observedChildren = new Set();
|
|
33
|
+
this.frame = 0;
|
|
34
|
+
this.scheduleLayout = () => {
|
|
35
|
+
if (!this.isConnected || this.frame !== 0) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this.frame = requestAnimationFrame(() => {
|
|
39
|
+
this.frame = 0;
|
|
40
|
+
this.updateLayout();
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
connectedCallback() {
|
|
45
|
+
super.connectedCallback();
|
|
46
|
+
this.resizeObserver.observe(this);
|
|
47
|
+
this.observeMutations();
|
|
48
|
+
this.ownerDocument.fonts.addEventListener('loadingdone', this.scheduleLayout);
|
|
49
|
+
this.scheduleLayout();
|
|
50
|
+
}
|
|
51
|
+
disconnectedCallback() {
|
|
52
|
+
this.resizeObserver.disconnect();
|
|
53
|
+
this.mutationObserver.disconnect();
|
|
54
|
+
this.ownerDocument.fonts.removeEventListener('loadingdone', this.scheduleLayout);
|
|
55
|
+
cancelAnimationFrame(this.frame);
|
|
56
|
+
this.frame = 0;
|
|
57
|
+
for (const item of this.items.values()) {
|
|
58
|
+
this.restoreItem(item);
|
|
59
|
+
}
|
|
60
|
+
this.items.clear();
|
|
61
|
+
this.observedChildren.clear();
|
|
62
|
+
super.disconnectedCallback();
|
|
63
|
+
}
|
|
64
|
+
get allSlottedItems() {
|
|
65
|
+
return [
|
|
66
|
+
...super.allSlottedItems,
|
|
67
|
+
...(this.hasOverflow ? [this.overflowButton] : [])
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
observeMutations() {
|
|
71
|
+
this.mutationObserver.observe(this, {
|
|
72
|
+
subtree: true,
|
|
73
|
+
childList: true,
|
|
74
|
+
characterData: true,
|
|
75
|
+
attributes: true,
|
|
76
|
+
attributeFilter: [
|
|
77
|
+
'data-responsive', 'data-priority', 'disabled', 'hidden',
|
|
78
|
+
'content-hidden', 'aria-label', 'slot', 'class', 'style'
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
restoreItem(item) {
|
|
83
|
+
item.button.hidden = item.hidden;
|
|
84
|
+
item.button.toggleAttribute('content-hidden', item.contentHidden);
|
|
85
|
+
item.menuItem.remove();
|
|
86
|
+
}
|
|
87
|
+
syncItems() {
|
|
88
|
+
const buttons = Array.from(this.children).filter((child) => child instanceof Button && child.hasAttribute('data-responsive'));
|
|
89
|
+
for (const [button, item] of this.items) {
|
|
90
|
+
if (!buttons.includes(button)) {
|
|
91
|
+
this.restoreItem(item);
|
|
92
|
+
this.items.delete(button);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
for (const button of buttons) {
|
|
96
|
+
const value = button.getAttribute('data-responsive')?.trim() ?? '';
|
|
97
|
+
const tokens = value.split(/\s+/);
|
|
98
|
+
const stages = ['label', 'icon', 'overflow'].filter(stage => tokens.includes(stage));
|
|
99
|
+
const priority = Number(button.getAttribute('data-priority') ?? 0);
|
|
100
|
+
if (stages.length === 0 || tokens.some(token => !stages.some(stage => stage === token))
|
|
101
|
+
|| !Number.isFinite(priority)
|
|
102
|
+
|| (stages.includes('icon') && !button.querySelector(':scope > [slot="start"]'))) {
|
|
103
|
+
throw new Error('ok-fv-toolbar requires valid data-responsive stages, a finite data-priority, and a direct start-slot icon for icon-only actions.');
|
|
104
|
+
}
|
|
105
|
+
let item = this.items.get(button);
|
|
106
|
+
if (!item) {
|
|
107
|
+
const menuItem = this.ownerDocument.createElement(menuItemTag);
|
|
108
|
+
menuItem.addEventListener('change', () => {
|
|
109
|
+
if (!button.disabled) {
|
|
110
|
+
button.click();
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
item = {
|
|
114
|
+
button,
|
|
115
|
+
stages,
|
|
116
|
+
priority,
|
|
117
|
+
hidden: button.hidden,
|
|
118
|
+
contentHidden: button.contentHidden,
|
|
119
|
+
menuItem
|
|
120
|
+
};
|
|
121
|
+
this.items.set(button, item);
|
|
122
|
+
}
|
|
123
|
+
item.stages = stages;
|
|
124
|
+
item.priority = priority;
|
|
125
|
+
item.menuItem.disabled = button.disabled;
|
|
126
|
+
const label = (button.getAttribute('aria-label')
|
|
127
|
+
?? Array.from(button.childNodes)
|
|
128
|
+
.filter(node => node.nodeType === Node.TEXT_NODE
|
|
129
|
+
|| (node instanceof Element && !node.hasAttribute('slot')))
|
|
130
|
+
.map(node => node.textContent).join('')).trim();
|
|
131
|
+
if (!label) {
|
|
132
|
+
throw new Error('ok-fv-toolbar responsive actions require a text label or aria-label.');
|
|
133
|
+
}
|
|
134
|
+
if (item.menuItem.textContent !== label) {
|
|
135
|
+
item.menuItem.textContent = label;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return buttons.map(button => this.items.get(button));
|
|
139
|
+
}
|
|
140
|
+
updateLayout() {
|
|
141
|
+
// Ignore our own presentation mutations, not application changes.
|
|
142
|
+
this.mutationObserver.disconnect();
|
|
143
|
+
try {
|
|
144
|
+
const menuFocus = this.shadowRoot?.activeElement;
|
|
145
|
+
const menuHadFocus = menuFocus && this.overflowButton.contains(menuFocus);
|
|
146
|
+
const previousMenuItems = Array.from(this.overflowMenu.children);
|
|
147
|
+
const items = this.syncItems();
|
|
148
|
+
const root = this.getRootNode();
|
|
149
|
+
const activeElement = root instanceof ShadowRoot ? root.activeElement : this.ownerDocument.activeElement;
|
|
150
|
+
const focusedItem = items.find(item => item.button === activeElement);
|
|
151
|
+
for (const child of this.observedChildren) {
|
|
152
|
+
if (child.parentElement !== this) {
|
|
153
|
+
this.resizeObserver.unobserve(child);
|
|
154
|
+
this.observedChildren.delete(child);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
for (const child of this.children) {
|
|
158
|
+
if (!this.observedChildren.has(child)) {
|
|
159
|
+
this.resizeObserver.observe(child);
|
|
160
|
+
this.observedChildren.add(child);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const overflow = new Set();
|
|
164
|
+
for (const item of items) {
|
|
165
|
+
item.button.hidden = item.hidden;
|
|
166
|
+
item.button.toggleAttribute('content-hidden', item.stages[0] === 'icon');
|
|
167
|
+
if (!item.hidden && item.stages[0] === 'overflow') {
|
|
168
|
+
overflow.add(item);
|
|
169
|
+
item.button.hidden = true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
this.showOverflow(overflow.size > 0);
|
|
173
|
+
const ordered = items.filter(item => !item.hidden).reverse()
|
|
174
|
+
.sort((a, b) => a.priority - b.priority);
|
|
175
|
+
// ponytail: measure each transition; cache widths only if large toolbars make this costly.
|
|
176
|
+
for (const stage of ['icon', 'overflow']) {
|
|
177
|
+
for (const item of ordered) {
|
|
178
|
+
if (this.fits()) {
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
if (overflow.has(item) || !item.stages.includes(stage)) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (stage === 'icon') {
|
|
185
|
+
item.button.toggleAttribute('content-hidden', true);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
item.button.hidden = true;
|
|
189
|
+
overflow.add(item);
|
|
190
|
+
this.showOverflow(true);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const overflowItems = items.filter(item => overflow.has(item));
|
|
195
|
+
const nextMenuItems = overflowItems.map(item => item.menuItem);
|
|
196
|
+
if (nextMenuItems.length !== previousMenuItems.length
|
|
197
|
+
|| nextMenuItems.some((item, index) => previousMenuItems[index] !== item)) {
|
|
198
|
+
this.overflowButton.open = false;
|
|
199
|
+
this.overflowMenu.replaceChildren(...nextMenuItems);
|
|
200
|
+
}
|
|
201
|
+
if (!this.hasOverflow) {
|
|
202
|
+
this.overflowButton.open = false;
|
|
203
|
+
}
|
|
204
|
+
this.overflowButton.hidden = !this.hasOverflow;
|
|
205
|
+
this.overflowButton.classList.remove('unreserved');
|
|
206
|
+
this.reduceFocusableElements();
|
|
207
|
+
if (focusedItem && overflow.has(focusedItem)) {
|
|
208
|
+
this.overflowButton.focus();
|
|
209
|
+
}
|
|
210
|
+
else if (menuHadFocus) {
|
|
211
|
+
if (this.hasOverflow) {
|
|
212
|
+
if (this.overflowButton.open && menuFocus instanceof HTMLElement && menuFocus.isConnected) {
|
|
213
|
+
menuFocus.focus();
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
this.overflowButton.focus();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
Array.from(this.querySelectorAll('[tabindex="0"]'))
|
|
221
|
+
.find(control => !control.closest('[hidden], [disabled]'))?.focus();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
finally {
|
|
226
|
+
this.observeMutations();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
showOverflow(show) {
|
|
230
|
+
this.hasOverflow = show;
|
|
231
|
+
// Remove the trigger from width calculations without hiding its focused menu.
|
|
232
|
+
this.overflowButton.classList.toggle('unreserved', !show);
|
|
233
|
+
this.overflowButton.hidden = false;
|
|
234
|
+
}
|
|
235
|
+
fits() {
|
|
236
|
+
const region = this.shadowRoot.querySelector('.positioning-region');
|
|
237
|
+
return region.scrollWidth <= region.clientWidth;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
__decorate([
|
|
241
|
+
attr({ attribute: 'overflow-label' })
|
|
242
|
+
], FvToolbar.prototype, "overflowLabel", void 0);
|
|
243
|
+
__decorate([
|
|
244
|
+
observable
|
|
245
|
+
], FvToolbar.prototype, "hasOverflow", void 0);
|
|
246
|
+
const okFvToolbar = FvToolbar.compose({
|
|
247
|
+
baseName: 'fv-toolbar',
|
|
248
|
+
template,
|
|
249
|
+
styles
|
|
250
|
+
});
|
|
251
|
+
DesignSystem.getOrCreate().withPrefix('ok').register(okFvToolbar());
|
|
252
|
+
export const fvToolbarTag = 'ok-fv-toolbar';
|
|
253
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/fv/toolbar/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAEjF,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAmBtC;;GAEG;AACH,MAAM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GAAG,eAAe,CAAC","sourcesContent":["import { attr, observable } from '@ni/fast-element';\nimport { DesignSystem } from '@ni/fast-foundation';\nimport { Toolbar } from '@ni/nimble-components/dist/esm/toolbar';\nimport { Button } from '@ni/nimble-components/dist/esm/button';\nimport type { MenuButton } from '@ni/nimble-components/dist/esm/menu-button';\nimport { MenuItem, menuItemTag } from '@ni/nimble-components/dist/esm/menu-item';\nimport type { Menu } from '@ni/nimble-components/dist/esm/menu';\nimport { styles } from './styles';\nimport { template } from './template';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ok-fv-toolbar': FvToolbar;\n }\n}\n\ntype Presentation = 'label' | 'icon' | 'overflow';\n\ninterface ResponsiveItem {\n button: Button;\n stages: Presentation[];\n priority: number;\n contentHidden: boolean;\n hidden: boolean;\n menuItem: MenuItem;\n}\n\n/**\n * A Nimble toolbar that automatically collapses declaratively configured actions.\n */\nexport class FvToolbar extends Toolbar {\n @attr({ attribute: 'overflow-label' })\n public overflowLabel = 'More actions';\n\n /** @internal */\n @observable\n public hasOverflow = false;\n\n /** @internal */\n public overflowButton!: MenuButton;\n\n /** @internal */\n public overflowMenu!: Menu;\n\n private readonly items = new Map<Button, ResponsiveItem>();\n private readonly resizeObserver = new ResizeObserver(() => this.scheduleLayout());\n private readonly mutationObserver = new MutationObserver(records => {\n for (const record of records) {\n const item = record.target instanceof Button ? this.items.get(record.target) : undefined;\n if (item && record.attributeName === 'hidden') {\n item.hidden = item.button.hidden;\n }\n if (item && record.attributeName === 'content-hidden') {\n item.contentHidden = item.button.contentHidden;\n }\n }\n this.scheduleLayout();\n });\n\n private readonly observedChildren = new Set<Element>();\n private frame = 0;\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this.resizeObserver.observe(this);\n this.observeMutations();\n this.ownerDocument.fonts.addEventListener('loadingdone', this.scheduleLayout);\n this.scheduleLayout();\n }\n\n public override disconnectedCallback(): void {\n this.resizeObserver.disconnect();\n this.mutationObserver.disconnect();\n this.ownerDocument.fonts.removeEventListener('loadingdone', this.scheduleLayout);\n cancelAnimationFrame(this.frame);\n this.frame = 0;\n for (const item of this.items.values()) {\n this.restoreItem(item);\n }\n this.items.clear();\n this.observedChildren.clear();\n super.disconnectedCallback();\n }\n\n protected override get allSlottedItems(): (HTMLElement | Node)[] {\n return [\n ...super.allSlottedItems,\n ...(this.hasOverflow ? [this.overflowButton] : [])\n ];\n }\n\n private observeMutations(): void {\n this.mutationObserver.observe(this, {\n subtree: true,\n childList: true,\n characterData: true,\n attributes: true,\n attributeFilter: [\n 'data-responsive', 'data-priority', 'disabled', 'hidden',\n 'content-hidden', 'aria-label', 'slot', 'class', 'style'\n ]\n });\n }\n\n private readonly scheduleLayout = (): void => {\n if (!this.isConnected || this.frame !== 0) {\n return;\n }\n this.frame = requestAnimationFrame(() => {\n this.frame = 0;\n this.updateLayout();\n });\n };\n\n private restoreItem(item: ResponsiveItem): void {\n item.button.hidden = item.hidden;\n item.button.toggleAttribute('content-hidden', item.contentHidden);\n item.menuItem.remove();\n }\n\n private syncItems(): ResponsiveItem[] {\n const buttons = Array.from(this.children).filter(\n (child): child is Button => child instanceof Button && child.hasAttribute('data-responsive')\n );\n for (const [button, item] of this.items) {\n if (!buttons.includes(button)) {\n this.restoreItem(item);\n this.items.delete(button);\n }\n }\n for (const button of buttons) {\n const value = button.getAttribute('data-responsive')?.trim() ?? '';\n const tokens = value.split(/\\s+/);\n const stages = (['label', 'icon', 'overflow'] as const).filter(stage => tokens.includes(stage));\n const priority = Number(button.getAttribute('data-priority') ?? 0);\n if (stages.length === 0 || tokens.some(token => !stages.some(stage => stage === token))\n || !Number.isFinite(priority)\n || (stages.includes('icon') && !button.querySelector(':scope > [slot=\"start\"]'))) {\n throw new Error('ok-fv-toolbar requires valid data-responsive stages, a finite data-priority, and a direct start-slot icon for icon-only actions.');\n }\n let item = this.items.get(button);\n if (!item) {\n const menuItem = this.ownerDocument.createElement(menuItemTag);\n menuItem.addEventListener('change', () => {\n if (!button.disabled) {\n button.click();\n }\n });\n item = {\n button,\n stages,\n priority,\n hidden: button.hidden,\n contentHidden: button.contentHidden,\n menuItem\n };\n this.items.set(button, item);\n }\n item.stages = stages;\n item.priority = priority;\n item.menuItem.disabled = button.disabled;\n const label = (button.getAttribute('aria-label')\n ?? Array.from(button.childNodes)\n .filter(node => node.nodeType === Node.TEXT_NODE\n || (node instanceof Element && !node.hasAttribute('slot')))\n .map(node => node.textContent).join('')).trim();\n if (!label) {\n throw new Error('ok-fv-toolbar responsive actions require a text label or aria-label.');\n }\n if (item.menuItem.textContent !== label) {\n item.menuItem.textContent = label;\n }\n }\n return buttons.map(button => this.items.get(button)!);\n }\n\n private updateLayout(): void {\n // Ignore our own presentation mutations, not application changes.\n this.mutationObserver.disconnect();\n try {\n const menuFocus = this.shadowRoot?.activeElement;\n const menuHadFocus = menuFocus && this.overflowButton.contains(menuFocus);\n const previousMenuItems = Array.from(this.overflowMenu.children);\n const items = this.syncItems();\n const root = this.getRootNode();\n const activeElement = root instanceof ShadowRoot ? root.activeElement : this.ownerDocument.activeElement;\n const focusedItem = items.find(item => item.button === activeElement);\n for (const child of this.observedChildren) {\n if (child.parentElement !== this) {\n this.resizeObserver.unobserve(child);\n this.observedChildren.delete(child);\n }\n }\n for (const child of this.children) {\n if (!this.observedChildren.has(child)) {\n this.resizeObserver.observe(child);\n this.observedChildren.add(child);\n }\n }\n const overflow = new Set<ResponsiveItem>();\n for (const item of items) {\n item.button.hidden = item.hidden;\n item.button.toggleAttribute('content-hidden', item.stages[0] === 'icon');\n if (!item.hidden && item.stages[0] === 'overflow') {\n overflow.add(item);\n item.button.hidden = true;\n }\n }\n this.showOverflow(overflow.size > 0);\n const ordered = items.filter(item => !item.hidden).reverse()\n .sort((a, b) => a.priority - b.priority);\n // ponytail: measure each transition; cache widths only if large toolbars make this costly.\n for (const stage of ['icon', 'overflow'] as const) {\n for (const item of ordered) {\n if (this.fits()) {\n break;\n }\n if (overflow.has(item) || !item.stages.includes(stage)) {\n continue;\n }\n if (stage === 'icon') {\n item.button.toggleAttribute('content-hidden', true);\n } else {\n item.button.hidden = true;\n overflow.add(item);\n this.showOverflow(true);\n }\n }\n }\n const overflowItems = items.filter(item => overflow.has(item));\n const nextMenuItems = overflowItems.map(item => item.menuItem);\n if (nextMenuItems.length !== previousMenuItems.length\n || nextMenuItems.some((item, index) => previousMenuItems[index] !== item)) {\n this.overflowButton.open = false;\n this.overflowMenu.replaceChildren(...nextMenuItems);\n }\n if (!this.hasOverflow) {\n this.overflowButton.open = false;\n }\n this.overflowButton.hidden = !this.hasOverflow;\n this.overflowButton.classList.remove('unreserved');\n this.reduceFocusableElements();\n if (focusedItem && overflow.has(focusedItem)) {\n this.overflowButton.focus();\n } else if (menuHadFocus) {\n if (this.hasOverflow) {\n if (this.overflowButton.open && menuFocus instanceof HTMLElement && menuFocus.isConnected) {\n menuFocus.focus();\n } else {\n this.overflowButton.focus();\n }\n } else {\n Array.from(this.querySelectorAll<HTMLElement>('[tabindex=\"0\"]'))\n .find(control => !control.closest('[hidden], [disabled]'))?.focus();\n }\n }\n } finally {\n this.observeMutations();\n }\n }\n\n private showOverflow(show: boolean): void {\n this.hasOverflow = show;\n // Remove the trigger from width calculations without hiding its focused menu.\n this.overflowButton.classList.toggle('unreserved', !show);\n this.overflowButton.hidden = false;\n }\n\n private fits(): boolean {\n const region = this.shadowRoot!.querySelector<HTMLElement>('.positioning-region')!;\n return region.scrollWidth <= region.clientWidth;\n }\n}\n\nconst okFvToolbar = FvToolbar.compose({\n baseName: 'fv-toolbar',\n template,\n styles\n});\n\nDesignSystem.getOrCreate().withPrefix('ok').register(okFvToolbar());\nexport const fvToolbarTag = 'ok-fv-toolbar';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const styles: import("@ni/fast-element").ElementStyles;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { css } from '@ni/fast-element';
|
|
2
|
+
import { styles as toolbarStyles } from '@ni/nimble-components/dist/esm/toolbar/styles';
|
|
3
|
+
export const styles = css `
|
|
4
|
+
${toolbarStyles}
|
|
5
|
+
|
|
6
|
+
:host {
|
|
7
|
+
display: block;
|
|
8
|
+
min-width: 0;
|
|
9
|
+
max-width: 100%;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.positioning-region {
|
|
13
|
+
position: relative;
|
|
14
|
+
overflow-x: auto;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.unreserved {
|
|
18
|
+
position: absolute;
|
|
19
|
+
inset-inline-end: 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
[part='start'],
|
|
23
|
+
[part='end'],
|
|
24
|
+
nimble-menu-button,
|
|
25
|
+
::slotted(*) {
|
|
26
|
+
flex-shrink: 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
[part='start'] {
|
|
30
|
+
margin: 0;
|
|
31
|
+
margin-inline-end: auto;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
[part='end'] {
|
|
35
|
+
margin: 0;
|
|
36
|
+
margin-inline-start: auto;
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../../src/fv/toolbar/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,+CAA+C,CAAC;AAExF,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;MACnB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkClB,CAAC","sourcesContent":["import { css } from '@ni/fast-element';\nimport { styles as toolbarStyles } from '@ni/nimble-components/dist/esm/toolbar/styles';\n\nexport const styles = css`\n ${toolbarStyles}\n\n :host {\n display: block;\n min-width: 0;\n max-width: 100%;\n }\n\n .positioning-region {\n position: relative;\n overflow-x: auto;\n }\n\n .unreserved {\n position: absolute;\n inset-inline-end: 0;\n }\n\n [part='start'],\n [part='end'],\n nimble-menu-button,\n ::slotted(*) {\n flex-shrink: 0;\n }\n\n [part='start'] {\n margin: 0;\n margin-inline-end: auto;\n }\n\n [part='end'] {\n margin: 0;\n margin-inline-start: auto;\n }\n`;\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ViewTemplate } from '@ni/fast-element';
|
|
2
|
+
import { type FoundationElementTemplate, type ToolbarOptions } from '@ni/fast-foundation';
|
|
3
|
+
import type { FvToolbar } from '.';
|
|
4
|
+
export declare const template: FoundationElementTemplate<ViewTemplate<FvToolbar>, ToolbarOptions>;
|