@leafer-in/state 1.0.0-rc.22 → 1.0.0-rc.23

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/dist/state.cjs ADDED
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+
3
+ var core = require('@leafer-ui/core');
4
+
5
+ function hasFixedState(leaf) {
6
+ return leaf.selected || leaf.disabled || core.State.isFocus(leaf);
7
+ }
8
+ function restoreStyle(leaf) {
9
+ const style = leaf.__.normalStyle;
10
+ if (style) {
11
+ leaf.set(style);
12
+ leaf.__.normalStyle = undefined;
13
+ }
14
+ }
15
+
16
+ function setStateStyle(leaf, stateType, pointerState) {
17
+ let style;
18
+ const data = leaf.__;
19
+ if (pointerState) {
20
+ style = !hasFixedState(leaf) && data[stateType];
21
+ }
22
+ else {
23
+ switch (stateType) {
24
+ case 'disabledStyle':
25
+ style = data[stateType];
26
+ break;
27
+ case 'focusStyle':
28
+ style = !leaf.disabled && data[stateType];
29
+ break;
30
+ case 'selectedStyle':
31
+ style = !leaf.disabled && !core.State.isFocus(leaf) && data[stateType];
32
+ break;
33
+ }
34
+ }
35
+ if (style) {
36
+ restoreStyle(leaf);
37
+ leaf.__.normalStyle = leaf.get(style);
38
+ leaf.set(style);
39
+ }
40
+ }
41
+
42
+ function unsetStateStyle(leaf, _stateType, pointerState) {
43
+ if (pointerState) {
44
+ if (!hasFixedState(leaf)) {
45
+ restoreStyle(leaf);
46
+ if (core.State.isPress(leaf) && leaf.pressStyle) {
47
+ setStateStyle(leaf, 'pressStyle', true);
48
+ }
49
+ else if (core.State.isHover(leaf) && leaf.hoverStyle) {
50
+ setStateStyle(leaf, 'hoverStyle', true);
51
+ }
52
+ }
53
+ }
54
+ else {
55
+ restoreStyle(leaf);
56
+ if (leaf.disabledStyle && leaf.disabled) {
57
+ setStateStyle(leaf, 'disabledStyle');
58
+ }
59
+ else if (leaf.focusStyle && core.State.isFocus(leaf)) {
60
+ setStateStyle(leaf, 'focusStyle');
61
+ }
62
+ else if (leaf.selectedStyle && leaf.selected) {
63
+ setStateStyle(leaf, 'selectedStyle');
64
+ }
65
+ }
66
+ }
67
+
68
+ function updateEventStyle(leaf, eventType) {
69
+ switch (eventType) {
70
+ case core.PointerEvent.ENTER:
71
+ setStateStyle(leaf, 'hoverStyle', true);
72
+ break;
73
+ case core.PointerEvent.LEAVE:
74
+ unsetStateStyle(leaf, 'hoverStyle', true);
75
+ break;
76
+ case core.PointerEvent.DOWN:
77
+ setStateStyle(leaf, 'pressStyle', true);
78
+ break;
79
+ case core.PointerEvent.UP:
80
+ unsetStateStyle(leaf, 'pressStyle', true);
81
+ break;
82
+ }
83
+ }
84
+
85
+ core.State.isHover = function (leaf) { return leaf.leafer && leaf.leafer.interaction.isHover(leaf); };
86
+ core.State.isPress = function (leaf) { return leaf.leafer && leaf.leafer.interaction.isPress(leaf); };
87
+ core.State.isFocus = function (leaf) { return leaf.leafer && leaf.leafer.interaction.isFocus(leaf); };
88
+ core.State.isDrag = function (leaf) { return leaf.leafer && leaf.leafer.interaction.isDrag(leaf); };
89
+ core.State.setStyle = function (leaf, stateType, value) { value ? setStateStyle(leaf, stateType) : unsetStateStyle(leaf); };
90
+ core.State.updateEventStyle = updateEventStyle;
91
+ core.UI.prototype.focus = function (value = true) {
92
+ this.waitLeafer(() => {
93
+ let { focusData } = this.app.interaction;
94
+ if (value) {
95
+ if (focusData)
96
+ focusData.focus(false);
97
+ focusData = this;
98
+ }
99
+ else {
100
+ focusData = null;
101
+ }
102
+ this.app.interaction.focusData = focusData;
103
+ core.State.setStyle(this, 'focusStyle', value);
104
+ });
105
+ };
@@ -0,0 +1 @@
1
+ "use strict";var e=require("@leafer-ui/core");function t(t){return t.selected||t.disabled||e.State.isFocus(t)}function s(e){const t=e.__.normalStyle;t&&(e.set(t),e.__.normalStyle=void 0)}function a(a,i,r){let n;const l=a.__;if(r)n=!t(a)&&l[i];else switch(i){case"disabledStyle":n=l[i];break;case"focusStyle":n=!a.disabled&&l[i];break;case"selectedStyle":n=!a.disabled&&!e.State.isFocus(a)&&l[i]}n&&(s(a),a.__.normalStyle=a.get(n),a.set(n))}function i(i,r,n){n?t(i)||(s(i),e.State.isPress(i)&&i.pressStyle?a(i,"pressStyle",!0):e.State.isHover(i)&&i.hoverStyle&&a(i,"hoverStyle",!0)):(s(i),i.disabledStyle&&i.disabled?a(i,"disabledStyle"):i.focusStyle&&e.State.isFocus(i)?a(i,"focusStyle"):i.selectedStyle&&i.selected&&a(i,"selectedStyle"))}e.State.isHover=function(e){return e.leafer&&e.leafer.interaction.isHover(e)},e.State.isPress=function(e){return e.leafer&&e.leafer.interaction.isPress(e)},e.State.isFocus=function(e){return e.leafer&&e.leafer.interaction.isFocus(e)},e.State.isDrag=function(e){return e.leafer&&e.leafer.interaction.isDrag(e)},e.State.setStyle=function(e,t,s){s?a(e,t):i(e)},e.State.updateEventStyle=function(t,s){switch(s){case e.PointerEvent.ENTER:a(t,"hoverStyle",!0);break;case e.PointerEvent.LEAVE:i(t,0,!0);break;case e.PointerEvent.DOWN:a(t,"pressStyle",!0);break;case e.PointerEvent.UP:i(t,0,!0)}},e.UI.prototype.focus=function(t=!0){this.waitLeafer((()=>{let{focusData:s}=this.app.interaction;t?(s&&s.focus(!1),s=this):s=null,this.app.interaction.focusData=s,e.State.setStyle(this,"focusStyle",t)}))};
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "@leafer-in/state",
3
- "version": "1.0.0-rc.22",
3
+ "version": "1.0.0-rc.23",
4
4
  "description": "@leafer-in/state",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
7
+ "type": "module",
7
8
  "main": "dist/state.esm.js",
9
+ "exports": {
10
+ "import": "./dist/state.esm.js",
11
+ "require": "./dist/state.cjs",
12
+ "types": "./types/index.d.ts"
13
+ },
14
+ "types": "types/index.d.ts",
8
15
  "unpkg": "dist/state.js",
9
16
  "jsdelivr": "dist/state.js",
10
- "types": "types/index.d.ts",
11
17
  "files": [
12
18
  "src",
13
19
  "types",
@@ -28,8 +34,8 @@
28
34
  "leaferjs"
29
35
  ],
30
36
  "dependencies": {
31
- "@leafer-ui/core": "1.0.0-rc.22",
32
- "@leafer-ui/interface": "1.0.0-rc.22",
33
- "@leafer-in/interface": "1.0.0-rc.22"
37
+ "@leafer-ui/core": "1.0.0-rc.23",
38
+ "@leafer-ui/interface": "1.0.0-rc.23",
39
+ "@leafer-in/interface": "1.0.0-rc.23"
34
40
  }
35
41
  }