@scalar/api-reference 1.28.10 → 1.28.11

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.
@@ -1,12 +1,18 @@
1
- import { isDefined as S } from "@scalar/oas-utils/helpers";
2
- import { isConfigurationWithSources as m } from "@scalar/types/api-reference";
3
- import h from "github-slugger";
4
- import { computed as p, ref as y, watch as b } from "vue";
5
- const w = "api", g = new h(), I = (l, a = 0) => {
1
+ import { isDefined as h } from "@scalar/oas-utils/helpers";
2
+ import { isConfigurationWithSources as y } from "@scalar/types/api-reference";
3
+ import S from "github-slugger";
4
+ import { computed as v, ref as A, watch as b } from "vue";
5
+ const w = "api", g = new S(), C = (t) => t ? (Array.isArray(t) ? t : [t]).flatMap((u) => {
6
+ if (y(u)) {
7
+ const { sources: a, ...r } = u;
8
+ return (a == null ? void 0 : a.map((m) => ({ ...r, ...m }))) ?? [];
9
+ }
10
+ return [u];
11
+ }).map((u, a) => u && I(u, a)).filter(h) : [], I = (t, s = 0) => {
6
12
  const e = {
7
- ...l,
13
+ ...t,
8
14
  // @ts-expect-error this is before parsing so we transform the old style
9
- ...l.spec ?? {}
15
+ ...t.spec ?? {}
10
16
  };
11
17
  if (!(!(e != null && e.url) && !(e != null && e.content)))
12
18
  return g.reset(), e.title ? {
@@ -18,66 +24,61 @@ const w = "api", g = new h(), I = (l, a = 0) => {
18
24
  title: e.slug
19
25
  } : {
20
26
  ...e,
21
- slug: `api-${a + 1}`,
22
- title: `API #${a + 1}`
27
+ slug: `api-${s + 1}`,
28
+ title: `API #${s + 1}`
23
29
  };
24
30
  }, P = ({
25
- configuration: l,
26
- initialIndex: a,
31
+ configuration: t,
32
+ initialIndex: s,
27
33
  isIntersectionEnabled: e,
28
- hash: c,
29
- hashPrefix: d
34
+ hash: u,
35
+ hashPrefix: a
30
36
  }) => {
31
- const r = p(() => l.value ? (m(l.value) ? (
32
- // This IFFE is needed for the type guard as it doens't persist into the callback scope
33
- (() => {
34
- const { sources: t, ...u } = l.value;
35
- return (t == null ? void 0 : t.map((n) => ({ ...u, ...n }))) ?? [];
36
- })()
37
- ) : [l.value].flat()).map((t, u) => t && I(t, u)).filter(S) : []), o = y((() => {
37
+ const r = v(() => C(t.value)), f = A((() => {
38
38
  if (typeof window > "u")
39
- return typeof a == "number" ? a : 0;
40
- const t = new URL(window.location.href).searchParams.get(w);
41
- if (t) {
42
- const n = r.value.findIndex((f) => f.slug === t);
43
- if (n !== -1)
44
- return n;
45
- const s = Number.parseInt(t, 10);
46
- if (!isNaN(s) && s >= 0 && s < r.value.length)
47
- return s;
39
+ return typeof s == "number" ? s : 0;
40
+ const n = new URL(window.location.href).searchParams.get(w);
41
+ if (n) {
42
+ const o = r.value.findIndex((d) => d.slug === n);
43
+ if (o !== -1)
44
+ return o;
45
+ const i = Number.parseInt(n, 10);
46
+ if (!isNaN(i) && i >= 0 && i < r.value.length)
47
+ return i;
48
48
  }
49
- const u = r.value.findIndex((n) => "default" in n && n.default === !0);
50
- return u !== -1 ? u : typeof a == "number" ? a : 0;
51
- })()), v = p(() => {
52
- var t, u;
53
- return l.value && m(l.value) ? {
54
- ...l.value,
55
- ...(u = (t = l.value) == null ? void 0 : t.sources) == null ? void 0 : u[o.value],
56
- ...r.value[o.value]
49
+ const l = r.value.findIndex((o) => "default" in o && o.default === !0);
50
+ return l !== -1 ? l : typeof s == "number" ? s : 0;
51
+ })()), p = v(() => {
52
+ var n, l;
53
+ return t.value && y(t.value) ? {
54
+ ...t.value,
55
+ ...(l = (n = t.value) == null ? void 0 : n.sources) == null ? void 0 : l[f.value],
56
+ ...r.value[f.value]
57
57
  } : {
58
- ...[l.value].flat()[o.value] ?? {},
59
- ...r.value[o.value]
58
+ ...[t.value].flat()[f.value] ?? {},
59
+ ...r.value[f.value]
60
60
  };
61
61
  });
62
62
  return b(
63
- o,
64
- (i) => {
65
- var s, f;
63
+ f,
64
+ (c) => {
65
+ var i, d;
66
66
  if (typeof window > "u" || r.value.length === 1)
67
67
  return;
68
- const t = new URL(window.location.href), u = r.value[i], n = (u == null ? void 0 : u.slug) ?? i.toString();
69
- t.searchParams.set(w, n), t.hash = "", window.history.replaceState({}, "", t.toString()), c.value = "", d.value = "", e.value = !1, typeof window < "u" && window.scrollTo({ top: 0, behavior: "instant" }), (f = (s = v.value).onDocumentSelect) == null || f.call(s);
68
+ const n = new URL(window.location.href), l = r.value[c], o = (l == null ? void 0 : l.slug) ?? c.toString();
69
+ n.searchParams.set(w, o), n.hash = "", window.history.replaceState({}, "", n.toString()), u.value = "", a.value = "", e.value = !1, typeof window < "u" && window.scrollTo({ top: 0, behavior: "instant" }), (d = (i = p.value).onDocumentSelect) == null || d.call(i);
70
70
  },
71
71
  { flush: "sync" }
72
72
  ), {
73
- selectedConfiguration: v,
73
+ selectedConfiguration: p,
74
74
  availableDocuments: r,
75
- selectedDocumentIndex: o,
75
+ selectedDocumentIndex: f,
76
76
  isIntersectionEnabled: e,
77
- hash: c,
78
- hashPrefix: d
77
+ hash: u,
78
+ hashPrefix: a
79
79
  };
80
80
  };
81
81
  export {
82
+ C as normalizeConfigurations,
82
83
  P as useMultipleDocuments
83
84
  };
@@ -1,3 +1,4 @@
1
+ import type { ApiReferenceConfiguration } from '@scalar/types/api-reference';
1
2
  import type { Heading, Tag, TransformedOperation } from '@scalar/types/legacy';
2
3
  import { type InjectionKey, type Ref } from 'vue';
3
4
  export type NavState = {
@@ -15,8 +16,10 @@ export declare const NAV_STATE_SYMBOL: InjectionKey<NavState>;
15
16
  *
16
17
  * isIntersectionEnabled is a hack to prevent intersection observer from triggering
17
18
  * when clicking on sidebar links or going backwards
19
+ *
20
+ * @param _config this is used to pass in the config if we have not provided it yet to the useConfig hook such as in ApiReferenceLayout
18
21
  */
19
- export declare const useNavState: () => {
22
+ export declare const useNavState: (_config?: Ref<ApiReferenceConfiguration>) => {
20
23
  hash: Ref<string, string>;
21
24
  /** Sets the prefix for the hash */
22
25
  setHashPrefix: (prefix: string) => void;
@@ -38,8 +41,7 @@ export declare const useNavState: () => {
38
41
  * Replacement is used so that hash changes don't trigger the url hash watcher and cause a scroll
39
42
  */
40
43
  replaceUrlState: (replacementHash: string, url?: string) => void;
41
- /** Gets the portion of the hash used by the references */
42
- getReferenceHash: () => string;
44
+ getReferenceId: () => string;
43
45
  getWebhookId: (webhook?: {
44
46
  name: string;
45
47
  method?: string;
@@ -53,6 +55,6 @@ export declare const useNavState: () => {
53
55
  getSectionId: (hashStr?: string) => string;
54
56
  getTagId: (tag: Tag) => string;
55
57
  isIntersectionEnabled: Ref<boolean, boolean>;
56
- updateHash: () => void;
58
+ updateHash: () => string;
57
59
  };
58
60
  //# sourceMappingURL=useNavState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useNavState.d.ts","sourceRoot":"","sources":["../../src/hooks/useNavState.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAE9E,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,GAAG,EAAe,MAAM,KAAK,CAAA;AAE9D,MAAM,MAAM,QAAQ,GAAG;IACrB,0EAA0E;IAC1E,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACjB,2CAA2C;IAC3C,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACvB,sFAAsF;IACtF,qBAAqB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;CACpC,CAAA;AACD,eAAO,MAAM,gBAAgB,EAAe,YAAY,CAAC,QAAQ,CAAC,CAAA;AAOlE;;;;;;GAMG;AACH,eAAO,MAAM,WAAW;;IAiIpB,mCAAmC;4BACX,MAAM;IAG9B;;;;OAIG;+BA7E4B,MAAM;IA+ErC;;;;;OAKG;oCA3FkC,MAAM;IA6F3C;;;OAGG;uCAlHqC,MAAM;IAoH9C,0DAA0D;;6BAnC5B;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;yBA9BrC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;4BAXb,OAAO;gCA6BH,oBAAoB,aAAa,GAAG;iCA/FnC,MAAM;;oBAwFnB,GAAG;;;CAkE3B,CAAA"}
1
+ {"version":3,"file":"useNavState.d.ts","sourceRoot":"","sources":["../../src/hooks/useNavState.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAE9E,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,GAAG,EAAe,MAAM,KAAK,CAAA;AAE9D,MAAM,MAAM,QAAQ,GAAG;IACrB,0EAA0E;IAC1E,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACjB,2CAA2C;IAC3C,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACvB,sFAAsF;IACtF,qBAAqB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;CACpC,CAAA;AACD,eAAO,MAAM,gBAAgB,EAAe,YAAY,CAAC,QAAQ,CAAC,CAAA;AAOlE;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,aAAc,GAAG,CAAC,yBAAyB,CAAC;;IA+HhE,mCAAmC;4BACX,MAAM;IAG9B;;;;OAIG;+BArE4B,MAAM;IAuErC;;;;;OAKG;oCAnFkC,MAAM;IAqF3C;;;OAGG;uCA1GqC,MAAM;;6BAyEhB;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;yBA9BrC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;4BAXb,OAAO;gCA6BH,oBAAoB,aAAa,GAAG;iCA7FnC,MAAM;;oBAsFnB,GAAG;;;CAiE3B,CAAA"}
@@ -1,63 +1,60 @@
1
- import { useConfig as $ } from "./useConfig.js";
1
+ import { useConfig as b } from "./useConfig.js";
2
2
  import { combineUrlAndPath as R } from "@scalar/oas-utils/helpers";
3
- import { slug as l } from "github-slugger";
4
- import { ref as i, inject as b } from "vue";
5
- const y = Symbol(), U = i(!1), P = i(""), k = i(""), C = () => {
6
- const { isIntersectionEnabled: h, hash: r, hashPrefix: o } = b(y, {
7
- isIntersectionEnabled: U,
8
- hash: P,
9
- hashPrefix: k
10
- }), t = $(), c = (e) => {
3
+ import { slug as i } from "github-slugger";
4
+ import { ref as l, inject as y } from "vue";
5
+ const U = Symbol(), P = l(!1), k = l(""), x = l(""), T = (d) => {
6
+ const { isIntersectionEnabled: f, hash: o, hashPrefix: r } = y(U, {
7
+ isIntersectionEnabled: P,
8
+ hash: k,
9
+ hashPrefix: x
10
+ }), t = d ?? b(), c = (e) => {
11
11
  var n;
12
12
  if (!t.value.pathRouting)
13
13
  return "";
14
14
  const a = new RegExp("^" + ((n = t.value.pathRouting) == null ? void 0 : n.basePath) + "/?");
15
15
  return decodeURIComponent(e.replace(a, ""));
16
- }, d = (e = r.value) => {
17
- var g;
18
- const a = (g = e.match(/(tag\/[^/]+)/)) == null ? void 0 : g[0], n = e.startsWith("model") ? "models" : "", u = e.startsWith("webhook") ? "webhooks" : "";
16
+ }, p = (e = o.value) => {
17
+ var h;
18
+ const a = (h = e.match(/(tag\/[^/]+)/)) == null ? void 0 : h[0], n = e.startsWith("model") ? "models" : "", u = e.startsWith("webhook") ? "webhooks" : "";
19
19
  return a || n || u;
20
- }, f = () => {
21
- r.value = t.value.pathRouting ? c(window.location.pathname) : (
22
- // Must remove the prefix from the hash as the internal hash value should be pure
23
- decodeURIComponent(window.location.hash.replace(/^#/, "")).slice(o.value.length)
24
- );
25
- }, p = (e, a = window.location.href) => {
20
+ }, g = () => t.value.pathRouting ? c(window.location.pathname) : (
21
+ // Must remove the prefix from the hash as the internal hash value should be pure
22
+ decodeURIComponent(window.location.hash.replace(/^#/, "")).slice(r.value.length)
23
+ ), m = () => o.value = g(), v = (e, a = window.location.href) => {
26
24
  const n = new URL(a);
27
- t.value.pathRouting ? n.pathname = R(t.value.pathRouting.basePath, e) : n.hash = o.value + e, r.value = e, window.history.replaceState({}, "", n);
28
- }, m = (e, a = window.location.href, n = window.location.search) => {
25
+ t.value.pathRouting ? n.pathname = R(t.value.pathRouting.basePath, e) : n.hash = r.value + e, o.value = e, window.history.replaceState({}, "", n);
26
+ }, I = (e, a = window.location.href, n = window.location.search) => {
29
27
  const u = new URL(a);
30
- return u.hash = o.value + e, u.search = n, u.toString();
31
- }, v = (e = r.value) => `${o.value}${e}`, I = () => decodeURIComponent(window.location.hash.replace(/^#/, "").slice(o.value.length)), w = (e) => typeof t.value.generateHeadingSlug == "function" ? `${t.value.generateHeadingSlug(e)}` : e.slug ? `description/${e.slug}` : "", S = (e) => e != null && e.name ? typeof t.value.generateModelSlug == "function" ? `model/${t.value.generateModelSlug(e)}` : `model/${l(e.name)}` : "models", s = (e) => typeof t.value.generateTagSlug == "function" ? `tag/${t.value.generateTagSlug(e)}` : `tag/${l(e.name)}`;
28
+ return u.hash = r.value + e, u.search = n, u.toString();
29
+ }, w = (e = o.value) => `${r.value}${e}`, S = (e) => typeof t.value.generateHeadingSlug == "function" ? `${t.value.generateHeadingSlug(e)}` : e.slug ? `description/${e.slug}` : "", $ = (e) => e != null && e.name ? typeof t.value.generateModelSlug == "function" ? `model/${t.value.generateModelSlug(e)}` : `model/${i(e.name)}` : "models", s = (e) => typeof t.value.generateTagSlug == "function" ? `tag/${t.value.generateTagSlug(e)}` : `tag/${i(e.name)}`;
32
30
  return {
33
- hash: r,
31
+ hash: o,
34
32
  /** Sets the prefix for the hash */
35
33
  setHashPrefix: (e) => {
36
- o.value = e;
34
+ r.value = e;
37
35
  },
38
36
  /**
39
37
  * Gets the full hash with the prefix
40
38
  * @param hashTarget The hash to target with the return
41
39
  * @returns The full hash
42
40
  */
43
- getFullHash: v,
41
+ getFullHash: w,
44
42
  /**
45
43
  * Gets the hashed url with the prefix
46
44
  * @param replacementHash The hash to replace the current hash with
47
45
  * @param url The url to get the hashed url from
48
46
  * @returns The hashed url
49
47
  */
50
- getHashedUrl: m,
48
+ getHashedUrl: I,
51
49
  /**
52
50
  * Replaces the URL state with the new url and hash
53
51
  * Replacement is used so that hash changes don't trigger the url hash watcher and cause a scroll
54
52
  */
55
- replaceUrlState: p,
56
- /** Gets the portion of the hash used by the references */
57
- getReferenceHash: I,
58
- getWebhookId: (e) => e != null && e.name ? typeof t.value.generateWebhookSlug == "function" ? `webhook/${t.value.generateWebhookSlug(e)}` : `webhook/${e.method}/${l(e.name)}` : "webhooks",
59
- getModelId: S,
60
- getHeadingId: w,
53
+ replaceUrlState: v,
54
+ getReferenceId: g,
55
+ getWebhookId: (e) => e != null && e.name ? typeof t.value.generateWebhookSlug == "function" ? `webhook/${t.value.generateWebhookSlug(e)}` : `webhook/${e.method}/${i(e.name)}` : "webhooks",
56
+ getModelId: $,
57
+ getHeadingId: S,
61
58
  getOperationId: (e, a) => {
62
59
  var n;
63
60
  return typeof t.value.generateOperationSlug == "function" ? `${s(a)}/${t.value.generateOperationSlug({
@@ -68,13 +65,13 @@ const y = Symbol(), U = i(!1), P = i(""), k = i(""), C = () => {
68
65
  })}` : `${s(a)}/${e.httpVerb}${e.path}`;
69
66
  },
70
67
  getPathRoutingId: c,
71
- getSectionId: d,
68
+ getSectionId: p,
72
69
  getTagId: s,
73
- isIntersectionEnabled: h,
74
- updateHash: f
70
+ isIntersectionEnabled: f,
71
+ updateHash: m
75
72
  };
76
73
  };
77
74
  export {
78
- y as NAV_STATE_SYMBOL,
79
- C as useNavState
75
+ U as NAV_STATE_SYMBOL,
76
+ T as useNavState
80
77
  };