@makeswift/runtime 0.0.22 → 0.1.1

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.
Files changed (203) hide show
  1. package/dist/Box.cjs.js +502 -0
  2. package/dist/Box.cjs.js.map +1 -0
  3. package/dist/Box.es.js +496 -0
  4. package/dist/Box.es.js.map +1 -0
  5. package/dist/Button.cjs.js +308 -0
  6. package/dist/Button.cjs.js.map +1 -0
  7. package/dist/Button.es.js +301 -0
  8. package/dist/Button.es.js.map +1 -0
  9. package/dist/Carousel.cjs.js +487 -0
  10. package/dist/Carousel.cjs.js.map +1 -0
  11. package/dist/Carousel.es.js +481 -0
  12. package/dist/Carousel.es.js.map +1 -0
  13. package/dist/Countdown.cjs.js +340 -0
  14. package/dist/Countdown.cjs.js.map +1 -0
  15. package/dist/Countdown.es.js +334 -0
  16. package/dist/Countdown.es.js.map +1 -0
  17. package/dist/Divider.cjs.js +115 -0
  18. package/dist/Divider.cjs.js.map +1 -0
  19. package/dist/Divider.es.js +109 -0
  20. package/dist/Divider.es.js.map +1 -0
  21. package/dist/Embed.cjs.js +129 -0
  22. package/dist/Embed.cjs.js.map +1 -0
  23. package/dist/Embed.es.js +123 -0
  24. package/dist/Embed.es.js.map +1 -0
  25. package/dist/Form.cjs.js +1724 -0
  26. package/dist/Form.cjs.js.map +1 -0
  27. package/dist/Form.es.js +1697 -0
  28. package/dist/Form.es.js.map +1 -0
  29. package/dist/Image.cjs2.js +148 -0
  30. package/dist/Image.cjs2.js.map +1 -0
  31. package/dist/Image.es2.js +141 -0
  32. package/dist/Image.es2.js.map +1 -0
  33. package/dist/Navigation.cjs.js +736 -0
  34. package/dist/Navigation.cjs.js.map +1 -0
  35. package/dist/Navigation.es.js +710 -0
  36. package/dist/Navigation.es.js.map +1 -0
  37. package/dist/Root.cjs.js +143 -0
  38. package/dist/Root.cjs.js.map +1 -0
  39. package/dist/Root.es.js +137 -0
  40. package/dist/Root.es.js.map +1 -0
  41. package/dist/SocialLinks.cjs.js +900 -0
  42. package/dist/SocialLinks.cjs.js.map +1 -0
  43. package/dist/SocialLinks.es.js +874 -0
  44. package/dist/SocialLinks.es.js.map +1 -0
  45. package/dist/Text.cjs.js +475 -0
  46. package/dist/Text.cjs.js.map +1 -0
  47. package/dist/Text.es.js +467 -0
  48. package/dist/Text.es.js.map +1 -0
  49. package/dist/Video.cjs.js +121 -0
  50. package/dist/Video.cjs.js.map +1 -0
  51. package/dist/Video.es.js +114 -0
  52. package/dist/Video.es.js.map +1 -0
  53. package/dist/components.cjs.js +79 -58
  54. package/dist/components.cjs.js.map +1 -1
  55. package/dist/components.es.js +41 -18
  56. package/dist/components.es.js.map +1 -1
  57. package/dist/cssMediaRules.cjs.js +222 -0
  58. package/dist/cssMediaRules.cjs.js.map +1 -0
  59. package/dist/cssMediaRules.es.js +213 -0
  60. package/dist/cssMediaRules.es.js.map +1 -0
  61. package/dist/descriptors.es.js +1 -1
  62. package/dist/index.cjs.js +1408 -7741
  63. package/dist/index.cjs.js.map +1 -1
  64. package/dist/index.cjs2.js +522 -0
  65. package/dist/index.cjs2.js.map +1 -0
  66. package/dist/index.cjs3.js +141 -0
  67. package/dist/index.cjs3.js.map +1 -0
  68. package/dist/index.cjs4.js +18 -0
  69. package/dist/index.cjs4.js.map +1 -0
  70. package/dist/index.es.js +1339 -7697
  71. package/dist/index.es.js.map +1 -1
  72. package/dist/index.es2.js +514 -0
  73. package/dist/index.es2.js.map +1 -0
  74. package/dist/index.es3.js +134 -0
  75. package/dist/index.es3.js.map +1 -0
  76. package/dist/index.es4.js +13 -0
  77. package/dist/index.es4.js.map +1 -0
  78. package/dist/next.cjs.js +19 -201
  79. package/dist/next.cjs.js.map +1 -1
  80. package/dist/next.es.js +12 -192
  81. package/dist/next.es.js.map +1 -1
  82. package/dist/placeholders.cjs.js +13 -0
  83. package/dist/placeholders.cjs.js.map +1 -0
  84. package/dist/placeholders.es.js +12 -0
  85. package/dist/placeholders.es.js.map +1 -0
  86. package/dist/react-builder-preview.cjs.js +23 -33
  87. package/dist/react-builder-preview.cjs.js.map +1 -1
  88. package/dist/react-builder-preview.es.js +13 -23
  89. package/dist/react-builder-preview.es.js.map +1 -1
  90. package/dist/react-page.es.js +1 -1
  91. package/dist/react.cjs.js +16 -28
  92. package/dist/react.cjs.js.map +1 -1
  93. package/dist/react.es.js +8 -20
  94. package/dist/react.es.js.map +1 -1
  95. package/dist/types/components/builtin/Box/Box.d.ts +1 -4
  96. package/dist/types/components/builtin/Box/Box.d.ts.map +1 -1
  97. package/dist/types/components/builtin/Box/animations.d.ts +1 -8
  98. package/dist/types/components/builtin/Box/animations.d.ts.map +1 -1
  99. package/dist/types/components/builtin/Box/constants.d.ts +9 -0
  100. package/dist/types/components/builtin/Box/constants.d.ts.map +1 -0
  101. package/dist/types/components/builtin/Box/index.d.ts +2 -2
  102. package/dist/types/components/builtin/Box/index.d.ts.map +1 -1
  103. package/dist/types/components/builtin/Box/register.d.ts +3 -0
  104. package/dist/types/components/builtin/Box/register.d.ts.map +1 -0
  105. package/dist/types/components/builtin/Button/Button.d.ts +1 -4
  106. package/dist/types/components/builtin/Button/Button.d.ts.map +1 -1
  107. package/dist/types/components/builtin/Button/contants.d.ts +2 -0
  108. package/dist/types/components/builtin/Button/contants.d.ts.map +1 -0
  109. package/dist/types/components/builtin/Button/index.d.ts +1 -1
  110. package/dist/types/components/builtin/Button/index.d.ts.map +1 -1
  111. package/dist/types/components/builtin/Button/register.d.ts +3 -0
  112. package/dist/types/components/builtin/Button/register.d.ts.map +1 -0
  113. package/dist/types/components/builtin/Carousel/Carousel.d.ts +0 -3
  114. package/dist/types/components/builtin/Carousel/Carousel.d.ts.map +1 -1
  115. package/dist/types/components/builtin/Carousel/index.d.ts +1 -1
  116. package/dist/types/components/builtin/Carousel/index.d.ts.map +1 -1
  117. package/dist/types/components/builtin/Carousel/register.d.ts +3 -0
  118. package/dist/types/components/builtin/Carousel/register.d.ts.map +1 -0
  119. package/dist/types/components/builtin/Countdown/Countdown.d.ts +0 -3
  120. package/dist/types/components/builtin/Countdown/Countdown.d.ts.map +1 -1
  121. package/dist/types/components/builtin/Countdown/index.d.ts +1 -1
  122. package/dist/types/components/builtin/Countdown/index.d.ts.map +1 -1
  123. package/dist/types/components/builtin/Countdown/register.d.ts +3 -0
  124. package/dist/types/components/builtin/Countdown/register.d.ts.map +1 -0
  125. package/dist/types/components/builtin/Divider/Divider.d.ts +0 -3
  126. package/dist/types/components/builtin/Divider/Divider.d.ts.map +1 -1
  127. package/dist/types/components/builtin/Divider/index.d.ts +1 -1
  128. package/dist/types/components/builtin/Divider/index.d.ts.map +1 -1
  129. package/dist/types/components/builtin/Divider/register.d.ts +3 -0
  130. package/dist/types/components/builtin/Divider/register.d.ts.map +1 -0
  131. package/dist/types/components/builtin/Embed/Embed.d.ts +0 -3
  132. package/dist/types/components/builtin/Embed/Embed.d.ts.map +1 -1
  133. package/dist/types/components/builtin/Embed/index.d.ts +1 -1
  134. package/dist/types/components/builtin/Embed/index.d.ts.map +1 -1
  135. package/dist/types/components/builtin/Embed/register.d.ts +3 -0
  136. package/dist/types/components/builtin/Embed/register.d.ts.map +1 -0
  137. package/dist/types/components/builtin/Form/Form.d.ts +1 -10
  138. package/dist/types/components/builtin/Form/Form.d.ts.map +1 -1
  139. package/dist/types/components/builtin/Form/components/Field/index.d.ts +1 -1
  140. package/dist/types/components/builtin/Form/components/Field/index.d.ts.map +1 -1
  141. package/dist/types/components/builtin/Form/context/FormContext.d.ts +6 -0
  142. package/dist/types/components/builtin/Form/context/FormContext.d.ts.map +1 -1
  143. package/dist/types/components/builtin/Form/index.d.ts +1 -1
  144. package/dist/types/components/builtin/Form/index.d.ts.map +1 -1
  145. package/dist/types/components/builtin/Form/register.d.ts +3 -0
  146. package/dist/types/components/builtin/Form/register.d.ts.map +1 -0
  147. package/dist/types/components/{hooks/useTable.d.ts → builtin/Form/types.d.ts} +2 -6
  148. package/dist/types/components/builtin/Form/types.d.ts.map +1 -0
  149. package/dist/types/components/builtin/Image/Image.d.ts +0 -3
  150. package/dist/types/components/builtin/Image/Image.d.ts.map +1 -1
  151. package/dist/types/components/builtin/Image/index.d.ts +1 -1
  152. package/dist/types/components/builtin/Image/index.d.ts.map +1 -1
  153. package/dist/types/components/builtin/Image/register.d.ts +3 -0
  154. package/dist/types/components/builtin/Image/register.d.ts.map +1 -0
  155. package/dist/types/components/builtin/Navigation/Navigation.d.ts +0 -3
  156. package/dist/types/components/builtin/Navigation/Navigation.d.ts.map +1 -1
  157. package/dist/types/components/builtin/Navigation/index.d.ts +1 -1
  158. package/dist/types/components/builtin/Navigation/index.d.ts.map +1 -1
  159. package/dist/types/components/builtin/Navigation/register.d.ts +3 -0
  160. package/dist/types/components/builtin/Navigation/register.d.ts.map +1 -0
  161. package/dist/types/components/builtin/Root/Root.d.ts +0 -2
  162. package/dist/types/components/builtin/Root/Root.d.ts.map +1 -1
  163. package/dist/types/components/builtin/Root/index.d.ts +1 -1
  164. package/dist/types/components/builtin/Root/index.d.ts.map +1 -1
  165. package/dist/types/components/builtin/Root/register.d.ts +3 -0
  166. package/dist/types/components/builtin/Root/register.d.ts.map +1 -0
  167. package/dist/types/components/builtin/SocialLinks/SocialLinks.d.ts +0 -3
  168. package/dist/types/components/builtin/SocialLinks/SocialLinks.d.ts.map +1 -1
  169. package/dist/types/components/builtin/SocialLinks/index.d.ts +1 -1
  170. package/dist/types/components/builtin/SocialLinks/index.d.ts.map +1 -1
  171. package/dist/types/components/builtin/SocialLinks/register.d.ts +3 -0
  172. package/dist/types/components/builtin/SocialLinks/register.d.ts.map +1 -0
  173. package/dist/types/components/builtin/Text/Text.d.ts +0 -3
  174. package/dist/types/components/builtin/Text/Text.d.ts.map +1 -1
  175. package/dist/types/components/builtin/Text/index.d.ts +1 -1
  176. package/dist/types/components/builtin/Text/index.d.ts.map +1 -1
  177. package/dist/types/components/builtin/Text/register.d.ts +3 -0
  178. package/dist/types/components/builtin/Text/register.d.ts.map +1 -0
  179. package/dist/types/components/builtin/Video/Video.d.ts +0 -3
  180. package/dist/types/components/builtin/Video/Video.d.ts.map +1 -1
  181. package/dist/types/components/builtin/Video/index.d.ts +1 -1
  182. package/dist/types/components/builtin/Video/index.d.ts.map +1 -1
  183. package/dist/types/components/builtin/Video/register.d.ts +3 -0
  184. package/dist/types/components/builtin/Video/register.d.ts.map +1 -0
  185. package/dist/types/components/builtin/index.d.ts +1 -2
  186. package/dist/types/components/builtin/index.d.ts.map +1 -1
  187. package/dist/types/components/builtin/register.d.ts +3 -0
  188. package/dist/types/components/builtin/register.d.ts.map +1 -0
  189. package/dist/types/components/hooks/index.d.ts +0 -1
  190. package/dist/types/components/hooks/index.d.ts.map +1 -1
  191. package/dist/types/next.d.ts +12 -2
  192. package/dist/types/next.d.ts.map +1 -1
  193. package/dist/useBoxShadow.cjs.js +78 -0
  194. package/dist/useBoxShadow.cjs.js.map +1 -0
  195. package/dist/useBoxShadow.es.js +77 -0
  196. package/dist/useBoxShadow.es.js.map +1 -0
  197. package/dist/useMediaQuery.cjs.js +26 -0
  198. package/dist/useMediaQuery.cjs.js.map +1 -0
  199. package/dist/useMediaQuery.es.js +25 -0
  200. package/dist/useMediaQuery.es.js.map +1 -0
  201. package/next/plugin.js +1 -0
  202. package/package.json +4 -1
  203. package/dist/types/components/hooks/useTable.d.ts.map +0 -1
