jrs-react 1.2.47 → 1.2.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,9 +4,7 @@ import styled from "styled-components";
4
4
  import TitleBar from "./TitleBar";
5
5
  import Sliders from "./Slider";
6
6
  import { JRHTML } from "jrs-js";
7
- import { po, random } from "../JRUtils";
8
-
9
-
7
+ import { po } from "../JRUtils";
10
8
 
11
9
  const StyledBackdrop=styled.div`
12
10
  ${({$zIndex})=>$zIndex!=null?`z-index:${$zIndex};`:null}
@@ -58,8 +56,6 @@ const StyledJRWindow=styled.div`
58
56
  }
59
57
  `
60
58
 
61
-
62
-
63
59
  class Backdrop extends JRHTML{
64
60
  backdropConfig={
65
61
  yo:'div'
@@ -73,51 +69,108 @@ class Backdrop extends JRHTML{
73
69
  }
74
70
  }
75
71
 
76
- constructor({zIndex,fullScreen,...params}){
72
+ constructor(params){
77
73
  super(params)
78
- this.backdropConfig.style.zIndex=zIndex
79
- this.backdropConfig.personajes={
80
- id:params.backdropId
81
- }
82
74
  Object.assign(this.backdropConfig.style,params.backdropStyle)
83
75
  }
76
+
77
+
84
78
  show(){
85
- this.agregarHijo(this.backdropConfig)
79
+ this.backdrop=this.agregarHijo(this.backdropConfig)
86
80
  }
87
81
  hide(){
88
- const backdrop=document.getElementById(this.backdropId)
89
- if(backdrop){
90
- backdrop.parentNode.removeChild(backdrop);
91
- }
82
+ this.yo.removeChild(this.yo.children[this.yo.children.length-1])
92
83
  this.hijos=[]
93
84
  }
94
85
  }
95
86
 
96
-
97
-
98
- class RWindow extends React.Component {
87
+ export default class JRWindow extends JRFrame {
88
+ // x=0
89
+ // y=0
90
+ // width=300
91
+ // height=300
99
92
  padding=1
100
93
  thick=5
94
+
101
95
  constructor(props){
102
96
  super(props)
97
+ this.ref=React.createRef()
103
98
  this.titleBarRef=React.createRef()
104
99
  }
105
100
 
106
- componentDidMount(){
107
- if(this.props.open){
108
- this.props.jrWindow.backdropTarget?.show()
109
- this.props.onOpen?.bind(this.props.jrWindow)()
101
+ createBackdrop(){
102
+ if(typeof this.props.backdrop === 'string'){
103
+ const target=document.getElementById(this.props.backdrop)
104
+ if(target){
105
+ this.backdropTarget=new Backdrop({
106
+ yo:target
107
+ ,style:{
108
+ position: 'relative'
109
+ }
110
+ ,backdropStyle:this.props.backdropStyle
111
+ })
112
+ }
110
113
  }
111
114
  }
112
- componentWillUnmount(){
115
+
116
+ addMaskToTarget=(target)=>{
117
+ this.mask=document.createElement('div')
118
+ this.mask.style.background='#868686cc'
119
+ this.mask.style.position='absolute'
120
+ this.mask.style.top='0'
121
+ this.mask.style.left='0'
122
+ this.mask.style.right='0'
123
+ this.mask.style.bottom='0'
124
+ this.mask.style.borderRadius='inherit'
125
+ this.mask.style.height='10000px'
126
+ this.mask.style.width='10000px'
127
+ target.appendChild(this.mask)
128
+ }
129
+ removeMaskFromTarget=()=>{
130
+ this.mask.remove()
131
+ }
132
+
133
+ // backdropOn(on){
134
+ // const target=(typeof this.props.backdrop)==='object'
135
+ // ?this.props.backdrop
136
+ // :typeof this.props.backdrop ==='string'
137
+ // ?document.getElementById(this.props.backdrop)
138
+ // :document.body
139
+ // target?.classList[on?'add':'remove']('withMask')
140
+ // }
141
+
142
+ componentDidMount(){
143
+ super.componentDidMount()
144
+ this.createBackdrop()
113
145
  if(this.props.open){
114
- this.props.jrWindow.backdropTarget?.hide()
146
+ this.open()
115
147
  }
116
148
  }
117
149
 
150
+ open(){
151
+ this.backdropTarget?.show()
152
+ this.props.onOpen?.bind(this)()
153
+ }
154
+ close(){
155
+ this.backdropTarget?.hide()
156
+ this.props.onClose?.bind(this)()
157
+ }
158
+
159
+ componentDidUpdate(prevProps, prevState, snapshot){
160
+ if(this.props.popup===true){
161
+ if(this.props.open && prevProps.open===false){
162
+ this.open()
163
+ }else if(this.props.open===false && prevProps.open){
164
+ this.close()
165
+ }
166
+ // if(this.props.backdrop && this.props.open!=prevProps.open){
167
+ // this.backdropOn(this.props.open)
168
+ // }
169
+ }
170
+ }
118
171
 
119
172
  get xw(){
120
- let width=700
173
+ let width
121
174
  if(this.props.width?.indexOf?.('%')>-1){
122
175
  width=(this.props.width.split('%')[0]*window.innerWidth)/100
123
176
  }else{
@@ -130,7 +183,7 @@ class RWindow extends React.Component {
130
183
  }
131
184
 
132
185
  get yh(){
133
- let height=400
186
+ let height
134
187
  if(this.props.height?.indexOf?.('%')>-1){
135
188
  height=(this.props.height.split('%')[0]*window.innerHeight)/100
136
189
  }else{
@@ -142,89 +195,43 @@ class RWindow extends React.Component {
142
195
  }
143
196
  }
144
197
 
145
- render(){
146
- const {children,title,resizable,jrWindow,...props}=this.props
147
- return <StyledJRWindow
148
- $zIndex={this.props.zIndex?this.props.zIndex+1:null}
149
- className={`jr-window ${this.props.className??''}`}
150
- ref={this.props.windowRef}
151
- $xw={this.xw}
152
- $yh={this.yh}
153
- $thick={this.thick}
154
- >
155
- <main style={{zIndex:this.props.zIndex?this.props.zIndex+1:null}} >
156
- <TitleBar
157
- titleBarRef={this.titleBarRef}
158
- jrWindow={jrWindow}
159
- windowRef={this.props.windowRef}
160
- window={this}
161
- title={title}
162
- thick={this.thick}
163
- resizable={resizable}
164
- />
165
- {children}
166
- {this.props.resizable !== false
167
- && <Sliders
168
- thick={this.thick}
169
- windowRef={this.props.windowRef}
170
- window={this}
171
- titleBarRef={this.titleBarRef}
172
- />
173
- }
174
- </main>
175
- {this.props.backdrop===true && <StyledBackdrop $zIndex={this.props.zIndex}/>}
176
- </StyledJRWindow>
177
- }
178
- }
179
-
180
- export default class JRWindow extends JRFrame {
181
- constructor(props){
182
- super(props)
183
- this.windowRef=React.createRef()
184
- this.backdropId=`backdropId-${random(10000,99999)}`
185
- }
186
-
187
- componentDidMount(){
188
- super.componentDidMount()
189
- this.createBackdrop()
190
- }
191
- componentWillUnmount(){
192
- if(this.props.open){
193
- this.backdropTarget?.hide()
194
- }
195
- }
196
- componentDidUpdate(prevProps, prevState){
197
- if(prevProps.open && prevProps.open!=this.props.open){
198
- this.props.onClose?.bind(this)()
199
- }
200
- }
201
-
202
- componentWillUpdate
203
- createBackdrop(){
204
- if(typeof this.props.backdrop === 'string'){
205
- const target=document.getElementById(this.props.backdrop)
206
- if(target){
207
- this.backdropTarget=new Backdrop({
208
- yo:target
209
- ,backdropId:this.backdropId
210
- ,fullScreen:this.props.backdrop===true
211
- ,zIndex:this.props.zIndex
212
- ,backdropStyle:this.props.backdropStyle
213
- })
214
- if(this.props.open){
215
- this.backdropTarget.show()
216
- }
217
- }
218
- }
219
- }
220
-
221
198
  renderer(){
222
- const {popup,open,xzIndex=1,...props}=this.props
223
- return popup===true
224
- ?open
225
- ?<RWindow {...props} jrWindow={this} open={open} windowRef={this.windowRef}>
226
- {super.renderer()}
227
- </RWindow>
199
+ return this.props.popup===true
200
+ ?this.props.open
201
+ ?<>
202
+ <StyledJRWindow
203
+ $zIndex={this.props.zIndex}
204
+ rule={'dialog'}
205
+ ref={this.ref}
206
+ className={`jr-window ${this.props.className??''}`}
207
+ $xw={this.xw}
208
+ $yh={this.yh}
209
+ $thick={this.thick}
210
+ >
211
+ <main style={{zIndex:1}}>
212
+ <TitleBar
213
+ titleBarRef={this.titleBarRef}
214
+ windowRef={this.ref}
215
+ window={this}
216
+ title={this.props.title}
217
+ thick={this.thick}
218
+ resizable={this.props.resizable}
219
+ />
220
+ <main>
221
+ {super.renderer()}
222
+ </main>
223
+ {this.props.resizable !== false
224
+ && <Sliders
225
+ thick={this.thick}
226
+ windowRef={this.ref}
227
+ window={this}
228
+ titleBarRef={this.titleBarRef}
229
+ />
230
+ }
231
+ </main>
232
+ {this.props.backdrop!==false && typeof this.props.backdrop!=='string' && <StyledBackdrop $zIndex={this.props.zIndex}/>}
233
+ </StyledJRWindow>
234
+ </>
228
235
  :''
229
236
  :super.renderer()
230
237
  }
@@ -199,8 +199,6 @@ export default class TitleBar extends React.Component{
199
199
  window.removeEventListener('mousemove',this.preMove)
200
200
  }
201
201
  start(e){
202
- po('start',this)
203
- po('this.props.windowRef',this.props.windowRef)
204
202
  e.preventDefault()
205
203
  this.moved=false
206
204
  this.pos3 = e.clientX
@@ -228,7 +226,7 @@ export default class TitleBar extends React.Component{
228
226
  {/* <JRButton icon={<IconMinus />}/>
229
227
  <JRButton icon={<IconSquare />}/> */}
230
228
  {
231
- this.props.jrWindow.props.close
229
+ this.props.window.props.setOpen
232
230
  ?<JRButton icon={<IconX />}
233
231
  className={'danger'}
234
232
  onClick={(e)=>{
@@ -236,7 +234,7 @@ export default class TitleBar extends React.Component{
236
234
  if(this.props.window.orgBodyOverflow!=null){
237
235
  document.body.style.overflow=this.props.window.orgBodyOverflow
238
236
  }
239
- this.props.jrWindow.props.close()
237
+ this.props.window.props.setOpen(false)
240
238
  }}
241
239
  onMouseDown={(e)=>{
242
240
  e.stopPropagation()