tosijs-ui 1.0.0 → 1.0.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.
Files changed (94) hide show
  1. package/README.md +4 -2
  2. package/dist/iife.js +70 -60
  3. package/dist/iife.js.map +42 -42
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +15 -37
  6. package/dist/index.js.map +39 -39
  7. package/dist/version.d.ts +1 -1
  8. package/package.json +2 -2
  9. package/dist/ab-test.js +0 -116
  10. package/dist/babylon-3d.js +0 -292
  11. package/dist/bodymovin-player.js +0 -172
  12. package/dist/bp-loader.js +0 -26
  13. package/dist/carousel.js +0 -308
  14. package/dist/code-editor.js +0 -102
  15. package/dist/color-input.js +0 -112
  16. package/dist/data-table.js +0 -774
  17. package/dist/drag-and-drop.js +0 -386
  18. package/dist/editable-rect.js +0 -450
  19. package/dist/filter-builder.js +0 -468
  20. package/dist/float.js +0 -170
  21. package/dist/form.js +0 -466
  22. package/dist/gamepad.js +0 -115
  23. package/dist/icon-data.js +0 -308
  24. package/dist/icon-types.js +0 -1
  25. package/dist/icons.js +0 -374
  26. package/dist/index-iife.js +0 -4
  27. package/dist/live-example.js +0 -611
  28. package/dist/localize.js +0 -381
  29. package/dist/make-sorter.js +0 -119
  30. package/dist/make-sorter.test.d.ts +0 -1
  31. package/dist/make-sorter.test.js +0 -48
  32. package/dist/mapbox.js +0 -161
  33. package/dist/markdown-viewer.js +0 -173
  34. package/dist/match-shortcut.js +0 -13
  35. package/dist/match-shortcut.test.d.ts +0 -1
  36. package/dist/match-shortcut.test.js +0 -194
  37. package/dist/menu.js +0 -614
  38. package/dist/notifications.js +0 -308
  39. package/dist/password-strength.js +0 -302
  40. package/dist/playwright.config.d.ts +0 -9
  41. package/dist/playwright.config.js +0 -73
  42. package/dist/pop-float.js +0 -231
  43. package/dist/rating.js +0 -192
  44. package/dist/rich-text.js +0 -296
  45. package/dist/segmented.js +0 -298
  46. package/dist/select.js +0 -427
  47. package/dist/side-nav.js +0 -106
  48. package/dist/size-break.js +0 -118
  49. package/dist/sizer.js +0 -92
  50. package/dist/src/ab-test.d.ts +0 -14
  51. package/dist/src/babylon-3d.d.ts +0 -53
  52. package/dist/src/bodymovin-player.d.ts +0 -32
  53. package/dist/src/bp-loader.d.ts +0 -0
  54. package/dist/src/carousel.d.ts +0 -113
  55. package/dist/src/code-editor.d.ts +0 -27
  56. package/dist/src/color-input.d.ts +0 -41
  57. package/dist/src/data-table.d.ts +0 -79
  58. package/dist/src/drag-and-drop.d.ts +0 -2
  59. package/dist/src/editable-rect.d.ts +0 -97
  60. package/dist/src/filter-builder.d.ts +0 -64
  61. package/dist/src/float.d.ts +0 -18
  62. package/dist/src/form.d.ts +0 -68
  63. package/dist/src/gamepad.d.ts +0 -34
  64. package/dist/src/icon-data.d.ts +0 -309
  65. package/dist/src/icon-types.d.ts +0 -7
  66. package/dist/src/icons.d.ts +0 -17
  67. package/dist/src/index.d.ts +0 -37
  68. package/dist/src/live-example.d.ts +0 -51
  69. package/dist/src/localize.d.ts +0 -30
  70. package/dist/src/make-sorter.d.ts +0 -3
  71. package/dist/src/mapbox.d.ts +0 -24
  72. package/dist/src/markdown-viewer.d.ts +0 -15
  73. package/dist/src/match-shortcut.d.ts +0 -9
  74. package/dist/src/menu.d.ts +0 -60
  75. package/dist/src/notifications.d.ts +0 -106
  76. package/dist/src/password-strength.d.ts +0 -35
  77. package/dist/src/pop-float.d.ts +0 -10
  78. package/dist/src/rating.d.ts +0 -62
  79. package/dist/src/rich-text.d.ts +0 -28
  80. package/dist/src/segmented.d.ts +0 -80
  81. package/dist/src/select.d.ts +0 -43
  82. package/dist/src/side-nav.d.ts +0 -36
  83. package/dist/src/size-break.d.ts +0 -18
  84. package/dist/src/sizer.d.ts +0 -34
  85. package/dist/src/tab-selector.d.ts +0 -91
  86. package/dist/src/tag-list.d.ts +0 -37
  87. package/dist/src/track-drag.d.ts +0 -5
  88. package/dist/src/version.d.ts +0 -1
  89. package/dist/src/via-tag.d.ts +0 -2
  90. package/dist/tab-selector.js +0 -326
  91. package/dist/tag-list.js +0 -375
  92. package/dist/track-drag.js +0 -143
  93. package/dist/version.js +0 -1
  94. package/dist/via-tag.js +0 -102
