Skip to content

Commit 341003c

Browse files
committed
Added markdown and hyperlink behaviors.
1 parent 310d3e5 commit 341003c

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

src/behaviors/bahavior.markdown.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { remark } from "remark";
2+
import remarkParse from "remark-parse";
3+
import remarkGfm from "remark-gfm";
4+
import remarkRehype from "remark-rehype";
5+
import rehypeRaw from "rehype-raw";
6+
import rehypeStringify from "rehype-stringify";
7+
import { BehaviorHandle } from "./behavior";
8+
9+
10+
export class MarkdownBehavior {
11+
public attach(element: HTMLElement, markdown: string): BehaviorHandle {
12+
const updateContent = async (markdown) => {
13+
const html: any = await remark()
14+
.use(remarkParse)
15+
.use(remarkGfm)
16+
.use(remarkRehype, { allowDangerousHtml: true })
17+
.use(rehypeRaw)
18+
.use(rehypeStringify)
19+
.process(markdown);
20+
21+
element.innerHTML = html;
22+
}
23+
24+
updateContent(markdown);
25+
26+
const handle: BehaviorHandle = {
27+
detach: () => { }
28+
}
29+
30+
return handle;
31+
}
32+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
import { HyperlinkModel, HyperlinkTarget } from "@paperbits/common/permalinks";
3-
import { Attributes, DataAttributes, HyperlinkRels } from "@paperbits/common/html";
2+
import { HyperlinkModel, HyperlinkTarget } from "../permalinks";
3+
import { Attributes, DataAttributes, HyperlinkRels } from "../html";
44

55
export class HyperlinkBehavior {
66
public attach(element: HTMLElement, hyperlink: HyperlinkModel): void {

src/behaviors/behavior.listbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as Array from "@paperbits/common";
22
import * as ko from "knockout";
33
import { Keys } from "@paperbits/common";
44
import { Events } from "@paperbits/common/events";
5-
import { AriaAttributes, AriaRoles, Attributes } from "@paperbits/common/html";
5+
import { AriaAttributes, AriaRoles, Attributes } from "../html";
66
import { BehaviorHandle } from "./behavior";
77

88
const selectedClassName = "selected";

src/behaviors/behavior.stickTo.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
import { ViewManager, ViewManagerMode } from "@paperbits/common/ui";
3-
import { Events } from "@paperbits/common/events";
4-
import { BehaviorHandle } from "@paperbits/common/behaviors/behavior";
2+
import { ViewManager, ViewManagerMode } from "../ui";
3+
import { Events } from "../events";
4+
import { BehaviorHandle } from "./behavior";
55

66
export enum StickToPlacement {
77
border = "border",
@@ -103,6 +103,8 @@ export class StickToBehavior {
103103

104104
element.style.top = frameRect.top + coordY + "px";
105105

106+
107+
106108
if (anchors.includes("left")) {
107109
element.style.left = frameRect.left + targetRect.left + offsetX + "px";
108110
}
@@ -130,6 +132,17 @@ export class StickToBehavior {
130132
const targetParentRect = config.target.parentElement.getBoundingClientRect();
131133
element.style.top = targetParentRect.top - Math.floor(element.clientHeight / 2) + "px";
132134
}
135+
136+
setTimeout(() => {
137+
const elementRect = element.getBoundingClientRect();
138+
139+
console.log(elementRect);
140+
141+
if (elementRect.left < 0) {
142+
element.style.left = "0px";
143+
element.style.right = null
144+
}
145+
}, 10);
133146
};
134147

135148
updatePosition();

0 commit comments

Comments
 (0)