@jbpark/live-editor 1.9.0 → 1.10.0

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/dist/index.d.mts CHANGED
@@ -133,17 +133,26 @@ declare const Core: ({
133
133
  }: Props$2) => react_jsx_runtime0.JSX.Element;
134
134
  //#endregion
135
135
  //#region src/components/editor/editor.d.ts
136
+ interface EditorRenderData {
137
+ value: string;
138
+ onChange: (value: string) => void;
139
+ formatCode: (code: string) => Promise<string>;
140
+ }
136
141
  interface Props$1 extends Omit<Props$2, 'onSave' | 'onError'> {
137
142
  defaultValue?: string;
138
143
  debounce?: number;
144
+ renderEditor?: (data: EditorRenderData) => React.ReactNode;
139
145
  }
140
146
  declare const Editor$1: ({
141
147
  defaultValue,
142
148
  value: _value,
143
149
  debounce,
144
150
  onChange: _onChange,
151
+ renderEditor,
152
+ fragment,
153
+ prettierOptions,
145
154
  ...props
146
- }: Props$1) => react_jsx_runtime0.JSX.Element;
155
+ }: Props$1) => string | number | bigint | boolean | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | react_jsx_runtime0.JSX.Element | null | undefined;
147
156
  //#endregion
148
157
  //#region src/components/editor/index.d.ts
149
158
  type EditorComponent = typeof Editor$1 & {
@@ -252,8 +261,11 @@ declare const App: {
252
261
  value: _value,
253
262
  debounce,
254
263
  onChange: _onChange,
264
+ renderEditor,
265
+ fragment,
266
+ prettierOptions,
255
267
  ...props
256
- }: Props$1) => react_jsx_runtime0.JSX.Element) & {
268
+ }: Props$1) => string | number | bigint | boolean | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | react_jsx_runtime0.JSX.Element | null | undefined) & {
257
269
  Core: ({
258
270
  value,
259
271
  theme,
package/dist/index.mjs CHANGED
@@ -11351,8 +11351,8 @@ GutterMarker.prototype.startSide = GutterMarker.prototype.endSide = -1;
11351
11351
  GutterMarker.prototype.point = true;
11352
11352
 
11353
11353
  //#endregion
11354
- //#region src/components/editor/core.tsx
11355
- const prettierInitialOptions = {
11354
+ //#region src/components/editor/use-format-code.ts
11355
+ const DEFAULT_PRETTIER_OPTIONS = {
11356
11356
  tabWidth: 2,
11357
11357
  singleQuote: true,
11358
11358
  trailingComma: "all",
@@ -11360,13 +11360,12 @@ const prettierInitialOptions = {
11360
11360
  arrowParens: "avoid",
11361
11361
  printWidth: 60
11362
11362
  };
11363
- const Core = ({ value, theme, height, className, prettierOptions, fragment, raw, onChange, onSave: _onSave, onError, ...props }) => {
11364
- const editorRef = useRef(null);
11363
+ const useFormatCode = ({ fragment, prettierOptions } = {}) => {
11365
11364
  const prettierConfig = useMemo(() => ({
11366
- ...prettierInitialOptions,
11365
+ ...DEFAULT_PRETTIER_OPTIONS,
11367
11366
  ...prettierOptions
11368
11367
  }), [prettierOptions]);
11369
- const formatCode = useCallback(async (code) => {
11368
+ return useCallback(async (code) => {
11370
11369
  const isTypeScript = detectTypeScript(code);
11371
11370
  const source = fragment ? `<>${code}</>` : code;
11372
11371
  const formatted = await prettier.format(source, {
@@ -11381,6 +11380,16 @@ const Core = ({ value, theme, height, className, prettierOptions, fragment, raw,
11381
11380
  if (fragment) return formatted.replace(/^<>\n?/, "").replace(/\n?<\/>;?\s*$/, "").replace(/^ {2}/gm, "").trim();
11382
11381
  return formatted;
11383
11382
  }, [prettierConfig, fragment]);
11383
+ };
11384
+
11385
+ //#endregion
11386
+ //#region src/components/editor/core.tsx
11387
+ const Core = ({ value, theme, height, className, prettierOptions, fragment, raw, onChange, onSave: _onSave, onError, ...props }) => {
11388
+ const editorRef = useRef(null);
11389
+ const formatCode = useFormatCode({
11390
+ fragment,
11391
+ prettierOptions
11392
+ });
11384
11393
  const onSave = useCallback(async (val) => {
11385
11394
  try {
11386
11395
  const currentView = editorRef.current?.view;
@@ -12857,7 +12866,7 @@ Dnd.DraggableItem = DraggableItem;
12857
12866
 
12858
12867
  //#endregion
12859
12868
  //#region src/components/editor/editor.tsx
12860
- const Editor$1 = ({ defaultValue, value: _value, debounce = 1e3, onChange: _onChange, ...props }) => {
12869
+ const Editor$1 = ({ defaultValue, value: _value, debounce = 1e3, onChange: _onChange, renderEditor, fragment, prettierOptions, ...props }) => {
12861
12870
  const { setCode } = usePreview();
12862
12871
  const { setError } = useError();
12863
12872
  const value = _value.trim() === "" ? defaultValue || DEFAULT_TEMPLATE : _value;
@@ -12870,15 +12879,26 @@ const Editor$1 = ({ defaultValue, value: _value, debounce = 1e3, onChange: _onCh
12870
12879
  const onError = useCallback((error) => {
12871
12880
  setError(error);
12872
12881
  }, [setError]);
12882
+ const formatCode = useFormatCode({
12883
+ fragment,
12884
+ prettierOptions
12885
+ });
12873
12886
  const debouncedValue = useDebouncedValue(value, debounce);
12874
12887
  useEffect(() => {
12875
12888
  setCode(debouncedValue);
12876
12889
  }, [debouncedValue, setCode]);
12890
+ if (renderEditor) return renderEditor({
12891
+ value,
12892
+ onChange,
12893
+ formatCode
12894
+ });
12877
12895
  return /* @__PURE__ */ jsx(Core, {
12878
12896
  value,
12879
12897
  onChange,
12880
12898
  onSave,
12881
12899
  onError,
12900
+ fragment,
12901
+ prettierOptions,
12882
12902
  ...props
12883
12903
  });
12884
12904
  };