mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 21:50:34 +03:00
SortableList presenter prop (#2437)
Signed-off-by: Sergei Ogorelkov <sergei.ogorelkov@xored.com>
This commit is contained in:
parent
12c244ddf3
commit
0673e715df
@ -35,7 +35,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{:then Ctor}
|
{:then Ctor}
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<Ctor {...props} on:change on:close on:open on:click on:delete>
|
<Ctor {...props} on:change on:close on:open on:click on:delete on:action>
|
||||||
{#if $$slots.default}
|
{#if $$slots.default}
|
||||||
<slot />
|
<slot />
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -13,12 +13,14 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { Asset } from '@hcengineering/platform'
|
||||||
import { TagElement } from '@hcengineering/tags'
|
import { TagElement } from '@hcengineering/tags'
|
||||||
import { eventToHTMLElement, showPopup } from '@hcengineering/ui'
|
import { AnySvelteComponent, eventToHTMLElement, showPopup } from '@hcengineering/ui'
|
||||||
import EditTagElement from './EditTagElement.svelte'
|
import EditTagElement from './EditTagElement.svelte'
|
||||||
import TagItem from './TagItem.svelte'
|
import TagItem from './TagItem.svelte'
|
||||||
|
|
||||||
export let value: TagElement
|
export let value: TagElement
|
||||||
|
export let action: Asset | AnySvelteComponent | undefined = undefined
|
||||||
export let edit: boolean = false
|
export let edit: boolean = false
|
||||||
export let keyTitle: string = ''
|
export let keyTitle: string = ''
|
||||||
</script>
|
</script>
|
||||||
@ -31,9 +33,9 @@
|
|||||||
showPopup(EditTagElement, { value, keyTitle }, eventToHTMLElement(evt))
|
showPopup(EditTagElement, { value, keyTitle }, eventToHTMLElement(evt))
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TagItem element={value} />
|
<TagItem element={value} {action} on:action />
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<TagItem element={value} />
|
<TagItem element={value} {action} on:action />
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -19,7 +19,6 @@ import { Filter } from '@hcengineering/view'
|
|||||||
|
|
||||||
export default mergeIds(tagsId, tags, {
|
export default mergeIds(tagsId, tags, {
|
||||||
component: {
|
component: {
|
||||||
TagElementPresenter: '' as AnyComponent,
|
|
||||||
CategoryPresenter: '' as AnyComponent,
|
CategoryPresenter: '' as AnyComponent,
|
||||||
TagElementCountPresenter: '' as AnyComponent
|
TagElementCountPresenter: '' as AnyComponent
|
||||||
},
|
},
|
||||||
|
@ -106,7 +106,8 @@ const tagsPlugin = plugin(tagsId, {
|
|||||||
TagsCategoryBar: '' as AnyComponent,
|
TagsCategoryBar: '' as AnyComponent,
|
||||||
TagsAttributeEditor: '' as AnyComponent,
|
TagsAttributeEditor: '' as AnyComponent,
|
||||||
TagsPresenter: '' as AnyComponent,
|
TagsPresenter: '' as AnyComponent,
|
||||||
LabelsPresenter: '' as AnyComponent
|
LabelsPresenter: '' as AnyComponent,
|
||||||
|
TagElementPresenter: '' as AnyComponent
|
||||||
},
|
},
|
||||||
category: {
|
category: {
|
||||||
NoCategory: '' as Ref<TagCategory>
|
NoCategory: '' as Ref<TagCategory>
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
import { getResource, IntlString } from '@hcengineering/platform'
|
import { getResource, IntlString } from '@hcengineering/platform'
|
||||||
import presentation, { createQuery, getClient } from '@hcengineering/presentation'
|
import presentation, { createQuery, getClient } from '@hcengineering/presentation'
|
||||||
import { calcRank, DocWithRank } from '@hcengineering/task'
|
import { calcRank, DocWithRank } from '@hcengineering/task'
|
||||||
import { Button, Component, IconAdd, Label, Loading } from '@hcengineering/ui'
|
import { AnyComponent, Button, Component, IconAdd, Label, Loading } from '@hcengineering/ui'
|
||||||
import view, { AttributeModel, ObjectFactory } from '@hcengineering/view'
|
import view, { AttributeModel, ObjectFactory } from '@hcengineering/view'
|
||||||
import { flip } from 'svelte/animate'
|
import { flip } from 'svelte/animate'
|
||||||
import { getObjectPresenter } from '../../utils'
|
import { getObjectPresenter } from '../../utils'
|
||||||
@ -26,7 +26,7 @@
|
|||||||
How to use:
|
How to use:
|
||||||
|
|
||||||
We must add presenter for the "_class" via "AttributePresenter" mixin
|
We must add presenter for the "_class" via "AttributePresenter" mixin
|
||||||
to be able display the rows list.
|
or pass it through "presenter" prop to be able display the rows list.
|
||||||
|
|
||||||
To create a new items, we should add "ObjectFactory" mixin also.
|
To create a new items, we should add "ObjectFactory" mixin also.
|
||||||
|
|
||||||
@ -39,6 +39,7 @@
|
|||||||
export let label: IntlString | undefined = undefined
|
export let label: IntlString | undefined = undefined
|
||||||
export let query: DocumentQuery<Doc> = {}
|
export let query: DocumentQuery<Doc> = {}
|
||||||
export let queryOptions: FindOptions<Doc> | undefined = undefined
|
export let queryOptions: FindOptions<Doc> | undefined = undefined
|
||||||
|
export let presenter: AnyComponent | undefined = undefined
|
||||||
export let presenterProps: Record<string, any> = {}
|
export let presenterProps: Record<string, any> = {}
|
||||||
export let direction: 'row' | 'column' = 'column'
|
export let direction: 'row' | 'column' = 'column'
|
||||||
export let flipDuration = 200
|
export let flipDuration = 200
|
||||||
@ -134,7 +135,7 @@
|
|||||||
hoveringIndex = null
|
hoveringIndex = null
|
||||||
}
|
}
|
||||||
|
|
||||||
$: updateModel(_class, presenterProps)
|
$: !presenter && updateModel(_class, presenterProps)
|
||||||
$: updateObjectFactory(_class)
|
$: updateObjectFactory(_class)
|
||||||
$: itemsQuery.query(_class, query, updateItems, { ...queryOptions, limit: Math.max(queryOptions?.limit ?? 0, 200) })
|
$: itemsQuery.query(_class, query, updateItems, { ...queryOptions, limit: Math.max(queryOptions?.limit ?? 0, 200) })
|
||||||
|
|
||||||
@ -171,7 +172,7 @@
|
|||||||
|
|
||||||
{#if isLoading}
|
{#if isLoading}
|
||||||
<Loading />
|
<Loading />
|
||||||
{:else if model && items}
|
{:else if (presenter || model) && items}
|
||||||
{@const isVertical = direction === 'column'}
|
{@const isVertical = direction === 'column'}
|
||||||
<div class="flex-gap-1" class:flex-col={isVertical} class:flex={!isVertical} class:flex-wrap={!isVertical}>
|
<div class="flex-gap-1" class:flex-col={isVertical} class:flex={!isVertical} class:flex-wrap={!isVertical}>
|
||||||
{#each items as item, index (item._id)}
|
{#each items as item, index (item._id)}
|
||||||
@ -189,7 +190,11 @@
|
|||||||
on:drop={() => handleDrop(index)}
|
on:drop={() => handleDrop(index)}
|
||||||
on:dragend={resetDrag}
|
on:dragend={resetDrag}
|
||||||
>
|
>
|
||||||
<svelte:component this={model.presenter} {isDraggable} {...model.props ?? {}} value={item} />
|
{#if presenter}
|
||||||
|
<Component is={presenter} props={{ isDraggable, ...presenterProps, value: item }} />
|
||||||
|
{:else if model}
|
||||||
|
<svelte:component this={model.presenter} {isDraggable} {...model.props ?? {}} value={item} />
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user