@streamline-pulse/formkrafter-wc 0.3.0 → 0.4.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.
Files changed (158) hide show
  1. package/README.md +10 -8
  2. package/dist/components/fk-brick-actions.js +1 -1
  3. package/dist/components/fk-brick-list.js +1 -1
  4. package/dist/components/fk-brick-mold-item.js +1 -1
  5. package/dist/components/fk-brick-render.js +1 -1
  6. package/dist/components/fk-code-editor.js +1 -1
  7. package/dist/components/fk-data-grid.js +1 -1
  8. package/dist/components/fk-drop-area.js +1 -1
  9. package/dist/components/fk-empty-form.js +1 -1
  10. package/dist/components/fk-file-input.js +1 -1
  11. package/dist/components/fk-form-builder.js +1 -1
  12. package/dist/components/fk-form-render.js +1 -1
  13. package/dist/components/fk-property-panel.js +1 -1
  14. package/dist/components/fk-rules-editor.js +1 -1
  15. package/dist/components/fk-select-input.js +1 -1
  16. package/dist/components/fk-signature-input.js +1 -1
  17. package/dist/components/fk-stepper.js +1 -1
  18. package/dist/components/fk-tabs.js +1 -1
  19. package/dist/components/index.js +1 -1
  20. package/dist/components/{p-CKMHMpID.js → p-28GBFlUX.js} +4 -4
  21. package/dist/components/{p-D6n74M9d.js → p-BGxmFcpL.js} +1 -1
  22. package/dist/components/{p-DYchD23x.js → p-BInUBjyw.js} +1 -1
  23. package/dist/{formkrafter-wc/p-C-wnqV3i.js → components/p-BietHxaT.js} +1 -1
  24. package/dist/components/{p-fDJP6whN.js → p-BnzSarwW.js} +1 -1
  25. package/dist/components/p-BpkKcCCr.js +1 -0
  26. package/dist/components/p-C0Y8qh8R.js +1 -0
  27. package/dist/components/p-C5OWoRhO.js +1 -0
  28. package/dist/components/{p-wuC5rVU7.js → p-CKs1CWVz.js} +1 -1
  29. package/dist/components/{p-v7LxwCAc.js → p-CZHykCYD.js} +1 -1
  30. package/dist/components/{p-4COASNrZ.js → p-CehxuHtl.js} +1 -1
  31. package/dist/components/p-CqVSd56Z.js +1 -0
  32. package/dist/components/p-CyZA17qf.js +1 -0
  33. package/dist/components/{p-BGkZP87K.js → p-D4HhZxQ-.js} +1 -1
  34. package/dist/components/p-DC6Wxbnz.js +1 -0
  35. package/dist/components/p-DRNycSdI.js +1 -0
  36. package/dist/components/{p--vL6GR31.js → p-Dh5Z49YD.js} +1 -1
  37. package/dist/components/p-DiOstAi9.js +1 -0
  38. package/dist/components/p-DlqnIm46.js +1 -0
  39. package/dist/components/{p-CIfjRTky.js → p-DshUS8Zm.js} +1 -1
  40. package/dist/components/{p-DMCkrZqi.js → p-RzeBwfwG.js} +1 -1
  41. package/dist/components/{p-BWdm2a6q.js → p-ajy8ZcBX.js} +1 -1
  42. package/dist/components/p-kYG3E0GQ.js +1 -0
  43. package/dist/components/p-tTJg_I4V.js +1 -0
  44. package/dist/formkrafter-wc/formkrafter-wc.css +1 -1
  45. package/dist/formkrafter-wc/formkrafter-wc.esm.js +1 -1
  46. package/dist/formkrafter-wc/index.esm.js +1 -1
  47. package/dist/formkrafter-wc/p-3579150a.entry.js +1 -0
  48. package/dist/formkrafter-wc/p-8b0ff66e.entry.js +1 -0
  49. package/dist/formkrafter-wc/p-BHZMDq2e.js +1 -0
  50. package/dist/{components/p-C-wnqV3i.js → formkrafter-wc/p-BietHxaT.js} +1 -1
  51. package/dist/formkrafter-wc/p-C0Y8qh8R.js +1 -0
  52. package/dist/formkrafter-wc/{p-4COASNrZ.js → p-CehxuHtl.js} +1 -1
  53. package/dist/formkrafter-wc/p-DlqnIm46.js +1 -0
  54. package/dist/formkrafter-wc/{p-DMCkrZqi.js → p-RzeBwfwG.js} +1 -1
  55. package/dist/formkrafter-wc/p-WWmY5Z05.js +1 -0
  56. package/dist/formkrafter-wc/p-hcT25XX4.js +12 -0
  57. package/dist/types/components/fk-code-editor/fk-code-editor.d.ts +1 -0
  58. package/dist/types/components/fk-data-grid/fk-data-grid.d.ts +1 -0
  59. package/dist/types/components/fk-drop-area/fk-drop-area.d.ts +1 -0
  60. package/dist/types/components/fk-form-render/fk-form-render.d.ts +7 -1
  61. package/dist/types/components.d.ts +17 -0
  62. package/dist/types/index.d.ts +1 -1
  63. package/dist/types/registry/default-bricks.d.ts +36 -0
  64. package/dist/types/utils/mask.d.ts +1 -0
  65. package/package.json +10 -15
  66. package/dist/cjs/app-globals-V2Kpy_OQ.js +0 -5
  67. package/dist/cjs/fk-brick-actions_18.cjs.entry.js +0 -4224
  68. package/dist/cjs/formkrafter-wc.cjs.js +0 -25
  69. package/dist/cjs/index-Bhy1RJMV.js +0 -3042
  70. package/dist/cjs/index-CImTe9BG.js +0 -2126
  71. package/dist/cjs/index-CdaT3-qx.js +0 -5444
  72. package/dist/cjs/index-CkPPRg03.js +0 -17548
  73. package/dist/cjs/index-DHgK3reD.js +0 -12233
  74. package/dist/cjs/index-Ds0sDbXV.js +0 -4019
  75. package/dist/cjs/index-c9BL7y3N.js +0 -1922
  76. package/dist/cjs/index.cjs.js +0 -48
  77. package/dist/cjs/loader.cjs.js +0 -13
  78. package/dist/collection/collection-manifest.json +0 -30
  79. package/dist/collection/components/fk-brick-actions/fk-brick-actions.css +0 -78
  80. package/dist/collection/components/fk-brick-actions/fk-brick-actions.js +0 -215
  81. package/dist/collection/components/fk-brick-list/fk-brick-list.css +0 -71
  82. package/dist/collection/components/fk-brick-list/fk-brick-list.js +0 -55
  83. package/dist/collection/components/fk-brick-mold-item/fk-brick-mold-item.css +0 -33
  84. package/dist/collection/components/fk-brick-mold-item/fk-brick-mold-item.js +0 -73
  85. package/dist/collection/components/fk-brick-not-found/fk-brick-not-found.css +0 -8
  86. package/dist/collection/components/fk-brick-not-found/fk-brick-not-found.js +0 -18
  87. package/dist/collection/components/fk-brick-render/fk-brick-render.js +0 -447
  88. package/dist/collection/components/fk-code-editor/fk-code-editor.css +0 -26
  89. package/dist/collection/components/fk-code-editor/fk-code-editor.js +0 -145
  90. package/dist/collection/components/fk-data-grid/fk-data-grid.css +0 -75
  91. package/dist/collection/components/fk-data-grid/fk-data-grid.js +0 -300
  92. package/dist/collection/components/fk-drop-area/fk-drop-area.css +0 -18
  93. package/dist/collection/components/fk-drop-area/fk-drop-area.js +0 -98
  94. package/dist/collection/components/fk-empty-form/fk-empty-form.css +0 -22
  95. package/dist/collection/components/fk-empty-form/fk-empty-form.js +0 -19
  96. package/dist/collection/components/fk-file-input/fk-file-input.css +0 -95
  97. package/dist/collection/components/fk-file-input/fk-file-input.js +0 -239
  98. package/dist/collection/components/fk-form-builder/fk-form-builder.css +0 -112
  99. package/dist/collection/components/fk-form-builder/fk-form-builder.js +0 -431
  100. package/dist/collection/components/fk-form-render/fk-form-render.css +0 -7
  101. package/dist/collection/components/fk-form-render/fk-form-render.js +0 -352
  102. package/dist/collection/components/fk-property-panel/fk-property-panel.css +0 -153
  103. package/dist/collection/components/fk-property-panel/fk-property-panel.js +0 -388
  104. package/dist/collection/components/fk-rules-editor/fk-rules-editor.css +0 -166
  105. package/dist/collection/components/fk-rules-editor/fk-rules-editor.js +0 -250
  106. package/dist/collection/components/fk-select-input/fk-select-input.css +0 -153
  107. package/dist/collection/components/fk-select-input/fk-select-input.js +0 -454
  108. package/dist/collection/components/fk-signature-input/fk-signature-input.css +0 -42
  109. package/dist/collection/components/fk-signature-input/fk-signature-input.js +0 -158
  110. package/dist/collection/components/fk-stepper/fk-stepper.css +0 -99
  111. package/dist/collection/components/fk-stepper/fk-stepper.js +0 -285
  112. package/dist/collection/components/fk-tabs/fk-tabs.css +0 -38
  113. package/dist/collection/components/fk-tabs/fk-tabs.js +0 -249
  114. package/dist/collection/i18n/i18n.js +0 -265
  115. package/dist/collection/index.js +0 -5
  116. package/dist/collection/registry/create-brick.js +0 -34
  117. package/dist/collection/registry/default-bricks.js +0 -564
  118. package/dist/collection/registry/registry.js +0 -44
  119. package/dist/collection/utils/brick-data.js +0 -16
  120. package/dist/collection/utils/drop.js +0 -14
  121. package/dist/collection/utils/events.js +0 -1
  122. package/dist/collection/utils/options.js +0 -21
  123. package/dist/collection/utils/remote.js +0 -27
  124. package/dist/collection/utils/rule-condition.js +0 -72
  125. package/dist/collection/utils/style.js +0 -11
  126. package/dist/components/p-BOmBVgfJ.js +0 -1
  127. package/dist/components/p-B_-x-GlA.js +0 -1
  128. package/dist/components/p-Br1s4Ujx.js +0 -1
  129. package/dist/components/p-CUF31e-P.js +0 -1
  130. package/dist/components/p-CWQX0sXS.js +0 -1
  131. package/dist/components/p-DFe3zZCI.js +0 -1
  132. package/dist/components/p-DOInQkG6.js +0 -1
  133. package/dist/components/p-PAr7WoWG.js +0 -1
  134. package/dist/components/p-YyGnQmX-.js +0 -1
  135. package/dist/components/p-swxZqinH.js +0 -1
  136. package/dist/esm/app-globals-DQuL1Twl.js +0 -3
  137. package/dist/esm/fk-brick-actions_18.entry.js +0 -4205
  138. package/dist/esm/formkrafter-wc.js +0 -21
  139. package/dist/esm/index-BAcz7b5u.js +0 -5416
  140. package/dist/esm/index-BkRMoLXK.js +0 -3029
  141. package/dist/esm/index-CGMDfZ5m.js +0 -1808
  142. package/dist/esm/index-D7Cta1UB.js +0 -17488
  143. package/dist/esm/index-DtcM1yw5.js +0 -3991
  144. package/dist/esm/index-DuVf3NlP.js +0 -12222
  145. package/dist/esm/index-qLZlXROB.js +0 -2117
  146. package/dist/esm/index.js +0 -2
  147. package/dist/esm/loader.js +0 -11
  148. package/dist/formkrafter-wc/p-6d29555b.entry.js +0 -1
  149. package/dist/formkrafter-wc/p-DOInQkG6.js +0 -1
  150. package/dist/formkrafter-wc/p-Ddu6BquK.js +0 -12
  151. package/dist/index.cjs.js +0 -1
  152. package/dist/index.js +0 -1
  153. package/dist/stencil.config.js +0 -34
  154. package/loader/cdn.js +0 -1
  155. package/loader/index.cjs.js +0 -1
  156. package/loader/index.d.ts +0 -24
  157. package/loader/index.es2017.js +0 -1
  158. package/loader/index.js +0 -2
