UNPKG

@grafana/ui

Version:
1 lines 2.8 kB
{"version":3,"file":"options.mjs","sources":["../../../../src/slate-plugins/slate-prism/options.tsx"],"sourcesContent":["import { Record } from 'immutable';\nimport * as React from 'react';\nimport { Mark, Node, Decoration } from 'slate';\nimport { Editor } from 'slate-react';\n\nimport TOKEN_MARK from './TOKEN_MARK';\n\nexport interface OptionsFormat {\n // Determine which node should be highlighted\n onlyIn?: (node: Node) => boolean;\n // Returns the syntax for a node that should be highlighted\n getSyntax?: (node: Node) => string;\n // Render a highlighting mark in a highlighted node\n renderMark?: ({ mark, children }: { mark: Mark; children: React.ReactNode }) => void | React.ReactNode;\n}\n\n/**\n * Default filter for code blocks\n */\nfunction defaultOnlyIn(node: Node): boolean {\n return node.object === 'block' && node.type === 'code_block';\n}\n\n/**\n * Default getter for syntax\n */\nfunction defaultGetSyntax(node: Node): string {\n return 'javascript';\n}\n\n/**\n * Default rendering for decorations\n */\nfunction defaultRenderDecoration(\n props: { children: React.ReactNode; decoration: Decoration },\n editor: Editor,\n next: () => any\n): void | React.ReactNode {\n const { decoration } = props;\n if (decoration.type !== TOKEN_MARK) {\n return next();\n }\n\n const className = decoration.data.get('className');\n return <span className={className}>{props.children}</span>;\n}\n\n/**\n * The plugin options\n */\nclass Options\n extends Record({\n onlyIn: defaultOnlyIn,\n getSyntax: defaultGetSyntax,\n renderDecoration: defaultRenderDecoration,\n })\n implements OptionsFormat\n{\n declare readonly onlyIn: (node: Node) => boolean;\n declare readonly getSyntax: (node: Node) => string;\n declare readonly renderDecoration: (\n {\n decoration,\n children,\n }: {\n decoration: Decoration;\n children: React.ReactNode;\n },\n editor: Editor,\n next: () => any\n ) => void | React.ReactNode;\n\n constructor(props: OptionsFormat) {\n super(props);\n }\n}\n\nexport default Options;\n"],"names":[],"mappings":";;;;;AAmBA,SAAS,cAAc,IAAA,EAAqB;AAC1C,EAAA,OAAO,IAAA,CAAK,MAAA,KAAW,OAAA,IAAW,IAAA,CAAK,IAAA,KAAS,YAAA;AAClD;AAKA,SAAS,iBAAiB,IAAA,EAAoB;AAC5C,EAAA,OAAO,YAAA;AACT;AAKA,SAAS,uBAAA,CACP,KAAA,EACA,MAAA,EACA,IAAA,EACwB;AACxB,EAAA,MAAM,EAAE,YAAW,GAAI,KAAA;AACvB,EAAA,IAAI,UAAA,CAAW,SAAS,UAAA,EAAY;AAClC,IAAA,OAAO,IAAA,EAAK;AAAA,EACd;AAEA,EAAA,MAAM,SAAA,GAAY,UAAA,CAAW,IAAA,CAAK,GAAA,CAAI,WAAW,CAAA;AACjD,EAAA,uBAAO,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAuB,QAAA,EAAA,KAAA,CAAM,QAAA,EAAS,CAAA;AACrD;AAKA,MAAM,gBACI,MAAA,CAAO;AAAA,EACb,MAAA,EAAQ,aAAA;AAAA,EACR,SAAA,EAAW,gBAAA;AAAA,EACX,gBAAA,EAAkB;AACpB,CAAC,CAAA,CAEH;AAAA,EAeE,YAAY,KAAA,EAAsB;AAChC,IAAA,KAAA,CAAM,KAAK,CAAA;AAAA,EACb;AACF;;;;"}