Skip to content

Commit

Permalink
Fixed issues with menu and hyperlink rendering. (#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
azaslonov committed Apr 1, 2021
1 parent 18e7c8a commit f70ebf1
Show file tree
Hide file tree
Showing 14 changed files with 894 additions and 3,655 deletions.
4,179 changes: 624 additions & 3,555 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
},
"dependencies": {
"@paperbits/azure": "0.1.356-hotfix",
"@paperbits/common": "0.1.389",
"@paperbits/core": "0.1.389",
"@paperbits/prosemirror": "0.1.389",
"@paperbits/styles": "0.1.389",
"@paperbits/common": "0.1.395",
"@paperbits/core": "0.1.395",
"@paperbits/prosemirror": "0.1.395",
"@paperbits/styles": "0.1.395",
"@webcomponents/custom-elements": "1.4.2",
"@webcomponents/shadydom": "^1.7.4",
"adal-vanilla": "^1.0.18",
Expand All @@ -81,7 +81,6 @@
"knockout-mapping": "^2.6.0",
"knockout.validation": "^2.0.4",
"liquidjs": "^9.16.1",
"lodash": "^4.17.20",
"lunr": "^2.3.9",
"mime-types": "^2.1.27",
"moment": "^2.29.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as ko from "knockout";
import * as validation from "knockout.validation";
import * as _ from "lodash";
import template from "./operation-console.html";
import { Component, Param, OnMounted } from "@paperbits/common/ko/decorators";
import { Operation } from "../../../../../models/operation";
Expand Down
17 changes: 15 additions & 2 deletions src/persistence/mapiObjectStorage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as _ from "lodash";
import * as Objects from "@paperbits/common";
import { IObjectStorage, Query, Operator, Page } from "@paperbits/common/persistence";
import { MapiClient } from "../services/mapiClient";
Expand All @@ -8,6 +7,7 @@ import { AppError } from "../errors";
import { defaultPageSize } from "../constants";
import { PageContract } from "../contracts/page";
import { LocaleModel } from "@paperbits/common/localization";
import { PopupModel } from "@paperbits/core/popup";


const localizedContentTypes = ["page", "layout", "blogpost", "navigation", "block"];
Expand Down Expand Up @@ -194,6 +194,11 @@ export class MapiObjectStorage implements IObjectStorage {
mapiContentItem = "en-us";
break;

case "popups":
mapiContentType = "popups";
mapiContentItem = contentItem;
break;

default:
// throw new AppError(`Unknown content type: "${contentType}"`);
return key;
Expand Down Expand Up @@ -375,13 +380,21 @@ export class MapiObjectStorage implements IObjectStorage {
const isLocalized = localizedContentTypes.includes(contentType);
const localeSearchPrefix = isLocalized ? `${selectedLocale}/` : "";

if (key === "popups") {
const pageOfPopups: Page<PopupModel> = {
value: []
};

return <any>pageOfPopups;
}

if (key === "locales") {
const pageOfLocales: Page<LocaleModel> = {
value: [{
key: `contentTypes/locales/contentItem/en_us`,
code: "en-us",
displayName: "English (US)"
}]
}]
};

return <any>pageOfLocales;
Expand Down
5 changes: 2 additions & 3 deletions src/services/mapiClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as _ from "lodash";
import * as Constants from "./../constants";
import { ISettingsProvider } from "@paperbits/common/configuration";
import { Logger } from "@paperbits/common/logging";
Expand Down Expand Up @@ -129,7 +128,7 @@ export class MapiClient {
}
}
}