@@ -1,386 +0,0 @@
1
- /*#
2
- # drag & drop
3
-
4
- > **Note** this library is a modernized version of the [b8rjs](https://b8rjs.com) drag-and-drop.js library.
5
- > It removes all usage of b8rjs and has no dependencies.
6
-
7
- A lightweight library building on top of HTML5 drag and drop behavior.
8
-
9
- To use it, simply call `dragAndDrop.init()` (it only needs to be called once,
10
- but calling it again is harmless).
11
-
12
- ```
13
- import { dragAndDrop } from 'xinjs-ui'
14
-
15
- dragAndDrop.init()
16
- ```
17
-
18
- The library just sets up some event listeners.
19
-
20
- You can use `dragAndDrop.draggedElement()` to get the element being dragged (if it's
21
- actually from the page you're in).
22
-
23
- > ### Important Note
24
- >
25
- > The nice thing about HTML5 drag-and-drop is that it leverages the OS's drag and
26
- > drop support. This means you can drag from one window to another, from the desktop
27
- > to your app and vice versa. It's all a matter of configuring the DOM elements.
28
-
29
- This module sets up some global event handlers and *just works*™ (arguably, it merely does things
30
- that the browser should do, such as add a CSS selector for drop zones that are compatible
31
- with what's being dragged).
32
-
33
- This module uses but *does not define* the following class selectors:
34
-
35
- - `.drag-source` an element being dragged
36
- - `.drag-target` an element on which the dragged object may be dropped
37
- - `.drag-over` a `.drag-target` which the object is currently over
38
-
39
- You may also wish to create style rules for:
40
-
41
- - `[draggable="true"]` anything other than a `<a>` (and perhaps an `<img>`) that can be dragged
42
- - `[data-drag]` indicates *types* of draggable things that can be dropped on them.
43
- - `[data-drop]` indicates potential *drop zones*.
44
-
45
- > **Note** `draggable` is has to be set to "true", [see documentation on draggable](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/draggable).
46
-
47
- ## Draggable Objects
48
-
49
- To create a draggable element, add `draggable="true"`.
50
-
51
- <div draggable="true">Drag Me</div>
52
-
53
- To specify the type(s) of content that will be dragged, use the `data-drag` attribute:
54
-
55
- <div draggable="true" data-drag="text/plain">Drag Me</div>
56
-
57
- To specify the content dragged, use a `data-drag-content` attribute.
58
-
59
- <div
60
- draggable="true"
61
- data-drag="text/plain"
62
- data-drag-content="Surprise!"
63
- >Drag Me</div>
64
-
65
- ## Drop Zones
66
-
67
- To create a drop zone, use the data-drop attribute set to a semicolon-delimited list
68
- of mime types:
69
-
70
- <div data-drop="text/plain">
71
- Drop plain text here
72
- </div>
73
- <div data-drop="text/plain;text/html">
74
- Drop html or plain text here
75
- </div>
76
-
77
- Finally, you can override default drop behavior (which is to copy the dragged node into
78
- the drop zone node) simply using data-event="drop:path.to.drop_handler" as usual.
79
-
80
- <div
81
- data-drop="custom"
82
- data-event="drop:path.to.drop_handler"
83
- >
84
- Drop some custom thing here
85
- </div>
86
-
87
- ### Typed Drop Zones Example
88
-
89
- ```html
90
- <div style="display: grid; grid-template-columns: 50% 50%">
91
- <div>
92
- <h4>Draggable</h4>
93
- <a class="drag" href="javascript: alert('I don't do anything)">Links are draggable by default</a>
94
- <p draggable="true">
95
- Just adding the <code>draggable="true"</code>
96
- makes this paragraph draggable (as text/html by default)
97
- </p>
98
- <p draggable="true" data-drag="text/html">
99
- Draggable as <i>text/html</i>
100
- </p>
101
- <p draggable="true" data-drag="text/plain" data-drag-content="Surprise!">
102
- Draggable as <i>text/plain</i>, with <b>custom content</b>
103
- </p>
104
- <p draggable="true" data-drag="text/html;text/plain">
105
- Draggable as <i>text/html</i> or <i>text/plain</i>
106
- </p>
107
- <p draggable="true" data-drag="text/plain">
108
- Draggable as <i>text/plain</i>
109
- </p>
110
- </div>
111
- <div>
112
- <h4>Drop Targets</h4>
113
- <div data-drop="text/html">
114
- You can drop stuff here
115
- </div>
116
- <div data-drop="text/html">
117
- You can drop HTML here
118
- </div>
119
- <div data-drop="text/*">
120
- You can drop any text
121
- </div>
122
- <div data-drop="text/html;url">
123
- You can drop HTML or urls here
124
- </div>
125
- <div
126
- data-drop="special/any"
127
- data-event="drop:_component_.drop"
128
- >
129
- I accept anything and have special drop handling
130
- </div>
131
- </div>
132
- </div>
133
- ```
134
- ```css
135
- .drag-source {
136
- box-shadow: 0 0 2px 2px orange;
137
- opacity: 0.5;
138
- }
139
- .drag-target {
140
- min-height: 10px;
141
- background: rgba(0,0,255,0.25);
142
- }
143
- .drag-target.drag-over {
144
- background: rgba(0,0,255,0.5);
145
- }
146
- :not([data-drop]) > .drag,
147
- [draggable="true"] {
148
- border: 1px solid rgba(255,192,0,0.5);
149
- cursor: pointer;
150
- display: block;
151
- }
152
-
153
- :not([data-drop]) > .drag,
154
- [data-drop],
155
- [draggable="true"] {
156
- padding: 4px;
157
- margin: 4px;
158
- border-radius: 5px;
159
- }
160
- ```
161
- ```js
162
- const { dragAndDrop } = xinjsui
163
-
164
- dragAndDrop.init()
165
- ```
166
-
167
- > Note that you can drag between two browser tabs containing this
168
- > example (or between two different browsers) and it will work.
169
-
170
- ### Reorderable List Example
171
-
172
- ```js
173
- const { elements, boxedProxy, getListItem } = xinjs
174
- const { dragAndDrop } = xinjsui
175
-
176
- dragAndDrop.init()
177
-
178
- const shuffle = (deck) => {
179
- var shuffled = [];
180
- for( const card of deck ){
181
- shuffled.splice( Math.floor( Math.random() * (1 + shuffled.length) ), 0, card );
182
- }
183
- return shuffled;
184
- }
185
-
186
- const colors = [
187
- 'red',
188
- 'orange',
189
- 'yellow',
190
- 'green',
191
- 'blue',
192
- 'indigo',
193
- 'violet',
194
- ]
195
- const { spectrum } = boxedProxy({
196
- spectrum: shuffle(colors).map(color => ({color}))
197
- })
198
-
199
- const { div, template } = elements
200
-
201
- let dragged = null
202
-
203
- const dropColor = (event) => {
204
- const dropped = getListItem(event.target)
205
- const draggedIndex = spectrum.indexOf(dragged)
206
- const droppedIndex = spectrum.indexOf(dropped)
207
- spectrum.splice(draggedIndex, 1)
208
- spectrum.splice(droppedIndex, 0, dragged)
209
-
210
- console.log({dragged, draggedIndex, dropped, droppedIndex})
211
-
212
- event.preventDefault()
213
- event.stopPropagation()
214
- }
215
-
216
- const dragId = 'spectrum/' + Math.floor(Math.random() * 1e9)
217
-
218
- preview.append(
219
- div(
220
- {
221
- bindList: { value: spectrum, idPath: 'color' }
222
- },
223
- template(
224
- div({
225
- class: 'spectrum',
226
- bindText: '^.color',
227
- draggable: 'true',
228
- dataDrag: dragId,
229
- dataDrop: dragId,
230
- onDrop: dropColor,
231
- bind: {
232
- value: '^.color',
233
- binding(element, value) {
234
- element.style.backgroundColor = value
235
- }
236
- },
237
- onDragstart(event) {
238
- dragged = getListItem(event.target)
239
- }
240
- })
241
- )
242
- ),
243
- )
244
- ```
245
- ```css
246
- .spectrum {
247
- height: 36px;
248
- color: white;
249
- font-weight: 700;
250
- text-shadow: 1px 2px 0 black;
251
- padding-left: 10px;
252
- }
253
-
254
- .spectrum.drag-over {
255
- box-shadow: 0 0 0 4px blue;
256
- }
257
- ```
258
-
259
- > To prevent this example from allowing drags between windows (which
260
- > wouldn't make sense) a random dragId is assigned to `data-drag` and
261
- > `data-drop` in this example.
262
- )
263
- */
264
- const dragInProgress = () => !!document.querySelector('.drag-source');
265
- const isTypeAllowed = (allowedTypes, type) => {
266
- if (!allowedTypes) {
267
- return false;
268
- }
269
- for (const allowedType of allowedTypes) {
270
- if (allowedType === 'special/any') {
271
- return true;
272
- }
273
- else if (allowedType.indexOf('*') > -1) {
274
- const [A, B] = allowedType.split('/');
275
- const [a, b] = type.split('/');
276
- if ((A === '*' || A === a) && (B === '*' || B === b)) {
277
- return true;
278
- }
279
- }
280
- else {
281
- if (allowedType === type) {
282
- return true;
283
- }
284
- }
285
- }
286
- };
287
- const removeClass = (className) => {
288
- for (const elt of [...document.querySelectorAll(`.${className}`)]) {
289
- elt.classList.remove(className);
290
- }
291
- };
292
- const end = () => {
293
- removeClass('drag-over');
294
- removeClass('drag-source');
295
- removeClass('drag-target');
296
- };
297
- const stringToTypes = (s, delimiter = ';') => {
298
- return (s || '')
299
- .split(delimiter)
300
- .map((t) => t.trim())
301
- .filter((i) => i !== '');
302
- };
303
- const markDroppable = (types) => {
304
- if (!types)
305
- types = [];
306
- const elements = [
307
- ...document.querySelectorAll('[data-drop]'),
308
- ];
309
- for (const element of elements) {
310
- const dropTypes = stringToTypes(element.dataset.drop);
311
- if (types.find((type) => isTypeAllowed(dropTypes, type))) {
312
- element.classList.add('drag-target');
313
- }
314
- else {
315
- element.classList.remove('drag-target');
316
- }
317
- }
318
- };
319
- function start(evt) {
320
- const target = evt.target?.closest('[draggable="true"],a[href]');
321
- if (!target) {
322
- return;
323
- }
324
- target.classList.add('drag-source');
325
- const types = target.matches('[draggable="true"]')
326
- ? stringToTypes(target.dataset.drag || 'text/html')
327
- : stringToTypes(target.dataset.drag || 'url');
328
- for (const type of types) {
329
- const content = target.dataset.dragContent ||
330
- (type === 'text/html' ? target.innerHTML : target.textContent);
331
- evt.dataTransfer?.setData(type, content || '');
332
- }
333
- markDroppable(evt.dataTransfer?.types);
334
- evt.stopPropagation();
335
- }
336
- function drag(evt) {
337
- if (!dragInProgress()) {
338
- markDroppable(evt.dataTransfer?.types);
339
- }
340
- const target = evt.target.closest('.drag-target');
341
- if (target && evt.dataTransfer) {
342
- target.classList.add('drag-over');
343
- evt.dataTransfer.dropEffect = 'copy';
344
- }
345
- else {
346
- evt.preventDefault();
347
- evt.stopPropagation();
348
- }
349
- }
350
- function leave() {
351
- removeClass('drag-over');
352
- }
353
- function drop(evt) {
354
- const target = evt.target.closest('.drag-target');
355
- if (target) {
356
- const dropTypes = (target.dataset?.drop || '').split(';');
357
- for (const type of dropTypes) {
358
- if (isTypeAllowed(evt.dataTransfer?.types, type)) {
359
- if (type === 'text/html') {
360
- target.innerHTML = evt.dataTransfer?.getData(type) || '';
361
- }
362
- else {
363
- target.textContent = evt.dataTransfer?.getData(type) || '';
364
- }
365
- }
366
- }
367
- }
368
- end();
369
- }
370
- export const draggedElement = () => document.querySelector('.drag-source');
371
- let isInitialized = false;
372
- export const init = () => {
373
- if (isInitialized) {
374
- return;
375
- }
376
- document.body.addEventListener('dragstart', start);
377
- document.body.addEventListener('dragenter', drag);
378
- document.body.addEventListener('dragover', drag);
379
- document.body.addEventListener('drop', drop);
380
- document.body.addEventListener('dragleave', leave);
381
- document.body.addEventListener('dragend', end);
382
- // stop dragged items from reloading the window
383
- window.addEventListener('dragover', (evt) => evt.preventDefault());
384
- window.addEventListener('drop', (evt) => evt.preventDefault());
385
- isInitialized = true;
386
- };