workspace base and content refactor
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
import { UUITextStyles } from '@umbraco-ui/uui-css/lib';
|
import { UUITextStyles } from '@umbraco-ui/uui-css/lib';
|
||||||
import { css, html, LitElement } from 'lit';
|
import { css, html, LitElement } from 'lit';
|
||||||
import { customElement, property } from 'lit/decorators.js';
|
import { customElement, property } from 'lit/decorators.js';
|
||||||
|
import type { UmbWorkspaceContext } from '../shared/workspace/workspace.context';
|
||||||
import { umbExtensionsRegistry } from '@umbraco-cms/extensions-registry';
|
import { umbExtensionsRegistry } from '@umbraco-cms/extensions-registry';
|
||||||
import type { ManifestWorkspaceView } from '@umbraco-cms/models';
|
import type { ManifestWorkspaceView } from '@umbraco-cms/models';
|
||||||
import { UmbContextConsumerMixin, UmbContextProviderMixin } from '@umbraco-cms/context-api';
|
import { UmbContextConsumerMixin, UmbContextProviderMixin } from '@umbraco-cms/context-api';
|
||||||
|
|
||||||
import '../shared/workspace-content/workspace-content.element';
|
import '../shared/workspace-content/workspace-content.element';
|
||||||
|
|
||||||
@customElement('umb-workspace-document')
|
@customElement('umb-workspace-document')
|
||||||
@@ -23,9 +23,14 @@ export class UmbWorkspaceDocumentElement extends UmbContextConsumerMixin(UmbCont
|
|||||||
@property()
|
@property()
|
||||||
entityKey!: string;
|
entityKey!: string;
|
||||||
|
|
||||||
|
private _workspaceContext!:UmbWorkspaceContext;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
// TODO: Implement RXJS for reactivity if one of two props changes.
|
||||||
|
this.consumeContext('umbWorkspaceContext', (context) => this._workspaceContext = context)
|
||||||
|
|
||||||
// TODO: consider if registering extensions should happen initially or else where, to enable unregister of extensions.
|
// TODO: consider if registering extensions should happen initially or else where, to enable unregister of extensions.
|
||||||
this._registerWorkspaceViews();
|
this._registerWorkspaceViews();
|
||||||
}
|
}
|
||||||
@@ -67,7 +72,7 @@ export class UmbWorkspaceDocumentElement extends UmbContextConsumerMixin(UmbCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return html`<umb-workspace-content store-alias='umbDocumentStore' .entityKey=${this.entityKey} alias="Umb.Workspace.Document"></umb-workspace-content>`;
|
return html`<umb-workspace-content store-alias='umbDocumentStore' .entityKey=${this._workspaceContext.entityKey} alias="Umb.Workspace.Document"></umb-workspace-content>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,17 @@ export class UmbWorkspaceContentElement extends UmbContextProviderMixin(
|
|||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
private _entityKey!: string;
|
||||||
@property()
|
@property()
|
||||||
entityKey!: string;
|
public get entityKey() : string {
|
||||||
|
return this._entityKey;
|
||||||
|
}
|
||||||
|
public set entityKey(value:string) {
|
||||||
|
if(this._entityKey !== value) {
|
||||||
|
this._entityKey = value;
|
||||||
|
this._observeContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@property()
|
@property()
|
||||||
alias!: string;
|
alias!: string;
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
export class UmbWorkspaceContext {
|
||||||
|
|
||||||
|
// TODO: Should this use RxJS to be reactive? A store, to hold the props below?
|
||||||
|
|
||||||
|
public entityKey = '';
|
||||||
|
public entityType = '';
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,16 +1,13 @@
|
|||||||
import { css, html, LitElement } from 'lit';
|
import { css, html, LitElement } from 'lit';
|
||||||
import { UUITextStyles } from '@umbraco-ui/uui-css/lib';
|
import { UUITextStyles } from '@umbraco-ui/uui-css/lib';
|
||||||
import { customElement, property, state } from 'lit/decorators.js';
|
import { customElement, property } from 'lit/decorators.js';
|
||||||
import { map } from 'rxjs';
|
|
||||||
|
|
||||||
import { UmbObserverMixin } from '@umbraco-cms/observable-api';
|
import { UmbObserverMixin } from '@umbraco-cms/observable-api';
|
||||||
import { createExtensionElement } from '@umbraco-cms/extensions-api';
|
import { UmbContextConsumerMixin, UmbContextProviderMixin } from '@umbraco-cms/context-api';
|
||||||
import { umbExtensionsRegistry } from '@umbraco-cms/extensions-registry';
|
import { UmbWorkspaceContext } from './workspace.context';
|
||||||
import { UmbContextConsumerMixin } from '@umbraco-cms/context-api';
|
|
||||||
import type { ManifestWorkspace } from '@umbraco-cms/models';
|
|
||||||
|
|
||||||
@customElement('umb-workspace')
|
@customElement('umb-workspace')
|
||||||
export class UmbWorkspaceElement extends UmbContextConsumerMixin(UmbObserverMixin(LitElement)) {
|
export class UmbWorkspaceElement extends UmbContextProviderMixin(UmbContextConsumerMixin(UmbObserverMixin(LitElement))) {
|
||||||
static styles = [
|
static styles = [
|
||||||
UUITextStyles,
|
UUITextStyles,
|
||||||
css`
|
css`
|
||||||
@@ -22,8 +19,15 @@ export class UmbWorkspaceElement extends UmbContextConsumerMixin(UmbObserverMixi
|
|||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
private _entityKey!: string;
|
||||||
@property()
|
@property()
|
||||||
public entityKey!: string;
|
public get entityKey(): string {
|
||||||
|
return this._entityKey;
|
||||||
|
}
|
||||||
|
public set entityKey(value: string) {
|
||||||
|
this._entityKey = value;
|
||||||
|
this._workspaceContext.entityKey = value;
|
||||||
|
}
|
||||||
|
|
||||||
private _entityType = '';
|
private _entityType = '';
|
||||||
@property()
|
@property()
|
||||||
@@ -32,55 +36,24 @@ export class UmbWorkspaceElement extends UmbContextConsumerMixin(UmbObserverMixi
|
|||||||
}
|
}
|
||||||
public set entityType(value: string) {
|
public set entityType(value: string) {
|
||||||
this._entityType = value;
|
this._entityType = value;
|
||||||
this._observeWorkspace();
|
this._workspaceContext.entityType = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@state()
|
private _workspaceContext:UmbWorkspaceContext = new UmbWorkspaceContext();
|
||||||
private _element?: HTMLElement;
|
|
||||||
|
|
||||||
private _currentWorkspaceAlias:string | null = null;
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
connectedCallback(): void {
|
this.provideContext('umbWorkspaceContext', this._workspaceContext);
|
||||||
super.connectedCallback();
|
|
||||||
this._observeWorkspace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
TODO: use future system of extension-slot, extension slots must use a condition-system which will be used to determine the filtering happening below.
|
|
||||||
This will first be possible to make when ContextApi is available, as conditions will use this system.
|
|
||||||
*/
|
|
||||||
private _observeWorkspace() {
|
|
||||||
this.observe<ManifestWorkspace | undefined>(
|
|
||||||
umbExtensionsRegistry
|
|
||||||
.extensionsOfType('workspace')
|
|
||||||
.pipe(map((workspaces) => workspaces.find((workspace) => workspace.meta.entityType === this.entityType))),
|
|
||||||
(workspace) => {
|
|
||||||
// don't rerender workspace if it's the same
|
|
||||||
const newWorkspaceAlias = workspace?.alias || '';
|
|
||||||
if (this._currentWorkspaceAlias === newWorkspaceAlias) return;
|
|
||||||
this._currentWorkspaceAlias = newWorkspaceAlias;
|
|
||||||
this._createElement(workspace);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _createElement(workspace?: ManifestWorkspace) {
|
// TODO: implement fallback workspace
|
||||||
this._element = workspace ? (await createExtensionElement(workspace)) : undefined;
|
// Note for extension-slot, we must enable giving the extension-slot a fallback element.
|
||||||
if (this._element) {
|
|
||||||
// TODO: use contextApi for this.
|
|
||||||
(this._element as any).entityKey = this.entityKey;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: implement fallback workspace
|
|
||||||
// Note for extension-slot, we must enable giving the extension-slot a fallback element.
|
|
||||||
const fallbackWorkspace = document.createElement('div');
|
|
||||||
fallbackWorkspace.innerHTML = '<p>No Workspace found</p>';
|
|
||||||
this._element = fallbackWorkspace;
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return html`${this._element}`;
|
return html`<umb-extension-slot type="workspace" .filter=${(workspace: any) => (workspace).meta.entityType === this._entityType}></umb-extension-slot>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user