-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for appearances (and body classes)
Automated testing is pending. Some manual validation has been done to verify that this likely works as intended. The intent is to make this first pass available for client iteration as quickly as possible. While it’s possible to include unit tests for `TokenListParser`, it seems more likely we’ll want to add integration tests in the `scenario` package. Given there’s a ton of unaddressed feedback in #110, it seems most prudent to get this into draft first, and bring in integration tests once that lands.
- Loading branch information
1 parent
8d33847
commit 2807d7e
Showing
33 changed files
with
507 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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,27 @@ | ||
/** | ||
* Produces a `string` type while preserving autocomplete/autosuggest | ||
* functionality for a known string (union). | ||
* | ||
* @see {@link https://www.totaltypescript.com/tips/create-autocomplete-helper-which-allows-for-arbitrary-values} | ||
* | ||
* @example | ||
* ```ts | ||
* let foo: PartiallyKnownString<'a' | 'b' | 'zed'>; | ||
* | ||
* // Each of these will be suggested by a TypeScript-supporting editor: | ||
* foo = 'a'; | ||
* foo = 'b'; | ||
* foo = 'zed'; | ||
* | ||
* // ... but any string is valid: | ||
* foo = 'lmnop'; | ||
* ``` | ||
*/ | ||
// prettier-ignore | ||
export type PartiallyKnownString<Known extends string> = | ||
[string] extends [Known] | ||
? string | ||
: ( | ||
| Known | ||
| (string & { /* Type hack! */ }) | ||
); |
This file contains 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
This file contains 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
39 changes: 39 additions & 0 deletions
39
packages/xforms-engine/src/body/appearance/inputAppearanceParser.ts
This file contains 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,39 @@ | ||
import { TokenListParser, type ParsedTokenList } from '../../lib/TokenListParser.ts'; | ||
|
||
export const inputAppearanceParser = new TokenListParser([ | ||
'multiline', | ||
'numbers', | ||
'url', | ||
'thousand-sep', | ||
|
||
// date (TODO: data types) | ||
'no-calendar', | ||
'month-year', | ||
'year', | ||
// date > calendars | ||
'ethiopian', | ||
'coptic', | ||
'islamic', | ||
'bikram-sambat', | ||
'myanmar', | ||
'persian', | ||
|
||
// geo (TODO: data types) | ||
'placement-map', | ||
'maps', | ||
|
||
// image/media (TODO: move to eventual `<upload>`?) | ||
'hidden-answer', | ||
'annotate', | ||
'draw', | ||
'signature', | ||
'new-front', | ||
'new', | ||
'front', | ||
|
||
// *? | ||
'printer', // Note: actual usage uses `printer:...` (like `ex:...`). | ||
'masked', | ||
]); | ||
|
||
export type InputAppearanceDefinition = ParsedTokenList<typeof inputAppearanceParser>; |
38 changes: 38 additions & 0 deletions
38
packages/xforms-engine/src/body/appearance/selectAppearanceParser.ts
This file contains 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,38 @@ | ||
import { TokenListParser, type ParsedTokenList } from '../../lib/TokenListParser.ts'; | ||
|
||
export const selectAppearanceParser = new TokenListParser( | ||
[ | ||
// From XLSForm Docs: | ||
'compact', | ||
'horizontal', | ||
'horizontal-compact', | ||
'label', | ||
'list-nolabel', | ||
'minimal', | ||
|
||
// From Collect `Appearances.kt`: | ||
'columns', | ||
'columns-1', | ||
'columns-2', | ||
'columns-3', | ||
'columns-4', | ||
'columns-5', | ||
// Note: Collect supports arbitrary columns-n. Technically we do too (we parse | ||
// out any appearance, not just those we know about). But we'll only include | ||
// types/defaults up to 5. | ||
'columns-pack', | ||
'autocomplete', | ||
|
||
// TODO: these are `<select1>` only | ||
'likert', | ||
'quick', | ||
'quickcompact', | ||
'map', | ||
// "quick map" | ||
], | ||
{ | ||
aliases: [{ fromAlias: 'search', toCanonical: 'autocomplete' }], | ||
} | ||
); | ||
|
||
export type SelectAppearanceDefinition = ParsedTokenList<typeof selectAppearanceParser>; |
7 changes: 7 additions & 0 deletions
7
packages/xforms-engine/src/body/appearance/structureElementAppearanceParser.ts
This file contains 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,7 @@ | ||
import { TokenListParser, type ParsedTokenList } from '../../lib/TokenListParser.ts'; | ||
|
||
export const structureElementAppearanceParser = new TokenListParser(['field-list', 'table-list']); | ||
|
||
export type StructureElementAppearanceDefinition = ParsedTokenList< | ||
typeof structureElementAppearanceParser | ||
>; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.