@limetech/lime-elements 38.31.0 → 38.31.2
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/CHANGELOG.md +16 -0
- package/dist/cjs/lime-elements.cjs.js +1 -1
- package/dist/cjs/limel-action-bar_2.cjs.entry.js +1 -1
- package/dist/cjs/limel-ai-avatar.cjs.entry.js +1 -1
- package/dist/cjs/limel-callout.cjs.entry.js +1 -1
- package/dist/cjs/limel-chart.cjs.entry.js +1 -1
- package/dist/cjs/limel-chip_2.cjs.entry.js +1 -1
- package/dist/cjs/limel-collapsible-section.cjs.entry.js +2 -2
- package/dist/cjs/limel-collapsible-section.cjs.entry.js.map +1 -1
- package/dist/cjs/limel-drag-handle.cjs.entry.js +34 -0
- package/dist/cjs/limel-drag-handle.cjs.entry.js.map +1 -0
- package/dist/cjs/limel-file-viewer.cjs.entry.js +1 -1
- package/dist/cjs/limel-file.cjs.entry.js +1 -1
- package/dist/cjs/limel-flatpickr-adapter.cjs.entry.js +1 -1
- package/dist/cjs/limel-form.cjs.entry.js +3220 -305
- package/dist/cjs/limel-form.cjs.entry.js.map +1 -1
- package/dist/cjs/limel-info-tile.cjs.entry.js +1 -1
- package/dist/cjs/limel-info-tile.cjs.entry.js.map +1 -1
- package/dist/cjs/limel-linear-progress.cjs.entry.js +1 -1
- package/dist/cjs/limel-list-item.cjs.entry.js +1 -1
- package/dist/cjs/limel-profile-picture.cjs.entry.js +1 -1
- package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +1 -1
- package/dist/cjs/limel-snackbar.cjs.entry.js +1 -1
- package/dist/cjs/limel-table.cjs.entry.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{translations-d2be6dd7.js → translations-a42886f2.js} +17 -1
- package/dist/cjs/translations-a42886f2.js.map +1 -0
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/action-bar/action-bar-item/action-bar-item.css +3 -0
- package/dist/collection/components/action-bar/action-bar.css +3 -0
- package/dist/collection/components/badge/badge.css +3 -0
- package/dist/collection/components/breadcrumbs/breadcrumbs.css +3 -0
- package/dist/collection/components/button/button.css +3 -0
- package/dist/collection/components/button-group/button-group.css +3 -0
- package/dist/collection/components/card/card.css +3 -0
- package/dist/collection/components/chart/chart.css +6 -0
- package/dist/collection/components/checkbox/checkbox.css +3 -0
- package/dist/collection/components/chip/chip.css +3 -0
- package/dist/collection/components/chip-set/chip-set.css +6 -0
- package/dist/collection/components/circular-progress/circular-progress.css +3 -0
- package/dist/collection/components/code-editor/code-editor.css +3 -0
- package/dist/collection/components/collapsible-section/collapsible-section.css +17 -8
- package/dist/collection/components/color-picker/color-picker-palette.css +3 -0
- package/dist/collection/components/color-picker/color-picker.css +3 -0
- package/dist/collection/components/date-picker/flatpickr-adapter/flatpickr-adapter.css +3 -0
- package/dist/collection/components/dialog/dialog.css +3 -0
- package/dist/collection/components/dock/dock-button/dock-button.css +3 -0
- package/dist/collection/components/dock/dock.css +3 -0
- package/dist/collection/components/drag-handle/drag-handle.css +174 -0
- package/dist/collection/components/drag-handle/drag-handle.js +125 -0
- package/dist/collection/components/drag-handle/drag-handle.js.map +1 -0
- package/dist/collection/components/file/file.css +3 -0
- package/dist/collection/components/file-viewer/file-viewer.css +3 -0
- package/dist/collection/components/form/form.css +143 -14
- package/dist/collection/components/form/templates/array-field-collapsible-item.js +13 -16
- package/dist/collection/components/form/templates/array-field-collapsible-item.js.map +1 -1
- package/dist/collection/components/form/templates/array-field-simple-item.js +16 -49
- package/dist/collection/components/form/templates/array-field-simple-item.js.map +1 -1
- package/dist/collection/components/form/templates/array-field.js +306 -19
- package/dist/collection/components/form/templates/array-field.js.map +1 -1
- package/dist/collection/components/header/header.css +3 -0
- package/dist/collection/components/help/help.css +3 -0
- package/dist/collection/components/help/limel-help-content.css +3 -0
- package/dist/collection/components/icon-button/icon-button.css +3 -0
- package/dist/collection/components/info-tile/info-tile.css +3 -0
- package/dist/collection/components/input-field/input-field.css +3 -0
- package/dist/collection/components/list/list.css +6 -0
- package/dist/collection/components/list-item/list-item.css +3 -0
- package/dist/collection/components/list-item/menu-item-meta/menu-item-meta.css +3 -0
- package/dist/collection/components/markdown/markdown.css +3 -0
- package/dist/collection/components/menu-list/menu-list.css +6 -0
- package/dist/collection/components/notched-outline/notched-outline.css +3 -0
- package/dist/collection/components/popover-surface/popover-surface.css +3 -0
- package/dist/collection/components/profile-picture/profile-picture.css +3 -0
- package/dist/collection/components/progress-flow/progress-flow-item/progress-flow-item.css +3 -0
- package/dist/collection/components/radio-button-group/radio-button.css +3 -0
- package/dist/collection/components/select/select.css +6 -0
- package/dist/collection/components/shortcut/shortcut.css +3 -0
- package/dist/collection/components/slider/slider.css +3 -0
- package/dist/collection/components/split-button/split-button.css +3 -0
- package/dist/collection/components/switch/switch.css +3 -0
- package/dist/collection/components/tab-bar/tab-bar.css +3 -0
- package/dist/collection/components/table/table.css +12 -0
- package/dist/collection/components/text-editor/prosemirror-adapter/prosemirror-adapter.css +3 -0
- package/dist/collection/components/text-editor/text-editor.css +3 -0
- package/dist/collection/style/mixins.scss +53 -0
- package/dist/collection/translations/da.js +2 -0
- package/dist/collection/translations/da.js.map +1 -1
- package/dist/collection/translations/de.js +2 -0
- package/dist/collection/translations/de.js.map +1 -1
- package/dist/collection/translations/en.js +2 -0
- package/dist/collection/translations/en.js.map +1 -1
- package/dist/collection/translations/fi.js +2 -0
- package/dist/collection/translations/fi.js.map +1 -1
- package/dist/collection/translations/fr.js +2 -0
- package/dist/collection/translations/fr.js.map +1 -1
- package/dist/collection/translations/nl.js +2 -0
- package/dist/collection/translations/nl.js.map +1 -1
- package/dist/collection/translations/no.js +2 -0
- package/dist/collection/translations/no.js.map +1 -1
- package/dist/collection/translations/sv.js +2 -0
- package/dist/collection/translations/sv.js.map +1 -1
- package/dist/esm/lime-elements.js +1 -1
- package/dist/esm/limel-action-bar_2.entry.js +1 -1
- package/dist/esm/limel-ai-avatar.entry.js +1 -1
- package/dist/esm/limel-callout.entry.js +1 -1
- package/dist/esm/limel-chart.entry.js +1 -1
- package/dist/esm/limel-chip_2.entry.js +1 -1
- package/dist/esm/limel-collapsible-section.entry.js +2 -2
- package/dist/esm/limel-collapsible-section.entry.js.map +1 -1
- package/dist/esm/limel-drag-handle.entry.js +30 -0
- package/dist/esm/limel-drag-handle.entry.js.map +1 -0
- package/dist/esm/limel-file-viewer.entry.js +1 -1
- package/dist/esm/limel-file.entry.js +1 -1
- package/dist/esm/limel-flatpickr-adapter.entry.js +1 -1
- package/dist/esm/limel-form.entry.js +3214 -299
- package/dist/esm/limel-form.entry.js.map +1 -1
- package/dist/esm/limel-info-tile.entry.js +1 -1
- package/dist/esm/limel-info-tile.entry.js.map +1 -1
- package/dist/esm/limel-linear-progress.entry.js +1 -1
- package/dist/esm/limel-list-item.entry.js +1 -1
- package/dist/esm/limel-profile-picture.entry.js +1 -1
- package/dist/esm/limel-prosemirror-adapter.entry.js +1 -1
- package/dist/esm/limel-snackbar.entry.js +1 -1
- package/dist/esm/limel-table.entry.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{translations-91c611da.js → translations-9bfde9f4.js} +17 -1
- package/dist/esm/translations-9bfde9f4.js.map +1 -0
- package/dist/lime-elements/lime-elements.esm.js +1 -1
- package/dist/lime-elements/lime-elements.esm.js.map +1 -1
- package/dist/lime-elements/p-309d0652.entry.js +2 -0
- package/dist/lime-elements/{p-e6245ef7.entry.js.map → p-309d0652.entry.js.map} +1 -1
- package/dist/lime-elements/p-31f1cb08.entry.js +2 -0
- package/dist/lime-elements/p-31f1cb08.entry.js.map +1 -0
- package/dist/lime-elements/{p-cc7f4c81.entry.js → p-3311eaf3.entry.js} +2 -2
- package/dist/lime-elements/{p-aeba4aa4.entry.js → p-40542ccc.entry.js} +2 -2
- package/dist/lime-elements/{p-d349e355.entry.js → p-42e889d8.entry.js} +2 -2
- package/dist/lime-elements/p-5df2361b.js +2 -0
- package/dist/lime-elements/p-5df2361b.js.map +1 -0
- package/dist/lime-elements/{p-b5abf284.entry.js → p-5e976a59.entry.js} +2 -2
- package/dist/lime-elements/{p-6c60172e.entry.js → p-787be044.entry.js} +2 -2
- package/dist/lime-elements/p-8ea3b80a.entry.js +2 -0
- package/dist/lime-elements/p-8ea3b80a.entry.js.map +1 -0
- package/dist/lime-elements/{p-d1aa44e1.entry.js → p-92aa9610.entry.js} +2 -2
- package/dist/lime-elements/{p-8e3c4418.entry.js → p-aa1e7319.entry.js} +2 -2
- package/dist/lime-elements/p-ae267255.entry.js +27 -0
- package/dist/lime-elements/p-ae267255.entry.js.map +1 -0
- package/dist/lime-elements/{p-ed04acfc.entry.js → p-b0acf522.entry.js} +2 -2
- package/dist/lime-elements/{p-f83ebd28.entry.js → p-b7bbb6a5.entry.js} +2 -2
- package/dist/lime-elements/{p-eb396630.entry.js → p-cd2f780a.entry.js} +2 -2
- package/dist/lime-elements/{p-aae161ef.entry.js → p-d79c85e2.entry.js} +2 -2
- package/dist/lime-elements/{p-1b036add.entry.js → p-e00465fa.entry.js} +2 -2
- package/dist/lime-elements/{p-29c2cdc6.entry.js → p-ee5c4112.entry.js} +2 -2
- package/dist/lime-elements/{p-e6bb4d1a.entry.js → p-fbac230b.entry.js} +2 -2
- package/dist/lime-elements/style/mixins.scss +53 -0
- package/dist/scss/mixins.scss +53 -0
- package/dist/types/components/drag-handle/drag-handle.d.ts +46 -0
- package/dist/types/components/form/templates/array-field-collapsible-item.d.ts +3 -1
- package/dist/types/components/form/templates/array-field-simple-item.d.ts +5 -9
- package/dist/types/components/form/templates/array-field.d.ts +35 -4
- package/dist/types/components.d.ts +113 -0
- package/dist/types/translations/da.d.ts +2 -0
- package/dist/types/translations/de.d.ts +2 -0
- package/dist/types/translations/en.d.ts +2 -0
- package/dist/types/translations/fi.d.ts +2 -0
- package/dist/types/translations/fr.d.ts +2 -0
- package/dist/types/translations/nl.d.ts +2 -0
- package/dist/types/translations/no.d.ts +2 -0
- package/dist/types/translations/sv.d.ts +2 -0
- package/package.json +5 -2
- package/dist/cjs/translations-d2be6dd7.js.map +0 -1
- package/dist/esm/translations-91c611da.js.map +0 -1
- package/dist/lime-elements/p-4c88e5d3.js +0 -2
- package/dist/lime-elements/p-4c88e5d3.js.map +0 -1
- package/dist/lime-elements/p-d6d66daa.entry.js +0 -21
- package/dist/lime-elements/p-d6d66daa.entry.js.map +0 -1
- package/dist/lime-elements/p-e6245ef7.entry.js +0 -2
- package/dist/lime-elements/p-ed8aa16c.entry.js +0 -2
- package/dist/lime-elements/p-ed8aa16c.entry.js.map +0 -1
- /package/dist/lime-elements/{p-cc7f4c81.entry.js.map → p-3311eaf3.entry.js.map} +0 -0
- /package/dist/lime-elements/{p-aeba4aa4.entry.js.map → p-40542ccc.entry.js.map} +0 -0
- /package/dist/lime-elements/{p-d349e355.entry.js.map → p-42e889d8.entry.js.map} +0 -0
- /package/dist/lime-elements/{p-b5abf284.entry.js.map → p-5e976a59.entry.js.map} +0 -0
- /package/dist/lime-elements/{p-6c60172e.entry.js.map → p-787be044.entry.js.map} +0 -0
- /package/dist/lime-elements/{p-d1aa44e1.entry.js.map → p-92aa9610.entry.js.map} +0 -0
- /package/dist/lime-elements/{p-8e3c4418.entry.js.map → p-aa1e7319.entry.js.map} +0 -0
- /package/dist/lime-elements/{p-ed04acfc.entry.js.map → p-b0acf522.entry.js.map} +0 -0
- /package/dist/lime-elements/{p-f83ebd28.entry.js.map → p-b7bbb6a5.entry.js.map} +0 -0
- /package/dist/lime-elements/{p-eb396630.entry.js.map → p-cd2f780a.entry.js.map} +0 -0
- /package/dist/lime-elements/{p-aae161ef.entry.js.map → p-d79c85e2.entry.js.map} +0 -0
- /package/dist/lime-elements/{p-1b036add.entry.js.map → p-e00465fa.entry.js.map} +0 -0
- /package/dist/lime-elements/{p-29c2cdc6.entry.js.map → p-ee5c4112.entry.js.map} +0 -0
- /package/dist/lime-elements/{p-e6bb4d1a.entry.js.map → p-fbac230b.entry.js.map} +0 -0
|
@@ -3,15 +3,128 @@ import { isObjectType } from '../schema';
|
|
|
3
3
|
import { CollapsibleItemTemplate } from './array-field-collapsible-item';
|
|
4
4
|
import { SimpleItemTemplate } from './array-field-simple-item';
|
|
5
5
|
import { renderDescription, renderTitle } from './common';
|
|
6
|
+
import Sortable from 'sortablejs';
|
|
7
|
+
const DRAG_HANDLE_SELECTOR = '[data-drag-handle]';
|
|
8
|
+
const DRAGGABLE_ITEM_SELECTOR = '.array-item[data-reorderable="true"]';
|
|
9
|
+
const DEFAULT_CONTAINER_CLASS = 'has-an-item-which-is-being-dragged';
|
|
10
|
+
const DEFAULT_DROP_ELEVATION_CLASS = 'is-elevated';
|
|
11
|
+
const DROP_ELEVATION_DURATION = 1000;
|
|
12
|
+
const TOUCH_DRAG_DELAY_MS = 200; // Adds a short hold on touch (long-press) so scroll gestures do not reorder items.
|
|
6
13
|
export class ArrayFieldTemplate extends React.Component {
|
|
7
14
|
constructor(props) {
|
|
8
15
|
super(props);
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
|
|
16
|
+
this.itemByIndex = new Map();
|
|
17
|
+
this.handleAddClick = (event) => {
|
|
18
|
+
event.stopPropagation();
|
|
19
|
+
this.props.onAddClick(event);
|
|
20
|
+
};
|
|
21
|
+
this.setContainer = (element) => {
|
|
22
|
+
if (this.container === element) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this.teardownDragController();
|
|
26
|
+
this.container = element !== null && element !== void 0 ? element : undefined;
|
|
27
|
+
this.setupDragController();
|
|
28
|
+
};
|
|
29
|
+
this.handleSortStart = (event) => {
|
|
30
|
+
if (!this.canReorderItems()) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
this.dragSnapshot = [...this.state.order];
|
|
34
|
+
this.draggedItemIndex = this.getReorderId(event.item);
|
|
35
|
+
if (this.container) {
|
|
36
|
+
this.container.classList.add(DEFAULT_CONTAINER_CLASS);
|
|
37
|
+
}
|
|
38
|
+
if (event.item instanceof HTMLElement) {
|
|
39
|
+
this.applyDropElevation(event.item);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
this.handleSortEnd = (event) => {
|
|
43
|
+
var _a;
|
|
44
|
+
if (!this.canReorderItems()) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (this.container) {
|
|
48
|
+
this.container.classList.remove(DEFAULT_CONTAINER_CLASS);
|
|
49
|
+
}
|
|
50
|
+
const snapshot = this.dragSnapshot;
|
|
51
|
+
const draggedItemIndex = this.draggedItemIndex;
|
|
52
|
+
this.dragSnapshot = undefined;
|
|
53
|
+
this.draggedItemIndex = undefined;
|
|
54
|
+
if (event.item instanceof HTMLElement) {
|
|
55
|
+
this.dropElevationTarget = event.item;
|
|
56
|
+
}
|
|
57
|
+
const finalOrder = this.readOrderFromDom();
|
|
58
|
+
if (!this.arraysEqual(this.state.order, finalOrder)) {
|
|
59
|
+
this.setState({ order: finalOrder });
|
|
60
|
+
}
|
|
61
|
+
if (snapshot === undefined ||
|
|
62
|
+
draggedItemIndex === undefined ||
|
|
63
|
+
!(event.item instanceof HTMLElement)) {
|
|
64
|
+
this.scheduleDropElevationRemoval();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const fromPosition = snapshot.indexOf(draggedItemIndex);
|
|
68
|
+
const toPosition = finalOrder.indexOf(draggedItemIndex);
|
|
69
|
+
if (fromPosition === -1 ||
|
|
70
|
+
toPosition === -1 ||
|
|
71
|
+
fromPosition === toPosition) {
|
|
72
|
+
this.scheduleDropElevationRemoval();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const targetItem = ((_a = this.props.items) !== null && _a !== void 0 ? _a : []).find((entry) => {
|
|
76
|
+
var _a;
|
|
77
|
+
return ((_a = entry.index) !== null && _a !== void 0 ? _a : -1) === draggedItemIndex;
|
|
78
|
+
});
|
|
79
|
+
if (!targetItem || typeof targetItem.onReorderClick !== 'function') {
|
|
80
|
+
this.scheduleDropElevationRemoval();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
requestAnimationFrame(() => {
|
|
84
|
+
const reorder = targetItem.onReorderClick(draggedItemIndex, toPosition);
|
|
85
|
+
if (typeof reorder === 'function') {
|
|
86
|
+
reorder();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
this.scheduleDropElevationRemoval();
|
|
90
|
+
};
|
|
91
|
+
this.state = {
|
|
92
|
+
order: this.extractIndices(props.items),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
componentWillUnmount() {
|
|
96
|
+
this.teardownDragController();
|
|
97
|
+
}
|
|
98
|
+
componentDidMount() {
|
|
99
|
+
this.setupDragController();
|
|
100
|
+
}
|
|
101
|
+
componentDidUpdate(previousProps) {
|
|
102
|
+
if (previousProps.items !== this.props.items) {
|
|
103
|
+
const nextOrder = this.extractIndices(this.props.items);
|
|
104
|
+
if (!this.arraysEqual(this.state.order, nextOrder)) {
|
|
105
|
+
this.setState({
|
|
106
|
+
order: nextOrder,
|
|
107
|
+
}, () => {
|
|
108
|
+
this.setupDragController();
|
|
109
|
+
});
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (previousProps.items !== this.props.items ||
|
|
114
|
+
previousProps.schema !== this.props.schema ||
|
|
115
|
+
previousProps.disabled !== this.props.disabled ||
|
|
116
|
+
previousProps.readonly !== this.props.readonly) {
|
|
117
|
+
this.setupDragController();
|
|
118
|
+
}
|
|
12
119
|
}
|
|
13
120
|
render() {
|
|
14
|
-
|
|
121
|
+
const controls = this.getItemControls();
|
|
122
|
+
const { ordered: orderedItems, byIndex } = this.getOrderedItems();
|
|
123
|
+
this.itemByIndex = byIndex;
|
|
124
|
+
return React.createElement('div', {}, renderTitle(this.props.title), renderDescription(this.props.schema.description), React.createElement('div', {
|
|
125
|
+
className: 'array-items',
|
|
126
|
+
ref: this.setContainer,
|
|
127
|
+
}, orderedItems.map((item, index) => this.renderItem(item, index, controls))), this.renderAddButton());
|
|
15
128
|
}
|
|
16
129
|
renderAddButton() {
|
|
17
130
|
if (!this.props.canAdd) {
|
|
@@ -24,40 +137,214 @@ export class ArrayFieldTemplate extends React.Component {
|
|
|
24
137
|
class: 'button-add-new',
|
|
25
138
|
});
|
|
26
139
|
}
|
|
27
|
-
|
|
140
|
+
getItemControls() {
|
|
141
|
+
return {
|
|
142
|
+
allowItemRemoval: this.canRemoveItems(),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
renderItem(item, index, controls) {
|
|
146
|
+
var _a;
|
|
28
147
|
const { schema, formData, formContext } = this.props;
|
|
29
|
-
const
|
|
148
|
+
const itemIndex = (_a = item.index) !== null && _a !== void 0 ? _a : index;
|
|
149
|
+
const allowItemReorder = this.isItemReorderable(item);
|
|
30
150
|
if (isObjectType(schema.items)) {
|
|
31
151
|
return React.createElement(CollapsibleItemTemplate, {
|
|
32
152
|
key: item.key,
|
|
33
153
|
item: item,
|
|
34
|
-
data: formData[
|
|
154
|
+
data: Array.isArray(formData) ? formData[itemIndex] : undefined,
|
|
35
155
|
schema: schema,
|
|
36
156
|
formSchema: formContext.schema,
|
|
37
|
-
index:
|
|
157
|
+
index: itemIndex,
|
|
38
158
|
allowItemRemoval: controls.allowItemRemoval,
|
|
39
|
-
allowItemReorder:
|
|
159
|
+
allowItemReorder: allowItemReorder,
|
|
40
160
|
});
|
|
41
161
|
}
|
|
42
162
|
return React.createElement(SimpleItemTemplate, {
|
|
43
163
|
key: item.key,
|
|
44
164
|
item: item,
|
|
45
|
-
index:
|
|
165
|
+
index: itemIndex,
|
|
166
|
+
dataIndex: itemIndex,
|
|
46
167
|
allowItemRemoval: controls.allowItemRemoval,
|
|
47
|
-
allowItemReorder:
|
|
168
|
+
allowItemReorder: allowItemReorder,
|
|
48
169
|
});
|
|
49
170
|
}
|
|
50
|
-
|
|
51
|
-
var _a;
|
|
52
|
-
const
|
|
171
|
+
getOrderedItems() {
|
|
172
|
+
var _a, _b;
|
|
173
|
+
const items = (_a = this.props.items) !== null && _a !== void 0 ? _a : [];
|
|
174
|
+
const byIndex = new Map();
|
|
175
|
+
let entryIndex = 0;
|
|
176
|
+
for (const entry of items) {
|
|
177
|
+
byIndex.set((_b = entry.index) !== null && _b !== void 0 ? _b : entryIndex, entry);
|
|
178
|
+
entryIndex += 1;
|
|
179
|
+
}
|
|
180
|
+
const ordered = [];
|
|
181
|
+
const used = new Set();
|
|
182
|
+
for (const index of this.state.order) {
|
|
183
|
+
const entry = byIndex.get(index);
|
|
184
|
+
if (!entry) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
ordered.push(entry);
|
|
188
|
+
used.add(index);
|
|
189
|
+
}
|
|
190
|
+
for (const [index, entry] of byIndex.entries()) {
|
|
191
|
+
if (!used.has(index)) {
|
|
192
|
+
ordered.push(entry);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
53
195
|
return {
|
|
54
|
-
|
|
55
|
-
|
|
196
|
+
ordered,
|
|
197
|
+
byIndex,
|
|
56
198
|
};
|
|
57
199
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
200
|
+
setupDragController() {
|
|
201
|
+
if (!this.container || !this.canReorderItems()) {
|
|
202
|
+
this.teardownDragController();
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const reorderableCount = this.getReorderableOrder().length;
|
|
206
|
+
if (reorderableCount < 2) {
|
|
207
|
+
this.teardownDragController();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (this.sortable) {
|
|
211
|
+
this.sortable.option('handle', DRAG_HANDLE_SELECTOR);
|
|
212
|
+
this.sortable.option('draggable', DRAGGABLE_ITEM_SELECTOR);
|
|
213
|
+
this.sortable.option('disabled', false);
|
|
214
|
+
this.sortable.option('delay', TOUCH_DRAG_DELAY_MS);
|
|
215
|
+
this.sortable.option('delayOnTouchOnly', true);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
this.sortable = Sortable.create(this.container, {
|
|
219
|
+
animation: 150,
|
|
220
|
+
handle: DRAG_HANDLE_SELECTOR,
|
|
221
|
+
draggable: DRAGGABLE_ITEM_SELECTOR,
|
|
222
|
+
delay: TOUCH_DRAG_DELAY_MS,
|
|
223
|
+
delayOnTouchOnly: true,
|
|
224
|
+
onStart: this.handleSortStart,
|
|
225
|
+
onEnd: this.handleSortEnd,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
teardownDragController() {
|
|
229
|
+
if (this.sortable) {
|
|
230
|
+
this.sortable.destroy();
|
|
231
|
+
this.sortable = undefined;
|
|
232
|
+
}
|
|
233
|
+
this.clearDropElevationTimer();
|
|
234
|
+
if (this.dropElevationTarget) {
|
|
235
|
+
this.dropElevationTarget.classList.remove(DEFAULT_DROP_ELEVATION_CLASS);
|
|
236
|
+
this.dropElevationTarget = undefined;
|
|
237
|
+
}
|
|
238
|
+
if (this.container) {
|
|
239
|
+
this.container.classList.remove(DEFAULT_CONTAINER_CLASS);
|
|
240
|
+
}
|
|
241
|
+
this.dragSnapshot = undefined;
|
|
242
|
+
this.draggedItemIndex = undefined;
|
|
243
|
+
}
|
|
244
|
+
canReorderItems() {
|
|
245
|
+
if (this.props.disabled || this.props.readonly) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
const schema = this.props.schema;
|
|
249
|
+
const limeOptions = (schema === null || schema === void 0 ? void 0 : schema.lime) || {};
|
|
250
|
+
return limeOptions.allowItemReorder !== false;
|
|
251
|
+
}
|
|
252
|
+
canRemoveItems() {
|
|
253
|
+
const schema = this.props.schema;
|
|
254
|
+
const limeOptions = (schema === null || schema === void 0 ? void 0 : schema.lime) || {};
|
|
255
|
+
return limeOptions.allowItemRemoval !== false;
|
|
256
|
+
}
|
|
257
|
+
isItemReorderable(item) {
|
|
258
|
+
return (this.canReorderItems() &&
|
|
259
|
+
Boolean((item === null || item === void 0 ? void 0 : item.hasMoveDown) || (item === null || item === void 0 ? void 0 : item.hasMoveUp)));
|
|
260
|
+
}
|
|
261
|
+
isIndexReorderable(index) {
|
|
262
|
+
const item = this.itemByIndex.get(index);
|
|
263
|
+
if (!item) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
return this.isItemReorderable(item);
|
|
267
|
+
}
|
|
268
|
+
getReorderableOrder(order = this.state.order) {
|
|
269
|
+
const result = [];
|
|
270
|
+
for (const index of order) {
|
|
271
|
+
if (this.isIndexReorderable(index)) {
|
|
272
|
+
result.push(index);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
readOrderFromDom() {
|
|
278
|
+
if (!this.container) {
|
|
279
|
+
return [];
|
|
280
|
+
}
|
|
281
|
+
const items = [...this.container.querySelectorAll('.array-item')];
|
|
282
|
+
const order = [];
|
|
283
|
+
for (const element of items) {
|
|
284
|
+
const index = this.getReorderId(element);
|
|
285
|
+
if (index !== undefined) {
|
|
286
|
+
order.push(index);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return order;
|
|
290
|
+
}
|
|
291
|
+
getReorderId(element) {
|
|
292
|
+
if (!element) {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
if (!(element instanceof HTMLElement)) {
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
const value = element.dataset.reorderId;
|
|
299
|
+
if (value === undefined) {
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
const parsed = Number.parseInt(value, 10);
|
|
303
|
+
return Number.isNaN(parsed) ? undefined : parsed;
|
|
304
|
+
}
|
|
305
|
+
applyDropElevation(item) {
|
|
306
|
+
if (this.dropElevationTarget && this.dropElevationTarget !== item) {
|
|
307
|
+
this.dropElevationTarget.classList.remove(DEFAULT_DROP_ELEVATION_CLASS);
|
|
308
|
+
}
|
|
309
|
+
this.clearDropElevationTimer();
|
|
310
|
+
item.classList.add(DEFAULT_DROP_ELEVATION_CLASS);
|
|
311
|
+
this.dropElevationTarget = item;
|
|
312
|
+
}
|
|
313
|
+
scheduleDropElevationRemoval() {
|
|
314
|
+
if (!this.dropElevationTarget) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const target = this.dropElevationTarget;
|
|
318
|
+
this.clearDropElevationTimer();
|
|
319
|
+
this.dropElevationTimeout = globalThis.setTimeout(() => {
|
|
320
|
+
target.classList.remove(DEFAULT_DROP_ELEVATION_CLASS);
|
|
321
|
+
if (this.dropElevationTarget === target) {
|
|
322
|
+
this.dropElevationTarget = undefined;
|
|
323
|
+
}
|
|
324
|
+
this.dropElevationTimeout = undefined;
|
|
325
|
+
}, DROP_ELEVATION_DURATION);
|
|
326
|
+
}
|
|
327
|
+
clearDropElevationTimer() {
|
|
328
|
+
if (this.dropElevationTimeout !== undefined) {
|
|
329
|
+
clearTimeout(this.dropElevationTimeout);
|
|
330
|
+
this.dropElevationTimeout = undefined;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
arraysEqual(a, b) {
|
|
334
|
+
if (a.length !== b.length) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
let index = 0;
|
|
338
|
+
for (const value of a) {
|
|
339
|
+
if (value !== b[index]) {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
index += 1;
|
|
343
|
+
}
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
extractIndices(items = []) {
|
|
347
|
+
return (items !== null && items !== void 0 ? items : []).map((item, index) => { var _a; return (_a = item.index) !== null && _a !== void 0 ? _a : index; });
|
|
61
348
|
}
|
|
62
349
|
}
|
|
63
350
|
//# sourceMappingURL=array-field.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-field.js","sourceRoot":"","sources":["../../../../src/components/form/templates/array-field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAA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C,IAAI,YAAY,CAAC,MAAM,CAAC,KAAmB,CAAC,EAAE;MAC1C,OAAO,KAAK,CAAC,aAAa,CAAC,uBAAuB,EAAE;QAChD,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC;QACrB,MAAM,EAAE,MAAM;QACd,UAAU,EAAE,WAAW,CAAC,MAAM;QAC9B,KAAK,EAAE,KAAK;QACZ,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;QAC3C,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;OAC9C,CAAC,CAAC;KACN;IAED,OAAO,KAAK,CAAC,aAAa,CAAC,kBAAkB,EAAE;MAC3C,GAAG,EAAE,IAAI,CAAC,GAAG;MACb,IAAI,EAAE,IAAI;MACV,KAAK,EAAE,KAAK;MACZ,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;MAC3C,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;KAC9C,CAAC,CAAC;EACP,CAAC;EAEO,eAAe;;IACnB,MAAM,WAAW,GAAG,CAAA,MAAA,IAAI,CAAC,KAAK,CAAC,MAAM,0CAAE,IAAI,KAAI,EAAE,CAAC;IAElD,OAAO;MACH,gBAAgB,EAAE,WAAW,CAAC,gBAAgB,KAAK,KAAK;MACxD,gBAAgB,EAAE,WAAW,CAAC,gBAAgB,KAAK,KAAK;KAC3D,CAAC;EACN,CAAC;EAEO,cAAc,CAAC,KAAiB;IACpC,KAAK,CAAC,eAAe,EAAE,CAAC;IACxB,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;EACjC,CAAC;CACJ","sourcesContent":["import React from 'react';\nimport { isObjectType } from '../schema';\nimport { CollapsibleItemTemplate } from './array-field-collapsible-item';\nimport { SimpleItemTemplate } from './array-field-simple-item';\nimport { renderDescription, renderTitle } from './common';\nimport { ArrayFieldItem, ArrayFieldTemplateProps } from './types';\nimport { FormSchema } from '../form.types';\n\ninterface ArrayItemControls {\n allowItemRemoval: boolean;\n allowItemReorder: boolean;\n}\n\nexport class ArrayFieldTemplate extends React.Component {\n constructor(public props: ArrayFieldTemplateProps) {\n super(props);\n this.renderItem = this.renderItem.bind(this);\n this.handleAddClick = this.handleAddClick.bind(this);\n }\n\n public render() {\n return React.createElement(\n 'div',\n {},\n renderTitle(this.props.title),\n renderDescription(this.props.schema.description),\n this.props.items.map(this.renderItem),\n this.renderAddButton()\n );\n }\n\n private renderAddButton() {\n if (!this.props.canAdd) {\n return;\n }\n\n return React.createElement('limel-button', {\n label: this.props.title || 'Add',\n onClick: this.handleAddClick,\n icon: 'plus_math',\n class: 'button-add-new',\n });\n }\n\n private renderItem(item: ArrayFieldItem, index: number) {\n const { schema, formData, formContext } = this.props;\n const controls = this.getItemControls();\n\n if (isObjectType(schema.items as FormSchema)) {\n return React.createElement(CollapsibleItemTemplate, {\n key: item.key,\n item: item,\n data: formData[index],\n schema: schema,\n formSchema: formContext.schema,\n index: index,\n allowItemRemoval: controls.allowItemRemoval,\n allowItemReorder: controls.allowItemReorder,\n });\n }\n\n return React.createElement(SimpleItemTemplate, {\n key: item.key,\n item: item,\n index: index,\n allowItemRemoval: controls.allowItemRemoval,\n allowItemReorder: controls.allowItemReorder,\n });\n }\n\n private getItemControls(): ArrayItemControls {\n const limeOptions = this.props.schema?.lime || {};\n\n return {\n allowItemRemoval: limeOptions.allowItemRemoval !== false,\n allowItemReorder: limeOptions.allowItemReorder !== false,\n };\n }\n\n private handleAddClick(event: MouseEvent) {\n event.stopPropagation();\n this.props.onAddClick(event);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"array-field.js","sourceRoot":"","sources":["../../../../src/components/form/templates/array-field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,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,CAAC,oBAAoB,GAAG,SAAS,CAAC;KACzC;EACL,CAAC;EAEO,WAAW,CAAC,CAAW,EAAE,CAAW;IACxC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE;MACvB,OAAO,KAAK,CAAC;KAChB;IAED,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,KAAK,IAAI,CAAC,EAAE;MACnB,IAAI,KAAK,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE;QACpB,OAAO,KAAK,CAAC;OAChB;MACD,KAAK,IAAI,CAAC,CAAC;KACd;IAED,OAAO,IAAI,CAAC;EAChB,CAAC;EAEO,cAAc,CAAC,QAA0B,EAAE;IAC/C,OAAO,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,WAAC,OAAA,MAAA,IAAI,CAAC,KAAK,mCAAI,KAAK,CAAA,EAAA,CAAC,CAAC;EACnE,CAAC;CACJ","sourcesContent":["import React from 'react';\nimport { isObjectType } from '../schema';\nimport { CollapsibleItemTemplate } from './array-field-collapsible-item';\nimport { SimpleItemTemplate } from './array-field-simple-item';\nimport { renderDescription, renderTitle } from './common';\nimport { ArrayFieldItem, ArrayFieldTemplateProps } from './types';\nimport { FormSchema } from '../form.types';\nimport Sortable, { SortableEvent } from 'sortablejs';\n\ninterface ArrayItemControls {\n allowItemRemoval: boolean;\n}\n\ninterface ArrayFieldTemplateState {\n order: number[];\n}\n\nconst DRAG_HANDLE_SELECTOR = '[data-drag-handle]';\nconst DRAGGABLE_ITEM_SELECTOR = '.array-item[data-reorderable=\"true\"]';\nconst DEFAULT_CONTAINER_CLASS = 'has-an-item-which-is-being-dragged';\nconst DEFAULT_DROP_ELEVATION_CLASS = 'is-elevated';\nconst DROP_ELEVATION_DURATION = 1000;\nconst TOUCH_DRAG_DELAY_MS = 200; // Adds a short hold on touch (long-press) so scroll gestures do not reorder items.\n\nexport class ArrayFieldTemplate extends React.Component<\n ArrayFieldTemplateProps,\n ArrayFieldTemplateState\n> {\n private container?: HTMLDivElement;\n private sortable?: Sortable;\n private dragSnapshot?: number[];\n private draggedItemIndex?: number;\n private dropElevationTimeout?: ReturnType<typeof setTimeout>;\n private dropElevationTarget?: HTMLElement;\n private itemByIndex: Map<number, ArrayFieldItem> = new Map();\n\n public constructor(props: ArrayFieldTemplateProps) {\n super(props);\n\n this.state = {\n order: this.extractIndices(props.items),\n };\n }\n\n public componentWillUnmount() {\n this.teardownDragController();\n }\n\n public componentDidMount() {\n this.setupDragController();\n }\n\n public componentDidUpdate(previousProps: ArrayFieldTemplateProps) {\n if (previousProps.items !== this.props.items) {\n const nextOrder = this.extractIndices(this.props.items);\n\n if (!this.arraysEqual(this.state.order, nextOrder)) {\n this.setState(\n {\n order: nextOrder,\n },\n () => {\n this.setupDragController();\n }\n );\n return;\n }\n }\n\n if (\n previousProps.items !== this.props.items ||\n previousProps.schema !== this.props.schema ||\n previousProps.disabled !== this.props.disabled ||\n previousProps.readonly !== this.props.readonly\n ) {\n this.setupDragController();\n }\n }\n\n public render() {\n const controls = this.getItemControls();\n const { ordered: orderedItems, byIndex } = this.getOrderedItems();\n this.itemByIndex = byIndex;\n\n return React.createElement(\n 'div',\n {},\n renderTitle(this.props.title),\n renderDescription(this.props.schema.description),\n React.createElement(\n 'div',\n {\n className: 'array-items',\n ref: this.setContainer,\n },\n orderedItems.map((item, index) =>\n this.renderItem(item, index, controls)\n )\n ),\n this.renderAddButton()\n );\n }\n\n private renderAddButton() {\n if (!this.props.canAdd) {\n return;\n }\n\n return React.createElement('limel-button', {\n label: this.props.title || 'Add',\n onClick: this.handleAddClick,\n icon: 'plus_math',\n class: 'button-add-new',\n });\n }\n\n private getItemControls(): ArrayItemControls {\n return {\n allowItemRemoval: this.canRemoveItems(),\n };\n }\n\n private readonly handleAddClick = (event: MouseEvent) => {\n event.stopPropagation();\n this.props.onAddClick(event);\n };\n\n private renderItem(\n item: ArrayFieldItem,\n index: number,\n controls: ArrayItemControls\n ) {\n const { schema, formData, formContext } = this.props;\n const itemIndex = item.index ?? index;\n const allowItemReorder = this.isItemReorderable(item);\n\n if (isObjectType(schema.items as FormSchema)) {\n return React.createElement(CollapsibleItemTemplate, {\n key: item.key,\n item: item,\n data: Array.isArray(formData) ? formData[itemIndex] : undefined,\n schema: schema,\n formSchema: formContext.schema,\n index: itemIndex,\n allowItemRemoval: controls.allowItemRemoval,\n allowItemReorder: allowItemReorder,\n });\n }\n\n return React.createElement(SimpleItemTemplate, {\n key: item.key,\n item: item,\n index: itemIndex,\n dataIndex: itemIndex,\n allowItemRemoval: controls.allowItemRemoval,\n allowItemReorder: allowItemReorder,\n });\n }\n\n private readonly setContainer = (element: HTMLDivElement | null) => {\n if (this.container === element) {\n return;\n }\n\n this.teardownDragController();\n this.container = element ?? undefined;\n this.setupDragController();\n };\n\n private getOrderedItems(): {\n ordered: ArrayFieldItem[];\n byIndex: Map<number, ArrayFieldItem>;\n } {\n const items = this.props.items ?? [];\n const byIndex = new Map<number, ArrayFieldItem>();\n\n let entryIndex = 0;\n for (const entry of items) {\n byIndex.set(entry.index ?? entryIndex, entry);\n entryIndex += 1;\n }\n\n const ordered: ArrayFieldItem[] = [];\n const used = new Set<number>();\n\n for (const index of this.state.order) {\n const entry = byIndex.get(index);\n if (!entry) {\n continue;\n }\n\n ordered.push(entry);\n used.add(index);\n }\n\n for (const [index, entry] of byIndex.entries()) {\n if (!used.has(index)) {\n ordered.push(entry);\n }\n }\n\n return {\n ordered,\n byIndex,\n };\n }\n\n private readonly handleSortStart = (event: SortableEvent) => {\n if (!this.canReorderItems()) {\n return;\n }\n\n this.dragSnapshot = [...this.state.order];\n this.draggedItemIndex = this.getReorderId(event.item);\n\n if (this.container) {\n this.container.classList.add(DEFAULT_CONTAINER_CLASS);\n }\n\n if (event.item instanceof HTMLElement) {\n this.applyDropElevation(event.item);\n }\n };\n\n private readonly handleSortEnd = (event: SortableEvent) => {\n if (!this.canReorderItems()) {\n return;\n }\n\n if (this.container) {\n this.container.classList.remove(DEFAULT_CONTAINER_CLASS);\n }\n\n const snapshot = this.dragSnapshot;\n const draggedItemIndex = this.draggedItemIndex;\n this.dragSnapshot = undefined;\n this.draggedItemIndex = undefined;\n\n if (event.item instanceof HTMLElement) {\n this.dropElevationTarget = event.item;\n }\n\n const finalOrder = this.readOrderFromDom();\n\n if (!this.arraysEqual(this.state.order, finalOrder)) {\n this.setState({ order: finalOrder });\n }\n\n if (\n snapshot === undefined ||\n draggedItemIndex === undefined ||\n !(event.item instanceof HTMLElement)\n ) {\n this.scheduleDropElevationRemoval();\n return;\n }\n\n const fromPosition = snapshot.indexOf(draggedItemIndex);\n const toPosition = finalOrder.indexOf(draggedItemIndex);\n\n if (\n fromPosition === -1 ||\n toPosition === -1 ||\n fromPosition === toPosition\n ) {\n this.scheduleDropElevationRemoval();\n return;\n }\n\n const targetItem = (this.props.items ?? []).find((entry) => {\n return (entry.index ?? -1) === draggedItemIndex;\n });\n\n if (!targetItem || typeof targetItem.onReorderClick !== 'function') {\n this.scheduleDropElevationRemoval();\n return;\n }\n\n requestAnimationFrame(() => {\n const reorder = targetItem.onReorderClick(\n draggedItemIndex,\n toPosition\n );\n\n if (typeof reorder === 'function') {\n reorder();\n }\n });\n\n this.scheduleDropElevationRemoval();\n };\n\n private setupDragController() {\n if (!this.container || !this.canReorderItems()) {\n this.teardownDragController();\n return;\n }\n\n const reorderableCount = this.getReorderableOrder().length;\n if (reorderableCount < 2) {\n this.teardownDragController();\n return;\n }\n\n if (this.sortable) {\n this.sortable.option('handle', DRAG_HANDLE_SELECTOR);\n this.sortable.option('draggable', DRAGGABLE_ITEM_SELECTOR);\n this.sortable.option('disabled', false);\n this.sortable.option('delay', TOUCH_DRAG_DELAY_MS);\n this.sortable.option('delayOnTouchOnly', true);\n return;\n }\n\n this.sortable = Sortable.create(this.container, {\n animation: 150,\n handle: DRAG_HANDLE_SELECTOR,\n draggable: DRAGGABLE_ITEM_SELECTOR,\n delay: TOUCH_DRAG_DELAY_MS,\n delayOnTouchOnly: true,\n onStart: this.handleSortStart,\n onEnd: this.handleSortEnd,\n });\n }\n\n private teardownDragController() {\n if (this.sortable) {\n this.sortable.destroy();\n this.sortable = undefined;\n }\n\n this.clearDropElevationTimer();\n\n if (this.dropElevationTarget) {\n this.dropElevationTarget.classList.remove(\n DEFAULT_DROP_ELEVATION_CLASS\n );\n this.dropElevationTarget = undefined;\n }\n\n if (this.container) {\n this.container.classList.remove(DEFAULT_CONTAINER_CLASS);\n }\n\n this.dragSnapshot = undefined;\n this.draggedItemIndex = undefined;\n }\n\n private canReorderItems(): boolean {\n if (this.props.disabled || this.props.readonly) {\n return false;\n }\n\n const schema = this.props.schema as FormSchema;\n const limeOptions = schema?.lime || {};\n\n return limeOptions.allowItemReorder !== false;\n }\n\n private canRemoveItems(): boolean {\n const schema = this.props.schema as FormSchema;\n const limeOptions = schema?.lime || {};\n\n return limeOptions.allowItemRemoval !== false;\n }\n\n private isItemReorderable(item: ArrayFieldItem): boolean {\n return (\n this.canReorderItems() &&\n Boolean(item?.hasMoveDown || item?.hasMoveUp)\n );\n }\n\n private isIndexReorderable(index: number): boolean {\n const item = this.itemByIndex.get(index);\n\n if (!item) {\n return false;\n }\n\n return this.isItemReorderable(item);\n }\n\n private getReorderableOrder(order: number[] = this.state.order): number[] {\n const result: number[] = [];\n\n for (const index of order) {\n if (this.isIndexReorderable(index)) {\n result.push(index);\n }\n }\n\n return result;\n }\n\n private readOrderFromDom(): number[] {\n if (!this.container) {\n return [];\n }\n\n const items = [...this.container.querySelectorAll('.array-item')];\n\n const order: number[] = [];\n\n for (const element of items) {\n const index = this.getReorderId(element);\n if (index !== undefined) {\n order.push(index);\n }\n }\n\n return order;\n }\n\n private getReorderId(element: Element | null): number | undefined {\n if (!element) {\n return undefined;\n }\n\n if (!(element instanceof HTMLElement)) {\n return undefined;\n }\n\n const value = element.dataset.reorderId;\n if (value === undefined) {\n return undefined;\n }\n\n const parsed = Number.parseInt(value, 10);\n return Number.isNaN(parsed) ? undefined : parsed;\n }\n\n private applyDropElevation(item: HTMLElement) {\n if (this.dropElevationTarget && this.dropElevationTarget !== item) {\n this.dropElevationTarget.classList.remove(\n DEFAULT_DROP_ELEVATION_CLASS\n );\n }\n\n this.clearDropElevationTimer();\n item.classList.add(DEFAULT_DROP_ELEVATION_CLASS);\n this.dropElevationTarget = item;\n }\n\n private scheduleDropElevationRemoval() {\n if (!this.dropElevationTarget) {\n return;\n }\n\n const target = this.dropElevationTarget;\n this.clearDropElevationTimer();\n this.dropElevationTimeout = globalThis.setTimeout(() => {\n target.classList.remove(DEFAULT_DROP_ELEVATION_CLASS);\n if (this.dropElevationTarget === target) {\n this.dropElevationTarget = undefined;\n }\n this.dropElevationTimeout = undefined;\n }, DROP_ELEVATION_DURATION);\n }\n\n private clearDropElevationTimer() {\n if (this.dropElevationTimeout !== undefined) {\n clearTimeout(this.dropElevationTimeout);\n this.dropElevationTimeout = undefined;\n }\n }\n\n private arraysEqual(a: number[], b: number[]): boolean {\n if (a.length !== b.length) {\n return false;\n }\n\n let index = 0;\n for (const value of a) {\n if (value !== b[index]) {\n return false;\n }\n index += 1;\n }\n\n return true;\n }\n\n private extractIndices(items: ArrayFieldItem[] = []): number[] {\n return (items ?? []).map((item, index) => item.index ?? index);\n }\n}\n"]}
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -73,6 +73,9 @@
|
|
|
73
73
|
* of some components, to demonstrate how the component
|
|
74
74
|
* behaves in a resizable container.
|
|
75
75
|
*/
|
|
76
|
+
/**
|
|
77
|
+
* Drag to reorder mixins
|
|
78
|
+
*/
|
|
76
79
|
/**
|
|
77
80
|
* The breakpoints below are used to create responsive designs
|
|
78
81
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -208,6 +211,9 @@ ul {
|
|
|
208
211
|
* of some components, to demonstrate how the component
|
|
209
212
|
* behaves in a resizable container.
|
|
210
213
|
*/
|
|
214
|
+
/**
|
|
215
|
+
* Drag to reorder mixins
|
|
216
|
+
*/
|
|
211
217
|
/**
|
|
212
218
|
* The breakpoints below are used to create responsive designs
|
|
213
219
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -208,6 +211,9 @@ ul {
|
|
|
208
211
|
* of some components, to demonstrate how the component
|
|
209
212
|
* behaves in a resizable container.
|
|
210
213
|
*/
|
|
214
|
+
/**
|
|
215
|
+
* Drag to reorder mixins
|
|
216
|
+
*/
|
|
211
217
|
/**
|
|
212
218
|
* The breakpoints below are used to create responsive designs
|
|
213
219
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -73,6 +73,9 @@
|
|
|
73
73
|
* of some components, to demonstrate how the component
|
|
74
74
|
* behaves in a resizable container.
|
|
75
75
|
*/
|
|
76
|
+
/**
|
|
77
|
+
* Drag to reorder mixins
|
|
78
|
+
*/
|
|
76
79
|
/**
|
|
77
80
|
* The breakpoints below are used to create responsive designs
|
|
78
81
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -73,6 +73,9 @@
|
|
|
73
73
|
* of some components, to demonstrate how the component
|
|
74
74
|
* behaves in a resizable container.
|
|
75
75
|
*/
|
|
76
|
+
/**
|
|
77
|
+
* Drag to reorder mixins
|
|
78
|
+
*/
|
|
76
79
|
/**
|
|
77
80
|
* The breakpoints below are used to create responsive designs
|
|
78
81
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -1820,6 +1823,9 @@ select.limel-select__native-control {
|
|
|
1820
1823
|
* of some components, to demonstrate how the component
|
|
1821
1824
|
* behaves in a resizable container.
|
|
1822
1825
|
*/
|
|
1826
|
+
/**
|
|
1827
|
+
* Drag to reorder mixins
|
|
1828
|
+
*/
|
|
1823
1829
|
/**
|
|
1824
1830
|
* The breakpoints below are used to create responsive designs
|
|
1825
1831
|
* in Lime's products. Therefore, they are here to get distributed
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
* of some components, to demonstrate how the component
|
|
68
68
|
* behaves in a resizable container.
|
|
69
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Drag to reorder mixins
|
|
72
|
+
*/
|
|
70
73
|
/**
|
|
71
74
|
* The breakpoints below are used to create responsive designs
|
|
72
75
|
* in Lime's products. Therefore, they are here to get distributed
|