@nectary/components 0.42.1 → 0.44.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/accordion/index.js +3 -3
- package/action-menu/index.js +1 -2
- package/card-container/index.js +1 -1
- package/color-menu/index.d.ts +3 -3
- package/color-menu/index.js +2 -3
- package/color-menu/types.d.ts +2 -2
- package/date-picker/index.js +173 -64
- package/date-picker/types.d.ts +6 -0
- package/date-picker/utils.d.ts +6 -3
- package/date-picker/utils.js +19 -4
- package/dialog/index.js +2 -2
- package/emoji/index.d.ts +11 -0
- package/emoji/index.js +47 -0
- package/emoji/types.d.ts +11 -0
- package/emoji/types.js +1 -0
- package/emoji/utils.d.ts +1 -0
- package/emoji/utils.js +46 -0
- package/emoji-picker/index.d.ts +28 -0
- package/emoji-picker/index.js +319 -0
- package/emoji-picker/types.d.ts +25 -0
- package/emoji-picker/types.js +1 -0
- package/file-drop/types.d.ts +2 -2
- package/file-picker/types.d.ts +1 -1
- package/icon/index.d.ts +11 -0
- package/icon/index.js +32 -0
- package/icon/types.d.ts +11 -0
- package/icon/types.js +1 -0
- package/icon-button/index.js +1 -1
- package/package.json +2 -2
- package/pop/index.js +1 -2
- package/popover/index.js +1 -2
- package/segment/index.js +1 -1
- package/segmented-icon-control/index.js +3 -3
- package/select-menu/index.js +3 -4
- package/stop-events/index.js +3 -3
- package/tabs/index.js +24 -76
- package/tabs/types.d.ts +9 -2
- package/tabs-icon-option/index.d.ts +11 -0
- package/tabs-icon-option/index.js +75 -0
- package/tabs-icon-option/types.d.ts +19 -0
- package/tabs-icon-option/types.js +1 -0
- package/tabs-option/index.d.ts +1 -0
- package/tabs-option/index.js +8 -15
- package/tabs-option/types.d.ts +13 -5
- package/theme/emoji.css +6 -0
- package/theme/fonts.css +9 -0
- package/theme/fonts.json +9 -0
- package/theme/icon.css +7 -0
- package/theme.css +2 -0
- package/tile-control/index.js +3 -3
- package/tooltip/index.js +78 -31
- package/utils/csv.d.ts +5 -0
- package/utils/csv.js +22 -0
- package/utils/dom.d.ts +30 -0
- package/utils/dom.js +143 -0
- package/utils/element.d.ts +12 -0
- package/utils/element.js +38 -0
- package/utils/get-react-event-handler.d.ts +1 -0
- package/utils/get-react-event-handler.js +8 -0
- package/utils/index.d.ts +8 -57
- package/utils/index.js +8 -301
- package/utils/rect.d.ts +4 -0
- package/utils/rect.js +29 -0
- package/utils/slot.d.ts +4 -0
- package/utils/slot.js +38 -0
- package/utils/throttle.d.ts +4 -0
- package/utils/throttle.js +25 -0
- /package/{utils/animation.d.ts → tooltip/tooltip-state.d.ts} +0 -0
- /package/{utils/animation.js → tooltip/tooltip-state.js} +0 -0
package/utils/index.js
CHANGED
|
@@ -1,301 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
nectaryDefinitions.set(name, constructor);
|
|
12
|
-
};
|
|
13
|
-
export const setNectaryRegistry = registry => {
|
|
14
|
-
if (nectaryRegistry !== null) {
|
|
15
|
-
throw new Error('Nectary elements already registered');
|
|
16
|
-
}
|
|
17
|
-
nectaryRegistry = registry;
|
|
18
|
-
for (const [name, ctor] of nectaryDefinitions.entries()) {
|
|
19
|
-
if (nectaryRegistry.get(name) == null) {
|
|
20
|
-
nectaryRegistry.define(name, ctor);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
nectaryDefinitions.clear();
|
|
24
|
-
};
|
|
25
|
-
export class NectaryElement extends HTMLElement {
|
|
26
|
-
attachShadow(options) {
|
|
27
|
-
return super.attachShadow({
|
|
28
|
-
mode: 'closed',
|
|
29
|
-
delegatesFocus: false,
|
|
30
|
-
customElements: nectaryRegistry,
|
|
31
|
-
...options
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
version = pkg.version;
|
|
35
|
-
get focusable() {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export const getReactEventHandler = ($element, handlerName) => {
|
|
40
|
-
for (const key in $element) {
|
|
41
|
-
if (key.startsWith('__reactProps$')) {
|
|
42
|
-
return $element[key][handlerName];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
};
|
|
47
|
-
export const updateExplicitBooleanAttribute = ($element, attrName, attrValue) => {
|
|
48
|
-
$element.setAttribute(attrName, attrValue === true ? 'true' : 'false');
|
|
49
|
-
};
|
|
50
|
-
export const isAttrTrue = attrValue => {
|
|
51
|
-
return attrValue === '' || attrValue !== 'false' && attrValue !== null;
|
|
52
|
-
};
|
|
53
|
-
export const getBooleanAttribute = ($element, attrName) => {
|
|
54
|
-
return isAttrTrue($element.getAttribute(attrName));
|
|
55
|
-
};
|
|
56
|
-
export const updateBooleanAttribute = ($element, attrName, attrValue) => {
|
|
57
|
-
const currentAttrValue = $element.getAttribute(attrName);
|
|
58
|
-
if (attrValue === true) {
|
|
59
|
-
if (!isAttrTrue(currentAttrValue)) {
|
|
60
|
-
$element.setAttribute(attrName, '');
|
|
61
|
-
}
|
|
62
|
-
} else if (currentAttrValue !== null) {
|
|
63
|
-
$element.removeAttribute(attrName);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
export const updateAttribute = ($element, attrName, attrValue) => {
|
|
67
|
-
if (attrValue != null) {
|
|
68
|
-
$element.setAttribute(attrName, String(attrValue));
|
|
69
|
-
} else {
|
|
70
|
-
$element.removeAttribute(attrName);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
export function getAttribute($element, attrName) {
|
|
74
|
-
let defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
75
|
-
return $element.getAttribute(attrName) ?? defaultValue;
|
|
76
|
-
}
|
|
77
|
-
export const isLiteralValue = (literals, value) => {
|
|
78
|
-
return value != null && literals.includes(value);
|
|
79
|
-
};
|
|
80
|
-
export const updateLiteralAttribute = ($element, literals, attrName, attrValue) => {
|
|
81
|
-
if (isLiteralValue(literals, attrValue)) {
|
|
82
|
-
$element.setAttribute(attrName, attrValue);
|
|
83
|
-
} else {
|
|
84
|
-
$element.removeAttribute(attrName);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
export function getLiteralAttribute($element, literals, attrName, defaultValue) {
|
|
88
|
-
const attrValue = $element.getAttribute(attrName);
|
|
89
|
-
if (isLiteralValue(literals, attrValue)) {
|
|
90
|
-
return attrValue;
|
|
91
|
-
}
|
|
92
|
-
if (typeof defaultValue === 'undefined') {
|
|
93
|
-
throw new Error(`Invalid attribute value: ${attrName} = ${attrValue}`);
|
|
94
|
-
}
|
|
95
|
-
return defaultValue;
|
|
96
|
-
}
|
|
97
|
-
export const clampNumber = (value, min, max) => {
|
|
98
|
-
return Math.min(max, Math.max(min, value));
|
|
99
|
-
};
|
|
100
|
-
const DEFAULT_INTEGER_OPTIONS = {
|
|
101
|
-
itemSizeMultiplier: 1,
|
|
102
|
-
itemSpaceBetween: 0,
|
|
103
|
-
defaultValue: null
|
|
104
|
-
};
|
|
105
|
-
const applyRange = (value, _ref) => {
|
|
106
|
-
let {
|
|
107
|
-
min,
|
|
108
|
-
max
|
|
109
|
-
} = _ref;
|
|
110
|
-
let result = value;
|
|
111
|
-
if (min != null) {
|
|
112
|
-
result = Math.max(min, result);
|
|
113
|
-
}
|
|
114
|
-
if (max != null) {
|
|
115
|
-
result = Math.min(max, result);
|
|
116
|
-
}
|
|
117
|
-
return result;
|
|
118
|
-
};
|
|
119
|
-
export const attrValueToInteger = function (value) {
|
|
120
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_INTEGER_OPTIONS;
|
|
121
|
-
const {
|
|
122
|
-
defaultValue = null,
|
|
123
|
-
itemSizeMultiplier = 1,
|
|
124
|
-
itemSpaceBetween = 0
|
|
125
|
-
} = options;
|
|
126
|
-
let intValue = defaultValue;
|
|
127
|
-
if (value !== null) {
|
|
128
|
-
const int = parseInt(value);
|
|
129
|
-
if (Number.isInteger(int)) {
|
|
130
|
-
intValue = applyRange(int, options);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (intValue !== null) {
|
|
134
|
-
return intValue * itemSizeMultiplier + Math.max(intValue - 1, 0) * itemSpaceBetween;
|
|
135
|
-
}
|
|
136
|
-
return null;
|
|
137
|
-
};
|
|
138
|
-
export const attrValueToPixels = function (value) {
|
|
139
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_INTEGER_OPTIONS;
|
|
140
|
-
const int = attrValueToInteger(value, options);
|
|
141
|
-
return int === null ? 'unset' : `${int}px`;
|
|
142
|
-
};
|
|
143
|
-
export const updateIntegerAttribute = function ($element, attrName, attrValue) {
|
|
144
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_INTEGER_OPTIONS;
|
|
145
|
-
const {
|
|
146
|
-
defaultValue = null,
|
|
147
|
-
itemSizeMultiplier: multiplier = 1
|
|
148
|
-
} = options;
|
|
149
|
-
let intValue = null;
|
|
150
|
-
if (typeof attrValue === 'string') {
|
|
151
|
-
intValue = attrValueToInteger(attrValue, options);
|
|
152
|
-
} else if (typeof attrValue === 'number') {
|
|
153
|
-
intValue = applyRange(attrValue, options) * multiplier;
|
|
154
|
-
} else {
|
|
155
|
-
intValue = defaultValue;
|
|
156
|
-
}
|
|
157
|
-
if (intValue === null) {
|
|
158
|
-
$element.removeAttribute(attrName);
|
|
159
|
-
} else {
|
|
160
|
-
$element.setAttribute(attrName, intValue.toFixed(0));
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
export function getIntegerAttribute($element, attrName, defaultValue) {
|
|
164
|
-
return attrValueToInteger($element.getAttribute(attrName)) ?? defaultValue;
|
|
165
|
-
}
|
|
166
|
-
const unpackCsv = csv => {
|
|
167
|
-
return csv === '' ? [] : csv.split(',');
|
|
168
|
-
};
|
|
169
|
-
const packCsv = values => {
|
|
170
|
-
return Array.from(values).join(',');
|
|
171
|
-
};
|
|
172
|
-
export const getCsvSet = acc => {
|
|
173
|
-
return new Set(unpackCsv(acc));
|
|
174
|
-
};
|
|
175
|
-
export const updateCsv = (acc, value, setActive) => {
|
|
176
|
-
const values = getCsvSet(acc);
|
|
177
|
-
if (setActive) {
|
|
178
|
-
values.add(value);
|
|
179
|
-
} else {
|
|
180
|
-
values.delete(value);
|
|
181
|
-
}
|
|
182
|
-
return packCsv(values);
|
|
183
|
-
};
|
|
184
|
-
export const getFirstCsvValue = acc => {
|
|
185
|
-
return acc === '' ? null : unpackCsv(acc)[0];
|
|
186
|
-
};
|
|
187
|
-
export const getRect = el => {
|
|
188
|
-
const {
|
|
189
|
-
x,
|
|
190
|
-
y,
|
|
191
|
-
width,
|
|
192
|
-
height
|
|
193
|
-
} = el.getBoundingClientRect();
|
|
194
|
-
return {
|
|
195
|
-
x,
|
|
196
|
-
y,
|
|
197
|
-
width,
|
|
198
|
-
height
|
|
199
|
-
};
|
|
200
|
-
};
|
|
201
|
-
export const setClass = (elem, name, isSet) => {
|
|
202
|
-
isSet ? elem.classList.add(name) : elem.classList.remove(name);
|
|
203
|
-
};
|
|
204
|
-
export const getCssVar = (element, variableName) => {
|
|
205
|
-
const result = getComputedStyle(element).getPropertyValue(variableName);
|
|
206
|
-
return result === '' ? null : result;
|
|
207
|
-
};
|
|
208
|
-
const throttle = (delayFn, cancelFn) => cb => {
|
|
209
|
-
let id = null;
|
|
210
|
-
let fnArgs;
|
|
211
|
-
const delayCallback = () => {
|
|
212
|
-
id = null;
|
|
213
|
-
cb(fnArgs);
|
|
214
|
-
};
|
|
215
|
-
return {
|
|
216
|
-
fn: function () {
|
|
217
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
218
|
-
args[_key] = arguments[_key];
|
|
219
|
-
}
|
|
220
|
-
fnArgs = args;
|
|
221
|
-
if (id === null) {
|
|
222
|
-
id = delayFn(delayCallback);
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
cancel: () => {
|
|
226
|
-
if (id !== null) {
|
|
227
|
-
cancelFn(id);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
};
|
|
232
|
-
export const throttleAnimationFrame = throttle(global.requestAnimationFrame, global.cancelAnimationFrame);
|
|
233
|
-
const isSlotElement = el => {
|
|
234
|
-
return el.tagName === 'SLOT';
|
|
235
|
-
};
|
|
236
|
-
export const getFirstSlotElement = function (root) {
|
|
237
|
-
let isDeep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
238
|
-
const el = root.assignedElements()[0];
|
|
239
|
-
if (el == null) {
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
if (isDeep && isSlotElement(el)) {
|
|
243
|
-
return getFirstSlotElement(el, isDeep);
|
|
244
|
-
}
|
|
245
|
-
return el;
|
|
246
|
-
};
|
|
247
|
-
const getChildren = root => {
|
|
248
|
-
if (isSlotElement(root)) {
|
|
249
|
-
return root.assignedElements();
|
|
250
|
-
}
|
|
251
|
-
return Array.from(root.children);
|
|
252
|
-
};
|
|
253
|
-
const isFocusable = el => {
|
|
254
|
-
return el.focusable === true;
|
|
255
|
-
};
|
|
256
|
-
export const getFirstFocusableElement = root => {
|
|
257
|
-
for (const child of getChildren(root)) {
|
|
258
|
-
if (isFocusable(child)) {
|
|
259
|
-
return child;
|
|
260
|
-
}
|
|
261
|
-
const resultEl = getFirstFocusableElement(child);
|
|
262
|
-
if (resultEl !== null) {
|
|
263
|
-
return resultEl;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
return null;
|
|
267
|
-
};
|
|
268
|
-
export const cloneNode = (el, deep) => {
|
|
269
|
-
const root = el.getRootNode();
|
|
270
|
-
if (root !== document && Reflect.has(root, 'createElement')) {
|
|
271
|
-
const cloned = root.createElement(el.tagName.toLowerCase());
|
|
272
|
-
for (const attr of el.getAttributeNames()) {
|
|
273
|
-
cloned.setAttribute(attr, el.getAttribute(attr));
|
|
274
|
-
}
|
|
275
|
-
if (deep) {
|
|
276
|
-
for (let i = 0; i < el.children.length; i++) {
|
|
277
|
-
const clonedChild = cloneNode(el.children[i], deep);
|
|
278
|
-
cloned.appendChild(clonedChild);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
return cloned;
|
|
282
|
-
}
|
|
283
|
-
return el.cloneNode(deep);
|
|
284
|
-
};
|
|
285
|
-
export const isElementFocused = $el => {
|
|
286
|
-
return $el !== null && $el === $el.getRootNode().activeElement;
|
|
287
|
-
};
|
|
288
|
-
export const rectOverlap = (targetRect, contentRect) => {
|
|
289
|
-
return targetRect.x < contentRect.x + contentRect.width && targetRect.x + targetRect.width > contentRect.x && targetRect.y < contentRect.y + contentRect.height && targetRect.y + targetRect.height > contentRect.y;
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
export const getTargetRect = slot => {
|
|
293
|
-
const item = getFirstSlotElement(slot, true);
|
|
294
|
-
if (item === null) {
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
if (Reflect.has(item, 'footprintRect')) {
|
|
298
|
-
return item.footprintRect;
|
|
299
|
-
}
|
|
300
|
-
return getRect(item);
|
|
301
|
-
};
|
|
1
|
+
export * from './context';
|
|
2
|
+
export * from './csv';
|
|
3
|
+
export * from './dom';
|
|
4
|
+
export * from './element';
|
|
5
|
+
export * from './rect';
|
|
6
|
+
export * from './slot';
|
|
7
|
+
export * from './throttle';
|
|
8
|
+
export * from './get-react-event-handler';
|
package/utils/rect.d.ts
ADDED
package/utils/rect.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getFirstSlotElement } from './slot';
|
|
2
|
+
export const getRect = el => {
|
|
3
|
+
const {
|
|
4
|
+
x,
|
|
5
|
+
y,
|
|
6
|
+
width,
|
|
7
|
+
height
|
|
8
|
+
} = el.getBoundingClientRect();
|
|
9
|
+
return {
|
|
10
|
+
x,
|
|
11
|
+
y,
|
|
12
|
+
width,
|
|
13
|
+
height
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export const rectOverlap = (targetRect, contentRect) => {
|
|
17
|
+
return targetRect.x < contentRect.x + contentRect.width && targetRect.x + targetRect.width > contentRect.x && targetRect.y < contentRect.y + contentRect.height && targetRect.y + targetRect.height > contentRect.y;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const getTargetRect = slot => {
|
|
21
|
+
const item = getFirstSlotElement(slot, true);
|
|
22
|
+
if (item === null) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (Reflect.has(item, 'footprintRect')) {
|
|
26
|
+
return item.footprintRect;
|
|
27
|
+
}
|
|
28
|
+
return getRect(item);
|
|
29
|
+
};
|
package/utils/slot.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NectaryElement } from './element';
|
|
2
|
+
export declare const getFirstSlotElement: (root: HTMLSlotElement, isDeep?: boolean) => HTMLElement | null;
|
|
3
|
+
export declare const getFirstFocusableElement: (root: Element) => NectaryElement | null;
|
|
4
|
+
export declare const isElementFocused: ($el: Element | null) => boolean;
|
package/utils/slot.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const isSlotElement = el => {
|
|
2
|
+
return el.tagName === 'SLOT';
|
|
3
|
+
};
|
|
4
|
+
export const getFirstSlotElement = function (root) {
|
|
5
|
+
let isDeep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
6
|
+
const el = root.assignedElements()[0];
|
|
7
|
+
if (el == null) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
if (isDeep && isSlotElement(el)) {
|
|
11
|
+
return getFirstSlotElement(el, isDeep);
|
|
12
|
+
}
|
|
13
|
+
return el;
|
|
14
|
+
};
|
|
15
|
+
const getChildren = root => {
|
|
16
|
+
if (isSlotElement(root)) {
|
|
17
|
+
return root.assignedElements();
|
|
18
|
+
}
|
|
19
|
+
return Array.from(root.children);
|
|
20
|
+
};
|
|
21
|
+
const isFocusable = el => {
|
|
22
|
+
return el.focusable === true;
|
|
23
|
+
};
|
|
24
|
+
export const getFirstFocusableElement = root => {
|
|
25
|
+
for (const child of getChildren(root)) {
|
|
26
|
+
if (isFocusable(child)) {
|
|
27
|
+
return child;
|
|
28
|
+
}
|
|
29
|
+
const resultEl = getFirstFocusableElement(child);
|
|
30
|
+
if (resultEl !== null) {
|
|
31
|
+
return resultEl;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
36
|
+
export const isElementFocused = $el => {
|
|
37
|
+
return $el !== null && $el === $el.getRootNode().activeElement;
|
|
38
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const throttle = (delayFn, cancelFn) => cb => {
|
|
2
|
+
let id = null;
|
|
3
|
+
let fnArgs;
|
|
4
|
+
const delayCallback = () => {
|
|
5
|
+
id = null;
|
|
6
|
+
cb(fnArgs);
|
|
7
|
+
};
|
|
8
|
+
return {
|
|
9
|
+
fn: function () {
|
|
10
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
11
|
+
args[_key] = arguments[_key];
|
|
12
|
+
}
|
|
13
|
+
fnArgs = args;
|
|
14
|
+
if (id === null) {
|
|
15
|
+
id = delayFn(delayCallback);
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
cancel: () => {
|
|
19
|
+
if (id !== null) {
|
|
20
|
+
cancelFn(id);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export const throttleAnimationFrame = throttle(global.requestAnimationFrame, global.cancelAnimationFrame);
|
|
File without changes
|
|
File without changes
|