@har-analyzer/components 0.0.8 → 0.0.9

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 CHANGED
@@ -114,6 +114,31 @@ function App() {
114
114
 
115
115
  ---
116
116
 
117
+ ### HARAnalyzerPreferencesProvider
118
+
119
+ Provides a persistent context for managing user preferences (like theme, content width, table preferences and board layouts). By default, preferences rely on browser storage. However, you can provide a custom async store (e.g., to save preferences to a backend database or external extension API) by wrapping your application in `HARAnalyzerPreferencesProvider`.
120
+
121
+ ```jsx
122
+ import HARAnalyzerPreferencesProvider from '@har-analyzer/components/har-analyzer-preferences';
123
+
124
+ // Optional: Custom external store
125
+ const customStore = {
126
+ getPreference: async (key) => fetch(`/api/prefs/${key}`).then(res => res.text()),
127
+ setPreference: async (key, value) => { await fetch(`/api/prefs/${key}`, { method: 'POST', body: value }) }
128
+ };
129
+
130
+ function App() {
131
+ return (
132
+ <HARAnalyzerPreferencesProvider store={customStore}>
133
+ <HARAnalyzer appName="HAR Analyzer" />;
134
+ </HARAnalyzerPreferencesProvider>
135
+ );
136
+ }
137
+
138
+ ```
139
+
140
+ ---
141
+
117
142
  ### HAR Utilities
118
143
 
119
144
  Various types and utilities for working with HTTP Archive (.har) files are directly exported.
@@ -0,0 +1,18 @@
1
+ import { Dispatch } from 'react';
2
+ import { JSX } from 'react/jsx-runtime';
3
+ import { PropsWithChildren } from 'react';
4
+ import { SetStateAction } from 'react';
5
+
6
+ declare function HARAnalyzerPreferencesProvider({ store, children }: PropsWithChildren<{
7
+ store: UserPreferenceStore;
8
+ }>): JSX.Element;
9
+ export default HARAnalyzerPreferencesProvider;
10
+
11
+ export declare function useHARAnalyzerPreferences<T>(preferenceKey: string, defaultValue: T): readonly [T, Dispatch<SetStateAction<T>>];
12
+
13
+ declare interface UserPreferenceStore {
14
+ getPreference: (key: string) => Promise<string | undefined>;
15
+ setPreference: (key: string, value: string) => Promise<void>;
16
+ }
17
+
18
+ export { }
@@ -0,0 +1,97 @@
1
+ import { jsx as v } from "react/jsx-runtime";
2
+ import { createContext as D, use as E, useState as F, useCallback as h, useEffect as m } from "react";
3
+ function x(t, e) {
4
+ try {
5
+ return JSON.parse(t ?? "");
6
+ } catch (r) {
7
+ return console.warn("Failed to parse JSON string:", t, "Error:", r), e;
8
+ }
9
+ }
10
+ async function i(t, e) {
11
+ return new Promise((r, n) => {
12
+ t.addEventListener("success", () => {
13
+ r(t.result);
14
+ }), t.addEventListener("error", () => {
15
+ n(e);
16
+ });
17
+ });
18
+ }
19
+ var y = function(t, e, r, n, o) {
20
+ if (n === "m") throw new TypeError("Private method is not writable");
21
+ if (n === "a" && !o) throw new TypeError("Private accessor was defined without a setter");
22
+ if (typeof e == "function" ? t !== e || !o : !e.has(t)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
23
+ return n === "a" ? o.call(t, r) : o ? o.value = r : e.set(t, r), r;
24
+ }, a = function(t, e, r, n) {
25
+ if (r === "a" && !n) throw new TypeError("Private accessor was defined without a getter");
26
+ if (typeof e == "function" ? t !== e || !n : !e.has(t)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
27
+ return r === "m" ? n : r === "a" ? n.call(t) : n ? n.value : e.get(t);
28
+ }, s, l, c, d, b, g;
29
+ class A {
30
+ constructor({ name: e }) {
31
+ s.add(this), l.set(this, void 0), c.set(this, void 0), y(this, l, e, "f");
32
+ }
33
+ async getItem(e) {
34
+ const r = await a(this, s, "m", d).call(this);
35
+ return i(r.get(e), "Failed to get item");
36
+ }
37
+ async setItem(e, r) {
38
+ const n = await a(this, s, "m", d).call(this);
39
+ return i(n.put(r, e), "Failed to set item");
40
+ }
41
+ async removeItem(e) {
42
+ const r = await a(this, s, "m", d).call(this);
43
+ return i(r.delete(e), "Failed to remove item");
44
+ }
45
+ async clear() {
46
+ const e = await a(this, s, "m", d).call(this);
47
+ return i(e.clear(), "Failed to clear store");
48
+ }
49
+ }
50
+ l = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), s = /* @__PURE__ */ new WeakSet(), d = async function() {
51
+ return (await a(this, s, "m", b).call(this)).transaction("store", "readwrite").objectStore("store");
52
+ }, b = async function() {
53
+ return a(this, c, "f") === void 0 && y(this, c, a(this, s, "m", g).call(this), "f"), a(this, c, "f");
54
+ }, g = async function() {
55
+ const e = indexedDB.open(a(this, l, "f"), 1);
56
+ return e.addEventListener("upgradeneeded", () => {
57
+ e.result.createObjectStore("store");
58
+ }), i(e, "Failed to open IndexedDB");
59
+ };
60
+ const _ = new A({ name: "node_modules/local-db-storage" }), p = {
61
+ get: async (t) => await _.getItem(t),
62
+ set: async (t, e) => {
63
+ await _.setItem(t, e);
64
+ }
65
+ }, P = D(void 0);
66
+ function T({ store: t, children: e }) {
67
+ return /* @__PURE__ */ v(P, { value: t, children: e });
68
+ }
69
+ const C = {
70
+ getPreference: p.get,
71
+ setPreference: p.set
72
+ };
73
+ function z(t, e) {
74
+ let r = E(P);
75
+ r || (console.warn("Invoked outside of HARAnalyzerPreferencesProvider. Falling back to use fallback preferences store."), r = C);
76
+ const [n, o] = F(e), f = h(async () => {
77
+ const u = await r.getPreference(t), S = x(u, e);
78
+ o(S);
79
+ }, [r, t, e]);
80
+ m(() => {
81
+ f();
82
+ }, [f]);
83
+ const w = h(async () => {
84
+ try {
85
+ await r.setPreference(t, JSON.stringify(n));
86
+ } catch (u) {
87
+ console.error(`Failed to update preference for key ${t}:`, u);
88
+ }
89
+ }, [r, t, n]);
90
+ return m(() => {
91
+ w();
92
+ }, [w]), [n, o];
93
+ }
94
+ export {
95
+ T as default,
96
+ z as useHARAnalyzerPreferences
97
+ };
@@ -1,88 +1,88 @@
1
1
  import { jsx as e, jsxs as i, Fragment as F } from "react/jsx-runtime";
2
2
  import { useEffect as N, useState as a } from "react";
3
- import v from "@cloudscape-design/components/app-layout";
4
- import { I18nProvider as D } from "@cloudscape-design/components/i18n";
5
- import R from "@cloudscape-design/components/i18n/messages/all.en";
6
- import { u as p } from "./chunks/index2.js";
7
- import T from "@cloudscape-design/components/header";
8
- import { borderWidthAlert as b, colorBorderDividerDefault as y } from "@cloudscape-design/design-tokens";
3
+ import R from "@cloudscape-design/components/app-layout";
4
+ import { I18nProvider as v } from "@cloudscape-design/components/i18n";
5
+ import y from "@cloudscape-design/components/i18n/messages/all.en";
6
+ import { useHARAnalyzerPreferences as p } from "./har-analyzer-preferences.js";
7
+ import D from "@cloudscape-design/components/header";
8
+ import { borderWidthAlert as T, colorBorderDividerDefault as b } from "@cloudscape-design/design-tokens";
9
9
  import { H as E } from "./chunks/index.js";
10
- import l from "@cloudscape-design/components/box";
11
- import c from "@cloudscape-design/components/button";
10
+ import c from "@cloudscape-design/components/box";
11
+ import l from "@cloudscape-design/components/button";
12
12
  import M from "@cloudscape-design/components/modal";
13
- import { V as u } from "./chunks/vertical-gap.js";
14
- import f from "@cloudscape-design/components/toggle";
15
- import { Mode as m, applyMode as S } from "@cloudscape-design/global-styles";
16
- import W from "./har-file-uploader.js";
17
- import I from "./har-content-viewer.js";
13
+ import { V as f } from "./chunks/vertical-gap.js";
14
+ import u from "@cloudscape-design/components/toggle";
15
+ import { Mode as m, applyMode as W } from "@cloudscape-design/global-styles";
16
+ import I from "./har-file-uploader.js";
17
+ import S from "./har-content-viewer.js";
18
18
  function A() {
19
19
  return p("isFullContentWidth", !1);
20
20
  }
21
- const g = "top-navigation", d = "blur(16px)";
22
- function L({
21
+ function U() {
22
+ return p("isDarkTheme", !1);
23
+ }
24
+ const k = "top-navigation", d = "blur(16px)";
25
+ function _({
23
26
  logo: t,
24
- appName: r,
25
- utilities: o
27
+ appName: o,
28
+ utilities: r
26
29
  }) {
27
30
  return /* @__PURE__ */ e(
28
31
  "nav",
29
32
  {
30
- id: g,
33
+ id: k,
31
34
  style: {
32
35
  position: "sticky",
33
36
  top: 0,
34
37
  zIndex: 1002,
35
38
  padding: "0.5rem 1rem",
36
- borderBlockEnd: `${b} solid ${y}`,
39
+ borderBlockEnd: `${T} solid ${b}`,
37
40
  backdropFilter: d,
38
41
  WebkitBackdropFilter: d
39
42
  // for Safari
40
43
  },
41
- children: /* @__PURE__ */ e(T, { actions: o, children: /* @__PURE__ */ i(E, { children: [
44
+ children: /* @__PURE__ */ e(D, { actions: r, children: /* @__PURE__ */ i(E, { children: [
42
45
  t,
43
- r
46
+ o
44
47
  ] }) })
45
48
  }
46
49
  );
47
50
  }
48
- function U() {
49
- const [t, r] = A();
50
- return /* @__PURE__ */ e(f, { onChange: ({ detail: o }) => {
51
- r(o.checked);
51
+ function x() {
52
+ const [t, o] = A();
53
+ return /* @__PURE__ */ e(u, { onChange: ({ detail: r }) => {
54
+ o(r.checked);
52
55
  }, checked: t, children: "Use entire screen width" });
53
56
  }
54
- function _() {
55
- return p("isDarkTheme", !1);
56
- }
57
- function x() {
58
- const [t, r] = _();
57
+ function L() {
58
+ const [t, o] = U();
59
59
  return N(() => {
60
- const o = t ? m.Dark : m.Light;
61
- S(o);
62
- }, [t]), /* @__PURE__ */ e(f, { onChange: ({ detail: o }) => {
63
- r(o.checked);
60
+ const r = t ? m.Dark : m.Light;
61
+ W(r);
62
+ }, [t]), /* @__PURE__ */ e(u, { onChange: ({ detail: r }) => {
63
+ o(r.checked);
64
64
  }, checked: t, children: "Use dark theme" });
65
65
  }
66
66
  function V() {
67
- const [t, r] = a(!1), o = () => {
68
- r(!0);
67
+ const [t, o] = a(!1), r = () => {
68
+ o(!0);
69
69
  }, n = () => {
70
- r(!1);
70
+ o(!1);
71
71
  };
72
72
  return /* @__PURE__ */ i(F, { children: [
73
- /* @__PURE__ */ e(c, { iconName: "settings", variant: "icon", onClick: o }),
73
+ /* @__PURE__ */ e(l, { iconName: "settings", variant: "icon", onClick: r }),
74
74
  /* @__PURE__ */ i(
75
75
  M,
76
76
  {
77
77
  visible: t,
78
78
  onDismiss: n,
79
79
  header: "Manage your preferences",
80
- footer: /* @__PURE__ */ e(l, { float: "right", children: /* @__PURE__ */ e(c, { variant: "primary", onClick: n, children: "Ok" }) }),
80
+ footer: /* @__PURE__ */ e(c, { float: "right", children: /* @__PURE__ */ e(l, { variant: "primary", onClick: n, children: "Ok" }) }),
81
81
  children: [
82
- /* @__PURE__ */ e(l, { margin: { top: "m" } }),
83
- /* @__PURE__ */ i(u, { size: "m", children: [
84
- /* @__PURE__ */ e(x, {}),
85
- /* @__PURE__ */ e(U, {})
82
+ /* @__PURE__ */ e(c, { margin: { top: "m" } }),
83
+ /* @__PURE__ */ i(f, { size: "m", children: [
84
+ /* @__PURE__ */ e(L, {}),
85
+ /* @__PURE__ */ e(x, {})
86
86
  ] })
87
87
  ]
88
88
  }
@@ -91,37 +91,37 @@ function V() {
91
91
  }
92
92
  function w({
93
93
  logo: t,
94
- appName: r,
95
- content: o
94
+ appName: o,
95
+ content: r
96
96
  }) {
97
97
  const [n] = A();
98
- return /* @__PURE__ */ i(D, { locale: "en", messages: [R], children: [
99
- /* @__PURE__ */ e(L, { logo: t, appName: r, utilities: /* @__PURE__ */ e(V, {}) }),
98
+ return /* @__PURE__ */ i(v, { locale: "en", messages: [y], children: [
99
+ /* @__PURE__ */ e(_, { logo: t, appName: o, utilities: /* @__PURE__ */ e(V, {}) }),
100
100
  /* @__PURE__ */ e(
101
- v,
101
+ R,
102
102
  {
103
- headerSelector: `#${g}`,
103
+ headerSelector: `#${k}`,
104
104
  navigationHide: !0,
105
105
  toolsHide: !0,
106
106
  maxContentWidth: n ? Number.MAX_VALUE : void 0,
107
- content: o
107
+ content: r
108
108
  }
109
109
  )
110
110
  ] });
111
111
  }
112
112
  const h = "unknown.har";
113
- function ne({ logo: t, appName: r = "HAR Analyzer" }) {
114
- const [o, n] = a(h), [s, k] = a();
113
+ function ne({ logo: t, appName: o = "HAR Analyzer" }) {
114
+ const [r, n] = a(h), [s, C] = a();
115
115
  return /* @__PURE__ */ e(
116
116
  w,
117
117
  {
118
118
  logo: t,
119
- appName: r,
120
- content: /* @__PURE__ */ i(u, { children: [
121
- /* @__PURE__ */ e(W, { onChange: ({ harContent: C, harFileName: H }) => {
122
- k(C), n(H ?? h);
119
+ appName: o,
120
+ content: /* @__PURE__ */ i(f, { children: [
121
+ /* @__PURE__ */ e(I, { onChange: ({ harContent: g, harFileName: H }) => {
122
+ C(g), n(H ?? h);
123
123
  } }),
124
- s && /* @__PURE__ */ e(I, { harFileName: o, harContent: s })
124
+ s && /* @__PURE__ */ e(S, { harFileName: r, harContent: s })
125
125
  ] })
126
126
  }
127
127
  );
@@ -5,9 +5,10 @@ import $ from "@cloudscape-design/board-components/board-item";
5
5
  import b from "@cloudscape-design/components/button";
6
6
  import H from "@cloudscape-design/components/header";
7
7
  import { u as C } from "./chunks/index.js";
8
- import { u as B, H as z } from "./chunks/index2.js";
9
- import L from "./har-entry-viewer.js";
10
- import { a as _ } from "./chunks/har.js";
8
+ import z from "./har-entries-viewer.js";
9
+ import B from "./har-entry-viewer.js";
10
+ import { useHARAnalyzerPreferences as _ } from "./har-analyzer-preferences.js";
11
+ import { a as L } from "./chunks/har.js";
11
12
  const F = {
12
13
  dragHandleAriaLabel: "Drag handle",
13
14
  dragHandleAriaDescription: "Use Space or Enter to activate drag, arrow keys to move, Space or Enter to submit, or Escape to discard. Be sure to temporarily disable any screen reader navigation feature that may interfere with the functionality of the arrow keys.",
@@ -15,8 +16,8 @@ const F = {
15
16
  resizeHandleAriaDescription: "Use Space or Enter to activate resize, arrow keys to move, Space or Enter to submit, or Escape to discard. Be sure to temporarily disable any screen reader navigation feature that may interfere with the functionality of the arrow keys."
16
17
  };
17
18
  function d(e, n, t) {
18
- const i = n.length > 0 ? `Conflicts with ${n.map((r) => r.id).join(", ")}.` : "", s = t.length > 0 ? `Disturbed ${t.length} items.` : "";
19
- return [e, i, s].filter(Boolean).join(" ");
19
+ const r = n.length > 0 ? `Conflicts with ${n.map((i) => i.id).join(", ")}.` : "", s = t.length > 0 ? `Disturbed ${t.length} items.` : "";
20
+ return [e, r, s].filter(Boolean).join(" ");
20
21
  }
21
22
  const N = {
22
23
  liveAnnouncementDndStarted: (e) => e === "resize" ? "Resizing" : "Dragging",
@@ -29,8 +30,8 @@ const N = {
29
30
  );
30
31
  },
31
32
  liveAnnouncementDndItemResized: (e) => {
32
- const n = e.isMinimalColumnsReached ? " (minimal)" : "", t = e.isMinimalRowsReached ? " (minimal)" : "", i = e.direction === "horizontal" ? `columns ${e.placement.width}${n}` : `rows ${e.placement.height}${t}`;
33
- return d(`Item resized to ${i}.`, e.conflicts, e.disturbed);
33
+ const n = e.isMinimalColumnsReached ? " (minimal)" : "", t = e.isMinimalRowsReached ? " (minimal)" : "", r = e.direction === "horizontal" ? `columns ${e.placement.width}${n}` : `rows ${e.placement.height}${t}`;
34
+ return d(`Item resized to ${r}.`, e.conflicts, e.disturbed);
34
35
  },
35
36
  liveAnnouncementDndItemInserted: (e) => {
36
37
  const n = `column ${e.placement.x + 1}`, t = `row ${e.placement.y + 1}`;
@@ -47,7 +48,7 @@ function T(e) {
47
48
  const {
48
49
  components: n,
49
50
  definitions: t,
50
- onDefinitionsChange: i,
51
+ onDefinitionsChange: r,
51
52
  empty: s
52
53
  } = e;
53
54
  return /* @__PURE__ */ o(
@@ -55,14 +56,14 @@ function T(e) {
55
56
  {
56
57
  i18nStrings: N,
57
58
  items: t,
58
- renderItem: ({ id: r }, { removeItem: c }) => {
59
+ renderItem: ({ id: i }, { removeItem: c }) => {
59
60
  const {
60
61
  title: m,
61
62
  content: l,
62
63
  actions: u,
63
64
  counter: f,
64
65
  canRemove: h
65
- } = n[r] ?? {};
66
+ } = n[i] ?? {};
66
67
  return /* @__PURE__ */ o(
67
68
  $,
68
69
  {
@@ -73,15 +74,15 @@ function T(e) {
73
74
  }
74
75
  );
75
76
  },
76
- onItemsChange: ({ detail: { items: r } }) => {
77
- i(r);
77
+ onItemsChange: ({ detail: { items: i } }) => {
78
+ r(i);
78
79
  },
79
80
  empty: s
80
81
  }
81
82
  );
82
83
  }
83
84
  function k(e, n) {
84
- return B(`boardDefinitionsPreference_${e}`, n);
85
+ return _(`boardDefinitionsPreference_${e}`, n);
85
86
  }
86
87
  const v = 6, D = "har-entries-viewer", E = "selected-har-entry-viewer", R = [
87
88
  {
@@ -97,25 +98,25 @@ const v = 6, D = "har-entries-viewer", E = "selected-har-entry-viewer", R = [
97
98
  columnSpan: 12
98
99
  }
99
100
  ];
100
- function K(e) {
101
- const { harFileName: n, harContent: t } = e, i = I(() => _(t), [t]), [s, r] = g(), [c, m] = g(R);
101
+ function Q(e) {
102
+ const { harFileName: n, harContent: t } = e, r = I(() => L(t), [t]), [s, i] = g(), [c, m] = g(R);
102
103
  S(() => {
103
- r(void 0);
104
- }, [i]);
104
+ i(void 0);
105
+ }, [r]);
105
106
  const [l, u] = k(
106
107
  "har-contents-viewer",
107
108
  O
108
109
  ), f = (a) => {
109
110
  m(a), a.length > 1 && u(a);
110
111
  }, h = (a) => {
111
- r(a), c.length === 1 && m(l);
112
+ i(a), c.length === 1 && m(l);
112
113
  }, {
113
114
  HAREntriesFilters: p,
114
115
  filteredHAREntries: A
115
- } = C(i), y = {
116
+ } = C(r), y = {
116
117
  [D]: {
117
118
  title: n,
118
- counter: `(${A.length} / ${i.length})`,
119
+ counter: `(${A.length} / ${r.length})`,
119
120
  actions: /* @__PURE__ */ o(p, {}),
120
121
  content: /* @__PURE__ */ o(
121
122
  z,
@@ -127,7 +128,7 @@ function K(e) {
127
128
  },
128
129
  [E]: s ? {
129
130
  title: "Details",
130
- content: /* @__PURE__ */ o(L, { harEntry: s }),
131
+ content: /* @__PURE__ */ o(B, { harEntry: s }),
131
132
  canRemove: !0
132
133
  } : {
133
134
  title: "Select an entry to see details",
@@ -145,5 +146,5 @@ function K(e) {
145
146
  );
146
147
  }
147
148
  export {
148
- K as default
149
+ Q as default
149
150
  };