@wrdagency/blockout 1.0.29 → 1.0.30

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.
@@ -10,5 +10,19 @@ export type PartialOption<T extends string = string> = Partial<Option<T>> & {
10
10
  value: T;
11
11
  };
12
12
  export type Optionable<T extends string = string> = Option<T> | PartialOption<T> | T;
13
+ export type OptionGroup<T extends string = string> = {
14
+ type: "group";
15
+ label: string;
16
+ items: Option<T>[];
17
+ };
18
+ export type OptionableGroup<T extends string = string> = {
19
+ type: "group";
20
+ label: string;
21
+ items: Optionable<T>[];
22
+ };
23
+ export declare function isOptionGroup<T extends string = string>(value: Optionable<T> | OptionableGroup<T>): value is OptionGroup<T> | OptionableGroup<T>;
13
24
  export declare function normalizeOption<T extends string = string>(opt: Optionable<T>): Option<T>;
25
+ export declare function normalizeOptionGroup<T extends string = string>(group: OptionableGroup<T>): OptionGroup<T>;
26
+ export declare function normalizeOptions<T extends string = string>(opts: (OptionableGroup<T> | Optionable<T>)[]): OptionGroup<T>[];
27
+ export declare function findOption<T extends string = string>(options: (OptionableGroup<T> | Optionable<T>)[], value: T | undefined): Option<T> | undefined;
14
28
  export declare function uniqueOptions<T extends string = string>(value: Optionable<T>, index: number, array: Optionable<T>[]): boolean;
@@ -1,18 +1,50 @@
1
- function n(e) {
2
- return typeof e == "string" ? {
3
- value: e,
4
- label: e
1
+ function s(n) {
2
+ return typeof n == "object" && n.hasOwnProperty("type") && n.type === "group";
3
+ }
4
+ function i(n) {
5
+ return typeof n == "string" ? {
6
+ value: n,
7
+ label: n
5
8
  } : {
6
- label: e.label || e.value,
7
- ...e
9
+ label: n.label || n.value,
10
+ ...n
11
+ };
12
+ }
13
+ function f(n) {
14
+ return {
15
+ ...n,
16
+ items: n.items.map(i)
8
17
  };
9
18
  }
10
- function r(e, l, u) {
11
- return u.findIndex(
12
- (i) => n(i).value === n(e).value
13
- ) === l;
19
+ function p(n) {
20
+ const o = [], e = {
21
+ type: "group",
22
+ label: "",
23
+ items: []
24
+ };
25
+ for (const t of n)
26
+ s(t) ? o.push(f(t)) : e.items.push(i(t));
27
+ return e.items.length > 0 && o.push(e), o;
28
+ }
29
+ function l(n, o) {
30
+ const e = p(n);
31
+ console.log(e, o);
32
+ for (const t of e) {
33
+ const r = t.items.find((u) => u.value === o);
34
+ if (r)
35
+ return r;
36
+ }
37
+ }
38
+ function c(n, o, e) {
39
+ return e.findIndex(
40
+ (t) => i(t).value === i(n).value
41
+ ) === o;
14
42
  }
15
43
  export {
16
- n as normalizeOption,
17
- r as uniqueOptions
44
+ l as findOption,
45
+ s as isOptionGroup,
46
+ i as normalizeOption,
47
+ f as normalizeOptionGroup,
48
+ p as normalizeOptions,
49
+ c as uniqueOptions
18
50
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrdagency/blockout",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
4
4
  "description": "A React component library created by WRD.agency",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",