dsh-querit 1.1.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -46
- package/cordis.patch.yml +6 -0
- package/lib/card.js +264 -240
- package/lib/client.d.ts +105 -6
- package/lib/client.js +198 -41
- package/lib/index.d.ts +70 -59
- package/lib/index.js +150 -123
- package/lib/provider.d.ts +51 -17
- package/lib/provider.js +160 -90
- package/lib/sanitize.d.ts +2 -0
- package/lib/sanitize.js +4 -0
- package/package.json +29 -30
- package/lib/invariant.d.ts +0 -18
- package/lib/invariant.js +0 -20
package/lib/card.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-querit browser bundle — Querit
|
|
2
|
+
* dsh-querit browser bundle — the Querit row's configuration page.
|
|
3
3
|
*
|
|
4
4
|
* Built by scripts/build-client.mjs into lib/card.js (do not edit the
|
|
5
5
|
* generated file). The browser loader wraps this module; the node-side unit
|
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
*
|
|
29
29
|
* This file is the SINGLE SOURCE of truth for the card's field conversions and
|
|
30
30
|
* save planning. The browser bundle inlines these exact definitions (see
|
|
31
|
-
* scripts/build-client.mjs); the node-side unit tests import
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* scripts/build-client.mjs); the node-side unit tests import this file
|
|
32
|
+
* directly. Keep everything here free of DOM, React, and window references so
|
|
33
|
+
* both consumers can run it.
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* A whole-number field. An empty draft clears the field; any other draft that
|
|
38
38
|
* is not a finite number blocks the save.
|
|
39
39
|
* @param {string} field - field name inside the namespace section.
|
|
40
|
-
* @returns {
|
|
40
|
+
* @returns {object} the field's conversion spec: `format(value)` renders a stored value, `parse(text)` reads a draft back.
|
|
41
41
|
*/
|
|
42
42
|
function numberField(field) {
|
|
43
43
|
return {
|
|
@@ -58,7 +58,7 @@ function numberField(field) {
|
|
|
58
58
|
* A free-text field. An empty draft clears the field, so emptying the control
|
|
59
59
|
* and saving is the same gesture as resetting it.
|
|
60
60
|
* @param {string} field - field name inside the namespace section.
|
|
61
|
-
* @returns {
|
|
61
|
+
* @returns {object} the field's conversion spec: `format(value)` renders a stored value, `parse(text)` reads a draft back.
|
|
62
62
|
*/
|
|
63
63
|
function textField(field) {
|
|
64
64
|
return {
|
|
@@ -75,7 +75,7 @@ function textField(field) {
|
|
|
75
75
|
* A comma-separated list field (string[] ↔ "a, b, c"). An empty draft clears
|
|
76
76
|
* the field; duplicates and blank entries are dropped.
|
|
77
77
|
* @param {string} field - field name inside the namespace section.
|
|
78
|
-
* @returns {
|
|
78
|
+
* @returns {object} the field's conversion spec: `format(value)` renders a stored value, `parse(text)` reads a draft back.
|
|
79
79
|
*/
|
|
80
80
|
function listField(field) {
|
|
81
81
|
return {
|
|
@@ -100,7 +100,7 @@ function listField(field) {
|
|
|
100
100
|
/**
|
|
101
101
|
* A boolean toggle field. It always writes a value; there is no "clear".
|
|
102
102
|
* @param {string} field - field name inside the namespace section.
|
|
103
|
-
* @returns {
|
|
103
|
+
* @returns {object} the field's conversion spec: `format(value)` renders a stored value, `parse(text)` reads a draft back.
|
|
104
104
|
*/
|
|
105
105
|
function booleanField(field) {
|
|
106
106
|
return {
|
|
@@ -115,7 +115,7 @@ function booleanField(field) {
|
|
|
115
115
|
* A single-choice field over a fixed set of strings.
|
|
116
116
|
* @param {string} field - field name inside the namespace section.
|
|
117
117
|
* @param {readonly string[]} choices - acceptable values.
|
|
118
|
-
* @returns {
|
|
118
|
+
* @returns {object} the field's conversion spec: `format(value)` renders a stored value, `parse(text)` reads a draft back.
|
|
119
119
|
*/
|
|
120
120
|
function enumField(field, choices) {
|
|
121
121
|
return {
|
|
@@ -135,7 +135,7 @@ function enumField(field, choices) {
|
|
|
135
135
|
* stored in the credentials domain, never in the settings document).
|
|
136
136
|
* @param {string} field - field name this control stages under.
|
|
137
137
|
* @param {(value: string) => Promise<boolean>} write - persist the literal.
|
|
138
|
-
* @returns {
|
|
138
|
+
* @returns {object} the secret's spec: the field name and its `write`.
|
|
139
139
|
*/
|
|
140
140
|
function secretSpec(field, write) {
|
|
141
141
|
return { field, write };
|
|
@@ -152,7 +152,7 @@ function secretSpec(field, write) {
|
|
|
152
152
|
* a field overridden.
|
|
153
153
|
*/
|
|
154
154
|
class QueritFormModel {
|
|
155
|
-
/** @param {
|
|
155
|
+
/** @param {object} scope - the namespace's config form: `getSnapshot()`, `subscribe(listener)`, `set(field, value)`, and `unset(field)`. */
|
|
156
156
|
constructor(scope, specs, secrets = []) {
|
|
157
157
|
this.scope = scope;
|
|
158
158
|
this.specs = new Map(specs.map((spec) => [spec.field, spec]));
|
|
@@ -161,14 +161,20 @@ class QueritFormModel {
|
|
|
161
161
|
this.listeners = new Set();
|
|
162
162
|
this.saving = false;
|
|
163
163
|
this.failed = false;
|
|
164
|
-
scope.subscribe(() => this.publish());
|
|
164
|
+
this.unsubscribe = scope.subscribe(() => this.publish());
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Stop following the scope; a disposed form publishes nothing more. */
|
|
168
|
+
dispose() {
|
|
169
|
+
this.unsubscribe();
|
|
170
|
+
this.listeners.clear();
|
|
165
171
|
}
|
|
166
172
|
|
|
167
173
|
/**
|
|
168
174
|
* Publish a projection of this form rebuilt whenever the scope or a draft
|
|
169
175
|
* changes.
|
|
170
176
|
* @param {() => object} project - build the card's state from the form reads.
|
|
171
|
-
* @returns {
|
|
177
|
+
* @returns {object} the store the component reads: `getSnapshot()`, `subscribe(listener)`, and `set(next)`.
|
|
172
178
|
*/
|
|
173
179
|
bind(project) {
|
|
174
180
|
const store = makeStore(project());
|
|
@@ -337,29 +343,23 @@ function makeStore(initial) {
|
|
|
337
343
|
}
|
|
338
344
|
|
|
339
345
|
var NS = 'dsh-querit';
|
|
346
|
+
/** The plugin entry id: its config form is what this page edits. */
|
|
340
347
|
var NAMESPACE = 'web-search-querit';
|
|
348
|
+
/** `plugins.row.config` key: `<package name>#<row id>`, both as the bundle patch declares them. */
|
|
349
|
+
var ROW_CONFIG_KEY = NS + '#' + NAMESPACE;
|
|
341
350
|
var DEFAULT_API_KEY_REF = 'QUERIT_API_KEY';
|
|
342
351
|
var FETCH_FORMATS = ['markdown', 'text', 'html'];
|
|
352
|
+
var RANK_VALUES = ['relevance', 'freshness'];
|
|
353
|
+
var VERTICAL_VALUES = ['code', 'finance'];
|
|
343
354
|
|
|
344
|
-
/*
|
|
355
|
+
/* Page styles: scoped classes over the theme's alias tokens. */
|
|
345
356
|
(function injectCardCss() {
|
|
346
357
|
if (typeof document === 'undefined') return;
|
|
347
|
-
var tagId = NS + '/
|
|
358
|
+
var tagId = NS + '/page.css';
|
|
348
359
|
if (document.querySelector('style[data-plugin-css="' + tagId + '"]') !== null) return;
|
|
349
360
|
var css = [
|
|
350
|
-
'.qr-
|
|
351
|
-
'.qr-
|
|
352
|
-
'.qr-card.qr-open{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}',
|
|
353
|
-
'.qr-header{appearance:none;display:flex;align-items:center;gap:12px;width:100%;padding:14px 16px;background:0 0;border:0;border-radius:12px;cursor:pointer;color:inherit;font:inherit;text-align:left}',
|
|
354
|
-
'.qr-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}',
|
|
355
|
-
'.qr-head{flex-direction:column;flex:1;min-width:0;gap:4px;display:flex}',
|
|
356
|
-
'.qr-name{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}',
|
|
357
|
-
'.qr-desc{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}',
|
|
358
|
-
'.qr-pending{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}',
|
|
359
|
-
'.qr-chev{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s}',
|
|
360
|
-
'.qr-card.qr-open .qr-chev{transform:rotate(180deg)}',
|
|
361
|
-
'.qr-body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding-bottom:8px}',
|
|
362
|
-
'.qr-readonly{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}',
|
|
361
|
+
'.qr-page{display:flex;flex-direction:column}',
|
|
362
|
+
'.qr-readonly{color:var(--dsw-alias-label-tertiary);margin:0 0 4px;font-size:12px;line-height:1.5}',
|
|
363
363
|
'.qr-field{display:flex;flex-direction:column;gap:6px;padding:12px 0}',
|
|
364
364
|
'.qr-field+.qr-field{border-top:1px solid var(--dsw-alias-border-l2)}',
|
|
365
365
|
'.qr-fhead{display:flex;align-items:center;gap:8px}',
|
|
@@ -394,78 +394,102 @@ function makeStore(initial) {
|
|
|
394
394
|
})();
|
|
395
395
|
|
|
396
396
|
var en = {
|
|
397
|
-
|
|
398
|
-
|
|
397
|
+
summary: 'Querit web search and page fetch. Configure the API key, result count, and search filters.',
|
|
398
|
+
loading: 'Loading settings\u2026',
|
|
399
399
|
readOnly: 'This deployment stores settings read-only.',
|
|
400
|
-
expand: 'Show settings',
|
|
401
|
-
collapse: 'Hide settings',
|
|
402
400
|
pass: 'Password',
|
|
403
401
|
save: 'Save',
|
|
404
402
|
saving: 'Saving\u2026',
|
|
405
403
|
discard: 'Discard',
|
|
406
|
-
unsaved: 'Unsaved',
|
|
407
404
|
overridden: 'Overridden',
|
|
408
405
|
reset: 'Reset to default',
|
|
406
|
+
useDefault: 'Default (not set)',
|
|
409
407
|
saveFailed: 'The deployment did not accept these values; they were left for you to correct.',
|
|
410
|
-
invalidNumber: 'Enter a number, or leave blank to use the default.',
|
|
408
|
+
invalidNumber: 'Enter a whole number, or leave blank to use the default.',
|
|
411
409
|
keyLabel: 'API key',
|
|
412
410
|
keyHint: 'Stored outside the settings file. Leave blank to keep the current key.',
|
|
413
411
|
keySet: 'A key is configured for',
|
|
414
|
-
keyUnset: 'No key is configured; search fails until one is set
|
|
412
|
+
keyUnset: 'No key is configured; search fails until one is set here or in the credentials store.',
|
|
415
413
|
refLabel: 'Credential reference',
|
|
416
|
-
refHint: '
|
|
414
|
+
refHint: 'Credentials-store name the provider resolves per call.',
|
|
417
415
|
countLabel: 'Result count',
|
|
418
|
-
countHint: 'Results per search when no explicit bound is given (1\
|
|
416
|
+
countHint: 'Results per search when no explicit bound is given (1\u2013100). Blank leaves the choice to Querit.',
|
|
419
417
|
timeRangeLabel: 'Time range',
|
|
420
418
|
timeRangeHint: 'Relative (d7, w2, m3, y1, \u2026) or YYYY-MM-DDtoYYYY-MM-DD.',
|
|
421
419
|
languagesLabel: 'Languages',
|
|
422
|
-
languagesHint: 'Comma-separated: english, japanese, korean, german, french, spanish, portuguese.',
|
|
420
|
+
languagesHint: 'Comma-separated: english, japanese, korean, german, french, spanish, portuguese, russian.',
|
|
423
421
|
countriesLabel: 'Countries',
|
|
424
422
|
countriesHint: 'Comma-separated country bias (argentina, australia, brazil, \u2026).',
|
|
425
423
|
includeLabel: 'Include domains',
|
|
426
424
|
includeHint: 'Whitelist hostnames; only these domains return results.',
|
|
427
425
|
excludeLabel: 'Exclude domains',
|
|
428
426
|
excludeHint: 'Blacklist hostnames; these domains never return results.',
|
|
429
|
-
contentLabel: 'Include
|
|
430
|
-
contentHint: 'Request sentence-level
|
|
427
|
+
contentLabel: 'Include body text',
|
|
428
|
+
contentHint: 'Request sentence-level body text alongside snippets. Billed per page.',
|
|
429
|
+
contentMaxCharsLabel: 'Body text limit',
|
|
430
|
+
contentMaxCharsHint: 'Characters of body text per result (1\u20131000000). Blank returns everything.',
|
|
431
|
+
highlightsLabel: 'Highlights',
|
|
432
|
+
highlightsHint: 'Ask Querit for the passages of each page that match the query, instead of whole pages.',
|
|
433
|
+
markdownLabel: 'Markdown body',
|
|
434
|
+
markdownHint: 'Enterprise plans only: return the snippet and body as Markdown.',
|
|
435
|
+
rankLabel: 'Ranking preference',
|
|
436
|
+
rankHint: 'A nudge on Querit\u2019s default ranking, not a sort. Not supported by the code vertical.',
|
|
437
|
+
verticalLabel: 'Vertical',
|
|
438
|
+
verticalHint: 'Route every search to a vertical data source. A mismatched vertical loses results, so leave unset unless this profile only asks code or finance questions.',
|
|
439
|
+
resourceTagsLabel: 'Vertical sub-tags',
|
|
440
|
+
resourceTagsHint: 'Code vertical only, comma-separated: qa, github. Blank searches the whole vertical.',
|
|
441
|
+
chunksLabel: 'Chunks per document (deprecated)',
|
|
442
|
+
chunksHint: 'Deprecated by Querit; prefer highlights. Blank sends nothing.',
|
|
431
443
|
formatLabel: 'Fetch format',
|
|
432
444
|
formatHint: 'Format requested from /v1/contents for fetch calls.'
|
|
433
445
|
};
|
|
434
446
|
var zh = {
|
|
435
|
-
|
|
436
|
-
|
|
447
|
+
summary: 'Querit 网页搜索与网页抓取。配置 API Key、结果数量与搜索过滤条件。',
|
|
448
|
+
loading: '正在加载设置\u2026',
|
|
437
449
|
readOnly: '本部署的设置为只读。',
|
|
438
|
-
expand: '展开设置',
|
|
439
|
-
collapse: '收起设置',
|
|
440
450
|
pass: '密码',
|
|
441
451
|
save: '保存',
|
|
442
452
|
saving: '保存中\u2026',
|
|
443
453
|
discard: '放弃修改',
|
|
444
|
-
unsaved: '未保存',
|
|
445
454
|
overridden: '已覆盖',
|
|
446
455
|
reset: '恢复默认',
|
|
456
|
+
useDefault: '默认(不设置)',
|
|
447
457
|
saveFailed: '本部署没有接受这些值,已保留供你修改。',
|
|
448
|
-
invalidNumber: '
|
|
458
|
+
invalidNumber: '请填整数;留空表示使用默认值。',
|
|
449
459
|
keyLabel: 'API Key',
|
|
450
460
|
keyHint: '不写入设置文件。留空表示保持当前密钥。',
|
|
451
461
|
keySet: '已为',
|
|
452
|
-
keyUnset: '
|
|
462
|
+
keyUnset: '未配置密钥;请在此处或凭据存储中配置后搜索才可用。',
|
|
453
463
|
refLabel: '凭据引用名',
|
|
454
|
-
refHint: '
|
|
464
|
+
refHint: '每次调用解析的凭据存储键名。',
|
|
455
465
|
countLabel: '结果数量',
|
|
456
|
-
countHint: '未指定上限时每次搜索返回的结果数(1–
|
|
466
|
+
countHint: '未指定上限时每次搜索返回的结果数(1–100)。留空表示由 Querit 决定。',
|
|
457
467
|
timeRangeLabel: '时间范围',
|
|
458
468
|
timeRangeHint: '相对(d7、w2、m3、y1…)或 YYYY-MM-DDtoYYYY-MM-DD。',
|
|
459
469
|
languagesLabel: '语言',
|
|
460
|
-
languagesHint: '逗号分隔:english、japanese、korean、german、french、spanish、portuguese。',
|
|
470
|
+
languagesHint: '逗号分隔:english、japanese、korean、german、french、spanish、portuguese、russian。',
|
|
461
471
|
countriesLabel: '国家',
|
|
462
472
|
countriesHint: '逗号分隔的国家偏好(argentina、australia、brazil…)。',
|
|
463
473
|
includeLabel: '仅限域名',
|
|
464
474
|
includeHint: '白名单主机名;只返回这些域的结果。',
|
|
465
475
|
excludeLabel: '排除域名',
|
|
466
476
|
excludeHint: '黑名单主机名;这些域永不返回结果。',
|
|
467
|
-
contentLabel: '
|
|
468
|
-
contentHint: '
|
|
477
|
+
contentLabel: '包含正文',
|
|
478
|
+
contentHint: '在摘要旁请求句子级正文。按页计费。',
|
|
479
|
+
contentMaxCharsLabel: '正文长度上限',
|
|
480
|
+
contentMaxCharsHint: '每条结果返回的正文字符数(1–1000000)。留空返回全部。',
|
|
481
|
+
highlightsLabel: '高亮片段',
|
|
482
|
+
highlightsHint: '让 Querit 只返回每个页面中与查询相关的段落,而不是整页。',
|
|
483
|
+
markdownLabel: 'Markdown 正文',
|
|
484
|
+
markdownHint: '仅企业版:以 Markdown 返回摘要与正文。',
|
|
485
|
+
rankLabel: '排序偏好',
|
|
486
|
+
rankHint: '在 Querit 默认排序之上的微调,并非严格排序。代码垂直搜索不支持。',
|
|
487
|
+
verticalLabel: '垂直搜索',
|
|
488
|
+
verticalHint: '把每次搜索都路由到垂直数据源。类型不匹配会丢失结果,除非本配置只问代码或金融问题,否则请留空。',
|
|
489
|
+
resourceTagsLabel: '垂直子标签',
|
|
490
|
+
resourceTagsHint: '仅代码垂直搜索,逗号分隔:qa、github。留空搜索整个垂直。',
|
|
491
|
+
chunksLabel: '每文档分块数(已废弃)',
|
|
492
|
+
chunksHint: 'Querit 已废弃,请改用高亮片段。留空则不发送。',
|
|
469
493
|
formatLabel: '抓取格式',
|
|
470
494
|
formatHint: '/v1/contents 抓取请求的格式。'
|
|
471
495
|
};
|
|
@@ -476,13 +500,12 @@ function makeStore(initial) {
|
|
|
476
500
|
return declared !== undefined && declared.length > 0 ? declared : DEFAULT_API_KEY_REF;
|
|
477
501
|
}
|
|
478
502
|
|
|
479
|
-
/** Bridges the
|
|
480
|
-
function QueritCardController(
|
|
481
|
-
this.scope = scope;
|
|
503
|
+
/** Bridges the entry's config form and the credentials domain onto the page. */
|
|
504
|
+
function QueritCardController(form, ctx) {
|
|
482
505
|
this.ctx = ctx;
|
|
483
506
|
this.credential = { ref: '', configured: false, writable: true };
|
|
484
507
|
this.form = new QueritFormModel(
|
|
485
|
-
|
|
508
|
+
form,
|
|
486
509
|
[
|
|
487
510
|
textField('apiKeyEnv'),
|
|
488
511
|
numberField('count'),
|
|
@@ -492,31 +515,50 @@ function makeStore(initial) {
|
|
|
492
515
|
listField('includeDomains'),
|
|
493
516
|
listField('excludeDomains'),
|
|
494
517
|
booleanField('includeContent'),
|
|
518
|
+
numberField('contentMaxChars'),
|
|
519
|
+
booleanField('highlights'),
|
|
520
|
+
booleanField('needMarkdown'),
|
|
521
|
+
enumField('rank', RANK_VALUES),
|
|
522
|
+
enumField('vertical', VERTICAL_VALUES),
|
|
523
|
+
listField('resourceTags'),
|
|
524
|
+
numberField('chunksPerDoc'),
|
|
495
525
|
enumField('fetchFormat', FETCH_FORMATS)
|
|
496
526
|
],
|
|
497
527
|
[secretSpec('apiKey', (value) => this.writeKey(value))]
|
|
498
528
|
);
|
|
499
529
|
this.store = this.form.bind(() => this.projection());
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
self.readCredential();
|
|
530
|
+
this.unsubscribe = form.subscribe(() => {
|
|
531
|
+
this.readCredential();
|
|
503
532
|
});
|
|
504
533
|
this.readCredential();
|
|
505
534
|
}
|
|
506
535
|
|
|
536
|
+
QueritCardController.prototype.dispose = function () {
|
|
537
|
+
this.unsubscribe();
|
|
538
|
+
this.form.dispose();
|
|
539
|
+
};
|
|
540
|
+
|
|
507
541
|
QueritCardController.prototype.projection = function () {
|
|
542
|
+
var field = (name) => this.form.field(name);
|
|
508
543
|
return {
|
|
509
544
|
...this.form.shell(),
|
|
510
|
-
apiKeyEnv:
|
|
511
|
-
count:
|
|
512
|
-
timeRange:
|
|
513
|
-
languages:
|
|
514
|
-
countries:
|
|
515
|
-
includeDomains:
|
|
516
|
-
excludeDomains:
|
|
517
|
-
includeContent:
|
|
518
|
-
|
|
519
|
-
|
|
545
|
+
apiKeyEnv: field('apiKeyEnv'),
|
|
546
|
+
count: field('count'),
|
|
547
|
+
timeRange: field('timeRange'),
|
|
548
|
+
languages: field('languages'),
|
|
549
|
+
countries: field('countries'),
|
|
550
|
+
includeDomains: field('includeDomains'),
|
|
551
|
+
excludeDomains: field('excludeDomains'),
|
|
552
|
+
includeContent: field('includeContent'),
|
|
553
|
+
contentMaxChars: field('contentMaxChars'),
|
|
554
|
+
highlights: field('highlights'),
|
|
555
|
+
needMarkdown: field('needMarkdown'),
|
|
556
|
+
rank: field('rank'),
|
|
557
|
+
vertical: field('vertical'),
|
|
558
|
+
resourceTags: field('resourceTags'),
|
|
559
|
+
chunksPerDoc: field('chunksPerDoc'),
|
|
560
|
+
fetchFormat: field('fetchFormat'),
|
|
561
|
+
apiKey: field('apiKey'),
|
|
520
562
|
apiKeyConfigured: this.credential.configured,
|
|
521
563
|
apiKeyWritable: this.credential.writable,
|
|
522
564
|
apiKeyRef: this.credential.ref
|
|
@@ -525,7 +567,7 @@ function makeStore(initial) {
|
|
|
525
567
|
|
|
526
568
|
QueritCardController.prototype.readCredential = function () {
|
|
527
569
|
var self = this;
|
|
528
|
-
var ref = refOf(this.scope.getSnapshot());
|
|
570
|
+
var ref = refOf(this.form.scope.getSnapshot());
|
|
529
571
|
if (ref !== this.credential.ref) {
|
|
530
572
|
this.credential = { ref: ref, configured: false, writable: true };
|
|
531
573
|
this.store.set(this.projection());
|
|
@@ -534,7 +576,7 @@ function makeStore(initial) {
|
|
|
534
576
|
.describe([ref])
|
|
535
577
|
.then(function (response) {
|
|
536
578
|
if (!response || response.ok !== true) return;
|
|
537
|
-
if (ref !== refOf(self.scope.getSnapshot())) return;
|
|
579
|
+
if (ref !== refOf(self.form.scope.getSnapshot())) return;
|
|
538
580
|
var view = response.value !== undefined ? response.value[ref] : undefined;
|
|
539
581
|
var next = {
|
|
540
582
|
ref: ref,
|
|
@@ -556,7 +598,7 @@ function makeStore(initial) {
|
|
|
556
598
|
QueritCardController.prototype.writeKey = function (value) {
|
|
557
599
|
var self = this;
|
|
558
600
|
return this.ctx.remote.credentials
|
|
559
|
-
.set(refOf(this.scope.getSnapshot()), value)
|
|
601
|
+
.set(refOf(this.form.scope.getSnapshot()), value)
|
|
560
602
|
.then(function () {
|
|
561
603
|
return self.readCredential();
|
|
562
604
|
})
|
|
@@ -575,31 +617,6 @@ function makeStore(initial) {
|
|
|
575
617
|
};
|
|
576
618
|
};
|
|
577
619
|
|
|
578
|
-
/** Chevron-down icon mirroring the official PluginCard toggle glyph. */
|
|
579
|
-
function ChevronDown(props) {
|
|
580
|
-
var className = props.className || '';
|
|
581
|
-
return React.createElement(
|
|
582
|
-
'svg',
|
|
583
|
-
{
|
|
584
|
-
className: className,
|
|
585
|
-
width: 14,
|
|
586
|
-
height: 14,
|
|
587
|
-
viewBox: '0 0 14 14',
|
|
588
|
-
fill: 'none',
|
|
589
|
-
xmlns: 'http://www.w3.org/2000/svg',
|
|
590
|
-
'aria-hidden': true,
|
|
591
|
-
focusable: false
|
|
592
|
-
},
|
|
593
|
-
React.createElement('path', {
|
|
594
|
-
d: 'M3.5 5.25L7 8.75L10.5 5.25',
|
|
595
|
-
stroke: 'currentColor',
|
|
596
|
-
strokeWidth: 1.4,
|
|
597
|
-
strokeLinecap: 'round',
|
|
598
|
-
strokeLinejoin: 'round'
|
|
599
|
-
})
|
|
600
|
-
);
|
|
601
|
-
}
|
|
602
|
-
|
|
603
620
|
/** One labeled control row. `inline` puts the control on the label line (toggle rows). */
|
|
604
621
|
function FieldRow(props) {
|
|
605
622
|
var inline = props.inline === true;
|
|
@@ -651,137 +668,136 @@ function makeStore(initial) {
|
|
|
651
668
|
);
|
|
652
669
|
}
|
|
653
670
|
|
|
654
|
-
/**
|
|
655
|
-
function
|
|
671
|
+
/** A checkbox row bound to one boolean field. */
|
|
672
|
+
function toggleRow(props, t, state, name, label, hint, id, disabled) {
|
|
673
|
+
return React.createElement(
|
|
674
|
+
FieldRow,
|
|
675
|
+
{
|
|
676
|
+
id: id,
|
|
677
|
+
label: label,
|
|
678
|
+
hint: hint,
|
|
679
|
+
state: state,
|
|
680
|
+
disabled: disabled,
|
|
681
|
+
inline: true,
|
|
682
|
+
overriddenLabel: t('overridden'),
|
|
683
|
+
resetLabel: t('reset'),
|
|
684
|
+
onReset: function () { props.resetField(name); }
|
|
685
|
+
},
|
|
686
|
+
React.createElement('input', {
|
|
687
|
+
className: 'qr-check',
|
|
688
|
+
type: 'checkbox',
|
|
689
|
+
disabled: disabled,
|
|
690
|
+
checked: state.text === 'true',
|
|
691
|
+
onChange: function (event) { props.edit(name, event.target.checked ? 'true' : 'false'); }
|
|
692
|
+
})
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/** A dropdown over a fixed set, with a blank option that clears the field. */
|
|
697
|
+
function selectRow(props, t, state, name, label, hint, choices, id, disabled, optional) {
|
|
698
|
+
var options = (optional === true ? [React.createElement('option', { key: '', value: '' }, t('useDefault'))] : []).concat(
|
|
699
|
+
choices.map(function (choice) {
|
|
700
|
+
return React.createElement('option', { key: choice, value: choice }, choice);
|
|
701
|
+
})
|
|
702
|
+
);
|
|
703
|
+
return React.createElement(
|
|
704
|
+
FieldRow,
|
|
705
|
+
{
|
|
706
|
+
id: id,
|
|
707
|
+
label: label,
|
|
708
|
+
hint: hint,
|
|
709
|
+
state: state,
|
|
710
|
+
disabled: disabled,
|
|
711
|
+
overriddenLabel: t('overridden'),
|
|
712
|
+
resetLabel: t('reset'),
|
|
713
|
+
onReset: function () { props.resetField(name); },
|
|
714
|
+
inputProps: {
|
|
715
|
+
disabled: disabled,
|
|
716
|
+
value: state.text,
|
|
717
|
+
onChange: function (event) { props.edit(name, event.target.value); },
|
|
718
|
+
as: 'select'
|
|
719
|
+
},
|
|
720
|
+
options: options
|
|
721
|
+
}
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* The entry the Plugins page renders for the Querit row: a one-liner while
|
|
727
|
+
* collapsed (`view: 'summary'`), the settings form on the row's own page
|
|
728
|
+
* (`view: 'page'`). The page draws the row's title itself.
|
|
729
|
+
*/
|
|
730
|
+
function QueritRowConfig(props) {
|
|
656
731
|
var t = props.t || function (key) {
|
|
657
732
|
return zh[key] || en[key] || key;
|
|
658
733
|
};
|
|
734
|
+
if (props.view === 'summary') return React.createElement('span', null, t('summary'));
|
|
735
|
+
|
|
659
736
|
var state = props.useQueritCard(function (snapshot) {
|
|
660
737
|
return snapshot;
|
|
661
738
|
});
|
|
662
|
-
var openState = React.useState(props.defaultOpen === true);
|
|
663
|
-
var open = openState[0];
|
|
664
|
-
var setOpen = openState[1];
|
|
665
739
|
if (!state.available) return null;
|
|
666
740
|
var disabled = !state.writable;
|
|
667
741
|
var blocked = !state.dirty || state.invalid || state.saving;
|
|
668
742
|
var text = function (control) {
|
|
669
743
|
return control.text;
|
|
670
744
|
};
|
|
671
|
-
var
|
|
745
|
+
var prefix = 'plugin-config-querit-';
|
|
672
746
|
return React.createElement(
|
|
673
|
-
'
|
|
674
|
-
{ className: 'qr-
|
|
747
|
+
'div',
|
|
748
|
+
{ className: 'qr-page', 'data-querit-config': 'page' },
|
|
749
|
+
disabled ? React.createElement('p', { className: 'qr-readonly', role: 'status' }, t('readOnly')) : null,
|
|
675
750
|
React.createElement(
|
|
676
|
-
|
|
751
|
+
FieldRow,
|
|
677
752
|
{
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
753
|
+
id: prefix + 'key',
|
|
754
|
+
label: t('keyLabel'),
|
|
755
|
+
hint: state.apiKeyConfigured
|
|
756
|
+
? t('keySet') + ' ' + state.apiKeyRef + '.'
|
|
757
|
+
: t('keyUnset'),
|
|
758
|
+
disabled: disabled || !state.apiKeyWritable,
|
|
759
|
+
inputProps: {
|
|
760
|
+
className: 'qr-input',
|
|
761
|
+
type: 'password',
|
|
762
|
+
autoComplete: 'new-password',
|
|
763
|
+
disabled: disabled || !state.apiKeyWritable,
|
|
764
|
+
placeholder: state.apiKeyConfigured ? '\u2022\u2022\u2022\u2022\u2022\u2022' : '',
|
|
765
|
+
value: text(state.apiKey),
|
|
766
|
+
onChange: function (event) { props.edit('apiKey', event.target.value); }
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
),
|
|
770
|
+
field(props, t('refLabel'), t('refHint'), state.apiKeyEnv, 'apiKeyEnv', disabled, prefix + 'env'),
|
|
771
|
+
field(props, t('countLabel'), t('countHint'), state.count, 'count', disabled, prefix + 'count', true),
|
|
772
|
+
field(props, t('timeRangeLabel'), t('timeRangeHint'), state.timeRange, 'timeRange', disabled, prefix + 'time'),
|
|
773
|
+
field(props, t('languagesLabel'), t('languagesHint'), state.languages, 'languages', disabled, prefix + 'languages'),
|
|
774
|
+
field(props, t('countriesLabel'), t('countriesHint'), state.countries, 'countries', disabled, prefix + 'countries'),
|
|
775
|
+
field(props, t('includeLabel'), t('includeHint'), state.includeDomains, 'includeDomains', disabled, prefix + 'include'),
|
|
776
|
+
field(props, t('excludeLabel'), t('excludeHint'), state.excludeDomains, 'excludeDomains', disabled, prefix + 'exclude'),
|
|
777
|
+
toggleRow(props, t, state.includeContent, 'includeContent', t('contentLabel'), t('contentHint'), prefix + 'content', disabled),
|
|
778
|
+
field(props, t('contentMaxCharsLabel'), t('contentMaxCharsHint'), state.contentMaxChars, 'contentMaxChars', disabled, prefix + 'content-max', true),
|
|
779
|
+
toggleRow(props, t, state.highlights, 'highlights', t('highlightsLabel'), t('highlightsHint'), prefix + 'highlights', disabled),
|
|
780
|
+
toggleRow(props, t, state.needMarkdown, 'needMarkdown', t('markdownLabel'), t('markdownHint'), prefix + 'markdown', disabled),
|
|
781
|
+
selectRow(props, t, state.rank, 'rank', t('rankLabel'), t('rankHint'), RANK_VALUES, prefix + 'rank', disabled, true),
|
|
782
|
+
selectRow(props, t, state.vertical, 'vertical', t('verticalLabel'), t('verticalHint'), VERTICAL_VALUES, prefix + 'vertical', disabled, true),
|
|
783
|
+
field(props, t('resourceTagsLabel'), t('resourceTagsHint'), state.resourceTags, 'resourceTags', disabled, prefix + 'resource-tags'),
|
|
784
|
+
field(props, t('chunksLabel'), t('chunksHint'), state.chunksPerDoc, 'chunksPerDoc', disabled, prefix + 'chunks', true),
|
|
785
|
+
selectRow(props, t, state.fetchFormat, 'fetchFormat', t('formatLabel'), t('formatHint'), FETCH_FORMATS, prefix + 'format', disabled, false),
|
|
786
|
+
React.createElement(
|
|
787
|
+
'div',
|
|
788
|
+
{ className: 'qr-foot' },
|
|
789
|
+
state.failed ? React.createElement('p', { className: 'qr-failed', role: 'status' }, t('saveFailed')) : null,
|
|
684
790
|
React.createElement(
|
|
685
|
-
'
|
|
686
|
-
{ className: 'qr-
|
|
687
|
-
|
|
688
|
-
React.createElement('span', { className: 'qr-desc' }, t('description'))
|
|
791
|
+
'button',
|
|
792
|
+
{ type: 'button', className: 'qr-btn qr-discard', disabled: (!state.dirty && !state.failed) || state.saving, onClick: props.discard },
|
|
793
|
+
t('discard')
|
|
689
794
|
),
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
{ className: 'qr-body' },
|
|
697
|
-
disabled ? React.createElement('p', { className: 'qr-readonly', role: 'status' }, t('readOnly')) : null,
|
|
698
|
-
React.createElement(
|
|
699
|
-
FieldRow,
|
|
700
|
-
{
|
|
701
|
-
id: 'plugin-config-querit-key',
|
|
702
|
-
label: t('keyLabel'),
|
|
703
|
-
hint: state.apiKeyConfigured
|
|
704
|
-
? t('keySet') + ' ' + state.apiKeyRef + '.'
|
|
705
|
-
: t('keyUnset'),
|
|
706
|
-
disabled: disabled || !state.apiKeyWritable,
|
|
707
|
-
inputProps: {
|
|
708
|
-
className: 'qr-input',
|
|
709
|
-
type: 'password',
|
|
710
|
-
autoComplete: 'new-password',
|
|
711
|
-
disabled: disabled || !state.apiKeyWritable,
|
|
712
|
-
placeholder: state.apiKeyConfigured ? '\u2022\u2022\u2022\u2022\u2022\u2022' : '',
|
|
713
|
-
value: text(state.apiKey),
|
|
714
|
-
onChange: function (event) { props.edit('apiKey', event.target.value); }
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
),
|
|
718
|
-
field(props, t('refLabel'), t('refHint'), state.apiKeyEnv, 'apiKeyEnv', disabled, 'plugin-config-querit-env'),
|
|
719
|
-
field(props, t('countLabel'), t('countHint'), state.count, 'count', disabled, 'plugin-config-querit-count', true),
|
|
720
|
-
field(props, t('timeRangeLabel'), t('timeRangeHint'), state.timeRange, 'timeRange', disabled, 'plugin-config-querit-time'),
|
|
721
|
-
field(props, t('languagesLabel'), t('languagesHint'), state.languages, 'languages', disabled, 'plugin-config-querit-languages'),
|
|
722
|
-
field(props, t('countriesLabel'), t('countriesHint'), state.countries, 'countries', disabled, 'plugin-config-querit-countries'),
|
|
723
|
-
field(props, t('includeLabel'), t('includeHint'), state.includeDomains, 'includeDomains', disabled, 'plugin-config-querit-include'),
|
|
724
|
-
field(props, t('excludeLabel'), t('excludeHint'), state.excludeDomains, 'excludeDomains', disabled, 'plugin-config-querit-exclude'),
|
|
725
|
-
React.createElement(
|
|
726
|
-
FieldRow,
|
|
727
|
-
{
|
|
728
|
-
id: 'plugin-config-querit-content',
|
|
729
|
-
label: t('contentLabel'),
|
|
730
|
-
hint: t('contentHint'),
|
|
731
|
-
state: state.includeContent,
|
|
732
|
-
disabled: disabled,
|
|
733
|
-
inline: true,
|
|
734
|
-
overriddenLabel: t('overridden'),
|
|
735
|
-
resetLabel: t('reset'),
|
|
736
|
-
onReset: function () { props.resetField('includeContent'); }
|
|
737
|
-
},
|
|
738
|
-
React.createElement('input', {
|
|
739
|
-
className: 'qr-check',
|
|
740
|
-
type: 'checkbox',
|
|
741
|
-
disabled: disabled,
|
|
742
|
-
checked: state.includeContent.text === 'true',
|
|
743
|
-
onChange: function (event) { props.edit('includeContent', event.target.checked ? 'true' : 'false'); }
|
|
744
|
-
})
|
|
745
|
-
),
|
|
746
|
-
React.createElement(
|
|
747
|
-
FieldRow,
|
|
748
|
-
{
|
|
749
|
-
id: 'plugin-config-querit-format',
|
|
750
|
-
label: t('formatLabel'),
|
|
751
|
-
hint: t('formatHint'),
|
|
752
|
-
state: state.fetchFormat,
|
|
753
|
-
disabled: disabled,
|
|
754
|
-
overriddenLabel: t('overridden'),
|
|
755
|
-
resetLabel: t('reset'),
|
|
756
|
-
onReset: function () { props.resetField('fetchFormat'); },
|
|
757
|
-
inputProps: {
|
|
758
|
-
disabled: disabled,
|
|
759
|
-
value: text(state.fetchFormat),
|
|
760
|
-
onChange: function (event) { props.edit('fetchFormat', event.target.value); },
|
|
761
|
-
as: 'select'
|
|
762
|
-
},
|
|
763
|
-
options: FETCH_FORMATS.map(function (format) {
|
|
764
|
-
return React.createElement('option', { key: format, value: format }, format);
|
|
765
|
-
})
|
|
766
|
-
}
|
|
767
|
-
),
|
|
768
|
-
React.createElement(
|
|
769
|
-
'div',
|
|
770
|
-
{ className: 'qr-foot' },
|
|
771
|
-
state.failed ? React.createElement('p', { className: 'qr-failed', role: 'status' }, t('saveFailed')) : null,
|
|
772
|
-
React.createElement(
|
|
773
|
-
'button',
|
|
774
|
-
{ type: 'button', className: 'qr-btn qr-discard', disabled: (!state.dirty && !state.failed) || state.saving, onClick: props.discard },
|
|
775
|
-
t('discard')
|
|
776
|
-
),
|
|
777
|
-
React.createElement(
|
|
778
|
-
'button',
|
|
779
|
-
{ type: 'button', className: 'qr-btn qr-save', disabled: blocked, onClick: props.save },
|
|
780
|
-
t(state.saving ? 'saving' : 'save')
|
|
781
|
-
)
|
|
782
|
-
)
|
|
783
|
-
)
|
|
784
|
-
: null
|
|
795
|
+
React.createElement(
|
|
796
|
+
'button',
|
|
797
|
+
{ type: 'button', className: 'qr-btn qr-save', disabled: blocked, onClick: props.save },
|
|
798
|
+
t(state.saving ? 'saving' : 'save')
|
|
799
|
+
)
|
|
800
|
+
)
|
|
785
801
|
);
|
|
786
802
|
}
|
|
787
803
|
|
|
@@ -813,57 +829,65 @@ function makeStore(initial) {
|
|
|
813
829
|
);
|
|
814
830
|
}
|
|
815
831
|
|
|
816
|
-
/** Required services (cordis fiber inject); `remote.credentials` gates the
|
|
817
|
-
var inject = ['slots', 'locale', 'remote', 'remote.credentials', '
|
|
832
|
+
/** Required services (cordis fiber inject); `remote.credentials` gates the page on the credentials namespace. */
|
|
833
|
+
var inject = ['slots', 'locale', 'remote', 'remote.credentials', 'configForms'];
|
|
818
834
|
|
|
819
835
|
/**
|
|
820
|
-
* Mount the Querit
|
|
836
|
+
* Mount the Querit row's configuration page while the Host serves its namespace.
|
|
821
837
|
* @param ctx - the browser plugin context.
|
|
822
838
|
*/
|
|
823
839
|
function apply(ctx) {
|
|
824
840
|
var slots = ctx.get('slots');
|
|
825
|
-
var scopeService = ctx.get('settingsScope');
|
|
826
841
|
var locale = ctx.get('locale');
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
//
|
|
830
|
-
//
|
|
831
|
-
// backed for this entry.
|
|
842
|
+
var configForms = ctx.get('configForms');
|
|
843
|
+
if (slots === undefined || locale === undefined || configForms === undefined) return;
|
|
844
|
+
// Register the page dictionaries, then bind our own translator so text
|
|
845
|
+
// resolves even if the slot framework delivers no `t` seat for this entry.
|
|
832
846
|
var dicts = { zh: zh, en: en };
|
|
833
847
|
ctx.effect(function () {
|
|
834
848
|
return locale.register(NS, dicts);
|
|
835
|
-
}, 'dsh-querit:
|
|
849
|
+
}, 'dsh-querit: page dictionaries');
|
|
836
850
|
var t = locale.bind(NS);
|
|
837
|
-
var
|
|
838
|
-
|
|
851
|
+
var controller = new QueritCardController(configForms.get(NAMESPACE), ctx);
|
|
852
|
+
ctx.effect(function () {
|
|
853
|
+
return function () { controller.dispose(); };
|
|
854
|
+
}, 'dsh-querit: form subscription');
|
|
839
855
|
var remote = ctx.get('remote');
|
|
840
856
|
if (remote !== undefined) {
|
|
857
|
+
// A key written on another surface changes no settings section, so this
|
|
858
|
+
// event is the only signal that it reached the Host.
|
|
841
859
|
ctx.effect(function () {
|
|
842
860
|
return remote.$on('credentials/reference-updated', function (ref) {
|
|
843
861
|
controller.refreshCredential(ref);
|
|
844
862
|
});
|
|
845
863
|
}, 'dsh-querit: credential invalidations');
|
|
846
864
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
865
|
+
// A deployment that never composed this entry shows no trace of the page.
|
|
866
|
+
ctx.effect(function () {
|
|
867
|
+
return configForms.whileServed([NAMESPACE], function () {
|
|
868
|
+
return ctx.slots.inject('plugins.row.config', function () {
|
|
869
|
+
return ctx.slots.register(
|
|
870
|
+
{
|
|
871
|
+
name: 'plugins.row.config',
|
|
872
|
+
key: ROW_CONFIG_KEY,
|
|
873
|
+
locale: NS,
|
|
874
|
+
inject: function () {
|
|
875
|
+
var face = controller.inject();
|
|
876
|
+
face.t = t;
|
|
877
|
+
return face;
|
|
878
|
+
}
|
|
879
|
+
},
|
|
880
|
+
QueritRowConfig
|
|
881
|
+
);
|
|
882
|
+
});
|
|
883
|
+
});
|
|
884
|
+
}, 'dsh-querit: row configuration page');
|
|
862
885
|
}
|
|
863
886
|
|
|
864
887
|
exports.apply = apply;
|
|
865
888
|
exports.inject = inject;
|
|
889
|
+
exports.ROW_CONFIG_KEY = ROW_CONFIG_KEY;
|
|
866
890
|
exports.QueritCardController = QueritCardController;
|
|
867
|
-
exports.
|
|
891
|
+
exports.QueritRowConfig = QueritRowConfig;
|
|
868
892
|
return module.exports;
|
|
869
|
-
});
|
|
893
|
+
});
|