@docusaurus/core 0.0.0-4821 → 0.0.0-4822

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.
@@ -5,48 +5,29 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React, { isValidElement } from 'react';
8
- /*
9
- Minimal implementation of a React interpolate component.
10
- We don't ship a markdown parser nor a feature-complete i18n library on purpose.
11
- More details here: https://github.com/facebook/docusaurus/pull/4295
12
- */
13
- const ValueFoundMarker = '{}'; // does not care much
14
8
  export function interpolate(text, values) {
15
- const elements = [];
16
- const processedText = text.replace(
17
9
  // eslint-disable-next-line prefer-named-capture-group
18
- /\{(\w+)\}/g, (match, key) => {
19
- const value = values?.[key];
20
- if (typeof value !== 'undefined') {
21
- const element = isValidElement(value)
22
- ? value
23
- : // For non-React elements: basic primitive->string conversion
24
- String(value);
25
- elements.push(element);
26
- return ValueFoundMarker;
10
+ const segments = text.split(/(\{\w+\})/).map((seg, index) => {
11
+ // Odd indices (1, 3, 5...) of the segments are (potentially) interpolatable
12
+ if (index % 2 === 1) {
13
+ const value = values?.[seg.slice(1, -1)];
14
+ if (value !== undefined) {
15
+ return value;
16
+ }
17
+ // No match: add warning? There's no way to "escape" interpolation though
27
18
  }
28
- return match; // no match? add warning?
19
+ return seg;
29
20
  });
30
- // No interpolation to be done: just return the text
31
- if (elements.length === 0) {
32
- return text;
21
+ if (segments.some((seg) => isValidElement(seg))) {
22
+ return segments
23
+ .map((seg, index) => isValidElement(seg) ? React.cloneElement(seg, { key: index }) : seg)
24
+ .filter((seg) => seg !== '');
33
25
  }
34
- // Basic string interpolation: returns interpolated string
35
- if (elements.every((el) => typeof el === 'string')) {
36
- return processedText
37
- .split(ValueFoundMarker)
38
- .reduce((str, value, index) => str.concat(value).concat(elements[index] ?? ''), '');
39
- }
40
- // JSX interpolation: returns ReactNode
41
- return processedText.split(ValueFoundMarker).map((value, index) => (<React.Fragment key={index}>
42
- {value}
43
- {elements[index]}
44
- </React.Fragment>));
26
+ return segments.join('');
45
27
  }
46
28
  export default function Interpolate({ children, values, }) {
47
29
  if (typeof children !== 'string') {
48
- console.warn('Illegal <Interpolate> children', children);
49
- throw new Error('The Docusaurus <Interpolate> component only accept simple string values');
30
+ throw new Error(`The Docusaurus <Interpolate> component only accept simple string values. Received: ${isValidElement(children) ? 'React element' : typeof children}`);
50
31
  }
51
32
  return <>{interpolate(children, values)}</>;
52
33
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docusaurus/core",
3
3
  "description": "Easy to Maintain Open Source Documentation Websites",
4
- "version": "0.0.0-4821",
4
+ "version": "0.0.0-4822",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -41,13 +41,13 @@
41
41
  "@babel/runtime": "^7.17.8",
42
42
  "@babel/runtime-corejs3": "^7.17.8",
43
43
  "@babel/traverse": "^7.17.3",
44
- "@docusaurus/cssnano-preset": "0.0.0-4821",
45
- "@docusaurus/logger": "0.0.0-4821",
46
- "@docusaurus/mdx-loader": "0.0.0-4821",
44
+ "@docusaurus/cssnano-preset": "0.0.0-4822",
45
+ "@docusaurus/logger": "0.0.0-4822",
46
+ "@docusaurus/mdx-loader": "0.0.0-4822",
47
47
  "@docusaurus/react-loadable": "5.5.2",
48
- "@docusaurus/utils": "0.0.0-4821",
49
- "@docusaurus/utils-common": "0.0.0-4821",
50
- "@docusaurus/utils-validation": "0.0.0-4821",
48
+ "@docusaurus/utils": "0.0.0-4822",
49
+ "@docusaurus/utils-common": "0.0.0-4822",
50
+ "@docusaurus/utils-validation": "0.0.0-4822",
51
51
  "@slorber/static-site-generator-webpack-plugin": "^4.0.4",
52
52
  "@svgr/webpack": "^6.2.1",
53
53
  "autoprefixer": "^10.4.4",
@@ -105,8 +105,8 @@
105
105
  "webpackbar": "^5.0.2"
106
106
  },
107
107
  "devDependencies": {
108
- "@docusaurus/module-type-aliases": "0.0.0-4821",
109
- "@docusaurus/types": "0.0.0-4821",
108
+ "@docusaurus/module-type-aliases": "0.0.0-4822",
109
+ "@docusaurus/types": "0.0.0-4822",
110
110
  "@types/detect-port": "^1.3.2",
111
111
  "@types/nprogress": "^0.2.0",
112
112
  "@types/react-dom": "^17.0.14",
@@ -127,5 +127,5 @@
127
127
  "engines": {
128
128
  "node": ">=14"
129
129
  },
130
- "gitHead": "8a074bee9e416464a8d8856cebbf346838d8ef6b"
130
+ "gitHead": "f5794fa6f34b17bd69e144e6e1c7c53f43552a93"
131
131
  }