2023-06-29 11:55:02 +08:00
/ *
THIS IS A GENERATED / BUNDLED FILE BY ESBUILD
if you want to view the source , please visit the github repository of this plugin
* /
var _ _create = Object . create ;
var _ _defProp = Object . defineProperty ;
var _ _defProps = Object . defineProperties ;
var _ _getOwnPropDesc = Object . getOwnPropertyDescriptor ;
var _ _getOwnPropDescs = Object . getOwnPropertyDescriptors ;
var _ _getOwnPropNames = Object . getOwnPropertyNames ;
var _ _getOwnPropSymbols = Object . getOwnPropertySymbols ;
var _ _getProtoOf = Object . getPrototypeOf ;
var _ _hasOwnProp = Object . prototype . hasOwnProperty ;
var _ _propIsEnum = Object . prototype . propertyIsEnumerable ;
var _ _defNormalProp = ( obj , key , value ) => key in obj ? _ _defProp ( obj , key , { enumerable : true , configurable : true , writable : true , value } ) : obj [ key ] = value ;
var _ _spreadValues = ( a , b ) => {
for ( var prop in b || ( b = { } ) )
if ( _ _hasOwnProp . call ( b , prop ) )
_ _defNormalProp ( a , prop , b [ prop ] ) ;
if ( _ _getOwnPropSymbols )
for ( var prop of _ _getOwnPropSymbols ( b ) ) {
if ( _ _propIsEnum . call ( b , prop ) )
_ _defNormalProp ( a , prop , b [ prop ] ) ;
}
return a ;
} ;
var _ _spreadProps = ( a , b ) => _ _defProps ( a , _ _getOwnPropDescs ( b ) ) ;
var _ _markAsModule = ( target ) => _ _defProp ( target , "__esModule" , { value : true } ) ;
var _ _commonJS = ( cb , mod ) => function _ _require ( ) {
return mod || ( 0 , cb [ Object . keys ( cb ) [ 0 ] ] ) ( ( mod = { exports : { } } ) . exports , mod ) , mod . exports ;
} ;
var _ _export = ( target , all ) => {
_ _markAsModule ( target ) ;
for ( var name in all )
_ _defProp ( target , name , { get : all [ name ] , enumerable : true } ) ;
} ;
var _ _reExport = ( target , module2 , desc ) => {
if ( module2 && typeof module2 === "object" || typeof module2 === "function" ) {
for ( let key of _ _getOwnPropNames ( module2 ) )
if ( ! _ _hasOwnProp . call ( target , key ) && key !== "default" )
_ _defProp ( target , key , { get : ( ) => module2 [ key ] , enumerable : ! ( desc = _ _getOwnPropDesc ( module2 , key ) ) || desc . enumerable } ) ;
}
return target ;
} ;
var _ _toModule = ( module2 ) => {
return _ _reExport ( _ _markAsModule ( _ _defProp ( module2 != null ? _ _create ( _ _getProtoOf ( module2 ) ) : { } , "default" , module2 && module2 . _ _esModule && "default" in module2 ? { get : ( ) => module2 . default , enumerable : true } : { value : module2 , enumerable : true } ) ) , module2 ) ;
} ;
var _ _async = ( _ _this , _ _arguments , generator ) => {
return new Promise ( ( resolve , reject ) => {
var fulfilled = ( value ) => {
try {
step ( generator . next ( value ) ) ;
} catch ( e ) {
reject ( e ) ;
}
} ;
var rejected = ( value ) => {
try {
step ( generator . throw ( value ) ) ;
} catch ( e ) {
reject ( e ) ;
}
} ;
var step = ( x ) => x . done ? resolve ( x . value ) : Promise . resolve ( x . value ) . then ( fulfilled , rejected ) ;
step ( ( generator = generator . apply ( _ _this , _ _arguments ) ) . next ( ) ) ;
} ) ;
} ;
// node_modules/tslib/tslib.js
var require _tslib = _ _commonJS ( {
"node_modules/tslib/tslib.js" ( exports , module2 ) {
var _ _extends2 ;
var _ _assign2 ;
var _ _rest2 ;
var _ _decorate2 ;
var _ _param2 ;
var _ _metadata2 ;
var _ _awaiter2 ;
var _ _generator2 ;
var _ _exportStar2 ;
var _ _values2 ;
var _ _read2 ;
var _ _spread2 ;
var _ _spreadArrays2 ;
var _ _spreadArray2 ;
var _ _await2 ;
var _ _asyncGenerator2 ;
var _ _asyncDelegator2 ;
var _ _asyncValues2 ;
var _ _makeTemplateObject2 ;
var _ _importStar2 ;
var _ _importDefault2 ;
var _ _classPrivateFieldGet2 ;
var _ _classPrivateFieldSet2 ;
var _ _createBinding2 ;
( function ( factory ) {
var root = typeof global === "object" ? global : typeof self === "object" ? self : typeof this === "object" ? this : { } ;
if ( typeof define === "function" && define . amd ) {
define ( "tslib" , [ "exports" ] , function ( exports2 ) {
factory ( createExporter ( root , createExporter ( exports2 ) ) ) ;
} ) ;
} else if ( typeof module2 === "object" && typeof module2 . exports === "object" ) {
factory ( createExporter ( root , createExporter ( module2 . exports ) ) ) ;
} else {
factory ( createExporter ( root ) ) ;
}
function createExporter ( exports2 , previous ) {
if ( exports2 !== root ) {
if ( typeof Object . create === "function" ) {
Object . defineProperty ( exports2 , "__esModule" , { value : true } ) ;
} else {
exports2 . _ _esModule = true ;
}
}
return function ( id , v ) {
return exports2 [ id ] = previous ? previous ( id , v ) : v ;
} ;
}
} ) ( function ( exporter ) {
var extendStatics = Object . setPrototypeOf || { _ _proto _ _ : [ ] } instanceof Array && function ( d , b ) {
d . _ _proto _ _ = b ;
} || function ( d , b ) {
for ( var p in b )
if ( Object . prototype . hasOwnProperty . call ( b , p ) )
d [ p ] = b [ p ] ;
} ;
_ _extends2 = function ( d , b ) {
if ( typeof b !== "function" && b !== null )
throw new TypeError ( "Class extends value " + String ( b ) + " is not a constructor or null" ) ;
extendStatics ( d , b ) ;
function _ _ ( ) {
this . constructor = d ;
}
d . prototype = b === null ? Object . create ( b ) : ( _ _ . prototype = b . prototype , new _ _ ( ) ) ;
} ;
_ _assign2 = Object . assign || function ( t ) {
for ( var s , i = 1 , n = arguments . length ; i < n ; i ++ ) {
s = arguments [ i ] ;
for ( var p in s )
if ( Object . prototype . hasOwnProperty . call ( s , p ) )
t [ p ] = s [ p ] ;
}
return t ;
} ;
_ _rest2 = function ( s , e ) {
var t = { } ;
for ( var p in s )
if ( Object . prototype . hasOwnProperty . call ( s , p ) && e . indexOf ( p ) < 0 )
t [ p ] = s [ p ] ;
if ( s != null && typeof Object . getOwnPropertySymbols === "function" )
for ( var i = 0 , p = Object . getOwnPropertySymbols ( s ) ; i < p . length ; i ++ ) {
if ( e . indexOf ( p [ i ] ) < 0 && Object . prototype . propertyIsEnumerable . call ( s , p [ i ] ) )
t [ p [ i ] ] = s [ p [ i ] ] ;
}
return t ;
} ;
_ _decorate2 = function ( decorators , target , key , desc ) {
var c = arguments . length , r = c < 3 ? target : desc === null ? desc = Object . getOwnPropertyDescriptor ( target , key ) : desc , d ;
if ( typeof Reflect === "object" && typeof Reflect . decorate === "function" )
r = Reflect . decorate ( decorators , target , key , desc ) ;
else
for ( var i = decorators . length - 1 ; i >= 0 ; i -- )
if ( d = decorators [ i ] )
r = ( c < 3 ? d ( r ) : c > 3 ? d ( target , key , r ) : d ( target , key ) ) || r ;
return c > 3 && r && Object . defineProperty ( target , key , r ) , r ;
} ;
_ _param2 = function ( paramIndex , decorator ) {
return function ( target , key ) {
decorator ( target , key , paramIndex ) ;
} ;
} ;
_ _metadata2 = function ( metadataKey , metadataValue ) {
if ( typeof Reflect === "object" && typeof Reflect . metadata === "function" )
return Reflect . metadata ( metadataKey , metadataValue ) ;
} ;
_ _awaiter2 = function ( thisArg , _arguments , P , generator ) {
function adopt ( value ) {
return value instanceof P ? value : new P ( function ( resolve ) {
resolve ( value ) ;
} ) ;
}
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
function fulfilled ( value ) {
try {
step ( generator . next ( value ) ) ;
} catch ( e ) {
reject ( e ) ;
}
}
function rejected ( value ) {
try {
step ( generator [ "throw" ] ( value ) ) ;
} catch ( e ) {
reject ( e ) ;
}
}
function step ( result ) {
result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ;
}
step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
} ) ;
} ;
_ _generator2 = function ( thisArg , body ) {
var _ = { label : 0 , sent : function ( ) {
if ( t [ 0 ] & 1 )
throw t [ 1 ] ;
return t [ 1 ] ;
} , trys : [ ] , ops : [ ] } , f , y , t , g ;
return g = { next : verb ( 0 ) , "throw" : verb ( 1 ) , "return" : verb ( 2 ) } , typeof Symbol === "function" && ( g [ Symbol . iterator ] = function ( ) {
return this ;
} ) , g ;
function verb ( n ) {
return function ( v ) {
return step ( [ n , v ] ) ;
} ;
}
function step ( op ) {
if ( f )
throw new TypeError ( "Generator is already executing." ) ;
while ( _ )
try {
if ( f = 1 , y && ( t = op [ 0 ] & 2 ? y [ "return" ] : op [ 0 ] ? y [ "throw" ] || ( ( t = y [ "return" ] ) && t . call ( y ) , 0 ) : y . next ) && ! ( t = t . call ( y , op [ 1 ] ) ) . done )
return t ;
if ( y = 0 , t )
op = [ op [ 0 ] & 2 , t . value ] ;
switch ( op [ 0 ] ) {
case 0 :
case 1 :
t = op ;
break ;
case 4 :
_ . label ++ ;
return { value : op [ 1 ] , done : false } ;
case 5 :
_ . label ++ ;
y = op [ 1 ] ;
op = [ 0 ] ;
continue ;
case 7 :
op = _ . ops . pop ( ) ;
_ . trys . pop ( ) ;
continue ;
default :
if ( ! ( t = _ . trys , t = t . length > 0 && t [ t . length - 1 ] ) && ( op [ 0 ] === 6 || op [ 0 ] === 2 ) ) {
_ = 0 ;
continue ;
}
if ( op [ 0 ] === 3 && ( ! t || op [ 1 ] > t [ 0 ] && op [ 1 ] < t [ 3 ] ) ) {
_ . label = op [ 1 ] ;
break ;
}
if ( op [ 0 ] === 6 && _ . label < t [ 1 ] ) {
_ . label = t [ 1 ] ;
t = op ;
break ;
}
if ( t && _ . label < t [ 2 ] ) {
_ . label = t [ 2 ] ;
_ . ops . push ( op ) ;
break ;
}
if ( t [ 2 ] )
_ . ops . pop ( ) ;
_ . trys . pop ( ) ;
continue ;
}
op = body . call ( thisArg , _ ) ;
} catch ( e ) {
op = [ 6 , e ] ;
y = 0 ;
} finally {
f = t = 0 ;
}
if ( op [ 0 ] & 5 )
throw op [ 1 ] ;
return { value : op [ 0 ] ? op [ 1 ] : void 0 , done : true } ;
}
} ;
_ _exportStar2 = function ( m , o ) {
for ( var p in m )
if ( p !== "default" && ! Object . prototype . hasOwnProperty . call ( o , p ) )
_ _createBinding2 ( o , m , p ) ;
} ;
_ _createBinding2 = Object . create ? function ( o , m , k , k2 ) {
if ( k2 === void 0 )
k2 = k ;
Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) {
return m [ k ] ;
} } ) ;
} : function ( o , m , k , k2 ) {
if ( k2 === void 0 )
k2 = k ;
o [ k2 ] = m [ k ] ;
} ;
_ _values2 = function ( o ) {
var s = typeof Symbol === "function" && Symbol . iterator , m = s && o [ s ] , i = 0 ;
if ( m )
return m . call ( o ) ;
if ( o && typeof o . length === "number" )
return {
next : function ( ) {
if ( o && i >= o . length )
o = void 0 ;
return { value : o && o [ i ++ ] , done : ! o } ;
}
} ;
throw new TypeError ( s ? "Object is not iterable." : "Symbol.iterator is not defined." ) ;
} ;
_ _read2 = function ( o , n ) {
var m = typeof Symbol === "function" && o [ Symbol . iterator ] ;
if ( ! m )
return o ;
var i = m . call ( o ) , r , ar = [ ] , e ;
try {
while ( ( n === void 0 || n -- > 0 ) && ! ( r = i . next ( ) ) . done )
ar . push ( r . value ) ;
} catch ( error ) {
e = { error } ;
} finally {
try {
if ( r && ! r . done && ( m = i [ "return" ] ) )
m . call ( i ) ;
} finally {
if ( e )
throw e . error ;
}
}
return ar ;
} ;
_ _spread2 = function ( ) {
for ( var ar = [ ] , i = 0 ; i < arguments . length ; i ++ )
ar = ar . concat ( _ _read2 ( arguments [ i ] ) ) ;
return ar ;
} ;
_ _spreadArrays2 = function ( ) {
for ( var s = 0 , i = 0 , il = arguments . length ; i < il ; i ++ )
s += arguments [ i ] . length ;
for ( var r = Array ( s ) , k = 0 , i = 0 ; i < il ; i ++ )
for ( var a = arguments [ i ] , j = 0 , jl = a . length ; j < jl ; j ++ , k ++ )
r [ k ] = a [ j ] ;
return r ;
} ;
_ _spreadArray2 = function ( to , from , pack ) {
if ( pack || arguments . length === 2 )
for ( var i = 0 , l = from . length , ar ; i < l ; i ++ ) {
if ( ar || ! ( i in from ) ) {
if ( ! ar )
ar = Array . prototype . slice . call ( from , 0 , i ) ;
ar [ i ] = from [ i ] ;
}
}
return to . concat ( ar || Array . prototype . slice . call ( from ) ) ;
} ;
_ _await2 = function ( v ) {
return this instanceof _ _await2 ? ( this . v = v , this ) : new _ _await2 ( v ) ;
} ;
_ _asyncGenerator2 = function ( thisArg , _arguments , generator ) {
if ( ! Symbol . asyncIterator )
throw new TypeError ( "Symbol.asyncIterator is not defined." ) ;
var g = generator . apply ( thisArg , _arguments || [ ] ) , i , q = [ ] ;
return i = { } , verb ( "next" ) , verb ( "throw" ) , verb ( "return" ) , i [ Symbol . asyncIterator ] = function ( ) {
return this ;
} , i ;
function verb ( n ) {
if ( g [ n ] )
i [ n ] = function ( v ) {
return new Promise ( function ( a , b ) {
q . push ( [ n , v , a , b ] ) > 1 || resume ( n , v ) ;
} ) ;
} ;
}
function resume ( n , v ) {
try {
step ( g [ n ] ( v ) ) ;
} catch ( e ) {
settle ( q [ 0 ] [ 3 ] , e ) ;
}
}
function step ( r ) {
r . value instanceof _ _await2 ? Promise . resolve ( r . value . v ) . then ( fulfill , reject ) : settle ( q [ 0 ] [ 2 ] , r ) ;
}
function fulfill ( value ) {
resume ( "next" , value ) ;
}
function reject ( value ) {
resume ( "throw" , value ) ;
}
function settle ( f , v ) {
if ( f ( v ) , q . shift ( ) , q . length )
resume ( q [ 0 ] [ 0 ] , q [ 0 ] [ 1 ] ) ;
}
} ;
_ _asyncDelegator2 = function ( o ) {
var i , p ;
return i = { } , verb ( "next" ) , verb ( "throw" , function ( e ) {
throw e ;
} ) , verb ( "return" ) , i [ Symbol . iterator ] = function ( ) {
return this ;
} , i ;
function verb ( n , f ) {
i [ n ] = o [ n ] ? function ( v ) {
return ( p = ! p ) ? { value : _ _await2 ( o [ n ] ( v ) ) , done : n === "return" } : f ? f ( v ) : v ;
} : f ;
}
} ;
_ _asyncValues2 = function ( o ) {
if ( ! Symbol . asyncIterator )
throw new TypeError ( "Symbol.asyncIterator is not defined." ) ;
var m = o [ Symbol . asyncIterator ] , i ;
return m ? m . call ( o ) : ( o = typeof _ _values2 === "function" ? _ _values2 ( o ) : o [ Symbol . iterator ] ( ) , i = { } , verb ( "next" ) , verb ( "throw" ) , verb ( "return" ) , i [ Symbol . asyncIterator ] = function ( ) {
return this ;
} , i ) ;
function verb ( n ) {
i [ n ] = o [ n ] && function ( v ) {
return new Promise ( function ( resolve , reject ) {
v = o [ n ] ( v ) , settle ( resolve , reject , v . done , v . value ) ;
} ) ;
} ;
}
function settle ( resolve , reject , d , v ) {
Promise . resolve ( v ) . then ( function ( v2 ) {
resolve ( { value : v2 , done : d } ) ;
} , reject ) ;
}
} ;
_ _makeTemplateObject2 = function ( cooked , raw ) {
if ( Object . defineProperty ) {
Object . defineProperty ( cooked , "raw" , { value : raw } ) ;
} else {
cooked . raw = raw ;
}
return cooked ;
} ;
var _ _setModuleDefault = Object . create ? function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} : function ( o , v ) {
o [ "default" ] = v ;
} ;
_ _importStar2 = function ( mod ) {
if ( mod && mod . _ _esModule )
return mod ;
var result = { } ;
if ( mod != null ) {
for ( var k in mod )
if ( k !== "default" && Object . prototype . hasOwnProperty . call ( mod , k ) )
_ _createBinding2 ( result , mod , k ) ;
}
_ _setModuleDefault ( result , mod ) ;
return result ;
} ;
_ _importDefault2 = function ( mod ) {
return mod && mod . _ _esModule ? mod : { "default" : mod } ;
} ;
_ _classPrivateFieldGet2 = function ( receiver , state , kind , f ) {
if ( kind === "a" && ! f )
throw new TypeError ( "Private accessor was defined without a getter" ) ;
if ( typeof state === "function" ? receiver !== state || ! f : ! state . has ( receiver ) )
throw new TypeError ( "Cannot read private member from an object whose class did not declare it" ) ;
return kind === "m" ? f : kind === "a" ? f . call ( receiver ) : f ? f . value : state . get ( receiver ) ;
} ;
_ _classPrivateFieldSet2 = function ( receiver , state , value , kind , f ) {
if ( kind === "m" )
throw new TypeError ( "Private method is not writable" ) ;
if ( kind === "a" && ! f )
throw new TypeError ( "Private accessor was defined without a setter" ) ;
if ( typeof state === "function" ? receiver !== state || ! f : ! state . has ( receiver ) )
throw new TypeError ( "Cannot write private member to an object whose class did not declare it" ) ;
return kind === "a" ? f . call ( receiver , value ) : f ? f . value = value : state . set ( receiver , value ) , value ;
} ;
exporter ( "__extends" , _ _extends2 ) ;
exporter ( "__assign" , _ _assign2 ) ;
exporter ( "__rest" , _ _rest2 ) ;
exporter ( "__decorate" , _ _decorate2 ) ;
exporter ( "__param" , _ _param2 ) ;
exporter ( "__metadata" , _ _metadata2 ) ;
exporter ( "__awaiter" , _ _awaiter2 ) ;
exporter ( "__generator" , _ _generator2 ) ;
exporter ( "__exportStar" , _ _exportStar2 ) ;
exporter ( "__createBinding" , _ _createBinding2 ) ;
exporter ( "__values" , _ _values2 ) ;
exporter ( "__read" , _ _read2 ) ;
exporter ( "__spread" , _ _spread2 ) ;
exporter ( "__spreadArrays" , _ _spreadArrays2 ) ;
exporter ( "__spreadArray" , _ _spreadArray2 ) ;
exporter ( "__await" , _ _await2 ) ;
exporter ( "__asyncGenerator" , _ _asyncGenerator2 ) ;
exporter ( "__asyncDelegator" , _ _asyncDelegator2 ) ;
exporter ( "__asyncValues" , _ _asyncValues2 ) ;
exporter ( "__makeTemplateObject" , _ _makeTemplateObject2 ) ;
exporter ( "__importStar" , _ _importStar2 ) ;
exporter ( "__importDefault" , _ _importDefault2 ) ;
exporter ( "__classPrivateFieldGet" , _ _classPrivateFieldGet2 ) ;
exporter ( "__classPrivateFieldSet" , _ _classPrivateFieldSet2 ) ;
} ) ;
}
} ) ;
// src/main.ts
_ _export ( exports , {
default : ( ) => CoreSearchAssistantPlugin
} ) ;
// src/Events.ts
var import _obsidian = _ _toModule ( require ( "obsidian" ) ) ;
var EVENT _SEARCH _RESULT _ITEM _DETECTED = "search-result-item-detected" ;
var EVENT _SORT _ORDER _CHANGED = "sort-order-changed" ;
var CoreSearchAssistantEvents = class extends import _obsidian . Events {
trigger ( name , ... data ) {
super . trigger ( name , ... data ) ;
}
on ( name , callback , ctx ) {
return super . on ( name , callback , ctx ) ;
}
} ;
// src/Controller.ts
var obsidian = _ _toModule ( require ( "obsidian" ) ) ;
// src/components/OptionModal.ts
var import _obsidian2 = _ _toModule ( require ( "obsidian" ) ) ;
// src/types/Option.ts
var searchOptions = {
matchingCase : {
iconId : "uppercase-lowercase-a" ,
description : "Toggle matching case"
} ,
explainSearch : {
iconId : "info" ,
description : "Toggle explanation of search term"
} ,
collapseAll : {
iconId : "bullet-list" ,
description : "Toggle collapsing results"
} ,
extraContext : {
iconId : "expand-vertically" ,
description : "Toggle showing more context"
} ,
alphabetical : {
iconId : "down-arrow-with-tail" ,
description : "Sort by file name (A \u2192 Z)"
} ,
alphabeticalReverse : {
iconId : "up-arrow-with-tail" ,
description : "Sort by file name (Z \u2192 A)"
} ,
byModifiedTime : {
iconId : "down-arrow-with-tail" ,
description : "Sort by modified time (new \u2192 old)"
} ,
byModifiedTimeReverse : {
iconId : "up-arrow-with-tail" ,
description : "Sort by modified time (old \u2192 new)"
} ,
byCreatedTime : {
iconId : "down-arrow-with-tail" ,
description : "Sort by created time (new \u2192 old)"
} ,
byCreatedTimeReverse : {
iconId : "up-arrow-with-tail" ,
description : "Sort by created time (old \u2192 new)"
}
} ;
// src/components/OptionModal.ts
var OptionModal = class extends import _obsidian2 . Modal {
constructor ( app2 , plugin2 , modeScope ) {
super ( app2 ) ;
this . plugin = plugin2 ;
this . modeScope = modeScope ;
this . items = [
{
id : "matchingCase" ,
key : "a" ,
onChoose : ( ) => {
var _a , _b , _c ;
( _a = this . plugin . searchInterface ) == null ? void 0 : _a . toggleMatchingCase ( ) ;
( _b = this . plugin . searchInterface ) == null ? void 0 : _b . renewSortOrderInfo ( ) ;
( _c = this . plugin . controller ) == null ? void 0 : _c . reset ( ) ;
}
} ,
{
id : "explainSearch" ,
key : "s" ,
onChoose : ( ) => {
var _a ;
( _a = this . plugin . searchInterface ) == null ? void 0 : _a . toggleExplainSearch ( ) ;
}
} ,
{
id : "collapseAll" ,
key : "d" ,
onChoose : ( ) => {
var _a ;
( _a = this . plugin . searchInterface ) == null ? void 0 : _a . toggleCollapseAll ( ) ;
}
} ,
{
id : "extraContext" ,
key : "f" ,
onChoose : ( ) => {
var _a ;
( _a = this . plugin . searchInterface ) == null ? void 0 : _a . toggleExtraContext ( ) ;
}
} ,
{
id : "alphabetical" ,
key : "g" ,
onChoose : ( ) => {
var _a , _b , _c ;
const changed = ( _a = this . plugin . searchInterface ) == null ? void 0 : _a . setSortOrder ( "alphabetical" ) ;
if ( changed ) {
( _b = this . plugin . searchInterface ) == null ? void 0 : _b . renewSortOrderInfo ( ) ;
( _c = this . plugin . controller ) == null ? void 0 : _c . reset ( ) ;
}
}
} ,
{
id : "alphabeticalReverse" ,
key : "h" ,
onChoose : ( ) => {
var _a , _b , _c ;
const changed = ( _a = this . plugin . searchInterface ) == null ? void 0 : _a . setSortOrder ( "alphabeticalReverse" ) ;
if ( changed ) {
( _b = this . plugin . searchInterface ) == null ? void 0 : _b . renewSortOrderInfo ( ) ;
( _c = this . plugin . controller ) == null ? void 0 : _c . reset ( ) ;
}
}
} ,
{
id : "byModifiedTime" ,
key : "j" ,
onChoose : ( ) => {
var _a , _b , _c ;
const changed = ( _a = this . plugin . searchInterface ) == null ? void 0 : _a . setSortOrder ( "byModifiedTime" ) ;
if ( changed ) {
( _b = this . plugin . searchInterface ) == null ? void 0 : _b . renewSortOrderInfo ( ) ;
( _c = this . plugin . controller ) == null ? void 0 : _c . reset ( ) ;
}
}
} ,
{
id : "byModifiedTimeReverse" ,
key : "k" ,
onChoose : ( ) => {
var _a , _b , _c ;
const changed = ( _a = this . plugin . searchInterface ) == null ? void 0 : _a . setSortOrder ( "byModifiedTimeReverse" ) ;
if ( changed ) {
( _b = this . plugin . searchInterface ) == null ? void 0 : _b . renewSortOrderInfo ( ) ;
( _c = this . plugin . controller ) == null ? void 0 : _c . reset ( ) ;
}
}
} ,
{
id : "byCreatedTime" ,
key : "l" ,
onChoose : ( ) => {
var _a , _b , _c ;
const changed = ( _a = this . plugin . searchInterface ) == null ? void 0 : _a . setSortOrder ( "byCreatedTime" ) ;
if ( changed ) {
( _b = this . plugin . searchInterface ) == null ? void 0 : _b . renewSortOrderInfo ( ) ;
( _c = this . plugin . controller ) == null ? void 0 : _c . reset ( ) ;
}
}
} ,
{
id : "byCreatedTimeReverse" ,
key : ";" ,
onChoose : ( ) => {
var _a , _b , _c ;
const changed = ( _a = this . plugin . searchInterface ) == null ? void 0 : _a . setSortOrder ( "byCreatedTimeReverse" ) ;
if ( changed ) {
( _b = this . plugin . searchInterface ) == null ? void 0 : _b . renewSortOrderInfo ( ) ;
( _c = this . plugin . controller ) == null ? void 0 : _c . reset ( ) ;
}
}
}
] ;
}
onOpen ( ) {
this . modeScope . push ( ) ;
this . items . forEach ( ( item ) => {
this . scope . register ( [ ] , item . key , item . onChoose ) ;
} ) ;
this . renderOptions ( ) ;
}
onClose ( ) {
const { containerEl } = this ;
containerEl . empty ( ) ;
setTimeout ( ( ) => this . modeScope . pop ( ) , 100 ) ;
}
renderOptions ( ) {
const { contentEl } = this ;
contentEl . empty ( ) ;
this . containerEl . addClass ( "core-search-assistant_option-modal" ) ;
this . items . forEach ( ( item ) => {
const entryEl = contentEl . createEl ( "div" , {
cls : "suggestion-item"
} ) ;
const iconEl = entryEl . createEl ( "span" , {
cls : "suggestion-icon"
} ) ;
( 0 , import _obsidian2 . setIcon ) ( iconEl , searchOptions [ item . id ] . iconId ) ;
entryEl . createEl ( "span" , {
text : searchOptions [ item . id ] . description ,
cls : "suggestion-content"
} ) ;
entryEl . createEl ( "kbd" , {
text : item . key . toUpperCase ( ) ,
cls : "suggestion-hotkey"
} ) ;
} ) ;
}
} ;
// src/Setting.ts
var import _obsidian7 = _ _toModule ( require ( "obsidian" ) ) ;
// src/ui/HotkeySetter.ts
var import _obsidian6 = _ _toModule ( require ( "obsidian" ) ) ;
// node_modules/svelte/internal/index.mjs
function noop ( ) {
}
function run ( fn ) {
return fn ( ) ;
}
function blank _object ( ) {
return Object . create ( null ) ;
}
function run _all ( fns ) {
fns . forEach ( run ) ;
}
function is _function ( thing ) {
return typeof thing === "function" ;
}
function safe _not _equal ( a , b ) {
return a != a ? b == b : a !== b || ( a && typeof a === "object" || typeof a === "function" ) ;
}
function is _empty ( obj ) {
return Object . keys ( obj ) . length === 0 ;
}
function subscribe ( store2 , ... callbacks ) {
if ( store2 == null ) {
return noop ;
}
const unsub = store2 . subscribe ( ... callbacks ) ;
return unsub . unsubscribe ? ( ) => unsub . unsubscribe ( ) : unsub ;
}
function component _subscribe ( component , store2 , callback ) {
component . $$ . on _destroy . push ( subscribe ( store2 , callback ) ) ;
}
var tasks = new Set ( ) ;
var is _hydrating = false ;
function start _hydrating ( ) {
is _hydrating = true ;
}
function end _hydrating ( ) {
is _hydrating = false ;
}
function append ( target , node ) {
target . appendChild ( node ) ;
}
function append _styles ( target , style _sheet _id , styles ) {
const append _styles _to = get _root _for _style ( target ) ;
if ( ! append _styles _to . getElementById ( style _sheet _id ) ) {
const style = element ( "style" ) ;
style . id = style _sheet _id ;
style . textContent = styles ;
append _stylesheet ( append _styles _to , style ) ;
}
}
function get _root _for _style ( node ) {
if ( ! node )
return document ;
const root = node . getRootNode ? node . getRootNode ( ) : node . ownerDocument ;
if ( root && root . host ) {
return root ;
}
return node . ownerDocument ;
}
function append _stylesheet ( node , style ) {
append ( node . head || node , style ) ;
}
function insert ( target , node , anchor ) {
target . insertBefore ( node , anchor || null ) ;
}
function detach ( node ) {
node . parentNode . removeChild ( node ) ;
}
function destroy _each ( iterations , detaching ) {
for ( let i = 0 ; i < iterations . length ; i += 1 ) {
if ( iterations [ i ] )
iterations [ i ] . d ( detaching ) ;
}
}
function element ( name ) {
return document . createElement ( name ) ;
}
function text ( data ) {
return document . createTextNode ( data ) ;
}
function space ( ) {
return text ( " " ) ;
}
function listen ( node , event , handler , options ) {
node . addEventListener ( event , handler , options ) ;
return ( ) => node . removeEventListener ( event , handler , options ) ;
}
function attr ( node , attribute , value ) {
if ( value == null )
node . removeAttribute ( attribute ) ;
else if ( node . getAttribute ( attribute ) !== value )
node . setAttribute ( attribute , value ) ;
}
function children ( element2 ) {
return Array . from ( element2 . childNodes ) ;
}
function set _data ( text2 , data ) {
data = "" + data ;
if ( text2 . wholeText !== data )
text2 . data = data ;
}
function toggle _class ( element2 , name , toggle ) {
element2 . classList [ toggle ? "add" : "remove" ] ( name ) ;
}
function custom _event ( type , detail , bubbles = false ) {
const e = document . createEvent ( "CustomEvent" ) ;
e . initCustomEvent ( type , bubbles , false , detail ) ;
return e ;
}
var managed _styles = new Map ( ) ;
var current _component ;
function set _current _component ( component ) {
current _component = component ;
}
function get _current _component ( ) {
if ( ! current _component )
throw new Error ( "Function called outside component initialization" ) ;
return current _component ;
}
function onMount ( fn ) {
get _current _component ( ) . $$ . on _mount . push ( fn ) ;
}
function onDestroy ( fn ) {
get _current _component ( ) . $$ . on _destroy . push ( fn ) ;
}
function createEventDispatcher ( ) {
const component = get _current _component ( ) ;
return ( type , detail ) => {
const callbacks = component . $$ . callbacks [ type ] ;
if ( callbacks ) {
const event = custom _event ( type , detail ) ;
callbacks . slice ( ) . forEach ( ( fn ) => {
fn . call ( component , event ) ;
} ) ;
}
} ;
}
var dirty _components = [ ] ;
var binding _callbacks = [ ] ;
var render _callbacks = [ ] ;
var flush _callbacks = [ ] ;
var resolved _promise = Promise . resolve ( ) ;
var update _scheduled = false ;
function schedule _update ( ) {
if ( ! update _scheduled ) {
update _scheduled = true ;
resolved _promise . then ( flush ) ;
}
}
function add _render _callback ( fn ) {
render _callbacks . push ( fn ) ;
}
var seen _callbacks = new Set ( ) ;
var flushidx = 0 ;
function flush ( ) {
const saved _component = current _component ;
do {
while ( flushidx < dirty _components . length ) {
const component = dirty _components [ flushidx ] ;
flushidx ++ ;
set _current _component ( component ) ;
update ( component . $$ ) ;
}
set _current _component ( null ) ;
dirty _components . length = 0 ;
flushidx = 0 ;
while ( binding _callbacks . length )
binding _callbacks . pop ( ) ( ) ;
for ( let i = 0 ; i < render _callbacks . length ; i += 1 ) {
const callback = render _callbacks [ i ] ;
if ( ! seen _callbacks . has ( callback ) ) {
seen _callbacks . add ( callback ) ;
callback ( ) ;
}
}
render _callbacks . length = 0 ;
} while ( dirty _components . length ) ;
while ( flush _callbacks . length ) {
flush _callbacks . pop ( ) ( ) ;
}
update _scheduled = false ;
seen _callbacks . clear ( ) ;
set _current _component ( saved _component ) ;
}
function update ( $$ ) {
if ( $$ . fragment !== null ) {
$$ . update ( ) ;
run _all ( $$ . before _update ) ;
const dirty = $$ . dirty ;
$$ . dirty = [ - 1 ] ;
$$ . fragment && $$ . fragment . p ( $$ . ctx , dirty ) ;
$$ . after _update . forEach ( add _render _callback ) ;
}
}
var outroing = new Set ( ) ;
var outros ;
function group _outros ( ) {
outros = {
r : 0 ,
c : [ ] ,
p : outros
} ;
}
function check _outros ( ) {
if ( ! outros . r ) {
run _all ( outros . c ) ;
}
outros = outros . p ;
}
function transition _in ( block , local ) {
if ( block && block . i ) {
outroing . delete ( block ) ;
block . i ( local ) ;
}
}
function transition _out ( block , local , detach2 , callback ) {
if ( block && block . o ) {
if ( outroing . has ( block ) )
return ;
outroing . add ( block ) ;
outros . c . push ( ( ) => {
outroing . delete ( block ) ;
if ( callback ) {
if ( detach2 )
block . d ( 1 ) ;
callback ( ) ;
}
} ) ;
block . o ( local ) ;
}
}
var globals = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : global ;
var boolean _attributes = new Set ( [
"allowfullscreen" ,
"allowpaymentrequest" ,
"async" ,
"autofocus" ,
"autoplay" ,
"checked" ,
"controls" ,
"default" ,
"defer" ,
"disabled" ,
"formnovalidate" ,
"hidden" ,
"ismap" ,
"loop" ,
"multiple" ,
"muted" ,
"nomodule" ,
"novalidate" ,
"open" ,
"playsinline" ,
"readonly" ,
"required" ,
"reversed" ,
"selected"
] ) ;
function create _component ( block ) {
block && block . c ( ) ;
}
function mount _component ( component , target , anchor , customElement ) {
const { fragment , on _mount , on _destroy , after _update } = component . $$ ;
fragment && fragment . m ( target , anchor ) ;
if ( ! customElement ) {
add _render _callback ( ( ) => {
const new _on _destroy = on _mount . map ( run ) . filter ( is _function ) ;
if ( on _destroy ) {
on _destroy . push ( ... new _on _destroy ) ;
} else {
run _all ( new _on _destroy ) ;
}
component . $$ . on _mount = [ ] ;
} ) ;
}
after _update . forEach ( add _render _callback ) ;
}
function destroy _component ( component , detaching ) {
const $$ = component . $$ ;
if ( $$ . fragment !== null ) {
run _all ( $$ . on _destroy ) ;
$$ . fragment && $$ . fragment . d ( detaching ) ;
$$ . on _destroy = $$ . fragment = null ;
$$ . ctx = [ ] ;
}
}
function make _dirty ( component , i ) {
if ( component . $$ . dirty [ 0 ] === - 1 ) {
dirty _components . push ( component ) ;
schedule _update ( ) ;
component . $$ . dirty . fill ( 0 ) ;
}
component . $$ . dirty [ i / 31 | 0 ] |= 1 << i % 31 ;
}
function init ( component , options , instance8 , create _fragment8 , not _equal , props , append _styles2 , dirty = [ - 1 ] ) {
const parent _component = current _component ;
set _current _component ( component ) ;
const $$ = component . $$ = {
fragment : null ,
ctx : null ,
props ,
update : noop ,
not _equal ,
bound : blank _object ( ) ,
on _mount : [ ] ,
on _destroy : [ ] ,
on _disconnect : [ ] ,
before _update : [ ] ,
after _update : [ ] ,
context : new Map ( options . context || ( parent _component ? parent _component . $$ . context : [ ] ) ) ,
callbacks : blank _object ( ) ,
dirty ,
skip _bound : false ,
root : options . target || parent _component . $$ . root
} ;
append _styles2 && append _styles2 ( $$ . root ) ;
let ready = false ;
$$ . ctx = instance8 ? instance8 ( component , options . props || { } , ( i , ret , ... rest ) => {
const value = rest . length ? rest [ 0 ] : ret ;
if ( $$ . ctx && not _equal ( $$ . ctx [ i ] , $$ . ctx [ i ] = value ) ) {
if ( ! $$ . skip _bound && $$ . bound [ i ] )
$$ . bound [ i ] ( value ) ;
if ( ready )
make _dirty ( component , i ) ;
}
return ret ;
} ) : [ ] ;
$$ . update ( ) ;
ready = true ;
run _all ( $$ . before _update ) ;
$$ . fragment = create _fragment8 ? create _fragment8 ( $$ . ctx ) : false ;
if ( options . target ) {
if ( options . hydrate ) {
start _hydrating ( ) ;
const nodes = children ( options . target ) ;
$$ . fragment && $$ . fragment . l ( nodes ) ;
nodes . forEach ( detach ) ;
} else {
$$ . fragment && $$ . fragment . c ( ) ;
}
if ( options . intro )
transition _in ( component . $$ . fragment ) ;
mount _component ( component , options . target , options . anchor , options . customElement ) ;
end _hydrating ( ) ;
flush ( ) ;
}
set _current _component ( parent _component ) ;
}
var SvelteElement ;
if ( typeof HTMLElement === "function" ) {
SvelteElement = class extends HTMLElement {
constructor ( ) {
super ( ) ;
this . attachShadow ( { mode : "open" } ) ;
}
connectedCallback ( ) {
const { on _mount } = this . $$ ;
this . $$ . on _disconnect = on _mount . map ( run ) . filter ( is _function ) ;
for ( const key in this . $$ . slotted ) {
this . appendChild ( this . $$ . slotted [ key ] ) ;
}
}
attributeChangedCallback ( attr2 , _oldValue , newValue ) {
this [ attr2 ] = newValue ;
}
disconnectedCallback ( ) {
run _all ( this . $$ . on _disconnect ) ;
}
$destroy ( ) {
destroy _component ( this , 1 ) ;
this . $destroy = noop ;
}
$on ( type , callback ) {
const callbacks = this . $$ . callbacks [ type ] || ( this . $$ . callbacks [ type ] = [ ] ) ;
callbacks . push ( callback ) ;
return ( ) => {
const index = callbacks . indexOf ( callback ) ;
if ( index !== - 1 )
callbacks . splice ( index , 1 ) ;
} ;
}
$set ( $$props ) {
if ( this . $$set && ! is _empty ( $$props ) ) {
this . $$ . skip _bound = true ;
this . $$set ( $$props ) ;
this . $$ . skip _bound = false ;
}
}
} ;
}
var SvelteComponent = class {
$destroy ( ) {
destroy _component ( this , 1 ) ;
this . $destroy = noop ;
}
$on ( type , callback ) {
const callbacks = this . $$ . callbacks [ type ] || ( this . $$ . callbacks [ type ] = [ ] ) ;
callbacks . push ( callback ) ;
return ( ) => {
const index = callbacks . indexOf ( callback ) ;
if ( index !== - 1 )
callbacks . splice ( index , 1 ) ;
} ;
}
$set ( $$props ) {
if ( this . $$set && ! is _empty ( $$props ) ) {
this . $$ . skip _bound = true ;
this . $$set ( $$props ) ;
this . $$ . skip _bound = false ;
}
}
} ;
// src/ui/HotkeyEntry.svelte
var import _obsidian5 = _ _toModule ( require ( "obsidian" ) ) ;
// src/ui/HotkeySetting.svelte
var import _obsidian4 = _ _toModule ( require ( "obsidian" ) ) ;
// src/utils/Keymap.ts
var import _obsidian3 = _ _toModule ( require ( "obsidian" ) ) ;
var CODE _KEY _MAP = {
Semicolon : ";" ,
Quote : "'" ,
Comma : "," ,
Period : "." ,
Slash : "/" ,
BracketLeft : "[" ,
BracketRight : "]" ,
BackSlash : "\\" ,
Backquote : "`" ,
Space : " " ,
Minus : "-" ,
Equal : "="
} ;
for ( let i = 0 ; i < 10 ; i ++ ) {
CODE _KEY _MAP [ ` Digit ${ i } ` ] = i . toString ( ) ;
}
for ( let i = 65 ; i < 91 ; i ++ ) {
const char = String . fromCharCode ( i ) ;
const upChar = char . toUpperCase ( ) ;
CODE _KEY _MAP [ ` Key ${ upChar } ` ] = char ;
}
function convertCodeToKey ( code ) {
var _a ;
return ( _a = CODE _KEY _MAP [ code ] ) != null ? _a : code ;
}
function convertKeyToText ( key ) {
switch ( key ) {
case "ArrowLeft" :
return "\u2190" ;
case "ArrowRight" :
return "\u2192" ;
case "ArrowUp" :
return "\u2191" ;
case "ArrowDown" :
return "\u2193" ;
case "Mod" :
return import _obsidian3 . Platform . isMacOS ? "\u2318" : "Ctrl" ;
case "Ctrl" :
return import _obsidian3 . Platform . isMacOS ? "\u2303" : "Ctrl" ;
case "Meta" :
return import _obsidian3 . Platform . isMacOS ? "\u2318" : "Win" ;
case "Alt" :
return import _obsidian3 . Platform . isMacOS ? "\u2325" : "Alt" ;
case "Shift" :
return import _obsidian3 . Platform . isMacOS ? "\u21E7" : "Shift" ;
case " " :
return "Space" ;
case "Enter" :
return "\u21B5" ;
default :
return key . charAt ( 0 ) . toUpperCase ( ) + key . slice ( 1 ) ;
}
}
function convertHotkeyToText ( hotkey ) {
const parts = [ ] ;
hotkey . modifiers . forEach ( ( mod ) => {
parts . push ( convertKeyToText ( mod ) ) ;
} ) ;
const modifierPart = parts . join ( " " ) ;
const keyPart = convertKeyToText ( hotkey . key ) ;
return ` ${ modifierPart } ${ keyPart } ` ;
}
function compileModifiers ( modifiers ) {
return modifiers . map ( ( modifier ) => {
return modifier === "Mod" ? import _obsidian3 . Platform . isMacOS ? "Meta" : "Ctrl" : modifier ;
} ) . sort ( ) . join ( "," ) ;
}
function decompileModifiers ( modifiersId ) {
const modifiers = [ ] ;
const parts = modifiersId . split ( "," ) ;
parts . forEach ( ( s ) => {
if ( import _obsidian3 . Platform . isMacOS && s === "Meta" || ! import _obsidian3 . Platform . isMacOS && s === "Ctrl" ) {
modifiers . push ( "Mod" ) ;
return ;
}
if ( s === "Alt" || s === "Shift" || s === "Meta" || s === "Ctrl" ) {
modifiers . push ( s ) ;
return ;
}
} ) ;
return modifiers ;
}
function getModifiers ( evt ) {
const modifiers = [ ] ;
evt . ctrlKey && modifiers . push ( "Ctrl" ) ;
evt . metaKey && modifiers . push ( "Meta" ) ;
evt . altKey && modifiers . push ( "Alt" ) ;
evt . shiftKey && modifiers . push ( "Shift" ) ;
return compileModifiers ( modifiers ) ;
}
function getHotkey ( evt ) {
const modifiers = decompileModifiers ( getModifiers ( evt ) ) ;
const key = convertCodeToKey ( evt . code ) ;
return {
modifiers ,
key
} ;
}
function contain ( hotkeys , hotkey ) {
const hotkeyId = convertHotkeyToText ( hotkey ) ;
return hotkeys . some ( ( key ) => {
return hotkeyId === convertHotkeyToText ( key ) ;
} ) ;
}
// src/ui/HotkeySetting.svelte
function add _css ( target ) {
append _styles ( target , "svelte-2wacg2" , ".icon-container.svelte-2wacg2{display:inline-block;cursor:pointer;width:16px;height:16px;border-radius:10px;line-height:16px;text-align:center}.icon-container.svelte-2wacg2:hover{background-color:var(--background-modifier-error);color:var(--text-on-accent)}.setting-hotkey.svelte-2wacg2{font-size:12px;background-color:var(--background-secondary-alt);border-radius:4px;padding:0 10px;min-height:24px;align-self:flex-end;position:relative}" ) ;
}
function create _fragment ( ctx ) {
let span1 ;
let t0 _value = convertHotkeyToText ( ctx [ 0 ] ) + "" ;
let t0 ;
let t1 ;
let span0 ;
let mounted ;
let dispose ;
return {
c ( ) {
span1 = element ( "span" ) ;
t0 = text ( t0 _value ) ;
t1 = space ( ) ;
span0 = element ( "span" ) ;
attr ( span0 , "class" , "icon-container svelte-2wacg2" ) ;
attr ( span1 , "class" , "setting-hotkey svelte-2wacg2" ) ;
} ,
m ( target , anchor ) {
insert ( target , span1 , anchor ) ;
append ( span1 , t0 ) ;
append ( span1 , t1 ) ;
append ( span1 , span0 ) ;
ctx [ 3 ] ( span0 ) ;
if ( ! mounted ) {
dispose = listen ( span0 , "click" , ctx [ 2 ] ) ;
mounted = true ;
}
} ,
p ( ctx2 , [ dirty ] ) {
if ( dirty & 1 && t0 _value !== ( t0 _value = convertHotkeyToText ( ctx2 [ 0 ] ) + "" ) )
set _data ( t0 , t0 _value ) ;
} ,
i : noop ,
o : noop ,
d ( detaching ) {
if ( detaching )
detach ( span1 ) ;
ctx [ 3 ] ( null ) ;
mounted = false ;
dispose ( ) ;
}
} ;
}
function instance ( $$self , $$props , $$invalidate ) {
let { hotkey } = $$props ;
let iconContainerEl ;
const dispatcher = createEventDispatcher ( ) ;
onMount ( ( ) => {
if ( iconContainerEl instanceof HTMLSpanElement ) {
( 0 , import _obsidian4 . setIcon ) ( iconContainerEl , "cross" , 8 ) ;
}
} ) ;
function onIconClicked ( ) {
dispatcher ( "removed" ) ;
}
function span0 _binding ( $$value ) {
binding _callbacks [ $$value ? "unshift" : "push" ] ( ( ) => {
iconContainerEl = $$value ;
$$invalidate ( 1 , iconContainerEl ) ;
} ) ;
}
$$self . $$set = ( $$props2 ) => {
if ( "hotkey" in $$props2 )
$$invalidate ( 0 , hotkey = $$props2 . hotkey ) ;
} ;
return [ hotkey , iconContainerEl , onIconClicked , span0 _binding ] ;
}
var HotkeySetting = class extends SvelteComponent {
constructor ( options ) {
super ( ) ;
init ( this , options , instance , create _fragment , safe _not _equal , { hotkey : 0 } , add _css ) ;
}
} ;
var HotkeySetting _default = HotkeySetting ;
// src/ui/HotkeyEntry.svelte
function add _css2 ( target ) {
append _styles ( target , "svelte-1my40ui" , ".item-container.svelte-1my40ui{display:flex;align-items:center;padding:18px 0 18px 0;border-top:1px solid var(--background-modifier-border)}.info-container.svelte-1my40ui{flex:1 1 auto;flex-grow:1;margin-right:20px}.control-container.svelte-1my40ui{flex:1 1 auto;text-align:right;display:flex;justify-content:flex-end;align-items:center}.hotkeys-container.svelte-1my40ui{display:flex;flex-direction:column;margin-right:6px}.setting-hotkey.svelte-1my40ui{font-size:12px;background-color:var(--interactive-accent);border-radius:4px;padding:0 10px;min-height:24px;align-self:flex-end;position:relative;color:var(--text-on-accent)}.icon-container.svelte-1my40ui{padding:4px 6px;border-radius:4px;color:var(--text-faint);cursor:pointer;height:26px}.icon-container.svelte-1my40ui:hover{background-color:var(--background-secondary-alt);color:var(--text-normal)}.icon-container.svelte-1my40ui .clickable-icon{color:unset;cursor:unset;margin:unset}.icon-container.svelte-1my40ui .setting-editor-extra-setting-button{line-height:0}.icon-container.svelte-1my40ui .clickable-icon svg{position:relative;bottom:2px}" ) ;
}
function get _each _context ( ctx , list , i ) {
const child _ctx = ctx . slice ( ) ;
child _ctx [ 13 ] = list [ i ] ;
return child _ctx ;
}
function create _each _block ( ctx ) {
let hotkeysetting ;
let current ;
function removed _handler ( ) {
return ctx [ 8 ] ( ctx [ 13 ] ) ;
}
hotkeysetting = new HotkeySetting _default ( { props : { hotkey : ctx [ 13 ] } } ) ;
hotkeysetting . $on ( "removed" , removed _handler ) ;
return {
c ( ) {
create _component ( hotkeysetting . $$ . fragment ) ;
} ,
m ( target , anchor ) {
mount _component ( hotkeysetting , target , anchor ) ;
current = true ;
} ,
p ( new _ctx , dirty ) {
ctx = new _ctx ;
const hotkeysetting _changes = { } ;
if ( dirty & 16 )
hotkeysetting _changes . hotkey = ctx [ 13 ] ;
hotkeysetting . $set ( hotkeysetting _changes ) ;
} ,
i ( local ) {
if ( current )
return ;
transition _in ( hotkeysetting . $$ . fragment , local ) ;
current = true ;
} ,
o ( local ) {
transition _out ( hotkeysetting . $$ . fragment , local ) ;
current = false ;
} ,
d ( detaching ) {
destroy _component ( hotkeysetting , detaching ) ;
}
} ;
}
function create _if _block ( ctx ) {
let div ;
return {
c ( ) {
div = element ( "div" ) ;
div . textContent = "Press hotkey..." ;
attr ( div , "class" , "setting-hotkey svelte-1my40ui" ) ;
} ,
m ( target , anchor ) {
insert ( target , div , anchor ) ;
} ,
d ( detaching ) {
if ( detaching )
detach ( div ) ;
}
} ;
}
function create _fragment2 ( ctx ) {
var _a ;
let div3 ;
let div0 ;
let t0 ;
let t1 ;
let div2 ;
let div1 ;
let t2 ;
let t3 ;
let span0 ;
let t4 ;
let span1 ;
let current ;
let mounted ;
let dispose ;
let each _value = ( _a = ctx [ 4 ] ) != null ? _a : [ ] ;
let each _blocks = [ ] ;
for ( let i = 0 ; i < each _value . length ; i += 1 ) {
each _blocks [ i ] = create _each _block ( get _each _context ( ctx , each _value , i ) ) ;
}
const out = ( i ) => transition _out ( each _blocks [ i ] , 1 , 1 , ( ) => {
each _blocks [ i ] = null ;
} ) ;
let if _block = ctx [ 3 ] && create _if _block ( ctx ) ;
return {
c ( ) {
div3 = element ( "div" ) ;
div0 = element ( "div" ) ;
t0 = text ( ctx [ 0 ] ) ;
t1 = space ( ) ;
div2 = element ( "div" ) ;
div1 = element ( "div" ) ;
for ( let i = 0 ; i < each _blocks . length ; i += 1 ) {
each _blocks [ i ] . c ( ) ;
}
t2 = space ( ) ;
if ( if _block )
if _block . c ( ) ;
t3 = space ( ) ;
span0 = element ( "span" ) ;
t4 = space ( ) ;
span1 = element ( "span" ) ;
attr ( div0 , "class" , "info-container svelte-1my40ui" ) ;
attr ( div1 , "class" , "hotkeys-container svelte-1my40ui" ) ;
attr ( span0 , "class" , "icon-container svelte-1my40ui" ) ;
attr ( span1 , "class" , "icon-container svelte-1my40ui" ) ;
attr ( div2 , "class" , "control-container svelte-1my40ui" ) ;
attr ( div3 , "class" , "item-container svelte-1my40ui" ) ;
} ,
m ( target , anchor ) {
insert ( target , div3 , anchor ) ;
append ( div3 , div0 ) ;
append ( div0 , t0 ) ;
append ( div3 , t1 ) ;
append ( div3 , div2 ) ;
append ( div2 , div1 ) ;
for ( let i = 0 ; i < each _blocks . length ; i += 1 ) {
each _blocks [ i ] . m ( div1 , null ) ;
}
append ( div1 , t2 ) ;
if ( if _block )
if _block . m ( div1 , null ) ;
append ( div2 , t3 ) ;
append ( div2 , span0 ) ;
ctx [ 9 ] ( span0 ) ;
append ( div2 , t4 ) ;
append ( div2 , span1 ) ;
ctx [ 11 ] ( span1 ) ;
current = true ;
if ( ! mounted ) {
dispose = [
listen ( span0 , "click" , ctx [ 10 ] ) ,
listen ( span1 , "click" , ctx [ 12 ] )
] ;
mounted = true ;
}
} ,
p ( ctx2 , [ dirty ] ) {
var _a2 ;
if ( ! current || dirty & 1 )
set _data ( t0 , ctx2 [ 0 ] ) ;
if ( dirty & 48 ) {
each _value = ( _a2 = ctx2 [ 4 ] ) != null ? _a2 : [ ] ;
let i ;
for ( i = 0 ; i < each _value . length ; i += 1 ) {
const child _ctx = get _each _context ( ctx2 , each _value , i ) ;
if ( each _blocks [ i ] ) {
each _blocks [ i ] . p ( child _ctx , dirty ) ;
transition _in ( each _blocks [ i ] , 1 ) ;
} else {
each _blocks [ i ] = create _each _block ( child _ctx ) ;
each _blocks [ i ] . c ( ) ;
transition _in ( each _blocks [ i ] , 1 ) ;
each _blocks [ i ] . m ( div1 , t2 ) ;
}
}
group _outros ( ) ;
for ( i = each _value . length ; i < each _blocks . length ; i += 1 ) {
out ( i ) ;
}
check _outros ( ) ;
}
if ( ctx2 [ 3 ] ) {
if ( if _block ) {
} else {
if _block = create _if _block ( ctx2 ) ;
if _block . c ( ) ;
if _block . m ( div1 , null ) ;
}
} else if ( if _block ) {
if _block . d ( 1 ) ;
if _block = null ;
}
} ,
i ( local ) {
if ( current )
return ;
for ( let i = 0 ; i < each _value . length ; i += 1 ) {
transition _in ( each _blocks [ i ] ) ;
}
current = true ;
} ,
o ( local ) {
each _blocks = each _blocks . filter ( Boolean ) ;
for ( let i = 0 ; i < each _blocks . length ; i += 1 ) {
transition _out ( each _blocks [ i ] ) ;
}
current = false ;
} ,
d ( detaching ) {
if ( detaching )
detach ( div3 ) ;
destroy _each ( each _blocks , detaching ) ;
if ( if _block )
if _block . d ( ) ;
ctx [ 9 ] ( null ) ;
ctx [ 11 ] ( null ) ;
mounted = false ;
run _all ( dispose ) ;
}
} ;
}
var ICON _SIZE = 22 ;
function instance2 ( $$self , $$props , $$invalidate ) {
let _hotkeys ;
let _listening ;
let { actionName } = $$props ;
let { hotkeys } = $$props ;
let { listening = false } = $$props ;
let restoreButtonEl ;
let addHotkeyButtonEl ;
const dispatcher = createEventDispatcher ( ) ;
onMount ( ( ) => {
if ( restoreButtonEl ) {
const component = new import _obsidian5 . ExtraButtonComponent ( restoreButtonEl ) . setTooltip ( "Restore default" ) ;
( 0 , import _obsidian5 . setIcon ) ( component . extraSettingsEl , "reset" , ICON _SIZE ) ;
}
if ( addHotkeyButtonEl ) {
const component = new import _obsidian5 . ExtraButtonComponent ( addHotkeyButtonEl ) . setTooltip ( "Customize this action" ) ;
( 0 , import _obsidian5 . setIcon ) ( component . extraSettingsEl , "any-key" , ICON _SIZE ) ;
}
} ) ;
const removed _handler = ( hotkey ) => {
dispatcher ( "removed" , { removed : hotkey } ) ;
} ;
function span0 _binding ( $$value ) {
binding _callbacks [ $$value ? "unshift" : "push" ] ( ( ) => {
restoreButtonEl = $$value ;
$$invalidate ( 1 , restoreButtonEl ) ;
} ) ;
}
const click _handler = ( ) => {
dispatcher ( "restored" ) ;
} ;
function span1 _binding ( $$value ) {
binding _callbacks [ $$value ? "unshift" : "push" ] ( ( ) => {
addHotkeyButtonEl = $$value ;
$$invalidate ( 2 , addHotkeyButtonEl ) ;
} ) ;
}
const click _handler _1 = ( ) => {
dispatcher ( "start-listening-keys" ) ;
} ;
$$self . $$set = ( $$props2 ) => {
if ( "actionName" in $$props2 )
$$invalidate ( 0 , actionName = $$props2 . actionName ) ;
if ( "hotkeys" in $$props2 )
$$invalidate ( 6 , hotkeys = $$props2 . hotkeys ) ;
if ( "listening" in $$props2 )
$$invalidate ( 7 , listening = $$props2 . listening ) ;
} ;
$$self . $$ . update = ( ) => {
if ( $$self . $$ . dirty & 64 ) {
$ :
$$invalidate ( 4 , _hotkeys = [ ... hotkeys !== null && hotkeys !== void 0 ? hotkeys : [ ] ] ) ;
}
if ( $$self . $$ . dirty & 128 ) {
$ :
$$invalidate ( 3 , _listening = listening ) ;
}
} ;
return [
actionName ,
restoreButtonEl ,
addHotkeyButtonEl ,
_listening ,
_hotkeys ,
dispatcher ,
hotkeys ,
listening ,
removed _handler ,
span0 _binding ,
click _handler ,
span1 _binding ,
click _handler _1
] ;
}
var HotkeyEntry = class extends SvelteComponent {
constructor ( options ) {
super ( ) ;
init ( this , options , instance2 , create _fragment2 , safe _not _equal , { actionName : 0 , hotkeys : 6 , listening : 7 } , add _css2 ) ;
}
} ;
var HotkeyEntry _default = HotkeyEntry ;
// src/ui/HotkeySetter.ts
var HotkeySetter = class {
constructor ( app2 , containerEl , text2 , currentHotkeys , defaultHotkeys ) {
this . shouldReflect = ( _ ) => true ;
this . onRestored = ( ) => {
const { component } = this ;
if ( ! component )
return ;
const renewed = [ ... this . defaultHotkeys ] ;
if ( this . shouldReflect ( renewed ) ) {
this . currentHotkeys = renewed ;
component . $set ( {
hotkeys : renewed
} ) ;
}
} ;
this . onRemoved = ( evt ) => {
const { component } = this ;
if ( ! component )
return ;
if ( ! ( evt instanceof CustomEvent ) )
return ;
const removed = evt . detail . removed ;
const renewed = [ ... this . currentHotkeys ] ;
renewed . remove ( removed ) ;
if ( this . shouldReflect ( renewed ) ) {
this . currentHotkeys = renewed ;
component . $set ( {
hotkeys : renewed
} ) ;
}
} ;
this . onStartListening = ( ) => {
const { component } = this ;
if ( ! component )
return ;
component . $set ( {
listening : true
} ) ;
this . scope = new import _obsidian6 . Scope ( ) ;
this . app . keymap . pushScope ( this . scope ) ;
this . scope . register ( null , null , ( evt ) => {
evt . preventDefault ( ) ;
if ( evt . key === "Escape" ) {
component . $set ( {
listening : false
} ) ;
if ( this . scope )
this . app . keymap . popScope ( this . scope ) ;
return ;
}
const hotkey = getHotkey ( evt ) ;
const collision = contain ( this . currentHotkeys , hotkey ) ;
if ( collision )
return ;
const renewed = [ ... this . currentHotkeys ] ;
renewed . push ( hotkey ) ;
if ( ! this . shouldReflect ( renewed , hotkey ) )
return ;
this . currentHotkeys = renewed ;
component . $set ( {
hotkeys : renewed
} ) ;
component . $set ( {
listening : false
} ) ;
if ( this . scope )
this . app . keymap . popScope ( this . scope ) ;
} ) ;
} ;
this . app = app2 ;
this . containerEl = containerEl ;
this . text = text2 ;
this . currentHotkeys = [ ... currentHotkeys ] ;
this . defaultHotkeys = [ ... defaultHotkeys ] ;
this . component = this . attachComponent ( ) ;
}
unload ( ) {
this . onunload ( ) ;
}
onChanged ( cb ) {
this . shouldReflect = cb ;
return this ;
}
attachComponent ( ) {
const component = new HotkeyEntry _default ( {
target : this . containerEl ,
props : {
actionName : this . text ,
hotkeys : this . currentHotkeys
}
} ) ;
component . $on ( "removed" , this . onRemoved ) ;
component . $on ( "restored" , this . onRestored ) ;
component . $on ( "start-listening-keys" , this . onStartListening ) ;
return component ;
}
onunload ( ) {
var _a ;
( _a = this . component ) == null ? void 0 : _a . $destroy ( ) ;
if ( this . scope ) {
this . app . keymap . popScope ( this . scope ) ;
}
}
} ;
// src/Setting.ts
var AVAILABLE _OUTLINE _WIDTHS = [ 0 , 3 , 5 , 7 , 10 ] ;
var AUTO _PREVIEW _MODE _IDS = [ "none" , "singleView" , "cardView" ] ;
var autoPreviewModeInfos = {
none : "none" ,
singleView : "single view" ,
cardView : "card view"
} ;
var AVAILABLE _CARD _LAYOUT = [ "2x2" , "2x3" , "3x2" , "3x3" ] ;
var DEFAULT _SETTINGS = {
keepSelectedItemsCentered : false ,
outlineWidth : 5 ,
autoPreviewMode : "cardView" ,
cardViewLayout : "2x3" ,
splitDirection : "horizontal" ,
autoToggleSidebar : false ,
renderCardsManually : false ,
searchModeHotkeys : {
selectNext : [
{ modifiers : [ "Ctrl" ] , key : "n" } ,
{ modifiers : [ ] , key : "ArrowDown" }
] ,
selectPrevious : [
{ modifiers : [ "Ctrl" ] , key : "p" } ,
{ modifiers : [ ] , key : "ArrowUp" }
] ,
previewModal : [ { modifiers : [ "Ctrl" ] , key : " " } ] ,
open : [ { modifiers : [ "Ctrl" ] , key : "Enter" } ] ,
openInNewPane : [ { modifiers : [ "Ctrl" , "Shift" ] , key : "Enter" } ] ,
showOptions : [ { modifiers : [ "Shift" ] , key : " " } ] ,
nextPage : [ { modifiers : [ "Ctrl" ] , key : "]" } ] ,
previousPage : [ { modifiers : [ "Ctrl" ] , key : "[" } ] ,
copyLink : [ { modifiers : [ "Ctrl" ] , key : "i" } ]
} ,
previewModalHotkeys : {
scrollDown : [
{ modifiers : [ "Ctrl" ] , key : "n" } ,
{ modifiers : [ ] , key : "ArrowDown" }
] ,
scrollUp : [
{ modifiers : [ "Ctrl" ] , key : "p" } ,
{ modifiers : [ ] , key : "ArrowUp" }
] ,
bigScrollDown : [ { modifiers : [ ] , key : " " } ] ,
bigScrollUp : [ { modifiers : [ "Shift" ] , key : " " } ] ,
open : [ { modifiers : [ "Ctrl" ] , key : "Enter" } ] ,
openInNewPage : [ { modifiers : [ "Ctrl" , "Shift" ] , key : "Enter" } ] ,
closeModal : [ { modifiers : [ "Ctrl" ] , key : " " } ] ,
focusNext : [ { modifiers : [ ] , key : "Tab" } ] ,
focusPrevious : [ { modifiers : [ "Shift" ] , key : "Tab" } ] ,
togglePreviewMode : [ { modifiers : [ "Ctrl" ] , key : "e" } ] ,
copyLink : [ { modifiers : [ "Ctrl" ] , key : "i" } ]
}
} ;
var CoreSearchAssistantSettingTab = class extends import _obsidian7 . PluginSettingTab {
constructor ( app2 , plugin2 ) {
super ( app2 , plugin2 ) ;
this . plugin = plugin2 ;
this . hotkeySetters = [ ] ;
}
display ( ) {
this . hide ( ) ;
const { containerEl } = this ;
containerEl . empty ( ) ;
new import _obsidian7 . Setting ( containerEl ) . setName ( "Keep selected item centered" ) . addToggle ( ( component ) => {
var _a , _b ;
component . setValue ( ( _b = ( _a = this . plugin . settings ) == null ? void 0 : _a . keepSelectedItemsCentered ) != null ? _b : DEFAULT _SETTINGS . keepSelectedItemsCentered ) . onChange ( ( value ) => {
if ( ! this . plugin . settings ) {
return ;
}
this . plugin . settings . keepSelectedItemsCentered = value ;
this . plugin . saveSettings ( ) ;
} ) ;
} ) ;
new import _obsidian7 . Setting ( containerEl ) . setName ( "Outline width (px)" ) . setDesc ( "An outline appears when you enter search mode." ) . addDropdown ( ( component ) => {
var _a ;
AVAILABLE _OUTLINE _WIDTHS . forEach ( ( width ) => {
const text2 = width . toString ( ) ;
component . addOption ( text2 , text2 ) ;
} ) ;
component . setValue ( validOutlineWidth ( ( _a = this . plugin . settings ) == null ? void 0 : _a . outlineWidth ) . toString ( ) ) . onChange ( ( value ) => {
const width = Number . parseInt ( value ) ;
if ( ! this . plugin . settings ) {
return ;
}
if ( ! AVAILABLE _OUTLINE _WIDTHS . includes ( width ) ) {
return ;
}
this . plugin . settings . outlineWidth = width ;
this . plugin . saveSettings ( ) ;
} ) ;
} ) ;
new import _obsidian7 . Setting ( containerEl ) . setName ( "Auto preview mode" ) . addDropdown ( ( component ) => {
var _a , _b ;
component . addOptions ( autoPreviewModeInfos ) . setValue ( ( _b = ( _a = this . plugin . settings ) == null ? void 0 : _a . autoPreviewMode ) != null ? _b : "cardView" ) . onChange ( ( id ) => {
if ( ! this . plugin . settings ) {
return ;
}
if ( ! AUTO _PREVIEW _MODE _IDS . includes ( id ) ) {
return ;
}
this . plugin . settings . autoPreviewMode = id ;
this . plugin . saveSettings ( ) ;
} ) ;
} ) ;
new import _obsidian7 . Setting ( containerEl ) . setName ( "Default layout of card view" ) . addDropdown ( ( component ) => {
var _a , _b ;
AVAILABLE _CARD _LAYOUT . forEach ( ( layout ) => {
component . addOption ( layout , layout ) ;
} ) ;
component . setValue ( ( _b = ( _a = this . plugin . settings ) == null ? void 0 : _a . cardViewLayout ) != null ? _b : DEFAULT _SETTINGS . cardViewLayout ) . onChange ( ( value ) => {
if ( ! this . plugin . settings ) {
return ;
}
if ( ! AVAILABLE _CARD _LAYOUT . includes ( value ) ) {
return ;
}
this . plugin . settings . cardViewLayout = value ;
this . plugin . saveSettings ( ) ;
} ) ;
} ) ;
new import _obsidian7 . Setting ( containerEl ) . setName ( "Default split direction" ) . setDesc ( "This applies when you open a file in a new pane" ) . addDropdown ( ( component ) => {
if ( ! this . plugin . settings ) {
return ;
}
component . addOptions ( {
horizontal : "horizontal" ,
vertical : "vertical"
} ) . setValue ( this . plugin . settings . splitDirection ) . onChange ( ( direction ) => _ _async ( this , null , function * ( ) {
if ( ! this . plugin . settings ) {
return ;
}
if ( direction == "horizontal" || direction == "vertical" ) {
this . plugin . settings . splitDirection = direction ;
yield this . plugin . saveSettings ( ) ;
}
} ) ) ;
} ) ;
new import _obsidian7 . Setting ( containerEl ) . setName ( "Toggle sidebars automatically" ) . setDesc ( "Automatically collapse the other sidebar when entering the search mode and the search panel when exiting the search mode" ) . addToggle ( ( component ) => {
if ( ! this . plugin . settings ) {
return ;
}
component . setValue ( this . plugin . settings . autoToggleSidebar ) . onChange ( ( value ) => {
if ( ! this . plugin . settings ) {
return ;
}
this . plugin . settings . autoToggleSidebar = value ;
this . plugin . saveSettings ( ) ;
} ) ;
} ) ;
new import _obsidian7 . Setting ( containerEl ) . setName ( "Render cards manually" ) . setDesc ( "If enabled, you must hit the enter key to render cards." ) . addToggle ( ( component ) => {
if ( ! this . plugin . settings )
return ;
component . setValue ( this . plugin . settings . renderCardsManually ) . onChange ( ( value ) => {
if ( ! this . plugin . settings )
return ;
this . plugin . settings . renderCardsManually = value ;
this . plugin . saveSettings ( ) ;
} ) ;
} ) ;
containerEl . createEl ( "h2" , { text : "Hotkeys" } ) ;
const { settings } = this . plugin ;
containerEl . createEl ( "h3" , { text : "Search mode" } ) ;
if ( ! settings )
return ;
SEARCH _MODE _HOTKEY _ACTION _IDS . forEach ( ( actionId ) => {
const hotkeys = settings . searchModeHotkeys [ actionId ] ;
const defaultHotkeys = DEFAULT _SETTINGS . searchModeHotkeys [ actionId ] ;
const description = SEARCH _MODE _HOTKEY _ACTION _INFO [ actionId ] ;
const hotkeySetter = new HotkeySetter ( this . app , containerEl , description , hotkeys , defaultHotkeys ) . onChanged ( ( renewed , added ) => {
if ( added ) {
if ( added . modifiers . length === 0 )
return false ;
const collision = SEARCH _MODE _HOTKEY _ACTION _IDS . some ( ( actionId2 ) => {
const hotkeys2 = settings . searchModeHotkeys [ actionId2 ] ;
return contain ( hotkeys2 , added ) ;
} ) ;
if ( collision ) {
new import _obsidian7 . Notice ( "Hotkeys are conflicting!" ) ;
return false ;
}
}
settings . searchModeHotkeys [ actionId ] = renewed ;
this . plugin . saveSettings ( ) ;
return true ;
} ) ;
this . hotkeySetters . push ( hotkeySetter ) ;
} ) ;
containerEl . createEl ( "h3" , { text : "Preview Modal" } ) ;
PREVIEW _MODAL _HOTKEY _ACTION _IDS . forEach ( ( actionId ) => {
const hotkeys = settings . previewModalHotkeys [ actionId ] ;
const defaultHotkeys = DEFAULT _SETTINGS . previewModalHotkeys [ actionId ] ;
const description = PREVIEW _MODAL _HOTKEY _ACTION _INFO [ actionId ] ;
DEFAULT _SETTINGS . previewModalHotkeys [ actionId ] ;
const hotkeySetter = new HotkeySetter ( this . app , containerEl , description , hotkeys , defaultHotkeys ) . onChanged ( ( renewed , added ) => {
if ( added ) {
const collision = PREVIEW _MODAL _HOTKEY _ACTION _IDS . some ( ( actionId2 ) => {
const hotkeys2 = settings . previewModalHotkeys [ actionId2 ] ;
return contain ( hotkeys2 , added ) ;
} ) ;
if ( collision ) {
new import _obsidian7 . Notice ( "Hotkeys are conflicting!" ) ;
return false ;
}
}
settings . previewModalHotkeys [ actionId ] = renewed ;
this . plugin . saveSettings ( ) ;
return true ;
} ) ;
this . hotkeySetters . push ( hotkeySetter ) ;
} ) ;
}
hide ( ) {
super . hide ( ) ;
this . hotkeySetters . forEach ( ( s ) => s . unload ( ) ) ;
this . hotkeySetters = [ ] ;
}
} ;
function validOutlineWidth ( width ) {
if ( typeof width !== "number" ) {
return DEFAULT _SETTINGS . outlineWidth ;
}
if ( ! Number . isInteger ( width ) ) {
return DEFAULT _SETTINGS . outlineWidth ;
}
if ( ! AVAILABLE _OUTLINE _WIDTHS . includes ( width ) ) {
return DEFAULT _SETTINGS . outlineWidth ;
}
return width ;
}
function parseCardLayout ( layout ) {
const [ row , column ] = layout . split ( "x" ) ;
return [ Number . parseInt ( row != null ? row : "0" ) , Number . parseInt ( column != null ? column : "0" ) ] ;
}
var SEARCH _MODE _HOTKEY _ACTION _IDS = [
"selectNext" ,
"selectPrevious" ,
"previewModal" ,
"open" ,
"openInNewPane" ,
"showOptions" ,
"nextPage" ,
"previousPage" ,
"copyLink"
] ;
var SEARCH _MODE _HOTKEY _ACTION _INFO = {
selectNext : "Select the next item" ,
selectPrevious : "Select the previous item" ,
previewModal : "Preview the selected item" ,
open : "Open the selected item" ,
openInNewPane : "Open the selected item in a new pane" ,
showOptions : "Set search options" ,
nextPage : "Move to the next set of cards" ,
previousPage : "Move to the previous set of cards" ,
copyLink : "Copy wiki link of the selected item"
} ;
var PREVIEW _MODAL _HOTKEY _ACTION _IDS = [
"scrollDown" ,
"scrollUp" ,
"bigScrollDown" ,
"bigScrollUp" ,
"open" ,
"openInNewPage" ,
"closeModal" ,
"focusNext" ,
"focusPrevious" ,
"togglePreviewMode" ,
"copyLink"
] ;
var PREVIEW _MODAL _HOTKEY _ACTION _INFO = {
scrollDown : "Scroll down a bit" ,
scrollUp : "Scroll up a bit" ,
bigScrollDown : "Scroll down a lot" ,
bigScrollUp : "Scroll up a lot" ,
open : "Open the selected item" ,
openInNewPage : "Open the selected item in a new pane" ,
closeModal : "Close the modal" ,
focusNext : "Focus on the next match" ,
focusPrevious : "Focus on the previous match" ,
togglePreviewMode : "Toggle preview mode" ,
copyLink : "Copy wiki link of the selected item"
} ;
// src/components/PreviewModal.ts
var import _obsidian13 = _ _toModule ( require ( "obsidian" ) ) ;
// src/utils/Util.ts
function delay ( millisecond ) {
return _ _async ( this , null , function * ( ) {
yield new Promise ( ( resolve ) => setTimeout ( resolve , millisecond ) ) ;
} ) ;
}
function scrollIteration ( editor ) {
const line = lineCount ( editor ) ;
if ( line === void 0 ) {
return void 0 ;
}
return Math . max ( Math . floor ( line / 1e3 ) , 1 ) ;
}
function lineCount ( editor ) {
var _a , _b , _c ;
const line = ( _c = ( _b = ( _a = editor == null ? void 0 : editor [ "cm" ] ) == null ? void 0 : _a [ "state" ] ) == null ? void 0 : _b [ "doc" ] ) == null ? void 0 : _c . length ;
return typeof line === "number" ? line : void 0 ;
}
function retry ( cb , interval , trials , check = ( got ) => got !== void 0 ) {
return _ _async ( this , null , function * ( ) {
for ( let i = 0 ; i < trials ; i ++ ) {
const got = cb ( ) ;
if ( check ( got ) ) {
return got ;
}
yield delay ( interval ) ;
}
return void 0 ;
} ) ;
}
function shallowClone ( obj ) {
return Object . assign ( { } , obj ) ;
}
function deepClone ( obj ) {
if ( obj === null )
return obj ;
if ( typeof obj !== "object" )
return obj ;
if ( obj instanceof Array ) {
const clone2 = new Array ( obj . length ) ;
obj . forEach ( ( value , id ) => {
clone2 [ id ] = deepClone ( value ) ;
} ) ;
return clone2 ;
}
const clone = shallowClone ( obj ) ;
for ( const key in clone ) {
const value = clone [ key ] ;
clone [ key ] = deepClone ( value ) ;
}
return clone ;
}
function deepMerge ( a , b ) {
if ( b === void 0 ) {
return deepClone ( a ) ;
} else if ( a === void 0 ) {
return deepClone ( b ) ;
}
if ( typeof a !== typeof b ) {
throw new Error ( ` failed to deepMerge ${ a } and ${ b } ` ) ;
}
if ( typeof b !== "object" )
return deepClone ( b ) ;
if ( b === null ) {
return deepClone ( a ) ;
} else if ( a === null ) {
return deepClone ( b ) ;
}
if ( b instanceof Array ) {
if ( a instanceof Array ) {
return deepClone ( b ) ;
} else {
throw new Error ( ` failed to deepMerge ${ a } and ${ b } ` ) ;
}
} else if ( a instanceof Array ) {
throw new Error ( ` failed to deepMerge ${ a } and ${ b } ` ) ;
}
const clone = shallowClone ( a ) ;
for ( const key in a ) {
clone [ key ] = deepMerge ( a [ key ] , b [ key ] ) ;
}
for ( const key in b ) {
clone [ key ] = deepMerge ( a [ key ] , b [ key ] ) ;
}
return clone ;
}
// src/utils/Link.ts
function generateInternalLinkFrom ( app2 , file ) {
const text2 = getDisplayText ( app2 . metadataCache , file ) ;
return app2 . fileManager . generateMarkdownLink ( file , "" , void 0 , text2 ) ;
}
function getDisplayText ( metadataCache , file ) {
const cache = metadataCache . getFileCache ( file ) ;
if ( ! cache )
return void 0 ;
const title = getTitle ( cache . frontmatter ) ;
if ( title !== void 0 ) {
return title ;
}
const h1 = getFirstH1 ( cache . headings ) ;
if ( h1 !== void 0 ) {
return h1 ;
}
return void 0 ;
}
function getTitle ( frontmatter ) {
return frontmatter == null ? void 0 : frontmatter [ "title" ] ;
}
function getFirstH1 ( headings ) {
if ( ! headings )
return void 0 ;
for ( const heading of headings ) {
if ( heading . level !== 1 )
continue ;
return heading . heading ;
}
return void 0 ;
}
// node_modules/tslib/modules/index.js
var import _tslib = _ _toModule ( require _tslib ( ) ) ;
var {
_ _extends ,
_ _assign ,
_ _rest ,
_ _decorate ,
_ _param ,
_ _metadata ,
_ _awaiter ,
_ _generator ,
_ _exportStar ,
_ _createBinding ,
_ _values ,
_ _read ,
_ _spread ,
_ _spreadArrays ,
_ _spreadArray ,
_ _await ,
_ _asyncGenerator ,
_ _asyncDelegator ,
_ _asyncValues ,
_ _makeTemplateObject ,
_ _importStar ,
_ _importDefault ,
_ _classPrivateFieldGet ,
_ _classPrivateFieldSet
} = import _tslib . default ;
// src/interfaces/ViewGenerator.ts
var import _obsidian8 = _ _toModule ( require ( "obsidian" ) ) ;
var ViewGenerator = class {
constructor ( app2 , containerEl , file ) {
this . extensions = [ ] ;
this . app = app2 ;
this . containerEl = containerEl ;
this . leaf = new import _obsidian8 . WorkspaceLeaf ( this . app ) ;
this . file = file ;
}
load ( mode ) {
return _ _async ( this , null , function * ( ) {
yield this . onload ( mode ) ;
return this ;
} ) ;
}
unload ( ) {
return _ _async ( this , null , function * ( ) {
this . onunload ( ) ;
} ) ;
}
toggleViewMode ( ) {
return _ _async ( this , null , function * ( ) {
for ( const ext of this . extensions ) {
if ( ! ( yield ext . isMine ( this . leaf ) ) )
continue ;
yield ext . toggleViewMode ( this . leaf ) ;
return ;
}
} ) ;
}
onload ( mode ) {
return _ _async ( this , null , function * ( ) {
const fileType = fileTypeMap [ this . file . extension ] ;
if ( ! fileType )
return ;
this . containerEl . appendChild ( this . leaf . containerEl ) ;
yield this . openFile ( ) ;
for ( const ext of this . extensions ) {
if ( ! ( yield ext . isMine ( this . leaf ) ) )
continue ;
yield ext . setViewMode ( this . leaf , mode != null ? mode : "preview" ) ;
return ;
}
} ) ;
}
onunload ( ) {
this . leaf . detach ( ) ;
}
openFile ( ) {
return _ _async ( this , null , function * ( ) {
const { leaf , file } = this ;
yield leaf . openFile ( file ) ;
} ) ;
}
highlightMatches ( matches , cls ) {
const view = this . leaf . view ;
if ( ! ( view instanceof import _obsidian8 . MarkdownView ) ) {
return ;
}
const editor = view . editor ;
const ranges = [ ] ;
matches . forEach ( ( match ) => {
const range = {
from : editor . offsetToPos ( match [ 0 ] ) ,
to : editor . offsetToPos ( match [ 1 ] )
} ;
ranges . push ( range ) ;
} ) ;
editor . addHighlights ( ranges , cls ) ;
}
scrollIntoView ( match , center ) {
return _ _async ( this , null , function * ( ) {
const view = this . leaf . view ;
if ( ! ( view instanceof import _obsidian8 . MarkdownView ) ) {
return ;
}
if ( view . getMode ( ) !== "source" ) {
return ;
}
const editor = view . editor ;
const range = {
from : editor . offsetToPos ( match [ 0 ] ) ,
to : editor . offsetToPos ( match [ 1 ] )
} ;
const iter = scrollIteration ( editor ) ;
if ( iter === void 0 ) {
return ;
}
for ( let i = 0 ; i < iter ; i ++ ) {
editor . scrollIntoView ( range , center ) ;
yield delay ( 1 ) ;
}
} ) ;
}
focusOn ( match , cls , center ) {
return _ _async ( this , null , function * ( ) {
const view = this . leaf . view ;
if ( ! ( view instanceof import _obsidian8 . MarkdownView ) ) {
return ;
}
if ( view . getMode ( ) !== "source" ) {
return ;
}
yield this . scrollIntoView ( match , center ) ;
const { editor } = view ;
editor . removeHighlights ( cls ) ;
const range = {
from : editor . offsetToPos ( match [ 0 ] ) ,
to : editor . offsetToPos ( match [ 1 ] )
} ;
editor . addHighlights ( [ range ] , cls ) ;
} ) ;
}
registerExtension ( ext ) {
this . extensions . push ( ext ) ;
return this ;
}
} ;
var fileTypeMap = {
md : "md" ,
png : "image" ,
jpg : "image" ,
jpeg : "image" ,
gif : "image" ,
bmp : "image" ,
svg : "image" ,
webp : "image" ,
mp3 : "audio" ,
webm : "audio" ,
wav : "audio" ,
m4a : "audio" ,
ogg : "audio" ,
"3gp" : "audio" ,
flac : "audio" ,
mp4 : "movie" ,
ogv : "movie" ,
pdf : "pdf"
} ;
// src/interfaces/viewGeneratorExtensions/Excalidraw.ts
var import _obsidian9 = _ _toModule ( require ( "obsidian" ) ) ;
var excalidrawPluginId = "obsidian-excalidraw-plugin" ;
var excalidrawViewType = "excalidraw" ;
var ExcalidrawViewGeneratorExtension = class {
constructor ( app2 ) {
this . app = app2 ;
const excalidraw = this . app . plugins . plugins [ excalidrawPluginId ] ;
if ( ! isExcalidrawPlugin ( excalidraw ) ) {
this . excalidraw = void 0 ;
} else {
this . excalidraw = excalidraw ;
}
}
isMine ( leaf ) {
return leaf . view . getViewType ( ) === excalidrawViewType ;
}
setViewMode ( leaf , mode ) {
return _ _async ( this , null , function * ( ) {
const { excalidraw } = this ;
if ( ! excalidraw )
return ;
excalidraw . excalidrawFileModes [ leaf . id ] = "markdown" ;
yield excalidraw . setMarkdownView ( leaf ) ;
if ( ! ( leaf . view instanceof import _obsidian9 . MarkdownView ) )
return ;
yield leaf . view . setState ( _ _spreadProps ( _ _spreadValues ( { } , leaf . view . getState ( ) ) , {
mode
} ) , { } ) ;
leaf . view . editor . blur ( ) ;
} ) ;
}
toggleViewMode ( leaf ) {
return _ _async ( this , null , function * ( ) {
const { excalidraw } = this ;
if ( ! excalidraw )
return ;
excalidraw . excalidrawFileModes [ leaf . id ] = "markdown" ;
yield excalidraw . setMarkdownView ( leaf ) ;
if ( ! ( leaf . view instanceof import _obsidian9 . MarkdownView ) )
return ;
const mode = leaf . view . getMode ( ) ;
yield leaf . view . setState ( _ _spreadProps ( _ _spreadValues ( { } , leaf . view . getState ( ) ) , {
mode : mode === "preview" ? "source" : "preview"
} ) , { } ) ;
leaf . view . editor . blur ( ) ;
} ) ;
}
} ;
function isExcalidrawPlugin ( plugin2 ) {
if ( ! ( plugin2 instanceof import _obsidian9 . Plugin ) )
return false ;
const { excalidrawFileModes , setMarkdownView } = plugin2 ;
if ( typeof excalidrawFileModes !== "object" )
return false ;
if ( typeof setMarkdownView !== "function" )
return false ;
return true ;
}
// src/interfaces/viewGeneratorExtensions/Kanban.ts
var import _obsidian10 = _ _toModule ( require ( "obsidian" ) ) ;
var kanbanPluginId = "obsidian-kanban" ;
var frontMatterKey = "kanban-plugin" ;
var kanbanViewType = "kanban" ;
var KanbanViewGeneratorExtension = class {
constructor ( app2 ) {
this . app = app2 ;
const kanban = this . app . plugins . plugins [ kanbanPluginId ] ;
if ( IsKanbanPlugin ( kanban ) ) {
this . kanban = kanban ;
}
if ( kanban === void 0 ) {
this . kanban = void 0 ;
}
}
isMine ( leaf ) {
const { view } = leaf ;
if ( view . getViewType ( ) == kanbanViewType )
return true ;
if ( ! ( view instanceof import _obsidian10 . TextFileView ) )
return false ;
const fileCache = this . app . metadataCache . getFileCache ( view . file ) ;
const fileIsKanban = ! ! ( fileCache == null ? void 0 : fileCache . frontmatter ) && ! ! fileCache . frontmatter [ frontMatterKey ] ;
return fileIsKanban ;
}
setViewMode ( leaf , mode ) {
return _ _async ( this , null , function * ( ) {
const { kanban } = this ;
if ( ! kanban )
return ;
if ( mode === "source" ) {
kanban . kanbanFileModes [ leaf . id ] = "markdown" ;
yield kanban . setMarkdownView ( leaf ) ;
yield leaf . view . setState ( _ _spreadProps ( _ _spreadValues ( { } , leaf . view . getState ( ) ) , {
mode : "source"
} ) , { } ) ;
if ( leaf . view instanceof import _obsidian10 . MarkdownView ) {
leaf . view . editor . blur ( ) ;
}
} else {
kanban . kanbanFileModes [ leaf . id ] = kanbanViewType ;
yield kanban . setKanbanView ( leaf ) ;
}
} ) ;
}
toggleViewMode ( leaf ) {
return _ _async ( this , null , function * ( ) {
const { kanban } = this ;
if ( ! kanban )
return ;
const mode = kanban . kanbanFileModes [ leaf . id ] ;
yield this . setViewMode ( leaf , mode === "markdown" ? "preview" : "source" ) ;
} ) ;
}
} ;
function IsKanbanPlugin ( plugin2 ) {
if ( ! ( plugin2 instanceof import _obsidian10 . Plugin ) )
return false ;
const { kanbanFileModes , setKanbanView , setMarkdownView } = plugin2 ;
if ( typeof kanbanFileModes !== "object" )
return false ;
if ( typeof setMarkdownView !== "function" )
return false ;
if ( typeof setKanbanView !== "function" )
return false ;
return true ;
}
// src/interfaces/viewGeneratorExtensions/Markdown.ts
var import _obsidian11 = _ _toModule ( require ( "obsidian" ) ) ;
var MarkdownViewGeneratorExtension = class {
isMine ( leaf ) {
return leaf . view instanceof import _obsidian11 . MarkdownView ;
}
setViewMode ( leaf , mode ) {
return _ _async ( this , null , function * ( ) {
yield leaf . view . setState ( _ _spreadProps ( _ _spreadValues ( { } , leaf . view . getState ( ) ) , {
mode
} ) , { } ) ;
} ) ;
}
toggleViewMode ( leaf ) {
return _ _async ( this , null , function * ( ) {
if ( ! ( leaf . view instanceof import _obsidian11 . MarkdownView ) )
return ;
yield this . setViewMode ( leaf , leaf . view . getMode ( ) === "preview" ? "source" : "preview" ) ;
} ) ;
}
} ;
// src/interfaces/viewGeneratorExtensions/NonMarkdown.ts
var import _obsidian12 = _ _toModule ( require ( "obsidian" ) ) ;
var NON _MARKDOWN _FILE _TYPES = [ "image" , "audio" , "pdf" , "video" ] ;
var NonMarkdownViewGeneratorExtension = class {
isMine ( leaf ) {
if ( ! ( leaf . view instanceof import _obsidian12 . FileView ) )
return false ;
return NON _MARKDOWN _FILE _TYPES . includes ( leaf . view . getViewType ( ) ) ;
}
setViewMode ( _leaf , _mode ) {
return ;
}
toggleViewMode ( _ ) {
return ;
}
} ;
// node_modules/svelte/store/index.mjs
var subscriber _queue = [ ] ;
function writable ( value , start = noop ) {
let stop ;
const subscribers = new Set ( ) ;
function set ( new _value ) {
if ( safe _not _equal ( value , new _value ) ) {
value = new _value ;
if ( stop ) {
const run _queue = ! subscriber _queue . length ;
for ( const subscriber of subscribers ) {
subscriber [ 1 ] ( ) ;
subscriber _queue . push ( subscriber , value ) ;
}
if ( run _queue ) {
for ( let i = 0 ; i < subscriber _queue . length ; i += 2 ) {
subscriber _queue [ i ] [ 0 ] ( subscriber _queue [ i + 1 ] ) ;
}
subscriber _queue . length = 0 ;
}
}
}
}
function update2 ( fn ) {
set ( fn ( value ) ) ;
}
function subscribe2 ( run2 , invalidate = noop ) {
const subscriber = [ run2 , invalidate ] ;
subscribers . add ( subscriber ) ;
if ( subscribers . size === 1 ) {
stop = start ( set ) || noop ;
}
run2 ( value ) ;
return ( ) => {
subscribers . delete ( subscriber ) ;
if ( subscribers . size === 0 ) {
stop ( ) ;
stop = null ;
}
} ;
}
return { set , update : update2 , subscribe : subscribe2 } ;
}
// src/ui/store.ts
var app = writable ( ) ;
var plugin = writable ( ) ;
// src/ui/PreviewModalContent.svelte
function add _css3 ( target ) {
append _styles ( target , "svelte-6cqu2r" , ".core-search-assistant_preview-modal_view-container.svelte-6cqu2r{min-width:700px}.core-search-assistant_preview-modal_view-container.svelte-6cqu2r .highlight-search-match{color:var(--highlight-search-match);background-color:var(--highlight-search-match-bg)}.core-search-assistant_preview-modal_view-container.svelte-6cqu2r .focus-search-match{background-color:var(--focus-search-match-bg)}.core-search-assistant_preview-modal_view-container.svelte-6cqu2r .workspace-leaf{contain:initial !important}.core-search-assistant_preview-modal_view-container.svelte-6cqu2r .view-content{overflow:unset}.core-search-assistant_preview-modal_view-container.svelte-6cqu2r .markdown-preview-view{overflow:unset}.core-search-assistant_preview-modal_view-container.svelte-6cqu2r .workspace-leaf-content{overflow:unset}.core-search-assistant_preview-modal_view-container.svelte-6cqu2r .workspace-leaf-resize-handle{display:none}.core-search-assistant_preview-modal_view-container.svelte-6cqu2r .view-header{display:none}.core-search-assistant_preview-modal_view-container.svelte-6cqu2r .markdown-preview-view{padding:0}.core-search-assistant_preview-modal_view-container.svelte-6cqu2r .markdown-source-view{pointer-events:none}.core-search-assistant_preview-modal_view-container.svelte-6cqu2r .workspace-leaf-content[data-type='pdf']{height:990px}.core-search-assistant_preview-modal_view-container.svelte-6cqu2r .markdown-source-view.mod-cm6 .cm-editor{flex:initial;display:initial}.core-search-assistant_preview-modal_view-container.svelte-6cqu2r .markdown-source-view.mod-cm6{display:initial}.core-search-assistant_preview-modal_view-container.svelte-6cqu2r .markdown-source-view.mod-cm6 .cm-scroller{padding:0}" ) ;
}
function create _fragment3 ( ctx ) {
let div ;
return {
c ( ) {
div = element ( "div" ) ;
attr ( div , "class" , "core-search-assistant_preview-modal_view-container svelte-6cqu2r" ) ;
} ,
m ( target , anchor ) {
insert ( target , div , anchor ) ;
ctx [ 5 ] ( div ) ;
} ,
p : noop ,
i : noop ,
o : noop ,
d ( detaching ) {
if ( detaching )
detach ( div ) ;
ctx [ 5 ] ( null ) ;
}
} ;
}
function instance3 ( $$self , $$props , $$invalidate ) {
let $app ;
component _subscribe ( $$self , app , ( $$value ) => $$invalidate ( 7 , $app = $$value ) ) ;
let { file } = $$props ;
let { matches } = $$props ;
let contentContainerEl ;
let renderer ;
onMount ( ( ) => _ _awaiter ( void 0 , void 0 , void 0 , function * ( ) {
if ( ! file ) {
return ;
}
if ( ! contentContainerEl ) {
return ;
}
const fileType = fileTypeMap [ file . extension ] ;
if ( fileType !== void 0 ) {
contentContainerEl . empty ( ) ;
renderer = yield new ViewGenerator ( $app , contentContainerEl , file ) . registerExtension ( new ExcalidrawViewGeneratorExtension ( $app ) ) . registerExtension ( new KanbanViewGeneratorExtension ( $app ) ) . registerExtension ( new MarkdownViewGeneratorExtension ( ) ) . registerExtension ( new NonMarkdownViewGeneratorExtension ( ) ) . load ( "source" ) ;
highlightMatches ( ) ;
}
} ) ) ;
onDestroy ( ( ) => {
setTimeout ( ( ) => renderer === null || renderer === void 0 ? void 0 : renderer . unload ( ) , 1e3 ) ;
} ) ;
function toggleViewMode ( ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
yield renderer === null || renderer === void 0 ? void 0 : renderer . toggleViewMode ( ) ;
} ) ;
}
function focusOn ( matchId , center ) {
if ( ! matches )
return ;
const match = matches [ matchId ] ;
if ( match === void 0 ) {
return ;
}
renderer === null || renderer === void 0 ? void 0 : renderer . focusOn ( match , "focus-search-match" , center ) ;
}
function highlightMatches ( ) {
renderer === null || renderer === void 0 ? void 0 : renderer . highlightMatches ( matches !== null && matches !== void 0 ? matches : [ ] , "highlight-search-match" ) ;
}
function div _binding ( $$value ) {
binding _callbacks [ $$value ? "unshift" : "push" ] ( ( ) => {
contentContainerEl = $$value ;
$$invalidate ( 0 , contentContainerEl ) ;
} ) ;
}
$$self . $$set = ( $$props2 ) => {
if ( "file" in $$props2 )
$$invalidate ( 1 , file = $$props2 . file ) ;
if ( "matches" in $$props2 )
$$invalidate ( 2 , matches = $$props2 . matches ) ;
} ;
return [ contentContainerEl , file , matches , toggleViewMode , focusOn , div _binding ] ;
}
var PreviewModalContent = class extends SvelteComponent {
constructor ( options ) {
super ( ) ;
init ( this , options , instance3 , create _fragment3 , safe _not _equal , {
file : 1 ,
matches : 2 ,
toggleViewMode : 3 ,
focusOn : 4
} , add _css3 ) ;
}
get toggleViewMode ( ) {
return this . $$ . ctx [ 3 ] ;
}
get focusOn ( ) {
return this . $$ . ctx [ 4 ] ;
}
} ;
var PreviewModalContent _default = PreviewModalContent ;
// src/components/PreviewModal.ts
var SCROLL _AMOUNT = 70 ;
var PreviewModal = class extends import _obsidian13 . Modal {
constructor ( app2 , plugin2 , modeScope , item ) {
super ( app2 ) ;
this . plugin = plugin2 ;
this . modeScope = modeScope ;
this . item = item ;
this . currentFocus = - 1 ;
}
onOpen ( ) {
return _ _async ( this , null , function * ( ) {
var _a ;
yield this . renderView ( ) ;
this . modeScope . push ( ) ;
const hotkeyMap = ( _a = this . plugin . settings ) == null ? void 0 : _a . previewModalHotkeys ;
if ( ! hotkeyMap )
return ;
hotkeyMap . closeModal . forEach ( ( hotkey ) => {
this . scope . register ( hotkey . modifiers , hotkey . key , ( ) => {
this . shouldRestoreSelection = true ;
this . close ( ) ;
} ) ;
} ) ;
hotkeyMap . open . forEach ( ( hotkey ) => {
this . scope . register ( hotkey . modifiers , hotkey . key , ( ) => {
var _a2 ;
this . openAndFocus ( this . currentFocus ) ;
( _a2 = this . plugin . controller ) == null ? void 0 : _a2 . exit ( ) ;
this . shouldRestoreSelection = false ;
this . close ( ) ;
} ) ;
} ) ;
hotkeyMap . openInNewPage . forEach ( ( hotkey ) => {
this . scope . register ( hotkey . modifiers , hotkey . key , ( ) => {
var _a2 , _b ;
this . openAndFocus ( this . currentFocus , ( _a2 = this . plugin . settings ) == null ? void 0 : _a2 . splitDirection ) ;
( _b = this . plugin . controller ) == null ? void 0 : _b . exit ( ) ;
this . shouldRestoreSelection = false ;
this . close ( ) ;
} ) ;
} ) ;
hotkeyMap . bigScrollDown . forEach ( ( hotkey ) => {
this . scope . register ( hotkey . modifiers , hotkey . key , ( ) => {
this . scroll ( "down" ) ;
} ) ;
} ) ;
hotkeyMap . bigScrollUp . forEach ( ( hotkey ) => {
this . scope . register ( hotkey . modifiers , hotkey . key , ( ) => {
this . scroll ( "up" ) ;
} ) ;
} ) ;
hotkeyMap . scrollDown . forEach ( ( hotkey ) => {
this . scope . register ( hotkey . modifiers , hotkey . key , ( ) => {
this . scroll ( "down" , SCROLL _AMOUNT ) ;
} ) ;
} ) ;
hotkeyMap . scrollUp . forEach ( ( hotkey ) => {
this . scope . register ( hotkey . modifiers , hotkey . key , ( ) => {
this . scroll ( "up" , SCROLL _AMOUNT ) ;
} ) ;
} ) ;
hotkeyMap . focusNext . forEach ( ( hotkey ) => {
this . scope . register ( hotkey . modifiers , hotkey . key , ( evt ) => {
var _a2 ;
evt . preventDefault ( ) ;
const numMatches = this . countMatches ( ) ;
if ( numMatches === void 0 || numMatches === 0 ) {
return ;
}
this . currentFocus = cyclicId ( ++ this . currentFocus , numMatches ) ;
( _a2 = this . previewContent ) == null ? void 0 : _a2 . focusOn ( this . currentFocus , true ) ;
} ) ;
} ) ;
hotkeyMap . focusPrevious . forEach ( ( hotkey ) => {
this . scope . register ( hotkey . modifiers , hotkey . key , ( evt ) => {
var _a2 ;
evt . preventDefault ( ) ;
const numMatches = this . countMatches ( ) ;
if ( numMatches === void 0 || numMatches === 0 ) {
return ;
}
this . currentFocus = cyclicId ( -- this . currentFocus , numMatches ) ;
( _a2 = this . previewContent ) == null ? void 0 : _a2 . focusOn ( this . currentFocus , true ) ;
} ) ;
} ) ;
hotkeyMap . togglePreviewMode . forEach ( ( hotkey ) => {
this . scope . register ( hotkey . modifiers , hotkey . key , ( evt ) => {
( ( ) => _ _async ( this , null , function * ( ) {
var _a2 ;
evt . preventDefault ( ) ;
yield ( _a2 = this . previewContent ) == null ? void 0 : _a2 . toggleViewMode ( ) ;
} ) ) ( ) ;
} ) ;
} ) ;
hotkeyMap . copyLink . forEach ( ( hotkey ) => {
this . scope . register ( hotkey . modifiers , hotkey . key , ( ) => {
const { file } = this . item ;
const internalLink = generateInternalLinkFrom ( this . app , file ) ;
navigator . clipboard . writeText ( internalLink ) ;
new import _obsidian13 . Notice ( "Copy wiki link!" ) ;
} ) ;
} ) ;
} ) ;
}
onClose ( ) {
var _a ;
( _a = this . previewContent ) == null ? void 0 : _a . $destroy ( ) ;
setTimeout ( ( ) => {
if ( this . modeScope . depth > 1 ) {
this . modeScope . pop ( ) ;
}
} , 100 ) ;
}
renderView ( ) {
return _ _async ( this , null , function * ( ) {
const { contentEl } = this ;
contentEl . empty ( ) ;
contentEl . hide ( ) ;
this . previewContent = new PreviewModalContent _default ( {
target : contentEl ,
props : {
file : this . item . file ,
matches : this . item . result . content
}
} ) ;
contentEl . show ( ) ;
} ) ;
}
countMatches ( ) {
var _a ;
return ( _a = this . item . result . content ) == null ? void 0 : _a . length ;
}
scroll ( direction , px ) {
const { containerEl , contentEl } = this ;
const move = ( px != null ? px : containerEl . clientHeight / 2 ) * ( direction === "up" ? - 1 : 1 ) ;
contentEl . scrollBy ( {
top : move ,
behavior : "smooth"
} ) ;
}
openAndFocus ( matchId , direction ) {
return _ _async ( this , null , function * ( ) {
var _a , _b ;
const { item } = this ;
const leaf = direction === void 0 ? this . app . workspace . getMostRecentLeaf ( ) : this . app . workspace . splitActiveLeaf ( direction ) ;
yield leaf . openFile ( item . file ) ;
this . app . workspace . setActiveLeaf ( leaf , true , true ) ;
const match = ( _b = ( _a = item == null ? void 0 : item . result ) == null ? void 0 : _a . content ) == null ? void 0 : _b [ matchId ] ;
if ( ! match ) {
return ;
}
const { view } = leaf ;
if ( ! ( view instanceof import _obsidian13 . MarkdownView ) ) {
return ;
}
const editor = view . editor ;
const range = {
from : editor . offsetToPos ( match [ 0 ] ) ,
to : editor . offsetToPos ( match [ 1 ] )
} ;
editor . addHighlights ( [ range ] , "obsidian-search-match-highlight" ) ;
const iter = scrollIteration ( editor ) ;
if ( iter === void 0 ) {
return ;
}
for ( let i = 0 ; i < iter ; i ++ ) {
editor . scrollIntoView ( range , true ) ;
}
editor . setCursor ( range . from ) ;
} ) ;
}
} ;
function cyclicId ( id , total ) {
return ( id % total + total ) % total ;
}
// src/ModeScope.ts
var ModeScope = class {
constructor ( ) {
this . _depth = 0 ;
}
get inSearchMode ( ) {
return this . _depth > 0 ;
}
get depth ( ) {
return this . _depth ;
}
push ( ) {
this . _depth ++ ;
}
pop ( ) {
this . _depth -- ;
if ( this . depth < 0 ) {
throw "[ERROR in Core Search Assistant] ModeScope.depth < 0" ;
}
}
reset ( ) {
this . _depth = 0 ;
}
} ;
// src/Controller.ts
var import _obsidian14 = _ _toModule ( require ( "obsidian" ) ) ;
// src/ui/CardContainer.svelte
function add _css4 ( target ) {
append _styles ( target , "svelte-1g7kfgn" , ".core-search-assistant_card-container.svelte-1g7kfgn.svelte-1g7kfgn{overflow:hidden;display:flex;flex-direction:column;height:100%;position:relative;box-shadow:0 2px 5px rgba(0, 0, 0, 0.2);border-radius:10px;cursor:pointer;background-color:var(--background-primary);box-sizing:content-box}.core-search-assistant_card-container.svelte-1g7kfgn.svelte-1g7kfgn:hover{border:5px solid var(--interactive-accent);margin:-5px}.core-search-assistant_card-container.is-selected.svelte-1g7kfgn.svelte-1g7kfgn{border:5px solid var(--interactive-accent);margin:-5px}.card-container-header.svelte-1g7kfgn.svelte-1g7kfgn{padding:5px 10px;background-color:var(--background-secondary);display:flex;color:var(--text-muted)}.file-name-container.svelte-1g7kfgn.svelte-1g7kfgn{font-size:1rem;line-height:1.2rem;overflow-wrap:break-word;min-width:0;flex:1}.file-name-container.svelte-1g7kfgn span.matched-in-path{color:var(--text-normal);font-weight:bold}.content-container-wrapper.svelte-1g7kfgn.svelte-1g7kfgn{padding:5px;flex:1;height:100%;min-height:0}.content-container.svelte-1g7kfgn.svelte-1g7kfgn{overflow:hidden;height:100%;font-size:0.8rem;line-height:1.2}.content-container.svelte-1g7kfgn div.content-not-supported-file-format.svelte-1g7kfgn{font-size:1rem;color:var(--text-muted)}.content-container.svelte-1g7kfgn p{font-size:0.8rem;line-height:1.2}.content-container.svelte-1g7kfgn code{font-size:0.8rem;line-height:1.2}.content-container.svelte-1g7kfgn div{font-size:0.8rem}.content-container.svelte-1g7kfgn li{font-size:0.8rem;line-height:1.2}.content-container.svelte-1g7kfgn h1{font-size:1rem;line-height:1.2;margin:5px}.content-container.svelte-1g7kfgn h2{font-size:1rem;line-height:1.2;margin:5px}.content-container.svelte-1g7kfgn h3{font-size:1rem;line-height:1.2;margin:5px}.content-container.svelte-1g7kfgn h4{font-size:1rem;line-height:1.2;margin:5px}.content-container.svelte-1g7kfgn h5{font-size:1rem;line-height:1.2;margin:5px}.content-container.svelte-1g7kfgn h6{font-size:1rem;line-height:1.2;margin:5px}.content-container.svelte-1g7kfgn a{pointer-events:none}.content-container.svelte-1g7kfgn .workspace-leaf{contain:initial !important;height:100%}.content-container.svelte-1g7kfgn .workspace-leaf-resize-handle{display:none}.content-container.svelte-1g7kfgn .view-header{display:none}.content-container.svelte-1g7kfgn .view-content{flex:1;overflow:hidden}.content-container.svelte-1g7kfgn .markdown-preview-view{padding:0;overflow:hidden}.content-container.svelte-1g7kfgn .modal-content{margin:0}" ) ;
}
function create _fragment4 ( ctx ) {
let div5 ;
let div1 ;
let div0 ;
let t0 ;
let div4 ;
let div3 ;
let div2 ;
let t1 _value = ` ${ ctx [ 1 ] . extension . toUpperCase ( ) } file ` ;
let t1 ;
let div5 _data _path _value ;
let mounted ;
let dispose ;
return {
c ( ) {
div5 = element ( "div" ) ;
div1 = element ( "div" ) ;
div0 = element ( "div" ) ;
t0 = space ( ) ;
div4 = element ( "div" ) ;
div3 = element ( "div" ) ;
div2 = element ( "div" ) ;
t1 = text ( t1 _value ) ;
attr ( div0 , "class" , "file-name-container svelte-1g7kfgn" ) ;
attr ( div1 , "class" , "card-container-header svelte-1g7kfgn" ) ;
attr ( div2 , "class" , "content-not-supported-file-format svelte-1g7kfgn" ) ;
attr ( div3 , "class" , "content-container svelte-1g7kfgn" ) ;
attr ( div4 , "class" , "content-container-wrapper svelte-1g7kfgn" ) ;
attr ( div5 , "class" , "core-search-assistant_card-container svelte-1g7kfgn" ) ;
attr ( div5 , "data-id" , ctx [ 0 ] ) ;
attr ( div5 , "data-path" , div5 _data _path _value = ctx [ 1 ] . path ) ;
toggle _class ( div5 , "is-selected" , ctx [ 2 ] ) ;
} ,
m ( target , anchor ) {
insert ( target , div5 , anchor ) ;
append ( div5 , div1 ) ;
append ( div1 , div0 ) ;
ctx [ 8 ] ( div0 ) ;
append ( div5 , t0 ) ;
append ( div5 , div4 ) ;
append ( div4 , div3 ) ;
append ( div3 , div2 ) ;
append ( div2 , t1 ) ;
ctx [ 9 ] ( div3 ) ;
if ( ! mounted ) {
dispose = listen ( div5 , "click" , ctx [ 5 ] ) ;
mounted = true ;
}
} ,
p ( ctx2 , [ dirty ] ) {
if ( dirty & 2 && t1 _value !== ( t1 _value = ` ${ ctx2 [ 1 ] . extension . toUpperCase ( ) } file ` ) )
set _data ( t1 , t1 _value ) ;
if ( dirty & 1 ) {
attr ( div5 , "data-id" , ctx2 [ 0 ] ) ;
}
if ( dirty & 2 && div5 _data _path _value !== ( div5 _data _path _value = ctx2 [ 1 ] . path ) ) {
attr ( div5 , "data-path" , div5 _data _path _value ) ;
}
if ( dirty & 4 ) {
toggle _class ( div5 , "is-selected" , ctx2 [ 2 ] ) ;
}
} ,
i : noop ,
o : noop ,
d ( detaching ) {
if ( detaching )
detach ( div5 ) ;
ctx [ 8 ] ( null ) ;
ctx [ 9 ] ( null ) ;
mounted = false ;
dispose ( ) ;
}
} ;
}
function renderFileName ( fileName , containerEl ) {
containerEl . appendText ( fileName ) ;
}
function instance4 ( $$self , $$props , $$invalidate ) {
let $app ;
component _subscribe ( $$self , app , ( $$value ) => $$invalidate ( 11 , $app = $$value ) ) ;
let { id } = $$props ;
let { file } = $$props ;
let { selected } = $$props ;
let { focusEl } = $$props ;
let contentContainerEl ;
let fileNameContainerEl ;
let renderer ;
const dispatch = createEventDispatcher ( ) ;
function path ( ) {
return file . path ;
}
onMount ( ( ) => _ _awaiter ( void 0 , void 0 , void 0 , function * ( ) {
if ( ! fileNameContainerEl ) {
return ;
}
renderFileName ( file . name , fileNameContainerEl ) ;
if ( ! contentContainerEl ) {
return ;
}
const fileType = fileTypeMap [ file . extension ] ;
if ( fileType !== void 0 ) {
contentContainerEl . empty ( ) ;
renderer = yield new ViewGenerator ( $app , contentContainerEl , file ) . registerExtension ( new ExcalidrawViewGeneratorExtension ( $app ) ) . registerExtension ( new KanbanViewGeneratorExtension ( $app ) ) . registerExtension ( new MarkdownViewGeneratorExtension ( ) ) . registerExtension ( new NonMarkdownViewGeneratorExtension ( ) ) . load ( "preview" ) ;
}
focusEl === null || focusEl === void 0 ? void 0 : focusEl . focus ( ) ;
} ) ) ;
onDestroy ( ( ) => {
setTimeout ( ( ) => renderer === null || renderer === void 0 ? void 0 : renderer . unload ( ) , 1e3 ) ;
} ) ;
function onClicked ( ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
yield openFile ( ) ;
dispatch ( "click" ) ;
} ) ;
}
function openFile ( ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
const leaf = $app . workspace . getMostRecentLeaf ( ) ;
yield leaf . openFile ( file ) ;
$app . workspace . setActiveLeaf ( leaf , true , true ) ;
} ) ;
}
function div0 _binding ( $$value ) {
binding _callbacks [ $$value ? "unshift" : "push" ] ( ( ) => {
fileNameContainerEl = $$value ;
$$invalidate ( 4 , fileNameContainerEl ) ;
} ) ;
}
function div3 _binding ( $$value ) {
binding _callbacks [ $$value ? "unshift" : "push" ] ( ( ) => {
contentContainerEl = $$value ;
$$invalidate ( 3 , contentContainerEl ) ;
} ) ;
}
$$self . $$set = ( $$props2 ) => {
if ( "id" in $$props2 )
$$invalidate ( 0 , id = $$props2 . id ) ;
if ( "file" in $$props2 )
$$invalidate ( 1 , file = $$props2 . file ) ;
if ( "selected" in $$props2 )
$$invalidate ( 2 , selected = $$props2 . selected ) ;
if ( "focusEl" in $$props2 )
$$invalidate ( 6 , focusEl = $$props2 . focusEl ) ;
} ;
return [
id ,
file ,
selected ,
contentContainerEl ,
fileNameContainerEl ,
onClicked ,
focusEl ,
path ,
div0 _binding ,
div3 _binding
] ;
}
var CardContainer = class extends SvelteComponent {
constructor ( options ) {
super ( ) ;
init ( this , options , instance4 , create _fragment4 , safe _not _equal , {
id : 0 ,
file : 1 ,
selected : 2 ,
focusEl : 6 ,
path : 7
} , add _css4 ) ;
}
get path ( ) {
return this . $$ . ctx [ 7 ] ;
}
} ;
var CardContainer _default = CardContainer ;
// src/ui/CardViewComponent.svelte
function add _css5 ( target ) {
append _styles ( target , "svelte-pwex1j" , ".card-view-container.svelte-pwex1j{position:absolute;top:0;left:0;width:100%;height:100%;z-index:var(--layer-modal);padding:20px 30px;display:flex;justify-content:center}.card-view-background.svelte-pwex1j{position:absolute;top:0;left:0;width:100%;height:100%;background-color:var(--background-modifier-cover)}.cards-container.svelte-pwex1j{display:grid;grid-gap:20px;height:100%;width:100%;min-height:0}" ) ;
}
function create _fragment5 ( ctx ) {
let div2 ;
let div0 ;
let t ;
let div1 ;
let mounted ;
let dispose ;
return {
c ( ) {
div2 = element ( "div" ) ;
div0 = element ( "div" ) ;
t = space ( ) ;
div1 = element ( "div" ) ;
attr ( div0 , "class" , "card-view-background svelte-pwex1j" ) ;
attr ( div1 , "class" , "cards-container svelte-pwex1j" ) ;
attr ( div2 , "class" , "card-view-container svelte-pwex1j" ) ;
} ,
m ( target , anchor ) {
insert ( target , div2 , anchor ) ;
append ( div2 , div0 ) ;
append ( div2 , t ) ;
append ( div2 , div1 ) ;
ctx [ 10 ] ( div1 ) ;
if ( ! mounted ) {
dispose = listen ( div0 , "click" , ctx [ 9 ] ) ;
mounted = true ;
}
} ,
p : noop ,
i : noop ,
o : noop ,
d ( detaching ) {
if ( detaching )
detach ( div2 ) ;
ctx [ 10 ] ( null ) ;
mounted = false ;
dispose ( ) ;
}
} ;
}
function cardsPerPage ( layout ) {
if ( ! checkLayout ( layout ) )
return 0 ;
return layout [ 0 ] * layout [ 1 ] ;
}
function setLayout ( contentEl , layout ) {
if ( ! contentEl )
return ;
if ( ! checkLayout ( layout ) )
return ;
contentEl . style . gridTemplateColumns = ` repeat( ${ layout [ 1 ] } , minmax(0, 1fr)) ` ;
contentEl . style . gridTemplateRows = ` repeat( ${ layout [ 0 ] } , 1fr) ` ;
}
function checkLayout ( layout ) {
const check = ( x ) => Number . isInteger ( x ) && x > 0 ;
return check ( layout [ 0 ] ) && check ( layout [ 1 ] ) ;
}
function instance5 ( $$self , $$props , $$invalidate ) {
let { layout } = $$props ;
let { focusEl } = $$props ;
let contentEl ;
let cards = [ ] ;
const dispatcher = createEventDispatcher ( ) ;
function addCard ( file ) {
if ( ! contentEl )
return ;
if ( ! focusEl )
return ;
if ( cards . length >= cardsPerPage ( layout ) )
return ;
const card = new CardContainer _default ( {
target : contentEl ,
props : {
file ,
id : cards . length ,
selected : false ,
focusEl
}
} ) ;
cards . push ( card ) ;
}
function renderPage ( files ) {
files . forEach ( ( file ) => {
addCard ( file ) ;
} ) ;
}
function focusOn ( id ) {
const pos = id % cardsPerPage ( layout ) ;
[ - 1 , 0 , 1 ] . forEach ( ( i ) => {
const card = cards [ pos + i ] ;
if ( ! card )
return ;
if ( i == 0 ) {
card . $set ( { selected : true } ) ;
} else {
card . $set ( { selected : false } ) ;
}
} ) ;
}
function detachCards ( ) {
cards . forEach ( ( card ) => {
card . $destroy ( ) ;
} ) ;
cards = [ ] ;
}
function checkCardsRenderedCorrectly ( files ) {
if ( ! checkLayout ( layout ) )
return false ;
for ( let i = 0 ; i < cardsPerPage ( layout ) ; i ++ ) {
const file = files [ i ] ;
const card = cards [ i ] ;
if ( ( file === null || file === void 0 ? void 0 : file . path ) !== ( card === null || card === void 0 ? void 0 : card . path ( ) ) ) {
return false ;
}
}
return true ;
}
onMount ( ( ) => {
setLayout ( contentEl , layout ) ;
} ) ;
onDestroy ( ( ) => {
detachCards ( ) ;
} ) ;
const click _handler = ( ) => {
dispatcher ( "should-destroy" ) ;
} ;
function div1 _binding ( $$value ) {
binding _callbacks [ $$value ? "unshift" : "push" ] ( ( ) => {
contentEl = $$value ;
$$invalidate ( 0 , contentEl ) ;
} ) ;
}
$$self . $$set = ( $$props2 ) => {
if ( "layout" in $$props2 )
$$invalidate ( 2 , layout = $$props2 . layout ) ;
if ( "focusEl" in $$props2 )
$$invalidate ( 3 , focusEl = $$props2 . focusEl ) ;
} ;
return [
contentEl ,
dispatcher ,
layout ,
focusEl ,
addCard ,
renderPage ,
focusOn ,
detachCards ,
checkCardsRenderedCorrectly ,
click _handler ,
div1 _binding
] ;
}
var CardViewComponent = class extends SvelteComponent {
constructor ( options ) {
super ( ) ;
init ( this , options , instance5 , create _fragment5 , safe _not _equal , {
layout : 2 ,
focusEl : 3 ,
addCard : 4 ,
renderPage : 5 ,
focusOn : 6 ,
detachCards : 7 ,
checkCardsRenderedCorrectly : 8
} , add _css5 ) ;
}
get addCard ( ) {
return this . $$ . ctx [ 4 ] ;
}
get renderPage ( ) {
return this . $$ . ctx [ 5 ] ;
}
get focusOn ( ) {
return this . $$ . ctx [ 6 ] ;
}
get detachCards ( ) {
return this . $$ . ctx [ 7 ] ;
}
get checkCardsRenderedCorrectly ( ) {
return this . $$ . ctx [ 8 ] ;
}
} ;
var CardViewComponent _default = CardViewComponent ;
// src/ui/WorkspacePreview.svelte
function add _css6 ( target ) {
append _styles ( target , "svelte-1fata0e" , ".core-search-assistant_workspace-preview_container.svelte-1fata0e{position:absolute;top:0;left:0;width:100%;height:100%;z-index:var(--layer-modal);background-color:var(--background-primary);padding:20px 30px;overflow:auto}.core-search-assistant_workspace-preview_container.svelte-1fata0e .highlight-search-match{color:var(--highlight-search-match);background-color:var(--highlight-search-match-bg)}.core-search-assistant_workspace-preview_container.svelte-1fata0e .focus-search-match{background-color:var(--focus-search-match-bg)}.core-search-assistant_workspace-preview_container.svelte-1fata0e .workspace-leaf{contain:initial !important;height:100%}.core-search-assistant_workspace-preview_container.svelte-1fata0e .workspace-leaf-resize-handle{display:none}.core-search-assistant_workspace-preview_container.svelte-1fata0e .view-header{display:none}.core-search-assistant_workspace-preview_container.svelte-1fata0e .view-content{overflow:hidden}.core-search-assistant_workspace-preview_container.svelte-1fata0e .markdown-preview-view{padding:0}.core-search-assistant_workspace-preview_container.svelte-1fata0e .modal-content{margin:0}.core-search-assistant_workspace-preview_container.svelte-1fata0e .markdown-source-view.mod-cm6 .cm-editor{flex:initial;display:initial}.core-search-assistant_workspace-preview_container.svelte-1fata0e .markdown-source-view.mod-cm6{display:initial}.core-search-assistant_workspace-preview_container.svelte-1fata0e .markdown-source-view{pointer-events:none}.core-search-assistant_workspace-preview_container.svelte-1fata0e .markdown-source-view.mod-cm6 .cm-scroller{padding:0}" ) ;
}
function create _fragment6 ( ctx ) {
let div1 ;
let div0 ;
let t _value = ` ${ ctx [ 0 ] . extension . toUpperCase ( ) } file ` ;
let t ;
return {
c ( ) {
div1 = element ( "div" ) ;
div0 = element ( "div" ) ;
t = text ( t _value ) ;
attr ( div0 , "class" , "content-not-supported-file-format" ) ;
attr ( div1 , "class" , "core-search-assistant_workspace-preview_container svelte-1fata0e" ) ;
} ,
m ( target , anchor ) {
insert ( target , div1 , anchor ) ;
append ( div1 , div0 ) ;
append ( div0 , t ) ;
ctx [ 4 ] ( div1 ) ;
} ,
p ( ctx2 , [ dirty ] ) {
if ( dirty & 1 && t _value !== ( t _value = ` ${ ctx2 [ 0 ] . extension . toUpperCase ( ) } file ` ) )
set _data ( t , t _value ) ;
} ,
i : noop ,
o : noop ,
d ( detaching ) {
if ( detaching )
detach ( div1 ) ;
ctx [ 4 ] ( null ) ;
}
} ;
}
function instance6 ( $$self , $$props , $$invalidate ) {
let $app ;
component _subscribe ( $$self , app , ( $$value ) => $$invalidate ( 6 , $app = $$value ) ) ;
let { file } = $$props ;
let { matches } = $$props ;
let { focusEl } = $$props ;
let containerEl ;
let renderer ;
onMount ( ( ) => _ _awaiter ( void 0 , void 0 , void 0 , function * ( ) {
if ( ! containerEl )
return ;
const fileType = fileTypeMap [ file . extension ] ;
if ( fileType !== void 0 ) {
containerEl . empty ( ) ;
renderer = yield new ViewGenerator ( $app , containerEl , file ) . registerExtension ( new ExcalidrawViewGeneratorExtension ( $app ) ) . registerExtension ( new KanbanViewGeneratorExtension ( $app ) ) . registerExtension ( new MarkdownViewGeneratorExtension ( ) ) . registerExtension ( new NonMarkdownViewGeneratorExtension ( ) ) . load ( "source" ) ;
highlightMatches ( ) ;
}
focusEl === null || focusEl === void 0 ? void 0 : focusEl . focus ( ) ;
} ) ) ;
onDestroy ( ( ) => {
setTimeout ( ( ) => renderer === null || renderer === void 0 ? void 0 : renderer . unload ( ) , 1e3 ) ;
} ) ;
function highlightMatches ( ) {
renderer === null || renderer === void 0 ? void 0 : renderer . highlightMatches ( matches !== null && matches !== void 0 ? matches : [ ] , "highlight-search-match" ) ;
}
function div1 _binding ( $$value ) {
binding _callbacks [ $$value ? "unshift" : "push" ] ( ( ) => {
containerEl = $$value ;
$$invalidate ( 1 , containerEl ) ;
} ) ;
}
$$self . $$set = ( $$props2 ) => {
if ( "file" in $$props2 )
$$invalidate ( 0 , file = $$props2 . file ) ;
if ( "matches" in $$props2 )
$$invalidate ( 2 , matches = $$props2 . matches ) ;
if ( "focusEl" in $$props2 )
$$invalidate ( 3 , focusEl = $$props2 . focusEl ) ;
} ;
return [ file , containerEl , matches , focusEl , div1 _binding ] ;
}
var WorkspacePreview = class extends SvelteComponent {
constructor ( options ) {
super ( ) ;
init ( this , options , instance6 , create _fragment6 , safe _not _equal , { file : 0 , matches : 2 , focusEl : 3 } , add _css6 ) ;
}
} ;
var WorkspacePreview _default = WorkspacePreview ;
// src/ui/Outline.svelte
function add _css7 ( target ) {
append _styles ( target , "svelte-f5i2qg" , ".outline-container.svelte-f5i2qg{position:absolute;top:0;left:0;width:100%;height:100%;z-index:var(--layer-modal);pointer-events:none}" ) ;
}
function create _fragment7 ( ctx ) {
let div ;
return {
c ( ) {
div = element ( "div" ) ;
attr ( div , "class" , "outline-container svelte-f5i2qg" ) ;
} ,
m ( target , anchor ) {
insert ( target , div , anchor ) ;
ctx [ 2 ] ( div ) ;
} ,
p : noop ,
i : noop ,
o : noop ,
d ( detaching ) {
if ( detaching )
detach ( div ) ;
ctx [ 2 ] ( null ) ;
}
} ;
}
var STYLE _VAR _COLOR _SEARCH _MODE _OUTLINE = "--search-mode-outline" ;
function instance7 ( $$self , $$props , $$invalidate ) {
let { lineWidth } = $$props ;
let el ;
onMount ( ( ) => {
if ( ! el )
return ;
$$invalidate ( 0 , el . style . outline = ` ${ lineWidth } px solid var( ${ STYLE _VAR _COLOR _SEARCH _MODE _OUTLINE } ) ` , el ) ;
$$invalidate ( 0 , el . style . outlineOffset = ` - ${ lineWidth } px ` , el ) ;
} ) ;
function div _binding ( $$value ) {
binding _callbacks [ $$value ? "unshift" : "push" ] ( ( ) => {
el = $$value ;
$$invalidate ( 0 , el ) ;
} ) ;
}
$$self . $$set = ( $$props2 ) => {
if ( "lineWidth" in $$props2 )
$$invalidate ( 1 , lineWidth = $$props2 . lineWidth ) ;
} ;
return [ el , lineWidth , div _binding ] ;
}
var Outline = class extends SvelteComponent {
constructor ( options ) {
super ( ) ;
init ( this , options , instance7 , create _fragment7 , safe _not _equal , { lineWidth : 1 } , add _css7 ) ;
}
} ;
var Outline _default = Outline ;
// src/Controller.ts
var DELAY _TO _RELOAD _IN _MILLISECOND = 1e3 ;
var RETRY _INTERVAL = 1 ;
var RETRY _TRIALS = 1e3 ;
var DELAY _TO _RENDER _CARD _VIEW _ON _ENTRY _IN _MILLISECOND = 100 ;
var Controller = class extends obsidian . Component {
constructor ( app2 , plugin2 , events , searchInterface ) {
super ( ) ;
this . app = app2 ;
this . plugin = plugin2 ;
this . events = events ;
this . searchInterface = searchInterface ;
this . modeScope = new ModeScope ( ) ;
this . cardViewCheckDebouncer = ( 0 , import _obsidian14 . debounce ) ( this . onCheckCardView , DELAY _TO _RELOAD _IN _MILLISECOND , true ) ;
this . countSearchItemDetected = 0 ;
}
onunload ( ) {
this . exit ( ) ;
}
onload ( ) {
this . saveLayout ( ) ;
this . setSearchModeTriggers ( ) ;
}
enter ( ) {
return _ _async ( this , null , function * ( ) {
var _a , _b ;
if ( this . modeScope . inSearchMode ) {
return ;
}
this . setHotkeys ( ) ;
this . addChildren ( ) ;
if ( ( _a = this . plugin . settings ) == null ? void 0 : _a . autoToggleSidebar ) {
this . collapseOppositeSidedock ( ) ;
}
const shouldDetectSearchItems = ( ( _b = this . plugin . settings ) == null ? void 0 : _b . autoPreviewMode ) === "cardView" && this . plugin . settings . renderCardsManually === false ;
if ( shouldDetectSearchItems ) {
this . searchInterface . startWatching ( this . events ) ;
yield delay ( DELAY _TO _RENDER _CARD _VIEW _ON _ENTRY _IN _MILLISECOND ) ;
this . renewCardViewPage ( ) ;
this . cardViewCheckDebouncer ( ) ;
}
this . modeScope . push ( ) ;
} ) ;
}
reset ( ) {
var _a ;
if ( ! this . modeScope . inSearchMode ) {
return ;
}
this . forget ( ) ;
this . unfocus ( ) ;
( _a = this . cardViewComponent ) == null ? void 0 : _a . detachCards ( ) ;
this . countSearchItemDetected = 0 ;
}
exit ( reason ) {
var _a ;
if ( ! this . modeScope . inSearchMode ) {
return ;
}
this . reset ( ) ;
this . detachHotkeys ( ) ;
this . removeChildren ( ) ;
if ( this . shouldCollapseSidedock ( reason ) ) {
this . collapseSidedock ( ) ;
}
if ( ( _a = this . plugin . settings ) == null ? void 0 : _a . autoToggleSidebar ) {
this . restoreOppositeSidedock ( ) ;
}
this . countSearchItemDetected = 0 ;
this . searchInterface . stopWatching ( ) ;
this . unfocus ( ) ;
this . modeScope . reset ( ) ;
}
focus ( ) {
var _a ;
if ( this . currentFocusId === void 0 ) {
return ;
}
this . searchInterface . focusOn ( this . currentFocusId ) ;
( _a = this . cardViewComponent ) == null ? void 0 : _a . focusOn ( this . currentFocusId ) ;
}
open ( direction ) {
if ( this . currentFocusId === void 0 ) {
return ;
}
this . searchInterface . open ( this . currentFocusId , direction ) ;
}
renewCardViewPage ( ) {
return _ _async ( this , null , function * ( ) {
var _a , _b , _c , _d , _e ;
if ( ( ( _a = this . plugin . settings ) == null ? void 0 : _a . autoPreviewMode ) !== "cardView" )
return ;
( _b = this . cardViewComponent ) == null ? void 0 : _b . detachCards ( ) ;
( _c = this . cardViewComponent ) == null ? void 0 : _c . renderPage ( this . filesToBeRendered ( ) ) ;
if ( this . currentFocusId !== void 0 ) {
( _e = this . cardViewComponent ) == null ? void 0 : _e . focusOn ( ( _d = this . currentFocusId ) != null ? _d : 0 ) ;
}
} ) ;
}
filesToBeRendered ( ) {
var _a , _b ;
const cardsPerPage2 = this . cardsPerPage ( ) ;
if ( cardsPerPage2 === void 0 ) {
return [ ] ;
}
const pageId = Math . floor ( ( ( _a = this . currentFocusId ) != null ? _a : 0 ) / cardsPerPage2 ) ;
const items = ( _b = this . plugin . searchInterface ) == null ? void 0 : _b . resultItems ;
if ( ! items )
return [ ] ;
return items . slice ( pageId * cardsPerPage2 ) . map ( ( item ) => item . file ) ;
}
collapseSidedock ( ) {
var _a ;
( _a = this . plugin . searchInterface ) == null ? void 0 : _a . collapseSidedock ( ) ;
}
collapseOppositeSidedock ( ) {
var _a , _b , _c ;
const collapsed = ( _b = ( _a = this . plugin . searchInterface ) == null ? void 0 : _a . oppositeSidedock ) == null ? void 0 : _b . collapsed ;
( _c = this . plugin . searchInterface ) == null ? void 0 : _c . collapseOppositeSidedock ( ) ;
this . _restoreOppositeSidedock = ( ) => {
var _a2 ;
if ( collapsed === false ) {
( _a2 = this . plugin . searchInterface ) == null ? void 0 : _a2 . expandOppositeSidedock ( ) ;
}
} ;
}
restoreOppositeSidedock ( ) {
const restoreOppositeSidedock = this . _restoreOppositeSidedock ;
if ( restoreOppositeSidedock === void 0 ) {
return void 0 ;
}
return restoreOppositeSidedock ( ) ;
}
addChildren ( ) {
this . removeChildren ( ) ;
const { settings } = this . plugin ;
if ( settings === void 0 ) {
throw "[ERROR in Core Search Assistant] failed to addChildren: failed to read setting" ;
}
this . outline = new Outline _default ( {
target : document . body ,
props : {
lineWidth : settings . outlineWidth
}
} ) ;
if ( settings . autoPreviewMode === "cardView" ) {
this . renewCardViewComponent ( ) ;
}
}
removeChildren ( ) {
var _a , _b , _c ;
( _a = this . outline ) == null ? void 0 : _a . $destroy ( ) ;
this . outline = void 0 ;
( _b = this . cardViewComponent ) == null ? void 0 : _b . $destroy ( ) ;
this . cardViewComponent = void 0 ;
( _c = this . workspacePreviewComponent ) == null ? void 0 : _c . $destroy ( ) ;
this . workspacePreviewComponent = void 0 ;
}
forget ( ) {
this . currentFocusId = void 0 ;
this . countSearchItemDetected = 0 ;
}
navigateForward ( ) {
var _a ;
let updated = true ;
const numResults = ( _a = this . searchInterface . count ( ) ) != null ? _a : 0 ;
if ( this . currentFocusId === void 0 ) {
this . currentFocusId = 0 ;
} else {
this . currentFocusId ++ ;
if ( this . currentFocusId >= numResults ) {
this . currentFocusId = numResults - 1 ;
updated = false ;
}
}
if ( ! updated )
return ;
const { settings } = this . plugin ;
if ( ! settings )
return ;
if ( settings . autoPreviewMode === "cardView" && this . shouldTransitNextPageInCardView ( ) ) {
this . renewCardViewPage ( ) ;
} else if ( settings . autoPreviewMode === "singleView" ) {
this . renewWorkspacePreviewComponent ( ) ;
}
this . focus ( ) ;
}
navigateBack ( ) {
if ( this . currentFocusId === void 0 ) {
return ;
}
let updated = true ;
this . currentFocusId -- ;
if ( this . currentFocusId < 0 ) {
this . currentFocusId = 0 ;
updated = false ;
}
if ( ! updated )
return ;
const { settings } = this . plugin ;
if ( ! settings )
return ;
if ( settings . autoPreviewMode === "cardView" && this . shouldTransitPreviousPageInCardView ( ) ) {
this . renewCardViewPage ( ) ;
} else if ( settings . autoPreviewMode === "singleView" ) {
this . renewWorkspacePreviewComponent ( ) ;
}
this . focus ( ) ;
}
moveToNextPage ( ) {
const pageId = this . pageId ;
if ( pageId === void 0 )
return ;
const pageCount = this . pageCount ;
if ( pageCount === void 0 )
return ;
if ( pageId >= pageCount - 1 )
return ;
const cardsPerPage2 = this . cardsPerPage ( ) ;
if ( cardsPerPage2 === void 0 )
return ;
this . currentFocusId = cardsPerPage2 * ( pageId + 1 ) ;
this . renewCardViewPage ( ) ;
this . focus ( ) ;
}
moveToPreviousPage ( ) {
const pageId = this . pageId ;
if ( pageId === void 0 )
return ;
const pageCount = this . pageCount ;
if ( pageCount === void 0 )
return ;
if ( pageId <= 0 )
return ;
const cardsPerPage2 = this . cardsPerPage ( ) ;
if ( cardsPerPage2 === void 0 )
return ;
this . currentFocusId = cardsPerPage2 * ( pageId - 1 ) ;
this . renewCardViewPage ( ) ;
this . focus ( ) ;
}
unfocus ( ) {
this . searchInterface . unfocus ( ) ;
}
openPreviewModal ( ) {
const { currentFocusId } = this ;
if ( currentFocusId === void 0 ) {
return ;
}
const item = this . searchInterface . getResultItemAt ( currentFocusId ) ;
if ( ! item ) {
return ;
}
new PreviewModal ( this . app , this . plugin , this . modeScope , item ) . open ( ) ;
}
shouldTransitNextPageInCardView ( ) {
if ( this . currentFocusId === void 0 || this . currentFocusId === 0 ) {
return false ;
}
if ( ! this . plugin . settings ) {
return false ;
}
const [ row , column ] = parseCardLayout ( this . plugin . settings . cardViewLayout ) ;
const cardsPerPage2 = row * column ;
return this . currentFocusId % cardsPerPage2 === 0 ;
}
shouldTransitPreviousPageInCardView ( ) {
if ( ! this . plugin . settings ) {
return false ;
}
const [ row , column ] = parseCardLayout ( this . plugin . settings . cardViewLayout ) ;
const cardsPerPage2 = row * column ;
if ( this . currentFocusId === void 0 ) {
return false ;
}
return ( this . currentFocusId + 1 ) % cardsPerPage2 === 0 ;
}
get pageId ( ) {
if ( this . currentFocusId === void 0 )
return void 0 ;
const cardsPerPage2 = this . cardsPerPage ( ) ;
if ( cardsPerPage2 === void 0 )
return void 0 ;
const pageId = Math . floor ( this . currentFocusId / cardsPerPage2 ) ;
return pageId ;
}
get pageCount ( ) {
var _a ;
const numResults = ( _a = this . plugin . searchInterface ) == null ? void 0 : _a . count ( ) ;
const cardsPerPage2 = this . cardsPerPage ( ) ;
if ( cardsPerPage2 === void 0 )
return void 0 ;
const pageCount = Math . ceil ( ( numResults != null ? numResults : 0 ) / cardsPerPage2 ) ;
return pageCount ;
}
cardsPerPage ( ) {
if ( ! this . plugin . settings ) {
return void 0 ;
}
const [ row , column ] = parseCardLayout ( this . plugin . settings . cardViewLayout ) ;
return row * column ;
}
saveLayout ( ) {
this . app . workspace . onLayoutReady ( ( ) => _ _async ( this , null , function * ( ) {
const inputEl = yield retry ( ( ) => this . searchInterface . searchInputEl , RETRY _INTERVAL , RETRY _TRIALS ) ;
this . _layoutChanged = ( ) => _ _async ( this , null , function * ( ) {
return inputEl !== ( yield retry ( ( ) => this . searchInterface . searchInputEl , RETRY _INTERVAL , RETRY _TRIALS ) ) ;
} ) ;
} ) ) ;
}
layoutChanged ( ) {
return _ _async ( this , null , function * ( ) {
var _a ;
const shouldRenewController = yield ( _a = this . _layoutChanged ) == null ? void 0 : _a . call ( this ) ;
if ( shouldRenewController === void 0 ) {
throw "[ERROR in Core Search Assistant] failed to renewRequired: saveLayout was not called." ;
}
return shouldRenewController ;
} ) ;
}
setSearchModeTriggers ( ) {
this . registerEvent ( this . events . on ( EVENT _SEARCH _RESULT _ITEM _DETECTED , this . onSearchResultItemDetected ) ) ;
this . registerEvent ( this . events . on ( EVENT _SORT _ORDER _CHANGED , this . onSortOrderChanged ) ) ;
this . app . workspace . onLayoutReady ( ( ) => _ _async ( this , null , function * ( ) {
const appContainerEl = yield retry ( ( ) => this . app . dom . appContainerEl , RETRY _INTERVAL , RETRY _TRIALS ) ;
if ( appContainerEl === void 0 ) {
throw "[ERROR in Core Search Assistant] failed to find the app container element" ;
}
const inputEl = yield retry ( ( ) => {
var _a ;
return ( _a = this . plugin . searchInterface ) == null ? void 0 : _a . searchInputEl ;
} , RETRY _INTERVAL , RETRY _TRIALS ) ;
if ( inputEl === void 0 ) {
throw "[ERROR in Core Search Assistant] failed to find the search input form." ;
}
const matchingCaseButtonEl = yield retry ( ( ) => {
var _a ;
return ( _a = this . plugin . searchInterface ) == null ? void 0 : _a . matchingCaseButtonEl ;
} , RETRY _INTERVAL , RETRY _TRIALS ) ;
if ( matchingCaseButtonEl === void 0 ) {
throw "[ERROR in Core Search Assistant] failed to find the matching case button." ;
}
this . registerDomEvent ( appContainerEl , "click" , ( evt ) => {
var _a , _b , _c , _d , _e ;
const targetEl = evt . target ;
if ( ! ( targetEl instanceof HTMLElement ) ) {
return ;
}
if ( ( _b = ( _a = this . plugin . searchInterface ) == null ? void 0 : _a . searchLeaf ) == null ? void 0 : _b . containerEl . contains ( targetEl ) ) {
if ( ! this . plugin . searchInterface . isBuiltInElementToOpenFile ( targetEl ) )
return ;
}
if ( ( _d = ( _c = this . plugin . searchInterface ) == null ? void 0 : _c . tabHeaderEl ) == null ? void 0 : _d . contains ( targetEl ) ) {
return ;
}
if ( ( _e = this . plugin . searchInterface ) == null ? void 0 : _e . isShowMoreContextButton ( targetEl ) ) {
return ;
}
if ( this . modeScope . depth === 1 ) {
this . exit ( { id : "mouse" , event : evt } ) ;
}
} ) ;
this . registerDomEvent ( matchingCaseButtonEl , "click" , ( ) => {
if ( this . modeScope . inSearchMode ) {
this . reset ( ) ;
}
} ) ;
this . registerDomEvent ( inputEl , "input" , ( ) => {
if ( ! this . modeScope . inSearchMode ) {
this . enter ( ) ;
}
this . reset ( ) ;
} ) ;
this . registerDomEvent ( inputEl , "keypress" , ( evt ) => {
if ( evt . key !== "Enter" ) {
return ;
}
if ( ! this . modeScope . inSearchMode ) {
this . enter ( ) ;
}
this . reset ( ) ;
} ) ;
this . registerDomEvent ( inputEl , "focus" , ( ) => {
if ( ! this . modeScope . inSearchMode ) {
this . enter ( ) ;
}
} ) ;
} ) ) ;
}
setHotkeys ( ) {
var _a ;
const hotkeyMap = ( _a = this . plugin . settings ) == null ? void 0 : _a . searchModeHotkeys ;
if ( ! hotkeyMap )
return ;
const scope = new obsidian . Scope ( ) ;
this . app . keymap . pushScope ( scope ) ;
hotkeyMap . selectNext . forEach ( ( hotkey ) => {
scope . register ( hotkey . modifiers , hotkey . key , ( evt ) => {
evt . preventDefault ( ) ;
this . navigateForward ( ) ;
} ) ;
} ) ;
hotkeyMap . selectPrevious . forEach ( ( hotkey ) => {
scope . register ( hotkey . modifiers , hotkey . key , ( evt ) => {
evt . preventDefault ( ) ;
this . navigateBack ( ) ;
} ) ;
} ) ;
hotkeyMap . open . forEach ( ( hotkey ) => {
scope . register ( hotkey . modifiers , hotkey . key , ( evt ) => {
evt . preventDefault ( ) ;
this . open ( ) ;
this . exit ( ) ;
} ) ;
} ) ;
hotkeyMap . openInNewPane . forEach ( ( hotkey ) => {
scope . register ( hotkey . modifiers , hotkey . key , ( evt ) => {
var _a2 ;
evt . preventDefault ( ) ;
this . open ( ( _a2 = this . plugin . settings ) == null ? void 0 : _a2 . splitDirection ) ;
this . exit ( ) ;
} ) ;
} ) ;
hotkeyMap . previewModal . forEach ( ( hotkey ) => {
scope . register ( hotkey . modifiers , hotkey . key , ( ) => {
if ( this . app . vault . config . legacyEditor ) {
return ;
}
this . openPreviewModal ( ) ;
} ) ;
} ) ;
hotkeyMap . showOptions . forEach ( ( hotkey ) => {
scope . register ( hotkey . modifiers , hotkey . key , ( ) => {
new OptionModal ( this . app , this . plugin , this . modeScope ) . open ( ) ;
} ) ;
} ) ;
hotkeyMap . nextPage . forEach ( ( hotkey ) => {
scope . register ( hotkey . modifiers , hotkey . key , ( ) => {
var _a2 ;
if ( ( ( _a2 = this . plugin . settings ) == null ? void 0 : _a2 . autoPreviewMode ) === "cardView" ) {
this . moveToNextPage ( ) ;
}
} ) ;
} ) ;
hotkeyMap . previousPage . forEach ( ( hotkey ) => {
scope . register ( hotkey . modifiers , hotkey . key , ( ) => {
var _a2 ;
if ( ( ( _a2 = this . plugin . settings ) == null ? void 0 : _a2 . autoPreviewMode ) === "cardView" ) {
this . moveToPreviousPage ( ) ;
}
} ) ;
} ) ;
hotkeyMap . copyLink . forEach ( ( hotkey ) => {
scope . register ( hotkey . modifiers , hotkey . key , ( ) => {
var _a2 ;
const item = this . searchInterface . getResultItemAt ( ( _a2 = this . currentFocusId ) != null ? _a2 : 0 ) ;
if ( ! item )
return ;
const { file } = item ;
const internalLink = generateInternalLinkFrom ( this . app , file ) ;
navigator . clipboard . writeText ( internalLink ) ;
new import _obsidian14 . Notice ( "Copy wiki link!" ) ;
} ) ;
} ) ;
scope . register ( [ ] , "Escape" , ( evt ) => {
evt . preventDefault ( ) ;
this . exit ( ) ;
} ) ;
scope . register ( [ ] , "Enter" , ( evt ) => {
var _a2 ;
setTimeout ( this . focusOnInput , 100 ) ;
const shouldRenderCardsManually = ( ( _a2 = this . plugin . settings ) == null ? void 0 : _a2 . autoPreviewMode ) === "cardView" && this . plugin . settings . renderCardsManually ;
if ( shouldRenderCardsManually ) {
evt . preventDefault ( ) ;
this . reset ( ) ;
this . renewCardViewPage ( ) ;
}
} ) ;
this . _detachHotkeys = ( ) => {
this . app . keymap . popScope ( scope ) ;
} ;
}
detachHotkeys ( ) {
const detachHotkeys = this . _detachHotkeys ;
if ( detachHotkeys === void 0 ) {
return ;
}
detachHotkeys ( ) ;
}
get onSearchResultItemDetected ( ) {
return ( ) => {
var _a , _b , _c ;
if ( ( ( _a = this . plugin . settings ) == null ? void 0 : _a . autoPreviewMode ) !== "cardView" ) {
return ;
}
if ( this . currentFocusId !== void 0 ) {
return ;
}
if ( this . countSearchItemDetected === 0 ) {
( _b = this . cardViewComponent ) == null ? void 0 : _b . detachCards ( ) ;
}
const item = this . searchInterface . getResultItemAt ( this . countSearchItemDetected ) ;
if ( ! item )
return ;
( _c = this . cardViewComponent ) == null ? void 0 : _c . addCard ( item . file ) ;
this . cardViewCheckDebouncer ( ) ;
this . countSearchItemDetected ++ ;
} ;
}
renewCardViewComponent ( ) {
var _a ;
( _a = this . cardViewComponent ) == null ? void 0 : _a . $destroy ( ) ;
const { settings } = this . plugin ;
if ( ! settings )
return ;
const focusEl = this . searchInterface . searchInputEl ;
if ( ! focusEl )
return ;
const layout = parseCardLayout ( settings . cardViewLayout ) ;
this . app . workspace . onLayoutReady ( ( ) => {
const containerEl = this . app . workspace . rootSplit . containerEl ;
const cardViewComponent = new CardViewComponent _default ( {
target : containerEl ,
props : {
layout ,
focusEl
}
} ) ;
this . cardViewComponent = cardViewComponent ;
} ) ;
}
renewWorkspacePreviewComponent ( ) {
var _a ;
( _a = this . workspacePreviewComponent ) == null ? void 0 : _a . $destroy ( ) ;
if ( this . currentFocusId === void 0 )
return ;
const focusEl = this . searchInterface . searchInputEl ;
if ( ! focusEl )
return ;
const item = this . searchInterface . getResultItemAt ( this . currentFocusId ) ;
if ( ! item )
return ;
this . app . workspace . onLayoutReady ( ( ) => {
var _a2 ;
const containerEl = this . app . workspace . rootSplit . containerEl ;
const workspacePreviewComponent = new WorkspacePreview _default ( {
target : containerEl ,
props : {
file : item . file ,
matches : ( _a2 = item . result . content ) != null ? _a2 : [ ] ,
focusEl
}
} ) ;
this . workspacePreviewComponent = workspacePreviewComponent ;
} ) ;
}
get focusOnInput ( ) {
return ( ) => _ _async ( this , null , function * ( ) {
const inputEl = yield retry ( ( ) => {
var _a ;
return ( _a = this . plugin . searchInterface ) == null ? void 0 : _a . searchInputEl ;
} , RETRY _INTERVAL , RETRY _TRIALS ) ;
if ( inputEl === void 0 ) {
throw "[ERROR in Core Search Assistant] failed to find the search input form." ;
}
inputEl . focus ( ) ;
} ) ;
}
get onSortOrderChanged ( ) {
return ( ) => {
var _a ;
this . reset ( ) ;
if ( ( ( _a = this . plugin . settings ) == null ? void 0 : _a . autoPreviewMode ) === "cardView" ) {
this . renewCardViewPage ( ) ;
}
} ;
}
shouldCollapseSidedock ( reason ) {
var _a , _b ;
if ( ! ( ( _a = this . plugin . settings ) == null ? void 0 : _a . autoToggleSidebar ) ) {
return false ;
}
if ( reason === void 0 ) {
return true ;
}
if ( reason . id !== "mouse" ) {
return true ;
}
const targetEl = reason . event . target ;
if ( ! ( targetEl instanceof HTMLElement ) ) {
return true ;
}
return ! ( ( _b = this . searchInterface . sideDock ) == null ? void 0 : _b . containerEl . contains ( targetEl ) ) ;
}
get onCheckCardView ( ) {
return ( ) => {
const { cardViewComponent } = this ;
if ( ! cardViewComponent )
return ;
const ok = cardViewComponent . checkCardsRenderedCorrectly ( this . filesToBeRendered ( ) ) ;
if ( ! ok ) {
this . reset ( ) ;
this . renewCardViewPage ( ) ;
}
} ;
}
} ;
// src/interfaces/SearchComponentInterface.ts
var import _obsidian16 = _ _toModule ( require ( "obsidian" ) ) ;
// src/types/Guards.ts
var import _obsidian15 = _ _toModule ( require ( "obsidian" ) ) ;
var SORT _ORDER _IN _SEARCH = [
"alphabeticalReverse" ,
"alphabetical" ,
"byModifiedTime" ,
"byModifiedTimeReverse" ,
"byCreatedTime" ,
"byCreatedTimeReverse"
] ;
function isSearchView ( view ) {
if ( typeof view !== "object" ) {
return false ;
}
if ( view === null ) {
return false ;
}
const {
matchingCase ,
explainSearch ,
dom ,
setCollapseAll ,
setExplainSearch ,
setExtraContext ,
setMatchingCase ,
setSortOrder ,
searchInfoEl ,
2024-04-15 11:54:03 +08:00
searchComponent
2023-06-29 11:55:02 +08:00
} = view ;
if ( typeof matchingCase !== "boolean" ) {
return false ;
}
if ( typeof explainSearch !== "boolean" ) {
return false ;
}
if ( ! isSearchDom ( dom ) ) {
return false ;
}
if ( typeof searchComponent !== "object" ) {
return false ;
}
if ( typeof searchInfoEl !== "object" ) {
return false ;
}
if ( ! ( searchInfoEl instanceof HTMLDivElement ) ) {
return false ;
}
if ( ! ( setCollapseAll instanceof Function ) ) {
return false ;
}
if ( ! ( setExplainSearch instanceof Function ) ) {
return false ;
}
if ( ! ( setExtraContext instanceof Function ) ) {
return false ;
}
if ( ! ( setMatchingCase instanceof Function ) ) {
return false ;
}
if ( ! ( setSortOrder instanceof Function ) ) {
return false ;
}
return true ;
}
function isSearchDom ( obj ) {
if ( typeof obj !== "object" ) {
return false ;
}
if ( obj === null ) {
return false ;
}
const { extraContext , collapseAll , sortOrder , vChildren , childrenEl } = obj ;
if ( typeof extraContext !== "boolean" ) {
return false ;
}
if ( typeof collapseAll !== "boolean" ) {
return false ;
}
if ( typeof sortOrder !== "string" ) {
return false ;
}
if ( ! SORT _ORDER _IN _SEARCH . includes ( sortOrder ) ) {
return false ;
}
if ( ! isSearchResultItemGroup ( vChildren ) ) {
return false ;
}
if ( typeof childrenEl !== "object" ) {
return false ;
}
if ( ! ( childrenEl instanceof HTMLElement ) ) {
return false ;
}
return true ;
}
function isSearchResultItemGroup ( obj ) {
if ( typeof obj !== "object" || obj === null ) {
return false ;
}
const { _children : children2 } = obj ;
if ( typeof children2 !== "object" ) {
return false ;
}
if ( ! ( children2 instanceof Array ) ) {
return false ;
}
for ( const child of children2 ) {
if ( ! isSearchResultItem ( child ) ) {
return false ;
}
}
return true ;
}
function isSearchResultItem ( obj ) {
if ( typeof obj !== "object" || obj === null ) {
return false ;
}
const { file , containerEl } = obj ;
if ( ! ( file instanceof import _obsidian15 . TFile ) ) {
return false ;
}
if ( ! ( containerEl instanceof HTMLElement ) ) {
return false ;
}
return true ;
}
// src/utils/LinkedList.ts
var LinkedList = class {
constructor ( events , eventId ) {
this . unlinkedPool = new Map ( ) ;
this . events = events ;
this . eventId = eventId ;
}
structure ( cur , pre ) {
let linked = false ;
if ( pre === void 0 ) {
this . setRoot ( cur ) ;
linked = true ;
this . signal ( ) ;
} else if ( this . tail !== void 0 && pre === this . tail . entity ) {
this . link ( cur ) ;
linked = true ;
this . unlinkedPool . delete ( cur ) ;
this . signal ( ) ;
}
if ( linked ) {
if ( ! this . unlinkedPool . has ( cur ) ) {
return ;
}
const next = this . unlinkedPool . get ( cur ) ;
if ( next === void 0 ) {
return ;
}
this . structure ( next , cur ) ;
} else {
if ( pre ) {
this . unlinkedPool . set ( pre , cur ) ;
}
}
}
setRoot ( entity ) {
const rootNode = {
entity ,
pre : void 0 ,
next : void 0
} ;
this . head = rootNode ;
this . tail = rootNode ;
}
link ( cur ) {
if ( ! this . tail ) {
return ;
}
const currentTail = this . tail ;
currentTail . next = {
entity : cur ,
pre : currentTail ,
next : void 0
} ;
this . tail = currentTail . next ;
}
clean ( ) {
this . head = void 0 ;
this . tail = void 0 ;
this . unlinkedPool = new Map ( ) ;
}
signal ( ) {
this . events . trigger ( this . eventId ) ;
}
} ;
// src/interfaces/SearchComponentInterface.ts
var SearchComponentInterface = class extends import _obsidian16 . Component {
constructor ( app2 , plugin2 , events ) {
super ( ) ;
this . observationConfig = {
childList : true
} ;
this . onObservedCallback = ( mutations , _observer ) => _ _async ( this , null , function * ( ) {
for ( const mutation of mutations ) {
if ( mutation . addedNodes . length === 0 ) {
continue ;
}
const pre = mutation . previousSibling ;
if ( ! ( pre instanceof HTMLElement ) ) {
continue ;
}
for ( const node of Array . from ( mutation . addedNodes ) ) {
if ( ! ( node instanceof HTMLElement ) ) {
continue ;
}
const isSearchResultItem2 = node . tagName === "DIV" && node . hasClass ( "tree-item" ) && node . hasClass ( "search-result" ) ;
if ( ! isSearchResultItem2 ) {
continue ;
}
if ( ! this . linkedList ) {
return ;
}
this . linkedList . structure ( node , this . isRootSearchResult ( pre ) ? void 0 : pre ) ;
}
}
} ) ;
this . app = app2 ;
this . plugin = plugin2 ;
this . events = events ;
this . observer = new MutationObserver ( this . onObservedCallback . bind ( this ) ) ;
}
onload ( ) {
this . app . workspace . onLayoutReady ( ( ) => {
this . renewSortOrderInfo ( ) ;
this . registerDomEvent ( document , "click" , ( ) => {
this . renewSortOrderInfo ( this . events ) ;
} ) ;
} ) ;
}
onunload ( ) {
var _a , _b ;
( _a = this . sortOrderContainerEl ) == null ? void 0 : _a . empty ( ) ;
( _b = this . sortOrderContainerEl ) == null ? void 0 : _b . remove ( ) ;
this . observer . disconnect ( ) ;
}
toggleMatchingCase ( ) {
const view = this . searchView ;
view == null ? void 0 : view . setMatchingCase ( ! view . matchingCase ) ;
}
toggleExplainSearch ( ) {
const view = this . searchView ;
view == null ? void 0 : view . setExplainSearch ( ! view . explainSearch ) ;
}
toggleCollapseAll ( ) {
const view = this . searchView ;
view == null ? void 0 : view . setCollapseAll ( ! view . dom . collapseAll ) ;
}
toggleExtraContext ( ) {
const view = this . searchView ;
view == null ? void 0 : view . setExtraContext ( ! view . dom . extraContext ) ;
}
setSortOrder ( sortOrder ) {
const view = this . searchView ;
const originalOrder = view == null ? void 0 : view . dom . sortOrder ;
view == null ? void 0 : view . setSortOrder ( sortOrder ) ;
return sortOrder !== originalOrder ;
}
focusOn ( pos ) {
var _a ;
this . unfocus ( ) ;
const item = this . getResultItemAt ( pos ) ;
if ( ! item ) {
return ;
}
item . containerEl . addClass ( "core-search-assistant_search-result-items-focus" ) ;
item . containerEl . scrollIntoView ( ( ( _a = this . plugin . settings ) == null ? void 0 : _a . keepSelectedItemsCentered ) ? { block : "center" } : { block : "nearest" } ) ;
}
unfocus ( ) {
const items = this . resultItems ;
items . forEach ( ( item ) => {
item . containerEl . removeClass ( "core-search-assistant_search-result-items-focus" ) ;
} ) ;
}
open ( pos , direction ) {
return _ _async ( this , null , function * ( ) {
const item = this . getResultItemAt ( pos ) ;
if ( ! item ) {
return ;
}
const { file } = item ;
const leaf = direction === void 0 ? this . app . workspace . getMostRecentLeaf ( ) : this . app . workspace . splitActiveLeaf ( direction ) ;
yield leaf . openFile ( file ) ;
this . app . workspace . setActiveLeaf ( leaf , true , true ) ;
} ) ;
}
renewSortOrderInfo ( events ) {
if ( ! this . sortOrderContainerEl ) {
this . createSortOrderEls ( ) ;
}
const view = this . searchView ;
if ( ! view ) {
return ;
}
const sortOrder = view . dom . sortOrder ;
if ( ! this . sortOrderContentEl ) {
return ;
}
const originalContent = this . sortOrderContentEl . textContent ;
this . sortOrderContentEl . textContent = searchOptions [ sortOrder ] . description ;
if ( events !== void 0 && originalContent !== this . sortOrderContentEl . textContent ) {
events . trigger ( EVENT _SORT _ORDER _CHANGED ) ;
}
}
count ( ) {
var _a ;
const results = ( _a = this . searchView ) == null ? void 0 : _a . dom . vChildren . _children ;
if ( ! results ) {
return 0 ;
}
return results . length ;
}
get resultItems ( ) {
var _a , _b ;
return ( _b = ( _a = this . searchView ) == null ? void 0 : _a . dom . vChildren . _children ) != null ? _b : [ ] ;
}
getResultItemAt ( pos ) {
var _a ;
return ( _a = this . searchView ) == null ? void 0 : _a . dom . vChildren . _children [ pos ] ;
}
get searchInputEl ( ) {
var _a ;
return ( _a = this . searchView ) == null ? void 0 : _a . searchComponent . inputEl ;
}
startWatching ( events ) {
var _a ;
this . linkedList = new LinkedList ( events , EVENT _SEARCH _RESULT _ITEM _DETECTED ) ;
const childrenContainerEl = ( _a = this . searchView ) == null ? void 0 : _a . dom . childrenEl ;
if ( ! ( childrenContainerEl instanceof HTMLElement ) ) {
throw "[ERROR in Core Search Assistant] failed to SearchComponentInterface#startWatching: childrenContainerEl is not an instance of HTMLElement" ;
}
this . observer . observe ( childrenContainerEl , this . observationConfig ) ;
}
stopWatching ( ) {
this . observer . disconnect ( ) ;
}
collapseOppositeSidedock ( ) {
const sideDock = this . oppositeSidedock ;
if ( sideDock === void 0 ) {
throw "[ERROR in Core Search Assistant] failed to collapseOppositeSidedock: failed to fetch the opposite sidedock" ;
}
sideDock . collapse ( ) ;
}
expandOppositeSidedock ( ) {
const sideDock = this . oppositeSidedock ;
if ( sideDock === void 0 ) {
throw "[ERROR in Core Search Assistant] failed to expandOppositeSidedock: failed to fetch the opposite sidedock" ;
}
sideDock . expand ( ) ;
}
collapseSidedock ( ) {
const sideDock = this . sideDock ;
if ( sideDock === void 0 ) {
throw "[ERROR in Core Search Assistant] failed to collapseSidedock: failed to fetch the sidedock" ;
}
sideDock . collapse ( ) ;
}
get sideDock ( ) {
const leaf = this . searchLeaf ;
if ( leaf === void 0 ) {
return void 0 ;
}
const parent = leaf . getRoot ( ) ;
if ( parent instanceof import _obsidian16 . WorkspaceSidedock ) {
return parent ;
} else {
return void 0 ;
}
}
get oppositeSidedock ( ) {
const leaf = this . searchLeaf ;
if ( leaf === void 0 ) {
return void 0 ;
}
const parent = leaf . getRoot ( ) ;
if ( parent === this . app . workspace . leftSplit ) {
const opposite = this . app . workspace . rightSplit ;
return opposite instanceof import _obsidian16 . WorkspaceSidedock ? opposite : void 0 ;
} else if ( parent === this . app . workspace . rightSplit ) {
const opposite = this . app . workspace . leftSplit ;
return opposite instanceof import _obsidian16 . WorkspaceSidedock ? opposite : void 0 ;
} else {
return void 0 ;
}
}
createSortOrderEls ( ) {
this . sortOrderContainerEl = createEl ( "div" , {
cls : "search-info-container"
} ) ;
this . sortOrderContentEl = this . sortOrderContainerEl . createEl ( "div" ) ;
const view = this . searchView ;
if ( ! view ) {
return void 0 ;
}
this . sortOrderContainerEl . insertAfter ( view . searchInfoEl ) ;
}
get matchingCaseButtonEl ( ) {
var _a ;
return ( _a = this . searchView ) == null ? void 0 : _a . matchingCaseButtonEl ;
}
get tabHeaderEl ( ) {
var _a ;
return ( _a = this . searchLeaf ) == null ? void 0 : _a . tabHeaderEl ;
}
isBuiltInElementToOpenFile ( el ) {
const isFileNameContainerEl = el . tagName === "DIV" && el . hasClass ( "tree-item-inner" ) ;
const isMatchCountContainerEl = el . tagName === "DIV" && el . hasClass ( "tree-item-flair-outer" ) ;
const isMatchContainerEl = el . tagName === "DIV" && el . hasClass ( "search-result-file-match" ) ;
if ( isFileNameContainerEl || isMatchContainerEl || isMatchCountContainerEl ) {
return true ;
}
const parentEl = el . parentElement ;
if ( parentEl === null ) {
return false ;
} else {
return this . isBuiltInElementToOpenFile ( parentEl ) ;
}
}
isShowMoreContextButton ( el ) {
return el . tagName === "DIV" && el . hasClass ( "search-result-hover-button" ) ;
}
get searchView ( ) {
const leaf = this . searchLeaf ;
if ( ! leaf ) {
return void 0 ;
}
const view = leaf . view ;
return isSearchView ( view ) ? view : void 0 ;
}
get searchLeaf ( ) {
return this . app . workspace . getLeavesOfType ( "search" ) [ 0 ] ;
}
isRootSearchResult ( el ) {
return el . tagName === "DIV" && ! el . hasClass ( "tree-item" ) && ! el . hasClass ( "search-result" ) ;
}
} ;
// src/main.ts
var import _obsidian17 = _ _toModule ( require ( "obsidian" ) ) ;
var CoreSearchAssistantPlugin = class extends import _obsidian17 . Plugin {
onload ( ) {
return _ _async ( this , null , function * ( ) {
yield this . loadSettings ( ) ;
this . events = new CoreSearchAssistantEvents ( ) ;
this . searchInterface = this . addChild ( new SearchComponentInterface ( this . app , this , this . events ) ) ;
this . controller = this . addChild ( new Controller ( this . app , this , this . events , this . searchInterface ) ) ;
this . watchLayoutChange ( ) ;
this . setSvelteStoreValues ( ) ;
this . addSettingTab ( new CoreSearchAssistantSettingTab ( this . app , this ) ) ;
} ) ;
}
loadSettings ( ) {
return _ _async ( this , null , function * ( ) {
this . settings = deepMerge ( DEFAULT _SETTINGS , yield this . loadData ( ) ) ;
} ) ;
}
saveSettings ( ) {
return _ _async ( this , null , function * ( ) {
yield this . saveData ( this . settings ) ;
} ) ;
}
renewController ( ) {
if ( this . controller ) {
this . removeChild ( this . controller ) ;
}
if ( this . events === void 0 ) {
throw "[ERROR in Core Search Interface] failed to renewController: plugin.events = undefined" ;
}
if ( this . searchInterface === void 0 ) {
throw "[ERROR in Core Search Interface] failed to renewController: plugin.searchInterface = undefined" ;
}
this . controller = this . addChild ( new Controller ( this . app , this , this . events , this . searchInterface ) ) ;
}
watchLayoutChange ( ) {
this . app . workspace . onLayoutReady ( ( ) => {
this . app . workspace . on ( "layout-change" , ( ) => _ _async ( this , null , function * ( ) {
var _a ;
if ( yield ( _a = this . controller ) == null ? void 0 : _a . layoutChanged ( ) ) {
this . renewController ( ) ;
}
} ) ) ;
} ) ;
}
setSvelteStoreValues ( ) {
plugin . set ( this ) ;
app . set ( this . app ) ;
}
} ;
/ * ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Copyright ( c ) Microsoft Corporation .
Permission to use , copy , modify , and / or distribute this software for any
purpose with or without fee is hereby granted .
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS . IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL , DIRECT ,
INDIRECT , OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE , DATA OR PROFITS , WHETHER IN AN ACTION OF CONTRACT , NEGLIGENCE OR
OTHER TORTIOUS ACTION , ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /