import { Facet, EditorSelection } from "../_vendor/@codemirror/state/dist-index.js";
import { formatWithCursor as cu } from "../_vendor/prettier/standalone.js";
import Vo from "../_vendor/prettier/plugins-babel.js";
import Nx from "../_vendor/prettier/plugins-estree.js";
const formatCallbackFacet = Facet.define({
  combine: (callbacks) => callbacks[0] ?? (() => {
  })
});
function formatDocument(view) {
  const onFormat = view.state.facet(formatCallbackFacet);
  function format(parser) {
    void cu(view.state.doc.toString(), {
      cursorOffset: view.state.selection.main.anchor,
      parser,
      plugins: [Vo, Nx]
    }).then(({ formatted, cursorOffset }) => {
      view.dispatch({
        changes: {
          from: 0,
          to: view.state.doc.length,
          insert: formatted
        },
        selection: EditorSelection.single(cursorOffset)
      });
      onFormat(formatted);
    });
  }
  format("babel");
  return true;
}
function createFormatExtension(onFormat) {
  return [formatCallbackFacet.of(onFormat)];
}
export {
  createFormatExtension,
  formatCallbackFacet,
  formatDocument
};
//# sourceMappingURL=format.js.map
