-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/stencila-authorship-component-2206'
- Loading branch information
Showing
15 changed files
with
266 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { createContext } from '@lit/context' | ||
|
||
/** | ||
* Context object to be used for the state of any Entity | ||
*/ | ||
export interface EntityContext { | ||
readonly nodeId?: string | ||
|
||
/** | ||
* Whether the entity's respective node card is open | ||
*/ | ||
cardOpen?: boolean | ||
} | ||
|
||
/** | ||
* Context object for state of Entity | ||
*/ | ||
export const entityContext = createContext<EntityContext>('entity-node-card') | ||
|
||
export interface InstructionContext extends EntityContext { | ||
childEntitys: string[] | ||
} | ||
|
||
export const instructionContext = createContext<InstructionContext>( | ||
'instruction-node-card' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,92 @@ | ||
import { apply } from '@twind/core' | ||
import { consume } from '@lit/context' | ||
import { ProvenanceCategory } from '@stencila/types' | ||
import { apply, css } from '@twind/core' | ||
import { LitElement, html } from 'lit' | ||
import { property, customElement } from 'lit/decorators' | ||
import { property, customElement, state } from 'lit/decorators' | ||
|
||
import { withTwind } from '../../../twind' | ||
import { ProvenanceHighlightLvl, getProvHighlight } from '../icons-and-colours' | ||
import { entityContext, EntityContext } from '../context' | ||
import { | ||
ProvenanceHighlightLevel, | ||
getProvenanceHighlight, | ||
} from '../icons-and-colours' | ||
|
||
/** | ||
* Renders the author provenance highlighting of document text. | ||
*/ | ||
@customElement('stencila-authorship') | ||
@withTwind() | ||
export class StencilaAuthorship extends LitElement { | ||
@consume({ context: entityContext, subscribe: true }) | ||
@state() | ||
context: EntityContext | ||
|
||
/** | ||
* Number of authors who have edited this content. | ||
*/ | ||
@property() | ||
count: number | ||
|
||
/** | ||
* A stringified array, containing the numeric value for each author. | ||
*/ | ||
@property() | ||
authors: string | ||
|
||
/** | ||
* provenance string | ||
* one, or a combination of: 'Hw', 'He', 'Hv', 'Mw', 'Me', 'Mv'. | ||
*/ | ||
@property() | ||
provenance: string | ||
provenance: ProvenanceCategory | ||
|
||
/** | ||
* 'Machine influence' rank, | ||
* number from 0 (human only) to 5 (machine only). | ||
*/ | ||
@property() | ||
mi: number | ||
|
||
override render() { | ||
const bgColour = getProvHighlight(this.mi as ProvenanceHighlightLvl) | ||
|
||
return html` | ||
<sl-tooltip style="--show-delay: 1000ms;"> | ||
<div slot="content"> | ||
${this.renderTooltipContent('Author count', this.count)} | ||
${this.renderTooltipContent('Provenance', this.provenance)} | ||
</div> | ||
<span style="background-color: ${bgColour}"> | ||
<slot></slot> | ||
</span> | ||
</sl-tooltip> | ||
const bgColour = getProvenanceHighlight(this.mi as ProvenanceHighlightLevel) | ||
|
||
const toolTipStyles = css` | ||
&::part(body) { | ||
color: #000000; | ||
background-color: ${getProvenanceHighlight(2)}; | ||
} | ||
&::part(base__arrow) { | ||
background-color: ${getProvenanceHighlight(2)}; | ||
} | ||
` | ||
|
||
if (this.context.cardOpen) { | ||
return html` | ||
<sl-tooltip | ||
style="--show-delay: 1000ms; background-color: white;" | ||
placement="bottom-start" | ||
class=${toolTipStyles} | ||
> | ||
<!-- tooltip content --> | ||
<div slot="content"> | ||
${this.renderTooltipContent( | ||
`${this.count} Author${this.count > 1 ? 's' : ''}` | ||
)} | ||
${this.renderTooltipContent(this.provenance)} | ||
</div> | ||
<!-- --> | ||
<span style="background-color: ${bgColour};"> | ||
<slot></slot> | ||
</span> | ||
</sl-tooltip> | ||
` | ||
} else { | ||
return html`<slot></slot>` | ||
} | ||
} | ||
|
||
renderTooltipContent(property: string, value: string | number) { | ||
renderTooltipContent(value: string | number) { | ||
const styles = apply(['flex justify-between', 'text-sm']) | ||
return html` | ||
<div class=${styles}> | ||
<span class="font-bold mr-2">${property}: </span> | ||
<span>${value}</span> | ||
</div> | ||
` | ||
return html` <div class=${styles}>${value}</div> ` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.