@thestarweb/ui 1.6.0 → 1.6.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thestarweb/ui",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "A UI lib",
5
5
  "scripts": {
6
6
  "build": "vue-cli-service build --target lib --name star-ui --dest dist/ src/main.ts",
@@ -27,8 +27,8 @@ export default class SuButton extends Vue {
27
27
  <style>
28
28
  .star-ui-button{
29
29
  border-width: 1px;
30
- }
31
- .star-ui-button.star-ui-size-mini{
32
- border-radius:2px;
30
+ cursor: pointer;
31
+ background: var(--star-ui-backgorund-color);
32
+ color: var(--star-ui-font-color);
33
33
  }
34
34
  </style>
@@ -1,6 +1,6 @@
1
1
  <template>
2
- <teleport :to="'#'+id">
3
- <div>
2
+ <teleport to="body">
3
+ <div ref="root" :class="['star-ui-base-popper', ...ctrlClass]" :style="{visibility: visible ? '' : 'hidden', ...baseStyle, ...style}">
4
4
  <div class="star-ui-popper-background" v-if="isMobile" @click="$emit('out-click')"></div>
5
5
  <slot></slot>
6
6
  </div>
@@ -38,11 +38,18 @@ let nowId=0;
38
38
  watch:{
39
39
  visible(){
40
40
  this._updateVisible();
41
+ },
42
+ isMobile(){
43
+ if(this.syncRequestId)cancelAnimationFrame(this.syncRequestId);
44
+ this.updatePos();
41
45
  }
42
46
  },
43
47
  // inject: ['$suControl']
44
48
  })
