@universal-material/data-grid 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +155 -2
- package/custom-elements.json +4624 -0
- package/dist/attribute-converters.d.ts +53 -0
- package/dist/attribute-converters.js +98 -0
- package/dist/attribute-converters.js.map +1 -0
- package/dist/change-source.d.ts +3 -0
- package/dist/change-source.js +2 -0
- package/dist/change-source.js.map +1 -0
- package/dist/data/data-source.d.ts +164 -0
- package/dist/data/data-source.js +75 -0
- package/dist/data/data-source.js.map +1 -0
- package/dist/data/local-source.d.ts +20 -0
- package/dist/data/local-source.js +94 -0
- package/dist/data/local-source.js.map +1 -0
- package/dist/data/remote-loader.d.ts +190 -0
- package/dist/data/remote-loader.js +608 -0
- package/dist/data/remote-loader.js.map +1 -0
- package/dist/export/csv.d.ts +28 -0
- package/dist/export/csv.js +61 -0
- package/dist/export/csv.js.map +1 -0
- package/dist/export/download.d.ts +7 -0
- package/dist/export/download.js +17 -0
- package/dist/export/download.js.map +1 -0
- package/dist/export/rows.d.ts +75 -0
- package/dist/export/rows.js +134 -0
- package/dist/export/rows.js.map +1 -0
- package/dist/export/slice.d.ts +15 -0
- package/dist/export/slice.js +35 -0
- package/dist/export/slice.js.map +1 -0
- package/dist/export/types.d.ts +155 -0
- package/dist/export/types.js +2 -0
- package/dist/export/types.js.map +1 -0
- package/dist/export/write.d.ts +38 -0
- package/dist/export/write.js +178 -0
- package/dist/export/write.js.map +1 -0
- package/dist/export-pdf/client.d.ts +75 -0
- package/dist/export-pdf/client.js +155 -0
- package/dist/export-pdf/client.js.map +1 -0
- package/dist/export-pdf/engine.d.ts +73 -0
- package/dist/export-pdf/engine.js +131 -0
- package/dist/export-pdf/engine.js.map +1 -0
- package/dist/export-pdf/grid-pdf.wasm +0 -0
- package/dist/export-pdf/index.d.ts +27 -0
- package/dist/export-pdf/index.js +566 -0
- package/dist/export-pdf/index.js.map +1 -0
- package/dist/export-pdf/serialize.d.ts +23 -0
- package/dist/export-pdf/serialize.js +127 -0
- package/dist/export-pdf/serialize.js.map +1 -0
- package/dist/export-pdf/types.d.ts +150 -0
- package/dist/export-pdf/types.js +2 -0
- package/dist/export-pdf/types.js.map +1 -0
- package/dist/export-pdf/worker.d.ts +2 -0
- package/dist/export-pdf/worker.js +81 -0
- package/dist/export-pdf/worker.js.map +1 -0
- package/dist/export-xlsx/formats.d.ts +14 -0
- package/dist/export-xlsx/formats.js +40 -0
- package/dist/export-xlsx/formats.js.map +1 -0
- package/dist/export-xlsx/index.d.ts +74 -0
- package/dist/export-xlsx/index.js +137 -0
- package/dist/export-xlsx/index.js.map +1 -0
- package/dist/features/adaptive.d.ts +25 -0
- package/dist/features/adaptive.js +47 -0
- package/dist/features/adaptive.js.map +1 -0
- package/dist/features/cell-content-focus.d.ts +29 -0
- package/dist/features/cell-content-focus.js +95 -0
- package/dist/features/cell-content-focus.js.map +1 -0
- package/dist/features/cell-range.d.ts +97 -0
- package/dist/features/cell-range.js +75 -0
- package/dist/features/cell-range.js.map +1 -0
- package/dist/features/clipboard.d.ts +28 -0
- package/dist/features/clipboard.js +48 -0
- package/dist/features/clipboard.js.map +1 -0
- package/dist/features/column-chooser.d.ts +91 -0
- package/dist/features/column-chooser.js +450 -0
- package/dist/features/column-chooser.js.map +1 -0
- package/dist/features/column-dnd.d.ts +10 -0
- package/dist/features/column-dnd.js +126 -0
- package/dist/features/column-dnd.js.map +1 -0
- package/dist/features/context-menu.d.ts +122 -0
- package/dist/features/context-menu.js +153 -0
- package/dist/features/context-menu.js.map +1 -0
- package/dist/features/drag-helper.d.ts +39 -0
- package/dist/features/drag-helper.js +108 -0
- package/dist/features/drag-helper.js.map +1 -0
- package/dist/features/drop-position.d.ts +15 -0
- package/dist/features/drop-position.js +24 -0
- package/dist/features/drop-position.js.map +1 -0
- package/dist/features/editing.d.ts +111 -0
- package/dist/features/editing.js +244 -0
- package/dist/features/editing.js.map +1 -0
- package/dist/features/filter-row.d.ts +80 -0
- package/dist/features/filter-row.js +537 -0
- package/dist/features/filter-row.js.map +1 -0
- package/dist/features/filtering.d.ts +55 -0
- package/dist/features/filtering.js +209 -0
- package/dist/features/filtering.js.map +1 -0
- package/dist/features/group-dnd.d.ts +11 -0
- package/dist/features/group-dnd.js +119 -0
- package/dist/features/group-dnd.js.map +1 -0
- package/dist/features/header-filter.d.ts +96 -0
- package/dist/features/header-filter.js +579 -0
- package/dist/features/header-filter.js.map +1 -0
- package/dist/features/host-label.d.ts +36 -0
- package/dist/features/host-label.js +184 -0
- package/dist/features/host-label.js.map +1 -0
- package/dist/features/keyboard.d.ts +59 -0
- package/dist/features/keyboard.js +127 -0
- package/dist/features/keyboard.js.map +1 -0
- package/dist/features/menu.d.ts +113 -0
- package/dist/features/menu.js +491 -0
- package/dist/features/menu.js.map +1 -0
- package/dist/features/resize.d.ts +82 -0
- package/dist/features/resize.js +214 -0
- package/dist/features/resize.js.map +1 -0
- package/dist/features/search.d.ts +45 -0
- package/dist/features/search.js +123 -0
- package/dist/features/search.js.map +1 -0
- package/dist/features/selection.d.ts +37 -0
- package/dist/features/selection.js +103 -0
- package/dist/features/selection.js.map +1 -0
- package/dist/features/sorting.d.ts +39 -0
- package/dist/features/sorting.js +53 -0
- package/dist/features/sorting.js.map +1 -0
- package/dist/features/toolbar.d.ts +125 -0
- package/dist/features/toolbar.js +135 -0
- package/dist/features/toolbar.js.map +1 -0
- package/dist/features/tree.d.ts +53 -0
- package/dist/features/tree.js +94 -0
- package/dist/features/tree.js.map +1 -0
- package/dist/features/validation.d.ts +48 -0
- package/dist/features/validation.js +172 -0
- package/dist/features/validation.js.map +1 -0
- package/dist/grid-column-def.d.ts +509 -0
- package/dist/grid-column-def.js +32 -0
- package/dist/grid-column-def.js.map +1 -0
- package/dist/grid-column.d.ts +167 -0
- package/dist/grid-column.js +376 -0
- package/dist/grid-column.js.map +1 -0
- package/dist/grid-i18n.d.ts +469 -0
- package/dist/grid-i18n.js +3222 -0
- package/dist/grid-i18n.js.map +1 -0
- package/dist/grid.d.ts +1484 -0
- package/dist/grid.js +15579 -0
- package/dist/grid.js.map +1 -0
- package/dist/grid.min.js +3858 -0
- package/dist/grid.styles.d.ts +2 -0
- package/dist/grid.styles.js +2747 -0
- package/dist/grid.styles.js.map +1 -0
- package/dist/render/cell.d.ts +16 -0
- package/dist/render/cell.js +78 -0
- package/dist/render/cell.js.map +1 -0
- package/dist/render/column-window.d.ts +18 -0
- package/dist/render/column-window.js +50 -0
- package/dist/render/column-window.js.map +1 -0
- package/dist/render/content.d.ts +45 -0
- package/dist/render/content.js +140 -0
- package/dist/render/content.js.map +1 -0
- package/dist/render/editors.d.ts +28 -0
- package/dist/render/editors.js +41 -0
- package/dist/render/editors.js.map +1 -0
- package/dist/render/footer.d.ts +61 -0
- package/dist/render/footer.js +61 -0
- package/dist/render/footer.js.map +1 -0
- package/dist/render/group-row.d.ts +35 -0
- package/dist/render/group-row.js +59 -0
- package/dist/render/group-row.js.map +1 -0
- package/dist/render/header.d.ts +92 -0
- package/dist/render/header.js +103 -0
- package/dist/render/header.js.map +1 -0
- package/dist/render/keyed-rows.d.ts +25 -0
- package/dist/render/keyed-rows.js +98 -0
- package/dist/render/keyed-rows.js.map +1 -0
- package/dist/render/virtualizer.d.ts +110 -0
- package/dist/render/virtualizer.js +509 -0
- package/dist/render/virtualizer.js.map +1 -0
- package/dist/row-model/added-rows.d.ts +32 -0
- package/dist/row-model/added-rows.js +95 -0
- package/dist/row-model/added-rows.js.map +1 -0
- package/dist/row-model/cell-range.d.ts +71 -0
- package/dist/row-model/cell-range.js +187 -0
- package/dist/row-model/cell-range.js.map +1 -0
- package/dist/row-model/columns.d.ts +80 -0
- package/dist/row-model/columns.js +207 -0
- package/dist/row-model/columns.js.map +1 -0
- package/dist/row-model/compare.d.ts +40 -0
- package/dist/row-model/compare.js +590 -0
- package/dist/row-model/compare.js.map +1 -0
- package/dist/row-model/distinct.d.ts +39 -0
- package/dist/row-model/distinct.js +105 -0
- package/dist/row-model/distinct.js.map +1 -0
- package/dist/row-model/filter.d.ts +80 -0
- package/dist/row-model/filter.js +582 -0
- package/dist/row-model/filter.js.map +1 -0
- package/dist/row-model/flatten.d.ts +129 -0
- package/dist/row-model/flatten.js +511 -0
- package/dist/row-model/flatten.js.map +1 -0
- package/dist/row-model/fold.d.ts +25 -0
- package/dist/row-model/fold.js +104 -0
- package/dist/row-model/fold.js.map +1 -0
- package/dist/row-model/format.d.ts +58 -0
- package/dist/row-model/format.js +239 -0
- package/dist/row-model/format.js.map +1 -0
- package/dist/row-model/group.d.ts +30 -0
- package/dist/row-model/group.js +173 -0
- package/dist/row-model/group.js.map +1 -0
- package/dist/row-model/lru.d.ts +19 -0
- package/dist/row-model/lru.js +48 -0
- package/dist/row-model/lru.js.map +1 -0
- package/dist/row-model/sort.d.ts +30 -0
- package/dist/row-model/sort.js +107 -0
- package/dist/row-model/sort.js.map +1 -0
- package/dist/row-model/summary.d.ts +64 -0
- package/dist/row-model/summary.js +213 -0
- package/dist/row-model/summary.js.map +1 -0
- package/dist/row-model/tree.d.ts +116 -0
- package/dist/row-model/tree.js +478 -0
- package/dist/row-model/tree.js.map +1 -0
- package/dist/row-model/types.d.ts +109 -0
- package/dist/row-model/types.js +5 -0
- package/dist/row-model/types.js.map +1 -0
- package/dist/row-model/value.d.ts +20 -0
- package/dist/row-model/value.js +57 -0
- package/dist/row-model/value.js.map +1 -0
- package/dist/state/grid-state.d.ts +147 -0
- package/dist/state/grid-state.js +295 -0
- package/dist/state/grid-state.js.map +1 -0
- package/dist/state/storage.d.ts +33 -0
- package/dist/state/storage.js +62 -0
- package/dist/state/storage.js.map +1 -0
- package/dist/state/versioned.d.ts +18 -0
- package/dist/state/versioned.js +56 -0
- package/dist/state/versioned.js.map +1 -0
- package/package.json +141 -6
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import interact from 'interactjs';
|
|
2
|
+
import { GridDragHelper, InteractRegistry, trackDragThreshold } from './drag-helper.js';
|
|
3
|
+
import { calcCursorRelativePosition, dropIndicatorEdge, RelativePosition } from './drop-position.js';
|
|
4
|
+
export class ColumnDragAndDropAdapter {
|
|
5
|
+
#headers = new InteractRegistry();
|
|
6
|
+
#grid;
|
|
7
|
+
constructor(grid) {
|
|
8
|
+
this.#grid = grid;
|
|
9
|
+
}
|
|
10
|
+
get size() {
|
|
11
|
+
return this.#headers.size;
|
|
12
|
+
}
|
|
13
|
+
prune() {
|
|
14
|
+
this.#headers.prune();
|
|
15
|
+
}
|
|
16
|
+
attach(column) {
|
|
17
|
+
if (!column || !this.#headers.add(column)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const interactable = GridDragHelper.set(column);
|
|
21
|
+
const movedEnough = trackDragThreshold(interactable);
|
|
22
|
+
interactable
|
|
23
|
+
.on('move', (event) => {
|
|
24
|
+
const interaction = event.interaction;
|
|
25
|
+
if (!(interaction.pointerIsDown && !interaction.interacting()) || !movedEnough(event)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// O clique que termina este arrasto não pode ordenar.
|
|
29
|
+
this.#grid._dragStarted();
|
|
30
|
+
const original = event.currentTarget;
|
|
31
|
+
const clone = event.currentTarget.cloneNode(true);
|
|
32
|
+
// Fora da tabela o clone perde o CSS de `th` da grade: leva o tamanho e
|
|
33
|
+
// a aparência calculados da célula (mesma largura e altura, com rowspan).
|
|
34
|
+
const rect = original.getBoundingClientRect();
|
|
35
|
+
const computed = getComputedStyle(original);
|
|
36
|
+
Object.assign(clone.style, {
|
|
37
|
+
display: 'flex',
|
|
38
|
+
alignItems: computed.verticalAlign === 'bottom' ? 'flex-end' : 'center',
|
|
39
|
+
justifyContent: computed.textAlign === 'center' ? 'center' : computed.textAlign === 'end' || computed.textAlign === 'right' ? 'flex-end' : 'flex-start',
|
|
40
|
+
boxSizing: 'border-box',
|
|
41
|
+
width: `${rect.width}px`,
|
|
42
|
+
minWidth: `${rect.width}px`,
|
|
43
|
+
maxWidth: `${rect.width}px`,
|
|
44
|
+
height: `${rect.height}px`,
|
|
45
|
+
padding: computed.padding,
|
|
46
|
+
font: computed.font,
|
|
47
|
+
color: computed.color,
|
|
48
|
+
overflow: 'hidden',
|
|
49
|
+
whiteSpace: computed.whiteSpace,
|
|
50
|
+
});
|
|
51
|
+
const moveContainer = document.createElement('div');
|
|
52
|
+
moveContainer.style.top = rect.top + 'px';
|
|
53
|
+
moveContainer.style.left = rect.left + 'px';
|
|
54
|
+
moveContainer.classList.add('move-container');
|
|
55
|
+
// Só visual: fora da árvore de acessibilidade e sem focáveis (spec 17). Sem
|
|
56
|
+
// \`inert\`: o fantasma precisa continuar recebendo o clique que termina o arrasto.
|
|
57
|
+
moveContainer.setAttribute('aria-hidden', 'true');
|
|
58
|
+
// Nada focável sob `aria-hidden` (axe aria-hidden-focus): o th e os botões clonados ficam fora do Tab.
|
|
59
|
+
[clone, ...clone.querySelectorAll('[tabindex], button, input, a[href]')].forEach(element => element.setAttribute('tabindex', '-1'));
|
|
60
|
+
moveContainer.appendChild(clone);
|
|
61
|
+
this.#grid._containerRef.value.appendChild(moveContainer);
|
|
62
|
+
interaction.start({ name: 'drag' }, event.interactable, moveContainer);
|
|
63
|
+
});
|
|
64
|
+
interact(column).dropzone({
|
|
65
|
+
accept: '.move-container',
|
|
66
|
+
ondragenter: (event) => {
|
|
67
|
+
if (!this.#accepts(event)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.#grid._containerRef.value?.classList.add('drop-target');
|
|
71
|
+
},
|
|
72
|
+
ondragleave: () => {
|
|
73
|
+
this.#grid._containerRef.value?.classList.remove('drop-target');
|
|
74
|
+
},
|
|
75
|
+
ondropdeactivate: () => {
|
|
76
|
+
this.#grid._containerRef.value?.classList.remove('drop-target');
|
|
77
|
+
},
|
|
78
|
+
ondropmove: (event) => {
|
|
79
|
+
if (!this.#accepts(event)) {
|
|
80
|
+
this.#grid._containerRef.value?.classList.remove('drop-target');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.#grid._containerRef.value?.classList.add('drop-target');
|
|
84
|
+
const container = this.#grid._containerRef.value;
|
|
85
|
+
const containerRect = container.getBoundingClientRect();
|
|
86
|
+
const position = calcCursorRelativePosition(event);
|
|
87
|
+
const left = dropIndicatorEdge(event.target, position) - containerRect.left;
|
|
88
|
+
container.style.setProperty('--_drop-indicator-left', `${Math.floor(left)}px`);
|
|
89
|
+
},
|
|
90
|
+
ondrop: (event) => {
|
|
91
|
+
const targetColumn = this.#grid._nativeColumnMap.get(event.target);
|
|
92
|
+
const movingColumn = this.#grid._nativeColumnMap.get(event.draggable.target);
|
|
93
|
+
if (!this.#accepts(event) || !targetColumn || !movingColumn) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const position = calcCursorRelativePosition(event);
|
|
97
|
+
// Índice entre as irmãs (mesma banda ou nível de cima, frente 13).
|
|
98
|
+
let targetIndex = this.#grid._siblingIndexOf(targetColumn);
|
|
99
|
+
if (position === RelativePosition.After) {
|
|
100
|
+
targetIndex++;
|
|
101
|
+
}
|
|
102
|
+
this.#grid._userMoveColumn(movingColumn, targetIndex);
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Soltar em outro cabeçalho do MESMO bloco (fixas no início, livres, fixas
|
|
108
|
+
* no fim) e da mesma banda (frente 13: banda só entre irmãs, coluna não sai
|
|
109
|
+
* da própria banda). Chip de grupo pode cair em qualquer lugar (desagrupa).
|
|
110
|
+
*/
|
|
111
|
+
#accepts(event) {
|
|
112
|
+
if (event.target === event.draggable.target) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
const targetColumn = this.#grid._nativeColumnMap.get(event.target);
|
|
116
|
+
const movingColumn = this.#grid._nativeColumnMap.get(event.draggable.target);
|
|
117
|
+
if (!targetColumn || !movingColumn || !this.#grid._isRegularColumn(movingColumn)) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
return this.#grid._canDropColumn(movingColumn, targetColumn);
|
|
121
|
+
}
|
|
122
|
+
detach() {
|
|
123
|
+
this.#headers.clear();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=column-dnd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-dnd.js","sourceRoot":"","sources":["../../src/features/column-dnd.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAGlC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAErG,MAAM,OAAO,wBAAwB;IAC1B,QAAQ,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAClC,KAAK,CAAW;IAEzB,YAAY,IAAc;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,MAAmB;QACxB,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1C,OAAO;QACT,CAAC;QAED,MAAM,YAAY,GAAG,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAChD,MAAM,WAAW,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;QAErD,YAAY;aACT,EAAE,CAAC,MAAM,EAAE,CAAC,KAAoB,EAAE,EAAE;YACnC,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;YAEtC,IAAI,CAAC,CAAC,WAAW,CAAC,aAAa,IAAI,CAAC,WAAW,CAA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ourcesContent":["import type { DropEvent } from '@interactjs/actions/drop/DropEvent';\nimport type { InteractEvent } from '@interactjs/core/InteractEvent';\nimport interact from 'interactjs';\n\nimport type { DataGrid } from '../grid.js';\nimport { GridDragHelper, InteractRegistry, trackDragThreshold } from './drag-helper.js';\nimport { calcCursorRelativePosition, dropIndicatorEdge, RelativePosition } from './drop-position.js';\n\nexport class ColumnDragAndDropAdapter {\n readonly #headers = new InteractRegistry();\n readonly #grid: DataGrid;\n\n constructor(grid: DataGrid) {\n this.#grid = grid;\n }\n\n get size(): number {\n return this.#headers.size;\n }\n\n prune(): void {\n this.#headers.prune();\n }\n\n attach(column: HTMLElement): void {\n if (!column || !this.#headers.add(column)) {\n return;\n }\n\n const interactable = GridDragHelper.set(column);\n const movedEnough = trackDragThreshold(interactable);\n\n interactable\n .on('move', (event: InteractEvent) => {\n const interaction = event.interaction;\n\n if (!(interaction.pointerIsDown && !interaction.interacting()) || !movedEnough(event)) {\n return;\n }\n\n // O clique que termina este arrasto não pode ordenar.\n this.#grid._dragStarted();\n\n const original = event.currentTarget;\n const clone = event.currentTarget.cloneNode(true) as HTMLElement;\n\n // Fora da tabela o clone perde o CSS de `th` da grade: leva o tamanho e\n // a aparência calculados da célula (mesma largura e altura, com rowspan).\n const rect = original.getBoundingClientRect();\n const computed = getComputedStyle(original);\n Object.assign(clone.style, {\n display: 'flex',\n alignItems: computed.verticalAlign === 'bottom' ? 'flex-end' : 'center',\n justifyContent: computed.textAlign === 'center' ? 'center' : computed.textAlign === 'end' || computed.textAlign === 'right' ? 'flex-end' : 'flex-start',\n boxSizing: 'border-box',\n width: `${rect.width}px`,\n minWidth: `${rect.width}px`,\n maxWidth: `${rect.width}px`,\n height: `${rect.height}px`,\n padding: computed.padding,\n font: computed.font,\n color: computed.color,\n overflow: 'hidden',\n whiteSpace: computed.whiteSpace,\n });\n\n const moveContainer = document.createElement('div');\n moveContainer.style.top = rect.top + 'px';\n moveContainer.style.left = rect.left + 'px';\n moveContainer.classList.add('move-container');\n // Só visual: fora da árvore de acessibilidade e sem focáveis (spec 17). Sem\n // \\`inert\\`: o fantasma precisa continuar recebendo o clique que termina o arrasto.\n moveContainer.setAttribute('aria-hidden', 'true');\n // Nada focável sob `aria-hidden` (axe aria-hidden-focus): o th e os botões clonados ficam fora do Tab.\n [clone, ...clone.querySelectorAll('[tabindex], button, input, a[href]')].forEach(element => element.setAttribute('tabindex', '-1'));\n moveContainer.appendChild(clone);\n\n this.#grid._containerRef.value!.appendChild(moveContainer);\n interaction.start({ name: 'drag' }, event.interactable, moveContainer);\n });\n\n interact(column).dropzone({\n accept: '.move-container',\n\n ondragenter: (event: DropEvent) => {\n if (!this.#accepts(event)) {\n return;\n }\n\n this.#grid._containerRef.value?.classList.add('drop-target');\n },\n\n ondragleave: () => {\n this.#grid._containerRef.value?.classList.remove('drop-target');\n },\n\n ondropdeactivate: () => {\n this.#grid._containerRef.value?.classList.remove('drop-target');\n },\n\n ondropmove: (event: DropEvent) => {\n if (!this.#accepts(event)) {\n this.#grid._containerRef.value?.classList.remove('drop-target');\n return;\n }\n\n this.#grid._containerRef.value?.classList.add('drop-target');\n\n const container = this.#grid._containerRef.value!;\n const containerRect = container.getBoundingClientRect();\n const position = calcCursorRelativePosition(event);\n const left = dropIndicatorEdge(event.target as HTMLElement, position) - containerRect.left;\n\n container.style.setProperty('--_drop-indicator-left', `${Math.floor(left)}px`);\n },\n\n ondrop: (event: DropEvent) => {\n\n const targetColumn = this.#grid._nativeColumnMap.get(event.target as HTMLElement);\n const movingColumn = this.#grid._nativeColumnMap.get(event.draggable.target as HTMLElement);\n\n if (!this.#accepts(event) || !targetColumn || !movingColumn) {\n return;\n }\n\n const position = calcCursorRelativePosition(event);\n\n // Índice entre as irmãs (mesma banda ou nível de cima, frente 13).\n let targetIndex = this.#grid._siblingIndexOf(targetColumn);\n\n if (position === RelativePosition.After) {\n targetIndex++;\n }\n\n this.#grid._userMoveColumn(movingColumn, targetIndex);\n },\n });\n }\n\n /**\n * Soltar em outro cabeçalho do MESMO bloco (fixas no início, livres, fixas\n * no fim) e da mesma banda (frente 13: banda só entre irmãs, coluna não sai\n * da própria banda). Chip de grupo pode cair em qualquer lugar (desagrupa).\n */\n #accepts(event: DropEvent): boolean {\n if (event.target === event.draggable.target) {\n return false;\n }\n\n const targetColumn = this.#grid._nativeColumnMap.get(event.target as HTMLElement);\n const movingColumn = this.#grid._nativeColumnMap.get(event.draggable.target as HTMLElement);\n\n if (!targetColumn || !movingColumn || !this.#grid._isRegularColumn(movingColumn)) {\n return true;\n }\n\n return this.#grid._canDropColumn(movingColumn, targetColumn);\n }\n\n detach(): void {\n this.#headers.clear();\n }\n}\n"]}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
import type { GridColumnDef, GridGroupPath } from '../grid-column-def.js';
|
|
3
|
+
import type { DataGrid, GridCellType } from '../grid.js';
|
|
4
|
+
/**
|
|
5
|
+
* Menu de contexto (frente 18): tipos públicos, quais itens embutidos valem
|
|
6
|
+
* em cada alvo e o toque longo (iOS não dispara `contextmenu` no toque).
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Where a context menu opens: a column header (bands included), the group
|
|
10
|
+
* panel (a chip or its empty area), a data row (any of its cells) or a group
|
|
11
|
+
* row. May gain members in minor versions.
|
|
12
|
+
*/
|
|
13
|
+
export type GridContextMenuTarget = 'header' | 'group-panel' | 'row' | 'group-row';
|
|
14
|
+
/** Built-in context menu items (the grid runs their action). */
|
|
15
|
+
export type GridContextMenuItemName = 'sortColumnAscending' | 'sortColumnDescending' | 'clearColumnSorting' | 'groupColumn' | 'fixColumn' | 'fixColumnStart' | 'fixColumnEnd' | 'unfixColumn' | 'moveLeft' | 'moveRight' | 'autoSizeColumn' | 'autoSizeAllColumns' | 'increaseColumnWidth' | 'decreaseColumnWidth' | 'openColumnChooser' | 'resetColumns' | 'ungroupColumn' | 'ungroupAll' | 'expandAllGroups' | 'collapseAllGroups' | 'copyCell' | 'copySelectedRows' | 'copySelectedCells' | 'paste' | 'extendSelectionToCell' | 'addCellToSelection' | 'exportSelectedCsv' | 'exportSelectedXlsx' | 'exportSelectedPdf' | 'editRow' | 'editCell' | 'removeRow' | 'restoreRow' | 'expandRow' | 'collapseRow' | 'expandNode' | 'collapseNode' | 'addChildRow' | 'expandGroup' | 'collapseGroup';
|
|
16
|
+
/**
|
|
17
|
+
* A context menu item. Built-in (`name`): the grid runs it; `text` replaces
|
|
18
|
+
* the translated label. Host (`id`): needs `text` and `action`. An item
|
|
19
|
+
* without a name is skipped with a warning.
|
|
20
|
+
*
|
|
21
|
+
* The built-in `fixColumn` ("Pin column") is a submenu: its `items` hold
|
|
22
|
+
* `fixColumnStart`, `fixColumnEnd` and `unfixColumn` (shown as radio items).
|
|
23
|
+
* You may reorder or remove them, or move one to the top level, where it is
|
|
24
|
+
* a plain item.
|
|
25
|
+
*/
|
|
26
|
+
export interface GridContextMenuItem<TItem = any> {
|
|
27
|
+
/** Built-in item (see `GridContextMenuItemName`). */
|
|
28
|
+
name?: GridContextMenuItemName;
|
|
29
|
+
/** Host item id (free; never read by the grid). */
|
|
30
|
+
id?: string;
|
|
31
|
+
/** Label (required for host items; built-ins default to the translation). */
|
|
32
|
+
text?: string;
|
|
33
|
+
/** Shown and focusable, but does nothing (`aria-disabled`). A built-in that does not apply never acts, even with `disabled: false`. */
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
/** Separator line before the item. */
|
|
36
|
+
separatorBefore?: boolean;
|
|
37
|
+
/** Host action: runs after the menu closed and the focus went back to where the menu was opened. With it, `name` is ignored. */
|
|
38
|
+
action?: (context: GridContextMenuItemActionContext<TItem>) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Submenu items. Only the built-in `fixColumn` has them: its pin items
|
|
41
|
+
* (`fixColumnStart`, `fixColumnEnd`, `unfixColumn`) and host items with
|
|
42
|
+
* `action`; other built-ins there, and `items` on any other item, are
|
|
43
|
+
* ignored with a console warning.
|
|
44
|
+
*/
|
|
45
|
+
items?: GridContextMenuItem<TItem>[];
|
|
46
|
+
}
|
|
47
|
+
/** Fields shared by `u-grid-context-menu-opening` and the item actions. */
|
|
48
|
+
export interface GridContextMenuContext<TItem = any> {
|
|
49
|
+
readonly target: GridContextMenuTarget;
|
|
50
|
+
/**
|
|
51
|
+
* Kind of the cell the menu was opened on (`row`: data, selection,
|
|
52
|
+
* command, detail toggle, full-width; `header`: header; `group-row`:
|
|
53
|
+
* group); `null` in the group panel. Fixed rows (`fixedTopItems`/
|
|
54
|
+
* `fixedBottomItems`) have no context menu and fire no event.
|
|
55
|
+
*/
|
|
56
|
+
readonly cellType: GridCellType | null;
|
|
57
|
+
/**
|
|
58
|
+
* `header`: the column or band; `group-panel`: the chip's column (`null`
|
|
59
|
+
* in the empty area); `row`: the column of the cell (`null` in the
|
|
60
|
+
* selection, detail toggle and buttons columns and in a full-width cell);
|
|
61
|
+
* `group-row`: the grouped column.
|
|
62
|
+
*/
|
|
63
|
+
readonly column: GridColumnDef<TItem> | null;
|
|
64
|
+
/** `row`: the item; `null` elsewhere. */
|
|
65
|
+
readonly item: TItem | null;
|
|
66
|
+
/** `row`: the row key; `null` elsewhere. */
|
|
67
|
+
readonly rowKey: unknown;
|
|
68
|
+
/** `group-row`: the group path; `null` elsewhere. */
|
|
69
|
+
readonly groupPath: GridGroupPath | null;
|
|
70
|
+
readonly grid: DataGrid;
|
|
71
|
+
}
|
|
72
|
+
/** Context of a host item `action`. */
|
|
73
|
+
export interface GridContextMenuItemActionContext<TItem = any> extends GridContextMenuContext<TItem> {
|
|
74
|
+
readonly menuItem: GridContextMenuItem<TItem>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* `detail` of `u-grid-context-menu-opening`. The built-in items come as
|
|
78
|
+
* `{ name, disabled, separatorBefore }` (their default state; `text` absent =
|
|
79
|
+
* the translation); `fixColumn` also has `items` (its pin sides; the current
|
|
80
|
+
* side comes enabled and only closes the menu). Change `menuItems` in place,
|
|
81
|
+
* synchronously in the listener (add, remove, reorder, change `text`,
|
|
82
|
+
* `disabled`, `separatorBefore`): the grid reads the array right after the
|
|
83
|
+
* dispatch; later changes are ignored. Do not keep the reference.
|
|
84
|
+
*/
|
|
85
|
+
export interface GridContextMenuOpeningEventDetail<TItem = any> extends GridContextMenuContext<TItem> {
|
|
86
|
+
readonly menuItems: GridContextMenuItem<TItem>[];
|
|
87
|
+
}
|
|
88
|
+
/** Embutidos de cada alvo (o hospedeiro pode tirar e repor; de outro alvo é ignorado com aviso). */
|
|
89
|
+
export declare const CONTEXT_MENU_ITEMS_BY_TARGET: Readonly<Record<GridContextMenuTarget, ReadonlySet<GridContextMenuItemName>>>;
|
|
90
|
+
/** Itens embutidos que só valem dentro do submenu "Fixar coluna" (ou soltos no nível de cima). */
|
|
91
|
+
export declare const FIX_COLUMN_ITEMS: ReadonlySet<GridContextMenuItemName>;
|
|
92
|
+
/** Espera do toque longo (como o AG Grid no cabeçalho). */
|
|
93
|
+
export declare const LONG_PRESS_MS = 500;
|
|
94
|
+
/** Deslocamento do menu aberto pelo toque (não fica sob o dedo). */
|
|
95
|
+
export declare const LONG_PRESS_OFFSET = 24;
|
|
96
|
+
export interface LongPressHost extends ReactiveControllerHost {
|
|
97
|
+
readonly renderRoot: HTMLElement | DocumentFragment;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Toque longo (500 ms, sem mover > 10 px) onde o navegador não dispara
|
|
101
|
+
* `contextmenu` no toque (iOS). Escuta só pelos bindings do template
|
|
102
|
+
* (`pointerdown` no alvo); o timer e os listeners do toque em curso saem no
|
|
103
|
+
* `hostDisconnected` (spec 14). Se o navegador dispara `contextmenu` (Android)
|
|
104
|
+
* antes do timer, o toque longo desiste (`cancel`). Depois de abrir, engole o
|
|
105
|
+
* próximo `click` (não ativa o que está sob o dedo).
|
|
106
|
+
*/
|
|
107
|
+
export declare class LongPressController implements ReactiveController {
|
|
108
|
+
#private;
|
|
109
|
+
constructor(host: LongPressHost);
|
|
110
|
+
/** Timer pendente (diagnóstico de memória). */
|
|
111
|
+
get timers(): number;
|
|
112
|
+
/** O toque longo acabou de abrir um menu (o `contextmenu` do mesmo toque não abre outro). */
|
|
113
|
+
get justFired(): boolean;
|
|
114
|
+
/** `pointerdown` de toque num alvo com menu: arma o timer. */
|
|
115
|
+
start(event: PointerEvent, open: (path: EventTarget[], x: number, y: number) => boolean): void;
|
|
116
|
+
/** O navegador disparou `contextmenu` (Android): o toque longo desiste. */
|
|
117
|
+
cancel(): void;
|
|
118
|
+
/** `click` (captura) depois do toque longo: engolido uma vez. */
|
|
119
|
+
readonly onClickCapture: (event: Event) => void;
|
|
120
|
+
hostDisconnected(): void;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=context-menu.d.ts.map
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/** Embutidos de cada alvo (o hospedeiro pode tirar e repor; de outro alvo é ignorado com aviso). */
|
|
2
|
+
export const CONTEXT_MENU_ITEMS_BY_TARGET = {
|
|
3
|
+
header: new Set([
|
|
4
|
+
'sortColumnAscending',
|
|
5
|
+
'sortColumnDescending',
|
|
6
|
+
'clearColumnSorting',
|
|
7
|
+
'fixColumn',
|
|
8
|
+
'fixColumnStart',
|
|
9
|
+
'fixColumnEnd',
|
|
10
|
+
'unfixColumn',
|
|
11
|
+
'autoSizeColumn',
|
|
12
|
+
'autoSizeAllColumns',
|
|
13
|
+
'increaseColumnWidth',
|
|
14
|
+
'decreaseColumnWidth',
|
|
15
|
+
'moveLeft',
|
|
16
|
+
'moveRight',
|
|
17
|
+
'groupColumn',
|
|
18
|
+
'openColumnChooser',
|
|
19
|
+
'resetColumns',
|
|
20
|
+
]),
|
|
21
|
+
'group-panel': new Set(['ungroupColumn', 'moveLeft', 'moveRight', 'ungroupAll', 'expandAllGroups', 'collapseAllGroups']),
|
|
22
|
+
row: new Set([
|
|
23
|
+
'copySelectedCells',
|
|
24
|
+
'paste',
|
|
25
|
+
'extendSelectionToCell',
|
|
26
|
+
'addCellToSelection',
|
|
27
|
+
'copyCell',
|
|
28
|
+
'copySelectedRows',
|
|
29
|
+
'exportSelectedCsv',
|
|
30
|
+
'exportSelectedXlsx',
|
|
31
|
+
'exportSelectedPdf',
|
|
32
|
+
'editRow',
|
|
33
|
+
'editCell',
|
|
34
|
+
'removeRow',
|
|
35
|
+
'restoreRow',
|
|
36
|
+
'expandRow',
|
|
37
|
+
'collapseRow',
|
|
38
|
+
'expandNode',
|
|
39
|
+
'collapseNode',
|
|
40
|
+
'addChildRow',
|
|
41
|
+
]),
|
|
42
|
+
'group-row': new Set(['expandGroup', 'collapseGroup', 'expandAllGroups', 'collapseAllGroups', 'ungroupColumn']),
|
|
43
|
+
};
|
|
44
|
+
/** Itens embutidos que só valem dentro do submenu "Fixar coluna" (ou soltos no nível de cima). */
|
|
45
|
+
export const FIX_COLUMN_ITEMS = new Set(['fixColumnStart', 'fixColumnEnd', 'unfixColumn']);
|
|
46
|
+
/** Espera do toque longo (como o AG Grid no cabeçalho). */
|
|
47
|
+
export const LONG_PRESS_MS = 500;
|
|
48
|
+
/** Movimento que cancela o toque longo (px). */
|
|
49
|
+
const LONG_PRESS_SLOP = 10;
|
|
50
|
+
/** Deslocamento do menu aberto pelo toque (não fica sob o dedo). */
|
|
51
|
+
export const LONG_PRESS_OFFSET = 24;
|
|
52
|
+
/**
|
|
53
|
+
* Toque longo (500 ms, sem mover > 10 px) onde o navegador não dispara
|
|
54
|
+
* `contextmenu` no toque (iOS). Escuta só pelos bindings do template
|
|
55
|
+
* (`pointerdown` no alvo); o timer e os listeners do toque em curso saem no
|
|
56
|
+
* `hostDisconnected` (spec 14). Se o navegador dispara `contextmenu` (Android)
|
|
57
|
+
* antes do timer, o toque longo desiste (`cancel`). Depois de abrir, engole o
|
|
58
|
+
* próximo `click` (não ativa o que está sob o dedo).
|
|
59
|
+
*/
|
|
60
|
+
export class LongPressController {
|
|
61
|
+
#timer;
|
|
62
|
+
#start;
|
|
63
|
+
#target;
|
|
64
|
+
#swallowClick;
|
|
65
|
+
/** Momento em que o toque longo abriu (o `contextmenu` tardio do Android é ignorado). */
|
|
66
|
+
#firedAt;
|
|
67
|
+
constructor(host) {
|
|
68
|
+
this.#target = null;
|
|
69
|
+
this.#swallowClick = false;
|
|
70
|
+
/** Momento em que o toque longo abriu (o `contextmenu` tardio do Android é ignorado). */
|
|
71
|
+
this.#firedAt = -Infinity;
|
|
72
|
+
/** `click` (captura) depois do toque longo: engolido uma vez. */
|
|
73
|
+
this.onClickCapture = (event) => {
|
|
74
|
+
if (this.#swallowClick) {
|
|
75
|
+
this.#swallowClick = false;
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
event.stopPropagation();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
this.#onMove = (event) => {
|
|
81
|
+
const start = this.#start;
|
|
82
|
+
if (start?.pointerId === event.pointerId
|
|
83
|
+
&& Math.hypot(event.clientX - start.x, event.clientY - start.y) > LONG_PRESS_SLOP) {
|
|
84
|
+
this.#release();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
this.#onEnd = () => {
|
|
88
|
+
this.#release();
|
|
89
|
+
};
|
|
90
|
+
host.addController(this);
|
|
91
|
+
}
|
|
92
|
+
/** Timer pendente (diagnóstico de memória). */
|
|
93
|
+
get timers() {
|
|
94
|
+
return this.#timer === undefined ? 0 : 1;
|
|
95
|
+
}
|
|
96
|
+
/** O toque longo acabou de abrir um menu (o `contextmenu` do mesmo toque não abre outro). */
|
|
97
|
+
get justFired() {
|
|
98
|
+
return performance.now() - this.#firedAt < 1000;
|
|
99
|
+
}
|
|
100
|
+
/** `pointerdown` de toque num alvo com menu: arma o timer. */
|
|
101
|
+
start(event, open) {
|
|
102
|
+
// Toque novo: o `click` do toque longo anterior (se nunca veio) não engole este.
|
|
103
|
+
this.#swallowClick = false;
|
|
104
|
+
if (event.pointerType !== 'touch' || !event.isPrimary) {
|
|
105
|
+
// Segundo dedo (multitoque) cancela.
|
|
106
|
+
if (event.pointerType === 'touch') {
|
|
107
|
+
this.cancel();
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
this.cancel();
|
|
112
|
+
const path = event.composedPath();
|
|
113
|
+
const target = event.currentTarget;
|
|
114
|
+
this.#start = { x: event.clientX, y: event.clientY, pointerId: event.pointerId };
|
|
115
|
+
this.#target = target;
|
|
116
|
+
target?.addEventListener('pointermove', this.#onMove);
|
|
117
|
+
target?.addEventListener('pointerup', this.#onEnd);
|
|
118
|
+
target?.addEventListener('pointercancel', this.#onEnd);
|
|
119
|
+
target?.addEventListener('scroll', this.#onEnd, true);
|
|
120
|
+
this.#timer = setTimeout(() => {
|
|
121
|
+
const start = this.#start;
|
|
122
|
+
this.#release();
|
|
123
|
+
// Só um menu aberto engole o clique e o \`contextmenu\` do mesmo toque
|
|
124
|
+
// (sem menu, como numa linha fixa, fica o do navegador).
|
|
125
|
+
if (open(path, start.x + LONG_PRESS_OFFSET, start.y + LONG_PRESS_OFFSET)) {
|
|
126
|
+
this.#swallowClick = true;
|
|
127
|
+
this.#firedAt = performance.now();
|
|
128
|
+
}
|
|
129
|
+
}, LONG_PRESS_MS);
|
|
130
|
+
}
|
|
131
|
+
/** O navegador disparou `contextmenu` (Android): o toque longo desiste. */
|
|
132
|
+
cancel() {
|
|
133
|
+
this.#release();
|
|
134
|
+
}
|
|
135
|
+
#onMove;
|
|
136
|
+
#onEnd;
|
|
137
|
+
#release() {
|
|
138
|
+
clearTimeout(this.#timer);
|
|
139
|
+
this.#timer = undefined;
|
|
140
|
+
this.#start = undefined;
|
|
141
|
+
const target = this.#target;
|
|
142
|
+
this.#target = null;
|
|
143
|
+
target?.removeEventListener('pointermove', this.#onMove);
|
|
144
|
+
target?.removeEventListener('pointerup', this.#onEnd);
|
|
145
|
+
target?.removeEventListener('pointercancel', this.#onEnd);
|
|
146
|
+
target?.removeEventListener('scroll', this.#onEnd, true);
|
|
147
|
+
}
|
|
148
|
+
hostDisconnected() {
|
|
149
|
+
this.#release();
|
|
150
|
+
this.#swallowClick = false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=context-menu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-menu.js","sourceRoot":"","sources":["../../src/features/context-menu.ts"],"names":[],"mappings":"AAwIA,oGAAoG;AACpG,MAAM,CAAC,MAAM,4BAA4B,GAAkF;IACzH,MAAM,EAAE,IAAI,GAAG,CAA0B;QACvC,qBAAqB;QACrB,sBAAsB;QACtB,oBAAoB;QACpB,WAAW;QACX,gBAAgB;QAChB,cAAc;QACd,aAAa;QACb,gBAAgB;QAChB,oBAAoB;QACpB,qBAAqB;QACrB,qBAAqB;QACrB,UAAU;QACV,WAAW;QACX,aAAa;QACb,mBAAmB;QACnB,cAAc;KACf,CAAC;IACF,aAAa,EAAE,IAAI,GAAG,CAA0B,CAAC,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;IACjJ,GAAG,EAAE,IAAI,GAAG,CAA0B;QACpC,mBAAmB;QACnB,OAAO;QACP,uBAAuB;QACvB,oBAAoB;QACpB,UAAU;QACV,kBAAkB;QAClB,mBAAmB;QACnB,oBAAoB;QACpB,mBAAmB;QACnB,SAAS;QACT,UAAU;QACV,WAAW;QACX,YAAY;QACZ,WAAW;QACX,aAAa;QACb,YAAY;QACZ,cAAc;QACd,aAAa;KACd,CAAC;IACF,WAAW,EAAE,IAAI,GAAG,CAA0B,CAAC,aAAa,EAAE,eAAe,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,eAAe,CAAC,CAAC;CACzI,CAAC;AAEF,kGAAkG;AAClG,MAAM,CAAC,MAAM,gBAAgB,GAAyC,IAAI,GAAG,CAA0B,CAAC,gBAAgB,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC;AAE1J,2DAA2D;AAC3D,MAAM,CAAC,MAAM,a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cesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\n\nimport type { GridColumnDef, GridGroupPath } from '../grid-column-def.js';\nimport type { DataGrid, GridCellType } from '../grid.js';\n\n/**\n * Menu de contexto (frente 18): tipos públicos, quais itens embutidos valem\n * em cada alvo e o toque longo (iOS não dispara `contextmenu` no toque).\n */\n\n/**\n * Where a context menu opens: a column header (bands included), the group\n * panel (a chip or its empty area), a data row (any of its cells) or a group\n * row. May gain members in minor versions.\n */\nexport type GridContextMenuTarget = 'header' | 'group-panel' | 'row' | 'group-row';\n\n/** Built-in context menu items (the grid runs their action). */\nexport type GridContextMenuItemName =\n | 'sortColumnAscending'\n | 'sortColumnDescending'\n | 'clearColumnSorting'\n | 'groupColumn'\n | 'fixColumn'\n | 'fixColumnStart'\n | 'fixColumnEnd'\n | 'unfixColumn'\n | 'moveLeft'\n | 'moveRight'\n | 'autoSizeColumn'\n | 'autoSizeAllColumns'\n | 'increaseColumnWidth'\n | 'decreaseColumnWidth'\n | 'openColumnChooser'\n | 'resetColumns'\n | 'ungroupColumn'\n | 'ungroupAll'\n | 'expandAllGroups'\n | 'collapseAllGroups'\n | 'copyCell'\n | 'copySelectedRows'\n | 'copySelectedCells'\n | 'paste'\n | 'extendSelectionToCell'\n | 'addCellToSelection'\n | 'exportSelectedCsv'\n | 'exportSelectedXlsx'\n | 'exportSelectedPdf'\n | 'editRow'\n | 'editCell'\n | 'removeRow'\n | 'restoreRow'\n | 'expandRow'\n | 'collapseRow'\n | 'expandNode'\n | 'collapseNode'\n | 'addChildRow'\n | 'expandGroup'\n | 'collapseGroup';\n\n/**\n * A context menu item. Built-in (`name`): the grid runs it; `text` replaces\n * the translated label. Host (`id`): needs `text` and `action`. An item\n * without a name is skipped with a warning.\n *\n * The built-in `fixColumn` (\"Pin column\") is a submenu: its `items` hold\n * `fixColumnStart`, `fixColumnEnd` and `unfixColumn` (shown as radio items).\n * You may reorder or remove them, or move one to the top level, where it is\n * a plain item.\n */\nexport interface GridContextMenuItem<TItem = any> {\n /** Built-in item (see `GridContextMenuItemName`). */\n name?: GridContextMenuItemName;\n /** Host item id (free; never read by the grid). */\n id?: string;\n /** Label (required for host items; built-ins default to the translation). */\n text?: string;\n /** Shown and focusable, but does nothing (`aria-disabled`). A built-in that does not apply never acts, even with `disabled: false`. */\n disabled?: boolean;\n /** Separator line before the item. */\n separatorBefore?: boolean;\n /** Host action: runs after the menu closed and the focus went back to where the menu was opened. With it, `name` is ignored. */\n action?: (context: GridContextMenuItemActionContext<TItem>) => void;\n /**\n * Submenu items. Only the built-in `fixColumn` has them: its pin items\n * (`fixColumnStart`, `fixColumnEnd`, `unfixColumn`) and host items with\n * `action`; other built-ins there, and `items` on any other item, are\n * ignored with a console warning.\n */\n items?: GridContextMenuItem<TItem>[];\n}\n\n/** Fields shared by `u-grid-context-menu-opening` and the item actions. */\nexport interface GridContextMenuContext<TItem = any> {\n readonly target: GridContextMenuTarget;\n /**\n * Kind of the cell the menu was opened on (`row`: data, selection,\n * command, detail toggle, full-width; `header`: header; `group-row`:\n * group); `null` in the group panel. Fixed rows (`fixedTopItems`/\n * `fixedBottomItems`) have no context menu and fire no event.\n */\n readonly cellType: GridCellType | null;\n /**\n * `header`: the column or band; `group-panel`: the chip's column (`null`\n * in the empty area); `row`: the column of the cell (`null` in the\n * selection, detail toggle and buttons columns and in a full-width cell);\n * `group-row`: the grouped column.\n */\n readonly column: GridColumnDef<TItem> | null;\n /** `row`: the item; `null` elsewhere. */\n readonly item: TItem | null;\n /** `row`: the row key; `null` elsewhere. */\n readonly rowKey: unknown;\n /** `group-row`: the group path; `null` elsewhere. */\n readonly groupPath: GridGroupPath | null;\n readonly grid: DataGrid;\n}\n\n/** Context of a host item `action`. */\nexport interface GridContextMenuItemActionContext<TItem = any> extends GridContextMenuContext<TItem> {\n readonly menuItem: GridContextMenuItem<TItem>;\n}\n\n/**\n * `detail` of `u-grid-context-menu-opening`. The built-in items come as\n * `{ name, disabled, separatorBefore }` (their default state; `text` absent =\n * the translation); `fixColumn` also has `items` (its pin sides; the current\n * side comes enabled and only closes the menu). Change `menuItems` in place,\n * synchronously in the listener (add, remove, reorder, change `text`,\n * `disabled`, `separatorBefore`): the grid reads the array right after the\n * dispatch; later changes are ignored. Do not keep the reference.\n */\nexport interface GridContextMenuOpeningEventDetail<TItem = any> extends GridContextMenuContext<TItem> {\n readonly menuItems: GridContextMenuItem<TItem>[];\n}\n\n/** Embutidos de cada alvo (o hospedeiro pode tirar e repor; de outro alvo é ignorado com aviso). */\nexport const CONTEXT_MENU_ITEMS_BY_TARGET: Readonly<Record<GridContextMenuTarget, ReadonlySet<GridContextMenuItemName>>> = {\n header: new Set<GridContextMenuItemName>([\n 'sortColumnAscending',\n 'sortColumnDescending',\n 'clearColumnSorting',\n 'fixColumn',\n 'fixColumnStart',\n 'fixColumnEnd',\n 'unfixColumn',\n 'autoSizeColumn',\n 'autoSizeAllColumns',\n 'increaseColumnWidth',\n 'decreaseColumnWidth',\n 'moveLeft',\n 'moveRight',\n 'groupColumn',\n 'openColumnChooser',\n 'resetColumns',\n ]),\n 'group-panel': new Set<GridContextMenuItemName>(['ungroupColumn', 'moveLeft', 'moveRight', 'ungroupAll', 'expandAllGroups', 'collapseAllGroups']),\n row: new Set<GridContextMenuItemName>([\n 'copySelectedCells',\n 'paste',\n 'extendSelectionToCell',\n 'addCellToSelection',\n 'copyCell',\n 'copySelectedRows',\n 'exportSelectedCsv',\n 'exportSelectedXlsx',\n 'exportSelectedPdf',\n 'editRow',\n 'editCell',\n 'removeRow',\n 'restoreRow',\n 'expandRow',\n 'collapseRow',\n 'expandNode',\n 'collapseNode',\n 'addChildRow',\n ]),\n 'group-row': new Set<GridContextMenuItemName>(['expandGroup', 'collapseGroup', 'expandAllGroups', 'collapseAllGroups', 'ungroupColumn']),\n};\n\n/** Itens embutidos que só valem dentro do submenu \"Fixar coluna\" (ou soltos no nível de cima). */\nexport const FIX_COLUMN_ITEMS: ReadonlySet<GridContextMenuItemName> = new Set<GridContextMenuItemName>(['fixColumnStart', 'fixColumnEnd', 'unfixColumn']);\n\n/** Espera do toque longo (como o AG Grid no cabeçalho). */\nexport const LONG_PRESS_MS = 500;\n/** Movimento que cancela o toque longo (px). */\nconst LONG_PRESS_SLOP = 10;\n/** Deslocamento do menu aberto pelo toque (não fica sob o dedo). */\nexport const LONG_PRESS_OFFSET = 24;\n\nexport interface LongPressHost extends ReactiveControllerHost {\n readonly renderRoot: HTMLElement | DocumentFragment;\n}\n\n/**\n * Toque longo (500 ms, sem mover > 10 px) onde o navegador não dispara\n * `contextmenu` no toque (iOS). Escuta só pelos bindings do template\n * (`pointerdown` no alvo); o timer e os listeners do toque em curso saem no\n * `hostDisconnected` (spec 14). Se o navegador dispara `contextmenu` (Android)\n * antes do timer, o toque longo desiste (`cancel`). Depois de abrir, engole o\n * próximo `click` (não ativa o que está sob o dedo).\n */\nexport class LongPressController implements ReactiveController {\n #timer: ReturnType<typeof setTimeout> | undefined;\n #start: { x: number; y: number; pointerId: number } | undefined;\n #target: EventTarget | null = null;\n #swallowClick = false;\n /** Momento em que o toque longo abriu (o `contextmenu` tardio do Android é ignorado). */\n #firedAt = -Infinity;\n\n constructor(host: LongPressHost) {\n host.addController(this);\n }\n\n /** Timer pendente (diagnóstico de memória). */\n get timers(): number {\n return this.#timer === undefined ? 0 : 1;\n }\n\n /** O toque longo acabou de abrir um menu (o `contextmenu` do mesmo toque não abre outro). */\n get justFired(): boolean {\n return performance.now() - this.#firedAt < 1000;\n }\n\n /** `pointerdown` de toque num alvo com menu: arma o timer. */\n start(event: PointerEvent, open: (path: EventTarget[], x: number, y: number) => boolean): void {\n // Toque novo: o `click` do toque longo anterior (se nunca veio) não engole este.\n this.#swallowClick = false;\n\n if (event.pointerType !== 'touch' || !event.isPrimary) {\n // Segundo dedo (multitoque) cancela.\n if (event.pointerType === 'touch') {\n this.cancel();\n }\n\n return;\n }\n\n this.cancel();\n const path = event.composedPath();\n const target = event.currentTarget;\n this.#start = { x: event.clientX, y: event.clientY, pointerId: event.pointerId };\n this.#target = target;\n target?.addEventListener('pointermove', this.#onMove as EventListener);\n target?.addEventListener('pointerup', this.#onEnd);\n target?.addEventListener('pointercancel', this.#onEnd);\n target?.addEventListener('scroll', this.#onEnd, true);\n this.#timer = setTimeout(() => {\n const start = this.#start!;\n this.#release();\n\n // Só um menu aberto engole o clique e o \\`contextmenu\\` do mesmo toque\n // (sem menu, como numa linha fixa, fica o do navegador).\n if (open(path, start.x + LONG_PRESS_OFFSET, start.y + LONG_PRESS_OFFSET)) {\n this.#swallowClick = true;\n this.#firedAt = performance.now();\n }\n }, LONG_PRESS_MS);\n }\n\n /** O navegador disparou `contextmenu` (Android): o toque longo desiste. */\n cancel(): void {\n this.#release();\n }\n\n /** `click` (captura) depois do toque longo: engolido uma vez. */\n readonly onClickCapture = (event: Event): void => {\n if (this.#swallowClick) {\n this.#swallowClick = false;\n event.preventDefault();\n event.stopPropagation();\n }\n };\n\n readonly #onMove = (event: PointerEvent): void => {\n const start = this.#start;\n\n if (start?.pointerId === event.pointerId\n && Math.hypot(event.clientX - start.x, event.clientY - start.y) > LONG_PRESS_SLOP) {\n this.#release();\n }\n };\n\n readonly #onEnd = (): void => {\n this.#release();\n };\n\n #release(): void {\n clearTimeout(this.#timer);\n this.#timer = undefined;\n this.#start = undefined;\n\n const target = this.#target;\n this.#target = null;\n target?.removeEventListener('pointermove', this.#onMove as EventListener);\n target?.removeEventListener('pointerup', this.#onEnd);\n target?.removeEventListener('pointercancel', this.#onEnd);\n target?.removeEventListener('scroll', this.#onEnd, true);\n }\n\n hostDisconnected(): void {\n this.#release();\n this.#swallowClick = false;\n }\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Interactable } from '@interactjs/core/Interactable';
|
|
2
|
+
import type { InteractEvent } from '@interactjs/core/InteractEvent';
|
|
3
|
+
/**
|
|
4
|
+
* Distância (px) que o ponteiro precisa andar para um cabeçalho/chip virar
|
|
5
|
+
* arrasto. Abaixo disso o gesto é clique (ordenar), não arrasto.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DRAG_START_DISTANCE = 4;
|
|
8
|
+
type DragThresholdTest = (event: InteractEvent) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Guarda onde o ponteiro desceu no elemento e devolve o teste "já andou o
|
|
11
|
+
* bastante para ser arrasto?" para o `move` do mesmo elemento.
|
|
12
|
+
*/
|
|
13
|
+
export declare const trackDragThreshold: (interactable: Interactable) => DragThresholdTest;
|
|
14
|
+
export declare class GridDragHelper {
|
|
15
|
+
static set(element: HTMLElement): Interactable;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* O interactjs guarda num array global (`scope.interactions.list`) a última
|
|
19
|
+
* `Interaction` de cada ponteiro, com o evento de `pointerdown` (alvo = o
|
|
20
|
+
* grid). Ela fica lá até o próximo `pointerdown` na página e segura o grid
|
|
21
|
+
* removido. Chamado no `disconnectedCallback`, depois do `unset` dos
|
|
22
|
+
* elementos: descarta as interações paradas que apontam para `owner` (o
|
|
23
|
+
* interactjs cria outra quando precisar).
|
|
24
|
+
*/
|
|
25
|
+
export declare const releaseInteractions: (owner: HTMLElement) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Conjunto de elementos registrados no interactjs. Registrar de novo o mesmo
|
|
28
|
+
* elemento não faz nada; elementos que saíram do DOM são soltos no `prune`.
|
|
29
|
+
*/
|
|
30
|
+
export declare class InteractRegistry {
|
|
31
|
+
#private;
|
|
32
|
+
get size(): number;
|
|
33
|
+
/** Devolve `false` se o elemento já estava registrado. */
|
|
34
|
+
add(element: HTMLElement): boolean;
|
|
35
|
+
prune(): void;
|
|
36
|
+
clear(): void;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=drag-helper.d.ts.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import interact from 'interactjs';
|
|
2
|
+
/**
|
|
3
|
+
* Distância (px) que o ponteiro precisa andar para um cabeçalho/chip virar
|
|
4
|
+
* arrasto. Abaixo disso o gesto é clique (ordenar), não arrasto.
|
|
5
|
+
*/
|
|
6
|
+
export const DRAG_START_DISTANCE = 4;
|
|
7
|
+
/**
|
|
8
|
+
* Guarda onde o ponteiro desceu no elemento e devolve o teste "já andou o
|
|
9
|
+
* bastante para ser arrasto?" para o `move` do mesmo elemento.
|
|
10
|
+
*/
|
|
11
|
+
export const trackDragThreshold = (interactable) => {
|
|
12
|
+
let start = { x: 0, y: 0 };
|
|
13
|
+
interactable.on('down', (event) => {
|
|
14
|
+
start = { x: event.clientX, y: event.clientY };
|
|
15
|
+
});
|
|
16
|
+
return event => Math.hypot(event.clientX - start.x, event.clientY - start.y) >= DRAG_START_DISTANCE;
|
|
17
|
+
};
|
|
18
|
+
export class GridDragHelper {
|
|
19
|
+
static set(element) {
|
|
20
|
+
const position = { x: 0, y: 0 };
|
|
21
|
+
return interact(element).draggable({
|
|
22
|
+
manualStart: true,
|
|
23
|
+
listeners: {
|
|
24
|
+
start: () => {
|
|
25
|
+
position.x = 0;
|
|
26
|
+
position.y = 0;
|
|
27
|
+
},
|
|
28
|
+
move: (event) => {
|
|
29
|
+
position.x += event.dx;
|
|
30
|
+
position.y += event.dy;
|
|
31
|
+
event.target.style.transform = `translate(${position.x}px, ${position.y}px)`;
|
|
32
|
+
},
|
|
33
|
+
end: (event) => {
|
|
34
|
+
const target = event.target;
|
|
35
|
+
target.remove();
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const interactScope = () => interact.scope;
|
|
42
|
+
/** `node` está em `owner`, no light DOM ou dentro do shadow root dele. */
|
|
43
|
+
const belongsTo = (node, owner) => node instanceof Node
|
|
44
|
+
&& (owner.contains(node) || !!owner.shadowRoot?.contains(node));
|
|
45
|
+
const referencesOwner = (interaction, owner) => [
|
|
46
|
+
interaction.element,
|
|
47
|
+
interaction.downEvent?.target,
|
|
48
|
+
interaction.downPointer?.target,
|
|
49
|
+
interaction._latestPointer?.eventTarget,
|
|
50
|
+
...(interaction.pointers ?? []).map(pointer => pointer.downTarget),
|
|
51
|
+
].some(node => belongsTo(node, owner));
|
|
52
|
+
/**
|
|
53
|
+
* O interactjs guarda num array global (`scope.interactions.list`) a última
|
|
54
|
+
* `Interaction` de cada ponteiro, com o evento de `pointerdown` (alvo = o
|
|
55
|
+
* grid). Ela fica lá até o próximo `pointerdown` na página e segura o grid
|
|
56
|
+
* removido. Chamado no `disconnectedCallback`, depois do `unset` dos
|
|
57
|
+
* elementos: descarta as interações paradas que apontam para `owner` (o
|
|
58
|
+
* interactjs cria outra quando precisar).
|
|
59
|
+
*/
|
|
60
|
+
export const releaseInteractions = (owner) => {
|
|
61
|
+
const scope = interactScope();
|
|
62
|
+
const list = scope?.interactions?.list;
|
|
63
|
+
if (!scope || !list) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
67
|
+
const interaction = list[i];
|
|
68
|
+
if (interaction.interacting() || !referencesOwner(interaction, owner)) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
scope.fire('interactions:destroy', { interaction });
|
|
72
|
+
interaction.destroy();
|
|
73
|
+
list.splice(i, 1);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Conjunto de elementos registrados no interactjs. Registrar de novo o mesmo
|
|
78
|
+
* elemento não faz nada; elementos que saíram do DOM são soltos no `prune`.
|
|
79
|
+
*/
|
|
80
|
+
export class InteractRegistry {
|
|
81
|
+
#elements = new Set();
|
|
82
|
+
get size() {
|
|
83
|
+
return this.#elements.size;
|
|
84
|
+
}
|
|
85
|
+
/** Devolve `false` se o elemento já estava registrado. */
|
|
86
|
+
add(element) {
|
|
87
|
+
if (this.#elements.has(element)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
this.#elements.add(element);
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
prune() {
|
|
94
|
+
for (const element of this.#elements) {
|
|
95
|
+
if (!element.isConnected) {
|
|
96
|
+
interact(element).unset();
|
|
97
|
+
this.#elements.delete(element);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
clear() {
|
|
102
|
+
for (const element of this.#elements) {
|
|
103
|
+
interact(element).unset();
|
|
104
|
+
}
|
|
105
|
+
this.#elements.clear();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=drag-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drag-helper.js","sourceRoot":"","sources":["../../src/features/drag-helper.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAElC;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAIrC;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,YAA0B,EAAqB,EAAE;IAClF,IAAI,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAE3B,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAoB,EAAE,EAAE;QAC/C,KAAK,GAAG,EAAE,CAAC,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IACjD,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,mBAAmB,CAAC;AACtG,CAAC,CAAC;AAEF,MAAM,OAAO,cAAc;IACzB,MAAM,CAAC,GAAG,CAAC,OAAoB;QAC7B,MAAM,QAAQ,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QA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AAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACrC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;gBACzB,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC;gBAC1B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK;QACH,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACrC,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC;QAC5B,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["import type { Interactable } from '@interactjs/core/Interactable';\nimport type { InteractEvent } from '@interactjs/core/InteractEvent';\nimport interact from 'interactjs';\n\n/**\n * Distância (px) que o ponteiro precisa andar para um cabeçalho/chip virar\n * arrasto. Abaixo disso o gesto é clique (ordenar), não arrasto.\n */\nexport const DRAG_START_DISTANCE = 4;\n\ntype DragThresholdTest = (event: InteractEvent) => boolean;\n\n/**\n * Guarda onde o ponteiro desceu no elemento e devolve o teste \"já andou o\n * bastante para ser arrasto?\" para o `move` do mesmo elemento.\n */\nexport const trackDragThreshold = (interactable: Interactable): DragThresholdTest => {\n let start = { x: 0, y: 0 };\n\n interactable.on('down', (event: InteractEvent) => {\n start = { x: event.clientX, y: event.clientY };\n });\n\n return event => Math.hypot(event.clientX - start.x, event.clientY - start.y) >= DRAG_START_DISTANCE;\n};\n\nexport class GridDragHelper {\n static set(element: HTMLElement): Interactable {\n const position = { x: 0, y: 0 };\n\n return interact(element).draggable({\n manualStart: true,\n listeners: {\n start: () => {\n position.x = 0;\n position.y = 0;\n },\n move: (event: InteractEvent) => {\n position.x += event.dx;\n position.y += event.dy;\n\n event.target.style.transform = `translate(${position.x}px, ${position.y}px)`;\n },\n end: (event: InteractEvent) => {\n const target = event.target as HTMLElement;\n target.remove();\n },\n },\n });\n }\n}\n\n/** O que usamos das `Interaction`s internas do interactjs 1.10 (sem tipo público). */\ninterface InteractionInternals {\n interacting(): boolean;\n destroy(): void;\n element: unknown;\n downEvent: { target?: unknown } | null;\n downPointer: { target?: unknown } | null;\n pointers: { downTarget?: unknown }[] | null;\n _latestPointer: { eventTarget?: unknown } | null;\n}\n\ninterface InteractScope {\n interactions?: { list: InteractionInternals[] };\n fire(name: string, arg: object): unknown;\n}\n\nconst interactScope = (): InteractScope | undefined =>\n (interact as unknown as { scope?: InteractScope }).scope;\n\n/** `node` está em `owner`, no light DOM ou dentro do shadow root dele. */\nconst belongsTo = (node: unknown, owner: HTMLElement): boolean =>\n node instanceof Node\n && (owner.contains(node) || !!owner.shadowRoot?.contains(node));\n\nconst referencesOwner = (interaction: InteractionInternals, owner: HTMLElement): boolean =>\n [\n interaction.element,\n interaction.downEvent?.target,\n interaction.downPointer?.target,\n interaction._latestPointer?.eventTarget,\n ...(interaction.pointers ?? []).map(pointer => pointer.downTarget),\n ].some(node => belongsTo(node, owner));\n\n/**\n * O interactjs guarda num array global (`scope.interactions.list`) a última\n * `Interaction` de cada ponteiro, com o evento de `pointerdown` (alvo = o\n * grid). Ela fica lá até o próximo `pointerdown` na página e segura o grid\n * removido. Chamado no `disconnectedCallback`, depois do `unset` dos\n * elementos: descarta as interações paradas que apontam para `owner` (o\n * interactjs cria outra quando precisar).\n */\nexport const releaseInteractions = (owner: HTMLElement): void => {\n const scope = interactScope();\n const list = scope?.interactions?.list;\n\n if (!scope || !list) {\n return;\n }\n\n for (let i = list.length - 1; i >= 0; i--) {\n const interaction = list[i];\n\n if (interaction.interacting() || !referencesOwner(interaction, owner)) {\n continue;\n }\n\n scope.fire('interactions:destroy', { interaction });\n interaction.destroy();\n list.splice(i, 1);\n }\n};\n\n/**\n * Conjunto de elementos registrados no interactjs. Registrar de novo o mesmo\n * elemento não faz nada; elementos que saíram do DOM são soltos no `prune`.\n */\nexport class InteractRegistry {\n readonly #elements = new Set<HTMLElement>();\n\n get size(): number {\n return this.#elements.size;\n }\n\n /** Devolve `false` se o elemento já estava registrado. */\n add(element: HTMLElement): boolean {\n if (this.#elements.has(element)) {\n return false;\n }\n\n this.#elements.add(element);\n return true;\n }\n\n prune(): void {\n for (const element of this.#elements) {\n if (!element.isConnected) {\n interact(element).unset();\n this.#elements.delete(element);\n }\n }\n }\n\n clear(): void {\n for (const element of this.#elements) {\n interact(element).unset();\n }\n\n this.#elements.clear();\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DropEvent } from '@interactjs/actions/drop/DropEvent';
|
|
2
|
+
export declare const RelativePosition: {
|
|
3
|
+
readonly Before: 0;
|
|
4
|
+
readonly After: 1;
|
|
5
|
+
};
|
|
6
|
+
export type DropSide = typeof RelativePosition[keyof typeof RelativePosition];
|
|
7
|
+
export declare const isRtl: (element: Element) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Posição LÓGICA do cursor em relação ao alvo: antes ou depois na ordem das
|
|
10
|
+
* colunas. Em RTL a metade esquerda é "depois".
|
|
11
|
+
*/
|
|
12
|
+
export declare const calcCursorRelativePosition: (event: DropEvent) => DropSide;
|
|
13
|
+
/** Borda física (px no viewport) onde o indicador de soltar deve aparecer. */
|
|
14
|
+
export declare const dropIndicatorEdge: (target: Element, position: DropSide) => number;
|
|
15
|
+
//# sourceMappingURL=drop-position.d.ts.map
|