jrs-react 1.2.19 → 1.2.21

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,146 @@
1
+ import { JRHTML } from "jrs-js"
2
+ import { useEffect, useRef } from "react"
3
+ import { po, random } from "../../components/JRUtils"
4
+ import MyFunction from "./tobeimport"
5
+ import JRMask, { showMask } from "../../components/JRMask/JRMask"
6
+ import JRFields from "../../components/JRFields/JRFields"
7
+ import JRTable from "../../components/JRTable/JRTable"
8
+ import JRSelect from "../../components/JRInput/JRSelect"
9
+
10
+
11
+
12
+ const removeFunctions={}
13
+ export default function DevApp() {
14
+ const tRef=useRef()
15
+ const fRef=useRef()
16
+ const sRef=useRef()
17
+ const no=5
18
+
19
+ useEffect(()=>{
20
+ // showMask('JRMask',null,'jr-mask')
21
+ },[])
22
+ return <div id={'dev'}>
23
+ <JRMask />
24
+
25
+ <button
26
+ onClick={()=>{
27
+ po(random())
28
+ }}
29
+ >
30
+ Random
31
+ </button>
32
+
33
+ <button
34
+ onClick={()=>{
35
+ const removeFunction=showMask('JRMask',null,'jr-mask')
36
+ removeFunction()
37
+ }}
38
+ >
39
+ JRMask
40
+ </button>
41
+
42
+ <button
43
+ onClick={()=>{
44
+ const removeFunction=showMask('Default')
45
+ removeFunction()
46
+ }}
47
+ >
48
+ Default
49
+ </button>
50
+ <br/>
51
+
52
+ <button
53
+ onClick={()=>{
54
+ setTimeout(()=>{tRef.current.get({mask:random(2000,100)})},random(4000,100))
55
+ setTimeout(()=>{fRef.current.get()},random(3000,100))
56
+ setTimeout(()=>{sRef.current.get()},random(2000,100))
57
+ }}
58
+ >
59
+ Get all
60
+ </button>
61
+ <br/>
62
+ {
63
+ Array(no).fill().map((f,a,i)=>{
64
+ return <button
65
+ key={a}
66
+ onClick={()=>{
67
+ removeFunctions[a]=showMask(`message ${a}`,null,'jr-mask')
68
+
69
+ }}
70
+ >
71
+ Add {a}
72
+ </button>
73
+ })
74
+ }
75
+ <br/>
76
+ {
77
+ Array(no).fill().map((f,a,i)=>{
78
+ return <button
79
+ key={a}
80
+ onClick={()=>{
81
+ removeFunctions[a]?.()
82
+ }}
83
+ >
84
+ del {a}
85
+ </button>
86
+ })
87
+ }
88
+ <JRFields
89
+ ref={fRef}
90
+ get={{
91
+ url:'data.json'
92
+ // ,autoRun:true
93
+ ,mask:'JRFields loading'
94
+ }}
95
+ columns={[
96
+ {name:'name'}
97
+ ]}
98
+ left={function(){
99
+ return <div>
100
+ <button
101
+ onClick={()=>{
102
+ this.get({
103
+ mask:'Field is loading'
104
+ })
105
+ }}
106
+ >Get</button>
107
+ </div>
108
+ }}
109
+ />
110
+ <JRTable
111
+ ref={tRef}
112
+ get={{
113
+ url:'list.json'
114
+ // ,autoRun:true
115
+ ,mask:'JRTable loading'
116
+ }}
117
+ style={{
118
+ height:'50px'
119
+ }}
120
+ columns={[
121
+ {name:'name'}
122
+ ]}
123
+ left={function(){
124
+ return <div>
125
+ <button
126
+ onClick={()=>{
127
+ this.get({
128
+ mask:'Table is loading'
129
+ })
130
+ }}
131
+ >Get</button>
132
+ </div>
133
+ }}
134
+ />
135
+ <JRSelect
136
+ ref={sRef}
137
+ get={{
138
+ url:'list.json'
139
+ ,autoRun:true
140
+ ,mask:'JRSelect is loading'
141
+ }}
142
+ labelName={'name'}
143
+ valueName={'id'}
144
+ />
145
+ </div>
146
+ }
@@ -0,0 +1,7 @@
1
+ import { po } from "../../components/JRUtils"
2
+
3
+ export default function MyFunction(){
4
+ return 'MyFunction'
5
+ }
6
+
7
+ po('import -----------------')
@@ -1,8 +1,48 @@
1
- import React, { useEffect } from "react"
2
-
1
+ import React, { useEffect, useRef, useState } from "react"
2
+ import { po } from "../../components/JRUtils"
3
+ import JRFields from "../../components/JRFields/JRFields"
4
+ import JRFrame from "../../components/JRFrame/JRFrame"
5
+ import styled from "styled-components"
3
6
 
