@multiplatform.one/backoffice 7.86.0 → 7.87.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -168,3 +168,186 @@ describe("form builder drag session", () => {
168
168
  expect(test.onChange).not.toHaveBeenCalled();
169
169
  });
170
170
  });
171
+
172
+ describe("form builder drag guards", () => {
173
+ it("ignores a secondary button and a press off any field card", () => {
174
+ const test = setup();
175
+ act(() =>
176
+ test.result.current.fieldPointerDown(test.second.fields[0].key, {
177
+ currentTarget: test.source,
178
+ clientX: 210,
179
+ clientY: 110,
180
+ button: 2,
181
+ pointerId: 1,
182
+ }),
183
+ );
184
+ test.move(50, 110);
185
+ expect(test.result.current.drag).toBeNull();
186
+ const loose = document.createElement("div");
187
+ test.root.append(loose);
188
+ act(() =>
189
+ test.result.current.fieldPointerDown(test.second.fields[0].key, {
190
+ currentTarget: loose,
191
+ clientX: 210,
192
+ clientY: 110,
193
+ pointerId: 1,
194
+ }),
195
+ );
196
+ test.move(50, 110);
197
+ expect(test.result.current.drag).toBeNull();
198
+ });
199
+
200
+ it("ignores a press on a field that is no longer in the layout", () => {
201
+ const test = setup();
202
+ act(() =>
203
+ test.result.current.fieldPointerDown("builder_404", {
204
+ currentTarget: test.source,
205
+ clientX: 210,
206
+ clientY: 110,
207
+ pointerId: 1,
208
+ }),
209
+ );
210
+ test.move(50, 110);
211
+ expect(test.result.current.drag).toBeNull();
212
+ });
213
+
214
+ it("follows only the pointer that started the drag", () => {
215
+ const test = setup();
216
+ test.down();
217
+ act(() =>
218
+ window.dispatchEvent(
219
+ new PointerEvent("pointermove", { pointerId: 2, clientX: 50, clientY: 110 }),
220
+ ),
221
+ );
222
+ expect(test.result.current.drag).toBeNull();
223
+ test.move(50, 110);
224
+ expect(test.result.current.drag?.target).toMatchObject({ columnId: test.first.key });
225
+ const lifted = test.result.current.drag;
226
+ act(() =>
227
+ test.result.current.fieldPointerDown(test.second.fields[0].key, {
228
+ currentTarget: test.source,
229
+ clientX: 0,
230
+ clientY: 0,
231
+ pointerId: 3,
232
+ }),
233
+ );
234
+ expect(test.result.current.drag).toBe(lifted);
235
+ });
236
+
237
+ it("holds the context menu during a touch hold and the page scroll once lifted", () => {
238
+ vi.useFakeTimers();
239
+ const test = setup();
240
+ test.down("touch");
241
+ const menu = new Event("contextmenu", { cancelable: true });
242
+ act(() => {
243
+ window.dispatchEvent(menu);
244
+ });
245
+ expect(menu.defaultPrevented).toBe(true);
246
+ const early = new Event("touchmove", { cancelable: true });
247
+ act(() => {
248
+ window.dispatchEvent(early);
249
+ });
250
+ expect(early.defaultPrevented).toBe(false);
251
+ act(() => vi.advanceTimersByTime(TOUCH_LONG_PRESS_MS));
252
+ const scroll = new Event("touchmove", { cancelable: true });
253
+ act(() => {
254
+ window.dispatchEvent(scroll);
255
+ });
256
+ expect(scroll.defaultPrevented).toBe(true);
257
+ });
258
+
259
+ it("scrolls the canvas while the card is held near its bottom edge", () => {
260
+ vi.useFakeTimers({ toFake: ["requestAnimationFrame", "cancelAnimationFrame", "setTimeout"] });
261
+ const test = setup();
262
+ const canvas = {
263
+ scrollTop: 0,
264
+ getBoundingClientRect: () => ({ left: 0, right: 400, top: 0, bottom: 200 }),
265
+ };
266
+ test.result.current.scrollRef.current = canvas as unknown as HTMLElement;
267
+ test.down();
268
+ test.move(50, 198);
269
+ act(() => vi.advanceTimersByTime(50));
270
+ expect(canvas.scrollTop).toBeGreaterThan(0);
271
+ const held = canvas.scrollTop;
272
+ test.move(500, 198);
273
+ act(() => vi.advanceTimersByTime(50));
274
+ expect(canvas.scrollTop).toBe(held);
275
+ });
276
+ });
277
+
278
+ describe("form builder keyboard drag", () => {
279
+ const key = (k: string) => ({ key: k, preventDefault: vi.fn() });
280
+
281
+ it("lifts with Enter, moves with the arrows and drops with Space", () => {
282
+ const test = setup();
283
+ const card = test.first.fields[0].key;
284
+ const ignored = key("a");
285
+ act(() => test.result.current.keyDown(card, ignored));
286
+ expect(test.result.current.drag).toBeNull();
287
+ expect(ignored.preventDefault).not.toHaveBeenCalled();
288
+ act(() => test.result.current.keyDown(card, key("Enter")));
289
+ expect(test.result.current.drag).toMatchObject({ mode: "keyboard" });
290
+ expect(test.result.current.announcement).toMatch(/^Lifted /);
291
+ const stray = key("Tab");
292
+ act(() => test.result.current.keyDown(card, stray));
293
+ expect(stray.preventDefault).not.toHaveBeenCalled();
294
+ act(() => test.result.current.keyDown(card, key("ArrowRight")));
295
+ expect(test.result.current.drag?.target.columnId).toBe(test.second.key);
296
+ expect(test.result.current.announcement).toMatch(/^Moved /);
297
+ act(() => test.result.current.keyDown(card, key(" ")));
298
+ expect(test.result.current.drag).toBeNull();
299
+ const moved = test.onChange.mock.calls[0][0].tabs[0].sections[0].columns;
300
+ expect(moved[1].fields.map((f: { df: { fieldname: string } }) => f.df.fieldname)).toContain(
301
+ "first",
302
+ );
303
+ });
304
+
305
+ it("cancels a keyboard drag on Escape anywhere in the window", () => {
306
+ const test = setup();
307
+ act(() => test.result.current.keyDown(test.first.fields[0].key, key(" ")));
308
+ expect(test.result.current.drag).not.toBeNull();
309
+ act(() => window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape" })));
310
+ expect(test.result.current.drag).toBeNull();
311
+ expect(test.result.current.announcement).toMatch(/^Movement cancelled/);
312
+ expect(test.onChange).not.toHaveBeenCalled();
313
+ });
314
+
315
+ it("leaves a pointer drag to the pointer and ignores unknown fields", () => {
316
+ const test = setup();
317
+ const unknown = key("Enter");
318
+ act(() => test.result.current.keyDown("builder_404", unknown));
319
+ expect(unknown.preventDefault).not.toHaveBeenCalled();
320
+ test.down();
321
+ test.move(50, 110);
322
+ const during = key("ArrowDown");
323
+ act(() => test.result.current.keyDown(test.first.fields[0].key, during));
324
+ expect(during.preventDefault).not.toHaveBeenCalled();
325
+ expect(test.result.current.drag?.mode).toBe("pointer");
326
+ });
327
+
328
+ it("drops a drag in progress when the layout changes under it", () => {
329
+ const layout = layoutFromFields([{ fieldname: "only", fieldtype: "Data", label: "Only" }]);
330
+ const onChange = vi.fn();
331
+ const mounted = renderHook(
332
+ ({ current }) =>
333
+ useFormBuilderDrag({
334
+ layout: current,
335
+ tabKey: current.tabs[0].key,
336
+ onChange,
337
+ onSelect: vi.fn(),
338
+ }),
339
+ { initialProps: { current: layout } },
340
+ );
341
+ act(() =>
342
+ mounted.result.current.keyDown(layout.tabs[0].sections[0].columns[0].fields[0].key, {
343
+ key: "Enter",
344
+ preventDefault: () => {},
345
+ }),
346
+ );
347
+ expect(mounted.result.current.drag).not.toBeNull();
348
+ mounted.rerender({ current: { ...layout } });
349
+ expect(mounted.result.current.drag).toBeNull();
350
+ expect(onChange).not.toHaveBeenCalled();
351
+ mounted.unmount();
352
+ });
353
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"FormConnections.d.ts","sourceRoot":"","sources":["../../src/form/FormConnections.tsx"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAY5D,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAsID,wBAAgB,eAAe,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,oBAAoB,2CA2DtF"}
1
+ {"version":3,"file":"FormConnections.d.ts","sourceRoot":"","sources":["../../src/form/FormConnections.tsx"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAY5D,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAsID,wBAAgB,eAAe,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,oBAAoB,2CA0DtF"}