Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Fix lib type export #1013

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platforms/web/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ vite.demo.config.ts
scripts
cypress
example-wysiwyg
coverage
7 changes: 7 additions & 0 deletions platforms/web/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { ComposerUpdate } from '../generated/wysiwyg';
import { ACTION_TYPES, SUGGESTIONS } from './constants';
import { AllowedMentionAttributes, LinkEvent } from './useListeners/types';

Expand Down Expand Up @@ -71,3 +72,9 @@ export type MappedSuggestion = {
text: string;
type: SuggestionType;
};
export type TraceAction = (
update: ComposerUpdate | null,
name: string,
value1?: string | number,
value2?: string | number,
) => ComposerUpdate | null;
1 change: 0 additions & 1 deletion platforms/web/lib/useTestCases/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
import { useTestCases } from './useTestCases';

export type TestUtilities = ReturnType<typeof useTestCases>['utilities'];

export type SelectTuple = ['select', number, number];
export type Tuple =
| SelectTuple
Expand Down
10 changes: 2 additions & 8 deletions platforms/web/lib/useTestCases/useTestCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@ limitations under the License.

import { RefObject, useCallback, useMemo, useRef, useState } from 'react';

import { ComposerModel, ComposerUpdate } from '../../generated/wysiwyg';
import { ComposerModel } from '../../generated/wysiwyg';
import { Actions } from './types';
import {
getSelectionAccordingToActions,
resetTestCase,
traceAction,
} from './utils';

export type TraceAction = (
update: ComposerUpdate | null,
name: string,
value1?: string | number,
value2?: string | number,
) => ComposerUpdate | null;
import { TraceAction } from '../types';

export type UseTestCases = {
testRef: RefObject<HTMLDivElement>;
Expand Down
2 changes: 1 addition & 1 deletion platforms/web/lib/useTestCases/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import {
new_composer_model_from_html,
} from '../../generated/wysiwyg';
import { getCurrentSelection } from '../dom';
import { TraceAction } from '../types';
import { isSelectTuple } from './assert';
import { Actions } from './types';
import { TraceAction } from './useTestCases';

export function traceAction(
testNode: HTMLElement | null,
Expand Down
2 changes: 1 addition & 1 deletion platforms/web/lib/useWysiwyg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import {
FormattingFunctions,
InputEventProcessor,
MappedSuggestion,
TraceAction,
} from './types.js';
import { useFormattingFunctions } from './useFormattingFunctions';
import { useComposerModel } from './useComposerModel';
import { useListeners } from './useListeners';
import { useTestCases } from './useTestCases';
import { mapSuggestion } from './suggestion.js';
import { TraceAction } from './useTestCases/useTestCases.js';

export { richToPlain, plainToRich } from './conversion';

Expand Down
1 change: 1 addition & 0 deletions platforms/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default defineConfig({
'lib/types.ts',
'lib/constants.ts',
'lib/useListeners/types.ts',
'lib/useTestCases/types.ts',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, why do we need to export a type used in test cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, its a bit weird that the function in question I think just returns this type so that we can unit test it.

At a high level you are right though, the app code shouldn't depend on the test code. I'll move the type to the app code to switch this around.

],
rollupTypes: true,
}),
Expand Down
Loading