@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/dist/index.js CHANGED
@@ -1,5 +1,73 @@
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, from, pipe, tap as tap$1, share, NEVER, takeUntil as takeUntil$1, ignoreElements, ReplaySubject } from 'rxjs';
1
+ import { mergeMap, EMPTY, merge, connect, filter, takeUntil, Observable, concat, defer, throttleTime, distinctUntilChanged, switchMap, of, debounceTime, map, take, fromEvent, tap, shareReplay, share, NEVER, ignoreElements, ReplaySubject } from 'rxjs';
2
+ import { __rest } from 'tslib';
3
+
4
+ function assuredArray(values) {
5
+ if (values instanceof Array) {
6
+ return values;
7
+ }
8
+ if (values) {
9
+ return [values];
10
+ }
11
+ return [];
12
+ }
13
+ function mergeMapAddedElements(projectOrOptions, options) {
14
+ // #region Options parsing
15
+ let project;
16
+ let stableOptions;
17
+ if (typeof projectOrOptions === 'function') {
18
+ project = projectOrOptions;
19
+ stableOptions = options || {};
20
+ }
21
+ else {
22
+ project = projectOrOptions.project;
23
+ stableOptions = projectOrOptions;
24
+ }
25
+ const { takeUntil: takeUntilOption = 'removed' } = stableOptions;
26
+ // #endregion
27
+ if (takeUntilOption === 'always') {
28
+ return source$ => source$.pipe(mergeMap(changes => {
29
+ const added = assuredArray(changes.added);
30
+ if (added.length === 0) {
31
+ return EMPTY;
32
+ }
33
+ const addedObservers = added.map(project);
34
+ return merge(...addedObservers);
35
+ }));
36
+ }
37
+ return source$ => source$.pipe(connect(connectedSource$ => connectedSource$.pipe(mergeMap(changes => {
38
+ const added = assuredArray(changes.added);
39
+ if (added.length === 0) {
40
+ return EMPTY;
41
+ }
42
+ const addedObservers = added.map(addedElement => {
43
+ let takeUntil$;
44
+ if (takeUntilOption === 'removed') {
45
+ takeUntil$ = connectedSource$.pipe(filter(connectedChanges => connectedChanges.removed instanceof Array
46
+ ? connectedChanges.removed.indexOf(addedElement) !== -1
47
+ : connectedChanges.removed === addedElement));
48
+ }
49
+ else {
50
+ let wasRemoved = false;
51
+ takeUntil$ = connectedSource$.pipe(filter(connectedChanges => {
52
+ if (!wasRemoved) {
53
+ wasRemoved = connectedChanges.removed instanceof Array
54
+ ? connectedChanges.removed.indexOf(addedElement) !== -1
55
+ : connectedChanges.removed === addedElement;
56
+ }
57
+ if (wasRemoved) {
58
+ const hasTarget = connectedChanges.target instanceof Array
59
+ ? connectedChanges.target.indexOf(addedElement) !== -1
60
+ : connectedChanges.target === addedElement;
61
+ return hasTarget;
62
+ }
63
+ return false;
64
+ }));
65
+ }
66
+ return project(addedElement).pipe(takeUntil(takeUntil$));
67
+ });
68
+ return merge(...addedObservers);
69
+ }))));
70
+ }
3
71
 
