@vertexvis/ui 0.1.1-canary.4 → 0.1.1
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/README.md +1 -1
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/tooltip-634eb8c9.js +333 -0
- package/dist/cjs/vertex-tooltip.cjs.entry.js +1 -1
- package/dist/components/components.esm.js +1 -1
- package/dist/components/index.esm.js +1 -1
- package/dist/components/p-3b794014.entry.js +1 -0
- package/dist/components/p-5fb1724f.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/tooltip-bed548f4.js +331 -0
- package/dist/esm/vertex-tooltip.entry.js +1 -1
- package/package.json +3 -3
- package/dist/cjs/tooltip-9d097c55.js +0 -2188
- package/dist/components/p-45848878.js +0 -1
- package/dist/components/p-cbfc041e.entry.js +0 -1
- package/dist/esm/tooltip-db8ebd41.js +0 -2186
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { r as registerInstance, h, H as Host, g as getElement } from './index-72f28b71.js';
|
|
2
|
+
import { _ as __extends, a as __read } from './tslib.es6-99cd0de8.js';
|
|
3
|
+
import { c as classnames } from './index-9c609209.js';
|
|
4
|
+
import { g as getBoundingClientRect } from './dom-9d0f7bf4.js';
|
|
5
|
+
import { a as getSlottedContent } from './slots-fbb5afb3.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A module for defining functional schemas to map between different types. This
|
|
9
|
+
* module is useful for parsing to or from JSON/protobufs to domain types.
|
|
10
|
+
*
|
|
11
|
+
* Mappers support greedy validation, so all validation errors are aggregated
|
|
12
|
+
* and reported vs failing on the first invalid input.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { Mapper as M } from '@vertexvis/utils';
|
|
18
|
+
*
|
|
19
|
+
* interface Address {
|
|
20
|
+
* address: string;
|
|
21
|
+
* city: string;
|
|
22
|
+
* state: string;
|
|
23
|
+
* zip: string;
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* interface Person {
|
|
27
|
+
* name: string;
|
|
28
|
+
* addresses: Address[];
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* type AddressJson = Partial<Address>;
|
|
32
|
+
* type PersonJson = {
|
|
33
|
+
* name?: string;
|
|
34
|
+
* addresses?: AddressJson[];
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* const mapAddress: M.Func<AddressJson, Address> = M.defineMapper(
|
|
38
|
+
* M.read(
|
|
39
|
+
* M.requireProp('address'),
|
|
40
|
+
* M.requireProp('city'),
|
|
41
|
+
* M.requireProp('state'),
|
|
42
|
+
* M.requireProp('zip')
|
|
43
|
+
* ),
|
|
44
|
+
* ([address, city, state, zip]) => ({
|
|
45
|
+
* address, city, state, zip
|
|
46
|
+
* })
|
|
47
|
+
* );
|
|
48
|
+
*
|
|
49
|
+
* const mapPerson: M.Func<PersonJson, Person> = M.defineMapper(
|
|
50
|
+
* M.read(
|
|
51
|
+
* M.requireProp('name'),
|
|
52
|
+
* M.mapProp(
|
|
53
|
+
* 'addresses',
|
|
54
|
+
* M.compose(M.required('addresses'), M.mapArray(mapAddress))
|
|
55
|
+
* )
|
|
56
|
+
* ),
|
|
57
|
+
* ([name, addresses]) => ({ name, addresses })
|
|
58
|
+
* );
|
|
59
|
+
*
|
|
60
|
+
* const person = mapPerson({
|
|
61
|
+
* name: 'John',
|
|
62
|
+
* addresses: [{ address: '123', city: 'Ames', state: 'IA', zip: '50010' }]
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* const invalidPerson = mapPerson({
|
|
66
|
+
* addresses: [{ city: 'Ames', state: 'IA', zip: '50010' }]
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
* // {
|
|
70
|
+
* // errors: ["Name is required.", "Address is required."]
|
|
71
|
+
* // }
|
|
72
|
+
*
|
|
73
|
+
* @module
|
|
74
|
+
*/
|
|
75
|
+
/**
|
|
76
|
+
* An error that is thrown when validation of a schema fails.
|
|
77
|
+
*
|
|
78
|
+
* @see {@link ifInvalidThrow} - for throwing errors on invalid input.
|
|
79
|
+
*/
|
|
80
|
+
/** @class */ ((function (_super) {
|
|
81
|
+
__extends(MapperValidationError, _super);
|
|
82
|
+
function MapperValidationError(errors) {
|
|
83
|
+
var _this = _super.call(this, 'Validation error mapping object.') || this;
|
|
84
|
+
_this.errors = errors;
|
|
85
|
+
Object.setPrototypeOf(_this, MapperValidationError.prototype);
|
|
86
|
+
return _this;
|
|
87
|
+
}
|
|
88
|
+
return MapperValidationError;
|
|
89
|
+
})(Error));
|
|
90
|
+
|
|
91
|
+
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
|
92
|
+
// require the crypto API and do not support built-in fallback to lower quality random number
|
|
93
|
+
// generators (like Math.random()).
|
|
94
|
+
var getRandomValues;
|
|
95
|
+
var rnds8 = new Uint8Array(16);
|
|
96
|
+
function rng() {
|
|
97
|
+
// lazy load so that environments that need to polyfill have a chance to do so
|
|
98
|
+
if (!getRandomValues) {
|
|
99
|
+
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
|
|
100
|
+
// find the complete implementation of crypto (msCrypto) on IE11.
|
|
101
|
+
getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
|
|
102
|
+
|
|
103
|
+
if (!getRandomValues) {
|
|
104
|
+
throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return getRandomValues(rnds8);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
112
|
+
|
|
113
|
+
function validate(uuid) {
|
|
114
|
+
return typeof uuid === 'string' && REGEX.test(uuid);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Convert array of 16 byte values to UUID string format of the form:
|
|
119
|
+
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
var byteToHex = [];
|
|
123
|
+
|
|
124
|
+
for (var i = 0; i < 256; ++i) {
|
|
125
|
+
byteToHex.push((i + 0x100).toString(16).substr(1));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function stringify(arr) {
|
|
129
|
+
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
130
|
+
// Note: Be careful editing this code! It's been tuned for performance
|
|
131
|
+
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
132
|
+
var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
|
|
133
|
+
// of the following:
|
|
134
|
+
// - One or more input array values don't map to a hex octet (leading to
|
|
135
|
+
// "undefined" in the uuid)
|
|
136
|
+
// - Invalid input values for the RFC `version` or `variant` fields
|
|
137
|
+
|
|
138
|
+
if (!validate(uuid)) {
|
|
139
|
+
throw TypeError('Stringified UUID is invalid');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return uuid;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function v4(options, buf, offset) {
|
|
146
|
+
options = options || {};
|
|
147
|
+
var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
148
|
+
|
|
149
|
+
rnds[6] = rnds[6] & 0x0f | 0x40;
|
|
150
|
+
rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
|
|
151
|
+
|
|
152
|
+
if (buf) {
|
|
153
|
+
offset = offset || 0;
|
|
154
|
+
|
|
155
|
+
for (var i = 0; i < 16; ++i) {
|
|
156
|
+
buf[offset + i] = rnds[i];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return buf;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return stringify(rnds);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function create() {
|
|
166
|
+
return v4();
|
|
167
|
+
}
|
|
168
|
+
function fromMsbLsb(msb, lsb) {
|
|
169
|
+
function digits(val, ds) {
|
|
170
|
+
var hi = BigInt(1) << (ds * BigInt(4));
|
|
171
|
+
return (hi | (val & (hi - BigInt(1)))).toString(16).substring(1);
|
|
172
|
+
}
|
|
173
|
+
var msbB = typeof msb === 'string' ? BigInt(msb) : msb;
|
|
174
|
+
var lsbB = typeof lsb === 'string' ? BigInt(lsb) : lsb;
|
|
175
|
+
var sec1 = digits(msbB >> BigInt(32), BigInt(8));
|
|
176
|
+
var sec2 = digits(msbB >> BigInt(16), BigInt(4));
|
|
177
|
+
var sec3 = digits(msbB, BigInt(4));
|
|
178
|
+
var sec4 = digits(lsbB >> BigInt(48), BigInt(4));
|
|
179
|
+
var sec5 = digits(lsbB, BigInt(12));
|
|
180
|
+
return "".concat(sec1, "-").concat(sec2, "-").concat(sec3, "-").concat(sec4, "-").concat(sec5);
|
|
181
|
+
}
|
|
182
|
+
function toMsbLsb(id) {
|
|
183
|
+
var _a = __read(id.split('-'), 5), c1 = _a[0], c2 = _a[1], c3 = _a[2], c4 = _a[3], c5 = _a[4];
|
|
184
|
+
if (c1 == null || c2 == null || c3 == null || c4 == null || c5 == null) {
|
|
185
|
+
throw new Error("Invalid UUID string ".concat(id));
|
|
186
|
+
}
|
|
187
|
+
var msb = BigInt.asIntN(64, BigInt("0x".concat(c1 + c2 + c3)));
|
|
188
|
+
var lsb = BigInt.asIntN(64, BigInt("0x".concat(c4 + c5)));
|
|
189
|
+
return { msb: msb.toString(), lsb: lsb.toString() };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
var uuid = /*#__PURE__*/Object.freeze({
|
|
193
|
+
__proto__: null,
|
|
194
|
+
create: create,
|
|
195
|
+
fromMsbLsb: fromMsbLsb,
|
|
196
|
+
toMsbLsb: toMsbLsb
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const tooltipCss = ":host{--tooltip-width:auto;--tooltip-white-space:normal;display:flex}.popover{width:100%;height:100%}.target{display:flex;width:100%;height:100%}.content-hidden{display:none}.tooltip{display:flex;justify-content:center;text-align:center;width:var(--tooltip-width);font-family:var(--vertex-ui-font-family);font-size:var(--vertex-ui-text-xxs);background-color:var(--vertex-ui-neutral-700);color:var(--vertex-ui-white);padding:0.25rem 0.5rem;border-radius:4px;pointer-events:none;white-space:var(--tooltip-white-space);user-select:none}.tooltip.hidden{display:none}";
|
|
200
|
+
|
|
201
|
+
const TOOLTIP_OPEN_DELAY = 500;
|
|
202
|
+
const Tooltip = class {
|
|
203
|
+
constructor(hostRef) {
|
|
204
|
+
registerInstance(this, hostRef);
|
|
205
|
+
this.pointerEntered = false;
|
|
206
|
+
this.content = undefined;
|
|
207
|
+
this.disabled = undefined;
|
|
208
|
+
this.placement = 'bottom';
|
|
209
|
+
this.delay = TOOLTIP_OPEN_DELAY;
|
|
210
|
+
this.animated = true;
|
|
211
|
+
this.open = false;
|
|
212
|
+
this.handlePointerEnter = this.handlePointerEnter.bind(this);
|
|
213
|
+
this.handlePointerLeave = this.handlePointerLeave.bind(this);
|
|
214
|
+
this.handleContentChange = this.handleContentChange.bind(this);
|
|
215
|
+
this.handleDisabledChange = this.handleDisabledChange.bind(this);
|
|
216
|
+
this.tooltipId = `vertex-tooltip-${uuid.create()}`;
|
|
217
|
+
}
|
|
218
|
+
disconnectedCallback() {
|
|
219
|
+
this.removeElement();
|
|
220
|
+
this.clearOpenTimeout();
|
|
221
|
+
this.pointerEntered = false;
|
|
222
|
+
}
|
|
223
|
+
handleContentChange() {
|
|
224
|
+
if (this.internalContentElement != null) {
|
|
225
|
+
this.updateContentElementChildren(this.internalContentElement);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
handleDisabledChange() {
|
|
229
|
+
if (this.internalContentElement != null) {
|
|
230
|
+
this.updateContentElementClass(this.internalContentElement);
|
|
231
|
+
}
|
|
232
|
+
if (!this.disabled && this.pointerEntered) {
|
|
233
|
+
this.handlePointerEnter();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
render() {
|
|
237
|
+
return (h(Host, null, h("div", { class: "target", ref: (el) => {
|
|
238
|
+
this.targetElement = el;
|
|
239
|
+
}, onPointerEnter: this.handlePointerEnter, onPointerLeave: this.handlePointerLeave }, h("slot", null)), h("div", { class: "content-hidden", ref: (el) => {
|
|
240
|
+
this.contentElement = el;
|
|
241
|
+
} }, h("slot", { name: "content", onSlotchange: this.handleContentChange }))));
|
|
242
|
+
}
|
|
243
|
+
addElement() {
|
|
244
|
+
if (this.targetElement != null) {
|
|
245
|
+
const popover = this.createPopoverElement(this.targetElement);
|
|
246
|
+
const content = this.createContentElement();
|
|
247
|
+
this.updateContentElementChildren(content);
|
|
248
|
+
popover.appendChild(content);
|
|
249
|
+
this.hostElement.ownerDocument.body.appendChild(popover);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
removeElement() {
|
|
253
|
+
const popover = this.hostElement.ownerDocument.getElementById(this.tooltipId);
|
|
254
|
+
if (popover != null) {
|
|
255
|
+
popover.remove();
|
|
256
|
+
}
|
|
257
|
+
this.internalContentElement = undefined;
|
|
258
|
+
}
|
|
259
|
+
createPopoverElement(anchorElement) {
|
|
260
|
+
const popover = this.hostElement.ownerDocument.createElement('vertex-popover');
|
|
261
|
+
popover.id = this.tooltipId;
|
|
262
|
+
popover.setAttribute('class', 'vertex-tooltip-popover');
|
|
263
|
+
popover.open = this.open;
|
|
264
|
+
popover.resizeBehavior = 'fixed';
|
|
265
|
+
popover.backdrop = false;
|
|
266
|
+
popover.placement = this.placement;
|
|
267
|
+
popover.animated = this.animated;
|
|
268
|
+
popover.anchorBounds = getBoundingClientRect(anchorElement);
|
|
269
|
+
return popover;
|
|
270
|
+
}
|
|
271
|
+
createContentElement() {
|
|
272
|
+
this.internalContentElement =
|
|
273
|
+
this.hostElement.ownerDocument.createElement('div');
|
|
274
|
+
this.internalContentElement.setAttribute('class', classnames('vertex-tooltip-content', {
|
|
275
|
+
hidden: !this.open || this.disabled,
|
|
276
|
+
}));
|
|
277
|
+
return this.internalContentElement;
|
|
278
|
+
}
|
|
279
|
+
updateContentElementClass(element) {
|
|
280
|
+
element.setAttribute('class', classnames('vertex-tooltip-content', {
|
|
281
|
+
hidden: !this.open || this.disabled,
|
|
282
|
+
}));
|
|
283
|
+
}
|
|
284
|
+
updateContentElementChildren(element) {
|
|
285
|
+
var _a;
|
|
286
|
+
this.displayedSlottedContent =
|
|
287
|
+
(_a = getSlottedContent(this.contentElement)) !== null && _a !== void 0 ? _a : this.displayedSlottedContent;
|
|
288
|
+
if (this.content != null) {
|
|
289
|
+
element.innerText = this.content;
|
|
290
|
+
}
|
|
291
|
+
else if (this.displayedSlottedContent != null) {
|
|
292
|
+
element.appendChild(this.displayedSlottedContent);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
handlePointerEnter() {
|
|
296
|
+
if (this.openTimeout == null && !this.disabled) {
|
|
297
|
+
this.createOpenTimeout();
|
|
298
|
+
}
|
|
299
|
+
else if (this.openTimeout == null) {
|
|
300
|
+
this.pointerEntered = true;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
handlePointerLeave() {
|
|
304
|
+
this.clearOpenTimeout();
|
|
305
|
+
this.removeElement();
|
|
306
|
+
this.open = false;
|
|
307
|
+
this.pointerEntered = false;
|
|
308
|
+
}
|
|
309
|
+
createOpenTimeout() {
|
|
310
|
+
this.openTimeout = setTimeout(() => {
|
|
311
|
+
this.open = true;
|
|
312
|
+
this.openTimeout = undefined;
|
|
313
|
+
this.addElement();
|
|
314
|
+
}, this.delay);
|
|
315
|
+
this.pointerEntered = false;
|
|
316
|
+
}
|
|
317
|
+
clearOpenTimeout() {
|
|
318
|
+
if (this.openTimeout != null) {
|
|
319
|
+
clearTimeout(this.openTimeout);
|
|
320
|
+
this.openTimeout = undefined;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
get hostElement() { return getElement(this); }
|
|
324
|
+
static get watchers() { return {
|
|
325
|
+
"content": ["handleContentChange"],
|
|
326
|
+
"disabled": ["handleDisabledChange"]
|
|
327
|
+
}; }
|
|
328
|
+
};
|
|
329
|
+
Tooltip.style = tooltipCss;
|
|
330
|
+
|
|
331
|
+
export { Tooltip as T };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vertexvis/ui",
|
|
3
|
-
"version": "0.1.1
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "The Vertex UI component library.",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -84,8 +84,8 @@
|
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
86
|
"@floating-ui/dom": "^1.6.5",
|
|
87
|
-
"@vertexvis/utils": "^0.
|
|
87
|
+
"@vertexvis/utils": "^0.23.2",
|
|
88
88
|
"fast-deep-equal": "^3.1.3"
|
|
89
89
|
},
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "0ebf1efa87266ea287cab323d705a0e439bab95f"
|
|
91
91
|
}
|