app-devtools 0.13.0 → 0.16.0

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 (2) hide show
  1. package/dist/main.js +116 -10
  2. package/package.json +2 -1
package/dist/main.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import dayjs from 'dayjs';
2
2
  import { dequal } from 'dequal';
3
+ import { produce as produce$1 } from 'immer';
3
4
  import { nanoid } from 'nanoid';
4
5
  import { parse } from 'regexparam';
5
6
  import * as diff from 'diff';
@@ -1445,7 +1446,7 @@ const colors = createThemeColors({
1445
1446
  black: "#000"
1446
1447
  });
1447
1448
  const fonts = {
1448
- primary: "Work Sans, sans-serif",
1449
+ primary: '"Work Sans", sans-serif',
1449
1450
  decorative: '"Fira Code", monospaced'
1450
1451
  };
1451
1452
 
@@ -1481,8 +1482,11 @@ function createSignalRef(initialValue) {
1481
1482
  set value(newValue) {
1482
1483
  setValue(() => newValue);
1483
1484
  },
1484
- set(newValue) {
1485
- setValue(() => newValue);
1485
+ produce(recipe) {
1486
+ setValue((val) => produce$1(val, recipe));
1487
+ },
1488
+ peek() {
1489
+ return untrack(value);
1486
1490
  }
1487
1491
  };
1488
1492
  }
@@ -1819,7 +1823,7 @@ function addCall(request) {
1819
1823
  url: pathURL,
1820
1824
  type: request.type,
1821
1825
  subType: request.subType
1822
- }) || typeof relatedConfig?.match === "string" && relatedConfig.match;
1826
+ }) || typeof relatedConfig?.match === "string" && `${request.type}${request.subType || ""}{relatedConfig.match}`;
1823
1827
  const callID = btoa(
1824
1828
  normalizedCallId || `${pathURL.pathname}|${request.type}${request.subType ? `|${request.subType}` : ""}`
1825
1829
  );
@@ -1875,6 +1879,49 @@ function addCall(request) {
1875
1879
  };
1876
1880
  }
1877
1881
 
1882
+ const normalizeString = (str) => str.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim();
1883
+
1884
+ function searchQueryMatch(query, string) {
1885
+ const queryIndex = normalizeString(String(string)).indexOf(
1886
+ normalizeString(String(query))
1887
+ );
1888
+ return {
1889
+ matched: queryIndex !== -1,
1890
+ matchedIndex: queryIndex
1891
+ };
1892
+ }
1893
+
1894
+ function sortBy(arr, getPriority, { lowerFirst } = {}) {
1895
+ return [...arr].sort((a, b) => {
1896
+ const aPriority = getPriority(a);
1897
+ const bPriority = getPriority(b);
1898
+ if (aPriority < bPriority) {
1899
+ return lowerFirst ? -1 : 1;
1900
+ }
1901
+ if (aPriority > bPriority) {
1902
+ return lowerFirst ? 1 : -1;
1903
+ }
1904
+ return 0;
1905
+ });
1906
+ }
1907
+
1908
+ function searchItems({
1909
+ items,
1910
+ searchQuery,
1911
+ getStringToMatch
1912
+ }) {
1913
+ const searchedItems = [];
1914
+ for (const item of items) {
1915
+ const search = searchQueryMatch(searchQuery, getStringToMatch(item));
1916
+ if (search.matched) {
1917
+ searchedItems.push({ item, matchedIndex: search.matchedIndex });
1918
+ }
1919
+ }
1920
+ return sortBy(searchedItems, (item) => item.matchedIndex, {
1921
+ lowerFirst: true
1922
+ }).map(({ item }) => item);
1923
+ }
1924
+
1878
1925
  const _tmpl$$8 = /*#__PURE__*/template(`<div><h1>API EXPLORER</h1><label><input type="text" placeholder="Search"></label><div></div></div>`);
