@md-plugins/quasar-app-extension-q-press 0.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +230 -0
- package/old/prompts.js +44 -0
- package/old/uninstall.js +9 -0
- package/package.json +60 -0
- package/scripts/build.js +33 -0
- package/src/index.js +63 -0
- package/src/install.js +49 -0
- package/src/templates/.gitkeep +0 -0
- package/src/templates/init/src/_q-press/.gitkeep +0 -0
- package/src/templates/init/src/_q-press/api/components/DarkModeToggle.json +37 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownApi.json +67 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownApiEntry.json +76 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownCardLink.json +28 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownCardTitle.json +48 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownCode.json +37 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownCodePrism.json +29 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownCodepen.json +21 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownCopyButton.json +36 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownDrawerSidebar.json +17 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownDrawerToc.json +17 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownExample.json +22 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownHeader.json +28 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownHeaderIconLinks.json +16 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownHeaderMenu.json +77 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownHeaderTextLinks.json +33 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownInstallation.json +33 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownLayout.json +52 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownLink.json +23 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownPage.json +71 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownPageFooter.json +21 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownPageSidebar.json +56 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownPageToc.json +17 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownPrerender.json +25 -0
- package/src/templates/init/src/_q-press/api/components/MarkdownTree.json +27 -0
- package/src/templates/init/src/_q-press/api/composables/dark.json +29 -0
- package/src/templates/init/src/_q-press/api/composables/scroll.json +34 -0
- package/src/templates/init/src/_q-press/assets/get-meta.ts +29 -0
- package/src/templates/init/src/_q-press/components/DarkModeToggle.vue +105 -0
- package/src/templates/init/src/_q-press/components/MarkdownApi.vue +588 -0
- package/src/templates/init/src/_q-press/components/MarkdownApiEntry.ts +594 -0
- package/src/templates/init/src/_q-press/components/MarkdownCardLink.vue +25 -0
- package/src/templates/init/src/_q-press/components/MarkdownCardTitle.vue +21 -0
- package/src/templates/init/src/_q-press/components/MarkdownCode.vue +25 -0
- package/src/templates/init/src/_q-press/components/MarkdownCodePrism.ts +36 -0
- package/src/templates/init/src/_q-press/components/MarkdownCodepen.vue +183 -0
- package/src/templates/init/src/_q-press/components/MarkdownCopyButton.vue +104 -0
- package/src/templates/init/src/_q-press/components/MarkdownExample.vue +221 -0
- package/src/templates/init/src/_q-press/components/MarkdownInstallation.vue +166 -0
- package/src/templates/init/src/_q-press/components/MarkdownLink.vue +38 -0
- package/src/templates/init/src/_q-press/components/MarkdownPrerender.ts +82 -0
- package/src/templates/init/src/_q-press/components/MarkdownTree.vue +105 -0
- package/src/templates/init/src/_q-press/components/markdown-utils.ts +105 -0
- package/src/templates/init/src/_q-press/composables/dark.ts +39 -0
- package/src/templates/init/src/_q-press/composables/scroll.ts +115 -0
- package/src/templates/init/src/_q-press/css/app.scss +662 -0
- package/src/templates/init/src/_q-press/css/fonts.scss +100 -0
- package/src/templates/init/src/_q-press/css/prism-theme.scss +298 -0
- package/src/templates/init/src/_q-press/css/themes/default.scss +68 -0
- package/src/templates/init/src/_q-press/css/themes/newspaper.scss +69 -0
- package/src/templates/init/src/_q-press/css/themes/sunrise.scss +67 -0
- package/src/templates/init/src/_q-press/css/themes/tawny.scss +69 -0
- package/src/templates/init/src/_q-press/layouts/MarkdownDrawerSidebar.vue +32 -0
- package/src/templates/init/src/_q-press/layouts/MarkdownDrawerToc.vue +37 -0
- package/src/templates/init/src/_q-press/layouts/MarkdownHeader.vue +412 -0
- package/src/templates/init/src/_q-press/layouts/MarkdownHeaderIconLinks.vue +31 -0
- package/src/templates/init/src/_q-press/layouts/MarkdownHeaderMenu.ts +93 -0
- package/src/templates/init/src/_q-press/layouts/MarkdownHeaderTextLinks.vue +37 -0
- package/src/templates/init/src/_q-press/layouts/MarkdownLayout.vue +239 -0
- package/src/templates/init/src/_q-press/layouts/MarkdownPage.vue +307 -0
- package/src/templates/init/src/_q-press/layouts/MarkdownPageFooter.vue +187 -0
- package/src/templates/init/src/_q-press/layouts/MarkdownPageSidebar.scss +54 -0
- package/src/templates/init/src/_q-press/layouts/MarkdownPageSidebar.ts +218 -0
- package/src/templates/init/src/_q-press/layouts/MarkdownPageToc.vue +23 -0
- package/src/templates/init/src/_q-press/layouts/MarkdownSearch.vue +449 -0
- package/src/templates/init/src/_q-press/stores/markdown.ts +101 -0
- package/src/templates/init/src/components/LandingPage/LandingPage.vue +341 -0
- package/src/templates/init/src/components/Releases/PackageReleases.vue +164 -0
- package/src/templates/init/src/components/Releases/PublicReleases.vue +149 -0
- package/src/templates/init/src/components/Releases/ReleasesAvailable.vue +74 -0
- package/src/templates/init/src/examples/QAvatar/BasicExample.vue +11 -0
- package/src/templates/init/src/markdown/__elements.md +548 -0
- package/src/templates/init/src/markdown/__elements2.md +347 -0
- package/src/templates/init/src/markdown/faq/best-practices.md +0 -0
- package/src/templates/init/src/markdown/faq/general.md +0 -0
- package/src/templates/init/src/markdown/faq/troubleshooting.md +0 -0
- package/src/templates/init/src/markdown/getting-started/introduction.md +67 -0
- package/src/templates/init/src/markdown/guides/contributing.md +101 -0
- package/src/templates/init/src/markdown/guides/faq.md +115 -0
- package/src/templates/init/src/markdown/guides/release-notes.md +0 -0
- package/src/templates/init/src/markdown/guides/style-guide.md +0 -0
- package/src/templates/init/src/markdown/landing-page.md +11 -0
- package/src/templates/init/src/markdown/listing.ts +3 -0
- package/src/templates/init/src/markdown/md-plugins/blockquote/advanced.md +83 -0
- package/src/templates/init/src/markdown/md-plugins/blockquote/overview.md +183 -0
- package/src/templates/init/src/markdown/md-plugins/codeblocks/advanced.md +210 -0
- package/src/templates/init/src/markdown/md-plugins/codeblocks/overview.md +616 -0
- package/src/templates/init/src/markdown/md-plugins/containers/advanced.md +301 -0
- package/src/templates/init/src/markdown/md-plugins/containers/overview.md +206 -0
- package/src/templates/init/src/markdown/md-plugins/frontmatter/advanced.md +164 -0
- package/src/templates/init/src/markdown/md-plugins/frontmatter/overview.md +131 -0
- package/src/templates/init/src/markdown/md-plugins/headers/advanced.md +236 -0
- package/src/templates/init/src/markdown/md-plugins/headers/overview.md +134 -0
- package/src/templates/init/src/markdown/md-plugins/image/advanced.md +114 -0
- package/src/templates/init/src/markdown/md-plugins/image/overview.md +124 -0
- package/src/templates/init/src/markdown/md-plugins/imports/advanced.md +105 -0
- package/src/templates/init/src/markdown/md-plugins/imports/overview.md +80 -0
- package/src/templates/init/src/markdown/md-plugins/inline-code/advanced.md +133 -0
- package/src/templates/init/src/markdown/md-plugins/inline-code/overview.md +101 -0
- package/src/templates/init/src/markdown/md-plugins/link/advanced.md +157 -0
- package/src/templates/init/src/markdown/md-plugins/link/overview.md +126 -0
- package/src/templates/init/src/markdown/md-plugins/shared/overview.md +175 -0
- package/src/templates/init/src/markdown/md-plugins/table/advanced.md +190 -0
- package/src/templates/init/src/markdown/md-plugins/table/overview.md +186 -0
- package/src/templates/init/src/markdown/md-plugins/title/advanced.md +88 -0
- package/src/templates/init/src/markdown/md-plugins/title/overview.md +99 -0
- package/src/templates/init/src/markdown/other/release-notes.md +12 -0
- package/src/templates/init/src/markdown/privacy-policy.md +12 -0
- package/src/templates/init/src/markdown/quasar-app-extensions/qpress/advanced.md +101 -0
- package/src/templates/init/src/markdown/quasar-app-extensions/qpress/components.md +69 -0
- package/src/templates/init/src/markdown/quasar-app-extensions/qpress/overview.md +254 -0
- package/src/templates/init/src/markdown/quasar-app-extensions/qpress/themes.md +4 -0
- package/src/templates/init/src/markdown/quasar-app-extensions/vitemdpluginappext/advanced.md +4 -0
- package/src/templates/init/src/markdown/quasar-app-extensions/vitemdpluginappext/overview.md +103 -0
- package/src/templates/init/src/markdown/vite-plugins/index.md +6 -0
- package/src/templates/init/src/markdown/vite-plugins/viteexamplesplugin/advanced.md +138 -0
- package/src/templates/init/src/markdown/vite-plugins/viteexamplesplugin/overview.md +88 -0
- package/src/templates/init/src/markdown/vite-plugins/vitemdplugin/advanced.md +226 -0
- package/src/templates/init/src/markdown/vite-plugins/vitemdplugin/index.md +6 -0
- package/src/templates/init/src/markdown/vite-plugins/vitemdplugin/overview.md +166 -0
- package/src/templates/init/src/q-press.globals.d.ts +36 -0
- package/src/templates/init/src/siteConfig/index.ts +440 -0
- package/src/templates/update/src/_q-press/.gitkeep +0 -0
- package/src/templates/update/src/_q-press/api/components/DarkModeToggle.json +37 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownApi.json +67 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownApiEntry.json +76 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownCardLink.json +28 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownCardTitle.json +48 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownCode.json +37 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownCodePrism.json +29 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownCodepen.json +21 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownCopyButton.json +36 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownDrawerSidebar.json +17 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownDrawerToc.json +17 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownExample.json +22 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownHeader.json +28 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownHeaderIconLinks.json +16 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownHeaderMenu.json +77 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownHeaderTextLinks.json +33 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownInstallation.json +33 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownLayout.json +52 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownLink.json +23 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownPage.json +71 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownPageFooter.json +21 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownPageSidebar.json +56 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownPageToc.json +17 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownPrerender.json +25 -0
- package/src/templates/update/src/_q-press/api/components/MarkdownTree.json +27 -0
- package/src/templates/update/src/_q-press/api/composables/dark.json +29 -0
- package/src/templates/update/src/_q-press/api/composables/scroll.json +34 -0
- package/src/templates/update/src/_q-press/assets/get-meta.ts +29 -0
- package/src/templates/update/src/_q-press/components/DarkModeToggle.vue +105 -0
- package/src/templates/update/src/_q-press/components/MarkdownApi.vue +588 -0
- package/src/templates/update/src/_q-press/components/MarkdownApiEntry.ts +594 -0
- package/src/templates/update/src/_q-press/components/MarkdownCardLink.vue +25 -0
- package/src/templates/update/src/_q-press/components/MarkdownCardTitle.vue +21 -0
- package/src/templates/update/src/_q-press/components/MarkdownCode.vue +25 -0
- package/src/templates/update/src/_q-press/components/MarkdownCodePrism.ts +36 -0
- package/src/templates/update/src/_q-press/components/MarkdownCodepen.vue +183 -0
- package/src/templates/update/src/_q-press/components/MarkdownCopyButton.vue +104 -0
- package/src/templates/update/src/_q-press/components/MarkdownExample.vue +221 -0
- package/src/templates/update/src/_q-press/components/MarkdownInstallation.vue +166 -0
- package/src/templates/update/src/_q-press/components/MarkdownLink.vue +38 -0
- package/src/templates/update/src/_q-press/components/MarkdownPrerender.ts +82 -0
- package/src/templates/update/src/_q-press/components/MarkdownTree.vue +105 -0
- package/src/templates/update/src/_q-press/components/markdown-utils.ts +105 -0
- package/src/templates/update/src/_q-press/composables/dark.ts +39 -0
- package/src/templates/update/src/_q-press/composables/scroll.ts +115 -0
- package/src/templates/update/src/_q-press/css/app.scss +662 -0
- package/src/templates/update/src/_q-press/css/fonts.scss +100 -0
- package/src/templates/update/src/_q-press/css/prism-theme.scss +298 -0
- package/src/templates/update/src/_q-press/css/themes/default.scss +68 -0
- package/src/templates/update/src/_q-press/css/themes/newspaper.scss +69 -0
- package/src/templates/update/src/_q-press/css/themes/sunrise.scss +67 -0
- package/src/templates/update/src/_q-press/css/themes/tawny.scss +69 -0
- package/src/templates/update/src/_q-press/layouts/MarkdownDrawerSidebar.vue +32 -0
- package/src/templates/update/src/_q-press/layouts/MarkdownDrawerToc.vue +37 -0
- package/src/templates/update/src/_q-press/layouts/MarkdownHeader.vue +412 -0
- package/src/templates/update/src/_q-press/layouts/MarkdownHeaderIconLinks.vue +31 -0
- package/src/templates/update/src/_q-press/layouts/MarkdownHeaderMenu.ts +93 -0
- package/src/templates/update/src/_q-press/layouts/MarkdownHeaderTextLinks.vue +37 -0
- package/src/templates/update/src/_q-press/layouts/MarkdownLayout.vue +239 -0
- package/src/templates/update/src/_q-press/layouts/MarkdownPage.vue +307 -0
- package/src/templates/update/src/_q-press/layouts/MarkdownPageFooter.vue +187 -0
- package/src/templates/update/src/_q-press/layouts/MarkdownPageSidebar.scss +54 -0
- package/src/templates/update/src/_q-press/layouts/MarkdownPageSidebar.ts +218 -0
- package/src/templates/update/src/_q-press/layouts/MarkdownPageToc.vue +23 -0
- package/src/templates/update/src/_q-press/layouts/MarkdownSearch.vue +449 -0
- package/src/templates/update/src/_q-press/stores/markdown.ts +101 -0
- package/src/templates/update/src/q-press.globals.d.ts +36 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
<!-- <template>
|
|
2
|
+
<div
|
|
3
|
+
ref="rootRef"
|
|
4
|
+
class="markdown-search z-max self-center"
|
|
5
|
+
:class="classes"
|
|
6
|
+
@click.prevent="onClick"
|
|
7
|
+
@focusin="onFocusin"
|
|
8
|
+
@focusout="onFocusout"
|
|
9
|
+
>
|
|
10
|
+
<div class="markdown-search__field rounded-borders row items-center no-wrap q-pl-sm q-pr-md">
|
|
11
|
+
<input
|
|
12
|
+
class="col"
|
|
13
|
+
name="search"
|
|
14
|
+
ref="inputRef"
|
|
15
|
+
placeholder="Search Quasar v2..."
|
|
16
|
+
v-model="terms"
|
|
17
|
+
@keydown="onKeydown"
|
|
18
|
+
/>
|
|
19
|
+
|
|
20
|
+
<q-icon class="markdown-search__icon cursor-pointer" :name="icon.name" size="24px" @click="icon.onClick" />
|
|
21
|
+
<q-no-ssr v-if="keysLabel">
|
|
22
|
+
<kbd class="markdown-search__kbd q-ma-none">{{ keysLabel }}</kbd>
|
|
23
|
+
</q-no-ssr>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<div :class="resultsClass">
|
|
27
|
+
<template v-if="results">
|
|
28
|
+
<component
|
|
29
|
+
v-if="results.masterComponent !== void 0"
|
|
30
|
+
:is="results.masterComponent"
|
|
31
|
+
/>
|
|
32
|
+
<app-search-results
|
|
33
|
+
v-else
|
|
34
|
+
:results="results"
|
|
35
|
+
:search-active-id="activeId"
|
|
36
|
+
/>
|
|
37
|
+
</template>
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
</template>
|
|
41
|
+
|
|
42
|
+
<script setup>
|
|
43
|
+
import { useQuasar } from 'quasar'
|
|
44
|
+
import { computed, ref, watch, markRaw, onMounted, onBeforeUnmount } from 'vue'
|
|
45
|
+
import { useRoute, useRouter } from 'vue-router'
|
|
46
|
+
|
|
47
|
+
import AppSearchResults from './search/SearchResults.vue'
|
|
48
|
+
import ResultEmpty from './search/ResultEmpty.vue'
|
|
49
|
+
import ResultError from './search/ResultError.vue'
|
|
50
|
+
|
|
51
|
+
const $q = useQuasar()
|
|
52
|
+
const route = useRoute()
|
|
53
|
+
const router = useRouter()
|
|
54
|
+
|
|
55
|
+
const rootRef = ref(null)
|
|
56
|
+
const inputRef = ref(null)
|
|
57
|
+
|
|
58
|
+
const terms = ref('')
|
|
59
|
+
const results = ref(null)
|
|
60
|
+
const activeId = ref(null)
|
|
61
|
+
|
|
62
|
+
const icon = computed(() => (
|
|
63
|
+
terms.value.length !== 0
|
|
64
|
+
? { name: 'clear', onClick: resetSearch }
|
|
65
|
+
: { name: 'search', onClick: () => {} }
|
|
66
|
+
))
|
|
67
|
+
|
|
68
|
+
const keysLabel = computed(() => $q.platform.is.desktop === true ? ($q.platform.is.mac ? '⌘K' : 'Ctrl+K') : null)
|
|
69
|
+
|
|
70
|
+
let focusoutTimer
|
|
71
|
+
const hasFocus = ref(false)
|
|
72
|
+
|
|
73
|
+
function onFocusin () {
|
|
74
|
+
clearTimeout(focusoutTimer)
|
|
75
|
+
hasFocus.value = true
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function onFocusout () {
|
|
79
|
+
clearTimeout(focusoutTimer)
|
|
80
|
+
focusoutTimer = setTimeout(() => {
|
|
81
|
+
hasFocus.value = false
|
|
82
|
+
}, 150)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const classes = computed(() => (hasFocus.value ? 'markdown-search--focused' : null))
|
|
86
|
+
const resultsClass = computed(() => (
|
|
87
|
+
'markdown-search__results rounded-borders rounded-borders overflow-auto' +
|
|
88
|
+
` markdown-search__results--${ results.value ? 'active' : 'hidden' }`
|
|
89
|
+
))
|
|
90
|
+
|
|
91
|
+
function closePopup () {
|
|
92
|
+
hasFocus.value = false
|
|
93
|
+
activeId.value = null
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function resetSearch () {
|
|
97
|
+
terms.value = ''
|
|
98
|
+
results.value = null
|
|
99
|
+
activeId.value = null
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let requestId = 0, fetchTimer
|
|
103
|
+
|
|
104
|
+
function fetchQuery (val, onResult, onError) {
|
|
105
|
+
const localRequestId = requestId
|
|
106
|
+
clearTimeout(fetchTimer)
|
|
107
|
+
|
|
108
|
+
fetchTimer = setTimeout(() => {
|
|
109
|
+
if (localRequestId !== requestId) { return }
|
|
110
|
+
|
|
111
|
+
const xhr = new XMLHttpRequest()
|
|
112
|
+
const data = JSON.stringify({
|
|
113
|
+
q: val, limit: 15, cropLength: 50, attributesToCrop: ['content'], attributesToHighlight: ['content']
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
xhr.addEventListener('load', function () {
|
|
117
|
+
localRequestId === requestId && onResult(JSON.parse(this.responseText))
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
xhr.addEventListener('error', () => {
|
|
121
|
+
localRequestId === requestId && onError()
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
xhr.open('POST', `https://search.quasar.dev/indexes/${ process.env.SEARCH_INDEX }/search`)
|
|
125
|
+
xhr.setRequestHeader('Content-Type', 'application/json')
|
|
126
|
+
xhr.setRequestHeader('Authorization', 'Bearer b7a6ea9a9978a4e4d994c1f9451210327f207441adbcf04a4aada3d17d829359')
|
|
127
|
+
xhr.send(data)
|
|
128
|
+
}, 400)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const contentRE = /(<em>|<\/em>)/
|
|
132
|
+
const startsWithRE = /^[a-z0-9]/
|
|
133
|
+
const endsWithRE = /[a-z0-9]$/
|
|
134
|
+
|
|
135
|
+
function parseContent (content) {
|
|
136
|
+
if (!content) {
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let inToken = false
|
|
141
|
+
|
|
142
|
+
const acc = []
|
|
143
|
+
const str = (
|
|
144
|
+
(startsWithRE.test(content) ? '...' : '') +
|
|
145
|
+
content +
|
|
146
|
+
(endsWithRE.test(content) ? '...' : '')
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
str.split(contentRE).forEach(str => {
|
|
150
|
+
if (str === '') {
|
|
151
|
+
inToken = true
|
|
152
|
+
}
|
|
153
|
+
else if (str !== '<em>' && str !== '</em>') {
|
|
154
|
+
acc.push({
|
|
155
|
+
str,
|
|
156
|
+
class: inToken ? 'app-search__result-token' : null
|
|
157
|
+
})
|
|
158
|
+
inToken = !inToken
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
return acc
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const supportedHitTypes = [ 'page-content', 'page-link' ]
|
|
166
|
+
|
|
167
|
+
function parseResults (hits) {
|
|
168
|
+
if (hits.length === 0) {
|
|
169
|
+
return { masterComponent: markRaw(ResultEmpty) }
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const acc = {
|
|
173
|
+
entries: [],
|
|
174
|
+
ids: []
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
hits.forEach(hit => {
|
|
178
|
+
// if we don't know how to display this API type then just abort
|
|
179
|
+
if (supportedHitTypes.includes(hit.type) === false) {
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const entry = {
|
|
184
|
+
page: hit.menu.join(' » '),
|
|
185
|
+
section: [ hit.l1, hit.l2, hit.l3, hit.l4, hit.l5, hit.l6 ].filter(e => e).join(' » ') || null,
|
|
186
|
+
content: parseContent(hit._formatted.content),
|
|
187
|
+
|
|
188
|
+
onMouseenter () {
|
|
189
|
+
activeId.value = entry.id
|
|
190
|
+
},
|
|
191
|
+
onClick () {
|
|
192
|
+
closePopup()
|
|
193
|
+
router.push(hit.url).catch(() => {})
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
acc.entries.push(entry)
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
// ensure that the ids are assigned in the right order
|
|
201
|
+
// otherwise keyboard up/down will not work correctly
|
|
202
|
+
let globalId = 0
|
|
203
|
+
acc.entries.forEach(hit => {
|
|
204
|
+
const id = 'search--' + (++globalId)
|
|
205
|
+
hit.id = id
|
|
206
|
+
acc.ids.push(id)
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
return acc
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function onKeydown (evt) {
|
|
213
|
+
switch (evt.keyCode) {
|
|
214
|
+
case 27: // escape
|
|
215
|
+
evt.preventDefault()
|
|
216
|
+
if (hasFocus.value === true) {
|
|
217
|
+
closePopup()
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
resetSearch()
|
|
221
|
+
}
|
|
222
|
+
break
|
|
223
|
+
case 38: // up
|
|
224
|
+
case 40: // down
|
|
225
|
+
evt.preventDefault()
|
|
226
|
+
if (results.value !== null && results.value.ids !== void 0) {
|
|
227
|
+
if (activeId.value === null) {
|
|
228
|
+
activeId.value = results.value.ids[ 0 ]
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
const ids = results.value.ids
|
|
232
|
+
const index = ids.indexOf(activeId.value)
|
|
233
|
+
activeId.value = ids[ (ids.length + index + (evt.keyCode === 38 ? -1 : 1)) % ids.length ]
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const target = document.getElementById(activeId.value)
|
|
237
|
+
if (target.scrollIntoViewIfNeeded !== void 0) {
|
|
238
|
+
target.scrollIntoViewIfNeeded()
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
target.scrollIntoView({ block: 'center' })
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
break
|
|
245
|
+
case 13: // enter
|
|
246
|
+
evt.preventDefault()
|
|
247
|
+
evt.stopPropagation()
|
|
248
|
+
if (results.value !== null) {
|
|
249
|
+
if (hasFocus.value === false) {
|
|
250
|
+
hasFocus.value = true
|
|
251
|
+
return
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (activeId.value !== null) {
|
|
255
|
+
document.getElementById(activeId.value).click(evt)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
break
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function onResultSuccess (response) {
|
|
263
|
+
results.value = parseResults(response.hits)
|
|
264
|
+
hasFocus.value = true
|
|
265
|
+
activeId.value = results.value.ids?.[ 0 ] || null
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function onResultError () {
|
|
269
|
+
results.value = { masterComponent: markRaw(ResultError) }
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
watch(terms, val => {
|
|
273
|
+
requestId++
|
|
274
|
+
|
|
275
|
+
if (!val) {
|
|
276
|
+
resetSearch()
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
fetchQuery(val, onResultSuccess, onResultError)
|
|
280
|
+
}
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
function onClick () {
|
|
284
|
+
inputRef.value.focus()
|
|
285
|
+
onFocusin()
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function onGlobalKeydown (e) {
|
|
289
|
+
if ((e.ctrlKey || e.metaKey) && e.keyCode === 75 /* K */) {
|
|
290
|
+
e.preventDefault()
|
|
291
|
+
inputRef.value.focus()
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
onMounted(() => {
|
|
296
|
+
// If we have a search string in the query (mostly from tab-to-search functionality),
|
|
297
|
+
// we need to open the drawer to fill in the search string in the input later
|
|
298
|
+
const searchQuery = route.query.search
|
|
299
|
+
|
|
300
|
+
window.addEventListener('keydown', onGlobalKeydown)
|
|
301
|
+
|
|
302
|
+
if (searchQuery) {
|
|
303
|
+
terms.value = searchQuery
|
|
304
|
+
inputRef.value.focus()
|
|
305
|
+
}
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
onBeforeUnmount(() => {
|
|
309
|
+
window.removeEventListener('keydown', onGlobalKeydown)
|
|
310
|
+
})
|
|
311
|
+
</script>
|
|
312
|
+
|
|
313
|
+
<style lang="scss">
|
|
314
|
+
body.desktop {
|
|
315
|
+
.markdown-search__icon {
|
|
316
|
+
display: none;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.markdown-search {
|
|
321
|
+
width: 400px;
|
|
322
|
+
height: 43px;
|
|
323
|
+
|
|
324
|
+
&__field {
|
|
325
|
+
height: inherit;
|
|
326
|
+
width: inherit;
|
|
327
|
+
cursor: text;
|
|
328
|
+
transition: box-shadow $header-quick-transition, background-color $header-quick-transition;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
input {
|
|
332
|
+
font-size: $font-size;
|
|
333
|
+
width: 1px !important; // required when on narrow width window to not overflow the page
|
|
334
|
+
border: 0;
|
|
335
|
+
outline: 0;
|
|
336
|
+
background: none;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
&__kbd {
|
|
340
|
+
box-shadow: none !important;
|
|
341
|
+
padding: 4px;
|
|
342
|
+
border: 1px solid $grey !important;
|
|
343
|
+
background: transparent !important;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
&__results {
|
|
347
|
+
max-height: 80vh;
|
|
348
|
+
top: 45px;
|
|
349
|
+
left: 0;
|
|
350
|
+
right: 0;
|
|
351
|
+
transform: scale3d(1, 0, 1);
|
|
352
|
+
transform-origin: top;
|
|
353
|
+
transition: transform 0.14s ease-in-out, box-shadow $header-quick-transition;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
&--focused {
|
|
357
|
+
.markdown-search__results--active {
|
|
358
|
+
transform: scale3d(1, 1, 1);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.markdown-search__icon {
|
|
362
|
+
display: inline-block !important;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
.markdown-search__kbd {
|
|
366
|
+
display: none;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
@media (max-width: 445px) {
|
|
372
|
+
.markdown-search__results {
|
|
373
|
+
position: fixed;
|
|
374
|
+
top: 60px;
|
|
375
|
+
left: 16px;
|
|
376
|
+
right: 16px;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
@media (min-width: 446px) {
|
|
381
|
+
.markdown-search {
|
|
382
|
+
position: relative;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
.markdown-search__results {
|
|
386
|
+
position: absolute;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
body.mobile {
|
|
391
|
+
.markdown-search__results {
|
|
392
|
+
max-height: 50vh;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
body.body--light .markdown-search {
|
|
397
|
+
input {
|
|
398
|
+
color: $light-text;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
&__field {
|
|
402
|
+
background: $grey-4;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
&__results {
|
|
406
|
+
background: #fff;
|
|
407
|
+
color: $light-text;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
&--focused {
|
|
411
|
+
.markdown-search__results--active {
|
|
412
|
+
border: 1px solid $separator-color;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
.markdown-search__field {
|
|
416
|
+
background-color: rgba(#000, 0.28);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
body.body--dark .markdown-search {
|
|
422
|
+
input {
|
|
423
|
+
color: #fff;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
&__field {
|
|
427
|
+
background-color: rgba(#fff, 0.12);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
&__icon {
|
|
431
|
+
color: $brand-primary;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
&__results {
|
|
435
|
+
background: $dark-bg;
|
|
436
|
+
color: $dark-text;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
&--focused {
|
|
440
|
+
.markdown-search__results--active {
|
|
441
|
+
border: 1px solid $separator-dark-color;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
.markdown-search__field {
|
|
445
|
+
background-color: rgba(#fff, 0.28);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
</style> -->
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { defineStore, acceptHMRUpdate } from 'pinia'
|
|
2
|
+
import { useRoute } from 'vue-router'
|
|
3
|
+
import { useScroll } from '../composables/scroll'
|
|
4
|
+
import type { TocItem } from '@md-plugins/md-plugin-headers'
|
|
5
|
+
|
|
6
|
+
export const useMarkdownStore = defineStore('markdown-store', {
|
|
7
|
+
state: () => ({
|
|
8
|
+
title: '',
|
|
9
|
+
toc: [] as TocMenuItem[],
|
|
10
|
+
activeToc: null as string | null,
|
|
11
|
+
menuDrawer: false,
|
|
12
|
+
tocDrawer: false,
|
|
13
|
+
dark: false,
|
|
14
|
+
}),
|
|
15
|
+
getters: {
|
|
16
|
+
isDark: (state) => state.dark === true,
|
|
17
|
+
isMenuDrawerOpen: (state) => state.menuDrawer,
|
|
18
|
+
isTocDrawerOpen: (state) => state.tocDrawer,
|
|
19
|
+
activeTocIndex: (state) => state.toc.findIndex((section) => section.id === state.activeToc),
|
|
20
|
+
},
|
|
21
|
+
actions: {
|
|
22
|
+
toggleMenuDrawer() {
|
|
23
|
+
this.menuDrawer = this.menuDrawer === false
|
|
24
|
+
},
|
|
25
|
+
toggleTocDrawer() {
|
|
26
|
+
this.tocDrawer = this.tocDrawer === false
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
updateActiveToc(position?: number): void {
|
|
30
|
+
if (!position) {
|
|
31
|
+
position = document.documentElement.scrollTop || document.body.scrollTop
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let last
|
|
35
|
+
|
|
36
|
+
for (const section of this.toc) {
|
|
37
|
+
const item = document.getElementById(section.id)
|
|
38
|
+
|
|
39
|
+
if (!item) {
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const offset =
|
|
44
|
+
section.deep === true
|
|
45
|
+
? item.offsetTop + (item.offsetParent as HTMLElement).offsetTop
|
|
46
|
+
: item.offsetTop
|
|
47
|
+
|
|
48
|
+
if (offset >= position + 155) {
|
|
49
|
+
if (last === void 0) {
|
|
50
|
+
last = section.id
|
|
51
|
+
}
|
|
52
|
+
break
|
|
53
|
+
} else {
|
|
54
|
+
last = section.id
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (last !== void 0) {
|
|
59
|
+
this.activeToc = last
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
setToc(toc: TocItem[]) {
|
|
64
|
+
const { scrollTo } = useScroll()
|
|
65
|
+
this.toc =
|
|
66
|
+
toc !== void 0
|
|
67
|
+
? ([
|
|
68
|
+
{
|
|
69
|
+
id: 'introduction',
|
|
70
|
+
title: '1. Introduction',
|
|
71
|
+
level: 0,
|
|
72
|
+
sub: false,
|
|
73
|
+
onClick: () => scrollTo('introduction'),
|
|
74
|
+
},
|
|
75
|
+
...toc.map((entry) => ({
|
|
76
|
+
...entry,
|
|
77
|
+
onClick: () => {
|
|
78
|
+
this.tocDrawer = false
|
|
79
|
+
scrollTo(entry.id)
|
|
80
|
+
},
|
|
81
|
+
})),
|
|
82
|
+
] as TocMenuItem[])
|
|
83
|
+
: []
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
injectToc() {
|
|
87
|
+
const route = useRoute()
|
|
88
|
+
|
|
89
|
+
this.toc = []
|
|
90
|
+
this.activeToc = route.hash.length > 1 ? route.hash.substring(1) : null
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
setActiveToc(pos?: number): void {
|
|
94
|
+
this.updateActiveToc(pos)
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
if (import.meta.hot) {
|
|
100
|
+
import.meta.hot.accept(acceptHMRUpdate(useMarkdownStore, import.meta.hot))
|
|
101
|
+
}
|