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