@startinblox/core 0.19.0-beta.1 → 0.19.0-beta.10
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/{_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css → assets/MarkerCluster-614dea0a.css} +0 -0
- package/dist/{_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css → assets/MarkerCluster.Default-61258232.css} +0 -0
- package/dist/assets/en-e53105c5.js +14 -0
- package/dist/assets/en-e53105c5.js.map +1 -0
- package/dist/assets/fr-a7fcdb64.js +14 -0
- package/dist/assets/fr-a7fcdb64.js.map +1 -0
- package/dist/{_snowpack/pkg/fusejs.js → assets/helpers-bf15809c.js} +398 -454
- package/dist/assets/helpers-bf15809c.js.map +1 -0
- package/dist/{_snowpack/pkg/leaflet/dist/leaflet.css → assets/leaflet-3c081932.css} +3 -3
- package/dist/helpers.js +18 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.js +54600 -48
- package/dist/index.js.map +1 -0
- package/package.json +7 -22
- package/dist/_snowpack/pkg/autolinker.js +0 -4429
- package/dist/_snowpack/pkg/autolinker.js.map +0 -1
- package/dist/_snowpack/pkg/common/_baseUnary-d2677655.js +0 -353
- package/dist/_snowpack/pkg/common/_baseUnary-d2677655.js.map +0 -1
- package/dist/_snowpack/pkg/common/_commonjsHelpers-0597c316.js +0 -26
- package/dist/_snowpack/pkg/common/_commonjsHelpers-0597c316.js.map +0 -1
- package/dist/_snowpack/pkg/common/decode-26fbf385.js +0 -185
- package/dist/_snowpack/pkg/common/decode-26fbf385.js.map +0 -1
- package/dist/_snowpack/pkg/common/lit-html-3647afce.js +0 -1104
- package/dist/_snowpack/pkg/common/lit-html-3647afce.js.map +0 -1
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js +0 -26198
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js.map +0 -1
- package/dist/_snowpack/pkg/dialog-polyfill.js +0 -826
- package/dist/_snowpack/pkg/dialog-polyfill.js.map +0 -1
- package/dist/_snowpack/pkg/fusejs.js.map +0 -1
- package/dist/_snowpack/pkg/import-map.json +0 -25
- package/dist/_snowpack/pkg/jsonld-context-parser.js +0 -836
- package/dist/_snowpack/pkg/jsonld-context-parser.js.map +0 -1
- package/dist/_snowpack/pkg/jsonld.js +0 -11760
- package/dist/_snowpack/pkg/jsonld.js.map +0 -1
- package/dist/_snowpack/pkg/leaflet/dist/leaflet.css.proxy.js +0 -10
- package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css.proxy.js +0 -10
- package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css.proxy.js +0 -10
- package/dist/_snowpack/pkg/lit-html/directives/if-defined.js +0 -39
- package/dist/_snowpack/pkg/lit-html/directives/if-defined.js.map +0 -1
- package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js +0 -48
- package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js.map +0 -1
- package/dist/_snowpack/pkg/lit-html/directives/until.js +0 -87
- package/dist/_snowpack/pkg/lit-html/directives/until.js.map +0 -1
- package/dist/_snowpack/pkg/lit-html.js +0 -94
- package/dist/_snowpack/pkg/lit-html.js.map +0 -1
- package/dist/_snowpack/pkg/markdown-it-link-attributes.js +0 -68
- package/dist/_snowpack/pkg/markdown-it-link-attributes.js.map +0 -1
- package/dist/_snowpack/pkg/markdown-it.js +0 -11307
- package/dist/_snowpack/pkg/markdown-it.js.map +0 -1
- package/dist/_snowpack/pkg/quill/dist/quill.snow.css.proxy.js +0 -10
- package/dist/_snowpack/pkg/quill-delta-to-markdown.js +0 -971
- package/dist/_snowpack/pkg/quill-delta-to-markdown.js.map +0 -1
- package/dist/_snowpack/pkg/quill.js +0 -14441
- package/dist/_snowpack/pkg/quill.js.map +0 -1
- package/dist/_snowpack/pkg/slim-select.js +0 -714
- package/dist/_snowpack/pkg/slim-select.js.map +0 -1
- package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css +0 -1149
- package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css.proxy.js +0 -10
- package/dist/_snowpack/pkg/tui-calendar.js +0 -46503
- package/dist/_snowpack/pkg/tui-calendar.js.map +0 -1
- package/dist/components/solid-ac-checker.js +0 -45
- package/dist/components/solid-calendar.js +0 -66
- package/dist/components/solid-delete.js +0 -96
- package/dist/components/solid-display.js +0 -150
- package/dist/components/solid-form-search.js +0 -173
- package/dist/components/solid-form.js +0 -257
- package/dist/components/solid-lang.js +0 -35
- package/dist/components/solid-map.js +0 -204
- package/dist/components/solid-table.js +0 -181
- package/dist/components/solid-widget.js +0 -72
- package/dist/import.css +0 -4
- package/dist/libs/Component.js +0 -13
- package/dist/libs/ComponentFactory.js +0 -165
- package/dist/libs/Compositor.js +0 -96
- package/dist/libs/Sib.js +0 -44
- package/dist/libs/filter.js +0 -184
- package/dist/libs/helpers.js +0 -185
- package/dist/libs/interfaces.js +0 -6
- package/dist/libs/lit-helpers.js +0 -139
- package/dist/libs/polyfills.js +0 -35
- package/dist/libs/store/custom-getter.js +0 -344
- package/dist/libs/store/server-pagination.js +0 -19
- package/dist/libs/store/server-search.js +0 -32
- package/dist/libs/store/store.js +0 -560
- package/dist/locales/en.json +0 -10
- package/dist/locales/en.json.proxy.js +0 -2
- package/dist/locales/fr.json +0 -10
- package/dist/locales/fr.json.proxy.js +0 -2
- package/dist/mixins/attributeBinderMixin.js +0 -113
- package/dist/mixins/contextMixin.js +0 -26
- package/dist/mixins/counterMixin.js +0 -54
- package/dist/mixins/federationMixin.js +0 -57
- package/dist/mixins/filterMixin.js +0 -152
- package/dist/mixins/grouperMixin.js +0 -73
- package/dist/mixins/highlighterMixin.js +0 -36
- package/dist/mixins/interfaces.js +0 -6
- package/dist/mixins/listMixin.js +0 -116
- package/dist/mixins/nextMixin.js +0 -23
- package/dist/mixins/paginateMixin.js +0 -97
- package/dist/mixins/requiredMixin.js +0 -38
- package/dist/mixins/serverPaginationMixin.js +0 -122
- package/dist/mixins/sorterMixin.js +0 -131
- package/dist/mixins/storeMixin.js +0 -139
- package/dist/mixins/translationMixin.js +0 -58
- package/dist/mixins/validationMixin.js +0 -95
- package/dist/mixins/widgetMixin.js +0 -358
- package/dist/new-widgets/attributeMixins/actionMixin.js +0 -13
- package/dist/new-widgets/attributeMixins/blankMixin.js +0 -7
- package/dist/new-widgets/attributeMixins/booleanMixin.js +0 -7
- package/dist/new-widgets/attributeMixins/index.js +0 -19
- package/dist/new-widgets/attributeMixins/mailtoMixin.js +0 -7
- package/dist/new-widgets/attributeMixins/multipleMixin.js +0 -27
- package/dist/new-widgets/attributeMixins/numberMixin.js +0 -7
- package/dist/new-widgets/attributeMixins/placeholderMixin.js +0 -16
- package/dist/new-widgets/attributeMixins/telMixin.js +0 -7
- package/dist/new-widgets/baseWidgetMixin.js +0 -109
- package/dist/new-widgets/callbackMixins/autocompletionMixin.js +0 -96
- package/dist/new-widgets/callbackMixins/index.js +0 -7
- package/dist/new-widgets/callbackMixins/richtextMixin.js +0 -37
- package/dist/new-widgets/callbackMixins/slimselect.css.proxy.js +0 -10
- package/dist/new-widgets/interfaces.js +0 -1
- package/dist/new-widgets/new-widget-factory.js +0 -91
- package/dist/new-widgets/templateAdditionMixins/addableMixin.js +0 -26
- package/dist/new-widgets/templateAdditionMixins/index.js +0 -13
- package/dist/new-widgets/templateAdditionMixins/labelLastMixin.js +0 -16
- package/dist/new-widgets/templateAdditionMixins/labelMixin.js +0 -18
- package/dist/new-widgets/templates/defaultTemplatesDirectory.js +0 -29
- package/dist/new-widgets/templates/displayTemplatesDirectory.js +0 -54
- package/dist/new-widgets/templates/formTemplatesDirectory.js +0 -423
- package/dist/new-widgets/templates/groupTemplatesDirectory.js +0 -11
- package/dist/new-widgets/templates/index.js +0 -6
- package/dist/new-widgets/templates/setTemplatesDirectory.js +0 -16
- package/dist/new-widgets/templatesDependencies/altMixin.js +0 -12
- package/dist/new-widgets/templatesDependencies/editableMixin.js +0 -60
- package/dist/new-widgets/templatesDependencies/filterRangeFormMixin.js +0 -34
- package/dist/new-widgets/templatesDependencies/formCheckboxMixin.js +0 -10
- package/dist/new-widgets/templatesDependencies/formCheckboxesMixin.js +0 -41
- package/dist/new-widgets/templatesDependencies/formDropdownMixin.js +0 -59
- package/dist/new-widgets/templatesDependencies/formFileMixin.js +0 -82
- package/dist/new-widgets/templatesDependencies/formLengthMixin.js +0 -18
- package/dist/new-widgets/templatesDependencies/formMinMaxMixin.js +0 -18
- package/dist/new-widgets/templatesDependencies/formMixin.js +0 -56
- package/dist/new-widgets/templatesDependencies/formNumberMixin.js +0 -10
- package/dist/new-widgets/templatesDependencies/formRadioMixin.js +0 -12
- package/dist/new-widgets/templatesDependencies/formStepMixin.js +0 -12
- package/dist/new-widgets/templatesDependencies/linkTextMixin.js +0 -13
- package/dist/new-widgets/templatesDependencies/multipleFormMixin.js +0 -116
- package/dist/new-widgets/templatesDependencies/multipleselectFormMixin.js +0 -74
- package/dist/new-widgets/templatesDependencies/patternMixin.js +0 -18
- package/dist/new-widgets/templatesDependencies/rangeMixin.js +0 -100
- package/dist/new-widgets/templatesDependencies/setMixin.js +0 -9
- package/dist/new-widgets/templatesDependencies/valueRichtextMixin.js +0 -9
- package/dist/new-widgets/valueTransformationMixins/autolinkMixin.js +0 -14
- package/dist/new-widgets/valueTransformationMixins/dateMixin.js +0 -29
- package/dist/new-widgets/valueTransformationMixins/dateTimeMixin.js +0 -12
- package/dist/new-widgets/valueTransformationMixins/index.js +0 -15
- package/dist/new-widgets/valueTransformationMixins/markdownMixin.js +0 -30
- package/dist/new-widgets/valueTransformationMixins/multilineMixin.js +0 -13
- package/dist/new-widgets/valueTransformationMixins/oembedMixin.js +0 -21
- package/dist/solid-template-element.js +0 -144
- package/dist/style/default-theme.css.proxy.js +0 -10
- package/dist/widgets/baseWidget.js +0 -267
- package/dist/widgets/widget-factory.js +0 -20
- /package/dist/{style/default-theme.css → assets/default-theme-d0f20a8a.css} +0 -0
- /package/dist/{_snowpack/pkg/quill/dist/quill.snow.css → assets/quill.snow-8f222e44.css} +0 -0
- /package/dist/{new-widgets/callbackMixins/slimselect.css → assets/slimselect-43e3ebc8.css} +0 -0
|
@@ -1,82 +1,61 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fuse.js v6.6.2 - Lightweight fuzzy-search (http://fusejs.io)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2022 Kiro Risk (http://kiro.me)
|
|
5
|
-
* All Rights Reserved. Apache Software License 2.0
|
|
6
|
-
*
|
|
7
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
1
|
function isArray(value) {
|
|
11
|
-
return !Array.isArray ? getTag(value) ===
|
|
2
|
+
return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
|
|
12
3
|
}
|
|
13
|
-
|
|
14
|
-
// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js
|
|
15
4
|
const INFINITY = 1 / 0;
|
|
16
5
|
function baseToString(value) {
|
|
17
|
-
|
|
18
|
-
if (typeof value == 'string') {
|
|
6
|
+
if (typeof value == "string") {
|
|
19
7
|
return value;
|
|
20
8
|
}
|
|
21
|
-
let result = value +
|
|
22
|
-
return result ==
|
|
9
|
+
let result = value + "";
|
|
10
|
+
return result == "0" && 1 / value == -INFINITY ? "-0" : result;
|
|
23
11
|
}
|
|
24
12
|
function toString(value) {
|
|
25
|
-
return value == null ?
|
|
13
|
+
return value == null ? "" : baseToString(value);
|
|
26
14
|
}
|
|
27
15
|
function isString(value) {
|
|
28
|
-
return typeof value ===
|
|
16
|
+
return typeof value === "string";
|
|
29
17
|
}
|
|
30
18
|
function isNumber(value) {
|
|
31
|
-
return typeof value ===
|
|
19
|
+
return typeof value === "number";
|
|
32
20
|
}
|
|
33
|
-
|
|
34
|
-
// Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js
|
|
35
21
|
function isBoolean(value) {
|
|
36
|
-
return value === true || value === false || isObjectLike(value) && getTag(value) ==
|
|
22
|
+
return value === true || value === false || isObjectLike(value) && getTag(value) == "[object Boolean]";
|
|
37
23
|
}
|
|
38
24
|
function isObject(value) {
|
|
39
|
-
return typeof value ===
|
|
25
|
+
return typeof value === "object";
|
|
40
26
|
}
|
|
41
|
-
|
|
42
|
-
// Checks if `value` is object-like.
|
|
43
27
|
function isObjectLike(value) {
|
|
44
28
|
return isObject(value) && value !== null;
|
|
45
29
|
}
|
|
46
30
|
function isDefined(value) {
|
|
47
|
-
return value !==
|
|
31
|
+
return value !== void 0 && value !== null;
|
|
48
32
|
}
|
|
49
33
|
function isBlank(value) {
|
|
50
34
|
return !value.trim().length;
|
|
51
35
|
}
|
|
52
|
-
|
|
53
|
-
// Gets the `toStringTag` of `value`.
|
|
54
|
-
// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js
|
|
55
36
|
function getTag(value) {
|
|
56
|
-
return value == null ? value ===
|
|
37
|
+
return value == null ? value === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
|
|
57
38
|
}
|
|
58
|
-
const EXTENDED_SEARCH_UNAVAILABLE =
|
|
39
|
+
const EXTENDED_SEARCH_UNAVAILABLE = "Extended search is not available";
|
|
59
40
|
const INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
|
|
60
|
-
const LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = key => `Invalid value for key ${key}`;
|
|
61
|
-
const PATTERN_LENGTH_TOO_LARGE = max => `Pattern length exceeds max of ${max}.`;
|
|
62
|
-
const MISSING_KEY_PROPERTY = name => `Missing ${name} property in key`;
|
|
63
|
-
const INVALID_KEY_WEIGHT_VALUE = key => `Property 'weight' in key '${key}' must be a positive integer`;
|
|
41
|
+
const LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
|
|
42
|
+
const PATTERN_LENGTH_TOO_LARGE = (max) => `Pattern length exceeds max of ${max}.`;
|
|
43
|
+
const MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
|
|
44
|
+
const INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
|
|
64
45
|
const hasOwn = Object.prototype.hasOwnProperty;
|
|
65
46
|
class KeyStore {
|
|
66
47
|
constructor(keys) {
|
|
67
48
|
this._keys = [];
|
|
68
49
|
this._keyMap = {};
|
|
69
50
|
let totalWeight = 0;
|
|
70
|
-
keys.forEach(key => {
|
|
51
|
+
keys.forEach((key) => {
|
|
71
52
|
let obj = createKey(key);
|
|
72
53
|
totalWeight += obj.weight;
|
|
73
54
|
this._keys.push(obj);
|
|
74
55
|
this._keyMap[obj.id] = obj;
|
|
75
56
|
totalWeight += obj.weight;
|
|
76
57
|
});
|
|
77
|
-
|
|
78
|
-
// Normalize weights so that their sum is equal to 1
|
|
79
|
-
this._keys.forEach(key => {
|
|
58
|
+
this._keys.forEach((key) => {
|
|
80
59
|
key.weight /= totalWeight;
|
|
81
60
|
});
|
|
82
61
|
}
|
|
@@ -101,12 +80,12 @@ function createKey(key) {
|
|
|
101
80
|
path = createKeyPath(key);
|
|
102
81
|
id = createKeyId(key);
|
|
103
82
|
} else {
|
|
104
|
-
if (!hasOwn.call(key,
|
|
105
|
-
throw new Error(MISSING_KEY_PROPERTY(
|
|
83
|
+
if (!hasOwn.call(key, "name")) {
|
|
84
|
+
throw new Error(MISSING_KEY_PROPERTY("name"));
|
|
106
85
|
}
|
|
107
86
|
const name = key.name;
|
|
108
87
|
src = name;
|
|
109
|
-
if (hasOwn.call(key,
|
|
88
|
+
if (hasOwn.call(key, "weight")) {
|
|
110
89
|
weight = key.weight;
|
|
111
90
|
if (weight <= 0) {
|
|
112
91
|
throw new Error(INVALID_KEY_WEIGHT_VALUE(name));
|
|
@@ -116,56 +95,42 @@ function createKey(key) {
|
|
|
116
95
|
id = createKeyId(name);
|
|
117
96
|
getFn = key.getFn;
|
|
118
97
|
}
|
|
119
|
-
return {
|
|
120
|
-
path,
|
|
121
|
-
id,
|
|
122
|
-
weight,
|
|
123
|
-
src,
|
|
124
|
-
getFn
|
|
125
|
-
};
|
|
98
|
+
return { path, id, weight, src, getFn };
|
|
126
99
|
}
|
|
127
100
|
function createKeyPath(key) {
|
|
128
|
-
return isArray(key) ? key : key.split(
|
|
101
|
+
return isArray(key) ? key : key.split(".");
|
|
129
102
|
}
|
|
130
103
|
function createKeyId(key) {
|
|
131
|
-
return isArray(key) ? key.join(
|
|
104
|
+
return isArray(key) ? key.join(".") : key;
|
|
132
105
|
}
|
|
133
106
|
function get(obj, path) {
|
|
134
107
|
let list = [];
|
|
135
108
|
let arr = false;
|
|
136
|
-
const deepGet = (
|
|
137
|
-
if (!isDefined(
|
|
109
|
+
const deepGet = (obj2, path2, index) => {
|
|
110
|
+
if (!isDefined(obj2)) {
|
|
138
111
|
return;
|
|
139
112
|
}
|
|
140
|
-
if (!
|
|
141
|
-
|
|
142
|
-
list.push(obj);
|
|
113
|
+
if (!path2[index]) {
|
|
114
|
+
list.push(obj2);
|
|
143
115
|
} else {
|
|
144
|
-
let key =
|
|
145
|
-
const value =
|
|
116
|
+
let key = path2[index];
|
|
117
|
+
const value = obj2[key];
|
|
146
118
|
if (!isDefined(value)) {
|
|
147
119
|
return;
|
|
148
120
|
}
|
|
149
|
-
|
|
150
|
-
// If we're at the last value in the path, and if it's a string/number/bool,
|
|
151
|
-
// add it to the list
|
|
152
|
-
if (index === path.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) {
|
|
121
|
+
if (index === path2.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) {
|
|
153
122
|
list.push(toString(value));
|
|
154
123
|
} else if (isArray(value)) {
|
|
155
124
|
arr = true;
|
|
156
|
-
// Search each item in the array.
|
|
157
125
|
for (let i = 0, len = value.length; i < len; i += 1) {
|
|
158
|
-
deepGet(value[i],
|
|
126
|
+
deepGet(value[i], path2, index + 1);
|
|
159
127
|
}
|
|
160
|
-
} else if (
|
|
161
|
-
|
|
162
|
-
deepGet(value, path, index + 1);
|
|
128
|
+
} else if (path2.length) {
|
|
129
|
+
deepGet(value, path2, index + 1);
|
|
163
130
|
}
|
|
164
131
|
}
|
|
165
132
|
};
|
|
166
|
-
|
|
167
|
-
// Backwards compatibility (since path used to be a string)
|
|
168
|
-
deepGet(obj, isString(path) ? path.split('.') : path, 0);
|
|
133
|
+
deepGet(obj, isString(path) ? path.split(".") : path, 0);
|
|
169
134
|
return arr ? list : list[0];
|
|
170
135
|
}
|
|
171
136
|
const MatchOptions = {
|
|
@@ -229,11 +194,8 @@ var Config = {
|
|
|
229
194
|
...AdvancedOptions
|
|
230
195
|
};
|
|
231
196
|
const SPACE = /[^ ]+/g;
|
|
232
|
-
|
|
233
|
-
// Field-length norm: the shorter the field, the higher the weight.
|
|
234
|
-
// Set to 3 decimals to reduce index size.
|
|
235
197
|
function norm(weight = 1, mantissa = 3) {
|
|
236
|
-
const cache = new Map();
|
|
198
|
+
const cache = /* @__PURE__ */ new Map();
|
|
237
199
|
const m = Math.pow(10, mantissa);
|
|
238
200
|
return {
|
|
239
201
|
get(value) {
|
|
@@ -241,12 +203,8 @@ function norm(weight = 1, mantissa = 3) {
|
|
|
241
203
|
if (cache.has(numTokens)) {
|
|
242
204
|
return cache.get(numTokens);
|
|
243
205
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const norm = 1 / Math.pow(numTokens, 0.5 * weight);
|
|
247
|
-
|
|
248
|
-
// In place of `toFixed(mantissa)`, for faster computation
|
|
249
|
-
const n = parseFloat(Math.round(norm * m) / m);
|
|
206
|
+
const norm2 = 1 / Math.pow(numTokens, 0.5 * weight);
|
|
207
|
+
const n = parseFloat(Math.round(norm2 * m) / m);
|
|
250
208
|
cache.set(numTokens, n);
|
|
251
209
|
return n;
|
|
252
210
|
},
|
|
@@ -283,14 +241,11 @@ class FuseIndex {
|
|
|
283
241
|
return;
|
|
284
242
|
}
|
|
285
243
|
this.isCreated = true;
|
|
286
|
-
|
|
287
|
-
// List is Array<String>
|
|
288
244
|
if (isString(this.docs[0])) {
|
|
289
245
|
this.docs.forEach((doc, docIndex) => {
|
|
290
246
|
this._addString(doc, docIndex);
|
|
291
247
|
});
|
|
292
248
|
} else {
|
|
293
|
-
// List is Array<Object>
|
|
294
249
|
this.docs.forEach((doc, docIndex) => {
|
|
295
250
|
this._addObject(doc, docIndex);
|
|
296
251
|
});
|
|
@@ -309,8 +264,6 @@ class FuseIndex {
|
|
|
309
264
|
// Removes the doc at the specified index of the index
|
|
310
265
|
removeAt(idx) {
|
|
311
266
|
this.records.splice(idx, 1);
|
|
312
|
-
|
|
313
|
-
// Change ref index of every subsquent doc
|
|
314
267
|
for (let i = idx, len = this.size(); i < len; i += 1) {
|
|
315
268
|
this.records[i].i -= 1;
|
|
316
269
|
}
|
|
@@ -333,12 +286,7 @@ class FuseIndex {
|
|
|
333
286
|
this.records.push(record);
|
|
334
287
|
}
|
|
335
288
|
_addObject(doc, docIndex) {
|
|
336
|
-
let record = {
|
|
337
|
-
i: docIndex,
|
|
338
|
-
$: {}
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
// Iterate over every key (i.e, path), and fetch the value at that key
|
|
289
|
+
let record = { i: docIndex, $: {} };
|
|
342
290
|
this.keys.forEach((key, keyIndex) => {
|
|
343
291
|
let value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
|
|
344
292
|
if (!isDefined(value)) {
|
|
@@ -346,33 +294,28 @@ class FuseIndex {
|
|
|
346
294
|
}
|
|
347
295
|
if (isArray(value)) {
|
|
348
296
|
let subRecords = [];
|
|
349
|
-
const stack = [{
|
|
350
|
-
nestedArrIndex: -1,
|
|
351
|
-
value
|
|
352
|
-
}];
|
|
297
|
+
const stack = [{ nestedArrIndex: -1, value }];
|
|
353
298
|
while (stack.length) {
|
|
354
|
-
const {
|
|
355
|
-
|
|
356
|
-
value
|
|
357
|
-
} = stack.pop();
|
|
358
|
-
if (!isDefined(value)) {
|
|
299
|
+
const { nestedArrIndex, value: value2 } = stack.pop();
|
|
300
|
+
if (!isDefined(value2)) {
|
|
359
301
|
continue;
|
|
360
302
|
}
|
|
361
|
-
if (isString(
|
|
303
|
+
if (isString(value2) && !isBlank(value2)) {
|
|
362
304
|
let subRecord = {
|
|
363
|
-
v:
|
|
305
|
+
v: value2,
|
|
364
306
|
i: nestedArrIndex,
|
|
365
|
-
n: this.norm.get(
|
|
307
|
+
n: this.norm.get(value2)
|
|
366
308
|
};
|
|
367
309
|
subRecords.push(subRecord);
|
|
368
|
-
} else if (isArray(
|
|
369
|
-
|
|
310
|
+
} else if (isArray(value2)) {
|
|
311
|
+
value2.forEach((item, k) => {
|
|
370
312
|
stack.push({
|
|
371
313
|
nestedArrIndex: k,
|
|
372
314
|
value: item
|
|
373
315
|
});
|
|
374
316
|
});
|
|
375
|
-
} else
|
|
317
|
+
} else
|
|
318
|
+
;
|
|
376
319
|
}
|
|
377
320
|
record.$[keyIndex] = subRecords;
|
|
378
321
|
} else if (isString(value) && !isBlank(value)) {
|
|
@@ -392,31 +335,16 @@ class FuseIndex {
|
|
|
392
335
|
};
|
|
393
336
|
}
|
|
394
337
|
}
|
|
395
|
-
function createIndex(keys, docs, {
|
|
396
|
-
|
|
397
|
-
fieldNormWeight = Config.fieldNormWeight
|
|
398
|
-
} = {}) {
|
|
399
|
-
const myIndex = new FuseIndex({
|
|
400
|
-
getFn,
|
|
401
|
-
fieldNormWeight
|
|
402
|
-
});
|
|
338
|
+
function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
339
|
+
const myIndex = new FuseIndex({ getFn, fieldNormWeight });
|
|
403
340
|
myIndex.setKeys(keys.map(createKey));
|
|
404
341
|
myIndex.setSources(docs);
|
|
405
342
|
myIndex.create();
|
|
406
343
|
return myIndex;
|
|
407
344
|
}
|
|
408
|
-
function parseIndex(data, {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
} = {}) {
|
|
412
|
-
const {
|
|
413
|
-
keys,
|
|
414
|
-
records
|
|
415
|
-
} = data;
|
|
416
|
-
const myIndex = new FuseIndex({
|
|
417
|
-
getFn,
|
|
418
|
-
fieldNormWeight
|
|
419
|
-
});
|
|
345
|
+
function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
346
|
+
const { keys, records } = data;
|
|
347
|
+
const myIndex = new FuseIndex({ getFn, fieldNormWeight });
|
|
420
348
|
myIndex.setKeys(keys);
|
|
421
349
|
myIndex.setIndexRecords(records);
|
|
422
350
|
return myIndex;
|
|
@@ -434,8 +362,7 @@ function computeScore$1(pattern, {
|
|
|
434
362
|
}
|
|
435
363
|
const proximity = Math.abs(expectedLocation - currentLocation);
|
|
436
364
|
if (!distance) {
|
|
437
|
-
|
|
438
|
-
return proximity ? 1.0 : accuracy;
|
|
365
|
+
return proximity ? 1 : accuracy;
|
|
439
366
|
}
|
|
440
367
|
return accuracy + proximity / distance;
|
|
441
368
|
}
|
|
@@ -456,15 +383,11 @@ function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMat
|
|
|
456
383
|
start = -1;
|
|
457
384
|
}
|
|
458
385
|
}
|
|
459
|
-
|
|
460
|
-
// (i-1 - start) + 1 => i - start
|
|
461
386
|
if (matchmask[i - 1] && i - start >= minMatchCharLength) {
|
|
462
387
|
indices.push([start, i - 1]);
|
|
463
388
|
}
|
|
464
389
|
return indices;
|
|
465
390
|
}
|
|
466
|
-
|
|
467
|
-
// Machine word size
|
|
468
391
|
const MAX_BITS = 32;
|
|
469
392
|
function search(text, pattern, patternAlphabet, {
|
|
470
393
|
location = Config.location,
|
|
@@ -479,23 +402,13 @@ function search(text, pattern, patternAlphabet, {
|
|
|
479
402
|
throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
|
|
480
403
|
}
|
|
481
404
|
const patternLen = pattern.length;
|
|
482
|
-
// Set starting location at beginning text and initialize the alphabet.
|
|
483
405
|
const textLen = text.length;
|
|
484
|
-
// Handle the case when location > text.length
|
|
485
406
|
const expectedLocation = Math.max(0, Math.min(location, textLen));
|
|
486
|
-
// Highest score beyond which we give up.
|
|
487
407
|
let currentThreshold = threshold;
|
|
488
|
-
// Is there a nearby exact match? (speedup)
|
|
489
408
|
let bestLocation = expectedLocation;
|
|
490
|
-
|
|
491
|
-
// Performance: only computer matches when the minMatchCharLength > 1
|
|
492
|
-
// OR if `includeMatches` is true.
|
|
493
409
|
const computeMatches = minMatchCharLength > 1 || includeMatches;
|
|
494
|
-
// A mask of the matches, used for building the indices
|
|
495
410
|
const matchMask = computeMatches ? Array(textLen) : [];
|
|
496
411
|
let index;
|
|
497
|
-
|
|
498
|
-
// Get all exact matches, here for speed up
|
|
499
412
|
while ((index = text.indexOf(pattern, bestLocation)) > -1) {
|
|
500
413
|
let score = computeScore$1(pattern, {
|
|
501
414
|
currentLocation: index,
|
|
@@ -513,55 +426,41 @@ function search(text, pattern, patternAlphabet, {
|
|
|
513
426
|
}
|
|
514
427
|
}
|
|
515
428
|
}
|
|
516
|
-
|
|
517
|
-
// Reset the best location
|
|
518
429
|
bestLocation = -1;
|
|
519
430
|
let lastBitArr = [];
|
|
520
431
|
let finalScore = 1;
|
|
521
432
|
let binMax = patternLen + textLen;
|
|
522
433
|
const mask = 1 << patternLen - 1;
|
|
523
434
|
for (let i = 0; i < patternLen; i += 1) {
|
|
524
|
-
// Scan for the best match; each iteration allows for one more error.
|
|
525
|
-
// Run a binary search to determine how far from the match location we can stray
|
|
526
|
-
// at this error level.
|
|
527
435
|
let binMin = 0;
|
|
528
436
|
let binMid = binMax;
|
|
529
437
|
while (binMin < binMid) {
|
|
530
|
-
const
|
|
438
|
+
const score2 = computeScore$1(pattern, {
|
|
531
439
|
errors: i,
|
|
532
440
|
currentLocation: expectedLocation + binMid,
|
|
533
441
|
expectedLocation,
|
|
534
442
|
distance,
|
|
535
443
|
ignoreLocation
|
|
536
444
|
});
|
|
537
|
-
if (
|
|
445
|
+
if (score2 <= currentThreshold) {
|
|
538
446
|
binMin = binMid;
|
|
539
447
|
} else {
|
|
540
448
|
binMax = binMid;
|
|
541
449
|
}
|
|
542
450
|
binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
543
451
|
}
|
|
544
|
-
|
|
545
|
-
// Use the result from this iteration as the maximum for the next.
|
|
546
452
|
binMax = binMid;
|
|
547
453
|
let start = Math.max(1, expectedLocation - binMid + 1);
|
|
548
454
|
let finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
|
|
549
|
-
|
|
550
|
-
// Initialize the bit array
|
|
551
455
|
let bitArr = Array(finish + 2);
|
|
552
456
|
bitArr[finish + 1] = (1 << i) - 1;
|
|
553
457
|
for (let j = finish; j >= start; j -= 1) {
|
|
554
458
|
let currentLocation = j - 1;
|
|
555
459
|
let charMatch = patternAlphabet[text.charAt(currentLocation)];
|
|
556
460
|
if (computeMatches) {
|
|
557
|
-
// Speed up: quick bool to int conversion (i.e, `charMatch ? 1 : 0`)
|
|
558
461
|
matchMask[currentLocation] = +!!charMatch;
|
|
559
462
|
}
|
|
560
|
-
|
|
561
|
-
// First pass: exact match
|
|
562
463
|
bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
|
|
563
|
-
|
|
564
|
-
// Subsequent passes: fuzzy match
|
|
565
464
|
if (i) {
|
|
566
465
|
bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
|
|
567
466
|
}
|
|
@@ -573,26 +472,16 @@ function search(text, pattern, patternAlphabet, {
|
|
|
573
472
|
distance,
|
|
574
473
|
ignoreLocation
|
|
575
474
|
});
|
|
576
|
-
|
|
577
|
-
// This match will almost certainly be better than any existing match.
|
|
578
|
-
// But check anyway.
|
|
579
475
|
if (finalScore <= currentThreshold) {
|
|
580
|
-
// Indeed it is
|
|
581
476
|
currentThreshold = finalScore;
|
|
582
477
|
bestLocation = currentLocation;
|
|
583
|
-
|
|
584
|
-
// Already passed `loc`, downhill from here on in.
|
|
585
478
|
if (bestLocation <= expectedLocation) {
|
|
586
479
|
break;
|
|
587
480
|
}
|
|
588
|
-
|
|
589
|
-
// When passing `bestLocation`, don't exceed our current distance from `expectedLocation`.
|
|
590
481
|
start = Math.max(1, 2 * expectedLocation - bestLocation);
|
|
591
482
|
}
|
|
592
483
|
}
|
|
593
484
|
}
|
|
594
|
-
|
|
595
|
-
// No hope for a (better) match at greater error levels.
|
|
596
485
|
const score = computeScore$1(pattern, {
|
|
597
486
|
errors: i + 1,
|
|
598
487
|
currentLocation: expectedLocation,
|
|
@@ -608,7 +497,7 @@ function search(text, pattern, patternAlphabet, {
|
|
|
608
497
|
const result = {
|
|
609
498
|
isMatch: bestLocation >= 0,
|
|
610
499
|
// Count exact matches (those with a score of 0) to be "almost" exact
|
|
611
|
-
score: Math.max(
|
|
500
|
+
score: Math.max(1e-3, finalScore)
|
|
612
501
|
};
|
|
613
502
|
if (computeMatches) {
|
|
614
503
|
const indices = convertMaskToIndices(matchMask, minMatchCharLength);
|
|
@@ -654,10 +543,10 @@ class BitapSearch {
|
|
|
654
543
|
if (!this.pattern.length) {
|
|
655
544
|
return;
|
|
656
545
|
}
|
|
657
|
-
const addChunk = (
|
|
546
|
+
const addChunk = (pattern2, startIndex) => {
|
|
658
547
|
this.chunks.push({
|
|
659
|
-
pattern,
|
|
660
|
-
alphabet: createPatternAlphabet(
|
|
548
|
+
pattern: pattern2,
|
|
549
|
+
alphabet: createPatternAlphabet(pattern2),
|
|
661
550
|
startIndex
|
|
662
551
|
});
|
|
663
552
|
};
|
|
@@ -679,27 +568,20 @@ class BitapSearch {
|
|
|
679
568
|
}
|
|
680
569
|
}
|
|
681
570
|
searchIn(text) {
|
|
682
|
-
const {
|
|
683
|
-
isCaseSensitive,
|
|
684
|
-
includeMatches
|
|
685
|
-
} = this.options;
|
|
571
|
+
const { isCaseSensitive, includeMatches } = this.options;
|
|
686
572
|
if (!isCaseSensitive) {
|
|
687
573
|
text = text.toLowerCase();
|
|
688
574
|
}
|
|
689
|
-
|
|
690
|
-
// Exact match
|
|
691
575
|
if (this.pattern === text) {
|
|
692
|
-
let
|
|
576
|
+
let result2 = {
|
|
693
577
|
isMatch: true,
|
|
694
578
|
score: 0
|
|
695
579
|
};
|
|
696
580
|
if (includeMatches) {
|
|
697
|
-
|
|
581
|
+
result2.indices = [[0, text.length - 1]];
|
|
698
582
|
}
|
|
699
|
-
return
|
|
583
|
+
return result2;
|
|
700
584
|
}
|
|
701
|
-
|
|
702
|
-
// Otherwise, use Bitap algorithm
|
|
703
585
|
const {
|
|
704
586
|
location,
|
|
705
587
|
distance,
|
|
@@ -711,16 +593,8 @@ class BitapSearch {
|
|
|
711
593
|
let allIndices = [];
|
|
712
594
|
let totalScore = 0;
|
|
713
595
|
let hasMatches = false;
|
|
714
|
-
this.chunks.forEach(({
|
|
715
|
-
pattern,
|
|
716
|
-
alphabet,
|
|
717
|
-
startIndex
|
|
718
|
-
}) => {
|
|
719
|
-
const {
|
|
720
|
-
isMatch,
|
|
721
|
-
score,
|
|
722
|
-
indices
|
|
723
|
-
} = search(text, pattern, alphabet, {
|
|
596
|
+
this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
|
|
597
|
+
const { isMatch, score, indices } = search(text, pattern, alphabet, {
|
|
724
598
|
location: location + startIndex,
|
|
725
599
|
distance,
|
|
726
600
|
threshold,
|
|
@@ -757,21 +631,19 @@ class BaseMatch {
|
|
|
757
631
|
static isSingleMatch(pattern) {
|
|
758
632
|
return getMatch(pattern, this.singleRegex);
|
|
759
633
|
}
|
|
760
|
-
search(
|
|
634
|
+
search() {
|
|
635
|
+
}
|
|
761
636
|
}
|
|
762
637
|
function getMatch(pattern, exp) {
|
|
763
638
|
const matches = pattern.match(exp);
|
|
764
639
|
return matches ? matches[1] : null;
|
|
765
640
|
}
|
|
766
|
-
|
|
767
|
-
// Token: 'file
|
|
768
|
-
|
|
769
641
|
class ExactMatch extends BaseMatch {
|
|
770
642
|
constructor(pattern) {
|
|
771
643
|
super(pattern);
|
|
772
644
|
}
|
|
773
645
|
static get type() {
|
|
774
|
-
return
|
|
646
|
+
return "exact";
|
|
775
647
|
}
|
|
776
648
|
static get multiRegex() {
|
|
777
649
|
return /^="(.*)"$/;
|
|
@@ -788,15 +660,12 @@ class ExactMatch extends BaseMatch {
|
|
|
788
660
|
};
|
|
789
661
|
}
|
|
790
662
|
}
|
|
791
|
-
|
|
792
|
-
// Token: !fire
|
|
793
|
-
|
|
794
663
|
class InverseExactMatch extends BaseMatch {
|
|
795
664
|
constructor(pattern) {
|
|
796
665
|
super(pattern);
|
|
797
666
|
}
|
|
798
667
|
static get type() {
|
|
799
|
-
return
|
|
668
|
+
return "inverse-exact";
|
|
800
669
|
}
|
|
801
670
|
static get multiRegex() {
|
|
802
671
|
return /^!"(.*)"$/;
|
|
@@ -814,15 +683,12 @@ class InverseExactMatch extends BaseMatch {
|
|
|
814
683
|
};
|
|
815
684
|
}
|
|
816
685
|
}
|
|
817
|
-
|
|
818
|
-
// Token: ^file
|
|
819
|
-
|
|
820
686
|
class PrefixExactMatch extends BaseMatch {
|
|
821
687
|
constructor(pattern) {
|
|
822
688
|
super(pattern);
|
|
823
689
|
}
|
|
824
690
|
static get type() {
|
|
825
|
-
return
|
|
691
|
+
return "prefix-exact";
|
|
826
692
|
}
|
|
827
693
|
static get multiRegex() {
|
|
828
694
|
return /^\^"(.*)"$/;
|
|
@@ -839,15 +705,12 @@ class PrefixExactMatch extends BaseMatch {
|
|
|
839
705
|
};
|
|
840
706
|
}
|
|
841
707
|
}
|
|
842
|
-
|
|
843
|
-
// Token: !^fire
|
|
844
|
-
|
|
845
708
|
class InversePrefixExactMatch extends BaseMatch {
|
|
846
709
|
constructor(pattern) {
|
|
847
710
|
super(pattern);
|
|
848
711
|
}
|
|
849
712
|
static get type() {
|
|
850
|
-
return
|
|
713
|
+
return "inverse-prefix-exact";
|
|
851
714
|
}
|
|
852
715
|
static get multiRegex() {
|
|
853
716
|
return /^!\^"(.*)"$/;
|
|
@@ -864,15 +727,12 @@ class InversePrefixExactMatch extends BaseMatch {
|
|
|
864
727
|
};
|
|
865
728
|
}
|
|
866
729
|
}
|
|
867
|
-
|
|
868
|
-
// Token: .file$
|
|
869
|
-
|
|
870
730
|
class SuffixExactMatch extends BaseMatch {
|
|
871
731
|
constructor(pattern) {
|
|
872
732
|
super(pattern);
|
|
873
733
|
}
|
|
874
734
|
static get type() {
|
|
875
|
-
return
|
|
735
|
+
return "suffix-exact";
|
|
876
736
|
}
|
|
877
737
|
static get multiRegex() {
|
|
878
738
|
return /^"(.*)"\$$/;
|
|
@@ -889,15 +749,12 @@ class SuffixExactMatch extends BaseMatch {
|
|
|
889
749
|
};
|
|
890
750
|
}
|
|
891
751
|
}
|
|
892
|
-
|
|
893
|
-
// Token: !.file$
|
|
894
|
-
|
|
895
752
|
class InverseSuffixExactMatch extends BaseMatch {
|
|
896
753
|
constructor(pattern) {
|
|
897
754
|
super(pattern);
|
|
898
755
|
}
|
|
899
756
|
static get type() {
|
|
900
|
-
return
|
|
757
|
+
return "inverse-suffix-exact";
|
|
901
758
|
}
|
|
902
759
|
static get multiRegex() {
|
|
903
760
|
return /^!"(.*)"\$$/;
|
|
@@ -938,7 +795,7 @@ class FuzzyMatch extends BaseMatch {
|
|
|
938
795
|
});
|
|
939
796
|
}
|
|
940
797
|
static get type() {
|
|
941
|
-
return
|
|
798
|
+
return "fuzzy";
|
|
942
799
|
}
|
|
943
800
|
static get multiRegex() {
|
|
944
801
|
return /^"(.*)"$/;
|
|
@@ -950,15 +807,12 @@ class FuzzyMatch extends BaseMatch {
|
|
|
950
807
|
return this._bitapSearch.searchIn(text);
|
|
951
808
|
}
|
|
952
809
|
}
|
|
953
|
-
|
|
954
|
-
// Token: 'file
|
|
955
|
-
|
|
956
810
|
class IncludeMatch extends BaseMatch {
|
|
957
811
|
constructor(pattern) {
|
|
958
812
|
super(pattern);
|
|
959
813
|
}
|
|
960
814
|
static get type() {
|
|
961
|
-
return
|
|
815
|
+
return "include";
|
|
962
816
|
}
|
|
963
817
|
static get multiRegex() {
|
|
964
818
|
return /^'"(.*)"$/;
|
|
@@ -971,8 +825,6 @@ class IncludeMatch extends BaseMatch {
|
|
|
971
825
|
let index;
|
|
972
826
|
const indices = [];
|
|
973
827
|
const patternLen = this.pattern.length;
|
|
974
|
-
|
|
975
|
-
// Get all exact matches
|
|
976
828
|
while ((index = text.indexOf(this.pattern, location)) > -1) {
|
|
977
829
|
location = index + patternLen;
|
|
978
830
|
indices.push([index, location - 1]);
|
|
@@ -985,26 +837,25 @@ class IncludeMatch extends BaseMatch {
|
|
|
985
837
|
};
|
|
986
838
|
}
|
|
987
839
|
}
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
840
|
+
const searchers = [
|
|
841
|
+
ExactMatch,
|
|
842
|
+
IncludeMatch,
|
|
843
|
+
PrefixExactMatch,
|
|
844
|
+
InversePrefixExactMatch,
|
|
845
|
+
InverseSuffixExactMatch,
|
|
846
|
+
SuffixExactMatch,
|
|
847
|
+
InverseExactMatch,
|
|
848
|
+
FuzzyMatch
|
|
849
|
+
];
|
|
991
850
|
const searchersLen = searchers.length;
|
|
992
|
-
|
|
993
|
-
// Regex to split by spaces, but keep anything in quotes together
|
|
994
851
|
const SPACE_RE = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/;
|
|
995
|
-
const OR_TOKEN =
|
|
996
|
-
|
|
997
|
-
// Return a 2D array representation of the query, for simpler parsing.
|
|
998
|
-
// Example:
|
|
999
|
-
// "^core go$ | rb$ | py$ xy$" => [["^core", "go$"], ["rb$"], ["py$", "xy$"]]
|
|
852
|
+
const OR_TOKEN = "|";
|
|
1000
853
|
function parseQuery(pattern, options = {}) {
|
|
1001
|
-
return pattern.split(OR_TOKEN).map(item => {
|
|
1002
|
-
let query = item.trim().split(SPACE_RE).filter(
|
|
854
|
+
return pattern.split(OR_TOKEN).map((item) => {
|
|
855
|
+
let query = item.trim().split(SPACE_RE).filter((item2) => item2 && !!item2.trim());
|
|
1003
856
|
let results = [];
|
|
1004
857
|
for (let i = 0, len = query.length; i < len; i += 1) {
|
|
1005
858
|
const queryItem = query[i];
|
|
1006
|
-
|
|
1007
|
-
// 1. Handle multiple query match (i.e, once that are quoted, like `"hello world"`)
|
|
1008
859
|
let found = false;
|
|
1009
860
|
let idx = -1;
|
|
1010
861
|
while (!found && ++idx < searchersLen) {
|
|
@@ -1018,8 +869,6 @@ function parseQuery(pattern, options = {}) {
|
|
|
1018
869
|
if (found) {
|
|
1019
870
|
continue;
|
|
1020
871
|
}
|
|
1021
|
-
|
|
1022
|
-
// 2. Handle single query matches (i.e, once that are *not* quoted)
|
|
1023
872
|
idx = -1;
|
|
1024
873
|
while (++idx < searchersLen) {
|
|
1025
874
|
const searcher = searchers[idx];
|
|
@@ -1033,39 +882,7 @@ function parseQuery(pattern, options = {}) {
|
|
|
1033
882
|
return results;
|
|
1034
883
|
});
|
|
1035
884
|
}
|
|
1036
|
-
|
|
1037
|
-
// These extended matchers can return an array of matches, as opposed
|
|
1038
|
-
// to a singl match
|
|
1039
|
-
const MultiMatchSet = new Set([FuzzyMatch.type, IncludeMatch.type]);
|
|
1040
|
-
|
|
1041
|
-
/**
|
|
1042
|
-
* Command-like searching
|
|
1043
|
-
* ======================
|
|
1044
|
-
*
|
|
1045
|
-
* Given multiple search terms delimited by spaces.e.g. `^jscript .python$ ruby !java`,
|
|
1046
|
-
* search in a given text.
|
|
1047
|
-
*
|
|
1048
|
-
* Search syntax:
|
|
1049
|
-
*
|
|
1050
|
-
* | Token | Match type | Description |
|
|
1051
|
-
* | ----------- | -------------------------- | -------------------------------------- |
|
|
1052
|
-
* | `jscript` | fuzzy-match | Items that fuzzy match `jscript` |
|
|
1053
|
-
* | `=scheme` | exact-match | Items that are `scheme` |
|
|
1054
|
-
* | `'python` | include-match | Items that include `python` |
|
|
1055
|
-
* | `!ruby` | inverse-exact-match | Items that do not include `ruby` |
|
|
1056
|
-
* | `^java` | prefix-exact-match | Items that start with `java` |
|
|
1057
|
-
* | `!^earlang` | inverse-prefix-exact-match | Items that do not start with `earlang` |
|
|
1058
|
-
* | `.js$` | suffix-exact-match | Items that end with `.js` |
|
|
1059
|
-
* | `!.go$` | inverse-suffix-exact-match | Items that do not end with `.go` |
|
|
1060
|
-
*
|
|
1061
|
-
* A single pipe character acts as an OR operator. For example, the following
|
|
1062
|
-
* query matches entries that start with `core` and end with either`go`, `rb`,
|
|
1063
|
-
* or`py`.
|
|
1064
|
-
*
|
|
1065
|
-
* ```
|
|
1066
|
-
* ^core go$ | rb$ | py$
|
|
1067
|
-
* ```
|
|
1068
|
-
*/
|
|
885
|
+
const MultiMatchSet = /* @__PURE__ */ new Set([FuzzyMatch.type, IncludeMatch.type]);
|
|
1069
886
|
class ExtendedSearch {
|
|
1070
887
|
constructor(pattern, {
|
|
1071
888
|
isCaseSensitive = Config.isCaseSensitive,
|
|
@@ -1102,31 +919,18 @@ class ExtendedSearch {
|
|
|
1102
919
|
score: 1
|
|
1103
920
|
};
|
|
1104
921
|
}
|
|
1105
|
-
const {
|
|
1106
|
-
includeMatches,
|
|
1107
|
-
isCaseSensitive
|
|
1108
|
-
} = this.options;
|
|
922
|
+
const { includeMatches, isCaseSensitive } = this.options;
|
|
1109
923
|
text = isCaseSensitive ? text : text.toLowerCase();
|
|
1110
924
|
let numMatches = 0;
|
|
1111
925
|
let allIndices = [];
|
|
1112
926
|
let totalScore = 0;
|
|
1113
|
-
|
|
1114
|
-
// ORs
|
|
1115
927
|
for (let i = 0, qLen = query.length; i < qLen; i += 1) {
|
|
1116
|
-
const
|
|
1117
|
-
|
|
1118
|
-
// Reset indices
|
|
928
|
+
const searchers2 = query[i];
|
|
1119
929
|
allIndices.length = 0;
|
|
1120
930
|
numMatches = 0;
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
const searcher = searchers[j];
|
|
1125
|
-
const {
|
|
1126
|
-
isMatch,
|
|
1127
|
-
indices,
|
|
1128
|
-
score
|
|
1129
|
-
} = searcher.search(text);
|
|
931
|
+
for (let j = 0, pLen = searchers2.length; j < pLen; j += 1) {
|
|
932
|
+
const searcher = searchers2[j];
|
|
933
|
+
const { isMatch, indices, score } = searcher.search(text);
|
|
1130
934
|
if (isMatch) {
|
|
1131
935
|
numMatches += 1;
|
|
1132
936
|
totalScore += score;
|
|
@@ -1145,8 +949,6 @@ class ExtendedSearch {
|
|
|
1145
949
|
break;
|
|
1146
950
|
}
|
|
1147
951
|
}
|
|
1148
|
-
|
|
1149
|
-
// OR condition, so if TRUE, return
|
|
1150
952
|
if (numMatches) {
|
|
1151
953
|
let result = {
|
|
1152
954
|
isMatch: true,
|
|
@@ -1158,8 +960,6 @@ class ExtendedSearch {
|
|
|
1158
960
|
return result;
|
|
1159
961
|
}
|
|
1160
962
|
}
|
|
1161
|
-
|
|
1162
|
-
// Nothing was matched
|
|
1163
963
|
return {
|
|
1164
964
|
isMatch: false,
|
|
1165
965
|
score: 1
|
|
@@ -1180,36 +980,31 @@ function createSearcher(pattern, options) {
|
|
|
1180
980
|
return new BitapSearch(pattern, options);
|
|
1181
981
|
}
|
|
1182
982
|
const LogicalOperator = {
|
|
1183
|
-
AND:
|
|
1184
|
-
OR:
|
|
983
|
+
AND: "$and",
|
|
984
|
+
OR: "$or"
|
|
1185
985
|
};
|
|
1186
986
|
const KeyType = {
|
|
1187
|
-
PATH:
|
|
1188
|
-
PATTERN:
|
|
987
|
+
PATH: "$path",
|
|
988
|
+
PATTERN: "$val"
|
|
1189
989
|
};
|
|
1190
|
-
const isExpression = query => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
|
|
1191
|
-
const isPath = query => !!query[KeyType.PATH];
|
|
1192
|
-
const isLeaf = query => !isArray(query) && isObject(query) && !isExpression(query);
|
|
1193
|
-
const convertToExplicit = query => ({
|
|
1194
|
-
[LogicalOperator.AND]: Object.keys(query).map(key => ({
|
|
990
|
+
const isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
|
|
991
|
+
const isPath = (query) => !!query[KeyType.PATH];
|
|
992
|
+
const isLeaf = (query) => !isArray(query) && isObject(query) && !isExpression(query);
|
|
993
|
+
const convertToExplicit = (query) => ({
|
|
994
|
+
[LogicalOperator.AND]: Object.keys(query).map((key) => ({
|
|
1195
995
|
[key]: query[key]
|
|
1196
996
|
}))
|
|
1197
997
|
});
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
const next = query => {
|
|
1205
|
-
let keys = Object.keys(query);
|
|
1206
|
-
const isQueryPath = isPath(query);
|
|
1207
|
-
if (!isQueryPath && keys.length > 1 && !isExpression(query)) {
|
|
1208
|
-
return next(convertToExplicit(query));
|
|
998
|
+
function parse(query, options, { auto = true } = {}) {
|
|
999
|
+
const next = (query2) => {
|
|
1000
|
+
let keys = Object.keys(query2);
|
|
1001
|
+
const isQueryPath = isPath(query2);
|
|
1002
|
+
if (!isQueryPath && keys.length > 1 && !isExpression(query2)) {
|
|
1003
|
+
return next(convertToExplicit(query2));
|
|
1209
1004
|
}
|
|
1210
|
-
if (isLeaf(
|
|
1211
|
-
const key = isQueryPath ?
|
|
1212
|
-
const pattern = isQueryPath ?
|
|
1005
|
+
if (isLeaf(query2)) {
|
|
1006
|
+
const key = isQueryPath ? query2[KeyType.PATH] : keys[0];
|
|
1007
|
+
const pattern = isQueryPath ? query2[KeyType.PATTERN] : query2[key];
|
|
1213
1008
|
if (!isString(pattern)) {
|
|
1214
1009
|
throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
|
|
1215
1010
|
}
|
|
@@ -1226,10 +1021,10 @@ function parse(query, options, {
|
|
|
1226
1021
|
children: [],
|
|
1227
1022
|
operator: keys[0]
|
|
1228
1023
|
};
|
|
1229
|
-
keys.forEach(key => {
|
|
1230
|
-
const value =
|
|
1024
|
+
keys.forEach((key) => {
|
|
1025
|
+
const value = query2[key];
|
|
1231
1026
|
if (isArray(value)) {
|
|
1232
|
-
value.forEach(item => {
|
|
1027
|
+
value.forEach((item) => {
|
|
1233
1028
|
node.children.push(next(item));
|
|
1234
1029
|
});
|
|
1235
1030
|
}
|
|
@@ -1241,20 +1036,15 @@ function parse(query, options, {
|
|
|
1241
1036
|
}
|
|
1242
1037
|
return next(query);
|
|
1243
1038
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
function computeScore(results, {
|
|
1247
|
-
ignoreFieldNorm = Config.ignoreFieldNorm
|
|
1248
|
-
}) {
|
|
1249
|
-
results.forEach(result => {
|
|
1039
|
+
function computeScore(results, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
|
|
1040
|
+
results.forEach((result) => {
|
|
1250
1041
|
let totalScore = 1;
|
|
1251
|
-
result.matches.forEach(({
|
|
1252
|
-
key,
|
|
1253
|
-
norm,
|
|
1254
|
-
score
|
|
1255
|
-
}) => {
|
|
1042
|
+
result.matches.forEach(({ key, norm: norm2, score }) => {
|
|
1256
1043
|
const weight = key ? key.weight : null;
|
|
1257
|
-
totalScore *= Math.pow(
|
|
1044
|
+
totalScore *= Math.pow(
|
|
1045
|
+
score === 0 && weight ? Number.EPSILON : score,
|
|
1046
|
+
(weight || 1) * (ignoreFieldNorm ? 1 : norm2)
|
|
1047
|
+
);
|
|
1258
1048
|
});
|
|
1259
1049
|
result.score = totalScore;
|
|
1260
1050
|
});
|
|
@@ -1265,14 +1055,11 @@ function transformMatches(result, data) {
|
|
|
1265
1055
|
if (!isDefined(matches)) {
|
|
1266
1056
|
return;
|
|
1267
1057
|
}
|
|
1268
|
-
matches.forEach(match => {
|
|
1058
|
+
matches.forEach((match) => {
|
|
1269
1059
|
if (!isDefined(match.indices) || !match.indices.length) {
|
|
1270
1060
|
return;
|
|
1271
1061
|
}
|
|
1272
|
-
const {
|
|
1273
|
-
indices,
|
|
1274
|
-
value
|
|
1275
|
-
} = match;
|
|
1062
|
+
const { indices, value } = match;
|
|
1276
1063
|
let obj = {
|
|
1277
1064
|
indices,
|
|
1278
1065
|
value
|
|
@@ -1294,18 +1081,18 @@ function format(results, docs, {
|
|
|
1294
1081
|
includeScore = Config.includeScore
|
|
1295
1082
|
} = {}) {
|
|
1296
1083
|
const transformers = [];
|
|
1297
|
-
if (includeMatches)
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
} = result;
|
|
1084
|
+
if (includeMatches)
|
|
1085
|
+
transformers.push(transformMatches);
|
|
1086
|
+
if (includeScore)
|
|
1087
|
+
transformers.push(transformScore);
|
|
1088
|
+
return results.map((result) => {
|
|
1089
|
+
const { idx } = result;
|
|
1303
1090
|
const data = {
|
|
1304
1091
|
item: docs[idx],
|
|
1305
1092
|
refIndex: idx
|
|
1306
1093
|
};
|
|
1307
1094
|
if (transformers.length) {
|
|
1308
|
-
transformers.forEach(transformer => {
|
|
1095
|
+
transformers.forEach((transformer) => {
|
|
1309
1096
|
transformer(result, data);
|
|
1310
1097
|
});
|
|
1311
1098
|
}
|
|
@@ -1314,11 +1101,8 @@ function format(results, docs, {
|
|
|
1314
1101
|
}
|
|
1315
1102
|
class Fuse {
|
|
1316
1103
|
constructor(docs, options = {}, index) {
|
|
1317
|
-
this.options = {
|
|
1318
|
-
|
|
1319
|
-
...options
|
|
1320
|
-
};
|
|
1321
|
-
if (this.options.useExtendedSearch && !true) {
|
|
1104
|
+
this.options = { ...Config, ...options };
|
|
1105
|
+
if (this.options.useExtendedSearch && false) {
|
|
1322
1106
|
throw new Error(EXTENDED_SEARCH_UNAVAILABLE);
|
|
1323
1107
|
}
|
|
1324
1108
|
this._keyStore = new KeyStore(this.options.keys);
|
|
@@ -1341,7 +1125,7 @@ class Fuse {
|
|
|
1341
1125
|
this._docs.push(doc);
|
|
1342
1126
|
this._myIndex.add(doc);
|
|
1343
1127
|
}
|
|
1344
|
-
remove(predicate = (
|
|
1128
|
+
remove(predicate = () => false) {
|
|
1345
1129
|
const results = [];
|
|
1346
1130
|
for (let i = 0, len = this._docs.length; i < len; i += 1) {
|
|
1347
1131
|
const doc = this._docs[i];
|
|
@@ -1361,9 +1145,7 @@ class Fuse {
|
|
|
1361
1145
|
getIndex() {
|
|
1362
1146
|
return this._myIndex;
|
|
1363
1147
|
}
|
|
1364
|
-
search(query, {
|
|
1365
|
-
limit = -1
|
|
1366
|
-
} = {}) {
|
|
1148
|
+
search(query, { limit = -1 } = {}) {
|
|
1367
1149
|
const {
|
|
1368
1150
|
includeMatches,
|
|
1369
1151
|
includeScore,
|
|
@@ -1372,9 +1154,7 @@ class Fuse {
|
|
|
1372
1154
|
ignoreFieldNorm
|
|
1373
1155
|
} = this.options;
|
|
1374
1156
|
let results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
|
|
1375
|
-
computeScore(results, {
|
|
1376
|
-
ignoreFieldNorm
|
|
1377
|
-
});
|
|
1157
|
+
computeScore(results, { ignoreFieldNorm });
|
|
1378
1158
|
if (shouldSort) {
|
|
1379
1159
|
results.sort(sortFn);
|
|
1380
1160
|
}
|
|
@@ -1388,35 +1168,18 @@ class Fuse {
|
|
|
1388
1168
|
}
|
|
1389
1169
|
_searchStringList(query) {
|
|
1390
1170
|
const searcher = createSearcher(query, this.options);
|
|
1391
|
-
const {
|
|
1392
|
-
records
|
|
1393
|
-
} = this._myIndex;
|
|
1171
|
+
const { records } = this._myIndex;
|
|
1394
1172
|
const results = [];
|
|
1395
|
-
|
|
1396
|
-
// Iterate over every string in the index
|
|
1397
|
-
records.forEach(({
|
|
1398
|
-
v: text,
|
|
1399
|
-
i: idx,
|
|
1400
|
-
n: norm
|
|
1401
|
-
}) => {
|
|
1173
|
+
records.forEach(({ v: text, i: idx, n: norm2 }) => {
|
|
1402
1174
|
if (!isDefined(text)) {
|
|
1403
1175
|
return;
|
|
1404
1176
|
}
|
|
1405
|
-
const {
|
|
1406
|
-
isMatch,
|
|
1407
|
-
score,
|
|
1408
|
-
indices
|
|
1409
|
-
} = searcher.searchIn(text);
|
|
1177
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1410
1178
|
if (isMatch) {
|
|
1411
1179
|
results.push({
|
|
1412
1180
|
item: text,
|
|
1413
1181
|
idx,
|
|
1414
|
-
matches: [{
|
|
1415
|
-
score,
|
|
1416
|
-
value: text,
|
|
1417
|
-
norm,
|
|
1418
|
-
indices
|
|
1419
|
-
}]
|
|
1182
|
+
matches: [{ score, value: text, norm: norm2, indices }]
|
|
1420
1183
|
});
|
|
1421
1184
|
}
|
|
1422
1185
|
});
|
|
@@ -1426,21 +1189,20 @@ class Fuse {
|
|
|
1426
1189
|
const expression = parse(query, this.options);
|
|
1427
1190
|
const evaluate = (node, item, idx) => {
|
|
1428
1191
|
if (!node.children) {
|
|
1429
|
-
const {
|
|
1430
|
-
keyId,
|
|
1431
|
-
searcher
|
|
1432
|
-
} = node;
|
|
1192
|
+
const { keyId, searcher } = node;
|
|
1433
1193
|
const matches = this._findMatches({
|
|
1434
1194
|
key: this._keyStore.get(keyId),
|
|
1435
1195
|
value: this._myIndex.getValueForItemAtKeyId(item, keyId),
|
|
1436
1196
|
searcher
|
|
1437
1197
|
});
|
|
1438
1198
|
if (matches && matches.length) {
|
|
1439
|
-
return [
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1199
|
+
return [
|
|
1200
|
+
{
|
|
1201
|
+
idx,
|
|
1202
|
+
item,
|
|
1203
|
+
matches
|
|
1204
|
+
}
|
|
1205
|
+
];
|
|
1444
1206
|
}
|
|
1445
1207
|
return [];
|
|
1446
1208
|
}
|
|
@@ -1459,25 +1221,15 @@ class Fuse {
|
|
|
1459
1221
|
const records = this._myIndex.records;
|
|
1460
1222
|
const resultMap = {};
|
|
1461
1223
|
const results = [];
|
|
1462
|
-
records.forEach(({
|
|
1463
|
-
$: item,
|
|
1464
|
-
i: idx
|
|
1465
|
-
}) => {
|
|
1224
|
+
records.forEach(({ $: item, i: idx }) => {
|
|
1466
1225
|
if (isDefined(item)) {
|
|
1467
1226
|
let expResults = evaluate(expression, item, idx);
|
|
1468
1227
|
if (expResults.length) {
|
|
1469
|
-
// Dedupe when adding
|
|
1470
1228
|
if (!resultMap[idx]) {
|
|
1471
|
-
resultMap[idx] = {
|
|
1472
|
-
idx,
|
|
1473
|
-
item,
|
|
1474
|
-
matches: []
|
|
1475
|
-
};
|
|
1229
|
+
resultMap[idx] = { idx, item, matches: [] };
|
|
1476
1230
|
results.push(resultMap[idx]);
|
|
1477
1231
|
}
|
|
1478
|
-
expResults.forEach(({
|
|
1479
|
-
matches
|
|
1480
|
-
}) => {
|
|
1232
|
+
expResults.forEach(({ matches }) => {
|
|
1481
1233
|
resultMap[idx].matches.push(...matches);
|
|
1482
1234
|
});
|
|
1483
1235
|
}
|
|
@@ -1487,29 +1239,21 @@ class Fuse {
|
|
|
1487
1239
|
}
|
|
1488
1240
|
_searchObjectList(query) {
|
|
1489
1241
|
const searcher = createSearcher(query, this.options);
|
|
1490
|
-
const {
|
|
1491
|
-
keys,
|
|
1492
|
-
records
|
|
1493
|
-
} = this._myIndex;
|
|
1242
|
+
const { keys, records } = this._myIndex;
|
|
1494
1243
|
const results = [];
|
|
1495
|
-
|
|
1496
|
-
// List is Array<Object>
|
|
1497
|
-
records.forEach(({
|
|
1498
|
-
$: item,
|
|
1499
|
-
i: idx
|
|
1500
|
-
}) => {
|
|
1244
|
+
records.forEach(({ $: item, i: idx }) => {
|
|
1501
1245
|
if (!isDefined(item)) {
|
|
1502
1246
|
return;
|
|
1503
1247
|
}
|
|
1504
1248
|
let matches = [];
|
|
1505
|
-
|
|
1506
|
-
// Iterate over every key (i.e, path), and fetch the value at that key
|
|
1507
1249
|
keys.forEach((key, keyIndex) => {
|
|
1508
|
-
matches.push(
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1250
|
+
matches.push(
|
|
1251
|
+
...this._findMatches({
|
|
1252
|
+
key,
|
|
1253
|
+
value: item[keyIndex],
|
|
1254
|
+
searcher
|
|
1255
|
+
})
|
|
1256
|
+
);
|
|
1513
1257
|
});
|
|
1514
1258
|
if (matches.length) {
|
|
1515
1259
|
results.push({
|
|
@@ -1521,64 +1265,39 @@ class Fuse {
|
|
|
1521
1265
|
});
|
|
1522
1266
|
return results;
|
|
1523
1267
|
}
|
|
1524
|
-
_findMatches({
|
|
1525
|
-
key,
|
|
1526
|
-
value,
|
|
1527
|
-
searcher
|
|
1528
|
-
}) {
|
|
1268
|
+
_findMatches({ key, value, searcher }) {
|
|
1529
1269
|
if (!isDefined(value)) {
|
|
1530
1270
|
return [];
|
|
1531
1271
|
}
|
|
1532
1272
|
let matches = [];
|
|
1533
1273
|
if (isArray(value)) {
|
|
1534
|
-
value.forEach(({
|
|
1535
|
-
v: text,
|
|
1536
|
-
i: idx,
|
|
1537
|
-
n: norm
|
|
1538
|
-
}) => {
|
|
1274
|
+
value.forEach(({ v: text, i: idx, n: norm2 }) => {
|
|
1539
1275
|
if (!isDefined(text)) {
|
|
1540
1276
|
return;
|
|
1541
1277
|
}
|
|
1542
|
-
const {
|
|
1543
|
-
isMatch,
|
|
1544
|
-
score,
|
|
1545
|
-
indices
|
|
1546
|
-
} = searcher.searchIn(text);
|
|
1278
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1547
1279
|
if (isMatch) {
|
|
1548
1280
|
matches.push({
|
|
1549
1281
|
score,
|
|
1550
1282
|
key,
|
|
1551
1283
|
value: text,
|
|
1552
1284
|
idx,
|
|
1553
|
-
norm,
|
|
1285
|
+
norm: norm2,
|
|
1554
1286
|
indices
|
|
1555
1287
|
});
|
|
1556
1288
|
}
|
|
1557
1289
|
});
|
|
1558
1290
|
} else {
|
|
1559
|
-
const {
|
|
1560
|
-
|
|
1561
|
-
n: norm
|
|
1562
|
-
} = value;
|
|
1563
|
-
const {
|
|
1564
|
-
isMatch,
|
|
1565
|
-
score,
|
|
1566
|
-
indices
|
|
1567
|
-
} = searcher.searchIn(text);
|
|
1291
|
+
const { v: text, n: norm2 } = value;
|
|
1292
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1568
1293
|
if (isMatch) {
|
|
1569
|
-
matches.push({
|
|
1570
|
-
score,
|
|
1571
|
-
key,
|
|
1572
|
-
value: text,
|
|
1573
|
-
norm,
|
|
1574
|
-
indices
|
|
1575
|
-
});
|
|
1294
|
+
matches.push({ score, key, value: text, norm: norm2, indices });
|
|
1576
1295
|
}
|
|
1577
1296
|
}
|
|
1578
1297
|
return matches;
|
|
1579
1298
|
}
|
|
1580
1299
|
}
|
|
1581
|
-
Fuse.version =
|
|
1300
|
+
Fuse.version = "6.6.2";
|
|
1582
1301
|
Fuse.createIndex = createIndex;
|
|
1583
1302
|
Fuse.parseIndex = parseIndex;
|
|
1584
1303
|
Fuse.config = Config;
|
|
@@ -1588,6 +1307,231 @@ Fuse.config = Config;
|
|
|
1588
1307
|
{
|
|
1589
1308
|
register(ExtendedSearch);
|
|
1590
1309
|
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1310
|
+
function uniqID() {
|
|
1311
|
+
return "_" + (Math.random() * Math.pow(36, 20)).toString(36).slice(0, 10);
|
|
1312
|
+
}
|
|
1313
|
+
function stringToDom(html) {
|
|
1314
|
+
const template = document.createElement("template");
|
|
1315
|
+
template.innerHTML = html;
|
|
1316
|
+
return template.content;
|
|
1317
|
+
}
|
|
1318
|
+
async function evalTemplateString(str, variables = {}) {
|
|
1319
|
+
const keys = Object.keys(variables);
|
|
1320
|
+
const values = keys.map((key) => variables[key]);
|
|
1321
|
+
try {
|
|
1322
|
+
const AsyncFunction = Object.getPrototypeOf(async function() {
|
|
1323
|
+
}).constructor;
|
|
1324
|
+
const func = AsyncFunction.call(null, ...keys, "return `" + str + "`");
|
|
1325
|
+
return await func(...values);
|
|
1326
|
+
} catch (e) {
|
|
1327
|
+
console.log(e);
|
|
1328
|
+
throw new SyntaxError("`" + str + "`");
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
function importCSS(...stylesheets) {
|
|
1332
|
+
const linksElements = [];
|
|
1333
|
+
for (let url of stylesheets) {
|
|
1334
|
+
url = relativeSource(url);
|
|
1335
|
+
let link = Array.from(document.head.querySelectorAll("link")).find(
|
|
1336
|
+
(link2) => link2.href === url
|
|
1337
|
+
);
|
|
1338
|
+
if (link)
|
|
1339
|
+
return link;
|
|
1340
|
+
link = document.createElement("link");
|
|
1341
|
+
link.rel = "stylesheet";
|
|
1342
|
+
link.href = url;
|
|
1343
|
+
document.head.appendChild(link);
|
|
1344
|
+
linksElements.push(link);
|
|
1345
|
+
}
|
|
1346
|
+
return linksElements;
|
|
1347
|
+
}
|
|
1348
|
+
function importJS(...plugins) {
|
|
1349
|
+
return plugins.map((url) => {
|
|
1350
|
+
url = new URL(url, document.baseURI).href;
|
|
1351
|
+
let script = Array.from(document.querySelectorAll("script")).find(
|
|
1352
|
+
(script2) => script2.src === url
|
|
1353
|
+
);
|
|
1354
|
+
if (script)
|
|
1355
|
+
return script;
|
|
1356
|
+
script = document.createElement("script");
|
|
1357
|
+
script.src = url;
|
|
1358
|
+
document.head.appendChild(script);
|
|
1359
|
+
return script;
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
function relativeSource(source) {
|
|
1363
|
+
if (!source.match(/^\..?\//))
|
|
1364
|
+
return new URL(source, document.baseURI).href;
|
|
1365
|
+
const e = new Error();
|
|
1366
|
+
if (!e.stack)
|
|
1367
|
+
return source;
|
|
1368
|
+
const f2 = e.stack.split("\n").filter((l) => l.includes(":"))[2];
|
|
1369
|
+
let line = f2.match(/[a-z]+:.*$/);
|
|
1370
|
+
if (!line)
|
|
1371
|
+
return source;
|
|
1372
|
+
const calledFile = line[0].replace(/(\:[0-9]+){2}\)?$/, "");
|
|
1373
|
+
source = new URL(source, calledFile).href;
|
|
1374
|
+
return source;
|
|
1375
|
+
}
|
|
1376
|
+
function loadScript(source) {
|
|
1377
|
+
source = relativeSource(source);
|
|
1378
|
+
return new Promise((resolve) => {
|
|
1379
|
+
var script = document.createElement("script");
|
|
1380
|
+
var head = document.querySelector("head");
|
|
1381
|
+
script.async = true;
|
|
1382
|
+
script.onload = () => setTimeout(resolve, 0);
|
|
1383
|
+
script.src = source;
|
|
1384
|
+
if (head)
|
|
1385
|
+
head.appendChild(script);
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
function domIsReady() {
|
|
1389
|
+
return new Promise(function(resolve) {
|
|
1390
|
+
if (document.readyState === "complete") {
|
|
1391
|
+
resolve();
|
|
1392
|
+
} else {
|
|
1393
|
+
document.addEventListener("DOMContentLoaded", () => resolve());
|
|
1394
|
+
}
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
function setDeepProperty(obj, path, value) {
|
|
1398
|
+
const name = path.shift();
|
|
1399
|
+
if (name) {
|
|
1400
|
+
if (!(name in obj))
|
|
1401
|
+
obj[name] = {};
|
|
1402
|
+
if (path.length)
|
|
1403
|
+
setDeepProperty(obj[name], path, value);
|
|
1404
|
+
else
|
|
1405
|
+
obj[name] = value;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
function parseFieldsString(fields) {
|
|
1409
|
+
let fieldsArray;
|
|
1410
|
+
while (fields.indexOf("(") > 0) {
|
|
1411
|
+
let firstBracket = fields.indexOf("(");
|
|
1412
|
+
let noset = fields.substring(firstBracket, findClosingBracketMatchIndex(fields, firstBracket) + 1);
|
|
1413
|
+
fields = fields.replace(noset, "");
|
|
1414
|
+
}
|
|
1415
|
+
const re = /((^\s*|,)\s*)(("(\\"|[^"])*")|('(\\'|[^'])*')|[^,]*)/gm;
|
|
1416
|
+
fieldsArray = fields.match(re) || [];
|
|
1417
|
+
if (!fieldsArray)
|
|
1418
|
+
return [];
|
|
1419
|
+
return fieldsArray.map((a) => a.replace(/^[\s,]+/, ""));
|
|
1420
|
+
}
|
|
1421
|
+
function findClosingBracketMatchIndex(str, pos) {
|
|
1422
|
+
if (str[pos] != "(")
|
|
1423
|
+
throw new Error("No '(' at index " + pos);
|
|
1424
|
+
let depth = 1;
|
|
1425
|
+
for (let i = pos + 1; i < str.length; i++) {
|
|
1426
|
+
switch (str[i]) {
|
|
1427
|
+
case "(":
|
|
1428
|
+
depth++;
|
|
1429
|
+
break;
|
|
1430
|
+
case ")":
|
|
1431
|
+
if (--depth == 0)
|
|
1432
|
+
return i;
|
|
1433
|
+
break;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
return -1;
|
|
1437
|
+
}
|
|
1438
|
+
function defineComponent(tagName, componentClass) {
|
|
1439
|
+
if (!customElements.get(tagName)) {
|
|
1440
|
+
customElements.define(tagName, componentClass);
|
|
1441
|
+
} else {
|
|
1442
|
+
console.warn(`Warning: the component "${tagName}" has already been loaded in another version of sib-core.`);
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
function fuzzyCompare(subject, search2) {
|
|
1446
|
+
const fuse = new Fuse([subject], {
|
|
1447
|
+
shouldSort: false,
|
|
1448
|
+
threshold: 0.37
|
|
1449
|
+
}).search(search2);
|
|
1450
|
+
return fuse.length > 0;
|
|
1451
|
+
}
|
|
1452
|
+
const compare = {
|
|
1453
|
+
string(subject, query) {
|
|
1454
|
+
if (query === "")
|
|
1455
|
+
return true;
|
|
1456
|
+
if (subject.toString().toLowerCase().includes(String(query).toLowerCase()))
|
|
1457
|
+
return true;
|
|
1458
|
+
return fuzzyCompare(subject, query);
|
|
1459
|
+
},
|
|
1460
|
+
boolean(subject, query) {
|
|
1461
|
+
if (!query)
|
|
1462
|
+
return true;
|
|
1463
|
+
return subject;
|
|
1464
|
+
},
|
|
1465
|
+
number(subject, query) {
|
|
1466
|
+
return subject === query;
|
|
1467
|
+
},
|
|
1468
|
+
list(subject, list) {
|
|
1469
|
+
return list.includes(subject);
|
|
1470
|
+
},
|
|
1471
|
+
range(subject, range) {
|
|
1472
|
+
return (range[0] == null || range[0] === "" || subject >= range[0]) && (range[1] == null || range[1] === "" || subject <= range[1]);
|
|
1473
|
+
},
|
|
1474
|
+
resource(subject, query) {
|
|
1475
|
+
if (query === "")
|
|
1476
|
+
return true;
|
|
1477
|
+
if (!query["@id"])
|
|
1478
|
+
return false;
|
|
1479
|
+
const ret = subject["@id"] === query["@id"];
|
|
1480
|
+
return ret;
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
function transformArrayToContainer(resource) {
|
|
1484
|
+
const newValue = { ...resource };
|
|
1485
|
+
for (let predicate of Object.keys(newValue)) {
|
|
1486
|
+
const predicateValue = newValue[predicate];
|
|
1487
|
+
if (!predicateValue || typeof predicateValue !== "object")
|
|
1488
|
+
continue;
|
|
1489
|
+
if (["permissions", "@context"].includes(predicate))
|
|
1490
|
+
continue;
|
|
1491
|
+
if (!Array.isArray(predicateValue) && predicateValue["@id"]) {
|
|
1492
|
+
newValue[predicate] = transformArrayToContainer(resource[predicate]);
|
|
1493
|
+
}
|
|
1494
|
+
if (Array.isArray(predicateValue)) {
|
|
1495
|
+
newValue[predicate] = { "ldp:contains": [...predicateValue] };
|
|
1496
|
+
newValue[predicate]["ldp:contains"].forEach((childPredicate, index) => {
|
|
1497
|
+
newValue[predicate]["ldp:contains"][index] = transformArrayToContainer(childPredicate);
|
|
1498
|
+
});
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
return newValue;
|
|
1502
|
+
}
|
|
1503
|
+
const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1504
|
+
__proto__: null,
|
|
1505
|
+
compare,
|
|
1506
|
+
defineComponent,
|
|
1507
|
+
domIsReady,
|
|
1508
|
+
evalTemplateString,
|
|
1509
|
+
findClosingBracketMatchIndex,
|
|
1510
|
+
fuzzyCompare,
|
|
1511
|
+
importCSS,
|
|
1512
|
+
importJS,
|
|
1513
|
+
loadScript,
|
|
1514
|
+
parseFieldsString,
|
|
1515
|
+
setDeepProperty,
|
|
1516
|
+
stringToDom,
|
|
1517
|
+
transformArrayToContainer,
|
|
1518
|
+
uniqID
|
|
1519
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
1520
|
+
export {
|
|
1521
|
+
findClosingBracketMatchIndex as a,
|
|
1522
|
+
stringToDom as b,
|
|
1523
|
+
compare as c,
|
|
1524
|
+
defineComponent as d,
|
|
1525
|
+
evalTemplateString as e,
|
|
1526
|
+
fuzzyCompare as f,
|
|
1527
|
+
importJS as g,
|
|
1528
|
+
helpers as h,
|
|
1529
|
+
importCSS as i,
|
|
1530
|
+
domIsReady as j,
|
|
1531
|
+
loadScript as l,
|
|
1532
|
+
parseFieldsString as p,
|
|
1533
|
+
setDeepProperty as s,
|
|
1534
|
+
transformArrayToContainer as t,
|
|
1535
|
+
uniqID as u
|
|
1536
|
+
};
|
|
1537
|
+
//# sourceMappingURL=helpers-bf15809c.js.map
|