tosijs-ui 1.0.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 +165 -0
- package/dist/ab-test.d.ts +14 -0
- package/dist/ab-test.js +116 -0
- package/dist/babylon-3d.d.ts +53 -0
- package/dist/babylon-3d.js +292 -0
- package/dist/bodymovin-player.d.ts +32 -0
- package/dist/bodymovin-player.js +172 -0
- package/dist/bp-loader.d.ts +1 -0
- package/dist/bp-loader.js +26 -0
- package/dist/carousel.d.ts +113 -0
- package/dist/carousel.js +308 -0
- package/dist/code-editor.d.ts +27 -0
- package/dist/code-editor.js +102 -0
- package/dist/color-input.d.ts +41 -0
- package/dist/color-input.js +112 -0
- package/dist/data-table.d.ts +79 -0
- package/dist/data-table.js +774 -0
- package/dist/drag-and-drop.d.ts +2 -0
- package/dist/drag-and-drop.js +386 -0
- package/dist/editable-rect.d.ts +97 -0
- package/dist/editable-rect.js +450 -0
- package/dist/filter-builder.d.ts +64 -0
- package/dist/filter-builder.js +468 -0
- package/dist/float.d.ts +18 -0
- package/dist/float.js +170 -0
- package/dist/form.d.ts +68 -0
- package/dist/form.js +466 -0
- package/dist/gamepad.d.ts +34 -0
- package/dist/gamepad.js +115 -0
- package/dist/icon-data.d.ts +312 -0
- package/dist/icon-data.js +308 -0
- package/dist/icon-types.d.ts +7 -0
- package/dist/icon-types.js +1 -0
- package/dist/icons.d.ts +17 -0
- package/dist/icons.js +374 -0
- package/dist/iife.js +69 -0
- package/dist/iife.js.map +49 -0
- package/dist/index-iife.d.ts +1 -0
- package/dist/index-iife.js +4 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +47 -0
- package/dist/live-example.d.ts +63 -0
- package/dist/live-example.js +611 -0
- package/dist/localize.d.ts +46 -0
- package/dist/localize.js +381 -0
- package/dist/make-sorter.d.ts +3 -0
- package/dist/make-sorter.js +119 -0
- package/dist/make-sorter.test.d.ts +1 -0
- package/dist/make-sorter.test.js +48 -0
- package/dist/mapbox.d.ts +24 -0
- package/dist/mapbox.js +161 -0
- package/dist/markdown-viewer.d.ts +17 -0
- package/dist/markdown-viewer.js +173 -0
- package/dist/match-shortcut.d.ts +9 -0
- package/dist/match-shortcut.js +13 -0
- package/dist/match-shortcut.test.d.ts +1 -0
- package/dist/match-shortcut.test.js +194 -0
- package/dist/menu.d.ts +60 -0
- package/dist/menu.js +614 -0
- package/dist/notifications.d.ts +106 -0
- package/dist/notifications.js +308 -0
- package/dist/password-strength.d.ts +35 -0
- package/dist/password-strength.js +302 -0
- package/dist/playwright.config.d.ts +9 -0
- package/dist/playwright.config.js +73 -0
- package/dist/pop-float.d.ts +10 -0
- package/dist/pop-float.js +231 -0
- package/dist/rating.d.ts +62 -0
- package/dist/rating.js +192 -0
- package/dist/rich-text.d.ts +35 -0
- package/dist/rich-text.js +296 -0
- package/dist/segmented.d.ts +80 -0
- package/dist/segmented.js +298 -0
- package/dist/select.d.ts +43 -0
- package/dist/select.js +427 -0
- package/dist/side-nav.d.ts +36 -0
- package/dist/side-nav.js +106 -0
- package/dist/size-break.d.ts +18 -0
- package/dist/size-break.js +118 -0
- package/dist/sizer.d.ts +34 -0
- package/dist/sizer.js +92 -0
- package/dist/src/ab-test.d.ts +14 -0
- package/dist/src/babylon-3d.d.ts +53 -0
- package/dist/src/bodymovin-player.d.ts +32 -0
- package/dist/src/bp-loader.d.ts +0 -0
- package/dist/src/carousel.d.ts +113 -0
- package/dist/src/code-editor.d.ts +27 -0
- package/dist/src/color-input.d.ts +41 -0
- package/dist/src/data-table.d.ts +79 -0
- package/dist/src/drag-and-drop.d.ts +2 -0
- package/dist/src/editable-rect.d.ts +97 -0
- package/dist/src/filter-builder.d.ts +64 -0
- package/dist/src/float.d.ts +18 -0
- package/dist/src/form.d.ts +68 -0
- package/dist/src/gamepad.d.ts +34 -0
- package/dist/src/icon-data.d.ts +309 -0
- package/dist/src/icon-types.d.ts +7 -0
- package/dist/src/icons.d.ts +17 -0
- package/dist/src/index.d.ts +37 -0
- package/dist/src/live-example.d.ts +51 -0
- package/dist/src/localize.d.ts +30 -0
- package/dist/src/make-sorter.d.ts +3 -0
- package/dist/src/mapbox.d.ts +24 -0
- package/dist/src/markdown-viewer.d.ts +15 -0
- package/dist/src/match-shortcut.d.ts +9 -0
- package/dist/src/menu.d.ts +60 -0
- package/dist/src/notifications.d.ts +106 -0
- package/dist/src/password-strength.d.ts +35 -0
- package/dist/src/pop-float.d.ts +10 -0
- package/dist/src/rating.d.ts +62 -0
- package/dist/src/rich-text.d.ts +28 -0
- package/dist/src/segmented.d.ts +80 -0
- package/dist/src/select.d.ts +43 -0
- package/dist/src/side-nav.d.ts +36 -0
- package/dist/src/size-break.d.ts +18 -0
- package/dist/src/sizer.d.ts +34 -0
- package/dist/src/tab-selector.d.ts +91 -0
- package/dist/src/tag-list.d.ts +37 -0
- package/dist/src/track-drag.d.ts +5 -0
- package/dist/src/version.d.ts +1 -0
- package/dist/src/via-tag.d.ts +2 -0
- package/dist/tab-selector.d.ts +91 -0
- package/dist/tab-selector.js +326 -0
- package/dist/tag-list.d.ts +37 -0
- package/dist/tag-list.js +375 -0
- package/dist/track-drag.d.ts +5 -0
- package/dist/track-drag.js +143 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/dist/via-tag.d.ts +2 -0
- package/dist/via-tag.js +102 -0
- package/package.json +58 -0
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
/*#
|
|
2
|
+
# editable-rect
|
|
3
|
+
|
|
4
|
+
`<xin-editable>` (`editableRect` is the `ElementCreator` and `EditableRect` is the class) is an element
|
|
5
|
+
for allowing the adjustment of another element's position and size. Simply insert it in a `position: absolute`
|
|
6
|
+
or `position: fixed` element and you can directly adjust its CSS positioning, including rotation.
|
|
7
|
+
|
|
8
|
+
Click on an element to adjust its position, dimensions, and rotation.
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
const { editableRect, icons } = xinjsui
|
|
12
|
+
const { elements } = xinjs
|
|
13
|
+
const { button } = elements
|
|
14
|
+
|
|
15
|
+
function showTools(event) {
|
|
16
|
+
event.stopPropagation()
|
|
17
|
+
event.preventDefault()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const editable = editableRect(button({class: 'more-popup', onClick: showTools}, icons.moreVertical()))
|
|
21
|
+
preview.addEventListener('click', (event) => {
|
|
22
|
+
const target = event.target
|
|
23
|
+
if (['absolute', 'fixed'].includes(getComputedStyle(target).position)) {
|
|
24
|
+
target.append(editable)
|
|
25
|
+
} else {
|
|
26
|
+
editable.remove()
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
preview.addEventListener('change', event => console.log(event))
|
|
30
|
+
```
|
|
31
|
+
```html
|
|
32
|
+
<div class="editable" style="top: 20px; left: 20px; width: auto; height: auto; right: 20px; bottom: 20px;">
|
|
33
|
+
<div class="editable" style="top: 20px; left: 20px; width: 200px; height: 150px;">
|
|
34
|
+
</div>
|
|
35
|
+
<div class="editable" style="bottom: 20px; top: 20px; width: 300px; height: auto; right: 20px;">
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
```
|
|
39
|
+
```css
|
|
40
|
+
.preview .editable {
|
|
41
|
+
position: absolute;
|
|
42
|
+
box-shadow: inset 0 0 0 1px #0ccc;
|
|
43
|
+
background: #0cc1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.preview button.more-popup {
|
|
47
|
+
position: absolute;
|
|
48
|
+
width: 44px;
|
|
49
|
+
height: 44px;
|
|
50
|
+
top: 2px;
|
|
51
|
+
right: 2px;
|
|
52
|
+
--text-color: black;
|
|
53
|
+
background: transparent;
|
|
54
|
+
box-shadow: none;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.previw button
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Snapping
|
|
61
|
+
|
|
62
|
+
When `EditableRect.snapToGrid === true` or the shift-key is depresseed, position will snap to `EditableRect.gridSize` pixels (default = 8).
|
|
63
|
+
|
|
64
|
+
Similarly `EditableRect.snapAngle === true` or the shift-key will snap rotation to increments of `EditableRect.angleSize` degrees (default = 15).
|
|
65
|
+
|
|
66
|
+
## Events
|
|
67
|
+
|
|
68
|
+
After an element's position, size, or rotation are adjusted a `change` event is triggered on the element.
|
|
69
|
+
*/
|
|
70
|
+
import { Component, elements, vars } from 'xinjs';
|
|
71
|
+
import { icons } from './icons';
|
|
72
|
+
import { trackDrag } from './track-drag';
|
|
73
|
+
const { div, slot } = elements;
|
|
74
|
+
export class EditableRect extends Component {
|
|
75
|
+
static angleSize = 15;
|
|
76
|
+
static gridSize = 8;
|
|
77
|
+
static snapAngle = false;
|
|
78
|
+
static snapToGrid = false;
|
|
79
|
+
static styleSpec = {
|
|
80
|
+
':host': {
|
|
81
|
+
'--handle-bg': '#fff4',
|
|
82
|
+
'--handle-color': '#2228',
|
|
83
|
+
'--handle-hover-bg': '#8ff8',
|
|
84
|
+
'--handle-hover-color': '#222',
|
|
85
|
+
'--handle-size': '20px',
|
|
86
|
+
'--handle-padding': '2px',
|
|
87
|
+
},
|
|
88
|
+
':host ::slotted(*)': {
|
|
89
|
+
position: 'absolute',
|
|
90
|
+
},
|
|
91
|
+
':host > :not(style,slot)': {
|
|
92
|
+
boxSizing: 'border-box',
|
|
93
|
+
content: '" "',
|
|
94
|
+
position: 'absolute',
|
|
95
|
+
display: 'flex',
|
|
96
|
+
height: vars.handleSize,
|
|
97
|
+
width: vars.handleSize,
|
|
98
|
+
padding: vars.handlePadding,
|
|
99
|
+
'--text-color': vars.handleColor,
|
|
100
|
+
background: vars.handleBg,
|
|
101
|
+
},
|
|
102
|
+
':host > .drag-size': {
|
|
103
|
+
top: 0,
|
|
104
|
+
bottom: 0,
|
|
105
|
+
left: 0,
|
|
106
|
+
right: 0,
|
|
107
|
+
height: 'auto',
|
|
108
|
+
width: 'auto',
|
|
109
|
+
background: 'transparent',
|
|
110
|
+
cursor: 'ew-resize',
|
|
111
|
+
},
|
|
112
|
+
':host > [part="rotate"]': {
|
|
113
|
+
transform: `translateY(${vars.handleSize_50})`,
|
|
114
|
+
},
|
|
115
|
+
':host > [locked] > svg:first-child, :host > :not([locked]) > svg+svg': {
|
|
116
|
+
display: 'none',
|
|
117
|
+
},
|
|
118
|
+
':host .icon-unlock': {
|
|
119
|
+
opacity: 0.5,
|
|
120
|
+
},
|
|
121
|
+
':host svg': {
|
|
122
|
+
pointerEvents: 'none',
|
|
123
|
+
},
|
|
124
|
+
':host > *:hover': {
|
|
125
|
+
'--text-color': vars.handleHoverColor,
|
|
126
|
+
background: vars.handleHoverBg,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
static snappedCoords(event, coords) {
|
|
130
|
+
const { gridSize } = EditableRect;
|
|
131
|
+
return EditableRect.snapToGrid || event.shiftKey
|
|
132
|
+
? coords.map((v) => Math.round(v / gridSize) * gridSize)
|
|
133
|
+
: coords;
|
|
134
|
+
}
|
|
135
|
+
static snappedAngle(event, a) {
|
|
136
|
+
const { angleSize } = EditableRect;
|
|
137
|
+
return EditableRect.snapAngle || event.shiftKey
|
|
138
|
+
? Math.round(a / angleSize) * angleSize
|
|
139
|
+
: a;
|
|
140
|
+
}
|
|
141
|
+
get locked() {
|
|
142
|
+
const element = this.parentElement;
|
|
143
|
+
if (element.style.inset) {
|
|
144
|
+
return { left: true, top: true, bottom: true, right: true };
|
|
145
|
+
}
|
|
146
|
+
const right = element.style.right.match(/\d/) !== null;
|
|
147
|
+
const left = !right || element.style.left.match(/\d/) !== null;
|
|
148
|
+
const bottom = element.style.bottom.match(/\d/) !== null;
|
|
149
|
+
const top = !bottom || element.style.top.match(/\d/) !== null;
|
|
150
|
+
return { left, top, bottom, right };
|
|
151
|
+
}
|
|
152
|
+
set locked(locks) {
|
|
153
|
+
const { bottom, right } = locks;
|
|
154
|
+
let { left, top } = locks;
|
|
155
|
+
const element = this.parentElement;
|
|
156
|
+
const l = element.offsetLeft;
|
|
157
|
+
const t = element.offsetTop;
|
|
158
|
+
const w = element.offsetWidth;
|
|
159
|
+
const h = element.offsetHeight;
|
|
160
|
+
const r = element.offsetParent.offsetWidth - l - w;
|
|
161
|
+
const b = element.offsetParent.offsetHeight - t - h;
|
|
162
|
+
Object.assign(element.style, {
|
|
163
|
+
left: '',
|
|
164
|
+
right: '',
|
|
165
|
+
top: '',
|
|
166
|
+
bottom: '',
|
|
167
|
+
width: '',
|
|
168
|
+
height: '',
|
|
169
|
+
});
|
|
170
|
+
if (!right)
|
|
171
|
+
left = true;
|
|
172
|
+
if (!bottom)
|
|
173
|
+
top = true;
|
|
174
|
+
if (left)
|
|
175
|
+
element.style.left = l + 'px';
|
|
176
|
+
if (right)
|
|
177
|
+
element.style.right = r + 'px';
|
|
178
|
+
if (left && right) {
|
|
179
|
+
element.style.width = 'auto';
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
element.style.width = w + 'px';
|
|
183
|
+
}
|
|
184
|
+
if (top)
|
|
185
|
+
element.style.top = t + 'px';
|
|
186
|
+
if (bottom)
|
|
187
|
+
element.style.bottom = b + 'px';
|
|
188
|
+
if (top && bottom) {
|
|
189
|
+
element.style.height = 'auto';
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
element.style.height = h + 'px';
|
|
193
|
+
}
|
|
194
|
+
this.queueRender();
|
|
195
|
+
}
|
|
196
|
+
get coords() {
|
|
197
|
+
const { top, left, right, bottom } = this.parentElement.style;
|
|
198
|
+
return {
|
|
199
|
+
top: parseFloat(top),
|
|
200
|
+
left: parseFloat(left),
|
|
201
|
+
right: parseFloat(right),
|
|
202
|
+
bottom: parseFloat(bottom),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
get left() {
|
|
206
|
+
return this.parentElement.offsetLeft;
|
|
207
|
+
}
|
|
208
|
+
get width() {
|
|
209
|
+
return this.parentElement.offsetWidth;
|
|
210
|
+
}
|
|
211
|
+
get right() {
|
|
212
|
+
return (this.parentElement.offsetParent.offsetWidth -
|
|
213
|
+
(this.left + this.width));
|
|
214
|
+
}
|
|
215
|
+
get top() {
|
|
216
|
+
return this.parentElement.offsetTop;
|
|
217
|
+
}
|
|
218
|
+
get height() {
|
|
219
|
+
return this.parentElement.offsetHeight;
|
|
220
|
+
}
|
|
221
|
+
get bottom() {
|
|
222
|
+
return (this.parentElement.offsetParent.offsetHeight -
|
|
223
|
+
(this.top + this.height));
|
|
224
|
+
}
|
|
225
|
+
triggerChange = () => {
|
|
226
|
+
this.parentElement.dispatchEvent(new Event('change', {
|
|
227
|
+
bubbles: true,
|
|
228
|
+
composed: true,
|
|
229
|
+
}));
|
|
230
|
+
};
|
|
231
|
+
adjustPosition = (event) => {
|
|
232
|
+
// this means there will be some positioning coordinate set!
|
|
233
|
+
const { locked } = this;
|
|
234
|
+
this.locked = locked;
|
|
235
|
+
const target = this.parentElement;
|
|
236
|
+
const { top, left, bottom, right } = this.coords;
|
|
237
|
+
trackDrag(event, (dx, dy, dragEvent) => {
|
|
238
|
+
;
|
|
239
|
+
[dx, dy] = EditableRect.snappedCoords(dragEvent, [dx, dy]);
|
|
240
|
+
if (!isNaN(top)) {
|
|
241
|
+
target.style.top = top + dy + 'px';
|
|
242
|
+
}
|
|
243
|
+
if (!isNaN(bottom)) {
|
|
244
|
+
target.style.bottom = bottom - dy + 'px';
|
|
245
|
+
}
|
|
246
|
+
if (!isNaN(left)) {
|
|
247
|
+
target.style.left = left + dx + 'px';
|
|
248
|
+
}
|
|
249
|
+
if (!isNaN(right)) {
|
|
250
|
+
target.style.right = right - dx + 'px';
|
|
251
|
+
}
|
|
252
|
+
if (dragEvent.type === 'mouseup') {
|
|
253
|
+
this.triggerChange();
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
resize = (event) => {
|
|
259
|
+
const target = this.parentElement;
|
|
260
|
+
const { locked } = this;
|
|
261
|
+
this.locked = Object.assign({
|
|
262
|
+
left: true,
|
|
263
|
+
top: true,
|
|
264
|
+
right: true,
|
|
265
|
+
bottom: true,
|
|
266
|
+
});
|
|
267
|
+
const [right, bottom] = [this.right, this.bottom];
|
|
268
|
+
trackDrag(event, (dx, dy, dragEvent) => {
|
|
269
|
+
let r = right - dx;
|
|
270
|
+
let b = bottom - dy;
|
|
271
|
+
[r, b] = EditableRect.snappedCoords(dragEvent, [r, b]);
|
|
272
|
+
target.style.right = r + 'px';
|
|
273
|
+
target.style.bottom = b + 'px';
|
|
274
|
+
if (dragEvent.type === 'mouseup') {
|
|
275
|
+
this.locked = locked;
|
|
276
|
+
this.triggerChange();
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
adjustSize = (event) => {
|
|
282
|
+
const target = this.parentElement;
|
|
283
|
+
const { locked } = this;
|
|
284
|
+
const dimension = event.target.getAttribute('part');
|
|
285
|
+
this.locked = Object.assign({
|
|
286
|
+
left: true,
|
|
287
|
+
right: true,
|
|
288
|
+
top: true,
|
|
289
|
+
bottom: true,
|
|
290
|
+
});
|
|
291
|
+
const original = this[dimension];
|
|
292
|
+
trackDrag(event, (dx, dy, dragEvent) => {
|
|
293
|
+
const [adjusted] = EditableRect.snappedCoords(dragEvent, [
|
|
294
|
+
original +
|
|
295
|
+
(['left', 'right'].includes(dimension) ? dx : dy) *
|
|
296
|
+
(['right', 'bottom'].includes(dimension) ? -1 : 1),
|
|
297
|
+
]);
|
|
298
|
+
target.style[dimension] = adjusted + 'px';
|
|
299
|
+
if (dragEvent.type === 'mouseup') {
|
|
300
|
+
this.locked = locked;
|
|
301
|
+
this.triggerChange();
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
get rect() {
|
|
307
|
+
return this.parentElement.getBoundingClientRect();
|
|
308
|
+
}
|
|
309
|
+
get center() {
|
|
310
|
+
const rect = this.parentElement.getBoundingClientRect();
|
|
311
|
+
return {
|
|
312
|
+
x: rect.x + rect.width * 0.5,
|
|
313
|
+
y: rect.y + rect.height * 0.5,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
get element() {
|
|
317
|
+
return this.parentElement;
|
|
318
|
+
}
|
|
319
|
+
adjustRotation = (event) => {
|
|
320
|
+
const { center } = this;
|
|
321
|
+
const { transformOrigin } = this.element.style;
|
|
322
|
+
if (!transformOrigin) {
|
|
323
|
+
this.element.style.transformOrigin = '50% 50%';
|
|
324
|
+
}
|
|
325
|
+
trackDrag(event, (_dx, _dy, dragEvent) => {
|
|
326
|
+
const { clientX, clientY } = dragEvent;
|
|
327
|
+
const x = clientX - center.x;
|
|
328
|
+
const y = clientY - center.y;
|
|
329
|
+
let alpha = y > 0 ? 90 : -90;
|
|
330
|
+
if (x !== 0) {
|
|
331
|
+
alpha = (Math.atan2(y, x) * 180) / Math.PI;
|
|
332
|
+
}
|
|
333
|
+
alpha = EditableRect.snappedAngle(dragEvent, alpha);
|
|
334
|
+
if (alpha === 0) {
|
|
335
|
+
this.element.style.transformOrigin = '';
|
|
336
|
+
this.element.style.transform = '';
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
this.element.style.transform = `rotate(${alpha}deg)`;
|
|
340
|
+
}
|
|
341
|
+
this.triggerChange();
|
|
342
|
+
return dragEvent.type === 'mouseup';
|
|
343
|
+
});
|
|
344
|
+
};
|
|
345
|
+
toggleLock = (event) => {
|
|
346
|
+
const { locked } = this;
|
|
347
|
+
const which = event.target.title.split(' ')[1];
|
|
348
|
+
locked[which] = !locked[which];
|
|
349
|
+
this.locked = locked;
|
|
350
|
+
this.queueRender();
|
|
351
|
+
event.stopPropagation();
|
|
352
|
+
event.preventDefault();
|
|
353
|
+
};
|
|
354
|
+
content = () => [
|
|
355
|
+
div({
|
|
356
|
+
part: 'move',
|
|
357
|
+
style: { top: '50%', left: '50%', transform: 'translate(-50%,-50%)' },
|
|
358
|
+
}, icons.move()),
|
|
359
|
+
div({
|
|
360
|
+
part: 'left',
|
|
361
|
+
title: 'resize left',
|
|
362
|
+
class: 'drag-size',
|
|
363
|
+
style: { left: '-6px', width: '8px' },
|
|
364
|
+
}),
|
|
365
|
+
div({
|
|
366
|
+
part: 'right',
|
|
367
|
+
title: 'resize right',
|
|
368
|
+
class: 'drag-size',
|
|
369
|
+
style: { left: 'calc(100% - 2px)', width: '8px' },
|
|
370
|
+
}),
|
|
371
|
+
div({
|
|
372
|
+
part: 'top',
|
|
373
|
+
title: 'resize top',
|
|
374
|
+
class: 'drag-size',
|
|
375
|
+
style: { top: '-6px', height: '8px', cursor: 'ns-resize' },
|
|
376
|
+
}),
|
|
377
|
+
div({
|
|
378
|
+
part: 'bottom',
|
|
379
|
+
title: 'resize bottom',
|
|
380
|
+
class: 'drag-size',
|
|
381
|
+
style: { top: 'calc(100% - 2px)', height: '8px', cursor: 'ns-resize' },
|
|
382
|
+
}),
|
|
383
|
+
div({
|
|
384
|
+
part: 'resize',
|
|
385
|
+
style: { top: '100%', left: '100%' },
|
|
386
|
+
}, icons.resize()),
|
|
387
|
+
div({
|
|
388
|
+
part: 'rotate',
|
|
389
|
+
style: { top: '50%', right: '0' },
|
|
390
|
+
}, icons.refreshCw()),
|
|
391
|
+
div({
|
|
392
|
+
part: 'lockLeft',
|
|
393
|
+
title: 'lock left',
|
|
394
|
+
style: { top: '50%', left: 0, transform: 'translate(-100%, -50%)' },
|
|
395
|
+
}, icons.unlock(), icons.lock()),
|
|
396
|
+
div({
|
|
397
|
+
part: 'lockRight',
|
|
398
|
+
title: 'lock right',
|
|
399
|
+
style: { top: '50%', left: '100%', transform: 'translate(0%, -50%)' },
|
|
400
|
+
}, icons.unlock(), icons.lock()),
|
|
401
|
+
div({
|
|
402
|
+
part: 'lockTop',
|
|
403
|
+
title: 'lock top',
|
|
404
|
+
style: { top: 0, left: '50%', transform: 'translate(-50%, -100%)' },
|
|
405
|
+
}, icons.unlock(), icons.lock()),
|
|
406
|
+
div({
|
|
407
|
+
part: 'lockBottom',
|
|
408
|
+
title: 'lock bottom',
|
|
409
|
+
style: { top: '100%', left: '50%', transform: 'translate(-50%, 0%)' },
|
|
410
|
+
}, icons.unlock(), icons.lock()),
|
|
411
|
+
slot(),
|
|
412
|
+
];
|
|
413
|
+
constructor() {
|
|
414
|
+
super();
|
|
415
|
+
this.initAttributes('rotationSnap', 'positionSnap');
|
|
416
|
+
}
|
|
417
|
+
connectedCallback() {
|
|
418
|
+
super.connectedCallback();
|
|
419
|
+
const { left, right, top, bottom, lockLeft, lockRight, lockTop, lockBottom, move, resize, rotate, } = this.parts;
|
|
420
|
+
const PASSIVE = { passive: true };
|
|
421
|
+
[left, right, top, bottom].forEach((elt) => {
|
|
422
|
+
elt.addEventListener('mousedown', this.adjustSize, PASSIVE);
|
|
423
|
+
elt.addEventListener('touchstart', this.adjustSize, PASSIVE);
|
|
424
|
+
});
|
|
425
|
+
[lockLeft, lockRight, lockTop, lockBottom].forEach((elt) => {
|
|
426
|
+
elt.addEventListener('click', this.toggleLock);
|
|
427
|
+
});
|
|
428
|
+
resize.addEventListener('mousedown', this.resize, PASSIVE);
|
|
429
|
+
move.addEventListener('mousedown', this.adjustPosition, PASSIVE);
|
|
430
|
+
rotate.addEventListener('mousedown', this.adjustRotation, PASSIVE);
|
|
431
|
+
resize.addEventListener('touchstart', this.resize, PASSIVE);
|
|
432
|
+
move.addEventListener('touchstart', this.adjustPosition, PASSIVE);
|
|
433
|
+
rotate.addEventListener('touchstart', this.adjustRotation, PASSIVE);
|
|
434
|
+
}
|
|
435
|
+
render() {
|
|
436
|
+
super.render();
|
|
437
|
+
if (!this.parentElement) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
const { lockLeft, lockRight, lockTop, lockBottom } = this.parts;
|
|
441
|
+
const { left, right, top, bottom } = this.locked;
|
|
442
|
+
lockLeft.toggleAttribute('locked', left);
|
|
443
|
+
lockRight.toggleAttribute('locked', right);
|
|
444
|
+
lockTop.toggleAttribute('locked', top);
|
|
445
|
+
lockBottom.toggleAttribute('locked', bottom);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
export const editableRect = EditableRect.elementCreator({
|
|
449
|
+
tag: 'xin-editable',
|
|
450
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Component as WebComponent, ElementCreator } from 'tosijs';
|
|
2
|
+
type ObjectTest = (obj: any) => boolean;
|
|
3
|
+
type ArrayFilter = (array: any[]) => any[];
|
|
4
|
+
interface FilterMaker {
|
|
5
|
+
caption: string;
|
|
6
|
+
negative?: string;
|
|
7
|
+
needsValue?: boolean;
|
|
8
|
+
makeTest: (value: any) => ObjectTest;
|
|
9
|
+
}
|
|
10
|
+
export declare const availableFilters: {
|
|
11
|
+
[key: string]: FilterMaker;
|
|
12
|
+
};
|
|
13
|
+
interface Filter {
|
|
14
|
+
description: string;
|
|
15
|
+
test: ObjectTest;
|
|
16
|
+
}
|
|
17
|
+
type Fields = Array<{
|
|
18
|
+
name?: string;
|
|
19
|
+
prop: string;
|
|
20
|
+
}>;
|
|
21
|
+
export interface FilterPartState {
|
|
22
|
+
haystack: string;
|
|
23
|
+
condition: string;
|
|
24
|
+
needle: string;
|
|
25
|
+
}
|
|
26
|
+
export declare class FilterPart extends WebComponent {
|
|
27
|
+
fields: Fields;
|
|
28
|
+
filters: {
|
|
29
|
+
[key: string]: FilterMaker;
|
|
30
|
+
};
|
|
31
|
+
haystack: string;
|
|
32
|
+
condition: string;
|
|
33
|
+
needle: string;
|
|
34
|
+
content: () => (SVGElement | HTMLSpanElement)[];
|
|
35
|
+
filter: Filter;
|
|
36
|
+
constructor();
|
|
37
|
+
get state(): FilterPartState;
|
|
38
|
+
set state(newState: FilterPartState);
|
|
39
|
+
buildFilter: () => void;
|
|
40
|
+
connectedCallback(): void;
|
|
41
|
+
render(): void;
|
|
42
|
+
}
|
|
43
|
+
export declare const filterPart: ElementCreator<FilterPart>;
|
|
44
|
+
export type FilterState = FilterPartState[];
|
|
45
|
+
export declare class FilterBuilder extends WebComponent {
|
|
46
|
+
private _fields;
|
|
47
|
+
get fields(): Fields;
|
|
48
|
+
set fields(_fields: Fields);
|
|
49
|
+
get state(): FilterState;
|
|
50
|
+
set state(parts: FilterState);
|
|
51
|
+
filter: ArrayFilter;
|
|
52
|
+
description: string;
|
|
53
|
+
addFilter: () => void;
|
|
54
|
+
content: () => (HTMLButtonElement | HTMLDivElement)[];
|
|
55
|
+
filters: {
|
|
56
|
+
[key: string]: FilterMaker;
|
|
57
|
+
};
|
|
58
|
+
reset: () => void;
|
|
59
|
+
buildFilter: () => void;
|
|
60
|
+
connectedCallback(): void;
|
|
61
|
+
render(): void;
|
|
62
|
+
}
|
|
63
|
+
export declare const filterBuilder: ElementCreator<FilterBuilder>;
|
|
64
|
+
export {};
|