-
-
Notifications
You must be signed in to change notification settings - Fork 6
Vanilla state management for language chooser #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gmjgeek
wants to merge
54
commits into
sillsdev:main
Choose a base branch
from
gmjgeek:ui-controller
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
126fa14
Create project
3f3fc14
Select language card
214689a
Select and deselect scripts
378771c
Refactor state management
4be8195
Add unique IDs to view models
83f8477
Create language chooser view model
90e446e
Adds tag preview
99e9fb0
Adds display name
d8a6812
Add search text
568c57b
Make language and script lists reactive
f9303aa
Clear search results
c9cf4c2
Correct tag preview when no language selected
decb47f
Expose selected script and language
0713fdb
Automatically select a language's only script
e938459
Allow creating unlisted language
47d8025
Add cases for clearing selections
7c69a21
Improve a method signature
2398017
Allow customizing selected language
3450b50
Allow entering custom language tag
4957ef1
Refine Field API
8abe0f2
Add isReadyToSubmit
8afe6cd
Refactor for clarity
6eab6bb
Separate state management into new project
764f102
Add state-management-svelte project
fa4d014
Remove unused import
c5702e9
Implement useViewModel for Svelte 5
c7de333
Make Field.onUpdate explicitly public
d7994aa
Refactor selectItem for clarity
ccca4dc
Add a blank Svelte 5 project
gmjgeek dbc7080
Install DaisyUI for svelte app
c7db596
Rename svelte demo project
c825c2a
Delete unused files
b6edcc8
Scaffold UI for Svelte demo app
e9cf2f0
Use view model in Svelte demo app
d3f72ff
Implement more UI elements
dc673a2
Return selected language from modal
a33f054
Implement customization modal
3bee4a1
Add a temporary hack for customization modal
5f45264
Refactor svelte state management
a202cd8
Update view model to new convention
9faaf84
Fix svelte demo app
0d9b03e
Update language and script card view models
cd3ae96
Correctly populate customization modal
1fcdfd5
Add help text to customize modal
23b96ad
Add icon attribution
7984152
Add prompt for custom language tag
dd38de0
Allow customize button to edit custom tag
cc386dc
Scroll to selected language
1233ed3
Undo accidental change
c359839
Add state management documentation
7a829c5
Rename svelte demo app
dcf16d8
Adds unit tests
50ca793
Fix configuration errors
969e658
Highlight search results
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| { | ||
| "recommendations": ["ms-playwright.playwright"] | ||
| "recommendations": ["ms-playwright.playwright", "esbenp.prettier-vscode"] | ||
| } |
4 changes: 4 additions & 0 deletions
4
components/language-chooser/common/language-chooser-controller/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export * from "./src/view-models/language-card"; | ||
| export * from "./src/view-models/script-card"; | ||
| export * from "./src/view-models/language-chooser"; | ||
| export * from "./src/highlight"; |
25 changes: 25 additions & 0 deletions
25
components/language-chooser/common/language-chooser-controller/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "name": "@ethnolib/language-chooser-controller", | ||
| "description": "A framework-agnostic controller for a language chooser", | ||
| "author": "SIL Global", | ||
| "license": "MIT", | ||
| "version": "0.1.0", | ||
| "main": "./index.js", | ||
| "types": "./index.d.ts", | ||
| "scripts": { | ||
| "build": "nx vite:build", | ||
| "typecheck": "tsc", | ||
| "test": "nx vite:test --config vitest.config.ts", | ||
| "testonce": "nx vite:test --config vitest.config.ts --run", | ||
| "lint": "eslint ." | ||
| }, | ||
| "devDependencies": { | ||
| "@nx/vite": "^19.1.2", | ||
| "@types/node": "^20.16.11", | ||
| "tsx": "^4.19.2", | ||
| "typescript": "^5.2.2" | ||
| }, | ||
| "volta": { | ||
| "extends": "../../../../package.json" | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
components/language-chooser/common/language-chooser-controller/src/highlight.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| export interface FormattedText { | ||
| text: string; | ||
| isHighlighted: boolean; | ||
| } | ||
|
|
||
| export function highlightMatches( | ||
| matchWith: string, | ||
| text: string | ||
| ): FormattedText[] { | ||
| if (text === "") { | ||
| return []; | ||
| } | ||
|
|
||
| if (matchWith === "") { | ||
| return [{ text, isHighlighted: false }]; | ||
| } | ||
|
|
||
| // Escape special regex characters and split while capturing the delimiter | ||
| const escapedMatch = matchWith.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); | ||
| const regex = new RegExp(`(${escapedMatch})`, "gi"); | ||
|
|
||
| return text | ||
| .split(regex) | ||
| .map((segment, index) => ({ | ||
| text: segment, | ||
| isHighlighted: index % 2 === 1, // Odd indices are the captured matches | ||
| })) | ||
| .filter((x) => x.text); | ||
| } |
11 changes: 11 additions & 0 deletions
11
components/language-chooser/common/language-chooser-controller/src/selectable.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { Field } from "@ethnolib/state-management-core"; | ||
|
|
||
| export interface Selectable { | ||
| isSelected: Field<boolean>; | ||
| } | ||
|
|
||
| export function selectItem(index: number, items: Selectable[]) { | ||
| items.forEach((item, i) => { | ||
| item.isSelected.value = i === index; | ||
| }); | ||
| } |
52 changes: 52 additions & 0 deletions
52
...ents/language-chooser/common/language-chooser-controller/src/view-models/language-card.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,52 @@ | ||||||||||||||||||
| import { ILanguage } from "@ethnolib/find-language"; | ||||||||||||||||||
| import { Field } from "@ethnolib/state-management-core"; | ||||||||||||||||||
|
|
||||||||||||||||||
| interface ViewModelArgs { | ||||||||||||||||||
| onSelect?: (isSelected: boolean) => void; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| export type LanguageCardViewModel = ReturnType< | ||||||||||||||||||
| typeof useLanguageChardViewModel | ||||||||||||||||||
| >; | ||||||||||||||||||
|
|
||||||||||||||||||
| export function useLanguageChardViewModel( | ||||||||||||||||||
|
Comment on lines
+9
to
+12
|
||||||||||||||||||
| typeof useLanguageChardViewModel | |
| >; | |
| export function useLanguageChardViewModel( | |
| typeof useLanguageCardViewModel | |
| >; | |
| export function useLanguageCardViewModel( |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing dependencies: The package depends on "@ethnolib/find-language" and "@ethnolib/state-management-core" but these are not listed in the dependencies or devDependencies. Add them to ensure the package can be properly installed and used.