if (!portalHeader && httpRequest.method !== HttpMethod.head) {
httpRequest.headers.push(MapiClient.getPortalHeader());
}
Expand Down Expand Up @@ -160,7 +159,7 @@ export class MapiClient {
const text = response.toText();

if (response.statusCode >= 200 && response.statusCode < 300) {
if (_.includes(contentType, "json") && text.length > 0) {
if ((contentType.includes("json")) && text.length > 0) {
return JSON.parse(text) as T;
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/themes/designer/styles/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}

&.form-group-collapsible {
.form-label {
& > .form-label {
position: unset;
}

Expand Down
78 changes: 0 additions & 78 deletions src/themes/website/scripts/collapsibles.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/themes/website/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* found in the LICENSE file and at https://paperbits.io/license/mit.
*/

import "./collapsibles";
import "./toggles";
173 changes: 173 additions & 0 deletions src/themes/website/scripts/toggles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import { Keys } from "@paperbits/common";
import { AriaAttributes } from "@paperbits/common/html";

const toggleAtributeName = "data-toggle";
const targetAttributeName = "data-target";
const dismissAttributeName = "data-dismiss";
const showClassName = "show";


const onClick = (event: MouseEvent) => {
if (event.button !== 0) {
return;
}

const clickedElement = <HTMLElement>event.target;
const toggleElement = <HTMLElement>clickedElement.closest(`[${toggleAtributeName}]`);

if (!toggleElement) {
return;
}

event.preventDefault();

const toggleType = toggleElement.getAttribute(toggleAtributeName);

switch (toggleType) {
case "popup":
const targetSelector = toggleElement.getAttribute(targetAttributeName);

if (!targetSelector) {
return;
}

const targetElement = <HTMLElement>document.querySelector(targetSelector);

if (!targetElement) {
return;
}

onShowPopup(toggleElement, targetElement);
break;

case "dropdown":
onShowDropdown(toggleElement);
break;

case "collapsible":
onShowCollapsible(toggleElement);
break;

default:
console.warn(`Unknown data-toggle value ${toggleType}`);
}
};

const onKeyDown = (event: KeyboardEvent) => {
if (event.keyCode !== Keys.Enter && event.keyCode !== Keys.Space) {
return;
}
};

const onShowCollapsible = (toggleElement: HTMLElement): void => {
const collapsiblePanelElement = toggleElement.closest(".collapsible-panel");
const collapsiblePanelDismissElement = collapsiblePanelElement.querySelector(`[${dismissAttributeName}]`);

collapsiblePanelElement.classList.add(showClassName);
toggleElement.setAttribute(AriaAttributes.expanded, "true");

const closeCollapsible = () => {
toggleElement.setAttribute(AriaAttributes.expanded, "false");
collapsiblePanelElement.ownerDocument.removeEventListener("mousedown", associatedClick, true);
collapsiblePanelDismissElement.removeEventListener("mousedown", associatedClick);
collapsiblePanelElement.classList.remove(showClassName);
};

const associatedClick = (event: MouseEvent) => {
const clickedElement = <HTMLElement>event.target;

if (collapsiblePanelElement.contains(clickedElement)) {
return;
}

closeCollapsible();
};

collapsiblePanelElement.ownerDocument.addEventListener("mousedown", associatedClick, true);
collapsiblePanelDismissElement.addEventListener("mousedown", closeCollapsible);
};

const onShowDropdown = (toggleElement: HTMLElement): void => {
const dropdownElement = toggleElement.closest(".nav-item").querySelector(".dropdown");

if (!dropdownElement) {
return;
}

dropdownElement.classList.add(showClassName);
toggleElement.setAttribute(AriaAttributes.expanded, "true");

const associatedClick = (event: MouseEvent) => {
toggleElement.setAttribute(AriaAttributes.expanded, "false");
dropdownElement.ownerDocument.removeEventListener("mousedown", associatedClick, true);
dropdownElement.classList.remove(showClassName);
};

dropdownElement.ownerDocument.addEventListener("mousedown", associatedClick, true);
};

const onShowPopup = (toggleElement: HTMLElement, targetElement: HTMLElement): void => {
toggleElement.setAttribute(AriaAttributes.expanded, "true");

const popupContainerElement: HTMLElement = targetElement.querySelector(".popup-container");

const repositionPopup = () => {
const computedStyles = getComputedStyle(popupContainerElement);

if (computedStyles.position === "absolute") {
const toggleElementRect = toggleElement.getBoundingClientRect();
const popupContainerElement: HTMLElement = targetElement.querySelector(".popup-container");
popupContainerElement.style.top = window.scrollY + toggleElementRect.bottom + "px";
popupContainerElement.style.left = toggleElementRect.left + "px";
}
else {
popupContainerElement.removeAttribute("style");
}
};

repositionPopup();

const popupDismissElement: HTMLElement = targetElement.querySelector("[data-dismiss]");

const clickOutside = (event: MouseEvent) => {
const clickTarget = <HTMLElement>event.target;

if (clickTarget.nodeName === "BODY") {
return;
}

const isPopupContainer = popupContainerElement.contains(clickTarget);

if (isPopupContainer) {
return;
}

closePopup();
};

const closePopup = () => {
popupDismissElement.removeEventListener("mousedown", closePopup);
targetElement.ownerDocument.removeEventListener("mousedown", clickOutside);
document.removeEventListener("onPopupRepositionRequested", repositionPopup);
targetElement.classList.remove(showClassName);
};

popupDismissElement.addEventListener("mousedown", closePopup);

targetElement.classList.add(showClassName);

setTimeout(() => {
targetElement.ownerDocument.addEventListener("mousedown", clickOutside);
}, 500);

// Temporary hack to reposition popup:
document.addEventListener("onPopupRepositionRequested", () => {
setTimeout(() => {
repositionPopup();
}, 10);

});
};

document.addEventListener("mousedown", onClick, true);
document.addEventListener("keydown", onKeyDown, true);
Loading

0 comments on commit f70ebf1

Please sign in to comment.