7
+ const StyledDialog=styled.dialog`
8
+ `
9
+ class JRDialog extends JRFrame {
10
+ renderer(){
11
+ return <StyledDialog open>
12
+ Dialog
13
+ {super.renderer()}
14
+ </StyledDialog>
15
+ }
16
+ }
4
17
  export default function TestApp(){
18
+ const ref=useRef()
19
+ const [open,setOpen]=useState(false)
5
20
  useEffect(()=>{
6
- },[])
7
- return <div>Test</div>
21
+ if(open){
22
+ po('open',open)
23
+ ref.current.showModal()
24
+ }else{
25
+ po('close',open)
26
+ ref.current.close()
27
+ }
28
+ },[open])
29
+ return <div>
30
+ isOpen={open+''}
31
+ <button onClick={()=>{
32
+ // ref.current.showModal();
33
+ po(true)
34
+ setOpen(true)
35
+ }}>open dialog</button>
36
+
37
+ <StyledDialog id="dialog" ref={ref} >
38
+ <JRFields/>
39
+ <p>I'm a dialog.</p>
40
+ <button
41
+ onClick={()=>{
42
+ // ref.current.close();
43
+ setOpen(false)
44
+ }}
45
+ >Close</button>
46
+ </StyledDialog>
47
+ </div>
8
48
  }