4
72
  function trueStub() {
5
73
  return true;
@@ -8,9 +76,7 @@ function falseStub() {
8
76
  return false;
9
77
  }
10
78
 
11
- /**
12
- * Converts the callback of the MutationObserver class to an Rx event stream
13
- */
79
+ /** Converts the callback of the {@link MutationObserver} class to an Rx event stream */
14
80
  function observeElementMutation(node, options) {
15
81
  return new Observable(subscriber => {
16
82
  const mutationObserver = new MutationObserver(mutation => subscriber.next(mutation));
@@ -19,18 +85,36 @@ function observeElementMutation(node, options) {
19
85
  });
20
86
  }
21
87
 
22
- /**
23
- * Returns change (addition and deletion) of element that match selectors, like an Rx stream.
24
- */
25
- function observeQuerySelector(query, options = {}) {
26
- const { parent = document.documentElement, asRemovedWhen, filter = trueStub, } = options;
88
+ function observeQuerySelector(queryOrOptions, projectOrOptions, options) {
89
+ // #region Options parsing
90
+ let query;
91
+ let project;
92
+ let stableOptions;
93
+ if (typeof queryOrOptions === 'string') {
94
+ query = queryOrOptions;
95
+ if (typeof projectOrOptions === 'function') {
96
+ project = projectOrOptions;
97
+ stableOptions = options || {};
98
+ }
99
+ else {
100
+ stableOptions = projectOrOptions || {};
101
+ project = projectOrOptions === null || projectOrOptions === void 0 ? void 0 : projectOrOptions.project;
102
+ }
103
+ }
104
+ else {
105
+ stableOptions = queryOrOptions;
106
+ query = queryOrOptions.query;
107
+ project = queryOrOptions === null || queryOrOptions === void 0 ? void 0 : queryOrOptions.project;
108
+ }
109
+ const { parent = document.documentElement, asRemovedWhen, filter = trueStub, has, tap } = stableOptions, restOfStableOptions = __rest(stableOptions, ["parent", "asRemovedWhen", "filter", "has", "tap"]);
110
+ // #endregion
27
111
  let targetElement;
28
112
  function checkChanges() {
29
113
  const querySelectedElements = parent.querySelectorAll(query);
30
114
  let filteredSelectedElement;
31
115
  const changes = {};
32
116
  for (const querySelectedElement of querySelectedElements) {
33
- if (options.has && !querySelectedElement.querySelector(options.has)) {
117
+ if (has && !querySelectedElement.querySelector(has)) {
34
118
  continue;
35
119
  }
36
120
  if (!filter(querySelectedElement)) {
@@ -47,12 +131,14 @@ function observeQuerySelector(query, options = {}) {
47
131
  }
48
132
  if (filteredSelectedElement) {
49
133
  changes.added = filteredSelectedElement;
134
+ tap === null || tap === void 0 ? void 0 : tap(filteredSelectedElement);
50
135
  }
51
136
  changes.target = filteredSelectedElement;
52
137
  targetElement = filteredSelectedElement;
53
138
  return of(changes);
54
139
  }
55
140
  const observeQuerySelector$ = concat(defer(() => checkChanges()), observeElementMutation(parent, { subtree: true, childList: true }).pipe(throttleTime(0, undefined, { leading: true, trailing: true }), mergeMap(checkChanges)));
141
+ let observeQuerySelectorWithRemovedWhen$ = observeQuerySelector$;
56
142
  if (asRemovedWhen) {
57
143
  const removedObserver$ = defer(() => {
58
144
  if (!targetElement) {
@@ -64,30 +150,60 @@ function observeQuerySelector(query, options = {}) {
64
150
  targetElement = undefined;
65
151
  return of(changes);
66
152
  });
67
- const observeQuerySelectorWithRemovedWhen$ = asRemovedWhen.pipe(distinctUntilChanged(), switchMap(asRemoved => asRemoved ? removedObserver$ : observeQuerySelector$));
68
- return observeQuerySelectorWithRemovedWhen$;
153
+ observeQuerySelectorWithRemovedWhen$ = asRemovedWhen.pipe(distinctUntilChanged(), switchMap(asRemoved => asRemoved ? removedObserver$ : observeQuerySelector$));
69
154
  }
70
- return observeQuerySelector$;
155
+ if (project) {
156
+ return observeQuerySelectorWithRemovedWhen$.pipe(mergeMapAddedElements(Object.assign({ project }, restOfStableOptions)));
157
+ }
158
+ return observeQuerySelectorWithRemovedWhen$;
71
159
  }
72
160
 
73
- /**
74
- * Awaiting only one element to match the selector and returns it as an Rx stream.
75
- * The stream ends after one element is found / added.
76
- */
77
- function awaitElement(query, options = {}) {
78
- return observeQuerySelector(query, options).pipe(debounceTime(options.debounceTime || 0, options.debounceScheduler), filter(changes => !!changes.target), map(changes => changes.target), take(1));
161
+ function awaitElement(queryOrOptions, options) {
162
+ // #region Options parsing
163
+ let query;
164
+ let stableOptions;
165
+ if (typeof queryOrOptions === 'string') {
166
+ query = queryOrOptions;
167
+ stableOptions = options || {};
168
+ }
169
+ else {
170
+ stableOptions = queryOrOptions;
171
+ query = queryOrOptions.query;
172
+ }
173
+ // #endregion
174
+ return observeQuerySelector(query, stableOptions).pipe(debounceTime(stableOptions.debounceTime || 0, stableOptions.debounceScheduler), filter(changes => !!changes.target), map(changes => changes.target), take(1));
79
175
  }
80
176
 
81
- /** Returns changes (additions and deletions) of elements that match selectors, like an Rx stream. */
82
- function observeQuerySelectorAll(query, options = {}) {
83
- const { parent = document.documentElement, asRemovedWhen, filter = trueStub, } = options;
177
+ function observeQuerySelectorAll(queryOrOptions, projectOrOptions, options) {
178
+ // #region Options parsing
179
+ let query;
180
+ let project;
181
+ let stableOptions;
182
+ if (typeof queryOrOptions === 'string') {
183
+ query = queryOrOptions;
184
+ if (typeof projectOrOptions === 'function') {
185
+ project = projectOrOptions;
186
+ stableOptions = options || {};
187
+ }
188
+ else {
189
+ stableOptions = projectOrOptions || {};
190
+ project = projectOrOptions === null || projectOrOptions === void 0 ? void 0 : projectOrOptions.project;
191
+ }
192
+ }
193
+ else {
194
+ stableOptions = queryOrOptions;
195
+ query = queryOrOptions.query;
196
+ project = queryOrOptions === null || queryOrOptions === void 0 ? void 0 : queryOrOptions.project;
197
+ }
198
+ const { parent = document.documentElement, asRemovedWhen, filter = trueStub, has, tap } = stableOptions, restOfStableOptions = __rest(stableOptions, ["parent", "asRemovedWhen", "filter", "has", "tap"]);
199
+ // #endregion
84
200
  const targetElements = new Set();
85
201
  function checkChanges() {
86
202
  const addedElements = new Set();
87
203
  const targetElementsDiff = new Set(targetElements);
88
204
  const querySelectedElements = new Set(parent.querySelectorAll(query));
89
205
  for (const querySelectedElement of querySelectedElements) {
90
- if (options.has && !querySelectedElement.querySelector(options.has)) {
206
+ if (has && !querySelectedElement.querySelector(has)) {
91
207
  continue;
92
208
  }
93
209
  if (!filter(querySelectedElement)) {
@@ -109,6 +225,7 @@ function observeQuerySelectorAll(query, options = {}) {
109
225
  }
110
226
  for (const addedElement of addedElements) {
111
227
  targetElements.add(addedElement);
228
+ tap === null || tap === void 0 ? void 0 : tap(addedElement);
112
229
  }
113
230
  const changes = {
114
231
  target: [...targetElements.values()],
@@ -117,7 +234,8 @@ function observeQuerySelectorAll(query, options = {}) {
117
234
  };
118
235
  return of(changes);
119
236
  }
120
- let observeQuerySelectorAll$ = concat(defer(() => checkChanges()), observeElementMutation(parent, { subtree: true, childList: true }).pipe(throttleTime(0, undefined, { leading: true, trailing: true }), mergeMap(checkChanges)));
237
+ const observeQuerySelectorAll$ = concat(defer(() => checkChanges()), observeElementMutation(parent, { subtree: true, childList: true }).pipe(throttleTime(0, undefined, { leading: true, trailing: true }), mergeMap(checkChanges)));
238
+ let observeQuerySelectorAllWithRemovedWhen$ = observeQuerySelectorAll$;
121
239
  if (asRemovedWhen) {
122
240
  const removedObserver$ = defer(() => {
123
241
  if (targetElements.size === 0) {
@@ -131,18 +249,28 @@ function observeQuerySelectorAll(query, options = {}) {
131
249
  targetElements.clear();
132
250
  return of(changes);
133
251
  });
134
- const observeQuerySelectorAllWithRemovedWhen$ = asRemovedWhen.pipe(distinctUntilChanged(), switchMap(asRemoved => asRemoved ? removedObserver$ : observeQuerySelectorAll$));
135
- return observeQuerySelectorAllWithRemovedWhen$;
252
+ observeQuerySelectorAllWithRemovedWhen$ = asRemovedWhen.pipe(distinctUntilChanged(), switchMap(asRemoved => asRemoved ? removedObserver$ : observeQuerySelectorAll$));
253
+ }
254
+ if (project) {
255
+ return observeQuerySelectorAllWithRemovedWhen$.pipe(mergeMapAddedElements(Object.assign({ project }, restOfStableOptions)));
136
256
  }
137
- return observeQuerySelectorAll$;
257
+ return observeQuerySelectorAllWithRemovedWhen$;
138
258
  }
139
259
 
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));
260
+ function awaitElements(queryOrOptions, options) {
261
+ // #region Options parsing
262
+ let query;
263
+ let stableOptions;
264
+ if (typeof queryOrOptions === 'string') {
265
+ query = queryOrOptions;
266
+ stableOptions = options || {};
267
+ }
268
+ else {
269
+ stableOptions = queryOrOptions;
270
+ query = queryOrOptions.query;
271
+ }
272
+ // #endregion
273
+ return observeQuerySelectorAll(query, stableOptions).pipe(debounceTime(stableOptions.debounceTime || 0, stableOptions.debounceScheduler), filter(changes => !!changes.target), map(changes => changes.target), take(1));
146
274
  }
147
275
 
148
276
  function randomFromArray(array, from = 0, to = array.length) {
@@ -152,13 +280,20 @@ function randomFromArray(array, from = 0, to = array.length) {
152
280
  return array[Math.floor(Math.random() * (to - from)) + from];
153
281
  }
154
282
 
155
- /**
156
- * Awaiting Expects at least one element to match the selector and returns it as an Rx stream.
157
- * If there are more than 1 elements, it will return a random one.
158
- * The stream ends after the elements are found / added.
159
- */
160
- function awaitRandomElement(query, options = {}) {
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));
283
+ function awaitRandomElement(queryOrOptions, options) {
284
+ // #region Options parsing
285
+ let query;
286
+ let stableOptions;
287
+ if (typeof queryOrOptions === 'string') {
288
+ query = queryOrOptions;
289
+ stableOptions = options || {};
290
+ }
291
+ else {
292
+ stableOptions = queryOrOptions;
293
+ query = queryOrOptions.query;
294
+ }
295
+ // #endregion
296
+ return observeQuerySelectorAll(query, stableOptions).pipe(debounceTime(stableOptions.debounceTime || 0, stableOptions.debounceScheduler), filter(changes => changes.target.length > 0), map(changes => randomFromArray(changes.target)), take(1));
162
297
  }
163
298
 
164
299
  function observePressedKeyboardButtons(options = {}) {
@@ -196,6 +331,82 @@ const urlChange$ = new Observable(subscriber$ => {
196
331
  };
197
332
  }).pipe(distinctUntilChanged(), shareReplay(1));
198
333
 
334
+ function mergeMapByCondition(conditionOrOptions, project, options) {
335
+ // #region Options parsing
336
+ let stableOptions;
337
+ let conditionFn;
338
+ let stableProject;
339
+ if ('condition' in conditionOrOptions) {
340
+ stableOptions = conditionOrOptions;
341
+ conditionFn = conditionOrOptions.condition;
342
+ stableProject = conditionOrOptions.project;
343
+ }
344
+ else {
345
+ conditionFn = conditionOrOptions;
346
+ stableOptions = options || {};
347
+ stableProject = project;
348
+ }
349
+ const { takeFor = 'new', takeUntil: takeUntilOption = 'fail', } = stableOptions;
350
+ // #endregion
351
+ let isPrevConditionPass = false;
352
+ return source$ => source$.pipe(map(source => ({ source, isConditionPassed: conditionFn(source) })), connect(connectedSource$ => {
353
+ let takeUntil$;
354
+ if (takeUntilOption === 'fail') {
355
+ takeUntil$ = connectedSource$.pipe(filter(({ isConditionPassed }) => isConditionPassed));
356
+ }
357
+ else if (takeUntilOption === 'pass') {
358
+ let wasFailed = false;
359
+ takeUntil$ = connectedSource$.pipe(filter(({ isConditionPassed }) => {
360
+ if (isConditionPassed) {
361
+ if (wasFailed) {
362
+ return true;
363
+ }
364
+ }
365
+ else {
366
+ wasFailed = true;
367
+ }
368
+ return false;
369
+ }));
370
+ }
371
+ return connectedSource$.pipe(mergeMap(({ source, isConditionPassed }) => {
372
+ if (isConditionPassed) {
373
+ const isCreateNewProject = takeFor === 'all' || !isPrevConditionPass;
374
+ isPrevConditionPass = true;
375
+ if (isCreateNewProject) {
376
+ if (!stableProject) {
377
+ return of(source);
378
+ }
379
+ let project$ = stableProject(source);
380
+ if (takeUntil$) {
381
+ project$ = project$.pipe(takeUntil(takeUntil$));
382
+ }
383
+ return project$;
384
+ }
385
+ }
386
+ else {
387
+ isPrevConditionPass = false;
388
+ }
389
+ return EMPTY;
390
+ }));
391
+ }));
392
+ }
393
+
394
+ function getStringConditionFunction(condition) {
395
+ return typeof condition === 'function' ? condition : (value) => condition.test(value);
396
+ }
397
+ function mergeMapStringCondition(conditionOrOptions, project, options) {
398
+ if ('condition' in conditionOrOptions) {
399
+ return mergeMapByCondition(Object.assign(Object.assign({}, conditionOrOptions), { condition: getStringConditionFunction(conditionOrOptions.condition) }));
400
+ }
401
+ else {
402
+ return mergeMapByCondition(Object.assign(Object.assign({}, options), { condition: getStringConditionFunction(conditionOrOptions), project }));
403
+ }
404
+ }
405
+
406
+ function observeUrlChanges(options = {}) {
407
+ return urlChange$.pipe(mergeMapStringCondition(Object.assign(Object.assign({}, options), { condition: options.condition || (() => true) })));
408
+ }
409
+
199
410
  function clickElementImmediately(element) {
200
411
  if ('click' in element) {
201
412
  element.click();
@@ -233,60 +444,6 @@ function focusElement(element) {
233
444
  }
234
445
  }
235
446
 
236
- function assuredArray(values) {
237
- if (values instanceof Array) {
238
- return values;
239
- }
240
- if (values) {
241
- return [values];
242
- }
243
- return [];
244
- }
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)) {
248
- return source$ => source$.pipe(mergeMap(changes => {
249
- const added = assuredArray(changes.added);
250
- if (added.length === 0) {
251
- return EMPTY;
252
- }
253
- const addedObservers = added.map(project);
254
- return merge(...addedObservers);
255
- }));
256
- }
257
- return source$ => source$.pipe(connect(connectedSource$ => connectedSource$.pipe(mergeMap(changes => {
258
- const added = assuredArray(changes.added);
259
- if (added.length === 0) {
260
- return EMPTY;
261
- }
262
- const addedObservers = added.map(addedElement => from(project(addedElement)).pipe(takeUntil(connectedSource$.pipe(filter(changes => {
263
- if (changes.removed instanceof Array) {
264
- return changes.removed.indexOf(addedElement) != -1;
265
- }
266
- else {
267
- return changes.removed === addedElement;
268
- }
269
- })))));
270
- return merge(...addedObservers);
271
- }))));
272
- }
273
-
274
- /** The operator creates a separate stream when the source string is validated. */
275
- function mergeMapStringToggle(condition, project, options) {
276
- const mapConditionFn = typeof condition === 'function' ? condition : (url) => condition.test(url);
277
- let urlMatchToggler;
278
- if (typeof project === 'function') {
279
- urlMatchToggler = (isUrlMatch) => isUrlMatch ? from(project()) : EMPTY;
280
- }
281
- else {
282
- urlMatchToggler = (isUrlMatch) => isUrlMatch ? from(project) : EMPTY;
283
- }
284
- const mergeOperator = (options === null || options === void 0 ? void 0 : options.isTakeUntilToggle)
285
- ? switchMap(urlMatchToggler)
286
- : mergeMap(urlMatchToggler);
287
- return pipe(map(mapConditionFn), distinctUntilChanged(), mergeOperator);
288
- }
289
-
290
447
  function removeElement() {
291
448
  return tap((element) => {
292
449
  element.remove();
@@ -299,7 +456,7 @@ function restoreHistory(options) {
299
456
  let hasStory = false;
300
457
  const observeCancel$ = options.cancelRestore
301
458
  ? defer(() => options.cancelRestore())
302
- .pipe(tap$1(() => {
459
+ .pipe(tap(() => {
303
460
  if (hasStory) {
304
461
  options.removeStory();
305
462
  }
@@ -313,10 +470,10 @@ function restoreHistory(options) {
313
470
  hasStory = true;
314
471
  let rested$ = of(story);
315
472
  if (options.cancelRestore) {
316
- rested$ = rested$.pipe(takeUntil$1(observeCancel$));
473
+ rested$ = rested$.pipe(takeUntil(observeCancel$));
317
474
  }
318
475
  return rested$;
319
- }), source$.pipe(tap$1((data) => {
476
+ }), source$.pipe(tap((data) => {
320
477
  options.setStory(data);
321
478
  hasStory = true;
322
479
  })));
@@ -493,5 +650,5 @@ function findRecursively(obj, options = {}) {
493
650
  return searched;
494
651
  }
495
652
 
496
- export { awaitElement, awaitElements, awaitRandomElement, clickElement, composeRestoreHistory, findRecursively, focusElement, mergeMapAddedElements, mergeMapStringToggle, observeElementMutation, observePressedKeyboardButtons, observeQuerySelector, observeQuerySelectorAll, randomFromArray, removeElement, restoreHistory, setInputValue, urlChange$ };
653
+ export { awaitElement, awaitElements, awaitRandomElement, clickElement, composeRestoreHistory, findRecursively, focusElement, mergeMapAddedElements, mergeMapByCondition, mergeMapStringCondition, observeElementMutation, observePressedKeyboardButtons, observeQuerySelector, observeQuerySelectorAll, observeUrlChanges, randomFromArray, removeElement, restoreHistory, setInputValue, urlChange$ };
497
654
  //# 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,25 +1,25 @@
1
- {
2
- "name": "@plohoj/html-editor",
3
- "version": "0.0.7",
4
- "description": "html-editor it's a tool for helping modification html elements",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/plohoj/html-editor.git"
8
- },
9
- "scripts": {
10
- "build": "rollup --config"
11
- },
12
- "author": "Plokhikh Alexandr",
13
- "license": "ISC",
14
- "module": "./dist/index.js",
15
- "types": "./src/index.ts",
16
- "type": "module",
17
- "dependencies": {
18
- "rxjs": "^7.0.0"
19
- },
20
- "devDependencies": {
21
- "rollup": "^3.9.1",
22
- "rollup-plugin-typescript2": "^0.34.1",
23
- "typescript": "^4.9.4"
24
- }
25
- }
1
+ {
2
+ "name": "@plohoj/html-editor",
3
+ "version": "0.1.0",
4
+ "description": "html-editor it's a tool for helping modification html elements",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/plohoj/html-editor.git"
8
+ },
9
+ "scripts": {
10
+ "build": "rollup --config"
11
+ },
12
+ "author": "Plokhikh Alexandr",
13
+ "license": "ISC",
14
+ "module": "./dist/index.js",
15
+ "types": "./src/index.ts",
16
+ "type": "module",
17
+ "dependencies": {
18
+ "rxjs": "^7.0.0"
19
+ },
20
+ "devDependencies": {
21
+ "rollup": "^3.9.1",
22
+ "rollup-plugin-typescript2": "^0.34.1",
23
+ "typescript": "^4.9.4"
24
+ }
25
+ }
package/src/index.ts CHANGED
@@ -1,23 +1,25 @@
1
- // Observable
2
- export { awaitElement, IAwaitElementOptions } from "./observable/await-element";
3
- export { awaitElements } from './observable/await-elements';
4
- export { awaitRandomElement } from './observable/await-random-element';
5
- export { observeElementMutation } from "./observable/observe-mutation";
6
- export { IObservePressedKeyboardButtonsOptions, observePressedKeyboardButtons } from './observable/observe-pressed-keyboard-buttons';
7
- export { IObserveElementChange, IObserveQuerySelectorBaseOptions, IObserveQuerySelectorOptions, observeQuerySelector } from "./observable/observe-query-selector";
8
- export { IObservedElementsChanges, observeQuerySelectorAll } from "./observable/observe-query-selector-all";
9
- export { urlChange$ } from "./observable/url-change";
10
-
11
- // Operators
12
- export { clickElement } from "./operators/click-element";
13
- export { focusElement } from './operators/focus-element';
14
- export { mergeMapAddedElements } from "./operators/merge-map-added-elements";
15
- export { mergeMapStringToggle } from "./operators/merge-map-string-toggle";
16
- export { removeElement } from "./operators/remove-element";
17
- export { IRestoredHistoryOption, restoreHistory } from './operators/restore-history';
18
- export { setInputValue } from "./operators/set-input-value";
19
-
20
- // Utils
21
- export { ComposedRestoredHistoryOperatorsArray, ComposedRestoredHistoryOperatorsList, ComposedRestoredHistoryOperatorsRecord, ComposedRestoredHistoryOptionList, composeRestoreHistory, IComposedRestoredHistory } from './utils/compose-restore-history';
22
- export { findRecursively, FindRecursivelyContinue, FindRecursivelyMatcher, FindRecursivelyResult, IFindRecursivelyMatherOptions, IFindRecursivelyOptions } from "./utils/find-recursively";
23
- export { randomFromArray } from "./utils/random-from-array";
1
+ // Observable
2
+ export { awaitElement, IAwaitElementOptions } from "./observable/await-element";
3
+ export { awaitElements } from './observable/await-elements';
4
+ export { awaitRandomElement } from './observable/await-random-element';
5
+ export { observeElementMutation } from "./observable/observe-mutation";
6
+ export { IObservePressedKeyboardButtonsOptions, observePressedKeyboardButtons } from './observable/observe-pressed-keyboard-buttons';
7
+ export { IObservedElementChange, IObserveQuerySelectorBaseOptions, IObserveQuerySelectorOptions, observeQuerySelector } from "./observable/observe-query-selector";
8
+ export { IObservedElementsChanges, observeQuerySelectorAll } from "./observable/observe-query-selector-all";
9
+ export { urlChange$ } from "./observable/url-change";
10
+
11
+ // Operators
12
+ export { observeUrlChanges } from './observable/observe-url-changes';
13
+ export { clickElement } from "./operators/click-element";
14
+ export { focusElement } from './operators/focus-element';
15
+ export { mergeMapAddedElements } from "./operators/merge-map-added-elements";
16
+ export { mergeMapByCondition } from './operators/merge-map-by-condition';
17
+ export { mergeMapStringCondition } from "./operators/merge-map-by-string-condition";
18
+ export { removeElement } from "./operators/remove-element";
19
+ export { IRestoredHistoryOption, restoreHistory } from './operators/restore-history';
20
+ export { setInputValue } from "./operators/set-input-value";
21
+
22
+ // Utils
23
+ export { ComposedRestoredHistoryOperatorsArray, ComposedRestoredHistoryOperatorsList, ComposedRestoredHistoryOperatorsRecord, ComposedRestoredHistoryOptionList, composeRestoreHistory, IComposedRestoredHistory } from './utils/compose-restore-history';
24
+ export { findRecursively, FindRecursivelyContinue, FindRecursivelyMatcher, FindRecursivelyResult, IFindRecursivelyMatherOptions, IFindRecursivelyOptions } from "./utils/find-recursively";
25
+ export { randomFromArray } from "./utils/random-from-array";
@@ -1,29 +1,47 @@
1
- import { Observable, SchedulerLike } from "rxjs";
2
- import { debounceTime, filter, map, take } from "rxjs/operators";
3
- import { IObserveQuerySelectorBaseOptions, observeQuerySelector } from "./observe-query-selector";
4
-
5
- export interface IAwaitElementOptions<T extends Element = Element> extends IObserveQuerySelectorBaseOptions<T> {
6
- /**
7
- * The time to wait for elements changes.
8
- * If during the waiting time the elements have changed the timer will be reset.
9
- * @default 0
10
- */
11
- debounceTime?: number;
12
- debounceScheduler?: SchedulerLike;
13
- }
14
-
15
- /**
16
- * Awaiting only one element to match the selector and returns it as an Rx stream.
17
- * The stream ends after one element is found / added.
18
- */
19
- export function awaitElement<T extends Element = Element>(
20
- query: string,
21
- options: IAwaitElementOptions<T> = {},
22
- ): Observable<T> {
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
- );
29
- }
1
+ import { Observable, SchedulerLike, debounceTime, filter, map, take } from "rxjs";
2
+ import { IObserveQuerySelectorBaseOptions, observeQuerySelector } from "./observe-query-selector";
3
+
4
+ export interface IAwaitElementOptions<T extends Element = Element> extends IObserveQuerySelectorBaseOptions<T> {
5
+ /**
6
+ * The time to wait for elements changes.
7
+ * If during the waiting time the elements have changed the timer will be reset.
8
+ * @default 0
9
+ */
10
+ debounceTime?: number;
11
+ debounceScheduler?: SchedulerLike;
12
+ }
13
+
14
+ /**
15
+ * Awaiting only one element to match the selector and returns it as an Rx stream.
16
+ * The stream ends after one element is found / added.
17
+ */
18
+ export function awaitElement<T extends Element = Element>(
19
+ options: IAwaitElementOptions<T>,
20
+ ): Observable<T>;
21
+ export function awaitElement<T extends Element = Element>(
22
+ query: string,
23
+ options?: Omit<IAwaitElementOptions<T>, 'query'>,
24
+ ): Observable<T>;
25
+ export function awaitElement<T extends Element = Element>(
26
+ queryOrOptions: string | IAwaitElementOptions<T>,
27
+ options?: Omit<IAwaitElementOptions<T>, 'query'>,
28
+ ): Observable<T> {
29
+ // #region Options parsing
30
+ let query: string;
31
+ let stableOptions: Omit<IAwaitElementOptions<T>, 'query'>;
32
+ if (typeof queryOrOptions === 'string') {
33
+ query = queryOrOptions;
34
+ stableOptions = options || {};
35
+ } else {
36
+ stableOptions = queryOrOptions;
37
+ query = queryOrOptions.query;
38
+ }
39
+ // #endregion
40
+
41
+ return observeQuerySelector<T>(query, stableOptions).pipe(
42
+ debounceTime(stableOptions.debounceTime || 0, stableOptions.debounceScheduler),
43
+ filter(changes => !!changes.target),
44
+ map(changes => changes.target!),
45
+ take(1),
46
+ );
47
+ }