@plohoj/html-editor 0.0.6 → 0.0.7
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/dist/index.js +59 -33
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/index.ts +4 -0
- package/src/observable/await-element.ts +6 -7
- package/src/observable/await-elements.ts +20 -0
- package/src/observable/await-random-element.ts +6 -7
- package/src/observable/observe-pressed-keyboard-buttons.ts +4 -5
- package/src/operators/click-element.ts +7 -6
- package/src/operators/focus-element.ts +22 -0
- package/src/operators/remove-element.ts +3 -3
- package/src/operators/restore-history.ts +1 -1
- package/src/operators/set-input-value.ts +3 -5
- package/src/utils/find-recursively.ts +9 -8
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { throttleTime, mergeMap, distinctUntilChanged, switchMap, debounceTime, filter, map, take, tap, shareReplay, connect, takeUntil } from 'rxjs/operators';
|
|
2
|
-
import { Observable, concat, defer, EMPTY, of, merge, fromEvent,
|
|
2
|
+
import { Observable, concat, defer, EMPTY, of, merge, fromEvent, from, pipe, tap as tap$1, share, NEVER, takeUntil as takeUntil$1, ignoreElements, ReplaySubject } from 'rxjs';
|
|
3
3
|
|
|
4
4
|
function trueStub() {
|
|
5
5
|
return true;
|
|
@@ -75,15 +75,7 @@ function observeQuerySelector(query, options = {}) {
|
|
|
75
75
|
* The stream ends after one element is found / added.
|
|
76
76
|
*/
|
|
77
77
|
function awaitElement(query, options = {}) {
|
|
78
|
-
return observeQuerySelector(query, options)
|
|
79
|
-
.pipe(debounceTime(options.debounceTime || 0, options.debounceScheduler), filter(changes => !!changes.target), map(changes => changes.target), take(1));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function randomFromArray(array, from = 0, to = array.length) {
|
|
83
|
-
if (to < 0) {
|
|
84
|
-
to = array.length + to;
|
|
85
|
-
}
|
|
86
|
-
return array[Math.floor(Math.random() * (to - from)) + from];
|
|
78
|
+
return observeQuerySelector(query, options).pipe(debounceTime(options.debounceTime || 0, options.debounceScheduler), filter(changes => !!changes.target), map(changes => changes.target), take(1));
|
|
87
79
|
}
|
|
88
80
|
|
|
89
81
|
/** Returns changes (additions and deletions) of elements that match selectors, like an Rx stream. */
|
|
@@ -145,22 +137,35 @@ function observeQuerySelectorAll(query, options = {}) {
|
|
|
145
137
|
return observeQuerySelectorAll$;
|
|
146
138
|
}
|
|
147
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Awaiting only first elements changes to match the selector and returns it as an Rx stream.
|
|
142
|
+
* The stream ends after any element is found / added.
|
|
143
|
+
*/
|
|
144
|
+
function awaitElements(query, options = {}) {
|
|
145
|
+
return observeQuerySelectorAll(query, options).pipe(debounceTime(options.debounceTime || 0, options.debounceScheduler), filter(changes => !!changes.target), map(changes => changes.target), take(1));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function randomFromArray(array, from = 0, to = array.length) {
|
|
149
|
+
if (to < 0) {
|
|
150
|
+
to = array.length + to;
|
|
151
|
+
}
|
|
152
|
+
return array[Math.floor(Math.random() * (to - from)) + from];
|
|
153
|
+
}
|
|
154
|
+
|
|
148
155
|
/**
|
|
149
156
|
* Awaiting Expects at least one element to match the selector and returns it as an Rx stream.
|
|
150
157
|
* If there are more than 1 elements, it will return a random one.
|
|
151
158
|
* The stream ends after the elements are found / added.
|
|
152
159
|
*/
|
|
153
160
|
function awaitRandomElement(query, options = {}) {
|
|
154
|
-
return observeQuerySelectorAll(query, options)
|
|
155
|
-
.pipe(debounceTime(options.debounceTime || 0, options.debounceScheduler), filter(changes => changes.target.length > 0), map(changes => randomFromArray(changes.target)), take(1));
|
|
161
|
+
return observeQuerySelectorAll(query, options).pipe(debounceTime(options.debounceTime || 0, options.debounceScheduler), filter(changes => changes.target.length > 0), map(changes => randomFromArray(changes.target)), take(1));
|
|
156
162
|
}
|
|
157
163
|
|
|
158
164
|
function observePressedKeyboardButtons(options = {}) {
|
|
159
165
|
const target = options.target || window;
|
|
160
166
|
const set = new Set();
|
|
161
167
|
const addKey$ = merge(fromEvent(target, 'keydown'), fromEvent(target, 'keypress')).pipe(filter((event) => !set.has(event.key)), tap((event) => set.add(event.key)));
|
|
162
|
-
const keyRemove$ = fromEvent(target, 'keyup')
|
|
163
|
-
.pipe(filter((event) => set.has(event.key)), tap((event) => set.delete(event.key)));
|
|
168
|
+
const keyRemove$ = fromEvent(target, 'keyup').pipe(filter((event) => set.has(event.key)), tap((event) => set.delete(event.key)));
|
|
164
169
|
return merge(addKey$, keyRemove$).pipe(map(() => set));
|
|
165
170
|
}
|
|
166
171
|
|
|
@@ -192,7 +197,12 @@ const urlChange$ = new Observable(subscriber$ => {
|
|
|
192
197
|
}).pipe(distinctUntilChanged(), shareReplay(1));
|
|
193
198
|
|
|
194
199
|
function clickElementImmediately(element) {
|
|
195
|
-
|
|
200
|
+
if ('click' in element) {
|
|
201
|
+
element.click();
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
element.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
205
|
+
}
|
|
196
206
|
console.log(`Click: `, element);
|
|
197
207
|
}
|
|
198
208
|
function clickElement(element) {
|
|
@@ -200,7 +210,26 @@ function clickElement(element) {
|
|
|
200
210
|
clickElementImmediately(element);
|
|
201
211
|
}
|
|
202
212
|
else {
|
|
203
|
-
return
|
|
213
|
+
return tap((element) => clickElementImmediately(element));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function focusElementImmediately(element) {
|
|
218
|
+
if ('focus' in element) {
|
|
219
|
+
element.focus();
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
element.dispatchEvent(new FocusEvent('focus'));
|
|
223
|
+
element.dispatchEvent(new FocusEvent('focusin', { bubbles: true }));
|
|
224
|
+
}
|
|
225
|
+
console.log(`Focus: `, element);
|
|
226
|
+
}
|
|
227
|
+
function focusElement(element) {
|
|
228
|
+
if (element) {
|
|
229
|
+
focusElementImmediately(element);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
return tap((element) => focusElementImmediately(element));
|
|
204
233
|
}
|
|
205
234
|
}
|
|
206
235
|
|
|
@@ -213,13 +242,9 @@ function assuredArray(values) {
|
|
|
213
242
|
}
|
|
214
243
|
return [];
|
|
215
244
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
: (element) => of(element);
|
|
220
|
-
options = typeof projectOrOptions === 'object' ? projectOrOptions : options;
|
|
221
|
-
const { isTakeUntilRemoved = false } = options || {};
|
|
222
|
-
if (!isTakeUntilRemoved) {
|
|
245
|
+
/** Conversion operator to a new stream for each new added element */
|
|
246
|
+
function mergeMapAddedElements(project, options) {
|
|
247
|
+
if (!(options === null || options === void 0 ? void 0 : options.isTakeUntilRemoved)) {
|
|
223
248
|
return source$ => source$.pipe(mergeMap(changes => {
|
|
224
249
|
const added = assuredArray(changes.added);
|
|
225
250
|
if (added.length === 0) {
|
|
@@ -263,10 +288,10 @@ function mergeMapStringToggle(condition, project, options) {
|
|
|
263
288
|
}
|
|
264
289
|
|
|
265
290
|
function removeElement() {
|
|
266
|
-
return
|
|
291
|
+
return tap((element) => {
|
|
267
292
|
element.remove();
|
|
268
293
|
console.log(`Remove: `, element);
|
|
269
|
-
})
|
|
294
|
+
});
|
|
270
295
|
}
|
|
271
296
|
|
|
272
297
|
function restoreHistory(options) {
|
|
@@ -302,12 +327,12 @@ function restoreHistory(options) {
|
|
|
302
327
|
function setInputValueImmediately(element, value) {
|
|
303
328
|
element.value = value;
|
|
304
329
|
element.focus();
|
|
305
|
-
element.dispatchEvent(new Event('input'
|
|
330
|
+
element.dispatchEvent(new Event('input'));
|
|
306
331
|
console.log(`Set value: `, { element, value });
|
|
307
332
|
}
|
|
308
333
|
function setInputValue(elementOrValue, value) {
|
|
309
334
|
if (typeof elementOrValue === 'string') {
|
|
310
|
-
return
|
|
335
|
+
return tap((element) => setInputValueImmediately(element, elementOrValue));
|
|
311
336
|
}
|
|
312
337
|
else {
|
|
313
338
|
setInputValueImmediately(elementOrValue, value);
|
|
@@ -349,6 +374,7 @@ function findRecursively(obj, options = {}) {
|
|
|
349
374
|
const needSeen = new Set([{
|
|
350
375
|
value: obj,
|
|
351
376
|
depth: 0,
|
|
377
|
+
path: '',
|
|
352
378
|
}]);
|
|
353
379
|
const { matcher = falseStub, filter = trueStub, continueAfterGetterError = trueStub, stop = falseStub, minDepth = 1, maxDepth = Infinity, } = options;
|
|
354
380
|
const pathRegExpCheck = options.pathRegExp
|
|
@@ -368,7 +394,7 @@ function findRecursively(obj, options = {}) {
|
|
|
368
394
|
if (seenPathsForValue) {
|
|
369
395
|
// TODO windows or document
|
|
370
396
|
// TODO List of visited objects, but with the wrong path
|
|
371
|
-
const hasCircularPath = seenPathsForValue.some(path => options.path
|
|
397
|
+
const hasCircularPath = seenPathsForValue.some(path => options.path.includes(path));
|
|
372
398
|
if (hasCircularPath) {
|
|
373
399
|
return;
|
|
374
400
|
}
|
|
@@ -415,12 +441,12 @@ function findRecursively(obj, options = {}) {
|
|
|
415
441
|
const incrementalDepth = depth + 1;
|
|
416
442
|
needSeen.delete(iterator.value);
|
|
417
443
|
if (value instanceof Array) {
|
|
418
|
-
iterateArrayLike(value.entries(), (fieldIndex) => `${path
|
|
444
|
+
iterateArrayLike(value.entries(), (fieldIndex) => `${path}[${fieldIndex}]`, incrementalDepth);
|
|
419
445
|
}
|
|
420
|
-
if (value instanceof Map) {
|
|
421
|
-
iterateArrayLike(value.entries(), (fieldIndex) => `${path
|
|
446
|
+
else if (value instanceof Map) {
|
|
447
|
+
iterateArrayLike(value.entries(), (fieldIndex) => `${path}{${fieldIndex}}`, incrementalDepth);
|
|
422
448
|
}
|
|
423
|
-
if (value instanceof Set) {
|
|
449
|
+
else if (value instanceof Set) {
|
|
424
450
|
for (const [fieldIndex, fieldValue] of [...value].entries()) {
|
|
425
451
|
checkForNeedSeen({
|
|
426
452
|
field: fieldValue,
|
|
@@ -467,5 +493,5 @@ function findRecursively(obj, options = {}) {
|
|
|
467
493
|
return searched;
|
|
468
494
|
}
|
|
469
495
|
|
|
470
|
-
export { awaitElement, awaitRandomElement, clickElement, composeRestoreHistory, findRecursively, mergeMapAddedElements, mergeMapStringToggle, observeElementMutation, observePressedKeyboardButtons, observeQuerySelector, observeQuerySelectorAll, randomFromArray, removeElement, restoreHistory, setInputValue, urlChange$ };
|
|
496
|
+
export { awaitElement, awaitElements, awaitRandomElement, clickElement, composeRestoreHistory, findRecursively, focusElement, mergeMapAddedElements, mergeMapStringToggle, observeElementMutation, observePressedKeyboardButtons, observeQuerySelector, observeQuerySelectorAll, randomFromArray, removeElement, restoreHistory, setInputValue, urlChange$ };
|
|
471
497
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plohoj/html-editor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "html-editor it's a tool for helping modification html elements",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
"license": "ISC",
|
|
14
14
|
"module": "./dist/index.js",
|
|
15
15
|
"types": "./src/index.ts",
|
|
16
|
+
"type": "module",
|
|
16
17
|
"dependencies": {
|
|
17
18
|
"rxjs": "^7.0.0"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
|
-
"rollup": "^
|
|
21
|
-
"rollup-plugin-typescript2": "^0.
|
|
22
|
-
"typescript": "^4.
|
|
21
|
+
"rollup": "^3.9.1",
|
|
22
|
+
"rollup-plugin-typescript2": "^0.34.1",
|
|
23
|
+
"typescript": "^4.9.4"
|
|
23
24
|
}
|
|
24
25
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
// Observable
|
|
2
2
|
export { awaitElement, IAwaitElementOptions } from "./observable/await-element";
|
|
3
|
+
export { awaitElements } from './observable/await-elements';
|
|
3
4
|
export { awaitRandomElement } from './observable/await-random-element';
|
|
4
5
|
export { observeElementMutation } from "./observable/observe-mutation";
|
|
5
6
|
export { IObservePressedKeyboardButtonsOptions, observePressedKeyboardButtons } from './observable/observe-pressed-keyboard-buttons';
|
|
6
7
|
export { IObserveElementChange, IObserveQuerySelectorBaseOptions, IObserveQuerySelectorOptions, observeQuerySelector } from "./observable/observe-query-selector";
|
|
7
8
|
export { IObservedElementsChanges, observeQuerySelectorAll } from "./observable/observe-query-selector-all";
|
|
8
9
|
export { urlChange$ } from "./observable/url-change";
|
|
10
|
+
|
|
9
11
|
// Operators
|
|
10
12
|
export { clickElement } from "./operators/click-element";
|
|
13
|
+
export { focusElement } from './operators/focus-element';
|
|
11
14
|
export { mergeMapAddedElements } from "./operators/merge-map-added-elements";
|
|
12
15
|
export { mergeMapStringToggle } from "./operators/merge-map-string-toggle";
|
|
13
16
|
export { removeElement } from "./operators/remove-element";
|
|
14
17
|
export { IRestoredHistoryOption, restoreHistory } from './operators/restore-history';
|
|
15
18
|
export { setInputValue } from "./operators/set-input-value";
|
|
19
|
+
|
|
16
20
|
// Utils
|
|
17
21
|
export { ComposedRestoredHistoryOperatorsArray, ComposedRestoredHistoryOperatorsList, ComposedRestoredHistoryOperatorsRecord, ComposedRestoredHistoryOptionList, composeRestoreHistory, IComposedRestoredHistory } from './utils/compose-restore-history';
|
|
18
22
|
export { findRecursively, FindRecursivelyContinue, FindRecursivelyMatcher, FindRecursivelyResult, IFindRecursivelyMatherOptions, IFindRecursivelyOptions } from "./utils/find-recursively";
|
|
@@ -20,11 +20,10 @@ export function awaitElement<T extends Element = Element>(
|
|
|
20
20
|
query: string,
|
|
21
21
|
options: IAwaitElementOptions<T> = {},
|
|
22
22
|
): Observable<T> {
|
|
23
|
-
return observeQuerySelector<T>(query, options)
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
);
|
|
23
|
+
return observeQuerySelector<T>(query, options).pipe(
|
|
24
|
+
debounceTime(options.debounceTime || 0, options.debounceScheduler),
|
|
25
|
+
filter(changes => !!changes.target),
|
|
26
|
+
map(changes => changes.target!),
|
|
27
|
+
take(1),
|
|
28
|
+
);
|
|
30
29
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { debounceTime, filter, map, take } from "rxjs/operators";
|
|
3
|
+
import { IAwaitElementOptions } from './await-element';
|
|
4
|
+
import { observeQuerySelectorAll } from './observe-query-selector-all';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Awaiting only first elements changes to match the selector and returns it as an Rx stream.
|
|
8
|
+
* The stream ends after any element is found / added.
|
|
9
|
+
*/
|
|
10
|
+
export function awaitElements<T extends Element = Element>(
|
|
11
|
+
query: string,
|
|
12
|
+
options: IAwaitElementOptions<T> = {},
|
|
13
|
+
): Observable<T[]> {
|
|
14
|
+
return observeQuerySelectorAll<T>(query, options).pipe(
|
|
15
|
+
debounceTime(options.debounceTime || 0, options.debounceScheduler),
|
|
16
|
+
filter(changes => !!changes.target),
|
|
17
|
+
map(changes => changes.target!),
|
|
18
|
+
take(1),
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -13,11 +13,10 @@ export function awaitRandomElement<T extends Element = Element>(
|
|
|
13
13
|
query: string,
|
|
14
14
|
options: IAwaitElementOptions<T> = {},
|
|
15
15
|
): Observable<T> {
|
|
16
|
-
return observeQuerySelectorAll<T>(query, options)
|
|
17
|
-
.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
);
|
|
16
|
+
return observeQuerySelectorAll<T>(query, options).pipe(
|
|
17
|
+
debounceTime(options.debounceTime || 0, options.debounceScheduler),
|
|
18
|
+
filter(changes => changes.target.length > 0),
|
|
19
|
+
map(changes => randomFromArray(changes.target)),
|
|
20
|
+
take(1)
|
|
21
|
+
);
|
|
23
22
|
}
|
|
@@ -19,11 +19,10 @@ export function observePressedKeyboardButtons(
|
|
|
19
19
|
filter((event: KeyboardEvent) => !set.has(event.key)),
|
|
20
20
|
tap((event: KeyboardEvent) => set.add(event.key)),
|
|
21
21
|
)
|
|
22
|
-
const keyRemove$ = fromEvent(target, 'keyup')
|
|
23
|
-
.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
);
|
|
22
|
+
const keyRemove$ = fromEvent(target, 'keyup').pipe(
|
|
23
|
+
filter((event: KeyboardEvent) => set.has(event.key)),
|
|
24
|
+
tap((event: KeyboardEvent) => set.delete(event.key)),
|
|
25
|
+
);
|
|
27
26
|
return merge(
|
|
28
27
|
addKey$,
|
|
29
28
|
keyRemove$,
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { MonoTypeOperatorFunction
|
|
1
|
+
import { MonoTypeOperatorFunction } from "rxjs";
|
|
2
2
|
import { tap } from "rxjs/operators";
|
|
3
3
|
|
|
4
4
|
function clickElementImmediately(element: Element): void {
|
|
5
|
-
|
|
5
|
+
if ('click' in element) {
|
|
6
|
+
(element as HTMLElement).click();
|
|
7
|
+
} else {
|
|
8
|
+
element.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
9
|
+
}
|
|
6
10
|
console.log(`Click: `, element);
|
|
7
11
|
}
|
|
8
12
|
|
|
9
|
-
|
|
10
13
|
export function clickElement<T extends Element>(): MonoTypeOperatorFunction<T>;
|
|
11
14
|
export function clickElement<T extends Element>(element: T): void;
|
|
12
15
|
export function clickElement<T extends Element>(element?: T): MonoTypeOperatorFunction<T> | void {
|
|
13
16
|
if (element) {
|
|
14
17
|
clickElementImmediately(element);
|
|
15
18
|
} else {
|
|
16
|
-
return
|
|
17
|
-
tap((element: T) => clickElementImmediately(element)),
|
|
18
|
-
);
|
|
19
|
+
return tap((element: T) => clickElementImmediately(element));
|
|
19
20
|
}
|
|
20
21
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MonoTypeOperatorFunction } from "rxjs";
|
|
2
|
+
import { tap } from "rxjs/operators";
|
|
3
|
+
|
|
4
|
+
function focusElementImmediately(element: Element): void {
|
|
5
|
+
if ('focus' in element) {
|
|
6
|
+
(element as HTMLElement).focus();
|
|
7
|
+
} else {
|
|
8
|
+
element.dispatchEvent(new FocusEvent('focus'));
|
|
9
|
+
element.dispatchEvent(new FocusEvent('focusin', {bubbles: true}));
|
|
10
|
+
}
|
|
11
|
+
console.log(`Focus: `, element);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function focusElement<T extends Element>(): MonoTypeOperatorFunction<T>;
|
|
15
|
+
export function focusElement<T extends Element>(element: T): void;
|
|
16
|
+
export function focusElement<T extends Element>(element?: T): MonoTypeOperatorFunction<T> | void {
|
|
17
|
+
if (element) {
|
|
18
|
+
focusElementImmediately(element);
|
|
19
|
+
} else {
|
|
20
|
+
return tap((element: T) => focusElementImmediately(element));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { MonoTypeOperatorFunction
|
|
1
|
+
import { MonoTypeOperatorFunction } from "rxjs";
|
|
2
2
|
import { tap } from "rxjs/operators";
|
|
3
3
|
|
|
4
4
|
export function removeElement<T extends Element>(): MonoTypeOperatorFunction<T> {
|
|
5
|
-
return
|
|
5
|
+
return tap((element) => {
|
|
6
6
|
element.remove();
|
|
7
7
|
console.log(`Remove: `, element);
|
|
8
|
-
})
|
|
8
|
+
});
|
|
9
9
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { concat, defer, EMPTY, ignoreElements, merge, MonoTypeOperatorFunction, NEVER, Observable, ObservableInput, of, share,
|
|
1
|
+
import { concat, defer, EMPTY, ignoreElements, merge, MonoTypeOperatorFunction, NEVER, Observable, ObservableInput, of, share, takeUntil, tap } from 'rxjs';
|
|
2
2
|
|
|
3
3
|
export interface IRestoredHistoryOption<T = unknown> {
|
|
4
4
|
getStory(): T | undefined;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { MonoTypeOperatorFunction
|
|
1
|
+
import { MonoTypeOperatorFunction } from "rxjs";
|
|
2
2
|
import { tap } from "rxjs/operators";
|
|
3
3
|
|
|
4
4
|
function setInputValueImmediately(element: HTMLInputElement, value: string): void {
|
|
5
5
|
element.value = value;
|
|
6
6
|
element.focus();
|
|
7
|
-
element.dispatchEvent(new Event('input'
|
|
7
|
+
element.dispatchEvent(new Event('input'));
|
|
8
8
|
console.log(`Set value: `, { element, value });
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -14,9 +14,7 @@ export function setInputValue(
|
|
|
14
14
|
elementOrValue: HTMLInputElement | string, value?: string
|
|
15
15
|
): MonoTypeOperatorFunction<HTMLInputElement> | void {
|
|
16
16
|
if (typeof elementOrValue === 'string') {
|
|
17
|
-
return
|
|
18
|
-
tap((element: HTMLInputElement) => setInputValueImmediately(element, elementOrValue))
|
|
19
|
-
);
|
|
17
|
+
return tap((element: HTMLInputElement) => setInputValueImmediately(element, elementOrValue));
|
|
20
18
|
} else {
|
|
21
19
|
setInputValueImmediately(elementOrValue, value!);
|
|
22
20
|
}
|
|
@@ -3,7 +3,7 @@ import { falseStub, trueStub } from './stubs';
|
|
|
3
3
|
export interface IFindRecursivelyMatherOptions {
|
|
4
4
|
field?: unknown;
|
|
5
5
|
value: unknown;
|
|
6
|
-
path
|
|
6
|
+
path: string;
|
|
7
7
|
depth: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -58,11 +58,12 @@ export interface IFindRecursivelyOptions {
|
|
|
58
58
|
/** Recursive search on entity fields */
|
|
59
59
|
export function findRecursively(obj: unknown, options: IFindRecursivelyOptions = {}): FindRecursivelyResult {
|
|
60
60
|
/** {value: path[]} */
|
|
61
|
-
const seen = new Map<unknown, Array<string
|
|
61
|
+
const seen = new Map<unknown, Array<string>>();
|
|
62
62
|
const searched: Record<string, unknown> = {};
|
|
63
63
|
const needSeen = new Set<IFindRecursivelyMatherOptions>([{
|
|
64
64
|
value: obj,
|
|
65
65
|
depth: 0,
|
|
66
|
+
path: '',
|
|
66
67
|
}]);
|
|
67
68
|
const {
|
|
68
69
|
matcher = falseStub,
|
|
@@ -86,11 +87,11 @@ export function findRecursively(obj: unknown, options: IFindRecursivelyOptions =
|
|
|
86
87
|
}
|
|
87
88
|
const isPrimitiveOrFunction = options.value === null || typeof options.value !== 'object';
|
|
88
89
|
if (!isPrimitiveOrFunction) {
|
|
89
|
-
const seenPathsForValue: Array<string
|
|
90
|
+
const seenPathsForValue: Array<string> | undefined = seen.get(options.value);
|
|
90
91
|
if (seenPathsForValue) {
|
|
91
92
|
// TODO windows or document
|
|
92
93
|
// TODO List of visited objects, but with the wrong path
|
|
93
|
-
const hasCircularPath = seenPathsForValue.some(path => options.path
|
|
94
|
+
const hasCircularPath = seenPathsForValue.some(path => options.path.includes(path));
|
|
94
95
|
if (hasCircularPath) {
|
|
95
96
|
return;
|
|
96
97
|
}
|
|
@@ -145,16 +146,16 @@ export function findRecursively(obj: unknown, options: IFindRecursivelyOptions =
|
|
|
145
146
|
if (value instanceof Array) {
|
|
146
147
|
iterateArrayLike(
|
|
147
148
|
(value as unknown[]).entries(),
|
|
148
|
-
(fieldIndex) => `${path
|
|
149
|
+
(fieldIndex) => `${path}[${fieldIndex}]`,
|
|
149
150
|
incrementalDepth,
|
|
150
151
|
);
|
|
151
|
-
} if (value instanceof Map) {
|
|
152
|
+
} else if (value instanceof Map) {
|
|
152
153
|
iterateArrayLike(
|
|
153
154
|
(value as Map<unknown, unknown>).entries(),
|
|
154
|
-
(fieldIndex) => `${path
|
|
155
|
+
(fieldIndex) => `${path}{${fieldIndex}}`,
|
|
155
156
|
incrementalDepth,
|
|
156
157
|
);
|
|
157
|
-
} if (value instanceof Set) {
|
|
158
|
+
} else if (value instanceof Set) {
|
|
158
159
|
for (const [fieldIndex, fieldValue] of ([...value] as unknown[]).entries()) {
|
|
159
160
|
checkForNeedSeen({
|
|
160
161
|
field: fieldValue,
|