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.
Files changed (134) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +165 -0
  3. package/dist/ab-test.d.ts +14 -0
  4. package/dist/ab-test.js +116 -0
  5. package/dist/babylon-3d.d.ts +53 -0
  6. package/dist/babylon-3d.js +292 -0
  7. package/dist/bodymovin-player.d.ts +32 -0
  8. package/dist/bodymovin-player.js +172 -0
  9. package/dist/bp-loader.d.ts +1 -0
  10. package/dist/bp-loader.js +26 -0
  11. package/dist/carousel.d.ts +113 -0
  12. package/dist/carousel.js +308 -0
  13. package/dist/code-editor.d.ts +27 -0
  14. package/dist/code-editor.js +102 -0
  15. package/dist/color-input.d.ts +41 -0
  16. package/dist/color-input.js +112 -0
  17. package/dist/data-table.d.ts +79 -0
  18. package/dist/data-table.js +774 -0
  19. package/dist/drag-and-drop.d.ts +2 -0
  20. package/dist/drag-and-drop.js +386 -0
  21. package/dist/editable-rect.d.ts +97 -0
  22. package/dist/editable-rect.js +450 -0
  23. package/dist/filter-builder.d.ts +64 -0
  24. package/dist/filter-builder.js +468 -0
  25. package/dist/float.d.ts +18 -0
  26. package/dist/float.js +170 -0
  27. package/dist/form.d.ts +68 -0
  28. package/dist/form.js +466 -0
  29. package/dist/gamepad.d.ts +34 -0
  30. package/dist/gamepad.js +115 -0
  31. package/dist/icon-data.d.ts +312 -0
  32. package/dist/icon-data.js +308 -0
  33. package/dist/icon-types.d.ts +7 -0
  34. package/dist/icon-types.js +1 -0
  35. package/dist/icons.d.ts +17 -0
  36. package/dist/icons.js +374 -0
  37. package/dist/iife.js +69 -0
  38. package/dist/iife.js.map +49 -0
  39. package/dist/index-iife.d.ts +1 -0
  40. package/dist/index-iife.js +4 -0
  41. package/dist/index.d.ts +37 -0
  42. package/dist/index.js +37 -0
  43. package/dist/index.js.map +47 -0
  44. package/dist/live-example.d.ts +63 -0
  45. package/dist/live-example.js +611 -0
  46. package/dist/localize.d.ts +46 -0
  47. package/dist/localize.js +381 -0
  48. package/dist/make-sorter.d.ts +3 -0
  49. package/dist/make-sorter.js +119 -0
  50. package/dist/make-sorter.test.d.ts +1 -0
  51. package/dist/make-sorter.test.js +48 -0
  52. package/dist/mapbox.d.ts +24 -0
  53. package/dist/mapbox.js +161 -0
  54. package/dist/markdown-viewer.d.ts +17 -0
  55. package/dist/markdown-viewer.js +173 -0
  56. package/dist/match-shortcut.d.ts +9 -0
  57. package/dist/match-shortcut.js +13 -0
  58. package/dist/match-shortcut.test.d.ts +1 -0
  59. package/dist/match-shortcut.test.js +194 -0
  60. package/dist/menu.d.ts +60 -0
  61. package/dist/menu.js +614 -0
  62. package/dist/notifications.d.ts +106 -0
  63. package/dist/notifications.js +308 -0
  64. package/dist/password-strength.d.ts +35 -0
  65. package/dist/password-strength.js +302 -0
  66. package/dist/playwright.config.d.ts +9 -0
  67. package/dist/playwright.config.js +73 -0
  68. package/dist/pop-float.d.ts +10 -0
  69. package/dist/pop-float.js +231 -0
  70. package/dist/rating.d.ts +62 -0
  71. package/dist/rating.js +192 -0
  72. package/dist/rich-text.d.ts +35 -0
  73. package/dist/rich-text.js +296 -0
  74. package/dist/segmented.d.ts +80 -0
  75. package/dist/segmented.js +298 -0
  76. package/dist/select.d.ts +43 -0
  77. package/dist/select.js +427 -0
  78. package/dist/side-nav.d.ts +36 -0
  79. package/dist/side-nav.js +106 -0
  80. package/dist/size-break.d.ts +18 -0
  81. package/dist/size-break.js +118 -0
  82. package/dist/sizer.d.ts +34 -0
  83. package/dist/sizer.js +92 -0
  84. package/dist/src/ab-test.d.ts +14 -0
  85. package/dist/src/babylon-3d.d.ts +53 -0
  86. package/dist/src/bodymovin-player.d.ts +32 -0
  87. package/dist/src/bp-loader.d.ts +0 -0
  88. package/dist/src/carousel.d.ts +113 -0
  89. package/dist/src/code-editor.d.ts +27 -0
  90. package/dist/src/color-input.d.ts +41 -0
  91. package/dist/src/data-table.d.ts +79 -0
  92. package/dist/src/drag-and-drop.d.ts +2 -0
  93. package/dist/src/editable-rect.d.ts +97 -0
  94. package/dist/src/filter-builder.d.ts +64 -0
  95. package/dist/src/float.d.ts +18 -0
  96. package/dist/src/form.d.ts +68 -0
  97. package/dist/src/gamepad.d.ts +34 -0
  98. package/dist/src/icon-data.d.ts +309 -0
  99. package/dist/src/icon-types.d.ts +7 -0
  100. package/dist/src/icons.d.ts +17 -0
  101. package/dist/src/index.d.ts +37 -0
  102. package/dist/src/live-example.d.ts +51 -0
  103. package/dist/src/localize.d.ts +30 -0
  104. package/dist/src/make-sorter.d.ts +3 -0
  105. package/dist/src/mapbox.d.ts +24 -0
  106. package/dist/src/markdown-viewer.d.ts +15 -0
  107. package/dist/src/match-shortcut.d.ts +9 -0
  108. package/dist/src/menu.d.ts +60 -0
  109. package/dist/src/notifications.d.ts +106 -0
  110. package/dist/src/password-strength.d.ts +35 -0
  111. package/dist/src/pop-float.d.ts +10 -0
  112. package/dist/src/rating.d.ts +62 -0
  113. package/dist/src/rich-text.d.ts +28 -0
  114. package/dist/src/segmented.d.ts +80 -0
  115. package/dist/src/select.d.ts +43 -0
  116. package/dist/src/side-nav.d.ts +36 -0
  117. package/dist/src/size-break.d.ts +18 -0
  118. package/dist/src/sizer.d.ts +34 -0
  119. package/dist/src/tab-selector.d.ts +91 -0
  120. package/dist/src/tag-list.d.ts +37 -0
  121. package/dist/src/track-drag.d.ts +5 -0
  122. package/dist/src/version.d.ts +1 -0
  123. package/dist/src/via-tag.d.ts +2 -0
  124. package/dist/tab-selector.d.ts +91 -0
  125. package/dist/tab-selector.js +326 -0
  126. package/dist/tag-list.d.ts +37 -0
  127. package/dist/tag-list.js +375 -0
  128. package/dist/track-drag.d.ts +5 -0
  129. package/dist/track-drag.js +143 -0
  130. package/dist/version.d.ts +1 -0
  131. package/dist/version.js +1 -0
  132. package/dist/via-tag.d.ts +2 -0
  133. package/dist/via-tag.js +102 -0
  134. package/package.json +58 -0
