@scrabble-solver/scrabble-solver 2.13.6 → 2.13.7
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/.next/BUILD_ID +1 -1
- package/.next/build-manifest.json +6 -6
- package/.next/cache/.tsbuildinfo +1 -1
- package/.next/cache/eslint/.cache_8dgz12 +1 -1
- package/.next/cache/webpack/client-production/0.pack +0 -0
- package/.next/cache/webpack/client-production/index.pack +0 -0
- package/.next/cache/webpack/edge-server-production/0.pack +0 -0
- package/.next/cache/webpack/edge-server-production/index.pack +0 -0
- package/.next/cache/webpack/server-production/0.pack +0 -0
- package/.next/cache/webpack/server-production/index.pack +0 -0
- package/.next/prerender-manifest.js +1 -1
- package/.next/prerender-manifest.json +1 -1
- package/.next/routes-manifest.json +1 -1
- package/.next/server/chunks/807.js +1 -1
- package/.next/server/chunks/977.js +1 -1
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/pages/_app.js +1 -1
- package/.next/server/pages/_error.js +1 -1
- package/.next/server/pages/api/solve.js +1 -1
- package/.next/server/pages/index.html +1 -1
- package/.next/server/pages/index.js +1 -1
- package/.next/server/pages/index.json +1 -1
- package/.next/server/pages-manifest.json +1 -1
- package/.next/static/{4GWIKe7khKxREyq3ZamDK → QbBIK_mEs1LhYSpQwv6rZ}/_buildManifest.js +1 -1
- package/.next/static/chunks/pages/{404-129e0943628b6fab.js → 404-9d5621b1ca024a45.js} +1 -1
- package/.next/static/chunks/pages/_app-7bc3bf713c40526a.js +17 -0
- package/.next/static/chunks/pages/index-710b5c27542027be.js +1 -0
- package/.next/static/css/{f549d7823f599b8d.css → fe70298e6f597553.css} +1 -1
- package/.next/trace +44 -44
- package/package.json +9 -10
- package/src/components/Board/BoardPure.tsx +1 -1
- package/src/components/Board/hooks/useGrid.ts +13 -5
- package/src/components/Board/lib/index.ts +0 -1
- package/src/components/Button/Button.tsx +16 -17
- package/src/components/Button/Link.tsx +15 -16
- package/src/components/IconButton/IconButton.tsx +8 -8
- package/src/components/IconButton/Link.tsx +8 -8
- package/src/components/Results/Cell.tsx +4 -5
- package/src/components/Results/HeaderButton.tsx +25 -22
- package/src/components/Results/Result.tsx +15 -3
- package/src/components/Results/Results.module.scss +25 -10
- package/src/components/Results/Results.tsx +1 -1
- package/src/components/Results/getCoordinatesColumn.ts +15 -0
- package/src/components/Results/getLocaleColumns.ts +7 -0
- package/src/components/Results/types.ts +1 -0
- package/src/components/Results/useColumns.ts +9 -6
- package/src/components/Tooltip/Tooltip.tsx +28 -0
- package/src/components/Tooltip/TooltipContent.tsx +53 -0
- package/src/components/Tooltip/TooltipTrigger.tsx +26 -0
- package/src/components/Tooltip/context.ts +17 -0
- package/src/components/Tooltip/index.ts +1 -1
- package/src/components/Tooltip/useTooltip.ts +54 -0
- package/src/components/index.ts +1 -1
- package/src/hooks/index.ts +0 -1
- package/src/lib/getCoordinates.ts +18 -0
- package/src/lib/groupResults.ts +16 -11
- package/src/lib/index.ts +2 -1
- package/src/lib/sortResults.ts +1 -0
- package/src/pages/_app.tsx +5 -1
- package/src/parameters/index.ts +1 -0
- package/src/types/index.ts +1 -0
- package/.next/static/chunks/pages/_app-cccda36d00fa2328.js +0 -17
- package/.next/static/chunks/pages/index-caaf20b2488cb10e.js +0 -1
- package/src/components/Tooltip/useTooltip.tsx +0 -134
- package/src/hooks/usePortal.tsx +0 -47
- package/src/lib/canUseDom.ts +0 -3
- /package/.next/static/{4GWIKe7khKxREyq3ZamDK → QbBIK_mEs1LhYSpQwv6rZ}/_ssgManifest.js +0 -0
- /package/src/{components/Board/lib → lib}/getCoordinate.ts +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { FloatingArrow, FloatingPortal, useDelayGroup, useMergeRefs, useTransitionStyles } from '@floating-ui/react';
|
|
2
|
+
import { forwardRef, HTMLProps } from 'react';
|
|
3
|
+
|
|
4
|
+
import { TOOLTIP_DURATION } from 'parameters';
|
|
5
|
+
|
|
6
|
+
import { useTooltipContext } from './context';
|
|
7
|
+
import styles from './Tooltip.module.scss';
|
|
8
|
+
|
|
9
|
+
type Props = HTMLProps<HTMLDivElement>;
|
|
10
|
+
|
|
11
|
+
const INSTANT_DURATION = 0;
|
|
12
|
+
|
|
13
|
+
export const TooltipContent = forwardRef<HTMLDivElement, Props>((props, ref) => {
|
|
14
|
+
const state = useTooltipContext();
|
|
15
|
+
const { context } = state;
|
|
16
|
+
const { isInstantPhase, currentId } = useDelayGroup(context, { id: context.floatingId });
|
|
17
|
+
const finalRef = useMergeRefs([state.refs.setFloating, ref]);
|
|
18
|
+
|
|
19
|
+
const instantPhaseDuration = {
|
|
20
|
+
open: INSTANT_DURATION,
|
|
21
|
+
close: currentId === context.floatingId ? TOOLTIP_DURATION : INSTANT_DURATION,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const { isMounted, styles: transitionStyles } = useTransitionStyles(context, {
|
|
25
|
+
duration: isInstantPhase ? instantPhaseDuration : TOOLTIP_DURATION,
|
|
26
|
+
initial: {
|
|
27
|
+
opacity: 0,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (!isMounted) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<FloatingPortal>
|
|
37
|
+
<div
|
|
38
|
+
className={styles.tooltip}
|
|
39
|
+
ref={finalRef}
|
|
40
|
+
style={{
|
|
41
|
+
...state.floatingStyles,
|
|
42
|
+
...props.style,
|
|
43
|
+
...transitionStyles,
|
|
44
|
+
}}
|
|
45
|
+
{...state.getFloatingProps(props)}
|
|
46
|
+
>
|
|
47
|
+
<div>{props.children}</div>
|
|
48
|
+
|
|
49
|
+
<FloatingArrow className={styles.arrow} context={context} ref={state.arrowRef} />
|
|
50
|
+
</div>
|
|
51
|
+
</FloatingPortal>
|
|
52
|
+
);
|
|
53
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useMergeRefs } from '@floating-ui/react';
|
|
2
|
+
import { HTMLProps, cloneElement, forwardRef, isValidElement } from 'react';
|
|
3
|
+
|
|
4
|
+
import { useTooltipContext } from './context';
|
|
5
|
+
|
|
6
|
+
type Props = HTMLProps<HTMLElement>;
|
|
7
|
+
|
|
8
|
+
export const TooltipTrigger = forwardRef<HTMLElement, Props>(({ children, ...props }, ref) => {
|
|
9
|
+
const state = useTooltipContext();
|
|
10
|
+
const childrenElement = children as any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
11
|
+
const finalRef = useMergeRefs([state.refs.setReference, ref, childrenElement.ref]);
|
|
12
|
+
|
|
13
|
+
if (!isValidElement(children)) {
|
|
14
|
+
throw new Error("TooltipTrigger's children are not a valid element");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return cloneElement(
|
|
18
|
+
children,
|
|
19
|
+
state.getReferenceProps({
|
|
20
|
+
ref: finalRef,
|
|
21
|
+
...props,
|
|
22
|
+
...children.props,
|
|
23
|
+
'data-state': state.open ? 'open' : 'closed',
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
26
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useTooltip } from './useTooltip';
|
|
4
|
+
|
|
5
|
+
type TooltipContextType = ReturnType<typeof useTooltip> | null;
|
|
6
|
+
|
|
7
|
+
export const TooltipContext = createContext<TooltipContextType>(null);
|
|
8
|
+
|
|
9
|
+
export const useTooltipContext = () => {
|
|
10
|
+
const context = useContext(TooltipContext);
|
|
11
|
+
|
|
12
|
+
if (context === null) {
|
|
13
|
+
throw new Error('Tooltip components must be wrapped in <Tooltip />');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return context;
|
|
17
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Tooltip } from './Tooltip';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Placement,
|
|
3
|
+
arrow,
|
|
4
|
+
autoUpdate,
|
|
5
|
+
flip,
|
|
6
|
+
offset,
|
|
7
|
+
shift,
|
|
8
|
+
useDelayGroup,
|
|
9
|
+
useDismiss,
|
|
10
|
+
useFloating,
|
|
11
|
+
useFocus,
|
|
12
|
+
useHover,
|
|
13
|
+
useInteractions,
|
|
14
|
+
useRole,
|
|
15
|
+
} from '@floating-ui/react';
|
|
16
|
+
import { useMemo, useRef, useState } from 'react';
|
|
17
|
+
|
|
18
|
+
const ARROW_SIZE = 7;
|
|
19
|
+
const ARROW_GAP = 3;
|
|
20
|
+
const PADDING = 10;
|
|
21
|
+
|
|
22
|
+
interface TooltipOptions {
|
|
23
|
+
placement?: Placement;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const useTooltip = ({ placement = 'top' }: TooltipOptions = {}) => {
|
|
27
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
28
|
+
const arrowRef = useRef(null);
|
|
29
|
+
const data = useFloating({
|
|
30
|
+
placement,
|
|
31
|
+
open: isOpen,
|
|
32
|
+
onOpenChange: setIsOpen,
|
|
33
|
+
whileElementsMounted: autoUpdate,
|
|
34
|
+
middleware: [flip(), shift({ padding: PADDING }), offset(ARROW_SIZE + ARROW_GAP), arrow({ element: arrowRef })],
|
|
35
|
+
});
|
|
36
|
+
const { context } = data;
|
|
37
|
+
const { delay } = useDelayGroup(context);
|
|
38
|
+
const hover = useHover(context, { move: false, delay });
|
|
39
|
+
const focus = useFocus(context);
|
|
40
|
+
const dismiss = useDismiss(context);
|
|
41
|
+
const role = useRole(context, { role: 'tooltip' });
|
|
42
|
+
const interactions = useInteractions([hover, focus, dismiss, role]);
|
|
43
|
+
|
|
44
|
+
return useMemo(
|
|
45
|
+
() => ({
|
|
46
|
+
arrowRef,
|
|
47
|
+
open: isOpen,
|
|
48
|
+
setOpen: setIsOpen,
|
|
49
|
+
...interactions,
|
|
50
|
+
...data,
|
|
51
|
+
}),
|
|
52
|
+
[arrowRef, isOpen, setIsOpen, interactions, data],
|
|
53
|
+
);
|
|
54
|
+
};
|
package/src/components/index.ts
CHANGED
|
@@ -23,4 +23,4 @@ export { default as SeoMessage } from './SeoMessage';
|
|
|
23
23
|
export { default as Solver } from './Solver';
|
|
24
24
|
export { default as Spinner } from './Spinner';
|
|
25
25
|
export { default as Tile } from './Tile';
|
|
26
|
-
export
|
|
26
|
+
export * from './Tooltip';
|
package/src/hooks/index.ts
CHANGED
|
@@ -9,5 +9,4 @@ export { default as useMedia } from './useMedia';
|
|
|
9
9
|
export { default as useMediaQueries } from './useMediaQueries';
|
|
10
10
|
export { default as useMediaQuery } from './useMediaQuery';
|
|
11
11
|
export { default as useOnWindowResize } from './useOnWindowResize';
|
|
12
|
-
export { default as usePortal } from './usePortal';
|
|
13
12
|
export { default as useViewportSize } from './useViewportSize';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Result, ShowCoordinates } from '@scrabble-solver/types';
|
|
2
|
+
|
|
3
|
+
import getCoordinate from './getCoordinate';
|
|
4
|
+
|
|
5
|
+
const getCoordinates = (result: Result, showCoordinates: ShowCoordinates): string => {
|
|
6
|
+
if (showCoordinates === 'hidden') {
|
|
7
|
+
return '';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const firstCell = result.cells[0];
|
|
11
|
+
const isHorizontal = firstCell.x !== result.cells[1].x;
|
|
12
|
+
const x = getCoordinate(firstCell.x, showCoordinates === 'original' ? 'letter' : 'number');
|
|
13
|
+
const y = getCoordinate(firstCell.y, showCoordinates === 'original' ? 'number' : 'letter');
|
|
14
|
+
|
|
15
|
+
return isHorizontal ? `${y}${x}` : `${x}${y}`;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default getCoordinates;
|
package/src/lib/groupResults.ts
CHANGED
|
@@ -18,18 +18,23 @@ const groupResults = (
|
|
|
18
18
|
return results;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
const regExp = createRegExp(query);
|
|
22
|
+
|
|
21
23
|
return results.reduce<GroupedResults>(
|
|
22
|
-
(
|
|
23
|
-
const matchesQuery =
|
|
24
|
-
const matchesCellFilter =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
matching
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
(groupedResults, result) => {
|
|
25
|
+
const matchesQuery = () => regExp.test(result.word);
|
|
26
|
+
const matchesCellFilter = () =>
|
|
27
|
+
cellFilter.every(({ x, y }) => {
|
|
28
|
+
return result.cells.some((cell) => cell.x === x && cell.y === y);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (matchesCellFilter() && matchesQuery()) {
|
|
32
|
+
groupedResults.matching.push(result);
|
|
33
|
+
} else {
|
|
34
|
+
groupedResults.other.push(result);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return groupedResults;
|
|
33
38
|
},
|
|
34
39
|
{ matching: [], other: [] },
|
|
35
40
|
);
|
package/src/lib/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { default as arrayEquals } from './arrayEquals';
|
|
2
|
-
export { default as canUseDom } from './canUseDom';
|
|
3
2
|
export { default as createArray } from './createArray';
|
|
4
3
|
export { default as createComparator } from './createComparator';
|
|
5
4
|
export { default as createGridOf } from './createGridOf';
|
|
@@ -15,6 +14,8 @@ export { default as extractCharactersByCase } from './extractCharactersByCase';
|
|
|
15
14
|
export { default as extractInputValue } from './extractInputValue';
|
|
16
15
|
export { default as findCell } from './findCell';
|
|
17
16
|
export { default as getCellSize } from './getCellSize';
|
|
17
|
+
export { default as getCoordinate } from './getCoordinate';
|
|
18
|
+
export { default as getCoordinates } from './getCoordinates';
|
|
18
19
|
export { default as getRemainingTiles } from './getRemainingTiles';
|
|
19
20
|
export { default as getRemainingTilesCount } from './getRemainingTilesCount';
|
|
20
21
|
export { default as getRemainingTilesGroups } from './getRemainingTilesGroups';
|
package/src/lib/sortResults.ts
CHANGED
|
@@ -8,6 +8,7 @@ import reverseComparator from './reverseComparator';
|
|
|
8
8
|
const comparators: Record<ResultColumn, (locale: string) => Comparator<Result>> = {
|
|
9
9
|
[ResultColumn.BlanksCount]: (locale: string) => createKeyComparator('blanksCount', locale),
|
|
10
10
|
[ResultColumn.ConsonantsCount]: (locale: string) => createKeyComparator('consonantsCount', locale),
|
|
11
|
+
[ResultColumn.Coordinates]: () => () => 0,
|
|
11
12
|
[ResultColumn.Points]: (locale: string) => createKeyComparator('points', locale),
|
|
12
13
|
[ResultColumn.TilesCount]: (locale: string) => createKeyComparator('tilesCount', locale),
|
|
13
14
|
[ResultColumn.VowelsCount]: (locale: string) => createKeyComparator('vowelsCount', locale),
|
package/src/pages/_app.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FloatingDelayGroup } from '@floating-ui/react';
|
|
1
2
|
import { AppProps } from 'next/app';
|
|
2
3
|
import Head from 'next/head';
|
|
3
4
|
import { FunctionComponent } from 'react';
|
|
@@ -64,7 +65,10 @@ const App: FunctionComponent<AppProps> = ({ Component, pageProps }) => (
|
|
|
64
65
|
|
|
65
66
|
<Provider store={store}>
|
|
66
67
|
<SeoMessage />
|
|
67
|
-
|
|
68
|
+
|
|
69
|
+
<FloatingDelayGroup delay={0}>
|
|
70
|
+
<Component {...pageProps} />
|
|
71
|
+
</FloatingDelayGroup>
|
|
68
72
|
</Provider>
|
|
69
73
|
</>
|
|
70
74
|
);
|
package/src/parameters/index.ts
CHANGED
|
@@ -90,6 +90,7 @@ export const MODAL_HEADER_HEIGHT = 45;
|
|
|
90
90
|
export const NAV_PADDING = SPACING_L;
|
|
91
91
|
|
|
92
92
|
export const TILE_SIZE = 80;
|
|
93
|
+
export const TOOLTIP_DURATION = TRANSITION_DURATION;
|
|
93
94
|
|
|
94
95
|
export const PLAIN_TILES_COLOR_DEFAULT = COLOR_GREEN;
|
|
95
96
|
export const PLAIN_TILES_PADDING_HORIZONTAL = 0;
|
package/src/types/index.ts
CHANGED