@axium/client 0.14.3 → 0.14.4
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/lib/attachments.ts +27 -4
- package/package.json +1 -1
package/lib/attachments.ts
CHANGED
|
@@ -17,8 +17,8 @@ export interface ContextMenuItem {
|
|
|
17
17
|
/**
|
|
18
18
|
* Attach a context menu to an element with the given actions
|
|
19
19
|
*/
|
|
20
|
-
export function contextMenu(...menuItems: (ContextMenuItem | false | null | undefined)[]) {
|
|
21
|
-
function _attachContextMenu(element: HTMLElement) {
|
|
20
|
+
export function contextMenu(...menuItems: (ContextMenuItem | false | null | undefined)[]): Attachment<HTMLElement> {
|
|
21
|
+
return function _attachContextMenu(element: HTMLElement) {
|
|
22
22
|
const menu = document.createElement('div');
|
|
23
23
|
menu.popover = 'auto';
|
|
24
24
|
menu.className = 'context-menu';
|
|
@@ -88,6 +88,29 @@ export function contextMenu(...menuItems: (ContextMenuItem | false | null | unde
|
|
|
88
88
|
for (const icon of mountedIcons) unmount(icon);
|
|
89
89
|
menu.remove();
|
|
90
90
|
};
|
|
91
|
-
}
|
|
92
|
-
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function dynamicRows(max: number = 40, min: number = 3): Attachment<HTMLTextAreaElement> {
|
|
95
|
+
return function _attackDynamicRows(element: HTMLTextAreaElement) {
|
|
96
|
+
element.style.resize = 'none';
|
|
97
|
+
// @ts-expect-error field-sizing is not yet in the types
|
|
98
|
+
element.style.fieldSizing = 'content';
|
|
99
|
+
element.style.height = 'max-content';
|
|
100
|
+
element.style.overflowY = 'scroll';
|
|
101
|
+
|
|
102
|
+
function update() {
|
|
103
|
+
if (!element.value) return;
|
|
104
|
+
element.rows = Math.max(Math.min(element.value.split('\n').length, max), min);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!navigator.userAgent.includes('Firefox')) return;
|
|
108
|
+
update();
|
|
109
|
+
element.addEventListener('input', update);
|
|
110
|
+
element.addEventListener('keyup', update);
|
|
111
|
+
return () => {
|
|
112
|
+
element.removeEventListener('input', update);
|
|
113
|
+
element.removeEventListener('keyup', update);
|
|
114
|
+
};
|
|
115
|
+
};
|
|
93
116
|
}
|