11<!DOCTYPE html>
22< html lang ="en ">
3-
4- < head >
5- < meta charset ="UTF-8 ">
6- < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7- < title > Regular Layout</ title >
8- < style >
9- regular-layout {
10- overflow : hidden;
11- position : absolute;
12- top : 36px ;
13- left : 0 ;
14- right : 0 ;
15- bottom : 0 ;
16- }
17-
18- regular-layout-frame {
19- position : relative;
20- box-sizing : border-box;
21- margin : 3px ;
22- border-radius : 0 0 6px 6px ;
23- border : 1px solid # 666 ;
24- box-shadow : 0px 6px 6px -4px rgba (150 , 150 , 180 );
25- }
26-
27- .AAA {
28- background-color : # ffb3b0 ;
29- }
30-
31- .BBB {
32- background-color : # b0e0a3 ;
33- }
34-
35- .CCC {
36- background-color : # 99c9ff ;
37- }
38-
39- .DDD {
40- background-color : # ffe699 ;
41- }
42-
43- .EEE {
44- background-color : # ffcf99 ;
45- }
46-
47- .FFF {
48- background-color : # ff99fd ;
49- }
50-
51- regular-layout-frame : not ([slot ]) {
52- background-color : rgba (0 , 0 , 0 , 0.2 );
53- border : 1px dashed rgb (0 , 0 , 0 );
54- border-radius : 6px ;
55- margin : 0 ;
56- box-shadow : none;
57- transition :
58- top 0.1s ease-in-out,
59- height 0.1s ease-in-out,
60- width 0.1s ease-in-out,
61- left 0.1s ease-in-out;
62- }
63-
64- regular-layout-frame ::part (container ) {
65- display : none;
66- }
67-
68- regular-layout-frame [slot ]::part (container ) {
69- display : revert;
70- }
71-
72-
73- regular-layout-frame {
74- --titlebar-height : 24px ;
75- }
76-
77- regular-layout-frame ::part (titlebar ) {
78- display : flex;
79- align-items : center;
80- padding : 0 12px ;
81- cursor : pointer;
82- background-color : inherit;
83- border : 1px solid # 666 ;
84- border-radius : 6px 6px 0 0 ;
85- margin-left : -1px ;
86- margin-right : -1px ;
87- margin-bottom : 0px ;
88- max-width : 200px ;
89- }
90- </ style >
91- </ head >
92-
93- < body >
94- < header >
95- < button id ="add "> Add Panel</ button >
96- < button id ="save "> Save State</ button >
97- < button id ="restore "> Restore State</ button >
98- < button id ="clear "> Clear</ button >
99- </ header >
100- < regular-layout >
101- < regular-layout-frame class ="AAA " slot ="AAA "> </ regular-layout-frame >
102- < regular-layout-frame class ="BBB " slot ="BBB "> </ regular-layout-frame >
103- < regular-layout-frame class ="CCC " slot ="CCC "> </ regular-layout-frame >
104- < regular-layout-frame class ="DDD " slot ="DDD "> </ regular-layout-frame >
105- < regular-layout-frame class ="EEE " slot ="EEE "> </ regular-layout-frame >
106- < regular-layout-frame class ="FFF " slot ="FFF "> </ regular-layout-frame >
107- </ regular-layout >
108- </ body >
109-
110- < script type ="module ">
111- import "./dist/index.js" ;
112-
113- const add = document . querySelector ( "#add" ) ;
114- const save = document . querySelector ( "#save" ) ;
115- const restore = document . querySelector ( "#restore" ) ;
116- const clear = document . querySelector ( "#clear" ) ;
117- add . addEventListener ( "click" , ( ) => {
118- // Note: this *demo* implementation leaks `div` elements, because they
119- // are not removed from the light DOM by `clear` or `restore`. You must
120- // handle the lifecycle of the light DOM objects yourself!
121- const chars = 'abcdefghijklmnopqrstuvwxyz' ;
122- let name = '' ;
123- for ( let i = 0 ; i < 8 ; i ++ ) {
124- name += chars . charAt ( Math . floor ( Math . random ( ) * chars . length ) ) ;
125- }
126-
127- const COLORS = [ "AAA" , "BBB" , "CCC" , "DDD" , "EEE" , "FFF" ] ;
128- const elem = document . createElement ( "regular-layout-frame" ) ;
129- elem . setAttribute ( "slot" , name ) ;
130- elem . classList . add ( COLORS [ Math . floor ( COLORS . length * Math . random ( ) ) ] )
131- layout . appendChild ( elem ) ;
132- layout . insertPanel ( name , [ ] ) ;
133- } )
134-
135- const req = await fetch ( "./layout.json" ) ;
136- let state = await req . json ( ) ;
137-
138- const layout = document . querySelector ( "regular-layout" ) ;
139- layout . restore ( state ) ;
140- save . addEventListener ( "click" , ( ) => {
141- state = layout . save ( ) ;
142- } )
143-
144- restore . addEventListener ( "click" , ( ) => {
145- if ( state ) {
146- layout . restore ( state ) ;
147- }
148- } )
149-
150- clear . addEventListener ( "click" , ( ) => {
151- layout . clear ( ) ;
152- } )
153-
154- </ script >
155- </ html >
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Regular Layout</ title >
7+ < link rel ="stylesheet " href ="./index.css ">
8+ < script type ="module " src ="./index.js "> </ script >
9+ </ head >
10+ < body >
11+ < header >
12+ < button id ="add "> Add Panel</ button >
13+ < button id ="save "> Save State</ button >
14+ < button id ="restore "> Restore State</ button >
15+ < button id ="clear "> Clear</ button >
16+ </ header >
17+ < regular-layout >
18+ < regular-layout-frame slot ="AAA "> </ regular-layout-frame >
19+ < regular-layout-frame slot ="BBB "> </ regular-layout-frame >
20+ < regular-layout-frame slot ="CCC "> </ regular-layout-frame >
21+ < regular-layout-frame slot ="DDD "> </ regular-layout-frame >
22+ < regular-layout-frame slot ="EEE "> </ regular-layout-frame >
23+ < regular-layout-frame slot ="FFF "> </ regular-layout-frame >
24+ < regular-layout-frame slot ="GGG "> </ regular-layout-frame >
25+ < regular-layout-frame slot ="HHH "> </ regular-layout-frame >
26+ </ regular-layout >
27+ </ body >
28+ </ html >
0 commit comments