File tree Expand file tree Collapse file tree 4 files changed +51
-6
lines changed
Expand file tree Collapse file tree 4 files changed +51
-6
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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
55export class HyperlinkBehavior {
66 public attach ( element : HTMLElement , hyperlink : HyperlinkModel ) : void {
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import * as Array from "@paperbits/common";
22import * as ko from "knockout" ;
33import { Keys } from "@paperbits/common" ;
44import { Events } from "@paperbits/common/events" ;
5- import { AriaAttributes , AriaRoles , Attributes } from "@paperbits/common /html" ;
5+ import { AriaAttributes , AriaRoles , Attributes } from ".. /html" ;
66import { BehaviorHandle } from "./behavior" ;
77
88const selectedClassName = "selected" ;
Original file line number Diff line number Diff line change 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
66export 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 ( ) ;
You can’t perform that action at this time.
0 commit comments