preloading of popup component

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-09-22 12:43:25 +02:00
parent 479fb21600
commit 74a9366688
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0
2 changed files with 16 additions and 11 deletions

View File

@ -89,11 +89,7 @@ $: {
</script>
<div class="popup" bind:this={modalHTML} style={`z-index: ${zIndex + 1};`}>
{#if typeof(is) === 'string'}
<Component is={is} props={props} on:close={ (ev) => close(ev.detail) }/>
{:else}
<svelte:component this={is} {...props} on:close={ (ev) => close(ev.detail) } />
{/if}
<svelte:component this={is} {...props} on:close={ (ev) => close(ev.detail) } />
</div>
<div bind:this={modalOHTML} class="modal-overlay" style={`z-index: ${zIndex};`} on:click={() => close(undefined)} />

View File

@ -15,7 +15,7 @@
import { SvelteComponent } from 'svelte'
import type { AnySvelteComponent, AnyComponent, PopupAlignment, LabelAndProps, TooltipAligment } from './types'
import type { IntlString } from '@anticrm/platform'
import { getResource, IntlString } from '@anticrm/platform'
import { addStringsLoader } from '@anticrm/platform'
import { uiId } from './plugin'
@ -81,7 +81,7 @@ export function createApp (target: HTMLElement): SvelteComponent {
}
interface CompAndProps {
is: AnySvelteComponent | AnyComponent
is: AnySvelteComponent
props: any
element?: PopupAlignment
onClose?: (result: any) => void
@ -95,10 +95,19 @@ interface CompAndProps {
export const popupstore = writable<CompAndProps[]>([])
export function showPopup (component: AnySvelteComponent | AnyComponent, props: any, element?: PopupAlignment, onClose?: (result: any) => void): void {
popupstore.update(popups => {
popups.push({ is: component, props, element, onClose })
return popups
})
if (typeof component === 'string') {
getResource(component).then(resolved => {
popupstore.update(popups => {
popups.push({ is: resolved, props, element, onClose })
return popups
})
})
} else {
popupstore.update(popups => {
popups.push({ is: component, props, element, onClose })
return popups
})
}
}
export function closePopup (): void {