@bennerinformatics/ember-fw-table 2.1.4 → 2.1.6

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 (166) hide show
  1. package/addon/components/fw-table-resort.js +18 -4
  2. package/addon/components/fw-table-sortable.js +23 -0
  3. package/addon/templates/components/fw-table-resort.hbs +3 -0
  4. package/addon/templates/components/fw-table-sortable.hbs +10 -1
  5. package/docs/api.js +61 -0
  6. package/docs/assets/css/custom.css +82 -0
  7. package/docs/assets/css/external-small.png +0 -0
  8. package/docs/assets/css/logo.png +0 -0
  9. package/docs/assets/css/main.css +793 -0
  10. package/docs/assets/css/theme.css +547 -0
  11. package/docs/assets/favicon.ico +0 -0
  12. package/docs/assets/icons/android-icon-144x144.png +0 -0
  13. package/docs/assets/icons/android-icon-192x192.png +0 -0
  14. package/docs/assets/icons/android-icon-36x36.png +0 -0
  15. package/docs/assets/icons/android-icon-48x48.png +0 -0
  16. package/docs/assets/icons/android-icon-72x72.png +0 -0
  17. package/docs/assets/icons/android-icon-96x96.png +0 -0
  18. package/docs/assets/icons/apple-icon-114x114.png +0 -0
  19. package/docs/assets/icons/apple-icon-120x120.png +0 -0
  20. package/docs/assets/icons/apple-icon-144x144.png +0 -0
  21. package/docs/assets/icons/apple-icon-152x152.png +0 -0
  22. package/docs/assets/icons/apple-icon-180x180.png +0 -0
  23. package/docs/assets/icons/apple-icon-57x57.png +0 -0
  24. package/docs/assets/icons/apple-icon-60x60.png +0 -0
  25. package/docs/assets/icons/apple-icon-72x72.png +0 -0
  26. package/docs/assets/icons/apple-icon-76x76.png +0 -0
  27. package/docs/assets/icons/apple-icon-precomposed.png +0 -0
  28. package/docs/assets/icons/apple-icon.png +0 -0
  29. package/docs/assets/icons/browserconfig.xml +2 -0
  30. package/docs/assets/icons/favicon-16x16.png +0 -0
  31. package/docs/assets/icons/favicon-32x32.png +0 -0
  32. package/docs/assets/icons/favicon-96x96.png +0 -0
  33. package/docs/assets/icons/favicon.ico +0 -0
  34. package/docs/assets/icons/manifest.json +41 -0
  35. package/docs/assets/icons/ms-icon-144x144.png +0 -0
  36. package/docs/assets/icons/ms-icon-150x150.png +0 -0
  37. package/docs/assets/icons/ms-icon-310x310.png +0 -0
  38. package/docs/assets/icons/ms-icon-70x70.png +0 -0
  39. package/docs/assets/img/ember-logo.png +0 -0
  40. package/docs/assets/img/fw-logo.png +0 -0
  41. package/docs/assets/img/spinner.gif +0 -0
  42. package/docs/assets/index.html +10 -0
  43. package/docs/assets/js/api-filter.js +56 -0
  44. package/docs/assets/js/api-list.js +255 -0
  45. package/docs/assets/js/api-search.js +98 -0
  46. package/docs/assets/js/apidocs.js +376 -0
  47. package/docs/assets/js/yui-prettify.js +17 -0
  48. package/docs/assets/js/yuidoc-bootstrap.js +274 -0
  49. package/docs/assets/vendor/bootstrap/css/bootstrap.css +6760 -0
  50. package/docs/assets/vendor/bootstrap/css/bootstrap.min.css +6 -0
  51. package/docs/assets/vendor/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
  52. package/docs/assets/vendor/bootstrap/fonts/glyphicons-halflings-regular.svg +288 -0
  53. package/docs/assets/vendor/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
  54. package/docs/assets/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
  55. package/docs/assets/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff2 +0 -0
  56. package/docs/assets/vendor/bootstrap/img/glyphicons-halflings-white.png +0 -0
  57. package/docs/assets/vendor/bootstrap/img/glyphicons-halflings.png +0 -0
  58. package/docs/assets/vendor/bootstrap/js/bootstrap.js +2363 -0
  59. package/docs/assets/vendor/bootstrap/js/bootstrap.min.js +7 -0
  60. package/docs/assets/vendor/font-awesome/css/font-awesome.css +2199 -0
  61. package/docs/assets/vendor/font-awesome/css/font-awesome.min.css +4 -0
  62. package/docs/assets/vendor/font-awesome/fonts/FontAwesome.otf +0 -0
  63. package/docs/assets/vendor/font-awesome/fonts/fontawesome-webfont.eot +0 -0
  64. package/docs/assets/vendor/font-awesome/fonts/fontawesome-webfont.svg +685 -0
  65. package/docs/assets/vendor/font-awesome/fonts/fontawesome-webfont.ttf +0 -0
  66. package/docs/assets/vendor/font-awesome/fonts/fontawesome-webfont.woff +0 -0
  67. package/docs/assets/vendor/font-awesome/fonts/fontawesome-webfont.woff2 +0 -0
  68. package/docs/assets/vendor/github-slugger/slugger.js +59 -0
  69. package/docs/assets/vendor/jquery/jquery.min.js +6 -0
  70. package/docs/assets/vendor/jquery-ui/jquery-ui.min.js +6 -0
  71. package/docs/assets/vendor/prettify/CHANGES.html +130 -0
  72. package/docs/assets/vendor/prettify/COPYING +202 -0
  73. package/docs/assets/vendor/prettify/README.html +203 -0
  74. package/docs/assets/vendor/prettify/prettify-min.css +1 -0
  75. package/docs/assets/vendor/prettify/prettify-min.js +1 -0
  76. package/docs/classes/BaseCells.html +484 -0
  77. package/docs/classes/Export.html +457 -0
  78. package/docs/classes/Format.html +577 -0
  79. package/docs/classes/FwCellAction.html +312 -0
  80. package/docs/classes/FwCellBoolean.html +311 -0
  81. package/docs/classes/FwCellNullable.html +312 -0
  82. package/docs/classes/FwCellPermissionIcon.html +321 -0
  83. package/docs/classes/FwColumnSortable.html +358 -0
  84. package/docs/classes/FwColumnTitle.html +314 -0
  85. package/docs/classes/FwDeleteModal.html +485 -0
  86. package/docs/classes/FwExpandableRow.html +307 -0
  87. package/docs/classes/FwPaginationWrapper.html +2129 -0
  88. package/docs/classes/FwRowToggle.html +355 -0
  89. package/docs/classes/FwRowToggleIndex.html +312 -0
  90. package/docs/classes/FwTableExpandedRow.html +307 -0
  91. package/docs/classes/FwTableResort.html +827 -0
  92. package/docs/classes/FwTableSortable.html +1293 -0
  93. package/docs/classes/Row.html +352 -0
  94. package/docs/classes/Table.html +672 -0
  95. package/docs/classes/TableUtil.html +410 -0
  96. package/docs/classes/index.html +10 -0
  97. package/docs/data.json +2324 -0
  98. package/docs/elements/index.html +10 -0
  99. package/docs/files/addon_classes_Row.js.html +318 -0
  100. package/docs/files/addon_classes_Table.js.html +390 -0
  101. package/docs/files/addon_components_fw-cell-action.js.html +257 -0
  102. package/docs/files/addon_components_fw-cell-boolean.js.html +251 -0
  103. package/docs/files/addon_components_fw-cell-nullable.js.html +253 -0
  104. package/docs/files/addon_components_fw-cell-permission-icon.js.html +266 -0
  105. package/docs/files/addon_components_fw-column-sortable.js.html +281 -0
  106. package/docs/files/addon_components_fw-column-title.js.html +259 -0
  107. package/docs/files/addon_components_fw-delete-modal.js.html +318 -0
  108. package/docs/files/addon_components_fw-expandable-row.js.html +248 -0
  109. package/docs/files/addon_components_fw-pagination-wrapper.js.html +838 -0
  110. package/docs/files/addon_components_fw-row-toggle-index.js.html +252 -0
  111. package/docs/files/addon_components_fw-row-toggle.js.html +270 -0
  112. package/docs/files/addon_components_fw-table-expanded-row.js.html +261 -0
  113. package/docs/files/addon_components_fw-table-expanded-rows.js.html +263 -0
  114. package/docs/files/addon_components_fw-table-resort.js.html +457 -0
  115. package/docs/files/addon_components_fw-table-sortable.js.html +663 -0
  116. package/docs/files/addon_documentation.js.html +301 -0
  117. package/docs/files/addon_initializers_responsive.js.html +253 -0
  118. package/docs/files/addon_utils_base-cells.js.html +313 -0
  119. package/docs/files/addon_utils_export.js.html +316 -0
  120. package/docs/files/addon_utils_formats.js.html +335 -0
  121. package/docs/files/addon_utils_table.js.html +274 -0
  122. package/docs/files/index.html +10 -0
  123. package/docs/index.html +252 -0
  124. package/docs/modules/CellComponents.html +313 -0
  125. package/docs/modules/ColumnComponents.html +284 -0
  126. package/docs/modules/Components.html +285 -0
  127. package/docs/modules/Introduction.html +261 -0
  128. package/docs/modules/Utils.html +285 -0
  129. package/docs/modules/index.html +10 -0
  130. package/package.json +64 -64
  131. package/.yalc/ember-sortable/.huskyrc +0 -5
  132. package/.yalc/ember-sortable/CHANGELOG.md +0 -755
  133. package/.yalc/ember-sortable/CODE_OF_CONDUCT.md +0 -6
  134. package/.yalc/ember-sortable/LICENSE.md +0 -9
  135. package/.yalc/ember-sortable/MIGRATION_GUIDE_MODIFIERS.md +0 -95
  136. package/.yalc/ember-sortable/MIGRATION_GUIDE_V2.md +0 -120
  137. package/.yalc/ember-sortable/Makefile +0 -24
  138. package/.yalc/ember-sortable/README.md +0 -423
  139. package/.yalc/ember-sortable/RELEASE.md +0 -60
  140. package/.yalc/ember-sortable/V2_MIGRATION_RFC.md +0 -1100
  141. package/.yalc/ember-sortable/addon/modifiers/sortable-group.js +0 -754
  142. package/.yalc/ember-sortable/addon/modifiers/sortable-handle.js +0 -29
  143. package/.yalc/ember-sortable/addon/modifiers/sortable-item.js +0 -869
  144. package/.yalc/ember-sortable/addon/services/ember-sortable.js +0 -92
  145. package/.yalc/ember-sortable/addon/system/scroll-container.js +0 -53
  146. package/.yalc/ember-sortable/addon/system/scroll-parent.js +0 -33
  147. package/.yalc/ember-sortable/addon/utils/constant.js +0 -9
  148. package/.yalc/ember-sortable/addon/utils/coordinate.js +0 -34
  149. package/.yalc/ember-sortable/addon/utils/css-calculation.js +0 -20
  150. package/.yalc/ember-sortable/addon/utils/defaults.js +0 -26
  151. package/.yalc/ember-sortable/addon/utils/keyboard.js +0 -32
  152. package/.yalc/ember-sortable/addon-test-support/helpers/drag.js +0 -111
  153. package/.yalc/ember-sortable/addon-test-support/helpers/index.js +0 -4
  154. package/.yalc/ember-sortable/addon-test-support/helpers/reorder.js +0 -41
  155. package/.yalc/ember-sortable/addon-test-support/utils/keyboard.js +0 -32
  156. package/.yalc/ember-sortable/addon-test-support/utils/offset.js +0 -14
  157. package/.yalc/ember-sortable/app/modifiers/sortable-group.js +0 -1
  158. package/.yalc/ember-sortable/app/modifiers/sortable-handle.js +0 -1
  159. package/.yalc/ember-sortable/app/modifiers/sortable-item.js +0 -1
  160. package/.yalc/ember-sortable/app/services/ember-sortable-internal-state.js +0 -1
  161. package/.yalc/ember-sortable/config/environment.js +0 -5
  162. package/.yalc/ember-sortable/demo.gif +0 -0
  163. package/.yalc/ember-sortable/index.js +0 -5
  164. package/.yalc/ember-sortable/package.json +0 -65
  165. package/.yalc/ember-sortable/yalc.sig +0 -1
  166. package/yalc.lock +0 -10
