File tree Expand file tree Collapse file tree 8 files changed +191
-0
lines changed Expand file tree Collapse file tree 8 files changed +191
-0
lines changed Original file line number Diff line number Diff line change
1
+ lib
Original file line number Diff line number Diff line change
1
+ src
2
+ demo
Original file line number Diff line number Diff line change
1
+ .pie
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ elements : {
3
+ 'passage-element' : '..'
4
+ } ,
5
+ models : [
6
+ {
7
+ id : '1' ,
8
+ element : 'passage-element' ,
9
+ mode : 'view' ,
10
+ title : 'Ineskeen Road, July Evening' ,
11
+ content : `The bicycles go by in twos and threes -<br/>
12
+ There's a dance in Billy Brennan's barn tonight,<br/>
13
+ And there's the half-talk code of mysteries<br/>
14
+ And the wink-and-elbow language of delight.<br/>
15
+ Half-past eight and there is not a spot<br/>
16
+ Upon a mile of road, no shadow thrown<br/>
17
+ That might turn out a man or woman, not<br/>
18
+ A footfall tapping secrecies of stone. <br/>
19
+ <p/>
20
+ I have what every poet hates in spite<br/>
21
+ Of all the solemn talk of contemplation.<br/>
22
+ Oh, Alexander Selkirk knew the plight<br/>
23
+ Of being king and government and nation.<br/>
24
+ A road, a mile of kingdom. I am king<br/>
25
+ Of banks and stones and every blooming thing.<br/>
26
+ `
27
+ }
28
+ ]
29
+ } ;
Original file line number Diff line number Diff line change
1
+ < passage-element pie-id ="1 "> </ passage-element >
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " @pie-ui/passage" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " Element for rendering passage content" ,
5
+ "author" : " pie framework developers" ,
6
+ "keywords" : [
7
+ " pie" ,
8
+ " pie-ui" ,
9
+ " custom-element"
10
+ ],
11
+ "main" : " lib/index.js" ,
12
+ "repository" : " pie-framework/pie-ui" ,
13
+ "publishConfig" : {
14
+ "access" : " public"
15
+ },
16
+ "license" : " ISC" ,
17
+ "dependencies" : {
18
+ "@pie-framework/pie-player-events" : " ^0.1.0"
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ import { SessionChangedEvent } from '@pie-framework/pie-player-events' ;
2
+
3
+ const defaultModel = {
4
+ title : 'title' ,
5
+ content : 'content' ,
6
+ } ;
7
+
8
+ const defaultSession = { id : 1 } ;
9
+
10
+
11
+ describe ( 'passage' , ( ) => {
12
+ let Def ;
13
+ let el ;
14
+
15
+ beforeAll ( ( ) => {
16
+ Def = require ( '../index' ) . default ;
17
+ } ) ;
18
+
19
+ beforeEach ( ( ) => {
20
+ el = new Def ( ) ;
21
+ el . connectedCallback ( ) ;
22
+ el . tagName = 'passage-element' ;
23
+ el . model = defaultModel ;
24
+ el . session = defaultSession ;
25
+ } ) ;
26
+
27
+ describe ( 'model' , ( ) => {
28
+ it ( 'should have set the model' , ( ) => {
29
+ expect ( el . _model ) . toEqual ( defaultModel ) ;
30
+ } ) ;
31
+ } ) ;
32
+
33
+ it ( 'should have set the session' , ( ) => {
34
+ expect ( el . _session ) . toEqual ( defaultSession ) ;
35
+ } ) ;
36
+
37
+ describe ( 'session' , ( ) => {
38
+ const dispatchesSessionEvent = ( key , value ) => {
39
+ it ( `${ key } dispatches session changed event` , ( ) => {
40
+ const session = { id : key , value} ;
41
+ el . dispatchSessionChanged ( session , key ) ;
42
+
43
+ expect ( el . dispatchEvent ) . toBeCalledWith (
44
+ new SessionChangedEvent ( 'passage-element' , false )
45
+ ) ;
46
+ expect ( el . _session . value [ key ] ) . toEqual ( session ) ;
47
+ } ) ;
48
+ } ;
49
+
50
+ } ) ;
51
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { ModelSetEvent } from '@pie-framework/pie-player-events' ;
2
+
3
+ export default class PiePassage extends HTMLElement {
4
+ constructor ( ) {
5
+ super ( ) ;
6
+ this . _model = {
7
+ title : '' ,
8
+ content : ''
9
+ } ;
10
+ this . _session = null ;
11
+ }
12
+
13
+
14
+ containerStyle = `
15
+ display: -ms-flexbox;
16
+ display: -webkit-flex;
17
+ display: flex;
18
+ -webkit-flex-direction: column;
19
+ -ms-flex-direction: column;
20
+ flex-direction: column;
21
+ -webkit-flex-wrap: nowrap;
22
+ -ms-flex-wrap: nowrap;
23
+ flex-wrap: nowrap;
24
+ -webkit-justify-content: flex-start;
25
+ -ms-flex-pack: start;
26
+ justify-content: flex-start;
27
+ -webkit-align-content: stretch;
28
+ -ms-flex-line-pack: stretch;
29
+ align-content: stretch;
30
+ -webkit-align-items: flex-start;
31
+ -ms-flex-align: start;
32
+ align-items: flex-start;
33
+ ` ;
34
+
35
+ titleStyle = `
36
+ -webkit-order: 0;
37
+ -ms-flex-order: 0;
38
+ order: 0;
39
+ -webkit-flex: 0 1 auto;
40
+ -ms-flex: 0 1 auto;
41
+ flex: 0 1 auto;
42
+ -webkit-align-self: stretch;
43
+ -ms-flex-item-align: stretch;
44
+ align-self: stretch;
45
+ ` ;
46
+
47
+ contentStyle = `
48
+ -webkit-order: 0;
49
+ -ms-flex-order: 0;
50
+ order: 0;
51
+ -webkit-flex: 1 1 auto;
52
+ -ms-flex: 1 1 auto;
53
+ flex: 1 1 auto;
54
+ -webkit-align-self: stretch;
55
+ -ms-flex-item-align: stretch;
56
+ align-self: stretch;
57
+ ` ;
58
+ set model ( s ) {
59
+ this . _model = s ;
60
+ this . dispatchEvent (
61
+ new ModelSetEvent (
62
+ this . tagName . toLowerCase ( ) ,
63
+ this . _session ,
64
+ ! ! this . _model
65
+ )
66
+ ) ;
67
+ this . _render ( ) ;
68
+ }
69
+
70
+ set session ( s ) {
71
+ this . _session = s ;
72
+ }
73
+
74
+ connectedCallback ( ) {
75
+ this . _render ( ) ;
76
+ }
77
+
78
+ _render ( ) {
79
+ this . innerHTML = `
80
+ <div style="${ this . containerStyle } ">
81
+ <h2 style="${ this . titleStyle } ">${ this . _model . title } </h2>
82
+ <divs tyle="${ this . contentStyle } ">${ this . _model . content } </div>
83
+ </div>
84
+ ` ;
85
+ }
86
+ }
You can’t perform that action at this time.
0 commit comments