2021-08-06 08:31:17 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
|
|
|
// Copyright © 2021 Hardcore Engineering Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
2022-01-20 09:18:24 +00:00
|
|
|
// import core from '@anticrm/core'
|
|
|
|
import type { Class, Doc, Ref } from '@anticrm/core'
|
2021-08-06 08:31:17 +00:00
|
|
|
import { getResource } from '@anticrm/platform'
|
|
|
|
import type { AnySvelteComponent } from '@anticrm/ui'
|
|
|
|
import view from '@anticrm/view'
|
2021-12-30 09:04:32 +00:00
|
|
|
import { getAttribute, KeyedAttribute, updateAttribute } from '../attributes'
|
2021-12-06 15:15:53 +00:00
|
|
|
import { getAttributePresenterClass, getClient } from '../utils'
|
2021-08-06 08:31:17 +00:00
|
|
|
|
|
|
|
export let _class: Ref<Class<Doc>>
|
2021-12-30 09:04:32 +00:00
|
|
|
export let key: KeyedAttribute | string
|
2021-09-12 22:01:18 +00:00
|
|
|
export let object: any
|
|
|
|
export let maxWidth: string
|
2021-08-06 08:31:17 +00:00
|
|
|
export let focus: boolean = false
|
2022-02-25 15:32:23 +00:00
|
|
|
export let editable = true
|
2022-05-14 09:47:00 +00:00
|
|
|
export let focusIndex = -1
|
2021-08-06 08:31:17 +00:00
|
|
|
|
|
|
|
const client = getClient()
|
|
|
|
const hierarchy = client.getHierarchy()
|
|
|
|
|
2021-12-30 09:04:32 +00:00
|
|
|
$: attribute = typeof key === 'string' ? hierarchy.getAttribute(_class, key) : key.attr
|
|
|
|
$: attributeKey = typeof key === 'string' ? key : key.key
|
2022-06-08 13:55:01 +00:00
|
|
|
$: presenterClass = attribute !== undefined ? getAttributePresenterClass(hierarchy, attribute) : undefined
|
2021-08-06 08:31:17 +00:00
|
|
|
|
|
|
|
let editor: Promise<AnySvelteComponent> | undefined
|
|
|
|
|
2022-06-08 13:55:01 +00:00
|
|
|
$: if (presenterClass !== undefined) {
|
|
|
|
const typeClass = hierarchy.getClass(presenterClass.attrClass)
|
2021-08-06 08:31:17 +00:00
|
|
|
const editorMixin = hierarchy.as(typeClass, view.mixin.AttributeEditor)
|
2022-06-15 17:25:58 +00:00
|
|
|
editor = getResource(editorMixin.inlineEditor)
|
2021-08-06 08:31:17 +00:00
|
|
|
}
|
2021-09-12 22:01:18 +00:00
|
|
|
|
2021-12-06 15:15:53 +00:00
|
|
|
function onChange (value: any) {
|
2022-02-25 15:32:23 +00:00
|
|
|
if (!editable) return
|
2021-09-12 22:01:18 +00:00
|
|
|
const doc = object as Doc
|
2021-12-30 09:04:32 +00:00
|
|
|
updateAttribute(client, doc, _class, { key: attributeKey, attr: attribute }, value)
|
2021-09-12 22:01:18 +00:00
|
|
|
}
|
2021-08-06 08:31:17 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if editor}
|
|
|
|
{#await editor}
|
|
|
|
...
|
|
|
|
{:then instance}
|
2022-04-29 05:27:17 +00:00
|
|
|
<svelte:component
|
|
|
|
this={instance}
|
|
|
|
label={attribute?.label}
|
|
|
|
placeholder={attribute?.label}
|
2022-05-06 17:46:34 +00:00
|
|
|
type={attribute?.type}
|
2022-04-29 05:27:17 +00:00
|
|
|
{maxWidth}
|
|
|
|
value={getAttribute(client, object, { key: attributeKey, attr: attribute })}
|
|
|
|
{onChange}
|
|
|
|
{focus}
|
2022-05-14 09:47:00 +00:00
|
|
|
{focusIndex}
|
2022-04-29 05:27:17 +00:00
|
|
|
/>
|
2021-08-06 08:31:17 +00:00
|
|
|
{/await}
|
|
|
|
{/if}
|