@@ -1,869 +0,0 @@
1
- /* eslint-disable ember/no-computed-properties-in-native-classes */
2
- import Modifier from 'ember-modifier';
3
- import { Promise, defer } from 'rsvp';
4
- import { action, set } from '@ember/object';
5
- import { DRAG_ACTIONS, ELEMENT_CLICK_ACTION, END_ACTIONS } from '../utils/constant';
6
- import { run, throttle, bind, scheduleOnce, later } from '@ember/runloop';
7
- import { DEBUG } from '@glimmer/env';
8
- import { getX, getY } from '../utils/coordinate';
9
- import ScrollContainer from '../system/scroll-container';
10
- import scrollParent from '../system/scroll-parent';
11
- import { getBorderSpacing } from '../utils/css-calculation';
12
- import { buildWaiter } from '@ember/test-waiters';
13
- import { inject as service } from '@ember/service';
14
- import { assert, deprecate } from '@ember/debug';
15
- import { registerDestructor } from '@ember/destroyable';
16
- import { isTesting } from '@embroider/macros';
17
-
18
- const sortableItemWaiter = buildWaiter('sortable-item-waiter');
19
-
20
- /**
21
- * Modifier to mark an element as an item to be reordered
22
- *
23
- * @param {Object} model The model that this item will represent
24
- * @param {boolean} [disabled=false] Set to true to make this item not sortable
25
- * @param {Function} [onDragStart] An optional callback for when dragging starts.
26
- * @param {Function} [onDragStop] An optional callback for when dragging stops.
27
- *
28
- * @module drag-drop/draggable-group
29
- * @example
30
- * <ol {{sortable-group onChange=this.update a11yAnnouncementConfig=this.myA11yConfig}}>
31
- * {{#each model.items as |item|}}
32
- * <li {{sortable-item model=item}}>
33
- * {{item.name}}
34
- * <span class="handle" {{sortable-handle}}>&varr;</span>
35
- * </li>
36
- * {{/each}}
37
- * </ol>
38
- */
39
- export default class SortableItemModifier extends Modifier {
40
- className = 'sortable-item';
41
-
42
- @service('ember-sortable-internal-state') sortableService;
43
-
44
- _sortableGroup;
45
- /**
46
- * The SortableGroupModifier this item belongs to. Assigned by the group
47
- * when it inspects all the items in the list
48
- *
49
- * @type SortableGroupModifier
50
- */
51
- get sortableGroup() {
52
- if (this._sortableGroup === undefined) {
53
- this._sortableGroup = this.sortableService.fetchGroup(this.groupName);
54
- assert(
55
- `No sortable group named ${this.groupName} found. Please check that the groups and items have the same groupName`,
56
- this._sortableGroup !== undefined
57
- );
58
- }
59
- return this._sortableGroup.groupModifier;
60
- }
61
-
62
- get model() {
63
- return this.named.model;
64
- }
65
-
66
- get direction() {
67
- return this.sortableGroup?.direction;
68
- }
69
-
70
- get groupDisabled() {
71
- return this.sortableGroup?.disabled;
72
- }
73
-
74
- /**
75
- * This is the group name used to keep groups separate if there are more than one on the screen at a time.
76
- * If no group is assigned a default is used
77
- *
78
- * @default "_EmberSortableGroup"
79
- * @returns {*|string}
80
- */
81
- get groupName() {
82
- return this.named.groupName || '_EmberSortableGroup';
83
- }
84
-
85
- /**
86
- The frequency with which the group is informed
87
- that an update is required.
88
- @property updateInterval
89
- @type Number
90
- @default 125
91
- */
92
- get updateInterval() {
93
- return this.named.updateInterval || 125;
94
- }
95
-
96
- /**
97
- Additional spacing between active item and the rest of the elements.
98
- @property spacing
99
- @type Number
100
- @default 0[px]
101
- */
102
- get spacing() {
103
- return this.named.spacing || 0;
104
- }
105
-
106
- /**
107
- Removes the ability for the current item to be sorted
108
- @property disabled
109
- @type boolean
110
- @default false
111
- */
112
- get isDisabled() {
113
- deprecate(
114
- '"isDraggingDisabled" is deprecated. Please migrate to "disabled" named argument',
115
- !('isDraggingDisabled' in this.named),
116
- {
117
- id: 'ember-sortable.is-dragging-disabled',
118
- url: 'https://github.com/adopted-ember-addons/ember-sortable#readme',
119
- until: '3.0.0',
120
- for: 'ember-sortable',
121
- since: {
122
- available: '2.2.6',
123
- enabled: '2.2.6',
124
- },
125
- }
126
- );
127
-
128
- return this.groupDisabled || this.named.disabled || this.named.isDraggingDisabled || false;
129
- }
130
-
131
- /**
132
- Selector for the element to use as handle.
133
- 1. By default, we will hook it the yielded sortable-handle.
134
- 2. If you don't use the sortable-handle, the entire element will be used as the handle.
135
- 3. In very rare situations, if you want to use a handle, but not the sortable-handle,
136
- you can override this class with your own handle's selector. This behavior will be
137
- synonymous with v1
138
- @property handle
139
- @type String
140
- @default "[data-sortable-handle]"
141
- */
142
- get handle() {
143
- return this.named.handle || '[data-sortable-handle]';
144
- }
145
-
146
- handleElement;
147
-
148
- /**
149
- * Tolerance, in pixels, for when sorting should start.
150
- * If specified, sorting will not start until after mouse
151
- * is dragged beyond distance. Can be used to allow for clicks
152
- * on elements within a handle.
153
- *
154
- * @property distance
155
- * @type Integer
156
- * @default 0
157
- */
158
- get distance() {
159
- return this.named.distance || 0;
160
- }
161
-
162
- /**
163
- * True if the item is currently being dragged.
164
- *
165
- * @property isDragging
166
- * @type boolean
167
- * @default false
168
- * @protected
169
- */
170
- _isDragging = false;
171
- get isDragging() {
172
- return this._isDragging;
173
- }
174
- set isDragging(value) {
175
- if (value) {
176
- this.element.classList.add('is-dragging');
177
- } else {
178
- this.element.classList.remove('is-dragging');
179
- }
180
- this._isDragging = value;
181
- }
182
-
183
- /**
184
- Action that fires when the item starts being dragged.
185
- @property onDragStart
186
- @type Function
187
- @param {Object} item model
188
- @default null
189
- */
190
- get onDragStart() {
191
- return this.named.onDragStart || ((item) => item);
192
- }
193
-
194
- /**
195
- Action that fires when the item stops being dragged.
196
- @property onDragStop
197
- @type Function
198
- @param {Object} item model
199
- @default null
200
- */
201
- get onDragStop() {
202
- return this.named.onDragStop || ((item) => item);
203
- }
204
-
205
- /**
206
- True if the item is currently dropping.
207
- @property isDropping
208
- @type Boolean
209
- @default false
210
- */
211
- _isDropping = false;
212
- get isDropping() {
213
- return this._isDropping;
214
- }
215
- set isDropping(value) {
216
- if (value) {
217
- this.element.classList.add('is-dropping');
218
- } else {
219
- this.element.classList.remove('is-dropping');
220
- }
221
- this._isDropping = value;
222
- }
223
-
224
- /**
225
- True if the item was dropped during the interaction
226
- @property wasDropped
227
- @type Boolean
228
- @default false
229
- */
230
- wasDropped = false;
231
-
232
- /**
233
- @property isBusy
234
- @type Boolean
235
- */
236
- get isBusy() {
237
- return this.isDragging || this.isDropping;
238
- }
239
-
240
- /**
241
- @property disableCheckScrollBounds
242
- */
243
- get disableCheckScrollBounds() {
244
- return this.named.disableCheckScrollBounds != undefined ? this.named.disableCheckScrollBounds : isTesting();
245
- }
246
-
247
- /**
248
- @method mouseDown
249
- */
250
- @action
251
- mouseDown(event) {
252
- if (event.which !== 1) {
253
- return;
254
- }
255
- if (event.ctrlKey) {
256
- return;
257
- }
258
-
259
- this._primeDrag(event);
260
- }
261
-
262
- @action
263
- keyDown(event) {
264
- if (this.isDisabled) {
265
- return;
266
- }
267
-
268
- this.setupHandleElement();
269
-
270
- // If the event is coming from within the item, we do not want to activate keyboard reorder mode.
271
- if (event.target === this.handleElement || event.target === this.element) {
272
- this.sortableGroup.activateKeyDown(this);
273
- } else {
274
- this.sortableGroup.deactivateKeyDown();
275
- }
276
- }
277
-
278
- /**
279
- @method touchStart
280
- */
281
- @action
282
- touchStart(event) {
283
- this._primeDrag(event);
284
- }
285
-
286
- /**
287
- @method freeze
288
- */
289
- freeze() {
290
- let el = this.element;
291
- if (!el) {
292
- return;
293
- }
294
-
295
- el.style.transition = 'none';
296
- }
297
-
298
- /**
299
- @method reset
300
- */
301
- reset() {
302
- let el = this.element;
303
- if (!el) {
304
- return;
305
- }
306
-
307
- delete this._y;
308
- delete this._x;
309
-
310
- el.style.transform = '';
311
- }
312
-
313
- /**
314
- @method thaw
315
- */
316
- thaw() {
317
- let el = this.element;
318
- if (!el) {
319
- return;
320
- }
321
-
322
- el.style.transition = '';
323
- }
324
-
325
- /**
326
- * Setup event listeners for drag and drop
327
- *
328
- * @method _primeDrag
329
- * @param {Event} startEvent JS Event object
330
- * @private
331
- */
332
- _primeDrag(startEvent) {
333
- if (this.isDisabled) {
334
- return;
335
- }
336
-
337
- if (this.handleElement && !startEvent.target.closest(this.handle)) {
338
- return;
339
- }
340
-
341
- startEvent.preventDefault();
342
- startEvent.stopPropagation();
343
-
344
- this._prepareDragListener = bind(this, this._prepareDrag, startEvent);
345
-
346
- DRAG_ACTIONS.forEach((event) => window.addEventListener(event, this._prepareDragListener));
347
-
348
- this._cancelStartDragListener = () => {
349
- DRAG_ACTIONS.forEach((event) => window.removeEventListener(event, this._prepareDragListener));
350
- };
351
-
352
- const selfCancellingCallback = () => {
353
- END_ACTIONS.forEach((event) => window.removeEventListener(event, selfCancellingCallback));
354
- this._cancelStartDragListener();
355
- };
356
-
357
- END_ACTIONS.forEach((event) => window.addEventListener(event, selfCancellingCallback));
358
- }
359
-
360
- /**
361
- * Prepares for the drag event
362
- *
363
- * @method _prepareDrag
364
- * @param {Event} startEvent JS Event object
365
- * @param {Event} event JS Event object
366
- * @private
367
- */
368
- _prepareDrag(startEvent, event) {
369
- let distance = this.distance;
370
- let dx = Math.abs(getX(startEvent) - getX(event));
371
- let dy = Math.abs(getY(startEvent) - getY(event));
372
-
373
- if (distance <= dx || distance <= dy) {
374
- DRAG_ACTIONS.forEach((event) => window.removeEventListener(event, this._prepareDragListener));
375
- this._startDrag(startEvent);
376
- }
377
- }
378
-
379
- /**
380
- * Start dragging & setup more event listeners
381
- *
382
- * @method _startDrag
383
- * @param {Event} event JS Event object
384
- * @private
385
- */
386
- _startDrag(event) {
387
- if (this.isBusy) {
388
- return;
389
- }
390
-
391
- let drag = this._makeDragHandler(event);
392
- let dragThrottled = (ev) => throttle(this, drag, ev, 16, false);
393
-
394
- let drop = () => {
395
- DRAG_ACTIONS.forEach((event) => window.removeEventListener(event, dragThrottled));
396
- END_ACTIONS.forEach((event) => window.removeEventListener(event, drop));
397
-
398
- run(() => {
399
- this._drop();
400
- });
401
- };
402
-
403
- DRAG_ACTIONS.forEach((event) => window.addEventListener(event, dragThrottled));
404
- END_ACTIONS.forEach((event) => window.addEventListener(event, drop));
405
-
406
- this.sortableGroup.prepare();
407
- set(this, 'isDragging', true);
408
- this.onDragStart(this.model);
409
- this._scrollOnEdges(drag);
410
- }
411
-
412
- /**
413
- The maximum scroll speed when dragging element.
414
- @property maxScrollSpeed
415
- @default 20
416
- */
417
- maxScrollSpeed = 20;
418
-
419
- _scrollOnEdges(drag) {
420
- let groupDirection = this.direction;
421
- let element = this.element;
422
- let scrollContainer = new ScrollContainer(scrollParent(element));
423
- let itemContainer = {
424
- width: parseInt(getComputedStyle(element).width, 10),
425
- get height() {
426
- return parseInt(getComputedStyle(element).height, 10);
427
- },
428
- get left() {
429
- return element.getBoundingClientRect().left;
430
- },
431
- get right() {
432
- return this.left + this.width;
433
- },
434
- get top() {
435
- return element.getBoundingClientRect().top;
436
- },
437
- get bottom() {
438
- return this.top + this.height;
439
- },
440
- };
441
-
442
- let leadingEdgeKey, trailingEdgeKey, scrollKey, pageKey;
443
- if (groupDirection === 'x') {
444
- leadingEdgeKey = 'left';
445
- trailingEdgeKey = 'right';
446
- scrollKey = 'scrollLeft';
447
- pageKey = 'pageX';
448
- } else {
449
- leadingEdgeKey = 'top';
450
- trailingEdgeKey = 'bottom';
451
- scrollKey = 'scrollTop';
452
- pageKey = 'pageY';
453
- }
454
-
455
- let createFakeEvent = () => {
456
- if (this._pageX == null && this._pageY == null) {
457
- return;
458
- }
459
- return {
460
- pageX: this._pageX,
461
- pageY: this._pageY,
462
- clientX: this._pageX,
463
- clientY: this._pageY,
464
- };
465
- };
466
-
467
- // Set a trigger padding that will start scrolling
468
- // the box when the item reaches within padding pixels
469
- // of the edge of the scroll container.
470
- let checkScrollBounds = () => {
471
- let leadingEdge = itemContainer[leadingEdgeKey];
472
- let trailingEdge = itemContainer[trailingEdgeKey];
473
- let scroll = scrollContainer[scrollKey]();
474
-
475
- let delta = 0;
476
- if (trailingEdge >= scrollContainer[trailingEdgeKey]) {
477
- delta = trailingEdge - scrollContainer[trailingEdgeKey];
478
- } else if (leadingEdge <= scrollContainer[leadingEdgeKey]) {
479
- delta = leadingEdge - scrollContainer[leadingEdgeKey];
480
- }
481
-
482
- if (delta !== 0) {
483
- let speed = this.maxScrollSpeed;
484
- delta = Math.min(Math.max(delta, -1 * speed), speed);
485
-
486
- delta = scrollContainer[scrollKey](scroll + delta) - scroll;
487
-
488
- let event = createFakeEvent();
489
- if (event) {
490
- if (scrollContainer.isWindow) {
491
- event[pageKey] += delta;
492
- }
493
- run(() => drag(event));
494
- }
495
- }
496
- if (this.isDragging) {
497
- requestAnimationFrame(checkScrollBounds);
498
- }
499
- };
500
-
501
- if (!this.disableCheckScrollBounds) {
502
- requestAnimationFrame(checkScrollBounds);
503
- }
504
- }
505
-
506
- /**
507
- @method _makeDragHandler
508
- @param {Event} startEvent
509
- @return {Function}
510
- @private
511
- */
512
- _makeDragHandler(startEvent) {
513
- const groupDirection = this.direction;
514
- let dragOrigin;
515
- let elementOrigin;
516
- let scrollOrigin;
517
- let parentElement = this.element.parentNode;
518
-
519
- if (groupDirection === 'x') {
520
- dragOrigin = getX(startEvent);
521
- elementOrigin = this.x;
522
- scrollOrigin = parentElement.getBoundingClientRect().left;
523
-
524
- return (event) => {
525
- this._pageX = getX(event);
526
- let dx = this._pageX - dragOrigin;
527
- let scrollX = parentElement.getBoundingClientRect().left;
528
- let x = elementOrigin + dx + (scrollOrigin - scrollX);
529
-
530
- this._drag(x);
531
- };
532
- }
533
-
534
- if (groupDirection === 'y') {
535
- dragOrigin = getY(startEvent);
536
- elementOrigin = this.y;
537
- scrollOrigin = parentElement.getBoundingClientRect().top;
538
-
539
- return (event) => {
540
- this._pageY = getY(event);
541
- let dy = this._pageY - dragOrigin;
542
- let scrollY = parentElement.getBoundingClientRect().top;
543
- let y = elementOrigin + dy + (scrollOrigin - scrollY);
544
-
545
- this._drag(y);
546
- };
547
- }
548
- }
549
-
550
- /**
551
- @method _scheduleApplyPosition
552
- @private
553
- */
554
- _scheduleApplyPosition() {
555
- scheduleOnce('render', this, '_applyPosition');
556
- }
557
-
558
- /**
559
- @method _applyPosition
560
- @private
561
- */
562
- _applyPosition() {
563
- if (!this.element || !this.element) {
564
- return;
565
- }
566
-
567
- const groupDirection = this.direction;
568
-
569
- if (groupDirection === 'x') {
570
- let x = this.x;
571
- let dx = x - this.element.offsetLeft + parseFloat(getComputedStyle(this.element).marginLeft);
572
-
573
- this.element.style.transform = `translateX(${dx}px)`;
574
- }
575
- if (groupDirection === 'y') {
576
- let y = this.y;
577
- let dy = y - this.element.offsetTop;
578
-
579
- this.element.style.transform = `translateY(${dy}px)`;
580
- }
581
- }
582
-
583
- /**
584
- @method _drag
585
- @private
586
- */
587
- _drag(dimension) {
588
- if (!this.isDragging) {
589
- return;
590
- }
591
- let updateInterval = this.updateInterval;
592
- const groupDirection = this.direction;
593
-
594
- if (groupDirection === 'x') {
595
- this.x = dimension;
596
- }
597
- if (groupDirection === 'y') {
598
- this.y = dimension;
599
- }
600
-
601
- throttle(this, this.sortableGroup.update, updateInterval);
602
- }
603
-
604
- /**
605
- @method _drop
606
- @private
607
- */
608
- _drop() {
609
- if (!this.element) {
610
- return;
611
- }
612
-
613
- let transitionPromise = this._waitForTransition();
614
-
615
- this._preventClick();
616
-
617
- set(this, 'isDragging', false);
618
- set(this, 'isDropping', true);
619
-
620
- this.sortableGroup.update();
621
- transitionPromise.then(() => this._complete());
622
- }
623
-
624
- /**
625
- @method _preventClick
626
- @private
627
- */
628
- _preventClick() {
629
- const selfCancellingCallback = (event) => {
630
- this.element.removeEventListener(ELEMENT_CLICK_ACTION, selfCancellingCallback);
631
- this._preventClickHandler(event);
632
- };
633
-
634
- this.element.addEventListener(ELEMENT_CLICK_ACTION, selfCancellingCallback);
635
- }
636
-
637
- /**
638
- @method _preventClickHandler
639
- @private
640
- */
641
- _preventClickHandler(e) {
642
- e.stopPropagation();
643
- e.preventDefault();
644
- e.stopImmediatePropagation();
645
- }
646
-
647
- /**
648
- @method _waitForTransition
649
- @private
650
- @return Promise
651
- */
652
- _waitForTransition() {
653
- let waiterToken;
654
-
655
- if (DEBUG) {
656
- waiterToken = sortableItemWaiter.beginAsync();
657
- }
658
-
659
- let transitionPromise;
660
-
661
- if (this.isAnimated) {
662
- const deferred = defer();
663
- this.element.addEventListener('transitionend', deferred.resolve);
664
- transitionPromise = deferred.promise.finally(() => {
665
- this.element.removeEventListener('transitionend', deferred.resolve);
666
- });
667
- } else {
668
- const duration = this.isAnimated ? this.transitionDuration : 200;
669
- transitionPromise = new Promise((resolve) => later(resolve, duration));
670
- }
671
-
672
- if (DEBUG) {
673
- transitionPromise = transitionPromise.finally(() => {
674
- sortableItemWaiter.endAsync(waiterToken);
675
- });
676
- }
677
-
678
- return transitionPromise;
679
- }
680
-
681
- /**
682
- @method _complete
683
- @private
684
- */
685
- _complete() {
686
- this.onDragStop(this.model);
687
- set(this, 'isDropping', false);
688
- set(this, 'wasDropped', true);
689
- this.sortableGroup.commit();
690
- }
691
-
692
- get isAnimated() {
693
- if (!this.element) {
694
- return undefined;
695
- }
696
-
697
- let el = this.element;
698
- let transitionProperty = getComputedStyle(el).transitionProperty;
699
-
700
- return /all|transform/.test(transitionProperty) && this.transitionDuration > 0;
701
- }
702
-
703
- /**
704
- The current transition duration in milliseconds.
705
- @property transitionDuration
706
- @type Number
707
- */
708
- get transitionDuration() {
709
- let el = this.element;
710
- let rule = getComputedStyle(el).transitionDuration;
711
- let match = rule.match(/([\d.]+)([ms]*)/);
712
-
713
- if (match) {
714
- let value = parseFloat(match[1]);
715
- let unit = match[2];
716
-
717
- if (unit === 's') {
718
- value = value * 1000;
719
- }
720
-
721
- return value;
722
- }
723
-
724
- return 0;
725
- }
726
-
727
- /**
728
- Horizontal position of the item.
729
- @property x
730
- @type Number
731
- */
732
- get x() {
733
- if (this._x === undefined) {
734
- let marginLeft = parseFloat(getComputedStyle(this.element).marginLeft);
735
- this._x = this.element.scrollLeft + this.element.offsetLeft - marginLeft;
736
- }
737
-
738
- return this._x;
739
- }
740
- set x(value) {
741
- if (value !== this._x) {
742
- this._x = value;
743
- this._scheduleApplyPosition();
744
- }
745
- }
746
-
747
- /**
748
- Vertical position of the item relative to its offset parent.
749
- @property y
750
- @type Number
751
- */
752
- get y() {
753
- if (this._y === undefined) {
754
- this._y = this.element.offsetTop;
755
- }
756
-
757
- return this._y;
758
- }
759
-
760
- set y(value) {
761
- if (value !== this._y) {
762
- this._y = value;
763
- this._scheduleApplyPosition();
764
- }
765
- }
766
-
767
- /**
768
- Width of the item.
769
- @property height
770
- @type Number
771
- */
772
- get width() {
773
- let el = this.element;
774
- let width = el.offsetWidth;
775
- let elStyles = getComputedStyle(el);
776
-
777
- width += parseInt(elStyles.marginLeft) + parseInt(elStyles.marginRight); // equal to jQuery.outerWidth(true)
778
-
779
- width += getBorderSpacing(el).horizontal;
780
-
781
- return width;
782
- }
783
-
784
- /**
785
- Height of the item including margins.
786
- @property height
787
- @type Number
788
- */
789
- get height() {
790
- let el = this.element;
791
- let height = el.offsetHeight;
792
-
793
- let marginBottom = parseFloat(getComputedStyle(el).marginBottom);
794
- height += marginBottom;
795
-
796
- height += getBorderSpacing(el).vertical;
797
-
798
- return height;
799
- }
800
-
801
- addEventListener() {
802
- this.element.addEventListener('keydown', this.keyDown);
803
- this.element.addEventListener('mousedown', this.mouseDown);
804
- this.element.addEventListener('touchstart', this.touchStart);
805
- this.listenersRegistered = true;
806
- }
807
-
808
- removeEventListener() {
809
- this.element.removeEventListener('keydown', this.keyDown);
810
- this.element.removeEventListener('mousedown', this.mouseDown);
811
- this.element.removeEventListener('touchstart', this.touchStart);
812
- this.listenersRegistered = false;
813
- }
814
-
815
- setupHandleElement() {
816
- this.handleElement = this.element.querySelector(this.handle);
817
-
818
- if (this.handleElement) {
819
- this.handleElement.style['touch-action'] = 'none';
820
- } else {
821
- this.element.style['touch-action'] = 'none';
822
- }
823
- }
824
-
825
- element;
826
- didSetup = false;
827
-
828
- /**
829
- * tracks if event listeners have been registered. Registering event handlers is unnecessary if item is disabled.
830
- */
831
- listenersRegistered = false;
832
-
833
- constructor(owner, args) {
834
- super(owner, args);
835
- registerDestructor(this, cleanup);
836
- }
837
-
838
- modify(element, _positional, named) {
839
- this.element = element;
840
- this.named = named;
841
-
842
- this.element.classList.add(this.className);
843
-
844
- // Instead of using `event.preventDefault()` in the 'primeDrag' event,
845
- // (doesn't work in Chrome 56), we set touch-action: none as a workaround.
846
- this.setupHandleElement();
847
-
848
- if (!this.didSetup) {
849
- this.element.dataset.sortableItem = true;
850
- this.sortableService.registerItem(this.groupName, this);
851
- this.didSetup = true;
852
- }
853
-
854
- if (this.named.disabled && this.listenersRegistered) {
855
- this.removeEventListener();
856
- } else if (!this.named.disabled && !this.listenersRegistered) {
857
- this.addEventListener();
858
- }
859
- }
860
- }
861
-
862
- /**
863
- *
864
- * @param {SortableItemModifier} instance
865
- */
866
- function cleanup(instance) {
867
- instance.removeEventListener();
868
- instance.sortableService.deregisterItem(instance.groupName, instance);
869
- }