Added dialog for copy-to-clipboard action

This commit is contained in:
squidfunk
2020-02-18 14:30:06 +01:00
parent fdff60e33d
commit b2654777b8
17 changed files with 192 additions and 43 deletions

View File

@@ -40,7 +40,8 @@ import {
tap,
filter,
withLatestFrom,
observeOn
observeOn,
take
} from "rxjs/operators"
import {
@@ -77,6 +78,7 @@ import { mountClipboard } from "./integrations/clipboard"
import { patchTables, patchDetails, patchScrollfix } from "patches"
import { takeIf, not, isConfig } from "utilities"
import { fetchSourceFacts } from "integrations/source"
import { renderDialog } from "templates/dialog"
/* ------------------------------------------------------------------------- */
@@ -208,7 +210,26 @@ export function initialize(config: unknown) {
/* ----------------------------------------------------------------------- */
// must be in another scope!
const dialog = renderDialog("Copied to Clipboard")
// snackbar for copy to clipboard
mountClipboard({ document$ })
.pipe(
switchMap(ev => {
ev.clearSelection()
return useComponent("container")
.pipe(
tap(el => el.appendChild(dialog)), // only set text on dialog... render once...
observeOn(animationFrameScheduler),
tap(() => dialog.dataset.mdState = "open"),
delay(2000),
tap(() => dialog.dataset.mdState = ""),
delay(400),
tap(() => dialog.remove())
)
})
)
.subscribe()
patchTables({ document$ })
@@ -294,6 +315,20 @@ export function initialize(config: unknown) {
}
})
// if we use a single tab outside of search, unhide all permalinks.
keyboard$
.pipe(
takeIf(not(toggle$.pipe(switchMap(watchToggle)))),
filter(key => ["Tab"].includes(key.type)),
take(1)
)
.subscribe(() => {
for (const link of getElements(".headerlink"))
link.style.visibility = "visible"
})
// build a notification component! feed txt into it...
/* ----------------------------------------------------------------------- */
// TODO: WIP repo rendering

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
import { h } from "utilities"
/* ----------------------------------------------------------------------------
* Data
* ------------------------------------------------------------------------- */
/**
* CSS classes
*/
const css = {
container: "md-dialog md-typeset"
}
/* ----------------------------------------------------------------------------
* Functions
* ------------------------------------------------------------------------- */
/**
* Render a dismissable dialog
*
* @param text - Dialog text
*
* @return Element
*/
export function renderDialog(
text: string
): HTMLElement {
return (
<div class={css.container}>
{text}
</div>
)
}

View File

@@ -21,6 +21,7 @@
*/
export * from "./clipboard"
export * from "./dialog"
export * from "./search"
export * from "./source"
export * from "./table"