1 | import { adapt } from '@cycle/run/lib/adapt';
|
2 | import { DocumentDOMSource } from './DocumentDOMSource';
|
3 | import { BodyDOMSource } from './BodyDOMSource';
|
4 | import { ElementFinder } from './ElementFinder';
|
5 | import { makeIsolateSink, getScopeObj } from './isolate';
|
6 | var MainDOMSource = (function () {
|
7 | function MainDOMSource(_rootElement$, _sanitation$, _namespace, _isolateModule, _eventDelegator, _name) {
|
8 | if (_namespace === void 0) { _namespace = []; }
|
9 | this._rootElement$ = _rootElement$;
|
10 | this._sanitation$ = _sanitation$;
|
11 | this._namespace = _namespace;
|
12 | this._isolateModule = _isolateModule;
|
13 | this._eventDelegator = _eventDelegator;
|
14 | this._name = _name;
|
15 | this.isolateSource = function (source, scope) {
|
16 | return new MainDOMSource(source._rootElement$, source._sanitation$, source._namespace.concat(getScopeObj(scope)), source._isolateModule, source._eventDelegator, source._name);
|
17 | };
|
18 | this.isolateSink = makeIsolateSink(this._namespace);
|
19 | }
|
20 | MainDOMSource.prototype._elements = function () {
|
21 | if (this._namespace.length === 0) {
|
22 | return this._rootElement$.map(function (x) { return [x]; });
|
23 | }
|
24 | else {
|
25 | var elementFinder_1 = new ElementFinder(this._namespace, this._isolateModule);
|
26 | return this._rootElement$.map(function () { return elementFinder_1.call(); });
|
27 | }
|
28 | };
|
29 | MainDOMSource.prototype.elements = function () {
|
30 | var out = adapt(this._elements().remember());
|
31 | out._isCycleSource = this._name;
|
32 | return out;
|
33 | };
|
34 | MainDOMSource.prototype.element = function () {
|
35 | var out = adapt(this._elements()
|
36 | .filter(function (arr) { return arr.length > 0; })
|
37 | .map(function (arr) { return arr[0]; })
|
38 | .remember());
|
39 | out._isCycleSource = this._name;
|
40 | return out;
|
41 | };
|
42 | Object.defineProperty(MainDOMSource.prototype, "namespace", {
|
43 | get: function () {
|
44 | return this._namespace;
|
45 | },
|
46 | enumerable: true,
|
47 | configurable: true
|
48 | });
|
49 | MainDOMSource.prototype.select = function (selector) {
|
50 | if (typeof selector !== 'string') {
|
51 | throw new Error("DOM driver's select() expects the argument to be a " +
|
52 | "string as a CSS selector");
|
53 | }
|
54 | if (selector === 'document') {
|
55 | return new DocumentDOMSource(this._name);
|
56 | }
|
57 | if (selector === 'body') {
|
58 | return new BodyDOMSource(this._name);
|
59 | }
|
60 | var namespace = selector === ':root'
|
61 | ? []
|
62 | : this._namespace.concat({ type: 'selector', scope: selector.trim() });
|
63 | return new MainDOMSource(this._rootElement$, this._sanitation$, namespace, this._isolateModule, this._eventDelegator, this._name);
|
64 | };
|
65 | MainDOMSource.prototype.events = function (eventType, options, bubbles) {
|
66 | if (options === void 0) { options = {}; }
|
67 | if (typeof eventType !== "string") {
|
68 | throw new Error("DOM driver's events() expects argument to be a " +
|
69 | "string representing the event type to listen for.");
|
70 | }
|
71 | var event$ = this._eventDelegator.addEventListener(eventType, this._namespace, options, bubbles);
|
72 | var out = adapt(event$);
|
73 | out._isCycleSource = this._name;
|
74 | return out;
|
75 | };
|
76 | MainDOMSource.prototype.dispose = function () {
|
77 | this._sanitation$.shamefullySendNext(null);
|
78 |
|
79 | };
|
80 | return MainDOMSource;
|
81 | }());
|
82 | export { MainDOMSource };
|
83 |
|
\ | No newline at end of file |