Coder Social home page Coder Social logo

t-blackwell / mycrossword Goto Github PK

View Code? Open in Web Editor NEW
13.0 13.0 10.0 833 KB

React crossword component

Home Page: https://mycrossword.co.uk/

License: MIT License

JavaScript 0.43% HTML 0.62% TypeScript 90.74% SCSS 7.60% Dockerfile 0.35% CSS 0.26%
crossword crosswords grid react

mycrossword's People

Contributors

andrew-nowak avatar hood avatar t-blackwell avatar tblackwell-tm avatar zetter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mycrossword's Issues

SSR responsive issues

When using a framework that supports SSR, say Remix, the initial render does not display particularly well. The reason for this is because the MyCrossword component makes use of the useBreakpoint hook, and all of the responsive CSS code is built on top of it. Therefore the relevant media queries only work with CSR i.e. after hydration.

Display clue markup

React escapes HTML by default. There needs to be a way to show markup in the Clue and StickyClue components. The display should be limited to specific tags:

  • <b> or <strong>
  • <i> or <em>
  • <u>
  • <sub>
  • <sup>
  • plus others?

`react` version in `peerDeps` is downgradable to v16

Hi, I’m successfully using this library in a React16 project at work, but since bumping my npm version my dependencies are subject to stricter peerDependencies checks, and this library fails them by pinning react at version 17 in its peerDependencies, despite it not using any features exclusively available from 17+. I think it’d be safer to pin react to version 17 in the peer dependencies.

Use NVM

Confirm the correct node version to use and include it in an NVM config file.

New onComplete prop

When a puzzle has been filled it would be good to have an onComplete prop to allow the developer to run a function e.g. to show a message.

Update documentation

Update README with overview and examples. It would also be useful generate another markdown doc to show the functional benefits and technical improvements when compared to the Guardian component.

Intro message

There should be a mechanism to allow setters to display a message at the start of a crossword. This message should overlay the grid area and prevent the puzzle from being started until it's been acknowledged. One thing to bear in mind is that this function should be designed in a way to allow adverts (image or video) to be displayed in the future.

SSR grid loading state

When the initial render (SSR) happens, the grid is put into a loading state. This is most likely due to it needing access to localStorage to display the user's progress. Consider useLocalStorage hook with initializeWithValue prop set to false.

Anagram helper input focus

When pressing the enter key in the anagram helper input on mobile*, it results in a focus switch i.e. moves to the next available input.

*Pixel 7 / Android 14 / Chrome 122.0.6261.119

Guesses grid is initialised with the wrong dimensions

Unfortunately I’ve just found out that the guesses grid is initialised with the wrong dimensions for non-square puzzles.

The guesses grid is currently built as a rowsXcols matrix:

export function initialiseGuessGrid(
  cols: number,
  rows: number,
  char: string = '',
) {
  const grid: GuessGrid = {
    value: new Array(rows).fill(char).map(() => new Array(cols).fill(char)),
  };
  return grid;
}

whereas everywhere else in the codebase we work with a colsXrows matrix:

export function validateGuessGrid(
  guessGrid: GuessGrid,
  cols: number,
  rows: number,
  cellMatcher: RegExp,
) {
  // ...

  for (let i = 0; i < cols; i += 1) {
    for (let j = 0; j < rows; j += 1) {
      const cell = guessGrid.value[i][j];
      if (cell !== '' && !isValidChar(cell, cellMatcher)) {
        return false;
      }
    }
  }

  // ...
}

This breaks initialisation for non-square puzzle matrices.

Allow missing solutions

The strict validation currently in place means that you can only use data for a complete grid i.e. all of the solution props have been populated. There are scenarios where it would be useful to allow an incomplete grid to be displayed. The validation logic could be driven by a prop e.g. allowMissingSolutions, which would default to false.

Highlight cells on check

When checking solutions in the grid, it's not obvious if the characters are correct. Currently if the characters aren't removed it means the cells are correct. This would be clearer if the cells were highlighted in some way e.g. green and red for a few seconds.

Vite

Move build over to use Vite. Also, improve import paths.

Previous/next clue

It would be nice to have previous and next arrows on the sticky clue component to allow users to cycle through the clues when on mobile devices.

Interactive prop

By default the grid should be interactive but there are some use cases where it's useful to make the entire component read-only. Therefore a new optional interactive prop could be added which would be defaulted to true to satisfy the majority of the cases.

