jrs-react 1.2.4 → 1.2.6

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.
@@ -0,0 +1,251 @@
1
+ import React from "react"
2
+ import styled from "styled-components"
3
+ import { po } from "../JRUtils"
4
+
5
+ const borderWidth='px'
6
+
7
+ const StyledSlider=styled.div`
8
+ Xborder:1px solid ${({$direction:{color}})=>color};
9
+ xbackground:${({$direction:{color}})=>color};
10
+ position: absolute;
11
+ top: ${({$direction:{top}})=>top};
12
+ bottom: ${({$direction:{bottom}})=>bottom};
13
+ right: ${({$direction:{right}})=>right};
14
+ left: ${({$direction:{left}})=>left};
15
+ height: ${({$direction:{height}})=>height};
16
+ width: ${({$direction:{width}})=>width};
17
+ cursor: ${({$direction:{cursor}})=>cursor};
18
+
19
+ -webkit-user-select: none;
20
+ -khtml-user-select: none;
21
+ -moz-user-select: none;
22
+ -o-user-select: none;
23
+ user-select: none;
24
+
25
+ `
26
+ export default class Slider extends React.Component {
27
+ width='3px'
28
+ borderWidth='px'
29
+ borderLong='10px'
30
+
31
+ constructor(props){
32
+ super(props);
33
+ this.sliderRef=React.createRef()
34
+ }
35
+ directions={
36
+ n:{
37
+ top:0
38
+ ,color:'red'
39
+ ,width:'100%'
40
+ ,height:`${this.props.thick}px`
41
+ ,cursor: 'n-resize'
42
+ ,resize:(props)=>{
43
+ this.resizeN(props)
44
+ }
45
+
46
+ }
47
+ ,e:{
48
+ color:'yellow'
49
+ ,right:0
50
+ ,width:`${this.props.thick}px`
51
+ ,height:'100%'
52
+ ,cursor: 'e-resize'
53
+ ,resize:(props)=>{
54
+ this.resizeE(props)
55
+ }
56
+ }
57
+ ,s:{
58
+ color:'blue'
59
+ ,bottom:0
60
+ ,width:'100%'
61
+ ,height:`${this.props.thick}px`
62
+ ,cursor: 's-resize'
63
+ ,resize:(props)=>{
64
+ this.resizeS(props)
65
+ }
66
+ }
67
+ ,w:{
68
+ color:'green'
69
+ ,left:0
70
+ ,width:`${this.props.thick}px`
71
+ ,height:'100%'
72
+ ,cursor: 'w-resize'
73
+ ,resize:(props)=>{
74
+ this.resizeW(props)
75
+ }
76
+ }
77
+ ,nww:{
78
+ top:0
79
+ ,left:0
80
+ ,color:'blue'
81
+ ,width:`${this.props.thick}px`
82
+ ,height:this.borderLong
83
+ ,cursor: 'nw-resize'
84
+ ,resize:(props)=>{
85
+ this.resizeN(props)
86
+ this.resizeW(props)
87
+ }
88
+ }
89
+ ,nnw:{
90
+ top:0
91
+ ,left:0
92
+ ,color:'blue'
93
+ ,width:this.borderLong
94
+ ,height:`${this.props.thick}px`
95
+ ,cursor: 'nw-resize'
96
+ ,resize:(props)=>{
97
+ this.resizeN(props)
98
+ this.resizeW(props)
99
+ }
100
+ }
101
+ ,nne:{
102
+ top:0
103
+ ,right:0
104
+ ,color:'green'
105
+ ,width:this.borderLong
106
+ ,height:`${this.props.thick}px`
107
+ ,cursor: 'ne-resize'
108
+ ,resize:(props)=>{
109
+ this.resizeN(props)
110
+ this.resizeE(props)
111
+ }
112
+ }
113
+ ,nee:{
114
+ top:0
115
+ ,right:0
116
+ ,color:'green'
117
+ ,width:`${this.props.thick}px`
118
+ ,height:this.borderLong
119
+ ,cursor: 'ne-resize'
120
+ ,resize:(props)=>{
121
+ this.resizeN(props)
122
+ this.resizeE(props)
123
+ }
124
+ }
125
+ ,sse:{
126
+ color:'red'
127
+ ,right:0
128
+ ,bottom:0
129
+ ,width:this.borderLong
130
+ ,height:`${this.props.thick}px`
131
+ ,cursor: 'se-resize'
132
+ ,resize:(props)=>{
133
+ this.resizeS(props)
134
+ this.resizeE(props)
135
+ }
136
+ }
137
+ ,see:{
138
+ color:'red'
139
+ ,right:0
140
+ ,bottom:0
141
+ ,width:`${this.props.thick}px`
142
+ ,height:this.borderLong
143
+ ,cursor: 'se-resize'
144
+ ,resize:(props)=>{
145
+ this.resizeS(props)
146
+ this.resizeE(props)
147
+ }
148
+ }
149
+ ,ssw:{
150
+ color:'yellow'
151
+ ,bottom:0
152
+ ,left:0
153
+ ,width:this.borderLong
154
+ ,height:`${this.props.thick}px`
155
+ ,cursor: 'sw-resize'
156
+ ,resize:(props)=>{
157
+ this.resizeS(props)
158
+ this.resizeW(props)
159
+ }
160
+ }
161
+ ,sww:{
162
+ color:'yellow'
163
+ ,bottom:0
164
+ ,left:0
165
+ ,width:`${this.props.thick}px`
166
+ ,height:this.borderLong
167
+ ,cursor: 'sw-resize'
168
+ ,resize:(props)=>{
169
+ this.resizeS(props)
170
+ this.resizeW(props)
171
+ }
172
+ }
173
+ }
174
+
175
+ stop=(e)=>{
176
+ document.body.style.cursor='default'
177
+ window.removeEventListener('mousemove',this.move)
178
+ window.removeEventListener('mouseup',this.stop)
179
+ }
180
+
181
+ resizeN=({window,cursorY,startY,startHeight,titleBarHeight})=>{
182
+ let y=cursorY-(this.props.thick)
183
+ if(y<0)y=0
184
+ let height=startHeight+(startY-y)
185
+ if(height<titleBarHeight+(this.props.thick*2)){
186
+ height=titleBarHeight+(this.props.thick*2)
187
+ y=startY + startHeight - titleBarHeight - (this.props.thick*2)
188
+ }
189
+ window.style.top=`${y}px`
190
+ window.style.height=`${height}px`
191
+
192
+ }
193
+ resizeE=({window,clientX,left,titleBarHeight})=>{
194
+ let width=clientX-left-this.props.thick
195
+ if(width<titleBarHeight)width=titleBarHeight
196
+ window.style.width=`${width+(this.props.thick*2)}px`
197
+ }
198
+ resizeS=({window,clientY,top,titleBarHeight})=>{
199
+ let height=clientY-top-this.props.thick
200
+ if(height<titleBarHeight)height=titleBarHeight
201
+ window.style.height=`${height+(this.props.thick*2)}px`
202
+ }
203
+ resizeW=({window,cursorX,startX,startWidth,titleBarHeight})=>{
204
+ let x=cursorX
205
+ if(x<=1)x=1
206
+ let width=startWidth+(startX-x)
207
+ if(width<titleBarHeight+ (this.props.thick*2)){
208
+ width=titleBarHeight+ (this.props.thick*2)
209
+ x=startX+startWidth -titleBarHeight - (this.props.thick*2)
210
+ }
211
+ window.style.left=`${x}px`
212
+ window.style.width=`${width}px`
213
+ }
214
+ move=(e)=>{
215
+ const {clientX,clientY,x:cursorX,y:cursorY}=e
216
+ const window=this.props.windowRef.current
217
+ const {left,top}=window.getBoundingClientRect()
218
+ const {x:startX,width:startWidth,y:startY,height:startHeight,titleBarHeight}=this.data
219
+
220
+ this.directions[this.props.direction].resize({
221
+ window,titleBarHeight
222
+ ,clientX,cursorX,startX,startWidth,left
223
+ ,clientY,cursorY,startY,startHeight,top
224
+ })
225
+ /////////////////////////////////////////////////////////////
226
+
227
+
228
+
229
+
230
+ /////////////////////////////////////////////////////////////
231
+
232
+
233
+
234
+ }
235
+ start=()=>{
236
+ const {height:titleBarHeight}=this.props.titleBarRef.current.getBoundingClientRect()
237
+ const {x,y,width,height}=this.props.windowRef.current.getBoundingClientRect()
238
+ this.data={x,y,width,height,titleBarHeight}
239
+ document.body.style.cursor=this.directions[this.props.direction].cursor
240
+ window.addEventListener('mousemove',this.move)
241
+ window.addEventListener('mouseup',this.stop)
242
+ }
243
+
244
+ render(){
245
+ return <StyledSlider
246
+ $direction={this.directions[this.props.direction]}
247
+ $padding={this.props.padding}
248
+ onMouseDown={this.start}
249
+ />
250
+ }
251
+ }
@@ -0,0 +1,84 @@
1
+ import styled from "styled-components";
2
+ import { po } from "../JRUtils";
3
+ import React from "react";
4
+ import { FreeType } from "../JRFrame/JRFrame";
5
+
6
+ const StyledTitle=styled.div`
7
+ overflow: hidden;
8
+ display: flex;
9
+ padding:2px 8px;
10
+ border:1px solid black;
11
+ background:rgb(214, 214, 214);
12
+ color: black;
13
+ &:active:hover{
14
+ cursor: grabbing;
15
+ }
16
+
17
+ -webkit-user-select: none;
18
+ -khtml-user-select: none;
19
+ -moz-user-select: none;
20
+ -o-user-select: none;
21
+ user-select: none;
22
+
23
+ > .title{
24
+ flex: 1;
25
+ }
26
+ `
27
+
28
+
29
+
30
+
31
+ export default class TitleBar extends React.Component{
32
+ pos1 = 0
33
+ pos2 = 0
34
+ pos3 = 0
35
+ pos4 = 0
36
+ x=0
37
+ y=0
38
+
39
+ move=(e)=>{
40
+ e.preventDefault()
41
+ const {clientX,clientY}=e
42
+ this.pos1 = this.pos3 - e.clientX
43
+ this.pos2 = this.pos4 - e.clientY
44
+ this.pos3 = e.clientX
45
+ this.pos4 = e.clientY
46
+
47
+ const w= this.props.windowRef.current
48
+ this.x=w.offsetLeft - this.pos1
49
+ this.y=w.offsetTop - this.pos2
50
+ w.style.top = this.y + 'px'
51
+ w.style.left = this.x + 'px'
52
+ }
53
+ stop=(e)=>{
54
+ // const w= this.props.windowRef.current
55
+ // if(this.y<1)this.props.windowRef.current.style.top = '1px'
56
+ // if(this.y>window.innerHeight)this.props.windowRef.current.style.top = `${window.innerHeight-32}px`
57
+ // if(this.x<1)this.props.windowRef.current.style.left = '1px'
58
+ // if(this.x>window.innerWidth)this.props.windowRef.current.style.left = `${window.innerWidth-100}px`
59
+ document.body.style.cursor='default'
60
+ window.removeEventListener('mousemove',this.move)
61
+ window.removeEventListener('mouseup',this.stop)
62
+ }
63
+ start(e){
64
+ e.preventDefault()
65
+ this.pos3 = e.clientX
66
+ this.pos4 = e.clientY
67
+
68
+ document.body.style.cursor='grabbing'
69
+ window.addEventListener('mousemove',this.move)
70
+ window.addEventListener('mouseup',this.stop)
71
+ }
72
+ render(){
73
+ return <StyledTitle
74
+ ref={this.props.titleBarRef}
75
+ draggable="false"
76
+ onMouseDown={(e)=>{
77
+ this.start(e)
78
+ }}
79
+ >
80
+ <FreeType tag='div' config={this.props.title??''} me={this.props.window} className={'title'}/>
81
+ <nav><button>X</button></nav>
82
+ </StyledTitle>
83
+ }
84
+ }
package/src/main.jsx ADDED
@@ -0,0 +1,6 @@
1
+ import { StrictMode } from 'react'
2
+ import { createRoot } from 'react-dom/client'
3
+ import './app/index.css'
4
+ import App from './app/App.jsx'
5
+
6
+ createRoot(document.getElementById('root')).render(<App/>)
package/vite.config.js ADDED
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from 'vite'
2
+ import react from '@vitejs/plugin-react'
3
+
4
+ // https://vite.dev/config/
5
+ export default defineConfig({
6
+ plugins: [react()],
7
+ })