@equinor/cpl-error-snackbar-react 1.0.1 → 1.0.2

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.
Files changed (3) hide show
  1. package/dist/index.js +26 -86
  2. package/dist/index.mjs +26 -89
  3. package/package.json +22 -15
package/dist/index.js CHANGED
@@ -1,39 +1,10 @@
1
1
  "use strict";
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
6
  var __getProtoOf = Object.getPrototypeOf;
10
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- if (__propIsEnum.call(b, prop))
20
- __defNormalProp(a, prop, b[prop]);
21
- }
22
- return a;
23
- };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
- var __objRest = (source, exclude) => {
26
- var target = {};
27
- for (var prop in source)
28
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
- target[prop] = source[prop];
30
- if (source != null && __getOwnPropSymbols)
31
- for (var prop of __getOwnPropSymbols(source)) {
32
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
- target[prop] = source[prop];
34
- }
35
- return target;
36
- };
37
8
  var __export = (target, all) => {
38
9
  for (var name in all)
39
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -55,26 +26,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
55
26
  mod
56
27
  ));
57
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
- var __async = (__this, __arguments, generator) => {
59
- return new Promise((resolve, reject) => {
60
- var fulfilled = (value) => {
61
- try {
62
- step(generator.next(value));
63
- } catch (e) {
64
- reject(e);
65
- }
66
- };
67
- var rejected = (value) => {
68
- try {
69
- step(generator.throw(value));
70
- } catch (e) {
71
- reject(e);
72
- }
73
- };
74
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
75
- step((generator = generator.apply(__this, __arguments)).next());
76
- });
77
- };
78
29
 
79
30
  // src/index.ts
80
31
  var index_exports = {};
@@ -113,14 +64,14 @@ function CopyToClipboardButton({ value }) {
113
64
  if (timer) clearTimeout(timer);
114
65
  };
115
66
  }, [showPopover]);
116
- const handleCopy = () => __async(null, null, function* () {
67
+ const handleCopy = async () => {
117
68
  try {
118
- yield navigator.clipboard.writeText(value);
69
+ await navigator.clipboard.writeText(value);
119
70
  setShowPopover(true);
120
71
  } catch (error) {
121
72
  console.error("Failed to copy text: ", error);
122
73
  }
123
- });
74
+ };
124
75
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StyledButton, { onClick: handleCopy, title: "Copy to Clipboard", variant: "ghost", color: "secondary", children: showPopover ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
125
76
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_eds_core_react.Icon, { data: import_eds_icons.check, size: 16 }),
126
77
  "Copied"