1879
1926
  const containerStyle$8 = u`
1880
1927
  &&& {
@@ -1933,12 +1980,10 @@ const searchStyle = u`
1933
1980
  const ApiExplorerMenu = () => {
1934
1981
  const search = createSignalRef('');
1935
1982
  const menuItems = createReconciledArray(() => {
1983
+ const [callSearch = '', requestSearch = ''] = search.value.split('>');
1936
1984
  const callsEntries = Object.entries(callsStore.calls);
1937
1985
  const filtered = [];
1938
1986
  for (const [key, value] of callsEntries.reverse()) {
1939
- if (search.value.trim() && !value.name.includes(search.value.toLowerCase())) {
1940
- continue;
1941
- }
1942
1987
  const subitemsWithAlias = new Set();
1943
1988
  for (const request of value.requests) {
1944
1989
  if (request.alias) {
@@ -1947,11 +1992,23 @@ const ApiExplorerMenu = () => {
1947
1992
  }
1948
1993
  filtered.push({
1949
1994
  id: key,
1950
- subitemsWithAlias: [...subitemsWithAlias],
1995
+ subitemsWithAlias: searchItems({
1996
+ items: [...subitemsWithAlias],
1997
+ searchQuery: requestSearch.trim(),
1998
+ getStringToMatch(item) {
1999
+ return item;
2000
+ }
2001
+ }),
1951
2002
  ...value
1952
2003
  });
1953
2004
  }
1954
- return filtered;
2005
+ return searchItems({
2006
+ items: filtered,
2007
+ searchQuery: callSearch.trim(),
2008
+ getStringToMatch(item) {
2009
+ return item.name;
2010
+ }
2011
+ });
1955
2012
  }, 'id');
1956
2013
  const _currentCallId = createMemo(() => uiStore.selectedCall);
1957
2014
  return (() => {
@@ -3472,9 +3529,58 @@ const Root = () => {
3472
3529
  return createComponent(App, {});
3473
3530
  };
3474
3531
 
3532
+ function getGoogleFontsImportUrl(fonts) {
3533
+ let url = "";
3534
+ fonts.forEach(({ family, weights, italics }) => {
3535
+ url += `${url ? "&" : ""}family=${family}:`;
3536
+ if (weights[1] === "..") {
3537
+ url += `wght@${weights[0]}..${weights[2]}`;
3538
+ } else {
3539
+ url += "ital,wght@";
3540
+ weights.forEach((value, i) => {
3541
+ if (i !== 0) {
3542
+ url += ";";
3543
+ }
3544
+ url += `0,${value}`;
3545
+ });
3546
+ italics?.forEach((value) => {
3547
+ url += `;1,${value}`;
3548
+ });
3549
+ }
3550
+ });
3551
+ return `https://fonts.googleapis.com/css2?${url}&display=swap`;
3552
+ }
3553
+
3554
+ let fontsWereAdded = false;
3555
+ function addGoogleFonts() {
3556
+ if (fontsWereAdded)
3557
+ return;
3558
+ fontsWereAdded = true;
3559
+ const googleFonts = getGoogleFontsImportUrl([
3560
+ {
3561
+ family: "Work+Sans",
3562
+ weights: [300, "..", 700]
3563
+ }
3564
+ ]);
3565
+ const headID = document.getElementsByTagName("head")[0];
3566
+ const link = document.createElement("link");
3567
+ link.type = "text/css";
3568
+ link.rel = "stylesheet";
3569
+ link.href = googleFonts;
3570
+ headID?.appendChild(link);
3571
+ }
3572
+
3475
3573
  let unmount = () => {};
3574
+ let isInitialized = false;
3476
3575
  function initializeApp() {
3477
3576
  dayjs.extend(relativeTime);
3577
+ if (isInitialized) {
3578
+ unmountApp();
3579
+ isInitialized = false;
3580
+ return;
3581
+ }
3582
+ isInitialized = true;
3583
+ addGoogleFonts();
3478
3584
  if (navigator.platform.indexOf('Win') > -1) {
3479
3585
  document.body.classList.add('windows');
3480
3586
  }
@@ -3493,11 +3599,11 @@ function initializeDevTools({
3493
3599
  }) {
3494
3600
  tinykeys(window, {
3495
3601
  [shortcut]: (e) => {
3496
- e.preventDefault();
3497
3602
  const active = document.activeElement;
3498
3603
  const enteringText = active instanceof HTMLElement && (active.isContentEditable || active.tagName === "INPUT" || active.tagName === "TEXTAREA");
3499
3604
  if (enteringText)
3500
3605
  return;
3606
+ e.preventDefault();
3501
3607
  initializeApp();
3502
3608
  }
3503
3609
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "app-devtools",
3
- "version": "0.13.0",
3
+ "version": "0.16.0",
4
4
  "description": "",
5
5
  "packageManager": "pnpm@6.29.1",
6
6
  "license": "MIT",
@@ -24,6 +24,7 @@
24
24
  "dayjs": "^1.11.7",
25
25
  "dequal": "^2.0.3",
26
26
  "diff": "^5.1.0",
27
+ "immer": "^9.0.19",
27
28
  "klona": "^2.0.6",
28
29
  "nanoid": "^4.0.1",
29
30
  "regexparam": "^2.0.1",