@@ -0,0 +1,205 @@
1
+ import React from "react"
2
+ import { JRHTML } from "jrs-js"
3
+ import { po } from "../JRUtils"
4
+ import styled from "styled-components"
5
+
6
+ const StyledMask = styled.dialog`
7
+ display:none;
8
+ &:open{
9
+ display:flex;
10
+ }
11
+
12
+ &:modal {
13
+ outline: 0;
14
+ background: #000c6e77;
15
+ }
16
+
17
+ #jr-mask-msg{
18
+ padding: 10px;
19
+ }
20
+
21
+ max-width: 100vw;
22
+ max-height: 100vh;
23
+
24
+ width: 100vw;
25
+ height: 100vh;
26
+
27
+ border:0;
28
+ margin: 0;
29
+ top: 0;
30
+ left: 0;
31
+
32
+ user-select: none;
33
+ cursor: wait;
34
+ flex-direction: column;
35
+ justify-content: center;
36
+ align-items: center;
37
+ position: fixed;
38
+
39
+ z-index: 20000;
40
+ overflow: hidden;
41
+
42
+ .cs-loader-inner {
43
+ transform: translateY(-30%);
44
+ width: calc(100% - 200xpx);
45
+ }
46
+
47
+ .cs-loader-inner label {
48
+ font-size: 20px;
49
+ opacity: 0;
50
+ display:inline-block;
51
+ color:white;
52
+ }
53
+
54
+ @keyframes lol {
55
+ 0% {
56
+ opacity: 0;
57
+ transform: translateX(-300px);
58
+ }
59
+ 33% {
60
+ opacity: 1;
61
+ transform: translateX(0px);
62
+ }
63
+ 66% {
64
+ opacity: 1;
65
+ transform: translateX(0px);
66
+ }
67
+ 100% {
68
+ opacity: 0;
69
+ transform: translateX(300px);
70
+ }
71
+ }
72
+
73
+ @-webkit-keyframes lol {
74
+ 0% {
75
+ opacity: 0;
76
+ -webkit-transform: translateX(-300px);
77
+ }
78
+ 33% {
79
+ opacity: 1;
80
+ -webkit-transform: translateX(0px);
81
+ }
82
+ 66% {
83
+ opacity: 1;
84
+ -webkit-transform: translateX(0px);
85
+ }
86
+ 100% {
87
+ opacity: 0;
88
+ -webkit-transform: translateX(300px);
89
+ }
90
+ }
91
+
92
+ .cs-loader-inner label:nth-child(6) {
93
+ -webkit-animation: lol 3s infinite ease-in-out;
94
+ animation: lol 3s infinite ease-in-out;
95
+ }
96
+
97
+ .cs-loader-inner label:nth-child(5) {
98
+ -webkit-animation: lol 3s 100ms infinite ease-in-out;
99
+ animation: lol 3s 100ms infinite ease-in-out;
100
+ }
101
+
102
+ .cs-loader-inner label:nth-child(4) {
103
+ -webkit-animation: lol 3s 200ms infinite ease-in-out;
104
+ animation: lol 3s 200ms infinite ease-in-out;
105
+ }
106
+
107
+ .cs-loader-inner label:nth-child(3) {
108
+ -webkit-animation: lol 3s 300ms infinite ease-in-out;
109
+ animation: lol 3s 300ms infinite ease-in-out;
110
+ }
111
+
112
+ .cs-loader-inner label:nth-child(2) {
113
+ -webkit-animation: lol 3s 400ms infinite ease-in-out;
114
+ animation: lol 3s 400ms infinite ease-in-out;
115
+ }
116
+
117
+ .cs-loader-inner label:nth-child(1) {
118
+ -webkit-animation: lol 3s 500ms infinite ease-in-out;
119
+ animation: lol 3s 500ms infinite ease-in-out;
120
+ }
121
+ `
122
+
123
+ export default function JRMask({id='jr-mask'}){
124
+ return <StyledMask id={id} className={'jr-mask'}>
125
+ <div id={'jr-mask-msg'} ></div>
126
+ <div className="cs-loader-inner">
127
+ <label>●</label>
128
+ <label>●</label>
129
+ <label>●</label>
130
+ <label>●</label>
131
+ <label>●</label>
132
+ <label>●</label>
133
+ </div>
134
+ </StyledMask>
135
+ }
136
+
137
+
138
+
139
+
140
+ class Mask extends JRHTML{
141
+ msg=[]
142
+ #msgIndex=0
143
+ #mask
144
+ get msgIndex(){
145
+ return this.#msgIndex++
146
+ }
147
+
148
+ addMsg(msg){
149
+ const index=this.msgIndex
150
+ this.msg.push({
151
+ i:index
152
+ ,msg
153
+ })
154
+ this.renderMsg()
155
+ return ()=>{
156
+ po('remove function', index)
157
+ this.removeMsg(index)
158
+ }
159
+ }
160
+ removeMsg(index){
161
+ this.msg=this.msg.filter(r=>r.i!=index)
162
+ this.renderMsg()
163
+ }
164
+ renderMsg(){
165
+ this.msgDiv.removeAllHijos()
166
+ if(this.msg.length){
167
+ this.msgDiv.agregarHijo(
168
+ new JRHTML({
169
+ yo:'div'
170
+ ,textContent:this.msg[this.msg.length-1].msg
171
+ })
172
+ )
173
+ if(!this.yo.open){
174
+ this.yo.showModal()
175
+ }
176
+ }else{
177
+ this.yo.close()
178
+ }
179
+ }
180
+ get msg(){
181
+ return 'msg'
182
+ }
183
+ }
184
+
185
+ export function showMask(msg,maskTarget,whichMask){
186
+ const jrMask=document.getElementById('jr-mask')
187
+ const jrMaskMsg=document.getElementById('jr-mask-msg')
188
+
189
+ if(!jrMask.maskDiv){
190
+ jrMask.maskDiv=new Mask({
191
+ yo:jrMask
192
+ ,msgDiv:new JRHTML({
193
+ yo:jrMaskMsg
194
+ })
195
+ ,listeners:{
196
+ keydown(e){
197
+ if (e.key === 'Escape') {
198
+ e.preventDefault();
199
+ }
200
+ }
201
+ }
202
+ })
203
+ }
204
+ return jrMask.maskDiv.addMsg(msg)
205
+ }
@@ -1,8 +1,8 @@
1
1
  import React from 'react'
2
2
  import axios from 'axios'
3
- import { colonValueString, flexType, po } from './JRUtils'
4
- import { displaySpinner } from './LoadingBar'
3
+ import { colonValueString, flexType, po, random } from './JRUtils'
5
4
  import styled from 'styled-components'
5
+ import { showMask } from './JRMask/JRMask'
6
6
 
