govuk_publishing_components 58.1.0 → 58.2.0
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.
- checksums.yaml +4 -4
- data/app/assets/images/select-with-search/cross-icon.svg +6 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-search-tracker.js +4 -0
- data/app/assets/javascripts/govuk_publishing_components/components/select-with-search.js +57 -0
- data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss +7 -2
- data/app/assets/stylesheets/govuk_publishing_components/components/_select-with-search.scss +168 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_select.scss +6 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_contact.scss +10 -10
- data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_typography.scss +3 -16
- data/app/views/govuk_publishing_components/components/_add_another.html.erb +0 -1
- data/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_select.html.erb +22 -23
- data/app/views/govuk_publishing_components/components/_select_with_search.html.erb +14 -0
- data/app/views/govuk_publishing_components/components/docs/select.yml +11 -0
- data/app/views/govuk_publishing_components/components/docs/select_with_search.yml +196 -0
- data/lib/govuk_publishing_components/presenters/select_helper.rb +8 -5
- data/lib/govuk_publishing_components/presenters/select_with_search_helper.rb +92 -0
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/lib/govuk_publishing_components.rb +1 -0
- data/node_modules/choices.js/LICENSE +21 -0
- data/node_modules/choices.js/README.md +1360 -0
- data/node_modules/choices.js/package.json +173 -0
- data/node_modules/choices.js/public/assets/scripts/choices.js +5230 -0
- data/node_modules/choices.js/public/assets/scripts/choices.min.js +2 -0
- data/node_modules/choices.js/public/assets/scripts/choices.mjs +5222 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-basic.js +4748 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-basic.min.js +2 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-basic.mjs +4740 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.js +3631 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.min.js +2 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.mjs +3623 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.js +3590 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.min.js +2 -0
- data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.mjs +3582 -0
- data/node_modules/choices.js/public/assets/styles/base.css +180 -0
- data/node_modules/choices.js/public/assets/styles/base.css.map +1 -0
- data/node_modules/choices.js/public/assets/styles/base.min.css +1 -0
- data/node_modules/choices.js/public/assets/styles/choices.css +338 -0
- data/node_modules/choices.js/public/assets/styles/choices.css.map +1 -0
- data/node_modules/choices.js/public/assets/styles/choices.min.css +1 -0
- data/node_modules/choices.js/public/types/src/index.d.ts +6 -0
- data/node_modules/choices.js/public/types/src/scripts/actions/choices.d.ts +30 -0
- data/node_modules/choices.js/public/types/src/scripts/actions/groups.d.ts +8 -0
- data/node_modules/choices.js/public/types/src/scripts/actions/items.d.ts +17 -0
- data/node_modules/choices.js/public/types/src/scripts/choices.d.ts +210 -0
- data/node_modules/choices.js/public/types/src/scripts/components/container.d.ts +36 -0
- data/node_modules/choices.js/public/types/src/scripts/components/dropdown.d.ts +21 -0
- data/node_modules/choices.js/public/types/src/scripts/components/index.d.ts +7 -0
- data/node_modules/choices.js/public/types/src/scripts/components/input.d.ts +37 -0
- data/node_modules/choices.js/public/types/src/scripts/components/list.d.ts +14 -0
- data/node_modules/choices.js/public/types/src/scripts/components/wrapped-element.d.ts +21 -0
- data/node_modules/choices.js/public/types/src/scripts/components/wrapped-input.d.ts +3 -0
- data/node_modules/choices.js/public/types/src/scripts/components/wrapped-select.d.ts +20 -0
- data/node_modules/choices.js/public/types/src/scripts/constants.d.ts +1 -0
- data/node_modules/choices.js/public/types/src/scripts/defaults.d.ts +4 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/action-type.d.ts +13 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/build-flags.d.ts +11 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/choice-full.d.ts +23 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/class-names.d.ts +61 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/event-choice.d.ts +7 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/event-type.d.ts +14 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/group-full.d.ts +10 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/index.d.ts +14 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/input-choice.d.ts +15 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/input-group.d.ts +10 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/item.d.ts +17 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/keycode-map.d.ts +13 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/options.d.ts +566 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/passed-element-type.d.ts +7 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/passed-element.d.ts +95 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/position-options-type.d.ts +1 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/search.d.ts +11 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/state.d.ts +10 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/store.d.ts +64 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/string-pre-escaped.d.ts +3 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/string-untrusted.d.ts +4 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/templates.d.ts +29 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/types.d.ts +18 -0
- data/node_modules/choices.js/public/types/src/scripts/lib/choice-input.d.ts +9 -0
- data/node_modules/choices.js/public/types/src/scripts/lib/html-guard-statements.d.ts +4 -0
- data/node_modules/choices.js/public/types/src/scripts/lib/utils.d.ts +31 -0
- data/node_modules/choices.js/public/types/src/scripts/reducers/choices.d.ts +8 -0
- data/node_modules/choices.js/public/types/src/scripts/reducers/groups.d.ts +8 -0
- data/node_modules/choices.js/public/types/src/scripts/reducers/items.d.ts +9 -0
- data/node_modules/choices.js/public/types/src/scripts/search/fuse.d.ts +14 -0
- data/node_modules/choices.js/public/types/src/scripts/search/index.d.ts +3 -0
- data/node_modules/choices.js/public/types/src/scripts/search/kmp.d.ts +11 -0
- data/node_modules/choices.js/public/types/src/scripts/search/prefix-filter.d.ts +11 -0
- data/node_modules/choices.js/public/types/src/scripts/store/store.d.ts +59 -0
- data/node_modules/choices.js/public/types/src/scripts/templates.d.ts +8 -0
- data/node_modules/choices.js/src/entry.js +3 -0
- data/node_modules/choices.js/src/icons/cross-inverse.svg +1 -0
- data/node_modules/choices.js/src/icons/cross.svg +1 -0
- data/node_modules/choices.js/src/index.ts +8 -0
- data/node_modules/choices.js/src/scripts/actions/choices.ts +59 -0
- data/node_modules/choices.js/src/scripts/actions/groups.ts +14 -0
- data/node_modules/choices.js/src/scripts/actions/items.ts +34 -0
- data/node_modules/choices.js/src/scripts/choices.ts +2364 -0
- data/node_modules/choices.js/src/scripts/components/container.ts +157 -0
- data/node_modules/choices.js/src/scripts/components/dropdown.ts +50 -0
- data/node_modules/choices.js/src/scripts/components/index.ts +8 -0
- data/node_modules/choices.js/src/scripts/components/input.ts +146 -0
- data/node_modules/choices.js/src/scripts/components/list.ts +89 -0
- data/node_modules/choices.js/src/scripts/components/wrapped-element.ts +89 -0
- data/node_modules/choices.js/src/scripts/components/wrapped-input.ts +3 -0
- data/node_modules/choices.js/src/scripts/components/wrapped-select.ts +115 -0
- data/node_modules/choices.js/src/scripts/constants.ts +1 -0
- data/node_modules/choices.js/src/scripts/defaults.ts +93 -0
- data/node_modules/choices.js/src/scripts/interfaces/action-type.ts +15 -0
- data/node_modules/choices.js/src/scripts/interfaces/build-flags.ts +17 -0
- data/node_modules/choices.js/src/scripts/interfaces/choice-full.ts +30 -0
- data/node_modules/choices.js/src/scripts/interfaces/class-names.ts +61 -0
- data/node_modules/choices.js/src/scripts/interfaces/event-choice.ts +9 -0
- data/node_modules/choices.js/src/scripts/interfaces/event-type.ts +16 -0
- data/node_modules/choices.js/src/scripts/interfaces/group-full.ts +12 -0
- data/node_modules/choices.js/src/scripts/interfaces/index.ts +14 -0
- data/node_modules/choices.js/src/scripts/interfaces/input-choice.ts +17 -0
- data/node_modules/choices.js/src/scripts/interfaces/input-group.ts +11 -0
- data/node_modules/choices.js/src/scripts/interfaces/item.ts +17 -0
- data/node_modules/choices.js/src/scripts/interfaces/keycode-map.ts +13 -0
- data/node_modules/choices.js/src/scripts/interfaces/options.ts +619 -0
- data/node_modules/choices.js/src/scripts/interfaces/passed-element-type.ts +9 -0
- data/node_modules/choices.js/src/scripts/interfaces/passed-element.ts +96 -0
- data/node_modules/choices.js/src/scripts/interfaces/position-options-type.ts +1 -0
- data/node_modules/choices.js/src/scripts/interfaces/search.ts +12 -0
- data/node_modules/choices.js/src/scripts/interfaces/state.ts +12 -0
- data/node_modules/choices.js/src/scripts/interfaces/store.ts +84 -0
- data/node_modules/choices.js/src/scripts/interfaces/string-pre-escaped.ts +3 -0
- data/node_modules/choices.js/src/scripts/interfaces/string-untrusted.ts +5 -0
- data/node_modules/choices.js/src/scripts/interfaces/templates.ts +66 -0
- data/node_modules/choices.js/src/scripts/interfaces/types.ts +21 -0
- data/node_modules/choices.js/src/scripts/lib/choice-input.ts +88 -0
- data/node_modules/choices.js/src/scripts/lib/html-guard-statements.ts +7 -0
- data/node_modules/choices.js/src/scripts/lib/utils.ts +230 -0
- data/node_modules/choices.js/src/scripts/reducers/choices.ts +86 -0
- data/node_modules/choices.js/src/scripts/reducers/groups.ts +32 -0
- data/node_modules/choices.js/src/scripts/reducers/items.ts +86 -0
- data/node_modules/choices.js/src/scripts/search/fuse.ts +59 -0
- data/node_modules/choices.js/src/scripts/search/index.ts +17 -0
- data/node_modules/choices.js/src/scripts/search/kmp.ts +87 -0
- data/node_modules/choices.js/src/scripts/search/prefix-filter.ts +42 -0
- data/node_modules/choices.js/src/scripts/store/store.ts +184 -0
- data/node_modules/choices.js/src/scripts/templates.ts +409 -0
- data/node_modules/choices.js/src/styles/base.scss +189 -0
- data/node_modules/choices.js/src/styles/choices.scss +414 -0
- data/node_modules/choices.js/src/tsconfig.json +22 -0
- metadata +134 -1
@@ -0,0 +1,64 @@
|
|
1
|
+
import { StateChangeSet, State } from './state';
|
2
|
+
import { ChoiceFull } from './choice-full';
|
3
|
+
import { GroupFull } from './group-full';
|
4
|
+
import { ActionTypes } from './action-type';
|
5
|
+
export interface AnyAction<A extends ActionTypes = ActionTypes> {
|
6
|
+
type: A;
|
7
|
+
}
|
8
|
+
export interface StateUpdate<T> {
|
9
|
+
update: boolean;
|
10
|
+
state: T;
|
11
|
+
}
|
12
|
+
export type Reducer<T> = (state: T, action: AnyAction, context?: unknown) => StateUpdate<T>;
|
13
|
+
export type StoreListener = (changes: StateChangeSet) => void;
|
14
|
+
export interface Store {
|
15
|
+
dispatch(action: AnyAction): void;
|
16
|
+
subscribe(onChange: StoreListener): void;
|
17
|
+
withTxn(func: () => void): void;
|
18
|
+
reset(): void;
|
19
|
+
get defaultState(): State;
|
20
|
+
/**
|
21
|
+
* Get store object
|
22
|
+
*/
|
23
|
+
get state(): State;
|
24
|
+
/**
|
25
|
+
* Get items from store
|
26
|
+
*/
|
27
|
+
get items(): ChoiceFull[];
|
28
|
+
/**
|
29
|
+
* Get highlighted items from store
|
30
|
+
*/
|
31
|
+
get highlightedActiveItems(): ChoiceFull[];
|
32
|
+
/**
|
33
|
+
* Get choices from store
|
34
|
+
*/
|
35
|
+
get choices(): ChoiceFull[];
|
36
|
+
/**
|
37
|
+
* Get active choices from store
|
38
|
+
*/
|
39
|
+
get activeChoices(): ChoiceFull[];
|
40
|
+
/**
|
41
|
+
* Get choices that can be searched (excluding placeholders)
|
42
|
+
*/
|
43
|
+
get searchableChoices(): ChoiceFull[];
|
44
|
+
/**
|
45
|
+
* Get groups from store
|
46
|
+
*/
|
47
|
+
get groups(): GroupFull[];
|
48
|
+
/**
|
49
|
+
* Get active groups from store
|
50
|
+
*/
|
51
|
+
get activeGroups(): GroupFull[];
|
52
|
+
/**
|
53
|
+
* Get loading state from store
|
54
|
+
*/
|
55
|
+
inTxn(): boolean;
|
56
|
+
/**
|
57
|
+
* Get single choice by it's ID
|
58
|
+
*/
|
59
|
+
getChoiceById(id: number): ChoiceFull | undefined;
|
60
|
+
/**
|
61
|
+
* Get group by group id
|
62
|
+
*/
|
63
|
+
getGroupById(id: number): GroupFull | undefined;
|
64
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { PassedElementType } from './passed-element-type';
|
2
|
+
import { StringPreEscaped } from './string-pre-escaped';
|
3
|
+
import { ChoiceFull } from './choice-full';
|
4
|
+
import { GroupFull } from './group-full';
|
5
|
+
import { Options } from './options';
|
6
|
+
import { Types } from './types';
|
7
|
+
export type TemplateOptions = Pick<Options, 'classNames' | 'allowHTML' | 'removeItemButtonAlignLeft' | 'removeItemIconText' | 'removeItemLabelText' | 'searchEnabled' | 'labelId'>;
|
8
|
+
export declare const NoticeTypes: {
|
9
|
+
readonly noChoices: "no-choices";
|
10
|
+
readonly noResults: "no-results";
|
11
|
+
readonly addChoice: "add-choice";
|
12
|
+
readonly generic: "";
|
13
|
+
};
|
14
|
+
export type NoticeType = Types.ValueOf<typeof NoticeTypes>;
|
15
|
+
export type CallbackOnCreateTemplatesFn = (template: Types.StrToEl, escapeForTemplate: Types.EscapeForTemplateFn, getClassNames: Types.GetClassNamesFn) => Partial<Templates>;
|
16
|
+
export interface Templates {
|
17
|
+
containerOuter(options: TemplateOptions, dir: HTMLElement['dir'], isSelectElement: boolean, isSelectOneElement: boolean, searchEnabled: boolean, passedElementType: PassedElementType, labelId: string): HTMLDivElement;
|
18
|
+
containerInner({ classNames: { containerInner } }: TemplateOptions): HTMLDivElement;
|
19
|
+
itemList(options: TemplateOptions, isSelectOneElement: boolean): HTMLDivElement;
|
20
|
+
placeholder(options: TemplateOptions, value: StringPreEscaped | string): HTMLDivElement;
|
21
|
+
item(options: TemplateOptions, choice: ChoiceFull, removeItemButton: boolean): HTMLDivElement;
|
22
|
+
choiceList(options: TemplateOptions, isSelectOneElement: boolean): HTMLDivElement;
|
23
|
+
choiceGroup(options: TemplateOptions, group: GroupFull): HTMLDivElement;
|
24
|
+
choice(options: TemplateOptions, choice: ChoiceFull, selectText: string, groupText?: string): HTMLDivElement;
|
25
|
+
input(options: TemplateOptions, placeholderValue: string | null): HTMLInputElement;
|
26
|
+
dropdown(options: TemplateOptions): HTMLDivElement;
|
27
|
+
notice(options: TemplateOptions, innerText: string, type: NoticeType): HTMLDivElement;
|
28
|
+
option(choice: ChoiceFull): HTMLOptionElement;
|
29
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { StringUntrusted } from './string-untrusted';
|
2
|
+
import { StringPreEscaped } from './string-pre-escaped';
|
3
|
+
export declare namespace Types {
|
4
|
+
type StrToEl = (str: string) => HTMLElement | HTMLInputElement | HTMLOptionElement;
|
5
|
+
type EscapeForTemplateFn = (allowHTML: boolean, s: StringUntrusted | StringPreEscaped | string) => string;
|
6
|
+
type GetClassNamesFn = (s: string | Array<string>) => string;
|
7
|
+
type StringFunction = () => string;
|
8
|
+
type NoticeStringFunction = (value: string, valueRaw: string) => string;
|
9
|
+
type NoticeLimitFunction = (maxItemCount: number) => string;
|
10
|
+
type FilterFunction = (value: string) => boolean;
|
11
|
+
type ValueCompareFunction = (value1: string, value2: string) => boolean;
|
12
|
+
interface RecordToCompare {
|
13
|
+
value?: StringUntrusted | string;
|
14
|
+
label?: StringUntrusted | string;
|
15
|
+
}
|
16
|
+
type ValueOf<T extends object> = T[keyof T];
|
17
|
+
type CustomProperties = Record<string, any> | string;
|
18
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { InputChoice } from '../interfaces/input-choice';
|
2
|
+
import { InputGroup } from '../interfaces/input-group';
|
3
|
+
import { GroupFull } from '../interfaces/group-full';
|
4
|
+
import { ChoiceFull } from '../interfaces/choice-full';
|
5
|
+
type MappedInputTypeToChoiceType<T extends string | InputChoice | InputGroup> = T extends InputGroup ? GroupFull : ChoiceFull;
|
6
|
+
export declare const coerceBool: (arg: unknown, defaultValue?: boolean) => boolean;
|
7
|
+
export declare const stringToHtmlClass: (input: string | string[] | undefined) => string[] | undefined;
|
8
|
+
export declare const mapInputToChoice: <T extends string | InputChoice | InputGroup>(value: T, allowGroup: boolean, allowRawString?: boolean) => MappedInputTypeToChoiceType<T>;
|
9
|
+
export {};
|
@@ -0,0 +1,4 @@
|
|
1
|
+
export declare const isHtmlInputElement: (e: Element) => e is HTMLInputElement;
|
2
|
+
export declare const isHtmlSelectElement: (e: Element) => e is HTMLSelectElement;
|
3
|
+
export declare const isHtmlOption: (e: Element) => e is HTMLOptionElement;
|
4
|
+
export declare const isHtmlOptgroup: (e: Element) => e is HTMLOptGroupElement;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { EventTypes } from '../interfaces/event-type';
|
2
|
+
import { StringUntrusted } from '../interfaces/string-untrusted';
|
3
|
+
import { StringPreEscaped } from '../interfaces/string-pre-escaped';
|
4
|
+
import { ChoiceFull } from '../interfaces/choice-full';
|
5
|
+
import { Types } from '../interfaces/types';
|
6
|
+
export declare const generateId: (element: HTMLInputElement | HTMLSelectElement, prefix: string) => string;
|
7
|
+
export declare const getAdjacentEl: (startEl: HTMLElement, selector: string, direction?: number) => HTMLElement | null;
|
8
|
+
export declare const isScrolledIntoView: (element: HTMLElement, parent: HTMLElement, direction?: number) => boolean;
|
9
|
+
export declare const sanitise: <T>(value: T | StringUntrusted | StringPreEscaped | string) => T | string;
|
10
|
+
export declare const strToEl: (str: string) => Element;
|
11
|
+
export declare const resolveNoticeFunction: (fn: Types.NoticeStringFunction | string, value: string) => string;
|
12
|
+
export declare const resolveStringFunction: (fn: Types.StringFunction | string) => string;
|
13
|
+
export declare const unwrapStringForRaw: (s?: StringUntrusted | StringPreEscaped | string) => string;
|
14
|
+
export declare const unwrapStringForEscaped: (s?: StringUntrusted | StringPreEscaped | string) => string;
|
15
|
+
export declare const escapeForTemplate: (allowHTML: boolean, s: StringUntrusted | StringPreEscaped | string) => string;
|
16
|
+
export declare const setElementHtml: (el: HTMLElement, allowHtml: boolean, html: StringUntrusted | StringPreEscaped | string) => void;
|
17
|
+
export declare const sortByAlpha: ({ value, label }: Types.RecordToCompare, { value: value2, label: label2 }: Types.RecordToCompare) => number;
|
18
|
+
export declare const sortByScore: (a: Pick<ChoiceFull, "score">, b: Pick<ChoiceFull, "score">) => number;
|
19
|
+
export declare const sortByRank: (a: Pick<ChoiceFull, "rank">, b: Pick<ChoiceFull, "rank">) => number;
|
20
|
+
export declare const dispatchEvent: (element: HTMLElement, type: EventTypes, customArgs?: object | null) => boolean;
|
21
|
+
export declare const cloneObject: <T>(obj: T) => T;
|
22
|
+
/**
|
23
|
+
* Returns an array of keys present on the first but missing on the second object
|
24
|
+
*/
|
25
|
+
export declare const diff: (a: Record<string, any>, b: Record<string, any>) => string[];
|
26
|
+
export declare const getClassNames: (ClassNames: Array<string> | string) => Array<string>;
|
27
|
+
export declare const getClassNamesSelector: (option: string | Array<string> | null) => string;
|
28
|
+
export declare const addClassesToElement: (element: HTMLElement, className: Array<string> | string) => void;
|
29
|
+
export declare const removeClassesFromElement: (element: HTMLElement, className: Array<string> | string) => void;
|
30
|
+
export declare const parseCustomProperties: (customProperties?: string) => object | string;
|
31
|
+
export declare const updateClassList: (item: ChoiceFull, add: string | string[], remove: string | string[]) => void;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { Options, State } from '../interfaces';
|
2
|
+
import { StateUpdate } from '../interfaces/store';
|
3
|
+
import { ChoiceActions } from '../actions/choices';
|
4
|
+
import { ItemActions } from '../actions/items';
|
5
|
+
type ActionTypes = ChoiceActions | ItemActions;
|
6
|
+
type StateType = State['choices'];
|
7
|
+
export default function choices(s: StateType, action: ActionTypes, context?: Options): StateUpdate<StateType>;
|
8
|
+
export {};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { GroupActions } from '../actions/groups';
|
2
|
+
import { State } from '../interfaces/state';
|
3
|
+
import { StateUpdate } from '../interfaces/store';
|
4
|
+
import { ChoiceActions } from '../actions/choices';
|
5
|
+
type ActionTypes = ChoiceActions | GroupActions;
|
6
|
+
type StateType = State['groups'];
|
7
|
+
export default function groups(s: StateType, action: ActionTypes): StateUpdate<StateType>;
|
8
|
+
export {};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { ItemActions } from '../actions/items';
|
2
|
+
import { State } from '../interfaces/state';
|
3
|
+
import { ChoiceActions } from '../actions/choices';
|
4
|
+
import { Options } from '../interfaces';
|
5
|
+
import { StateUpdate } from '../interfaces/store';
|
6
|
+
type ActionTypes = ChoiceActions | ItemActions;
|
7
|
+
type StateType = State['items'];
|
8
|
+
export default function items(s: StateType, action: ActionTypes, context?: Options): StateUpdate<StateType>;
|
9
|
+
export {};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { default as FuseFull, IFuseOptions } from 'fuse.js';
|
2
|
+
import { default as FuseBasic } from 'fuse.js/basic';
|
3
|
+
import { Options } from '../interfaces/options';
|
4
|
+
import { Searcher, SearchResult } from '../interfaces/search';
|
5
|
+
export declare class SearchByFuse<T extends object> implements Searcher<T> {
|
6
|
+
_fuseOptions: IFuseOptions<T>;
|
7
|
+
_haystack: T[];
|
8
|
+
_fuse: FuseFull<T> | FuseBasic<T> | undefined;
|
9
|
+
constructor(config: Options);
|
10
|
+
index(data: T[]): void;
|
11
|
+
reset(): void;
|
12
|
+
isEmptyIndex(): boolean;
|
13
|
+
search(needle: string): SearchResult<T>[];
|
14
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Options } from '../interfaces';
|
2
|
+
import { Searcher, SearchResult } from '../interfaces/search';
|
3
|
+
export declare class SearchByKMP<T extends object> implements Searcher<T> {
|
4
|
+
_fields: string[];
|
5
|
+
_haystack: T[];
|
6
|
+
constructor(config: Options);
|
7
|
+
index(data: T[]): void;
|
8
|
+
reset(): void;
|
9
|
+
isEmptyIndex(): boolean;
|
10
|
+
search(_needle: string): SearchResult<T>[];
|
11
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Options } from '../interfaces';
|
2
|
+
import { Searcher, SearchResult } from '../interfaces/search';
|
3
|
+
export declare class SearchByPrefixFilter<T extends object> implements Searcher<T> {
|
4
|
+
_fields: string[];
|
5
|
+
_haystack: T[];
|
6
|
+
constructor(config: Options);
|
7
|
+
index(data: T[]): void;
|
8
|
+
reset(): void;
|
9
|
+
isEmptyIndex(): boolean;
|
10
|
+
search(_needle: string): SearchResult<T>[];
|
11
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { AnyAction, Store as IStore, StoreListener } from '../interfaces/store';
|
2
|
+
import { StateChangeSet, State } from '../interfaces/state';
|
3
|
+
import { ChoiceFull } from '../interfaces/choice-full';
|
4
|
+
import { GroupFull } from '../interfaces/group-full';
|
5
|
+
export default class Store<T> implements IStore {
|
6
|
+
_state: State;
|
7
|
+
_listeners: StoreListener[];
|
8
|
+
_txn: number;
|
9
|
+
_changeSet?: StateChangeSet;
|
10
|
+
_context: T;
|
11
|
+
constructor(context: T);
|
12
|
+
get defaultState(): State;
|
13
|
+
changeSet(init: boolean): StateChangeSet;
|
14
|
+
reset(): void;
|
15
|
+
subscribe(onChange: StoreListener): this;
|
16
|
+
dispatch(action: AnyAction): void;
|
17
|
+
withTxn(func: () => void): void;
|
18
|
+
/**
|
19
|
+
* Get store object
|
20
|
+
*/
|
21
|
+
get state(): State;
|
22
|
+
/**
|
23
|
+
* Get items from store
|
24
|
+
*/
|
25
|
+
get items(): ChoiceFull[];
|
26
|
+
/**
|
27
|
+
* Get highlighted items from store
|
28
|
+
*/
|
29
|
+
get highlightedActiveItems(): ChoiceFull[];
|
30
|
+
/**
|
31
|
+
* Get choices from store
|
32
|
+
*/
|
33
|
+
get choices(): ChoiceFull[];
|
34
|
+
/**
|
35
|
+
* Get active choices from store
|
36
|
+
*/
|
37
|
+
get activeChoices(): ChoiceFull[];
|
38
|
+
/**
|
39
|
+
* Get choices that can be searched (excluding placeholders or disabled choices)
|
40
|
+
*/
|
41
|
+
get searchableChoices(): ChoiceFull[];
|
42
|
+
/**
|
43
|
+
* Get groups from store
|
44
|
+
*/
|
45
|
+
get groups(): GroupFull[];
|
46
|
+
/**
|
47
|
+
* Get active groups from store
|
48
|
+
*/
|
49
|
+
get activeGroups(): GroupFull[];
|
50
|
+
inTxn(): boolean;
|
51
|
+
/**
|
52
|
+
* Get single choice by it's ID
|
53
|
+
*/
|
54
|
+
getChoiceById(id: number): ChoiceFull | undefined;
|
55
|
+
/**
|
56
|
+
* Get group by group id
|
57
|
+
*/
|
58
|
+
getGroupById(id: number): GroupFull | undefined;
|
59
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/**
|
2
|
+
* Helpers to create HTML elements used by Choices
|
3
|
+
* Can be overridden by providing `callbackOnCreateTemplates` option.
|
4
|
+
* `Choices.defaults.templates` allows access to the default template methods from `callbackOnCreateTemplates`
|
5
|
+
*/
|
6
|
+
import { Templates as TemplatesInterface } from './interfaces/templates';
|
7
|
+
declare const templates: TemplatesInterface;
|
8
|
+
export default templates;
|
@@ -0,0 +1 @@
|
|
1
|
+
<svg width="21" height="21" viewBox="0 0 21 21" xmlns="http://www.w3.org/2000/svg"><g fill="#000" fill-rule="evenodd"><path d="M2.592.044l18.364 18.364-2.548 2.548L.044 2.592z"/><path d="M0 18.364L18.364 0l2.548 2.548L2.548 20.912z"/></g></svg>
|
@@ -0,0 +1 @@
|
|
1
|
+
<svg width="21" height="21" viewBox="0 0 21 21" xmlns="http://www.w3.org/2000/svg"><g fill="#FFF" fill-rule="evenodd"><path d="M2.592.044l18.364 18.364-2.548 2.548L.044 2.592z"/><path d="M0 18.364L18.364 0l2.548 2.548L2.548 20.912z"/></g></svg>
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { ChoiceFull } from '../interfaces/choice-full';
|
2
|
+
import { ActionType } from '../interfaces';
|
3
|
+
import { SearchResult } from '../interfaces/search';
|
4
|
+
import { AnyAction } from '../interfaces/store';
|
5
|
+
|
6
|
+
export type ChoiceActions =
|
7
|
+
| AddChoiceAction
|
8
|
+
| RemoveChoiceAction
|
9
|
+
| FilterChoicesAction
|
10
|
+
| ActivateChoicesAction
|
11
|
+
| ClearChoicesAction;
|
12
|
+
|
13
|
+
export interface AddChoiceAction extends AnyAction<typeof ActionType.ADD_CHOICE> {
|
14
|
+
choice: ChoiceFull;
|
15
|
+
}
|
16
|
+
|
17
|
+
export interface RemoveChoiceAction extends AnyAction<typeof ActionType.REMOVE_CHOICE> {
|
18
|
+
choice: ChoiceFull;
|
19
|
+
}
|
20
|
+
|
21
|
+
export interface FilterChoicesAction extends AnyAction<typeof ActionType.FILTER_CHOICES> {
|
22
|
+
results: SearchResult<ChoiceFull>[];
|
23
|
+
}
|
24
|
+
|
25
|
+
export interface ActivateChoicesAction extends AnyAction<typeof ActionType.ACTIVATE_CHOICES> {
|
26
|
+
active: boolean;
|
27
|
+
}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* @deprecated use clearStore() or clearChoices() instead.
|
31
|
+
*/
|
32
|
+
export interface ClearChoicesAction extends AnyAction<typeof ActionType.CLEAR_CHOICES> {}
|
33
|
+
|
34
|
+
export const addChoice = (choice: ChoiceFull): AddChoiceAction => ({
|
35
|
+
type: ActionType.ADD_CHOICE,
|
36
|
+
choice,
|
37
|
+
});
|
38
|
+
|
39
|
+
export const removeChoice = (choice: ChoiceFull): RemoveChoiceAction => ({
|
40
|
+
type: ActionType.REMOVE_CHOICE,
|
41
|
+
choice,
|
42
|
+
});
|
43
|
+
|
44
|
+
export const filterChoices = (results: SearchResult<ChoiceFull>[]): FilterChoicesAction => ({
|
45
|
+
type: ActionType.FILTER_CHOICES,
|
46
|
+
results,
|
47
|
+
});
|
48
|
+
|
49
|
+
export const activateChoices = (active = true): ActivateChoicesAction => ({
|
50
|
+
type: ActionType.ACTIVATE_CHOICES,
|
51
|
+
active,
|
52
|
+
});
|
53
|
+
|
54
|
+
/**
|
55
|
+
* @deprecated use clearStore() or clearChoices() instead.
|
56
|
+
*/
|
57
|
+
export const clearChoices = (): ClearChoicesAction => ({
|
58
|
+
type: ActionType.CLEAR_CHOICES,
|
59
|
+
});
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { GroupFull } from '../interfaces/group-full';
|
2
|
+
import { ActionType } from '../interfaces';
|
3
|
+
import { AnyAction } from '../interfaces/store';
|
4
|
+
|
5
|
+
export type GroupActions = AddGroupAction;
|
6
|
+
|
7
|
+
export interface AddGroupAction extends AnyAction<typeof ActionType.ADD_GROUP> {
|
8
|
+
group: GroupFull;
|
9
|
+
}
|
10
|
+
|
11
|
+
export const addGroup = (group: GroupFull): AddGroupAction => ({
|
12
|
+
type: ActionType.ADD_GROUP,
|
13
|
+
group,
|
14
|
+
});
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { ChoiceFull } from '../interfaces/choice-full';
|
2
|
+
import { ActionType } from '../interfaces';
|
3
|
+
import { AnyAction } from '../interfaces/store';
|
4
|
+
|
5
|
+
export type ItemActions = AddItemAction | RemoveItemAction | HighlightItemAction;
|
6
|
+
|
7
|
+
export interface AddItemAction extends AnyAction<typeof ActionType.ADD_ITEM> {
|
8
|
+
item: ChoiceFull;
|
9
|
+
}
|
10
|
+
|
11
|
+
export interface RemoveItemAction extends AnyAction<typeof ActionType.REMOVE_ITEM> {
|
12
|
+
item: ChoiceFull;
|
13
|
+
}
|
14
|
+
|
15
|
+
export interface HighlightItemAction extends AnyAction<typeof ActionType.HIGHLIGHT_ITEM> {
|
16
|
+
item: ChoiceFull;
|
17
|
+
highlighted: boolean;
|
18
|
+
}
|
19
|
+
|
20
|
+
export const addItem = (item: ChoiceFull): AddItemAction => ({
|
21
|
+
type: ActionType.ADD_ITEM,
|
22
|
+
item,
|
23
|
+
});
|
24
|
+
|
25
|
+
export const removeItem = (item: ChoiceFull): RemoveItemAction => ({
|
26
|
+
type: ActionType.REMOVE_ITEM,
|
27
|
+
item,
|
28
|
+
});
|
29
|
+
|
30
|
+
export const highlightItem = (item: ChoiceFull, highlighted: boolean): HighlightItemAction => ({
|
31
|
+
type: ActionType.HIGHLIGHT_ITEM,
|
32
|
+
item,
|
33
|
+
highlighted,
|
34
|
+
});
|