@washingtonpost/subs-de-inputs 1.0.0-react18.0 → 1.0.0-react18.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/dist/components/DESelect/Dropdown.d.ts +17 -0
- package/dist/components/DESelect/index.d.ts +0 -5
- package/dist/index.d.ts +1 -0
- package/dist/interfaces/index.d.ts +8 -0
- package/dist/interfaces/twpdeu.d.ts +11 -0
- package/dist/services/dataEnrichment.d.ts +18 -2
- package/dist/subs-de-inputs.cjs.development.js +305 -483
- package/dist/subs-de-inputs.cjs.development.js.map +1 -1
- package/dist/subs-de-inputs.cjs.production.min.js +1 -1
- package/dist/subs-de-inputs.cjs.production.min.js.map +1 -1
- package/dist/subs-de-inputs.esm.js +306 -486
- package/dist/subs-de-inputs.esm.js.map +1 -1
- package/package.json +23 -8
|
@@ -1,540 +1,360 @@
|
|
|
1
|
-
import { getCookie, WPGeo, JSON_HEADERS,
|
|
1
|
+
import { getCookie, WPGeo, JSON_HEADERS, ResponseStatus, ENDPOINTS } from '@washingtonpost/subs-sdk';
|
|
2
2
|
import React, { useState, useEffect } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { Icon, theme, Select, styled } from '@washingtonpost/wpds-ui-kit';
|
|
4
|
+
import { useWindowSize, useScript, ScriptStatus } from '@washingtonpost/subs-hooks';
|
|
5
|
+
import { ChevronDown } from '@washingtonpost/wpds-assets';
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
const CollectionBehaviors = {
|
|
6
8
|
COLLECT: 'COLLECT',
|
|
7
9
|
DO_NOT_COLLECT: 'DO_NOT_COLLECT'
|
|
8
10
|
};
|
|
9
|
-
|
|
11
|
+
const AttributesState = {
|
|
10
12
|
SUCCESS: '100'
|
|
11
13
|
};
|
|
12
|
-
|
|
14
|
+
const IngestType = {
|
|
15
|
+
EXPLICIT: 'explicit',
|
|
16
|
+
IMPLICIT: 'implicit'
|
|
17
|
+
};
|
|
18
|
+
const IngestResponseState = {
|
|
13
19
|
SUCCESS: '100',
|
|
14
20
|
SYSTEM_ERROR: '101',
|
|
15
21
|
INVALID_TYPE: '102',
|
|
16
22
|
INVALID_IDENTIFIER: '103',
|
|
17
23
|
INVALID_DATA: '104',
|
|
18
24
|
INVALID_ATTRIBUTE_DEFINITION: '105',
|
|
19
|
-
INVALID_META_DEFINITION: '106'
|
|
25
|
+
INVALID_META_DEFINITION: '106',
|
|
26
|
+
UNAUTHENTICATED: '107',
|
|
27
|
+
MISMATCHED_IDENTIFIER: '108',
|
|
28
|
+
DISABLED_ATTRIBUTE_DEFINITION: '109',
|
|
29
|
+
DO_NOT_COLLECT: '110'
|
|
20
30
|
};
|
|
21
31
|
|
|
22
|
-
|
|
32
|
+
const hasRequiredPrivacyCookies = () => {
|
|
23
33
|
var _WPGeo;
|
|
24
34
|
if (typeof window === 'undefined') {
|
|
25
35
|
return false;
|
|
26
36
|
}
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
const wp_usp = getCookie('wp_usp');
|
|
38
|
+
const countryCode = (_WPGeo = WPGeo()) === null || _WPGeo === void 0 ? void 0 : _WPGeo.country_code;
|
|
29
39
|
return !!(wp_usp && countryCode === 'US');
|
|
30
40
|
};
|
|
31
41
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
n = r.hasOwnProperty,
|
|
40
|
-
o = Object.defineProperty || function (t, e, r) {
|
|
41
|
-
t[e] = r.value;
|
|
42
|
-
},
|
|
43
|
-
i = "function" == typeof Symbol ? Symbol : {},
|
|
44
|
-
a = i.iterator || "@@iterator",
|
|
45
|
-
c = i.asyncIterator || "@@asyncIterator",
|
|
46
|
-
u = i.toStringTag || "@@toStringTag";
|
|
47
|
-
function define(t, e, r) {
|
|
48
|
-
return Object.defineProperty(t, e, {
|
|
49
|
-
value: r,
|
|
50
|
-
enumerable: !0,
|
|
51
|
-
configurable: !0,
|
|
52
|
-
writable: !0
|
|
53
|
-
}), t[e];
|
|
42
|
+
const base = `${ENDPOINTS.base}/de/v1`;
|
|
43
|
+
const attributesCache = {};
|
|
44
|
+
const getAttributes = async ({
|
|
45
|
+
fieldName
|
|
46
|
+
}) => {
|
|
47
|
+
if (attributesCache[fieldName]) {
|
|
48
|
+
return attributesCache[fieldName];
|
|
54
49
|
}
|
|
50
|
+
const fieldNames = [fieldName];
|
|
55
51
|
try {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
function wrap(t, e, r, n) {
|
|
63
|
-
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
64
|
-
a = Object.create(i.prototype),
|
|
65
|
-
c = new Context(n || []);
|
|
66
|
-
return o(a, "_invoke", {
|
|
67
|
-
value: makeInvokeMethod(t, r, c)
|
|
68
|
-
}), a;
|
|
69
|
-
}
|
|
70
|
-
function tryCatch(t, e, r) {
|
|
71
|
-
try {
|
|
72
|
-
return {
|
|
73
|
-
type: "normal",
|
|
74
|
-
arg: t.call(e, r)
|
|
75
|
-
};
|
|
76
|
-
} catch (t) {
|
|
77
|
-
return {
|
|
78
|
-
type: "throw",
|
|
79
|
-
arg: t
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
e.wrap = wrap;
|
|
84
|
-
var h = "suspendedStart",
|
|
85
|
-
l = "suspendedYield",
|
|
86
|
-
f = "executing",
|
|
87
|
-
s = "completed",
|
|
88
|
-
y = {};
|
|
89
|
-
function Generator() {}
|
|
90
|
-
function GeneratorFunction() {}
|
|
91
|
-
function GeneratorFunctionPrototype() {}
|
|
92
|
-
var p = {};
|
|
93
|
-
define(p, a, function () {
|
|
94
|
-
return this;
|
|
95
|
-
});
|
|
96
|
-
var d = Object.getPrototypeOf,
|
|
97
|
-
v = d && d(d(values([])));
|
|
98
|
-
v && v !== r && n.call(v, a) && (p = v);
|
|
99
|
-
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
100
|
-
function defineIteratorMethods(t) {
|
|
101
|
-
["next", "throw", "return"].forEach(function (e) {
|
|
102
|
-
define(t, e, function (t) {
|
|
103
|
-
return this._invoke(e, t);
|
|
104
|
-
});
|
|
52
|
+
const url = new URL(`${base}/attributes`);
|
|
53
|
+
url.searchParams.set('attributes', fieldNames.join(','));
|
|
54
|
+
const data = await fetch(url.toString(), {
|
|
55
|
+
credentials: 'include',
|
|
56
|
+
headers: JSON_HEADERS
|
|
105
57
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
114
|
-
invoke("next", t, i, a);
|
|
115
|
-
}, function (t) {
|
|
116
|
-
invoke("throw", t, i, a);
|
|
117
|
-
}) : e.resolve(h).then(function (t) {
|
|
118
|
-
u.value = t, i(u);
|
|
119
|
-
}, function (t) {
|
|
120
|
-
return invoke("throw", t, i, a);
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
a(c.arg);
|
|
58
|
+
const json = await data.json();
|
|
59
|
+
if (data.ok && json.status === ResponseStatus.SUCCESS) {
|
|
60
|
+
const attributes = json.attributes || [];
|
|
61
|
+
attributesCache[fieldName] = attributes;
|
|
62
|
+
return attributes;
|
|
63
|
+
} else {
|
|
64
|
+
return [];
|
|
124
65
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
function callInvokeWithMethodAndArg() {
|
|
129
|
-
return new e(function (e, r) {
|
|
130
|
-
invoke(t, n, e, r);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
function makeInvokeMethod(e, r, n) {
|
|
138
|
-
var o = h;
|
|
139
|
-
return function (i, a) {
|
|
140
|
-
if (o === f) throw Error("Generator is already running");
|
|
141
|
-
if (o === s) {
|
|
142
|
-
if ("throw" === i) throw a;
|
|
143
|
-
return {
|
|
144
|
-
value: t,
|
|
145
|
-
done: !0
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
for (n.method = i, n.arg = a;;) {
|
|
149
|
-
var c = n.delegate;
|
|
150
|
-
if (c) {
|
|
151
|
-
var u = maybeInvokeDelegate(c, n);
|
|
152
|
-
if (u) {
|
|
153
|
-
if (u === y) continue;
|
|
154
|
-
return u;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
158
|
-
if (o === h) throw o = s, n.arg;
|
|
159
|
-
n.dispatchException(n.arg);
|
|
160
|
-
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
161
|
-
o = f;
|
|
162
|
-
var p = tryCatch(e, r, n);
|
|
163
|
-
if ("normal" === p.type) {
|
|
164
|
-
if (o = n.done ? s : l, p.arg === y) continue;
|
|
165
|
-
return {
|
|
166
|
-
value: p.arg,
|
|
167
|
-
done: n.done
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
function maybeInvokeDelegate(e, r) {
|
|
175
|
-
var n = r.method,
|
|
176
|
-
o = e.iterator[n];
|
|
177
|
-
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
178
|
-
var i = tryCatch(o, e.iterator, r.arg);
|
|
179
|
-
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
180
|
-
var a = i.arg;
|
|
181
|
-
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
182
|
-
}
|
|
183
|
-
function pushTryEntry(t) {
|
|
184
|
-
var e = {
|
|
185
|
-
tryLoc: t[0]
|
|
186
|
-
};
|
|
187
|
-
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.debug(e);
|
|
68
|
+
return [];
|
|
188
69
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
70
|
+
};
|
|
71
|
+
const ingest = async ({
|
|
72
|
+
submitData: {
|
|
73
|
+
fieldName,
|
|
74
|
+
value
|
|
75
|
+
},
|
|
76
|
+
type = IngestType.IMPLICIT,
|
|
77
|
+
source
|
|
78
|
+
}) => {
|
|
79
|
+
const url = `${base}/ingest`;
|
|
80
|
+
const wapo_login_id = getCookie('wapo_login_id');
|
|
81
|
+
if (!hasRequiredPrivacyCookies()) {
|
|
82
|
+
throw new Error('does not satisfy cookie check');
|
|
192
83
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
84
|
+
let attributeInfo = attributesCache[fieldName];
|
|
85
|
+
if (!attributeInfo) {
|
|
86
|
+
attributeInfo = await getAttributes({
|
|
87
|
+
fieldName
|
|
88
|
+
});
|
|
197
89
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
var r = e[a];
|
|
201
|
-
if (r) return r.call(e);
|
|
202
|
-
if ("function" == typeof e.next) return e;
|
|
203
|
-
if (!isNaN(e.length)) {
|
|
204
|
-
var o = -1,
|
|
205
|
-
i = function next() {
|
|
206
|
-
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
207
|
-
return next.value = t, next.done = !0, next;
|
|
208
|
-
};
|
|
209
|
-
return i.next = i;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
throw new TypeError(typeof e + " is not iterable");
|
|
90
|
+
if (attributeInfo[0] && attributeInfo[0].name === fieldName && attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT) {
|
|
91
|
+
throw new Error('do not collect');
|
|
213
92
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
225
|
-
}, e.awrap = function (t) {
|
|
226
|
-
return {
|
|
227
|
-
__await: t
|
|
228
|
-
};
|
|
229
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
230
|
-
return this;
|
|
231
|
-
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
232
|
-
void 0 === i && (i = Promise);
|
|
233
|
-
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
234
|
-
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
235
|
-
return t.done ? t.value : a.next();
|
|
236
|
-
});
|
|
237
|
-
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
238
|
-
return this;
|
|
239
|
-
}), define(g, "toString", function () {
|
|
240
|
-
return "[object Generator]";
|
|
241
|
-
}), e.keys = function (t) {
|
|
242
|
-
var e = Object(t),
|
|
243
|
-
r = [];
|
|
244
|
-
for (var n in e) r.push(n);
|
|
245
|
-
return r.reverse(), function next() {
|
|
246
|
-
for (; r.length;) {
|
|
247
|
-
var t = r.pop();
|
|
248
|
-
if (t in e) return next.value = t, next.done = !1, next;
|
|
249
|
-
}
|
|
250
|
-
return next.done = !0, next;
|
|
251
|
-
};
|
|
252
|
-
}, e.values = values, Context.prototype = {
|
|
253
|
-
constructor: Context,
|
|
254
|
-
reset: function (e) {
|
|
255
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
256
|
-
},
|
|
257
|
-
stop: function () {
|
|
258
|
-
this.done = !0;
|
|
259
|
-
var t = this.tryEntries[0].completion;
|
|
260
|
-
if ("throw" === t.type) throw t.arg;
|
|
261
|
-
return this.rval;
|
|
262
|
-
},
|
|
263
|
-
dispatchException: function (e) {
|
|
264
|
-
if (this.done) throw e;
|
|
265
|
-
var r = this;
|
|
266
|
-
function handle(n, o) {
|
|
267
|
-
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
268
|
-
}
|
|
269
|
-
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
270
|
-
var i = this.tryEntries[o],
|
|
271
|
-
a = i.completion;
|
|
272
|
-
if ("root" === i.tryLoc) return handle("end");
|
|
273
|
-
if (i.tryLoc <= this.prev) {
|
|
274
|
-
var c = n.call(i, "catchLoc"),
|
|
275
|
-
u = n.call(i, "finallyLoc");
|
|
276
|
-
if (c && u) {
|
|
277
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
278
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
279
|
-
} else if (c) {
|
|
280
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
281
|
-
} else {
|
|
282
|
-
if (!u) throw Error("try statement without catch or finally");
|
|
283
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
},
|
|
288
|
-
abrupt: function (t, e) {
|
|
289
|
-
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
290
|
-
var o = this.tryEntries[r];
|
|
291
|
-
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
292
|
-
var i = o;
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
297
|
-
var a = i ? i.completion : {};
|
|
298
|
-
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
299
|
-
},
|
|
300
|
-
complete: function (t, e) {
|
|
301
|
-
if ("throw" === t.type) throw t.arg;
|
|
302
|
-
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
303
|
-
},
|
|
304
|
-
finish: function (t) {
|
|
305
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
306
|
-
var r = this.tryEntries[e];
|
|
307
|
-
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
308
|
-
}
|
|
309
|
-
},
|
|
310
|
-
catch: function (t) {
|
|
311
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
312
|
-
var r = this.tryEntries[e];
|
|
313
|
-
if (r.tryLoc === t) {
|
|
314
|
-
var n = r.completion;
|
|
315
|
-
if ("throw" === n.type) {
|
|
316
|
-
var o = n.arg;
|
|
317
|
-
resetTryEntry(r);
|
|
318
|
-
}
|
|
319
|
-
return o;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
throw Error("illegal catch attempt");
|
|
93
|
+
const jucid = localStorage.getItem('uuid');
|
|
94
|
+
const ga = getCookie('_ga');
|
|
95
|
+
const payload = {
|
|
96
|
+
jucid,
|
|
97
|
+
ga,
|
|
98
|
+
type,
|
|
99
|
+
wapo_login_id,
|
|
100
|
+
// TODO: move this to BE to read from cookie headers
|
|
101
|
+
data: {
|
|
102
|
+
[fieldName]: [value]
|
|
323
103
|
},
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
iterator: values(e),
|
|
327
|
-
resultName: r,
|
|
328
|
-
nextLoc: n
|
|
329
|
-
}, "next" === this.method && (this.arg = t), y;
|
|
104
|
+
metadata: {
|
|
105
|
+
source
|
|
330
106
|
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
107
|
+
};
|
|
334
108
|
try {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
109
|
+
const response = await fetch(url, {
|
|
110
|
+
method: 'POST',
|
|
111
|
+
credentials: 'include',
|
|
112
|
+
headers: JSON_HEADERS,
|
|
113
|
+
body: JSON.stringify(payload)
|
|
114
|
+
});
|
|
115
|
+
const json = await response.json();
|
|
116
|
+
return json;
|
|
117
|
+
} catch (e) {
|
|
118
|
+
console.debug(e);
|
|
119
|
+
return null;
|
|
340
120
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const StyledMobileSelect = /*#__PURE__*/styled('select', {
|
|
124
|
+
padding: '12px 16px 12px 6px',
|
|
125
|
+
display: 'flex',
|
|
126
|
+
justifyContent: 'space-between',
|
|
127
|
+
width: '100%',
|
|
128
|
+
backgroundColor: '$secondary',
|
|
129
|
+
color: '$primary',
|
|
130
|
+
fontFamily: '$meta',
|
|
131
|
+
fontSize: '$100',
|
|
132
|
+
fontWeight: '$light',
|
|
133
|
+
lineHeight: '$125',
|
|
134
|
+
paddingBlockRight: '$125',
|
|
135
|
+
textOverflow: 'ellipsis',
|
|
136
|
+
position: 'relative',
|
|
137
|
+
borderColor: 'transparent',
|
|
138
|
+
borderRightWidth: '10px',
|
|
139
|
+
borderRightColor: 'transparent',
|
|
140
|
+
appearance: 'none',
|
|
141
|
+
'-webkit-appearance': 'none',
|
|
142
|
+
'&:disabled': {
|
|
143
|
+
backgroundColor: theme.colors.disabled,
|
|
144
|
+
borderColor: theme.colors.disabled,
|
|
145
|
+
color: theme.colors.onDisabled,
|
|
146
|
+
cursor: 'not-allowed'
|
|
345
147
|
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
148
|
+
});
|
|
149
|
+
const StyledSelectWrapper = /*#__PURE__*/styled('div', {
|
|
150
|
+
width: '100%',
|
|
151
|
+
maxWidth: '380px',
|
|
152
|
+
borderRadius: '$012',
|
|
153
|
+
borderColor: '$subtle',
|
|
154
|
+
borderStyle: 'solid',
|
|
155
|
+
borderWidth: '1px',
|
|
156
|
+
backgroundColor: '$secondary',
|
|
157
|
+
position: 'relative'
|
|
158
|
+
});
|
|
159
|
+
const StyledMobileOption = /*#__PURE__*/styled('option', {
|
|
160
|
+
fontFamily: 'inherit',
|
|
161
|
+
fontSize: 'inherit',
|
|
162
|
+
color: 'inherit'
|
|
163
|
+
});
|
|
164
|
+
/**
|
|
165
|
+
* Dropdown component. Uses wpds-ui-kit on desktop and native select on mobile.
|
|
166
|
+
* @param {IDropdownProps} props The props.
|
|
167
|
+
* @returns {React.ReactElement} The dropdown.
|
|
168
|
+
*/
|
|
169
|
+
const Dropdown = ({
|
|
170
|
+
id,
|
|
171
|
+
label,
|
|
172
|
+
values,
|
|
173
|
+
required = false,
|
|
174
|
+
defaultValue,
|
|
175
|
+
onChange = () => {},
|
|
176
|
+
disabled = false
|
|
177
|
+
}) => {
|
|
178
|
+
const [answer, setAnswer] = useState();
|
|
179
|
+
const {
|
|
180
|
+
isMobileSize
|
|
181
|
+
} = useWindowSize();
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
if (answer) onChange(answer);
|
|
184
|
+
}, [answer]);
|
|
185
|
+
const disabledProp = disabled ? {
|
|
186
|
+
disabled: true
|
|
187
|
+
} : {};
|
|
188
|
+
// helps maintain state between WPDS and native dropdowns
|
|
189
|
+
const defaultValueProp = answer ? {
|
|
190
|
+
defaultValue: answer
|
|
191
|
+
} : defaultValue ? {
|
|
192
|
+
defaultValue
|
|
193
|
+
} : {};
|
|
194
|
+
const defaultValuePropMobile = value => {
|
|
195
|
+
if (answer) {
|
|
196
|
+
return value === answer ? {
|
|
197
|
+
selected: true
|
|
198
|
+
} : {};
|
|
372
199
|
}
|
|
373
|
-
return
|
|
200
|
+
return value === defaultValue ? {
|
|
201
|
+
selected: true
|
|
202
|
+
} : {};
|
|
374
203
|
};
|
|
375
|
-
return
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
return _context.abrupt("return", []);
|
|
425
|
-
case 26:
|
|
426
|
-
case "end":
|
|
427
|
-
return _context.stop();
|
|
428
|
-
}
|
|
429
|
-
}, _callee, null, [[4, 22]]);
|
|
430
|
-
}));
|
|
431
|
-
return function getAttributes(_x) {
|
|
432
|
-
return _ref2.apply(this, arguments);
|
|
433
|
-
};
|
|
434
|
-
}();
|
|
204
|
+
return isMobileSize ? React.createElement(StyledSelectWrapper, null, React.createElement(StyledMobileSelect, {
|
|
205
|
+
id: "",
|
|
206
|
+
required: required,
|
|
207
|
+
onChange: e => setAnswer(e.target.value),
|
|
208
|
+
...disabledProp
|
|
209
|
+
}, React.createElement("label", null, label), React.createElement(StyledMobileOption, {
|
|
210
|
+
value: "",
|
|
211
|
+
disabled: true,
|
|
212
|
+
selected: true,
|
|
213
|
+
style: {
|
|
214
|
+
color: '#666666'
|
|
215
|
+
}
|
|
216
|
+
}, label), values.map(value => React.createElement(StyledMobileOption, {
|
|
217
|
+
value: value,
|
|
218
|
+
key: value,
|
|
219
|
+
...defaultValuePropMobile(value)
|
|
220
|
+
}, value))), React.createElement(Icon, {
|
|
221
|
+
label: "",
|
|
222
|
+
size: "100",
|
|
223
|
+
fill: theme.colors.gray80,
|
|
224
|
+
style: {
|
|
225
|
+
pointerEvents: 'none',
|
|
226
|
+
position: 'absolute',
|
|
227
|
+
right: '10px',
|
|
228
|
+
top: '50%',
|
|
229
|
+
transform: 'translateY(-50%)'
|
|
230
|
+
}
|
|
231
|
+
}, React.createElement(ChevronDown, {
|
|
232
|
+
style: {
|
|
233
|
+
position: 'absolute',
|
|
234
|
+
right: '10px'
|
|
235
|
+
}
|
|
236
|
+
}))) : React.createElement(Select.Root, {
|
|
237
|
+
onValueChange: e => setAnswer(e),
|
|
238
|
+
required: required,
|
|
239
|
+
...defaultValueProp,
|
|
240
|
+
...disabledProp
|
|
241
|
+
}, React.createElement(Select.Trigger, {
|
|
242
|
+
"data-test-id": `${id}-select-trigger`
|
|
243
|
+
}, React.createElement(Select.Label, null, label), React.createElement(Select.Value, null)), React.createElement(Select.Content, {
|
|
244
|
+
css: {
|
|
245
|
+
zIndex: theme.zIndices.page
|
|
246
|
+
},
|
|
247
|
+
"data-test-id": `${id}-select-content`
|
|
248
|
+
}, values.map(value => React.createElement(Select.Item, {
|
|
249
|
+
value: value,
|
|
250
|
+
key: value
|
|
251
|
+
}, value))));
|
|
252
|
+
};
|
|
435
253
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
254
|
+
const scriptSrc = `${ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static' ? 'https://www.washingtonpost.com/subscribe/static/' : ENDPOINTS.staticAssets}/de-utils/twpdeu.min.js`;
|
|
255
|
+
const DESelect = ({
|
|
256
|
+
source,
|
|
257
|
+
fieldName,
|
|
258
|
+
label,
|
|
259
|
+
dataDictionaryConfig,
|
|
260
|
+
defaultValue,
|
|
261
|
+
disabled,
|
|
262
|
+
submit,
|
|
263
|
+
onChange = () => {},
|
|
264
|
+
onFinished = () => {},
|
|
265
|
+
valuesFilter = () => true,
|
|
266
|
+
children
|
|
267
|
+
}) => {
|
|
268
|
+
const [config, setConfig] = useState(dataDictionaryConfig);
|
|
269
|
+
const [selected, setSelected] = useState('');
|
|
270
|
+
const scriptStatus = useScript(scriptSrc);
|
|
271
|
+
useEffect(() => {
|
|
272
|
+
const fetchConfig = async () => {
|
|
273
|
+
try {
|
|
274
|
+
var _window;
|
|
275
|
+
const config = await ((_window = window) === null || _window === void 0 || (_window = _window.__twpdeu) === null || _window === void 0 ? void 0 : _window.getFieldConfigs({
|
|
276
|
+
fieldName
|
|
277
|
+
}));
|
|
278
|
+
if (config) {
|
|
279
|
+
setConfig(config[0]);
|
|
280
|
+
} else {
|
|
281
|
+
console.error('unable to get config', fieldName);
|
|
282
|
+
}
|
|
283
|
+
} catch (e) {
|
|
284
|
+
console.warn('unable to get config', fieldName, e);
|
|
463
285
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
468
|
-
var config;
|
|
469
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
470
|
-
while (1) switch (_context.prev = _context.next) {
|
|
471
|
-
case 0:
|
|
472
|
-
_context.next = 2;
|
|
473
|
-
return getAttributes({
|
|
474
|
-
fieldName: fieldName
|
|
475
|
-
});
|
|
476
|
-
case 2:
|
|
477
|
-
config = _context.sent;
|
|
478
|
-
if (process.env.NODE_ENV !== "production") {
|
|
479
|
-
console.debug('config from API', config);
|
|
480
|
-
}
|
|
481
|
-
setConfig(config[0]);
|
|
482
|
-
case 5:
|
|
483
|
-
case "end":
|
|
484
|
-
return _context.stop();
|
|
485
|
-
}
|
|
486
|
-
}, _callee);
|
|
487
|
-
}))();
|
|
286
|
+
};
|
|
287
|
+
if (scriptStatus === ScriptStatus.READY && !(children || config)) {
|
|
288
|
+
fetchConfig();
|
|
488
289
|
}
|
|
489
|
-
}, []);
|
|
490
|
-
useEffect(
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
290
|
+
}, [scriptStatus]);
|
|
291
|
+
useEffect(() => {
|
|
292
|
+
const submitSelected = async () => {
|
|
293
|
+
try {
|
|
294
|
+
var _window2;
|
|
295
|
+
// TODO: Log to GA?
|
|
296
|
+
const result = await ((_window2 = window) === null || _window2 === void 0 || (_window2 = _window2.__twpdeu) === null || _window2 === void 0 ? void 0 : _window2.push({
|
|
297
|
+
submitData: {
|
|
298
|
+
fieldName,
|
|
299
|
+
value: selected
|
|
300
|
+
},
|
|
301
|
+
type: config !== null && config !== void 0 && config.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,
|
|
302
|
+
source
|
|
303
|
+
}));
|
|
304
|
+
const isError = result ? result.status !== ResponseStatus.SUCCESS : true;
|
|
305
|
+
onFinished({
|
|
306
|
+
isFinished: true,
|
|
307
|
+
isError
|
|
308
|
+
});
|
|
309
|
+
} catch (e) {
|
|
310
|
+
onFinished({
|
|
311
|
+
isFinished: false,
|
|
312
|
+
isError: true
|
|
313
|
+
});
|
|
494
314
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
});
|
|
315
|
+
};
|
|
316
|
+
if (scriptStatus === ScriptStatus.READY && submit && selected) {
|
|
317
|
+
submitSelected();
|
|
499
318
|
}
|
|
500
|
-
}, [
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
504
|
-
var defaultValueProp = defaultValue ? {
|
|
505
|
-
defaultValue: defaultValue
|
|
319
|
+
}, [scriptStatus, submit]);
|
|
320
|
+
const defaultValueProp = defaultValue && config ? {
|
|
321
|
+
defaultValue
|
|
506
322
|
} : {};
|
|
507
|
-
|
|
323
|
+
const isLoading = !(children || config);
|
|
324
|
+
const disabledProp = disabled || isLoading ? {
|
|
508
325
|
disabled: true
|
|
509
326
|
} : {};
|
|
510
327
|
// sort and filter out archived values
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}).filter(valuesFilter) : [];
|
|
516
|
-
return React.createElement(SelectWrapper, null, React.createElement(Select.Root, _extends({
|
|
517
|
-
onValueChange: function onValueChange(e) {
|
|
328
|
+
const values = config ? config.values.sort((a, b) => a.order - b.order).filter(value => value.archived !== true).filter(valuesFilter) : [];
|
|
329
|
+
return React.createElement(SelectWrapper, null, children && React.createElement(Select.Root, {
|
|
330
|
+
onValueChange: e => {
|
|
331
|
+
setSelected(e);
|
|
518
332
|
onChange({
|
|
519
333
|
value: e
|
|
520
334
|
});
|
|
335
|
+
},
|
|
336
|
+
...defaultValueProp,
|
|
337
|
+
...disabledProp
|
|
338
|
+
}, children), !children && !config && React.createElement(Dropdown, {
|
|
339
|
+
id: 'loading',
|
|
340
|
+
label: 'Loading...',
|
|
341
|
+
values: [],
|
|
342
|
+
disabled: true
|
|
343
|
+
}), !children && config && React.createElement(Dropdown, {
|
|
344
|
+
id: config.name,
|
|
345
|
+
label: label || config.name,
|
|
346
|
+
onChange: e => {
|
|
521
347
|
setSelected(e);
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
}, React.createElement(Select.Label, null, label || config.name), React.createElement(Select.Value, null)), React.createElement(Select.Content, {
|
|
526
|
-
css: {
|
|
527
|
-
zIndex: theme.zIndices.page
|
|
348
|
+
onChange({
|
|
349
|
+
value: e
|
|
350
|
+
});
|
|
528
351
|
},
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
key: value.name
|
|
534
|
-
}, value.name);
|
|
535
|
-
})))));
|
|
352
|
+
values: values.map(value => value.name),
|
|
353
|
+
defaultValue: defaultValue,
|
|
354
|
+
disabled: disabled
|
|
355
|
+
}));
|
|
536
356
|
};
|
|
537
|
-
|
|
357
|
+
const SelectWrapper = /*#__PURE__*/styled('div', {
|
|
538
358
|
boxSizing: 'border-box',
|
|
539
359
|
display: 'flex',
|
|
540
360
|
marginBottom: '$100',
|
|
@@ -547,5 +367,5 @@ var SelectWrapper = /*#__PURE__*/styled('div', {
|
|
|
547
367
|
}
|
|
548
368
|
});
|
|
549
369
|
|
|
550
|
-
export { AttributesState, CollectionBehaviors, DESelect, IngestResponseState, getAttributes, hasRequiredPrivacyCookies };
|
|
370
|
+
export { AttributesState, CollectionBehaviors, DESelect, IngestResponseState, IngestType, getAttributes, hasRequiredPrivacyCookies, ingest };
|
|
551
371
|
//# sourceMappingURL=subs-de-inputs.esm.js.map
|