@@ -0,0 +1,1724 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ var __objRest = (source, exclude) => {
22
+ var target = {};
23
+ for (var prop in source)
24
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
+ target[prop] = source[prop];
26
+ if (source != null && __getOwnPropSymbols)
27
+ for (var prop of __getOwnPropSymbols(source)) {
28
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
+ target[prop] = source[prop];
30
+ }
31
+ return target;
32
+ };
33
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
34
+ var React = require("react");
35
+ var styled = require("styled-components");
36
+ var formik = require("formik");
37
+ var css = require("@emotion/css");
38
+ var cssMediaRules = require("./cssMediaRules.cjs.js");
39
+ var next = require("./index.cjs.js");
40
+ var jsxRuntime = require("react/jsx-runtime");
41
+ var ColorHelper = require("color");
42
+ var Button$1 = require("./Button.cjs.js");
43
+ var index = require("./index.cjs3.js");
44
+ var boxModels = require("./box-models.cjs.js");
45
+ var client = require("@apollo/client");
46
+ require("use-sync-external-store/shim/with-selector");
47
+ require("./react-page.cjs.js");
48
+ require("redux");
49
+ require("redux-thunk");
50
+ require("./actions.cjs.js");
51
+ require("./descriptors.cjs.js");
52
+ require("./style.cjs.js");
53
+ require("./color.cjs.js");
54
+ require("./image.cjs.js");
55
+ require("next/dynamic");
56
+ require("next/document");
57
+ require("slate");
58
+ require("@emotion/server/create-instance");
59
+ require("@apollo/client/link/batch-http");
60
+ require("./graphql.cjs.js");
61
+ require("./text-input.cjs.js");
62
+ require("./shape.cjs.js");
63
+ require("react-dom");
64
+ require("html-react-parser");
65
+ require("next/head");
66
+ require("uuid/v4");
67
+ require("corporate-ipsum");
68
+ require("scroll-into-view-if-needed");
69
+ require("next/link");
70
+ require("css-box-model");
71
+ function _interopDefaultLegacy(e) {
72
+ return e && typeof e === "object" && "default" in e ? e : { "default": e };
73
+ }
74
+ function _interopNamespace(e) {
75
+ if (e && e.__esModule)
76
+ return e;
77
+ var n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
78
+ if (e) {
79
+ Object.keys(e).forEach(function(k) {
80
+ if (k !== "default") {
81
+ var d = Object.getOwnPropertyDescriptor(e, k);
82
+ Object.defineProperty(n, k, d.get ? d : {
83
+ enumerable: true,
84
+ get: function() {
85
+ return e[k];
86
+ }
87
+ });
88
+ }
89
+ });
90
+ }
91
+ n["default"] = e;
92
+ return Object.freeze(n);
93
+ }
94
+ var React__namespace = /* @__PURE__ */ _interopNamespace(React);
95
+ var styled__default = /* @__PURE__ */ _interopDefaultLegacy(styled);
96
+ var ColorHelper__default = /* @__PURE__ */ _interopDefaultLegacy(ColorHelper);
97
+ var _path;
98
+ function _extends$1() {
99
+ _extends$1 = Object.assign || function(target) {
100
+ for (var i = 1; i < arguments.length; i++) {
101
+ var source = arguments[i];
102
+ for (var key in source) {
103
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
104
+ target[key] = source[key];
105
+ }
106
+ }
107
+ }
108
+ return target;
109
+ };
110
+ return _extends$1.apply(this, arguments);
111
+ }
112
+ var SvgCheck12 = function SvgCheck122(props) {
113
+ return /* @__PURE__ */ React__namespace.createElement("svg", _extends$1({
114
+ width: 12,
115
+ height: 12,
116
+ viewBox: "0 0 12 12",
117
+ xmlns: "http://www.w3.org/2000/svg"
118
+ }, props), _path || (_path = /* @__PURE__ */ React__namespace.createElement("path", {
119
+ fillRule: "evenodd",
120
+ clipRule: "evenodd",
121
+ d: "M11.7071 1.79289C12.0976 2.18342 12.0976 2.81658 11.7071 3.20711L4.70711 10.2071C4.31658 10.5976 3.68342 10.5976 3.29289 10.2071L0.292893 7.20711C-0.0976311 6.81658 -0.0976311 6.18342 0.292893 5.79289C0.683417 5.40237 1.31658 5.40237 1.70711 5.79289L4 8.08579L10.2929 1.79289C10.6834 1.40237 11.3166 1.40237 11.7071 1.79289Z"
122
+ })));
123
+ };
124
+ function getSizeHeight$2(size) {
125
+ switch (size) {
126
+ case next.Sizes.SMALL:
127
+ return 30;
128
+ case next.Sizes.MEDIUM:
129
+ return 38;
130
+ case next.Sizes.LARGE:
131
+ return 48;
132
+ default:
133
+ throw new Error(`Invalid form size "${size}"`);
134
+ }
135
+ }
136
+ function getSizeHorizontalPadding(size) {
137
+ switch (size) {
138
+ case next.Sizes.SMALL:
139
+ return 8;
140
+ case next.Sizes.MEDIUM:
141
+ return 12;
142
+ case next.Sizes.LARGE:
143
+ return 16;
144
+ default:
145
+ throw new Error(`Invalid form size "${size}"`);
146
+ }
147
+ }
148
+ function getSizeVerticalPadding(size) {
149
+ switch (size) {
150
+ case next.Sizes.SMALL:
151
+ return 3;
152
+ case next.Sizes.MEDIUM:
153
+ return 7;
154
+ case next.Sizes.LARGE:
155
+ return 11;
156
+ default:
157
+ throw new Error(`Invalid form size "${size}"`);
158
+ }
159
+ }
160
+ function getShapeBorderRadius(shape) {
161
+ switch (shape) {
162
+ case next.Shapes.SQUARE:
163
+ return 0;
164
+ case next.Shapes.ROUNDED:
165
+ return 4;
166
+ case next.Shapes.PILL:
167
+ return 500;
168
+ default:
169
+ throw new Error(`Invalid form shape "${shape}"`);
170
+ }
171
+ }
172
+ function getContrastBorderColor(contrast, error) {
173
+ switch (contrast) {
174
+ case next.Contrasts.LIGHT:
175
+ return error ? "rgba(255, 0, 0, 0.7)" : "rgba(0, 0, 0, 0.25)";
176
+ case next.Contrasts.DARK:
177
+ return error ? "rgba(255, 0, 0, 0.7)" : "rgba(255, 255, 255, 0.6)";
178
+ default:
179
+ throw new Error(`Invalid form contrast "${contrast}"`);
180
+ }
181
+ }
182
+ function getContrastBackgroundColor(contrast) {
183
+ switch (contrast) {
184
+ case next.Contrasts.LIGHT:
185
+ return "white";
186
+ case next.Contrasts.DARK:
187
+ return "rgba(0, 0, 0, 0.7)";
188
+ default:
189
+ throw new Error(`Invalid form contrast "${contrast}"`);
190
+ }
191
+ }
192
+ function getContrastColor$1(contrast) {
193
+ switch (contrast) {
194
+ case next.Contrasts.LIGHT:
195
+ return "rgba(0, 0, 0, 0.95)";
196
+ case next.Contrasts.DARK:
197
+ return "white";
198
+ default:
199
+ throw new Error(`Invalid form contrast "${contrast}"`);
200
+ }
201
+ }
202
+ function getContrastPlaceholderColor(contrast) {
203
+ switch (contrast) {
204
+ case next.Contrasts.LIGHT:
205
+ return "rgba(0, 0, 0, 0.3)";
206
+ case next.Contrasts.DARK:
207
+ return "rgba(255,255,255,0.3)";
208
+ default:
209
+ throw new Error(`Invalid form contrast "${contrast}"`);
210
+ }
211
+ }
212
+ function cssField() {
213
+ return styled.css`
214
+ display: block;
215
+ width: 100%;
216
+ outline: none;
217
+ border-width: 1px;
218
+ border-style: solid;
219
+ transition: border-color 200ms;
220
+ ${(props) => cssMediaRules.cssMediaRules([props.shape, props.size, props.contrast, props.brandColor], ([
221
+ shape = next.Shapes.ROUNDED,
222
+ size = next.Sizes.MEDIUM,
223
+ contrast = next.Contrasts.LIGHT,
224
+ brandColor = { swatch: { hue: 0, saturation: 0, lightness: 0 }, alpha: 1 }
225
+ ]) => styled.css`
226
+ padding: ${getSizeVerticalPadding(size)}px ${getSizeHorizontalPadding(size)}px;
227
+ border-radius: ${getShapeBorderRadius(shape)}px;
228
+ border-color: ${getContrastBorderColor(contrast, props.error)};
229
+ color: ${getContrastColor$1(contrast)};
230
+ background-color: ${getContrastBackgroundColor(contrast)};
231
+
232
+ :focus,
233
+ :focus-within {
234
+ border-color: ${next.colorToString(brandColor)};
235
+ }
236
+
237
+ ::placeholder {
238
+ color: ${getContrastPlaceholderColor(contrast)};
239
+ }
240
+ `)}
241
+ `;
242
+ }
243
+ function getSizeHeight$1(size) {
244
+ switch (size) {
245
+ case next.Sizes.SMALL:
246
+ return 36;
247
+ case next.Sizes.MEDIUM:
248
+ return 42;
249
+ case next.Sizes.LARGE:
250
+ return 48;
251
+ default:
252
+ throw new Error(`Invalid form size "${size}"`);
253
+ }
254
+ }
255
+ const Base$2 = styled__default["default"].input.withConfig({
256
+ shouldForwardProp: (prop, defaultValidator) => !["shape", "size", "contrast", "brandColor", "error"].includes(prop.toString()) && defaultValidator(prop)
257
+ })`
258
+ ${cssField()}
259
+ ${(props) => cssMediaRules.cssMediaRules([props.size], ([size = next.Sizes.MEDIUM]) => styled.css`
260
+ min-height: ${getSizeHeight$1(size)}px;
261
+ max-height: ${getSizeHeight$1(size)}px;
262
+ `)}
263
+ `;
264
+ var Input$2 = React.forwardRef(function Input2(_a, ref) {
265
+ var _b = _a, {
266
+ error = false,
267
+ form
268
+ } = _b, restOfProps = __objRest(_b, [
269
+ "error",
270
+ "form"
271
+ ]);
272
+ const {
273
+ shape,
274
+ size,
275
+ contrast,
276
+ brandColor
277
+ } = next.useFormContext();
278
+ return /* @__PURE__ */ jsxRuntime.jsx(Base$2, __spreadProps(__spreadValues({}, restOfProps), {
279
+ ref,
280
+ error,
281
+ shape,
282
+ size,
283
+ contrast,
284
+ brandColor
285
+ }));
286
+ });
287
+ const Container$3 = styled__default["default"].div.withConfig({
288
+ shouldForwardProp: (prop) => !["width", "margin"].includes(prop.toString())
289
+ })`
290
+ display: flex;
291
+ flex-direction: column;
292
+ ${cssMediaRules.cssMargin()};
293
+ `;
294
+ const Label$2 = styled__default["default"].div`
295
+ max-width: 120px;
296
+ min-width: 60px;
297
+ height: 8px;
298
+ border-radius: 2px;
299
+ background-color: #a1a8c2;
300
+ opacity: 0.4;
301
+ margin-bottom: 8px;
302
+ `;
303
+ const Input$1 = styled__default["default"].div`
304
+ min-width: 80px;
305
+ height: 32px;
306
+ border-radius: 4px;
307
+ border-width: 2px;
308
+ border-style: solid;
309
+ border-color: #a1a8c2;
310
+ opacity: 0.4;
311
+ `;
312
+ const Button = styled__default["default"].div`
313
+ min-width: 140px;
314
+ height: 32px;
315
+ border-radius: 4px;
316
+ background-color: #a1a8c2;
317
+ opacity: 0.4;
318
+ `;
319
+ var Placeholder = React.forwardRef(function Placeholder2({
320
+ className,
321
+ margin
322
+ }, ref) {
323
+ return /* @__PURE__ */ jsxRuntime.jsxs(Container$3, {
324
+ ref,
325
+ className,
326
+ margin,
327
+ children: [/* @__PURE__ */ jsxRuntime.jsxs("div", {
328
+ style: {
329
+ display: "flex",
330
+ flexDirection: "column",
331
+ marginBottom: 16
332
+ },
333
+ children: [/* @__PURE__ */ jsxRuntime.jsx(Label$2, {}), /* @__PURE__ */ jsxRuntime.jsx(Input$1, {})]
334
+ }), /* @__PURE__ */ jsxRuntime.jsxs("div", {
335
+ style: {
336
+ display: "flex",
337
+ flexDirection: "column",
338
+ marginBottom: 16
339
+ },
340
+ children: [/* @__PURE__ */ jsxRuntime.jsx(Label$2, {}), /* @__PURE__ */ jsxRuntime.jsx(Input$1, {})]
341
+ }), /* @__PURE__ */ jsxRuntime.jsx("div", {
342
+ style: {
343
+ display: "flex",
344
+ flexDirection: "column",
345
+ justifyContent: "flex-end"
346
+ },
347
+ children: /* @__PURE__ */ jsxRuntime.jsx(Button, {})
348
+ })]
349
+ });
350
+ });
351
+ function getSizeHeight(size) {
352
+ switch (size) {
353
+ case next.Sizes.SMALL:
354
+ return 14;
355
+ case next.Sizes.MEDIUM:
356
+ return 18;
357
+ case next.Sizes.LARGE:
358
+ return 22;
359
+ default:
360
+ throw new Error(`Invalid form size "${size}"`);
361
+ }
362
+ }
363
+ function getContrastColor(contrast) {
364
+ switch (contrast) {
365
+ case next.Contrasts.LIGHT:
366
+ return "rgba(0, 0, 0, 0.8)";
367
+ case next.Contrasts.DARK:
368
+ return "rgba(255, 255, 255, 0.95)";
369
+ default:
370
+ throw new Error(`Invalid form contrast "${contrast}"`);
371
+ }
372
+ }
373
+ const Base$1 = styled__default["default"].label.withConfig({
374
+ shouldForwardProp: (prop, defaultValidator) => !["contrast", "size", "textStyle", "textColor"].includes(prop.toString()) && defaultValidator(prop)
375
+ })`
376
+ display: block;
377
+ margin: 0 0 0.25em 0;
378
+ ${cssMediaRules.cssTextStyle()}
379
+ ${(props) => cssMediaRules.cssMediaRules([props.size, props.contrast, props.textColor], ([size = next.Sizes.MEDIUM, contrast = next.Contrasts.LIGHT, textColor]) => styled.css`
380
+ min-height: ${getSizeHeight(size)}px;
381
+ color: ${textColor == null ? getContrastColor(contrast) : next.colorToString(textColor)};
382
+ `)}
383
+ `;
384
+ function Label$1(props) {
385
+ const {
386
+ contrast,
387
+ size,
388
+ labelTextStyle,
389
+ labelTextColor
390
+ } = next.useFormContext();
391
+ return /* @__PURE__ */ jsxRuntime.jsx(Base$1, __spreadProps(__spreadValues({}, props), {
392
+ contrast,
393
+ size,
394
+ textStyle: labelTextStyle,
395
+ textColor: labelTextColor
396
+ }));
397
+ }
398
+ var SingleLineTextTableField = React.forwardRef(function SingleLineTextTableField2(_c, ref) {
399
+ var _d = _c, {
400
+ id,
401
+ label = "",
402
+ name,
403
+ error,
404
+ hideLabel = false
405
+ } = _d, restOfProps = __objRest(_d, [
406
+ "id",
407
+ "label",
408
+ "name",
409
+ "error",
410
+ "hideLabel"
411
+ ]);
412
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
413
+ children: [!hideLabel && /* @__PURE__ */ jsxRuntime.jsx(Label$1, {
414
+ htmlFor: id,
415
+ children: label
416
+ }), /* @__PURE__ */ jsxRuntime.jsx(Input$2, __spreadProps(__spreadValues({}, restOfProps), {
417
+ "aria-label": label,
418
+ ref,
419
+ id,
420
+ name,
421
+ type: "text",
422
+ error: error != null
423
+ }))]
424
+ });
425
+ });
426
+ const Base = styled__default["default"].textarea.withConfig({
427
+ shouldForwardProp: (prop, defaultValidator) => !["error", "shape", "size", "contrast", "brandColor"].includes(prop.toString()) && defaultValidator(prop)
428
+ })`
429
+ resize: vertical;
430
+ ${cssField()}
431
+ `;
432
+ var TextArea = React.forwardRef(function TextArea2(_e, ref) {
433
+ var _f = _e, {
434
+ error = false,
435
+ form
436
+ } = _f, restOfProps = __objRest(_f, [
437
+ "error",
438
+ "form"
439
+ ]);
440
+ const {
441
+ shape,
442
+ size,
443
+ contrast,
444
+ brandColor
445
+ } = next.useFormContext();
446
+ return /* @__PURE__ */ jsxRuntime.jsx(Base, __spreadProps(__spreadValues({}, restOfProps), {
447
+ ref,
448
+ rows: 4,
449
+ error,
450
+ shape,
451
+ size,
452
+ contrast,
453
+ brandColor
454
+ }));
455
+ });
456
+ var LongTextTableField = React.forwardRef(function LongTextTableField2(_g2, ref) {
457
+ var _h = _g2, {
458
+ id,
459
+ label = "",
460
+ error,
461
+ hideLabel = false
462
+ } = _h, restOfProps = __objRest(_h, [
463
+ "id",
464
+ "label",
465
+ "error",
466
+ "hideLabel"
467
+ ]);
468
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
469
+ children: [!hideLabel && /* @__PURE__ */ jsxRuntime.jsx(Label$1, {
470
+ htmlFor: id,
471
+ children: label
472
+ }), /* @__PURE__ */ jsxRuntime.jsx(TextArea, __spreadProps(__spreadValues({}, restOfProps), {
473
+ "aria-label": label,
474
+ ref,
475
+ id,
476
+ error: error != null
477
+ }))]
478
+ });
479
+ });
480
+ function getCheckmarkColor$1({
481
+ swatch: {
482
+ hue: h,
483
+ saturation: s,
484
+ lightness: l
485
+ },
486
+ alpha: a
487
+ }) {
488
+ return ColorHelper__default["default"]({
489
+ h,
490
+ s,
491
+ l
492
+ }).alpha(a).isLight() ? "rgba(0, 0, 0, 0.7)" : "rgba(255, 255, 255, 0.95)";
493
+ }
494
+ const Container$2 = styled__default["default"].div.withConfig({
495
+ shouldForwardProp: (prop) => !["size"].includes(prop)
496
+ })`
497
+ position: relative;
498
+ ${(props) => cssMediaRules.cssMediaRules([props.size], ([size = next.Sizes.MEDIUM]) => styled.css`
499
+ height: ${getSizeHeight(size)}px;
500
+ width: ${getSizeHeight(size)}px;
501
+ `)}
502
+ `;
503
+ const FakeCheckbox = styled__default["default"].div.withConfig({
504
+ shouldForwardProp: (prop) => !["contrast", "error"].includes(prop)
505
+ })`
506
+ position: absolute;
507
+ width: 100%;
508
+ height: 100%;
509
+ border-style: solid;
510
+ border-radius: 4px;
511
+ pointer-events: none;
512
+ border-width: 1px;
513
+ ${(props) => cssMediaRules.cssMediaRules([props.contrast], ([contrast = next.Contrasts.LIGHT]) => styled.css`
514
+ border-color: ${getContrastBorderColor(contrast, props.error)};
515
+ background-color: ${getContrastBackgroundColor(contrast)};
516
+ `)}
517
+ `;
518
+ const HiddenCheckbox = styled__default["default"].input.withConfig({
519
+ shouldForwardProp: (prop, defaultValidator) => !["size", "brandColor", "contrast", "error"].includes(prop) && defaultValidator(prop)
520
+ })`
521
+ position: absolute;
522
+ opacity: 0;
523
+ width: 100%;
524
+ height: 100%;
525
+ cursor: pointer;
526
+
527
+ &:disabled {
528
+ cursor: no-drop;
529
+
530
+ & ~ ${FakeCheckbox} {
531
+ opacity: 0.5;
532
+ }
533
+ }
534
+
535
+ &:checked ~ ${FakeCheckbox} {
536
+ ${(props) => cssMediaRules.cssMediaRules([props.brandColor], ([{
537
+ swatch = {
538
+ hue: 0,
539
+ saturation: 0,
540
+ lightness: 0
541
+ },
542
+ alpha = 1
543
+ } = {}]) => styled.css`
544
+ background-color: ${next.colorToString({
545
+ swatch,
546
+ alpha
547
+ })};
548
+ `)}
549
+ border-color: transparent;
550
+
551
+ &::after {
552
+ content: '';
553
+ position: absolute;
554
+ box-sizing: content-box;
555
+ width: 25%;
556
+ height: 50%;
557
+ ${(props) => cssMediaRules.cssMediaRules([props.size], ([size = next.Sizes.MEDIUM]) => styled.css`
558
+ border-width: ${getSizeHeight(size) * 0.1}px;
559
+ border-left: 0;
560
+ border-top: 0;
561
+ `)}
562
+ border-style: solid;
563
+ ${(props) => cssMediaRules.cssMediaRules([props.brandColor], ([{
564
+ swatch = {
565
+ hue: 0,
566
+ saturation: 0,
567
+ lightness: 0
568
+ },
569
+ alpha = 1
570
+ } = {}]) => styled.css`
571
+ border-color: ${getCheckmarkColor$1({
572
+ swatch,
573
+ alpha
574
+ })};
575
+ `)}
576
+ transform: rotate(45deg) translate3d(91%, -23%, 0);
577
+ }
578
+ }
579
+
580
+ &:not(:disabled) {
581
+ &:focus ~ ${FakeCheckbox} {
582
+ ${(props) => cssMediaRules.cssMediaRules([props.brandColor], ([brandColor = {
583
+ swatch: {
584
+ hue: 0,
585
+ saturation: 0,
586
+ lightness: 0
587
+ },
588
+ alpha: 1
589
+ }]) => styled.css`
590
+ border-color: ${next.colorToString(brandColor)};
591
+ `)}
592
+ }
593
+ }
594
+
595
+ &:not(:disabled):checked {
596
+ &:focus ~ ${FakeCheckbox} {
597
+ ${(props) => cssMediaRules.cssMediaRules([props.contrast], ([contrast = next.Contrasts.LIGHT]) => styled.css`
598
+ border-color: ${getContrastBorderColor(contrast, props.error)};
599
+ `)}
600
+ }
601
+ }
602
+ `;
603
+ var Checkbox = React.forwardRef(function Checkbox2(_i, ref) {
604
+ var _j = _i, {
605
+ error,
606
+ className,
607
+ style,
608
+ form
609
+ } = _j, restOfProps = __objRest(_j, [
610
+ "error",
611
+ "className",
612
+ "style",
613
+ "form"
614
+ ]);
615
+ const {
616
+ size,
617
+ contrast,
618
+ brandColor
619
+ } = next.useFormContext();
620
+ return /* @__PURE__ */ jsxRuntime.jsxs(Container$2, {
621
+ size,
622
+ children: [/* @__PURE__ */ jsxRuntime.jsx(HiddenCheckbox, __spreadProps(__spreadValues({}, restOfProps), {
623
+ type: "checkbox",
624
+ ref,
625
+ error,
626
+ size,
627
+ contrast,
628
+ brandColor
629
+ })), /* @__PURE__ */ jsxRuntime.jsx(FakeCheckbox, {
630
+ className,
631
+ error,
632
+ contrast,
633
+ style
634
+ })]
635
+ });
636
+ });
637
+ const StyledLabel$2 = styled__default["default"](Label$1)`
638
+ display: flex;
639
+ align-items: center;
640
+ margin: 0;
641
+ ${(props) => cssMediaRules.cssMediaRules([props.size], ([size = next.Sizes.MEDIUM]) => styled.css`
642
+ min-height: ${getSizeHeight$1(size)}px;
643
+ max-height: ${getSizeHeight$1(size)}px;
644
+ `)}
645
+ `;
646
+ const CheckboxContainer$1 = styled__default["default"].span`
647
+ margin-right: 8px;
648
+ `;
649
+ var CheckboxTableField = React.forwardRef(function CheckboxTableField2(_k, ref) {
650
+ var _l = _k, {
651
+ form,
652
+ id,
653
+ name,
654
+ label = "",
655
+ value = false,
656
+ error
657
+ } = _l, restOfProps = __objRest(_l, [
658
+ "form",
659
+ "id",
660
+ "name",
661
+ "label",
662
+ "value",
663
+ "error"
664
+ ]);
665
+ const {
666
+ size
667
+ } = next.useFormContext();
668
+ function handleChange(event) {
669
+ form.setFieldValue(name, event.currentTarget.checked);
670
+ }
671
+ return /* @__PURE__ */ jsxRuntime.jsxs(StyledLabel$2, {
672
+ htmlFor: id,
673
+ size,
674
+ children: [/* @__PURE__ */ jsxRuntime.jsx(CheckboxContainer$1, {
675
+ children: /* @__PURE__ */ jsxRuntime.jsx(Checkbox, __spreadProps(__spreadValues({}, restOfProps), {
676
+ "aria-label": label,
677
+ checked: value,
678
+ onChange: handleChange,
679
+ ref,
680
+ id,
681
+ error: error != null
682
+ }))
683
+ }), label]
684
+ });
685
+ });
686
+ const MainLabel = styled__default["default"](Label$1)`
687
+ margin: 0 0 4px 0;
688
+ `;
689
+ const StyledLabel$1 = styled__default["default"](Label$1)`
690
+ display: flex;
691
+ align-items: center;
692
+ margin: 8px 0;
693
+
694
+ &:last-of-type {
695
+ margin-bottom: 0;
696
+ }
697
+ `;
698
+ const CheckboxContainer = styled__default["default"].span`
699
+ margin-right: 8px;
700
+ `;
701
+ var MultipleSelectTableField = React.forwardRef(function MultipleSelectTableField2(_m, ref) {
702
+ var _n = _m, {
703
+ tableColumn,
704
+ label = "",
705
+ required,
706
+ value = [],
707
+ onChange,
708
+ hideLabel = false
709
+ } = _n, restOfProps = __objRest(_n, [
710
+ "tableColumn",
711
+ "label",
712
+ "required",
713
+ "value",
714
+ "onChange",
715
+ "hideLabel"
716
+ ]);
717
+ const handle = React.useRef({
718
+ validity: {
719
+ valueMissing: required === true && value.length === 0,
720
+ typeMismatch: false
721
+ }
722
+ });
723
+ React.useImperativeHandle(ref, () => handle.current, []);
724
+ function handleChange(event) {
725
+ handle.current.validity.valueMissing = required === true && !event.currentTarget.checked && value.filter((v) => v !== event.currentTarget.value).length === 0;
726
+ onChange(event);
727
+ }
728
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", {
729
+ children: [!hideLabel && /* @__PURE__ */ jsxRuntime.jsx(MainLabel, {
730
+ children: label
731
+ }), tableColumn.options.map((option) => /* @__PURE__ */ jsxRuntime.jsxs(StyledLabel$1, {
732
+ htmlFor: option.id,
733
+ children: [/* @__PURE__ */ jsxRuntime.jsx(CheckboxContainer, {
734
+ children: /* @__PURE__ */ jsxRuntime.jsx(Checkbox, __spreadProps(__spreadValues({}, restOfProps), {
735
+ "aria-label": label,
736
+ onChange: handleChange,
737
+ checked: value.includes(option.name),
738
+ id: option.id,
739
+ value: option.name
740
+ }))
741
+ }), option.name]
742
+ }, option.id))]
743
+ });
744
+ });
745
+ function getCheckmarkColor({
746
+ swatch: {
747
+ hue: h,
748
+ saturation: s,
749
+ lightness: l
750
+ } = {
751
+ hue: 0,
752
+ saturation: 0,
753
+ lightness: 0
754
+ },
755
+ alpha: a
756
+ }) {
757
+ return ColorHelper__default["default"]({
758
+ h,
759
+ s,
760
+ l
761
+ }).alpha(a).isLight() ? "rgba(0, 0, 0, 0.7)" : "rgba(255, 255, 255, 0.95)";
762
+ }
763
+ const Container$1 = styled__default["default"].div.withConfig({
764
+ shouldForwardProp: (prop) => !["size"].includes(prop.toString())
765
+ })`
766
+ position: relative;
767
+ ${(props) => cssMediaRules.cssMediaRules([props.size], ([size = next.Sizes.MEDIUM]) => styled.css`
768
+ height: ${getSizeHeight(size)}px;
769
+ width: ${getSizeHeight(size)}px;
770
+ `)}
771
+ `;
772
+ const FakeRadioButton = styled__default["default"].div.withConfig({
773
+ shouldForwardProp: (prop) => !["contrast", "error"].includes(prop.toString())
774
+ })`
775
+ position: absolute;
776
+ width: 100%;
777
+ height: 100%;
778
+ border-style: solid;
779
+ border-radius: 50%;
780
+ pointer-events: none;
781
+ border-width: 1px;
782
+ ${(props) => cssMediaRules.cssMediaRules([props.contrast], ([contrast = next.Contrasts.LIGHT]) => styled.css`
783
+ border-color: ${getContrastBorderColor(contrast, props.error)};
784
+ background-color: ${getContrastBackgroundColor(contrast)};
785
+ `)}
786
+ `;
787
+ const HiddenRadioButton = styled__default["default"].input.withConfig({
788
+ shouldForwardProp: (prop) => !["brandColor", "contrast", "error"].includes(prop.toString())
789
+ }).attrs({
790
+ type: "radio"
791
+ })`
792
+ position: absolute;
793
+ opacity: 0;
794
+ width: 100%;
795
+ height: 100%;
796
+ cursor: pointer;
797
+
798
+ &:disabled {
799
+ cursor: no-drop;
800
+
801
+ & ~ ${FakeRadioButton} {
802
+ opacity: 0.5;
803
+ }
804
+ }
805
+
806
+ &:checked ~ ${FakeRadioButton} {
807
+ ${(props) => cssMediaRules.cssMediaRules([props.brandColor], ([brandColor = {
808
+ swatch: {
809
+ hue: 0,
810
+ saturation: 0,
811
+ lightness: 0
812
+ },
813
+ alpha: 1
814
+ }]) => styled.css`
815
+ background-color: ${next.colorToString(brandColor)};
816
+ `)}
817
+ border-color: transparent;
818
+
819
+ &::after {
820
+ content: '';
821
+ position: absolute;
822
+ box-sizing: content-box;
823
+ top: 50%;
824
+ left: 50%;
825
+ width: 50%;
826
+ height: 50%;
827
+ border-radius: 50%;
828
+ transform: translate(-50%, -50%);
829
+ ${(props) => cssMediaRules.cssMediaRules([props.brandColor], ([brandColor = {
830
+ swatch: {
831
+ hue: 0,
832
+ saturation: 0,
833
+ lightness: 0
834
+ },
835
+ alpha: 1
836
+ }]) => styled.css`
837
+ background-color: ${getCheckmarkColor(brandColor)};
838
+ `)}
839
+ }
840
+ }
841
+
842
+ &:not(:disabled) {
843
+ &:focus ~ ${FakeRadioButton} {
844
+ ${(props) => cssMediaRules.cssMediaRules([props.brandColor], ([brandColor = {
845
+ swatch: {
846
+ hue: 0,
847
+ saturation: 0,
848
+ lightness: 0
849
+ },
850
+ alpha: 1
851
+ }]) => styled.css`
852
+ border-color: ${next.colorToString(brandColor)};
853
+ `)}
854
+ }
855
+ }
856
+
857
+ &:not(:disabled):checked {
858
+ &:focus ~ ${FakeRadioButton} {
859
+ ${(props) => cssMediaRules.cssMediaRules([props.contrast], ([contrast = next.Contrasts.LIGHT]) => styled.css`
860
+ border-color: ${getContrastBorderColor(contrast, props.error)};
861
+ `)}
862
+ }
863
+ }
864
+ `;
865
+ var RadioButton = React.forwardRef(function RadioButton2(_o, ref) {
866
+ var _p = _o, {
867
+ error,
868
+ className,
869
+ style,
870
+ form
871
+ } = _p, restOfProps = __objRest(_p, [
872
+ "error",
873
+ "className",
874
+ "style",
875
+ "form"
876
+ ]);
877
+ const {
878
+ size,
879
+ contrast,
880
+ brandColor
881
+ } = next.useFormContext();
882
+ return /* @__PURE__ */ jsxRuntime.jsxs(Container$1, {
883
+ size,
884
+ children: [/* @__PURE__ */ jsxRuntime.jsx(HiddenRadioButton, __spreadProps(__spreadValues({}, restOfProps), {
885
+ ref,
886
+ error,
887
+ contrast,
888
+ brandColor
889
+ })), /* @__PURE__ */ jsxRuntime.jsx(FakeRadioButton, {
890
+ className,
891
+ error,
892
+ contrast,
893
+ style
894
+ })]
895
+ });
896
+ });
897
+ const StyledLabel = styled__default["default"](Label$1)`
898
+ display: flex;
899
+ align-items: center;
900
+ margin: 8px 0;
901
+
902
+ &:last-of-type {
903
+ margin-bottom: 0;
904
+ }
905
+ `;
906
+ const RadioButtonContainer = styled__default["default"].span`
907
+ margin-right: 8px;
908
+ `;
909
+ var TableColumnRadioButtonGroup = React.forwardRef(function TableColumnRadioButtonGroup2(_q, ref) {
910
+ var _r = _q, {
911
+ tableColumn,
912
+ label = "",
913
+ value = "",
914
+ required = false,
915
+ hideLabel = false,
916
+ onChange
917
+ } = _r, restOfProps = __objRest(_r, [
918
+ "tableColumn",
919
+ "label",
920
+ "value",
921
+ "required",
922
+ "hideLabel",
923
+ "onChange"
924
+ ]);
925
+ const handle = React.useRef({
926
+ validity: {
927
+ valueMissing: required === true && value === "",
928
+ typeMismatch: false
929
+ }
930
+ });
931
+ React.useImperativeHandle(ref, () => handle.current, []);
932
+ function handleChange(event) {
933
+ handle.current.validity.valueMissing = required === true && !event.currentTarget.checked;
934
+ onChange(event);
935
+ }
936
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", {
937
+ children: [!hideLabel && /* @__PURE__ */ jsxRuntime.jsx(Label$1, {
938
+ as: "p",
939
+ children: label
940
+ }), tableColumn.options.map((option) => /* @__PURE__ */ jsxRuntime.jsxs(StyledLabel, {
941
+ htmlFor: option.id,
942
+ "aria-label": label,
943
+ children: [/* @__PURE__ */ jsxRuntime.jsx(RadioButtonContainer, {
944
+ children: /* @__PURE__ */ jsxRuntime.jsx(RadioButton, __spreadProps(__spreadValues({}, restOfProps), {
945
+ onChange: handleChange,
946
+ checked: value === option.name,
947
+ id: option.id,
948
+ value: option.name
949
+ }))
950
+ }), option.name]
951
+ }, option.id))]
952
+ });
953
+ });
954
+ const Container = styled__default["default"].div.withConfig({
955
+ shouldForwardProp: (prop) => !["error", "shape", "size", "contrast", "brandColor"].includes(prop.toString())
956
+ })`
957
+ ${cssField()}
958
+ display: flex;
959
+ align-items: center;
960
+ position: relative;
961
+ user-select: none;
962
+ border-color: #f19eb9;
963
+
964
+ &:focus,
965
+ &:focus-within {
966
+ border-color: #e54e7f;
967
+ }
968
+
969
+ ${(props) => cssMediaRules.cssMediaRules([props.size, props.contrast], ([size = next.Sizes.MEDIUM, contrast = next.Contrasts.LIGHT]) => styled.css`
970
+ min-height: ${getSizeHeight$2(size)}px;
971
+ max-height: ${getSizeHeight$2(size)}px;
972
+
973
+ &::after {
974
+ content: '';
975
+ position: absolute;
976
+ right: ${getSizeHorizontalPadding(size)}px;
977
+ top: 50%;
978
+ transform: translate3d(0, -25%, 0);
979
+ border: solid 0.35em transparent;
980
+ border-top-color: ${getContrastColor$1(contrast)};
981
+ }
982
+ `)}
983
+ `;
984
+ const Select = styled__default["default"].select`
985
+ appearance: none;
986
+ position: absolute;
987
+ top: 0;
988
+ left: 0;
989
+ opacity: 0;
990
+ width: 100%;
991
+ height: 100%;
992
+ `;
993
+ var TableColumnSingleSelect = React.forwardRef(function TableColumnSingleSelect2(_s, ref) {
994
+ var _t = _s, {
995
+ id,
996
+ tableColumn,
997
+ value = "",
998
+ label = "",
999
+ error = false,
1000
+ hideLabel = false,
1001
+ form
1002
+ } = _t, restOfProps = __objRest(_t, [
1003
+ "id",
1004
+ "tableColumn",
1005
+ "value",
1006
+ "label",
1007
+ "error",
1008
+ "hideLabel",
1009
+ "form"
1010
+ ]);
1011
+ const {
1012
+ shape,
1013
+ size,
1014
+ contrast,
1015
+ brandColor
1016
+ } = next.useFormContext();
1017
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1018
+ children: [!hideLabel && /* @__PURE__ */ jsxRuntime.jsx(Label$1, {
1019
+ htmlFor: id,
1020
+ children: label
1021
+ }), /* @__PURE__ */ jsxRuntime.jsxs(Container, {
1022
+ error,
1023
+ shape,
1024
+ size,
1025
+ contrast,
1026
+ brandColor,
1027
+ children: [/* @__PURE__ */ jsxRuntime.jsx("span", {
1028
+ children: value === "" ? "-" : value
1029
+ }), /* @__PURE__ */ jsxRuntime.jsxs(Select, __spreadProps(__spreadValues({}, restOfProps), {
1030
+ "aria-label": label,
1031
+ ref,
1032
+ id,
1033
+ value,
1034
+ children: [/* @__PURE__ */ jsxRuntime.jsx("option", {
1035
+ value: "",
1036
+ children: "-"
1037
+ }), tableColumn.options.map((option) => /* @__PURE__ */ jsxRuntime.jsx("option", {
1038
+ value: option.name,
1039
+ children: option.name
1040
+ }, option.id))]
1041
+ }))]
1042
+ })]
1043
+ });
1044
+ });
1045
+ var SingleSelectTableField = React.forwardRef(function SingleSelectTableField2(_u, ref) {
1046
+ var _v = _u, {
1047
+ type
1048
+ } = _v, restOfProps = __objRest(_v, [
1049
+ "type"
1050
+ ]);
1051
+ return type === "select" ? /* @__PURE__ */ jsxRuntime.jsx(TableColumnSingleSelect, __spreadProps(__spreadValues({}, restOfProps), {
1052
+ ref
1053
+ })) : /* @__PURE__ */ jsxRuntime.jsx(TableColumnRadioButtonGroup, __spreadProps(__spreadValues({}, restOfProps), {
1054
+ ref
1055
+ }));
1056
+ });
1057
+ var PhoneNumberTableField = React.forwardRef(function PhoneNumberTableField2(_w, ref) {
1058
+ var _x = _w, {
1059
+ id,
1060
+ label = "",
1061
+ name,
1062
+ error,
1063
+ hideLabel = false
1064
+ } = _x, restOfProps = __objRest(_x, [
1065
+ "id",
1066
+ "label",
1067
+ "name",
1068
+ "error",
1069
+ "hideLabel"
1070
+ ]);
1071
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1072
+ children: [!hideLabel && /* @__PURE__ */ jsxRuntime.jsx(Label$1, {
1073
+ htmlFor: id,
1074
+ children: label
1075
+ }), /* @__PURE__ */ jsxRuntime.jsx(Input$2, __spreadProps(__spreadValues({}, restOfProps), {
1076
+ "aria-label": label,
1077
+ ref,
1078
+ id,
1079
+ name,
1080
+ type: "tel",
1081
+ error: error != null
1082
+ }))]
1083
+ });
1084
+ });
1085
+ var EmailTableField = React.forwardRef(function EmailTableField2(_y, ref) {
1086
+ var _z = _y, {
1087
+ id,
1088
+ label = "",
1089
+ name,
1090
+ error,
1091
+ hideLabel = false
1092
+ } = _z, restOfProps = __objRest(_z, [
1093
+ "id",
1094
+ "label",
1095
+ "name",
1096
+ "error",
1097
+ "hideLabel"
1098
+ ]);
1099
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1100
+ children: [!hideLabel && /* @__PURE__ */ jsxRuntime.jsx(Label$1, {
1101
+ htmlFor: id,
1102
+ children: label
1103
+ }), /* @__PURE__ */ jsxRuntime.jsx(Input$2, __spreadProps(__spreadValues({}, restOfProps), {
1104
+ "aria-label": label,
1105
+ ref,
1106
+ id,
1107
+ name,
1108
+ type: "email",
1109
+ error: error != null
1110
+ }))]
1111
+ });
1112
+ });
1113
+ var URLTableField = React.forwardRef(function URLTableField2(_A, ref) {
1114
+ var _B = _A, {
1115
+ id,
1116
+ label = "",
1117
+ name,
1118
+ error,
1119
+ hideLabel = false
1120
+ } = _B, restOfProps = __objRest(_B, [
1121
+ "id",
1122
+ "label",
1123
+ "name",
1124
+ "error",
1125
+ "hideLabel"
1126
+ ]);
1127
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1128
+ children: [!hideLabel && /* @__PURE__ */ jsxRuntime.jsx(Label$1, {
1129
+ htmlFor: id,
1130
+ children: label
1131
+ }), /* @__PURE__ */ jsxRuntime.jsx(Input$2, __spreadProps(__spreadValues({}, restOfProps), {
1132
+ "aria-label": label,
1133
+ ref,
1134
+ id,
1135
+ name,
1136
+ type: "url",
1137
+ error: error != null
1138
+ }))]
1139
+ });
1140
+ });
1141
+ var NumberTableField = React.forwardRef(function NumberTableField2(_C, ref) {
1142
+ var _D = _C, {
1143
+ id,
1144
+ label = "",
1145
+ name,
1146
+ error,
1147
+ hideLabel = false
1148
+ } = _D, restOfProps = __objRest(_D, [
1149
+ "id",
1150
+ "label",
1151
+ "name",
1152
+ "error",
1153
+ "hideLabel"
1154
+ ]);
1155
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1156
+ children: [!hideLabel && /* @__PURE__ */ jsxRuntime.jsx(Label$1, {
1157
+ htmlFor: id,
1158
+ children: label
1159
+ }), /* @__PURE__ */ jsxRuntime.jsx(Input$2, __spreadProps(__spreadValues({}, restOfProps), {
1160
+ "aria-label": label,
1161
+ ref,
1162
+ id,
1163
+ name,
1164
+ type: "number",
1165
+ error: error != null
1166
+ }))]
1167
+ });
1168
+ });
1169
+ const Label = styled__default["default"].div.withConfig({
1170
+ shouldForwardProp: (prop) => !["size"].includes(prop.toString())
1171
+ })`
1172
+ display: block;
1173
+ max-width: 120px;
1174
+ min-width: 60px;
1175
+ border-radius: 2px;
1176
+ background-color: #5f49f4;
1177
+ opacity: 0.4;
1178
+ ${(props) => cssMediaRules.cssMediaRules([props.size], ([size = next.Sizes.MEDIUM]) => styled.css`
1179
+ margin: calc(0.25 * ${getSizeHeight(size)}px + 2px) 0;
1180
+ min-height: ${0.5 * getSizeHeight(size)}px;
1181
+ max-height: ${0.5 * getSizeHeight(size)}px;
1182
+ `)}
1183
+ `;
1184
+ const Input = styled__default["default"].div.withConfig({
1185
+ shouldForwardProp: (prop) => !["shape", "size"].includes(prop.toString())
1186
+ })`
1187
+ display: block;
1188
+ width: 100%;
1189
+ border-width: 2px;
1190
+ border-style: solid;
1191
+ border-color: #5f49f4;
1192
+ opacity: 0.4;
1193
+ ${(props) => cssMediaRules.cssMediaRules([props.shape, props.size], ([shape = next.Shapes.ROUNDED, size = next.Sizes.MEDIUM]) => styled.css`
1194
+ min-height: ${getSizeHeight$1(size)}px;
1195
+ max-height: ${getSizeHeight$1(size)}px;
1196
+ border-radius: ${getShapeBorderRadius(shape)}px;
1197
+ `)}
1198
+ `;
1199
+ function PlaceholderTableField() {
1200
+ const {
1201
+ size,
1202
+ shape
1203
+ } = next.useFormContext();
1204
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1205
+ children: [/* @__PURE__ */ jsxRuntime.jsx(Label, {
1206
+ size
1207
+ }), /* @__PURE__ */ jsxRuntime.jsx(Input, {
1208
+ shape,
1209
+ size
1210
+ })]
1211
+ });
1212
+ }
1213
+ function getTypeMismatchErrorMessage(tableColumn, label) {
1214
+ switch ((tableColumn || {}).__typename) {
1215
+ case "PhoneNumberTableColumn":
1216
+ return `${label} field must be a valid phone number.`;
1217
+ case "EmailTableColumn":
1218
+ return `${label} field must be a valid email.`;
1219
+ case "URLTableColumn":
1220
+ return `${label} field must be a valid URL.`;
1221
+ case "NumberTableColumn":
1222
+ return `${label} field must be a valid number.`;
1223
+ case "SingleLineTextTableColumn":
1224
+ case "LongTextTableColumn":
1225
+ case "CheckboxTableColumn":
1226
+ default:
1227
+ return `${label} field is invalid.`;
1228
+ }
1229
+ }
1230
+ function getTableColumnField(tableColumn) {
1231
+ switch ((tableColumn || {}).__typename) {
1232
+ case "SingleLineTextTableColumn":
1233
+ return SingleLineTextTableField;
1234
+ case "LongTextTableColumn":
1235
+ return LongTextTableField;
1236
+ case "CheckboxTableColumn":
1237
+ return CheckboxTableField;
1238
+ case "MultipleSelectTableColumn":
1239
+ return MultipleSelectTableField;
1240
+ case "SingleSelectTableColumn":
1241
+ return SingleSelectTableField;
1242
+ case "PhoneNumberTableColumn":
1243
+ return PhoneNumberTableField;
1244
+ case "EmailTableColumn":
1245
+ return EmailTableField;
1246
+ case "URLTableColumn":
1247
+ return URLTableField;
1248
+ case "NumberTableColumn":
1249
+ return NumberTableField;
1250
+ default:
1251
+ return SingleLineTextTableField;
1252
+ }
1253
+ }
1254
+ function Field({
1255
+ tableColumn,
1256
+ tableFormField: {
1257
+ id,
1258
+ label = "",
1259
+ placeholder,
1260
+ required = false,
1261
+ hidden = false,
1262
+ type = "radio",
1263
+ hideLabel = false
1264
+ }
1265
+ }) {
1266
+ const TableColumnField = getTableColumnField(tableColumn);
1267
+ const input = React.useRef(null);
1268
+ if (!tableColumn)
1269
+ return /* @__PURE__ */ jsxRuntime.jsx(PlaceholderTableField, {});
1270
+ function validate() {
1271
+ let errorMessage;
1272
+ if (input.current) {
1273
+ const {
1274
+ validity = {}
1275
+ } = input.current;
1276
+ if (validity.valueMissing)
1277
+ errorMessage = `${label} is required.`;
1278
+ if (validity.typeMismatch)
1279
+ errorMessage = getTypeMismatchErrorMessage(tableColumn, label);
1280
+ }
1281
+ return errorMessage;
1282
+ }
1283
+ return /* @__PURE__ */ jsxRuntime.jsx(formik.Field, {
1284
+ name: tableColumn.name,
1285
+ validate,
1286
+ children: ({
1287
+ field,
1288
+ form
1289
+ }) => hidden ? /* @__PURE__ */ jsxRuntime.jsx("input", __spreadProps(__spreadValues({}, field), {
1290
+ ref: input,
1291
+ type: "hidden"
1292
+ })) : /* @__PURE__ */ jsxRuntime.jsx(TableColumnField, __spreadProps(__spreadValues({}, field), {
1293
+ type,
1294
+ form,
1295
+ tableColumn,
1296
+ ref: input,
1297
+ id,
1298
+ error: formik.getIn(form.touched, field.name) && formik.getIn(form.errors, field.name),
1299
+ label,
1300
+ placeholder,
1301
+ required,
1302
+ hideLabel
1303
+ }))
1304
+ });
1305
+ }
1306
+ var _g;
1307
+ function _extends() {
1308
+ _extends = Object.assign || function(target) {
1309
+ for (var i = 1; i < arguments.length; i++) {
1310
+ var source = arguments[i];
1311
+ for (var key in source) {
1312
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1313
+ target[key] = source[key];
1314
+ }
1315
+ }
1316
+ }
1317
+ return target;
1318
+ };
1319
+ return _extends.apply(this, arguments);
1320
+ }
1321
+ var SvgSpinner20 = function SvgSpinner202(props) {
1322
+ return /* @__PURE__ */ React__namespace.createElement("svg", _extends({
1323
+ xmlns: "http://www.w3.org/2000/svg",
1324
+ width: 20,
1325
+ height: 20
1326
+ }, props), _g || (_g = /* @__PURE__ */ React__namespace.createElement("g", {
1327
+ fill: "none",
1328
+ strokeWidth: 2,
1329
+ transform: "translate(1 1)"
1330
+ }, /* @__PURE__ */ React__namespace.createElement("circle", {
1331
+ stroke: "currentColor",
1332
+ cx: 9,
1333
+ cy: 9,
1334
+ r: 9,
1335
+ strokeOpacity: 0.4
1336
+ }), /* @__PURE__ */ React__namespace.createElement("path", {
1337
+ strokeLinecap: "round",
1338
+ d: "M9 18A9 9 0 0 0 9 0"
1339
+ }))));
1340
+ };
1341
+ const spin = styled.keyframes`
1342
+ from {
1343
+ transform: rotate(0deg);
1344
+ }
1345
+ to {
1346
+ transform: rotate(360deg);
1347
+ }
1348
+ `;
1349
+ const Icon = styled__default["default"](SvgSpinner20)`
1350
+ display: inline-flex;
1351
+ animation: ${spin} 1s linear infinite;
1352
+ stroke: currentColor;
1353
+ `;
1354
+ function Spinner() {
1355
+ return /* @__PURE__ */ jsxRuntime.jsx(Icon, {});
1356
+ }
1357
+ function useTableFormFieldRefs(propController, { fieldsCount }) {
1358
+ const [container, setContainer] = React.useState(null);
1359
+ const [items, setItems] = React.useState(Array(fieldsCount + 1).fill(null));
1360
+ const isInBuilder = next.useIsInBuilder();
1361
+ React.useEffect(() => {
1362
+ if (!isInBuilder)
1363
+ return;
1364
+ let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest);
1365
+ return () => {
1366
+ cancelAnimationFrame(animationFrameHandle);
1367
+ };
1368
+ function handleAnimationFrameRequest() {
1369
+ if (propController == null)
1370
+ return;
1371
+ if (container != null)
1372
+ propController.tableFormLayoutChange({ layout: boxModels.getBox(container) });
1373
+ items.map((item, index2) => {
1374
+ if (item == null)
1375
+ return;
1376
+ propController.tableFormFieldLayoutChange({ index: index2, layout: boxModels.getBox(item) });
1377
+ });
1378
+ animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest);
1379
+ }
1380
+ }, [propController, container, items, isInBuilder]);
1381
+ const itemRefs = React.useMemo(() => Array.from({ length: fieldsCount + 1 }).map((_, index2) => (item) => {
1382
+ setItems((is) => [...is.slice(0, index2), item, ...is.slice(index2 + 1)]);
1383
+ }), [fieldsCount, setItems]);
1384
+ return { container: setContainer, items: itemRefs };
1385
+ }
1386
+ const LOCAL_STORAGE_NAMESPACE = "@@makeswift/components/form";
1387
+ function getSizeFontSize(size) {
1388
+ switch (size) {
1389
+ case next.Sizes.SMALL:
1390
+ return 12;
1391
+ case next.Sizes.MEDIUM:
1392
+ return 14;
1393
+ case next.Sizes.LARGE:
1394
+ return 18;
1395
+ default:
1396
+ throw new Error(`Invalid form size "${size}"`);
1397
+ }
1398
+ }
1399
+ const GridForm = styled__default["default"].form.withConfig({
1400
+ shouldForwardProp: (prop) => !["size", "width", "margin"].includes(prop)
1401
+ })`
1402
+ display: flex;
1403
+ flex-wrap: wrap;
1404
+ width: 100%;
1405
+ ${(props) => cssMediaRules.cssMediaRules([props.size], ([size = next.Sizes.MEDIUM]) => styled.css`
1406
+ font-size: ${getSizeFontSize(size)}px;
1407
+ `)}
1408
+ ${cssMediaRules.cssMargin()}
1409
+ `;
1410
+ const GridItem = styled__default["default"].div.withConfig({
1411
+ shouldForwardProp: (prop) => !["grid", "index", "rowGap", "columnGap"].includes(prop)
1412
+ })`
1413
+ align-self: flex-end;
1414
+ flex-direction: column;
1415
+ ${cssMediaRules.cssGridItem()}
1416
+ `;
1417
+ function getAlignmentMargin(alignment) {
1418
+ switch (alignment) {
1419
+ case next.Alignments.LEFT:
1420
+ return "0 auto 0 0";
1421
+ case next.Alignments.RIGHT:
1422
+ return "0 0 0 auto";
1423
+ default:
1424
+ return "0 auto";
1425
+ }
1426
+ }
1427
+ const StyledButton = styled__default["default"]((props) => /* @__PURE__ */ jsxRuntime.jsx(Button$1["default"], __spreadProps(__spreadValues({}, props), {
1428
+ as: "button"
1429
+ }))).withConfig({
1430
+ shouldForwardProp: (prop) => !["alignment"].includes(prop.toString())
1431
+ })`
1432
+ display: flex;
1433
+ align-items: center;
1434
+ justify-content: center;
1435
+ ${(props) => cssMediaRules.cssMediaRules([props.size, props.alignment], ([size = next.Sizes.MEDIUM, alignment = next.Alignments.CENTER]) => styled.css`
1436
+ min-height: ${getSizeHeight$1(size)}px;
1437
+ max-height: ${getSizeHeight$1(size)}px;
1438
+ margin: ${getAlignmentMargin(alignment)};
1439
+ padding-top: 0;
1440
+ padding-bottom: 0;
1441
+ `)}
1442
+ `;
1443
+ const ErrorContainer = styled__default["default"].div`
1444
+ padding: 8px 16px;
1445
+ background-color: #f19eb9;
1446
+ border-radius: 4px;
1447
+ margin-top: 16px;
1448
+ `;
1449
+ const IconContainer = styled__default["default"].div`
1450
+ fill: currentColor;
1451
+ `;
1452
+ const ErrorMessage = styled__default["default"].p`
1453
+ font-size: 12px;
1454
+ margin: 8px 0;
1455
+ color: rgba(127, 0, 0, 0.95);
1456
+ `;
1457
+ function getTableColumnDefaultValue(tableColumn) {
1458
+ switch (tableColumn.__typename) {
1459
+ case "CheckboxTableColumn":
1460
+ return false;
1461
+ case "MultipleSelectTableColumn":
1462
+ return [];
1463
+ case "SingleLineTextTableColumn":
1464
+ case "LongTextTableColumn":
1465
+ case "SingleSelectTableColumn":
1466
+ case "PhoneNumberTableColumn":
1467
+ case "EmailTableColumn":
1468
+ case "URLTableColumn":
1469
+ case "NumberTableColumn":
1470
+ default:
1471
+ return "";
1472
+ }
1473
+ }
1474
+ const CREATE_TABLE_RECORD = client.gql`
1475
+ mutation CreateTableRecord($input: CreateTableRecordInput!) {
1476
+ createTableRecord(input: $input) {
1477
+ tableRecord {
1478
+ id
1479
+ }
1480
+ }
1481
+ }
1482
+ `;
1483
+ const Form = React.forwardRef(function Form2({
1484
+ id,
1485
+ tableId,
1486
+ fields: fieldsProp,
1487
+ submitLabel = "Submit",
1488
+ submitLink,
1489
+ shape,
1490
+ size,
1491
+ contrast,
1492
+ brandColor,
1493
+ gap,
1494
+ width,
1495
+ margin,
1496
+ submitTextStyle,
1497
+ submitVariant,
1498
+ submitTextColor,
1499
+ submitWidth,
1500
+ submitAlignment,
1501
+ labelTextStyle,
1502
+ labelTextColor
1503
+ }, ref) {
1504
+ const fields = React.useMemo(() => {
1505
+ var _a;
1506
+ return (_a = fieldsProp == null ? void 0 : fieldsProp.fields) != null ? _a : [];
1507
+ }, [fieldsProp]);
1508
+ const grid = React.useMemo(() => {
1509
+ var _a;
1510
+ return (_a = fieldsProp == null ? void 0 : fieldsProp.grid) != null ? _a : [];
1511
+ }, [fieldsProp]);
1512
+ const {
1513
+ data: {
1514
+ table
1515
+ } = {}
1516
+ } = next.useQuery(next.TABLE_BY_ID, {
1517
+ skip: tableId == null,
1518
+ variables: {
1519
+ id: tableId
1520
+ }
1521
+ });
1522
+ const [createTableRecord] = next.useMutation(CREATE_TABLE_RECORD);
1523
+ const [refEl, setRefEl] = React.useState(null);
1524
+ const [propControllers, setPropControllers] = React.useState(null);
1525
+ const [initialValues, setInitialValues] = React.useState(() => fields.reduce((acc, formField) => {
1526
+ const tableColumn = table && table.columns.find((field) => field.id === formField.tableColumnId);
1527
+ const defaultValue = formField ? formField.defaultValue : null;
1528
+ if (tableColumn) {
1529
+ acc[tableColumn.name] = defaultValue == null ? getTableColumnDefaultValue(tableColumn) : defaultValue;
1530
+ }
1531
+ return acc;
1532
+ }, {}));
1533
+ const controller = propControllers == null ? void 0 : propControllers.fields;
1534
+ const {
1535
+ container,
1536
+ items
1537
+ } = useTableFormFieldRefs(controller, {
1538
+ fieldsCount: fields.length
1539
+ });
1540
+ const [isDone, setIsDone] = React.useState(false);
1541
+ const linkRef = React.useRef(null);
1542
+ React.useImperativeHandle(ref, () => ({
1543
+ getBoxModel() {
1544
+ return refEl instanceof Element ? boxModels.getBox(refEl) : null;
1545
+ },
1546
+ setPropControllers
1547
+ }), [refEl, setPropControllers]);
1548
+ React.useEffect(() => {
1549
+ container(refEl);
1550
+ }, [container, refEl]);
1551
+ React.useEffect(() => {
1552
+ if (!isDone)
1553
+ return;
1554
+ let timeoutId = setTimeout(() => setIsDone(false), 2500);
1555
+ return () => clearTimeout(timeoutId);
1556
+ }, [isDone]);
1557
+ function getTableColumn({
1558
+ tableColumnId
1559
+ }) {
1560
+ return table && table.columns.find((field) => tableColumnId === field.id);
1561
+ }
1562
+ async function handleSubmit(values, {
1563
+ setSubmitting,
1564
+ resetForm,
1565
+ setStatus
1566
+ }) {
1567
+ if (table) {
1568
+ const columns = [];
1569
+ fields.forEach((field) => {
1570
+ const tableColumn = getTableColumn(field);
1571
+ if (tableColumn) {
1572
+ const data = values[tableColumn.name];
1573
+ if (data) {
1574
+ columns.push({
1575
+ columnId: field.tableColumnId,
1576
+ data
1577
+ });
1578
+ if (field.autofill) {
1579
+ localStorage.setItem(`${LOCAL_STORAGE_NAMESPACE}/${tableColumn.name}`, JSON.stringify(data));
1580
+ }
1581
+ }
1582
+ }
1583
+ });
1584
+ try {
1585
+ await createTableRecord({
1586
+ variables: {
1587
+ input: {
1588
+ data: {
1589
+ tableId: table.id,
1590
+ columns
1591
+ }
1592
+ }
1593
+ }
1594
+ });
1595
+ setIsDone(true);
1596
+ setInitialValues((prev) => fields.reduce((acc, field) => {
1597
+ const tableColumn = getTableColumn(field);
1598
+ if (tableColumn) {
1599
+ const data = values[tableColumn.name];
1600
+ if (data && field.autofill)
1601
+ return __spreadProps(__spreadValues({}, acc), {
1602
+ [tableColumn.name]: data
1603
+ });
1604
+ }
1605
+ return acc;
1606
+ }, __spreadValues({}, prev)));
1607
+ resetForm();
1608
+ if (linkRef.current != null)
1609
+ linkRef.current.click();
1610
+ } catch (error) {
1611
+ setStatus({
1612
+ error: "An unexpected error has occurred, please try again later"
1613
+ });
1614
+ } finally {
1615
+ setSubmitting(false);
1616
+ }
1617
+ }
1618
+ }
1619
+ React.useEffect(() => {
1620
+ setInitialValues((prev) => fields.reduce((acc, formField) => {
1621
+ const tableColumn = table && table.columns.find((field) => field.id === formField.tableColumnId);
1622
+ if (tableColumn && formField.autofill) {
1623
+ const storedValue = localStorage.getItem(`${LOCAL_STORAGE_NAMESPACE}/${tableColumn.name}`);
1624
+ if (storedValue) {
1625
+ try {
1626
+ acc[tableColumn.name] = JSON.parse(storedValue);
1627
+ } catch (e) {
1628
+ }
1629
+ }
1630
+ }
1631
+ return acc;
1632
+ }, __spreadValues({}, prev)));
1633
+ }, [fields, table]);
1634
+ return /* @__PURE__ */ jsxRuntime.jsx(next.Provider, {
1635
+ value: {
1636
+ shape,
1637
+ size,
1638
+ contrast,
1639
+ brandColor,
1640
+ labelTextStyle,
1641
+ labelTextColor
1642
+ },
1643
+ children: tableId == null ? /* @__PURE__ */ jsxRuntime.jsx(Placeholder, {
1644
+ ref: setRefEl,
1645
+ className: css.cx(width),
1646
+ margin
1647
+ }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
1648
+ children: /* @__PURE__ */ jsxRuntime.jsx(formik.Formik, {
1649
+ onSubmit: handleSubmit,
1650
+ initialValues,
1651
+ initialStatus: {
1652
+ error: null
1653
+ },
1654
+ enableReinitialize: true,
1655
+ children: (formik$1) => {
1656
+ const error = formik$1.status && formik$1.status.error;
1657
+ const errors = fields.map((field) => {
1658
+ const tableColumn = getTableColumn(field);
1659
+ return tableColumn && formik.getIn(formik$1.touched, tableColumn.name) && formik.getIn(formik$1.errors, tableColumn.name);
1660
+ }).filter((message) => typeof message === "string");
1661
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1662
+ children: [/* @__PURE__ */ jsxRuntime.jsxs(GridForm, {
1663
+ ref: setRefEl,
1664
+ id,
1665
+ className: css.cx(width),
1666
+ margin,
1667
+ size,
1668
+ onSubmit: formik$1.handleSubmit,
1669
+ onReset: formik$1.handleReset,
1670
+ noValidate: true,
1671
+ children: [fields.map((field, index2) => {
1672
+ const tableColumn = getTableColumn(field);
1673
+ return /* @__PURE__ */ jsxRuntime.jsx(GridItem, {
1674
+ ref: items[index2],
1675
+ grid,
1676
+ index: index2,
1677
+ rowGap: gap,
1678
+ columnGap: gap,
1679
+ children: /* @__PURE__ */ jsxRuntime.jsx(Field, {
1680
+ tableColumn,
1681
+ tableFormField: field
1682
+ })
1683
+ }, field.id);
1684
+ }), /* @__PURE__ */ jsxRuntime.jsxs(GridItem, {
1685
+ ref: items[fields.length],
1686
+ grid,
1687
+ index: fields.length,
1688
+ rowGap: gap,
1689
+ columnGap: gap,
1690
+ children: [/* @__PURE__ */ jsxRuntime.jsx(StyledButton, {
1691
+ type: "submit",
1692
+ disabled: formik$1.isSubmitting || isDone,
1693
+ shape,
1694
+ size,
1695
+ color: brandColor,
1696
+ variant: submitVariant,
1697
+ textColor: submitTextColor,
1698
+ width: submitWidth,
1699
+ alignment: submitAlignment,
1700
+ textStyle: submitTextStyle,
1701
+ children: formik$1.isSubmitting ? /* @__PURE__ */ jsxRuntime.jsx(Spinner, {}) : isDone ? /* @__PURE__ */ jsxRuntime.jsx(IconContainer, {
1702
+ children: /* @__PURE__ */ jsxRuntime.jsx(SvgCheck12, {})
1703
+ }) : submitLabel
1704
+ }), (errors.length > 0 || error) && /* @__PURE__ */ jsxRuntime.jsxs(ErrorContainer, {
1705
+ children: [errors.map((message) => /* @__PURE__ */ jsxRuntime.jsx(ErrorMessage, {
1706
+ children: message
1707
+ }, message)), error != null && /* @__PURE__ */ jsxRuntime.jsx(ErrorMessage, {
1708
+ children: error
1709
+ })]
1710
+ })]
1711
+ })]
1712
+ }), submitLink != null && /* @__PURE__ */ jsxRuntime.jsx(index.Link, {
1713
+ ref: linkRef,
1714
+ hidden: true,
1715
+ link: submitLink
1716
+ })]
1717
+ });
1718
+ }
1719
+ })
1720
+ })
1721
+ });
1722
+ });
1723
+ exports["default"] = Form;
1724
+ //# sourceMappingURL=Form.cjs.js.map