@wrdagency/blockout 1.0.6 → 1.0.8

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.
@@ -1,10 +1,10 @@
1
- import { ControlFC } from '../base-control/props';
2
- import { Tag, Taggable } from './props';
3
- interface TagControlProps {
4
- value?: Taggable[];
5
- onChangeValue?: (value: Tag[]) => void;
6
- options?: Taggable[];
7
- allowCreate?: boolean;
1
+ import { ControlProps } from '../base-control/props';
2
+ import { Tag, Taggable, UnnormalizedCreateTagRules } from './props';
3
+ interface TagControlProps<T extends number | string = string> {
4
+ value?: Taggable<T>[];
5
+ onChangeValue?: (value: Tag<T>[]) => void;
6
+ options?: Taggable<T>[];
7
+ create?: UnnormalizedCreateTagRules<T>;
8
8
  }
9
- export declare const TagControl: ControlFC<TagControlProps>;
9
+ export declare function TagControl<T extends number | string = string>(props: ControlProps<TagControlProps<T>>): import("react/jsx-runtime").JSX.Element;
10
10
  export type { Tag, Taggable } from './props';
@@ -1,7 +1,7 @@
1
1
  import { jsx as e, jsxs as t } from "react/jsx-runtime";
2
- import { Colourway as p } from "../../../primitives/colourway/index.js";
3
- import { noop as w } from "../../../utils/noop.js";
4
- import { useState as x, useMemo as P } from "react";
2
+ import { Colourway as _ } from "../../../primitives/colourway/index.js";
3
+ import { noop as O } from "../../../utils/noop.js";
4
+ import { useState as g, useMemo as R } from "react";
5
5
  import '../../../assets/style18.css';import '../../../assets/styles.css';import '../../../assets/style7.css';import '../../../assets/style6.css';import '../../../assets/style5.css';import '../../../assets/style4.css';import '../../../assets/style3.css';import '../../../assets/style2.css';import '../../../assets/style.css';/* empty css */
6
6
  /* empty css */
7
7
  /* empty css */
@@ -13,70 +13,75 @@ import "../../../primitives/symbol/index.js";
13
13
  /* empty css */
14
14
  /* empty css */
15
15
  /* empty css */
16
- import { o as T } from "../../../Check.es-CMkTf2It.js";
17
- import { e as S } from "../../../Plus.es-DJ5SuqNv.js";
18
- import { e as V } from "../../../X.es-TbGOnXOO.js";
19
- import { m as y } from "../../../match-sorter.esm-MNVE8H_6.js";
20
- import { BaseControl as k } from "../base-control/index.js";
21
- import { useBaseControlProps as z } from "../base-control/props.js";
22
- import { T as I, a as j, b as B, c as L, d as M, C as O, e as U } from "../../../tag-remove-BVa8oSsq.js";
23
- import { normalizeTag as m } from "./props.js";
16
+ import { o as k } from "../../../Check.es-CMkTf2It.js";
17
+ import { e as B } from "../../../Plus.es-DJ5SuqNv.js";
18
+ import { e as I } from "../../../X.es-TbGOnXOO.js";
19
+ import { m as j } from "../../../match-sorter.esm-MNVE8H_6.js";
20
+ import { BaseControl as L } from "../base-control/index.js";
21
+ import { useBaseControlProps as M } from "../base-control/props.js";
22
+ import { T as A, a as K, b as U, c as $, d as q, C as D, e as E } from "../../../tag-remove-BVa8oSsq.js";
23
+ import { normalizeTag as d, normalizeCreateTagRules as F } from "./props.js";
24
24
  /* empty css */
25
- import { C as A, a as K, c as i } from "../../../MAXQOH4L-DBaf8WKp.js";
26
- const io = (_) => {
27
- const { baseProps: u, controlProps: h } = z(_, {
25
+ import { C as G, a as H, c as h } from "../../../MAXQOH4L-DBaf8WKp.js";
26
+ function Co(v) {
27
+ const { baseProps: b, controlProps: f } = M(v, {
28
28
  className: "component-tag-control"
29
- }), [a, d] = x(""), {
30
- value: g = [],
31
- onChangeValue: v = w,
32
- options: b = [],
33
- allowCreate: l = !1
34
- } = h, s = b.map(m), c = g.map(m), n = P(() => y(s, a, {
35
- baseSort: (o, r) => o.index < r.index ? -1 : 1,
29
+ }), [a, C] = g(""), [N, w] = g([]), {
30
+ value: x = [],
31
+ onChangeValue: T = O,
32
+ options: P = [],
33
+ create: S = !1
34
+ } = f, c = [...P.map(d), ...N], p = x.map(d), n = F(S), l = R(() => j(c, a, {
35
+ baseSort: (o, s) => o.index < s.index ? -1 : 1,
36
36
  keys: ["label", "value"]
37
- }), [a]), f = n.length > 0 || l, C = (o) => {
38
- v(
39
- o.map(
40
- (r) => s.find((N) => N.value === r) || m(r)
41
- )
42
- );
37
+ }), [a]), i = !l.length && n.allow(a), V = l.length > 0 || i, y = (o) => {
38
+ const s = o.map((m) => {
39
+ const u = c.find((r) => r.value == m);
40
+ if (u)
41
+ return u;
42
+ if (n.allow(m)) {
43
+ const r = n.create(m);
44
+ return w((z) => [...z, r]), r;
45
+ }
46
+ }).filter(Boolean);
47
+ T(s);
43
48
  };
44
49
  return /* @__PURE__ */ e(
45
- I,
50
+ A,
46
51
  {
47
- values: c.map((o) => o.value),
48
- setValues: C,
52
+ values: p.map((o) => String(o.value)),
53
+ setValues: y,
49
54
  value: a,
50
- setValue: d,
51
- children: /* @__PURE__ */ e(k, { ...u, children: /* @__PURE__ */ t(j, { className: "component-tag-control__box", children: [
52
- c.map((o) => /* @__PURE__ */ t(
53
- p,
55
+ setValue: C,
56
+ children: /* @__PURE__ */ e(L, { ...b, children: /* @__PURE__ */ t(K, { className: "component-tag-control__box", children: [
57
+ p.map((o) => /* @__PURE__ */ t(
58
+ _,
54
59
  {
55
- value: o.value,
56
- as: B,
60
+ value: String(o.value),
61
+ as: U,
57
62
  theme: o.colourway,
58
63
  className: "component-tag-control__tag",
59
64
  children: [
60
65
  /* @__PURE__ */ e("span", { className: "component-tag-control__tag__label", children: o.label }),
61
- /* @__PURE__ */ e(L, { className: "component-tag-control__tag__remove", children: /* @__PURE__ */ e(V, {}) })
66
+ /* @__PURE__ */ e($, { className: "component-tag-control__tag__remove", children: /* @__PURE__ */ e(I, {}) })
62
67
  ]
63
68
  },
64
69
  o.value
65
70
  )),
66
- /* @__PURE__ */ t(A, { children: [
71
+ /* @__PURE__ */ t(G, { children: [
67
72
  /* @__PURE__ */ e(
68
- K,
73
+ H,
69
74
  {
70
75
  autoSelect: !0,
71
76
  showMinLength: 1,
72
77
  showOnKeyPress: !0,
73
78
  autoComplete: "both",
74
- render: /* @__PURE__ */ e(M, {}),
79
+ render: /* @__PURE__ */ e(q, {}),
75
80
  className: "component-tag-control__input"
76
81
  }
77
82
  ),
78
- f && /* @__PURE__ */ t(
79
- O,
83
+ V && /* @__PURE__ */ t(
84
+ D,
80
85
  {
81
86
  className: "component-tag-control__popover",
82
87
  "data-colour-scheme": "invert",
@@ -87,32 +92,32 @@ const io = (_) => {
87
92
  gutter: 8,
88
93
  overflowPadding: 4,
89
94
  children: [
90
- n.map((o) => /* @__PURE__ */ t(
91
- i,
95
+ l.map((o) => /* @__PURE__ */ t(
96
+ h,
92
97
  {
93
- value: o.value,
98
+ value: String(o.value),
94
99
  className: "component-tag-control__option",
95
100
  children: [
96
101
  /* @__PURE__ */ e(
97
- p,
102
+ _,
98
103
  {
99
104
  className: "component-tag-control__option__chip",
100
105
  theme: o.colourway
101
106
  }
102
107
  ),
103
108
  /* @__PURE__ */ e("span", { className: "component-tag-control__option__label", children: o.label }),
104
- /* @__PURE__ */ e(U, { className: "component-tag-control__option__check", children: /* @__PURE__ */ e(T, {}) })
109
+ /* @__PURE__ */ e(E, { className: "component-tag-control__option__check", children: /* @__PURE__ */ e(k, {}) })
105
110
  ]
106
111
  },
107
112
  o.value
108
113
  )),
109
- !n.length && l && /* @__PURE__ */ t(
110
- i,
114
+ i && /* @__PURE__ */ t(
115
+ h,
111
116
  {
112
- value: a.toUpperCase(),
117
+ value: a,
113
118
  className: "component-tag-control__option component-tag-control__option--create",
114
119
  children: [
115
- /* @__PURE__ */ e(S, { className: "component-tag-control__option--add" }),
120
+ /* @__PURE__ */ e(B, { className: "component-tag-control__option--add" }),
116
121
  /* @__PURE__ */ t("span", { className: "component-tag-control__option__label", children: [
117
122
  'Add "',
118
123
  a.toUpperCase(),
@@ -128,7 +133,7 @@ const io = (_) => {
128
133
  ] }) })
129
134
  }
130
135
  );
131
- };
136
+ }
132
137
  export {
133
- io as TagControl
138
+ Co as TagControl
134
139
  };
@@ -8,4 +8,13 @@ export type PartialTag<T extends string | number = string> = Partial<Tag<T>> & {
8
8
  value: T;
9
9
  };
10
10
  export type Taggable<T extends string | number = string> = Tag<T> | PartialTag<T> | T;
11
+ export type CreateTagRules<T extends number | string = string> = {
12
+ create: (input: string) => Tag<T>;
13
+ allow: (input: string) => boolean;
14
+ };
15
+ export type UnnormalizedCreateTagRules<T extends number | string = string> = boolean | {
16
+ create?: ((input: string) => PartialTag<T>) | "slugify" | "uuid";
17
+ allow?: (input: string) => boolean;
18
+ };
11
19
  export declare function normalizeTag<T extends string | number = string>(opt: Taggable<T>): Tag<T>;
20
+ export declare function normalizeCreateTagRules<T extends string | number = string>(rules: UnnormalizedCreateTagRules<T>): CreateTagRules<T>;
@@ -1,6 +1,6 @@
1
1
  import "react/jsx-runtime";
2
2
  import '../../../assets/styles.css';import '../../../assets/style7.css';import '../../../assets/style6.css';import '../../../assets/style5.css';import '../../../assets/style4.css';import '../../../assets/style3.css';import '../../../assets/style2.css';import '../../../assets/style.css';import '../../../assets/style10.css';/* empty css */
3
- import { getRandomTheme as i } from "../../../primitives/colourway/util.js";
3
+ import { getRandomTheme as t } from "../../../primitives/colourway/util.js";
4
4
  import "react";
5
5
  /* empty css */
6
6
  /* empty css */
@@ -13,17 +13,38 @@ import "../../../primitives/symbol/index.js";
13
13
  /* empty css */
14
14
  /* empty css */
15
15
  /* empty css */
16
- function w(r) {
16
+ import { slugify as i } from "../../../utils/string.js";
17
+ function S(r) {
17
18
  return typeof r == "string" || typeof r == "number" ? {
18
19
  value: r,
19
20
  label: String(r),
20
- colourway: i(r)
21
+ colourway: t(r)
21
22
  } : {
22
23
  label: r.label || String(r.value),
23
- colourway: i(r.value),
24
+ colourway: t(r.value),
24
25
  ...r
25
26
  };
26
27
  }
28
+ function U(r) {
29
+ return {
30
+ create: (e) => {
31
+ var o = e;
32
+ if (typeof r == "boolean" || typeof r.create > "u" || r.create === "slugify")
33
+ o = i(e);
34
+ else if (r.create === "uuid")
35
+ o = crypto.randomUUID();
36
+ else
37
+ return {
38
+ label: e,
39
+ colourway: t(e),
40
+ ...r.create(e)
41
+ };
42
+ return { label: e, colourway: t(e), value: o };
43
+ },
44
+ allow: (e) => r === !1 ? !1 : r === !0 || typeof r.allow > "u" ? e.trim().length >= 1 : r.allow(e)
45
+ };
46
+ }
27
47
  export {
28
- w as normalizeTag
48
+ U as normalizeCreateTagRules,
49
+ S as normalizeTag
29
50
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrdagency/blockout",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "A React component library created by WRD.agency",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",