@yoopta/code 6.0.0-beta.4 → 6.0.0-beta.5

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.
@@ -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 CodeCommands = {
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
- prettifyCode: (_editor: YooEditor, code: string, language: string) => Promise<string>;
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: CodeCommands;
33
+ export declare const CodeCommands: CodeCommandsType;
20
34
  export {};
21
35
  //# sourceMappingURL=code-commands.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file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,8EAA8E;IAC9E,YAAY,EAAE,CACZ,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,iBAAiB,KACxB,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtE,2EAA2E;IAC3E,YAAY,EAAE,CACZ,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,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
  };
12
+ export type BeautifyTabResult = {
13
+ success: boolean;
14
+ error?: string;
15
+ };
11
16
  export type CodeGroupCommandsType = {
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
25
  export declare const CodeGroupCommands: CodeGroupCommandsType;
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,EAAE,MAAM,UAAU,CAAC;AAE1D,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,qBAAqB,GAAG;IAClC,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;CACxF,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,qBA0N/B,CAAC"}
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,qBAAqB,GAAG;IAClC,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,qBA0Q/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 };
@@ -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;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAExE,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"}
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,2BAA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