Add missing props

The onCellChange prop needs to be added to the Controls component and called when invoking the menu functions. There also needs to be a onCellFocus prop added to MyCrossword that's called whenever a cell receives focus via a cell or clue selection.

Linting

Add ESLint for TS with the AirBnB ruleset.

WordWheel shape

The anagram helper word wheel shape becomes oval when the screen width is too narrow to display a circle.

Scrolling Issue

If you press the vertical arrow keys to switch cell when the grid has been scrolled such that the top row is above the viewport, it scrolls the entire page.

mycrossword_scroll_issue
☝️ Example of holding down ArrowDown and scrolling downwards on the mouse.

I've tried playing around with different combinations of tabindex, preventDefault(), stopPropagation() and focus({ preventScroll: true }) but haven't made any progress.

Send help!

Anagram characters

In the anagram helper, you can click on the words in the clue to enter them into the text input. The words are split by non-alpha characters like hyphens, spaces and apostrophes. Unfortunately this means characters with accents also split words. Where possible these characters should be translated to their A-Z equivalent.

URI fragment history

When changing clues, the URI fragment is updated. This should not append an entry to the browser's history but overwrite the existing one.

Anagram helper

The anagram helper component needs to be created. It should be largely analogous to the original Guardian version with a few changes:

  • the cells should be editable
  • it should show how many characters you're over or under by e.g. 8/11
  • it should have a central letter in the word wheel
  • put letters in squares - give it a scrabble tile feel
  • nice to have: click words to add them to the fodder
  • nice to have: shuffle animations - nothing naff though

Accessibility mode

There needs to be an accessible version of the crossword component for people using screen readers. The Guardian provide an accessible version but it's not currently interactive. I think this could be improved upon by having the cells inline with the clues, something like this perhaps...

image

Window scroll on cell focus

When typing in a letter, the cell switches focus and this causes the window to scroll to ensure it's in the viewport. This issue is most prominent when entering a solution to a long, down clue.

Edit: this seems to be a problem with the window having focus.

mycrossword + Exolve?

I think mycrossword.co.uk is awesome!

You've clearly put a lot of good effort into the solver interface (https://github.com/t-blackwell/mycrossword). I should know, because I have put in a lot of effort doing similar things in Exolve (https://github.com/viresh-ratnakar/exolve) :-).

I think it is totally fine to have such multiple efforts go on in parallel, occasionally picking up ideas from each other. Both the projects are open-source, which is great.

We should at least briefly and periodically consider the possibility of collaborating, imo.

I think Exolve can easily be a snap-in infrastructure that can be used to do the interactive solving part in mycrossword. I'm not sure if you've looked at the Exolve format, but it is a pretty simple plaintext format. And it supports loads of tiny and big features that are currently not there in mycrossword (afaik). A few examples:

  • Clue numbers are right-aligned and formatted as in a newspaper, including when there are linked clues
  • 3-d crosswords.
  • Barred grids, diagramless squares, circles, colours, ninas.
  • Creating 2- or 3-column PDFs formatted similar to newspapers.
  • Annotations that can be revealed inline within clues.
  • Arbitrary languages.
  • Taking notes on the crossword (overall/per-clue) to be provided as feedback (I use this extensively when test-solving)
  • Support for an accessibility interface ("webifi") that is text-only and can be used with audio.
  • Non-numeric clue labels
  • Automatic conversion of just the text of the clues to a solvable grid (i.e., automatic inference of the grid)

You can experiment with the idea by simply adding support for Exolve-based puzzles in addition to the current interface. I can help with coding the changes if needed. Exolve can be easily customized to any look-and-feel.

And of course, along similar lines, Exet can be used for powering the construction interface, but we can discuss that separately/later (unless that intrigues you more).

Cheers,
Viresh 

Validate clue.group

A clue's group isn't currently being validated. The following conditions need to be checked as part of the initialiseCells util:

  • group cannot be empty
  • if group length is 1 then it must match the clue id
  • if group length is greater than 1 then the clue id must appear in the array
  • all group ids must be valid i.e. appear as an entry in the data

Clues overlapping grid on iOS

image

iOS: 9.3.5
Safari: 9? (TBC)

It looks like there are some CSS styles that don't play well with older versions of Safari. Without the means to reproduce the issue this is going to be very difficult to resolve.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.