Skip to content

Commit

Permalink
merging all conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
react-translations-bot committed Jan 8, 2024
2 parents 805b597 + 315cb7a commit 9eb9c77
Show file tree
Hide file tree
Showing 94 changed files with 1,155 additions and 952 deletions.
47 changes: 44 additions & 3 deletions plugins/remark-smartypants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*!
* Based on 'silvenon/remark-smartypants'
* https://github.com/silvenon/remark-smartypants/pull/80
*/

const visit = require('unist-util-visit');
const retext = require('retext');
const smartypants = require('retext-smartypants');
Expand All @@ -9,12 +14,48 @@ function check(parent) {
}

module.exports = function (options) {
const processor = retext().use(smartypants, options);
const processor = retext().use(smartypants, {
...options,
// Do not replace ellipses, dashes, backticks because they change string
// length, and we couldn't guarantee right splice of text in second visit of
// tree
ellipses: false,
dashes: false,
backticks: false,
});

const processor2 = retext().use(smartypants, {
...options,
// Do not replace quotes because they are already replaced in the first
// processor
quotes: false,
});

function transformer(tree) {
visit(tree, 'text', (node, index, parent) => {
if (check(parent)) node.value = String(processor.processSync(node.value));
let allText = '';
let startIndex = 0;
const textOrInlineCodeNodes = [];

visit(tree, ['text', 'inlineCode'], (node, _, parent) => {
if (check(parent)) {
if (node.type === 'text') allText += node.value;
// for the case when inlineCode contains just one part of quote: `foo'bar`
else allText += 'A'.repeat(node.value.length);
textOrInlineCodeNodes.push(node);
}
});

// Concat all text into one string, to properly replace quotes around non-"text" nodes
allText = String(processor.processSync(allText));

for (const node of textOrInlineCodeNodes) {
const endIndex = startIndex + node.value.length;
if (node.type === 'text') {
const processedText = allText.slice(startIndex, endIndex);
node.value = String(processor2.processSync(processedText));
}
startIndex = endIndex;
}
}

return transformer;
Expand Down
14 changes: 11 additions & 3 deletions src/components/Layout/HomeContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ function ConferenceLayout({conf, children}) {
navigate(e.target.value);
});
}}
className="appearance-none pe-8 bg-transparent text-primary-dark text-2xl font-bold mb-0.5"
className="appearance-none pe-8 ps-2 bg-transparent text-primary-dark text-2xl font-bold mb-0.5"
style={{
backgroundSize: '4px 4px, 4px 4px',
backgroundRepeat: 'no-repeat',
Expand All @@ -1508,8 +1508,16 @@ function ConferenceLayout({conf, children}) {
backgroundImage:
'linear-gradient(45deg,transparent 50%,currentColor 50%),linear-gradient(135deg,currentColor 50%,transparent 50%)',
}}>
<option value="react-conf-2021">React Conf 2021</option>
<option value="react-conf-2019">React Conf 2019</option>
<option
className="bg-wash dark:bg-wash-dark text-primary dark:text-primary-dark"
value="react-conf-2021">
React Conf 2021
</option>
<option
className="bg-wash dark:bg-wash-dark text-primary dark:text-primary-dark"
value="react-conf-2019">
React Conf 2019
</option>
</select>
</Cover>
<div className="px-4 pb-4" key={conf.id}>
Expand Down
7 changes: 3 additions & 4 deletions src/components/MDX/Sandpack/DownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import {useSyncExternalStore} from 'react';
import {useSandpack} from '@codesandbox/sandpack-react/unstyled';
import {IconDownload} from '../../Icon/IconDownload';
import {AppJSPath, StylesCSSPath, SUPPORTED_FILES} from './createFileMap';
export interface DownloadButtonProps {}

let supportsImportMap = false;
Expand Down Expand Up @@ -32,8 +33,6 @@ function useSupportsImportMap() {
return useSyncExternalStore(subscribe, getCurrentValue, getServerSnapshot);
}

const SUPPORTED_FILES = ['/App.js', '/styles.css'];

export function DownloadButton({
providedFiles,
}: {
Expand All @@ -49,8 +48,8 @@ export function DownloadButton({
}

const downloadHTML = () => {
const css = sandpack.files['/styles.css']?.code ?? '';
const code = sandpack.files['/App.js']?.code ?? '';
const css = sandpack.files[StylesCSSPath]?.code ?? '';
const code = sandpack.files[AppJSPath]?.code ?? '';
const blob = new Blob([
`<!DOCTYPE html>
<html>
Expand Down
2 changes: 1 addition & 1 deletion src/components/MDX/Sandpack/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function Preview({

// When throwing a new Error in Sandpack - we want to disable the dev error dialog
// to show the Error Boundary fallback
if (rawError && rawError.message.includes(`throw Error('Example error')`)) {
if (rawError && rawError.message.includes('Example Error:')) {
rawError = null;
}

Expand Down
13 changes: 8 additions & 5 deletions src/components/MDX/Sandpack/SandpackRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {SandpackLogLevel} from '@codesandbox/sandpack-client';
import {CustomPreset} from './CustomPreset';
import {createFileMap} from './createFileMap';
import {CustomTheme} from './Themes';
import {template} from './template';

type SandpackProps = {
children: React.ReactNode;
Expand Down Expand Up @@ -70,17 +71,19 @@ function SandpackRoot(props: SandpackProps) {
const codeSnippets = Children.toArray(children) as React.ReactElement[];
const files = createFileMap(codeSnippets);

files['/styles.css'] = {
code: [sandboxStyle, files['/styles.css']?.code ?? ''].join('\n\n'),
hidden: !files['/styles.css']?.visible,
files['/src/styles.css'] = {
code: [sandboxStyle, files['/src/styles.css']?.code ?? ''].join('\n\n'),
hidden: !files['/src/styles.css']?.visible,
};

return (
<div className="sandpack sandpack--playground w-full my-8" dir="ltr">
<SandpackProvider
template="react"
files={files}
files={{...template, ...files}}
theme={CustomTheme}
customSetup={{
environment: 'create-react-app',
}}
options={{
autorun,
initMode: 'user-visible',
Expand Down
9 changes: 7 additions & 2 deletions src/components/MDX/Sandpack/createFileMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

import type {SandpackFile} from '@codesandbox/sandpack-react/unstyled';

export const AppJSPath = `/src/App.js`;
export const StylesCSSPath = `/src/styles.css`;
export const SUPPORTED_FILES = [AppJSPath, StylesCSSPath];

export const createFileMap = (codeSnippets: any) => {
return codeSnippets.reduce(
(result: Record<string, SandpackFile>, codeSnippet: React.ReactElement) => {
Expand All @@ -26,15 +30,16 @@ export const createFileMap = (codeSnippets: any) => {
}
} else {
if (props.className === 'language-js') {
filePath = '/App.js';
filePath = AppJSPath;
} else if (props.className === 'language-css') {
filePath = '/styles.css';
filePath = StylesCSSPath;
} else {
throw new Error(
`Code block is missing a filename: ${props.children}`
);
}
}

if (result[filePath]) {
throw new Error(
`File ${filePath} was defined multiple times. Each file snippet should have a unique path name`
Expand Down
4 changes: 2 additions & 2 deletions src/components/MDX/Sandpack/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import {lazy, memo, Children, Suspense} from 'react';
import {createFileMap} from './createFileMap';
import {AppJSPath, createFileMap} from './createFileMap';

const SandpackRoot = lazy(() => import('./SandpackRoot'));

Expand Down Expand Up @@ -57,7 +57,7 @@ export default memo(function SandpackWrapper(props: any): any {
);
let activeCode;
if (!activeCodeSnippet.length) {
activeCode = codeSnippet['/App.js'].code;
activeCode = codeSnippet[AppJSPath].code;
} else {
activeCode = codeSnippet[activeCodeSnippet[0]].code;
}
Expand Down
54 changes: 54 additions & 0 deletions src/components/MDX/Sandpack/template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
export const template = {
'/src/index.js': {
hidden: true,
code: `import React, { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import "./styles.css";
import App from "./App";
const root = createRoot(document.getElementById("root"));
root.render(
<StrictMode>
<App />
</StrictMode>
);`,
},
'/package.json': {
hidden: true,
code: JSON.stringify(
{
name: 'react.dev',
version: '0.0.0',
main: '/src/index.js',
scripts: {
start: 'react-scripts start',
build: 'react-scripts build',
test: 'react-scripts test --env=jsdom',
eject: 'react-scripts eject',
},
dependencies: {
react: '^18.0.0',
'react-dom': '^18.0.0',
'react-scripts': '^5.0.0',
},
},
null,
2
),
},
'/public/index.html': {
hidden: true,
code: `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="root"></div>
</body>
</html>`,
},
};
1 change: 1 addition & 0 deletions src/components/Seo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const deployedTranslations = [
'es',
'fr',
'ja',
'tr',
// We'll add more languages when they have enough content.
// Please DO NOT edit this list without a discussion in the reactjs/react.dev repo.
// It must be the same between all translations.
Expand Down
7 changes: 3 additions & 4 deletions src/content/blog/2023/03/16/introducing-react-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ If you like to learn by doing, we recommend checking out the [Tic-Tac-Toe Tutori

<Sandpack>

```js App.js
```js src/App.js
import { useState } from 'react';

function Square({ value, onSquareClick }) {
Expand Down Expand Up @@ -175,7 +175,7 @@ function calculateWinner(squares) {
}
```

```css styles.css
```css src/styles.css
* {
box-sizing: border-box;
}
Expand Down Expand Up @@ -428,7 +428,7 @@ export default function PackingList() {

Note that you must write `importance > 0 && ...` rather than `importance && ...` so that if the `importance` is `0`, `0` isn't rendered as the result!

In this solution, two separate conditions are used to insert a space between then name and the importance label. Alternatively, you could use a fragment with a leading space: `importance > 0 && <> <i>...</i></>` or add a space immediately inside the `<i>`: `importance > 0 && <i> ...</i>`.
In this solution, two separate conditions are used to insert a space between then name and the importance label. Alternatively, you could use a Fragment with a leading space: `importance > 0 && <> <i>...</i></>` or add a space immediately inside the `<i>`: `importance > 0 && <i> ...</i>`.

</Solution>

Expand Down Expand Up @@ -643,4 +643,3 @@ On the development front, thanks to [Jared Palmer](https://twitter.com/jaredpalm
Huge thanks to the folks who volunteered their time to participate in the alpha and beta testing program. Your enthusiasm and invaluable feedback helped us shape these docs. A special shout out to our beta tester, [Debbie O'Brien](https://twitter.com/debs_obrien), who gave a talk about her experience using the React docs at React Conf 2021.

Finally, thanks to the React community for being the inspiration behind this effort. You are the reason we do this, and we hope that the new docs will help you use React to build any user interface that you want.

Loading

0 comments on commit 9eb9c77

Please sign in to comment.