@wrdagency/blockout 1.0.6 → 1.0.7

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