@plohoj/html-editor 0.0.7 → 0.1.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.
- package/LICENSE +21 -21
- package/README.md +137 -123
- package/dist/index.js +256 -99
- package/dist/index.js.map +1 -1
- package/package.json +25 -25
- package/src/index.ts +25 -23
- package/src/observable/await-element.ts +47 -29
- package/src/observable/await-elements.ts +38 -20
- package/src/observable/await-random-element.ts +40 -22
- package/src/observable/observe-mutation.ts +10 -12
- package/src/observable/observe-pressed-keyboard-buttons.ts +29 -30
- package/src/observable/observe-query-selector-all.ts +154 -101
- package/src/observable/observe-query-selector.ts +176 -112
- package/src/observable/observe-url-changes.ts +23 -0
- package/src/observable/url-change.ts +37 -38
- package/src/operators/blur-element.ts +21 -0
- package/src/operators/click-element.ts +20 -21
- package/src/operators/focus-element.ts +21 -22
- package/src/operators/merge-map-added-elements.ts +120 -77
- package/src/operators/merge-map-by-condition.ts +124 -0
- package/src/operators/merge-map-by-string-condition.ts +57 -0
- package/src/operators/remove-element.ts +8 -9
- package/src/operators/restore-history.ts +53 -51
- package/src/operators/set-input-value.ts +20 -21
- package/src/utils/compose-restore-history.ts +61 -61
- package/src/utils/find-recursively.ts +203 -203
- package/src/utils/random-from-array.ts +6 -6
- package/src/utils/stubs.ts +7 -7
- package/src/operators/merge-map-string-toggle.ts +0 -36
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018 Alexandr Plokhih
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Alexandr Plokhih
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,123 +1,137 @@
|
|
|
1
|
-
# HTML editor
|
|
2
|
-
**`html-editor`** it's a
|
|
3
|
-
|
|
4
|
-
## Table of contents
|
|
5
|
-
* [Observables](#observables)
|
|
6
|
-
* [observeElementMutation](#
|
|
7
|
-
* [observeQuerySelector](#
|
|
8
|
-
* [observeQuerySelectorAll](#
|
|
9
|
-
* [awaitElement](#
|
|
10
|
-
* [awaitRandomElement](#
|
|
11
|
-
* [urlChange
|
|
12
|
-
* [
|
|
13
|
-
|
|
14
|
-
* [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
{added:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
```
|
|
1
|
+
# HTML editor
|
|
2
|
+
**`html-editor`** it's a set of tools that helps find and modify HTML elements in the Rx stream. Useful for browser extensions and userscripts.
|
|
3
|
+
|
|
4
|
+
## Table of contents
|
|
5
|
+
* [Observables](#observables)
|
|
6
|
+
* [`observeElementMutation`](#observeElementMutation)
|
|
7
|
+
* [`observeQuerySelector`](#observeQuerySelector)
|
|
8
|
+
* [`observeQuerySelectorAll`](#observeQuerySelectorAll)
|
|
9
|
+
* [`awaitElement`](#awaitElement)
|
|
10
|
+
* [`awaitRandomElement`](#awaitRandomElement)
|
|
11
|
+
* [`urlChange$`](#urlChange)
|
|
12
|
+
* [`observeUrlChanges`](#observeUrlChanges)
|
|
13
|
+
* [Operators](#operators)
|
|
14
|
+
* [`mergeMapAddedElements`](#mergeMapAddedElements)
|
|
15
|
+
* [`mergeMapStringCondition`](#mergeMapStringCondition)
|
|
16
|
+
|
|
17
|
+
# <a name="observables"></a> Observables
|
|
18
|
+
## <a name="observeElementMutation"></a> `observeElementMutation`
|
|
19
|
+
Converts the callback of the MutationObserver class to an Rx event stream.
|
|
20
|
+
|
|
21
|
+
Example:
|
|
22
|
+
```ts
|
|
23
|
+
observeElementMutation(
|
|
24
|
+
document.querySelector('#my-element')!,
|
|
25
|
+
{ attributeFilter: ['data-my-data'] },
|
|
26
|
+
).subscribe(console.log);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## <a name="observeQuerySelector"></a> `observeQuerySelector`
|
|
30
|
+
Observation changes (addition and deletion) of elements that match to query selectors as an Rx stream.
|
|
31
|
+
|
|
32
|
+
Example:
|
|
33
|
+
```ts
|
|
34
|
+
observeQuerySelector({
|
|
35
|
+
query: '.my-child',
|
|
36
|
+
parent: document.querySelector('#my-parent')!,
|
|
37
|
+
has: '.my-sub-child',
|
|
38
|
+
filter: element => element.classList.contains('.my-child-modifier'),
|
|
39
|
+
}).subscribe(console.log);
|
|
40
|
+
```
|
|
41
|
+
Example log:
|
|
42
|
+
```ts
|
|
43
|
+
{added: Element, target: Element, removed: undefined};
|
|
44
|
+
{added: undefined, target: undefined, removed: Element};
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## <a name="observeQuerySelectorAll"></a> `observeQuerySelectorAll`
|
|
48
|
+
Observation changes (additions and deletions) of elements that match to query selectors as an Rx stream.
|
|
49
|
+
|
|
50
|
+
Example:
|
|
51
|
+
```ts
|
|
52
|
+
observeQuerySelectorAll({
|
|
53
|
+
query: '.my-child',
|
|
54
|
+
parent: document.querySelector('#my-parent')!,
|
|
55
|
+
has: '.my-sub-child',
|
|
56
|
+
filter: element => element.classList.contains('.my-child-modifier'),
|
|
57
|
+
}).subscribe(console.log);
|
|
58
|
+
```
|
|
59
|
+
Example log:
|
|
60
|
+
```ts
|
|
61
|
+
{added: [Element], target: [Element, Element], removed: []};
|
|
62
|
+
{added: [], target: [Element], removed: [Element]};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## <a name="awaitElement"></a> `awaitElement`
|
|
66
|
+
Awaiting only one element to match the selector and returns it as an Rx stream. The stream ends immediately after one element is found / added.
|
|
67
|
+
|
|
68
|
+
Example:
|
|
69
|
+
```ts
|
|
70
|
+
awaitElement('#my-element')
|
|
71
|
+
.subscribe(console.log);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## <a name="awaitRandomElement"></a> `awaitRandomElement`
|
|
75
|
+
Awaiting Expects at least one element to match the selector and returns it as an Rx stream. If there are more than 1 elements, it will return a random one. The stream ends immediately after the elements are found / added.
|
|
76
|
+
|
|
77
|
+
Example:
|
|
78
|
+
```ts
|
|
79
|
+
awaitRandomElement('.my-element')
|
|
80
|
+
.subscribe(console.log);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## <a name="urlChange"></a> `urlChange$`
|
|
84
|
+
Emit new location url when the URL is changes.
|
|
85
|
+
|
|
86
|
+
Example:
|
|
87
|
+
```ts
|
|
88
|
+
urlChange$.subscribe(console.log);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## <a name="observeUrlChanges"></a> `observeUrlChanges`
|
|
92
|
+
Observation of `URL` changes that satisfy the conditions.
|
|
93
|
+
|
|
94
|
+
Example:
|
|
95
|
+
```ts
|
|
96
|
+
observeUrlChanges({ condition: /my-url-segment/ })
|
|
97
|
+
.subscribe(console.log);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
# <a name="operators"></a> Operators
|
|
101
|
+
|
|
102
|
+
## <a name="mergeMapAddedElements"></a> `mergeMapAddedElements`
|
|
103
|
+
Conversion operator to a new stream for each new added element.
|
|
104
|
+
|
|
105
|
+
Example:
|
|
106
|
+
```ts
|
|
107
|
+
observeQuerySelectorAll('.my-button').pipe(
|
|
108
|
+
mergeMapAddedElements(element => fromEvent(element, 'click'))
|
|
109
|
+
).subscribe(console.log);
|
|
110
|
+
```
|
|
111
|
+
It can be more convenient to use the `project` option in [`observeQuerySelector`](#observeQuerySelector) and [`observeQuerySelectorAll`](#observeQuerySelectorAll) functions. Example:
|
|
112
|
+
```ts
|
|
113
|
+
observeQuerySelectorAll({
|
|
114
|
+
query: '.my-button',
|
|
115
|
+
project: element => fromEvent(element, 'click'),
|
|
116
|
+
}).subscribe(console.log);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## <a name="mergeMapStringCondition"></a> `mergeMapStringCondition`
|
|
120
|
+
The operator creates a separate stream when the source string is validated.
|
|
121
|
+
|
|
122
|
+
Example:
|
|
123
|
+
```ts
|
|
124
|
+
urlChange$.pipe(
|
|
125
|
+
mergeMapStringCondition(
|
|
126
|
+
/my-url-segment/,
|
|
127
|
+
() => observeQuerySelectorAll('.my-element'),
|
|
128
|
+
)
|
|
129
|
+
).subscribe(console.log);
|
|
130
|
+
```
|
|
131
|
+
It can be more convenient to use the `project` option in observeUrlChanges function. Example:
|
|
132
|
+
```ts
|
|
133
|
+
observeUrlChanges({
|
|
134
|
+
condition: /my-url-segment/,
|
|
135
|
+
project: () => observeQuerySelectorAll('.my-element')
|
|
136
|
+
}).subscribe(console.log);
|
|
137
|
+
```
|