@docusaurus/theme-common 0.0.0-4518 → 0.0.0-4524
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/lib/components/Collapsible/index.d.ts.map +1 -1
- package/lib/components/Collapsible/index.js +9 -5
- package/lib/components/Collapsible/index.js.map +1 -1
- package/lib/components/Details/index.js +1 -1
- package/lib/components/Details/index.js.map +1 -1
- package/lib/hooks/useWindowSize.d.ts.map +1 -1
- package/lib/hooks/useWindowSize.js +4 -2
- package/lib/hooks/useWindowSize.js.map +1 -1
- package/lib/utils/ThemeClassNames.d.ts.map +1 -1
- package/lib/utils/ThemeClassNames.js +2 -1
- package/lib/utils/ThemeClassNames.js.map +1 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts.map +1 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +3 -7
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js.map +1 -1
- package/lib/utils/docsUtils.d.ts.map +1 -1
- package/lib/utils/docsUtils.js +4 -6
- package/lib/utils/docsUtils.js.map +1 -1
- package/lib/utils/historyUtils.d.ts +11 -0
- package/lib/utils/historyUtils.d.ts.map +1 -1
- package/lib/utils/historyUtils.js +9 -8
- package/lib/utils/historyUtils.js.map +1 -1
- package/lib/utils/jsUtils.d.ts +5 -2
- package/lib/utils/jsUtils.d.ts.map +1 -1
- package/lib/utils/jsUtils.js +5 -2
- package/lib/utils/jsUtils.js.map +1 -1
- package/lib/utils/mobileSecondaryMenu.d.ts.map +1 -1
- package/lib/utils/mobileSecondaryMenu.js.map +1 -1
- package/lib/utils/reactUtils.d.ts +18 -0
- package/lib/utils/reactUtils.d.ts.map +1 -1
- package/lib/utils/reactUtils.js +20 -11
- package/lib/utils/reactUtils.js.map +1 -1
- package/lib/utils/regexpUtils.d.ts +1 -1
- package/lib/utils/regexpUtils.js +1 -1
- package/lib/utils/storageUtils.d.ts +4 -4
- package/lib/utils/storageUtils.d.ts.map +1 -1
- package/lib/utils/storageUtils.js +12 -14
- package/lib/utils/storageUtils.js.map +1 -1
- package/lib/utils/tocUtils.d.ts.map +1 -1
- package/lib/utils/tocUtils.js +1 -3
- package/lib/utils/tocUtils.js.map +1 -1
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -1
- package/lib/utils/useAlternatePageUtils.js +2 -1
- package/lib/utils/useAlternatePageUtils.js.map +1 -1
- package/lib/utils/useContextualSearchFilters.js +2 -2
- package/lib/utils/useContextualSearchFilters.js.map +1 -1
- package/lib/utils/usePluralForm.d.ts.map +1 -1
- package/lib/utils/usePluralForm.js +25 -20
- package/lib/utils/usePluralForm.js.map +1 -1
- package/lib/utils/useTOCHighlight.d.ts.map +1 -1
- package/lib/utils/useTOCHighlight.js +20 -17
- package/lib/utils/useTOCHighlight.js.map +1 -1
- package/package.json +8 -8
- package/src/components/Collapsible/index.tsx +14 -9
- package/src/components/Details/index.tsx +1 -1
- package/src/hooks/useWindowSize.ts +4 -2
- package/src/utils/ThemeClassNames.ts +2 -1
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +3 -5
- package/src/utils/docsUtils.tsx +5 -6
- package/src/utils/historyUtils.ts +9 -8
- package/src/utils/jsUtils.ts +5 -2
- package/src/utils/mobileSecondaryMenu.tsx +6 -5
- package/src/utils/reactUtils.tsx +20 -11
- package/src/utils/regexpUtils.ts +1 -1
- package/src/utils/storageUtils.ts +12 -13
- package/src/utils/tocUtils.ts +1 -2
- package/src/utils/useAlternatePageUtils.ts +4 -3
- package/src/utils/useContextualSearchFilters.ts +2 -2
- package/src/utils/usePluralForm.ts +28 -22
- package/src/utils/useTOCHighlight.ts +20 -17
package/lib/utils/tocUtils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tocUtils.js","sourceRoot":"","sources":["../../src/utils/tocUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,OAA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gD;AAChD,MAAM,UAAU,YAAY,CAAC,EAC3B,GAAG,EACH,eAAe,EACf,eAAe,GACA;IACf,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,eAAe,EAAE,eAAe,EAAC,CAAC,EACxD,CAAC,GAAG,EAAE,eAAe,EAAE,eAAe,CAAC,CACxC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAlternatePageUtils.d.ts","sourceRoot":"","sources":["../../src/utils/useAlternatePageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,wBAAgB,qBAAqB,IAAI;IACvC,SAAS,EAAE,CAAC,EACV,MAAM,EACN,cAAc,GACf,EAAE;QACD,MAAM,EAAE,MAAM,CAAC;QACf,cAAc,EAAE,OAAO,CAAC;KACzB,KAAK,MAAM,CAAC;CACd,
|
|
1
|
+
{"version":3,"file":"useAlternatePageUtils.d.ts","sourceRoot":"","sources":["../../src/utils/useAlternatePageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,wBAAgB,qBAAqB,IAAI;IACvC,SAAS,EAAE,CAAC,EACV,MAAM,EACN,cAAc,GACf,EAAE;QACD,MAAM,EAAE,MAAM,CAAC;QACf,cAAc,EAAE,OAAO,CAAC;KACzB,KAAK,MAAM,CAAC;CACd,CAqCA"}
|
|
@@ -21,7 +21,8 @@ export function useAlternatePageUtils() {
|
|
|
21
21
|
? `${baseUrlUnlocalized}`
|
|
22
22
|
: `${baseUrlUnlocalized}${locale}/`;
|
|
23
23
|
}
|
|
24
|
-
// TODO support correct alternate url when localized site is deployed on
|
|
24
|
+
// TODO support correct alternate url when localized site is deployed on
|
|
25
|
+
// another domain
|
|
25
26
|
function createUrl({ locale, fullyQualified, }) {
|
|
26
27
|
return `${fullyQualified ? url : ''}${getLocalizedBaseUrl(locale)}${pathnameSuffix}`;
|
|
27
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAlternatePageUtils.js","sourceRoot":"","sources":["../../src/utils/useAlternatePageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C,kEAAkE;AAClE,kDAAkD;AAClD,qFAAqF;AACrF,MAAM,UAAU,qBAAqB;IASnC,MAAM,EACJ,UAAU,EAAE,EAAC,OAAO,EAAE,GAAG,EAAC,EAC1B,IAAI,EAAE,EAAC,aAAa,EAAE,aAAa,EAAC,GACrC,GAAG,oBAAoB,EAAE,CAAC;IAC3B,MAAM,EAAC,QAAQ,EAAC,GAAG,WAAW,EAAE,CAAC;IAEjC,MAAM,kBAAkB,GACtB,aAAa,KAAK,aAAa;QAC7B,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,aAAa,GAAG,EAAE,GAAG,CAAC,CAAC;IAEjD,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAErD,SAAS,mBAAmB,CAAC,MAAc;QACzC,OAAO,MAAM,KAAK,aAAa;YAC7B,CAAC,CAAC,GAAG,kBAAkB,EAAE;YACzB,CAAC,CAAC,GAAG,kBAAkB,GAAG,MAAM,GAAG,CAAC;IACxC,CAAC;IAED,
|
|
1
|
+
{"version":3,"file":"useAlternatePageUtils.js","sourceRoot":"","sources":["../../src/utils/useAlternatePageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C,kEAAkE;AAClE,kDAAkD;AAClD,qFAAqF;AACrF,MAAM,UAAU,qBAAqB;IASnC,MAAM,EACJ,UAAU,EAAE,EAAC,OAAO,EAAE,GAAG,EAAC,EAC1B,IAAI,EAAE,EAAC,aAAa,EAAE,aAAa,EAAC,GACrC,GAAG,oBAAoB,EAAE,CAAC;IAC3B,MAAM,EAAC,QAAQ,EAAC,GAAG,WAAW,EAAE,CAAC;IAEjC,MAAM,kBAAkB,GACtB,aAAa,KAAK,aAAa;QAC7B,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,aAAa,GAAG,EAAE,GAAG,CAAC,CAAC;IAEjD,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAErD,SAAS,mBAAmB,CAAC,MAAc;QACzC,OAAO,MAAM,KAAK,aAAa;YAC7B,CAAC,CAAC,GAAG,kBAAkB,EAAE;YACzB,CAAC,CAAC,GAAG,kBAAkB,GAAG,MAAM,GAAG,CAAC;IACxC,CAAC;IAED,wEAAwE;IACxE,iBAAiB;IACjB,SAAS,SAAS,CAAC,EACjB,MAAM,EACN,cAAc,GAMf;QACC,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,mBAAmB,CACvD,MAAM,CACP,GAAG,cAAc,EAAE,CAAC;IACvB,CAAC;IAED,OAAO,EAAC,SAAS,EAAC,CAAC;AACrB,CAAC"}
|
|
@@ -8,8 +8,8 @@ import { useAllDocsData, useActivePluginAndVersion, } from '@docusaurus/plugin-c
|
|
|
8
8
|
import { useDocsPreferredVersionByPluginId } from './docsPreferredVersion/useDocsPreferredVersion';
|
|
9
9
|
import { docVersionSearchTag, DEFAULT_SEARCH_TAG } from './searchUtils';
|
|
10
10
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
11
|
-
// We may want to support multiple search engines, don't couple that to
|
|
12
|
-
// Maybe users
|
|
11
|
+
// We may want to support multiple search engines, don't couple that to
|
|
12
|
+
// Algolia/DocSearch. Maybe users want to use their own search engine solution
|
|
13
13
|
export function useContextualSearchFilters() {
|
|
14
14
|
const { i18n } = useDocusaurusContext();
|
|
15
15
|
const allDocsData = useAllDocsData();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useContextualSearchFilters.js","sourceRoot":"","sources":["../../src/utils/useContextualSearchFilters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,cAAc,EACd,yBAAyB,GAC1B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAC,iCAAiC,EAAC,MAAM,gDAAgD,CAAC;AACjG,OAAO,EAAC,mBAAmB,EAAE,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACtE,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAOpE,
|
|
1
|
+
{"version":3,"file":"useContextualSearchFilters.js","sourceRoot":"","sources":["../../src/utils/useContextualSearchFilters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,cAAc,EACd,yBAAyB,GAC1B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAC,iCAAiC,EAAC,MAAM,gDAAgD,CAAC;AACjG,OAAO,EAAC,mBAAmB,EAAE,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACtE,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAOpE,uEAAuE;AACvE,8EAA8E;AAC9E,MAAM,UAAU,0BAA0B;IACxC,MAAM,EAAC,IAAI,EAAC,GAAG,oBAAoB,EAAE,CAAC;IACtC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAAM,sBAAsB,GAAG,yBAAyB,EAAE,CAAC;IAC3D,MAAM,8BAA8B,GAAG,iCAAiC,EAAE,CAAC;IAE3E,SAAS,gBAAgB,CAAC,QAAgB;;QACxC,MAAM,aAAa,GACjB,CAAA,MAAA,sBAAsB,aAAtB,sBAAsB,uBAAtB,sBAAsB,CAAE,YAAY,0CAAE,QAAQ,MAAK,QAAQ;YACzD,CAAC,CAAC,sBAAsB,CAAC,aAAa;YACtC,CAAC,CAAC,SAAS,CAAC;QAEhB,MAAM,gBAAgB,GAAG,8BAA8B,CAAC,QAAQ,CAAC,CAAC;QAElE,MAAM,aAAa,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAE,CAAC;QAE5E,MAAM,OAAO,GAAG,MAAA,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,gBAAgB,mCAAI,aAAa,CAAC;QAEnE,OAAO,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,IAAI,GAAG;QACX,kBAAkB;QAClB,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC;KAClD,CAAC;IAEF,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,aAAa;QAC1B,IAAI;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePluralForm.d.ts","sourceRoot":"","sources":["../../src/utils/usePluralForm.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"usePluralForm.d.ts","sourceRoot":"","sources":["../../src/utils/usePluralForm.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA8GH,wBAAgB,aAAa,IAAI;IAC/B,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,KAAK,MAAM,CAAC;CAClE,CAMA"}
|
|
@@ -34,21 +34,27 @@ function createLocalePluralForms(locale) {
|
|
|
34
34
|
select: (count) => pluralRules.select(count),
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Poor man's PluralSelector implementation, using an english fallback. We want
|
|
39
|
+
* a lightweight, future-proof and good-enough solution. We don't want a perfect
|
|
40
|
+
* and heavy solution.
|
|
41
|
+
*
|
|
42
|
+
* Docusaurus classic theme has only 2 deeply nested labels requiring complex
|
|
43
|
+
* plural rules. We don't want to use Intl + PluralRules polyfills + full ICU
|
|
44
|
+
* syntax (react-intl) just for that.
|
|
45
|
+
*
|
|
46
|
+
* Notes:
|
|
47
|
+
* - 2021: 92+% Browsers support Intl.PluralRules, and support will increase in
|
|
48
|
+
* the future
|
|
49
|
+
* - NodeJS >= 13 has full ICU support by default
|
|
50
|
+
* - In case of "mismatch" between SSR and Browser ICU support, React keeps
|
|
51
|
+
* working!
|
|
52
|
+
*/
|
|
48
53
|
function useLocalePluralForms() {
|
|
49
54
|
const { i18n: { currentLocale }, } = useDocusaurusContext();
|
|
50
55
|
return useMemo(() => {
|
|
51
|
-
// @ts-expect-error checking Intl.PluralRules in case browser doesn't
|
|
56
|
+
// @ts-expect-error checking Intl.PluralRules in case browser doesn't
|
|
57
|
+
// have it (e.g Safari 12-)
|
|
52
58
|
if (Intl.PluralRules) {
|
|
53
59
|
try {
|
|
54
60
|
return createLocalePluralForms(currentLocale);
|
|
@@ -74,15 +80,14 @@ function selectPluralMessage(pluralMessages, count, localePluralForms) {
|
|
|
74
80
|
if (parts.length === 1) {
|
|
75
81
|
return parts[0];
|
|
76
82
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
console.error(`For locale=${localePluralForms.locale}, a maximum of ${localePluralForms.pluralForms.length} plural forms are expected (${localePluralForms.pluralForms}), but the message contains ${parts.length} plural forms: ${pluralMessages} `);
|
|
80
|
-
}
|
|
81
|
-
const pluralForm = localePluralForms.select(count);
|
|
82
|
-
const pluralFormIndex = localePluralForms.pluralForms.indexOf(pluralForm);
|
|
83
|
-
// In case of not enough plural form messages, we take the last one (other) instead of returning undefined
|
|
84
|
-
return parts[Math.min(pluralFormIndex, parts.length - 1)];
|
|
83
|
+
if (parts.length > localePluralForms.pluralForms.length) {
|
|
84
|
+
console.error(`For locale=${localePluralForms.locale}, a maximum of ${localePluralForms.pluralForms.length} plural forms are expected (${localePluralForms.pluralForms}), but the message contains ${parts.length} plural forms: ${pluralMessages} `);
|
|
85
85
|
}
|
|
86
|
+
const pluralForm = localePluralForms.select(count);
|
|
87
|
+
const pluralFormIndex = localePluralForms.pluralForms.indexOf(pluralForm);
|
|
88
|
+
// In case of not enough plural form messages, we take the last one (other)
|
|
89
|
+
// instead of returning undefined
|
|
90
|
+
return parts[Math.min(pluralFormIndex, parts.length - 1)];
|
|
86
91
|
}
|
|
87
92
|
export function usePluralForm() {
|
|
88
93
|
const localePluralForm = useLocalePluralForms();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePluralForm.js","sourceRoot":"","sources":["../../src/utils/usePluralForm.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAEpE,6DAA6D;AAC7D,mEAAmE;AACnE,qEAAqE;AACrE,MAAM,kBAAkB,GAA0B;IAChD,MAAM;IACN,KAAK;IACL,KAAK;IACL,KAAK;IACL,MAAM;IACN,OAAO;CACR,CAAC;AACF,SAAS,eAAe,CACtB,WAAkC;IAElC,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AACrE,CAAC;AAQD,4CAA4C;AAC5C,MAAM,kBAAkB,GAAsB;IAC5C,MAAM,EAAE,IAAI;IACZ,WAAW,EAAE,eAAe,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC;CACnD,CAAC;AAEF,SAAS,uBAAuB,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vO,CAAC;KACH;IACD,MAAM,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,eAAe,GAAG,iBAAiB,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC1E,2EAA2E;IAC3E,iCAAiC;IACjC,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,aAAa;IAG3B,MAAM,gBAAgB,GAAG,oBAAoB,EAAE,CAAC;IAChD,OAAO;QACL,aAAa,EAAE,CAAC,KAAa,EAAE,cAAsB,EAAU,EAAE,CAC/D,mBAAmB,CAAC,cAAc,EAAE,KAAK,EAAE,gBAAgB,CAAC;KAC/D,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTOCHighlight.d.ts","sourceRoot":"","sources":["../../src/utils/useTOCHighlight.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"useTOCHighlight.d.ts","sourceRoot":"","sources":["../../src/utils/useTOCHighlight.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgHH,oBAAY,kBAAkB,GAAG;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,iBAAS,eAAe,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,GAAG,IAAI,CAwDrE;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -10,7 +10,8 @@ import { useThemeConfig } from './useThemeConfig';
|
|
|
10
10
|
TODO make the hardcoded theme-classic classnames configurable
|
|
11
11
|
(or add them to ThemeClassNames?)
|
|
12
12
|
*/
|
|
13
|
-
// If the anchor has no height and is just a "marker" in the dom; we'll use the
|
|
13
|
+
// If the anchor has no height and is just a "marker" in the dom; we'll use the
|
|
14
|
+
// parent (normally the link text) rect boundaries instead
|
|
14
15
|
function getVisibleBoundingClientRect(element) {
|
|
15
16
|
const rect = element.getBoundingClientRect();
|
|
16
17
|
const hasNoHeight = rect.top === rect.bottom;
|
|
@@ -19,8 +20,10 @@ function getVisibleBoundingClientRect(element) {
|
|
|
19
20
|
}
|
|
20
21
|
return rect;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Considering we divide viewport into 2 zones of each 50vh, this returns true
|
|
25
|
+
* if an element is in the first zone (ie, appear in viewport, near the top)
|
|
26
|
+
*/
|
|
24
27
|
function isInViewportTopHalf(boundingRect) {
|
|
25
28
|
return boundingRect.top > 0 && boundingRect.bottom < window.innerHeight / 2;
|
|
26
29
|
}
|
|
@@ -33,32 +36,32 @@ function getAnchors({ minHeadingLevel, maxHeadingLevel, }) {
|
|
|
33
36
|
}
|
|
34
37
|
function getActiveAnchor(anchors, { anchorTopOffset, }) {
|
|
35
38
|
var _a;
|
|
36
|
-
// Naming is hard
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
+
// Naming is hard: The "nextVisibleAnchor" is the first anchor that appear
|
|
40
|
+
// under the viewport top boundary. It does not mean this anchor is visible
|
|
41
|
+
// yet, but if user continues scrolling down, it will be the first to become
|
|
42
|
+
// visible
|
|
39
43
|
const nextVisibleAnchor = anchors.find((anchor) => {
|
|
40
44
|
const boundingRect = getVisibleBoundingClientRect(anchor);
|
|
41
45
|
return boundingRect.top >= anchorTopOffset;
|
|
42
46
|
});
|
|
43
47
|
if (nextVisibleAnchor) {
|
|
44
48
|
const boundingRect = getVisibleBoundingClientRect(nextVisibleAnchor);
|
|
45
|
-
// If anchor is in the top half of the viewport: it is the one we consider
|
|
46
|
-
// (unless it's too close to the top and and soon to be scrolled
|
|
49
|
+
// If anchor is in the top half of the viewport: it is the one we consider
|
|
50
|
+
// "active" (unless it's too close to the top and and soon to be scrolled
|
|
51
|
+
// outside viewport)
|
|
47
52
|
if (isInViewportTopHalf(boundingRect)) {
|
|
48
53
|
return nextVisibleAnchor;
|
|
49
54
|
}
|
|
50
|
-
// If anchor is in the bottom half of the viewport, or under the viewport,
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
// If anchor is in the bottom half of the viewport, or under the viewport,
|
|
56
|
+
// we consider the active anchor is the previous one. This is because the
|
|
57
|
+
// main text appearing in the user screen mostly belong to the previous
|
|
58
|
+
// anchor. Returns null for the first anchor, see
|
|
59
|
+
// https://github.com/facebook/docusaurus/issues/5318
|
|
60
|
+
return (_a = anchors[anchors.indexOf(nextVisibleAnchor) - 1]) !== null && _a !== void 0 ? _a : null;
|
|
56
61
|
}
|
|
57
62
|
// no anchor under viewport top? (ie we are at the bottom of the page)
|
|
58
63
|
// => highlight the last anchor found
|
|
59
|
-
|
|
60
|
-
return anchors[anchors.length - 1];
|
|
61
|
-
}
|
|
64
|
+
return anchors[anchors.length - 1];
|
|
62
65
|
}
|
|
63
66
|
function getLinkAnchorValue(link) {
|
|
64
67
|
return decodeURIComponent(link.href.substring(link.href.indexOf('#') + 1));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTOCHighlight.js","sourceRoot":"","sources":["../../src/utils/useTOCHighlight.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AACxC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD;;;GAGG;AAEH,
|
|
1
|
+
{"version":3,"file":"useTOCHighlight.js","sourceRoot":"","sources":["../../src/utils/useTOCHighlight.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AACxC,OAAO,EAAC,cAAc,EAAC,MAAM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,EAAE,CAAC,YAAY,IAAI,YAAY,CAAC,EAAE,KAAK,kBAAkB,CAAC,IAAI,CAAC,CACvE,CAAC;YAEF,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBACrB,qBAAqB,CAAC,IAAI,EAAE,IAAI,KAAK,UAAU,CAAC,CAAC;YACnD,CAAC,CAAC,CAAC;QACL,CAAC;QAED,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QACtD,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QAEtD,gBAAgB,EAAE,CAAC;QAEnB,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;YACzD,QAAQ,CAAC,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QAC3D,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;AACnC,CAAC;AAED,eAAe,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-common",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4524",
|
|
4
4
|
"description": "Common code for Docusaurus themes.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/plugin-content-blog": "0.0.0-
|
|
22
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
23
|
-
"@docusaurus/plugin-content-pages": "0.0.0-
|
|
21
|
+
"@docusaurus/plugin-content-blog": "0.0.0-4524",
|
|
22
|
+
"@docusaurus/plugin-content-docs": "0.0.0-4524",
|
|
23
|
+
"@docusaurus/plugin-content-pages": "0.0.0-4524",
|
|
24
24
|
"clsx": "^1.1.1",
|
|
25
25
|
"parse-numeric-range": "^1.3.0",
|
|
26
26
|
"tslib": "^2.3.1",
|
|
27
27
|
"utility-types": "^3.10.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@docusaurus/core": "0.0.0-
|
|
31
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
32
|
-
"@docusaurus/types": "0.0.0-
|
|
30
|
+
"@docusaurus/core": "0.0.0-4524",
|
|
31
|
+
"@docusaurus/module-type-aliases": "0.0.0-4524",
|
|
32
|
+
"@docusaurus/types": "0.0.0-4524",
|
|
33
33
|
"@testing-library/react-hooks": "^7.0.2",
|
|
34
34
|
"fs-extra": "^10.0.0",
|
|
35
35
|
"lodash": "^4.17.20"
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=14"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "41a6bff3a67446f7d2a2972cbe4d05fec7378a15"
|
|
47
47
|
}
|
|
@@ -67,7 +67,8 @@ function applyCollapsedStyle(el: HTMLElement, collapsed: boolean) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/*
|
|
70
|
-
Lex111: Dynamic transition duration is used in Material design, this technique
|
|
70
|
+
Lex111: Dynamic transition duration is used in Material design, this technique
|
|
71
|
+
is good for a large number of items.
|
|
71
72
|
https://material.io/archive/guidelines/motion/duration-easing.html#duration-easing-dynamic-durations
|
|
72
73
|
https://github.com/mui-org/material-ui/blob/e724d98eba018e55e1a684236a2037e24bcf050c/packages/material-ui/src/styles/createTransitions.js#L40-L43
|
|
73
74
|
*/
|
|
@@ -151,7 +152,8 @@ type CollapsibleElementType = React.ElementType<
|
|
|
151
152
|
Pick<React.HTMLAttributes<unknown>, 'className' | 'onTransitionEnd' | 'style'>
|
|
152
153
|
>;
|
|
153
154
|
|
|
154
|
-
// Prevent hydration layout shift before animations are handled imperatively
|
|
155
|
+
// Prevent hydration layout shift before animations are handled imperatively
|
|
156
|
+
// with JS
|
|
155
157
|
function getSSRStyle(collapsed: boolean) {
|
|
156
158
|
if (ExecutionEnvironment.canUseDOM) {
|
|
157
159
|
return undefined;
|
|
@@ -167,8 +169,9 @@ type CollapsibleBaseProps = {
|
|
|
167
169
|
onCollapseTransitionEnd?: (collapsed: boolean) => void;
|
|
168
170
|
className?: string;
|
|
169
171
|
|
|
170
|
-
// This is mostly useful for details/summary component where ssrStyle is not
|
|
171
|
-
// and can mess
|
|
172
|
+
// This is mostly useful for details/summary component where ssrStyle is not
|
|
173
|
+
// needed (as details are hidden natively) and can mess up with the default
|
|
174
|
+
// native behavior of the browser when JS fails to load or is disabled
|
|
172
175
|
disableSSRStyle?: boolean;
|
|
173
176
|
};
|
|
174
177
|
|
|
@@ -189,7 +192,8 @@ function CollapsibleBase({
|
|
|
189
192
|
|
|
190
193
|
return (
|
|
191
194
|
<As
|
|
192
|
-
// @ts-expect-error: the "too complicated type" is produced from
|
|
195
|
+
// @ts-expect-error: the "too complicated type" is produced from
|
|
196
|
+
// "CollapsibleElementType" being a huge union
|
|
193
197
|
ref={collapsibleRef}
|
|
194
198
|
style={disableSSRStyle ? undefined : getSSRStyle(collapsed)}
|
|
195
199
|
onTransitionEnd={(e: React.TransitionEvent) => {
|
|
@@ -215,7 +219,7 @@ function CollapsibleLazy({collapsed, ...props}: CollapsibleBaseProps) {
|
|
|
215
219
|
}
|
|
216
220
|
}, [collapsed]);
|
|
217
221
|
|
|
218
|
-
// lazyCollapsed updated in effect so that
|
|
222
|
+
// lazyCollapsed updated in effect so that first expansion transition can work
|
|
219
223
|
const [lazyCollapsed, setLazyCollapsed] = useState(collapsed);
|
|
220
224
|
useLayoutEffect(() => {
|
|
221
225
|
if (mounted) {
|
|
@@ -229,9 +233,10 @@ function CollapsibleLazy({collapsed, ...props}: CollapsibleBaseProps) {
|
|
|
229
233
|
}
|
|
230
234
|
|
|
231
235
|
type CollapsibleProps = CollapsibleBaseProps & {
|
|
232
|
-
// Lazy allows to delay the rendering when collapsed => it will render
|
|
233
|
-
//
|
|
234
|
-
//
|
|
236
|
+
// Lazy allows to delay the rendering when collapsed => it will render
|
|
237
|
+
// children only after hydration, on first expansion
|
|
238
|
+
// Required prop: it forces to think if content should be server-rendered
|
|
239
|
+
// or not! This has perf impact on the SSR output and html file sizes
|
|
235
240
|
// See https://github.com/facebook/docusaurus/issues/4753
|
|
236
241
|
lazy: boolean;
|
|
237
242
|
};
|
|
@@ -41,7 +41,7 @@ function Details({summary, children, ...props}: DetailsProps): JSX.Element {
|
|
|
41
41
|
const {collapsed, setCollapsed} = useCollapsible({
|
|
42
42
|
initialState: !props.open,
|
|
43
43
|
});
|
|
44
|
-
//
|
|
44
|
+
// Use a separate prop because it must be set only after animation completes
|
|
45
45
|
// Otherwise close anim won't work
|
|
46
46
|
const [open, setOpen] = useState(props.open);
|
|
47
47
|
|
|
@@ -15,7 +15,8 @@ const windowSizes = {
|
|
|
15
15
|
|
|
16
16
|
// This "ssr" value is very important to handle hydration FOUC / layout shifts
|
|
17
17
|
// You have to handle server-rendering explicitly on the call-site
|
|
18
|
-
// On the server, you may need to render BOTH the mobile/desktop elements (and
|
|
18
|
+
// On the server, you may need to render BOTH the mobile/desktop elements (and
|
|
19
|
+
// hide one of them with mediaquery)
|
|
19
20
|
// We don't return "undefined" on purpose, to make it more explicit
|
|
20
21
|
ssr: 'ssr',
|
|
21
22
|
} as const;
|
|
@@ -33,7 +34,8 @@ function getWindowSize() {
|
|
|
33
34
|
: windowSizes.mobile;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
// Simulate the SSR window size in dev, so that potential hydration FOUC/layout
|
|
37
|
+
// Simulate the SSR window size in dev, so that potential hydration FOUC/layout
|
|
38
|
+
// shift problems can be seen in dev too!
|
|
37
39
|
const DevSimulateSSR = process.env.NODE_ENV === 'development' && true;
|
|
38
40
|
|
|
39
41
|
// This hook returns an enum value on purpose!
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
// These class names are used to style page layouts in Docusaurus
|
|
9
9
|
// Those are meant to be targeted by user-provided custom CSS selectors
|
|
10
|
-
//
|
|
10
|
+
// Please do not modify the classnames! This is a breaking change, and annoying
|
|
11
|
+
// for users!
|
|
11
12
|
export const ThemeClassNames = {
|
|
12
13
|
page: {
|
|
13
14
|
blogListPage: 'blog-list-page',
|
|
@@ -76,10 +76,9 @@ function readStorageState({
|
|
|
76
76
|
);
|
|
77
77
|
if (versionExists) {
|
|
78
78
|
return {preferredVersionName: preferredVersionNameUnsafe};
|
|
79
|
-
} else {
|
|
80
|
-
DocsPreferredVersionStorage.clear(pluginId, versionPersistence);
|
|
81
|
-
return {preferredVersionName: null};
|
|
82
79
|
}
|
|
80
|
+
DocsPreferredVersionStorage.clear(pluginId, versionPersistence);
|
|
81
|
+
return {preferredVersionName: null};
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
const initialState: DocsPreferredVersionState = {};
|
|
@@ -144,9 +143,8 @@ export function DocsPreferredVersionContextProvider({
|
|
|
144
143
|
{children}
|
|
145
144
|
</DocsPreferredVersionContextProviderUnsafe>
|
|
146
145
|
);
|
|
147
|
-
} else {
|
|
148
|
-
return children;
|
|
149
146
|
}
|
|
147
|
+
return children;
|
|
150
148
|
}
|
|
151
149
|
|
|
152
150
|
function DocsPreferredVersionContextProviderUnsafe({
|
package/src/utils/docsUtils.tsx
CHANGED
|
@@ -20,7 +20,7 @@ import {useLocation} from '@docusaurus/router';
|
|
|
20
20
|
// TODO not ideal, see also "useDocs"
|
|
21
21
|
export const isDocsPluginEnabled: boolean = !!useAllDocsData;
|
|
22
22
|
|
|
23
|
-
// Using a Symbol because null is a valid context value (a doc
|
|
23
|
+
// Using a Symbol because null is a valid context value (a doc with no sidebar)
|
|
24
24
|
// Inspired by https://github.com/jamiebuilds/unstated-next/blob/master/src/unstated-next.tsx
|
|
25
25
|
const EmptyContextValue: unique symbol = Symbol('EmptyContext');
|
|
26
26
|
|
|
@@ -101,11 +101,10 @@ export function findSidebarCategory(
|
|
|
101
101
|
if (item.type === 'category') {
|
|
102
102
|
if (predicate(item)) {
|
|
103
103
|
return item;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
104
|
+
}
|
|
105
|
+
const subItem = findSidebarCategory(item.items, predicate);
|
|
106
|
+
if (subItem) {
|
|
107
|
+
return subItem;
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
}
|
|
@@ -11,9 +11,10 @@ import type {Location, Action} from '@docusaurus/history';
|
|
|
11
11
|
|
|
12
12
|
type HistoryBlockHandler = (location: Location, action: Action) => void | false;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
Permits to register a handler that will be called on history actions (pop,
|
|
16
|
-
If the handler returns false, the navigation transition will
|
|
14
|
+
/**
|
|
15
|
+
* Permits to register a handler that will be called on history actions (pop,
|
|
16
|
+
* push, replace) If the handler returns false, the navigation transition will
|
|
17
|
+
* be blocked/cancelled
|
|
17
18
|
*/
|
|
18
19
|
export function useHistoryActionHandler(handler: HistoryBlockHandler): void {
|
|
19
20
|
const {block} = useHistory();
|
|
@@ -32,11 +33,11 @@ export function useHistoryActionHandler(handler: HistoryBlockHandler): void {
|
|
|
32
33
|
);
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
Permits to register a handler that will be called on history pop navigation
|
|
37
|
-
If the handler returns false, the backward/forward
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Permits to register a handler that will be called on history pop navigation
|
|
38
|
+
* (backward/forward) If the handler returns false, the backward/forward
|
|
39
|
+
* transition will be blocked. Unfortunately there's no good way to detect the
|
|
40
|
+
* "direction" (backward/forward) of the POP event.
|
|
40
41
|
*/
|
|
41
42
|
export function useHistoryPopHandler(handler: HistoryBlockHandler): void {
|
|
42
43
|
useHistoryActionHandler((location, action) => {
|
package/src/utils/jsUtils.ts
CHANGED
|
@@ -10,8 +10,11 @@
|
|
|
10
10
|
/**
|
|
11
11
|
* Gets the duplicate values in an array.
|
|
12
12
|
* @param arr The array.
|
|
13
|
-
* @param comparator Compares two values and returns `true` if they are equal
|
|
14
|
-
*
|
|
13
|
+
* @param comparator Compares two values and returns `true` if they are equal
|
|
14
|
+
* (duplicated).
|
|
15
|
+
* @returns Value of the elements `v` that have a preceding element `u` where
|
|
16
|
+
* `comparator(u, v) === true`. Values within the returned array are not
|
|
17
|
+
* guaranteed to be unique.
|
|
15
18
|
*/
|
|
16
19
|
export function duplicates<T>(
|
|
17
20
|
arr: readonly T[],
|
|
@@ -16,12 +16,13 @@ import React, {
|
|
|
16
16
|
} from 'react';
|
|
17
17
|
|
|
18
18
|
/*
|
|
19
|
-
The idea behind all this is that a specific component must be able to fill a
|
|
20
|
-
The doc page should be able to fill the
|
|
21
|
-
|
|
19
|
+
The idea behind all this is that a specific component must be able to fill a
|
|
20
|
+
placeholder in the generic layout. The doc page should be able to fill the
|
|
21
|
+
secondary menu of the main mobile navbar. This permits to reduce coupling
|
|
22
|
+
between the main layout and the specific page.
|
|
22
23
|
|
|
23
|
-
This kind of feature is often called portal/teleport/gateway... various
|
|
24
|
-
Most up-to-date one: https://github.com/gregberge/react-teleporter
|
|
24
|
+
This kind of feature is often called portal/teleport/gateway... various
|
|
25
|
+
unmaintained React libs exist. Most up-to-date one: https://github.com/gregberge/react-teleporter
|
|
25
26
|
Not sure any of those is safe regarding concurrent mode.
|
|
26
27
|
*/
|
|
27
28
|
|
package/src/utils/reactUtils.tsx
CHANGED
|
@@ -7,19 +7,27 @@
|
|
|
7
7
|
|
|
8
8
|
import {useCallback, useEffect, useLayoutEffect, useRef} from 'react';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/**
|
|
11
|
+
* This hook is like useLayoutEffect, but without the SSR warning
|
|
12
|
+
* It seems hacky but it's used in many React libs (Redux, Formik...)
|
|
13
|
+
* Also mentioned here: https://github.com/facebook/react/issues/16956
|
|
14
|
+
* It is useful when you need to update a ref as soon as possible after a React
|
|
15
|
+
* render (before `useEffect`)
|
|
16
|
+
*/
|
|
14
17
|
export const useIsomorphicLayoutEffect =
|
|
15
18
|
typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Permits to transform an unstable callback (like an arrow function provided as
|
|
22
|
+
* props) to a "stable" callback that is safe to use in a useEffect dependency
|
|
23
|
+
* array. Useful to avoid React stale closure problems + avoid useless effect
|
|
24
|
+
* re-executions
|
|
25
|
+
*
|
|
26
|
+
* Workaround until the React team recommends a good solution, see
|
|
27
|
+
* https://github.com/facebook/react/issues/16956
|
|
28
|
+
* This generally works but has some potential drawbacks, such as
|
|
29
|
+
* https://github.com/facebook/react/issues/16956#issuecomment-536636418
|
|
30
|
+
*/
|
|
23
31
|
export function useDynamicCallback<T extends (...args: never[]) => unknown>(
|
|
24
32
|
callback: T,
|
|
25
33
|
): T {
|
|
@@ -29,6 +37,7 @@ export function useDynamicCallback<T extends (...args: never[]) => unknown>(
|
|
|
29
37
|
ref.current = callback;
|
|
30
38
|
}, [callback]);
|
|
31
39
|
|
|
32
|
-
// @ts-expect-error: TS is right that this callback may be a supertype of T,
|
|
40
|
+
// @ts-expect-error: TS is right that this callback may be a supertype of T,
|
|
41
|
+
// but good enough for our use
|
|
33
42
|
return useCallback<T>((...args) => ref.current(...args), []);
|
|
34
43
|
}
|
package/src/utils/regexpUtils.ts
CHANGED
|
@@ -11,8 +11,8 @@ export type StorageType = typeof StorageTypes[number];
|
|
|
11
11
|
|
|
12
12
|
const DefaultStorageType: StorageType = 'localStorage';
|
|
13
13
|
|
|
14
|
-
// Will return null browser storage is unavailable (like running Docusaurus in
|
|
15
|
-
// See https://github.com/facebook/docusaurus/pull/4501
|
|
14
|
+
// Will return null browser storage is unavailable (like running Docusaurus in
|
|
15
|
+
// iframe) See https://github.com/facebook/docusaurus/pull/4501
|
|
16
16
|
function getBrowserStorage(
|
|
17
17
|
storageType: StorageType = DefaultStorageType,
|
|
18
18
|
): Storage | null {
|
|
@@ -23,13 +23,12 @@ function getBrowserStorage(
|
|
|
23
23
|
}
|
|
24
24
|
if (storageType === 'none') {
|
|
25
25
|
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
return window[storageType];
|
|
29
|
+
} catch (e) {
|
|
30
|
+
logOnceBrowserStorageNotAvailableWarning(e as Error);
|
|
31
|
+
return null;
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
|
|
@@ -79,10 +78,10 @@ Please only call storage APIs in effects and event handlers.`);
|
|
|
79
78
|
|
|
80
79
|
/**
|
|
81
80
|
* Creates an object for accessing a particular key in localStorage.
|
|
82
|
-
* The API is fail-safe, and usage of browser storage should be considered
|
|
83
|
-
* Local storage might simply be unavailable (iframe + browser
|
|
84
|
-
*
|
|
85
|
-
* See also https://github.com/facebook/docusaurus/issues/6036
|
|
81
|
+
* The API is fail-safe, and usage of browser storage should be considered
|
|
82
|
+
* unreliable. Local storage might simply be unavailable (iframe + browser
|
|
83
|
+
* security) or operations might fail individually. Please assume that using
|
|
84
|
+
* this API can be a NO-OP. See also https://github.com/facebook/docusaurus/issues/6036
|
|
86
85
|
*/
|
|
87
86
|
export const createStorageSlot = (
|
|
88
87
|
key: string,
|