@startinblox/core 0.19.0-beta.2 → 0.19.0-beta.21
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-411e08e4.js} +499 -454
- package/dist/assets/helpers-411e08e4.js.map +1 -0
- package/dist/{_snowpack/pkg/leaflet/dist/leaflet.css → assets/leaflet-3c081932.css} +3 -3
- package/dist/helpers.js +22 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.js +54873 -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 -313
- 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 -364
- 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 -125
- 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,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
var __accessCheck = (obj, member, msg) => {
|
|
2
|
+
if (!member.has(obj))
|
|
3
|
+
throw TypeError("Cannot " + msg);
|
|
4
|
+
};
|
|
5
|
+
var __privateGet = (obj, member, getter) => {
|
|
6
|
+
__accessCheck(obj, member, "read from private field");
|
|
7
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
8
|
+
};
|
|
9
|
+
var __privateAdd = (obj, member, value) => {
|
|
10
|
+
if (member.has(obj))
|
|
11
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
12
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
13
|
+
};
|
|
14
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
15
|
+
__accessCheck(obj, member, "write to private field");
|
|
16
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
|
+
var __privateMethod = (obj, member, method) => {
|
|
20
|
+
__accessCheck(obj, member, "access private method");
|
|
21
|
+
return method;
|
|
22
|
+
};
|
|
23
|
+
var _values, _resolve, _createIterable, createIterable_fn, _next, next_fn, _nextPromise, nextPromise_fn;
|
|
10
24
|
function isArray(value) {
|
|
11
|
-
return !Array.isArray ? getTag(value) ===
|
|
25
|
+
return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
|
|
12
26
|
}
|
|
13
|
-
|
|
14
|
-
// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js
|
|
15
27
|
const INFINITY = 1 / 0;
|
|
16
28
|
function baseToString(value) {
|
|
17
|
-
|
|
18
|
-
if (typeof value == 'string') {
|
|
29
|
+
if (typeof value == "string") {
|
|
19
30
|
return value;
|
|
20
31
|
}
|
|
21
|
-
let result = value +
|
|
22
|
-
return result ==
|
|
32
|
+
let result = value + "";
|
|
33
|
+
return result == "0" && 1 / value == -INFINITY ? "-0" : result;
|
|
23
34
|
}
|
|
24
35
|
function toString(value) {
|
|
25
|
-
return value == null ?
|
|
36
|
+
return value == null ? "" : baseToString(value);
|
|
26
37
|
}
|
|
27
38
|
function isString(value) {
|
|
28
|
-
return typeof value ===
|
|
39
|
+
return typeof value === "string";
|
|
29
40
|
}
|
|
30
41
|
function isNumber(value) {
|
|
31
|
-
return typeof value ===
|
|
42
|
+
return typeof value === "number";
|
|
32
43
|
}
|
|
33
|
-
|
|
34
|
-
// Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js
|
|
35
44
|
function isBoolean(value) {
|
|
36
|
-
return value === true || value === false || isObjectLike(value) && getTag(value) ==
|
|
45
|
+
return value === true || value === false || isObjectLike(value) && getTag(value) == "[object Boolean]";
|
|
37
46
|
}
|
|
38
47
|
function isObject(value) {
|
|
39
|
-
return typeof value ===
|
|
48
|
+
return typeof value === "object";
|
|
40
49
|
}
|
|
41
|
-
|
|
42
|
-
// Checks if `value` is object-like.
|
|
43
50
|
function isObjectLike(value) {
|
|
44
51
|
return isObject(value) && value !== null;
|
|
45
52
|
}
|
|
46
53
|
function isDefined(value) {
|
|
47
|
-
return value !==
|
|
54
|
+
return value !== void 0 && value !== null;
|
|
48
55
|
}
|
|
49
56
|
function isBlank(value) {
|
|
50
57
|
return !value.trim().length;
|
|
51
58
|
}
|
|
52
|
-
|
|
53
|
-
// Gets the `toStringTag` of `value`.
|
|
54
|
-
// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js
|
|
55
59
|
function getTag(value) {
|
|
56
|
-
return value == null ? value ===
|
|
60
|
+
return value == null ? value === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
|
|
57
61
|
}
|
|
58
|
-
const EXTENDED_SEARCH_UNAVAILABLE =
|
|
62
|
+
const EXTENDED_SEARCH_UNAVAILABLE = "Extended search is not available";
|
|
59
63
|
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`;
|
|
64
|
+
const LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
|
|
65
|
+
const PATTERN_LENGTH_TOO_LARGE = (max) => `Pattern length exceeds max of ${max}.`;
|
|
66
|
+
const MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
|
|
67
|
+
const INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
|
|
64
68
|
const hasOwn = Object.prototype.hasOwnProperty;
|
|
65
69
|
class KeyStore {
|
|
66
70
|
constructor(keys) {
|
|
67
71
|
this._keys = [];
|
|
68
72
|
this._keyMap = {};
|
|
69
73
|
let totalWeight = 0;
|
|
70
|
-
keys.forEach(key => {
|
|
74
|
+
keys.forEach((key) => {
|
|
71
75
|
let obj = createKey(key);
|
|
72
76
|
totalWeight += obj.weight;
|
|
73
77
|
this._keys.push(obj);
|
|
74
78
|
this._keyMap[obj.id] = obj;
|
|
75
79
|
totalWeight += obj.weight;
|
|
76
80
|
});
|
|
77
|
-
|
|
78
|
-
// Normalize weights so that their sum is equal to 1
|
|
79
|
-
this._keys.forEach(key => {
|
|
81
|
+
this._keys.forEach((key) => {
|
|
80
82
|
key.weight /= totalWeight;
|
|
81
83
|
});
|
|
82
84
|
}
|
|
@@ -101,12 +103,12 @@ function createKey(key) {
|
|
|
101
103
|
path = createKeyPath(key);
|
|
102
104
|
id = createKeyId(key);
|
|
103
105
|
} else {
|
|
104
|
-
if (!hasOwn.call(key,
|
|
105
|
-
throw new Error(MISSING_KEY_PROPERTY(
|
|
106
|
+
if (!hasOwn.call(key, "name")) {
|
|
107
|
+
throw new Error(MISSING_KEY_PROPERTY("name"));
|
|
106
108
|
}
|
|
107
109
|
const name = key.name;
|
|
108
110
|
src = name;
|
|
109
|
-
if (hasOwn.call(key,
|
|
111
|
+
if (hasOwn.call(key, "weight")) {
|
|
110
112
|
weight = key.weight;
|
|
111
113
|
if (weight <= 0) {
|
|
112
114
|
throw new Error(INVALID_KEY_WEIGHT_VALUE(name));
|
|
@@ -116,56 +118,42 @@ function createKey(key) {
|
|
|
116
118
|
id = createKeyId(name);
|
|
117
119
|
getFn = key.getFn;
|
|
118
120
|
}
|
|
119
|
-
return {
|
|
120
|
-
path,
|
|
121
|
-
id,
|
|
122
|
-
weight,
|
|
123
|
-
src,
|
|
124
|
-
getFn
|
|
125
|
-
};
|
|
121
|
+
return { path, id, weight, src, getFn };
|
|
126
122
|
}
|
|
127
123
|
function createKeyPath(key) {
|
|
128
|
-
return isArray(key) ? key : key.split(
|
|
124
|
+
return isArray(key) ? key : key.split(".");
|
|
129
125
|
}
|
|
130
126
|
function createKeyId(key) {
|
|
131
|
-
return isArray(key) ? key.join(
|
|
127
|
+
return isArray(key) ? key.join(".") : key;
|
|
132
128
|
}
|
|
133
129
|
function get(obj, path) {
|
|
134
130
|
let list = [];
|
|
135
131
|
let arr = false;
|
|
136
|
-
const deepGet = (
|
|
137
|
-
if (!isDefined(
|
|
132
|
+
const deepGet = (obj2, path2, index) => {
|
|
133
|
+
if (!isDefined(obj2)) {
|
|
138
134
|
return;
|
|
139
135
|
}
|
|
140
|
-
if (!
|
|
141
|
-
|
|
142
|
-
list.push(obj);
|
|
136
|
+
if (!path2[index]) {
|
|
137
|
+
list.push(obj2);
|
|
143
138
|
} else {
|
|
144
|
-
let key =
|
|
145
|
-
const value =
|
|
139
|
+
let key = path2[index];
|
|
140
|
+
const value = obj2[key];
|
|
146
141
|
if (!isDefined(value)) {
|
|
147
142
|
return;
|
|
148
143
|
}
|
|
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))) {
|
|
144
|
+
if (index === path2.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) {
|
|
153
145
|
list.push(toString(value));
|
|
154
146
|
} else if (isArray(value)) {
|
|
155
147
|
arr = true;
|
|
156
|
-
// Search each item in the array.
|
|
157
148
|
for (let i = 0, len = value.length; i < len; i += 1) {
|
|
158
|
-
deepGet(value[i],
|
|
149
|
+
deepGet(value[i], path2, index + 1);
|
|
159
150
|
}
|
|
160
|
-
} else if (
|
|
161
|
-
|
|
162
|
-
deepGet(value, path, index + 1);
|
|
151
|
+
} else if (path2.length) {
|
|
152
|
+
deepGet(value, path2, index + 1);
|
|
163
153
|
}
|
|
164
154
|
}
|
|
165
155
|
};
|
|
166
|
-
|
|
167
|
-
// Backwards compatibility (since path used to be a string)
|
|
168
|
-
deepGet(obj, isString(path) ? path.split('.') : path, 0);
|
|
156
|
+
deepGet(obj, isString(path) ? path.split(".") : path, 0);
|
|
169
157
|
return arr ? list : list[0];
|
|
170
158
|
}
|
|
171
159
|
const MatchOptions = {
|
|
@@ -229,11 +217,8 @@ var Config = {
|
|
|
229
217
|
...AdvancedOptions
|
|
230
218
|
};
|
|
231
219
|
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
220
|
function norm(weight = 1, mantissa = 3) {
|
|
236
|
-
const cache = new Map();
|
|
221
|
+
const cache = /* @__PURE__ */ new Map();
|
|
237
222
|
const m = Math.pow(10, mantissa);
|
|
238
223
|
return {
|
|
239
224
|
get(value) {
|
|
@@ -241,12 +226,8 @@ function norm(weight = 1, mantissa = 3) {
|
|
|
241
226
|
if (cache.has(numTokens)) {
|
|
242
227
|
return cache.get(numTokens);
|
|
243
228
|
}
|
|
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);
|
|
229
|
+
const norm2 = 1 / Math.pow(numTokens, 0.5 * weight);
|
|
230
|
+
const n = parseFloat(Math.round(norm2 * m) / m);
|
|
250
231
|
cache.set(numTokens, n);
|
|
251
232
|
return n;
|
|
252
233
|
},
|
|
@@ -283,14 +264,11 @@ class FuseIndex {
|
|
|
283
264
|
return;
|
|
284
265
|
}
|
|
285
266
|
this.isCreated = true;
|
|
286
|
-
|
|
287
|
-
// List is Array<String>
|
|
288
267
|
if (isString(this.docs[0])) {
|
|
289
268
|
this.docs.forEach((doc, docIndex) => {
|
|
290
269
|
this._addString(doc, docIndex);
|
|
291
270
|
});
|
|
292
271
|
} else {
|
|
293
|
-
// List is Array<Object>
|
|
294
272
|
this.docs.forEach((doc, docIndex) => {
|
|
295
273
|
this._addObject(doc, docIndex);
|
|
296
274
|
});
|
|
@@ -309,8 +287,6 @@ class FuseIndex {
|
|
|
309
287
|
// Removes the doc at the specified index of the index
|
|
310
288
|
removeAt(idx) {
|
|
311
289
|
this.records.splice(idx, 1);
|
|
312
|
-
|
|
313
|
-
// Change ref index of every subsquent doc
|
|
314
290
|
for (let i = idx, len = this.size(); i < len; i += 1) {
|
|
315
291
|
this.records[i].i -= 1;
|
|
316
292
|
}
|
|
@@ -333,12 +309,7 @@ class FuseIndex {
|
|
|
333
309
|
this.records.push(record);
|
|
334
310
|
}
|
|
335
311
|
_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
|
|
312
|
+
let record = { i: docIndex, $: {} };
|
|
342
313
|
this.keys.forEach((key, keyIndex) => {
|
|
343
314
|
let value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
|
|
344
315
|
if (!isDefined(value)) {
|
|
@@ -346,33 +317,28 @@ class FuseIndex {
|
|
|
346
317
|
}
|
|
347
318
|
if (isArray(value)) {
|
|
348
319
|
let subRecords = [];
|
|
349
|
-
const stack = [{
|
|
350
|
-
nestedArrIndex: -1,
|
|
351
|
-
value
|
|
352
|
-
}];
|
|
320
|
+
const stack = [{ nestedArrIndex: -1, value }];
|
|
353
321
|
while (stack.length) {
|
|
354
|
-
const {
|
|
355
|
-
|
|
356
|
-
value
|
|
357
|
-
} = stack.pop();
|
|
358
|
-
if (!isDefined(value)) {
|
|
322
|
+
const { nestedArrIndex, value: value2 } = stack.pop();
|
|
323
|
+
if (!isDefined(value2)) {
|
|
359
324
|
continue;
|
|
360
325
|
}
|
|
361
|
-
if (isString(
|
|
326
|
+
if (isString(value2) && !isBlank(value2)) {
|
|
362
327
|
let subRecord = {
|
|
363
|
-
v:
|
|
328
|
+
v: value2,
|
|
364
329
|
i: nestedArrIndex,
|
|
365
|
-
n: this.norm.get(
|
|
330
|
+
n: this.norm.get(value2)
|
|
366
331
|
};
|
|
367
332
|
subRecords.push(subRecord);
|
|
368
|
-
} else if (isArray(
|
|
369
|
-
|
|
333
|
+
} else if (isArray(value2)) {
|
|
334
|
+
value2.forEach((item, k) => {
|
|
370
335
|
stack.push({
|
|
371
336
|
nestedArrIndex: k,
|
|
372
337
|
value: item
|
|
373
338
|
});
|
|
374
339
|
});
|
|
375
|
-
} else
|
|
340
|
+
} else
|
|
341
|
+
;
|
|
376
342
|
}
|
|
377
343
|
record.$[keyIndex] = subRecords;
|
|
378
344
|
} else if (isString(value) && !isBlank(value)) {
|
|
@@ -392,31 +358,16 @@ class FuseIndex {
|
|
|
392
358
|
};
|
|
393
359
|
}
|
|
394
360
|
}
|
|
395
|
-
function createIndex(keys, docs, {
|
|
396
|
-
|
|
397
|
-
fieldNormWeight = Config.fieldNormWeight
|
|
398
|
-
} = {}) {
|
|
399
|
-
const myIndex = new FuseIndex({
|
|
400
|
-
getFn,
|
|
401
|
-
fieldNormWeight
|
|
402
|
-
});
|
|
361
|
+
function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
362
|
+
const myIndex = new FuseIndex({ getFn, fieldNormWeight });
|
|
403
363
|
myIndex.setKeys(keys.map(createKey));
|
|
404
364
|
myIndex.setSources(docs);
|
|
405
365
|
myIndex.create();
|
|
406
366
|
return myIndex;
|
|
407
367
|
}
|
|
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
|
-
});
|
|
368
|
+
function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
369
|
+
const { keys, records } = data;
|
|
370
|
+
const myIndex = new FuseIndex({ getFn, fieldNormWeight });
|
|
420
371
|
myIndex.setKeys(keys);
|
|
421
372
|
myIndex.setIndexRecords(records);
|
|
422
373
|
return myIndex;
|
|
@@ -434,8 +385,7 @@ function computeScore$1(pattern, {
|
|
|
434
385
|
}
|
|
435
386
|
const proximity = Math.abs(expectedLocation - currentLocation);
|
|
436
387
|
if (!distance) {
|
|
437
|
-
|
|
438
|
-
return proximity ? 1.0 : accuracy;
|
|
388
|
+
return proximity ? 1 : accuracy;
|
|
439
389
|
}
|
|
440
390
|
return accuracy + proximity / distance;
|
|
441
391
|
}
|
|
@@ -456,15 +406,11 @@ function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMat
|
|
|
456
406
|
start = -1;
|
|
457
407
|
}
|
|
458
408
|
}
|
|
459
|
-
|
|
460
|
-
// (i-1 - start) + 1 => i - start
|
|
461
409
|
if (matchmask[i - 1] && i - start >= minMatchCharLength) {
|
|
462
410
|
indices.push([start, i - 1]);
|
|
463
411
|
}
|
|
464
412
|
return indices;
|
|
465
413
|
}
|
|
466
|
-
|
|
467
|
-
// Machine word size
|
|
468
414
|
const MAX_BITS = 32;
|
|
469
415
|
function search(text, pattern, patternAlphabet, {
|
|
470
416
|
location = Config.location,
|
|
@@ -479,23 +425,13 @@ function search(text, pattern, patternAlphabet, {
|
|
|
479
425
|
throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
|
|
480
426
|
}
|
|
481
427
|
const patternLen = pattern.length;
|
|
482
|
-
// Set starting location at beginning text and initialize the alphabet.
|
|
483
428
|
const textLen = text.length;
|
|
484
|
-
// Handle the case when location > text.length
|
|
485
429
|
const expectedLocation = Math.max(0, Math.min(location, textLen));
|
|
486
|
-
// Highest score beyond which we give up.
|
|
487
430
|
let currentThreshold = threshold;
|
|
488
|
-
// Is there a nearby exact match? (speedup)
|
|
489
431
|
let bestLocation = expectedLocation;
|
|
490
|
-
|
|
491
|
-
// Performance: only computer matches when the minMatchCharLength > 1
|
|
492
|
-
// OR if `includeMatches` is true.
|
|
493
432
|
const computeMatches = minMatchCharLength > 1 || includeMatches;
|
|
494
|
-
// A mask of the matches, used for building the indices
|
|
495
433
|
const matchMask = computeMatches ? Array(textLen) : [];
|
|
496
434
|
let index;
|
|
497
|
-
|
|
498
|
-
// Get all exact matches, here for speed up
|
|
499
435
|
while ((index = text.indexOf(pattern, bestLocation)) > -1) {
|
|
500
436
|
let score = computeScore$1(pattern, {
|
|
501
437
|
currentLocation: index,
|
|
@@ -513,55 +449,41 @@ function search(text, pattern, patternAlphabet, {
|
|
|
513
449
|
}
|
|
514
450
|
}
|
|
515
451
|
}
|
|
516
|
-
|
|
517
|
-
// Reset the best location
|
|
518
452
|
bestLocation = -1;
|
|
519
453
|
let lastBitArr = [];
|
|
520
454
|
let finalScore = 1;
|
|
521
455
|
let binMax = patternLen + textLen;
|
|
522
456
|
const mask = 1 << patternLen - 1;
|
|
523
457
|
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
458
|
let binMin = 0;
|
|
528
459
|
let binMid = binMax;
|
|
529
460
|
while (binMin < binMid) {
|
|
530
|
-
const
|
|
461
|
+
const score2 = computeScore$1(pattern, {
|
|
531
462
|
errors: i,
|
|
532
463
|
currentLocation: expectedLocation + binMid,
|
|
533
464
|
expectedLocation,
|
|
534
465
|
distance,
|
|
535
466
|
ignoreLocation
|
|
536
467
|
});
|
|
537
|
-
if (
|
|
468
|
+
if (score2 <= currentThreshold) {
|
|
538
469
|
binMin = binMid;
|
|
539
470
|
} else {
|
|
540
471
|
binMax = binMid;
|
|
541
472
|
}
|
|
542
473
|
binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
543
474
|
}
|
|
544
|
-
|
|
545
|
-
// Use the result from this iteration as the maximum for the next.
|
|
546
475
|
binMax = binMid;
|
|
547
476
|
let start = Math.max(1, expectedLocation - binMid + 1);
|
|
548
477
|
let finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
|
|
549
|
-
|
|
550
|
-
// Initialize the bit array
|
|
551
478
|
let bitArr = Array(finish + 2);
|
|
552
479
|
bitArr[finish + 1] = (1 << i) - 1;
|
|
553
480
|
for (let j = finish; j >= start; j -= 1) {
|
|
554
481
|
let currentLocation = j - 1;
|
|
555
482
|
let charMatch = patternAlphabet[text.charAt(currentLocation)];
|
|
556
483
|
if (computeMatches) {
|
|
557
|
-
// Speed up: quick bool to int conversion (i.e, `charMatch ? 1 : 0`)
|
|
558
484
|
matchMask[currentLocation] = +!!charMatch;
|
|
559
485
|
}
|
|
560
|
-
|
|
561
|
-
// First pass: exact match
|
|
562
486
|
bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
|
|
563
|
-
|
|
564
|
-
// Subsequent passes: fuzzy match
|
|
565
487
|
if (i) {
|
|
566
488
|
bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
|
|
567
489
|
}
|
|
@@ -573,26 +495,16 @@ function search(text, pattern, patternAlphabet, {
|
|
|
573
495
|
distance,
|
|
574
496
|
ignoreLocation
|
|
575
497
|
});
|
|
576
|
-
|
|
577
|
-
// This match will almost certainly be better than any existing match.
|
|
578
|
-
// But check anyway.
|
|
579
498
|
if (finalScore <= currentThreshold) {
|
|
580
|
-
// Indeed it is
|
|
581
499
|
currentThreshold = finalScore;
|
|
582
500
|
bestLocation = currentLocation;
|
|
583
|
-
|
|
584
|
-
// Already passed `loc`, downhill from here on in.
|
|
585
501
|
if (bestLocation <= expectedLocation) {
|
|
586
502
|
break;
|
|
587
503
|
}
|
|
588
|
-
|
|
589
|
-
// When passing `bestLocation`, don't exceed our current distance from `expectedLocation`.
|
|
590
504
|
start = Math.max(1, 2 * expectedLocation - bestLocation);
|
|
591
505
|
}
|
|
592
506
|
}
|
|
593
507
|
}
|
|
594
|
-
|
|
595
|
-
// No hope for a (better) match at greater error levels.
|
|
596
508
|
const score = computeScore$1(pattern, {
|
|
597
509
|
errors: i + 1,
|
|
598
510
|
currentLocation: expectedLocation,
|
|
@@ -608,7 +520,7 @@ function search(text, pattern, patternAlphabet, {
|
|
|
608
520
|
const result = {
|
|
609
521
|
isMatch: bestLocation >= 0,
|
|
610
522
|
// Count exact matches (those with a score of 0) to be "almost" exact
|
|
611
|
-
score: Math.max(
|
|
523
|
+
score: Math.max(1e-3, finalScore)
|
|
612
524
|
};
|
|
613
525
|
if (computeMatches) {
|
|
614
526
|
const indices = convertMaskToIndices(matchMask, minMatchCharLength);
|
|
@@ -654,10 +566,10 @@ class BitapSearch {
|
|
|
654
566
|
if (!this.pattern.length) {
|
|
655
567
|
return;
|
|
656
568
|
}
|
|
657
|
-
const addChunk = (
|
|
569
|
+
const addChunk = (pattern2, startIndex) => {
|
|
658
570
|
this.chunks.push({
|
|
659
|
-
pattern,
|
|
660
|
-
alphabet: createPatternAlphabet(
|
|
571
|
+
pattern: pattern2,
|
|
572
|
+
alphabet: createPatternAlphabet(pattern2),
|
|
661
573
|
startIndex
|
|
662
574
|
});
|
|
663
575
|
};
|
|
@@ -679,27 +591,20 @@ class BitapSearch {
|
|
|
679
591
|
}
|
|
680
592
|
}
|
|
681
593
|
searchIn(text) {
|
|
682
|
-
const {
|
|
683
|
-
isCaseSensitive,
|
|
684
|
-
includeMatches
|
|
685
|
-
} = this.options;
|
|
594
|
+
const { isCaseSensitive, includeMatches } = this.options;
|
|
686
595
|
if (!isCaseSensitive) {
|
|
687
596
|
text = text.toLowerCase();
|
|
688
597
|
}
|
|
689
|
-
|
|
690
|
-
// Exact match
|
|
691
598
|
if (this.pattern === text) {
|
|
692
|
-
let
|
|
599
|
+
let result2 = {
|
|
693
600
|
isMatch: true,
|
|
694
601
|
score: 0
|
|
695
602
|
};
|
|
696
603
|
if (includeMatches) {
|
|
697
|
-
|
|
604
|
+
result2.indices = [[0, text.length - 1]];
|
|
698
605
|
}
|
|
699
|
-
return
|
|
606
|
+
return result2;
|
|
700
607
|
}
|
|
701
|
-
|
|
702
|
-
// Otherwise, use Bitap algorithm
|
|
703
608
|
const {
|
|
704
609
|
location,
|
|
705
610
|
distance,
|
|
@@ -711,16 +616,8 @@ class BitapSearch {
|
|
|
711
616
|
let allIndices = [];
|
|
712
617
|
let totalScore = 0;
|
|
713
618
|
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, {
|
|
619
|
+
this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
|
|
620
|
+
const { isMatch, score, indices } = search(text, pattern, alphabet, {
|
|
724
621
|
location: location + startIndex,
|
|
725
622
|
distance,
|
|
726
623
|
threshold,
|
|
@@ -757,21 +654,19 @@ class BaseMatch {
|
|
|
757
654
|
static isSingleMatch(pattern) {
|
|
758
655
|
return getMatch(pattern, this.singleRegex);
|
|
759
656
|
}
|
|
760
|
-
search(
|
|
657
|
+
search() {
|
|
658
|
+
}
|
|
761
659
|
}
|
|
762
660
|
function getMatch(pattern, exp) {
|
|
763
661
|
const matches = pattern.match(exp);
|
|
764
662
|
return matches ? matches[1] : null;
|
|
765
663
|
}
|
|
766
|
-
|
|
767
|
-
// Token: 'file
|
|
768
|
-
|
|
769
664
|
class ExactMatch extends BaseMatch {
|
|
770
665
|
constructor(pattern) {
|
|
771
666
|
super(pattern);
|
|
772
667
|
}
|
|
773
668
|
static get type() {
|
|
774
|
-
return
|
|
669
|
+
return "exact";
|
|
775
670
|
}
|
|
776
671
|
static get multiRegex() {
|
|
777
672
|
return /^="(.*)"$/;
|
|
@@ -788,15 +683,12 @@ class ExactMatch extends BaseMatch {
|
|
|
788
683
|
};
|
|
789
684
|
}
|
|
790
685
|
}
|
|
791
|
-
|
|
792
|
-
// Token: !fire
|
|
793
|
-
|
|
794
686
|
class InverseExactMatch extends BaseMatch {
|
|
795
687
|
constructor(pattern) {
|
|
796
688
|
super(pattern);
|
|
797
689
|
}
|
|
798
690
|
static get type() {
|
|
799
|
-
return
|
|
691
|
+
return "inverse-exact";
|
|
800
692
|
}
|
|
801
693
|
static get multiRegex() {
|
|
802
694
|
return /^!"(.*)"$/;
|
|
@@ -814,15 +706,12 @@ class InverseExactMatch extends BaseMatch {
|
|
|
814
706
|
};
|
|
815
707
|
}
|
|
816
708
|
}
|
|
817
|
-
|
|
818
|
-
// Token: ^file
|
|
819
|
-
|
|
820
709
|
class PrefixExactMatch extends BaseMatch {
|
|
821
710
|
constructor(pattern) {
|
|
822
711
|
super(pattern);
|
|
823
712
|
}
|
|
824
713
|
static get type() {
|
|
825
|
-
return
|
|
714
|
+
return "prefix-exact";
|
|
826
715
|
}
|
|
827
716
|
static get multiRegex() {
|
|
828
717
|
return /^\^"(.*)"$/;
|
|
@@ -839,15 +728,12 @@ class PrefixExactMatch extends BaseMatch {
|
|
|
839
728
|
};
|
|
840
729
|
}
|
|
841
730
|
}
|
|
842
|
-
|
|
843
|
-
// Token: !^fire
|
|
844
|
-
|
|
845
731
|
class InversePrefixExactMatch extends BaseMatch {
|
|
846
732
|
constructor(pattern) {
|
|
847
733
|
super(pattern);
|
|
848
734
|
}
|
|
849
735
|
static get type() {
|
|
850
|
-
return
|
|
736
|
+
return "inverse-prefix-exact";
|
|
851
737
|
}
|
|
852
738
|
static get multiRegex() {
|
|
853
739
|
return /^!\^"(.*)"$/;
|
|
@@ -864,15 +750,12 @@ class InversePrefixExactMatch extends BaseMatch {
|
|
|
864
750
|
};
|
|
865
751
|
}
|
|
866
752
|
}
|
|
867
|
-
|
|
868
|
-
// Token: .file$
|
|
869
|
-
|
|
870
753
|
class SuffixExactMatch extends BaseMatch {
|
|
871
754
|
constructor(pattern) {
|
|
872
755
|
super(pattern);
|
|
873
756
|
}
|
|
874
757
|
static get type() {
|
|
875
|
-
return
|
|
758
|
+
return "suffix-exact";
|
|
876
759
|
}
|
|
877
760
|
static get multiRegex() {
|
|
878
761
|
return /^"(.*)"\$$/;
|
|
@@ -889,15 +772,12 @@ class SuffixExactMatch extends BaseMatch {
|
|
|
889
772
|
};
|
|
890
773
|
}
|
|
891
774
|
}
|
|
892
|
-
|
|
893
|
-
// Token: !.file$
|
|
894
|
-
|
|
895
775
|
class InverseSuffixExactMatch extends BaseMatch {
|
|
896
776
|
constructor(pattern) {
|
|
897
777
|
super(pattern);
|
|
898
778
|
}
|
|
899
779
|
static get type() {
|
|
900
|
-
return
|
|
780
|
+
return "inverse-suffix-exact";
|
|
901
781
|
}
|
|
902
782
|
static get multiRegex() {
|
|
903
783
|
return /^!"(.*)"\$$/;
|
|
@@ -938,7 +818,7 @@ class FuzzyMatch extends BaseMatch {
|
|
|
938
818
|
});
|
|
939
819
|
}
|
|
940
820
|
static get type() {
|
|
941
|
-
return
|
|
821
|
+
return "fuzzy";
|
|
942
822
|
}
|
|
943
823
|
static get multiRegex() {
|
|
944
824
|
return /^"(.*)"$/;
|
|
@@ -950,15 +830,12 @@ class FuzzyMatch extends BaseMatch {
|
|
|
950
830
|
return this._bitapSearch.searchIn(text);
|
|
951
831
|
}
|
|
952
832
|
}
|
|
953
|
-
|
|
954
|
-
// Token: 'file
|
|
955
|
-
|
|
956
833
|
class IncludeMatch extends BaseMatch {
|
|
957
834
|
constructor(pattern) {
|
|
958
835
|
super(pattern);
|
|
959
836
|
}
|
|
960
837
|
static get type() {
|
|
961
|
-
return
|
|
838
|
+
return "include";
|
|
962
839
|
}
|
|
963
840
|
static get multiRegex() {
|
|
964
841
|
return /^'"(.*)"$/;
|
|
@@ -971,8 +848,6 @@ class IncludeMatch extends BaseMatch {
|
|
|
971
848
|
let index;
|
|
972
849
|
const indices = [];
|
|
973
850
|
const patternLen = this.pattern.length;
|
|
974
|
-
|
|
975
|
-
// Get all exact matches
|
|
976
851
|
while ((index = text.indexOf(this.pattern, location)) > -1) {
|
|
977
852
|
location = index + patternLen;
|
|
978
853
|
indices.push([index, location - 1]);
|
|
@@ -985,26 +860,25 @@ class IncludeMatch extends BaseMatch {
|
|
|
985
860
|
};
|
|
986
861
|
}
|
|
987
862
|
}
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
863
|
+
const searchers = [
|
|
864
|
+
ExactMatch,
|
|
865
|
+
IncludeMatch,
|
|
866
|
+
PrefixExactMatch,
|
|
867
|
+
InversePrefixExactMatch,
|
|
868
|
+
InverseSuffixExactMatch,
|
|
869
|
+
SuffixExactMatch,
|
|
870
|
+
InverseExactMatch,
|
|
871
|
+
FuzzyMatch
|
|
872
|
+
];
|
|
991
873
|
const searchersLen = searchers.length;
|
|
992
|
-
|
|
993
|
-
// Regex to split by spaces, but keep anything in quotes together
|
|
994
874
|
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$"]]
|
|
875
|
+
const OR_TOKEN = "|";
|
|
1000
876
|
function parseQuery(pattern, options = {}) {
|
|
1001
|
-
return pattern.split(OR_TOKEN).map(item => {
|
|
1002
|
-
let query = item.trim().split(SPACE_RE).filter(
|
|
877
|
+
return pattern.split(OR_TOKEN).map((item) => {
|
|
878
|
+
let query = item.trim().split(SPACE_RE).filter((item2) => item2 && !!item2.trim());
|
|
1003
879
|
let results = [];
|
|
1004
880
|
for (let i = 0, len = query.length; i < len; i += 1) {
|
|
1005
881
|
const queryItem = query[i];
|
|
1006
|
-
|
|
1007
|
-
// 1. Handle multiple query match (i.e, once that are quoted, like `"hello world"`)
|
|
1008
882
|
let found = false;
|
|
1009
883
|
let idx = -1;
|
|
1010
884
|
while (!found && ++idx < searchersLen) {
|
|
@@ -1018,8 +892,6 @@ function parseQuery(pattern, options = {}) {
|
|
|
1018
892
|
if (found) {
|
|
1019
893
|
continue;
|
|
1020
894
|
}
|
|
1021
|
-
|
|
1022
|
-
// 2. Handle single query matches (i.e, once that are *not* quoted)
|
|
1023
895
|
idx = -1;
|
|
1024
896
|
while (++idx < searchersLen) {
|
|
1025
897
|
const searcher = searchers[idx];
|
|
@@ -1033,39 +905,7 @@ function parseQuery(pattern, options = {}) {
|
|
|
1033
905
|
return results;
|
|
1034
906
|
});
|
|
1035
907
|
}
|
|
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
|
-
*/
|
|
908
|
+
const MultiMatchSet = /* @__PURE__ */ new Set([FuzzyMatch.type, IncludeMatch.type]);
|
|
1069
909
|
class ExtendedSearch {
|
|
1070
910
|
constructor(pattern, {
|
|
1071
911
|
isCaseSensitive = Config.isCaseSensitive,
|
|
@@ -1102,31 +942,18 @@ class ExtendedSearch {
|
|
|
1102
942
|
score: 1
|
|
1103
943
|
};
|
|
1104
944
|
}
|
|
1105
|
-
const {
|
|
1106
|
-
includeMatches,
|
|
1107
|
-
isCaseSensitive
|
|
1108
|
-
} = this.options;
|
|
945
|
+
const { includeMatches, isCaseSensitive } = this.options;
|
|
1109
946
|
text = isCaseSensitive ? text : text.toLowerCase();
|
|
1110
947
|
let numMatches = 0;
|
|
1111
948
|
let allIndices = [];
|
|
1112
949
|
let totalScore = 0;
|
|
1113
|
-
|
|
1114
|
-
// ORs
|
|
1115
950
|
for (let i = 0, qLen = query.length; i < qLen; i += 1) {
|
|
1116
|
-
const
|
|
1117
|
-
|
|
1118
|
-
// Reset indices
|
|
951
|
+
const searchers2 = query[i];
|
|
1119
952
|
allIndices.length = 0;
|
|
1120
953
|
numMatches = 0;
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
const searcher = searchers[j];
|
|
1125
|
-
const {
|
|
1126
|
-
isMatch,
|
|
1127
|
-
indices,
|
|
1128
|
-
score
|
|
1129
|
-
} = searcher.search(text);
|
|
954
|
+
for (let j = 0, pLen = searchers2.length; j < pLen; j += 1) {
|
|
955
|
+
const searcher = searchers2[j];
|
|
956
|
+
const { isMatch, indices, score } = searcher.search(text);
|
|
1130
957
|
if (isMatch) {
|
|
1131
958
|
numMatches += 1;
|
|
1132
959
|
totalScore += score;
|
|
@@ -1145,8 +972,6 @@ class ExtendedSearch {
|
|
|
1145
972
|
break;
|
|
1146
973
|
}
|
|
1147
974
|
}
|
|
1148
|
-
|
|
1149
|
-
// OR condition, so if TRUE, return
|
|
1150
975
|
if (numMatches) {
|
|
1151
976
|
let result = {
|
|
1152
977
|
isMatch: true,
|
|
@@ -1158,8 +983,6 @@ class ExtendedSearch {
|
|
|
1158
983
|
return result;
|
|
1159
984
|
}
|
|
1160
985
|
}
|
|
1161
|
-
|
|
1162
|
-
// Nothing was matched
|
|
1163
986
|
return {
|
|
1164
987
|
isMatch: false,
|
|
1165
988
|
score: 1
|
|
@@ -1180,36 +1003,31 @@ function createSearcher(pattern, options) {
|
|
|
1180
1003
|
return new BitapSearch(pattern, options);
|
|
1181
1004
|
}
|
|
1182
1005
|
const LogicalOperator = {
|
|
1183
|
-
AND:
|
|
1184
|
-
OR:
|
|
1006
|
+
AND: "$and",
|
|
1007
|
+
OR: "$or"
|
|
1185
1008
|
};
|
|
1186
1009
|
const KeyType = {
|
|
1187
|
-
PATH:
|
|
1188
|
-
PATTERN:
|
|
1010
|
+
PATH: "$path",
|
|
1011
|
+
PATTERN: "$val"
|
|
1189
1012
|
};
|
|
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 => ({
|
|
1013
|
+
const isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
|
|
1014
|
+
const isPath = (query) => !!query[KeyType.PATH];
|
|
1015
|
+
const isLeaf = (query) => !isArray(query) && isObject(query) && !isExpression(query);
|
|
1016
|
+
const convertToExplicit = (query) => ({
|
|
1017
|
+
[LogicalOperator.AND]: Object.keys(query).map((key) => ({
|
|
1195
1018
|
[key]: query[key]
|
|
1196
1019
|
}))
|
|
1197
1020
|
});
|
|
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));
|
|
1021
|
+
function parse(query, options, { auto = true } = {}) {
|
|
1022
|
+
const next = (query2) => {
|
|
1023
|
+
let keys = Object.keys(query2);
|
|
1024
|
+
const isQueryPath = isPath(query2);
|
|
1025
|
+
if (!isQueryPath && keys.length > 1 && !isExpression(query2)) {
|
|
1026
|
+
return next(convertToExplicit(query2));
|
|
1209
1027
|
}
|
|
1210
|
-
if (isLeaf(
|
|
1211
|
-
const key = isQueryPath ?
|
|
1212
|
-
const pattern = isQueryPath ?
|
|
1028
|
+
if (isLeaf(query2)) {
|
|
1029
|
+
const key = isQueryPath ? query2[KeyType.PATH] : keys[0];
|
|
1030
|
+
const pattern = isQueryPath ? query2[KeyType.PATTERN] : query2[key];
|
|
1213
1031
|
if (!isString(pattern)) {
|
|
1214
1032
|
throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
|
|
1215
1033
|
}
|
|
@@ -1226,10 +1044,10 @@ function parse(query, options, {
|
|
|
1226
1044
|
children: [],
|
|
1227
1045
|
operator: keys[0]
|
|
1228
1046
|
};
|
|
1229
|
-
keys.forEach(key => {
|
|
1230
|
-
const value =
|
|
1047
|
+
keys.forEach((key) => {
|
|
1048
|
+
const value = query2[key];
|
|
1231
1049
|
if (isArray(value)) {
|
|
1232
|
-
value.forEach(item => {
|
|
1050
|
+
value.forEach((item) => {
|
|
1233
1051
|
node.children.push(next(item));
|
|
1234
1052
|
});
|
|
1235
1053
|
}
|
|
@@ -1241,20 +1059,15 @@ function parse(query, options, {
|
|
|
1241
1059
|
}
|
|
1242
1060
|
return next(query);
|
|
1243
1061
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
function computeScore(results, {
|
|
1247
|
-
ignoreFieldNorm = Config.ignoreFieldNorm
|
|
1248
|
-
}) {
|
|
1249
|
-
results.forEach(result => {
|
|
1062
|
+
function computeScore(results, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
|
|
1063
|
+
results.forEach((result) => {
|
|
1250
1064
|
let totalScore = 1;
|
|
1251
|
-
result.matches.forEach(({
|
|
1252
|
-
key,
|
|
1253
|
-
norm,
|
|
1254
|
-
score
|
|
1255
|
-
}) => {
|
|
1065
|
+
result.matches.forEach(({ key, norm: norm2, score }) => {
|
|
1256
1066
|
const weight = key ? key.weight : null;
|
|
1257
|
-
totalScore *= Math.pow(
|
|
1067
|
+
totalScore *= Math.pow(
|
|
1068
|
+
score === 0 && weight ? Number.EPSILON : score,
|
|
1069
|
+
(weight || 1) * (ignoreFieldNorm ? 1 : norm2)
|
|
1070
|
+
);
|
|
1258
1071
|
});
|
|
1259
1072
|
result.score = totalScore;
|
|
1260
1073
|
});
|
|
@@ -1265,14 +1078,11 @@ function transformMatches(result, data) {
|
|
|
1265
1078
|
if (!isDefined(matches)) {
|
|
1266
1079
|
return;
|
|
1267
1080
|
}
|
|
1268
|
-
matches.forEach(match => {
|
|
1081
|
+
matches.forEach((match) => {
|
|
1269
1082
|
if (!isDefined(match.indices) || !match.indices.length) {
|
|
1270
1083
|
return;
|
|
1271
1084
|
}
|
|
1272
|
-
const {
|
|
1273
|
-
indices,
|
|
1274
|
-
value
|
|
1275
|
-
} = match;
|
|
1085
|
+
const { indices, value } = match;
|
|
1276
1086
|
let obj = {
|
|
1277
1087
|
indices,
|
|
1278
1088
|
value
|
|
@@ -1294,18 +1104,18 @@ function format(results, docs, {
|
|
|
1294
1104
|
includeScore = Config.includeScore
|
|
1295
1105
|
} = {}) {
|
|
1296
1106
|
const transformers = [];
|
|
1297
|
-
if (includeMatches)
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
} = result;
|
|
1107
|
+
if (includeMatches)
|
|
1108
|
+
transformers.push(transformMatches);
|
|
1109
|
+
if (includeScore)
|
|
1110
|
+
transformers.push(transformScore);
|
|
1111
|
+
return results.map((result) => {
|
|
1112
|
+
const { idx } = result;
|
|
1303
1113
|
const data = {
|
|
1304
1114
|
item: docs[idx],
|
|
1305
1115
|
refIndex: idx
|
|
1306
1116
|
};
|
|
1307
1117
|
if (transformers.length) {
|
|
1308
|
-
transformers.forEach(transformer => {
|
|
1118
|
+
transformers.forEach((transformer) => {
|
|
1309
1119
|
transformer(result, data);
|
|
1310
1120
|
});
|
|
1311
1121
|
}
|
|
@@ -1314,11 +1124,8 @@ function format(results, docs, {
|
|
|
1314
1124
|
}
|
|
1315
1125
|
class Fuse {
|
|
1316
1126
|
constructor(docs, options = {}, index) {
|
|
1317
|
-
this.options = {
|
|
1318
|
-
|
|
1319
|
-
...options
|
|
1320
|
-
};
|
|
1321
|
-
if (this.options.useExtendedSearch && !true) {
|
|
1127
|
+
this.options = { ...Config, ...options };
|
|
1128
|
+
if (this.options.useExtendedSearch && false) {
|
|
1322
1129
|
throw new Error(EXTENDED_SEARCH_UNAVAILABLE);
|
|
1323
1130
|
}
|
|
1324
1131
|
this._keyStore = new KeyStore(this.options.keys);
|
|
@@ -1341,7 +1148,7 @@ class Fuse {
|
|
|
1341
1148
|
this._docs.push(doc);
|
|
1342
1149
|
this._myIndex.add(doc);
|
|
1343
1150
|
}
|
|
1344
|
-
remove(predicate = (
|
|
1151
|
+
remove(predicate = () => false) {
|
|
1345
1152
|
const results = [];
|
|
1346
1153
|
for (let i = 0, len = this._docs.length; i < len; i += 1) {
|
|
1347
1154
|
const doc = this._docs[i];
|
|
@@ -1361,9 +1168,7 @@ class Fuse {
|
|
|
1361
1168
|
getIndex() {
|
|
1362
1169
|
return this._myIndex;
|
|
1363
1170
|
}
|
|
1364
|
-
search(query, {
|
|
1365
|
-
limit = -1
|
|
1366
|
-
} = {}) {
|
|
1171
|
+
search(query, { limit = -1 } = {}) {
|
|
1367
1172
|
const {
|
|
1368
1173
|
includeMatches,
|
|
1369
1174
|
includeScore,
|
|
@@ -1372,9 +1177,7 @@ class Fuse {
|
|
|
1372
1177
|
ignoreFieldNorm
|
|
1373
1178
|
} = this.options;
|
|
1374
1179
|
let results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
|
|
1375
|
-
computeScore(results, {
|
|
1376
|
-
ignoreFieldNorm
|
|
1377
|
-
});
|
|
1180
|
+
computeScore(results, { ignoreFieldNorm });
|
|
1378
1181
|
if (shouldSort) {
|
|
1379
1182
|
results.sort(sortFn);
|
|
1380
1183
|
}
|
|
@@ -1388,35 +1191,18 @@ class Fuse {
|
|
|
1388
1191
|
}
|
|
1389
1192
|
_searchStringList(query) {
|
|
1390
1193
|
const searcher = createSearcher(query, this.options);
|
|
1391
|
-
const {
|
|
1392
|
-
records
|
|
1393
|
-
} = this._myIndex;
|
|
1194
|
+
const { records } = this._myIndex;
|
|
1394
1195
|
const results = [];
|
|
1395
|
-
|
|
1396
|
-
// Iterate over every string in the index
|
|
1397
|
-
records.forEach(({
|
|
1398
|
-
v: text,
|
|
1399
|
-
i: idx,
|
|
1400
|
-
n: norm
|
|
1401
|
-
}) => {
|
|
1196
|
+
records.forEach(({ v: text, i: idx, n: norm2 }) => {
|
|
1402
1197
|
if (!isDefined(text)) {
|
|
1403
1198
|
return;
|
|
1404
1199
|
}
|
|
1405
|
-
const {
|
|
1406
|
-
isMatch,
|
|
1407
|
-
score,
|
|
1408
|
-
indices
|
|
1409
|
-
} = searcher.searchIn(text);
|
|
1200
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1410
1201
|
if (isMatch) {
|
|
1411
1202
|
results.push({
|
|
1412
1203
|
item: text,
|
|
1413
1204
|
idx,
|
|
1414
|
-
matches: [{
|
|
1415
|
-
score,
|
|
1416
|
-
value: text,
|
|
1417
|
-
norm,
|
|
1418
|
-
indices
|
|
1419
|
-
}]
|
|
1205
|
+
matches: [{ score, value: text, norm: norm2, indices }]
|
|
1420
1206
|
});
|
|
1421
1207
|
}
|
|
1422
1208
|
});
|
|
@@ -1426,21 +1212,20 @@ class Fuse {
|
|
|
1426
1212
|
const expression = parse(query, this.options);
|
|
1427
1213
|
const evaluate = (node, item, idx) => {
|
|
1428
1214
|
if (!node.children) {
|
|
1429
|
-
const {
|
|
1430
|
-
keyId,
|
|
1431
|
-
searcher
|
|
1432
|
-
} = node;
|
|
1215
|
+
const { keyId, searcher } = node;
|
|
1433
1216
|
const matches = this._findMatches({
|
|
1434
1217
|
key: this._keyStore.get(keyId),
|
|
1435
1218
|
value: this._myIndex.getValueForItemAtKeyId(item, keyId),
|
|
1436
1219
|
searcher
|
|
1437
1220
|
});
|
|
1438
1221
|
if (matches && matches.length) {
|
|
1439
|
-
return [
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1222
|
+
return [
|
|
1223
|
+
{
|
|
1224
|
+
idx,
|
|
1225
|
+
item,
|
|
1226
|
+
matches
|
|
1227
|
+
}
|
|
1228
|
+
];
|
|
1444
1229
|
}
|
|
1445
1230
|
return [];
|
|
1446
1231
|
}
|
|
@@ -1459,25 +1244,15 @@ class Fuse {
|
|
|
1459
1244
|
const records = this._myIndex.records;
|
|
1460
1245
|
const resultMap = {};
|
|
1461
1246
|
const results = [];
|
|
1462
|
-
records.forEach(({
|
|
1463
|
-
$: item,
|
|
1464
|
-
i: idx
|
|
1465
|
-
}) => {
|
|
1247
|
+
records.forEach(({ $: item, i: idx }) => {
|
|
1466
1248
|
if (isDefined(item)) {
|
|
1467
1249
|
let expResults = evaluate(expression, item, idx);
|
|
1468
1250
|
if (expResults.length) {
|
|
1469
|
-
// Dedupe when adding
|
|
1470
1251
|
if (!resultMap[idx]) {
|
|
1471
|
-
resultMap[idx] = {
|
|
1472
|
-
idx,
|
|
1473
|
-
item,
|
|
1474
|
-
matches: []
|
|
1475
|
-
};
|
|
1252
|
+
resultMap[idx] = { idx, item, matches: [] };
|
|
1476
1253
|
results.push(resultMap[idx]);
|
|
1477
1254
|
}
|
|
1478
|
-
expResults.forEach(({
|
|
1479
|
-
matches
|
|
1480
|
-
}) => {
|
|
1255
|
+
expResults.forEach(({ matches }) => {
|
|
1481
1256
|
resultMap[idx].matches.push(...matches);
|
|
1482
1257
|
});
|
|
1483
1258
|
}
|
|
@@ -1487,29 +1262,21 @@ class Fuse {
|
|
|
1487
1262
|
}
|
|
1488
1263
|
_searchObjectList(query) {
|
|
1489
1264
|
const searcher = createSearcher(query, this.options);
|
|
1490
|
-
const {
|
|
1491
|
-
keys,
|
|
1492
|
-
records
|
|
1493
|
-
} = this._myIndex;
|
|
1265
|
+
const { keys, records } = this._myIndex;
|
|
1494
1266
|
const results = [];
|
|
1495
|
-
|
|
1496
|
-
// List is Array<Object>
|
|
1497
|
-
records.forEach(({
|
|
1498
|
-
$: item,
|
|
1499
|
-
i: idx
|
|
1500
|
-
}) => {
|
|
1267
|
+
records.forEach(({ $: item, i: idx }) => {
|
|
1501
1268
|
if (!isDefined(item)) {
|
|
1502
1269
|
return;
|
|
1503
1270
|
}
|
|
1504
1271
|
let matches = [];
|
|
1505
|
-
|
|
1506
|
-
// Iterate over every key (i.e, path), and fetch the value at that key
|
|
1507
1272
|
keys.forEach((key, keyIndex) => {
|
|
1508
|
-
matches.push(
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1273
|
+
matches.push(
|
|
1274
|
+
...this._findMatches({
|
|
1275
|
+
key,
|
|
1276
|
+
value: item[keyIndex],
|
|
1277
|
+
searcher
|
|
1278
|
+
})
|
|
1279
|
+
);
|
|
1513
1280
|
});
|
|
1514
1281
|
if (matches.length) {
|
|
1515
1282
|
results.push({
|
|
@@ -1521,64 +1288,39 @@ class Fuse {
|
|
|
1521
1288
|
});
|
|
1522
1289
|
return results;
|
|
1523
1290
|
}
|
|
1524
|
-
_findMatches({
|
|
1525
|
-
key,
|
|
1526
|
-
value,
|
|
1527
|
-
searcher
|
|
1528
|
-
}) {
|
|
1291
|
+
_findMatches({ key, value, searcher }) {
|
|
1529
1292
|
if (!isDefined(value)) {
|
|
1530
1293
|
return [];
|
|
1531
1294
|
}
|
|
1532
1295
|
let matches = [];
|
|
1533
1296
|
if (isArray(value)) {
|
|
1534
|
-
value.forEach(({
|
|
1535
|
-
v: text,
|
|
1536
|
-
i: idx,
|
|
1537
|
-
n: norm
|
|
1538
|
-
}) => {
|
|
1297
|
+
value.forEach(({ v: text, i: idx, n: norm2 }) => {
|
|
1539
1298
|
if (!isDefined(text)) {
|
|
1540
1299
|
return;
|
|
1541
1300
|
}
|
|
1542
|
-
const {
|
|
1543
|
-
isMatch,
|
|
1544
|
-
score,
|
|
1545
|
-
indices
|
|
1546
|
-
} = searcher.searchIn(text);
|
|
1301
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1547
1302
|
if (isMatch) {
|
|
1548
1303
|
matches.push({
|
|
1549
1304
|
score,
|
|
1550
1305
|
key,
|
|
1551
1306
|
value: text,
|
|
1552
1307
|
idx,
|
|
1553
|
-
norm,
|
|
1308
|
+
norm: norm2,
|
|
1554
1309
|
indices
|
|
1555
1310
|
});
|
|
1556
1311
|
}
|
|
1557
1312
|
});
|
|
1558
1313
|
} else {
|
|
1559
|
-
const {
|
|
1560
|
-
|
|
1561
|
-
n: norm
|
|
1562
|
-
} = value;
|
|
1563
|
-
const {
|
|
1564
|
-
isMatch,
|
|
1565
|
-
score,
|
|
1566
|
-
indices
|
|
1567
|
-
} = searcher.searchIn(text);
|
|
1314
|
+
const { v: text, n: norm2 } = value;
|
|
1315
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1568
1316
|
if (isMatch) {
|
|
1569
|
-
matches.push({
|
|
1570
|
-
score,
|
|
1571
|
-
key,
|
|
1572
|
-
value: text,
|
|
1573
|
-
norm,
|
|
1574
|
-
indices
|
|
1575
|
-
});
|
|
1317
|
+
matches.push({ score, key, value: text, norm: norm2, indices });
|
|
1576
1318
|
}
|
|
1577
1319
|
}
|
|
1578
1320
|
return matches;
|
|
1579
1321
|
}
|
|
1580
1322
|
}
|
|
1581
|
-
Fuse.version =
|
|
1323
|
+
Fuse.version = "6.6.2";
|
|
1582
1324
|
Fuse.createIndex = createIndex;
|
|
1583
1325
|
Fuse.parseIndex = parseIndex;
|
|
1584
1326
|
Fuse.config = Config;
|
|
@@ -1588,6 +1330,309 @@ Fuse.config = Config;
|
|
|
1588
1330
|
{
|
|
1589
1331
|
register(ExtendedSearch);
|
|
1590
1332
|
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1333
|
+
function uniqID() {
|
|
1334
|
+
return "_" + (Math.random() * Math.pow(36, 20)).toString(36).slice(0, 10);
|
|
1335
|
+
}
|
|
1336
|
+
function stringToDom(html) {
|
|
1337
|
+
const template = document.createElement("template");
|
|
1338
|
+
template.innerHTML = html;
|
|
1339
|
+
return template.content;
|
|
1340
|
+
}
|
|
1341
|
+
async function evalTemplateString(str, variables = {}) {
|
|
1342
|
+
const keys = Object.keys(variables);
|
|
1343
|
+
const values = keys.map((key) => variables[key]);
|
|
1344
|
+
try {
|
|
1345
|
+
const AsyncFunction = Object.getPrototypeOf(async function() {
|
|
1346
|
+
}).constructor;
|
|
1347
|
+
const func = AsyncFunction.call(null, ...keys, "return `" + str + "`");
|
|
1348
|
+
return await func(...values);
|
|
1349
|
+
} catch (e) {
|
|
1350
|
+
console.log(e);
|
|
1351
|
+
throw new SyntaxError("`" + str + "`");
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
function importCSS(...stylesheets) {
|
|
1355
|
+
const linksElements = [];
|
|
1356
|
+
for (let url of stylesheets) {
|
|
1357
|
+
url = relativeSource(url);
|
|
1358
|
+
let link = Array.from(document.head.querySelectorAll("link")).find(
|
|
1359
|
+
(link2) => link2.href === url
|
|
1360
|
+
);
|
|
1361
|
+
if (link)
|
|
1362
|
+
return link;
|
|
1363
|
+
link = document.createElement("link");
|
|
1364
|
+
link.rel = "stylesheet";
|
|
1365
|
+
link.href = url;
|
|
1366
|
+
document.head.appendChild(link);
|
|
1367
|
+
linksElements.push(link);
|
|
1368
|
+
}
|
|
1369
|
+
return linksElements;
|
|
1370
|
+
}
|
|
1371
|
+
function importJS(...plugins) {
|
|
1372
|
+
return plugins.map((url) => {
|
|
1373
|
+
url = new URL(url, document.baseURI).href;
|
|
1374
|
+
let script = Array.from(document.querySelectorAll("script")).find(
|
|
1375
|
+
(script2) => script2.src === url
|
|
1376
|
+
);
|
|
1377
|
+
if (script)
|
|
1378
|
+
return script;
|
|
1379
|
+
script = document.createElement("script");
|
|
1380
|
+
script.src = url;
|
|
1381
|
+
document.head.appendChild(script);
|
|
1382
|
+
return script;
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
function relativeSource(source) {
|
|
1386
|
+
if (!source.match(/^\..?\//))
|
|
1387
|
+
return new URL(source, document.baseURI).href;
|
|
1388
|
+
const e = new Error();
|
|
1389
|
+
if (!e.stack)
|
|
1390
|
+
return source;
|
|
1391
|
+
const f2 = e.stack.split("\n").filter((l) => l.includes(":"))[2];
|
|
1392
|
+
let line = f2.match(/[a-z]+:.*$/);
|
|
1393
|
+
if (!line)
|
|
1394
|
+
return source;
|
|
1395
|
+
const calledFile = line[0].replace(/(\:[0-9]+){2}\)?$/, "");
|
|
1396
|
+
source = new URL(source, calledFile).href;
|
|
1397
|
+
return source;
|
|
1398
|
+
}
|
|
1399
|
+
function loadScript(source) {
|
|
1400
|
+
source = relativeSource(source);
|
|
1401
|
+
return new Promise((resolve) => {
|
|
1402
|
+
var script = document.createElement("script");
|
|
1403
|
+
var head = document.querySelector("head");
|
|
1404
|
+
script.async = true;
|
|
1405
|
+
script.onload = () => setTimeout(resolve, 0);
|
|
1406
|
+
script.src = source;
|
|
1407
|
+
if (head)
|
|
1408
|
+
head.appendChild(script);
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
function domIsReady() {
|
|
1412
|
+
return new Promise(function(resolve) {
|
|
1413
|
+
if (document.readyState === "complete") {
|
|
1414
|
+
resolve();
|
|
1415
|
+
} else {
|
|
1416
|
+
document.addEventListener("DOMContentLoaded", () => resolve());
|
|
1417
|
+
}
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
function setDeepProperty(obj, path, value) {
|
|
1421
|
+
const name = path.shift();
|
|
1422
|
+
if (name) {
|
|
1423
|
+
if (!(name in obj))
|
|
1424
|
+
obj[name] = {};
|
|
1425
|
+
if (path.length)
|
|
1426
|
+
setDeepProperty(obj[name], path, value);
|
|
1427
|
+
else
|
|
1428
|
+
obj[name] = value;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
function parseFieldsString(fields) {
|
|
1432
|
+
let fieldsArray;
|
|
1433
|
+
while (fields.indexOf("(") > 0) {
|
|
1434
|
+
let firstBracket = fields.indexOf("(");
|
|
1435
|
+
let noset = fields.substring(firstBracket, findClosingBracketMatchIndex(fields, firstBracket) + 1);
|
|
1436
|
+
fields = fields.replace(noset, "");
|
|
1437
|
+
}
|
|
1438
|
+
const re = /((^\s*|,)\s*)(("(\\"|[^"])*")|('(\\'|[^'])*')|[^,]*)/gm;
|
|
1439
|
+
fieldsArray = fields.match(re) || [];
|
|
1440
|
+
if (!fieldsArray)
|
|
1441
|
+
return [];
|
|
1442
|
+
return fieldsArray.map((a) => a.replace(/^[\s,]+/, ""));
|
|
1443
|
+
}
|
|
1444
|
+
function findClosingBracketMatchIndex(str, pos) {
|
|
1445
|
+
if (str[pos] != "(")
|
|
1446
|
+
throw new Error("No '(' at index " + pos);
|
|
1447
|
+
let depth = 1;
|
|
1448
|
+
for (let i = pos + 1; i < str.length; i++) {
|
|
1449
|
+
switch (str[i]) {
|
|
1450
|
+
case "(":
|
|
1451
|
+
depth++;
|
|
1452
|
+
break;
|
|
1453
|
+
case ")":
|
|
1454
|
+
if (--depth == 0)
|
|
1455
|
+
return i;
|
|
1456
|
+
break;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
return -1;
|
|
1460
|
+
}
|
|
1461
|
+
function defineComponent(tagName, componentClass) {
|
|
1462
|
+
if (!customElements.get(tagName)) {
|
|
1463
|
+
customElements.define(tagName, componentClass);
|
|
1464
|
+
} else {
|
|
1465
|
+
console.warn(`Warning: the component "${tagName}" has already been loaded in another version of sib-core.`);
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
function fuzzyCompare(subject, search2) {
|
|
1469
|
+
const fuse = new Fuse([subject], {
|
|
1470
|
+
shouldSort: false,
|
|
1471
|
+
threshold: 0.37
|
|
1472
|
+
}).search(search2);
|
|
1473
|
+
return fuse.length > 0;
|
|
1474
|
+
}
|
|
1475
|
+
const compare = {
|
|
1476
|
+
string(subject, query) {
|
|
1477
|
+
if (query === "")
|
|
1478
|
+
return true;
|
|
1479
|
+
if (subject.toString().toLowerCase().includes(String(query).toLowerCase()))
|
|
1480
|
+
return true;
|
|
1481
|
+
return fuzzyCompare(subject, query);
|
|
1482
|
+
},
|
|
1483
|
+
boolean(subject, query) {
|
|
1484
|
+
if (!query)
|
|
1485
|
+
return true;
|
|
1486
|
+
return subject;
|
|
1487
|
+
},
|
|
1488
|
+
number(subject, query) {
|
|
1489
|
+
return subject === query;
|
|
1490
|
+
},
|
|
1491
|
+
list(subject, list) {
|
|
1492
|
+
return list.includes(subject);
|
|
1493
|
+
},
|
|
1494
|
+
range(subject, range) {
|
|
1495
|
+
return (range[0] == null || range[0] === "" || subject >= range[0]) && (range[1] == null || range[1] === "" || subject <= range[1]);
|
|
1496
|
+
},
|
|
1497
|
+
resource(subject, query) {
|
|
1498
|
+
if (query === "")
|
|
1499
|
+
return true;
|
|
1500
|
+
if (!query["@id"])
|
|
1501
|
+
return false;
|
|
1502
|
+
const ret = subject["@id"] === query["@id"];
|
|
1503
|
+
return ret;
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
function transformArrayToContainer(resource) {
|
|
1507
|
+
const newValue = { ...resource };
|
|
1508
|
+
for (let predicate of Object.keys(newValue)) {
|
|
1509
|
+
const predicateValue = newValue[predicate];
|
|
1510
|
+
if (!predicateValue || typeof predicateValue !== "object")
|
|
1511
|
+
continue;
|
|
1512
|
+
if (["permissions", "@context"].includes(predicate))
|
|
1513
|
+
continue;
|
|
1514
|
+
if (!Array.isArray(predicateValue) && predicateValue["@id"]) {
|
|
1515
|
+
newValue[predicate] = transformArrayToContainer(resource[predicate]);
|
|
1516
|
+
}
|
|
1517
|
+
if (Array.isArray(predicateValue)) {
|
|
1518
|
+
newValue[predicate] = { "ldp:contains": [...predicateValue] };
|
|
1519
|
+
newValue[predicate]["ldp:contains"].forEach((childPredicate, index) => {
|
|
1520
|
+
newValue[predicate]["ldp:contains"][index] = transformArrayToContainer(childPredicate);
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
return newValue;
|
|
1525
|
+
}
|
|
1526
|
+
class AsyncIterableBuilder {
|
|
1527
|
+
constructor() {
|
|
1528
|
+
__privateAdd(this, _createIterable);
|
|
1529
|
+
__privateAdd(this, _next);
|
|
1530
|
+
__privateAdd(this, _nextPromise);
|
|
1531
|
+
__privateAdd(this, _values, void 0);
|
|
1532
|
+
__privateAdd(this, _resolve, void 0);
|
|
1533
|
+
__privateSet(this, _values, []);
|
|
1534
|
+
__privateMethod(this, _nextPromise, nextPromise_fn).call(this);
|
|
1535
|
+
this.iterable = __privateMethod(this, _createIterable, createIterable_fn).call(this);
|
|
1536
|
+
this.next = __privateMethod(this, _next, next_fn).bind(this);
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
_values = new WeakMap();
|
|
1540
|
+
_resolve = new WeakMap();
|
|
1541
|
+
_createIterable = new WeakSet();
|
|
1542
|
+
createIterable_fn = async function* () {
|
|
1543
|
+
for (let index = 0; ; index++) {
|
|
1544
|
+
const { value, done } = await __privateGet(this, _values)[index];
|
|
1545
|
+
delete __privateGet(this, _values)[index];
|
|
1546
|
+
yield value;
|
|
1547
|
+
if (done)
|
|
1548
|
+
return;
|
|
1549
|
+
}
|
|
1550
|
+
};
|
|
1551
|
+
_next = new WeakSet();
|
|
1552
|
+
next_fn = function(value, done = false) {
|
|
1553
|
+
__privateGet(this, _resolve).call(this, { value, done });
|
|
1554
|
+
__privateMethod(this, _nextPromise, nextPromise_fn).call(this);
|
|
1555
|
+
};
|
|
1556
|
+
_nextPromise = new WeakSet();
|
|
1557
|
+
nextPromise_fn = function() {
|
|
1558
|
+
__privateGet(this, _values).push(new Promise((resolve) => __privateSet(this, _resolve, resolve)));
|
|
1559
|
+
};
|
|
1560
|
+
const asyncQuerySelector = (selector, parent = document) => new Promise((resolve) => {
|
|
1561
|
+
const element = parent.querySelector(selector);
|
|
1562
|
+
if (element)
|
|
1563
|
+
return resolve(element);
|
|
1564
|
+
const observer = new MutationObserver(() => {
|
|
1565
|
+
const element2 = parent.querySelector(selector);
|
|
1566
|
+
if (!element2)
|
|
1567
|
+
return;
|
|
1568
|
+
observer.disconnect();
|
|
1569
|
+
return resolve(element2);
|
|
1570
|
+
});
|
|
1571
|
+
observer.observe(parent, {
|
|
1572
|
+
subtree: true,
|
|
1573
|
+
childList: true,
|
|
1574
|
+
attributes: true
|
|
1575
|
+
});
|
|
1576
|
+
});
|
|
1577
|
+
const asyncQuerySelectorAll = (selector, parent = document) => {
|
|
1578
|
+
const delivered = /* @__PURE__ */ new WeakSet();
|
|
1579
|
+
const { next, iterable } = new AsyncIterableBuilder();
|
|
1580
|
+
function checkNewElement() {
|
|
1581
|
+
for (const element of parent.querySelectorAll(selector)) {
|
|
1582
|
+
if (delivered.has(element))
|
|
1583
|
+
continue;
|
|
1584
|
+
delivered.add(element);
|
|
1585
|
+
next(element);
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
checkNewElement();
|
|
1589
|
+
const observer = new MutationObserver(checkNewElement);
|
|
1590
|
+
observer.observe(parent, {
|
|
1591
|
+
subtree: true,
|
|
1592
|
+
childList: true,
|
|
1593
|
+
attributes: true
|
|
1594
|
+
});
|
|
1595
|
+
return iterable;
|
|
1596
|
+
};
|
|
1597
|
+
const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1598
|
+
__proto__: null,
|
|
1599
|
+
AsyncIterableBuilder,
|
|
1600
|
+
asyncQuerySelector,
|
|
1601
|
+
asyncQuerySelectorAll,
|
|
1602
|
+
compare,
|
|
1603
|
+
default: AsyncIterableBuilder,
|
|
1604
|
+
defineComponent,
|
|
1605
|
+
domIsReady,
|
|
1606
|
+
evalTemplateString,
|
|
1607
|
+
findClosingBracketMatchIndex,
|
|
1608
|
+
fuzzyCompare,
|
|
1609
|
+
importCSS,
|
|
1610
|
+
importJS,
|
|
1611
|
+
loadScript,
|
|
1612
|
+
parseFieldsString,
|
|
1613
|
+
setDeepProperty,
|
|
1614
|
+
stringToDom,
|
|
1615
|
+
transformArrayToContainer,
|
|
1616
|
+
uniqID
|
|
1617
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
1618
|
+
export {
|
|
1619
|
+
AsyncIterableBuilder as A,
|
|
1620
|
+
findClosingBracketMatchIndex as a,
|
|
1621
|
+
stringToDom as b,
|
|
1622
|
+
compare as c,
|
|
1623
|
+
defineComponent as d,
|
|
1624
|
+
evalTemplateString as e,
|
|
1625
|
+
fuzzyCompare as f,
|
|
1626
|
+
importJS as g,
|
|
1627
|
+
helpers as h,
|
|
1628
|
+
importCSS as i,
|
|
1629
|
+
domIsReady as j,
|
|
1630
|
+
asyncQuerySelector as k,
|
|
1631
|
+
loadScript as l,
|
|
1632
|
+
asyncQuerySelectorAll as m,
|
|
1633
|
+
parseFieldsString as p,
|
|
1634
|
+
setDeepProperty as s,
|
|
1635
|
+
transformArrayToContainer as t,
|
|
1636
|
+
uniqID as u
|
|
1637
|
+
};
|
|
1638
|
+
//# sourceMappingURL=helpers-411e08e4.js.map
|