@@ -1,4224 +0,0 @@
1
- 'use strict';
2
-
3
- var index$1 = require('./index-CImTe9BG.js');
4
- var index = require('./index-CkPPRg03.js');
5
-
6
- function _arrayWithHoles(r) {
7
- if (Array.isArray(r)) return r;
8
- }
9
-
10
- function _iterableToArrayLimit(r, l) {
11
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
12
- if (null != t) {
13
- var e,
14
- n,
15
- i,
16
- u,
17
- a = [],
18
- f = true,
19
- o = false;
20
- try {
21
- if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true);
22
- } catch (r) {
23
- o = true, n = r;
24
- } finally {
25
- try {
26
- if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
27
- } finally {
28
- if (o) throw n;
29
- }
30
- }
31
- return a;
32
- }
33
- }
34
-
35
- function _arrayLikeToArray$2(r, a) {
36
- (null == a || a > r.length) && (a = r.length);
37
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
38
- return n;
39
- }
40
-
41
- function _unsupportedIterableToArray$2(r, a) {
42
- if (r) {
43
- if ("string" == typeof r) return _arrayLikeToArray$2(r, a);
44
- var t = {}.toString.call(r).slice(8, -1);
45
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$2(r, a) : void 0;
46
- }
47
- }
48
-
49
- function _nonIterableRest() {
50
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
51
- }
52
-
53
- function _slicedToArray(r, e) {
54
- return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray$2(r, e) || _nonIterableRest();
55
- }
56
-
57
- var dist = {};
58
-
59
- var bind = {};
60
-
61
- var hasRequiredBind;
62
-
63
- function requireBind () {
64
- if (hasRequiredBind) return bind;
65
- hasRequiredBind = 1;
66
- Object.defineProperty(bind, "__esModule", { value: true });
67
- bind.bind = void 0;
68
- function bind$1(target, _a) {
69
- var type = _a.type, listener = _a.listener, options = _a.options;
70
- target.addEventListener(type, listener, options);
71
- return function unbind() {
72
- target.removeEventListener(type, listener, options);
73
- };
74
- }
75
- bind.bind = bind$1;
76
- return bind;
77
- }
78
-
79
- var bindAll = {};
80
-
81
- var hasRequiredBindAll;
82
-
83
- function requireBindAll () {
84
- if (hasRequiredBindAll) return bindAll;
85
- hasRequiredBindAll = 1;
86
- var __assign = (bindAll && bindAll.__assign) || function () {
87
- __assign = Object.assign || function(t) {
88
- for (var s, i = 1, n = arguments.length; i < n; i++) {
89
- s = arguments[i];
90
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
91
- t[p] = s[p];
92
- }
93
- return t;
94
- };
95
- return __assign.apply(this, arguments);
96
- };
97
- Object.defineProperty(bindAll, "__esModule", { value: true });
98
- bindAll.bindAll = void 0;
99
- var bind_1 = /*@__PURE__*/ requireBind();
100
- function toOptions(value) {
101
- if (typeof value === 'undefined') {
102
- return undefined;
103
- }
104
- if (typeof value === 'boolean') {
105
- return {
106
- capture: value,
107
- };
108
- }
109
- return value;
110
- }
111
- function getBinding(original, sharedOptions) {
112
- if (sharedOptions == null) {
113
- return original;
114
- }
115
- var binding = __assign(__assign({}, original), { options: __assign(__assign({}, toOptions(sharedOptions)), toOptions(original.options)) });
116
- return binding;
117
- }
118
- function bindAll$1(target, bindings, sharedOptions) {
119
- var unbinds = bindings.map(function (original) {
120
- var binding = getBinding(original, sharedOptions);
121
- return (0, bind_1.bind)(target, binding);
122
- });
123
- return function unbindAll() {
124
- unbinds.forEach(function (unbind) { return unbind(); });
125
- };
126
- }
127
- bindAll.bindAll = bindAll$1;
128
- return bindAll;
129
- }
130
-
131
- var hasRequiredDist;
132
-
133
- function requireDist () {
134
- if (hasRequiredDist) return dist;
135
- hasRequiredDist = 1;
136
- (function (exports) {
137
- Object.defineProperty(exports, "__esModule", { value: true });
138
- exports.bindAll = exports.bind = void 0;
139
- var bind_1 = /*@__PURE__*/ requireBind();
140
- Object.defineProperty(exports, "bind", { enumerable: true, get: function () { return bind_1.bind; } });
141
- var bind_all_1 = /*@__PURE__*/ requireBindAll();
142
- Object.defineProperty(exports, "bindAll", { enumerable: true, get: function () { return bind_all_1.bindAll; } });
143
- } (dist));
144
- return dist;
145
- }
146
-
147
- var distExports = /*@__PURE__*/ requireDist();
148
-
149
- // pulling this into a separate file so adapter(s) that don't
150
- // need the honey pot can pay as little as possible for it.
151
- var honeyPotDataAttribute = 'data-pdnd-honey-pot';
152
-
153
- function isHoneyPotElement(target) {
154
- return target instanceof Element && target.hasAttribute(honeyPotDataAttribute);
155
- }
156
-
157
- function getElementFromPointWithoutHoneypot(client) {
158
- // eslint-disable-next-line no-restricted-syntax
159
- var _document$elementsFro = document.elementsFromPoint(client.x, client.y),
160
- _document$elementsFro2 = _slicedToArray(_document$elementsFro, 2),
161
- top = _document$elementsFro2[0],
162
- second = _document$elementsFro2[1];
163
- if (!top) {
164
- return null;
165
- }
166
- if (isHoneyPotElement(top)) {
167
- return second !== null && second !== void 0 ? second : null;
168
- }
169
- return top;
170
- }
171
-
172
- function _typeof(o) {
173
- "@babel/helpers - typeof";
174
-
175
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
176
- return typeof o;
177
- } : function (o) {
178
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
179
- }, _typeof(o);
180
- }
181
-
182
- function toPrimitive(t, r) {
183
- if ("object" != _typeof(t) || !t) return t;
184
- var e = t[Symbol.toPrimitive];
185
- if (void 0 !== e) {
186
- var i = e.call(t, r);
187
- if ("object" != _typeof(i)) return i;
188
- throw new TypeError("@@toPrimitive must return a primitive value.");
189
- }
190
- return ("string" === r ? String : Number)(t);
191
- }
192
-
193
- function toPropertyKey(t) {
194
- var i = toPrimitive(t, "string");
195
- return "symbol" == _typeof(i) ? i : i + "";
196
- }
197
-
198
- function _defineProperty(e, r, t) {
199
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
200
- value: t,
201
- enumerable: true,
202
- configurable: true,
203
- writable: true
204
- }) : e[r] = t, e;
205
- }
206
-
207
- // Maximum possible z-index
208
- // https://stackoverflow.com/questions/491052/minimum-and-maximum-value-of-z-index
209
- var maxZIndex = 2147483647;
210
-
211
- /**
212
- * Resets user agent styles for `[popover]` elements.
213
- *
214
- * Browsers apply these defaults to popovers (per the WHATWG HTML spec rendering section):
215
- * - `inset: 0` + `margin: auto` → centers the popover in the viewport
216
- * - `border: solid` → visible border
217
- * - `padding: 0.25em` → internal spacing
218
- * - `overflow: auto` → scrollbars when content overflows
219
- * - `color: CanvasText` + `background-color: Canvas` → system theme colors
220
- *
221
- * This object neutralizes those defaults so the popover behaves like a plain
222
- * positioned `<div>`, matching the sizing of the legacy (non-popover)
223
- * fallback container exactly.
224
- *
225
- * **Width and height (`auto`)**
226
- *
227
- * `width` and `height` override the spec user agent value of `fit-content`
228
- * with `auto`.
229
- *
230
- * _Why?_
231
- *
232
- * - When a `[popover]` is sized with `fit-content` and contains a flex
233
- * container, Safari collapses any flex item that uses `overflow: auto`
234
- * to `0px`.
235
- * - Setting the popover's `width` and `height` to `auto` skips the `fit-content`
236
- * pass and avoids the bug in Safari
237
- * - Chromium and Firefox tolerate `fit-content` here, but `auto` is safe
238
- * everywhere and matches our non-popover path
239
- */
240
- var popoverResetUserAgentStyles = {
241
- inset: 'unset',
242
- border: 'none',
243
- padding: 0,
244
- margin: 0,
245
- overflow: 'visible',
246
- color: 'inherit',
247
- background: 'transparent',
248
- width: 'auto',
249
- height: 'auto'
250
- };
251
-
252
- /** Provide a function that you only ever want to be called a single time */
253
- function once(fn) {
254
- var cache = null;
255
- return function wrapped() {
256
- if (!cache) {
257
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
258
- args[_key] = arguments[_key];
259
- }
260
- var result = fn.apply(this, args);
261
- cache = {
262
- result: result
263
- };
264
- }
265
- return cache.result;
266
- };
267
- }
268
-
269
- // Using `once` as the value won't change in a browser
270
-
271
- /**
272
- * Returns `true` if the browser supports the Popover API (top-layer).
273
- *
274
- * When supported, elements with `popover="manual"` can be promoted to the
275
- * browser's top layer via `element.showPopover()`, which is more reliable
276
- * than `z-index` for ensuring an element renders above everything else.
277
- *
278
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Popover_API
279
- */
280
- var supportsPopover = once(function supportsPopover() {
281
- return typeof HTMLElement !== 'undefined' && typeof HTMLElement.prototype.showPopover === 'function';
282
- });
283
-
284
- function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
285
- function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
286
- var honeyPotSize = 2;
287
- var halfHoneyPotSize = honeyPotSize / 2;
288
-
289
- /**
290
- * `clientX` and `clientY` can be in sub pixels (eg `2.332`)
291
- * However, browser hitbox testing is commonly do to the closest pixel.
292
- *
293
- * → https://issues.chromium.org/issues/40940531
294
- *
295
- * To be sure that the honey pot will be over the `client` position,
296
- * we `.floor()` `clientX` and`clientY` and then make it `2px` in size.
297
- **/
298
- function floorToClosestPixel(point) {
299
- return {
300
- x: Math.floor(point.x),
301
- y: Math.floor(point.y)
302
- };
303
- }
304
-
305
- /**
306
- * We want to make sure the honey pot sits around the users position.
307
- * This seemed to be the most resilient while testing.
308
- */
309
- function pullBackByHalfHoneyPotSize(point) {
310
- return {
311
- x: point.x - halfHoneyPotSize,
312
- y: point.y - halfHoneyPotSize
313
- };
314
- }
315
-
316
- /**
317
- * Prevent the honey pot from changing the window size.
318
- * This is super unlikely to occur, but just being safe.
319
- */
320
- function preventGoingBackwardsOffScreen(point) {
321
- return {
322
- x: Math.max(point.x, 0),
323
- y: Math.max(point.y, 0)
324
- };
325
- }
326
-
327
- /**
328
- * Prevent the honey pot from changing the window size.
329
- * This is super unlikely to occur, but just being safe.
330
- */
331
- function preventGoingForwardsOffScreen(point) {
332
- return {
333
- x: Math.min(point.x, window.innerWidth - honeyPotSize),
334
- y: Math.min(point.y, window.innerHeight - honeyPotSize)
335
- };
336
- }
337
-
338
- /**
339
- * Create a `2x2` `DOMRect` around the `client` position
340
- */
341
- function getHoneyPotRectFor(_ref) {
342
- var client = _ref.client;
343
- var point = preventGoingForwardsOffScreen(preventGoingBackwardsOffScreen(pullBackByHalfHoneyPotSize(floorToClosestPixel(client))));
344
-
345
- // When debugging, it is helpful to
346
- // make this element a bit bigger
347
- return DOMRect.fromRect({
348
- x: point.x,
349
- y: point.y,
350
- width: honeyPotSize,
351
- height: honeyPotSize
352
- });
353
- }
354
- function getRectStyles(_ref2) {
355
- var clientRect = _ref2.clientRect;
356
- return {
357
- left: "".concat(clientRect.left, "px"),
358
- top: "".concat(clientRect.top, "px"),
359
- width: "".concat(clientRect.width, "px"),
360
- height: "".concat(clientRect.height, "px")
361
- };
362
- }
363
- function isWithin(_ref3) {
364
- var client = _ref3.client,
365
- clientRect = _ref3.clientRect;
366
- return (
367
- // is within horizontal bounds
368
- client.x >= clientRect.x && client.x <= clientRect.x + clientRect.width &&
369
- // is within vertical bounds
370
- client.y >= clientRect.y && client.y <= clientRect.y + clientRect.height
371
- );
372
- }
373
- /**
374
- * The honey pot fix is designed to get around a painful bug in all browsers.
375
- *
376
- * [Overview](https://www.youtube.com/watch?v=udE9qbFTeQg)
377
- *
378
- * **Background**
379
- *
380
- * When a drag starts, browsers incorrectly think that the users pointer is
381
- * still depressed where the drag started. Any element that goes under this position
382
- * will be entered into, causing `"mouseenter"` events and `":hover"` styles to be applied.
383
- *
384
- * _This is a violation of the spec_
385
- *
386
- * > "From the moment that the user agent is to initiate the drag-and-drop operation,
387
- * > until the end of the drag-and-drop operation, device input events
388
- * > (e.g. mouse and keyboard events) must be suppressed."
389
- * >
390
- * > - https://html.spec.whatwg.org/multipage/dnd.html#drag-and-drop-processing-model
391
- *
392
- * _Some impacts_
393
- *
394
- * - `":hover"` styles being applied where they shouldn't (looks messy)
395
- * - components such as tooltips responding to `"mouseenter"` can show during a drag,
396
- * and on an element the user isn't even over
397
- *
398
- * Bug: https://issues.chromium.org/issues/41129937
399
- *
400
- * **Honey pot fix**
401
- *
402
- * 1. Create an element where the browser thinks the depressed pointer is
403
- * to absorb the incorrect pointer events
404
- * 2. Remove that element when it is no longer needed
405
- */
406
- function mountHoneyPot(_ref4) {
407
- var initial = _ref4.initial;
408
- var element = document.createElement('div');
409
- element.setAttribute(honeyPotDataAttribute, 'true');
410
-
411
- // Using popover="manual" to place the element in the browser's top layer.
412
- // This ensures the honey pot is visually on top of everything else,
413
- // including elements using z-index and other stacking contexts.
414
- // "manual" means no light dismiss — we manage the lifecycle ourselves.
415
- // Falls back to position:fixed + maxZIndex when the popover API is not available.
416
- if (supportsPopover()) {
417
- element.setAttribute('popover', 'manual');
418
- }
419
-
420
- // can shift during the drag thanks to Firefox
421
- var clientRect = getHoneyPotRectFor({
422
- client: initial
423
- });
424
- Object.assign(element.style, _objectSpread$2(_objectSpread$2({
425
- position: 'fixed'
426
- }, supportsPopover() ?
427
- // needs to come first as it has 'inset: unset' which
428
- // needs to be overridden by our top / left values
429
- popoverResetUserAgentStyles : {
430
- // Fallback: using maximum possible z-index so that this element
431
- // will always be on top of other positioned content.
432
- zIndex: maxZIndex
433
- }), {}, {
434
- // Setting a background color explicitly to avoid any inherited styles.
435
- // Looks like this could be `opacity: 0`, but worried that _might_
436
- // cause the element to be ignored on some platforms.
437
- // When debugging, set backgroundColor to something like "red".
438
- backgroundColor: 'transparent',
439
- // Being explicit to avoid inheriting styles
440
- padding: 0,
441
- margin: 0,
442
- boxSizing: 'border-box',
443
- // We want this element to absorb pointer events,
444
- // it's kind of the whole point 😉
445
- pointerEvents: 'auto'
446
- }, getRectStyles({
447
- clientRect: clientRect
448
- })));
449
- document.body.appendChild(element);
450
- if (supportsPopover()) {
451
- element.showPopover();
452
- }
453
-
454
- /**
455
- * 🦊 In firefox we can get `"pointermove"` events after the drag
456
- * has started, which is a spec violation.
457
- * The final `"pointermove"` will reveal where the "depressed" position
458
- * is for our honey pot fix.
459
- */
460
- var unbindPointerMove = distExports.bind(window, {
461
- type: 'pointermove',
462
- listener: function listener(event) {
463
- var client = {
464
- x: event.clientX,
465
- y: event.clientY
466
- };
467
- clientRect = getHoneyPotRectFor({
468
- client: client
469
- });
470
- Object.assign(element.style, getRectStyles({
471
- clientRect: clientRect
472
- }));
473
- },
474
- // using capture so we are less likely to be impacted by event stopping
475
- options: {
476
- capture: true
477
- }
478
- });
479
- return function finish(_ref5) {
480
- var current = _ref5.current;
481
- // Don't need this any more
482
- unbindPointerMove();
483
-
484
- // If the user is hover the honey pot, we remove it
485
- // so that the user can continue to interact with the page normally.
486
- if (isWithin({
487
- client: current,
488
- clientRect: clientRect
489
- })) {
490
- element.remove();
491
- return;
492
- }
493
- function cleanup() {
494
- unbindPostDragEvents();
495
- element.remove();
496
- }
497
- var unbindPostDragEvents = distExports.bindAll(window, [{
498
- type: 'pointerdown',
499
- listener: cleanup
500
- }, {
501
- type: 'pointermove',
502
- listener: cleanup
503
- }, {
504
- type: 'focusin',
505
- listener: cleanup
506
- }, {
507
- type: 'focusout',
508
- listener: cleanup
509
- },
510
- // a 'pointerdown' should happen before 'dragstart', but just being super safe
511
- {
512
- type: 'dragstart',
513
- listener: cleanup
514
- },
515
- // if the user has dragged something out of the window
516
- // and then is dragging something back into the window
517
- // the first events we will see are "dragenter" (and then "dragover").
518
- // So if we see any of these we need to clear the post drag fix.
519
- {
520
- type: 'dragenter',
521
- listener: cleanup
522
- }, {
523
- type: 'dragover',
524
- listener: cleanup
525
- }
526
-
527
- // Not adding a "wheel" event listener, as "wheel" by itself does not
528
- // resolve the bug.
529
- ], {
530
- // Using `capture` so less likely to be impacted by other code stopping events
531
- capture: true
532
- });
533
- };
534
- }
535
- function makeHoneyPotFix() {
536
- var latestPointerMove = null;
537
- function bindEvents() {
538
- // For sanity, only collecting this value from when events are first bound.
539
- // This prevents the case where a super old "pointermove" could be used
540
- // from a prior interaction.
541
- latestPointerMove = null;
542
- return distExports.bind(window, {
543
- type: 'pointermove',
544
- listener: function listener(event) {
545
- latestPointerMove = {
546
- x: event.clientX,
547
- y: event.clientY
548
- };
549
- },
550
- // listening for pointer move in capture phase
551
- // so we are less likely to be impacted by events being stopped.
552
- options: {
553
- capture: true
554
- }
555
- });
556
- }
557
- function getOnPostDispatch() {
558
- var finish = null;
559
- return function onPostEvent(_ref6) {
560
- var eventName = _ref6.eventName,
561
- payload = _ref6.payload;
562
- // We are adding the honey pot `onDragStart` so we don't
563
- // impact the creation of the native drag preview.
564
- if (eventName === 'onDragStart') {
565
- var input = payload.location.initial.input;
566
-
567
- // Sometimes there will be no latest "pointermove" (eg iOS).
568
- // In which case, we use the start position of the drag.
569
- var initial = latestPointerMove !== null && latestPointerMove !== void 0 ? latestPointerMove : {
570
- x: input.clientX,
571
- y: input.clientY
572
- };
573
-
574
- // Don't need to defensively call `finish()` as `onDrop` from
575
- // one interaction is guaranteed to be called before `onDragStart`
576
- // of the next.
577
- finish = mountHoneyPot({
578
- initial: initial
579
- });
580
- }
581
- if (eventName === 'onDrop') {
582
- var _finish;
583
- var _input = payload.location.current.input;
584
- (_finish = finish) === null || _finish === void 0 || _finish({
585
- current: {
586
- x: _input.clientX,
587
- y: _input.clientY
588
- }
589
- });
590
- finish = null;
591
- // this interaction is finished, we want to use
592
- // the latest "pointermove" for each interaction
593
- latestPointerMove = null;
594
- }
595
- };
596
- }
597
- return {
598
- bindEvents: bindEvents,
599
- getOnPostDispatch: getOnPostDispatch
600
- };
601
- }
602
-
603
- function _arrayWithoutHoles(r) {
604
- if (Array.isArray(r)) return _arrayLikeToArray$2(r);
605
- }
606
-
607
- function _iterableToArray(r) {
608
- if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
609
- }
610
-
611
- function _nonIterableSpread() {
612
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
613
- }
614
-
615
- function _toConsumableArray(r) {
616
- return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray$2(r) || _nonIterableSpread();
617
- }
618
-
619
- // using `cache` as our `isFirefox()` result will not change in a browser
620
-
621
- /**
622
- * Returns `true` if a `Firefox` browser
623
- * */
624
- var isFirefox = once(function isFirefox() {
625
- return navigator.userAgent.includes('Firefox');
626
- });
627
-
628
- // using `cache` as our `isSafari()` result will not change in a browser
629
-
630
- /**
631
- * Returns `true` if a `Safari` browser.
632
- * Returns `true` if the browser is running on iOS (they are all Safari).
633
- *
634
- * Use `isSafariOnIOS` if you want to check if something is Safari + iOS
635
- * */
636
- var isSafari = once(function isSafari() {
637
- var _navigator = navigator,
638
- userAgent = _navigator.userAgent;
639
- return userAgent.includes('AppleWebKit') && !userAgent.includes('Chrome');
640
- });
641
-
642
- /* For "dragenter" events, the browser should set `relatedTarget` to the previous element.
643
- * For external drag operations, our first "dragenter" event should have a `event.relatedTarget` of `null`.
644
- *
645
- * Unfortunately in Safari `event.relatedTarget` is *always* set to `null`
646
- * Safari bug: https://bugs.webkit.org/show_bug.cgi?id=242627
647
- * To work around this we count "dragenter" and "dragleave" events */
648
-
649
- // Using symbols for event properties so we don't clash with
650
- // anything on the `event` object
651
- var symbols = {
652
- isLeavingWindow: Symbol('leaving'),
653
- isEnteringWindow: Symbol('entering')
654
- };
655
-
656
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
657
- function isLeavingWindowInSafari(_ref2) {
658
- var dragLeave = _ref2.dragLeave;
659
- if (!isSafari()) {
660
- return false;
661
- }
662
- return dragLeave.hasOwnProperty(symbols.isLeavingWindow);
663
- }
664
- (function fixSafari() {
665
- // Don't do anything when server side rendering
666
- if (typeof window === 'undefined') {
667
- return;
668
- }
669
- if (!isSafari()) {
670
- return;
671
- }
672
- function getInitialState() {
673
- return {
674
- enterCount: 0,
675
- isOverWindow: false
676
- };
677
- }
678
- var state = getInitialState();
679
- function resetState() {
680
- state = getInitialState();
681
- }
682
-
683
- // These event listeners are bound _forever_ and _never_ removed
684
- // We don't bother cleaning up these event listeners (for now)
685
- // as this workaround is only for Safari
686
-
687
- // This is how the event count works:
688
- //
689
- // lift (+1 enterCount)
690
- // - dragstart(draggable) [enterCount: 0]
691
- // - dragenter(draggable) [enterCount: 1]
692
- // leaving draggable (+0 enterCount)
693
- // - dragenter(document.body) [enterCount: 2]
694
- // - dragleave(draggable) [enterCount: 1]
695
- // leaving window (-1 enterCount)
696
- // - dragleave(document.body) [enterCount: 0] {leaving the window}
697
-
698
- // Things to note:
699
- // - dragenter and dragleave bubble
700
- // - the first dragenter when entering a window might not be on `window`
701
- // - it could be on an element that is pressed up against the window
702
- // - (so we cannot rely on `event.target` values)
703
-
704
- distExports.bindAll(window, [{
705
- type: 'dragstart',
706
- listener: function listener() {
707
- state.enterCount = 0;
708
- // drag start occurs in the source window
709
- state.isOverWindow = true;
710
- // When a drag first starts it will also trigger a "dragenter" on the draggable element
711
- }
712
- }, {
713
- type: 'drop',
714
- listener: resetState
715
- }, {
716
- type: 'dragend',
717
- listener: resetState
718
- }, {
719
- type: 'dragenter',
720
- listener: function listener(event) {
721
- if (!state.isOverWindow && state.enterCount === 0) {
722
- // Patching the `event` object
723
- // The `event` object is shared with all event listeners for the event
724
- event[symbols.isEnteringWindow] = true;
725
- }
726
- state.isOverWindow = true;
727
- state.enterCount++;
728
- }
729
- }, {
730
- type: 'dragleave',
731
- listener: function listener(event) {
732
- state.enterCount--;
733
- if (state.isOverWindow && state.enterCount === 0) {
734
- // Patching the `event` object as it is shared with all event listeners
735
- // The `event` object is shared with all event listeners for the event
736
- event[symbols.isLeavingWindow] = true;
737
- state.isOverWindow = false;
738
- }
739
- }
740
- }],
741
- // using `capture: true` so that adding event listeners
742
- // in bubble phase will have the correct symbols
743
- {
744
- capture: true
745
- });
746
- })();
747
-
748
- /**
749
- * Does the `EventTarget` look like a `Node` based on "duck typing".
750
- *
751
- * Helpful when the `Node` might be outside of the current document
752
- * so we cannot to an `target instanceof Node` check.
753
- */
754
- function isNodeLike(target) {
755
- return 'nodeName' in target;
756
- }
757
-
758
- /**
759
- * Is an `EventTarget` a `Node` from another `window`?
760
- */
761
- function isFromAnotherWindow(eventTarget) {
762
- return isNodeLike(eventTarget) && eventTarget.ownerDocument !== document;
763
- }
764
-
765
- function isLeavingWindow(_ref) {
766
- var dragLeave = _ref.dragLeave;
767
- var type = dragLeave.type,
768
- relatedTarget = dragLeave.relatedTarget;
769
- if (type !== 'dragleave') {
770
- return false;
771
- }
772
- if (isSafari()) {
773
- return isLeavingWindowInSafari({
774
- dragLeave: dragLeave
775
- });
776
- }
777
-
778
- // Standard check: if going to `null` we are leaving the `window`
779
- if (relatedTarget == null) {
780
- return true;
781
- }
782
-
783
- /**
784
- * 🦊 Exception: `iframe` in Firefox (`125.0`)
785
- *
786
- * Case 1: parent `window` → child `iframe`
787
- * `dragLeave.relatedTarget` is element _inside_ the child `iframe`
788
- * (foreign element)
789
- *
790
- * Case 2: child `iframe` → parent `window`
791
- * `dragLeave.relatedTarget` is the `iframe` in the parent `window`
792
- * (foreign element)
793
- */
794
-
795
- if (isFirefox()) {
796
- return isFromAnotherWindow(relatedTarget);
797
- }
798
-
799
- /**
800
- * 🌏 Exception: `iframe` in Chrome (`124.0`)
801
- *
802
- * Case 1: parent `window` → child `iframe`
803
- * `dragLeave.relatedTarget` is the `iframe` in the parent `window`
804
- *
805
- * Case 2: child `iframe` → parent `window`
806
- * `dragLeave.relatedTarget` is `null` *(standard check)*
807
- */
808
-
809
- // Case 2
810
- // Using `instanceof` check as the element will be in the same `window`
811
- return relatedTarget instanceof HTMLIFrameElement;
812
- }
813
-
814
- function getBindingsForBrokenDrags(_ref) {
815
- var onDragEnd = _ref.onDragEnd;
816
- return [
817
- // ## Detecting drag ending for removed draggables
818
- //
819
- // If a draggable element is removed during a drag and the user drops:
820
- // 1. if over a valid drop target: we get a "drop" event to know the drag is finished
821
- // 2. if not over a valid drop target (or cancelled): we get nothing
822
- // The "dragend" event will not fire on the source draggable if it has been
823
- // removed from the DOM.
824
- // So we need to figure out if a drag operation has finished by looking at other events
825
- // We can do this by looking at other events
826
-
827
- // ### First detection: "pointermove" events
828
-
829
- // 1. "pointermove" events cannot fire during a drag and drop operation
830
- // according to the spec. So if we get a "pointermove" it means that
831
- // the drag and drop operations has finished. So if we get a "pointermove"
832
- // we know that the drag is over
833
- // 2. 🦊😤 Drag and drop operations are _supposed_ to suppress
834
- // other pointer events. However, firefox will allow a few
835
- // pointer event to get through after a drag starts.
836
- // The most I've seen is 3
837
- {
838
- type: 'pointermove',
839
- listener: function () {
840
- var callCount = 0;
841
- return function listener() {
842
- // Using 20 as it is far bigger than the most observed (3)
843
- if (callCount < 20) {
844
- callCount++;
845
- return;
846
- }
847
- onDragEnd();
848
- };
849
- }()
850
- },
851
- // ### Second detection: "pointerdown" events
852
-
853
- // If we receive this event then we know that a drag operation has finished
854
- // and potentially another one is about to start.
855
- // Note: `pointerdown` fires on all browsers / platforms before "dragstart"
856
- {
857
- type: 'pointerdown',
858
- listener: onDragEnd
859
- }];
860
- }
861
-
862
- function getInput(event) {
863
- return {
864
- altKey: event.altKey,
865
- button: event.button,
866
- buttons: event.buttons,
867
- ctrlKey: event.ctrlKey,
868
- metaKey: event.metaKey,
869
- shiftKey: event.shiftKey,
870
- clientX: event.clientX,
871
- clientY: event.clientY,
872
- pageX: event.pageX,
873
- pageY: event.pageY
874
- };
875
- }
876
-
877
- var rafSchd = function rafSchd(fn) {
878
- var lastArgs = [];
879
- var frameId = null;
880
-
881
- var wrapperFn = function wrapperFn() {
882
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
883
- args[_key] = arguments[_key];
884
- }
885
-
886
- lastArgs = args;
887
-
888
- if (frameId) {
889
- return;
890
- }
891
-
892
- frameId = requestAnimationFrame(function () {
893
- frameId = null;
894
- fn.apply(void 0, lastArgs);
895
- });
896
- };
897
-
898
- wrapperFn.cancel = function () {
899
- if (!frameId) {
900
- return;
901
- }
902
-
903
- cancelAnimationFrame(frameId);
904
- frameId = null;
905
- };
906
-
907
- return wrapperFn;
908
- };
909
-
910
- var scheduleOnDrag = rafSchd(function (fn) {
911
- return fn();
912
- });
913
- var dragStart = function () {
914
- var scheduled = null;
915
- function schedule(fn) {
916
- var frameId = requestAnimationFrame(function () {
917
- scheduled = null;
918
- fn();
919
- });
920
- scheduled = {
921
- frameId: frameId,
922
- fn: fn
923
- };
924
- }
925
- function flush() {
926
- if (scheduled) {
927
- cancelAnimationFrame(scheduled.frameId);
928
- scheduled.fn();
929
- scheduled = null;
930
- }
931
- }
932
- return {
933
- schedule: schedule,
934
- flush: flush
935
- };
936
- }();
937
- function makeDispatch(_ref) {
938
- var source = _ref.source,
939
- initial = _ref.initial,
940
- dispatchEvent = _ref.dispatchEvent;
941
- var previous = {
942
- dropTargets: []
943
- };
944
- function safeDispatch(args) {
945
- dispatchEvent(args);
946
- previous = {
947
- dropTargets: args.payload.location.current.dropTargets
948
- };
949
- }
950
- var dispatch = {
951
- start: function start(_ref2) {
952
- var nativeSetDragImage = _ref2.nativeSetDragImage;
953
- // Ensuring that both `onGenerateDragPreview` and `onDragStart` get the same location.
954
- // We do this so that `previous` is`[]` in `onDragStart` (which is logical)
955
- var location = {
956
- current: initial,
957
- previous: previous,
958
- initial: initial
959
- };
960
- // a `onGenerateDragPreview` does _not_ add another entry for `previous`
961
- // onDragPreview
962
- safeDispatch({
963
- eventName: 'onGenerateDragPreview',
964
- payload: {
965
- source: source,
966
- location: location,
967
- nativeSetDragImage: nativeSetDragImage
968
- }
969
- });
970
- dragStart.schedule(function () {
971
- safeDispatch({
972
- eventName: 'onDragStart',
973
- payload: {
974
- source: source,
975
- location: location
976
- }
977
- });
978
- });
979
- },
980
- dragUpdate: function dragUpdate(_ref3) {
981
- var current = _ref3.current;
982
- dragStart.flush();
983
- scheduleOnDrag.cancel();
984
- safeDispatch({
985
- eventName: 'onDropTargetChange',
986
- payload: {
987
- source: source,
988
- location: {
989
- initial: initial,
990
- previous: previous,
991
- current: current
992
- }
993
- }
994
- });
995
- },
996
- drag: function drag(_ref4) {
997
- var current = _ref4.current;
998
- scheduleOnDrag(function () {
999
- dragStart.flush();
1000
- var location = {
1001
- initial: initial,
1002
- previous: previous,
1003
- current: current
1004
- };
1005
- safeDispatch({
1006
- eventName: 'onDrag',
1007
- payload: {
1008
- source: source,
1009
- location: location
1010
- }
1011
- });
1012
- });
1013
- },
1014
- drop: function drop(_ref5) {
1015
- var current = _ref5.current,
1016
- updatedSourcePayload = _ref5.updatedSourcePayload;
1017
- dragStart.flush();
1018
- scheduleOnDrag.cancel();
1019
- safeDispatch({
1020
- eventName: 'onDrop',
1021
- payload: {
1022
- source: updatedSourcePayload !== null && updatedSourcePayload !== void 0 ? updatedSourcePayload : source,
1023
- location: {
1024
- current: current,
1025
- previous: previous,
1026
- initial: initial
1027
- }
1028
- }
1029
- });
1030
- }
1031
- };
1032
- return dispatch;
1033
- }
1034
-
1035
- var globalState = {
1036
- isActive: false
1037
- };
1038
- function canStart() {
1039
- return !globalState.isActive;
1040
- }
1041
- function getNativeSetDragImage(event) {
1042
- if (event.dataTransfer) {
1043
- // need to use `.bind` as `setDragImage` is required
1044
- // to be run with `event.dataTransfer` as the "this" context
1045
- return event.dataTransfer.setDragImage.bind(event.dataTransfer);
1046
- }
1047
- return null;
1048
- }
1049
- function hasHierarchyChanged(_ref) {
1050
- var current = _ref.current,
1051
- next = _ref.next;
1052
- if (current.length !== next.length) {
1053
- return true;
1054
- }
1055
- // not checking stickiness, data or dropEffect,
1056
- // just whether the hierarchy has changed
1057
- for (var i = 0; i < current.length; i++) {
1058
- if (current[i].element !== next[i].element) {
1059
- return true;
1060
- }
1061
- }
1062
- return false;
1063
- }
1064
- function start(_ref2) {
1065
- var event = _ref2.event,
1066
- dragType = _ref2.dragType,
1067
- getDropTargetsOver = _ref2.getDropTargetsOver,
1068
- dispatchEvent = _ref2.dispatchEvent;
1069
- if (!canStart()) {
1070
- return;
1071
- }
1072
- var initial = getStartLocation({
1073
- event: event,
1074
- dragType: dragType,
1075
- getDropTargetsOver: getDropTargetsOver
1076
- });
1077
- globalState.isActive = true;
1078
- var state = {
1079
- current: initial
1080
- };
1081
-
1082
- // Setting initial drop effect for the drag
1083
- setDropEffectOnEvent({
1084
- event: event,
1085
- current: initial.dropTargets
1086
- });
1087
- var dispatch = makeDispatch({
1088
- source: dragType.payload,
1089
- dispatchEvent: dispatchEvent,
1090
- initial: initial
1091
- });
1092
- function updateState(next) {
1093
- // only looking at whether hierarchy has changed to determine whether something as 'changed'
1094
- var hasChanged = hasHierarchyChanged({
1095
- current: state.current.dropTargets,
1096
- next: next.dropTargets
1097
- });
1098
-
1099
- // Always updating the state to include latest data, dropEffect and stickiness
1100
- // Only updating consumers if the hierarchy has changed in some way
1101
- // Consumers can get the latest data by using `onDrag`
1102
- state.current = next;
1103
- if (hasChanged) {
1104
- dispatch.dragUpdate({
1105
- current: state.current
1106
- });
1107
- }
1108
- }
1109
- function onUpdateEvent(event) {
1110
- var input = getInput(event);
1111
-
1112
- // If we are over the honey pot, we need to get the element
1113
- // that the user would have been over if not for the honey pot
1114
- var target = isHoneyPotElement(event.target) ? getElementFromPointWithoutHoneypot({
1115
- x: input.clientX,
1116
- y: input.clientY
1117
- }) : event.target;
1118
- var nextDropTargets = getDropTargetsOver({
1119
- target: target,
1120
- input: input,
1121
- source: dragType.payload,
1122
- current: state.current.dropTargets
1123
- });
1124
- if (nextDropTargets.length) {
1125
- // 🩸 must call `event.preventDefault()` to allow a browser drop to occur
1126
- event.preventDefault();
1127
- setDropEffectOnEvent({
1128
- event: event,
1129
- current: nextDropTargets
1130
- });
1131
- }
1132
- updateState({
1133
- dropTargets: nextDropTargets,
1134
- input: input
1135
- });
1136
- }
1137
- function cancel() {
1138
- // The spec behaviour is that when a drag is cancelled, or when dropping on no drop targets,
1139
- // a "dragleave" event is fired on the active drop target before a "dragend" event.
1140
- // We are replicating that behaviour in `cancel` if there are any active drop targets to
1141
- // ensure consistent behaviour.
1142
- //
1143
- // Note: When cancelling, or dropping on no drop targets, a "dragleave" event
1144
- // will have already cleared the dropTargets to `[]` (as that particular "dragleave" has a `relatedTarget` of `null`)
1145
-
1146
- if (state.current.dropTargets.length) {
1147
- updateState({
1148
- dropTargets: [],
1149
- input: state.current.input
1150
- });
1151
- }
1152
- dispatch.drop({
1153
- current: state.current,
1154
- updatedSourcePayload: null
1155
- });
1156
- finish();
1157
- }
1158
- function finish() {
1159
- globalState.isActive = false;
1160
- unbindEvents();
1161
- }
1162
- var unbindEvents = distExports.bindAll(window, [{
1163
- // 👋 Note: we are repurposing the `dragover` event as our `drag` event
1164
- // this is because firefox does not publish pointer coordinates during
1165
- // a `drag` event, but does for every other type of drag event
1166
- // `dragover` fires on all elements that are being dragged over
1167
- // Because we are binding to `window` - our `dragover` is effectively the same as a `drag`
1168
- // 🦊😤
1169
- type: 'dragover',
1170
- listener: function listener(event) {
1171
- // We need to regularly calculate the drop targets in order to allow:
1172
- // - dynamic `canDrop()` checks
1173
- // - rapid updating `getData()` calls to attach data in response to user input (eg for edge detection)
1174
- // Sadly we cannot schedule inspecting changes resulting from this event
1175
- // we need to be able to conditionally cancel the event with `event.preventDefault()`
1176
- // to enable the correct native drop experience.
1177
-
1178
- // 1. check to see if anything has changed
1179
- onUpdateEvent(event);
1180
-
1181
- // 2. let consumers know a move has occurred
1182
- // This will include the latest 'input' values
1183
- dispatch.drag({
1184
- current: state.current
1185
- });
1186
- }
1187
- }, {
1188
- type: 'dragenter',
1189
- listener: onUpdateEvent
1190
- }, {
1191
- type: 'dragleave',
1192
- listener: function listener(event) {
1193
- if (!isLeavingWindow({
1194
- dragLeave: event
1195
- })) {
1196
- return;
1197
- }
1198
-
1199
- /**
1200
- * At this point we don't know if a drag is being cancelled,
1201
- * or if a drag is leaving the `window`.
1202
- *
1203
- * Both have:
1204
- * 1. "dragleave" (with `relatedTarget: null`)
1205
- * 2. "dragend" (a "dragend" can occur when outside the `window`)
1206
- *
1207
- * **Clearing drop targets**
1208
- *
1209
- * For either case we are clearing the the drop targets
1210
- *
1211
- * - cancelling: we clear drop targets in `"dragend"` anyway
1212
- * - leaving the `window`: we clear the drop targets (to clear stickiness)
1213
- *
1214
- * **Leaving the window and finishing the drag**
1215
- *
1216
- * _internal drags_
1217
- *
1218
- * - The drag continues when the user is outside the `window`
1219
- * and can resume if the user drags back over the `window`,
1220
- * or end when the user drops in an external `window`.
1221
- * - We will get a `"dragend"`, or we can listen for other
1222
- * events to determine the drag is finished when the user re-enters the `window`).
1223
- *
1224
- * _external drags_
1225
- *
1226
- * - We conclude the drag operation.
1227
- * - We have no idea if the user will drag back over the `window`,
1228
- * or if the drag ends elsewhere.
1229
- * - We will create a new drag if the user re-enters the `window`.
1230
- *
1231
- * **Not updating `input`**
1232
- *
1233
- * 🐛 Bug[Chrome] the final `"dragleave"` has default input values (eg `clientX == 0`)
1234
- * Workaround: intentionally not updating `input` in "dragleave"
1235
- * rather than the users current input values
1236
- * - [Conversation](https://twitter.com/alexandereardon/status/1642697633864241152)
1237
- * - [Bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1429937)
1238
- **/
1239
-
1240
- updateState({
1241
- input: state.current.input,
1242
- dropTargets: []
1243
- });
1244
- if (dragType.startedFrom === 'external') {
1245
- cancel();
1246
- }
1247
- }
1248
- }, {
1249
- // A "drop" can only happen if the browser allowed the drop
1250
- type: 'drop',
1251
- listener: function listener(event) {
1252
- // Capture the final input.
1253
- // We are capturing the final `input` for the
1254
- // most accurate honey pot experience
1255
- state.current = {
1256
- dropTargets: state.current.dropTargets,
1257
- input: getInput(event)
1258
- };
1259
-
1260
- /** If there are no drop targets, then we will get
1261
- * a "drop" event if:
1262
- * - `preventUnhandled()` is being used
1263
- * - there is an unmanaged drop target (eg another library)
1264
- * In these cases, it's up to the consumer
1265
- * to handle the drop if it's not over one of our drop targets
1266
- * - `preventUnhandled()` will cancel the "drop"
1267
- * - unmanaged drop targets can handle the "drop" how they want to
1268
- * We won't call `event.preventDefault()` in this call path */
1269
-
1270
- if (!state.current.dropTargets.length) {
1271
- cancel();
1272
- return;
1273
- }
1274
- event.preventDefault();
1275
-
1276
- // applying the latest drop effect to the event
1277
- setDropEffectOnEvent({
1278
- event: event,
1279
- current: state.current.dropTargets
1280
- });
1281
- dispatch.drop({
1282
- current: state.current,
1283
- // When dropping something native, we need to extract the latest
1284
- // `.items` from the "drop" event as it is now accessible
1285
- updatedSourcePayload: dragType.type === 'external' ? dragType.getDropPayload(event) : null
1286
- });
1287
- finish();
1288
- }
1289
- }, {
1290
- // "dragend" fires when on the drag source (eg a draggable element)
1291
- // when the drag is finished.
1292
- // "dragend" will fire after "drop" (if there was a successful drop)
1293
- // "dragend" does not fire if the draggable source has been removed during the drag
1294
- // or for external drag sources (eg files)
1295
-
1296
- // This "dragend" listener will not fire if there was a successful drop
1297
- // as we will have already removed the event listener
1298
-
1299
- type: 'dragend',
1300
- listener: function listener(event) {
1301
- // In firefox, the position of the "dragend" event can
1302
- // be a bit different to the last "dragover" event.
1303
- // Updating the input so we can get the best possible
1304
- // information for the honey pot.
1305
- state.current = {
1306
- dropTargets: state.current.dropTargets,
1307
- input: getInput(event)
1308
- };
1309
- cancel();
1310
- }
1311
- }].concat(_toConsumableArray(getBindingsForBrokenDrags({
1312
- onDragEnd: cancel
1313
- }))),
1314
- // Once we have started a managed drag operation it is important that we see / own all drag events
1315
- // We got one adoption bug pop up where some code was stopping (`event.stopPropagation()`)
1316
- // all "drop" events in the bubble phase on the `document.body`.
1317
- // This meant that we never saw the "drop" event.
1318
- {
1319
- capture: true
1320
- });
1321
- dispatch.start({
1322
- nativeSetDragImage: getNativeSetDragImage(event)
1323
- });
1324
- }
1325
- function setDropEffectOnEvent(_ref3) {
1326
- var _current$;
1327
- var event = _ref3.event,
1328
- current = _ref3.current;
1329
- // setting the `dropEffect` to be the innerMost drop targets dropEffect
1330
- var innerMost = (_current$ = current[0]) === null || _current$ === void 0 ? void 0 : _current$.dropEffect;
1331
- if (innerMost != null && event.dataTransfer) {
1332
- event.dataTransfer.dropEffect = innerMost;
1333
- }
1334
- }
1335
- function getStartLocation(_ref4) {
1336
- var event = _ref4.event,
1337
- dragType = _ref4.dragType,
1338
- getDropTargetsOver = _ref4.getDropTargetsOver;
1339
- var input = getInput(event);
1340
-
1341
- // When dragging from outside of the browser,
1342
- // the drag is not being sourced from any local drop targets
1343
- if (dragType.startedFrom === 'external') {
1344
- return {
1345
- input: input,
1346
- dropTargets: []
1347
- };
1348
- }
1349
- var dropTargets = getDropTargetsOver({
1350
- input: input,
1351
- source: dragType.payload,
1352
- target: event.target,
1353
- current: []
1354
- });
1355
- return {
1356
- input: input,
1357
- dropTargets: dropTargets
1358
- };
1359
- }
1360
- var lifecycle = {
1361
- canStart: canStart,
1362
- start: start
1363
- };
1364
-
1365
- // Extending `Map` to allow us to link Key and Values together
1366
-
1367
- var ledger = new Map();
1368
- function registerUsage(_ref) {
1369
- var typeKey = _ref.typeKey,
1370
- mount = _ref.mount;
1371
- var entry = ledger.get(typeKey);
1372
- if (entry) {
1373
- entry.usageCount++;
1374
- return entry;
1375
- }
1376
- var initial = {
1377
- typeKey: typeKey,
1378
- unmount: mount(),
1379
- usageCount: 1
1380
- };
1381
- ledger.set(typeKey, initial);
1382
- return initial;
1383
- }
1384
- function register(args) {
1385
- var entry = registerUsage(args);
1386
- return function unregister() {
1387
- entry.usageCount--;
1388
- if (entry.usageCount > 0) {
1389
- return;
1390
- }
1391
- // Only a single usage left, remove it
1392
- entry.unmount();
1393
- ledger.delete(args.typeKey);
1394
- };
1395
- }
1396
-
1397
- /** Create a new combined function that will call all the provided functions */
1398
- function combine() {
1399
- for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
1400
- fns[_key] = arguments[_key];
1401
- }
1402
- return function cleanup() {
1403
- fns.forEach(function (fn) {
1404
- return fn();
1405
- });
1406
- };
1407
- }
1408
-
1409
- function addAttribute(element, _ref) {
1410
- var attribute = _ref.attribute,
1411
- value = _ref.value;
1412
- element.setAttribute(attribute, value);
1413
- return function () {
1414
- return element.removeAttribute(attribute);
1415
- };
1416
- }
1417
-
1418
- function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1419
- function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1420
- function _createForOfIteratorHelper$1(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$1(r)) || e) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: true } : { done: false, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = true, u = false; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = true, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
1421
- function _unsupportedIterableToArray$1(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$1(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$1(r, a) : void 0; } }
1422
- function _arrayLikeToArray$1(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
1423
- function copyReverse(array) {
1424
- return array.slice(0).reverse();
1425
- }
1426
- function makeDropTarget(_ref) {
1427
- var typeKey = _ref.typeKey,
1428
- defaultDropEffect = _ref.defaultDropEffect;
1429
- var registry = new WeakMap();
1430
- var dropTargetDataAtt = "data-drop-target-for-".concat(typeKey);
1431
- var dropTargetSelector = "[".concat(dropTargetDataAtt, "]");
1432
- function addToRegistry(args) {
1433
- registry.set(args.element, args);
1434
- return function () {
1435
- return registry.delete(args.element);
1436
- };
1437
- }
1438
- function dropTargetForConsumers(args) {
1439
- var cleanup = combine(addAttribute(args.element, {
1440
- attribute: dropTargetDataAtt,
1441
- value: 'true'
1442
- }), addToRegistry(args));
1443
-
1444
- // Wrapping in `once` to prevent unexpected side effects if consumers call
1445
- // the clean up function multiple times.
1446
- return once(cleanup);
1447
- }
1448
- function getActualDropTargets(_ref2) {
1449
- var _args$getData, _args$getData2, _args$getDropEffect, _args$getDropEffect2;
1450
- var source = _ref2.source,
1451
- target = _ref2.target,
1452
- input = _ref2.input,
1453
- _ref2$result = _ref2.result,
1454
- result = _ref2$result === void 0 ? [] : _ref2$result;
1455
- if (target == null) {
1456
- return result;
1457
- }
1458
- if (!(target instanceof Element)) {
1459
- // For "text-selection" drags, the original `target`
1460
- // is not an `Element`, so we need to start looking from
1461
- // the parent element
1462
- if (target instanceof Node) {
1463
- return getActualDropTargets({
1464
- source: source,
1465
- target: target.parentElement,
1466
- input: input,
1467
- result: result
1468
- });
1469
- }
1470
-
1471
- // not sure what we are working with,
1472
- // so we can exit.
1473
- return result;
1474
- }
1475
- var closest = target.closest(dropTargetSelector);
1476
-
1477
- // Cannot find anything else
1478
- if (closest == null) {
1479
- return result;
1480
- }
1481
- var args = registry.get(closest);
1482
-
1483
- // error: something had a dropTargetSelector but we could not
1484
- // find a match. For now, failing silently
1485
- if (args == null) {
1486
- return result;
1487
- }
1488
- var feedback = {
1489
- input: input,
1490
- source: source,
1491
- element: args.element
1492
- };
1493
-
1494
- // if dropping is not allowed, skip this drop target
1495
- // and continue looking up the DOM tree
1496
- if (args.canDrop && !args.canDrop(feedback)) {
1497
- return getActualDropTargets({
1498
- source: source,
1499
- target: args.element.parentElement,
1500
- input: input,
1501
- result: result
1502
- });
1503
- }
1504
-
1505
- // calculate our new record
1506
- var data = (_args$getData = (_args$getData2 = args.getData) === null || _args$getData2 === void 0 ? void 0 : _args$getData2.call(args, feedback)) !== null && _args$getData !== void 0 ? _args$getData : {};
1507
- var dropEffect = (_args$getDropEffect = (_args$getDropEffect2 = args.getDropEffect) === null || _args$getDropEffect2 === void 0 ? void 0 : _args$getDropEffect2.call(args, feedback)) !== null && _args$getDropEffect !== void 0 ? _args$getDropEffect : defaultDropEffect;
1508
- var record = {
1509
- data: data,
1510
- element: args.element,
1511
- dropEffect: dropEffect,
1512
- // we are collecting _actual_ drop targets, so these are
1513
- // being applied _not_ due to stickiness
1514
- isActiveDueToStickiness: false
1515
- };
1516
- return getActualDropTargets({
1517
- source: source,
1518
- target: args.element.parentElement,
1519
- input: input,
1520
- // Using bubble ordering. Same ordering as `event.getPath()`
1521
- result: [].concat(_toConsumableArray(result), [record])
1522
- });
1523
- }
1524
- function notifyCurrent(_ref3) {
1525
- var eventName = _ref3.eventName,
1526
- payload = _ref3.payload;
1527
- var _iterator = _createForOfIteratorHelper$1(payload.location.current.dropTargets),
1528
- _step;
1529
- try {
1530
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
1531
- var _entry$eventName;
1532
- var record = _step.value;
1533
- var entry = registry.get(record.element);
1534
- var args = _objectSpread$1(_objectSpread$1({}, payload), {}, {
1535
- self: record
1536
- });
1537
- entry === null || entry === void 0 || (_entry$eventName = entry[eventName]) === null || _entry$eventName === void 0 || _entry$eventName.call(entry,
1538
- // I cannot seem to get the types right here.
1539
- // TS doesn't seem to like that one event can need `nativeSetDragImage`
1540
- // @ts-expect-error
1541
- args);
1542
- }
1543
- } catch (err) {
1544
- _iterator.e(err);
1545
- } finally {
1546
- _iterator.f();
1547
- }
1548
- }
1549
- var actions = {
1550
- onGenerateDragPreview: notifyCurrent,
1551
- onDrag: notifyCurrent,
1552
- onDragStart: notifyCurrent,
1553
- onDrop: notifyCurrent,
1554
- onDropTargetChange: function onDropTargetChange(_ref4) {
1555
- var payload = _ref4.payload;
1556
- var isCurrent = new Set(payload.location.current.dropTargets.map(function (record) {
1557
- return record.element;
1558
- }));
1559
- var visited = new Set();
1560
- var _iterator2 = _createForOfIteratorHelper$1(payload.location.previous.dropTargets),
1561
- _step2;
1562
- try {
1563
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1564
- var _entry$onDropTargetCh;
1565
- var record = _step2.value;
1566
- visited.add(record.element);
1567
- var entry = registry.get(record.element);
1568
- var isOver = isCurrent.has(record.element);
1569
- var args = _objectSpread$1(_objectSpread$1({}, payload), {}, {
1570
- self: record
1571
- });
1572
- entry === null || entry === void 0 || (_entry$onDropTargetCh = entry.onDropTargetChange) === null || _entry$onDropTargetCh === void 0 || _entry$onDropTargetCh.call(entry, args);
1573
-
1574
- // if we cannot find the drop target in the current array, then it has been left
1575
- if (!isOver) {
1576
- var _entry$onDragLeave;
1577
- entry === null || entry === void 0 || (_entry$onDragLeave = entry.onDragLeave) === null || _entry$onDragLeave === void 0 || _entry$onDragLeave.call(entry, args);
1578
- }
1579
- }
1580
- } catch (err) {
1581
- _iterator2.e(err);
1582
- } finally {
1583
- _iterator2.f();
1584
- }
1585
- var _iterator3 = _createForOfIteratorHelper$1(payload.location.current.dropTargets),
1586
- _step3;
1587
- try {
1588
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1589
- var _entry$onDropTargetCh2, _entry$onDragEnter;
1590
- var _record = _step3.value;
1591
- // already published an update to this drop target
1592
- if (visited.has(_record.element)) {
1593
- continue;
1594
- }
1595
- // at this point we have a new drop target that is being entered into
1596
- var _args = _objectSpread$1(_objectSpread$1({}, payload), {}, {
1597
- self: _record
1598
- });
1599
- var _entry = registry.get(_record.element);
1600
- _entry === null || _entry === void 0 || (_entry$onDropTargetCh2 = _entry.onDropTargetChange) === null || _entry$onDropTargetCh2 === void 0 || _entry$onDropTargetCh2.call(_entry, _args);
1601
- _entry === null || _entry === void 0 || (_entry$onDragEnter = _entry.onDragEnter) === null || _entry$onDragEnter === void 0 || _entry$onDragEnter.call(_entry, _args);
1602
- }
1603
- } catch (err) {
1604
- _iterator3.e(err);
1605
- } finally {
1606
- _iterator3.f();
1607
- }
1608
- }
1609
- };
1610
- function dispatchEvent(args) {
1611
- actions[args.eventName](args);
1612
- }
1613
- function getIsOver(_ref5) {
1614
- var source = _ref5.source,
1615
- target = _ref5.target,
1616
- input = _ref5.input,
1617
- current = _ref5.current;
1618
- var actual = getActualDropTargets({
1619
- source: source,
1620
- target: target,
1621
- input: input
1622
- });
1623
-
1624
- // stickiness is only relevant when we have less
1625
- // drop targets than we did before
1626
- if (actual.length >= current.length) {
1627
- return actual;
1628
- }
1629
-
1630
- // less 'actual' drop targets than before,
1631
- // we need to see if 'stickiness' applies
1632
-
1633
- // An old drop target will continue to be dropped on if:
1634
- // 1. it has the same parent
1635
- // 2. nothing exists in it's previous index
1636
-
1637
- var lastCaptureOrdered = copyReverse(current);
1638
- var actualCaptureOrdered = copyReverse(actual);
1639
- var resultCaptureOrdered = [];
1640
- for (var index = 0; index < lastCaptureOrdered.length; index++) {
1641
- var _argsForLast$getIsSti;
1642
- var last = lastCaptureOrdered[index];
1643
- var fresh = actualCaptureOrdered[index];
1644
-
1645
- // if a record is in the new index -> use that
1646
- // it will have the latest data + dropEffect
1647
- if (fresh != null) {
1648
- resultCaptureOrdered.push(fresh);
1649
- continue;
1650
- }
1651
-
1652
- // At this point we have no drop target in the old spot
1653
- // Check to see if we can use a previous sticky drop target
1654
-
1655
- // The "parent" is the one inside of `resultCaptureOrdered`
1656
- // (the parent might be a drop target that was sticky)
1657
- var parent = resultCaptureOrdered[index - 1];
1658
- var lastParent = lastCaptureOrdered[index - 1];
1659
-
1660
- // Stickiness is based on parent relationships, so if the parent relationship has change
1661
- // then we can stop our search
1662
- if ((parent === null || parent === void 0 ? void 0 : parent.element) !== (lastParent === null || lastParent === void 0 ? void 0 : lastParent.element)) {
1663
- break;
1664
- }
1665
-
1666
- // We need to check whether the old drop target can still be dropped on
1667
-
1668
- var argsForLast = registry.get(last.element);
1669
-
1670
- // We cannot drop on a drop target that is no longer mounted
1671
- if (!argsForLast) {
1672
- break;
1673
- }
1674
- var feedback = {
1675
- input: input,
1676
- source: source,
1677
- element: argsForLast.element
1678
- };
1679
-
1680
- // We cannot drop on a drop target that no longer allows being dropped on
1681
- if (argsForLast.canDrop && !argsForLast.canDrop(feedback)) {
1682
- break;
1683
- }
1684
-
1685
- // We cannot drop on a drop target that is no longer sticky
1686
- if (!((_argsForLast$getIsSti = argsForLast.getIsSticky) !== null && _argsForLast$getIsSti !== void 0 && _argsForLast$getIsSti.call(argsForLast, feedback))) {
1687
- break;
1688
- }
1689
-
1690
- // Note: intentionally not recollecting `getData()` or `getDropEffect()`
1691
- // Previous values for `data` and `dropEffect` will be borrowed
1692
- // This is to prevent things like the 'closest edge' changing when
1693
- // no longer over a drop target.
1694
- // We could change our mind on this behaviour in the future
1695
-
1696
- resultCaptureOrdered.push(_objectSpread$1(_objectSpread$1({}, last), {}, {
1697
- // making it clear to consumers this drop target is active due to stickiness
1698
- isActiveDueToStickiness: true
1699
- }));
1700
- }
1701
-
1702
- // return bubble ordered result
1703
- return copyReverse(resultCaptureOrdered);
1704
- }
1705
- return {
1706
- dropTargetForConsumers: dropTargetForConsumers,
1707
- getIsOver: getIsOver,
1708
- dispatchEvent: dispatchEvent
1709
- };
1710
- }
1711
-
1712
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: true } : { done: false, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = true, u = false; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = true, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
1713
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
1714
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
1715
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1716
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1717
- function makeMonitor() {
1718
- var registry = new Set();
1719
- var dragging = null;
1720
- function tryAddToActive(monitor) {
1721
- if (!dragging) {
1722
- return;
1723
- }
1724
- // Monitor is allowed to monitor events if:
1725
- // 1. It has no `canMonitor` function (default is that a monitor can listen to everything)
1726
- // 2. `canMonitor` returns true
1727
- if (!monitor.canMonitor || monitor.canMonitor(dragging.canMonitorArgs)) {
1728
- dragging.active.add(monitor);
1729
- }
1730
- }
1731
- function monitorForConsumers(args) {
1732
- // We are giving each `args` a new reference so that you
1733
- // can create multiple monitors with the same `args`.
1734
- var entry = _objectSpread({}, args);
1735
- registry.add(entry);
1736
-
1737
- // if there is an active drag we need to see if this new monitor is relevant
1738
- tryAddToActive(entry);
1739
- function cleanup() {
1740
- registry.delete(entry);
1741
-
1742
- // We need to stop publishing events during a drag to this monitor!
1743
- if (dragging) {
1744
- dragging.active.delete(entry);
1745
- }
1746
- }
1747
-
1748
- // Wrapping in `once` to prevent unexpected side effects if consumers call
1749
- // the clean up function multiple times.
1750
- return once(cleanup);
1751
- }
1752
- function dispatchEvent(_ref) {
1753
- var eventName = _ref.eventName,
1754
- payload = _ref.payload;
1755
- if (eventName === 'onGenerateDragPreview') {
1756
- dragging = {
1757
- canMonitorArgs: {
1758
- initial: payload.location.initial,
1759
- source: payload.source
1760
- },
1761
- active: new Set()
1762
- };
1763
- var _iterator = _createForOfIteratorHelper(registry),
1764
- _step;
1765
- try {
1766
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
1767
- var monitor = _step.value;
1768
- tryAddToActive(monitor);
1769
- }
1770
- } catch (err) {
1771
- _iterator.e(err);
1772
- } finally {
1773
- _iterator.f();
1774
- }
1775
- }
1776
-
1777
- // This should never happen.
1778
- if (!dragging) {
1779
- return;
1780
- }
1781
-
1782
- // Creating an array from the set _before_ iterating
1783
- // This is so that monitors added during the current event will not be called.
1784
- // This behaviour matches native EventTargets where an event listener
1785
- // cannot add another event listener during an active event to the same
1786
- // event target in the same event (for us we have a single global event target)
1787
- var active = Array.from(dragging.active);
1788
- for (var _i = 0, _active = active; _i < _active.length; _i++) {
1789
- var _monitor = _active[_i];
1790
- // A monitor can be removed by another monitor during an event.
1791
- // We need to check that the monitor is still registered before calling it
1792
- if (dragging.active.has(_monitor)) {
1793
- var _monitor$eventName;
1794
- // @ts-expect-error: I cannot get this type working!
1795
- (_monitor$eventName = _monitor[eventName]) === null || _monitor$eventName === void 0 || _monitor$eventName.call(_monitor, payload);
1796
- }
1797
- }
1798
- if (eventName === 'onDrop') {
1799
- dragging.active.clear();
1800
- dragging = null;
1801
- }
1802
- }
1803
- return {
1804
- dispatchEvent: dispatchEvent,
1805
- monitorForConsumers: monitorForConsumers
1806
- };
1807
- }
1808
-
1809
- function makeAdapter(_ref) {
1810
- var typeKey = _ref.typeKey,
1811
- mount = _ref.mount,
1812
- dispatchEventToSource = _ref.dispatchEventToSource,
1813
- onPostDispatch = _ref.onPostDispatch,
1814
- defaultDropEffect = _ref.defaultDropEffect;
1815
- var monitorAPI = makeMonitor();
1816
- var dropTargetAPI = makeDropTarget({
1817
- typeKey: typeKey,
1818
- defaultDropEffect: defaultDropEffect
1819
- });
1820
- function dispatchEvent(args) {
1821
- // 1. forward the event to source
1822
- dispatchEventToSource === null || dispatchEventToSource === void 0 || dispatchEventToSource(args);
1823
-
1824
- // 2. forward the event to relevant dropTargets
1825
- dropTargetAPI.dispatchEvent(args);
1826
-
1827
- // 3. forward event to monitors
1828
- monitorAPI.dispatchEvent(args);
1829
-
1830
- // 4. post consumer dispatch (used for honey pot fix)
1831
- onPostDispatch === null || onPostDispatch === void 0 || onPostDispatch(args);
1832
- }
1833
- function start(_ref2) {
1834
- var event = _ref2.event,
1835
- dragType = _ref2.dragType;
1836
- lifecycle.start({
1837
- event: event,
1838
- dragType: dragType,
1839
- getDropTargetsOver: dropTargetAPI.getIsOver,
1840
- dispatchEvent: dispatchEvent
1841
- });
1842
- }
1843
- function registerUsage() {
1844
- function mountAdapter() {
1845
- var api = {
1846
- canStart: lifecycle.canStart,
1847
- start: start
1848
- };
1849
- return mount(api);
1850
- }
1851
- return register({
1852
- typeKey: typeKey,
1853
- mount: mountAdapter
1854
- });
1855
- }
1856
- return {
1857
- registerUsage: registerUsage,
1858
- dropTarget: dropTargetAPI.dropTargetForConsumers,
1859
- monitor: monitorAPI.monitorForConsumers
1860
- };
1861
- }
1862
-
1863
- // Using `once` as the value won't change in a browser
1864
-
1865
- var isAndroid = once(function isAndroid() {
1866
- return navigator.userAgent.toLocaleLowerCase().includes('android');
1867
- });
1868
-
1869
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
1870
- var androidFallbackText = 'pdnd:android-fallback';
1871
-
1872
- // Why we put the media types in their own files:
1873
- //
1874
- // - we are not putting them all in one file as not all adapters need all types
1875
- // - we are not putting them in the external helpers as some things just need the
1876
- // types and not the external functions code
1877
- var textMediaType = 'text/plain';
1878
-
1879
- // Why we put the media types in their own files:
1880
- //
1881
- // - we are not putting them all in one file as not all adapters need all types
1882
- // - we are not putting them in the external helpers as some things just need the
1883
- // types and not the external functions code
1884
- var URLMediaType = 'text/uri-list';
1885
-
1886
- /**
1887
- * This key has been pulled into a separate module
1888
- * so that the external adapter does not need to import
1889
- * the element adapter
1890
- */
1891
- var elementAdapterNativeDataKey = 'application/vnd.pdnd';
1892
-
1893
- var draggableRegistry = new WeakMap();
1894
- function addToRegistry(args) {
1895
- draggableRegistry.set(args.element, args);
1896
- return function cleanup() {
1897
- draggableRegistry.delete(args.element);
1898
- };
1899
- }
1900
- var honeyPotFix = makeHoneyPotFix();
1901
- var adapter = makeAdapter({
1902
- typeKey: 'element',
1903
- defaultDropEffect: 'move',
1904
- mount: function mount(api) {
1905
- /** Binding event listeners the `document` rather than `window` so that
1906
- * this adapter always gets preference over the text adapter.
1907
- * `document` is the first `EventTarget` under `window`
1908
- * https://twitter.com/alexandereardon/status/1604658588311465985
1909
- */
1910
- return combine(honeyPotFix.bindEvents(), distExports.bind(document, {
1911
- type: 'dragstart',
1912
- listener: function listener(event) {
1913
- var _entry$dragHandle, _entry$getInitialData, _entry$getInitialData2, _entry$dragHandle2, _entry$getInitialData3, _entry$getInitialData4;
1914
- if (!api.canStart(event)) {
1915
- return;
1916
- }
1917
-
1918
- // If the "dragstart" event is cancelled, then a drag won't start
1919
- // There will be no further drag operation events (eg no "dragend" event)
1920
- if (event.defaultPrevented) {
1921
- return;
1922
- }
1923
-
1924
- // Technically `dataTransfer` can be `null` according to the types
1925
- // But that behaviour does not seem to appear in the spec.
1926
- // If there is not `dataTransfer`, we can assume something is wrong and not
1927
- // start a drag
1928
- if (!event.dataTransfer) {
1929
- return;
1930
- }
1931
-
1932
- // the closest parent that is a draggable element will be marked as
1933
- // the `event.target` for the event
1934
- var target = event.target;
1935
-
1936
- // this source is only for elements
1937
- // Note: only HTMLElements can have the "draggable" attribute
1938
- if (!(target instanceof HTMLElement)) {
1939
- return;
1940
- }
1941
-
1942
- // see if the thing being dragged is owned by us
1943
- var entry = draggableRegistry.get(target);
1944
-
1945
- // no matching element found
1946
- // → dragging an element with `draggable="true"` that is not controlled by us
1947
- if (!entry) {
1948
- return;
1949
- }
1950
-
1951
- /**
1952
- * A text selection drag _can_ have the `draggable` element be
1953
- * the `event.target` if the user is dragging the text selection
1954
- * from the `draggable`.
1955
- *
1956
- * To know if the `draggable` is being dragged, we look at whether any
1957
- * `"text/plain"` data is being dragged. If it is, then a text selection
1958
- * drag is occurring.
1959
- *
1960
- * This behaviour has been validated on:
1961
- *
1962
- * - Chrome@128 on Android@14
1963
- * - Chrome@128 on iOS@17.6.1
1964
- * - Chrome@128 on Windows@11
1965
- * - Chrome@128 on MacOS@14.6.1
1966
- * - Firefox@129 on Windows@11 (not possible for user to select text in a draggable)
1967
- * - Firefox@129 on MacOS@14.6.1 (not possible for user to select text in a draggable)
1968
- *
1969
- * Note: Could usually just use: `event.dataTransfer.types.includes(textMediaType)`
1970
- * but unfortunately ProseMirror is always setting `""` as the dragged text
1971
- *
1972
- * Note: Unfortunately editor is (heavily) leaning on the current functionality today
1973
- * and unwinding it will be a decent amount of effort. So for now, a text selection
1974
- * where the `event.target` is a `draggable` element will still trigger the
1975
- * element adapter.
1976
- *
1977
- * // Future state:
1978
- * if(event.dataTransfer.getData(textMediaType)) {
1979
- * return;
1980
- * }
1981
- *
1982
- */
1983
-
1984
- var input = getInput(event);
1985
- var feedback = {
1986
- element: entry.element,
1987
- dragHandle: (_entry$dragHandle = entry.dragHandle) !== null && _entry$dragHandle !== void 0 ? _entry$dragHandle : null,
1988
- input: input
1989
- };
1990
-
1991
- // Check: does the draggable want to allow dragging?
1992
- if (entry.canDrag && !entry.canDrag(feedback)) {
1993
- // cancel drag operation if we cannot drag
1994
- event.preventDefault();
1995
- return;
1996
- }
1997
-
1998
- // Check: is there a drag handle and is the user using it?
1999
- if (entry.dragHandle) {
2000
- // technically don't need this util, but just being
2001
- // consistent with how we look up what is under the users
2002
- // cursor.
2003
- var over = getElementFromPointWithoutHoneypot({
2004
- x: input.clientX,
2005
- y: input.clientY
2006
- });
2007
-
2008
- // if we are not dragging from the drag handle (or something inside the drag handle)
2009
- // then we will cancel the active drag
2010
- if (!entry.dragHandle.contains(over)) {
2011
- event.preventDefault();
2012
- return;
2013
- }
2014
- }
2015
-
2016
- /**
2017
- * **Goal**
2018
- * Pass information to other applications
2019
- *
2020
- * **Approach**
2021
- * Put data into the native data store
2022
- *
2023
- * **What about the native adapter?**
2024
- * When the element adapter puts native data into the native data store
2025
- * the native adapter is not triggered in the current window,
2026
- * but a native adapter in an external window _can_ be triggered
2027
- *
2028
- * **Why bake this into core?**
2029
- * This functionality could be pulled out and exposed inside of
2030
- * `onGenerateDragPreview`. But decided to make it a part of the
2031
- * base API as it felt like a common enough use case and ended
2032
- * up being a similar amount of code to include this function as
2033
- * it was to expose the hook for it
2034
- */
2035
- var nativeData = (_entry$getInitialData = (_entry$getInitialData2 = entry.getInitialDataForExternal) === null || _entry$getInitialData2 === void 0 ? void 0 : _entry$getInitialData2.call(entry, feedback)) !== null && _entry$getInitialData !== void 0 ? _entry$getInitialData : null;
2036
- if (nativeData) {
2037
- for (var _i = 0, _Object$entries = Object.entries(nativeData); _i < _Object$entries.length; _i++) {
2038
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
2039
- key = _Object$entries$_i[0],
2040
- data = _Object$entries$_i[1];
2041
- event.dataTransfer.setData(key, data !== null && data !== void 0 ? data : '');
2042
- }
2043
- }
2044
-
2045
- /**
2046
- * 📱 For Android devices, a drag operation will not start unless
2047
- * "text/plain" or "text/uri-list" data exists in the native data store
2048
- * https://twitter.com/alexandereardon/status/1732189803754713424
2049
- *
2050
- * Tested on:
2051
- * Device: Google Pixel 5
2052
- * Android version: 14 (November 5, 2023)
2053
- * Chrome version: 120.0
2054
- */
2055
- if (isAndroid() && !event.dataTransfer.types.includes(textMediaType) && !event.dataTransfer.types.includes(URLMediaType)) {
2056
- event.dataTransfer.setData(textMediaType, androidFallbackText);
2057
- }
2058
-
2059
- /**
2060
- * 1. Must set any media type for `iOS15` to work
2061
- * 2. We are also doing adding data so that the native adapter
2062
- * can know that the element adapter has handled this drag
2063
- *
2064
- * We used to wrap this `setData()` in a `try/catch` for Firefox,
2065
- * but it looks like that was not needed.
2066
- *
2067
- * Tested using: https://codesandbox.io/s/checking-firefox-throw-behaviour-on-dragstart-qt8h4f
2068
- *
2069
- * - ✅ Firefox@70.0 (Oct 2019) on macOS Sonoma
2070
- * - ✅ Firefox@70.0 (Oct 2019) on macOS Big Sur
2071
- * - ✅ Firefox@70.0 (Oct 2019) on Windows 10
2072
- *
2073
- * // just checking a few more combinations to be super safe
2074
- *
2075
- * - ✅ Chrome@78 (Oct 2019) on macOS Big Sur
2076
- * - ✅ Chrome@78 (Oct 2019) on Windows 10
2077
- * - ✅ Safari@14.1 on macOS Big Sur
2078
- */
2079
- event.dataTransfer.setData(elementAdapterNativeDataKey, '');
2080
- var payload = {
2081
- element: entry.element,
2082
- dragHandle: (_entry$dragHandle2 = entry.dragHandle) !== null && _entry$dragHandle2 !== void 0 ? _entry$dragHandle2 : null,
2083
- data: (_entry$getInitialData3 = (_entry$getInitialData4 = entry.getInitialData) === null || _entry$getInitialData4 === void 0 ? void 0 : _entry$getInitialData4.call(entry, feedback)) !== null && _entry$getInitialData3 !== void 0 ? _entry$getInitialData3 : {}
2084
- };
2085
- var dragType = {
2086
- type: 'element',
2087
- payload: payload,
2088
- startedFrom: 'internal'
2089
- };
2090
- api.start({
2091
- event: event,
2092
- dragType: dragType
2093
- });
2094
- }
2095
- }));
2096
- },
2097
- dispatchEventToSource: function dispatchEventToSource(_ref) {
2098
- var _draggableRegistry$ge, _draggableRegistry$ge2;
2099
- var eventName = _ref.eventName,
2100
- payload = _ref.payload;
2101
- // During a drag operation, a draggable can be:
2102
- // - remounted with different functions
2103
- // - removed completely
2104
- // So we need to get the latest entry from the registry in order
2105
- // to call the latest event functions
2106
-
2107
- (_draggableRegistry$ge = draggableRegistry.get(payload.source.element)) === null || _draggableRegistry$ge === void 0 || (_draggableRegistry$ge2 = _draggableRegistry$ge[eventName]) === null || _draggableRegistry$ge2 === void 0 || _draggableRegistry$ge2.call(_draggableRegistry$ge,
2108
- // I cannot seem to get the types right here.
2109
- // TS doesn't seem to like that one event can need `nativeSetDragImage`
2110
- // @ts-expect-error
2111
- payload);
2112
- },
2113
- onPostDispatch: honeyPotFix.getOnPostDispatch()
2114
- });
2115
- var dropTargetForElements = adapter.dropTarget;
2116
-
2117
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
2118
- function draggable(args) {
2119
- var cleanup = combine(
2120
- // making the draggable register the adapter rather than drop targets
2121
- // this is because you *must* have a draggable element to start a drag
2122
- // but you _might_ not have any drop targets immediately
2123
- // (You might create drop targets async)
2124
- adapter.registerUsage(), addToRegistry(args), addAttribute(args.element, {
2125
- attribute: 'draggable',
2126
- value: 'true'
2127
- }));
2128
-
2129
- // Wrapping in `once` to prevent unexpected side effects if consumers call
2130
- // the clean up function multiple times.
2131
- return once(cleanup);
2132
- }
2133
-
2134
- /** Common event payload for all events */
2135
-
2136
- /** A map containing payloads for all events */
2137
-
2138
- /** Common event payload for all drop target events */
2139
-
2140
- /** A map containing payloads for all events on drop targets */
2141
-
2142
- /** Arguments given to all feedback functions (eg `canDrag()`) on for a `draggable()` */
2143
-
2144
- /** Arguments given to all feedback functions (eg `canDrop()`) on a `dropTargetForElements()` */
2145
-
2146
- /** Arguments given to all monitor feedback functions (eg `canMonitor()`) for a `monitorForElements` */
2147
-
2148
- function toBrickDropDetail(data, parentPath, index$1) {
2149
- if (data.kind === 'new-brick') {
2150
- const mold = index.getBrickMolds().find((candidate) => candidate.type === data.moldType &&
2151
- candidate.id === data.moldId);
2152
- if (!mold)
2153
- return undefined;
2154
- return { source: 'new', mold, parentPath, index: index$1 };
2155
- }
2156
- if (data.kind === 'move-brick') {
2157
- return { source: 'move', from: data.path, parentPath, index: index$1 };
2158
- }
2159
- return undefined;
2160
- }
2161
-
2162
- const fkBrickActionsCss = () => `.fk-actions.sc-fk-brick-actions{position:relative;padding:calc(var(--fk-spacing) / 2);border:1px solid transparent;border-radius:var(--fk-radius)}.fk-actions.sc-fk-brick-actions:hover{border-color:var(--fk-color-border)}.fk-actions--selected.sc-fk-brick-actions,.fk-actions--selected.sc-fk-brick-actions:hover{border-color:var(--fk-color-primary);box-shadow:0 0 0 2px color-mix(in srgb, var(--fk-color-primary) 20%, transparent)}.fk-actions--dragging.sc-fk-brick-actions{opacity:0.5}.fk-actions--drop-before.sc-fk-brick-actions::before{content:'';position:absolute;top:-2px;left:0;right:0;height:3px;border-radius:2px;background:var(--fk-color-primary)}.fk-actions__toolbar.sc-fk-brick-actions{position:absolute;top:calc(var(--fk-spacing) / -2);right:var(--fk-spacing);z-index:1;display:none;gap:2px;padding:2px;border:1px solid var(--fk-color-border);border-radius:calc(var(--fk-radius) / 2);background:var(--fk-color-surface);box-shadow:0 2px 6px var(--fk-color-shadow)}.fk-actions.sc-fk-brick-actions:hover>.fk-actions__toolbar.sc-fk-brick-actions{display:flex}.fk-actions__button.sc-fk-brick-actions{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:none;border-radius:calc(var(--fk-radius) / 2);background:transparent;color:var(--fk-color-muted);font-size:0.8rem;cursor:pointer}.fk-actions__button.sc-fk-brick-actions:hover{background:color-mix(in srgb, var(--fk-color-primary) 12%, transparent);color:var(--fk-color-primary)}.fk-actions__button--danger.sc-fk-brick-actions:hover{background:color-mix(in srgb, var(--fk-color-danger) 12%, transparent);color:var(--fk-color-danger)}.fk-actions__handle.sc-fk-brick-actions{cursor:grab}`;
2163
-
2164
- const FkBrickActions = class {
2165
- constructor(hostRef) {
2166
- index$1.registerInstance(this, hostRef);
2167
- this.brickRemove = index$1.createEvent(this, "brickRemove");
2168
- this.brickDuplicate = index$1.createEvent(this, "brickDuplicate");
2169
- this.brickDrop = index$1.createEvent(this, "brickDrop");
2170
- this.brickSelect = index$1.createEvent(this, "brickSelect");
2171
- this.selected = false;
2172
- this.isDragging = false;
2173
- this.isDropTarget = false;
2174
- this.cleanups = [];
2175
- }
2176
- componentDidLoad() {
2177
- if (this.handleEl) {
2178
- this.cleanups.push(draggable({
2179
- element: this.handleEl,
2180
- getInitialData: () => ({ kind: 'move-brick', path: this.path }),
2181
- onDragStart: () => (this.isDragging = true),
2182
- onDrop: () => (this.isDragging = false),
2183
- }));
2184
- }
2185
- this.cleanups.push(dropTargetForElements({
2186
- element: this.host,
2187
- onDrag: ({ location }) => {
2188
- var _a;
2189
- return (this.isDropTarget =
2190
- ((_a = location.current.dropTargets[0]) === null || _a === void 0 ? void 0 : _a.element) === this.host);
2191
- },
2192
- onDragLeave: () => (this.isDropTarget = false),
2193
- onDrop: ({ source, location }) => {
2194
- var _a;
2195
- this.isDropTarget = false;
2196
- if (((_a = location.current.dropTargets[0]) === null || _a === void 0 ? void 0 : _a.element) !== this.host)
2197
- return;
2198
- const segments = this.path.split('.');
2199
- const detail = toBrickDropDetail(source.data, segments.slice(0, -1).join('.'), Number(segments[segments.length - 1]));
2200
- if (detail)
2201
- this.brickDrop.emit(detail);
2202
- },
2203
- }));
2204
- }
2205
- disconnectedCallback() {
2206
- this.cleanups.forEach((cleanup) => cleanup());
2207
- this.cleanups = [];
2208
- }
2209
- render() {
2210
- return (index$1.h("div", { key: 'ea1cc1c7af646f403330c98b251714f3968c1aae', class: {
2211
- 'fk-actions': true,
2212
- 'fk-actions--dragging': this.isDragging,
2213
- 'fk-actions--drop-before': this.isDropTarget,
2214
- 'fk-actions--selected': this.selected,
2215
- }, onClick: (event) => {
2216
- event.stopPropagation();
2217
- this.brickSelect.emit({ path: this.path });
2218
- } }, index$1.h("div", { key: '99c08de8c78ff6362103f9e355ff6aa3da1367ee', class: "fk-actions__toolbar" }, index$1.h("button", { key: '8702b1f565ea639585614d4c6e88b2dc44c7ed7c', type: "button", class: "fk-actions__button fk-actions__handle", ref: (el) => (this.handleEl = el), title: index.fkT('actions.move') }, "\u283F"), index$1.h("button", { key: '7394adc36780dbd61195b69cd21fce3c8a852f2a', type: "button", class: "fk-actions__button", title: index.fkT('actions.duplicate'), onClick: (event) => {
2219
- event.stopPropagation();
2220
- this.brickDuplicate.emit({ path: this.path });
2221
- } }, "\u29C9"), index$1.h("button", { key: 'ddea0decbc02a4b0627170c973ed19180aa6f651', type: "button", class: "fk-actions__button fk-actions__button--danger", title: index.fkT('actions.delete'), onClick: (event) => {
2222
- event.stopPropagation();
2223
- this.brickRemove.emit({ path: this.path });
2224
- } }, "\u2715")), index$1.h("slot", { key: '44fa7c12a7581ff6b62f29fb1249d427594b5e1f' })));
2225
- }
2226
- get host() { return index$1.getElement(this); }
2227
- };
2228
- FkBrickActions.style = fkBrickActionsCss();
2229
-
2230
- const fkBrickListCss = () => `.fk-palette.sc-fk-brick-list{display:flex;flex-direction:column;gap:var(--fk-spacing);font-family:var(--fk-font)}.fk-palette__search.sc-fk-brick-list{font:inherit;font-size:0.85rem;padding:calc(var(--fk-spacing) / 1.5) var(--fk-spacing);border:1px solid var(--fk-color-border);border-radius:calc(var(--fk-radius) / 1.5);background:var(--fk-color-surface);color:var(--fk-color-text)}.fk-palette__search.sc-fk-brick-list:focus{outline:none;border-color:var(--fk-color-primary);box-shadow:0 0 0 2px color-mix(in srgb, var(--fk-color-primary) 20%, transparent)}.fk-palette__category.sc-fk-brick-list{display:flex;align-items:center;gap:calc(var(--fk-spacing) / 2);width:100%;margin:0 0 calc(var(--fk-spacing) / 2);padding:calc(var(--fk-spacing) / 2) 0;border:none;background:transparent;font:inherit;font-size:0.7rem;font-weight:700;letter-spacing:0.08em;text-transform:uppercase;color:var(--fk-color-muted);cursor:pointer}.fk-palette__category.sc-fk-brick-list:hover{color:var(--fk-color-text)}.fk-palette__chevron.sc-fk-brick-list{display:inline-block;transition:transform 120ms ease}.fk-palette__chevron--collapsed.sc-fk-brick-list{transform:rotate(-90deg)}.fk-palette__count.sc-fk-brick-list{margin-left:auto;font-weight:600;color:var(--fk-color-muted)}.fk-palette__items.sc-fk-brick-list{display:grid;grid-template-columns:repeat(2, minmax(0, 1fr));gap:calc(var(--fk-spacing) / 2)}.fk-palette__empty.sc-fk-brick-list{margin:0;font-size:0.8rem;color:var(--fk-color-muted)}`;
2231
-
2232
- const FkBrickList = class {
2233
- constructor(hostRef) {
2234
- index$1.registerInstance(this, hostRef);
2235
- this.query = '';
2236
- this.collapsed = {};
2237
- }
2238
- toggle(category) {
2239
- this.collapsed = Object.assign(Object.assign({}, this.collapsed), { [category]: !this.collapsed[category] });
2240
- }
2241
- render() {
2242
- const grouped = index.getBrickMoldsGroupedByCategory();
2243
- const query = this.query.trim().toLowerCase();
2244
- const filtered = Object.entries(grouped)
2245
- .map(([category, molds]) => ({
2246
- category,
2247
- molds: query
2248
- ? molds.filter((mold) => [
2249
- mold.name,
2250
- index.fkTOr(`brick.${mold.id}.name`, mold.name),
2251
- mold.id,
2252
- category,
2253
- index.fkTOr(`category.${category}`, category),
2254
- ].some((candidate) => candidate.toLowerCase().includes(query)))
2255
- : molds,
2256
- }))
2257
- .filter((group) => group.molds.length > 0);
2258
- return (index$1.h(index$1.Host, { key: '93facfae49363bb2fe1ceeb5ab84105fc5f339fa' }, index$1.h("div", { key: 'dc68df2c48929c7e5d6c4037b755761f0f581898', class: "fk-palette" }, index$1.h("input", { key: '6acf14db7433b4a4bfb4cca2ca0fd51465785d7f', class: "fk-palette__search", type: "search", placeholder: index.fkT('palette.search'), value: this.query, onInput: (event) => (this.query = event.target.value) }), filtered.map(({ category, molds }) => {
2259
- const isCollapsed = !query && this.collapsed[category];
2260
- return (index$1.h("section", { class: "fk-palette__group", key: category }, index$1.h("button", { type: "button", class: "fk-palette__category", onClick: () => this.toggle(category) }, index$1.h("span", { class: {
2261
- 'fk-palette__chevron': true,
2262
- 'fk-palette__chevron--collapsed': isCollapsed,
2263
- } }, "\u25BE"), index.fkTOr(`category.${category}`, category), index$1.h("span", { class: "fk-palette__count" }, molds.length)), !isCollapsed ? (index$1.h("div", { class: "fk-palette__items" }, molds.map((mold) => (index$1.h("fk-brick-mold-item", { brickMold: mold, key: `${mold.type}:${mold.id}` }))))) : null));
2264
- }), filtered.length === 0 ? (index$1.h("p", { class: "fk-palette__empty" }, index.fkT('palette.empty', { query: this.query }))) : null)));
2265
- }
2266
- };
2267
- FkBrickList.style = fkBrickListCss();
2268
-
2269
- const fkBrickMoldItemCss = () => `.sc-fk-brick-mold-item-h{display:block;cursor:grab;min-width:0}.fk-mold.sc-fk-brick-mold-item{display:flex;align-items:center;padding:calc(var(--fk-spacing) / 1.5) var(--fk-spacing);border:1px solid var(--fk-color-border);border-radius:calc(var(--fk-radius) / 1.5);background:var(--fk-color-surface);font-size:0.8rem;transition:border-color 120ms ease, box-shadow 120ms ease}.fk-mold.sc-fk-brick-mold-item:hover{border-color:var(--fk-color-primary);box-shadow:0 1px 4px var(--fk-color-shadow)}.fk-mold--dragging.sc-fk-brick-mold-item{opacity:0.5}.fk-mold__name.sc-fk-brick-mold-item{font-weight:500;color:var(--fk-color-text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}`;
2270
-
2271
- const FkBrickMoldItem = class {
2272
- constructor(hostRef) {
2273
- index$1.registerInstance(this, hostRef);
2274
- this.isDragging = false;
2275
- }
2276
- componentDidLoad() {
2277
- this.cleanup = draggable({
2278
- element: this.host,
2279
- getInitialData: () => ({
2280
- kind: 'new-brick',
2281
- moldType: this.brickMold.type,
2282
- moldId: this.brickMold.id,
2283
- }),
2284
- onDragStart: () => (this.isDragging = true),
2285
- onDrop: () => (this.isDragging = false),
2286
- });
2287
- }
2288
- disconnectedCallback() {
2289
- var _a;
2290
- (_a = this.cleanup) === null || _a === void 0 ? void 0 : _a.call(this);
2291
- }
2292
- render() {
2293
- return (index$1.h("div", { key: '0570015fb47b6be613f900a333b061537006edec', class: { 'fk-mold': true, 'fk-mold--dragging': this.isDragging }, title: index.fkTOr(`brick.${this.brickMold.id}.name`, this.brickMold.name) }, index$1.h("span", { key: 'bf3ab329f7a4b054c56e042dd83822706546c93b', class: "fk-mold__name" }, index.fkTOr(`brick.${this.brickMold.id}.name`, this.brickMold.name))));
2294
- }
2295
- get host() { return index$1.getElement(this); }
2296
- };
2297
- FkBrickMoldItem.style = fkBrickMoldItemCss();
2298
-
2299
- const fkBrickNotFoundCss = () => `.fk-not-found.sc-fk-brick-not-found{margin:0;padding:calc(var(--fk-spacing) * 1.5);border:1px dashed var(--fk-color-danger);border-radius:var(--fk-radius);color:var(--fk-color-danger);font-size:0.875rem}`;
2300
-
2301
- const FkBrickNotFound = class {
2302
- constructor(hostRef) {
2303
- index$1.registerInstance(this, hostRef);
2304
- }
2305
- render() {
2306
- return (index$1.h(index$1.Host, { key: '558231ac77ac07f7b40bd08081a498dc5623442c' }, index$1.h("p", { key: 'f1ca1f59750c6ed2b1a3c2e22bd6f7f1dc721496', class: "fk-not-found" }, "Brick ", index$1.h("slot", { key: '0003d9dcc23c52cb8d466d794eafd4dd6be4b708' }), " not found")));
2307
- }
2308
- };
2309
- FkBrickNotFound.style = fkBrickNotFoundCss();
2310
-
2311
- function getBrickData(brickSpec, data) {
2312
- var _a;
2313
- if (!((_a = brickSpec.configs) === null || _a === void 0 ? void 0 : _a.key) || !data)
2314
- return undefined;
2315
- if (brickSpec.unWrapData)
2316
- return data;
2317
- return data[brickSpec.configs.key];
2318
- }
2319
- function wrapBrickData(brickSpec, value) {
2320
- var _a;
2321
- if (!((_a = brickSpec.configs) === null || _a === void 0 ? void 0 : _a.key))
2322
- return undefined;
2323
- if (brickSpec.unWrapData)
2324
- return value;
2325
- return { [brickSpec.configs.key]: value };
2326
- }
2327
-
2328
- const FkBrickRender = class {
2329
- constructor(hostRef) {
2330
- index$1.registerInstance(this, hostRef);
2331
- this.brickDataChange = index$1.createEvent(this, "brickDataChange");
2332
- this.brickConfigsChange = index$1.createEvent(this, "brickConfigsChange");
2333
- this.brickStylesChange = index$1.createEvent(this, "brickStylesChange");
2334
- this.brickValidationsChange = index$1.createEvent(this, "brickValidationsChange");
2335
- this.brickRulesChange = index$1.createEvent(this, "brickRulesChange");
2336
- this.brickRemove = index$1.createEvent(this, "brickRemove");
2337
- this.brickDuplicate = index$1.createEvent(this, "brickDuplicate");
2338
- this.path = '0';
2339
- this.editable = false;
2340
- this.errors = {};
2341
- }
2342
- render() {
2343
- var _a, _b, _c, _d, _e, _f;
2344
- const spec = this.brickSpec;
2345
- if (!spec)
2346
- return null;
2347
- const brick = index.getBrick(spec.type, spec.id);
2348
- if (!brick) {
2349
- return index$1.h("fk-brick-not-found", null, `${spec.type}:${spec.id}`);
2350
- }
2351
- const editing = this.editable && ((_a = spec.editable) !== null && _a !== void 0 ? _a : true);
2352
- const affected = index.getAffectedProperties(spec.rules, this.dataMap);
2353
- if (!editing && affected.hidden === true)
2354
- return null;
2355
- const isContainer = spec.type === 'panel' || spec.type === 'collection';
2356
- const uid = (_b = spec.configs) === null || _b === void 0 ? void 0 : _b.uid;
2357
- const childNodes = ((_c = spec.children) !== null && _c !== void 0 ? _c : []).map((childSpec, index) => {
2358
- var _a;
2359
- return (index$1.h("fk-brick-render", { brickSpec: childSpec, rootSpec: (_a = this.rootSpec) !== null && _a !== void 0 ? _a : this.brickSpec, data: this.data, dataMap: this.dataMap, errors: this.errors, locale: this.locale, path: `${this.path}.${index}`, editable: this.editable, selectedUid: this.selectedUid, utils: this.utils }));
2360
- });
2361
- if (editing && isContainer) {
2362
- childNodes.push(index$1.h("fk-drop-area", { path: this.path }));
2363
- }
2364
- const props = {
2365
- brickSpec: spec,
2366
- configsForm: spec.configsForm,
2367
- configs: index.resolveLocalizedRecord(spec.configs, this.locale),
2368
- locale: this.locale,
2369
- styles: (_d = spec.styles) !== null && _d !== void 0 ? _d : {},
2370
- data: getBrickData(spec, this.data),
2371
- dataMap: this.dataMap,
2372
- rootSpec: (_e = this.rootSpec) !== null && _e !== void 0 ? _e : this.brickSpec,
2373
- error: ((_f = spec.configs) === null || _f === void 0 ? void 0 : _f.key) ? this.errors[spec.configs.key] : undefined,
2374
- disabled: editing ? false : affected.disabled === true,
2375
- path: this.path,
2376
- editable: editing,
2377
- children: childNodes,
2378
- validations: spec.validations,
2379
- rules: spec.rules,
2380
- utils: this.utils,
2381
- onDataChange: (value) => {
2382
- const wrapped = wrapBrickData(spec, value);
2383
- if (wrapped !== undefined)
2384
- this.brickDataChange.emit(wrapped);
2385
- },
2386
- onConfigsChange: (configs, changedUid) => this.brickConfigsChange.emit({ configs, uid: changedUid !== null && changedUid !== void 0 ? changedUid : uid }),
2387
- onStylesChange: (styles, changedUid) => this.brickStylesChange.emit({
2388
- styles: styles,
2389
- uid: changedUid !== null && changedUid !== void 0 ? changedUid : uid,
2390
- }),
2391
- onValidationsChange: (validations, changedUid) => this.brickValidationsChange.emit({ validations, uid: changedUid !== null && changedUid !== void 0 ? changedUid : uid }),
2392
- onRulesChange: (rules, changedUid) => this.brickRulesChange.emit({ rules, uid: changedUid !== null && changedUid !== void 0 ? changedUid : uid }),
2393
- onDelete: (path) => this.brickRemove.emit({ path }),
2394
- onDuplicate: (path) => this.brickDuplicate.emit({ path }),
2395
- };
2396
- const node = (editing ? brick.renderBuilder(props) : brick.render(props));
2397
- if (!editing || this.path === '0')
2398
- return node;
2399
- return (index$1.h("fk-brick-actions", { path: this.path, selected: uid !== undefined && uid === this.selectedUid }, node));
2400
- }
2401
- };
2402
-
2403
- const fkCodeEditorCss = () => `.sc-fk-code-editor-h{display:block}.sc-fk-code-editor-h .cm-editor.sc-fk-code-editor{min-height:88px;font-size:0.75rem;border:1px solid var(--fk-color-border);border-radius:calc(var(--fk-radius) / 2);background:var(--fk-color-surface)}.sc-fk-code-editor-h .cm-editor.cm-focused.sc-fk-code-editor{outline:none;border-color:var(--fk-color-primary)}.sc-fk-code-editor-h .cm-gutters.sc-fk-code-editor{border-right:1px solid var(--fk-color-border);background:color-mix(in srgb, var(--fk-color-surface) 70%, transparent);color:var(--fk-color-muted)}.sc-fk-code-editor-h .cm-content.sc-fk-code-editor{font-family:ui-monospace, SFMono-Regular, Menlo, monospace}`;
2404
-
2405
- const fetchCodeMirror = () => Promise.all([
2406
- Promise.resolve().then(function () { return require('./index-Ds0sDbXV.js'); }),
2407
- Promise.resolve().then(function () { return require('./index-DHgK3reD.js'); }).then(function (n) { return n.index; }),
2408
- Promise.resolve().then(function () { return require('./index-c9BL7y3N.js'); }),
2409
- Promise.resolve().then(function () { return require('./index-CdaT3-qx.js'); }).then(function (n) { return n.index; }),
2410
- Promise.resolve().then(function () { return require('./index-Bhy1RJMV.js'); }),
2411
- ]);
2412
- let codeMirrorModules;
2413
- const loadCodeMirror = () => (codeMirrorModules !== null && codeMirrorModules !== void 0 ? codeMirrorModules : (codeMirrorModules = fetchCodeMirror()));
2414
- const FkCodeEditor = class {
2415
- constructor(hostRef) {
2416
- index$1.registerInstance(this, hostRef);
2417
- this.codeChange = index$1.createEvent(this, "codeChange");
2418
- this.value = '';
2419
- this.placeholder = '';
2420
- this.disconnected = false;
2421
- }
2422
- async componentDidLoad() {
2423
- const [{ EditorState }, { EditorView: View, keymap, lineNumbers, placeholder: cmPlaceholder }, { defaultKeymap, history, historyKeymap }, { defaultHighlightStyle, syntaxHighlighting }, { javascript },] = await loadCodeMirror();
2424
- if (this.disconnected)
2425
- return;
2426
- this.view = new View({
2427
- parent: this.host,
2428
- state: EditorState.create({
2429
- doc: this.value,
2430
- extensions: [
2431
- lineNumbers(),
2432
- history(),
2433
- keymap.of([...defaultKeymap, ...historyKeymap]),
2434
- javascript(),
2435
- syntaxHighlighting(defaultHighlightStyle),
2436
- cmPlaceholder(this.placeholder),
2437
- View.domEventHandlers({
2438
- blur: () => this.emitIfChanged(),
2439
- }),
2440
- ],
2441
- }),
2442
- });
2443
- }
2444
- syncValue(next) {
2445
- if (!this.view || this.view.hasFocus)
2446
- return;
2447
- const current = this.view.state.doc.toString();
2448
- if (current !== next) {
2449
- this.view.dispatch({
2450
- changes: { from: 0, to: current.length, insert: next },
2451
- });
2452
- }
2453
- }
2454
- emitIfChanged() {
2455
- if (!this.view)
2456
- return;
2457
- const doc = this.view.state.doc.toString();
2458
- if (doc !== this.value)
2459
- this.codeChange.emit(doc);
2460
- }
2461
- disconnectedCallback() {
2462
- var _a;
2463
- this.disconnected = true;
2464
- (_a = this.view) === null || _a === void 0 ? void 0 : _a.destroy();
2465
- this.view = undefined;
2466
- }
2467
- render() {
2468
- return null;
2469
- }
2470
- get host() { return index$1.getElement(this); }
2471
- static get watchers() { return {
2472
- "value": [{
2473
- "syncValue": 0
2474
- }]
2475
- }; }
2476
- };
2477
- FkCodeEditor.style = fkCodeEditorCss();
2478
-
2479
- const fkDataGridCss = () => `.sc-fk-data-grid-h{display:block}.fk-grid.sc-fk-data-grid{display:flex;flex-direction:column;gap:var(--fk-spacing)}.fk-grid__empty.sc-fk-data-grid{margin:0;padding:var(--fk-spacing);border:1px dashed var(--fk-color-border);border-radius:var(--fk-radius);font-size:0.85rem;color:var(--fk-color-muted);text-align:center}.fk-grid__row.sc-fk-data-grid{display:flex;align-items:flex-start;gap:var(--fk-spacing);padding:var(--fk-spacing);border:1px solid var(--fk-color-border);border-radius:var(--fk-radius);background:color-mix(in srgb, var(--fk-color-surface) 60%, transparent)}.fk-grid__cells.sc-fk-data-grid{display:flex;flex:1;flex-wrap:wrap;gap:var(--fk-spacing);min-width:0}.fk-grid__cells.sc-fk-data-grid>*.sc-fk-data-grid{flex:1;min-width:160px}.fk-grid__remove.sc-fk-data-grid{border:none;background:transparent;color:var(--fk-color-muted);font-size:0.8rem;cursor:pointer;padding:4px 6px;border-radius:calc(var(--fk-radius) / 2)}.fk-grid__remove.sc-fk-data-grid:hover:not(:disabled){color:var(--fk-color-danger);background:color-mix(in srgb, var(--fk-color-danger) 10%, transparent)}.fk-grid__add.sc-fk-data-grid{align-self:flex-start;font:inherit;font-size:0.8rem;font-weight:600;padding:calc(var(--fk-spacing) / 1.5) var(--fk-spacing);border:1px dashed var(--fk-color-border);border-radius:var(--fk-radius);background:transparent;color:var(--fk-color-muted);cursor:pointer}.fk-grid__add.sc-fk-data-grid:hover:not(:disabled){border-color:var(--fk-color-primary);color:var(--fk-color-primary)}`;
2480
-
2481
- const FkDataGrid = class {
2482
- constructor(hostRef) {
2483
- index$1.registerInstance(this, hostRef);
2484
- this.gridValueChange = index$1.createEvent(this, "gridValueChange");
2485
- this.disabled = false;
2486
- this.touched = {};
2487
- this.addRow = (event) => {
2488
- event.preventDefault();
2489
- this.gridValueChange.emit([...this.rows(), {}]);
2490
- };
2491
- }
2492
- rows() {
2493
- return Array.isArray(this.value)
2494
- ? this.value
2495
- : [];
2496
- }
2497
- rowSpec() {
2498
- var _a, _b;
2499
- if (((_a = this.rowSpecCache) === null || _a === void 0 ? void 0 : _a.source) !== this.spec) {
2500
- this.rowSpecCache = {
2501
- source: this.spec,
2502
- rowSpec: {
2503
- type: 'panel',
2504
- id: 'grid-row',
2505
- name: 'Row',
2506
- configs: { key: 'row' },
2507
- children: (_b = this.spec.children) !== null && _b !== void 0 ? _b : [],
2508
- },
2509
- };
2510
- }
2511
- return this.rowSpecCache.rowSpec;
2512
- }
2513
- rowErrors(row) {
2514
- const present = Object.fromEntries(Object.entries(row).filter(([, value]) => value !== '' && value !== null && value !== undefined));
2515
- return index.validateBrickSpecDataDetailed(this.rowSpec(), present, this.locale)
2516
- .errors;
2517
- }
2518
- visibleRowErrors(index) {
2519
- var _a, _b;
2520
- const row = (_a = this.rows()[index]) !== null && _a !== void 0 ? _a : {};
2521
- const touched = (_b = this.touched[index]) !== null && _b !== void 0 ? _b : {};
2522
- const errors = {};
2523
- for (const [key, message] of Object.entries(this.rowErrors(row))) {
2524
- if (touched[key])
2525
- errors[key] = message;
2526
- }
2527
- return errors;
2528
- }
2529
- handleRowChange(event) {
2530
- var _a, _b;
2531
- event.stopPropagation();
2532
- const origin = event.target;
2533
- const rowEl = origin.closest('[data-grid-row]');
2534
- const index = Number((_a = rowEl === null || rowEl === void 0 ? void 0 : rowEl.getAttribute('data-grid-row')) !== null && _a !== void 0 ? _a : -1);
2535
- if (index < 0)
2536
- return;
2537
- const rowTouched = Object.assign({}, ((_b = this.touched[index]) !== null && _b !== void 0 ? _b : {}));
2538
- for (const key of Object.keys(event.detail))
2539
- rowTouched[key] = true;
2540
- this.touched = Object.assign(Object.assign({}, this.touched), { [index]: rowTouched });
2541
- const rows = this.rows().map((row, i) => i === index ? Object.assign(Object.assign({}, row), event.detail) : row);
2542
- this.gridValueChange.emit(rows);
2543
- }
2544
- async validateRows() {
2545
- var _a, _b;
2546
- const rows = this.rows();
2547
- const gridKey = (_b = (_a = this.spec.configs) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : 'grid';
2548
- const allTouched = {};
2549
- const errors = {};
2550
- rows.forEach((row, index) => {
2551
- var _a, _b;
2552
- const rowTouched = {};
2553
- for (const child of (_a = this.spec.children) !== null && _a !== void 0 ? _a : []) {
2554
- if ((_b = child.configs) === null || _b === void 0 ? void 0 : _b.key)
2555
- rowTouched[child.configs.key] = true;
2556
- }
2557
- allTouched[index] = rowTouched;
2558
- for (const [key, message] of Object.entries(this.rowErrors(row))) {
2559
- errors[`${gridKey}[${index}].${key}`] = message;
2560
- }
2561
- });
2562
- this.touched = allTouched;
2563
- return { valid: Object.keys(errors).length === 0, errors };
2564
- }
2565
- removeRow(index) {
2566
- const rows = this.rows().filter((_, i) => i !== index);
2567
- const touched = {};
2568
- for (const [key, value] of Object.entries(this.touched)) {
2569
- const i = Number(key);
2570
- if (i < index)
2571
- touched[i] = value;
2572
- else if (i > index)
2573
- touched[i - 1] = value;
2574
- }
2575
- this.touched = touched;
2576
- this.gridValueChange.emit(rows.length ? rows : undefined);
2577
- }
2578
- render() {
2579
- var _a;
2580
- const children = (_a = this.spec.children) !== null && _a !== void 0 ? _a : [];
2581
- const rows = this.rows();
2582
- return (index$1.h("div", { key: '1c77d72cd1482d673ffdb5b7d67ca200e55919d7', class: "fk-grid" }, rows.length === 0 ? (index$1.h("p", { class: "fk-grid__empty" }, index.fkT('grid.empty'))) : null, rows.map((row, index$2) => (index$1.h("div", { class: "fk-grid__row", "data-grid-row": index$2, key: index$2 }, index$1.h("div", { class: "fk-grid__cells" }, children.map((child, childIndex) => (index$1.h("fk-brick-render", { brickSpec: child, data: row, dataMap: row, errors: this.visibleRowErrors(index$2), locale: this.locale, path: `grid.${index$2}.${childIndex}`, utils: this.utils })))), index$1.h("button", { type: "button", class: "fk-grid__remove", title: index.fkT('grid.removeRow'), disabled: this.disabled, onClick: (event) => {
2583
- event.preventDefault();
2584
- this.removeRow(index$2);
2585
- } }, "\u2715")))), index$1.h("button", { key: '9bf04c364b3262c436ffb580daf802d15f29de57', type: "button", class: "fk-grid__add", disabled: this.disabled, onClick: this.addRow }, index.fkT('grid.addRow'))));
2586
- }
2587
- };
2588
- FkDataGrid.style = fkDataGridCss();
2589
-
2590
- const fkDropAreaCss = () => `.fk-drop.sc-fk-drop-area{display:flex;align-items:center;justify-content:center;min-height:40px;margin-top:calc(var(--fk-spacing) / 2);border:1px dashed var(--fk-color-border);border-radius:var(--fk-radius);color:var(--fk-color-muted);font-size:0.75rem;transition:border-color 120ms ease, background-color 120ms ease}.fk-drop--over.sc-fk-drop-area{border-color:var(--fk-color-primary);background:color-mix(in srgb, var(--fk-color-primary) 8%, transparent);color:var(--fk-color-primary)}`;
2591
-
2592
- const FkDropArea = class {
2593
- constructor(hostRef) {
2594
- index$1.registerInstance(this, hostRef);
2595
- this.brickDrop = index$1.createEvent(this, "brickDrop");
2596
- this.isOver = false;
2597
- }
2598
- componentDidLoad() {
2599
- this.cleanup = dropTargetForElements({
2600
- element: this.host,
2601
- onDragEnter: () => (this.isOver = true),
2602
- onDragLeave: () => (this.isOver = false),
2603
- onDrop: ({ source, location }) => {
2604
- var _a;
2605
- this.isOver = false;
2606
- if (((_a = location.current.dropTargets[0]) === null || _a === void 0 ? void 0 : _a.element) !== this.host)
2607
- return;
2608
- const detail = toBrickDropDetail(source.data, this.path);
2609
- if (detail)
2610
- this.brickDrop.emit(detail);
2611
- },
2612
- });
2613
- }
2614
- disconnectedCallback() {
2615
- var _a;
2616
- (_a = this.cleanup) === null || _a === void 0 ? void 0 : _a.call(this);
2617
- }
2618
- render() {
2619
- return (index$1.h("div", { key: '727b7005fcc58e3b6b2f455b03312fd91e3b063b', class: { 'fk-drop': true, 'fk-drop--over': this.isOver } }, index$1.h("span", { key: '41d1158e101100ebb229b74aec2ddfaf1aa57202', class: "fk-drop__hint" }, index.fkT('drop.hint'))));
2620
- }
2621
- get host() { return index$1.getElement(this); }
2622
- };
2623
- FkDropArea.style = fkDropAreaCss();
2624
-
2625
- const fkEmptyFormCss = () => `.fk-empty.sc-fk-empty-form{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:calc(var(--fk-spacing) / 2);min-height:160px;border:2px dashed var(--fk-color-border);border-radius:var(--fk-radius);color:var(--fk-color-muted);text-align:center}.fk-empty__title.sc-fk-empty-form{margin:0;font-weight:600}.fk-empty__hint.sc-fk-empty-form{margin:0;font-size:0.875rem}`;
2626
-
2627
- const FkEmptyForm = class {
2628
- constructor(hostRef) {
2629
- index$1.registerInstance(this, hostRef);
2630
- }
2631
- render() {
2632
- return (index$1.h(index$1.Host, { key: '1b0ab4cd1d988a4800deeb6e3cfd8f5074520f6b' }, index$1.h("div", { key: '65b551e1cab6162514ad941b21e318c5f19b824a', class: "fk-empty" }, index$1.h("p", { key: 'c4eba1c6fecb4f2669f1c4dfb09cd816790a5ebf', class: "fk-empty__title" }, index.fkT('empty.title')), index$1.h("p", { key: '751bb3a2fc07982c90a214bd1e71592ec03d988d', class: "fk-empty__hint" }, index.fkT('empty.hint')))));
2633
- }
2634
- };
2635
- FkEmptyForm.style = fkEmptyFormCss();
2636
-
2637
- const fkFileInputCss = () => `.sc-fk-file-input-h{display:block}.fk-file.sc-fk-file-input{display:flex;flex-direction:column;gap:calc(var(--fk-spacing) / 2);align-items:flex-start}.fk-file__native.sc-fk-file-input{display:none}.fk-file__choose.sc-fk-file-input{font:inherit;font-size:0.85rem;padding:calc(var(--fk-spacing) / 1.5) var(--fk-spacing);border:1px dashed var(--fk-color-border);border-radius:var(--fk-radius);background:transparent;color:var(--fk-color-muted);cursor:pointer}.fk-file__choose.sc-fk-file-input:hover:not(:disabled){border-color:var(--fk-color-primary);color:var(--fk-color-primary)}.fk-file__choose.sc-fk-file-input:disabled{opacity:0.55;cursor:not-allowed}.fk-file__selected.sc-fk-file-input{display:flex;align-items:center;gap:var(--fk-spacing);width:100%;box-sizing:border-box;padding:calc(var(--fk-spacing) * 0.75) var(--fk-spacing);border:1px solid var(--fk-color-border);border-radius:var(--fk-radius);background:var(--fk-color-surface)}.fk-file__icon.sc-fk-file-input{display:inline-flex;flex-shrink:0;color:var(--fk-color-primary)}.fk-file__meta.sc-fk-file-input{display:flex;flex-direction:column;gap:2px;flex:1;min-width:0}.fk-file__name.sc-fk-file-input{font-size:0.85rem;font-weight:600;color:var(--fk-color-text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.fk-file__size.sc-fk-file-input{font-size:0.72rem;color:var(--fk-color-muted);white-space:nowrap}.fk-file__remove.sc-fk-file-input{border:none;background:transparent;color:var(--fk-color-muted);font-size:0.8rem;cursor:pointer;padding:4px 6px;border-radius:calc(var(--fk-radius) / 2);flex-shrink:0}.fk-file__remove.sc-fk-file-input:hover:not(:disabled){background:color-mix(in srgb, var(--fk-color-danger) 12%, transparent)}.fk-file__remove.sc-fk-file-input:hover:not(:disabled){color:var(--fk-color-danger)}`;
2638
-
2639
- const FkFileInput = class {
2640
- constructor(hostRef) {
2641
- index$1.registerInstance(this, hostRef);
2642
- this.fileValueChange = index$1.createEvent(this, "fileValueChange");
2643
- this.disabled = false;
2644
- this.multiple = false;
2645
- this.uploading = false;
2646
- this.handleFile = async (event) => {
2647
- var _a;
2648
- const input = event.target;
2649
- const selected = Array.from((_a = input.files) !== null && _a !== void 0 ? _a : []);
2650
- if (!selected.length)
2651
- return;
2652
- this.uploading = true;
2653
- this.uploadError = undefined;
2654
- try {
2655
- const uploaded = [];
2656
- for (const file of this.multiple ? selected : selected.slice(0, 1)) {
2657
- uploaded.push(await index.services.fileUploadService.upload(file, { url: this.uploadUrl }));
2658
- }
2659
- this.emitFiles(this.multiple ? [...this.files, ...uploaded] : uploaded);
2660
- }
2661
- catch (error) {
2662
- this.uploadError =
2663
- error instanceof Error ? error.message : String(error);
2664
- }
2665
- finally {
2666
- this.uploading = false;
2667
- input.value = '';
2668
- }
2669
- };
2670
- this.handleRemove = async (file) => {
2671
- var _a, _b;
2672
- this.removingUrl = file.url;
2673
- this.uploadError = undefined;
2674
- try {
2675
- await ((_b = (_a = index.services.fileUploadService).remove) === null || _b === void 0 ? void 0 : _b.call(_a, file, { url: this.uploadUrl }));
2676
- }
2677
- catch (error) {
2678
- this.uploadError = error instanceof Error ? error.message : String(error);
2679
- }
2680
- finally {
2681
- this.removingUrl = undefined;
2682
- this.emitFiles(this.files.filter((item) => item !== file));
2683
- }
2684
- };
2685
- }
2686
- get files() {
2687
- if (Array.isArray(this.value))
2688
- return this.value;
2689
- return this.value ? [this.value] : [];
2690
- }
2691
- emitFiles(files) {
2692
- if (this.multiple) {
2693
- this.fileValueChange.emit(files.length ? files : undefined);
2694
- }
2695
- else {
2696
- this.fileValueChange.emit(files[0]);
2697
- }
2698
- }
2699
- formatSize(size) {
2700
- if (size < 1024)
2701
- return `${size} B`;
2702
- if (size < 1024 * 1024)
2703
- return `${(size / 1024).toFixed(1)} KB`;
2704
- return `${(size / (1024 * 1024)).toFixed(1)} MB`;
2705
- }
2706
- renderFile(file) {
2707
- const removing = this.removingUrl !== undefined && this.removingUrl === file.url;
2708
- return (index$1.h("div", { class: "fk-file__selected", key: `${file.url}:${file.name}` }, index$1.h("span", { class: "fk-file__icon", "aria-hidden": "true" }, index$1.h("svg", { viewBox: "0 0 24 24", width: "16", height: "16", fill: "none", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }, index$1.h("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }), index$1.h("polyline", { points: "14 2 14 8 20 8" }))), index$1.h("span", { class: "fk-file__meta" }, index$1.h("span", { class: "fk-file__name", title: file.name }, file.name), index$1.h("span", { class: "fk-file__size" }, this.formatSize(file.size))), index$1.h("button", { type: "button", class: "fk-file__remove", title: index.fkT('file.remove'), disabled: this.disabled || removing, onClick: (event) => {
2709
- event.preventDefault();
2710
- void this.handleRemove(file);
2711
- } }, removing ? '…' : '✕')));
2712
- }
2713
- render() {
2714
- const files = this.files;
2715
- const showChoose = this.multiple || files.length === 0;
2716
- return (index$1.h("div", { key: '883cb0627b948d807f59ed5c62e44b0db421c3c6', class: "fk-file" }, files.map((file) => this.renderFile(file)), showChoose ? (index$1.h("button", { type: "button", class: "fk-file__choose", disabled: this.disabled || this.uploading, onClick: (event) => {
2717
- var _a;
2718
- event.preventDefault();
2719
- (_a = this.inputEl) === null || _a === void 0 ? void 0 : _a.click();
2720
- } }, this.uploading
2721
- ? index.fkT('file.uploading')
2722
- : this.multiple && files.length
2723
- ? index.fkTOr('file.addAnother', '+ Add a file')
2724
- : index.fkT('file.choose'))) : null, index$1.h("input", { key: 'a35947614d82f94eba8453b1f43382d2754cb36f', class: "fk-file__native", type: "file", accept: this.accept, multiple: this.multiple, disabled: this.disabled, ref: (element) => (this.inputEl = element), onChange: this.handleFile }), this.uploadError ? (index$1.h("span", { class: "fk-field__error" }, this.uploadError)) : null));
2725
- }
2726
- };
2727
- FkFileInput.style = fkFileInputCss();
2728
-
2729
- const fkFormBuilderCss = () => `.sc-fk-form-builder-h{display:block;container-type:inline-size}.fk-builder.sc-fk-form-builder{display:flex;gap:calc(var(--fk-spacing) * 2);align-items:flex-start;font-family:var(--fk-font);color:var(--fk-color-text)}@container (max-width: 820px){.fk-builder{flex-wrap:wrap}.fk-builder__palette,.fk-builder__inspector{width:100%}.fk-builder__main{order:2;flex-basis:100%}.fk-builder__palette{order:1}.fk-builder__inspector{order:3}}.fk-builder__palette.sc-fk-form-builder{width:220px;flex-shrink:0;padding:calc(var(--fk-spacing) * 1.5);border:1px solid var(--fk-color-border);border-radius:var(--fk-radius);background:var(--fk-color-surface)}.fk-builder__main.sc-fk-form-builder{flex:1;min-width:0;display:flex;flex-direction:column;gap:var(--fk-spacing)}.fk-builder__toolbar.sc-fk-form-builder{display:flex;align-items:center;gap:calc(var(--fk-spacing) / 2)}.fk-builder__spacer.sc-fk-form-builder{flex:1}.fk-builder__import-error.sc-fk-form-builder{font-size:0.75rem;color:var(--fk-color-danger)}.fk-builder__tool.sc-fk-form-builder{padding:calc(var(--fk-spacing) / 2) var(--fk-spacing);border:1px solid var(--fk-color-border);border-radius:calc(var(--fk-radius) / 2);background:var(--fk-color-surface);color:var(--fk-color-text);font-size:0.8rem;cursor:pointer}.fk-builder__tool.sc-fk-form-builder:hover:not(:disabled){border-color:var(--fk-color-primary);color:var(--fk-color-primary)}.fk-builder__tool.sc-fk-form-builder:disabled{opacity:0.4;cursor:default}.fk-builder__canvas.sc-fk-form-builder{min-height:320px;padding:calc(var(--fk-spacing) * 2);border:1px solid var(--fk-color-border);border-radius:var(--fk-radius);background:var(--fk-color-surface);overflow-x:auto}.fk-builder__inspector.sc-fk-form-builder{width:260px;flex-shrink:0;padding:calc(var(--fk-spacing) * 1.5);border:1px solid var(--fk-color-border);border-radius:var(--fk-radius);background:var(--fk-color-surface)}.fk-builder__hint.sc-fk-form-builder{margin:0;font-size:0.8rem;color:var(--fk-color-muted)}`;
2730
-
2731
- const FkFormBuilder = class {
2732
- constructor(hostRef) {
2733
- index$1.registerInstance(this, hostRef);
2734
- this.specChange = index$1.createEvent(this, "specChange");
2735
- this.locales = [];
2736
- this.currentData = {};
2737
- this.copied = false;
2738
- this.history = new index.SpecHistory();
2739
- this.importFromClipboard = async () => {
2740
- try {
2741
- const text = await navigator.clipboard.readText();
2742
- this.importSpec(text, false);
2743
- }
2744
- catch (_a) {
2745
- this.flashImportError(index.fkT('builder.pasteHint'));
2746
- }
2747
- };
2748
- this.copySpec = async () => {
2749
- if (!this.currentSpec)
2750
- return;
2751
- await navigator.clipboard.writeText(this.specJson());
2752
- this.copied = true;
2753
- setTimeout(() => (this.copied = false), 1500);
2754
- };
2755
- this.downloadSpec = () => {
2756
- if (!this.currentSpec)
2757
- return;
2758
- const blob = new Blob([this.specJson()], { type: 'application/json' });
2759
- const url = URL.createObjectURL(blob);
2760
- const link = document.createElement('a');
2761
- link.href = url;
2762
- link.download = 'form-spec.json';
2763
- link.click();
2764
- URL.revokeObjectURL(url);
2765
- };
2766
- this.undo = () => {
2767
- if (!this.currentSpec)
2768
- return;
2769
- const spec = this.history.undo(this.currentSpec);
2770
- if (spec === undefined)
2771
- return;
2772
- this.currentSpec = spec;
2773
- this.specChange.emit({ spec, patches: [], inverse: [] });
2774
- };
2775
- this.redo = () => {
2776
- if (!this.currentSpec)
2777
- return;
2778
- const spec = this.history.redo(this.currentSpec);
2779
- if (spec === undefined)
2780
- return;
2781
- this.currentSpec = spec;
2782
- this.specChange.emit({ spec, patches: [], inverse: [] });
2783
- };
2784
- }
2785
- componentWillLoad() {
2786
- if (index.getBrickMolds().length === 0)
2787
- index.registerDefaultBricks();
2788
- this.editLocale = this.locales[0];
2789
- this.currentSpec = this.spec;
2790
- this.currentData = Object.assign({}, this.data);
2791
- }
2792
- syncSpec(next) {
2793
- this.currentSpec = next;
2794
- this.history.clear();
2795
- }
2796
- handleBrickDrop(event) {
2797
- var _a, _b;
2798
- event.stopPropagation();
2799
- const { source, mold, from, parentPath, index: index$1 } = event.detail;
2800
- if (source === 'new' && mold) {
2801
- const brickSpec = index.newBrickSpec(mold.type, mold.id);
2802
- if (!brickSpec)
2803
- return;
2804
- if (!this.currentSpec) {
2805
- this.setRootSpec(brickSpec.type === 'panel'
2806
- ? brickSpec
2807
- : this.wrapInRootGroup(brickSpec));
2808
- return;
2809
- }
2810
- this.applyUpdate(index.addBrick(this.currentSpec, brickSpec, parentPath, index$1));
2811
- return;
2812
- }
2813
- if (source === 'move' && from && this.currentSpec) {
2814
- if (parentPath === from || parentPath.startsWith(`${from}.`))
2815
- return;
2816
- const parent = index.getBrickAt(this.currentSpec, parentPath);
2817
- if (!parent)
2818
- return;
2819
- const count = (_b = (_a = parent.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
2820
- const fromSegments = from.split('.');
2821
- const fromParent = fromSegments.slice(0, -1).join('.');
2822
- const fromIndex = Number(fromSegments[fromSegments.length - 1]);
2823
- const targetIndex = index$1 !== null && index$1 !== void 0 ? index$1 : count;
2824
- if (fromParent === parentPath &&
2825
- (targetIndex === fromIndex || targetIndex === fromIndex + 1)) {
2826
- return;
2827
- }
2828
- this.applyUpdate(index.moveBrick(this.currentSpec, from, `${parentPath}.${targetIndex}`));
2829
- }
2830
- }
2831
- handleBrickRemove(event) {
2832
- event.stopPropagation();
2833
- if (!this.currentSpec)
2834
- return;
2835
- if (event.detail.path === '0') {
2836
- this.setRootSpec(undefined);
2837
- return;
2838
- }
2839
- this.applyUpdate(index.removeBrick(this.currentSpec, event.detail.path));
2840
- }
2841
- handleBrickDuplicate(event) {
2842
- event.stopPropagation();
2843
- if (!this.currentSpec)
2844
- return;
2845
- this.applyUpdate(index.duplicateBrick(this.currentSpec, event.detail.path));
2846
- }
2847
- handleConfigsChange(event) {
2848
- event.stopPropagation();
2849
- if (!this.currentSpec || !event.detail.uid)
2850
- return;
2851
- this.applyUpdate(index.updateBrickConfigs(this.currentSpec, event.detail.uid, event.detail.configs));
2852
- }
2853
- handleStylesChange(event) {
2854
- event.stopPropagation();
2855
- if (!this.currentSpec || !event.detail.uid)
2856
- return;
2857
- this.applyUpdate(index.updateBrickStyles(this.currentSpec, event.detail.uid, event.detail.styles));
2858
- }
2859
- handleValidationsChange(event) {
2860
- event.stopPropagation();
2861
- if (!this.currentSpec || !event.detail.uid)
2862
- return;
2863
- this.applyUpdate(index.updateBrickValidations(this.currentSpec, event.detail.uid, event.detail.validations));
2864
- }
2865
- handleRulesChange(event) {
2866
- event.stopPropagation();
2867
- if (!this.currentSpec || !event.detail.uid)
2868
- return;
2869
- this.applyUpdate(index.updateBrickRules(this.currentSpec, event.detail.uid, event.detail.rules));
2870
- }
2871
- handleDataChange(event) {
2872
- this.currentData = event.detail.data;
2873
- }
2874
- handlePaste(event) {
2875
- var _a;
2876
- const target = event.target;
2877
- if (target === null || target === void 0 ? void 0 : target.closest('input, textarea, select, [contenteditable]'))
2878
- return;
2879
- this.importSpec((_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text/plain'), true);
2880
- }
2881
- importSpec(text, silent) {
2882
- if (!text) {
2883
- if (!silent)
2884
- this.flashImportError(index.fkT('builder.importInvalid'));
2885
- return;
2886
- }
2887
- try {
2888
- const parsed = JSON.parse(text);
2889
- if (typeof parsed !== 'object' ||
2890
- parsed === null ||
2891
- typeof parsed.type !== 'string' ||
2892
- typeof parsed.id !== 'string') {
2893
- throw new Error('not a brick spec');
2894
- }
2895
- this.selectedUid = undefined;
2896
- this.importError = undefined;
2897
- this.setRootSpec(this.ensureUids(parsed));
2898
- }
2899
- catch (_a) {
2900
- if (!silent)
2901
- this.flashImportError(index.fkT('builder.importInvalid'));
2902
- }
2903
- }
2904
- ensureUids(spec) {
2905
- var _a;
2906
- const clone = structuredClone(spec);
2907
- for (const { brick } of index.iterateBricks(clone)) {
2908
- if (!((_a = brick.configs) === null || _a === void 0 ? void 0 : _a.uid)) {
2909
- brick.configs = Object.assign(Object.assign({}, brick.configs), { uid: crypto.randomUUID() });
2910
- }
2911
- }
2912
- return clone;
2913
- }
2914
- flashImportError(message) {
2915
- this.importError = message;
2916
- setTimeout(() => (this.importError = undefined), 4000);
2917
- }
2918
- handleBrickSelect(event) {
2919
- var _a, _b;
2920
- event.stopPropagation();
2921
- if (!this.currentSpec)
2922
- return;
2923
- this.selectedUid = (_b = (_a = index.getBrickAt(this.currentSpec, event.detail.path)) === null || _a === void 0 ? void 0 : _a.configs) === null || _b === void 0 ? void 0 : _b.uid;
2924
- }
2925
- findSelected() {
2926
- var _a;
2927
- if (!this.currentSpec || !this.selectedUid)
2928
- return undefined;
2929
- for (const { brick, path } of index.iterateBricks(this.currentSpec)) {
2930
- if (((_a = brick.configs) === null || _a === void 0 ? void 0 : _a.uid) === this.selectedUid)
2931
- return { brick, path };
2932
- }
2933
- return undefined;
2934
- }
2935
- inputFieldKeys() {
2936
- var _a;
2937
- const keys = [];
2938
- for (const { brick } of index.iterateBricks(this.currentSpec)) {
2939
- const key = (_a = brick.configs) === null || _a === void 0 ? void 0 : _a.key;
2940
- if (brick.type === 'input' && key)
2941
- keys.push(key);
2942
- }
2943
- return keys;
2944
- }
2945
- wrapInRootGroup(brickSpec) {
2946
- const root = index.newBrickSpec('panel', 'column');
2947
- if (!root)
2948
- return brickSpec;
2949
- return Object.assign(Object.assign({}, root), { name: 'Form', children: [brickSpec] });
2950
- }
2951
- setRootSpec(spec) {
2952
- this.currentSpec = spec;
2953
- this.history.clear();
2954
- this.specChange.emit({ spec, patches: [], inverse: [] });
2955
- }
2956
- applyUpdate(update) {
2957
- this.history.record(update);
2958
- this.currentSpec = update.spec;
2959
- this.specChange.emit({
2960
- spec: update.spec,
2961
- patches: update.patches,
2962
- inverse: update.inverse,
2963
- });
2964
- }
2965
- specJson() {
2966
- return JSON.stringify(this.currentSpec, null, 2);
2967
- }
2968
- render() {
2969
- return (index$1.h("div", { key: 'f23b549325059ff00dc9b4dcce05f82e7905f646', class: "fk-builder" }, index$1.h("aside", { key: '76d630af39352b324fa1160945953bcc92f7e678', class: "fk-builder__palette" }, index$1.h("fk-brick-list", { key: 'a2fbf6fb78febd993e1972a3077e07cd952501f9' })), index$1.h("main", { key: 'e65836c299ef0b102bf99da9263823cb8506aa87', class: "fk-builder__main" }, index$1.h("div", { key: 'cf6681fdc4f36720919f3e52852eeaf247b4cd3f', class: "fk-builder__toolbar" }, index$1.h("button", { key: '8669e0c0bff778cee7b5a0f8dc85d762cd923309', type: "button", class: "fk-builder__tool", disabled: !this.history.canUndo, onClick: this.undo }, "\u21A9 ", index.fkT('builder.undo')), index$1.h("button", { key: 'e8f1b9e73a97ce7fc134628ec9dd80c43ef27f16', type: "button", class: "fk-builder__tool", disabled: !this.history.canRedo, onClick: this.redo }, "\u21AA ", index.fkT('builder.redo')), index$1.h("span", { key: 'e0af911cdb8686c8276ef3b48f75cf65b3f300ea', class: "fk-builder__spacer" }), this.locales.length > 1 ? (index$1.h("select", { class: "fk-builder__tool", onChange: (event) => (this.editLocale = event.target.value) }, this.locales.map((locale) => (index$1.h("option", { value: locale, selected: locale === this.editLocale }, locale.toUpperCase()))))) : null, this.importError ? (index$1.h("span", { class: "fk-builder__import-error" }, this.importError)) : null, index$1.h("button", { key: '5eb508486721587353400365ca3826bed2037620', type: "button", class: "fk-builder__tool", onClick: this.importFromClipboard }, "\u2913 ", index.fkT('builder.importJson')), index$1.h("button", { key: '4e60dd9edeef51da8871c34ea042cb828c6a547b', type: "button", class: "fk-builder__tool", disabled: !this.currentSpec, onClick: this.copySpec }, "\u29C9 ", this.copied ? index.fkT('builder.copied') : index.fkT('builder.copyJson')), index$1.h("button", { key: '40fc0afc683894136b6be5f73fd7f9803e0cc34c', type: "button", class: "fk-builder__tool", disabled: !this.currentSpec, onClick: this.downloadSpec }, "\u2B07 ", index.fkT('builder.downloadJson'))), index$1.h("div", { key: '317a25b31e4fa22204b923457a507f94bcbe5fbe', class: "fk-builder__canvas" }, this.currentSpec ? (index$1.h("fk-form-render", { spec: this.currentSpec, data: this.currentData, editable: true, selectedUid: this.selectedUid, locale: this.editLocale })) : ([index$1.h("fk-empty-form", null), index$1.h("fk-drop-area", { path: "0" })]))), index$1.h("aside", { key: '7d6491acc432ed158eec6727db75f152fa8398d4', class: "fk-builder__inspector" }, (() => {
2970
- const selected = this.findSelected();
2971
- return selected ? (index$1.h("fk-property-panel", { brick: selected.brick, fields: this.inputFieldKeys(), locales: this.locales, editLocale: this.editLocale })) : (index$1.h("p", { class: "fk-builder__hint" }, index.fkT('builder.hint')));
2972
- })())));
2973
- }
2974
- static get watchers() { return {
2975
- "spec": [{
2976
- "syncSpec": 0
2977
- }]
2978
- }; }
2979
- };
2980
- FkFormBuilder.style = fkFormBuilderCss();
2981
-
2982
- const fkFormRenderCss = () => `.fk-form.sc-fk-form-render{display:flex;flex-direction:column;gap:var(--fk-spacing);font-family:var(--fk-font);color:var(--fk-color-text)}`;
2983
-
2984
- const FkFormRender = class {
2985
- constructor(hostRef) {
2986
- index$1.registerInstance(this, hostRef);
2987
- this.formDataChange = index$1.createEvent(this, "formDataChange");
2988
- this.formSubmit = index$1.createEvent(this, "formSubmit");
2989
- this.editable = false;
2990
- this.currentData = {};
2991
- this.touched = {};
2992
- this.utils = {
2993
- validateForm: () => ({
2994
- isValid: this.runValidation().valid,
2995
- }),
2996
- };
2997
- }
2998
- componentWillLoad() {
2999
- this.currentData = Object.assign({}, this.data);
3000
- }
3001
- syncData(next) {
3002
- this.currentData = Object.assign({}, next);
3003
- }
3004
- publicData() {
3005
- return Object.fromEntries(Object.entries(this.currentData).filter(([key]) => !key.startsWith('_')));
3006
- }
3007
- handleBrickDataChange(event) {
3008
- event.stopPropagation();
3009
- this.currentData = this.applyValueEffects(Object.assign(Object.assign({}, this.currentData), event.detail));
3010
- const touched = Object.assign({}, this.touched);
3011
- for (const key of Object.keys(event.detail))
3012
- touched[key] = true;
3013
- this.touched = touched;
3014
- const { valid, errors } = this.runValidation();
3015
- this.formDataChange.emit({
3016
- data: this.publicData(),
3017
- isValid: valid,
3018
- errors,
3019
- });
3020
- }
3021
- applyValueEffects(data) {
3022
- var _a, _b;
3023
- let result = data;
3024
- for (const { brick } of index.iterateBricks(this.spec)) {
3025
- const key = (_a = brick.configs) === null || _a === void 0 ? void 0 : _a.key;
3026
- if (!key || !((_b = brick.rules) === null || _b === void 0 ? void 0 : _b.length))
3027
- continue;
3028
- const affected = index.getAffectedProperties(brick.rules, result);
3029
- if (affected.value !== undefined && result[key] !== affected.value) {
3030
- result = Object.assign(Object.assign({}, result), { [key]: affected.value });
3031
- }
3032
- }
3033
- return result;
3034
- }
3035
- async validate() {
3036
- var _a;
3037
- const touched = {};
3038
- for (const { brick } of index.iterateBricks(this.spec)) {
3039
- const key = (_a = brick.configs) === null || _a === void 0 ? void 0 : _a.key;
3040
- if (key)
3041
- touched[key] = true;
3042
- }
3043
- this.touched = touched;
3044
- const flat = this.runValidation();
3045
- const errors = Object.assign({}, flat.errors);
3046
- let valid = flat.valid;
3047
- const grids = Array.from(this.host.querySelectorAll('fk-data-grid'));
3048
- for (const grid of grids) {
3049
- const rowResult = await grid.validateRows();
3050
- valid = valid && rowResult.valid;
3051
- Object.assign(errors, rowResult.errors);
3052
- }
3053
- const result = { valid, errors };
3054
- this.formDataChange.emit({
3055
- data: this.publicData(),
3056
- isValid: result.valid,
3057
- errors: result.errors,
3058
- });
3059
- return result;
3060
- }
3061
- handleStepTouch(event) {
3062
- event.stopPropagation();
3063
- const touched = Object.assign({}, this.touched);
3064
- for (const key of event.detail.keys)
3065
- touched[key] = true;
3066
- this.touched = touched;
3067
- }
3068
- async handleStepperSubmit(event) {
3069
- event.stopPropagation();
3070
- const result = await this.validate();
3071
- this.formSubmit.emit({
3072
- data: this.publicData(),
3073
- isValid: result.valid,
3074
- errors: result.errors,
3075
- });
3076
- }
3077
- runValidation() {
3078
- const presentData = Object.fromEntries(Object.entries(this.currentData).filter(([, value]) => value !== '' && value !== null && value !== undefined));
3079
- return index.validateBrickSpecDataDetailed(this.spec, presentData, this.locale);
3080
- }
3081
- visibleErrors() {
3082
- if (this.editable)
3083
- return {};
3084
- const errors = {};
3085
- for (const [key, message] of Object.entries(this.runValidation().errors)) {
3086
- if (this.touched[key])
3087
- errors[key] = message;
3088
- }
3089
- return errors;
3090
- }
3091
- render() {
3092
- if (!this.spec)
3093
- return null;
3094
- return (index$1.h("form", { class: "fk-form", onSubmit: (event) => event.preventDefault() }, index$1.h("fk-brick-render", { brickSpec: this.spec, rootSpec: this.spec, data: this.currentData, dataMap: this.currentData, errors: this.visibleErrors(), locale: this.locale, path: "0", editable: this.editable, selectedUid: this.selectedUid, utils: this.utils })));
3095
- }
3096
- get host() { return index$1.getElement(this); }
3097
- static get watchers() { return {
3098
- "data": [{
3099
- "syncData": 0
3100
- }]
3101
- }; }
3102
- };
3103
- FkFormRender.style = fkFormRenderCss();
3104
-
3105
- const fkPropertyPanelCss = () => `.sc-fk-property-panel-h{display:block}.fk-props.sc-fk-property-panel{display:flex;flex-direction:column;gap:calc(var(--fk-spacing) * 1.5)}.fk-props__header.sc-fk-property-panel{display:flex;flex-direction:column;gap:2px}.fk-props__type.sc-fk-property-panel{font-size:0.65rem;font-weight:700;text-transform:uppercase;letter-spacing:0.08em;color:var(--fk-color-primary)}.fk-props__title.sc-fk-property-panel{margin:0;font-size:0.95rem;color:var(--fk-color-text)}.fk-props__section.sc-fk-property-panel{display:flex;flex-direction:column;gap:var(--fk-spacing);padding-top:var(--fk-spacing)}.fk-props__tabs.sc-fk-property-panel{display:flex;gap:2px;border-bottom:1px solid var(--fk-color-border)}.fk-props__tab.sc-fk-property-panel{font:inherit;font-size:0.72rem;font-weight:600;padding:5px 9px;border:none;border-bottom:2px solid transparent;background:transparent;color:var(--fk-color-muted);cursor:pointer}.fk-props__tab.sc-fk-property-panel:hover{color:var(--fk-color-text)}.fk-props__tab--active.sc-fk-property-panel{color:var(--fk-color-primary);border-bottom-color:var(--fk-color-primary)}.fk-props__section-title.sc-fk-property-panel{margin:0;font-size:0.7rem;font-weight:700;text-transform:uppercase;letter-spacing:0.08em;color:var(--fk-color-muted)}.fk-props__field.sc-fk-property-panel{display:flex;flex-direction:column;gap:4px}.fk-props__field--inline.sc-fk-property-panel{flex-direction:row;align-items:center;gap:8px}.fk-props__label.sc-fk-property-panel{font-size:0.75rem;font-weight:600;color:var(--fk-color-muted)}.fk-props__input.sc-fk-property-panel{font:inherit;font-size:0.85rem;padding:6px 8px;border:1px solid var(--fk-color-border);border-radius:calc(var(--fk-radius) / 2);background:var(--fk-color-surface);color:var(--fk-color-text)}.fk-props__input.sc-fk-property-panel:focus{outline:none;border-color:var(--fk-color-primary);box-shadow:0 0 0 2px color-mix(in srgb, var(--fk-color-primary) 20%, transparent)}.fk-props__input--textarea.sc-fk-property-panel{min-height:72px;resize:vertical}.fk-props__vrule.sc-fk-property-panel{display:flex;flex-direction:column;gap:6px;padding:calc(var(--fk-spacing) / 1.5);border:1px solid var(--fk-color-border);border-radius:calc(var(--fk-radius) / 1.5)}.fk-props__style-row.sc-fk-property-panel{display:flex;align-items:center;gap:6px}.fk-props__style-key.sc-fk-property-panel{font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-size:0.75rem;color:var(--fk-color-text);min-width:72px}.fk-props__input--grow.sc-fk-property-panel{flex:1;min-width:0}.fk-props__remove.sc-fk-property-panel{border:none;background:transparent;color:var(--fk-color-muted);font-size:0.75rem;cursor:pointer;padding:2px 4px;border-radius:calc(var(--fk-radius) / 2)}.fk-props__remove.sc-fk-property-panel:hover{color:var(--fk-color-danger);background:color-mix(in srgb, var(--fk-color-danger) 10%, transparent)}`;
3106
-
3107
- const FkPropertyPanel = class {
3108
- constructor(hostRef) {
3109
- index$1.registerInstance(this, hostRef);
3110
- this.brickConfigsChange = index$1.createEvent(this, "brickConfigsChange");
3111
- this.brickValidationsChange = index$1.createEvent(this, "brickValidationsChange");
3112
- this.brickStylesChange = index$1.createEvent(this, "brickStylesChange");
3113
- this.fields = [];
3114
- this.locales = [];
3115
- this.activeTab = 'config';
3116
- this.newStyleKey = '';
3117
- }
3118
- onBrickChange() {
3119
- if (!this.availableTabs().some((tab) => tab.id === this.activeTab)) {
3120
- this.activeTab = 'config';
3121
- }
3122
- }
3123
- availableTabs() {
3124
- const tabs = [
3125
- { id: 'config', label: index.fkT('panel.tab.config') },
3126
- ];
3127
- if (this.brick.type === 'input') {
3128
- tabs.push({ id: 'validation', label: index.fkT('panel.tab.validation') });
3129
- }
3130
- tabs.push({ id: 'styles', label: index.fkT('panel.tab.styles') }, { id: 'rules', label: index.fkT('panel.tab.rules') });
3131
- return tabs;
3132
- }
3133
- localized(current, value) {
3134
- var _a;
3135
- if (this.locales.length <= 1)
3136
- return value || undefined;
3137
- const map = index.isLocalizedObject(current)
3138
- ? Object.assign({}, current) : {};
3139
- if (typeof current === 'string' && current && !index.isLocalizedObject(current)) {
3140
- map[this.locales[0]] = current;
3141
- }
3142
- map[(_a = this.editLocale) !== null && _a !== void 0 ? _a : this.locales[0]] = value;
3143
- return map;
3144
- }
3145
- readLocalized(current) {
3146
- var _a, _b, _c;
3147
- if (index.isLocalizedObject(current)) {
3148
- return (_b = current[(_a = this.editLocale) !== null && _a !== void 0 ? _a : this.locales[0]]) !== null && _b !== void 0 ? _b : '';
3149
- }
3150
- return (_c = current) !== null && _c !== void 0 ? _c : '';
3151
- }
3152
- writeTextConfig(key, value) {
3153
- var _a;
3154
- this.emitConfigs({ [key]: this.localized((_a = this.brick.configs) === null || _a === void 0 ? void 0 : _a[key], value) });
3155
- }
3156
- emitConfigs(patch) {
3157
- var _a;
3158
- const uid = (_a = this.brick.configs) === null || _a === void 0 ? void 0 : _a.uid;
3159
- if (!uid)
3160
- return;
3161
- this.brickConfigsChange.emit({ configs: patch, uid });
3162
- }
3163
- emitValidations(validations) {
3164
- var _a;
3165
- const uid = (_a = this.brick.configs) === null || _a === void 0 ? void 0 : _a.uid;
3166
- if (!uid)
3167
- return;
3168
- this.brickValidationsChange.emit({ validations, uid });
3169
- }
3170
- emitStyles(patch) {
3171
- var _a;
3172
- const uid = (_a = this.brick.configs) === null || _a === void 0 ? void 0 : _a.uid;
3173
- if (!uid)
3174
- return;
3175
- this.brickStylesChange.emit({ styles: patch, uid });
3176
- }
3177
- validationOf(validator) {
3178
- var _a;
3179
- return (_a = this.brick.validations) === null || _a === void 0 ? void 0 : _a.find((validation) => validation.validator === validator);
3180
- }
3181
- setValidation(validator, active, patch = {}) {
3182
- var _a;
3183
- const current = this.validationOf(validator);
3184
- const others = ((_a = this.brick.validations) !== null && _a !== void 0 ? _a : []).filter((validation) => validation.validator !== validator);
3185
- this.emitValidations(active ? [...others, Object.assign(Object.assign(Object.assign({}, current), { validator }), patch)] : others);
3186
- }
3187
- addStyle(value) {
3188
- const key = this.newStyleKey.trim();
3189
- if (!key)
3190
- return;
3191
- this.emitStyles({ [key]: value });
3192
- this.newStyleKey = '';
3193
- }
3194
- textField(label, value, onCommit) {
3195
- var _a;
3196
- return (index$1.h("label", { class: "fk-props__field" }, index$1.h("span", { class: "fk-props__label" }, label), index$1.h("input", { class: "fk-props__input", type: "text", value: (_a = value) !== null && _a !== void 0 ? _a : '', onChange: (event) => onCommit(event.target.value) })));
3197
- }
3198
- optionsFields() {
3199
- var _a, _b, _c;
3200
- const configs = this.brick.configs;
3201
- if (!configs || !('options' in configs || 'optionsSource' in configs)) {
3202
- return [];
3203
- }
3204
- const supportsSources = 'optionsSource' in configs;
3205
- const source = supportsSources
3206
- ? ((_a = configs.optionsSource) !== null && _a !== void 0 ? _a : 'static')
3207
- : 'static';
3208
- const nodes = supportsSources
3209
- ? [
3210
- index$1.h("label", { class: "fk-props__field" }, index$1.h("span", { class: "fk-props__label" }, index.fkT('panel.optionsSource')), index$1.h("select", { class: "fk-props__input", onChange: (event) => this.emitConfigs({
3211
- optionsSource: event.target.value,
3212
- }) }, ['static', 'dataMap', 'remote', 'js'].map((candidate) => (index$1.h("option", { value: candidate, selected: candidate === source }, candidate))))),
3213
- ]
3214
- : [];
3215
- if (source === 'static') {
3216
- nodes.push(index$1.h("label", { class: "fk-props__field" }, index$1.h("span", { class: "fk-props__label" }, index.fkT('panel.options')), index$1.h("textarea", { class: "fk-props__input fk-props__input--textarea", onChange: (event) => this.writeTextConfig('options', event.target.value) }, this.readLocalized(configs.options))));
3217
- }
3218
- if (source === 'dataMap') {
3219
- nodes.push(this.textField(index.fkT('panel.dataKey'), configs.optionsPath, (value) => this.emitConfigs({ optionsPath: value })));
3220
- }
3221
- if (source === 'remote') {
3222
- nodes.push(this.textField(index.fkT('panel.url'), configs.optionsUrl, (value) => this.emitConfigs({ optionsUrl: value })), index$1.h("label", { class: "fk-props__field" }, index$1.h("span", { class: "fk-props__label" }, index.fkT('panel.headers')), index$1.h("textarea", { class: "fk-props__input fk-props__input--textarea", placeholder: 'Authorization: Bearer {token}', onChange: (event) => this.emitConfigs({
3223
- optionsHeaders: event.target.value || undefined,
3224
- }) }, (_b = configs.optionsHeaders) !== null && _b !== void 0 ? _b : '')), this.textField(index.fkT('panel.searchParam'), configs.searchParam, (value) => this.emitConfigs({ searchParam: value || undefined })));
3225
- }
3226
- if (source === 'js') {
3227
- nodes.push(index$1.h("label", { class: "fk-props__field" }, index$1.h("span", { class: "fk-props__label" }, "Code"), index$1.h("fk-code-editor", { value: (_c = configs.optionsCode) !== null && _c !== void 0 ? _c : '', placeholder: "return dataMap.country === 'BJ' ? ['Cotonou'] : ['Paris'];", onCodeChange: (event) => this.emitConfigs({ optionsCode: event.detail }) })));
3228
- }
3229
- if (source === 'remote' || source === 'js') {
3230
- nodes.push(this.textField(index.fkT('panel.labelKey'), configs.labelKey, (value) => this.emitConfigs({ labelKey: value })), this.textField(index.fkT('panel.valueKey'), configs.valueKey, (value) => this.emitConfigs({ valueKey: value })));
3231
- }
3232
- return nodes;
3233
- }
3234
- renderConfigTab() {
3235
- const configs = this.brick.configs;
3236
- const isInput = this.brick.type === 'input';
3237
- return (index$1.h("section", { class: "fk-props__section" }, this.textField(index.fkT('panel.key'), configs === null || configs === void 0 ? void 0 : configs.key, (value) => this.emitConfigs({ key: value })), this.textField(index.fkT('panel.label'), this.readLocalized(configs === null || configs === void 0 ? void 0 : configs.label), (value) => this.writeTextConfig('label', value)), isInput
3238
- ? [
3239
- this.textField(index.fkT('panel.placeholder'), this.readLocalized(configs === null || configs === void 0 ? void 0 : configs.placeholder), (value) => this.writeTextConfig('placeholder', value)),
3240
- this.textField(index.fkT('panel.prefix'), configs === null || configs === void 0 ? void 0 : configs.prefix, (value) => this.emitConfigs({ prefix: value || undefined })),
3241
- this.textField(index.fkT('panel.suffix'), configs === null || configs === void 0 ? void 0 : configs.suffix, (value) => this.emitConfigs({ suffix: value || undefined })),
3242
- ]
3243
- : null, configs && 'accept' in configs
3244
- ? this.textField(index.fkTOr('panel.accept', 'Accepted file types'), configs.accept, (value) => this.emitConfigs({ accept: value }))
3245
- : null, configs && 'uploadUrl' in configs
3246
- ? this.textField(index.fkTOr('panel.uploadUrl', 'Upload URL'), configs.uploadUrl, (value) => this.emitConfigs({ uploadUrl: value }))
3247
- : null, this.optionsFields(), Object.entries(configs !== null && configs !== void 0 ? configs : {})
3248
- .filter(([, value]) => typeof value === 'boolean')
3249
- .map(([key, value]) => (index$1.h("label", { class: "fk-props__field fk-props__field--inline", key: key }, index$1.h("input", { type: "checkbox", checked: value === true, onChange: (event) => this.emitConfigs({
3250
- [key]: event.target.checked,
3251
- }) }), index$1.h("span", { class: "fk-props__label" }, index.fkTOr(`panel.cfg.${key}`, key))))), configs && 'content' in configs ? (index$1.h("label", { class: "fk-props__field" }, index$1.h("span", { class: "fk-props__label" }, index.fkT('panel.content')), index$1.h("textarea", { class: "fk-props__input fk-props__input--textarea", onChange: (event) => this.writeTextConfig('content', event.target.value) }, this.readLocalized(configs.content)))) : null));
3252
- }
3253
- validationRow(validator, label, valueType) {
3254
- const rule = this.validationOf(validator);
3255
- return (index$1.h("div", { class: "fk-props__vrule" }, index$1.h("label", { class: "fk-props__field fk-props__field--inline" }, index$1.h("input", { type: "checkbox", checked: !!rule, onChange: (event) => this.setValidation(validator, event.target.checked) }), index$1.h("span", { class: "fk-props__label" }, label)), rule && valueType ? (index$1.h("input", { class: "fk-props__input", type: valueType, placeholder: valueType === 'number' ? 'value' : 'regex', value: rule.value == null ? '' : String(rule.value), onChange: (event) => {
3256
- const raw = event.target.value;
3257
- this.setValidation(validator, true, {
3258
- value: valueType === 'number'
3259
- ? raw === ''
3260
- ? undefined
3261
- : Number(raw)
3262
- : raw || undefined,
3263
- });
3264
- } })) : null, rule
3265
- ? this.textField(index.fkT('panel.errorMessage'), this.readLocalized(rule.message), (value) => this.setValidation(validator, true, {
3266
- message: this.localized(rule.message, value),
3267
- }))
3268
- : null));
3269
- }
3270
- renderValidationTab() {
3271
- var _a;
3272
- const dataType = this.brick.dataType;
3273
- const custom = this.validationOf('custom');
3274
- return (index$1.h("section", { class: "fk-props__section" }, this.validationRow('required', index.fkT('panel.required')), dataType === 'string'
3275
- ? [
3276
- this.validationRow('minLength', index.fkT('panel.minLength'), 'number'),
3277
- this.validationRow('maxLength', index.fkT('panel.maxLength'), 'number'),
3278
- this.validationRow('pattern', index.fkT('panel.pattern'), 'text'),
3279
- this.validationRow('email', index.fkT('panel.emailFormat')),
3280
- this.validationRow('url', index.fkT('panel.urlFormat')),
3281
- ]
3282
- : null, dataType === 'number'
3283
- ? [
3284
- this.validationRow('min', index.fkT('panel.min'), 'number'),
3285
- this.validationRow('max', index.fkT('panel.max'), 'number'),
3286
- ]
3287
- : null, dataType === 'array'
3288
- ? [
3289
- this.validationRow('minItems', index.fkT('panel.minItems'), 'number'),
3290
- this.validationRow('maxItems', index.fkT('panel.maxItems'), 'number'),
3291
- ]
3292
- : null, index$1.h("div", { class: "fk-props__vrule" }, index$1.h("label", { class: "fk-props__field fk-props__field--inline" }, index$1.h("input", { type: "checkbox", checked: !!custom, onChange: (event) => {
3293
- var _a;
3294
- return this.setValidation('custom', event.target.checked, { customValidator: (_a = custom === null || custom === void 0 ? void 0 : custom.customValidator) !== null && _a !== void 0 ? _a : 'return true;' });
3295
- } }), index$1.h("span", { class: "fk-props__label" }, index.fkT('panel.custom'))), custom ? (index$1.h("fk-code-editor", { value: (_a = custom.customValidator) !== null && _a !== void 0 ? _a : '', placeholder: 'return value?.startsWith("BJ-") ? true : "Must start with BJ-";', onCodeChange: (event) => this.setValidation('custom', true, {
3296
- customValidator: event.detail,
3297
- }) })) : null, custom
3298
- ? this.textField(index.fkT('panel.fallbackMessage'), this.readLocalized(custom.message), (value) => this.setValidation('custom', true, {
3299
- message: this.localized(custom.message, value),
3300
- }))
3301
- : null)));
3302
- }
3303
- renderStylesTab() {
3304
- var _a;
3305
- return (index$1.h("section", { class: "fk-props__section" }, Object.entries((_a = this.brick.styles) !== null && _a !== void 0 ? _a : {}).map(([key, value]) => (index$1.h("div", { class: "fk-props__style-row", key: key }, index$1.h("span", { class: "fk-props__style-key" }, key), index$1.h("input", { class: "fk-props__input fk-props__input--grow", type: "text", value: String(value !== null && value !== void 0 ? value : ''), onChange: (event) => this.emitStyles({
3306
- [key]: event.target.value,
3307
- }) }), index$1.h("button", { type: "button", class: "fk-props__remove", title: "Remove style", onClick: () => this.emitStyles({ [key]: undefined }) }, "\u2715")))), index$1.h("div", { class: "fk-props__style-row" }, index$1.h("input", { class: "fk-props__input", type: "text", placeholder: index.fkT('panel.styleProperty'), value: this.newStyleKey, onInput: (event) => (this.newStyleKey = event.target.value) }), index$1.h("input", { class: "fk-props__input fk-props__input--grow", type: "text", placeholder: index.fkT('panel.styleValue'), onChange: (event) => {
3308
- const target = event.target;
3309
- this.addStyle(target.value);
3310
- target.value = '';
3311
- } }))));
3312
- }
3313
- render() {
3314
- return (index$1.h("div", { key: '095fc127131cc509f0fb27ae2853042d3ca97e8f', class: "fk-props" }, index$1.h("header", { key: '5e5c3eb0cc844dbc023336c93e7b347bc87f5501', class: "fk-props__header" }, index$1.h("span", { key: 'f01a54c31c5885741c3671bbcd2bb46ec9deff32', class: "fk-props__type" }, this.brick.type), index$1.h("h4", { key: 'a558c48e018a228084eeac289b98e76495d7e630', class: "fk-props__title" }, index.fkTOr(`brick.${this.brick.id}.name`, this.brick.name))), index$1.h("div", { key: 'c11ee0bf0f17754abc00b561fef398bf9cdd9416', class: "fk-props__tabs" }, this.availableTabs().map((tab) => (index$1.h("button", { key: tab.id, type: "button", class: {
3315
- 'fk-props__tab': true,
3316
- 'fk-props__tab--active': this.activeTab === tab.id,
3317
- }, onClick: () => (this.activeTab = tab.id) }, tab.label)))), this.activeTab === 'config' ? this.renderConfigTab() : null, this.activeTab === 'validation' ? this.renderValidationTab() : null, this.activeTab === 'styles' ? this.renderStylesTab() : null, this.activeTab === 'rules' ? (index$1.h("section", { class: "fk-props__section" }, index$1.h("fk-rules-editor", { brick: this.brick, fields: this.fields }))) : null));
3318
- }
3319
- static get watchers() { return {
3320
- "brick": [{
3321
- "onBrickChange": 0
3322
- }]
3323
- }; }
3324
- };
3325
- FkPropertyPanel.style = fkPropertyPanelCss();
3326
-
3327
- const OPERATORS = [
3328
- { id: 'equals', label: 'equals' },
3329
- { id: 'notEquals', label: 'does not equal' },
3330
- { id: 'greaterThan', label: 'is greater than' },
3331
- { id: 'lessThan', label: 'is less than' },
3332
- { id: 'isEmpty', label: 'is empty' },
3333
- { id: 'isNotEmpty', label: 'is not empty' },
3334
- ];
3335
- function buildLogic(condition) {
3336
- const variable = { var: condition.field };
3337
- switch (condition.operator) {
3338
- case 'equals':
3339
- return { '==': [variable, condition.value] };
3340
- case 'notEquals':
3341
- return { '!=': [variable, condition.value] };
3342
- case 'greaterThan':
3343
- return { '>': [variable, condition.value] };
3344
- case 'lessThan':
3345
- return { '<': [variable, condition.value] };
3346
- case 'isEmpty':
3347
- return { '!': variable };
3348
- case 'isNotEmpty':
3349
- return { '!!': variable };
3350
- }
3351
- }
3352
- const varName = (value) => value !== null &&
3353
- typeof value === 'object' &&
3354
- typeof value.var === 'string'
3355
- ? value.var
3356
- : undefined;
3357
- const BINARY_OPERATORS = {
3358
- '==': 'equals',
3359
- '!=': 'notEquals',
3360
- '>': 'greaterThan',
3361
- '<': 'lessThan',
3362
- };
3363
- function parseLogic(logic) {
3364
- if (!logic || typeof logic !== 'object')
3365
- return undefined;
3366
- const entries = Object.entries(logic);
3367
- if (entries.length !== 1)
3368
- return undefined;
3369
- const [operator, args] = entries[0];
3370
- if (operator === '!' || operator === '!!') {
3371
- const field = varName(Array.isArray(args) ? args[0] : args);
3372
- if (!field)
3373
- return undefined;
3374
- return { field, operator: operator === '!' ? 'isEmpty' : 'isNotEmpty' };
3375
- }
3376
- const mapped = BINARY_OPERATORS[operator];
3377
- if (!mapped || !Array.isArray(args) || args.length !== 2)
3378
- return undefined;
3379
- const field = varName(args[0]);
3380
- if (!field)
3381
- return undefined;
3382
- return { field, operator: mapped, value: args[1] };
3383
- }
3384
- function parseValueInput(raw) {
3385
- if (raw === '')
3386
- return '';
3387
- try {
3388
- return JSON.parse(raw);
3389
- }
3390
- catch (_a) {
3391
- return raw;
3392
- }
3393
- }
3394
- function formatValue(value) {
3395
- if (value === undefined)
3396
- return '';
3397
- return typeof value === 'string' ? value : JSON.stringify(value);
3398
- }
3399
-
3400
- const fkRulesEditorCss = () => `.sc-fk-rules-editor-h{display:block}.fk-rules.sc-fk-rules-editor{display:flex;flex-direction:column;gap:var(--fk-spacing)}.fk-rule.sc-fk-rules-editor{display:flex;flex-direction:column;gap:calc(var(--fk-spacing) / 1.5);padding:var(--fk-spacing);border:1px solid var(--fk-color-border);border-radius:calc(var(--fk-radius) / 1.5);background:color-mix(in srgb, var(--fk-color-surface) 60%, transparent)}.fk-rule__header.sc-fk-rules-editor{display:flex;align-items:center;gap:6px}.fk-rule__name.sc-fk-rules-editor{flex:1;min-width:0;font:inherit;font-size:0.8rem;font-weight:600;padding:4px 6px;border:1px solid transparent;border-radius:calc(var(--fk-radius) / 2);background:transparent;color:var(--fk-color-text)}.fk-rule__name.sc-fk-rules-editor:hover,.fk-rule__name.sc-fk-rules-editor:focus{border-color:var(--fk-color-border);background:var(--fk-color-surface);outline:none}.fk-rule__modes.sc-fk-rules-editor{display:flex;gap:4px}.fk-rule__mode.sc-fk-rules-editor{font:inherit;font-size:0.65rem;font-weight:600;text-transform:uppercase;letter-spacing:0.05em;padding:3px 8px;border:1px solid var(--fk-color-border);border-radius:999px;background:transparent;color:var(--fk-color-muted);cursor:pointer}.fk-rule__mode--active.sc-fk-rules-editor{border-color:var(--fk-color-primary);background:color-mix(in srgb, var(--fk-color-primary) 12%, transparent);color:var(--fk-color-primary)}.fk-rule__condition.sc-fk-rules-editor,.fk-rule__effect.sc-fk-rules-editor{display:flex;flex-wrap:wrap;align-items:center;gap:4px}.fk-rule__keyword.sc-fk-rules-editor{font-size:0.65rem;font-weight:700;text-transform:uppercase;letter-spacing:0.08em;color:var(--fk-color-muted)}.fk-rule__control.sc-fk-rules-editor{font:inherit;font-size:0.78rem;padding:4px 6px;max-width:100%;min-width:0;border:1px solid var(--fk-color-border);border-radius:calc(var(--fk-radius) / 2);background:var(--fk-color-surface);color:var(--fk-color-text)}.fk-rule__control.sc-fk-rules-editor:focus{outline:none;border-color:var(--fk-color-primary)}.fk-rule__advanced.sc-fk-rules-editor{display:flex;flex-direction:column;gap:4px}.fk-rule__code.sc-fk-rules-editor{font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-size:0.75rem;min-height:72px;padding:6px 8px;border:1px solid var(--fk-color-border);border-radius:calc(var(--fk-radius) / 2);background:var(--fk-color-surface);color:var(--fk-color-text);resize:vertical}.fk-rule__error.sc-fk-rules-editor{margin:0;font-size:0.72rem;color:var(--fk-color-danger)}.fk-rule__effects.sc-fk-rules-editor{display:flex;flex-direction:column;gap:6px}.fk-rule__remove.sc-fk-rules-editor{border:none;background:transparent;color:var(--fk-color-muted);font-size:0.75rem;cursor:pointer;padding:2px 4px;border-radius:calc(var(--fk-radius) / 2)}.fk-rule__remove.sc-fk-rules-editor:hover{color:var(--fk-color-danger);background:color-mix(in srgb, var(--fk-color-danger) 10%, transparent)}.fk-rule__add.sc-fk-rules-editor{align-self:flex-start;font:inherit;font-size:0.75rem;font-weight:600;padding:4px 10px;border:1px dashed var(--fk-color-border);border-radius:calc(var(--fk-radius) / 2);background:transparent;color:var(--fk-color-muted);cursor:pointer}.fk-rule__add.sc-fk-rules-editor:hover{border-color:var(--fk-color-primary);color:var(--fk-color-primary)}`;
3401
-
3402
- const EFFECT_TARGETS = ['hidden', 'disabled', 'required', 'value'];
3403
- const FkRulesEditor = class {
3404
- constructor(hostRef) {
3405
- index$1.registerInstance(this, hostRef);
3406
- this.brickRulesChange = index$1.createEvent(this, "brickRulesChange");
3407
- this.fields = [];
3408
- this.forcedModes = {};
3409
- this.jsonErrors = {};
3410
- this.codeErrors = {};
3411
- this.addRule = () => {
3412
- var _a;
3413
- this.commit([
3414
- ...this.rules(),
3415
- {
3416
- name: `Rule ${this.rules().length + 1}`,
3417
- type: 'jsonLogic',
3418
- logic: buildLogic({
3419
- field: (_a = this.fields[0]) !== null && _a !== void 0 ? _a : '',
3420
- operator: 'equals',
3421
- value: '',
3422
- }),
3423
- effects: [{ property: { target: 'hidden', type: 'boolean' }, boolean: true }],
3424
- },
3425
- ]);
3426
- };
3427
- }
3428
- rules() {
3429
- var _a;
3430
- return (_a = this.brick.rules) !== null && _a !== void 0 ? _a : [];
3431
- }
3432
- commit(rules) {
3433
- var _a;
3434
- const uid = (_a = this.brick.configs) === null || _a === void 0 ? void 0 : _a.uid;
3435
- if (!uid)
3436
- return;
3437
- this.brickRulesChange.emit({ rules, uid });
3438
- }
3439
- updateRule(index, patch) {
3440
- this.commit(this.rules().map((rule, i) => (i === index ? Object.assign(Object.assign({}, rule), patch) : rule)));
3441
- }
3442
- removeRule(index) {
3443
- this.commit(this.rules().filter((_, i) => i !== index));
3444
- this.forcedModes = Object.assign(Object.assign({}, this.forcedModes), { [index]: undefined });
3445
- }
3446
- modeOf(index, rule) {
3447
- if (rule.type === 'javaScript')
3448
- return 'javaScript';
3449
- if (this.forcedModes[index])
3450
- return this.forcedModes[index];
3451
- return parseLogic(rule.logic) ? 'simple' : 'json';
3452
- }
3453
- setMode(index, rule, mode) {
3454
- var _a, _b, _c;
3455
- this.forcedModes = Object.assign(Object.assign({}, this.forcedModes), { [index]: mode });
3456
- this.jsonErrors = Object.assign(Object.assign({}, this.jsonErrors), { [index]: '' });
3457
- this.codeErrors = Object.assign(Object.assign({}, this.codeErrors), { [index]: '' });
3458
- if (mode === 'javaScript' && rule.type !== 'javaScript') {
3459
- this.updateRule(index, { type: 'javaScript', code: (_a = rule.code) !== null && _a !== void 0 ? _a : 'return true;' });
3460
- return;
3461
- }
3462
- if (mode !== 'javaScript' && rule.type !== 'jsonLogic') {
3463
- this.updateRule(index, {
3464
- type: 'jsonLogic',
3465
- logic: (_b = rule.logic) !== null && _b !== void 0 ? _b : buildLogic({ field: (_c = this.fields[0]) !== null && _c !== void 0 ? _c : '', operator: 'equals', value: '' }),
3466
- });
3467
- }
3468
- }
3469
- updateCondition(index, rule, patch) {
3470
- var _a, _b;
3471
- const current = (_a = parseLogic(rule.logic)) !== null && _a !== void 0 ? _a : {
3472
- field: (_b = this.fields[0]) !== null && _b !== void 0 ? _b : '',
3473
- operator: 'equals',
3474
- value: '',
3475
- };
3476
- this.updateRule(index, {
3477
- logic: buildLogic(Object.assign(Object.assign({}, current), patch)),
3478
- });
3479
- }
3480
- commitJson(index, raw) {
3481
- try {
3482
- const logic = JSON.parse(raw);
3483
- this.jsonErrors = Object.assign(Object.assign({}, this.jsonErrors), { [index]: '' });
3484
- this.updateRule(index, { logic });
3485
- }
3486
- catch (error) {
3487
- this.jsonErrors = Object.assign(Object.assign({}, this.jsonErrors), { [index]: error instanceof Error ? error.message : String(error) });
3488
- }
3489
- }
3490
- commitCode(index$1, code) {
3491
- var _a, _b;
3492
- const validation = index.services.jsRunnerService.validateJs(`(() => {${code}})();`);
3493
- this.codeErrors = Object.assign(Object.assign({}, this.codeErrors), { [index$1]: validation.valide ? '' : ((_b = (_a = validation.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : 'Invalid code') });
3494
- this.updateRule(index$1, { code });
3495
- }
3496
- updateEffect(ruleIndex, effectIndex, effect) {
3497
- var _a;
3498
- const rule = this.rules()[ruleIndex];
3499
- const effects = ((_a = rule.effects) !== null && _a !== void 0 ? _a : []).map((current, i) => i === effectIndex ? effect : current);
3500
- this.updateRule(ruleIndex, { effects });
3501
- }
3502
- addEffect(ruleIndex) {
3503
- var _a;
3504
- const rule = this.rules()[ruleIndex];
3505
- this.updateRule(ruleIndex, {
3506
- effects: [
3507
- ...((_a = rule.effects) !== null && _a !== void 0 ? _a : []),
3508
- { property: { target: 'hidden', type: 'boolean' }, boolean: true },
3509
- ],
3510
- });
3511
- }
3512
- removeEffect(ruleIndex, effectIndex) {
3513
- var _a;
3514
- const rule = this.rules()[ruleIndex];
3515
- this.updateRule(ruleIndex, {
3516
- effects: ((_a = rule.effects) !== null && _a !== void 0 ? _a : []).filter((_, i) => i !== effectIndex),
3517
- });
3518
- }
3519
- renderCondition(index$2, rule) {
3520
- var _a, _b;
3521
- const condition = (_a = parseLogic(rule.logic)) !== null && _a !== void 0 ? _a : {
3522
- field: (_b = this.fields[0]) !== null && _b !== void 0 ? _b : '',
3523
- operator: 'equals',
3524
- value: '',
3525
- };
3526
- const needsValue = condition.operator !== 'isEmpty' && condition.operator !== 'isNotEmpty';
3527
- return (index$1.h("div", { class: "fk-rule__condition" }, index$1.h("span", { class: "fk-rule__keyword" }, index.fkT('rules.when')), index$1.h("select", { class: "fk-rule__control", onChange: (event) => this.updateCondition(index$2, rule, {
3528
- field: event.target.value,
3529
- }) }, this.fields.map((field) => (index$1.h("option", { value: field, selected: field === condition.field }, field)))), index$1.h("select", { class: "fk-rule__control", onChange: (event) => this.updateCondition(index$2, rule, {
3530
- operator: event.target.value,
3531
- }) }, OPERATORS.map((operator) => (index$1.h("option", { value: operator.id, selected: operator.id === condition.operator }, operator.label)))), needsValue ? (index$1.h("input", { class: "fk-rule__control", type: "text", value: formatValue(condition.value), onChange: (event) => this.updateCondition(index$2, rule, {
3532
- value: parseValueInput(event.target.value),
3533
- }) })) : null));
3534
- }
3535
- renderEffect(ruleIndex, effect, effectIndex) {
3536
- var _a, _b, _c, _d, _e;
3537
- const target = (_b = (_a = effect.property) === null || _a === void 0 ? void 0 : _a.target) !== null && _b !== void 0 ? _b : 'hidden';
3538
- const type = (_d = (_c = effect.property) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : 'boolean';
3539
- return (index$1.h("div", { class: "fk-rule__effect" }, index$1.h("select", { class: "fk-rule__control", onChange: (event) => this.updateEffect(ruleIndex, effectIndex, Object.assign(Object.assign({}, effect), { property: {
3540
- target: event.target.value,
3541
- type: type,
3542
- } })) }, EFFECT_TARGETS.map((candidate) => (index$1.h("option", { value: candidate, selected: candidate === target }, candidate)))), index$1.h("select", { class: "fk-rule__control", onChange: (event) => {
3543
- const nextType = event.target.value;
3544
- this.updateEffect(ruleIndex, effectIndex, Object.assign({ property: { target, type: nextType } }, (nextType === 'boolean' ? { boolean: true } : { string: '' })));
3545
- } }, index$1.h("option", { value: "boolean", selected: type === 'boolean' }, "boolean"), index$1.h("option", { value: "string", selected: type === 'string' }, "string")), type === 'boolean' ? (index$1.h("select", { class: "fk-rule__control", onChange: (event) => this.updateEffect(ruleIndex, effectIndex, Object.assign(Object.assign({}, effect), { boolean: event.target.value === 'true' })) }, index$1.h("option", { value: "true", selected: effect.boolean !== false }, "true"), index$1.h("option", { value: "false", selected: effect.boolean === false }, "false"))) : (index$1.h("input", { class: "fk-rule__control", type: "text", value: (_e = effect.string) !== null && _e !== void 0 ? _e : '', onChange: (event) => this.updateEffect(ruleIndex, effectIndex, Object.assign(Object.assign({}, effect), { string: event.target.value })) })), index$1.h("button", { type: "button", class: "fk-rule__remove", title: index.fkT('rules.removeEffect'), onClick: () => this.removeEffect(ruleIndex, effectIndex) }, "\u2715")));
3546
- }
3547
- render() {
3548
- return (index$1.h("div", { key: '24bddb2835ae3148acc15bef38c855e0b5de0bf8', class: "fk-rules" }, this.rules().map((rule, index$2) => {
3549
- var _a, _b, _c;
3550
- const mode = this.modeOf(index$2, rule);
3551
- return (index$1.h("article", { class: "fk-rule" }, index$1.h("header", { class: "fk-rule__header" }, index$1.h("input", { class: "fk-rule__name", type: "text", value: rule.name, onChange: (event) => this.updateRule(index$2, {
3552
- name: event.target.value,
3553
- }) }), index$1.h("button", { type: "button", class: "fk-rule__remove", title: index.fkT('rules.removeRule'), onClick: () => this.removeRule(index$2) }, "\u2715")), index$1.h("div", { class: "fk-rule__modes" }, ['simple', 'json', 'javaScript'].map((candidate) => (index$1.h("button", { type: "button", class: {
3554
- 'fk-rule__mode': true,
3555
- 'fk-rule__mode--active': mode === candidate,
3556
- }, onClick: () => this.setMode(index$2, rule, candidate) }, index.fkT(`rules.mode.${candidate === 'javaScript' ? 'js' : candidate}`))))), mode === 'simple' ? this.renderCondition(index$2, rule) : null, mode === 'json' ? (index$1.h("div", { class: "fk-rule__advanced" }, index$1.h("textarea", { class: "fk-rule__code", onChange: (event) => this.commitJson(index$2, event.target.value) }, JSON.stringify((_a = rule.logic) !== null && _a !== void 0 ? _a : null, null, 2)), this.jsonErrors[index$2] ? (index$1.h("p", { class: "fk-rule__error" }, this.jsonErrors[index$2])) : null)) : null, mode === 'javaScript' ? (index$1.h("div", { class: "fk-rule__advanced" }, index$1.h("fk-code-editor", { value: (_b = rule.code) !== null && _b !== void 0 ? _b : '', placeholder: "return dataMap.country === 'BJ';", onCodeChange: (event) => this.commitCode(index$2, event.detail) }), this.codeErrors[index$2] ? (index$1.h("p", { class: "fk-rule__error" }, this.codeErrors[index$2])) : null)) : null, index$1.h("div", { class: "fk-rule__effects" }, index$1.h("span", { class: "fk-rule__keyword" }, index.fkT('rules.then')), ((_c = rule.effects) !== null && _c !== void 0 ? _c : []).map((effect, effectIndex) => this.renderEffect(index$2, effect, effectIndex)), index$1.h("button", { type: "button", class: "fk-rule__add", onClick: () => this.addEffect(index$2) }, index.fkT('rules.addEffect')))));
3557
- }), index$1.h("button", { key: '55f42fc21a6054d46f53835e0b9638391d12bf6f', type: "button", class: "fk-rule__add", onClick: this.addRule }, index.fkT('rules.addRule'))));
3558
- }
3559
- };
3560
- FkRulesEditor.style = fkRulesEditorCss();
3561
-
3562
- function interpolateTemplate(template, dataMap) {
3563
- return template.replace(/\{(\w+)\}/g, (_, token) => {
3564
- const value = dataMap === null || dataMap === void 0 ? void 0 : dataMap[token];
3565
- return value === undefined || value === null ? '' : String(value);
3566
- });
3567
- }
3568
- function parseHeaderLines(raw, dataMap) {
3569
- if (typeof raw !== 'string' || !raw.trim())
3570
- return undefined;
3571
- const headers = {};
3572
- for (const line of raw.split('\n')) {
3573
- const separator = line.indexOf(':');
3574
- if (separator <= 0)
3575
- continue;
3576
- const name = line.slice(0, separator).trim();
3577
- const value = interpolateTemplate(line.slice(separator + 1).trim(), dataMap);
3578
- if (name)
3579
- headers[name] = value;
3580
- }
3581
- return Object.keys(headers).length ? headers : undefined;
3582
- }
3583
- function appendSearchParam(url, param, term) {
3584
- if (!term)
3585
- return url;
3586
- const separator = url.includes('?') ? '&' : '?';
3587
- return `${url}${separator}${encodeURIComponent(param)}=${encodeURIComponent(term)}`;
3588
- }
3589
-
3590
- const fkSelectInputCss = () => `.sc-fk-select-input-h{display:block}.fk-select.sc-fk-select-input{position:relative;font-family:var(--fk-font)}.fk-select__trigger.sc-fk-select-input{display:flex;align-items:center;gap:calc(var(--fk-spacing) / 2);min-height:38px;padding:calc(var(--fk-spacing) / 2) var(--fk-spacing);border:1px solid var(--fk-color-border);border-radius:var(--fk-radius);background:var(--fk-color-surface);color:var(--fk-color-text);cursor:pointer}.fk-select--disabled.sc-fk-select-input .fk-select__trigger.sc-fk-select-input{cursor:not-allowed;opacity:0.6}.fk-select__trigger--open.sc-fk-select-input{border-color:var(--fk-color-primary)}.fk-select__values.sc-fk-select-input{display:flex;flex:1;flex-wrap:wrap;align-items:center;gap:4px;min-width:0;font-size:0.9rem}.fk-select__placeholder.sc-fk-select-input{color:var(--fk-color-muted)}.fk-select__chip.sc-fk-select-input{display:inline-flex;align-items:center;gap:4px;padding:1px 8px;border-radius:999px;background:color-mix(in srgb, var(--fk-color-primary) 14%, transparent);color:var(--fk-color-primary);font-size:0.8rem;font-weight:600}.fk-select__chip-remove.sc-fk-select-input,.fk-select__clear.sc-fk-select-input{border:none;background:transparent;color:inherit;font-size:0.7rem;cursor:pointer;padding:0 2px}.fk-select__clear.sc-fk-select-input{color:var(--fk-color-muted)}.fk-select__clear.sc-fk-select-input:hover{color:var(--fk-color-danger)}.fk-select__caret.sc-fk-select-input{color:var(--fk-color-muted);font-size:0.8rem}.fk-select__dropdown.sc-fk-select-input{position:absolute;top:calc(100% + 4px);left:0;right:0;z-index:20;display:flex;flex-direction:column;border:1px solid var(--fk-color-border);border-radius:var(--fk-radius);background:var(--fk-color-surface);box-shadow:0 8px 24px var(--fk-color-shadow);overflow:hidden}.fk-select__search.sc-fk-select-input{font:inherit;font-size:0.85rem;padding:calc(var(--fk-spacing) / 1.5) var(--fk-spacing);border:none;border-bottom:1px solid var(--fk-color-border);background:transparent;color:var(--fk-color-text)}.fk-select__search.sc-fk-select-input:focus{outline:none}.fk-select__options.sc-fk-select-input{max-height:220px;overflow-y:auto}.fk-select__option.sc-fk-select-input{display:flex;align-items:center;justify-content:space-between;gap:var(--fk-spacing);padding:calc(var(--fk-spacing) / 1.5) var(--fk-spacing);font-size:0.9rem;color:var(--fk-color-text);cursor:pointer}.fk-select__option.sc-fk-select-input:hover{background:color-mix(in srgb, var(--fk-color-primary) 8%, transparent)}.fk-select__option--selected.sc-fk-select-input{color:var(--fk-color-primary);font-weight:600}.fk-select__check.sc-fk-select-input{font-size:0.8rem}.fk-select__empty.sc-fk-select-input{margin:0;padding:var(--fk-spacing);font-size:0.85rem;color:var(--fk-color-muted)}.fk-select__trigger.sc-fk-select-input:focus-visible{outline:2px solid color-mix(in srgb, var(--fk-color-primary) 55%, transparent);outline-offset:1px}.fk-select__option--active.sc-fk-select-input{background:color-mix(in srgb, var(--fk-color-primary) 12%, transparent)}`;
3591
-
3592
- let selectInstanceCounter = 0;
3593
- const FkSelectInput = class {
3594
- constructor(hostRef) {
3595
- index$1.registerInstance(this, hostRef);
3596
- this.selectValueChange = index$1.createEvent(this, "selectValueChange");
3597
- this.disabled = false;
3598
- this.multiple = false;
3599
- this.invalid = false;
3600
- this.open = false;
3601
- this.query = '';
3602
- this.activeIndex = 0;
3603
- this.instanceId = `fk-select-${++selectInstanceCounter}`;
3604
- this.remoteOptions = [];
3605
- this.outsideClick = (event) => {
3606
- if (!this.host.contains(event.target))
3607
- this.close();
3608
- };
3609
- this.onTriggerKeyDown = (event) => {
3610
- if (this.disabled)
3611
- return;
3612
- if (['Enter', ' ', 'ArrowDown', 'ArrowUp'].includes(event.key)) {
3613
- event.preventDefault();
3614
- this.openDropdown();
3615
- }
3616
- else if (event.key === 'Escape' && this.open) {
3617
- event.preventDefault();
3618
- this.close();
3619
- }
3620
- };
3621
- }
3622
- componentWillLoad() {
3623
- return this.resolveRemote();
3624
- }
3625
- disconnectedCallback() {
3626
- this.unbindOutsideClick();
3627
- }
3628
- onConfigsChange() {
3629
- this.resolveRemote();
3630
- }
3631
- onDataMapChange() {
3632
- this.resolveRemote();
3633
- }
3634
- searchParam() {
3635
- var _a;
3636
- return ((_a = this.configs) === null || _a === void 0 ? void 0 : _a.searchParam) || undefined;
3637
- }
3638
- remoteUrl() {
3639
- var _a;
3640
- const raw = (_a = this.configs) === null || _a === void 0 ? void 0 : _a.optionsUrl;
3641
- if (!raw)
3642
- return undefined;
3643
- let url = interpolateTemplate(raw, this.dataMap);
3644
- const param = this.searchParam();
3645
- if (param)
3646
- url = appendSearchParam(url, param, this.query.trim());
3647
- return url;
3648
- }
3649
- bindOutsideClick() {
3650
- document.addEventListener('mousedown', this.outsideClick);
3651
- }
3652
- unbindOutsideClick() {
3653
- document.removeEventListener('mousedown', this.outsideClick);
3654
- }
3655
- toggleOpen() {
3656
- if (this.disabled)
3657
- return;
3658
- if (this.open)
3659
- this.close();
3660
- else
3661
- this.openDropdown();
3662
- }
3663
- openDropdown() {
3664
- if (this.disabled || this.open)
3665
- return;
3666
- this.open = true;
3667
- this.query = '';
3668
- const { options } = this.resolve();
3669
- const selected = this.selectedValues();
3670
- const selectedIndex = options.findIndex((option) => selected.includes(option.value));
3671
- this.activeIndex = selectedIndex >= 0 ? selectedIndex : 0;
3672
- this.bindOutsideClick();
3673
- }
3674
- close(refocusTrigger = false) {
3675
- var _a;
3676
- this.open = false;
3677
- this.unbindOutsideClick();
3678
- if (refocusTrigger)
3679
- (_a = this.triggerEl) === null || _a === void 0 ? void 0 : _a.focus();
3680
- }
3681
- moveActive(delta, count) {
3682
- if (!count)
3683
- return;
3684
- this.activeIndex = (this.activeIndex + delta + count) % count;
3685
- this.scrollActiveIntoView();
3686
- }
3687
- scrollActiveIntoView() {
3688
- requestAnimationFrame(() => {
3689
- var _a;
3690
- const active = this.host.querySelector(`#${this.instanceId}-opt-${this.activeIndex}`);
3691
- (_a = active === null || active === void 0 ? void 0 : active.scrollIntoView) === null || _a === void 0 ? void 0 : _a.call(active, { block: 'nearest' });
3692
- });
3693
- }
3694
- onSearchKeyDown(event, filtered) {
3695
- var _a;
3696
- switch (event.key) {
3697
- case 'ArrowDown':
3698
- event.preventDefault();
3699
- this.moveActive(1, filtered.length);
3700
- break;
3701
- case 'ArrowUp':
3702
- event.preventDefault();
3703
- this.moveActive(-1, filtered.length);
3704
- break;
3705
- case 'Home':
3706
- event.preventDefault();
3707
- this.activeIndex = 0;
3708
- this.scrollActiveIntoView();
3709
- break;
3710
- case 'End':
3711
- event.preventDefault();
3712
- this.activeIndex = Math.max(filtered.length - 1, 0);
3713
- this.scrollActiveIntoView();
3714
- break;
3715
- case 'Enter': {
3716
- event.preventDefault();
3717
- const option = (_a = filtered[this.activeIndex]) !== null && _a !== void 0 ? _a : filtered[0];
3718
- if (option)
3719
- this.pick(option);
3720
- break;
3721
- }
3722
- case 'Escape':
3723
- event.preventDefault();
3724
- this.close(true);
3725
- break;
3726
- case 'Tab':
3727
- this.close();
3728
- break;
3729
- }
3730
- }
3731
- source() {
3732
- var _a, _b;
3733
- return (_b = (_a = this.configs) === null || _a === void 0 ? void 0 : _a.optionsSource) !== null && _b !== void 0 ? _b : 'static';
3734
- }
3735
- async resolveRemote(force = false) {
3736
- var _a;
3737
- if (this.source() !== 'remote')
3738
- return;
3739
- const url = this.remoteUrl();
3740
- if (!url) {
3741
- this.remoteOptions = [];
3742
- return;
3743
- }
3744
- const headers = parseHeaderLines((_a = this.configs) === null || _a === void 0 ? void 0 : _a.optionsHeaders, this.dataMap);
3745
- const signature = `${url}|${JSON.stringify(headers !== null && headers !== void 0 ? headers : {})}`;
3746
- if (!force && signature === this.lastRemoteSignature)
3747
- return;
3748
- this.lastRemoteSignature = signature;
3749
- try {
3750
- this.remoteError = undefined;
3751
- this.remoteOptions = await index.services.dataSourceService.fetchOptions(url, headers ? { headers } : undefined);
3752
- }
3753
- catch (error) {
3754
- this.remoteOptions = [];
3755
- this.remoteError = error instanceof Error ? error.message : String(error);
3756
- }
3757
- }
3758
- onSearchInput(value) {
3759
- this.query = value;
3760
- if (this.source() !== 'remote' || !this.searchParam())
3761
- return;
3762
- if (this.searchTimer)
3763
- clearTimeout(this.searchTimer);
3764
- this.searchTimer = setTimeout(() => this.resolveRemote(), 250);
3765
- }
3766
- resolve() {
3767
- var _a, _b, _c, _d, _e, _f;
3768
- const labelKey = ((_a = this.configs) === null || _a === void 0 ? void 0 : _a.labelKey) || undefined;
3769
- const valueKey = ((_b = this.configs) === null || _b === void 0 ? void 0 : _b.valueKey) || undefined;
3770
- switch (this.source()) {
3771
- case 'remote':
3772
- return {
3773
- options: index.normalizeOptions(this.remoteOptions, labelKey, valueKey),
3774
- error: this.remoteError,
3775
- };
3776
- case 'dataMap': {
3777
- const path = (_c = this.configs) === null || _c === void 0 ? void 0 : _c.optionsPath;
3778
- return {
3779
- options: index.normalizeOptions(path ? (_d = this.dataMap) === null || _d === void 0 ? void 0 : _d[path] : [], labelKey, valueKey),
3780
- };
3781
- }
3782
- case 'js': {
3783
- const code = (_e = this.configs) === null || _e === void 0 ? void 0 : _e.optionsCode;
3784
- if (!code)
3785
- return { options: [] };
3786
- const result = index.evalBrickCode(code, this.dataMap);
3787
- if (result instanceof Error) {
3788
- return { options: [], error: result.message };
3789
- }
3790
- return { options: index.normalizeOptions(result, labelKey, valueKey) };
3791
- }
3792
- default:
3793
- return {
3794
- options: index.normalizeOptions((_f = this.configs) === null || _f === void 0 ? void 0 : _f.options, labelKey, valueKey),
3795
- };
3796
- }
3797
- }
3798
- selectedValues() {
3799
- if (this.multiple) {
3800
- return Array.isArray(this.value) ? this.value : [];
3801
- }
3802
- return typeof this.value === 'string' && this.value !== '' ? [this.value] : [];
3803
- }
3804
- labelOf(value, options) {
3805
- var _a, _b;
3806
- return (_b = (_a = options.find((option) => option.value === value)) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : value;
3807
- }
3808
- pick(option) {
3809
- if (this.multiple) {
3810
- const selected = this.selectedValues();
3811
- const next = selected.includes(option.value)
3812
- ? selected.filter((value) => value !== option.value)
3813
- : [...selected, option.value];
3814
- this.selectValueChange.emit(next.length ? next : undefined);
3815
- return;
3816
- }
3817
- this.selectValueChange.emit(option.value);
3818
- this.close(true);
3819
- }
3820
- unpick(value) {
3821
- const next = this.selectedValues().filter((entry) => entry !== value);
3822
- this.selectValueChange.emit(next.length ? next : undefined);
3823
- }
3824
- filteredOptions(options) {
3825
- if (this.source() === 'remote' && this.searchParam())
3826
- return options;
3827
- const query = this.query.trim().toLowerCase();
3828
- if (!query)
3829
- return options;
3830
- return options.filter((option) => option.label.toLowerCase().includes(query));
3831
- }
3832
- render() {
3833
- var _a, _b;
3834
- const { options, error } = this.resolve();
3835
- const selected = this.selectedValues();
3836
- const filtered = this.filteredOptions(options);
3837
- return (index$1.h("div", { key: 'b891babd7bf125b1e388618ed12be7283136def1', class: { 'fk-select': true, 'fk-select--disabled': this.disabled } }, index$1.h("div", { key: 'ef9d0b05e422f78f92a74fcd7dd589c25bc2cbe0', class: { 'fk-select__trigger': true, 'fk-select__trigger--open': this.open }, role: "combobox", tabIndex: this.disabled ? undefined : 0, "aria-expanded": this.open ? 'true' : 'false', "aria-haspopup": "listbox", "aria-controls": `${this.instanceId}-listbox`, "aria-disabled": this.disabled ? 'true' : undefined, "aria-invalid": this.invalid ? 'true' : undefined, ref: (element) => (this.triggerEl = element), onKeyDown: this.onTriggerKeyDown, onClick: (event) => {
3838
- event.preventDefault();
3839
- this.toggleOpen();
3840
- } }, index$1.h("div", { key: '9f803f11783a2730865685c34770171a8bf92850', class: "fk-select__values" }, selected.length === 0 ? (index$1.h("span", { class: "fk-select__placeholder" }, String((_b = (_a = this.configs) === null || _a === void 0 ? void 0 : _a.placeholder) !== null && _b !== void 0 ? _b : ''))) : this.multiple ? (selected.map((value) => (index$1.h("span", { class: "fk-select__chip", key: value }, this.labelOf(value, options), index$1.h("button", { type: "button", class: "fk-select__chip-remove", "aria-label": `${index.fkT('select.clear')} — ${this.labelOf(value, options)}`, disabled: this.disabled, onClick: (event) => {
3841
- event.preventDefault();
3842
- event.stopPropagation();
3843
- this.unpick(value);
3844
- } }, "\u2715"))))) : (index$1.h("span", { class: "fk-select__value" }, this.labelOf(selected[0], options)))), !this.multiple && selected.length > 0 && !this.disabled ? (index$1.h("button", { type: "button", class: "fk-select__clear", title: index.fkT('select.clear'), "aria-label": index.fkT('select.clear'), onClick: (event) => {
3845
- event.preventDefault();
3846
- event.stopPropagation();
3847
- this.selectValueChange.emit(undefined);
3848
- } }, "\u2715")) : null, index$1.h("span", { key: '2fabef683d5007a58b1b2c34e7005cd4d3eaef04', class: "fk-select__caret" }, "\u25BE")), this.open ? (index$1.h("div", { class: "fk-select__dropdown" }, index$1.h("input", { class: "fk-select__search", type: "text", placeholder: index.fkT('select.search'), value: this.query, role: "combobox", "aria-expanded": "true", "aria-autocomplete": "list", "aria-controls": `${this.instanceId}-listbox`, "aria-activedescendant": filtered.length
3849
- ? `${this.instanceId}-opt-${Math.min(this.activeIndex, filtered.length - 1)}`
3850
- : undefined, ref: (element) => setTimeout(() => element === null || element === void 0 ? void 0 : element.focus(), 0), onInput: (event) => {
3851
- this.activeIndex = 0;
3852
- this.onSearchInput(event.target.value);
3853
- }, onKeyDown: (event) => this.onSearchKeyDown(event, filtered) }), index$1.h("div", { class: "fk-select__options", role: "listbox", id: `${this.instanceId}-listbox`, "aria-multiselectable": this.multiple ? 'true' : undefined }, filtered.map((option, index) => {
3854
- const isSelected = selected.includes(option.value);
3855
- const isActive = index === Math.min(this.activeIndex, filtered.length - 1);
3856
- return (index$1.h("div", { key: option.value, id: `${this.instanceId}-opt-${index}`, role: "option", "aria-selected": isSelected ? 'true' : 'false', class: {
3857
- 'fk-select__option': true,
3858
- 'fk-select__option--selected': isSelected,
3859
- 'fk-select__option--active': isActive,
3860
- }, onMouseEnter: () => (this.activeIndex = index), onClick: (event) => {
3861
- event.preventDefault();
3862
- this.pick(option);
3863
- } }, index$1.h("span", { class: "fk-select__option-label" }, option.label), isSelected ? index$1.h("span", { class: "fk-select__check" }, "\u2713") : null));
3864
- }), filtered.length === 0 ? (index$1.h("p", { class: "fk-select__empty" }, index.fkT('select.empty'))) : null))) : null, error ? index$1.h("span", { class: "fk-field__error" }, error) : null));
3865
- }
3866
- get host() { return index$1.getElement(this); }
3867
- static get watchers() { return {
3868
- "configs": [{
3869
- "onConfigsChange": 0
3870
- }],
3871
- "dataMap": [{
3872
- "onDataMapChange": 0
3873
- }]
3874
- }; }
3875
- };
3876
- FkSelectInput.style = fkSelectInputCss();
3877
-
3878
- const fkSignatureInputCss = () => `.sc-fk-signature-input-h{display:block}.fk-signature.sc-fk-signature-input{display:flex;flex-direction:column;gap:calc(var(--fk-spacing) / 2);align-items:flex-start}.fk-signature__canvas.sc-fk-signature-input{width:100%;max-width:480px;border:1px dashed var(--fk-color-border);border-radius:var(--fk-radius);background:var(--fk-color-surface);color:var(--fk-color-text);touch-action:none;cursor:crosshair}.fk-signature--disabled.sc-fk-signature-input .fk-signature__canvas.sc-fk-signature-input{cursor:not-allowed;opacity:0.6}.fk-signature__clear.sc-fk-signature-input{font:inherit;font-size:0.75rem;padding:3px 10px;border:1px solid var(--fk-color-border);border-radius:calc(var(--fk-radius) / 2);background:transparent;color:var(--fk-color-muted);cursor:pointer}.fk-signature__clear.sc-fk-signature-input:hover:not(:disabled){color:var(--fk-color-danger);border-color:var(--fk-color-danger)}`;
3879
-
3880
- const FkSignatureInput = class {
3881
- constructor(hostRef) {
3882
- index$1.registerInstance(this, hostRef);
3883
- this.signatureChange = index$1.createEvent(this, "signatureChange");
3884
- this.disabled = false;
3885
- this.drawing = false;
3886
- this.start = (event) => {
3887
- if (this.disabled || !this.canvas)
3888
- return;
3889
- this.drawing = true;
3890
- this.canvas.setPointerCapture(event.pointerId);
3891
- const ctx = this.context();
3892
- if (!ctx)
3893
- return;
3894
- ctx.lineWidth = 2;
3895
- ctx.lineCap = 'round';
3896
- ctx.strokeStyle = getComputedStyle(this.canvas).color;
3897
- ctx.beginPath();
3898
- ctx.moveTo(...this.position(event));
3899
- };
3900
- this.move = (event) => {
3901
- if (!this.drawing)
3902
- return;
3903
- const ctx = this.context();
3904
- if (!ctx)
3905
- return;
3906
- ctx.lineTo(...this.position(event));
3907
- ctx.stroke();
3908
- };
3909
- this.end = () => {
3910
- if (!this.drawing || !this.canvas)
3911
- return;
3912
- this.drawing = false;
3913
- this.lastEmitted = this.canvas.toDataURL('image/png');
3914
- this.signatureChange.emit(this.lastEmitted);
3915
- };
3916
- this.clear = () => {
3917
- const ctx = this.context();
3918
- if (!ctx || !this.canvas)
3919
- return;
3920
- ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
3921
- this.lastEmitted = undefined;
3922
- this.signatureChange.emit(undefined);
3923
- };
3924
- }
3925
- componentDidLoad() {
3926
- this.restore();
3927
- }
3928
- onValueChange(next) {
3929
- if (next === this.lastEmitted)
3930
- return;
3931
- this.restore();
3932
- }
3933
- context() {
3934
- var _a, _b;
3935
- return (_b = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.getContext('2d')) !== null && _b !== void 0 ? _b : undefined;
3936
- }
3937
- restore() {
3938
- const ctx = this.context();
3939
- if (!ctx || !this.canvas)
3940
- return;
3941
- ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
3942
- if (!this.value)
3943
- return;
3944
- const image = new Image();
3945
- image.onload = () => ctx.drawImage(image, 0, 0);
3946
- image.src = this.value;
3947
- }
3948
- position(event) {
3949
- const rect = this.canvas.getBoundingClientRect();
3950
- return [
3951
- ((event.clientX - rect.left) * this.canvas.width) / rect.width,
3952
- ((event.clientY - rect.top) * this.canvas.height) / rect.height,
3953
- ];
3954
- }
3955
- render() {
3956
- return (index$1.h("div", { key: 'e81687b01b30d71794b09cae1eb2215cc10a894f', class: { 'fk-signature': true, 'fk-signature--disabled': this.disabled } }, index$1.h("canvas", { key: '9a1031b1c89ee5c9d3ab465b06433125eaa7ee8c', class: "fk-signature__canvas", width: 480, height: 140, ref: (element) => (this.canvas = element), onPointerDown: this.start, onPointerMove: this.move, onPointerUp: this.end, onPointerLeave: this.end }), index$1.h("button", { key: '09e36234ffbd7367b65596a1eadf3cb019aeedad', type: "button", class: "fk-signature__clear", disabled: this.disabled, onClick: this.clear }, index.fkT('signature.clear'))));
3957
- }
3958
- static get watchers() { return {
3959
- "value": [{
3960
- "onValueChange": 0
3961
- }]
3962
- }; }
3963
- };
3964
- FkSignatureInput.style = fkSignatureInputCss();
3965
-
3966
- const fkStepperCss = () => `.sc-fk-stepper-h{display:block}.fk-stepper.sc-fk-stepper{display:flex;flex-direction:column;gap:var(--fk-spacing)}.fk-stepper__nav.sc-fk-stepper{display:flex;flex-wrap:wrap;gap:calc(var(--fk-spacing) * 1.5);margin:0;padding:0 0 var(--fk-spacing);list-style:none;border-bottom:1px solid var(--fk-color-border)}.fk-stepper__step.sc-fk-stepper{display:flex;align-items:center;gap:calc(var(--fk-spacing) / 2);cursor:pointer;color:var(--fk-color-muted);font-size:0.85rem}.fk-stepper__index.sc-fk-stepper{display:inline-flex;align-items:center;justify-content:center;width:22px;height:22px;border-radius:50%;border:1px solid var(--fk-color-border);font-size:0.72rem;font-weight:700}.fk-stepper__step--active.sc-fk-stepper{color:var(--fk-color-text);font-weight:600}.fk-stepper__step--active.sc-fk-stepper .fk-stepper__index.sc-fk-stepper{border-color:var(--fk-color-primary);background:var(--fk-color-primary);color:#ffffff}.fk-stepper__step--done.sc-fk-stepper .fk-stepper__index.sc-fk-stepper{border-color:var(--fk-color-primary);color:var(--fk-color-primary)}.fk-stepper__actions.sc-fk-stepper{display:flex;justify-content:space-between;padding-top:var(--fk-spacing);border-top:1px solid var(--fk-color-border)}.fk-stepper__button.sc-fk-stepper{font:inherit;font-size:0.85rem;padding:calc(var(--fk-spacing) / 1.5) calc(var(--fk-spacing) * 1.5);border:1px solid var(--fk-color-border);border-radius:var(--fk-radius);background:var(--fk-color-surface);color:var(--fk-color-text);cursor:pointer}.fk-stepper__button--primary.sc-fk-stepper{border-color:var(--fk-color-primary);background:var(--fk-color-primary);color:#ffffff}.fk-stepper__button.sc-fk-stepper:disabled{opacity:0.45;cursor:not-allowed}.fk-stepper__step-button.sc-fk-stepper{all:unset;display:inline-flex;align-items:center;gap:inherit;cursor:pointer}.fk-stepper__step-button.sc-fk-stepper:focus-visible{outline:2px solid color-mix(in srgb, var(--fk-color-primary) 55%, transparent);outline-offset:2px;border-radius:calc(var(--fk-radius) / 2)}`;
3967
-
3968
- const FkStepper = class {
3969
- constructor(hostRef) {
3970
- index$1.registerInstance(this, hostRef);
3971
- this.stepTouch = index$1.createEvent(this, "stepTouch");
3972
- this.stepperSubmit = index$1.createEvent(this, "stepperSubmit");
3973
- this.stepLabels = [];
3974
- this.editable = false;
3975
- this.active = 0;
3976
- this.next = (event) => {
3977
- event.preventDefault();
3978
- if (this.config('validateSteps', false) && !this.stepValid(this.active)) {
3979
- this.stepTouch.emit({ keys: this.stepKeys(this.active) });
3980
- return;
3981
- }
3982
- this.active = Math.min(this.active + 1, this.stepLabels.length - 1);
3983
- };
3984
- this.back = (event) => {
3985
- event.preventDefault();
3986
- this.active = Math.max(this.active - 1, 0);
3987
- };
3988
- this.submit = (event) => {
3989
- event.preventDefault();
3990
- if (this.config('validateSteps', false) && !this.stepValid(this.active)) {
3991
- this.stepTouch.emit({ keys: this.stepKeys(this.active) });
3992
- return;
3993
- }
3994
- this.stepperSubmit.emit();
3995
- };
3996
- }
3997
- clampActive() {
3998
- if (this.active > Math.max(this.stepLabels.length - 1, 0)) {
3999
- this.active = 0;
4000
- }
4001
- }
4002
- componentDidRender() {
4003
- const body = this.host.querySelector('.fk-stepper__body');
4004
- if (!body)
4005
- return;
4006
- Array.from(body.children).forEach((child, index) => {
4007
- const element = child;
4008
- if (this.editable)
4009
- element.style.removeProperty('display');
4010
- else
4011
- element.style.display = index === this.active ? '' : 'none';
4012
- });
4013
- }
4014
- config(name, fallback) {
4015
- var _a, _b;
4016
- const raw = (_b = (_a = this.spec) === null || _a === void 0 ? void 0 : _a.configs) === null || _b === void 0 ? void 0 : _b[name];
4017
- return typeof raw === 'boolean' ? raw : fallback;
4018
- }
4019
- stepSpec(index) {
4020
- var _a, _b, _c;
4021
- const child = (_b = (_a = this.spec) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b[index];
4022
- if (!child || !this.spec)
4023
- return undefined;
4024
- if (((_c = this.stepCache) === null || _c === void 0 ? void 0 : _c.source) !== this.spec) {
4025
- this.stepCache = { source: this.spec, specs: [] };
4026
- }
4027
- if (!this.stepCache.specs[index]) {
4028
- this.stepCache.specs[index] = {
4029
- type: 'panel',
4030
- id: 'step',
4031
- name: 'Step',
4032
- configs: { key: `step_${index}` },
4033
- children: [child],
4034
- };
4035
- }
4036
- return this.stepCache.specs[index];
4037
- }
4038
- stepKeys(index$1) {
4039
- var _a, _b, _c;
4040
- const child = (_b = (_a = this.spec) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b[index$1];
4041
- if (!child)
4042
- return [];
4043
- const keys = [];
4044
- for (const brick of index.iterateSchemaBricks(child)) {
4045
- if ((_c = brick.configs) === null || _c === void 0 ? void 0 : _c.key)
4046
- keys.push(brick.configs.key);
4047
- }
4048
- return keys;
4049
- }
4050
- stepValid(index$1) {
4051
- var _a;
4052
- const stepSpec = this.stepSpec(index$1);
4053
- if (!stepSpec)
4054
- return true;
4055
- const present = Object.fromEntries(Object.entries((_a = this.dataMap) !== null && _a !== void 0 ? _a : {}).filter(([, value]) => value !== '' && value !== null && value !== undefined));
4056
- return index.validateBrickSpecDataDetailed(stepSpec, present, this.locale).valid;
4057
- }
4058
- goToStep(index) {
4059
- if (this.editable || index <= this.active) {
4060
- this.active = index;
4061
- return;
4062
- }
4063
- if (!this.config('allowStepClick', true))
4064
- return;
4065
- if (this.config('validateSteps', false)) {
4066
- for (let i = this.active; i < index; i++) {
4067
- if (!this.stepValid(i)) {
4068
- this.active = i;
4069
- this.stepTouch.emit({ keys: this.stepKeys(i) });
4070
- return;
4071
- }
4072
- }
4073
- }
4074
- this.active = index;
4075
- }
4076
- render() {
4077
- const lastStep = Math.max(this.stepLabels.length - 1, 0);
4078
- const showSubmit = !this.editable && this.config('showSubmit', false) && this.active === lastStep;
4079
- return (index$1.h("div", { key: '3a5a9d1aa6e870241cf5a353359fe89a7c4a376a', class: "fk-stepper" }, index$1.h("ol", { key: '8d6b154016d12cd00827b8bddbe4d476dc378fab', class: "fk-stepper__nav" }, this.stepLabels.map((label, index) => (index$1.h("li", { key: `${index}-${label}`, class: {
4080
- 'fk-stepper__step': true,
4081
- 'fk-stepper__step--active': index === this.active,
4082
- 'fk-stepper__step--done': !this.editable && index < this.active,
4083
- } }, index$1.h("button", { type: "button", class: "fk-stepper__step-button", "aria-current": index === this.active ? 'step' : undefined, onClick: (event) => {
4084
- event.preventDefault();
4085
- this.goToStep(index);
4086
- } }, index$1.h("span", { class: "fk-stepper__index" }, index + 1), index$1.h("span", { class: "fk-stepper__label" }, label)))))), index$1.h("div", { key: 'cd902a9df2d72a4d7f452e7621287df50a89d3c4', class: "fk-stepper__body" }, index$1.h("slot", { key: 'ab689448817eaf7b5ddfc9146e18411fe6b5924c' })), !this.editable && this.stepLabels.length > 1 ? (index$1.h("div", { class: "fk-stepper__actions" }, index$1.h("button", { type: "button", class: "fk-stepper__button", disabled: this.active === 0, onClick: this.back }, index.fkT('stepper.back')), this.active < lastStep ? (index$1.h("button", { type: "button", class: "fk-stepper__button fk-stepper__button--primary", onClick: this.next }, index.fkT('stepper.next'))) : null, showSubmit ? (index$1.h("button", { type: "button", class: "fk-stepper__button fk-stepper__button--primary", onClick: this.submit }, index.fkT('stepper.submit'))) : null)) : null));
4087
- }
4088
- get host() { return index$1.getElement(this); }
4089
- static get watchers() { return {
4090
- "stepLabels": [{
4091
- "clampActive": 0
4092
- }]
4093
- }; }
4094
- };
4095
- FkStepper.style = fkStepperCss();
4096
-
4097
- const fkTabsCss = () => `.sc-fk-tabs-h{display:block}.fk-tabs.sc-fk-tabs{display:flex;flex-direction:column;gap:var(--fk-spacing)}.fk-tabs__nav.sc-fk-tabs{display:flex;flex-wrap:wrap;gap:2px;border-bottom:1px solid var(--fk-color-border)}.fk-tabs__tab.sc-fk-tabs{font:inherit;font-size:0.85rem;font-weight:500;padding:calc(var(--fk-spacing) / 1.5) var(--fk-spacing);border:none;border-bottom:2px solid transparent;background:transparent;color:var(--fk-color-muted);cursor:pointer}.fk-tabs__tab.sc-fk-tabs:hover{color:var(--fk-color-text)}.fk-tabs__tab--active.sc-fk-tabs{color:var(--fk-color-primary);border-bottom-color:var(--fk-color-primary);font-weight:600}`;
4098
-
4099
- const FkTabs = class {
4100
- constructor(hostRef) {
4101
- index$1.registerInstance(this, hostRef);
4102
- this.stepTouch = index$1.createEvent(this, "stepTouch");
4103
- this.tabLabels = [];
4104
- this.editable = false;
4105
- this.active = 0;
4106
- }
4107
- clampActive() {
4108
- if (this.active > Math.max(this.tabLabels.length - 1, 0)) {
4109
- this.active = 0;
4110
- }
4111
- }
4112
- componentDidRender() {
4113
- const body = this.host.querySelector('.fk-tabs__body');
4114
- if (!body)
4115
- return;
4116
- Array.from(body.children).forEach((child, index) => {
4117
- const element = child;
4118
- if (this.editable)
4119
- element.style.removeProperty('display');
4120
- else
4121
- element.style.display = index === this.active ? '' : 'none';
4122
- });
4123
- }
4124
- validateTabs() {
4125
- var _a, _b;
4126
- return ((_b = (_a = this.spec) === null || _a === void 0 ? void 0 : _a.configs) === null || _b === void 0 ? void 0 : _b.validateTabs) === true;
4127
- }
4128
- tabSpec(index) {
4129
- var _a, _b, _c;
4130
- const child = (_b = (_a = this.spec) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b[index];
4131
- if (!child || !this.spec)
4132
- return undefined;
4133
- if (((_c = this.tabCache) === null || _c === void 0 ? void 0 : _c.source) !== this.spec) {
4134
- this.tabCache = { source: this.spec, specs: [] };
4135
- }
4136
- if (!this.tabCache.specs[index]) {
4137
- this.tabCache.specs[index] = {
4138
- type: 'panel',
4139
- id: 'tab',
4140
- name: 'Tab',
4141
- configs: { key: `tab_${index}` },
4142
- children: [child],
4143
- };
4144
- }
4145
- return this.tabCache.specs[index];
4146
- }
4147
- tabKeys(index$1) {
4148
- var _a, _b, _c;
4149
- const child = (_b = (_a = this.spec) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b[index$1];
4150
- if (!child)
4151
- return [];
4152
- const keys = [];
4153
- for (const brick of index.iterateSchemaBricks(child)) {
4154
- if ((_c = brick.configs) === null || _c === void 0 ? void 0 : _c.key)
4155
- keys.push(brick.configs.key);
4156
- }
4157
- return keys;
4158
- }
4159
- tabValid(index$1) {
4160
- var _a;
4161
- const tabSpec = this.tabSpec(index$1);
4162
- if (!tabSpec)
4163
- return true;
4164
- const present = Object.fromEntries(Object.entries((_a = this.dataMap) !== null && _a !== void 0 ? _a : {}).filter(([, value]) => value !== '' && value !== null && value !== undefined));
4165
- return index.validateBrickSpecDataDetailed(tabSpec, present, this.locale).valid;
4166
- }
4167
- goToTab(index) {
4168
- if (index === this.active)
4169
- return;
4170
- if (!this.editable && this.validateTabs() && !this.tabValid(this.active)) {
4171
- this.stepTouch.emit({ keys: this.tabKeys(this.active) });
4172
- return;
4173
- }
4174
- this.active = index;
4175
- }
4176
- render() {
4177
- return (index$1.h("div", { key: 'dc3d42e16d4dd2c948b780326d13afce15bbd908', class: "fk-tabs" }, index$1.h("div", { key: 'a5cfd97f5decd63774b9054559f392c5c23447cc', class: "fk-tabs__nav", role: "tablist" }, this.tabLabels.map((label, index) => (index$1.h("button", { key: `${index}-${label}`, type: "button", role: "tab", "aria-selected": index === this.active ? 'true' : 'false', tabIndex: index === this.active ? 0 : -1, class: {
4178
- 'fk-tabs__tab': true,
4179
- 'fk-tabs__tab--active': index === this.active,
4180
- }, onKeyDown: (event) => {
4181
- const count = this.tabLabels.length;
4182
- if (!count)
4183
- return;
4184
- if (event.key === 'ArrowRight' || event.key === 'ArrowLeft') {
4185
- event.preventDefault();
4186
- const delta = event.key === 'ArrowRight' ? 1 : -1;
4187
- this.goToTab((index + delta + count) % count);
4188
- requestAnimationFrame(() => {
4189
- var _a;
4190
- (_a = this.host.querySelector('.fk-tabs__tab--active')) === null || _a === void 0 ? void 0 : _a.focus();
4191
- });
4192
- }
4193
- }, onClick: (event) => {
4194
- event.preventDefault();
4195
- this.goToTab(index);
4196
- } }, label)))), index$1.h("div", { key: 'fe33c5bdfe8a876452850abfd8082b8e4325c355', class: "fk-tabs__body" }, index$1.h("slot", { key: 'b3de83a128f36d328c34554cc6df7b1cbeae4761' }))));
4197
- }
4198
- get host() { return index$1.getElement(this); }
4199
- static get watchers() { return {
4200
- "tabLabels": [{
4201
- "clampActive": 0
4202
- }]
4203
- }; }
4204
- };
4205
- FkTabs.style = fkTabsCss();
4206
-
4207
- exports.fk_brick_actions = FkBrickActions;
4208
- exports.fk_brick_list = FkBrickList;
4209
- exports.fk_brick_mold_item = FkBrickMoldItem;
4210
- exports.fk_brick_not_found = FkBrickNotFound;
4211
- exports.fk_brick_render = FkBrickRender;
4212
- exports.fk_code_editor = FkCodeEditor;
4213
- exports.fk_data_grid = FkDataGrid;
4214
- exports.fk_drop_area = FkDropArea;
4215
- exports.fk_empty_form = FkEmptyForm;
4216
- exports.fk_file_input = FkFileInput;
4217
- exports.fk_form_builder = FkFormBuilder;
4218
- exports.fk_form_render = FkFormRender;
4219
- exports.fk_property_panel = FkPropertyPanel;
4220
- exports.fk_rules_editor = FkRulesEditor;
4221
- exports.fk_select_input = FkSelectInput;
4222
- exports.fk_signature_input = FkSignatureInput;
4223
- exports.fk_stepper = FkStepper;
4224
- exports.fk_tabs = FkTabs;