45
49
  export default class SuButton extends Vue {
50
+ declare $refs: {
51
+ root:HTMLDivElement;
52
+ };
46
53
  @Prop({
47
54
  type:Object
48
55
  })
@@ -52,16 +59,6 @@ export default class SuButton extends Vue {
52
59
  private updateType!:string;
53
60
  private visible!:boolean;
54
61
  @SuViewCtrlInjectIsMobile readonly isMobile!:false;
55
- beforeCreate():void{
56
- this.div=document.createElement("div");
57
- document.body.append(this.div);
58
- this.id="star-ui-popper-"+nowId++;
59
- this.div.id=this.id;
60
- this.div.style.position="fixed";
61
- }
62
- unmounted():void{
63
- document.body.removeChild(this.div);
64
- }
65
62
  mounted():void{
66
63
  window.addEventListener("click",this._clickCheck);
67
64
  this._updateVisible();
@@ -73,7 +70,7 @@ export default class SuButton extends Vue {
73
70
  _clickCheck(ev:MouseEvent):boolean{
74
71
  var dom=ev.target;
75
72
  while(dom&&dom!=document){
76
- if(dom==this.div||(this.fromItem&&dom==((this.fromItem instanceof HTMLElement)?this.fromItem:this.fromItem.$el))){
73
+ if(dom==this.$refs.root||(this.fromItem&&dom==((this.fromItem instanceof HTMLElement)?this.fromItem:this.fromItem.$el))){
77
74
  return false;
78
75
  }
79
76
  dom=(dom as HTMLElement).parentElement;
@@ -83,26 +80,24 @@ export default class SuButton extends Vue {
83
80
  private syncRequestId!:number;
84
81
  _updateVisible():void{
85
82
  if(this.visible){
86
- this.div.style.display="";
87
83
  this.updatePos();
88
84
  }else{
89
- this.div.style.display="none";
90
85
  if(this.syncRequestId)cancelAnimationFrame(this.syncRequestId);
91
86
  }
92
87
  }
93
88
  @SuViewCtrlInjectClassName
94
89
  readonly ctrlClass!:string[];
90
+ // eslint-disable-next-line
91
+ private baseStyle:Record<string, any>={};
95
92
  updatePos():void{
96
93
  if(this.fromItem){
94
+ this.baseStyle={};
97
95
  let dom=(this.fromItem instanceof HTMLElement)?this.fromItem:this.fromItem.$el;
98
96
  if(this.isMobile){
99
- this.div.style.bottom="0";
100
- this.div.style.left="0";
101
- this.div.style.width="100%";
102
- // this.div.style.height="100%";
103
- this.div.className=this.ctrlClass.join(' ');
97
+ this.baseStyle.bottom="0";
98
+ this.baseStyle.left="0";
99
+ this.baseStyle.width="100%";
104
100
  }else{
105
- this.div.className=this.ctrlClass.join(' ');
106
101
  const height=dom.clientHeight;
107
102
  let top=0,left=0;
108
103
  while(dom&&dom!=document){
@@ -111,8 +106,8 @@ export default class SuButton extends Vue {
111
106
  dom=dom.offsetParent;
112
107
  }
113
108
  top+=height;
114
- this.div.style.top=top+"px";
115
- this.div.style.left=left+"px";
109
+ this.baseStyle.top=top+"px";
110
+ this.baseStyle.left=left+"px";
116
111
  if(this.updateType=="v-sync"){
117
112
  this.syncRequestId=requestAnimationFrame(this.updatePos);
118
113
  }
@@ -123,6 +118,9 @@ export default class SuButton extends Vue {
123
118
  </script>
124
119
 
125
120
  <style>
121
+ .star-ui-base-popper{
122
+ position: fixed;
123
+ }
126
124
  .star-ui-popper-background{
127
125
  position: fixed;
128
126
  width: 100%;
@@ -129,5 +129,6 @@ export default class SuMain extends Vue {
129
129
  }
130
130
  .su-page--main{
131
131
  overflow: auto;
132
+ flex: 1;
132
133
  }
133
134
  </style>
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div :class="`star-ui su-form-item star-ui-form-item star-ui-col-${col} star-ui-form--label-align-${labelAlign||pLabelAlign}`">
3
- <div class="start-ui star-ui-container star-ui-form-item--label" :style="labelStyle">
3
+ <div ref="labelDiv" class="start-ui star-ui-container star-ui-form-item--label" :style="labelStyle">
4
4
  {{label}}
5
5
  <slot name="label"></slot>
6
6
  </div>
@@ -15,17 +15,27 @@ import { Vue } from "vue-class-component";
15
15
  import { Inject } from "vue-property-decorator";
16
16
  import { Register, Prop } from "@ui-root/reg";
17
17
  import { TypeFormLabelAlign } from "@ui-root/outher";
18
+ import { Bus } from "./form.vue";
18
19
 
19
20
  import "@ui-root/global-style.css";
20
21
 
21
22
  export const InjectLabelWidth = Symbol('InjectLabelWidth');
22
23
  export const InjectLabelAlign = Symbol('InjectLabelAlign');
24
+ export const InjectEventBus = Symbol('InjectEventBus');
23
25
 
24
26
  @Register({
25
27
  name:"su-form-item",
26
28
  hideInDoc:true,
29
+ watch:{
30
+ label(this:SuButton){
31
+ this.bus&&this.bus.labelUpdate(this);
32
+ }
33
+ }
27
34
  })
28
35
  export default class SuButton extends Vue {
36
+ declare $refs: {
37
+ labelDiv: HTMLDivElement
38
+ };
29
39
  @Prop({
30
40
  type:String,
31
41
  default:()=>{
@@ -37,7 +47,7 @@ export default class SuButton extends Vue {
37
47
  type:[String, Number],
38
48
  })
39
49
  readonly labelWidth!:string|number|undefined;
40
- @Inject({from:InjectLabelWidth})
50
+ @Inject({from:InjectLabelWidth,default:undefined})
41
51
  readonly pLabelWidth!:string|number|undefined;
42
52
  @Prop({
43
53
  autoType: "FormLabelAlign",
@@ -60,8 +70,18 @@ export default class SuButton extends Vue {
60
70
  }
61
71
  return ret;
62
72
  }
73
+ @Inject({from:InjectEventBus})
74
+ readonly bus!:Bus|undefined;
63
75
  created(){
64
- console.log(this.col);
76
+ if(this.bus){
77
+ this.bus.addItem(this);
78
+ }
79
+ debugger
80
+ }
81
+ beforeUnmount(){
82
+ if(this.bus){
83
+ this.bus.removeItem(this);
84
+ }
65
85
  }
66
86
  }
67
87
  </script>
@@ -75,6 +95,7 @@ export default class SuButton extends Vue {
75
95
  }
76
96
  .star-ui-form-item--label{
77
97
  overflow: hidden;
98
+ box-sizing: border-box;
78
99
  }
79
100
  .star-ui-form-item--content{
80
101
  flex: 1;
@@ -8,13 +8,19 @@
8
8
  import { Vue } from "vue-class-component";
9
9
  import { Register, Prop } from "@ui-root/reg";
10
10
  import type { TypeFormLabelAlign } from "@ui-root/outher";
11
+ import { Provide } from "vue-property-decorator";
12
+ import Item, { InjectEventBus, InjectLabelAlign, InjectLabelWidth } from "./form-item.vue";
11
13
 
12
14
  import "@ui-root/global-style.css";
13
- import { Provide } from "vue-property-decorator";
14
- import { InjectLabelAlign, InjectLabelWidth } from "./form-item.vue";
15
+
16
+ export interface Bus{
17
+ addItem:(item:Item)=>void,
18
+ removeItem:(item:Item)=>void,
19
+ labelUpdate:(item:Item)=>void,
20
+ }
15
21
 
16
22
  @Register({
17
- name:"su-form"
23
+ name:"su-form",
18
24
  })
19
25
  export default class SuButton extends Vue {
20
26
  @Prop({
@@ -23,12 +29,11 @@ export default class SuButton extends Vue {
23
29
  return "right"
24
30
  }
25
31
  })
26
- @Provide({to:InjectLabelAlign})
32
+ @Provide({to:InjectLabelAlign,reactive:true})
27
33
  readonly labelAlign!:TypeFormLabelAlign;
28
34
  @Prop({
29
35
  type: Number
30
36
  })
31
- @Provide({to:InjectLabelWidth})
32
37
  readonly labelWidth!:number|undefined;
33
38
  @Prop({
34
39
  type: Boolean,
@@ -37,6 +42,59 @@ export default class SuButton extends Vue {
37
42
  }
38
43
  })
39
44
  readonly allowAotoMobile!:boolean;
45
+ @Provide({to:InjectEventBus,reactive:true})
46
+ private bus:Bus|undefined;
47
+ private items=new Set<Item>();
48
+ private addItem(item:Item):void{
49
+ this.items.add(item);
50
+ this.$nextTick(this.updateLabelWidth);
51
+ }
52
+ private removeItem(item:Item):void{
53
+ this.items.delete(item);
54
+ this.$nextTick(this.updateLabelWidth);
55
+ }
56
+ private updateLabelWidth(){
57
+ if(!this.isLoaded) return;
58
+ if(typeof this.labelWidth === 'undefined'){
59
+ this.sendLabelWidth = undefined;
60
+ }else if(this.labelWidth === 0){
61
+ this.sendLabelWidth=undefined;
62
+ this.$nextTick(() => {
63
+ let maxWidth = 0;
64
+ this.items.forEach((item => {
65
+ if((item.labelAlign||this.labelAlign) === 'top'){
66
+ return;
67
+ }
68
+ const width = item.$refs.labelDiv.offsetWidth;
69
+ if(width>maxWidth){
70
+ maxWidth=width;
71
+ }
72
+ }));
73
+ this.sendLabelWidth=maxWidth;
74
+ })
75
+ }else{
76
+ this.sendLabelWidth=this.labelWidth;
77
+ }
78
+ }
79
+ private isLoaded=false;
80
+ @Provide({to:InjectLabelWidth,reactive:true})
81
+ private sendLabelWidth:number|undefined=0;
82
+ created(){
83
+ this.bus={
84
+ addItem: this.addItem,
85
+ removeItem: this.removeItem,
86
+ labelUpdate: this.updateLabelWidth,
87
+ }
88
+ }
89
+ mounted(){
90
+ this.$nextTick(() => {
91
+ this.isLoaded=true;
92
+ this.updateLabelWidth();
93
+ });
94
+ }
95
+ beforeUnmount(){
96
+ this.isLoaded=false;
97
+ }
40
98
  }
41
99
  </script>
42
100
  <style>
@@ -0,0 +1,28 @@
1
+ <template>
2
+ <div class="star-ui star-ui-auto-direction su-auto-direction">
3
+ <slot />
4
+ </div>
5
+ </template>
6
+
7
+ <script lang="ts">
8
+ import { Vue } from "vue-class-component";
9
+ import { Register } from "@ui-root/reg";
10
+ import "@ui-root/global-style.css";
11
+
12
+ @Register({
13
+ name:"su-auto-direction",
14
+ })
15
+ export default class SuAutoDirection extends Vue {
16
+ }
17
+ </script>
18
+
19
+ <style>
20
+ .star-ui-auto-direction{
21
+ display: flex;
22
+ padding: 0;
23
+ flex-direction: row;
24
+ }
25
+ .star-ui-view-control.star-ui-view-control-mobile .star-ui-auto-direction{
26
+ flex-direction: column;
27
+ }
28
+ </style>
@@ -0,0 +1 @@
1
+ export { default as SuAutoDirection } from "./auto-direction/index.vue";
@@ -44,7 +44,7 @@ export default class SuViewControl extends Vue {
44
44
  this.windowWidth = window.innerWidth;
45
45
  this.windowHeight = window.innerHeight;
46
46
  }
47
- @Provide({to:SuViewCtrlInjectKeyIsMobile})
47
+ @Provide({to:SuViewCtrlInjectKeyIsMobile,reactive:true})
48
48
  public get $isMobile():boolean{
49
49
  switch (this.deviceType) {
50
50
  case "mobile":
@@ -56,12 +56,11 @@ export default class SuViewControl extends Vue {
56
56
  case "ua":
57
57
  return navigator.userAgent.toLowerCase().indexOf("mobile")!=-1;
58
58
  case "screen-width":
59
- console.log(this.windowWidth);
60
59
  return this.windowWidth < 1000;
61
60
  }
62
61
  return false;
63
62
  }
64
- @Provide({to:SuViewCtrlInjectKeyClassName})
63
+ @Provide({to:SuViewCtrlInjectKeyClassName,reactive:true})
65
64
  public get className():string[]{
66
65
  return [
67
66
  'su-view-control',
package/src/main.ts CHANGED
@@ -21,6 +21,7 @@ export { default as SuCalendar } from "./components/calendar.vue";
21
21
  export { default as SuViewControl } from "./components/view-control.vue";
22
22
 
23
23
  export * from "./components/menu";
24
+ export * from "./components/layout"
24
25
  export * from "./components/content";
25
26
 
26
27
  import { data } from "./reg";
@@ -1,19 +1,21 @@
1
1
  import { Vue } from 'vue-class-component';
2
2
  import "../../global-style.css";
3
3
  export default class SuButton extends Vue {
4
+ $refs: {
5
+ root: HTMLDivElement;
6
+ };
4
7
  fromItem: Vue | HTMLElement;
5
8
  private div;
6
9
  private id;
7
10
  private updateType;
8
11
  private visible;
9
12
  readonly isMobile: false;
10
- beforeCreate(): void;
11
- unmounted(): void;
12
13
  mounted(): void;
13
14
  beforeUnmount(): void;
14
15
  _clickCheck(ev: MouseEvent): boolean;
15
16
  private syncRequestId;
16
17
  _updateVisible(): void;
17
18
  readonly ctrlClass: string[];
19
+ private baseStyle;
18
20
  updatePos(): void;
19
21
  }
@@ -1,9 +1,14 @@
1
1
  import { Vue } from "vue-class-component";
2
2
  import { TypeFormLabelAlign } from "../../../outher";
3
+ import { Bus } from "./form.vue";
3
4
  import "@ui-root/global-style.css";
4
5
  export declare const InjectLabelWidth: unique symbol;
5
6
  export declare const InjectLabelAlign: unique symbol;
7
+ export declare const InjectEventBus: unique symbol;
6
8
  export default class SuButton extends Vue {
9
+ $refs: {
10
+ labelDiv: HTMLDivElement;
11
+ };
7
12
  readonly label: string;
8
13
  readonly labelWidth: string | number | undefined;
9
14
  readonly pLabelWidth: string | number | undefined;
@@ -11,5 +16,7 @@ export default class SuButton extends Vue {
11
16
  readonly pLabelAlign: TypeFormLabelAlign;
12
17
  readonly col: number;
13
18
  private get labelStyle();
19
+ readonly bus: Bus | undefined;
14
20
  created(): void;
21
+ beforeUnmount(): void;
15
22
  }
@@ -1,8 +1,24 @@
1
1
  import { Vue } from "vue-class-component";
2
2
  import type { TypeFormLabelAlign } from "../../../outher";
3
+ import Item from "./form-item.vue";
3
4
  import "@ui-root/global-style.css";
5
+ export interface Bus {
6
+ addItem: (item: Item) => void;
7
+ removeItem: (item: Item) => void;
8
+ labelUpdate: (item: Item) => void;
9
+ }
4
10
  export default class SuButton extends Vue {
5
11
  readonly labelAlign: TypeFormLabelAlign;
6
12
  readonly labelWidth: number | undefined;
7
13
  readonly allowAotoMobile: boolean;
14
+ private bus;
15
+ private items;
16
+ private addItem;
17
+ private removeItem;
18
+ private updateLabelWidth;
19
+ private isLoaded;
20
+ private sendLabelWidth;
21
+ created(): void;
22
+ mounted(): void;
23
+ beforeUnmount(): void;
8
24
  }
@@ -0,0 +1,4 @@
1
+ import { Vue } from "vue-class-component";
2
+ import "@ui-root/global-style.css";
3
+ export default class SuAutoDirection extends Vue {
4
+ }
@@ -0,0 +1 @@
1
+ export { default as SuAutoDirection } from "./auto-direction/index.vue";
package/types/main.d.ts CHANGED
@@ -15,6 +15,7 @@ export { default as SuSlider } from "./components/slider.vue";
15
15
  export { default as SuCalendar } from "./components/calendar.vue";
16
16
  export { default as SuViewControl } from "./components/view-control.vue";
17
17
  export * from "./components/menu";
18
+ export * from "./components/layout";
18
19
  export * from "./components/content";
19
20
  export * from "./outher";
20
21
  import { App } from "vue";