@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 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 tool for helping modification html elements
3
-
4
- ## Table of contents
5
- * [Observables](#observables)
6
- * [observeElementMutation](#observe-element-mutation)
7
- * [observeQuerySelector](#observe-query-selector)
8
- * [observeQuerySelectorAll](#observe-query-selector-all)
9
- * [awaitElement](#await-element)
10
- * [awaitRandomElement](#await-random-element)
11
- * [urlChange$](#url-change)
12
- * [Operators](#operators)
13
- * [mergeMapAddedElements](#merge-map-added-elements)
14
- * [mergeMapStringToggle](#merge-map-string-toggle)
15
-
16
- # <a name="observables"></a> Observables
17
- ## <a name="observe-element-mutation"></a> `observeElementMutation`
18
- Converts the callback of the MutationObserver class to an Rx event stream.
19
-
20
- Example:
21
- ```ts
22
- observeElementMutation(
23
- document.querySelector('#my-element'),
24
- { attributeFilter: ['data-my-data'] },
25
- ).subscribe(console.log);
26
- ```
27
-
28
- ## <a name="observe-query-selector"></a> `observeQuerySelector`
29
- Returns change (addition and deletion) of element that match selectors, like an Rx stream.
30
-
31
- Example:
32
- ```ts
33
- observeQuerySelector(
34
- '.my-child',
35
- {
36
- parent: document.querySelector('#my-parent'),
37
- has: '.my-sub-child',
38
- filter: element => element.classList.contains('.my-child-modifier'),
39
- }
40
- ).subscribe(console.log);
41
- ```
42
- Example log:
43
- ```ts
44
- {added: Element, target: Element, removed: undefined};
45
- {added: undefined, target: undefined, removed: Element};
46
- ```
47
-
48
- ## <a name="observe-query-selector-all"></a> `observeQuerySelectorAll`
49
- Returns changes (additions and deletions) of elements that match selectors, like an Rx stream.
50
-
51
- Example:
52
- ```ts
53
- observeQuerySelectorAll(
54
- '.my-child',
55
- {
56
- parent: document.querySelector('#my-parent'),
57
- has: '.my-sub-child',
58
- filter: element => element.classList.contains('.my-child-modifier'),
59
- }
60
- ).subscribe(console.log);
61
- ```
62
- Example log:
63
- ```ts
64
- {added: [Element], target: [Element, Element], removed: []};
65
- {added: [], target: [Element], removed: [Element]};
66
- ```
67
-
68
- ## <a name="await-element"></a> `awaitElement`
69
- 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.
70
-
71
- Example:
72
- ```ts
73
- awaitElement('#my-element')
74
- .subscribe(console.log);
75
- ```
76
-
77
- ## <a name="await-random-element"></a> `awaitRandomElement`
78
- 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.
79
-
80
- Example:
81
- ```ts
82
- awaitRandomElement('.my-element')
83
- .subscribe(console.log);
84
- ```
85
-
86
- ## <a name="url-change"></a> `urlChange$`
87
- Emit new location url when the URL is changes
88
-
89
- Example:
90
- ```ts
91
- urlChange$.subscribe(console.log);
92
- ```
93
-
94
- # <a name="operators"></a> Operators
95
-
96
- ## <a name="merge-map-added-elements"></a> `mergeMapAddedElements`
97
- Conversion operator to a new stream for each new added element
98
-
99
- Example:
100
- ```ts
101
- observeQuerySelectorAll('.my-button')
102
- .pipe(
103
- mergeMapAddedElements(
104
- element => fromEvent(element, 'click'),
105
- { isTakeUntilRemoved: true }
106
- )
107
- ).subscribe(console.log);
108
- ```
109
-
110
- ## <a name="merge-map-string-toggle"></a> `mergeMapStringToggle`
111
- The operator creates a separate stream when the source string is validated.
112
-
113
- Example:
114
- ```ts
115
- urlChange$
116
- .pipe(
117
- mergeMapStringToggle(
118
- /my-url-segment/,
119
- () => observeQuerySelectorAll('.my-element'),
120
- { isTakeUntilToggle: true },
121
- )
122
- ).subscribe(console.log);
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
+ ```