@@ -0,0 +1,2 @@
1
+ export declare const draggedElement: () => Element | null;
2
+ export declare const init: () => void;
@@ -0,0 +1,386 @@
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
+ };
@@ -0,0 +1,97 @@
1
+ import { Component } from 'tosijs';
2
+ interface Locks {
3
+ left: boolean;
4
+ right: boolean;
5
+ top: boolean;
6
+ bottom: boolean;
7
+ }
8
+ export declare class EditableRect extends Component {
9
+ static angleSize: number;
10
+ static gridSize: number;
11
+ static snapAngle: boolean;
12
+ static snapToGrid: boolean;
13
+ static styleSpec: {
14
+ ':host': {
15
+ '--handle-bg': string;
16
+ '--handle-color': string;
17
+ '--handle-hover-bg': string;
18
+ '--handle-hover-color': string;
19
+ '--handle-size': string;
20
+ '--handle-padding': string;
21
+ };
22
+ ':host ::slotted(*)': {
23
+ position: string;
24
+ };
25
+ ':host > :not(style,slot)': {
26
+ boxSizing: string;
27
+ content: string;
28
+ position: string;
29
+ display: string;
30
+ height: string;
31
+ width: string;
32
+ padding: string;
33
+ '--text-color': string;
34
+ background: string;
35
+ };
36
+ ':host > .drag-size': {
37
+ top: number;
38
+ bottom: number;
39
+ left: number;
40
+ right: number;
41
+ height: string;
42
+ width: string;
43
+ background: string;
44
+ cursor: string;
45
+ };
46
+ ':host > [part="rotate"]': {
47
+ transform: string;
48
+ };
49
+ ':host > [locked] > svg:first-child, :host > :not([locked]) > svg+svg': {
50
+ display: string;
51
+ };
52
+ ':host .icon-unlock': {
53
+ opacity: number;
54
+ };
55
+ ':host svg': {
56
+ pointerEvents: string;
57
+ };
58
+ ':host > *:hover': {
59
+ '--text-color': string;
60
+ background: string;
61
+ };
62
+ };
63
+ static snappedCoords(event: PointerEvent, coords: number[]): number[];
64
+ static snappedAngle(event: PointerEvent, a: number): number;
65
+ get locked(): Locks;
66
+ set locked(locks: Locks);
67
+ get coords(): {
68
+ top: number;
69
+ left: number;
70
+ bottom: number;
71
+ right: number;
72
+ };
73
+ get left(): number;
74
+ get width(): number;
75
+ get right(): number;
76
+ get top(): number;
77
+ get height(): number;
78
+ get bottom(): number;
79
+ triggerChange: () => void;
80
+ adjustPosition: (event: Event) => void;
81
+ resize: (event: Event) => void;
82
+ adjustSize: (event: Event) => void;
83
+ get rect(): DOMRect;
84
+ get center(): {
85
+ x: number;
86
+ y: number;
87
+ };
88
+ get element(): HTMLElement;
89
+ adjustRotation: (event: Event) => void;
90
+ toggleLock: (event: Event) => void;
91
+ content: () => (HTMLDivElement | HTMLSlotElement)[];
92
+ constructor();
93
+ connectedCallback(): void;
94
+ render(): void;
95
+ }
96
+ export declare const editableRect: import("tosijs").ElementCreator<Component<import("tosijs").PartsMap>>;
97
+ export {};