@scrabble-solver/scrabble-solver 2.11.0 → 2.11.2
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 +7 -7
- package/.next/cache/.tsbuildinfo +1 -1
- package/.next/cache/eslint/.cache_8dgz12 +1 -1
- package/.next/cache/next-server.js.nft.json +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/next-server.js.nft.json +1 -1
- package/.next/prerender-manifest.json +1 -1
- package/.next/routes-manifest.json +1 -1
- package/.next/server/chunks/277.js +523 -611
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/pages/404.html +2 -2
- package/.next/server/pages/404.js.nft.json +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/pages/_app.js +0 -24
- package/.next/server/pages/_app.js.nft.json +1 -1
- package/.next/server/pages/_document.js.nft.json +1 -1
- package/.next/server/pages/api/dictionary/[locale]/[word].js +0 -1
- package/.next/server/pages/api/dictionary/[locale].js +0 -1
- package/.next/server/pages/api/solve.js +28 -8
- package/.next/server/pages/api/verify.js +0 -1
- package/.next/server/pages/api/visit.js +0 -1
- package/.next/server/pages/index.html +1 -1
- package/.next/server/pages/index.js +49 -90
- package/.next/server/pages/index.js.nft.json +1 -1
- package/.next/server/pages/index.json +1 -1
- package/.next/static/Mdvi3FY0PqkILKLbPlVBU/_buildManifest.js +1 -0
- package/.next/static/chunks/pages/{404-e0f30450e9920dc3.js → 404-448ba28510855455.js} +1 -1
- package/.next/static/chunks/pages/_app-495e6f4ccc278bb2.js +28 -0
- package/.next/static/chunks/pages/index-5ecc51900ca29685.js +1 -0
- package/.next/static/css/17b0a2db8742105f.css +1 -0
- package/.next/static/css/e1ffeb2558330c55.css +2 -0
- package/.next/trace +54 -55
- package/package.json +9 -14
- package/src/components/{Solver/components/EmptyState/EmptyState.module.scss → Alert/Alert.module.scss} +11 -7
- package/src/components/{Solver/components/EmptyState/EmptyState.tsx → Alert/Alert.tsx} +8 -6
- package/src/components/Alert/index.ts +1 -0
- package/src/components/Board/Board.module.scss +55 -0
- package/src/components/Board/BoardPure.tsx +4 -0
- package/src/components/Board/components/Cell/Cell.module.scss +51 -2
- package/src/components/Board/components/Cell/Cell.tsx +12 -0
- package/src/components/Board/components/Cell/CellPure.tsx +12 -0
- package/src/components/Board/hooks/useGrid.ts +9 -26
- package/src/components/Board/lib/getPositionInGrid.ts +1 -1
- package/src/components/Dictionary/Dictionary.module.scss +4 -0
- package/src/components/DictionaryInput/DictionaryInput.module.scss +1 -0
- package/src/components/EmptyState/EmptyState.module.scss +2 -1
- package/src/components/EmptyState/EmptyState.tsx +1 -2
- package/src/components/Loading/Loading.module.scss +1 -1
- package/src/components/Logo/Logo.tsx +5 -0
- package/src/components/LogoSplashScreen/LogoSplashScreen.module.scss +4 -1
- package/src/components/Modal/Modal.module.scss +14 -0
- package/src/components/Modal/Modal.tsx +4 -1
- package/src/components/PlainTiles/PlainTiles.module.scss +1 -1
- package/src/components/PlainTiles/Tile.tsx +3 -3
- package/src/components/Rack/Rack.module.scss +25 -0
- package/src/components/Rack/Rack.tsx +5 -4
- package/src/components/Rack/RackTile.tsx +6 -13
- package/src/components/Results/HeaderButton.tsx +5 -12
- package/src/components/Results/Result.tsx +5 -3
- package/src/components/Results/Results.module.scss +41 -1
- package/src/components/Results/Results.tsx +29 -43
- package/src/components/Results/types.ts +1 -1
- package/src/components/ResultsInput/ResultsInput.module.scss +1 -0
- package/src/components/Solver/Solver.module.scss +9 -4
- package/src/components/Solver/Solver.tsx +17 -19
- package/src/components/Solver/components/ResultCandidatePicker/ResultCandidatePicker.tsx +5 -6
- package/src/components/Solver/components/index.ts +0 -1
- package/src/components/Tile/Tile.module.scss +42 -61
- package/src/components/Tile/Tile.tsx +4 -3
- package/src/components/Tile/TilePure.tsx +4 -13
- package/src/components/Tooltip/Tooltip.module.scss +1 -72
- package/src/components/Tooltip/useTooltip.tsx +25 -35
- package/src/components/index.ts +1 -0
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useAppLayout.ts +3 -1
- package/src/i18n/de.json +0 -1
- package/src/i18n/en.json +0 -1
- package/src/i18n/es.json +0 -1
- package/src/i18n/fa.json +0 -1
- package/src/i18n/fr.json +0 -1
- package/src/i18n/pl.json +0 -1
- package/src/lib/createRegExp.ts +13 -0
- package/src/lib/groupResults.ts +38 -0
- package/src/lib/guessLocale.ts +22 -0
- package/src/lib/index.ts +4 -2
- package/src/lib/sortResults.ts +6 -10
- package/src/modals/DictionaryModal/DictionaryModal.module.scss +6 -2
- package/src/modals/KeyMapModal/KeyMapModal.tsx +5 -21
- package/src/modals/KeyMapModal/components/Mapping/Mapping.module.scss +4 -0
- package/src/modals/MenuModal/MenuModal.module.scss +7 -0
- package/src/modals/RemainingTilesModal/components/Character/Character.module.scss +1 -0
- package/src/modals/ResultsModal/ResultsModal.module.scss +3 -3
- package/src/modals/ResultsModal/ResultsModal.tsx +23 -11
- package/src/modals/SettingsModal/components/LocaleSetting/LocaleSetting.module.scss +2 -0
- package/src/modals/WordsModal/WordsModal.module.scss +8 -1
- package/src/pages/api/dictionary/[locale]/[word].ts +0 -1
- package/src/pages/api/dictionary/[locale]/index.ts +0 -1
- package/src/pages/api/solve.ts +0 -1
- package/src/pages/api/verify.ts +0 -1
- package/src/pages/api/visit.ts +0 -1
- package/src/pages/index.tsx +13 -15
- package/src/parameters/index.ts +2 -2
- package/src/state/createAppStore.ts +26 -10
- package/src/state/sagas.ts +1 -0
- package/src/state/selectors.ts +37 -37
- package/src/state/slices/boardInitialState.ts +3 -1
- package/src/state/slices/cellFilterInitialState.ts +3 -3
- package/src/state/slices/cellFilterSlice.ts +3 -1
- package/src/state/slices/dictionaryInitialState.ts +2 -2
- package/src/state/slices/rackInitialState.ts +3 -1
- package/src/state/slices/resultsInitialState.ts +11 -4
- package/src/state/slices/settingsInitialState.ts +10 -21
- package/src/state/slices/solveInitialState.ts +2 -2
- package/src/state/slices/solveSlice.ts +2 -0
- package/src/state/slices/verifyInitialState.ts +13 -4
- package/src/state/types.ts +20 -2
- package/src/styles/mixins.scss +25 -1
- package/src/styles/variables.scss +17 -1
- package/src/types/index.ts +10 -2
- package/.next/static/45ye7793DY705HOcuK9lJ/_buildManifest.js +0 -1
- package/.next/static/chunks/pages/_app-d7acee5e526752d9.js +0 -28
- package/.next/static/chunks/pages/index-35d2c1c79a201ae2.js +0 -1
- package/.next/static/css/a48caa6f57de6e98.css +0 -1
- package/.next/static/css/c49bbe944ddd1b39.css +0 -2
- package/src/components/Board/types/index.ts +0 -4
- package/src/components/Solver/components/EmptyState/index.ts +0 -1
- package/src/components/Tooltip/constants.ts +0 -28
- package/src/hooks/useUniqueId.ts +0 -9
- package/src/lib/isCtrl.ts +0 -7
- package/src/state/rootReducer.ts +0 -25
- /package/.next/static/{45ye7793DY705HOcuK9lJ → Mdvi3FY0PqkILKLbPlVBU}/_ssgManifest.js +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { FunctionComponent } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Modal } from 'components';
|
|
4
|
+
import { useTranslate } from 'state';
|
|
5
5
|
|
|
6
6
|
import { Mapping } from './components';
|
|
7
|
-
import { ARROWS, BACKSPACE,
|
|
7
|
+
import { ARROWS, BACKSPACE, DEL, ENTER, SPACE } from './keys';
|
|
8
8
|
|
|
9
9
|
interface Props {
|
|
10
10
|
className?: string;
|
|
@@ -14,7 +14,6 @@ interface Props {
|
|
|
14
14
|
|
|
15
15
|
const KeyMapModal: FunctionComponent<Props> = ({ className, isOpen, onClose }) => {
|
|
16
16
|
const translate = useTranslate();
|
|
17
|
-
const config = useTypedSelector(selectConfig);
|
|
18
17
|
|
|
19
18
|
return (
|
|
20
19
|
<Modal className={className} isOpen={isOpen} title={translate('keyMap')} onClose={onClose}>
|
|
@@ -22,26 +21,11 @@ const KeyMapModal: FunctionComponent<Props> = ({ className, isOpen, onClose }) =
|
|
|
22
21
|
<Mapping description={translate('keyMap.board-and-rack.navigate')} mapping={[ARROWS]} />
|
|
23
22
|
<Mapping description={translate('keyMap.board-and-rack.remove-tile')} mapping={[DEL, BACKSPACE]} />
|
|
24
23
|
<Mapping description={translate('keyMap.board-and-rack.submit')} mapping={[ENTER]} />
|
|
25
|
-
{config.twoCharacterTiles.length > 0 && (
|
|
26
|
-
<Mapping
|
|
27
|
-
description={translate('keyMap.board-and-rack.insert-two-letter-tile')}
|
|
28
|
-
mapping={[
|
|
29
|
-
[
|
|
30
|
-
CTRL,
|
|
31
|
-
<>
|
|
32
|
-
{config.twoCharacterTiles.map(([firstLetter]) => (
|
|
33
|
-
<Key key={firstLetter}>{firstLetter.toUpperCase()}</Key>
|
|
34
|
-
))}
|
|
35
|
-
</>,
|
|
36
|
-
],
|
|
37
|
-
]}
|
|
38
|
-
/>
|
|
39
|
-
)}
|
|
40
24
|
</Modal.Section>
|
|
41
25
|
|
|
42
26
|
<Modal.Section title={translate('keyMap.board')}>
|
|
43
|
-
<Mapping description={translate('keyMap.board.toggle-blank')} mapping={[SPACE
|
|
44
|
-
<Mapping description={translate('keyMap.board.toggle-direction')} mapping={[
|
|
27
|
+
<Mapping description={translate('keyMap.board.toggle-blank')} mapping={[SPACE]} />
|
|
28
|
+
<Mapping description={translate('keyMap.board.toggle-direction')} mapping={[ARROWS]} />
|
|
45
29
|
</Modal.Section>
|
|
46
30
|
|
|
47
31
|
<Modal.Section title={translate('keyMap.rack')}>
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
.results {
|
|
12
|
-
flex: 1;
|
|
12
|
+
flex: 1 1 auto;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
.dictionary {
|
|
16
|
-
flex: 0
|
|
16
|
+
flex: 0 1 calc(var(--dictionary--height) - var(--text-input--height));
|
|
17
17
|
background-color: var(--color--background--element);
|
|
18
18
|
border: var(--border);
|
|
19
|
-
|
|
19
|
+
border-radius: var(--border--radius);
|
|
20
20
|
|
|
21
21
|
@media (max-height: 600px) {
|
|
22
22
|
display: none;
|
|
@@ -2,14 +2,9 @@ import { Result } from '@scrabble-solver/types';
|
|
|
2
2
|
import { FunctionComponent, useMemo } from 'react';
|
|
3
3
|
import { useDispatch } from 'react-redux';
|
|
4
4
|
|
|
5
|
-
import { Dictionary, Modal, Results } from 'components';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
selectResultCandidate,
|
|
9
|
-
selectSortedFilteredResults,
|
|
10
|
-
useTranslate,
|
|
11
|
-
useTypedSelector,
|
|
12
|
-
} from 'state';
|
|
5
|
+
import { Button, Dictionary, Modal, Results } from 'components';
|
|
6
|
+
import { Check } from 'icons';
|
|
7
|
+
import { resultsSlice, selectResultCandidate, selectResults, useTranslate, useTypedSelector } from 'state';
|
|
13
8
|
|
|
14
9
|
import styles from './ResultsModal.module.scss';
|
|
15
10
|
|
|
@@ -22,9 +17,9 @@ interface Props {
|
|
|
22
17
|
const ResultsModal: FunctionComponent<Props> = ({ className, isOpen, onClose }) => {
|
|
23
18
|
const dispatch = useDispatch();
|
|
24
19
|
const translate = useTranslate();
|
|
25
|
-
const results = useTypedSelector(
|
|
20
|
+
const results = useTypedSelector(selectResults);
|
|
26
21
|
const resultCandidate = useTypedSelector(selectResultCandidate);
|
|
27
|
-
const index =
|
|
22
|
+
const index = results ? results.findIndex((result) => result.id === resultCandidate?.id) : -1;
|
|
28
23
|
const highlightedIndex = index === -1 ? undefined : index;
|
|
29
24
|
|
|
30
25
|
const callbacks = useMemo(
|
|
@@ -43,7 +38,24 @@ const ResultsModal: FunctionComponent<Props> = ({ className, isOpen, onClose })
|
|
|
43
38
|
);
|
|
44
39
|
|
|
45
40
|
return (
|
|
46
|
-
<Modal
|
|
41
|
+
<Modal
|
|
42
|
+
className={className}
|
|
43
|
+
footer={
|
|
44
|
+
<Button
|
|
45
|
+
aria-label={translate('results.insert')}
|
|
46
|
+
disabled={!resultCandidate}
|
|
47
|
+
Icon={Check}
|
|
48
|
+
tooltip={translate('results.insert')}
|
|
49
|
+
variant="primary"
|
|
50
|
+
onClick={onClose}
|
|
51
|
+
>
|
|
52
|
+
{translate('results.insert')}
|
|
53
|
+
</Button>
|
|
54
|
+
}
|
|
55
|
+
isOpen={isOpen}
|
|
56
|
+
title={translate('results')}
|
|
57
|
+
onClose={onClose}
|
|
58
|
+
>
|
|
47
59
|
<div className={styles.content}>
|
|
48
60
|
<Results callbacks={callbacks} className={styles.results} highlightedIndex={highlightedIndex} />
|
|
49
61
|
<Dictionary className={styles.dictionary} />
|
|
@@ -37,7 +37,6 @@ const dictionary = async (request: NextApiRequest, response: NextApiResponse): P
|
|
|
37
37
|
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
38
38
|
logger.error('dictionary - error', { error, meta });
|
|
39
39
|
response.status(500).send({ error: 'Server error', message });
|
|
40
|
-
throw error;
|
|
41
40
|
}
|
|
42
41
|
};
|
|
43
42
|
|
|
@@ -28,7 +28,6 @@ const dictionary = async (request: NextApiRequest, response: NextApiResponse): P
|
|
|
28
28
|
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
29
29
|
logger.error('dictionary - error', { error, meta });
|
|
30
30
|
response.status(500).send({ error: 'Server error', message });
|
|
31
|
-
throw error;
|
|
32
31
|
}
|
|
33
32
|
};
|
|
34
33
|
|
package/src/pages/api/solve.ts
CHANGED
|
@@ -42,7 +42,6 @@ const solve = async (request: NextApiRequest, response: NextApiResponse): Promis
|
|
|
42
42
|
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
43
43
|
logger.error('solve - error', { error, meta });
|
|
44
44
|
response.status(500).send({ error: 'Server error', message });
|
|
45
|
-
throw error;
|
|
46
45
|
}
|
|
47
46
|
};
|
|
48
47
|
|
package/src/pages/api/verify.ts
CHANGED
|
@@ -38,7 +38,6 @@ const verify = async (request: NextApiRequest, response: NextApiResponse): Promi
|
|
|
38
38
|
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
39
39
|
logger.error('verify - error', { error, meta });
|
|
40
40
|
response.status(500).send({ error: 'Server error', message });
|
|
41
|
-
throw error;
|
|
42
41
|
}
|
|
43
42
|
};
|
|
44
43
|
|
package/src/pages/api/visit.ts
CHANGED
|
@@ -13,7 +13,6 @@ const visit = async (request: NextApiRequest, response: NextApiResponse): Promis
|
|
|
13
13
|
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
14
14
|
logger.error('visit - error', { error, meta });
|
|
15
15
|
response.status(500).send({ error: 'Server error', message });
|
|
16
|
-
throw error;
|
|
17
16
|
}
|
|
18
17
|
};
|
|
19
18
|
|
package/src/pages/index.tsx
CHANGED
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
SettingsModal,
|
|
19
19
|
WordsModal,
|
|
20
20
|
} from 'modals';
|
|
21
|
-
import { INITIALIZATION_DURATION } from 'parameters';
|
|
22
21
|
import { registerServiceWorker } from 'serviceWorkerManager';
|
|
23
22
|
import { initialize, reset, selectLocale, useTypedSelector } from 'state';
|
|
24
23
|
|
|
@@ -44,7 +43,7 @@ const Index: FunctionComponent<Props> = ({ version }) => {
|
|
|
44
43
|
const [showWords, setShowWords] = useState(false);
|
|
45
44
|
const [isInitialized, setIsInitialized] = useState(false);
|
|
46
45
|
const [indexRef, { height: indexHeight, width: indexWidth }] = useMeasure<HTMLDivElement>();
|
|
47
|
-
const [navRef, { height: navHeight }] = useMeasure<
|
|
46
|
+
const [navRef, { height: navHeight }] = useMeasure<HTMLElement>();
|
|
48
47
|
const solverHeight = indexHeight - navHeight;
|
|
49
48
|
const solverWidth = indexWidth;
|
|
50
49
|
const [isClient, setIsClient] = useState(false);
|
|
@@ -60,10 +59,7 @@ const Index: FunctionComponent<Props> = ({ version }) => {
|
|
|
60
59
|
useEffectOnce(() => {
|
|
61
60
|
setIsClient(true);
|
|
62
61
|
dispatch(initialize());
|
|
63
|
-
|
|
64
|
-
globalThis.setTimeout(() => {
|
|
65
|
-
setIsInitialized(true);
|
|
66
|
-
}, INITIALIZATION_DURATION);
|
|
62
|
+
setIsInitialized(true);
|
|
67
63
|
});
|
|
68
64
|
|
|
69
65
|
useEffect(() => {
|
|
@@ -87,7 +83,7 @@ const Index: FunctionComponent<Props> = ({ version }) => {
|
|
|
87
83
|
<SvgFontFix />
|
|
88
84
|
|
|
89
85
|
<div className={classNames(styles.index, { [styles.initialized]: isInitialized })} ref={indexRef}>
|
|
90
|
-
<
|
|
86
|
+
<nav className={styles.nav} ref={navRef}>
|
|
91
87
|
<div className={styles.navContent}>
|
|
92
88
|
<div className={styles.navLogo}>
|
|
93
89
|
<a className={styles.logoContainer} href="/" title={version}>
|
|
@@ -104,14 +100,16 @@ const Index: FunctionComponent<Props> = ({ version }) => {
|
|
|
104
100
|
onShowWords={() => setShowWords(true)}
|
|
105
101
|
/>
|
|
106
102
|
</div>
|
|
107
|
-
</
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
103
|
+
</nav>
|
|
104
|
+
|
|
105
|
+
{solverHeight > 0 && solverWidth > 0 && (
|
|
106
|
+
<Solver
|
|
107
|
+
className={styles.solver}
|
|
108
|
+
height={solverHeight}
|
|
109
|
+
width={solverWidth}
|
|
110
|
+
onShowResults={() => setShowResults(true)}
|
|
111
|
+
/>
|
|
112
|
+
)}
|
|
115
113
|
</div>
|
|
116
114
|
|
|
117
115
|
<MenuModal
|
package/src/parameters/index.ts
CHANGED
|
@@ -11,8 +11,6 @@ export const TRANSITION = 'var(--transition)';
|
|
|
11
11
|
|
|
12
12
|
export const GITHUB_PROJECT_URL = 'https://github.com/kamilmielnik/scrabble-solver';
|
|
13
13
|
|
|
14
|
-
export const INITIALIZATION_DURATION = 100;
|
|
15
|
-
|
|
16
14
|
export const TRANSITION_DURATION = 100;
|
|
17
15
|
export const TRANSITION_DURATION_LONG = 250;
|
|
18
16
|
|
|
@@ -71,6 +69,8 @@ export const REMAINING_TILES_TILE_SIZE = 50;
|
|
|
71
69
|
|
|
72
70
|
export const RESULTS_ITEM_HEIGHT = 40;
|
|
73
71
|
|
|
72
|
+
export const SOLVER_COLUMN_WIDTH = 580;
|
|
73
|
+
|
|
74
74
|
export const TILE_APPEAR_DURATION = 200;
|
|
75
75
|
|
|
76
76
|
export const TILE_APPEAR_KEYFRAMES = [
|
|
@@ -1,21 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { configureStore } from '@reduxjs/toolkit';
|
|
2
2
|
import reduxSaga from 'redux-saga';
|
|
3
3
|
|
|
4
|
-
import rootReducer from './rootReducer';
|
|
5
4
|
import { rootSaga } from './sagas';
|
|
6
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
boardSlice,
|
|
7
|
+
cellFilterSlice,
|
|
8
|
+
dictionarySlice,
|
|
9
|
+
rackSlice,
|
|
10
|
+
resultsSlice,
|
|
11
|
+
settingsSlice,
|
|
12
|
+
solveSlice,
|
|
13
|
+
verifySlice,
|
|
14
|
+
} from './slices';
|
|
7
15
|
|
|
8
16
|
const sagaMiddleware = reduxSaga();
|
|
9
|
-
const initialState: Partial<RootState> | undefined = undefined;
|
|
10
17
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
const createAppStore = () => {
|
|
19
|
+
const store = configureStore({
|
|
20
|
+
reducer: {
|
|
21
|
+
board: boardSlice.reducer,
|
|
22
|
+
cellFilter: cellFilterSlice.reducer,
|
|
23
|
+
dictionary: dictionarySlice.reducer,
|
|
24
|
+
rack: rackSlice.reducer,
|
|
25
|
+
results: resultsSlice.reducer,
|
|
26
|
+
settings: settingsSlice.reducer,
|
|
27
|
+
solve: solveSlice.reducer,
|
|
28
|
+
verify: verifySlice.reducer,
|
|
29
|
+
},
|
|
30
|
+
middleware: [sagaMiddleware],
|
|
31
|
+
});
|
|
15
32
|
|
|
16
|
-
const createAppStore = (): ReturnType<typeof createStore> => {
|
|
17
|
-
const store = createStore(rootReducer, initialState, composeEnhancers(applyMiddleware(sagaMiddleware)));
|
|
18
33
|
sagaMiddleware.run(rootSaga);
|
|
34
|
+
|
|
19
35
|
return store;
|
|
20
36
|
};
|
|
21
37
|
|
package/src/state/sagas.ts
CHANGED
|
@@ -116,6 +116,7 @@ function* onReset(): AnyGenerator {
|
|
|
116
116
|
yield put(dictionarySlice.actions.reset());
|
|
117
117
|
yield put(rackSlice.actions.reset());
|
|
118
118
|
yield put(resultsSlice.actions.reset());
|
|
119
|
+
yield put(solveSlice.actions.reset());
|
|
119
120
|
yield put(verifySlice.actions.submit());
|
|
120
121
|
}
|
|
121
122
|
|
package/src/state/selectors.ts
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
|
+
/* eslint-disable max-lines */
|
|
2
|
+
|
|
1
3
|
import { createSelector } from '@reduxjs/toolkit';
|
|
2
4
|
import { getLocaleConfig } from '@scrabble-solver/configs';
|
|
3
5
|
import { BLANK } from '@scrabble-solver/constants';
|
|
4
|
-
import { Cell, Config, isError,
|
|
6
|
+
import { Cell, Config, isError, Tile } from '@scrabble-solver/types';
|
|
5
7
|
|
|
6
8
|
import i18n, { LOCALE_FEATURES } from 'i18n';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
+
import {
|
|
10
|
+
createRegExp,
|
|
11
|
+
findCell,
|
|
12
|
+
getRemainingTiles,
|
|
13
|
+
getRemainingTilesGroups,
|
|
14
|
+
groupResults,
|
|
15
|
+
sortResults,
|
|
16
|
+
unorderedArraysEqual,
|
|
17
|
+
} from 'lib';
|
|
18
|
+
import { Point, Translations } from 'types';
|
|
9
19
|
|
|
10
20
|
import { RootState } from './types';
|
|
11
21
|
|
|
12
22
|
const selectCell = (_: unknown, cell: Cell): Cell => cell;
|
|
13
23
|
|
|
14
|
-
const selectPoint = (_: unknown, point:
|
|
24
|
+
const selectPoint = (_: unknown, point: Point): Point => point;
|
|
25
|
+
|
|
26
|
+
const selectResultIndex = (_: unknown, index: number): number => index;
|
|
15
27
|
|
|
16
28
|
const selectCharacter = (_: unknown, character: string | null): string | null => character;
|
|
17
29
|
|
|
@@ -71,54 +83,42 @@ export const selectCellIsValid = createSelector([selectConfig, selectCell], (con
|
|
|
71
83
|
return config.tiles.some((tile) => tile.character === cell.tile.character);
|
|
72
84
|
});
|
|
73
85
|
|
|
74
|
-
export const
|
|
86
|
+
export const selectResultsRaw = createSelector([selectResultsRoot], (results) => results.results);
|
|
75
87
|
|
|
76
88
|
export const selectResultsQuery = createSelector([selectResultsRoot], (results) => results.query);
|
|
77
89
|
|
|
78
|
-
export const
|
|
90
|
+
export const selectResultsSort = createSelector([selectResultsRoot], (results) => results.sort);
|
|
79
91
|
|
|
80
|
-
export const
|
|
92
|
+
export const selectSortedResults = createSelector([selectResultsRaw, selectResultsSort, selectLocale], sortResults);
|
|
81
93
|
|
|
82
|
-
export const
|
|
83
|
-
[
|
|
84
|
-
|
|
94
|
+
export const selectGroupedResults = createSelector(
|
|
95
|
+
[selectSortedResults, selectResultsQuery, selectCellFilter],
|
|
96
|
+
groupResults,
|
|
85
97
|
);
|
|
86
98
|
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
let regExp: RegExp | undefined;
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
regExp = new RegExp(query, 'gi');
|
|
96
|
-
} catch {
|
|
97
|
-
return results;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return results.filter((result) => {
|
|
101
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
102
|
-
return regExp!.test(result.word);
|
|
103
|
-
});
|
|
104
|
-
};
|
|
99
|
+
export const selectResults = createSelector([selectGroupedResults], (groupedResults) => {
|
|
100
|
+
return groupedResults ? [...groupedResults.matching, ...groupedResults.other] : groupedResults;
|
|
101
|
+
});
|
|
105
102
|
|
|
106
|
-
export const
|
|
107
|
-
[
|
|
108
|
-
(results, query, cellFilter) => {
|
|
103
|
+
export const selectIsResultMatching = createSelector(
|
|
104
|
+
[selectResults, selectResultsQuery, selectCellFilter, selectResultIndex],
|
|
105
|
+
(results, query, cellFilter, index) => {
|
|
109
106
|
if (!results) {
|
|
110
|
-
return
|
|
107
|
+
return false;
|
|
111
108
|
}
|
|
112
109
|
|
|
113
|
-
const
|
|
110
|
+
const result = results[index];
|
|
111
|
+
const regExp = createRegExp(query);
|
|
114
112
|
|
|
115
|
-
if (!
|
|
116
|
-
return
|
|
113
|
+
if (!regExp.test(result.word)) {
|
|
114
|
+
return false;
|
|
117
115
|
}
|
|
118
116
|
|
|
119
|
-
|
|
117
|
+
if (cellFilter) {
|
|
120
118
|
return cellFilter.every(({ x, y }) => result.cells.some((cell) => cell.x === x && cell.y === y));
|
|
121
|
-
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return true;
|
|
122
122
|
},
|
|
123
123
|
);
|
|
124
124
|
|
|
@@ -3,9 +3,11 @@ import { Board } from '@scrabble-solver/types';
|
|
|
3
3
|
|
|
4
4
|
import settingsInitialState from './settingsInitialState';
|
|
5
5
|
|
|
6
|
+
export type BoardState = Board;
|
|
7
|
+
|
|
6
8
|
const { configId, locale } = settingsInitialState;
|
|
7
9
|
const { boardHeight, boardWidth } = getLocaleConfig(configId, locale);
|
|
8
|
-
const boardInitialState:
|
|
10
|
+
const boardInitialState: BoardState = Board.create(boardWidth, boardHeight);
|
|
9
11
|
|
|
10
12
|
// const createOxyphenbutazone = () => {
|
|
11
13
|
// // Tiles: oypbaze
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Point } from 'types';
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type CellFilterState = Point[];
|
|
4
4
|
|
|
5
|
-
const cellFilterInitialState:
|
|
5
|
+
const cellFilterInitialState: CellFilterState = [];
|
|
6
6
|
|
|
7
7
|
export default cellFilterInitialState;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { Point } from 'types';
|
|
4
|
+
|
|
5
|
+
import cellFilterInitialState from './cellFilterInitialState';
|
|
4
6
|
|
|
5
7
|
const cellFilterSlice = createSlice({
|
|
6
8
|
initialState: cellFilterInitialState,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { WordDefinition } from '@scrabble-solver/types';
|
|
2
2
|
|
|
3
|
-
interface
|
|
3
|
+
export interface DictionaryState {
|
|
4
4
|
error: unknown | undefined;
|
|
5
5
|
input: string;
|
|
6
6
|
isLoading: boolean;
|
|
7
7
|
results: WordDefinition[];
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
const dictionaryInitialState:
|
|
10
|
+
const dictionaryInitialState: DictionaryState = {
|
|
11
11
|
error: undefined,
|
|
12
12
|
input: '',
|
|
13
13
|
isLoading: false,
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { Result } from '@scrabble-solver/types';
|
|
2
2
|
|
|
3
|
-
import { ResultColumn, SortDirection } from 'types';
|
|
3
|
+
import { ResultColumn, Sort, SortDirection } from 'types';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
candidate:
|
|
5
|
+
export interface ResultsState {
|
|
6
|
+
candidate: Result | null;
|
|
7
|
+
query: string;
|
|
8
|
+
results: Result[] | undefined;
|
|
9
|
+
sort: Sort;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const resultsInitialState: ResultsState = {
|
|
13
|
+
candidate: null,
|
|
7
14
|
query: '',
|
|
8
|
-
results: undefined
|
|
15
|
+
results: undefined,
|
|
9
16
|
sort: {
|
|
10
17
|
column: ResultColumn.Points,
|
|
11
18
|
direction: SortDirection.Descending,
|
|
@@ -1,29 +1,18 @@
|
|
|
1
|
-
import { scrabble } from '@scrabble-solver/configs';
|
|
1
|
+
import { literaki, scrabble } from '@scrabble-solver/configs';
|
|
2
2
|
import { Locale } from '@scrabble-solver/types';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
if (!globalThis.navigator) {
|
|
6
|
-
return Locale.EN_US;
|
|
7
|
-
}
|
|
4
|
+
import { guessLocale } from 'lib';
|
|
8
5
|
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
export interface SettingsState {
|
|
7
|
+
autoGroupTiles: 'left' | 'right' | null;
|
|
8
|
+
configId: typeof literaki.id | typeof scrabble.id;
|
|
9
|
+
locale: Locale;
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const partialMatch = locales.find((locale) => {
|
|
17
|
-
return globalThis.navigator.language === locale.substring(0, 2);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
return partialMatch || Locale.EN_US;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const settingsInitialState = {
|
|
24
|
-
autoGroupTiles: 'left' as 'left' | 'right' | null,
|
|
12
|
+
const settingsInitialState: SettingsState = {
|
|
13
|
+
autoGroupTiles: 'left',
|
|
25
14
|
configId: scrabble.id,
|
|
26
|
-
locale:
|
|
15
|
+
locale: guessLocale(),
|
|
27
16
|
};
|
|
28
17
|
|
|
29
18
|
export default settingsInitialState;
|
|
@@ -2,7 +2,7 @@ import { Board } from '@scrabble-solver/types';
|
|
|
2
2
|
|
|
3
3
|
import boardInitialState from './boardInitialState';
|
|
4
4
|
|
|
5
|
-
interface
|
|
5
|
+
export interface SolveState {
|
|
6
6
|
error: unknown | undefined;
|
|
7
7
|
isLoading: boolean;
|
|
8
8
|
lastSolvedParameters: {
|
|
@@ -11,7 +11,7 @@ interface SolveInitialState {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const solveInitialState:
|
|
14
|
+
const solveInitialState: SolveState = {
|
|
15
15
|
error: undefined,
|
|
16
16
|
isLoading: false,
|
|
17
17
|
lastSolvedParameters: {
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import boardInitialState from './boardInitialState';
|
|
1
|
+
import boardInitialState, { BoardState } from './boardInitialState';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export interface VerifyState {
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
lastSolvedParameters: {
|
|
6
|
+
board: BoardState;
|
|
7
|
+
};
|
|
8
|
+
invalidWords: string[];
|
|
9
|
+
validWords: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const verifyInitialState: VerifyState = {
|
|
4
13
|
isLoading: false,
|
|
5
14
|
lastSolvedParameters: {
|
|
6
15
|
board: boardInitialState,
|
|
7
16
|
},
|
|
8
|
-
invalidWords: []
|
|
9
|
-
validWords: []
|
|
17
|
+
invalidWords: [],
|
|
18
|
+
validWords: [],
|
|
10
19
|
};
|
|
11
20
|
|
|
12
21
|
export default verifyInitialState;
|