|
|
@ -14,17 +14,27 @@ let activeContainerIndex = -1;
|
|
|
|
|
|
|
|
|
|
|
|
export const getViewContent = () => containers[activeContainerIndex]?.content;
|
|
|
|
export const getViewContent = () => containers[activeContainerIndex]?.content;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* clears current view so it is empty and ready to be re-used.
|
|
|
|
|
|
|
|
* only clears the current view, not all views
|
|
|
|
|
|
|
|
*/
|
|
|
|
export const clearView = () => {
|
|
|
|
export const clearView = () => {
|
|
|
|
// TODO: this is clears the current view, but it should probably do this for all views
|
|
|
|
|
|
|
|
const domMap = containers[activeContainerIndex]?.dom;
|
|
|
|
const domMap = containers[activeContainerIndex]?.dom;
|
|
|
|
Object.keys(domMap).forEach(eventId => delete domMap[eventId]);
|
|
|
|
Object.keys(domMap).forEach(eventId => delete domMap[eventId]);
|
|
|
|
getViewContent().replaceChildren();
|
|
|
|
getViewContent().replaceChildren();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* get elmenet stored in internal DOMMap of the current view
|
|
|
|
|
|
|
|
* alternative to internal map in view.dom, is to use id="" attribute, however same event could be shown in different views so event.id is not unique.
|
|
|
|
|
|
|
|
*/
|
|
|
|
export const getViewElem = (id: string) => {
|
|
|
|
export const getViewElem = (id: string) => {
|
|
|
|
return containers[activeContainerIndex]?.dom[id];
|
|
|
|
return containers[activeContainerIndex]?.dom[id];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* store element in internal view.dom map using id as key
|
|
|
|
|
|
|
|
*/
|
|
|
|
export const setViewElem = (id: string, node: HTMLElement) => {
|
|
|
|
export const setViewElem = (id: string, node: HTMLElement) => {
|
|
|
|
const container = containers[activeContainerIndex];
|
|
|
|
const container = containers[activeContainerIndex];
|
|
|
|
if (container) {
|
|
|
|
if (container) {
|
|
|
@ -54,6 +64,11 @@ type GetViewOptions = () => ViewTemplateOptions;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export const getViewOptions: GetViewOptions = () => containers[activeContainerIndex]?.options || {type: 'feed'};
|
|
|
|
export const getViewOptions: GetViewOptions = () => containers[activeContainerIndex]?.options || {type: 'feed'};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* changes the current view and transitions to the view specified by route
|
|
|
|
|
|
|
|
* example:
|
|
|
|
|
|
|
|
* view('/npub0293ji3gojaed32r4r412', {type: 'feed})
|
|
|
|
|
|
|
|
*/
|
|
|
|
export const view = (
|
|
|
|
export const view = (
|
|
|
|
route: string,
|
|
|
|
route: string,
|
|
|
|
options: ViewTemplateOptions,
|
|
|
|
options: ViewTemplateOptions,
|
|
|
|