Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeyens committed Aug 8, 2024
1 parent 70b1581 commit b512674
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 42 deletions.
2 changes: 1 addition & 1 deletion apps/www/src/lib/plate/demo/plugins/autoformatOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export const autoformatIndentLists: AutoformatRule[] = [
];

export const getAutoformatOptions = (
id: string | undefined,
id?: string,
enabled?: Record<string, boolean>
): Partial<AutoformatPluginOptions> => {
const autoformatOptions: Partial<AutoformatPluginOptions> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { jsx } from '@udecode/plate-test-utils';
import { withReact } from 'slate-react';
import { autoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';
import { getAutoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';

import { AutoformatPlugin } from '../../../AutoformatPlugin';
import { withAutoformat } from '../../../withAutoformat';
Expand All @@ -28,7 +28,7 @@ const output = (
it('should autoformat', () => {
const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText(' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { jsx } from '@udecode/plate-test-utils';
import { withReact } from 'slate-react';
import {
autoformatOptions,
getAutoformatOptions,
preFormat,
} from 'www/src/lib/plate/demo/plugins/autoformatOptions';

Expand Down Expand Up @@ -48,7 +48,7 @@ describe('when ``` at block start', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText('`');
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('when ```', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText('`');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ELEMENT_H1 } from '@udecode/plate-heading';
import { jsx } from '@udecode/plate-test-utils';
import { withReact } from 'slate-react';
import {
autoformatOptions,
getAutoformatOptions,
preFormat,
} from 'www/src/lib/plate/demo/plugins/autoformatOptions';

Expand Down Expand Up @@ -71,7 +71,7 @@ describe('when ##space', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText(' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import { jsx } from '@udecode/plate-test-utils';
import { withReact } from 'slate-react';
import { autoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';
import { getAutoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';

import type { AutoformatBlockRule } from '../../../common/types';
import type {
AutoformatBlockRule,
AutoformatPluginOptions,
} from '../../../types';

import { AutoformatPlugin } from '../../../AutoformatPlugin';
import { withAutoformat } from '../../../withAutoformat';
Expand Down Expand Up @@ -35,7 +38,7 @@ describe('when -space', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText(' ');
Expand Down Expand Up @@ -68,7 +71,7 @@ describe('when 1.space', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText(' ');
Expand Down Expand Up @@ -97,7 +100,7 @@ describe('when [].space', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText(' ');
Expand Down Expand Up @@ -126,7 +129,7 @@ describe('when [x].space', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText(' ');
Expand Down Expand Up @@ -157,16 +160,16 @@ describe('when +space', () => {
// so here we need to remove the `preformat` property of the autoformat rule that uses this overload.

const autoformatPluginRulesWitoutTogglePreformat =
autoformatOptions!.rules!.map((rule) => {
getAutoformatOptions()!.rules!.map((rule) => {
const { preFormat, ...rest } = rule as AutoformatBlockRule;

if (rule.match === '+ ') return rest;

return rule;
});

const autoformatPluginWitoutTogglePreformat: typeof autoformatOptions = {
...autoformatOptions,
const autoformatPluginWitoutTogglePreformat: AutoformatPluginOptions = {
...getAutoformatOptions(),
rules: autoformatPluginRulesWitoutTogglePreformat as any,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { jsx } from '@udecode/plate-test-utils';
import { withReact } from 'slate-react';
import { autoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';
import { getAutoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';

import { AutoformatPlugin } from '../../../AutoformatPlugin';
import { withAutoformat } from '../../../withAutoformat';
Expand Down Expand Up @@ -32,7 +32,7 @@ const output = (
it('should autoformat', () => {
const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText(' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { jsx } from '@udecode/plate-test-utils';
import { withReact } from 'slate-react';
import { autoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';
import { getAutoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';

import { AutoformatPlugin } from '../../AutoformatPlugin';
import { withAutoformat } from '../../withAutoformat';
Expand All @@ -28,7 +28,7 @@ describe('when the start match is not present and the end match is present', ()

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText(' ');
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('when there is a character before match', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText('*');
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('when there is a character before match', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText('*');
Expand All @@ -111,7 +111,7 @@ describe('when selection is null', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText(' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { jsx } from '@udecode/plate-test-utils';
import { withReact } from 'slate-react';
import { autoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';
import { getAutoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';

import { AutoformatPlugin } from '../../../AutoformatPlugin';
import { withAutoformat } from '../../../withAutoformat';
Expand All @@ -29,7 +29,7 @@ const output = (
it('should autoformat', () => {
const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText('*');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { jsx } from '@udecode/plate-test-utils';
import { withReact } from 'slate-react';
import { autoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';
import { getAutoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';

import { AutoformatPlugin } from '../../../AutoformatPlugin';
import { withAutoformat } from '../../../withAutoformat';
Expand All @@ -29,7 +29,7 @@ const output = (
it('should autoformat', () => {
const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText('`');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { jsx } from '@udecode/plate-test-utils';
import { withReact } from 'slate-react';
import { autoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';
import { getAutoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';

import { AutoformatPlugin } from '../../../AutoformatPlugin';
import { withAutoformat } from '../../../withAutoformat';
Expand All @@ -29,7 +29,7 @@ const output = (
it('should autoformat', () => {
const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText('*');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@udecode/plate-basic-marks';
import { jsx } from '@udecode/plate-test-utils';
import { withReact } from 'slate-react';
import { autoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';
import { getAutoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';

import { AutoformatPlugin } from '../../../AutoformatPlugin';
import { withAutoformat } from '../../../withAutoformat';
Expand Down Expand Up @@ -37,7 +37,7 @@ describe('when inserting ***', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText('*');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { jsx } from '@udecode/plate-test-utils';
import { withReact } from 'slate-react';
import { autoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';
import { getAutoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';

import { AutoformatPlugin } from '../../../AutoformatPlugin';
import { withAutoformat } from '../../../withAutoformat';
Expand All @@ -29,7 +29,7 @@ const output = (
it('should autoformat', () => {
const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText('~');
Expand Down
16 changes: 8 additions & 8 deletions packages/autoformat/src/__tests__/withAutoformat/text.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { jsx } from '@udecode/plate-test-utils';
import { withReact } from 'slate-react';
import { autoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';
import { getAutoformatOptions } from 'www/src/lib/plate/demo/plugins/autoformatOptions';

import { AutoformatPlugin } from '../../AutoformatPlugin';
import { withAutoformat } from '../../withAutoformat';
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('when --space', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText('-');
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('when --space', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText('-');
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('when --space', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText('-');
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('when (tm)', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText(')');
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('when &sect', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText(';');
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('when //', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText('/');
Expand Down Expand Up @@ -237,7 +237,7 @@ describe('when typing %%%', () => {

const editor = withAutoformat({
editor: withReact(input),
plugin: AutoformatPlugin.configure(autoformatOptions),
plugin: AutoformatPlugin.configure(getAutoformatOptions()),
});

editor.insertText('%');
Expand Down

0 comments on commit b512674

Please sign in to comment.