@blackglory/observe 0.1.3
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.
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +17 -0
- package/dist/es2015/index.min.mjs +16 -0
- package/dist/es2015/index.min.mjs.map +1 -0
- package/dist/es2015/index.mjs +5664 -0
- package/dist/es2015/index.mjs.map +1 -0
- package/dist/es2015/index.umd.js +5677 -0
- package/dist/es2015/index.umd.js.map +1 -0
- package/dist/es2015/index.umd.min.js +16 -0
- package/dist/es2015/index.umd.min.js.map +1 -0
- package/dist/es2018/index.min.mjs +16 -0
- package/dist/es2018/index.min.mjs.map +1 -0
- package/dist/es2018/index.mjs +5664 -0
- package/dist/es2018/index.mjs.map +1 -0
- package/dist/es2018/index.umd.js +5677 -0
- package/dist/es2018/index.umd.js.map +1 -0
- package/dist/es2018/index.umd.min.js +16 -0
- package/dist/es2018/index.umd.min.js.map +1 -0
- package/lib/es2015/index.d.ts +4 -0
- package/lib/es2015/index.js +17 -0
- package/lib/es2015/index.js.map +1 -0
- package/lib/es2015/observe-addtion-of-descendant-nodes.d.ts +2 -0
- package/lib/es2015/observe-addtion-of-descendant-nodes.js +14 -0
- package/lib/es2015/observe-addtion-of-descendant-nodes.js.map +1 -0
- package/lib/es2015/observe-removal-of-descendant-nodes.d.ts +2 -0
- package/lib/es2015/observe-removal-of-descendant-nodes.js +14 -0
- package/lib/es2015/observe-removal-of-descendant-nodes.js.map +1 -0
- package/lib/es2015/observe-state-changes.d.ts +2 -0
- package/lib/es2015/observe-state-changes.js +46 -0
- package/lib/es2015/observe-state-changes.js.map +1 -0
- package/lib/es2015/observe-url-changes.d.ts +2 -0
- package/lib/es2015/observe-url-changes.js +11 -0
- package/lib/es2015/observe-url-changes.js.map +1 -0
- package/lib/es2015/utils/from-mutation-observer.d.ts +2 -0
- package/lib/es2015/utils/from-mutation-observer.js +13 -0
- package/lib/es2015/utils/from-mutation-observer.js.map +1 -0
- package/lib/es2018/index.d.ts +4 -0
- package/lib/es2018/index.js +17 -0
- package/lib/es2018/index.js.map +1 -0
- package/lib/es2018/observe-addtion-of-descendant-nodes.d.ts +2 -0
- package/lib/es2018/observe-addtion-of-descendant-nodes.js +14 -0
- package/lib/es2018/observe-addtion-of-descendant-nodes.js.map +1 -0
- package/lib/es2018/observe-removal-of-descendant-nodes.d.ts +2 -0
- package/lib/es2018/observe-removal-of-descendant-nodes.js +14 -0
- package/lib/es2018/observe-removal-of-descendant-nodes.js.map +1 -0
- package/lib/es2018/observe-state-changes.d.ts +2 -0
- package/lib/es2018/observe-state-changes.js +46 -0
- package/lib/es2018/observe-state-changes.js.map +1 -0
- package/lib/es2018/observe-url-changes.d.ts +2 -0
- package/lib/es2018/observe-url-changes.js +11 -0
- package/lib/es2018/observe-url-changes.js.map +1 -0
- package/lib/es2018/utils/from-mutation-observer.d.ts +2 -0
- package/lib/es2018/utils/from-mutation-observer.js +13 -0
- package/lib/es2018/utils/from-mutation-observer.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./observe-addtion-of-descendant-nodes"), exports);
|
|
14
|
+
__exportStar(require("./observe-removal-of-descendant-nodes"), exports);
|
|
15
|
+
__exportStar(require("./observe-state-changes"), exports);
|
|
16
|
+
__exportStar(require("./observe-url-changes"), exports);
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wEAAqD;AACrD,wEAAqD;AACrD,0DAAuC;AACvC,wDAAqC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.observeAdditionOfDescendantNodes = void 0;
|
|
4
|
+
const from_mutation_observer_1 = require("./utils/from-mutation-observer");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const chaining_1 = require("iterable-operator/lib/es2015/style/chaining");
|
|
7
|
+
function observeAdditionOfDescendantNodes(node) {
|
|
8
|
+
return (0, from_mutation_observer_1.fromMutationObserver)(node, { childList: true, subtree: true }).pipe((0, operators_1.map)(records => new chaining_1.IterableOperator(records)
|
|
9
|
+
.map(x => x.addedNodes)
|
|
10
|
+
.flatten()
|
|
11
|
+
.toArray()), (0, operators_1.filter)(addedNodes => addedNodes.length > 0));
|
|
12
|
+
}
|
|
13
|
+
exports.observeAdditionOfDescendantNodes = observeAdditionOfDescendantNodes;
|
|
14
|
+
//# sourceMappingURL=observe-addtion-of-descendant-nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe-addtion-of-descendant-nodes.js","sourceRoot":"","sources":["../../src/observe-addtion-of-descendant-nodes.ts"],"names":[],"mappings":";;;AAAA,0EAAoE;AACpE,8CAA4C;AAE5C,0EAA8E;AAE9E,SAAgB,gCAAgC,CAAC,IAAU;IACzD,OAAO,IAAA,6CAAoB,EACzB,IAAI,EACJ,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CACnC,CAAC,IAAI,CACJ,IAAA,eAAG,EAAC,OAAO,CAAC,EAAE,CAAC,IAAI,2BAAgB,CAAC,OAAO,CAAC;SACzC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;SACtB,OAAO,EAAQ;SACf,OAAO,EAAE,CACX,EACD,IAAA,kBAAM,EAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAC5C,CAAA;AACH,CAAC;AAZD,4EAYC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.observeRemovalOfDescendantNodes = void 0;
|
|
4
|
+
const from_mutation_observer_1 = require("./utils/from-mutation-observer");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const chaining_1 = require("iterable-operator/lib/es2015/style/chaining");
|
|
7
|
+
function observeRemovalOfDescendantNodes(node) {
|
|
8
|
+
return (0, from_mutation_observer_1.fromMutationObserver)(node, { childList: true, subtree: true }).pipe((0, operators_1.map)(records => new chaining_1.IterableOperator(records)
|
|
9
|
+
.map(x => x.removedNodes)
|
|
10
|
+
.flatten()
|
|
11
|
+
.toArray()), (0, operators_1.filter)(removedNodes => removedNodes.length > 0));
|
|
12
|
+
}
|
|
13
|
+
exports.observeRemovalOfDescendantNodes = observeRemovalOfDescendantNodes;
|
|
14
|
+
//# sourceMappingURL=observe-removal-of-descendant-nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe-removal-of-descendant-nodes.js","sourceRoot":"","sources":["../../src/observe-removal-of-descendant-nodes.ts"],"names":[],"mappings":";;;AAAA,0EAAoE;AACpE,8CAA4C;AAE5C,0EAA8E;AAE9E,SAAgB,+BAA+B,CAAC,IAAU;IACxD,OAAO,IAAA,6CAAoB,EACzB,IAAI,EACJ,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CACnC,CAAC,IAAI,CACJ,IAAA,eAAG,EAAC,OAAO,CAAC,EAAE,CAAC,IAAI,2BAAgB,CAAC,OAAO,CAAC;SACzC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC;SACxB,OAAO,EAAQ;SACf,OAAO,EAAE,CACX,EACD,IAAA,kBAAM,EAAC,YAAY,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAChD,CAAA;AACH,CAAC;AAZD,0EAYC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.observeStateChanges = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const pushStateHooks = new Set();
|
|
7
|
+
const replaceStateHooks = new Set();
|
|
8
|
+
let pushStateHookRegistered = false;
|
|
9
|
+
let replaceStateHookRegistered = false;
|
|
10
|
+
function observeStateChanges() {
|
|
11
|
+
return (0, rxjs_1.merge)(observePushState(), observeReplaceState(), (0, rxjs_1.fromEvent)(window, 'popstate')).pipe((0, operators_1.map)(_ => undefined));
|
|
12
|
+
}
|
|
13
|
+
exports.observeStateChanges = observeStateChanges;
|
|
14
|
+
function observePushState() {
|
|
15
|
+
return new rxjs_1.Observable(observer => {
|
|
16
|
+
if (!pushStateHookRegistered)
|
|
17
|
+
registerPushStateHook();
|
|
18
|
+
pushStateHooks.add(observer);
|
|
19
|
+
return () => pushStateHooks.delete(observer);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function observeReplaceState() {
|
|
23
|
+
return new rxjs_1.Observable(observer => {
|
|
24
|
+
if (!replaceStateHookRegistered)
|
|
25
|
+
registerReplaceStateHook();
|
|
26
|
+
replaceStateHooks.add(observer);
|
|
27
|
+
return () => replaceStateHooks.delete(observer);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function registerPushStateHook() {
|
|
31
|
+
const pushState = history.pushState;
|
|
32
|
+
history.pushState = function (...args) {
|
|
33
|
+
Reflect.apply(pushState, this, args);
|
|
34
|
+
pushStateHooks.forEach(observer => observer.next());
|
|
35
|
+
};
|
|
36
|
+
pushStateHookRegistered = true;
|
|
37
|
+
}
|
|
38
|
+
function registerReplaceStateHook() {
|
|
39
|
+
const replaceState = history.replaceState;
|
|
40
|
+
history.replaceState = function (...args) {
|
|
41
|
+
Reflect.apply(replaceState, this, args);
|
|
42
|
+
replaceStateHooks.forEach(observer => observer.next());
|
|
43
|
+
};
|
|
44
|
+
replaceStateHookRegistered = true;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=observe-state-changes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe-state-changes.js","sourceRoot":"","sources":["../../src/observe-state-changes.ts"],"names":[],"mappings":";;;AAAA,+BAA+D;AAC/D,8CAAoC;AAEpC,MAAM,cAAc,GAAG,IAAI,GAAG,EAAoB,CAAA;AAClD,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAoB,CAAA;AACrD,IAAI,uBAAuB,GAAG,KAAK,CAAA;AACnC,IAAI,0BAA0B,GAAG,KAAK,CAAA;AAEtC,SAAgB,mBAAmB;IACjC,OAAO,IAAA,YAAK,EACV,gBAAgB,EAAE,EAClB,mBAAmB,EAAE,EACrB,IAAA,gBAAS,EAAC,MAAM,EAAE,UAAU,CAAC,CAC9B,CAAC,IAAI,CACJ,IAAA,eAAG,EAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CACpB,CAAA;AACH,CAAC;AARD,kDAQC;AAED,SAAS,gBAAgB;IACvB,OAAO,IAAI,iBAAU,CAAC,QAAQ,CAAC,EAAE;QAC/B,IAAI,CAAC,uBAAuB;YAAE,qBAAqB,EAAE,CAAA;QACrD,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAC5B,OAAO,GAAG,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAC9C,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,mBAAmB;IAC1B,OAAO,IAAI,iBAAU,CAAC,QAAQ,CAAC,EAAE;QAC/B,IAAI,CAAC,0BAA0B;YAAE,wBAAwB,EAAE,CAAA;QAC3D,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAC/B,OAAO,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACjD,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,qBAAqB;IAC5B,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;IACnC,OAAO,CAAC,SAAS,GAAG,UAAU,GAAG,IAAI;QACnC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;QACpC,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IACrD,CAAC,CAAA;IACD,uBAAuB,GAAG,IAAI,CAAA;AAChC,CAAC;AAED,SAAS,wBAAwB;IAC/B,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;IACzC,OAAO,CAAC,YAAY,GAAG,UAAU,GAAG,IAAI;QACtC,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;QACvC,iBAAiB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IACxD,CAAC,CAAA;IACD,0BAA0B,GAAG,IAAI,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.observeUrlChanges = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
function observeUrlChanges() {
|
|
7
|
+
let url = document.URL;
|
|
8
|
+
return (0, rxjs_1.animationFrames)().pipe((0, operators_1.filter)(() => url !== document.URL), (0, operators_1.tap)(() => url = document.URL), (0, operators_1.map)(() => undefined));
|
|
9
|
+
}
|
|
10
|
+
exports.observeUrlChanges = observeUrlChanges;
|
|
11
|
+
//# sourceMappingURL=observe-url-changes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe-url-changes.js","sourceRoot":"","sources":["../../src/observe-url-changes.ts"],"names":[],"mappings":";;;AAAA,+BAAkD;AAClD,8CAAiD;AAEjD,SAAgB,iBAAiB;IAC/B,IAAI,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAA;IACtB,OAAO,IAAA,sBAAe,GAAE,CAAC,IAAI,CAC3B,IAAA,kBAAM,EAAC,GAAG,EAAE,CAAC,GAAG,KAAK,QAAQ,CAAC,GAAG,CAAC,EAClC,IAAA,eAAG,EAAC,GAAG,EAAE,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,EAC7B,IAAA,eAAG,EAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CACrB,CAAA;AACH,CAAC;AAPD,8CAOC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromMutationObserver = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
function fromMutationObserver(...args) {
|
|
6
|
+
return new rxjs_1.Observable(subscriber => {
|
|
7
|
+
const observer = new MutationObserver(mutationList => subscriber.next(mutationList));
|
|
8
|
+
observer.observe(...args);
|
|
9
|
+
return () => observer.disconnect();
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
exports.fromMutationObserver = fromMutationObserver;
|
|
13
|
+
//# sourceMappingURL=from-mutation-observer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"from-mutation-observer.js","sourceRoot":"","sources":["../../../src/utils/from-mutation-observer.ts"],"names":[],"mappings":";;;AAAA,+BAAiC;AAEjC,SAAgB,oBAAoB,CAClC,GAAG,IAA6C;IAEhD,OAAO,IAAI,iBAAU,CAAC,UAAU,CAAC,EAAE;QACjC,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CACnC,YAAY,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAC9C,CAAA;QACD,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA;QACzB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAA;IACpC,CAAC,CAAC,CAAA;AACJ,CAAC;AAVD,oDAUC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./observe-addtion-of-descendant-nodes"), exports);
|
|
14
|
+
__exportStar(require("./observe-removal-of-descendant-nodes"), exports);
|
|
15
|
+
__exportStar(require("./observe-state-changes"), exports);
|
|
16
|
+
__exportStar(require("./observe-url-changes"), exports);
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wEAAqD;AACrD,wEAAqD;AACrD,0DAAuC;AACvC,wDAAqC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.observeAdditionOfDescendantNodes = void 0;
|
|
4
|
+
const from_mutation_observer_1 = require("./utils/from-mutation-observer");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const chaining_1 = require("iterable-operator/lib/es2015/style/chaining");
|
|
7
|
+
function observeAdditionOfDescendantNodes(node) {
|
|
8
|
+
return (0, from_mutation_observer_1.fromMutationObserver)(node, { childList: true, subtree: true }).pipe((0, operators_1.map)(records => new chaining_1.IterableOperator(records)
|
|
9
|
+
.map(x => x.addedNodes)
|
|
10
|
+
.flatten()
|
|
11
|
+
.toArray()), (0, operators_1.filter)(addedNodes => addedNodes.length > 0));
|
|
12
|
+
}
|
|
13
|
+
exports.observeAdditionOfDescendantNodes = observeAdditionOfDescendantNodes;
|
|
14
|
+
//# sourceMappingURL=observe-addtion-of-descendant-nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe-addtion-of-descendant-nodes.js","sourceRoot":"","sources":["../../src/observe-addtion-of-descendant-nodes.ts"],"names":[],"mappings":";;;AAAA,0EAAoE;AACpE,8CAA4C;AAE5C,0EAA8E;AAE9E,SAAgB,gCAAgC,CAAC,IAAU;IACzD,OAAO,IAAA,6CAAoB,EACzB,IAAI,EACJ,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CACnC,CAAC,IAAI,CACJ,IAAA,eAAG,EAAC,OAAO,CAAC,EAAE,CAAC,IAAI,2BAAgB,CAAC,OAAO,CAAC;SACzC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;SACtB,OAAO,EAAQ;SACf,OAAO,EAAE,CACX,EACD,IAAA,kBAAM,EAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAC5C,CAAA;AACH,CAAC;AAZD,4EAYC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.observeRemovalOfDescendantNodes = void 0;
|
|
4
|
+
const from_mutation_observer_1 = require("./utils/from-mutation-observer");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const chaining_1 = require("iterable-operator/lib/es2015/style/chaining");
|
|
7
|
+
function observeRemovalOfDescendantNodes(node) {
|
|
8
|
+
return (0, from_mutation_observer_1.fromMutationObserver)(node, { childList: true, subtree: true }).pipe((0, operators_1.map)(records => new chaining_1.IterableOperator(records)
|
|
9
|
+
.map(x => x.removedNodes)
|
|
10
|
+
.flatten()
|
|
11
|
+
.toArray()), (0, operators_1.filter)(removedNodes => removedNodes.length > 0));
|
|
12
|
+
}
|
|
13
|
+
exports.observeRemovalOfDescendantNodes = observeRemovalOfDescendantNodes;
|
|
14
|
+
//# sourceMappingURL=observe-removal-of-descendant-nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe-removal-of-descendant-nodes.js","sourceRoot":"","sources":["../../src/observe-removal-of-descendant-nodes.ts"],"names":[],"mappings":";;;AAAA,0EAAoE;AACpE,8CAA4C;AAE5C,0EAA8E;AAE9E,SAAgB,+BAA+B,CAAC,IAAU;IACxD,OAAO,IAAA,6CAAoB,EACzB,IAAI,EACJ,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CACnC,CAAC,IAAI,CACJ,IAAA,eAAG,EAAC,OAAO,CAAC,EAAE,CAAC,IAAI,2BAAgB,CAAC,OAAO,CAAC;SACzC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC;SACxB,OAAO,EAAQ;SACf,OAAO,EAAE,CACX,EACD,IAAA,kBAAM,EAAC,YAAY,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAChD,CAAA;AACH,CAAC;AAZD,0EAYC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.observeStateChanges = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const pushStateHooks = new Set();
|
|
7
|
+
const replaceStateHooks = new Set();
|
|
8
|
+
let pushStateHookRegistered = false;
|
|
9
|
+
let replaceStateHookRegistered = false;
|
|
10
|
+
function observeStateChanges() {
|
|
11
|
+
return (0, rxjs_1.merge)(observePushState(), observeReplaceState(), (0, rxjs_1.fromEvent)(window, 'popstate')).pipe((0, operators_1.map)(_ => undefined));
|
|
12
|
+
}
|
|
13
|
+
exports.observeStateChanges = observeStateChanges;
|
|
14
|
+
function observePushState() {
|
|
15
|
+
return new rxjs_1.Observable(observer => {
|
|
16
|
+
if (!pushStateHookRegistered)
|
|
17
|
+
registerPushStateHook();
|
|
18
|
+
pushStateHooks.add(observer);
|
|
19
|
+
return () => pushStateHooks.delete(observer);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function observeReplaceState() {
|
|
23
|
+
return new rxjs_1.Observable(observer => {
|
|
24
|
+
if (!replaceStateHookRegistered)
|
|
25
|
+
registerReplaceStateHook();
|
|
26
|
+
replaceStateHooks.add(observer);
|
|
27
|
+
return () => replaceStateHooks.delete(observer);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function registerPushStateHook() {
|
|
31
|
+
const pushState = history.pushState;
|
|
32
|
+
history.pushState = function (...args) {
|
|
33
|
+
Reflect.apply(pushState, this, args);
|
|
34
|
+
pushStateHooks.forEach(observer => observer.next());
|
|
35
|
+
};
|
|
36
|
+
pushStateHookRegistered = true;
|
|
37
|
+
}
|
|
38
|
+
function registerReplaceStateHook() {
|
|
39
|
+
const replaceState = history.replaceState;
|
|
40
|
+
history.replaceState = function (...args) {
|
|
41
|
+
Reflect.apply(replaceState, this, args);
|
|
42
|
+
replaceStateHooks.forEach(observer => observer.next());
|
|
43
|
+
};
|
|
44
|
+
replaceStateHookRegistered = true;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=observe-state-changes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe-state-changes.js","sourceRoot":"","sources":["../../src/observe-state-changes.ts"],"names":[],"mappings":";;;AAAA,+BAA+D;AAC/D,8CAAoC;AAEpC,MAAM,cAAc,GAAG,IAAI,GAAG,EAAoB,CAAA;AAClD,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAoB,CAAA;AACrD,IAAI,uBAAuB,GAAG,KAAK,CAAA;AACnC,IAAI,0BAA0B,GAAG,KAAK,CAAA;AAEtC,SAAgB,mBAAmB;IACjC,OAAO,IAAA,YAAK,EACV,gBAAgB,EAAE,EAClB,mBAAmB,EAAE,EACrB,IAAA,gBAAS,EAAC,MAAM,EAAE,UAAU,CAAC,CAC9B,CAAC,IAAI,CACJ,IAAA,eAAG,EAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CACpB,CAAA;AACH,CAAC;AARD,kDAQC;AAED,SAAS,gBAAgB;IACvB,OAAO,IAAI,iBAAU,CAAC,QAAQ,CAAC,EAAE;QAC/B,IAAI,CAAC,uBAAuB;YAAE,qBAAqB,EAAE,CAAA;QACrD,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAC5B,OAAO,GAAG,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAC9C,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,mBAAmB;IAC1B,OAAO,IAAI,iBAAU,CAAC,QAAQ,CAAC,EAAE;QAC/B,IAAI,CAAC,0BAA0B;YAAE,wBAAwB,EAAE,CAAA;QAC3D,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAC/B,OAAO,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACjD,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,qBAAqB;IAC5B,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;IACnC,OAAO,CAAC,SAAS,GAAG,UAAU,GAAG,IAAI;QACnC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;QACpC,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IACrD,CAAC,CAAA;IACD,uBAAuB,GAAG,IAAI,CAAA;AAChC,CAAC;AAED,SAAS,wBAAwB;IAC/B,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;IACzC,OAAO,CAAC,YAAY,GAAG,UAAU,GAAG,IAAI;QACtC,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;QACvC,iBAAiB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IACxD,CAAC,CAAA;IACD,0BAA0B,GAAG,IAAI,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.observeUrlChanges = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
function observeUrlChanges() {
|
|
7
|
+
let url = document.URL;
|
|
8
|
+
return (0, rxjs_1.animationFrames)().pipe((0, operators_1.filter)(() => url !== document.URL), (0, operators_1.tap)(() => url = document.URL), (0, operators_1.map)(() => undefined));
|
|
9
|
+
}
|
|
10
|
+
exports.observeUrlChanges = observeUrlChanges;
|
|
11
|
+
//# sourceMappingURL=observe-url-changes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe-url-changes.js","sourceRoot":"","sources":["../../src/observe-url-changes.ts"],"names":[],"mappings":";;;AAAA,+BAAkD;AAClD,8CAAiD;AAEjD,SAAgB,iBAAiB;IAC/B,IAAI,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAA;IACtB,OAAO,IAAA,sBAAe,GAAE,CAAC,IAAI,CAC3B,IAAA,kBAAM,EAAC,GAAG,EAAE,CAAC,GAAG,KAAK,QAAQ,CAAC,GAAG,CAAC,EAClC,IAAA,eAAG,EAAC,GAAG,EAAE,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,EAC7B,IAAA,eAAG,EAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CACrB,CAAA;AACH,CAAC;AAPD,8CAOC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromMutationObserver = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
function fromMutationObserver(...args) {
|
|
6
|
+
return new rxjs_1.Observable(subscriber => {
|
|
7
|
+
const observer = new MutationObserver(mutationList => subscriber.next(mutationList));
|
|
8
|
+
observer.observe(...args);
|
|
9
|
+
return () => observer.disconnect();
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
exports.fromMutationObserver = fromMutationObserver;
|
|
13
|
+
//# sourceMappingURL=from-mutation-observer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"from-mutation-observer.js","sourceRoot":"","sources":["../../../src/utils/from-mutation-observer.ts"],"names":[],"mappings":";;;AAAA,+BAAiC;AAEjC,SAAgB,oBAAoB,CAClC,GAAG,IAA6C;IAEhD,OAAO,IAAI,iBAAU,CAAC,UAAU,CAAC,EAAE;QACjC,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CACnC,YAAY,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAC9C,CAAA;QACD,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA;QACzB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAA;IACpC,CAAC,CAAC,CAAA;AACJ,CAAC;AAVD,oDAUC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@blackglory/observe",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "A module for observing things happening.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"DOM"
|
|
7
|
+
],
|
|
8
|
+
"files": [
|
|
9
|
+
"lib",
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"main": "lib/es2018/index.js",
|
|
13
|
+
"types": "lib/es2018/index.d.ts",
|
|
14
|
+
"repository": "git@github.com:BlackGlory/observe.git",
|
|
15
|
+
"author": "BlackGlory <woshenmedoubuzhidao@blackglory.me>",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"lint": "eslint --ext .js,.jsx,.ts,.tsx --quiet src __tests__",
|
|
19
|
+
"test": "jest --config jest.config.js",
|
|
20
|
+
"test:coverage": "jest --coverage --config jest.config.js",
|
|
21
|
+
"prepublishOnly": "run-s clean build bundle",
|
|
22
|
+
"clean": "run-p clean:*",
|
|
23
|
+
"clean:build": "rimraf lib",
|
|
24
|
+
"clean:bundle": "rimraf dist",
|
|
25
|
+
"build": "run-p build:*",
|
|
26
|
+
"build:es2015": "run-s build:es2015:*",
|
|
27
|
+
"build:es2015:compile": "tsc --project tsconfig.build.json --module commonjs --target es2015 --outDir lib/es2015",
|
|
28
|
+
"build:es2015:patch": "tscpaths -p tsconfig.build.json -s ./src -o ./lib/es2015",
|
|
29
|
+
"build:es2018": "run-s build:es2018:*",
|
|
30
|
+
"build:es2018:compile": "tsc --project tsconfig.build.json --module commonjs --target es2018 --outDir lib/es2018",
|
|
31
|
+
"build:es2018:patch": "tscpaths -p tsconfig.build.json -s ./src -o ./lib/es2018",
|
|
32
|
+
"bundle": "rollup --config rollup.config.js",
|
|
33
|
+
"release": "standard-version"
|
|
34
|
+
},
|
|
35
|
+
"husky": {
|
|
36
|
+
"hooks": {
|
|
37
|
+
"pre-commit": "run-s lint build test",
|
|
38
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@blackglory/jest-matchers": "^0.1.21",
|
|
43
|
+
"@blackglory/wait-for": "^0.3.3",
|
|
44
|
+
"@commitlint/cli": "^13.2.1",
|
|
45
|
+
"@commitlint/config-conventional": "^13.2.0",
|
|
46
|
+
"@rollup/plugin-commonjs": "^21.0.0",
|
|
47
|
+
"@rollup/plugin-json": "^4.1.0",
|
|
48
|
+
"@rollup/plugin-node-resolve": "^13.0.5",
|
|
49
|
+
"@rollup/plugin-replace": "^3.0.0",
|
|
50
|
+
"@rollup/plugin-typescript": "^8.2.5",
|
|
51
|
+
"@types/jest": "^27.0.2",
|
|
52
|
+
"@types/node": "^16.10.9",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
54
|
+
"@typescript-eslint/parser": "^5.0.0",
|
|
55
|
+
"eslint": "^8.0.1",
|
|
56
|
+
"husky": "^4.3.6",
|
|
57
|
+
"jest": "^27.2.5",
|
|
58
|
+
"npm-run-all": "^4.1.5",
|
|
59
|
+
"rimraf": "^3.0.2",
|
|
60
|
+
"rollup": "^2.58.0",
|
|
61
|
+
"rollup-plugin-analyzer": "^4.0.0",
|
|
62
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
63
|
+
"standard-version": "^9.3.1",
|
|
64
|
+
"ts-jest": "^27.0.5",
|
|
65
|
+
"tscpaths": "^0.0.9",
|
|
66
|
+
"tslib": "^2.3.1",
|
|
67
|
+
"typescript": "^4.4.4"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"iterable-operator": "^0.14.3",
|
|
71
|
+
"rxjs": "^7.4.0"
|
|
72
|
+
}
|
|
73
|
+
}
|