diff --git a/docs/playground/index.md b/docs/playground/index.md index 149bc48b7..66ab04f5f 100644 --- a/docs/playground/index.md +++ b/docs/playground/index.md @@ -8,4 +8,4 @@ custom_edit_url: null import Playground from '@site/src/components/Playground/index'; import version from '../pixi-version.json'; - \ No newline at end of file + \ No newline at end of file diff --git a/docs/tutorials/getting-started.md b/docs/tutorials/getting-started.md deleted file mode 100644 index 8c14b2f21..000000000 --- a/docs/tutorials/getting-started.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -hide_title: true -pagination_next: null -pagination_prev: null -custom_edit_url: null ---- - -import Tutorial from '@site/src/components/tutorial/index'; -import version from '../pixi-version.json'; - - diff --git a/scripts/generate-example-docs.js b/scripts/generate-example-docs.js index 8b48a64f2..8c864fa54 100755 --- a/scripts/generate-example-docs.js +++ b/scripts/generate-example-docs.js @@ -110,7 +110,7 @@ async function go() '', `# ${exampleTitle}`, '', - ``, + ``, '', ].join('\n'); diff --git a/scripts/generate-tutorial-docs.js b/scripts/generate-tutorial-docs.js index dc50a8fd6..f09b2cf3c 100755 --- a/scripts/generate-tutorial-docs.js +++ b/scripts/generate-tutorial-docs.js @@ -70,7 +70,7 @@ async function go() 'import Tutorial from \'@site/src/components/tutorial/index\';', 'import version from \'../pixi-version.json\';', '', - ``, + ``, '', ].join('\n'); diff --git a/src/components/Example/index.tsx b/src/components/Example/index.tsx index 6bb5ff9be..26216af38 100644 --- a/src/components/Example/index.tsx +++ b/src/components/Example/index.tsx @@ -3,11 +3,11 @@ import type { IVersion } from '@site/src/components/Playground/PixiPlayground/us import styles from './index.module.scss'; import BrowserOnly from '@docusaurus/BrowserOnly'; -import { getExampleEntry } from '@site/src/examples/v7.3.2'; +import { getExampleEntry } from '@site/src/examples'; -export default function Example({ id, version }: { id: string; version: IVersion }) +export default function Example({ id, pixiVersion }: { id: string; pixiVersion: IVersion }) { - const entry = getExampleEntry(id); + const entry = getExampleEntry(pixiVersion.version, id); const source = (entry?.source ?? entry) as string; return ( @@ -16,8 +16,8 @@ export default function Example({ id, version }: { id: string; version: IVersion {() => ( diff --git a/src/components/Playground/PixiPlayground/useEditorCode.ts b/src/components/Playground/PixiPlayground/useEditorCode.ts index d4d4cd056..af9b2dc57 100644 --- a/src/components/Playground/PixiPlayground/useEditorCode.ts +++ b/src/components/Playground/PixiPlayground/useEditorCode.ts @@ -1,25 +1,28 @@ import { useCallback, useMemo } from 'react'; -import type { ExampleSourceEntry } from '@site/src/examples/v7.3.2'; -import { getExampleOptions, getExampleEntry } from '@site/src/examples/v7.3.2'; import type { OptionGroup } from '@site/src/components/Select'; import type { SetURLStateType } from '@site/src/components/Playground/PixiPlayground/usePlaygroundURLState'; +import type { ExampleSourceEntry } from '@site/src/examples'; +import { getExampleEntry, getExampleOptions } from '@site/src/examples'; +import type { IVersion } from './usePixiVersions'; export const defaultExampleId = 'sprite.basic'; -const defaultExampleOptions = getExampleOptions(); type UseCodeExamplesParams = { urlSourceCode: string | undefined; selectedOptionId: string; setURLState: SetURLStateType; + pixiVersion: IVersion; }; -export const useCodeExamples = ({ urlSourceCode, selectedOptionId, setURLState }: UseCodeExamplesParams) => +export const useCodeExamples = ({ urlSourceCode, selectedOptionId, setURLState, pixiVersion }: UseCodeExamplesParams) => { + const version = pixiVersion.version; + const defaultExampleOptions = getExampleOptions(version); const hasUrlHashedCode = Boolean(urlSourceCode); const exampleEntry = useMemo( - () => getExampleEntry(selectedOptionId), - [selectedOptionId], + () => getExampleEntry(version, selectedOptionId), + [version, selectedOptionId], ); const { source: sourceCode, usesWebWorkerLibrary } = useMemo>( () => @@ -50,7 +53,7 @@ export const useCodeExamples = ({ urlSourceCode, selectedOptionId, setURLState } }, ], })), - [hasUrlHashedCode], + [defaultExampleOptions, hasUrlHashedCode], ); const handleOptionSelected = useCallback( diff --git a/src/components/Playground/PixiPlayground/useSandpackConfiguration.ts b/src/components/Playground/PixiPlayground/useSandpackConfiguration.ts index 7836cead5..4e8e7ecd7 100644 --- a/src/components/Playground/PixiPlayground/useSandpackConfiguration.ts +++ b/src/components/Playground/PixiPlayground/useSandpackConfiguration.ts @@ -65,6 +65,8 @@ type UseDependenciesParams = { pixiVersion: string; }; +const isPreV8 = (pixiVersion: string) => Number(pixiVersion.split('.')[0]) < 8; + const useDependencies = ({ isPixiWebWorkerVersion, isPixiDevVersion, pixiVersion }: UseDependenciesParams) => useMemo(() => { @@ -74,7 +76,7 @@ const useDependencies = ({ isPixiWebWorkerVersion, isPixiDevVersion, pixiVersion const packages = [pixiPackageName]; // Add these packages if we're using a version of pixi that doesn't have them built in, ie. < v8 - if (Number(pixiVersion.split('.')[0]) < 8) + if (isPreV8(pixiVersion)) { packages.push('@pixi/graphics-extras', '@pixi/math-extras'); } @@ -112,15 +114,22 @@ export const useSandpackConfiguration = ({ // could flip between examples easily, investigate why it bugs out during editing const key = `${dependenciesKey}-${code}`; - const customSetup = { + let customSetup: Record = { entry: 'index.html', dependencies, - devDependencies: { - '@babel/core': '^7.21.3', - 'parcel-bundler': '^1.6.1', - }, }; + if (isPreV8(pixiVersion)) + { + customSetup = { + ...customSetup, + devDependencies: { + '@babel/core': '^7.21.3', + 'parcel-bundler': '^1.6.1', + }, + }; + } + return { files, key, diff --git a/src/components/Playground/index.tsx b/src/components/Playground/index.tsx index 1c712fe70..d132271a6 100644 --- a/src/components/Playground/index.tsx +++ b/src/components/Playground/index.tsx @@ -7,11 +7,11 @@ import { usePlaygroundURLState } from '@site/src/components/Playground/PixiPlayg import styles from './index.module.scss'; import BrowserOnly from '@docusaurus/BrowserOnly'; -export default function Playground({ version }: { version: IVersion }) +export default function Playground({ pixiVersion }: { pixiVersion: IVersion }) { const [urlState, setURLState] = usePlaygroundURLState({ defaultExampleId, - defaultPixiVersion: version.version, + defaultPixiVersion: pixiVersion.version, }); const { source: urlSourceCode, exampleId: selectedOptionId } = urlState; @@ -20,6 +20,7 @@ export default function Playground({ version }: { version: IVersion }) urlSourceCode, selectedOptionId, setURLState, + pixiVersion, }); return ( @@ -38,8 +39,8 @@ export default function Playground({ version }: { version: IVersion }) ); } -export default function Tutorial({ id, version }: { id: string; version: IVersion }): JSX.Element +export default function Tutorial({ id, pixiVersion }: { id: string; pixiVersion: IVersion }): JSX.Element { + const version = pixiVersion.version; const [showEditor, setShowEditor] = useState(false); const handleEditorToggle = (): void => { setShowEditor(!showEditor); }; - const entry = getTutorialEntry(id); + const entry = getTutorialEntry(version, id); return (
@@ -87,7 +89,7 @@ export default function Tutorial({ id, version }: { id: string; version: IVersio {showEditor ? '< To Instructions' : 'To Editor >'} LOADING...}> - {() => } + {() => }
); diff --git a/src/examples/index.ts b/src/examples/index.ts new file mode 100644 index 000000000..ca4f2e393 --- /dev/null +++ b/src/examples/index.ts @@ -0,0 +1,40 @@ +import type { OptionGroup } from '../components/Select'; +import v7x from './v7.3.2/index'; +import v8x from './v8.0.0-rc/index'; + +export type ExampleDataEntry = { + name: string; + hide?: boolean; + usesWebWorkerLibrary?: boolean; +}; +export type ExampleSourceEntry = { + source: string; + hide: boolean; + usesWebWorkerLibrary: boolean; +}; + +// json data structure +export type ExamplesJsonType = Record; +// sourcecode dictionary structure for below +export type ExamplesSourceType = Record>; +// normalized combination of the above +export type CategoryDataType = Record; +export type ExamplesDataType = Record; + +// TODO: Use await import to dynamically load versioned content on demand instead? +const versions: Record = { + '7.3.2': v7x, + '8.0.0-rc': v8x, +}; + +export function getExampleEntry(version: string, pathString: string): ExampleSourceEntry | undefined +{ + const [directory, example] = pathString.split('.'); + + return versions[version]?.entries[directory]?.[example]; +} + +export function getExampleOptions(version: string): OptionGroup[] +{ + return versions[version]?.options; +} diff --git a/src/examples/v7.3.2/index.ts b/src/examples/v7.3.2/index.ts index 7588e51dc..e950e4884 100644 --- a/src/examples/v7.3.2/index.ts +++ b/src/examples/v7.3.2/index.ts @@ -83,30 +83,13 @@ import gradientResource from '!!raw-loader!./textures/gradientResource.js'; import renderTextureAdvanced from '!!raw-loader!./textures/renderTextureAdvanced.js'; import renderTextureBasic from '!!raw-loader!./textures/renderTextureBasic.js'; import textureRotate from '!!raw-loader!./textures/textureRotate.js'; -import type { Option, OptionGroup } from '@site/src/components/Select'; +import type { Option } from '@site/src/components/Select'; // Defines order of examples in documentation and playground dropdown, it's defined // separately here so it can be used in runtime code and in the md generation script import examplesData from './examplesData.json'; import { camelCaseToSentenceCase } from '@site/src/utils/utils'; - -export type ExampleDataEntry = { - name: string; - hide?: boolean; - usesWebWorkerLibrary?: boolean; -}; -export type ExampleSourceEntry = { - source: string; - hide: boolean; - usesWebWorkerLibrary: boolean; -}; -// json data structure -export type ExamplesJsonType = Record; -// sourcecode dictionary structure for below -export type ExamplesSourceType = Record>; -// normalized combination of the above -export type CategoryDataType = Record; -export type ExamplesDataType = Record; +import type { CategoryDataType, ExampleDataEntry, ExamplesDataType, ExamplesJsonType, ExamplesSourceType } from '..'; const examplesSource: ExamplesSourceType = { basic: { @@ -231,7 +214,7 @@ const normalizeExampleDataEntry = (categoryExample: ExampleDataEntry | string): }; }; -const normalizedExamplesData = Object.entries(examplesData as ExamplesJsonType).reduce( +const entries = Object.entries(examplesData as ExamplesJsonType).reduce( (directoryAcc, [categoryKey, categoryExamples]) => ({ ...directoryAcc, [categoryKey]: categoryExamples.reduce((categoryAcc, categoryExampleOrString) => @@ -252,35 +235,27 @@ const normalizedExamplesData = Object.entries(examplesData as ExamplesJsonType). {} as ExamplesDataType, ); -export function getExampleEntry(pathString: string): ExampleSourceEntry | undefined -{ - const [directory, example] = pathString.split('.'); - - return normalizedExamplesData[directory]?.[example]; -} - -export function getExampleOptions(): OptionGroup[] +const options = Object.entries(examplesData as ExamplesJsonType).map(([folderKey, folderEntries]) => { - return Object.entries(examplesData as ExamplesJsonType).map(([folderKey, folderEntries]) => + const options = folderEntries.reduce((acc, exampleDataEntry) => { - const options = folderEntries.reduce((acc, exampleDataEntry) => + const { name: exampleKey, hide } = normalizeExampleDataEntry(exampleDataEntry); + + if (hide) { - const { name: exampleKey, hide } = normalizeExampleDataEntry(exampleDataEntry); + return acc; + } - if (hide) - { - return acc; - } + return acc.concat({ + value: `${folderKey}.${exampleKey}`, + label: camelCaseToSentenceCase(exampleKey), + }); + }, [] as Option[]); - return acc.concat({ - value: `${folderKey}.${exampleKey}`, - label: camelCaseToSentenceCase(exampleKey), - }); - }, [] as Option[]); + return { + label: camelCaseToSentenceCase(folderKey), + options, + }; +}); - return { - label: camelCaseToSentenceCase(folderKey), - options, - }; - }); -} +export default { entries, options }; diff --git a/src/examples/v8.0.0-rc/index.ts b/src/examples/v8.0.0-rc/index.ts index 7588e51dc..e950e4884 100644 --- a/src/examples/v8.0.0-rc/index.ts +++ b/src/examples/v8.0.0-rc/index.ts @@ -83,30 +83,13 @@ import gradientResource from '!!raw-loader!./textures/gradientResource.js'; import renderTextureAdvanced from '!!raw-loader!./textures/renderTextureAdvanced.js'; import renderTextureBasic from '!!raw-loader!./textures/renderTextureBasic.js'; import textureRotate from '!!raw-loader!./textures/textureRotate.js'; -import type { Option, OptionGroup } from '@site/src/components/Select'; +import type { Option } from '@site/src/components/Select'; // Defines order of examples in documentation and playground dropdown, it's defined // separately here so it can be used in runtime code and in the md generation script import examplesData from './examplesData.json'; import { camelCaseToSentenceCase } from '@site/src/utils/utils'; - -export type ExampleDataEntry = { - name: string; - hide?: boolean; - usesWebWorkerLibrary?: boolean; -}; -export type ExampleSourceEntry = { - source: string; - hide: boolean; - usesWebWorkerLibrary: boolean; -}; -// json data structure -export type ExamplesJsonType = Record; -// sourcecode dictionary structure for below -export type ExamplesSourceType = Record>; -// normalized combination of the above -export type CategoryDataType = Record; -export type ExamplesDataType = Record; +import type { CategoryDataType, ExampleDataEntry, ExamplesDataType, ExamplesJsonType, ExamplesSourceType } from '..'; const examplesSource: ExamplesSourceType = { basic: { @@ -231,7 +214,7 @@ const normalizeExampleDataEntry = (categoryExample: ExampleDataEntry | string): }; }; -const normalizedExamplesData = Object.entries(examplesData as ExamplesJsonType).reduce( +const entries = Object.entries(examplesData as ExamplesJsonType).reduce( (directoryAcc, [categoryKey, categoryExamples]) => ({ ...directoryAcc, [categoryKey]: categoryExamples.reduce((categoryAcc, categoryExampleOrString) => @@ -252,35 +235,27 @@ const normalizedExamplesData = Object.entries(examplesData as ExamplesJsonType). {} as ExamplesDataType, ); -export function getExampleEntry(pathString: string): ExampleSourceEntry | undefined -{ - const [directory, example] = pathString.split('.'); - - return normalizedExamplesData[directory]?.[example]; -} - -export function getExampleOptions(): OptionGroup[] +const options = Object.entries(examplesData as ExamplesJsonType).map(([folderKey, folderEntries]) => { - return Object.entries(examplesData as ExamplesJsonType).map(([folderKey, folderEntries]) => + const options = folderEntries.reduce((acc, exampleDataEntry) => { - const options = folderEntries.reduce((acc, exampleDataEntry) => + const { name: exampleKey, hide } = normalizeExampleDataEntry(exampleDataEntry); + + if (hide) { - const { name: exampleKey, hide } = normalizeExampleDataEntry(exampleDataEntry); + return acc; + } - if (hide) - { - return acc; - } + return acc.concat({ + value: `${folderKey}.${exampleKey}`, + label: camelCaseToSentenceCase(exampleKey), + }); + }, [] as Option[]); - return acc.concat({ - value: `${folderKey}.${exampleKey}`, - label: camelCaseToSentenceCase(exampleKey), - }); - }, [] as Option[]); + return { + label: camelCaseToSentenceCase(folderKey), + options, + }; +}); - return { - label: camelCaseToSentenceCase(folderKey), - options, - }; - }); -} +export default { entries, options }; diff --git a/src/tutorials/index.ts b/src/tutorials/index.ts new file mode 100644 index 000000000..88dd5b4fe --- /dev/null +++ b/src/tutorials/index.ts @@ -0,0 +1,26 @@ +import v7x from './v7.3.2/index'; +import v8x from './v8.0.0-rc/index'; + +export type TutorialStep = { + header: string; + Content: string; + code: string; + completedCode?: string; +}; + +export type TutorialEntry = { + description: string; + thumbnail?: string; + steps: TutorialStep[]; +}; + +// TODO: Use await import to dynamically load versioned content on demand instead? +const versions: Record> = { + '7.3.2': v7x, + '8.0.0-rc': v8x, +}; + +export function getTutorialEntry(version: string, key: string) +{ + return versions[version]?.[key]; +} diff --git a/src/tutorials/v7.3.2/index.ts b/src/tutorials/v7.3.2/index.ts index 30959e667..78bf74949 100644 --- a/src/tutorials/v7.3.2/index.ts +++ b/src/tutorials/v7.3.2/index.ts @@ -1,26 +1,8 @@ import { gettingStartedTutorialSteps } from './gettingStarted'; -export type TutorialStep = { - header: string; - Content: string; - code: string; - completedCode?: string; -}; - -export type TutorialEntry = { - description: string; - thumbnail?: string; - steps: TutorialStep[]; -}; - -const tutorialsData: Record = { +export default { gettingStarted: { description: 'Learn the basics of how to use PixiJS.', steps: gettingStartedTutorialSteps, }, }; - -export function getTutorialEntry(key: string) -{ - return tutorialsData[key]; -} diff --git a/src/tutorials/v8.0.0-rc/index.ts b/src/tutorials/v8.0.0-rc/index.ts index 30959e667..78bf74949 100644 --- a/src/tutorials/v8.0.0-rc/index.ts +++ b/src/tutorials/v8.0.0-rc/index.ts @@ -1,26 +1,8 @@ import { gettingStartedTutorialSteps } from './gettingStarted'; -export type TutorialStep = { - header: string; - Content: string; - code: string; - completedCode?: string; -}; - -export type TutorialEntry = { - description: string; - thumbnail?: string; - steps: TutorialStep[]; -}; - -const tutorialsData: Record = { +export default { gettingStarted: { description: 'Learn the basics of how to use PixiJS.', steps: gettingStartedTutorialSteps, }, }; - -export function getTutorialEntry(key: string) -{ - return tutorialsData[key]; -} diff --git a/versioned_docs/version-7.3.2/playground/index.md b/versioned_docs/version-7.3.2/playground/index.md index 149bc48b7..66ab04f5f 100644 --- a/versioned_docs/version-7.3.2/playground/index.md +++ b/versioned_docs/version-7.3.2/playground/index.md @@ -8,4 +8,4 @@ custom_edit_url: null import Playground from '@site/src/components/Playground/index'; import version from '../pixi-version.json'; - \ No newline at end of file + \ No newline at end of file