@jupyterlab/filebrowser 4.0.0-alpha.1 → 4.0.0-alpha.12

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/lib/search.js DELETED
@@ -1,92 +0,0 @@
1
- // Copyright (c) Jupyter Development Team.
2
- // Distributed under the terms of the Modified BSD License.
3
- import { InputGroup, ReactWidget } from '@jupyterlab/ui-components';
4
- import { StringExt } from '@lumino/algorithm';
5
- import React, { useEffect, useState } from 'react';
6
- /**
7
- * Perform a fuzzy search on a single item.
8
- */
9
- function fuzzySearch(source, query) {
10
- // Set up the match score and indices array.
11
- let score = Infinity;
12
- let indices = null;
13
- // The regex for search word boundaries
14
- const rgx = /\b\w/g;
15
- let continueSearch = true;
16
- // Search the source by word boundary.
17
- while (continueSearch) {
18
- // Find the next word boundary in the source.
19
- let rgxMatch = rgx.exec(source);
20
- // Break if there is no more source context.
21
- if (!rgxMatch) {
22
- break;
23
- }
24
- // Run the string match on the relevant substring.
25
- let match = StringExt.matchSumOfDeltas(source, query, rgxMatch.index);
26
- // Break if there is no match.
27
- if (!match) {
28
- break;
29
- }
30
- // Update the match if the score is better.
31
- if (match && match.score <= score) {
32
- score = match.score;
33
- indices = match.indices;
34
- }
35
- }
36
- // Bail if there was no match.
37
- if (!indices || score === Infinity) {
38
- return null;
39
- }
40
- // Handle a split match.
41
- return {
42
- score,
43
- indices
44
- };
45
- }
46
- const FilterBox = (props) => {
47
- const [filter, setFilter] = useState('');
48
- if (props.forceRefresh) {
49
- useEffect(() => {
50
- props.listing.model.setFilter((item) => {
51
- return true;
52
- });
53
- }, []);
54
- }
55
- /**
56
- * Handler for search input changes.
57
- */
58
- const handleChange = (e) => {
59
- const target = e.target;
60
- setFilter(target.value);
61
- props.listing.model.setFilter((item) => {
62
- if (props.useFuzzyFilter) {
63
- // Run the fuzzy search for the item and query.
64
- const name = item.name.toLowerCase();
65
- const query = target.value.toLowerCase();
66
- let score = fuzzySearch(name, query);
67
- // Ignore the item if it is not a match.
68
- if (!score) {
69
- item.indices = [];
70
- return false;
71
- }
72
- item.indices = score.indices;
73
- return true;
74
- }
75
- const i = item.name.indexOf(target.value);
76
- if (i === -1) {
77
- item.indices = [];
78
- return false;
79
- }
80
- item.indices = [...Array(target.value.length).keys()].map(x => x + i);
81
- return true;
82
- });
83
- };
84
- return (React.createElement(InputGroup, { type: "text", rightIcon: "ui-components:search", placeholder: props.placeholder, onChange: handleChange, value: filter }));
85
- };
86
- /**
87
- * A widget which hosts a input textbox to filter on file names.
88
- */
89
- export const FilenameSearcher = (props) => {
90
- return ReactWidget.create(React.createElement(FilterBox, { listing: props.listing, useFuzzyFilter: props.useFuzzyFilter, placeholder: props.placeholder, forceRefresh: props.forceRefresh }));
91
- };
92
- //# sourceMappingURL=search.js.map
package/lib/search.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"search.js","sourceRoot":"","sources":["../src/search.tsx"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAG3D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA4BnD;;GAEG;AACH,SAAS,WAAW,CAAC,MAAc,EAAE,KAAa;IAChD,4CAA4C;IAC5C,IAAI,KAAK,GAAG,QAAQ,CAAC;IACrB,IAAI,OAAO,GAAoB,IAAI,CAAC;IAEpC,uCAAuC;IACvC,MAAM,GAAG,GAAG,OAAO,CAAC;IAEpB,IAAI,cAAc,GAAG,IAAI,CAAC;IAE1B,sCAAsC;IACtC,OAAO,cAAc,EAAE;QACrB,6CAA6C;QAC7C,IAAI,QAAQ,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEhC,4CAA4C;QAC5C,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM;S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