@yoopta/code 6.0.0-beta.2 → 6.0.0-beta.20
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.
- package/README.md +46 -4
- package/dist/commands/code-commands.d.ts +17 -3
- package/dist/commands/code-commands.d.ts.map +1 -1
- package/dist/commands/code-group-commands.d.ts +11 -2
- package/dist/commands/code-group-commands.d.ts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/plugin/code-group-plugin.d.ts.map +1 -1
- package/dist/utils/prettier.d.ts +22 -1
- package/dist/utils/prettier.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,11 +1,53 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yoopta/code
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Code block plugin for Yoopta Editor. Renders code blocks with optional language and theme (e.g. for syntax highlighting). Use headless or with theme UI from `@yoopta/themes-shadcn`.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn add @yoopta/code
|
|
9
|
+
```
|
|
4
10
|
|
|
5
11
|
## Usage
|
|
6
12
|
|
|
13
|
+
Pass the plugin to `createYooptaEditor`. Do not pass `plugins` to `<YooptaEditor>`.
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { useMemo } from 'react';
|
|
17
|
+
import YooptaEditor, { createYooptaEditor } from '@yoopta/editor';
|
|
18
|
+
import Code from '@yoopta/code';
|
|
19
|
+
|
|
20
|
+
const plugins = [Code];
|
|
21
|
+
|
|
22
|
+
export default function Editor() {
|
|
23
|
+
const editor = useMemo(() => createYooptaEditor({ plugins, marks: [] }), []);
|
|
24
|
+
return <YooptaEditor editor={editor} onChange={() => {}} />;
|
|
25
|
+
}
|
|
7
26
|
```
|
|
8
|
-
const code = require('yoopta-code');
|
|
9
27
|
|
|
10
|
-
|
|
28
|
+
## Themed UI
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { applyTheme } from '@yoopta/themes-shadcn';
|
|
32
|
+
const plugins = applyTheme([Paragraph, Code, /* ... */]);
|
|
11
33
|
```
|
|
34
|
+
|
|
35
|
+
Or: `Code.extend({ elements: CodeUI })` with `CodeUI` from `@yoopta/themes-shadcn/code`.
|
|
36
|
+
|
|
37
|
+
## Extend
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
Code.extend({
|
|
41
|
+
elements: {
|
|
42
|
+
code: { render: (props) => <YourCodeBlock {...props} /> },
|
|
43
|
+
},
|
|
44
|
+
options: {
|
|
45
|
+
display: { title: 'Code', description: 'Code block' },
|
|
46
|
+
shortcuts: ['code', '```'],
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Docs
|
|
52
|
+
|
|
53
|
+
See [Code plugin docs](https://docs.yoopta.dev/plugins/code) and [Code group](https://docs.yoopta.dev/plugins/code-group).
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { YooEditor, YooptaPathIndex } from '@yoopta/editor';
|
|
2
2
|
import type { CodeElement, CodeElementProps } from '../types';
|
|
3
|
+
import { type FormatCodeOptions } from '../utils/prettier';
|
|
3
4
|
type CodeElementOptions = {
|
|
4
5
|
text?: string;
|
|
5
6
|
props?: CodeElementProps;
|
|
@@ -8,14 +9,27 @@ type InsertCodeOptions = CodeElementOptions & {
|
|
|
8
9
|
at?: YooptaPathIndex;
|
|
9
10
|
focus?: boolean;
|
|
10
11
|
};
|
|
11
|
-
export type
|
|
12
|
+
export type BeautifyCodeResult = {
|
|
13
|
+
success: boolean;
|
|
14
|
+
error?: string;
|
|
15
|
+
};
|
|
16
|
+
export type CodeCommandsType = {
|
|
12
17
|
buildCodeElements: (editor: YooEditor, options?: Partial<CodeElementOptions>) => CodeElement;
|
|
13
18
|
insertCode: (editor: YooEditor, options?: Partial<InsertCodeOptions>) => void;
|
|
14
19
|
deleteCode: (editor: YooEditor, blockId: string) => void;
|
|
15
20
|
updateCodeTheme: (editor: YooEditor, blockId: string, theme: CodeElementProps['theme']) => void;
|
|
16
21
|
updateCodeLanguage: (editor: YooEditor, blockId: string, language: CodeElementProps['language']) => void;
|
|
17
|
-
|
|
22
|
+
/** Formats the code string and returns the result (does not modify editor) */
|
|
23
|
+
prettifyCode: (editor: YooEditor, code: string, language: string, options?: FormatCodeOptions) => Promise<{
|
|
24
|
+
formatted: string;
|
|
25
|
+
success: boolean;
|
|
26
|
+
error?: string;
|
|
27
|
+
}>;
|
|
28
|
+
/** Beautifies the code in the specified block (modifies editor content) */
|
|
29
|
+
beautifyCode: (editor: YooEditor, blockId: string, options?: FormatCodeOptions) => Promise<BeautifyCodeResult>;
|
|
30
|
+
/** Checks if a language supports formatting */
|
|
31
|
+
isLanguageSupported: (language: string) => boolean;
|
|
18
32
|
};
|
|
19
|
-
export declare const CodeCommands:
|
|
33
|
+
export declare const CodeCommands: CodeCommandsType;
|
|
20
34
|
export {};
|
|
21
35
|
//# sourceMappingURL=code-commands.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-commands.d.ts","sourceRoot":"","sources":["../../src/commands/code-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"code-commands.d.ts","sourceRoot":"","sources":["../../src/commands/code-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAIjE,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,KAAK,iBAAiB,EAAmC,MAAM,mBAAmB,CAAC;AAE5F,KAAK,kBAAkB,GAAG;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,gBA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AC,EAAE,iBAAiB,KACxB,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACjC,+CAA+C;IAC/C,mBAAmB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;CACpD,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,gBA4E1B,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { YooEditor } from '@yoopta/editor';
|
|
2
2
|
import type { Location } from 'slate';
|
|
3
3
|
import type { CodeGroupContainerElement } from '../types';
|
|
4
|
+
import { type FormatCodeOptions } from '../utils/prettier';
|
|
4
5
|
export type InsertTabOptions = {
|
|
5
6
|
afterTabId?: string;
|
|
6
7
|
at?: Location;
|
|
@@ -8,10 +9,18 @@ export type InsertTabOptions = {
|
|
|
8
9
|
export type DeleteTabOptions = {
|
|
9
10
|
tabId: string;
|
|
10
11
|
};
|
|
11
|
-
export type
|
|
12
|
+
export type BeautifyTabResult = {
|
|
13
|
+
success: boolean;
|
|
14
|
+
error?: string;
|
|
15
|
+
};
|
|
16
|
+
export type CodeGroupCommands = {
|
|
12
17
|
buildCodeElements: (editor: YooEditor) => CodeGroupContainerElement;
|
|
13
18
|
addTabItem: (editor: YooEditor, blockId: string, options?: InsertTabOptions) => void;
|
|
14
19
|
deleteTabItem: (editor: YooEditor, blockId: string, options: DeleteTabOptions) => void;
|
|
20
|
+
/** Beautifies the code in the specified tab (modifies editor content) */
|
|
21
|
+
beautifyTab: (editor: YooEditor, blockId: string, tabId: string, options?: FormatCodeOptions) => Promise<BeautifyTabResult>;
|
|
22
|
+
/** Checks if a language supports formatting */
|
|
23
|
+
isLanguageSupported: (language: string) => boolean;
|
|
15
24
|
};
|
|
16
|
-
export declare const CodeGroupCommands:
|
|
25
|
+
export declare const CodeGroupCommands: CodeGroupCommands;
|
|
17
26
|
//# sourceMappingURL=code-group-commands.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-group-commands.d.ts","sourceRoot":"","sources":["../../src/commands/code-group-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGtC,OAAO,KAAK,EAAE,yBAAyB,
|
|
1
|
+
{"version":3,"file":"code-group-commands.d.ts","sourceRoot":"","sources":["../../src/commands/code-group-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGtC,OAAO,KAAK,EAAE,yBAAyB,EAA2B,MAAM,UAAU,CAAC;AACnF,OAAO,EAAE,KAAK,iBAAiB,EAAmC,MAAM,mBAAmB,CAAC;AAE5F,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,QAAQ,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,iBAAiB,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,yBAAyB,CAAC;IACpE,UAAU,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACrF,aAAa,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACvF,yEAAyE;IACzE,WAAW,EAAE,CACX,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,iBAAiB,KACxB,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAChC,+CAA+C;IAC/C,mBAAmB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;CACpD,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,iBA4R/B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,10 @@ import { CodeGroup } from './plugin/code-group-plugin';
|
|
|
2
2
|
import { Code } from './plugin/code-plugin';
|
|
3
3
|
import { CodeElement, CodeElementProps, CodeGroupElementMap, CodeGroupPluginBlockOptions } from './types';
|
|
4
4
|
export { HighlightedCodeOverlay, useHighlighter } from './components/highlighted-code-overlay';
|
|
5
|
-
export { CodeCommands } from './commands/code-commands';
|
|
6
|
-
export { CodeGroupCommands } from './commands/code-group-commands';
|
|
5
|
+
export { CodeCommands, type BeautifyCodeResult } from './commands/code-commands';
|
|
6
|
+
export { CodeGroupCommands, type BeautifyTabResult } from './commands/code-group-commands';
|
|
7
7
|
export { SHIKI_CODE_LANGUAGES, SHIKI_CODE_THEMES } from './utils/shiki';
|
|
8
|
+
export { isLanguageSupported, type FormatCodeOptions } from './utils/prettier';
|
|
8
9
|
export { CodeElement, CodeElementProps };
|
|
9
10
|
export { CodeGroupElementMap, CodeGroupPluginBlockOptions };
|
|
10
11
|
export { CodeGroup, Code };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,2BAA2B,EAC5B,MAAM,SAAS,CAAC;AAKjB,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,2BAA2B,EAC5B,MAAM,SAAS,CAAC;AAKjB,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAE3B,QAAA,MAAM,WAAW;;;CAGhB,CAAC;AAEF,eAAe,WAAW,CAAC"}
|