1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | };
|
9 | return function (d, b) {
|
10 | if (typeof b !== "function" && b !== null)
|
11 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
12 | extendStatics(d, b);
|
13 | function __() { this.constructor = d; }
|
14 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15 | };
|
16 | })();
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.UID = void 0;
|
19 | var React = require("react");
|
20 | var context_1 = require("./context");
|
21 |
|
22 | var prefixId = function (id, prefix, name) {
|
23 | var uid = prefix + id;
|
24 | return String(name ? name(uid) : uid);
|
25 | };
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | var UID = (function (_super) {
|
42 | __extends(UID, _super);
|
43 | function UID() {
|
44 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
45 | _this.state = {
|
46 | quartz: _this.props.idSource || context_1.counter,
|
47 | prefix: (0, context_1.getPrefix)(_this.props.idSource),
|
48 | id: (0, context_1.getId)(_this.props.idSource || context_1.counter),
|
49 | };
|
50 | _this.uid = function (item) {
|
51 | return prefixId(_this.state.id + '-' + _this.state.quartz.uid(item), _this.state.prefix, _this.props.name);
|
52 | };
|
53 | return _this;
|
54 | }
|
55 | UID.prototype.render = function () {
|
56 | var _a = this.props, children = _a.children, name = _a.name;
|
57 | var _b = this.state, id = _b.id, prefix = _b.prefix;
|
58 | return children(prefixId(id, prefix, name), this.uid);
|
59 | };
|
60 | return UID;
|
61 | }(React.Component));
|
62 | exports.UID = UID;
|