-
Notifications
You must be signed in to change notification settings - Fork 165
Experimental search completion #7979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5945d45
7c451f6
091a61b
50888de
c9f36cb
7849d99
feb8361
11ecb6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:convert'; | ||
|
||
import 'package:pub_dev/frontend/request_context.dart'; | ||
|
||
import '../../../dom/dom.dart' as d; | ||
import '../../../static_files.dart' show staticUrls; | ||
|
||
|
@@ -16,17 +20,25 @@ d.Node searchBannerNode({ | |
}) { | ||
return d.form( | ||
classes: ['search-bar', 'banner-item'], | ||
attributes: { | ||
'autocomplete': 'off', | ||
}, | ||
action: formUrl, | ||
children: [ | ||
d.input( | ||
classes: ['input'], | ||
type: 'search', | ||
name: 'q', | ||
placeholder: placeholder, | ||
autocomplete: 'on', | ||
autocomplete: 'off', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this not be conditional on the experiment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, we don't want the browser to auto-complete, it just suggests what you've typed before. |
||
autofocus: autofocus, | ||
value: queryText, | ||
attributes: { | ||
'title': 'Search', | ||
if (requestContext.experimentalFlags.isSearchCompletionEnabled) | ||
'data-widget': 'completion', | ||
'data-completion-src': '/api/search-input-completion-data', | ||
'data-completion-class': 'search-completion', | ||
}, | ||
), | ||
d.span(classes: ['icon']), | ||
|
@@ -64,3 +76,109 @@ d.Node searchBannerNode({ | |
], | ||
); | ||
} | ||
|
||
/// Create completion data for search input. | ||
/// | ||
/// Format is dictacted by `pkg/web_app/lib/src/completion.dart`. | ||
/// | ||
/// If values in `match` is a prefix of what is being typed completion | ||
/// will automatically start. It'll always try to use the longest match. | ||
/// If not specified options available are assumed to be `terminal`, that is | ||
/// they will be followed by whitespace. | ||
/// If `forcedOnly` is specified, completion can only be initiated with | ||
/// Ctrl+Space. | ||
/// | ||
/// This can generate completion data of different sizes given [topics] and | ||
/// [licenses]. | ||
String completionDataJson({ | ||
isoos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
List<String> topics = const [], | ||
List<String> licenses = const [], | ||
}) => | ||
json.encode({ | ||
// TODO: Write a shared type for this in `pkg/_pub_shared/lib/data/` | ||
'completions': [ | ||
jonasfj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
'match': ['', '-'], | ||
'terminal': false, | ||
'forcedOnly': true, | ||
'options': [ | ||
'has:', | ||
'is:', | ||
'license:', | ||
'platform:', | ||
'sdk:', | ||
'show:', | ||
'topic:', | ||
'runtime:', | ||
'dependency:', | ||
'dependency*:', | ||
'publisher:', | ||
], | ||
}, | ||
// TODO: Consider completion support for dependency:, dependency*: and publisher: | ||
{ | ||
'match': ['is:', '-is:'], | ||
'options': [ | ||
'dart3-compatible', | ||
'flutter-favorite', | ||
'legacy', | ||
'null-safe', | ||
'plugin', | ||
'unlisted', | ||
'wasm-ready', | ||
], | ||
}, | ||
{ | ||
'match': ['has:', '-has:'], | ||
'options': [ | ||
'executable', | ||
'screenshot', | ||
], | ||
}, | ||
{ | ||
'match': ['license:', '-license:'], | ||
'options': [ | ||
'osi-approved', | ||
...licenses, | ||
], | ||
}, | ||
{ | ||
'match': ['show:', '-show:'], | ||
'options': [ | ||
'unlisted', | ||
], | ||
}, | ||
{ | ||
'match': ['sdk:', '-sdk:'], | ||
'options': [ | ||
'dart', | ||
'flutter', | ||
], | ||
}, | ||
{ | ||
'match': ['platform:', '-platform:'], | ||
'options': [ | ||
'android', | ||
'ios', | ||
'linux', | ||
'macos', | ||
'web', | ||
'windows', | ||
], | ||
}, | ||
{ | ||
'match': ['runtime:', '-runtime:'], | ||
'options': [ | ||
'native-aot', | ||
'native-jit', | ||
'web', | ||
], | ||
}, | ||
{ | ||
'match': ['topic:', '-topic:'], | ||
'options': [ | ||
...topics, | ||
], | ||
}, | ||
], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just reject the request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm 50/50 on that, maybe it's the better choice.