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