3.0.0-alpha.15 • Published 4 months ago
@yozora/react-code-runners v3.0.0-alpha.15
This package is designed to provide code runners for @yozora/react-code-embed or @yozora/react-code-live.
Install
npm
npm install --save @yozora/react-code-runners
yarn
yarn add @yozora/react-code-runners
Usage
Create a GraphvizRunner.
import loadable from '@loadable/component' import type { CodeRunner } from '@yozora/react-code-runners' import { createGraphvizRunner } from '@yozora/react-code-runners' const GraphvizRenderer = loadable( () => import('@yozora/react-code-renderer-graphviz'), ) export const GraphvizRunner: CodeRunner = createGraphvizRunner(GraphvizRenderer)
Create a JsxRunner.
import styled from '@emotion/styled' import loadable from '@loadable/component' import type { EcmaImport } from '@yozora/ast' import type { ICodeRendererJsxProps } from '@yozora/react-code-renderer-jsx' import type { ICodeRunner } from '@yozora/react-code-runners' import { createUseJsxRunner } from '@yozora/react-code-runners' import { useCallback, useEffect, useMemo, useState } from 'react' const JsxRenderer = loadable<ICodeRendererJsxProps>( () => import('@yozora/react-code-renderer-jsx') as any, ) export const useJsxRunner: (ecmaImports: EcmaImport[]) => ICodeRunner = createUseJsxRunner( { styled, useCallback, useEffect, useMemo, useState, }, [], JsxRenderer, 'block', ) function Demo() { const JsxRunner = useJsxRunner([]) // .... }
Create a MathRunner.
import type { ICodeRunner } from '@yozora/react-code-runners' import { createMathRunner } from '@yozora/react-code-runners' import { MathJaxNode } from '@yozora/react-mathjax' export const MathRunner: ICodeRunner = createMathRunner( props => <MathJaxNode className="yozora-math" inline={false} formula={props.value} /> )
Create runner items.
import type { EcmaImport } from '@yozora/ast' import type { ICodeRunnerItem } from '@yozora/react-code-runners' import React from 'react' import GraphvizRunner from './runner-graphviz' import { useJsxRunner } from './runner-jsx' import MathRunner from './runner-math' export function useCodeRunners(ecmaImports: EcmaImport[]): ICodeRunnerItem[] { const JsxRunner = useJsxRunner(ecmaImports) return React.useMemo( () => [ { title: 'jsx', pattern: /^jsx$/, runner: JsxRunner, }, { title: 'graphviz', pattern: /^graphviz|dot$/, runner: GraphvizRunner, }, { title: 'math', pattern: /^tex|latex|math|mathjax$/, runner: MathRunner, }, ], [JsxRunner], ) }
Overview
Name | Description |
---|---|
createUseJsxRunner | Create a jsx live code runner creator. |
createGraphvizRunner | Create a graphviz live code runner. |
createMathRunner | Create a formula live code runner. |
Related
3.0.0-alpha.15
4 months ago
3.0.0-alpha.14
4 months ago
3.0.0-alpha.13
8 months ago
3.0.0-alpha.12
9 months ago
3.0.0-alpha.11
1 year ago
3.0.0-alpha.7
2 years ago
3.0.0-alpha.6
2 years ago
3.0.0-alpha.9
2 years ago
3.0.0-alpha.8
2 years ago
3.0.0-alpha.1
2 years ago
3.0.0-alpha.0
2 years ago
3.0.0-alpha.3
2 years ago
3.0.0-alpha.2
2 years ago
3.0.0-alpha.5
2 years ago
3.0.0-alpha.4
2 years ago
3.0.0-alpha.10
2 years ago
2.3.4
2 years ago
2.3.3
2 years ago
2.3.0
2 years ago
2.3.2
2 years ago
2.3.1
2 years ago
2.0.0-alpha.7
3 years ago
2.2.1
2 years ago
2.2.0
2 years ago
2.0.2
3 years ago
2.0.0-alpha.5
3 years ago
2.2.2
2 years ago
2.0.0-alpha.6
3 years ago
2.1.0
3 years ago
2.0.1
3 years ago
2.0.0
3 years ago
2.1.0-alpha.4
3 years ago
2.1.0-alpha.3
3 years ago
2.1.0-alpha.2
3 years ago
2.1.0-alpha.1
3 years ago
2.1.0-alpha.0
3 years ago
2.0.0-alpha.3
3 years ago
2.0.0-alpha.4
3 years ago
2.0.0-alpha.0
3 years ago
2.0.0-alpha.1
3 years ago
2.0.0-alpha.2
3 years ago
1.0.0-alpha.40
4 years ago
1.0.0-alpha.38
4 years ago
1.0.0-alpha.39
4 years ago
1.0.0-alpha.37
4 years ago
1.0.0-alpha.36
4 years ago