@@ -146,7 +97,6 @@ function ErrorSnackbar({
146
97
  onClose,
147
98
  hideCopyToClipboardButton = false
148
99
  }) {
149
- var _a;
150
100
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(ErrorSnackbarWrapper, { tabIndex: 0, children: [
151
101
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconWrapper, { children: icon || /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
152
102
  import_eds_core_react2.Icon,
@@ -177,7 +127,7 @@ function ErrorSnackbar({
177
127
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(HeaderTypography, { variant: "h6", children: "Error details:" }),
178
128
  error.error.message && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BodyTypography, { children: error.error.message }),
179
129
  error.error.possibleAction && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BodyTypography, { children: error.error.possibleAction }),
180
- ((_a = error.error.accessRequirements) == null ? void 0 : _a.length) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StyledList, { style: { color: "inherit" }, children: error.error.accessRequirements.map((accessRequirement) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StyledList.Item, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(BodyTypography, { children: [
130
+ error.error.accessRequirements?.length && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StyledList, { style: { color: "inherit" }, children: error.error.accessRequirements.map((accessRequirement) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StyledList.Item, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(BodyTypography, { children: [
181
131
  accessRequirement.description,
182
132
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("br", {}),
183
133
  "Outcome: ",
@@ -405,11 +355,10 @@ function parseUnknownError(unknownError) {
405
355
  };
406
356
  }
407
357
  function parseInnerError(rawInnerError) {
408
- var _a;
409
358
  if (typeof rawInnerError !== "object" || rawInnerError === null || rawInnerError === void 0) {
410
359
  return void 0;
411
360
  }
412
- const accessRequirements = (_a = getTypedPropertyIfExists(rawInnerError, "accessRequirements", "array")) == null ? void 0 : _a.map(parseAccessRequirement).filter(itemIsDefined);
361
+ const accessRequirements = getTypedPropertyIfExists(rawInnerError, "accessRequirements", "array")?.map(parseAccessRequirement).filter(itemIsDefined);
413
362
  return {
414
363
  code: getTypedPropertyIfExists(rawInnerError, "code", "string"),
415
364
  attemptedValue: getTypedPropertyIfExists(rawInnerError, "attemptedValue", "string"),
@@ -421,15 +370,14 @@ function parseInnerError(rawInnerError) {
421
370
  };
422
371
  }
423
372
  function parseAccessRequirement(rawAccessRequirement) {
424
- var _a, _b, _c, _d;
425
373
  if (typeof rawAccessRequirement !== "object" || !rawAccessRequirement) {
426
374
  return void 0;
427
375
  }
428
376
  return {
429
- code: (_a = getTypedPropertyIfExists(rawAccessRequirement, "code", "string")) != null ? _a : "",
430
- description: (_b = getTypedPropertyIfExists(rawAccessRequirement, "description", "string")) != null ? _b : "",
431
- outcome: (_c = getTypedPropertyIfExists(rawAccessRequirement, "outcome", "string")) != null ? _c : "",
432
- wasEvaluated: (_d = getTypedPropertyIfExists(rawAccessRequirement, "wasEvaluated", "boolean")) != null ? _d : false
377
+ code: getTypedPropertyIfExists(rawAccessRequirement, "code", "string") ?? "",
378
+ description: getTypedPropertyIfExists(rawAccessRequirement, "description", "string") ?? "",
379
+ outcome: getTypedPropertyIfExists(rawAccessRequirement, "outcome", "string") ?? "",
380
+ wasEvaluated: getTypedPropertyIfExists(rawAccessRequirement, "wasEvaluated", "boolean") ?? false
433
381
  };
434
382
  }
435
383
  function getTypedPropertyIfExists(object, key, ...acceptedTypes) {
@@ -478,22 +426,19 @@ function buildToaster(options = {}) {
478
426
  useState: useState4,
479
427
  create: (toast) => {
480
428
  const id = crypto.randomUUID();
481
- setState((old) => {
482
- var _a;
483
- return [
484
- __spreadProps(__spreadValues({
485
- id
486
- }, toast), {
487
- timeout: (_a = timeoutOverrides[toast.type]) != null ? _a : DEFAULT_TIMEOUT_MS_BY_TYPE[toast.type]
488
- }),
489
- ...old
490
- ];
491
- });
429
+ setState((old) => [
430
+ {
431
+ id,
432
+ ...toast,
433
+ timeout: timeoutOverrides[toast.type] ?? DEFAULT_TIMEOUT_MS_BY_TYPE[toast.type]
434
+ },
435
+ ...old
436
+ ]);
492
437
  return id;
493
438
  },
494
439
  update: (id, toast) => {
495
440
  setState((old) => {
496
- return old.map((item) => item.id === id ? __spreadValues(__spreadValues({}, item), toast) : item);
441
+ return old.map((item) => item.id === id ? { ...item, ...toast } : item);
497
442
  });
498
443
  },
499
444
  delete: (id) => {
@@ -659,19 +604,14 @@ var StyledPaper = (0, import_styled_components4.default)(import_eds_core_react3.
659
604
  // src/toast/ToastContainerInner.tsx
660
605
  var import_jsx_runtime7 = require("react/jsx-runtime");
661
606
  var DEFAULT_TOAST_CONTAINER_Z_INDEX = 1e3;
662
- function ToastContainerInner(_a) {
663
- var _b = _a, {
664
- deleteToastById,
665
- toasts,
666
- placement = "top-right",
667
- zIndex = DEFAULT_TOAST_CONTAINER_Z_INDEX
668
- } = _b, containerProps = __objRest(_b, [
669
- "deleteToastById",
670
- "toasts",
671
- "placement",
672
- "zIndex"
673
- ]);
674
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Container, __spreadProps(__spreadValues({ $placement: placement, $zIndex: zIndex }, containerProps), { children: toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ToastItem, { toast, onDelete: deleteToastById }, toast.id)) }));
607
+ function ToastContainerInner({
608
+ deleteToastById,
609
+ toasts,
610
+ placement = "top-right",
611
+ zIndex = DEFAULT_TOAST_CONTAINER_Z_INDEX,
612
+ ...containerProps
613
+ }) {
614
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Container, { $placement: placement, $zIndex: zIndex, ...containerProps, children: toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ToastItem, { toast, onDelete: deleteToastById }, toast.id)) });
675
615
  }
676
616
  var Container = import_styled_components5.default.div`
677
617
  position: fixed;
package/dist/index.mjs CHANGED
@@ -1,55 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
- var __async = (__this, __arguments, generator) => {
33
- return new Promise((resolve, reject) => {
34
- var fulfilled = (value) => {
35
- try {
36
- step(generator.next(value));
37
- } catch (e) {
38
- reject(e);
39
- }
40
- };
41
- var rejected = (value) => {
42
- try {
43
- step(generator.throw(value));
44
- } catch (e) {
45
- reject(e);
46
- }
47
- };
48
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
- step((generator = generator.apply(__this, __arguments)).next());
50
- });
51
- };
52
-
53
1
  // src/CopyToClipboardButton.tsx
54
2
  import { Button, Icon } from "@equinor/eds-core-react";
55
3
  import { check, copy } from "@equinor/eds-icons";
@@ -69,14 +17,14 @@ function CopyToClipboardButton({ value }) {
69
17
  if (timer) clearTimeout(timer);
70
18
  };
71
19
  }, [showPopover]);
72
- const handleCopy = () => __async(null, null, function* () {
20
+ const handleCopy = async () => {
73
21
  try {
74
- yield navigator.clipboard.writeText(value);
22
+ await navigator.clipboard.writeText(value);
75
23
  setShowPopover(true);
76
24
  } catch (error) {
77
25
  console.error("Failed to copy text: ", error);
78
26
  }
79
- });
27
+ };
80
28
  return /* @__PURE__ */ jsx(StyledButton, { onClick: handleCopy, title: "Copy to Clipboard", variant: "ghost", color: "secondary", children: showPopover ? /* @__PURE__ */ jsxs(Fragment, { children: [
81
29
  /* @__PURE__ */ jsx(Icon, { data: check, size: 16 }),
82
30
  "Copied"
@@ -102,7 +50,6 @@ function ErrorSnackbar({
102
50
  onClose,
103
51
  hideCopyToClipboardButton = false
104
52
  }) {
105
- var _a;
106
53
  return /* @__PURE__ */ jsxs2(ErrorSnackbarWrapper, { tabIndex: 0, children: [
107
54
  /* @__PURE__ */ jsx2(IconWrapper, { children: icon || /* @__PURE__ */ jsx2(
108
55
  Icon2,
@@ -133,7 +80,7 @@ function ErrorSnackbar({
133
80
  /* @__PURE__ */ jsx2(HeaderTypography, { variant: "h6", children: "Error details:" }),
134
81
  error.error.message && /* @__PURE__ */ jsx2(BodyTypography, { children: error.error.message }),
135
82
  error.error.possibleAction && /* @__PURE__ */ jsx2(BodyTypography, { children: error.error.possibleAction }),
136
- ((_a = error.error.accessRequirements) == null ? void 0 : _a.length) && /* @__PURE__ */ jsx2(StyledList, { style: { color: "inherit" }, children: error.error.accessRequirements.map((accessRequirement) => /* @__PURE__ */ jsx2(StyledList.Item, { children: /* @__PURE__ */ jsxs2(BodyTypography, { children: [
83
+ error.error.accessRequirements?.length && /* @__PURE__ */ jsx2(StyledList, { style: { color: "inherit" }, children: error.error.accessRequirements.map((accessRequirement) => /* @__PURE__ */ jsx2(StyledList.Item, { children: /* @__PURE__ */ jsxs2(BodyTypography, { children: [
137
84
  accessRequirement.description,
138
85
  /* @__PURE__ */ jsx2("br", {}),
139
86
  "Outcome: ",
@@ -361,11 +308,10 @@ function parseUnknownError(unknownError) {
361
308
  };
362
309
  }
363
310
  function parseInnerError(rawInnerError) {
364
- var _a;
365
311
  if (typeof rawInnerError !== "object" || rawInnerError === null || rawInnerError === void 0) {
366
312
  return void 0;
367
313
  }
368
- const accessRequirements = (_a = getTypedPropertyIfExists(rawInnerError, "accessRequirements", "array")) == null ? void 0 : _a.map(parseAccessRequirement).filter(itemIsDefined);
314
+ const accessRequirements = getTypedPropertyIfExists(rawInnerError, "accessRequirements", "array")?.map(parseAccessRequirement).filter(itemIsDefined);
369
315
  return {
370
316
  code: getTypedPropertyIfExists(rawInnerError, "code", "string"),
371
317
  attemptedValue: getTypedPropertyIfExists(rawInnerError, "attemptedValue", "string"),
@@ -377,15 +323,14 @@ function parseInnerError(rawInnerError) {
377
323
  };
378
324
  }
379
325
  function parseAccessRequirement(rawAccessRequirement) {
380
- var _a, _b, _c, _d;
381
326
  if (typeof rawAccessRequirement !== "object" || !rawAccessRequirement) {
382
327
  return void 0;
383
328
  }
384
329
  return {
385
- code: (_a = getTypedPropertyIfExists(rawAccessRequirement, "code", "string")) != null ? _a : "",
386
- description: (_b = getTypedPropertyIfExists(rawAccessRequirement, "description", "string")) != null ? _b : "",
387
- outcome: (_c = getTypedPropertyIfExists(rawAccessRequirement, "outcome", "string")) != null ? _c : "",
388
- wasEvaluated: (_d = getTypedPropertyIfExists(rawAccessRequirement, "wasEvaluated", "boolean")) != null ? _d : false
330
+ code: getTypedPropertyIfExists(rawAccessRequirement, "code", "string") ?? "",
331
+ description: getTypedPropertyIfExists(rawAccessRequirement, "description", "string") ?? "",
332
+ outcome: getTypedPropertyIfExists(rawAccessRequirement, "outcome", "string") ?? "",
333
+ wasEvaluated: getTypedPropertyIfExists(rawAccessRequirement, "wasEvaluated", "boolean") ?? false
389
334
  };
390
335
  }
391
336
  function getTypedPropertyIfExists(object, key, ...acceptedTypes) {
@@ -434,22 +379,19 @@ function buildToaster(options = {}) {
434
379
  useState: useState4,
435
380
  create: (toast) => {
436
381
  const id = crypto.randomUUID();
437
- setState((old) => {
438
- var _a;
439
- return [
440
- __spreadProps(__spreadValues({
441
- id
442
- }, toast), {
443
- timeout: (_a = timeoutOverrides[toast.type]) != null ? _a : DEFAULT_TIMEOUT_MS_BY_TYPE[toast.type]
444
- }),
445
- ...old
446
- ];
447
- });
382
+ setState((old) => [
383
+ {
384
+ id,
385
+ ...toast,
386
+ timeout: timeoutOverrides[toast.type] ?? DEFAULT_TIMEOUT_MS_BY_TYPE[toast.type]
387
+ },
388
+ ...old
389
+ ]);
448
390
  return id;
449
391
  },
450
392
  update: (id, toast) => {
451
393
  setState((old) => {
452
- return old.map((item) => item.id === id ? __spreadValues(__spreadValues({}, item), toast) : item);
394
+ return old.map((item) => item.id === id ? { ...item, ...toast } : item);
453
395
  });
454
396
  },
455
397
  delete: (id) => {
@@ -615,19 +557,14 @@ var StyledPaper = styled4(Paper)`
615
557
  // src/toast/ToastContainerInner.tsx
616
558
  import { jsx as jsx7 } from "react/jsx-runtime";
617
559
  var DEFAULT_TOAST_CONTAINER_Z_INDEX = 1e3;
618
- function ToastContainerInner(_a) {
619
- var _b = _a, {
620
- deleteToastById,
621
- toasts,
622
- placement = "top-right",
623
- zIndex = DEFAULT_TOAST_CONTAINER_Z_INDEX
624
- } = _b, containerProps = __objRest(_b, [
625
- "deleteToastById",
626
- "toasts",
627
- "placement",
628
- "zIndex"
629
- ]);
630
- return /* @__PURE__ */ jsx7(Container, __spreadProps(__spreadValues({ $placement: placement, $zIndex: zIndex }, containerProps), { children: toasts.map((toast) => /* @__PURE__ */ jsx7(ToastItem, { toast, onDelete: deleteToastById }, toast.id)) }));
560
+ function ToastContainerInner({
561
+ deleteToastById,
562
+ toasts,
563
+ placement = "top-right",
564
+ zIndex = DEFAULT_TOAST_CONTAINER_Z_INDEX,
565
+ ...containerProps
566
+ }) {
567
+ return /* @__PURE__ */ jsx7(Container, { $placement: placement, $zIndex: zIndex, ...containerProps, children: toasts.map((toast) => /* @__PURE__ */ jsx7(ToastItem, { toast, onDelete: deleteToastById }, toast.id)) });
631
568
  }
632
569
  var Container = styled5.div`
633
570
  position: fixed;
package/package.json CHANGED
@@ -1,30 +1,37 @@
1
1
  {
2
2
  "name": "@equinor/cpl-error-snackbar-react",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
8
15
  "files": [
9
16
  "dist/**"
10
17
  ],
11
18
  "dependencies": {
12
- "@equinor/eds-icons": "^0.21.0",
13
- "@equinor/eds-tokens": "^0.9.2"
19
+ "@equinor/eds-icons": "1.2.1",
20
+ "@equinor/eds-tokens": "2.1.1"
14
21
  },
15
22
  "devDependencies": {
16
- "@equinor/eds-core-react": "^2.2.0",
17
- "@storybook/react": "^9.1.1",
18
- "@types/react": "^18.3.18",
19
- "@types/react-dom": "^18.3.5",
20
- "@types/styled-components": "^5.1.34",
21
- "eslint": "^9.21.0",
22
- "react": "^18.2.0",
23
- "react-dom": "^18.2.0",
24
- "styled-components": "^6.1.14",
25
- "tsup": "^8.5.1",
26
- "@equinor/cpl-eslint-config": "1.0.0",
27
- "@equinor/cpl-typescript-config": "0.0.2"
23
+ "@equinor/eds-core-react": "2.3.4",
24
+ "@storybook/react-vite": "10.2.8",
25
+ "@types/react": "19.2.13",
26
+ "@types/react-dom": "19.2.3",
27
+ "@types/styled-components": "5.1.36",
28
+ "eslint": "10.0.0",
29
+ "react": "19.2.4",
30
+ "react-dom": "19.2.4",
31
+ "styled-components": "6.3.9",
32
+ "tsup": "8.5.1",
33
+ "@equinor/cpl-eslint-config": "1.0.1",
34
+ "@equinor/cpl-typescript-config": "0.0.3"
28
35
  },
29
36
  "peerDependencies": {
30
37
  "@equinor/eds-core-react": ">=2.2.0",