Skip to content

Commit c12321c

Browse files
committed
Fix horizontal reordering
1 parent e02c37c commit c12321c

File tree

13 files changed

+1153
-1238
lines changed

13 files changed

+1153
-1238
lines changed

examples/horizontal/src/index.ts

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,74 @@
11
import { Observable } from 'rxjs';
22
import { run } from '@cycle/rxjs-run';
3-
import { ul, li, div, h3, p, makeDOMDriver, DOMSource, VNode } from '@cycle/dom';
3+
import {
4+
ul,
5+
li,
6+
div,
7+
h3,
8+
p,
9+
makeDOMDriver,
10+
DOMSource,
11+
VNode
12+
} from '@cycle/dom';
413

514
import { makeSortable } from '../../../src/makeSortable';
615

716
type Sources = {
8-
DOM : DOMSource;
17+
DOM: DOMSource;
918
};
1019

1120
type Sinks = {
12-
DOM : Observable<VNode>;
21+
DOM?: Observable<VNode>;
22+
sortable?: Observable<boolean>;
1323
};
1424

15-
function main({ DOM } : Sources) : Sinks
16-
{
17-
const vdom$ : Observable<VNode> = Observable.of(
18-
div([
19-
h3('Horizontal too!'),
20-
p('this is running with RxJS'),
21-
ul('.ul', [
22-
li('.li', '', ['Option 1']),
23-
li('.li', '', ['Option 2']),
24-
li('.li', '', ['Option 3']),
25-
li('.li', '', ['Option 4']),
26-
li('.li', '', ['Option 5']),
27-
li('.li', '', ['Option 6']),
28-
])
25+
function userSelectDriver(sort$): void {
26+
sort$.addListener({
27+
next(b) {
28+
if (b) {
29+
document.body.setAttribute(
30+
'style',
31+
'-webkit-user-select: none; -moz-user-select: none;' +
32+
' -ms-user-select: none; user-select: none;'
33+
);
34+
} else {
35+
document.body.removeAttribute('style');
36+
}
37+
}
38+
});
39+
}
40+
41+
function main(sources: Sources): Sinks {
42+
const sinks = makeSortable(Child, {
43+
itemSelector: '.li'
44+
})(sources);
45+
46+
return {
47+
...sinks,
48+
DOM: sinks.DOM.map(dom =>
49+
div([h3('Horizontal too!'), p('this is running with RxJS'), dom])
50+
)
51+
};
52+
}
53+
54+
function Child({ DOM }: Sources): Sinks {
55+
const vdom$: Observable<VNode> = Observable.of(
56+
ul('.ul', [
57+
li('.li', '', ['Option 1']),
58+
li('.li', '', ['Option 2']),
59+
li('.li', '', ['Option 3']),
60+
li('.li', '', ['Option 4']),
61+
li('.li', '', ['Option 5']),
62+
li('.li', '', ['Option 6'])
2963
])
30-
)
31-
.let(makeSortable<Observable<VNode>>(DOM, {
32-
parentSelector: '.ul'
33-
}));
64+
);
3465

3566
return {
3667
DOM: vdom$
3768
};
3869
}
3970

4071
run(main, {
41-
DOM: makeDOMDriver('#app')
72+
DOM: makeDOMDriver('#app'),
73+
sortable: userSelectDriver
4274
});

examples/parentSelector/css/main.css

Lines changed: 0 additions & 26 deletions
This file was deleted.

examples/parentSelector/index.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

examples/parentSelector/src/index.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

examples/simple/src/index.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,22 @@ type Sinks = {
1212
DOM: Stream<VNode>;
1313
};
1414

15-
function main({ DOM }: Sources): Sinks {
16-
const vdom$: Stream<VNode> = xs
17-
.of(
18-
ul('.ul', [
19-
li('.li', '', [
20-
'You have to hold for 500ms to start reordering'
21-
]),
22-
li('.li', '', ['Option 2']),
23-
li('.li', '', ['Option 3']),
24-
li('.li', '', ['Option 4']),
25-
li('.li', '', ['Option 5']),
26-
li('.li', '', ['Option 6'])
27-
])
28-
)
29-
.compose(
30-
makeSortable<Stream<VNode>>(DOM, {
31-
ghostClass: '.ghost',
32-
selectionDelay: 500
33-
})
34-
);
15+
const main = makeSortable(Child, {
16+
itemSelector: '.li',
17+
selectionDelay: 500
18+
});
19+
20+
function Child({ DOM }: Sources): Sinks {
21+
const vdom$: Stream<VNode> = xs.of(
22+
ul('.ul', [
23+
li('.li', '', ['You have to hold for 500ms to start reordering']),
24+
li('.li', '', ['Option 2']),
25+
li('.li', '', ['Option 3']),
26+
li('.li', '', ['Option 4']),
27+
li('.li', '', ['Option 5']),
28+
li('.li', '', ['Option 6'])
29+
])
30+
);
3531

3632
return {
3733
DOM: vdom$

examples/updateEvent/css/main.css

Lines changed: 0 additions & 26 deletions
This file was deleted.

examples/updateEvent/index.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

examples/updateEvent/src/index.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)