7
7
  const axiosSubmit = axios.create({
8
8
  authorization: `Bearer ${localStorage.getItem("accessToken")}`
@@ -218,9 +218,11 @@ export default class JRSubmit extends React.Component {
218
218
  }
219
219
 
220
220
  submit(config){
221
- const me=this
222
- displaySpinner({mask:config.mask})
223
- this.setState({loading:true})
221
+ // const me=this
222
+ // displaySpinner({mask:config.mask})
223
+ // this.setState({loading:true})//拿掉可能會有問題, 先觀察看看
224
+ if(config.mask) config.removeMaskFunction=showMask(config.mask,null,'jr-mask')
225
+
224
226
  let _payload
225
227
  ;(()=>{
226
228
  if (Array.isArray(config.url)) {
@@ -248,9 +250,12 @@ export default class JRSubmit extends React.Component {
248
250
  .catch((res)=>{
249
251
  this.handleResponse(res,_payload,config)
250
252
  })
251
- .finally(function (a,b,c) {
252
- me.setState({loading:false})
253
- displaySpinner({mask:false})
253
+ .finally(()=> {
254
+ // this.setState({loading:false})
255
+ // displaySpinner({mask:false})
256
+ // setTimeout(()=>{
257
+ config.removeMaskFunction?.()
258
+ // },random(4000,1000))
254
259
  })
255
260
  }
256
261
 
@@ -76,4 +76,8 @@ export const whatType=(
76
76
  return doElse
77
77
  }
78
78
  return 'what type'
79
+ }
80
+
81
+ export function random(max=100, min=0){
82
+ return Math.floor(Math.random() * (max+1-min)) + min;
79
83
  }
@@ -107,7 +107,6 @@ export default class TitleBar extends React.Component{
107
107
  }
108
108
  }
109
109
  floatScreen=(e)=>{
110
- po('floatScreen')
111
110
  const w=this.props.windowRef.current
112
111
  const {clientX,clientY}=e
113
112
 
@@ -119,8 +118,6 @@ export default class TitleBar extends React.Component{
119
118
  document.body.style.overflow=this.props.window.orgBodyOverflow
120
119
  }
121
120
  fullScreen=(e)=>{
122
- po('fullScreen',this.props.thick)
123
-
124
121
  this.props.windowRef.current.style.transition='var(--transition-x-y), left .05s ease-in'
125
122
  this.props.windowRef.current.style.left=`${-this.props.thick}px`
126
123
  this.props.windowRef.current.style.top=`${-this.props.thick}px`
@@ -134,7 +131,6 @@ export default class TitleBar extends React.Component{
134
131
 
135
132
  }
136
133
  stop=(e)=>{
137
- po('stop')
138
134
  e.preventDefault()
139
135
  if(this.moved){
140
136
  const {clientX,clientY}=e
@@ -155,7 +151,6 @@ export default class TitleBar extends React.Component{
155
151
 
156
152
  }
157
153
  move=(e)=>{
158
- po('move')
159
154
  e.preventDefault()
160
155
  this.moved=true
161
156
  const {clientX,clientY}=e
@@ -169,32 +164,18 @@ export default class TitleBar extends React.Component{
169
164
  this.y=w.offsetTop - this.pos2
170
165
  this.x=w.offsetLeft - this.pos1
171
166
 
172
- // if(this.props.window.orgWidth){
173
- // w.style.width=`${this.props.window.orgWidth}px`
174
- // this.props.window.orgWidth=null
175
- // }
176
-
177
167
  this.y=this.y<-this.props.thick?-this.props.thick:this.y
178
168
  w.style.transition='unset'
179
169
  w.style.top = `${this.y}px`
180
170
  w.style.left = `${this.x}px`
181
171
  }
182
172
  preMove=(e)=>{
183
- console.clear()
184
- po('preMove')
185
-
186
173
  const w=this.props.windowRef.current
187
174
  const {clientX,clientY,...oe}=e
188
- po('e',e)
189
175
 
190
176
  const {x,y,width,height}=w.getBoundingClientRect()
191
- po('width',width)
192
177
 
193
- if(y<=-this.props.thick){
194
-
195
-
196
- }
197
- w.style.transition='left .05s ease-in, height .05s ease-in'
178
+ w.style.transition='left .05s ease-in, height .05s ease-in'
198
179
  if(y<=0){
199
180
  // contt browserWidth=
200
181
  const w1=window.innerWidth-(this.props.thick*2)
@@ -220,7 +201,6 @@ w.style.transition='left .05s ease-in, height .05s ease-in'
220
201
  window.removeEventListener('mousemove',this.preMove)
221
202
  }
222
203
  start(e){
223
- po('start')
224
204
  e.preventDefault()
225
205
  this.moved=false
226
206
  this.pos3 = e.clientX
package/src/index.js CHANGED
@@ -10,11 +10,14 @@ import JRSelect from './components/JRInput/JRSelect'
10
10
  import JRCheckbox from './components/JRInput/JRCheckbox'
11
11
  import JRRadio from './components/JRInput/JRRadio'
12
12
  import JRText from './components/JRInput/JRText'
13
-
13
+ import JRMask,{showMask} from './components/JRMask/JRMask'
14
+ import {random} from './components/JRUtils'
14
15
  export {
15
16
  JRTestReact
16
17
  ,JRSubmit,JRFrame,JRWindow,JRTable,JRFields,JRAlert
17
18
  ,JRButton
18
19
  ,JRText,JRSelect,JRCheckbox,JRRadio
20
+ ,JRMask,showMask
21
+ ,random
19
22
 
20
23
  }